jp (base): progressStarted signals are cached until progress_id is known, this avoid missing the progression if we have the signal before the id.

This commit is contained in:
Goffi 2015-11-22 17:37:19 +01:00
commit 11d7dfa8fe

View file

@ -117,6 +117,7 @@ class Jp(object):
@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 @@ class Jp(object):
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 @@ class CommandBase(object):
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 @@ class CommandBase(object):
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)