GameFile: Use enums for custom/length parameters

This commit is contained in:
JosJuice 2019-09-25 11:36:45 +02:00
parent 59f27ae4e1
commit d8958fbdf7
6 changed files with 32 additions and 18 deletions

View File

@ -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, JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env,
jobject obj) 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, JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env,
jobject obj) 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, JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCompany(JNIEnv* env,

View File

@ -73,7 +73,7 @@ QGroupBox* InfoWidget::CreateISODetails()
QLineEdit* country = CreateValueDisplay(DiscIO::GetName(m_game.GetCountry(), true)); 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 = QLineEdit* maker =
CreateValueDisplay((game_maker.empty() ? UNKNOWN_NAME.toStdString() : game_maker) + " (" + CreateValueDisplay((game_maker.empty() ? UNKNOWN_NAME.toStdString() : game_maker) + " (" +

View File

@ -442,7 +442,7 @@ void GameList::ExportWiiSave()
for (const auto& game : GetSelectedGames()) for (const auto& game : GetSelectedGames())
{ {
if (!WiiSave::Export(game->GetTitleID(), export_dir.toStdString())) 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()) if (!failed.isEmpty())

View File

@ -124,13 +124,17 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
case COL_DESCRIPTION: case COL_DESCRIPTION:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) 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(' ')); .replace(QLatin1Char('\n'), QLatin1Char(' '));
} }
break; break;
case COL_MAKER: case COL_MAKER:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
return QString::fromStdString(game.GetMaker(true)); {
return QString::fromStdString(
game.GetMaker(UICommon::GameFile::Variant::LongAndPossiblyCustom));
}
break; break;
case COL_FILE_NAME: case COL_FILE_NAME:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)

View File

@ -472,15 +472,15 @@ const std::string& GameFile::GetName(const Core::TitleDatabase& title_database)
return m_custom_name; return m_custom_name;
const std::string& database_name = title_database.GetTitleName(m_gametdb_id, GetConfigLanguage()); 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; return m_custom_name;
const std::string& name = long_name ? GetLongName() : GetShortName(); const std::string& name = variant == Variant::ShortAndNotCustom ? GetShortName() : GetLongName();
if (!name.empty()) if (!name.empty())
return name; return name;
@ -488,12 +488,13 @@ const std::string& GameFile::GetName(bool allow_custom_name, bool long_name) con
return m_file_name; 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; return m_custom_maker;
const std::string& maker = long_maker ? GetLongMaker() : GetShortMaker(); const std::string& maker =
variant == Variant::ShortAndNotCustom ? GetShortMaker() : GetLongMaker();
if (!maker.empty()) if (!maker.empty())
return maker; return maker;
@ -503,9 +504,9 @@ const std::string& GameFile::GetMaker(bool allow_custom_maker, bool long_maker)
return EMPTY_STRING; 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 m_custom_description;
return LookupUsingConfigLanguage(m_descriptions); return LookupUsingConfigLanguage(m_descriptions);

View File

@ -44,6 +44,13 @@ bool operator!=(const GameBanner& lhs, const GameBanner& rhs);
class GameFile final class GameFile final
{ {
public: public:
enum class Variant
{
LongAndPossiblyCustom,
LongAndNotCustom,
ShortAndNotCustom,
};
GameFile(); GameFile();
explicit GameFile(std::string path); explicit GameFile(std::string path);
~GameFile(); ~GameFile();
@ -52,8 +59,8 @@ public:
const std::string& GetFilePath() const { return m_file_path; } const std::string& GetFilePath() const { return m_file_path; }
const std::string& GetFileName() const { return m_file_name; } const std::string& GetFileName() const { return m_file_name; }
const std::string& GetName(const Core::TitleDatabase& title_database) const; 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& GetName(Variant variant) const;
const std::string& GetMaker(bool allow_custom_maker, bool long_maker = true) 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(DiscIO::Language l) const { return Lookup(l, m_short_names); }
const std::string& GetShortName() const { return LookupUsingConfigLanguage(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); } 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(DiscIO::Language l) const { return Lookup(l, m_long_makers); }
const std::string& GetLongMaker() const { return LookupUsingConfigLanguage(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(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<DiscIO::Language> GetLanguages() const; std::vector<DiscIO::Language> GetLanguages() const;
const std::string& GetInternalName() const { return m_internal_name; } const std::string& GetInternalName() const { return m_internal_name; }
const std::string& GetGameID() const { return m_game_id; } const std::string& GetGameID() const { return m_game_id; }