[eog] Update totem-scrsaver from upstream



commit 63b4670443d0900f3203bd8ca2cd3fd84c82f9e9
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Jun 13 13:31:40 2010 +0100

    Update totem-scrsaver from upstream
    
    Update from recent evince and totem changes, port to libgdbus.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621439

 configure.ac                                   |    2 +-
 cut-n-paste/totem-screensaver/totem-scrsaver.c |  382 ++++++++++++++----------
 cut-n-paste/totem-screensaver/totem-scrsaver.h |   24 +-
 po/POTFILES.in                                 |    1 -
 src/eog-application.c                          |    5 +-
 5 files changed, 242 insertions(+), 172 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 967dc16..e6af985 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,7 +84,7 @@ GNOME_DOC_INIT
 # **********
 
 GTK_REQUIRED=2.18.0
-GLIB_REQUIRED=2.25.6
+GLIB_REQUIRED=2.25.8
 GNOME_DESKTOP_REQUIRED=2.25.1
 GDKPIXBUF_REQUIRED=2.4.0
 # Require GConf 2.31+ for GConf-GSettings-Backend
diff --git a/cut-n-paste/totem-screensaver/totem-scrsaver.c b/cut-n-paste/totem-screensaver/totem-scrsaver.c
index a57b506..8622079 100644
--- a/cut-n-paste/totem-screensaver/totem-scrsaver.c
+++ b/cut-n-paste/totem-screensaver/totem-scrsaver.c
@@ -1,6 +1,8 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 
    Copyright (C) 2004-2006 Bastien Nocera <hadess hadess net>
+   Copyright © 2010 Christian Persch
+   Copyright © 2010 Carlos Garcia Campos
 
    The Gnome Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public License as
@@ -17,10 +19,11 @@
    write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301  USA.
 
-   Author: Bastien Nocera <hadess hadess net>
+   Authors: Bastien Nocera <hadess hadess net>
+            Christian Persch
+            Carlos Garcia Campos
  */
 
-
 #include "config.h"
 
 #include <glib/gi18n.h>
@@ -36,32 +39,32 @@
 #endif /* HAVE_XTEST */
 #endif /* GDK_WINDOWING_X11 */
 
-#ifdef HAVE_DBUS
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
+#include "totem-scrsaver.h"
 
 #define GS_SERVICE   "org.gnome.ScreenSaver"
 #define GS_PATH      "/org/gnome/ScreenSaver"
 #define GS_INTERFACE "org.gnome.ScreenSaver"
-#endif /* HAVE_DBUS */
-
-#include "totem-scrsaver.h"
 
 #define XSCREENSAVER_MIN_TIMEOUT 60
 
-static GObjectClass *parent_class = NULL;
-static void totem_scrsaver_finalize   (GObject *object);
+enum {
+	PROP_0,
+	PROP_REASON
+};
 
+static void totem_scrsaver_finalize   (GObject *object);
 
 struct TotemScrsaverPrivate {
 	/* Whether the screensaver is disabled */
 	gboolean disabled;
+	/* The reason for the inhibition */
+	char *reason;
 
-#ifdef HAVE_DBUS
-	DBusGConnection *connection;
-	DBusGProxy *gs_proxy;
+	GDBusProxy *gs_proxy;
+        gboolean have_screensaver_dbus;
+        guint watch_id;
 	guint32 cookie;
-#endif /* HAVE_DBUS */
+	gboolean old_dbus_api;
 
 	/* To save the screensaver info */
 	int timeout;
@@ -80,96 +83,121 @@ G_DEFINE_TYPE(TotemScrsaver, totem_scrsaver, G_TYPE_OBJECT)
 static gboolean
 screensaver_is_running_dbus (TotemScrsaver *scr)
 {
-#ifdef HAVE_DBUS
-	if (! scr->priv->connection)
-		return FALSE;
-
-	if (! scr->priv->gs_proxy)
-		return FALSE;
-
-	return TRUE;
-#else
-	return FALSE;
-#endif /* HAVE_DBUS */
+        return scr->priv->have_screensaver_dbus;
 }
 
 static void
-screensaver_inhibit_dbus (TotemScrsaver *scr,
-			  gboolean	 inhibit)
+on_inhibit_cb (GObject      *source_object,
+	       GAsyncResult *res,
+	       gpointer      user_data)
 {
-#ifdef HAVE_DBUS
-	GError *error;
-	gboolean res;
-
-	g_return_if_fail (scr != NULL);
-	g_return_if_fail (scr->priv->connection != NULL);
-	g_return_if_fail (scr->priv->gs_proxy != NULL);
-
-	error = NULL;
-	if (inhibit) {
-		char   *application;
-		char   *reason;
-		guint32 cookie;
-
-		application = g_strdup ("Eye of GNOME");
-		reason = g_strdup (_("Running in fullscreen mode"));
-
-		res = dbus_g_proxy_call (scr->priv->gs_proxy,
-					 "Inhibit",
-					 &error,
-					 G_TYPE_STRING, application,
-					 G_TYPE_STRING, reason,
-					 G_TYPE_INVALID,
-					 G_TYPE_UINT, &cookie,
-					 G_TYPE_INVALID);
-
-		if (res) {
-			/* save the cookie */
-			scr->priv->cookie = cookie;
-		} else {
+	GDBusProxy    *proxy = G_DBUS_PROXY (source_object);
+	TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
+	GVariant      *value;
+	GError        *error = NULL;
+
+	value = g_dbus_proxy_call_finish (proxy, res, &error);
+	if (!value) {
+		if (!scr->priv->old_dbus_api &&
+		    g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
+			g_return_if_fail (scr->priv->reason != NULL);
 			/* try the old API */
-			res = dbus_g_proxy_call (scr->priv->gs_proxy,
-						 "InhibitActivation",
-						 NULL,
-						 G_TYPE_STRING, reason,
-						 G_TYPE_INVALID,
-						 G_TYPE_INVALID);
-			if (res)
-				g_error_free (error);
+			scr->priv->old_dbus_api = TRUE;
+			g_dbus_proxy_call (proxy,
+					   "InhibitActivation",
+					   g_variant_new ("(s)",
+							  scr->priv->reason),
+					   G_DBUS_CALL_FLAGS_NO_AUTO_START,
+					   -1,
+					   NULL,
+					   on_inhibit_cb,
+					   scr);
+		} else {
+			g_warning ("Problem inhibiting the screensaver: %s", error->message);
 		}
+		g_error_free (error);
 
-		g_free (reason);
-		g_free (application);
+		return;
+	}
 
-	} else {
-		res = dbus_g_proxy_call (scr->priv->gs_proxy,
-					 "UnInhibit",
-					 &error,
-					 G_TYPE_UINT, scr->priv->cookie,
-					 G_TYPE_INVALID,
-					 G_TYPE_INVALID);
-		if (res) {
-			/* clear the cookie */
-			scr->priv->cookie = 0;
-		} else {
+	/* save the cookie */
+	if (g_variant_is_of_type (value, G_VARIANT_TYPE ("(u)")))
+		g_variant_get (value, "(u)", &scr->priv->cookie);
+	else
+		scr->priv->cookie = 0;
+	g_variant_unref (value);
+}
+
+static void
+on_uninhibit_cb (GObject      *source_object,
+		 GAsyncResult *res,
+		 gpointer      user_data)
+{
+	GDBusProxy    *proxy = G_DBUS_PROXY (source_object);
+	TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
+	GVariant      *value;
+	GError        *error = NULL;
+
+	value = g_dbus_proxy_call_finish (proxy, res, &error);
+	if (!value) {
+		if (!scr->priv->old_dbus_api &&
+		    g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
 			/* try the old API */
-			res = dbus_g_proxy_call (scr->priv->gs_proxy,
-						 "AllowActivation",
-						 NULL,
-						 G_TYPE_INVALID,
-						 G_TYPE_INVALID);
-			if (res)
-				g_error_free (error);
+			scr->priv->old_dbus_api = TRUE;
+			g_dbus_proxy_call (proxy,
+					   "AllowActivation",
+					   g_variant_new ("()"),
+					   G_DBUS_CALL_FLAGS_NO_AUTO_START,
+					   -1,
+					   NULL,
+					   on_uninhibit_cb,
+					   scr);
+		} else {
+			g_warning ("Problem uninhibiting the screensaver: %s", error->message);
 		}
+		g_error_free (error);
+
+		return;
 	}
 
-	if (! res) {
-		if (error) {
-			g_warning ("Problem inhibiting the screensaver: %s", error->message);
-			g_error_free (error);
-		}
+	/* clear the cookie */
+	scr->priv->cookie = 0;
+	g_variant_unref (value);
+}
+
+static void
+screensaver_inhibit_dbus (TotemScrsaver *scr,
+			  gboolean	 inhibit)
+{
+        TotemScrsaverPrivate *priv = scr->priv;
+
+        if (!priv->have_screensaver_dbus)
+                return;
+
+	scr->priv->old_dbus_api = FALSE;
+
+	if (inhibit) {
+		g_return_if_fail (scr->priv->reason != NULL);
+		g_dbus_proxy_call (priv->gs_proxy,
+				   "Inhibit",
+				   g_variant_new ("(ss)",
+						  g_get_application_name (),
+						  scr->priv->reason),
+				   G_DBUS_CALL_FLAGS_NO_AUTO_START,
+				   -1,
+				   NULL,
+				   on_inhibit_cb,
+				   scr);
+	} else {
+                g_dbus_proxy_call (priv->gs_proxy,
+				   "UnInhibit",
+				   g_variant_new ("(u)", priv->cookie),
+				   G_DBUS_CALL_FLAGS_NO_AUTO_START,
+				   -1,
+				   NULL,
+				   on_uninhibit_cb,
+				   scr);
 	}
-#endif /* HAVE_DBUS */
 }
 
 static void
@@ -184,62 +212,66 @@ screensaver_disable_dbus (TotemScrsaver *scr)
 	screensaver_inhibit_dbus (scr, TRUE);
 }
 
-#ifdef HAVE_DBUS
 static void
-gs_proxy_destroy_cb (GObject *proxy,
-		     TotemScrsaver *scr)
+screensaver_dbus_appeared_cb (GDBusConnection *connection,
+			      const gchar     *name,
+			      const gchar     *name_owner,
+			      GDBusProxy      *proxy,
+			      gpointer         user_data)
 {
-	g_warning ("Detected that GNOME screensaver has left the bus");
+        TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
+        TotemScrsaverPrivate *priv = scr->priv;
+
+	priv->gs_proxy = g_object_ref (proxy);
 
-	/* just invalidate for now */
-	scr->priv->gs_proxy = NULL;
+        priv->have_screensaver_dbus = TRUE;
 }
-#endif
 
-#ifdef HAVE_DBUS
 static void
-screensaver_init_dbus (TotemScrsaver *scr, DBusGConnection *connection)
+screensaver_dbus_disappeared_cb (GDBusConnection *connection,
+				 const gchar     *name,
+				 gpointer         user_data)
 {
-	GError *error = NULL;
+        TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
+        TotemScrsaverPrivate *priv = scr->priv;
 
-	if (!connection)
-		scr->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-	else
-		scr->priv->connection = connection;
-
-	if (! scr->priv->connection) {
-		if (error) {
-			g_warning ("Failed to connect to the session bus: %s", error->message);
-			g_error_free (error);
-		}
-		return;
+	if (priv->gs_proxy) {
+		g_object_unref (priv->gs_proxy);
+		priv->gs_proxy = NULL;
 	}
 
-	scr->priv->gs_proxy = dbus_g_proxy_new_for_name_owner (scr->priv->connection,
-							       GS_SERVICE,
-							       GS_PATH,
-							       GS_INTERFACE,
-							       NULL);
-	if (scr->priv->gs_proxy != NULL) {
-		g_signal_connect_object (scr->priv->gs_proxy,
-					 "destroy",
-					 G_CALLBACK (gs_proxy_destroy_cb),
-					 scr,
-					 0);
-
-	}
+        priv->have_screensaver_dbus = FALSE;
+}
 
+static void
+screensaver_init_dbus (TotemScrsaver *scr)
+{
+	TotemScrsaverPrivate *priv = scr->priv;
+
+        priv->watch_id = g_bus_watch_proxy (G_BUS_TYPE_SESSION,
+					    GS_SERVICE,
+					    G_BUS_NAME_WATCHER_FLAGS_NONE,
+					    GS_PATH,
+					    GS_INTERFACE,
+					    G_TYPE_DBUS_PROXY,
+					    G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+					    G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+					    screensaver_dbus_appeared_cb,
+					    screensaver_dbus_disappeared_cb,
+					    scr, NULL);
 }
-#endif /* HAVE_DBUS */
 
 static void
 screensaver_finalize_dbus (TotemScrsaver *scr)
 {
-#ifdef HAVE_DBUS
+        TotemScrsaverPrivate *priv = scr->priv;
+
 	if (scr->priv->gs_proxy) {
 		g_object_unref (scr->priv->gs_proxy);
 	}
-#endif /* HAVE_DBUS */
+
+	if (priv->watch_id > 0)
+		g_bus_unwatch_proxy (priv->watch_id);
 }
 
 #ifdef GDK_WINDOWING_X11
@@ -358,42 +390,87 @@ screensaver_finalize_x11 (TotemScrsaver *scr)
 #endif
 
 static void
+totem_scrsaver_get_property (GObject *object,
+			     guint property_id,
+			     GValue *value,
+			     GParamSpec *pspec)
+{
+	TotemScrsaver *scr;
+
+	scr = TOTEM_SCRSAVER (object);
+
+	switch (property_id)
+	{
+	case PROP_REASON:
+		g_value_set_string (value, scr->priv->reason);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+	}
+}
+
+static void
+totem_scrsaver_set_property (GObject *object,
+			     guint property_id,
+			     const GValue *value,
+			     GParamSpec *pspec)
+{
+	TotemScrsaver *scr;
+
+	scr = TOTEM_SCRSAVER (object);
+
+	switch (property_id)
+	{
+	case PROP_REASON:
+		g_free (scr->priv->reason);
+		scr->priv->reason = g_value_dup_string (value);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+	}
+}
+
+static void
 totem_scrsaver_class_init (TotemScrsaverClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-	parent_class = g_type_class_peek_parent (klass);
+	g_type_class_add_private (klass, sizeof (TotemScrsaverPrivate));
 
+	object_class->set_property = totem_scrsaver_set_property;
+	object_class->get_property = totem_scrsaver_get_property;
 	object_class->finalize = totem_scrsaver_finalize;
-}
 
-#ifdef HAVE_DBUS
-TotemScrsaver *
-totem_scrsaver_new	(DBusGConnection *connection)
-{
-	TotemScrsaver * scr;
-	scr = TOTEM_SCRSAVER (g_object_new (TOTEM_TYPE_SCRSAVER, NULL));
+	g_object_class_install_property (object_class, PROP_REASON,
+					 g_param_spec_string ("reason", NULL, NULL,
+							      NULL, G_PARAM_READWRITE));
 
-	screensaver_init_dbus (scr, connection);
-	
-	return scr;
 }
-#else
+
+/**
+ * totem_scrsaver_new:
+ *
+ * Creates a #TotemScrsaver object.
+ * If the GNOME screen saver is running, it uses its DBUS interface to
+ * inhibit the screensaver; otherwise it falls back to using the X
+ * screensaver functionality for this.
+ *
+ * Returns: a newly created #TotemScrsaver
+ */
 TotemScrsaver *
-totem_scrsaver_new()
+totem_scrsaver_new (void)
 {
-	TotemScrsaver * scr;
-	scr = TOTEM_SCRSAVER (g_object_new (TOTEM_TYPE_SCRSAVER, NULL));
-	
-	return scr;
+	return TOTEM_SCRSAVER (g_object_new (TOTEM_TYPE_SCRSAVER, NULL));
 }
-#endif
 
 static void
 totem_scrsaver_init (TotemScrsaver *scr)
 {
-	scr->priv = g_new0 (TotemScrsaverPrivate, 1);
+	scr->priv = G_TYPE_INSTANCE_GET_PRIVATE (scr,
+						 TOTEM_TYPE_SCRSAVER,
+						 TotemScrsaverPrivate);
 
+	screensaver_init_dbus (scr);
 #ifdef GDK_WINDOWING_X11
 	screensaver_init_x11 (scr);
 #else
@@ -434,7 +511,7 @@ totem_scrsaver_enable (TotemScrsaver *scr)
 
 	if (screensaver_is_running_dbus (scr) != FALSE)
 		screensaver_enable_dbus (scr);
-	else 
+	else
 #ifdef GDK_WINDOWING_X11
 		screensaver_enable_x11 (scr);
 #else
@@ -462,6 +539,8 @@ totem_scrsaver_finalize (GObject *object)
 {
 	TotemScrsaver *scr = TOTEM_SCRSAVER (object);
 
+	g_free (scr->priv->reason);
+
 	screensaver_finalize_dbus (scr);
 #ifdef GDK_WINDOWING_X11
 	screensaver_finalize_x11 (scr);
@@ -470,10 +549,5 @@ totem_scrsaver_finalize (GObject *object)
 	{}
 #endif
 
-	g_free (scr->priv);
-
-	if (G_OBJECT_CLASS (parent_class)->finalize != NULL) {
-		(* G_OBJECT_CLASS (parent_class)->finalize) (object);
-	}
+        G_OBJECT_CLASS (totem_scrsaver_parent_class)->finalize (object);
 }
-
diff --git a/cut-n-paste/totem-screensaver/totem-scrsaver.h b/cut-n-paste/totem-screensaver/totem-scrsaver.h
index 6a0af34..f3301c8 100644
--- a/cut-n-paste/totem-screensaver/totem-scrsaver.h
+++ b/cut-n-paste/totem-screensaver/totem-scrsaver.h
@@ -19,15 +19,12 @@
    Author: Bastien Nocera <hadess hadess net>
  */
 
-#ifndef __TOTEM_SCRSAVER_H__
-#define __TOTEM_SCRSAVER_H__
+#ifndef TOTEM_SCRSAVER_H
+#define TOTEM_SCRSAVER_H
 
-#include <glib.h>
 #include <glib-object.h>
 
-#ifdef HAVE_DBUS
-#include <dbus/dbus-glib.h>
-#endif
+G_BEGIN_DECLS
 
 #define TOTEM_TYPE_SCRSAVER		(totem_scrsaver_get_type ())
 #define TOTEM_SCRSAVER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOTEM_TYPE_SCRSAVER, TotemScrsaver))
@@ -35,7 +32,6 @@
 #define TOTEM_IS_SCRSAVER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOTEM_TYPE_SCRSAVER))
 #define TOTEM_IS_SCRSAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOTEM_TYPE_SCRSAVER))
 
-
 typedef struct TotemScrsaver TotemScrsaver;
 typedef struct TotemScrsaverClass TotemScrsaverClass;
 typedef struct TotemScrsaverPrivate TotemScrsaverPrivate;
@@ -46,18 +42,16 @@ struct TotemScrsaver {
 };
 
 struct TotemScrsaverClass {
-	GObjectClass parent_class; 
+	GObjectClass parent_class;
 };
 
-GType totem_scrsaver_get_type		(void);
-#ifdef HAVE_DBUS
-TotemScrsaver *totem_scrsaver_new	(DBusGConnection *connection);
-#else
-TotemScrsaver *totem_scrsaver_new	();
-#endif
+GType totem_scrsaver_get_type		(void) G_GNUC_CONST;
+TotemScrsaver *totem_scrsaver_new       (void);
 void totem_scrsaver_enable		(TotemScrsaver *scr);
 void totem_scrsaver_disable		(TotemScrsaver *scr);
 void totem_scrsaver_set_state		(TotemScrsaver *scr,
 					 gboolean enable);
 
-#endif /* __TOTEM_SCRSAVER_H__ */
+G_END_DECLS
+
+#endif /* !TOTEM_SCRSAVER_H */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 76b69d5..46e25a7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,7 +3,6 @@
 [encoding: UTF-8]
 cut-n-paste/toolbar-editor/egg-editable-toolbar.c
 cut-n-paste/toolbar-editor/egg-toolbar-editor.c
-cut-n-paste/totem-screensaver/totem-scrsaver.c
 plugins/fullscreen/fullscreen.eog-plugin.desktop.in
 plugins/fullscreen/eog-fullscreen-plugin.c
 plugins/reload/reload.eog-plugin.desktop.in
diff --git a/src/eog-application.c b/src/eog-application.c
index d24ffea..d2074c8 100644
--- a/src/eog-application.c
+++ b/src/eog-application.c
@@ -118,7 +118,10 @@ eog_application_register_service (EogApplication *application)
 					     "/org/gnome/eog/Eog",
                                              G_OBJECT (application));
 
-        application->scr_saver = totem_scrsaver_new (connection);
+        application->scr_saver = totem_scrsaver_new ();
+        g_object_set (application->scr_saver,
+		      "reason", _("Running in fullscreen mode"),
+		      NULL);
 
 	return TRUE;
 }



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