1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* GIO - GLib Input, Output and Streaming Library
3 *
4 * Copyright © 2018 Endless Mobile, Inc.
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
18 * <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * - Philip Withnall <withnall@endlessm.com>
22 */
23
24 #include "config.h"
25
26 #include "gnotificationbackend.h"
27
28 #include "giomodule-priv.h"
29 #include "gnotification-private.h"
30
31 #define G_TYPE_WIN32_NOTIFICATION_BACKEND (g_win32_notification_backend_get_type ())
32 #define G_WIN32_NOTIFICATION_BACKEND(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_WIN32_NOTIFICATION_BACKEND, GWin32NotificationBackend))
33
34 typedef struct _GWin32NotificationBackend GWin32NotificationBackend;
35 typedef GNotificationBackendClass GWin32NotificationBackendClass;
36
37 struct _GWin32NotificationBackend
38 {
39 GNotificationBackend parent;
40 };
41
42 GType g_win32_notification_backend_get_type (void);
43
44 G_DEFINE_TYPE_WITH_CODE (GWin32NotificationBackend, g_win32_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, "win32", 0))
48
49 static gboolean
g_win32_notification_backend_is_supported(void)50 g_win32_notification_backend_is_supported (void)
51 {
52 /* This is the only backend supported on Windows, and always needs to be
53 * present to avoid no backend being selected. */
54 return TRUE;
55 }
56
57 static void
g_win32_notification_backend_send_notification(GNotificationBackend * backend,const gchar * id,GNotification * notification)58 g_win32_notification_backend_send_notification (GNotificationBackend *backend,
59 const gchar *id,
60 GNotification *notification)
61 {
62 static gsize warned = 0;
63
64 /* FIXME: See https://bugzilla.gnome.org/show_bug.cgi?id=776583. This backend
65 * exists purely to stop crashes when applications use g_notification*()
66 * on Windows, by providing a dummy backend implementation. (The alternative
67 * was to modify all of the backend call sites in g_notification*(), which
68 * seemed less scalable.) */
69 if (g_once_init_enter (&warned))
70 {
71 g_warning ("Notifications are not yet supported on Windows.");
72 g_once_init_leave (&warned, 1);
73 }
74 }
75
76 static void
g_win32_notification_backend_withdraw_notification(GNotificationBackend * backend,const gchar * id)77 g_win32_notification_backend_withdraw_notification (GNotificationBackend *backend,
78 const gchar *id)
79 {
80 /* FIXME: Nothing needs doing here until send_notification() is implemented. */
81 }
82
83 static void
g_win32_notification_backend_init(GWin32NotificationBackend * backend)84 g_win32_notification_backend_init (GWin32NotificationBackend *backend)
85 {
86 }
87
88 static void
g_win32_notification_backend_class_init(GWin32NotificationBackendClass * class)89 g_win32_notification_backend_class_init (GWin32NotificationBackendClass *class)
90 {
91 GNotificationBackendClass *backend_class = G_NOTIFICATION_BACKEND_CLASS (class);
92
93 backend_class->is_supported = g_win32_notification_backend_is_supported;
94 backend_class->send_notification = g_win32_notification_backend_send_notification;
95 backend_class->withdraw_notification = g_win32_notification_backend_withdraw_notification;
96 }
97