--- guake-0.4.0.orig/src/guake.py	2009-03-25 17:19:41.000000000 +0200
+++ guake-0.4.0.mine/src/guake.py	2009-08-25 19:19:03.000000000 +0300
@@ -35,6 +35,7 @@
 import sys
 from thread import start_new_thread
 from time import sleep
+import posix
 
 import globalhotkeys
 from simplegladeapp import SimpleGladeApp, bindtextdomain
@@ -50,6 +51,36 @@
 bindtextdomain(name, locale_dir)
 
 
+class PromptQuitDialog(SimpleGladeApp):
+    """Prompts the user whether to quit or not if there are procs running.
+    """
+    def __init__ (self, parent, runningProcs):
+        super(PromptQuitDialog, self).__init__(gladefile('prompt_on_quit.glade'),
+                                             root='promptdialog')
+        self.parent = parent
+        self.dialog = self.get_widget('promptdialog')
+        self.dialog.set_keep_above (True)
+
+        self.parent.show_hide ()
+
+        if runningProcs == 1:
+            self.get_widget("labelNumberOfProcs").set_markup(
+                "<b>There is one process still running.</b>"
+            )
+        elif runningProcs > 1:
+            self.get_widget("labelNumberOfProcs").set_markup(
+                "<b>There are %d processes running...</b>" % runningProcs
+            )
+
+    def on_buttonQuit_clicked(self, Button, *data):
+        gtk.main_quit ()
+
+    def on_buttonCancel_clicked(self, Button, *data):
+        self.parent.show_hide ()
+        self.dialog.destroy()
+        return gtk.FALSE
+
+
 class AboutDialog(SimpleGladeApp):
     """The About Guake dialog class
     """
@@ -337,7 +368,7 @@
         key, mask = gtk.accelerator_parse(gets('quit'))
         if key > 0:
             self.accel_group.connect_group(key, mask, gtk.ACCEL_VISIBLE,
-                                           gtk.main_quit)
+                                           self.guake.accel_quit)
 
         key, mask = gtk.accelerator_parse(gets('new_tab'))
         if key > 0:
@@ -731,12 +762,34 @@
         window_rect.height = window_rect.height * height / 100
         return window_rect
 
+    def get_running_fg_processes(self):
+        """Get the number processes for each terminal/tab. The code is taken
+        from gnome-terminal.
+        """
+        total_procs = 0
+
+        term_idx = 0
+        for terminal in self.term_list:
+            fdpty    = terminal.get_pty ()
+            term_pid = self.pid_list [term_idx]
+
+            fgpid = posix.tcgetpgrp(fdpty)
+            if fgpid == -1 or fgpid == term_pid:
+            	pass
+            else:
+            	total_procs += 1
+
+            term_idx += 1
+
+        return total_procs
+
     # -- configuration --
 
     def load_config(self):
         """"Just a proxy for all the configuration stuff.
         """
         self.client.notify(KEY('/general/use_trayicon'))
+        self.client.notify(KEY('/general/prompt_on_quit'))
         self.client.notify(KEY('/general/window_tabbar'))
         self.client.notify(KEY('/general/window_ontop'))
         self.client.notify(KEY('/general/window_size'))
@@ -750,6 +803,19 @@
         self.client.notify(KEY('/style/background/transparency'))
         self.client.notify(KEY('/general/use_default_font'))
 
+    def accel_quit(self, *args):
+        """Callback to prompt the user whether to quit Guake or not.
+        """
+        if self.client.get_bool(KEY('/general/prompt_on_quit')):
+            procs = self.get_running_fg_processes()
+
+            if procs >= 1:
+                PromptQuitDialog (self, procs)
+            else:
+                gtk.main_quit ()
+        else:
+            gtk.main_quit ()
+
     def accel_add(self, *args):
         """Callback to add a new tab. Called by the accel key.
         """

