telepathy-qt: Add BaseChannelSMSInterface

David Edmundson davidedmundson at kemper.freedesktop.org
Tue Feb 10 06:30:10 PST 2015


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

Author: Tiago Salem Herrmann <tiago.herrmann at canonical.com>
Date:   Fri Jan 30 17:43:57 2015 -0200

Add BaseChannelSMSInterface

---

 TelepathyQt/base-channel-internal.h |   25 +++++++++
 TelepathyQt/base-channel.cpp        |  105 +++++++++++++++++++++++++++++++++++
 TelepathyQt/base-channel.h          |   38 +++++++++++++
 TelepathyQt/service-types.h         |    2 +
 4 files changed, 170 insertions(+)

diff --git a/TelepathyQt/base-channel-internal.h b/TelepathyQt/base-channel-internal.h
index 156780d..95a50ae 100644
--- a/TelepathyQt/base-channel-internal.h
+++ b/TelepathyQt/base-channel-internal.h
@@ -418,6 +418,31 @@ public:
     BaseChannelCallType *mInterface;
 };
 
+class TP_QT_NO_EXPORT BaseChannelSMSInterface::Adaptee : public QObject
+{
+    Q_OBJECT
+    Q_PROPERTY(bool flash READ flash)
+    Q_PROPERTY(bool smsChannel READ smsChannel)
+public:
+    Adaptee(BaseChannelSMSInterface *interface);
+    ~Adaptee();
+
+    bool flash() {
+        return mInterface->flash();
+    }
+
+    bool smsChannel() {
+        return mInterface->smsChannel();
+    }
+
+public slots:
+    void getSMSLength(const Tp::MessagePartList &messages, const Tp::Service::ChannelInterfaceSMSAdaptor::GetSMSLengthContextPtr &context);
+signals:
+    void smsChannelChanged(bool smsChannel);
+public:
+    BaseChannelSMSInterface *mInterface;
+};
+
 class TP_QT_NO_EXPORT BaseChannelHoldInterface::Adaptee : public QObject
 {
     Q_OBJECT
diff --git a/TelepathyQt/base-channel.cpp b/TelepathyQt/base-channel.cpp
index 8bcf6bf..e5d721e 100644
--- a/TelepathyQt/base-channel.cpp
+++ b/TelepathyQt/base-channel.cpp
@@ -2595,4 +2595,109 @@ void BaseChannelConferenceInterface::createAdaptor()
             mPriv->adaptee, dbusObject());
 }
 
+// Chan.I.SMS
+BaseChannelSMSInterface::Adaptee::Adaptee(BaseChannelSMSInterface *interface)
+    : QObject(interface),
+      mInterface(interface)
+{
+}
+
+BaseChannelSMSInterface::Adaptee::~Adaptee()
+{
+}
+
+struct TP_QT_NO_EXPORT BaseChannelSMSInterface::Private {
+    Private(BaseChannelSMSInterface *parent, bool flash, bool smsChannel)
+        : flash(flash),
+        smsChannel(smsChannel),
+        adaptee(new BaseChannelSMSInterface::Adaptee(parent))
+    {
+    }
+
+    bool flash;
+    bool smsChannel;
+    GetSMSLengthCallback getSMSLengthCB;
+    BaseChannelSMSInterface::Adaptee *adaptee;
+};
+
+void BaseChannelSMSInterface::Adaptee::getSMSLength(const Tp::MessagePartList & messages, const Tp::Service::ChannelInterfaceSMSAdaptor::GetSMSLengthContextPtr &context)
+{
+    if (!mInterface->mPriv->getSMSLengthCB.isValid()) {
+        context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
+        return;
+    }
+
+    DBusError error;
+    mInterface->mPriv->getSMSLengthCB(messages, &error);
+    if (error.isValid()) {
+        context->setFinishedWithError(error.name(), error.message());
+        return;
+    }
+    // TODO: implement
+    context->setFinished(0,0,0);
+}
+
+/**
+ * \class BaseChannelSMSInterface
+ * \ingroup servicecm
+ * \headerfile TelepathyQt/base-channel.h <TelepathyQt/BaseChannel>
+ *
+ * \brief Base class for implementations of Channel.Interface.SMS
+ *
+ */
+
+/**
+ * Class constructor.
+ */
+BaseChannelSMSInterface::BaseChannelSMSInterface(bool flash, bool smsChannel)
+    : AbstractChannelInterface(TP_QT_IFACE_CHANNEL_INTERFACE_SMS),
+      mPriv(new Private(this, flash, smsChannel))
+{
+}
+
+void BaseChannelSMSInterface::setGetSMSLengthCallback(const GetSMSLengthCallback &cb)
+{
+    mPriv->getSMSLengthCB = cb;
+}
+
+/**
+ * Class destructor.
+ */
+BaseChannelSMSInterface::~BaseChannelSMSInterface()
+{
+    delete mPriv;
+}
+
+bool BaseChannelSMSInterface::flash() const
+{
+    return mPriv->flash;
+}
+
+bool BaseChannelSMSInterface::smsChannel() const
+{
+    return mPriv->smsChannel;
+}
+
+/**
+ * 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 BaseChannelSMSInterface::immutableProperties() const
+{
+    QVariantMap map;
+    map.insert(TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash"),
+               QVariant::fromValue(mPriv->adaptee->flash()));
+    return map;
+}
+
+void BaseChannelSMSInterface::createAdaptor()
+{
+    (void) new Service::ChannelInterfaceSMSAdaptor(dbusObject()->dbusConnection(),
+            mPriv->adaptee, dbusObject());
+}
+
 }
diff --git a/TelepathyQt/base-channel.h b/TelepathyQt/base-channel.h
index 9a8bfc3..699ff07 100644
--- a/TelepathyQt/base-channel.h
+++ b/TelepathyQt/base-channel.h
@@ -772,5 +772,43 @@ private:
     Private *mPriv;
 };
 
+class TP_QT_EXPORT BaseChannelSMSInterface : public AbstractChannelInterface
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(BaseChannelSMSInterface)
+
+public:
+    static BaseChannelSMSInterfacePtr create(bool flash, bool smsChannel) {
+        return BaseChannelSMSInterfacePtr(new BaseChannelSMSInterface(flash, smsChannel));
+    }
+    template<typename BaseChannelSMSInterfaceSubclass>
+    static SharedPtr<BaseChannelSMSInterfaceSubclass> create(bool flash, bool smsChannel) {
+        return SharedPtr<BaseChannelSMSInterfaceSubclass>(
+                   new BaseChannelSMSInterfaceSubclass(flash, smsChannel));
+    }
+    virtual ~BaseChannelSMSInterface();
+
+    QVariantMap immutableProperties() const;
+
+    typedef Callback2<void, const Tp::MessagePartList &, DBusError*> GetSMSLengthCallback;
+    void setGetSMSLengthCallback(const GetSMSLengthCallback &cb);
+
+    bool flash() const;
+    bool smsChannel() const;
+
+Q_SIGNALS:
+    void smsChannelChanged(bool smsChannel);
+
+private:
+    BaseChannelSMSInterface(bool flash, bool smsChannel);
+    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 c93d363..24d68f7 100644
--- a/TelepathyQt/service-types.h
+++ b/TelepathyQt/service-types.h
@@ -66,6 +66,7 @@ class BaseChannelGroupInterface;
 class BaseChannelHoldInterface;
 class BaseChannelMergeableConferenceInterface;
 class BaseChannelSplittableInterface;
+class BaseChannelSMSInterface;
 class BaseChannelConferenceInterface;
 class DBusService;
 
@@ -105,6 +106,7 @@ typedef SharedPtr<BaseChannelGroupInterface> BaseChannelGroupInterfacePtr;
 typedef SharedPtr<BaseChannelHoldInterface> BaseChannelHoldInterfacePtr;
 typedef SharedPtr<BaseChannelMergeableConferenceInterface> BaseChannelMergeableConferenceInterfacePtr;
 typedef SharedPtr<BaseChannelSplittableInterface> BaseChannelSplittableInterfacePtr;
+typedef SharedPtr<BaseChannelSMSInterface> BaseChannelSMSInterfacePtr;
 typedef SharedPtr<BaseChannelConferenceInterface> BaseChannelConferenceInterfacePtr;
 typedef SharedPtr<DBusService> DBusServicePtr;
 



More information about the telepathy-commits mailing list