示例#1
0
    def on_remove_download_dialog(self, action):
        if action != 2:
            infohash = self.selected_item.download_info["infohash"]

            # Reset video player if necessary before doing the actual request
            if self.window().video_player_page.active_infohash == infohash:
                self.window().video_player_page.reset_player()

            self.request_mgr = TriblerRequestManager()
            self.request_mgr.perform_request("downloads/%s" % infohash, self.on_download_removed,
                                             method='DELETE', data="remove_data=%d" % action)

        self.dialog.close_dialog()
        self.dialog = None
示例#2
0
    def on_rss_feed_dialog_removed(self, action):
        if action == 0:
            url = urllib.quote_plus(
                self.window().edit_channel_rss_feeds_list.selectedItems()
                [0].text(0))
            self.editchannel_request_mgr = TriblerRequestManager()
            self.editchannel_request_mgr.perform_request(
                "channels/discovered/%s/rssfeeds/%s" %
                (self.channel_overview["identifier"], url),
                self.on_rss_feed_removed,
                method='DELETE')

        self.dialog.setParent(None)
        self.dialog = None
示例#3
0
    def on_credit_mining_button_click(self):
        old_sources = self.window(
        ).tribler_settings["credit_mining"]["sources"]
        new_sources = [] if self.channel_info[
            "dispersy_cid"] in old_sources else [
                self.channel_info["dispersy_cid"]
            ]
        settings = {"credit_mining": {"sources": new_sources}}

        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("settings",
                                         self.on_credit_mining_sources,
                                         method='POST',
                                         data=json.dumps(settings))
示例#4
0
 def __init__(self):
     QWidget.__init__(self)
     self.export_dir = None
     self.filter = DOWNLOADS_FILTER_ALL
     self.download_widgets = {}  # key: infohash, value: QTreeWidgetItem
     self.downloads = None
     self.downloads_timer = QTimer()
     self.downloads_timeout_timer = QTimer()
     self.downloads_last_update = 0
     self.selected_items = None
     self.dialog = None
     self.downloads_request_mgr = TriblerRequestManager()
     self.request_mgr = None
     self.loading_message_widget = None
示例#5
0
 def on_subscribe_button_click(self):
     self.request_mgr = TriblerRequestManager()
     if int(self.channel_info["subscribed"]):
         self.request_mgr.perform_request("metadata/channels/%s" %
                                          self.channel_info['public_key'],
                                          self.on_channel_unsubscribed,
                                          data={"subscribe": 0},
                                          method='POST')
     else:
         self.request_mgr.perform_request("metadata/channels/%s" %
                                          self.channel_info['public_key'],
                                          self.on_channel_subscribed,
                                          data={"subscribe": 1},
                                          method='POST')
示例#6
0
    def check_health(self):
        """
        Perform a request to check the health of the torrent that is represented by this widget.
        Don't do this if we are already checking the health or if we have the health info.
        """
        if self.is_health_checking or self.has_health:  # Don't check health again
            return

        self.health_text.setText("checking health...")
        self.set_health_indicator(STATUS_UNKNOWN)
        self.is_health_checking = True
        self.health_request_mgr = TriblerRequestManager()
        self.health_request_mgr.perform_request("torrents/%s/health?timeout=15" % self.torrent_info["infohash"],
                                                self.on_health_response, capture_errors=False)
示例#7
0
    def load_downloads(self):
        url = "downloads?get_pieces=1"
        if self.window().download_details_widget.currentIndex() == 3:
            url = "downloads?get_peers=1&get_pieces=1"

        if not self.isHidden() or (time.time() - self.downloads_last_update >
                                   30):
            # Update if the downloads page is visible or if we haven't updated for longer than 30 seconds
            self.downloads_last_update = time.time()
            priority = "LOW" if self.isHidden() else "HIGH"
            self.downloads_request_mgr.cancel_request()
            self.downloads_request_mgr = TriblerRequestManager()
            self.downloads_request_mgr.perform_request(
                url, self.on_received_downloads, priority=priority)
示例#8
0
    def should_create_wallet(self, wallet_id):
        if (wallet_id == "BTC"
                or wallet_id == "TBTC") and not self.btc_module_available:
            ConfirmationDialog.show_error(
                self.window(), "bitcoinlib not found",
                "bitcoinlib could not be located on your system. "
                "Please install it using the following command: "
                "pip install bitcoinlib --user")
            return

        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("wallets/%s" % wallet_id,
                                         self.on_wallet_created,
                                         method='PUT')
示例#9
0
    def on_torrents_remove_all_action(self, action):
        if action == 0:
            for torrent_ind in xrange(self.window().edit_channel_torrents_list.count()):
                torrent_data = self.window().edit_channel_torrents_list.item(torrent_ind).data(Qt.UserRole)
                request_mgr = TriblerRequestManager()
                request_mgr.perform_request("channels/discovered/%s/torrents/%s" %
                                            (self.channel_overview["identifier"], torrent_data['infohash']),
                                            None, method='DELETE')
                self.remove_torrent_requests.append(request_mgr)

            self.window().edit_channel_torrents_list.set_data_items([])

        self.dialog.close_dialog()
        self.dialog = None
示例#10
0
    def on_add_torrent_browse_file(self):
        filename = QFileDialog.getOpenFileName(
            self, "Please select the .torrent file", "",
            "Torrent files (*.torrent)")

        with open(filename[0], "rb") as torrent_file:
            torrent_content = base64.b64encode(torrent_file.read())
            self.editchannel_request_mgr = TriblerRequestManager()
            self.editchannel_request_mgr.perform_request(
                "channels/discovered/%s/torrents" %
                self.channel_overview['identifier'],
                self.on_torrent_to_channel_added,
                method='PUT',
                data='torrent=%s' % torrent_content)
示例#11
0
    def on_iom_input(self, action):
        if action == 1:
            post_data = {'input_name': self.dialog.required_input['name']}
            for input_name, input_widget in self.dialog.input_widgets.iteritems(
            ):
                post_data[input_name] = input_widget.text()

            self.request_mgr = TriblerRequestManager()
            self.request_mgr.perform_request("iominput",
                                             None,
                                             data=urlencode(post_data),
                                             method='POST')

        self.dialog.setParent(None)
        self.dialog = None
示例#12
0
    def initialize_with_channel(self, channel_info):
        self.playlists = []
        self.torrents = []
        self.loaded_channels = False
        self.loaded_playlists = False

        self.get_torents_in_channel_manager = None
        self.get_playlists_in_channel_manager = None

        self.channel_info = channel_info

        self.window().channel_torrents_list.set_data_items([(LoadingListItem,
                                                             None)])
        self.window().channel_torrents_detail_widget.hide()

        self.window().channel_preview_label.setHidden(
            channel_info['subscribed'])
        self.window().channel_back_button.setIcon(
            QIcon(get_image_path('page_back.png')))

        self.get_torents_in_channel_manager = TriblerRequestManager()
        self.get_torents_in_channel_manager.perform_request(
            "channels/discovered/%s/torrents" % channel_info['dispersy_cid'],
            self.received_torrents_in_channel)

        self.get_playlists_in_channel_manager = TriblerRequestManager()
        self.get_playlists_in_channel_manager.perform_request(
            "channels/discovered/%s/playlists" % channel_info['dispersy_cid'],
            self.received_playlists_in_channel)

        # initialize the page about a channel
        self.window().channel_name_label.setText(channel_info['name'])
        self.window().num_subs_label.setText(str(channel_info['votes']))
        self.window().subscription_widget.initialize_with_channel(channel_info)

        self.window().edit_channel_button.setHidden(True)
示例#13
0
    def on_torrents_remove_selected_action(self, action, items):
        if action == 0:

            if isinstance(items, list):
                infohash = ",".join([torrent_item.torrent_info['infohash'] for torrent_item in items])
            else:
                infohash = items.torrent_info['infohash']
            self.editchannel_request_mgr = TriblerRequestManager()
            self.editchannel_request_mgr.perform_request("channels/discovered/%s/torrents/%s" %
                                                         (self.channel_overview["identifier"],
                                                          infohash),
                                                         self.on_torrent_removed, method='DELETE')

        self.dialog.close_dialog()
        self.dialog = None
示例#14
0
 def on_subscribe_control_clicked(self, index):
     item = index.model().data_items[index.row()]
     # skip LEGACY entries, regular torrents and personal channel
     if (u'subscribed' not in item or
             item[u'status'] == 1000 or
             item[u'my_channel']):
         return
     status = int(item[u'subscribed'])
     public_key = item[u'public_key']
     request_mgr = TriblerRequestManager()
     request_mgr.perform_request("metadata/channels/%s" % public_key,
                                 (lambda _: self.on_unsubscribed_channel.emit(index)) if status else
                                 (lambda _: self.on_subscribed_channel.emit(index)),
                                 data={"subscribe": int(not status)}, method='POST')
     index.model().data_items[index.row()][u'subscribed'] = int(not status)
示例#15
0
    def on_create_btc_wallet_dialog_done(self, action, wallet_id):
        password = self.dialog.dialog_widget.dialog_input.text()

        if action == 1:  # Remove the dialog right now
            self.dialog.close_dialog()
            self.dialog = None
        elif action == 0:
            self.dialog.buttons[0].setEnabled(False)
            self.dialog.buttons[1].setEnabled(False)
            self.dialog.buttons[0].setText("CREATING...")
            self.request_mgr = TriblerRequestManager()
            post_data = str("password=%s" % password)
            self.request_mgr.perform_request("wallets/%s" % wallet_id,
                                             self.on_wallet_created,
                                             method='PUT',
                                             data=post_data)
示例#16
0
    def on_create_channel_button_pressed(self):
        channel_name = self.window().new_channel_name_edit.text()
        channel_description = self.window(
        ).new_channel_description_edit.toPlainText()
        if len(channel_name) == 0:
            self.window().new_channel_name_label.setStyleSheet("color: red;")
            return

        self.window().create_channel_button.setEnabled(False)
        self.editchannel_request_mgr = TriblerRequestManager()
        self.editchannel_request_mgr.perform_request(
            "channels/discovered",
            self.on_channel_created,
            data=unicode('name=%s&description=%s' %
                         (channel_name, channel_description)).encode('utf-8'),
            method='PUT')
示例#17
0
    def on_check_health_clicked(self, timeout=15):
        if self.is_health_checking and (time.time() - self.last_health_check_ts
                                        < timeout):
            return

        self.is_health_checking = True
        self.torrent_detail_health_label.setText("Checking...")
        self.last_health_check_ts = time.time()
        self.health_request_mgr = TriblerRequestManager()
        self.health_request_mgr.perform_request(
            "torrents/%s/health?timeout=%s&refresh=%d" %
            (self.torrent_info["infohash"], timeout, 1),
            self.on_health_response,
            capture_errors=False,
            priority="LOW",
            on_cancel=self.on_cancel_health_check)
示例#18
0
    def on_memory_dump_button_clicked(self, dump_core):
        self.export_dir = QFileDialog.getExistingDirectory(
            self, "Please select the destination directory", "",
            QFileDialog.ShowDirsOnly)

        if len(self.export_dir) > 0:
            filename = "tribler_mem_dump_%s_%s.json" % \
                       ('core' if dump_core else 'gui', datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S"))
            if dump_core:
                self.request_mgr = TriblerRequestManager()
                self.request_mgr.download_file(
                    "debug/memory/dump",
                    lambda data: self.on_memory_dump_data_available(
                        filename, data))
            else:
                scanner.dump_all_objects(
                    os.path.join(self.export_dir, filename))
示例#19
0
 def create_order(self, is_ask, asset1_amount, asset1_type, asset2_amount,
                  asset2_type):
     """
     Create a new ask or bid order.
     """
     post_data = {
         "first_asset_amount": asset1_amount,
         "first_asset_type": asset1_type,
         "second_asset_amount": asset2_amount,
         "second_asset_type": asset2_type
     }
     self.request_mgr = TriblerRequestManager()
     self.request_mgr.perform_request(
         "market/%s" % ('asks' if is_ask else 'bids'),
         lambda response: self.on_order_created(response, is_ask),
         data=post_data,
         method='PUT')
示例#20
0
    def received_trustchain_statistics(self, statistics):
        statistics = statistics["statistics"]
        self.window().trust_contribution_amount_label.setText(
            "%s MBytes" % (statistics["total_up"] / self.byte_scale))
        self.window().trust_consumption_amount_label.setText(
            "%s MBytes" % (statistics["total_down"] / self.byte_scale))

        self.window().trust_people_helped_label.setText(
            "%d" % statistics["peers_that_pk_helped"])
        self.window().trust_people_helped_you_label.setText(
            "%d" % statistics["peers_that_helped_pk"])

        # Fetch the latest blocks of this user
        self.public_key = statistics["id"]
        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request(
            "trustchain/blocks/%s" % self.public_key,
            self.received_trustchain_blocks)
示例#21
0
    def create_order(self, is_ask, price, price_type, quantity, quantity_type):
        """
        Create a new ask or bid order.
        """
        asset1_amount = long(quantity * (10 ** self.wallets[quantity_type]["precision"]))

        price_num = price * (10 ** self.wallets[price_type]["precision"])
        price_denom = float(10 ** self.wallets[quantity_type]["precision"])
        price = price_num / price_denom

        asset2_amount = long(asset1_amount * price)

        post_data = str("first_asset_amount=%d&first_asset_type=%s&second_asset_amount=%d&second_asset_type=%s" %
                        (asset1_amount, quantity_type, asset2_amount, price_type))
        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("market/%s" % ('asks' if is_ask else 'bids'),
                                         lambda response: self.on_order_created(response, is_ask),
                                         data=post_data, method='PUT')
示例#22
0
    def should_create_wallet(self, wallet_id):
        if wallet_id == "BTC" or wallet_id == "TBTC":
            # We check whether bitcoinlib is installed, if not, warn the user (should only happen on linux systems)
            try:
                import bitcoinlib
            except ImportError:
                ConfirmationDialog.show_error(
                    self.window(), "bitcoinlib not found",
                    "bitcoinlib could not be located on your system. "
                    "Please install it using the following command: "
                    "pip install bitcoinlib --user")
                return

        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("wallets/%s" % wallet_id,
                                         self.on_wallet_created,
                                         method='PUT',
                                         data='')
示例#23
0
    def __init__(self):
        QWidget.__init__(self)
        self.trust_plot = None
        self.public_key = None
        self.request_mgr = None
        self.blocks = None
        self.byte_scale = 1024 * 1024
        self.dialog = None

        # Timer for garbage collection
        self.gc_timer = 0

        self.downloads_timer = QTimer()
        self.downloads_timeout_timer = QTimer()
        self.downloads_last_update = 0
        self.downloads_request_mgr = TriblerRequestManager()

        self.plot_data = [[[], []], []]
示例#24
0
    def on_top_search_button_click(self):
        current_ts = time.time()
        current_search_query = self.top_search_bar.text()

        if self.last_search_query and self.last_search_time \
                and self.last_search_query == self.top_search_bar.text() \
                and current_ts - self.last_search_time < 1:
            logging.info("Same search query already sent within 500ms so dropping this one")
            return

        self.left_menu_button_search.setChecked(True)
        self.has_search_results = True
        self.clicked_menu_button_search()
        self.search_results_page.perform_search(current_search_query)
        self.search_request_mgr = TriblerRequestManager()
        self.search_request_mgr.perform_request("search?q=%s" % current_search_query, None)
        self.last_search_query = current_search_query
        self.last_search_time = current_ts
示例#25
0
    def perform_start_download_request(self,
                                       uri,
                                       anon_download,
                                       safe_seeding,
                                       destination,
                                       selected_files,
                                       total_files=0,
                                       callback=None):
        selected_files_uri = ""
        if len(selected_files) != total_files:  # Not all files included
            selected_files_uri = u'&' + u''.join(
                u"selected_files[]=%s&" % file for file in selected_files)[:-1]

        anon_hops = int(self.tribler_settings['download_defaults']
                        ['number_hops']) if anon_download else 0
        safe_seeding = 1 if safe_seeding else 0
        post_data = "uri=%s&anon_hops=%d&safe_seeding=%d&destination=%s%s" % (
            uri, anon_hops, safe_seeding, destination, selected_files_uri)
        post_data = post_data.encode(
            'utf-8')  # We need to send bytes in the request, not unicode

        request_mgr = TriblerRequestManager()
        self.pending_requests[request_mgr.request_id] = request_mgr
        request_mgr.perform_request(
            "downloads",
            callback if callback else self.on_download_added,
            method='PUT',
            data=post_data)

        # Save the download location to the GUI settings
        current_settings = get_gui_setting(self.gui_settings,
                                           "recent_download_locations", "")
        recent_locations = current_settings.split(
            ",") if len(current_settings) > 0 else []
        encoded_destination = destination.encode('hex')
        if encoded_destination in recent_locations:
            recent_locations.remove(encoded_destination)
        recent_locations.insert(0, encoded_destination)

        if len(recent_locations) > 5:
            recent_locations = recent_locations[:5]

        self.gui_settings.setValue("recent_download_locations",
                                   ','.join(recent_locations))
示例#26
0
    def load_open_files_tab(self):
        # Fill the open files (GUI) tree widget
        my_process = psutil.Process()
        self.window().open_files_tree_widget.clear()
        gui_item = QTreeWidgetItem(self.window().open_files_tree_widget)

        open_files = my_process.open_files()
        gui_item.setText(0, "GUI (%d)" % len(open_files))
        self.window().open_files_tree_widget.addTopLevelItem(gui_item)

        for open_file in open_files:
            item = QTreeWidgetItem()
            item.setText(0, open_file.path)
            item.setText(1, "%d" % open_file.fd)
            gui_item.addChild(item)

        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("debug/open_files",
                                         self.on_core_open_files)
示例#27
0
    def received_multichain_statistics(self, statistics):
        statistics = statistics["statistics"]
        self.window().trust_contribution_amount_label.setText(
            "%s MBytes" % statistics["self_total_up_mb"])
        self.window().trust_consumption_amount_label.setText(
            "%s MBytes" % statistics["self_total_down_mb"])

        self.window().trust_people_helped_label.setText(
            "%d" % statistics["self_peers_helped"])
        self.window().trust_people_helped_you_label.setText(
            "%d" % statistics["self_peers_helped_you"])

        # Fetch the latest blocks of this user
        encoded_pub_key = urllib.quote_plus(statistics["self_id"])
        self.public_key = statistics["self_id"]
        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request(
            "multichain/blocks/%s" % encoded_pub_key,
            self.received_multichain_blocks)
示例#28
0
    def autocommit_fired(self):
        def commit_channel(overview):
            try:
                if overview and overview['mychannel']['dirty']:
                    self.editchannel_request_mgr = TriblerRequestManager()
                    self.editchannel_request_mgr.perform_request(
                        "mychannel/commit",
                        lambda _: None,
                        method='POST',
                        capture_errors=False)
            except KeyError:
                return

        if self.channel_overview:
            self.clicked_edit_channel_commit_button()
        else:
            self.editchannel_request_mgr = TriblerRequestManager()
            self.editchannel_request_mgr.perform_request("mychannel",
                                                         commit_channel,
                                                         capture_errors=False)
示例#29
0
    def on_torrents_remove_selected_action(self, action, items):
        if action == 0:
            items = [str(item) for item in items]
            infohashes = ",".join(items)

            post_data = {
                "infohashes": infohashes,
                "status": COMMIT_STATUS_TODELETE
            }

            request_mgr = TriblerRequestManager()
            request_mgr.perform_request(
                "mychannel/torrents",
                lambda response: self.on_torrents_removed_response(
                    response, items),
                data=post_data,
                method='POST')
        if self.dialog:
            self.dialog.close_dialog()
            self.dialog = None
示例#30
0
 def should_create_wallet(self, wallet_id):
     if wallet_id == 'BTC':
         self.dialog = ConfirmationDialog(
             self,
             "Create Bitcoin wallet",
             "Please enter the password of your Bitcoin wallet below:",
             [('CREATE', BUTTON_TYPE_NORMAL),
              ('CANCEL', BUTTON_TYPE_CONFIRM)],
             show_input=True)
         self.dialog.dialog_widget.dialog_input.setPlaceholderText(
             'Wallet password')
         self.dialog.button_clicked.connect(
             self.on_create_btc_wallet_dialog_done)
         self.dialog.show()
     else:
         self.request_mgr = TriblerRequestManager()
         self.request_mgr.perform_request("wallets/%s" % wallet_id,
                                          self.on_wallet_created,
                                          method='PUT',
                                          data='')