コード例 #1
0
    def on_right_click_file_item(self, pos):
        num_selected = len(self.window().download_files_list.selectedItems())
        if num_selected == 0:
            return

        item_infos = []  # Array of (item, included, is_selected)
        selected_files_info = []

        for i in range(self.window().download_files_list.topLevelItemCount()):
            item = self.window().download_files_list.topLevelItem(i)
            is_selected = item in self.window(
            ).download_files_list.selectedItems()
            item_infos.append((item, item.file_info["included"], is_selected))

            if is_selected:
                selected_files_info.append(item.file_info)

        item_clicked = self.window().download_files_list.itemAt(pos)
        if not item_clicked or not item_clicked in self.window(
        ).download_files_list.selectedItems():
            return

        # Check whether we should enable the 'exclude' button
        num_excludes = 0
        num_includes_selected = 0
        for item_info in item_infos:
            if item_info[1] and item_info[0] in self.window(
            ).download_files_list.selectedItems():
                num_includes_selected += 1
            if not item_info[1]:
                num_excludes += 1

        menu = TriblerActionMenu(self)

        include_action = QAction(
            'Include file' + ('(s)' if num_selected > 1 else ''), self)
        exclude_action = QAction(
            'Exclude file' + ('(s)' if num_selected > 1 else ''), self)

        include_action.triggered.connect(
            lambda: self.on_files_included(selected_files_info))
        include_action.setEnabled(True)
        exclude_action.triggered.connect(
            lambda: self.on_files_excluded(selected_files_info))
        exclude_action.setEnabled(not (
            num_excludes + num_includes_selected == len(item_infos)))

        menu.addAction(include_action)
        menu.addAction(exclude_action)

        if (len(selected_files_info) == 1
                and is_video_file(selected_files_info[0]['name'])
                and self.window().vlc_available):
            play_action = QAction('Play', self)
            play_action.triggered.connect(
                lambda: self.on_play_file(selected_files_info[0]))
            menu.addAction(play_action)

        menu.exec_(self.window().download_files_list.mapToGlobal(pos))
コード例 #2
0
ファイル: tribler_window.py プロジェクト: wsxy162/tribler
    def create_add_torrent_menu(self, menu=None):
        """
        Create a menu to add new torrents. Shows when users click on the tray icon or the big plus button.
        """
        menu = menu if menu is not None else TriblerActionMenu(self)

        browse_files_action = QAction(tr("Import torrent from file"), self)
        browse_directory_action = QAction(
            tr("Import torrent(s) from directory"), self)
        add_url_action = QAction(tr("Import torrent from magnet/URL"), self)
        create_torrent_action = QAction(tr("Create torrent from file(s)"),
                                        self)

        connect(browse_files_action.triggered, self.on_add_torrent_browse_file)
        connect(browse_directory_action.triggered,
                self.on_add_torrent_browse_dir)
        connect(add_url_action.triggered, self.on_add_torrent_from_url)
        connect(create_torrent_action.triggered, self.on_create_torrent)

        menu.addAction(browse_files_action)
        menu.addAction(browse_directory_action)
        menu.addAction(add_url_action)
        menu.addSeparator()
        menu.addAction(create_torrent_action)

        return menu
コード例 #3
0
    def create_channel_options_menu(self):
        browse_files_action = QAction(tr("Add .torrent file"), self)
        browse_dir_action = QAction(tr("Add torrent(s) directory"), self)
        add_url_action = QAction(tr("Add URL/magnet links"), self)

        connect(browse_files_action.triggered, self.on_add_torrent_browse_file)
        connect(browse_dir_action.triggered, self.on_add_torrents_browse_dir)
        connect(add_url_action.triggered, self.on_add_torrent_from_url)

        channel_options_menu = TriblerActionMenu(self)
        channel_options_menu.addAction(browse_files_action)
        channel_options_menu.addAction(browse_dir_action)
        channel_options_menu.addAction(add_url_action)
        return channel_options_menu
コード例 #4
0
ファイル: marketwalletspage.py プロジェクト: hbiyik/tribler
    def on_add_wallet_clicked(self):
        menu = TriblerActionMenu(self)

        for wallet_id in self.wallets_to_create:
            wallet_action = QAction(self.wallets[wallet_id]['name'], self)
            wallet_action.triggered.connect(
                lambda _, wid=wallet_id: self.should_create_wallet(wid))
            menu.addAction(wallet_action)

        menu.exec_(QCursor.pos())
コード例 #5
0
    def create_personal_menu(self):
        menu = TriblerActionMenu(self)
        delete_action = QAction(tr("Delete channel"), self)
        connect(delete_action.triggered, self._on_delete_action)
        menu.addAction(delete_action)

        rename_action = QAction(tr("Rename channel"), self)
        connect(rename_action.triggered, self._trigger_name_editor)
        menu.addAction(rename_action)
        return menu
コード例 #6
0
ファイル: feedbackdialog.py プロジェクト: wsxy162/tribler
    def on_right_click_item(self, pos):
        item_clicked = self.env_variables_list.itemAt(pos)
        if not item_clicked:
            return

        self.selected_item_index = self.env_variables_list.indexOfTopLevelItem(item_clicked)

        menu = TriblerActionMenu(self)

        remove_action = QAction(tr("Remove entry"), self)
        connect(remove_action.triggered, self.on_remove_entry)
        menu.addAction(remove_action)
        menu.exec_(self.env_variables_list.mapToGlobal(pos))
コード例 #7
0
    def on_right_click_file_item(self, pos):
        item_clicked = self.dialog_widget.create_torrent_files_list.itemAt(pos)
        if not item_clicked:
            return

        selected_item_index = self.dialog_widget.create_torrent_files_list.row(item_clicked)

        remove_action = QAction(tr("Remove file"), self)
        connect(remove_action.triggered, lambda index=selected_item_index: self.on_remove_entry(index))

        menu = TriblerActionMenu(self)
        menu.addAction(remove_action)
        menu.exec_(self.dialog_widget.create_torrent_files_list.mapToGlobal(pos))
コード例 #8
0
    def on_right_click_file_item(self, pos):
        num_selected = len(self.window().download_files_list.selectedItems())
        if num_selected == 0:
            return

        item_infos = []  # Array of (item, included, is_selected)
        self.selected_files_info = []

        for i in range(self.window().download_files_list.topLevelItemCount()):
            item = self.window().download_files_list.topLevelItem(i)
            is_selected = item in self.window(
            ).download_files_list.selectedItems()
            item_infos.append((item, item.file_info["included"], is_selected))

            if is_selected:
                self.selected_files_info.append(item.file_info)

        item_clicked = self.window().download_files_list.itemAt(pos)
        if not item_clicked or not item_clicked in self.window(
        ).download_files_list.selectedItems():
            return

        # Check whether we should enable the 'exclude' button
        num_excludes = 0
        num_includes_selected = 0
        for item_info in item_infos:
            if item_info[1] and item_info[0] in self.window(
            ).download_files_list.selectedItems():
                num_includes_selected += 1
            if not item_info[1]:
                num_excludes += 1

        menu = TriblerActionMenu(self)

        include_action = QAction(
            tr("Include files") if num_selected > 1 else tr("Include file"),
            self)
        exclude_action = QAction(
            tr("Exclude files") if num_selected > 1 else tr("Exclude file"),
            self)

        connect(include_action.triggered, self.on_files_included)
        include_action.setEnabled(True)
        connect(exclude_action.triggered, self.on_files_excluded)
        exclude_action.setEnabled(not (
            num_excludes + num_includes_selected == len(item_infos)))

        menu.addAction(include_action)
        menu.addAction(exclude_action)

        menu.exec_(self.window().download_files_list.mapToGlobal(pos))
コード例 #9
0
    def on_right_click_file_item(self, pos):
        item_clicked = self.window().create_torrent_files_list.itemAt(pos)
        if not item_clicked:
            return

        self.selected_item_index = self.window().create_torrent_files_list.row(
            item_clicked)

        menu = TriblerActionMenu(self)

        remove_action = QAction('Remove file', self)
        connect(remove_action.triggered, self.on_remove_entry)
        menu.addAction(remove_action)
        menu.exec_(self.window().create_torrent_files_list.mapToGlobal(pos))
コード例 #10
0
    def on_right_click_order(self, pos):
        item_clicked = self.window().market_orders_list.itemAt(pos)
        if not item_clicked:
            return

        self.selected_item = item_clicked

        if self.selected_item.order[
                'status'] == 'open':  # We can only cancel an open order
            menu = TriblerActionMenu(self)
            cancel_action = QAction('Cancel order', self)
            cancel_action.triggered.connect(self.on_cancel_order_clicked)
            menu.addAction(cancel_action)
            menu.exec_(self.window().market_orders_list.mapToGlobal(pos))
コード例 #11
0
ファイル: marketpage.py プロジェクト: hbiyik/tribler
    def on_asset_type_clicked(self):
        menu = TriblerActionMenu(self)

        asset_pairs = []
        for first_wallet_id in self.wallets.keys():
            for second_wallet_id in self.wallets.keys():
                if first_wallet_id >= second_wallet_id:
                    continue
                asset_pairs.append((first_wallet_id, second_wallet_id))

        for asset_pair in sorted(asset_pairs):
            wallet_action = QAction('%s / %s' % asset_pair, self)
            wallet_action.triggered.connect(lambda _, id1=asset_pair[
                0], id2=asset_pair[1]: self.on_asset_type_changed(id1, id2))
            menu.addAction(wallet_action)
        menu.exec_(QCursor.pos())
コード例 #12
0
 def create_foreign_menu(self):
     menu = TriblerActionMenu(self)
     unsubscribe_action = QAction(tr("Unsubscribe"), self)
     connect(unsubscribe_action.triggered, self._on_unsubscribe_action)
     menu.addAction(unsubscribe_action)
     return menu
コード例 #13
0
    def _show_context_menu(self, pos):
        if not self.table_view or not self.model:
            return

        item_index = self.table_view.indexAt(pos)
        if not item_index or item_index.row() < 0:
            return

        menu = TriblerActionMenu(self.table_view)

        # Single selection menu items
        num_selected = len(self.table_view.selectionModel().selectedRows())
        if num_selected == 1 and item_index.model().data_items[
                item_index.row()]["type"] == REGULAR_TORRENT:
            self.add_menu_item(menu, tr(" Download "), item_index,
                               self.table_view.start_download_from_index)
            if issubclass(type(self), HealthCheckerMixin):
                self.add_menu_item(
                    menu,
                    tr(" Recheck health"),
                    item_index.model().data_items[item_index.row()],
                    lambda x: self.check_torrent_health(x, forced=True),
                )
        if num_selected == 1 and item_index.model().column_position.get(
                Column.SUBSCRIBED) is not None:
            data_item = item_index.model().data_items[item_index.row()]
            if data_item["type"] == CHANNEL_TORRENT and data_item[
                    "state"] != CHANNEL_STATE.PERSONAL.value:
                self.add_menu_item(
                    menu,
                    tr("Unsubscribe channel")
                    if data_item["subscribed"] else tr("Subscribe channel"),
                    item_index.model().index(
                        item_index.row(),
                        item_index.model().column_position[Column.SUBSCRIBED]),
                    self.table_view.delegate.subscribe_control.clicked.emit,
                )

        # Add menu separator for channel stuff
        menu.addSeparator()

        entries = [
            self.model.data_items[index.row()]
            for index in self.table_view.selectionModel().selectedRows()
        ]

        def on_add_to_channel(_):
            def on_confirm_clicked(channel_id):
                TriblerNetworkRequest(
                    f"collections/mychannel/{channel_id}/copy",
                    lambda _: self.table_view.window().tray_show_message(
                        tr("Channel update"),
                        tr("Torrent(s) added to your channel")),
                    raw_data=json.dumps(entries),
                    method='POST',
                )

            self.table_view.window().add_to_channel_dialog.show_dialog(
                on_confirm_clicked, confirm_button_text=tr("Copy"))

        def on_move(_):
            def on_confirm_clicked(channel_id):
                changes_list = [{
                    'public_key': entry['public_key'],
                    'id': entry['id'],
                    'origin_id': channel_id
                } for entry in entries]
                self.model.remove_items(entries)
                TriblerNetworkRequest("metadata",
                                      lambda _: None,
                                      raw_data=json.dumps(changes_list),
                                      method='PATCH')

            self.table_view.window().add_to_channel_dialog.show_dialog(
                on_confirm_clicked, confirm_button_text=tr("Move"))

        if not self.model.edit_enabled:
            if self.selection_can_be_added_to_channel():
                self.add_menu_item(menu, tr(" Copy into personal channel"),
                                   item_index, on_add_to_channel)
        else:
            self.add_menu_item(menu, tr(" Move "), item_index, on_move)
            self.add_menu_item(menu, tr(" Rename "), item_index,
                               self._trigger_name_editor)
            self.add_menu_item(menu, tr(" Change category "), item_index,
                               self._trigger_category_editor)
            menu.addSeparator()
            self.add_menu_item(menu, tr(" Remove from channel"), item_index,
                               self.table_view.on_delete_button_clicked)

        menu.exec_(QCursor.pos())
コード例 #14
0
ファイル: tribler_window.py プロジェクト: wsxy162/tribler
    def __init__(self,
                 settings,
                 core_args=None,
                 core_env=None,
                 api_port=None,
                 api_key=None):
        QMainWindow.__init__(self)
        self._logger = logging.getLogger(self.__class__.__name__)

        QCoreApplication.setOrganizationDomain("nl")
        QCoreApplication.setOrganizationName("TUDelft")
        QCoreApplication.setApplicationName("Tribler")

        self.setWindowIcon(QIcon(QPixmap(get_image_path('tribler.png'))))

        self.gui_settings = settings
        api_port = api_port or int(
            get_gui_setting(self.gui_settings, "api_port", DEFAULT_API_PORT))
        api_key = api_key or get_gui_setting(
            self.gui_settings, "api_key",
            hexlify(os.urandom(16)).encode('utf-8'))
        self.gui_settings.setValue("api_key", api_key)

        api_port = get_first_free_port(start=api_port, limit=100)
        request_manager.port, request_manager.key = api_port, api_key

        self.tribler_started = False
        self.tribler_settings = None
        # TODO: move version_id to tribler_common and get core version in the core crash message
        self.tribler_version = version_id
        self.debug_window = None

        self.error_handler = ErrorHandler(self)
        self.core_manager = CoreManager(api_port, api_key, self.error_handler)
        self.pending_requests = {}
        self.pending_uri_requests = []
        self.download_uri = None
        self.dialog = None
        self.create_dialog = None
        self.chosen_dir = None
        self.new_version_dialog = None
        self.start_download_dialog_active = False
        self.selected_torrent_files = []
        self.last_search_query = None
        self.last_search_time = None
        self.start_time = time.time()
        self.token_refresh_timer = None
        self.shutdown_timer = None
        self.add_torrent_url_dialog_active = False

        sys.excepthook = self.error_handler.gui_error

        uic.loadUi(get_ui_file_path('mainwindow.ui'), self)
        TriblerRequestManager.window = self
        self.tribler_status_bar.hide()

        self.token_balance_widget.mouseReleaseEvent = self.on_token_balance_click

        def on_state_update(new_state):
            self.loading_text_label.setText(new_state)

        connect(self.core_manager.core_state_update, on_state_update)

        self.magnet_handler = MagnetHandler(self.window)
        QDesktopServices.setUrlHandler("magnet", self.magnet_handler,
                                       "on_open_magnet_link")

        self.debug_pane_shortcut = QShortcut(QKeySequence("Ctrl+d"), self)
        connect(self.debug_pane_shortcut.activated,
                self.clicked_debug_panel_button)
        self.import_torrent_shortcut = QShortcut(QKeySequence("Ctrl+o"), self)
        connect(self.import_torrent_shortcut.activated,
                self.on_add_torrent_browse_file)
        self.add_torrent_url_shortcut = QShortcut(QKeySequence("Ctrl+i"), self)
        connect(self.add_torrent_url_shortcut.activated,
                self.on_add_torrent_from_url)

        connect(self.top_search_bar.clicked, self.clicked_search_bar)
        connect(self.top_search_bar.returnPressed,
                self.on_top_search_bar_return_pressed)

        # Remove the focus rect on OS X
        for widget in self.findChildren(QLineEdit) + self.findChildren(
                QListWidget) + self.findChildren(QTreeWidget):
            widget.setAttribute(Qt.WA_MacShowFocusRect, 0)

        self.menu_buttons = [
            self.left_menu_button_downloads,
            self.left_menu_button_discovered,
            self.left_menu_button_popular,
        ]

        self.search_results_page.initialize(hide_xxx=self.hide_xxx)
        connect(
            self.core_manager.events_manager.received_remote_query_results,
            self.search_results_page.received_remote_results.emit,
        )
        self.settings_page.initialize_settings_page()
        self.downloads_page.initialize_downloads_page()
        self.loading_page.initialize_loading_page()
        self.discovering_page.initialize_discovering_page()

        self.discovered_page.initialize_content_page(hide_xxx=self.hide_xxx)

        self.popular_page.initialize_content_page(
            hide_xxx=self.hide_xxx,
            controller_class=PopularContentTableViewController)

        self.trust_page.initialize_trust_page()
        self.trust_graph_page.initialize_trust_graph()

        self.stackedWidget.setCurrentIndex(PAGE_LOADING)

        # Create the system tray icon
        self.tray_icon = None
        # System tray doesn't make sense on Mac
        if QSystemTrayIcon.isSystemTrayAvailable():
            self.tray_icon = QSystemTrayIcon()
            if not DARWIN:
                connect(self.tray_icon.activated,
                        self.on_system_tray_icon_activated)
            use_monochrome_icon = get_gui_setting(self.gui_settings,
                                                  "use_monochrome_icon",
                                                  False,
                                                  is_bool=True)
            self.update_tray_icon(use_monochrome_icon)

            # Create the tray icon menu
            menu = TriblerActionMenu(self)
            menu.addAction(tr('Show Tribler window'), self.raise_window)
            menu.addSeparator()
            self.create_add_torrent_menu(menu)
            menu.addSeparator()
            menu.addAction(tr('Show downloads'),
                           self.clicked_menu_button_downloads)
            menu.addSeparator()
            menu.addAction(tr('Quit Tribler'), self.close_tribler)
            self.tray_icon.setContextMenu(menu)

        self.debug_panel_button.setHidden(True)
        self.top_menu_button.setHidden(True)
        self.left_menu.setHidden(True)
        self.token_balance_widget.setHidden(True)
        self.settings_button.setHidden(True)
        self.add_torrent_button.setHidden(True)
        self.top_search_bar.setHidden(True)

        # Set various icons
        self.top_menu_button.setIcon(QIcon(get_image_path('menu.png')))

        self.search_completion_model = QStringListModel()
        completer = QCompleter()
        completer.setModel(self.search_completion_model)
        completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
        self.item_delegate = QStyledItemDelegate()
        completer.popup().setItemDelegate(self.item_delegate)
        completer.popup().setStyleSheet("""
        QListView {
            background-color: #404040;
        }

        QListView::item {
            color: #D0D0D0;
            padding-top: 5px;
            padding-bottom: 5px;
        }

        QListView::item:hover {
            background-color: #707070;
        }
        """)
        self.top_search_bar.setCompleter(completer)

        # Start Tribler
        self.core_manager.start(core_args=core_args, core_env=core_env)

        connect(self.core_manager.events_manager.torrent_finished,
                self.on_torrent_finished)
        connect(self.core_manager.events_manager.new_version_available,
                self.on_new_version_available)
        connect(self.core_manager.events_manager.tribler_started,
                self.on_tribler_started)
        connect(self.core_manager.events_manager.low_storage_signal,
                self.on_low_storage)
        connect(self.core_manager.events_manager.tribler_shutdown_signal,
                self.on_tribler_shutdown_state_update)
        connect(self.core_manager.events_manager.config_error_signal,
                self.on_config_error_signal)

        # Install signal handler for ctrl+c events
        def sigint_handler(*_):
            self.close_tribler()

        signal.signal(signal.SIGINT, sigint_handler)

        # Resize the window according to the settings
        center = QApplication.desktop().availableGeometry(self).center()
        pos = self.gui_settings.value(
            "pos",
            QPoint(center.x() - self.width() * 0.5,
                   center.y() - self.height() * 0.5))
        size = self.gui_settings.value("size", self.size())

        self.move(pos)
        self.resize(size)

        self.show()

        self.add_to_channel_dialog = AddToChannelDialog(self.window())

        self.add_torrent_menu = self.create_add_torrent_menu()
        self.add_torrent_button.setMenu(self.add_torrent_menu)

        self.channels_menu_list = self.findChild(ChannelsMenuListWidget,
                                                 "channels_menu_list")

        connect(self.channels_menu_list.itemClicked,
                self.open_channel_contents_page)

        # The channels content page is only used to show subscribed channels, so we always show xxx
        # contents in it.
        connect(
            self.core_manager.events_manager.node_info_updated,
            lambda data: self.channels_menu_list.reload_if_necessary([data]),
        )
        connect(self.left_menu_button_new_channel.clicked,
                self.create_new_channel)
        connect(self.debug_panel_button.clicked,
                self.clicked_debug_panel_button)
        connect(self.trust_graph_button.clicked,
                self.clicked_trust_graph_page_button)
コード例 #15
0
    def _show_context_menu(self, pos):
        if not self.table_view or not self.model:
            return

        item_index = self.table_view.indexAt(pos)
        if not item_index or item_index.row() < 0:
            return

        menu = TriblerActionMenu(self.table_view)

        # Single selection menu items
        num_selected = len(self.table_view.selectionModel().selectedRows())
        if num_selected == 1 and item_index.model().data_items[
                item_index.row()]["type"] == REGULAR_TORRENT:
            self.add_menu_item(menu, ' Download ', item_index,
                               self.table_view.on_download_button_clicked)
            if item_index.model().data_items[
                    item_index.row()][u'category'] == u'Video':
                self.add_menu_item(menu, ' Play ', item_index,
                                   self.table_view.on_play_button_clicked)

        # Add menu separator for channel stuff
        menu.addSeparator()

        entries = [
            self.model.data_items[index.row()]
            for index in self.table_view.selectionModel().selectedRows()
        ]

        def on_add_to_channel(_):
            def on_confirm_clicked(channel_id):
                TriblerNetworkRequest(
                    f"collections/mychannel/{channel_id}/copy",
                    lambda _: self.table_view.window().tray_show_message(
                        "Channel update", "Torrent(s) added to your channel"),
                    raw_data=dumps(entries),
                    method='POST',
                )

            self.table_view.window().add_to_channel_dialog.show_dialog(
                on_confirm_clicked, confirm_button_text="Copy")

        def on_move(_):
            def on_confirm_clicked(channel_id):
                changes_list = [{
                    'public_key': entry['public_key'],
                    'id': entry['id'],
                    'origin_id': channel_id
                } for entry in entries]
                TriblerNetworkRequest("metadata",
                                      self.model.remove_items,
                                      raw_data=dumps(changes_list),
                                      method='PATCH')

            self.table_view.window().add_to_channel_dialog.show_dialog(
                on_confirm_clicked, confirm_button_text="Move")

        if not self.model.edit_enabled:
            if self.selection_can_be_added_to_channel():
                self.add_menu_item(menu, ' Add to My Channel ', item_index,
                                   on_add_to_channel)
        else:
            self.add_menu_item(menu, ' Move ', item_index, on_move)
            self.add_menu_item(menu, ' Rename ', item_index,
                               self._trigger_name_editor)
            self.add_menu_item(menu, ' Change category ', item_index,
                               self._trigger_category_editor)
            menu.addSeparator()
            self.add_menu_item(menu, ' Remove from My Channel ', item_index,
                               self.table_view.on_delete_button_clicked)

        menu.exec_(QCursor.pos())
コード例 #16
0
ファイル: downloadspage.py プロジェクト: hbiyik/tribler
    def on_right_click_item(self, pos):
        item_clicked = self.window().downloads_list.itemAt(pos)
        if not item_clicked or self.selected_items is None:
            return

        if item_clicked not in self.selected_items:
            self.selected_items.append(item_clicked)

        menu = TriblerActionMenu(self)

        start_action = QAction('Start', self)
        stop_action = QAction('Stop', self)
        remove_download_action = QAction('Remove download', self)
        add_to_channel_action = QAction('Add to my channel', self)
        force_recheck_action = QAction('Force recheck', self)
        export_download_action = QAction('Export .torrent file', self)
        explore_files_action = QAction('Explore files', self)
        move_files_action = QAction('Move file storage', self)

        no_anon_action = QAction('No anonymity', self)
        one_hop_anon_action = QAction('One hop', self)
        two_hop_anon_action = QAction('Two hops', self)
        three_hop_anon_action = QAction('Three hops', self)

        start_action.triggered.connect(self.on_start_download_clicked)
        start_action.setEnabled(
            DownloadsPage.start_download_enabled(self.selected_items))
        stop_action.triggered.connect(self.on_stop_download_clicked)
        stop_action.setEnabled(
            DownloadsPage.stop_download_enabled(self.selected_items))
        add_to_channel_action.triggered.connect(self.on_add_to_channel)
        remove_download_action.triggered.connect(
            self.on_remove_download_clicked)
        force_recheck_action.triggered.connect(self.on_force_recheck_download)
        force_recheck_action.setEnabled(
            DownloadsPage.force_recheck_download_enabled(self.selected_items))
        export_download_action.triggered.connect(self.on_export_download)
        explore_files_action.triggered.connect(self.on_explore_files)
        move_files_action.triggered.connect(self.on_move_files)

        no_anon_action.triggered.connect(lambda: self.change_anonymity(0))
        one_hop_anon_action.triggered.connect(lambda: self.change_anonymity(1))
        two_hop_anon_action.triggered.connect(lambda: self.change_anonymity(2))
        three_hop_anon_action.triggered.connect(
            lambda: self.change_anonymity(3))

        menu.addAction(start_action)
        menu.addAction(stop_action)

        if self.window().vlc_available and len(self.selected_items) == 1:
            play_action = QAction('Play', self)
            play_action.triggered.connect(self.on_play_download_clicked)
            menu.addAction(play_action)
        menu.addSeparator()
        menu.addAction(add_to_channel_action)
        menu.addSeparator()
        menu.addAction(remove_download_action)
        menu.addSeparator()
        menu.addAction(force_recheck_action)
        menu.addSeparator()

        exclude_states = [
            DLSTATUS_METADATA,
            DLSTATUS_CIRCUITS,
            DLSTATUS_EXIT_NODES,
            DLSTATUS_HASHCHECKING,
            DLSTATUS_WAITING4HASHCHECK,
        ]
        if len(self.selected_items) == 1 and self.selected_items[
                0].get_raw_download_status() not in exclude_states:
            menu.addAction(export_download_action)
        menu.addAction(explore_files_action)
        if len(self.selected_items) == 1:
            menu.addAction(move_files_action)
        menu.addSeparator()

        menu_anon_level = menu.addMenu("Change Anonymity ")
        menu_anon_level.addAction(no_anon_action)
        menu_anon_level.addAction(one_hop_anon_action)
        menu_anon_level.addAction(two_hop_anon_action)
        menu_anon_level.addAction(three_hop_anon_action)

        menu.exec_(self.window().downloads_list.mapToGlobal(pos))
コード例 #17
0
ファイル: downloadspage.py プロジェクト: ish4ra/tribler
    def on_right_click_item(self, pos):
        item_clicked = self.window().downloads_list.itemAt(pos)
        if not item_clicked or self.selected_items is None:
            return

        if item_clicked not in self.selected_items:
            self.selected_items.append(item_clicked)

        menu = TriblerActionMenu(self)

        start_action = QAction(tr("Start"), self)
        stop_action = QAction(tr("Stop"), self)
        remove_download_action = QAction(tr("Remove download"), self)
        add_to_channel_action = QAction(tr("Add to my channel"), self)
        force_recheck_action = QAction(tr("Force recheck"), self)
        export_download_action = QAction(tr("Export .torrent file"), self)
        explore_files_action = QAction(tr("Explore files"), self)
        move_files_action = QAction(tr("Move file storage"), self)

        no_anon_action = QAction(tr("No anonymity"), self)
        one_hop_anon_action = QAction(tr("One hop"), self)
        two_hop_anon_action = QAction(tr("Two hops"), self)
        three_hop_anon_action = QAction(tr("Three hops"), self)

        connect(start_action.triggered, self.on_start_download_clicked)
        start_action.setEnabled(
            DownloadsPage.start_download_enabled(self.selected_items))
        connect(stop_action.triggered, self.on_stop_download_clicked)
        stop_action.setEnabled(
            DownloadsPage.stop_download_enabled(self.selected_items))
        connect(add_to_channel_action.triggered, self.on_add_to_channel)
        connect(remove_download_action.triggered,
                self.on_remove_download_clicked)
        connect(force_recheck_action.triggered, self.on_force_recheck_download)
        force_recheck_action.setEnabled(
            DownloadsPage.force_recheck_download_enabled(self.selected_items))
        connect(export_download_action.triggered, self.on_export_download)
        connect(explore_files_action.triggered, self.on_explore_files)
        connect(move_files_action.triggered, self.on_move_files)

        connect(no_anon_action.triggered, lambda _: self.change_anonymity(0))
        connect(one_hop_anon_action.triggered,
                lambda _: self.change_anonymity(1))
        connect(two_hop_anon_action.triggered,
                lambda _: self.change_anonymity(2))
        connect(three_hop_anon_action.triggered,
                lambda _: self.change_anonymity(3))

        menu.addAction(start_action)
        menu.addAction(stop_action)

        menu.addSeparator()
        menu.addAction(add_to_channel_action)
        menu.addSeparator()
        menu.addAction(remove_download_action)
        menu.addSeparator()
        menu.addAction(force_recheck_action)
        menu.addSeparator()

        exclude_states = [
            DLSTATUS_METADATA,
            DLSTATUS_CIRCUITS,
            DLSTATUS_EXIT_NODES,
            DLSTATUS_HASHCHECKING,
            DLSTATUS_WAITING4HASHCHECK,
        ]
        if len(self.selected_items) == 1 and self.selected_items[
                0].get_raw_download_status() not in exclude_states:
            menu.addAction(export_download_action)
        menu.addAction(explore_files_action)
        if len(self.selected_items) == 1:
            menu.addAction(move_files_action)
        menu.addSeparator()

        menu_anon_level = menu.addMenu(tr("Change Anonymity "))
        menu_anon_level.addAction(no_anon_action)
        menu_anon_level.addAction(one_hop_anon_action)
        menu_anon_level.addAction(two_hop_anon_action)
        menu_anon_level.addAction(three_hop_anon_action)

        menu.exec_(self.window().downloads_list.mapToGlobal(pos))
コード例 #18
0
    def create_add_torrent_menu(self):
        """
        Create a menu to add new torrents. Shows when users click on the tray icon or the big plus button.
        """
        menu = TriblerActionMenu(self)

        browse_files_action = QAction('Import torrent from file', self)
        browse_directory_action = QAction('Import torrent(s) from directory',
                                          self)
        add_url_action = QAction('Import torrent from magnet/URL', self)
        add_mdblob_action = QAction('Import Tribler metadata from file', self)
        create_torrent_action = QAction('Create torrent from file(s)', self)

        browse_files_action.triggered.connect(self.on_add_torrent_browse_file)
        browse_directory_action.triggered.connect(
            self.on_add_torrent_browse_dir)
        add_url_action.triggered.connect(self.on_add_torrent_from_url)
        add_mdblob_action.triggered.connect(self.on_add_mdblob_browse_file)
        create_torrent_action.triggered.connect(self.on_create_torrent)

        menu.addAction(browse_files_action)
        menu.addAction(browse_directory_action)
        menu.addAction(add_url_action)
        menu.addAction(add_mdblob_action)
        menu.addSeparator()
        menu.addAction(create_torrent_action)

        return menu