From ea12bccf804303d0b99fa24b0ccceef5268b5938 Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Fri, 5 Feb 2021 01:04:18 +0300 Subject: [PATCH] connect switches and save it values --- src/main.rs | 22 ++++++++++++++++++---- src/signal_handle.rs | 9 +++++++++ windows/ui.glade | 2 +- 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/signal_handle.rs diff --git a/src/main.rs b/src/main.rs index 25bbbae..e79878c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,17 @@ extern crate gio; extern crate gtk; mod config_management; +mod signal_handle; use gio::prelude::*; use gtk::prelude::*; use gtk::ComboBoxText; use gtk::{ - AboutDialog, Adjustment, Builder, Button, CheckButton, ComboBox, Entry, FileChooser, Label, - MenuItem, SpinButton, Window, + AboutDialog, Adjustment, Builder, Button, CheckButton, Entry, FileChooser, Label, MenuItem, + SpinButton, Window, }; use std::path::Path; use std::process::{Command, Stdio}; - fn main() { if gtk::init().is_err() { println!("Failed to initialize GTK."); @@ -48,6 +48,7 @@ fn main() { let mouse_switch: CheckButton = builder.get_object("mouseswitch").unwrap(); let follow_mouse_switch: CheckButton = builder.get_object("followmouseswitch").unwrap(); let about_menu_item: MenuItem = builder.get_object("about_menu_item").unwrap(); + // --- default properties // Windows main_window.set_title("Blue Recorder"); @@ -65,7 +66,6 @@ fn main() { format_chooser_combobox.append(Some("gif"), "GIF (Graphics Interchange Format)"); format_chooser_combobox.append(Some("nut"), "NUT (NUT Recording Format)"); format_chooser_combobox.set_active(Some(0)); - // get audio sources let sources_descriptions: Vec = { let sources_descriptions = String::from_utf8( @@ -111,6 +111,18 @@ fn main() { audio_switch.set_active(config_management::get_bool("default", "audiocheck")); mouse_switch.set_active(config_management::get_bool("default", "mousecheck")); follow_mouse_switch.set_active(config_management::get_bool("default", "followmousecheck")); + video_switch.connect_toggled(|switch: &CheckButton| { + config_management::set_bool("default", "videocheck", switch.get_active()); + }); + audio_switch.connect_toggled(|switch: &CheckButton| { + config_management::set_bool("default", "audiocheck", switch.get_active()); + }); + mouse_switch.connect_toggled(|switch: &CheckButton| { + config_management::set_bool("default", "mousecheck", switch.get_active()); + }); + follow_mouse_switch.connect_toggled(|switch: &CheckButton| { + config_management::set_bool("default", "followmousecheck", switch.get_active()); + }); // About Dialog about_menu_item.set_label("about"); @@ -132,6 +144,7 @@ fn main() { about_dialog.set_artists(&["Mustapha Assabar"]); about_dialog.set_website(Some("https://github.com/xlmnxp/blue-recorder/")); about_dialog.set_logo_icon_name(Some("blue-recorder")); + // Buttons window_grab_button.set_label("Select a Window"); area_grab_button.set_label("Select an Area"); @@ -158,6 +171,7 @@ fn main() { // Other folder_chooser.set_uri(&config_management::get("default", "folder")); + // --- connections // show dialog window when about button clicked then hide it after close { diff --git a/src/signal_handle.rs b/src/signal_handle.rs new file mode 100644 index 0000000..1bd155d --- /dev/null +++ b/src/signal_handle.rs @@ -0,0 +1,9 @@ +use gtk::{CheckButton, ToggleButtonExt}; +use crate::config_management; + +pub struct SignalHandle {} +impl SignalHandle { + pub fn follow_mouse_switch_changed(self, switch: CheckButton) { + config_management::set_bool("default", "mousecheck", switch.get_active()); + } +} \ No newline at end of file diff --git a/windows/ui.glade b/windows/ui.glade index 4f9f2b0..09c86bf 100644 --- a/windows/ui.glade +++ b/windows/ui.glade @@ -424,7 +424,7 @@ True False True - + 1