Show total download speed in titlebar (bug 139)

While downloading episodes, show the total download speed
in the title bar in addition to the total progress percentage.

Only update the progress at most once per second, to avoid
updating the GUI too often (progress notifications).

Reported by Will <war59312@gmail.com> in gPodder bug 139
This commit is contained in:
Thomas Perl 2008-08-04 14:17:01 +02:00
parent b06632a967
commit bc44648b84
3 changed files with 23 additions and 6 deletions

View File

@ -89,6 +89,7 @@ class DownloadThread(threading.Thread):
self.cancelled = False
self.start_time = 0.0
self.speed = _('Queued')
self.speed_value = 0
self.progress = 0.0
self.downloader = DownloadURLOpener( self.channel)
self.last_update = 0.0
@ -152,6 +153,7 @@ class DownloadThread(threading.Thread):
speed = count*blockSize
self.speed = '%s/s' % gl.format_filesize(speed)
self.speed_value = speed
if gl.config.limit_rate and speed > gl.config.limit_rate_value:
# calculate the time that should have passed to reach

View File

@ -977,13 +977,15 @@ class gPodder(GladeWidget):
def download_progress_updated( self, count, percentage):
title = [ self.default_title ]
total_speed = gl.format_filesize(services.download_status_manager.total_speed())
if count == 1:
title.append( _('downloading one file'))
elif count > 1:
title.append( _('downloading %d files') % count)
if len(title) == 2:
title[1] = ''.join( [ title[1], ' (%d%%)' % ( percentage, ) ])
title[1] = ''.join( [ title[1], ' (%d%%, %s/s)' % (percentage, total_speed) ])
self.gPodder.set_title( ' - '.join( title))

View File

@ -33,6 +33,7 @@ import gtk
import gobject
import threading
import time
import urllib2
import os
import os.path
@ -198,12 +199,14 @@ cover_downloader = CoverDownloader()
class DownloadStatusManager(ObservableService):
COLUMN_NAMES = { 0: 'episode', 1: 'speed', 2: 'progress', 3: 'url' }
COLUMN_TYPES = ( gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_FLOAT, gobject.TYPE_STRING )
PROGRESS_HOLDDOWN_TIMEOUT = 1
def __init__( self):
self.status_list = {}
self.next_status_id = 0
self.last_progress_status = ( 0, 0 )
self.last_progress_status = (0, 0)
self.last_progress_update = 0
# use to correctly calculate percentage done
self.downloads_done_bytes = 0
@ -250,12 +253,16 @@ class DownloadStatusManager(ObservableService):
self.notify('list-changed')
self.batch_mode_notify_flag = False
def notify_progress( self):
now = ( self.count(), self.average_progress() )
def notify_progress(self, force=False):
now = (self.count(), self.average_progress())
if now != self.last_progress_status:
next_progress_update = self.last_progress_update + self.PROGRESS_HOLDDOWN_TIMEOUT
if force or (now != self.last_progress_status and \
time.time() > next_progress_update):
self.notify( 'progress-changed', *now)
self.last_progress_status = now
self.last_progress_update = time.time()
def s_acquire( self):
if not gl.config.max_downloads_enabled:
@ -336,7 +343,7 @@ class DownloadStatusManager(ObservableService):
self.batch_mode_notify_flag = True
else:
self.notify('list-changed')
self.notify_progress()
self.notify_progress(force=True)
def count( self):
return len(self.status_list)
@ -354,6 +361,12 @@ class DownloadStatusManager(ObservableService):
return 0
return float(done + self.downloads_done_bytes) / float(total + self.downloads_done_bytes) * 100
def total_speed(self):
if not len(self.status_list):
return 0
return sum(status['thread'].speed_value for status in self.status_list.values())
def update_status( self, id, **kwargs):
if not id in self.status_list:
return