summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2014-12-02 23:33:19 +0100
committerJavier <dev.git@javispedro.com>2014-12-02 23:33:19 +0100
commitc35a3a9bea759cadf1e975a2a62e50789cad096c (patch)
tree0e8b48fdb8bf07226b18a87f312631debbf41383 /app
parent81f91639969de0f3852a3fe73db13b4cb0ecf3b4 (diff)
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
Diffstat (limited to 'app')
-rw-r--r--app/app.pro2
-rw-r--r--app/pebbledinterface.cpp100
-rw-r--r--app/pebbledinterface.h45
3 files changed, 58 insertions, 89 deletions
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<QVariantMap> 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, QMap<QString,QVari
{
qDebug() << __FUNCTION__ << interface << changed << invalidated;
if (interface != "org.freedesktop.systemd1.Unit") return;
- if (invalidated.contains("UnitFileState") or invalidated.contains("ActiveState"))
+ if (invalidated.contains("UnitFileState") || invalidated.contains("ActiveState"))
getUnitProperties();
}
-void PebbledInterface::onPebbleChanged()
-{
- qDebug() << __FUNCTION__;
- emit nameChanged();
- emit addressChanged();
- emit pebbleChanged();
-}
-
bool PebbledInterface::enabled() const
{
qDebug() << __FUNCTION__;
- return properties["UnitFileState"].toString() == "enabled";
+ return unitProperties["UnitFileState"].toString() == "enabled";
}
void PebbledInterface::setEnabled(bool enabled)
@@ -108,7 +96,7 @@ void PebbledInterface::setEnabled(bool enabled)
bool PebbledInterface::active() const
{
qDebug() << __FUNCTION__;
- return properties["ActiveState"].toString() == "active";
+ return unitProperties["ActiveState"].toString() == "active";
}
void PebbledInterface::setActive(bool active)
@@ -123,59 +111,53 @@ void PebbledInterface::setActive(bool active)
bool PebbledInterface::connected() const
{
qDebug() << __FUNCTION__;
- return PebbledDbusInterface.property(__FUNCTION__).toBool();
-}
-
-QVariantMap PebbledInterface::pebble() const
-{
- qDebug() << __FUNCTION__;
- return PebbledDbusInterface.property(__FUNCTION__).toMap();
+ return watch->connected();
}
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 <QObject>
-#include <QtDBus/QtDBus>
-#include <QDBusArgument>
+#include <QUrl>
+#include <QDBusInterface>
+
+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<QString, QVariant> changed, QStringList invalidated);
- void onPebbleChanged();
private:
QDBusInterface *systemd;
+ OrgPebbledWatchInterface *watch;
QDBusObjectPath unitPath;
-
- QVariantMap properties;
+ QVariantMap unitProperties;
};
#endif // PEBBLEDINTERFACE_H