diff options
| author | 2018-11-01 19:10:26 -0400 | |
|---|---|---|
| committer | 2018-11-01 19:10:26 -0400 | |
| commit | 1069eced8482bd01be9fd305447ef94a82c4c999 (patch) | |
| tree | 5ed2254962898473242829701edef6fd323c6b6d /src | |
| parent | Merge pull request #1623 from Tinob/master (diff) | |
| parent | configure_system: Contrain profile usernames to 32 characters (diff) | |
| download | yuzu-1069eced8482bd01be9fd305447ef94a82c4c999.tar.gz yuzu-1069eced8482bd01be9fd305447ef94a82c4c999.tar.xz yuzu-1069eced8482bd01be9fd305447ef94a82c4c999.zip | |
Merge pull request #1615 from lioncash/input
configure_system: Contrain profile usernames to 32 characters
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 3 | ||||
| -rw-r--r-- | src/yuzu/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_system.cpp | 43 | ||||
| -rw-r--r-- | src/yuzu/util/limitable_input_dialog.cpp | 59 | ||||
| -rw-r--r-- | src/yuzu/util/limitable_input_dialog.h | 31 |
5 files changed, 113 insertions, 25 deletions
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index 1cd2e51b2..747c46c20 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h | |||
| @@ -57,7 +57,8 @@ struct UUID { | |||
| 57 | }; | 57 | }; |
| 58 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); | 58 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); |
| 59 | 59 | ||
| 60 | using ProfileUsername = std::array<u8, 0x20>; | 60 | constexpr std::size_t profile_username_size = 32; |
| 61 | using ProfileUsername = std::array<u8, profile_username_size>; | ||
| 61 | using ProfileData = std::array<u8, MAX_DATA>; | 62 | using ProfileData = std::array<u8, MAX_DATA>; |
| 62 | using UserIDArray = std::array<UUID, MAX_USERS>; | 63 | using UserIDArray = std::array<UUID, MAX_USERS>; |
| 63 | 64 | ||
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 9379d9110..f9ca2948e 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt | |||
| @@ -56,6 +56,8 @@ add_executable(yuzu | |||
| 56 | main.h | 56 | main.h |
| 57 | ui_settings.cpp | 57 | ui_settings.cpp |
| 58 | ui_settings.h | 58 | ui_settings.h |
| 59 | util/limitable_input_dialog.cpp | ||
| 60 | util/limitable_input_dialog.h | ||
| 59 | util/spinbox.cpp | 61 | util/spinbox.cpp |
| 60 | util/spinbox.h | 62 | util/spinbox.h |
| 61 | util/util.cpp | 63 | util/util.cpp |
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 1b8aa7de2..b4b4a4a56 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp | |||
| @@ -6,20 +6,20 @@ | |||
| 6 | #include <QFileDialog> | 6 | #include <QFileDialog> |
| 7 | #include <QGraphicsItem> | 7 | #include <QGraphicsItem> |
| 8 | #include <QGraphicsScene> | 8 | #include <QGraphicsScene> |
| 9 | #include <QInputDialog> | 9 | #include <QHeaderView> |
| 10 | #include <QMessageBox> | 10 | #include <QMessageBox> |
| 11 | #include <QStandardItemModel> | 11 | #include <QStandardItemModel> |
| 12 | #include <QTreeView> | 12 | #include <QTreeView> |
| 13 | #include <QVBoxLayout> | 13 | #include <QVBoxLayout> |
| 14 | #include "common/common_paths.h" | 14 | #include "common/assert.h" |
| 15 | #include "common/logging/backend.h" | 15 | #include "common/file_util.h" |
| 16 | #include "common/string_util.h" | 16 | #include "common/string_util.h" |
| 17 | #include "core/core.h" | 17 | #include "core/core.h" |
| 18 | #include "core/hle/service/acc/profile_manager.h" | 18 | #include "core/hle/service/acc/profile_manager.h" |
| 19 | #include "core/settings.h" | 19 | #include "core/settings.h" |
| 20 | #include "ui_configure_system.h" | 20 | #include "ui_configure_system.h" |
| 21 | #include "yuzu/configuration/configure_system.h" | 21 | #include "yuzu/configuration/configure_system.h" |
| 22 | #include "yuzu/main.h" | 22 | #include "yuzu/util/limitable_input_dialog.h" |
| 23 | 23 | ||
| 24 | namespace { | 24 | namespace { |
| 25 | constexpr std::array<int, 12> days_in_month = {{ | 25 | constexpr std::array<int, 12> days_in_month = {{ |
| @@ -83,6 +83,12 @@ QPixmap GetIcon(Service::Account::UUID uuid) { | |||
| 83 | 83 | ||
| 84 | return icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); | 84 | return icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
| 85 | } | 85 | } |
| 86 | |||
| 87 | QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_text) { | ||
| 88 | return LimitableInputDialog::GetText(parent, ConfigureSystem::tr("Enter Username"), | ||
| 89 | description_text, 1, | ||
| 90 | static_cast<int>(Service::Account::profile_username_size)); | ||
| 91 | } | ||
| 86 | } // Anonymous namespace | 92 | } // Anonymous namespace |
| 87 | 93 | ||
| 88 | ConfigureSystem::ConfigureSystem(QWidget* parent) | 94 | ConfigureSystem::ConfigureSystem(QWidget* parent) |
| @@ -244,15 +250,13 @@ void ConfigureSystem::SelectUser(const QModelIndex& index) { | |||
| 244 | } | 250 | } |
| 245 | 251 | ||
| 246 | void ConfigureSystem::AddUser() { | 252 | void ConfigureSystem::AddUser() { |
| 247 | const auto uuid = Service::Account::UUID::Generate(); | ||
| 248 | |||
| 249 | bool ok = false; | ||
| 250 | const auto username = | 253 | const auto username = |
| 251 | QInputDialog::getText(this, tr("Enter Username"), tr("Enter a username for the new user:"), | 254 | GetProfileUsernameFromUser(this, tr("Enter a username for the new user:")); |
| 252 | QLineEdit::Normal, QString(), &ok); | 255 | if (username.isEmpty()) { |
| 253 | if (!ok) | ||
| 254 | return; | 256 | return; |
| 257 | } | ||
| 255 | 258 | ||
| 259 | const auto uuid = Service::Account::UUID::Generate(); | ||
| 256 | profile_manager->CreateNewUser(uuid, username.toStdString()); | 260 | profile_manager->CreateNewUser(uuid, username.toStdString()); |
| 257 | 261 | ||
| 258 | item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); | 262 | item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); |
| @@ -267,23 +271,14 @@ void ConfigureSystem::RenameUser() { | |||
| 267 | if (!profile_manager->GetProfileBase(*uuid, profile)) | 271 | if (!profile_manager->GetProfileBase(*uuid, profile)) |
| 268 | return; | 272 | return; |
| 269 | 273 | ||
| 270 | bool ok = false; | 274 | const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:")); |
| 271 | const auto old_username = GetAccountUsername(*profile_manager, *uuid); | 275 | if (new_username.isEmpty()) { |
| 272 | const auto new_username = | ||
| 273 | QInputDialog::getText(this, tr("Enter Username"), tr("Enter a new username:"), | ||
| 274 | QLineEdit::Normal, old_username, &ok); | ||
| 275 | |||
| 276 | if (!ok) | ||
| 277 | return; | 276 | return; |
| 277 | } | ||
| 278 | 278 | ||
| 279 | std::fill(profile.username.begin(), profile.username.end(), '\0'); | ||
| 280 | const auto username_std = new_username.toStdString(); | 279 | const auto username_std = new_username.toStdString(); |
| 281 | if (username_std.size() > profile.username.size()) { | 280 | std::fill(profile.username.begin(), profile.username.end(), '\0'); |
| 282 | std::copy_n(username_std.begin(), std::min(profile.username.size(), username_std.size()), | 281 | std::copy(username_std.begin(), username_std.end(), profile.username.begin()); |
| 283 | profile.username.begin()); | ||
| 284 | } else { | ||
| 285 | std::copy(username_std.begin(), username_std.end(), profile.username.begin()); | ||
| 286 | } | ||
| 287 | 282 | ||
| 288 | profile_manager->SetProfileBase(*uuid, profile); | 283 | profile_manager->SetProfileBase(*uuid, profile); |
| 289 | 284 | ||
diff --git a/src/yuzu/util/limitable_input_dialog.cpp b/src/yuzu/util/limitable_input_dialog.cpp new file mode 100644 index 000000000..edd78e579 --- /dev/null +++ b/src/yuzu/util/limitable_input_dialog.cpp | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QDialogButtonBox> | ||
| 6 | #include <QLabel> | ||
| 7 | #include <QLineEdit> | ||
| 8 | #include <QPushButton> | ||
| 9 | #include <QVBoxLayout> | ||
| 10 | #include "yuzu/util/limitable_input_dialog.h" | ||
| 11 | |||
| 12 | LimitableInputDialog::LimitableInputDialog(QWidget* parent) : QDialog{parent} { | ||
| 13 | CreateUI(); | ||
| 14 | ConnectEvents(); | ||
| 15 | } | ||
| 16 | |||
| 17 | LimitableInputDialog::~LimitableInputDialog() = default; | ||
| 18 | |||
| 19 | void LimitableInputDialog::CreateUI() { | ||
| 20 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); | ||
| 21 | |||
| 22 | text_label = new QLabel(this); | ||
| 23 | text_entry = new QLineEdit(this); | ||
| 24 | buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | ||
| 25 | |||
| 26 | auto* const layout = new QVBoxLayout; | ||
| 27 | layout->addWidget(text_label); | ||
| 28 | layout->addWidget(text_entry); | ||
| 29 | layout->addWidget(buttons); | ||
| 30 | |||
| 31 | setLayout(layout); | ||
| 32 | } | ||
| 33 | |||
| 34 | void LimitableInputDialog::ConnectEvents() { | ||
| 35 | connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); | ||
| 36 | connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); | ||
| 37 | } | ||
| 38 | |||
| 39 | QString LimitableInputDialog::GetText(QWidget* parent, const QString& title, const QString& text, | ||
| 40 | int min_character_limit, int max_character_limit) { | ||
| 41 | Q_ASSERT(min_character_limit <= max_character_limit); | ||
| 42 | |||
| 43 | LimitableInputDialog dialog{parent}; | ||
| 44 | dialog.setWindowTitle(title); | ||
| 45 | dialog.text_label->setText(text); | ||
| 46 | dialog.text_entry->setMaxLength(max_character_limit); | ||
| 47 | |||
| 48 | auto* const ok_button = dialog.buttons->button(QDialogButtonBox::Ok); | ||
| 49 | ok_button->setEnabled(false); | ||
| 50 | connect(dialog.text_entry, &QLineEdit::textEdited, [&](const QString& new_text) { | ||
| 51 | ok_button->setEnabled(new_text.length() >= min_character_limit); | ||
| 52 | }); | ||
| 53 | |||
| 54 | if (dialog.exec() != QDialog::Accepted) { | ||
| 55 | return {}; | ||
| 56 | } | ||
| 57 | |||
| 58 | return dialog.text_entry->text(); | ||
| 59 | } | ||
diff --git a/src/yuzu/util/limitable_input_dialog.h b/src/yuzu/util/limitable_input_dialog.h new file mode 100644 index 000000000..164ad7301 --- /dev/null +++ b/src/yuzu/util/limitable_input_dialog.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <QDialog> | ||
| 8 | |||
| 9 | class QDialogButtonBox; | ||
| 10 | class QLabel; | ||
| 11 | class QLineEdit; | ||
| 12 | |||
| 13 | /// A QDialog that functions similarly to QInputDialog, however, it allows | ||
| 14 | /// restricting the minimum and total number of characters that can be entered. | ||
| 15 | class LimitableInputDialog final : public QDialog { | ||
| 16 | Q_OBJECT | ||
| 17 | public: | ||
| 18 | explicit LimitableInputDialog(QWidget* parent = nullptr); | ||
| 19 | ~LimitableInputDialog() override; | ||
| 20 | |||
| 21 | static QString GetText(QWidget* parent, const QString& title, const QString& text, | ||
| 22 | int min_character_limit, int max_character_limit); | ||
| 23 | |||
| 24 | private: | ||
| 25 | void CreateUI(); | ||
| 26 | void ConnectEvents(); | ||
| 27 | |||
| 28 | QLabel* text_label; | ||
| 29 | QLineEdit* text_entry; | ||
| 30 | QDialogButtonBox* buttons; | ||
| 31 | }; | ||