2 * Copyright © 2016 Red Hat, Inc.
4 * SPDX-License-Identifier: LGPL-2.1-or-later
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 * Author: Matthias Clasen
23 #include "gnotificationbackend.h"
25 #include "giomodule-priv.h"
26 #include "gdbusconnection.h"
27 #include "gapplication.h"
28 #include "gnotification-private.h"
29 #include "gportalsupport.h"
31 #define G_TYPE_PORTAL_NOTIFICATION_BACKEND (g_portal_notification_backend_get_type ())
32 #define G_PORTAL_NOTIFICATION_BACKEND(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_PORTAL_NOTIFICATION_BACKEND, GPortalNotificationBackend))
34 typedef struct _GPortalNotificationBackend GPortalNotificationBackend;
35 typedef GNotificationBackendClass GPortalNotificationBackendClass;
37 struct _GPortalNotificationBackend
39 GNotificationBackend parent;
42 GType g_portal_notification_backend_get_type (void);
44 G_DEFINE_TYPE_WITH_CODE (GPortalNotificationBackend, g_portal_notification_backend, G_TYPE_NOTIFICATION_BACKEND,
45 _g_io_modules_ensure_extension_points_registered ();
46 g_io_extension_point_implement (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME,
47 g_define_type_id, "portal", 110))
50 g_portal_notification_backend_is_supported (void)
52 return glib_should_use_portal ();
56 g_portal_notification_backend_send_notification (GNotificationBackend *backend,
58 GNotification *notification)
60 g_dbus_connection_call (backend->dbus_connection,
61 "org.freedesktop.portal.Desktop",
62 "/org/freedesktop/portal/desktop",
63 "org.freedesktop.portal.Notification",
65 g_variant_new ("(s@a{sv})",
67 g_notification_serialize (notification)),
69 G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
73 g_portal_notification_backend_withdraw_notification (GNotificationBackend *backend,
76 g_dbus_connection_call (backend->dbus_connection,
77 "org.freedesktop.portal.Desktop",
78 "/org/freedesktop/portal/desktop",
79 "org.freedesktop.portal.Notification",
81 g_variant_new ("(s)", id),
83 G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
87 g_portal_notification_backend_init (GPortalNotificationBackend *backend)
92 g_portal_notification_backend_class_init (GPortalNotificationBackendClass *class)
94 GNotificationBackendClass *backend_class = G_NOTIFICATION_BACKEND_CLASS (class);
96 backend_class->is_supported = g_portal_notification_backend_is_supported;
97 backend_class->send_notification = g_portal_notification_backend_send_notification;
98 backend_class->withdraw_notification = g_portal_notification_backend_withdraw_notification;