File indexing completed on 2024-04-21 04:59:27

0001 // SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 #include "filetransferpseudojob.h"
0005 #include <KLocalizedString>
0006 #include <QDebug>
0007 #include <QUrl>
0008 
0009 FileTransferPseudoJob::FileTransferPseudoJob(Operation operation, const QString &path, const QString &eventId)
0010     : KJob()
0011     , m_path(path)
0012     , m_eventId(eventId)
0013     , m_operation(operation)
0014 {
0015 }
0016 
0017 void FileTransferPseudoJob::fileTransferProgress(const QString &id, qint64 progress, qint64 total)
0018 {
0019     if (id != m_eventId) {
0020         return;
0021     }
0022     setProcessedAmount(Unit::Bytes, progress);
0023     setTotalAmount(Unit::Bytes, total);
0024 }
0025 
0026 void FileTransferPseudoJob::fileTransferCompleted(const QString &id, const QUrl &localFile)
0027 {
0028     Q_UNUSED(localFile);
0029     if (id != m_eventId) {
0030         return;
0031     }
0032     emitResult();
0033 }
0034 
0035 void FileTransferPseudoJob::fileTransferFailed(const QString &id, const QString &errorMessage)
0036 {
0037     if (id != m_eventId) {
0038         return;
0039     }
0040     setErrorText(errorMessage);
0041     emitResult();
0042 }
0043 
0044 void FileTransferPseudoJob::start()
0045 {
0046     setTotalAmount(Unit::Files, 1);
0047     Q_EMIT description(this,
0048                        m_operation == Download ? i18nc("Job heading, like 'Copying'", "Downloading") : i18nc("Job heading, like 'Copying'", "Uploading"),
0049                        {i18nc("The URL being downloaded/uploaded", "Source"), m_path},
0050                        {i18nc("The location being downloaded to", "Destination"), m_path});
0051 }