From c39ba20abefd7b8d0183994c0f5dbdd98008e815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 10 Oct 2022 15:01:07 +0200 Subject: [PATCH 1/6] debian/install: Drop leading '/' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make this consistent with phosh.install Gbp-Dch: Ignore Signed-off-by: Guido Günther Part-of: --- debian/phosh-doc.install | 2 +- debian/phosh-mobile-tweaks.install | 2 +- debian/phosh-plugins.install | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/debian/phosh-doc.install b/debian/phosh-doc.install index 7f0cf467d..c5d24aff8 100644 --- a/debian/phosh-doc.install +++ b/debian/phosh-doc.install @@ -1 +1 @@ -/usr/share/gtk-doc/html/phosh/ +usr/share/gtk-doc/html/phosh/ diff --git a/debian/phosh-mobile-tweaks.install b/debian/phosh-mobile-tweaks.install index 6c77abb2a..ff5939789 100644 --- a/debian/phosh-mobile-tweaks.install +++ b/debian/phosh-mobile-tweaks.install @@ -1 +1 @@ -/usr/share/glib-2.0/schemas/*.override +usr/share/glib-2.0/schemas/*.override diff --git a/debian/phosh-plugins.install b/debian/phosh-plugins.install index ee809e605..af2400deb 100644 --- a/debian/phosh-plugins.install +++ b/debian/phosh-plugins.install @@ -1,2 +1,2 @@ -/usr/lib/*/phosh/plugins/libphosh-plugin-*.so -/usr/lib/*/phosh/plugins/*.plugin +usr/lib/*/phosh/plugins/libphosh-plugin-*.so +usr/lib/*/phosh/plugins/*.plugin -- GitLab From 5b6da4bc1401857e984819f4cfe1cc9c9ff3e6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 10 Oct 2022 15:04:53 +0200 Subject: [PATCH 2/6] debian: Don't use wild card for schemas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to have plugin schemas in an extra package. Signed-off-by: Guido Günther Part-of: --- debian/phosh.install | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debian/phosh.install b/debian/phosh.install index f9408551a..7a6ac2930 100644 --- a/debian/phosh.install +++ b/debian/phosh.install @@ -6,7 +6,8 @@ usr/share/icons/hicolor/symbolic/apps/sm.puri.Phosh-symbolic.svg usr/share/locale usr/share/wayland-sessions/phosh.desktop usr/share/phosh/phoc.ini -usr/share/glib-2.0/schemas/sm.puri.phosh*.xml +usr/share/glib-2.0/schemas/sm.puri.phosh.enums.xml +usr/share/glib-2.0/schemas/sm.puri.phosh.gschema.xml usr/share/gnome-session/sessions/phosh.session usr/share/applications/sm.puri.Phosh.desktop usr/share/dbus-1/services/sm.puri.Phosh.CalendarServer.service -- GitLab From e3fc51fea62c917ad3a37580cb8c5a96f56d5d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 10 Oct 2022 09:51:06 +0200 Subject: [PATCH 3/6] build: Move schemasdir to toplevel build file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- data/meson.build | 2 -- meson.build | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/data/meson.build b/data/meson.build index 264fb1727..858d569aa 100644 --- a/data/meson.build +++ b/data/meson.build @@ -92,8 +92,6 @@ configure_file( install: true ) -schemasdir = 'share/glib-2.0/schemas' - #generate XML enum definitions for GSettings schema schema_enum_headers = files( '../src/app-grid.h', diff --git a/meson.build b/meson.build index a66bb0c10..5c7515578 100644 --- a/meson.build +++ b/meson.build @@ -20,6 +20,7 @@ systemddir = join_paths(prefix, 'lib/systemd') systemduserdir = join_paths(systemddir, 'user') plugins_dir = join_paths(prefix, libdir, 'phosh', 'plugins') servicedir = join_paths(datadir, 'dbus-1', 'services') +schemasdir = datadir / 'glib-2.0/schemas' glib_ver = 'GLIB_VERSION_2_66' -- GitLab From 22eeec0927ecec1f8e4696a80fe93c2324a1dd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Thu, 8 Sep 2022 17:57:41 +0200 Subject: [PATCH 4/6] ci: Add evince-dev to alpine deps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c788e7fc0..f18f4857a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,7 +34,7 @@ variables: ALPINE_EDGE_DEPS: alpine-sdk callaudiod-dev elogind-dev feedbackd-dev gcr-dev git glib-dev gnome-desktop-dev gtk+3.0-dev libgudev-dev libhandy1-dev gcr-dev libsecret-dev gcovr linux-pam-dev meson musl-dev networkmanager networkmanager-dev ninja polkit-elogind-dev pulseaudio-dev - upower-dev wayland-dev wayland-protocols ttf-dejavu evolution-data-server-dev + upower-dev wayland-dev wayland-protocols ttf-dejavu evolution-data-server-dev evince-dev .bookworm_vars: &bookworm_vars variables: -- GitLab From 0e0740198f5588785a94c26e63b98f151725f8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Fri, 8 Jul 2022 08:02:23 +0200 Subject: [PATCH 5/6] plugins: Add ticket box MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Displays the PDFs from a fixed folder Signed-off-by: Guido Günther Part-of: --- debian/control | 1 + plugins/meson.build | 1 + plugins/ticket-box/meson.build | 53 ++++ plugins/ticket-box/phosh-plugin-ticket-box.c | 38 +++ .../phosh-plugin-ticket-box.gresources.xml | 7 + plugins/ticket-box/stylesheet/common.css | 9 + plugins/ticket-box/ticket-box.c | 239 ++++++++++++++++++ plugins/ticket-box/ticket-box.desktop.in.in | 5 + plugins/ticket-box/ticket-box.h | 19 ++ plugins/ticket-box/ticket-box.ui | 104 ++++++++ plugins/ticket-box/ticket-row.c | 116 +++++++++ plugins/ticket-box/ticket-row.h | 22 ++ plugins/ticket-box/ticket-row.ui | 34 +++ plugins/ticket-box/ticket.c | 155 ++++++++++++ plugins/ticket-box/ticket.h | 23 ++ po/POTFILES.in | 2 + tools/widget-box-standalone.c | 2 +- 17 files changed, 829 insertions(+), 1 deletion(-) create mode 100644 plugins/ticket-box/meson.build create mode 100644 plugins/ticket-box/phosh-plugin-ticket-box.c create mode 100644 plugins/ticket-box/phosh-plugin-ticket-box.gresources.xml create mode 100644 plugins/ticket-box/stylesheet/common.css create mode 100644 plugins/ticket-box/ticket-box.c create mode 100644 plugins/ticket-box/ticket-box.desktop.in.in create mode 100644 plugins/ticket-box/ticket-box.h create mode 100644 plugins/ticket-box/ticket-box.ui create mode 100644 plugins/ticket-box/ticket-row.c create mode 100644 plugins/ticket-box/ticket-row.h create mode 100644 plugins/ticket-box/ticket-row.ui create mode 100644 plugins/ticket-box/ticket.c create mode 100644 plugins/ticket-box/ticket.h diff --git a/debian/control b/debian/control index e67e1a290..c0f894ee8 100644 --- a/debian/control +++ b/debian/control @@ -6,6 +6,7 @@ Build-Depends: debhelper-compat (= 13), gtk-doc-tools , libcallaudio-dev, + libevince-dev, libsecret-1-dev, libsystemd-dev, libfeedback-dev, diff --git a/plugins/meson.build b/plugins/meson.build index 67ea60b37..031a0b649 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -1,2 +1,3 @@ subdir('calendar') subdir('upcoming-events') +subdir('ticket-box') diff --git a/plugins/ticket-box/meson.build b/plugins/ticket-box/meson.build new file mode 100644 index 000000000..8854c9cc7 --- /dev/null +++ b/plugins/ticket-box/meson.build @@ -0,0 +1,53 @@ +name='ticket-box' + +ticket_box_plugin_deps = [ + dependency('gobject-2.0'), + dependency('gtk+-3.0'), + dependency('libhandy-1'), + dependency('evince-document-3.0'), + dependency('evince-view-3.0'), +] + +ticket_box_resources = gnome.compile_resources( + 'phosh-plugin-ticket-box-resources', + 'phosh-plugin-ticket-box.gresources.xml', + c_name: 'phosh_plugin_ticket_box', +) + +ticket_box_plugin_sources = files( + 'phosh-plugin-ticket-box.c', + 'ticket.c', + 'ticket.h', + 'ticket-box.c', + 'ticket-box.h', + 'ticket-row.c', + 'ticket-row.h', +) + +phosh_ticket_box_plugin = shared_module( + 'phosh-plugin-ticket-box', + ticket_box_plugin_sources, + ticket_box_resources, + c_args : ['-DG_LOG_DOMAIN="phosh-plugin-ticket-box"'], + dependencies: ticket_box_plugin_deps, + include_directories: [root_inc, phosh_gtk_list_models_inc], + install: true, + install_dir: plugins_dir, +) + +pluginconf = configuration_data() +pluginconf.set('name', name) +pluginconf.set('plugins_dir', plugins_dir) + +i18n.merge_file( + input: configure_file( + input: name + '.desktop.in.in', + output: name + '.desktop.in', + configuration: pluginconf, + ), + output: name + '.plugin', + po_dir: join_paths(meson.source_root(), 'po'), + install: true, + install_dir: plugins_dir, + type: 'desktop' +) diff --git a/plugins/ticket-box/phosh-plugin-ticket-box.c b/plugins/ticket-box/phosh-plugin-ticket-box.c new file mode 100644 index 000000000..ed2dc2fff --- /dev/null +++ b/plugins/ticket-box/phosh-plugin-ticket-box.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + +#include "ticket-box.h" + +#define PHOSH_EXTENSION_POINT_LOCKSCREEN_WIDGET "phosh-lockscreen-widget" + +char **g_io_phosh_plugin_ticket_box_query (void); + +void +g_io_module_load (GIOModule *module) +{ + g_type_module_use (G_TYPE_MODULE (module)); + + g_io_extension_point_implement (PHOSH_EXTENSION_POINT_LOCKSCREEN_WIDGET, + PHOSH_TYPE_TICKET_BOX, + "ticket-box", + 10); +} + +void +g_io_module_unload (GIOModule *module) +{ +} + + +char ** +g_io_phosh_plugin_ticket_box_query (void) +{ + char *extension_points[] = {PHOSH_EXTENSION_POINT_LOCKSCREEN_WIDGET, NULL}; + + return g_strdupv (extension_points); +} diff --git a/plugins/ticket-box/phosh-plugin-ticket-box.gresources.xml b/plugins/ticket-box/phosh-plugin-ticket-box.gresources.xml new file mode 100644 index 000000000..7351859ed --- /dev/null +++ b/plugins/ticket-box/phosh-plugin-ticket-box.gresources.xml @@ -0,0 +1,7 @@ + + + + ticket-box.ui + stylesheet/common.css + + diff --git a/plugins/ticket-box/stylesheet/common.css b/plugins/ticket-box/stylesheet/common.css new file mode 100644 index 000000000..d564b64cd --- /dev/null +++ b/plugins/ticket-box/stylesheet/common.css @@ -0,0 +1,9 @@ +phosh-ticket-box { + background-color: @phosh_notification_bg_color; + border-radius: 12px; + padding: 8px; +} + +phosh-ticket-row { + margin-top: 6px; +} diff --git a/plugins/ticket-box/ticket-box.c b/plugins/ticket-box/ticket-box.c new file mode 100644 index 000000000..77c504d25 --- /dev/null +++ b/plugins/ticket-box/ticket-box.c @@ -0,0 +1,239 @@ +/* + * Copyright (C) 2022 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + +#include "ticket.h" +#include "ticket-box.h" +#include "ticket-row.h" + +#include +#include + +#define TICKET_BOX_PATH "phosh-ticket-box" + +/** + * PhoshTicketBox + * + * Show tickets in a folder. For now we do PDF but + * should add PNG and pass. + */ +struct _PhoshTicketBox { + GtkBox parent; + + GFileMonitor *monitor; + GFile *dir; + char *ticket_box_path; + GCancellable *cancel; + + GListStore *model; + GtkListBox *lb_tickets; + GtkStack *stack_tickets; + + EvView *view; +}; + +G_DEFINE_TYPE (PhoshTicketBox, phosh_ticket_box, GTK_TYPE_BOX); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (EvDocument, g_object_unref) + +static void +on_row_selected (PhoshTicketBox *self, + GtkListBoxRow *row, + GtkListBox *box) +{ + g_autoptr (GError) err = NULL; + g_autoptr (PhoshTicket) ticket = NULL; + g_autoptr (EvDocument) doc = NULL; + g_autoptr (EvDocumentModel) model = NULL; + + if (row == NULL) + return; + + g_object_get (row, "ticket", &ticket, NULL); + g_debug ("row selected: %s", phosh_ticket_get_display_name (ticket)); + + doc = ev_document_factory_get_document_for_gfile (phosh_ticket_get_file (ticket), + EV_DOCUMENT_LOAD_FLAG_NONE, + self->cancel, + &err); + if (doc == NULL) { + g_warning ("Failed to load %s: %s", phosh_ticket_get_display_name (ticket), err->message); + return; + } + model = ev_document_model_new_with_document (doc); + ev_view_set_model (self->view, model); + + gtk_stack_set_visible_child_name (self->stack_tickets, "ticket-view"); + + gtk_list_box_select_row (box, NULL); +} + + +static void +on_view_close_clicked (PhoshTicketBox *self) +{ + gtk_stack_set_visible_child_name (self->stack_tickets, "tickets"); +} + + +static void +phosh_ticket_box_finalize (GObject *object) +{ + PhoshTicketBox *self = PHOSH_TICKET_BOX (object); + + g_cancellable_cancel (self->cancel); + g_clear_object (&self->cancel); + g_clear_object (&self->model); + + g_clear_object (&self->monitor); + g_clear_object (&self->dir); + g_clear_pointer (&self->ticket_box_path, g_free); + + G_OBJECT_CLASS (phosh_ticket_box_parent_class)->finalize (object); +} + + +static void +phosh_ticket_box_class_init (PhoshTicketBoxClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->finalize = phosh_ticket_box_finalize; + + g_type_ensure (EV_TYPE_VIEW); + g_type_ensure (PHOSH_TYPE_TICKET_ROW); + + gtk_widget_class_set_template_from_resource (widget_class, + "/sm/puri/phosh/plugins/ticket-box/ticket-box.ui"); + gtk_widget_class_bind_template_child (widget_class, PhoshTicketBox, lb_tickets); + gtk_widget_class_bind_template_child (widget_class, PhoshTicketBox, stack_tickets); + gtk_widget_class_bind_template_child (widget_class, PhoshTicketBox, view); + gtk_widget_class_bind_template_callback (widget_class, on_view_close_clicked); + + gtk_widget_class_set_css_name (widget_class, "phosh-ticket-box"); +} + + +static GtkWidget * +create_ticket_row (gpointer item, gpointer user_data) +{ + PhoshTicket *ticket = PHOSH_TICKET (item); + GtkWidget *row = phosh_ticket_row_new (ticket); + + return row; +} + + +static gint +ticket_compare (gconstpointer a, gconstpointer b, gpointer user_data) +{ + g_autoptr (GDateTime) dt_a = phosh_ticket_get_mod_time (PHOSH_TICKET ((gpointer)a)); + g_autoptr (GDateTime) dt_b = phosh_ticket_get_mod_time (PHOSH_TICKET ((gpointer)b)); + + return -1 * g_date_time_compare (dt_a, dt_b); +} + + +static void +on_file_child_enumerated (GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + g_autoptr (GError) err = NULL; + GFile *dir = G_FILE (source_object); + GFileEnumerator *enumerator; + PhoshTicketBox *self; + const char *stack_child = "tickets"; + + enumerator = g_file_enumerate_children_finish (dir, res, &err); + if (enumerator == NULL) { + g_warning ("Failed to list %s", g_file_get_basename (dir)); + } + + self = PHOSH_TICKET_BOX (user_data); + + while (TRUE) { + GFile *file; + GFileInfo *info; + g_autoptr (PhoshTicket) ticket = NULL; + + if (!g_file_enumerator_iterate (enumerator, &info, &file, self->cancel, &err)) { + g_warning ("Failed to list contents of ticket dir %s: $%s", self->ticket_box_path, err->message); + return; + } + + if (!file) + break; + + if (g_strcmp0 (g_file_info_get_content_type (info), "application/pdf") != 0) + continue; + + ticket = phosh_ticket_new (file, info); + g_list_store_insert_sorted (self->model, ticket, ticket_compare, NULL); + } + + if (g_list_model_get_n_items (G_LIST_MODEL (self->model)) == 0) + stack_child = "no-tickets"; + + gtk_stack_set_visible_child_name (self->stack_tickets, stack_child); +} + + +static void +load_tickets (PhoshTicketBox *self) +{ + self->ticket_box_path = g_build_filename (g_get_home_dir (), TICKET_BOX_PATH, NULL); + self->dir = g_file_new_for_path (self->ticket_box_path); + + /* + * Since the lockscreen is rebuilt on lock we don't worry about changes in directory contesnt, + * should we do, we can add a GFileMonitor later on + */ + g_file_enumerate_children_async (self->dir, + G_FILE_ATTRIBUTE_STANDARD_NAME "," + G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON "," + G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," + G_FILE_ATTRIBUTE_TIME_MODIFIED "," + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + G_FILE_QUERY_INFO_NONE, + G_PRIORITY_LOW, + self->cancel, + on_file_child_enumerated, + self); +} + + +static void +phosh_ticket_box_init (PhoshTicketBox *self) +{ + g_autoptr (GtkCssProvider) css_provider = NULL; + + ev_init (); + + gtk_widget_init_template (GTK_WIDGET (self)); + + self->model = g_list_store_new (PHOSH_TYPE_TICKET); + + css_provider = gtk_css_provider_new (); + gtk_css_provider_load_from_resource (css_provider, + "/sm/puri/phosh/plugins/ticket-box/stylesheet/common.css"); + gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (self)), + GTK_STYLE_PROVIDER (css_provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + + gtk_list_box_bind_model (self->lb_tickets, + G_LIST_MODEL (self->model), + create_ticket_row, + NULL, + NULL); + + g_signal_connect_swapped (self->lb_tickets, + "row-selected", + G_CALLBACK (on_row_selected), + self); + + load_tickets (self); +} diff --git a/plugins/ticket-box/ticket-box.desktop.in.in b/plugins/ticket-box/ticket-box.desktop.in.in new file mode 100644 index 000000000..7a1a3d477 --- /dev/null +++ b/plugins/ticket-box/ticket-box.desktop.in.in @@ -0,0 +1,5 @@ +[Plugin] +Id=@name@ +Name=Ticket Box +Comment=Show PDFs on the lock screen. This plugin is experimental. This plugin is experimental. +Plugin=@plugins_dir@/libphosh-plugin-@name@.so diff --git a/plugins/ticket-box/ticket-box.h b/plugins/ticket-box/ticket-box.h new file mode 100644 index 000000000..55a69f86b --- /dev/null +++ b/plugins/ticket-box/ticket-box.h @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2022 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + + +#include + +#pragma once + +G_BEGIN_DECLS + +#define PHOSH_TYPE_TICKET_BOX (phosh_ticket_box_get_type ()) +G_DECLARE_FINAL_TYPE (PhoshTicketBox, phosh_ticket_box, PHOSH, TICKET_BOX, GtkBox) + +G_END_DECLS diff --git a/plugins/ticket-box/ticket-box.ui b/plugins/ticket-box/ticket-box.ui new file mode 100644 index 000000000..a3840e672 --- /dev/null +++ b/plugins/ticket-box/ticket-box.ui @@ -0,0 +1,104 @@ + + + + + diff --git a/plugins/ticket-box/ticket-row.c b/plugins/ticket-box/ticket-row.c new file mode 100644 index 000000000..8701f70e0 --- /dev/null +++ b/plugins/ticket-box/ticket-row.c @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2022 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + +#include "phosh-config.h" + +#include "ticket-row.h" + +#include +#include + +enum { + PROP_0, + PROP_TICKET, + PROP_LAST_PROP, +}; +static GParamSpec *props[PROP_LAST_PROP]; + + +struct _PhoshTicketRow { + HdyActionRow parent; + + PhoshTicket *ticket; +}; +G_DEFINE_TYPE (PhoshTicketRow, phosh_ticket_row, HDY_TYPE_ACTION_ROW) + + +static void +phosh_ticket_row_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + PhoshTicketRow *self = PHOSH_TICKET_ROW (object); + + switch (property_id) { + case PROP_TICKET: + self->ticket = g_value_dup_object (value); + hdy_preferences_row_set_title (HDY_PREFERENCES_ROW (self), + phosh_ticket_get_display_name (self->ticket)); +/* TODO: by document type */ + hdy_action_row_set_icon_name (HDY_ACTION_ROW (self), "x-office-document-symbolic"); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phosh_ticket_row_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + PhoshTicketRow *self = PHOSH_TICKET_ROW (object); + + switch (property_id) { + case PROP_TICKET: + g_value_set_object (value, self->ticket); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phosh_ticket_row_finalize (GObject *object) +{ + PhoshTicketRow *self = PHOSH_TICKET_ROW (object); + + g_clear_object (&self->ticket); + + G_OBJECT_CLASS (phosh_ticket_row_parent_class)->finalize (object); +} + + +static void +phosh_ticket_row_class_init (PhoshTicketRowClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->get_property = phosh_ticket_row_get_property; + object_class->set_property = phosh_ticket_row_set_property; + object_class->finalize = phosh_ticket_row_finalize; + + props[PROP_TICKET] = + g_param_spec_object ("ticket", "", "", + PHOSH_TYPE_TICKET, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + + g_object_class_install_properties (object_class, PROP_LAST_PROP, props); + + gtk_widget_class_set_css_name (widget_class, "phosh-ticket-row"); +} + + +static void +phosh_ticket_row_init (PhoshTicketRow *self) +{ +} + + +GtkWidget * +phosh_ticket_row_new (PhoshTicket *ticket) +{ + return GTK_WIDGET (g_object_new (PHOSH_TYPE_TICKET_ROW, "ticket", ticket, NULL)); +} diff --git a/plugins/ticket-box/ticket-row.h b/plugins/ticket-box/ticket-row.h new file mode 100644 index 000000000..200998878 --- /dev/null +++ b/plugins/ticket-box/ticket-row.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2022 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "ticket.h" + +#include +#include + +G_BEGIN_DECLS + +#define PHOSH_TYPE_TICKET_ROW (phosh_ticket_row_get_type ()) + +G_DECLARE_FINAL_TYPE (PhoshTicketRow, phosh_ticket_row, PHOSH, TICKET_ROW, HdyActionRow) + +GtkWidget *phosh_ticket_row_new (PhoshTicket *ticket); + +G_END_DECLS diff --git a/plugins/ticket-box/ticket-row.ui b/plugins/ticket-box/ticket-row.ui new file mode 100644 index 000000000..34aa1d97b --- /dev/null +++ b/plugins/ticket-box/ticket-row.ui @@ -0,0 +1,34 @@ + + + + + diff --git a/plugins/ticket-box/ticket.c b/plugins/ticket-box/ticket.c new file mode 100644 index 000000000..c700d1221 --- /dev/null +++ b/plugins/ticket-box/ticket.c @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2022 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + +#include "ticket.h" + +enum { + PROP_0, + PROP_FILE, + PROP_INFO, + PROP_LAST_PROP +}; +static GParamSpec *props[PROP_LAST_PROP]; + +struct _PhoshTicket { + GObject parent; + + GFile *file; + GFileInfo *info; +}; +G_DEFINE_TYPE (PhoshTicket, phosh_ticket, G_TYPE_OBJECT) + + +static void +phosh_ticket_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + PhoshTicket *self = PHOSH_TICKET (object); + + switch (property_id) { + case PROP_FILE: + self->file = g_value_dup_object (value); + break; + case PROP_INFO: + self->info = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phosh_ticket_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + PhoshTicket *self = PHOSH_TICKET (object); + + switch (property_id) { + case PROP_FILE: + g_value_set_object (value, self->file); + break; + case PROP_INFO: + g_value_set_object (value, self->info); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phosh_ticket_finalize (GObject *object) +{ + PhoshTicket *self = PHOSH_TICKET (object); + + g_clear_object (&self->file); + g_clear_object (&self->info); + + G_OBJECT_CLASS (phosh_ticket_parent_class)->finalize (object); +} + + +static void +phosh_ticket_class_init (PhoshTicketClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = phosh_ticket_get_property; + object_class->set_property = phosh_ticket_set_property; + object_class->finalize = phosh_ticket_finalize; + + props[PROP_FILE] = + g_param_spec_object ("file", "", "", + G_TYPE_FILE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + + props[PROP_INFO] = + g_param_spec_object ("info", "", "", + G_TYPE_FILE_INFO, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + + g_object_class_install_properties (object_class, PROP_LAST_PROP, props); +} + + +static void +phosh_ticket_init (PhoshTicket *self) +{ +} + + +PhoshTicket * +phosh_ticket_new (GFile *file, GFileInfo *info) +{ + return PHOSH_TICKET (g_object_new (PHOSH_TYPE_TICKET, + "file", file, + "info", info, + NULL)); +} + + +GFile * +phosh_ticket_get_file (PhoshTicket *self) +{ + g_return_val_if_fail (PHOSH_IS_TICKET (self), NULL); + + return self->file; +} + + +GIcon * +phosh_ticket_get_icon (PhoshTicket *self) +{ + g_return_val_if_fail (PHOSH_IS_TICKET (self), NULL); + + return g_file_info_get_symbolic_icon (self->info); +} + + +const char * +phosh_ticket_get_display_name (PhoshTicket *self) +{ + g_return_val_if_fail (PHOSH_IS_TICKET (self), NULL); + + return g_file_info_get_display_name (self->info); +} + +GDateTime * +phosh_ticket_get_mod_time (PhoshTicket *self) +{ + g_return_val_if_fail (PHOSH_IS_TICKET (self), NULL); + + return g_file_info_get_modification_date_time (self->info); +} diff --git a/plugins/ticket-box/ticket.h b/plugins/ticket-box/ticket.h new file mode 100644 index 000000000..3b20dd743 --- /dev/null +++ b/plugins/ticket-box/ticket.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define PHOSH_TYPE_TICKET (phosh_ticket_get_type ()) + +G_DECLARE_FINAL_TYPE (PhoshTicket, phosh_ticket, PHOSH, TICKET, GObject) + +PhoshTicket *phosh_ticket_new (GFile *file, GFileInfo *info); +GFile *phosh_ticket_get_file (PhoshTicket *self); +const char *phosh_ticket_get_display_name (PhoshTicket *self); +GIcon *phosh_ticket_get_icon (PhoshTicket *self); +GDateTime *phosh_ticket_get_mod_time (PhoshTicket *self); + +G_END_DECLS diff --git a/po/POTFILES.in b/po/POTFILES.in index 8e991f80c..c7d930f17 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,6 +1,7 @@ data/phosh.session.desktop.in.in data/sm.puri.Phosh.desktop.in.in plugins/calendar/calendar.desktop.in.in +plugins/ticket-box/ticket-box.desktop.in.in plugins/upcoming-events/upcoming-events.desktop.in.in src/activity.c src/app-grid-button.c @@ -78,6 +79,7 @@ src/widget-box.c src/wifiinfo.c src/wifimanager.c src/wwan-info.c +plugins/ticket-box/ticket-box.ui plugins/upcoming-events/event-list.c plugins/upcoming-events/event-list.ui plugins/upcoming-events/upcoming-event.c diff --git a/tools/widget-box-standalone.c b/tools/widget-box-standalone.c index b72c3d899..e6b2794c5 100644 --- a/tools/widget-box-standalone.c +++ b/tools/widget-box-standalone.c @@ -53,7 +53,7 @@ main (int argc, char *argv[]) { GtkWidget *win; GtkWidget *box; - char *plugins[] = { "calendar", "upcoming-events", "doesnotexist", NULL }; + char *plugins[] = { "calendar", "upcoming-events", "ticket-box", "doesnotexist", NULL }; GStrv plugin_dirs = NULL; gtk_init (&argc, &argv); -- GitLab From 3af7effe02ab8f1c9b93a23a45ee48fee4bd4a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 10 Oct 2022 09:48:58 +0200 Subject: [PATCH 6/6] plugins/ticket-box: Make folder configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also adds an example how plugins can add configuration data Signed-off-by: Guido Günther Part-of: --- debian/phosh-plugins.install | 1 + plugins/ticket-box/meson.build | 20 +++++++++++++++++++ ....puri.phosh.plugins.ticket-box.gschema.xml | 13 ++++++++++++ plugins/ticket-box/ticket-box.c | 13 ++++++++++-- run.in | 4 ++-- tools/run_tool.in | 4 +++- 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 plugins/ticket-box/sm.puri.phosh.plugins.ticket-box.gschema.xml diff --git a/debian/phosh-plugins.install b/debian/phosh-plugins.install index af2400deb..cab818674 100644 --- a/debian/phosh-plugins.install +++ b/debian/phosh-plugins.install @@ -1,2 +1,3 @@ +usr/share/glib-2.0/schemas/sm.puri.phosh.plugins.*.gschema.xml usr/lib/*/phosh/plugins/libphosh-plugin-*.so usr/lib/*/phosh/plugins/*.plugin diff --git a/plugins/ticket-box/meson.build b/plugins/ticket-box/meson.build index 8854c9cc7..a6fff9b2e 100644 --- a/plugins/ticket-box/meson.build +++ b/plugins/ticket-box/meson.build @@ -51,3 +51,23 @@ i18n.merge_file( install_dir: plugins_dir, type: 'desktop' ) + +ticket_box_schema = 'sm.puri.phosh.plugins.ticket-box.gschema.xml' +copy_schema = custom_target('copy-ticket-box-gschema-to-builddir', + input: ticket_box_schema, + output: ticket_box_schema, + command: ['cp', '@INPUT@', '@OUTPUT@'] +) +compile_schemas = custom_target('glib-compile-schemas', + build_by_default: true, + output: 'gschemas.compiled', + install: false, + command: [find_program('glib-compile-schemas'), + meson.current_build_dir() + ], + depends: copy_schema +) +install_data( + ticket_box_schema, + install_dir: 'share/glib-2.0/schemas' +) diff --git a/plugins/ticket-box/sm.puri.phosh.plugins.ticket-box.gschema.xml b/plugins/ticket-box/sm.puri.phosh.plugins.ticket-box.gschema.xml new file mode 100644 index 000000000..d17f2663f --- /dev/null +++ b/plugins/ticket-box/sm.puri.phosh.plugins.ticket-box.gschema.xml @@ -0,0 +1,13 @@ + + + + 'phosh-ticket-box' + Folder containing tickets + + The folder that contains the tickets that should be available + on the lock screen. + + + + diff --git a/plugins/ticket-box/ticket-box.c b/plugins/ticket-box/ticket-box.c index 77c504d25..f2fdbccc3 100644 --- a/plugins/ticket-box/ticket-box.c +++ b/plugins/ticket-box/ticket-box.c @@ -13,7 +13,8 @@ #include #include -#define TICKET_BOX_PATH "phosh-ticket-box" +#define TICKET_BOX_SCHEMA_ID "sm.puri.phosh.plugins.ticket-box" +#define TICKET_BOX_FOLDER_KEY "folder" /** * PhoshTicketBox @@ -185,7 +186,15 @@ on_file_child_enumerated (GObject *source_object, GAsyncResult *res, gpointer us static void load_tickets (PhoshTicketBox *self) { - self->ticket_box_path = g_build_filename (g_get_home_dir (), TICKET_BOX_PATH, NULL); + g_autoptr (GSettings) settings = g_settings_new (TICKET_BOX_SCHEMA_ID); + g_autofree char *folder = NULL; + + folder = g_settings_get_string (settings, TICKET_BOX_FOLDER_KEY); + if (folder[0] != '/') + self->ticket_box_path = g_build_filename (g_get_home_dir (), folder, NULL); + else + self->ticket_box_path = g_steal_pointer (&folder); + self->dir = g_file_new_for_path (self->ticket_box_path); /* diff --git a/run.in b/run.in index b245226df..fd98ac3d4 100755 --- a/run.in +++ b/run.in @@ -23,8 +23,8 @@ elif [ "${PHOSH_AUTO_GDB}" = 1 ]; then WRAPPER="gdb -batch -ex run -ex bt --args" fi - -export GSETTINGS_SCHEMA_DIR="${ABS_BUILDDIR}/data:${GSETTINGS_SCHEMA_DIR}" +GSETTINGS_SCHEMA_DIR="${ABS_BUILDDIR}/data:${ABS_BUILDDIR}/plugins/ticket-box:${GSETTINGS_SCHEMA_DIR}" +export GSETTINGS_SCHEMA_DIR [ -n "${G_MESSAGES_DEBUG}" ] || G_MESSAGES_DEBUG=all export G_MESSAGES_DEBUG diff --git a/tools/run_tool.in b/tools/run_tool.in index 600f0220f..48af764fa 100755 --- a/tools/run_tool.in +++ b/tools/run_tool.in @@ -3,7 +3,9 @@ set -e ABS_BUILDDIR='@ABS_BUILDDIR@' -export GSETTINGS_SCHEMA_DIR="${ABS_BUILDDIR}/data" +GSETTINGS_SCHEMA_DIR="${ABS_BUILDDIR}/data:${ABS_BUILDDIR}/plugins/ticket-box:${GSETTINGS_SCHEMA_DIR}" +export GSETTINGS_SCHEMA_DIR + export G_MESSAGES_DEBUG=all export GNOTIFICATION_BACKEND=freedesktop set -x -- GitLab