From f1089aa515b189f16abfb7db160cda0a15e7e911 Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 1 Nov 2011 22:52:36 +0100 Subject: [PATCH] Quick frontend: use of asyncGetParamA when pluging profile --- frontends/src/quick_frontend/quick_app.py | 32 ++++++++++++++++------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/frontends/src/quick_frontend/quick_app.py b/frontends/src/quick_frontend/quick_app.py index c45a3695..fa325aff 100644 --- a/frontends/src/quick_frontend/quick_app.py +++ b/frontends/src/quick_frontend/quick_app.py @@ -111,6 +111,9 @@ class QuickApp(): 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 @@ class QuickApp(): 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 @@ class QuickApp(): 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 @@ class QuickApp(): """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