From fdb67659189a9935d83af899858ea8447e04f4f6 Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Sat, 4 Dec 2021 00:31:59 +0300 Subject: [PATCH] fix(#22): ask before overwrite the file --- src/ffmpeg_interface.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ffmpeg_interface.rs b/src/ffmpeg_interface.rs index 5209eac..556fcaf 100644 --- a/src/ffmpeg_interface.rs +++ b/src/ffmpeg_interface.rs @@ -15,6 +15,8 @@ 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 { @@ -137,6 +139,19 @@ impl Ffmpeg { .to_string(), ); + let is_file_already_exists = std::path::Path::new(format!("{}", self.saved_filename.unwrap())) + .exists(); + + if is_file_already_exists { + if MessageDialog::new(None::<&Window>, + DialogFlags::empty(), + MessageType::Question, + ButtonsType::Ok, + &gettext("Would you like to overwrite this file?")).run() != ResponseType::Ok { + return (None, None); + } + } + if self.record_audio.get_active() { let mut ffmpeg_command = Command::new("ffmpeg"); ffmpeg_command.arg("-f");