Bind refresh/cleanup rate

This commit is contained in:
Zander Brown 2018-05-21 23:26:13 +01:00 committed by Jordan Petridis
parent a4a012368e
commit ef2286dca4
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
4 changed files with 77 additions and 4 deletions

View File

@ -21,7 +21,7 @@
<item>
<attribute name="label" translatable="yes">_Preferences</attribute>
<attribute name="action">app.preferences</attribute>
<attribute name="accel">&lt;primary&gt;,</attribute>
<attribute name="accel">&lt;primary&gt;e</attribute>
</item>
</section>
<section>

View File

@ -21,7 +21,7 @@
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="accelerator">&lt;primary&gt;,</property>
<property name="accelerator">&lt;primary&gt;e</property>
<property name="title" translatable="yes" context="shortcut window">Preferences</property>
</object>
</child>

View File

@ -2,6 +2,20 @@
<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="cleanup_value_adj">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="refresh_value_adj">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkWindow" id="prefs">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Preferences</property>
@ -69,6 +83,8 @@
<property name="height_request">50</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -157,6 +173,8 @@
<property name="height_request">50</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -200,6 +218,8 @@
<property name="height_request">50</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -243,6 +263,8 @@
<property name="height_request">50</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -272,6 +294,9 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="input_purpose">digits</property>
<property name="adjustment">refresh_value_adj</property>
<property name="climb_rate">1</property>
<property name="value">1</property>
</object>
<packing>
<property name="expand">False</property>
@ -357,6 +382,8 @@
<property name="height_request">50</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -386,6 +413,9 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="input_purpose">digits</property>
<property name="adjustment">cleanup_value_adj</property>
<property name="climb_rate">1</property>
<property name="value">1</property>
</object>
<packing>
<property name="expand">False</property>
@ -446,7 +476,7 @@
</child>
</object>
</child>
<child>
<child type="titlebar">
<placeholder/>
</child>
</object>

View File

@ -9,7 +9,9 @@ pub struct Prefs {
dark_toggle: gtk::Switch,
startup_toggle: gtk::Switch,
auto_toggle: gtk::Switch,
refresh_value: gtk::SpinButton,
refresh_type: gtk::ComboBox,
cleanup_value: gtk::SpinButton,
cleanup_type: gtk::ComboBox,
}
@ -21,7 +23,9 @@ impl Default for Prefs {
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_value = builder.get_object("refresh_value").unwrap();
let refresh_type = builder.get_object("refresh_type").unwrap();
let cleanup_value = builder.get_object("cleanup_value").unwrap();
let cleanup_type = builder.get_object("cleanup_type").unwrap();
Prefs {
@ -29,7 +33,9 @@ impl Default for Prefs {
dark_toggle,
startup_toggle,
auto_toggle,
refresh_value,
refresh_type,
cleanup_value,
cleanup_type,
}
}
@ -62,10 +68,34 @@ impl Prefs {
"active",
gio::SettingsBindFlags::DEFAULT,
);
settings.bind(
"refresh-interval-time",
&self.refresh_value,
"value",
gio::SettingsBindFlags::DEFAULT,
);
settings.bind(
"cleanup-age-time",
&self.cleanup_value,
"value",
gio::SettingsBindFlags::DEFAULT,
);
let refresh_p = settings.get_string("refresh-interval-period").unwrap();
let mut refresh_pos = 0;
let cleanup_p = settings.get_string("cleanup-age-period").unwrap();
let mut cleanup_pos = 0;
let store = gtk::ListStore::new(&[gtk::Type::String]);
let mut i = 0;
for item in ["Seconds", "Minutes", "Hours", "Days", "Weeks"].iter() {
let row = [&(item) as &ToValue];
if item.to_lowercase() == refresh_p {
refresh_pos = i;
}
if item.to_lowercase() == cleanup_p {
cleanup_pos = i;
}
store.insert_with_values(None, &[0], &row);
i += 1 ;
}
for combo in [self.refresh_type.clone(), self.cleanup_type.clone()].iter() {
combo.set_model(Some(&store));
@ -73,7 +103,20 @@ impl Prefs {
combo.pack_start(&renderer, true);
combo.add_attribute(&renderer, "text", 0);
}
// settings.get_string("cleanup-age-period").unwrap();
self.refresh_type.set_active(refresh_pos);
self.refresh_type
.connect_changed(clone!(settings, store => move |combo| {
let value = store.get_value(&combo.get_active_iter().unwrap(), 0);
let value: &str = value.get().unwrap();
settings.set_string("refresh-interval-period", &value.to_lowercase());
}));
self.cleanup_type.set_active(cleanup_pos);
self.cleanup_type
.connect_changed(clone!(settings, store => move |combo| {
let value = store.get_value(&combo.get_active_iter().unwrap(), 0);
let value: &str = value.get().unwrap();
settings.set_string("cleanup-age-period", &value.to_lowercase());
}));
}
pub fn show(&self, parent: &gtk::Window) {