diff frontends/src/quick_frontend/quick_contact_list.py @ 1939:e68483c5a999

quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
author Goffi <goffi@goffi.org>
date Mon, 18 Apr 2016 18:33:55 +0200
parents 011eff37e21d
children ccfe45302a5c
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_contact_list.py	Mon Apr 18 18:31:13 2016 +0200
+++ b/frontends/src/quick_frontend/quick_contact_list.py	Mon Apr 18 18:33:55 2016 +0200
@@ -645,6 +645,7 @@
         handler = self
         self._clist = {} # key: profile, value: ProfileContactList
         self._widgets = set()
+        self._update_locked = False # se to True to ignore updates
 
     def __getitem__(self, profile):
         """Return ProfileContactList instance for the requested profile"""
@@ -857,9 +858,25 @@
         for contact_list in self._clist.itervalues():
             contact_list.select(entity)
 
+    def lockUpdate(self, locked=True, do_update=True):
+        """Forbid contact list updates
+
+        Used mainly while profiles are plugged, as many updates can occurs, causing
+        an impact on performances
+        @param locked(bool): updates are forbidden if True
+        @param do_update(bool): if True, a full update is done after unlocking
+            if set to False, widget state can be inconsistent, be sure to know
+            what youa re doing!
+        """
+        log.debug(u"Contact lists updates are now {}".format(u"LOCKED" if locked else u"UNLOCKED"))
+        self._update_locked = locked
+        if not locked and do_update:
+            self.update()
+
     def update(self, entities=None, type_=None, profile=None):
-        for widget in self._widgets:
-            widget.update(entities, type_, profile)
+        if not self._update_locked:
+            for widget in self._widgets:
+                widget.update(entities, type_, profile)
 
 
 class QuickContactList(QuickWidget):