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")
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)
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")
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)