def on_remove_download_clicked(self): self.dialog = ConfirmationDialog(self, "Remove download", "Are you sure you want to remove this download?", [('remove download', BUTTON_TYPE_NORMAL), ('remove download + data', BUTTON_TYPE_NORMAL), ('cancel', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect(self.on_remove_download_dialog) self.dialog.show()
def on_torrents_remove_all_clicked(self): self.dialog = ConfirmationDialog(self.window(), "Remove all torrents", "Are you sure that you want to remove all torrents from your channel? " "You cannot undo this action.", [('CONFIRM', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect(self.on_torrents_remove_all_action) self.dialog.show()
def on_emptying_tokens(self, data): if not data: return json_data = json.dumps(data) if has_qr: self.empty_tokens_barcode_dialog = QWidget() self.empty_tokens_barcode_dialog.setWindowTitle("Please scan the following QR code") self.empty_tokens_barcode_dialog.setGeometry(10, 10, 500, 500) qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=10, border=5, ) qr.add_data(json_data) qr.make(fit=True) img = qr.make_image() # PIL format qim = ImageQt(img) pixmap = QtGui.QPixmap.fromImage(qim).scaled(600, 600, QtCore.Qt.KeepAspectRatio) label = QLabel(self.empty_tokens_barcode_dialog) label.setPixmap(pixmap) self.empty_tokens_barcode_dialog.resize(pixmap.width(), pixmap.height()) self.empty_tokens_barcode_dialog.show() else: ConfirmationDialog.show_error(self.window(), DEPENDENCY_ERROR_TITLE, DEPENDENCY_ERROR_MESSAGE)
def on_playlist_remove_clicked(self, item): self.dialog = ConfirmationDialog(self, "Remove selected playlist", "Are you sure that you want to remove the selected playlist " "from your channel?", [('CONFIRM', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect(lambda action: self.on_playlist_remove_selected_action(item, action)) self.dialog.show()
def on_emptying_tokens(self, data): json_data = json.dumps(data) if has_qr: self.empty_tokens_barcode_dialog = QWidget() self.empty_tokens_barcode_dialog.setWindowTitle( "Please scan the following QR code") self.empty_tokens_barcode_dialog.setGeometry(10, 10, 500, 500) qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=10, border=5, ) qr.add_data(json_data) qr.make(fit=True) img = qr.make_image() # PIL format qim = ImageQt(img) pixmap = QtGui.QPixmap.fromImage(qim).scaled( 600, 600, QtCore.Qt.KeepAspectRatio) label = QLabel(self.empty_tokens_barcode_dialog) label.setPixmap(pixmap) self.empty_tokens_barcode_dialog.resize(pixmap.width(), pixmap.height()) self.empty_tokens_barcode_dialog.show() else: ConfirmationDialog.show_error(self.window(), DEPENDENCY_ERROR_TITLE, DEPENDENCY_ERROR_MESSAGE)
def confirm_partially_empty_tokens(self, action): tokens = self.empty_partial_tokens_dialog.dialog_widget.dialog_input.text( ) self.empty_partial_tokens_dialog.close_dialog() self.empty_partial_tokens_dialog = None if action == 0: try: tokens = int(float(tokens)) except ValueError: ConfirmationDialog.show_error( self.window(), "Wrong input", "The provided amount is not a number") return self.confirm_empty_tokens_dialog = ConfirmationDialog( self, "Empty tokens into another account", "Are you sure you want to empty %d bandwidth tokens " "into another account? " "Warning: one-way action that cannot be revered" % tokens, [('EMPTY', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)]) self.confirm_empty_tokens_dialog.button_clicked.connect( lambda action2: self.on_confirm_partially_empty_tokens( action2, tokens)) self.confirm_empty_tokens_dialog.show()
def start_download_from_uri(self, uri): self.download_uri = uri if get_gui_setting(self.gui_settings, "ask_download_settings", True, is_bool=True): # If tribler settings is not available, fetch the settings and inform the user to try again. if not self.tribler_settings: self.fetch_settings() ConfirmationDialog.show_error(self, "Download Error", "Tribler settings is not available yet. " "Fetching it now. Please try again later.") return # Clear any previous dialog if exists if self.dialog: self.dialog.close_dialog() self.dialog = None self.dialog = StartDownloadDialog(self, self.download_uri) self.dialog.button_clicked.connect(self.on_start_download_action) self.dialog.show() self.start_download_dialog_active = True else: # In the unlikely scenario that tribler settings are not available yet, try to fetch settings again and # add the download uri back to self.pending_uri_requests to process again. if not self.tribler_settings: self.fetch_settings() if self.download_uri not in self.pending_uri_requests: self.pending_uri_requests.append(self.download_uri) return self.window().perform_start_download_request(self.download_uri, self.window().tribler_settings['download_defaults'][ 'anonymity_enabled'], self.window().tribler_settings['download_defaults'][ 'safeseeding_enabled'], self.tribler_settings['download_defaults']['saveas'], [], 0) self.process_uri_request()
def on_start_download_action(self, action): if action == 1: if self.dialog and self.dialog.dialog_widget: self.window().perform_start_download_request( self.download_uri, self.dialog.dialog_widget.anon_download_checkbox.isChecked( ), self.dialog.dialog_widget.safe_seed_checkbox.isChecked(), self.dialog.dialog_widget.destination_input.currentText(), self.dialog.get_selected_files(), self.dialog.dialog_widget.files_list_view. topLevelItemCount()) else: ConfirmationDialog.show_error( self, "Tribler UI Error", "Something went wrong. Please try again.") logging.exception( "Error while trying to download. Either dialog or dialog.dialog_widget is None" ) self.dialog.request_mgr.cancel_request( ) # To abort the torrent info request self.dialog.close_dialog() self.dialog = None self.start_download_dialog_active = False if action == 0: # We do this after removing the dialog since process_uri_request is blocking self.process_uri_request()
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 files_str = u"" for ind in xrange(self.window().create_torrent_files_list.count()): files_str += u"files[]=%s&" % urllib.quote_plus(self.window( ).create_torrent_files_list.item(ind).text().encode('utf-8')) name = urllib.quote_plus( self.window().create_torrent_name_field.text().encode('utf-8')) description = urllib.quote_plus(self.window( ).create_torrent_description_field.toPlainText().encode('utf-8')) post_data = (u"%s&name=%s&description=%s" % (files_str[:-1], name, description)).encode('utf-8') 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()
def on_rss_feed_add_clicked(self): self.dialog = ConfirmationDialog(self, "Add RSS feed", "Please enter the RSS feed URL in the field below:", [('ADD', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)], show_input=True) self.dialog.dialog_widget.dialog_input.setPlaceholderText('RSS feed URL') self.dialog.button_clicked.connect(self.on_rss_feed_dialog_added) self.dialog.show()
def on_rss_feeds_remove_selected_clicked(self): self.dialog = ConfirmationDialog( self, "Remove RSS feed", "Are you sure you want to remove the selected RSS feed?", [('REMOVE', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect(self.on_rss_feed_dialog_removed) self.dialog.show()
def on_cancel_order_clicked(self): self.dialog = ConfirmationDialog( self, "Cancel order", "Are you sure you want to cancel the order with id %s?" % self.selected_item.order['order_number'], [('NO', BUTTON_TYPE_NORMAL), ('YES', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect(self.on_confirm_cancel_order) self.dialog.show()
def on_add_torrent_from_url(self): self.dialog = ConfirmationDialog(self, "Add torrent from URL/magnet link", "Please enter the URL/magnet link in the field below:", [('ADD', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)], show_input=True) self.dialog.dialog_widget.dialog_input.setPlaceholderText('URL/magnet link') self.dialog.button_clicked.connect(self.on_torrent_from_url_dialog_done) self.dialog.show()
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))
def on_torrent_remove_clicked(self, item): self.dialog = ConfirmationDialog( self, "Remove selected torrent", "Are you sure that you want to remove the selected torrent from this channel?", [('CONFIRM', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect( lambda action: self.on_torrents_remove_selected_action( action, item)) self.dialog.show()
def on_payment(self, payment): if not payment["success"]: # Error occurred during payment main_text = "Transaction with id %s failed." % payment["transaction_number"] self.window().tray_show_message("Transaction failed", main_text) ConfirmationDialog.show_error(self.window(), "Transaction failed", main_text) self.window().hide_status_bar() else: self.window().show_status_bar("Transaction in process, please don't close Tribler.")
def __init__(self, title, main_text): super(CustomConfDialog, self).__init__() self.setObjectName("Tribler") self.setWindowTitle("Tribler: Critical Error!") self.resize(500, 300) dlg = ConfirmationDialog(self, title, main_text, [('CLOSE', BUTTON_TYPE_NORMAL)]) dlg.show() dlg.button_clicked.connect(lambda: sys.exit(1))
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
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_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 } 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, six.text_type): destination = destination.encode('utf-8') encoded_destination = hexlify(destination) 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))
def on_rss_feeds_remove_selected_clicked(self): if len(self.window().edit_channel_rss_feeds_list.selectedItems()) == 0: ConfirmationDialog.show_message(self, "Remove RSS Feeds", "Selection is empty. Please select the feeds to remove.", "OK") return self.dialog = ConfirmationDialog(self, "Remove RSS feed", "Are you sure you want to remove the selected RSS feed?", [('REMOVE', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect(self.on_rss_feed_dialog_removed) self.dialog.show()
def save_to_file(self, filename, data): base_dir = QFileDialog.getExistingDirectory(self, "Select an export directory", "", QFileDialog.ShowDirsOnly) if len(base_dir) > 0: dest_path = os.path.join(base_dir, filename) try: torrent_file = open(dest_path, "wb") torrent_file.write(json.dumps(data)) torrent_file.close() except IOError as exc: ConfirmationDialog.show_error(self.window(), "Error exporting file", str(exc))
def on_memory_dump_data_available(self, filename, data): dest_path = os.path.join(self.export_dir, filename) try: memory_dump_file = open(dest_path, "wb") memory_dump_file.write(data) memory_dump_file.close() except IOError as exc: ConfirmationDialog.show_error(self.window(), "Error when exporting file", "An error occurred when exporting the torrent file: %s" % str(exc))
def show_error(self, error_text): main_text = "An error occurred during the request:\n\n%s" % error_text error_dialog = ConfirmationDialog(TriblerRequestManager.window, "Request error", main_text, [('CLOSE', BUTTON_TYPE_NORMAL)]) def on_close(): error_dialog.setParent(None) error_dialog.button_clicked.connect(on_close) error_dialog.show()
def show_error(self, error_text): main_text = "An error occurred during the request:\n\n%s" % error_text error_dialog = ConfirmationDialog(TriblerRequestManager.window, "Request error", main_text, [('CLOSE', BUTTON_TYPE_NORMAL)]) def on_close(): error_dialog.close_dialog() error_dialog.button_clicked.connect(on_close) error_dialog.show()
def on_playlist_torrent_remove_clicked(self, item): self.dialog = ConfirmationDialog( self, "Remove selected torrent from playlist", "Are you sure that you want to remove the selected torrent " "from this playlist?", [('confirm', BUTTON_TYPE_NORMAL), ('cancel', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect( lambda action: self.on_playlist_torrent_remove_selected_action( item, action)) self.dialog.show()
def confirm_fully_empty_tokens(self): self.confirm_empty_tokens_dialog = ConfirmationDialog( self, "Empty tokens into another account", "Are you sure you want to empty ALL bandwidth tokens " "into another account? " "Warning: one-way action that cannot be revered", [('EMPTY', BUTTON_TYPE_CONFIRM), ('CANCEL', BUTTON_TYPE_NORMAL)]) self.confirm_empty_tokens_dialog.button_clicked.connect( self.on_confirm_fully_empty_tokens) self.confirm_empty_tokens_dialog.show()
def on_export_download_request_done(dest_path, data): try: torrent_file = open(dest_path, "wb") torrent_file.write(data) torrent_file.close() except IOError as exc: ConfirmationDialog.show_error(self.window(), "Error when exporting file", "An error occurred when exporting the torrent file: %s" % str(exc)) else: self.window().tray_show_message("Torrent file exported", "Torrent file exported to %s" % dest_path)
def on_new_version_available(self, version): if version == str(self.gui_settings.value('last_reported_version')): return self.new_version_dialog = ConfirmationDialog(self, "New version available", "Version %s of Tribler is available.Do you want to visit the " "website to download the newest version?" % version, [('IGNORE', BUTTON_TYPE_NORMAL), ('LATER', BUTTON_TYPE_NORMAL), ('OK', BUTTON_TYPE_NORMAL)]) self.new_version_dialog.button_clicked.connect(lambda action: self.on_new_version_dialog_done(version, action)) self.new_version_dialog.show()
def on_add_torrent_from_url(self): # Make sure that the window is visible (this action might be triggered from the tray icon) self.raise_window() self.dialog = ConfirmationDialog(self, "Add torrent from URL/magnet link", "Please enter the URL/magnet link in the field below:", [('ADD', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)], show_input=True) self.dialog.dialog_widget.dialog_input.setPlaceholderText('URL/magnet link') self.dialog.dialog_widget.dialog_input.setFocus() self.dialog.button_clicked.connect(self.on_torrent_from_url_dialog_done) self.dialog.show()
def on_settings_saved(self, _): # Now save the GUI settings self.window().gui_settings.setValue("ask_download_settings", self.window().always_ask_location_checkbox.isChecked()) self.window().gui_settings.setValue("use_monochrome_icon", self.window().use_monochrome_icon_checkbox.isChecked()) self.saved_dialog = ConfirmationDialog(TriblerRequestManager.window, "Settings saved", "Your settings have been saved.", [('CLOSE', BUTTON_TYPE_NORMAL)]) self.saved_dialog.button_clicked.connect(self.on_dialog_cancel_clicked) self.saved_dialog.show() self.window().fetch_settings()
def on_export_download_request_done(self, filename, data): dest_path = os.path.join(self.export_dir, filename) try: torrent_file = open(dest_path, "wb") torrent_file.write(data) torrent_file.close() except IOError as exc: ConfirmationDialog.show_error(self.window(), "Error when exporting file", "An error occurred when exporting the torrent file: %s" % str(exc)) else: self.window().tray_show_message("Torrent file exported", "Torrent file exported to %s" % dest_path)
def on_add_torrent_browse_dir(self): chosen_dir = QFileDialog.getExistingDirectory(self, "Please select the directory containing the .torrent files", "", QFileDialog.ShowDirsOnly) if len(chosen_dir) != 0: self.selected_torrent_files = [torrent_file for torrent_file in glob.glob(chosen_dir + "/*.torrent")] self.dialog = ConfirmationDialog(self, "Add torrents from directory", "Are you sure you want to add %d torrents to Tribler?" % len(self.selected_torrent_files), [('ADD', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect(self.on_confirm_add_directory_dialog) self.dialog.show()
def save_to_file(self, filename, data): base_dir = QFileDialog.getExistingDirectory( self, "Select an export directory", "", QFileDialog.ShowDirsOnly) if len(base_dir) > 0: dest_path = os.path.join(base_dir, filename) try: torrent_file = open(dest_path, "wb") torrent_file.write(json.dumps(data)) torrent_file.close() except IOError as exc: ConfirmationDialog.show_error(self.window(), "Error exporting file", str(exc))
def on_memory_dump_data_available(self, filename, data): if not data: return dest_path = os.path.join(self.export_dir, filename) try: memory_dump_file = open(dest_path, "wb") memory_dump_file.write(data) memory_dump_file.close() except IOError as exc: ConfirmationDialog.show_error(self.window(), "Error when exporting file", "An error occurred when exporting the torrent file: %s" % str(exc))
def on_files_list_loaded(self): if self.active_index == -1: largest_index, largest_file = self.window().left_menu_playlist.get_largest_file() if not largest_file: # We don't have a media file in this torrent. Reset everything and show an error ConfirmationDialog.show_error(self.window(), "No media files", "This download contains no media files.") self.window().hide_left_menu_playlist() return self.active_index = largest_index self.play_active_item()
def partially_empty_tokens(self): self.empty_partial_tokens_dialog = ConfirmationDialog(self, "Empty tokens into another account", "Specify the amount of bandwidth tokens to empty into " "another account below:", [ ('EMPTY', BUTTON_TYPE_CONFIRM), ('CANCEL', BUTTON_TYPE_NORMAL) ], show_input=True) self.empty_partial_tokens_dialog.dialog_widget.dialog_input.setPlaceholderText( 'Please enter the amount of tokens in MB') self.empty_partial_tokens_dialog.dialog_widget.dialog_input.setFocus() self.empty_partial_tokens_dialog.button_clicked.connect(self.confirm_partially_empty_tokens) self.empty_partial_tokens_dialog.show()
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 show_new_order_dialog(self, is_ask): if not self.wallets[self.chosen_wallets[0]]['created']: ConfirmationDialog.show_error(self.window(), "Wallet not available", "%s wallet not available, please create it first." % self.chosen_wallets[0]) return elif not self.wallets[self.chosen_wallets[1]]['created']: ConfirmationDialog.show_error(self.window(), "Wallet not available", "%s wallet not available, please create it first." % self.chosen_wallets[1]) return self.dialog = NewMarketOrderDialog(self.window().stackedWidget, is_ask, self.chosen_wallets[0], self.chosen_wallets[1], self.wallets) self.dialog.button_clicked.connect(self.on_new_order_action) self.dialog.show()
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)
def on_low_storage(self): """ Dealing with low storage space available. First stop the downloads and the core manager and ask user to user to make free space. :return: """ self.downloads_page.stop_loading_downloads() self.core_manager.stop(False) close_dialog = ConfirmationDialog(self.window(), "<b>CRITICAL ERROR</b>", "You are running low on disk space (<100MB). Please make sure to have " "sufficient free space available and restart Tribler again.", [("Close Tribler", BUTTON_TYPE_NORMAL)]) close_dialog.button_clicked.connect(lambda _: self.close_tribler()) close_dialog.show()
def on_choose_log_dir_clicked(self): 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 = "<i>%s</i> is not writable. [%s]" % (log_dir, error) ConfirmationDialog.show_message(self.window(), "Insufficient Permissions", gui_error_message, "OK") else: self.window().log_location_input.setText(log_dir)
def on_cancel_order_clicked(self): self.dialog = ConfirmationDialog(self, "Cancel order", "Are you sure you want to cancel the order with id %s?" % self.selected_item.order['order_number'], [('NO', BUTTON_TYPE_NORMAL), ('YES', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect(self.on_confirm_cancel_order) self.dialog.show()
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()
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)) elif scanner: scanner.dump_all_objects(os.path.join(self.export_dir, filename)) else: ConfirmationDialog.show_error(self.window(), "Error when performing a memory dump", "meliae memory dumper is not compatible with Python 3")
def on_torrents_remove_selected_clicked(self): num_selected = len(self.my_channel_torrents_list.selectedItems()) if num_selected == 0: return self.dialog = ConfirmationDialog(self, "Remove %s selected torrents" % num_selected, "Are you sure that you want to remove %s selected torrents from your channel?" % num_selected) self.dialog.button_clicked.connect(self.on_torrents_remove_selected_action) self.dialog.show()
def on_torrent_remove_clicked(self, item): if "chant" in self.channel_overview: self.on_torrents_remove_selected_action(0, item) return self.dialog = ConfirmationDialog(self, "Remove selected torrent", "Are you sure that you want to remove the selected torrent from this channel?", [('CONFIRM', BUTTON_TYPE_NORMAL), ('CANCEL', BUTTON_TYPE_CONFIRM)]) self.dialog.button_clicked.connect(lambda action: self.on_torrents_remove_selected_action(action, item)) self.dialog.show()
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 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_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 } 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, six.text_type): destination = destination.encode('utf-8') encoded_destination = hexlify(destination) 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))
def on_start_download_action(self, action): if action == 1: if self.dialog and self.dialog.dialog_widget: self.window().perform_start_download_request( self.download_uri, self.dialog.dialog_widget.anon_download_checkbox.isChecked(), self.dialog.dialog_widget.safe_seed_checkbox.isChecked(), self.dialog.dialog_widget.destination_input.currentText(), self.dialog.get_selected_files(), self.dialog.dialog_widget.files_list_view.topLevelItemCount()) else: ConfirmationDialog.show_error(self, "Tribler UI Error", "Something went wrong. Please try again.") logging.exception("Error while trying to download. Either dialog or dialog.dialog_widget is None") if self.dialog: self.dialog.close_dialog() self.dialog = None self.start_download_dialog_active = False if action == 0: # We do this after removing the dialog since process_uri_request is blocking self.process_uri_request()
def confirm_fully_empty_tokens(self): self.confirm_empty_tokens_dialog = ConfirmationDialog(self, "Empty tokens into another account", "Are you sure you want to empty ALL bandwidth tokens " "into another account? " "Warning: one-way action that cannot be revered", [ ('EMPTY', BUTTON_TYPE_CONFIRM), ('CANCEL', BUTTON_TYPE_NORMAL) ]) self.confirm_empty_tokens_dialog.button_clicked.connect(self.on_confirm_fully_empty_tokens) self.confirm_empty_tokens_dialog.show()