22e600e5e8c2211f519d992bab64f8b9d33c382a
[apps/launcher.git] / launcher / src / main.cpp
1 /*
2  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
3  * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <QGuiApplication>
19 #include <QCommandLineParser>
20 #include <QtCore/QUrlQuery>
21 #include <QtGui/QGuiApplication>
22 #include <QtQml/QQmlApplicationEngine>
23 #include <QtQml/QQmlContext>
24 #include <QtQml/qqml.h>
25 #include <QQuickWindow>
26 #include <QThread>
27
28 #include "applicationmodel.h"
29 #include "appinfo.h"
30 #include "homescreenhandler.h"
31 #include "hmi-debug.h"
32 #include "shell-desktop.h"
33
34 int main(int argc, char *argv[])
35 {
36     QString myname = QString("launcher");
37     QGuiApplication a(argc, argv);
38
39     //QCoreApplication::setOrganizationDomain("LinuxFoundation");
40     //QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
41     //QCoreApplication::setApplicationName(myname);
42     //QCoreApplication::setApplicationVersion("0.1.0");
43
44     // necessary to identify correctly by app_id
45     a.setDesktopFileName(myname);
46
47     QCommandLineParser parser;
48     parser.addPositionalArgument("port", a.translate("main", "port for binding"));
49     parser.addPositionalArgument("secret", a.translate("main", "secret for binding"));
50     parser.addHelpOption();
51     parser.addVersionOption();
52     parser.process(a);
53     QStringList positionalArguments = parser.positionalArguments();
54
55     int port = 1700;
56     QString token = "wm";
57
58     if (positionalArguments.length() == 2) {
59         port = positionalArguments.takeFirst().toInt();
60         token = positionalArguments.takeFirst();
61     }
62
63     HMI_DEBUG("launcher","port = %d, token = %s", port, token.toStdString().c_str());
64
65     // import C++ class to QML
66     qmlRegisterType<ApplicationModel>("AppModel", 1, 0, "ApplicationModel");
67
68     HomescreenHandler* homescreenHandler = new HomescreenHandler();
69     homescreenHandler->init(port, token.toStdString().c_str(), myname);
70
71     QUrl bindingAddress;
72     bindingAddress.setScheme(QStringLiteral("ws"));
73     bindingAddress.setHost(QStringLiteral("localhost"));
74     bindingAddress.setPort(port);
75     bindingAddress.setPath(QStringLiteral("/api"));
76
77     QUrlQuery query;
78     query.addQueryItem(QStringLiteral("token"), token);
79     bindingAddress.setQuery(query);
80
81     // mail.qml loading
82     QQmlApplicationEngine engine;
83     engine.rootContext()->setContextProperty(QStringLiteral("homescreenHandler"), homescreenHandler);
84     engine.load(QUrl(QStringLiteral("qrc:/Launcher.qml")));
85     homescreenHandler->getRunnables();
86
87     return a.exec();
88 }