allow to change the number of thumbnails per row
authorgc <gc>
Fri, 29 Jul 2005 20:46:59 +0000 (20:46 +0000)
committergc <gc>
Fri, 29 Jul 2005 20:46:59 +0000 (20:46 +0000)
bin/booh
bin/booh-backend
data/booh/themes/simple/metadata/parameters.rb
data/booh/themes/simple/skeleton_thumbnails.html
lib/booh/booh-lib.rb

index 4943d57..a4357ba 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -2088,9 +2088,10 @@ def open_file(filename)
 
     limit_sizes = $xmldoc.root.attributes['limit-sizes']
     optimizefor32 = !$xmldoc.root.attributes['optimize-for-32'].nil?
+    nperrow = $xmldoc.root.attributes['thumbnails-per-row']
 
     $filename = filename
-    select_theme(theme, limit_sizes, optimizefor32)
+    select_theme(theme, limit_sizes, optimizefor32, nperrow)
     $default_size['thumbnails'] =~ /(.*)x(.*)/
     $default_thumbnails = { :x => $1.to_i, :y => $2.to_i }
     $albums_thumbnail_size =~ /(.*)x(.*)/
@@ -2205,6 +2206,8 @@ def new_album
                                    pack_start(sizes = Gtk::HBox.new, false, false, 0))
     vb.add(optimize432 = Gtk::CheckButton.new(utf8(_("Optimize for 3/2 aspect ratio"))))
     tooltips.set_tip(optimize432, utf8(_("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)")), nil)
+    vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("Number of thumbnails per row: "))), false, false, 0).
+                                   pack_start(nperrowradios = Gtk::HBox.new, false, false, 0))
 
     src_nb_calculated_for = ''
     src_nb_thread = nil
@@ -2292,10 +2295,11 @@ def new_album
     }
 
     theme_sizes = []
+    nperrows = []
     recreate_theme_config = proc {
         theme_sizes.each { |e| sizes.remove(e[:widget]) }
         theme_sizes = []
-        select_theme(theme_button.label, 'all', optimize432.active?)
+        select_theme(theme_button.label, 'all', optimize432.active?, nil)
         $images_size.each { |s|
             sizes.add(cb = Gtk::CheckButton.new(sizename(s['name'])))
             if !s['optional']
@@ -2309,6 +2313,22 @@ def new_album
         tooltips.set_tip(cb, utf8(_("Include original image in web-album")), nil)
         theme_sizes << { :widget => cb, :value => 'original' }
         sizes.show_all
+
+        nperrows.each { |e| nperrowradios.remove(e[:widget]) }
+        nperrow_group = nil
+        nperrows = []
+        $allowed_N_values.each { |n|
+            if nperrow_group
+                nperrowradios.add(rb = Gtk::RadioButton.new(nperrow_group, n.to_s, false))
+            else
+                nperrowradios.add(nperrow_group = rb = Gtk::RadioButton.new(n.to_s))
+            end
+            if $default_N == n
+                rb.active = true
+            end
+            nperrows << { :widget => rb, :value => n }
+        }
+        nperrowradios.show_all
     }
     recreate_theme_config.call
 
@@ -2367,6 +2387,7 @@ def new_album
     configskel = File.expand_path(from_utf8(conf.text))
     theme = theme_button.label
     sizes = theme_sizes.find_all { |e| e[:widget].active? }.collect { |e| e[:value] }.join(',')
+    nperrow = nperrows.find { |e| e[:widget].active? }[:value]
     opt432 = optimize432.active?
     if src_nb_thread
         Thread.kill(src_nb_thread)
@@ -2377,7 +2398,8 @@ def new_album
 
     if ok
         call_backend("booh-backend --source '#{srcdir}' --destination '#{destdir}' --config-skel '#{configskel}' --for-gui " +
-                     "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{sizes} #{opt432 ? '--optimize-for-32' : ''} #{additional_booh_options}",
+                     "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{sizes} --thumbnails-per-row #{nperrow} " +
+                     "#{opt432 ? '--optimize-for-32' : ''} #{additional_booh_options}",
                      utf8(_("Please wait while scanning source directory...")),
                      'full scan',
                      { :closure_after => proc { open_file(configskel) } })
@@ -2395,6 +2417,7 @@ def properties
     dest = $xmldoc.root.attributes['destination']
     theme = $xmldoc.root.attributes['theme']
     opt432 = !$xmldoc.root.attributes['optimize-for-32'].nil?
+    nperrow = $xmldoc.root.attributes['thumbnails-per-row']
     limit_sizes = $xmldoc.root.attributes['limit-sizes']
     if limit_sizes
         limit_sizes = limit_sizes.split(/,/)
@@ -2422,12 +2445,16 @@ def properties
                                    pack_start(sizes = Gtk::HBox.new, false, false, 0))
     vb.add(optimize432 = Gtk::CheckButton.new(utf8(_("Optimize for 3/2 aspect ratio"))).set_active(opt432))
     tooltips.set_tip(optimize432, utf8(_("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)")), nil)
+    vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("Number of thumbnails per row: "))), false, false, 0).
+                                   pack_start(nperrowradios = Gtk::HBox.new, false, false, 0))
 
     theme_sizes = []
+    nperrows = []
     recreate_theme_config = proc {
         theme_sizes.each { |e| sizes.remove(e[:widget]) }
         theme_sizes = []
-        select_theme(theme_button.label, 'all', optimize432.active?)
+        select_theme(theme_button.label, 'all', optimize432.active?, nperrow)
+
         $images_size.each { |s|
             sizes.add(cb = Gtk::CheckButton.new(sizename(s['name'])))
             if limit_sizes
@@ -2450,12 +2477,30 @@ def properties
         end
         theme_sizes << { :widget => cb, :value => 'original' }
         sizes.show_all
+
+        nperrows.each { |e| nperrowradios.remove(e[:widget]) }
+        nperrow_group = nil
+        nperrows = []
+        $allowed_N_values.each { |n|
+            if nperrow_group
+                nperrowradios.add(rb = Gtk::RadioButton.new(nperrow_group, n.to_s, false))
+            else
+                nperrowradios.add(nperrow_group = rb = Gtk::RadioButton.new(n.to_s))
+            end
+            nperrowradios.add(Gtk::Label.new('  '))
+            if nperrow && n.to_s == nperrow || !nperrow && $default_N == n
+                rb.active = true
+            end
+            nperrows << { :widget => rb, :value => n.to_s }
+        }
+        nperrowradios.show_all
     }
     recreate_theme_config.call
 
     theme_button.signal_connect('clicked') {
         if newtheme = theme_choose(theme_button.label)
             limit_sizes = nil
+            nperrow = nil
             theme_button.label = newtheme
             recreate_theme_config.call
         end
@@ -2484,18 +2529,23 @@ def properties
     save_theme = theme_button.label
     save_limit_sizes = theme_sizes.find_all { |e| e[:widget].active? }.collect { |e| e[:value] }
     save_opt432 = optimize432.active?
+    save_nperrow = nperrows.find { |e| e[:widget].active? }[:value]
     dialog.destroy
 
-    if ok && (save_theme != theme || save_limit_sizes != limit_sizes || save_opt432 != opt432)
+    if ok && (save_theme != theme || save_limit_sizes != limit_sizes || save_opt432 != opt432 || save_nperrow != nperrow)
         $xmldoc.elements.each('//dir') { |elem|
             elem.delete_attribute('already-generated')
         }
         save_current_file
         call_backend("booh-backend --use-config '#{$filename}' --for-gui --verbose-level #{$verbose_level} " +
-                     "--theme #{theme} --sizes #{save_limit_sizes.join(',')} #{save_opt432 ? '--optimize-for-32' : ''} #{additional_booh_options}",
+                     "--thumbnails-per-row #{save_nperrow} --theme #{theme} --sizes #{save_limit_sizes.join(',')} " +
+                     "#{save_opt432 ? '--optimize-for-32' : ''} #{additional_booh_options}",
                      utf8(_("Please wait while scanning source directory...")),
                      'full scan',
-                     { :closure_after => proc { open_file($filename) } })
+                     { :closure_after => proc {
+                             open_file($filename)
+                             $modified = true
+                         } })
     end
 end
 
index 35eddd6..7a46959 100755 (executable)
@@ -52,6 +52,7 @@ $options = [
     [ '--force',         '-f', GetoptLong::NO_ARGUMENT,       _("Force generation of album even if the GUI marked some directories as already generated") ],
 
     [ '--sizes',         '-S', GetoptLong::REQUIRED_ARGUMENT, _("Specify the list of images sizes to use instead of all specified in the theme (this is a comma-separated list)") ],
+    [ '--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)") ],
     [ '--empty-comments','-e', GetoptLong::NO_ARGUMENT,       _("Prefer empty comments over filename when creating new albums") ],
 
@@ -174,6 +175,9 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
             when '--sizes'
                 $limit_sizes = arg
 
+            when '--thumbnails-per-row'
+                $N_per_row = arg
+
             when '--optimize-for-32'
                 $optimize_for_32 = true
 
@@ -209,8 +213,9 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
         $dest = from_utf8($xmldoc.root.attributes['destination'])
         $theme = $xmldoc.root.attributes['theme']
         $limit_sizes ||= $xmldoc.root.attributes['limit-sizes']
-        if $mode == 'use_config'
+        if $mode == 'use_config' || $mode =~ /^merge_config/
             $optimize_for_32 = !$xmldoc.root.attributes['optimize-for-32'].nil?
+            $N_per_row = $xmldoc.root.attributes['thumbnails-per-row']
         end
     end
 
@@ -229,7 +234,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
         $theme = 'simple'
     end
 
-    select_theme($theme, $limit_sizes, $optimize_for_32)
+    select_theme($theme, $limit_sizes, $optimize_for_32, $N_per_row)
 
     if !$xmldoc
         additional_params = ''
@@ -239,6 +244,9 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
         if $optimize_for_32
             additional_params += " optimize-for-32='true'"
         end
+        if $N_per_row
+            additional_params += " thumbnails-per-row='#{$N_per_row}'"
+        end
         $xmldoc = Document.new "<booh version='#{$VERSION}' source='#{utf8($source)}' destination='#{utf8($dest)}' theme='#{$theme}' #{additional_params}/>"
         $xmldoc << XMLDecl.new(XMLDecl::DEFAULT_VERSION, $CURRENT_CHARSET)
         $mode = 'gen_config'
@@ -256,6 +264,11 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
         else
             $xmldoc.root.delete_attribute('optimize-for-32')
         end
+        if $N_per_row
+            $xmldoc.root.add_attribute('thumbnails-per-row', $N_per_row)
+        else
+            $xmldoc.root.delete_attribute('thumbnails-per-row')
+        end
     end
 end
 
@@ -334,14 +347,15 @@ def html_reload_to_thumbnails
 end
 
 def discover_iterations(iterations, line)
-    if line =~ /~~iterate(\d)_open(_max(\d+))?~~/
+    if line =~ /~~iterate(\d)_open(_max(\d+|N))?~~/
         for iter in iterations.values
             if iter['open']
                 iter['open'] = false
                 iter['close_wait'] = $1.to_i
             end
         end
-        iterations[$1.to_i] = { 'open' => true, 'max' => $3, 'opening' => '', 'closing' => '' }
+        max = $3 == 'N' ? ($N_per_row || $default_N) : $3
+        iterations[$1.to_i] = { 'open' => true, 'max' => max, 'opening' => '', 'closing' => '' }
         if $1.to_i == 1
             line.sub!(/.*/, '~~thumbnails~~')
         else
index 5dfe518..117eca3 100644 (file)
@@ -63,4 +63,7 @@ $images_size = [
     }
 ]
 
+$allowed_N_values = [ 3, 4, 6, 8, 12 ]
+$default_N = 4
+
 $albums_thumbnail_size = '300x225'
index b29679f..2213e90 100644 (file)
@@ -55,8 +55,8 @@ input {
 <table width="100%">
 ~~iterate1_open~~
 <tr>
-    ~~iterate2_open_max4~~
-    <td width="25%" align="center" valign="top">
+    ~~iterate2_open_maxN~~
+    <td align="center" valign="top">
        ~~image_iteration~~
        <p>~~ifvideo?~~<img src="video.png"/>~~fi~~ ~~caption_iteration~~</p>
     </td>
index 36ed034..5214136 100644 (file)
@@ -87,7 +87,7 @@ module Booh
         exit 1
     end
 
-    def select_theme(name, limit_sizes, optimizefor32)
+    def select_theme(name, limit_sizes, optimizefor32, nperrow)
         $theme = name
         msg 3, _("Selecting theme `%s'") % $theme
         themedir = "#{$FPATH}/themes/#{$theme}"
@@ -116,6 +116,13 @@ module Booh
             $albums_thumbnail_size.gsub!(/(\d+x)(\d+)/) { $1 + ($2.to_f*8/9).to_i.to_s }
         end
 
+        if nperrow && nperrow != $default_N
+            ratio = nperrow.to_f / $default_N.to_f
+            $images_size.each { |e|
+                e['thumbnails'].gsub!(/(\d+)x(\d+)/) { ($1.to_f/ratio).to_i.to_s + 'x' + ($2.to_f/ratio).to_i.to_s }
+            }
+        end
+
         $default_size = $images_size.detect { |sizeobj| sizeobj['default'] }
         if $default_size == nil
             $default_size = $images_size[0]