diff frontends/src/primitivus/profile_manager.py @ 413:dd4caab17008

core: - individual parameters managed through sqlite - new asyncGetParamA method, which allow to get parameter for a not connected profile ==> individual parameters are cached in memory when the profile is connected, but must be accessed though sqlite else, and that must be done asynchronously primitivus: - profile manager updated to use asyncGetParamA /!\ still broken, need more work before being able to run again
author Goffi <goffi@goffi.org>
date Tue, 01 Nov 2011 20:39:22 +0100
parents b1794cbb88e5
children 28e4299d4553
line wrap: on
line diff
--- a/frontends/src/primitivus/profile_manager.py	Sun Oct 30 23:13:40 2011 +0100
+++ b/frontends/src/primitivus/profile_manager.py	Tue Nov 01 20:39:22 2011 +0100
@@ -91,12 +91,15 @@
         self.host.showPopUp(pop_up_widget)
 
     def onProfileChange(self, list_wid):
+        def setJID(jabberID):
+            self.login_wid.set_edit_text(jabberID)
+        def setPassword(password):
+            self.pass_wid.set_edit_text(password)
+
         profile_name = list_wid.getSelectedValue()
         if profile_name:
-            jabberID = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile_name)
-            password = self.host.bridge.getParamA("Password", "Connection", profile_key=profile_name)
-            self.login_wid.set_edit_text(jabberID)
-            self.pass_wid.set_edit_text(password)
+            self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile_name, callback=setJID, errback=self.getParamError)
+            self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile_name, callback=setPassword, errback=self.getParamError)
         
     def onConnectProfile(self, button):
         profile_name = self.list_profile.getSelectedValue()
@@ -110,15 +113,24 @@
             profile = self.host.bridge.getProfileName(profile_name)
             assert(profile)
             #TODO: move this to quick_app
-            old_jid = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile)
-            old_pass = self.host.bridge.getParamA("Password", "Connection", profile_key=profile)
-            new_jid = self.login_wid.get_edit_text()
-            new_pass = self.pass_wid.get_edit_text()
+            self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile,
+                                            callback=lambda old_jid: self.__old_jidReceived(old_jid, profile), errback=self.getParamError)
 
-            if old_jid != new_jid:
-                self.host.bridge.setParam("JabberID", new_jid, "Connection", profile)
-                self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile)
-            if old_pass != new_pass:
-                self.host.bridge.setParam("Password", new_pass, "Connection", profile)
-            self.host.plug_profile(profile)
+    def __old_jidReceived(self, old_jid, profile):
+        self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile,
+                                        callback=lambda old_pass: self.__old_passReceived(old_jid, old_pass, profile), errback=self.getParamError)
+    
+    def __old_passReceived(self, old_jid, old_pass, profile):
+        """Check if we have new jid/pass, save them if it is the case, and plug profile"""
+        new_jid = self.login_wid.get_edit_text()
+        new_pass = self.pass_wid.get_edit_text()
+
+        if old_jid != new_jid:
+            self.host.bridge.setParam("JabberID", new_jid, "Connection", profile)
+            self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile)
+        if old_pass != new_pass:
+            self.host.bridge.setParam("Password", new_pass, "Connection", profile)
+        self.host.plug_profile(profile)
             
+    def getParamError(self):
+        error(_("Can't get profile parameter"))