Commit 3fa0d46b authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

[slideshow] started work on a clutter based slideshow

parent f865a15f
......@@ -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}
"
......@@ -10,6 +10,7 @@ SUBDIRS = \
list_tools \
photo_importer \
rename_series \
search
search \
slideshow
-include $(top_srcdir)/git.mk
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
/* -*- 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);
}
/* -*- 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 */
/* -*- 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);
}
/* -*- 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 */
/* -*- 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)