File indexing completed on 2025-01-05 04:59:50
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 #include "fakejob.h" 0008 0009 #include <QTimer> 0010 0011 FakeJob::FakeJob(QObject *parent) 0012 : KJob(parent), 0013 m_timer(new QTimer(this)), 0014 m_done(false), 0015 m_launched(false), 0016 m_errorCode(KJob::NoError) 0017 { 0018 m_timer->setTimerType(Qt::PreciseTimer); 0019 m_timer->setSingleShot(true); 0020 connect(m_timer, &QTimer::timeout, this, &FakeJob::onTimeout); 0021 } 0022 0023 void FakeJob::setExpectedError(int errorCode, const QString &errorText) 0024 { 0025 m_errorCode = errorCode; 0026 m_errorText = errorText; 0027 } 0028 0029 void FakeJob::start() 0030 { 0031 if (!m_launched) { 0032 m_launched = true; 0033 m_timer->start(DURATION); 0034 } 0035 } 0036 0037 void FakeJob::onTimeout() 0038 { 0039 if (m_errorCode == KJob::NoError) 0040 m_done = true; 0041 0042 setError(m_errorCode); 0043 setErrorText(m_errorText); 0044 emitResult(); 0045 } 0046 0047 bool FakeJob::isDone() const 0048 { 0049 return m_done; 0050 } 0051 0052 int FakeJob::expectedError() const 0053 { 0054 return m_errorCode; 0055 } 0056 0057 QString FakeJob::expectedErrorText() const 0058 { 0059 return m_errorText; 0060 } 0061 0062 #include "moc_fakejob.cpp"