diff frontends/src/quick_frontend/quick_app.py @ 1938:011eff37e21d

quick frontend, primitivus: quickContactList refactored to handle several profiles at once
author Goffi <goffi@goffi.org>
date Mon, 18 Apr 2016 18:31:13 +0200
parents 2daf7b4c6756
children e68483c5a999
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Sun Apr 17 18:07:55 2016 +0200
+++ b/frontends/src/quick_frontend/quick_app.py	Mon Apr 18 18:31:13 2016 +0200
@@ -29,6 +29,7 @@
 from sat_frontends.quick_frontend import quick_menus
 from sat_frontends.quick_frontend import quick_blog
 from sat_frontends.quick_frontend import quick_chat, quick_games
+from sat_frontends.quick_frontend import quick_contact_list
 from sat_frontends.quick_frontend.constants import Const as C
 
 import sys
@@ -95,8 +96,7 @@
 
     def _plug_profile_gotCachedValues(self, cached_values):
         # add the contact list and its listener
-        contact_list = self.host.addContactList(self.profile)
-        self.host.contact_lists[self.profile] = contact_list
+        contact_list = self.host.contact_lists.addProfile(self.profile)
 
         for entity, data in cached_values.iteritems():
             for key, value in data.iteritems():
@@ -192,8 +192,7 @@
 
         # remove the contact list and its listener
         host = self._profiles[profile].host
-        host.contact_lists[profile].onDelete()
-        del host.contact_lists[profile]
+        host.contact_lists[profile].unplug()
 
         del self._profiles[profile]
 
@@ -218,7 +217,7 @@
         self.profiles = ProfilesManager()
         self.ready_profiles = set() # profiles which are connected and ready
         self.signals_cache = {} # used to keep signal received between start of plug_profile and when the profile is actualy ready
-        self.contact_lists = {}
+        self.contact_lists = quick_contact_list.QuickContactListHandler(self)
         self.widgets = quick_widgets.QuickWidgetsManager(self)
         if check_options is not None:
             self.options = check_options()
@@ -296,7 +295,8 @@
     @property
     def alerts_count(self):
         """Count the over whole alerts for all contact lists"""
-        return sum([sum(clist._alerts.values()) for clist in self.contact_lists.values()])
+        # FIXME
+        # return sum([sum(clist._alerts.values()) for clist in self.contact_lists.values()])
 
     def registerSignal(self, function_name, handler=None, iface="core", with_profile=True):
         """Register a handler for a signal
@@ -448,14 +448,6 @@
     def clear_profile(self):
         self.profiles.clear()
 
-    def addContactList(self, profile):
-        """Method to subclass to add a contact list widget
-
-        will be called on each profile session build
-        @return: a ContactList widget
-        """
-        return NotImplementedError
-
     def newWidget(self, widget):
         raise NotImplementedError
 
@@ -473,7 +465,7 @@
     def disconnectedHandler(self, profile):
         """called when the connection is closed"""
         log.debug(_("Disconnected"))
-        self.contact_lists[profile].clearContacts()
+        self.contact_lists[profile].disconnect()
         self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile)
 
     def actionNewHandler(self, action_data, id_, security_limit, profile):
@@ -481,8 +473,8 @@
 
     def newContactHandler(self, jid_s, attributes, groups, profile):
         entity = jid.JID(jid_s)
-        _groups = list(groups)
-        self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True)
+        groups = list(groups)
+        self.contact_lists[profile].setContact(entity, groups, attributes, in_roster=True)
 
     def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile):
         from_jid = jid.JID(from_jid_s)
@@ -516,7 +508,7 @@
                 if isinstance(widget, quick_chat.QuickChat) and widget.manageMessage(from_jid, type_):
                     visible = True
                     break
-            if visible:
+            if visible: # FIXME: à virer gof:
                 if self.isHidden():  # the window is hidden
                     self.updateAlertsCounter(extra_inc=1)
             else:
@@ -730,7 +722,7 @@
 
     def contactDeletedHandler(self, jid_s, profile):
         target = jid.JID(jid_s)
-        self.contact_lists[profile].removeContact(target, in_roster=True)
+        self.contact_lists[profile].removeContact(target)
 
     def entityDataUpdatedHandler(self, entity_s, key, value, profile):
         entity = jid.JID(entity_s)