Skip to content
Permalink
Browse files

GameFile: Use enums for custom/length parameters

  • Loading branch information
JosJuice committed Sep 25, 2019
1 parent 59f27ae commit d8958fbdf7fa123d61c453989483b7116727d4be
@@ -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,
@@ -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) + " (" +
@@ -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())
@@ -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)
@@ -472,28 +472,29 @@ 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;

// No usable name, return filename (better than nothing)
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);
@@ -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 @@ class GameFile final
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 @@ class GameFile final
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<DiscIO::Language> GetLanguages() const;
const std::string& GetInternalName() const { return m_internal_name; }
const std::string& GetGameID() const { return m_game_id; }

0 comments on commit d8958fb

Please sign in to comment.
You can’t perform that action at this time.