mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-02 09:16:17 +01:00
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
This commit is contained in:
parent
ec20cb4402
commit
b868cf5864
@ -334,6 +334,7 @@ win32_actual_sources = \
|
||||
gwin32networking.h \
|
||||
gwin32networkmonitor.c \
|
||||
gwin32networkmonitor.h \
|
||||
gwin32notificationbackend.c \
|
||||
$(NULL)
|
||||
|
||||
win32_more_sources_for_vcproj = \
|
||||
|
@ -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 ());
|
||||
|
90
gio/gwin32notificationbackend.c
Normal file
90
gio/gwin32notificationbackend.c
Normal file
@ -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;
|
||||
}
|
@ -440,6 +440,7 @@ else
|
||||
'gwin32outputstream.c',
|
||||
'gwin32networkmonitor.c',
|
||||
'gwin32networkmonitor.h',
|
||||
'gwin32notificationbackend.c',
|
||||
)
|
||||
|
||||
gio_win_rc = configure_file(
|
||||
|
Loading…
Reference in New Issue
Block a user