Skip to content

Commit

Permalink
Add calendar name
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Oct 12, 2023
1 parent 5960b1e commit 22ffad6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
3 changes: 3 additions & 0 deletions data/io.github.mrvladus.List.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<key name="sync-password" type="s">
<default>""</default>
</key>
<key name="sync-cal-name" type="s">
<default>""</default>
</key>
<key name="sync-token" type="s">
<default>""</default>
</key>
Expand Down
8 changes: 5 additions & 3 deletions src/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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 --- #
Expand Down
7 changes: 7 additions & 0 deletions src/res/ui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@
</object>
</child>

<!-- Calendar name -->
<child>
<object class="AdwEntryRow" id="sync_cal_name">
<property name="title" translatable="yes">Calendar Name ("Errands" by Default)</property>
</object>
</child>

<!-- Token -->
<child>
<object class="AdwPasswordEntryRow" id="sync_token">
Expand Down
17 changes: 12 additions & 5 deletions src/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 22ffad6

Please sign in to comment.