File indexing completed on 2024-10-06 07:36:07

0001 // SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <KJob>
0007 #include <QString>
0008 
0009 /**
0010  * @class FileTransferPseudoJob
0011  *
0012  * A class inherited from KJob to track a file download.
0013  *
0014  * @sa KJob
0015  */
0016 class FileTransferPseudoJob : public KJob
0017 {
0018 public:
0019     enum Operation {
0020         Download,
0021         Upload,
0022     };
0023     Q_ENUM(Operation)
0024     FileTransferPseudoJob(Operation operation, const QString &srcDest, const QString &path);
0025 
0026     /**
0027      * @brief Set the current number of bytes transferred.
0028      */
0029     void fileTransferProgress(const QString &id, qint64 progress, qint64 total);
0030 
0031     /**
0032      * @brief Set the file transfer as complete.
0033      */
0034     void fileTransferCompleted(const QString &id, const QUrl &localFile);
0035 
0036     /**
0037      * @brief Set the file transfer as failed.
0038      */
0039     void fileTransferFailed(const QString &id, const QString &errorMessage = {});
0040 
0041     /**
0042      * @brief Start the file transfer.
0043      */
0044     void start() override;
0045 
0046 private:
0047     QString m_path;
0048     QString m_eventId;
0049     Operation m_operation;
0050 };