Automatic clean up of downloads list (bug 724)

Converted the "Clean up" button that would
manually carry out a clean up action into a
toggle button that will (when enabled) remove
all finished/cancelled downloads automatically
after a download session.
This commit is contained in:
Thomas Perl 2009-12-17 14:50:39 +01:00
parent 6ab9856fe9
commit 8953df0dcd
6 changed files with 45 additions and 19 deletions

View file

@ -1058,13 +1058,12 @@
</packing>
</child>
<child>
<object class="GtkButton" id="btnCleanUpDownloads">
<object class="GtkToggleButton" id="btnCleanUpDownloads">
<property name="label" translatable="yes">Clean up</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">imageCleanUpDownloads</property>
<signal name="clicked" handler="on_btnCleanUpDownloads_clicked"/>
</object>
<packing>
<property name="position">7</property>

View file

@ -49,9 +49,8 @@
<property name="label" translatable="yes">Cancel selected</property>
<signal name="activate" handler="on_cancel_button_clicked"/>
</object>
<object class="GtkAction" id="action_cleanup">
<property name="label" translatable="yes">Clean up list</property>
<signal name="activate" handler="on_cleanup_button_clicked"/>
<object class="GtkToggleAction" id="action_auto_cleanup">
<property name="label" translatable="yes">Automatic clean-up</property>
</object>
<object class="GtkAction" id="action_select_all">
<property name="label" translatable="yes">Select all</property>

View file

@ -879,13 +879,12 @@
</packing>
</child>
<child>
<object class="GtkButton" id="btnCleanUpDownloads">
<object class="GtkToggleButton" id="btnCleanUpDownloads">
<property name="label" translatable="yes">Clean up</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">imageCleanUpDownloads</property>
<signal name="clicked" handler="on_btnCleanUpDownloads_clicked"/>
</object>
<packing>
<property name="position">7</property>

View file

@ -94,6 +94,8 @@ gPodderSettings = {
'auto_update_frequency': (int, 20,
("The frequency (in minutes) at which gPodder will update all feeds "
"if 'auto_update_feeds' is enabled.")),
'auto_cleanup_downloads': (bool, True,
('Automatically removed cancelled and finished downloads from the list')),
'episode_list_descriptions': (bool, True,
("Display the episode's description under the episode title in the GUI.")),
'show_toolbar': (bool, True,

View file

@ -36,15 +36,21 @@ class gPodderDownloads(BuilderWidget):
selection.connect('changed', self.on_selection_changed)
appmenu = hildon.AppMenu()
for action in (self.action_pause, \
for action in (self.action_select_all, \
self.action_select_none, \
self.action_pause, \
self.action_resume, \
self.action_cancel, \
self.action_cleanup, \
self.action_select_all, \
self.action_select_none):
self.action_cancel):
button = gtk.Button()
action.connect_proxy(button)
appmenu.append(button)
button = hildon.CheckButton(gtk.HILDON_SIZE_AUTO)
self.action_auto_cleanup.connect_proxy(button)
appmenu.append(button)
self._config.connect_gtk_togglebutton('auto_cleanup_downloads', \
button)
appmenu.show_all()
self.main_window.set_app_menu(appmenu)
@ -80,7 +86,7 @@ class gPodderDownloads(BuilderWidget):
self.on_select_none_button_clicked(button)
def on_cleanup_button_clicked(self, button):
self.on_btnCleanUpDownloads_clicked(button)
self.on_btnCleanUpDownloads_clicked(button, remove_failed=True)
def on_select_all_button_clicked(self, button):
selection = self.treeview.get_selection()

View file

@ -321,7 +321,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
on_treeview_expose_event=self.on_treeview_expose_event, \
on_btnCleanUpDownloads_clicked=self.on_btnCleanUpDownloads_clicked, \
_for_each_task_set_status=self._for_each_task_set_status, \
downloads_list_get_selection=self.downloads_list_get_selection)
downloads_list_get_selection=self.downloads_list_get_selection, \
_config=self.config)
self.treeChannels = self.podcasts_window.treeview
self.treeAvailable = self.episodes_window.treeview
self.treeDownloads = self.downloads_window.treeview
@ -418,6 +419,11 @@ class gPodder(BuilderWidget, dbus.service.Object):
if self.config.auto_update_feeds:
self.restart_auto_update_timer()
# Connect the auto cleanup button to the configuration
if gpodder.ui.desktop or gpodder.ui.diablo:
self.config.connect_gtk_togglebutton('auto_cleanup_downloads', \
self.btnCleanUpDownloads)
# Delete old episodes if the user wishes to
if self.config.auto_remove_old_episodes:
old_episodes = self.get_old_episodes()
@ -818,13 +824,14 @@ class gPodder(BuilderWidget, dbus.service.Object):
gobject.timeout_add(1500, self.update_downloads_list)
self.download_list_update_enabled = True
def on_btnCleanUpDownloads_clicked(self, button):
def on_btnCleanUpDownloads_clicked(self, button=None):
model = self.download_status_model
all_tasks = [(gtk.TreeRowReference(model, row.path), row[0]) for row in model]
changed_episode_urls = []
for row_reference, task in all_tasks:
if task.status in (task.DONE, task.CANCELLED, task.FAILED):
if task.status in (task.DONE, task.CANCELLED) or \
(task.status == task.FAILED and gpodder.ui.fremantle):
model.remove(model.get_iter(row_reference.get_path()))
try:
# We don't "see" this task anymore - remove it;
@ -847,7 +854,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
self.episode_shownotes_window._download_status_changed(None)
# Update the tab title and downloads list
self.update_downloads_list()
self.update_downloads_list(from_cleanup=True)
def on_tool_downloads_toggled(self, toolbutton):
if toolbutton.get_active():
@ -855,7 +862,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
else:
self.wNotebook.set_current_page(0)
def update_downloads_list(self):
def update_downloads_list(self, from_cleanup=False):
try:
model = self.download_status_model
@ -878,6 +885,7 @@ 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)
@ -897,6 +905,7 @@ 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
@ -968,7 +977,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
# Update the tray icon status and progress bar
self.tray_icon.set_status(self.tray_icon.STATUS_DOWNLOAD_IN_PROGRESS, title[1])
self.tray_icon.draw_progress_bar(percentage/100.)
elif self.last_download_count > 0:
elif self.last_download_count > 0 and not from_cleanup:
if self.tray_icon is not None:
# Update the tray icon status
self.tray_icon.set_status()
@ -978,6 +987,15 @@ class gPodder(BuilderWidget, dbus.service.Object):
log('All downloads have finished.', sender=self)
if self.config.cmd_all_downloads_complete:
util.run_external_command(self.config.cmd_all_downloads_complete)
if gpodder.ui.fremantle and failed:
message = '\n'.join(['%s: %s' % (str(task), \
task.error_message) for task in failed_downloads])
self.show_message(message, _('Downloads failed'), important=True)
# Automatically remove finished downloads from the list
if self.config.auto_cleanup_downloads:
self.on_btnCleanUpDownloads_clicked()
self.last_download_count = count
if not gpodder.ui.fremantle:
@ -1017,6 +1035,9 @@ class gPodder(BuilderWidget, dbus.service.Object):
# Force a update of the podcast list model
self.channel_list_changed = True
self.update_podcast_list_model()
elif name == 'auto_cleanup_downloads' and new_value:
# Always cleanup when this option is enabled
self.on_btnCleanUpDownloads_clicked()
def on_treeview_query_tooltip(self, treeview, x, y, keyboard_tooltip, tooltip):
# With get_bin_window, we get the window that contains the rows without