-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
82 lines (65 loc) · 2.32 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
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "rootcontext.h"
#include <iostream>
/*
* The app usage:
* vmmanager [--vmd-client-dir <directory>]
* The application vmmanager can be run with or without vmd-client-dir argument. If no argument specified the vmd-client dir is set to current dir.
*/
//! add check for another app instance?
const QString get_option(const QList<QString>& args, const QString& option_name)
{
for (auto it = args.begin(), end = args.end(); it != end; ++it)
{
if (*it == option_name)
{
if (it + 1 != end)
return *(it + 1);
}
}
return "";
}
bool has_option(const QList<QString>& args, const QString& option_name)
{
for (auto it = args.begin(), end = args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
return false;
}
int main(int argc, char *argv[])
{
//args handling
const QList<QString> args(argv, argv + argc);
QString vmd_dir = get_option(args, "--vmd-client-dir");
if (vmd_dir.isEmpty() && argc > 1) {
std::cout << "Wrong arguments!\nUsage: vmmanager [--vmd-client-dir] <DIRECTORY>\n<DIRECTORY> - directory where CLI client is located (temporary solution for Ubuntu)\n";
return 1;
}
qDebug() << "arg: " << vmd_dir;
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
//register enums
qRegisterMetaType<Views>("Views");
qmlRegisterUncreatableType<EnumClass>("ViewEnums", 1, 0, "Views", "Not creatable as it is an enum type");
RootContext context;
context.setVmdDir(vmd_dir);//set dir to the CLI client and update the model
QQmlApplicationEngine engine;
#ifdef TABLET
const QUrl url(QStringLiteral("qrc:/tablet/main.qml"));
#else
const QUrl url(QStringLiteral("qrc:/main.qml"));
#endif
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.rootContext()->setContextProperty("rootContext", &context);
engine.rootContext()->setContextProperty("VMDataModel", context.getVMDataModel());
engine.load(url);
return app.exec();
}