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))
Esempio n. 2
0
    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())
Esempio n. 3
0
    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))
Esempio n. 4
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))
Esempio n. 5
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))
Esempio n. 6
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))
Esempio n. 7
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))
Esempio n. 8
0
    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())
Esempio n. 9
0
    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))
Esempio n. 10
0
    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))
Esempio n. 11
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())
Esempio n. 12
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())