-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathLemonBaseApplication.cpp
More file actions
97 lines (86 loc) · 2.69 KB
/
LemonBaseApplication.cpp
File metadata and controls
97 lines (86 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* SPDX-FileCopyrightText: 2020-2021 Project LemonLime
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "LemonBaseApplication.hpp"
//
#include "base/LemonLog.hpp"
#include "base/LemonTranslator.hpp"
#include "base/settings.h" // TODO: Config Refactor
//
#include <QCoreApplication>
//
#define LEMON_MODULE_NAME "LemonBaseApplication"
using namespace Lemon;
auto LemonBaseApplication::Initialize() -> bool {
QString errorMessage;
bool canContinue;
const auto hasError = parseCommandLine(&canContinue, &errorMessage);
if (hasError) {
LOG("Command line: " GEN_PAIR(errorMessage));
if (! canContinue) {
LOG("Fatal Error, LemonLime cannot continue.");
return false;
} else {
LOG("Non-fatal error, LemonLime will continue starting up.");
}
}
// Load Translations
Settings *settings = new Settings;
settings->loadSettings();
LemonLimeTranslator = std::make_unique<LemonTranslator>();
const auto allTranslations = LemonLimeTranslator->GetAvailableLanguages();
const auto osLanguage = QLocale::system().name();
if (! allTranslations.contains(settings->getUiLanguage())) {
// If we need to reset the language.
if (allTranslations.contains(osLanguage)) {
settings->setUiLanguage(osLanguage);
} else if (! allTranslations.isEmpty()) {
settings->setUiLanguage(allTranslations.first());
}
}
LemonLimeTranslator->InstallTranslation(settings->getUiLanguage());
return true;
}
auto LemonBaseApplication::parseCommandLine(bool *canContinue, QString *errorMessage) -> bool {
*canContinue = true;
QStringList filteredArgs;
for (const auto &arg : arguments()) {
#ifdef Q_OS_MACOS
if (arg.contains("-psn"))
continue;
#endif
filteredArgs << arg;
}
QCommandLineParser parser;
//
QCommandLineOption debugLogOption("debug", QObject::tr("Enable debug output"));
//
parser.setApplicationDescription(QObject::tr("LemonLime - A tiny judging environment for OI contest."));
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
//
parser.addOption(debugLogOption);
//
const auto helpOption = parser.addHelpOption();
const auto versionOption = parser.addVersionOption();
if (! parser.parse(filteredArgs)) {
*canContinue = true;
*errorMessage = parser.errorText();
return false;
}
if (parser.isSet(versionOption)) {
parser.showVersion();
return true;
}
if (parser.isSet(helpOption)) {
parser.showHelp();
return true;
}
#define ProcessExtraStartupOptions(option) \
DEBUG("Startup Options:" GEN_PAIR(parser.isSet(option##Option))); \
StartupArguments.option = parser.isSet(option##Option);
ProcessExtraStartupOptions(debugLog);
return true;
}