aboutsummaryrefslogtreecommitdiff
path: root/src/client/QXmppFileSharingManager.h
diff options
context:
space:
mode:
authorJonah BrĂ¼chert <jbb@kaidan.im>2022-09-09 23:15:10 +0200
committerLinus Jahn <lnj@kaidan.im>2022-09-29 23:46:36 +0200
commit68f167995e7ba71a6f2e556a7a0eab3d234e2d1a (patch)
treede645b606d96f01da7ea6db63e90224519a89de3 /src/client/QXmppFileSharingManager.h
parent7b02df3ef42ccb2d8c40eea901c5c6dd4b140204 (diff)
downloadqxmpp-68f167995e7ba71a6f2e556a7a0eab3d234e2d1a.tar.gz
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 <lnj@kaidan.im>
Diffstat (limited to 'src/client/QXmppFileSharingManager.h')
-rw-r--r--src/client/QXmppFileSharingManager.h77
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