diff options
| author | Alexandr Akulich <akulichalexander@gmail.com> | 2016-04-28 20:11:07 +0500 |
|---|---|---|
| committer | Alexandr Akulich <akulichalexander@gmail.com> | 2016-05-05 17:03:08 +0500 |
| commit | 6e8d5f7aa14dbf868481b0a2995a041c5cf78d05 (patch) | |
| tree | 5e6c3d6431b96e4afe8cf521c874a7ce66b20ffa | |
| parent | a66aacabbe8f6a8a4e3bad5d0a9f730652e98479 (diff) | |
Added BaseConnectionClientTypesInterface.
Current design doesn't allow to delay DBus answers, so probably there
is a big problem with RequestClientTypes(), which is expected to "If
necessary, make a request to the server for up-to-date information,
and wait for a reply."
| -rw-r--r-- | TelepathyQt/base-connection-internal.h | 21 | ||||
| -rw-r--r-- | TelepathyQt/base-connection.cpp | 127 | ||||
| -rw-r--r-- | TelepathyQt/base-connection.h | 44 | ||||
| -rw-r--r-- | TelepathyQt/service-types.h | 2 |
4 files changed, 194 insertions, 0 deletions
diff --git a/TelepathyQt/base-connection-internal.h b/TelepathyQt/base-connection-internal.h index 6b97237b..4cc45004 100644 --- a/TelepathyQt/base-connection-internal.h +++ b/TelepathyQt/base-connection-internal.h @@ -320,6 +320,27 @@ private: BaseConnectionAvatarsInterface *mInterface; }; +class TP_QT_NO_EXPORT BaseConnectionClientTypesInterface::Adaptee : public QObject +{ + Q_OBJECT + +public: + Adaptee(BaseConnectionClientTypesInterface *interface); + ~Adaptee(); + +private Q_SLOTS: + void getClientTypes(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceClientTypesAdaptor::GetClientTypesContextPtr &context); + void requestClientTypes(uint contact, + const Tp::Service::ConnectionInterfaceClientTypesAdaptor::RequestClientTypesContextPtr &context); + +Q_SIGNALS: + void clientTypesUpdated(uint contact, const QStringList &clientTypes); + +private: + BaseConnectionClientTypesInterface *mInterface; +}; + class TP_QT_NO_EXPORT BaseConnectionContactCapabilitiesInterface::Adaptee : public QObject { Q_OBJECT diff --git a/TelepathyQt/base-connection.cpp b/TelepathyQt/base-connection.cpp index 7377f658..b9999faa 100644 --- a/TelepathyQt/base-connection.cpp +++ b/TelepathyQt/base-connection.cpp @@ -2395,6 +2395,133 @@ void BaseConnectionAvatarsInterface::avatarRetrieved(uint contact, const QString QMetaObject::invokeMethod(mPriv->adaptee, "avatarRetrieved", Q_ARG(uint, contact), Q_ARG(QString, token), Q_ARG(QByteArray, avatar), Q_ARG(QString, type)); //Can simply use emit in Qt5 } +// Conn.I.ClientTypes +// The BaseConnectionClientTypesInterface code is fully or partially generated by the TelepathyQt-Generator. +struct TP_QT_NO_EXPORT BaseConnectionClientTypesInterface::Private { + Private(BaseConnectionClientTypesInterface *parent) + : adaptee(new BaseConnectionClientTypesInterface::Adaptee(parent)) + { + } + + GetClientTypesCallback getClientTypesCB; + RequestClientTypesCallback requestClientTypesCB; + BaseConnectionClientTypesInterface::Adaptee *adaptee; +}; + +BaseConnectionClientTypesInterface::Adaptee::Adaptee(BaseConnectionClientTypesInterface *interface) + : QObject(interface), + mInterface(interface) +{ +} + +BaseConnectionClientTypesInterface::Adaptee::~Adaptee() +{ +} + +void BaseConnectionClientTypesInterface::Adaptee::getClientTypes(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceClientTypesAdaptor::GetClientTypesContextPtr &context) +{ + debug() << "BaseConnectionClientTypesInterface::Adaptee::getClientTypes"; + DBusError error; + Tp::ContactClientTypes clientTypes = mInterface->getClientTypes(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(clientTypes); +} + +void BaseConnectionClientTypesInterface::Adaptee::requestClientTypes(uint contact, + const Tp::Service::ConnectionInterfaceClientTypesAdaptor::RequestClientTypesContextPtr &context) +{ + debug() << "BaseConnectionClientTypesInterface::Adaptee::requestClientTypes"; + DBusError error; + QStringList clientTypes = mInterface->requestClientTypes(contact, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(clientTypes); +} + +/** + * \class BaseConnectionClientTypesInterface + * \ingroup serviceconn + * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> + * + * \brief Base class for implementations of Connection.Interface.ClientTypes + */ + +/** + * Class constructor. + */ +BaseConnectionClientTypesInterface::BaseConnectionClientTypesInterface() + : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_INTERFACE_CLIENT_TYPES), + mPriv(new Private(this)) +{ +} + +/** + * Class destructor. + */ +BaseConnectionClientTypesInterface::~BaseConnectionClientTypesInterface() +{ + 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 BaseConnectionClientTypesInterface::immutableProperties() const +{ + QVariantMap map; + return map; +} + +void BaseConnectionClientTypesInterface::createAdaptor() +{ + (void) new Tp::Service::ConnectionInterfaceClientTypesAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + +void BaseConnectionClientTypesInterface::setGetClientTypesCallback(const GetClientTypesCallback &cb) +{ + mPriv->getClientTypesCB = cb; +} + +Tp::ContactClientTypes BaseConnectionClientTypesInterface::getClientTypes(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->getClientTypesCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return Tp::ContactClientTypes(); + } + return mPriv->getClientTypesCB(contacts, error); +} + +void BaseConnectionClientTypesInterface::setRequestClientTypesCallback(const RequestClientTypesCallback &cb) +{ + mPriv->requestClientTypesCB = cb; +} + +QStringList BaseConnectionClientTypesInterface::requestClientTypes(uint contact, DBusError *error) +{ + if (!mPriv->requestClientTypesCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return QStringList(); + } + return mPriv->requestClientTypesCB(contact, error); +} + +void BaseConnectionClientTypesInterface::clientTypesUpdated(uint contact, const QStringList &clientTypes) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "clientTypesUpdated", Q_ARG(uint, contact), Q_ARG(QStringList, clientTypes)); //Can simply use emit in Qt5 +} + // Conn.I.ContactCapabilities // The BaseConnectionContactCapabilitiesInterface code is fully or partially generated by the TelepathyQt-Generator. struct TP_QT_NO_EXPORT BaseConnectionContactCapabilitiesInterface::Private { diff --git a/TelepathyQt/base-connection.h b/TelepathyQt/base-connection.h index 7cf98b8e..1d2d124a 100644 --- a/TelepathyQt/base-connection.h +++ b/TelepathyQt/base-connection.h @@ -574,6 +574,50 @@ private: Private *mPriv; }; +class TP_QT_EXPORT BaseConnectionClientTypesInterface : public AbstractConnectionInterface +{ + Q_OBJECT + Q_DISABLE_COPY(BaseConnectionClientTypesInterface) + +public: + static BaseConnectionClientTypesInterfacePtr create() + { + return BaseConnectionClientTypesInterfacePtr(new BaseConnectionClientTypesInterface()); + } + template<typename BaseConnectionClientTypesInterfaceSubclass> + static SharedPtr<BaseConnectionClientTypesInterfaceSubclass> create() + { + return SharedPtr<BaseConnectionClientTypesInterfaceSubclass>( + new BaseConnectionClientTypesInterfaceSubclass()); + } + + virtual ~BaseConnectionClientTypesInterface(); + + QVariantMap immutableProperties() const; + + typedef Callback2<Tp::ContactClientTypes, const Tp::UIntList &, DBusError*> GetClientTypesCallback; + void setGetClientTypesCallback(const GetClientTypesCallback &cb); + Tp::ContactClientTypes getClientTypes(const Tp::UIntList &contacts, DBusError *error); + + typedef Callback2<QStringList, uint, DBusError*> RequestClientTypesCallback; + void setRequestClientTypesCallback(const RequestClientTypesCallback &cb); + QStringList requestClientTypes(uint contact, DBusError *error); + + void clientTypesUpdated(uint contact, const QStringList &clientTypes); + +protected: + BaseConnectionClientTypesInterface(); + +private: + void createAdaptor(); + + class Adaptee; + friend class Adaptee; + struct Private; + friend struct Private; + Private *mPriv; +}; + class TP_QT_EXPORT BaseConnectionContactCapabilitiesInterface : public AbstractConnectionInterface { Q_OBJECT diff --git a/TelepathyQt/service-types.h b/TelepathyQt/service-types.h index 96d0a29c..b9627933 100644 --- a/TelepathyQt/service-types.h +++ b/TelepathyQt/service-types.h @@ -48,6 +48,7 @@ class BaseConnectionContactInfoInterface; class BaseConnectionAddressingInterface; class BaseConnectionAliasingInterface; class BaseConnectionAvatarsInterface; +class BaseConnectionClientTypesInterface; class BaseConnectionContactCapabilitiesInterface; class BaseConnectionManager; class BaseProtocol; @@ -93,6 +94,7 @@ typedef SharedPtr<BaseConnectionContactInfoInterface> BaseConnectionContactInfoI typedef SharedPtr<BaseConnectionAddressingInterface> BaseConnectionAddressingInterfacePtr; typedef SharedPtr<BaseConnectionAliasingInterface> BaseConnectionAliasingInterfacePtr; typedef SharedPtr<BaseConnectionAvatarsInterface> BaseConnectionAvatarsInterfacePtr; +typedef SharedPtr<BaseConnectionClientTypesInterface> BaseConnectionClientTypesInterfacePtr; typedef SharedPtr<BaseConnectionContactCapabilitiesInterface> BaseConnectionContactCapabilitiesInterfacePtr; typedef SharedPtr<BaseConnectionManager> BaseConnectionManagerPtr; typedef SharedPtr<BaseProtocol> BaseProtocolPtr; |
