/src/glib/gio/gnotificationbackend.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2013 Lars Uebernickel |
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 | | * Authors: Lars Uebernickel <lars@uebernic.de> |
20 | | */ |
21 | | |
22 | | #include "gnotificationbackend.h" |
23 | | |
24 | | #include "gnotification.h" |
25 | | #include "gapplication.h" |
26 | | #include "gactiongroup.h" |
27 | | #include "giomodule-priv.h" |
28 | | |
29 | | G_DEFINE_TYPE (GNotificationBackend, g_notification_backend, G_TYPE_OBJECT) |
30 | | |
31 | | static void |
32 | | g_notification_backend_dispose (GObject *obj) |
33 | 0 | { |
34 | 0 | GNotificationBackend *backend = G_NOTIFICATION_BACKEND (obj); |
35 | |
|
36 | 0 | backend->application = NULL; /* no reference held, but clear the pointer anyway to avoid it dangling */ |
37 | 0 | g_clear_object (&backend->dbus_connection); |
38 | |
|
39 | 0 | G_OBJECT_CLASS (g_notification_backend_parent_class)->dispose (obj); |
40 | 0 | } |
41 | | |
42 | | static void |
43 | | g_notification_backend_class_init (GNotificationBackendClass *class) |
44 | 0 | { |
45 | 0 | GObjectClass *object_class = G_OBJECT_CLASS (class); |
46 | |
|
47 | 0 | object_class->dispose = g_notification_backend_dispose; |
48 | 0 | } |
49 | | |
50 | | static void |
51 | | g_notification_backend_init (GNotificationBackend *backend) |
52 | 0 | { |
53 | 0 | } |
54 | | |
55 | | GNotificationBackend * |
56 | | g_notification_backend_new_default (GApplication *application) |
57 | 0 | { |
58 | 0 | GType backend_type; |
59 | 0 | GNotificationBackend *backend; |
60 | |
|
61 | 0 | g_return_val_if_fail (G_IS_APPLICATION (application), NULL); |
62 | | |
63 | 0 | backend_type = _g_io_module_get_default_type (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME, |
64 | 0 | "GNOTIFICATION_BACKEND", |
65 | 0 | G_STRUCT_OFFSET (GNotificationBackendClass, is_supported)); |
66 | |
|
67 | 0 | backend = g_object_new (backend_type, NULL); |
68 | | |
69 | | /* Avoid ref cycle by not taking a ref to the application at all. The |
70 | | * backend only lives as long as the application does. |
71 | | */ |
72 | 0 | backend->application = application; |
73 | |
|
74 | 0 | backend->dbus_connection = g_application_get_dbus_connection (application); |
75 | 0 | if (backend->dbus_connection) |
76 | 0 | g_object_ref (backend->dbus_connection); |
77 | |
|
78 | 0 | return backend; |
79 | 0 | } |
80 | | |
81 | | void |
82 | | g_notification_backend_send_notification (GNotificationBackend *backend, |
83 | | const gchar *id, |
84 | | GNotification *notification) |
85 | 0 | { |
86 | 0 | g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend)); |
87 | 0 | g_return_if_fail (G_IS_NOTIFICATION (notification)); |
88 | | |
89 | 0 | G_NOTIFICATION_BACKEND_GET_CLASS (backend)->send_notification (backend, id, notification); |
90 | 0 | } |
91 | | |
92 | | void |
93 | | g_notification_backend_withdraw_notification (GNotificationBackend *backend, |
94 | | const gchar *id) |
95 | 0 | { |
96 | 0 | g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend)); |
97 | 0 | g_return_if_fail (id != NULL); |
98 | | |
99 | 0 | G_NOTIFICATION_BACKEND_GET_CLASS (backend)->withdraw_notification (backend, id); |
100 | 0 | } |