diff options
author | Ricky Kresslein <rk@lakoliu.com> | 2023-06-03 15:48:46 +0200 |
---|---|---|
committer | Ricky Kresslein <rk@lakoliu.com> | 2023-06-03 15:48:46 +0200 |
commit | 3cbbabd4aa35342b36dce327794149f0c5704508 (patch) | |
tree | 3d128ef166b2aabfedffbc7a7ac7a26c3f854d10 | |
parent | 432362b9c3c028d7525fec0bdfbd3660355ea894 (diff) | |
download | Furtherance-3cbbabd4aa35342b36dce327794149f0c5704508.tar.zst |
#99: Inclusive total time
-rw-r--r-- | data/com.lakoliu.Furtherance.gschema.xml | 3 | ||||
-rw-r--r-- | src/gtk/preferences_window.ui | 15 | ||||
-rw-r--r-- | src/gtk/tasks_page.ui | 3 | ||||
-rw-r--r-- | src/ui/history_box.rs | 10 | ||||
-rw-r--r-- | src/ui/preferences_window.rs | 10 | ||||
-rw-r--r-- | src/ui/tasks_page.rs | 37 | ||||
-rw-r--r-- | src/ui/window.rs | 26 |
7 files changed, 99 insertions, 5 deletions
diff --git a/data/com.lakoliu.Furtherance.gschema.xml b/data/com.lakoliu.Furtherance.gschema.xml index 615a6cf..fd96c00 100644 --- a/data/com.lakoliu.Furtherance.gschema.xml +++ b/data/com.lakoliu.Furtherance.gschema.xml @@ -40,6 +40,9 @@ <key name="autosave-time" type="i"> <default>5</default> </key> + <key name="inclusive-total" type="b"> + <default>false</default> + </key> <key name="database-loc" type="s"> <default>"default"</default> </key> diff --git a/src/gtk/preferences_window.ui b/src/gtk/preferences_window.ui index 168d614..3b862c0 100644 --- a/src/gtk/preferences_window.ui +++ b/src/gtk/preferences_window.ui @@ -204,6 +204,21 @@ </child> </object> </child> + + <child> + <object class="AdwActionRow"> + <property name="title" translatable="yes">Inclusive total time</property> + <property name="use_underline">True</property> + <property name="activatable_widget">inclusive_total_switch</property> + <property name="subtitle" translatable="yes">Today's total time includes the ongoing timer</property> + <child> + <object class="GtkSwitch" id="inclusive_total_switch"> + <property name="valign">center</property> + </object> + </child> + </object> + </child> + </object> </child> <child> diff --git a/src/gtk/tasks_page.ui b/src/gtk/tasks_page.ui index dcd6513..6db6f92 100644 --- a/src/gtk/tasks_page.ui +++ b/src/gtk/tasks_page.ui @@ -1,5 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <interface> <template class="FurTasksPage" parent="AdwPreferencesPage"> + <style> + <class name="numeric"/> + </style> </template> </interface> diff --git a/src/ui/history_box.rs b/src/ui/history_box.rs index 8590bd0..28ae699 100644 --- a/src/ui/history_box.rs +++ b/src/ui/history_box.rs @@ -133,6 +133,16 @@ impl FurHistoryBox { } } + pub fn set_todays_time(&self, added_time: i32) { + let imp = imp::FurHistoryBox::from_obj(self); + imp.tasks_page.add_to_todays_time(added_time); + } + + pub fn set_todays_stored_secs(&self, new_time: i32) { + let imp = imp::FurHistoryBox::from_obj(self); + imp.tasks_page.set_todays_stored_secs(new_time) + } + pub fn empty_view(&self) { self.set_view(View::Empty); let window = FurtheranceWindow::default(); diff --git a/src/ui/preferences_window.rs b/src/ui/preferences_window.rs index c7f6344..bd135de 100644 --- a/src/ui/preferences_window.rs +++ b/src/ui/preferences_window.rs @@ -73,6 +73,9 @@ mod imp { pub autosave_spin: TemplateChild<gtk::SpinButton>, #[template_child] + pub inclusive_total_switch: TemplateChild<gtk::Switch>, + + #[template_child] pub database_loc_row: TemplateChild<adw::ActionRow>, #[template_child] pub database_browse_btn: TemplateChild<gtk::Button>, @@ -181,6 +184,8 @@ impl FurPreferencesWindow { settings_manager::bind_property("autosave-time", &*imp.autosave_spin, "value"); + settings_manager::bind_property("inclusive-total", &*imp.inclusive_total_switch, "active"); + imp.dark_theme_switch.connect_active_notify(move |_| { let app = FurtheranceApplication::default(); app.update_light_dark(); @@ -224,6 +229,11 @@ impl FurPreferencesWindow { window.refresh_timer(); }); + imp.inclusive_total_switch.connect_active_notify(move |_| { + let window = FurtheranceWindow::default(); + window.reset_history_box(); + }); + imp.database_browse_btn.connect_clicked(clone!(@weak self as this => move |_| { let window = FurtheranceApplication::default().active_window().unwrap(); let dialog = gtk::FileChooserDialog::new( diff --git a/src/ui/tasks_page.rs b/src/ui/tasks_page.rs index 4fddb22..ffe73a7 100644 --- a/src/ui/tasks_page.rs +++ b/src/ui/tasks_page.rs @@ -21,6 +21,7 @@ use chrono_locale::LocaleDate; use gettextrs::*; use gtk::glib; use std::env; +use std::sync::Mutex; use crate::database::{self, SortOrder, TaskSort}; use crate::settings_manager; @@ -36,6 +37,7 @@ mod imp { #[template(resource = "/com/lakoliu/Furtherance/gtk/tasks_page.ui")] pub struct FurTasksPage { pub all_groups: RefCell<Vec<FurTasksGroup>>, + pub today_stored_secs: Mutex<i32>, } #[glib::object_subclass] @@ -76,6 +78,35 @@ impl FurTasksPage { self.build_task_list(); } + pub fn add_to_todays_time(&self, added_time: i32) { + let imp = imp::FurTasksPage::from_obj(&self); + if imp.all_groups.borrow().len() > 0 { + let today_group = imp.all_groups.borrow()[0].clone(); + if today_group.title() == "Today" { + // Add the time to the thing here + let new_total_time = added_time + *imp.today_stored_secs.lock().unwrap(); + + let h = new_total_time / 3600; + let m = new_total_time % 3600 / 60; + let s = new_total_time % 60; + + let mut total_time_str = format!("{:02}:{:02}:{:02}", h, m, s); + if !settings_manager::get_bool("show-seconds") { + total_time_str = format!("{:02}:{:02}", h, m); + } + + let total_time_label = gtk::Label::new(Some(&total_time_str)); + today_group.set_header_suffix(Some(&total_time_label)); + } + } + } + + pub fn set_todays_stored_secs(&self, new_time: i32) { + let imp = imp::FurTasksPage::from_obj(&self); + let old_time = *imp.today_stored_secs.lock().unwrap(); + *imp.today_stored_secs.lock().unwrap() = old_time + new_time; + } + pub fn clear_task_list(&self) { let imp = imp::FurTasksPage::from_obj(&self); @@ -84,6 +115,7 @@ impl FurTasksPage { } imp.all_groups.borrow_mut().clear(); + *imp.today_stored_secs.lock().unwrap() = 0; } pub fn build_task_list(&self) { @@ -166,10 +198,15 @@ impl FurTasksPage { // Set total time for each day if settings_manager::get_bool("show-daily-sums") { let day_total_time = group.get_total_day_time(); + if uniq_date_list[i] == today { + *imp.today_stored_secs.lock().unwrap() = day_total_time as i32; + } + // Format total time to readable string let h = day_total_time / 3600; let m = day_total_time % 3600 / 60; let s = day_total_time % 60; + let mut total_time_str = format!("{:02}:{:02}:{:02}", h, m, s); if !settings_manager::get_bool("show-seconds") { total_time_str = format!("{:02}:{:02}", h, m); diff --git a/src/ui/window.rs b/src/ui/window.rs index 173d953..2270711 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -213,6 +213,7 @@ impl FurtheranceWindow { if settings_manager::get_bool("pomodoro") && !*imp2.pomodoro_continue.lock().unwrap() { let pomodoro_time = settings_manager::get_int("pomodoro-time"); let mut secs: i32 = 0; + let mut secs_only: i32 = 0; let mut mins: i32 = pomodoro_time; let mut hrs: i32 = mins / 60; mins %= 60; @@ -236,6 +237,11 @@ impl FurtheranceWindow { } let watch_text: &str = &format!("{:02}:{:02}:{:02}", hrs, mins, secs).to_string(); this_clone.set_watch_time(watch_text); + + if settings_manager::get_bool("inclusive-total") { + secs_only += 1; + imp3.history_box.set_todays_time(secs_only); + } } if settings_manager::get_bool("autosave") { let autosave_mins = settings_manager::get_int("autosave-time"); @@ -252,21 +258,26 @@ impl FurtheranceWindow { Continue(*imp3.running.lock().unwrap()) })); } else { - let mut secs: u32 = 0; - let mut mins: u32 = 0; - let mut hrs: u32 = 0; + let mut secs: i32 = 0; + let mut secs_only: i32 = 0; + let mut mins: i32 = 0; + let mut hrs: i32 = 0; if *imp2.pomodoro_continue.lock().unwrap() { let pomodoro_start_time = *start_time.borrow(); let now_time = Local::now(); let continue_time = now_time - pomodoro_start_time; - let continue_time = continue_time.num_seconds() as u32; + let continue_time = continue_time.num_seconds() as i32; hrs = continue_time / 3600; mins = continue_time % 3600 / 60; secs = continue_time % 60; let watch_text: &str = &format!("{:02}:{:02}:{:02}", hrs, mins, secs).to_string(); this.set_watch_time(watch_text); + if settings_manager::get_bool("inclusive-total") { + imp2.history_box.set_todays_stored_secs(continue_time); + } + *imp2.pomodoro_continue.lock().unwrap() = false; } else { *start_time.borrow_mut() = Local::now(); @@ -291,8 +302,13 @@ impl FurtheranceWindow { let watch_text: &str = &format!("{:02}:{:02}:{:02}", hrs, mins, secs).to_string(); this_clone.set_watch_time(watch_text); + if settings_manager::get_bool("inclusive-total") { + secs_only +=1; + imp3.history_box.set_todays_time(secs_only); + } + if settings_manager::get_bool("autosave") { - let autosave_mins = settings_manager::get_int("autosave-time") as u32; + let autosave_mins = settings_manager::get_int("autosave-time"); let total_elapsed = (hrs * 3600) + (mins * 60) + secs; if total_elapsed % (autosave_mins * 60) == 0 { this_clone.write_autosave(autosave_start); |