6#ifndef QXMPPFILESHARINGMANAGER_H
7#define QXMPPFILESHARINGMANAGER_H
9#include "QXmppBitsOfBinaryDataList.h"
10#include "QXmppClientExtension.h"
11#include "QXmppFileShare.h"
12#include "QXmppFileSharingProvider.h"
13#include "QXmppGlobal.h"
25class QXmppFileDownloadPrivate;
28class QXmppFileSharingManagerPrivate;
29class QXmppFileUploadPrivate;
31class QXMPP_EXPORT QXmppFileUpload :
public QObject
42 using Result = std::variant<FileResult, QXmpp::Cancelled, QXmppError>;
60 void reportFinished();
62 std::unique_ptr<QXmppFileUploadPrivate> d;
63 friend class QXmppFileSharingManager;
68class QXMPP_EXPORT QXmppFileDownload :
public QObject
91 using Result = std::variant<Downloaded, QXmpp::Cancelled, QXmppError>;
109 void reportProgress(quint64 bytesReceived, quint64
bytesTotal);
110 void reportFinished(
Result);
112 std::unique_ptr<QXmppFileDownloadPrivate> d;
113 friend class QXmppFileSharingManager;
121 struct MetadataThumbnail {
128 struct MetadataGeneratorResult {
129 std::optional<QSize> dimensions;
130 std::optional<uint32_t> length;
131 QVector<MetadataThumbnail> thumbnails;
132 std::unique_ptr<QIODevice> dataDevice;
135 using MetadataGenerator = std::function<QFuture<std::shared_ptr<MetadataGeneratorResult>>(std::unique_ptr<QIODevice>)>;
137 QXmppFileSharingManager();
138 ~QXmppFileSharingManager();
147 template<
typename Prov
iderType>
150 std::type_index index(
typeid(
typename ProviderType::SourceType));
151 internalRegisterProvider(index, manager);
154 std::shared_ptr<QXmppFileUpload> uploadFile(std::shared_ptr<QXmppFileSharingProvider> provider,
155 const QString &filePath,
156 const std::optional<QString> &description = {});
158 std::shared_ptr<QXmppFileDownload> downloadFile(
const QXmppFileShare &fileShare,
159 std::unique_ptr<QIODevice> output);
162 friend class QXmppEncryptedFileSharingProvider;
164 void internalRegisterProvider(std::type_index, std::shared_ptr<QXmppFileSharingProvider> provider);
165 std::shared_ptr<QXmppFileSharingProvider> providerForSource(
const std::any &source)
const;
167 std::unique_ptr<QXmppFileSharingManagerPrivate> d;
Definition QXmppBitsOfBinaryDataList.h:16
QXmppClientExtension()
Definition QXmppClientExtension.cpp:12
Q_SIGNAL void progressChanged()
Emitted when new bytes have been transferred.
bool isFinished() const
Returns whether the file transfer is finished.
Definition QXmppFileSharingManager.cpp:274
Result result() const
Returns the result of the download.
Definition QXmppFileSharingManager.cpp:300
quint64 bytesTransferred() const
Returns the number of bytes that have been uploaded or downloaded.
Definition QXmppFileSharingManager.cpp:282
quint64 bytesTotal() const
Returns the number of bytes that totally need to be transferred.
Definition QXmppFileSharingManager.cpp:290
float progress
Progress of the file download between 0.0 and 1.0.
Definition QXmppFileSharingManager.h:72
std::variant< Downloaded, QXmpp::Cancelled, QXmppError > Result
Contains QXmpp::Success (successfully finished), QXmpp::Cancelled (manually cancelled) or QXmppError ...
Definition QXmppFileSharingManager.h:91
HashVerificationResult
Definition QXmppFileSharingManager.h:74
@ HashVerified
The file integrity could be proved using a strong hash algorithm.
Definition QXmppFileSharingManager.h:84
@ NoStrongHashes
File did not contain strong hashes (or no hashes at all) and no verification was done.
Definition QXmppFileSharingManager.h:82
void cancel()
Cancels the file transfer. finished() will be emitted.
Definition QXmppFileSharingManager.cpp:263
Definition QXmppFileShare.h:50
void setMetadataGenerator(MetadataGenerator &&generator)
Register a function that is called when metadata needs to be gererated for a file.
Definition QXmppFileSharingManager.cpp:381
void registerProvider(std::shared_ptr< ProviderType > manager)
Register a provider for automatic downloads.
Definition QXmppFileSharingManager.h:148
std::function< QFuture< std::shared_ptr< MetadataGeneratorResult > >(std::unique_ptr< QIODevice >)> MetadataGenerator
Definition QXmppFileSharingManager.h:135
void cancel()
Cancels the file transfer. finished() will be emitted.
Definition QXmppFileSharingManager.cpp:120
std::variant< FileResult, QXmpp::Cancelled, QXmppError > Result
Contains FileResult (successfully finished), QXmpp::Cancelled (manually cancelled) or QXmppError (an ...
Definition QXmppFileSharingManager.h:42
quint64 bytesTotal() const
Returns the number of bytes that totally need to be transferred.
Definition QXmppFileSharingManager.cpp:148
Result result() const
Returns the result of the upload.
Definition QXmppFileSharingManager.cpp:158
bool isFinished() const
Returns whether the file transfer is finished.
Definition QXmppFileSharingManager.cpp:132
float progress
Progress of the file upload between 0.0 and 1.0.
Definition QXmppFileSharingManager.h:35
quint64 bytesTransferred() const
Returns the number of bytes that have been uploaded or downloaded.
Definition QXmppFileSharingManager.cpp:140
Q_SIGNAL void progressChanged()
Emitted when new bytes have been transferred.
Definition QXmppFileSharingManager.h:87
HashVerificationResult hashVerificationResult
Definition QXmppFileSharingManager.h:88
Contains QXmppFileShare of the uploaded file and possible data blobs containing referenced thumbnails...
Definition QXmppFileSharingManager.h:37
QXmppFileShare fileShare
File share with file metadata and file shares of the uploaded file.
Definition QXmppFileSharingManager.h:38
QXmppBitsOfBinaryDataList dataBlobs
Data blobs of possibly in the metadata referenced thumbnails.
Definition QXmppFileSharingManager.h:39