Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Sep 25, 2023
1 parent 89125b8 commit e9b4362
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
25 changes: 18 additions & 7 deletions src/sync.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
from .utils import GSettings, Log, TaskUtils, UserData
from gi.repository import Adw

from .utils import GSettings, Log, TaskUtils, UserData, threaded
from nextcloud_tasks_api import NextcloudTasksApi, TaskFile, get_nextcloud_tasks_api
from nextcloud_tasks_api.ical import Task


class Sync:
providers: list = []
window: Adw.ApplicationWindow = None

@classmethod
def init(self) -> None:
def init(self, window: Adw.ApplicationWindow) -> None:
self.window = window
self.providers.append(SyncProviderNextcloud())
# self.providers.append(SyncProviderTodoist())

# @threaded
@classmethod
def sync(self) -> None:
return
if not self.window.can_sync:
return
for provider in self.providers:
provider.sync()

Expand All @@ -22,7 +28,7 @@ def _setup_providers(self) -> None:


class SyncProviderNextcloud:
can_sync: bool = False
connected: bool = False

def __init__(self) -> None:
if not GSettings.get("nc-enabled"):
Expand Down Expand Up @@ -62,14 +68,19 @@ def connect(self) -> None:
return None

def get_tasks(self) -> list[TaskFile] | None:
if not GSettings.get("nc-enabled"):
return
try:
return [task for task in self.api.get_list(self.errands_task_list)]
Log.debug("Getting tasks from Nextcloud")
tasks = self.api.get_list(self.errands_task_list)
return [task for task in tasks]
except:
Log.error("Can't connect to Nextcloud server")
return None

def sync(self) -> None:
# TODO: can_sync property
if not GSettings.get("nc-enabled"):
return
Log.info("Sync tasks with Nextcloud")

data: dict = UserData.get()
Expand Down Expand Up @@ -129,7 +140,7 @@ def sync(self) -> None:

# Create new local task that was created on NC
l_ids: list = [t["id"] for t in data["tasks"]]
for task in nc_task:
for nc_task in self.get_tasks():
task_obj = Task(nc_task.content)
if task_obj.uid not in l_ids:
new_task = TaskUtils.new_task(
Expand Down
3 changes: 2 additions & 1 deletion src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Window(Adw.ApplicationWindow):
# - State - #
scrolling: bool = False # Is window scrolling
tasks: list[Task] = [] # Task widgets list
can_sync: bool = True # Can perform sync operations

def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
Expand Down Expand Up @@ -193,7 +194,7 @@ def shortcuts(*_) -> None:
create_action("open_log", open_log)

def load_tasks(self) -> None:
Sync.init()
Sync.init(self)
Sync.sync()
Log.debug("Loading tasks")
count: int = 0
Expand Down

0 comments on commit e9b4362

Please sign in to comment.