totem r5032 - in trunk: . src src/plugins/thumbnail



Author: hadess
Date: Mon Jan 21 15:02:28 2008
New Revision: 5032
URL: http://svn.gnome.org/viewvc/totem?rev=5032&view=rev

Log:
2008-01-21  Bastien Nocera  <hadess hadess net>

	Patch from Patrick Hulin <patrick hulin gmail com>

	* src/totem-object.c: (totem_object_class_init),
	(totem_object_set_property), (totem_object_get_property):
	Add current-mrl property which gets/sets the current MRL
	that Totem is playing

	* configure.in:
	* src/plugins/thumbnail/*: Add the thumbnail plugin to show
	the currently playing file's thumbnail as the window icon
	(Closes: #407513)



Added:
   trunk/src/plugins/thumbnail/
   trunk/src/plugins/thumbnail/Makefile.am
   trunk/src/plugins/thumbnail/thumbnail.totem-plugin.in
   trunk/src/plugins/thumbnail/totem-thumbnail.c
Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/src/totem-object.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Mon Jan 21 15:02:28 2008
@@ -49,7 +49,7 @@
 AC_SUBST(TOTEM_VERSION_MICRO)
 
 # The full list of plugins
-allowed_plugins="screensaver ontop galago gromit lirc media-player-keys mythtv properties sidebar-test skipto sample-python sample-vala bemused youtube publish tracker"
+allowed_plugins="thumbnail screensaver ontop galago gromit lirc media-player-keys mythtv properties sidebar-test skipto sample-python sample-vala bemused youtube publish tracker"
 
 PLUGINDIR='${libdir}/totem/plugins'
 AC_SUBST(PLUGINDIR)
@@ -533,6 +533,14 @@
 				add_plugin="0"
 			fi
 		;;
+		thumbnail)
+			PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.15.0,
+				[HAVE_GLIB_2_15=yes], [HAVE_GLIB_2_15=no])
+			if test "${HAVE_GLIB_2_15}" != "yes" ; then
+				plugin_error_or_ignore "you need glib >= 2.15.0 to use the thumbnail plugin"
+				add_plugin="0"
+			fi
+		;;
 	esac
 
 	# Add the specified plugin
@@ -1025,6 +1033,7 @@
 src/plugins/skipto/Makefile
 src/plugins/sample-python/Makefile
 src/plugins/sample-vala/Makefile
+src/plugins/thumbnail/Makefile
 src/plugins/totem/Makefile
 src/plugins/tracker/Makefile
 src/plugins/youtube/Makefile

Added: trunk/src/plugins/thumbnail/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/src/plugins/thumbnail/Makefile.am	Mon Jan 21 15:02:28 2008
@@ -0,0 +1,42 @@
+modules_flags = -export_dynamic -avoid-version -module
+
+plugindir = $(PLUGINDIR)/thumbnail
+plugin_LTLIBRARIES = libthumbnail.la
+
+plugin_in_files = thumbnail.totem-plugin.in
+
+%.totem-plugin: %.totem-plugin.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+
+plugin_DATA = $(plugin_in_files:.totem-plugin.in=.totem-plugin)
+
+common_defines = \
+	-D_REENTRANT					\
+	-DDBUS_API_SUBJECT_TO_CHANGE			\
+	-DGNOMELOCALEDIR=\""$(datadir)/locale"\"	\
+	-DGCONF_PREFIX=\""/apps/totem"\"		\
+	-DDATADIR=\""$(datadir)"\"			\
+	-DLIBEXECDIR=\""$(libexecdir)"\"		\
+	-DBINDIR=\""$(bindir)"\"			\
+	-DTOTEM_PLUGIN_DIR=\""$(libdir)/totem/plugins"\"\
+	$(DISABLE_DEPRECATED)
+
+libthumbnail_la_SOURCES = totem-thumbnail.c
+libthumbnail_la_LDFLAGS = $(modules_flags)
+libthumbnail_la_LIBADD = 
+libthumbnail_la_CPPFLAGS = $(common_defines)
+
+libthumbnail_la_CFLAGS = \
+	$(EXTRA_GNOME_CFLAGS)	\
+	$(WARN_CFLAGS)		\
+	$(DBUS_CFLAGS)		\
+	$(AM_CFLAGS)		\
+	-I$(top_srcdir)/	\
+	-I$(top_srcdir)/lib	\
+	-I$(top_srcdir)/src	\
+	-I$(top_srcdir)/src/plugins
+
+EXTRA_DIST = $(plugin_in_files)
+
+CLEANFILES = $(plugin_DATA) $(BUILT_SOURCES)
+DISTCLEANFILES = $(plugin_DATA)
+

Added: trunk/src/plugins/thumbnail/thumbnail.totem-plugin.in
==============================================================================
--- (empty file)
+++ trunk/src/plugins/thumbnail/thumbnail.totem-plugin.in	Mon Jan 21 15:02:28 2008
@@ -0,0 +1,8 @@
+[Totem Plugin]
+Module=thumbnail
+IAge=1
+_Name=Thumbnail
+_Description=Set the window icon to the thumbnail of the playing movie
+Authors=Patrick Hulin
+Copyright=Copyright  2007 Patrick Hulin
+Website=http://www.gnome.org/projects/totem/

Added: trunk/src/plugins/thumbnail/totem-thumbnail.c
==============================================================================
--- (empty file)
+++ trunk/src/plugins/thumbnail/totem-thumbnail.c	Mon Jan 21 15:02:28 2008
@@ -0,0 +1,216 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* 
+ * Copyright (C) 2007 Patrick Hulin <patrick hulin gmail com>
+ *
+ * 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.
+ *
+ * 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 <gmodule.h>
+#include <string.h>
+
+#include "totem-plugin.h"
+#include "totem.h"
+
+#define TOTEM_TYPE_THUMBNAIL_PLUGIN		(totem_thumbnail_plugin_get_type ())
+#define TOTEM_THUMBNAIL_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_THUMBNAIL_PLUGIN, TotemThumbnailPlugin))
+#define TOTEM_THUMBNAIL_PLUGIN_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), TOTEM_TYPE_THUMBNAIL_PLUGIN, TotemThumbnailPluginClass))
+#define TOTEM_IS_THUMBNAIL_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), TOTEM_TYPE_THUMBNAIL_PLUGIN))
+#define TOTEM_IS_THUMBNAIL_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_THUMBNAIL_PLUGIN))
+#define TOTEM_THUMBNAIL_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_THUMBNAIL_PLUGIN, TotemThumbnailPluginClass))
+
+typedef struct
+{
+	guint file_closed_handler_id;
+	guint file_opened_handler_id;
+	GtkWindow *window;
+	TotemObject *totem;
+} TotemThumbnailPluginPrivate;
+
+typedef struct
+{
+	TotemPlugin parent;
+	TotemThumbnailPluginPrivate *priv;
+} TotemThumbnailPlugin;
+
+typedef struct
+{
+	TotemPluginClass parent_class;
+} TotemThumbnailPluginClass;
+
+G_MODULE_EXPORT GType register_totem_plugin	(GTypeModule *module);
+GType totem_thumbnail_plugin_get_type		(void) G_GNUC_CONST;
+
+static void totem_thumbnail_plugin_init		(TotemThumbnailPlugin *plugin);
+static gboolean impl_activate			(TotemPlugin *plugin, TotemObject *totem, GError **error);
+static void impl_deactivate			(TotemPlugin *plugin, TotemObject *totem);
+
+TOTEM_PLUGIN_REGISTER (TotemThumbnailPlugin, totem_thumbnail_plugin)
+
+static void
+totem_thumbnail_plugin_class_init (TotemThumbnailPluginClass *klass)
+{
+	TotemPluginClass *plugin_class = TOTEM_PLUGIN_CLASS (klass);
+
+	g_type_class_add_private (klass, sizeof (TotemThumbnailPluginPrivate));
+
+	plugin_class->activate = impl_activate;
+	plugin_class->deactivate = impl_deactivate;
+}
+
+static void
+totem_thumbnail_plugin_init (TotemThumbnailPlugin *plugin)
+{
+	plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin,
+						    TOTEM_TYPE_THUMBNAIL_PLUGIN,
+						    TotemThumbnailPluginPrivate);
+}
+
+static void
+set_icon_to_default (TotemObject *totem)
+{
+	GtkWindow *window = NULL;
+	g_return_if_fail (TOTEM_IS_OBJECT (totem));
+
+	window = totem_get_main_window (totem);
+	gtk_window_set_icon_name (window, "totem");
+}
+
+static void
+update_from_state (TotemThumbnailPluginPrivate *priv,
+		   TotemObject *totem,
+		   const char *mrl)
+{
+	GdkPixbuf *pixbuf = NULL;
+	GtkWindow *window = NULL;
+	char *file_basename, *file_name, *uri_md5;
+	GError *err = NULL;
+
+	g_return_if_fail (TOTEM_IS_OBJECT (totem));
+	window = totem_get_main_window (totem);
+
+	if (mrl == NULL) {
+		set_icon_to_default (totem);
+		return;
+	}
+
+	uri_md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5,
+						 mrl,
+						 strlen (mrl));
+	file_basename = g_strdup_printf ("%s.png", uri_md5);
+	file_name = g_build_filename (g_get_home_dir (),
+				      ".thumbnails",
+				      "normal",
+				      file_basename,
+				      NULL);
+
+	pixbuf = gdk_pixbuf_new_from_file (file_name, &err);
+	if (pixbuf == NULL && err != NULL && err->domain == G_FILE_ERROR) {
+		g_clear_error (&err);
+		g_free (file_name);
+		file_name= g_build_filename (g_get_home_dir (),
+					     ".thumbnails",
+					     "normal",
+					     file_basename,
+					     NULL);
+
+		pixbuf = gdk_pixbuf_new_from_file (file_name, &err);
+	}
+
+	g_free (uri_md5);
+	g_free (file_basename);
+	g_free (file_name);
+
+	if (pixbuf == NULL) {
+		if (err != NULL && err->domain != G_FILE_ERROR) {
+			g_printerr ("%s\n", err->message);
+		}
+		set_icon_to_default (totem);
+		return;
+	}
+
+	gtk_window_set_icon (window, pixbuf);
+
+	g_object_unref (pixbuf);
+}
+
+static void
+file_opened_cb (TotemObject *totem,
+		const char *mrl,
+		TotemThumbnailPlugin *pi)
+{
+	update_from_state (pi->priv, totem, mrl);
+}
+
+static void
+file_closed_cb (TotemObject *totem,
+		 TotemThumbnailPlugin *pi)
+{
+	update_from_state (pi->priv, totem, NULL);
+}
+
+static gboolean
+impl_activate (TotemPlugin *plugin,
+	       TotemObject *totem,
+	       GError **error)
+{
+	TotemThumbnailPlugin *pi = TOTEM_THUMBNAIL_PLUGIN (plugin);
+	char *mrl;
+
+	pi->priv->window = totem_get_main_window (totem);
+	pi->priv->totem = totem;
+
+	pi->priv->file_opened_handler_id = g_signal_connect (G_OBJECT (totem),
+							     "file-opened",
+							     G_CALLBACK (file_opened_cb),
+							     pi);
+	pi->priv->file_closed_handler_id = g_signal_connect (G_OBJECT (totem),
+							     "file-closed",
+							     G_CALLBACK (file_closed_cb),
+							     pi);
+
+	g_object_get (totem, "current-mrl", &mrl, NULL);
+
+	update_from_state (pi->priv, totem, mrl);
+
+	g_free (mrl);
+
+	return TRUE;
+}
+
+static void
+impl_deactivate (TotemPlugin *plugin,
+		 TotemObject *totem)
+{
+	TotemThumbnailPlugin *pi = TOTEM_THUMBNAIL_PLUGIN (plugin);
+
+	g_signal_handler_disconnect (totem, pi->priv->file_opened_handler_id);
+	g_signal_handler_disconnect (totem, pi->priv->file_closed_handler_id);
+
+	set_icon_to_default (totem);
+}
+

Modified: trunk/src/totem-object.c
==============================================================================
--- trunk/src/totem-object.c	(original)
+++ trunk/src/totem-object.c	Mon Jan 21 15:02:28 2008
@@ -45,7 +45,8 @@
 	PROP_STREAM_LENGTH,
 	PROP_SEEKABLE,
 	PROP_CURRENT_TIME,
-	PROP_ERROR_SHOWN
+	PROP_ERROR_SHOWN,
+	PROP_CURRENT_MRL
 };
 
 enum {
@@ -100,6 +101,9 @@
 	g_object_class_install_property (object_class, PROP_ERROR_SHOWN,
 					 g_param_spec_boolean ("error-shown", NULL, NULL,
 							       FALSE, G_PARAM_READABLE));
+	g_object_class_install_property (object_class, PROP_CURRENT_MRL,
+					 g_param_spec_string ("current-mrl", NULL, NULL,
+							      NULL, G_PARAM_READABLE));
 
 	totem_table_signals[FILE_OPENED] =
 		g_signal_new ("file-opened",
@@ -181,6 +185,9 @@
 	case PROP_ERROR_SHOWN:
 		//g_value_set_boolean (value, XXX);
 		break;
+	case PROP_CURRENT_MRL:
+		g_value_set_string (value, totem->mrl);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 	}



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