telepathy-qt: Added BaseChannelChatStateInterface.

David Edmundson davidedmundson at kemper.freedesktop.org
Sun Aug 17 10:55:03 PDT 2014


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

Author: Alexandr Akulich <akulichalexander at gmail.com>
Date:   Sun Aug 10 12:18:12 2014 +0600

Added BaseChannelChatStateInterface.

---

 TelepathyQt/base-channel-internal.h |   22 +++++++
 TelepathyQt/base-channel.cpp        |  114 +++++++++++++++++++++++++++++++++++
 TelepathyQt/base-channel.h          |   43 +++++++++++++
 TelepathyQt/service-types.h         |    2 +
 4 files changed, 181 insertions(+)

diff --git a/TelepathyQt/base-channel-internal.h b/TelepathyQt/base-channel-internal.h
index 653969d..8ac91d8 100644
--- a/TelepathyQt/base-channel-internal.h
+++ b/TelepathyQt/base-channel-internal.h
@@ -257,6 +257,28 @@ private:
     BaseChannelSecurableInterface *mInterface;
 };
 
+class TP_QT_NO_EXPORT BaseChannelChatStateInterface::Adaptee : public QObject
+{
+    Q_OBJECT
+    Q_PROPERTY(Tp::ChatStateMap chatStates READ chatStates)
+
+public:
+    Adaptee(BaseChannelChatStateInterface *interface);
+    ~Adaptee();
+
+    Tp::ChatStateMap chatStates() const;
+
+private Q_SLOTS:
+    void setChatState(uint state,
+            const Tp::Service::ChannelInterfaceChatStateAdaptor::SetChatStateContextPtr &context);
+
+signals:
+    void chatStateChanged(uint contact, uint state);
+
+private:
+    BaseChannelChatStateInterface *mInterface;
+};
+
 class TP_QT_NO_EXPORT BaseChannelGroupInterface::Adaptee : public QObject
 {
     Q_OBJECT
diff --git a/TelepathyQt/base-channel.cpp b/TelepathyQt/base-channel.cpp
index 1c20cca..c1c6307 100644
--- a/TelepathyQt/base-channel.cpp
+++ b/TelepathyQt/base-channel.cpp
@@ -1457,6 +1457,120 @@ void BaseChannelSecurableInterface::createAdaptor()
             mPriv->adaptee, dbusObject());
 }
 
+// Chan.I.ChatState
+struct TP_QT_NO_EXPORT BaseChannelChatStateInterface::Private {
+    Private(BaseChannelChatStateInterface *parent)
+        : adaptee(new BaseChannelChatStateInterface::Adaptee(parent))
+    {
+    }
+
+    Tp::ChatStateMap chatStates;
+    SetChatStateCallback setChatStateCB;
+    BaseChannelChatStateInterface::Adaptee *adaptee;
+};
+
+BaseChannelChatStateInterface::Adaptee::Adaptee(BaseChannelChatStateInterface *interface)
+    : QObject(interface),
+      mInterface(interface)
+{
+}
+
+BaseChannelChatStateInterface::Adaptee::~Adaptee()
+{
+}
+
+Tp::ChatStateMap BaseChannelChatStateInterface::Adaptee::chatStates() const
+{
+    return mInterface->chatStates();
+}
+
+void BaseChannelChatStateInterface::Adaptee::setChatState(uint state,
+        const Tp::Service::ChannelInterfaceChatStateAdaptor::SetChatStateContextPtr &context)
+{
+    qDebug() << "BaseChannelChatStateInterface::Adaptee::setChatState";
+    DBusError error;
+    mInterface->setChatState(state, &error);
+    if (error.isValid()) {
+        context->setFinishedWithError(error.name(), error.message());
+        return;
+    }
+    context->setFinished();
+}
+
+/**
+ * \class BaseChannelChatStateInterface
+ * \ingroup servicecm
+ * \headerfile TelepathyQt/base-channel.h <TelepathyQt/BaseChannel>
+ *
+ * \brief Base class for implementations of Channel.Interface.Chat.State
+ */
+
+/**
+ * Class constructor.
+ */
+BaseChannelChatStateInterface::BaseChannelChatStateInterface()
+    : AbstractChannelInterface(TP_QT_IFACE_CHANNEL_INTERFACE_CHAT_STATE),
+      mPriv(new Private(this))
+{
+}
+
+/**
+ * Class destructor.
+ */
+BaseChannelChatStateInterface::~BaseChannelChatStateInterface()
+{
+    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 BaseChannelChatStateInterface::immutableProperties() const
+{
+    QVariantMap map;
+    return map;
+}
+
+Tp::ChatStateMap BaseChannelChatStateInterface::chatStates() const
+{
+    return mPriv->chatStates;
+}
+
+void BaseChannelChatStateInterface::setChatStates(const Tp::ChatStateMap &chatStates)
+{
+    mPriv->chatStates = chatStates;
+}
+
+void BaseChannelChatStateInterface::createAdaptor()
+{
+    (void) new Service::ChannelInterfaceChatStateAdaptor(dbusObject()->dbusConnection(),
+            mPriv->adaptee, dbusObject());
+}
+
+void BaseChannelChatStateInterface::setSetChatStateCallback(const BaseChannelChatStateInterface::SetChatStateCallback &cb)
+{
+    mPriv->setChatStateCB = cb;
+}
+
+void BaseChannelChatStateInterface::setChatState(uint state, DBusError *error)
+{
+    if (!mPriv->setChatStateCB.isValid()) {
+        error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
+        return;
+    }
+    return mPriv->setChatStateCB(state, error);
+}
+
+void BaseChannelChatStateInterface::chatStateChanged(uint contact, uint state)
+{
+    QMetaObject::invokeMethod(mPriv->adaptee, "chatStateChanged", Q_ARG(uint, contact), Q_ARG(uint, state)); //Can simply use emit in Qt5
+}
+
 //Chan.I.Group
 BaseChannelGroupInterface::Adaptee::Adaptee(BaseChannelGroupInterface *interface)
     : QObject(interface),
diff --git a/TelepathyQt/base-channel.h b/TelepathyQt/base-channel.h
index c141df4..edfa0de 100644
--- a/TelepathyQt/base-channel.h
+++ b/TelepathyQt/base-channel.h
@@ -432,6 +432,49 @@ private:
     Private *mPriv;
 };
 
+class TP_QT_EXPORT BaseChannelChatStateInterface : public AbstractChannelInterface
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(BaseChannelChatStateInterface)
+
+public:
+    static BaseChannelChatStateInterfacePtr create()
+    {
+        return BaseChannelChatStateInterfacePtr(new BaseChannelChatStateInterface());
+    }
+    template<typename BaseChannelChatStateInterfaceSubclass>
+    static SharedPtr<BaseChannelChatStateInterfaceSubclass> create()
+    {
+        return SharedPtr<BaseChannelChatStateInterfaceSubclass>(
+                new BaseChannelChatStateInterfaceSubclass());
+    }
+
+    virtual ~BaseChannelChatStateInterface();
+
+    QVariantMap immutableProperties() const;
+
+    Tp::ChatStateMap chatStates() const;
+    void setChatStates(const Tp::ChatStateMap &chatStates);
+
+    typedef Callback2<void, uint, DBusError*> SetChatStateCallback;
+    void setSetChatStateCallback(const SetChatStateCallback &cb);
+    void setChatState(uint state, DBusError *error);
+
+    void chatStateChanged(uint contact, uint state);
+
+protected:
+    BaseChannelChatStateInterface();
+
+private:
+    void createAdaptor();
+
+    class Adaptee;
+    friend class Adaptee;
+    struct Private;
+    friend struct Private;
+    Private *mPriv;
+};
+
 class TP_QT_EXPORT BaseChannelGroupInterface : public AbstractChannelInterface
 {
     Q_OBJECT
diff --git a/TelepathyQt/service-types.h b/TelepathyQt/service-types.h
index fda50e1..e231aeb 100644
--- a/TelepathyQt/service-types.h
+++ b/TelepathyQt/service-types.h
@@ -55,6 +55,7 @@ class BaseChannelServerAuthenticationType;
 class BaseChannelSASLAuthenticationInterface;
 class BaseChannelCaptchaAuthenticationInterface;
 class BaseChannelSecurableInterface;
+class BaseChannelChatStateInterface;
 class BaseChannelGroupInterface;
 class DBusService;
 
@@ -83,6 +84,7 @@ typedef SharedPtr<BaseChannelServerAuthenticationType> BaseChannelServerAuthenti
 typedef SharedPtr<BaseChannelSASLAuthenticationInterface> BaseChannelSASLAuthenticationInterfacePtr;
 typedef SharedPtr<BaseChannelCaptchaAuthenticationInterface> BaseChannelCaptchaAuthenticationInterfacePtr;
 typedef SharedPtr<BaseChannelSecurableInterface> BaseChannelSecurableInterfacePtr;
+typedef SharedPtr<BaseChannelChatStateInterface> BaseChannelChatStateInterfacePtr;
 typedef SharedPtr<BaseChannelGroupInterface> BaseChannelGroupInterfacePtr;
 typedef SharedPtr<DBusService> DBusServicePtr;
 



More information about the telepathy-commits mailing list