Пример #1
0
    def build_widget(self):
        self._make_item_views()

        self.titlebar = self.make_titlebar()
        self.widget.titlebar_vbox.pack_start(self.titlebar)

        self.toolbar = DownloadToolbar()
        self.toolbar.connect("pause-all", self._on_pause_all)
        self.toolbar.connect("resume-all", self._on_resume_all)
        self.toolbar.connect("cancel-all", self._on_cancel_all)
        self.toolbar.connect("settings", self._on_settings)

        self.widget.titlebar_vbox.pack_start(self.toolbar)

        vbox = widgetset.VBox()
        vbox.pack_start(self.indydownloads_section)
        vbox.pack_start(self.downloads_section)
        vbox.pack_start(self.seeding_section)

        background = widgetset.SolidBackground((1, 1, 1))
        background.add(vbox)

        scroller = widgetset.Scroller(False, True)
        scroller.add(background)

        self.widget.normal_view_vbox.pack_start(scroller, expand=True)

        self.status_toolbar = DownloadStatusToolbar()
        self.widget.statusbar_vbox.pack_start(self.status_toolbar)

        self._update_free_space()
Пример #2
0
class DownloadsController(itemlistcontroller.ItemListController):
    def __init__(self):
        itemlistcontroller.ItemListController.__init__(self, 'downloading', None)
        for item_list in self.item_list_group.item_lists:
            item_list.resort_on_update = True

    def build_widget(self):
        self._make_item_views()

        self.titlebar = self.make_titlebar()
        self.widget.titlebar_vbox.pack_start(self.titlebar)

        self.toolbar = DownloadToolbar()
        self.toolbar.connect("pause-all", self._on_pause_all)
        self.toolbar.connect("resume-all", self._on_resume_all)
        self.toolbar.connect("cancel-all", self._on_cancel_all)
        self.toolbar.connect("settings", self._on_settings)

        self.widget.titlebar_vbox.pack_start(self.toolbar)

        vbox = widgetset.VBox()
        vbox.pack_start(self.indydownloads_section)
        vbox.pack_start(self.downloads_section)
        vbox.pack_start(self.seeding_section)

        background = widgetset.SolidBackground((1, 1, 1))
        background.add(vbox)

        scroller = widgetset.Scroller(False, True)
        scroller.add(background)

        self.widget.normal_view_vbox.pack_start(scroller, expand=True)

        self.status_toolbar = DownloadStatusToolbar()
        self.widget.statusbar_vbox.pack_start(self.status_toolbar)

        self._update_free_space()

    def make_titlebar(self):
        image_path = resources.path("images/icon-downloading_large.png")
        icon = imagepool.get(image_path)
        titlebar = ItemListTitlebar(_("Downloads"), icon)
        titlebar.connect('search-changed', self._on_search_changed)
        return titlebar

    def make_context_menu_handler(self):
        return itemcontextmenu.ItemContextMenuHandler()

    def _make_item_views(self):
        self.indydownloads_view = ItemView(
            itemlist.IndividualDownloadItemList())
        self.indydownloads_section = HideableSection(
            _("Single and external downloads"), self.indydownloads_view)

        self.downloads_view = ItemView(itemlist.ChannelDownloadItemList())
        self.downloads_section = HideableSection(
            _("Feed downloads"), self.downloads_view)

        self.seeding_view = ItemView(itemlist.SeedingItemList())
        self.seeding_section = HideableSection(_("Seeding"), self.seeding_view)

    def normal_item_views(self):
        return [self.indydownloads_view, self.downloads_view, self.seeding_view]

    def default_item_view(self):
        return self.downloads_view

    def _on_search_changed(self, widget, search_text):
        self.set_search(search_text)

    def _update_free_space(self):
        self.status_toolbar.update_free_space()

    def _on_pause_all(self, widget):
        messages.PauseAllDownloads().send_to_backend()

    def _on_resume_all(self, widget):
        messages.ResumeAllDownloads().send_to_backend()

    def _on_cancel_all(self, widget):
        messages.CancelAllDownloads().send_to_backend()

    def _on_settings(self, widget):
        prefpanel.show_window("downloads")

    def _expand_lists_initially(self):
        self.indydownloads_section.show()
        self.downloads_section.show()

        if len(self.indydownloads_view.item_list.get_items()) > 0:
            self.indydownloads_section.show()
        else:
            self.indydownloads_section.hide()

        if len(self.downloads_view.item_list.get_items()) > 0:
            self.downloads_section.show()
        else:
            self.downloads_section.hide()

        if len(self.seeding_view.item_list.get_items()) > 0:
            self.seeding_section.show()
        else:
            self.seeding_section.hide()

        self.indydownloads_section.expand()
        self.downloads_section.expand()
        self.seeding_section.expand()

    def on_initial_list(self):
        self._expand_lists_initially()

    def on_items_changed(self):
        self.status_toolbar.update_rates(
            downloader.total_down_rate, downloader.total_up_rate)

        if len(self.indydownloads_view.item_list.get_items()) > 0:
            self.indydownloads_section.show()
        else:
            self.indydownloads_section.hide()

        if len(self.downloads_view.item_list.get_items()) > 0:
            self.downloads_section.show()
        else:
            self.downloads_section.hide()

        if len(self.seeding_view.item_list.get_items()) > 0:
            self.seeding_section.show()
        else:
            self.seeding_section.hide()