diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c788e7fc0e0ceef952abc7c95aa3932cefb263a2..f18f4857a3d2df20a4744b5cf9c7a3bf595af356 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: diff --git a/data/meson.build b/data/meson.build index 264fb1727467e2253e6ed7a3d074052ae45699b8..858d569aae577395c763c80c94735150ad766ae5 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/debian/control b/debian/control index e67e1a2906e432b2925a284caebc32275094e48c..c0f894ee88aacf2a63a40aa4365209a374428d63 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/debian/phosh-doc.install b/debian/phosh-doc.install index 7f0cf467d3c80f6999483deb146dd21679e2432a..c5d24aff8cd3648d803fabde1abb2e520b34f532 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 6c77abb2ae7295e729fdc64dc8b7013477b5a6f5..ff59397890caabe0db623e3d7404ab4c9b2ce890 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 ee809e605f1460216aca9eb31010829699962ff0..cab818674d7684d4bafe9374ca005ac222e6f9dc 100644 --- a/debian/phosh-plugins.install +++ b/debian/phosh-plugins.install @@ -1,2 +1,3 @@ -/usr/lib/*/phosh/plugins/libphosh-plugin-*.so -/usr/lib/*/phosh/plugins/*.plugin +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/debian/phosh.install b/debian/phosh.install index f9408551a7dce848800c3370f814ef241dcd2d5e..7a6ac29306a48d653a538c7859cfb7856bc75008 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 diff --git a/meson.build b/meson.build index a66bb0c10b3a85159ac3c2d21da6e51456c70b27..5c7515578dcf9713da63e1010059a924a5e41ec0 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' diff --git a/plugins/meson.build b/plugins/meson.build index 67ea60b3736271d6909d63a5269ff70a5c770063..031a0b649fe5d966050a4d72c519ba2a586bd250 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 0000000000000000000000000000000000000000..a6fff9b2ea40aba44813e8e21cf1744484edc4f8 --- /dev/null +++ b/plugins/ticket-box/meson.build @@ -0,0 +1,73 @@ +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' +) + +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/phosh-plugin-ticket-box.c b/plugins/ticket-box/phosh-plugin-ticket-box.c new file mode 100644 index 0000000000000000000000000000000000000000..ed2dc2fffe195c56ae815a0b3b199093b78136eb --- /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 0000000000000000000000000000000000000000..7351859ed9ce0cbaf6ffa77bd12c25baafe43613 --- /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/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 0000000000000000000000000000000000000000..d17f2663f0bfcaf306ecd72b08ec16478540ccba --- /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/stylesheet/common.css b/plugins/ticket-box/stylesheet/common.css new file mode 100644 index 0000000000000000000000000000000000000000..d564b64cd1ba966ed62fb8647329bb4b146452c2 --- /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 0000000000000000000000000000000000000000..f2fdbccc3f4b779ac9170cf472fc7b6f6c7d6641 --- /dev/null +++ b/plugins/ticket-box/ticket-box.c @@ -0,0 +1,248 @@ +/* + * 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_SCHEMA_ID "sm.puri.phosh.plugins.ticket-box" +#define TICKET_BOX_FOLDER_KEY "folder" + +/** + * 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) +{ + 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); + + /* + * 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 0000000000000000000000000000000000000000..7a1a3d477fb96701930f5794f2adc4e4a5eecd9d --- /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 0000000000000000000000000000000000000000..55a69f86b165ed643b2ab2e8ff7341e05e7d5508 --- /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 0000000000000000000000000000000000000000..a3840e6725d5edbfa4fcd6e0c2a87b9877c85edd --- /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 0000000000000000000000000000000000000000..8701f70e05f572cd496bc0e41128b8c9c0801832 --- /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 0000000000000000000000000000000000000000..200998878631ed51afab25b1c82cc2e415b5d1b5 --- /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 0000000000000000000000000000000000000000..34aa1d97bf4ec3a79aac4974801daf8cb0247ae3 --- /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 0000000000000000000000000000000000000000..c700d1221475de09662495eabeff9fa081656352 --- /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 0000000000000000000000000000000000000000..3b20dd743bbb5732a3f257390c515a35bafdd751 --- /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 8e991f80ca5c17052abf57499de8149e037b733c..c7d930f1777baddf75f69d68651f77cb189b32b2 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/run.in b/run.in index b245226df0e43bedf45c2c40f60695b428bf658e..fd98ac3d493e07213313db39e065b93b603886e0 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 600f0220fdd4f1221c7554d8d610b9b5078740f8..48af764faf55eaf3c8b9395947ff8686906254e7 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 diff --git a/tools/widget-box-standalone.c b/tools/widget-box-standalone.c index b72c3d89905657c0f2b2f91bfc2fae59d213301e..e6b2794c5b7e97139bbcdd4bb17dd454cdf6949c 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);