quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
This commit is contained in:
parent
8c46a23869
commit
b836fef4dd
3 changed files with 24 additions and 4 deletions
|
|
@ -464,7 +464,6 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
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):
|
||||
|
|
|
|||
|
|
@ -84,11 +84,14 @@ class ProfileManager(object):
|
|||
|
||||
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 @@ class ProfilesManager(object):
|
|||
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 @@ class QuickApp(object):
|
|||
"""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 @@ class QuickApp(object):
|
|||
# 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 @@ class QuickApp(object):
|
|||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -71,6 +71,10 @@ class QuickContactList(QuickWidget):
|
|||
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 @@ class QuickContactList(QuickWidget):
|
|||
return
|
||||
self.show_resources = show
|
||||
self.update()
|
||||
|
||||
def onDelete(self):
|
||||
QuickWidget.onDelete(self)
|
||||
self.host.removeListener('presence', self.presenceListener)
|
||||
|
|
|
|||
Loading…
Reference in a new issue