Proper single-time download notifications (bug 1161)
Only show a notification for finished or failed downloads once, both on the Desktop version and on Maemo 5 by adding a special function to DownloadTask to keep track whether or not the notification has already been shown previously.
This commit is contained in:
parent
8f167f89a0
commit
10cad7aad0
|
@ -516,6 +516,14 @@ class DownloadTask(object):
|
|||
it from the UI, so that it can carry out any pending clean-up
|
||||
actions (e.g. removing the temporary file when the task has not
|
||||
finished successfully; i.e. task.status != DownloadTask.DONE).
|
||||
|
||||
The UI can call the method "notify_as_finished()" to determine if
|
||||
this episode still has still to be shown as "finished" download
|
||||
in a notification window. This will return True only the first time
|
||||
it is called when the status is DONE. After returning True once,
|
||||
it will always return False afterwards.
|
||||
|
||||
The same thing works for failed downloads ("notify_as_failed()").
|
||||
"""
|
||||
# Possible states this download task can be in
|
||||
STATUS_MESSAGE = (_('Added'), _('Queued'), _('Downloading'),
|
||||
|
@ -582,6 +590,9 @@ class DownloadTask(object):
|
|||
self.progress = 0.0
|
||||
self.error_message = None
|
||||
|
||||
# Have we already shown this task in a notification?
|
||||
self._notification_shown = False
|
||||
|
||||
# Variables for speed limit and speed calculation
|
||||
self.__start_time = 0
|
||||
self.__start_blocks = 0
|
||||
|
@ -604,6 +615,26 @@ class DownloadTask(object):
|
|||
# files for resuming when the file is queued
|
||||
open(self.tempname, 'w').close()
|
||||
|
||||
def notify_as_finished(self):
|
||||
if self.status == DownloadTask.DONE:
|
||||
if self._notification_shown:
|
||||
return False
|
||||
else:
|
||||
self._notification_shown = True
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def notify_as_failed(self):
|
||||
if self.status == DownloadTask.FAILED:
|
||||
if self._notification_shown:
|
||||
return False
|
||||
else:
|
||||
self._notification_shown = True
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def add_progress_callback(self, callback):
|
||||
self._progress_updated = callback
|
||||
|
||||
|
@ -683,6 +714,7 @@ class DownloadTask(object):
|
|||
|
||||
# We are downloading this file right now
|
||||
self.status = DownloadTask.DOWNLOADING
|
||||
self._notification_shown = False
|
||||
|
||||
try:
|
||||
# Resolve URL and start downloading the episode
|
||||
|
@ -761,7 +793,8 @@ class DownloadTask(object):
|
|||
self.error_message = _('HTTP Error %(code)s: %(message)s') % d
|
||||
except Exception, e:
|
||||
self.status = DownloadTask.FAILED
|
||||
self.error_message = _('Error: %s') % (e.message,)
|
||||
log('Download error: %s', str(e), traceback=True, sender=self)
|
||||
self.error_message = _('Error: %s') % (str(e),)
|
||||
|
||||
if self.status == DownloadTask.DOWNLOADING:
|
||||
# Everything went well - we're done
|
||||
|
|
|
@ -1321,7 +1321,6 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
if model is None:
|
||||
model = ()
|
||||
|
||||
failed_downloads = []
|
||||
for row in model:
|
||||
self.download_status_model.request_update(row.iter)
|
||||
|
||||
|
@ -1345,7 +1344,6 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
downloading += 1
|
||||
total_speed += speed
|
||||
elif status == download.DownloadTask.FAILED:
|
||||
failed_downloads.append(task)
|
||||
failed += 1
|
||||
elif status == download.DownloadTask.DONE:
|
||||
finished += 1
|
||||
|
@ -1424,10 +1422,11 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
if self.config.cmd_all_downloads_complete:
|
||||
util.run_external_command(self.config.cmd_all_downloads_complete)
|
||||
|
||||
if gpodder.ui.fremantle and failed:
|
||||
if gpodder.ui.fremantle:
|
||||
message = '\n'.join(['%s: %s' % (str(task), \
|
||||
task.error_message) for task in failed_downloads])
|
||||
self.show_message(message, _('Downloads failed'), important=True)
|
||||
task.error_message) for task in self.download_tasks_seen if task.notify_as_failed()])
|
||||
if message:
|
||||
self.show_message(message, _('Downloads failed'), important=True)
|
||||
|
||||
# Remove finished episodes
|
||||
if self.config.auto_cleanup_downloads and can_call_cleanup:
|
||||
|
@ -1645,9 +1644,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
return selected_tasks, can_queue, can_cancel, can_pause, can_remove, can_force
|
||||
|
||||
def downloads_finished(self, download_tasks_seen):
|
||||
# FIXME: Filter all tasks that have already been reported
|
||||
finished_downloads = [str(task) for task in download_tasks_seen if task.status == task.DONE]
|
||||
failed_downloads = [str(task)+' ('+task.error_message+')' for task in download_tasks_seen if task.status == task.FAILED]
|
||||
finished_downloads = [str(task) for task in download_tasks_seen if task.notify_as_finished()]
|
||||
failed_downloads = [str(task)+' ('+task.error_message+')' for task in download_tasks_seen if task.notify_as_failed()]
|
||||
|
||||
if finished_downloads and failed_downloads:
|
||||
message = self.format_episode_list(finished_downloads, 5)
|
||||
|
|
Loading…
Reference in New Issue