1
# Miro - an RSS based video player application
2
# Copyright (C) 2005-2010 Participatory Culture Foundation
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# In addition, as a special exception, the copyright holders give
19
# permission to link the code of portions of this program with the OpenSSL
22
# You must obey the GNU General Public License in all respects for all of
23
# the code used other than OpenSSL. If you modify file(s) with this
24
# exception, you may extend this exception to your version of the file(s),
25
# but you are not obligated to do so. If you do not wish to do so, delete
26
# this exception statement from your version. If you delete this exception
27
# statement from all source files in the program, then also delete it here.
29
"""Controller for Downloads tab.
32
from miro.gtcache import gettext as _
34
from miro.frontends.widgets import itemlistcontroller
35
from miro.frontends.widgets.itemlistwidgets import (
36
ItemView, HideableSection, ItemContainerWidget, DownloadToolbar,
38
from miro.frontends.widgets import itemcontextmenu
39
from miro.frontends.widgets import imagepool
40
from miro.frontends.widgets import itemlist
41
from miro.frontends.widgets import prefpanel
43
from miro import messages
44
from miro import downloader
45
from miro.plat import resources
46
from miro.plat.frontends.widgets import widgetset
48
class DownloadsController(itemlistcontroller.ItemListController):
50
itemlistcontroller.ItemListController.__init__(self, 'downloads', None)
51
for item_list in self.item_list_group.item_lists:
52
item_list.resort_on_update = True
54
def build_widget(self):
55
self._make_item_views()
57
self.titlebar = self.make_titlebar()
58
self.widget.titlebar_vbox.pack_start(self.titlebar)
60
self.toolbar = DownloadToolbar()
61
self.toolbar.connect("pause-all", self._on_pause_all)
62
self.toolbar.connect("resume-all", self._on_resume_all)
63
self.toolbar.connect("cancel-all", self._on_cancel_all)
64
self.toolbar.connect("settings", self._on_settings)
66
self._update_free_space()
68
self.widget.titlebar_vbox.pack_start(self.toolbar)
70
vbox = widgetset.VBox()
71
vbox.pack_start(self.indydownloads_section)
72
vbox.pack_start(self.downloads_section)
73
vbox.pack_start(self.seeding_section)
75
background = widgetset.SolidBackground((1, 1, 1))
78
scroller = widgetset.Scroller(False, True)
79
scroller.add(background)
81
self.widget.normal_view_vbox.pack_start(scroller, expand=True)
83
def make_titlebar(self):
84
image_path = resources.path("images/icon-downloading_large.png")
85
icon = imagepool.get(image_path)
86
titlebar = ItemListTitlebar(_("Downloads"), icon)
87
titlebar.connect('search-changed', self._on_search_changed)
90
def make_context_menu_handler(self):
91
return itemcontextmenu.ItemContextMenuHandler()
93
def _make_item_views(self):
94
self.indydownloads_view = ItemView(
95
itemlist.IndividualDownloadItemList())
96
self.indydownloads_section = HideableSection(
97
_("Single and external downloads"), self.indydownloads_view)
99
self.downloads_view = ItemView(itemlist.ChannelDownloadItemList())
100
self.downloads_section = HideableSection(
101
_("Feed downloads"), self.downloads_view)
103
self.seeding_view = ItemView(itemlist.SeedingItemList())
104
self.seeding_section = HideableSection(_("Seeding"), self.seeding_view)
106
def normal_item_views(self):
107
return [self.indydownloads_view, self.downloads_view, self.seeding_view]
109
def default_item_view(self):
110
return self.downloads_view
112
def _on_search_changed(self, widget, search_text):
113
self.set_search(search_text)
115
def _update_free_space(self):
116
self.toolbar.update_free_space()
118
def _on_pause_all(self, widget):
119
messages.PauseAllDownloads().send_to_backend()
121
def _on_resume_all(self, widget):
122
messages.ResumeAllDownloads().send_to_backend()
124
def _on_cancel_all(self, widget):
125
messages.CancelAllDownloads().send_to_backend()
127
def _on_settings(self, widget):
128
prefpanel.show_window("downloads")
130
def _expand_lists_initially(self):
131
self.indydownloads_section.show()
132
self.downloads_section.show()
134
if len(self.indydownloads_view.item_list.get_items()) > 0:
135
self.indydownloads_section.show()
137
self.indydownloads_section.hide()
139
if len(self.downloads_view.item_list.get_items()) > 0:
140
self.downloads_section.show()
142
self.downloads_section.hide()
144
if len(self.seeding_view.item_list.get_items()) > 0:
145
self.seeding_section.show()
147
self.seeding_section.hide()
149
self.indydownloads_section.expand()
150
self.downloads_section.expand()
151
self.seeding_section.expand()
153
def on_initial_list(self):
154
self._expand_lists_initially()
156
def on_items_changed(self):
157
self.toolbar.update_rates(
158
downloader.total_down_rate, downloader.total_up_rate)
160
if len(self.indydownloads_view.item_list.get_items()) > 0:
161
self.indydownloads_section.show()
163
self.indydownloads_section.hide()
165
if len(self.downloads_view.item_list.get_items()) > 0:
166
self.downloads_section.show()
168
self.downloads_section.hide()
170
if len(self.seeding_view.item_list.get_items()) > 0:
171
self.seeding_section.show()
173
self.seeding_section.hide()