diff options
author | Andre Moreira Magalhaes (andrunko) <andre.magalhaes@collabora.co.uk> | 2012-04-02 09:40:18 -0300 |
---|---|---|
committer | Andre Moreira Magalhaes (andrunko) <andre.magalhaes@collabora.co.uk> | 2012-04-02 10:37:18 -0300 |
commit | 8a408ee686e6a75861376bdbfbf2c2acacc8ebe0 (patch) | |
tree | fcca777561a0df9961b9aade2a0ab67236ac4dac | |
parent | b412bae468047952d9d45341a7fcfe2cbae901a9 (diff) |
BaseProtocolAddressingInterface: Add support for Proto.I.Addressing.
-rw-r--r-- | TelepathyQt/BaseProtocolAddressingInterface | 13 | ||||
-rw-r--r-- | TelepathyQt/CMakeLists.txt | 1 | ||||
-rw-r--r-- | TelepathyQt/base-protocol-internal.h | 25 | ||||
-rw-r--r-- | TelepathyQt/base-protocol.cpp | 135 | ||||
-rw-r--r-- | TelepathyQt/base-protocol.h | 34 | ||||
-rw-r--r-- | TelepathyQt/types.h | 2 |
6 files changed, 203 insertions, 7 deletions
diff --git a/TelepathyQt/BaseProtocolAddressingInterface b/TelepathyQt/BaseProtocolAddressingInterface new file mode 100644 index 00000000..b4605482 --- /dev/null +++ b/TelepathyQt/BaseProtocolAddressingInterface @@ -0,0 +1,13 @@ +#ifndef _TelepathyQt_BaseProtocolAddressingInterface_HEADER_GUARD_ +#define _TelepathyQt_BaseProtocolAddressingInterface_HEADER_GUARD_ + +#ifndef IN_TP_QT_HEADER +#define IN_TP_QT_HEADER +#endif + +#include <TelepathyQt/base-protocol.h> + +#undef IN_TP_QT_HEADER + +#endif +// vim:set ft=cpp: diff --git a/TelepathyQt/CMakeLists.txt b/TelepathyQt/CMakeLists.txt index 36ef8ee1..c282efe3 100644 --- a/TelepathyQt/CMakeLists.txt +++ b/TelepathyQt/CMakeLists.txt @@ -840,6 +840,7 @@ if(ENABLE_EXPERIMENTAL_SERVICE_SUPPORT) BaseConnection base-connection.h BaseProtocol + BaseProtocolAddressingInterface base-protocol.h DBusError dbus-error.h diff --git a/TelepathyQt/base-protocol-internal.h b/TelepathyQt/base-protocol-internal.h index b79e97db..b5bc616d 100644 --- a/TelepathyQt/base-protocol-internal.h +++ b/TelepathyQt/base-protocol-internal.h @@ -70,4 +70,29 @@ public: Service::ProtocolAdaptor *mAdaptor; }; +class TP_QT_NO_EXPORT BaseProtocolAddressingInterface::Adaptee : public QObject +{ + Q_OBJECT + Q_PROPERTY(QStringList addressableVCardFields READ addressableVCardFields) + Q_PROPERTY(QStringList addressableURISchemes READ addressableURISchemes) + +public: + Adaptee(const QDBusConnection &dbusConnection, QObject *dbusObject, + BaseProtocolAddressingInterface *interface); + ~Adaptee(); + + QStringList addressableVCardFields() const; + QStringList addressableURISchemes() const; + +private Q_SLOTS: + void normalizeVCardAddress(const QString &vCardField, const QString &vCardAddress, + const Tp::Service::ProtocolInterfaceAddressingAdaptor::NormalizeVCardAddressContextPtr &context); + void normalizeContactURI(const QString &uri, + const Tp::Service::ProtocolInterfaceAddressingAdaptor::NormalizeContactURIContextPtr &context); + +public: + BaseProtocolAddressingInterface *mInterface; + Service::ProtocolInterfaceAddressingAdaptor *mAdaptor; +}; + } diff --git a/TelepathyQt/base-protocol.cpp b/TelepathyQt/base-protocol.cpp index 3505a973..008baf54 100644 --- a/TelepathyQt/base-protocol.cpp +++ b/TelepathyQt/base-protocol.cpp @@ -329,4 +329,139 @@ AbstractProtocolInterface::~AbstractProtocolInterface() { } +BaseProtocolAddressingInterface::Adaptee::Adaptee(const QDBusConnection &dbusConnection, + QObject *dbusObject, BaseProtocolAddressingInterface *interface) + : QObject(), + mInterface(interface) +{ + mAdaptor = new Service::ProtocolInterfaceAddressingAdaptor(dbusConnection, this, dbusObject); +} + +BaseProtocolAddressingInterface::Adaptee::~Adaptee() +{ +} + +QStringList BaseProtocolAddressingInterface::Adaptee::addressableVCardFields() const +{ + return mInterface->addressableVCardFields(); +} + +QStringList BaseProtocolAddressingInterface::Adaptee::addressableURISchemes() const +{ + return mInterface->addressableUriSchemes(); +} + +void BaseProtocolAddressingInterface::Adaptee::normalizeVCardAddress(const QString& vCardField, + const QString& vCardAddress, + const Tp::Service::ProtocolInterfaceAddressingAdaptor::NormalizeVCardAddressContextPtr &context) +{ + DBusError error; + QString normalizedAddress; + normalizedAddress = mInterface->normalizeVCardAddress(vCardField, vCardAddress, &error); + if (normalizedAddress.isEmpty()) { + context->setFinishedWithError(error); + return; + } + context->setFinished(normalizedAddress); +} + +void BaseProtocolAddressingInterface::Adaptee::normalizeContactURI(const QString& uri, + const Tp::Service::ProtocolInterfaceAddressingAdaptor::NormalizeContactURIContextPtr &context) +{ + DBusError error; + QString normalizedUri; + normalizedUri = mInterface->normalizeContactUri(uri, &error); + if (normalizedUri.isEmpty()) { + context->setFinishedWithError(error); + return; + } + context->setFinished(normalizedUri); +} + +struct TP_QT_NO_EXPORT BaseProtocolAddressingInterface::Private +{ + Private() + : adaptee(0) + { + } + + ~Private() + { + delete adaptee; + } + + BaseProtocolAddressingInterface::Adaptee *adaptee; + QStringList addressableVCardFields; + QStringList addressableUriSchemes; + NormalizeVCardAddressCallback normalizeVCardAddressCb; + NormalizeContactUriCallback normalizeContactUriCb; +}; + +BaseProtocolAddressingInterface::BaseProtocolAddressingInterface() + : AbstractProtocolInterface(TP_QT_IFACE_PROTOCOL_INTERFACE_ADDRESSING), + mPriv(new Private) +{ +} + +BaseProtocolAddressingInterface::~BaseProtocolAddressingInterface() +{ + delete mPriv; +} + +QStringList BaseProtocolAddressingInterface::addressableVCardFields() const +{ + return mPriv->addressableVCardFields; +} + +void BaseProtocolAddressingInterface::setAddressableVCardFields(const QStringList &vcardFields) +{ + mPriv->addressableVCardFields = vcardFields; +} + +QStringList BaseProtocolAddressingInterface::addressableUriSchemes() const +{ + return mPriv->addressableUriSchemes; +} + +void BaseProtocolAddressingInterface::setAddressableUriSchemes(const QStringList &uriSchemes) +{ + mPriv->addressableUriSchemes = uriSchemes; +} + +void BaseProtocolAddressingInterface::setNormalizeVCardAddressCallback( + const NormalizeVCardAddressCallback &cb) +{ + mPriv->normalizeVCardAddressCb = cb; +} + +QString BaseProtocolAddressingInterface::normalizeVCardAddress(const QString &vCardField, + const QString &vCardAddress, DBusError *error) +{ + if (!mPriv->normalizeVCardAddressCb.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return QString(); + } + return mPriv->normalizeVCardAddressCb(vCardField, vCardAddress, error); +} + +void BaseProtocolAddressingInterface::setNormalizeContactUriCallback( + const NormalizeContactUriCallback &cb) +{ + mPriv->normalizeContactUriCb = cb; +} + +QString BaseProtocolAddressingInterface::normalizeContactUri(const QString &uri, DBusError *error) +{ + if (!mPriv->normalizeContactUriCb.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return QString(); + } + return mPriv->normalizeContactUriCb(uri, error); +} + +void BaseProtocolAddressingInterface::createAdaptor(const QDBusConnection &dbusConnection, QObject *dbusObject) +{ + mPriv->adaptee = new BaseProtocolAddressingInterface::Adaptee(dbusConnection, dbusObject, this); +} + } diff --git a/TelepathyQt/base-protocol.h b/TelepathyQt/base-protocol.h index 5d7feffd..bdef6bc2 100644 --- a/TelepathyQt/base-protocol.h +++ b/TelepathyQt/base-protocol.h @@ -145,13 +145,21 @@ protected: Private *mPriv; }; -/* -class TP_QT_EXPORT BaseProtocolAddressingInterface : public QObject +class TP_QT_EXPORT BaseProtocolAddressingInterface : public AbstractProtocolInterface { - Q_OBJECT + Q_DISABLE_COPY(BaseProtocolAddressingInterface) public: - BaseProtocolAddressingInterface(); + static BaseProtocolAddressingInterfacePtr create() + { + return BaseProtocolAddressingInterfacePtr(new BaseProtocolAddressingInterface()); + } + template<typename BaseProtocolAddressingInterfaceSubclass> + static BaseProtocolAddressingInterfacePtr create() + { + return BaseProtocolAddressingInterfacePtr(new BaseProtocolAddressingInterfaceSubclass()); + } + virtual ~BaseProtocolAddressingInterface(); QStringList addressableVCardFields() const; @@ -160,16 +168,28 @@ public: QStringList addressableUriSchemes() const; void setAddressableUriSchemes(const QStringList &uriSchemes); -protected Q_SLOTS: - // normalizeVCardAddress - // normalizeContactURI + typedef Callback3<QString, const QString &, const QString &, DBusError*> NormalizeVCardAddressCallback; + void setNormalizeVCardAddressCallback(const NormalizeVCardAddressCallback &cb); + QString normalizeVCardAddress(const QString &vCardField, const QString &vCardAddress, DBusError *error); + + typedef Callback2<QString, const QString &, DBusError*> NormalizeContactUriCallback; + void setNormalizeContactUriCallback(const NormalizeContactUriCallback &cb); + QString normalizeContactUri(const QString &uri, DBusError *error); + +protected: + BaseProtocolAddressingInterface(); private: + void createAdaptor(const QDBusConnection &dbusConnection, QObject *dbusObject); + + class Adaptee; + friend class Adaptee; struct Private; friend struct Private; Private *mPriv; }; +/* class TP_QT_EXPORT BaseProtocolAvatarsInterface : public QObject { Q_OBJECT diff --git a/TelepathyQt/types.h b/TelepathyQt/types.h index b9bbc7f9..0aebbefb 100644 --- a/TelepathyQt/types.h +++ b/TelepathyQt/types.h @@ -63,6 +63,7 @@ class CaptchaAuthentication; class BaseConnection; class BaseConnectionManager; class BaseProtocol; +class BaseProtocolAddressingInterface; class Channel; class ChannelDispatchOperation; class ChannelFactory; @@ -126,6 +127,7 @@ typedef SharedPtr<CaptchaAuthentication> CaptchaAuthenticationPtr; typedef SharedPtr<BaseConnection> BaseConnectionPtr; typedef SharedPtr<BaseConnectionManager> BaseConnectionManagerPtr; typedef SharedPtr<BaseProtocol> BaseProtocolPtr; +typedef SharedPtr<BaseProtocolAddressingInterface> BaseProtocolAddressingInterfacePtr; typedef SharedPtr<Channel> ChannelPtr; typedef SharedPtr<ChannelDispatchOperation> ChannelDispatchOperationPtr; typedef SharedPtr<ChannelFactory> ChannelFactoryPtr; |