telepathy-qt: Implemented BaseChannelRoomListType.

Alexandr Akulich kaffeine at kemper.freedesktop.org
Wed May 6 01:10:28 PDT 2015


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

Author: Alexandr Akulich <akulichalexander at gmail.com>
Date:   Tue Apr 21 20:17:55 2015 +0500

Implemented BaseChannelRoomListType.

The "Server" property marked as immutable, despite of the spec:
http://telepathy.freedesktop.org/spec/Channel_Type_Room_List.html

Reviewed-by: David Edmundson

---

 TelepathyQt/base-channel-internal.h |   27 ++++++
 TelepathyQt/base-channel.cpp        |  164 +++++++++++++++++++++++++++++++++++
 TelepathyQt/base-channel.h          |   49 +++++++++++
 TelepathyQt/service-types.h         |    2 +
 4 files changed, 242 insertions(+)

diff --git a/TelepathyQt/base-channel-internal.h b/TelepathyQt/base-channel-internal.h
index 334909f..d83e73b 100644
--- a/TelepathyQt/base-channel-internal.h
+++ b/TelepathyQt/base-channel-internal.h
@@ -157,6 +157,33 @@ public:
     BaseChannelMessagesInterface *mInterface;
 };
 
+class TP_QT_NO_EXPORT BaseChannelRoomListType::Adaptee : public QObject
+{
+    Q_OBJECT
+    Q_PROPERTY(QString server READ server)
+
+public:
+    Adaptee(BaseChannelRoomListType *interface);
+    ~Adaptee();
+
+    QString server() const;
+
+private Q_SLOTS:
+    void getListingRooms(
+            const Tp::Service::ChannelTypeRoomListAdaptor::GetListingRoomsContextPtr &context);
+    void listRooms(
+            const Tp::Service::ChannelTypeRoomListAdaptor::ListRoomsContextPtr &context);
+    void stopListing(
+            const Tp::Service::ChannelTypeRoomListAdaptor::StopListingContextPtr &context);
+
+Q_SIGNALS:
+    void gotRooms(const Tp::RoomInfoList &rooms);
+    void listingRooms(bool listing);
+
+private:
+    BaseChannelRoomListType *mInterface;
+};
+
 class TP_QT_NO_EXPORT BaseChannelServerAuthenticationType::Adaptee : public QObject
 {
     Q_OBJECT
diff --git a/TelepathyQt/base-channel.cpp b/TelepathyQt/base-channel.cpp
index 6edf885..6186508 100644
--- a/TelepathyQt/base-channel.cpp
+++ b/TelepathyQt/base-channel.cpp
@@ -756,6 +756,170 @@ QString BaseChannelMessagesInterface::sendMessage(const Tp::MessagePartList &mes
     return token;
 }
 
+// Chan.T.RoomList
+// The BaseChannelRoomListType code is fully or partially generated by the TelepathyQt-Generator.
+struct TP_QT_NO_EXPORT BaseChannelRoomListType::Private {
+    Private(BaseChannelRoomListType *parent,
+            const QString &server)
+        : server(server),
+          listingRooms(false),
+          adaptee(new BaseChannelRoomListType::Adaptee(parent))
+    {
+    }
+
+    QString server;
+    bool listingRooms;
+    ListRoomsCallback listRoomsCB;
+    StopListingCallback stopListingCB;
+    BaseChannelRoomListType::Adaptee *adaptee;
+};
+
+BaseChannelRoomListType::Adaptee::Adaptee(BaseChannelRoomListType *interface)
+    : QObject(interface),
+      mInterface(interface)
+{
+}
+
+BaseChannelRoomListType::Adaptee::~Adaptee()
+{
+}
+
+QString BaseChannelRoomListType::Adaptee::server() const
+{
+    return mInterface->server();
+}
+
+void BaseChannelRoomListType::Adaptee::getListingRooms(
+        const Tp::Service::ChannelTypeRoomListAdaptor::GetListingRoomsContextPtr &context)
+{
+    context->setFinished(mInterface->getListingRooms());
+}
+
+void BaseChannelRoomListType::Adaptee::listRooms(
+        const Tp::Service::ChannelTypeRoomListAdaptor::ListRoomsContextPtr &context)
+{
+    qDebug() << "BaseChannelRoomListType::Adaptee::listRooms";
+    DBusError error;
+    mInterface->listRooms(&error);
+    if (error.isValid()) {
+        context->setFinishedWithError(error.name(), error.message());
+        return;
+    }
+    context->setFinished();
+}
+
+void BaseChannelRoomListType::Adaptee::stopListing(
+        const Tp::Service::ChannelTypeRoomListAdaptor::StopListingContextPtr &context)
+{
+    qDebug() << "BaseChannelRoomListType::Adaptee::stopListing";
+    DBusError error;
+    mInterface->stopListing(&error);
+    if (error.isValid()) {
+        context->setFinishedWithError(error.name(), error.message());
+        return;
+    }
+    context->setFinished();
+}
+
+/**
+ * \class BaseChannelRoomListType
+ * \ingroup servicecm
+ * \headerfile TelepathyQt/base-channel.h <TelepathyQt/BaseChannel>
+ *
+ * \brief Base class for implementations of Channel.Type.RoomList
+ */
+
+/**
+ * Class constructor.
+ */
+BaseChannelRoomListType::BaseChannelRoomListType(const QString &server)
+    : AbstractChannelInterface(TP_QT_IFACE_CHANNEL_TYPE_ROOM_LIST),
+      mPriv(new Private(this, server))
+{
+}
+
+/**
+ * Class destructor.
+ */
+BaseChannelRoomListType::~BaseChannelRoomListType()
+{
+    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 BaseChannelRoomListType::immutableProperties() const
+{
+    QVariantMap map;
+    map.insert(TP_QT_IFACE_CHANNEL_TYPE_ROOM_LIST + QLatin1String(".Server"),
+               QVariant::fromValue(mPriv->adaptee->server()));
+    return map;
+}
+
+QString BaseChannelRoomListType::server() const
+{
+    return mPriv->server;
+}
+
+void BaseChannelRoomListType::createAdaptor()
+{
+    (void) new Tp::Service::ChannelTypeRoomListAdaptor(dbusObject()->dbusConnection(),
+            mPriv->adaptee, dbusObject());
+}
+
+bool BaseChannelRoomListType::getListingRooms()
+{
+    return mPriv->listingRooms;
+}
+
+void BaseChannelRoomListType::setListingRooms(bool listing)
+{
+    if (mPriv->listingRooms == listing) {
+        return;
+    }
+
+    mPriv->listingRooms = listing;
+    QMetaObject::invokeMethod(mPriv->adaptee, "listingRooms", Q_ARG(bool, listing)); //Can simply use emit in Qt5
+}
+
+void BaseChannelRoomListType::setListRoomsCallback(const ListRoomsCallback &cb)
+{
+    mPriv->listRoomsCB = cb;
+}
+
+void BaseChannelRoomListType::listRooms(DBusError *error)
+{
+    if (!mPriv->listRoomsCB.isValid()) {
+        error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
+        return;
+    }
+    return mPriv->listRoomsCB(error);
+}
+
+void BaseChannelRoomListType::setStopListingCallback(const StopListingCallback &cb)
+{
+    mPriv->stopListingCB = cb;
+}
+
+void BaseChannelRoomListType::stopListing(DBusError *error)
+{
+    if (!mPriv->stopListingCB.isValid()) {
+        error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
+        return;
+    }
+    return mPriv->stopListingCB(error);
+}
+
+void BaseChannelRoomListType::gotRooms(const Tp::RoomInfoList &rooms)
+{
+    QMetaObject::invokeMethod(mPriv->adaptee, "gotRooms", Q_ARG(Tp::RoomInfoList, rooms)); //Can simply use emit in Qt5
+}
 
 //Chan.T.ServerAuthentication
 BaseChannelServerAuthenticationType::Adaptee::Adaptee(BaseChannelServerAuthenticationType *interface)
diff --git a/TelepathyQt/base-channel.h b/TelepathyQt/base-channel.h
index eb64e04..4f5319e 100644
--- a/TelepathyQt/base-channel.h
+++ b/TelepathyQt/base-channel.h
@@ -216,6 +216,55 @@ private:
     Private *mPriv;
 };
 
+class TP_QT_EXPORT BaseChannelRoomListType : public AbstractChannelInterface
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(BaseChannelRoomListType)
+
+public:
+    static BaseChannelRoomListTypePtr create(const QString &server = QString())
+    {
+        return BaseChannelRoomListTypePtr(new BaseChannelRoomListType(server));
+    }
+    template<typename BaseChannelRoomListTypeSubclass>
+    static SharedPtr<BaseChannelRoomListTypeSubclass> create(const QString &server = QString())
+    {
+        return SharedPtr<BaseChannelRoomListTypeSubclass>(
+                new BaseChannelRoomListTypeSubclass(server));
+    }
+
+    virtual ~BaseChannelRoomListType();
+
+    QVariantMap immutableProperties() const;
+
+    QString server() const;
+
+    bool getListingRooms();
+    void setListingRooms(bool listing);
+
+    typedef Callback1<void, DBusError*> ListRoomsCallback;
+    void setListRoomsCallback(const ListRoomsCallback &cb);
+    void listRooms(DBusError *error);
+
+    typedef Callback1<void, DBusError*> StopListingCallback;
+    void setStopListingCallback(const StopListingCallback &cb);
+    void stopListing(DBusError *error);
+
+    void gotRooms(const Tp::RoomInfoList &rooms);
+
+protected:
+    BaseChannelRoomListType(const QString &server);
+
+private:
+    void createAdaptor();
+
+    class Adaptee;
+    friend class Adaptee;
+    struct Private;
+    friend struct Private;
+    Private *mPriv;
+};
+
 class TP_QT_EXPORT BaseChannelServerAuthenticationType : public AbstractChannelInterface
 {
     Q_OBJECT
diff --git a/TelepathyQt/service-types.h b/TelepathyQt/service-types.h
index 216c37c..04be6cf 100644
--- a/TelepathyQt/service-types.h
+++ b/TelepathyQt/service-types.h
@@ -57,6 +57,7 @@ class BaseChannel;
 class BaseChannelTextType;
 class BaseChannelCallType;
 class BaseChannelMessagesInterface;
+class BaseChannelRoomListType;
 class BaseChannelServerAuthenticationType;
 class BaseChannelSASLAuthenticationInterface;
 class BaseChannelCaptchaAuthenticationInterface;
@@ -98,6 +99,7 @@ typedef SharedPtr<BaseChannel> BaseChannelPtr;
 typedef SharedPtr<BaseChannelCallType> BaseChannelCallTypePtr;
 typedef SharedPtr<BaseChannelTextType> BaseChannelTextTypePtr;
 typedef SharedPtr<BaseChannelMessagesInterface> BaseChannelMessagesInterfacePtr;
+typedef SharedPtr<BaseChannelRoomListType> BaseChannelRoomListTypePtr;
 typedef SharedPtr<BaseChannelServerAuthenticationType> BaseChannelServerAuthenticationTypePtr;
 typedef SharedPtr<BaseChannelSASLAuthenticationInterface> BaseChannelSASLAuthenticationInterfacePtr;
 typedef SharedPtr<BaseChannelCaptchaAuthenticationInterface> BaseChannelCaptchaAuthenticationInterfacePtr;



More information about the telepathy-commits mailing list