[totem] galago: Rename to im-status and use gnome-session



commit ddfe98fba2418002ef19a0097aa0c025747c4218
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Feb 23 14:06:04 2011 +0000

    galago: Rename to im-status and use gnome-session
    
    No need for the galago stack any more, we'll use gnome-session's
    Presence API instead.

 configure.in                                       |   12 +-
 po/POTFILES.in                                     |    4 +-
 src/plugins/galago/Makefile.am                     |   17 --
 src/plugins/galago/totem-galago.c                  |  162 ----------------
 src/plugins/im-status/Makefile.am                  |   15 ++
 src/plugins/im-status/totem-im-status.c            |  203 ++++++++++++++++++++
 .../totem-im-status.plugin.in}                     |    4 +-
 7 files changed, 224 insertions(+), 193 deletions(-)
---
diff --git a/configure.in b/configure.in
index c7ff11e..1831688 100644
--- a/configure.in
+++ b/configure.in
@@ -68,7 +68,7 @@ AC_SUBST(TOTEM_API_VERSION)
 AC_DEFINE_UNQUOTED(TOTEM_API_VERSION, ["$TOTEM_API_VERSION"], [Define to the Totem plugin API version])
 
 # The full list of plugins
-allowed_plugins="bemused brasero-disc-recorder chapters coherence_upnp dbus-service galago gromit iplayer jamendo lirc media-player-keys ontop opensubtitles properties publish pythonconsole save-file sample-python sample-vala screensaver screenshot sidebar-test skipto thumbnail tracker youtube zeitgeist-dp"
+allowed_plugins="bemused brasero-disc-recorder chapters coherence_upnp dbus-service im-status gromit iplayer jamendo lirc media-player-keys ontop opensubtitles properties publish pythonconsole save-file sample-python sample-vala screensaver screenshot sidebar-test skipto thumbnail tracker youtube zeitgeist-dp"
 
 PLUGINDIR='${libdir}/totem/plugins'
 AC_SUBST(PLUGINDIR)
@@ -399,14 +399,6 @@ for plugin in ${used_plugins}; do
 			plugin_error_or_ignore "the coherence_upnp plugin uses PyGTK and conflicts with the new pygobject bindings"
 			add_plugin="0"
 		;;
-		galago)
-			PKG_CHECK_MODULES(LIBGALAGO, libgalago >= 0.5.2,
-				[HAVE_LIBGALAGO=yes], [HAVE_LIBGALAGO=no])
-			if test "${HAVE_LIBGALAGO}" != "yes" ; then
-				plugin_error_or_ignore "you need libgalago >= 0.5.2 installed for the galago plugin"
-				add_plugin="0"
-			fi
-		;;
 		gromit)
 			if test "${have_x11}" != "yes" ; then
 				plugin_error_or_ignore "the gromit plugin is not supported on non-X11 targets"
@@ -786,7 +778,7 @@ src/plugins/dbus-service/Makefile
 src/plugins/screensaver/Makefile
 src/plugins/screenshot/Makefile
 src/plugins/ontop/Makefile
-src/plugins/galago/Makefile
+src/plugins/im-status/Makefile
 src/plugins/gromit/Makefile
 src/plugins/iplayer/Makefile
 src/plugins/lirc/Makefile
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 77a30ab..93771c5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -49,8 +49,8 @@ src/plugins/chapters/totem-cmml-parser.c
 src/plugins/coherence_upnp/coherence_upnp.py
 [type: gettext/ini]src/plugins/coherence_upnp/coherence_upnp.plugin.in
 [type: gettext/ini]src/plugins/dbus-service/dbus-service.plugin.in
-[type: gettext/ini]src/plugins/galago/galago.plugin.in
-src/plugins/galago/totem-galago.c
+[type: gettext/ini]src/plugins/im-status/totem-im-status.plugin.in
+src/plugins/im-status/totem-im-status.c
 [type: gettext/ini]src/plugins/gromit/gromit.plugin.in
 src/plugins/gromit/totem-gromit.c
 [type: gettext/ini]src/plugins/iplayer/iplayer.plugin.in
diff --git a/src/plugins/im-status/Makefile.am b/src/plugins/im-status/Makefile.am
new file mode 100644
index 0000000..fe28da5
--- /dev/null
+++ b/src/plugins/im-status/Makefile.am
@@ -0,0 +1,15 @@
+include $(top_srcdir)/src/plugins/Makefile.plugins
+
+plugindir = $(PLUGINDIR)/im-status
+plugin_LTLIBRARIES = libtotem-im-status.la
+
+plugin_in_files = totem-im-status.plugin.in
+
+libtotem_im_status_la_SOURCES = totem-im-status.c
+libtotem_im_status_la_LDFLAGS = $(plugin_ldflags)
+libtotem_im_status_la_LIBADD = \
+	$(plugin_libadd)
+libtotem_im_status_la_CFLAGS = \
+	$(plugin_cflags)
+
+-include $(top_srcdir)/git.mk
diff --git a/src/plugins/im-status/totem-im-status.c b/src/plugins/im-status/totem-im-status.c
new file mode 100644
index 0000000..c2ddc7f
--- /dev/null
+++ b/src/plugins/im-status/totem-im-status.c
@@ -0,0 +1,203 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2007, 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+ *
+ * The Totem project hereby grant permission for non-gpl compatible GStreamer
+ * plugins to be used and distributed together with GStreamer and Totem. This
+ * permission are above and beyond the permissions granted by the GPL license
+ * Totem is covered by.
+ *
+ * See license_change file for details.
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n-lib.h>
+#include <string.h>
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
+#include <libpeas/peas-activatable.h>
+
+#include "totem.h"
+#include "totem-interface.h"
+#include "totem-plugin.h"
+
+#define TOTEM_TYPE_IM_STATUS_PLUGIN		(totem_im_status_plugin_get_type ())
+#define TOTEM_IM_STATUS_PLUGIN(o)			(G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_IM_STATUS_PLUGIN, TotemImStatusPlugin))
+#define TOTEM_IM_STATUS_PLUGIN_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), TOTEM_TYPE_IM_STATUS_PLUGIN, TotemImStatusPluginClass))
+#define TOTEM_IS_IM_STATUS_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), TOTEM_TYPE_IM_STATUS_PLUGIN))
+#define TOTEM_IS_IM_STATUS_PLUGIN_CLASS(k)		(G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_IM_STATUS_PLUGIN))
+#define TOTEM_IM_STATUS_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_IM_STATUS_PLUGIN, TotemImStatusPluginClass))
+
+typedef struct {
+	guint		handler_id_fullscreen;
+	guint		handler_id_playing;
+	GCancellable   *cancellable;
+	gboolean	idle; /* Whether we're idle */
+	GDBusProxy     *proxy;
+} TotemImStatusPluginPrivate;
+
+enum {
+	STATUS_AVAILABLE = 0,
+	STATUS_INVISIBLE = 1,
+	STATUS_BUSY      = 2,
+	STATUS_IDLE      = 3
+};
+
+TOTEM_PLUGIN_REGISTER (TOTEM_TYPE_IM_STATUS_PLUGIN, TotemImStatusPlugin, totem_im_status_plugin);
+
+static void
+totem_im_status_set_idleness (TotemImStatusPlugin *pi,
+			      gboolean             idle)
+{
+	GVariant *variant;
+	GError *error = NULL;
+
+	if (pi->priv->idle == idle)
+		return;
+
+	pi->priv->idle = idle;
+	variant = g_dbus_proxy_call_sync (pi->priv->proxy,
+					  "SetStatus",
+					  g_variant_new ("(u)", idle ? STATUS_IDLE : STATUS_AVAILABLE),
+					  G_DBUS_CALL_FLAGS_NONE,
+					  -1,
+					  NULL,
+					  &error);
+	if (variant == NULL) {
+		g_warning ("Failed to set presence: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_variant_unref (variant);
+}
+
+static void
+totem_im_status_update_from_state (TotemObject         *totem,
+				   TotemImStatusPlugin *pi)
+{
+	/* Session Proxy not ready yet */
+	if (pi->priv->proxy == NULL)
+		return;
+
+	if (totem_is_playing (totem) != FALSE
+	    && totem_is_fullscreen (totem) != FALSE) {
+		totem_im_status_set_idleness (pi, TRUE);
+	} else {
+		totem_im_status_set_idleness (pi, FALSE);
+	}
+}
+
+static void
+property_notify_cb (TotemObject         *totem,
+		    GParamSpec          *spec,
+		    TotemImStatusPlugin *plugin)
+{
+	totem_im_status_update_from_state (totem, plugin);
+}
+
+static void
+got_proxy_cb (GObject             *source_object,
+	      GAsyncResult        *res,
+	      TotemImStatusPlugin *pi)
+{
+	GError *error = NULL;
+	TotemObject *totem;
+
+	pi->priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
+
+	g_object_unref (pi->priv->cancellable);
+	pi->priv->cancellable = NULL;
+
+	if (pi->priv->proxy == NULL) {
+		g_warning ("Failed to contact session manager: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_object_get (pi, "object", &totem, NULL);
+	totem_im_status_update_from_state (totem, pi);
+	g_object_unref (totem);
+}
+
+static void
+impl_activate (PeasActivatable *plugin)
+{
+	TotemImStatusPlugin *pi = TOTEM_IM_STATUS_PLUGIN (plugin);
+	TotemObject *totem;
+
+	pi->priv->cancellable = g_cancellable_new ();
+	g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+				  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+				  G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+				  NULL,
+				  "org.gnome.SessionManager",
+				  "/org/gnome/SessionManager/Presence",
+				  "org.gnome.SessionManager.Presence",
+				  pi->priv->cancellable,
+				  (GAsyncReadyCallback) got_proxy_cb,
+				  pi);
+
+	g_object_get (plugin, "object", &totem, NULL);
+
+	pi->priv->handler_id_fullscreen = g_signal_connect (G_OBJECT (totem),
+				"notify::fullscreen",
+				G_CALLBACK (property_notify_cb),
+				pi);
+	pi->priv->handler_id_playing = g_signal_connect (G_OBJECT (totem),
+				"notify::playing",
+				G_CALLBACK (property_notify_cb),
+				pi);
+
+	g_object_unref (totem);
+}
+
+static void
+impl_deactivate (PeasActivatable *plugin)
+{
+	TotemImStatusPlugin *pi = TOTEM_IM_STATUS_PLUGIN (plugin);
+	TotemObject *totem;
+
+	/* In flight? */
+	if (pi->priv->cancellable != NULL) {
+		g_cancellable_cancel (pi->priv->cancellable);
+		g_object_unref (pi->priv->cancellable);
+		pi->priv->cancellable = NULL;
+	}
+
+	if (pi->priv->proxy != NULL) {
+		g_object_unref (pi->priv->proxy);
+		pi->priv->proxy = NULL;
+	}
+
+	g_object_get (plugin, "object", &totem, NULL);
+
+	if (pi->priv->handler_id_fullscreen != 0) {
+		g_signal_handler_disconnect (G_OBJECT (totem),
+					     pi->priv->handler_id_fullscreen);
+		pi->priv->handler_id_fullscreen = 0;
+	}
+	if (pi->priv->handler_id_playing != 0) {
+		g_signal_handler_disconnect (G_OBJECT (totem),
+					     pi->priv->handler_id_playing);
+		pi->priv->handler_id_playing = 0;
+	}
+
+	g_object_unref (totem);
+}
diff --git a/src/plugins/galago/galago.plugin.in b/src/plugins/im-status/totem-im-status.plugin.in
similarity index 71%
rename from src/plugins/galago/galago.plugin.in
rename to src/plugins/im-status/totem-im-status.plugin.in
index ad8fa24..dff223f 100644
--- a/src/plugins/galago/galago.plugin.in
+++ b/src/plugins/im-status/totem-im-status.plugin.in
@@ -1,9 +1,9 @@
 [Plugin]
-Module=tgp
+Module=totem-im-status
 IAge=1
 Builtin=false
 _Name=Instant Messenger status
 _Description=Set your Instant Messenger status to away when a movie is playing
 Authors=Bastien Nocera, Philip Withnall
-Copyright=Copyright © 2007 Bastien Nocera, Philip Withnall
+Copyright=Copyright © 2007, 2011 Bastien Nocera, Philip Withnall
 Website=http://www.gnome.org/projects/totem/



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