From f857ba542c8c1eaa5d4c95357ce6feafc4496cb5 Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Sat, 14 Oct 2023 05:18:53 +0300 Subject: [PATCH] remove overwrite switch and fix message dialog --- interfaces/main.ui | 9 --------- src/ffmpeg_interface.rs | 21 +++++++++++---------- src/main.rs | 11 ++++------- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/interfaces/main.ui b/interfaces/main.ui index f8d67a8..eb00b39 100644 --- a/interfaces/main.ui +++ b/interfaces/main.ui @@ -187,15 +187,6 @@ 5 - - - checkbutton - True - True - False - True - - True diff --git a/src/ffmpeg_interface.rs b/src/ffmpeg_interface.rs index 7db0464..0a3b68b 100644 --- a/src/ffmpeg_interface.rs +++ b/src/ffmpeg_interface.rs @@ -1,7 +1,7 @@ extern crate subprocess; use chrono::prelude::*; use gettextrs::gettext; -use gtk::prelude::*; +use gtk::{prelude::*, ResponseType}; use gtk::{ButtonsType, DialogFlags, MessageDialog, MessageType}; use gtk::{CheckButton, ComboBoxText, Entry, FileChooserNative, ProgressBar, SpinButton, Window}; use std::cell::RefCell; @@ -12,6 +12,7 @@ use std::sync::mpsc::Sender; use std::thread::sleep; use std::time::Duration; use subprocess::Exec; +use crate::wayland_record::WaylandRecorder; #[derive(Clone)] pub struct ProgressWidget { @@ -60,7 +61,7 @@ pub struct Ffmpeg { pub unbound: Option>, pub progress_widget: ProgressWidget, pub window: Window, - pub overwrite: CheckButton, + pub record_wayland: WaylandRecorder } impl Ffmpeg { @@ -89,21 +90,21 @@ impl Ffmpeg { let is_file_already_exists = std::path::Path::new(&self.saved_filename.clone().unwrap()).exists(); - if !self.overwrite.is_active() && is_file_already_exists { + if is_file_already_exists { let message_dialog = MessageDialog::new( Some(&self.window), - DialogFlags::empty(), - MessageType::Question, + DialogFlags::all(), + MessageType::Warning, ButtonsType::YesNo, &gettext("File already exist. Do you want to overwrite it?"), ); - message_dialog - .connect_response(|message_dialog: &MessageDialog, _| message_dialog.hide()); + let answer = glib::MainContext::default().block_on(message_dialog.run_future()); + message_dialog.close(); - message_dialog.show(); - - return None; + if answer != ResponseType::Yes { + return None; + } } if self.record_audio.is_active() { diff --git a/src/main.rs b/src/main.rs index 92aa214..c9d20cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,6 @@ use std::process::{Command, Stdio}; use std::rc::Rc; use timer::{recording_delay, start_timer, stop_timer}; use wayland_record::WaylandRecorder; -use futures::executor; #[async_std::main] @@ -95,7 +94,6 @@ pub fn build_ui(application: &Application) { let frames_spin: SpinButton = builder.object("frames").unwrap(); let main_window: Window = builder.object("main_window").unwrap(); let mouse_switch: CheckButton = builder.object("mouseswitch").unwrap(); - let overwrite_switch: CheckButton = builder.object("overwriteswitch").unwrap(); let play_button: Button = builder.object("playbutton").unwrap(); let progress_dialog: MessageDialog = builder.object("progress_dialog").unwrap(); let progressbar: ProgressBar = builder.object("progressbar").unwrap(); @@ -120,8 +118,10 @@ pub fn build_ui(application: &Application) { // Hide window grab button in Wayland if is_wayland() { + area_grab_button.set_can_focus(false); area_grab_button.set_can_target(false); - area_grab_button.add_css_class("disabled") + area_grab_button.add_css_class("disabled"); + area_grab_button.set_tooltip_text(Some(&gettext("Not supported in Wayland"))); } // Entries @@ -182,12 +182,10 @@ pub fn build_ui(application: &Application) { audio_switch.set_label(Some(&gettext("Record Audio"))); mouse_switch.set_label(Some(&gettext("Show Mouse"))); follow_mouse_switch.set_label(Some(&gettext("Follow Mouse"))); - overwrite_switch.set_label(Some(&gettext("Overwrite"))); video_switch.set_active(config_management::get_bool("default", "videocheck")); audio_switch.set_active(config_management::get_bool("default", "audiocheck")); mouse_switch.set_active(config_management::get_bool("default", "mousecheck")); follow_mouse_switch.set_active(config_management::get_bool("default", "followmousecheck")); - overwrite_switch.set_active(config_management::get_bool("default", "overwritecheck")); let _video_switch = video_switch.clone(); let _audio_switch = audio_switch.clone(); @@ -473,9 +471,8 @@ pub fn build_ui(application: &Application) { unbound: None, progress_widget: ProgressWidget::new(progress_dialog, progressbar), window: main_window.clone(), - overwrite: overwrite_switch, record_delay: delay_spin, - record_wayland: executor::block_on(WaylandRecorder::new()) + record_wayland: glib::MainContext::default().block_on(WaylandRecorder::new()) })); // Record Button