classifier: allow to sort by EXIF dates
[booh] / bin / booh
index 18861ee568edaf0fc777982c202c17ff27ac4f3d..68454e01d61aaa8e041ec01df23b92dab0c41e26 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -137,6 +137,9 @@ It is generally available with the 'ImageMagick' software package.")), { :pos_ce
         show_popup($main_window, utf8(_("The program 'identify' is needed to get images sizes and EXIF data. Please install it.
 It is generally available with the 'ImageMagick' software package.")), { :pos_centered => true })
     end
+    if !system("which exif >/dev/null 2>/dev/null")
+        show_popup($main_window, utf8(_("The program 'exif' is needed to view EXIF data. Please install it.")), { :pos_centered => true })
+    end
     missing = %w(transcode mencoder).delete_if { |prg| system("which #{prg} >/dev/null 2>/dev/null") }
     if missing != []
         show_popup($main_window, utf8(_("The following program(s) are needed to handle videos: '%s'. Videos will be ignored.") % missing.join(', ')), { :pos_centered => true })
@@ -2139,42 +2142,53 @@ def sort_by_exif_date
     }
 
     #- look for EXIF dates
-    w = Gtk::Window.new
-    w.set_transient_for($main_window)
-    w.modal = true
-    vb = Gtk::VBox.new(false, 5).set_border_width(5)
-    vb.pack_start(Gtk::Label.new(utf8(_("Scanning sub-album looking for EXIF dates..."))), false, false)
-    vb.pack_start(pb = Gtk::ProgressBar.new, false, false)
-    bottom = Gtk::Alignment.new(0.5, 0.5, 0, 0).add(b = Gtk::Button.new(utf8(_("_Abort"))))
-    b.image = Gtk::Image.new("#{$FPATH}/images/stock-close-24.png")
-    vb.pack_end(bottom, false, false)
-    w.add(vb)
-    w.signal_connect('delete-event') { w.destroy }
-    w.window_position = Gtk::Window::POS_CENTER
-    w.show_all
-
-    aborted = false
-    b.signal_connect('clicked') { aborted = true }
     dates = {}
-    i = 0
-    current_order.each { |f|
-        i += 1
-        if entry2type(f) == 'image'
-            pb.text = f
-            pb.fraction = i.to_f / current_order.size
-            Gtk.main_iteration while Gtk.events_pending?
+
+    if current_order.size > 20
+        w = Gtk::Window.new
+        w.set_transient_for($main_window)
+        w.modal = true
+        vb = Gtk::VBox.new(false, 5).set_border_width(5)
+        vb.pack_start(Gtk::Label.new(utf8(_("Scanning sub-album looking for EXIF dates..."))), false, false)
+        vb.pack_start(pb = Gtk::ProgressBar.new, false, false)
+        bottom = Gtk::Alignment.new(0.5, 0.5, 0, 0).add(b = Gtk::Button.new(utf8(_("_Abort"))))
+        b.image = Gtk::Image.new("#{$FPATH}/images/stock-close-24.png")
+        vb.pack_end(bottom, false, false)
+        w.add(vb)
+        w.signal_connect('delete-event') { w.destroy }
+        w.window_position = Gtk::Window::POS_CENTER
+        w.show_all
+
+        aborted = false
+        b.signal_connect('clicked') { aborted = true }
+        i = 0
+        current_order.each { |f|
+            i += 1
+            if entry2type(f) == 'image'
+                pb.text = f
+                pb.fraction = i.to_f / current_order.size
+                Gtk.main_iteration while Gtk.events_pending?
+                date_time = Exif.datetimeoriginal(from_utf8($current_path + "/" + f))
+                if ! date_time.nil?
+                    dates[f] = date_time
+                end
+            end
+            if aborted
+                break
+            end
+        }
+        w.destroy
+        if aborted
+            return
+        end
+
+    else
+        current_order.each { |f|
             date_time = Exif.datetimeoriginal(from_utf8($current_path + "/" + f))
             if ! date_time.nil?
                 dates[f] = date_time
             end
-        end
-        if aborted
-            break
-        end
-    }
-    w.destroy
-    if aborted
-        return
+        }
     end
 
     saves = {}
@@ -2184,17 +2198,8 @@ def sort_by_exif_date
         end
     }
 
-    #- find a good fallback for all entries without a date (still next to the item they were next to)
-    neworder = dates.keys.sort { |a,b| dates[a] <=> dates[b] }
-    for i in 0 .. current_order.size - 1
-        if ! neworder.include?(current_order[i])
-            j = i - 1
-            while j > 0 && ! neworder.include?(current_order[j])
-                j -= 1
-            end
-            neworder[(neworder.index(current_order[j]) || -1 ) + 1, 0] = current_order[i]
-        end
-    end
+    neworder = smartsort(current_order, dates)
+
     neworder.each { |f|
         $xmldir.add_element(saves[f].name, saves[f].attributes)
     }