no longer use internalized rexml
[booh] / bin / booh-classifier
index 1edbc4aa5707c1851f38f852e827fcd6327eadfd..3be4fab23d05dc1e5ca9ee46b0649b64d269b3c6 100644 (file)
@@ -10,7 +10,7 @@
 # called Boo, so this one will be it "Booh". Or whatever.
 #
 #
-# Copyright (c) 2004-2009 Guillaume Cottenceau <http://zarb.org/~gc/resource/gc_mail.png>
+# Copyright (c) 2004-2013 Guillaume Cottenceau <http://zarb.org/~gc/resource/gc_mail.png>
 #
 # This software may be freely redistributed under the terms of the GNU
 # public license version 2.
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
+begin
+    require 'rubygems'
+rescue LoadError
+end
+
 require 'getoptlong'
 require 'tempfile'
 
@@ -29,7 +34,7 @@ require 'gettext'
 include GetText
 bindtextdomain("booh")
 
-require 'booh/rexml/document'
+require 'rexml/document'
 include REXML
 
 require 'booh/booh-lib'
@@ -73,7 +78,7 @@ def handle_options
             when '--version'
                 puts _("Booh version %s
 
-Copyright (c) 2005-2009 Guillaume Cottenceau.
+Copyright (c) 2005-2013 Guillaume Cottenceau.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") % $VERSION
 
@@ -148,8 +153,8 @@ def read_config
             end
         }
     end
-    $config['video-viewer'] ||= '/usr/bin/mplayer %f'
-    $config['browser'] ||= "/usr/bin/mozilla-firefox -remote 'openURL(%f,new-window)' || /usr/bin/mozilla-firefox %f"
+    $config['video-viewer'] ||= '/usr/bin/mplayer %f || /usr/bin/vlc %f'
+    $config['browser'] ||= "/usr/bin/mozilla-firefox -remote 'openURL(%f,new-window)' || /usr/bin/mozilla-firefox %f || /usr/bin/firefox -remote 'openURL(%f,new-window)' || /usr/bin/firefox %f"
     $config['preload-distance'] ||= '5'
     $config['cache-memory-use'] ||= 'memfree_80%'
     $config['rotate-set-exif'] ||= 'true'
@@ -245,7 +250,7 @@ $colors = [ Gdk::Color.new(0, 65535, 0),
             Gdk::Color.new(65535, 0, 65535) ]
 
 class Label
-    attr_accessor :color, :name, :button
+    attr_accessor :color, :name, :button, :counter
     def initialize(name)
         @name = name
     end
@@ -256,11 +261,13 @@ class InterruptedLoading < Exception
 end
 
 def show_pixbufs_present
-    out = 'Full pixbufs ['
-    for entry in $allentries
-        out += entry.pixbuf_full_present? ? 'F' : '.'
+    if 3 <= $verbose_level
+        out = 'Full pixbufs ['
+        for entry in $allentries
+            out += entry.pixbuf_full_present? ? 'F' : '.'
+        end
+        msg 3, out + ']'
     end
-    msg 3, out + ']'
 end
 
 class Entry
@@ -269,7 +276,7 @@ class Entry
         return $config['thumbnails-height'].to_i
     end
 
-    attr_accessor :path, :guipath, :type, :angle, :button, :image, :alignment, :removed, :labeled
+    attr_accessor :path, :guipath, :type, :angle, :button, :image, :alignment, :removed, :labeled, :loader
 
     def initialize(path, type, guipath)
         @path = path
@@ -308,14 +315,14 @@ class Entry
             if @pixbuf_full.width.to_f / @pixbuf_full.height > width.to_f / height
                 resized_height = @pixbuf_full.height * (width.to_f/@pixbuf_full.width)
                 if @pixbuf_full.width > width || @pixbuf_full.height > resized_height
-                    @pixbuf_main = @pixbuf_full.scale(width, resized_height, Gdk::Pixbuf::INTERP_BILINEAR)
+                    @pixbuf_main = @pixbuf_full.scale(width, resized_height, :bilinear)
                 else
                     @pixbuf_main = @pixbuf_full
                 end
             else
                 resized_width = @pixbuf_full.width * (height.to_f/@pixbuf_full.height)
                 if @pixbuf_full.width > resized_width || @pixbuf_full.height > height
-                    @pixbuf_main = @pixbuf_full.scale(resized_width, height, Gdk::Pixbuf::INTERP_BILINEAR)
+                    @pixbuf_main = @pixbuf_full.scale(resized_width, height, :bilinear)
                 else
                     @pixbuf_main = @pixbuf_full
                 end
@@ -341,7 +348,7 @@ class Entry
         if @pixbuf_thumbnail.nil?
             if @pixbuf_main
                 msg 3, ">>> pixbuf_thumbnail from main #{path}"
-                @pixbuf_thumbnail = @pixbuf_main.scale(@pixbuf_main.width * (Entry.thumbnails_height.to_f/@pixbuf_main.height), Entry.thumbnails_height, Gdk::Pixbuf::INTERP_BILINEAR)
+                @pixbuf_thumbnail = @pixbuf_main.scale(@pixbuf_main.width * (Entry.thumbnails_height.to_f/@pixbuf_main.height), Entry.thumbnails_height, :bilinear)
             else
                 msg 3, ">>> pixbuf_thumbnail from file #{path}"
                 @pixbuf_thumbnail = load_into_pixbuf_at_size { |w, h|
@@ -408,12 +415,20 @@ class Entry
         end
     end
 
-    private
-    def cleanup_dir(dir)
-        Dir.entries(dir).each { |file| file != '.' && file != '..' and File.delete(File.join(dir, file)) }
-        Dir.delete(dir)
+    def cancel_loader
+        if ! @loader.nil?
+            #- avoid unneeded memory allocation
+            @loader.signal_handler_disconnect(@area_prepared_cb)
+            begin
+                @loader.close
+            rescue
+                #- ignore loader errors, at that point they are fairly normal, we're canceling a partial load
+            end
+            @loader = nil
+        end
     end
 
+    private
     def load_into_pixbuf_full
         if @pixbuf_full.nil?
             msg 3, ">>> load_into_pixbuf_full #{path}"
@@ -438,18 +453,16 @@ class Entry
     end
 
     def load_into_pixbuf_at_size(&specify_size)
-        pixbuf = nil
         if @type == 'video'
-            tmp = Tempfile.new("boohclassifiertemp")
-            dest_dir = tmp.path
-            tmp.close!
-            Dir.mkdir(dest_dir)
-            orig_base = File.basename(path)
-            tmpdir = gen_video_thumbnail(path, false, 0)
-            if tmpdir.nil?
-                return
+            if @video_image_path.nil?
+                orig_base = File.basename(path)
+                tmpdir = gen_video_thumbnail(path, false, 0)
+                if tmpdir.nil?
+                    return
+                end
+                @video_image_path = "#{tmpdir}/00000001.jpg"
             end
-            image_path = "#{tmpdir}/00000001.jpg"
+            image_path = @video_image_path
         else
             image_path = @path
         end
@@ -461,41 +474,45 @@ class Entry
             end
         end
         begin
-            #- use a pixbuf loader and trigger Gtk.main_iteration on each chunk if needed, to keep the UI responsive even
+            #- use a pixbuf loader and check Gtk.events_pending? on each chunk, to keep the UI responsive even
             #- if loaded pictures are several MBs large
-            loader = Gdk::PixbufLoader.new
-            loader.signal_connect('size-prepared') { |l, w, h|
-                r = specify_size.call(w, h)
-                #msg 3, "specified sizes: #{r[0]} #{r[1]}"
-                loader.set_size(*specify_size.call(w, h))
-            }
-            id = loader.signal_connect('area-prepared') { pixbuf = loader.pixbuf }
-            if ! loader.load_not_freezing_ui(image_path, id)
+            if @loader.nil?
+                @loader = GdkPixbuf::PixbufLoader.new
+                @loader.signal_connect('size-prepared') { |l, w, h|
+                    @loader.set_size(*specify_size.call(w, h))
+                }
+                @area_prepared_cb = @loader.signal_connect('area-prepared') { @loaded_pixbuf = @loader.pixbuf }
+                @loader_offset = 0
+            end
+            msg 3, "calling load_not_freezing_ui on #{image_path}, offset #{@loader_offset}"
+            @loader_offset = @loader.load_not_freezing_ui(image_path, @loader_offset)
+            if @loader_offset > 0
                 #- interrupted
                 raise InterruptedLoading
             end
-            if pixbuf.nil?
+            @loader = nil
+            if @loaded_pixbuf.nil?
                 raise "Loaded pixbuf nil - #{path} #{image_path}"
             end
         rescue
             msg 0, "Cannot load #{image_path}: #{$!}"
             return
         ensure
-            if @type == 'video'
-                File.delete(image_path)
-                Dir.rmdir(tmpdir)
+            if @video_image_path && @loader.nil?
+                File.delete(@video_image_path)
+                Dir.rmdir(File.dirname(@video_image_path))
+                @video_image_path = nil
             end
         end
-        if pixbuf
+        if @loaded_pixbuf
             if @angle != 0
                 msg 3, ">>> load_into_pixbuf_full #{image_path} => rotate #{@angle}"
-                pixbuf = rotate_pixbuf(pixbuf, @angle)
+                @loaded_pixbuf = rotate_pixbuf(@loaded_pixbuf, @angle)
             end
         end
-        if @type == 'video'
-            cleanup_dir(dest_dir)
-        end
-        return pixbuf
+        retval = @loaded_pixbuf
+        @loaded_pixbuf = nil
+        return retval
     end
 
     def to_s
@@ -723,6 +740,14 @@ class MainView < Gtk::DrawingArea
         end
         if index < $allentries.size && $allentries[index] && $allentries[index].button && $allentries[index].button.visible?
             try_show_entry($allentries[index])
+            return
+        end
+        #- find a fallback before
+        while index < $allentries.size && index > 0 && $allentries[index] && (! $allentries[index].button || ! $allentries[index].button.visible?)
+            index -= 1
+        end
+        if index < $allentries.size && index > 0 && $allentries[index] && $allentries[index].button && $allentries[index].button.visible?
+            try_show_entry($allentries[index])
         end
     end
 
@@ -858,9 +883,6 @@ def show_popup(parent, msg, *options)
     if options[:selectable]
         lbl.selectable = true
     end
-    if options[:topwidget]
-        dialog.vbox.add(options[0][:topwidget])
-    end
     if options[:scrolled]
         sw = Gtk::ScrolledWindow.new(nil, nil)
         sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
@@ -876,12 +898,16 @@ def show_popup(parent, msg, *options)
     end
     if options[:okcancel]
         cancel = dialog.add_button(Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL)
+        dialog.add_button(Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK)
+    elsif options[:yestoall]
+        cancel = dialog.add_button(Gtk::Stock::NO, Gtk::Dialog::RESPONSE_NO)
         if ! options[:bottomwidget]
             cancel.grab_focus
         end
-        dialog.add_button(Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK)
+        dialog.add_button(Gtk::Stock::YES, Gtk::Dialog::RESPONSE_YES)
+        dialog.add_button(utf8(_("Yes to all")), Gtk::Dialog::RESPONSE_ACCEPT)
     else
-        ok = dialog.add_button(Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK).grab_focus
+        ok = dialog.add_button(Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK)
         if ! options[:bottomwidget]
             ok.grab_focus
         end
@@ -922,6 +948,8 @@ def show_popup(parent, msg, *options)
             dialog.destroy
             if options[:okcancel]
                 return response == Gtk::Dialog::RESPONSE_OK
+            elsif options[:yestoall]
+                return response == Gtk::Dialog::RESPONSE_YES ? 'yes' : response == Gtk::Dialog::RESPONSE_ACCEPT ? 'yestoall' : 'no'
             end
         }
     else
@@ -941,6 +969,32 @@ def view_entry(entry)
     end
 end
 
+def update_counters
+    value = 0
+    $allentries.each { |entry|
+        if ! entry.removed && entry.labeled.nil?
+            value += 1
+        end
+    }
+    $unlabelled_counter.set_markup('<tt>' + value.to_s + '</tt>')
+    value = 0
+    $allentries.each { |entry|
+        if entry.removed 
+            value += 1
+        end
+    }
+    $toremove_counter.set_markup('<tt>' + value.to_s + '</tt>')
+    $labels.values.each { |label|
+        value = 0
+        $allentries.each { |entry|
+            if entry.labeled == label
+                value += 1
+            end
+        }
+        label.counter.set_markup('<tt>' + value.to_s + '</tt>')
+    }
+end
+
 def thumbnail_keypressed(entry, event)
     if event.state & Gdk::Window::MOD1_MASK != 0
         #- ALT pressed: Alt-Left and Alft-Right rotate
@@ -986,6 +1040,7 @@ def thumbnail_keypressed(entry, event)
             entry.labeled = nil
             entry.show_bg
             update_visibility(entry)
+            update_counters
             $mainview.show_next_entry(entry)
 
             save_undo(_("set for removal"),
@@ -994,6 +1049,7 @@ def thumbnail_keypressed(entry, event)
                           entry.labeled = label_before
                           entry.show_bg
                           update_visibility(entry)
+                          update_counters
                           if entry.button.visible?
                               $mainview.try_show_entry(entry)
                           end
@@ -1002,6 +1058,7 @@ def thumbnail_keypressed(entry, event)
                               entry.labeled = nil
                               entry.show_bg
                               update_visibility(entry)
+                              update_counters
                               if entry.button.visible?
                                   $mainview.try_show_entry(entry)
                               end
@@ -1017,6 +1074,7 @@ def thumbnail_keypressed(entry, event)
             entry.removed = false
             entry.labeled = nil
             entry.show_bg
+            update_counters
             $mainview.show_next_entry(entry)
 
             save_undo(msg,
@@ -1024,11 +1082,13 @@ def thumbnail_keypressed(entry, event)
                           entry.removed = removed_before
                           entry.labeled = label_before
                           entry.show_bg
+                          update_counters
                           $mainview.try_show_entry(entry)
                           proc {
                               entry.removed = false
                               entry.labeled = nil
                               entry.show_bg
+                              update_counters
                               $mainview.try_show_entry(entry)
                           }
                       })
@@ -1047,8 +1107,12 @@ def thumbnail_keypressed(entry, event)
 
         elsif event.keyval == Gdk::Keyval::GDK_End
             index = $allentries.size - 1
+            while $allentries[index] && ! $allentries[index].button
+                #- not yet loaded
+                index -= 1
+            end
             while $allentries[index] && $allentries[index].button && !visible($allentries[index])
-                index += 1
+                index -= 1
             end
             if $allentries[index] && $allentries[index].button
                 $allentries[index].button.grab_focus
@@ -1084,7 +1148,9 @@ def thumbnail_keypressed(entry, event)
                             $labels[char] = label
                             $ordered_labels << label
                             lbl = Gtk::Label.new.set_markup('<b>(' + char + ')</b>' + text[1..-1]).set_justify(Gtk::Justification::CENTER)
-                            $labels_vbox.pack_start(label.button = Gtk::CheckButton.new.add(evt = Gtk::EventBox.new.add(lbl)).show_all)
+                            $labels_vbox.pack_start(Gtk::HBox.new(false, 5).pack_start(label.button = Gtk::CheckButton.new.add(evt = Gtk::EventBox.new.add(lbl))).
+                                                                            pack_start(Gtk::Label.new, true, true).
+                                                                            pack_start(label.counter = Gtk::Label.new.set_markup('<tt>0</tt>'), false, false).show_all)
                             label.button.active = true
                             label.button.signal_connect('toggled') { update_all_visibilities }
                             evt.modify_bg(Gtk::StateType::NORMAL, label.color)
@@ -1099,6 +1165,7 @@ def thumbnail_keypressed(entry, event)
                     entry.labeled = label
                     entry.show_bg
                     update_visibility(entry)
+                    update_counters
                     $mainview.show_next_entry(entry)
 
                     save_undo(_("set label"),
@@ -1107,6 +1174,7 @@ def thumbnail_keypressed(entry, event)
                                   entry.labeled = label_before
                                   entry.show_bg
                                   update_visibility(entry)
+                                  update_counters
                                   if entry.button.visible?
                                       $mainview.try_show_entry(entry)
                                   end
@@ -1115,6 +1183,7 @@ def thumbnail_keypressed(entry, event)
                                       entry.labeled = label
                                       entry.show_bg
                                       update_visibility(entry)
+                                      update_counters
                                       if entry.button.visible?
                                           $mainview.try_show_entry(entry)
                                       end
@@ -1171,9 +1240,10 @@ def show_entry(entry, i, tips)
 end
 
 def show_entries(allentries)
+    update_counters
     sb_msg(_("Loading images..."))
     $loading_progressbar.fraction = 0
-    $loading_progressbar.text = utf8(_("Loading... %d%") % 0)
+    $loading_progressbar.text = utf8(_("Loading... %d%%") % 0)
     $loading_progressbar.show
     t1 = Time.now
     total_loaded_files = 0
@@ -1225,7 +1295,7 @@ def show_entries(allentries)
             allentries.delete_at(i)
         end
         $loading_progressbar.fraction = i.to_f / allentries.size
-        $loading_progressbar.text = utf8(_("Loading... %d%") % (100 * $loading_progressbar.fraction))
+        $loading_progressbar.text = utf8(_("Loading... %d%%") % (100 * $loading_progressbar.fraction))
         if $quit
             return
         end
@@ -1255,7 +1325,7 @@ end
 def open_dir(*paths)
     #- remove visual stuff, so that user will see something is happening
     reset_all
-    sb_msg(_("Scanning source directory..."))
+    sb_msg(_("Scanning source directory... %s") % "")
     Gtk.main_iteration while Gtk.events_pending?
 
     for path in paths
@@ -1263,17 +1333,21 @@ def open_dir(*paths)
         $workingdir = path
         entries = []
         if File.directory?(path)
-            examined_dirs = `find '#{path}' -type d -follow`.sort.collect { |v| v.chomp }
+            examined_dirs = `find '#{path}' -type d -follow`.split("\n").sort.collect { |v| v.chomp }
             #- validate first
             examined_dirs.each { |dir|
                 if dir =~ /'/
                     return utf8(_("Source directory or sub-directories can't contain a single-quote character, sorry: %s") % dir)
                 end
-                Dir.entries(dir).each { |file|
-                    if file =~ /'/ && type = entry2type(file) && type == 'video'
-                        return utf8(_("Videos can't contain a single quote character ('), sorry: %s") % "#{dir}/#{file}")
-                    end
-                }
+                begin
+                    Dir.entries(dir).each { |file|
+                        if file =~ /'/ && type = entry2type(file) && type == 'video'
+                            return utf8(_("Videos can't contain a single quote character ('), sorry: %s") % "#{dir}/#{file}")
+                        end
+                    }
+                rescue
+                    puts "Failed to open directory #{dir}: #{$!}"
+                end
             }
             
             #- scan for populate second
@@ -1282,7 +1356,13 @@ def open_dir(*paths)
                     msg 1, _("Ignoring directory %s, begins with a dot (indicating a hidden directory)") % dir
                     next
                 end
-                entries += Dir.entries(dir).collect { |file| File.join(dir, file) }
+                begin
+                    entries += Dir.entries(dir).collect { |file| File.join(dir, file) }
+                rescue
+                    #- already puts'ed 10 lines upper
+                end
+                sb_msg(_("Scanning source directory... %s") % (_("%d entries found") % entries.size))
+                Gtk.main_iteration while Gtk.events_pending?
             }
 
         else
@@ -1295,6 +1375,8 @@ def open_dir(*paths)
                 date_time = Exif.datetimeoriginal(file)
                 if ! date_time.nil?
                     dates[file] = date_time
+                elsif file =~ /(20\d{2}).?(\d{2}).?(\d{2}).(\d{2}).?(\d{2}).?(\d{2})/
+                    dates[file] = "#$1:#$2:#$3 #$4:#$5:#$6"
                 end
             }
             entries = smartsort(entries, dates)
@@ -1328,7 +1410,7 @@ def open_dir_popup
     ok = false
     load = false
     while !ok
-        if fc.run == Gtk::Dialog::RESPONSE_ACCEPT
+        if fc.run == Gtk::Dialog::RESPONSE_ACCEPT && fc.filename
             msg = open_dir(fc.filename)
             if msg
                 show_popup(fc, msg)
@@ -1403,7 +1485,7 @@ def execute
         table.attach(examples, 2, 3, row, row + 1, Gtk::FILL, Gtk::FILL, 5, 5)
 
         if counter == 0
-            return {}
+            next {}
         end
 
         combostore = Gtk::ListStore.new(Gdk::Pixbuf, String)
@@ -1442,7 +1524,7 @@ def execute
                 if lastpath
                     fc.current_folder = lastpath
                 end
-                if fc.run == Gtk::Dialog::RESPONSE_ACCEPT
+                if fc.run == Gtk::Dialog::RESPONSE_ACCEPT && fc.filename
                     pathlabel.text = fc.filename
                     pathlabel.set_alignment(0, 0.5)
                 end
@@ -1520,7 +1602,7 @@ def execute
                         end
                         begin
                             Dir.mkdir(destination)
-                        rescue Errno::EEXIST
+                        rescue
                         end
                         begin
                             st = File.stat(destination)
@@ -1529,7 +1611,7 @@ def execute
                             problem = true
                             break
                         end
-                        if ! st.directory? || ! st.writable?
+                        if ! st.directory? || ! writable(destination)
                             show_popup(dialog, utf8(_("Directory %s, where to move/copy %s, is not valid or not writable.") % [destination, key.name]))
                             problem = true
                             break
@@ -1561,16 +1643,36 @@ def execute
                     begin
                         moved = 0
                         copied = 0
+                        ignored_errors = []
                         stuff.keys.each { |key|
                             if key.is_a?(Label) && stuff[key][:combo] && stuff[key][:combo].active <= 1
                                 destination = stuff[key][:pathlabel].text
                                 label2entries[key].each { |entry|
                                     if stuff[key][:combo].active == 0
-                                        system("cp -dp '#{entry.path}' '#{destination}'") or raise "failed to copy '#{entry.path}'"
-                                        copied += 1
+                                        result = `cp -dp '#{entry.path}' '#{destination}' 2>&1`
                                     elsif stuff[key][:combo].active == 1
-                                        system("mv '#{entry.path}' '#{destination}'") or raise "failed to move '#{entry.path}'"
-                                        moved += 1
+                                        result = `mv '#{entry.path}' '#{destination}' 2>&1`
+                                    end
+                                    if $?.exitstatus > 0
+                                        simplified_error = result.sub(/#{Regexp.quote(destination + '/' + File.basename(entry.path))}/, '').  #'
+                                                                  sub(/#{Regexp.quote(entry.path)}/, '').
+                                                                  sub(/#{Regexp.quote(File.basename(entry.path))}/, '')
+                                        if ! ignored_errors.include?(simplified_error)
+                                            response = show_popup($main_window,
+                                                                  utf8(_("Failure:\n\n%s\nDo you wish to continue?" % result)),
+                                                                  { :yestoall => true })
+                                            if response == 'no'
+                                                raise "failure on '#{entry.path}'"
+                                            elsif response == 'yestoall'
+                                                ignored_errors << simplified_error
+                                            end
+                                        end
+                                    else
+                                        if stuff[key][:combo].active == 0
+                                            copied += 1
+                                        else
+                                            moved += 1
+                                        end
                                     end
                                 }
                             end
@@ -1585,8 +1687,7 @@ def execute
                             }
                         end
                     rescue
-                        msg 1, "woops: #{$!}"
-                        show_popup(dialog, utf8(_("Unexpected error: '%s'.") % $!))
+                        msg 1, "woops: #{$!}\n" + $@.join("\n")
                     end
                     show_popup(dialog, utf8(_("Successfully moved %d files, copied %d file, and removed %d files.") % [ moved, copied, removed ]))
                     dialog.destroy
@@ -1882,11 +1983,15 @@ def reset_labels
     $labels = {}
     $ordered_labels = []
     lbl = Gtk::Label.new.set_markup(utf8(_("<i>unlabelled</i>")))
-    $labels_vbox.pack_start($unlabelled_button = Gtk::CheckButton.new.add(Gtk::EventBox.new.add(lbl)).show_all)
+    $labels_vbox.pack_start(Gtk::HBox.new(false, 5).pack_start($unlabelled_button = Gtk::CheckButton.new.add(Gtk::EventBox.new.add(lbl)), false, false).
+                                                    pack_start(Gtk::Label.new, true, true).  #- I suck
+                                                    pack_start($unlabelled_counter = Gtk::Label.new.set_markup('<tt>0</tt>'), false, false).show_all)
     $unlabelled_button.active = true
     $unlabelled_button.signal_connect('toggled') { update_all_visibilities }
     lbl = Gtk::Label.new.set_markup(utf8(_("<i>to remove</i>")))
-    $labels_vbox.pack_start($toremove_button = Gtk::CheckButton.new.add(evt = Gtk::EventBox.new.add(lbl)).show_all)
+    $labels_vbox.pack_start(Gtk::HBox.new(false, 5).pack_start($toremove_button = Gtk::CheckButton.new.add(evt = Gtk::EventBox.new.add(lbl)), false, false).
+                                                    pack_start(Gtk::Label.new, true, true).
+                                                    pack_start($toremove_counter = Gtk::Label.new.set_markup('<tt>0</tt>'), false, false).show_all)
     $toremove_button.active = true
     $toremove_button.signal_connect('toggled') { update_all_visibilities }
     evt.modify_bg(Gtk::StateType::NORMAL, $color_red)
@@ -1894,7 +1999,14 @@ def reset_labels
     evt.modify_bg(Gtk::StateType::ACTIVE, $color_red.lighter)
 end
 
+def cleanup_loaders
+    $allentries.each { |e| 
+        e.cancel_loader
+    }
+end
+
 def reset_thumbnails
+    cleanup_loaders
     $allentries = []
     if $preloader_running
         $preloader_force_exit = true
@@ -1911,7 +2023,7 @@ end
 
 def create_main_window
 
-    $videoborder_pixbuf = Gdk::Pixbuf.new("#{$FPATH}/images/video_border.png")
+    $videoborder_pixbuf = GdkPixbuf::Pixbuf.new(:file => "#{$FPATH}/images/video_border.png")
     $videoborder_pixmap, = $videoborder_pixbuf.render_pixmap_and_mask(0)
 
     mb = create_menubar
@@ -1921,7 +2033,7 @@ def create_main_window
     mainview_hbox = Gtk::HBox.new
     mainview_hbox.pack_start(Gtk::Alignment.new(0.5, 0, 1, 1).add(left_vbox = Gtk::VBox.new(false, 5)), false, true)
     left_vbox.pack_start(($labels_vbox = Gtk::VBox.new(false, 5)), false, true)
-    left_vbox.pack_end($loading_progressbar = Gtk::ProgressBar.new.set_text(utf8(_("Loading... %d%") % 0)), false, true)
+    left_vbox.pack_end($loading_progressbar = Gtk::ProgressBar.new.set_text(utf8(_("Loading... %d%%") % 0)), false, true)
     mainview_hbox.pack_start($mainview = MainView.new, true, true)
     main_vbox.pack_start(mainview_hbox, true, true)
     $imagesline_sw = Gtk::ScrolledWindow.new(nil, nil)
@@ -1982,4 +2094,6 @@ if ARGV[0]
 end
 Gtk.main
 
+cleanup_loaders
+
 write_config