Coverage Report

Created: 2025-06-13 06:55

/src/glib/gio/gportalnotificationbackend.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
* Copyright © 2016 Red Hat, Inc.
3
*
4
* SPDX-License-Identifier: LGPL-2.1-or-later
5
*
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.
10
*
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.
15
*
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/>.
18
*
19
* Author: Matthias Clasen
20
*/
21
22
#include "config.h"
23
#include "gnotificationbackend.h"
24
25
#include "giomodule-priv.h"
26
#include "gdbusconnection.h"
27
#include "gapplication.h"
28
#include "gnotification-private.h"
29
#include "gportalsupport.h"
30
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))
33
34
typedef struct _GPortalNotificationBackend GPortalNotificationBackend;
35
typedef GNotificationBackendClass       GPortalNotificationBackendClass;
36
37
struct _GPortalNotificationBackend
38
{
39
  GNotificationBackend parent;
40
};
41
42
GType g_portal_notification_backend_get_type (void);
43
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))
48
49
static gboolean
50
g_portal_notification_backend_is_supported (void)
51
0
{
52
0
  return glib_should_use_portal ();
53
0
}
54
55
static void
56
g_portal_notification_backend_send_notification (GNotificationBackend *backend,
57
                                                 const gchar          *id,
58
                                                 GNotification        *notification)
59
0
{
60
0
  g_dbus_connection_call (backend->dbus_connection,
61
0
                          "org.freedesktop.portal.Desktop",
62
0
                          "/org/freedesktop/portal/desktop",
63
0
                          "org.freedesktop.portal.Notification",
64
0
                          "AddNotification",
65
0
                          g_variant_new ("(s@a{sv})",
66
0
                                         id,
67
0
                                         g_notification_serialize (notification)),
68
0
                          G_VARIANT_TYPE_UNIT,
69
0
                          G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
70
0
}
71
72
static void
73
g_portal_notification_backend_withdraw_notification (GNotificationBackend *backend,
74
                                                     const gchar          *id)
75
0
{
76
0
  g_dbus_connection_call (backend->dbus_connection,
77
0
                          "org.freedesktop.portal.Desktop",
78
0
                          "/org/freedesktop/portal/desktop",
79
0
                          "org.freedesktop.portal.Notification",
80
0
                          "RemoveNotification",
81
0
                          g_variant_new ("(s)", id),
82
0
                          G_VARIANT_TYPE_UNIT,
83
0
                          G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
84
0
}
85
86
static void
87
g_portal_notification_backend_init (GPortalNotificationBackend *backend)
88
0
{
89
0
}
90
91
static void
92
g_portal_notification_backend_class_init (GPortalNotificationBackendClass *class)
93
0
{
94
0
  GNotificationBackendClass *backend_class = G_NOTIFICATION_BACKEND_CLASS (class);
95
96
0
  backend_class->is_supported = g_portal_notification_backend_is_supported;
97
0
  backend_class->send_notification = g_portal_notification_backend_send_notification;
98
0
  backend_class->withdraw_notification = g_portal_notification_backend_withdraw_notification;
99
0
}