mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-30 21:30:04 +00:00 
			
		
		
		
	Check input profile name for duplicates in New/Rename (#4779)
* Check input profile name for duplicates in New/Rename * DRY + separation of concerns * simplify return branching * make readonly function const
This commit is contained in:
		
							parent
							
								
									5727e1b43d
								
							
						
					
					
						commit
						186ffc235f
					
				
					 2 changed files with 22 additions and 0 deletions
				
			
		|  | @ -437,6 +437,11 @@ void ConfigureInput::NewProfile() { | ||||||
|     if (name.isEmpty()) { |     if (name.isEmpty()) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |     if (IsProfileNameDuplicate(name)) { | ||||||
|  |         WarnProposedProfileNameIsDuplicate(); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     applyConfiguration(); |     applyConfiguration(); | ||||||
|     Settings::SaveProfile(ui->profile->currentIndex()); |     Settings::SaveProfile(ui->profile->currentIndex()); | ||||||
|     Settings::CreateProfile(name.toStdString()); |     Settings::CreateProfile(name.toStdString()); | ||||||
|  | @ -465,6 +470,20 @@ void ConfigureInput::RenameProfile() { | ||||||
|     if (new_name.isEmpty()) { |     if (new_name.isEmpty()) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |     if (IsProfileNameDuplicate(new_name)) { | ||||||
|  |         WarnProposedProfileNameIsDuplicate(); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     ui->profile->setItemText(ui->profile->currentIndex(), new_name); |     ui->profile->setItemText(ui->profile->currentIndex(), new_name); | ||||||
|     Settings::RenameCurrentProfile(new_name.toStdString()); |     Settings::RenameCurrentProfile(new_name.toStdString()); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | bool ConfigureInput::IsProfileNameDuplicate(const QString& name) const { | ||||||
|  |     return ui->profile->findText(name, Qt::MatchFixedString | Qt::MatchCaseSensitive) != -1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void ConfigureInput::WarnProposedProfileNameIsDuplicate() { | ||||||
|  |     QMessageBox::warning(this, tr("Duplicate profile name"), | ||||||
|  |                          tr("Profile name already exists. Please choose a different name.")); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -119,4 +119,7 @@ private: | ||||||
|     void NewProfile(); |     void NewProfile(); | ||||||
|     void DeleteProfile(); |     void DeleteProfile(); | ||||||
|     void RenameProfile(); |     void RenameProfile(); | ||||||
|  | 
 | ||||||
|  |     bool IsProfileNameDuplicate(const QString& name) const; | ||||||
|  |     void WarnProposedProfileNameIsDuplicate(); | ||||||
| }; | }; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue