blob: c80f86986fb0b46a7b326a31ad3e7b42054484fc (
plain)
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
|
#include <QtCore/QDebug>
#include <QtCore/QCommandLineParser>
#include <QtCore/QUrlQuery>
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlContext>
#include <QtQml/qqml.h>
#include <QQuickWindow>
#include <QQmlApplicationEngine>
#include <QApplication>
#include <taskmanager.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
QString graphic_role = QString("utility");
QString myname = QString("taskmanager");
QApplication app(argc, argv);
app.setDesktopFileName(myname);
QCommandLineParser parser;
parser.addPositionalArgument("port", app.translate("main", "port for binding"));
parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
parser.addHelpOption();
parser.addVersionOption();
parser.process(app);
QStringList positionalArguments = parser.positionalArguments();
qmlRegisterType<TaskManager>("TaskManager", 1, 0, "TaskManager");
QQmlApplicationEngine engine;
if (positionalArguments.length() != 2) {
qDebug() << "[ERROR] No port and token specified!";
return -1;
}
int port = positionalArguments.takeFirst().toInt();
QString secret = positionalArguments.takeFirst();
QUrl bindingAddress;
bindingAddress.setScheme(QStringLiteral("ws"));
bindingAddress.setHost(QStringLiteral("localhost"));
bindingAddress.setPort(port);
bindingAddress.setPath(QStringLiteral("/api"));
QUrlQuery query;
query.addQueryItem(QStringLiteral("token"), secret);
bindingAddress.setQuery(query);
QQmlContext *context = engine.rootContext();
context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
qDebug() << "Connect to: " << bindingAddress;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
|