Blame gio/gportalnotificationbackend.c

Packit ae235b
/*
Packit ae235b
* Copyright © 2016 Red Hat, Inc.
Packit ae235b
*
Packit ae235b
* This library is free software; you can redistribute it and/or
Packit ae235b
* modify it under the terms of the GNU Lesser General Public
Packit ae235b
* License as published by the Free Software Foundation; either
Packit ae235b
* version 2.1 of the License, or (at your option) any later version.
Packit ae235b
*
Packit ae235b
* This library is distributed in the hope that it will be useful,
Packit ae235b
* but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
* Lesser General Public License for more details.
Packit ae235b
*
Packit ae235b
* You should have received a copy of the GNU Lesser General
Packit ae235b
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
*
Packit ae235b
* Author: Matthias Clasen
Packit ae235b
*/
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
#include "gnotificationbackend.h"
Packit ae235b
Packit ae235b
#include "giomodule-priv.h"
Packit ae235b
#include "gdbusconnection.h"
Packit ae235b
#include "gapplication.h"
Packit ae235b
#include "gnotification-private.h"
Packit ae235b
#include "gportalsupport.h"
Packit ae235b
Packit ae235b
#define G_TYPE_PORTAL_NOTIFICATION_BACKEND  (g_portal_notification_backend_get_type ())
Packit ae235b
#define G_PORTAL_NOTIFICATION_BACKEND(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_PORTAL_NOTIFICATION_BACKEND, GPortalNotificationBackend))
Packit ae235b
Packit ae235b
typedef struct _GPortalNotificationBackend GPortalNotificationBackend;
Packit ae235b
typedef GNotificationBackendClass       GPortalNotificationBackendClass;
Packit ae235b
Packit ae235b
struct _GPortalNotificationBackend
Packit ae235b
{
Packit ae235b
  GNotificationBackend parent;
Packit ae235b
};
Packit ae235b
Packit ae235b
GType g_portal_notification_backend_get_type (void);
Packit ae235b
Packit ae235b
G_DEFINE_TYPE_WITH_CODE (GPortalNotificationBackend, g_portal_notification_backend, G_TYPE_NOTIFICATION_BACKEND,
Packit ae235b
  _g_io_modules_ensure_extension_points_registered ();
Packit ae235b
  g_io_extension_point_implement (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME,
Packit ae235b
                                 g_define_type_id, "portal", 110))
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
g_portal_notification_backend_is_supported (void)
Packit ae235b
{
Packit ae235b
  return glib_should_use_portal ();
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_portal_notification_backend_send_notification (GNotificationBackend *backend,
Packit ae235b
                                                 const gchar          *id,
Packit ae235b
                                                 GNotification        *notification)
Packit ae235b
{
Packit ae235b
  g_dbus_connection_call (backend->dbus_connection,
Packit ae235b
                          "org.freedesktop.portal.Desktop",
Packit ae235b
                          "/org/freedesktop/portal/desktop",
Packit ae235b
                          "org.freedesktop.portal.Notification",
Packit ae235b
                          "AddNotification",
Packit ae235b
                          g_variant_new ("(s@a{sv})",
Packit ae235b
                                         id,
Packit ae235b
                                         g_notification_serialize (notification)),
Packit ae235b
                          G_VARIANT_TYPE_UNIT,
Packit ae235b
                          G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_portal_notification_backend_withdraw_notification (GNotificationBackend *backend,
Packit ae235b
                                                     const gchar          *id)
Packit ae235b
{
Packit ae235b
  g_dbus_connection_call (backend->dbus_connection,
Packit ae235b
                          "org.freedesktop.portal.Desktop",
Packit ae235b
                          "/org/freedesktop/portal/desktop",
Packit ae235b
                          "org.freedesktop.portal.Notification",
Packit ae235b
                          "RemoveNotification",
Packit ae235b
                          g_variant_new ("(s)", id),
Packit ae235b
                          G_VARIANT_TYPE_UNIT,
Packit ae235b
                          G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_portal_notification_backend_init (GPortalNotificationBackend *backend)
Packit ae235b
{
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_portal_notification_backend_class_init (GPortalNotificationBackendClass *class)
Packit ae235b
{
Packit ae235b
  GNotificationBackendClass *backend_class = G_NOTIFICATION_BACKEND_CLASS (class);
Packit ae235b
Packit ae235b
  backend_class->is_supported = g_portal_notification_backend_is_supported;
Packit ae235b
  backend_class->send_notification = g_portal_notification_backend_send_notification;
Packit ae235b
  backend_class->withdraw_notification = g_portal_notification_backend_withdraw_notification;
Packit ae235b
}