From 379561117862952d567bfdbf0700b5c7f470a1a8 Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Sun, 20 Feb 2022 12:59:46 +0100 Subject: - Added Preferences - Added idle notify to preferences - Bug fix: if user deleted first task none would show --- src/application.rs | 9 +++- src/database.rs | 2 +- src/furtherance.gresource.xml | 1 + src/gtk/preferences_window.ui | 45 +++++++++++++++++ src/main.rs | 1 + src/meson.build | 3 ++ src/settings_manager.rs | 44 +++++++++++++++++ src/ui.rs | 2 + src/ui/preferences_window.rs | 111 ++++++++++++++++++++++++++++++++++++++++++ src/ui/window.rs | 9 +++- 10 files changed, 223 insertions(+), 4 deletions(-) create mode 100644 src/gtk/preferences_window.ui create mode 100644 src/settings_manager.rs create mode 100644 src/ui/preferences_window.rs (limited to 'src') diff --git a/src/application.rs b/src/application.rs index 6c51523..f8b5527 100644 --- a/src/application.rs +++ b/src/application.rs @@ -20,7 +20,7 @@ use gtk::subclass::prelude::*; use gtk::{gdk, gio, glib}; use crate::config; -use crate::ui::FurtheranceWindow; +use crate::ui::{FurtheranceWindow, FurPreferencesWindow}; use crate::database; mod imp { @@ -96,6 +96,13 @@ impl FurtheranceApplication { })); self.add_action(&quit_action); + let preferences_action = gio::SimpleAction::new("preferences", None); + preferences_action.connect_activate(clone!(@weak self as app => move |_, _| { + FurPreferencesWindow::new().show(); + })); + self.set_accels_for_action("app.preferences", &["comma"]); + self.add_action(&preferences_action); + let about_action = gio::SimpleAction::new("about", None); about_action.connect_activate(clone!(@weak self as app => move |_, _| { app.show_about(); diff --git a/src/database.rs b/src/database.rs index 70e6043..7612643 100644 --- a/src/database.rs +++ b/src/database.rs @@ -149,7 +149,7 @@ pub fn check_for_tasks() -> Result { let conn = Connection::open(get_directory())?; conn.query_row( - "SELECT task_name FROM tasks WHERE id='1'", + "SELECT task_name FROM tasks ORDER BY ROWID ASC LIMIT 1", [], |row| row.get(0), ) diff --git a/src/furtherance.gresource.xml b/src/furtherance.gresource.xml index 0116668..bfab2ff 100644 --- a/src/furtherance.gresource.xml +++ b/src/furtherance.gresource.xml @@ -8,5 +8,6 @@ gtk/tasks_group.ui gtk/task_row.ui gtk/task_details.ui + gtk/preferences_window.ui diff --git a/src/gtk/preferences_window.ui b/src/gtk/preferences_window.ui new file mode 100644 index 0000000..a9866cb --- /dev/null +++ b/src/gtk/preferences_window.ui @@ -0,0 +1,45 @@ + + + + diff --git a/src/main.rs b/src/main.rs index 541e42c..a4959c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ mod application; mod config; mod ui; mod database; +mod settings_manager; use self::application::FurtheranceApplication; diff --git a/src/meson.build b/src/meson.build index 7833e8f..66df479 100644 --- a/src/meson.build +++ b/src/meson.build @@ -31,6 +31,7 @@ run_command( rust_sources = files( 'ui.rs', + 'ui/preferences_window.rs', 'ui/task_details.rs', 'ui/task_row.rs', 'ui/tasks_group.rs', @@ -38,6 +39,8 @@ rust_sources = files( 'ui/history_box.rs', 'ui/window.rs', + 'settings_manager.rs', + 'application.rs', 'config.rs', 'main.rs', diff --git a/src/settings_manager.rs b/src/settings_manager.rs new file mode 100644 index 0000000..0343cdc --- /dev/null +++ b/src/settings_manager.rs @@ -0,0 +1,44 @@ +// Furtherance - Track your time without being tracked +// Copyright (C) 2022 Ricky Kresslein +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gtk::{gio, gio::prelude::*, glib}; +use crate::config; + +pub fn get_settings() -> gio::Settings { + let app_id = config::APP_ID; + gio::Settings::new(app_id) +} + + +pub fn bind_property>(key: &str, object: &P, property: &str) { + let settings = get_settings(); + settings + .bind(key, object, property) + .flags(gio::SettingsBindFlags::DEFAULT) + .build(); +} + +#[allow(dead_code)] +pub fn get_bool(key: &str) -> bool { + let settings = get_settings(); + settings.boolean(key) +} + +#[allow(dead_code)] +pub fn get_int(key: &str) -> i32 { + let settings = get_settings(); + settings.int(key) +} diff --git a/src/ui.rs b/src/ui.rs index e1cf7fe..1a3e3fc 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -20,6 +20,7 @@ mod tasks_page; mod tasks_group; mod task_row; mod task_details; +mod preferences_window; pub use window::FurtheranceWindow; pub use history_box::FurHistoryBox; @@ -27,3 +28,4 @@ pub use tasks_page::FurTasksPage; pub use tasks_group::FurTasksGroup; pub use task_row::FurTaskRow; pub use task_details::FurTaskDetails; +pub use preferences_window::FurPreferencesWindow; diff --git a/src/ui/preferences_window.rs b/src/ui/preferences_window.rs new file mode 100644 index 0000000..e9ef36e --- /dev/null +++ b/src/ui/preferences_window.rs @@ -0,0 +1,111 @@ +// Furtherance - Track your time without being tracked +// Copyright (C) 2022 Ricky Kresslein +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use adw::prelude::*; +use adw::subclass::prelude::*; +use gtk::glib; +use gtk::subclass::prelude::*; +use gtk::CompositeTemplate; + +use crate::settings_manager; +use crate::ui::FurtheranceWindow; + +mod imp { + use super::*; + use glib::subclass; + + #[derive(Default, Debug, CompositeTemplate)] + #[template(resource = "/com/lakoliu/Furtherance/gtk/preferences_window.ui")] + pub struct FurPreferencesWindow { + #[template_child] + pub idle_group: TemplateChild, + #[template_child] + pub notify_of_idle_expander: TemplateChild, + #[template_child] + pub notify_of_idle_spin: TemplateChild, + } + + #[glib::object_subclass] + impl ObjectSubclass for FurPreferencesWindow { + const NAME: &'static str = "FurPreferencesWindow"; + type ParentType = adw::PreferencesWindow; + type Type = super::FurPreferencesWindow; + + fn class_init(klass: &mut Self::Class) { + Self::bind_template(klass); + } + + fn instance_init(obj: &subclass::InitializingObject) { + obj.init_template(); + } + } + + impl ObjectImpl for FurPreferencesWindow { + + fn constructed(&self, obj: &Self::Type) { + let window = FurtheranceWindow::default(); + obj.set_transient_for(Some(&window)); + + obj.setup_signals(); + obj.setup_widgets(); + + self.parent_constructed(obj); + } + } + + impl WidgetImpl for FurPreferencesWindow {} + + impl WindowImpl for FurPreferencesWindow {} + + impl AdwWindowImpl for FurPreferencesWindow {} + + impl PreferencesWindowImpl for FurPreferencesWindow {} +} + +glib::wrapper! { + pub struct FurPreferencesWindow( + ObjectSubclass) + @extends gtk::Widget, gtk::Window, adw::Window, adw::PreferencesWindow; + +} + +impl FurPreferencesWindow { + pub fn new() -> Self { + glib::Object::new::(&[]).unwrap() + } + + fn setup_widgets(&self) { + + } + + fn setup_signals(&self) { + let imp = imp::FurPreferencesWindow::from_instance(self); + + settings_manager::bind_property( + "notify-of-idle", + &*imp.notify_of_idle_expander, + "enable-expansion", + ); + + settings_manager::bind_property( + "idle-time", + &*imp.notify_of_idle_spin, + "value", + ); + } + +} + diff --git a/src/ui/window.rs b/src/ui/window.rs index 965f0f3..3106306 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -30,6 +30,7 @@ use once_cell::unsync::OnceCell; use crate::ui::FurHistoryBox; use crate::FurtheranceApplication; use crate::database; +use crate::settings_manager; mod imp { use super::*; @@ -111,7 +112,9 @@ impl FurtheranceWindow { // Update watch time while timer is running let imp = imp::FurtheranceWindow::from_instance(self); imp.watch.set_text(text); - self.check_user_idle(); + if settings_manager::get_bool("notify-of-idle") { + self.check_user_idle(); + } } fn activate_task_input(&self, sensitive: bool) { @@ -213,7 +216,9 @@ impl FurtheranceWindow { fn setup_settings(&self) { let imp = imp::FurtheranceWindow::from_instance(self); - imp.notify_of_idle.set(300).expect("Failed to set notify_of_idle"); + // Get user setting idle-time in minutes and convert it to seconds + imp.notify_of_idle.set((settings_manager::get_int("idle-time") * 60) as u64) + .expect("Failed to set notify_of_idle"); self.reset_vars(); // Enter starts timer -- cgit 1.4.1