Qt: use config to load translation file on startup

This commit is contained in:
Megamouse 2020-02-04 13:40:02 +01:00
parent 0bba04ef8d
commit efe907ffae
24 changed files with 835 additions and 635 deletions

View file

@ -293,7 +293,7 @@ bool game_list_frame::IsEntryVisible(const game_info& game)
{
return m_categoryFilters.contains(qstr(game->info.category));
}
return category::CategoryInMap(game->info.category, category::cat_boot);
return category::CategoryInMap(game->info.category, Localized().category.cat_boot);
};
const QString serial = qstr(game->info.serial);
@ -461,15 +461,16 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
{
if (fromDrive)
{
const Localized localized;
// Load PSF
m_game_data.clear();
m_notes.clear();
const std::string _hdd = Emulator::GetHddDir();
const std::string cat_DG = sstr(category::disc_game);
const std::string cat_GD = sstr(category::ps3_data);
const std::string cat_unknown = sstr(category::unknown);
const std::string cat_unknown = sstr(category::cat_unknown);
const std::string cat_unknown_localized = sstr(localized.category.unknown);
std::vector<std::string> path_list;
@ -546,6 +547,8 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
{
const std::string dir = path_list[i];
const Localized thread_localized;
try
{
const std::string sfo_dir = Emulator::GetSfoDirFromGamePath(dir, Emu.GetUsr());
@ -560,11 +563,11 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
GameInfo game;
game.path = dir;
game.serial = psf::get_string(psf, "TITLE_ID", "");
game.name = psf::get_string(psf, "TITLE", cat_unknown);
game.app_ver = psf::get_string(psf, "APP_VER", cat_unknown);
game.version = psf::get_string(psf, "VERSION", cat_unknown);
game.name = psf::get_string(psf, "TITLE", cat_unknown_localized);
game.app_ver = psf::get_string(psf, "APP_VER", cat_unknown_localized);
game.version = psf::get_string(psf, "VERSION", cat_unknown_localized);
game.category = psf::get_string(psf, "CATEGORY", cat_unknown);
game.fw = psf::get_string(psf, "PS3_SYSTEM_VER", cat_unknown);
game.fw = psf::get_string(psf, "PS3_SYSTEM_VER", cat_unknown_localized);
game.parental_lvl = psf::get_integer(psf, "PARENTAL_LEVEL", 0);
game.resolution = psf::get_integer(psf, "RESOLUTION", 0);
game.sound_format = psf::get_integer(psf, "SOUND_FORMAT", 0);
@ -621,25 +624,27 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
m_titles.insert(serial, title);
}
auto cat = category::cat_boot.find(game.category);
if (cat != category::cat_boot.end())
auto qt_cat = qstr(game.category);
auto cat = thread_localized.category.cat_boot.find(qt_cat);
if (cat != thread_localized.category.cat_boot.end())
{
game.icon_path = sfo_dir + "/ICON0.PNG";
game.category = sstr(cat->second);
qt_cat = cat->second;
}
else if ((cat = category::cat_data.find(game.category)) != category::cat_data.end())
else if ((cat = thread_localized.category.cat_data.find(qt_cat)) != thread_localized.category.cat_data.end())
{
game.icon_path = sfo_dir + "/ICON0.PNG";
game.category = sstr(cat->second);
qt_cat = cat->second;
}
else if (game.category == cat_unknown)
{
game.icon_path = sfo_dir + "/ICON0.PNG";
qt_cat = localized.category.unknown;
}
else
{
game.icon_path = sfo_dir + "/ICON0.PNG";
game.category = sstr(category::other);
qt_cat = localized.category.other;
}
mutex_cat.unlock();
@ -660,7 +665,7 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
const QColor color = getGridCompatibilityColor(compat.color);
const QPixmap pxmap = PaintedPixmap(icon, hasCustomConfig, hasCustomPadConfig, color);
games.push(std::make_shared<gui_game_info>(gui_game_info{game, compat, icon, pxmap, hasCustomConfig, hasCustomPadConfig}));
games.push(std::make_shared<gui_game_info>(gui_game_info{game, qt_cat, compat, icon, pxmap, hasCustomConfig, hasCustomPadConfig}));
}
catch (const std::exception& e)
{
@ -677,12 +682,12 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
// Try to update the app version for disc games if there is a patch
for (const auto& entry : m_game_data)
{
if (entry->info.category == cat_DG)
if (entry->info.category == "DG")
{
for (const auto& other : m_game_data)
{
// The patch is game data and must have the same serial and an app version
if (entry->info.serial == other->info.serial && other->info.category == cat_GD && other->info.app_ver != cat_unknown)
if (entry->info.serial == other->info.serial && other->info.category == "GD" && other->info.app_ver != cat_unknown)
{
try
{
@ -1171,13 +1176,13 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
});
// Disable options depending on software category
QString category = qstr(currGame.category);
const QString category = qstr(currGame.category);
if (category == category::disc_game)
if (category == cat_disc_game)
{
removeGame->setEnabled(false);
}
else if (category != category::hdd_game)
else if (category != cat_hdd_game)
{
checkCompat->setEnabled(false);
}
@ -1912,7 +1917,8 @@ int game_list_frame::PopulateGameList()
m_gameList->setRowCount(m_game_data.size());
// Default locale. Uses current Qt application language.
QLocale locale{};
const QLocale locale{};
const Localized localized;
int row = 0, index = -1;
for (const auto& game : m_game_data)
@ -1973,13 +1979,13 @@ int game_list_frame::PopulateGameList()
// Version
QString app_version = qstr(game->info.app_ver);
if (app_version == category::unknown)
if (app_version == localized.category.unknown)
{
// Fall back to Disc/Pkg Revision
app_version = qstr(game->info.version);
}
if (!game->compat.version.isEmpty() && (app_version == category::unknown || game->compat.version.toDouble() > app_version.toDouble()))
if (!game->compat.version.isEmpty() && (app_version == localized.category.unknown || game->compat.version.toDouble() > app_version.toDouble()))
{
app_version = tr("%0 (Update available: %1)").arg(app_version, game->compat.version);
}
@ -2006,12 +2012,12 @@ int game_list_frame::PopulateGameList()
m_gameList->setItem(row, gui::column_serial, serial_item);
m_gameList->setItem(row, gui::column_firmware, new custom_table_widget_item(game->info.fw));
m_gameList->setItem(row, gui::column_version, new custom_table_widget_item(app_version));
m_gameList->setItem(row, gui::column_category, new custom_table_widget_item(game->info.category));
m_gameList->setItem(row, gui::column_category, new custom_table_widget_item(game->localized_category));
m_gameList->setItem(row, gui::column_path, new custom_table_widget_item(game->info.path));
m_gameList->setItem(row, gui::column_move, new custom_table_widget_item(sstr(supports_move ? tr("Supported") : tr("Not Supported")), Qt::UserRole, !supports_move));
m_gameList->setItem(row, gui::column_resolution, new custom_table_widget_item(GetStringFromU32(game->info.resolution, resolution::mode, true)));
m_gameList->setItem(row, gui::column_sound, new custom_table_widget_item(GetStringFromU32(game->info.sound_format, sound::format, true)));
m_gameList->setItem(row, gui::column_parental, new custom_table_widget_item(GetStringFromU32(game->info.parental_lvl, parental::level), Qt::UserRole, game->info.parental_lvl));
m_gameList->setItem(row, gui::column_resolution, new custom_table_widget_item(GetStringFromU32(game->info.resolution, localized.resolution.mode, true)));
m_gameList->setItem(row, gui::column_sound, new custom_table_widget_item(GetStringFromU32(game->info.sound_format, localized.sound.format, true)));
m_gameList->setItem(row, gui::column_parental, new custom_table_widget_item(GetStringFromU32(game->info.parental_lvl, localized.parental.level), Qt::UserRole, game->info.parental_lvl));
m_gameList->setItem(row, gui::column_last_play, new custom_table_widget_item(locale.toString(last_played, gui::persistent::last_played_date_format_new), Qt::UserRole, last_played));
m_gameList->setItem(row, gui::column_playtime, new custom_table_widget_item(GetPlayTimeByMs(elapsed_ms), Qt::UserRole, elapsed_ms));
m_gameList->setItem(row, gui::column_compat, compat_item);