Proxmark3GUI/main.cpp

60 lines
1.5 KiB
C++
Raw Normal View History

2020-04-22 16:42:58 +08:00
#include "ui/mainwindow.h"
2020-04-07 18:28:41 +08:00
#include <QApplication>
2020-04-25 18:15:00 +08:00
#include <QSettings>
#include <QTranslator>
#include <QMessageBox>
#include <QInputDialog>
2020-04-07 18:28:41 +08:00
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
2020-04-25 18:15:00 +08:00
QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat);
2020-06-13 01:27:59 +08:00
settings->beginGroup("lang");
QVariant lang = settings->value("language", "null");
2020-04-25 18:15:00 +08:00
if(lang == "null")
{
2020-04-29 16:30:27 +08:00
#ifdef Q_OS_WIN
2020-04-25 18:15:00 +08:00
lang = "lang/en_US.qm";
2020-04-29 16:30:27 +08:00
#else
lang = "lang/en_US.ts";
#endif
2020-04-25 18:15:00 +08:00
QStringList langList;
langList.append("English");
langList.append("简体中文");
QString seletedText = QInputDialog::getItem(&w, "", "Choose a language:", langList, 0, false);
if(seletedText == "English")
{
2020-04-29 16:30:27 +08:00
#ifdef Q_OS_WIN
2020-04-25 18:15:00 +08:00
lang = "lang/en_US.qm";
2020-04-29 16:30:27 +08:00
#else
lang = "lang/en_US.ts";
#endif
2020-04-25 18:15:00 +08:00
}
else if(seletedText == "简体中文")
{
2020-04-29 16:30:27 +08:00
#ifdef Q_OS_WIN
2020-04-25 18:15:00 +08:00
lang = "lang/zh_CN.qm";
2020-04-29 16:30:27 +08:00
#else
lang = "lang/zh_CN.ts";
#endif
2020-04-25 18:15:00 +08:00
}
}
QTranslator* translator = new QTranslator(&w);
if(translator->load(lang.toString()))
{
a.installTranslator(translator);
2020-06-13 01:27:59 +08:00
settings->setValue("language", lang);
2020-04-25 18:15:00 +08:00
}
else
{
QMessageBox::information(&w, "Error", "Can't load " + lang.toString() + " as translation file.");
}
2020-06-13 01:27:59 +08:00
settings->endGroup();
2020-04-25 18:15:00 +08:00
delete settings;
w.initUI();
2020-04-07 18:28:41 +08:00
w.show();
return a.exec();
}