Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (58 loc) · 2.06 KB
/
Copy pathmain.cpp
File metadata and controls
68 lines (58 loc) · 2.06 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
/*
* Copyright (C) 2017 ~ 2026 Deepin Technology Co., Ltd. / GXDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <QApplication>
#include <QIcon>
#include <QLocalServer>
#include <QLocalSocket>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
#include <QUrl>
#include "dictapi.h"
#include "systembridge.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QCoreApplication::setOrganizationName("GXDE");
QCoreApplication::setApplicationName("gxde-dict");
QCoreApplication::setApplicationVersion("1.0.4");
app.setWindowIcon(QIcon(":/images/gxde-dict.svg"));
// Custom styles are resolved by their full module URI.
QQuickStyle::setStyle("QtQuick.Controls.Gxde");
QQuickStyle::setFallbackStyle("Basic");
const QString instanceName = QStringLiteral("gxde-dict");
QLocalSocket socket;
socket.connectToServer(instanceName);
if (socket.waitForConnected(200)) {
return 0;
}
QLocalServer server;
if (!server.listen(instanceName)) {
QLocalServer::removeServer(instanceName);
server.listen(instanceName);
}
DictApi *api = DictApi::instance();
SystemBridge bridge;
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("dictApi", api);
engine.rootContext()->setContextProperty("systemBridge", &bridge);
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && objUrl == url) {
QCoreApplication::exit(-1);
}
},
Qt::QueuedConnection);
engine.load(url);
if (engine.rootObjects().isEmpty()) {
return -1;
}
return app.exec();
}