From f7c72ff8a59b8284636efe87752bc05a90749085 Mon Sep 17 00:00:00 2001
From: ochibani <11yzyv86j@relay.firefox.com>
Date: Wed, 2 Nov 2022 14:09:33 +0200
Subject: [PATCH] add recording timer
---
interfaces/main.ui | 10 ++++++++--
src/main.rs | 17 ++++++++++++++---
src/styles/global.css | 3 +++
src/timer.rs | 40 +++++++++++++++++++++++++++++++++-------
4 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/interfaces/main.ui b/interfaces/main.ui
index 1be6b15..11dee5d 100644
--- a/interfaces/main.ui
+++ b/interfaces/main.ui
@@ -37,7 +37,6 @@
False
True
True
- blue-recorder
-
+
+
+ False
+ True
+
+
media-playback-start
diff --git a/src/main.rs b/src/main.rs
index 5a9daf4..e282591 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,7 +17,7 @@ use std::ops::Add;
use std::path::Path;
use std::process::{Command, Stdio};
use std::rc::Rc;
-use timer::{recording_delay};
+use timer::{recording_delay, start_timer, stop_timer};
fn main() {
// Create new application
@@ -75,7 +75,7 @@ pub fn build_ui(application: &Application) {
let delay_spin: SpinButton = builder.object("delay").unwrap();
let delay_window: Window = builder.object("delay_window").unwrap();
let delay_window_label: Label = builder.object("delay_window_label").unwrap();
- let delay_window_button: Button = builder.object("delay_window_stopbutton").unwrap();
+ let delay_window_button: ToggleButton = builder.object("delay_window_stopbutton").unwrap();
let filename_entry: Entry = builder.object("filename").unwrap();
let folder_chooser_button: Button = builder.object("folder_chooser").unwrap();
let folder_chooser_image: Image = builder.object("folder_chooser_image").unwrap();
@@ -91,6 +91,7 @@ pub fn build_ui(application: &Application) {
let progress_dialog: MessageDialog = builder.object("progress_dialog").unwrap();
let progressbar: ProgressBar = builder.object("progressbar").unwrap();
let record_button: Button = builder.object("recordbutton").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_icon: Image = builder.object("screen_grab_icon").unwrap();
let stop_button: Button = builder.object("stopbutton").unwrap();
@@ -404,12 +405,16 @@ pub fn build_ui(application: &Application) {
}));
let _delay_window = delay_window.clone();
+ let _delay_window_button = delay_window_button.clone();
let mut _ffmpeg_record_interface = ffmpeg_record_interface.clone();
+ let _play_button = play_button.clone();
let _record_button = record_button.clone();
+ let _record_time_label = record_time_label.clone();
let _stop_button = stop_button.clone();
record_button.connect_clicked(move |_| {
+ _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_label.clone(), _record_button.clone());
+ recording_delay(delay_spin.clone(), delay_spin.value()as u64, delay_window.clone(), _delay_window_button.clone(), delay_window_label.clone(), _record_button.clone());
}
if delay_spin.value()as u64 == 0 {
let _area_capture = area_capture.borrow_mut();
@@ -423,6 +428,9 @@ pub fn build_ui(application: &Application) {
// Do nothing if the start_record function return nothing
}
_ => {
+ start_timer(record_time_label.clone());
+ record_time_label.set_visible(true);
+ _play_button.hide();
_record_button.hide();
_stop_button.show();
}
@@ -430,6 +438,7 @@ pub fn build_ui(application: &Application) {
}
});
+ let _delay_window_button = delay_window_button.clone();
delay_window_button.connect_clicked(move |_| {
});
@@ -437,6 +446,8 @@ pub fn build_ui(application: &Application) {
let _play_button = play_button.clone();
let _stop_button = stop_button.clone();
stop_button.connect_clicked(move |_| {
+ _record_time_label.set_visible(false);
+ stop_timer(_record_time_label.clone());
_ffmpeg_record_interface.borrow_mut().clone().stop_record();
record_button.show();
_stop_button.hide();
diff --git a/src/styles/global.css b/src/styles/global.css
index a3177b6..bd66879 100644
--- a/src/styles/global.css
+++ b/src/styles/global.css
@@ -23,6 +23,9 @@
background: @theme_selected_bg_color;
}
+#delay_window {
+ border: 3px solid @theme_selected_bg_color;
+}
#delay_window_label{
font-size: 350%;
font-weight: 250;
diff --git a/src/timer.rs b/src/timer.rs
index f25000d..3e77fd9 100644
--- a/src/timer.rs
+++ b/src/timer.rs
@@ -1,19 +1,24 @@
extern crate secfmt;
use gtk::glib;
-use gtk::{Button, Label, SpinButton, Window};
+use gtk::{Button, ToggleButton, Label, SpinButton, Window};
use gtk::prelude::*;
-pub fn recording_delay(delay_spin: SpinButton, mut delay_time: u64, delay_window: Window, delay_window_label: Label, record_button: Button) {
+pub fn recording_delay(delay_spin: SpinButton, mut delay_time: u64, delay_window: Window, delay_window_button: ToggleButton, delay_window_label: Label, record_button: Button) {
// Keep time label alive and update every 1sec
let default_value = delay_time;
- let capture_label = move || {
+ let capture_delay_label = move || {
// Show delay window if delay time is not zero
delay_window.show();
- if delay_time > 0 {
+ if delay_time > 0 {
delay_window_label.set_text(¤t_time(delay_time));
delay_time -= 1;
- glib::source::Continue(true)
+ if delay_window_button.is_active() {
+ delay_window.hide();
+ glib::source::Continue(false)
+ } else {
+ glib::source::Continue(true)
+ }
} else {
// Hide delay window and start recording
delay_window.hide();
@@ -25,10 +30,31 @@ pub fn recording_delay(delay_spin: SpinButton, mut delay_time: u64, delay_window
}
};
// Execute capture_label every 1sec
- glib::source::timeout_add_seconds_local(1, capture_label);
+ glib::source::timeout_add_seconds_local(1, capture_delay_label);
}
+pub fn start_timer(record_time_label: Label) {
+ let mut start_time = 0;
+ let capture_record_label = move || {
+ if record_time_label.is_visible() {
+ record_time_label.set_text(¤t_time(start_time));
+ start_time += 1;
+ glib::source::Continue(true)
+ } else {
+ glib::source::Continue(false)
+ }
+ };
+ // Execute capture_label every 1sec
+ glib::source::timeout_add_seconds_local(1, capture_record_label);
+}
+
+pub fn stop_timer(record_time_label: Label) {
+ let stop_time = 0;
+ record_time_label.set_text(¤t_time(stop_time));
+}
+
+
fn current_time(delay_time: u64) -> String {
let delay = secfmt::from(delay_time);
- format!("{}:{}", delay.minutes, delay.seconds)
+ format!("{:02}:{:02}", delay.minutes, delay.seconds)
}