From: gc Date: Sun, 29 Jan 2006 16:58:44 +0000 (+0000) Subject: dont abort when user specifies a character system locale cannot encode in "new album... X-Git-Tag: 0.9.0~282 X-Git-Url: http://git.zarb.org/?p=booh;a=commitdiff_plain;h=69e975189495415c4509de41860199ef24af3297 dont abort when user specifies a character system locale cannot encode in "new album" dialog --- diff --git a/bin/booh b/bin/booh index ad765a1..cd6f1b4 100755 --- a/bin/booh +++ b/bin/booh @@ -2718,31 +2718,35 @@ def new_album Thread.kill(src_nb_thread) src_nb_thread = nil end - if File.directory?(from_utf8_safe(src_nb_calculated_for)) && src_nb_calculated_for != '/' - if File.readable?(from_utf8_safe(src_nb_calculated_for)) - src_nb_thread = Thread.new { - gtk_thread_protect { src_nb.set_markup(utf8(_("processing..."))) } - total = { 'image' => 0, 'video' => 0, nil => 0 } - `find '#{from_utf8_safe(src_nb_calculated_for)}' -type d -follow`.each { |dir| - if File.basename(dir) =~ /^\./ - next - else - begin - Dir.entries(dir.chomp).each { |file| - total[entry2type(file)] += 1 - } - rescue Errno::EACCES, Errno::ENOENT + if src_nb_calculated_for != '' && from_utf8_safe(src_nb_calculated_for) == '' + src_nb.set_markup(utf8(_("invalid source directory"))) + else + if File.directory?(from_utf8_safe(src_nb_calculated_for)) && src_nb_calculated_for != '/' + if File.readable?(from_utf8_safe(src_nb_calculated_for)) + src_nb_thread = Thread.new { + gtk_thread_protect { src_nb.set_markup(utf8(_("processing..."))) } + total = { 'image' => 0, 'video' => 0, nil => 0 } + `find '#{from_utf8_safe(src_nb_calculated_for)}' -type d -follow`.each { |dir| + if File.basename(dir) =~ /^\./ + next + else + begin + Dir.entries(dir.chomp).each { |file| + total[entry2type(file)] += 1 + } + rescue Errno::EACCES, Errno::ENOENT + end end - end + } + gtk_thread_protect { src_nb.set_markup(utf8(_("%s images and %s videos") % [ total['image'], total['video'] ])) } + src_nb_thread = nil } - gtk_thread_protect { src_nb.set_markup(utf8(_("%s images and %s videos") % [ total['image'], total['video'] ])) } - src_nb_thread = nil - } + else + src_nb.set_markup(utf8(_("permission denied"))) + end else - src_nb.set_markup(utf8(_("permission denied"))) + src_nb.set_markup(utf8(_("N/A"))) end - else - src_nb.set_markup(utf8(_("N/A"))) end end true @@ -2850,17 +2854,18 @@ def new_album while keepon dialog.run { |response| if response == Gtk::Dialog::RESPONSE_OK - srcdir = from_utf8(src.text) - destdir = from_utf8(dest.text) - if !File.directory?(srcdir) + srcdir = from_utf8_safe(src.text) + destdir = from_utf8_safe(dest.text) + confpath = from_utf8_safe(conf.text) + if src.text != '' && srcdir == '' + show_popup(dialog, utf8(_("The directory of images/videos is invalid. Please check your input."))) + src.grab_focus + elsif !File.directory?(srcdir) show_popup(dialog, utf8(_("The directory of images/videos doesn't exist. Please check your input."))) src.grab_focus - elsif conf.text == '' - show_popup(dialog, utf8(_("Please specify a filename to store the album's properties."))) - conf.grab_focus - elsif File.directory?(from_utf8(conf.text)) - show_popup(dialog, utf8(_("Sorry, the filename specified to store the album's properties is an existing directory. Please choose another one."))) - conf.grab_focus + elsif dest.text != '' && destdir == '' + show_popup(dialog, utf8(_("The destination directory is invalid. Please check your input."))) + dest.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 @@ -2870,6 +2875,15 @@ def new_album elsif File.exists?(destdir) && !File.directory?(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 conf.text == '' + show_popup(dialog, utf8(_("Please specify a filename to store the album's properties."))) + conf.grab_focus + elsif conf.text != '' && confpath == '' + show_popup(dialog, utf8(_("The filename to store the album's properties is invalid. Please check your input."))) + conf.grab_focus + elsif File.directory?(confpath) + show_popup(dialog, utf8(_("Sorry, the filename specified to store the album's properties is an existing directory. Please choose another one."))) + conf.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 @@ -2886,14 +2900,16 @@ def new_album end } end - srcdir = from_utf8(src.text) - destdir = from_utf8(dest.text) - 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? - madewith = madewithentry.text + if ok + srcdir = from_utf8(src.text) + destdir = from_utf8(dest.text) + 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? + madewith = madewithentry.text + end if src_nb_thread Thread.kill(src_nb_thread) gtk_thread_flush #- needed because we're about to destroy widgets in dialog, for which they may be some pending gtk calls diff --git a/lib/booh/booh-lib.rb b/lib/booh/booh-lib.rb index e1a7e6f..1121c95 100644 --- a/lib/booh/booh-lib.rb +++ b/lib/booh/booh-lib.rb @@ -63,7 +63,7 @@ module Booh begin return Iconv::iconv($CURRENT_CHARSET, "UTF-8", string).to_s rescue Iconv::IllegalSequence - return nil + return '' end end