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
|
This is a simple gtk4 libadwaita Notes program which uses CalDAV as a backend
|
||||||
to store the notes in a calendar as VJOURNAL.
|
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/preferences.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/help-overlay.ui</file>
|
<file preprocess="xml-stripblanks">ui/help-overlay.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/sidebar.ui</file>
|
<file preprocess="xml-stripblanks">ui/sidebar.ui</file>
|
||||||
|
<file preprocess="xml-stripblanks">ui/notes_list.ui</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
|
11
src/main.py
11
src/main.py
|
@ -28,6 +28,7 @@ from .window import JnotesWindow
|
||||||
from .preferences import PreferencesWindow
|
from .preferences import PreferencesWindow
|
||||||
from .sidebar import Sidebar
|
from .sidebar import Sidebar
|
||||||
from .sync import Sync
|
from .sync import Sync
|
||||||
|
from .notes_list import NotesList
|
||||||
|
|
||||||
|
|
||||||
class JnotesApplication(Adw.Application):
|
class JnotesApplication(Adw.Application):
|
||||||
|
@ -53,11 +54,19 @@ class JnotesApplication(Adw.Application):
|
||||||
win = JnotesWindow(application=self)
|
win = JnotesWindow(application=self)
|
||||||
win.present()
|
win.present()
|
||||||
|
|
||||||
self.calendar_set = Sync.get_calendar_set()
|
def callback(calendar_set):
|
||||||
|
self.calendar_set = calendar_set
|
||||||
if not self.calendar_set:
|
if not self.calendar_set:
|
||||||
self.on_preferences_action(win, False)
|
self.on_preferences_action(win, False)
|
||||||
else:
|
else:
|
||||||
win.sidebar.set_calendars(self.calendar_set)
|
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, _):
|
def on_about_action(self, widget, _):
|
||||||
"""Callback for the app.about action."""
|
"""Callback for the app.about action."""
|
||||||
|
|
|
@ -34,6 +34,7 @@ jnotes_sources = [
|
||||||
'gsettings.py',
|
'gsettings.py',
|
||||||
'sync.py',
|
'sync.py',
|
||||||
'sidebar.py',
|
'sidebar.py',
|
||||||
|
'notes_list.py',
|
||||||
]
|
]
|
||||||
|
|
||||||
install_data(jnotes_sources, install_dir: moduledir)
|
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()
|
server_url = Gtk.Template.Child()
|
||||||
username = Gtk.Template.Child()
|
username = Gtk.Template.Child()
|
||||||
password = Gtk.Template.Child()
|
password = Gtk.Template.Child()
|
||||||
spinner = Gtk.Template.Child()
|
preferences_spinner = Gtk.Template.Child()
|
||||||
test_connection_row = Gtk.Template.Child()
|
test_connection_row = Gtk.Template.Child()
|
||||||
test_connection = Gtk.Template.Child()
|
test_connection = Gtk.Template.Child()
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||||
server_url = self.server_url.get_text()
|
server_url = self.server_url.get_text()
|
||||||
username = self.username.get_text()
|
username = self.username.get_text()
|
||||||
password = self.password.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)
|
GLib.idle_add(self.deactivate_test_button)
|
||||||
Sync.test_connection(server_url, username, password, self.sync_ok_callback)
|
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):
|
def sync_ok_callback(self, ok, e=None):
|
||||||
self.activate_test_button()
|
self.activate_test_button()
|
||||||
self.spinner.stop()
|
self.preferences_spinner.stop()
|
||||||
if ok:
|
if ok:
|
||||||
self.test_connection_row.set_icon_name("emblem-ok-symbolic")
|
self.test_connection_row.set_icon_name("emblem-ok-symbolic")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -25,6 +25,7 @@ class Sidebar(Adw.NavigationPage):
|
||||||
__gtype_name__ = 'Sidebar'
|
__gtype_name__ = 'Sidebar'
|
||||||
|
|
||||||
calendar_set = Gtk.Template.Child()
|
calendar_set = Gtk.Template.Child()
|
||||||
|
spinner = Gtk.Template.Child()
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
23
src/sync.py
23
src/sync.py
|
@ -40,6 +40,11 @@ def threaded(function: Callable):
|
||||||
class Sync():
|
class Sync():
|
||||||
client = None
|
client = None
|
||||||
principal = None
|
principal = None
|
||||||
|
spinner = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_spinner(self, spinner):
|
||||||
|
self.spinner = spinner
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@threaded
|
@threaded
|
||||||
|
@ -70,8 +75,10 @@ class Sync():
|
||||||
logging.warning(e)
|
logging.warning(e)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_calendar_set(self):
|
@threaded
|
||||||
|
def get_calendar_set(self, callback):
|
||||||
calendar_set = CalendarSet()
|
calendar_set = CalendarSet()
|
||||||
|
self.spinner.start()
|
||||||
if not self.client:
|
if not self.client:
|
||||||
self.init()
|
self.init()
|
||||||
if self.principal:
|
if self.principal:
|
||||||
|
@ -79,13 +86,21 @@ class Sync():
|
||||||
for remote_calendar in remote_calendars:
|
for remote_calendar in remote_calendars:
|
||||||
if "VJOURNAL" in remote_calendar.get_supported_components():
|
if "VJOURNAL" in remote_calendar.get_supported_components():
|
||||||
calendar = Calendar(remote_calendar.get_display_name(), remote_calendar.url)
|
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():
|
for journal in remote_calendar.journals():
|
||||||
summary = journal.icalendar_component.get("summary", "")
|
summary = journal.icalendar_component.get("summary", "")
|
||||||
description = journal.icalendar_component.get("description", "")
|
description = journal.icalendar_component.get("description", "")
|
||||||
calendar.add_note(Note(calendar, summary, description))
|
calendar.add_note(Note(calendar, summary, description))
|
||||||
calendar_set.add_calendar(calendar)
|
self.spinner.stop()
|
||||||
|
callback(calendar)
|
||||||
return calendar_set
|
|
||||||
|
|
||||||
class CalendarSet(Gio.ListStore):
|
class CalendarSet(Gio.ListStore):
|
||||||
def add_calendar(self, calendar):
|
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">
|
<object class="AdwActionRow" id="test_connection_row">
|
||||||
<property name="title">Test Connection</property>
|
<property name="title">Test Connection</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSpinner" id="spinner"></object>
|
<object class="GtkSpinner" id="preferences_spinner"></object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="test_connection">
|
<object class="GtkButton" id="test_connection">
|
||||||
|
|
|
@ -7,12 +7,8 @@
|
||||||
<object class="AdwToolbarView">
|
<object class="AdwToolbarView">
|
||||||
<child type="top">
|
<child type="top">
|
||||||
<object class="AdwHeaderBar">
|
<object class="AdwHeaderBar">
|
||||||
<child type="start">
|
<child type="end">
|
||||||
<object class="GtkToggleButton">
|
<object class="GtkSpinner" id="spinner"></object>
|
||||||
<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>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
|
|
@ -36,9 +36,7 @@
|
||||||
<object class="AdwNavigationSplitView" id="split_view">
|
<object class="AdwNavigationSplitView" id="split_view">
|
||||||
<property name="min-sidebar-width">200</property>
|
<property name="min-sidebar-width">200</property>
|
||||||
<property name="sidebar">
|
<property name="sidebar">
|
||||||
<object class="Sidebar" id="sidebar">
|
<object class="Sidebar" id="sidebar"></object>
|
||||||
|
|
||||||
</object>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="content">
|
<property name="content">
|
||||||
<object class="AdwNavigationPage">
|
<object class="AdwNavigationPage">
|
||||||
|
@ -58,37 +56,7 @@
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<property name="content">
|
<property name="content">
|
||||||
<object class="GtkScrolledWindow">
|
<object class="NotesList" id="notes_list"></object>
|
||||||
<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>
|
|
||||||
</property>
|
</property>
|
||||||
</object>
|
</object>
|
||||||
</property>
|
</property>
|
||||||
|
@ -99,3 +67,4 @@
|
||||||
</template>
|
</template>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ class JnotesWindow(Adw.ApplicationWindow):
|
||||||
__gtype_name__ = 'JnotesWindow'
|
__gtype_name__ = 'JnotesWindow'
|
||||||
|
|
||||||
sidebar = Gtk.Template.Child()
|
sidebar = Gtk.Template.Child()
|
||||||
|
notes_list = Gtk.Template.Child()
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue