telepathy-qt: Add BaseConnectionContactsInterface

David Edmundson davidedmundson at kemper.freedesktop.org
Sat Jun 14 04:57:35 PDT 2014


Module: telepathy-qt
Branch: master
Commit: 516e26cf2d4b3e13b58e2f6d0fbd6ed052b5d8d7
URL:    http://cgit.freedesktop.org/telepathy/telepathy-qt/commit/?id=516e26cf2d4b3e13b58e2f6d0fbd6ed052b5d8d7

Author: Matthias Gehre <M.Gehre at gmx.de>
Date:   Mon Mar 25 15:32:57 2013 -0500

Add BaseConnectionContactsInterface

---

 TelepathyQt/base-connection-internal.h |   17 +++++
 TelepathyQt/base-connection.cpp        |  107 ++++++++++++++++++++++++++++++++
 TelepathyQt/base-connection.h          |   40 ++++++++++++
 TelepathyQt/service-types.h            |    2 +
 4 files changed, 166 insertions(+)

diff --git a/TelepathyQt/base-connection-internal.h b/TelepathyQt/base-connection-internal.h
index 220e10a..3efb68f 100644
--- a/TelepathyQt/base-connection-internal.h
+++ b/TelepathyQt/base-connection-internal.h
@@ -118,4 +118,21 @@ public:
     BaseConnectionRequestsInterface *mInterface;
 };
 
+class TP_QT_NO_EXPORT BaseConnectionContactsInterface::Adaptee : public QObject
+{
+    Q_OBJECT
+
+    Q_PROPERTY(QStringList contactAttributeInterfaces READ contactAttributeInterfaces)
+public:
+    Adaptee(BaseConnectionContactsInterface *interface);
+    ~Adaptee();
+    QStringList contactAttributeInterfaces() const;
+
+private Q_SLOTS:
+    void getContactAttributes(const Tp::UIntList &handles, const QStringList &interfaces, bool hold,
+                              const Tp::Service::ConnectionInterfaceContactsAdaptor::GetContactAttributesContextPtr &context);
+public:
+    BaseConnectionContactsInterface *mInterface;
+};
+
 }
diff --git a/TelepathyQt/base-connection.cpp b/TelepathyQt/base-connection.cpp
index d65ba3d..cdc856a 100644
--- a/TelepathyQt/base-connection.cpp
+++ b/TelepathyQt/base-connection.cpp
@@ -770,4 +770,111 @@ void BaseConnectionRequestsInterface::createChannel(const QVariantMap &request,
     details = channel->details().properties;
 }
 
+
+// Conn.I.Contacts
+BaseConnectionContactsInterface::Adaptee::Adaptee(BaseConnectionContactsInterface *interface)
+    : QObject(interface),
+      mInterface(interface)
+{
+}
+
+BaseConnectionContactsInterface::Adaptee::~Adaptee()
+{
+}
+
+void BaseConnectionContactsInterface::Adaptee::getContactAttributes(const Tp::UIntList &handles,
+        const QStringList &interfaces, bool /*hold*/,
+        const Tp::Service::ConnectionInterfaceContactsAdaptor::GetContactAttributesContextPtr &context)
+{
+    DBusError error;
+    ContactAttributesMap contactAttributes = mInterface->getContactAttributes(handles, interfaces, &error);
+    if (error.isValid()) {
+        context->setFinishedWithError(error.name(), error.message());
+        return;
+    }
+    context->setFinished(contactAttributes);
+}
+
+struct TP_QT_NO_EXPORT BaseConnectionContactsInterface::Private {
+    Private(BaseConnectionContactsInterface *parent)
+        : adaptee(new BaseConnectionContactsInterface::Adaptee(parent)) {
+    }
+    QStringList contactAttributeInterfaces;
+    GetContactAttributesCallback getContactAttributesCallback;
+    BaseConnectionContactsInterface::Adaptee *adaptee;
+};
+
+QStringList BaseConnectionContactsInterface::Adaptee::contactAttributeInterfaces() const
+{
+    return mInterface->mPriv->contactAttributeInterfaces;
+}
+
+/**
+ * \class BaseConnectionContactsInterface
+ * \ingroup servicecm
+ * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection>
+ *
+ * \brief Base class for implementations of Connection.Interface.Contacts
+ */
+
+/**
+ * Class constructor.
+ */
+BaseConnectionContactsInterface::BaseConnectionContactsInterface()
+    : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_INTERFACE_CONTACTS),
+      mPriv(new Private(this))
+{
+}
+
+/**
+ * Class destructor.
+ */
+BaseConnectionContactsInterface::~BaseConnectionContactsInterface()
+{
+    delete mPriv;
+}
+
+/**
+ * Return the immutable properties of this<interface.
+ *
+ * Immutable properties cannot change after the interface has been registered
+ * on a service on the bus with registerInterface().
+ *
+ * \return The immutable properties of this interface.
+ */
+QVariantMap BaseConnectionContactsInterface::immutableProperties() const
+{
+    QVariantMap map;
+    map.insert(TP_QT_IFACE_CONNECTION_INTERFACE_CONTACTS + QLatin1String(".ContactAttributeInterfaces"),
+               QVariant::fromValue(mPriv->adaptee->contactAttributeInterfaces()));
+    return map;
+}
+
+void BaseConnectionContactsInterface::createAdaptor()
+{
+    (void) new Service::ConnectionInterfaceContactsAdaptor(dbusObject()->dbusConnection(),
+            mPriv->adaptee, dbusObject());
+}
+
+void BaseConnectionContactsInterface::setContactAttributeInterfaces(const QStringList &contactAttributeInterfaces)
+{
+    mPriv->contactAttributeInterfaces = contactAttributeInterfaces;
+}
+
+void BaseConnectionContactsInterface::setGetContactAttributesCallback(const GetContactAttributesCallback &cb)
+{
+    mPriv->getContactAttributesCallback = cb;
+}
+
+ContactAttributesMap BaseConnectionContactsInterface::getContactAttributes(const Tp::UIntList &handles,
+        const QStringList &interfaces,
+        DBusError *error)
+{
+    if (!mPriv->getContactAttributesCallback.isValid()) {
+        error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
+        return ContactAttributesMap();
+    }
+    return mPriv->getContactAttributesCallback(handles, interfaces, error);
+}
+
 }
diff --git a/TelepathyQt/base-connection.h b/TelepathyQt/base-connection.h
index 51134f1..6451ff2 100644
--- a/TelepathyQt/base-connection.h
+++ b/TelepathyQt/base-connection.h
@@ -193,6 +193,46 @@ private:
     Private *mPriv;
 };
 
+
+class TP_QT_EXPORT BaseConnectionContactsInterface : public AbstractConnectionInterface
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(BaseConnectionContactsInterface)
+
+
+public:
+    static BaseConnectionContactsInterfacePtr create() {
+        return BaseConnectionContactsInterfacePtr(new BaseConnectionContactsInterface());
+    }
+    template<typename BaseConnectionContactsInterfaceSubclass>
+    static SharedPtr<BaseConnectionContactsInterfaceSubclass> create() {
+        return SharedPtr<BaseConnectionContactsInterfaceSubclass>(
+                   new BaseConnectionContactsInterfaceSubclass());
+    }
+
+    virtual ~BaseConnectionContactsInterface();
+
+    QVariantMap immutableProperties() const;
+
+    typedef Callback3<ContactAttributesMap, const Tp::UIntList&, const QStringList&, DBusError*> GetContactAttributesCallback;
+    void setGetContactAttributesCallback(const GetContactAttributesCallback &cb);
+    ContactAttributesMap getContactAttributes(const Tp::UIntList &handles,
+            const QStringList &interfaces,
+            DBusError *error);
+    void setContactAttributeInterfaces(const QStringList &contactAttributeInterfaces);
+protected:
+    BaseConnectionContactsInterface();
+
+private:
+    void createAdaptor();
+
+    class Adaptee;
+    friend class Adaptee;
+    struct Private;
+    friend struct Private;
+    Private *mPriv;
+};
+
 }
 
 #endif
diff --git a/TelepathyQt/service-types.h b/TelepathyQt/service-types.h
index 3ec1fe6..c579767 100644
--- a/TelepathyQt/service-types.h
+++ b/TelepathyQt/service-types.h
@@ -37,6 +37,7 @@ class AbstractConnectionInterface;
 class AbstractChannelInterface;
 class BaseConnection;
 class BaseConnectionRequestsInterface;
+class BaseConnectionContactsInterface;
 class BaseConnectionManager;
 class BaseProtocol;
 class BaseProtocolAddressingInterface;
@@ -52,6 +53,7 @@ typedef SharedPtr<AbstractConnectionInterface> AbstractConnectionInterfacePtr;
 typedef SharedPtr<AbstractChannelInterface> AbstractChannelInterfacePtr;
 typedef SharedPtr<BaseConnection> BaseConnectionPtr;
 typedef SharedPtr<BaseConnectionRequestsInterface> BaseConnectionRequestsInterfacePtr;
+typedef SharedPtr<BaseConnectionContactsInterface> BaseConnectionContactsInterfacePtr;
 typedef SharedPtr<BaseConnectionManager> BaseConnectionManagerPtr;
 typedef SharedPtr<BaseProtocol> BaseProtocolPtr;
 typedef SharedPtr<BaseProtocolAddressingInterface> BaseProtocolAddressingInterfacePtr;



More information about the telepathy-commits mailing list