summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2018-10-26 19:36:41 -0400
committerGravatar Lioncash2018-10-27 01:05:56 -0400
commit85ed0af84eeff3d2a7acf1104180a87a4d468a2e (patch)
tree18df6f7f25ef275d7a9517efaaea4b47c52fc55b /src
parentconfigure_system: Display errors to the user if file operations fail when set... (diff)
downloadyuzu-85ed0af84eeff3d2a7acf1104180a87a4d468a2e.tar.gz
yuzu-85ed0af84eeff3d2a7acf1104180a87a4d468a2e.tar.xz
yuzu-85ed0af84eeff3d2a7acf1104180a87a4d468a2e.zip
configure_system: Move entry formatting for the user account list entries to its own function
Avoids the need to duplicate this all over the place, and makes it translator-friendly across the board.
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/configuration/configure_system.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp
index adb16de8a..f4e892a21 100644
--- a/src/yuzu/configuration/configure_system.cpp
+++ b/src/yuzu/configuration/configure_system.cpp
@@ -54,15 +54,23 @@ QString GetImagePath(Service::Account::UUID uuid) {
54 return QString::fromStdString(path); 54 return QString::fromStdString(path);
55} 55}
56 56
57std::string GetAccountUsername(const Service::Account::ProfileManager& manager, 57QString GetAccountUsername(const Service::Account::ProfileManager& manager,
58 Service::Account::UUID uuid) { 58 Service::Account::UUID uuid) {
59 Service::Account::ProfileBase profile; 59 Service::Account::ProfileBase profile;
60 if (!manager.GetProfileBase(uuid, profile)) { 60 if (!manager.GetProfileBase(uuid, profile)) {
61 return ""; 61 return {};
62 } 62 }
63 63
64 return Common::StringFromFixedZeroTerminatedBuffer( 64 const auto text = Common::StringFromFixedZeroTerminatedBuffer(
65 reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); 65 reinterpret_cast<const char*>(profile.username.data()), profile.username.size());
66 return QString::fromStdString(text);
67}
68
69QString FormatUserEntryText(const QString& username, Service::Account::UUID uuid) {
70 return ConfigureSystem::tr("%1\n%2",
71 "%1 is the profile username, %2 is the formatted UUID (e.g. "
72 "00112233-4455-6677-8899-AABBCCDDEEFF))")
73 .arg(username, QString::fromStdString(uuid.FormatSwitch()));
66} 74}
67 75
68QPixmap GetIcon(Service::Account::UUID uuid) { 76QPixmap GetIcon(Service::Account::UUID uuid) {
@@ -155,7 +163,7 @@ void ConfigureSystem::PopulateUserList() {
155 163
156 list_items.push_back(QList<QStandardItem*>{new QStandardItem{ 164 list_items.push_back(QList<QStandardItem*>{new QStandardItem{
157 GetIcon(user).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), 165 GetIcon(user).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
158 QString::fromStdString(username + '\n' + user.FormatSwitch())}}); 166 FormatUserEntryText(QString::fromStdString(username), user)}});
159 } 167 }
160 168
161 for (const auto& item : list_items) 169 for (const auto& item : list_items)
@@ -172,7 +180,7 @@ void ConfigureSystem::UpdateCurrentUser() {
172 scene->clear(); 180 scene->clear();
173 scene->addPixmap( 181 scene->addPixmap(
174 GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); 182 GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
175 ui->current_user_username->setText(QString::fromStdString(username)); 183 ui->current_user_username->setText(username);
176} 184}
177 185
178void ConfigureSystem::ReadSystemSettings() {} 186void ConfigureSystem::ReadSystemSettings() {}
@@ -250,23 +258,23 @@ void ConfigureSystem::AddUser() {
250 258
251 item_model->appendRow(new QStandardItem{ 259 item_model->appendRow(new QStandardItem{
252 GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), 260 GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
253 QString::fromStdString(username.toStdString() + '\n' + uuid.FormatSwitch())}); 261 FormatUserEntryText(username, uuid)});
254} 262}
255 263
256void ConfigureSystem::RenameUser() { 264void ConfigureSystem::RenameUser() {
257 const auto user = tree_view->currentIndex().row(); 265 const auto user = tree_view->currentIndex().row();
258 const auto uuid = profile_manager->GetUser(user); 266 const auto uuid = profile_manager->GetUser(user);
259 ASSERT(uuid != std::nullopt); 267 ASSERT(uuid != std::nullopt);
260 const auto username = GetAccountUsername(*profile_manager, *uuid);
261 268
262 Service::Account::ProfileBase profile; 269 Service::Account::ProfileBase profile;
263 if (!profile_manager->GetProfileBase(*uuid, profile)) 270 if (!profile_manager->GetProfileBase(*uuid, profile))
264 return; 271 return;
265 272
266 bool ok = false; 273 bool ok = false;
274 const auto old_username = GetAccountUsername(*profile_manager, *uuid);
267 const auto new_username = 275 const auto new_username =
268 QInputDialog::getText(this, tr("Enter Username"), tr("Enter a new username:"), 276 QInputDialog::getText(this, tr("Enter Username"), tr("Enter a new username:"),
269 QLineEdit::Normal, QString::fromStdString(username), &ok); 277 QLineEdit::Normal, old_username, &ok);
270 278
271 if (!ok) 279 if (!ok)
272 return; 280 return;
@@ -286,10 +294,7 @@ void ConfigureSystem::RenameUser() {
286 user, 0, 294 user, 0,
287 new QStandardItem{ 295 new QStandardItem{
288 GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), 296 GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
289 tr("%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. " 297 FormatUserEntryText(QString::fromStdString(username_std), *uuid)});
290 "00112233-4455-6677-8899-AABBCCDDEEFF))")
291 .arg(QString::fromStdString(username_std),
292 QString::fromStdString(uuid->FormatSwitch()))});
293 UpdateCurrentUser(); 298 UpdateCurrentUser();
294} 299}
295 300
@@ -299,10 +304,9 @@ void ConfigureSystem::DeleteUser() {
299 ASSERT(uuid != std::nullopt); 304 ASSERT(uuid != std::nullopt);
300 const auto username = GetAccountUsername(*profile_manager, *uuid); 305 const auto username = GetAccountUsername(*profile_manager, *uuid);
301 306
302 const auto confirm = 307 const auto confirm = QMessageBox::question(
303 QMessageBox::question(this, tr("Confirm Delete"), 308 this, tr("Confirm Delete"),
304 tr("You are about to delete user with name %1. Are you sure?") 309 tr("You are about to delete user with name \"%1\". Are you sure?").arg(username));
305 .arg(QString::fromStdString(username)));
306 310
307 if (confirm == QMessageBox::No) 311 if (confirm == QMessageBox::No)
308 return; 312 return;
@@ -369,6 +373,6 @@ void ConfigureSystem::SetUserImage() {
369 index, 0, 373 index, 0,
370 new QStandardItem{ 374 new QStandardItem{
371 GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), 375 GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
372 QString::fromStdString(username + '\n' + uuid->FormatSwitch())}); 376 FormatUserEntryText(username, *uuid)});
373 UpdateCurrentUser(); 377 UpdateCurrentUser();
374} 378}