/src/glib/gio/gnotificationbackend.c
Line | Count | Source |
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 | 0 | G_DEFINE_TYPE (GNotificationBackend, g_notification_backend, G_TYPE_OBJECT) |
30 | 0 |
|
31 | 0 | typedef enum |
32 | 0 | { |
33 | 0 | PROP_APPLICATION = 1, |
34 | 0 | } GNotificationBackendProperty; |
35 | 0 |
|
36 | 0 | static GParamSpec *props[PROP_APPLICATION + 1]; |
37 | 0 |
|
38 | 0 | /** |
39 | 0 | * g_notification_backend_dup_application: |
40 | 0 | * |
41 | 0 | * Returns: (transfer full) (nullable): |
42 | 0 | * The application object this notification backend handles notifications for. |
43 | 0 | */ |
44 | 0 | GApplication * |
45 | 0 | g_notification_backend_dup_application (GNotificationBackend *self) |
46 | 0 | { |
47 | 0 | g_return_val_if_fail (G_IS_NOTIFICATION_BACKEND (self), NULL); |
48 | | |
49 | 0 | return (GApplication *) g_weak_ref_get (&self->application); |
50 | 0 | } |
51 | | |
52 | | static void |
53 | | g_notification_backend_get_property (GObject *obj, |
54 | | guint prop_id, |
55 | | GValue *value, |
56 | | GParamSpec *pspec) |
57 | 0 | { |
58 | 0 | GNotificationBackend *self = G_NOTIFICATION_BACKEND (obj); |
59 | |
|
60 | 0 | switch ((GNotificationBackendProperty) prop_id) |
61 | 0 | { |
62 | 0 | case PROP_APPLICATION: |
63 | 0 | { |
64 | 0 | g_value_take_object (value, g_notification_backend_dup_application (self)); |
65 | 0 | break; |
66 | 0 | } |
67 | 0 | default: |
68 | 0 | G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | | static void |
73 | | g_notification_backend_set_property (GObject *obj, |
74 | | guint prop_id, |
75 | | const GValue *value, |
76 | | GParamSpec *pspec) |
77 | 0 | { |
78 | 0 | GNotificationBackend *self = G_NOTIFICATION_BACKEND (obj); |
79 | |
|
80 | 0 | switch ((GNotificationBackendProperty) prop_id) |
81 | 0 | { |
82 | 0 | case PROP_APPLICATION: |
83 | 0 | { |
84 | 0 | g_weak_ref_init (&self->application, g_value_get_object (value)); |
85 | 0 | break; |
86 | 0 | } |
87 | 0 | default: |
88 | 0 | G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | static void |
93 | | g_notification_backend_dispose (GObject *obj) |
94 | 0 | { |
95 | 0 | GNotificationBackend *backend = G_NOTIFICATION_BACKEND (obj); |
96 | |
|
97 | 0 | g_weak_ref_clear (&backend->application); |
98 | 0 | g_clear_object (&backend->dbus_connection); |
99 | |
|
100 | 0 | G_OBJECT_CLASS (g_notification_backend_parent_class)->dispose (obj); |
101 | 0 | } |
102 | | |
103 | | static void |
104 | | g_notification_backend_class_init (GNotificationBackendClass *class) |
105 | 0 | { |
106 | 0 | GObjectClass *object_class = G_OBJECT_CLASS (class); |
107 | |
|
108 | 0 | object_class->dispose = g_notification_backend_dispose; |
109 | 0 | object_class->get_property = g_notification_backend_get_property; |
110 | 0 | object_class->set_property = g_notification_backend_set_property; |
111 | | |
112 | | /** |
113 | | * GNotificationBackend:application: |
114 | | * |
115 | | * The application object this notification backend handles |
116 | | * notifications for. |
117 | | * |
118 | | * Since: 2.90 |
119 | | */ |
120 | 0 | props[PROP_APPLICATION] = |
121 | 0 | g_param_spec_object ("application", NULL, NULL, |
122 | 0 | G_TYPE_APPLICATION, |
123 | 0 | G_PARAM_STATIC_STRINGS | |
124 | 0 | G_PARAM_READWRITE | |
125 | 0 | G_PARAM_CONSTRUCT_ONLY); |
126 | |
|
127 | 0 | g_object_class_install_properties (object_class, G_N_ELEMENTS (props), props); |
128 | 0 | } |
129 | | |
130 | | static void |
131 | | g_notification_backend_init (GNotificationBackend *backend) |
132 | 0 | { |
133 | 0 | } |
134 | | |
135 | | GNotificationBackend * |
136 | | g_notification_backend_new_default (GApplication *application) |
137 | 0 | { |
138 | 0 | GType backend_type; |
139 | 0 | GNotificationBackend *backend; |
140 | |
|
141 | 0 | g_return_val_if_fail (G_IS_APPLICATION (application), NULL); |
142 | | |
143 | 0 | backend_type = _g_io_module_get_default_type (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME, |
144 | 0 | "GNOTIFICATION_BACKEND", |
145 | 0 | G_STRUCT_OFFSET (GNotificationBackendClass, is_supported)); |
146 | |
|
147 | 0 | backend = g_object_new (backend_type, "application", application, NULL); |
148 | |
|
149 | 0 | backend->dbus_connection = g_application_get_dbus_connection (application); |
150 | 0 | if (backend->dbus_connection) |
151 | 0 | g_object_ref (backend->dbus_connection); |
152 | |
|
153 | 0 | return backend; |
154 | 0 | } |
155 | | |
156 | | void |
157 | | g_notification_backend_send_notification (GNotificationBackend *backend, |
158 | | const gchar *id, |
159 | | GNotification *notification) |
160 | 0 | { |
161 | 0 | g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend)); |
162 | 0 | g_return_if_fail (G_IS_NOTIFICATION (notification)); |
163 | | |
164 | 0 | G_NOTIFICATION_BACKEND_GET_CLASS (backend)->send_notification (backend, id, notification); |
165 | 0 | } |
166 | | |
167 | | void |
168 | | g_notification_backend_withdraw_notification (GNotificationBackend *backend, |
169 | | const gchar *id) |
170 | 0 | { |
171 | 0 | g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend)); |
172 | 0 | g_return_if_fail (id != NULL); |
173 | | |
174 | 0 | G_NOTIFICATION_BACKEND_GET_CLASS (backend)->withdraw_notification (backend, id); |
175 | 0 | } |