/src/glib/gio/gportalnotificationbackend.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2016 Red Hat, Inc. |
3 | | * |
4 | | * This library is free software; you can redistribute it and/or |
5 | | * modify it under the terms of the GNU Lesser General Public |
6 | | * License as published by the Free Software Foundation; either |
7 | | * version 2.1 of the License, or (at your option) any later version. |
8 | | * |
9 | | * This library is distributed in the hope that it will be useful, |
10 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | | * Lesser General Public License for more details. |
13 | | * |
14 | | * You should have received a copy of the GNU Lesser General |
15 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
16 | | * |
17 | | * Author: Matthias Clasen |
18 | | */ |
19 | | |
20 | | #include "config.h" |
21 | | #include "gnotificationbackend.h" |
22 | | |
23 | | #include "giomodule-priv.h" |
24 | | #include "gdbusconnection.h" |
25 | | #include "gapplication.h" |
26 | | #include "gnotification-private.h" |
27 | | #include "gportalsupport.h" |
28 | | |
29 | | #define G_TYPE_PORTAL_NOTIFICATION_BACKEND (g_portal_notification_backend_get_type ()) |
30 | | #define G_PORTAL_NOTIFICATION_BACKEND(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_PORTAL_NOTIFICATION_BACKEND, GPortalNotificationBackend)) |
31 | | |
32 | | typedef struct _GPortalNotificationBackend GPortalNotificationBackend; |
33 | | typedef GNotificationBackendClass GPortalNotificationBackendClass; |
34 | | |
35 | | struct _GPortalNotificationBackend |
36 | | { |
37 | | GNotificationBackend parent; |
38 | | }; |
39 | | |
40 | | GType g_portal_notification_backend_get_type (void); |
41 | | |
42 | | G_DEFINE_TYPE_WITH_CODE (GPortalNotificationBackend, g_portal_notification_backend, G_TYPE_NOTIFICATION_BACKEND, |
43 | | _g_io_modules_ensure_extension_points_registered (); |
44 | | g_io_extension_point_implement (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME, |
45 | | g_define_type_id, "portal", 110)) |
46 | | |
47 | | static gboolean |
48 | | g_portal_notification_backend_is_supported (void) |
49 | 0 | { |
50 | 0 | return glib_should_use_portal (); |
51 | 0 | } |
52 | | |
53 | | static void |
54 | | g_portal_notification_backend_send_notification (GNotificationBackend *backend, |
55 | | const gchar *id, |
56 | | GNotification *notification) |
57 | 0 | { |
58 | 0 | g_dbus_connection_call (backend->dbus_connection, |
59 | 0 | "org.freedesktop.portal.Desktop", |
60 | 0 | "/org/freedesktop/portal/desktop", |
61 | 0 | "org.freedesktop.portal.Notification", |
62 | 0 | "AddNotification", |
63 | 0 | g_variant_new ("(s@a{sv})", |
64 | 0 | id, |
65 | 0 | g_notification_serialize (notification)), |
66 | 0 | G_VARIANT_TYPE_UNIT, |
67 | 0 | G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); |
68 | 0 | } |
69 | | |
70 | | static void |
71 | | g_portal_notification_backend_withdraw_notification (GNotificationBackend *backend, |
72 | | const gchar *id) |
73 | 0 | { |
74 | 0 | g_dbus_connection_call (backend->dbus_connection, |
75 | 0 | "org.freedesktop.portal.Desktop", |
76 | 0 | "/org/freedesktop/portal/desktop", |
77 | 0 | "org.freedesktop.portal.Notification", |
78 | 0 | "RemoveNotification", |
79 | 0 | g_variant_new ("(s)", id), |
80 | 0 | G_VARIANT_TYPE_UNIT, |
81 | 0 | G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); |
82 | 0 | } |
83 | | |
84 | | static void |
85 | | g_portal_notification_backend_init (GPortalNotificationBackend *backend) |
86 | 0 | { |
87 | 0 | } |
88 | | |
89 | | static void |
90 | | g_portal_notification_backend_class_init (GPortalNotificationBackendClass *class) |
91 | 0 | { |
92 | 0 | GNotificationBackendClass *backend_class = G_NOTIFICATION_BACKEND_CLASS (class); |
93 | |
|
94 | 0 | backend_class->is_supported = g_portal_notification_backend_is_supported; |
95 | 0 | backend_class->send_notification = g_portal_notification_backend_send_notification; |
96 | 0 | backend_class->withdraw_notification = g_portal_notification_backend_withdraw_notification; |
97 | 0 | } |