[gthumb/ext: 1/3] [slideshow] started work on a clutter based slideshow



commit 3fa0d46bb9cee2e542c25b489d15a9ef679fe4a3
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Sep 1 09:17:47 2009 +0200

    [slideshow] started work on a clutter based slideshow

 configure.ac                                   |   24 ++-
 extensions/Makefile.am                         |    3 +-
 extensions/slideshow/Makefile.am               |   36 ++
 extensions/slideshow/actions.c                 |   52 +++
 extensions/slideshow/actions.h                 |   32 ++
 extensions/slideshow/callbacks.c               |  120 +++++++
 extensions/slideshow/callbacks.h               |   31 ++
 extensions/slideshow/gth-slideshow.c           |  432 ++++++++++++++++++++++++
 extensions/slideshow/gth-slideshow.h           |   59 ++++
 extensions/slideshow/main.c                    |   54 +++
 extensions/slideshow/slideshow.extension.in.in |   11 +
 gthumb/Makefile.am                             |    2 +
 gthumb/gth-browser-ui.h                        |    1 +
 gthumb/main.c                                  |    9 +
 14 files changed, 864 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 92a591c..d63faa9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,8 @@ GLIB_REQUIRED=2.16.0
 GTK_REQUIRED=2.16.0
 GCONF_REQUIRED=2.6.0
 EXIV2_REQUIRED=0.18
+CLUTTER_REQUIRED=1.0.0
+CLUTTER_GTK_REQUIRED=0.10.0
 
 dnl ===========================================================================
 
@@ -108,6 +110,24 @@ AM_CONDITIONAL(ENABLE_EXIV2, test "x$enable_exiv2" = xyes)
 
 dnl ===========================================================================
 
+AC_ARG_ENABLE([clutter],
+	      [AC_HELP_STRING([--disable-clutter],[do not compile code that uses the clutter library])],,
+	      [enable_clutter=yes])
+
+if test x$enable_clutter = xyes ; then
+	PKG_CHECK_MODULES(CLUTTER,
+			  [clutter-1.0 >= $CLUTTER_REQUIRED
+			   clutter-gtk-0.10 >= $CLUTTER_GTK_REQUIRED],
+			  [enable_clutter=yes],
+			  [enable_clutter=no])
+	AC_DEFINE(HAVE_CLUTTER, 1, [Define to 1 if clutter support is included])
+fi
+AC_SUBST(CLUTTER_LIBS)
+AC_SUBST(CLUTTER_CFLAGS)
+AM_CONDITIONAL(ENABLE_CLUTTER, test "x$enable_clutter" = xyes)
+
+dnl ===========================================================================
+
 IT_PROG_INTLTOOL([0.35.0])
 GETTEXT_PACKAGE=gthumb
 AC_SUBST([GETTEXT_PACKAGE])
@@ -208,8 +228,8 @@ AC_ARG_ENABLE([jpeg],
 AC_CHECK_LIB(jpeg, jpeg_destroy_decompress,
              [enable_jpeg=yes],
 	     [enable_jpeg=no])
-AC_DEFINE(HAVE_LIBJPEG, 1, [Define to 1 if libjpeg support is included])
 if test "x$enable_jpeg" = "xyes"; then
+	AC_DEFINE(HAVE_LIBJPEG, 1, [Define to 1 if libjpeg support is included])
 	JPEG_LIBS='-ljpeg -lm -lz'
 fi
 AC_SUBST(JPEG_LIBS)
@@ -265,6 +285,7 @@ extensions/rename_series/data/ui/Makefile
 extensions/search/Makefile
 extensions/search/data/Makefile
 extensions/search/data/ui/Makefile
+extensions/slideshow/Makefile
 gthumb/Makefile
 gthumb/cursors/Makefile
 gthumb/icons/Makefile
@@ -285,4 +306,5 @@ Configuration:
 	Build tests          : $ENABLE_TEST_SUITE
 	Exiv2 support        : ${enable_exiv2}
 	JPEG tools           : ${enable_jpeg}
+	Clutter support      : ${enable_clutter}
 "
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index aaae30d..ada6456 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -10,6 +10,7 @@ SUBDIRS = 		\
 	list_tools	\
 	photo_importer	\
 	rename_series 	\
-	search
+	search		\
+	slideshow
 
 -include $(top_srcdir)/git.mk
diff --git a/extensions/slideshow/Makefile.am b/extensions/slideshow/Makefile.am
new file mode 100644
index 0000000..8f70c94
--- /dev/null
+++ b/extensions/slideshow/Makefile.am
@@ -0,0 +1,36 @@
+if ENABLE_CLUTTER
+
+extensiondir = $(libdir)/gthumb-2.0/extensions
+extension_LTLIBRARIES = libslideshow.la
+
+libslideshow_la_SOURCES = 		\
+	actions.c			\
+	actions.h			\
+	callbacks.c			\
+	callbacks.h			\
+	gth-slideshow.c			\
+	gth-slideshow.h			\
+	main.c
+
+libslideshow_la_CFLAGS = $(GTHUMB_CFLAGS) $(CLUTTER_CFLAGS) $(DISABLE_DEPRECATED) $(WARNINGS) -I$(top_srcdir) -I$(top_builddir)/gthumb 
+libslideshow_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
+libslideshow_la_LIBADD = $(GTHUMB_LIBS)
+libslideshow_la_DEPENDENCIES = $(top_builddir)/gthumb/gthumb$(EXEEXT)
+
+extensioninidir = $(extensiondir)
+extensionini_in_files = slideshow.extension.in.in
+extensionini_DATA = $(extensionini_in_files:.extension.in.in=.extension)
+
+%.extension.in: %.extension.in.in $(extension_LTLIBRARIES)
+	sed -e "s|%LIBRARY%|`. ./$(extension_LTLIBRARIES) && echo $$dlname`|" \
+	$< > $@
+
+%.extension: %.extension.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@
+
+EXTRA_DIST = $(extensionini_in_files) 
+
+DISTCLEANFILES = $(extensionini_DATA)
+
+endif
+
+-include $(top_srcdir)/git.mk
diff --git a/extensions/slideshow/actions.c b/extensions/slideshow/actions.c
new file mode 100644
index 0000000..316e63d
--- /dev/null
+++ b/extensions/slideshow/actions.c
@@ -0,0 +1,52 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ *  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 Street #330, Boston, MA 02111-1307, USA.
+ */
+
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <gthumb.h>
+#include "gth-slideshow.h"
+
+
+void
+gth_browser_activate_action_view_slideshow (GtkAction  *action,
+					    GthBrowser *browser)
+{
+	GList     *items;
+	GList     *file_list;
+	GtkWidget *slideshow;
+
+	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+	if ((items == NULL) || (items->next == NULL))
+		file_list = gth_file_store_get_visibles (GTH_FILE_STORE (gth_browser_get_file_store (browser)));
+	else
+		file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+
+	slideshow = gth_slideshow_new (browser, file_list);
+	gtk_window_fullscreen (GTK_WINDOW (slideshow));
+	/*gtk_window_set_default_size (GTK_WINDOW (slideshow), 700, 700);*/
+	gtk_window_present (GTK_WINDOW (slideshow));
+	gth_slideshow_play (GTH_SLIDESHOW (slideshow));
+
+	_g_object_list_unref (file_list);
+	_gtk_tree_path_list_free (items);
+}
diff --git a/extensions/slideshow/actions.h b/extensions/slideshow/actions.h
new file mode 100644
index 0000000..91cc1a9
--- /dev/null
+++ b/extensions/slideshow/actions.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ *  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 Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef ACTIONS_H
+#define ACTIONS_H
+
+#include <gtk/gtk.h>
+
+#define DEFINE_ACTION(x) void x (GtkAction *action, gpointer data);
+
+DEFINE_ACTION(gth_browser_activate_action_view_slideshow)
+
+#endif /* ACTIONS_H */
diff --git a/extensions/slideshow/callbacks.c b/extensions/slideshow/callbacks.c
new file mode 100644
index 0000000..5a6ba4b
--- /dev/null
+++ b/extensions/slideshow/callbacks.c
@@ -0,0 +1,120 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ *  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 Street #330, Boston, MA 02111-1307, USA.
+ */
+
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+#include <gthumb.h>
+#include "actions.h"
+
+
+#define BROWSER_DATA_KEY "slideshow-browser-data"
+
+
+static const char *ui_info =
+"<ui>"
+"  <menubar name='MenuBar'>"
+"    <menu name='View' action='ViewMenu'>"
+"      <placeholder name='View_Actions'>"
+"        <menuitem action='View_Slideshow'/>"
+"      </placeholder>"
+"    </menu>"
+"  </menubar>"
+"</ui>";
+
+
+static GtkActionEntry action_entries[] = {
+	{ "View_Slideshow", NULL,
+	  "_Slideshow", "F5",
+	  N_("View as a slideshow"),
+	  G_CALLBACK (gth_browser_activate_action_view_slideshow) }
+};
+
+
+typedef struct {
+	GtkActionGroup *action_group;
+	guint           actions_merge_id;
+} BrowserData;
+
+
+static void
+browser_data_free (BrowserData *data)
+{
+	g_free (data);
+}
+
+
+void
+ss__gth_browser_construct_cb (GthBrowser *browser)
+{
+	BrowserData *data;
+	GError      *error = NULL;
+
+	g_return_if_fail (GTH_IS_BROWSER (browser));
+
+	data = g_new0 (BrowserData, 1);
+
+	data->action_group = gtk_action_group_new ("Slideshow Action");
+	gtk_action_group_set_translation_domain (data->action_group, NULL);
+	gtk_action_group_add_actions (data->action_group,
+				      action_entries,
+				      G_N_ELEMENTS (action_entries),
+				      browser);
+	gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->action_group, 0);
+
+	data->actions_merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), ui_info, -1, &error);
+	if (data->actions_merge_id == 0) {
+		g_warning ("building menus failed: %s", error->message);
+		g_error_free (error);
+	}
+
+	g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
+}
+
+
+static void
+set_action_sensitive (BrowserData *data,
+		      const char  *action_name,
+		      gboolean     sensitive)
+{
+	GtkAction *action;
+
+	action = gtk_action_group_get_action (data->action_group, action_name);
+	g_object_set (action, "sensitive", sensitive, NULL);
+}
+
+
+void
+ss__gth_browser_update_sensitivity_cb (GthBrowser *browser)
+{
+	BrowserData  *data;
+	GtkTreeModel *file_store;
+	gboolean      sensitive;
+
+	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
+	g_return_if_fail (data != NULL);
+
+	file_store = gth_file_view_get_model (GTH_FILE_VIEW (gth_browser_get_file_list_view (browser)));
+	sensitive = (gth_file_store_n_visibles (GTH_FILE_STORE (file_store)) > 0);
+	set_action_sensitive (data, "View_Slideshow", sensitive);
+}
diff --git a/extensions/slideshow/callbacks.h b/extensions/slideshow/callbacks.h
new file mode 100644
index 0000000..a6d7c71
--- /dev/null
+++ b/extensions/slideshow/callbacks.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ *  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 Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef CALLBACKS_H
+#define CALLBACKS_H
+
+#include <gthumb.h>
+
+void ss__gth_browser_construct_cb          (GthBrowser *browser);
+void ss__gth_browser_update_sensitivity_cb (GthBrowser *browser);
+
+#endif /* CALLBACKS_H */
diff --git a/extensions/slideshow/gth-slideshow.c b/extensions/slideshow/gth-slideshow.c
new file mode 100644
index 0000000..f269f55
--- /dev/null
+++ b/extensions/slideshow/gth-slideshow.c
@@ -0,0 +1,432 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ *  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 Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <gtk/gtk.h>
+#include <clutter/clutter.h>
+#include <clutter-gtk/clutter-gtk.h>
+#include "gth-slideshow.h"
+
+#define ANIMATION_DURATION 200
+#define OPACITY_AT_MSECS(t)((int) (255 * ((double) (t) / ANIMATION_DURATION)))
+#define HIDE_CURSOR_DELAY 1000
+#define DEFAULT_DELAY 2000
+#define ANGLE_AT_MSECS(t)((180.0 * ((double) (t) / ANIMATION_DURATION)))
+#define POSITION_AT_MSECS(x, t)(((float)(x) * ((double) (t) / ANIMATION_DURATION)))
+
+struct _GthSlideshowPrivate {
+	GthBrowser      *browser;
+	GList           *file_list; /* GthFileData */
+	GList           *current;
+	GthImageLoader  *image_loader;
+	ClutterActor    *stage;
+	ClutterActor    *texture1;
+	ClutterActor    *texture2;
+	ClutterActor    *current_texture;
+	ClutterActor    *next_texture;
+	ClutterTimeline *timeline;
+	gboolean         first_frame;
+	guint            next_event;
+	guint            delay;
+	guint            hide_cursor_event;
+};
+
+
+static gpointer parent_class = NULL;
+
+
+static void
+_gth_slideshow_load_current_image (GthSlideshow *self)
+{
+	if (self->priv->current == NULL) {
+		gtk_widget_destroy (GTK_WIDGET (self));
+		return;
+	}
+
+	gth_image_loader_set_file_data (GTH_IMAGE_LOADER (self->priv->image_loader), (GthFileData *) self->priv->current->data);
+	gth_image_loader_load (GTH_IMAGE_LOADER (self->priv->image_loader));
+}
+
+
+static void
+_gth_slideshow_load_next_image (GthSlideshow *self)
+{
+	if (clutter_timeline_is_playing (self->priv->timeline))
+		return;
+	self->priv->current = self->priv->current->next;
+	clutter_timeline_set_direction (self->priv->timeline, CLUTTER_TIMELINE_FORWARD);
+	_gth_slideshow_load_current_image (self);
+}
+
+
+static void
+_gth_slideshow_load_prev_image (GthSlideshow *self)
+{
+	if (clutter_timeline_is_playing (self->priv->timeline))
+			return;
+	self->priv->current = self->priv->current->prev;
+	clutter_timeline_set_direction (self->priv->timeline, CLUTTER_TIMELINE_BACKWARD);
+	_gth_slideshow_load_current_image (self);
+}
+
+
+static gboolean
+next_image_cb (gpointer user_data)
+{
+	GthSlideshow *self = user_data;
+
+	g_source_remove (self->priv->next_event);
+	self->priv->next_event = 0;
+	_gth_slideshow_load_next_image (self);
+
+	return FALSE;
+}
+
+
+static void
+animation_completed_cb (ClutterTimeline *timeline,
+			GthSlideshow    *self)
+{
+	if (clutter_timeline_get_direction (self->priv->timeline) == CLUTTER_TIMELINE_FORWARD) {
+		self->priv->current_texture = self->priv->next_texture;
+		if (self->priv->current_texture == self->priv->texture1)
+			self->priv->next_texture = self->priv->texture2;
+		else
+			self->priv->next_texture = self->priv->texture1;
+	}
+
+	/*self->priv->next_event = g_timeout_add (self->priv->delay, next_image_cb, self);*/
+}
+
+
+static void
+animation_frame_cb (ClutterTimeline *timeline,
+		    int              msecs,
+		    GthSlideshow    *self)
+{
+	float image_w, image_h;
+
+#ifndef SLIDE
+	clutter_actor_get_size (self->priv->stage, &image_w, &image_h);
+
+	clutter_actor_set_x (self->priv->next_texture, POSITION_AT_MSECS(image_w, ANIMATION_DURATION - msecs));
+	if (self->priv->current_texture != NULL)
+		clutter_actor_set_x (self->priv->current_texture, POSITION_AT_MSECS(- image_w, msecs));
+
+	if (self->priv->first_frame) {
+		if (self->priv->current_texture != NULL)
+			clutter_actor_show (self->priv->current_texture);
+		clutter_actor_show (self->priv->next_texture);
+		self->priv->first_frame = FALSE;
+	}
+#endif
+
+#ifdef FADE
+	if (self->priv->current_texture != NULL)
+		clutter_actor_set_opacity (self->priv->current_texture, OPACITY_AT_MSECS(ANIMATION_DURATION - msecs));
+	clutter_actor_set_opacity (self->priv->next_texture, OPACITY_AT_MSECS(msecs));
+
+	if (self->priv->first_frame) {
+		if (self->priv->current_texture != NULL) {
+			clutter_actor_show (self->priv->current_texture);
+			clutter_actor_raise (self->priv->next_texture, self->priv->current_texture);
+		}
+		clutter_actor_show (self->priv->next_texture);
+		self->priv->first_frame = FALSE;
+	}
+#endif
+
+#ifdef ROTATE
+	if ((float) msecs >= (float) ANIMATION_DURATION / 2.0) {
+		clutter_actor_show (self->priv->next_texture);
+		if (self->priv->current_texture != NULL)
+			clutter_actor_hide (self->priv->current_texture);
+	}
+	else {
+		clutter_actor_hide (self->priv->next_texture);
+		if (self->priv->current_texture != NULL)
+			clutter_actor_show (self->priv->current_texture);
+	}
+
+	clutter_actor_get_size (self->priv->stage, &image_w, &image_h);
+	clutter_actor_set_rotation (self->priv->next_texture,
+				    CLUTTER_Y_AXIS,
+		 		    ANGLE_AT_MSECS (ANIMATION_DURATION - msecs),
+		 		    image_w / 2.0,
+		 		    0.0,
+		 		    0.0);
+	if (self->priv->current_texture != NULL)
+		clutter_actor_set_rotation (self->priv->current_texture,
+					    CLUTTER_Y_AXIS,
+					    ANGLE_AT_MSECS (- msecs),
+					    image_w / 2.0,
+					    0.0,
+					    0.0);
+
+	if (self->priv->first_frame) {
+		if (self->priv->current_texture != NULL)
+			clutter_actor_raise (self->priv->next_texture, self->priv->current_texture);
+		clutter_actor_show (self->priv->next_texture);
+		self->priv->first_frame = FALSE;
+	}
+#endif
+}
+
+
+static void
+animation_started_cb (ClutterTimeline *timeline,
+		      GthSlideshow    *self)
+{
+	self->priv->first_frame = TRUE;
+}
+
+
+static void
+image_loader_ready_cb (GthImageLoader *image_loader,
+		       GError         *error,
+		       GthSlideshow   *self)
+{
+	GdkPixbuf *image;
+	int        image_w, image_h;
+	float      stage_w, stage_h;
+	float      image_x, image_y;
+
+	if (error != NULL) {
+		g_clear_error (&error);
+		_gth_slideshow_load_next_image (self);
+	}
+
+	clutter_actor_hide (self->priv->next_texture);
+
+	image = gth_image_loader_get_pixbuf (GTH_IMAGE_LOADER (image_loader));
+	gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (self->priv->next_texture), image, NULL);
+
+	image_w = gdk_pixbuf_get_width (image);
+	image_h = gdk_pixbuf_get_height (image);
+	clutter_actor_get_size (self->priv->stage, &stage_w, &stage_h);
+	scale_keeping_ratio (&image_w, &image_h, (int) stage_w, (int) stage_h, TRUE);
+	clutter_actor_set_size (self->priv->next_texture, (float) image_w, (float) image_h);
+
+	image_x = (stage_w - image_w) / 2;
+	image_y = (stage_h - image_h) / 2;
+	clutter_actor_set_position (self->priv->next_texture, image_x, image_y);
+
+	if (clutter_timeline_get_direction (self->priv->timeline) == CLUTTER_TIMELINE_BACKWARD) {
+		ClutterActor *tmp;
+
+		tmp = self->priv->next_texture;
+		self->priv->next_texture = self->priv->current_texture;
+		self->priv->current_texture = tmp;
+	}
+
+	clutter_timeline_rewind (self->priv->timeline);
+	clutter_timeline_start (self->priv->timeline);
+	if (self->priv->current_texture == NULL)
+		clutter_timeline_advance (self->priv->timeline, ANIMATION_DURATION);
+}
+
+
+static void
+gth_slideshow_init (GthSlideshow *self)
+{
+	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_SLIDESHOW, GthSlideshowPrivate);
+	self->priv->file_list = NULL;
+	self->priv->next_event = 0;
+	self->priv->delay = DEFAULT_DELAY;
+
+	self->priv->image_loader = gth_image_loader_new (FALSE);
+	g_signal_connect (self->priv->image_loader, "ready", G_CALLBACK (image_loader_ready_cb), self);
+}
+
+
+static void
+gth_slideshow_finalize (GObject *object)
+{
+	GthSlideshow *self = GTH_SLIDESHOW (object);
+
+	if (self->priv->next_event != 0)
+		g_source_remove (self->priv->next_event);
+	if (self->priv->hide_cursor_event != 0)
+		g_source_remove (self->priv->hide_cursor_event);
+
+	_g_object_list_unref (self->priv->file_list);
+	_g_object_unref (self->priv->browser);
+	_g_object_unref (self->priv->image_loader);
+	_g_object_unref (self->priv->timeline);
+
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+static void
+gth_slideshow_class_init (GthSlideshowClass *klass)
+{
+	GObjectClass *gobject_class;
+
+	parent_class = g_type_class_peek_parent (klass);
+	g_type_class_add_private (klass, sizeof (GthSlideshowPrivate));
+
+	gobject_class = G_OBJECT_CLASS (klass);
+	gobject_class->finalize = gth_slideshow_finalize;
+}
+
+
+GType
+gth_slideshow_get_type (void)
+{
+	static GType type = 0;
+
+	if (! type) {
+		GTypeInfo type_info = {
+			sizeof (GthSlideshowClass),
+			NULL,
+			NULL,
+			(GClassInitFunc) gth_slideshow_class_init,
+			NULL,
+			NULL,
+			sizeof (GthSlideshow),
+			0,
+			(GInstanceInitFunc) gth_slideshow_init
+		};
+
+		type = g_type_register_static (GTK_TYPE_WINDOW,
+					       "GthSlideshow",
+					       &type_info,
+					       0);
+	}
+
+	return type;
+}
+
+
+static gboolean
+hide_cursor_cb (gpointer data)
+{
+	GthSlideshow *self = data;
+
+	g_source_remove (self->priv->hide_cursor_event);
+	self->priv->hide_cursor_event = 0;
+
+	clutter_stage_hide_cursor (CLUTTER_STAGE (self->priv->stage));
+
+	return FALSE;
+}
+
+
+static void
+stage_input_cb (ClutterStage *stage,
+	        ClutterEvent *event,
+	        GthSlideshow *self)
+{
+	if (event->type == CLUTTER_MOTION) {
+		clutter_stage_show_cursor (CLUTTER_STAGE (self->priv->stage));
+		if (self->priv->hide_cursor_event != 0)
+			g_source_remove (self->priv->hide_cursor_event);
+		self->priv->hide_cursor_event = g_timeout_add (HIDE_CURSOR_DELAY, hide_cursor_cb, self);
+	}
+	else if (event->type == CLUTTER_KEY_RELEASE) {
+		switch (clutter_event_get_key_symbol (event)) {
+		case CLUTTER_Escape:
+			gtk_widget_destroy (GTK_WIDGET (self));
+			break;
+
+		case CLUTTER_space:
+			_gth_slideshow_load_next_image (self);
+			break;
+
+		case CLUTTER_BackSpace:
+			_gth_slideshow_load_prev_image (self);
+			break;
+		}
+	}
+}
+
+
+static void
+_gth_slideshow_construct (GthSlideshow *self,
+			  GthBrowser   *browser,
+			  GList        *file_list)
+{
+	GtkWidget    *embed;
+	ClutterColor  stage_color = { 0x0, 0x0, 0x0, 0xff };
+
+	self->priv->browser = _g_object_ref (browser);
+	self->priv->file_list = _g_object_list_ref (file_list);
+	self->priv->current = self->priv->file_list;
+
+	embed = gtk_clutter_embed_new ();
+	self->priv->stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (embed));
+	clutter_stage_hide_cursor (CLUTTER_STAGE (self->priv->stage));
+	clutter_stage_set_color (CLUTTER_STAGE (self->priv->stage), &stage_color);
+	g_signal_connect (self->priv->stage, "motion-event", G_CALLBACK (stage_input_cb), self);
+	g_signal_connect (self->priv->stage, "key-release-event", G_CALLBACK (stage_input_cb), self);
+
+	gtk_widget_show (embed);
+	gtk_container_add (GTK_CONTAINER (self), embed);
+
+	self->priv->texture1 = clutter_texture_new ();
+	clutter_actor_hide (self->priv->texture1);
+	clutter_container_add_actor (CLUTTER_CONTAINER (self->priv->stage), self->priv->texture1);
+
+	self->priv->texture2 = clutter_texture_new ();
+	clutter_actor_hide (self->priv->texture2);
+	clutter_container_add_actor (CLUTTER_CONTAINER (self->priv->stage), self->priv->texture2);
+
+	self->priv->current_texture = NULL;
+	self->priv->next_texture = self->priv->texture1;
+
+	self->priv->timeline = clutter_timeline_new (ANIMATION_DURATION);
+	g_signal_connect (self->priv->timeline, "completed", G_CALLBACK (animation_completed_cb), self);
+	g_signal_connect (self->priv->timeline, "new-frame", G_CALLBACK (animation_frame_cb), self);
+	g_signal_connect (self->priv->timeline, "started", G_CALLBACK (animation_started_cb), self);
+}
+
+
+GtkWidget *
+gth_slideshow_new (GthBrowser *browser,
+		   GList      *file_list /* GthFileData */)
+{
+	GthSlideshow *window;
+
+	window = (GthSlideshow *) g_object_new (GTH_TYPE_SLIDESHOW, NULL);
+	_gth_slideshow_construct (window, browser, file_list);
+
+	return (GtkWidget*) window;
+}
+
+
+static gboolean
+start_playing (gpointer user_data)
+{
+	GthSlideshow *self = user_data;
+
+	_gth_slideshow_load_current_image (self);
+
+	return FALSE;
+}
+
+
+void
+gth_slideshow_play (GthSlideshow *self)
+{
+	g_idle_add (start_playing, self);
+}
diff --git a/extensions/slideshow/gth-slideshow.h b/extensions/slideshow/gth-slideshow.h
new file mode 100644
index 0000000..7d05209
--- /dev/null
+++ b/extensions/slideshow/gth-slideshow.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ *  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 Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GTH_SLIDESHOW_H
+#define GTH_SLIDESHOW_H
+
+#include <gthumb.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_SLIDESHOW              (gth_slideshow_get_type ())
+#define GTH_SLIDESHOW(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_SLIDESHOW, GthSlideshow))
+#define GTH_SLIDESHOW_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_SLIDESHOW_TYPE, GthSlideshowClass))
+#define GTH_IS_SLIDESHOW(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_SLIDESHOW))
+#define GTH_IS_SLIDESHOW_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_SLIDESHOW))
+#define GTH_SLIDESHOW_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), GTH_TYPE_SLIDESHOW, GthSlideshowClass))
+
+typedef struct _GthSlideshow         GthSlideshow;
+typedef struct _GthSlideshowClass    GthSlideshowClass;
+typedef struct _GthSlideshowPrivate  GthSlideshowPrivate;
+
+struct _GthSlideshow
+{
+	GtkWindow __parent;
+	GthSlideshowPrivate *priv;
+};
+
+struct _GthSlideshowClass
+{
+	GtkWindowClass __parent_class;
+};
+
+GType            gth_slideshow_get_type  (void);
+GtkWidget *      gth_slideshow_new       (GthBrowser   *browser,
+					  GList        *file_list /* GthFileData */);
+void             gth_slideshow_play      (GthSlideshow *self);
+
+G_END_DECLS
+
+#endif /* GTH_SLIDESHOW_H */
diff --git a/extensions/slideshow/main.c b/extensions/slideshow/main.c
new file mode 100644
index 0000000..b6e4e74
--- /dev/null
+++ b/extensions/slideshow/main.c
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ *  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 Street #330, Boston, MA 02111-1307, USA.
+ */
+
+
+#include <config.h>
+#include <gtk/gtk.h>
+#include <gthumb.h>
+#include "callbacks.h"
+
+
+G_MODULE_EXPORT void
+gthumb_extension_activate (void)
+{
+	gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (ss__gth_browser_construct_cb), NULL);
+	gth_hook_add_callback ("gth-browser-update-sensitivity", 10, G_CALLBACK (ss__gth_browser_update_sensitivity_cb), NULL);
+}
+
+
+G_MODULE_EXPORT void
+gthumb_extension_deactivate (void)
+{
+}
+
+
+G_MODULE_EXPORT gboolean
+gthumb_extension_is_configurable (void)
+{
+	return FALSE;
+}
+
+
+G_MODULE_EXPORT void
+gthumb_extension_configure (GtkWindow *parent)
+{
+}
diff --git a/extensions/slideshow/slideshow.extension.in.in b/extensions/slideshow/slideshow.extension.in.in
new file mode 100644
index 0000000..6b4226c
--- /dev/null
+++ b/extensions/slideshow/slideshow.extension.in.in
@@ -0,0 +1,11 @@
+[Extension]
+_Name=Slideshow
+_Description=View images as a slideshow
+_Authors=gthumb development team
+Copyright=Copyright © 2008-2009 The Free Software Foundation, Inc.
+Version=1.0
+
+[Loader]
+Type=module
+File=%LIBRARY%
+Requires=catalogs
diff --git a/gthumb/Makefile.am b/gthumb/Makefile.am
index bd175cf..aaf2e4d 100644
--- a/gthumb/Makefile.am
+++ b/gthumb/Makefile.am
@@ -222,6 +222,7 @@ gthumb_LDADD =						\
 	$(GTHUMB_LIBS)					\
 	$(EXIV2_LIBS)					\
 	$(JPEG_LIBS)					\
+	$(CLUTTER_LIBS)					\
 	$(NULL)	
 
 if RUN_IN_PLACE
@@ -237,6 +238,7 @@ endif
 gthumb_CFLAGS =							\
 	$(GTHUMB_CFLAGS)					\
 	$(EXIV2_CFLAGS)						\
+	$(CLUTTER_CFLAGS)					\
 	$(DISABLE_DEPRECATED)                   		\
         $(WARNINGS)                             		\
 	-I$(top_srcdir)/copy-n-paste/				\
diff --git a/gthumb/gth-browser-ui.h b/gthumb/gth-browser-ui.h
index a5b14ce..8b99987 100644
--- a/gthumb/gth-browser-ui.h
+++ b/gthumb/gth-browser-ui.h
@@ -66,6 +66,7 @@ static const char *fixed_ui_info =
 "      <placeholder name='View_Bars'/>"
 "      <separator/>"
 "      <menuitem action='View_Fullscreen'/>"
+"      <placeholder name='View_Actions'/>"
 "      <separator/>"
 "      <placeholder name='File_Actions'/>"
 "      <separator/>"
diff --git a/gthumb/main.c b/gthumb/main.c
index 21484e2..b0190d9 100644
--- a/gthumb/main.c
+++ b/gthumb/main.c
@@ -25,6 +25,10 @@
 #include <glib/gprintf.h>
 #include <gtk/gtk.h>
 #include <unique/unique.h>
+#ifdef HAVE_CLUTTER
+#include <clutter/clutter.h>
+#include <clutter-gtk/clutter-gtk.h>
+#endif
 #include "eggsmclient.h"
 #include "glib-utils.h"
 #include "gth-browser.h"
@@ -355,6 +359,11 @@ main (int argc, char *argv[])
 
 	/* command line options */
 
+#ifdef HAVE_CLUTTER
+	if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
+		g_error ("Unable to initialize GtkClutter");
+#endif
+
 	context = g_option_context_new (N_("- Image browser and viewer"));
 	g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
 	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);



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