From 2ce25c6ab0dcc9155eceec50f86ef647b6374cc9 Mon Sep 17 00:00:00 2001 From: ochibani <11yzyv86j@relay.firefox.com> Date: Sat, 6 Jul 2024 02:57:31 +0200 Subject: [PATCH] play button error dialog --- README.md | 5 +---- interfaces/main.ui | 21 ++++++++++++++----- locales/ar.ftl | 6 ++++++ locales/en.ftl | 6 ++++++ src/ffmpeg_interface.rs | 46 ++++++++++++++++++++++++++++++++++------- src/main.rs | 21 ++++++++++++++----- 6 files changed, 84 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 7758306..ee4a2f5 100644 --- a/README.md +++ b/README.md @@ -24,15 +24,12 @@ ffmpeg gtk gdk gio -gettext -libappindicator3 x11-utils -pulseaudio ``` Install dependencies Ubuntu and Debian based distros: ``` -sudo apt install build-essential clang cargo libappindicator3-1 x11-utils gettext pulseaudio ffmpeg +sudo apt install build-essential clang cargo x11-utils ffmpeg libgtk-3-dev libgtk-4-dev libatk1.0-dev librust-alsa-dev librust-gstreamer-dev ``` Then use `Cargo` to build it: ``` diff --git a/interfaces/main.ui b/interfaces/main.ui index 2561eb9..9163714 100644 --- a/interfaces/main.ui +++ b/interfaces/main.ui @@ -10,6 +10,7 @@ True True + False True @@ -20,7 +21,7 @@ True True - 32 + 48 dialog-error-symbolic @@ -37,10 +38,20 @@ expander_label - - False - False - False + + True + True + never + + + False + False + False + word-char + True + True + + diff --git a/locales/ar.ftl b/locales/ar.ftl index 1c03ab8..469bd97 100644 --- a/locales/ar.ftl +++ b/locales/ar.ftl @@ -60,6 +60,9 @@ wmv-format = WMV (Windows Media Video) # Name blue-recorder = المسجّل الأزرق +# Close error dialog +close = Close + # Copy right copy-right = © 2021 Salem Yaslem @@ -87,6 +90,9 @@ details-button = Details # Run command input enter-command = اكتب الأمر هنا.. +# Error dialog title +error-title = Error + # Frames label file-name = اسم الملفّ الافتراضي: diff --git a/locales/en.ftl b/locales/en.ftl index c5c7e87..05b77bb 100644 --- a/locales/en.ftl +++ b/locales/en.ftl @@ -60,6 +60,9 @@ wmv-format = WMV (Windows Media Video) # Name blue-recorder = Blue Recorder +# Close error dialog +close = Close + # Copy right copy-right = © 2021 Salem Yaslem @@ -87,6 +90,9 @@ details-button = Details # Run command input enter-command = Enter your command here.. +# Error dialog title +error-title = Error + # Frames label file-name = Default filename: diff --git a/src/ffmpeg_interface.rs b/src/ffmpeg_interface.rs index 860d2d5..8fcc96c 100644 --- a/src/ffmpeg_interface.rs +++ b/src/ffmpeg_interface.rs @@ -1,13 +1,13 @@ extern crate subprocess; use crate::config_management; -use crate::utils::{is_snap, is_wayland}; +use crate::utils::{get_bundle, is_snap, is_wayland}; use crate::wayland_record::{CursorModeTypes, RecordTypes, WaylandRecorder}; use chrono::prelude::*; use ffmpeg_sidecar::child::FfmpegChild; use ffmpeg_sidecar::command::FfmpegCommand; -use gtk::{prelude::*, ResponseType}; +use gtk::{prelude::*, ResponseType, TextBuffer, TextView}; use gtk::{ButtonsType, DialogFlags, MessageDialog, MessageType}; -use gtk::{CheckButton, ComboBoxText, Entry, FileChooserNative, SpinButton, Window}; +use gtk::{CheckButton, ComboBoxText, Entry, FileChooserNative, Label, SpinButton, Window}; use std::cell::RefCell; use std::path::PathBuf; use std::process::Command; @@ -42,6 +42,9 @@ pub struct Ffmpeg { pub bundle: String, pub video_record_bitrate: SpinButton, pub audio_record_bitrate: SpinButton, + pub error_window: MessageDialog, + pub error_window_text: Label, + pub error_details: TextView, } impl Ffmpeg { @@ -425,13 +428,42 @@ impl Ffmpeg { if self.saved_filename.is_some() { if is_snap() { // open the video using snapctrl for snap package - Command::new("snapctl") + let snapctl = Command::new("snapctl") .arg("user-open") .arg(self.saved_filename.unwrap()) - .spawn() - .unwrap(); + .spawn(); + match snapctl { + Ok(_) => { + // Continue + }, + Err(error) => { + let text_buffer = TextBuffer::new(None); + text_buffer.set_text(&error.to_string()); + self.error_window.set_title(Some(&get_bundle("error-title", None))); + self.error_window_text.set_label(&get_bundle("play-error", None)); + self.error_details.set_buffer(Some(&text_buffer)); + self.error_window.set_transient_for(Some(&self.window)); + self.error_window.show(); + self.error_window.set_hide_on_close(true); + }, + } } else { - open::that(self.saved_filename.unwrap()).unwrap(); + let open_file = open::that(self.saved_filename.unwrap()); + match open_file { + Ok(_) => { + // Continue + }, + Err(error) => { + let text_buffer = TextBuffer::new(None); + text_buffer.set_text(&error.to_string()); + self.error_window.set_title(Some(&get_bundle("error-title", None))); + self.error_window_text.set_label(&get_bundle("play-error", None)); + self.error_details.set_buffer(Some(&text_buffer)); + self.error_window.set_transient_for(Some(&self.window)); + self.error_window.show(); + self.error_window.set_hide_on_close(true); + }, + } } } } diff --git a/src/main.rs b/src/main.rs index d0be7d4..3c88250 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,6 +112,14 @@ pub fn build_ui(application: &Application) { stop_button.hide(); play_button.hide(); + // Error dialog + error_dialog_button.set_label(&get_bundle("close", None)); + error_expander_label.set_label(&get_bundle("details-button", None)); + let _error_dialog = error_dialog.clone(); + error_dialog_button.connect_clicked(move |_|{ + _error_dialog.close(); + }); + // Toggle button config_management::set("default", "mode", "screen"); screen_grab_button.set_active(true); @@ -569,9 +577,12 @@ pub fn build_ui(application: &Application) { bundle: bundle_msg, video_record_bitrate: video_bitrate_spin, audio_record_bitrate: audio_bitrate_spin, + error_window: error_dialog, + error_window_text: error_dialog_label, + error_details: error_message, })); - // Record Button + // Record button let _delay_window = delay_window.clone(); let _delay_window_button = delay_window_button.clone(); let _ffmpeg_record_interface = ffmpeg_record_interface.clone(); @@ -620,7 +631,7 @@ pub fn build_ui(application: &Application) { } }); - // Stop Record Button + // Stop record button let mut _ffmpeg_record_interface = ffmpeg_record_interface.clone(); let _play_button = play_button.clone(); let _stop_button = stop_button.clone(); @@ -635,17 +646,17 @@ pub fn build_ui(application: &Application) { _play_button.show(); }); - // Delay Window Button + // Delay window button let _delay_window_button = delay_window_button.clone(); delay_window_button.connect_clicked(move |_| {}); - // Play Button + // Play button let mut _ffmpeg_record_interface = ffmpeg_record_interface.clone(); play_button.connect_clicked(move |_| { _ffmpeg_record_interface.borrow_mut().clone().play_record(); }); - // About Dialog + // About dialog let mut about_icon_path = { let mut current_exec_dir = std::env::current_exe().unwrap(); current_exec_dir.pop();