1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2009 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # gpodder.gtkui.download -- Download management in GUIs (2009-08-24)
23 # Based on code from gpodder.services (thp, 2007-08-24)
27 from gpodder
.liblogger
import log
29 from gpodder
import util
30 from gpodder
import download
40 class DownloadStatusModel(gtk
.ListStore
):
41 # Symbolic names for our columns, so we know what we're up to
42 C_TASK
, C_NAME
, C_URL
, C_PROGRESS
, C_PROGRESS_TEXT
, C_ICON_NAME
= range(6)
44 SEARCH_COLUMNS
= (C_NAME
, C_URL
)
47 gtk
.ListStore
.__init
__(self
, object, str, str, int, str, str)
49 # Set up stock icon IDs for tasks
50 self
._status
_ids
= collections
.defaultdict(lambda: None)
51 self
._status
_ids
[download
.DownloadTask
.DOWNLOADING
] = gtk
.STOCK_GO_DOWN
52 self
._status
_ids
[download
.DownloadTask
.DONE
] = gtk
.STOCK_APPLY
53 self
._status
_ids
[download
.DownloadTask
.FAILED
] = gtk
.STOCK_STOP
54 self
._status
_ids
[download
.DownloadTask
.CANCELLED
] = gtk
.STOCK_CANCEL
55 self
._status
_ids
[download
.DownloadTask
.PAUSED
] = gtk
.STOCK_MEDIA_PAUSE
57 def request_update(self
, iter, task
=None):
59 # Ongoing update request from UI - get task from model
60 task
= self
.get_value(iter, self
.C_TASK
)
62 # Initial update request - update non-changing fields
67 if task
.status
== task
.FAILED
:
68 status_message
= '%s: %s' % (\
69 task
.STATUS_MESSAGE
[task
.status
], \
71 elif task
.status
== task
.DOWNLOADING
:
72 status_message
= '%s (%s, %s/s)' % (\
73 task
.STATUS_MESSAGE
[task
.status
], \
74 util
.format_filesize(task
.total_size
), \
75 util
.format_filesize(task
.speed
))
77 status_message
= '%s (%s)' % (\
78 task
.STATUS_MESSAGE
[task
.status
], \
79 util
.format_filesize(task
.total_size
))
82 self
.C_NAME
, '%s\n<small>%s - %s</small>' % (\
85 task
.markup_podcast_name
),
86 self
.C_PROGRESS
, 100.*task
.progress
,
87 self
.C_PROGRESS_TEXT
, '%.0f%%' % (task
.progress
*100.,),
88 self
.C_ICON_NAME
, self
._status
_ids
[task
.status
])
90 def __add_new_task(self
, task
):
92 self
.request_update(iter, task
)
94 def register_task(self
, task
):
95 util
.idle_add(self
.__add
_new
_task
, task
)
97 def tell_all_tasks_to_quit(self
):
99 task
= row
[DownloadStatusModel
.C_TASK
]
101 # Pause currently-running (and queued) downloads
102 if task
.status
in (task
.QUEUED
, task
.DOWNLOADING
):
103 task
.status
= task
.PAUSED
105 # Delete cancelled and failed downloads
106 if task
.status
in (task
.CANCELLED
, task
.FAILED
):
107 task
.removed_from_list()
109 def are_downloads_in_progress(self
):
111 Returns True if there are any downloads in the
112 QUEUED or DOWNLOADING status, False otherwise.
115 task
= row
[DownloadStatusModel
.C_TASK
]
116 if task
is not None and \
117 task
.status
in (task
.DOWNLOADING
, \
123 def cancel_by_url(self
, url
):
125 task
= row
[DownloadStatusModel
.C_TASK
]
126 if task
is not None and task
.url
== url
and \
127 task
.status
in (task
.DOWNLOADING
, \
129 task
.status
= task
.CANCELLED