~ubuntu-branches/ubuntu/natty/miro/natty

« back to all changes in this revision

Viewing changes to lib/frontends/widgets/downloadscontroller.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-01-22 02:46:33 UTC
  • mfrom: (1.4.10 upstream) (1.7.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110122024633-kjme8u93y2il5nmf
Tags: 3.5.1-1ubuntu1
* Merge from debian.  Remaining ubuntu changes:
  - Use python 2.7 instead of python 2.6
  - Relax dependency on python-dbus to >= 0.83.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Miro - an RSS based video player application
 
2
# Copyright (C) 2005-2010 Participatory Culture Foundation
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
 
17
#
 
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
 
20
# library.
 
21
#
 
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.
 
28
 
 
29
"""Controller for Downloads tab.
 
30
"""
 
31
 
 
32
from miro.gtcache import gettext as _
 
33
 
 
34
from miro.frontends.widgets import itemlistcontroller
 
35
from miro.frontends.widgets.itemlistwidgets import (
 
36
    ItemView, HideableSection, ItemContainerWidget, DownloadToolbar,
 
37
    ItemListTitlebar)
 
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
 
42
 
 
43
from miro import messages
 
44
from miro import downloader
 
45
from miro.plat import resources
 
46
from miro.plat.frontends.widgets import widgetset
 
47
 
 
48
class DownloadsController(itemlistcontroller.ItemListController):
 
49
    def __init__(self):
 
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
 
53
 
 
54
    def build_widget(self):
 
55
        self._make_item_views()
 
56
 
 
57
        self.titlebar = self.make_titlebar()
 
58
        self.widget.titlebar_vbox.pack_start(self.titlebar)
 
59
 
 
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)
 
65
 
 
66
        self._update_free_space()
 
67
 
 
68
        self.widget.titlebar_vbox.pack_start(self.toolbar)
 
69
 
 
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)
 
74
 
 
75
        background = widgetset.SolidBackground((1, 1, 1))
 
76
        background.add(vbox)
 
77
 
 
78
        scroller = widgetset.Scroller(False, True)
 
79
        scroller.add(background)
 
80
 
 
81
        self.widget.normal_view_vbox.pack_start(scroller, expand=True)
 
82
 
 
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)
 
88
        return titlebar
 
89
 
 
90
    def make_context_menu_handler(self):
 
91
        return itemcontextmenu.ItemContextMenuHandler()
 
92
 
 
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)
 
98
 
 
99
        self.downloads_view = ItemView(itemlist.ChannelDownloadItemList())
 
100
        self.downloads_section = HideableSection(
 
101
            _("Feed downloads"), self.downloads_view)
 
102
 
 
103
        self.seeding_view = ItemView(itemlist.SeedingItemList())
 
104
        self.seeding_section = HideableSection(_("Seeding"), self.seeding_view)
 
105
 
 
106
    def normal_item_views(self):
 
107
        return [self.indydownloads_view, self.downloads_view, self.seeding_view]
 
108
 
 
109
    def default_item_view(self):
 
110
        return self.downloads_view
 
111
 
 
112
    def _on_search_changed(self, widget, search_text):
 
113
        self.set_search(search_text)
 
114
 
 
115
    def _update_free_space(self):
 
116
        self.toolbar.update_free_space()
 
117
 
 
118
    def _on_pause_all(self, widget):
 
119
        messages.PauseAllDownloads().send_to_backend()
 
120
 
 
121
    def _on_resume_all(self, widget):
 
122
        messages.ResumeAllDownloads().send_to_backend()
 
123
 
 
124
    def _on_cancel_all(self, widget):
 
125
        messages.CancelAllDownloads().send_to_backend()
 
126
 
 
127
    def _on_settings(self, widget):
 
128
        prefpanel.show_window("downloads")
 
129
 
 
130
    def _expand_lists_initially(self):
 
131
        self.indydownloads_section.show()
 
132
        self.downloads_section.show()
 
133
 
 
134
        if len(self.indydownloads_view.item_list.get_items()) > 0:
 
135
            self.indydownloads_section.show()
 
136
        else:
 
137
            self.indydownloads_section.hide()
 
138
 
 
139
        if len(self.downloads_view.item_list.get_items()) > 0:
 
140
            self.downloads_section.show()
 
141
        else:
 
142
            self.downloads_section.hide()
 
143
 
 
144
        if len(self.seeding_view.item_list.get_items()) > 0:
 
145
            self.seeding_section.show()
 
146
        else:
 
147
            self.seeding_section.hide()
 
148
 
 
149
        self.indydownloads_section.expand()
 
150
        self.downloads_section.expand()
 
151
        self.seeding_section.expand()
 
152
 
 
153
    def on_initial_list(self):
 
154
        self._expand_lists_initially()
 
155
 
 
156
    def on_items_changed(self):
 
157
        self.toolbar.update_rates(
 
158
            downloader.total_down_rate, downloader.total_up_rate)
 
159
 
 
160
        if len(self.indydownloads_view.item_list.get_items()) > 0:
 
161
            self.indydownloads_section.show()
 
162
        else:
 
163
            self.indydownloads_section.hide()
 
164
 
 
165
        if len(self.downloads_view.item_list.get_items()) > 0:
 
166
            self.downloads_section.show()
 
167
        else:
 
168
            self.downloads_section.hide()
 
169
 
 
170
        if len(self.seeding_view.item_list.get_items()) > 0:
 
171
            self.seeding_section.show()
 
172
        else:
 
173
            self.seeding_section.hide()