*phew* commented and simplified.
[geeqie.git] / src / view_file / view_file_icon.c
index 3d39748..6b7131c 100644 (file)
@@ -1703,14 +1703,12 @@ void vficon_set_thumb_fd(ViewFile *vf, FileData *fd)
        gtk_list_store_set(GTK_LIST_STORE(store), &iter, FILE_COLUMN_POINTER, list, -1);
 }
 
-// TOOD(xsdg): This could be broken
+/* Returns the next fd without a loaded pixbuf, so the thumb-loader can load the pixbuf for it. */
 FileData *vficon_thumb_next_fd(ViewFile *vf)
 {
        GtkTreePath *tpath;
-       FileData *fd = NULL;
-
-       /* first check the visible files */
 
+       /* First see if there are visible files that don't have a loaded thumb... */
        if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
                {
                GtkTreeModel *store;
@@ -1722,40 +1720,34 @@ FileData *vficon_thumb_next_fd(ViewFile *vf)
                gtk_tree_path_free(tpath);
                tpath = NULL;
 
-               while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vf->listview), &iter, FALSE) == 0)
+               while (valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vf->listview), &iter, FALSE) == 0)
                        {
                        GList *list;
 
                        gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
 
-                       while (!fd && list)
+                       // TODO(xsdg): for loop here.
+                       for (; list; list = list->next)
                                {
-                               FileData *new_fd = list->data;
-                               if (new_fd && !fd->thumb_pixbuf) fd = new_fd;
-                               list = list->next;
+                               FileData *fd = list->data;
+                               if (fd && !fd->thumb_pixbuf) return fd;
                                }
 
                        valid = gtk_tree_model_iter_next(store, &iter);
                        }
                }
 
-       /* then find first undone */
-
-       if (!fd)
+       /* Then iterate through the entire list to load all of them. */
+       for (GList *work = vf->list; work; work = work->next)
                {
-               GList *work = vf->list;
-               while (work && !fd)
-                       {
-                       FileData *fd_p = work->data;
-                       work = work->next;
+               FileData *fd = work->data;
 
-                       // Note: This implementation differs from view_file_list.c because sidecar files are not
-                       // distinct list elements here, as they are in the list view.
-                       if (!fd_p->thumb_pixbuf) fd = fd_p;
-                       }
+               // Note: This implementation differs from view_file_list.c because sidecar files are not
+               // distinct list elements here, as they are in the list view.
+               if (!fd->thumb_pixbuf) return fd;
                }
 
-       return fd;
+       return NULL;
 }
 
 void vficon_thumb_reset_all(ViewFile *vf)
@@ -1859,9 +1851,9 @@ static gboolean vficon_refresh_real(ViewFile *vf, gboolean keep_position)
        gboolean ret = TRUE;
        GList *work, *new_work;
        FileData *focus_fd;
-       GList *new_filelist = NULL;
        FileData *first_selected = NULL;
-       GList *new_iconlist = NULL;  // TODO(xsdg): figure out what this should be named.
+       GList *new_filelist = NULL;
+       GList *new_fd_list = NULL;
 
        focus_fd = VFICON(vf)->focus_fd;
 
@@ -1882,7 +1874,7 @@ static gboolean vficon_refresh_real(ViewFile *vf, gboolean keep_position)
                VFICON(vf)->selection = NULL;
                }
 
-       /* check for same files from old_list */
+       /* iterate old list and new list, looking for differences */
        work = vf->list;
        new_work = new_filelist;
        while (work || new_work)
@@ -1913,11 +1905,13 @@ static gboolean vficon_refresh_real(ViewFile *vf, gboolean keep_position)
                        }
                else if (work)
                        {
+                       /* old item was deleted */
                        fd = work->data;
                        match = -1;
                        }
-               else /* new_work */
+               else
                        {
+                       /* new item was added */
                        new_fd = new_work->data;
                        match = 1;
                        }
@@ -1943,16 +1937,17 @@ static gboolean vficon_refresh_real(ViewFile *vf, gboolean keep_position)
                                }
                        else
                                {
-                               new_iconlist = g_list_prepend(new_iconlist, fd); /* it is faster to append all new entries together later */
+                               /* it is faster to append all new entries together later */
+                               new_fd_list = g_list_prepend(new_fd_list, new_fd);
                                }
 
                        new_work = new_work->next;
                        }
                }
 
-       if (new_iconlist)
+       if (new_fd_list)
                {
-               vf->list = g_list_concat(vf->list, g_list_reverse(new_iconlist));
+               vf->list = g_list_concat(vf->list, g_list_reverse(new_fd_list));
                }
 
        VFICON(vf)->selection = g_list_reverse(VFICON(vf)->selection);