aboutsummaryrefslogtreecommitdiff
path: root/src/client/QXmppFileSharingManager.h
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2022-10-02 20:36:11 +0200
committerLinus Jahn <lnj@kaidan.im>2022-10-02 23:01:13 +0200
commit2fe061ae4a5485201ecc79b163a2a3771d8f5be4 (patch)
treee81733ee9eec3cb347780b45522f4e2a4ee44aab /src/client/QXmppFileSharingManager.h
parentada1907bb5f22e0820e1d1d8004cc23f2246e74b (diff)
downloadqxmpp-2fe061ae4a5485201ecc79b163a2a3771d8f5be4.tar.gz
FileUpload/Download: Avoid unnecessary virtual functions
Diffstat (limited to 'src/client/QXmppFileSharingManager.h')
-rw-r--r--src/client/QXmppFileSharingManager.h102
1 files changed, 97 insertions, 5 deletions
diff --git a/src/client/QXmppFileSharingManager.h b/src/client/QXmppFileSharingManager.h
index b59eb46b..6224cf40 100644
--- a/src/client/QXmppFileSharingManager.h
+++ b/src/client/QXmppFileSharingManager.h
@@ -1,11 +1,14 @@
// SPDX-FileCopyrightText: 2022 Jonah BrĂ¼chert <jbb@kaidan.im>
+// SPDX-FileCopyrightText: 2022 Linus Jahn <lnj@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef QXMPPFILESHARINGMANAGER_H
#define QXMPPFILESHARINGMANAGER_H
+#include "QXmppBitsOfBinaryDataList.h"
#include "QXmppClientExtension.h"
+#include "QXmppFileShare.h"
#include "QXmppFileSharingProvider.h"
#include "QXmppGlobal.h"
@@ -19,9 +22,98 @@
#include <QSize>
class QIODevice;
+class QXmppFileDownloadPrivate;
class QXmppFileMetadata;
class QXmppFileShare;
class QXmppFileSharingManagerPrivate;
+class QXmppFileUploadPrivate;
+
+class QXMPP_EXPORT QXmppFileUpload : public QObject
+{
+ Q_OBJECT
+ /// Progress of the file upload between 0.0 and 1.0.
+ Q_PROPERTY(float progress READ progress NOTIFY progressChanged)
+public:
+ struct FileResult
+ {
+ QXmppFileShare fileShare;
+ QXmppBitsOfBinaryDataList dataBlobs;
+ };
+
+ using Result = std::variant<FileResult, QXmpp::Cancelled, QXmppError>;
+
+ ~QXmppFileUpload();
+
+ float progress() const;
+ Q_SIGNAL void progressChanged();
+
+ void cancel();
+ bool isFinished() const;
+ quint64 bytesTransferred() const;
+ quint64 bytesTotal() const;
+
+ Q_SIGNAL void finished(QXmppFileUpload::Result);
+
+private:
+ QXmppFileUpload();
+
+ void reportFinished(Result);
+
+ std::unique_ptr<QXmppFileUploadPrivate> d;
+ friend class QXmppFileSharingManager;
+};
+
+Q_DECLARE_METATYPE(QXmppFileUpload::Result);
+
+class QXMPP_EXPORT QXmppFileDownload : public QObject
+{
+ Q_OBJECT
+ /// Progress of the file download between 0.0 and 1.0.
+ Q_PROPERTY(float progress READ progress NOTIFY progressChanged)
+public:
+ enum HashVerificationResult {
+ ///
+ /// \brief File did not contain strong hashes (or no hashes at all) and no verification
+ /// was done.
+ ///
+ /// This value is not used when a hash value did not match. In that case the whole file
+ /// download returns an error.
+ ///
+ NoStrongHashes,
+ /// \brief The file integrity could be proved using a strong hash algorithm.
+ HashVerified,
+ };
+
+ struct Downloaded
+ {
+ HashVerificationResult hashVerificationResult;
+ };
+
+ using Result = std::variant<Downloaded, QXmpp::Cancelled, QXmppError>;
+
+ ~QXmppFileDownload();
+
+ float progress() const;
+ Q_SIGNAL void progressChanged();
+
+ void cancel();
+ bool isFinished() const;
+ quint64 bytesTransferred() const;
+ quint64 bytesTotal() const;
+
+ Q_SIGNAL void finished(QXmppFileDownload::Result);
+
+private:
+ QXmppFileDownload();
+
+ void reportProgress(quint64 bytesReceived, quint64 bytesTotal);
+ void reportFinished(Result);
+
+ std::unique_ptr<QXmppFileDownloadPrivate> d;
+ friend class QXmppFileSharingManager;
+};
+
+Q_DECLARE_METATYPE(QXmppFileDownload::Result);
class QXMPP_EXPORT QXmppFileSharingManager : public QXmppClientExtension
{
@@ -61,12 +153,12 @@ public:
internalRegisterProvider(index, manager);
}
- std::shared_ptr<QXmppUpload> sendFile(std::shared_ptr<QXmppFileSharingProvider> provider,
- const QString &filePath,
- const std::optional<QString> &description = {});
+ std::shared_ptr<QXmppFileUpload> 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);
+ std::shared_ptr<QXmppFileDownload> downloadFile(const QXmppFileShare &fileShare,
+ std::unique_ptr<QIODevice> output);
private:
friend class QXmppEncryptedFileSharingProvider;