make "abort" to abort immediately
authorgc <gc>
Sun, 24 Apr 2005 00:10:38 +0000 (00:10 +0000)
committergc <gc>
Sun, 24 Apr 2005 00:10:38 +0000 (00:10 +0000)
bin/booh-gui

index c91c5b67ed4d4b6f73315d30b64ba1b7c1642e00..b909cf699373c8863acec0085260968ad9d9d554 100755 (executable)
@@ -802,6 +802,7 @@ end
 def wait_message(parent, msg)
     w = Gtk::Window.new
     w.set_transient_for(parent)
+    w.modal = true
 
     vb = Gtk::VBox.new(false, 5)
     vb.pack_start(Gtk::Label.new(msg), false, false)
@@ -812,7 +813,6 @@ def wait_message(parent, msg)
     vb.pack_end(bottom, false, false)
 
     timeout = Gtk.timeout_add(200) { pb.pulse }
-    b.signal_connect_after('clicked') { w.destroy }
 
     w.add(vb)
     w.signal_connect('delete-event') { w.destroy }
@@ -823,6 +823,37 @@ def wait_message(parent, msg)
     return [ b, w ]
 end
 
+def perform_in_background(cmd, waitmsg, params)
+    button, w8 = wait_message($main_window, waitmsg)
+    pid = nil
+    Thread.new {
+        msg 2, cmd
+        if pid = fork
+            id, exitstatus = Process.waitpid2(pid)
+            w8.destroy
+            if exitstatus == 0
+                if params[:successmsg]
+                    show_popup($main_window, params[:successmsg])
+                end
+                if params[:closure_after]
+                    params[:closure_after].call
+                end
+            elsif exitstatus == 15
+                #- say nothing, user aborted
+            else
+                if params[:failuremsg]
+                    show_popup($main_window, params[:failuremsg])
+                end
+            end
+        else
+            exec(cmd)
+        end
+    }
+    button.signal_connect('clicked') {
+        Process.kill('SIGTERM', pid)
+    }
+end
+
 def save_changes
     if !$current_path
         return
@@ -1381,18 +1412,10 @@ def new_album
     dialog.destroy
 
     if ok
-        button, w8 = wait_message($main_window, utf8(_("Please wait while scanning source directory...")))
-        backend = Thread.new {
-            cmd = "booh --source #{srcdir} --destination #{destdir} --config-skel #{configskel} --for-gui " +
-                  "--verbose-level #{$verbose_level} --theme #{theme} #{additional_booh_options}"
-            msg 2, cmd
-            system(cmd)
-            w8.destroy
-            open_file(configskel)
-        }
-        button.signal_connect('clicked') {
-            Thread.kill(backend)
-        }
+        perform_in_background("booh --source #{srcdir} --destination #{destdir} --config-skel #{configskel} --for-gui " +
+                                  "--verbose-level #{$verbose_level} --theme #{theme} #{additional_booh_options}",
+                              utf8(_("Please wait while scanning source directory...")),
+                              { :closure_after => proc { open_file(configskel) } })
     end
 end
 
@@ -1484,18 +1507,11 @@ def create_menu_and_toolbar
     $save.signal_connect('activate') { save_current_file }
     $save_as.signal_connect('activate') { save_as_do }
     $generate.signal_connect('activate') {
-        button, w8 = wait_message($main_window, utf8(_("Please wait while generating web-album...\nThis may take a while, please be patient.")))
-        backend = Thread.new {
-            save_current_file
-            cmd = "booh --config #{$filename} --verbose-level #{$verbose_level} #{additional_booh_options}"
-            msg 2, cmd
-            system(cmd)
-            w8.destroy
-            show_popup($main_window, utf8(_("Your web-album is now ready in directory `%s'.") % $xmldoc.root.attributes['destination'] ))
-        }
-        button.signal_connect('clicked') {
-            Thread.kill(backend)
-        }
+        save_current_file
+        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.")) })
     }
 
     quit.signal_connect('activate') { try_quit }