allow to specify an arbitrary format for comments of new images
authorgc <gc>
Sat, 14 Jan 2006 17:20:07 +0000 (17:20 +0000)
committergc <gc>
Sat, 14 Jan 2006 17:20:07 +0000 (17:20 +0000)
bin/booh
bin/booh-backend

index c5079a2bda5b44c09cc7908d075b61ef9a4308de..eb26318dd1198b269dac87e2faaedd2c29819d82 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -109,6 +109,7 @@ def read_config
     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['comments-format'] ||= '%t'
     if !FileTest.directory?(File.expand_path('~/.booh'))
         system("mkdir ~/.booh")
     end
@@ -370,16 +371,14 @@ def create_editzone(scrolledwindow, pagenum, image)
         end
         false  #- propagate
     }
-    textview.signal_connect('focus-in-event') { |w, event|
-        textview.buffer.select_range(textview.buffer.get_iter_at_offset(0), textview.buffer.get_iter_at_offset(-1))
-        false  #- propagate
-    }
 
     candidate_undo_text = nil
     textview.signal_connect('focus-in-event') { |w, event|
+        textview.buffer.select_range(textview.buffer.get_iter_at_offset(0), textview.buffer.get_iter_at_offset(-1))
         candidate_undo_text = textview.buffer.text
         false  #- propagate
     }
+
     textview.signal_connect('key-release-event') { |w, event|
         if candidate_undo_text && candidate_undo_text != textview.buffer.text
             $modified = true
@@ -520,7 +519,7 @@ from. There are approximately 25 frames per second in a video.
             false  #- propagate if needed
         end
     }
-    
+
     dialog.window_position = Gtk::Window::POS_MOUSE
     dialog.show_all
 
@@ -1686,7 +1685,7 @@ def show_popup(parent, msg, *options)
         sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
         sw.add_with_viewport(lbl)
         dialog.vbox.add(sw)
-        dialog.set_default_size(400, 500)
+        dialog.set_default_size(500, 600)
     else
         dialog.vbox.add(lbl)
         dialog.set_default_size(200, 120)
@@ -2644,9 +2643,7 @@ def additional_booh_options
     if $config['mproc']
         options += "--mproc #{$config['mproc'].to_i} "
     end
-    if $config['emptycomments']
-        options += "--empty-comments "
-    end
+    options += "--comments-format '#{$config['comments-format']}'"
     return options
 end
 
@@ -3135,7 +3132,7 @@ def preferences
     notebook.append_page(tbl = Gtk::Table.new(0, 0, false), Gtk::Label.new(utf8(_("Options"))))
     tbl.attach(Gtk::Alignment.new(1, 0.5, 0, 0).add(Gtk::Label.new.set_markup(utf8(_("Command for watching videos: ")))),
                0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK, 2, 2)
-    tbl.attach(Gtk::Alignment.new(0, 0.5, 1, 0).add(video_viewer_entry = Gtk::Entry.new.set_text($config['video-viewer'])),
+    tbl.attach(Gtk::Alignment.new(0, 0.5, 1, 0).add(video_viewer_entry = Gtk::Entry.new.set_text($config['video-viewer']).set_size_request(250, -1)),
                1, 2, 0, 1, Gtk::FILL, Gtk::SHRINK, 2, 2)
     tooltips = Gtk::Tooltips.new
     tooltips.set_tip(video_viewer_entry, utf8(_("Use %f to specify the filename;
@@ -3154,12 +3151,10 @@ for example: /usr/bin/mozilla-firefox -remote 'openURL(%f,new-window)' || /usr/b
     tbl.attach(nogestures_check = Gtk::CheckButton.new(utf8(_("Disable mouse gestures"))),
                0, 2, 3, 4, Gtk::FILL, Gtk::SHRINK, 2, 2)
     tooltips.set_tip(nogestures_check, utf8(_("Mouse gestures are 'unusual' mouse movements triggering special actions, and are great for speeding up your editions. Get details on available mouse gestures from the Help menu.")), nil)
-    tbl.attach(emptycomments_check = Gtk::CheckButton.new(utf8(_("Use empty comments for new albums"))),
-               0, 2, 4, 5, Gtk::FILL, Gtk::SHRINK, 2, 2)
-    tooltips.set_tip(emptycomments_check, utf8(_("Normally, filenames are used as comments for new albums. Check this if you prefer empty comments.")), nil)
     tbl.attach(deleteondisk_check = Gtk::CheckButton.new(utf8(_("Delete original images/videos as well"))),
                0, 2, 5, 6, Gtk::FILL, Gtk::SHRINK, 2, 2)
     tooltips.set_tip(deleteondisk_check, utf8(_("Normally, deleting an image or video in booh only removes it from the web-album. If you check this option, the original file in source directory will be removed as well. Undo is possible, since actual deletion is performed only when web-album is saved.")), nil)
+
     smp_check.signal_connect('toggled') {
         if smp_check.active?
             smp_hbox.sensitive = true
@@ -3172,7 +3167,6 @@ for example: /usr/bin/mozilla-firefox -remote 'openURL(%f,new-window)' || /usr/b
         smp_spin.value = $config['mproc'].to_i
     end
     nogestures_check.active = $config['nogestures']
-    emptycomments_check.active = $config['emptycomments']
     deleteondisk_check.active = $config['deleteondisk']
 
     notebook.append_page(tbl = Gtk::Table.new(0, 0, false), Gtk::Label.new(utf8(_("Advanced"))))
@@ -3180,6 +3174,155 @@ for example: /usr/bin/mozilla-firefox -remote 'openURL(%f,new-window)' || /usr/b
                0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
     tbl.attach(enhance_entry = Gtk::Entry.new.set_text($config['convert-enhance'] || $convert_enhance).set_size_request(250, -1),
                1, 2, 0, 1, Gtk::FILL, Gtk::SHRINK, 2, 2)
+    tbl.attach(Gtk::Label.new.set_markup(utf8(_("Format to use for comments of \nimages in new albums:"))),
+               0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK, 2, 2)
+    tbl.attach(commentsformat_entry = Gtk::Entry.new.set_text($config['comments-format']),
+               1, 2, 1, 2, Gtk::FILL, Gtk::SHRINK, 2, 2)
+    tbl.attach(commentsformat_help = Gtk::Button.new(Gtk::Stock::HELP),
+               2, 3, 1, 2, Gtk::FILL, Gtk::SHRINK, 2, 2)
+    tooltips.set_tip(commentsformat_entry, utf8(_("Normally, filenames without extension are used as comments for images and videos in new albums. Use this entry to use something else for images.")), nil)
+    commentsformat_help.signal_connect('clicked') {
+        show_popup(dialog, utf8(_("The comments format you specify is actually passed to the 'identify' program,
+hence you should look at ImageMagick/identify documentation for the most    
+accurate and up-to-date documentation. Last time I checked, documentation
+was:
+
+Print information about the image in a format of your choosing. You can
+include the image filename, type, width, height, Exif data, or other image
+attributes by embedding special format characters:                          
+
+                     %O   page offset
+                     %P   page width and height                             
+                     %b   file size                                         
+                     %c   comment                                           
+                     %d   directory                                         
+                     %e   filename extension                                
+                     %f   filename                                          
+                     %g   page geometry                                     
+                     %h   height                                            
+                     %i   input filename                                    
+                     %k   number of unique colors                           
+                     %l   label                                             
+                     %m   magick                                            
+                     %n   number of scenes                                  
+                     %o   output filename                                   
+                     %p   page number                                       
+                     %q   quantum depth                                     
+                     %r   image class and colorspace                        
+                     %s   scene number                                      
+                     %t   top of filename                                   
+                     %u   unique temporary filename                         
+                     %w   width                                             
+                     %x   x resolution                                      
+                     %y   y resolution                                      
+                     %z   image depth                                       
+                     %@   bounding box                                      
+                     %#   signature                                         
+                     %%   a percent sign                                    
+                                                                            
+For example,                                                                
+                                                                            
+    %m:%f %wx%h
+                                                                            
+displays MIFF:bird.miff 512x480 for an image titled bird.miff and whose
+width is 512 and height is 480.                
+                                                                            
+If the first character of string is @, the format is read from a file titled
+by the remaining characters in the string.
+                                                                            
+You can also use the following special formatting syntax to print Exif
+information contained in the file:
+                                                                            
+    %[EXIF:tag]                                                             
+                                                                            
+Where tag can be one of the following:                                      
+                                                                            
+    *  (print all Exif tags, in keyword=data format)                        
+    !  (print all Exif tags, in tag_number data format)                     
+    #hhhh (print data for Exif tag #hhhh)                                   
+    ImageWidth                                                              
+    ImageLength                                                             
+    BitsPerSample                                                           
+    Compression                                                             
+    PhotometricInterpretation                                               
+    FillOrder                                                               
+    DocumentName                                                            
+    ImageDescription                                                        
+    Make                                                                    
+    Model                                                                   
+    StripOffsets                                                            
+    Orientation                                                             
+    SamplesPerPixel                                                         
+    RowsPerStrip                                                            
+    StripByteCounts                                                         
+    XResolution                                                             
+    YResolution                                                             
+    PlanarConfiguration                                                     
+    ResolutionUnit                                                          
+    TransferFunction                                                        
+    Software                                                                
+    DateTime                                                                
+    Artist                                                                  
+    WhitePoint                                                              
+    PrimaryChromaticities                                                   
+    TransferRange                                                           
+    JPEGProc                                                                
+    JPEGInterchangeFormat                                                   
+    JPEGInterchangeFormatLength                                             
+    YCbCrCoefficients                                                       
+    YCbCrSubSampling                                                        
+    YCbCrPositioning                                                        
+    ReferenceBlackWhite                                                     
+    CFARepeatPatternDim                                                     
+    CFAPattern                                                              
+    BatteryLevel                                                            
+    Copyright                                                               
+    ExposureTime                                                            
+    FNumber                                                                 
+    IPTC/NAA                                                                
+    ExifOffset                                                              
+    InterColorProfile                                                       
+    ExposureProgram                                                         
+    SpectralSensitivity                                                     
+    GPSInfo                                                                 
+    ISOSpeedRatings                                                         
+    OECF                                                                    
+    ExifVersion                                                             
+    DateTimeOriginal                                                        
+    DateTimeDigitized                                                       
+    ComponentsConfiguration                                                 
+    CompressedBitsPerPixel                                                  
+    ShutterSpeedValue                                                       
+    ApertureValue                                                           
+    BrightnessValue                                                         
+    ExposureBiasValue                                                       
+    MaxApertureValue                                                        
+    SubjectDistance                                                         
+    MeteringMode                                                            
+    LightSource                                                             
+    Flash                                                                   
+    FocalLength                                                             
+    MakerNote                                                               
+    UserComment                                                             
+    SubSecTime                                                              
+    SubSecTimeOriginal                                                      
+    SubSecTimeDigitized                                                     
+    FlashPixVersion                                                         
+    ColorSpace                                                              
+    ExifImageWidth                                                          
+    ExifImageLength                                                         
+    InteroperabilityOffset                                                  
+    FlashEnergy                                                             
+    SpatialFrequencyResponse                                                
+    FocalPlaneXResolution                                                   
+    FocalPlaneYResolution                                                   
+    FocalPlaneResolutionUnit                                                
+    SubjectLocation                                                         
+    ExposureIndex                                                           
+    SensingMethod                                                           
+    FileSource                                                              
+    SceneType")), { :scrolled => true })
+    }
 
     dialog.vbox.show_all
     dialog.run { |response|
@@ -3192,10 +3335,10 @@ for example: /usr/bin/mozilla-firefox -remote 'openURL(%f,new-window)' || /usr/b
                 $config.delete('mproc')
             end
             $config['nogestures'] = nogestures_check.active?
-            $config['emptycomments'] = emptycomments_check.active?
             $config['deleteondisk'] = deleteondisk_check.active?
 
             $config['convert-enhance'] = enhance_entry.text
+            $config['comments-format'] = commentsformat_entry.text.gsub(/'/, '')
         end
     }
     dialog.destroy
@@ -3227,7 +3370,7 @@ def show_one_click_explanation(intro)
 on a thumbnail will immediately apply the desired action.
 
 Click the <span foreground='darkblue'>None</span> icon when you're finished with One-Click tools.
-") % intro))
+") % intro), { :pos_centered => true })
 end
 
 def get_license
@@ -3621,7 +3764,7 @@ Click to view it in your browser:") % $xmldoc.root.attributes['destination']),
     speed.image = Gtk::Image.new("#{$FPATH}/images/stock-info-16.png")
     helpsubmenu.append(tutos = Gtk::ImageMenuItem.new(utf8(_("Online tutorials (opens a web-browser)"))))
     tutos.image = Gtk::Image.new("#{$FPATH}/images/stock-web-16.png")
-    helpsubmenu.append(        Gtk::SeparatorMenuItem.new)
+    helpsubmenu.append(Gtk::SeparatorMenuItem.new)
     helpsubmenu.append(about = Gtk::ImageMenuItem.new(Gtk::Stock::ABOUT))
     helpmenu.set_submenu(helpsubmenu)
     mb.append(helpmenu)
index 07b1dbd67ea5e9f07f7462cb32383b0c71d91ce7..382237225deddd52a760897d04bac58a4f493853 100755 (executable)
@@ -54,7 +54,7 @@ $options = [
     [ '--thumbnails-per-row', '-T', GetoptLong::REQUIRED_ARGUMENT, _("Specify the amount of thumbnails per row in the thumbnails page (if applicable in theme)") ],
     [ '--optimize-for-32', '-o', GetoptLong::NO_ARGUMENT,       _("Resize images with optimized sizes for 3/2 aspect ratio rather than 4/3 (typical aspect ratio of pictures from non digital cameras are 3/2 when pictures from digital cameras are 4/3)") ],
     [ '--made-with',     '-n', GetoptLong::REQUIRED_ARGUMENT, _("Specify the HTML markup to use on the bottom of pages") ],
-    [ '--empty-comments','-e', GetoptLong::NO_ARGUMENT,       _("Prefer empty comments over filename when creating new albums") ],
+    [ '--comments-format','-c', GetoptLong::REQUIRED_ARGUMENT, _("Specify comments format to use for images instead of only filename when creating new albums; use ImageMagick's format") ],
 
     [ '--mproc',         '-m', GetoptLong::REQUIRED_ARGUMENT, _("Specify the number of processors for multi-processors machines") ],
 
@@ -200,8 +200,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
             when '--made-with'
                 $madewith = arg
 
-            when '--empty-comments'
-                $empty_comments = true
+            when '--comments-format'
+                $commentsformat = arg
 
             when '--force'
                 $force = true
@@ -674,7 +674,12 @@ def walk_source_dir
                 else
                     type = entry2type(file)
                     if type && !xmldir.elements["#{type}[@filename='#{utf8(file)}']"]
-                        xmldir.add_element type, { "filename" => utf8(file), "caption" => $empty_comments ? '' : utf8cut(file.sub(/\.[^\.]+$/, ''), 18) }
+                        if $commentsformat && type == 'image'
+                            comment = utf8(`identify -format "#{$commentsformat}" '#{dir}/#{file}'`.chomp.sub(/\.$/, ''))
+                        else
+                            comment = utf8cut(file.sub(/\.[^\.]+$/, ''), 18)
+                        end
+                        xmldir.add_element type, { "filename" => utf8(file), "caption" => comment }
                     end
                 end
             end