File: fakejob.cpp

package info (click to toggle)
zanshin 25.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,668 kB
  • sloc: cpp: 35,501; xml: 1,405; sh: 16; makefile: 5
file content (69 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org>
 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/


#include "fakejob.h"

#include <QTimer>

FakeJob::FakeJob(QObject *parent)
    : KJob(parent),
      m_timer(new QTimer(this)),
      m_done(false),
      m_launched(false),
      m_errorCode(KJob::NoError)
{
    m_timer->setTimerType(Qt::PreciseTimer);
    m_timer->setSingleShot(true);
    connect(m_timer, &QTimer::timeout, this, &FakeJob::onTimeout);
}

void FakeJob::setExpectedError(int errorCode, const QString &errorText)
{
    m_errorCode = errorCode;
    m_errorText = errorText;
}

void FakeJob::start()
{
    if (!m_launched) {
        m_launched = true;
        m_timer->start(DURATION);
    }
}

void FakeJob::onTimeout()
{
    if (m_errorCode == KJob::NoError)
        m_done = true;

    setError(m_errorCode);
    setErrorText(m_errorText);
    emitResult();
}

bool FakeJob::isDone() const
{
    return m_done;
}

int FakeJob::expectedError() const
{
    return m_errorCode;
}

QString FakeJob::expectedErrorText() const
{
    return m_errorText;
}

bool FakeJob::doKill()
{
    setError(KJob::KilledJobError);
    emitResult();
    return true;
}

#include "moc_fakejob.cpp"