workaround progression pipe bug
[booh] / bin / booh
index 4843b9da3da43c579ea87a7dded8ffa807a35886..5766217ce57cc70ddd8ba30eb0682d7a15abd51c 100644 (file)
--- a/bin/booh
+++ b/bin/booh
@@ -10,7 +10,7 @@
 # called Boo, so this one will be it "Booh". Or whatever.
 #
 #
-# Copyright (c) 2004-2011 Guillaume Cottenceau <http://zarb.org/~gc/resource/gc_mail.png>
+# Copyright (c) 2004-2013 Guillaume Cottenceau <http://zarb.org/~gc/resource/gc_mail.png>
 #
 # This software may be freely redistributed under the terms of the GNU
 # public license version 2.
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
+begin
+    require 'rubygems'
+rescue LoadError
+end
+
 require 'getoptlong'
 require 'tempfile'
 require 'thread'
@@ -31,7 +36,7 @@ require 'gettext'
 include GetText
 bindtextdomain("booh")
 
-require 'booh/rexml/document'
+require 'rexml/document'
 include REXML
 
 require 'booh/booh-lib'
@@ -74,7 +79,7 @@ def handle_options
             when '--version'
                 puts _("Booh version %s
 
-Copyright (c) 2005-2011 Guillaume Cottenceau.
+Copyright (c) 2005-2013 Guillaume Cottenceau.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") % $VERSION
 
@@ -92,6 +97,14 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
     end
 end
 
+def count_cpus
+    cpus = 0
+    for line in IO.readlines('/proc/cpuinfo') do
+        line =~ /^processor/ and cpus += 1
+    end
+    return cpus
+end
+
 def read_config
     $config = {}
     $config_file = File.expand_path('~/.booh-gui-rc')
@@ -126,17 +139,14 @@ def read_config
     $config['video-viewer'] ||= '/usr/bin/mplayer %f || /usr/bin/vlc %f'
     $config['image-editor'] ||= '/usr/bin/gimp-remote %f || /usr/bin/gimp %f'
     $config['browser'] ||= "/usr/bin/mozilla-firefox -remote 'openURL(%f,new-window)' || /usr/bin/mozilla-firefox %f || /usr/bin/firefox -remote 'openURL(%f,new-window)' || /usr/bin/firefox %f"
-    $config['use-flv'] ||= "true"
-    $config['flv-generator'] ||= "/usr/bin/ffmpeg -i %f -b 800k -ar 22050 -ab 32k %o"
+    $config['use-mp4'] ||= "true"
+    $config['mp4-generator'] ||= "/usr/bin/ffmpeg -i %f -b 800k -ar 22050 -ab 32k %o"
     $config['comments-format'] ||= '%t'
     if !FileTest.directory?(File.expand_path('~/.booh'))
         system("mkdir ~/.booh")
     end
     if $config['mproc'].nil?
-        cpus = 0
-        for line in IO.readlines('/proc/cpuinfo') do
-            line =~ /^processor/ and cpus += 1
-        end
+        cpus = count_cpus
         if cpus > 1
             $config['mproc'] = cpus
         end
@@ -157,15 +167,15 @@ Hint: don't forget to specify the full path to the executable,
 e.g. '/usr/bin/mplayer' is correct but 'mplayer' only is not.") % viewer_binary), { :pos_centered => true, :not_transient => true })
     end
 
-    flv_generator_binary = $config['use-flv'] == 'true' && $config['flv-generator'].split.first
-    if flv_generator_binary && !File.executable?(flv_generator_binary)
-        show_popup($main_window, utf8(_("The configured .flv generator seems to be unavailable.
+    mp4_generator_binary = $config['use-mp4'] == 'true' && $config['mp4-generator'].split.first
+    if mp4_generator_binary && !File.executable?(mp4_generator_binary)
+        show_popup($main_window, utf8(_("The configured .mp4 generator seems to be unavailable.
 You should fix this in Edit/Preferences so that you can have working
 embedded flash videos.
 
 Problem was: '%s' is not an executable file.
 Hint: don't forget to specify the full path to the executable,
-e.g. '/usr/bin/ffmpeg' is correct but 'ffmpeg' only is not.") % flv_generator_binary), { :pos_centered => true, :not_transient => true })
+e.g. '/usr/bin/ffmpeg' is correct but 'ffmpeg' only is not.") % mp4_generator_binary), { :pos_centered => true, :not_transient => true })
     end
 end
 
@@ -188,6 +198,15 @@ It is generally available with the 'ImageMagick' software package.")), { :pos_ce
     end
 
     check_config_preferences_dep
+
+    cpus = count_cpus
+
+    if $config['cpus'] && cpus > $config['cpus'].to_i
+        show_popup($main_window, utf8(_("It seems you now have more CPUs available than last time booh was run.
+You should probably increase the amount of CPUs configured in Edit/Preferences,
+so that web-albums are generated as fast as possible on this computer.")), { :pos_centered => true, :not_transient => true })
+    end
+    $config['cpus'] = cpus
 end
 
 def check_image_editor
@@ -482,9 +501,9 @@ def update_shown_pixbuf(thumbnail_img, img, desired_x, desired_y)
         pixbuf = rotate_pixbuf(pixbuf, $modified_pixbufs[thumbnail_img][:angle_to_orig])
         msg 3, "sizes: #{pixbuf.width} #{pixbuf.height} - desired #{desired_x}x#{desired_x}"
         if pixbuf.height > desired_y
-            pixbuf = pixbuf.scale(pixbuf.width * (desired_y.to_f/pixbuf.height), desired_y, Gdk::Pixbuf::INTERP_BILINEAR)
+            pixbuf = pixbuf.scale(pixbuf.width * (desired_y.to_f/pixbuf.height), desired_y, :bilinear)
         elsif pixbuf.width < desired_x && pixbuf.height < desired_y
-            pixbuf = pixbuf.scale(desired_x, pixbuf.height * (desired_x.to_f/pixbuf.width), Gdk::Pixbuf::INTERP_BILINEAR)
+            pixbuf = pixbuf.scale(desired_x, pixbuf.height * (desired_x.to_f/pixbuf.width), :bilinear)
         end
     end
 
@@ -1174,7 +1193,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
     }
 
     if type == 'video'
-        pxb = Gdk::Pixbuf.new("#{$FPATH}/images/video_border.png")
+        pxb = GdkPixbuf::Pixbuf.new(:file => "#{$FPATH}/images/video_border.png")
         frame1.add(Gtk::HBox.new.pack_start(da1 = Gtk::DrawingArea.new.set_size_request(pxb.width, -1), false, false).
                                  pack_start(img = Gtk::Image.new).
                                  pack_start(da2 = Gtk::DrawingArea.new.set_size_request(pxb.width, -1), false, false))
@@ -2107,6 +2126,8 @@ def backend_wait_message(parent, msg, infopipe_path, mode)
     infopipe = File.open(infopipe_path, File::RDONLY | File::NONBLOCK)
     refresh_thread = Thread.new {
         directories_counter = 0
+        #- immediately stops if trying to read before file is written from backend.. simple dirty solution for the moment
+        sleep 1 
         while line = infopipe.gets
             msg 3, "infopipe got data: #{line}"
             if line =~ /^directories: (\d+), sizes: (\d+)/
@@ -2340,6 +2361,8 @@ def sort_by_exif_date
                 date_time = Exif.datetimeoriginal(from_utf8($current_path + "/" + f))
                 if ! date_time.nil?
                     dates[f] = date_time
+                elsif f =~ /(20\d{2}).?(\d{2}).?(\d{2}).(\d{2}).?(\d{2}).?(\d{2})/
+                    dates[f] = "#$1:#$2:#$3 #$4:#$5:#$6"
                 end
             end
             if aborted
@@ -2356,6 +2379,8 @@ def sort_by_exif_date
             date_time = Exif.datetimeoriginal(from_utf8($current_path + "/" + f))
             if ! date_time.nil?
                 dates[f] = date_time
+            elsif f =~ /(20\d{2}).?(\d{2}).?(\d{2}).(\d{2}).?(\d{2}).?(\d{2})/
+                dates[f] = "#$1:#$2:#$3 #$4:#$5:#$6"
             end
         }
     end
@@ -2495,7 +2520,8 @@ def change_dir
                             else
                                 tmpimage = "#{tmpdir}/00000001.jpg"
                                 begin
-                                    preview_img.pixbuf = Gdk::Pixbuf.new(tmpimage, 240, 180)
+                                    preview_img.pixbuf = GdkPixbuf::Pixbuf.new(:file => tmpimage, :width => 240,
+                                                                               :height => 180)
                                     fc.preview_widget_active = true
                                 rescue Gdk::PixbufError
                                     fc.preview_widget_active = false
@@ -2507,7 +2533,7 @@ def change_dir
                         end
                     else
                         begin
-                            preview_img.pixbuf = rotate_pixbuf(Gdk::Pixbuf.new(fc.preview_filename, 240, 180), guess_rotate(fc.preview_filename))
+                            preview_img.pixbuf = rotate_pixbuf(GdkPixbuf::Pixbuf.new(:file => fc.preview_filename, :width => 240, :height => 180), guess_rotate(fc.preview_filename))
                             fc.preview_widget_active = true
                         rescue Gdk::PixbufError
                             fc.preview_widget_active = false
@@ -2816,7 +2842,7 @@ end
 
 def pixbuf_or_nil(filename)
     begin
-        return Gdk::Pixbuf.new(filename)
+        return GdkPixbuf::Pixbuf.new(:file => filename)
     rescue
         return nil
     end
@@ -2844,7 +2870,7 @@ def theme_choose(current)
 
     dialog.vbox.add(sw = Gtk::ScrolledWindow.new(nil, nil).add(treeview).set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC))
 
-    ([ $FPATH + '/themes/simple' ] + (`find '#{$FPATH}/themes' ~/.booh-themes -mindepth 1 -maxdepth 1 -type d 2>/dev/null`.split("\n").find_all { |e| e !~ /simple$/ }.sort)).each { |dir|
+    ([ $FPATH + '/themes/gradient' ] + (`find '#{$FPATH}/themes' ~/.booh-themes -mindepth 1 -maxdepth 1 -type d 2>/dev/null`.split("\n").find_all { |e| e !~ /\bgradient\b/ }.sort)).each { |dir|
         dir.chomp!
         iter = model.append
         iter[0] = File.basename(dir)
@@ -3124,8 +3150,8 @@ def additional_booh_options
     if $config['transcode-videos']
         options += "--transcode-videos '#{$config['transcode-videos']}' "
     end
-    if $config['use-flv'] == 'true'
-        options += "--flv-generator '#{$config['flv-generator']}' "
+    if $config['use-mp4'] == 'true'
+        options += "--mp4-generator '#{$config['mp4-generator']}' "
     end
     return options
 end
@@ -3292,7 +3318,7 @@ def new_album
     tooltips = Gtk::Tooltips.new
     frame2 = Gtk::Frame.new(utf8(_("Configuration"))).add(vb = Gtk::VBox.new)
     vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("Theme: "))), false, false, 0).
-                         pack_start(theme_button = Gtk::Button.new($config['default-theme'] || 'simple'), false, false, 0))
+                         pack_start(theme_button = Gtk::Button.new($config['default-theme'] || 'gradient'), false, false, 0))
     vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("Sizes of images to generate: "))), false, false, 0).
                                    pack_start(sizes = Gtk::HBox.new, false, false, 0))
     vb.add(optimize432 = Gtk::CheckButton.new(utf8(_("Optimize for 3/2 aspect ratio"))).set_active($config['default-optimize32'].to_b))
@@ -3953,12 +3979,11 @@ for example: /usr/bin/gimp-remote %f")), nil)
 for example: /usr/bin/mozilla-firefox -remote 'openURL(%f,new-window)' || /usr/bin/mozilla-firefox %f")), nil)
 
     table_counter += 1
-    tbl.attach(Gtk::Alignment.new(1, 0.5, 0, 0).add(flv_check = Gtk::CheckButton.new(utf8(_("Use embedded flash player for videos,\nand use this .flv generator:")))),
+    tbl.attach(Gtk::Alignment.new(1, 0.5, 0, 0).add(mp4_check = Gtk::CheckButton.new(utf8(_("Use this .mp4 generator for videos:")))),
                0, 1, table_counter, table_counter + 1, Gtk::FILL, Gtk::SHRINK, 2, 2)
-    tbl.attach(Gtk::Alignment.new(0, 0.5, 1, 0).add(flv_generator_entry = Gtk::Entry.new.set_text($config['flv-generator']).set_sensitive(false)),
+    tbl.attach(Gtk::Alignment.new(0, 0.5, 1, 0).add(mp4_generator_entry = Gtk::Entry.new.set_text($config['mp4-generator']).set_sensitive(false)),
                1, 2, table_counter, table_counter + 1, Gtk::FILL, Gtk::SHRINK, 2, 2)
-    tooltips.set_tip(flv_check, utf8(_("Flowplayer will be used for embedded video playback")), nil)
-    tooltips.set_tip(flv_generator_entry, utf8(_("Use %f to specify the input filename, %o the output filename;
+    tooltips.set_tip(mp4_generator_entry, utf8(_("Use %f to specify the input filename, %o the output filename;
 for example: /usr/bin/ffmpeg -i %f -b ${i}k -ar 22050 -ab 32k %o")), nil)
 
     table_counter += 1
@@ -3978,11 +4003,11 @@ for example: /usr/bin/ffmpeg -i %f -b ${i}k -ar 22050 -ab 32k %o")), nil)
                0, 2, table_counter, table_counter + 1, Gtk::FILL, Gtk::SHRINK, 2, 2)
     tooltips.set_tip(deleteondisk_check, utf8(_("Normally, deleting a photo 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)
 
-    flv_check.signal_connect('toggled') {
-        flv_generator_entry.sensitive = flv_check.active?
+    mp4_check.signal_connect('toggled') {
+        mp4_generator_entry.sensitive = mp4_check.active?
     }
-    if $config['use-flv'] == 'true'
-        flv_check.active = true
+    if $config['use-mp4'] == 'true'
+        mp4_check.active = true
     end
     smp_check.signal_connect('toggled') {
         smp_hbox.sensitive = smp_check.active?
@@ -4170,11 +4195,11 @@ for example: avi:mencoder -nosound -ovc xvid -xvidencopts bitrate=800:me_quality
             $config['video-viewer'] = from_utf8(video_viewer_entry.text)
             $config['image-editor'] = from_utf8(image_editor_entry.text)
             $config['browser'] = from_utf8(browser_entry.text)
-            if flv_check.active?
-                $config['use-flv'] = 'true'
-                $config['flv-generator'] = from_utf8(flv_generator_entry.text)
+            if mp4_check.active?
+                $config['use-mp4'] = 'true'
+                $config['mp4-generator'] = from_utf8(mp4_generator_entry.text)
             else
-                $config['use-flv'] = 'false'
+                $config['use-mp4'] = 'false'
             end
             if smp_check.active?
                 $config['mproc'] = smp_spin.value.to_i
@@ -4258,7 +4283,7 @@ def perform_remote_synchronization(url, detail_label, progressbar_window, dialog
         if ! ok_to_mirror
             gtk_thread_protect {
                 progressbar_window.destroy
-                show_popup(dialog, utf8(_("Specified URL incorrect, please check your input.")), { :pos_centered => true })
+                show_popup(dialog, utf8(_("Failed to connect to specified URL, please check your input.")), { :pos_centered => true })
             }
             return
         end
@@ -4447,7 +4472,6 @@ def create_menu_and_toolbar
     $extend.signal_connect('activate') { extend_ }
     $generate.signal_connect('activate') {
         save_current_file
-        warning_flv_not_working = $config['use-flv'] == 'true' ? _("Notice: flash videos normally don't play locally.\n") : ''
         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',
@@ -4456,8 +4480,7 @@ def create_menu_and_toolbar
 As multi-languages is activated, you will not be able to view it
 locally in your browser though.") % $xmldoc.root.attributes['destination']) :
                          utf8(_("Your web-album is now ready in directory '%s'.
-%s
-Click to view it in your browser:") % [ $xmldoc.root.attributes['destination'], warning_flv_not_working ]),
+Click to view it in your browser:") % [ $xmldoc.root.attributes['destination'] ]),
                        :successmsg_linkurl => $xmldoc.root.attributes['multi-languages'] ? $xmldoc.root.attributes['destination'] :
                                                                                            $xmldoc.root.attributes['destination'] + '/index.html',
                        :closure_after => proc {
@@ -5034,7 +5057,7 @@ def create_main_window
         end
     }
 
-    $albums_ts = Gtk::TreeStore.new(String, String, Gdk::Pixbuf)
+    $albums_ts = Gtk::TreeStore.new(String, String, GdkPixbuf::Pixbuf)
     $albums_tv.set_model($albums_ts)
     $albums_tv.signal_connect('realize') { $albums_tv.grab_focus }