From f4912dd549d7a1af096d367f54ac8a4e29e08f84 Mon Sep 17 00:00:00 2001 From: mrvladus Date: Fri, 13 Oct 2023 15:03:16 +0300 Subject: [PATCH] Add other CalDAV providers support --- src/preferences.py | 10 +++++----- src/res/ui/preferences.ui | 2 +- src/sync.py | 18 +++++++++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/preferences.py b/src/preferences.py index 9ae8e5e8..3022886c 100644 --- a/src/preferences.py +++ b/src/preferences.py @@ -47,11 +47,11 @@ def __init__(self, win: Adw.ApplicationWindow) -> None: def setup_sync(self): selected = self.sync_providers.props.selected - self.sync_token.set_visible(selected == 3 and selected != 0) - 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.sync_url.set_visible(0 < selected < 3) + self.sync_username.set_visible(0 < selected < 3) + self.sync_password.set_visible(0 < selected < 3) + self.sync_cal_name.set_visible(0 < selected < 3) + self.sync_token.set_visible(0 < selected > 3) 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 a71bc7a8..e86bfd62 100644 --- a/src/res/ui/preferences.ui +++ b/src/res/ui/preferences.ui @@ -95,7 +95,7 @@ Disabled Nextcloud - + Other CalDAV Provider diff --git a/src/sync.py b/src/sync.py index a83ac755..8919ff40 100644 --- a/src/sync.py +++ b/src/sync.py @@ -21,6 +21,8 @@ def init(self, window: Adw.ApplicationWindow = None, testing: bool = False) -> N self.window.sync_btn.set_visible(False) case 1: self.provider = SyncProviderCalDAV("Nextcloud", self.window, testing) + case 2: + self.provider = SyncProviderCalDAV("CalDAV", self.window, testing) @classmethod @threaded @@ -79,11 +81,21 @@ def _check_credentials(self) -> bool: return True def _check_url(self) -> None: + # Add prefix if needed if not self.url.startswith("http"): self.url = "http://" + self.url GSettings.set("sync-url", "s", self.url) + # For Nextcloud provider if self.name == "Nextcloud": - self.url = f"{self.url}/remote.php/dav/" + # Add suffix if needed + if not GSettings.get("sync-url").endswith("/remote.php/dav/"): + self.url = f"{self.url}/remote.php/dav/" + GSettings.set("sync-url", "s", self.url) + else: + self.url = GSettings.get("sync-url") + # For other CalDAV providers + if self.name == "CalDAV": + self.url = GSettings.get("sync-url") def _connect(self) -> bool: with DAVClient( @@ -91,12 +103,12 @@ def _connect(self) -> bool: ) as client: try: principal: Principal = client.principal() - Log.info(f"Connected to {self.name} CalDAV server at '{self.url}'") + Log.info(f"Connected to {self.name} server at '{self.url}'") self.can_sync = True self._setup_calendar(principal) self.window.sync_btn.set_visible(True) except: - Log.error(f"Can't connect to {self.name} CalDAV server at '{self.url}'") + Log.error(f"Can't connect to {self.name} server at '{self.url}'") if not self.testing: self.window.add_toast( _("Can't connect to CalDAV server at:") # pyright:ignore