diff options
| author | 2019-05-20 15:18:36 -0400 | |
|---|---|---|
| committer | 2019-05-20 15:30:50 -0400 | |
| commit | bc3247490154bdeed40e630c801616e4535b7e0d (patch) | |
| tree | 76652a1460082e5b4934ad67197e5292913e733b /src | |
| parent | yuzu/game_list_worker: Specify string conversions explicitly (diff) | |
| download | yuzu-bc3247490154bdeed40e630c801616e4535b7e0d.tar.gz yuzu-bc3247490154bdeed40e630c801616e4535b7e0d.tar.xz yuzu-bc3247490154bdeed40e630c801616e4535b7e0d.zip | |
yuzu/game_list: Specify string conversions explicitly
Allows the game list code to compile successfully with implicit string
conversions disabled.
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/game_list.cpp | 103 | ||||
| -rw-r--r-- | src/yuzu/game_list.h | 2 |
2 files changed, 55 insertions, 50 deletions
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index b0ca766ec..83d675773 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -14,7 +14,6 @@ | |||
| 14 | #include <QMenu> | 14 | #include <QMenu> |
| 15 | #include <QThreadPool> | 15 | #include <QThreadPool> |
| 16 | #include <fmt/format.h> | 16 | #include <fmt/format.h> |
| 17 | #include "common/common_paths.h" | ||
| 18 | #include "common/common_types.h" | 17 | #include "common/common_types.h" |
| 19 | #include "common/logging/log.h" | 18 | #include "common/logging/log.h" |
| 20 | #include "core/file_sys/patch_manager.h" | 19 | #include "core/file_sys/patch_manager.h" |
| @@ -48,7 +47,7 @@ bool GameListSearchField::KeyReleaseEater::eventFilter(QObject* obj, QEvent* eve | |||
| 48 | return QObject::eventFilter(obj, event); | 47 | return QObject::eventFilter(obj, event); |
| 49 | } else { | 48 | } else { |
| 50 | gamelist->search_field->edit_filter->clear(); | 49 | gamelist->search_field->edit_filter->clear(); |
| 51 | edit_filter_text = ""; | 50 | edit_filter_text.clear(); |
| 52 | } | 51 | } |
| 53 | break; | 52 | break; |
| 54 | } | 53 | } |
| @@ -71,9 +70,9 @@ bool GameListSearchField::KeyReleaseEater::eventFilter(QObject* obj, QEvent* eve | |||
| 71 | } | 70 | } |
| 72 | if (resultCount == 1) { | 71 | if (resultCount == 1) { |
| 73 | // To avoid loading error dialog loops while confirming them using enter | 72 | // To avoid loading error dialog loops while confirming them using enter |
| 74 | // Also users usually want to run a diffrent game after closing one | 73 | // Also users usually want to run a different game after closing one |
| 75 | gamelist->search_field->edit_filter->setText(""); | 74 | gamelist->search_field->edit_filter->clear(); |
| 76 | edit_filter_text = ""; | 75 | edit_filter_text.clear(); |
| 77 | emit gamelist->GameChosen(file_path); | 76 | emit gamelist->GameChosen(file_path); |
| 78 | } else { | 77 | } else { |
| 79 | return QObject::eventFilter(obj, event); | 78 | return QObject::eventFilter(obj, event); |
| @@ -93,7 +92,7 @@ void GameListSearchField::setFilterResult(int visible, int total) { | |||
| 93 | } | 92 | } |
| 94 | 93 | ||
| 95 | void GameListSearchField::clear() { | 94 | void GameListSearchField::clear() { |
| 96 | edit_filter->setText(""); | 95 | edit_filter->clear(); |
| 97 | } | 96 | } |
| 98 | 97 | ||
| 99 | void GameListSearchField::setFocus() { | 98 | void GameListSearchField::setFocus() { |
| @@ -103,25 +102,26 @@ void GameListSearchField::setFocus() { | |||
| 103 | } | 102 | } |
| 104 | 103 | ||
| 105 | GameListSearchField::GameListSearchField(GameList* parent) : QWidget{parent} { | 104 | GameListSearchField::GameListSearchField(GameList* parent) : QWidget{parent} { |
| 106 | KeyReleaseEater* keyReleaseEater = new KeyReleaseEater(parent); | 105 | auto* const key_release_eater = new KeyReleaseEater(parent); |
| 107 | layout_filter = new QHBoxLayout; | 106 | layout_filter = new QHBoxLayout; |
| 108 | layout_filter->setMargin(8); | 107 | layout_filter->setMargin(8); |
| 109 | label_filter = new QLabel; | 108 | label_filter = new QLabel; |
| 110 | label_filter->setText(tr("Filter:")); | 109 | label_filter->setText(tr("Filter:")); |
| 111 | edit_filter = new QLineEdit; | 110 | edit_filter = new QLineEdit; |
| 112 | edit_filter->setText(""); | 111 | edit_filter->clear(); |
| 113 | edit_filter->setPlaceholderText(tr("Enter pattern to filter")); | 112 | edit_filter->setPlaceholderText(tr("Enter pattern to filter")); |
| 114 | edit_filter->installEventFilter(keyReleaseEater); | 113 | edit_filter->installEventFilter(key_release_eater); |
| 115 | edit_filter->setClearButtonEnabled(true); | 114 | edit_filter->setClearButtonEnabled(true); |
| 116 | connect(edit_filter, &QLineEdit::textChanged, parent, &GameList::onTextChanged); | 115 | connect(edit_filter, &QLineEdit::textChanged, parent, &GameList::onTextChanged); |
| 117 | label_filter_result = new QLabel; | 116 | label_filter_result = new QLabel; |
| 118 | button_filter_close = new QToolButton(this); | 117 | button_filter_close = new QToolButton(this); |
| 119 | button_filter_close->setText("X"); | 118 | button_filter_close->setText(QStringLiteral("X")); |
| 120 | button_filter_close->setCursor(Qt::ArrowCursor); | 119 | button_filter_close->setCursor(Qt::ArrowCursor); |
| 121 | button_filter_close->setStyleSheet("QToolButton{ border: none; padding: 0px; color: " | 120 | button_filter_close->setStyleSheet( |
| 122 | "#000000; font-weight: bold; background: #F0F0F0; }" | 121 | QStringLiteral("QToolButton{ border: none; padding: 0px; color: " |
| 123 | "QToolButton:hover{ border: none; padding: 0px; color: " | 122 | "#000000; font-weight: bold; background: #F0F0F0; }" |
| 124 | "#EEEEEE; font-weight: bold; background: #E81123}"); | 123 | "QToolButton:hover{ border: none; padding: 0px; color: " |
| 124 | "#EEEEEE; font-weight: bold; background: #E81123}")); | ||
| 125 | connect(button_filter_close, &QToolButton::clicked, parent, &GameList::onFilterCloseClicked); | 125 | connect(button_filter_close, &QToolButton::clicked, parent, &GameList::onFilterCloseClicked); |
| 126 | layout_filter->setSpacing(10); | 126 | layout_filter->setSpacing(10); |
| 127 | layout_filter->addWidget(label_filter); | 127 | layout_filter->addWidget(label_filter); |
| @@ -141,36 +141,34 @@ GameListSearchField::GameListSearchField(GameList* parent) : QWidget{parent} { | |||
| 141 | */ | 141 | */ |
| 142 | static bool ContainsAllWords(const QString& haystack, const QString& userinput) { | 142 | static bool ContainsAllWords(const QString& haystack, const QString& userinput) { |
| 143 | const QStringList userinput_split = | 143 | const QStringList userinput_split = |
| 144 | userinput.split(' ', QString::SplitBehavior::SkipEmptyParts); | 144 | userinput.split(QLatin1Char{' '}, QString::SplitBehavior::SkipEmptyParts); |
| 145 | 145 | ||
| 146 | return std::all_of(userinput_split.begin(), userinput_split.end(), | 146 | return std::all_of(userinput_split.begin(), userinput_split.end(), |
| 147 | [&haystack](const QString& s) { return haystack.contains(s); }); | 147 | [&haystack](const QString& s) { return haystack.contains(s); }); |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | // Event in order to filter the gamelist after editing the searchfield | 150 | // Event in order to filter the gamelist after editing the searchfield |
| 151 | void GameList::onTextChanged(const QString& newText) { | 151 | void GameList::onTextChanged(const QString& new_text) { |
| 152 | int rowCount = tree_view->model()->rowCount(); | 152 | const int row_count = tree_view->model()->rowCount(); |
| 153 | QString edit_filter_text = newText.toLower(); | 153 | const QString edit_filter_text = new_text.toLower(); |
| 154 | 154 | const QModelIndex root_index = item_model->invisibleRootItem()->index(); | |
| 155 | QModelIndex root_index = item_model->invisibleRootItem()->index(); | ||
| 156 | 155 | ||
| 157 | // If the searchfield is empty every item is visible | 156 | // If the searchfield is empty every item is visible |
| 158 | // Otherwise the filter gets applied | 157 | // Otherwise the filter gets applied |
| 159 | if (edit_filter_text.isEmpty()) { | 158 | if (edit_filter_text.isEmpty()) { |
| 160 | for (int i = 0; i < rowCount; ++i) { | 159 | for (int i = 0; i < row_count; ++i) { |
| 161 | tree_view->setRowHidden(i, root_index, false); | 160 | tree_view->setRowHidden(i, root_index, false); |
| 162 | } | 161 | } |
| 163 | search_field->setFilterResult(rowCount, rowCount); | 162 | search_field->setFilterResult(row_count, row_count); |
| 164 | } else { | 163 | } else { |
| 165 | int result_count = 0; | 164 | int result_count = 0; |
| 166 | for (int i = 0; i < rowCount; ++i) { | 165 | for (int i = 0; i < row_count; ++i) { |
| 167 | const QStandardItem* child_file = item_model->item(i, 0); | 166 | const QStandardItem* child_file = item_model->item(i, 0); |
| 168 | const QString file_path = | 167 | const QString file_path = |
| 169 | child_file->data(GameListItemPath::FullPathRole).toString().toLower(); | 168 | child_file->data(GameListItemPath::FullPathRole).toString().toLower(); |
| 170 | QString file_name = file_path.mid(file_path.lastIndexOf('/') + 1); | ||
| 171 | const QString file_title = | 169 | const QString file_title = |
| 172 | child_file->data(GameListItemPath::TitleRole).toString().toLower(); | 170 | child_file->data(GameListItemPath::TitleRole).toString().toLower(); |
| 173 | const QString file_programmid = | 171 | const QString file_program_id = |
| 174 | child_file->data(GameListItemPath::ProgramIdRole).toString().toLower(); | 172 | child_file->data(GameListItemPath::ProgramIdRole).toString().toLower(); |
| 175 | 173 | ||
| 176 | // Only items which filename in combination with its title contains all words | 174 | // Only items which filename in combination with its title contains all words |
| @@ -178,14 +176,16 @@ void GameList::onTextChanged(const QString& newText) { | |||
| 178 | // The search is case insensitive because of toLower() | 176 | // The search is case insensitive because of toLower() |
| 179 | // I decided not to use Qt::CaseInsensitive in containsAllWords to prevent | 177 | // I decided not to use Qt::CaseInsensitive in containsAllWords to prevent |
| 180 | // multiple conversions of edit_filter_text for each game in the gamelist | 178 | // multiple conversions of edit_filter_text for each game in the gamelist |
| 181 | if (ContainsAllWords(file_name.append(' ').append(file_title), edit_filter_text) || | 179 | const QString file_name = file_path.mid(file_path.lastIndexOf(QLatin1Char{'/'}) + 1) + |
| 182 | (file_programmid.count() == 16 && edit_filter_text.contains(file_programmid))) { | 180 | QLatin1Char{' '} + file_title; |
| 181 | if (ContainsAllWords(file_name, edit_filter_text) || | ||
| 182 | (file_program_id.count() == 16 && edit_filter_text.contains(file_program_id))) { | ||
| 183 | tree_view->setRowHidden(i, root_index, false); | 183 | tree_view->setRowHidden(i, root_index, false); |
| 184 | ++result_count; | 184 | ++result_count; |
| 185 | } else { | 185 | } else { |
| 186 | tree_view->setRowHidden(i, root_index, true); | 186 | tree_view->setRowHidden(i, root_index, true); |
| 187 | } | 187 | } |
| 188 | search_field->setFilterResult(result_count, rowCount); | 188 | search_field->setFilterResult(result_count, row_count); |
| 189 | } | 189 | } |
| 190 | } | 190 | } |
| 191 | } | 191 | } |
| @@ -216,7 +216,7 @@ GameList::GameList(FileSys::VirtualFilesystem vfs, FileSys::ManualContentProvide | |||
| 216 | tree_view->setEditTriggers(QHeaderView::NoEditTriggers); | 216 | tree_view->setEditTriggers(QHeaderView::NoEditTriggers); |
| 217 | tree_view->setUniformRowHeights(true); | 217 | tree_view->setUniformRowHeights(true); |
| 218 | tree_view->setContextMenuPolicy(Qt::CustomContextMenu); | 218 | tree_view->setContextMenuPolicy(Qt::CustomContextMenu); |
| 219 | tree_view->setStyleSheet("QTreeView{ border: none; }"); | 219 | tree_view->setStyleSheet(QStringLiteral("QTreeView{ border: none; }")); |
| 220 | 220 | ||
| 221 | item_model->insertColumns(0, UISettings::values.show_add_ons ? COLUMN_COUNT : COLUMN_COUNT - 1); | 221 | item_model->insertColumns(0, UISettings::values.show_add_ons ? COLUMN_COUNT : COLUMN_COUNT - 1); |
| 222 | item_model->setHeaderData(COLUMN_NAME, Qt::Horizontal, tr("Name")); | 222 | item_model->setHeaderData(COLUMN_NAME, Qt::Horizontal, tr("Name")); |
| @@ -282,9 +282,9 @@ void GameList::ValidateEntry(const QModelIndex& item) { | |||
| 282 | const QFileInfo file_info{file_path}; | 282 | const QFileInfo file_info{file_path}; |
| 283 | if (file_info.isDir()) { | 283 | if (file_info.isDir()) { |
| 284 | const QDir dir{file_path}; | 284 | const QDir dir{file_path}; |
| 285 | const QStringList matching_main = dir.entryList(QStringList("main"), QDir::Files); | 285 | const QStringList matching_main = dir.entryList({QStringLiteral("main")}, QDir::Files); |
| 286 | if (matching_main.size() == 1) { | 286 | if (matching_main.size() == 1) { |
| 287 | emit GameChosen(dir.path() + DIR_SEP + matching_main[0]); | 287 | emit GameChosen(dir.path() + QDir::separator() + matching_main[0]); |
| 288 | } | 288 | } |
| 289 | return; | 289 | return; |
| 290 | } | 290 | } |
| @@ -360,7 +360,7 @@ void GameList::PopupContextMenu(const QPoint& menu_location) { | |||
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | void GameList::LoadCompatibilityList() { | 362 | void GameList::LoadCompatibilityList() { |
| 363 | QFile compat_list{":compatibility_list/compatibility_list.json"}; | 363 | QFile compat_list{QStringLiteral(":compatibility_list/compatibility_list.json")}; |
| 364 | 364 | ||
| 365 | if (!compat_list.open(QFile::ReadOnly | QFile::Text)) { | 365 | if (!compat_list.open(QFile::ReadOnly | QFile::Text)) { |
| 366 | LOG_ERROR(Frontend, "Unable to open game compatibility list"); | 366 | LOG_ERROR(Frontend, "Unable to open game compatibility list"); |
| @@ -378,25 +378,27 @@ void GameList::LoadCompatibilityList() { | |||
| 378 | return; | 378 | return; |
| 379 | } | 379 | } |
| 380 | 380 | ||
| 381 | const QString string_content = content; | 381 | const QJsonDocument json = QJsonDocument::fromJson(content); |
| 382 | QJsonDocument json = QJsonDocument::fromJson(string_content.toUtf8()); | 382 | const QJsonArray arr = json.array(); |
| 383 | QJsonArray arr = json.array(); | ||
| 384 | 383 | ||
| 385 | for (const QJsonValueRef value : arr) { | 384 | for (const QJsonValue value : arr) { |
| 386 | QJsonObject game = value.toObject(); | 385 | const QJsonObject game = value.toObject(); |
| 386 | const QString compatibility_key = QStringLiteral("compatibility"); | ||
| 387 | 387 | ||
| 388 | if (game.contains("compatibility") && game["compatibility"].isDouble()) { | 388 | if (!game.contains(compatibility_key) || !game[compatibility_key].isDouble()) { |
| 389 | int compatibility = game["compatibility"].toInt(); | 389 | continue; |
| 390 | QString directory = game["directory"].toString(); | 390 | } |
| 391 | QJsonArray ids = game["releases"].toArray(); | ||
| 392 | 391 | ||
| 393 | for (const QJsonValueRef id_ref : ids) { | 392 | const int compatibility = game[compatibility_key].toInt(); |
| 394 | QJsonObject id_object = id_ref.toObject(); | 393 | const QString directory = game[QStringLiteral("directory")].toString(); |
| 395 | QString id = id_object["id"].toString(); | 394 | const QJsonArray ids = game[QStringLiteral("releases")].toArray(); |
| 396 | compatibility_list.emplace( | 395 | |
| 397 | id.toUpper().toStdString(), | 396 | for (const QJsonValue id_ref : ids) { |
| 398 | std::make_pair(QString::number(compatibility), directory)); | 397 | const QJsonObject id_object = id_ref.toObject(); |
| 399 | } | 398 | const QString id = id_object[QStringLiteral("id")].toString(); |
| 399 | |||
| 400 | compatibility_list.emplace(id.toUpper().toStdString(), | ||
| 401 | std::make_pair(QString::number(compatibility), directory)); | ||
| 400 | } | 402 | } |
| 401 | } | 403 | } |
| 402 | } | 404 | } |
| @@ -464,7 +466,10 @@ void GameList::LoadInterfaceLayout() { | |||
| 464 | item_model->sort(header->sortIndicatorSection(), header->sortIndicatorOrder()); | 466 | item_model->sort(header->sortIndicatorSection(), header->sortIndicatorOrder()); |
| 465 | } | 467 | } |
| 466 | 468 | ||
| 467 | const QStringList GameList::supported_file_extensions = {"nso", "nro", "nca", "xci", "nsp"}; | 469 | const QStringList GameList::supported_file_extensions = { |
| 470 | QStringLiteral("nso"), QStringLiteral("nro"), QStringLiteral("nca"), | ||
| 471 | QStringLiteral("xci"), QStringLiteral("nsp"), | ||
| 472 | }; | ||
| 468 | 473 | ||
| 469 | void GameList::RefreshGameDirectory() { | 474 | void GameList::RefreshGameDirectory() { |
| 470 | if (!UISettings::values.game_directory_path.isEmpty() && current_worker != nullptr) { | 475 | if (!UISettings::values.game_directory_path.isEmpty() && current_worker != nullptr) { |
diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index 56007eef8..f8f8bd6c5 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h | |||
| @@ -76,7 +76,7 @@ signals: | |||
| 76 | void OpenPerGameGeneralRequested(const std::string& file); | 76 | void OpenPerGameGeneralRequested(const std::string& file); |
| 77 | 77 | ||
| 78 | private slots: | 78 | private slots: |
| 79 | void onTextChanged(const QString& newText); | 79 | void onTextChanged(const QString& new_text); |
| 80 | void onFilterCloseClicked(); | 80 | void onFilterCloseClicked(); |
| 81 | 81 | ||
| 82 | private: | 82 | private: |