From 56f55985140413260b8b5ce7aa4861339d4ec522 Mon Sep 17 00:00:00 2001
From: ochibani <11yzyv86j@relay.firefox.com>
Date: Mon, 17 Oct 2022 01:56:43 +0200
Subject: [PATCH] fix is_file_already_exists & play button
---
interfaces/main.ui | 23 ++++++++++++++-----
src/config_management.rs | 1 +
src/ffmpeg_interface.rs | 48 ++++++++++++++++++++++++++--------------
src/main.rs | 24 ++++++++++++--------
4 files changed, 64 insertions(+), 32 deletions(-)
diff --git a/interfaces/main.ui b/interfaces/main.ui
index 3554bfa..d3f5d23 100644
--- a/interfaces/main.ui
+++ b/interfaces/main.ui
@@ -82,18 +82,20 @@
+
+
True
True
@@ -151,6 +154,15 @@
5
+
+
+ checkbutton
+ True
+ True
+ False
+ True
+
+
True
@@ -204,7 +216,6 @@
area_grab_button
- area_grab_button
True
True
True
diff --git a/src/config_management.rs b/src/config_management.rs
index fa6e9da..73e9428 100755
--- a/src/config_management.rs
+++ b/src/config_management.rs
@@ -45,6 +45,7 @@ fn default() {
set("default", "audiocheck", "1");
set("default", "mousecheck", "1");
set("default", "followmousecheck", "0");
+ set("default", "overwritecheck", "0");
}
fn merge_previous_version() -> Option {
diff --git a/src/ffmpeg_interface.rs b/src/ffmpeg_interface.rs
index 9b90b78..78f7d11 100644
--- a/src/ffmpeg_interface.rs
+++ b/src/ffmpeg_interface.rs
@@ -62,6 +62,8 @@ pub struct Ffmpeg {
pub saved_filename: Option,
pub unbound: Option>,
pub progress_widget: ProgressWidget,
+ pub window: Window,
+ pub overwrite: CheckButton,
}
impl Ffmpeg {
@@ -72,10 +74,6 @@ impl Ffmpeg {
width: u16,
height: u16,
) -> (Option, Option) {
- if self.video_process_id.is_some() || self.audio_process_id.is_some() {
- //self.stop_record();
- }
-
self.saved_filename = Some(
self.filename
.0
@@ -99,23 +97,22 @@ impl Ffmpeg {
std::path::Path::new(&self.saved_filename.clone().unwrap())
.exists();
- if is_file_already_exists {
+ if !self.overwrite.is_active() && is_file_already_exists {
let message_dialog = MessageDialog::new(
- None::<&Window>,
+ Some(&self.window),
DialogFlags::empty(),
MessageType::Warning,
- ButtonsType::OkCancel,
- &gettext("Would you like to overwrite this file?"),
+ ButtonsType::Ok,
+ &gettext("File already exist."),
);
-
- message_dialog.connect_response(glib::clone!(@strong message_dialog => move |_, response| {
message_dialog.show();
- if response != ResponseType::Ok {
+ message_dialog.connect_response(glib::clone!(@strong message_dialog => move |_, response| {
+ if response == ResponseType::Ok {
+ message_dialog.hide();
+ }
message_dialog.hide();
- return;
- }
- message_dialog.hide();
}));
+ return (None, None);
}
if self.record_audio.is_active() {
@@ -184,21 +181,29 @@ impl Ffmpeg {
pub fn stop_record(&self) {
self.progress_widget.show();
// kill the process to stop recording
+ self
+ .progress_widget
+ .set_progress("".to_string(), 1, 6);
+
if self.video_process_id.is_some() {
self
.progress_widget
.set_progress("Stop Recording Video".to_string(), 1, 6);
- Command::new("kill")
+ Command::new("kill")
.arg(format!("{}", self.video_process_id.unwrap()))
.output()
.unwrap();
}
+ self
+ .progress_widget
+ .set_progress("".to_string(), 2, 6);
+
if self.audio_process_id.is_some() {
self
.progress_widget
.set_progress("Stop Recording Audio".to_string(), 2, 6);
- Command::new("kill")
+ Command::new("kill")
.arg(format!("{}", self.audio_process_id.unwrap()))
.output()
.unwrap();
@@ -243,12 +248,15 @@ impl Ffmpeg {
));
move_command.output().unwrap();
+ self
+ .progress_widget
+ .set_progress("".to_string(), 4, 6);
+
// if audio record, then merge video with audio
if is_audio_record && is_video_record {
self
.progress_widget
.set_progress("Save Audio Recording".to_string(), 4, 6);
-
let mut ffmpeg_audio_merge_command = Command::new("ffmpeg");
ffmpeg_audio_merge_command.arg("-i");
ffmpeg_audio_merge_command.arg(format!(
@@ -306,6 +314,12 @@ impl Ffmpeg {
.unwrap();
}
+ self.progress_widget.set_progress(
+ "".to_string(),
+ 5,
+ 6,
+ );
+
// execute command after finish recording
if self.command.text().trim() != "" {
self.progress_widget.set_progress(
diff --git a/src/main.rs b/src/main.rs
index 65e0ca4..350e75b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -30,7 +30,6 @@ pub fn build_ui(application: &Application) {
println!("Failed to initialize GTK.");
return;
}
- // TODO: add wayland screen record support
let ui_src = include_str!("../interfaces/main.ui").to_string();
let builder: Builder = Builder::from_string(ui_src.as_str());
@@ -58,7 +57,6 @@ pub fn build_ui(application: &Application) {
config_management::initialize();
// get Objects from UI
- let main_window: Window = builder.object("main_window").unwrap();
let area_chooser_window: Window = builder.object("area_chooser_window").unwrap();
let area_grab_button: ToggleButton = builder.object("area_grab_button").unwrap();
let area_grab_icon: Image = builder.object("area_grab_icon").unwrap();
@@ -80,7 +78,9 @@ pub fn build_ui(application: &Application) {
let format_chooser_combobox: ComboBoxText = builder.object("comboboxtext1").unwrap();
let frames_label: Label = builder.object("frames_label").unwrap();
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_button: Button = builder.object("progressbutton").unwrap();
let progress_dialog: MessageDialog = builder.object("progress_dialog").unwrap();
@@ -92,7 +92,6 @@ pub fn build_ui(application: &Application) {
let video_switch: CheckButton = builder.object("videoswitch").unwrap();
let window_grab_icon: Image = builder.object("window_grab_icon").unwrap();
let window_grab_button: ToggleButton = builder.object("window_grab_button").unwrap();
- // TODO: add timer
// --- default properties
// Windows
@@ -166,27 +165,35 @@ pub fn build_ui(application: &Application) {
audio_source_combobox.set_active(Some(0));
// Switchs
- let _audio_switch = audio_switch.clone();
video_switch.set_label(Some(&gettext("Record Video")));
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 _audio_switch = audio_switch.clone();
let _mouse_switch = mouse_switch.clone();
let _follow_mouse_switch = follow_mouse_switch.clone();
video_switch.connect_toggled(move |switch: &CheckButton| {
config_management::set_bool("default", "videocheck", switch.is_active());
if switch.is_active() {
+ _audio_switch.set_active(false);
+ _audio_switch.set_sensitive(true);
_mouse_switch.set_sensitive(true);
- _follow_mouse_switch.set_sensitive(true);
} else {
_mouse_switch.set_sensitive(false);
_follow_mouse_switch.set_sensitive(false);
}
+ if !switch.is_active() {
+ _audio_switch.set_active(false);
+ _audio_switch.set_sensitive(false);
+ _mouse_switch.set_active(false);
+ }
});
let _follow_mouse_switch = follow_mouse_switch.clone();
mouse_switch.connect_toggled(move |switch: &CheckButton| {
@@ -194,6 +201,7 @@ pub fn build_ui(application: &Application) {
if switch.is_active() {
_follow_mouse_switch.set_sensitive(true);
} else {
+ _follow_mouse_switch.set_active(false);
_follow_mouse_switch.set_sensitive(false);
}
});
@@ -373,6 +381,8 @@ pub fn build_ui(application: &Application) {
saved_filename: None,
unbound: None,
progress_widget: ProgressWidget::new(progress_dialog, progressbar, progress_button),
+ window: main_window.clone(),
+ overwrite: overwrite_switch,
}));
let mut _ffmpeg_record_interface = ffmpeg_record_interface.clone();
@@ -388,11 +398,7 @@ pub fn build_ui(application: &Application) {
) {
(None, None) => {
// do nothing if the start_record function return nothing
- if _audio_switch.is_active() {
- _record_button.hide();
- _stop_button.show();
}
- }
_ => {
_record_button.hide();
_stop_button.show();