diff options
author | Alexandr Akulich <akulichalexander@gmail.com> | 2015-05-20 22:45:09 +0500 |
---|---|---|
committer | Alexandr Akulich <akulichalexander@gmail.com> | 2016-02-16 07:58:39 +0500 |
commit | 4ac16b53992599cc82244aa58966e1f4d6062e34 (patch) | |
tree | 2d7bd4dcaf79112be556bbcf5c041a6531793286 | |
parent | da67156c3d0cdb697c000eb0cb1475745f6fc001 (diff) |
Added bare BaseChannelFileTransferType implementation.
-rw-r--r-- | TelepathyQt/base-channel-internal.h | 51 | ||||
-rw-r--r-- | TelepathyQt/base-channel.cpp | 349 | ||||
-rw-r--r-- | TelepathyQt/base-channel.h | 105 | ||||
-rw-r--r-- | TelepathyQt/service-types.h | 2 |
4 files changed, 507 insertions, 0 deletions
diff --git a/TelepathyQt/base-channel-internal.h b/TelepathyQt/base-channel-internal.h index c86e07bc..85623964 100644 --- a/TelepathyQt/base-channel-internal.h +++ b/TelepathyQt/base-channel-internal.h @@ -157,6 +157,57 @@ public: BaseChannelMessagesInterface *mInterface; }; +class TP_QT_NO_EXPORT BaseChannelFileTransferType::Adaptee : public QObject +{ + Q_OBJECT + Q_PROPERTY(uint state READ state) + Q_PROPERTY(QString contentType READ contentType) + Q_PROPERTY(QString filename READ filename) + Q_PROPERTY(qulonglong size READ size) + Q_PROPERTY(uint contentHashType READ contentHashType) + Q_PROPERTY(QString contentHash READ contentHash) + Q_PROPERTY(QString description READ description) + Q_PROPERTY(qlonglong date READ date) + Q_PROPERTY(Tp::SupportedSocketMap availableSocketTypes READ availableSocketTypes) + Q_PROPERTY(qulonglong transferredBytes READ transferredBytes) + Q_PROPERTY(qulonglong initialOffset READ initialOffset) + Q_PROPERTY(QString uri READ uri) + Q_PROPERTY(QString fileCollection READ fileCollection) + +public: + Adaptee(BaseChannelFileTransferType *interface); + ~Adaptee(); + + uint state() const; + QString contentType() const; + QString filename() const; + qulonglong size() const; + uint contentHashType() const; + QString contentHash() const; + QString description() const; + qlonglong date() const; + Tp::SupportedSocketMap availableSocketTypes() const; + qulonglong transferredBytes() const; + qulonglong initialOffset() const; + QString uri() const; + QString fileCollection() const; + +private Q_SLOTS: + void acceptFile(uint addressType, uint accessControl, const QDBusVariant &accessControlParam, qulonglong offset, + const Tp::Service::ChannelTypeFileTransferAdaptor::AcceptFileContextPtr &context); + void provideFile(uint addressType, uint accessControl, const QDBusVariant &accessControlParam, + const Tp::Service::ChannelTypeFileTransferAdaptor::ProvideFileContextPtr &context); + +Q_SIGNALS: + void fileTransferStateChanged(uint state, uint reason); + void transferredBytesChanged(qulonglong count); + void initialOffsetDefined(qulonglong initialOffset); + void uriDefined(const QString &uri); + +private: + BaseChannelFileTransferType *mInterface; +}; + class TP_QT_NO_EXPORT BaseChannelRoomListType::Adaptee : public QObject { Q_OBJECT diff --git a/TelepathyQt/base-channel.cpp b/TelepathyQt/base-channel.cpp index 720d58ed..c13e8f04 100644 --- a/TelepathyQt/base-channel.cpp +++ b/TelepathyQt/base-channel.cpp @@ -779,6 +779,355 @@ QString BaseChannelMessagesInterface::sendMessage(const Tp::MessagePartList &mes return token; } +// Chan.T.FileTransfer +// The BaseChannelFileTransferType code is fully or partially generated by the TelepathyQt-Generator. +struct TP_QT_NO_EXPORT BaseChannelFileTransferType::Private { + Private(BaseChannelFileTransferType *parent, + const QString &contentType, + const QString &filename, + qulonglong size, + uint contentHashType, + const QString &contentHash, + const QString &description, + const QDateTime &date, + const Tp::SupportedSocketMap &availableSocketTypes) + : state(Tp::FileTransferStatePending), + contentType(contentType), + filename(filename), + size(size), + contentHashType(contentHashType), + contentHash(contentHash), + description(description), + date(date), + availableSocketTypes(availableSocketTypes), + transferredBytes(0), + initialOffset(0), + adaptee(new BaseChannelFileTransferType::Adaptee(parent)) + { + } + + uint state; + QString contentType; + QString filename; + qulonglong size; + uint contentHashType; + QString contentHash; + QString description; + QDateTime date; + Tp::SupportedSocketMap availableSocketTypes; + qulonglong transferredBytes; + qulonglong initialOffset; + QString uri; + QString fileCollection; + AcceptFileCallback acceptFileCB; + ProvideFileCallback provideFileCB; + BaseChannelFileTransferType::Adaptee *adaptee; +}; + +BaseChannelFileTransferType::Adaptee::Adaptee(BaseChannelFileTransferType *interface) + : QObject(interface), + mInterface(interface) +{ +} + +BaseChannelFileTransferType::Adaptee::~Adaptee() +{ +} + +uint BaseChannelFileTransferType::Adaptee::state() const +{ + return mInterface->state(); +} + +QString BaseChannelFileTransferType::Adaptee::contentType() const +{ + return mInterface->contentType(); +} + +QString BaseChannelFileTransferType::Adaptee::filename() const +{ + return mInterface->filename(); +} + +qulonglong BaseChannelFileTransferType::Adaptee::size() const +{ + return mInterface->size(); +} + +uint BaseChannelFileTransferType::Adaptee::contentHashType() const +{ + return mInterface->contentHashType(); +} + +QString BaseChannelFileTransferType::Adaptee::contentHash() const +{ + return mInterface->contentHash(); +} + +QString BaseChannelFileTransferType::Adaptee::description() const +{ + return mInterface->description(); +} + +qlonglong BaseChannelFileTransferType::Adaptee::date() const +{ + return mInterface->date().toTime_t(); +} + +Tp::SupportedSocketMap BaseChannelFileTransferType::Adaptee::availableSocketTypes() const +{ + return mInterface->availableSocketTypes(); +} + +qulonglong BaseChannelFileTransferType::Adaptee::transferredBytes() const +{ + return mInterface->transferredBytes(); +} + +qulonglong BaseChannelFileTransferType::Adaptee::initialOffset() const +{ + return mInterface->initialOffset(); +} + +QString BaseChannelFileTransferType::Adaptee::uri() const +{ + return mInterface->uri(); +} + +QString BaseChannelFileTransferType::Adaptee::fileCollection() const +{ + return mInterface->fileCollection(); +} + +void BaseChannelFileTransferType::Adaptee::acceptFile(uint addressType, uint accessControl, const QDBusVariant &accessControlParam, qulonglong offset, + const Tp::Service::ChannelTypeFileTransferAdaptor::AcceptFileContextPtr &context) +{ + qDebug() << "BaseChannelFileTransferType::Adaptee::acceptFile"; + DBusError error; + QDBusVariant address = mInterface->acceptFile(addressType, accessControl, accessControlParam, offset, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(address); +} + +void BaseChannelFileTransferType::Adaptee::provideFile(uint addressType, uint accessControl, const QDBusVariant &accessControlParam, + const Tp::Service::ChannelTypeFileTransferAdaptor::ProvideFileContextPtr &context) +{ + qDebug() << "BaseChannelFileTransferType::Adaptee::provideFile"; + DBusError error; + QDBusVariant address = mInterface->provideFile(addressType, accessControl, accessControlParam, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(address); +} + +/** + * \class BaseChannelFileTransferType + * \ingroup servicecm + * \headerfile TelepathyQt/base-channel.h <TelepathyQt/BaseChannel> + * + * \brief Base class for implementations of Channel.Type.FileTransfer + */ + +/** + * Class constructor. + */ +BaseChannelFileTransferType::BaseChannelFileTransferType(const QString &contentType, + const QString &filename, + qulonglong size, + uint contentHashType, + const QString &contentHash, + const QString &description, + const QDateTime &date, + const Tp::SupportedSocketMap &availableSocketTypes) + : AbstractChannelInterface(TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER), + mPriv(new Private(this, contentType, filename, size, contentHashType, contentHash, description, date, availableSocketTypes)) +{ +} + +/** + * Class destructor. + */ +BaseChannelFileTransferType::~BaseChannelFileTransferType() +{ + 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 BaseChannelFileTransferType::immutableProperties() const +{ + QVariantMap map; + map.insert(TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER + QLatin1String(".ContentType"), + QVariant::fromValue(contentType())); + map.insert(TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER + QLatin1String(".Filename"), + QVariant::fromValue(filename())); + map.insert(TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER + QLatin1String(".Size"), + QVariant::fromValue(size())); + map.insert(TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER + QLatin1String(".ContentHashType"), + QVariant::fromValue(contentHashType())); + map.insert(TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER + QLatin1String(".ContentHash"), + QVariant::fromValue(contentHash())); + map.insert(TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER + QLatin1String(".Description"), + QVariant::fromValue(description())); + map.insert(TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER + QLatin1String(".Date"), + QVariant::fromValue(date().toTime_t())); + map.insert(TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER + QLatin1String(".AvailableSocketTypes"), + QVariant::fromValue(availableSocketTypes())); + return map; +} + +uint BaseChannelFileTransferType::state() const +{ + return mPriv->state; +} + +void BaseChannelFileTransferType::setState(uint state, uint reason) +{ + mPriv->state = state; + QMetaObject::invokeMethod(mPriv->adaptee, "fileTransferStateChanged", Q_ARG(uint, state), Q_ARG(uint, reason)); //Can simply use emit in Qt5 +} + +QString BaseChannelFileTransferType::contentType() const +{ + return mPriv->contentType; +} + +QString BaseChannelFileTransferType::filename() const +{ + return mPriv->filename; +} + +qulonglong BaseChannelFileTransferType::size() const +{ + return mPriv->size; +} + +uint BaseChannelFileTransferType::contentHashType() const +{ + return mPriv->contentHashType; +} + +QString BaseChannelFileTransferType::contentHash() const +{ + return mPriv->contentHash; +} + +QString BaseChannelFileTransferType::description() const +{ + return mPriv->description; +} + +QDateTime BaseChannelFileTransferType::date() const +{ + return mPriv->date; +} + +Tp::SupportedSocketMap BaseChannelFileTransferType::availableSocketTypes() const +{ + return mPriv->availableSocketTypes; +} + +qulonglong BaseChannelFileTransferType::transferredBytes() const +{ + return mPriv->transferredBytes; +} + +void BaseChannelFileTransferType::setTransferredBytes(qulonglong count) +{ + mPriv->transferredBytes = count; + QMetaObject::invokeMethod(mPriv->adaptee, "transferredBytesChanged", Q_ARG(qulonglong, count)); //Can simply use emit in Qt5 +} + +qulonglong BaseChannelFileTransferType::initialOffset() const +{ + return mPriv->initialOffset; +} + +void BaseChannelFileTransferType::setInitialOffset(qulonglong initialOffset) +{ + mPriv->initialOffset = initialOffset; +} + +QString BaseChannelFileTransferType::uri() const +{ + return mPriv->uri; +} + +void BaseChannelFileTransferType::setUri(const QString &uri) +{ + mPriv->uri = uri; +} + +QString BaseChannelFileTransferType::fileCollection() const +{ + return mPriv->fileCollection; +} + +void BaseChannelFileTransferType::setFileCollection(const QString &fileCollection) +{ + mPriv->fileCollection = fileCollection; +} + +void BaseChannelFileTransferType::createAdaptor() +{ + (void) new Tp::Service::ChannelTypeFileTransferAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + +void BaseChannelFileTransferType::setAcceptFileCallback(const AcceptFileCallback &cb) +{ + mPriv->acceptFileCB = cb; +} + +QDBusVariant BaseChannelFileTransferType::acceptFile(uint addressType, uint accessControl, const QDBusVariant &accessControlParam, qulonglong offset, DBusError *error) +{ + if (!mPriv->acceptFileCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return QDBusVariant(); + } + return mPriv->acceptFileCB(addressType, accessControl, accessControlParam, offset, error); +} + +void BaseChannelFileTransferType::setProvideFileCallback(const ProvideFileCallback &cb) +{ + mPriv->provideFileCB = cb; +} + +QDBusVariant BaseChannelFileTransferType::provideFile(uint addressType, uint accessControl, const QDBusVariant &accessControlParam, DBusError *error) +{ + if (!mPriv->provideFileCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return QDBusVariant(); + } + return mPriv->provideFileCB(addressType, accessControl, accessControlParam, error); +} + +void BaseChannelFileTransferType::fileTransferStateChanged(uint state, uint reason) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "fileTransferStateChanged", Q_ARG(uint, state), Q_ARG(uint, reason)); //Can simply use emit in Qt5 +} + +void BaseChannelFileTransferType::initialOffsetDefined(qulonglong initialOffset) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "initialOffsetDefined", Q_ARG(qulonglong, initialOffset)); //Can simply use emit in Qt5 +} + +void BaseChannelFileTransferType::uriDefined(const QString &uri) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "uriDefined", Q_ARG(QString, uri)); //Can simply use emit in Qt5 +} + // Chan.T.RoomList // The BaseChannelRoomListType code is fully or partially generated by the TelepathyQt-Generator. struct TP_QT_NO_EXPORT BaseChannelRoomListType::Private { diff --git a/TelepathyQt/base-channel.h b/TelepathyQt/base-channel.h index 4ef02d9a..856ac09e 100644 --- a/TelepathyQt/base-channel.h +++ b/TelepathyQt/base-channel.h @@ -222,6 +222,111 @@ private: Private *mPriv; }; +class TP_QT_EXPORT BaseChannelFileTransferType : public AbstractChannelInterface +{ + Q_OBJECT + Q_DISABLE_COPY(BaseChannelFileTransferType) + +public: + static BaseChannelFileTransferTypePtr create(const QString &contentType, + const QString &filename, + qulonglong size, + uint contentHashType, + const QString &contentHash, + const QString &description, + const QDateTime &date, + const Tp::SupportedSocketMap &availableSocketTypes) + { + return BaseChannelFileTransferTypePtr(new BaseChannelFileTransferType(contentType, + filename, + size, + contentHashType, + contentHash, + description, + date, + availableSocketTypes)); + } + template<typename BaseChannelFileTransferTypeSubclass> + static SharedPtr<BaseChannelFileTransferTypeSubclass> create(const QString &contentType, + const QString &filename, + qulonglong size, + uint contentHashType, + const QString &contentHash, + const QString &description, + const QDateTime &date, + const Tp::SupportedSocketMap &availableSocketTypes) + { + return SharedPtr<BaseChannelFileTransferTypeSubclass>( + new BaseChannelFileTransferTypeSubclass(contentType, + filename, + size, + contentHashType, + contentHash, + description, + date, + availableSocketTypes)); + } + + virtual ~BaseChannelFileTransferType(); + + QVariantMap immutableProperties() const; + + QString contentType() const; + QString filename() const; + qulonglong size() const; + uint contentHashType() const; + QString contentHash() const; + QString description() const; + QDateTime date() const; + Tp::SupportedSocketMap availableSocketTypes() const; + + uint state() const; + void setState(uint state, uint reason); + + qulonglong transferredBytes() const; + void setTransferredBytes(qulonglong count); + + qulonglong initialOffset() const; + void setInitialOffset(qulonglong initialOffset); + + QString uri() const; + void setUri(const QString &uri); + + QString fileCollection() const; + void setFileCollection(const QString &fileCollection); + + typedef Callback5<QDBusVariant, uint, uint, const QDBusVariant &, qulonglong, DBusError*> AcceptFileCallback; + void setAcceptFileCallback(const AcceptFileCallback &cb); + QDBusVariant acceptFile(uint addressType, uint accessControl, const QDBusVariant &accessControlParam, qulonglong offset, DBusError *error); + + typedef Callback4<QDBusVariant, uint, uint, const QDBusVariant &, DBusError*> ProvideFileCallback; + void setProvideFileCallback(const ProvideFileCallback &cb); + QDBusVariant provideFile(uint addressType, uint accessControl, const QDBusVariant &accessControlParam, DBusError *error); + + void fileTransferStateChanged(uint state, uint reason); + void initialOffsetDefined(qulonglong initialOffset); + void uriDefined(const QString &uri); + +protected: + BaseChannelFileTransferType(const QString &contentType, + const QString &filename, + qulonglong size, + uint contentHashType, + const QString &contentHash, + const QString &description, + const QDateTime &date, + const Tp::SupportedSocketMap &availableSocketTypes); + +private: + void createAdaptor(); + + class Adaptee; + friend class Adaptee; + struct Private; + friend struct Private; + Private *mPriv; +}; + class TP_QT_EXPORT BaseChannelRoomListType : public AbstractChannelInterface { Q_OBJECT diff --git a/TelepathyQt/service-types.h b/TelepathyQt/service-types.h index c63202cd..96d0a29c 100644 --- a/TelepathyQt/service-types.h +++ b/TelepathyQt/service-types.h @@ -58,6 +58,7 @@ class BaseChannel; class BaseChannelTextType; class BaseChannelCallType; class BaseChannelMessagesInterface; +class BaseChannelFileTransferType; class BaseChannelRoomListType; class BaseChannelServerAuthenticationType; class BaseChannelSASLAuthenticationInterface; @@ -102,6 +103,7 @@ typedef SharedPtr<BaseChannel> BaseChannelPtr; typedef SharedPtr<BaseChannelCallType> BaseChannelCallTypePtr; typedef SharedPtr<BaseChannelTextType> BaseChannelTextTypePtr; typedef SharedPtr<BaseChannelMessagesInterface> BaseChannelMessagesInterfacePtr; +typedef SharedPtr<BaseChannelFileTransferType> BaseChannelFileTransferTypePtr; typedef SharedPtr<BaseChannelRoomListType> BaseChannelRoomListTypePtr; typedef SharedPtr<BaseChannelServerAuthenticationType> BaseChannelServerAuthenticationTypePtr; typedef SharedPtr<BaseChannelSASLAuthenticationInterface> BaseChannelSASLAuthenticationInterfacePtr; |