From e3bb347a12ad929619a51b37f0ca48dcfe46b731 Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Fri, 22 Apr 2022 10:30:19 +0300 Subject: Add tags to tasks (Issue #8) --- Cargo.lock | 16 +++++++++++++ Cargo.toml | 1 + data/com.lakoliu.Furtherance.gschema.xml | 3 +++ src/application.rs | 3 ++- src/database.rs | 37 ++++++++++++++++++++++++++---- src/gtk/preferences_window.ui | 27 +++++++++++++++++----- src/gtk/task_row.ui | 34 ++++++++++++++++++++-------- src/gtk/window.ui | 2 +- src/ui/preferences_window.rs | 13 +++++++++++ src/ui/task_details.rs | 39 +++++++++++++++++++++++++------- src/ui/task_row.rs | 23 +++++++++++++++---- src/ui/tasks_group.rs | 6 ++++- src/ui/window.rs | 36 +++++++++++++++++++++++++---- 13 files changed, 201 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e287a4..927ec1f 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,6 +181,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "fallible-iterator" version = "0.2.0" @@ -214,6 +220,7 @@ dependencies = [ "gettext-rs", "gtk4", "gtk4-macros", + "itertools", "libadwaita", "log", "once_cell", @@ -591,6 +598,15 @@ dependencies = [ "libc", ] +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + [[package]] name = "lazy_static" version = "1.4.0" diff --git a/Cargo.toml b/Cargo.toml index 7e0c6f2..e7f6fb3 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ dbus = "0.9.5" dbus-codegen = "0.10.0" log = "0.4" gtk4-macros = "=0.4.3" +itertools = "0.10.3" [dependencies.gtk] package = "gtk4" diff --git a/data/com.lakoliu.Furtherance.gschema.xml b/data/com.lakoliu.Furtherance.gschema.xml index eb19b87..af1d9b7 100755 --- a/data/com.lakoliu.Furtherance.gschema.xml +++ b/data/com.lakoliu.Furtherance.gschema.xml @@ -24,6 +24,9 @@ true + + + true diff --git a/src/application.rs b/src/application.rs index 9120446..06a033b 100755 --- a/src/application.rs +++ b/src/application.rs @@ -60,6 +60,7 @@ mod imp { fn activate(&self, application: &Self::Type) { // Initialize the database let _ = database::db_init(); + let _ = database::upgrade_old_db(); // Get the current window or create one if necessary let window = if let Some(window) = application.active_window() { @@ -142,7 +143,7 @@ impl FurtheranceApplication { } fn setup_application(&self) { - self.update_light_dark() + self.update_light_dark(); } fn show_about(&self) { diff --git a/src/database.rs b/src/database.rs index 7612643..5412896 100755 --- a/src/database.rs +++ b/src/database.rs @@ -26,6 +26,7 @@ pub struct Task { pub task_name: String, pub start_time: String, pub stop_time: String, + pub tags: String, } pub fn get_directory() -> PathBuf { @@ -45,21 +46,36 @@ pub fn db_init() -> Result<()> { id integer primary key, task_name text, start_time timestamp, - stop_time timestamp)", + stop_time timestamp, + tags text)", [], )?; Ok(()) } +pub fn upgrade_old_db() -> Result<()> { + // Update from old DB w/o tags + let conn = Connection::open(get_directory())?; + + conn.execute( + "ALTER TABLE tasks ADD COLUMN tags TEXT DEFAULT ' '", + [], + )?; + + Ok(()) +} -pub fn db_write(task_name: &str, start_time: DateTime, stop_time: DateTime) -> Result<()> { +pub fn db_write(task_name: &str, + start_time: DateTime, + stop_time: DateTime, + tags: String) -> Result<()> { // Write data into database let conn = Connection::open(get_directory())?; conn.execute( - "INSERT INTO tasks (task_name, start_time, stop_time) values (?1, ?2, ?3)", - &[&task_name.to_string(), &start_time.to_rfc3339(), &stop_time.to_rfc3339()], + "INSERT INTO tasks (task_name, start_time, stop_time, tags) values (?1, ?2, ?3, ?4)", + &[&task_name.to_string(), &start_time.to_rfc3339(), &stop_time.to_rfc3339(), &tags], )?; Ok(()) @@ -76,6 +92,7 @@ pub fn retrieve() -> Result, rusqlite::Error> { task_name: row.get(1)?, start_time: row.get(2)?, stop_time: row.get(3)?, + tags: row.get(4)?, }) })?; @@ -121,6 +138,17 @@ pub fn update_task_name(id: i32, task_name: String) -> Result<()> { Ok(()) } +pub fn update_tags(id: i32, tags: String) -> Result<()> { + let conn = Connection::open(get_directory())?; + + conn.execute( + "UPDATE tasks SET tags = (?1) WHERE id = (?2)", + &[&tags, &id.to_string()] + )?; + + Ok(()) +} + pub fn get_list_by_id(id_list: Vec) -> Result, rusqlite::Error> { let conn = Connection::open(get_directory())?; let mut tasks_vec: Vec = Vec::new(); @@ -134,6 +162,7 @@ pub fn get_list_by_id(id_list: Vec) -> Result, rusqlite::Error> { task_name: row.get(1)?, start_time: row.get(2)?, stop_time: row.get(3)?, + tags: row.get(4)?, }) })?; diff --git a/src/gtk/preferences_window.ui b/src/gtk/preferences_window.ui index 5c6140c..e288c52 100755 --- a/src/gtk/preferences_window.ui +++ b/src/gtk/preferences_window.ui @@ -62,6 +62,18 @@ Task List True + + + _Delete confirmation + True + delete_confirmation_switch + + + center + + + + Limit tasks shown @@ -93,11 +105,11 @@ - _Delete confirmation + Show daily sums True - delete_confirmation_switch + show_daily_sums_switch - + center @@ -116,18 +128,21 @@ + - Show daily sums + Show tags True - show_daily_sums_switch + show_tags_switch + Tags are saved, just not shown - + center + diff --git a/src/gtk/task_row.ui b/src/gtk/task_row.ui index edd2899..f5de3a5 100755 --- a/src/gtk/task_row.ui +++ b/src/gtk/task_row.ui @@ -2,7 +2,7 @@