RedPanda-CPP/RedPandaIDE/main.cpp

90 lines
2.7 KiB
C++
Raw Normal View History

2021-04-06 23:10:57 +08:00
#include "mainwindow.h"
#include "settings.h"
2021-04-11 21:33:08 +08:00
#include "systemconsts.h"
#include "utils.h"
2021-04-06 23:10:57 +08:00
#include <QApplication>
#include <QDir>
#include <QTranslator>
#include <QDebug>
#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"
Settings* createAppSettings(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
}
} else {
filename = filepath;
}
2021-04-15 11:18:14 +08:00
QFileInfo fileInfo(filename);
QDir dir(fileInfo.absoluteDir());
if (!dir.exists()) {
if (!dir.mkpath(dir.absolutePath())) {
QMessageBox::critical(nullptr, QObject::tr("Error"),
QString(QObject::tr("Can't create configuration folder %1")).arg(dir.absolutePath()));
return nullptr;
}
}
if (fileInfo.exists() && !fileInfo.isWritable()) {
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));
return nullptr;
}
return new Settings(filename);
}
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-24 15:57:45 +08:00
qRegisterMetaType<PCompileIssue>("PCompileIssue");
qRegisterMetaType<PCompileIssue>("PCompileIssue&");
2021-06-20 09:27:37 +08:00
try {
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
pSettings = createAppSettings();
if (pSettings == nullptr) {
return -1;
}
auto settings = std::unique_ptr<Settings>(pSettings);
2021-06-20 14:30:47 +08:00
settings->environment().load();
2021-06-20 09:27:37 +08:00
settings->compilerSets().loadSets();
settings->editor().load();
2021-06-20 14:30:47 +08:00
//Translation must be loaded after language setting is loaded
2021-06-20 09:27:37 +08:00
QTranslator trans;
trans.load("RedPandaIDE_"+pSettings->environment().language(),":/translations");
app.installTranslator(&trans);
2021-06-05 23:43:45 +08:00
2021-06-20 14:30:47 +08:00
//Color scheme settings must be loaded after translation
pColorManager = new ColorManager();
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) {
QMessageBox::critical(nullptr,QApplication::tr("Error"),e.reason());
return -1;
2021-06-20 09:27:37 +08:00
}
2021-04-06 23:10:57 +08:00
}