From 49f1261bf9d635d5e3d881e87a93ed4e76abfe90 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 30 Nov 2014 17:27:08 +0100 Subject: allow receiving responses to commands in watchconnector * the skeleton is in place for watchconnector to allow query->response messages. I've used call/cc style because it is impossible to make QBluetoothSocket synchronous (waitForReadyRead() is a no-op) * remove watchcommands, instead create musicmanager to listen for the music endpoint. The other (simpler) endpoints are now listened in watchconnector itself. hangupAll() slot is moved to voicecallmanager. * instead of emitting signals for each received message, listeners can now register for receiving messages targeted towards a given endpoint * when reading from bluetoothsocket, properly handle short reads * remove useless 'watch' namespace * create appmanager, which mantains a database of installed apps (installed on the phone, that is; watch installed apps will come later) * all the *Managers are now instantiated by the main Manager itself * introduce Unpacker helper class for decoding watch messages * implement getAppbankStatus and getAppbankUuids messages and response parsers * remove file logging for now (20MB is bad for eMMC!) * use dbus object path /org/pebbled instead of / --- daemon/dbusadaptor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'daemon/dbusadaptor.cpp') diff --git a/daemon/dbusadaptor.cpp b/daemon/dbusadaptor.cpp index 3332551..7bbf623 100644 --- a/daemon/dbusadaptor.cpp +++ b/daemon/dbusadaptor.cpp @@ -75,10 +75,13 @@ void PebbledAdaptor::time() QMetaObject::invokeMethod(parent(), "time"); } - void PebbledAdaptor::reconnect() { // handle method call org.pebbled.reconnect QMetaObject::invokeMethod(parent(), "reconnect"); } +void PebbledAdaptor::test() +{ + QMetaObject::invokeMethod(parent(), "test"); +} -- cgit v1.2.3 From 81f91639969de0f3852a3fe73db13b4cb0ecf3b4 Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 1 Dec 2014 04:13:06 +0100 Subject: hackily implement openURL by signalling the URLs via D-Bus to the settings app, which pops a webview --- app/app.pro | 3 ++- app/pebbledinterface.cpp | 16 ++++++++++++++++ app/pebbledinterface.h | 4 ++++ app/qml/pages/WebViewPage.qml | 29 +++++++++++++++++++++++++++++ app/qml/pebble.qml | 5 +++++ daemon/dbusadaptor.cpp | 5 +++++ daemon/dbusadaptor.h | 8 ++++++++ daemon/jskitmanager.cpp | 10 ++++++++++ daemon/jskitmanager.h | 2 ++ daemon/jskitobjects.cpp | 10 ++++++++-- daemon/jskitobjects.h | 12 ++++++------ daemon/manager.cpp | 6 ++++++ daemon/manager.h | 3 ++- 13 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 app/qml/pages/WebViewPage.qml (limited to 'daemon/dbusadaptor.cpp') diff --git a/app/app.pro b/app/app.pro index cb4c33b..e08fa87 100644 --- a/app/app.pro +++ b/app/app.pro @@ -22,4 +22,5 @@ OTHER_FILES += \ qml/pebble.qml \ qml/images/* \ pebble.desktop \ - pebble.png + pebble.png \ + qml/pages/WebViewPage.qml diff --git a/app/pebbledinterface.cpp b/app/pebbledinterface.cpp index c6f5674..8759863 100644 --- a/app/pebbledinterface.cpp +++ b/app/pebbledinterface.cpp @@ -19,6 +19,10 @@ PebbledInterface::PebbledInterface(QObject *parent) : PEBBLED_DBUS_SERVICE, PEBBLED_DBUS_PATH, PEBBLED_DBUS_IFACE, "pebbleChanged", this, SLOT(onPebbleChanged())); + QDBusConnection::sessionBus().connect( + PEBBLED_DBUS_SERVICE, PEBBLED_DBUS_PATH, PEBBLED_DBUS_IFACE, + "openUrl", this, SIGNAL(openUrl(QString))); + // simulate connected change on active changed // as the daemon might not had a chance to send 'connectedChanged' // when going down @@ -163,3 +167,15 @@ void PebbledInterface::reconnect() qDebug() << __FUNCTION__; PebbledDbusInterface.call("reconnect"); } + +void PebbledInterface::test() +{ + qDebug() << __FUNCTION__; + PebbledDbusInterface.call("test"); +} + +void PebbledInterface::webviewClosed(const QString &result) +{ + qDebug() << __FUNCTION__; + PebbledDbusInterface.call("webviewClosed", QVariant::fromValue(result)); +} diff --git a/app/pebbledinterface.h b/app/pebbledinterface.h index 0a6f15d..7d00110 100644 --- a/app/pebbledinterface.h +++ b/app/pebbledinterface.h @@ -45,6 +45,8 @@ signals: void nameChanged(); void addressChanged(); + void openUrl(const QString &url); + public slots: void setEnabled(bool); void setActive(bool); @@ -52,6 +54,8 @@ public slots: void time(); void disconnect(); void reconnect(); + void test(); + void webviewClosed(const QString &result); private slots: void getUnitProperties(); diff --git a/app/qml/pages/WebViewPage.qml b/app/qml/pages/WebViewPage.qml new file mode 100644 index 0000000..2c6fcf0 --- /dev/null +++ b/app/qml/pages/WebViewPage.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 +import QtQml 2.1 +import QtWebKit 3.0 +import Sailfish.Silica 1.0 + +Page { + id: webviewPage + + property alias url: webview.url + + SilicaWebView { + id: webview + anchors.fill: parent + + onNavigationRequested: { + console.log("navigation requested to " + request.url); + var url = request.url.toString() + if (/^pebblejs:\/\/close/.exec(url)) { + var data = decodeURI(url.substring(17)); + console.log("match with pebble close regexp. data: " + data); + pebbled.webviewClosed(data); + pageStack.pop(); + request.action = WebView.IgnoreRequest; + } else { + request.action = WebView.AcceptRequest; + } + } + } +} diff --git a/app/qml/pebble.qml b/app/qml/pebble.qml index da3bfb5..2ff0839 100644 --- a/app/qml/pebble.qml +++ b/app/qml/pebble.qml @@ -41,5 +41,10 @@ ApplicationWindow PebbledInterface { id: pebbled + + onOpenUrl: { + console.log("got open url: " + url); + pageStack.push(Qt.resolvedUrl("pages/WebViewPage.qml"), {url: url}); + } } } diff --git a/daemon/dbusadaptor.cpp b/daemon/dbusadaptor.cpp index 7bbf623..25e2508 100644 --- a/daemon/dbusadaptor.cpp +++ b/daemon/dbusadaptor.cpp @@ -85,3 +85,8 @@ void PebbledAdaptor::test() { QMetaObject::invokeMethod(parent(), "test"); } + +void PebbledAdaptor::webviewClosed(const QString &result) +{ + QMetaObject::invokeMethod(parent(), "webviewClosed", Q_ARG(QString, result)); +} diff --git a/daemon/dbusadaptor.h b/daemon/dbusadaptor.h index 54a0963..f347f92 100644 --- a/daemon/dbusadaptor.h +++ b/daemon/dbusadaptor.h @@ -47,6 +47,12 @@ class PebbledAdaptor: public QDBusAbstractAdaptor " \n" " \n" " \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" " \n" "") public: @@ -72,9 +78,11 @@ public Q_SLOTS: // METHODS void time(); void reconnect(); void test(); + void webviewClosed(const QString &result); Q_SIGNALS: // SIGNALS void connectedChanged(); void pebbleChanged(); + void openUrl(const QString &s); }; #endif diff --git a/daemon/jskitmanager.cpp b/daemon/jskitmanager.cpp index 6023a9a..cfd860e 100644 --- a/daemon/jskitmanager.cpp +++ b/daemon/jskitmanager.cpp @@ -31,6 +31,16 @@ void JSKitManager::showConfiguration() } } +void JSKitManager::handleWebviewClosed(const QString &result) +{ + if (_engine) { + QJSValue eventObj = _engine->newObject(); + eventObj.setProperty("response", _engine->toScriptValue(result)); + + _jspebble->invokeCallbacks("webviewclosed", QJSValueList({eventObj})); + } +} + void JSKitManager::handleAppStarted(const QUuid &uuid) { AppInfo info = _apps->info(uuid); diff --git a/daemon/jskitmanager.h b/daemon/jskitmanager.h index 73d7853..fd6040d 100644 --- a/daemon/jskitmanager.h +++ b/daemon/jskitmanager.h @@ -22,9 +22,11 @@ public: signals: void appNotification(const QUuid &uuid, const QString &title, const QString &body); + void appOpenUrl(const QString &url); public slots: void showConfiguration(); + void handleWebviewClosed(const QString &result); private slots: void handleAppStarted(const QUuid &uuid); diff --git a/daemon/jskitobjects.cpp b/daemon/jskitobjects.cpp index f745233..9e4cfde 100644 --- a/daemon/jskitobjects.cpp +++ b/daemon/jskitobjects.cpp @@ -54,12 +54,15 @@ void JSKitPebble::showSimpleNotificationOnPebble(const QString &title, const QSt emit _mgr->appNotification(_appInfo.uuid(), title, body); } -void JSKitPebble::openUrl(const QUrl &url) +void JSKitPebble::openURL(const QUrl &url) { logger()->debug() << "opening url" << url.toString(); + emit _mgr->appOpenUrl(url.toString()); +#if 0 /* Until we figure out how to do this. Maybe signal the daemon? */ if (!QDesktopServices::openUrl(url)) { logger()->warn() << "Failed to open URL:" << url; } +#endif } QJSValue JSKitPebble::createXMLHttpRequest() @@ -253,7 +256,10 @@ void JSKitXMLHttpRequest::handleReplyFinished() if (_onload.isCallable()) { logger()->debug() << "going to call onload handler:" << _onload.toString(); - _onload.callWithInstance(_mgr->engine()->toScriptValue(this)); + QJSValue result = _onload.callWithInstance(_mgr->engine()->newQObject(this)); + if (result.isError()) { + logger()->warn() << "JS error on onload handler:" << result.toString(); + } } else { logger()->debug() << "No onload set"; } diff --git a/daemon/jskitobjects.h b/daemon/jskitobjects.h index 1962e01..4f000f1 100644 --- a/daemon/jskitobjects.h +++ b/daemon/jskitobjects.h @@ -21,7 +21,7 @@ public: Q_INVOKABLE void showSimpleNotificationOnPebble(const QString &title, const QString &body); - Q_INVOKABLE void openUrl(const QUrl &url); + Q_INVOKABLE void openURL(const QUrl &url); Q_INVOKABLE QJSValue createXMLHttpRequest(); @@ -88,11 +88,11 @@ public: ~JSKitXMLHttpRequest(); enum ReadyStates { - UNSENT, - OPENED, - HEADERS_RECEIVED, - LOADING, - DONE + UNSENT = 0, + OPENED = 1, + HEADERS_RECEIVED = 2, + LOADING = 3, + DONE = 4 }; Q_INVOKABLE void open(const QString &method, const QString &url, bool async); diff --git a/daemon/manager.cpp b/daemon/manager.cpp index 9db4c70..e732d38 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -61,6 +61,7 @@ Manager::Manager(Settings *settings, QObject *parent) : session.registerService("org.pebbled"); connect(dbus, SIGNAL(pebbleChanged()), adaptor, SIGNAL(pebbleChanged())); connect(watch, SIGNAL(connectedChanged()), adaptor, SIGNAL(connectedChanged())); + connect(js, SIGNAL(appOpenUrl(QString)), adaptor, SIGNAL(openUrl(QString))); QString currentProfile = getCurrentProfile(); defaultProfile = currentProfile.isEmpty() ? "ambience" : currentProfile; @@ -397,3 +398,8 @@ void Manager::test() js->showConfiguration(); } + +void Manager::onWebviewClosed(const QString &result) +{ + js->handleWebviewClosed(result); +} diff --git a/daemon/manager.h b/daemon/manager.h index f1dd53e..b0e15fb 100644 --- a/daemon/manager.h +++ b/daemon/manager.h @@ -84,6 +84,7 @@ public slots: private slots: void test(); + void onWebviewClosed(const QString &result); void onSettingChanged(const QString &key); void onSettingsChanged(); void onPebbleChanged(); @@ -123,7 +124,7 @@ public slots: void disconnect() { static_cast(parent())->watch->disconnect(); } void reconnect() { static_cast(parent())->watch->reconnect(); } void test() { static_cast(parent())->test(); } - + void webviewClosed(const QString &result) { static_cast(parent())->onWebviewClosed(result); } }; #endif // MANAGER_H -- cgit v1.2.3 From c35a3a9bea759cadf1e975a2a62e50789cad096c Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 2 Dec 2014 23:33:19 +0100 Subject: define new D-Bus interface, use qmake to generate adaptors/interfaces also slightly clean up the way d-bus is handled both in daemon and UI --- app/app.pro | 2 + app/pebbledinterface.cpp | 100 +++++++++++++++++++---------------------------- app/pebbledinterface.h | 45 +++++++-------------- daemon/daemon.pro | 5 +-- daemon/dbusadaptor.cpp | 92 ------------------------------------------- daemon/dbusadaptor.h | 88 ----------------------------------------- daemon/dbusconnector.h | 4 +- daemon/manager.cpp | 32 ++++++++------- daemon/manager.h | 91 ++++++++++++++++++++++++++++++------------ daemon/org.pebbled.xml | 20 ---------- org.pebbled.Watch.xml | 46 ++++++++++++++++++++++ 11 files changed, 191 insertions(+), 334 deletions(-) delete mode 100644 daemon/dbusadaptor.cpp delete mode 100644 daemon/dbusadaptor.h delete mode 100644 daemon/org.pebbled.xml create mode 100644 org.pebbled.Watch.xml (limited to 'daemon/dbusadaptor.cpp') diff --git a/app/app.pro b/app/app.pro index e08fa87..e0ff449 100644 --- a/app/app.pro +++ b/app/app.pro @@ -14,6 +14,8 @@ SOURCES += \ HEADERS += \ pebbledinterface.h +DBUS_INTERFACES += ../org.pebbled.Watch.xml + OTHER_FILES += \ qml/cover/CoverPage.qml \ qml/pages/ManagerPage.qml \ diff --git a/app/pebbledinterface.cpp b/app/pebbledinterface.cpp index 8759863..fb937f2 100644 --- a/app/pebbledinterface.cpp +++ b/app/pebbledinterface.cpp @@ -1,37 +1,33 @@ #include "pebbledinterface.h" +#include "watch_interface.h" -QString PebbledInterface::PEBBLED_SYSTEMD_UNIT("pebbled.service"); -QString PebbledInterface::PEBBLED_DBUS_SERVICE("org.pebbled"); -QString PebbledInterface::PEBBLED_DBUS_PATH("/org/pebbled"); -QString PebbledInterface::PEBBLED_DBUS_IFACE("org.pebbled"); - -#define PebbledDbusInterface QDBusInterface(PEBBLED_DBUS_SERVICE, PEBBLED_DBUS_PATH, PEBBLED_DBUS_IFACE) - +static const QString PEBBLED_SYSTEMD_UNIT("pebbled.service"); +static const QString PEBBLED_DBUS_SERVICE("org.pebbled"); +static const QString PEBBLED_DBUS_PATH("/org/pebbled/watch"); +static const QString PEBBLED_DBUS_IFACE("org.pebbled.Watch"); PebbledInterface::PebbledInterface(QObject *parent) : - QObject(parent), systemd(0) -{ - QDBusConnection::sessionBus().connect( - PEBBLED_DBUS_SERVICE, PEBBLED_DBUS_PATH, PEBBLED_DBUS_IFACE, - "connectedChanged", this, SIGNAL(connectedChanged())); - - QDBusConnection::sessionBus().connect( - PEBBLED_DBUS_SERVICE, PEBBLED_DBUS_PATH, PEBBLED_DBUS_IFACE, - "pebbleChanged", this, SLOT(onPebbleChanged())); - - QDBusConnection::sessionBus().connect( - PEBBLED_DBUS_SERVICE, PEBBLED_DBUS_PATH, PEBBLED_DBUS_IFACE, - "openUrl", this, SIGNAL(openUrl(QString))); + QObject(parent), + systemd(new QDBusInterface("org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + QDBusConnection::sessionBus(), this)), + watch(new OrgPebbledWatchInterface(PEBBLED_DBUS_SERVICE, + PEBBLED_DBUS_PATH, + QDBusConnection::sessionBus(), this)) +{ + connect(watch, &OrgPebbledWatchInterface::NameChanged, + this, &PebbledInterface::nameChanged); + connect(watch, &OrgPebbledWatchInterface::AddressChanged, + this, &PebbledInterface::addressChanged); + connect(watch, &OrgPebbledWatchInterface::ConnectedChanged, + this, &PebbledInterface::connectedChanged); // simulate connected change on active changed // as the daemon might not had a chance to send 'connectedChanged' // when going down - connect(this, SIGNAL(activeChanged()), SIGNAL(connectedChanged())); - - systemd = new QDBusInterface("org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - QDBusConnection::sessionBus(), this); + connect(this, &PebbledInterface::activeChanged, + this, &PebbledInterface::connectedChanged); systemd->call("Subscribe"); @@ -59,9 +55,9 @@ void PebbledInterface::getUnitProperties() QDBusReply reply = QDBusConnection::sessionBus().call(request); if (reply.isValid()) { QVariantMap newProperties = reply.value(); - bool emitEnabledChanged = (properties["UnitFileState"] != newProperties["UnitFileState"]); - bool emitActiveChanged = (properties["ActiveState"] != newProperties["ActiveState"]); - properties = newProperties; + bool emitEnabledChanged = (unitProperties["UnitFileState"] != newProperties["UnitFileState"]); + bool emitActiveChanged = (unitProperties["ActiveState"] != newProperties["ActiveState"]); + unitProperties = newProperties; if (emitEnabledChanged) emit enabledChanged(); if (emitActiveChanged) emit activeChanged(); } else { @@ -73,22 +69,14 @@ void PebbledInterface::onPropertiesChanged(QString interface, QMapconnected(); } QString PebbledInterface::name() const { qDebug() << __FUNCTION__; - return PebbledDbusInterface.property(__FUNCTION__).toString(); + return watch->name(); } QString PebbledInterface::address() const { qDebug() << __FUNCTION__; - return PebbledDbusInterface.property(__FUNCTION__).toString(); + return watch->address(); } void PebbledInterface::ping() { qDebug() << __FUNCTION__; - PebbledDbusInterface.call("ping", 66); + watch->Ping(66); } void PebbledInterface::time() { qDebug() << __FUNCTION__; - PebbledDbusInterface.call("time"); + watch->SyncTime(); } void PebbledInterface::disconnect() { qDebug() << __FUNCTION__; - PebbledDbusInterface.call("disconnect"); + watch->Disconnect(); } void PebbledInterface::reconnect() { qDebug() << __FUNCTION__; - PebbledDbusInterface.call("reconnect"); + watch->Reconnect(); } -void PebbledInterface::test() +QUrl PebbledInterface::configureApp(const QUuid &uuid) { - qDebug() << __FUNCTION__; - PebbledDbusInterface.call("test"); + qDebug() << __FUNCTION__ << uuid; + QString url = watch->StartAppConfiguration(uuid.toString()); + return QUrl(url); } -void PebbledInterface::webviewClosed(const QString &result) +void PebbledInterface::setAppConfiguration(const QUuid &uuid, const QString &data) { - qDebug() << __FUNCTION__; - PebbledDbusInterface.call("webviewClosed", QVariant::fromValue(result)); + watch->SendAppConfigurationData(uuid.toString(), data); } diff --git a/app/pebbledinterface.h b/app/pebbledinterface.h index 7d00110..78724ad 100644 --- a/app/pebbledinterface.h +++ b/app/pebbledinterface.h @@ -2,51 +2,36 @@ #define PEBBLEDINTERFACE_H #include -#include -#include +#include +#include + +class OrgPebbledWatchInterface; class PebbledInterface : public QObject { Q_OBJECT - - static QString PEBBLED_SYSTEMD_UNIT; - static QString PEBBLED_DBUS_SERVICE; - static QString PEBBLED_DBUS_PATH; - static QString PEBBLED_DBUS_IFACE; - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - bool enabled() const; - Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) - bool active() const; - Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) - bool connected() const; - - Q_PROPERTY(QVariantMap pebble READ pebble NOTIFY pebbleChanged) - QVariantMap pebble() const; - Q_PROPERTY(QString name READ name NOTIFY nameChanged) - QString name() const; - Q_PROPERTY(QString address READ address NOTIFY addressChanged) - QString address() const; - public: explicit PebbledInterface(QObject *parent = 0); + bool enabled() const; + bool active() const; + bool connected() const; + QString name() const; + QString address() const; + signals: void enabledChanged(); void activeChanged(); - void connectedChanged(); - void pebbleChanged(); void nameChanged(); void addressChanged(); - void openUrl(const QString &url); - public slots: void setEnabled(bool); void setActive(bool); @@ -54,19 +39,19 @@ public slots: void time(); void disconnect(); void reconnect(); - void test(); - void webviewClosed(const QString &result); + + QUrl configureApp(const QUuid &uuid); + void setAppConfiguration(const QUuid &uuid, const QString &data); private slots: void getUnitProperties(); void onPropertiesChanged(QString interface, QMap changed, QStringList invalidated); - void onPebbleChanged(); private: QDBusInterface *systemd; + OrgPebbledWatchInterface *watch; QDBusObjectPath unitPath; - - QVariantMap properties; + QVariantMap unitProperties; }; #endif // PEBBLEDINTERFACE_H diff --git a/daemon/daemon.pro b/daemon/daemon.pro index c59d408..3306541 100644 --- a/daemon/daemon.pro +++ b/daemon/daemon.pro @@ -20,7 +20,6 @@ SOURCES += \ notificationmanager.cpp \ watchconnector.cpp \ dbusconnector.cpp \ - dbusadaptor.cpp \ appmanager.cpp \ musicmanager.cpp \ datalogmanager.cpp \ @@ -38,7 +37,6 @@ HEADERS += \ notificationmanager.h \ watchconnector.h \ dbusconnector.h \ - dbusadaptor.h \ settings.h \ appmanager.h \ musicmanager.h \ @@ -51,10 +49,11 @@ HEADERS += \ packer.h OTHER_FILES += \ - org.pebbled.xml \ ../log4qt-debug.conf \ ../log4qt-release.conf +DBUS_ADAPTORS += ../org.pebbled.Watch.xml + INSTALLS += target pebbled confile target.path = /usr/bin diff --git a/daemon/dbusadaptor.cpp b/daemon/dbusadaptor.cpp deleted file mode 100644 index 25e2508..0000000 --- a/daemon/dbusadaptor.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp -a dbusadaptor org.pebbled.xml - * - * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * Do not edit! All changes made to it will be lost. - */ - -#include "dbusadaptor.h" -#include -#include -#include -#include -#include -#include -#include - -/* - * Implementation of adaptor class PebbledAdaptor - */ - -PebbledAdaptor::PebbledAdaptor(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ - // constructor - setAutoRelaySignals(true); -} - -PebbledAdaptor::~PebbledAdaptor() -{ - // destructor -} - -QString PebbledAdaptor::address() const -{ - // get the value of property address - return qvariant_cast< QString >(parent()->property("address")); -} - -bool PebbledAdaptor::connected() const -{ - // get the value of property connected - return qvariant_cast< bool >(parent()->property("connected")); -} - -QString PebbledAdaptor::name() const -{ - // get the value of property name - return qvariant_cast< QString >(parent()->property("name")); -} - -QVariantMap PebbledAdaptor::pebble() const -{ - // get the value of property pebble - return qvariant_cast< QVariantMap >(parent()->property("pebble")); -} - -void PebbledAdaptor::disconnect() -{ - // handle method call org.pebbled.disconnect - QMetaObject::invokeMethod(parent(), "disconnect"); -} - -void PebbledAdaptor::ping(int val) -{ - // handle method call org.pebbled.ping - QMetaObject::invokeMethod(parent(), "ping", Q_ARG(int, val)); -} - -void PebbledAdaptor::time() -{ - // handle method call org.pebbled.time - QMetaObject::invokeMethod(parent(), "time"); -} - -void PebbledAdaptor::reconnect() -{ - // handle method call org.pebbled.reconnect - QMetaObject::invokeMethod(parent(), "reconnect"); -} - -void PebbledAdaptor::test() -{ - QMetaObject::invokeMethod(parent(), "test"); -} - -void PebbledAdaptor::webviewClosed(const QString &result) -{ - QMetaObject::invokeMethod(parent(), "webviewClosed", Q_ARG(QString, result)); -} diff --git a/daemon/dbusadaptor.h b/daemon/dbusadaptor.h deleted file mode 100644 index f347f92..0000000 --- a/daemon/dbusadaptor.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp -a dbusadaptor org.pebbled.xml - * - * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * This file may have been hand-edited. Look for HAND-EDIT comments - * before re-generating it. - */ - -#ifndef DBUSADAPTOR_H_1404986135 -#define DBUSADAPTOR_H_1404986135 - -#include -#include -QT_BEGIN_NAMESPACE -class QByteArray; -template class QList; -template class QMap; -class QString; -class QStringList; -class QVariant; -QT_END_NAMESPACE - -/* - * Adaptor class for interface org.pebbled - */ -class PebbledAdaptor: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.pebbled") - Q_CLASSINFO("D-Bus Introspection", "" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" - "") -public: - PebbledAdaptor(QObject *parent); - virtual ~PebbledAdaptor(); - -public: // PROPERTIES - Q_PROPERTY(QString address READ address) - QString address() const; - - Q_PROPERTY(bool connected READ connected) - bool connected() const; - - Q_PROPERTY(QString name READ name) - QString name() const; - - Q_PROPERTY(QVariantMap pebble READ pebble) - QVariantMap pebble() const; - -public Q_SLOTS: // METHODS - void disconnect(); - void ping(int val); - void time(); - void reconnect(); - void test(); - void webviewClosed(const QString &result); -Q_SIGNALS: // SIGNALS - void connectedChanged(); - void pebbleChanged(); - void openUrl(const QString &s); -}; - -#endif diff --git a/daemon/dbusconnector.h b/daemon/dbusconnector.h index e6dd793..d4c1bcb 100644 --- a/daemon/dbusconnector.h +++ b/daemon/dbusconnector.h @@ -20,8 +20,8 @@ class DBusConnector : public QObject public: explicit DBusConnector(QObject *parent = 0); - QVariantMap pebble() { return pebbleProps; } - QStringList services() { return dbusServices; } + QVariantMap pebble() const { return pebbleProps; } + QStringList services() const { return dbusServices; } signals: void pebbleChanged(); diff --git a/daemon/manager.cpp b/daemon/manager.cpp index e732d38..38b3948 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -3,10 +3,11 @@ #include #include "manager.h" -#include "dbusadaptor.h" +#include "watch_adaptor.h" Manager::Manager(Settings *settings, QObject *parent) : QObject(parent), settings(settings), + proxy(new PebbledProxy(this)), watch(new WatchConnector(this)), dbus(new DBusConnector(this)), apps(new AppManager(this)), @@ -54,14 +55,16 @@ Manager::Manager(Settings *settings, QObject *parent) : connect(notifications, SIGNAL(twitterNotify(const QString &,const QString &)), SLOT(onTwitterNotify(const QString &,const QString &))); connect(notifications, SIGNAL(facebookNotify(const QString &,const QString &)), SLOT(onFacebookNotify(const QString &,const QString &))); - PebbledProxy *proxy = new PebbledProxy(this); - PebbledAdaptor *adaptor = new PebbledAdaptor(proxy); + connect(appmsg, &AppMsgManager::messageReceived, this, &Manager::onAppMessage); + QDBusConnection session = QDBusConnection::sessionBus(); - session.registerObject("/org/pebbled", proxy); + new WatchAdaptor(proxy); + session.registerObject("/org/pebbled/watch", proxy); session.registerService("org.pebbled"); - connect(dbus, SIGNAL(pebbleChanged()), adaptor, SIGNAL(pebbleChanged())); - connect(watch, SIGNAL(connectedChanged()), adaptor, SIGNAL(connectedChanged())); - connect(js, SIGNAL(appOpenUrl(QString)), adaptor, SIGNAL(openUrl(QString))); + + connect(dbus, &DBusConnector::pebbleChanged, proxy, &PebbledProxy::NameChanged); + connect(dbus, &DBusConnector::pebbleChanged, proxy, &PebbledProxy::AddressChanged); + connect(watch, &WatchConnector::connectedChanged, proxy, &PebbledProxy::ConnectedChanged); QString currentProfile = getCurrentProfile(); defaultProfile = currentProfile.isEmpty() ? "ambience" : currentProfile; @@ -289,7 +292,7 @@ void Manager::onMprisPropertiesChanged(QString interface, QMap logger()->debug() << "lastSeenMpris:" << lastSeenMpris; } -QString Manager::mpris() +QString Manager::mpris() const { const QStringList &services = dbus->services(); if (not lastSeenMpris.isEmpty() && services.contains(lastSeenMpris)) @@ -316,7 +319,7 @@ void Manager::setMprisMetadata(QVariantMap metadata) emit mprisMetadataChanged(mprisMetadata); } -QString Manager::getCurrentProfile() +QString Manager::getCurrentProfile() const { QDBusReply profile = QDBusConnection::sessionBus().call( QDBusMessage::createMethodCall("com.nokia.profiled", "/com/nokia/profiled", "com.nokia.profiled", "get_profile")); @@ -386,12 +389,6 @@ void Manager::transliterateMessage(const QString &text) } } -bool Manager::uploadApp(const QUuid &uuid, int slot) -{ - // TODO - return false; -} - void Manager::test() { logger()->debug() << "Starting test"; @@ -399,6 +396,11 @@ void Manager::test() js->showConfiguration(); } +void Manager::onAppMessage(const QUuid &uuid, const QVariantMap &data) +{ + emit proxy->AppMessage(uuid.toString(), data); +} + void Manager::onWebviewClosed(const QString &result) { js->handleWebviewClosed(result); diff --git a/daemon/manager.h b/daemon/manager.h index b0e15fb..c12d3dc 100644 --- a/daemon/manager.h +++ b/daemon/manager.h @@ -24,9 +24,9 @@ using namespace QtContacts; -class Manager : - public QObject, - protected QDBusContext +class PebbledProxy; + +class Manager : public QObject, protected QDBusContext { Q_OBJECT LOG4QT_DECLARE_QCLASS_LOGGER @@ -40,6 +40,8 @@ class Manager : Settings *settings; + PebbledProxy *proxy; + WatchConnector *watch; DBusConnector *dbus; AppManager *apps; @@ -58,6 +60,7 @@ class Manager : QString defaultProfile; QString lastSeenMpris; + QVariantMap mprisMetadata; QScopedPointer transliterator; @@ -65,13 +68,11 @@ public: explicit Manager(Settings *settings, QObject *parent = 0); ~Manager(); - Q_INVOKABLE QString findPersonByNumber(QString number); - Q_INVOKABLE QString getCurrentProfile(); - Q_INVOKABLE QString mpris(); - QVariantMap mprisMetadata; - QVariantMap getMprisMetadata() { return mprisMetadata; } + QString findPersonByNumber(QString number); + QString getCurrentProfile() const; + QString mpris() const; - Q_INVOKABLE bool uploadApp(const QUuid &uuid, int slot = -1); + inline QVariantMap getMprisMetadata() const { return mprisMetadata; } protected: void transliterateMessage(const QString &text); @@ -100,31 +101,71 @@ private slots: void onMprisPropertiesChanged(QString,QMap,QStringList); void setMprisMetadata(QDBusArgument metadata); void setMprisMetadata(QVariantMap metadata); + + void onAppMessage(const QUuid &uuid, const QVariantMap &data); }; -class PebbledProxy : public QObject +/** This class is what's actually exported over D-Bus, + * so the names of the slots and properties must match with org.pebbled.Watch D-Bus interface. + * Case sensitive. Otherwise, _runtime_ failures will occur. */ +// The methods are marked inline so that they may be inlined inside qt_metacall +class PebbledProxy : public QObject, protected QDBusContext { Q_OBJECT - Q_PROPERTY(QVariantMap pebble READ pebble) - Q_PROPERTY(QString name READ pebbleName) - Q_PROPERTY(QString address READ pebbleAddress) - Q_PROPERTY(bool connected READ pebbleConnected) + Q_PROPERTY(QString Name READ Name NOTIFY NameChanged) + Q_PROPERTY(QString Address READ Address NOTIFY AddressChanged) + Q_PROPERTY(bool Connected READ Connected NOTIFY ConnectedChanged) - QVariantMap pebble() { return static_cast(parent())->dbus->pebble(); } - QString pebbleName() { return static_cast(parent())->dbus->pebble()["Name"].toString(); } - QString pebbleAddress() { return static_cast(parent())->dbus->pebble()["Address"].toString(); } - bool pebbleConnected() { return static_cast(parent())->watch->isConnected(); } + inline Manager* manager() const { return static_cast(parent()); } + inline QVariantMap pebble() const { return manager()->dbus->pebble(); } public: - explicit PebbledProxy(QObject *parent) : QObject(parent) {} + inline explicit PebbledProxy(QObject *parent) : QObject(parent) {} + + inline QString Name() const { return pebble()["Name"].toString(); } + inline QString Address() const { return pebble()["Address"].toString(); } + inline bool Connected() const { return manager()->watch->isConnected(); } public slots: - void ping(int val) { static_cast(parent())->watch->ping((unsigned int)val); } - void time() { static_cast(parent())->watch->time(); } - void disconnect() { static_cast(parent())->watch->disconnect(); } - void reconnect() { static_cast(parent())->watch->reconnect(); } - void test() { static_cast(parent())->test(); } - void webviewClosed(const QString &result) { static_cast(parent())->onWebviewClosed(result); } + inline void Disconnected() { manager()->watch->disconnect(); } + inline void Reconnect() { manager()->watch->reconnect(); } + inline void Ping(uint val) { manager()->watch->ping(val); } + inline void SyncTime() { manager()->watch->time(); } + + inline void LaunchApp(const QString &uuid) { /* TODO */ } + inline void CloseApp(const QString &uuid) { /* TODO */ } + + bool SendAppMessage(const QString &uuid, const QVariantMap &data) { + Q_ASSERT(calledFromDBus()); + const QDBusMessage msg = message(); + setDelayedReply(true); + manager()->appmsg->send(uuid, data, [this, msg]() { + QDBusMessage reply = msg.createReply(QVariant::fromValue(true)); + this->connection().send(reply); + }, [this, msg]() { + QDBusMessage reply = msg.createReply(QVariant::fromValue(false)); + this->connection().send(reply); + }); + return false; // D-Bus clients should never see this reply. + } + + QString StartAppConfiguration(const QString &uuid) { + Q_ASSERT(calledFromDBus()); + const QDBusMessage msg = message(); + setDelayedReply(true); + + // TODO + } + + inline void SendAppConfiguration(const QString &uuid, const QString &data) { + // TODO + } + +signals: + void NameChanged(); + void AddressChanged(); + void ConnectedChanged(); + void AppMessage(const QString &uuid, const QVariantMap &data); }; #endif // MANAGER_H diff --git a/daemon/org.pebbled.xml b/daemon/org.pebbled.xml deleted file mode 100644 index e255782..0000000 --- a/daemon/org.pebbled.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/org.pebbled.Watch.xml b/org.pebbled.Watch.xml new file mode 100644 index 0000000..72aab6b --- /dev/null +++ b/org.pebbled.Watch.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3