1 /*
2 * Copyright © 2013 Lars Uebernickel
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 * Authors: Lars Uebernickel <lars@uebernic.de>
18 */
19
20 #include "gnotificationbackend.h"
21
22 #include "gnotification.h"
23 #include "gapplication.h"
24 #include "gactiongroup.h"
25 #include "giomodule-priv.h"
26
G_DEFINE_TYPE(GNotificationBackend,g_notification_backend,G_TYPE_OBJECT)27 G_DEFINE_TYPE (GNotificationBackend, g_notification_backend, G_TYPE_OBJECT)
28
29 static void
30 g_notification_backend_class_init (GNotificationBackendClass *class)
31 {
32 }
33
34 static void
g_notification_backend_init(GNotificationBackend * backend)35 g_notification_backend_init (GNotificationBackend *backend)
36 {
37 }
38
39 GNotificationBackend *
g_notification_backend_new_default(GApplication * application)40 g_notification_backend_new_default (GApplication *application)
41 {
42 GType backend_type;
43 GNotificationBackend *backend;
44
45 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
46
47 backend_type = _g_io_module_get_default_type (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME,
48 "GNOTIFICATION_BACKEND",
49 G_STRUCT_OFFSET (GNotificationBackendClass, is_supported));
50
51 backend = g_object_new (backend_type, NULL);
52
53 /* Avoid ref cycle by not taking a ref to the application at all. The
54 * backend only lives as long as the application does.
55 */
56 backend->application = application;
57
58 backend->dbus_connection = g_application_get_dbus_connection (application);
59 if (backend->dbus_connection)
60 g_object_ref (backend->dbus_connection);
61
62 return backend;
63 }
64
65 void
g_notification_backend_send_notification(GNotificationBackend * backend,const gchar * id,GNotification * notification)66 g_notification_backend_send_notification (GNotificationBackend *backend,
67 const gchar *id,
68 GNotification *notification)
69 {
70 g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend));
71 g_return_if_fail (G_IS_NOTIFICATION (notification));
72
73 G_NOTIFICATION_BACKEND_GET_CLASS (backend)->send_notification (backend, id, notification);
74 }
75
76 void
g_notification_backend_withdraw_notification(GNotificationBackend * backend,const gchar * id)77 g_notification_backend_withdraw_notification (GNotificationBackend *backend,
78 const gchar *id)
79 {
80 g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend));
81 g_return_if_fail (id != NULL);
82
83 G_NOTIFICATION_BACKEND_GET_CLASS (backend)->withdraw_notification (backend, id);
84 }
85