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>
|
2021-02-14 22:47:56 +08:00
|
|
|
#include <QTextCodec>
|
2021-08-05 11:57:35 +08:00
|
|
|
#include <QDir>
|
2020-04-07 18:28:41 +08:00
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2021-12-15 21:43:10 +08:00
|
|
|
// A trick to handle non-ascii path
|
|
|
|
|
// The application cannot find the plugins when the path contains non ascii characters.
|
|
|
|
|
// However, the plugins will be load after creating MainWindow(or QApplication?).
|
|
|
|
|
// QDir will handle the path correctly.
|
|
|
|
|
QDir* pluginDir = new QDir;
|
|
|
|
|
if(pluginDir->cd("plugins")) // has plugins folder
|
|
|
|
|
{
|
|
|
|
|
qputenv("QT_PLUGIN_PATH", pluginDir->absolutePath().toLocal8Bit());
|
|
|
|
|
}
|
|
|
|
|
delete pluginDir;
|
|
|
|
|
|
2021-02-12 23:45:25 +08:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2021-02-14 22:47:56 +08:00
|
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
|
2021-08-05 11:57:35 +08:00
|
|
|
QDir *langPath = new QDir();
|
2020-04-07 18:28:41 +08:00
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
MainWindow w;
|
2021-02-14 22:47:56 +08:00
|
|
|
|
2020-04-25 18:15:00 +08:00
|
|
|
QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat);
|
2021-02-14 22:47:56 +08:00
|
|
|
settings->setIniCodec("UTF-8");
|
2020-06-13 01:27:59 +08:00
|
|
|
settings->beginGroup("lang");
|
2021-02-14 22:47:56 +08:00
|
|
|
QString currLang = settings->value("language", "").toString();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
if(currLang == "")
|
2020-04-25 18:15:00 +08:00
|
|
|
{
|
2021-02-14 22:47:56 +08:00
|
|
|
if(Util::chooseLanguage(settings, &w))
|
2020-04-25 18:15:00 +08:00
|
|
|
{
|
2021-02-14 22:47:56 +08:00
|
|
|
settings->beginGroup("lang");
|
|
|
|
|
currLang = settings->value("language", "").toString();
|
|
|
|
|
settings->endGroup();
|
2020-04-25 18:15:00 +08:00
|
|
|
}
|
2021-02-14 22:47:56 +08:00
|
|
|
else
|
|
|
|
|
currLang = "en_US";
|
|
|
|
|
}
|
|
|
|
|
currLang += ".qm";
|
2021-08-05 11:57:35 +08:00
|
|
|
langPath->cd("lang");
|
2020-04-25 18:15:00 +08:00
|
|
|
QTranslator* translator = new QTranslator(&w);
|
2021-08-05 11:57:35 +08:00
|
|
|
if(translator->load(currLang, langPath->absolutePath()))
|
2020-04-25 18:15:00 +08:00
|
|
|
{
|
|
|
|
|
a.installTranslator(translator);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-14 22:47:56 +08:00
|
|
|
QMessageBox::information(&w, "Error", "Can't load " + currLang + " as translation file.");
|
2020-04-25 18:15:00 +08:00
|
|
|
}
|
|
|
|
|
delete settings;
|
2021-08-05 11:57:35 +08:00
|
|
|
delete langPath;
|
2020-04-25 18:15:00 +08:00
|
|
|
w.initUI();
|
2020-04-07 18:28:41 +08:00
|
|
|
w.show();
|
|
|
|
|
return a.exec();
|
|
|
|
|
}
|
2021-02-14 22:47:56 +08:00
|
|
|
|
|
|
|
|
|