fix(#22): ask before overwrite the file

This commit is contained in:
Salem Yaslem 2021-12-04 00:39:18 +03:00
parent fdb6765918
commit 77ab1d62d2
2 changed files with 32 additions and 20 deletions

View File

@ -1,6 +1,8 @@
extern crate subprocess;
use chrono::prelude::*;
use gettextrs::gettext;
use gtk::prelude::*;
use gtk::{ButtonsType, DialogFlags, MessageDialog, MessageType, ResponseType};
use gtk::{
CheckButton, ComboBoxText, Entry, FileChooser, ProgressBar, SpinButton, Window, WindowPosition,
WindowType,
@ -15,8 +17,6 @@ use std::time::Duration;
use subprocess::Exec;
use zbus::dbus_proxy;
use zvariant::Value;
use gtk::{ButtonsType, DialogFlags, MessageType, MessageDialog, ResponseType};
use gettextrs::gettext;
#[derive(Clone)]
pub struct ProgressWidget {
@ -139,17 +139,24 @@ impl Ffmpeg {
.to_string(),
);
let is_file_already_exists = std::path::Path::new(format!("{}", self.saved_filename.unwrap()))
.exists();
let is_file_already_exists =
std::path::Path::new(format!("{}", self.saved_filename.clone().unwrap()).as_str())
.exists();
if is_file_already_exists {
if MessageDialog::new(None::<&Window>,
let message_dialog = MessageDialog::new(
None::<&Window>,
DialogFlags::empty(),
MessageType::Question,
ButtonsType::Ok,
&gettext("Would you like to overwrite this file?")).run() != ResponseType::Ok {
return (None, None);
}
MessageType::Warning,
ButtonsType::OkCancel,
&gettext("Would you like to overwrite this file?"),
);
if message_dialog.run() != ResponseType::Ok {
message_dialog.hide();
return (None, None);
}
message_dialog.hide();
}
if self.record_audio.get_active() {
@ -182,7 +189,7 @@ impl Ffmpeg {
x,
y,
width,
height
height,
);
}
@ -222,7 +229,6 @@ impl Ffmpeg {
ffmpeg_command.arg("-follow_mouse");
ffmpeg_command.arg("centered");
}
ffmpeg_command.arg("-crf");
ffmpeg_command.arg("1");
ffmpeg_command.arg(self.saved_filename.as_ref().unwrap().to_string());

View File

@ -356,18 +356,24 @@ fn main() {
let _record_button = record_button.clone();
record_button.connect_clicked(move |_| {
let _area_capture = _area_capture.borrow_mut().clone();
_ffmpeg_record_interface.borrow_mut().start_record(
match _ffmpeg_record_interface.borrow_mut().start_record(
_area_capture.x,
_area_capture.y,
_area_capture.width,
_area_capture.height,
);
_indicator
.borrow_mut()
.set_status(AppIndicatorStatus::Active);
_record_button.hide();
_stop_button.show();
) {
(None, None) => {
// do nothing if the start_record function return nothing
}
_ => {
_indicator
.borrow_mut()
.set_status(AppIndicatorStatus::Active);
_record_button.hide();
_stop_button.show();
}
}
});
let mut _ffmpeg_record_interface = ffmpeg_record_interface.clone();