File indexing completed on 2024-05-12 05:48:10

0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0002 // SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
0003 
0004 #include "getcommand.h"
0005 
0006 #include <KIO/TransferJob>
0007 
0008 GetCommand::GetCommand(const QUrl &url, const QString &remoteService, const QDBusObjectPath &objectPath, QObject *parent)
0009     : BusObject(remoteService, objectPath, parent)
0010     , m_url(url)
0011 {
0012 }
0013 
0014 void GetCommand::start()
0015 {
0016     if (!isAuthorized()) {
0017         sendErrorReply(QDBusError::AccessDenied);
0018         return;
0019     }
0020 
0021     auto job = KIO::get(m_url);
0022     setParent(job);
0023     connect(job, &KIO::TransferJob::data, this, [this](KIO::Job *, const QByteArray &blob) {
0024         sendSignal(&GetCommand::data, blob);
0025     });
0026     connect(job, &KIO::TransferJob::mimeTypeFound, this, [this](KIO::Job *, const QString &mimetype) {
0027         sendSignal(&GetCommand::mimeTypeFound, mimetype);
0028     });
0029     connect(job, &KIO::TransferJob::result, this, [this, job](KJob *) {
0030         sendSignal(&GetCommand::result, job->error(), job->errorString());
0031     });
0032 }
0033 
0034 void GetCommand::kill()
0035 {
0036     doKill();
0037 }