File indexing completed on 2024-11-24 04:43:52

0001 /*
0002     SPDX-FileCopyrightText: 2015-2017 Krzysztof Nowicki <krissn@op.pl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "faketransferjob.h"
0008 
0009 #include <QUrl>
0010 
0011 #include <KIO/TransferJob>
0012 
0013 QQueue<FakeTransferJob::Verifier> FakeTransferJob::mVerifierQueue;
0014 
0015 FakeTransferJob::FakeTransferJob(const QByteArray &postData, const VerifierFn &fn, QObject *parent)
0016     : KIO::SpecialJob(QUrl(QStringLiteral("file:///tmp/")), QByteArray())
0017     , mPostData(postData)
0018     , mVerifier(fn)
0019 {
0020     Q_UNUSED(parent)
0021 
0022     metaObject()->invokeMethod(this, "callVerifier", Qt::QueuedConnection);
0023 }
0024 
0025 FakeTransferJob::~FakeTransferJob() = default;
0026 
0027 void FakeTransferJob::callVerifier()
0028 {
0029     mVerifier(this, mPostData);
0030 }
0031 
0032 void FakeTransferJob::postResponse(const QByteArray &resp)
0033 {
0034     mResponse = resp;
0035     qRegisterMetaType<KIO::Job *>();
0036     metaObject()->invokeMethod(this, "doData", Qt::QueuedConnection, Q_ARG(QByteArray, mResponse));
0037     metaObject()->invokeMethod(this, "doEmitResult", Qt::QueuedConnection);
0038 }
0039 
0040 void FakeTransferJob::doData(const QByteArray &resp)
0041 {
0042     Q_EMIT data(this, resp);
0043 }
0044 
0045 void FakeTransferJob::doEmitResult()
0046 {
0047     emitResult();
0048 }
0049 
0050 void FakeTransferJob::addVerifier(QObject *obj, const VerifierFn &fn)
0051 {
0052     Verifier vfy = {obj, fn};
0053     mVerifierQueue.enqueue(vfy);
0054 }
0055 
0056 FakeTransferJob::Verifier FakeTransferJob::getVerifier()
0057 {
0058     return mVerifierQueue.dequeue();
0059 }
0060 
0061 #include "moc_faketransferjob.cpp"