take care of opening another directory while processing
authorgc <gc>
Sat, 23 Feb 2008 22:34:44 +0000 (22:34 +0000)
committergc <gc>
Sat, 23 Feb 2008 22:34:44 +0000 (22:34 +0000)
bin/booh-classifier

index 41e3de04646aa0fd8db82c54fe60bc6efb1514fe..9a9e7ef6a646d4678dd36e5b7ff6aa34b576ffdf 100644 (file)
@@ -493,10 +493,22 @@ def run_preloader_real
             if i < $allentries.size
                 $allentries[i].pixbuf_main
             end
             if i < $allentries.size
                 $allentries[i].pixbuf_main
             end
+            #- in case just loaded another directory
+            if $preloader_force_exit
+                $preloader_running = false
+                $preloader_force_exit = false
+                return
+            end
             i = index - j
             if i >= 0
                 $allentries[i].pixbuf_main
             end
             i = index - j
             if i >= 0
                 $allentries[i].pixbuf_main
             end
+            #- in case just loaded another directory
+            if $preloader_force_exit
+                $preloader_running = false
+                $preloader_force_exit = false
+                return
+            end
         end
         check_memory_free_cache_if_needed
     end
         end
         check_memory_free_cache_if_needed
     end
@@ -965,7 +977,7 @@ def show_entry(entry, i)
     Gtk.main_iteration while Gtk.events_pending?
 end
 
     Gtk.main_iteration while Gtk.events_pending?
 end
 
-def show_entries
+def show_entries(allentries)
     sb_msg(_("Loading images..."))
     $loading_progressbar.fraction = 0
     $loading_progressbar.text = utf8(_("Loading... %d%") % 0)
     sb_msg(_("Loading images..."))
     $loading_progressbar.fraction = 0
     $loading_progressbar.text = utf8(_("Loading... %d%") % 0)
@@ -974,17 +986,27 @@ def show_entries
     total_loaded_files = 0
     total_loaded_size = 0
     i = 0
     total_loaded_files = 0
     total_loaded_size = 0
     i = 0
-    while i < $allentries.size
+    while i < allentries.size
 #        printf "%d %s\n", i, __LINE__
 #        printf "%d %s\n", i, __LINE__
-        entry = $allentries[i]
+        entry = allentries[i]
         if i == 0
             loaded_pixbuf = entry.pixbuf_main
         else
             loaded_pixbuf = entry.pixbuf_thumbnail
         end
         if i == 0
             loaded_pixbuf = entry.pixbuf_main
         else
             loaded_pixbuf = entry.pixbuf_thumbnail
         end
+        if $allentries != allentries
+            #- loaded another directory while this one was not yet finished
+            msg 3, "allentries differ, stopping this deprecated load"
+            return
+        end
 
         if loaded_pixbuf
             show_entry(entry, i)
 
         if loaded_pixbuf
             show_entry(entry, i)
+            if $allentries != allentries
+                #- loaded another directory while this one was not yet finished
+                msg 3, "allentries differ, stopping this deprecated load"
+                return
+            end
 
             total_loaded_size += file_size(entry.path)
             if i % 4 == 0
 
             total_loaded_size += file_size(entry.path)
             if i % 4 == 0
@@ -994,7 +1016,7 @@ def show_entries
             i += 1
             if i > $config['preload-distance'].to_i && i <= $config['preload-distance'].to_i * 2
                 #- when we're at preload distance, beging preloading to preload distance
             i += 1
             if i > $config['preload-distance'].to_i && i <= $config['preload-distance'].to_i * 2
                 #- when we're at preload distance, beging preloading to preload distance
-                $allentries[i - $config['preload-distance'].to_i].pixbuf_main
+                allentries[i - $config['preload-distance'].to_i].pixbuf_main
             end
             if i == $config['preload-distance'].to_i * 2 + 1
                 #- when we're after double preload distance, activate normal preloading
             end
             if i == $config['preload-distance'].to_i * 2 + 1
                 #- when we're after double preload distance, activate normal preloading
@@ -1002,9 +1024,9 @@ def show_entries
             end
             
         else
             end
             
         else
-            $allentries.delete_at(i)
+            allentries.delete_at(i)
         end
         end
-        $loading_progressbar.fraction = i.to_f / $allentries.size
+        $loading_progressbar.fraction = i.to_f / allentries.size
         $loading_progressbar.text = utf8(_("Loading... %d%") % (100 * $loading_progressbar.fraction))
     end
     if i <= $config['preload-distance'].to_i * 2
         $loading_progressbar.text = utf8(_("Loading... %d%") % (100 * $loading_progressbar.fraction))
     end
     if i <= $config['preload-distance'].to_i * 2
@@ -1103,7 +1125,7 @@ def open_dir_popup
     end
     fc.destroy
     if load
     end
     fc.destroy
     if load
-        show_entries
+        show_entries($allentries)
     end
 end
 
     end
 end
 
@@ -1542,6 +1564,9 @@ end
 
 def reset_thumbnails
     $allentries = []
 
 def reset_thumbnails
     $allentries = []
+    if $preloader_running
+        $preloader_force_exit = true
+    end
     for child in $imagesline.children
         $imagesline.remove(child)
     end
     for child in $imagesline.children
         $imagesline.remove(child)
     end
@@ -1614,7 +1639,7 @@ if ARGV[0]
     if msg = open_dir(ARGV[0])
         puts msg
     else
     if msg = open_dir(ARGV[0])
         puts msg
     else
-        show_entries
+        show_entries($allentries)
     end
 end
 Gtk.main
     end
 end
 Gtk.main