[gnome-settings-daemon] screensaver-proxy: Add new screesaver proxy plugin



commit b6bd12a36397767f1693f99cb68e7d5cf613f982
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Nov 28 14:46:51 2012 +0100

    screensaver-proxy: Add new screesaver proxy plugin
    
    Proxy the org.freedesktop.ScreenSaver D-Bus API to gnome-session
    as needed.
    
    Note that, as we are the one talking to gnome-session, automatically
    removing inhibition cookies when the caller goes away won't work.
    We must watch incoming inhibition requests, and make sure to clean up
    and remove lingering cookies when the caller goes away.
    
    API:
    https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/master/entry/ksmserver/screenlocker/dbus/org.freedesktop.ScreenSaver.xm
    Documentation:
    https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/master/entry/ksmserver/screenlocker/interface.h
    
    https://bugzilla.gnome.org/show_bug.cgi?id=689225

 configure.ac                                       |    1 +
 ...gnome.settings-daemon.plugins.gschema.xml.in.in |   13 +
 plugins/Makefile.am                                |    1 +
 plugins/screensaver-proxy/Makefile.am              |   61 ++++
 .../gsd-screensaver-proxy-manager.c                |  378 ++++++++++++++++++++
 .../gsd-screensaver-proxy-manager.h                |   57 +++
 .../gsd-screensaver-proxy-plugin.c                 |  104 ++++++
 .../gsd-screensaver-proxy-plugin.h                 |   59 +++
 .../screensaver-proxy.gnome-settings-plugin.in     |    8 +
 plugins/screensaver-proxy/test-screensaver-proxy.c |    7 +
 10 files changed, 689 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index fa1f131..82dadb7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -489,6 +489,7 @@ plugins/media-keys/gvc/Makefile
 plugins/mouse/Makefile
 plugins/orientation/Makefile
 plugins/print-notifications/Makefile
+plugins/screensaver-proxy/Makefile
 plugins/smartcard/Makefile
 plugins/sound/Makefile
 plugins/updates/Makefile
diff --git a/data/org.gnome.settings-daemon.plugins.gschema.xml.in.in b/data/org.gnome.settings-daemon.plugins.gschema.xml.in.in
index 958863b..b2b3dc6 100644
--- a/data/org.gnome.settings-daemon.plugins.gschema.xml.in.in
+++ b/data/org.gnome.settings-daemon.plugins.gschema.xml.in.in
@@ -24,6 +24,7 @@
     <child name="orientation" schema="org.gnome.settings-daemon.plugins.orientation"/>
     <child name="power" schema="org.gnome.settings-daemon.plugins.power"/>
     <child name="print-notifications" schema="org.gnome.settings-daemon.plugins.print-notifications"/>
+    <child name="screensaver-proxy" schema="org.gnome.settings-daemon.plugins.screensaver-proxy"/>
     <child name="smartcard" schema="org.gnome.settings-daemon.plugins.smartcard"/>
     <child name="sound" schema="org.gnome.settings-daemon.plugins.sound"/>
     <child name="updates" schema="org.gnome.settings-daemon.plugins.updates"/>
@@ -114,6 +115,18 @@
       <_description>Priority to use for this plugin in gnome-settings-daemon startup queue</_description>
     </key>
   </schema>
+  <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.settings-daemon.plugins.screensaver-proxy" path="/org/gnome/settings-daemon/plugins/screensaver-proxy/">
+    <key name="active" type="b">
+      <default>true</default>
+      <_summary>Activation of this plugin</_summary>
+      <_description>Whether this plugin would be activated by gnome-settings-daemon or not</_description>
+    </key>
+    <key name="priority" type="i">
+      <default>8</default>
+      <_summary>Priority to use for this plugin</_summary>
+      <_description>Priority to use for this plugin in gnome-settings-daemon startup queue</_description>
+    </key>
+  </schema>
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.settings-daemon.plugins.smartcard" path="/org/gnome/settings-daemon/plugins/smartcard/">
     <key name="active" type="b">
       <default>true</default>
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 255ec5a..baaf252 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -13,6 +13,7 @@ enabled_plugins =	\
 	keyboard	\
 	media-keys	\
 	mouse		\
+	screensaver-proxy \
 	sound		\
 	xrandr		\
 	xsettings	\
diff --git a/plugins/screensaver-proxy/Makefile.am b/plugins/screensaver-proxy/Makefile.am
new file mode 100644
index 0000000..38d908b
--- /dev/null
+++ b/plugins/screensaver-proxy/Makefile.am
@@ -0,0 +1,61 @@
+plugin_name = screensaver-proxy
+
+plugin_LTLIBRARIES = libscreensaver-proxy.la
+
+libscreensaver_proxy_la_SOURCES =	\
+	gsd-screensaver-proxy-manager.c	\
+	gsd-screensaver-proxy-manager.h	\
+	gsd-screensaver-proxy-plugin.c	\
+	gsd-screensaver-proxy-plugin.h
+
+libscreensaver_proxy_la_CPPFLAGS =				\
+	-I$(top_srcdir)/gnome-settings-daemon			\
+	-DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\"	\
+	$(AM_CPPFLAGS)
+
+libscreensaver_proxy_la_CFLAGS =	\
+	$(PLUGIN_CFLAGS)		\
+	$(SETTINGS_PLUGIN_CFLAGS)	\
+	$(AM_CFLAGS)
+
+libscreensaver_proxy_la_LDFLAGS = $(GSD_PLUGIN_LDFLAGS)
+
+libscreensaver_proxy_la_LIBADD  = $(SETTINGS_PLUGIN_LIBS)
+
+libexec_PROGRAMS = gsd-test-screensaver-proxy
+
+gsd_test_screensaver_proxy_SOURCES =		\
+	test-screensaver-proxy.c			\
+	gsd-screensaver-proxy-manager.c		\
+	gsd-screensaver-proxy-manager.h
+
+gsd_test_screensaver_proxy_CPPFLAGS =					\
+	-I$(top_srcdir)/data/					\
+	-I$(top_srcdir)/gnome-settings-daemon			\
+	-I$(top_srcdir)/plugins/common				\
+	-DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\"	\
+	-DLIBEXECDIR=\""$(libexecdir)"\"			\
+	$(AM_CPPFLAGS)
+
+gsd_test_screensaver_proxy_CFLAGS =			\
+	$(PLUGIN_CFLAGS)		\
+	$(SETTINGS_PLUGIN_CFLAGS)	\
+	$(AM_CFLAGS)
+
+gsd_test_screensaver_proxy_LDADD =						\
+	$(top_builddir)/gnome-settings-daemon/libgsd.la		\
+	$(top_builddir)/plugins/common/libcommon.la		\
+	$(SETTINGS_DAEMON_LIBS)			\
+	$(SETTINGS_PLUGIN_LIBS)
+
+plugin_in_files = screensaver-proxy.gnome-settings-plugin.in
+
+plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin)
+
+EXTRA_DIST = $(plugin_in_files)
+
+CLEANFILES = $(plugin_DATA)
+
+DISTCLEANFILES = $(plugin_DATA)
+
+ GSD_INTLTOOL_PLUGIN_RULE@
diff --git a/plugins/screensaver-proxy/gsd-screensaver-proxy-manager.c b/plugins/screensaver-proxy/gsd-screensaver-proxy-manager.c
new file mode 100644
index 0000000..1f0741a
--- /dev/null
+++ b/plugins/screensaver-proxy/gsd-screensaver-proxy-manager.c
@@ -0,0 +1,378 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Bastien Nocera <hadess hadess net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <locale.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gdk/gdk.h>
+
+#include "gnome-settings-session.h"
+#include "gnome-settings-profile.h"
+#include "gsd-screensaver-proxy-manager.h"
+
+#define GSD_SCREENSAVER_PROXY_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SCREENSAVER_PROXY_MANAGER, GsdScreensaverProxyManagerPrivate))
+
+/* As available in:
+ * https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/master/entry/ksmserver/screenlocker/dbus/org.freedesktop.ScreenSaver.xml
+ * and documented in:
+ * https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/master/entry/ksmserver/screenlocker/interface.h */
+static const gchar introspection_xml[] =
+"<node name='/org/freedesktop/ScreenSaver'>"
+    "<interface name='org.freedesktop.ScreenSaver'>"
+    "<method name='Lock'/>"
+    "<method name='SimulateUserActivity'/>"
+    "<method name='GetActive'>"
+      "<arg type='b' direction='out'/>"
+    "</method>"
+    "<method name='GetActiveTime'>"
+      "<arg name='seconds' type='u' direction='out'/>"
+    "</method>"
+    "<method name='GetSessionIdleTime'>"
+      "<arg name='seconds' type='u' direction='out'/>"
+    "</method>"
+    "<method name='SetActive'>"
+      "<arg type='b' direction='out'/>"
+      "<arg name='e' type='b' direction='in'/>"
+    "</method>"
+    "<method name='Inhibit'>"
+      "<arg name='application_name' type='s' direction='in'/>"
+      "<arg name='reason_for_inhibit' type='s' direction='in'/>"
+      "<arg name='cookie' type='u' direction='out'/>"
+    "</method>"
+    "<method name='UnInhibit'>"
+      "<arg name='cookie' type='u' direction='in'/>"
+    "</method>"
+    "<method name='Throttle'>"
+      "<arg name='application_name' type='s' direction='in'/>"
+      "<arg name='reason_for_inhibit' type='s' direction='in'/>"
+      "<arg name='cookie' type='u' direction='out'/>"
+    "</method>"
+    "<method name='UnThrottle'>"
+      "<arg name='cookie' type='u' direction='in'/>"
+    "</method>"
+
+    "<signal name='ActiveChanged'>"
+      "<arg type='b'/>"
+    "</signal>"
+  "</interface>"
+"</node>";
+
+#define GSD_SCREENSAVER_PROXY_DBUS_SERVICE      "org.freedesktop.ScreenSaver"
+#define GSD_SCREENSAVER_PROXY_DBUS_PATH         "/org/freedesktop/ScreenSaver"
+#define GSD_SCREENSAVER_PROXY_DBUS_INTERFACE    "org.freedesktop.ScreenSaver"
+
+#define GSM_INHIBITOR_FLAG_IDLE 1 << 3
+
+struct GsdScreensaverProxyManagerPrivate
+{
+        GDBusProxy              *session;
+        GDBusConnection         *connection;
+        GCancellable            *bus_cancellable;
+        GDBusNodeInfo           *introspection_data;
+        guint                    name_id;
+
+        GHashTable              *watch_ht;  /* key = sender, value = name watch id */
+        GHashTable              *cookie_ht; /* key = cookie, value = sender */
+};
+
+static void     gsd_screensaver_proxy_manager_class_init  (GsdScreensaverProxyManagerClass *klass);
+static void     gsd_screensaver_proxy_manager_init        (GsdScreensaverProxyManager      *screensaver_proxy_manager);
+static void     gsd_screensaver_proxy_manager_finalize    (GObject             *object);
+
+G_DEFINE_TYPE (GsdScreensaverProxyManager, gsd_screensaver_proxy_manager, G_TYPE_OBJECT)
+
+static gpointer manager_object = NULL;
+
+static void
+name_vanished_cb (GDBusConnection            *connection,
+                  const gchar                *name,
+                  GsdScreensaverProxyManager *manager)
+{
+        GHashTableIter iter;
+        gpointer cookie_ptr;
+        const char *sender;
+
+        /* Look for all the cookies under that name,
+         * and call uninhibit for them */
+        g_hash_table_iter_init (&iter, manager->priv->cookie_ht);
+        while (g_hash_table_iter_next (&iter, &cookie_ptr, (gpointer *) &sender)) {
+                if (g_strcmp0 (sender, name) == 0) {
+                        guint cookie = GPOINTER_TO_UINT (cookie_ptr);
+
+                        g_dbus_proxy_call_sync (manager->priv->session,
+                                                "Uninhibit",
+                                                g_variant_new ("(u)", cookie),
+                                                G_DBUS_CALL_FLAGS_NONE,
+                                                -1, NULL, NULL);
+                        g_debug ("Removing cookie %u for sender %s",
+                                 cookie, sender);
+                        g_hash_table_iter_remove (&iter);
+                }
+        }
+
+        g_hash_table_remove (manager->priv->watch_ht, sender);
+}
+
+static void
+handle_method_call (GDBusConnection       *connection,
+                    const gchar           *sender,
+                    const gchar           *object_path,
+                    const gchar           *interface_name,
+                    const gchar           *method_name,
+                    GVariant              *parameters,
+                    GDBusMethodInvocation *invocation,
+                    gpointer               user_data)
+{
+        GsdScreensaverProxyManager *manager = GSD_SCREENSAVER_PROXY_MANAGER (user_data);
+
+        /* Check session pointer as a proxy for whether the manager is in the
+           start or stop state */
+        if (manager->priv->session == NULL) {
+                return;
+        }
+
+        g_debug ("Calling method '%s.%s' for ScreenSaver Proxy",
+                 interface_name, method_name);
+
+        if (g_strcmp0 (method_name, "Inhibit") == 0) {
+                GVariant *ret;
+                const char *app_id;
+                const char *reason;
+                guint cookie;
+
+                g_variant_get (parameters,
+                               "(ss)", &app_id, &reason);
+
+                ret = g_dbus_proxy_call_sync (manager->priv->session,
+                                              "Inhibit",
+                                              g_variant_new ("(susu)",
+                                                             app_id, 0, reason, GSM_INHIBITOR_FLAG_IDLE),
+                                              G_DBUS_CALL_FLAGS_NONE,
+                                              -1, NULL, NULL);
+                g_variant_get (ret, "(u)", &cookie);
+                g_hash_table_insert (manager->priv->cookie_ht,
+                                     GUINT_TO_POINTER (cookie),
+                                     g_strdup (sender));
+                if (g_hash_table_lookup (manager->priv->watch_ht, sender) == NULL) {
+                        guint watch_id;
+
+                        watch_id = g_bus_watch_name_on_connection (manager->priv->connection,
+                                                                   sender,
+                                                                   G_BUS_NAME_WATCHER_FLAGS_NONE,
+                                                                   NULL,
+                                                                   (GBusNameVanishedCallback) name_vanished_cb,
+                                                                   manager,
+                                                                   NULL);
+                        g_hash_table_insert (manager->priv->watch_ht,
+                                             g_strdup (sender),
+                                             GUINT_TO_POINTER (watch_id));
+                }
+                g_dbus_method_invocation_return_value (invocation, ret);
+        } else if (g_strcmp0 (method_name, "UnInhibit") == 0) {
+                guint cookie;
+
+                g_variant_get (parameters, "(u)", &cookie);
+                g_dbus_proxy_call_sync (manager->priv->session,
+                                        "Uninhibit",
+                                        parameters,
+                                        G_DBUS_CALL_FLAGS_NONE,
+                                        -1, NULL, NULL);
+                g_debug ("Removing cookie %u from the list for %s", cookie, sender);
+                g_hash_table_remove (manager->priv->cookie_ht, GUINT_TO_POINTER (cookie));
+                g_dbus_method_invocation_return_value (invocation, NULL);
+        } else if (g_strcmp0 (method_name, "Throttle") == 0) {
+                g_dbus_method_invocation_return_value (invocation, NULL);
+        } else if (g_strcmp0 (method_name, "UnThrottle") == 0) {
+                g_dbus_method_invocation_return_value (invocation, NULL);
+        } else if (g_strcmp0 (method_name, "Lock") == 0) {
+                goto unimplemented;
+        } else if (g_strcmp0 (method_name, "SimulateUserActivity") == 0) {
+                goto unimplemented;
+        } else if (g_strcmp0 (method_name, "GetActive") == 0) {
+                goto unimplemented;
+        } else if (g_strcmp0 (method_name, "GetActiveTime") == 0) {
+                goto unimplemented;
+        } else if (g_strcmp0 (method_name, "GetSessionIdleTime") == 0) {
+                goto unimplemented;
+        } else if (g_strcmp0 (method_name, "SetActive") == 0) {
+                goto unimplemented;
+        }
+
+        return;
+
+unimplemented:
+        g_dbus_method_invocation_return_dbus_error (invocation,
+                                                    "org.freedesktop.DBus.Error.NotSupported",
+                                                    "This method is not implemented");
+}
+
+static const GDBusInterfaceVTable interface_vtable =
+{
+        handle_method_call,
+        NULL, /* GetProperty */
+        NULL, /* SetProperty */
+};
+
+static void
+on_bus_gotten (GObject                    *source_object,
+               GAsyncResult               *res,
+               GsdScreensaverProxyManager *manager)
+{
+        GDBusConnection *connection;
+        GDBusInterfaceInfo **infos;
+        GError *error = NULL;
+
+        if (manager->priv->bus_cancellable == NULL ||
+            g_cancellable_is_cancelled (manager->priv->bus_cancellable)) {
+                g_warning ("Operation has been cancelled, so not retrieving session bus");
+                return;
+        }
+
+        connection = g_bus_get_finish (res, &error);
+        if (connection == NULL) {
+                g_warning ("Could not get session bus: %s", error->message);
+                g_error_free (error);
+                return;
+        }
+        manager->priv->connection = connection;
+        infos = manager->priv->introspection_data->interfaces;
+        g_dbus_connection_register_object (connection,
+                                           GSD_SCREENSAVER_PROXY_DBUS_PATH,
+                                           infos[0],
+                                           &interface_vtable,
+                                           manager,
+                                           NULL,
+                                           NULL);
+
+        manager->priv->name_id = g_bus_own_name_on_connection (manager->priv->connection,
+                                                               GSD_SCREENSAVER_PROXY_DBUS_SERVICE,
+                                                               G_BUS_NAME_OWNER_FLAGS_NONE,
+                                                               NULL,
+                                                               NULL,
+                                                               NULL,
+                                                               NULL);
+}
+
+static void
+register_manager_dbus (GsdScreensaverProxyManager *manager)
+{
+        manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
+        manager->priv->bus_cancellable = g_cancellable_new ();
+        g_assert (manager->priv->introspection_data != NULL);
+
+        g_bus_get (G_BUS_TYPE_SESSION,
+                   manager->priv->bus_cancellable,
+                   (GAsyncReadyCallback) on_bus_gotten,
+                   manager);
+}
+
+gboolean
+gsd_screensaver_proxy_manager_start (GsdScreensaverProxyManager *manager,
+                                     GError               **error)
+{
+        g_debug ("Starting screensaver-proxy manager");
+        gnome_settings_profile_start (NULL);
+        manager->priv->session =
+                gnome_settings_session_get_session_proxy ();
+        manager->priv->watch_ht = g_hash_table_new_full (g_str_hash,
+                                                         g_str_equal,
+                                                         (GDestroyNotify) g_free,
+                                                         (GDestroyNotify) g_bus_unwatch_name);
+        manager->priv->cookie_ht = g_hash_table_new_full (g_direct_hash,
+                                                          g_direct_equal,
+                                                          NULL,
+                                                          (GDestroyNotify) g_free);
+        gnome_settings_profile_end (NULL);
+        return TRUE;
+}
+
+void
+gsd_screensaver_proxy_manager_stop (GsdScreensaverProxyManager *manager)
+{
+        g_debug ("Stopping screensaver_proxy manager");
+        g_clear_object (&manager->priv->session);
+        g_clear_pointer (&manager->priv->watch_ht, g_hash_table_destroy);
+        g_clear_pointer (&manager->priv->cookie_ht, g_hash_table_destroy);
+}
+
+static void
+gsd_screensaver_proxy_manager_class_init (GsdScreensaverProxyManagerClass *klass)
+{
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->finalize = gsd_screensaver_proxy_manager_finalize;
+
+        g_type_class_add_private (klass, sizeof (GsdScreensaverProxyManagerPrivate));
+}
+
+static void
+gsd_screensaver_proxy_manager_init (GsdScreensaverProxyManager *manager)
+{
+        manager->priv = GSD_SCREENSAVER_PROXY_MANAGER_GET_PRIVATE (manager);
+}
+
+static void
+gsd_screensaver_proxy_manager_finalize (GObject *object)
+{
+        GsdScreensaverProxyManager *manager;
+
+        g_return_if_fail (object != NULL);
+        g_return_if_fail (GSD_IS_SCREENSAVER_PROXY_MANAGER (object));
+
+        manager = GSD_SCREENSAVER_PROXY_MANAGER (object);
+
+        g_return_if_fail (manager->priv != NULL);
+
+        if (manager->priv->name_id != 0) {
+                g_bus_unown_name (manager->priv->name_id);
+                manager->priv->name_id = 0;
+        }
+        g_clear_object (&manager->priv->connection);
+        g_clear_object (&manager->priv->bus_cancellable);
+        g_clear_pointer (&manager->priv->introspection_data, g_dbus_node_info_unref);
+
+        G_OBJECT_CLASS (gsd_screensaver_proxy_manager_parent_class)->finalize (object);
+}
+
+GsdScreensaverProxyManager *
+gsd_screensaver_proxy_manager_new (void)
+{
+        if (manager_object != NULL) {
+                g_object_ref (manager_object);
+        } else {
+                manager_object = g_object_new (GSD_TYPE_SCREENSAVER_PROXY_MANAGER, NULL);
+                g_object_add_weak_pointer (manager_object,
+                                           (gpointer *) &manager_object);
+                register_manager_dbus (manager_object);
+        }
+
+        return GSD_SCREENSAVER_PROXY_MANAGER (manager_object);
+}
diff --git a/plugins/screensaver-proxy/gsd-screensaver-proxy-manager.h b/plugins/screensaver-proxy/gsd-screensaver-proxy-manager.h
new file mode 100644
index 0000000..b529593
--- /dev/null
+++ b/plugins/screensaver-proxy/gsd-screensaver-proxy-manager.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Bastien Nocera <hadess hadess net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __GSD_SCREENSAVER_PROXY_MANAGER_H
+#define __GSD_SCREENSAVER_PROXY_MANAGER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GSD_TYPE_SCREENSAVER_PROXY_MANAGER         (gsd_screensaver_proxy_manager_get_type ())
+#define GSD_SCREENSAVER_PROXY_MANAGER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SCREENSAVER_PROXY_MANAGER, GsdScreensaverProxyManager))
+#define GSD_SCREENSAVER_PROXY_MANAGER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_SCREENSAVER_PROXY_MANAGER, GsdScreensaverProxyManagerClass))
+#define GSD_IS_SCREENSAVER_PROXY_MANAGER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SCREENSAVER_PROXY_MANAGER))
+#define GSD_IS_SCREENSAVER_PROXY_MANAGER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SCREENSAVER_PROXY_MANAGER))
+#define GSD_SCREENSAVER_PROXY_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SCREENSAVER_PROXY_MANAGER, GsdScreensaverProxyManagerClass))
+
+typedef struct GsdScreensaverProxyManagerPrivate GsdScreensaverProxyManagerPrivate;
+
+typedef struct
+{
+        GObject                     parent;
+        GsdScreensaverProxyManagerPrivate *priv;
+} GsdScreensaverProxyManager;
+
+typedef struct
+{
+        GObjectClass   parent_class;
+} GsdScreensaverProxyManagerClass;
+
+GType                       gsd_screensaver_proxy_manager_get_type            (void);
+
+GsdScreensaverProxyManager *gsd_screensaver_proxy_manager_new                 (void);
+gboolean                    gsd_screensaver_proxy_manager_start               (GsdScreensaverProxyManager  *manager,
+                                                                               GError                     **error);
+void                        gsd_screensaver_proxy_manager_stop                (GsdScreensaverProxyManager  *manager);
+
+G_END_DECLS
+
+#endif /* __GSD_SCREENSAVER_PROXY_MANAGER_H */
diff --git a/plugins/screensaver-proxy/gsd-screensaver-proxy-plugin.c b/plugins/screensaver-proxy/gsd-screensaver-proxy-plugin.c
new file mode 100644
index 0000000..d521843
--- /dev/null
+++ b/plugins/screensaver-proxy/gsd-screensaver-proxy-plugin.c
@@ -0,0 +1,104 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Bastien Nocera <hadess hadess net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+#include <gmodule.h>
+
+#include "gnome-settings-plugin.h"
+#include "gsd-screensaver-proxy-plugin.h"
+#include "gsd-screensaver-proxy-manager.h"
+
+struct GsdScreensaverProxyPluginPrivate {
+        GsdScreensaverProxyManager *manager;
+};
+
+#define GSD_SCREENSAVER_PROXY_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_SCREENSAVER_PROXY_PLUGIN, GsdScreensaverProxyPluginPrivate))
+
+GNOME_SETTINGS_PLUGIN_REGISTER (GsdScreensaverProxyPlugin, gsd_screensaver_proxy_plugin)
+
+static void
+gsd_screensaver_proxy_plugin_init (GsdScreensaverProxyPlugin *plugin)
+{
+        plugin->priv = GSD_SCREENSAVER_PROXY_PLUGIN_GET_PRIVATE (plugin);
+
+        g_debug ("GsdScreensaverProxyPlugin initializing");
+
+        plugin->priv->manager = gsd_screensaver_proxy_manager_new ();
+}
+
+static void
+gsd_screensaver_proxy_plugin_finalize (GObject *object)
+{
+        GsdScreensaverProxyPlugin *plugin;
+
+        g_return_if_fail (object != NULL);
+        g_return_if_fail (GSD_IS_SCREENSAVER_PROXY_PLUGIN (object));
+
+        g_debug ("GsdScreensaverProxyPlugin finalizing");
+
+        plugin = GSD_SCREENSAVER_PROXY_PLUGIN (object);
+
+        g_return_if_fail (plugin->priv != NULL);
+
+        if (plugin->priv->manager != NULL) {
+                g_object_unref (plugin->priv->manager);
+        }
+
+        G_OBJECT_CLASS (gsd_screensaver_proxy_plugin_parent_class)->finalize (object);
+}
+
+static void
+impl_activate (GnomeSettingsPlugin *plugin)
+{
+        gboolean res;
+        GError  *error;
+
+        g_debug ("Activating screensaver-proxy plugin");
+
+        error = NULL;
+        res = gsd_screensaver_proxy_manager_start (GSD_SCREENSAVER_PROXY_PLUGIN (plugin)->priv->manager, &error);
+        if (! res) {
+                g_warning ("Unable to start screensaver-proxy manager: %s", error->message);
+                g_error_free (error);
+        }
+}
+
+static void
+impl_deactivate (GnomeSettingsPlugin *plugin)
+{
+        g_debug ("Deactivating screensaver-proxy plugin");
+        gsd_screensaver_proxy_manager_stop (GSD_SCREENSAVER_PROXY_PLUGIN (plugin)->priv->manager);
+}
+
+static void
+gsd_screensaver_proxy_plugin_class_init (GsdScreensaverProxyPluginClass *klass)
+{
+        GObjectClass             *object_class = G_OBJECT_CLASS (klass);
+        GnomeSettingsPluginClass *plugin_class = GNOME_SETTINGS_PLUGIN_CLASS (klass);
+
+        object_class->finalize = gsd_screensaver_proxy_plugin_finalize;
+
+        plugin_class->activate = impl_activate;
+        plugin_class->deactivate = impl_deactivate;
+
+        g_type_class_add_private (klass, sizeof (GsdScreensaverProxyPluginPrivate));
+}
diff --git a/plugins/screensaver-proxy/gsd-screensaver-proxy-plugin.h b/plugins/screensaver-proxy/gsd-screensaver-proxy-plugin.h
new file mode 100644
index 0000000..13c3050
--- /dev/null
+++ b/plugins/screensaver-proxy/gsd-screensaver-proxy-plugin.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Bastien Nocera <hadess hadess net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __GSD_SCREENSAVER_PROXY_PLUGIN_H__
+#define __GSD_SCREENSAVER_PROXY_PLUGIN_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gmodule.h>
+
+#include "gnome-settings-plugin.h"
+
+G_BEGIN_DECLS
+
+#define GSD_TYPE_SCREENSAVER_PROXY_PLUGIN                (gsd_screensaver_proxy_plugin_get_type ())
+#define GSD_SCREENSAVER_PROXY_PLUGIN(o)                  (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SCREENSAVER_PROXY_PLUGIN, GsdScreensaverProxyPlugin))
+#define GSD_SCREENSAVER_PROXY_PLUGIN_CLASS(k)            (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_SCREENSAVER_PROXY_PLUGIN, GsdScreensaverProxyPluginClass))
+#define GSD_IS_SCREENSAVER_PROXY_PLUGIN(o)               (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SCREENSAVER_PROXY_PLUGIN))
+#define GSD_IS_SCREENSAVER_PROXY_PLUGIN_CLASS(k)         (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SCREENSAVER_PROXY_PLUGIN))
+#define GSD_SCREENSAVER_PROXY_PLUGIN_GET_CLASS(o)        (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SCREENSAVER_PROXY_PLUGIN, GsdScreensaverProxyPluginClass))
+
+typedef struct GsdScreensaverProxyPluginPrivate GsdScreensaverProxyPluginPrivate;
+
+typedef struct
+{
+        GnomeSettingsPlugin    parent;
+        GsdScreensaverProxyPluginPrivate *priv;
+} GsdScreensaverProxyPlugin;
+
+typedef struct
+{
+        GnomeSettingsPluginClass parent_class;
+} GsdScreensaverProxyPluginClass;
+
+GType   gsd_screensaver_proxy_plugin_get_type            (void) G_GNUC_CONST;
+
+/* All the plugins must implement this function */
+G_MODULE_EXPORT GType register_gnome_settings_plugin (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __GSD_SCREENSAVER_PROXY_PLUGIN_H__ */
diff --git a/plugins/screensaver-proxy/screensaver-proxy.gnome-settings-plugin.in b/plugins/screensaver-proxy/screensaver-proxy.gnome-settings-plugin.in
new file mode 100644
index 0000000..c1bd4ac
--- /dev/null
+++ b/plugins/screensaver-proxy/screensaver-proxy.gnome-settings-plugin.in
@@ -0,0 +1,8 @@
+[GNOME Settings Plugin]
+Module=screensaver-proxy
+IAge=0
+_Name=Screensaver Proxy
+_Description=Proxy FreeDesktop screensaver inhibition to gnome-session
+Authors=AUTHOR
+Copyright=Copyright  2012 Bastien Nocera
+Website=
diff --git a/plugins/screensaver-proxy/test-screensaver-proxy.c b/plugins/screensaver-proxy/test-screensaver-proxy.c
new file mode 100644
index 0000000..d5d9268
--- /dev/null
+++ b/plugins/screensaver-proxy/test-screensaver-proxy.c
@@ -0,0 +1,7 @@
+#define NEW gsd_screensaver_proxy_manager_new
+#define START gsd_screensaver_proxy_manager_start
+#define STOP gsd_screensaver_proxy_manager_stop
+#define MANAGER GsdScreensaverProxyManager
+#include "gsd-screensaver-proxy-manager.h"
+
+#include "test-plugin.h"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]