adding a dynamic list for language available and the language list
This commit is contained in:
@@ -3,6 +3,10 @@
|
|||||||
#include "helpwindow.h"
|
#include "helpwindow.h"
|
||||||
#include <qevent.h>
|
#include <qevent.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QRegExp>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
#include "simplecrypt.h"
|
#include "simplecrypt.h"
|
||||||
|
|
||||||
//using this simple encryption library to obfuscate stored password a bit. It's not super secure but better than
|
//using this simple encryption library to obfuscate stored password a bit. It's not super secure but better than
|
||||||
@@ -10,6 +14,42 @@
|
|||||||
//whatever key, you'd see it. Just behave yourselves
|
//whatever key, you'd see it. Just behave yourselves
|
||||||
SimpleCrypt crypto(Q_UINT64_C(0xdeadbeefface6285));
|
SimpleCrypt crypto(Q_UINT64_C(0xdeadbeefface6285));
|
||||||
|
|
||||||
|
static QStringList availableLanguageCodes()
|
||||||
|
{
|
||||||
|
QStringList codes;
|
||||||
|
QDir transDir(QCoreApplication::applicationDirPath() + "/translations");
|
||||||
|
QStringList list = transDir.entryList(QStringList() << "SavvyCAN_*.qm");
|
||||||
|
//* just for test purposes
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
// maybe only ts files exist during development
|
||||||
|
list = transDir.entryList(QStringList() << "SavvyCAN_*.ts");
|
||||||
|
}
|
||||||
|
for (QString file : list) {
|
||||||
|
QRegExp re("SavvyCAN_(.*)\\.(qm|ts)");
|
||||||
|
if (re.indexIn(file) != -1) {
|
||||||
|
codes << re.cap(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return codes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainSettingsDialog::populateLanguageCombo()
|
||||||
|
{
|
||||||
|
ui->comboLanguage->clear();
|
||||||
|
QStringList codes = availableLanguageCodes();
|
||||||
|
if (codes.isEmpty()) {
|
||||||
|
codes << "en"; // fallback
|
||||||
|
}
|
||||||
|
for (const QString &code : codes) {
|
||||||
|
QLocale locale(code);
|
||||||
|
QString name = locale.nativeLanguageName();
|
||||||
|
qInfo() << code;
|
||||||
|
if (name.isEmpty())
|
||||||
|
name = code;
|
||||||
|
ui->comboLanguage->addItem(name, code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MainSettingsDialog::MainSettingsDialog(QWidget *parent) :
|
MainSettingsDialog::MainSettingsDialog(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::MainSettingsDialog)
|
ui(new Ui::MainSettingsDialog)
|
||||||
@@ -17,6 +57,8 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) :
|
|||||||
QSettings settings;
|
QSettings settings;
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
populateLanguageCombo();
|
||||||
|
|
||||||
//TODO: This is still hard coded to support only two buses. Sometimes there is none, sometimes 1, sometimes much more than 2. Fix this.
|
//TODO: This is still hard coded to support only two buses. Sometimes there is none, sometimes 1, sometimes much more than 2. Fix this.
|
||||||
ui->comboSendingBus->addItem(tr("None"));
|
ui->comboSendingBus->addItem(tr("None"));
|
||||||
ui->comboSendingBus->addItem(tr("0"));
|
ui->comboSendingBus->addItem(tr("0"));
|
||||||
@@ -92,6 +134,12 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) :
|
|||||||
ui->cbFilterLabeling->setChecked(settings.value("Main/FilterLabeling", true).toBool());
|
ui->cbFilterLabeling->setChecked(settings.value("Main/FilterLabeling", true).toBool());
|
||||||
ui->cbIgnoreDBCColors->setChecked(settings.value("Main/IgnoreDBCColors", false).toBool());
|
ui->cbIgnoreDBCColors->setChecked(settings.value("Main/IgnoreDBCColors", false).toBool());
|
||||||
|
|
||||||
|
if (QString savedLang = settings.value("Main/Language").toString(); !savedLang.isEmpty()) {
|
||||||
|
int idx = ui->comboLanguage->findData(savedLang);
|
||||||
|
if (idx >= 0)
|
||||||
|
ui->comboLanguage->setCurrentIndex(idx);
|
||||||
|
}
|
||||||
|
|
||||||
int maxFramesDefault;
|
int maxFramesDefault;
|
||||||
if (QSysInfo::WordSize > 32)
|
if (QSysInfo::WordSize > 32)
|
||||||
{
|
{
|
||||||
@@ -108,6 +156,7 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) :
|
|||||||
ui->spinBytesPerLine->setValue(settings.value("Main/BytesPerLine", 8).toInt());
|
ui->spinBytesPerLine->setValue(settings.value("Main/BytesPerLine", 8).toInt());
|
||||||
|
|
||||||
//just for simplicity they all call the same function and that function updates all settings at once
|
//just for simplicity they all call the same function and that function updates all settings at once
|
||||||
|
connect(ui->comboLanguage, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSettings()));
|
||||||
connect(ui->cbDisplayHex, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
|
connect(ui->cbDisplayHex, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
|
||||||
connect(ui->cbFlowAutoRef, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
|
connect(ui->cbFlowAutoRef, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
|
||||||
connect(ui->cbFlowUseTimestamp, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
|
connect(ui->cbFlowUseTimestamp, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
|
||||||
@@ -177,6 +226,7 @@ void MainSettingsDialog::updateSettings()
|
|||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
|
settings.setValue("Main/Language", ui->comboLanguage->currentData().toString());
|
||||||
settings.setValue("Main/UseHex", ui->cbDisplayHex->isChecked());
|
settings.setValue("Main/UseHex", ui->cbDisplayHex->isChecked());
|
||||||
settings.setValue("FlowView/AutoRef", ui->cbFlowAutoRef->isChecked());
|
settings.setValue("FlowView/AutoRef", ui->cbFlowAutoRef->isChecked());
|
||||||
settings.setValue("FlowView/UseTimestamp", ui->cbFlowUseTimestamp->isChecked());
|
settings.setValue("FlowView/UseTimestamp", ui->cbFlowUseTimestamp->isChecked());
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
Ui::MainSettingsDialog *ui;
|
Ui::MainSettingsDialog *ui;
|
||||||
|
|
||||||
|
void populateLanguageCombo();
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
bool eventFilter(QObject *obj, QEvent *event);
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,6 +53,20 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_13">
|
||||||
|
<property name="text">
|
||||||
|
<string>Language</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboLanguage"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user