more robust thumbs progress bar
authorVladimir Nadvornik <nadvornik@suse.cz>
Tue, 17 Jun 2008 20:25:05 +0000 (20:25 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Tue, 17 Jun 2008 20:25:05 +0000 (20:25 +0000)
src/typedefs.h
src/view_file.c
src/view_file_icon.c
src/view_file_list.c

index 2293497..d5c9c82 100644 (file)
@@ -634,7 +634,6 @@ struct _ViewFile
 
        /* thumbs updates*/
        gint thumbs_running;
-       gint thumbs_count;
        ThumbLoader *thumbs_loader;
        FileData *thumbs_filedata;
 
index 2980b30..a578558 100644 (file)
@@ -671,7 +671,6 @@ ViewFile *vf_new(FileViewType type, FileData *dir_fd)
        vf->sort_ascend = TRUE;
        
        vf->thumbs_running = FALSE;
-       vf->thumbs_count = 0;
        vf->thumbs_loader = NULL;
        vf->thumbs_filedata = NULL;
 
index 09acead..9a31de9 100644 (file)
@@ -1794,6 +1794,25 @@ void vficon_sort_set(ViewFile *vf, SortType type, gint ascend)
 
 static gint vficon_thumb_next(ViewFile *vf);
 
+static gdouble vficon_thumb_progress(ViewFile *vf)
+{
+       gint count = 0;
+       gint done = 0;
+       
+       GList *work = vf->list;
+       while (work)
+               {
+               IconData *id = work->data;
+               FileData *fd = id->fd;
+               work = work->next;
+
+               if (fd->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)
@@ -1806,7 +1825,6 @@ static void vficon_thumb_cleanup(ViewFile *vf)
 {
        vficon_thumb_status(vf, 0.0, NULL);
 
-       vf->thumbs_count = 0;
        vf->thumbs_running = FALSE;
 
        thumb_loader_free(vf->thumbs_loader);
@@ -1826,7 +1844,7 @@ static void vficon_thumb_do(ViewFile *vf, ThumbLoader *tl, FileData *fd)
 
        vficon_set_thumb(vf, fd);
 
-       vficon_thumb_status(vf, (gdouble)(vf->thumbs_count) / g_list_length(vf->list), _("Loading thumbs..."));
+       vficon_thumb_status(vf, vficon_thumb_progress(vf), _("Loading thumbs..."));
 }
 
 static void vficon_thumb_error_cb(ThumbLoader *tl, gpointer data)
@@ -1913,8 +1931,6 @@ static gint vficon_thumb_next(ViewFile *vf)
                return FALSE;
                }
 
-       vf->thumbs_count++;
-
        vf->thumbs_filedata = fd;
 
        thumb_loader_free(vf->thumbs_loader);
index 4af7855..728aecc 100644 (file)
@@ -975,6 +975,36 @@ void vflist_sort_set(ViewFile *vf, SortType type, gint ascend)
 
 static gint vflist_thumb_next(ViewFile *vf);
 
+static void vflist_thumb_progress_count(GList *list, gint *count, gint *done)
+{
+       GList *work = list;
+       while (work)
+               {
+               FileData *fd = work->data;
+               work = work->next;
+
+               if (fd->pixbuf) (*done)++;
+               
+               if (fd->sidecar_files) 
+                       {
+                       vflist_thumb_progress_count(fd->sidecar_files, count, done);
+                       }
+               (*count)++;
+               }
+}
+
+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)
@@ -987,7 +1017,6 @@ static void vflist_thumb_cleanup(ViewFile *vf)
 {
        vflist_thumb_status(vf, 0.0, NULL);
 
-       vf->thumbs_count = 0;
        vf->thumbs_running = FALSE;
 
        thumb_loader_free(vf->thumbs_loader);
@@ -1011,7 +1040,7 @@ 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->pixbuf, -1);
 
-       vflist_thumb_status(vf, (gdouble)(vf->thumbs_count) / vflist_sidecar_list_count(vf->list), _("Loading thumbs..."));
+       vflist_thumb_status(vf, vflist_thumb_progress(vf), _("Loading thumbs..."));
 }
 
 static void vflist_thumb_error_cb(ThumbLoader *tl, gpointer data)
@@ -1097,8 +1126,6 @@ static gint vflist_thumb_next(ViewFile *vf)
                return FALSE;
                }
 
-       vf->thumbs_count++;
-
        vf->thumbs_filedata = fd;
 
        thumb_loader_free(vf->thumbs_loader);