aboutsummaryrefslogtreecommitdiff
path: root/src/client/QXmppFileSharingProvider.h
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2022-10-02 02:45:09 +0200
committerLinus Jahn <lnj@kaidan.im>2022-10-02 23:01:13 +0200
commitb871f6d3557c20fc7d1456e5080c33ea90795c84 (patch)
treefda2457ed2728a4cd6d346bce8168523b88c2b15 /src/client/QXmppFileSharingProvider.h
parent6ee26103c5383cef8664d9e7d19c96c83f9a89af (diff)
downloadqxmpp-b871f6d3557c20fc7d1456e5080c33ea90795c84.tar.gz
Generate QXmppUpload/Download only by FileSharingManager
Previously all the providers had to subclass the QXmppUpload/Download. It should be much easier to do additional tasks (e.g. hashing after downloading) now because the manager (and not the provider) decides when to emit the finished signal. Making the encrypted source provider able to handle arbitrary unencrypted sources should be possible too.
Diffstat (limited to 'src/client/QXmppFileSharingProvider.h')
-rw-r--r--src/client/QXmppFileSharingProvider.h52
1 files changed, 45 insertions, 7 deletions
diff --git a/src/client/QXmppFileSharingProvider.h b/src/client/QXmppFileSharingProvider.h
index cde719db..02e6252a 100644
--- a/src/client/QXmppFileSharingProvider.h
+++ b/src/client/QXmppFileSharingProvider.h
@@ -1,14 +1,18 @@
// 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 QXMPPFILESHARINGPROVIDER_H
#define QXMPPFILESHARINGPROVIDER_H
+#include "QXmppError.h"
#include "QXmppGlobal.h"
#include <any>
+#include <functional>
#include <memory>
+#include <variant>
class QIODevice;
class QXmppFileMetadata;
@@ -16,7 +20,7 @@ class QXmppUpload;
class QXmppDownload;
///
-/// \brief The interface of a provider for the FileSharingManager
+/// \brief The interface of a provider for the QXmppFileSharingManager
///
/// To use it, implement all the pure virtual functions,
/// and add a using declaration for the type of source you want to handle.
@@ -27,26 +31,60 @@ class QXmppDownload;
class QXMPP_EXPORT QXmppFileSharingProvider
{
public:
+ /// Contains QXmpp::Success (successfully finished), QXmpp::Cancelled (manually cancelled) or
+ /// QXmppError (an error occured while downloading).
+ using DownloadResult = std::variant<QXmpp::Success, QXmpp::Cancelled, QXmppError>;
+
+ /// Contains std::any (created file source), QXmpp::Cancelled (manually cancelled) or
+ /// QXmppError (an error occured while uploading).
+ using UploadResult = std::variant<std::any /* source */, QXmpp::Cancelled, QXmppError>;
+
+ /// Used to control ongoing downloads
+ class Download
+ {
+ public:
+ virtual ~Download() = default;
+ /// Cancels the download.
+ virtual void cancel() = 0;
+ };
+
+ /// Used to control ongoing uploads
+ class Upload
+ {
+ public:
+ virtual ~Upload() = default;
+ /// Cancels the upload.
+ virtual void cancel() = 0;
+ };
+
/// \cond
virtual ~QXmppFileSharingProvider() = default;
/// \endcond
///
/// \brief Handles the download of files for this provider
- /// \param source A type-erased source object. The provider will only ever have to handle its own sources,
- /// so this can be safely casted to a concrete type.
+ /// \param source A type-erased source object. The provider will only ever have to handle
+ /// its own sources, so this can safely be casted to the defined source type.
/// \param target QIODevice into which the received data should be written
- /// \return A subclass of QXmppDownload
+ /// \param reportProgress Can be called to report received bytes and total bytes
+ /// \param reportFinished Finalizes the download, no more progress must be reported after this
///
- virtual auto downloadFile(const std::any &source, std::unique_ptr<QIODevice> &&target) -> std::shared_ptr<QXmppDownload> = 0;
+ virtual auto downloadFile(const std::any &source,
+ std::unique_ptr<QIODevice> target,
+ std::function<void(quint64, quint64)> reportProgress,
+ std::function<void(DownloadResult)> reportFinished) -> std::shared_ptr<Download> = 0;
///
/// \brief Handles the upload of a file for this provider
/// \param source A QIODevice from which data for uploading should be read.
/// \param info Metadata of the file
- /// \return A subclass of QXmppUpload
+ /// \param reportProgress Can be called to report sent bytes and total bytes
+ /// \param reportFinished Finalizes the upload, no more progress must be reported after this
///
- virtual auto uploadFile(std::unique_ptr<QIODevice> source, const QXmppFileMetadata &info) -> std::shared_ptr<QXmppUpload> = 0;
+ virtual auto uploadFile(std::unique_ptr<QIODevice> source,
+ const QXmppFileMetadata &info,
+ std::function<void(quint64, quint64)> reportProgress,
+ std::function<void(UploadResult)> reportFinished) -> std::shared_ptr<Upload> = 0;
};
#endif // QXMPPFILESHARINGPROVIDER_H