Exemple #1
0
    def on_received_downloads(self, downloads):
        if not downloads:
            return  # This might happen when closing Tribler

        bytes_max = self.window().tribler_settings["credit_mining"]["max_disk_space"]
        bytes_used = 0
        total_up = total_down = 0
        for download in downloads["downloads"]:
            if download["credit_mining"] and \
                    download["status"] in ("DLSTATUS_DOWNLOADING", "DLSTATUS_SEEDING",
                                           "DLSTATUS_STOPPED", "DLSTATUS_STOPPED_ON_ERROR"):
                bytes_used += download["progress"] * download["size"]
                total_up += download["total_up"]
                total_down += download["total_down"]

        self.window().token_mining_upload_amount_label.setText(format_size(total_up))
        self.window().token_mining_download_amount_label.setText(format_size(total_down))
        self.window().token_mining_disk_usage_label.setText("%s / %s" % (format_size(float(bytes_used)),
                                                                         format_size(float(bytes_max))))

        self.push_data_to_plot(total_up, total_down)
        self.trust_plot.plot_data = self.plot_data
        self.trust_plot.compute_initial_figure()

        self.schedule_downloads_timer()

        # Matplotlib is leaking memory on re-plotting. Refer: https://github.com/matplotlib/matplotlib/issues/8528
        # Note that gc is called every 10 minutes.
        if self.gc_timer == GC_TIMEOUT:
            gc.collect()
            self.gc_timer = 0
        else:
            self.gc_timer += 1
Exemple #2
0
    def on_tribler_statistics(self, data):
        if not data:
            return
        data = data["tribler_statistics"]
        self.window().general_tree_widget.clear()
        self.create_and_add_widget_item("Tribler version",
                                        self.tribler_version,
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Number of channels",
                                        data["num_channels"],
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Database size",
                                        format_size(data["db_size"]),
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Number of known torrents",
                                        data["num_torrents"],
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("", "",
                                        self.window().general_tree_widget)

        disk_usage = psutil.disk_usage('/')
        self.create_and_add_widget_item("Total disk space",
                                        format_size(disk_usage.total),
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Used disk space",
                                        format_size(disk_usage.used),
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Free disk space",
                                        format_size(disk_usage.free),
                                        self.window().general_tree_widget)
    def on_tribler_statistics(self, data):
        data = data["tribler_statistics"]
        self.window().general_tree_widget.clear()
        self.create_and_add_widget_item("Number of channels",
                                        data["num_channels"],
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Database size",
                                        format_size(data["database_size"]),
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Number of collected torrents",
                                        data["torrents"]["num_collected"],
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Number of torrent files",
                                        data["torrents"]["num_files"],
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item(
            "Total size of torrent files",
            format_size(data["torrents"]["total_size"]),
            self.window().general_tree_widget)
        self.create_and_add_widget_item("", "",
                                        self.window().general_tree_widget)

        disk_usage = psutil.disk_usage('/')
        self.create_and_add_widget_item("Total disk space",
                                        format_size(disk_usage.total),
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Used disk space",
                                        format_size(disk_usage.used),
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Free disk space",
                                        format_size(disk_usage.free),
                                        self.window().general_tree_widget)
Exemple #4
0
    def update_pages(self, new_download=False):
        if self.current_download is None:
            return

        if "files" not in self.current_download:
            self.current_download["files"] = []

        self.window().download_progress_bar.update_with_download(self.current_download)
        self.window().download_detail_name_label.setText(self.current_download['name'])

        if self.current_download["vod_mode"]:
            self.window().download_detail_status_label.setText('Streaming')
        else:
            status_string = DLSTATUS_STRINGS[eval(self.current_download["status"])]
            if eval(self.current_download["status"]) == DLSTATUS_STOPPED_ON_ERROR:
                status_string += " (error: %s)" % self.current_download["error"]
            self.window().download_detail_status_label.setText(status_string)

        self.window().download_detail_filesize_label.setText("%s in %d files" %
                                                             (format_size(float(self.current_download["size"])),
                                                              len(self.current_download["files"])))
        self.window().download_detail_health_label.setText("%d seeders, %d leechers" %
                                                           (self.current_download["num_seeds"],
                                                            self.current_download["num_peers"]))
        self.window().download_detail_infohash_label.setText(self.current_download['infohash'])
        self.window().download_detail_destination_label.setText(self.current_download["destination"])
        self.window().download_detail_ratio_label.setText(
            "%.3f, up: %s, down: %s" % (
                self.current_download["ratio"],
                format_size(self.current_download["total_up"]),
                format_size(self.current_download["total_down"])))
        self.window().download_detail_availability_label.setText("%.2f" % self.current_download['availability'])

        if new_download or len(self.current_download["files"]) != len(self.files_widgets.keys()):

            # (re)populate the files list
            self.window().download_files_list.clear()
            self.files_widgets = {}
            for dfile in self.current_download["files"]:
                item = DownloadFileWidgetItem(self.window().download_files_list, dfile)
                DownloadsDetailsTabWidget.update_file_row(item, dfile)
                self.files_widgets[dfile["name"]] = item

        else:  # No new download, just update data in the lists
            for dfile in self.current_download["files"]:
                DownloadsDetailsTabWidget.update_file_row(self.files_widgets[dfile["name"]], dfile)

        # Populate the trackers list
        self.window().download_trackers_list.clear()
        for tracker in self.current_download["trackers"]:
            item = QTreeWidgetItem(self.window().download_trackers_list)
            DownloadsDetailsTabWidget.update_tracker_row(item, tracker)

        # Populate the peers list if the peer information is available
        self.window().download_peers_list.clear()
        if "peers" in self.current_download:
            for peer in self.current_download["peers"]:
                item = QTreeWidgetItem(self.window().download_peers_list)
                DownloadsDetailsTabWidget.update_peer_row(item, peer)
 def on_tribler_statistics(self, data):
     data = data["tribler_statistics"]
     self.window().general_tree_widget.clear()
     self.create_and_add_widget_item("Number of channels", data["num_channels"], self.window().general_tree_widget)
     self.create_and_add_widget_item("Database size", format_size(data["database_size"]),
                                     self.window().general_tree_widget)
     self.create_and_add_widget_item("Number of collected torrents", data["torrents"]["num_collected"],
                                     self.window().general_tree_widget)
     self.create_and_add_widget_item("Number of torrent files", data["torrents"]["num_files"],
                                     self.window().general_tree_widget)
     self.create_and_add_widget_item("Total size of torrent files", format_size(data["torrents"]["total_size"]),
                                     self.window().general_tree_widget)
Exemple #6
0
    def update_pages(self):
        if self.current_download is None:
            return

        self.window().download_progress_bar.update_with_download(
            self.current_download)
        self.window().download_detail_name_label.setText(
            self.current_download['name'])
        self.window().download_detail_status_label.setText(
            DLSTATUS_STRINGS[eval(self.current_download["status"])])
        self.window().download_detail_filesize_label.setText(
            "%s in %d files" %
            (format_size(float(self.current_download["size"])),
             len(self.current_download["files"])))
        self.window().download_detail_health_label.setText(
            "%d seeders, %d leechers" % (self.current_download["num_seeds"],
                                         self.current_download["num_peers"]))
        self.window().download_detail_infohash_label.setText(
            self.current_download['infohash'])
        self.window().download_detail_destination_label.setText(
            self.current_download["destination"])
        self.window().download_detail_availability_label.setText(
            "%.2f" % self.current_download['availability'])

        # Populate the files list
        self.window().download_files_list.clear()
        for filename in self.current_download["files"]:
            item = QTreeWidgetItem(self.window().download_files_list)
            item.setText(0, filename["name"])
            item.setText(1, format_size(float(filename["size"])))
            item.setText(2,
                         '{percent:.1%}'.format(percent=filename["progress"]))
            item.setText(3, "yes" if filename["included"] else "no")
            item.setData(0, Qt.UserRole, filename)
            self.window().download_files_list.addTopLevelItem(item)

        # Populate the trackers list
        self.window().download_trackers_list.clear()
        for tracker in self.current_download["trackers"]:
            item = QTreeWidgetItem(self.window().download_trackers_list)
            item.setText(0, tracker["url"])
            item.setText(1, tracker["status"])
            item.setText(2, str(tracker["peers"]))

        # Populate the peers list if the peer information is available
        self.window().download_peers_list.clear()
        if "peers" in self.current_download:
            for peer in self.current_download["peers"]:
                self.create_widget_with_peer_info(peer)
    def update_item(self):
        self.setText(0, self.download_info["name"])
        if self.download_info["name"] == u"<old version of your channel>":
            itfont = QFont(self.font(0))
            itfont.setItalic(True)
            self.setFont(0, itfont)
        else:
            self.font(0).setItalic(False)
        self.setText(1, format_size(float(self.download_info["size"])))

        try:
            self.progress_slider.setValue(int(self.download_info["progress"] * 100))
        except RuntimeError:
            self._logger.error("The underlying GUI widget has already been removed.")

        if self.download_info["vod_mode"]:
            self.setText(3, "Streaming")
        else:
            self.setText(3, DLSTATUS_STRINGS[eval(self.download_info["status"])])
        self.setText(4, "%s (%s)" % (self.download_info["num_connected_seeds"], self.download_info["num_seeds"]))
        self.setText(5, "%s (%s)" % (self.download_info["num_connected_peers"], self.download_info["num_peers"]))
        self.setText(6, format_speed(self.download_info["speed_down"]))
        self.setText(7, format_speed(self.download_info["speed_up"]))
        self.setText(8, "%.3f" % float(self.download_info["ratio"]))
        self.setText(9, "yes" if self.download_info["anon_download"] else "no")
        self.setText(10, str(self.download_info["hops"]) if self.download_info["anon_download"] else "-")
        self.setText(12, datetime.fromtimestamp(int(self.download_info["time_added"])).strftime('%Y-%m-%d %H:%M'))

        eta_text = "-"
        if self.get_raw_download_status() == DLSTATUS_DOWNLOADING:
            eta_text = duration_to_string(self.download_info["eta"])
        self.setText(11, eta_text)
Exemple #8
0
    def update_credit_mining_disk_usage(self):
        on_credit_mining_tab = self.filter == DOWNLOADS_FILTER_CREDITMINING
        self.window().diskspace_usage.setVisible(on_credit_mining_tab)

        if not on_credit_mining_tab or not self.window().tribler_settings or not self.downloads:
            return

        bytes_max = self.window().tribler_settings["credit_mining"]["max_disk_space"]
        bytes_used = 0
        for download in self.downloads["downloads"]:
            if download["credit_mining"] and \
               download["status"] in ("DLSTATUS_DOWNLOADING", "DLSTATUS_SEEDING",
                                      "DLSTATUS_STOPPED", "DLSTATUS_STOPPED_ON_ERROR"):
                bytes_used += download["progress"] * download["size"]
        self.window().diskspace_usage.setText("Current disk space usage %s / %s" % (format_size(float(bytes_used)),
                                                                                    format_size(float(bytes_max))))
    def update_with_torrent(self, torrent_info):
        self.torrent_info = torrent_info
        self.is_health_checking = False
        self.torrent_detail_name_label.setText(self.torrent_info["name"])
        if self.torrent_info["category"]:
            self.torrent_detail_category_label.setText(self.torrent_info["category"].lower())
        else:
            self.torrent_detail_category_label.setText("unknown")

        if self.torrent_info["size"] is None:
            self.torrent_detail_size_label.setText("Size: -")
        else:
            self.torrent_detail_size_label.setText("%s" % format_size(float(self.torrent_info["size"])))

        if self.torrent_info["num_seeders"] > 0:
            self.torrent_detail_health_label.setText("good health (S%d L%d)" % (self.torrent_info["num_seeders"],
                                                                                self.torrent_info["num_leechers"]))
        elif self.torrent_info["num_leechers"] > 0:
            self.torrent_detail_health_label.setText("unknown health (found peers)")
        else:
            self.torrent_detail_health_label.setText("no peers found")

        self.setCurrentIndex(0)
        self.setTabEnabled(1, False)
        self.setTabEnabled(2, False)

        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("torrents/%s" % self.torrent_info["infohash"], self.on_torrent_info)
    def on_torrent_info(self, torrent_info):
        if not torrent_info:
            return
        self.setTabEnabled(1, True)
        self.setTabEnabled(2, True)

        self.torrent_detail_files_list.clear()
        self.torrent_detail_trackers_list.clear()

        for file_info in torrent_info["files"]:
            item = QTreeWidgetItem(self.torrent_detail_files_list)
            item.setText(0, file_info["path"])
            item.setText(1, format_size(float(file_info["size"])))

        for tracker in torrent_info["trackers"]:
            if tracker == 'DHT':
                continue
            item = QTreeWidgetItem(self.torrent_detail_trackers_list)
            item.setText(0, tracker)

        if torrent_info["num_seeders"] > 0:
            self.torrent_detail_health_label.setText("good health (S%d L%d)" % (torrent_info["num_seeders"],
                                                                                torrent_info["num_leechers"]))
        elif torrent_info["num_leechers"] > 0:
            self.torrent_detail_health_label.setText("unknown health (found peers)")
        else:
            self.torrent_detail_health_label.setText("no peers found")
    def on_torrent_info(self, torrent_info):
        self.setTabEnabled(1, True)
        self.setTabEnabled(2, True)

        self.torrent_detail_files_list.clear()
        self.torrent_detail_trackers_list.clear()

        for file_info in torrent_info["files"]:
            item = QTreeWidgetItem(self.torrent_detail_files_list)
            item.setText(0, file_info["path"])
            item.setText(1, format_size(float(file_info["size"])))

        for tracker in torrent_info["trackers"]:
            if tracker == 'DHT':
                continue
            item = QTreeWidgetItem(self.torrent_detail_trackers_list)
            item.setText(0, tracker)

        if torrent_info["num_seeders"] > 0:
            self.torrent_detail_health_label.setText(
                "good health (S%d L%d)" %
                (torrent_info["num_seeders"], torrent_info["num_leechers"]))
        elif torrent_info["num_leechers"] > 0:
            self.torrent_detail_health_label.setText(
                "unknown health (found peers)")
        else:
            self.torrent_detail_health_label.setText("no peers found")
    def update_with_torrent(self, torrent_info):
        self.torrent_info = torrent_info
        self.torrent_detail_name_label.setText(self.torrent_info["name"])
        if self.torrent_info["category"]:
            self.torrent_detail_category_label.setText(
                self.torrent_info["category"].lower())
        else:
            self.torrent_detail_category_label.setText("unknown")

        if self.torrent_info["size"] is None:
            self.torrent_detail_size_label.setText("Size: -")
        else:
            self.torrent_detail_size_label.setText(
                "%s" % format_size(float(self.torrent_info["size"])))

        if self.torrent_info["num_seeders"] > 0:
            self.torrent_detail_health_label.setText(
                "good health (S%d L%d)" % (self.torrent_info["num_seeders"],
                                           self.torrent_info["num_leechers"]))
        elif self.torrent_info["num_leechers"] > 0:
            self.torrent_detail_health_label.setText(
                "unknown health (found peers)")
        else:
            self.torrent_detail_health_label.setText("no peers found")

        self.setCurrentIndex(0)
        self.setTabEnabled(1, False)
        self.setTabEnabled(2, False)

        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request(
            "torrents/%s" % self.torrent_info["infohash"],
            self.on_torrent_info)
    def on_received_metainfo(self, metainfo):
        if not metainfo:
            return

        if 'error' in metainfo:
            if metainfo['error'] == 'timeout':
                self.dialog_widget.loading_files_label.setText("Timeout when trying to fetch files.")
            elif 'code' in metainfo['error'] and metainfo['error']['code'] == 'IOError':
                self.dialog_widget.loading_files_label.setText("Unable to read torrent file data")
            else:
                self.dialog_widget.loading_files_label.setText("Error: %s" % metainfo['error'])
            return

        metainfo = metainfo['metainfo']
        if 'files' in metainfo['info']:  # Multi-file torrent
            files = metainfo['info']['files']
        else:
            files = [{'path': [metainfo['info']['name']], 'length': metainfo['info']['length']}]

        for filename in files:
            item = DownloadFileTreeWidgetItem(self.dialog_widget.files_list_view)
            item.setText(0, '/'.join(filename['path']))
            item.setText(1, format_size(float(filename['length'])))
            item.setData(0, Qt.UserRole, filename)
            item.setCheckState(2, Qt.Checked)
            self.dialog_widget.files_list_view.addTopLevelItem(item)

        self.has_metainfo = True
        self.dialog_widget.loading_files_label.setHidden(True)
        self.dialog_widget.download_files_container.setHidden(False)
        self.dialog_widget.files_list_view.setHidden(False)
        self.dialog_widget.adjustSize()
        self.on_main_window_resize()

        self.received_metainfo.emit(metainfo)
Exemple #14
0
    def update_item(self):
        self.setText(0, self.download_info["name"])
        self.setText(1, format_size(float(self.download_info["size"])))

        try:
            self.progress_slider.setValue(
                int(self.download_info["progress"] * 100))
        except RuntimeError:
            pass

        self.setText(3, DLSTATUS_STRINGS[eval(self.download_info["status"])])
        self.setText(4, str(self.download_info["num_seeds"]))
        self.setText(5, str(self.download_info["num_peers"]))
        self.setText(6, format_speed(self.download_info["speed_down"]))
        self.setText(7, format_speed(self.download_info["speed_up"]))
        self.setText(8, "yes" if self.download_info["anon_download"] else "no")
        self.setText(
            9,
            str(self.download_info["hops"])
            if self.download_info["anon_download"] else "-")

        eta_text = "-"
        if self.get_raw_download_status() == DLSTATUS_DOWNLOADING:
            eta_text = duration_to_string(self.download_info["eta"])
        self.setText(10, eta_text)
Exemple #15
0
class SearchResultsContentModel(TriblerContentModel):
    """
    Model for a list that shows search results.
    """
    columns = [
        u'category', u'name', u'torrents', u'size', u'updated', u'health',
        ACTION_BUTTONS
    ]
    column_headers = [
        u'Category', u'Name', u'Torrents', u'Size', u'Updated', u'health', u''
    ]
    column_flags = {
        u'category': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        u'name': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        u'torrents': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        u'size': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        u'updated': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        u'health': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        ACTION_BUTTONS: Qt.ItemIsEnabled | Qt.ItemIsSelectable
    }

    column_display_filters = {
        u'size': lambda data: (format_size(float(data)) if data != '' else ''),
        u'updated': pretty_date,
    }

    def __init__(self, **kwargs):
        TriblerContentModel.__init__(self, **kwargs)
        self.type_filter = ''
Exemple #16
0
    def update_item(self):
        self.setText(0, self.download_info["name"])
        self.setText(1, format_size(float(self.download_info["size"])))

        try:
            self.progress_slider.setValue(int(self.download_info["progress"] * 100))
        except RuntimeError:
            pass

        if self.download_info["vod_mode"]:
            self.setText(3, "Streaming")
        else:
            self.setText(3, DLSTATUS_STRINGS[eval(self.download_info["status"])])
        self.setText(4, str(self.download_info["num_seeds"]))
        self.setText(5, str(self.download_info["num_peers"]))
        self.setText(6, format_speed(self.download_info["speed_down"]))
        self.setText(7, format_speed(self.download_info["speed_up"]))
        self.setText(8, "%.3f" % float(self.download_info["ratio"]))
        self.setText(9, "yes" if self.download_info["anon_download"] else "no")
        self.setText(10, str(self.download_info["hops"]) if self.download_info["anon_download"] else "-")
        self.setText(12, datetime.fromtimestamp(int(self.download_info["time_added"])).strftime('%Y-%m-%d %H:%M'))

        eta_text = "-"
        if self.get_raw_download_status() == DLSTATUS_DOWNLOADING:
            eta_text = duration_to_string(self.download_info["eta"])
        self.setText(11, eta_text)
Exemple #17
0
 def add_items_to_tree(self, tree, items, keys):
     tree.clear()
     for item in items:
         widget_item = QTreeWidgetItem(tree)
         for index, key in enumerate(keys):
             value = format_size(item[key]) if key in ["bytes_up", "bytes_down"] else str(item[key])
             widget_item.setText(index, value)
         tree.addTopLevelItem(widget_item)
Exemple #18
0
 def add_items_to_tree(self, tree, items, keys):
     tree.clear()
     for item in items:
         widget_item = QTreeWidgetItem(tree)
         for index, key in enumerate(keys):
             value = format_size(item[key]) if key in ["bytes_up", "bytes_down"] else str(item[key])
             widget_item.setText(index, value)
         tree.addTopLevelItem(widget_item)
 def update_with_torrent(self, torrent):
     self.show_torrent = True
     self.torrent_info = torrent
     self.thumbnail_widget.initialize(torrent["name"], HOME_ITEM_FONT_SIZE)
     self.main_label.setText(torrent["name"])
     self.category_label.setText(torrent["category"].lower())
     self.category_label.adjustSize()
     self.category_label.setHidden(False)
     self.setCursor(Qt.ArrowCursor)
     self.detail_label.setText("Size: " + format_size(torrent["size"]))
Exemple #20
0
    def on_tribler_statistics(self, data):
        if not data:
            return
        data = data["tribler_statistics"]
        self.window().general_tree_widget.clear()
        self.create_and_add_widget_item("Tribler version", self.tribler_version, self.window().general_tree_widget)
        self.create_and_add_widget_item("Number of channels", data["num_channels"], self.window().general_tree_widget)
        self.create_and_add_widget_item("Database size", format_size(data["db_size"]),
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Number of known torrents", data["num_torrents"],
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("", "", self.window().general_tree_widget)

        disk_usage = psutil.disk_usage('/')
        self.create_and_add_widget_item("Total disk space", format_size(disk_usage.total),
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Used disk space", format_size(disk_usage.used),
                                        self.window().general_tree_widget)
        self.create_and_add_widget_item("Free disk space", format_size(disk_usage.free),
                                        self.window().general_tree_widget)
    def __init__(self,
                 parent,
                 torrent,
                 show_controls=False,
                 on_remove_clicked=None):
        QWidget.__init__(self, parent)
        fc_channel_torrent_list_item.__init__(self)

        self.torrent_info = torrent
        self._logger = logging.getLogger('TriblerGUI')

        self.setupUi(self)
        self.show_controls = show_controls
        self.remove_control_button_container.setHidden(True)
        self.control_buttons_container.setHidden(True)
        self.is_health_checking = False
        self.has_health = False
        self.health_request_mgr = None
        self.request_mgr = None
        self.download_uri = None
        self.dialog = None

        self.channel_torrent_name.setText(torrent["name"])
        if torrent["size"] is None:
            self.channel_torrent_description.setText("Size: -")
        else:
            self.channel_torrent_description.setText(
                "Size: %s" % format_size(float(torrent["size"])))

        if torrent["category"]:
            self.channel_torrent_category.setText(torrent["category"].lower())
        else:
            self.channel_torrent_category.setText("unknown")
        self.thumbnail_widget.initialize(torrent["name"], 24)

        if torrent["last_tracker_check"] > 0:
            self.has_health = True
            self.update_health(int(torrent["num_seeders"]),
                               int(torrent["num_leechers"]))

        if "commit_status" in torrent:
            self.update_commit_status(torrent["commit_status"])
        else:
            self.commit_state_label.setHidden(True)

        self.torrent_play_button.clicked.connect(self.on_play_button_clicked)
        self.torrent_download_button.clicked.connect(self.on_download_clicked)

        if not self.window().vlc_available:
            self.torrent_play_button.setHidden(True)

        if on_remove_clicked is not None:
            self.remove_torrent_button.clicked.connect(
                lambda: on_remove_clicked(self))
 def update_with_torrent(self, torrent):
     if not torrent:
         return
     self.show_torrent = True
     self.torrent_info = torrent
     self.thumbnail_widget.initialize(torrent["name"], HOME_ITEM_FONT_SIZE)
     self.main_label.setText(torrent["name"])
     self.category_label.setText(torrent["category"].lower())
     self.category_label.adjustSize()
     self.category_label.setHidden(False)
     self.setCursor(Qt.ArrowCursor)
     self.detail_label.setText("Size: " + format_size(torrent["size"]))
    def __init__(self, parent, torrent):
        super(QWidget, self).__init__(parent)

        uic.loadUi('qt_resources/channel_torrent_list_item.ui', self)

        self.channel_torrent_name.setText(torrent["name"])
        if torrent["length"] is None:
            self.channel_torrent_description.setText("Size: -")
        else:
            self.channel_torrent_description.setText("Size: %s" % format_size(float(torrent["length"])))

        self.channel_torrent_category.setText(torrent["category"])
Exemple #24
0
    def on_received_metainfo(self, metainfo):
        if not metainfo or not self:
            return

        if 'error' in metainfo:
            if metainfo['error'] == 'timeout':
                self.dialog_widget.loading_files_label.setText(
                    "Timeout when trying to fetch files.")
            elif 'code' in metainfo['error'] and metainfo['error'][
                    'code'] == 'IOError':
                self.dialog_widget.loading_files_label.setText(
                    "Unable to read torrent file data")
            else:
                self.dialog_widget.loading_files_label.setText(
                    "Error: %s" % metainfo['error'])
            return

        metainfo = json.loads(unhexlify(metainfo['metainfo']),
                              encoding='latin-1')
        if 'files' in metainfo['info']:  # Multi-file torrent
            files = metainfo['info']['files']
        else:
            files = [{
                'path': [metainfo['info']['name']],
                'length': metainfo['info']['length']
            }]

        # Show if the torrent already exists in the downloads
        if 'download_exists' in metainfo and metainfo['download_exists']:
            self.dialog_widget.existing_download_info_label.setText(
                "Note: this torrent already exists in the Downloads")
        else:
            self.dialog_widget.existing_download_info_label.setText("")

        for filename in files:
            item = DownloadFileTreeWidgetItem(
                self.dialog_widget.files_list_view)
            item.setText(
                0, '/'.join(filename['path']).encode('raw_unicode_escape'))
            item.setText(1, format_size(float(filename['length'])))
            item.setData(0, Qt.UserRole, filename)
            item.setCheckState(2, Qt.Checked)
            self.dialog_widget.files_list_view.addTopLevelItem(item)

        self.has_metainfo = True
        self.dialog_widget.loading_files_label.setHidden(True)
        self.dialog_widget.download_files_container.setHidden(False)
        self.dialog_widget.files_list_view.setHidden(False)
        self.dialog_widget.adjustSize()
        self.on_main_window_resize()

        self.received_metainfo.emit(metainfo)
Exemple #25
0
    def update_credit_mining_disk_usage(self):
        on_credit_mining_tab = self.filter == DOWNLOADS_FILTER_CREDITMINING
        self.window().diskspace_usage.setVisible(on_credit_mining_tab)

        if not on_credit_mining_tab or not self.window(
        ).tribler_settings or not self.downloads:
            return

        bytes_max = self.window(
        ).tribler_settings["credit_mining"]["max_disk_space"]
        bytes_used = 0
        total_up = total_down = 0
        for download in self.downloads["downloads"]:
            if download["credit_mining"] and \
               download["status"] in ("DLSTATUS_DOWNLOADING", "DLSTATUS_SEEDING",
                                      "DLSTATUS_STOPPED", "DLSTATUS_STOPPED_ON_ERROR"):
                bytes_used += download["progress"] * download["size"]
                total_up += download["total_up"]
                total_down += download["total_down"]
        self.window().diskspace_usage.setText(
            "Disk usage: %s / %s \tUpload: %.3f MB \tDownload: %.3f MB" %
            (format_size(float(bytes_used)), format_size(float(bytes_max)),
             total_up / 1048576.0, total_down / 1028576.0))
 def update_with_torrent(self, torrent):
     if not torrent:
         return
     self.show_torrent = True
     self.torrent_info = torrent
     self.thumbnail_widget.initialize(torrent["name"], HOME_ITEM_FONT_SIZE)
     self.main_label.setText(torrent["name"])
     self.category_label.setText(torrent["category"].lower() if (
         "category" in torrent and torrent["category"]) else 'other')
     self.category_label.adjustSize()
     self.category_label.setHidden(False)
     self.setCursor(Qt.ArrowCursor)
     self.detail_label.setText("Size: " +
                               format_size(torrent.get("size", 0)))
    def __init__(self, parent, torrent, show_controls=False, on_remove_clicked=None):
        QWidget.__init__(self, parent)
        fc_channel_torrent_list_item.__init__(self)

        self.torrent_info = torrent
        self._logger = logging.getLogger('TriblerGUI')

        self.setupUi(self)
        self.show_controls = show_controls
        self.remove_control_button_container.setHidden(True)
        self.control_buttons_container.setHidden(True)
        self.is_health_checking = False
        self.has_health = False
        self.health_request_mgr = None
        self.request_mgr = None
        self.download_uri = None
        self.dialog = None

        self.channel_torrent_name.setText(torrent["name"])
        if torrent["size"] is None:
            self.channel_torrent_description.setText("Size: -")
        else:
            self.channel_torrent_description.setText("Size: %s" % format_size(float(torrent["size"])))

        if torrent["category"]:
            self.channel_torrent_category.setText(torrent["category"].lower())
        else:
            self.channel_torrent_category.setText("unknown")
        self.thumbnail_widget.initialize(torrent["name"], 24)

        if torrent["last_tracker_check"] > 0:
            self.has_health = True
            self.update_health(int(torrent["num_seeders"]), int(torrent["num_leechers"]))

        if "commit_status" in torrent:
            self.update_commit_status(torrent["commit_status"])
        else:
            self.commit_state_label.setHidden(True)

        self.torrent_play_button.clicked.connect(self.on_play_button_clicked)
        self.torrent_download_button.clicked.connect(self.on_download_clicked)

        if not self.window().vlc_available:
            self.torrent_play_button.setHidden(True)

        if on_remove_clicked is not None:
            self.remove_torrent_button.clicked.connect(lambda: on_remove_clicked(self))
Exemple #28
0
    def update_item(self):
        self.setText(0, self.download_info["name"])
        if self.download_info["name"] == u"<old version of your channel>":
            itfont = QFont(self.font(0))
            itfont.setItalic(True)
            self.setFont(0, itfont)
        else:
            self.font(0).setItalic(False)
        self.setText(1, format_size(float(self.download_info["size"])))

        try:
            self.progress_slider.setValue(
                int(self.download_info["progress"] * 100))
        except RuntimeError:
            self._logger.error(
                "The underlying GUI widget has already been removed.")

        if self.download_info["vod_mode"]:
            self.setText(3, "Streaming")
        else:
            self.setText(3,
                         DLSTATUS_STRINGS[eval(self.download_info["status"])])
        self.setText(
            4, "%s (%s)" % (self.download_info["num_connected_seeds"],
                            self.download_info["num_seeds"]))
        self.setText(
            5, "%s (%s)" % (self.download_info["num_connected_peers"],
                            self.download_info["num_peers"]))
        self.setText(6, format_speed(self.download_info["speed_down"]))
        self.setText(7, format_speed(self.download_info["speed_up"]))
        self.setText(8, "%.3f" % float(self.download_info["ratio"]))
        self.setText(9, "yes" if self.download_info["anon_download"] else "no")
        self.setText(
            10,
            str(self.download_info["hops"])
            if self.download_info["anon_download"] else "-")
        self.setText(
            12,
            datetime.fromtimestamp(int(
                self.download_info["time_added"])).strftime('%Y-%m-%d %H:%M'))

        eta_text = "-"
        if self.get_raw_download_status() == DLSTATUS_DOWNLOADING:
            eta_text = duration_to_string(self.download_info["eta"])
        self.setText(11, eta_text)
Exemple #29
0
class TorrentsContentModel(TriblerContentModel):
    columns = [u'category', u'name', u'size', u'health', ACTION_BUTTONS]
    column_headers = [u'Category', u'Name', u'Size', u'Health', u'']
    column_flags = {
        u'category': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        u'name': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        u'size': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        u'health': Qt.ItemIsEnabled | Qt.ItemIsSelectable,
        ACTION_BUTTONS: Qt.ItemIsEnabled | Qt.ItemIsSelectable
    }

    column_display_filters = {
        u'size': lambda data: format_size(float(data)),
    }

    def __init__(self, channel_pk='', **kwargs):
        TriblerContentModel.__init__(self, **kwargs)
        self.channel_pk = channel_pk
    def on_received_metainfo(self, metainfo):
        if not metainfo:
            return

        if 'error' in metainfo:
            if metainfo['error'] == 'timeout':
                self.dialog_widget.loading_files_label.setText("Timeout when trying to fetch files.")
            elif 'code' in metainfo['error'] and metainfo['error']['code'] == 'IOError':
                self.dialog_widget.loading_files_label.setText("Unable to read torrent file data")
            else:
                self.dialog_widget.loading_files_label.setText("Error: %s" % metainfo['error'])
            return

        metainfo = metainfo['metainfo']
        if 'files' in metainfo['info']:  # Multi-file torrent
            files = metainfo['info']['files']
        else:
            files = [{'path': [metainfo['info']['name']], 'length': metainfo['info']['length']}]

        # Show if the torrent already exists in the downloads
        if 'download_exists' in metainfo and metainfo['download_exists']:
            self.dialog_widget.existing_download_info_label.setText("Note: this torrent already exists in the Downloads")
        else:
            self.dialog_widget.existing_download_info_label.setText("")

        for filename in files:
            item = DownloadFileTreeWidgetItem(self.dialog_widget.files_list_view)
            item.setText(0, '/'.join(filename['path']))
            item.setText(1, format_size(float(filename['length'])))
            item.setData(0, Qt.UserRole, filename)
            item.setCheckState(2, Qt.Checked)
            self.dialog_widget.files_list_view.addTopLevelItem(item)

        self.has_metainfo = True
        self.dialog_widget.loading_files_label.setHidden(True)
        self.dialog_widget.download_files_container.setHidden(False)
        self.dialog_widget.files_list_view.setHidden(False)
        self.dialog_widget.adjustSize()
        self.on_main_window_resize()

        self.received_metainfo.emit(metainfo)
    def update_with_torrent(self, index, torrent_info):
        self.torrent_info = torrent_info
        self.index = index
        self.torrent_detail_name_label.setText(self.torrent_info["name"])
        if self.torrent_info["category"]:
            self.torrent_detail_category_label.setText(self.torrent_info["category"].lower())
        else:
            self.torrent_detail_category_label.setText("unknown")

        if self.torrent_info["size"] is None:
            self.torrent_detail_size_label.setText("Size: -")
        else:
            self.torrent_detail_size_label.setText("%s" % format_size(float(self.torrent_info["size"])))

        self.update_health_label(torrent_info['num_seeders'], torrent_info['num_leechers'],
                                 torrent_info['last_tracker_check'])

        self.setCurrentIndex(0)
        self.setTabEnabled(1, False)

        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("metadata/torrents/%s" % self.torrent_info["infohash"], self.on_torrent_info)
 def update_item(self):
     self.setText(0, self.file_info["name"])
     self.setText(1, format_size(float(self.file_info["size"])))
     self.setText(2, '{percent:.1%}'.format(percent=self.file_info["progress"]))
     self.setText(3, "yes" if self.file_info["included"] else "no")
     self.setData(0, Qt.UserRole, self.file_info)