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/ui/preferences_window.rs | 111 +++++++++++++++++++++++++++++++++++++++++++ src/ui/window.rs | 9 +++- 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/ui/preferences_window.rs (limited to 'src/ui') 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