Bind switches to keys

This commit is contained in:
Zander Brown 2018-05-21 22:20:57 +01:00 committed by Jordan Petridis
parent 1b623ef346
commit a4a012368e
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 39 additions and 18 deletions

View File

@ -90,7 +90,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch">
<object class="GtkSwitch" id="dark_toggle">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
@ -178,7 +178,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch">
<object class="GtkSwitch" id="startup_toggle">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
@ -221,7 +221,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch">
<object class="GtkSwitch" id="auto_toggle">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
@ -268,7 +268,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkSpinButton">
<object class="GtkSpinButton" id="refresh_value">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="input_purpose">digits</property>
@ -382,7 +382,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkSpinButton">
<object class="GtkSpinButton" id="cleanup_value">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="input_purpose">digits</property>

View File

@ -1,11 +1,14 @@
use gio;
use gio::{Settings, SettingsExt};
use gtk;
use gtk::prelude::*;
#[derive(Debug, Clone)]
// TODO: split this into smaller
pub struct Prefs {
dialog: gtk::Window,
dark_toggle: gtk::Switch,
startup_toggle: gtk::Switch,
auto_toggle: gtk::Switch,
refresh_type: gtk::ComboBox,
cleanup_type: gtk::ComboBox,
}
@ -15,11 +18,17 @@ impl Default for Prefs {
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/prefs.ui");
let dialog = builder.get_object("prefs").unwrap();
let dark_toggle = builder.get_object("dark_toggle").unwrap();
let startup_toggle = builder.get_object("startup_toggle").unwrap();
let auto_toggle = builder.get_object("auto_toggle").unwrap();
let refresh_type = builder.get_object("refresh_type").unwrap();
let cleanup_type = builder.get_object("cleanup_type").unwrap();
Prefs {
dialog,
dark_toggle,
startup_toggle,
auto_toggle,
refresh_type,
cleanup_type,
}
@ -28,19 +37,31 @@ impl Default for Prefs {
// TODO: Refactor components into smaller state machines
impl Prefs {
pub fn new(
settings: &gio::Settings,
) -> Prefs {
pub fn new(settings: &Settings) -> Prefs {
let h = Prefs::default();
h.init(settings);
h
}
pub fn init(
&self,
_settings: &gio::Settings,
) {
println!("TODO");
pub fn init(&self, settings: &Settings) {
settings.bind(
"dark-theme",
&self.dark_toggle,
"active",
gio::SettingsBindFlags::DEFAULT,
);
settings.bind(
"refresh-on-startup",
&self.startup_toggle,
"active",
gio::SettingsBindFlags::DEFAULT,
);
settings.bind(
"refresh-interval",
&self.auto_toggle,
"active",
gio::SettingsBindFlags::DEFAULT,
);
let store = gtk::ListStore::new(&[gtk::Type::String]);
for item in ["Seconds", "Minutes", "Hours", "Days", "Weeks"].iter() {
let row = [&(item) as &ToValue];
@ -49,13 +70,13 @@ impl Prefs {
for combo in [self.refresh_type.clone(), self.cleanup_type.clone()].iter() {
combo.set_model(Some(&store));
let renderer = gtk::CellRendererText::new();
combo.pack_start (&renderer, true);
combo.add_attribute (&renderer, "text", 0);
combo.pack_start(&renderer, true);
combo.add_attribute(&renderer, "text", 0);
}
//settings.get_string("cleanup-age-period").unwrap();
// settings.get_string("cleanup-age-period").unwrap();
}
pub fn show (&self, parent: &gtk::Window) {
pub fn show(&self, parent: &gtk::Window) {
self.dialog.set_transient_for(Some(parent));
self.dialog.set_modal(true);
self.dialog.show_all();