From 9c89df45198ea4edb2c5b1be680b4e2434500a86 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Thu, 24 Nov 2022 01:24:13 +0800 Subject: [PATCH] Misc add config file to resource system move language folder --- README.md | 1 - config/config.qrc | 6 ++++++ doc/README/README_zh_CN.md | 1 - {src/i18n => i18n}/en_US.qm | Bin {src/i18n => i18n}/en_US.ts | 0 {src/i18n => i18n}/language.qrc | 0 {src/i18n => i18n}/languages.ini | 2 +- {src/i18n => i18n}/zh_CN.qm | Bin {src/i18n => i18n}/zh_CN.ts | 0 src/Proxmark3GUI.pro | 3 ++- src/common/pm3process.cpp | 2 +- src/common/util.cpp | 19 +++++++++++++---- src/common/util.h | 1 + src/main.cpp | 31 ++++++++++++++------------- src/ui/mainwindow.cpp | 35 ++++++++++++++++++++++++++++--- src/ui/mainwindow.h | 5 ++++- src/ui/mainwindow.ui | 26 ++++++++++++++++++++++- 17 files changed, 103 insertions(+), 29 deletions(-) create mode 100644 config/config.qrc rename {src/i18n => i18n}/en_US.qm (100%) rename {src/i18n => i18n}/en_US.ts (100%) rename {src/i18n => i18n}/language.qrc (100%) rename {src/i18n => i18n}/languages.ini (61%) rename {src/i18n => i18n}/zh_CN.qm (100%) rename {src/i18n => i18n}/zh_CN.ts (100%) diff --git a/README.md b/README.md index a3aa31e..ce9e834 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,6 @@ Great thanks to him. mkdir build && cd build qmake ../src make -j4 && make clean - cp -r ../config ./ ./Proxmark3GUI *** diff --git a/config/config.qrc b/config/config.qrc new file mode 100644 index 0000000..36db67f --- /dev/null +++ b/config/config.qrc @@ -0,0 +1,6 @@ + + + config_official.json + config_rrgv4.13.json + + diff --git a/doc/README/README_zh_CN.md b/doc/README/README_zh_CN.md index 9e050d5..1a6d8eb 100644 --- a/doc/README/README_zh_CN.md +++ b/doc/README/README_zh_CN.md @@ -57,7 +57,6 @@ release页面中有含客户端的GUI。这个GUI也可以搭配你自己的客 mkdir build && cd build qmake ../src make -j4 && make clean - cp -r ../config ./ ./Proxmark3GUI *** diff --git a/src/i18n/en_US.qm b/i18n/en_US.qm similarity index 100% rename from src/i18n/en_US.qm rename to i18n/en_US.qm diff --git a/src/i18n/en_US.ts b/i18n/en_US.ts similarity index 100% rename from src/i18n/en_US.ts rename to i18n/en_US.ts diff --git a/src/i18n/language.qrc b/i18n/language.qrc similarity index 100% rename from src/i18n/language.qrc rename to i18n/language.qrc diff --git a/src/i18n/languages.ini b/i18n/languages.ini similarity index 61% rename from src/i18n/languages.ini rename to i18n/languages.ini index 10c2e3f..d0914d1 100644 --- a/src/i18n/languages.ini +++ b/i18n/languages.ini @@ -1,4 +1,4 @@ [Languages] en_US=English zh_CN=简体中文 -ext=Load from external file +(ext)=Load from external file diff --git a/src/i18n/zh_CN.qm b/i18n/zh_CN.qm similarity index 100% rename from src/i18n/zh_CN.qm rename to i18n/zh_CN.qm diff --git a/src/i18n/zh_CN.ts b/i18n/zh_CN.ts similarity index 100% rename from src/i18n/zh_CN.ts rename to i18n/zh_CN.ts diff --git a/src/Proxmark3GUI.pro b/src/Proxmark3GUI.pro index e915502..d60391e 100644 --- a/src/Proxmark3GUI.pro +++ b/src/Proxmark3GUI.pro @@ -65,4 +65,5 @@ QMAKE_TARGET_DESCRIPTION = "Proxmark3GUI" QMAKE_TARGET_COMPANY = "wh201906" RESOURCES += \ - i18n/language.qrc + ../i18n/language.qrc \ + ../config/config.qrc diff --git a/src/common/pm3process.cpp b/src/common/pm3process.cpp index 19e9012..2b46748 100644 --- a/src/common/pm3process.cpp +++ b/src/common/pm3process.cpp @@ -28,7 +28,7 @@ void PM3Process::connectPM3(const QString& path, const QStringList args) currArgs = args; // using "-f" option to make the client output flushed after every print. - // single '\r' might appears. Don't use QProcess::Text there or '\r' is ignored. + // single '\r' might appear. Don't use QProcess::Text there or '\r' is ignored. start(path, args, QProcess::Unbuffered | QProcess::ReadWrite); if(waitForStarted(10000)) { diff --git a/src/common/util.cpp b/src/common/util.cpp index 9f3199b..21e2aa2 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -123,13 +123,24 @@ bool Util::chooseLanguage(QSettings* guiSettings, QMainWindow* window) delete langSettings; bool isOk = false; QString selectedText = QInputDialog::getItem(window, "", "Choose a language:", langMap.keys(), 0, false, &isOk); - if(isOk) + if(!isOk) + return false; + if(langMap[selectedText] == "(ext)") { - guiSettings->beginGroup("lang"); - guiSettings->setValue("language", langMap[selectedText]); + QString extPath = QFileDialog::getOpenFileName(nullptr, "Select the translation file:"); + if(extPath.isEmpty()) + return false; + + guiSettings->beginGroup("language"); + guiSettings->setValue("extPath", extPath); guiSettings->endGroup(); - guiSettings->sync(); } + + guiSettings->beginGroup("language"); + guiSettings->setValue("name", langMap[selectedText]); + guiSettings->endGroup(); + guiSettings->sync(); + return isOk; } diff --git a/src/common/util.h b/src/common/util.h index 23705d4..bda759b 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "ui_mainwindow.h" diff --git a/src/main.cpp b/src/main.cpp index 40b577b..9b6054f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,33 +27,34 @@ int main(int argc, char *argv[]) QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat); settings->setIniCodec("UTF-8"); - settings->beginGroup("lang"); - QString currLang = settings->value("language", "").toString(); + settings->beginGroup("language"); + QString languageFile = settings->value("extPath").toString(); + QString languageName = settings->value("name").toString(); settings->endGroup(); - if(currLang == "") + if(languageName == "") { if(Util::chooseLanguage(settings, &w)) { - settings->beginGroup("lang"); - currLang = settings->value("language", "").toString(); + settings->beginGroup("language"); + languageName = settings->value("name").toString(); settings->endGroup(); } else - currLang = "en_US"; + languageName = "en_US"; + } + if(languageName == "(ext)") + { + settings->beginGroup("language"); + languageFile = settings->value("extPath").toString(); + settings->endGroup(); } - if(currLang == "ext") - currLang = QFileDialog::getOpenFileName(nullptr, "Select the translation file:"); else - currLang = ":/i18n/" + currLang + ".qm"; + languageFile = ":/i18n/" + languageName + ".qm"; QTranslator* translator = new QTranslator(&w); - if(translator->load(currLang)) - { + if(translator->load(languageFile)) a.installTranslator(translator); - } else - { - QMessageBox::information(&w, "Error", "Can't load " + currLang + " as translation file."); - } + QMessageBox::information(&w, "Error", "Can't load " + languageFile + " as translation file."); delete settings; w.initUI(); w.show(); diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 5ff50e0..0bd31e7 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -2,6 +2,7 @@ #include "ui_mainwindow.h" #include +#include MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) @@ -79,7 +80,11 @@ MainWindow::~MainWindow() void MainWindow::loadConfig() { - QFile configList(ui->Set_Client_configPathEdit->text()); + QString filename = ui->Set_Client_configFileBox->currentData().toString(); + if(filename == "(ext)") + filename = ui->Set_Client_configPathEdit->text(); + qDebug() << "config file:" << filename; + QFile configList(filename); if(!configList.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::information(this, tr("Info"), tr("Failed to load config file")); @@ -1106,11 +1111,27 @@ void MainWindow::uiInit() ui->Set_Client_keepClientActiveBox->setChecked(keepClientActive); settings->endGroup(); + QDirIterator configFiles(":/config/"); + ui->Set_Client_configFileBox->blockSignals(true); + while(configFiles.hasNext()) + { + configFiles.next(); + ui->Set_Client_configFileBox->addItem(configFiles.fileName(), configFiles.filePath()); + } + ui->Set_Client_configFileBox->addItem(tr("External file"), "(ext)"); + + int configId = -1; settings->beginGroup("Client_Env"); ui->Set_Client_envScriptEdit->setText(settings->value("scriptPath").toString()); ui->Set_Client_workingDirEdit->setText(settings->value("workingDir", "../data").toString()); - ui->Set_Client_configPathEdit->setText(settings->value("configPath", "config.json").toString()); + configId = ui->Set_Client_configFileBox->findData(settings->value("configFile")); + ui->Set_Client_configPathEdit->setText(settings->value("extConfigFilePath", "config.json").toString()); settings->endGroup(); + if(configId != -1) + ui->Set_Client_configFileBox->setCurrentIndex(configId); + ui->Set_Client_configFileBox->blockSignals(false); + on_Set_Client_configFileBox_currentIndexChanged(ui->Set_Client_configFileBox->currentIndex()); + ui->MF_RW_keyTypeBox->addItem("A", Mifare::KEY_A); ui->MF_RW_keyTypeBox->addItem("B", Mifare::KEY_B); @@ -1314,7 +1335,7 @@ void MainWindow::on_Set_Client_workingDirEdit_editingFinished() void MainWindow::on_Set_Client_configPathEdit_editingFinished() { settings->beginGroup("Client_Env"); - settings->setValue("configPath", ui->Set_Client_configPathEdit->text()); + settings->setValue("extConfigFilePath", ui->Set_Client_configPathEdit->text()); settings->endGroup(); } @@ -1452,3 +1473,11 @@ void MainWindow::on_LF_LFConf_resetButton_clicked() setState(true); } +void MainWindow::on_Set_Client_configFileBox_currentIndexChanged(int index) +{ + ui->Set_Client_configPathEdit->setVisible(ui->Set_Client_configFileBox->itemData(index).toString() == "(ext)"); + settings->beginGroup("Client_Env"); + settings->setValue("configFile", ui->Set_Client_configFileBox->currentData()); + settings->endGroup(); +} + diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 37fccaa..1fcdb7f 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -51,7 +51,7 @@ public: ~MainWindow(); void initUI(); - bool eventFilter(QObject *watched, QEvent *event); + bool eventFilter(QObject *watched, QEvent *event) override; public slots: void refreshOutput(const QString& output); void refreshCMD(const QString& cmd); @@ -209,6 +209,9 @@ private slots: void on_Set_Client_configPathEdit_editingFinished(); void setState(bool st); + + void on_Set_Client_configFileBox_currentIndexChanged(int index); + private: Ui::MainWindow* ui; QButtonGroup* MFCardTypeBtnGroup; diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui index 9381e7e..f734d6a 100644 --- a/src/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -2763,10 +2763,34 @@ or the communication between a tag and a reader. - Config file path(Reconnect to apply): + Config file(Reconnect to apply): + + + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + +