Merge common thumb code from view_file_list and view_file_icon to view_file.
authorLaurent Monin <geeqie@norz.org>
Thu, 14 May 2009 20:32:14 +0000 (20:32 +0000)
committerLaurent Monin <geeqie@norz.org>
Thu, 14 May 2009 20:32:14 +0000 (20:32 +0000)
src/view_file.c
src/view_file.h
src/view_file_icon.c
src/view_file_icon.h
src/view_file_list.c
src/view_file_list.h

index a3dead5..a031b48 100644 (file)
@@ -15,6 +15,7 @@
 #include "editors.h"
 #include "layout.h"
 #include "menu.h"
+#include "thumb.h"
 #include "ui_menu.h"
 #include "ui_fileops.h"
 #include "utilops.h"
@@ -633,15 +634,6 @@ GtkWidget *vf_pop_menu(ViewFile *vf)
        return menu;
 }
 
-void vf_thumb_update(ViewFile *vf)
-{
-       switch (vf->type)
-       {
-       case FILEVIEW_LIST: vflist_thumb_update(vf); break;
-       case FILEVIEW_ICON: vficon_thumb_update(vf); break;
-       }
-}
-
 gboolean vf_refresh(ViewFile *vf)
 {
        gboolean ret = FALSE;
@@ -788,6 +780,163 @@ void vf_thumb_set(ViewFile *vf, gboolean enable)
        }
 }
 
+
+static gboolean vf_thumb_next(ViewFile *vf);
+
+static gdouble vf_thumb_progress(ViewFile *vf)
+{
+       gint count = 0;
+       gint done = 0;
+       
+       switch (vf->type)
+       {
+       case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, &count, &done); break;
+       case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, &count, &done); break;
+       }
+       
+       DEBUG_1("thumb progress: %d of %d", done, count);
+       return (gdouble)done / count;
+}
+
+static void vf_set_thumb_fd(ViewFile *vf, FileData *fd)
+{      
+       switch (vf->type)
+       {
+       case FILEVIEW_LIST: vflist_set_thumb_fd(vf, fd); break;
+       case FILEVIEW_ICON: vficon_set_thumb_fd(vf, fd); break;
+       }
+}
+
+static void vf_thumb_status(ViewFile *vf, gdouble val, const gchar *text)
+{
+       if (vf->func_thumb_status)
+               {
+               vf->func_thumb_status(vf, val, text, vf->data_thumb_status);
+               }
+}
+
+static void vf_thumb_do(ViewFile *vf, FileData *fd)
+{
+       if (!fd) return;
+
+       vf_set_thumb_fd(vf, fd);
+       vf_thumb_status(vf, vf_thumb_progress(vf), _("Loading thumbs..."));
+}
+
+void vf_thumb_cleanup(ViewFile *vf)
+{
+       vf_thumb_status(vf, 0.0, NULL);
+
+       vf->thumbs_running = FALSE;
+
+       thumb_loader_free(vf->thumbs_loader);
+       vf->thumbs_loader = NULL;
+
+       vf->thumbs_filedata = NULL;
+}
+
+void vf_thumb_stop(ViewFile *vf)
+{
+       if (vf->thumbs_running) vf_thumb_cleanup(vf);
+}
+
+static void vf_thumb_common_cb(ThumbLoader *tl, gpointer data)
+{
+       ViewFile *vf = data;
+
+       if (vf->thumbs_filedata && vf->thumbs_loader == tl)
+               {
+               vf_thumb_do(vf, vf->thumbs_filedata);
+               }
+
+       while (vf_thumb_next(vf));
+}
+
+static void vf_thumb_error_cb(ThumbLoader *tl, gpointer data)
+{
+       vf_thumb_common_cb(tl, data);
+}
+
+static void vf_thumb_done_cb(ThumbLoader *tl, gpointer data)
+{
+       vf_thumb_common_cb(tl, data);
+}
+
+static gboolean vf_thumb_next(ViewFile *vf)
+{
+       FileData *fd = NULL;
+       gint ret;
+
+       if (!GTK_WIDGET_REALIZED(vf->listview))
+               {
+               vf_thumb_status(vf, 0.0, NULL);
+               return FALSE;
+               }
+
+       switch (vf->type)
+       {
+       case FILEVIEW_LIST: fd = vflist_thumb_next_fd(vf); break;
+       case FILEVIEW_ICON: fd = vficon_thumb_next_fd(vf); break;
+       }
+
+       if (!fd)
+               {
+               /* done */
+               vf_thumb_cleanup(vf);
+               return FALSE;
+               }
+
+       vf->thumbs_filedata = fd;
+
+       thumb_loader_free(vf->thumbs_loader);
+
+       vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
+       thumb_loader_set_callbacks(vf->thumbs_loader,
+                                  vf_thumb_done_cb,
+                                  vf_thumb_error_cb,
+                                  NULL,
+                                  vf);
+
+       if (!thumb_loader_start(vf->thumbs_loader, fd))
+               {
+               /* set icon to unknown, continue */
+               DEBUG_1("thumb loader start failed %s", fd->path);
+               vf_thumb_do(vf, fd);
+
+               return TRUE;
+               }
+
+       return FALSE;
+}
+
+static void vf_thumb_reset_all(ViewFile *vf)
+{
+       switch (vf->type)
+       {
+       case FILEVIEW_LIST: vflist_thumb_reset_all(vf); break;
+       case FILEVIEW_ICON: vficon_thumb_reset_all(vf); break;
+       }
+}
+
+void vf_thumb_update(ViewFile *vf)
+{
+       vf_thumb_stop(vf);
+       
+       if (vf->type == FILEVIEW_LIST && !VFLIST(vf)->thumbs_enabled) return;
+
+       vf_thumb_status(vf, 0.0, _("Loading thumbs..."));
+       vf->thumbs_running = TRUE;
+
+       if (thumb_format_changed)
+               {
+               vf_thumb_reset_all(vf);
+               thumb_format_changed = FALSE;
+               }
+
+       while (vf_thumb_next(vf));
+}
+
+
 void vf_marks_set(ViewFile *vf, gboolean enable)
 {
        if (vf->marks_enabled == enable) return;
index 2d90939..c83e896 100644 (file)
@@ -61,6 +61,8 @@ void vf_refresh_idle_cancel(ViewFile *vf);
 void vf_notify_cb(FileData *fd, NotifyType type, gpointer data);
 
 void vf_thumb_update(ViewFile *vf);
+void vf_thumb_cleanup(ViewFile *vf);
+void vf_thumb_stop(ViewFile *vf);
 
 #endif /* VIEW_FILE_H */
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 0ee7f9c..3b53f38 100644 (file)
@@ -1561,20 +1561,6 @@ static void vficon_clear_store(ViewFile *vf)
        gtk_list_store_clear(GTK_LIST_STORE(store));
 }
 
-static void vficon_set_thumb(ViewFile *vf, FileData *fd)
-{
-       GtkTreeModel *store;
-       GtkTreeIter iter;
-       GList *list;
-
-       if (!vficon_find_iter(vf, vficon_icon_data(vf, fd), &iter, NULL)) return;
-
-       store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
-
-       gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
-       gtk_list_store_set(GTK_LIST_STORE(store), &iter, FILE_COLUMN_POINTER, list, -1);
-}
-
 static GList *vficon_add_row(ViewFile *vf, GtkTreeIter *iter)
 {
        GtkListStore *store;
@@ -1727,7 +1713,7 @@ static void vficon_populate(ViewFile *vf, gboolean resize, gboolean keep_positio
 
 
        vf_send_update(vf);
-       vficon_thumb_update(vf);
+       vf_thumb_update(vf);
 }
 
 static void vficon_populate_at_new_size(ViewFile *vf, gint w, gint h, gboolean force)
@@ -1864,96 +1850,40 @@ void vficon_sort_set(ViewFile *vf, SortType type, gboolean ascend)
  *-----------------------------------------------------------------------------
  */
 
-static gboolean vficon_thumb_next(ViewFile *vf);
-
-static gdouble vficon_thumb_progress(ViewFile *vf)
+void vficon_thumb_progress_count(GList *list, gint *count, gint *done)
 {
-       gint count = 0;
-       gint done = 0;
-       
-       GList *work = vf->list;
+       GList *work = list;
        while (work)
                {
                IconData *id = work->data;
                FileData *fd = id->fd;
                work = work->next;
 
-               if (fd->thumb_pixbuf) done++;
-               count++;
-               }
-       DEBUG_1("thumb progress: %d of %d", done, count);
-       return (gdouble)done / count;
-}
-
-static void vficon_thumb_status(ViewFile *vf, gdouble val, const gchar *text)
-{
-       if (vf->func_thumb_status)
-               {
-               vf->func_thumb_status(vf, val, text, vf->data_thumb_status);
+               if (fd->thumb_pixbuf) (*done)++;
+               (*count)++;
                }
 }
 
-static void vficon_thumb_cleanup(ViewFile *vf)
+void vficon_set_thumb_fd(ViewFile *vf, FileData *fd)
 {
-       vficon_thumb_status(vf, 0.0, NULL);
-
-       vf->thumbs_running = FALSE;
-
-       thumb_loader_free(vf->thumbs_loader);
-       vf->thumbs_loader = NULL;
-
-       vf->thumbs_filedata = NULL;
-}
-
-static void vficon_thumb_stop(ViewFile *vf)
-{
-       if (vf->thumbs_running) vficon_thumb_cleanup(vf);
-}
-
-static void vficon_thumb_do(ViewFile *vf, ThumbLoader *tl, FileData *fd)
-{
-       if (!fd) return;
-
-       vficon_set_thumb(vf, fd);
-
-       vficon_thumb_status(vf, vficon_thumb_progress(vf), _("Loading thumbs..."));
-}
+       GtkTreeModel *store;
+       GtkTreeIter iter;
+       GList *list;
 
-static void vficon_thumb_error_cb(ThumbLoader *tl, gpointer data)
-{
-       ViewFile *vf = data;
+       if (!vficon_find_iter(vf, vficon_icon_data(vf, fd), &iter, NULL)) return;
 
-       if (vf->thumbs_filedata && vf->thumbs_loader == tl)
-               {
-               vficon_thumb_do(vf, tl, vf->thumbs_filedata);
-               }
+       store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
 
-       while (vficon_thumb_next(vf));
+       gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
+       gtk_list_store_set(GTK_LIST_STORE(store), &iter, FILE_COLUMN_POINTER, list, -1);
 }
 
-static void vficon_thumb_done_cb(ThumbLoader *tl, gpointer data)
-{
-       ViewFile *vf = data;
-
-       if (vf->thumbs_filedata && vf->thumbs_loader == tl)
-               {
-               vficon_thumb_do(vf, tl, vf->thumbs_filedata);
-               }
-
-       while (vficon_thumb_next(vf));
-}
 
-static gboolean vficon_thumb_next(ViewFile *vf)
+FileData *vficon_thumb_next_fd(ViewFile *vf)
 {
        GtkTreePath *tpath;
        FileData *fd = NULL;
 
-       if (!GTK_WIDGET_REALIZED(vf->listview))
-               {
-               vficon_thumb_status(vf, 0.0, NULL);
-               return FALSE;
-               }
-
        if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
                {
                GtkTreeModel *store;
@@ -1996,64 +1926,27 @@ static gboolean vficon_thumb_next(ViewFile *vf)
                        }
                }
 
-       if (!fd)
-               {
-               /* done */
-               vficon_thumb_cleanup(vf);
-               return FALSE;
-               }
-
-       vf->thumbs_filedata = fd;
-
-       thumb_loader_free(vf->thumbs_loader);
-
-       vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
-       thumb_loader_set_callbacks(vf->thumbs_loader,
-                                  vficon_thumb_done_cb,
-                                  vficon_thumb_error_cb,
-                                  NULL,
-                                  vf);
-
-       if (!thumb_loader_start(vf->thumbs_loader, fd))
-               {
-               /* set icon to unknown, continue */
-               DEBUG_1("thumb loader start failed %s", fd->path);
-               vficon_thumb_do(vf, vf->thumbs_loader, fd);
-
-               return TRUE;
-               }
-
-       return FALSE;
+       return fd;
 }
 
-void vficon_thumb_update(ViewFile *vf)
+void vficon_thumb_reset_all(ViewFile *vf)
 {
-       vficon_thumb_stop(vf);
+       GList *work = vf->list;
 
-       vficon_thumb_status(vf, 0.0, _("Loading thumbs..."));
-       vf->thumbs_running = TRUE;
-       
-       if (thumb_format_changed)
+       while (work)
                {
-               GList *work = vf->list;
-               while (work)
+               IconData *id = work->data;
+               FileData *fd = id->fd;
+               if (fd->thumb_pixbuf)
                        {
-                       IconData *id = work->data;
-                       FileData *fd = id->fd;
-                       if (fd->thumb_pixbuf)
-                               {
-                               g_object_unref(fd->thumb_pixbuf);
-                               fd->thumb_pixbuf = NULL;
-                               }
-                       work = work->next;
+                       g_object_unref(fd->thumb_pixbuf);
+                       fd->thumb_pixbuf = NULL;
                        }
-
-               thumb_format_changed = FALSE;
+               work = work->next;
                }
-
-       while (vficon_thumb_next(vf));
 }
 
+
 /*
  *-----------------------------------------------------------------------------
  * row stuff
@@ -2456,7 +2349,7 @@ void vficon_destroy_cb(GtkWidget *widget, gpointer data)
 
        tip_unschedule(vf);
 
-       vficon_thumb_cleanup(vf);
+       vf_thumb_cleanup(vf);
 
        iconlist_free(vf->list);
        g_list_free(VFICON(vf)->selection);
index 3193e36..b4dcbf4 100644 (file)
@@ -54,7 +54,11 @@ void vficon_select_by_fd(ViewFile *vf, FileData *fd);
 void vficon_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode);
 void vficon_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode);
 
-void vficon_thumb_update(ViewFile *vf);
+
+void vficon_thumb_progress_count(GList *list, gint *count, gint *done);
+void vficon_set_thumb_fd(ViewFile *vf, FileData *fd);
+FileData *vficon_thumb_next_fd(ViewFile *vf);
+void vficon_thumb_reset_all(ViewFile *vf);
 
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 4adda65..edb1d4f 100644 (file)
@@ -1023,9 +1023,8 @@ void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend)
  *-----------------------------------------------------------------------------
  */
 
-static gboolean vflist_thumb_next(ViewFile *vf);
 
-static void vflist_thumb_progress_count(GList *list, gint *count, gint *done)
+void vflist_thumb_progress_count(GList *list, gint *count, gint *done)
 {
        GList *work = list;
        while (work)
@@ -1043,44 +1042,7 @@ static void vflist_thumb_progress_count(GList *list, gint *count, gint *done)
                }
 }
 
-static gdouble vflist_thumb_progress(ViewFile *vf)
-{
-       gint count = 0;
-       gint done = 0;
-       
-       vflist_thumb_progress_count(vf->list, &count, &done);
-
-       DEBUG_1("thumb progress: %d of %d", done, count);
-       return (gdouble)done / count;
-}
-
-
-static void vflist_thumb_status(ViewFile *vf, gdouble val, const gchar *text)
-{
-       if (vf->func_thumb_status)
-               {
-               vf->func_thumb_status(vf, val, text, vf->data_thumb_status);
-               }
-}
-
-static void vflist_thumb_cleanup(ViewFile *vf)
-{
-       vflist_thumb_status(vf, 0.0, NULL);
-
-       vf->thumbs_running = FALSE;
-
-       thumb_loader_free(vf->thumbs_loader);
-       vf->thumbs_loader = NULL;
-
-       vf->thumbs_filedata = NULL;
-}
-
-static void vflist_thumb_stop(ViewFile *vf)
-{
-       if (vf->thumbs_running) vflist_thumb_cleanup(vf);
-}
-
-static void vflist_thumb_do(ViewFile *vf, ThumbLoader *tl, FileData *fd)
+void vflist_set_thumb_fd(ViewFile *vf, FileData *fd)
 {
        GtkTreeStore *store;
        GtkTreeIter iter;
@@ -1089,43 +1051,16 @@ static void vflist_thumb_do(ViewFile *vf, ThumbLoader *tl, FileData *fd)
 
        store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)));
        gtk_tree_store_set(store, &iter, FILE_COLUMN_THUMB, fd->thumb_pixbuf, -1);
-
-       vflist_thumb_status(vf, vflist_thumb_progress(vf), _("Loading thumbs..."));
-}
-
-static void vflist_thumb_error_cb(ThumbLoader *tl, gpointer data)
-{
-       ViewFile *vf = data;
-
-       if (vf->thumbs_filedata && vf->thumbs_loader == tl)
-               {
-               vflist_thumb_do(vf, tl, vf->thumbs_filedata);
-               }
-
-       while (vflist_thumb_next(vf));
 }
 
-static void vflist_thumb_done_cb(ThumbLoader *tl, gpointer data)
-{
-       ViewFile *vf = data;
-
-       if (vf->thumbs_filedata && vf->thumbs_loader == tl)
-               {
-               vflist_thumb_do(vf, tl, vf->thumbs_filedata);
-               }
-
-       while (vflist_thumb_next(vf));
-}
-
-static gboolean vflist_thumb_next(ViewFile *vf)
+FileData *vflist_thumb_next_fd(ViewFile *vf)
 {
        GtkTreePath *tpath;
        FileData *fd = NULL;
 
        /* first check the visible files */
 
-       if (GTK_WIDGET_REALIZED(vf->listview) &&
-           gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
+       if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
                {
                GtkTreeModel *store;
                GtkTreeIter iter;
@@ -1172,62 +1107,23 @@ static gboolean vflist_thumb_next(ViewFile *vf)
                        }
                }
 
-       if (!fd)
-               {
-               /* done */
-               vflist_thumb_cleanup(vf);
-               return FALSE;
-               }
-
-       vf->thumbs_filedata = fd;
-
-       thumb_loader_free(vf->thumbs_loader);
-
-       vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
-       thumb_loader_set_callbacks(vf->thumbs_loader,
-                                  vflist_thumb_done_cb,
-                                  vflist_thumb_error_cb,
-                                  NULL,
-                                  vf);
-
-       if (!thumb_loader_start(vf->thumbs_loader, fd))
-               {
-               /* set icon to unknown, continue */
-               DEBUG_1("thumb loader start failed %s", fd->path);
-               vflist_thumb_do(vf, vf->thumbs_loader, fd);
-
-               return TRUE;
-               }
-
-       return FALSE;
+       return fd;
 }
 
-void vflist_thumb_update(ViewFile *vf)
-{
-       vflist_thumb_stop(vf);
-       if (!VFLIST(vf)->thumbs_enabled) return;
-
-       vflist_thumb_status(vf, 0.0, _("Loading thumbs..."));
-       vf->thumbs_running = TRUE;
 
-       if (thumb_format_changed)
+void vflist_thumb_reset_all(ViewFile *vf)
+{
+       GList *work = vf->list;
+       while (work)
                {
-               GList *work = vf->list;
-               while (work)
+               FileData *fd = work->data;
+               if (fd->thumb_pixbuf)
                        {
-                       FileData *fd = work->data;
-                       if (fd->thumb_pixbuf)
-                               {
-                               g_object_unref(fd->thumb_pixbuf);
-                               fd->thumb_pixbuf = NULL;
-                               }
-                       work = work->next;
+                       g_object_unref(fd->thumb_pixbuf);
+                       fd->thumb_pixbuf = NULL;
                        }
-
-               thumb_format_changed = FALSE;
+               work = work->next;
                }
-
-       while (vflist_thumb_next(vf));
 }
 
 /*
@@ -1732,7 +1628,7 @@ static void vflist_populate_view(ViewFile *vf)
        store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)));
        thumbs_enabled = VFLIST(vf)->thumbs_enabled;
 
-       vflist_thumb_stop(vf);
+       vf_thumb_stop(vf);
 
        if (!vf->list)
                {
@@ -1756,7 +1652,7 @@ static void vflist_populate_view(ViewFile *vf)
        filelist_free(selected);
        
        vf_send_update(vf);
-       vflist_thumb_update(vf);
+       vf_thumb_update(vf);
 }
 
 gboolean vflist_refresh(ViewFile *vf)
@@ -1969,7 +1865,7 @@ void vflist_destroy_cb(GtkWidget *widget, gpointer data)
 
        vflist_select_idle_cancel(vf);
        vf_refresh_idle_cancel(vf);
-       vflist_thumb_stop(vf);
+       vf_thumb_stop(vf);
 
        filelist_free(vf->list);
 }
index 6c90ffe..edc825c 100644 (file)
@@ -58,7 +58,11 @@ void vflist_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
 void vflist_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode);
 
 void vflist_color_set(ViewFile *vf, FileData *fd, gboolean color_set);
-void vflist_thumb_update(ViewFile *vf);
+
+void vflist_thumb_progress_count(GList *list, gint *count, gint *done);
+void vflist_set_thumb_fd(ViewFile *vf, FileData *fd);
+FileData *vflist_thumb_next_fd(ViewFile *vf);
+void vflist_thumb_reset_all(ViewFile *vf);
 
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */