changeset 421:28e4299d4553

primitivus: profile manager updated to use new asynchronous profile creation
author Goffi <goffi@goffi.org>
date Wed, 02 Nov 2011 22:50:06 +0100
parents acd908528ef7
children 5a18c5f08d9b
files frontends/src/bridge/DBus.py frontends/src/primitivus/profile_manager.py
diffstat 2 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py	Wed Nov 02 22:49:23 2011 +0100
+++ b/frontends/src/bridge/DBus.py	Wed Nov 02 22:50:06 2011 +0100
@@ -24,6 +24,7 @@
 from logging import debug, error
 
 const_INT_PREFIX = "org.goffi.SAT"  #Interface prefix
+const_ERROR_PREFIX = const_INT_PREFIX+".error"
 const_OBJ_PATH = '/org/goffi/SAT/bridge'
 const_CORE_SUFFIX = ".core"
 const_PLUGIN_SUFFIX = ".plugin"
@@ -60,10 +61,13 @@
         return self.db_core_iface.addContact(entity_jid, profile_key)
 
     def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
-        return self.db_core_iface.asyncConnect(profile_key, reply_handler=callback, error_handler=errback)
+        return self.db_core_iface.asyncConnect(profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
+
+    def asyncCreateProfile(self, profile, callback=None, errback=None):
+        return self.db_core_iface.asyncCreateProfile(profile, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
 
     def asyncGetParamA(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None):
-        return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, profile_key, reply_handler=callback, error_handler=errback))
+        return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])))
 
     def callMenu(self, category, name, menu_type, profile_key):
         return unicode(self.db_core_iface.callMenu(category, name, menu_type, profile_key))
--- a/frontends/src/primitivus/profile_manager.py	Wed Nov 02 22:49:23 2011 +0100
+++ b/frontends/src/primitivus/profile_manager.py	Wed Nov 02 22:50:06 2011 +0100
@@ -68,11 +68,27 @@
     def newProfile(self, button, edit):
         """Create the profile"""
         name = edit.get_edit_text()
-        self.host.bridge.createProfile(name)
+        self.host.bridge.asyncCreateProfile(name, callback=lambda: self._newProfileCreated(name), errback=self._profileCreationFailure)
+
+    def _newProfileCreated(self, name):
         self.__refillProfiles()
         #We select the profile created in the list
         self.list_profile.selectValue(name)
         self.host.removePopUp()
+        self.host.redraw()
+
+    def _profileCreationFailure(self, reason):
+        self.host.removePopUp()
+        if reason=="CONFLICT":
+            message=_("A profile with this name already exists")
+        elif reason=="CANCELED":
+            message=_("Profile creation cancelled by backend")
+        elif reason=="DATABASE":
+            message=_("Database error")
+        else:
+            message=_("Unknown reason (%s)") % reason
+        popup = Alert(_("Can't create profile"), message, ok_cb=self.host.removePopUp)
+        self.host.showPopUp(popup)
 
     def deleteProfile(self, button):
         profile_name = self.list_profile.getSelectedValue()
@@ -81,7 +97,6 @@
             self.__refillProfiles()
         self.host.removePopUp()
         
-
     def onNewProfile(self, e):
         pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile)
         self.host.showPopUp(pop_up_widget)