support choosing images sizes
authorgc <gc>
Mon, 25 Apr 2005 21:25:34 +0000 (21:25 +0000)
committergc <gc>
Mon, 25 Apr 2005 21:25:34 +0000 (21:25 +0000)
bin/booh
bin/booh-gui
data/booh/themes/simple/metadata/parameters.rb
data/booh/themes/simple/skeleton_image.html
data/booh/themes/simple/skeleton_thumbnails.html
lib/booh/booh-lib.rb

index 2855e518287b03d729839bfd5c57ef71d1b8888d..4ce1f123cfc6de65a421d4af25cd22e2a9f8be4f 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -46,6 +46,8 @@ $options = [
     [ '--config-skel',   '-k', GetoptLong::REQUIRED_ARGUMENT, _("Filename where the script will output a config skeleton") ],
     [ '--merge-config',  '-M', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, where to merge new images/videos from --source") ],
 
+    [ '--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)") ],
+
     [ '--mproc',         '-m', GetoptLong::REQUIRED_ARGUMENT, _("Specify the number of processors for multi-processors machines") ],
 
     [ '--for-gui',       '-g', GetoptLong::NO_ARGUMENT,       _("Do the minimum work to be able to see the album under the GUI (don't generate all thumbnails)") ],
@@ -120,6 +122,9 @@ def handle_options
                     die _('Config file does not exist or is unreadable.')
                 end
 
+            when '--sizes'
+                $limit_sizes = arg
+
             when '--mproc'
                 $mproc = arg.to_i
                 $pids = []
@@ -142,6 +147,7 @@ def handle_options
         $source = $xmldoc.root.attributes['source']
         $dest = $xmldoc.root.attributes['destination']
         $theme = $xmldoc.root.attributes['theme']
+        $limit_sizes = $xmldoc.root.attributes['limit-sizes']
     end
 
     if !$source
@@ -153,11 +159,16 @@ def handle_options
     if !$theme
         $theme = 'simple'
     end
-    select_theme($theme)
+
+    select_theme($theme, $limit_sizes)
 
     if !$xmldoc
-        $xmldoc = Document.new "<booh version='#{$VERSION}' source='#{utf8($source)}' destination='#{utf8($dest)}' theme='#{$theme}'/>"
-        $xmldoc << XMLDecl.new( XMLDecl::DEFAULT_VERSION, $CURRENT_CHARSET )
+        additional_params = ''
+        if $limit_sizes
+            additional_params += "limit-sizes='#{$limit_sizes}'"
+        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'
     end
 
@@ -293,6 +304,24 @@ def img_element(fullpath)
     return '<img src="' + File.basename(fullpath) + '" ' + sizespec + ' border="0"/>'
 end
 
+def substitute_html_sizes(html, sizeobj, type)
+    sizestrings = []
+    if $images_size.length > 1
+        for sizeobj2 in $images_size
+            if sizeobj != sizeobj2
+                if type == 'thumbnails'
+                    sizestrings << '<a href="thumbnails-' + sizeobj2['name'] + '.html">' + sizename(sizeobj2['name']) + '</a>'
+                else
+                    sizestrings << '<a id="link' + sizeobj2['name'] + '">' + sizename(sizeobj2['name']) + '</a>'
+                end
+            else
+                sizestrings << sizename(sizeobj2['name'])
+            end
+        end
+    end
+    html.sub!(/~~sizes~~(.+)~~/) { sizestrings.join($1) }
+end
+
 def walk_source_dir
 
     `find #{$source} -type d`.sort.each { |dir|
@@ -435,9 +464,6 @@ def walk_source_dir
                 end
             end
 
-            #- fake for gettext to find these; if themes need more sizes, english name for them should be added here
-            sizenames = { 'small' => utf8(_("small")), 'medium' => utf8(_("medium")), 'large' => utf8(_("large")) }
-
             msg 3, _("\tgenerating HTML pages...")
             
             #- generate thumbnails.html (page with thumbnails)
@@ -447,13 +473,7 @@ def walk_source_dir
                 for i in html
                     i.sub!(/~~run_slideshow~~/, images.size <= 1 ? '' : '<a href="image-' + sizeobj['name'] + '.html?run_slideshow">' + utf8(_('Run slideshow!')) + '</a>')
                     i.sub!(/~~title~~/, xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir)))
-                    for sizeobj2 in $images_size
-                        if sizeobj != sizeobj2
-                            i.sub!(/~~size_#{sizeobj2['name']}~~/, '<a href="thumbnails-' + sizeobj2['name'] + '.html">' + sizenames[sizeobj2['name']] + '</a>')
-                        else
-                            i.sub!(/~~size_#{sizeobj2['name']}~~/, sizenames[sizeobj2['name']])
-                        end
-                    end
+                    substitute_html_sizes(i, sizeobj, 'thumbnails')
                     discover_iterations(iterations, i)
                 end
                 html_thumbnails = ''
@@ -527,15 +547,7 @@ def walk_source_dir
                         i.gsub!(/~~thumbnails~~/, '<a href="thumbnails-' + sizeobj['name'] + '.html" id="thumbnails">' + utf8(_('Return to thumbnails')) + '</a>')
                         i.gsub!(/~~theme~~/, $theme)
                         i.gsub!(/~~current_size~~/, sizeobj['name'])
-                        for sizeobj2 in $images_size
-                            if sizeobj != sizeobj2
-                                i.sub!(/~~size_#{sizeobj2['name']}~~/,
-                                       '<a id="link' + sizeobj2['name'] + '">' + sizenames[sizeobj2['name']] + '</a>')
-                            else
-                                i.sub!(/~~size_#{sizeobj2['name']}~~/,
-                                       sizenames[sizeobj2['name']])
-                            end
-                        end
+                        substitute_html_sizes(i, sizeobj, 'image')
                     end
                     ios = File.open("#{dest_dir}/image-#{sizeobj['name']}.html", "w")
                     ios.write(html)
index 8eeac85aa28db22cb2cb3b6f06a9c0292d83db2c..85abed92982bf93f875b903b91a1bdca29bbf204 100755 (executable)
@@ -1150,6 +1150,11 @@ def theme_choose(current)
     treeview.append_column(Gtk::TreeViewColumn.new(utf8(_("Thumbnails page look")), Gtk::CellRendererPixbuf.new, { :pixbuf => 2 }).set_alignment(0.5).set_spacing(5))
     treeview.append_column(Gtk::TreeViewColumn.new(utf8(_("Fullscreen page look")), Gtk::CellRendererPixbuf.new, { :pixbuf => 3 }).set_alignment(0.5).set_spacing(5))
     treeview.append_column(Gtk::TreeViewColumn.new('', Gtk::CellRendererText.new, {}))
+    treeview.signal_connect('button-press-event') { |w, event|
+        if event.event_type == Gdk::Event::BUTTON2_PRESS && event.button == 1
+            dialog.response(Gtk::Dialog::RESPONSE_OK)
+        end
+    }
 
     dialog.vbox.add(sw = Gtk::ScrolledWindow.new(nil, nil).add(treeview).set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC))
 
@@ -1215,8 +1220,10 @@ def open_file(filename)
         return utf8(_("Corrupted booh file..."))
     end
 
+    limit_sizes = $xmldoc.root.attributes['limit-sizes']
+
     $filename = filename
-    select_theme(theme)
+    select_theme(theme, limit_sizes)
     $default_size['thumbnails'] =~ /(.*)x(.*)/
     $default_thumbnails = { :x => $1.to_i, :y => $2.to_i }
     $albums_thumbnail_size =~ /(.*)x(.*)/
@@ -1321,6 +1328,10 @@ def new_album
                0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
     tbl.attach(theme_button = Gtk::Button.new($config['default-theme'] || 'simple'),
                1, 2, 0, 1, Gtk::FILL, Gtk::SHRINK, 2, 2)
+    tbl.attach(Gtk::Label.new(utf8(_("Sizes of images to generate: "))),
+               0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
+    tbl.attach(sizes = Gtk::HBox.new,
+               1, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
 
     src_nb_calculated_for = ''
     src_nb_thread = nil
@@ -1403,9 +1414,27 @@ def new_album
         fc.destroy
     }
 
+    theme_sizes = []
+    recreate_theme_config = proc {
+        theme_sizes.each { |e| sizes.remove(e[:widget]) }
+        theme_sizes = []
+        select_theme(theme_button.label, nil)
+        $images_size.each { |s|
+            sizes.add(cb = Gtk::CheckButton.new(sizename(s['name'])).set_active(true))
+            tooltips = Gtk::Tooltips.new
+            tooltips.set_tip(cb, utf8(s['description']), nil)
+            theme_sizes << { :widget => cb, :value => s['name'] }
+        }
+        sizes.add(cb = Gtk::CheckButton.new(utf8(_('original'))))
+        theme_sizes << { :widget => cb, :value => 'original' }
+        sizes.show_all
+    }
+    recreate_theme_config.call
+
     theme_button.signal_connect('clicked') {
         if newtheme = theme_choose(theme_button.label)
             theme_button.label = newtheme
+            recreate_theme_config.call
         end
     }
 
@@ -1433,6 +1462,8 @@ def new_album
                 elsif File.exists?(destdir)
                     show_popup(dialog, utf8(_("There is already a file by the name of the destination directory. Please choose another one.")))
                     dest.grab_focus
+                elsif !theme_sizes.detect { |e| e[:value] != 'original' && e[:widget].active? }
+                    show_popup(dialog, utf8(_("You need to select at least one size (not counting original).")))
                 else
                     system("mkdir '#{destdir}'")
                     if !File.directory?(destdir)
@@ -1451,12 +1482,16 @@ def new_album
     destdir = from_utf8(dest.text)
     configskel = from_utf8(conf.text)
     theme = theme_button.label
+    sizes = theme_sizes.find_all { |e| e[:widget].active? }.collect { |e| e[:value] }.join(',')
     dialog.destroy
+    if src_nb_thread
+        Thread.kill(src_nb_thread)
+    end
     Gtk.timeout_remove(timeout_src_nb)
 
     if ok
         perform_in_background("booh --source #{srcdir} --destination #{destdir} --config-skel #{configskel} --for-gui " +
-                                  "--verbose-level #{$verbose_level} --theme #{theme} #{additional_booh_options}",
+                                  "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{sizes} #{additional_booh_options}",
                               utf8(_("Please wait while scanning source directory...")),
                               { :closure_after => proc { open_file(configskel) } })
     end
index fdac89029ca2f2af8543bf20fd0c3bc27ae69881..7a0fc5c6d5c2fe5dd310320f345e5114ab40af8c 100644 (file)
 $images_size = [
     {
         'name' => 'small',
+        'description' => _("Fullscreen 552x414, thumbnails 192x144, should fit 800x600 screens"),
         'fullscreen' => '552x414',
         'thumbnails' => '192x144',
     },
     {
         'name' => 'medium',
+        'description' => _("Fullscreen 704x528, thumbnails 240x180, should fit 1024x768 screens"),
         'fullscreen' => '704x528',
         'thumbnails' => '240x180',
         'default' => true,
     },
     {
         'name' => 'large',
+        'description' => _("Fullscreen 880x660, thumbnails 300x225, should fit 1280x1024 screens"),
         'fullscreen' => '880x660',
         'thumbnails' => '300x225',
     }
index d7764f8b3585da6c5e0fb92fb2a0bee7097bf85f..4cc3f44d7d201e49b40be9cd4d7088b6c6713131 100644 (file)
@@ -44,7 +44,7 @@ input {
     <td width="1%">~~~button_first~~~</td>
     <td width="3%">&nbsp;</td>
     <td width="1%">~~~button_previous~~~</td>
-    <td align="center"><font size="-2">~~size_small~~ | ~~size_medium~~ | ~~size_large~~</font></td>
+    <td align="center"><font size="-2">~~sizes~~ | ~~</font></td>
     <td width="1%">~~~button_next~~~</td>
     <td width="3%">&nbsp;</td>
     <td width="1%">~~~button_last~~~</td>
index 42ab8fccb39f4ca532f7d67929a6d2c2358e7e31..e75c97a1f09830e21944537c6ee5d5dc602315ca 100644 (file)
@@ -41,7 +41,7 @@ input {
 <p align="center">
     <font size="+3">~~title~~</font>
     <br/>
-    <font size="-2">~~size_small~~ | ~~size_medium~~ | ~~size_large~~</font>
+    <font size="-2">~~sizes~~ | ~~</font>
     <br/>
     <br/>
     ~~run_slideshow~~
index 15868e5f13ad43c95fd779e5f898af865a6e716c..dfc138becedda6b90a4bca16fe01f64659005618 100644 (file)
@@ -38,6 +38,12 @@ module Booh
     def utf8(string)
         return Iconv::iconv("UTF-8", $CURRENT_CHARSET, string).to_s
     end
+
+    def sizename(key)
+        #- fake for gettext to find these; if themes need more sizes, english name for them should be added here
+        sizenames = { 'small' => utf8(_("small")), 'medium' => utf8(_("medium")), 'large' => utf8(_("large")) }
+        return sizenames[key] || key
+    end
     
     def from_utf8(string)
         return Iconv::iconv($CURRENT_CHARSET, "UTF-8", string).to_s
@@ -79,17 +85,25 @@ module Booh
         exit 1
     end
 
-    def select_theme(name)
+    def select_theme(name, limit_sizes)
         $theme = name
         msg 3, _("Selecting theme `%s'") % $theme
         themedir = "#{$FPATH}/themes/#{$theme}"
         if !File.directory?(themedir)
             die _("Theme was not found (tried %s directory).") % themedir
         end
-        require "#{themedir}/metadata/parameters.rb"
+        eval File.open("#{themedir}/metadata/parameters.rb").readlines.join
+
+        if limit_sizes
+            sizes = limit_sizes.split(/,/)
+            $images_size = $images_size.find_all { |e| sizes.include?(e['name']) }
+            if $images_size.length == 0
+                die _("Can't carry on, no valid size selected.")
+            end
+        end
         $default_size = $images_size.detect { |sizeobj| sizeobj['default'] }
         if $default_size == nil
-            die _("Theme `%s' has no default size.") % $theme
+            $default_size = $images_size[0]
         end
     end