コード例 #1
0
ファイル: channelpage.py プロジェクト: synctext/tribler
    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)

        if len(channel_info['dispersy_cid']) == 148: # Check-hack for Channel2.0 style address
            self.loaded_playlists = True
        else:
            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)
コード例 #2
0
ファイル: editchannelpage.py プロジェクト: Tribler/tribler
 def add_torrent_to_channel(self, filename):
     with open(filename, "rb") as torrent_file:
         torrent_content = b64encode(torrent_file.read())
         request_mgr = TriblerRequestManager()
         request_mgr.perform_request("mychannel/torrents",
                                     self.on_torrent_to_channel_added, method='PUT',
                                     data={"torrent": torrent_content})
コード例 #3
0
ファイル: editchannelpage.py プロジェクト: Tribler/tribler
    def on_torrents_remove_all_action(self, action):
        if action == 0:
            request_mgr = TriblerRequestManager()
            request_mgr.perform_request("mychannel/torrents", self.on_all_torrents_removed_response, method='DELETE')

        self.dialog.close_dialog()
        self.dialog = None
コード例 #4
0
ファイル: editchannelpage.py プロジェクト: synctext/tribler
 def add_torrent_to_channel(self, filename):
     with open(filename, "rb") as torrent_file:
         torrent_content = urllib.quote_plus(base64.b64encode(torrent_file.read()))
         editchannel_request_mgr = TriblerRequestManager()
         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)
コード例 #5
0
ファイル: editchannelpage.py プロジェクト: Tribler/tribler
 def add_dir_to_channel(self, dirname, recursive=False):
     post_data = {
         "torrents_dir": dirname,
         "recursive": int(recursive)
     }
     request_mgr = TriblerRequestManager()
     request_mgr.perform_request("mychannel/torrents",
                                 self.on_torrent_to_channel_added, method='PUT', data=post_data)
コード例 #6
0
ファイル: editchannelpage.py プロジェクト: synctext/tribler
        def on_export_download_dialog_done(action):
            if action == 0:
                dest_path = os.path.join(export_dir, dialog.dialog_widget.dialog_input.text())
                request_mgr = TriblerRequestManager()
                request_mgr.download_file("channels/discovered/%s/mdblob" % mdblob_name,
                                          lambda data: on_export_download_request_done(dest_path, data))

            dialog.close_dialog()
コード例 #7
0
class SubscribedChannelsPage(QWidget):
    """
    This page shows all the channels that the user has subscribed to.
    """

    def __init__(self):
        QWidget.__init__(self)

        self.dialog = None
        self.request_mgr = None

    def initialize(self):
        self.window().add_subscription_button.clicked.connect(self.on_add_subscription_clicked)

    def load_subscribed_channels(self):
        self.window().subscribed_channels_list.set_data_items([(LoadingListItem, None)])

        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("channels/subscribed", self.received_subscribed_channels)

    def received_subscribed_channels(self, results):
        if not results:
            return
        self.window().subscribed_channels_list.set_data_items([])
        items = []

        if len(results['subscribed']) == 0:
            self.window().subscribed_channels_list.set_data_items(
                [(LoadingListItem, "You are not subscribed to any channel.")])
            return

        for result in results['subscribed']:
            items.append((ChannelListItem, result))
        self.window().subscribed_channels_list.set_data_items(items)

    def on_add_subscription_clicked(self):
        self.dialog = ConfirmationDialog(self, "Add subscribed channel",
                                         "Please enter the identifier of the channel you want to subscribe to below. "
                                         "It can take up to a minute before the channel is visible in your list of "
                                         "subscribed channels.",
                                         [('ADD', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)],
                                         show_input=True)
        self.dialog.dialog_widget.dialog_input.setPlaceholderText('Channel identifier')
        self.dialog.button_clicked.connect(self.on_subscription_added)
        self.dialog.show()

    def on_subscription_added(self, action):
        if action == 0:
            self.request_mgr = TriblerRequestManager()
            self.request_mgr.perform_request("channels/subscribed/%s" % self.dialog.dialog_widget.dialog_input.text(),
                                             self.on_channel_subscribed, method='PUT')

        self.dialog.close_dialog()
        self.dialog = None

    def on_channel_subscribed(self, _):
        pass
コード例 #8
0
ファイル: lazytableview.py プロジェクト: Tribler/tribler
    def on_commit_control_clicked(self, index):
        infohash = index.model().data_items[index.row()][u'infohash']
        status = index.model().data_items[index.row()][u'status']

        new_status = COMMIT_STATUS_COMMITTED
        if status == COMMIT_STATUS_NEW or status == COMMIT_STATUS_COMMITTED:
            new_status = COMMIT_STATUS_TODELETE

        request_mgr = TriblerRequestManager()
        request_mgr.perform_request("mychannel/torrents/%s" % infohash,
                                    lambda response: self.on_torrent_status_updated(response, index),
                                    data={"status": new_status}, method='PATCH')
コード例 #9
0
ファイル: lazytableview.py プロジェクト: Tribler/tribler
 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)
コード例 #10
0
ファイル: settingspage.py プロジェクト: Tribler/tribler
 def on_confirm_partially_empty_tokens(self, action, tokens):
     self.confirm_empty_tokens_dialog.close_dialog()
     self.confirm_empty_tokens_dialog = None
     if action == 0:
         self.trustchain_request_mgr = TriblerRequestManager()
         self.trustchain_request_mgr.perform_request("trustchain/bootstrap?amount=%d" % (tokens * MEBIBYTE),
                                                     self.on_emptying_tokens)
コード例 #11
0
ファイル: tribler_window.py プロジェクト: Tribler/tribler
    def received_settings(self, settings):
        if not settings:
            return
        # If we cannot receive the settings, stop Tribler with an option to send the crash report.
        if 'error' in settings:
            raise RuntimeError(TriblerRequestManager.get_message_from_error(settings))

        self.tribler_settings = settings['settings']

        # Set the video server port
        self.video_player_page.video_player_port = settings["ports"]["video_server~port"]

        # Disable various components based on the settings
        if not self.tribler_settings['video_server']['enabled']:
            self.left_menu_button_video_player.setHidden(True)
        self.downloads_creditmining_button.setHidden(not self.tribler_settings["credit_mining"]["enabled"])
        self.downloads_all_button.click()

        # process pending file requests (i.e. someone clicked a torrent file when Tribler was closed)
        # We do this after receiving the settings so we have the default download location.
        self.process_uri_request()

        # Set token balance refresh timer and load the token balance
        self.token_refresh_timer = QTimer()
        self.token_refresh_timer.timeout.connect(self.load_token_balance)
        self.token_refresh_timer.start(60000)

        self.load_token_balance()
コード例 #12
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 = []
     self.dialog = None
     self.downloads_request_mgr = TriblerRequestManager()
     self.request_mgr = None
     self.loading_message_widget = None
     self.total_download = 0
     self.total_upload = 0
コード例 #13
0
ファイル: marketwalletspage.py プロジェクト: pariahGH/tribler
    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: "
                "Linux: sudo chown -R $(id -un) ~/.local ; pip install bitcoinlib --user"
                "Windows: 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='')
コード例 #14
0
ファイル: settingspage.py プロジェクト: Tribler/tribler
    def on_confirm_fully_empty_tokens(self, action):
        self.confirm_empty_tokens_dialog.close_dialog()
        self.confirm_empty_tokens_dialog = None

        if action == 0:
            self.trustchain_request_mgr = TriblerRequestManager()
            self.trustchain_request_mgr.perform_request("trustchain/bootstrap", self.on_emptying_tokens)
コード例 #15
0
ファイル: tribler_window.py プロジェクト: yws/tribler
    def received_settings(self, settings):
        if not settings:
            return
        # If we cannot receive the settings, stop Tribler with an option to send the crash report.
        if 'error' in settings:
            raise RuntimeError(
                TriblerRequestManager.get_message_from_error(settings))

        self.tribler_settings = settings['settings']

        # Set the video server port
        self.video_player_page.video_player_port = settings["ports"][
            "video_server~port"]

        # Disable various components based on the settings
        if not self.tribler_settings['search_community']['enabled']:
            self.window().top_search_bar.setHidden(True)
        if not self.tribler_settings['video_server']['enabled']:
            self.left_menu_button_video_player.setHidden(True)
        self.downloads_creditmining_button.setHidden(
            not self.tribler_settings["credit_mining"]["enabled"])
        self.downloads_all_button.click()

        # process pending file requests (i.e. someone clicked a torrent file when Tribler was closed)
        # We do this after receiving the settings so we have the default download location.
        self.process_uri_request()

        # Set token balance refresh timer and load the token balance
        self.token_refresh_timer = QTimer()
        self.token_refresh_timer.timeout.connect(self.load_token_balance)
        self.token_refresh_timer.start(60000)

        self.load_token_balance()
コード例 #16
0
ファイル: createtorrentpage.py プロジェクト: Tribler/tribler
    def on_create_clicked(self):
        if self.window().create_torrent_files_list.count() == 0:
            self.dialog = ConfirmationDialog(self, "Notice", "You should add at least one file to your torrent.",
                                             [('CLOSE', BUTTON_TYPE_NORMAL)])
            self.dialog.button_clicked.connect(self.on_dialog_ok_clicked)
            self.dialog.show()
            return

        self.window().edit_channel_create_torrent_button.setEnabled(False)

        files_list = []
        for ind in xrange(self.window().create_torrent_files_list.count()):
            file_str = self.window().create_torrent_files_list.item(ind).text()
            files_list.append(file_str)

        name = self.window().create_torrent_name_field.text()
        description = self.window().create_torrent_description_field.toPlainText()
        post_data = {
            "name": name,
            "description": description,
            "files": files_list
        }
        url = "createtorrent?download=1" if self.window().seed_after_adding_checkbox.isChecked() else "createtorrent"
        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request(url, self.on_torrent_created, data=post_data, method='POST')
        # Show creating torrent text
        self.window().edit_channel_create_torrent_progress_label.show()
コード例 #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_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.setParent(None)
        self.dialog = None
コード例 #19
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.setParent(None)
            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)
コード例 #20
0
ファイル: Main.py プロジェクト: devos50/TriblerGUI
 def on_top_search_button_click(self):
     self.clicked_menu_button("-")
     self.stackedWidget.setCurrentIndex(PAGE_SEARCH_RESULTS)
     self.search_results_page.perform_search(self.top_search_bar.text())
     self.search_request_mgr = TriblerRequestManager()
     self.search_request_mgr.search_channels(self.top_search_bar.text(),
                                             self.search_results_page.received_search_results)
コード例 #21
0
ファイル: Main.py プロジェクト: devos50/TriblerGUI
    def clicked_menu_button(self, menu_button_name):
        # Deselect menu buttons
        for button in self.menu_buttons:
            button.unselectMenuButton()

        if menu_button_name == "left_menu_home_button":
            self.left_menu_home_button.selectMenuButton()
            self.stackedWidget.setCurrentIndex(PAGE_HOME)
        elif menu_button_name == "left_menu_my_channel_button":
            self.left_menu_my_channel_button.selectMenuButton()
            self.stackedWidget.setCurrentIndex(PAGE_MY_CHANNEL)
            self.my_channel_page.load_my_channel_overview()
        elif menu_button_name == "left_menu_videoplayer_button":
            self.left_menu_videoplayer_button.selectMenuButton()
            self.stackedWidget.setCurrentIndex(PAGE_VIDEO_PLAYER)
        elif menu_button_name == "left_menu_downloads_button":
            self.left_menu_downloads_button.selectMenuButton()
            self.stackedWidget.setCurrentIndex(PAGE_DOWNLOADS)
        elif menu_button_name == "left_menu_settings_button":
            self.left_menu_settings_button.selectMenuButton()
            self.stackedWidget.setCurrentIndex(PAGE_SETTINGS)
            self.settings_page.load_settings()
        elif menu_button_name == "left_menu_subscribed_button":
            self.left_menu_subscribed_button.selectMenuButton()
            self.subscribed_channels_request_manager = TriblerRequestManager()
            self.subscribed_channels_request_manager.get_subscribed_channels(self.received_subscribed_channels)
            self.stackedWidget.setCurrentIndex(PAGE_SUBSCRIBED_CHANNELS)
        self.navigation_stack = []
コード例 #22
0
    def perform_query(self, **kwargs):
        """
        Fetch results for a given query.
        """
        if 'first' not in kwargs or 'last' not in kwargs:
            kwargs["first"], kwargs[
                'last'] = self.model.rowCount() + 1, self.model.rowCount() + self.model.item_load_batch

        # Create a new uuid for each new search
        if kwargs['first'] == 1 or not self.query_uuid:
            self.query_uuid = uuid.uuid4().hex

        sort_by, sort_asc = self._get_sort_parameters()
        kwargs.update({
            "uuid": self.query_uuid,
            "filter": to_fts_query(self.query_text),
            "sort_by": sort_by,
            "sort_asc": sort_asc,
            "hide_xxx": self.model.hide_xxx})

        rest_endpoint_url = kwargs.pop("rest_endpoint_url")
        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request(rest_endpoint_url,
                                         self.on_query_results,
                                         url_params=kwargs)
コード例 #23
0
    def load_downloads(self):
        url = "downloads?get_pieces=1"
        if self.window().download_details_widget.currentIndex() == 3:
            url += "&get_peers=1"
        elif self.window().download_details_widget.currentIndex() == 1:
            url += "&get_files=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)
コード例 #24
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)
コード例 #25
0
ファイル: editchannelpage.py プロジェクト: brussee/tribler
    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')
コード例 #26
0
ファイル: editchannelpage.py プロジェクト: synctext/tribler
    def load_my_channel_overview(self):
        if not self.channel_overview:
            self.window().edit_channel_stacked_widget.setCurrentIndex(2)

        self.editchannel_request_mgr = TriblerRequestManager()
        self.editchannel_request_mgr.perform_request("mychannel", self.initialize_with_channel_overview,
                                                     capture_errors=False)
コード例 #27
0
    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)
コード例 #28
0
ファイル: editchannelpage.py プロジェクト: synctext/tribler
    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([])
            if "chant" in self.channel_overview:
                self.load_channel_torrents()

        self.dialog.close_dialog()
        self.dialog = None
コード例 #29
0
    def initialize(self, channel_info, playlist_info):
        self.channel_info = channel_info
        self.playlist_info = playlist_info
        self.window().edit_channel_details_manage_playlist_header.setText("Manage torrents in playlist '%s'" %
                                                                          playlist_info['name'])
        self.window().manage_channel_playlist_torrents_back.setIcon(QIcon(get_image_path('page_back.png')))

        self.window().playlist_manage_add_to_playlist.clicked.connect(self.on_add_clicked)
        self.window().playlist_manage_remove_from_playlist.clicked.connect(self.on_remove_clicked)
        self.window().edit_channel_manage_playlist_save_button.clicked.connect(self.on_save_clicked)
        self.window().manage_channel_playlist_torrents_back.clicked.connect(self.on_playlist_manage_back_clicked)

        # Load torrents in your channel
        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("channels/discovered/%s/torrents?disable_filter=1" %
                                         channel_info["identifier"], self.on_received_channel_torrents)

        self.torrents_in_playlist = []
        self.torrents_in_channel = []

        self.torrents_to_create = []
        self.torrents_to_remove = []

        self.pending_requests = []
        self.requests_done = 0
コード例 #30
0
class DiscoveredPage(QWidget):
    """
    The DiscoveredPage shows an overview of all discovered channels in Tribler.
    """
    def __init__(self):
        QWidget.__init__(self)
        self.discovered_channels = []
        self.request_mgr = None
        self.initialized = False

    def initialize_discovered_page(self):
        if not self.initialized:
            self.window(
            ).core_manager.events_manager.discovered_channel.connect(
                self.on_discovered_channel)
            self.initialized = True

    def load_discovered_channels(self):
        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("channels/discovered",
                                         self.received_discovered_channels)

    def received_discovered_channels(self, results):
        self.discovered_channels = []
        self.window().discovered_channels_list.set_data_items([])
        items = []

        results['channels'].sort(key=lambda x: x['torrents'], reverse=True)

        for result in results['channels']:
            items.append((ChannelListItem, result))
            self.discovered_channels.append(result)
            self.update_num_label()
        self.window().discovered_channels_list.set_data_items(items)

    def on_discovered_channel(self, channel_info):
        channel_info['torrents'] = 0
        channel_info['subscribed'] = False
        channel_info['votes'] = 0
        self.window().discovered_channels_list.append_item(
            (ChannelListItem, channel_info))
        self.discovered_channels.append(channel_info)
        self.update_num_label()

    def update_num_label(self):
        self.window().num_discovered_channels_label.setText(
            "%d items" % len(self.discovered_channels))
コード例 #31
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')
コード例 #32
0
    def on_subscription_added(self, action):
        if action == 0:
            self.request_mgr = TriblerRequestManager()
            self.request_mgr.perform_request("channels/subscribed/%s" % self.dialog.dialog_widget.dialog_input.text(),
                                             self.on_channel_subscribed, method='PUT')

        self.dialog.close_dialog()
        self.dialog = None
コード例 #33
0
ファイル: editchannelpage.py プロジェクト: Tribler/tribler
 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
コード例 #34
0
ファイル: editchannelpage.py プロジェクト: Tribler/tribler
    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
コード例 #35
0
    def load_payments(self):
        self.window().market_payments_list.clear()

        item = self.selected_transaction_item
        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("market/transactions/%s/%s/payments" %
                                         (item.transaction['trader_id'], item.transaction['transaction_number']),
                                         self.on_received_payments)
コード例 #36
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))
コード例 #37
0
ファイル: discoveredpage.py プロジェクト: synctext/tribler
class DiscoveredPage(QWidget):
    """
    The DiscoveredPage shows an overview of all discovered channels in Tribler.
    """

    def __init__(self):
        QWidget.__init__(self)
        self.discovered_channels = []
        self.request_mgr = None
        self.initialized = False

    def initialize_discovered_page(self):
        if not self.initialized:
            self.window().core_manager.events_manager.discovered_channel.connect(self.on_discovered_channel)
            self.initialized = True

    def load_discovered_channels(self):
        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("channels/discovered", self.received_discovered_channels)

    def received_discovered_channels(self, results):
        if not results or 'channels' not in results:
            return

        self.discovered_channels = []
        self.window().discovered_channels_list.set_data_items([])
        items = []

        results['channels'].sort(key=lambda x: x['torrents'], reverse=True)

        for result in results['channels']:
            items.append((ChannelListItem, result))
            self.discovered_channels.append(result)
            self.update_num_label()
        self.window().discovered_channels_list.set_data_items(items)

    def on_discovered_channel(self, channel_info):
        channel_info['torrents'] = 0
        channel_info['subscribed'] = False
        channel_info['votes'] = 0
        self.window().discovered_channels_list.append_item((ChannelListItem, channel_info))
        self.discovered_channels.append(channel_info)
        self.update_num_label()

    def update_num_label(self):
        self.window().num_discovered_channels_label.setText("%d items" % len(self.discovered_channels))
コード例 #38
0
ファイル: debug_window.py プロジェクト: Tribler/tribler
 def load_ipv8_community_details_tab(self):
     if self.ipv8_statistics_enabled:
         self.window().ipv8_statistics_error_label.setHidden(True)
         self.request_mgr = TriblerRequestManager()
         self.request_mgr.perform_request("ipv8/overlays/statistics", self.on_ipv8_community_detail_stats)
     else:
         self.window().ipv8_statistics_error_label.setHidden(False)
         self.window().ipv8_communities_details_widget.setHidden(True)
コード例 #39
0
ファイル: marketorderspage.py プロジェクト: synctext/tribler
    def on_confirm_cancel_order(self, action):
        if action == 1:
            self.request_mgr = TriblerRequestManager()
            self.request_mgr.perform_request("market/orders/%s/cancel" % self.selected_item.order['order_number'],
                                             self.on_order_cancelled, method='POST')

        self.dialog.close_dialog()
        self.dialog = None
コード例 #40
0
ファイル: debug_window.py プロジェクト: bluefalcon26/tribler
    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))
コード例 #41
0
ファイル: debug_window.py プロジェクト: Tribler/tribler
    def on_toggle_profiler_button_clicked(self):
        if self.toggling_profiler:
            return

        self.toggling_profiler = True
        self.window().toggle_profiler_button.setEnabled(False)
        self.request_mgr = TriblerRequestManager()
        method = "DELETE" if self.profiler_enabled else "PUT"
        self.request_mgr.perform_request("debug/profiler", self.on_profiler_state_changed, method=method)
コード例 #42
0
ファイル: marketpage.py プロジェクト: xiaomuweb/tribler
    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')
コード例 #43
0
ファイル: editchannelpage.py プロジェクト: synctext/tribler
 def on_torrent_from_url_dialog_done(self, action):
     if action == 0:
         url = urllib.quote_plus(self.dialog.dialog_widget.dialog_input.text())
         self.editchannel_request_mgr = TriblerRequestManager()
         self.editchannel_request_mgr.perform_request("channels/discovered/%s/torrents/%s" %
                                                      (self.channel_overview['identifier'], url),
                                                      self.on_torrent_to_channel_added, method='PUT')
     self.dialog.close_dialog()
     self.dialog = None
コード例 #44
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='')
コード例 #45
0
ファイル: tokenminingpage.py プロジェクト: zippav/tribler
    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 = [[[], []], []]
コード例 #46
0
    def on_add_torrent_browse_file(self):
        filename = QFileDialog.getOpenFileName(
            self, "Please select the .torrent file", "",
            "Torrent files (*.torrent)")

        if len(filename[0]) == 0:
            return

        with open(filename[0], "rb") as torrent_file:
            torrent_content = urllib.quote_plus(
                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)
コード例 #47
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
コード例 #48
0
ファイル: trustpage.py プロジェクト: wesavetheworld/tribler
    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)
コード例 #49
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))
コード例 #50
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.setParent(None)
        self.dialog = None
コード例 #51
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.setParent(None)
        self.dialog = None
コード例 #52
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)
コード例 #53
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)
コード例 #54
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='')
コード例 #55
0
ファイル: editchannelpage.py プロジェクト: zippav/tribler
    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)
コード例 #56
0
ファイル: editchannelpage.py プロジェクト: zippav/tribler
    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
コード例 #57
0
class MyTorrentsTableViewController(TorrentsTableViewController):
    """
    This class manages the list with the torrents in your own channel.
    """
    def __init__(self, *args, **kwargs):
        super(MyTorrentsTableViewController, self).__init__(*args, **kwargs)
        self.model.row_edited.connect(self._on_row_edited)

    def _on_row_edited(self, index, new_value):
        infohash = self.model.data_items[index.row()][u'infohash']
        attribute_name = self.model.columns[index.column()]
        attribute_name = u'tags' if attribute_name == u'category' else attribute_name
        attribute_name = u'title' if attribute_name == u'name' else attribute_name

        self.request_mgr = TriblerRequestManager()
        self.request_mgr.perform_request("mychannel/torrents/%s" % infohash,
                                         self._on_row_update_results,
                                         method='PATCH',
                                         data={attribute_name: new_value})

    def _on_row_update_results(self, response):
        if response:
            self.table_view.window(
            ).edit_channel_page.channel_dirty = response['dirty']
            self.table_view.window(
            ).edit_channel_page.update_channel_commit_views()

    def perform_query(self, **kwargs):
        kwargs.update({
            "rest_endpoint_url": "mychannel/torrents",
            "exclude_deleted": self.model.exclude_deleted
        })
        super(MyTorrentsTableViewController, self).perform_query(**kwargs)

    def on_query_results(self, response):
        if super(MyTorrentsTableViewController,
                 self).on_query_results(response):
            self.table_view.window(
            ).edit_channel_page.channel_dirty = response['dirty']
            self.table_view.window(
            ).edit_channel_page.update_channel_commit_views()
コード例 #58
0
    def perform_start_download_request(self, uri, anon_download, safe_seeding, destination, selected_files,
                                       total_files=0, callback=None):
        # Check if destination directory is writable
        is_writable, error = is_dir_writable(destination)
        if not is_writable:
            gui_error_message = "Insufficient write permissions to <i>%s</i> directory. Please add proper " \
                                "write permissions on the directory and add the torrent again. %s" \
                                % (destination, error)
            ConfirmationDialog.show_message(self.window(), "Download error <i>%s</i>" % uri, gui_error_message, "OK")
            return

        selected_files_uri = ""
        if len(selected_files) != total_files:  # Not all files included
            selected_files_uri = u'&' + u''.join(u"selected_files[]=%s&" %
                                                 quote_plus_unicode(filename) for filename 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" % (quote_plus_unicode(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()
        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 []
        if isinstance(destination, unicode):
            destination = destination.encode('utf-8')
        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))
コード例 #59
0
ファイル: editchannelpage.py プロジェクト: ildella/tribler
    def on_playlist_edit_save_clicked(self):
        if len(self.window().playlist_edit_name.text()) == 0:
            return

        name = self.window().playlist_edit_name.text()
        description = self.window().playlist_edit_description.toPlainText()

        self.editchannel_request_mgr = TriblerRequestManager()
        if self.editing_playlist is None:
            self.editchannel_request_mgr.perform_request("channels/discovered/%s/playlists" %
                                                         self.channel_overview["identifier"], self.on_playlist_created,
                                                         data=unicode('name=%s&description=%s' %
                                                                      (name, description)).encode('utf-8'),
                                                         method='PUT')
        else:
            self.editchannel_request_mgr.perform_request("channels/discovered/%s/playlists/%s" %
                                                         (self.channel_overview["identifier"],
                                                          self.editing_playlist["id"]), self.on_playlist_edited,
                                                         data=unicode('name=%s&description=%s' %
                                                                      (name, description)).encode('utf-8'),
                                                         method='POST')
コード例 #60
0
ファイル: tribler_window.py プロジェクト: yanheven/tribler
    def on_tribler_started(self):
        self.tribler_started = True

        self.top_menu_button.setHidden(False)
        self.left_menu.setHidden(False)
        self.token_balance_widget.setHidden(False)
        self.settings_button.setHidden(False)
        self.add_torrent_button.setHidden(False)
        self.top_search_bar.setHidden(False)

        # fetch the settings, needed for the video player port
        self.request_mgr = TriblerRequestManager()
        self.fetch_settings()

        self.downloads_page.start_loading_downloads()
        self.home_page.load_popular_torrents()
        if not self.gui_settings.value("first_discover", False) and not self.core_manager.use_existing_core:
            self.window().gui_settings.setValue("first_discover", True)
            self.discovering_page.is_discovering = True
            self.stackedWidget.setCurrentIndex(PAGE_DISCOVERING)
        else:
            self.clicked_menu_button_home()