diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/application.rs | 34 | ||||
-rwxr-xr-x | src/main.rs | 6 | ||||
-rwxr-xr-x | src/settings_manager.rs | 3 | ||||
-rwxr-xr-x | src/ui.rs | 4 | ||||
-rwxr-xr-x | src/ui/history_box.rs | 16 | ||||
-rwxr-xr-x | src/ui/preferences_window.rs | 95 | ||||
-rwxr-xr-x | src/ui/task_details.rs | 15 | ||||
-rwxr-xr-x | src/ui/task_row.rs | 24 | ||||
-rwxr-xr-x | src/ui/tasks_group.rs | 10 |
9 files changed, 85 insertions, 122 deletions
diff --git a/src/application.rs b/src/application.rs index fdc3637..157c432 100755 --- a/src/application.rs +++ b/src/application.rs @@ -23,9 +23,9 @@ use log::debug; use std::sync::Mutex; use crate::config; -use crate::ui::{FurtheranceWindow, FurPreferencesWindow, FurReport}; use crate::database; use crate::settings_manager; +use crate::ui::{FurPreferencesWindow, FurReport, FurtheranceWindow}; mod imp { use super::*; @@ -74,8 +74,15 @@ mod imp { // Load style.css let css_file = gtk::CssProvider::new(); - gtk::CssProvider::load_from_resource(&css_file, "/com/lakoliu/Furtherance/gtk/style.css"); - gtk::StyleContext::add_provider_for_display(&gdk::Display::default().unwrap(), &css_file, 500); + gtk::CssProvider::load_from_resource( + &css_file, + "/com/lakoliu/Furtherance/gtk/style.css", + ); + gtk::StyleContext::add_provider_for_display( + &gdk::Display::default().unwrap(), + &css_file, + 500, + ); // Ask the window manager/compositor to present the window window.present(); @@ -196,20 +203,27 @@ impl FurtheranceApplication { gtk::DialogFlags::MODAL, gtk::MessageType::Question, gtk::ButtonsType::None, - Some(&format!("<span size='x-large' weight='bold'>{}</span>", &gettext("Delete history?"))), + Some(&format!( + "<span size='x-large' weight='bold'>{}</span>", + &gettext("Delete history?") + )), ); dialog.add_buttons(&[ (&gettext("Cancel"), gtk::ResponseType::Reject), - (&gettext("Delete"), gtk::ResponseType::Accept) + (&gettext("Delete"), gtk::ResponseType::Accept), ]); dialog.set_default_response(gtk::ResponseType::Accept); - let delete_btn = dialog.widget_for_response(gtk::ResponseType::Accept).unwrap(); + let delete_btn = dialog + .widget_for_response(gtk::ResponseType::Accept) + .unwrap(); delete_btn.add_css_class("destructive-action"); let message_area = dialog.message_area().downcast::<gtk::Box>().unwrap(); - let explanation = gtk::Label::new(Some(&gettext("This will delete ALL of your task history."))); - let instructions = gtk::Label::new(Some( - &gettext("Type DELETE in the box below then click Delete to proceed."))); + let explanation = + gtk::Label::new(Some(&gettext("This will delete ALL of your task history."))); + let instructions = gtk::Label::new(Some(&gettext( + "Type DELETE in the box below then click Delete to proceed.", + ))); let delete_entry = gtk::Entry::new(); delete_entry.set_activates_default(true); message_area.append(&explanation); @@ -308,5 +322,3 @@ impl Default for FurtheranceApplication { .unwrap() } } - - diff --git a/src/main.rs b/src/main.rs index d9b299e..efe1522 100755 --- a/src/main.rs +++ b/src/main.rs @@ -16,16 +16,16 @@ mod application; mod config; -mod ui; mod database; mod settings_manager; +mod ui; use self::application::FurtheranceApplication; -use config::{GETTEXT_PACKAGE, LOCALEDIR, PKGDATADIR, APP_ID}; +use config::{APP_ID, GETTEXT_PACKAGE, LOCALEDIR, PKGDATADIR}; use gettextrs::{bind_textdomain_codeset, bindtextdomain, textdomain}; -use gtk::{gio, glib}; use gtk::prelude::*; +use gtk::{gio, glib}; fn main() { // Initialize GTK diff --git a/src/settings_manager.rs b/src/settings_manager.rs index 66c1092..d6ff17d 100755 --- a/src/settings_manager.rs +++ b/src/settings_manager.rs @@ -14,15 +14,14 @@ // 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; +use gtk::{gio, gio::prelude::*, glib}; pub fn get_settings() -> gio::Settings { let app_id = config::APP_ID.trim_end_matches(".Devel"); gio::Settings::new(app_id) } - pub fn bind_property<P: IsA<glib::Object>>(key: &str, object: &P, property: &str) { let settings = get_settings(); settings diff --git a/src/ui.rs b/src/ui.rs index 36ba710..d1ef0d3 100755 --- a/src/ui.rs +++ b/src/ui.rs @@ -18,16 +18,16 @@ mod history_box; mod preferences_window; mod report; mod task_details; +mod task_row; mod tasks_group; mod tasks_page; -mod task_row; pub mod window; pub use history_box::FurHistoryBox; pub use preferences_window::FurPreferencesWindow; pub use report::FurReport; pub use task_details::FurTaskDetails; +pub use task_row::FurTaskRow; pub use tasks_group::FurTasksGroup; pub use tasks_page::FurTasksPage; -pub use task_row::FurTaskRow; pub use window::FurtheranceWindow; diff --git a/src/ui/history_box.rs b/src/ui/history_box.rs index 73ca077..9d2f59f 100755 --- a/src/ui/history_box.rs +++ b/src/ui/history_box.rs @@ -14,15 +14,15 @@ // 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 glib::subclass; use gtk::prelude::*; use gtk::subclass::prelude::*; use gtk::{glib, CompositeTemplate}; -use glib::subclass; -use crate::ui::{FurtheranceWindow, FurTasksPage}; -use crate::FurtheranceApplication; -use crate::database; use crate::config; +use crate::database; +use crate::ui::{FurTasksPage, FurtheranceWindow}; +use crate::FurtheranceApplication; enum View { Loading, @@ -60,7 +60,6 @@ mod imp { fn instance_init(obj: &subclass::InitializingObject<Self>) { obj.init_template(); } - } impl ObjectImpl for FurHistoryBox { @@ -68,7 +67,6 @@ mod imp { obj.setup_widgets(); self.parent_constructed(obj); } - } impl WidgetImpl for FurHistoryBox {} impl BoxImpl for FurHistoryBox {} @@ -80,7 +78,6 @@ glib::wrapper! { @extends gtk::Widget, gtk::Box; } - impl FurHistoryBox { fn setup_widgets(&self) { self.set_view(View::Loading); @@ -97,9 +94,9 @@ impl FurHistoryBox { // Change "empty" page icon for development mode let imp = imp::FurHistoryBox::from_instance(self); if config::PROFILE == "development" { - imp.welcome_page.set_icon_name(Some("com.lakoliu.Furtherance.Devel")); + imp.welcome_page + .set_icon_name(Some("com.lakoliu.Furtherance.Devel")); } - } fn set_view(&self, view: View) { @@ -147,5 +144,4 @@ impl FurHistoryBox { let window = FurtheranceWindow::default(); window.set_height_request(390); } - } diff --git a/src/ui/preferences_window.rs b/src/ui/preferences_window.rs index d9495fd..188a478 100755 --- a/src/ui/preferences_window.rs +++ b/src/ui/preferences_window.rs @@ -87,7 +87,6 @@ mod imp { } impl ObjectImpl for FurPreferencesWindow { - fn constructed(&self, obj: &Self::Type) { let window = FurtheranceWindow::default(); obj.set_transient_for(Some(&window)); @@ -133,11 +132,7 @@ impl FurPreferencesWindow { fn setup_signals(&self) { let imp = imp::FurPreferencesWindow::from_instance(self); - settings_manager::bind_property( - "dark-mode", - &*imp.dark_theme_switch, - "active" - ); + settings_manager::bind_property("dark-mode", &*imp.dark_theme_switch, "active"); settings_manager::bind_property( "notify-of-idle", @@ -145,11 +140,7 @@ impl FurPreferencesWindow { "enable-expansion", ); - settings_manager::bind_property( - "idle-time", - &*imp.notify_of_idle_spin, - "value", - ); + settings_manager::bind_property("idle-time", &*imp.notify_of_idle_spin, "value"); settings_manager::bind_property( "limit-tasks", @@ -157,100 +148,68 @@ impl FurPreferencesWindow { "enable-expansion", ); - settings_manager::bind_property( - "limit-days", - &*imp.limit_days_spin, - "value", - ); + settings_manager::bind_property("limit-days", &*imp.limit_days_spin, "value"); settings_manager::bind_property( "delete-confirmation", &*imp.delete_confirmation_switch, - "active" + "active", ); - settings_manager::bind_property( - "show-seconds", - &*imp.show_seconds_switch, - "active" - ); + settings_manager::bind_property("show-seconds", &*imp.show_seconds_switch, "active"); - settings_manager::bind_property( - "show-daily-sums", - &*imp.show_daily_sums_switch, - "active" - ); + settings_manager::bind_property("show-daily-sums", &*imp.show_daily_sums_switch, "active"); - settings_manager::bind_property( - "show-tags", - &*imp.show_tags_switch, - "active" - ); + settings_manager::bind_property("show-tags", &*imp.show_tags_switch, "active"); - settings_manager::bind_property( - "pomodoro", - &*imp.pomodoro_expander, - "enable-expansion" - ); + settings_manager::bind_property("pomodoro", &*imp.pomodoro_expander, "enable-expansion"); - settings_manager::bind_property( - "pomodoro-time", - &*imp.pomodoro_spin, - "value" - ); + settings_manager::bind_property("pomodoro-time", &*imp.pomodoro_spin, "value"); - settings_manager::bind_property( - "autosave", - &*imp.autosave_expander, - "enable-expansion" - ); + settings_manager::bind_property("autosave", &*imp.autosave_expander, "enable-expansion"); - settings_manager::bind_property( - "autosave-time", - &*imp.autosave_spin, - "value" - ); + settings_manager::bind_property("autosave-time", &*imp.autosave_spin, "value"); - imp.dark_theme_switch.connect_active_notify(move |_|{ + imp.dark_theme_switch.connect_active_notify(move |_| { let app = FurtheranceApplication::default(); app.update_light_dark(); }); - imp.limit_tasks_expander.connect_enable_expansion_notify(move |_|{ - let window = FurtheranceWindow::default(); - window.reset_history_box(); - }); + imp.limit_tasks_expander + .connect_enable_expansion_notify(move |_| { + let window = FurtheranceWindow::default(); + window.reset_history_box(); + }); - imp.limit_days_spin.connect_value_changed(move |_|{ + imp.limit_days_spin.connect_value_changed(move |_| { let window = FurtheranceWindow::default(); window.reset_history_box(); }); - imp.show_seconds_switch.connect_active_notify(move |_|{ + imp.show_seconds_switch.connect_active_notify(move |_| { let window = FurtheranceWindow::default(); window.reset_history_box(); }); - imp.show_daily_sums_switch.connect_active_notify(move |_|{ + imp.show_daily_sums_switch.connect_active_notify(move |_| { let window = FurtheranceWindow::default(); window.reset_history_box(); }); - imp.show_tags_switch.connect_active_notify(move |_|{ + imp.show_tags_switch.connect_active_notify(move |_| { let window = FurtheranceWindow::default(); window.reset_history_box(); }); - imp.pomodoro_expander.connect_enable_expansion_notify(move |_|{ - let window = FurtheranceWindow::default(); - window.refresh_timer(); - }); + imp.pomodoro_expander + .connect_enable_expansion_notify(move |_| { + let window = FurtheranceWindow::default(); + window.refresh_timer(); + }); - imp.pomodoro_spin.connect_value_changed(move |_|{ + imp.pomodoro_spin.connect_value_changed(move |_| { let window = FurtheranceWindow::default(); window.refresh_timer(); }); } } - - diff --git a/src/ui/task_details.rs b/src/ui/task_details.rs index 37eced3..b8771ac 100755 --- a/src/ui/task_details.rs +++ b/src/ui/task_details.rs @@ -15,17 +15,17 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use adw::subclass::prelude::*; +use chrono::{offset::TimeZone, DateTime, Local, NaiveDateTime, ParseError}; use gettextrs::*; use glib::clone; use gtk::subclass::prelude::*; use gtk::{glib, prelude::*, CompositeTemplate}; -use chrono::{DateTime, NaiveDateTime, Local, ParseError, offset::TimeZone}; use itertools::Itertools; -use crate::FurtheranceApplication; -use crate::ui::FurtheranceWindow; use crate::database; use crate::settings_manager; +use crate::ui::FurtheranceWindow; +use crate::FurtheranceApplication; mod imp { use super::*; @@ -75,7 +75,6 @@ mod imp { } impl ObjectImpl for FurTaskDetails { - fn constructed(&self, obj: &Self::Type) { obj.setup_signals(); obj.setup_delete_all(); @@ -413,7 +412,7 @@ impl FurTaskDetails { dialog.show(); })); - stop.connect_clicked(move |_|{ + stop.connect_clicked(move |_| { start.emit_clicked(); }); } @@ -438,7 +437,8 @@ impl FurTaskDetails { let start_time_str = start_time.format("%x").to_string(); if imp.this_day.borrow().to_string() != start_time_str || imp.task_name_label.text() != task.task_name - || imp.orig_tags.borrow().to_string() != task.tags { + || imp.orig_tags.borrow().to_string() != task.tags + { false } else { true @@ -590,13 +590,10 @@ impl FurTaskDetails { } })); - } fn delete_all(&self) { let imp = imp::FurTaskDetails::from_instance(self); let _ = database::delete_by_ids(imp.all_task_ids.borrow().to_vec()); } - } - diff --git a/src/ui/task_row.rs b/src/ui/task_row.rs index cccc827..810d12e 100755 --- a/src/ui/task_row.rs +++ b/src/ui/task_row.rs @@ -14,17 +14,16 @@ // 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::subclass::prelude::*; -use gtk::{glib, gio, prelude::*, CompositeTemplate}; use chrono::DateTime; -use std::sync::Mutex; -use once_cell::sync::Lazy; use glib::clone; +use gtk::subclass::prelude::*; +use gtk::{gio, glib, prelude::*, CompositeTemplate}; +use once_cell::sync::Lazy; +use std::sync::Mutex; use crate::database::Task; -use crate::ui::{FurTaskDetails, FurtheranceWindow}; use crate::settings_manager; - +use crate::ui::{FurTaskDetails, FurtheranceWindow}; mod imp { use super::*; @@ -110,7 +109,8 @@ impl FurTaskRow { } // Display task's name - imp.task_name_label.set_text(&imp.tasks.lock().unwrap()[0].task_name); + imp.task_name_label + .set_text(&imp.tasks.lock().unwrap()[0].task_name); // Display task's tags if task_list[0].tags.trim().is_empty() || !settings_manager::get_bool("show-tags") { @@ -131,10 +131,11 @@ impl FurTaskRow { self.add_controller(&gesture); - imp.restart_task_btn.connect_clicked(clone!(@strong task_list => move |_| { - let window = FurtheranceWindow::default(); - window.duplicate_task(task_list[0].clone()); - })); + imp.restart_task_btn + .connect_clicked(clone!(@strong task_list => move |_| { + let window = FurtheranceWindow::default(); + window.duplicate_task(task_list[0].clone()); + })); // Add up all durations for task of said name to create total_time for task in &task_list { @@ -169,4 +170,3 @@ impl FurTaskRow { *imp.total_time.borrow() } } - diff --git a/src/ui/tasks_group.rs b/src/ui/tasks_group.rs index bd55c36..f53b13f 100755 --- a/src/ui/tasks_group.rs +++ b/src/ui/tasks_group.rs @@ -18,9 +18,9 @@ use adw::subclass::prelude::*; use gtk::subclass::prelude::*; use gtk::{glib, prelude::*}; -use crate::ui::FurTaskRow; use crate::database; use crate::settings_manager; +use crate::ui::FurTaskRow; mod imp { use super::*; @@ -86,9 +86,10 @@ impl FurTasksGroup { let mut unique = true; for i in 0..tasks_by_name.len() { if tasks_by_name[i][0].task_name == task.task_name - && ( ( settings_manager::get_bool("show-tags") - && tasks_by_name[i][0].tags == task.tags ) || - !settings_manager::get_bool("show-tags") ) { + && ((settings_manager::get_bool("show-tags") + && tasks_by_name[i][0].tags == task.tags) + || !settings_manager::get_bool("show-tags")) + { tasks_by_name[i].push(task.clone()); unique = false; } @@ -118,4 +119,3 @@ impl FurTasksGroup { *imp.day_total_time.borrow() } } - |