diff options
Diffstat (limited to 'src/client/QXmppFileSharingManager.h')
| -rw-r--r-- | src/client/QXmppFileSharingManager.h | 77 |
1 files changed, 77 insertions, 0 deletions
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 <jbb@kaidan.im> +// +// 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 <any> +#include <functional> +#include <memory> +#include <typeindex> +#include <variant> + +#include <QFuture> +#include <QMimeType> +#include <QObject> +#include <QSize> + +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<QSize> dimensions; + std::optional<uint32_t> length; + QVector<MetadataThumbnail> thumbnails; + std::unique_ptr<QIODevice> dataDevice; + }; + + using MetadataGenerator = std::function<QFuture<std::shared_ptr<MetadataGeneratorResult>>(std::unique_ptr<QIODevice>)>; + + QXmppFileSharingManager(); + + void setMetadataGenerator(MetadataGenerator &&generator); + + /// + /// \brief Register a provider for automatic downloads + /// \param manager A shared_ptr to a QXmppFileSharingProvider subclass + /// + template<typename ProviderType> + void registerProivder(std::shared_ptr<ProviderType> manager) + { + std::type_index index(typeid(typename ProviderType::SourceType)); + internalRegisterProvider(index, manager); + } + + std::shared_ptr<QXmppUpload> sendFile(std::shared_ptr<QXmppFileSharingProvider> provider, + const QString &filePath, + const std::optional<QString> &description = {}); + + std::shared_ptr<QXmppDownload> downloadFile(const QXmppFileShare &fileShare, + std::unique_ptr<QIODevice> &&output); + +private: + void internalRegisterProvider(std::type_index, std::shared_ptr<QXmppFileSharingProvider> provider); + + MetadataGenerator m_metadataGenerator; + std::unordered_map<std::type_index, std::shared_ptr<QXmppFileSharingProvider>> m_providers; +}; + +#endif // QXMPPFILESHARINGMANAGER_H |
