remove overwrite switch and fix message dialog

This commit is contained in:
Salem Yaslem 2023-10-14 05:18:53 +03:00
parent 369553007c
commit f857ba542c
3 changed files with 15 additions and 26 deletions

View File

@ -187,15 +187,6 @@
<property name="margin-bottom">5</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="overwriteswitch">
<property name="label" translatable="yes">checkbutton</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="active">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="folder_chooser">
<property name="visible">True</property>

View File

@ -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<Sender<bool>>,
pub progress_widget: ProgressWidget,
pub window: Window,
pub overwrite: CheckButton,
pub record_wayland: WaylandRecorder
}
impl Ffmpeg {
@ -89,22 +90,22 @@ 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());
message_dialog.show();
let answer = glib::MainContext::default().block_on(message_dialog.run_future());
message_dialog.close();
if answer != ResponseType::Yes {
return None;
}
}
if self.record_audio.is_active() {
let mut ffmpeg_command = Command::new("ffmpeg");

View File

@ -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