-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
126 lines (103 loc) · 4.23 KB
/
main.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <QApplication>
#include <QCoreApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
#include <QQuickWindow>
#include <QIcon>
#include <QTranslator>
#include <QDebug>
#include <QFile>
#include <QDateTime>
#include "singleappinstance.h"
#include "controller.h"
#include "helper.h"
#include "winsys.h"
#include "settings.h"
#include "keyboard.h"
#include "update.h"
int main(int argc, char *argv[])
{
WinSys *winSys = WinSys::instance();
SingleAppInstance *singleAppInstance = SingleAppInstance::instance();
if (singleAppInstance->isRunning())
return 1;
if (argc >= 2 && !strcmp(argv[1], "--elevate") && !winSys->hasAdminRights()) {
qInfo() << "Restarting with admin rights";
singleAppInstance->restartWithAdminRights();
return 0;
}
Settings *settings = Settings::instance();
Keyboard *keyboard = Keyboard::instance();
ControllerThread *controllerThread = ControllerThread::instance();
controllerThread->start();
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QQuickStyle::setStyle("Fusion");
QApplication app(argc, argv);
app.setWindowIcon(QIcon(":/images/icon.svg"));
Helper *helper = Helper::instance();
Update *update = Update::instance();
QTranslator translator;
QString lang = settings->language();
if (lang == Settings::LANGUAGE_STRING_SYSTEM)
lang = QLocale::system().name();
if (lang != "en_EN") {
if (!translator.load(QString(":/languages/PowerPAD_%1.qm").arg(lang)))
qDebug().nospace() << "Failed to load translator for language " << lang;
else {
if (!app.installTranslator(&translator))
qDebug().nospace() << "Failed to install translator for language " << lang;
else
qDebug().nospace() << "Translator for language " << lang << " successfully installed";
}
}
QLocale::setDefault(QLocale(lang));
qmlRegisterSingletonType<ControllerThread>("com.tekit.powerpad.winsys", 1, 0, "WinSys",
[winSys](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return winSys;
});
qmlRegisterSingletonType<ControllerThread>("com.tekit.powerpad.controllerthread", 1, 0, "ControllerThread",
[controllerThread](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return controllerThread;
});
qmlRegisterSingletonType<Helper>("com.tekit.powerpad.helper", 1, 0, "Helper",
[helper](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return helper;
});
qmlRegisterSingletonType<Settings>("com.tekit.powerpad.settings", 1, 0, "Settings",
[settings](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return settings;
});
qmlRegisterSingletonType<Keyboard>("com.tekit.powerpad.keyboard", 1, 0, "Keyboard",
[keyboard](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return keyboard;
});
qmlRegisterSingletonType<Keyboard>("com.tekit.powerpad.update", 1, 0, "Update",
[update](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return update;
});
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
int ret = app.exec();
controllerThread->stop();
return ret;
}