changeset 1642:7ec7ce9cdc4c

jp (base): progressStarted signals are cached until progress_id is known, this avoid missing the progression if we have the signal before the id.
author Goffi <goffi@goffi.org>
date Sun, 22 Nov 2015 17:37:19 +0100
parents 44a14f83e64b
children 17f9b911899a
files frontends/src/jp/base.py
diffstat 1 files changed, 31 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/base.py	Sun Nov 22 17:35:32 2015 +0100
+++ b/frontends/src/jp/base.py	Sun Nov 22 17:37:19 2015 +0100
@@ -117,6 +117,7 @@
     @progress_id.setter
     def progress_id(self, value):
         self._progress_id = value
+        self.replayCache('progress_ids_cache')
 
     @property
     def watch_progress(self):
@@ -139,6 +140,22 @@
         except AttributeError:
             return 0
 
+    def replayCache(self, cache_attribute):
+        """Replay cached signals
+
+        @param cache_attribute(str): name of the attribute containing the cache
+            if the attribute doesn't exist, there is no cache and the call is ignored
+            else the cache must be a list of tuples containing the replay callback as first item,
+            then the arguments to use
+        """
+        try:
+            cache = getattr(self, cache_attribute)
+        except AttributeError:
+            pass
+        else:
+            for cache_data in cache:
+                cache_data[0](*cache_data[1:])
+
     def disp(self, msg, verbosity=0, error=False):
         """Print a message to user
 
@@ -477,9 +494,19 @@
     def progressStartedHandler(self, uid, metadata, profile):
         if profile != self.profile:
             return
-        self.onProgressStarted(metadata)
-        if self.host.watch_progress and self.progress_id and uid == self.progress_id:
-            GLib.timeout_add(PROGRESS_DELAY, self.host.progressUpdate)
+        if self.progress_id is None:
+            # the progress started message can be received before the id
+            # so we keep progressStarted signals in cache to replay they
+            # when the progress_id is received
+            cache_data = (self.progressStartedHandler, uid, metadata, profile)
+            try:
+                self.host.progress_ids_cache.append(cache_data)
+            except AttributeError:
+                self.host.progress_ids_cache = [cache_data]
+        else:
+            if self.host.watch_progress and uid == self.progress_id:
+                self.onProgressStarted(metadata)
+                GLib.timeout_add(PROGRESS_DELAY, self.host.progressUpdate)
 
     def progressFinishedHandler(self, uid, metadata, profile):
         if profile != self.profile:
@@ -544,7 +571,7 @@
         else:
             if show_progress:
                 self.host.watch_progress = True
-            # we need to register the following signal even if we don't display the progress bas
+            # we need to register the following signal even if we don't display the progress bar
             self.host.bridge.register("progressStarted", self.progressStartedHandler)
             self.host.bridge.register("progressFinished", self.progressFinishedHandler)
             self.host.bridge.register("progressError", self.progressErrorHandler)