File indexing completed on 2024-11-24 04:44:44

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2008 Kevin Ottens <ervin@kde.org>
0004 
0005     SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
0006     SPDX-FileContributor: Kevin Ottens <kevin@kdab.com>
0007 
0008     SPDX-License-Identifier: LGPL-2.0-or-later
0009   */
0010 
0011 #include "mockjob.h"
0012 
0013 #include "job_p.h"
0014 #include "session.h"
0015 #include "session_p.h"
0016 #include <KLocalizedString>
0017 #include <QTimer>
0018 
0019 class MockJobPrivate : public KIMAP::JobPrivate
0020 {
0021 public:
0022     MockJobPrivate(KIMAP::Session *session, const QString &name)
0023         : KIMAP::JobPrivate(session, name)
0024         , timeout(10)
0025     {
0026     }
0027 
0028     ~MockJobPrivate()
0029     {
0030     }
0031 
0032     QByteArray command;
0033     int timeout;
0034 };
0035 
0036 MockJob::MockJob(KIMAP::Session *session)
0037     : KIMAP::Job(*new MockJobPrivate(session, i18n("Mock")))
0038 {
0039 }
0040 
0041 void MockJob::doStart()
0042 {
0043     Q_D(MockJob);
0044     if (isNull()) {
0045         QTimer::singleShot(d->timeout, this, SLOT(done()));
0046     } else {
0047         d->sessionInternal()->setSocketTimeout(d->timeout);
0048         d->tags << d->sessionInternal()->sendCommand(d->command);
0049     }
0050 }
0051 
0052 void MockJob::done()
0053 {
0054     emitResult();
0055 }
0056 
0057 void MockJob::setCommand(const QByteArray &command)
0058 {
0059     Q_D(MockJob);
0060     d->command = command;
0061 }
0062 
0063 QByteArray MockJob::command() const
0064 {
0065     Q_D(const MockJob);
0066     return d->command;
0067 }
0068 
0069 void MockJob::setTimeout(int timeout)
0070 {
0071     Q_D(MockJob);
0072     d->timeout = timeout;
0073 }
0074 
0075 int MockJob::timeout() const
0076 {
0077     Q_D(const MockJob);
0078     return d->timeout;
0079 }
0080 
0081 bool MockJob::isNull() const
0082 {
0083     Q_D(const MockJob);
0084     return d->command.isEmpty();
0085 }
0086 
0087 #include "moc_mockjob.cpp"