From 13ddf1eb832b63ecb10cea907c19de75caa67d6b Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 3 Mar 2020 15:58:13 +0100 Subject: [PATCH] calendar-server: Add 'Dismiss' button and application action - adds 'Dismiss' button to the notification - introduces org.gnome.Shell.CalendarServer.desktop.in.in to benefit from GNotification API Related to https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1064 --- data/meson.build | 2 + ...g.gnome.Shell.CalendarServer.desktop.in.in | 9 +++ .../gnome-shell-calendar-server.c | 27 ++++++-- src/calendar-server/reminder-watcher.c | 61 +++++++++++++++++++ src/calendar-server/reminder-watcher.h | 2 + 5 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 data/org.gnome.Shell.CalendarServer.desktop.in.in diff --git a/data/meson.build b/data/meson.build index 87b52ce54..58815576f 100644 --- a/data/meson.build +++ b/data/meson.build @@ -1,5 +1,6 @@ desktop_files = [ 'org.gnome.Shell.desktop', + 'org.gnome.Shell.CalendarServer.desktop', 'org.gnome.Extensions.desktop', ] service_files = [] @@ -13,6 +14,7 @@ desktopconf = configuration_data() # We substitute in bindir so it works as an autostart # file when built in a non-system prefix desktopconf.set('bindir', bindir) +desktopconf.set('libexecdir', libexecdir) desktopconf.set('systemd_hidden', have_systemd ? 'true' : 'false') foreach desktop_file : desktop_files diff --git a/data/org.gnome.Shell.CalendarServer.desktop.in.in b/data/org.gnome.Shell.CalendarServer.desktop.in.in new file mode 100644 index 000000000..ff48374ef --- /dev/null +++ b/data/org.gnome.Shell.CalendarServer.desktop.in.in @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Name=Clock Applet +Icon=appointment-soon +Exec=@libexecdir@/gnome-shell-calendar-server +Terminal=false +Categories= +OnlyShowIn=GNOME +NoDisplay=true diff --git a/src/calendar-server/gnome-shell-calendar-server.c b/src/calendar-server/gnome-shell-calendar-server.c index 27c74ddec..d2f36d96c 100644 --- a/src/calendar-server/gnome-shell-calendar-server.c +++ b/src/calendar-server/gnome-shell-calendar-server.c @@ -71,11 +71,6 @@ static GDBusNodeInfo *introspection_data = NULL; struct _App; typedef struct _App App; -static gboolean opt_replace = FALSE; -static GOptionEntry opt_entries[] = { - {"replace", 0, 0, G_OPTION_ARG_NONE, &opt_replace, "Replace existing daemon", NULL}, - {NULL } -}; static App *_global_app = NULL; /* ---------------------------------------------------------------------------------------------------- */ @@ -1104,10 +1099,30 @@ stdin_channel_io_func (GIOChannel *source, return FALSE; /* remove source */ } +static void +app_dismiss_reminder_cb (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + App *app = _global_app; + + g_return_if_fail (app != NULL); + + reminder_watcher_dismiss_by_id (app->reminder_watcher, g_variant_get_string (parameter, NULL)); +} + int main (int argc, char **argv) { + gboolean opt_replace = FALSE; + GOptionEntry opt_entries[] = { + {"replace", 0, 0, G_OPTION_ARG_NONE, &opt_replace, "Replace existing daemon", NULL}, + {NULL } + }; + const GActionEntry action_entries[] = { + { "dismiss-reminder", app_dismiss_reminder_cb, "s" } + }; GApplication *application; GError *error; GOptionContext *opt_context; @@ -1137,6 +1152,8 @@ main (int argc, application = g_application_new (BUS_NAME, G_APPLICATION_NON_UNIQUE); + g_action_map_add_action_entries (G_ACTION_MAP (application), action_entries, G_N_ELEMENTS (action_entries), NULL); + g_signal_connect (application, "activate", G_CALLBACK (g_application_hold), NULL); diff --git a/src/calendar-server/reminder-watcher.c b/src/calendar-server/reminder-watcher.c index 9e2061720..f004af56c 100644 --- a/src/calendar-server/reminder-watcher.c +++ b/src/calendar-server/reminder-watcher.c @@ -234,6 +234,9 @@ reminder_watcher_notify_display (ReminderWatcher *rw, } #endif + g_notification_add_button_with_target (notification, _("Dismiss"), "app.dismiss-reminder", "s", notif_id); + g_notification_set_default_action_and_target (notification, "app.dismiss-reminder", "s", notif_id); + g_application_send_notification (rw->priv->application, notif_id, notification); g_object_unref (notification); @@ -704,3 +707,61 @@ reminder_watcher_new (GApplication *application, return E_REMINDER_WATCHER (rw); } + +static void +reminder_watcher_dismiss_done_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + + if (!e_reminder_watcher_dismiss_finish (E_REMINDER_WATCHER (source_object), result, &error)) + { + if (!g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_NOT_SUPPORTED)) + print_debug ("Dismiss: Failed with error: %s", error ? error->message : "Unknown error"); + + g_clear_error (&error); + } +} + +void +reminder_watcher_dismiss_by_id (EReminderWatcher *reminder_watcher, + const gchar *id) +{ + ReminderWatcher *rw; + GSList *past, *link; + + g_return_if_fail (IS_REMINDER_WATCHER (reminder_watcher)); + g_return_if_fail (id && *id); + + rw = REMINDER_WATCHER (reminder_watcher); + past = e_reminder_watcher_dup_past (reminder_watcher); + + for (link = past; link; link = g_slist_next (link)) + { + EReminderData *rd = link->data; + gchar *rd_id; + + rd_id = reminder_watcher_build_notif_id (rd); + + if (g_strcmp0 (rd_id, id) == 0) + { + print_debug ("Dismiss: Going to dismiss '%s'", reminder_watcher_get_rd_summary (rd)); + + g_application_withdraw_notification (rw->priv->application, id); + + e_reminder_watcher_dismiss (reminder_watcher, rd, NULL, + reminder_watcher_dismiss_done_cb, NULL); + + g_free (rd_id); + break; + } + + g_free (rd_id); + } + + if (!link) + print_debug ("Dismiss: Cannot find reminder '%s'", id); + + g_slist_free_full (past, e_reminder_data_free); +} diff --git a/src/calendar-server/reminder-watcher.h b/src/calendar-server/reminder-watcher.h index f98fadf77..dae2cac65 100644 --- a/src/calendar-server/reminder-watcher.h +++ b/src/calendar-server/reminder-watcher.h @@ -59,6 +59,8 @@ struct _ReminderWatcherClass { GType reminder_watcher_get_type (void) G_GNUC_CONST; EReminderWatcher *reminder_watcher_new (GApplication *application, ESourceRegistry *registry); +void reminder_watcher_dismiss_by_id(EReminderWatcher *reminder_watcher, + const gchar *id); G_END_DECLS