add progressbars when merging and generating album
authorgc <gc>
Sun, 22 May 2005 15:18:48 +0000 (15:18 +0000)
committergc <gc>
Sun, 22 May 2005 15:18:48 +0000 (15:18 +0000)
bin/booh
bin/booh-backend

index de57cba5bef91fcdffc4a6c0562be4827d598971..7b9a50429fd1eb8fb1b651987a70ff8a3b7eae5d 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -161,6 +161,11 @@ def current_dest_dir
     return make_dest_filename(from_utf8($current_path.sub(/^#{Regexp.quote(source)}/, dest)))
 end
 
+def full_src_dir_to_rel(path)
+    source = from_utf8($xmldoc.root.attributes['source'])
+    return path.sub(/^#{Regexp.quote(source)}/, '')
+end
+
 def build_full_dest_filename(filename)
     return current_dest_dir + '/' + make_dest_filename(from_utf8(filename))
 end
@@ -986,33 +991,93 @@ def show_popup(parent, msg, *options)
     }
 end
 
-def wait_message(parent, msg)
+def backend_wait_message(parent, msg, infopipe_path, mode)
     w = Gtk::Window.new
     w.set_transient_for(parent)
     w.modal = true
 
-    vb = Gtk::VBox.new(false, 5)
-    vb.set_border_width(5)
+    vb = Gtk::VBox.new(false, 5).set_border_width(5)
     vb.pack_start(Gtk::Label.new(msg), false, false)
+
+    vb.pack_start(frame1 = Gtk::Frame.new(utf8(_("Thumbnails"))).add(vb1 = Gtk::VBox.new(false, 5)))
+    vb1.pack_start(pb1_1 = Gtk::ProgressBar.new.set_text(utf8(_("Scanning images and videos..."))), false, false)
+    if mode != 'one dir scan'
+        vb1.pack_start(pb1_2 = Gtk::ProgressBar.new.set_text(utf8(_("not started"))), false, false)
+    end
+    if mode == 'web-album'
+        vb.pack_start(frame2 = Gtk::Frame.new(utf8(_("HTML pages"))).add(vb1 = Gtk::VBox.new(false, 5)))
+        vb1.pack_start(pb2 = Gtk::ProgressBar.new.set_text(utf8(_("not started"))), false, false)
+    end
+    vb.pack_start(Gtk::HSeparator.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_start(pb = Gtk::ProgressBar.new.set_pulse_step(0.05), false, false)
-    vb.pack_start(Gtk::HSeparator.new, false, false)
     vb.pack_end(bottom, false, false)
 
-    timeout = Gtk.timeout_add(200) { pb.pulse }
+    infopipe = File.open(infopipe_path, File::RDONLY | File::NONBLOCK)
+    refresh_thread = Thread.new {
+        directories_counter = 0
+        while line = infopipe.gets
+            if line =~ /^directories: (\d+), sizes: (\d+)/
+                directories = $1.to_f + 1
+                sizes = $2.to_f
+            elsif line =~ /^walking: (.+), (\d+) elements$/
+                elements = $2.to_f + 1
+                if mode == 'web-album'
+                    elements += sizes
+                end
+                element_counter = 0
+                pb1_1.fraction = 0
+                if mode != 'one dir scan'
+                    newtext = utf8(full_src_dir_to_rel($1))
+                    newtext = '/' if newtext == ''
+                    pb1_2.text = newtext
+                    directories_counter += 1
+                    pb1_2.fraction = directories_counter / directories
+                end
+            elsif line =~ /^processing element$/
+                element_counter += 1
+                pb1_1.fraction = element_counter / elements
+            elsif line =~ /^processing size$/
+                element_counter += 1
+                pb1_1.fraction = element_counter / elements
+            elsif line =~ /^finished processing sizes$/
+                pb1_1.fraction = 1
+            elsif line =~ /^creating index.html$/
+                pb1_2.text = utf8(_("finished"))
+                pb1_2.fraction = 1
+                directories_counter = 0
+            elsif line =~ /^index.html: (.+)/
+                newtext = utf8(full_src_dir_to_rel($1))
+                newtext = '/' if newtext == ''
+                pb2.text = newtext
+                directories_counter += 1
+                pb2.fraction = directories_counter / directories
+            end
+        end
+    }
 
     w.add(vb)
     w.signal_connect('delete-event') { w.destroy }
-    w.signal_connect('destroy') { Gtk.timeout_remove(timeout) }
+    w.signal_connect('destroy') {
+        Thread.kill(refresh_thread)
+        if infopipe_path
+            infopipe.close
+            system("rm -f #{infopipe_path}")
+        end
+    }
     w.window_position = Gtk::Window::POS_CENTER
     w.show_all
 
     return [ b, w ]
 end
 
-def perform_in_background(cmd, waitmsg, params)
-    button, w8 = wait_message($main_window, waitmsg)
+def call_backend(cmd, waitmsg, mode, params)
+    pipe = Tempfile.new("boohpipe")
+    pipe.close!
+    system("mkfifo #{pipe.path}")
+    cmd += " --info-pipe #{pipe.path}"
+    button, w8 = backend_wait_message($main_window, waitmsg, pipe.path, mode)
     pid = nil
     Thread.new {
         msg 2, cmd
@@ -1760,10 +1825,11 @@ def new_album
     Gtk.timeout_remove(timeout_src_nb)
 
     if ok
-        perform_in_background("booh-backend --source '#{srcdir}' --destination '#{destdir}' --config-skel '#{configskel}' --for-gui " +
-                                  "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{sizes} #{additional_booh_options}",
-                              utf8(_("Please wait while scanning source directory...")),
-                              { :closure_after => proc { open_file(configskel) } })
+        call_backend("booh-backend --source '#{srcdir}' --destination '#{destdir}' --config-skel '#{configskel}' --for-gui " +
+                     "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{sizes} #{additional_booh_options}",
+                     utf8(_("Please wait while scanning source directory...")),
+                     'full scan',
+                     { :closure_after => proc { open_file(configskel) } })
     end
 end
 
@@ -1871,10 +1937,11 @@ def properties
 
     if ok && (save_theme != theme || save_limit_sizes != limit_sizes)
         save_current_file
-        perform_in_background("booh-backend --use-config '#{$filename}' --for-gui " +
-                                  "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{save_limit_sizes.join(',')} #{additional_booh_options}",
-                              utf8(_("Please wait while scanning source directory...")),
-                              { :closure_after => proc { open_file($filename) } })
+        call_backend("booh-backend --use-config '#{$filename}' --for-gui " +
+                     "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{save_limit_sizes.join(',')} #{additional_booh_options}",
+                     utf8(_("Please wait while scanning source directory...")),
+                     'full scan',
+                     { :closure_after => proc { open_file($filename) } })
     end
 end
 
@@ -1883,13 +1950,14 @@ def merge_current
 
     sel = $albums_tv.selection.selected_rows
 
-    perform_in_background("booh-backend --merge-config-onedir '#{$filename}' --dir '#{from_utf8($current_path)}' --for-gui " +
-                              "--verbose-level #{$verbose_level} #{additional_booh_options}",
-                          utf8(_("Please wait while scanning source directory...")),
-                          { :closure_after => proc {
-                                  open_file($filename)
-                                  $albums_tv.selection.select_path(sel[0])
-                              } })
+    call_backend("booh-backend --merge-config-onedir '#{$filename}' --dir '#{from_utf8($current_path)}' --for-gui " +
+                 "--verbose-level #{$verbose_level} #{additional_booh_options}",
+                 utf8(_("Please wait while scanning source directory...")),
+                 'one dir scan',
+                 { :closure_after => proc {
+                         open_file($filename)
+                         $albums_tv.selection.select_path(sel[0])
+                     } })
 end
 
 def merge
@@ -1900,19 +1968,21 @@ def merge
     if limit_sizes
         limit_sizes = "--sizes #{limit_sizes}"
     end
-    perform_in_background("booh-backend --merge-config '#{$filename}' --for-gui " +
-                              "--verbose-level #{$verbose_level} --theme #{theme} #{limit_sizes} #{additional_booh_options}",
-                          utf8(_("Please wait while scanning source directory...")),
-                          { :closure_after => proc { open_file($filename) } })
+    call_backend("booh-backend --merge-config '#{$filename}' --for-gui " +
+                 "--verbose-level #{$verbose_level} --theme #{theme} #{limit_sizes} #{additional_booh_options}",
+                 utf8(_("Please wait while scanning source directory...")),
+                 'full scan',
+                 { :closure_after => proc { open_file($filename) } })
 end
 
 def merge_subalbums
     save_current_file
 
-    perform_in_background("booh-backend --merge-config-newdirs '#{$filename}' --for-gui " +
-                              "--verbose-level #{$verbose_level} #{additional_booh_options}",
-                          utf8(_("Please wait while scanning source directory...")),
-                          { :closure_after => proc { open_file($filename) } })
+    call_backend("booh-backend --merge-config-newdirs '#{$filename}' --for-gui " +
+                 "--verbose-level #{$verbose_level} #{additional_booh_options}",
+                 utf8(_("Please wait while scanning source directory...")),
+                 'full scan',
+                 { :closure_after => proc { open_file($filename) } })
 end
 
 def save_as_do
@@ -2029,10 +2099,11 @@ def create_menu_and_toolbar
     $merge_subalbums.signal_connect('activate') { merge_subalbums }
     $generate.signal_connect('activate') {
         save_current_file
-        perform_in_background("booh-backend --config '#{$filename}' --verbose-level #{$verbose_level} #{additional_booh_options}",
-                              utf8(_("Please wait while generating web-album...\nThis may take a while, please be patient.")),
-                              { :successmsg => utf8(_("Your web-album is now ready in directory `%s'.") % $xmldoc.root.attributes['destination']),
-                                :failuremsg => utf8(_("There was something wrong when generating the web-album, sorry.")) })
+        call_backend("booh-backend --config '#{$filename}' --verbose-level #{$verbose_level} #{additional_booh_options}",
+                     utf8(_("Please wait while generating web-album...\nThis may take a while, please be patient.")),
+                     'web-album',
+                     { :successmsg => utf8(_("Your web-album is now ready in directory `%s'.") % $xmldoc.root.attributes['destination']),
+                       :failuremsg => utf8(_("There was something wrong when generating the web-album, sorry.")) })
     }
     $properties.signal_connect('activate') { properties }
 
index 49226d3c5c00466295a2a35bd7d6267ad5c8178f..747ca8149e960630f7f3d9d76e3a082bbab603ce 100755 (executable)
@@ -58,6 +58,7 @@ $options = [
     [ '--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)") ],
 
     [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, _("Set max verbosity level (0: errors, 1: warnings, 2: important messages, 3: other messages)") ],
+    [ '--info-pipe',     '-i', GetoptLong::REQUIRED_ARGUMENT, _("Name a file where to write information about what's going on (used by the GUI)") ],
 ]
 
 #- default values for some globals 
@@ -192,6 +193,9 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
             when '--verbose-level'
                 $verbose_level = arg.to_i
 
+            when '--info-pipe'
+                $info_pipe = File.open(arg, File::WRONLY)
+                $info_pipe.sync = true
             end
         end
     rescue
@@ -250,6 +254,12 @@ end
 def write_config
 end
 
+def info(value)
+    if $info_pipe
+        $info_pipe.puts(value)
+    end
+end
+
 def check_installation
     if $no_check
         return
@@ -489,6 +499,7 @@ def walk_source_dir
     }
 
     examined_dirs = $mode == 'merge_config_onedir' ? [ $onedir ] : `find '#{$source}' -type d`.sort
+    info("directories: #{examined_dirs.length}, sizes: #{$images_size.length}")
 
     examined_dirs.each { |dir|
         dir.chomp!
@@ -564,6 +575,7 @@ def walk_source_dir
         msg 3, _("\t%s images") % images.length
         videos = entries.find_all { |e| entry2type(e) == 'video' }
         msg 3, _("\t%s videos") % videos.length
+        info("walking: #{dir}, #{images.length + videos.length} elements")
 
         dest_dir = make_dest_filename(dir.sub(/^#{Regexp.quote($source)}/, $dest))
         system("mkdir -p '#{dest_dir}'")
@@ -592,6 +604,7 @@ def walk_source_dir
 
         #- create thumbnails for images
         images.each { |img|
+            info("processing element")
             base_dest_img = dest_dir + '/' + make_dest_filename(img.sub(/\.[^\.]+$/, ''))
             if $forgui
                 thumbnail_dest_img = base_dest_img + "-#{$default_size['thumbnails']}.jpg"
@@ -621,6 +634,7 @@ def walk_source_dir
 
         #- create thumbnails for videos
         videos.each { |video|
+            info("processing element")
             thumbnail_ok = true
             if $forgui
                 thumbnail_dest_img = dest_dir + '/' + make_dest_filename(video.sub(/\.[^\.]+$/, '')) + "-#{$default_size['thumbnails']}.jpg"
@@ -658,6 +672,7 @@ def walk_source_dir
             
             #- generate thumbnails.html (page with thumbnails)
             for sizeobj in $images_size
+                info("processing size")
                 html = $html_thumbnails.collect { |l| l.clone }
                 iterations = {}
                 for i in html
@@ -710,6 +725,8 @@ def walk_source_dir
                 ios.close
             end
 
+            info("finished processing sizes")
+
             #- generate "main" thumbnails.html page that will reload to correct size thanks to cookie
             ios = File.open("#{dest_dir}/thumbnails.html", "w")
             ios.write(html_reload_to_thumbnails)
@@ -798,6 +815,7 @@ def walk_source_dir
     end
 
     #- second pass to create index.html files
+    info("creating index.html")
     msg 3, _("\trescanning directories to generate all `index.html' files...")
 
     examined_dirs.each { |dir|
@@ -807,6 +825,7 @@ def walk_source_dir
             next
         end
         dest_dir = make_dest_filename(dir.sub(/^#{Regexp.quote($source)}/, $dest))
+        info("index.html: #{dir}")
 
         if xmldir.elements['dir']
             html = $html_index.collect { |l| l.clone }