mirror of
https://github.com/xlmnxp/blue-recorder.git
synced 2024-11-23 17:13:11 +03:00
add recording timer
This commit is contained in:
parent
a3dbd2989b
commit
f7c72ff8a5
@ -37,7 +37,6 @@
|
||||
<property name="decorated">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="icon-name">blue-recorder</property>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar" id="headerbar2">
|
||||
<property name="visible">True</property>
|
||||
@ -104,6 +103,7 @@
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkWindow" id="delay_window">
|
||||
<property name="name">delay_window</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="transient-for">main_window</property>
|
||||
<property name="resizable">False</property>
|
||||
@ -132,7 +132,7 @@
|
||||
</object>
|
||||
</child>
|
||||
<child type="bottom">
|
||||
<object class="GtkButton" id="delay_window_stopbutton">
|
||||
<object class="GtkToggleButton" id="delay_window_stopbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
@ -594,6 +594,12 @@
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="record_time_label">
|
||||
<property name="visible">False</property>
|
||||
<property name="can-focus">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="playbutton">
|
||||
<property name="icon_name">media-playback-start</property>
|
||||
|
17
src/main.rs
17
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();
|
||||
|
@ -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;
|
||||
|
40
src/timer.rs
40
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user