[glib/portal] Add a portal backend for GNotification
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/portal] Add a portal backend for GNotification
- Date: Fri, 1 Jul 2016 05:59:55 +0000 (UTC)
commit 9ca0e6e3f993893260f45ba75bd340383f9a40ab
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jul 1 01:12:30 2016 -0400
Add a portal backend for GNotification
This will talk to a portal api instead of directly to the shell.
gio/Makefile.am | 1 +
gio/giomodule.c | 2 +
gio/gportalnotificationbackend.c | 98 ++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/gio/Makefile.am b/gio/Makefile.am
index ad5ab45..534f249 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -263,6 +263,7 @@ unix_sources = \
gcontenttypeprivate.h \
gfdonotificationbackend.c \
ggtknotificationbackend.c \
+ gportalnotificationbackend.c \
$(NULL)
if OS_COCOA
diff --git a/gio/giomodule.c b/gio/giomodule.c
index b181e84..0c32af4 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -915,6 +915,7 @@ extern GType _g_network_monitor_nm_get_type (void);
#ifdef G_OS_UNIX
extern GType g_fdo_notification_backend_get_type (void);
extern GType g_gtk_notification_backend_get_type (void);
+extern GType g_portal_notification_backend_get_type (void);
#endif
#ifdef HAVE_COCOA
@@ -1116,6 +1117,7 @@ _g_io_modules_ensure_loaded (void)
g_type_ensure (_g_unix_volume_monitor_get_type ());
g_type_ensure (g_fdo_notification_backend_get_type ());
g_type_ensure (g_gtk_notification_backend_get_type ());
+ g_type_ensure (g_portal_notification_backend_get_type ());
#endif
#ifdef HAVE_COCOA
g_type_ensure (g_cocoa_notification_backend_get_type ());
diff --git a/gio/gportalnotificationbackend.c b/gio/gportalnotificationbackend.c
new file mode 100644
index 0000000..750c9b0
--- /dev/null
+++ b/gio/gportalnotificationbackend.c
@@ -0,0 +1,98 @@
+/*
+* Copyright © 2016 Red Hat, Inc.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General
+* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Matthias Clasen
+*/
+
+#include "config.h"
+#include "gnotificationbackend.h"
+
+#include "giomodule-priv.h"
+#include "gdbusconnection.h"
+#include "gapplication.h"
+#include "gnotification-private.h"
+#include "gportalsupport.h"
+
+#define G_TYPE_PORTAL_NOTIFICATION_BACKEND (g_portal_notification_backend_get_type ())
+#define G_PORTAL_NOTIFICATION_BACKEND(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
G_TYPE_PORTAL_NOTIFICATION_BACKEND, GPortalNotificationBackend))
+
+typedef struct _GPortalNotificationBackend GPortalNotificationBackend;
+typedef GNotificationBackendClass GPortalNotificationBackendClass;
+
+struct _GPortalNotificationBackend
+{
+ GNotificationBackend parent;
+};
+
+GType g_portal_notification_backend_get_type (void);
+
+G_DEFINE_TYPE_WITH_CODE (GPortalNotificationBackend, g_portal_notification_backend,
G_TYPE_NOTIFICATION_BACKEND,
+ _g_io_modules_ensure_extension_points_registered ();
+ g_io_extension_point_implement (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME,
+ g_define_type_id, "portal", 110))
+
+static gboolean
+g_portal_notification_backend_is_supported (void)
+{
+ return glib_should_use_portal ();
+}
+
+static void
+g_portal_notification_backend_send_notification (GNotificationBackend *backend,
+ const gchar *id,
+ GNotification *notification)
+{
+g_print ("use portal backend\n");
+ g_dbus_connection_call (backend->dbus_connection,
+ "org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ "org.freedesktop.portal.Notification",
+ "AddNotification",
+ g_variant_new ("(s a{sv})",
+ id,
+ g_notification_serialize (notification)),
+ G_VARIANT_TYPE_UNIT,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
+}
+
+static void
+g_portal_notification_backend_withdraw_notification (GNotificationBackend *backend,
+ const gchar *id)
+{
+ g_dbus_connection_call (backend->dbus_connection,
+ "org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ "org.freedesktop.portal.Notification",
+ "RemoveNotification",
+ g_variant_new ("(s)", id),
+ G_VARIANT_TYPE_UNIT,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
+}
+
+static void
+g_portal_notification_backend_init (GPortalNotificationBackend *backend)
+{
+}
+
+static void
+g_portal_notification_backend_class_init (GPortalNotificationBackendClass *class)
+{
+ GNotificationBackendClass *backend_class = G_NOTIFICATION_BACKEND_CLASS (class);
+
+ backend_class->is_supported = g_portal_notification_backend_is_supported;
+ backend_class->send_notification = g_portal_notification_backend_send_notification;
+ backend_class->withdraw_notification = g_portal_notification_backend_withdraw_notification;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]