示例#1
0
    def perform_start_download_request(
        self,
        uri,
        anon_download,
        safe_seeding,
        destination,
        selected_files,
        total_files=0,
        add_to_channel=False,
        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(), f"Download error <i>{uri}</i>", gui_error_message, "OK")
            return

        selected_files_list = []
        if len(selected_files) != total_files:  # Not all files included
            selected_files_list = [filename for filename in selected_files]

        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": uri,
            "anon_hops": anon_hops,
            "safe_seeding": safe_seeding,
            "destination": destination,
            "selected_files": selected_files_list,
        }
        TriblerNetworkRequest(
            "downloads", callback if callback else self.on_download_added, method='PUT', data=post_data
        )

        self.update_recent_download_locations(destination)

        if add_to_channel:

            def on_add_button_pressed(channel_id):
                post_data = {}
                if uri.startswith("file:"):
                    with open(uri[5:], "rb") as torrent_file:
                        post_data['torrent'] = b64encode(torrent_file.read()).decode('utf8')
                elif uri.startswith("magnet:"):
                    post_data['uri'] = uri

                if post_data:
                    TriblerNetworkRequest(
                        f"channels/mychannel/{channel_id}/torrents",
                        lambda _: self.tray_show_message("Channel update", "Torrent(s) added to your channel"),
                        method='PUT',
                        data=post_data,
                    )

            self.window().add_to_channel_dialog.show_dialog(on_add_button_pressed, confirm_button_text="Add torrent")
示例#2
0
    def on_create_clicked(self):
        if self.dialog_widget.create_torrent_files_list.count() == 0:
            dialog = ConfirmationDialog(
                self.dialog_widget,
                "Warning!",
                "You should add at least one file to your torrent.",
                [('CLOSE', BUTTON_TYPE_NORMAL)],
            )

            dialog.button_clicked.connect(dialog.close_dialog)
            dialog.show()
            return

        self.dialog_widget.btn_create.setEnabled(False)

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

        export_dir = self.dialog_widget.file_export_dir.text()
        if not os.path.exists(export_dir):
            ConfirmationDialog.show_error(
                self.dialog_widget,
                "Cannot save torrent file to %s" % export_dir,
                "Path does not exist")
            return

        is_writable, error = is_dir_writable(export_dir)
        if not is_writable:
            ConfirmationDialog.show_error(
                self.dialog_widget,
                "Cannot save torrent file to %s" % export_dir,
                "Error: %s" % error)
            return

        self.name = self.dialog_widget.create_torrent_name_field.text()
        description = self.dialog_widget.create_torrent_description_field.toPlainText(
        )
        post_data = {
            "name": self.name,
            "description": description,
            "files": files_list,
            "export_dir": export_dir
        }
        url = ("createtorrent?download=1"
               if self.dialog_widget.seed_after_adding_checkbox.isChecked()
               else "createtorrent")
        self.rest_request1 = TriblerNetworkRequest(url,
                                                   self.on_torrent_created,
                                                   data=post_data,
                                                   method='POST')
        self.dialog_widget.edit_channel_create_torrent_progress_label.setText(
            "Creating torrent. Please wait...")
示例#3
0
    def on_choose_log_dir_clicked(self, checked):
        previous_log_dir = self.window().log_location_input.text() or ""
        log_dir = QFileDialog.getExistingDirectory(
            self.window(), "Please select the log directory", previous_log_dir, QFileDialog.ShowDirsOnly
        )

        if not log_dir or log_dir == previous_log_dir:
            return

        is_writable, error = is_dir_writable(log_dir)
        if not is_writable:
            gui_error_message = f"<i>{log_dir}</i> is not writable. [{error}]"
            ConfirmationDialog.show_message(self.window(), "Insufficient Permissions", gui_error_message, "OK")
        else:
            self.window().log_location_input.setText(log_dir)
示例#4
0
    def on_browse_dir_clicked(self):
        chosen_dir = QFileDialog.getExistingDirectory(
            self.window(), "Please select the destination directory of your " "download", "", QFileDialog.ShowDirsOnly
        )

        if len(chosen_dir) != 0:
            self.dialog_widget.destination_input.setCurrentText(chosen_dir)

            is_writable, error = is_dir_writable(chosen_dir)
            if not is_writable:
                gui_error_message = (
                    "Tribler cannot download to <i>%s</i> directory. Please add proper write "
                    "permissions to the directory or choose another download directory. [%s]" % (chosen_dir, error)
                )
                ConfirmationDialog.show_message(self.dialog_widget, "Insufficient Permissions", gui_error_message, "OK")
示例#5
0
 def on_download_clicked(self):
     if self.has_metainfo and len(self.get_selected_files()) == 0:  # User deselected all torrents
         ConfirmationDialog.show_error(
             self.window(), "No files selected", "Please select at least one file to download."
         )
     else:
         download_dir = self.dialog_widget.destination_input.currentText()
         is_writable, error = is_dir_writable(download_dir)
         if not is_writable:
             gui_error_message = (
                 "Tribler cannot download to <i>%s</i> directory. Please add proper write "
                 "permissions to the directory or choose another download directory and try "
                 "to download again. [%s]" % (download_dir, error)
             )
             ConfirmationDialog.show_message(self.dialog_widget, "Insufficient Permissions", gui_error_message, "OK")
         else:
             self.button_clicked.emit(1)