mirror of
https://github.com/xlmnxp/blue-recorder.git
synced 2024-11-23 17:13:11 +03:00
fix is_file_already_exists & play button
This commit is contained in:
parent
3428d6dd35
commit
56f5598514
@ -82,18 +82,20 @@
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkMessageDialog" id="progress_dialog">
|
||||
<property name="title">Progress</property>
|
||||
<property name="transient-for">main_window</property>
|
||||
<property name="deletable">False</property>
|
||||
<property name="default-width">300</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="message-type">info</property>
|
||||
<child type="titlebar">
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkProgressBar" id="progressbar">
|
||||
<property name="visible">True</property>
|
||||
<property name="fraction">0.0</property>
|
||||
<property name="show-text">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="margin-top">10</property>
|
||||
<property name="margin-start">10</property>
|
||||
<property name="margin-end">10</property>
|
||||
</object>
|
||||
@ -105,11 +107,12 @@
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="label" translatable="yes">Finish Recording</property>
|
||||
<property name="margin-top">10</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="margin-top">15</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkImage" id="image3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
@ -151,6 +154,15 @@
|
||||
<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>
|
||||
@ -204,7 +216,6 @@
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="area_grab_button">
|
||||
<property name="name">area_grab_button</property>
|
||||
<property name="group">area_grab_button</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
|
@ -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<PathBuf> {
|
||||
|
@ -62,6 +62,8 @@ pub struct Ffmpeg {
|
||||
pub saved_filename: Option<String>,
|
||||
pub unbound: Option<Sender<bool>>,
|
||||
pub progress_widget: ProgressWidget,
|
||||
pub window: Window,
|
||||
pub overwrite: CheckButton,
|
||||
}
|
||||
|
||||
impl Ffmpeg {
|
||||
@ -72,10 +74,6 @@ impl Ffmpeg {
|
||||
width: u16,
|
||||
height: u16,
|
||||
) -> (Option<u32>, Option<u32>) {
|
||||
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(
|
||||
|
24
src/main.rs
24
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();
|
||||
|
Loading…
Reference in New Issue
Block a user