ugly is_file_already_exists

This commit is contained in:
ochibani 2025-01-03 05:16:26 +02:00
parent 0941b16efc
commit d544e75551

View File

@ -804,94 +804,198 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag
record_label.set_label(&get_bundle("record", None)); record_label.set_label(&get_bundle("record", None));
//let wayland_record = main_context.block_on(WaylandRecorder::new()); //let wayland_record = main_context.block_on(WaylandRecorder::new());
record_button.connect_clicked(move |_| { record_button.connect_clicked(move |_| {
_delay_window_button.set_active(false); if !_audio_input_switch.is_active() &&
if _delay_spin.value() as u64 > 0 { !_audio_output_switch.is_active() &&
recording_delay( !_video_switch.is_active()
_delay_spin.clone(), {
_delay_spin.value() as u64, // Do nothing
delay_window.clone(), } else {
_delay_window_button.clone(), let file_name = _ffmpeg_record_interface.borrow_mut().filename.clone();
delay_window_label.clone(), let is_file_already_exists = Path::new(&file_name).try_exists().is_ok();
_record_button.clone(), if is_file_already_exists {
); let message_dialog = MessageDialog::new(
} else if _delay_spin.value() as u64 == 0 { Some(&_main_window),
let _area_capture = area_capture.borrow_mut(); adw::gtk::DialogFlags::all(),
let start_video_record = _ffmpeg_record_interface.borrow_mut().start_video( adw::gtk::MessageType::Warning,
_area_capture.x, adw::gtk::ButtonsType::YesNo,
_area_capture.y, &&get_bundle("already-exist", None),
_area_capture.width, );
_area_capture.height, let main_context = glib::MainContext::default();
mode, let answer = main_context.block_on(message_dialog.run_future());
); message_dialog.close();
if !_audio_input_switch.is_active() && if answer != adw::gtk::ResponseType::Yes {
!_audio_output_switch.is_active() && // Do nothing
!_video_switch.is_active() } else {
{ _delay_window_button.set_active(false);
// Do nothing if _delay_spin.value() as u64 > 0 {
recording_delay(
_delay_spin.clone(),
_delay_spin.value() as u64,
delay_window.clone(),
_delay_window_button.clone(),
delay_window_label.clone(),
_record_button.clone(),
);
} else if _delay_spin.value() as u64 == 0 {
let _area_capture = area_capture.borrow_mut();
let start_video_record = _ffmpeg_record_interface.borrow_mut().start_video(
_area_capture.x,
_area_capture.y,
_area_capture.width,
_area_capture.height,
mode,
);
_audio_input_switch.set_sensitive(false);
_audio_output_switch.set_sensitive(false);
_video_switch.set_sensitive(false);
start_timer(record_time_label.clone());
record_time_label.set_visible(true);
if hide_switch.is_active() {
_main_window.minimize();
}
_play_button.hide();
_record_button.hide();
_stop_button.show();
if _audio_input_switch.is_active() {
match _ffmpeg_record_interface.borrow_mut().start_input_audio() {
Ok(_) => {
// Do nothing
},
Err(error) => {
_audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true);
_record_button.show();
_stop_button.hide();
let text_buffer = TextBuffer::new(None);
text_buffer.set_text(&format!("{}", error));
_error_message.set_buffer(Some(&text_buffer));
_error_dialog.show();
},
}
}
if _audio_output_switch.is_active() {
match _ffmpeg_record_interface.borrow_mut().start_output_audio() {
Ok(_) => {
// Do nothing
},
Err(error) => {
_audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true);
_record_button.show();
_stop_button.hide();
let text_buffer = TextBuffer::new(None);
text_buffer.set_text(&format!("{}", error));
_error_message.set_buffer(Some(&text_buffer));
_error_dialog.show();
},
}
}
if _video_switch.is_active() {
match start_video_record {
Ok(_) => {
// Do nothing
},
Err(error) => {
_audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true);
_record_button.show();
_stop_button.hide();
let text_buffer = TextBuffer::new(None);
text_buffer.set_text(&format!("{}", error));
_error_message.set_buffer(Some(&text_buffer));
_error_dialog.show();
},
}
}
}
}
} else { } else {
_audio_input_switch.set_sensitive(false); _delay_window_button.set_active(false);
_audio_output_switch.set_sensitive(false); if _delay_spin.value() as u64 > 0 {
_video_switch.set_sensitive(false); recording_delay(
start_timer(record_time_label.clone()); _delay_spin.clone(),
record_time_label.set_visible(true); _delay_spin.value() as u64,
if hide_switch.is_active() { delay_window.clone(),
_main_window.minimize(); _delay_window_button.clone(),
} delay_window_label.clone(),
_play_button.hide(); _record_button.clone(),
_record_button.hide(); );
_stop_button.show(); } else if _delay_spin.value() as u64 == 0 {
if _audio_input_switch.is_active() { let _area_capture = area_capture.borrow_mut();
match _ffmpeg_record_interface.borrow_mut().start_input_audio() { let start_video_record = _ffmpeg_record_interface.borrow_mut().start_video(
Ok(_) => { _area_capture.x,
// Do nothing _area_capture.y,
}, _area_capture.width,
Err(error) => { _area_capture.height,
_audio_input_switch.set_sensitive(true); mode,
_audio_output_switch.set_sensitive(true); );
_video_switch.set_sensitive(true); _audio_input_switch.set_sensitive(false);
_record_button.show(); _audio_output_switch.set_sensitive(false);
_stop_button.hide(); _video_switch.set_sensitive(false);
let text_buffer = TextBuffer::new(None); start_timer(record_time_label.clone());
text_buffer.set_text(&format!("{}", error)); record_time_label.set_visible(true);
_error_message.set_buffer(Some(&text_buffer)); if hide_switch.is_active() {
_error_dialog.show(); _main_window.minimize();
},
} }
} _play_button.hide();
if _audio_output_switch.is_active() { _record_button.hide();
match _ffmpeg_record_interface.borrow_mut().start_output_audio() { _stop_button.show();
Ok(_) => { if _audio_input_switch.is_active() {
// Do nothing match _ffmpeg_record_interface.borrow_mut().start_input_audio() {
Ok(_) => {
// Do nothing
}, },
Err(error) => { Err(error) => {
_audio_input_switch.set_sensitive(true); _audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true); _audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true); _video_switch.set_sensitive(true);
_record_button.show(); _record_button.show();
_stop_button.hide(); _stop_button.hide();
let text_buffer = TextBuffer::new(None); let text_buffer = TextBuffer::new(None);
text_buffer.set_text(&format!("{}", error)); text_buffer.set_text(&format!("{}", error));
_error_message.set_buffer(Some(&text_buffer)); _error_message.set_buffer(Some(&text_buffer));
_error_dialog.show(); _error_dialog.show();
}, },
}
} }
} if _audio_output_switch.is_active() {
if _video_switch.is_active() { match _ffmpeg_record_interface.borrow_mut().start_output_audio() {
match start_video_record { Ok(_) => {
Ok(_) => { // Do nothing
// Do nothing
}, },
Err(error) => { Err(error) => {
_audio_input_switch.set_sensitive(true); _audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true); _audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true); _video_switch.set_sensitive(true);
_record_button.show(); _record_button.show();
_stop_button.hide(); _stop_button.hide();
let text_buffer = TextBuffer::new(None); let text_buffer = TextBuffer::new(None);
text_buffer.set_text(&format!("{}", error)); text_buffer.set_text(&format!("{}", error));
_error_message.set_buffer(Some(&text_buffer)); _error_message.set_buffer(Some(&text_buffer));
_error_dialog.show(); _error_dialog.show();
}, },
}
}
if _video_switch.is_active() {
match start_video_record {
Ok(_) => {
// Do nothing
},
Err(error) => {
_audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true);
_record_button.show();
_stop_button.hide();
let text_buffer = TextBuffer::new(None);
text_buffer.set_text(&format!("{}", error));
_error_message.set_buffer(Some(&text_buffer));
_error_dialog.show();
},
}
} }
} }
} }
@ -918,7 +1022,6 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag
// Do nothing // Do nothing
}, },
Err(error) => { Err(error) => {
_ffmpeg_record_interface.borrow_mut().kill().unwrap();
_audio_input_switch.set_sensitive(true); _audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true); _audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true); _video_switch.set_sensitive(true);
@ -937,7 +1040,6 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag
// Do nothing // Do nothing
}, },
Err(error) => { Err(error) => {
_ffmpeg_record_interface.borrow_mut().kill().unwrap();
_audio_input_switch.set_sensitive(true); _audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true); _audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true); _video_switch.set_sensitive(true);
@ -956,7 +1058,6 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag
// Do nothing // Do nothing
}, },
Err(error) => { Err(error) => {
_ffmpeg_record_interface.borrow_mut().kill().unwrap();
_audio_input_switch.set_sensitive(true); _audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true); _audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true); _video_switch.set_sensitive(true);
@ -1108,3 +1209,90 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag
Ok(()) Ok(())
} }
/*fn record() {
_delay_window_button.set_active(false);
if _delay_spin.value() as u64 > 0 {
recording_delay(
_delay_spin.clone(),
_delay_spin.value() as u64,
delay_window.clone(),
_delay_window_button.clone(),
delay_window_label.clone(),
_record_button.clone(),
);
} else if _delay_spin.value() as u64 == 0 {
let _area_capture = area_capture.borrow_mut();
let start_video_record = _ffmpeg_record_interface.borrow_mut().start_video(
_area_capture.x,
_area_capture.y,
_area_capture.width,
_area_capture.height,
mode,
);
_audio_input_switch.set_sensitive(false);
_audio_output_switch.set_sensitive(false);
_video_switch.set_sensitive(false);
start_timer(record_time_label.clone());
record_time_label.set_visible(true);
if hide_switch.is_active() {
_main_window.minimize();
}
_play_button.hide();
_record_button.hide();
_stop_button.show();
if _audio_input_switch.is_active() {
match _ffmpeg_record_interface.borrow_mut().start_input_audio() {
Ok(_) => {
// Do nothing
},
Err(error) => {
_audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true);
_record_button.show();
_stop_button.hide();
let text_buffer = TextBuffer::new(None);
text_buffer.set_text(&format!("{}", error));
_error_message.set_buffer(Some(&text_buffer));
_error_dialog.show();
},
}
}
if _audio_output_switch.is_active() {
match _ffmpeg_record_interface.borrow_mut().start_output_audio() {
Ok(_) => {
// Do nothing
},
Err(error) => {
_audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true);
_record_button.show();
_stop_button.hide();
let text_buffer = TextBuffer::new(None);
text_buffer.set_text(&format!("{}", error));
_error_message.set_buffer(Some(&text_buffer));
_error_dialog.show();
},
}
}
if _video_switch.is_active() {
match start_video_record {
Ok(_) => {
// Do nothing
},
Err(error) => {
_audio_input_switch.set_sensitive(true);
_audio_output_switch.set_sensitive(true);
_video_switch.set_sensitive(true);
_record_button.show();
_stop_button.hide();
let text_buffer = TextBuffer::new(None);
text_buffer.set_text(&format!("{}", error));
_error_message.set_buffer(Some(&text_buffer));
_error_dialog.show();
},
}
}*/