Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_app.py @ 1332:0f92b6a150ff frontends_multi_profiles
quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 22 Feb 2015 21:30:20 +0100 |
parents | 7fa07c7b0761 |
children | f29beedb33b0 |
comparison
equal
deleted
inserted
replaced
1331:7fa07c7b0761 | 1332:0f92b6a150ff |
---|---|
82 log.error("Couldn't get cached values: {}".format(failure)) | 82 log.error("Couldn't get cached values: {}".format(failure)) |
83 self._plug_profile_gotCachedValues({}) | 83 self._plug_profile_gotCachedValues({}) |
84 | 84 |
85 def _plug_profile_gotCachedValues(self, cached_values): | 85 def _plug_profile_gotCachedValues(self, cached_values): |
86 # TODO: watched plugin | 86 # TODO: watched plugin |
87 | |
88 # add the contact list and its listener | |
87 contact_list = self.host.addContactList(self.profile) | 89 contact_list = self.host.addContactList(self.profile) |
90 self.host.contact_lists[self.profile] = contact_list | |
88 | 91 |
89 for entity, data in cached_values.iteritems(): | 92 for entity, data in cached_values.iteritems(): |
90 for key, value in data.iteritems(): | 93 for key, value in data.iteritems(): |
91 self.host.contact_lists[self.profile].setCache(jid.JID(entity), key, value) | 94 contact_list.setCache(jid.JID(entity), key, value) |
92 | 95 |
93 if not self.bridge.isConnected(self.profile): | 96 if not self.bridge.isConnected(self.profile): |
94 self.host.setStatusOnline(False, profile=self.profile) | 97 self.host.setStatusOnline(False, profile=self.profile) |
95 else: | 98 else: |
96 self.host.setStatusOnline(True, profile=self.profile) | 99 self.host.setStatusOnline(True, profile=self.profile) |
176 self._profiles[profile].plug() | 179 self._profiles[profile].plug() |
177 | 180 |
178 def unplug(self, profile): | 181 def unplug(self, profile): |
179 if profile not in self._profiles: | 182 if profile not in self._profiles: |
180 raise ValueError('The profile [{}] is not plugged'.format(profile)) | 183 raise ValueError('The profile [{}] is not plugged'.format(profile)) |
184 | |
185 # remove the contact list and its listener | |
186 host = self._profiles[profile].host | |
187 host.contact_lists[profile].onDelete() | |
188 del host.contact_lists[profile] | |
189 | |
181 del self._profiles[profile] | 190 del self._profiles[profile] |
182 | 191 |
183 def chooseOneProfile(self): | 192 def chooseOneProfile(self): |
184 return self._profiles.keys()[0] | 193 return self._profiles.keys()[0] |
194 | |
185 | 195 |
186 class QuickApp(object): | 196 class QuickApp(object): |
187 """This class contain the main methods needed for the frontend""" | 197 """This class contain the main methods needed for the frontend""" |
188 | 198 |
189 def __init__(self, create_bridge, check_options=None): | 199 def __init__(self, create_bridge, check_options=None): |
389 | 399 |
390 def unplug_profile(self, profile): | 400 def unplug_profile(self, profile): |
391 """Tell the application to not follow anymore the profile""" | 401 """Tell the application to not follow anymore the profile""" |
392 if not profile in self.profiles: | 402 if not profile in self.profiles: |
393 raise ValueError("The profile [{}] is not plugged".format(profile)) | 403 raise ValueError("The profile [{}] is not plugged".format(profile)) |
394 self.profiles.remove(profile) | 404 self.profiles.unplug(profile) |
395 | 405 |
396 def clear_profile(self): | 406 def clear_profile(self): |
397 self.profiles.clear() | 407 self.profiles.clear() |
398 | 408 |
399 def addContactList(self, profile): | 409 def addContactList(self, profile): |
470 | 480 |
471 # #FIXME: must be moved in a plugin | 481 # #FIXME: must be moved in a plugin |
472 # if entity.bare in self.profiles[profile].data.get('watched',[]) and not entity.bare in self.profiles[profile]['onlineContact']: | 482 # if entity.bare in self.profiles[profile].data.get('watched',[]) and not entity.bare in self.profiles[profile]['onlineContact']: |
473 # self.showAlert(_("Watched jid [%s] is connected !") % entity.bare) | 483 # self.showAlert(_("Watched jid [%s] is connected !") % entity.bare) |
474 | 484 |
475 self.contact_lists[profile].updatePresence(entity, show, priority, statuses) | |
476 self.callListeners('presence', profile, entity, show, priority, statuses) | 485 self.callListeners('presence', profile, entity, show, priority, statuses) |
477 | 486 |
478 def roomJoinedHandler(self, room_jid_s, room_nicks, user_nick, profile): | 487 def roomJoinedHandler(self, room_jid_s, room_nicks, user_nick, profile): |
479 """Called when a MUC room is joined""" | 488 """Called when a MUC room is joined""" |
480 log.debug("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s" % {'room_jid': room_jid_s, 'profile': profile, 'users': room_nicks}) | 489 log.debug("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s" % {'room_jid': room_jid_s, 'profile': profile, 'users': room_nicks}) |
688 """ | 697 """ |
689 raise NotImplementedError | 698 raise NotImplementedError |
690 | 699 |
691 def onExit(self): | 700 def onExit(self): |
692 """Must be called when the frontend is terminating""" | 701 """Must be called when the frontend is terminating""" |
702 to_unplug = [] | |
693 for profile in self.profiles: | 703 for profile in self.profiles: |
694 if self.bridge.isConnected(profile): | 704 if self.bridge.isConnected(profile): |
695 if C.bool(self.bridge.getParamA("autodisconnect", "Connection", profile_key=profile)): | 705 if C.bool(self.bridge.getParamA("autodisconnect", "Connection", profile_key=profile)): |
696 #The user wants autodisconnection | 706 #The user wants autodisconnection |
697 self.bridge.disconnect(profile) | 707 self.bridge.disconnect(profile) |
708 to_unplug.append(profile) | |
709 for profile in to_unplug: | |
710 self.unplug_profile(profile) |