Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_app.py @ 1060:aa15453ec54d
core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 23 May 2014 09:59:35 +0200 |
parents | 0a9986452bba |
children | 6ec513ad92c2 |
comparison
equal
deleted
inserted
replaced
1059:b2b9c184033f | 1060:aa15453ec54d |
---|---|
47 except BridgeInitError: | 47 except BridgeInitError: |
48 print(_(u"Can't init bridge")) | 48 print(_(u"Can't init bridge")) |
49 sys.exit(1) | 49 sys.exit(1) |
50 self.bridge.register("connected", self.connected) | 50 self.bridge.register("connected", self.connected) |
51 self.bridge.register("disconnected", self.disconnected) | 51 self.bridge.register("disconnected", self.disconnected) |
52 self.bridge.register("connectionError", self.connectionError) | |
53 self.bridge.register("newContact", self.newContact) | 52 self.bridge.register("newContact", self.newContact) |
54 self.bridge.register("newMessage", self._newMessage) | 53 self.bridge.register("newMessage", self._newMessage) |
55 self.bridge.register("newAlert", self.newAlert) | 54 self.bridge.register("newAlert", self.newAlert) |
56 self.bridge.register("presenceUpdate", self.presenceUpdate) | 55 self.bridge.register("presenceUpdate", self.presenceUpdate) |
57 self.bridge.register("subscribe", self.subscribe) | 56 self.bridge.register("subscribe", self.subscribe) |
150 | 149 |
151 def plug_profile_3(self, autoconnect, profile): | 150 def plug_profile_3(self, autoconnect, profile): |
152 self.bridge.asyncGetParamA("Watched", "Misc", profile_key=profile, | 151 self.bridge.asyncGetParamA("Watched", "Misc", profile_key=profile, |
153 callback=lambda watched: self.plug_profile_4(watched, autoconnect, profile), errback=self._getParamError) | 152 callback=lambda watched: self.plug_profile_4(watched, autoconnect, profile), errback=self._getParamError) |
154 | 153 |
154 def asyncConnect(self, profile, callback=None, errback=None): | |
155 if not callback: | |
156 callback = lambda dummy: None | |
157 if not errback: | |
158 def errback(failure): | |
159 log.error(_(u"Can't connect profile [%s]") % failure) | |
160 self.launchAction(C.CHANGE_XMPP_PASSWD_ID, {}, profile_key=profile) | |
161 self.bridge.asyncConnect(profile, callback=callback, errback=errback) | |
162 | |
155 def plug_profile_4(self, watched, autoconnect, profile): | 163 def plug_profile_4(self, watched, autoconnect, profile): |
156 if autoconnect and not self.bridge.isConnected(profile): | 164 if autoconnect and not self.bridge.isConnected(profile): |
157 #Does the user want autoconnection ? | 165 #Does the user want autoconnection ? |
158 self.bridge.asyncConnect(profile, callback=lambda dummy: self.plug_profile_5(watched, autoconnect, profile), errback=lambda ignore: log.error(_('Error during autoconnection'))) | 166 self.asyncConnect(profile, callback=lambda dummy: self.plug_profile_5(watched, autoconnect, profile)) |
159 else: | 167 else: |
160 self.plug_profile_5(watched, autoconnect, profile) | 168 self.plug_profile_5(watched, autoconnect, profile) |
161 | 169 |
162 def plug_profile_5(self, watched, autoconnect, profile): | 170 def plug_profile_5(self, watched, autoconnect, profile): |
163 self.profiles[profile]['watched'] = watched.split() # TODO: put this in a plugin | 171 self.profiles[profile]['watched'] = watched.split() # TODO: put this in a plugin |
226 if not self.check_profile(profile): | 234 if not self.check_profile(profile): |
227 return | 235 return |
228 log.debug(_("Disconnected")) | 236 log.debug(_("Disconnected")) |
229 self.contact_list.clearContacts() | 237 self.contact_list.clearContacts() |
230 self.setStatusOnline(False) | 238 self.setStatusOnline(False) |
231 | |
232 def connectionError(self, error_type, profile): | |
233 """called when something goes wrong with the connection""" | |
234 if not self.check_profile(profile): | |
235 return | |
236 log.debug(_("Connection Error")) | |
237 self.disconnected(profile) | |
238 if error_type == "AUTH_ERROR": | |
239 self.launchAction(C.CHANGE_XMPP_PASSWD_ID, {}, profile_key=profile) | |
240 else: | |
241 log.error(_('FIXME: error_type %s not implemented') % error_type) | |
242 | 239 |
243 def newContact(self, JabberId, attributes, groups, profile): | 240 def newContact(self, JabberId, attributes, groups, profile): |
244 if not self.check_profile(profile): | 241 if not self.check_profile(profile): |
245 return | 242 return |
246 entity = JID(JabberId) | 243 entity = JID(JabberId) |
610 raise NotImplementedError | 607 raise NotImplementedError |
611 | 608 |
612 def actionResult(self, type, id, data): | 609 def actionResult(self, type, id, data): |
613 raise NotImplementedError | 610 raise NotImplementedError |
614 | 611 |
612 def launchAction(self, callback_id, data=None, profile_key="@NONE@"): | |
613 """ Launch a dynamic action | |
614 @param callback_id: id of the action to launch | |
615 @param data: data needed only for certain actions | |
616 @param profile_key: %(doc_profile_key)s | |
617 | |
618 """ | |
619 raise NotImplementedError | |
620 | |
615 def onExit(self): | 621 def onExit(self): |
616 """Must be called when the frontend is terminating""" | 622 """Must be called when the frontend is terminating""" |
617 #TODO: mange multi-profile here | 623 #TODO: mange multi-profile here |
618 try: | 624 try: |
619 if self.bridge.isConnected(self.profile): | 625 if self.bridge.isConnected(self.profile): |