summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2013-05-24 16:55:58 +0200
committerRobert Griebl <robert.griebl@pelagicore.com>2016-04-14 13:46:16 +0000
commit631cbba46cf1d2c02eccf7c3960e6f934d0323f0 (patch)
tree31464d4c0605246cb1c6df39af23f04934dccc3e /src
parent169f9ceb6f020082cd36954753651fd2b31fc661 (diff)
Initial version of a QML DBus Plugin
Change-Id: I6382467d87e8597988fe8cbdb676b2f8ce234186 Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'src')
-rw-r--r--src/dbus.cpp127
-rw-r--r--src/dbus.h97
-rw-r--r--src/dbusinterface.cpp333
-rw-r--r--src/dbusinterface.h114
-rw-r--r--src/dbusplugin.cpp67
-rw-r--r--src/dbusplugin.h58
-rw-r--r--src/dbusplugin.json4
-rw-r--r--src/dbusreply.cpp147
-rw-r--r--src/dbusreply.h93
-rw-r--r--src/qdbusinterfacewrapper.cpp96
-rw-r--r--src/qdbusinterfacewrapper.h63
-rw-r--r--src/src.pro31
12 files changed, 1230 insertions, 0 deletions
diff --git a/src/dbus.cpp b/src/dbus.cpp
new file mode 100644
index 0000000..adff5a3
--- /dev/null
+++ b/src/dbus.cpp
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+#include "dbus.h"
+
+/*!
+ \qmltype DBus
+ \instantiates QuickDBus
+ \inmodule qmldbusplugin
+ \brief A QML representation of a Connection to specific DBus
+
+ The DBus object should only be used if you want to connect to
+ a specific non-standard Bus.
+
+ For the most usecases SessionBus and SystemBus are the suitable
+ Elements
+
+ \sa SessionBus, SystemBus
+*/
+
+
+/*!
+ \qmltype SessionBus
+ \instantiates QuickSessionBus
+ \inmodule qmldbusplugin
+ \brief A QML representation of a Connection to the SessionBus
+
+ This Bus should be used for all services you want to call on
+ the SessionBus
+
+ \sa SystemBus, DBus
+*/
+
+/*!
+ \qmltype SystemBus
+ \instantiates QuickSystemBus
+ \inmodule qmldbusplugin
+ \brief A QML representation of a Connection to the SystemBus
+
+ This Bus should be used for all services you want to call on
+ the SystemBus
+
+ \sa SessionBus, DBus
+*/
+
+/*!
+ \qmlproperty string DBus::address
+
+ The address where this DBus runs on
+*/
+
+QuickDBus::QuickDBus(QObject *parent)
+ : QObject(parent)
+ , m_connection(QDBusConnection("tmpDummy"))
+{
+}
+
+QuickDBus::QuickDBus(const QDBusConnection &connection, QObject *parent)
+ : QObject(parent)
+ , m_connection(connection)
+{
+}
+
+QuickDBus::~QuickDBus()
+{
+}
+
+QString QuickDBus::address() const
+{
+ return m_address;
+}
+
+QDBusConnection QuickDBus::connection() const
+{
+ return m_connection;
+}
+
+void QuickDBus::setAddress(const QString &address)
+{
+ if (m_address != address) {
+ m_address = address;
+
+ if (m_connection.isConnected())
+ m_connection.disconnectFromBus(m_connection.name());
+
+ m_connection = QDBusConnection::connectToBus(m_address, m_address);
+
+ emit addressChanged(address);
+ }
+}
diff --git a/src/dbus.h b/src/dbus.h
new file mode 100644
index 0000000..7a28043
--- /dev/null
+++ b/src/dbus.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+#ifndef DBUS_H
+#define DBUS_H
+
+#include <QObject>
+#include <QDBusConnection>
+
+//class QDBusConnection;
+
+class QuickDBus : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QuickDBus(QObject *parent = 0);
+ explicit QuickDBus(const QDBusConnection &connection, QObject *parent = 0);
+ virtual ~QuickDBus();
+
+ Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
+
+ QString address() const;
+
+ QDBusConnection connection() const;
+
+signals:
+ void addressChanged(const QString& address);
+ void connectionChanged(const QDBusConnection &connection);
+
+public slots:
+
+ void setAddress(const QString& address);
+
+private:
+ QString m_address;
+ QDBusConnection m_connection;
+};
+
+class QuickSessionBus: public QuickDBus
+{
+ Q_OBJECT
+
+public:
+ QuickSessionBus(QObject *parent = 0) : QuickDBus(QDBusConnection::sessionBus(), parent){}
+
+ Q_PROPERTY(QString address READ address CONSTANT)
+};
+
+class QuickSystemBus: public QuickDBus
+{
+ Q_OBJECT
+
+public:
+ QuickSystemBus(QObject *parent = 0) : QuickDBus(QDBusConnection::systemBus(), parent){}
+
+ Q_PROPERTY(QString address READ address CONSTANT)
+};
+
+#endif // DBUS_H
diff --git a/src/dbusinterface.cpp b/src/dbusinterface.cpp
new file mode 100644
index 0000000..032b78d
--- /dev/null
+++ b/src/dbusinterface.cpp
@@ -0,0 +1,333 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+#include "dbusinterface.h"
+#include "dbus.h"
+#include "qdbusinterfacewrapper.h"
+
+#include <QtDBus/QDBusInterface>
+#include <QtDBus/QDBusReply>
+#include <QtDBus/QDBusError>
+#include <QMetaMethod>
+
+#include <QDebug>
+
+
+/*!
+ \qmltype DBusInterface
+ \instantiates QuickDBusInterface
+ \inmodule qmldbusplugin
+ \brief A QML representation of a DBus Interface
+
+ The DBusInterface can be used to interact with any service running
+ on a DBus.
+
+ Per Default the DBusInterface is not connected to any Bus and is
+ not ready to be used.
+
+ To be usable you have to set the following four properties:
+
+ \list
+ \li \l {bus}
+ \li \l {service}
+ \li \l {path}
+ \li \l {interfaceName}
+ \endlist
+
+
+ In the following example we connect to a Interface and make a call to
+ that Interface:
+
+ \code
+ DBusInterface {
+ id: dbusInterface
+
+ interfaceName: "org.kde.KMix.Control"
+ service: "org.kde.kded"
+ path: "/Mixers/0/alsa_output_usb_Logitech_Logitech_USB_Headset_00_Headset_analog_stereo"
+
+ bus: SessionBus {}
+
+ Component.onCompleted: {
+ if (dbusInterface.interfaceObject) {
+ dbusInterface.interfaceObject.toggleMute()
+ }
+ }
+ }
+ \endcode
+
+
+ For calling the method the interfaceObject property is used. This property can also be used to
+ read DBus Properties or connect to DBus signals:
+
+ \code
+ DBusInterface {
+ id: dbusInterface
+
+ interfaceName: "com.pelagicore.test"
+ service: "com.pelagicore.test"
+ path: "/"
+
+ bus: SessionBus {}
+ }
+
+ Rectangle {
+ id: rect
+ width: dbusInterface.interfaceObject.width
+ height: dbusInterface.interfaceObject.height
+ }
+
+ //Connecting to a DBus signal
+ Connections {
+ ignoreUnknownSignals: true
+ target: dbusInterface.interfaceObject
+ onWidthChanged: {
+ print("muteChanged")
+ }
+ }
+ \endcode
+
+ The Rectangle with the id rect uses the width and height property of the DBus interface. When the
+ DBus interface changes the properties the Rectangle will also be resized.
+*/
+
+
+QuickDBusInterface::QuickDBusInterface(QObject *parent)
+ : QObject(parent)
+ , m_bus(0)
+ , m_dbusInterface(0)
+{
+}
+
+/*! \qmlproperty string DBusInterface::service
+ *
+ * The DBus Service you want to connect to
+ */
+QString QuickDBusInterface::service() const
+{
+ return m_service;
+}
+
+/*! \qmlproperty string DBusInterface::path
+ *
+ * The DBus Path you want to connect to
+ */
+QString QuickDBusInterface::path() const
+{
+ return m_path;
+}
+
+/*! \qmlproperty string DBusInterface::interfaceName
+ *
+ * The DBus interface you want to connect to
+ */
+QString QuickDBusInterface::interfaceName() const
+{
+ return m_interface;
+}
+
+/*! \qmlproperty bool DBusInterface::ready
+ *
+ * Returns true when the DBusInterface is ready to be used
+ */
+bool QuickDBusInterface::isReady() const
+{
+ return m_ready;
+}
+
+/*! \qmlproperty DBus DBusInterface::bus
+ *
+ * The D-Bus which should to used for the connection
+ *
+ * \sa DBus, SessionBus, SystemBus
+ */
+QuickDBus *QuickDBusInterface::bus() const
+{
+ return m_bus;
+}
+
+/*! \qmlmethod bool DBusReply QuickDBusInterface::call(string name, variant arg1, variant arg2,
+ variant arg3, variant arg4, variant arg5,
+ variant arg6, variant arg7, variant arg8)
+
+ Calls the function with the Name \a name on the DBus Interface and uses the arg1 - arg8
+ as arguments for this call.
+
+ The return value is a DBusReply which contains the value or an errorName and errorString
+ if the call was not successful.
+
+ This method can be used to call functions on Interfaces which you doesn't know at the time
+ of writing and instead used the DBus introspection.
+
+ The following example calls a function using this function and prints the return value
+
+ \code
+ DBusInterface {
+ id: dbusInterface
+
+ interfaceName: "org.kde.KMix.Control"
+ service: "org.kde.kded"
+ path: "/Mixers/0/alsa_output_usb_Logitech_Logitech_USB_Headset_00_Headset_analog_stereo"
+
+ bus: SessionBus {}
+
+ Component.onCompleted: {
+ //Call DBus method using a generic function
+ //With this you could also use functions you got using the DBus Introspection
+ var id= dbusInterface.call("getClipboardHistoryItem", 1)
+
+ print(id)
+ print(id.valid)
+ print(id.errorString)
+ print(id.values)
+ }
+ }
+ \endcode
+ */
+
+
+QuickDBusReply* QuickDBusInterface::call(const QString &name, const QVariant &arg1, const QVariant &arg2,
+ const QVariant &arg3, const QVariant &arg4, const QVariant &arg5,
+ const QVariant &arg6, const QVariant &arg7, const QVariant &arg8) const
+{
+ if (!m_dbusInterface)
+ return new QuickDBusReply(false, QList<QVariant>(), "No Interface", "The Interface is not initialized");
+
+ if (!m_bus)
+ return new QuickDBusReply(false, QList<QVariant>(), "No Bus", "The Bus is not initialized");
+
+ QDBusMessage reply = m_dbusInterface->call(name, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+
+ if (reply.type() == QDBusMessage::ReplyMessage)
+ return new QuickDBusReply(true, reply.arguments());
+ else
+ return new QuickDBusReply(false, QList<QVariant>(), reply.errorName(), reply.errorMessage());
+}
+
+QuickDBusReply *QuickDBusInterface::asyncCall(const QString &name, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8) const
+{
+ if (!m_dbusInterface)
+ return new QuickDBusReply(false, QList<QVariant>(), "No Interface", "The Interface is not initialized");
+
+ if (!m_bus)
+ return new QuickDBusReply(false, QList<QVariant>(), "No Bus", "The Bus is not initialized");
+
+ QDBusPendingCall pcall = m_dbusInterface->asyncCall(name, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+
+ return new QuickDBusReply(pcall);
+}
+
+QObject *QuickDBusInterface::interfaceObject()
+{
+ return m_dbusInterface;
+}
+
+void QuickDBusInterface::setService(const QString &arg)
+{
+ if (m_service != arg) {
+ m_service = arg;
+ emit serviceChanged(arg);
+ createDBusInterface();
+ }
+}
+void QuickDBusInterface::setPath(const QString &arg)
+{
+ if (m_path != arg) {
+ m_path = arg;
+ emit pathChanged(arg);
+ createDBusInterface();
+ }
+}
+void QuickDBusInterface::setInterfaceName(const QString &arg)
+{
+ if (m_interface != arg) {
+ m_interface = arg;
+ emit interfaceNameChanged(arg);
+ createDBusInterface();
+ }
+}
+
+void QuickDBusInterface::setBus(QuickDBus *bus)
+{
+ if (m_bus != bus) {
+
+ if (m_bus) {
+ disconnect(m_bus);
+ }
+
+ m_bus = bus;
+ emit busChanged(bus);
+ createDBusInterface();
+ }
+}
+
+void QuickDBusInterface::createDBusInterface()
+{
+ setReady(false);
+
+ if (m_dbusInterface) {
+ delete m_dbusInterface;
+ m_dbusInterface = 0;
+ emit interfaceObjectChanged(0);
+ }
+
+ if (!m_bus)
+ return;
+
+ if (m_service.isEmpty() || m_interface.isEmpty() || m_path.isEmpty())
+ return;
+
+ connect(m_bus, SIGNAL(connectionChanged(QDBusConnection)), this, SLOT(createDBusInterface()));
+ m_dbusInterface = new QDBusInterfaceWrapper(m_service, m_path, m_interface, m_bus->connection());
+ emit interfaceObjectChanged(m_dbusInterface);
+
+ if (!m_dbusInterface->isValid())
+ qWarning() << m_dbusInterface->lastError().message();
+
+ setReady(m_dbusInterface->isValid());
+}
+
+void QuickDBusInterface::setReady(bool ready)
+{
+ if (m_ready != ready) {
+ m_ready = ready;
+ emit readyChanged(ready);
+ }
+}
diff --git a/src/dbusinterface.h b/src/dbusinterface.h
new file mode 100644
index 0000000..25695ff
--- /dev/null
+++ b/src/dbusinterface.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+#ifndef DBUSINTERFACE_H
+#define DBUSINTERFACE_H
+
+#include <QObject>
+#include <dbusreply.h>
+
+class QDBusInterface;
+class QDBusInterfaceWrapper;
+class QuickDBus;
+
+class QuickDBusInterface : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit QuickDBusInterface(QObject *parent = 0);
+
+ Q_PROPERTY(QString service READ service WRITE setService NOTIFY serviceChanged)
+ Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
+ Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
+ Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged)
+ Q_PROPERTY(QObject* interfaceObject READ interfaceObject() NOTIFY interfaceObjectChanged)
+ Q_PROPERTY(QuickDBus* bus READ bus WRITE setBus NOTIFY busChanged)
+
+ QString service() const;
+ QString path() const;
+ QString interfaceName() const;
+ bool isReady() const;
+ QuickDBus* bus() const;
+
+ Q_INVOKABLE QuickDBusReply* call(const QString &name, const QVariant & arg1 = QVariant(), const QVariant & arg2 = QVariant(),
+ const QVariant & arg3 = QVariant(), const QVariant & arg4 = QVariant(),
+ const QVariant & arg5 = QVariant(), const QVariant & arg6 = QVariant(),
+ const QVariant & arg7 = QVariant(), const QVariant & arg8 = QVariant()) const;
+
+ Q_INVOKABLE QuickDBusReply* asyncCall(const QString &name, const QVariant & arg1 = QVariant(), const QVariant & arg2 = QVariant(),
+ const QVariant & arg3 = QVariant(), const QVariant & arg4 = QVariant(),
+ const QVariant & arg5 = QVariant(), const QVariant & arg6 = QVariant(),
+ const QVariant & arg7 = QVariant(), const QVariant & arg8 = QVariant()) const;
+
+ QObject *interfaceObject();
+
+ //TODO add lastError call
+
+signals:
+ void serviceChanged(const QString &arg);
+ void pathChanged(const QString &arg);
+ void interfaceNameChanged(const QString &arg);
+ void readyChanged(bool arg);
+ void interfaceObjectChanged(QObject* arg);
+ void busChanged(QuickDBus *bus);
+
+public slots:
+ void setService(const QString &arg);
+ void setPath(const QString &arg);
+ void setInterfaceName(const QString &arg);
+ void setBus(QuickDBus* bus);
+
+private slots:
+ void createDBusInterface();
+ void setReady(bool ready);
+
+private:
+ QString m_service;
+ QString m_path;
+ QString m_interface;
+ bool m_ready;
+ QuickDBus* m_bus;
+
+ QDBusInterfaceWrapper* m_dbusInterface;
+};
+
+#endif // DBUSINTERFACE_H
diff --git a/src/dbusplugin.cpp b/src/dbusplugin.cpp
new file mode 100644
index 0000000..b92ff90
--- /dev/null
+++ b/src/dbusplugin.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+#include "dbusplugin.h"
+
+#include <QtQml>
+#include <QQmlContext>
+#include <dbusreply.h>
+#include <dbusinterface.h>
+#include <dbus.h>
+
+void DBusPlugin::registerTypes(const char *uri)
+{
+ Q_UNUSED(uri);
+
+ qmlRegisterType<QuickDBusInterface>("com.pelagicore.dbus", 1, 0, "DBusInterface");
+ qmlRegisterType<QuickDBus>("com.pelagicore.dbus", 1, 0, "DBus");
+ qmlRegisterType<QuickSessionBus>("com.pelagicore.dbus", 1, 0, "SessionBus");
+ qmlRegisterType<QuickSystemBus>("com.pelagicore.dbus", 1, 0, "SystemBus");
+ qmlRegisterUncreatableType<QuickDBusReply>("com.pelagicore.dbus", 1, 0, "DBusReply", "Only accessible using DBusInterface");
+}
+
+void DBusPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
+{
+ Q_UNUSED(uri);
+ Q_UNUSED(engine);
+}
+
+
+
diff --git a/src/dbusplugin.h b/src/dbusplugin.h
new file mode 100644
index 0000000..1e8b7dd
--- /dev/null
+++ b/src/dbusplugin.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+#ifndef DBUSPLUGIN_H
+#define DBUSPLUGIN_H
+
+class QQmlEngine;
+
+#include <QQmlExtensionPlugin>
+
+class DBusPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "com.pelagicore.dbus" FILE "dbusplugin.json")
+
+public:
+ void registerTypes(const char *uri);
+ void initializeEngine(QQmlEngine *engine, const char *uri);
+};
+
+#endif // DBUSPLUGIN_H
diff --git a/src/dbusplugin.json b/src/dbusplugin.json
new file mode 100644
index 0000000..18f18b3
--- /dev/null
+++ b/src/dbusplugin.json
@@ -0,0 +1,4 @@
+{
+"keys": [ "dbus" ]
+}
+
diff --git a/src/dbusreply.cpp b/src/dbusreply.cpp
new file mode 100644
index 0000000..7ba1adc
--- /dev/null
+++ b/src/dbusreply.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+#include "dbusreply.h"
+#include <QDebug>
+
+QuickDBusReply::QuickDBusReply(bool isValid, QList<QVariant> values, QString errorName, QString errorString, QObject *parent)
+ : QObject(parent)
+ , m_valid(isValid)
+ , m_waiting(false)
+ , m_values(values)
+ , m_errorName(errorName)
+ , m_errorString(errorString)
+{
+}
+
+QuickDBusReply::QuickDBusReply(const QDBusPendingCall &pcall, QObject *parent)
+ : QObject(parent)
+ , m_valid(true)
+ , m_waiting(true)
+{
+ QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(pcall, this);
+
+ connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*)));
+}
+
+bool QuickDBusReply::isWaiting() const
+{
+ return m_waiting;
+}
+
+bool QuickDBusReply::isValid() const
+{
+ return m_valid;
+}
+
+QList<QVariant> QuickDBusReply::values() const
+{
+ return m_values;
+}
+
+QString QuickDBusReply::errorName() const
+{
+ return m_errorName;
+}
+
+QString QuickDBusReply::errorString() const
+{
+ return m_errorString;
+}
+
+void QuickDBusReply::callFinishedSlot(QDBusPendingCallWatcher *call)
+{
+ Q_ASSERT(call);
+
+ setWaiting(false);
+
+ QDBusMessage msg = call->reply();
+
+ if (msg.type() == QDBusMessage::ReplyMessage) {
+ setValues(msg.arguments());
+ } else {
+ setValid(false);
+ setErrorName(msg.errorName());
+ setErrorString(msg.errorMessage());
+ }
+
+ call->deleteLater();
+}
+
+
+void QuickDBusReply::setValid(bool arg)
+{
+ if (m_valid != arg) {
+ m_valid = arg;
+ emit validChanged();
+ }
+}
+
+void QuickDBusReply::setWaiting(bool arg)
+{
+ if (m_waiting != arg) {
+ m_waiting = arg;
+ emit waitingChanged();
+ }
+}
+
+void QuickDBusReply::setValues(const QList<QVariant> &values)
+{
+ if (m_values != values) {
+ m_values = values;
+ emit valuesChanged();
+ }
+}
+
+void QuickDBusReply::setErrorName(const QString &errorName)
+{
+ if (m_errorName != errorName) {
+ m_errorName = errorName;
+ emit errorNameChanged();
+ }
+}
+
+void QuickDBusReply::setErrorString(const QString &errorString)
+{
+ if (m_errorString != errorString) {
+ m_errorString = errorString;
+ emit errorStringChanged();
+ }
+}
diff --git a/src/dbusreply.h b/src/dbusreply.h
new file mode 100644
index 0000000..a377ea1
--- /dev/null
+++ b/src/dbusreply.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+#ifndef DBUSREPLY_H
+#define DBUSREPLY_H
+
+#include <QObject>
+#include <QVariant>
+#include <QDBusPendingCall>
+
+class QuickDBusReply : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit QuickDBusReply(bool isValid, QList<QVariant> values, QString errorName = QString(), QString errorString = QString(), QObject *parent = 0);
+ explicit QuickDBusReply(const QDBusPendingCall& pcall, QObject *parent = 0);
+
+ Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
+ Q_PROPERTY(bool waiting READ isWaiting NOTIFY waitingChanged)
+ Q_PROPERTY(QList<QVariant> values READ values NOTIFY valuesChanged)
+ Q_PROPERTY(QString errorName READ errorName NOTIFY errorNameChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
+
+ bool isWaiting() const;
+ bool isValid() const;
+ QList<QVariant> values() const;
+ QString errorName() const;
+ QString errorString() const;
+
+signals:
+ void validChanged();
+ void waitingChanged();
+ void valuesChanged();
+ void errorNameChanged();
+ void errorStringChanged();
+
+private slots:
+ void setValid(bool arg);
+ void setWaiting(bool arg);
+ void setValues(const QList<QVariant>& values);
+ void setErrorName(const QString& errorName);
+ void setErrorString(const QString& errorString);
+
+ void callFinishedSlot(QDBusPendingCallWatcher *call);
+
+private:
+ bool m_valid;
+ bool m_waiting;
+ QList<QVariant> m_values;
+ QString m_errorName;
+ QString m_errorString;
+};
+
+#endif // DBUSREPLY_H
diff --git a/src/qdbusinterfacewrapper.cpp b/src/qdbusinterfacewrapper.cpp
new file mode 100644
index 0000000..6f54993
--- /dev/null
+++ b/src/qdbusinterfacewrapper.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+#include "qdbusinterfacewrapper.h"
+#include <QDebug>
+#include <QMetaProperty>
+
+QDBusInterfaceWrapper::QDBusInterfaceWrapper(const QString &service, const QString &path, const QString &interface, const QDBusConnection &connection, QObject *parent) :
+ QDBusInterface(service, path, interface, connection, parent)
+{
+ QDBusInterface::connection().connect(service,
+ path,
+ "org.freedesktop.DBus.Properties",
+ "PropertiesChanged",
+ this,
+ SLOT(onPropertiesChanged(QString,QVariantMap,QStringList)));
+}
+
+int QDBusInterfaceWrapper::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
+{
+ if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty) {
+ QMetaProperty mp = metaObject()->property(_id);
+
+ QVariant var;
+ if (_c == QMetaObject::ReadProperty) {
+ var = QVariant(mp.type());
+ } else {
+ var = *reinterpret_cast<QVariant*>(_a[0]);
+ }
+
+ int status = -1;
+ void *args[] = { 0, &var, &status};
+
+ QDBusInterface::qt_metacall(_c, _id, args);
+
+ QVariant &returnValue = *reinterpret_cast<QVariant*>(_a[0]);
+ returnValue = var;
+
+ return status;
+ } else {
+ return QDBusInterface::qt_metacall(_c, _id, _a);
+ }
+}
+
+void QDBusInterfaceWrapper::onPropertiesChanged(const QString &interfaceName, const QVariantMap &changed_properties, const QStringList &invalidated_properties)
+{
+ if (interfaceName == interfaceName) {
+ foreach (const QString& key, changed_properties.keys()) {
+ int idx = metaObject()->indexOfProperty(qPrintable(key));
+ if (idx == -1)
+ continue;
+
+ QMetaProperty prop = metaObject()->property(idx);
+ QMetaMethod signal = prop.notifySignal();
+
+ signal.invoke(this);
+ }
+ }
+}
diff --git a/src/qdbusinterfacewrapper.h b/src/qdbusinterfacewrapper.h
new file mode 100644
index 0000000..5c41453
--- /dev/null
+++ b/src/qdbusinterfacewrapper.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the qmldpusplugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+#ifndef QDBUSINTERFACEWRAPPER_H
+#define QDBUSINTERFACEWRAPPER_H
+
+#include <QDBusInterface>
+
+class QDBusInterfaceWrapper : public QDBusInterface
+{
+public:
+ explicit QDBusInterfaceWrapper(const QString &service, const QString &path, const QString &interface = QString(),
+ const QDBusConnection &connection = QDBusConnection::sessionBus(),
+ QObject *parent = 0);
+
+ int qt_metacall(QMetaObject::Call _c, int _id, void **_a);
+
+private slots:
+
+ //FIX ME
+ void onPropertiesChanged(const QString& interfaceName,
+ const QVariantMap& changed_properties,
+ const QStringList& invalidated_properties);
+};
+
+#endif // QDBUSINTERFACEWRAPPER_H
diff --git a/src/src.pro b/src/src.pro
new file mode 100644
index 0000000..f665983
--- /dev/null
+++ b/src/src.pro
@@ -0,0 +1,31 @@
+TEMPLATE = lib
+TARGET = dbusplugin
+QT += quick dbus
+CONFIG += qt plugin
+
+DESTDIR = ../qml/com/pelagicore/dbus
+
+HEADERS += \
+ dbusplugin.h \
+ dbusinterface.h \
+ dbusreply.h \
+ qdbusinterfacewrapper.h \
+ dbus.h
+
+SOURCES += \
+ dbusplugin.cpp \
+ dbusinterface.cpp \
+ dbusreply.cpp \
+ qdbusinterfacewrapper.cpp \
+ dbus.cpp
+
+OTHER_FILES += \
+ ../qml/com/pelagicore/dbus/qmldir \
+ dbusplugin.json
+
+qmldir.files = ../qml/com/pelagicore/dbus/qmldir
+
+target.path = $$[QT_INSTALL_QML]/com/pelagicore/dbus
+qmldir.path = $$[QT_INSTALL_QML]/com/pelagicore/dbus
+
+INSTALLS+= qmldir target