generate fullscreen images if missing (after a rotation); generate thumbnails if...
authorgc <gc>
Sat, 2 Apr 2005 23:40:07 +0000 (23:40 +0000)
committergc <gc>
Sat, 2 Apr 2005 23:40:07 +0000 (23:40 +0000)
bin/booh-gui
lib/booh/booh-lib.rb

index bc6b12ecdc29f2a6879a783c5b3c78a90c8a5af8..43a384ec505feafd1c4f73bd7a123e6a64a125c5 100755 (executable)
@@ -129,11 +129,19 @@ def view_element(filename)
     dest_img = build_full_dest_filename(filename).sub(/\.[^\.]+$/, '') + "-#{$default_size['fullscreen']}.jpg"
     #- typically this file won't exist in case of videos; try with the largest thumbnail around
     if !File.exists?(dest_img)
-        alternatives = Dir[build_full_dest_filename(filename).sub(/\.[^\.]+$/, '') + '-*'].sort
-        if not alternatives.empty?
-            dest_img = alternatives[-1]
+        if entry2type(filename) == 'video'
+            alternatives = Dir[build_full_dest_filename(filename).sub(/\.[^\.]+$/, '') + '-*'].sort
+            if not alternatives.empty?
+                dest_img = alternatives[-1]
+            end
         else
-            return
+            set_mousecursor_wait($main_window.window)
+            gen_thumbnails(from_utf8("#{$current_path}/#{filename}"), $xmldir, false, [ { 'filename' => dest_img, 'size' => $default_size['fullscreen'] } ])
+            set_mousecursor_normal($main_window.window)
+            if !File.exists?(dest_img)
+                msg 2, _("Could not generate fullscreen thumbnail!")
+                return
+            end
         end
     end
     i = Gtk::Image.new(dest_img)
@@ -168,6 +176,10 @@ end
 
 def add_thumbnail(autotable, name, type, filename, caption)
 
+    #- generate the thumbnail if missing (if image was rotated but booh was not relaunched)
+    if !$rotated_pixbufs[filename] && !File.exists?(filename)
+        gen_thumbnails(from_utf8("#{$current_path}/#{name}"), $xmldir, false, [ { 'filename' => filename, 'size' => $default_size['thumbnails'] } ])
+    end
     frame1 = Gtk::Frame.new
     frame1.add(img = Gtk::Image.new($rotated_pixbufs[filename] ? $rotated_pixbufs[filename][:pixbuf] : filename))
     frame1.set_shadow_type(Gtk::SHADOW_ETCHED_OUT)
@@ -202,17 +214,16 @@ def add_thumbnail(autotable, name, type, filename, caption)
 
     rotate = Proc.new { |angle|
         #- update rotate attribute
-        xmldir = $xmldoc.elements["//dir[@path='#{$current_path}']"]
-        felem = xmldir.elements["[@filename='#{name}']"]
+        felem = $xmldir.elements["[@filename='#{name}']"]
         felem.add_attribute('rotate', current_angle = ( felem.attributes['rotate'].to_i + angle ) % 360)
 
         #- remove out of sync images
+        dest_img_base = build_full_dest_filename(name).sub(/\.[^\.]+$/, '')
+        for sizeobj in $images_size
+            system("rm -f #{dest_img_base}-#{sizeobj['fullscreen']}.jpg #{dest_img_base}-#{sizeobj['thumbnails']}.jpg")
+        end
         if !$rotated_pixbufs[filename]
             $rotated_pixbufs[filename] = { :orig => img.pixbuf, :angle_to_orig => angle % 360 }
-            dest_img_base = build_full_dest_filename(name).sub(/\.[^\.]+$/, '')
-            for sizeobj in $images_size
-                system("rm -f #{dest_img_base}-#{sizeobj['fullscreen']}.jpg #{dest_img_base}-#{sizeobj['thumbnails']}.jpg")
-            end
         else
             $rotated_pixbufs[filename][:angle_to_orig] = ( $rotated_pixbufs[filename][:angle_to_orig] + angle ) % 360
         end
@@ -309,7 +320,7 @@ def add_thumbnail(autotable, name, type, filename, caption)
                 delete.call
             end
             if event.keyval == Gdk::Keyval::GDK_Return && control_pressed
-                view_element(File.basename(name))
+                view_element(name)
                 propagate = false
             end
         end
@@ -336,7 +347,7 @@ def add_thumbnail(autotable, name, type, filename, caption)
         end
         textview.grab_focus
         if event.event_type == Gdk::Event::BUTTON2_PRESS
-            view_element(File.basename(name))
+            view_element(name)
         else
             retval = false  #- propagate
         end
@@ -408,8 +419,7 @@ def save_changes
     #- remove and reinsert elements to reflect new ordering
     save_attributes = {}
     save_types = {}
-    xmldir = $xmldoc.elements["//dir[@path='#{$current_path}']"]
-    xmldir.elements.each { |element|
+    $xmldir.elements.each { |element|
         if element.name == 'image' || element.name == 'video'
             save_types[element.attributes['filename']] = element.name
             save_attributes[element.attributes['filename']] = element.attributes
@@ -417,7 +427,7 @@ def save_changes
         end
     }
     $autotable.current_order.each { |path|
-        chld = xmldir.add_element save_types[path], save_attributes[path]
+        chld = $xmldir.add_element save_types[path], save_attributes[path]
         chld.add_attribute('caption', $name2widgets[File.basename(path)][:textview].buffer.text)
     }
 end
@@ -427,8 +437,8 @@ def show_thumbnails
     $vbox2textview = {}
     $name2widgets = {}
 
-    xmldir = $xmldoc.elements["//dir[@path='#{$current_path}']"]
-    xmldir.elements.each { |element|
+    $xmldir = $xmldoc.elements["//dir[@path='#{$current_path}']"]
+    $xmldir.elements.each { |element|
         if element.name == 'image' || element.name == 'video'
             dest_img = build_full_dest_filename(element.attributes['filename']).sub(/\.[^\.]+$/, '') + "-#{$default_size['thumbnails']}.jpg"
             msg 3, "dest_img: #{dest_img}"
index 0cfb77672e501bd2939052f66b70b869aa46ea2f..39bb5cf858436bec10f0ac53cad4c58caf841204 100644 (file)
@@ -185,7 +185,7 @@ module Booh
             end
             for dest in dests
                 if !File.exists?(dest['filename'])
-                    cmd = "#{$convert} #{convert_options}-geometry #{dest['size']} '#{orig}' '#{dest['filename']}'"
+                    cmd = "#{$convert} #{convert_options}-size #{dest['size']} -resize #{dest['size']} '#{orig}' '#{dest['filename']}'"
                     if allow_background
                         psys(cmd)
                     else