about summary refs log tree commit diff
path: root/src/ui
diff options
context:
space:
mode:
authorRicky Kresslein <ricky@kressle.in>2022-02-20 12:59:46 +0100
committerRicky Kresslein <ricky@kressle.in>2022-02-20 12:59:46 +0100
commit379561117862952d567bfdbf0700b5c7f470a1a8 (patch)
treee8ff9e5081109c87426eb35c5ade0407e4908419 /src/ui
parent1f46e93625cff30eaf63258fcabe4ddc0c243136 (diff)
downloadFurtherance-379561117862952d567bfdbf0700b5c7f470a1a8.tar.zst
- Added Preferences
- Added idle notify to preferences
- Bug fix: if user deleted first task none would show
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/preferences_window.rs111
-rw-r--r--src/ui/window.rs9
2 files changed, 118 insertions, 2 deletions
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 <rk@lakoliu.com>
+//
+// 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 <https://www.gnu.org/licenses/>.
+
+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<adw::PreferencesGroup>,
+        #[template_child]
+        pub notify_of_idle_expander: TemplateChild<adw::ExpanderRow>,
+        #[template_child]
+        pub notify_of_idle_spin: TemplateChild<gtk::SpinButton>,
+    }
+
+    #[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<Self>) {
+            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<imp::FurPreferencesWindow>)
+        @extends gtk::Widget, gtk::Window, adw::Window, adw::PreferencesWindow;
+
+}
+
+impl FurPreferencesWindow {
+    pub fn new() -> Self {
+        glib::Object::new::<FurPreferencesWindow>(&[]).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