Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Oct 18, 2023
2 parents c7bf06c + 4eaf19f commit 4f3d705
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ install_data(
'preferences.py',
'sync.py',
'task.py',
'task_details.py',
'trash_item.py',
'utils.py',
'window.py',
Expand Down
1 change: 1 addition & 0 deletions src/res/errands.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<file preprocess="xml-stripblanks" compressed="true" alias="window.ui">ui/window.ui</file>
<file preprocess="xml-stripblanks" compressed="true" alias="preferences.ui">ui/preferences.ui</file>
<file preprocess="xml-stripblanks" compressed="true" alias="task.ui">ui/task.ui</file>
<file preprocess="xml-stripblanks" compressed="true" alias="task_details.ui">ui/task_details.ui</file>
<file preprocess="xml-stripblanks" compressed="true" alias="trash_item.ui">ui/trash_item.ui</file>
<file>style.css</file>
<file>style-dark.css</file>
Expand Down
5 changes: 4 additions & 1 deletion src/res/ui/task.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<attribute name="label" translatable="yes">Copy</attribute>
<attribute name="action">task.copy</attribute>
</item>
<!-- <item>
<attribute name="label" translatable="yes">Details</attribute>
<attribute name="action">task.details</attribute>
</item> -->
</section>
</menu>

Expand Down Expand Up @@ -410,6 +414,5 @@
</object>
</child>


</template>
</interface>
33 changes: 33 additions & 0 deletions src/res/ui/task_details.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0" />
<requires lib="Adw" version="1.0" />
<template class="TaskDetails" parent="AdwPreferencesWindow">
<property name="modal">true</property>
<property name="title">Details</property>
<child>
<object class="AdwPreferencesPage">
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwActionRow">
<property name="title">Open in Calendar</property>
<property name="activatable-widget">open_calendar_btn</property>
<child type="suffix">
<object class="GtkButton" id="open_calendar_btn">
<property name="valign">center</property>
<property name="icon-name">x-office-calendar-symbolic</property>
<signal name="clicked" handler="on_calendar_open" />
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>
5 changes: 5 additions & 0 deletions src/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Self
from gi.repository import Gtk, Adw, Gdk, GObject, Gio
from .sync import Sync
from .task_details import TaskDetails
from .utils import (
Log,
Markup,
Expand Down Expand Up @@ -77,6 +78,9 @@ def _copy(*args) -> None:
clp.set(self.task["text"])
self.window.add_toast(_("Copied to Clipboard")) # pyright:ignore

def _details(*args) -> None:
TaskDetails(self)

def _edit(*_) -> None:
self.toggle_edit_mode()
# Set entry text and select it
Expand All @@ -87,6 +91,7 @@ def _edit(*_) -> None:
_add_action("delete", self.delete)
_add_action("edit", _edit)
_add_action("copy", _copy)
_add_action("details", _details)

def add_task(self, task: dict):
sub_task = Task(task, self.window, self)
Expand Down
38 changes: 38 additions & 0 deletions src/task_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2023 Vlad Krupinskii <mrvladus@yandex.ru>
# SPDX-License-Identifier: MIT

import os
from gi.repository import Adw, Gtk, GLib, Gio
from .utils import Log


@Gtk.Template(resource_path="/io/github/mrvladus/Errands/task_details.ui")
class TaskDetails(Adw.PreferencesWindow):
__gtype_name__ = "TaskDetails"

def __init__(self, task) -> None:
super().__init__()
self.task = task
self.set_transient_for(task.window)
self.present()

def _delete_old_ics(self):
pass

def _convert_to_ics(self):
ics_text: str = "hello"
cache_dir: str = os.path.join(GLib.get_user_cache_dir(), "list")
if not os.path.exists(cache_dir):
os.mkdir(cache_dir)
with open(os.path.join(cache_dir, f"{self.task.task['id']}.ics"), "w") as f:
f.write(ics_text)

@Gtk.Template.Callback()
def on_calendar_open(self, _btn):
self._convert_to_ics()
file: Gio.File = Gio.File.new_for_path(
os.path.join(
GLib.get_user_cache_dir(), "list", f"{self.task.task['id']}.ics"
)
)
Gtk.FileLauncher.new(file).launch()
9 changes: 7 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def get(self) -> UserDataDict:
with open(os.path.join(self.data_dir, "data.json"), "r") as f:
data: UserDataDict = json.load(f)
if data["version"] != VERSION:
converted_data: UserDataDict = self.convert(self, data)
converted_data: UserDataDict = self.convert(data)
self.set(converted_data)
return converted_data
if not self.validate(data):
Expand All @@ -295,7 +295,7 @@ def get(self) -> UserDataDict:
Log.error(
f"Data file is corrupted. Creating backup at {os.path.join(self.data_dir, 'data.old.json')}"
)
self.create_copy(self)
self.create_copy()

# Save user data to json
@classmethod
Expand Down Expand Up @@ -397,5 +397,10 @@ def convert(self, data: UserDataDict) -> UserDataDict:
task["synced_caldav"] = False
# task["synced_todoist"] = False

elif ver == "45.0" and os.path.exists(
os.path.join(self.data_dir, "data.old.json")
):
pass

data["version"] = VERSION
return data

0 comments on commit 4f3d705

Please sign in to comment.