Merge branch 'prefs' into 'master'
Prefrences dialog See merge request World/hammond!34
This commit is contained in:
commit
5fb2cb7e76
@ -21,6 +21,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<attribute name="label" translatable="yes">_Preferences</attribute>
|
<attribute name="label" translatable="yes">_Preferences</attribute>
|
||||||
<attribute name="action">win.preferences</attribute>
|
<attribute name="action">win.preferences</attribute>
|
||||||
|
<attribute name="accel"><primary>e</attribute>
|
||||||
</item>
|
</item>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
|
|||||||
@ -18,6 +18,13 @@
|
|||||||
<property name="title" translatable="yes" context="shortcut window">Check for new episodes</property>
|
<property name="title" translatable="yes" context="shortcut window">Check for new episodes</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="accelerator"><primary>e</property>
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Preferences</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkShortcutsShortcut">
|
<object class="GtkShortcutsShortcut">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|||||||
282
hammond-gtk/resources/gtk/prefs.ui
Normal file
282
hammond-gtk/resources/gtk/prefs.ui
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- 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="GtkWindow" id="prefs">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="title" translatable="yes">Preferences</property>
|
||||||
|
<property name="type_hint">dialog</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">2</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScrolledWindow">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="min_content_width">480</property>
|
||||||
|
<property name="min_content_height">200</property>
|
||||||
|
<property name="propagate_natural_width">True</property>
|
||||||
|
<property name="propagate_natural_height">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkViewport">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="shadow_type">none</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="halign">center</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="halign">start</property>
|
||||||
|
<property name="margin_top">10</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
|
<property name="label" translatable="yes">Appearance</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkFrame">
|
||||||
|
<property name="width_request">450</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label_xalign">0</property>
|
||||||
|
<property name="shadow_type">in</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkAlignment">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkListBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="selection_mode">none</property>
|
||||||
|
<property name="activate_on_single_click">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkListBoxRow">
|
||||||
|
<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>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<property name="margin_top">5</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Dark Theme</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSwitch" id="dark_toggle">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">False</property>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child type="label_item">
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="halign">start</property>
|
||||||
|
<property name="margin_top">20</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
|
<property name="label" translatable="yes">Delete played episodes</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkFrame">
|
||||||
|
<property name="width_request">300</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label_xalign">0</property>
|
||||||
|
<property name="shadow_type">in</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkAlignment">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkListBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="selection_mode">none</property>
|
||||||
|
<property name="activate_on_single_click">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkListBoxRow">
|
||||||
|
<property name="width_request">100</property>
|
||||||
|
<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>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<property name="margin_top">5</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">After</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSpinButton" id="cleanup_value">
|
||||||
|
<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>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkComboBox" id="cleanup_type">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<style>
|
||||||
|
<class name="linked"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child type="label_item">
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">3</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child type="titlebar">
|
||||||
|
<object class="GtkHeaderBar">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="title">Prefrences</property>
|
||||||
|
<property name="show_close_button">True</property>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</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>
|
||||||
|
</interface>
|
||||||
@ -17,6 +17,7 @@
|
|||||||
<file compressed="true" preprocess="xml-stripblanks">gtk/player_toolbar.ui</file>
|
<file compressed="true" preprocess="xml-stripblanks">gtk/player_toolbar.ui</file>
|
||||||
<file compressed="true" preprocess="xml-stripblanks">icons/skip-back-symbolic.svg</file>
|
<file compressed="true" preprocess="xml-stripblanks">icons/skip-back-symbolic.svg</file>
|
||||||
<file compressed="true" preprocess="xml-stripblanks">icons/skip-forward-symbolic.svg</file>
|
<file compressed="true" preprocess="xml-stripblanks">icons/skip-forward-symbolic.svg</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/prefs.ui</file>
|
||||||
<file compressed="true">gtk/style.css</file>
|
<file compressed="true">gtk/style.css</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
@ -1,19 +1,16 @@
|
|||||||
#![allow(new_without_default)]
|
#![allow(new_without_default)]
|
||||||
|
|
||||||
use gio::{
|
use gio::{self, prelude::*, ApplicationFlags, SettingsBindFlags, SettingsExt, SimpleAction};
|
||||||
self, ActionMapExt, ApplicationExt, ApplicationExtManual, ApplicationFlags, SettingsExt,
|
|
||||||
SimpleAction, SimpleActionExt,
|
|
||||||
};
|
|
||||||
use glib;
|
use glib;
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::SettingsExt as GtkSettingsExt;
|
|
||||||
|
|
||||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||||
use hammond_data::Show;
|
use hammond_data::Show;
|
||||||
use send_cell::SendCell;
|
use send_cell::SendCell;
|
||||||
|
|
||||||
use headerbar::Header;
|
use headerbar::Header;
|
||||||
|
use prefs::Prefs;
|
||||||
use settings::{self, WindowGeometry};
|
use settings::{self, WindowGeometry};
|
||||||
use stacks::{Content, PopulatedState};
|
use stacks::{Content, PopulatedState};
|
||||||
use utils;
|
use utils;
|
||||||
@ -149,9 +146,12 @@ impl App {
|
|||||||
|
|
||||||
fn setup_dark_theme(&self) {
|
fn setup_dark_theme(&self) {
|
||||||
let gtk_settings = gtk::Settings::get_default().unwrap();
|
let gtk_settings = gtk::Settings::get_default().unwrap();
|
||||||
let enabled = self.settings.get_boolean("dark-theme");
|
self.settings.bind(
|
||||||
|
"dark-theme",
|
||||||
gtk_settings.set_property_gtk_application_prefer_dark_theme(enabled);
|
>k_settings,
|
||||||
|
"gtk-application-prefer-dark-theme",
|
||||||
|
SettingsBindFlags::DEFAULT,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_refresh_on_startup(&self) {
|
fn setup_refresh_on_startup(&self) {
|
||||||
@ -186,6 +186,7 @@ impl App {
|
|||||||
let win = &self.window;
|
let win = &self.window;
|
||||||
let instance = &self.instance;
|
let instance = &self.instance;
|
||||||
let header = &self.headerbar;
|
let header = &self.headerbar;
|
||||||
|
let settings = &self.settings;
|
||||||
|
|
||||||
// Create the `refresh` action.
|
// Create the `refresh` action.
|
||||||
//
|
//
|
||||||
@ -211,6 +212,16 @@ impl App {
|
|||||||
action!(win, "quit", clone!(instance => move |_, _| instance.quit()));
|
action!(win, "quit", clone!(instance => move |_, _| instance.quit()));
|
||||||
self.instance.set_accels_for_action("win.quit", &["<primary>q"]);
|
self.instance.set_accels_for_action("win.quit", &["<primary>q"]);
|
||||||
|
|
||||||
|
action!(
|
||||||
|
win,
|
||||||
|
"preferences",
|
||||||
|
clone!(win, settings => move |_, _| {
|
||||||
|
let dialog = Prefs::new(&settings);
|
||||||
|
dialog.show(&win);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
self.instance.set_accels_for_action("win.preferences", &["<primary>e"]);
|
||||||
|
|
||||||
// Create the menu action
|
// Create the menu action
|
||||||
action!(win, "menu",clone!(header => move |_, _| header.open_menu()));
|
action!(win, "menu",clone!(header => move |_, _| header.open_menu()));
|
||||||
// Bind the hamburger menu button to `F10`
|
// Bind the hamburger menu button to `F10`
|
||||||
|
|||||||
@ -101,6 +101,7 @@ mod widgets;
|
|||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod headerbar;
|
mod headerbar;
|
||||||
|
mod prefs;
|
||||||
|
|
||||||
mod manager;
|
mod manager;
|
||||||
mod settings;
|
mod settings;
|
||||||
|
|||||||
84
hammond-gtk/src/prefs.rs
Normal file
84
hammond-gtk/src/prefs.rs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
use gio;
|
||||||
|
use gio::{Settings, SettingsExt};
|
||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Prefs {
|
||||||
|
dialog: gtk::Window,
|
||||||
|
dark_toggle: gtk::Switch,
|
||||||
|
cleanup_value: gtk::SpinButton,
|
||||||
|
cleanup_type: gtk::ComboBox,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Prefs {
|
||||||
|
fn default() -> 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 cleanup_value = builder.get_object("cleanup_value").unwrap();
|
||||||
|
let cleanup_type = builder.get_object("cleanup_type").unwrap();
|
||||||
|
|
||||||
|
Prefs {
|
||||||
|
dialog,
|
||||||
|
dark_toggle,
|
||||||
|
cleanup_value,
|
||||||
|
cleanup_type,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Refactor components into smaller state machines
|
||||||
|
impl Prefs {
|
||||||
|
pub fn new(settings: &Settings) -> Prefs {
|
||||||
|
let h = Prefs::default();
|
||||||
|
h.init(settings);
|
||||||
|
h
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(&self, settings: &Settings) {
|
||||||
|
settings.bind(
|
||||||
|
"dark-theme",
|
||||||
|
&self.dark_toggle,
|
||||||
|
"active",
|
||||||
|
gio::SettingsBindFlags::DEFAULT,
|
||||||
|
);
|
||||||
|
settings.bind(
|
||||||
|
"cleanup-age-time",
|
||||||
|
&self.cleanup_value,
|
||||||
|
"value",
|
||||||
|
gio::SettingsBindFlags::DEFAULT,
|
||||||
|
);
|
||||||
|
let cleanup_p = settings.get_string("cleanup-age-period").unwrap();
|
||||||
|
let mut cleanup_pos = 0;
|
||||||
|
let store = gtk::ListStore::new(&[gtk::Type::String]);
|
||||||
|
for (i, item) in ["Seconds", "Minutes", "Hours", "Days", "Weeks"]
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
|
let row: &[&ToValue] = &[item];
|
||||||
|
if item.to_lowercase() == cleanup_p {
|
||||||
|
cleanup_pos = i as i32;
|
||||||
|
}
|
||||||
|
store.insert_with_values(None, &[0], &row);
|
||||||
|
}
|
||||||
|
self.cleanup_type.set_model(Some(&store));
|
||||||
|
let renderer = gtk::CellRendererText::new();
|
||||||
|
self.cleanup_type.pack_start(&renderer, true);
|
||||||
|
self.cleanup_type.add_attribute(&renderer, "text", 0);
|
||||||
|
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: >k::ApplicationWindow) {
|
||||||
|
self.dialog.set_transient_for(Some(parent));
|
||||||
|
self.dialog.set_modal(true);
|
||||||
|
self.dialog.show_all();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user