mirror of
https://github.com/stenzek/duckstation.git
synced 2025-07-29 06:11:47 +00:00
Qt: Use application locale in most places
This commit is contained in:
parent
ef320c62a3
commit
7f5f90338f
@ -894,8 +894,8 @@ void MainWindow::populateGameListContextMenu(const GameList::Entry* entry, QWidg
|
||||
continue;
|
||||
|
||||
const s32 slot = ssi.slot;
|
||||
const QDateTime timestamp(QDateTime::fromSecsSinceEpoch(static_cast<qint64>(ssi.timestamp)));
|
||||
const QString timestamp_str(timestamp.toString(timestamp_format));
|
||||
const QString timestamp_str =
|
||||
QtHost::FormatNumber(Host::NumberFormatType::ShortDateTime, static_cast<s64>(ssi.timestamp));
|
||||
|
||||
QAction* action;
|
||||
if (slot < 0)
|
||||
@ -954,20 +954,16 @@ void MainWindow::populateGameListContextMenu(const GameList::Entry* entry, QWidg
|
||||
}
|
||||
}
|
||||
|
||||
QString MainWindow::formatTimestampForSaveStateMenu(u64 timestamp)
|
||||
{
|
||||
const QDateTime qtime(QDateTime::fromSecsSinceEpoch(static_cast<qint64>(timestamp)));
|
||||
return qtime.toString(QtHost::GetApplicationLocale().dateTimeFormat(QLocale::ShortFormat));
|
||||
}
|
||||
|
||||
void MainWindow::populateLoadStateMenu(std::string_view game_serial, QMenu* menu)
|
||||
{
|
||||
auto add_slot = [this, menu](const QString& title, const QString& empty_title, const std::string_view& serial,
|
||||
s32 slot) {
|
||||
std::optional<SaveStateInfo> ssi = System::GetSaveStateInfo(serial, slot);
|
||||
|
||||
const QString menu_title =
|
||||
ssi.has_value() ? title.arg(slot).arg(formatTimestampForSaveStateMenu(ssi->timestamp)) : empty_title.arg(slot);
|
||||
const QString menu_title = ssi.has_value() ?
|
||||
title.arg(slot).arg(QtHost::FormatNumber(Host::NumberFormatType::ShortDateTime,
|
||||
static_cast<s64>(ssi->timestamp))) :
|
||||
empty_title.arg(slot);
|
||||
|
||||
QAction* load_action = menu->addAction(menu_title);
|
||||
load_action->setEnabled(ssi.has_value());
|
||||
@ -990,7 +986,9 @@ void MainWindow::populateLoadStateMenu(std::string_view game_serial, QMenu* menu
|
||||
});
|
||||
QAction* load_from_state =
|
||||
menu->addAction(s_undo_state_timestamp.has_value() ?
|
||||
tr("Undo Load State (%1)").arg(formatTimestampForSaveStateMenu(s_undo_state_timestamp.value())) :
|
||||
tr("Undo Load State (%1)")
|
||||
.arg(QtHost::FormatNumber(Host::NumberFormatType::ShortDateTime,
|
||||
static_cast<s64>(s_undo_state_timestamp.value()))) :
|
||||
tr("Undo Load State"));
|
||||
load_from_state->setEnabled(s_undo_state_timestamp.has_value());
|
||||
connect(load_from_state, &QAction::triggered, g_emu_thread, &EmuThread::undoLoadState);
|
||||
@ -1014,8 +1012,10 @@ void MainWindow::populateSaveStateMenu(std::string_view game_serial, QMenu* menu
|
||||
auto add_slot = [menu](const QString& title, const QString& empty_title, const std::string_view& serial, s32 slot) {
|
||||
std::optional<SaveStateInfo> ssi = System::GetSaveStateInfo(serial, slot);
|
||||
|
||||
const QString menu_title =
|
||||
ssi.has_value() ? title.arg(slot).arg(formatTimestampForSaveStateMenu(ssi->timestamp)) : empty_title.arg(slot);
|
||||
const QString menu_title = ssi.has_value() ?
|
||||
title.arg(slot).arg(QtHost::FormatNumber(Host::NumberFormatType::ShortDateTime,
|
||||
static_cast<s64>(ssi->timestamp))) :
|
||||
empty_title.arg(slot);
|
||||
|
||||
QAction* save_action = menu->addAction(menu_title);
|
||||
connect(save_action, &QAction::triggered,
|
||||
@ -1132,9 +1132,10 @@ std::optional<bool> MainWindow::promptForResumeState(const std::string& save_sta
|
||||
msgbox.setIcon(QMessageBox::Question);
|
||||
msgbox.setWindowTitle(tr("Load Resume State"));
|
||||
msgbox.setWindowModality(Qt::WindowModal);
|
||||
msgbox.setText(tr("A resume save state was found for this game, saved at:\n\n%1.\n\nDo you want to load this state, "
|
||||
"or start from a fresh boot?")
|
||||
.arg(QDateTime::fromSecsSinceEpoch(sd.ModificationTime, QTimeZone::utc()).toLocalTime().toString()));
|
||||
msgbox.setText(
|
||||
tr("A resume save state was found for this game, saved at:\n\n%1.\n\nDo you want to load this state, "
|
||||
"or start from a fresh boot?")
|
||||
.arg(QtHost::FormatNumber(Host::NumberFormatType::LongDateTime, static_cast<s64>(sd.ModificationTime))));
|
||||
|
||||
QPushButton* load = msgbox.addButton(tr("Load State"), QMessageBox::AcceptRole);
|
||||
QPushButton* boot = msgbox.addButton(tr("Fresh Boot"), QMessageBox::RejectRole);
|
||||
|
@ -307,8 +307,6 @@ private:
|
||||
void startFileOrChangeDisc(const QString& path);
|
||||
void promptForDiscChange(const QString& path);
|
||||
|
||||
static QString formatTimestampForSaveStateMenu(u64 timestamp);
|
||||
|
||||
Ui::MainWindow m_ui;
|
||||
|
||||
GameListWidget* m_game_list_widget = nullptr;
|
||||
|
@ -2180,41 +2180,70 @@ bool Host::CopyTextToClipboard(std::string_view text)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Host::FormatNumber(NumberFormatType type, s64 value)
|
||||
QString QtHost::FormatNumber(Host::NumberFormatType type, s64 value)
|
||||
{
|
||||
std::string ret;
|
||||
QString ret;
|
||||
|
||||
if (type >= NumberFormatType::ShortDate && type <= NumberFormatType::LongDateTime)
|
||||
if (type >= Host::NumberFormatType::ShortDate && type <= Host::NumberFormatType::LongDateTime)
|
||||
{
|
||||
QString format;
|
||||
switch (type)
|
||||
{
|
||||
case NumberFormatType::ShortDate:
|
||||
case NumberFormatType::LongDate:
|
||||
format =
|
||||
s_app_locale.dateFormat((type == NumberFormatType::LongDate) ? QLocale::LongFormat : QLocale::ShortFormat);
|
||||
break;
|
||||
case Host::NumberFormatType::ShortDate:
|
||||
case Host::NumberFormatType::LongDate:
|
||||
{
|
||||
format = s_app_locale.dateFormat((type == Host::NumberFormatType::LongDate) ? QLocale::LongFormat :
|
||||
QLocale::ShortFormat);
|
||||
}
|
||||
break;
|
||||
|
||||
case NumberFormatType::ShortTime:
|
||||
case NumberFormatType::LongTime:
|
||||
format =
|
||||
s_app_locale.timeFormat((type == NumberFormatType::LongTime) ? QLocale::LongFormat : QLocale::ShortFormat);
|
||||
break;
|
||||
case Host::NumberFormatType::ShortTime:
|
||||
case Host::NumberFormatType::LongTime:
|
||||
{
|
||||
format = s_app_locale.timeFormat((type == Host::NumberFormatType::LongTime) ? QLocale::LongFormat :
|
||||
QLocale::ShortFormat);
|
||||
}
|
||||
break;
|
||||
|
||||
case NumberFormatType::ShortDateTime:
|
||||
case NumberFormatType::LongDateTime:
|
||||
format = s_app_locale.dateTimeFormat((type == NumberFormatType::LongDateTime) ? QLocale::LongFormat :
|
||||
QLocale::ShortFormat);
|
||||
break;
|
||||
case Host::NumberFormatType::ShortDateTime:
|
||||
case Host::NumberFormatType::LongDateTime:
|
||||
{
|
||||
format = s_app_locale.dateTimeFormat((type == Host::NumberFormatType::LongDateTime) ? QLocale::LongFormat :
|
||||
QLocale::ShortFormat);
|
||||
|
||||
// Remove time zone specifiers 't', 'tt', 'ttt', 'tttt'.
|
||||
format.remove(QRegularExpression("\\s*t+\\s*"));
|
||||
}
|
||||
break;
|
||||
|
||||
DefaultCaseIsUnreachable();
|
||||
}
|
||||
|
||||
ret = QDateTime::fromSecsSinceEpoch(value).toString(format).toStdString();
|
||||
ret = QDateTime::fromSecsSinceEpoch(value, QTimeZone::utc()).toLocalTime().toString(format);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = s_app_locale.toString(value).toStdString();
|
||||
ret = s_app_locale.toString(value);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string Host::FormatNumber(NumberFormatType type, s64 value)
|
||||
{
|
||||
return QtHost::FormatNumber(type, value).toStdString();
|
||||
}
|
||||
|
||||
QString QtHost::FormatNumber(Host::NumberFormatType type, double value)
|
||||
{
|
||||
QString ret;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Host::NumberFormatType::Number:
|
||||
default:
|
||||
ret = s_app_locale.toString(value);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -2222,17 +2251,7 @@ std::string Host::FormatNumber(NumberFormatType type, s64 value)
|
||||
|
||||
std::string Host::FormatNumber(NumberFormatType type, double value)
|
||||
{
|
||||
std::string ret;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case NumberFormatType::Number:
|
||||
default:
|
||||
ret = s_app_locale.toString(value).toStdString();
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return QtHost::FormatNumber(type, value).toStdString();
|
||||
}
|
||||
|
||||
void QtHost::UpdateApplicationLanguage(QWidget* dialog_parent)
|
||||
|
@ -393,6 +393,10 @@ INISettingsInterface* GetBaseSettingsInterface();
|
||||
/// Saves a game settings interface.
|
||||
bool SaveGameSettings(SettingsInterface* sif, bool delete_if_empty);
|
||||
|
||||
/// Formats a number according to the current locale.
|
||||
QString FormatNumber(Host::NumberFormatType type, s64 value);
|
||||
QString FormatNumber(Host::NumberFormatType type, double value);
|
||||
|
||||
/// Downloads the specified URL to the provided path.
|
||||
bool DownloadFile(QWidget* parent, const QString& title, std::string url, const char* path);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user