From 22ffad6607a8cb677ba7f29395b44a8b980f42a8 Mon Sep 17 00:00:00 2001 From: mrvladus Date: Thu, 12 Oct 2023 13:15:56 +0300 Subject: [PATCH] Add calendar name --- data/io.github.mrvladus.List.gschema.xml | 3 +++ src/preferences.py | 8 +++++--- src/res/ui/preferences.ui | 7 +++++++ src/sync.py | 17 ++++++++++++----- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/data/io.github.mrvladus.List.gschema.xml b/data/io.github.mrvladus.List.gschema.xml index 8647d9b6..e9ee8797 100644 --- a/data/io.github.mrvladus.List.gschema.xml +++ b/data/io.github.mrvladus.List.gschema.xml @@ -31,6 +31,9 @@ "" + + "" + "" diff --git a/src/preferences.py b/src/preferences.py index 61675d5f..eb988b13 100644 --- a/src/preferences.py +++ b/src/preferences.py @@ -32,11 +32,12 @@ class PreferencesWindow(Adw.PreferencesWindow): light_theme: Gtk.CheckButton = Gtk.Template.Child() dark_theme: Gtk.CheckButton = Gtk.Template.Child() expand_on_startup: Gtk.Switch = Gtk.Template.Child() + sync_cal_name: Adw.EntryRow = Gtk.Template.Child() sync_providers: Adw.ComboRow = Gtk.Template.Child() - sync_url: Adw.EntryRow = Gtk.Template.Child() - sync_username: Adw.EntryRow = Gtk.Template.Child() sync_password: Adw.EntryRow = Gtk.Template.Child() sync_token: Adw.EntryRow = Gtk.Template.Child() + sync_url: Adw.EntryRow = Gtk.Template.Child() + sync_username: Adw.EntryRow = Gtk.Template.Child() test_connection_row: Adw.ActionRow = Gtk.Template.Child() selected_provider = 0 @@ -59,6 +60,7 @@ def __init__(self, win: Adw.ApplicationWindow) -> None: GSettings.bind("sync-url", self.sync_url, "text") GSettings.bind("sync-username", self.sync_username, "text") GSettings.bind("sync-password", self.sync_password, "text") + GSettings.bind("sync-cal-name", self.sync_cal_name, "text") self.setup_sync() def setup_sync(self): @@ -67,7 +69,7 @@ def setup_sync(self): self.sync_url.set_visible(selected != 3 and selected != 0) self.sync_username.set_visible(selected != 3 and selected != 0) self.sync_password.set_visible(selected != 3 and selected != 0) - + self.sync_cal_name.set_visible(selected != 3 and selected != 0) self.test_connection_row.set_visible(selected > 0) # --- Template handlers --- # diff --git a/src/res/ui/preferences.ui b/src/res/ui/preferences.ui index 7968ec4e..d274037c 100644 --- a/src/res/ui/preferences.ui +++ b/src/res/ui/preferences.ui @@ -126,6 +126,13 @@ + + + + Calendar Name ("Errands" by Default) + + + diff --git a/src/sync.py b/src/sync.py index 9f73ad37..1813be04 100644 --- a/src/sync.py +++ b/src/sync.py @@ -181,16 +181,23 @@ def _fetch(self): UserData.set(data) def _setup_calendar(self, principal: Principal) -> None: - # Get calendars calendars: list[Calendar] = principal.calendars() - # Check if Errands calendar exists + cal_name = GSettings.get("sync-cal-name") + cal_exists: bool = False errands_cal_exists: bool = False for cal in calendars: - if cal.name == "Errands": + if cal.name == cal_name: + self.calendar = cal + cal_exists = True + elif cal.name == "Errands" and cal_name == "": self.calendar = cal errands_cal_exists = True - # Create one if not - if not errands_cal_exists: + if not cal_exists and cal_name != "": + Log.debug(f"Create new calendar '{cal_name}' on {self.name}") + self.calendar = principal.make_calendar( + cal_name, supported_calendar_component_set=["VTODO"] + ) + if not errands_cal_exists and cal_name == "": Log.debug(f"Create new calendar 'Errands' on {self.name}") self.calendar = principal.make_calendar( "Errands", supported_calendar_component_set=["VTODO"]