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
This commit is contained in:
Milan Crha 2020-03-03 15:58:13 +01:00
parent 15ab33a11a
commit 13ddf1eb83
5 changed files with 96 additions and 5 deletions

View File

@ -1,5 +1,6 @@
desktop_files = [ desktop_files = [
'org.gnome.Shell.desktop', 'org.gnome.Shell.desktop',
'org.gnome.Shell.CalendarServer.desktop',
'org.gnome.Extensions.desktop', 'org.gnome.Extensions.desktop',
] ]
service_files = [] service_files = []
@ -13,6 +14,7 @@ desktopconf = configuration_data()
# We substitute in bindir so it works as an autostart # We substitute in bindir so it works as an autostart
# file when built in a non-system prefix # file when built in a non-system prefix
desktopconf.set('bindir', bindir) desktopconf.set('bindir', bindir)
desktopconf.set('libexecdir', libexecdir)
desktopconf.set('systemd_hidden', have_systemd ? 'true' : 'false') desktopconf.set('systemd_hidden', have_systemd ? 'true' : 'false')
foreach desktop_file : desktop_files foreach desktop_file : desktop_files

View File

@ -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

View File

@ -71,11 +71,6 @@ static GDBusNodeInfo *introspection_data = NULL;
struct _App; struct _App;
typedef struct _App 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; static App *_global_app = NULL;
/* ---------------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------------- */
@ -1104,10 +1099,30 @@ stdin_channel_io_func (GIOChannel *source,
return FALSE; /* remove 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 int
main (int argc, main (int argc,
char **argv) 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; GApplication *application;
GError *error; GError *error;
GOptionContext *opt_context; GOptionContext *opt_context;
@ -1137,6 +1152,8 @@ main (int argc,
application = g_application_new (BUS_NAME, G_APPLICATION_NON_UNIQUE); 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_signal_connect (application, "activate",
G_CALLBACK (g_application_hold), NULL); G_CALLBACK (g_application_hold), NULL);

View File

@ -234,6 +234,9 @@ reminder_watcher_notify_display (ReminderWatcher *rw,
} }
#endif #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_application_send_notification (rw->priv->application, notif_id, notification);
g_object_unref (notification); g_object_unref (notification);
@ -704,3 +707,61 @@ reminder_watcher_new (GApplication *application,
return E_REMINDER_WATCHER (rw); 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);
}

View File

@ -59,6 +59,8 @@ struct _ReminderWatcherClass {
GType reminder_watcher_get_type (void) G_GNUC_CONST; GType reminder_watcher_get_type (void) G_GNUC_CONST;
EReminderWatcher *reminder_watcher_new (GApplication *application, EReminderWatcher *reminder_watcher_new (GApplication *application,
ESourceRegistry *registry); ESourceRegistry *registry);
void reminder_watcher_dismiss_by_id(EReminderWatcher *reminder_watcher,
const gchar *id);
G_END_DECLS G_END_DECLS