From 5ccb8ef9e54a70c33d54210427e7ccd81e8b7b9b Mon Sep 17 00:00:00 2001 From: Alain Date: Fri, 8 Dec 2023 12:20:18 -0500 Subject: [PATCH] Fix #1055 --- config.vala.in | 2 - data/io.github.alainm23.planify.gschema.xml | 5 + quick-add/Objects/BaseObject.vala | 2 +- quick-add/Objects/Item.vala | 8 +- quick-add/Services/Database.vala | 4 +- .../Preferences/PreferencesWindow.vala | 144 ++++-------------- src/Objects/BaseObject.vala | 2 +- src/Objects/Item.vala | 10 +- src/Objects/Label.vala | 2 +- src/Objects/Reminder.vala | 6 +- src/Services/Database.vala | 4 +- src/Widgets/Calendar/Calendar.vala | 14 ++ src/Widgets/Calendar/CalendarHeader.vala | 5 +- src/Widgets/Calendar/CalendarWeek.vala | 77 ++++------ 14 files changed, 97 insertions(+), 188 deletions(-) diff --git a/config.vala.in b/config.vala.in index bfd3c3027..073aaadce 100644 --- a/config.vala.in +++ b/config.vala.in @@ -8,8 +8,6 @@ namespace Constants { public const string TODOIST_CLIENT_SECRET = "a86dfeb12139459da3e5e2a8c197c678"; public const string TODOIST_SCOPE = "data:read_write,data:delete,project:delete"; public const string PROFILE = @PROFILE@; - public const int ACTIVE = 1; - public const int INACTIVE = 0; public const int UPDATE_TIMEOUT = 1500; public const int DESTROY_TIMEOUT = 750; public const int DRAG_TIMEOUT = 225; diff --git a/data/io.github.alainm23.planify.gschema.xml b/data/io.github.alainm23.planify.gschema.xml index 60852e046..36f0658a9 100644 --- a/data/io.github.alainm23.planify.gschema.xml +++ b/data/io.github.alainm23.planify.gschema.xml @@ -31,6 +31,11 @@ + + + + + diff --git a/quick-add/Objects/BaseObject.vala b/quick-add/Objects/BaseObject.vala index 3fffacacf..0caa5a38f 100644 --- a/quick-add/Objects/BaseObject.vala +++ b/quick-add/Objects/BaseObject.vala @@ -26,7 +26,7 @@ public class Objects.BaseObject : GLib.Object { public signal void deleted (); public signal void updated (); - public uint update_timeout_id { get; set; default = Constants.INACTIVE; } + public uint update_timeout_id { get; set; default = 0; } string _id_string; public string id_string { diff --git a/quick-add/Objects/Item.vala b/quick-add/Objects/Item.vala index bfa671c19..99a44be84 100644 --- a/quick-add/Objects/Item.vala +++ b/quick-add/Objects/Item.vala @@ -30,7 +30,7 @@ public class Objects.Item : Objects.BaseObject { public string project_id { get; set; default = ""; } public string parent_id { get; set; default = ""; } - public int priority { get; set; default = Constants.INACTIVE; } + public int priority { get; set; default = 0; } public string priority_icon { get { @@ -74,8 +74,8 @@ public class Objects.Item : Objects.BaseObject { } } - public int child_order { get; set; default = Constants.INACTIVE; } - public int day_order { get; set; default = Constants.INACTIVE; } + public int child_order { get; set; default = 0; } + public int day_order { get; set; default = 0; } public bool checked { get; set; default = false; } public bool is_deleted { get; set; default = false; } public bool collapsed { get; set; default = false; } @@ -195,7 +195,7 @@ public class Objects.Item : Objects.BaseObject { builder.add_string_value (Util.get_default ().get_encode_text (description)); builder.set_member_name ("priority"); - if (priority == Constants.INACTIVE) { + if (priority == 0) { builder.add_int_value (Constants.PRIORITY_4); } else { builder.add_int_value (priority); diff --git a/quick-add/Services/Database.vala b/quick-add/Services/Database.vala index 8077e5afc..f0f92dc93 100644 --- a/quick-add/Services/Database.vala +++ b/quick-add/Services/Database.vala @@ -341,10 +341,10 @@ public class Services.Database : GLib.Object { private void set_parameter_bool (Sqlite.Statement? stmt, string par, bool val) { int par_position = stmt.bind_parameter_index (par); - stmt.bind_int (par_position, val ? Constants.ACTIVE : Constants.INACTIVE); + stmt.bind_int (par_position, val ? 1 : 0); } private bool get_parameter_bool (Sqlite.Statement stmt, int col) { - return stmt.column_int (col) == Constants.ACTIVE; + return stmt.column_int (col) == 1; } } diff --git a/src/Dialogs/Preferences/PreferencesWindow.vala b/src/Dialogs/Preferences/PreferencesWindow.vala index 7e6062486..a237757b1 100644 --- a/src/Dialogs/Preferences/PreferencesWindow.vala +++ b/src/Dialogs/Preferences/PreferencesWindow.vala @@ -206,6 +206,11 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesWindow { var start_week_model = new Gtk.StringList (null); start_week_model.append (_("Sunday")); start_week_model.append (_("Monday")); + start_week_model.append (_("Tuesday")); + start_week_model.append (_("Wednesday")); + start_week_model.append (_("Thursday")); + start_week_model.append (_("Friday")); + start_week_model.append (_("Saturday")); var start_week_row = new Adw.ComboRow (); start_week_row.title = _("Start of the week"); @@ -274,7 +279,6 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesWindow { var content_clamp = new Adw.Clamp () { maximum_size = 600, - margin_top = 24, margin_start = 24, margin_end = 24, margin_bottom = 24 @@ -289,15 +293,11 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesWindow { }; scrolled_window.child = content_clamp; - var main_content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { - vexpand = true, - hexpand = true - }; - - main_content.append (settings_header); - main_content.append (scrolled_window); + var toolbar_view = new Adw.ToolbarView (); + toolbar_view.add_top_bar (settings_header); + toolbar_view.content = scrolled_window; - var page = new Adw.NavigationPage (main_content, "general"); + var page = new Adw.NavigationPage (toolbar_view, "general"); sort_projects_row.notify["selected"].connect (() => { Services.Settings.get_default ().settings.set_enum ("projects-sort-by", (int) sort_projects_row.selected); @@ -439,7 +439,6 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesWindow { var content_clamp = new Adw.Clamp () { maximum_size = 600, - margin_top = 24, margin_start = 24, margin_end = 24 }; @@ -631,22 +630,18 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesWindow { var content_clamp = new Adw.Clamp () { maximum_size = 600, - margin_top = 24, margin_start = 24, - margin_end = 24 + margin_end = 24, + margin_top = 12 }; content_clamp.child = content_box; - var main_content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { - vexpand = true, - hexpand = true - }; - - main_content.append (settings_header); - main_content.append (content_clamp); + var toolbar_view = new Adw.ToolbarView (); + toolbar_view.add_top_bar (settings_header); + toolbar_view.content = content_clamp; - var page = new Adw.NavigationPage (main_content, "account"); + var page = new Adw.NavigationPage (toolbar_view, "account"); var todoist_switch_gesture = new Gtk.GestureClick (); todoist_switch_gesture.set_button (1); @@ -713,7 +708,7 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesWindow { }); google_tasks_button.clicked.connect (() => { - push_subpage (get_google_view ()); + }); inbox_project_row.notify["selected"].connect (() => { @@ -758,7 +753,6 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesWindow { var content_clamp = new Adw.Clamp () { maximum_size = 600, - margin_top = 24, margin_start = 24, margin_end = 24 }; @@ -797,96 +791,14 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesWindow { hexpand = true }; - main_content.append (settings_header); main_content.append (user_box); main_content.append (content_clamp); - var page = new Adw.NavigationPage (main_content, "todoist"); - - settings_header.back_activated.connect (() => { - pop_subpage (); - }); - - sync_server_row.notify["active"].connect (() => { - Services.Settings.get_default ().settings.set_boolean ("todoist-sync-server", sync_server_switch.active); - }); - - return page; - } - - private Adw.NavigationPage get_google_view () { - var settings_header = new Widgets.SettingsHeader (_("Google Tasks")); - - var avatar = new Adw.Avatar (84, Services.Settings.get_default ().settings.get_string ("google-user-name"), true); - - var file = File.new_for_path (Util.get_default ().get_avatar_path ("google-user")); - if (file.query_exists ()) { - // todoist_avatar.set_loadable_icon (new FileIcon (file)); - } - - var user_label = new Gtk.Label (Services.Settings.get_default ().settings.get_string ("google-user-name")) { - margin_top = 12 - }; - user_label.add_css_class ("title-1"); - - var email_label = new Gtk.Label (Services.Settings.get_default ().settings.get_string ("todoist-user-email")); - email_label.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); - - var user_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { - margin_top = 64 - }; - user_box.append (avatar); - user_box.append (user_label); - user_box.append (email_label); - - var default_group = new Adw.PreferencesGroup (); - - var content_clamp = new Adw.Clamp () { - maximum_size = 400, - margin_top = 24, - margin_start = 24, - margin_end = 24 - }; - - content_clamp.child = default_group; - - var sync_server_switch = new Gtk.Switch () { - valign = Gtk.Align.CENTER, - active = Services.Settings.get_default ().settings.get_boolean ("todoist-sync-server") - }; - - var sync_server_row = new Adw.ActionRow (); - sync_server_row.title = _("Sync Server"); - sync_server_row.subtitle = _("Activate this setting so that Planner automatically synchronizes with your Todoist account every 15 minutes."); - sync_server_row.set_activatable_widget (sync_server_switch); - sync_server_row.add_suffix (sync_server_switch); - - var last_sync_date = new GLib.DateTime.from_iso8601 ( - Services.Settings.get_default ().settings.get_string ("todoist-last-sync"), new GLib.TimeZone.local () - ); - - var last_sync_label = new Gtk.Label (Util.get_default ().get_relative_date_from_date ( - last_sync_date - )); - - var last_sync_row = new Adw.ActionRow (); - last_sync_row.activatable = false; - last_sync_row.title = _("Last Sync"); - last_sync_row.add_suffix (last_sync_label); - - default_group.add (sync_server_row); - default_group.add (last_sync_row); - - var main_content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { - vexpand = true, - hexpand = true - }; - - main_content.append (settings_header); - main_content.append (user_box); - main_content.append (content_clamp); + var toolbar_view = new Adw.ToolbarView (); + toolbar_view.add_top_bar (settings_header); + toolbar_view.content = main_content; - var page = new Adw.NavigationPage (main_content, "google"); + var page = new Adw.NavigationPage (toolbar_view, "todoist"); settings_header.back_activated.connect (() => { pop_subpage (); @@ -940,22 +852,18 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesWindow { var content_clamp = new Adw.Clamp () { maximum_size = 400, - margin_top = 24, margin_start = 24, - margin_end = 24 + margin_end = 24, + margin_top = 12 }; content_clamp.child = content_box; - var main_content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { - vexpand = true, - hexpand = true - }; - - main_content.append (settings_header); - main_content.append (content_clamp); + var toolbar_view = new Adw.ToolbarView (); + toolbar_view.add_top_bar (settings_header); + toolbar_view.content = content_clamp; - var page = new Adw.NavigationPage (main_content, "quick-add"); + var page = new Adw.NavigationPage (toolbar_view, "quick-add"); copy_button.clicked.connect (() => { Gdk.Clipboard clipboard = Gdk.Display.get_default ().get_clipboard (); diff --git a/src/Objects/BaseObject.vala b/src/Objects/BaseObject.vala index 8531ee386..6b148759c 100644 --- a/src/Objects/BaseObject.vala +++ b/src/Objects/BaseObject.vala @@ -26,7 +26,7 @@ public class Objects.BaseObject : GLib.Object { public signal void deleted (); public signal void updated (); - public uint update_timeout_id { get; set; default = Constants.INACTIVE; } + public uint update_timeout_id { get; set; default = 0; } string _id_string; public string id_string { diff --git a/src/Objects/Item.vala b/src/Objects/Item.vala index c0ca68846..d479ec316 100644 --- a/src/Objects/Item.vala +++ b/src/Objects/Item.vala @@ -30,7 +30,7 @@ public class Objects.Item : Objects.BaseObject { public string project_id { get; set; default = ""; } public string parent_id { get; set; default = ""; } - public int priority { get; set; default = Constants.INACTIVE; } + public int priority { get; set; default = 0; } // Tmp public bool activate_name_editable { get; set; default = false; } @@ -77,8 +77,8 @@ public class Objects.Item : Objects.BaseObject { } } - public int child_order { get; set; default = Constants.INACTIVE; } - public int day_order { get; set; default = Constants.INACTIVE; } + public int child_order { get; set; default = 0; } + public int day_order { get; set; default = 0; } public bool checked { get; set; default = false; } public bool is_deleted { get; set; default = false; } public bool collapsed { get; set; default = false; } @@ -617,7 +617,7 @@ public class Objects.Item : Objects.BaseObject { builder.add_string_value (Util.get_default ().get_encode_text (description)); builder.set_member_name ("priority"); - if (priority == Constants.INACTIVE) { + if (priority == 0) { builder.add_int_value (Constants.PRIORITY_4); } else { builder.add_int_value (priority); @@ -694,7 +694,7 @@ public class Objects.Item : Objects.BaseObject { builder.add_string_value (Util.get_default ().get_encode_text (description)); builder.set_member_name ("priority"); - if (priority == Constants.INACTIVE) { + if (priority == 0) { builder.add_int_value (Constants.PRIORITY_4); } else { builder.add_int_value (priority); diff --git a/src/Objects/Label.vala b/src/Objects/Label.vala index 3870deb13..9bfd85d3f 100644 --- a/src/Objects/Label.vala +++ b/src/Objects/Label.vala @@ -21,7 +21,7 @@ public class Objects.Label : Objects.BaseObject { public string color { get; set; default = ""; } - public int item_order { get; set; default = Constants.INACTIVE; } + public int item_order { get; set; default = 0; } public bool is_deleted { get; set; default = false; } public bool is_favorite { get; set; default = false; } public BackendType backend_type { get; set; default = BackendType.NONE; } diff --git a/src/Objects/Reminder.vala b/src/Objects/Reminder.vala index 646f603e8..ff15c0b0c 100644 --- a/src/Objects/Reminder.vala +++ b/src/Objects/Reminder.vala @@ -1,10 +1,10 @@ public class Objects.Reminder : Objects.BaseObject { - public int64 notify_uid { get; set; default = Constants.INACTIVE; } + public int64 notify_uid { get; set; default = 0; } public string item_id { get; set; default = ""; } public string service { get; set; default = ""; } public Objects.DueDate due { get; set; default = new Objects.DueDate (); } - public int mm_offset { get; set; default = Constants.INACTIVE; } - public int is_deleted { get; set; default = Constants.INACTIVE; } + public int mm_offset { get; set; default = 0; } + public int is_deleted { get; set; default = 0; } Objects.Item? _item; public Objects.Item item { diff --git a/src/Services/Database.vala b/src/Services/Database.vala index 5c78e5999..9f80d85ab 100644 --- a/src/Services/Database.vala +++ b/src/Services/Database.vala @@ -2014,11 +2014,11 @@ public class Services.Database : GLib.Object { private void set_parameter_bool (Sqlite.Statement? stmt, string par, bool val) { int par_position = stmt.bind_parameter_index (par); - stmt.bind_int (par_position, val ? Constants.ACTIVE : Constants.INACTIVE); + stmt.bind_int (par_position, val ? 1 : 0); } private bool get_parameter_bool (Sqlite.Statement stmt, int col) { - return stmt.column_int (col) == Constants.ACTIVE; + return stmt.column_int (col) == 1; } Json.Parser parser; diff --git a/src/Widgets/Calendar/Calendar.vala b/src/Widgets/Calendar/Calendar.vala index 2f3e59c53..a4bcdf5fd 100644 --- a/src/Widgets/Calendar/Calendar.vala +++ b/src/Widgets/Calendar/Calendar.vala @@ -100,6 +100,11 @@ public class Widgets.Calendar.Calendar : Gtk.Box { var date = new GLib.DateTime.local (year_nav, month_nav, 1, 0, 0, 0); var firts_week = new DateTime.local (date.get_year (), date.get_month (), 1, 0, 0, 0); int start_day = firts_week.get_day_of_week () - Services.Settings.get_default ().settings.get_enum ("start-week"); + if (start_day < 0) { + start_day += 7; + } + start_day = (start_day + 7) % 7; + int max_days = Util.get_default ().get_days_of_month (date.get_month (), year_nav); calendar_view.fill_grid_days (start_day, @@ -123,6 +128,10 @@ public class Widgets.Calendar.Calendar : Gtk.Box { var date = new GLib.DateTime.local (year_nav, month_nav, 1, 0, 0, 0); var firts_week = new DateTime.local (date.get_year (), date.get_month (), 1, 0, 0, 0); int start_day = firts_week.get_day_of_week () - Services.Settings.get_default ().settings.get_enum ("start-week"); + if (start_day < 0) { + start_day += 7; + } + start_day = (start_day + 7) % 7; int max_days = Util.get_default ().get_days_of_month (date.get_month (), year_nav); calendar_view.fill_grid_days (start_day, max_days, @@ -145,6 +154,11 @@ public class Widgets.Calendar.Calendar : Gtk.Box { var firts_week = new DateTime.local (year, month, 1, 0, 0, 0); int start_day = firts_week.get_day_of_week () - Services.Settings.get_default ().settings.get_enum ("start-week"); + if (start_day < 0) { + start_day += 7; + } + start_day = (start_day + 7) % 7; + int max_days = Util.get_default ().get_days_of_month (current_date.get_month (), year_nav); calendar_view.fill_grid_days ( diff --git a/src/Widgets/Calendar/CalendarHeader.vala b/src/Widgets/Calendar/CalendarHeader.vala index 49176a79b..8433cdf1f 100644 --- a/src/Widgets/Calendar/CalendarHeader.vala +++ b/src/Widgets/Calendar/CalendarHeader.vala @@ -51,7 +51,7 @@ public class Widgets.Calendar.CalendarHeader : Gtk.Box { var chevron_left_image = new Widgets.DynamicIcon (); chevron_left_image.size = 16; - chevron_left_image.update_icon_name ("chevron-left"); + chevron_left_image.update_icon_name ("pan-start-symbolic"); left_button = new Gtk.Button () { valign = Gtk.Align.CENTER, @@ -64,7 +64,7 @@ public class Widgets.Calendar.CalendarHeader : Gtk.Box { var chevron_right_image = new Widgets.DynamicIcon (); chevron_right_image.size = 16; - chevron_right_image.update_icon_name ("chevron-right"); + chevron_right_image.update_icon_name ("pan-end-symbolic"); right_button = new Gtk.Button () { valign = Gtk.Align.CENTER, @@ -73,7 +73,6 @@ public class Widgets.Calendar.CalendarHeader : Gtk.Box { right_button.child = chevron_right_image; right_button.add_css_class (Granite.STYLE_CLASS_FLAT); - // right_button.add_css_class ("no-padding"); var date_grid = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6); date_grid.append (month_label); diff --git a/src/Widgets/Calendar/CalendarWeek.vala b/src/Widgets/Calendar/CalendarWeek.vala index fa85c2986..753174782 100644 --- a/src/Widgets/Calendar/CalendarWeek.vala +++ b/src/Widgets/Calendar/CalendarWeek.vala @@ -1,5 +1,5 @@ /* -* Copyright © 2019 Alain M. (https://github.com/alainm23/planner) +* Copyright © 2023 Alain M. (https://github.com/alainm23/planify) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public @@ -20,15 +20,9 @@ */ public class Widgets.Calendar.CalendarWeek : Gtk.Box { - private Gtk.Label label_monday; - private Gtk.Label label_tuesday; - private Gtk.Label label_wednesday; - private Gtk.Label label_thursday; - private Gtk.Label label_friday; - private Gtk.Label label_saturday; - private Gtk.Label label_sunday; + private Gtk.Label[] day_labels; - public CalendarWeek () { + construct { orientation = Gtk.Orientation.HORIZONTAL; homogeneous = true; valign = Gtk.Align.CENTER; @@ -36,27 +30,21 @@ public class Widgets.Calendar.CalendarWeek : Gtk.Box { margin_top = 6; margin_bottom = 6; margin_end = 6; - - label_monday = new Gtk.Label (_("Mo")); - label_monday.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); - label_tuesday = new Gtk.Label (_("Tu")); - label_tuesday.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); + day_labels = new Gtk.Label[] { + new Gtk.Label (_("Su")), + new Gtk.Label (_("Mo")), + new Gtk.Label (_("Tu")), + new Gtk.Label (_("We")), + new Gtk.Label (_("Th")), + new Gtk.Label (_("Fr")), + new Gtk.Label (_("Sa")) + }; - label_wednesday = new Gtk.Label (_("We")); - label_wednesday.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); - - label_thursday = new Gtk.Label (_("Th")); - label_thursday.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); - - label_friday = new Gtk.Label (_("Fr")); - label_friday.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); - - label_saturday = new Gtk.Label (_("Sa")); - label_saturday.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); - - label_sunday = new Gtk.Label (_("Su")); - label_sunday.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); + foreach (var label in day_labels) { + label.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); + append (label); + } update (); } @@ -65,28 +53,25 @@ public class Widgets.Calendar.CalendarWeek : Gtk.Box { for (Gtk.Widget? child = get_first_child (); child != null;) { Gtk.Widget? next = child.get_next_sibling (); remove (child); - child = next; } var start_week = Services.Settings.get_default ().settings.get_enum ("start-week"); - - if (start_week == 0) { - append (label_sunday); - append (label_monday); - append (label_tuesday); - append (label_wednesday); - append (label_thursday); - append (label_friday); - append (label_saturday); - } else if (start_week == 1) { - append (label_monday); - append (label_tuesday); - append (label_wednesday); - append (label_thursday); - append (label_friday); - append (label_saturday); - append (label_sunday); + var rotated_labels = rotate_left (day_labels, start_week); + + foreach (var label in rotated_labels) { + append (label); + } + } + + private Gtk.Label[] rotate_left (Gtk.Label[] array, int positions) { + positions = (positions % array.length + array.length) % array.length; + var rotated = new Gtk.Label[array.length]; + + for (int i = 0; i < array.length; i++) { + rotated[i] = array[(i + positions) % array.length]; } + + return rotated; } }