2021-04-06 23:10:57 +08:00
|
|
|
#include "mainwindow.h"
|
2021-04-08 10:29:21 +08:00
|
|
|
#include "settings.h"
|
2021-04-11 21:33:08 +08:00
|
|
|
#include "systemconsts.h"
|
2021-04-13 22:17:18 +08:00
|
|
|
#include "utils.h"
|
2021-04-06 23:10:57 +08:00
|
|
|
#include <QApplication>
|
2021-04-12 00:00:29 +08:00
|
|
|
#include <QDir>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QDebug>
|
2021-04-13 22:17:18 +08:00
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QMessageBox>
|
2021-04-15 11:18:14 +08:00
|
|
|
#include <QStringList>
|
2021-04-24 15:57:45 +08:00
|
|
|
#include "common.h"
|
2021-06-18 21:48:40 +08:00
|
|
|
#include "colorscheme.h"
|
2021-06-24 16:05:19 +08:00
|
|
|
#include "iconsmanager.h"
|
2021-09-04 11:37:04 +08:00
|
|
|
#include "autolinkmanager.h"
|
2021-08-13 11:18:42 +08:00
|
|
|
#include "parser/parserutils.h"
|
2021-04-13 22:17:18 +08:00
|
|
|
|
2021-08-30 18:07:55 +08:00
|
|
|
QString getSettingFilename(const QString& filepath = QString()) {
|
2021-04-15 11:18:14 +08:00
|
|
|
QString filename;
|
|
|
|
if (filepath.isEmpty()) {
|
|
|
|
if (isGreenEdition()) {
|
2021-04-20 22:24:33 +08:00
|
|
|
filename = includeTrailingPathDelimiter(QApplication::applicationDirPath()) +
|
|
|
|
"config/" + APP_SETTSINGS_FILENAME;
|
2021-04-15 11:18:14 +08:00
|
|
|
} else {
|
2021-04-20 22:24:33 +08:00
|
|
|
filename =includeTrailingPathDelimiter(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)[0])
|
|
|
|
+ APP_SETTSINGS_FILENAME;
|
2021-04-15 11:18:14 +08:00
|
|
|
}
|
2021-04-13 22:17:18 +08:00
|
|
|
} else {
|
|
|
|
filename = filepath;
|
|
|
|
}
|
|
|
|
|
2021-04-15 11:18:14 +08:00
|
|
|
QFileInfo fileInfo(filename);
|
|
|
|
QDir dir(fileInfo.absoluteDir());
|
2021-04-13 22:17:18 +08:00
|
|
|
if (!dir.exists()) {
|
|
|
|
if (!dir.mkpath(dir.absolutePath())) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(nullptr, QObject::tr("Error"),
|
2021-04-13 22:17:18 +08:00
|
|
|
QString(QObject::tr("Can't create configuration folder %1")).arg(dir.absolutePath()));
|
2021-08-30 18:07:55 +08:00
|
|
|
return "";
|
2021-04-13 22:17:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileInfo.exists() && !fileInfo.isWritable()) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(nullptr, QObject::tr("Error"),
|
2021-04-15 11:18:14 +08:00
|
|
|
QString(QObject::tr("Can't write to configuration file %1")).arg(filename));
|
|
|
|
|
2021-08-30 18:07:55 +08:00
|
|
|
return "";
|
2021-04-13 22:17:18 +08:00
|
|
|
}
|
2021-08-30 18:07:55 +08:00
|
|
|
return filename;
|
2021-04-13 22:17:18 +08:00
|
|
|
}
|
2021-04-06 23:10:57 +08:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-04-11 21:33:08 +08:00
|
|
|
QApplication app(argc, argv);
|
2021-04-13 22:17:18 +08:00
|
|
|
|
2021-08-30 18:07:55 +08:00
|
|
|
//Translation must be loaded first
|
|
|
|
QTranslator trans;
|
|
|
|
QString settingFilename = getSettingFilename();
|
|
|
|
if (settingFilename.isEmpty())
|
|
|
|
return -1;
|
|
|
|
{
|
2021-08-30 19:52:38 +08:00
|
|
|
QSettings languageSetting(settingFilename,QSettings::IniFormat);
|
|
|
|
languageSetting.beginGroup(SETTING_ENVIRONMENT);
|
|
|
|
QString language = languageSetting.value("language",QLocale::system().name()).toString();
|
|
|
|
trans.load("RedPandaIDE_"+language,":/translations");
|
|
|
|
app.installTranslator(&trans);
|
2021-08-30 18:07:55 +08:00
|
|
|
}
|
|
|
|
|
2021-04-24 15:57:45 +08:00
|
|
|
qRegisterMetaType<PCompileIssue>("PCompileIssue");
|
|
|
|
qRegisterMetaType<PCompileIssue>("PCompileIssue&");
|
2021-08-01 01:06:43 +08:00
|
|
|
qRegisterMetaType<QVector<int>>("QVector<int>");
|
2021-04-24 15:57:45 +08:00
|
|
|
|
2021-08-07 14:08:51 +08:00
|
|
|
initParser();
|
|
|
|
|
2021-06-20 09:27:37 +08:00
|
|
|
try {
|
2021-04-13 22:17:18 +08:00
|
|
|
|
2021-06-20 09:27:37 +08:00
|
|
|
SystemConsts systemConsts;
|
|
|
|
pSystemConsts = &systemConsts;
|
2021-06-18 21:48:40 +08:00
|
|
|
|
2021-06-20 09:27:37 +08:00
|
|
|
//load settings
|
2021-08-30 18:07:55 +08:00
|
|
|
pSettings = new Settings(settingFilename);
|
2021-06-20 09:27:37 +08:00
|
|
|
auto settings = std::unique_ptr<Settings>(pSettings);
|
2021-08-07 14:08:51 +08:00
|
|
|
|
2021-06-20 14:30:47 +08:00
|
|
|
//Color scheme settings must be loaded after translation
|
|
|
|
pColorManager = new ColorManager();
|
2021-06-24 16:05:19 +08:00
|
|
|
pIconsManager = new IconsManager();
|
2021-09-04 11:37:04 +08:00
|
|
|
pAutolinkManager = new AutolinkManager();
|
2021-09-04 19:27:44 +08:00
|
|
|
try {
|
|
|
|
pAutolinkManager->load();
|
|
|
|
} catch (FileError e) {
|
|
|
|
QMessageBox::critical(nullptr,
|
|
|
|
QObject::tr("Can't load autolink settings"),
|
|
|
|
e.reason(),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
}
|
2021-06-20 14:30:47 +08:00
|
|
|
|
2021-06-20 09:27:37 +08:00
|
|
|
MainWindow mainWindow;
|
|
|
|
pMainWindow = &mainWindow;
|
|
|
|
mainWindow.show();
|
|
|
|
int retCode = app.exec();
|
|
|
|
// save settings
|
|
|
|
// settings->compilerSets().saveSets();
|
|
|
|
return retCode;
|
|
|
|
} catch (BaseError e) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(nullptr,QApplication::tr("Error"),e.reason());
|
2021-06-21 22:01:35 +08:00
|
|
|
return -1;
|
2021-06-20 09:27:37 +08:00
|
|
|
}
|
2021-04-06 23:10:57 +08:00
|
|
|
}
|