mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-17 08:11:51 +00:00
Qt: use current locale for last played in gamelist
This also sets the basic groundwork for Qt translations
This commit is contained in:
parent
1759d6d90a
commit
d47a8b49a4
@ -1911,6 +1911,9 @@ int game_list_frame::PopulateGameList()
|
||||
m_gameList->clearContents();
|
||||
m_gameList->setRowCount(m_game_data.size());
|
||||
|
||||
// Default locale. Uses current Qt application language.
|
||||
QLocale locale{};
|
||||
|
||||
int row = 0, index = -1;
|
||||
for (const auto& game : m_game_data)
|
||||
{
|
||||
@ -1982,8 +1985,21 @@ int game_list_frame::PopulateGameList()
|
||||
}
|
||||
|
||||
// Playtimes
|
||||
const qint64 elapsed_ms = m_persistent_settings->GetPlaytime(serial);
|
||||
const QString last_played = GetLastPlayedBySerial(serial);
|
||||
const qint64 elapsed_ms = m_persistent_settings->GetPlaytime(serial);
|
||||
|
||||
// Last played (support outdated values)
|
||||
QDate last_played;
|
||||
const QString last_played_str = GetLastPlayedBySerial(serial);
|
||||
|
||||
if (!last_played_str.isEmpty())
|
||||
{
|
||||
last_played = QDate::fromString(last_played_str, gui::persistent::last_played_date_format);
|
||||
|
||||
if (!last_played.isValid())
|
||||
{
|
||||
last_played = QDate::fromString(last_played_str, gui::persistent::last_played_date_format_old);
|
||||
}
|
||||
}
|
||||
|
||||
m_gameList->setItem(row, gui::column_icon, icon_item);
|
||||
m_gameList->setItem(row, gui::column_name, title_item);
|
||||
@ -1996,7 +2012,7 @@ int game_list_frame::PopulateGameList()
|
||||
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_last_play, new custom_table_widget_item(last_played, Qt::UserRole, QDate::fromString(last_played, gui::persistent::last_played_date_format)));
|
||||
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);
|
||||
|
||||
|
@ -35,6 +35,8 @@ void gui_application::Init()
|
||||
{
|
||||
setWindowIcon(QIcon(":/rpcs3.ico"));
|
||||
|
||||
LoadLanguage(QLocale(QLocale::English).name());
|
||||
|
||||
m_emu_settings.reset(new emu_settings());
|
||||
m_gui_settings.reset(new gui_settings());
|
||||
m_persistent_settings.reset(new persistent_settings());
|
||||
@ -54,9 +56,6 @@ void gui_application::Init()
|
||||
// Create connects to propagate events throughout Gui.
|
||||
InitializeConnects();
|
||||
|
||||
// As per QT recommendations to avoid conflicts for POSIX functions
|
||||
std::setlocale(LC_NUMERIC, "C");
|
||||
|
||||
if (m_main_window)
|
||||
{
|
||||
m_main_window->Init();
|
||||
@ -77,6 +76,46 @@ void gui_application::Init()
|
||||
#endif
|
||||
}
|
||||
|
||||
void gui_application::SwitchTranslator(QTranslator& translator, const QString& filename)
|
||||
{
|
||||
// remove the old translator
|
||||
removeTranslator(&translator);
|
||||
|
||||
// load the new translator
|
||||
if (translator.load(QLocale(QLocale::English), filename))
|
||||
{
|
||||
installTranslator(&translator);
|
||||
}
|
||||
}
|
||||
|
||||
void gui_application::LoadLanguage(const QString& language)
|
||||
{
|
||||
if (m_language == language)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_language = language;
|
||||
|
||||
const QLocale locale = QLocale(language);
|
||||
QLocale::setDefault(locale);
|
||||
|
||||
// Idk if this is overruled by the QLocale default, so I'll change it here just to be sure.
|
||||
// As per QT recommendations to avoid conflicts for POSIX functions
|
||||
std::setlocale(LC_NUMERIC, "C");
|
||||
|
||||
// TODO: implement once we decided to enable translations
|
||||
//SwitchTranslator(m_translator, QString("TranslationExample''%1.qm").arg(language));
|
||||
//SwitchTranslator(m_translator_qt, QString("qt_%1.qm").arg(language));
|
||||
|
||||
if (m_main_window)
|
||||
{
|
||||
m_main_window->RepaintGui();
|
||||
}
|
||||
|
||||
gui_log.notice("Current language changed to %s (%s)", QLocale::languageToString(locale.language()).toStdString(), language.toStdString());
|
||||
}
|
||||
|
||||
void gui_application::InitializeConnects()
|
||||
{
|
||||
connect(this, &gui_application::OnEmulatorRun, this, &gui_application::StartPlaytime);
|
||||
|
@ -47,12 +47,19 @@ private:
|
||||
return thread();
|
||||
}
|
||||
|
||||
void SwitchTranslator(QTranslator& translator, const QString& filename);
|
||||
void LoadLanguage(const QString& language);
|
||||
|
||||
void InitializeCallbacks();
|
||||
void InitializeConnects();
|
||||
|
||||
void StartPlaytime();
|
||||
void StopPlaytime();
|
||||
|
||||
QTranslator m_translator;
|
||||
QTranslator m_translator_qt;
|
||||
QString m_language;
|
||||
|
||||
QElapsedTimer m_timer_playtime;
|
||||
|
||||
std::shared_ptr<emu_settings> m_emu_settings;
|
||||
|
@ -14,7 +14,9 @@ namespace gui
|
||||
const QString last_played = "LastPlayed";
|
||||
|
||||
// Date format
|
||||
const QString last_played_date_format = "MMMM d yyyy";
|
||||
const QString last_played_date_format_old = "MMMM d yyyy";
|
||||
const QString last_played_date_format_new = "MMMM d, yyyy";
|
||||
const Qt::DateFormat last_played_date_format = Qt::DateFormat::ISODate;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user