app/: Avoid any AGL wrappers and use plain Qt
authorMarius Vlad <marius.vlad@collabora.com>
Tue, 21 Jan 2020 23:18:44 +0000 (01:18 +0200)
committerMarius Vlad <marius.vlad@collabora.com>
Wed, 22 Jan 2020 18:25:47 +0000 (20:25 +0200)
Removes homescreen/windowmanger requirements from config

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I99a2221e44d04a06b8d3cf412b22e0204a9c89a5

app/app.pro
app/main.cpp
package/config.xml

index ef4de97..d10f9c0 100644 (file)
@@ -1,5 +1,10 @@
 TARGET = hvac
-QT = quick qml aglextras
+QT = quick qml websockets
+
+CONFIG += c++11 link_pkgconfig
+PKGCONFIG += qtappfw afb-helpers-qt
+
+#aglextras
 
 HEADERS += \
     translator.h
index 2fac9ae..6fe54a5 100644 (file)
  * limitations under the License.
  */
 
-#include <QtAGLExtras/AGLApplication>
+#include <QtGui/QGuiApplication>
+#include <QDebug>
+#include <QUrlQuery>
+#include <QCommandLineParser>
 #include <QtQml/QQmlApplicationEngine>
+#include <QtQml/QQmlContext>
 
 #include "translator.h"
 
 int main(int argc, char *argv[])
 {
-    AGLApplication app(argc, argv);
-    app.setApplicationName("HVAC");
-    app.setupApplicationRole("hvac");
-    qmlRegisterType<Translator>("Translator", 1, 0, "Translator");
-    app.load(QUrl(QStringLiteral("qrc:/HVAC.qml")));
-    return app.exec();
-}
+       setenv("QT_QPA_PLATFORM", "wayland", 1);
+       int port;
+       QString token;
+
+       QCommandLineParser parser;
+       QGuiApplication app(argc, argv);
+
+       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();
+
+       if (positionalArguments.length() == 2) {
+               port = positionalArguments.takeFirst().toInt();
+               token = positionalArguments.takeFirst();
+               qInfo() << "setting port:" << port << ", token:" << token;
+       } else {
+               qInfo() << "Need to specify port and token";
+               exit(EXIT_FAILURE);
+       }
 
+       QUrl bindingAddress;
+       bindingAddress.setScheme(QStringLiteral("ws"));
+       bindingAddress.setHost(QStringLiteral("localhost"));
+       bindingAddress.setPort(port);
+       bindingAddress.setPath(QStringLiteral("/api"));
+
+       QUrlQuery query;
+       query.addQueryItem(QStringLiteral("token"), token);
+       bindingAddress.setQuery(query);
+
+       QQmlApplicationEngine engine;
+       engine.rootContext()->setContextProperty("bindingAddress", bindingAddress);
+       qmlRegisterType<Translator>("Translator", 1, 0, "Translator");
+       engine.load(QUrl(QStringLiteral("qrc:/HVAC.qml")));
+
+       return app.exec();
+}
index cd4dbbd..c830521 100644 (file)
@@ -7,8 +7,6 @@
   <author>Romain Forlot &lt;romain.forlot@iot.bzh&gt;</author>
   <license>APL 2.0</license>
   <feature name="urn:AGL:widget:required-api">
-    <param name="windowmanager" value="ws" />
-    <param name="homescreen" value="ws" />
     <param name="identity" value="ws" />
     <param name="HVAC" value="ws" />
   </feature>