Remove homescreen api and windowmanager api depependency
[apps/videoplayer.git] / app / main.cpp
index 7fdff20..11b1230 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <QtAGLExtras/AGLApplication>
 #include <QtQml/QQmlApplicationEngine>
+#include <QtGui/QGuiApplication>
+#include <QDebug>
+#include <QUrlQuery>
+#include <QCommandLineParser>
+#include <QtQml/QQmlContext>
+
 
 int main(int argc, char *argv[])
 {
-    AGLApplication app(argc, argv);
-    app.setApplicationName("VideoPlayer");
-    app.setupApplicationRole("Video");
-    app.load(QUrl(QStringLiteral("qrc:/VideoPlayer.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(QStringLiteral("bindingAddress"), bindingAddress);
+       engine.load(QUrl(QStringLiteral("qrc:/VideoPlayer.qml")));
+
+       return app.exec();
+       
 }