diff options
Diffstat (limited to 'TelepathyQt/base-connection.cpp')
-rw-r--r-- | TelepathyQt/base-connection.cpp | 2122 |
1 files changed, 1820 insertions, 302 deletions
diff --git a/TelepathyQt/base-connection.cpp b/TelepathyQt/base-connection.cpp index 870e23fd..af6334f9 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> @@ -40,30 +39,32 @@ namespace Tp { struct TP_QT_NO_EXPORT BaseConnection::Private { - Private(BaseConnection *parent, const QDBusConnection &dbusConnection, + Private(BaseConnection *connection, const QDBusConnection &dbusConnection, const QString &cmName, const QString &protocolName, const QVariantMap ¶meters) - : parent(parent), + : connection(connection), cmName(cmName), protocolName(protocolName), parameters(parameters), - status(Tp::ConnectionStatusDisconnected), selfHandle(0), - adaptee(new BaseConnection::Adaptee(dbusConnection, parent)) { + status(Tp::ConnectionStatusDisconnected), + adaptee(new BaseConnection::Adaptee(dbusConnection, connection)) + { } - BaseConnection *parent; + BaseConnection *connection; QString cmName; QString protocolName; QVariantMap parameters; - uint status; QHash<QString, AbstractConnectionInterfacePtr> interfaces; QSet<BaseChannelPtr> channels; + uint selfHandle; + QString selfID; + uint status; CreateChannelCallback createChannelCB; - RequestHandlesCallback requestHandlesCB; ConnectCallback connectCB; InspectHandlesCallback inspectHandlesCB; - uint selfHandle; + RequestHandlesCallback requestHandlesCB; BaseConnection::Adaptee *adaptee; }; @@ -79,28 +80,36 @@ BaseConnection::Adaptee::~Adaptee() { } -void BaseConnection::Adaptee::disconnect(const Tp::Service::ConnectionAdaptor::DisconnectContextPtr &context) +QStringList BaseConnection::Adaptee::interfaces() const { - debug() << "BaseConnection::Adaptee::disconnect"; - /* This will remove the connection from the connection manager - * and destroy this object. */ - emit mConnection->disconnected(); - context->setFinished(); + QStringList ret; + foreach(const AbstractConnectionInterfacePtr &iface, mConnection->interfaces()) { + ret << iface->interfaceName(); + } + return ret; } -void BaseConnection::Adaptee::getSelfHandle(const Tp::Service::ConnectionAdaptor::GetSelfHandleContextPtr &context) +uint BaseConnection::Adaptee::selfHandle() const { - context->setFinished(mConnection->mPriv->selfHandle); + return mConnection->selfHandle(); } -uint BaseConnection::Adaptee::selfHandle() const +QString BaseConnection::Adaptee::selfID() const { - return mConnection->mPriv->selfHandle; + return mConnection->selfID(); } -void BaseConnection::Adaptee::getStatus(const Tp::Service::ConnectionAdaptor::GetStatusContextPtr &context) +uint BaseConnection::Adaptee::status() const { - context->setFinished(mConnection->status()); + return mConnection->status(); +} + +bool BaseConnection::Adaptee::hasImmortalHandles() const +{ + /* True if handles last for the whole lifetime of the Connection. + * This SHOULD be the case in all connection managers, but connection managers + * MUST interoperate with older clients (which reference-count handles). */ + return true; } void BaseConnection::Adaptee::connect(const Tp::Service::ConnectionAdaptor::ConnectContextPtr &context) @@ -118,29 +127,66 @@ void BaseConnection::Adaptee::connect(const Tp::Service::ConnectionAdaptor::Conn context->setFinished(); } +void BaseConnection::Adaptee::disconnect(const Tp::Service::ConnectionAdaptor::DisconnectContextPtr &context) +{ + debug() << "BaseConnection::Adaptee::disconnect"; + + foreach(const BaseChannelPtr &channel, mConnection->mPriv->channels) { + /* BaseChannel::closed() signal triggers removeChannel() method call with proper cleanup */ + channel->close(); + } + + /* This signal will remove the connection from the connection manager + * and destroy this object. */ + emit mConnection->disconnected(); + + context->setFinished(); +} + +void BaseConnection::Adaptee::getInterfaces(const Service::ConnectionAdaptor::GetInterfacesContextPtr &context) +{ + context->setFinished(interfaces()); +} + +void BaseConnection::Adaptee::getProtocol(const Service::ConnectionAdaptor::GetProtocolContextPtr &context) +{ + context->setFinished(mConnection->protocolName()); +} + +void BaseConnection::Adaptee::getSelfHandle(const Service::ConnectionAdaptor::GetSelfHandleContextPtr &context) +{ + context->setFinished(mConnection->selfHandle()); +} + +void BaseConnection::Adaptee::getStatus(const Tp::Service::ConnectionAdaptor::GetStatusContextPtr &context) +{ + context->setFinished(mConnection->status()); +} + +void BaseConnection::Adaptee::holdHandles(uint handleType, const UIntList &handles, const Service::ConnectionAdaptor::HoldHandlesContextPtr &context) +{ + // This method no does anything since 0.21.6 + Q_UNUSED(handleType) + Q_UNUSED(handles) + context->setFinished(); +} + void BaseConnection::Adaptee::inspectHandles(uint handleType, const Tp::UIntList &handles, const Tp::Service::ConnectionAdaptor::InspectHandlesContextPtr &context) { - if (!mConnection->mPriv->inspectHandlesCB.isValid()) { - context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); - return; - } DBusError error; - QStringList ret = mConnection->mPriv->inspectHandlesCB(handleType, handles, &error); + QStringList identifiers = mConnection->inspectHandles(handleType, handles, &error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } - context->setFinished(ret); + context->setFinished(identifiers); } -QStringList BaseConnection::Adaptee::interfaces() const + +void BaseConnection::Adaptee::listChannels(const Service::ConnectionAdaptor::ListChannelsContextPtr &context) { - QStringList ret; - foreach(const AbstractConnectionInterfacePtr & iface, mConnection->interfaces()) { - ret << iface->interfaceName(); - } - return ret; + context->setFinished(mConnection->channelsInfo()); } void BaseConnection::Adaptee::requestChannel(const QString &type, uint handleType, uint handle, bool suppressHandler, @@ -148,14 +194,14 @@ void BaseConnection::Adaptee::requestChannel(const QString &type, uint handleTyp { debug() << "BaseConnection::Adaptee::requestChannel (deprecated)"; DBusError error; + + QVariantMap request; + request[TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")] = type; + request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")] = handleType; + request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")] = handle; + bool yours; - BaseChannelPtr channel = mConnection->ensureChannel(type, - handleType, - handle, - yours, - selfHandle(), - suppressHandler, - &error); + BaseChannelPtr channel = mConnection->ensureChannel(request, yours, suppressHandler, &error); if (error.isValid() || !channel) { context->setFinishedWithError(error.name(), error.message()); return; @@ -163,6 +209,14 @@ void BaseConnection::Adaptee::requestChannel(const QString &type, uint handleTyp context->setFinished(QDBusObjectPath(channel->objectPath())); } +void BaseConnection::Adaptee::releaseHandles(uint handleType, const UIntList &handles, const Service::ConnectionAdaptor::ReleaseHandlesContextPtr &context) +{ + // This method no does anything since 0.21.6 + Q_UNUSED(handleType) + Q_UNUSED(handles) + context->setFinished(); +} + void BaseConnection::Adaptee::requestHandles(uint handleType, const QStringList &identifiers, const Tp::Service::ConnectionAdaptor::RequestHandlesContextPtr &context) { @@ -204,6 +258,10 @@ BaseConnection::BaseConnection(const QDBusConnection &dbusConnection, */ BaseConnection::~BaseConnection() { + foreach (BaseChannelPtr channel, mPriv->channels) { + channel->close(); + } + delete mPriv; } @@ -247,18 +305,54 @@ QVariantMap BaseConnection::parameters() const */ QVariantMap BaseConnection::immutableProperties() const { - // FIXME + // There is no immutable properties. return QVariantMap(); } -/** - * Return a unique name for this connection. - * - * \return A unique name for this connection. - */ -QString BaseConnection::uniqueName() const +uint BaseConnection::selfHandle() const +{ + return mPriv->selfHandle; +} + +void BaseConnection::setSelfHandle(uint selfHandle) +{ + if (selfHandle == mPriv->selfHandle) { + return; + } + + mPriv->selfHandle = selfHandle; + QMetaObject::invokeMethod(mPriv->adaptee, "selfHandleChanged", Q_ARG(uint, mPriv->selfHandle)); //Can simply use emit in Qt5 + QMetaObject::invokeMethod(mPriv->adaptee, "selfContactChanged", Q_ARG(uint, mPriv->selfHandle), Q_ARG(QString, mPriv->selfID)); //Can simply use emit in Qt5 +} + +QString BaseConnection::selfID() const { - return QString(QLatin1String("_%1")).arg((quintptr) this, 0, 16); + return mPriv->selfID; +} + +void BaseConnection::setSelfID(const QString &selfID) +{ + if (selfID == mPriv->selfID) { + return; + } + + mPriv->selfID = selfID; + QMetaObject::invokeMethod(mPriv->adaptee, "selfContactChanged", Q_ARG(uint, mPriv->selfHandle), Q_ARG(QString, mPriv->selfID)); //Can simply use emit in Qt5 +} + +void BaseConnection::setSelfContact(uint selfHandle, const QString &selfID) +{ + if ((selfHandle == mPriv->selfHandle) && (selfID == mPriv->selfID)) { + return; + } + + if (selfHandle != mPriv->selfHandle) { + QMetaObject::invokeMethod(mPriv->adaptee, "selfHandleChanged", Q_ARG(uint, mPriv->selfHandle)); //Can simply use emit in Qt5 + mPriv->selfHandle = selfHandle; + } + + mPriv->selfID = selfID; + QMetaObject::invokeMethod(mPriv->adaptee, "selfContactChanged", Q_ARG(uint, mPriv->selfHandle), Q_ARG(QString, mPriv->selfID)); //Can simply use emit in Qt5 } uint BaseConnection::status() const @@ -281,12 +375,7 @@ void BaseConnection::setCreateChannelCallback(const CreateChannelCallback &cb) mPriv->createChannelCB = cb; } -Tp::BaseChannelPtr BaseConnection::createChannel(const QString &channelType, - uint targetHandleType, - uint targetHandle, - uint initiatorHandle, - bool suppressHandler, - DBusError *error) +Tp::BaseChannelPtr BaseConnection::createChannel(const QVariantMap &request, bool suppressHandler, DBusError *error) { if (!mPriv->createChannelCB.isValid()) { error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); @@ -297,67 +386,75 @@ Tp::BaseChannelPtr BaseConnection::createChannel(const QString &channelType, return BaseChannelPtr(); } - BaseChannelPtr channel = mPriv->createChannelCB(channelType, targetHandleType, targetHandle, error); + if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".Requested"))) { + error->set(TP_QT_ERROR_INVALID_ARGUMENT, QString(QLatin1String("The %1.Requested property must not be presented in the request details.")).arg(TP_QT_IFACE_CHANNEL)); + return BaseChannelPtr(); + } + + QVariantMap requestDetails = request; + requestDetails[TP_QT_IFACE_CHANNEL + QLatin1String(".Requested")] = suppressHandler; + + BaseChannelPtr channel = mPriv->createChannelCB(requestDetails, error); if (error->isValid()) return BaseChannelPtr(); - QString targetID; - if (targetHandle != 0) { - QStringList list = mPriv->inspectHandlesCB(targetHandleType, UIntList() << targetHandle, error); + QString targetID = channel->targetID(); + if ((channel->targetHandle() != 0) && targetID.isEmpty()) { + QStringList list = mPriv->inspectHandlesCB(channel->targetHandleType(), UIntList() << channel->targetHandle(), error); if (error->isValid()) { - debug() << "BaseConnection::createChannel: could not resolve handle " << targetHandle; + debug() << "BaseConnection::createChannel: could not resolve handle " << channel->targetHandle(); return BaseChannelPtr(); } else { debug() << "BaseConnection::createChannel: found targetID " << *list.begin(); targetID = *list.begin(); } + channel->setTargetID(targetID); } - QString initiatorID; - if (initiatorHandle != 0) { - QStringList list = mPriv->inspectHandlesCB(HandleTypeContact, UIntList() << initiatorHandle, error); + + if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".InitiatorHandle"))) { + channel->setInitiatorHandle(request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".InitiatorHandle")).toUInt()); + } + + QString initiatorID = channel->initiatorID(); + if ((channel->initiatorHandle() != 0) && initiatorID.isEmpty()) { + QStringList list = mPriv->inspectHandlesCB(HandleTypeContact, UIntList() << channel->initiatorHandle(), error); if (error->isValid()) { - debug() << "BaseConnection::createChannel: could not resolve handle " << initiatorHandle; + debug() << "BaseConnection::createChannel: could not resolve handle " << channel->initiatorHandle(); return BaseChannelPtr(); } else { debug() << "BaseConnection::createChannel: found initiatorID " << *list.begin(); initiatorID = *list.begin(); } + channel->setInitiatorID(initiatorID); } - channel->setInitiatorHandle(initiatorHandle); - channel->setInitiatorID(initiatorID); - channel->setTargetID(targetID); - channel->setRequested(initiatorHandle == mPriv->selfHandle); + channel->setRequested(suppressHandler); channel->registerObject(error); if (error->isValid()) return BaseChannelPtr(); - mPriv->channels.insert(channel); - - BaseConnectionRequestsInterfacePtr reqIface = - BaseConnectionRequestsInterfacePtr::dynamicCast(interface(TP_QT_IFACE_CONNECTION_INTERFACE_REQUESTS)); - - if (!reqIface.isNull()) - //emit after return - QMetaObject::invokeMethod(reqIface.data(), "newChannels", - Qt::QueuedConnection, - Q_ARG(Tp::ChannelDetailsList, ChannelDetailsList() << channel->details())); + addChannel(channel, suppressHandler); + return channel; +} - //emit after return - QMetaObject::invokeMethod(mPriv->adaptee, "newChannel", - Qt::QueuedConnection, - Q_ARG(QDBusObjectPath, QDBusObjectPath(channel->objectPath())), - Q_ARG(QString, channel->channelType()), - Q_ARG(uint, channel->targetHandleType()), - Q_ARG(uint, channel->targetHandle()), - Q_ARG(bool, suppressHandler)); +void BaseConnection::setConnectCallback(const ConnectCallback &cb) +{ + mPriv->connectCB = cb; +} - QObject::connect(channel.data(), - SIGNAL(closed()), - SLOT(removeChannel())); +void BaseConnection::setInspectHandlesCallback(const InspectHandlesCallback &cb) +{ + mPriv->inspectHandlesCB = cb; +} - return channel; +QStringList BaseConnection::inspectHandles(uint handleType, const Tp::UIntList &handles, DBusError *error) +{ + if (!mPriv->inspectHandlesCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return QStringList(); + } + return mPriv->inspectHandlesCB(handleType, handles, error); } void BaseConnection::setRequestHandlesCallback(const RequestHandlesCallback &cb) @@ -365,18 +462,18 @@ void BaseConnection::setRequestHandlesCallback(const RequestHandlesCallback &cb) mPriv->requestHandlesCB = cb; } -UIntList BaseConnection::requestHandles(uint handleType, const QStringList &identifiers, DBusError* error) +Tp::UIntList BaseConnection::requestHandles(uint handleType, const QStringList &identifiers, DBusError *error) { if (!mPriv->requestHandlesCB.isValid()) { error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); - return UIntList(); + return Tp::UIntList(); } return mPriv->requestHandlesCB(handleType, identifiers, error); } Tp::ChannelInfoList BaseConnection::channelsInfo() { - qDebug() << "BaseConnection::channelsInfo:"; + debug() << "BaseConnection::channelsInfo:"; Tp::ChannelInfoList list; foreach(const BaseChannelPtr & c, mPriv->channels) { Tp::ChannelInfo info; @@ -384,7 +481,7 @@ Tp::ChannelInfoList BaseConnection::channelsInfo() info.channelType = c->channelType(); info.handle = c->targetHandle(); info.handleType = c->targetHandleType(); - qDebug() << "BaseConnection::channelsInfo " << info.channel.path(); + debug() << "BaseConnection::channelsInfo " << info.channel.path(); list << info; } return list; @@ -398,21 +495,113 @@ Tp::ChannelDetailsList BaseConnection::channelsDetails() return list; } -BaseChannelPtr BaseConnection::ensureChannel(const QString &channelType, uint targetHandleType, - uint targetHandle, bool &yours, uint initiatorHandle, - bool suppressHandler, - DBusError* error) +/** + * \fn Tp::BaseChannelPtr BaseConnection::getExistingChannel(const QVariantMap &request, DBusError *error) + * + * Returns an existing channel satisfying the given \a request or a null pointer if such a channel does not exist. + * + * This method iterates over the existing channels and calls matchChannel() to find the one satisfying the \a request. + * + * If \a error is passed, any error that may occur will be stored there. + * + * \param request A dictionary containing the desirable properties. + * \param error A pointer to an empty DBusError where any possible error will be stored. + * \return A pointer to a channel satisfying the given \a request or a null pointer. + * \sa matchChannel() + */ +Tp::BaseChannelPtr BaseConnection::getExistingChannel(const QVariantMap &request, DBusError *error) { - foreach(BaseChannelPtr channel, mPriv->channels) { - if (channel->channelType() == channelType - && channel->targetHandleType() == targetHandleType - && channel->targetHandle() == targetHandle) { - yours = false; + if (!request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"))) { + error->set(TP_QT_ERROR_INVALID_ARGUMENT, QLatin1String("Missing parameters")); + return Tp::BaseChannelPtr(); + } + + const QString channelType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")).toString(); + + foreach(const BaseChannelPtr &channel, mPriv->channels) { + if (channel->channelType() != channelType) { + continue; + } + + bool match = matchChannel(channel, request, error); + + if (error->isValid()) { + return BaseChannelPtr(); + } + + if (match) { return channel; } } + + return Tp::BaseChannelPtr(); +} + +/** + * \fn Tp::BaseChannelPtr BaseConnection::ensureChannel(const QVariantMap &request, bool &yours, bool suppressHandler, DBusError *error) + * + * Returns a new or existing channel satisfying the given \a request. + * + * This method uses getExistingChannel() to find one satisfying the \a request. If there is no + * suitable channel, then a new channel with the given request details will be created. + * + * If \a error is passed, any error that may occur will be stored there. + * + * \param request A dictionary containing the desirable properties. + * \param yours A returning argument. \c true if returned channel is a new one and \c false otherwise. + * \param suppressHandler An option to suppress handler in case of a new channel creation. + * \param error A pointer to an empty DBusError where any possible error will be stored. + * \return A pointer to a channel satisfying the given \a request. + * \sa getExistingChannel() + */ +Tp::BaseChannelPtr BaseConnection::ensureChannel(const QVariantMap &request, bool &yours, bool suppressHandler, DBusError *error) +{ + if (!request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"))) { + error->set(TP_QT_ERROR_INVALID_ARGUMENT, QLatin1String("Missing parameters")); + return Tp::BaseChannelPtr(); + } + + Tp::BaseChannelPtr existingChannel = getExistingChannel(request, error); + if (existingChannel) { + yours = false; + return existingChannel; + } + yours = true; - return createChannel(channelType, targetHandleType, targetHandle, initiatorHandle, suppressHandler, error); + return createChannel(request, suppressHandler, error); +} + +void BaseConnection::addChannel(BaseChannelPtr channel, bool suppressHandler) +{ + if (mPriv->channels.contains(channel)) { + warning() << "BaseConnection::addChannel: Channel already added."; + return; + } + + mPriv->channels.insert(channel); + + BaseConnectionRequestsInterfacePtr reqIface = + BaseConnectionRequestsInterfacePtr::dynamicCast(interface(TP_QT_IFACE_CONNECTION_INTERFACE_REQUESTS)); + + if (!reqIface.isNull()) { + //emit after return + QMetaObject::invokeMethod(reqIface.data(), "newChannels", + Qt::QueuedConnection, + Q_ARG(Tp::ChannelDetailsList, ChannelDetailsList() << channel->details())); + } + + //emit after return + QMetaObject::invokeMethod(mPriv->adaptee, "newChannel", + Qt::QueuedConnection, + Q_ARG(QDBusObjectPath, QDBusObjectPath(channel->objectPath())), + Q_ARG(QString, channel->channelType()), + Q_ARG(uint, channel->targetHandleType()), + Q_ARG(uint, channel->targetHandle()), + Q_ARG(bool, suppressHandler)); + + QObject::connect(channel.data(), + SIGNAL(closed()), + SLOT(removeChannel())); } void BaseConnection::removeChannel() @@ -421,6 +610,14 @@ void BaseConnection::removeChannel() qobject_cast<BaseChannel*>(sender())); Q_ASSERT(channel); Q_ASSERT(mPriv->channels.contains(channel)); + + BaseConnectionRequestsInterfacePtr reqIface = + BaseConnectionRequestsInterfacePtr::dynamicCast(interface(TP_QT_IFACE_CONNECTION_INTERFACE_REQUESTS)); + + if (!reqIface.isNull()) { + reqIface->channelClosed(QDBusObjectPath(channel->objectPath())); + } + mPriv->channels.remove(channel); } @@ -487,6 +684,7 @@ bool BaseConnection::plugInterface(const AbstractConnectionInterfacePtr &interfa debug() << "Interface" << interface->interfaceName() << "plugged"; mPriv->interfaces.insert(interface->interfaceName(), interface); + interface->setBaseConnection(this); return true; } @@ -544,6 +742,16 @@ bool BaseConnection::registerObject(DBusError *error) } /** + * Return a unique name for this connection. + * + * \return A unique name for this connection. + */ +QString BaseConnection::uniqueName() const +{ + return QString(QLatin1String("connection_%1")).arg((quintptr) this, 0, 16); +} + +/** * Reimplemented from DBusService. */ bool BaseConnection::registerObject(const QString &busName, @@ -552,24 +760,47 @@ bool BaseConnection::registerObject(const QString &busName, return DBusService::registerObject(busName, objectPath, error); } -void BaseConnection::setSelfHandle(uint selfHandle) -{ - mPriv->selfHandle = selfHandle; -} - -uint BaseConnection::selfHandle() const +/** + * \fn bool BaseConnection::matchChannel(const BaseChannelPtr &channel, const QVariantMap &request, DBusError *error) + * + * Check \a channel on conformity with \a request. + * + * This virtual method is used to check if a \a channel satisfying the given request. + * It is warranted, that the type of the channel meets the requested type. + * + * The default implementation compares TargetHandleType and TargetHandle/TargetID. + * If \a error is passed, any error that may occur will be stored there. + * + * \param channel A pointer to a channel to be checked. + * \param request A dictionary containing the desirable properties. + * \param error A pointer to an empty DBusError where any + * possible error will be stored. + * \return \c true if channel match the request and \c false otherwise. + * \sa ensureChannel() + */ +bool BaseConnection::matchChannel(const BaseChannelPtr &channel, const QVariantMap &request, DBusError *error) { - return mPriv->selfHandle; -} + Q_UNUSED(error); -void BaseConnection::setConnectCallback(const ConnectCallback &cb) -{ - mPriv->connectCB = cb; -} + if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType"))) { + uint targetHandleType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")).toUInt(); + if (channel->targetHandleType() != targetHandleType) { + return false; + } + if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle"))) { + uint targetHandle = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")).toUInt(); + return channel->targetHandle() == targetHandle; + } else if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetID"))) { + const QString targetID = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetID")).toString(); + return channel->targetID() == targetID; + } else { + // Request is not valid + return false; + } + } -void BaseConnection::setInspectHandlesCallback(const InspectHandlesCallback &cb) -{ - mPriv->inspectHandlesCB = cb; + // Unknown request + return false; } /** @@ -580,7 +811,7 @@ void BaseConnection::setInspectHandlesCallback(const InspectHandlesCallback &cb) /** * \class AbstractConnectionInterface - * \ingroup servicecm + * \ingroup serviceconn * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> * * \brief Base class for all the Connection object interface implementations. @@ -595,6 +826,11 @@ AbstractConnectionInterface::~AbstractConnectionInterface() { } +void AbstractConnectionInterface::setBaseConnection(BaseConnection *connection) +{ + Q_UNUSED(connection) +} + // Conn.I.Requests BaseConnectionRequestsInterface::Adaptee::Adaptee(BaseConnectionRequestsInterface *interface) : QObject(interface), @@ -647,7 +883,7 @@ struct TP_QT_NO_EXPORT BaseConnectionRequestsInterface::Private { /** * \class BaseConnectionRequestsInterface - * \ingroup servicecm + * \ingroup serviceconn * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> * * \brief Base class for implementations of Connection.Interface.Requests @@ -702,38 +938,16 @@ void BaseConnectionRequestsInterface::newChannels(const Tp::ChannelDetailsList & QMetaObject::invokeMethod(mPriv->adaptee,"newChannels", Q_ARG(Tp::ChannelDetailsList,channels)); //Can replace by a direct call in Qt5 } +void BaseConnectionRequestsInterface::channelClosed(const QDBusObjectPath &removed) +{ + QMetaObject::invokeMethod(mPriv->adaptee,"channelClosed", Q_ARG(QDBusObjectPath, removed)); //Can replace by a direct call in Qt5 +} + void BaseConnectionRequestsInterface::ensureChannel(const QVariantMap &request, bool &yours, QDBusObjectPath &objectPath, QVariantMap &details, DBusError *error) { - if (!request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")) - || !request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")) - || (!request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")) - && !request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetID")))) { - error->set(TP_QT_ERROR_INVALID_ARGUMENT, QLatin1String("Missing parameters")); - return; - } - - QString channelType = request[TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")].toString(); - uint targetHandleType = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")].toUInt(); - uint targetHandle; - if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle"))) - targetHandle = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")].toUInt(); - else { - QString targetID = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetID")].toString(); - Tp::UIntList list = mPriv->connection->requestHandles(targetHandleType, QStringList() << targetID, error); - if (error->isValid()) { - warning() << "BBaseConnectionRequestsInterface::ensureChannel: could not resolve ID " << targetID; - return; - } - targetHandle = *list.begin(); - } + BaseChannelPtr channel = mPriv->connection->ensureChannel(request, yours, /* suppressHandler */ true, error); - bool suppressHandler = true; - BaseChannelPtr channel = mPriv->connection->ensureChannel(channelType, targetHandleType, - targetHandle, yours, - mPriv->connection->selfHandle(), - suppressHandler, - error); if (error->isValid()) return; @@ -745,23 +959,13 @@ void BaseConnectionRequestsInterface::createChannel(const QVariantMap &request, QDBusObjectPath &objectPath, QVariantMap &details, DBusError *error) { - if (!request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")) - || !request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")) - || !request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"))) { + if (!request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"))) { error->set(TP_QT_ERROR_INVALID_ARGUMENT, QLatin1String("Missing parameters")); return; } - QString channelType = request[TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")].toString(); - uint targetHandleType = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")].toUInt(); - uint targetHandle = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")].toUInt(); + BaseChannelPtr channel = mPriv->connection->createChannel(request, /* suppressHandler */ true, error); - bool suppressHandler = true; - BaseChannelPtr channel = mPriv->connection->createChannel(channelType, targetHandleType, - targetHandle, - mPriv->connection->selfHandle(), - suppressHandler, - error); if (error->isValid()) return; @@ -769,8 +973,21 @@ void BaseConnectionRequestsInterface::createChannel(const QVariantMap &request, details = channel->details().properties; } - // Conn.I.Contacts +// The BaseConnectionContactsInterface code is fully or partially generated by the TelepathyQt-Generator. +struct TP_QT_NO_EXPORT BaseConnectionContactsInterface::Private { + Private(BaseConnectionContactsInterface *parent) + : connection(nullptr), + adaptee(new BaseConnectionContactsInterface::Adaptee(parent)) + { + } + + QStringList contactAttributeInterfaces; + GetContactAttributesCallback getContactAttributesCB; + BaseConnection *connection; + BaseConnectionContactsInterface::Adaptee *adaptee; +}; + BaseConnectionContactsInterface::Adaptee::Adaptee(BaseConnectionContactsInterface *interface) : QObject(interface), mInterface(interface) @@ -781,36 +998,42 @@ BaseConnectionContactsInterface::Adaptee::~Adaptee() { } -void BaseConnectionContactsInterface::Adaptee::getContactAttributes(const Tp::UIntList &handles, - const QStringList &interfaces, bool /*hold*/, +QStringList BaseConnectionContactsInterface::Adaptee::contactAttributeInterfaces() const +{ + return mInterface->contactAttributeInterfaces(); +} + +void BaseConnectionContactsInterface::Adaptee::getContactAttributes(const Tp::UIntList &handles, const QStringList &interfaces, bool /* hold */, const Tp::Service::ConnectionInterfaceContactsAdaptor::GetContactAttributesContextPtr &context) { DBusError error; - ContactAttributesMap contactAttributes = mInterface->getContactAttributes(handles, interfaces, &error); + Tp::ContactAttributesMap attributes = mInterface->getContactAttributes(handles, interfaces, &error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } - context->setFinished(contactAttributes); + context->setFinished(attributes); } -struct TP_QT_NO_EXPORT BaseConnectionContactsInterface::Private { - Private(BaseConnectionContactsInterface *parent) - : adaptee(new BaseConnectionContactsInterface::Adaptee(parent)) { - } - QStringList contactAttributeInterfaces; - GetContactAttributesCallback getContactAttributesCallback; - BaseConnectionContactsInterface::Adaptee *adaptee; -}; - -QStringList BaseConnectionContactsInterface::Adaptee::contactAttributeInterfaces() const +void BaseConnectionContactsInterface::Adaptee::getContactByID(const QString &identifier, const QStringList &interfaces, + const Tp::Service::ConnectionInterfaceContactsAdaptor::GetContactByIDContextPtr &context) { - return mInterface->mPriv->contactAttributeInterfaces; + debug() << "BaseConnectionContactsInterface::Adaptee::getContactByID"; + DBusError error; + uint handle; + QVariantMap attributes; + + mInterface->getContactByID(identifier, interfaces, handle, attributes, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(handle, attributes); } /** * \class BaseConnectionContactsInterface - * \ingroup servicecm + * \ingroup serviceconn * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> * * \brief Base class for implementations of Connection.Interface.Contacts @@ -833,8 +1056,13 @@ BaseConnectionContactsInterface::~BaseConnectionContactsInterface() delete mPriv; } +void BaseConnectionContactsInterface::setBaseConnection(BaseConnection *connection) +{ + mPriv->connection = connection; +} + /** - * Return the immutable properties of this<interface. + * 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(). @@ -849,10 +1077,9 @@ QVariantMap BaseConnectionContactsInterface::immutableProperties() const return map; } -void BaseConnectionContactsInterface::createAdaptor() +QStringList BaseConnectionContactsInterface::contactAttributeInterfaces() const { - (void) new Service::ConnectionInterfaceContactsAdaptor(dbusObject()->dbusConnection(), - mPriv->adaptee, dbusObject()); + return mPriv->contactAttributeInterfaces; } void BaseConnectionContactsInterface::setContactAttributeInterfaces(const QStringList &contactAttributeInterfaces) @@ -860,20 +1087,43 @@ void BaseConnectionContactsInterface::setContactAttributeInterfaces(const QStrin mPriv->contactAttributeInterfaces = contactAttributeInterfaces; } +void BaseConnectionContactsInterface::createAdaptor() +{ + (void) new Tp::Service::ConnectionInterfaceContactsAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + void BaseConnectionContactsInterface::setGetContactAttributesCallback(const GetContactAttributesCallback &cb) { - mPriv->getContactAttributesCallback = cb; + mPriv->getContactAttributesCB = cb; } -ContactAttributesMap BaseConnectionContactsInterface::getContactAttributes(const Tp::UIntList &handles, - const QStringList &interfaces, - DBusError *error) +Tp::ContactAttributesMap BaseConnectionContactsInterface::getContactAttributes(const Tp::UIntList &handles, const QStringList &interfaces, DBusError *error) { - if (!mPriv->getContactAttributesCallback.isValid()) { + if (!mPriv->getContactAttributesCB.isValid()) { error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); - return ContactAttributesMap(); + return Tp::ContactAttributesMap(); + } + return mPriv->getContactAttributesCB(handles, interfaces, error); +} + +void BaseConnectionContactsInterface::getContactByID(const QString &identifier, const QStringList &interfaces, uint &handle, QVariantMap &attributes, DBusError *error) +{ + const Tp::UIntList handles = mPriv->connection->requestHandles(Tp::HandleTypeContact, QStringList() << identifier, error); + if (error->isValid() || handles.isEmpty()) { + // The check for empty handles is paranoid, because the error must be set in such case. + error->set(TP_QT_ERROR_INVALID_HANDLE, QLatin1String("Could not process ID")); + return; + } + + const Tp::ContactAttributesMap result = getContactAttributes(handles, interfaces, error); + + if (error->isValid()) { + return; } - return mPriv->getContactAttributesCallback(handles, interfaces, error); + + handle = handles.first(); + attributes = result.value(handle); } // Conn.I.SimplePresence @@ -889,12 +1139,12 @@ BaseConnectionSimplePresenceInterface::Adaptee::~Adaptee() struct TP_QT_NO_EXPORT BaseConnectionSimplePresenceInterface::Private { Private(BaseConnectionSimplePresenceInterface *parent) - : maxmimumStatusMessageLength(0), + : maximumStatusMessageLength(0), adaptee(new BaseConnectionSimplePresenceInterface::Adaptee(parent)) { } SetPresenceCallback setPresenceCB; SimpleStatusSpecMap statuses; - uint maxmimumStatusMessageLength; + uint maximumStatusMessageLength; /* The current presences */ SimpleContactPresences presences; BaseConnectionSimplePresenceInterface::Adaptee *adaptee; @@ -902,7 +1152,7 @@ struct TP_QT_NO_EXPORT BaseConnectionSimplePresenceInterface::Private { /** * \class BaseConnectionSimplePresenceInterface - * \ingroup servicecm + * \ingroup serviceconn * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> * * \brief Base class for implementations of Connection.Interface.SimplePresence @@ -925,21 +1175,6 @@ BaseConnectionSimplePresenceInterface::~BaseConnectionSimplePresenceInterface() 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 BaseConnectionSimplePresenceInterface::immutableProperties() const -{ - QVariantMap map; - //FIXME - return map; -} - void BaseConnectionSimplePresenceInterface::createAdaptor() { (void) new Service::ConnectionInterfaceSimplePresenceAdaptor(dbusObject()->dbusConnection(), @@ -950,10 +1185,19 @@ void BaseConnectionSimplePresenceInterface::createAdaptor() void BaseConnectionSimplePresenceInterface::setPresences(const Tp::SimpleContactPresences &presences) { + Tp::SimpleContactPresences newPresences; + foreach(uint handle, presences.keys()) { + if (mPriv->presences.contains(handle) && mPriv->presences.value(handle) == presences.value(handle)) { + continue; + } mPriv->presences[handle] = presences[handle]; + newPresences[handle] = presences[handle]; + } + + if (!newPresences.isEmpty()) { + QMetaObject::invokeMethod(mPriv->adaptee, "presencesChanged", Q_ARG(Tp::SimpleContactPresences, newPresences)); //Can simply use emit in Qt5 } - QMetaObject::invokeMethod(mPriv->adaptee, "presencesChanged", Q_ARG(Tp::SimpleContactPresences, presences)); //Can simply use emit in Qt5 } void BaseConnectionSimplePresenceInterface::setSetPresenceCallback(const SetPresenceCallback &cb) @@ -961,16 +1205,36 @@ void BaseConnectionSimplePresenceInterface::setSetPresenceCallback(const SetPres mPriv->setPresenceCB = cb; } +SimpleContactPresences BaseConnectionSimplePresenceInterface::getPresences(const UIntList &contacts) +{ + Tp::SimpleContactPresences presences; + foreach(uint handle, contacts) { + static const Tp::SimplePresence unknownPresence = { /* type */ ConnectionPresenceTypeUnknown, /* status */ QLatin1String("unknown") }; + presences[handle] = mPriv->presences.value(handle, unknownPresence); + } + + return presences; +} + +Tp::SimpleStatusSpecMap BaseConnectionSimplePresenceInterface::statuses() const +{ + return mPriv->statuses; +} + void BaseConnectionSimplePresenceInterface::setStatuses(const SimpleStatusSpecMap &statuses) { mPriv->statuses = statuses; } -void BaseConnectionSimplePresenceInterface::setMaxmimumStatusMessageLength(uint maxmimumStatusMessageLength) +uint BaseConnectionSimplePresenceInterface::maximumStatusMessageLength() const { - mPriv->maxmimumStatusMessageLength = maxmimumStatusMessageLength; + return mPriv->maximumStatusMessageLength; } +void BaseConnectionSimplePresenceInterface::setMaximumStatusMessageLength(uint maximumStatusMessageLength) +{ + mPriv->maximumStatusMessageLength = maximumStatusMessageLength; +} Tp::SimpleStatusSpecMap BaseConnectionSimplePresenceInterface::Adaptee::statuses() const { @@ -979,7 +1243,7 @@ Tp::SimpleStatusSpecMap BaseConnectionSimplePresenceInterface::Adaptee::statuses int BaseConnectionSimplePresenceInterface::Adaptee::maximumStatusMessageLength() const { - return mInterface->mPriv->maxmimumStatusMessageLength; + return mInterface->mPriv->maximumStatusMessageLength; } void BaseConnectionSimplePresenceInterface::Adaptee::setPresence(const QString &status, const QString &statusMessage_, @@ -998,10 +1262,10 @@ void BaseConnectionSimplePresenceInterface::Adaptee::setPresence(const QString & } QString statusMessage = statusMessage_; - if ((uint)statusMessage.length() > mInterface->mPriv->maxmimumStatusMessageLength) { + if ((uint)statusMessage.length() > mInterface->mPriv->maximumStatusMessageLength) { debug() << "BaseConnectionSimplePresenceInterface::Adaptee::setPresence: " - << "truncating status to " << mInterface->mPriv->maxmimumStatusMessageLength; - statusMessage = statusMessage.left(mInterface->mPriv->maxmimumStatusMessageLength); + << "truncating status to " << mInterface->mPriv->maximumStatusMessageLength; + statusMessage = statusMessage.left(mInterface->mPriv->maximumStatusMessageLength); } DBusError error; @@ -1029,31 +1293,10 @@ void BaseConnectionSimplePresenceInterface::Adaptee::setPresence(const QString & void BaseConnectionSimplePresenceInterface::Adaptee::getPresences(const Tp::UIntList &contacts, const Tp::Service::ConnectionInterfaceSimplePresenceAdaptor::GetPresencesContextPtr &context) { - Tp::SimpleContactPresences presences; - foreach(uint handle, contacts) { - SimpleContactPresences::iterator i = mInterface->mPriv->presences.find(handle); - if (i == mInterface->mPriv->presences.end()) { - Tp::SimplePresence presence; - presence.type = ConnectionPresenceTypeUnknown; - presence.status = QLatin1String("unknown"); - presences[handle] = presence; - } else - presences[handle] = *i; - } - context->setFinished(presences); + context->setFinished(mInterface->getPresences(contacts)); } // Conn.I.ContactList -BaseConnectionContactListInterface::Adaptee::Adaptee(BaseConnectionContactListInterface *interface) - : QObject(interface), - mInterface(interface) -{ -} - -BaseConnectionContactListInterface::Adaptee::~Adaptee() -{ -} - struct TP_QT_NO_EXPORT BaseConnectionContactListInterface::Private { Private(BaseConnectionContactListInterface *parent) : contactListState(ContactListStateNone), @@ -1061,8 +1304,10 @@ struct TP_QT_NO_EXPORT BaseConnectionContactListInterface::Private { canChangeContactList(true), requestUsesMessage(false), downloadAtConnection(false), - adaptee(new BaseConnectionContactListInterface::Adaptee(parent)) { + adaptee(new BaseConnectionContactListInterface::Adaptee(parent)) + { } + uint contactListState; bool contactListPersists; bool canChangeContactList; @@ -1070,12 +1315,143 @@ struct TP_QT_NO_EXPORT BaseConnectionContactListInterface::Private { bool downloadAtConnection; GetContactListAttributesCallback getContactListAttributesCB; RequestSubscriptionCallback requestSubscriptionCB; + AuthorizePublicationCallback authorizePublicationCB; + RemoveContactsCallback removeContactsCB; + UnsubscribeCallback unsubscribeCB; + UnpublishCallback unpublishCB; + DownloadCallback downloadCB; BaseConnectionContactListInterface::Adaptee *adaptee; }; +BaseConnectionContactListInterface::Adaptee::Adaptee(BaseConnectionContactListInterface *interface) + : QObject(interface), + mInterface(interface) +{ +} + +BaseConnectionContactListInterface::Adaptee::~Adaptee() +{ +} + +uint BaseConnectionContactListInterface::Adaptee::contactListState() const +{ + return mInterface->contactListState(); +} + +bool BaseConnectionContactListInterface::Adaptee::contactListPersists() const +{ + return mInterface->contactListPersists(); +} + +bool BaseConnectionContactListInterface::Adaptee::canChangeContactList() const +{ + return mInterface->canChangeContactList(); +} + +bool BaseConnectionContactListInterface::Adaptee::requestUsesMessage() const +{ + return mInterface->requestUsesMessage(); +} + +bool BaseConnectionContactListInterface::Adaptee::downloadAtConnection() const +{ + return mInterface->downloadAtConnection(); +} + +void BaseConnectionContactListInterface::Adaptee::getContactListAttributes(const QStringList &interfaces, bool hold, + const Tp::Service::ConnectionInterfaceContactListAdaptor::GetContactListAttributesContextPtr &context) +{ + debug() << "BaseConnectionContactListInterface::Adaptee::getContactListAttributes"; + DBusError error; + Tp::ContactAttributesMap attributes = mInterface->getContactListAttributes(interfaces, hold, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(attributes); +} + +void BaseConnectionContactListInterface::Adaptee::requestSubscription(const Tp::UIntList &contacts, const QString &message, + const Tp::Service::ConnectionInterfaceContactListAdaptor::RequestSubscriptionContextPtr &context) +{ + debug() << "BaseConnectionContactListInterface::Adaptee::requestSubscription"; + DBusError error; + mInterface->requestSubscription(contacts, message, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactListInterface::Adaptee::authorizePublication(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceContactListAdaptor::AuthorizePublicationContextPtr &context) +{ + debug() << "BaseConnectionContactListInterface::Adaptee::authorizePublication"; + DBusError error; + mInterface->authorizePublication(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactListInterface::Adaptee::removeContacts(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceContactListAdaptor::RemoveContactsContextPtr &context) +{ + debug() << "BaseConnectionContactListInterface::Adaptee::removeContacts"; + DBusError error; + mInterface->removeContacts(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactListInterface::Adaptee::unsubscribe(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceContactListAdaptor::UnsubscribeContextPtr &context) +{ + debug() << "BaseConnectionContactListInterface::Adaptee::unsubscribe"; + DBusError error; + mInterface->unsubscribe(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactListInterface::Adaptee::unpublish(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceContactListAdaptor::UnpublishContextPtr &context) +{ + debug() << "BaseConnectionContactListInterface::Adaptee::unpublish"; + DBusError error; + mInterface->unpublish(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactListInterface::Adaptee::download( + const Tp::Service::ConnectionInterfaceContactListAdaptor::DownloadContextPtr &context) +{ + debug() << "BaseConnectionContactListInterface::Adaptee::download"; + DBusError error; + mInterface->download(&error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + /** * \class BaseConnectionContactListInterface - * \ingroup servicecm + * \ingroup serviceconn * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> * * \brief Base class for implementations of Connection.Interface.ContactList @@ -1098,36 +1474,24 @@ BaseConnectionContactListInterface::~BaseConnectionContactListInterface() 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 BaseConnectionContactListInterface::immutableProperties() const -{ - QVariantMap map; - return map; -} - -void BaseConnectionContactListInterface::createAdaptor() +uint BaseConnectionContactListInterface::contactListState() const { - (void) new Service::ConnectionInterfaceContactListAdaptor(dbusObject()->dbusConnection(), - mPriv->adaptee, dbusObject()); + return mPriv->contactListState; } void BaseConnectionContactListInterface::setContactListState(uint contactListState) { - bool changed = (contactListState != mPriv->contactListState); + if (mPriv->contactListState == contactListState) { + return; + } + mPriv->contactListState = contactListState; - if (changed) - //emit after return - QMetaObject::invokeMethod(mPriv->adaptee, "contactListStateChanged", - Qt::QueuedConnection, - Q_ARG(uint, contactListState)); + QMetaObject::invokeMethod(mPriv->adaptee, "contactListStateChanged", Q_ARG(uint, contactListState)); //Can simply use emit in Qt5 +} +bool BaseConnectionContactListInterface::contactListPersists() const +{ + return mPriv->contactListPersists; } void BaseConnectionContactListInterface::setContactListPersists(bool contactListPersists) @@ -1135,86 +1499,522 @@ void BaseConnectionContactListInterface::setContactListPersists(bool contactList mPriv->contactListPersists = contactListPersists; } +bool BaseConnectionContactListInterface::canChangeContactList() const +{ + return mPriv->canChangeContactList; +} + void BaseConnectionContactListInterface::setCanChangeContactList(bool canChangeContactList) { mPriv->canChangeContactList = canChangeContactList; } +bool BaseConnectionContactListInterface::requestUsesMessage() const +{ + return mPriv->requestUsesMessage; +} + void BaseConnectionContactListInterface::setRequestUsesMessage(bool requestUsesMessage) { mPriv->requestUsesMessage = requestUsesMessage; } +bool BaseConnectionContactListInterface::downloadAtConnection() const +{ + return mPriv->downloadAtConnection; +} + void BaseConnectionContactListInterface::setDownloadAtConnection(bool downloadAtConnection) { mPriv->downloadAtConnection = downloadAtConnection; } -void BaseConnectionContactListInterface::setGetContactListAttributesCallback(const GetContactListAttributesCallback &cb) +void BaseConnectionContactListInterface::createAdaptor() +{ + (void) new Service::ConnectionInterfaceContactListAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + +void BaseConnectionContactListInterface::setGetContactListAttributesCallback(const BaseConnectionContactListInterface::GetContactListAttributesCallback &cb) { mPriv->getContactListAttributesCB = cb; } -void BaseConnectionContactListInterface::setRequestSubscriptionCallback(const RequestSubscriptionCallback &cb) +Tp::ContactAttributesMap BaseConnectionContactListInterface::getContactListAttributes(const QStringList &interfaces, bool hold, DBusError *error) +{ + if (!mPriv->getContactListAttributesCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return Tp::ContactAttributesMap(); + } + return mPriv->getContactListAttributesCB(interfaces, hold, error); +} + +void BaseConnectionContactListInterface::setRequestSubscriptionCallback(const BaseConnectionContactListInterface::RequestSubscriptionCallback &cb) { mPriv->requestSubscriptionCB = cb; } +void BaseConnectionContactListInterface::requestSubscription(const Tp::UIntList &contacts, const QString &message, DBusError *error) +{ + if (!mPriv->requestSubscriptionCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->requestSubscriptionCB(contacts, message, error); +} + +void BaseConnectionContactListInterface::setAuthorizePublicationCallback(const BaseConnectionContactListInterface::AuthorizePublicationCallback &cb) +{ + mPriv->authorizePublicationCB = cb; +} + +void BaseConnectionContactListInterface::authorizePublication(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->authorizePublicationCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->authorizePublicationCB(contacts, error); +} + +void BaseConnectionContactListInterface::setRemoveContactsCallback(const BaseConnectionContactListInterface::RemoveContactsCallback &cb) +{ + mPriv->removeContactsCB = cb; +} + +void BaseConnectionContactListInterface::removeContacts(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->removeContactsCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->removeContactsCB(contacts, error); +} + +void BaseConnectionContactListInterface::setUnsubscribeCallback(const BaseConnectionContactListInterface::UnsubscribeCallback &cb) +{ + mPriv->unsubscribeCB = cb; +} + +void BaseConnectionContactListInterface::unsubscribe(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->unsubscribeCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->unsubscribeCB(contacts, error); +} + +void BaseConnectionContactListInterface::setUnpublishCallback(const BaseConnectionContactListInterface::UnpublishCallback &cb) +{ + mPriv->unpublishCB = cb; +} + +void BaseConnectionContactListInterface::unpublish(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->unpublishCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->unpublishCB(contacts, error); +} + +void BaseConnectionContactListInterface::setDownloadCallback(const BaseConnectionContactListInterface::DownloadCallback &cb) +{ + mPriv->downloadCB = cb; +} + +void BaseConnectionContactListInterface::download(DBusError *error) +{ + if (!mPriv->downloadCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->downloadCB(error); +} + void BaseConnectionContactListInterface::contactsChangedWithID(const Tp::ContactSubscriptionMap &changes, const Tp::HandleIdentifierMap &identifiers, const Tp::HandleIdentifierMap &removals) { - 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 + 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 } -uint BaseConnectionContactListInterface::Adaptee::contactListState() const +// Conn.I.ContactGroups +// The BaseConnectionContactGroupsInterface code is fully or partially generated by the TelepathyQt-Generator. +struct TP_QT_NO_EXPORT BaseConnectionContactGroupsInterface::Private { + Private(BaseConnectionContactGroupsInterface *parent) + : disjointGroups(false), + groupStorage(Tp::ContactMetadataStorageTypeNone), + adaptee(new BaseConnectionContactGroupsInterface::Adaptee(parent)) + { + } + + bool disjointGroups; + Tp::ContactMetadataStorageType groupStorage; + QStringList groups; + SetContactGroupsCallback setContactGroupsCB; + SetGroupMembersCallback setGroupMembersCB; + AddToGroupCallback addToGroupCB; + RemoveFromGroupCallback removeFromGroupCB; + RemoveGroupCallback removeGroupCB; + RenameGroupCallback renameGroupCB; + BaseConnectionContactGroupsInterface::Adaptee *adaptee; +}; + +BaseConnectionContactGroupsInterface::Adaptee::Adaptee(BaseConnectionContactGroupsInterface *interface) + : QObject(interface), + mInterface(interface) { - return mInterface->mPriv->contactListState; } -bool BaseConnectionContactListInterface::Adaptee::contactListPersists() const +BaseConnectionContactGroupsInterface::Adaptee::~Adaptee() { - return mInterface->mPriv->contactListPersists; } -bool BaseConnectionContactListInterface::Adaptee::canChangeContactList() const +bool BaseConnectionContactGroupsInterface::Adaptee::disjointGroups() const { - return mInterface->mPriv->canChangeContactList; + return mInterface->disjointGroups(); } -bool BaseConnectionContactListInterface::Adaptee::requestUsesMessage() const +uint BaseConnectionContactGroupsInterface::Adaptee::groupStorage() const { - return mInterface->mPriv->requestUsesMessage; + return mInterface->groupStorage(); } -bool BaseConnectionContactListInterface::Adaptee::downloadAtConnection() const +QStringList BaseConnectionContactGroupsInterface::Adaptee::groups() const { - return mInterface->mPriv->downloadAtConnection; + return mInterface->groups(); } -void BaseConnectionContactListInterface::Adaptee::getContactListAttributes(const QStringList &interfaces, - bool hold, const Tp::Service::ConnectionInterfaceContactListAdaptor::GetContactListAttributesContextPtr &context) +void BaseConnectionContactGroupsInterface::Adaptee::setContactGroups(uint contact, const QStringList &groups, + const Tp::Service::ConnectionInterfaceContactGroupsAdaptor::SetContactGroupsContextPtr &context) { - if (!mInterface->mPriv->getContactListAttributesCB.isValid()) { - context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + debug() << "BaseConnectionContactGroupsInterface::Adaptee::setContactGroups"; + DBusError error; + mInterface->setContactGroups(contact, groups, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); return; } + context->setFinished(); +} + +void BaseConnectionContactGroupsInterface::Adaptee::setGroupMembers(const QString &group, const Tp::UIntList &members, + const Tp::Service::ConnectionInterfaceContactGroupsAdaptor::SetGroupMembersContextPtr &context) +{ + debug() << "BaseConnectionContactGroupsInterface::Adaptee::setGroupMembers"; DBusError error; - Tp::ContactAttributesMap contactAttributesMap = mInterface->mPriv->getContactListAttributesCB(interfaces, hold, &error); + mInterface->setGroupMembers(group, members, &error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } - context->setFinished(contactAttributesMap); + context->setFinished(); } -void BaseConnectionContactListInterface::Adaptee::requestSubscription(const Tp::UIntList &contacts, - const QString &message, const Tp::Service::ConnectionInterfaceContactListAdaptor::RequestSubscriptionContextPtr &context) +void BaseConnectionContactGroupsInterface::Adaptee::addToGroup(const QString &group, const Tp::UIntList &members, + const Tp::Service::ConnectionInterfaceContactGroupsAdaptor::AddToGroupContextPtr &context) { - if (!mInterface->mPriv->requestSubscriptionCB.isValid()) { - context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + debug() << "BaseConnectionContactGroupsInterface::Adaptee::addToGroup"; + DBusError error; + mInterface->addToGroup(group, members, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactGroupsInterface::Adaptee::removeFromGroup(const QString &group, const Tp::UIntList &members, + const Tp::Service::ConnectionInterfaceContactGroupsAdaptor::RemoveFromGroupContextPtr &context) +{ + debug() << "BaseConnectionContactGroupsInterface::Adaptee::removeFromGroup"; + DBusError error; + mInterface->removeFromGroup(group, members, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactGroupsInterface::Adaptee::removeGroup(const QString &group, + const Tp::Service::ConnectionInterfaceContactGroupsAdaptor::RemoveGroupContextPtr &context) +{ + debug() << "BaseConnectionContactGroupsInterface::Adaptee::removeGroup"; + DBusError error; + mInterface->removeGroup(group, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactGroupsInterface::Adaptee::renameGroup(const QString &oldName, const QString &newName, + const Tp::Service::ConnectionInterfaceContactGroupsAdaptor::RenameGroupContextPtr &context) +{ + debug() << "BaseConnectionContactGroupsInterface::Adaptee::renameGroup"; + DBusError error; + mInterface->renameGroup(oldName, newName, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +/** + * \class BaseConnectionContactGroupsInterface + * \ingroup serviceconn + * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> + * + * \brief Base class for implementations of Connection.Interface.ContactGroups + */ + +/** + * Class constructor. + */ +BaseConnectionContactGroupsInterface::BaseConnectionContactGroupsInterface() + : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_INTERFACE_CONTACT_GROUPS), + mPriv(new Private(this)) +{ +} + +/** + * Class destructor. + */ +BaseConnectionContactGroupsInterface::~BaseConnectionContactGroupsInterface() +{ + delete mPriv; +} + +bool BaseConnectionContactGroupsInterface::disjointGroups() const +{ + return mPriv->disjointGroups; +} + +void BaseConnectionContactGroupsInterface::setDisjointGroups(bool disjointGroups) +{ + mPriv->disjointGroups = disjointGroups; +} + +Tp::ContactMetadataStorageType BaseConnectionContactGroupsInterface::groupStorage() const +{ + return mPriv->groupStorage; +} + +void BaseConnectionContactGroupsInterface::setGroupStorage(Tp::ContactMetadataStorageType groupStorage) +{ + mPriv->groupStorage = groupStorage; +} + +QStringList BaseConnectionContactGroupsInterface::groups() const +{ + return mPriv->groups; +} + +void BaseConnectionContactGroupsInterface::setGroups(const QStringList &groups) +{ + mPriv->groups = groups; +} + +void BaseConnectionContactGroupsInterface::createAdaptor() +{ + (void) new Tp::Service::ConnectionInterfaceContactGroupsAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + +void BaseConnectionContactGroupsInterface::setSetContactGroupsCallback(const SetContactGroupsCallback &cb) +{ + mPriv->setContactGroupsCB = cb; +} + +void BaseConnectionContactGroupsInterface::setContactGroups(uint contact, const QStringList &groups, DBusError *error) +{ + if (!mPriv->setContactGroupsCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->setContactGroupsCB(contact, groups, error); +} + +void BaseConnectionContactGroupsInterface::setSetGroupMembersCallback(const SetGroupMembersCallback &cb) +{ + mPriv->setGroupMembersCB = cb; +} + +void BaseConnectionContactGroupsInterface::setGroupMembers(const QString &group, const Tp::UIntList &members, DBusError *error) +{ + if (!mPriv->setGroupMembersCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->setGroupMembersCB(group, members, error); +} + +void BaseConnectionContactGroupsInterface::setAddToGroupCallback(const AddToGroupCallback &cb) +{ + mPriv->addToGroupCB = cb; +} + +void BaseConnectionContactGroupsInterface::addToGroup(const QString &group, const Tp::UIntList &members, DBusError *error) +{ + if (!mPriv->addToGroupCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->addToGroupCB(group, members, error); +} + +void BaseConnectionContactGroupsInterface::setRemoveFromGroupCallback(const RemoveFromGroupCallback &cb) +{ + mPriv->removeFromGroupCB = cb; +} + +void BaseConnectionContactGroupsInterface::removeFromGroup(const QString &group, const Tp::UIntList &members, DBusError *error) +{ + if (!mPriv->removeFromGroupCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->removeFromGroupCB(group, members, error); +} + +void BaseConnectionContactGroupsInterface::setRemoveGroupCallback(const RemoveGroupCallback &cb) +{ + mPriv->removeGroupCB = cb; +} + +void BaseConnectionContactGroupsInterface::removeGroup(const QString &group, DBusError *error) +{ + if (!mPriv->removeGroupCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->removeGroupCB(group, error); +} + +void BaseConnectionContactGroupsInterface::setRenameGroupCallback(const RenameGroupCallback &cb) +{ + mPriv->renameGroupCB = cb; +} + +void BaseConnectionContactGroupsInterface::renameGroup(const QString &oldName, const QString &newName, DBusError *error) +{ + if (!mPriv->renameGroupCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); return; } + mPriv->renameGroupCB(oldName, newName, error); + + if (!error->isValid()) { + groupRenamed(oldName, newName); + groupsCreated(QStringList() << newName); + groupsRemoved(QStringList() << oldName); + } +} + +void BaseConnectionContactGroupsInterface::groupsCreated(const QStringList &names) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "groupsCreated", Q_ARG(QStringList, names)); //Can simply use emit in Qt5 +} + +void BaseConnectionContactGroupsInterface::groupRenamed(const QString &oldName, const QString &newName) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "groupRenamed", Q_ARG(QString, oldName), Q_ARG(QString, newName)); //Can simply use emit in Qt5 +} + +void BaseConnectionContactGroupsInterface::groupsRemoved(const QStringList &names) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "groupsRemoved", Q_ARG(QStringList, names)); //Can simply use emit in Qt5 +} + +void BaseConnectionContactGroupsInterface::groupsChanged(const Tp::UIntList &contact, const QStringList &added, const QStringList &removed) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "groupsChanged", Q_ARG(Tp::UIntList, contact), Q_ARG(QStringList, added), Q_ARG(QStringList, removed)); //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) +{ + debug() << "BaseConnectionContactInfoInterface::Adaptee::getContactInfo"; DBusError error; - mInterface->mPriv->requestSubscriptionCB(contacts, message, &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) +{ + debug() << "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) +{ + debug() << "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) +{ + debug() << "BaseConnectionContactInfoInterface::Adaptee::setContactInfo"; + DBusError error; + mInterface->setContactInfo(contactInfo, &error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; @@ -1222,6 +2022,118 @@ void BaseConnectionContactListInterface::Adaptee::requestSubscription(const Tp:: context->setFinished(); } +/** + * \class BaseConnectionContactInfoInterface + * \ingroup serviceconn + * \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; +} + +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), @@ -1243,11 +2155,11 @@ struct TP_QT_NO_EXPORT BaseConnectionAddressingInterface::Private { }; /** - * \class BaseProtocolPresenceInterface - * \ingroup servicecm - * \headerfile TelepathyQt/base-protocol.h <TelepathyQt/BaseProtocolPresenceInterface> + * \class BaseConnectionAddressingInterface + * \ingroup serviceconn + * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> * - * \brief Base class for implementations of Protocol.Interface.Presence + * \brief Base class for implementations of Connection.Interface.Addressing */ /** @@ -1267,20 +2179,6 @@ BaseConnectionAddressingInterface::~BaseConnectionAddressingInterface() 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 BaseConnectionAddressingInterface::immutableProperties() const -{ - QVariantMap map; - return map; -} - void BaseConnectionAddressingInterface::createAdaptor() { (void) new Service::ConnectionInterfaceAddressingAdaptor(dbusObject()->dbusConnection(), @@ -1342,4 +2240,624 @@ void BaseConnectionAddressingInterface::Adaptee::getContactsByURI(const QStringL context->setFinished(addressingNormalizationMap, contactAttributesMap); } +// Conn.I.Aliasing +struct TP_QT_NO_EXPORT BaseConnectionAliasingInterface::Private { + Private(BaseConnectionAliasingInterface *parent) + : adaptee(new BaseConnectionAliasingInterface::Adaptee(parent)) + { + } + + GetAliasFlagsCallback getAliasFlagsCB; + RequestAliasesCallback requestAliasesCB; + GetAliasesCallback getAliasesCB; + SetAliasesCallback setAliasesCB; + BaseConnectionAliasingInterface::Adaptee *adaptee; +}; + +BaseConnectionAliasingInterface::Adaptee::Adaptee(BaseConnectionAliasingInterface *interface) + : QObject(interface), + mInterface(interface) +{ +} + +BaseConnectionAliasingInterface::Adaptee::~Adaptee() +{ +} + +void BaseConnectionAliasingInterface::Adaptee::getAliasFlags( + const Tp::Service::ConnectionInterfaceAliasingAdaptor::GetAliasFlagsContextPtr &context) +{ + debug() << "BaseConnectionAliasingInterface::Adaptee::getAliasFlags"; + DBusError error; + Tp::ConnectionAliasFlags aliasFlags = mInterface->getAliasFlags(&error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(aliasFlags); +} + +void BaseConnectionAliasingInterface::Adaptee::requestAliases(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceAliasingAdaptor::RequestAliasesContextPtr &context) +{ + debug() << "BaseConnectionAliasingInterface::Adaptee::requestAliases"; + DBusError error; + QStringList aliases = mInterface->requestAliases(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(aliases); +} + +void BaseConnectionAliasingInterface::Adaptee::getAliases(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceAliasingAdaptor::GetAliasesContextPtr &context) +{ + debug() << "BaseConnectionAliasingInterface::Adaptee::getAliases"; + DBusError error; + Tp::AliasMap aliases = mInterface->getAliases(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(aliases); +} + +void BaseConnectionAliasingInterface::Adaptee::setAliases(const Tp::AliasMap &aliases, + const Tp::Service::ConnectionInterfaceAliasingAdaptor::SetAliasesContextPtr &context) +{ + debug() << "BaseConnectionAliasingInterface::Adaptee::setAliases"; + DBusError error; + mInterface->setAliases(aliases, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +/** + * \class BaseConnectionAliasingInterface + * \ingroup serviceconn + * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> + * + * \brief Base class for implementations of Connection.Interface.Aliasing + */ + +/** + * Class constructor. + */ +BaseConnectionAliasingInterface::BaseConnectionAliasingInterface() + : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_INTERFACE_ALIASING), + mPriv(new Private(this)) +{ +} + +/** + * Class destructor. + */ +BaseConnectionAliasingInterface::~BaseConnectionAliasingInterface() +{ + delete mPriv; +} + +void BaseConnectionAliasingInterface::createAdaptor() +{ + (void) new Service::ConnectionInterfaceAliasingAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + +void BaseConnectionAliasingInterface::setGetAliasFlagsCallback(const BaseConnectionAliasingInterface::GetAliasFlagsCallback &cb) +{ + mPriv->getAliasFlagsCB = cb; +} + +Tp::ConnectionAliasFlags BaseConnectionAliasingInterface::getAliasFlags(DBusError *error) +{ + if (!mPriv->getAliasFlagsCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return Tp::ConnectionAliasFlags(); + } + return mPriv->getAliasFlagsCB(error); +} + +void BaseConnectionAliasingInterface::setRequestAliasesCallback(const BaseConnectionAliasingInterface::RequestAliasesCallback &cb) +{ + mPriv->requestAliasesCB = cb; +} + +QStringList BaseConnectionAliasingInterface::requestAliases(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->requestAliasesCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return QStringList(); + } + return mPriv->requestAliasesCB(contacts, error); +} + +void BaseConnectionAliasingInterface::setGetAliasesCallback(const BaseConnectionAliasingInterface::GetAliasesCallback &cb) +{ + mPriv->getAliasesCB = cb; +} + +Tp::AliasMap BaseConnectionAliasingInterface::getAliases(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->getAliasesCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return Tp::AliasMap(); + } + return mPriv->getAliasesCB(contacts, error); +} + +void BaseConnectionAliasingInterface::setSetAliasesCallback(const BaseConnectionAliasingInterface::SetAliasesCallback &cb) +{ + mPriv->setAliasesCB = cb; +} + +void BaseConnectionAliasingInterface::setAliases(const Tp::AliasMap &aliases, DBusError *error) +{ + if (!mPriv->setAliasesCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->setAliasesCB(aliases, error); +} + +void BaseConnectionAliasingInterface::aliasesChanged(const Tp::AliasPairList &aliases) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "aliasesChanged", Q_ARG(Tp::AliasPairList, aliases)); //Can simply use emit in Qt5 +} + +// Conn.I.Avatars +struct TP_QT_NO_EXPORT BaseConnectionAvatarsInterface::Private { + Private(BaseConnectionAvatarsInterface *parent) + : adaptee(new BaseConnectionAvatarsInterface::Adaptee(parent)) + { + } + + AvatarSpec avatarDetails; + GetKnownAvatarTokensCallback getKnownAvatarTokensCB; + RequestAvatarsCallback requestAvatarsCB; + SetAvatarCallback setAvatarCB; + ClearAvatarCallback clearAvatarCB; + BaseConnectionAvatarsInterface::Adaptee *adaptee; + + friend class BaseConnectionAvatarsInterface::Adaptee; +}; + +BaseConnectionAvatarsInterface::Adaptee::Adaptee(BaseConnectionAvatarsInterface *interface) + : QObject(interface), + mInterface(interface) +{ +} + +BaseConnectionAvatarsInterface::Adaptee::~Adaptee() +{ +} + +QStringList BaseConnectionAvatarsInterface::Adaptee::supportedAvatarMimeTypes() const +{ + return mInterface->mPriv->avatarDetails.supportedMimeTypes(); +} + +uint BaseConnectionAvatarsInterface::Adaptee::minimumAvatarHeight() const +{ + return mInterface->mPriv->avatarDetails.minimumHeight(); +} + +uint BaseConnectionAvatarsInterface::Adaptee::minimumAvatarWidth() const +{ + return mInterface->mPriv->avatarDetails.minimumWidth(); +} + +uint BaseConnectionAvatarsInterface::Adaptee::recommendedAvatarHeight() const +{ + return mInterface->mPriv->avatarDetails.recommendedHeight(); +} + +uint BaseConnectionAvatarsInterface::Adaptee::recommendedAvatarWidth() const +{ + return mInterface->mPriv->avatarDetails.recommendedWidth(); +} + +uint BaseConnectionAvatarsInterface::Adaptee::maximumAvatarHeight() const +{ + return mInterface->mPriv->avatarDetails.maximumHeight(); +} + +uint BaseConnectionAvatarsInterface::Adaptee::maximumAvatarWidth() const +{ + return mInterface->mPriv->avatarDetails.maximumWidth(); +} + +uint BaseConnectionAvatarsInterface::Adaptee::maximumAvatarBytes() const +{ + return mInterface->mPriv->avatarDetails.maximumBytes(); +} + +void BaseConnectionAvatarsInterface::Adaptee::getKnownAvatarTokens(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceAvatarsAdaptor::GetKnownAvatarTokensContextPtr &context) +{ + debug() << "BaseConnectionAvatarsInterface::Adaptee::getKnownAvatarTokens"; + DBusError error; + Tp::AvatarTokenMap tokens = mInterface->getKnownAvatarTokens(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(tokens); +} + +void BaseConnectionAvatarsInterface::Adaptee::requestAvatars(const Tp::UIntList &contacts, + const Tp::Service::ConnectionInterfaceAvatarsAdaptor::RequestAvatarsContextPtr &context) +{ + debug() << "BaseConnectionAvatarsInterface::Adaptee::requestAvatars"; + DBusError error; + mInterface->requestAvatars(contacts, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionAvatarsInterface::Adaptee::setAvatar(const QByteArray &avatar, const QString &mimeType, + const Tp::Service::ConnectionInterfaceAvatarsAdaptor::SetAvatarContextPtr &context) +{ + debug() << "BaseConnectionAvatarsInterface::Adaptee::setAvatar"; + DBusError error; + QString token = mInterface->setAvatar(avatar, mimeType, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(token); +} + +void BaseConnectionAvatarsInterface::Adaptee::clearAvatar( + const Tp::Service::ConnectionInterfaceAvatarsAdaptor::ClearAvatarContextPtr &context) +{ + debug() << "BaseConnectionAvatarsInterface::Adaptee::clearAvatar"; + DBusError error; + mInterface->clearAvatar(&error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +/** + * \class BaseConnectionAvatarsInterface + * \ingroup serviceconn + * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> + * + * \brief Base class for implementations of Connection.Interface.Avatars + */ + +/** + * Class constructor. + */ +BaseConnectionAvatarsInterface::BaseConnectionAvatarsInterface() + : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_INTERFACE_AVATARS), + mPriv(new Private(this)) +{ +} + +/** + * Class destructor. + */ +BaseConnectionAvatarsInterface::~BaseConnectionAvatarsInterface() +{ + delete mPriv; +} + +AvatarSpec BaseConnectionAvatarsInterface::avatarDetails() const +{ + return mPriv->avatarDetails; +} + +void BaseConnectionAvatarsInterface::setAvatarDetails(const AvatarSpec &spec) +{ + mPriv->avatarDetails = spec; +} + +void BaseConnectionAvatarsInterface::createAdaptor() +{ + (void) new Service::ConnectionInterfaceAvatarsAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + +void BaseConnectionAvatarsInterface::setGetKnownAvatarTokensCallback(const BaseConnectionAvatarsInterface::GetKnownAvatarTokensCallback &cb) +{ + mPriv->getKnownAvatarTokensCB = cb; +} + +Tp::AvatarTokenMap BaseConnectionAvatarsInterface::getKnownAvatarTokens(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->getKnownAvatarTokensCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return Tp::AvatarTokenMap(); + } + return mPriv->getKnownAvatarTokensCB(contacts, error); +} + +void BaseConnectionAvatarsInterface::setRequestAvatarsCallback(const BaseConnectionAvatarsInterface::RequestAvatarsCallback &cb) +{ + mPriv->requestAvatarsCB = cb; +} + +void BaseConnectionAvatarsInterface::requestAvatars(const Tp::UIntList &contacts, DBusError *error) +{ + if (!mPriv->requestAvatarsCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->requestAvatarsCB(contacts, error); +} + +void BaseConnectionAvatarsInterface::setSetAvatarCallback(const BaseConnectionAvatarsInterface::SetAvatarCallback &cb) +{ + mPriv->setAvatarCB = cb; +} + +QString BaseConnectionAvatarsInterface::setAvatar(const QByteArray &avatar, const QString &mimeType, DBusError *error) +{ + if (!mPriv->setAvatarCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return QString(); + } + return mPriv->setAvatarCB(avatar, mimeType, error); +} + +void BaseConnectionAvatarsInterface::setClearAvatarCallback(const BaseConnectionAvatarsInterface::ClearAvatarCallback &cb) +{ + mPriv->clearAvatarCB = cb; +} + +void BaseConnectionAvatarsInterface::clearAvatar(DBusError *error) +{ + if (!mPriv->clearAvatarCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->clearAvatarCB(error); +} + +void BaseConnectionAvatarsInterface::avatarUpdated(uint contact, const QString &newAvatarToken) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "avatarUpdated", Q_ARG(uint, contact), Q_ARG(QString, newAvatarToken)); //Can simply use emit in Qt5 +} + +void BaseConnectionAvatarsInterface::avatarRetrieved(uint contact, const QString &token, const QByteArray &avatar, const QString &type) +{ + 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; +} + +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 { + Private(BaseConnectionContactCapabilitiesInterface *parent) + : adaptee(new BaseConnectionContactCapabilitiesInterface::Adaptee(parent)) + { + } + + UpdateCapabilitiesCallback updateCapabilitiesCB; + GetContactCapabilitiesCallback getContactCapabilitiesCB; + BaseConnectionContactCapabilitiesInterface::Adaptee *adaptee; +}; + +BaseConnectionContactCapabilitiesInterface::Adaptee::Adaptee(BaseConnectionContactCapabilitiesInterface *interface) + : QObject(interface), + mInterface(interface) +{ +} + +BaseConnectionContactCapabilitiesInterface::Adaptee::~Adaptee() +{ +} + +void BaseConnectionContactCapabilitiesInterface::Adaptee::updateCapabilities(const Tp::HandlerCapabilitiesList &handlerCapabilities, + const Tp::Service::ConnectionInterfaceContactCapabilitiesAdaptor::UpdateCapabilitiesContextPtr &context) +{ + debug() << "BaseConnectionContactCapabilitiesInterface::Adaptee::updateCapabilities"; + DBusError error; + mInterface->updateCapabilities(handlerCapabilities, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseConnectionContactCapabilitiesInterface::Adaptee::getContactCapabilities(const Tp::UIntList &handles, + const Tp::Service::ConnectionInterfaceContactCapabilitiesAdaptor::GetContactCapabilitiesContextPtr &context) +{ + debug() << "BaseConnectionContactCapabilitiesInterface::Adaptee::getContactCapabilities"; + DBusError error; + Tp::ContactCapabilitiesMap contactCapabilities = mInterface->getContactCapabilities(handles, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(contactCapabilities); +} + +/** + * \class BaseConnectionContactCapabilitiesInterface + * \ingroup serviceconn + * \headerfile TelepathyQt/base-connection.h <TelepathyQt/BaseConnection> + * + * \brief Base class for implementations of Connection.Interface.ContactCapabilities + */ + +/** + * Class constructor. + */ +BaseConnectionContactCapabilitiesInterface::BaseConnectionContactCapabilitiesInterface() + : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES), + mPriv(new Private(this)) +{ +} + +/** + * Class destructor. + */ +BaseConnectionContactCapabilitiesInterface::~BaseConnectionContactCapabilitiesInterface() +{ + delete mPriv; +} + +void BaseConnectionContactCapabilitiesInterface::createAdaptor() +{ + (void) new Tp::Service::ConnectionInterfaceContactCapabilitiesAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + +void BaseConnectionContactCapabilitiesInterface::setUpdateCapabilitiesCallback(const UpdateCapabilitiesCallback &cb) +{ + mPriv->updateCapabilitiesCB = cb; +} + +void BaseConnectionContactCapabilitiesInterface::updateCapabilities(const Tp::HandlerCapabilitiesList &handlerCapabilities, DBusError *error) +{ + if (!mPriv->updateCapabilitiesCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->updateCapabilitiesCB(handlerCapabilities, error); +} + +void BaseConnectionContactCapabilitiesInterface::setGetContactCapabilitiesCallback(const GetContactCapabilitiesCallback &cb) +{ + mPriv->getContactCapabilitiesCB = cb; +} + +Tp::ContactCapabilitiesMap BaseConnectionContactCapabilitiesInterface::getContactCapabilities(const Tp::UIntList &handles, DBusError *error) +{ + if (!mPriv->getContactCapabilitiesCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return Tp::ContactCapabilitiesMap(); + } + return mPriv->getContactCapabilitiesCB(handles, error); +} + +void BaseConnectionContactCapabilitiesInterface::contactCapabilitiesChanged(const Tp::ContactCapabilitiesMap &caps) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "contactCapabilitiesChanged", Q_ARG(Tp::ContactCapabilitiesMap, caps)); //Can simply use emit in Qt5 +} + } |