connect switches and save it values

This commit is contained in:
Salem Yaslem 2021-02-05 01:04:18 +03:00
parent c7010a244f
commit ea12bccf80
3 changed files with 28 additions and 5 deletions

View File

@ -1,17 +1,17 @@
extern crate gio; extern crate gio;
extern crate gtk; extern crate gtk;
mod config_management; mod config_management;
mod signal_handle;
use gio::prelude::*; use gio::prelude::*;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::ComboBoxText; use gtk::ComboBoxText;
use gtk::{ use gtk::{
AboutDialog, Adjustment, Builder, Button, CheckButton, ComboBox, Entry, FileChooser, Label, AboutDialog, Adjustment, Builder, Button, CheckButton, Entry, FileChooser, Label, MenuItem,
MenuItem, SpinButton, Window, SpinButton, Window,
}; };
use std::path::Path; use std::path::Path;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
fn main() { fn main() {
if gtk::init().is_err() { if gtk::init().is_err() {
println!("Failed to initialize GTK."); println!("Failed to initialize GTK.");
@ -48,6 +48,7 @@ fn main() {
let mouse_switch: CheckButton = builder.get_object("mouseswitch").unwrap(); let mouse_switch: CheckButton = builder.get_object("mouseswitch").unwrap();
let follow_mouse_switch: CheckButton = builder.get_object("followmouseswitch").unwrap(); let follow_mouse_switch: CheckButton = builder.get_object("followmouseswitch").unwrap();
let about_menu_item: MenuItem = builder.get_object("about_menu_item").unwrap(); let about_menu_item: MenuItem = builder.get_object("about_menu_item").unwrap();
// --- default properties // --- default properties
// Windows // Windows
main_window.set_title("Blue Recorder"); 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("gif"), "GIF (Graphics Interchange Format)");
format_chooser_combobox.append(Some("nut"), "NUT (NUT Recording Format)"); format_chooser_combobox.append(Some("nut"), "NUT (NUT Recording Format)");
format_chooser_combobox.set_active(Some(0)); format_chooser_combobox.set_active(Some(0));
// get audio sources // get audio sources
let sources_descriptions: Vec<String> = { let sources_descriptions: Vec<String> = {
let sources_descriptions = String::from_utf8( let sources_descriptions = String::from_utf8(
@ -111,6 +111,18 @@ fn main() {
audio_switch.set_active(config_management::get_bool("default", "audiocheck")); audio_switch.set_active(config_management::get_bool("default", "audiocheck"));
mouse_switch.set_active(config_management::get_bool("default", "mousecheck")); mouse_switch.set_active(config_management::get_bool("default", "mousecheck"));
follow_mouse_switch.set_active(config_management::get_bool("default", "followmousecheck")); 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 Dialog
about_menu_item.set_label("about"); about_menu_item.set_label("about");
@ -132,6 +144,7 @@ fn main() {
about_dialog.set_artists(&["Mustapha Assabar"]); about_dialog.set_artists(&["Mustapha Assabar"]);
about_dialog.set_website(Some("https://github.com/xlmnxp/blue-recorder/")); about_dialog.set_website(Some("https://github.com/xlmnxp/blue-recorder/"));
about_dialog.set_logo_icon_name(Some("blue-recorder")); about_dialog.set_logo_icon_name(Some("blue-recorder"));
// Buttons // Buttons
window_grab_button.set_label("Select a Window"); window_grab_button.set_label("Select a Window");
area_grab_button.set_label("Select an Area"); area_grab_button.set_label("Select an Area");
@ -158,6 +171,7 @@ fn main() {
// Other // Other
folder_chooser.set_uri(&config_management::get("default", "folder")); folder_chooser.set_uri(&config_management::get("default", "folder"));
// --- connections // --- connections
// show dialog window when about button clicked then hide it after close // show dialog window when about button clicked then hide it after close
{ {

9
src/signal_handle.rs Normal file
View File

@ -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());
}
}

View File

@ -424,7 +424,7 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
<signal name="toggled" handler="followmouseswitchchanged" swapped="no"/> <signal name="toggled" handler="follow_mouse_switch_changed" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>