Skip to content

Commit

Permalink
DAB time should fallback to English format if system lovcale is not s…
Browse files Browse the repository at this point in the history
…upported as localization (Issue #68)
  • Loading branch information
KejPi committed Mar 15, 2023
1 parent b317524 commit 4c4b3fd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 4 additions & 2 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ void MainWindow::onDLComplete(const QString & dl, QLabel * dlLabel)

void MainWindow::onDabTime(const QDateTime & d)
{
m_timeLabel->setText(QLocale(m_setupDialog->settings().lang).toString(d, QString("dddd, dd.MM.yyyy, hh:mm")));
m_timeLabel->setText(m_timeLocale.toString(d, QString("dddd, dd.MM.yyyy, hh:mm")));
}

void MainWindow::onAudioParametersInfo(const struct AudioParameters & params)
Expand Down Expand Up @@ -1831,7 +1831,6 @@ void MainWindow::loadSettings()
s.applicationStyle = static_cast<ApplicationStyle>(settings->value("style", static_cast<int>(ApplicationStyle::Default)).toInt());
s.dlPlusEna = settings->value("dlPlus", true).toBool();
s.lang = QLocale::codeToLanguage(settings->value("language", QString("")).toString());

s.inputDevice = static_cast<InputDeviceId>(inDevice);
s.announcementEna = settings->value("announcementEna", 0x07FF).toUInt();
s.bringWindowToForeground = settings->value("bringWindowToForegroundOnAlarm", true).toBool();
Expand Down Expand Up @@ -1874,6 +1873,9 @@ void MainWindow::loadSettings()

m_setupDialog->setSettings(s);

// set DAB time locale
m_timeLocale = QLocale(m_setupDialog->applicationLanguage());

// need to run here because it expects that settings is up-to-date
if (ApplicationStyle::Default != s.applicationStyle)
{
Expand Down
1 change: 1 addition & 0 deletions gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class MainWindow : public QMainWindow
// status bar widgets
QStackedWidget * m_timeBasicQualWidget;
QLabel * m_timeLabel;
QLocale m_timeLocale;
QLabel * m_basicSignalQualityLabel;
QWidget * m_signalQualityWidget;
QLabel * m_syncLabel;
Expand Down
29 changes: 25 additions & 4 deletions gui/setupdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ SetupDialog::SetupDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SetupDia

// create combo box with language selection
ui->langComboBox->addItem("<" + tr("System language") + ">", QVariant(QLocale::AnyLanguage));
ui->langComboBox->addItem("English", QVariant(QLocale::English));
ui->langComboBox->addItem(QLocale(QLocale::Czech).nativeLanguageName(), QVariant(QLocale::Czech));
ui->langComboBox->addItem(QLocale(QLocale::German).nativeLanguageName(), QVariant(QLocale::German));
ui->langComboBox->addItem(QLocale(QLocale::Polish).nativeLanguageName(), QVariant(QLocale::Polish));
ui->langComboBox->addItem("English", QVariant(QLocale::English)); // QLocale::English native name returns "American English" :-(
for (auto l : m_supportedLocalization)
{
ui->langComboBox->addItem(QLocale(l).nativeLanguageName(), QVariant(l));
}
ui->langComboBox->model()->sort(0);
ui->langComboBox->setToolTip(tr("User interface language, the change will take effect after application restart."));
ui->langWarningLabel->setText("<span style=\"color:red\">"+tr("Language change will take effect after application restart.")+"</span>");
Expand Down Expand Up @@ -343,6 +344,26 @@ void SetupDialog::setXmlHeader(const InputDeviceDescription &desc)
adjustSize();
}

QLocale::Language SetupDialog::applicationLanguage() const
{
if (m_supportedLocalization.contains(m_settings.lang) || (QLocale::English == m_settings.lang))
{ // selected specific localization
return m_settings.lang;
}
else
{ // system default or not supported
// find if system default is supported
if (m_supportedLocalization.contains(QLocale::system().language()))
{
return QLocale::system().language();
}
else
{
return QLocale::English;
}
}
}

void SetupDialog::showEvent(QShowEvent *event)
{
int index = ui->inputCombo->findData(QVariant(static_cast<int>(m_settings.inputDevice)));
Expand Down
3 changes: 3 additions & 0 deletions gui/setupdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class SetupDialog : public QDialog
void onExpertMode(bool ena);
void setSettings(const Settings &settings);
void setXmlHeader(const InputDeviceDescription & desc);
QLocale::Language applicationLanguage() const;

signals:
void inputDeviceChanged(const InputDeviceId & inputDevice);
Expand All @@ -131,6 +132,8 @@ class SetupDialog : public QDialog
XMLSampleRate, XMLFreq, XMLLength, XMLFormat,
XMLNumLabels};

const QList<QLocale::Language> m_supportedLocalization = { QLocale::Czech, QLocale::German, QLocale::Polish };

Ui::SetupDialog *ui;
Settings m_settings;
QString m_rawfilename;
Expand Down

0 comments on commit 4c4b3fd

Please sign in to comment.