diff options
| author | Alexandr Akulich <akulichalexander@gmail.com> | 2014-07-09 20:17:35 +0600 |
|---|---|---|
| committer | Alexandr Akulich <akulichalexander@gmail.com> | 2014-08-05 21:29:26 +0600 |
| commit | b857325763461b8a61180bc2894abd0ff69eec59 (patch) | |
| tree | ae4fdfa693042b6b0353874a8d36790407999f88 | |
| parent | 916104436276bc526390ac44842e7a9d3b2df908 (diff) | |
Added BaseConnectionContactInfoInterface.
| -rw-r--r-- | TelepathyQt/base-connection-internal.h | 30 | ||||
| -rw-r--r-- | TelepathyQt/base-connection.cpp | 215 | ||||
| -rw-r--r-- | TelepathyQt/base-connection.h | 59 | ||||
| -rw-r--r-- | TelepathyQt/service-types.h | 2 |
4 files changed, 305 insertions, 1 deletions
diff --git a/TelepathyQt/base-connection-internal.h b/TelepathyQt/base-connection-internal.h index 06330255..173b11a0 100644 --- a/TelepathyQt/base-connection-internal.h +++ b/TelepathyQt/base-connection-internal.h @@ -202,6 +202,36 @@ private: BaseConnectionContactListInterface *mInterface; }; +class TP_QT_NO_EXPORT BaseConnectionContactInfoInterface::Adaptee : public QObject +{ + Q_OBJECT + Q_PROPERTY(uint contactInfoFlags READ contactInfoFlags) + Q_PROPERTY(Tp::FieldSpecs supportedFields READ supportedFields) + +public: + Adaptee(BaseConnectionContactInfoInterface *interface); + ~Adaptee(); + + uint contactInfoFlags() const; + Tp::FieldSpecs supportedFields() const; + +private Q_SLOTS: + void getContactInfo(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceContactInfoAdaptor::GetContactInfoContextPtr &context); + void refreshContactInfo(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceContactInfoAdaptor::RefreshContactInfoContextPtr &context); + void requestContactInfo(uint contact, + const Tp::Service::ConnectionInterfaceContactInfoAdaptor::RequestContactInfoContextPtr &context); + void setContactInfo(const Tp::ContactInfoFieldList &contactInfo, + const Tp::Service::ConnectionInterfaceContactInfoAdaptor::SetContactInfoContextPtr &context); + +signals: + void contactInfoChanged(uint contact, const Tp::ContactInfoFieldList &contactInfo); + +private: + BaseConnectionContactInfoInterface *mInterface; +}; + class TP_QT_NO_EXPORT BaseConnectionAddressingInterface::Adaptee : public QObject { Q_OBJECT diff --git a/TelepathyQt/base-connection.cpp b/TelepathyQt/base-connection.cpp index f0856fcd..74d60f50 100644 --- a/TelepathyQt/base-connection.cpp +++ b/TelepathyQt/base-connection.cpp @@ -29,7 +29,6 @@ #include "TelepathyQt/debug-internal.h" #include <TelepathyQt/BaseChannel> -#include <TelepathyQt/Constants> #include <TelepathyQt/DBusObject> #include <TelepathyQt/Utils> #include <TelepathyQt/AbstractProtocolInterface> @@ -1441,6 +1440,220 @@ void BaseConnectionContactListInterface::contactsChangedWithID(const Tp::Contact QMetaObject::invokeMethod(mPriv->adaptee, "contactsChangedWithID", Q_ARG(Tp::ContactSubscriptionMap, changes), Q_ARG(Tp::HandleIdentifierMap, identifiers), Q_ARG(Tp::HandleIdentifierMap, removals)); //Can simply use emit in Qt5 } +// Conn.I.ContactInfo +struct TP_QT_NO_EXPORT BaseConnectionContactInfoInterface::Private { + Private(BaseConnectionContactInfoInterface *parent) + : adaptee(new BaseConnectionContactInfoInterface::Adaptee(parent)) + { + } + + Tp::ContactInfoFlags contactInfoFlags; + Tp::FieldSpecs supportedFields; + GetContactInfoCallback getContactInfoCB; + RefreshContactInfoCallback refreshContactInfoCB; + RequestContactInfoCallback requestContactInfoCB; + SetContactInfoCallback setContactInfoCB; + BaseConnectionContactInfoInterface::Adaptee *adaptee; +}; + +BaseConnectionContactInfoInterface::Adaptee::Adaptee(BaseConnectionContactInfoInterface *interface) + : QObject(interface), + mInterface(interface) +{ +} + +BaseConnectionContactInfoInterface::Adaptee::~Adaptee() +{ +} + +uint BaseConnectionContactInfoInterface::Adaptee::contactInfoFlags() const +{ + return mInterface->contactInfoFlags(); +} + +Tp::FieldSpecs BaseConnectionContactInfoInterface::Adaptee::supportedFields() const +{ + return mInterface->supportedFields(); +} + +void BaseConnectionContactInfoInterface::Adaptee::getContactInfo(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceContactInfoAdaptor::GetContactInfoContextPtr &context) +{ + qDebug() << "BaseConnectionContactInfoInterface::Adaptee::getContactInfo"; + DBusError error; + Tp::ContactInfoMap contactInfo = mInterface->getContactInfo(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(contactInfo); +} + +void BaseConnectionContactInfoInterface::Adaptee::refreshContactInfo(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceContactInfoAdaptor::RefreshContactInfoContextPtr &context) +{ + qDebug() << "BaseConnectionContactInfoInterface::Adaptee::refreshContactInfo"; + DBusError error; + mInterface->refreshContactInfo(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactInfoInterface::Adaptee::requestContactInfo(uint contact, + const Tp::Service::ConnectionInterfaceContactInfoAdaptor::RequestContactInfoContextPtr &context) +{ + qDebug() << "BaseConnectionContactInfoInterface::Adaptee::requestContactInfo"; + DBusError error; + Tp::ContactInfoFieldList contactInfo = mInterface->requestContactInfo(contact, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(contactInfo); +} + +void BaseConnectionContactInfoInterface::Adaptee::setContactInfo(const Tp::ContactInfoFieldList &contactInfo, + const Tp::Service::ConnectionInterfaceContactInfoAdaptor::SetContactInfoContextPtr &context) +{ + qDebug() << "BaseConnectionContactInfoInterface::Adaptee::setContactInfo"; + DBusError error; + mInterface->setContactInfo(contactInfo, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +/** + * \class BaseConnectionContactInfoInterface + * \ingroup servicecm + * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> + * + * \brief Base class for implementations of Connection.Interface.Contact.Info + */ + +/** + * Class constructor. + */ +BaseConnectionContactInfoInterface::BaseConnectionContactInfoInterface() + : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_INTERFACE_CONTACT_INFO), + mPriv(new Private(this)) +{ +} + +/** + * Class destructor. + */ +BaseConnectionContactInfoInterface::~BaseConnectionContactInfoInterface() +{ + 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 BaseConnectionContactInfoInterface::immutableProperties() const +{ + QVariantMap map; + return map; +} + +Tp::ContactInfoFlags BaseConnectionContactInfoInterface::contactInfoFlags() const +{ + return mPriv->contactInfoFlags; +} + +void BaseConnectionContactInfoInterface::setContactInfoFlags(const Tp::ContactInfoFlags &contactInfoFlags) +{ + mPriv->contactInfoFlags = contactInfoFlags; +} + +Tp::FieldSpecs BaseConnectionContactInfoInterface::supportedFields() const +{ + return mPriv->supportedFields; +} + +void BaseConnectionContactInfoInterface::setSupportedFields(const Tp::FieldSpecs &supportedFields) +{ + mPriv->supportedFields = supportedFields; +} + +void BaseConnectionContactInfoInterface::createAdaptor() +{ + (void) new Service::ConnectionInterfaceContactInfoAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + +void BaseConnectionContactInfoInterface::setGetContactInfoCallback(const BaseConnectionContactInfoInterface::GetContactInfoCallback &cb) +{ + mPriv->getContactInfoCB = cb; +} + +Tp::ContactInfoMap BaseConnectionContactInfoInterface::getContactInfo(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->getContactInfoCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return Tp::ContactInfoMap(); + } + return mPriv->getContactInfoCB(contacts, error); +} + +void BaseConnectionContactInfoInterface::setRefreshContactInfoCallback(const BaseConnectionContactInfoInterface::RefreshContactInfoCallback &cb) +{ + mPriv->refreshContactInfoCB = cb; +} + +void BaseConnectionContactInfoInterface::refreshContactInfo(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->refreshContactInfoCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->refreshContactInfoCB(contacts, error); +} + +void BaseConnectionContactInfoInterface::setRequestContactInfoCallback(const BaseConnectionContactInfoInterface::RequestContactInfoCallback &cb) +{ + mPriv->requestContactInfoCB = cb; +} + +Tp::ContactInfoFieldList BaseConnectionContactInfoInterface::requestContactInfo(uint contact, DBusError *error) +{ + if (!mPriv->requestContactInfoCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return Tp::ContactInfoFieldList(); + } + return mPriv->requestContactInfoCB(contact, error); +} + +void BaseConnectionContactInfoInterface::setSetContactInfoCallback(const BaseConnectionContactInfoInterface::SetContactInfoCallback &cb) +{ + mPriv->setContactInfoCB = cb; +} + +void BaseConnectionContactInfoInterface::setContactInfo(const Tp::ContactInfoFieldList &contactInfo, DBusError *error) +{ + if (!mPriv->setContactInfoCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->setContactInfoCB(contactInfo, error); +} + +void BaseConnectionContactInfoInterface::contactInfoChanged(uint contact, const Tp::ContactInfoFieldList &contactInfo) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "contactInfoChanged", Q_ARG(uint, contact), Q_ARG(Tp::ContactInfoFieldList, contactInfo)); //Can simply use emit in Qt5 +} + // Conn.I.Addressing BaseConnectionAddressingInterface::Adaptee::Adaptee(BaseConnectionAddressingInterface *interface) : QObject(interface), diff --git a/TelepathyQt/base-connection.h b/TelepathyQt/base-connection.h index 56d5b654..2f9cd501 100644 --- a/TelepathyQt/base-connection.h +++ b/TelepathyQt/base-connection.h @@ -31,6 +31,7 @@ #include <TelepathyQt/Global> #include <TelepathyQt/Types> #include <TelepathyQt/Callbacks> +#include <TelepathyQt/Constants> #include <QDBusConnection> @@ -355,6 +356,64 @@ private: Private *mPriv; }; +class TP_QT_EXPORT BaseConnectionContactInfoInterface : public AbstractConnectionInterface +{ + Q_OBJECT + Q_DISABLE_COPY(BaseConnectionContactInfoInterface) + +public: + static BaseConnectionContactInfoInterfacePtr create() + { + return BaseConnectionContactInfoInterfacePtr(new BaseConnectionContactInfoInterface()); + } + template<typename BaseConnectionContactInfoInterfaceSubclass> + static SharedPtr<BaseConnectionContactInfoInterfaceSubclass> create() + { + return SharedPtr<BaseConnectionContactInfoInterfaceSubclass>( + new BaseConnectionContactInfoInterfaceSubclass()); + } + + virtual ~BaseConnectionContactInfoInterface(); + + QVariantMap immutableProperties() const; + + Tp::ContactInfoFlags contactInfoFlags() const; + void setContactInfoFlags(const Tp::ContactInfoFlags &contactInfoFlags); + + Tp::FieldSpecs supportedFields() const; + void setSupportedFields(const Tp::FieldSpecs &supportedFields); + + typedef Callback2<Tp::ContactInfoMap, const Tp::UIntList &, DBusError*> GetContactInfoCallback; + void setGetContactInfoCallback(const GetContactInfoCallback &cb); + Tp::ContactInfoMap getContactInfo(const Tp::UIntList &contacts, DBusError *error); + + typedef Callback2<void, const Tp::UIntList &, DBusError*> RefreshContactInfoCallback; + void setRefreshContactInfoCallback(const RefreshContactInfoCallback &cb); + void refreshContactInfo(const Tp::UIntList &contacts, DBusError *error); + + typedef Callback2<Tp::ContactInfoFieldList, uint, DBusError*> RequestContactInfoCallback; + void setRequestContactInfoCallback(const RequestContactInfoCallback &cb); + Tp::ContactInfoFieldList requestContactInfo(uint contact, DBusError *error); + + typedef Callback2<void, const Tp::ContactInfoFieldList &, DBusError*> SetContactInfoCallback; + void setSetContactInfoCallback(const SetContactInfoCallback &cb); + void setContactInfo(const Tp::ContactInfoFieldList &contactInfo, DBusError *error); + + void contactInfoChanged(uint contact, const Tp::ContactInfoFieldList &contactInfo); + +protected: + BaseConnectionContactInfoInterface(); + +private: + void createAdaptor(); + + class Adaptee; + friend class Adaptee; + struct Private; + friend struct Private; + Private *mPriv; +}; + class TP_QT_EXPORT BaseConnectionAddressingInterface : public AbstractConnectionInterface { Q_OBJECT diff --git a/TelepathyQt/service-types.h b/TelepathyQt/service-types.h index 158f11fa..199eb7cb 100644 --- a/TelepathyQt/service-types.h +++ b/TelepathyQt/service-types.h @@ -40,6 +40,7 @@ class BaseConnectionRequestsInterface; class BaseConnectionContactsInterface; class BaseConnectionSimplePresenceInterface; class BaseConnectionContactListInterface; +class BaseConnectionContactInfoInterface; class BaseConnectionAddressingInterface; class BaseConnectionAliasingInterface; class BaseConnectionManager; @@ -66,6 +67,7 @@ typedef SharedPtr<BaseConnectionRequestsInterface> BaseConnectionRequestsInterfa typedef SharedPtr<BaseConnectionContactsInterface> BaseConnectionContactsInterfacePtr; typedef SharedPtr<BaseConnectionSimplePresenceInterface> BaseConnectionSimplePresenceInterfacePtr; typedef SharedPtr<BaseConnectionContactListInterface> BaseConnectionContactListInterfacePtr; +typedef SharedPtr<BaseConnectionContactInfoInterface> BaseConnectionContactInfoInterfacePtr; typedef SharedPtr<BaseConnectionAddressingInterface> BaseConnectionAddressingInterfacePtr; typedef SharedPtr<BaseConnectionAliasingInterface> BaseConnectionAliasingInterfacePtr; typedef SharedPtr<BaseConnectionManager> BaseConnectionManagerPtr; |
