diff options
author | Tiago Salem Herrmann <tiago.herrmann@canonical.com> | 2015-01-30 17:43:57 -0200 |
---|---|---|
committer | David Edmundson <kde@davidedmundson.co.uk> | 2015-02-10 15:29:23 +0100 |
commit | fa32c36a1dc64ed9058a3b98d6c87edd4b227842 (patch) | |
tree | f7dac157b1b07508d39bfe3a1e7e2a1bc6373d00 | |
parent | 56667bfa6db7f108611b7d407f66108ba08d7a97 (diff) |
Add BaseChannelSMSInterface
-rw-r--r-- | TelepathyQt/base-channel-internal.h | 25 | ||||
-rw-r--r-- | TelepathyQt/base-channel.cpp | 105 | ||||
-rw-r--r-- | TelepathyQt/base-channel.h | 38 | ||||
-rw-r--r-- | TelepathyQt/service-types.h | 2 |
4 files changed, 170 insertions, 0 deletions
diff --git a/TelepathyQt/base-channel-internal.h b/TelepathyQt/base-channel-internal.h index 156780d8..95a50aef 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 8bcf6bf0..e5d721ed 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 9a8bfc30..699ff072 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 c93d3631..24d68f70 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; |