Mercurial > libervia-backend
changeset 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 |
files | frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_app.py frontends/src/quick_frontend/quick_contact_list.py |
diffstat | 3 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Sun Feb 22 20:39:33 2015 +0100 +++ b/frontends/src/primitivus/primitivus Sun Feb 22 21:30:20 2015 +0100 @@ -464,7 +464,6 @@ def addContactList(self, profile): contact_list = ContactList(self, on_click=self.contactSelected, on_change=lambda w: self.redraw(), profile=profile) self.contact_lists_pile.contents.append((contact_list, ('weight', 1))) - self.contact_lists[profile] = contact_list return contact_list def plugging_profiles(self):
--- a/frontends/src/quick_frontend/quick_app.py Sun Feb 22 20:39:33 2015 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Sun Feb 22 21:30:20 2015 +0100 @@ -84,11 +84,14 @@ def _plug_profile_gotCachedValues(self, cached_values): # TODO: watched plugin + + # add the contact list and its listener contact_list = self.host.addContactList(self.profile) + self.host.contact_lists[self.profile] = contact_list for entity, data in cached_values.iteritems(): for key, value in data.iteritems(): - self.host.contact_lists[self.profile].setCache(jid.JID(entity), key, value) + contact_list.setCache(jid.JID(entity), key, value) if not self.bridge.isConnected(self.profile): self.host.setStatusOnline(False, profile=self.profile) @@ -178,11 +181,18 @@ def unplug(self, profile): if profile not in self._profiles: raise ValueError('The profile [{}] is not plugged'.format(profile)) + + # remove the contact list and its listener + host = self._profiles[profile].host + host.contact_lists[profile].onDelete() + del host.contact_lists[profile] + del self._profiles[profile] def chooseOneProfile(self): return self._profiles.keys()[0] + class QuickApp(object): """This class contain the main methods needed for the frontend""" @@ -391,7 +401,7 @@ """Tell the application to not follow anymore the profile""" if not profile in self.profiles: raise ValueError("The profile [{}] is not plugged".format(profile)) - self.profiles.remove(profile) + self.profiles.unplug(profile) def clear_profile(self): self.profiles.clear() @@ -472,7 +482,6 @@ # if entity.bare in self.profiles[profile].data.get('watched',[]) and not entity.bare in self.profiles[profile]['onlineContact']: # self.showAlert(_("Watched jid [%s] is connected !") % entity.bare) - self.contact_lists[profile].updatePresence(entity, show, priority, statuses) self.callListeners('presence', profile, entity, show, priority, statuses) def roomJoinedHandler(self, room_jid_s, room_nicks, user_nick, profile): @@ -690,8 +699,12 @@ def onExit(self): """Must be called when the frontend is terminating""" + to_unplug = [] for profile in self.profiles: if self.bridge.isConnected(profile): if C.bool(self.bridge.getParamA("autodisconnect", "Connection", profile_key=profile)): #The user wants autodisconnection self.bridge.disconnect(profile) + to_unplug.append(profile) + for profile in to_unplug: + self.unplug_profile(profile)
--- a/frontends/src/quick_frontend/quick_contact_list.py Sun Feb 22 20:39:33 2015 +0100 +++ b/frontends/src/quick_frontend/quick_contact_list.py Sun Feb 22 21:30:20 2015 +0100 @@ -71,6 +71,10 @@ self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=profile, callback=self.showEmptyGroups) self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=profile, callback=self.showOfflineContacts) + # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) + self.presenceListener = self.updatePresence + self.host.addListener('presence', self.presenceListener, [profile]) + def __contains__(self, entity): """Check if entity is in contact list @@ -418,3 +422,7 @@ return self.show_resources = show self.update() + + def onDelete(self): + QuickWidget.onDelete(self) + self.host.removeListener('presence', self.presenceListener)