From 68f167995e7ba71a6f2e556a7a0eab3d234e2d1a Mon Sep 17 00:00:00 2001 From: Jonah BrĂ¼chert Date: Fri, 9 Sep 2022 23:15:10 +0200 Subject: Implement XEP-0448: Stateless File Sharing This adds a file sharing manager that is capable of using multiple back ends. Currently implemented are a normal HTTP File Upload backend and an encrypted HTTP File Upload. Jingle File Transfer could be implemented later. Co-authored-by: Linus Jahn --- src/client/QXmppFileSharingManager.h | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/client/QXmppFileSharingManager.h (limited to 'src/client/QXmppFileSharingManager.h') diff --git a/src/client/QXmppFileSharingManager.h b/src/client/QXmppFileSharingManager.h new file mode 100644 index 00000000..a7f4c5dd --- /dev/null +++ b/src/client/QXmppFileSharingManager.h @@ -0,0 +1,77 @@ +// SPDX-FileCopyrightText: 2022 Jonah BrĂ¼chert +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPFILESHARINGMANAGER_H +#define QXMPPFILESHARINGMANAGER_H + +#include "QXmppClientExtension.h" +#include "QXmppFileShare.h" +#include "QXmppFileSharingProvider.h" +#include "QXmppGlobal.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +class QIODevice; +class QXmppFileMetadata; + +class QXMPP_EXPORT QXmppFileSharingManager : public QXmppClientExtension +{ +public: + struct MetadataThumbnail + { + uint32_t width; + uint32_t height; + QByteArray data; + QMimeType mimeType; + }; + + struct MetadataGeneratorResult + { + std::optional dimensions; + std::optional length; + QVector thumbnails; + std::unique_ptr dataDevice; + }; + + using MetadataGenerator = std::function>(std::unique_ptr)>; + + QXmppFileSharingManager(); + + void setMetadataGenerator(MetadataGenerator &&generator); + + /// + /// \brief Register a provider for automatic downloads + /// \param manager A shared_ptr to a QXmppFileSharingProvider subclass + /// + template + void registerProivder(std::shared_ptr manager) + { + std::type_index index(typeid(typename ProviderType::SourceType)); + internalRegisterProvider(index, manager); + } + + std::shared_ptr sendFile(std::shared_ptr provider, + const QString &filePath, + const std::optional &description = {}); + + std::shared_ptr downloadFile(const QXmppFileShare &fileShare, + std::unique_ptr &&output); + +private: + void internalRegisterProvider(std::type_index, std::shared_ptr provider); + + MetadataGenerator m_metadataGenerator; + std::unordered_map> m_providers; +}; + +#endif // QXMPPFILESHARINGMANAGER_H -- cgit v1.2.3