From e2bbca53121f51c76bdfa54f0d239c8db5ca59be Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Sat, 5 Mar 2022 17:43:08 +0100 Subject: - Added 'delete confirmation' setting - Added 'show seconds' setting --- src/ui/preferences_window.rs | 24 ++++++++++++++++- src/ui/task_details.rs | 62 +++++++++++++++++++++++++++++++++++++------- src/ui/task_row.rs | 6 ++++- 3 files changed, 80 insertions(+), 12 deletions(-) (limited to 'src/ui') diff --git a/src/ui/preferences_window.rs b/src/ui/preferences_window.rs index 644ca22..12e8c30 100755 --- a/src/ui/preferences_window.rs +++ b/src/ui/preferences_window.rs @@ -48,6 +48,10 @@ mod imp { pub limit_tasks_expander: TemplateChild, #[template_child] pub limit_days_spin: TemplateChild, + #[template_child] + pub delete_confirmation_switch: TemplateChild, + #[template_child] + pub show_seconds_switch: TemplateChild, } #[glib::object_subclass] @@ -113,7 +117,8 @@ impl FurPreferencesWindow { settings_manager::bind_property( "dark-mode", &*imp.dark_theme_switch, - "active"); + "active" + ); settings_manager::bind_property( "notify-of-idle", @@ -139,6 +144,18 @@ impl FurPreferencesWindow { "value", ); + settings_manager::bind_property( + "delete-confirmation", + &*imp.delete_confirmation_switch, + "active" + ); + + settings_manager::bind_property( + "show-seconds", + &*imp.show_seconds_switch, + "active" + ); + imp.limit_tasks_expander.connect_enable_expansion_notify(move |_|{ let window = FurtheranceWindow::default(); window.reset_history_box(); @@ -148,6 +165,11 @@ impl FurPreferencesWindow { let window = FurtheranceWindow::default(); window.reset_history_box(); }); + + imp.show_seconds_switch.connect_active_notify(move |_|{ + let window = FurtheranceWindow::default(); + window.reset_history_box(); + }); } } diff --git a/src/ui/task_details.rs b/src/ui/task_details.rs index 69c3494..2e9d154 100755 --- a/src/ui/task_details.rs +++ b/src/ui/task_details.rs @@ -18,11 +18,12 @@ use adw::subclass::prelude::*; use glib::clone; use gtk::subclass::prelude::*; use gtk::{glib, prelude::*, CompositeTemplate}; -use chrono::{DateTime, NaiveDateTime, Local, offset::TimeZone}; +use chrono::{DateTime, NaiveDateTime, Local, ParseError, offset::TimeZone}; use crate::FurtheranceApplication; use crate::ui::FurtheranceWindow; use crate::database; +use crate::settings_manager; mod imp { use super::*; @@ -117,13 +118,19 @@ impl FurTaskDetails { task_box.set_homogeneous(true); let start_time = DateTime::parse_from_rfc3339(&task.start_time).unwrap(); - let start_time_str = start_time.format("%H:%M:%S").to_string(); + let mut start_time_str = start_time.format("%H:%M:%S").to_string(); + if !settings_manager::get_bool("show-seconds") { + start_time_str = start_time.format("%H:%M").to_string(); + } let start = gtk::Button::new(); start.set_label(&start_time_str); task_box.append(&start); let stop_time = DateTime::parse_from_rfc3339(&task.stop_time).unwrap(); - let stop_time_str = stop_time.format("%H:%M:%S").to_string(); + let mut stop_time_str = stop_time.format("%H:%M:%S").to_string(); + if !settings_manager::get_bool("show-seconds") { + stop_time_str = stop_time.format("%H:%M").to_string(); + } let stop = gtk::Button::new(); stop.set_label(&stop_time_str); task_box.append(&stop); @@ -133,7 +140,10 @@ impl FurTaskDetails { let h = total_time / 60 / 60; let m = (total_time / 60) - (h * 60); let s = total_time - (m * 60); - let total_time_str = format!("{:02}:{:02}:{:02}", h, m, s); + 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 = gtk::Button::new(); total.set_label(&total_time_str); total.add_css_class("inactive-button"); @@ -167,8 +177,14 @@ impl FurTaskDetails { let times_box = gtk::Box::new(gtk::Orientation::Horizontal, 5); times_box.set_homogeneous(true); - let start_time_w_year = start_time.format("%h %e %Y %H:%M:%S").to_string(); - let stop_time_w_year = stop_time.format("%h %e %Y %H:%M:%S").to_string(); + let mut start_time_w_year = start_time.format("%h %e %Y %H:%M:%S").to_string(); + if !settings_manager::get_bool("show-seconds") { + start_time_w_year = start_time.format("%h %e %Y %H:%M").to_string(); + } + let mut stop_time_w_year = stop_time.format("%h %e %Y %H:%M:%S").to_string(); + if !settings_manager::get_bool("show-seconds") { + stop_time_w_year = stop_time.format("%h %e %Y %H:%M").to_string(); + } let start_time_edit = gtk::Entry::new(); start_time_edit.set_text(&start_time_w_year); let stop_time_edit = gtk::Entry::new(); @@ -176,6 +192,9 @@ impl FurTaskDetails { let instructions = gtk::Label::new(Some( "*Use the format MMM DD YYYY HH:MM:SS")); + if !settings_manager::get_bool("show-seconds") { + instructions.set_text("*Use the format MMM DD YYYY HH:MM"); + } instructions.set_visible(false); instructions.add_css_class("error_message"); @@ -241,7 +260,11 @@ impl FurTaskDetails { } })); - delete_confirmation.show(); + if settings_manager::get_bool("delete-confirmation") { + delete_confirmation.show(); + } else { + delete_confirmation.response(gtk::ResponseType::Ok); + } })); @@ -262,9 +285,16 @@ impl FurTaskDetails { let new_stop_time_edited: String; if start_time_edit.text() != start_time_w_year { let new_start_time_str = start_time_edit.text(); - let new_start_time = NaiveDateTime::parse_from_str( + let new_start_time: Result; + if settings_manager::get_bool("show-seconds") { + new_start_time = NaiveDateTime::parse_from_str( &new_start_time_str, "%h %e %Y %H:%M:%S"); + } else { + new_start_time = NaiveDateTime::parse_from_str( + &new_start_time_str, + "%h %e %Y %H:%M"); + } if let Err(_) = new_start_time { instructions.set_visible(true); do_not_close = true; @@ -276,9 +306,16 @@ impl FurTaskDetails { } if stop_time_edit.text() != stop_time_w_year { let new_stop_time_str = stop_time_edit.text(); - let new_stop_time = NaiveDateTime::parse_from_str( + let new_stop_time: Result; + if settings_manager::get_bool("show-seconds") { + new_stop_time = NaiveDateTime::parse_from_str( &new_stop_time_str, "%h %e %Y %H:%M:%S"); + } else { + new_stop_time = NaiveDateTime::parse_from_str( + &new_stop_time_str, + "%h %e %Y %H:%M"); + } if let Err(_) = new_stop_time { instructions.set_visible(true); do_not_close = true; @@ -414,7 +451,6 @@ impl FurTaskDetails { ("Delete", gtk::ResponseType::Accept), ("Cancel", gtk::ResponseType::Reject) ]); - dialog.show(); dialog.connect_response(clone!(@strong dialog => move |_,resp|{ if resp == gtk::ResponseType::Accept { @@ -428,6 +464,12 @@ impl FurTaskDetails { } })); + if settings_manager::get_bool("delete-confirmation") { + dialog.show(); + } else { + dialog.response(gtk::ResponseType::Accept); + } + })); } diff --git a/src/ui/task_row.rs b/src/ui/task_row.rs index d17f263..cd0c69a 100755 --- a/src/ui/task_row.rs +++ b/src/ui/task_row.rs @@ -23,6 +23,7 @@ use glib::clone; use crate::database::Task; use crate::ui::FurTaskDetails; +use crate::settings_manager; mod imp { @@ -116,8 +117,11 @@ impl FurTaskRow { let h = total_time / 60 / 60; let m = (total_time / 60) - (h * 60); let s = total_time - (m * 60); + let mut total_time_str = format!("{:02}:{:02}:{:02}", h, m, s); - let 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); + } imp.total_time_label.set_text(&total_time_str); } -- cgit 1.4.1