about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/application.rs9
-rw-r--r--src/database.rs2
-rw-r--r--src/furtherance.gresource.xml1
-rw-r--r--src/gtk/preferences_window.ui45
-rw-r--r--src/main.rs1
-rw-r--r--src/meson.build3
-rw-r--r--src/settings_manager.rs44
-rw-r--r--src/ui.rs2
-rw-r--r--src/ui/preferences_window.rs111
-rw-r--r--src/ui/window.rs9
10 files changed, 223 insertions, 4 deletions
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", &["<primary>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<String> {
     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 @@
     <file>gtk/tasks_group.ui</file>
     <file>gtk/task_row.ui</file>
     <file>gtk/task_details.ui</file>
+    <file>gtk/preferences_window.ui</file>
   </gresource>
 </gresources>
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="FurPreferencesWindow" parent="AdwPreferencesWindow">
+    <child>
+      <object class="AdwPreferencesPage">
+        <property name="icon_name">emblem-system-symbolic</property>
+        <property name="title" translatable="yes">General</property>
+        <child>
+          <object class="AdwPreferencesGroup" id="idle_group">
+            <property name="title" translatable="yes">Idle</property>
+            <property name="visible">True</property>
+            <child>
+              <object class="AdwExpanderRow" id="notify_of_idle_expander">
+                <property name="title" translatable="yes">Notify of Idle</property>
+                <property name="show_enable_switch">True</property>
+                <property name="use_underline">True</property>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="yes">_Minutes to Idle</property>
+                    <property name="subtitle" translatable="yes">Number of miniutes before the user is considered idle</property>
+                    <property name="use_underline">True</property>
+                    <child>
+                      <object class="GtkSpinButton" id="notify_of_idle_spin">
+                        <property name="valign">center</property>
+                        <property name="adjustment">
+                          <object class="GtkAdjustment">
+                            <property name="upper">60</property>
+                            <property name="lower">1</property>
+                            <property name="step_increment">1</property>
+                            <property name="page_increment">10</property>
+                          </object>
+                        </property>
+                        <property name="numeric">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
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 <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 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<P: IsA<glib::Object>>(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 <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