[glib] gio: Add dummy win32 notification backend
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gio: Add dummy win32 notification backend
- Date: Tue, 10 Apr 2018 09:40:50 +0000 (UTC)
commit b868cf5864e64cb2f6ea417053ea7bc4b83bc4a6
Author: Philip Withnall <withnall endlessm com>
Date: Wed Mar 21 15:48:52 2018 +0000
gio: Add dummy win32 notification backend
This adds a null notification backend implementation for win32, purely
to avoid crashes due to a missing backend when applications use
GNotification. This backend does nothing except print a warning when a
notification is supposed to be emitted.
In future, it can be expanded to use win32 API to present toaster
notifications appropriately.
Signed-off-by: Philip Withnall <withnall endlessm com>
https://bugzilla.gnome.org/show_bug.cgi?id=776583
gio/Makefile.am | 1 +
gio/giomodule.c | 2 +
gio/gwin32notificationbackend.c | 90 +++++++++++++++++++++++++++++++++++++++++
gio/meson.build | 1 +
4 files changed, 94 insertions(+)
---
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 67b7fa966..d7fcb9161 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -334,6 +334,7 @@ win32_actual_sources = \
gwin32networking.h \
gwin32networkmonitor.c \
gwin32networkmonitor.h \
+ gwin32notificationbackend.c \
$(NULL)
win32_more_sources_for_vcproj = \
diff --git a/gio/giomodule.c b/gio/giomodule.c
index 72a12ea45..30731f7c2 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -962,6 +962,7 @@ extern GType g_cocoa_notification_backend_get_type (void);
#endif
#ifdef G_PLATFORM_WIN32
+extern GType g_win32_notification_backend_get_type (void);
#include <windows.h>
extern GType _g_win32_network_monitor_get_type (void);
@@ -1166,6 +1167,7 @@ _g_io_modules_ensure_loaded (void)
g_type_ensure (g_cocoa_notification_backend_get_type ());
#endif
#ifdef G_OS_WIN32
+ g_type_ensure (g_win32_notification_backend_get_type ());
g_type_ensure (_g_winhttp_vfs_get_type ());
#endif
g_type_ensure (_g_local_vfs_get_type ());
diff --git a/gio/gwin32notificationbackend.c b/gio/gwin32notificationbackend.c
new file mode 100644
index 000000000..7200fdffb
--- /dev/null
+++ b/gio/gwin32notificationbackend.c
@@ -0,0 +1,90 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright © 2018 Endless Mobile, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * - Philip Withnall <withnall endlessm com>
+ */
+
+#include "config.h"
+
+#include "gnotificationbackend.h"
+
+#include "giomodule-priv.h"
+#include "gnotification-private.h"
+
+#define G_TYPE_WIN32_NOTIFICATION_BACKEND (g_win32_notification_backend_get_type ())
+#define G_WIN32_NOTIFICATION_BACKEND(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
G_TYPE_WIN32_NOTIFICATION_BACKEND, GWin32NotificationBackend))
+
+typedef struct _GWin32NotificationBackend GWin32NotificationBackend;
+typedef GNotificationBackendClass GWin32NotificationBackendClass;
+
+struct _GWin32NotificationBackend
+{
+ GNotificationBackend parent;
+};
+
+GType g_win32_notification_backend_get_type (void);
+
+G_DEFINE_TYPE_WITH_CODE (GWin32NotificationBackend, g_win32_notification_backend,
G_TYPE_NOTIFICATION_BACKEND,
+ _g_io_modules_ensure_extension_points_registered ();
+ g_io_extension_point_implement (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME,
+ g_define_type_id, "win32", 0))
+
+static gboolean
+g_win32_notification_backend_is_supported (void)
+{
+ /* This is the only backend supported on Windows, and always needs to be
+ * present to avoid no backend being selected. */
+ return TRUE;
+}
+
+static void
+g_win32_notification_backend_send_notification (GNotificationBackend *backend,
+ const gchar *id,
+ GNotification *notification)
+{
+ /* FIXME: See https://bugzilla.gnome.org/show_bug.cgi?id=776583. This backend
+ * exists purely to stop crashes when applications use g_notification*()
+ * on Windows, by providing a dummy backend implementation. (The alternative
+ * was to modify all of the backend call sites in g_notification*(), which
+ * seemed less scalable.) */
+ g_warning ("Notifications are not yet supported on Windows.");
+}
+
+static void
+g_win32_notification_backend_withdraw_notification (GNotificationBackend *backend,
+ const gchar *id)
+{
+ /* FIXME: Nothing needs doing here until send_notification() is implemented. */
+}
+
+static void
+g_win32_notification_backend_init (GWin32NotificationBackend *backend)
+{
+}
+
+static void
+g_win32_notification_backend_class_init (GWin32NotificationBackendClass *class)
+{
+ GNotificationBackendClass *backend_class = G_NOTIFICATION_BACKEND_CLASS (class);
+
+ backend_class->is_supported = g_win32_notification_backend_is_supported;
+ backend_class->send_notification = g_win32_notification_backend_send_notification;
+ backend_class->withdraw_notification = g_win32_notification_backend_withdraw_notification;
+}
diff --git a/gio/meson.build b/gio/meson.build
index 44808f77e..f1faf0b3e 100644
--- a/gio/meson.build
+++ b/gio/meson.build
@@ -440,6 +440,7 @@ else
'gwin32outputstream.c',
'gwin32networkmonitor.c',
'gwin32networkmonitor.h',
+ 'gwin32notificationbackend.c',
)
gio_win_rc = configure_file(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]