-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·129 lines (119 loc) · 3.38 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
127
128
129
#include <QQmlApplicationEngine>
// #include <iostream>
#include <QQmlContext>
#include <QQuickWindow>
#include <QIcon>
#include <QUuid>
#include "com/async.h"
#include "com/global.h"
#include "app.h"
#include <QApplication>
#include <QDir>
#include <QFont>
#include <QSemaphore>
#include <QStandardPaths>
#include <QTranslator>
#include <QThread>
#include <QClipboard>
#ifdef Q_OS_MAC
#include "com/mac.h"
#endif
#include "com/runmain.h"
// #include "hserver.h"
#include "timer.h"
using namespace std;
class MyApplication: public QApplication {
public:
MyApplication(int &argc, char **argv): QApplication(argc, argv) {
}
bool event(QEvent *event) override {
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
QString curXM = openEvent->file();
qDebug() << "Open file" << curXM;
XM *pk = xm_format->openFile(curXM, "");
QObject* root = engine->rootObjects().at(0);
QMetaObject::invokeMethod(root, "openXM", Q_ARG(QVariant, QVariant::fromValue(pk->toVMap(true))));
}
return QApplication::event(event);
}
};
int start(int argc, char *argv[]);
int initGui(MyApplication* a);
void initCfg();
void exit_(int r);
int main(int argc, char *argv[]) {
return start(argc, argv);
}
int start(int argc, char* argv[]) {
MyApplication *ma = new MyApplication(argc, argv);
#ifdef Q_OS_MAC
mac->loadBookmarks();
#endif
a->initCfg();
initGlobal();
RunMain::INS().init();
Com_Async->start();
DB_Async->start();
SM_Async->start();
// HServer::INS().loop();
a->init();
Timer::INS().init();
return initGui(ma);
// return 0;
}
int initGui(MyApplication* ma) {
engine = new QQmlApplicationEngine();
engine->rootContext()->setContextProperty("$a", a);
engine->rootContext()->setContextProperty("$l", l);
engine->rootContext()->setContextProperty("$xm", xmAction);
engine->rootContext()->setContextProperty("$bk", bookAction);
//
QString mainQml = QStringLiteral("qrc:/qml/Main.qml");
// QString mainQml = QStringLiteral("qrc:/qml/com/VideoPlayer.qml");
const QUrl url(mainQml);
QObject::connect(engine, &QQmlApplicationEngine::objectCreated, a, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl) {
QCoreApplication::exit(-1);
}
}, Qt::QueuedConnection);
QObject::connect(engine, &QQmlEngine::quit, a, &QGuiApplication::quit);
QObject::connect(ma, &QCoreApplication::aboutToQuit, []{
exit_(0);
});
engine->load(url);
//
a->setGlobalHotkey(0, cfg->hotKeyXm);
a->setGlobalHotkey(1, cfg->hotKeyShow);
a->setGlobalHotkey(2, cfg->hotKeyCmd);
#ifdef Q_OS_MAC
ma->setWindowIcon(QIcon(":/assets/logo.icns"));
// w->setIcon(QIcon(":assets/logo.icns"));
// mac->initWindow(w);
#endif
#ifdef Q_OS_WIN
QObject *qmlRoot = engine->rootObjects().at(0);
QWindow *w = qobject_cast<QWindow *>(qmlRoot);
w->setIcon(QIcon(":assets/logo.ico"));
#endif
lg->info("xxmoon started");
QFont font;
#ifdef Q_OS_MAC
font.setFamily("Arial");
#endif
#ifdef Q_OS_WIN
font.setFamily("微软雅黑");
#endif
qApp->setFont(font);
// test13();
int r = ma->exec();
delete ma;
return r;
}
void exit_(int r) {
a->close(r);
#ifdef Q_OS_MAC
mac->close();
#endif
qDebug() << "XXMOON EXITED";
}