[Xfce4-commits] <ristretto:ristretto-0.0> Remove obsolete files and improve status messages
Stephan Arts
noreply at xfce.org
Sun Oct 23 19:21:14 CEST 2011
Updating branch refs/heads/ristretto-0.0
to d5e1cf2da6d0cff03ba5f2d3155fedff9b03768b (commit)
from fa40ab207a185499a3087a05eb860aa65b3ebe39 (commit)
commit d5e1cf2da6d0cff03ba5f2d3155fedff9b03768b
Author: Stephan Arts <stephan at xfce.org>
Date: Sat Sep 19 00:21:25 2009 +0200
Remove obsolete files and improve status messages
ChangeLog | 7 +
src/image_list.c | 22 +
src/main_window.c | 40 ++-
src/navigator.c | 1759 -----------------------------------------------------
src/navigator.h | 176 ------
5 files changed, 67 insertions(+), 1937 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 299a439..3c4babc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-09-19 Stephan Arts <stephan at xfce.org>
+
+ * src/navigator.c,
+ src/navigator.h: Remove obsolete source files
+ * src/main_window.c,
+ src/image_list.c: Improve status-messages
+
2009-09-06 Stephan Arts <stephan at xfce.org>
* src/main_window.c,
diff --git a/src/image_list.c b/src/image_list.c
index 7642280..08eaebf 100644
--- a/src/image_list.c
+++ b/src/image_list.c
@@ -62,6 +62,7 @@ enum
enum
{
RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED = 0,
+ RSTTO_IMAGE_LIST_ITER_SIGNAL_PREPARE_CHANGE,
RSTTO_IMAGE_LIST_ITER_SIGNAL_COUNT
};
@@ -315,6 +316,17 @@ rstto_image_list_iter_class_init(RsttoImageListIterClass *iter_class)
object_class->dispose = rstto_image_list_iter_dispose;
+ rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_PREPARE_CHANGE] = g_signal_new("prepare-change",
+ G_TYPE_FROM_CLASS(iter_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0,
+ NULL);
+
rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED] = g_signal_new("changed",
G_TYPE_FROM_CLASS(iter_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
@@ -363,6 +375,8 @@ rstto_image_list_iter_find_image (RsttoImageListIter *iter, RsttoImage *image)
gint pos = g_list_index (iter->priv->image_list->priv->images, image);
if (pos > -1)
{
+ g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_PREPARE_CHANGE], 0, NULL);
+
if (iter->priv->image)
{
iter->priv->image = NULL;
@@ -396,6 +410,8 @@ rstto_image_list_iter_get_image (RsttoImageListIter *iter)
void
rstto_image_list_iter_set_position (RsttoImageListIter *iter, gint pos)
{
+ g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_PREPARE_CHANGE], 0, NULL);
+
if (iter->priv->image)
{
iter->priv->image = NULL;
@@ -410,6 +426,9 @@ void
rstto_image_list_iter_next (RsttoImageListIter *iter)
{
GList *position = NULL;
+
+ g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_PREPARE_CHANGE], 0, NULL);
+
if (iter->priv->image)
{
position = g_list_find (iter->priv->image_list->priv->images, iter->priv->image);
@@ -435,6 +454,9 @@ void
rstto_image_list_iter_previous (RsttoImageListIter *iter)
{
GList *position = NULL;
+
+ g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_PREPARE_CHANGE], 0, NULL);
+
if (iter->priv->image)
{
position = g_list_find (iter->priv->image_list->priv->images, iter->priv->image);
diff --git a/src/main_window.c b/src/main_window.c
index 2fa8a9e..2a8a6c1 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -134,6 +134,9 @@ rstto_main_window_get_property (GObject *object,
static gboolean
rstto_window_save_geometry_timer (gpointer user_data);
+static void
+rstto_main_window_image_list_iter_changed (RsttoMainWindow *window);
+
static gboolean
cb_rstto_main_window_configure_event (GtkWidget *widget, GdkEventConfigure *event);
static void
@@ -143,7 +146,9 @@ cb_rstto_main_window_show_fs_toolbar_timeout (RsttoMainWindow *window);
static void
cb_rstto_main_window_image_list_iter_changed (RsttoImageListIter *iter, RsttoMainWindow *window);
static void
-rstto_main_window_image_list_iter_changed (RsttoMainWindow *window);
+cb_rstto_main_window_image_list_iter_prepare_change (RsttoImageListIter *iter, RsttoMainWindow *window);
+static void
+cb_rstto_main_window_image_prepared(RsttoImage *image, RsttoMainWindow *window);
static void
cb_rstto_main_window_image_list_new_image (RsttoImageList *image_list, RsttoImage *image, RsttoMainWindow *window);
@@ -707,6 +712,8 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window)
cur_image = rstto_image_list_iter_get_image (window->priv->iter);
if (cur_image)
{
+
+ g_signal_connect (G_OBJECT (cur_image), "prepared", G_CALLBACK (cb_rstto_main_window_image_prepared), window);
width = rstto_image_get_width(cur_image);
height = rstto_image_get_height(cur_image);
@@ -716,7 +723,14 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window)
basename = g_path_get_basename (path);
title = g_strdup_printf ("%s - %s [%d/%d]", RISTRETTO_APP_TITLE, basename, position+1, count);
- status = g_strdup_printf ("%d x %d", width, height);
+ if (width > 0)
+ {
+ status = g_strdup_printf ("%d x %d", width, height);
+ }
+ else
+ {
+ status = g_strdup_printf ("Loading '%s'", basename);
+ }
g_free (basename);
g_free (path);
@@ -738,6 +752,15 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window)
}
+static void
+cb_rstto_main_window_image_list_iter_prepare_change (RsttoImageListIter *iter, RsttoMainWindow *window)
+{
+ RsttoImage *image = rstto_image_list_iter_get_image (iter);
+ if (image)
+ {
+ g_signal_handlers_disconnect_by_func (image, cb_rstto_main_window_image_prepared, window);
+ }
+}
/**
* rstto_main_window_update_buttons:
@@ -2273,3 +2296,16 @@ cb_rstto_main_window_toggle_show_thumbnailbar (GtkWidget *widget, RsttoMainWindo
rstto_settings_set_boolean_property (RSTTO_SETTINGS (window->priv->settings_manager), "show-thumbnailbar", FALSE);
}
}
+
+static void
+cb_rstto_main_window_image_prepared (RsttoImage *image, RsttoMainWindow *window)
+{
+ gint width = rstto_image_get_width (image);
+ gint height = rstto_image_get_height (image);
+ gchar *status = g_strdup_printf ("%d x %d", width, height);
+
+ gtk_statusbar_pop (GTK_STATUSBAR (window->priv->statusbar), window->priv->statusbar_context_id);
+ gtk_statusbar_push (GTK_STATUSBAR (window->priv->statusbar), window->priv->statusbar_context_id, status);
+
+ g_free (status);
+}
diff --git a/src/navigator.c b/src/navigator.c
deleted file mode 100644
index 42f07f7..0000000
--- a/src/navigator.c
+++ /dev/null
@@ -1,1759 +0,0 @@
-/*
- * 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 Library 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.
- */
-
-#include <config.h>
-#include <gtk/gtk.h>
-#include <gtk/gtkmarshal.h>
-#include <string.h>
-
-#include <thunar-vfs/thunar-vfs.h>
-#include <libexif/exif-data.h>
-
-#include "navigator.h"
-
-static void
-rstto_navigator_init(RsttoNavigator *);
-static void
-rstto_navigator_class_init(RsttoNavigatorClass *);
-static void
-rstto_navigator_dispose(GObject *object);
-
-static void
-rstto_navigator_entry_clear (RsttoNavigatorEntry *nav_entry);
-
-static gboolean
-cb_rstto_navigator_running(RsttoNavigator *navigator);
-
-static GObjectClass *parent_class = NULL;
-
-static gint
-rstto_navigator_entry_name_compare_func(RsttoNavigatorEntry *a, RsttoNavigatorEntry *b);
-
-static void
-cb_rstto_navigator_entry_area_prepared (GdkPixbufLoader *loader, RsttoNavigatorEntry *entry);
-static void
-cb_rstto_navigator_entry_closed (GdkPixbufLoader *loader, RsttoNavigatorEntry *entry);
-static gboolean
-cb_rstto_navigator_entry_read_file(GIOChannel *io_channel, GIOCondition cond, RsttoNavigatorEntry *entry);
-
-static gboolean
-cb_rstto_navigator_entry_update_image (RsttoNavigatorEntry *entry);
-
-static void
-cb_rstto_navigator_entry_fs_event (ThunarVfsMonitor *,
- ThunarVfsMonitorHandle *,
- ThunarVfsMonitorEvent,
- ThunarVfsPath *,
- ThunarVfsPath *,
- RsttoNavigatorEntry *);
-static void
-cb_rstto_navigator_fs_event (ThunarVfsMonitor *monitor,
- ThunarVfsMonitorHandle *handl,
- ThunarVfsMonitorEvent event,
- ThunarVfsPath *handle_path,
- ThunarVfsPath *event_path,
- RsttoNavigator *nav);
-
-static void
-rstto_navigator_set_busy (RsttoNavigator *navigator, gboolean busy);
-
-static gint
-cb_rstto_navigator_entry_path_compare_func(RsttoNavigatorEntry *entry, ThunarVfsPath *path);
-
-enum
-{
- RSTTO_NAVIGATOR_SIGNAL_ENTRY_MODIFIED = 0,
- RSTTO_NAVIGATOR_SIGNAL_ENTRY_REMOVED,
- RSTTO_NAVIGATOR_SIGNAL_NEW_ENTRY,
- RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED,
- RSTTO_NAVIGATOR_SIGNAL_REORDERED,
- RSTTO_NAVIGATOR_SIGNAL_COUNT
-};
-
-struct _RsttoNavigatorEntry
-{
- ThunarVfsInfo *info;
- GdkPixbufLoader *loader;
- ExifData *exif_data;
- ThunarVfsMonitorHandle *monitor_handle;
-
- GdkPixbuf *thumb;
-
- GdkPixbufAnimation *animation;
- GdkPixbufAnimationIter *iter;
- GdkPixbuf *src_pixbuf;
-
- GIOChannel *io_channel;
- gint io_source_id;
- gint timeout_id;
-
- RsttoNavigator *navigator;
-
- gdouble scale;
- gboolean fit_to_screen;
- GdkPixbufRotation rotation;
- gboolean h_flipped;
- gboolean v_flipped;
- gint x_offset;
- gint y_offset;
-
- gboolean orientation_changed;
-};
-
-
-static gint rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_COUNT];
-
-GType
-rstto_navigator_get_type ()
-{
- static GType rstto_navigator_type = 0;
-
- if (!rstto_navigator_type)
- {
- static const GTypeInfo rstto_navigator_info =
- {
- sizeof (RsttoNavigatorClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) rstto_navigator_class_init,
- (GClassFinalizeFunc) NULL,
- NULL,
- sizeof (RsttoNavigator),
- 0,
- (GInstanceInitFunc) rstto_navigator_init,
- NULL
- };
-
- rstto_navigator_type = g_type_register_static (G_TYPE_OBJECT, "RsttoNavigator", &rstto_navigator_info, 0);
- }
- return rstto_navigator_type;
-}
-
-static void
-rstto_navigator_init(RsttoNavigator *navigator)
-{
- navigator->file_iter = NULL;
- navigator->compare_func = (GCompareFunc)rstto_navigator_entry_name_compare_func;
- navigator->old_position = -1;
- navigator->timeout = 5000;
- navigator->monitor = thunar_vfs_monitor_get_default();
- navigator->preload = FALSE;
-
- /* Max history size (in bytes) */
- navigator->max_history = 128000000;
-
- navigator->factory = thunar_vfs_thumb_factory_new(THUNAR_VFS_THUMB_SIZE_NORMAL);
-}
-
-static void
-rstto_navigator_class_init(RsttoNavigatorClass *nav_class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(nav_class);
-
- parent_class = g_type_class_peek_parent(nav_class);
-
- object_class->dispose = rstto_navigator_dispose;
-
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_REORDERED] = g_signal_new("reordered",
- G_TYPE_FROM_CLASS(nav_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0,
- NULL);
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ENTRY_MODIFIED] = g_signal_new("entry-modified",
- G_TYPE_FROM_CLASS(nav_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER,
- NULL);
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ENTRY_REMOVED] = g_signal_new("entry-removed",
- G_TYPE_FROM_CLASS(nav_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER,
- NULL);
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED] = g_signal_new("iter-changed",
- G_TYPE_FROM_CLASS(nav_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__UINT_POINTER,
- G_TYPE_NONE,
- 2,
- G_TYPE_UINT,
- G_TYPE_POINTER,
- NULL);
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_NEW_ENTRY] = g_signal_new("new-entry",
- G_TYPE_FROM_CLASS(nav_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__UINT_POINTER,
- G_TYPE_NONE,
- 2,
- G_TYPE_UINT,
- G_TYPE_POINTER,
- NULL);
-}
-
-static void
-rstto_navigator_dispose(GObject *object)
-{
- RsttoNavigator *navigator = RSTTO_NAVIGATOR(object);
-
- if(navigator->file_list)
- {
- g_list_foreach(navigator->file_list, (GFunc)rstto_navigator_entry_free, NULL);
- navigator->file_list = NULL;
- navigator->file_iter = NULL;
- }
-}
-
-RsttoNavigator *
-rstto_navigator_new(GtkRecentManager *manager)
-{
- RsttoNavigator *navigator;
-
- navigator = g_object_new(RSTTO_TYPE_NAVIGATOR, NULL);
- navigator->manager = manager;
-
- return navigator;
-}
-
-/*
- * static gint
- * rstto_navigator_entry_name_compare_func:
- *
- * @a: RsttoNavigatorEntry
- * @b: RsttoNavigatorEntry
- *
- * Return value: see g_strcasecmp
- */
-static gint
-rstto_navigator_entry_name_compare_func(RsttoNavigatorEntry *a, RsttoNavigatorEntry *b)
-{
- return g_strcasecmp(a->info->display_name, b->info->display_name);
-}
-
-
-static void
-rstto_navigator_add_entry_to_history(RsttoNavigator *navigator, RsttoNavigatorEntry *entry)
-{
-
- /* rstto_debug_print_src_pixbufs(navigator); */
-
- /* Check if the image is already available in the image-cache */
- if (g_list_index(navigator->history, entry) != -1)
- {
- /* Remove the image from the history, we are going to re-add it at the front of the list later */
- navigator->history = g_list_remove(navigator->history, entry);
- }
- navigator->history = g_list_prepend(navigator->history, entry);
-
- /* manage history by kicking excess elements out */
- GList *iter = NULL;
- guint64 size = 0;
-
- for (iter = navigator->history; iter != NULL; iter = g_list_next(iter))
- {
- RsttoNavigatorEntry *nav_entry = iter->data;
-
- if (nav_entry)
- {
- size += rstto_navigator_entry_get_size(nav_entry);
- size += sizeof (*nav_entry);
- size += sizeof (*nav_entry->info);
-
- if (nav_entry->exif_data);
- size += sizeof (*nav_entry->exif_data);
- if (nav_entry->loader)
- size += sizeof (nav_entry->loader);
-
- if (size > navigator->max_history)
- {
- if (iter != navigator->file_iter)
- {
- rstto_navigator_entry_clear (nav_entry);
- iter = g_list_previous(iter);
- }
- else
- {
- iter = g_list_previous(iter);
- nav_entry = iter->data;
- if (nav_entry)
- {
- rstto_navigator_entry_clear (nav_entry);
- }
- iter = g_list_next(iter);
- }
- navigator->history = g_list_remove(navigator->history, nav_entry);
- }
- }
- }
-}
-
-
-void
-rstto_navigator_guard_history(RsttoNavigator *navigator, RsttoNavigatorEntry *entry)
-{
- /* check if the image is still loading, if so... don't cache the image */
- if(entry->io_channel)
- {
- g_source_remove(entry->io_source_id);
- g_io_channel_unref(entry->io_channel);
- entry->io_channel = NULL;
- entry->io_source_id = 0;
- if(entry->loader)
- {
- g_signal_handlers_disconnect_by_func(entry->loader , cb_rstto_navigator_entry_area_prepared, entry);
- gdk_pixbuf_loader_close(entry->loader, NULL);
- }
-
- if (entry->timeout_id)
- {
- g_source_remove(entry->timeout_id);
- entry->timeout_id = 0;
- }
-
- if(entry->animation)
- {
- g_object_unref(entry->animation);
- entry->animation = NULL;
- }
-
- if(entry->src_pixbuf)
- {
- g_object_unref(entry->src_pixbuf);
- entry->src_pixbuf = NULL;
- }
-
- if(entry->iter)
- {
- g_object_unref(entry->iter);
- entry->iter = NULL;
- }
- }
-
- rstto_navigator_add_entry_to_history(navigator, entry);
-}
-
-/* for debugging:
- * iterate through navigator->file_list and print out all
- * pixbuf entries to see whether they've been loaded or not
- */
-void
-rstto_debug_print_src_pixbufs (RsttoNavigator *navigator)
-{
- GList *e = navigator->file_list;
- int i = 1;
- printf("src_pixbufs loaded for these image indices: ");
- while (e != NULL)
- {
- RsttoNavigatorEntry *re = e->data;
- if (re->src_pixbuf != NULL)
- {
- printf("%d ", i);
- }
- e = g_list_next(e);
- i++;
- }
- printf("\n");
-}
-
-
-/* preloading for improved responsiveness
- * (at the expense of increased memory usage)
- */
-static gboolean
-rstto_navigator_preload_next_img (RsttoNavigator *navigator)
-{
- GList *next = g_list_next(navigator->file_iter);
- /* wraparound case */
- if (next == NULL)
- {
- next = navigator->file_list;
- }
- if (next != NULL)
- {
- RsttoNavigatorEntry *next_entry = next->data;
- rstto_navigator_entry_load_image(next_entry, FALSE);
-
- /* add image to the cache-history */
- rstto_navigator_add_entry_to_history(navigator, next_entry);
- }
-
- /* for use with g_timeout_add() */
- return FALSE;
-}
-
-static gboolean
-rstto_navigator_preload_prev_img (RsttoNavigator *navigator)
-{
- GList *prev = g_list_previous(navigator->file_iter);
- /* wraparound case */
- if (prev == NULL)
- {
- prev = g_list_last(navigator->file_list);
- }
- if (prev != NULL)
- {
- RsttoNavigatorEntry *prev_entry = prev->data;
- rstto_navigator_entry_load_image(prev_entry, FALSE);
-
- /* add image to the cache-history */
- rstto_navigator_add_entry_to_history(navigator, prev_entry);
- }
-
- /* for use with g_timeout_add() */
- return FALSE;
-}
-
-
-void
-rstto_navigator_jump_first (RsttoNavigator *navigator)
-{
- if(navigator->file_iter)
- {
- rstto_navigator_guard_history(navigator, navigator->file_iter->data);
- navigator->old_position = rstto_navigator_get_position(navigator);
- }
- navigator->file_iter = g_list_first(navigator->file_list);
- if(navigator->file_iter)
- {
- g_signal_emit(G_OBJECT(navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED], 0, 0, navigator->file_iter->data, NULL);
-
- if (navigator->preload)
- {
- /* preload in both directions */
- g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_next_img, navigator);
- g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_prev_img, navigator);
- }
- }
-}
-
-void
-rstto_navigator_jump_forward (RsttoNavigator *navigator)
-{
- if(navigator->file_iter)
- {
- rstto_navigator_guard_history(navigator, navigator->file_iter->data);
- navigator->old_position = rstto_navigator_get_position(navigator);
- navigator->file_iter = g_list_next(navigator->file_iter);
- }
- if(!navigator->file_iter)
- navigator->file_iter = g_list_first(navigator->file_list);
-
- if(navigator->file_iter)
- {
- g_signal_emit(G_OBJECT(navigator),
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED],
- 0,
- g_list_position(navigator->file_list, navigator->file_iter),
- navigator->file_iter->data,
- NULL);
-
- if (navigator->preload)
- {
- /* preload forwards */
- g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_next_img, navigator);
- }
- }
- else
- {
- g_signal_emit(G_OBJECT(navigator),
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED],
- 0,
- -1,
- NULL,
- NULL);
-
- }
-}
-
-void
-rstto_navigator_jump_back (RsttoNavigator *navigator)
-{
- if(navigator->file_iter)
- {
- rstto_navigator_guard_history(navigator, navigator->file_iter->data);
- navigator->old_position = rstto_navigator_get_position(navigator);
- navigator->file_iter = g_list_previous(navigator->file_iter);
- }
- if(!navigator->file_iter)
- navigator->file_iter = g_list_last(navigator->file_list);
-
- if(navigator->file_iter)
- {
- g_signal_emit(G_OBJECT(navigator),
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED],
- 0,
- g_list_position(navigator->file_list, navigator->file_iter),
- navigator->file_iter->data,
- NULL);
-
- if (navigator->preload)
- {
- /* preload backwards */
- g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_prev_img, navigator);
- }
- }
-}
-
-void
-rstto_navigator_jump_last (RsttoNavigator *navigator)
-{
- if(navigator->file_iter)
- {
- rstto_navigator_guard_history(navigator, navigator->file_iter->data);
- navigator->old_position = rstto_navigator_get_position(navigator);
- }
- navigator->file_iter = g_list_last(navigator->file_list);
-
- if(navigator->file_iter)
- {
- g_signal_emit(G_OBJECT(navigator),
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED],
- 0,
- g_list_position(navigator->file_list, navigator->file_iter),
- navigator->file_iter->data,
- NULL);
-
- if (navigator->preload)
- {
- /* preload in both directions */
- g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_next_img, navigator);
- g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_prev_img, navigator);
- }
- }
-}
-
-void
-rstto_navigator_set_running (RsttoNavigator *navigator, gboolean running)
-{
- if(!navigator->running)
- {
- navigator->running = running;
- if(!navigator->id)
- {
- navigator->id = g_timeout_add(navigator->timeout, (GSourceFunc)cb_rstto_navigator_running, navigator);
- if (navigator->preload)
- {
- /* preload forwards */
- rstto_navigator_preload_next_img(navigator);
- }
- }
- }
- else
- {
- navigator->running = running;
- }
-}
-
-gboolean
-rstto_navigator_is_running (RsttoNavigator *navigator)
-{
- return navigator->running;
-}
-
-RsttoNavigatorEntry *
-rstto_navigator_get_file (RsttoNavigator *navigator)
-{
- if(navigator->file_iter)
- {
- return (RsttoNavigatorEntry *)(navigator->file_iter->data);
- }
- else
- {
- return NULL;
- }
-}
-
-gint
-rstto_navigator_get_position(RsttoNavigator *navigator)
-{
- return g_list_position(navigator->file_list, navigator->file_iter);
-}
-
-gint
-rstto_navigator_get_n_files (RsttoNavigator *navigator)
-{
- return g_list_length(navigator->file_list);
-}
-
-RsttoNavigatorEntry *
-rstto_navigator_get_nth_file (RsttoNavigator *navigator, gint n)
-{
- return g_list_nth_data(navigator->file_list, n);
-}
-
-gint
-rstto_navigator_add (RsttoNavigator *navigator, RsttoNavigatorEntry *entry, gboolean with_monitor)
-{
- g_return_val_if_fail(navigator == entry->navigator, -1);
-
- if (g_list_index(navigator->file_list, entry) == -1)
- {
- navigator->file_list = g_list_insert_sorted(navigator->file_list, entry, navigator->compare_func);
- if (!navigator->file_iter)
- {
- navigator->file_iter = navigator->file_list;
- if (navigator->busy == FALSE)
- {
- g_signal_emit(G_OBJECT(navigator),
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED],
- 0,
- g_list_index(navigator->file_list, entry),
- entry,
- NULL);
- }
- }
-
- if (with_monitor == TRUE)
- entry->monitor_handle = thunar_vfs_monitor_add_file(navigator->monitor, entry->info->path, (ThunarVfsMonitorCallback)cb_rstto_navigator_entry_fs_event, entry);
-
- if (navigator->busy == FALSE)
- {
- g_signal_emit(G_OBJECT(navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_NEW_ENTRY], 0, g_list_index(navigator->file_list, entry), entry, NULL);
- }
- }
- return g_list_index(navigator->file_list, entry);
-}
-
-void
-rstto_navigator_remove (RsttoNavigator *navigator, RsttoNavigatorEntry *entry)
-{
- if(navigator->file_iter)
- {
- if(navigator->file_iter->data == entry)
- {
- navigator->old_position = rstto_navigator_get_position(navigator);
- navigator->file_iter = g_list_next(navigator->file_iter);
-
- navigator->file_list = g_list_remove(navigator->file_list, entry);
-
- if(!navigator->file_iter)
- navigator->file_iter = g_list_first(navigator->file_list);
-
- /* An item should not be able to exist several times inside the
- * history, g_list_remove should suffice here
- */
- if (navigator->history)
- {
- navigator->history = g_list_remove (navigator->history, entry);
- }
-
- if (navigator->busy == FALSE)
- {
- g_signal_emit(G_OBJECT(navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ENTRY_REMOVED], 0, entry, NULL);
- }
- if(g_list_length(navigator->file_list) == 0)
- {
- navigator->file_iter = NULL;
- navigator->file_list = NULL;
- }
- if(navigator->file_iter)
- {
- if (navigator->busy == FALSE)
- {
- g_signal_emit(G_OBJECT(navigator),
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED],
- 0,
- g_list_position(navigator->file_list, navigator->file_iter),
- navigator->file_iter->data,
- NULL);
- }
- }
- else
- {
- g_signal_emit(G_OBJECT(navigator),
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED],
- 0,
- -1,
- NULL,
- NULL);
-
- }
- return;
- }
- if (g_list_find(navigator->history, entry))
- {
- navigator->history = g_list_remove(navigator->history, entry);
- }
- }
- navigator->file_list = g_list_remove(navigator->file_list, entry);
- if (entry->monitor_handle)
- {
- thunar_vfs_monitor_remove(navigator->monitor, entry->monitor_handle);
- }
- if(g_list_length(navigator->file_list) == 0)
- {
- navigator->file_iter = NULL;
- navigator->file_list = NULL;
- }
-}
-
-void
-rstto_navigator_clear (RsttoNavigator *navigator)
-{
- if(navigator->file_list)
- {
- g_list_free(navigator->history);
- g_list_foreach(navigator->file_list, (GFunc)rstto_navigator_entry_free, NULL);
- navigator->file_list = NULL;
- navigator->file_iter = NULL;
- navigator->old_position = -1;
- navigator->history = NULL;
- }
- g_signal_emit(G_OBJECT(navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED], 0, -1, NULL, NULL);
- g_signal_emit(G_OBJECT(navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_REORDERED], 0, NULL);
-}
-
-void
-rstto_navigator_set_file_nr (RsttoNavigator *navigator, gint n)
-{
- if(navigator->file_iter)
- {
- rstto_navigator_guard_history(navigator, navigator->file_iter->data);
- navigator->old_position = rstto_navigator_get_position(navigator);
- }
- navigator->file_iter = g_list_nth(navigator->file_list, n);
- if(navigator->file_iter)
- {
- g_signal_emit(G_OBJECT(navigator),
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED],
- 0,
- g_list_position(navigator->file_list, navigator->file_iter),
- navigator->file_iter->data,
- NULL);
- }
-}
-
-/* Callbacks */
-
-static gboolean
-cb_rstto_navigator_running(RsttoNavigator *navigator)
-{
- if(navigator->running)
- {
- rstto_navigator_jump_forward(navigator);
-
- if (navigator->preload)
- {
- /* preload forwards */
- rstto_navigator_preload_next_img(navigator);
- }
- }
- else
- {
- navigator->id = 0;
- }
- return navigator->running;
-}
-
-void
-rstto_navigator_set_timeout (RsttoNavigator *navigator, gint timeout)
-{
- navigator->timeout = timeout;
-}
-
-void
-rstto_navigator_flip_entry(RsttoNavigator *navigator, RsttoNavigatorEntry *entry, gboolean horizontal)
-{
- if (horizontal)
- {
- entry->h_flipped = !entry->h_flipped;
- }
- else
- {
- entry->v_flipped = !entry->v_flipped;
- }
-}
-
-
-RsttoNavigatorEntry *
-rstto_navigator_entry_new (RsttoNavigator *navigator, ThunarVfsInfo *info)
-{
- RsttoNavigatorEntry *entry = NULL;
- ExifEntry *exifentry = NULL;
- gchar *filename = thunar_vfs_path_dup_string(info->path);
- if(filename)
- {
- GList *iter = g_list_find_custom(navigator->file_list, info->path, (GCompareFunc)cb_rstto_navigator_entry_path_compare_func);
- if (iter)
- entry = iter->data;
-
- if (entry == NULL)
- {
- entry = g_new0(RsttoNavigatorEntry, 1);
-
- entry->info = info;
- entry->exif_data = exif_data_new_from_file(filename);
- entry->navigator = navigator;
- entry->animation = NULL;
-
- if (entry->exif_data) {
- exifentry = exif_data_get_entry(entry->exif_data, EXIF_TAG_ORIENTATION);
- }
- if (exifentry)
- {
- gchar *val = g_new0(gchar, 20);
- exif_entry_get_value(exifentry, val, 20);
- if (!strcmp(val, "top - left"))
- {
- entry->v_flipped = FALSE;
- entry->h_flipped = FALSE;
- entry->rotation = GDK_PIXBUF_ROTATE_NONE;
- }
- if (!strcmp(val, "top - right"))
- {
- entry->v_flipped = FALSE;
- entry->h_flipped = TRUE;
- entry->rotation = GDK_PIXBUF_ROTATE_NONE;
- }
- if (!strcmp(val, "bottom - left"))
- {
- entry->v_flipped = TRUE;
- entry->h_flipped = FALSE;
- entry->rotation = GDK_PIXBUF_ROTATE_NONE;
- }
- if (!strcmp(val, "bottom - right"))
- {
- entry->v_flipped = FALSE;
- entry->h_flipped = FALSE;
- entry->rotation = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
- }
- if (!strcmp(val, "right - top"))
- {
- entry->v_flipped = FALSE;
- entry->h_flipped = FALSE;
- entry->rotation = GDK_PIXBUF_ROTATE_CLOCKWISE;
- }
- if (!strcmp(val, "right - bottom"))
- {
- entry->v_flipped = FALSE;
- entry->h_flipped = TRUE;
- entry->rotation = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
- }
- if (!strcmp(val, "left - top"))
- {
- entry->v_flipped = FALSE;
- entry->h_flipped = TRUE;
- entry->rotation = GDK_PIXBUF_ROTATE_CLOCKWISE;
- }
- if (!strcmp(val, "left - bottom"))
- {
- entry->v_flipped = FALSE;
- entry->h_flipped = FALSE;
- entry->rotation = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
- }
- g_free(val);
- }
- }
-
- g_free(filename);
- }
- return entry;
-}
-
-ThunarVfsInfo *
-rstto_navigator_entry_get_info (RsttoNavigatorEntry *entry)
-{
- return entry->info;
-}
-
-GdkPixbufRotation
-rstto_navigator_entry_get_rotation (RsttoNavigatorEntry *entry)
-{
- return entry->rotation;
-}
-
-gboolean
-rstto_navigator_entry_get_flip (RsttoNavigatorEntry *entry, gboolean horizontal)
-{
- if (horizontal)
- {
- return entry->h_flipped;
- }
- else
- {
- return entry->v_flipped;
- }
-}
-
-static void
-rstto_navigator_entry_clear (RsttoNavigatorEntry *nav_entry)
-{
- if(nav_entry->thumb)
- {
- gdk_pixbuf_unref(nav_entry->thumb);
- nav_entry->thumb = NULL;
- }
-
- if(nav_entry->io_channel)
- {
- g_source_remove(nav_entry->io_source_id);
- g_io_channel_unref(nav_entry->io_channel);
- nav_entry->io_channel = NULL;
- nav_entry->io_source_id = 0;
- }
-
- if (nav_entry->timeout_id)
- {
- g_source_remove(nav_entry->timeout_id);
- nav_entry->timeout_id = 0;
- }
-
- if(nav_entry->loader)
- {
- g_signal_handlers_disconnect_by_func(nav_entry->loader , cb_rstto_navigator_entry_area_prepared, nav_entry);
- gdk_pixbuf_loader_close(nav_entry->loader, NULL);
- }
-
- if(nav_entry->animation)
- {
- g_object_unref(nav_entry->animation);
- nav_entry->animation = NULL;
- }
- if(nav_entry->src_pixbuf)
- {
- g_object_unref(nav_entry->src_pixbuf);
- nav_entry->src_pixbuf = NULL;
- }
-
- if(nav_entry->iter)
- {
- g_object_unref (nav_entry->iter);
- nav_entry->iter = NULL;
- }
-
-}
-
-void
-rstto_navigator_entry_free(RsttoNavigatorEntry *nav_entry)
-{
- rstto_navigator_entry_clear (nav_entry);
- thunar_vfs_info_unref(nav_entry->info);
- g_free(nav_entry);
-}
-
-GdkPixbuf *
-rstto_navigator_entry_get_thumb(RsttoNavigatorEntry *entry, gint size)
-{
- ThunarVfsPath *home_path = thunar_vfs_path_get_for_home();
- ThunarVfsPath *thumbnail_path = thunar_vfs_path_relative (home_path, ".thumbnails");
- if(entry->thumb)
- {
- if(!(gdk_pixbuf_get_width(entry->thumb) == size || gdk_pixbuf_get_height(entry->thumb) == size))
- {
- /* TODO: rebuild thumbnail */
- }
- }
- else
- {
- ThunarVfsInfo *info = rstto_navigator_entry_get_info(entry);
- gchar *thumbnail = thunar_vfs_thumb_factory_lookup_thumbnail(entry->navigator->factory, info);
- if (thumbnail == NULL)
- {
- if (!thunar_vfs_path_is_ancestor (info->path, thumbnail_path))
- {
- GdkPixbuf *pixbuf = thunar_vfs_thumb_factory_generate_thumbnail(entry->navigator->factory, info);
- if (pixbuf != NULL)
- {
- if (!thunar_vfs_thumb_factory_store_thumbnail(entry->navigator->factory, pixbuf, info, NULL))
- {
- g_critical("Storing thumbnail failed");
- }
-
- gint width = gdk_pixbuf_get_width(pixbuf);
- gint height = gdk_pixbuf_get_height(pixbuf);
-
- if (width > height)
- {
- entry->thumb = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
- gdk_pixbuf_get_has_alpha(pixbuf),
- gdk_pixbuf_get_bits_per_sample(pixbuf),
- size,
- height*size/width);
- }
- else
- {
- entry->thumb = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
- gdk_pixbuf_get_has_alpha(pixbuf),
- gdk_pixbuf_get_bits_per_sample(pixbuf),
- width*size/height,
- size);
- }
- gdk_pixbuf_scale(pixbuf, entry->thumb,
- 0, 0,
- gdk_pixbuf_get_width(entry->thumb),
- gdk_pixbuf_get_height(entry->thumb),
- 0, 0,
- ((gdouble)gdk_pixbuf_get_width(entry->thumb)) / (gdouble)width,
- ((gdouble)gdk_pixbuf_get_height(entry->thumb)) / (gdouble)height,
- GDK_INTERP_BILINEAR);
- }
- else
- {
- thumbnail = thunar_vfs_path_dup_string(info->path);
- entry->thumb = gdk_pixbuf_new_from_file_at_scale(thumbnail, size, size, TRUE, NULL);
- g_free(thumbnail);
- }
- }
- else
- {
- GtkIconTheme *theme = gtk_icon_theme_get_default();
- entry->thumb = gtk_icon_theme_load_icon (theme, thunar_vfs_mime_info_lookup_icon_name (info->mime_info, theme), size, 0, NULL);
- }
- }
- else
- {
- entry->thumb = gdk_pixbuf_new_from_file_at_scale(thumbnail, size, size, TRUE, NULL);
- g_free(thumbnail);
- }
- }
- return entry->thumb;
-}
-
-gint
-rstto_navigator_get_old_position (RsttoNavigator *navigator)
-{
- return navigator->old_position;
-}
-
-gdouble
-rstto_navigator_entry_get_scale (RsttoNavigatorEntry *entry)
-{
- return entry->scale;
-}
-
-void
-rstto_navigator_entry_set_scale (RsttoNavigatorEntry *entry, gdouble scale)
-{
- if (scale == 0.0)
- {
- entry->scale = scale;
- return;
- }
- /* Max scale 1600% */
- if (scale > 16)
- {
- scale = 16;
- }
- /* Min scale 5% */
- if (scale < 0.05)
- {
- scale = 0.05;
- }
- entry->scale = scale;
-}
-
-gboolean
-rstto_navigator_entry_get_fit_to_screen (RsttoNavigatorEntry *entry)
-{
- return entry->fit_to_screen;
-}
-
-void
-rstto_navigator_entry_set_fit_to_screen (RsttoNavigatorEntry *entry, gboolean fts)
-{
- entry->fit_to_screen = fts;
-}
-
-void
-rstto_navigator_entry_set_rotation (RsttoNavigatorEntry *entry, GdkPixbufRotation rotation)
-{
- GdkPixbuf *pixbuf = entry->src_pixbuf;
- if (pixbuf)
- {
- entry->src_pixbuf = gdk_pixbuf_rotate_simple(pixbuf, (360+(rotation-entry->rotation))%360);
- }
- entry->rotation = rotation;
- entry->orientation_changed = TRUE;
- g_signal_emit(G_OBJECT(entry->navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ENTRY_MODIFIED], 0, entry, NULL);
-}
-
-
-ExifData *
-rstto_navigator_entry_get_exif_data (RsttoNavigatorEntry *entry)
-{
- return entry->exif_data;
-}
-
-
-GdkPixbufLoader *
-rstto_navigator_entry_get_pixbuf_loader (RsttoNavigatorEntry *entry)
-{
- if (!entry->loader)
- {
- entry->loader = gdk_pixbuf_loader_new();
- }
- return entry->loader;
-}
-
-GdkPixbuf *
-rstto_navigator_entry_get_pixbuf (RsttoNavigatorEntry *entry)
-{
- return entry->src_pixbuf;
-}
-
-guint64
-rstto_navigator_entry_get_size (RsttoNavigatorEntry *entry)
-{
- guint64 size = 0;
-
- gint width, height, n_channels;
-
- if (entry->src_pixbuf)
- {
- width = gdk_pixbuf_get_rowstride(entry->src_pixbuf);
- height = gdk_pixbuf_get_height(entry->src_pixbuf);
-
- n_channels = gdk_pixbuf_get_n_channels(entry->src_pixbuf);
-
- //size += (guint64) width * height * n_channels;
- size += (guint64) width * height;
- }
- if (entry->thumb)
- {
- width = gdk_pixbuf_get_rowstride(entry->thumb);
- height = gdk_pixbuf_get_height(entry->thumb);
-
- n_channels = gdk_pixbuf_get_n_channels(entry->thumb);
- //size += (guint64) width * height * n_channels;
- size += (guint64) width * height;
- }
-
- size += (guint64)sizeof (RsttoNavigatorEntry);
-
- return size;
-}
-
-gboolean
-rstto_navigator_entry_get_orientation_changed (RsttoNavigatorEntry *entry)
-{
- return entry->orientation_changed;
-}
-
-gboolean
-rstto_navigator_entry_load_image (RsttoNavigatorEntry *entry, gboolean empty_cache)
-{
- g_return_val_if_fail(entry != NULL, FALSE);
- gchar *path = NULL;
-
- if (entry->io_channel)
- {
- return FALSE;
- }
- if ((entry->loader == NULL) && ((empty_cache == TRUE ) || entry->src_pixbuf == NULL))
- {
- if (entry->src_pixbuf)
- {
- gdk_pixbuf_unref(entry->src_pixbuf);
- entry->src_pixbuf = NULL;
- }
- entry->loader = gdk_pixbuf_loader_new();
-
- g_signal_connect(entry->loader, "area-prepared", G_CALLBACK(cb_rstto_navigator_entry_area_prepared), entry);
- /*g_signal_connect(entry->loader, "area-updated", G_CALLBACK(cb_rstto_navigator_entry_area_updated), viewer);*/
- g_signal_connect(entry->loader, "closed", G_CALLBACK(cb_rstto_navigator_entry_closed), entry);
-
- path = thunar_vfs_path_dup_string(entry->info->path);
-
- entry->io_channel = g_io_channel_new_file(path, "r", NULL);
-
- g_io_channel_set_encoding(entry->io_channel, NULL, NULL);
- entry->io_source_id = g_io_add_watch(entry->io_channel, G_IO_IN | G_IO_PRI, (GIOFunc)cb_rstto_navigator_entry_read_file, entry);
- g_free(path);
- }
- else
- {
- if (entry->src_pixbuf)
- {
- g_signal_emit(G_OBJECT(entry->navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ENTRY_MODIFIED], 0, entry, NULL);
- }
- }
-
- return TRUE;
-}
-
-
-static gboolean
-cb_rstto_navigator_entry_read_file(GIOChannel *io_channel, GIOCondition cond, RsttoNavigatorEntry *entry)
-{
- gchar buffer[1024];
- gsize bytes_read = 0;
- GError *error = NULL;
- GIOStatus status;
-
- g_return_val_if_fail(io_channel == entry->io_channel, FALSE);
-
- if (entry->loader)
- {
-
- status = g_io_channel_read_chars(io_channel, buffer, 1024, &bytes_read, &error);
-
- switch (status)
- {
- case G_IO_STATUS_NORMAL:
- if(gdk_pixbuf_loader_write(entry->loader, (const guchar *)buffer, bytes_read, NULL) == FALSE)
- {
- g_io_channel_unref(io_channel);
- entry->io_channel = NULL;
- entry->io_source_id = 0;
- return FALSE;
- }
- return TRUE;
- break;
- case G_IO_STATUS_EOF:
- gdk_pixbuf_loader_write(entry->loader, (const guchar *)buffer, bytes_read, NULL);
- gdk_pixbuf_loader_close(entry->loader, NULL);
- g_io_channel_unref(io_channel);
- entry->io_channel = NULL;
- entry->io_source_id = 0;
- return FALSE;
- break;
- case G_IO_STATUS_ERROR:
- if (entry->loader)
- {
- gdk_pixbuf_loader_close(entry->loader, NULL);
- }
- g_io_channel_unref(io_channel);
- entry->io_channel = NULL;
- entry->io_source_id = 0;
- return FALSE;
- break;
- case G_IO_STATUS_AGAIN:
- return TRUE;
- break;
- }
- }
- g_io_channel_unref(io_channel);
- entry->io_channel = NULL;
- entry->io_source_id = 0;
- return FALSE;
-}
-
-static void
-cb_rstto_navigator_entry_area_prepared (GdkPixbufLoader *loader, RsttoNavigatorEntry *entry)
-{
- entry->animation = gdk_pixbuf_loader_get_animation(loader);
- entry->iter = gdk_pixbuf_animation_get_iter(entry->animation, NULL);
- if (entry->src_pixbuf)
- {
- gdk_pixbuf_unref(entry->src_pixbuf);
- entry->src_pixbuf = NULL;
- }
-
- g_object_ref (entry->animation);
-
- gint time = gdk_pixbuf_animation_iter_get_delay_time(entry->iter);
-
- if (time != -1)
- {
- /* fix borked stuff */
- if (time == 0)
- {
- g_warning("timeout == 0: defaulting to 40ms");
- time = 40;
- }
-
- entry->timeout_id = g_timeout_add(time, (GSourceFunc)cb_rstto_navigator_entry_update_image, entry);
- }
- else
- {
- entry->iter = NULL;
- }
- g_signal_emit(G_OBJECT(entry->navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ENTRY_MODIFIED], 0, entry, NULL);
-}
-
-static void
-cb_rstto_navigator_entry_closed (GdkPixbufLoader *loader, RsttoNavigatorEntry *entry)
-{
- GdkPixbuf *pixbuf = NULL;
-
- if (entry->src_pixbuf)
- {
- gdk_pixbuf_unref(entry->src_pixbuf);
- entry->src_pixbuf = NULL;
- }
-
- if (entry->iter)
- {
- pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(entry->iter);
- }
- else
- {
- if (entry->loader)
- {
- pixbuf = gdk_pixbuf_loader_get_pixbuf(entry->loader);
- }
- }
-
- if (entry->loader == loader)
- {
- g_object_unref(entry->loader);
- entry->loader = NULL;
- }
-
-
- if (pixbuf != NULL)
- {
- entry->src_pixbuf = gdk_pixbuf_rotate_simple(pixbuf, rstto_navigator_entry_get_rotation(entry));
- gdk_pixbuf_unref(pixbuf);
- pixbuf = NULL;
- if (rstto_navigator_entry_get_flip(entry, FALSE))
- {
- pixbuf = entry->src_pixbuf;
- entry->src_pixbuf = gdk_pixbuf_flip(pixbuf, FALSE);
- gdk_pixbuf_unref(pixbuf);
- pixbuf = NULL;
- }
-
- if (rstto_navigator_entry_get_flip(entry, TRUE))
- {
- pixbuf = entry->src_pixbuf;
- entry->src_pixbuf = gdk_pixbuf_flip(pixbuf, TRUE);
- gdk_pixbuf_unref(pixbuf);
- pixbuf = NULL;
- }
- g_signal_emit(G_OBJECT(entry->navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ENTRY_MODIFIED], 0, entry, NULL);
- }
-}
-
-static gboolean
-cb_rstto_navigator_entry_update_image (RsttoNavigatorEntry *entry)
-{
- GdkPixbuf *src_pixbuf = NULL;
-
- if (entry->iter)
- {
- if(gdk_pixbuf_animation_iter_advance(entry->iter, NULL))
- {
- /* Cleanup old image */
- if (entry->src_pixbuf)
- {
- gdk_pixbuf_unref(entry->src_pixbuf);
- entry->src_pixbuf = NULL;
- }
- entry->src_pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(entry->iter);
- src_pixbuf = entry->src_pixbuf;
-
- if (src_pixbuf)
- {
- entry->src_pixbuf = gdk_pixbuf_rotate_simple(src_pixbuf, rstto_navigator_entry_get_rotation(entry));
- if (rstto_navigator_entry_get_flip(entry, FALSE))
- {
- src_pixbuf = entry->src_pixbuf;
- entry->src_pixbuf = gdk_pixbuf_flip(src_pixbuf, FALSE);
- gdk_pixbuf_unref(src_pixbuf);
- }
-
- if (rstto_navigator_entry_get_flip(entry, TRUE))
- {
- src_pixbuf = entry->src_pixbuf;
- entry->src_pixbuf = gdk_pixbuf_flip(src_pixbuf, TRUE);
- gdk_pixbuf_unref(src_pixbuf);
- }
- }
- }
-
- gint time = gdk_pixbuf_animation_iter_get_delay_time(entry->iter);
- if (time != -1)
- {
- if (time == 0)
- {
- g_warning("timeout == 0: defaulting to 40ms");
- time = 40;
- }
- entry->timeout_id = g_timeout_add(time, (GSourceFunc)cb_rstto_navigator_entry_update_image, entry);
- }
- g_signal_emit(G_OBJECT(entry->navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ENTRY_MODIFIED], 0, entry, NULL);
-
- return FALSE;
- }
- return TRUE;
-}
-
-static void
-cb_rstto_navigator_entry_fs_event (ThunarVfsMonitor *monitor,
- ThunarVfsMonitorHandle *handl,
- ThunarVfsMonitorEvent event,
- ThunarVfsPath *handle_path,
- ThunarVfsPath *event_path,
- RsttoNavigatorEntry *entry)
-{
- switch (event)
- {
- case THUNAR_VFS_MONITOR_EVENT_CHANGED:
- rstto_navigator_entry_load_image (entry, TRUE);
- break;
- case THUNAR_VFS_MONITOR_EVENT_CREATED:
- break;
- case THUNAR_VFS_MONITOR_EVENT_DELETED:
- rstto_navigator_remove(entry->navigator, entry);
- rstto_navigator_entry_free(entry);
- break;
- default:
- break;
- }
-}
-
-static void
-cb_rstto_navigator_fs_event (ThunarVfsMonitor *monitor,
- ThunarVfsMonitorHandle *handl,
- ThunarVfsMonitorEvent event,
- ThunarVfsPath *handle_path,
- ThunarVfsPath *event_path,
- RsttoNavigator *nav)
-{
- RsttoNavigatorEntry *entry = NULL;
- GList *iter = g_list_find_custom(nav->file_list, event_path, (GCompareFunc)cb_rstto_navigator_entry_path_compare_func);
- if (iter != NULL)
- entry = iter->data;
-
- switch (event)
- {
- case THUNAR_VFS_MONITOR_EVENT_CHANGED:
- if(entry)
- {
- rstto_navigator_entry_load_image (entry, TRUE);
- }
- break;
- case THUNAR_VFS_MONITOR_EVENT_CREATED:
- if (entry)
- {
- g_critical("File created... yet it is already here");
- rstto_navigator_remove(entry->navigator, entry);
- rstto_navigator_entry_free(entry);
- }
-
- ThunarVfsInfo *info = thunar_vfs_info_new_for_path(event_path, NULL);
- if (info)
- {
- gchar *file_media = thunar_vfs_mime_info_get_media(info->mime_info);
- if(!strcmp(file_media, "image"))
- {
- entry = rstto_navigator_entry_new(nav, info);
- rstto_navigator_add (nav, entry, FALSE);
- }
- g_free(file_media);
- }
- break;
- case THUNAR_VFS_MONITOR_EVENT_DELETED:
- if(entry)
- {
- rstto_navigator_remove(entry->navigator, entry);
- rstto_navigator_entry_free(entry);
- }
- break;
- default:
- break;
- }
-}
-
-void
-rstto_navigator_entry_select (RsttoNavigatorEntry *entry)
-{
- RsttoNavigator *navigator = entry->navigator;
- GList *iter = g_list_find (navigator->file_list, entry);
- if (iter)
- {
- if(navigator->file_iter)
- {
- rstto_navigator_guard_history(navigator, navigator->file_iter->data);
- navigator->old_position = rstto_navigator_get_position(navigator);
- }
-
- navigator->file_iter = iter;
-
- if (navigator->busy == FALSE)
- {
- g_signal_emit(G_OBJECT(navigator),
- rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED],
- 0,
- g_list_position(navigator->file_list, navigator->file_iter),
- navigator->file_iter->data,
- NULL);
- }
-
- if (navigator->preload)
- {
- /* preload in both directions */
- g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_next_img, navigator);
- g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_prev_img, navigator);
-
- }
- }
-
-}
-
-guint64
-rstto_navigator_get_max_history_size (RsttoNavigator *navigator)
-{
- return navigator->max_history;
-}
-
-
-
-gint
-rstto_navigator_entry_get_position(RsttoNavigatorEntry *entry)
-{
- RsttoNavigator *navigator = entry->navigator;
- GList *iter = g_list_find (navigator->file_list, entry);
- if (iter)
- {
- return g_list_position(navigator->file_list, iter);
- }
- return -1;
-}
-
-void
-rstto_navigator_set_max_history_size(RsttoNavigator *nav, guint64 size)
-{
- nav->max_history = size;
-}
-
-void
-rstto_navigator_set_monitor_handle_for_dir(RsttoNavigator *nav, ThunarVfsPath *dir_path)
-{
- if (nav->monitor_handle)
- {
- thunar_vfs_monitor_remove(nav->monitor, nav->monitor_handle);
- nav->monitor_handle = NULL;
- }
-
- if (dir_path)
- {
- nav->monitor_handle = thunar_vfs_monitor_add_directory(nav->monitor, dir_path, (ThunarVfsMonitorCallback)cb_rstto_navigator_fs_event, nav);
- }
-}
-
-static gint
-cb_rstto_navigator_entry_path_compare_func(RsttoNavigatorEntry *entry, ThunarVfsPath *path)
-{
- if (thunar_vfs_path_equal(entry->info->path, path) == TRUE)
- {
- return 0;
- }
- return 1;
-}
-
-gboolean
-rstto_navigator_entry_is_selected(RsttoNavigatorEntry *entry)
-{
- g_return_val_if_fail(RSTTO_IS_NAVIGATOR(entry->navigator), FALSE);
- g_return_val_if_fail((entry->navigator->file_iter != NULL), FALSE);
-
- if (entry == entry->navigator->file_iter->data)
- return TRUE;
- else
- return FALSE;
-}
-
-gboolean
-rstto_navigator_open_file(RsttoNavigator *navigator, const gchar *path, gboolean open_folder, GError **error)
-{
- ThunarVfsInfo *vfs_info = NULL;
- ThunarVfsPath *vfs_path = thunar_vfs_path_new(path, error);
-
- gchar *file_media = NULL;
- gchar *file_uri = NULL;
-
-
- if (vfs_path == NULL)
- {
- return FALSE;
- }
-
- vfs_info = thunar_vfs_info_new_for_path(vfs_path, error);
- if (vfs_info == NULL)
- {
- thunar_vfs_path_unref(vfs_path);
- return FALSE;
- }
-
- if(!strcmp(thunar_vfs_mime_info_get_name(vfs_info->mime_info),
- "inode/directory"))
- {
- g_set_error(error,
- g_quark_from_static_string(
- "Path refers to folder"),
- G_FILE_ERROR_ISDIR,
- "Path refers to directory\n"
- "Use rstto_navigator_open_folder instead.");
- return FALSE;
- }
-
- file_media = thunar_vfs_mime_info_get_media(vfs_info->mime_info);
- if(!strcmp(file_media, "image"))
- {
- RsttoNavigatorEntry *entry = rstto_navigator_entry_new(navigator, vfs_info);
- rstto_navigator_add (navigator, entry, TRUE);
-
- if (open_folder == TRUE)
- {
- ThunarVfsPath *parent_vfs_path = thunar_vfs_path_get_parent(vfs_path);
- thunar_vfs_path_ref(parent_vfs_path);
-
- gchar *parent_path = thunar_vfs_path_dup_string(parent_vfs_path);
-
- if(rstto_navigator_open_folder(navigator, parent_path, FALSE, error) == FALSE)
- {
- g_free(parent_path);
- thunar_vfs_path_unref(parent_vfs_path);
- return FALSE;
- }
-
- g_free(parent_path);
- thunar_vfs_path_unref(parent_vfs_path);
-
- rstto_navigator_entry_select(entry);
- }
- }
-
- file_uri = thunar_vfs_path_dup_uri(vfs_path);
- gtk_recent_manager_add_item(navigator->manager, file_uri);
- g_free(file_uri);
-
- g_free(file_media);
- return TRUE;
-}
-
-gboolean
-rstto_navigator_open_folder(RsttoNavigator *navigator, const gchar *path, gboolean clear, GError **error)
-{
- ThunarVfsInfo *vfs_info = NULL;
- ThunarVfsPath *vfs_path = thunar_vfs_path_new(path, error);
- GDir *dir = NULL;
- gchar *dir_path = NULL;
- gchar *dir_uri = NULL;
-
- rstto_navigator_set_busy(navigator, TRUE);
-
-
- if (vfs_path == NULL)
- {
- return FALSE;
- }
-
- vfs_info = thunar_vfs_info_new_for_path(vfs_path, error);
- if (vfs_info == NULL)
- {
- thunar_vfs_path_unref(vfs_path);
- return FALSE;
- }
-
- if(strcmp(thunar_vfs_mime_info_get_name(vfs_info->mime_info),
- "inode/directory"))
- {
- g_set_error(error,
- g_quark_from_static_string(
- "Path does not refer to folder"),
- G_FILE_ERROR_ISDIR,
- "Path does not refer to directory\n"
- "Use rstto_navigator_open_file instead.");
- return FALSE;
- }
-
- dir_path = thunar_vfs_path_dup_string(vfs_path);
-
- g_object_add_weak_pointer(G_OBJECT(navigator), (gpointer)navigator);
-
- dir = g_dir_open(dir_path, 0, NULL);
-
- dir_uri = thunar_vfs_path_dup_uri(vfs_path);
-
- gtk_recent_manager_add_item(navigator->manager, dir_uri);
-
-
- {
- if (clear == TRUE)
- {
- rstto_navigator_clear(navigator);
- }
- const gchar *filename = g_dir_read_name(dir);
- ThunarVfsPath *file_vfs_path = NULL;
- ThunarVfsInfo *file_vfs_info = NULL;
- gchar *file_media;
- gchar *path_name;
-
- while (filename)
- {
- path_name = g_strconcat(dir_path, "/", filename, NULL);
- file_vfs_path = thunar_vfs_path_new(path_name, NULL);
-
- if (file_vfs_path)
- {
- file_vfs_info = thunar_vfs_info_new_for_path(file_vfs_path, NULL);
- file_media = thunar_vfs_mime_info_get_media(file_vfs_info->mime_info);
-
- if (navigator == NULL)
- {
- g_free(file_media);
- thunar_vfs_path_unref(file_vfs_path);
- return FALSE;
- }
-
- if(!strcmp(file_media, "image"))
- {
- RsttoNavigatorEntry *entry = rstto_navigator_entry_new(navigator, file_vfs_info);
- rstto_navigator_add (navigator, entry, FALSE);
- }
-
- g_free(file_media);
- thunar_vfs_path_unref(file_vfs_path);
- while (gtk_events_pending())
- {
- gtk_main_iteration();
- }
- }
- g_free(path_name);
- filename = g_dir_read_name(dir);
- }
- }
-
- g_free(dir_uri);
- g_free(dir_path);
- g_object_remove_weak_pointer(G_OBJECT(navigator), (gpointer)navigator);
- rstto_navigator_set_busy(navigator, FALSE);
- return TRUE;
-}
-
-static void
-rstto_navigator_set_busy (RsttoNavigator *navigator, gboolean busy)
-{
- navigator->busy = busy;
- if (busy == FALSE)
- {
- g_signal_emit(G_OBJECT(navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_REORDERED], 0, NULL);
- }
-}
diff --git a/src/navigator.h b/src/navigator.h
deleted file mode 100644
index 0b6dab1..0000000
--- a/src/navigator.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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 Library 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.
- */
-
-#ifndef __RISTRETTO_NAVIGATOR_H__
-#define __RISTRETTO_NAVIGATOR_H__
-
-G_BEGIN_DECLS
-
-#define RSTTO_TYPE_NAVIGATOR rstto_navigator_get_type()
-
-#define RSTTO_NAVIGATOR(obj)( \
- G_TYPE_CHECK_INSTANCE_CAST ((obj), \
- RSTTO_TYPE_NAVIGATOR, \
- RsttoNavigator))
-
-#define RSTTO_IS_NAVIGATOR(obj)( \
- G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
- RSTTO_TYPE_NAVIGATOR))
-
-#define RSTTO_NAVIGATOR_CLASS(klass)( \
- G_TYPE_CHECK_CLASS_CAST ((klass), \
- RSTTO_TYPE_NAVIGATOR, \
- RsttoNavigatorClass))
-
-#define RSTTO_IS_NAVIGATOR_CLASS(klass)( \
- G_TYPE_CHECK_CLASS_TYPE ((klass), \
- RSTTO_TYPE_NAVIGATOR()))
-
-typedef struct _RsttoNavigatorEntry RsttoNavigatorEntry;
-
-typedef struct _RsttoNavigator RsttoNavigator;
-
-struct _RsttoNavigator
-{
- GObject parent;
- GtkRecentManager *manager;
- ThunarVfsMonitor *monitor;
- ThunarVfsMonitorHandle *monitor_handle;
-
- ThunarVfsThumbFactory *factory;
-
- ThunarVfsPath *path;
- GCompareFunc compare_func;
- GList *file_list;
- GList *file_iter;
- GList *history;
- guint64 max_history;
-
- gboolean preload;
-
- gint old_position;
- gboolean running;
- gint timeout;
- gint id;
-
- gboolean busy;
-};
-
-typedef struct _RsttoNavigatorClass RsttoNavigatorClass;
-struct _RsttoNavigatorClass
-{
- GObjectClass parent_class;
-};
-
-GType rstto_navigator_get_type ();
-
-RsttoNavigator *
-rstto_navigator_new (GtkRecentManager *recent_manager);
-
-void rstto_navigator_jump_first (RsttoNavigator *navigator);
-void rstto_navigator_jump_forward (RsttoNavigator *navigator);
-void rstto_navigator_jump_back (RsttoNavigator *navigator);
-void rstto_navigator_jump_last (RsttoNavigator *navigator);
-
-void rstto_navigator_set_running (RsttoNavigator *navigator,
- gboolean running);
-gboolean rstto_navigator_is_running (RsttoNavigator *navigator);
-void
-rstto_navigator_set_timeout (RsttoNavigator *nav, gint);
-
-
-RsttoNavigatorEntry *
-rstto_navigator_get_file (RsttoNavigator *navigator);
-gint
-rstto_navigator_get_position(RsttoNavigator *navigator);
-gint
-rstto_navigator_get_old_position(RsttoNavigator *navigator);
-
-gint
-rstto_navigator_add (RsttoNavigator *navigator, RsttoNavigatorEntry *entry, gboolean with_monitor);
-void
-rstto_navigator_remove (RsttoNavigator *navigator, RsttoNavigatorEntry *entry);
-gint
-rstto_navigator_get_n_files (RsttoNavigator *navigator);
-RsttoNavigatorEntry *
-rstto_navigator_get_nth_file (RsttoNavigator *navigator, gint n);
-void
-rstto_navigator_set_file_nr (RsttoNavigator *navigator, gint n);
-void
-rstto_navigator_clear (RsttoNavigator *navigator);
-
-RsttoNavigatorEntry *
-rstto_navigator_entry_new (RsttoNavigator *, ThunarVfsInfo *info);
-void
-rstto_navigator_entry_free(RsttoNavigatorEntry *nav_entry);
-ThunarVfsInfo *
-rstto_navigator_entry_get_info (RsttoNavigatorEntry *entry);
-gboolean
-rstto_navigator_entry_get_fit_to_screen (RsttoNavigatorEntry *entry);
-gdouble
-rstto_navigator_entry_get_scale (RsttoNavigatorEntry *entry);
-void
-rstto_navigator_entry_set_fit_to_screen (RsttoNavigatorEntry *entry, gboolean);
-void
-rstto_navigator_entry_set_scale (RsttoNavigatorEntry *entry, gdouble);
-void
-rstto_navigator_entry_set_rotation (RsttoNavigatorEntry *entry, GdkPixbufRotation rotation);
-gint
-rstto_navigator_entry_get_position(RsttoNavigatorEntry *entry);
-
-GdkPixbufRotation
-rstto_navigator_entry_get_rotation (RsttoNavigatorEntry *entry);
-gboolean
-rstto_navigator_entry_get_flip (RsttoNavigatorEntry *entry, gboolean horizontal);
-void
-rstto_navigator_flip_entry(RsttoNavigator *navigator, RsttoNavigatorEntry *entry, gboolean horizontal);
-GdkPixbuf *
-rstto_navigator_entry_get_thumb(RsttoNavigatorEntry *entry, gint size);
-ExifData *
-rstto_navigator_entry_get_exif_data (RsttoNavigatorEntry *entry);
-
-GdkPixbufLoader *
-rstto_navigator_entry_get_pixbuf_loader (RsttoNavigatorEntry *entry);
-GdkPixbuf *
-rstto_navigator_entry_get_pixbuf (RsttoNavigatorEntry *entry);
-gboolean
-rstto_navigator_entry_load_image (RsttoNavigatorEntry *entry, gboolean empty_cache);
-void
-rstto_navigator_entry_select (RsttoNavigatorEntry *entry);
-
-guint64
-rstto_navigator_entry_get_size (RsttoNavigatorEntry *entry);
-guint64
-rstto_navigator_get_max_history_size(RsttoNavigator *navigator);
-void
-rstto_navigator_set_max_history_size(RsttoNavigator *nav, guint64 size);
-void
-rstto_navigator_set_monitor_handle_for_dir(RsttoNavigator *nav, ThunarVfsPath *dir_path);
-
-gboolean
-rstto_navigator_entry_is_selected(RsttoNavigatorEntry *entry);
-
-gboolean
-rstto_navigator_open_file(RsttoNavigator *navigator, const gchar *path, gboolean open_folder, GError **error);
-gboolean
-rstto_navigator_open_folder(RsttoNavigator *navigator, const gchar *path, gboolean clear, GError **error);
-
-gboolean
-rstto_navigator_entry_get_orientation_changed (RsttoNavigatorEntry *entry);
-
-G_END_DECLS
-
-#endif /* __RISTRETTO_NAVIGATOR_H__ */
More information about the Xfce4-commits
mailing list