From d8958fbdf7fa123d61c453989483b7116727d4be Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 25 Sep 2019 11:36:45 +0200 Subject: [PATCH] GameFile: Use enums for custom/length parameters --- Source/Android/jni/GameList/GameFile.cpp | 6 ++++-- Source/Core/DolphinQt/Config/InfoWidget.cpp | 2 +- Source/Core/DolphinQt/GameList/GameList.cpp | 2 +- .../Core/DolphinQt/GameList/GameListModel.cpp | 8 ++++++-- Source/Core/UICommon/GameFile.cpp | 19 ++++++++++--------- Source/Core/UICommon/GameFile.h | 13 ++++++++++--- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Source/Android/jni/GameList/GameFile.cpp b/Source/Android/jni/GameList/GameFile.cpp index b43f7b4402..419a4694a5 100644 --- a/Source/Android/jni/GameList/GameFile.cpp +++ b/Source/Android/jni/GameList/GameFile.cpp @@ -84,13 +84,15 @@ JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPlatform JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env, jobject obj) { - return ToJString(env, GetRef(env, obj)->GetName(true)); + return ToJString(env, + GetRef(env, obj)->GetName(UICommon::GameFile::Variant::LongAndPossiblyCustom)); } JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env, jobject obj) { - return ToJString(env, GetRef(env, obj)->GetDescription(true)); + return ToJString( + env, GetRef(env, obj)->GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom)); } JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCompany(JNIEnv* env, diff --git a/Source/Core/DolphinQt/Config/InfoWidget.cpp b/Source/Core/DolphinQt/Config/InfoWidget.cpp index ad96cc25f9..416c1a8866 100644 --- a/Source/Core/DolphinQt/Config/InfoWidget.cpp +++ b/Source/Core/DolphinQt/Config/InfoWidget.cpp @@ -73,7 +73,7 @@ QGroupBox* InfoWidget::CreateISODetails() QLineEdit* country = CreateValueDisplay(DiscIO::GetName(m_game.GetCountry(), true)); - const std::string game_maker = m_game.GetMaker(false); + const std::string game_maker = m_game.GetMaker(UICommon::GameFile::Variant::LongAndNotCustom); QLineEdit* maker = CreateValueDisplay((game_maker.empty() ? UNKNOWN_NAME.toStdString() : game_maker) + " (" + diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index f75422f992..ae6266e99e 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -442,7 +442,7 @@ void GameList::ExportWiiSave() for (const auto& game : GetSelectedGames()) { if (!WiiSave::Export(game->GetTitleID(), export_dir.toStdString())) - failed.push_back(game->GetName(true)); + failed.push_back(game->GetName(UICommon::GameFile::Variant::LongAndPossiblyCustom)); } if (!failed.isEmpty()) diff --git a/Source/Core/DolphinQt/GameList/GameListModel.cpp b/Source/Core/DolphinQt/GameList/GameListModel.cpp index 923befda47..2baf8925a7 100644 --- a/Source/Core/DolphinQt/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt/GameList/GameListModel.cpp @@ -124,13 +124,17 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const case COL_DESCRIPTION: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) { - return QString::fromStdString(game.GetDescription(true)) + return QString::fromStdString( + game.GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom)) .replace(QLatin1Char('\n'), QLatin1Char(' ')); } break; case COL_MAKER: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) - return QString::fromStdString(game.GetMaker(true)); + { + return QString::fromStdString( + game.GetMaker(UICommon::GameFile::Variant::LongAndPossiblyCustom)); + } break; case COL_FILE_NAME: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index d29f5ad2ae..53b993a676 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -472,15 +472,15 @@ const std::string& GameFile::GetName(const Core::TitleDatabase& title_database) return m_custom_name; const std::string& database_name = title_database.GetTitleName(m_gametdb_id, GetConfigLanguage()); - return database_name.empty() ? GetName(true) : database_name; + return database_name.empty() ? GetName(Variant::LongAndPossiblyCustom) : database_name; } -const std::string& GameFile::GetName(bool allow_custom_name, bool long_name) const +const std::string& GameFile::GetName(Variant variant) const { - if (allow_custom_name && !m_custom_name.empty()) + if (variant == Variant::LongAndPossiblyCustom && !m_custom_name.empty()) return m_custom_name; - const std::string& name = long_name ? GetLongName() : GetShortName(); + const std::string& name = variant == Variant::ShortAndNotCustom ? GetShortName() : GetLongName(); if (!name.empty()) return name; @@ -488,12 +488,13 @@ const std::string& GameFile::GetName(bool allow_custom_name, bool long_name) con return m_file_name; } -const std::string& GameFile::GetMaker(bool allow_custom_maker, bool long_maker) const +const std::string& GameFile::GetMaker(Variant variant) const { - if (allow_custom_maker && !m_custom_maker.empty()) + if (variant == Variant::LongAndPossiblyCustom && !m_custom_maker.empty()) return m_custom_maker; - const std::string& maker = long_maker ? GetLongMaker() : GetShortMaker(); + const std::string& maker = + variant == Variant::ShortAndNotCustom ? GetShortMaker() : GetLongMaker(); if (!maker.empty()) return maker; @@ -503,9 +504,9 @@ const std::string& GameFile::GetMaker(bool allow_custom_maker, bool long_maker) return EMPTY_STRING; } -const std::string& GameFile::GetDescription(bool allow_custom_description) const +const std::string& GameFile::GetDescription(Variant variant) const { - if (allow_custom_description && !m_custom_description.empty()) + if (variant == Variant::LongAndPossiblyCustom && !m_custom_description.empty()) return m_custom_description; return LookupUsingConfigLanguage(m_descriptions); diff --git a/Source/Core/UICommon/GameFile.h b/Source/Core/UICommon/GameFile.h index f783d9cac0..87513118a9 100644 --- a/Source/Core/UICommon/GameFile.h +++ b/Source/Core/UICommon/GameFile.h @@ -44,6 +44,13 @@ bool operator!=(const GameBanner& lhs, const GameBanner& rhs); class GameFile final { public: + enum class Variant + { + LongAndPossiblyCustom, + LongAndNotCustom, + ShortAndNotCustom, + }; + GameFile(); explicit GameFile(std::string path); ~GameFile(); @@ -52,8 +59,8 @@ public: const std::string& GetFilePath() const { return m_file_path; } const std::string& GetFileName() const { return m_file_name; } const std::string& GetName(const Core::TitleDatabase& title_database) const; - const std::string& GetName(bool allow_custom_name, bool long_name = true) const; - const std::string& GetMaker(bool allow_custom_maker, bool long_maker = true) const; + const std::string& GetName(Variant variant) const; + const std::string& GetMaker(Variant variant) const; const std::string& GetShortName(DiscIO::Language l) const { return Lookup(l, m_short_names); } const std::string& GetShortName() const { return LookupUsingConfigLanguage(m_short_names); } const std::string& GetLongName(DiscIO::Language l) const { return Lookup(l, m_long_names); } @@ -63,7 +70,7 @@ public: const std::string& GetLongMaker(DiscIO::Language l) const { return Lookup(l, m_long_makers); } const std::string& GetLongMaker() const { return LookupUsingConfigLanguage(m_long_makers); } const std::string& GetDescription(DiscIO::Language l) const { return Lookup(l, m_descriptions); } - const std::string& GetDescription(bool allow_custom_description) const; + const std::string& GetDescription(Variant variant) const; std::vector GetLanguages() const; const std::string& GetInternalName() const { return m_internal_name; } const std::string& GetGameID() const { return m_game_id; }