def on_download_clicked(self): gui_settings = self.window().gui_settings self.download_uri = quote_plus( (u"magnet:?xt=urn:btih:%s&dn=%s" % (self.torrent_info["infohash"], self.torrent_info['name'])).encode('utf-8')) if get_gui_setting(gui_settings, "ask_download_settings", True, is_bool=True): self.dialog = StartDownloadDialog(self.window().stackedWidget, self.download_uri, self.torrent_info["name"]) self.dialog.button_clicked.connect(self.on_start_download_action) self.dialog.show() else: self.window().perform_start_download_request( self.download_uri, get_gui_setting(gui_settings, "default_anonymity_enabled", True, is_bool=True), get_gui_setting(gui_settings, "default_safeseeding_enabled", True, is_bool=True), self.window().tribler_settings['downloadconfig']['saveas'], [], 0)
def __init__(self, parent, download_uri, torrent_name): DialogContainer.__init__(self, parent) self.download_uri = download_uri gui_settings = self.window().gui_settings uic.loadUi(get_ui_file_path('startdownloaddialog.ui'), self.dialog_widget) self.dialog_widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) self.dialog_widget.browse_dir_button.clicked.connect(self.on_browse_dir_clicked) self.dialog_widget.cancel_button.clicked.connect(lambda: self.button_clicked.emit(0)) self.dialog_widget.download_button.clicked.connect(lambda: self.button_clicked.emit(1)) if self.window().tribler_settings: self.dialog_widget.destination_input.setText(self.window().tribler_settings['downloadconfig']['saveas']) self.dialog_widget.torrent_name_label.setText(torrent_name) self.dialog_widget.safe_seed_checkbox.setChecked(get_gui_setting(gui_settings, "default_safeseeding_enabled", True, is_bool=True)) self.dialog_widget.anon_download_checkbox.setChecked(get_gui_setting(gui_settings, "default_anonymity_enabled", True, is_bool=True)) self.dialog_widget.safe_seed_checkbox.setEnabled(self.dialog_widget.anon_download_checkbox.isChecked()) self.dialog_widget.anon_download_checkbox.stateChanged.connect(self.on_anon_download_state_changed) self.perform_files_request() self.dialog_widget.files_list_view.setHidden(True) self.dialog_widget.adjustSize() self.on_main_window_resize()
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): self.dialog = StartDownloadDialog(self.window().stackedWidget, self.download_uri) self.dialog.button_clicked.connect(self.on_start_download_action) self.dialog.show() self.start_download_dialog_active = True else: self.window().perform_start_download_request( self.download_uri, get_gui_setting(self.gui_settings, "default_anonymity_enabled", True, is_bool=True), get_gui_setting(self.gui_settings, "default_safeseeding_enabled", True, is_bool=True), self.tribler_settings['downloadconfig']['saveas'], [], 0) self.process_uri_request()
def on_play_button_clicked(self): gui_settings = self.window().gui_settings self.download_uri = (u"magnet:?xt=urn:btih:%s&dn=%s" % (self.torrent_info["infohash"], self.torrent_info['name'])).encode('utf-8') self.window().perform_start_download_request(self.download_uri, get_gui_setting(gui_settings, "default_anonymity_enabled", True, is_bool=True), get_gui_setting(gui_settings, "default_safeseeding_enabled", True, is_bool=True), self.window().tribler_settings['downloadconfig']['saveas'], [], 0, callback=self.on_play_request_done)
def initialize_with_settings(self, settings): self.settings = settings settings = settings["settings"] gui_settings = self.window().gui_settings # General settings self.window().developer_mode_enabled_checkbox.setChecked(get_gui_setting(gui_settings, "debug", False, is_bool=True)) self.window().family_filter_checkbox.setChecked(settings['general']['family_filter']) self.window().download_location_input.setText(settings['downloadconfig']['saveas']) self.window().always_ask_location_checkbox.setChecked( get_gui_setting(gui_settings, "ask_download_settings", True, is_bool=True)) self.window().download_settings_anon_checkbox.setChecked(get_gui_setting( gui_settings, "default_anonymity_enabled", True, is_bool=True)) self.window().download_settings_anon_seeding_checkbox.setChecked( get_gui_setting(gui_settings, "default_safeseeding_enabled", True, is_bool=True)) self.window().watchfolder_enabled_checkbox.setChecked(settings['watch_folder']['enabled']) self.window().watchfolder_location_input.setText(settings['watch_folder']['watch_folder_dir']) # Log directory self.window().log_location_input.setText(settings['general']['log_dir']) # Connection settings self.window().firewall_current_port_input.setText(str(settings['general']['minport'])) self.window().lt_proxy_type_combobox.setCurrentIndex(settings['libtorrent']['lt_proxytype']) if settings['libtorrent']['lt_proxyserver']: self.window().lt_proxy_server_input.setText(settings['libtorrent']['lt_proxyserver'][0]) self.window().lt_proxy_port_input.setText("%s" % settings['libtorrent']['lt_proxyserver'][1]) if settings['libtorrent']['lt_proxyauth']: self.window().lt_proxy_username_input.setText(settings['libtorrent']['lt_proxyauth'][0]) self.window().lt_proxy_password_input.setText(settings['libtorrent']['lt_proxyauth'][1]) self.window().lt_utp_checkbox.setChecked(settings['libtorrent']['utp']) max_conn_download = settings['libtorrent']['max_connections_download'] if max_conn_download == -1: max_conn_download = 0 self.window().max_connections_download_input.setText(str(max_conn_download)) # Bandwidth settings self.window().upload_rate_limit_input.setText(str(settings['libtorrent']['max_upload_rate'] / 1024)) self.window().download_rate_limit_input.setText(str(settings['libtorrent']['max_download_rate'] / 1024)) # Seeding settings getattr(self.window(), "seeding_" + settings['downloadconfig']['seeding_mode'] + "_radio").setChecked(True) self.window().seeding_time_input.setText(seconds_to_hhmm_string(settings['downloadconfig']['seeding_time'])) ind = self.window().seeding_ratio_combobox.findText(str(settings['downloadconfig']['seeding_ratio'])) if ind != -1: self.window().seeding_ratio_combobox.setCurrentIndex(ind) # Anonymity settings self.window().allow_exit_node_checkbox.setChecked(settings['tunnel_community']['exitnode_enabled']) self.window().number_hops_slider.setValue(int(settings['Tribler']['default_number_hops']) - 1) self.window().multichain_enabled_checkbox.setChecked(settings['multichain']['enabled'])
def on_confirm_add_directory_dialog(self, action): if action == 0: for torrent_file in self.selected_torrent_files: escaped_uri = quote_plus((u"file:%s" % torrent_file).encode('utf-8')) self.perform_start_download_request(escaped_uri, get_gui_setting(self.gui_settings, "default_anonymity_enabled", True, is_bool=True), get_gui_setting(self.gui_settings, "default_safeseeding_enabled", True, is_bool=True), self.tribler_settings['downloadconfig']['saveas'], [], 0) self.dialog.setParent(None) self.dialog = None
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): # Clear any previous dialog if exists if self.dialog: self.dialog.button_clicked.disconnect() self.dialog.setParent(None) 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 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 perform_start_download_request(self, uri, anon_download, safe_seeding, destination, selected_files, total_files=0, callback=None): selected_files_uri = "" if len(selected_files) != total_files: # Not all files included selected_files_uri = u'&' + u''.join(u"selected_files[]=%s&" % file for file 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" % (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() self.pending_requests[request_mgr.request_id] = request_mgr 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 [] 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 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 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 initialize_edit_channel_page(self, gui_settings): self.gui_settings = gui_settings self.window().create_channel_intro_button.clicked.connect(self.on_create_channel_intro_button_clicked) self.window().create_channel_form.hide() self.update_channel_commit_views() self.window().edit_channel_stacked_widget.setCurrentIndex(1) self.window().edit_channel_details_stacked_widget.setCurrentIndex(PAGE_EDIT_CHANNEL_OVERVIEW) self.window().create_channel_button.clicked.connect(self.on_create_channel_button_pressed) self.window().edit_channel_save_button.clicked.connect(self.on_edit_channel_save_button_pressed) self.window().edit_channel_commit_button.clicked.connect(self.clicked_edit_channel_commit_button) # Tab bar buttons self.window().channel_settings_tab.initialize() self.window().channel_settings_tab.clicked_tab_button.connect(self.clicked_tab_button) self.window().export_channel_button.clicked.connect(self.on_export_mdblob) # TODO: re-enable remove_selected button self.window().remove_selected_button.setHidden(True) # Connect torrent addition/removal buttons self.window().remove_selected_button.clicked.connect(self.on_torrents_remove_selected_clicked) self.window().remove_all_button.clicked.connect(self.on_torrents_remove_all_clicked) self.window().add_button.clicked.connect(self.on_torrents_add_clicked) self.model = MyTorrentsContentModel() self.controller = MyTorrentsTableViewController(self.model, self.window().edit_channel_torrents_container.content_table, self.window().edit_channel_torrents_container.details_container, self.window().edit_channel_torrents_num_items_label, self.window().edit_channel_torrents_filter) self.window().edit_channel_torrents_container.details_container.hide() self.autocommit_enabled = get_gui_setting(self.gui_settings, "autocommit_enabled", True, is_bool=True) if self.gui_settings else True # Commit the channel just in case there are uncommitted changes left since the last time (e.g. Tribler crashed) # The timer thing here is a workaround for race condition with the core startup if self.autocommit_enabled: if not self.commit_timer: self.commit_timer = QTimer() self.commit_timer.setSingleShot(True) self.commit_timer.timeout.connect(self.autocommit_fired) self.controller.table_view.setColumnHidden(3, True) self.model.exclude_deleted = True self.commit_timer.stop() self.commit_timer.start(10000) else: self.controller.table_view.setColumnHidden(4, True) self.model.exclude_deleted = False
def initialize_channel_page(self, gui_settings): self.gui_settings = gui_settings self.model = TorrentsContentModel(hide_xxx=get_gui_setting(self.gui_settings, "family_filter", True, is_bool=True) if self.gui_settings else True) self.window().core_manager.events_manager.torrent_info_updated.connect(self.model.update_torrent_info) self.controller = TorrentsTableViewController(self.model, self.window().channel_page_container.content_table, self.window().channel_page_container.details_container, None, self.window().channel_torrents_filter_input) # Remove the commit control from the delegate for performance commit_control = self.window().channel_page_container.content_table.delegate.commit_control self.window().channel_page_container.content_table.delegate.controls.remove(commit_control)
def on_selected_torrent_file(self, filepath): self.download_uri = u"file:%s" % filepath if get_gui_setting(self.gui_settings, "ask_download_settings", True, is_bool=True): self.dialog = StartDownloadDialog(self.window().stackedWidget, self.download_uri, filepath) self.dialog.button_clicked.connect(self.on_start_download_action) self.dialog.show() else: self.window().perform_start_download_request( self.download_uri, get_gui_setting(self.gui_settings, "default_anonymity_enabled", True, is_bool=True), get_gui_setting(self.gui_settings, "default_safeseeding_enabled", True, is_bool=True), self.tribler_settings['downloadconfig']['saveas'], [], 0)
def initialize_discovered_page(self, gui_settings): if not self.initialized: self.initialized = True self.gui_settings = gui_settings self.window().core_manager.events_manager.discovered_channel.connect(self.on_discovered_channel) self.model = ChannelsContentModel(hide_xxx=get_gui_setting(self.gui_settings, "family_filter", True, is_bool=True) if self.gui_settings else True) # Set the default sorting column/order to num_torrents/descending default_sort_column = self.model.columns.index(u'torrents') self.window().discovered_channels_list.horizontalHeader().setSortIndicator( default_sort_column, Qt.AscendingOrder) self.controller = ChannelsTableViewController(self.model, self.window().discovered_channels_list, self.window().num_discovered_channels_label, self.window().discovered_channels_filter_input)
def initialize_channel_page(self, gui_settings): self.gui_settings = gui_settings self.model = TorrentsContentModel(hide_xxx=get_gui_setting( self.gui_settings, "family_filter", True, is_bool=True) if self. gui_settings else True) self.window().core_manager.events_manager.torrent_info_updated.connect( self.model.update_torrent_info) self.controller = TorrentsTableViewController( self.model, self.window().channel_page_container.content_table, self.window().channel_page_container.details_container, None, self.window().channel_torrents_filter_input) # Remove the commit control from the delegate for performance commit_control = self.window( ).channel_page_container.content_table.delegate.commit_control self.window( ).channel_page_container.content_table.delegate.controls.remove( commit_control)
def initialize_discovered_page(self, gui_settings): if not self.initialized: self.initialized = True self.gui_settings = gui_settings self.window( ).core_manager.events_manager.discovered_channel.connect( self.on_discovered_channel) self.model = ChannelsContentModel(hide_xxx=get_gui_setting( self.gui_settings, "family_filter", True, is_bool=True ) if self.gui_settings else True) # Set the default sorting column/order to num_torrents/descending default_sort_column = self.model.columns.index(u'torrents') self.window().discovered_channels_list.horizontalHeader( ).setSortIndicator(default_sort_column, Qt.AscendingOrder) self.controller = ChannelsTableViewController( self.model, self.window().discovered_channels_list, self.window().num_discovered_channels_label, self.window().discovered_channels_filter_input)
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 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 start_download_from_uri(self, uri): self.download_uri = uri if get_gui_setting(self.gui_settings, "ask_download_settings", True, is_bool=True): # Clear any previous dialog if exists if self.dialog: self.dialog.button_clicked.disconnect() self.dialog.setParent(None) 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: 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 __init__(self, parent, download_uri): DialogContainer.__init__(self, parent) torrent_name = download_uri if torrent_name.startswith('file:'): torrent_name = torrent_name[5:] elif torrent_name.startswith('magnet:'): torrent_name = unquote_plus(torrent_name) self.download_uri = download_uri self.has_metainfo = False gui_settings = self.window().gui_settings uic.loadUi(get_ui_file_path('startdownloaddialog.ui'), self.dialog_widget) self.dialog_widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) self.dialog_widget.browse_dir_button.clicked.connect( self.on_browse_dir_clicked) self.dialog_widget.cancel_button.clicked.connect( lambda: self.button_clicked.emit(0)) self.dialog_widget.download_button.clicked.connect( self.on_download_clicked) self.dialog_widget.select_all_files_button.clicked.connect( self.on_all_files_selected_clicked) self.dialog_widget.deselect_all_files_button.clicked.connect( self.on_all_files_deselected_clicked) self.dialog_widget.destination_input.setStyleSheet(""" QComboBox { background-color: #444; border: none; color: #C0C0C0; padding: 4px; } QComboBox::drop-down { width: 20px; border: 1px solid #999; border-radius: 2px; } QComboBox QAbstractItemView { selection-background-color: #707070; color: #C0C0C0; } QComboBox::down-arrow { width: 12px; height: 12px; image: url('%s'); } """ % get_image_path('down_arrow_input.png')) if self.window().tribler_settings: # Set the most recent download locations in the QComboBox current_settings = get_gui_setting(self.window().gui_settings, "recent_download_locations", "") if len(current_settings) > 0: recent_locations = [ url.decode('hex') for url in current_settings.split(",") ] self.dialog_widget.destination_input.addItems(recent_locations) else: self.dialog_widget.destination_input.setCurrentText( self.window().tribler_settings['download_defaults'] ['saveas']) self.dialog_widget.torrent_name_label.setText(torrent_name) self.dialog_widget.anon_download_checkbox.stateChanged.connect( self.on_anon_download_state_changed) self.dialog_widget.anon_download_checkbox\ .setChecked(self.window().tribler_settings['download_defaults']['anonymity_enabled']) self.dialog_widget.safe_seed_checkbox\ .setChecked(self.window().tribler_settings['download_defaults']['safeseeding_enabled']) self.dialog_widget.safe_seed_checkbox.setEnabled( self.dialog_widget.anon_download_checkbox.isChecked()) self.perform_files_request() self.dialog_widget.files_list_view.setHidden(True) self.dialog_widget.download_files_container.setHidden(True) self.dialog_widget.adjustSize() self.on_anon_download_state_changed(None) self.on_main_window_resize()
def initialize_edit_channel_page(self, gui_settings): self.gui_settings = gui_settings self.window().create_channel_intro_button.clicked.connect( self.on_create_channel_intro_button_clicked) self.window().create_channel_form.hide() self.update_channel_commit_views() self.window().edit_channel_stacked_widget.setCurrentIndex(1) self.window().edit_channel_details_stacked_widget.setCurrentIndex( PAGE_EDIT_CHANNEL_OVERVIEW) self.window().create_channel_button.clicked.connect( self.on_create_channel_button_pressed) self.window().edit_channel_save_button.clicked.connect( self.on_edit_channel_save_button_pressed) self.window().edit_channel_commit_button.clicked.connect( self.clicked_edit_channel_commit_button) # Tab bar buttons self.window().channel_settings_tab.initialize() self.window().channel_settings_tab.clicked_tab_button.connect( self.clicked_tab_button) self.window().export_channel_button.clicked.connect( self.on_export_mdblob) # TODO: re-enable remove_selected button self.window().remove_selected_button.setHidden(True) # Connect torrent addition/removal buttons self.window().remove_selected_button.clicked.connect( self.on_torrents_remove_selected_clicked) self.window().remove_all_button.clicked.connect( self.on_torrents_remove_all_clicked) self.window().add_button.clicked.connect(self.on_torrents_add_clicked) self.model = MyTorrentsContentModel() self.controller = MyTorrentsTableViewController( self.model, self.window().edit_channel_torrents_container.content_table, self.window().edit_channel_torrents_container.details_container, self.window().edit_channel_torrents_num_items_label, self.window().edit_channel_torrents_filter) self.window().edit_channel_torrents_container.details_container.hide() self.autocommit_enabled = get_gui_setting( self.gui_settings, "autocommit_enabled", True, is_bool=True) if self.gui_settings else True # Commit the channel just in case there are uncommitted changes left since the last time (e.g. Tribler crashed) # The timer thing here is a workaround for race condition with the core startup if self.autocommit_enabled: if not self.commit_timer: self.commit_timer = QTimer() self.commit_timer.setSingleShot(True) self.commit_timer.timeout.connect(self.autocommit_fired) self.controller.table_view.setColumnHidden(3, True) self.model.exclude_deleted = True self.commit_timer.stop() self.commit_timer.start(10000) else: self.controller.table_view.setColumnHidden(4, True) self.model.exclude_deleted = False
def __init__(self, core_args=None, core_env=None, api_port=None): QMainWindow.__init__(self) QCoreApplication.setOrganizationDomain("nl") QCoreApplication.setOrganizationName("TUDelft") QCoreApplication.setApplicationName("Tribler") QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) self.gui_settings = QSettings() api_port = api_port or int(get_gui_setting(self.gui_settings, "api_port", DEFAULT_API_PORT)) dispatcher.update_worker_settings(port=api_port) self.navigation_stack = [] self.tribler_started = False self.tribler_settings = None self.debug_window = None self.core_manager = CoreManager(api_port) self.pending_requests = {} self.pending_uri_requests = [] self.download_uri = None self.dialog = None self.new_version_dialog = None self.start_download_dialog_active = False self.request_mgr = None self.search_request_mgr = None self.search_suggestion_mgr = None self.selected_torrent_files = [] self.vlc_available = True self.has_search_results = False self.last_search_query = None self.last_search_time = None self.start_time = time.time() self.exception_handler_called = False self.token_refresh_timer = None sys.excepthook = self.on_exception uic.loadUi(get_ui_file_path('mainwindow.ui'), self) TriblerRequestManager.window = self self.tribler_status_bar.hide() # Load dynamic widgets uic.loadUi(get_ui_file_path('torrent_channel_list_container.ui'), self.channel_page_container) self.channel_torrents_list = self.channel_page_container.items_list self.channel_torrents_detail_widget = self.channel_page_container.details_tab_widget self.channel_torrents_detail_widget.initialize_details_widget() self.channel_torrents_list.itemSelectionChanged.connect(self.channel_page.clicked_item) uic.loadUi(get_ui_file_path('torrent_channel_list_container.ui'), self.search_page_container) self.search_results_list = self.search_page_container.items_list self.search_torrents_detail_widget = self.search_page_container.details_tab_widget self.search_torrents_detail_widget.initialize_details_widget() self.search_results_list.itemClicked.connect(self.on_channel_item_click) self.search_results_list.itemSelectionChanged.connect(self.search_results_page.clicked_item) self.token_balance_widget.mouseReleaseEvent = self.on_token_balance_click def on_state_update(new_state): self.loading_text_label.setText(new_state) self.core_manager.core_state_update.connect(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) self.debug_pane_shortcut.activated.connect(self.clicked_menu_button_debug) # 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_home, self.left_menu_button_search, self.left_menu_button_my_channel, self.left_menu_button_subscriptions, self.left_menu_button_video_player, self.left_menu_button_downloads, self.left_menu_button_discovered] self.video_player_page.initialize_player() self.search_results_page.initialize_search_results_page() self.settings_page.initialize_settings_page() self.subscribed_channels_page.initialize() self.edit_channel_page.initialize_edit_channel_page() self.downloads_page.initialize_downloads_page() self.home_page.initialize_home_page() self.loading_page.initialize_loading_page() self.discovering_page.initialize_discovering_page() self.discovered_page.initialize_discovered_page() self.trust_page.initialize_trust_page() self.stackedWidget.setCurrentIndex(PAGE_LOADING) # Create the system tray icon if QSystemTrayIcon.isSystemTrayAvailable(): self.tray_icon = QSystemTrayIcon() 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 = self.create_add_torrent_menu() show_downloads_action = QAction('Show downloads', self) show_downloads_action.triggered.connect(self.clicked_menu_button_downloads) token_balance_action = QAction('Show token balance', self) token_balance_action.triggered.connect(lambda: self.on_token_balance_click(None)) quit_action = QAction('Quit Tribler', self) quit_action.triggered.connect(self.close_tribler) menu.addSeparator() menu.addAction(show_downloads_action) menu.addAction(token_balance_action) menu.addSeparator() menu.addAction(quit_action) self.tray_icon.setContextMenu(menu) else: self.tray_icon = None self.hide_left_menu_playlist() self.left_menu_button_debug.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) # Toggle debug if developer mode is enabled self.window().left_menu_button_debug.setHidden( not get_gui_setting(self.gui_settings, "debug", False, is_bool=True)) # Start Tribler self.core_manager.start(core_args=core_args, core_env=core_env) self.core_manager.events_manager.received_search_result_channel.connect( self.search_results_page.received_search_result_channel) self.core_manager.events_manager.received_search_result_torrent.connect( self.search_results_page.received_search_result_torrent) self.core_manager.events_manager.torrent_finished.connect(self.on_torrent_finished) self.core_manager.events_manager.new_version_available.connect(self.on_new_version_available) self.core_manager.events_manager.tribler_started.connect(self.on_tribler_started) self.core_manager.events_manager.events_started.connect(self.on_events_started) self.core_manager.events_manager.low_storage_signal.connect(self.on_low_storage) # Install signal handler for ctrl+c events def sigint_handler(*_): self.close_tribler() signal.signal(signal.SIGINT, sigint_handler) self.installEventFilter(self.video_player_page) # 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()
def __init__(self, core_args=None, core_env=None, api_port=None): QMainWindow.__init__(self) QCoreApplication.setOrganizationDomain("nl") QCoreApplication.setOrganizationName("TUDelft") QCoreApplication.setApplicationName("Tribler") QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) self.gui_settings = QSettings() api_port = api_port or int(get_gui_setting(self.gui_settings, "api_port", DEFAULT_API_PORT)) dispatcher.update_worker_settings(port=api_port) self.navigation_stack = [] self.tribler_started = False self.tribler_settings = None self.debug_window = None self.core_manager = CoreManager(api_port) self.pending_requests = {} self.pending_uri_requests = [] self.download_uri = None self.dialog = None self.new_version_dialog = None self.start_download_dialog_active = False self.request_mgr = None self.search_request_mgr = None self.search_suggestion_mgr = None self.selected_torrent_files = [] self.vlc_available = True self.has_search_results = False self.last_search_query = None self.last_search_time = None self.start_time = time.time() self.exception_handler_called = False self.token_refresh_timer = None self.shutdown_timer = None self.add_torrent_url_dialog_active = False sys.excepthook = self.on_exception 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) self.core_manager.core_state_update.connect(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) self.debug_pane_shortcut.activated.connect(self.clicked_menu_button_debug) self.import_torrent_shortcut = QShortcut(QKeySequence("Ctrl+o"), self) self.import_torrent_shortcut.activated.connect(self.on_add_torrent_browse_file) self.add_torrent_url_shortcut = QShortcut(QKeySequence("Ctrl+i"), self) self.add_torrent_url_shortcut.activated.connect(self.on_add_torrent_from_url) # 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_home, self.left_menu_button_search, self.left_menu_button_my_channel, self.left_menu_button_subscriptions, self.left_menu_button_video_player, self.left_menu_button_downloads, self.left_menu_button_discovered] self.video_player_page.initialize_player() self.search_results_page.initialize_search_results_page(self.gui_settings) self.settings_page.initialize_settings_page() self.subscribed_channels_page.initialize() self.edit_channel_page.initialize_edit_channel_page(self.gui_settings) self.downloads_page.initialize_downloads_page() self.home_page.initialize_home_page() self.loading_page.initialize_loading_page() self.discovering_page.initialize_discovering_page() self.discovered_page.initialize_discovered_page(self.gui_settings) self.channel_page.initialize_channel_page(self.gui_settings) self.trust_page.initialize_trust_page() self.token_mining_page.initialize_token_mining_page() self.stackedWidget.setCurrentIndex(PAGE_LOADING) # Create the system tray icon if QSystemTrayIcon.isSystemTrayAvailable(): self.tray_icon = QSystemTrayIcon() 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 = self.create_add_torrent_menu() show_downloads_action = QAction('Show downloads', self) show_downloads_action.triggered.connect(self.clicked_menu_button_downloads) token_balance_action = QAction('Show token balance', self) token_balance_action.triggered.connect(lambda: self.on_token_balance_click(None)) quit_action = QAction('Quit Tribler', self) quit_action.triggered.connect(self.close_tribler) menu.addSeparator() menu.addAction(show_downloads_action) menu.addAction(token_balance_action) menu.addSeparator() menu.addAction(quit_action) self.tray_icon.setContextMenu(menu) else: self.tray_icon = None self.hide_left_menu_playlist() self.left_menu_button_debug.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) # Toggle debug if developer mode is enabled self.window().left_menu_button_debug.setHidden( not get_gui_setting(self.gui_settings, "debug", False, is_bool=True)) # Start Tribler self.core_manager.start(core_args=core_args, core_env=core_env) self.core_manager.events_manager.torrent_finished.connect(self.on_torrent_finished) self.core_manager.events_manager.new_version_available.connect(self.on_new_version_available) self.core_manager.events_manager.tribler_started.connect(self.on_tribler_started) self.core_manager.events_manager.events_started.connect(self.on_events_started) self.core_manager.events_manager.low_storage_signal.connect(self.on_low_storage) self.core_manager.events_manager.credit_mining_signal.connect(self.on_credit_mining_error) self.core_manager.events_manager.tribler_shutdown_signal.connect(self.on_tribler_shutdown_state_update) self.core_manager.events_manager.upgrader_tick.connect( lambda text: self.show_status_bar("Upgrading Tribler database: " + text)) self.core_manager.events_manager.upgrader_finished.connect( lambda _: self.hide_status_bar()) self.core_manager.events_manager.received_search_result.connect( self.search_results_page.received_search_result) # Install signal handler for ctrl+c events def sigint_handler(*_): self.close_tribler() signal.signal(signal.SIGINT, sigint_handler) self.installEventFilter(self.video_player_page) # 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()
def __init__(self): QMainWindow.__init__(self) self.navigation_stack = [] self.feedback_dialog_is_open = False self.tribler_started = False self.tribler_settings = None self.debug_window = None self.core_manager = CoreManager() self.pending_requests = {} self.pending_uri_requests = [] self.download_uri = None self.dialog = None self.start_download_dialog_active = False self.request_mgr = None self.search_request_mgr = None self.search_suggestion_mgr = None self.selected_torrent_files = [] self.vlc_available = True self.has_search_results = False self.start_time = time.time() sys.excepthook = self.on_exception uic.loadUi(get_ui_file_path('mainwindow.ui'), self) TriblerRequestManager.window = self self.tribler_status_bar.hide() self.magnet_handler = MagnetHandler(self.window) QDesktopServices.setUrlHandler("magnet", self.magnet_handler, "on_open_magnet_link") QCoreApplication.setOrganizationDomain("nl") QCoreApplication.setOrganizationName("TUDelft") QCoreApplication.setApplicationName("Tribler") QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) self.read_settings() # 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_home, self.left_menu_button_search, self.left_menu_button_my_channel, self.left_menu_button_subscriptions, self.left_menu_button_video_player, self.left_menu_button_downloads, self.left_menu_button_discovered ] self.video_player_page.initialize_player() self.search_results_page.initialize_search_results_page() self.settings_page.initialize_settings_page() self.subscribed_channels_page.initialize() self.edit_channel_page.initialize_edit_channel_page() self.downloads_page.initialize_downloads_page() self.home_page.initialize_home_page() self.loading_page.initialize_loading_page() self.discovering_page.initialize_discovering_page() self.discovered_page.initialize_discovered_page() self.trust_page.initialize_trust_page() self.stackedWidget.setCurrentIndex(PAGE_LOADING) # Create the system tray icon if QSystemTrayIcon.isSystemTrayAvailable(): self.tray_icon = QSystemTrayIcon() use_monochrome_icon = get_gui_setting(self.gui_settings, "use_monochrome_icon", False, is_bool=True) self.update_tray_icon(use_monochrome_icon) self.hide_left_menu_playlist() self.left_menu_button_debug.setHidden(True) self.top_menu_button.setHidden(True) self.left_menu.setHidden(True) self.trust_button.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) # Toggle debug if developer mode is enabled self.window().left_menu_button_debug.setHidden(not get_gui_setting( self.gui_settings, "debug", False, is_bool=True)) self.core_manager.start() self.core_manager.events_manager.received_search_result_channel.connect( self.search_results_page.received_search_result_channel) self.core_manager.events_manager.received_search_result_torrent.connect( self.search_results_page.received_search_result_torrent) self.core_manager.events_manager.torrent_finished.connect( self.on_torrent_finished) self.core_manager.events_manager.new_version_available.connect( self.on_new_version_available) self.core_manager.events_manager.tribler_started.connect( self.on_tribler_started) # Install signal handler for ctrl+c events def sigint_handler(*_): self.close_tribler() signal.signal(signal.SIGINT, sigint_handler) self.installEventFilter(self.video_player_page) self.show()
def initialize_with_settings(self, settings): self.settings = settings settings = settings["settings"] gui_settings = self.window().gui_settings # General settings self.window().family_filter_checkbox.setChecked( settings['general']['family_filter']) self.window().use_monochrome_icon_checkbox.setChecked( get_gui_setting(gui_settings, "use_monochrome_icon", False, is_bool=True)) self.window().download_location_input.setText( settings['download_defaults']['saveas']) self.window().always_ask_location_checkbox.setChecked( get_gui_setting(gui_settings, "ask_download_settings", True, is_bool=True)) self.window().download_settings_anon_checkbox.setChecked( settings['download_defaults']['anonymity_enabled']) self.window().download_settings_anon_seeding_checkbox.setChecked( settings['download_defaults']['safeseeding_enabled']) self.window().watchfolder_enabled_checkbox.setChecked( settings['watch_folder']['enabled']) self.window().watchfolder_location_input.setText( settings['watch_folder']['directory']) # Log directory self.window().log_location_input.setText( settings['general']['log_dir']) # Connection settings self.window().lt_proxy_type_combobox.setCurrentIndex( settings['libtorrent']['proxy_type']) if settings['libtorrent']['proxy_server']: self.window().lt_proxy_server_input.setText( settings['libtorrent']['proxy_server'][0]) self.window().lt_proxy_port_input.setText( "%s" % settings['libtorrent']['proxy_server'][1]) if settings['libtorrent']['proxy_auth']: self.window().lt_proxy_username_input.setText( settings['libtorrent']['proxy_auth'][0]) self.window().lt_proxy_password_input.setText( settings['libtorrent']['proxy_auth'][1]) self.window().lt_utp_checkbox.setChecked(settings['libtorrent']['utp']) max_conn_download = settings['libtorrent']['max_connections_download'] if max_conn_download == -1: max_conn_download = 0 self.window().max_connections_download_input.setText( str(max_conn_download)) self.window().api_port_input.setText( "%s" % get_gui_setting(gui_settings, "api_port", DEFAULT_API_PORT)) # Bandwidth settings self.window().upload_rate_limit_input.setText( str(settings['libtorrent']['max_upload_rate'] / 1024)) self.window().download_rate_limit_input.setText( str(settings['libtorrent']['max_download_rate'] / 1024)) # Seeding settings getattr( self.window(), "seeding_" + settings['download_defaults']['seeding_mode'] + "_radio").setChecked(True) self.window().seeding_time_input.setText( seconds_to_hhmm_string( settings['download_defaults']['seeding_time'])) ind = self.window().seeding_ratio_combobox.findText( str(settings['download_defaults']['seeding_ratio'])) if ind != -1: self.window().seeding_ratio_combobox.setCurrentIndex(ind) # Anonymity settings self.window().allow_exit_node_checkbox.setChecked( settings['tunnel_community']['exitnode_enabled']) self.window().number_hops_slider.setValue( int(settings['download_defaults']['number_hops']) - 1) self.window().credit_mining_enabled_checkbox.setChecked( settings['credit_mining']['enabled']) self.window().max_disk_space_input.setText( str(settings['credit_mining']['max_disk_space'])) # Debug self.window().developer_mode_enabled_checkbox.setChecked( get_gui_setting(gui_settings, "debug", False, is_bool=True)) self.window().checkbox_enable_resource_log.setChecked( settings['resource_monitor']['enabled']) cpu_priority = 1 if 'cpu_priority' in settings['resource_monitor']: cpu_priority = int(settings['resource_monitor']['cpu_priority']) self.window().slider_cpu_level.setValue(cpu_priority) self.window().cpu_priority_value.setText("Current Priority = %s" % cpu_priority) self.window().slider_cpu_level.valueChanged.connect( self.show_updated_cpu_priority)
def initialize_with_settings(self, settings): if not settings: return self.settings = settings settings = settings["settings"] gui_settings = self.window().gui_settings # General settings self.window().family_filter_checkbox.setChecked(get_gui_setting(gui_settings, 'family_filter', True, is_bool=True)) self.window().use_monochrome_icon_checkbox.setChecked(get_gui_setting(gui_settings, "use_monochrome_icon", False, is_bool=True)) self.window().download_location_input.setText(settings['download_defaults']['saveas']) self.window().always_ask_location_checkbox.setChecked( get_gui_setting(gui_settings, "ask_download_settings", True, is_bool=True)) self.window().download_settings_anon_checkbox.setChecked(settings['download_defaults']['anonymity_enabled']) self.window().download_settings_anon_seeding_checkbox.setChecked(settings['download_defaults'][ 'safeseeding_enabled']) self.window().watchfolder_enabled_checkbox.setChecked(settings['watch_folder']['enabled']) self.window().watchfolder_location_input.setText(settings['watch_folder']['directory']) # Channel settings self.window().channel_autocommit_checkbox.setChecked( get_gui_setting(gui_settings, "autocommit_enabled", True, is_bool=True)) # Log directory self.window().log_location_input.setText(settings['general']['log_dir']) # Connection settings self.window().lt_proxy_type_combobox.setCurrentIndex(settings['libtorrent']['proxy_type']) if settings['libtorrent']['proxy_server']: proxy_server = settings['libtorrent']['proxy_server'].split(":") self.window().lt_proxy_server_input.setText(proxy_server[0]) self.window().lt_proxy_port_input.setText(proxy_server[1]) if settings['libtorrent']['proxy_auth']: proxy_auth = settings['libtorrent']['proxy_auth'].split(":") self.window().lt_proxy_username_input.setText(proxy_auth[0]) self.window().lt_proxy_password_input.setText(proxy_auth[1]) self.window().lt_utp_checkbox.setChecked(settings['libtorrent']['utp']) max_conn_download = settings['libtorrent']['max_connections_download'] if max_conn_download == -1: max_conn_download = 0 self.window().max_connections_download_input.setText(str(max_conn_download)) self.window().api_port_input.setText("%s" % get_gui_setting(gui_settings, "api_port", DEFAULT_API_PORT)) # Bandwidth settings self.window().upload_rate_limit_input.setText(str(settings['libtorrent']['max_upload_rate'] // 1024)) self.window().download_rate_limit_input.setText(str(settings['libtorrent']['max_download_rate'] // 1024)) # Seeding settings getattr(self.window(), "seeding_" + settings['download_defaults']['seeding_mode'] + "_radio").setChecked(True) self.window().seeding_time_input.setText(seconds_to_hhmm_string(settings['download_defaults']['seeding_time'])) ind = self.window().seeding_ratio_combobox.findText(str(settings['download_defaults']['seeding_ratio'])) if ind != -1: self.window().seeding_ratio_combobox.setCurrentIndex(ind) # Anonymity settings self.window().allow_exit_node_checkbox.setChecked(settings['tunnel_community']['exitnode_enabled']) self.window().number_hops_slider.setValue(int(settings['download_defaults']['number_hops'])) self.window().number_hops_slider.valueChanged.connect(self.update_anonymity_cost_label) self.update_anonymity_cost_label(int(settings['download_defaults']['number_hops'])) self.window().credit_mining_enabled_checkbox.setChecked(settings['credit_mining']['enabled']) self.window().max_disk_space_input.setText(str(settings['credit_mining']['max_disk_space'])) # Debug self.window().developer_mode_enabled_checkbox.setChecked(get_gui_setting(gui_settings, "debug", False, is_bool=True)) self.window().checkbox_enable_resource_log.setChecked(settings['resource_monitor']['enabled']) cpu_priority = 1 if 'cpu_priority' in settings['resource_monitor']: cpu_priority = int(settings['resource_monitor']['cpu_priority']) self.window().slider_cpu_level.setValue(cpu_priority) self.window().cpu_priority_value.setText("Current Priority = %s" % cpu_priority) self.window().slider_cpu_level.valueChanged.connect(self.show_updated_cpu_priority) self.window().checkbox_enable_network_statistics.setChecked(settings['ipv8']['statistics'])
def __init__(self, parent, download_uri): DialogContainer.__init__(self, parent) torrent_name = download_uri if torrent_name.startswith('file:'): torrent_name = torrent_name[5:] elif torrent_name.startswith('magnet:'): torrent_name = unquote_plus(torrent_name) self.download_uri = download_uri self.has_metainfo = False uic.loadUi(get_ui_file_path('startdownloaddialog.ui'), self.dialog_widget) self.dialog_widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) self.dialog_widget.browse_dir_button.clicked.connect(self.on_browse_dir_clicked) self.dialog_widget.cancel_button.clicked.connect(lambda: self.button_clicked.emit(0)) self.dialog_widget.download_button.clicked.connect(self.on_download_clicked) self.dialog_widget.select_all_files_button.clicked.connect(self.on_all_files_selected_clicked) self.dialog_widget.deselect_all_files_button.clicked.connect(self.on_all_files_deselected_clicked) self.dialog_widget.destination_input.setStyleSheet(""" QComboBox { background-color: #444; border: none; color: #C0C0C0; padding: 4px; } QComboBox::drop-down { width: 20px; border: 1px solid #999; border-radius: 2px; } QComboBox QAbstractItemView { selection-background-color: #707070; color: #C0C0C0; } QComboBox::down-arrow { width: 12px; height: 12px; image: url('%s'); } """ % get_image_path('down_arrow_input.png')) if self.window().tribler_settings: # Set the most recent download locations in the QComboBox current_settings = get_gui_setting(self.window().gui_settings, "recent_download_locations", "") if len(current_settings) > 0: recent_locations = [url.decode('hex').decode('utf-8') for url in current_settings.split(",")] self.dialog_widget.destination_input.addItems(recent_locations) else: self.dialog_widget.destination_input.setCurrentText( self.window().tribler_settings['download_defaults']['saveas']) self.dialog_widget.torrent_name_label.setText(torrent_name) self.dialog_widget.anon_download_checkbox.stateChanged.connect(self.on_anon_download_state_changed) self.dialog_widget.anon_download_checkbox\ .setChecked(self.window().tribler_settings['download_defaults']['anonymity_enabled']) self.dialog_widget.safe_seed_checkbox\ .setChecked(self.window().tribler_settings['download_defaults']['safeseeding_enabled']) self.dialog_widget.safe_seed_checkbox.setEnabled(self.dialog_widget.anon_download_checkbox.isChecked()) self.perform_files_request() self.dialog_widget.files_list_view.setHidden(True) self.dialog_widget.download_files_container.setHidden(True) self.dialog_widget.adjustSize() self.on_anon_download_state_changed(None) self.on_main_window_resize()