remove progress dialog

This commit is contained in:
Salem Yaslem 2023-10-21 19:55:33 +03:00
parent 0e9576265c
commit 5f847a021c
3 changed files with 3 additions and 101 deletions

View File

@ -81,28 +81,6 @@
</object> </object>
</child> </child>
</object> </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>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkProgressBar" id="progress_bar">
<property name="visible">True</property>
<property name="fraction">0.0</property>
<property name="show-text">True</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
</object>
</child>
</object>
</child>
</object>
<object class="GtkWindow" id="delay_window"> <object class="GtkWindow" id="delay_window">
<property name="name">delay_window</property> <property name="name">delay_window</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>

View File

@ -5,7 +5,7 @@ use chrono::prelude::*;
use gettextrs::gettext; use gettextrs::gettext;
use gtk::{prelude::*, ResponseType}; use gtk::{prelude::*, ResponseType};
use gtk::{ButtonsType, DialogFlags, MessageDialog, MessageType}; use gtk::{ButtonsType, DialogFlags, MessageDialog, MessageType};
use gtk::{CheckButton, ComboBoxText, Entry, FileChooserNative, ProgressBar, SpinButton, Window}; use gtk::{CheckButton, ComboBoxText, Entry, FileChooserNative, SpinButton, Window};
use std::cell::RefCell; use std::cell::RefCell;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::{Child, Command}; use std::process::{Child, Command};
@ -15,37 +15,6 @@ use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
use subprocess::Exec; use subprocess::Exec;
#[derive(Clone)]
pub struct ProgressWidget {
pub progress_dialog: MessageDialog,
pub progress_bar: ProgressBar,
}
impl ProgressWidget {
pub fn new(progress_dialog: MessageDialog, progress_bar: ProgressBar) -> ProgressWidget {
ProgressWidget {
progress_dialog,
progress_bar,
}
}
pub fn set_progress(&self, title: String, value: i32, max: i32) {
glib::MainContext::default().block_on(async {
let progress_percentage: f64 = value as f64 / max as f64;
self.progress_bar.set_text(Some(&title));
self.progress_bar.set_fraction(progress_percentage);
});
}
pub fn show(&self) {
self.progress_dialog.show();
}
pub fn hide(&self) {
self.progress_dialog.hide();
}
}
#[derive(Clone)] #[derive(Clone)]
pub struct Ffmpeg { pub struct Ffmpeg {
pub filename: (FileChooserNative, Entry, ComboBoxText), pub filename: (FileChooserNative, Entry, ComboBoxText),
@ -61,7 +30,6 @@ pub struct Ffmpeg {
pub audio_process: Option<Rc<RefCell<Child>>>, pub audio_process: Option<Rc<RefCell<Child>>>,
pub saved_filename: Option<String>, pub saved_filename: Option<String>,
pub unbound: Option<Sender<bool>>, pub unbound: Option<Sender<bool>>,
pub progress_widget: ProgressWidget,
pub window: Window, pub window: Window,
pub record_wayland: WaylandRecorder, pub record_wayland: WaylandRecorder,
pub main_context: gtk::glib::MainContext, pub main_context: gtk::glib::MainContext,
@ -211,16 +179,8 @@ impl Ffmpeg {
} }
pub fn stop_record(&mut self) { pub fn stop_record(&mut self) {
glib::MainContext::default().block_on(async {
self.progress_widget.show();
});
self.progress_widget.set_progress("".to_string(), 1, 7);
// kill the process to stop recording // kill the process to stop recording
if self.video_process.is_some() { if self.video_process.is_some() {
self.progress_widget
.set_progress("Stop Recording Video".to_string(), 1, 7);
Command::new("kill") Command::new("kill")
.arg(format!( .arg(format!(
"{}", "{}",
@ -241,12 +201,7 @@ impl Ffmpeg {
self.main_context.block_on(self.record_wayland.stop()); self.main_context.block_on(self.record_wayland.stop());
} }
self.progress_widget.set_progress("".to_string(), 2, 7);
if self.audio_process.is_some() { if self.audio_process.is_some() {
self.progress_widget
.set_progress("Stop Recording Audio".to_string(), 2, 7);
Command::new("kill") Command::new("kill")
.arg(format!( .arg(format!(
"{}", "{}",
@ -307,15 +262,7 @@ impl Ffmpeg {
]); ]);
move_command.output().unwrap(); move_command.output().unwrap();
} else { } else {
println!("convert webm to specified format");
// convert webm to specified format // convert webm to specified format
self.progress_widget.set_progress(
"Convert screen-cast to specified format".to_string(),
4,
7,
);
Command::new("ffmpeg") Command::new("ffmpeg")
.args([ .args([
"-i", "-i",
@ -334,14 +281,8 @@ impl Ffmpeg {
.output() .output()
.unwrap(); .unwrap();
} }
self.progress_widget.set_progress("".to_string(), 5, 7);
// if audio record, then merge video with audio // if audio record, then merge video with audio
if is_audio_record { if is_audio_record {
self.progress_widget
.set_progress("Save Audio Recording".to_string(), 5, 7);
Command::new("ffmpeg") Command::new("ffmpeg")
.args([ .args([
"-i", "-i",
@ -368,9 +309,6 @@ impl Ffmpeg {
} }
// if only audio is recording then convert it to chosen format // if only audio is recording then convert it to chosen format
else if is_audio_record { else if is_audio_record {
self.progress_widget
.set_progress("Convert Audio to choosen format".to_string(), 5, 7);
Command::new("ffmpeg") Command::new("ffmpeg")
.args([ .args([
"-f", "-f",
@ -385,21 +323,10 @@ impl Ffmpeg {
std::fs::remove_file(audio_filename).unwrap(); std::fs::remove_file(audio_filename).unwrap();
} }
self.progress_widget.set_progress("".to_string(), 6, 7);
// execute command after finish recording // execute command after finish recording
if self.command.text().trim() != "" { if self.command.text().trim() != "" {
self.progress_widget.set_progress(
"execute custom command after finish".to_string(),
5,
6,
);
Exec::shell(self.command.text().trim()).popen().unwrap(); Exec::shell(self.command.text().trim()).popen().unwrap();
} }
self.progress_widget
.set_progress("Finish".to_string(), 7, 7);
self.progress_widget.hide();
} }
pub fn play_record(self) { pub fn play_record(self) {

View File

@ -9,13 +9,13 @@ mod timer;
mod wayland_record; mod wayland_record;
mod utils; mod utils;
use ffmpeg_interface::{Ffmpeg, ProgressWidget}; use ffmpeg_interface::Ffmpeg;
use gettextrs::{bindtextdomain, gettext, setlocale, textdomain, LocaleCategory}; use gettextrs::{bindtextdomain, gettext, setlocale, textdomain, LocaleCategory};
use gtk::glib; use gtk::glib;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{ use gtk::{
AboutDialog, Application, Builder, Button, CheckButton, ComboBoxText, CssProvider, Entry, AboutDialog, Application, Builder, Button, CheckButton, ComboBoxText, CssProvider, Entry,
FileChooserAction, FileChooserNative, Image, Label, MessageDialog, ProgressBar, SpinButton, FileChooserAction, FileChooserNative, Image, Label, SpinButton,
ToggleButton, Window, ToggleButton, Window,
}; };
use utils::is_wayland; use utils::is_wayland;
@ -92,8 +92,6 @@ pub fn build_ui(application: &Application) {
let frames_spin: SpinButton = builder.object("frames").unwrap(); let frames_spin: SpinButton = builder.object("frames").unwrap();
let mouse_switch: CheckButton = builder.object("mouseswitch").unwrap(); let mouse_switch: CheckButton = builder.object("mouseswitch").unwrap();
let play_button: Button = builder.object("playbutton").unwrap(); let play_button: Button = builder.object("playbutton").unwrap();
let progress_dialog: MessageDialog = builder.object("progress_dialog").unwrap();
let progress_bar: ProgressBar = builder.object("progress_bar").unwrap();
let record_button: Button = builder.object("recordbutton").unwrap(); let record_button: Button = builder.object("recordbutton").unwrap();
let record_time_label: Label = builder.object("record_time_label").unwrap(); let record_time_label: Label = builder.object("record_time_label").unwrap();
let screen_grab_button: ToggleButton = builder.object("screen_grab_button").unwrap(); let screen_grab_button: ToggleButton = builder.object("screen_grab_button").unwrap();
@ -472,7 +470,6 @@ pub fn build_ui(application: &Application) {
audio_process: None, audio_process: None,
saved_filename: None, saved_filename: None,
unbound: None, unbound: None,
progress_widget: ProgressWidget::new(progress_dialog, progress_bar),
window: main_window.clone(), window: main_window.clone(),
record_delay: delay_spin, record_delay: delay_spin,
record_wayland: wayland_record, record_wayland: wayland_record,