summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/yuzu/configuration/configure_system.cpp121
1 files changed, 70 insertions, 51 deletions
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp
index 20ffb0a9a..4b34c1e28 100644
--- a/src/yuzu/configuration/configure_system.cpp
+++ b/src/yuzu/configuration/configure_system.cpp
@@ -48,20 +48,40 @@ constexpr std::array<u8, 107> backup_jpeg{
48 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, 48 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9,
49}; 49};
50 50
51std::string GetImagePath(Service::Account::UUID uuid) { 51QString GetImagePath(Service::Account::UUID uuid) {
52 return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + 52 const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
53 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; 53 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
54 return QString::fromStdString(path);
54} 55}
55 56
56std::string GetAccountUsername(const Service::Account::ProfileManager& manager, 57QString GetAccountUsername(const Service::Account::ProfileManager& manager,
57 Service::Account::UUID uuid) { 58 Service::Account::UUID uuid) {
58 Service::Account::ProfileBase profile; 59 Service::Account::ProfileBase profile;
59 if (!manager.GetProfileBase(uuid, profile)) { 60 if (!manager.GetProfileBase(uuid, profile)) {
60 return ""; 61 return {};
61 } 62 }
62 63
63 return Common::StringFromFixedZeroTerminatedBuffer( 64 const auto text = Common::StringFromFixedZeroTerminatedBuffer(
64 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()));
74}
75
76QPixmap GetIcon(Service::Account::UUID uuid) {
77 QPixmap icon{GetImagePath(uuid)};
78
79 if (!icon) {
80 icon.fill(Qt::black);
81 icon.loadFromData(backup_jpeg.data(), backup_jpeg.size());
82 }
83
84 return icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
65} 85}
66} // Anonymous namespace 86} // Anonymous namespace
67 87
@@ -131,18 +151,6 @@ void ConfigureSystem::setConfiguration() {
131 UpdateCurrentUser(); 151 UpdateCurrentUser();
132} 152}
133 153
134static QPixmap GetIcon(Service::Account::UUID uuid) {
135 const auto icon_url = QString::fromStdString(GetImagePath(uuid));
136 QPixmap icon{icon_url};
137
138 if (!icon) {
139 icon.fill(Qt::black);
140 icon.loadFromData(backup_jpeg.data(), backup_jpeg.size());
141 }
142
143 return icon;
144}
145
146void ConfigureSystem::PopulateUserList() { 154void ConfigureSystem::PopulateUserList() {
147 const auto& profiles = profile_manager->GetAllUsers(); 155 const auto& profiles = profile_manager->GetAllUsers();
148 for (const auto& user : profiles) { 156 for (const auto& user : profiles) {
@@ -154,8 +162,7 @@ void ConfigureSystem::PopulateUserList() {
154 reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); 162 reinterpret_cast<const char*>(profile.username.data()), profile.username.size());
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), FormatUserEntryText(QString::fromStdString(username), user)}});
158 QString::fromStdString(username + '\n' + user.FormatSwitch())}});
159 } 166 }
160 167
161 for (const auto& item : list_items) 168 for (const auto& item : list_items)
@@ -172,7 +179,7 @@ void ConfigureSystem::UpdateCurrentUser() {
172 scene->clear(); 179 scene->clear();
173 scene->addPixmap( 180 scene->addPixmap(
174 GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); 181 GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
175 ui->current_user_username->setText(QString::fromStdString(username)); 182 ui->current_user_username->setText(username);
176} 183}
177 184
178void ConfigureSystem::ReadSystemSettings() {} 185void ConfigureSystem::ReadSystemSettings() {}
@@ -248,25 +255,23 @@ void ConfigureSystem::AddUser() {
248 255
249 profile_manager->CreateNewUser(uuid, username.toStdString()); 256 profile_manager->CreateNewUser(uuid, username.toStdString());
250 257
251 item_model->appendRow(new QStandardItem{ 258 item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)});
252 GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
253 QString::fromStdString(username.toStdString() + '\n' + uuid.FormatSwitch())});
254} 259}
255 260
256void ConfigureSystem::RenameUser() { 261void ConfigureSystem::RenameUser() {
257 const auto user = tree_view->currentIndex().row(); 262 const auto user = tree_view->currentIndex().row();
258 const auto uuid = profile_manager->GetUser(user); 263 const auto uuid = profile_manager->GetUser(user);
259 ASSERT(uuid != std::nullopt); 264 ASSERT(uuid != std::nullopt);
260 const auto username = GetAccountUsername(*profile_manager, *uuid);
261 265
262 Service::Account::ProfileBase profile; 266 Service::Account::ProfileBase profile;
263 if (!profile_manager->GetProfileBase(*uuid, profile)) 267 if (!profile_manager->GetProfileBase(*uuid, profile))
264 return; 268 return;
265 269
266 bool ok = false; 270 bool ok = false;
271 const auto old_username = GetAccountUsername(*profile_manager, *uuid);
267 const auto new_username = 272 const auto new_username =
268 QInputDialog::getText(this, tr("Enter Username"), tr("Enter a new username:"), 273 QInputDialog::getText(this, tr("Enter Username"), tr("Enter a new username:"),
269 QLineEdit::Normal, QString::fromStdString(username), &ok); 274 QLineEdit::Normal, old_username, &ok);
270 275
271 if (!ok) 276 if (!ok)
272 return; 277 return;
@@ -284,12 +289,8 @@ void ConfigureSystem::RenameUser() {
284 289
285 item_model->setItem( 290 item_model->setItem(
286 user, 0, 291 user, 0,
287 new QStandardItem{ 292 new QStandardItem{GetIcon(*uuid),
288 GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), 293 FormatUserEntryText(QString::fromStdString(username_std), *uuid)});
289 tr("%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. "
290 "00112233-4455-6677-8899-AABBCCDDEEFF))")
291 .arg(QString::fromStdString(username_std),
292 QString::fromStdString(uuid->FormatSwitch()))});
293 UpdateCurrentUser(); 294 UpdateCurrentUser();
294} 295}
295 296
@@ -299,10 +300,9 @@ void ConfigureSystem::DeleteUser() {
299 ASSERT(uuid != std::nullopt); 300 ASSERT(uuid != std::nullopt);
300 const auto username = GetAccountUsername(*profile_manager, *uuid); 301 const auto username = GetAccountUsername(*profile_manager, *uuid);
301 302
302 const auto confirm = 303 const auto confirm = QMessageBox::question(
303 QMessageBox::question(this, tr("Confirm Delete"), 304 this, tr("Confirm Delete"),
304 tr("You are about to delete user with name %1. Are you sure?") 305 tr("You are about to delete user with name \"%1\". Are you sure?").arg(username));
305 .arg(QString::fromStdString(username)));
306 306
307 if (confirm == QMessageBox::No) 307 if (confirm == QMessageBox::No)
308 return; 308 return;
@@ -325,28 +325,47 @@ void ConfigureSystem::SetUserImage() {
325 const auto index = tree_view->currentIndex().row(); 325 const auto index = tree_view->currentIndex().row();
326 const auto uuid = profile_manager->GetUser(index); 326 const auto uuid = profile_manager->GetUser(index);
327 ASSERT(uuid != std::nullopt); 327 ASSERT(uuid != std::nullopt);
328 const auto username = GetAccountUsername(*profile_manager, *uuid);
329 328
330 const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), 329 const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(),
331 tr("JPEG Images (*.jpg *.jpeg)")); 330 tr("JPEG Images (*.jpg *.jpeg)"));
332 331
333 if (file.isEmpty()) 332 if (file.isEmpty()) {
334 return; 333 return;
334 }
335
336 const auto image_path = GetImagePath(*uuid);
337 if (QFile::exists(image_path) && !QFile::remove(image_path)) {
338 QMessageBox::warning(
339 this, tr("Error deleting image"),
340 tr("Error occurred attempting to overwrite previous image at: %1.").arg(image_path));
341 return;
342 }
335 343
336 FileUtil::Delete(GetImagePath(*uuid)); 344 const auto raw_path = QString::fromStdString(
345 FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010");
346 const QFileInfo raw_info{raw_path};
347 if (raw_info.exists() && !raw_info.isDir() && !QFile::remove(raw_path)) {
348 QMessageBox::warning(this, tr("Error deleting file"),
349 tr("Unable to delete existing file: %1.").arg(raw_path));
350 return;
351 }
337 352
338 const auto raw_path = 353 const QString absolute_dst_path = QFileInfo{image_path}.absolutePath();
339 FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"; 354 if (!QDir{raw_path}.mkpath(absolute_dst_path)) {
340 if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path)) 355 QMessageBox::warning(
341 FileUtil::Delete(raw_path); 356 this, tr("Error creating user image directory"),
357 tr("Unable to create directory %1 for storing user images.").arg(absolute_dst_path));
358 return;
359 }
342 360
343 FileUtil::CreateFullPath(GetImagePath(*uuid)); 361 if (!QFile::copy(file, image_path)) {
344 FileUtil::Copy(file.toStdString(), GetImagePath(*uuid)); 362 QMessageBox::warning(this, tr("Error copying user image"),
363 tr("Unable to copy image from %1 to %2").arg(file, image_path));
364 return;
365 }
345 366
346 item_model->setItem( 367 const auto username = GetAccountUsername(*profile_manager, *uuid);
347 index, 0, 368 item_model->setItem(index, 0,
348 new QStandardItem{ 369 new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)});
349 GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
350 QString::fromStdString(username + '\n' + uuid->FormatSwitch())});
351 UpdateCurrentUser(); 370 UpdateCurrentUser();
352} 371}