Subject: [PATCH] Processdialog prerequisite check support

From: Martin Abente <[email-masked]>
Date: Thu, 29 Jul 2010 17:20:45 -0400

---
 src/jarabe/journal/processdialog.py |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/jarabe/journal/processdialog.py b/src/jarabe/journal/processdialog.py
index 08c6d11..181174d 100644
--- a/src/jarabe/journal/processdialog.py
+++ b/src/jarabe/journal/processdialog.py
@@ -48,6 +48,7 @@ class ProcessDialog(gtk.Window):
         self._start_message = _('Running')
         self._failed_message = _('Failed')
         self._finished_message = _('Finished')
+        self._prerequisite_message = ('Prerequisites were not met')
 
         self.set_border_width(style.LINE_WIDTH)
         width = gtk.gdk.screen_width()
@@ -125,7 +126,7 @@ class ProcessDialog(gtk.Window):
 
         self._close_button = gtk.Button()
         self._close_button.set_image(icon)
-        self._close_button.set_label(_('Cancel'))
+        self._close_button.set_label(_('Close'))
         self._close_button.connect('clicked', self.__close_cb)
         self._close_button.show()
 
@@ -165,12 +166,18 @@ class ProcessDialog(gtk.Window):
         self.destroy()
 
     def __start_cb(self, button):
-        self._process_management.do_process([self._process_script] + self._process_params)
+        if self._check_prerequisites():
+            self._process_management.do_process([self._process_script] + self._process_params)
+        else:
+            self._set_status_failed(self, error_message=self._prerequisite_message)
 
     def __restart_cb(self, button):
         session_manager = get_session_manager()
         session_manager.logout()
 
+    def _check_prerequisites(self):
+        return True
+
     def _set_status_started(self, model, data=None):
         self._message.set_markup(self._start_message)
 
@@ -199,12 +206,13 @@ class ProcessDialog(gtk.Window):
         else:
             self._close_button.show()
 
-    def _set_status_failed(self, model, error_message=''):
+    def _set_status_failed(self, model=None, error_message=''):
         self._message.set_markup('%s %s' % (self._failed_message, error_message))
 
         self._progress_bar.hide()
         self._start_button.show()
         self._close_button.show()
+        self._restart_button.hide()
 
         logging.error(error_message)
 
@@ -246,6 +254,11 @@ class VolumeRestoreDialog(ProcessDialog):
         self._message.set_markup('%s %s.\n\n' % (_('Journal content will be restored from'), volume_path) + \
                                  '<big><b>%s</b> %s</big>' % (_('Warning:'), _('Current Journal content will be deleted!')))
 
+        self._prerequisite_message = _(', please close all the running activities.')
+
+    def _check_prerequisites(self):
+        return len(shell.get_model()) <= 1
+
 class XSBackupDialog(ProcessDialog):
 
     def __init__(self, xs_hostname):
@@ -276,3 +289,7 @@ class XSRestoreDialog(ProcessDialog):
 
         self._message.set_text('%s %s.' % (_('Journal content will be restored from'), xs_hostname))
 
+        self._prerequisite_message = _(', please close all the running activities.')
+
+    def _check_prerequisites(self):
+        return len(shell.get_model()) <= 1
-- 
1.6.0.4