diff 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
line wrap: on
line diff
--- 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)