changeset 414:f6f94e21c642

Quick frontend: use of asyncGetParamA when pluging profile
author Goffi <goffi@goffi.org>
date Tue, 01 Nov 2011 22:52:36 +0100
parents dd4caab17008
children 3348331e0f09
files frontends/src/quick_frontend/quick_app.py
diffstat 1 files changed, 23 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Tue Nov 01 20:39:22 2011 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Tue Nov 01 22:52:36 2011 +0100
@@ -111,6 +111,9 @@
             self.options.profile = self.options.profile.decode('utf-8')
         return args
 
+    def _getParamError(self):
+        error(_("Can't get profile parameter"))
+    
     def plug_profile(self, profile_key='@DEFAULT@'):
         """Tell application which profile must be used"""
         if self.single_profile and self.profiles:
@@ -128,9 +131,20 @@
             self.profile = profile
         
         ###now we get the essential params###
-        self.profiles[profile]['whoami']=JID(self.bridge.getParamA("JabberID","Connection", profile_key=profile))
-        autoconnect = self.bridge.getParamA("autoconnect","Connection", profile_key=profile) == "true"
-        self.profiles[profile]['watched']=self.bridge.getParamA("Watched", "Misc", profile_key=profile).split() #TODO: put this in a plugin
+        self.bridge.asyncGetParamA("JabberID","Connection", profile_key=profile,
+                                   callback=lambda _jid: self.plug_profile_2(_jid, profile), errback=self._getParamError)
+        
+    def plug_profile_2(self, _jid, profile):
+        self.profiles[profile]['whoami'] = JID(_jid)
+        self.bridge.asyncGetParamA("autoconnect","Connection", profile_key=profile,
+                                   callback=lambda value: self.plug_profile_3(value=="true", profile), errback=self._getParamError)
+
+    def plug_profile_3(self, autoconnect, profile):
+        self.bridge.asyncGetParamA("Watched", "Misc", profile_key=profile,
+                                   callback=lambda watched: self.plug_profile_4(watched, autoconnect, profile), errback=self._getParamError)
+
+    def plug_profile_4(self, watched, autoconnect, profile):
+        self.profiles[profile]['watched'] = watched.split() #TODO: put this in a plugin
 
         ## misc ##
         self.profiles[profile]['onlineContact'] = set()  #FIXME: temporary
@@ -166,9 +180,9 @@
             for subject_args in self.bridge.getRoomsSubjectss(profile):
                 self.roomNewSubject(*subject_args, profile=profile)
         
-        if autoconnect and not self.bridge.isConnected(profile_key):
+        if autoconnect and not self.bridge.isConnected(profile):
             #Does the user want autoconnection ?
-            self.bridge.connect(profile_key)
+            self.bridge.connect(profile)
         
 
     def unplug_profile(self, profile):
@@ -509,9 +523,9 @@
         """Must be called when the frontend is terminating"""
         #TODO: mange multi-profile here
         try:
-            autodisconnect = self.bridge.getParamA("autodisconnect","Connection", profile_key=self.profile) == "true"
-            if autodisconnect and self.bridge.isConnected(self.profile):
-                #Does the user want autodisconnection ?
-                self.bridge.disconnect(self.profile)
+            if self.bridge.isConnected(self.profile):
+                if self.bridge.getParamA("autodisconnect","Connection", profile_key=self.profile) == "true":
+                    #The user wants autodisconnection
+                    self.bridge.disconnect(self.profile)
         except:
             pass