fix all problems I could see with dirs/filenames containing spaces/accented chars...
[booh] / bin / booh-gui
index 81b531a5c62fbb2f2b0bd20753e2358c5b7f82d6..fc155a457bc08715a9f9f3a62bb8247aaefcb487 100755 (executable)
@@ -156,7 +156,7 @@ end
 def current_dest_dir
     source = $xmldoc.root.attributes['source']
     dest = $xmldoc.root.attributes['destination']
-    return make_dest_filename(from_utf8($current_path).sub(/^#{Regexp.quote(source)}/, dest))
+    return make_dest_filename($current_path.sub(/^#{Regexp.quote(source)}/, dest))
 end
 
 def build_full_dest_filename(filename)
@@ -170,7 +170,7 @@ end
 
 def view_element(filename)
     if entry2type(filename) == 'video'
-        system("mplayer #{$current_path + '/' + filename}")
+        system("mplayer '#{from_utf8($current_path + '/' + filename)}'")
         return
     end
 
@@ -198,7 +198,7 @@ def view_element(filename)
     evt = Gtk::EventBox.new.add(Gtk::Alignment.new(0.5, 0.5, 0, 0).add(Gtk::Frame.new.add(Gtk::Image.new(dest_img)).set_shadow_type(Gtk::SHADOW_ETCHED_OUT)))
 
     tooltips = Gtk::Tooltips.new
-    tooltips.set_tip(evt, utf8(File.basename(filename).gsub(/\.jpg/, '')), nil)
+    tooltips.set_tip(evt, File.basename(filename).gsub(/\.jpg/, ''), nil)
 
     bottom = Gtk::Alignment.new(0.5, 0.5, 0, 0).add(b = Gtk::Button.new(Gtk::Stock::CLOSE))
     b.signal_connect('clicked') { w.destroy }
@@ -447,7 +447,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
     evtbox = Gtk::EventBox.new.add(Gtk::Alignment.new(0.5, 0.5, 0, 0).add(frame1.set_shadow_type(Gtk::SHADOW_ETCHED_OUT)))
 
     tooltips = Gtk::Tooltips.new
-    tipname = File.basename(thumbnail_img).gsub(/-\d+x\d+\.jpg/, '')
+    tipname = from_utf8(File.basename(filename).gsub(/\.[^\.]+$/, ''))
     tooltips.set_tip(evtbox, utf8(type == 'video' ? (_("%s (video - %s KB)") % [tipname, commify(file_size(from_utf8("#{$current_path}/#{filename}"))/1024)]) : tipname), nil)
 
     frame2, textview = create_editzone($autotable_sw, 1)
@@ -1348,7 +1348,7 @@ def new_album
                     src_nb_thread = Thread.new {
                         src_nb.set_markup(utf8(_("<span size='small'><i>processing...</i></span>")))
                         total = { 'image' => 0, 'video' => 0, nil => 0 }
-                        `find #{from_utf8(src_nb_calculated_for)} -type d`.each { |dir|
+                        `find '#{from_utf8(src_nb_calculated_for)}' -type d`.each { |dir|
                             begin
                                 Dir.entries(dir.chomp).each { |file|
                                     total[entry2type(file)] += 1
@@ -1462,6 +1462,9 @@ def new_album
                 elsif conf.text == ''
                     show_popup(dialog, utf8(_("Please specify a filename to store the album's properties.")))
                     conf.grab_focus
+                elsif destdir != make_dest_filename(destdir)
+                    show_popup(dialog, utf8(_("Sorry, destination directory can't contain non simple alphanumeric characters.")))
+                    dest.grab_focus
                 elsif File.directory?(destdir)
                     keepon = !show_popup(dialog, utf8(_("The destination directory already exists. Are you sure you want to continue?")), { :okcancel => true })
                     dest.grab_focus
@@ -1496,7 +1499,7 @@ def new_album
     Gtk.timeout_remove(timeout_src_nb)
 
     if ok
-        perform_in_background("booh --source #{srcdir} --destination #{destdir} --config-skel #{configskel} --for-gui " +
+        perform_in_background("booh --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) } })
@@ -1606,7 +1609,7 @@ def properties
     dialog.destroy
 
     if ok && (save_theme != theme || save_limit_sizes != limit_sizes)
-        perform_in_background("booh --merge-config #{$filename} --for-gui " +
+        perform_in_background("booh --merge-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) } })
@@ -1621,7 +1624,7 @@ def merge
     if limit_sizes
         limit_sizes = "--sizes #{limit_sizes}"
     end
-    perform_in_background("booh --merge-config #{$filename} --for-gui " +
+    perform_in_background("booh --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) } })
@@ -1725,7 +1728,7 @@ def create_menu_and_toolbar
     $merge.signal_connect('activate') { merge }
     $generate.signal_connect('activate') {
         save_current_file
-        perform_in_background("booh --config #{$filename} --verbose-level #{$verbose_level} #{additional_booh_options}",
+        perform_in_background("booh --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.")) })