Merge branch 'wip/muktupavels/notifications' into 'master'

gfdonotificationbackend: remove notifications when bus name vanishes

See merge request GNOME/glib!1317
This commit is contained in:
Philip Withnall 2020-01-16 06:52:16 +00:00
commit 321fea1c5e

View File

@ -25,6 +25,7 @@
#include "giomodule-priv.h"
#include "gnotification-private.h"
#include "gdbusconnection.h"
#include "gdbusnamewatching.h"
#include "gactiongroup.h"
#include "gaction.h"
#include "gthemedicon.h"
@ -42,6 +43,8 @@ struct _GFdoNotificationBackend
{
GNotificationBackend parent;
guint bus_name_id;
guint notify_subscription;
GSList *notifications;
};
@ -205,6 +208,20 @@ notify_signal (GDBusConnection *connection,
}
}
static void
name_vanished_handler_cb (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
GFdoNotificationBackend *backend = user_data;
if (backend->notifications)
{
g_slist_free_full (backend->notifications, freedesktop_notification_free);
backend->notifications = NULL;
}
}
/* Converts a GNotificationPriority to an urgency level as defined by
* the freedesktop spec (0: low, 1: normal, 2: critical).
*/
@ -370,6 +387,12 @@ g_fdo_notification_backend_dispose (GObject *object)
{
GFdoNotificationBackend *backend = G_FDO_NOTIFICATION_BACKEND (object);
if (backend->bus_name_id)
{
g_bus_unwatch_name (backend->bus_name_id);
backend->bus_name_id = 0;
}
if (backend->notify_subscription)
{
GDBusConnection *session_bus;
@ -407,6 +430,17 @@ g_fdo_notification_backend_send_notification (GNotificationBackend *backend,
GFdoNotificationBackend *self = G_FDO_NOTIFICATION_BACKEND (backend);
FreedesktopNotification *n, *tmp;
if (self->bus_name_id == 0)
{
self->bus_name_id = g_bus_watch_name_on_connection (backend->dbus_connection,
"org.freedesktop.Notifications",
G_BUS_NAME_WATCHER_FLAGS_NONE,
NULL,
name_vanished_handler_cb,
backend,
NULL);
}
if (self->notify_subscription == 0)
{
self->notify_subscription =