summaryrefslogtreecommitdiffstats
path: root/app/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'app/main.cpp')
-rw-r--r--app/main.cpp130
1 files changed, 46 insertions, 84 deletions
diff --git a/app/main.cpp b/app/main.cpp
index 88a4978..6fd928d 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -19,76 +19,25 @@
#include <QtCore/QCommandLineParser>
#include <QtCore/QUrlQuery>
#include <QtCore/QFile>
-#include <QtDBus/QDBusInterface>
-#include <QtDBus/QDBusReply>
#include <QtGui/QGuiApplication>
-#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlContext>
+#include <QtQml/QQmlApplicationEngine>
#include <QtQuickControls2/QQuickStyle>
-#include <QtDBus/QDBusConnection>
#include <unistd.h>
#include "camera.h"
#include <QQuickWindow>
+
+#ifdef HAVE_LIBHOMESCREEN
#include <libhomescreen.hpp>
+#endif
+#ifdef HAVE_QLIBWINDOWMANAGER
#include <qlibwindowmanager.h>
-
-class AppVisible : public QObject
-{
- Q_OBJECT
-public:
- AppVisible(QObject *parent = nullptr) : QObject(parent){
- m_ppid = getppid();
- m_visible = true;
- QDBusConnection::sessionBus().connect("org.agl.windowmanager",
- "/windowmanager",
- "org.agl.windowmanager",
- "appLayerVisibleChanged",
- this,
- SLOT(appLayerVisibleChanged(int,bool)));
- }
-
-public slots:
- void appLayerVisibleChanged(int pid, bool visible){
- bool tempvis = visible;
-
- if(tempvis && (m_ppid != pid))
- tempvis = false;
-
- if(m_visible != tempvis){
- m_visible = tempvis;
- emit visibleChanged(m_visible);
- }
- }
-
-signals:
- void visibleChanged(const bool& visible);
-
-private:
- int m_ppid;
- bool m_visible;
-};
-
-class DBus : public QObject
-{
- Q_OBJECT
-public:
- DBus(QObject *parent = nullptr)
- : QObject(parent)
- , interface("org.agl.homescreen", "/StatusBar", "org.agl.statusbar", QDBusConnection::sessionBus())
- {}
-
- Q_INVOKABLE void setStatusIcon(int index, const QString &url) {
- interface.call("setStatusIcon", index, url);
- }
-
-private:
- QDBusInterface interface;
-};
+#endif
int main(int argc, char *argv[])
{
- QString myname = QString("Als-meter-demo");
+ QString myname = QString("camapp");
QGuiApplication app(argc, argv);
app.setApplicationName(myname);
@@ -109,29 +58,28 @@ int main(int argc, char *argv[])
qmlRegisterType<Camera>("Camera", 1, 0, "Camera");
QQmlApplicationEngine engine;
+ QQmlContext *context = engine.rootContext();
+ QUrl bindingAddress;
int port = 0;
+ QString secret;
if (positionalArguments.length() == 2) {
port = positionalArguments.takeFirst().toInt();
+ secret = positionalArguments.takeFirst();
+ 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);
+ context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
+ } else {
+ context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
}
- QString secret = positionalArguments.takeFirst();
- QUrl bindingAddressWS;
- bindingAddressWS.setScheme(QStringLiteral("ws"));
- bindingAddressWS.setHost(QStringLiteral("localhost"));
- bindingAddressWS.setPort(port);
- bindingAddressWS.setPath(QStringLiteral("/api"));
- QUrlQuery query;
- query.addQueryItem(QStringLiteral("token"), secret);
- bindingAddressWS.setQuery(query);
- QQmlContext *context = engine.rootContext();
- AppVisible appVisible;
- context->setContextProperty(QStringLiteral("appVisible"), &appVisible);
- context->setContextProperty(QStringLiteral("bindingAddressWS"), bindingAddressWS);
-
- std::string token = secret.toStdString();
- LibHomeScreen* hs = new LibHomeScreen();
- QLibWindowmanager* qwm = new QLibWindowmanager();
+#ifdef HAVE_QLIBWINDOWMANAGER
// WindowManager
+ QLibWindowmanager* qwm = new QLibWindowmanager();
if(qwm->init(port,secret) != 0){
exit(EXIT_FAILURE);
}
@@ -144,8 +92,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "Surface got syncDraw!\n");
qwm->endDraw(myname);
});
+#endif
+#ifdef HAVE_LIBHOMESCREEN
// HomeScreen
+ LibHomeScreen* hs = new LibHomeScreen();
+ std::string token = secret.toStdString();
hs->init(port, token.c_str());
// Set the event handler for Event_TapShortcut which will activate the surface for windowmanager
hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [qwm, myname](json_object *object){
@@ -153,24 +105,34 @@ int main(int argc, char *argv[])
if(json_object_object_get_ex(object, "application_name", &appnameJ))
{
const char *appname = json_object_get_string(appnameJ);
- if(myname == appname)
+ if(QString::compare(myname, appname, Qt::CaseInsensitive) == 0)
{
qDebug("Surface %s got tapShortcut\n", appname);
qwm->activateSurface(myname);
}
}
});
-
- DBus dbus;
- engine.rootContext()->setContextProperty("dbus", &dbus);
- engine.load(QUrl(QStringLiteral("qrc:/Als-meter-demo.qml")));
+#endif
+ engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QObject *root = engine.rootObjects().first();
QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
- QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface()
- ));
+#ifdef HAVE_QLIBWINDOWMANAGER
+ QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface()));
+
+ qwm->set_event_handler(QLibWindowmanager::Event_Visible, [qwm, root](json_object *object) {
+ fprintf(stderr, "Surface got Visible!\n");
+ QMetaObject::invokeMethod(root, "changeVisible", Q_ARG(QVariant, true));
+ });
+
+ qwm->set_event_handler(QLibWindowmanager::Event_Invisible, [qwm, root](json_object *object) {
+ fprintf(stderr, "Surface got Invisible!\n");
+ QMetaObject::invokeMethod(root, "changeVisible", Q_ARG(QVariant, false));
+ });
+#else
+ window->resize(1280, 720);
+ window->setVisible(true);
+#endif
return app.exec();
}
-
-#include "main.moc"