Add NotesList to show notes of first calendar
This commit is contained in:
parent
9439b53021
commit
871a14ddc0
13 changed files with 99 additions and 56 deletions
|
@ -1,4 +1,4 @@
|
|||
# jnotes
|
||||
# JNotes
|
||||
|
||||
This is a simple gtk4 libadwaita Notes program which uses CalDAV as a backend
|
||||
to store the notes in a calendar as VJOURNAL.
|
||||
|
|
|
@ -5,5 +5,6 @@
|
|||
<file preprocess="xml-stripblanks">ui/preferences.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/help-overlay.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/sidebar.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/notes_list.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
11
src/main.py
11
src/main.py
|
@ -28,6 +28,7 @@ from .window import JnotesWindow
|
|||
from .preferences import PreferencesWindow
|
||||
from .sidebar import Sidebar
|
||||
from .sync import Sync
|
||||
from .notes_list import NotesList
|
||||
|
||||
|
||||
class JnotesApplication(Adw.Application):
|
||||
|
@ -53,11 +54,19 @@ class JnotesApplication(Adw.Application):
|
|||
win = JnotesWindow(application=self)
|
||||
win.present()
|
||||
|
||||
self.calendar_set = Sync.get_calendar_set()
|
||||
def callback(calendar_set):
|
||||
self.calendar_set = calendar_set
|
||||
if not self.calendar_set:
|
||||
self.on_preferences_action(win, False)
|
||||
else:
|
||||
win.sidebar.set_calendars(self.calendar_set)
|
||||
def callb(calendar):
|
||||
win.notes_list.set_calendar(calendar)
|
||||
Sync.get_calenndar_notes(self.calendar_set[0], callb)
|
||||
|
||||
Sync.set_spinner(win.sidebar.spinner)
|
||||
Sync.get_calendar_set(callback)
|
||||
|
||||
|
||||
def on_about_action(self, widget, _):
|
||||
"""Callback for the app.about action."""
|
||||
|
|
|
@ -34,6 +34,7 @@ jnotes_sources = [
|
|||
'gsettings.py',
|
||||
'sync.py',
|
||||
'sidebar.py',
|
||||
'notes_list.py',
|
||||
]
|
||||
|
||||
install_data(jnotes_sources, install_dir: moduledir)
|
||||
|
|
21
src/notes_list.py
Normal file
21
src/notes_list.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from gi.repository import Adw
|
||||
from gi.repository import Gtk
|
||||
|
||||
@Gtk.Template(resource_path='/net/jeena/jnotes/ui/notes_list.ui')
|
||||
class NotesList(Gtk.ScrolledWindow):
|
||||
__gtype_name__ = 'NotesList'
|
||||
|
||||
notes_list = Gtk.Template.Child()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def set_calendar(self, calendar):
|
||||
self.notes_list.bind_model(calendar, self.create_item_widget)
|
||||
|
||||
def create_item_widget(self, note):
|
||||
print(note.summary)
|
||||
return Gtk.Label(label=note.summary, halign="start",
|
||||
hexpand=True, ellipsize=3)
|
|
@ -31,7 +31,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||
server_url = Gtk.Template.Child()
|
||||
username = Gtk.Template.Child()
|
||||
password = Gtk.Template.Child()
|
||||
spinner = Gtk.Template.Child()
|
||||
preferences_spinner = Gtk.Template.Child()
|
||||
test_connection_row = Gtk.Template.Child()
|
||||
test_connection = Gtk.Template.Child()
|
||||
|
||||
|
@ -46,7 +46,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||
server_url = self.server_url.get_text()
|
||||
username = self.username.get_text()
|
||||
password = self.password.get_text()
|
||||
GLib.idle_add(self.spinner.start)
|
||||
GLib.idle_add(self.preferences_spinner.start)
|
||||
GLib.idle_add(self.deactivate_test_button)
|
||||
Sync.test_connection(server_url, username, password, self.sync_ok_callback)
|
||||
|
||||
|
@ -72,7 +72,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||
|
||||
def sync_ok_callback(self, ok, e=None):
|
||||
self.activate_test_button()
|
||||
self.spinner.stop()
|
||||
self.preferences_spinner.stop()
|
||||
if ok:
|
||||
self.test_connection_row.set_icon_name("emblem-ok-symbolic")
|
||||
else:
|
||||
|
|
|
@ -25,6 +25,7 @@ class Sidebar(Adw.NavigationPage):
|
|||
__gtype_name__ = 'Sidebar'
|
||||
|
||||
calendar_set = Gtk.Template.Child()
|
||||
spinner = Gtk.Template.Child()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
|
23
src/sync.py
23
src/sync.py
|
@ -40,6 +40,11 @@ def threaded(function: Callable):
|
|||
class Sync():
|
||||
client = None
|
||||
principal = None
|
||||
spinner = None
|
||||
|
||||
@classmethod
|
||||
def set_spinner(self, spinner):
|
||||
self.spinner = spinner
|
||||
|
||||
@classmethod
|
||||
@threaded
|
||||
|
@ -70,8 +75,10 @@ class Sync():
|
|||
logging.warning(e)
|
||||
|
||||
@classmethod
|
||||
def get_calendar_set(self):
|
||||
@threaded
|
||||
def get_calendar_set(self, callback):
|
||||
calendar_set = CalendarSet()
|
||||
self.spinner.start()
|
||||
if not self.client:
|
||||
self.init()
|
||||
if self.principal:
|
||||
|
@ -79,13 +86,21 @@ class Sync():
|
|||
for remote_calendar in remote_calendars:
|
||||
if "VJOURNAL" in remote_calendar.get_supported_components():
|
||||
calendar = Calendar(remote_calendar.get_display_name(), remote_calendar.url)
|
||||
calendar_set.add_calendar(calendar)
|
||||
self.spinner.stop()
|
||||
callback(calendar_set)
|
||||
|
||||
@classmethod
|
||||
@threaded
|
||||
def get_calenndar_notes(self, calendar, callback):
|
||||
self.spinner.start()
|
||||
remote_calendar = self.principal.calendar(calendar.displayname)
|
||||
for journal in remote_calendar.journals():
|
||||
summary = journal.icalendar_component.get("summary", "")
|
||||
description = journal.icalendar_component.get("description", "")
|
||||
calendar.add_note(Note(calendar, summary, description))
|
||||
calendar_set.add_calendar(calendar)
|
||||
|
||||
return calendar_set
|
||||
self.spinner.stop()
|
||||
callback(calendar)
|
||||
|
||||
class CalendarSet(Gio.ListStore):
|
||||
def add_calendar(self, calendar):
|
||||
|
|
29
src/ui/notes_list.ui
Normal file
29
src/ui/notes_list.ui
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="NotesList" parent="GtkScrolledWindow">
|
||||
<property name="child">
|
||||
<object class="AdwClamp">
|
||||
<property name="maximum-size">500</property>
|
||||
<property name="tightening-threshold">400</property>
|
||||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="margin-start">12</property>
|
||||
<property name="margin-end">12</property>
|
||||
<property name="spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkListBox" id="notes_list">
|
||||
<property name="visible">True</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<style>
|
||||
<class name="boxed-list" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
</template>
|
||||
</interface>
|
|
@ -33,7 +33,7 @@
|
|||
<object class="AdwActionRow" id="test_connection_row">
|
||||
<property name="title">Test Connection</property>
|
||||
<child>
|
||||
<object class="GtkSpinner" id="spinner"></object>
|
||||
<object class="GtkSpinner" id="preferences_spinner"></object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="test_connection">
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar">
|
||||
<child type="start">
|
||||
<object class="GtkToggleButton">
|
||||
<property name="icon-name">list-add-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">New Collection</property>
|
||||
<property name="action-name">win.new-collection</property>
|
||||
</object>
|
||||
<child type="end">
|
||||
<object class="GtkSpinner" id="spinner"></object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
|
|
@ -36,9 +36,7 @@
|
|||
<object class="AdwNavigationSplitView" id="split_view">
|
||||
<property name="min-sidebar-width">200</property>
|
||||
<property name="sidebar">
|
||||
<object class="Sidebar" id="sidebar">
|
||||
|
||||
</object>
|
||||
<object class="Sidebar" id="sidebar"></object>
|
||||
</property>
|
||||
<property name="content">
|
||||
<object class="AdwNavigationPage">
|
||||
|
@ -58,37 +56,7 @@
|
|||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="child">
|
||||
<object class="AdwClamp">
|
||||
<property name="maximum-size">400</property>
|
||||
<property name="tightening-threshold">300</property>
|
||||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="margin-start">12</property>
|
||||
<property name="margin-end">12</property>
|
||||
<property name="spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="entry">
|
||||
<property name="placeholder-text" translatable="yes">Create new Note…</property>
|
||||
<property name="secondary-icon-name">list-add-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBox" id="tasks_list">
|
||||
<property name="visible">False</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<style>
|
||||
<class name="boxed-list" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
<object class="NotesList" id="notes_list"></object>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
|
@ -99,3 +67,4 @@
|
|||
</template>
|
||||
</interface>
|
||||
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ class JnotesWindow(Adw.ApplicationWindow):
|
|||
__gtype_name__ = 'JnotesWindow'
|
||||
|
||||
sidebar = Gtk.Template.Child()
|
||||
notes_list = Gtk.Template.Child()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue