diff --git a/.vala-lint.conf b/.vala-lint.conf index 48961f324..7a84419c3 100644 --- a/.vala-lint.conf +++ b/.vala-lint.conf @@ -9,7 +9,7 @@ no-space=error note=warn space-before-paren=error use-of-tabs=off -trailing-newlines=error +trailing-newlines=off trailing-whitespace=off unnecessary-string-template=error diff --git a/core/Enum.vala b/core/Enum.vala index de3b93000..9b05a2a6e 100644 --- a/core/Enum.vala +++ b/core/Enum.vala @@ -1,23 +1,23 @@ /* -* 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 -* License as published by the Free Software Foundation; either -* version 3 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -* Authored by: Alain M. -*/ + * 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 + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Alain M. + */ public enum ColorScheme { NO_PREFERENCE, @@ -49,14 +49,14 @@ public enum ProjectViewStyle { public static ProjectViewStyle parse (string value) { switch (value) { - case "list": - return ProjectViewStyle.LIST; + case "list": + return ProjectViewStyle.LIST; - case "board": - return ProjectViewStyle.BOARD; + case "board": + return ProjectViewStyle.BOARD; - default: - assert_not_reached (); + default: + assert_not_reached (); } } } @@ -80,14 +80,14 @@ public enum ProjectIconStyle { public static ProjectIconStyle parse (string value) { switch (value) { - case "progress": - return ProjectIconStyle.PROGRESS; + case "progress": + return ProjectIconStyle.PROGRESS; - case "emoji": - return ProjectIconStyle.EMOJI; + case "emoji": + return ProjectIconStyle.EMOJI; - default: - assert_not_reached (); + default: + assert_not_reached (); } } } @@ -102,101 +102,101 @@ public enum FilterType { public string to_string () { switch (this) { - case INBOX: - return "inbox"; + case INBOX: + return "inbox"; - case TODAY: - return "today"; + case TODAY: + return "today"; - case SCHEDULED: - return "scheduled"; + case SCHEDULED: + return "scheduled"; - case PINBOARD: - return "pinboard"; + case PINBOARD: + return "pinboard"; - case LABELS: - return "labels"; + case LABELS: + return "labels"; - case COMPLETED: - return "completed"; + case COMPLETED: + return "completed"; - default: - assert_not_reached (); - } + default: + assert_not_reached (); + } } public string get_name () { switch (this) { - case INBOX: - return _("Inbox"); + case INBOX: + return _("Inbox"); - case TODAY: - return _("Today"); + case TODAY: + return _("Today"); - case SCHEDULED: - return _("Scheduled"); + case SCHEDULED: + return _("Scheduled"); - case PINBOARD: - return _("Pinboard"); + case PINBOARD: + return _("Pinboard"); - case LABELS: - return _("Labels"); + case LABELS: + return _("Labels"); - case COMPLETED: - return _("Completed"); + case COMPLETED: + return _("Completed"); - default: - assert_not_reached (); + default: + assert_not_reached (); } } public string get_icon () { switch (this) { - case INBOX: - return "mailbox-symbolic"; + case INBOX: + return "mailbox-symbolic"; - case TODAY: - return "star-outline-thick-symbolic"; + case TODAY: + return "star-outline-thick-symbolic"; - case SCHEDULED: - return "month-symbolic"; + case SCHEDULED: + return "month-symbolic"; - case PINBOARD: - return "pin-symbolic"; + case PINBOARD: + return "pin-symbolic"; - case LABELS: - return "tag-outline-symbolic"; + case LABELS: + return "tag-outline-symbolic"; - case COMPLETED: - return "check-round-outline-symbolic"; + case COMPLETED: + return "check-round-outline-symbolic"; - default: - assert_not_reached (); + default: + assert_not_reached (); } } public string get_color () { switch (this) { - case INBOX: - return "#3584e4"; + case INBOX: + return "#3584e4"; - case TODAY: - return "#33d17a"; + case TODAY: + return "#33d17a"; - case SCHEDULED: - return "#9141ac"; + case SCHEDULED: + return "#9141ac"; - case PINBOARD: - return "#ed333b"; + case PINBOARD: + return "#ed333b"; - case LABELS: - return "#986a44"; + case LABELS: + return "#986a44"; - case COMPLETED: - return "#ff7800"; + case COMPLETED: + return "#ff7800"; - default: - assert_not_reached (); + default: + assert_not_reached (); } } } @@ -210,42 +210,42 @@ public enum SourceType { public string to_string () { switch (this) { - case NONE: - return "none"; + case NONE: + return "none"; - case LOCAL: - return "local"; + case LOCAL: + return "local"; - case TODOIST: - return "todoist"; + case TODOIST: + return "todoist"; - case GOOGLE_TASKS: - return "google-tasks"; + case GOOGLE_TASKS: + return "google-tasks"; - case CALDAV: - return "caldav"; + case CALDAV: + return "caldav"; - default: - assert_not_reached (); + default: + assert_not_reached (); } } public static SourceType parse (string value) { switch (value) { - case "local": - return SourceType.LOCAL; + case "local": + return SourceType.LOCAL; + + case "todoist": + return SourceType.TODOIST; - case "todoist": - return SourceType.TODOIST; + case "google-tasks": + return SourceType.GOOGLE_TASKS; - case "google-tasks": - return SourceType.GOOGLE_TASKS; - - case "caldav": - return SourceType.CALDAV; + case "caldav": + return SourceType.CALDAV; - default: - return SourceType.NONE; + default: + return SourceType.NONE; } } } @@ -274,29 +274,29 @@ public enum ObjectType { public string get_header () { switch (this) { - case PROJECT: - return _("Projects"); + case PROJECT: + return _("Projects"); - case SECTION: - return _("Sections"); + case SECTION: + return _("Sections"); - case ITEM: - return _("Tasks"); + case ITEM: + return _("Tasks"); - case LABEL: - return _("Labels"); + case LABEL: + return _("Labels"); - case FILTER: - return _("Filters"); + case FILTER: + return _("Filters"); - case TASK: - return _("Tasks"); + case TASK: + return _("Tasks"); - case TASK_LIST: - return _("Lists"); + case TASK_LIST: + return _("Lists"); - default: - assert_not_reached (); + default: + assert_not_reached (); } } } @@ -318,49 +318,49 @@ public enum RecurrencyType { public string to_friendly_string (int? interval = null) { switch (this) { - case NONE: - return _("Don't Repeat"); - case MINUTELY: - if (interval == null || interval == 0) { - return _("Every minute"); - } else { - return GLib.ngettext (_("Every minute"), _("Every %d minutes"), interval).printf (interval); - } - case HOURLY: - if (interval == null || interval == 0) { - return _("Every hour"); - } else { - return GLib.ngettext (_("Every hour"), _("Every %d hours"), interval).printf (interval); - } - case EVERY_DAY: - if (interval == null || interval == 0) { - return _("Every day"); - } else { - return GLib.ngettext (_("Every day"), _("Every %d days"), interval).printf (interval); - } - case EVERY_WEEK: - if (interval == null || interval == 0) { - return _("Every week"); - } else { - return GLib.ngettext (_("Every week"), _("Every %d weeks"), interval).printf (interval); - } - - case EVERY_MONTH: - if (interval == null || interval == 0) { - return _("Every month"); - } else { - return GLib.ngettext (_("Every month"), _("Every %d months"), interval).printf (interval); - } - - case EVERY_YEAR: - if (interval == null || interval == 0) { - return _("Every year"); - } else { - return GLib.ngettext (_("Every year"), _("Every %d years"), interval).printf (interval); - } - - default: - assert_not_reached (); + case NONE: + return _("Don't Repeat"); + case MINUTELY: + if (interval == null || interval == 0) { + return _("Every minute"); + } else { + return GLib.ngettext (_("Every minute"), _("Every %d minutes"), interval).printf (interval); + } + case HOURLY: + if (interval == null || interval == 0) { + return _("Every hour"); + } else { + return GLib.ngettext (_("Every hour"), _("Every %d hours"), interval).printf (interval); + } + case EVERY_DAY: + if (interval == null || interval == 0) { + return _("Every day"); + } else { + return GLib.ngettext (_("Every day"), _("Every %d days"), interval).printf (interval); + } + case EVERY_WEEK: + if (interval == null || interval == 0) { + return _("Every week"); + } else { + return GLib.ngettext (_("Every week"), _("Every %d weeks"), interval).printf (interval); + } + + case EVERY_MONTH: + if (interval == null || interval == 0) { + return _("Every month"); + } else { + return GLib.ngettext (_("Every month"), _("Every %d months"), interval).printf (interval); + } + + case EVERY_YEAR: + if (interval == null || interval == 0) { + return _("Every year"); + } else { + return GLib.ngettext (_("Every year"), _("Every %d years"), interval).printf (interval); + } + + default: + assert_not_reached (); } } } @@ -371,14 +371,14 @@ public enum PickerType { public string to_string () { switch (this) { - case PROJECTS: - return "projects"; + case PROJECTS: + return "projects"; - case SECTIONS: - return "sections"; + case SECTIONS: + return "sections"; - default: - assert_not_reached (); + default: + assert_not_reached (); } } } @@ -394,53 +394,53 @@ public enum CalDAVType { public string to_string () { switch (this) { - case NEXTCLOUD: - return "nextcloud"; + case NEXTCLOUD: + return "nextcloud"; - case RADICALE: - return "radicale"; + case RADICALE: + return "radicale"; - default: - assert_not_reached (); + default: + assert_not_reached (); } } public string title () { switch (this) { - case NEXTCLOUD: - return _("Nextcloud"); + case NEXTCLOUD: + return _("Nextcloud"); - case RADICALE: - return _("Radicale"); + case RADICALE: + return _("Radicale"); - default: - assert_not_reached (); + default: + assert_not_reached (); } } public static CalDAVType parse_index (uint value) { switch (value) { - case 0: - return CalDAVType.NEXTCLOUD; + case 0: + return CalDAVType.NEXTCLOUD; - case 1: - return CalDAVType.RADICALE; + case 1: + return CalDAVType.RADICALE; - default: - return CalDAVType.NEXTCLOUD; + default: + return CalDAVType.NEXTCLOUD; } } public static CalDAVType parse (string value) { switch (value) { - case "nextcloud": - return CalDAVType.NEXTCLOUD; + case "nextcloud": + return CalDAVType.NEXTCLOUD; - case "radicale": - return CalDAVType.RADICALE; + case "radicale": + return CalDAVType.RADICALE; - default: - return CalDAVType.NEXTCLOUD; + default: + return CalDAVType.NEXTCLOUD; } } } @@ -453,60 +453,60 @@ public enum FilterItemType { public string to_string () { switch (this) { - case PRIORITY: - return "priority"; - - case LABEL: - return "label"; - - case DUE_DATE: - return "due-date"; - - case SECTION: - return "section"; - - default: - assert_not_reached (); + case PRIORITY: + return "priority"; + + case LABEL: + return "label"; + + case DUE_DATE: + return "due-date"; + + case SECTION: + return "section"; + + default: + assert_not_reached (); } } public string get_title () { switch (this) { - case PRIORITY: - return _("Priority"); + case PRIORITY: + return _("Priority"); - case LABEL: - return _("Label"); + case LABEL: + return _("Label"); - case DUE_DATE: - return _("Due Date"); + case DUE_DATE: + return _("Due Date"); - case SECTION: - return _("Section"); + case SECTION: + return _("Section"); - default: - assert_not_reached (); + default: + assert_not_reached (); } } public string get_icon () { switch (this) { - case PRIORITY: - return "flag-outline-thick-symbolic"; + case PRIORITY: + return "flag-outline-thick-symbolic"; - case LABEL: - return "tag-outline-symbolic"; + case LABEL: + return "tag-outline-symbolic"; - case DUE_DATE: - return "month-symbolic"; + case DUE_DATE: + return "month-symbolic"; - case SECTION: - return "arrow3-right-symbolic"; + case SECTION: + return "arrow3-right-symbolic"; - default: - assert_not_reached (); + default: + assert_not_reached (); } - } + } } public enum ReminderType { @@ -515,14 +515,14 @@ public enum ReminderType { public string to_string () { switch (this) { - case ABSOLUTE: - return "absolute"; - - case RELATIVE: - return "relative"; - - default: - assert_not_reached (); + case ABSOLUTE: + return "absolute"; + + case RELATIVE: + return "relative"; + + default: + assert_not_reached (); } } } @@ -533,27 +533,27 @@ public enum ItemType { public string to_string () { switch (this) { - case TASK: - return "task"; + case TASK: + return "task"; - case NOTE: - return "note"; + case NOTE: + return "note"; - default: - assert_not_reached (); + default: + assert_not_reached (); } } public static ItemType parse (string value) { switch (value) { - case "task": - return ItemType.TASK; + case "task": + return ItemType.TASK; - case "note": - return ItemType.NOTE; + case "note": + return ItemType.NOTE; - default: - assert_not_reached (); + default: + assert_not_reached (); } } } @@ -564,40 +564,40 @@ public enum ObjectEventType { public static ObjectEventType parse (string value) { switch (value) { - case "insert": - return ObjectEventType.INSERT; + case "insert": + return ObjectEventType.INSERT; - case "update": - return ObjectEventType.UPDATE; + case "update": + return ObjectEventType.UPDATE; - default: - assert_not_reached (); + default: + assert_not_reached (); } } public string to_string () { switch (this) { - case INSERT: - return "insert"; + case INSERT: + return "insert"; - case UPDATE: - return "update"; + case UPDATE: + return "update"; - default: - assert_not_reached (); + default: + assert_not_reached (); } } public string get_label () { switch (this) { - case INSERT: - return _("Task Created"); + case INSERT: + return _("Task Created"); - case UPDATE: - return _("Task Updated"); + case UPDATE: + return _("Task Updated"); - default: - assert_not_reached (); + default: + assert_not_reached (); } } } @@ -615,60 +615,60 @@ public enum ObjectEventKeyType { public static ObjectEventKeyType parse (string value) { switch (value) { - case "content": - return ObjectEventKeyType.CONTENT; - - case "description": - return ObjectEventKeyType.DESCRIPTION; - - case "due": - return ObjectEventKeyType.DUE; - - case "priority": - return ObjectEventKeyType.PRIORITY; - - case "labels": - return ObjectEventKeyType.LABELS; - - case "pinned": - return ObjectEventKeyType.PINNED; - - case "checked": - return ObjectEventKeyType.CHECKED; - - case "project": - return ObjectEventKeyType.PROJECT; - - case "section": - return ObjectEventKeyType.SECTION; - - default: - assert_not_reached (); + case "content": + return ObjectEventKeyType.CONTENT; + + case "description": + return ObjectEventKeyType.DESCRIPTION; + + case "due": + return ObjectEventKeyType.DUE; + + case "priority": + return ObjectEventKeyType.PRIORITY; + + case "labels": + return ObjectEventKeyType.LABELS; + + case "pinned": + return ObjectEventKeyType.PINNED; + + case "checked": + return ObjectEventKeyType.CHECKED; + + case "project": + return ObjectEventKeyType.PROJECT; + + case "section": + return ObjectEventKeyType.SECTION; + + default: + assert_not_reached (); } } public string get_label () { switch (this) { - case ObjectEventKeyType.CONTENT: - return _("Content"); - - case ObjectEventKeyType.DESCRIPTION: - return _("Description"); - - case ObjectEventKeyType.DUE: - return _("Scheduled"); - - case ObjectEventKeyType.PRIORITY: - return _("Priority"); - - case ObjectEventKeyType.LABELS: - return _("Labels"); - - case ObjectEventKeyType.PINNED: - return _("Pin"); - - default: - assert_not_reached (); + case ObjectEventKeyType.CONTENT: + return _("Content"); + + case ObjectEventKeyType.DESCRIPTION: + return _("Description"); + + case ObjectEventKeyType.DUE: + return _("Scheduled"); + + case ObjectEventKeyType.PRIORITY: + return _("Priority"); + + case ObjectEventKeyType.LABELS: + return _("Labels"); + + case ObjectEventKeyType.PINNED: + return _("Pin"); + + default: + assert_not_reached (); } } } @@ -686,20 +686,20 @@ public enum ItemPriority { public static ItemPriority parse (string value) { switch (value) { - case "p1": - return ItemPriority.HIGHT; - - case "p2": - return ItemPriority.MEDIUM; - - case "p3": - return ItemPriority.LOW; - - case "p4": - return ItemPriority.NONE; - - default: - return ItemPriority.NONE; + case "p1": + return ItemPriority.HIGHT; + + case "p2": + return ItemPriority.MEDIUM; + + case "p3": + return ItemPriority.LOW; + + case "p4": + return ItemPriority.NONE; + + default: + return ItemPriority.NONE; } } -} \ No newline at end of file +} diff --git a/core/Objects/ObjectEvent.vala b/core/Objects/ObjectEvent.vala index 74863fefd..ddbea4136 100644 --- a/core/Objects/ObjectEvent.vala +++ b/core/Objects/ObjectEvent.vala @@ -1,123 +1,123 @@ /* -* Copyright © 2024 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 -* License as published by the Free Software Foundation; either -* version 3 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -* Authored by: Alain M. -*/ + * Copyright © 2024 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 + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Alain M. + */ public class Objects.ObjectEvent : GLib.Object { - public int64 id { get; set; default = 0; } - public ObjectEventType event_type { get; set; } - public string event_date { get; set; default = ""; } - public string object_id { get; set; default = ""; } - public string object_type { get; set; default = ""; } - public ObjectEventKeyType object_key { get; set; } - public string object_old_value { get; set; default = ""; } - public string object_new_value { get; set; default = ""; } - public string parent_item_id { get; set; default = ""; } - public string parent_project_id { get; set; default = ""; } + public int64 id { get; set; default = 0; } + public ObjectEventType event_type { get; set; } + public string event_date { get; set; default = ""; } + public string object_id { get; set; default = ""; } + public string object_type { get; set; default = ""; } + public ObjectEventKeyType object_key { get; set; } + public string object_old_value { get; set; default = ""; } + public string object_new_value { get; set; default = ""; } + public string parent_item_id { get; set; default = ""; } + public string parent_project_id { get; set; default = ""; } - public string icon_name { - get { - if (event_type == ObjectEventType.INSERT) { - return "plus-large-symbolic"; - } else if (event_type == ObjectEventType.UPDATE) { - if (object_key == ObjectEventKeyType.CONTENT) { - return "edit-symbolic"; - } else if (object_key == ObjectEventKeyType.DESCRIPTION) { - return "paper-symbolic"; - } else if (object_key == ObjectEventKeyType.DUE) { - return "month-symbolic"; - } else if (object_key == ObjectEventKeyType.PRIORITY) { - return "flag-outline-thick-symbolic"; - } else if (object_key == ObjectEventKeyType.LABELS) { - return "tag-outline-symbolic"; - } else if (object_key == ObjectEventKeyType.PINNED) { - return "pin-symbolic"; - } else if (object_key == ObjectEventKeyType.CHECKED) { - return "check-round-outline-symbolic"; - } else if (object_key == ObjectEventKeyType.SECTION || object_key == ObjectEventKeyType.PROJECT) { - return "arrow3-right-symbolic"; - } - } + public string icon_name { + get { + if (event_type == ObjectEventType.INSERT) { + return "plus-large-symbolic"; + } else if (event_type == ObjectEventType.UPDATE) { + if (object_key == ObjectEventKeyType.CONTENT) { + return "edit-symbolic"; + } else if (object_key == ObjectEventKeyType.DESCRIPTION) { + return "paper-symbolic"; + } else if (object_key == ObjectEventKeyType.DUE) { + return "month-symbolic"; + } else if (object_key == ObjectEventKeyType.PRIORITY) { + return "flag-outline-thick-symbolic"; + } else if (object_key == ObjectEventKeyType.LABELS) { + return "tag-outline-symbolic"; + } else if (object_key == ObjectEventKeyType.PINNED) { + return "pin-symbolic"; + } else if (object_key == ObjectEventKeyType.CHECKED) { + return "check-round-outline-symbolic"; + } else if (object_key == ObjectEventKeyType.SECTION || object_key == ObjectEventKeyType.PROJECT) { + return "arrow3-right-symbolic"; + } + } - return "plus-large-symbolic"; - } - } + return "plus-large-symbolic"; + } + } - GLib.DateTime _datetime; - public GLib.DateTime datetime { - get { - _datetime = Utils.Datetime.get_date_from_string (event_date); - return _datetime; - } - } + GLib.DateTime _datetime; + public GLib.DateTime datetime { + get { + _datetime = Utils.Datetime.get_date_from_string (event_date); + return _datetime; + } + } - GLib.DateTime _date; - public GLib.DateTime date { - get { - _date = Utils.Datetime.format_date (Utils.Datetime.get_date_from_string (event_date)); - return _date; - } - } + GLib.DateTime _date; + public GLib.DateTime date { + get { + _date = Utils.Datetime.format_date (Utils.Datetime.get_date_from_string (event_date)); + return _date; + } + } - string _time; - public string time { - get { - if (Utils.Datetime.is_clock_format_12h ()) { - _time = datetime.format (Granite.DateTime.get_default_time_format (true)); - } else { - _time = datetime.format (Granite.DateTime.get_default_time_format (false)); - } + string _time; + public string time { + get { + if (Utils.Datetime.is_clock_format_12h ()) { + _time = datetime.format (Granite.DateTime.get_default_time_format (true)); + } else { + _time = datetime.format (Granite.DateTime.get_default_time_format (false)); + } - return _time; - } - } + return _time; + } + } - public Objects.DueDate? get_due_value (string value) { - Json.Parser parser = new Json.Parser (); - - try { - parser.load_from_data (value, value.length); - } catch (Error e) { - warning (e.message); - return null; - } + public Objects.DueDate? get_due_value (string value) { + Json.Parser parser = new Json.Parser (); - var due = new Objects.DueDate (); - due.update_from_json (parser.get_root ().get_object ()); + try { + parser.load_from_data (value, value.length); + } catch (Error e) { + warning (e.message); + return null; + } - return due; - } + var due = new Objects.DueDate (); + due.update_from_json (parser.get_root ().get_object ()); - public string get_labels_value (string value) { - string return_value = ""; - Gee.ArrayList labels = Services.Store.instance ().get_labels_by_item_labels (value); + return due; + } - if (labels.size > 0) { - for (int index = 0; index < labels.size; index++) { - if (index < labels.size - 1) { - return_value += labels[index].name + ", "; - } else { - return_value += labels[index].name; - } - } - } + public string get_labels_value (string value) { + string return_value = ""; + Gee.ArrayList labels = Services.Store.instance ().get_labels_by_item_labels (value); - return return_value; - } -} \ No newline at end of file + if (labels.size > 0) { + for (int index = 0; index < labels.size; index++) { + if (index < labels.size - 1) { + return_value += labels[index].name + ", "; + } else { + return_value += labels[index].name; + } + } + } + + return return_value; + } +} diff --git a/core/Objects/Source.vala b/core/Objects/Source.vala index a62ca34fc..92d500299 100644 --- a/core/Objects/Source.vala +++ b/core/Objects/Source.vala @@ -1,190 +1,190 @@ /* -* 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 -* License as published by the Free Software Foundation; either -* version 3 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -* Authored by: Alain M. -*/ + * 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 + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Alain M. + */ public class Objects.Source : Objects.BaseObject { - public SourceType source_type { get; set; default = SourceType.NONE; } - public string added_at { get; set; default = new GLib.DateTime.now_local ().to_string (); } - public string updated_at { get; set; default = ""; } - public bool is_visible { get; set; default = true; } - public int child_order { get; set; default = 0; } - public bool sync_server { get; set; default = false; } - public string last_sync { get; set; default = ""; } - public Objects.SourceData data { get; set; } - public string display_name { get; set; default = ""; } - - Objects.SourceTodoistData _todoist_data; - public Objects.SourceTodoistData todoist_data { - get { - _todoist_data = data as Objects.SourceTodoistData ; - return _todoist_data; - } - } - - Objects.SourceCalDAVData _caldav_data; - public Objects.SourceCalDAVData caldav_data { - get { - _caldav_data = data as Objects.SourceCalDAVData ; - return _caldav_data; - } - } - - public string header_text { - get { - return display_name; - } - } - - string _subheader_text; - public string subheader_text { - get { - if (source_type == SourceType.TODOIST) { - return _("Todoist"); - } - - if (source_type == SourceType.CALDAV) { - _subheader_text = caldav_data.caldav_type.title (); - return _subheader_text; - } - - return ""; - } - } - - public string avatar_path { - get { - return todoist_data.user_image_id; - } - } - - public string user_displayname { - get { - if (source_type == SourceType.TODOIST) { - return todoist_data.user_name; - } - - if (source_type == SourceType.CALDAV) { - return caldav_data.user_displayname; - } - - return ""; - } - } - - public string user_email { - get { - if (source_type == SourceType.TODOIST) { - return todoist_data.user_email; - } - - if (source_type == SourceType.CALDAV) { - return caldav_data.user_email; - } - - return ""; - } - } - - private uint server_timeout = 0; - - public signal void sync_started (); + public SourceType source_type { get; set; default = SourceType.NONE; } + public string added_at { get; set; default = new GLib.DateTime.now_local ().to_string (); } + public string updated_at { get; set; default = ""; } + public bool is_visible { get; set; default = true; } + public int child_order { get; set; default = 0; } + public bool sync_server { get; set; default = false; } + public string last_sync { get; set; default = ""; } + public Objects.SourceData data { get; set; } + public string display_name { get; set; default = ""; } + + Objects.SourceTodoistData _todoist_data; + public Objects.SourceTodoistData todoist_data { + get { + _todoist_data = data as Objects.SourceTodoistData; + return _todoist_data; + } + } + + Objects.SourceCalDAVData _caldav_data; + public Objects.SourceCalDAVData caldav_data { + get { + _caldav_data = data as Objects.SourceCalDAVData; + return _caldav_data; + } + } + + public string header_text { + get { + return display_name; + } + } + + string _subheader_text; + public string subheader_text { + get { + if (source_type == SourceType.TODOIST) { + return _("Todoist"); + } + + if (source_type == SourceType.CALDAV) { + _subheader_text = caldav_data.caldav_type.title (); + return _subheader_text; + } + + return ""; + } + } + + public string avatar_path { + get { + return todoist_data.user_image_id; + } + } + + public string user_displayname { + get { + if (source_type == SourceType.TODOIST) { + return todoist_data.user_name; + } + + if (source_type == SourceType.CALDAV) { + return caldav_data.user_displayname; + } + + return ""; + } + } + + public string user_email { + get { + if (source_type == SourceType.TODOIST) { + return todoist_data.user_email; + } + + if (source_type == SourceType.CALDAV) { + return caldav_data.user_email; + } + + return ""; + } + } + + private uint server_timeout = 0; + + public signal void sync_started (); public signal void sync_finished (); - public Source.from_import_json (Json.Node node) { - id = node.get_object ().get_string_member ("id"); - source_type = SourceType.parse (node.get_object ().get_string_member ("source_type")); - added_at = node.get_object ().get_string_member ("added_at"); - updated_at = node.get_object ().get_string_member ("updated_at"); - is_visible = node.get_object ().get_boolean_member ("is_visible"); - child_order = (int32) node.get_object ().get_int_member ("is_visible"); - sync_server = node.get_object ().get_boolean_member ("sync_server"); - last_sync = node.get_object ().get_string_member ("last_sync"); - display_name = node.get_object ().get_string_member ("display_name"); - - if (source_type == SourceType.TODOIST) { - data = new Objects.SourceTodoistData.from_json (node.get_object ().get_string_member ("data")); - } else if (source_type == SourceType.CALDAV) { - data = new Objects.SourceCalDAVData.from_json (node.get_object ().get_string_member ("data")); - } - } - - public void run_server () { - _run_server (); + public Source.from_import_json (Json.Node node) { + id = node.get_object ().get_string_member ("id"); + source_type = SourceType.parse (node.get_object ().get_string_member ("source_type")); + added_at = node.get_object ().get_string_member ("added_at"); + updated_at = node.get_object ().get_string_member ("updated_at"); + is_visible = node.get_object ().get_boolean_member ("is_visible"); + child_order = (int32) node.get_object ().get_int_member ("is_visible"); + sync_server = node.get_object ().get_boolean_member ("sync_server"); + last_sync = node.get_object ().get_string_member ("last_sync"); + display_name = node.get_object ().get_string_member ("display_name"); + + if (source_type == SourceType.TODOIST) { + data = new Objects.SourceTodoistData.from_json (node.get_object ().get_string_member ("data")); + } else if (source_type == SourceType.CALDAV) { + data = new Objects.SourceCalDAVData.from_json (node.get_object ().get_string_member ("data")); + } + } + + public void run_server () { + _run_server (); server_timeout = Timeout.add_seconds (15 * 60, () => { - if (sync_server) { - _run_server (); - } - + if (sync_server) { + _run_server (); + } + return true; }); } - private void _run_server () { - if (source_type == SourceType.TODOIST) { - Services.Todoist.get_default ().sync.begin (this); - } else if (source_type == SourceType.CALDAV) { - Services.CalDAV.Core.get_default ().sync.begin (this); - } - } + private void _run_server () { + if (source_type == SourceType.TODOIST) { + Services.Todoist.get_default ().sync.begin (this); + } else if (source_type == SourceType.CALDAV) { + Services.CalDAV.Core.get_default ().sync.begin (this); + } + } - public void remove_sync_server () { - // Remove server_timeout + public void remove_sync_server () { + // Remove server_timeout GLib.Source.remove (server_timeout); server_timeout = 0; - } - - public void save () { - updated_at = new GLib.DateTime.now_local ().to_string (); - Services.Store.instance ().update_source (this); - } - - public void delete_source (Gtk.Window window) { - var dialog = new Adw.AlertDialog ( - _("Delete Source?"), - _("This can not be undone") - ); - - dialog.add_response ("cancel", _("Cancel")); - dialog.add_response ("delete", _("Delete")); - dialog.close_response = "cancel"; - dialog.set_response_appearance ("delete", Adw.ResponseAppearance.DESTRUCTIVE); - dialog.present (window); - - dialog.response.connect ((response) => { - if (response == "delete") { - _delete_source (); - } - }); - } - - private void _delete_source () { - // Remove server_timeout - remove_sync_server (); - - // Remove DB - Services.Store.instance ().delete_source (this); - } - - public string to_string () { - return """ + } + + public void save () { + updated_at = new GLib.DateTime.now_local ().to_string (); + Services.Store.instance ().update_source (this); + } + + public void delete_source (Gtk.Window window) { + var dialog = new Adw.AlertDialog ( + _("Delete Source?"), + _("This can not be undone") + ); + + dialog.add_response ("cancel", _("Cancel")); + dialog.add_response ("delete", _("Delete")); + dialog.close_response = "cancel"; + dialog.set_response_appearance ("delete", Adw.ResponseAppearance.DESTRUCTIVE); + dialog.present (window); + + dialog.response.connect ((response) => { + if (response == "delete") { + _delete_source (); + } + }); + } + + private void _delete_source () { + // Remove server_timeout + remove_sync_server (); + + // Remove DB + Services.Store.instance ().delete_source (this); + } + + public string to_string () { + return """ _________________________________ ID: %s DATA: %s @@ -192,187 +192,187 @@ public class Objects.Source : Objects.BaseObject { SYNC_SERVER: %s --------------------------------- """.printf ( - id, - data.to_json (), - source_type.to_string (), - sync_server.to_string () - ); - } + id, + data.to_json (), + source_type.to_string (), + sync_server.to_string () + ); + } } public class Objects.SourceData : GLib.Object { - Json.Builder _builder; - public Json.Builder builder { - get { - if (_builder == null) { - _builder = new Json.Builder (); - } - - return _builder; - } - } - - public virtual string to_json () { - return ""; - } + Json.Builder _builder; + public Json.Builder builder { + get { + if (_builder == null) { + _builder = new Json.Builder (); + } + + return _builder; + } + } + + public virtual string to_json () { + return ""; + } } public class Objects.SourceTodoistData : Objects.SourceData { - public string access_token { get; set; default = ""; } - public string sync_token { get; set; default = ""; } - public string user_image_id { get; set; default = ""; } - public string user_email { get; set; default = ""; } - public string user_name { get; set; default = ""; } - public string user_avatar { get; set; default = ""; } - public bool user_is_premium { get; set; default = false; } - - public SourceTodoistData.from_json (string json) { - Json.Parser parser = new Json.Parser (); - - try { - parser.load_from_data (json, -1); - var object = parser.get_root ().get_object (); - - if (object.has_member ("access_token")) { - access_token = object.get_string_member ("access_token"); - } - - if (object.has_member ("sync_token")) { - sync_token = object.get_string_member ("sync_token"); - } - - if (object.has_member ("user_image_id")) { - user_image_id = object.get_string_member ("user_image_id"); - } - - if (object.has_member ("user_email")) { - user_email = object.get_string_member ("user_email"); - } - - if (object.has_member ("user_name")) { - user_name = object.get_string_member ("user_name"); - } - - if (object.has_member ("user_avatar")) { - user_avatar = object.get_string_member ("user_avatar"); - } - - if (object.has_member ("user_is_premium")) { - user_is_premium = object.get_boolean_member ("user_is_premium"); - } - } catch (Error e) { - debug (e.message); - } - } - - public override string to_json () { - builder.reset (); - - builder.begin_object (); - - builder.set_member_name ("access_token"); - builder.add_string_value (access_token); - - builder.set_member_name ("sync_token"); - builder.add_string_value (sync_token); - - builder.set_member_name ("user_image_id"); - builder.add_string_value (user_image_id); - - builder.set_member_name ("user_email"); - builder.add_string_value (user_email); - - builder.set_member_name ("user_name"); - builder.add_string_value (user_name); - - builder.set_member_name ("user_avatar"); - builder.add_string_value (user_avatar); - - builder.set_member_name ("user_is_premium"); - builder.add_boolean_value (user_is_premium); - - builder.end_object (); - - Json.Generator generator = new Json.Generator (); - Json.Node root = builder.get_root (); - generator.set_root (root); - - return generator.to_data (null); - } + public string access_token { get; set; default = ""; } + public string sync_token { get; set; default = ""; } + public string user_image_id { get; set; default = ""; } + public string user_email { get; set; default = ""; } + public string user_name { get; set; default = ""; } + public string user_avatar { get; set; default = ""; } + public bool user_is_premium { get; set; default = false; } + + public SourceTodoistData.from_json (string json) { + Json.Parser parser = new Json.Parser (); + + try { + parser.load_from_data (json, -1); + var object = parser.get_root ().get_object (); + + if (object.has_member ("access_token")) { + access_token = object.get_string_member ("access_token"); + } + + if (object.has_member ("sync_token")) { + sync_token = object.get_string_member ("sync_token"); + } + + if (object.has_member ("user_image_id")) { + user_image_id = object.get_string_member ("user_image_id"); + } + + if (object.has_member ("user_email")) { + user_email = object.get_string_member ("user_email"); + } + + if (object.has_member ("user_name")) { + user_name = object.get_string_member ("user_name"); + } + + if (object.has_member ("user_avatar")) { + user_avatar = object.get_string_member ("user_avatar"); + } + + if (object.has_member ("user_is_premium")) { + user_is_premium = object.get_boolean_member ("user_is_premium"); + } + } catch (Error e) { + debug (e.message); + } + } + + public override string to_json () { + builder.reset (); + + builder.begin_object (); + + builder.set_member_name ("access_token"); + builder.add_string_value (access_token); + + builder.set_member_name ("sync_token"); + builder.add_string_value (sync_token); + + builder.set_member_name ("user_image_id"); + builder.add_string_value (user_image_id); + + builder.set_member_name ("user_email"); + builder.add_string_value (user_email); + + builder.set_member_name ("user_name"); + builder.add_string_value (user_name); + + builder.set_member_name ("user_avatar"); + builder.add_string_value (user_avatar); + + builder.set_member_name ("user_is_premium"); + builder.add_boolean_value (user_is_premium); + + builder.end_object (); + + Json.Generator generator = new Json.Generator (); + Json.Node root = builder.get_root (); + generator.set_root (root); + + return generator.to_data (null); + } } public class Objects.SourceCalDAVData : Objects.SourceData { - public string server_url { get; set; default = ""; } - public string username { get; set; default = ""; } - public string credentials { get; set; default = ""; } - public string user_displayname { get; set; default = ""; } - public string user_email { get; set; default = ""; } - public CalDAVType caldav_type { get; set; default = CalDAVType.NEXTCLOUD; } - - public SourceCalDAVData.from_json (string json) { - Json.Parser parser = new Json.Parser (); - - try { - parser.load_from_data (json, -1); - var object = parser.get_root ().get_object (); - - if (object.has_member ("server_url")) { - server_url = object.get_string_member ("server_url"); - } - - if (object.has_member ("username")) { - username = object.get_string_member ("username"); - } - - if (object.has_member ("credentials")) { - credentials = object.get_string_member ("credentials"); - } - - if (object.has_member ("user_displayname")) { - user_displayname = object.get_string_member ("user_displayname"); - } - - if (object.has_member ("user_email")) { - user_email = object.get_string_member ("user_email"); - } - - if (object.has_member ("caldav_type")) { - caldav_type = CalDAVType.parse (object.get_string_member ("caldav_type")); - } - } catch (Error e) { - debug (e.message); - } - } - - public override string to_json () { - builder.reset (); - - builder.begin_object (); - - builder.set_member_name ("server_url"); - builder.add_string_value (server_url); - - builder.set_member_name ("username"); - builder.add_string_value (username); - - builder.set_member_name ("credentials"); - builder.add_string_value (credentials); - - builder.set_member_name ("caldav_type"); - builder.add_string_value (caldav_type.to_string ()); - - builder.set_member_name ("user_displayname"); - builder.add_string_value (user_displayname); - - builder.set_member_name ("user_email"); - builder.add_string_value (user_email); - - builder.end_object (); - - Json.Generator generator = new Json.Generator (); - Json.Node root = builder.get_root (); - generator.set_root (root); - - return generator.to_data (null); - } -} \ No newline at end of file + public string server_url { get; set; default = ""; } + public string username { get; set; default = ""; } + public string credentials { get; set; default = ""; } + public string user_displayname { get; set; default = ""; } + public string user_email { get; set; default = ""; } + public CalDAVType caldav_type { get; set; default = CalDAVType.NEXTCLOUD; } + + public SourceCalDAVData.from_json (string json) { + Json.Parser parser = new Json.Parser (); + + try { + parser.load_from_data (json, -1); + var object = parser.get_root ().get_object (); + + if (object.has_member ("server_url")) { + server_url = object.get_string_member ("server_url"); + } + + if (object.has_member ("username")) { + username = object.get_string_member ("username"); + } + + if (object.has_member ("credentials")) { + credentials = object.get_string_member ("credentials"); + } + + if (object.has_member ("user_displayname")) { + user_displayname = object.get_string_member ("user_displayname"); + } + + if (object.has_member ("user_email")) { + user_email = object.get_string_member ("user_email"); + } + + if (object.has_member ("caldav_type")) { + caldav_type = CalDAVType.parse (object.get_string_member ("caldav_type")); + } + } catch (Error e) { + debug (e.message); + } + } + + public override string to_json () { + builder.reset (); + + builder.begin_object (); + + builder.set_member_name ("server_url"); + builder.add_string_value (server_url); + + builder.set_member_name ("username"); + builder.add_string_value (username); + + builder.set_member_name ("credentials"); + builder.add_string_value (credentials); + + builder.set_member_name ("caldav_type"); + builder.add_string_value (caldav_type.to_string ()); + + builder.set_member_name ("user_displayname"); + builder.add_string_value (user_displayname); + + builder.set_member_name ("user_email"); + builder.add_string_value (user_email); + + builder.end_object (); + + Json.Generator generator = new Json.Generator (); + Json.Node root = builder.get_root (); + generator.set_root (root); + + return generator.to_data (null); + } +} diff --git a/core/QuickAdd.vala b/core/QuickAdd.vala index 1377e89bb..800376a4c 100644 --- a/core/QuickAdd.vala +++ b/core/QuickAdd.vala @@ -60,7 +60,7 @@ public class Layouts.QuickAdd : Adw.Bin { ); } - ~QuickAdd() { + ~QuickAdd () { print ("Destroying Layouts.QuickAdd\n"); } @@ -335,7 +335,7 @@ public class Layouts.QuickAdd : Adw.Bin { label_button.labels_changed.connect (set_labels); label_button.picker_opened.connect ((active) => { parent_can_close (!active); - + if (!active) { Timeout.add (250, () => { labels_picker_activate_shortcut = false; @@ -353,7 +353,7 @@ public class Layouts.QuickAdd : Adw.Bin { remove_entry_char ("!"); } }); - + reminder_button.picker_opened.connect ((active) => { parent_can_close (!active); @@ -628,7 +628,7 @@ public class Layouts.QuickAdd : Adw.Bin { private void remove_entry_char (string value) { string current_text = content_entry.get_text (); - int at_position = content_entry.text.index_of(value); + int at_position = content_entry.text.index_of (value); if (at_position != -1) { string before_at = current_text.substring (0, at_position); string after_at = current_text.substring (at_position + 1); @@ -698,4 +698,4 @@ public class Layouts.QuickAdd : Adw.Bin { entry_focus (); } } -} \ No newline at end of file +} diff --git a/core/Services/CalDAV/Providers/Nextcloud.vala b/core/Services/CalDAV/Providers/Nextcloud.vala index aba3e0c2e..e35d25fe8 100644 --- a/core/Services/CalDAV/Providers/Nextcloud.vala +++ b/core/Services/CalDAV/Providers/Nextcloud.vala @@ -323,7 +323,7 @@ public class Services.CalDAV.Providers.Nextcloud : Services.CalDAV.Providers.Bas } public override string get_all_taskslist_url (string server_url, string username) { - return "%s/calendars/%s/".printf (server_url, username);; + return "%s/calendars/%s/".printf (server_url, username); } public override Gee.ArrayList get_projects_by_doc (GXml.DomDocument doc, Objects.Source source) { diff --git a/core/Services/CalDAV/Providers/ProviderBase.vala b/core/Services/CalDAV/Providers/ProviderBase.vala index 9f6b3c1fa..80c05948e 100644 --- a/core/Services/CalDAV/Providers/ProviderBase.vala +++ b/core/Services/CalDAV/Providers/ProviderBase.vala @@ -1,33 +1,33 @@ public class Services.CalDAV.Providers.Base { - // vala-lint=naming-convention - public virtual string LOGIN_REQUEST { get; set; default = ""; } + // vala-lint=naming-convention + public virtual string LOGIN_REQUEST { get; set; default = ""; } - // vala-lint=naming-convention - public virtual string USER_DATA_REQUEST { get; set; default = ""; } + // vala-lint=naming-convention + public virtual string USER_DATA_REQUEST { get; set; default = ""; } - public virtual string TASKLIST_REQUEST { get; set; default = ""; } + public virtual string TASKLIST_REQUEST { get; set; default = ""; } - public virtual string get_server_url (string server_url, string username, string password) { - return ""; - } + public virtual string get_server_url (string server_url, string username, string password) { + return ""; + } - public virtual string get_account_url (string server_url, string username) { - return ""; - } + public virtual string get_account_url (string server_url, string username) { + return ""; + } - public virtual void set_user_data (GXml.DomDocument doc, Objects.Source source) { + public virtual void set_user_data (GXml.DomDocument doc, Objects.Source source) { - } + } - public virtual string get_all_taskslist_url (string server_url, string username) { - return ""; - } + public virtual string get_all_taskslist_url (string server_url, string username) { + return ""; + } - public virtual Gee.ArrayList get_projects_by_doc (GXml.DomDocument doc, Objects.Source source) { - return new Gee.ArrayList (); - } + public virtual Gee.ArrayList get_projects_by_doc (GXml.DomDocument doc, Objects.Source source) { + return new Gee.ArrayList (); + } - public virtual bool is_vtodo_calendar (GXml.DomElement element) { - return false; - } -} \ No newline at end of file + public virtual bool is_vtodo_calendar (GXml.DomElement element) { + return false; + } +} diff --git a/core/Services/Store.vala b/core/Services/Store.vala index 6f7ece992..70862a783 100644 --- a/core/Services/Store.vala +++ b/core/Services/Store.vala @@ -1,1255 +1,1255 @@ /* -* Copyright © 2024 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 -* License as published by the Free Software Foundation; either -* version 3 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -* Authored by: Alain M. -*/ + * Copyright © 2024 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 + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Alain M. + */ public class Services.Store : GLib.Object { - static GLib.Once _instance; - public static unowned Services.Store instance () { - return _instance.once (() => { - return new Services.Store (); - }); - } - - public signal void source_added (Objects.Source source); - public signal void source_deleted (Objects.Source source); - public signal void source_updated (Objects.Source source); - - public signal void project_added (Objects.Project project); - public signal void project_updated (Objects.Project project); - public signal void project_deleted (Objects.Project project); - public signal void project_archived (Objects.Project project); - public signal void project_unarchived (Objects.Project project); - - public signal void label_added (Objects.Label label); - public signal void label_updated (Objects.Label label); - public signal void label_deleted (Objects.Label label); - - public signal void section_deleted (Objects.Section section); - public signal void section_moved (Objects.Section section, string old_project_id); - public signal void section_archived (Objects.Section section); - public signal void section_unarchived (Objects.Section section); - - public signal void item_deleted (Objects.Item item); - public signal void item_added (Objects.Item item, bool insert = true); - public signal void item_updated (Objects.Item item, string update_id); - public signal void item_archived (Objects.Item item); - public signal void item_unarchived (Objects.Item item); - public signal void item_pin_change (Objects.Item item); - - public signal void item_label_added (Objects.Label label); - public signal void item_label_deleted (Objects.Label label); - - public signal void reminder_added (Objects.Reminder reminder); - public signal void reminder_deleted (Objects.Reminder reminder); - - public signal void attachment_deleted (Objects.Attachment attachment); - - Gee.ArrayList _sources = null; - public Gee.ArrayList sources { - get { - if (_sources == null) { - _sources = Services.Database.get_default ().get_sources_collection (); - } - - return _sources; - } - } - - Gee.ArrayList _projects = null; - public Gee.ArrayList projects { - get { - if (_projects == null) { - _projects = Services.Database.get_default ().get_projects_collection (); - } - return _projects; - } - } - - Gee.ArrayList _sections = null; - public Gee.ArrayList sections { - get { - if (_sections == null) { - _sections = Services.Database.get_default ().get_sections_collection (); - } - return _sections; - } - } - - Gee.ArrayList _items = null; - public Gee.ArrayList items { - get { - if (_items == null) { - _items = Services.Database.get_default ().get_items_collection (); - } - return _items; - } - } - - Gee.ArrayList _labels = null; - public Gee.ArrayList labels { - get { - if (_labels == null) { - _labels = Services.Database.get_default ().get_labels_collection (); - } - return _labels; - } - } - - Gee.ArrayList _reminders = null; - public Gee.ArrayList reminders { - get { - if (_reminders == null) { - _reminders = Services.Database.get_default ().get_reminders_collection (); - } - - return _reminders; - } - } - - Gee.ArrayList _attachments = null; - public Gee.ArrayList attachments { - get { - if (_attachments == null) { - _attachments = Services.Database.get_default ().get_attachments_collection (); - } - - return _attachments; - } - } - - public bool is_database_empty () { - return projects.size <= 0; - } - - public bool is_sources_empty () { - return sources.size <= 0; - } - - - public Gee.ArrayList get_collection_by_type (Objects.BaseObject base_object) { - if (base_object is Objects.Project) { - return projects; - } else if (base_object is Objects.Section) { - return sections; - } else if (base_object is Objects.Item) { - return items; - } else if (base_object is Objects.Label) { - return labels; - } - - return new Gee.ArrayList (); - } - - /* - * Sources - */ - - public void insert_source (Objects.Source source) { - source.child_order = sources.size + 1; - if (Services.Database.get_default ().insert_source (source)) { - sources.add (source); - source_added (source); - } - } - - public void delete_source (Objects.Source source) { - if (Services.Database.get_default ().delete_source (source)) { - foreach (Objects.Project project in get_projects_by_source (source.id)) { - delete_project (project); - } - - source.deleted (); - source_deleted (source); - _sources.remove (source); - } - } - - public void update_source (Objects.Source source) { - if (Services.Database.get_default ().update_source (source)) { - source.updated (); - source_updated (source); - } - } - - public Objects.Source get_source (string id) { - Objects.Source? return_value = null; - lock (_sources) { - foreach (var source in sources) { - if (source.id == id) { - return_value = source; - break; - } - } - - return return_value; - } - } - - public bool source_todoist_exists (string email) { - bool return_value = false; - - lock (_sources) { - foreach (Objects.Source source in sources) { - if (source.source_type == SourceType.TODOIST && source.todoist_data.user_email == email) { - return_value = true; - break; - } - } - - return return_value; - } - } - - public bool source_caldav_exists (string server_url, string username) { - bool return_value = false; - - lock (_sources) { - foreach (Objects.Source source in sources) { - if (source.source_type == SourceType.CALDAV && - source.caldav_data.server_url == server_url && - source.caldav_data.username == username) { - return_value = true; - break; - } - } - - return return_value; - } - } - - /* - * Projects - */ - - public void insert_project (Objects.Project project) { - if (Services.Database.get_default ().insert_project (project)) { - projects.add (project); - - if (project.parent == null) { - project_added (project); - } else { - project.parent.subproject_added (project); - } - } - } - - public Gee.ArrayList get_projects_by_source (string source_id) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_projects) { - foreach (var project in projects) { - if (project.source_id == source_id) { - return_value.add (project); - } - } - - return return_value; - } - } - - public void delete_project (Objects.Project project) { - if (Services.Database.get_default ().delete_project (project)) { - foreach (Objects.Section section in get_sections_by_project (project)) { - delete_section (section); - } - - foreach (Objects.Item item in get_items_by_project (project)) { - delete_item (item); - } - - foreach (Objects.Project subproject in get_subprojects (project)) { - delete_project (subproject); - } - - project.deleted (); - project_deleted (project); - _projects.remove (project); - } - } - - public void archive_project (Objects.Project project) { - if (Services.Database.get_default ().archive_project (project)) { - foreach (Objects.Item item in project.items) { - archive_item (item, project.is_archived); - } - - foreach (Objects.Section section in project.sections) { - section.is_archived = project.is_archived; - archive_section (section); - } - - if (project.is_archived) { - project.archived (); - project_archived (project); - } else { - project.unarchived (); - project_unarchived (project); - } - } - } - - public void update_project (Objects.Project project) { - if (Services.Database.get_default ().update_project (project)) { - project.updated (); - project_updated (project); - } - } - - public void update_project_id (string current_id, string new_id) { - if (Services.Database.get_default ().update_project_id (current_id, new_id)) { - Objects.Project? project = get_project (current_id); - if (project != null) { - project.id = new_id; - } - - if (Services.Database.get_default ().update_project_section_id (current_id, new_id)) { - foreach (var section in sections) { - if (section.project_id == current_id) { - section.project_id = new_id; - } - } - - if (Services.Database.get_default ().update_project_item_id (current_id, new_id)) { - foreach (var item in items) { - if (item.project_id == current_id) { - item.project_id = new_id; - } - } - } - } - } - } - - public Objects.Project get_inbox_project () { - Objects.Project? return_value = null; - - lock (_projects) { - foreach (var project in projects) { - if (project.is_inbox_project) { - return_value = project; - break; - } - } - - return return_value; - } - } - - public Objects.Project get_project (string id) { - Objects.Project? return_value = null; - lock (_projects) { - foreach (var project in projects) { - if (project.id == id) { - return_value = project; - break; - } - } - - return return_value; - } - } - - public Gee.ArrayList get_subprojects (Objects.Project _project) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_projects) { - foreach (var project in projects) { - if (project.parent_id == _project.id) { - return_value.add (project); - } - } - } - - return return_value; - } - - public int next_project_child_order (Objects.Source source) { - int child_order = 0; - - lock (_projects) { - foreach (var project in projects) { - if (project.source_id == source.id && !project.is_deleted) { - child_order++; - } - } - - return child_order; - } - } - - /* - * Sections - */ - - public void insert_section (Objects.Section section) { - if (Services.Database.get_default ().insert_section (section)) { - sections.add (section); - section.project.section_added (section); - } - } - - public void update_section (Objects.Section section) { - if (Services.Database.get_default ().update_section (section)) { - section.updated (); - } - } - - public void delete_section (Objects.Section section) { - if (Services.Database.get_default ().delete_section (section)) { - foreach (Objects.Item item in section.items) { - delete_item (item); - } - - section.deleted (); - section_deleted (section); - _sections.remove (section); - } - } - - public void move_section (Objects.Section section, string old_project_id) { - if (Services.Database.get_default ().move_section (section, old_project_id)) { - if (Services.Database.get_default ().move_section_items (section)) { - foreach (Objects.Item item in section.items) { - item.project_id = section.project_id; - } - - section_moved (section, old_project_id); - } - } - } - - public void update_section_id (string current_id, string new_id) { - if (Services.Database.get_default ().update_section_id (current_id, new_id)) { - foreach (var section in sections) { - if (section.id == current_id) { - section.id = new_id; - } - } - - if (Services.Database.get_default ().update_section_item_id (current_id, new_id)) { - foreach (var item in items) { - if (item.section_id == current_id) { - item.section_id = new_id; - } - } - } - } - } - - public void archive_section (Objects.Section section) { - if (Services.Database.get_default ().archive_section (section)) { - foreach (Objects.Item item in section.items) { - archive_item (item, section.is_archived); - } - - if (section.is_archived) { - section.archived (); - section_archived (section); - } else { - section.unarchived (); - section_unarchived (section); - } - } - } - - public Gee.ArrayList get_sections_by_project (Objects.Project project) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_sections) { - foreach (var section in sections) { - if (section.project_id == project.id) { - return_value.add (section); - } - } - } - - return return_value; - } - - public Gee.ArrayList get_sections_archived_by_project (Objects.Project project) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_sections) { - foreach (var section in sections) { - if (section.project_id == project.id && section.was_archived ()) { - return_value.add (section); - } - } - } - - return return_value; - } - - public Objects.Section get_section (string id) { - Objects.Section? return_value = null; - lock (_sections) { - foreach (var section in sections) { - if (section.id == id) { - return_value = section; - break; - } - } - - return return_value; - } - } - - /* - * Items - */ - - public void insert_item (Objects.Item item, bool insert = true) { - if (Services.Database.get_default ().insert_item (item, insert)) { - add_item (item, insert); - } - } - - public void add_item (Objects.Item item, bool insert = true) { - items.add (item); - item_added (item, insert); - - if (insert) { - if (item.parent_id != "") { - item.parent.item_added (item); - } else { - if (item.section_id == "") { - item.project.item_added (item); - } else { - item.section.item_added (item); - } - } - } - - Services.EventBus.get_default ().update_items_position (item.project_id, item.section_id); - } - - public void update_item (Objects.Item item, string update_id = "") { - if (Services.Database.get_default ().update_item (item, update_id)) { - item.updated (update_id); - item_updated (item, update_id); - } - } - - public void update_item_pin (Objects.Item item) { - if (Services.Database.get_default ().update_item (item)) { - item_pin_change (item); - item.pin_updated (); - } - } - - public void delete_item (Objects.Item item) { - if (Services.Database.get_default ().delete_item (item)) { - foreach (Objects.Item subitem in get_subitems (item)) { - delete_item (subitem); - } - - item.deleted (); - item_deleted (item); - _items.remove (item); - - item.project.item_deleted (item); - if (item.has_section) { - item.section.item_deleted (item); - } - } - } - - public void move_item (Objects.Item item, string old_section_id = "", string old_parent_id = "") { - if (Services.Database.get_default ().move_item (item)) { - foreach (Objects.Item subitem in get_subitems (item)) { - subitem.project_id = item.project_id; - move_item (subitem); - } - - get_section (item.section_id).update_count (); - get_section (old_section_id).update_count (); - - item.updated (); - item_updated (item, ""); - } - } - - public void complete_item (Objects.Item item, bool old_checked, bool complete_subitems = true) { - if (Services.Database.get_default ().complete_item (item, old_checked)) { - if (complete_subitems) { - foreach (Objects.Item subitem in get_subitems (item)) { - subitem.checked = item.checked; - subitem.completed_at = item.completed_at; - complete_item (subitem, old_checked); - } - } - - item.updated (); - item_updated (item, ""); - - Services.EventBus.get_default ().checked_toggled (item, old_checked); - - if (item.has_parent && !item.checked) { - item.parent.checked = item.checked; - item.parent.completed_at = item.completed_at; - - complete_item (item.parent, old_checked, false); - } - } - } - - public void archive_item (Objects.Item item, bool is_archived) { - if (is_archived) { - item.archived (); - item_archived (item); - } else { - item.unarchived (); - item_unarchived (item); - } - - foreach (Objects.Item subitem in get_subitems (item)) { - archive_item (subitem, is_archived); - } - } - - public void update_item_id (string current_id, string new_id) { - if (Services.Database.get_default ().update_item_id (current_id, new_id)) { - foreach (var item in items) { - if (item.id == current_id) { - item.id = new_id; - } - } - - if (Services.Database.get_default ().update_item_child_id (current_id, new_id)) { - foreach (var item in items) { - if (item.parent_id == current_id) { - item.parent_id = new_id; - } - } - } - } - } - - public int next_item_child_order (string project_id, string section_id) { - int child_order = 0; - - lock (_items) { - foreach (var item in items) { - if (item.project_id == project_id && item.section_id == section_id) { - child_order++; - } - } - - return child_order; - } - } - - public Objects.Item get_item (string id) { - Objects.Item? return_value = null; - lock (_items) { - foreach (var item in items) { - if (item.id == id) { - return_value = item; - break; - } - } - - return return_value; - } - } - - public Objects.Item get_item_by_ics (string ics) { - Objects.Item? return_value = null; - lock (_items) { - foreach (var item in items) { - if (item.ics == ics) { - return_value = item; - break; - } - } - - return return_value; - } - } - - public Gee.ArrayList get_item_by_baseobject (Objects.BaseObject object) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (var item in items) { - if (object is Objects.Project) { - if (item.project_id == object.id && item.section_id == "" && !item.has_parent) { - return_value.add (item); - } - } - - if (object is Objects.Section) { - if (item.section_id == object.id && !item.has_parent) { - return_value.add (item); - } - } - } - } - - return return_value; - } - - public Gee.ArrayList get_items_checked () { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.checked) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_checked_by_project (Objects.Project project) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.project_id == project.id && item.checked) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_subitems (Objects.Item i) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (var item in items) { - if (item.parent_id == i.id) { - return_value.add (item); - } - } - } - - return return_value; - } - - public Gee.ArrayList get_subitems_uncomplete (Objects.Item i) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (var item in items) { - if (item.parent_id == i.id && !item.checked) { - return_value.add (item); - } - } - } - - return return_value; - } - - public Gee.ArrayList get_items_by_project (Objects.Project project) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.exists_project (project)) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_by_project_pinned (Objects.Project project) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.exists_project (project) && item.pinned) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_by_date (GLib.DateTime date, bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (valid_item_by_date (item, date, checked)) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_no_date (bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (!item.has_due && item.checked == checked) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_repeating (bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.has_due && item.due.is_recurring && item.checked == checked && !item.was_archived ()) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_by_date_range (GLib.DateTime start_date, GLib.DateTime end_date, bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (valid_item_by_date_range (item, start_date, end_date, checked)) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_by_month (GLib.DateTime date, bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (valid_item_by_month (item, date, checked)) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_pinned (bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.pinned && item.checked == checked && !item.was_archived ()) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_by_priority (int priority, bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.priority == priority && item.checked == checked && !item.was_archived ()) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_completed () { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.checked && !item.was_archived ()) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_by_label (Objects.Label label, bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.has_label (label.id) && item.checked == checked && !item.was_archived ()) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_unlabeled (bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.labels.size <= 0 && item.checked == checked && !item.was_archived ()) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_by_scheduled (bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.has_due && - !item.was_archived () && - item.checked == checked && - item.due.datetime.compare (new GLib.DateTime.now_local ()) > 0) { - return_value.add (item); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_items_no_parent (bool checked = true) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (!item.was_archived () && - item.checked == checked && - !item.has_parent) { - return_value.add (item); - } - } - - return return_value; - } - } - - public bool valid_item_by_date (Objects.Item item, GLib.DateTime date, bool checked = true) { - if (!item.has_due || item.was_archived ()) { - return false; - } - - return (item.checked == checked && Utils.Datetime.is_same_day (item.due.datetime, date)); - } - - public bool valid_item_by_date_range (Objects.Item item, GLib.DateTime start_date, GLib.DateTime end_date, bool checked = true) { - if (!item.has_due || item.was_archived ()) { - return false; - } - - var date = Utils.Datetime.get_date_only (item.due.datetime); - var start = Utils.Datetime.get_date_only (start_date); - var end = Utils.Datetime.get_date_only (end_date); - - return (item.checked == checked && date.compare (start) >= 0 && date.compare (end) <= 0); - } - - public bool valid_item_by_month (Objects.Item item, GLib.DateTime date, bool checked = true) { - if (!item.has_due || item.was_archived ()) { - return false; - } - - return (item.checked == checked && item.due.datetime.get_month () == date.get_month () && - item.due.datetime.get_year () == date.get_year ()); - } - - public Gee.ArrayList get_items_by_overdeue_view (bool checked = true) { - GLib.DateTime date_now = new GLib.DateTime.now_local (); - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.has_due && - !item.was_archived () && - item.checked == checked && - item.due.datetime.compare (date_now) < 0 && - !Utils.Datetime.is_same_day (item.due.datetime, date_now)) { - return_value.add (item); - } - } - - return return_value; - } - } - - public bool valid_item_by_overdue (Objects.Item item, GLib.DateTime date, bool checked = true) { - if (!item.has_due || item.was_archived ()) { - return false; - } - - return (item.checked == checked && - item.due.datetime.compare (new GLib.DateTime.now_local ()) < 0 && - !Utils.Datetime.is_same_day (item.due.datetime, new GLib.DateTime.now_local ())); - } - - /* - * Labels - */ - - public void insert_label (Objects.Label label) { - if (Services.Database.get_default ().insert_label (label)) { - labels.add (label); - label_added (label); - } - } - - public void delete_label (Objects.Label label) { - if (Services.Database.get_default ().delete_label (label)) { - label.deleted (); - label_deleted (label); - _labels.remove (label); - } - } - - public void update_label (Objects.Label label) { - if (Services.Database.get_default ().update_label (label)) { - label.updated (); - label_updated (label); - } - } - - public Gee.ArrayList get_labels_by_item_labels (string labels) { - Gee.ArrayList return_value = new Gee.ArrayList (); - - foreach (string id in labels.split (";")) { - Objects.Label? label = get_label (id); - if (label != null) { - return_value.add (label); - } - } - - return return_value; - } - - public Gee.ArrayList get_items_has_labels () { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (Objects.Item item in items) { - if (item.has_labels () && !item.completed && !item.was_archived ()) { - return_value.add (item); - } - } - - return return_value; - } - } - - public bool label_exists (string id) { - bool return_value = false; - lock (_labels) { - foreach (var label in _labels) { - if (label.id == id) { - return_value = true; - break; - } - } - - return return_value; - } - } - - public Objects.Label get_label (string id) { - Objects.Label? return_value = null; - lock (_labels) { - foreach (var label in labels) { - if (label.id == id) { - return_value = label; - break; - } - } - - return return_value; - } - } - - public Objects.Label? get_label_by_name (string name, bool lowercase = false, string source_id) { - lock (_labels) { - string compare_name = lowercase ? name.down () : name; - - foreach (var label in labels) { - string label_name = lowercase ? label.name.down () : label.name; - if (label.source_id == source_id && label_name == compare_name) { - return label; - } - } - - return null; - } - } - - public Gee.ArrayList get_labels_by_source (string source_id) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_labels) { - foreach (var label in labels) { - if (label.source_id == source_id) { - return_value.add (label); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_all_labels_by_search (string search_text) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_labels) { - foreach (var label in labels) { - if (search_text.down () in label.name.down ()) { - return_value.add (label); - } - } - - return return_value; - } - } - - /* - * Quick Find - */ - - public Gee.ArrayList get_all_projects_by_search (string search_text) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_projects) { - foreach (var project in projects) { - if (search_text.down () in project.name.down () && !project.is_archived) { - return_value.add (project); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_all_sections_by_search (string search_text) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_projects) { - foreach (var section in sections) { - if (search_text.down () in section.name.down () && !section.was_archived ()) { - return_value.add (section); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_all_projects_archived () { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_projects) { - foreach (var project in projects) { - if (project.is_archived) { - return_value.add (project); - } - } - - return return_value; - } - } - - public Gee.ArrayList get_all_items_by_search (string search_text) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_items) { - foreach (var item in items) { - if (!item.checked && !item.was_archived () && (search_text.down () in item.content.down () || - search_text.down () in item.description.down ())) { - return_value.add (item); - } - } - - return return_value; - } - } - - // Reminders - public void insert_reminder (Objects.Reminder reminder) { - if (Services.Database.get_default ().insert_reminder (reminder)) { - reminders.add (reminder); - reminder_added (reminder); - reminder.item.reminder_added (reminder); - } - } - - public void delete_reminder (Objects.Reminder reminder) { - if (Services.Database.get_default ().delete_reminder (reminder)) { - reminder.deleted (); - reminder_deleted (reminder); - _reminders.remove (reminder); - - reminder.item.reminder_deleted (reminder); - - } - } - - public Gee.ArrayList get_reminders_by_item (Objects.Item item) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_reminders) { - foreach (var reminder in reminders) { - if (reminder.item_id == item.id) { - return_value.add (reminder); - } - } - - return return_value; - } - } - - public Objects.Reminder get_reminder (string id) { - Objects.Reminder? return_value = null; - lock (_reminders) { - foreach (var reminder in reminders) { - if (reminder.id == id) { - return_value = reminder; - break; - } - } - - return return_value; - } - } - - // Atrachments - public void insert_attachment (Objects.Attachment attachment) { - if (Services.Database.get_default ().insert_attachment (attachment)) { - attachments.add (attachment); - attachment.item.attachment_added (attachment); - } - } - - public void delete_attachment (Objects.Attachment attachment) { - if (Services.Database.get_default ().delete_attachment (attachment)) { - attachment.deleted (); - attachment_deleted (attachment); - _attachments.remove (attachment); - - attachment.item.attachment_deleted (attachment); - } - } - - public Gee.ArrayList get_attachments_by_item (Objects.Item item) { - Gee.ArrayList return_value = new Gee.ArrayList (); - lock (_attachments) { - foreach (var attachment in attachments) { - if (attachment.item_id == item.id) { - return_value.add (attachment); - } - } - - return return_value; - } - } -} \ No newline at end of file + static GLib.Once _instance; + public static unowned Services.Store instance () { + return _instance.once (() => { + return new Services.Store (); + }); + } + + public signal void source_added (Objects.Source source); + public signal void source_deleted (Objects.Source source); + public signal void source_updated (Objects.Source source); + + public signal void project_added (Objects.Project project); + public signal void project_updated (Objects.Project project); + public signal void project_deleted (Objects.Project project); + public signal void project_archived (Objects.Project project); + public signal void project_unarchived (Objects.Project project); + + public signal void label_added (Objects.Label label); + public signal void label_updated (Objects.Label label); + public signal void label_deleted (Objects.Label label); + + public signal void section_deleted (Objects.Section section); + public signal void section_moved (Objects.Section section, string old_project_id); + public signal void section_archived (Objects.Section section); + public signal void section_unarchived (Objects.Section section); + + public signal void item_deleted (Objects.Item item); + public signal void item_added (Objects.Item item, bool insert = true); + public signal void item_updated (Objects.Item item, string update_id); + public signal void item_archived (Objects.Item item); + public signal void item_unarchived (Objects.Item item); + public signal void item_pin_change (Objects.Item item); + + public signal void item_label_added (Objects.Label label); + public signal void item_label_deleted (Objects.Label label); + + public signal void reminder_added (Objects.Reminder reminder); + public signal void reminder_deleted (Objects.Reminder reminder); + + public signal void attachment_deleted (Objects.Attachment attachment); + + Gee.ArrayList _sources = null; + public Gee.ArrayList sources { + get { + if (_sources == null) { + _sources = Services.Database.get_default ().get_sources_collection (); + } + + return _sources; + } + } + + Gee.ArrayList _projects = null; + public Gee.ArrayList projects { + get { + if (_projects == null) { + _projects = Services.Database.get_default ().get_projects_collection (); + } + return _projects; + } + } + + Gee.ArrayList _sections = null; + public Gee.ArrayList sections { + get { + if (_sections == null) { + _sections = Services.Database.get_default ().get_sections_collection (); + } + return _sections; + } + } + + Gee.ArrayList _items = null; + public Gee.ArrayList items { + get { + if (_items == null) { + _items = Services.Database.get_default ().get_items_collection (); + } + return _items; + } + } + + Gee.ArrayList _labels = null; + public Gee.ArrayList labels { + get { + if (_labels == null) { + _labels = Services.Database.get_default ().get_labels_collection (); + } + return _labels; + } + } + + Gee.ArrayList _reminders = null; + public Gee.ArrayList reminders { + get { + if (_reminders == null) { + _reminders = Services.Database.get_default ().get_reminders_collection (); + } + + return _reminders; + } + } + + Gee.ArrayList _attachments = null; + public Gee.ArrayList attachments { + get { + if (_attachments == null) { + _attachments = Services.Database.get_default ().get_attachments_collection (); + } + + return _attachments; + } + } + + public bool is_database_empty () { + return projects.size <= 0; + } + + public bool is_sources_empty () { + return sources.size <= 0; + } + + + public Gee.ArrayList get_collection_by_type (Objects.BaseObject base_object) { + if (base_object is Objects.Project) { + return projects; + } else if (base_object is Objects.Section) { + return sections; + } else if (base_object is Objects.Item) { + return items; + } else if (base_object is Objects.Label) { + return labels; + } + + return new Gee.ArrayList (); + } + + /* + * Sources + */ + + public void insert_source (Objects.Source source) { + source.child_order = sources.size + 1; + if (Services.Database.get_default ().insert_source (source)) { + sources.add (source); + source_added (source); + } + } + + public void delete_source (Objects.Source source) { + if (Services.Database.get_default ().delete_source (source)) { + foreach (Objects.Project project in get_projects_by_source (source.id)) { + delete_project (project); + } + + source.deleted (); + source_deleted (source); + _sources.remove (source); + } + } + + public void update_source (Objects.Source source) { + if (Services.Database.get_default ().update_source (source)) { + source.updated (); + source_updated (source); + } + } + + public Objects.Source get_source (string id) { + Objects.Source? return_value = null; + lock (_sources) { + foreach (var source in sources) { + if (source.id == id) { + return_value = source; + break; + } + } + + return return_value; + } + } + + public bool source_todoist_exists (string email) { + bool return_value = false; + + lock (_sources) { + foreach (Objects.Source source in sources) { + if (source.source_type == SourceType.TODOIST && source.todoist_data.user_email == email) { + return_value = true; + break; + } + } + + return return_value; + } + } + + public bool source_caldav_exists (string server_url, string username) { + bool return_value = false; + + lock (_sources) { + foreach (Objects.Source source in sources) { + if (source.source_type == SourceType.CALDAV && + source.caldav_data.server_url == server_url && + source.caldav_data.username == username) { + return_value = true; + break; + } + } + + return return_value; + } + } + + /* + * Projects + */ + + public void insert_project (Objects.Project project) { + if (Services.Database.get_default ().insert_project (project)) { + projects.add (project); + + if (project.parent == null) { + project_added (project); + } else { + project.parent.subproject_added (project); + } + } + } + + public Gee.ArrayList get_projects_by_source (string source_id) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_projects) { + foreach (var project in projects) { + if (project.source_id == source_id) { + return_value.add (project); + } + } + + return return_value; + } + } + + public void delete_project (Objects.Project project) { + if (Services.Database.get_default ().delete_project (project)) { + foreach (Objects.Section section in get_sections_by_project (project)) { + delete_section (section); + } + + foreach (Objects.Item item in get_items_by_project (project)) { + delete_item (item); + } + + foreach (Objects.Project subproject in get_subprojects (project)) { + delete_project (subproject); + } + + project.deleted (); + project_deleted (project); + _projects.remove (project); + } + } + + public void archive_project (Objects.Project project) { + if (Services.Database.get_default ().archive_project (project)) { + foreach (Objects.Item item in project.items) { + archive_item (item, project.is_archived); + } + + foreach (Objects.Section section in project.sections) { + section.is_archived = project.is_archived; + archive_section (section); + } + + if (project.is_archived) { + project.archived (); + project_archived (project); + } else { + project.unarchived (); + project_unarchived (project); + } + } + } + + public void update_project (Objects.Project project) { + if (Services.Database.get_default ().update_project (project)) { + project.updated (); + project_updated (project); + } + } + + public void update_project_id (string current_id, string new_id) { + if (Services.Database.get_default ().update_project_id (current_id, new_id)) { + Objects.Project? project = get_project (current_id); + if (project != null) { + project.id = new_id; + } + + if (Services.Database.get_default ().update_project_section_id (current_id, new_id)) { + foreach (var section in sections) { + if (section.project_id == current_id) { + section.project_id = new_id; + } + } + + if (Services.Database.get_default ().update_project_item_id (current_id, new_id)) { + foreach (var item in items) { + if (item.project_id == current_id) { + item.project_id = new_id; + } + } + } + } + } + } + + public Objects.Project get_inbox_project () { + Objects.Project? return_value = null; + + lock (_projects) { + foreach (var project in projects) { + if (project.is_inbox_project) { + return_value = project; + break; + } + } + + return return_value; + } + } + + public Objects.Project get_project (string id) { + Objects.Project? return_value = null; + lock (_projects) { + foreach (var project in projects) { + if (project.id == id) { + return_value = project; + break; + } + } + + return return_value; + } + } + + public Gee.ArrayList get_subprojects (Objects.Project _project) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_projects) { + foreach (var project in projects) { + if (project.parent_id == _project.id) { + return_value.add (project); + } + } + } + + return return_value; + } + + public int next_project_child_order (Objects.Source source) { + int child_order = 0; + + lock (_projects) { + foreach (var project in projects) { + if (project.source_id == source.id && !project.is_deleted) { + child_order++; + } + } + + return child_order; + } + } + + /* + * Sections + */ + + public void insert_section (Objects.Section section) { + if (Services.Database.get_default ().insert_section (section)) { + sections.add (section); + section.project.section_added (section); + } + } + + public void update_section (Objects.Section section) { + if (Services.Database.get_default ().update_section (section)) { + section.updated (); + } + } + + public void delete_section (Objects.Section section) { + if (Services.Database.get_default ().delete_section (section)) { + foreach (Objects.Item item in section.items) { + delete_item (item); + } + + section.deleted (); + section_deleted (section); + _sections.remove (section); + } + } + + public void move_section (Objects.Section section, string old_project_id) { + if (Services.Database.get_default ().move_section (section, old_project_id)) { + if (Services.Database.get_default ().move_section_items (section)) { + foreach (Objects.Item item in section.items) { + item.project_id = section.project_id; + } + + section_moved (section, old_project_id); + } + } + } + + public void update_section_id (string current_id, string new_id) { + if (Services.Database.get_default ().update_section_id (current_id, new_id)) { + foreach (var section in sections) { + if (section.id == current_id) { + section.id = new_id; + } + } + + if (Services.Database.get_default ().update_section_item_id (current_id, new_id)) { + foreach (var item in items) { + if (item.section_id == current_id) { + item.section_id = new_id; + } + } + } + } + } + + public void archive_section (Objects.Section section) { + if (Services.Database.get_default ().archive_section (section)) { + foreach (Objects.Item item in section.items) { + archive_item (item, section.is_archived); + } + + if (section.is_archived) { + section.archived (); + section_archived (section); + } else { + section.unarchived (); + section_unarchived (section); + } + } + } + + public Gee.ArrayList get_sections_by_project (Objects.Project project) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_sections) { + foreach (var section in sections) { + if (section.project_id == project.id) { + return_value.add (section); + } + } + } + + return return_value; + } + + public Gee.ArrayList get_sections_archived_by_project (Objects.Project project) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_sections) { + foreach (var section in sections) { + if (section.project_id == project.id && section.was_archived ()) { + return_value.add (section); + } + } + } + + return return_value; + } + + public Objects.Section get_section (string id) { + Objects.Section? return_value = null; + lock (_sections) { + foreach (var section in sections) { + if (section.id == id) { + return_value = section; + break; + } + } + + return return_value; + } + } + + /* + * Items + */ + + public void insert_item (Objects.Item item, bool insert = true) { + if (Services.Database.get_default ().insert_item (item, insert)) { + add_item (item, insert); + } + } + + public void add_item (Objects.Item item, bool insert = true) { + items.add (item); + item_added (item, insert); + + if (insert) { + if (item.parent_id != "") { + item.parent.item_added (item); + } else { + if (item.section_id == "") { + item.project.item_added (item); + } else { + item.section.item_added (item); + } + } + } + + Services.EventBus.get_default ().update_items_position (item.project_id, item.section_id); + } + + public void update_item (Objects.Item item, string update_id = "") { + if (Services.Database.get_default ().update_item (item, update_id)) { + item.updated (update_id); + item_updated (item, update_id); + } + } + + public void update_item_pin (Objects.Item item) { + if (Services.Database.get_default ().update_item (item)) { + item_pin_change (item); + item.pin_updated (); + } + } + + public void delete_item (Objects.Item item) { + if (Services.Database.get_default ().delete_item (item)) { + foreach (Objects.Item subitem in get_subitems (item)) { + delete_item (subitem); + } + + item.deleted (); + item_deleted (item); + _items.remove (item); + + item.project.item_deleted (item); + if (item.has_section) { + item.section.item_deleted (item); + } + } + } + + public void move_item (Objects.Item item, string old_section_id = "", string old_parent_id = "") { + if (Services.Database.get_default ().move_item (item)) { + foreach (Objects.Item subitem in get_subitems (item)) { + subitem.project_id = item.project_id; + move_item (subitem); + } + + get_section (item.section_id).update_count (); + get_section (old_section_id).update_count (); + + item.updated (); + item_updated (item, ""); + } + } + + public void complete_item (Objects.Item item, bool old_checked, bool complete_subitems = true) { + if (Services.Database.get_default ().complete_item (item, old_checked)) { + if (complete_subitems) { + foreach (Objects.Item subitem in get_subitems (item)) { + subitem.checked = item.checked; + subitem.completed_at = item.completed_at; + complete_item (subitem, old_checked); + } + } + + item.updated (); + item_updated (item, ""); + + Services.EventBus.get_default ().checked_toggled (item, old_checked); + + if (item.has_parent && !item.checked) { + item.parent.checked = item.checked; + item.parent.completed_at = item.completed_at; + + complete_item (item.parent, old_checked, false); + } + } + } + + public void archive_item (Objects.Item item, bool is_archived) { + if (is_archived) { + item.archived (); + item_archived (item); + } else { + item.unarchived (); + item_unarchived (item); + } + + foreach (Objects.Item subitem in get_subitems (item)) { + archive_item (subitem, is_archived); + } + } + + public void update_item_id (string current_id, string new_id) { + if (Services.Database.get_default ().update_item_id (current_id, new_id)) { + foreach (var item in items) { + if (item.id == current_id) { + item.id = new_id; + } + } + + if (Services.Database.get_default ().update_item_child_id (current_id, new_id)) { + foreach (var item in items) { + if (item.parent_id == current_id) { + item.parent_id = new_id; + } + } + } + } + } + + public int next_item_child_order (string project_id, string section_id) { + int child_order = 0; + + lock (_items) { + foreach (var item in items) { + if (item.project_id == project_id && item.section_id == section_id) { + child_order++; + } + } + + return child_order; + } + } + + public Objects.Item get_item (string id) { + Objects.Item? return_value = null; + lock (_items) { + foreach (var item in items) { + if (item.id == id) { + return_value = item; + break; + } + } + + return return_value; + } + } + + public Objects.Item get_item_by_ics (string ics) { + Objects.Item? return_value = null; + lock (_items) { + foreach (var item in items) { + if (item.ics == ics) { + return_value = item; + break; + } + } + + return return_value; + } + } + + public Gee.ArrayList get_item_by_baseobject (Objects.BaseObject object) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (var item in items) { + if (object is Objects.Project) { + if (item.project_id == object.id && item.section_id == "" && !item.has_parent) { + return_value.add (item); + } + } + + if (object is Objects.Section) { + if (item.section_id == object.id && !item.has_parent) { + return_value.add (item); + } + } + } + } + + return return_value; + } + + public Gee.ArrayList get_items_checked () { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.checked) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_checked_by_project (Objects.Project project) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.project_id == project.id && item.checked) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_subitems (Objects.Item i) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (var item in items) { + if (item.parent_id == i.id) { + return_value.add (item); + } + } + } + + return return_value; + } + + public Gee.ArrayList get_subitems_uncomplete (Objects.Item i) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (var item in items) { + if (item.parent_id == i.id && !item.checked) { + return_value.add (item); + } + } + } + + return return_value; + } + + public Gee.ArrayList get_items_by_project (Objects.Project project) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.exists_project (project)) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_by_project_pinned (Objects.Project project) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.exists_project (project) && item.pinned) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_by_date (GLib.DateTime date, bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (valid_item_by_date (item, date, checked)) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_no_date (bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (!item.has_due && item.checked == checked) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_repeating (bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.has_due && item.due.is_recurring && item.checked == checked && !item.was_archived ()) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_by_date_range (GLib.DateTime start_date, GLib.DateTime end_date, bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (valid_item_by_date_range (item, start_date, end_date, checked)) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_by_month (GLib.DateTime date, bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (valid_item_by_month (item, date, checked)) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_pinned (bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.pinned && item.checked == checked && !item.was_archived ()) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_by_priority (int priority, bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.priority == priority && item.checked == checked && !item.was_archived ()) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_completed () { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.checked && !item.was_archived ()) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_by_label (Objects.Label label, bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.has_label (label.id) && item.checked == checked && !item.was_archived ()) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_unlabeled (bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.labels.size <= 0 && item.checked == checked && !item.was_archived ()) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_by_scheduled (bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.has_due && + !item.was_archived () && + item.checked == checked && + item.due.datetime.compare (new GLib.DateTime.now_local ()) > 0) { + return_value.add (item); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_items_no_parent (bool checked = true) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (!item.was_archived () && + item.checked == checked && + !item.has_parent) { + return_value.add (item); + } + } + + return return_value; + } + } + + public bool valid_item_by_date (Objects.Item item, GLib.DateTime date, bool checked = true) { + if (!item.has_due || item.was_archived ()) { + return false; + } + + return (item.checked == checked && Utils.Datetime.is_same_day (item.due.datetime, date)); + } + + public bool valid_item_by_date_range (Objects.Item item, GLib.DateTime start_date, GLib.DateTime end_date, bool checked = true) { + if (!item.has_due || item.was_archived ()) { + return false; + } + + var date = Utils.Datetime.get_date_only (item.due.datetime); + var start = Utils.Datetime.get_date_only (start_date); + var end = Utils.Datetime.get_date_only (end_date); + + return (item.checked == checked && date.compare (start) >= 0 && date.compare (end) <= 0); + } + + public bool valid_item_by_month (Objects.Item item, GLib.DateTime date, bool checked = true) { + if (!item.has_due || item.was_archived ()) { + return false; + } + + return (item.checked == checked && item.due.datetime.get_month () == date.get_month () && + item.due.datetime.get_year () == date.get_year ()); + } + + public Gee.ArrayList get_items_by_overdeue_view (bool checked = true) { + GLib.DateTime date_now = new GLib.DateTime.now_local (); + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.has_due && + !item.was_archived () && + item.checked == checked && + item.due.datetime.compare (date_now) < 0 && + !Utils.Datetime.is_same_day (item.due.datetime, date_now)) { + return_value.add (item); + } + } + + return return_value; + } + } + + public bool valid_item_by_overdue (Objects.Item item, GLib.DateTime date, bool checked = true) { + if (!item.has_due || item.was_archived ()) { + return false; + } + + return (item.checked == checked && + item.due.datetime.compare (new GLib.DateTime.now_local ()) < 0 && + !Utils.Datetime.is_same_day (item.due.datetime, new GLib.DateTime.now_local ())); + } + + /* + * Labels + */ + + public void insert_label (Objects.Label label) { + if (Services.Database.get_default ().insert_label (label)) { + labels.add (label); + label_added (label); + } + } + + public void delete_label (Objects.Label label) { + if (Services.Database.get_default ().delete_label (label)) { + label.deleted (); + label_deleted (label); + _labels.remove (label); + } + } + + public void update_label (Objects.Label label) { + if (Services.Database.get_default ().update_label (label)) { + label.updated (); + label_updated (label); + } + } + + public Gee.ArrayList get_labels_by_item_labels (string labels) { + Gee.ArrayList return_value = new Gee.ArrayList (); + + foreach (string id in labels.split (";")) { + Objects.Label? label = get_label (id); + if (label != null) { + return_value.add (label); + } + } + + return return_value; + } + + public Gee.ArrayList get_items_has_labels () { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (Objects.Item item in items) { + if (item.has_labels () && !item.completed && !item.was_archived ()) { + return_value.add (item); + } + } + + return return_value; + } + } + + public bool label_exists (string id) { + bool return_value = false; + lock (_labels) { + foreach (var label in _labels) { + if (label.id == id) { + return_value = true; + break; + } + } + + return return_value; + } + } + + public Objects.Label get_label (string id) { + Objects.Label? return_value = null; + lock (_labels) { + foreach (var label in labels) { + if (label.id == id) { + return_value = label; + break; + } + } + + return return_value; + } + } + + public Objects.Label? get_label_by_name (string name, bool lowercase = false, string source_id) { + lock (_labels) { + string compare_name = lowercase ? name.down () : name; + + foreach (var label in labels) { + string label_name = lowercase ? label.name.down () : label.name; + if (label.source_id == source_id && label_name == compare_name) { + return label; + } + } + + return null; + } + } + + public Gee.ArrayList get_labels_by_source (string source_id) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_labels) { + foreach (var label in labels) { + if (label.source_id == source_id) { + return_value.add (label); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_all_labels_by_search (string search_text) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_labels) { + foreach (var label in labels) { + if (search_text.down () in label.name.down ()) { + return_value.add (label); + } + } + + return return_value; + } + } + + /* + * Quick Find + */ + + public Gee.ArrayList get_all_projects_by_search (string search_text) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_projects) { + foreach (var project in projects) { + if (search_text.down () in project.name.down () && !project.is_archived) { + return_value.add (project); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_all_sections_by_search (string search_text) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_projects) { + foreach (var section in sections) { + if (search_text.down () in section.name.down () && !section.was_archived ()) { + return_value.add (section); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_all_projects_archived () { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_projects) { + foreach (var project in projects) { + if (project.is_archived) { + return_value.add (project); + } + } + + return return_value; + } + } + + public Gee.ArrayList get_all_items_by_search (string search_text) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_items) { + foreach (var item in items) { + if (!item.checked && !item.was_archived () && (search_text.down () in item.content.down () || + search_text.down () in item.description.down ())) { + return_value.add (item); + } + } + + return return_value; + } + } + + // Reminders + public void insert_reminder (Objects.Reminder reminder) { + if (Services.Database.get_default ().insert_reminder (reminder)) { + reminders.add (reminder); + reminder_added (reminder); + reminder.item.reminder_added (reminder); + } + } + + public void delete_reminder (Objects.Reminder reminder) { + if (Services.Database.get_default ().delete_reminder (reminder)) { + reminder.deleted (); + reminder_deleted (reminder); + _reminders.remove (reminder); + + reminder.item.reminder_deleted (reminder); + + } + } + + public Gee.ArrayList get_reminders_by_item (Objects.Item item) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_reminders) { + foreach (var reminder in reminders) { + if (reminder.item_id == item.id) { + return_value.add (reminder); + } + } + + return return_value; + } + } + + public Objects.Reminder get_reminder (string id) { + Objects.Reminder? return_value = null; + lock (_reminders) { + foreach (var reminder in reminders) { + if (reminder.id == id) { + return_value = reminder; + break; + } + } + + return return_value; + } + } + + // Atrachments + public void insert_attachment (Objects.Attachment attachment) { + if (Services.Database.get_default ().insert_attachment (attachment)) { + attachments.add (attachment); + attachment.item.attachment_added (attachment); + } + } + + public void delete_attachment (Objects.Attachment attachment) { + if (Services.Database.get_default ().delete_attachment (attachment)) { + attachment.deleted (); + attachment_deleted (attachment); + _attachments.remove (attachment); + + attachment.item.attachment_deleted (attachment); + } + } + + public Gee.ArrayList get_attachments_by_item (Objects.Item item) { + Gee.ArrayList return_value = new Gee.ArrayList (); + lock (_attachments) { + foreach (var attachment in attachments) { + if (attachment.item_id == item.id) { + return_value.add (attachment); + } + } + + return return_value; + } + } +} diff --git a/core/Util/Migrate.vala b/core/Util/Migrate.vala index a3b37d15f..ab73082a8 100644 --- a/core/Util/Migrate.vala +++ b/core/Util/Migrate.vala @@ -1,72 +1,72 @@ /* -* 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 -* License as published by the Free Software Foundation; either -* version 3 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -* Authored by: Alain M. -*/ + * 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 + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Alain M. + */ public class Utils.AccountMigrate { - public static Objects.SourceTodoistData get_data_from_todoist () { - Objects.SourceTodoistData return_value = new Objects.SourceTodoistData (); + public static Objects.SourceTodoistData get_data_from_todoist () { + Objects.SourceTodoistData return_value = new Objects.SourceTodoistData (); - return_value.sync_token = Services.Settings.get_default ().settings.get_string ("todoist-sync-token"); - return_value.access_token = Services.Settings.get_default ().settings.get_string ("todoist-access-token"); + return_value.sync_token = Services.Settings.get_default ().settings.get_string ("todoist-sync-token"); + return_value.access_token = Services.Settings.get_default ().settings.get_string ("todoist-access-token"); return_value.user_email = Services.Settings.get_default ().settings.get_string ("todoist-user-email"); return_value.user_name = Services.Settings.get_default ().settings.get_string ("todoist-user-name"); return_value.user_avatar = Services.Settings.get_default ().settings.get_string ("todoist-user-avatar"); return_value.user_image_id = Services.Settings.get_default ().settings.get_string ("todoist-user-image-id"); return_value.user_is_premium = Services.Settings.get_default ().settings.get_boolean ("todoist-user-is-premium"); - return return_value; - } + return return_value; + } - public static Objects.SourceCalDAVData get_data_from_caldav () { - Objects.SourceCalDAVData return_value = new Objects.SourceCalDAVData (); + public static Objects.SourceCalDAVData get_data_from_caldav () { + Objects.SourceCalDAVData return_value = new Objects.SourceCalDAVData (); - string _server_url = ""; - var uri = GLib.Uri.parse (Services.Settings.get_default ().settings.get_string ("caldav-server-url"), GLib.UriFlags.NONE); - _server_url = "%s://%s".printf (uri.get_scheme (), uri.get_host ()); + string _server_url = ""; + var uri = GLib.Uri.parse (Services.Settings.get_default ().settings.get_string ("caldav-server-url"), GLib.UriFlags.NONE); + _server_url = "%s://%s".printf (uri.get_scheme (), uri.get_host ()); - return_value.server_url = "%s/remote.php/dav".printf (_server_url); - return_value.username = Services.Settings.get_default ().settings.get_string ("caldav-username"); - return_value.credentials = get_credential (); - return_value.user_displayname = Services.Settings.get_default ().settings.get_string ("caldav-user-displayname"); - return_value.user_email = Services.Settings.get_default ().settings.get_string ("caldav-user-email"); - return_value.caldav_type = CalDAVType.NEXTCLOUD; + return_value.server_url = "%s/remote.php/dav".printf (_server_url); + return_value.username = Services.Settings.get_default ().settings.get_string ("caldav-username"); + return_value.credentials = get_credential (); + return_value.user_displayname = Services.Settings.get_default ().settings.get_string ("caldav-user-displayname"); + return_value.user_email = Services.Settings.get_default ().settings.get_string ("caldav-user-email"); + return_value.caldav_type = CalDAVType.NEXTCLOUD; - return return_value; - } + return return_value; + } - private static string get_credential () throws Error { - Secret.Schema schema = new Secret.Schema ("io.github.alainm23.planify", Secret.SchemaFlags.NONE, - "username", Secret.SchemaAttributeType.STRING, - "server_url", Secret.SchemaAttributeType.STRING - ); + private static string get_credential () throws Error { + Secret.Schema schema = new Secret.Schema ("io.github.alainm23.planify", Secret.SchemaFlags.NONE, + "username", Secret.SchemaAttributeType.STRING, + "server_url", Secret.SchemaAttributeType.STRING + ); - string username = Services.Settings.get_default ().settings.get_string ("caldav-username"); + string username = Services.Settings.get_default ().settings.get_string ("caldav-username"); - GLib.HashTable attributes = new GLib.HashTable (str_hash, str_equal); - attributes["username"] = username; - attributes["server_url"] = Services.Settings.get_default ().settings.get_string ("caldav-server-url"); + GLib.HashTable attributes = new GLib.HashTable (str_hash, str_equal); + attributes["username"] = username; + attributes["server_url"] = Services.Settings.get_default ().settings.get_string ("caldav-server-url"); - string password = Secret.password_lookupv_sync (schema, attributes, null); - string credentials = "%s:%s".printf (username, password); - string base64_credentials = Base64.encode (credentials.data); - - return base64_credentials; - } -} \ No newline at end of file + string password = Secret.password_lookupv_sync (schema, attributes, null); + string credentials = "%s:%s".printf (username, password); + string base64_credentials = Base64.encode (credentials.data); + + return base64_credentials; + } +} diff --git a/core/Widgets/ContextMenu/MenuSwitch.vala b/core/Widgets/ContextMenu/MenuSwitch.vala index cb29a7267..a7fe6cd72 100644 --- a/core/Widgets/ContextMenu/MenuSwitch.vala +++ b/core/Widgets/ContextMenu/MenuSwitch.vala @@ -62,7 +62,7 @@ public class Widgets.ContextMenu.MenuSwitch : Gtk.Button { ); } - ~MenuSwitch() { + ~MenuSwitch () { print ("Destroying Widgets.ContextMenu.MenuSwitch\n"); } diff --git a/core/Widgets/DateTimePicker/RepeatConfig.vala b/core/Widgets/DateTimePicker/RepeatConfig.vala index 06bb78d6d..696ec46aa 100644 --- a/core/Widgets/DateTimePicker/RepeatConfig.vala +++ b/core/Widgets/DateTimePicker/RepeatConfig.vala @@ -1,213 +1,213 @@ /* -* 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 -* License as published by the Free Software Foundation; either -* version 3 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -* Authored by: Alain M. -*/ + * 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 + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Alain M. + */ public class Widgets.DateTimePicker.RepeatConfig : Adw.NavigationPage { - private Gtk.SpinButton recurrency_interval; - private Gtk.DropDown recurrency_combobox; - private Gtk.Label repeat_label; - - private Gtk.ToggleButton mo_button; - private Gtk.ToggleButton tu_button; - private Gtk.ToggleButton we_button; - private Gtk.ToggleButton th_button; - private Gtk.ToggleButton fr_button; - private Gtk.ToggleButton sa_button; - private Gtk.ToggleButton su_button; - - - private Gtk.ToggleButton never_button; - private Gtk.ToggleButton on_button; - private Gtk.ToggleButton after_button; - private Gtk.Calendar calendar; - private Gtk.MenuButton datepicker_button; - private Gtk.SpinButton count_interval; - private Gtk.Stack ends_stack; - - public Objects.DueDate duedate { - set { - recurrency_interval.value = value.recurrency_interval; - - if (value.recurrency_type == RecurrencyType.NONE) { - recurrency_combobox.selected = 0; - } else { - recurrency_combobox.selected = (int) value.recurrency_type; - } - - if (value.recurrency_type == RecurrencyType.EVERY_WEEK) { - mo_button.active = value.recurrency_weeks.contains ("1"); - tu_button.active = value.recurrency_weeks.contains ("2"); - we_button.active = value.recurrency_weeks.contains ("3"); - th_button.active = value.recurrency_weeks.contains ("4"); - fr_button.active = value.recurrency_weeks.contains ("5"); - sa_button.active = value.recurrency_weeks.contains ("6"); - su_button.active = value.recurrency_weeks.contains ("7"); - } - - if (value.recurrency_end != "") { - on_button.active = true; - } else if (value.recurrency_count > 0) { - after_button.active = true; - } - - count_interval.value = value.recurrency_count; - - if (value.recurrency_end != "") { - var date = Utils.Datetime.get_date_from_string (value.recurrency_end); - calendar.year = date.get_year (); - calendar.month = date.get_month (); - calendar.day = date.get_day_of_month (); - } - - update_repeat_label (); - } - } - - public signal void duedate_change (Objects.DueDate duedate); - public signal void back (); - - private Gee.HashMap signal_map = new Gee.HashMap (); - - public RepeatConfig () { - Object ( - title: _("Repeat") - ); - } - - ~RepeatConfig() { - print ("Destroying Dialogs.RepeatConfig\n"); - } - - construct { - var back_item = new Widgets.ContextMenu.MenuItem (_("Back"), "go-previous-symbolic"); - - repeat_label = new Gtk.Label (null) { - margin_top = 9, - margin_bottom = 9, - margin_start = 9, - margin_end = 9, - ellipsize = Pango.EllipsizeMode.END - }; - - var repeat_preview_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { - margin_top = 6 - }; - repeat_preview_box.append (repeat_label); - repeat_preview_box.add_css_class ("card"); - repeat_preview_box.add_css_class ("border-radius-6"); - - recurrency_interval = new Gtk.SpinButton.with_range (1, 100, 1) { - hexpand = true, - valign = CENTER, - css_classes = { "popover-spinbutton" } - }; - - string[] items = { - _("Minute(s)"), _("Hour(s)"), _("Day(s)"), _("Week(s)"), _("Month(s)"), _("Year(s)") - }; - - recurrency_combobox = new Gtk.DropDown.from_strings (items) { - hexpand = true, - vexpand = true, - selected = 2 - }; - - var repeat_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { - hexpand = true, - margin_top = 6, - homogeneous = true - }; - repeat_box.append (recurrency_interval); - repeat_box.append (recurrency_combobox); - - mo_button = new Gtk.ToggleButton.with_label (_("Mo")) { - css_classes = { "no-padding", "caption" }, - width_request = 32, - height_request = 32 - }; - - tu_button = new Gtk.ToggleButton.with_label (_("Tu")) { - css_classes = { "no-padding", "caption" }, - width_request = 32, - height_request = 32 - }; - - we_button = new Gtk.ToggleButton.with_label (_("We")) { - css_classes = { "no-padding", "caption" }, - width_request = 32, - height_request = 32 - }; - - th_button = new Gtk.ToggleButton.with_label (_("Th")) { - css_classes = { "no-padding", "caption" }, - width_request = 32, - height_request = 32 - }; - - fr_button = new Gtk.ToggleButton.with_label (_("Fr")) { - css_classes = { "no-padding", "caption" }, - width_request = 32, - height_request = 32 - }; - - sa_button = new Gtk.ToggleButton.with_label (_("Sa")) { - css_classes = { "no-padding", "caption" }, - width_request = 32, - height_request = 32 - }; - - su_button = new Gtk.ToggleButton.with_label (_("Su")) { - css_classes = { "no-padding", "caption" }, - width_request = 32, - height_request = 32 - }; - - var weeks_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { - hexpand = true, - margin_top = 12, - margin_bottom = 6, - homogeneous = true - }; - weeks_box.append (mo_button); - weeks_box.append (tu_button); - weeks_box.append (we_button); - weeks_box.append (th_button); - weeks_box.append (fr_button); - weeks_box.append (sa_button); - weeks_box.append (su_button); - - var weeks_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN, - reveal_child = false, - child = weeks_box - }; - - never_button = new Gtk.ToggleButton.with_label (_("Never")) { - active = true - }; - - on_button = new Gtk.ToggleButton.with_label (_("On Date")) { + private Gtk.SpinButton recurrency_interval; + private Gtk.DropDown recurrency_combobox; + private Gtk.Label repeat_label; + + private Gtk.ToggleButton mo_button; + private Gtk.ToggleButton tu_button; + private Gtk.ToggleButton we_button; + private Gtk.ToggleButton th_button; + private Gtk.ToggleButton fr_button; + private Gtk.ToggleButton sa_button; + private Gtk.ToggleButton su_button; + + + private Gtk.ToggleButton never_button; + private Gtk.ToggleButton on_button; + private Gtk.ToggleButton after_button; + private Gtk.Calendar calendar; + private Gtk.MenuButton datepicker_button; + private Gtk.SpinButton count_interval; + private Gtk.Stack ends_stack; + + public Objects.DueDate duedate { + set { + recurrency_interval.value = value.recurrency_interval; + + if (value.recurrency_type == RecurrencyType.NONE) { + recurrency_combobox.selected = 0; + } else { + recurrency_combobox.selected = (int) value.recurrency_type; + } + + if (value.recurrency_type == RecurrencyType.EVERY_WEEK) { + mo_button.active = value.recurrency_weeks.contains ("1"); + tu_button.active = value.recurrency_weeks.contains ("2"); + we_button.active = value.recurrency_weeks.contains ("3"); + th_button.active = value.recurrency_weeks.contains ("4"); + fr_button.active = value.recurrency_weeks.contains ("5"); + sa_button.active = value.recurrency_weeks.contains ("6"); + su_button.active = value.recurrency_weeks.contains ("7"); + } + + if (value.recurrency_end != "") { + on_button.active = true; + } else if (value.recurrency_count > 0) { + after_button.active = true; + } + + count_interval.value = value.recurrency_count; + + if (value.recurrency_end != "") { + var date = Utils.Datetime.get_date_from_string (value.recurrency_end); + calendar.year = date.get_year (); + calendar.month = date.get_month (); + calendar.day = date.get_day_of_month (); + } + + update_repeat_label (); + } + } + + public signal void duedate_change (Objects.DueDate duedate); + public signal void back (); + + private Gee.HashMap signal_map = new Gee.HashMap (); + + public RepeatConfig () { + Object ( + title: _("Repeat") + ); + } + + ~RepeatConfig () { + print ("Destroying Dialogs.RepeatConfig\n"); + } + + construct { + var back_item = new Widgets.ContextMenu.MenuItem (_("Back"), "go-previous-symbolic"); + + repeat_label = new Gtk.Label (null) { + margin_top = 9, + margin_bottom = 9, + margin_start = 9, + margin_end = 9, + ellipsize = Pango.EllipsizeMode.END + }; + + var repeat_preview_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { + margin_top = 6 + }; + repeat_preview_box.append (repeat_label); + repeat_preview_box.add_css_class ("card"); + repeat_preview_box.add_css_class ("border-radius-6"); + + recurrency_interval = new Gtk.SpinButton.with_range (1, 100, 1) { + hexpand = true, + valign = CENTER, + css_classes = { "popover-spinbutton" } + }; + + string[] items = { + _("Minute(s)"), _("Hour(s)"), _("Day(s)"), _("Week(s)"), _("Month(s)"), _("Year(s)") + }; + + recurrency_combobox = new Gtk.DropDown.from_strings (items) { + hexpand = true, + vexpand = true, + selected = 2 + }; + + var repeat_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { + hexpand = true, + margin_top = 6, + homogeneous = true + }; + repeat_box.append (recurrency_interval); + repeat_box.append (recurrency_combobox); + + mo_button = new Gtk.ToggleButton.with_label (_("Mo")) { + css_classes = { "no-padding", "caption" }, + width_request = 32, + height_request = 32 + }; + + tu_button = new Gtk.ToggleButton.with_label (_("Tu")) { + css_classes = { "no-padding", "caption" }, + width_request = 32, + height_request = 32 + }; + + we_button = new Gtk.ToggleButton.with_label (_("We")) { + css_classes = { "no-padding", "caption" }, + width_request = 32, + height_request = 32 + }; + + th_button = new Gtk.ToggleButton.with_label (_("Th")) { + css_classes = { "no-padding", "caption" }, + width_request = 32, + height_request = 32 + }; + + fr_button = new Gtk.ToggleButton.with_label (_("Fr")) { + css_classes = { "no-padding", "caption" }, + width_request = 32, + height_request = 32 + }; + + sa_button = new Gtk.ToggleButton.with_label (_("Sa")) { + css_classes = { "no-padding", "caption" }, + width_request = 32, + height_request = 32 + }; + + su_button = new Gtk.ToggleButton.with_label (_("Su")) { + css_classes = { "no-padding", "caption" }, + width_request = 32, + height_request = 32 + }; + + var weeks_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { + hexpand = true, + margin_top = 12, + margin_bottom = 6, + homogeneous = true + }; + weeks_box.append (mo_button); + weeks_box.append (tu_button); + weeks_box.append (we_button); + weeks_box.append (th_button); + weeks_box.append (fr_button); + weeks_box.append (sa_button); + weeks_box.append (su_button); + + var weeks_revealer = new Gtk.Revealer () { + transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN, + reveal_child = false, + child = weeks_box + }; + + never_button = new Gtk.ToggleButton.with_label (_("Never")) { + active = true + }; + + on_button = new Gtk.ToggleButton.with_label (_("On Date")) { group = never_button }; - after_button = new Gtk.ToggleButton.with_label (_("After")) { + after_button = new Gtk.ToggleButton.with_label (_("After")) { group = never_button }; @@ -215,248 +215,248 @@ public class Widgets.DateTimePicker.RepeatConfig : Adw.NavigationPage { css_classes = { "linked" }, hexpand = true, homogeneous = true, - margin_top = 6 + margin_top = 6 }; ends_grid.append (never_button); ends_grid.append (on_button); - ends_grid.append (after_button); - - calendar = new Gtk.Calendar (); - var calendar_popover = new Gtk.Popover () { - child = calendar, - has_arrow = false, - halign = Gtk.Align.END, - position = Gtk.PositionType.BOTTOM - }; - - datepicker_button = new Gtk.MenuButton () { - label = Utils.Datetime.get_default_date_format_from_date ( - Utils.Datetime.get_date_only (new GLib.DateTime.now_local ().add_days (1)) - ), - popover = calendar_popover - }; - - count_interval = new Gtk.SpinButton.with_range (1, 100, 1) { - hexpand = true, - halign = CENTER, - valign = CENTER, - css_classes = { "popover-spinbutton" } - }; - - ends_stack = new Gtk.Stack () { + ends_grid.append (after_button); + + calendar = new Gtk.Calendar (); + var calendar_popover = new Gtk.Popover () { + child = calendar, + has_arrow = false, + halign = Gtk.Align.END, + position = Gtk.PositionType.BOTTOM + }; + + datepicker_button = new Gtk.MenuButton () { + label = Utils.Datetime.get_default_date_format_from_date ( + Utils.Datetime.get_date_only (new GLib.DateTime.now_local ().add_days (1)) + ), + popover = calendar_popover + }; + + count_interval = new Gtk.SpinButton.with_range (1, 100, 1) { + hexpand = true, + halign = CENTER, + valign = CENTER, + css_classes = { "popover-spinbutton" } + }; + + ends_stack = new Gtk.Stack () { hexpand = true, transition_type = Gtk.StackTransitionType.CROSSFADE, - margin_top = 6 + margin_top = 6 }; - ends_stack.add_named (new Gtk.Label (null), "never"); - ends_stack.add_named (datepicker_button, "on"); - ends_stack.add_named (count_interval, "after"); - - var submit_button = new Widgets.LoadingButton (LoadingButtonType.LABEL, _("Done")) { - margin_top = 6, - vexpand = true, - valign = Gtk.Align.END - }; - submit_button.add_css_class ("suggested-action"); - - var content_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { - margin_start = 6, - margin_end = 6 - }; - content_box.append (new Widgets.ContextMenu.MenuSeparator ()); - content_box.append (new Gtk.Label (_("Summary")) { - css_classes = { "heading", "h4" }, - margin_top = 6, - halign = Gtk.Align.START - }); - content_box.append (repeat_preview_box); - content_box.append (new Gtk.Label (_("Repeat every")) { - css_classes = { "heading", "h4" }, - margin_top = 6, - halign = Gtk.Align.START - }); - content_box.append (repeat_box); - content_box.append (weeks_revealer); - content_box.append (new Gtk.Label (_("End")) { - css_classes = { "heading", "h4" }, - margin_top = 6, - halign = Gtk.Align.START - }); - content_box.append (ends_grid); - content_box.append (ends_stack); - content_box.append (submit_button); - - var toolbar_view = new Adw.ToolbarView (); - toolbar_view.add_top_bar (back_item); + ends_stack.add_named (new Gtk.Label (null), "never"); + ends_stack.add_named (datepicker_button, "on"); + ends_stack.add_named (count_interval, "after"); + + var submit_button = new Widgets.LoadingButton (LoadingButtonType.LABEL, _("Done")) { + margin_top = 6, + vexpand = true, + valign = Gtk.Align.END + }; + submit_button.add_css_class ("suggested-action"); + + var content_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { + margin_start = 6, + margin_end = 6 + }; + content_box.append (new Widgets.ContextMenu.MenuSeparator ()); + content_box.append (new Gtk.Label (_("Summary")) { + css_classes = { "heading", "h4" }, + margin_top = 6, + halign = Gtk.Align.START + }); + content_box.append (repeat_preview_box); + content_box.append (new Gtk.Label (_("Repeat every")) { + css_classes = { "heading", "h4" }, + margin_top = 6, + halign = Gtk.Align.START + }); + content_box.append (repeat_box); + content_box.append (weeks_revealer); + content_box.append (new Gtk.Label (_("End")) { + css_classes = { "heading", "h4" }, + margin_top = 6, + halign = Gtk.Align.START + }); + content_box.append (ends_grid); + content_box.append (ends_stack); + content_box.append (submit_button); + + var toolbar_view = new Adw.ToolbarView (); + toolbar_view.add_top_bar (back_item); toolbar_view.content = content_box; - child = toolbar_view; - update_repeat_label (); - Services.EventBus.get_default ().disconnect_typing_accel (); + child = toolbar_view; + update_repeat_label (); + Services.EventBus.get_default ().disconnect_typing_accel (); - signal_map[recurrency_interval.value_changed.connect (() => { - update_repeat_label (); - })] = recurrency_interval; + signal_map[recurrency_interval.value_changed.connect (() => { + update_repeat_label (); + })] = recurrency_interval; - signal_map[recurrency_combobox.notify["selected-item"].connect (() => { - if ((RecurrencyType) this.recurrency_combobox.selected == RecurrencyType.EVERY_WEEK) { - weeks_revealer.reveal_child = true; - } else { - weeks_revealer.reveal_child = false; - } + signal_map[recurrency_combobox.notify["selected-item"].connect (() => { + if ((RecurrencyType) this.recurrency_combobox.selected == RecurrencyType.EVERY_WEEK) { + weeks_revealer.reveal_child = true; + } else { + weeks_revealer.reveal_child = false; + } - update_repeat_label (); - })] = recurrency_combobox; + update_repeat_label (); + })] = recurrency_combobox; - signal_map[mo_button.toggled.connect (() => { - update_repeat_label (); - })] = mo_button; + signal_map[mo_button.toggled.connect (() => { + update_repeat_label (); + })] = mo_button; - signal_map[tu_button.toggled.connect (() => { - update_repeat_label (); - })] = tu_button; + signal_map[tu_button.toggled.connect (() => { + update_repeat_label (); + })] = tu_button; - signal_map[we_button.toggled.connect (() => { - update_repeat_label (); - })] = we_button; + signal_map[we_button.toggled.connect (() => { + update_repeat_label (); + })] = we_button; - signal_map[th_button.toggled.connect (() => { - update_repeat_label (); - })] = th_button; + signal_map[th_button.toggled.connect (() => { + update_repeat_label (); + })] = th_button; - signal_map[fr_button.toggled.connect (() => { - update_repeat_label (); - })] = fr_button; + signal_map[fr_button.toggled.connect (() => { + update_repeat_label (); + })] = fr_button; - signal_map[sa_button.toggled.connect (() => { - update_repeat_label (); - })] = sa_button; + signal_map[sa_button.toggled.connect (() => { + update_repeat_label (); + })] = sa_button; - signal_map[su_button.toggled.connect (() => { - update_repeat_label (); - })] = su_button; + signal_map[su_button.toggled.connect (() => { + update_repeat_label (); + })] = su_button; - submit_button.clicked.connect (() => { - set_repeat (); - }); + submit_button.clicked.connect (() => { + set_repeat (); + }); - signal_map[never_button.toggled.connect (() => { + signal_map[never_button.toggled.connect (() => { ends_stack.visible_child_name = "never"; - update_repeat_label (); + update_repeat_label (); })] = never_button; - signal_map[on_button.toggled.connect (() => { + signal_map[on_button.toggled.connect (() => { ends_stack.visible_child_name = "on"; - update_repeat_label (); + update_repeat_label (); })] = on_button; - signal_map[after_button.toggled.connect (() => { + signal_map[after_button.toggled.connect (() => { ends_stack.visible_child_name = "after"; - update_repeat_label (); + update_repeat_label (); })] = after_button; - signal_map[calendar.day_selected.connect (() => { - calendar_popover.popdown (); - update_repeat_label (); - })] = calendar; - - signal_map[count_interval.value_changed.connect (() => { - update_repeat_label (); - })] = count_interval; - - back_item.clicked.connect (() => { - back (); - }); - } - - private void set_repeat () { - var duedate = new Objects.DueDate (); - duedate.is_recurring = true; - duedate.recurrency_type = (RecurrencyType) this.recurrency_combobox.selected; - duedate.recurrency_interval = (int) recurrency_interval.value; - - if (on_button.active) { - duedate.recurrency_count = 0; - duedate.recurrency_end = calendar.get_date ().to_string (); - } else if (after_button.active) { - duedate.recurrency_count = (int) count_interval.value; - duedate.recurrency_end = ""; - } - - if (duedate.recurrency_type == RecurrencyType.EVERY_WEEK) { - duedate.recurrency_weeks = get_recurrency_weeks (); - } else { - duedate.recurrency_weeks = ""; - } - - duedate_change (duedate); - } - - private string get_recurrency_weeks () { - string returned = ""; - - if (mo_button.active) { - returned += "1,"; - } - - if (tu_button.active) { - returned += "2,"; - } - - - if (we_button.active) { - returned += "3,"; - } - - - if (th_button.active) { - returned += "4,"; - } - - - if (fr_button.active) { - returned += "5,"; - } - - - if (sa_button.active) { - returned += "6,"; - } - - - if (su_button.active) { - returned += "7,"; - } - - if (returned.split (",").length > 0) { - return returned.slice (0, -1); - } - - return returned; - } - - private void update_repeat_label () { - var end_label = ""; - if (on_button.active) { - var date_label = Utils.Datetime.get_default_date_format_from_date ( - Utils.Datetime.get_date_only (calendar.get_date ()) - ); - end_label = _("until") + " " + date_label; - datepicker_button.label = date_label; - } else if (after_button.active) { - int count = (int) count_interval.value; - end_label = _("for") + " " + "%d %s".printf (count, count > 1 ? _("times") : _("time")); - } - - RecurrencyType selected_option = (RecurrencyType) this.recurrency_combobox.selected; - string label = Utils.Datetime.get_recurrency_weeks ( - selected_option, - (int) recurrency_interval.value, - get_recurrency_weeks (), - end_label - ); - repeat_label.label = label; - } + signal_map[calendar.day_selected.connect (() => { + calendar_popover.popdown (); + update_repeat_label (); + })] = calendar; + + signal_map[count_interval.value_changed.connect (() => { + update_repeat_label (); + })] = count_interval; + + back_item.clicked.connect (() => { + back (); + }); + } + + private void set_repeat () { + var duedate = new Objects.DueDate (); + duedate.is_recurring = true; + duedate.recurrency_type = (RecurrencyType) this.recurrency_combobox.selected; + duedate.recurrency_interval = (int) recurrency_interval.value; + + if (on_button.active) { + duedate.recurrency_count = 0; + duedate.recurrency_end = calendar.get_date ().to_string (); + } else if (after_button.active) { + duedate.recurrency_count = (int) count_interval.value; + duedate.recurrency_end = ""; + } + + if (duedate.recurrency_type == RecurrencyType.EVERY_WEEK) { + duedate.recurrency_weeks = get_recurrency_weeks (); + } else { + duedate.recurrency_weeks = ""; + } + + duedate_change (duedate); + } + + private string get_recurrency_weeks () { + string returned = ""; + + if (mo_button.active) { + returned += "1,"; + } + + if (tu_button.active) { + returned += "2,"; + } + + + if (we_button.active) { + returned += "3,"; + } + + + if (th_button.active) { + returned += "4,"; + } + + + if (fr_button.active) { + returned += "5,"; + } + + + if (sa_button.active) { + returned += "6,"; + } + + + if (su_button.active) { + returned += "7,"; + } + + if (returned.split (",").length > 0) { + return returned.slice (0, -1); + } + + return returned; + } + + private void update_repeat_label () { + var end_label = ""; + if (on_button.active) { + var date_label = Utils.Datetime.get_default_date_format_from_date ( + Utils.Datetime.get_date_only (calendar.get_date ()) + ); + end_label = _("until") + " " + date_label; + datepicker_button.label = date_label; + } else if (after_button.active) { + int count = (int) count_interval.value; + end_label = _("for") + " " + "%d %s".printf (count, count > 1 ? _("times") : _("time")); + } + + RecurrencyType selected_option = (RecurrencyType) this.recurrency_combobox.selected; + string label = Utils.Datetime.get_recurrency_weeks ( + selected_option, + (int) recurrency_interval.value, + get_recurrency_weeks (), + end_label + ); + repeat_label.label = label; + } } diff --git a/core/Widgets/IconColorProject.vala b/core/Widgets/IconColorProject.vala index a3a31bc6d..fd2e93c1a 100644 --- a/core/Widgets/IconColorProject.vala +++ b/core/Widgets/IconColorProject.vala @@ -13,7 +13,7 @@ public class Widgets.IconColorProject : Adw.Bin { ); } - ~IconColorProject() { + ~IconColorProject () { print ("Destroying Widgets.IconColorProject\n"); } diff --git a/core/Widgets/LabelPicker/LabelButton.vala b/core/Widgets/LabelPicker/LabelButton.vala index a7f59c298..c6a6a4081 100644 --- a/core/Widgets/LabelPicker/LabelButton.vala +++ b/core/Widgets/LabelPicker/LabelButton.vala @@ -63,7 +63,7 @@ public class Widgets.LabelPicker.LabelButton : Adw.Bin { ); } - ~LabelButton() { + ~LabelButton () { print ("Destroying Widgets.LabelPicker.LabelButton\n"); } diff --git a/core/Widgets/LabelPicker/LabelPicker.vala b/core/Widgets/LabelPicker/LabelPicker.vala index 14b97fb5e..7a09cb7ce 100644 --- a/core/Widgets/LabelPicker/LabelPicker.vala +++ b/core/Widgets/LabelPicker/LabelPicker.vala @@ -56,7 +56,7 @@ public class Widgets.LabelPicker.LabelPicker : Gtk.Popover { ); } - ~LabelPicker() { + ~LabelPicker () { print ("Destroying Widgets.LabelPicker.LabelPicker\n"); } diff --git a/core/Widgets/LabelPicker/LabelRow.vala b/core/Widgets/LabelPicker/LabelRow.vala index 67c5cd755..3a72cbf13 100644 --- a/core/Widgets/LabelPicker/LabelRow.vala +++ b/core/Widgets/LabelPicker/LabelRow.vala @@ -37,7 +37,7 @@ public class Widgets.LabelPicker.LabelRow : Gtk.ListBoxRow { ); } - ~LabelRow() { + ~LabelRow () { print ("Destroying Widgets.LabelPicker.LabelRow\n"); } diff --git a/src/App.vala b/src/App.vala index cf7ee5662..ebfe2b9c2 100644 --- a/src/App.vala +++ b/src/App.vala @@ -54,7 +54,7 @@ public class Planify : Adw.Application { ); } - ~Planify() { + ~Planify () { print ("Destroying Planify\n"); } diff --git a/src/Dialogs/DatePicker.vala b/src/Dialogs/DatePicker.vala index 053744fff..ac1c76cf3 100644 --- a/src/Dialogs/DatePicker.vala +++ b/src/Dialogs/DatePicker.vala @@ -54,7 +54,7 @@ public class Dialogs.DatePicker : Adw.Dialog { ); } - ~DatePicker() { + ~DatePicker () { print ("Destroying Dialogs.DatePicker\n"); } diff --git a/src/Dialogs/ErrorDialog.vala b/src/Dialogs/ErrorDialog.vala index e80f319fe..539b0725d 100644 --- a/src/Dialogs/ErrorDialog.vala +++ b/src/Dialogs/ErrorDialog.vala @@ -32,7 +32,7 @@ public class Dialogs.ErrorDialog : Adw.Dialog { ); } - ~ErrorDialog() { + ~ErrorDialog () { print ("Destroying Dialogs.ErrorDialog\n"); } diff --git a/src/Dialogs/Label.vala b/src/Dialogs/Label.vala index fc5335a76..ed09d1a0f 100644 --- a/src/Dialogs/Label.vala +++ b/src/Dialogs/Label.vala @@ -51,7 +51,7 @@ public class Dialogs.Label : Adw.Dialog { ); } - ~Label() { + ~Label () { print ("Destroying Dialogs.Label\n"); } diff --git a/src/Dialogs/ManageProjects.vala b/src/Dialogs/ManageProjects.vala index c31c996b2..f8a12bf0a 100644 --- a/src/Dialogs/ManageProjects.vala +++ b/src/Dialogs/ManageProjects.vala @@ -31,7 +31,7 @@ public class Dialogs.ManageProjects : Adw.Dialog { ); } - ~ManageProjects() { + ~ManageProjects () { print ("Destroying Dialogs.ManageProjects\n"); } diff --git a/src/Dialogs/ManageSectionOrder.vala b/src/Dialogs/ManageSectionOrder.vala index 23851b00d..5a22b303f 100644 --- a/src/Dialogs/ManageSectionOrder.vala +++ b/src/Dialogs/ManageSectionOrder.vala @@ -37,7 +37,7 @@ public class Dialogs.ManageSectionOrder : Adw.Dialog { ); } - ~ManageSectionOrder() { + ~ManageSectionOrder () { print ("Destroying Dialogs.ManageSectionOrder\n"); } diff --git a/src/Dialogs/Preferences/Pages/Backup.vala b/src/Dialogs/Preferences/Pages/Backup.vala index 65cda0bdc..d0451f934 100644 --- a/src/Dialogs/Preferences/Pages/Backup.vala +++ b/src/Dialogs/Preferences/Pages/Backup.vala @@ -25,7 +25,7 @@ public class Dialogs.Preferences.Pages.Backup : Adw.Bin { public signal void pop_subpage (); public signal void popup_toast (string message); - ~Backup() { + ~Backup () { print ("Destroying Dialogs.Preferences.Pages.Backup\n"); } diff --git a/src/Dialogs/Preferences/PreferencesWindow.vala b/src/Dialogs/Preferences/PreferencesWindow.vala index c212feda0..0c21a18a4 100644 --- a/src/Dialogs/Preferences/PreferencesWindow.vala +++ b/src/Dialogs/Preferences/PreferencesWindow.vala @@ -27,7 +27,7 @@ public class Dialogs.Preferences.PreferencesWindow : Adw.PreferencesDialog { ); } - ~PreferencesWindow() { + ~PreferencesWindow () { print ("Destroying Dialogs.Preferences.PreferencesWindow\n"); } diff --git a/src/Dialogs/Preferences/SettingsHeader.vala b/src/Dialogs/Preferences/SettingsHeader.vala index 58b78dff6..98b4c7900 100644 --- a/src/Dialogs/Preferences/SettingsHeader.vala +++ b/src/Dialogs/Preferences/SettingsHeader.vala @@ -41,7 +41,7 @@ public class Dialogs.Preferences.SettingsHeader : Adw.Bin { ); } - ~SettingsHeader() { + ~SettingsHeader () { print ("Destroying Dialogs.Preferences.SettingsHeader\n"); } diff --git a/src/Dialogs/Project.vala b/src/Dialogs/Project.vala index d886f29be..823d6c5f9 100644 --- a/src/Dialogs/Project.vala +++ b/src/Dialogs/Project.vala @@ -67,7 +67,7 @@ public class Dialogs.Project : Adw.Dialog { ); } - ~Project() { + ~Project () { print ("Destroying Dialogs.Project\n"); } diff --git a/src/Dialogs/QuickAdd.vala b/src/Dialogs/QuickAdd.vala index 0ddf48a64..4e3ff555c 100644 --- a/src/Dialogs/QuickAdd.vala +++ b/src/Dialogs/QuickAdd.vala @@ -29,7 +29,7 @@ public class Dialogs.QuickAdd : Adw.Dialog { ); } - ~QuickAdd() { + ~QuickAdd () { print ("Destroying Dialogs.QuickAdd\n"); } diff --git a/src/Dialogs/Section.vala b/src/Dialogs/Section.vala index 47d998b4f..a562e5703 100644 --- a/src/Dialogs/Section.vala +++ b/src/Dialogs/Section.vala @@ -52,7 +52,7 @@ public class Dialogs.Section : Adw.Dialog { ); } - ~Section() { + ~Section () { print ("Destroying Dialogs.Section\n"); } diff --git a/src/Dialogs/WhatsNew.vala b/src/Dialogs/WhatsNew.vala index b6b966992..39d7bb6b2 100644 --- a/src/Dialogs/WhatsNew.vala +++ b/src/Dialogs/WhatsNew.vala @@ -33,7 +33,7 @@ public class Dialogs.WhatsNew : Adw.Dialog { ); } - ~WhatsNew() { + ~WhatsNew () { print ("Destroying Dialogs.WhatsNew\n"); } diff --git a/src/Layouts/ProjectRow.vala b/src/Layouts/ProjectRow.vala index d3ae36b6a..cab1f10eb 100644 --- a/src/Layouts/ProjectRow.vala +++ b/src/Layouts/ProjectRow.vala @@ -84,7 +84,7 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow { ); } - ~ProjectRow() { + ~ProjectRow () { print ("Destroying Layouts.ProjectRow\n"); } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 5337b5478..584e54439 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -45,7 +45,7 @@ public class MainWindow : Adw.ApplicationWindow { ); } - ~MainWindow() { + ~MainWindow () { print ("Destroy ing MainWindow\n"); } diff --git a/src/Widgets/ItemChangeHistoryRow.vala b/src/Widgets/ItemChangeHistoryRow.vala index f169591c7..11bac911e 100644 --- a/src/Widgets/ItemChangeHistoryRow.vala +++ b/src/Widgets/ItemChangeHistoryRow.vala @@ -30,7 +30,7 @@ public class Widgets.ItemChangeHistoryRow : Gtk.ListBoxRow { ); } - ~ItemChangeHistoryRow() { + ~ItemChangeHistoryRow () { print ("Destroying Widgets.ItemChangeHistoryRow\n"); } diff --git a/src/Widgets/ReorderChild.vala b/src/Widgets/ReorderChild.vala index c0707e619..ccde411de 100644 --- a/src/Widgets/ReorderChild.vala +++ b/src/Widgets/ReorderChild.vala @@ -52,7 +52,7 @@ public class Widgets.ReorderChild : Adw.Bin { ); } - ~ReorderChild() { + ~ReorderChild () { print ("Destroying Widgets.ReorderChild\n"); } diff --git a/src/Widgets/SourceRow.vala b/src/Widgets/SourceRow.vala index 03fb5910b..c8d2f5189 100644 --- a/src/Widgets/SourceRow.vala +++ b/src/Widgets/SourceRow.vala @@ -1,68 +1,68 @@ /* -* 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 -* License as published by the Free Software Foundation; either -* version 3 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -* Authored by: Alain M. -*/ + * 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 + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Alain M. + */ public class Widgets.SourceRow : Gtk.ListBoxRow { - public Objects.Source source { get; construct; } - - private Gtk.Revealer main_revealer; - - public signal void view_detail (); - - public SourceRow (Objects.Source source) { - Object ( - source: source - ); - } - - construct { - add_css_class ("no-selectable"); - - var visible_checkbutton = new Gtk.CheckButton () { - active = source.is_visible - }; - - var header_label = new Gtk.Label (source.display_name) { - halign = Gtk.Align.START - }; - - var subheader_label = new Gtk.Label (source.subheader_text) { - halign = Gtk.Align.START, - css_classes = { "caption", "dim-label" }, - visible = source.source_type != SourceType.LOCAL - }; - - var header_label_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { - valign = Gtk.Align.CENTER - }; - header_label_box.append (header_label); - header_label_box.append (subheader_label); - - var setting_button = new Gtk.Button.from_icon_name ("settings-symbolic") { + public Objects.Source source { get; construct; } + + private Gtk.Revealer main_revealer; + + public signal void view_detail (); + + public SourceRow (Objects.Source source) { + Object ( + source: source + ); + } + + construct { + add_css_class ("no-selectable"); + + var visible_checkbutton = new Gtk.CheckButton () { + active = source.is_visible + }; + + var header_label = new Gtk.Label (source.display_name) { + halign = Gtk.Align.START + }; + + var subheader_label = new Gtk.Label (source.subheader_text) { + halign = Gtk.Align.START, + css_classes = { "caption", "dim-label" }, + visible = source.source_type != SourceType.LOCAL + }; + + var header_label_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { + valign = Gtk.Align.CENTER + }; + header_label_box.append (header_label); + header_label_box.append (subheader_label); + + var setting_button = new Gtk.Button.from_icon_name ("settings-symbolic") { valign = Gtk.Align.CENTER, halign = Gtk.Align.CENTER, css_classes = { "flat" }, - visible = source.source_type != SourceType.LOCAL + visible = source.source_type != SourceType.LOCAL }; - var renove_item = new Widgets.ContextMenu.MenuItem (_("Remove"), "user-trash-symbolic"); + var renove_item = new Widgets.ContextMenu.MenuItem (_("Remove"), "user-trash-symbolic"); var menu_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); menu_box.margin_top = menu_box.margin_bottom = 3; @@ -76,101 +76,101 @@ public class Widgets.SourceRow : Gtk.ListBoxRow { }; var menu_button = new Gtk.MenuButton () { - valign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER, icon_name = "view-more-symbolic", - css_classes = { "flat", "dim-label" }, - tooltip_markup = _("Add Source"), + css_classes = { "flat", "dim-label" }, + tooltip_markup = _("Add Source"), popover = popover, - visible = source.source_type != SourceType.LOCAL - }; + visible = source.source_type != SourceType.LOCAL + }; - var end_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { - hexpand = true, - halign = END - }; - end_box.append (setting_button); - end_box.append (menu_button); + var end_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { + hexpand = true, + halign = END + }; + end_box.append (setting_button); + end_box.append (menu_button); var content_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { - margin_top = 6, - margin_bottom = 6, - margin_start = 6, - margin_end = 6 - }; - - content_box.append (visible_checkbutton); - content_box.append (header_label_box); - content_box.append (end_box); - - var card = new Adw.Bin () { - child = content_box, - margin_top = 3, - margin_bottom = 3, - margin_start = 3, - margin_end = 3 - }; - - var reorder = new Widgets.ReorderChild (card, this); + margin_top = 6, + margin_bottom = 6, + margin_start = 6, + margin_end = 6 + }; + + content_box.append (visible_checkbutton); + content_box.append (header_label_box); + content_box.append (end_box); + + var card = new Adw.Bin () { + child = content_box, + margin_top = 3, + margin_bottom = 3, + margin_start = 3, + margin_end = 3 + }; + + var reorder = new Widgets.ReorderChild (card, this); main_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN, + transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN, child = reorder - }; - + }; + child = main_revealer; - reorder.build_drag_and_drop (); + reorder.build_drag_and_drop (); + + Timeout.add (main_revealer.transition_duration, () => { + main_revealer.reveal_child = true; + return GLib.Source.REMOVE; + }); + + source.updated.connect (() => { + header_label.label = source.display_name; + }); + + visible_checkbutton.toggled.connect (() => { + source.is_visible = visible_checkbutton.active; + source.save (); + }); + + setting_button.clicked.connect (() => { + view_detail (); + }); + + renove_item.clicked.connect (() => { + popover.popdown (); + source.delete_source (Planify._instance.main_window); + }); + + reorder.on_drop_end.connect ((listbox) => { + update_views_order (listbox); + }); + } + + private void update_views_order (Gtk.ListBox listbox) { + unowned Widgets.SourceRow? row = null; + var row_index = 0; + + do { + row = (Widgets.SourceRow) listbox.get_row_at_index (row_index); + + if (row != null) { + row.source.child_order = row_index; + row.source.save (); + } + + row_index++; + } while (row != null); + + Services.EventBus.get_default ().update_sources_position (); + } + public void hide_destroy () { + main_revealer.reveal_child = false; Timeout.add (main_revealer.transition_duration, () => { - main_revealer.reveal_child = true; - return GLib.Source.REMOVE; - }); - - source.updated.connect (() => { - header_label.label = source.display_name; - }); - - visible_checkbutton.toggled.connect (() => { - source.is_visible = visible_checkbutton.active; - source.save (); - }); - - setting_button.clicked.connect (() => { - view_detail (); - }); - - renove_item.clicked.connect (() => { - popover.popdown (); - source.delete_source (Planify._instance.main_window); - }); - - reorder.on_drop_end.connect ((listbox) => { - update_views_order (listbox); - }); - } - - private void update_views_order (Gtk.ListBox listbox) { - unowned Widgets.SourceRow? row = null; - var row_index = 0; - - do { - row = (Widgets.SourceRow) listbox.get_row_at_index (row_index); - - if (row != null) { - row.source.child_order = row_index; - row.source.save (); - } - - row_index++; - } while (row != null); - - Services.EventBus.get_default ().update_sources_position (); - } - - public void hide_destroy () { - main_revealer.reveal_child = false; - Timeout.add (main_revealer.transition_duration, () => { - ((Gtk.ListBox) parent).remove (this); - return GLib.Source.REMOVE; - }); - } -} \ No newline at end of file + ((Gtk.ListBox) parent).remove (this); + return GLib.Source.REMOVE; + }); + } +} diff --git a/src/Widgets/SubItems.vala b/src/Widgets/SubItems.vala index 256d0df57..1c1645c05 100644 --- a/src/Widgets/SubItems.vala +++ b/src/Widgets/SubItems.vala @@ -469,4 +469,4 @@ public class Widgets.SubItems : Adw.Bin { return placeholder_grid; } -} \ No newline at end of file +}