Skip to content

Commit

Permalink
Add other CalDAV providers support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Oct 13, 2023
1 parent 49ffee9 commit f4912dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 --- #
Expand Down
2 changes: 1 addition & 1 deletion src/res/ui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<items>
<item translatable="yes">Disabled</item>
<item>Nextcloud</item>
<!-- <item>OwnCloud</item> -->
<item>Other CalDAV Provider</item>
<!-- <item>Todoist</item> -->
<!-- <item>Google Keep</item> -->
</items>
Expand Down
18 changes: 15 additions & 3 deletions src/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,24 +81,34 @@ 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(
url=self.url, username=self.username, password=self.password
) 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
Expand Down

0 comments on commit f4912dd

Please sign in to comment.