File indexing completed on 2024-05-26 05:19:10

0001 /*
0002     This file is part of the KDE project
0003     Copyright (C) 2008 Kevin Ottens <ervin@kde.org>
0004 
0005     Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
0006     Author: Kevin Ottens <kevin@kdab.com>
0007 
0008     This library is free software; you can redistribute it and/or
0009     modify it under the terms of the GNU Library General Public
0010     License as published by the Free Software Foundation; either
0011     version 2 of the License, or (at your option) any later version.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Library General Public License for more details.
0017 
0018     You should have received a copy of the GNU Library General Public License
0019     along with this library; see the file COPYING.LIB.  If not, write to
0020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021     Boston, MA 02110-1301, USA.
0022   */
0023 
0024 #include "mockjob.h"
0025 
0026 #include "job_p.h"
0027 #include "session.h"
0028 #include "session_p.h"
0029 #include <QtCore/QTimer>
0030 
0031 class MockJobPrivate : public KIMAP2::JobPrivate
0032 {
0033 public:
0034     MockJobPrivate(KIMAP2::Session *session, const QString &name)
0035         : KIMAP2::JobPrivate(session, name),
0036           timeout(10)
0037     { }
0038 
0039     ~MockJobPrivate() { }
0040 
0041     QByteArray command;
0042     int timeout;
0043 };
0044 
0045 MockJob::MockJob(KIMAP2::Session *session)
0046     : KIMAP2::Job(*new MockJobPrivate(session, "Mock"))
0047 {
0048 }
0049 
0050 void MockJob::doStart()
0051 {
0052     Q_D(MockJob);
0053     if (isNull()) {
0054         QTimer::singleShot(d->timeout, this, SLOT(done()));
0055     } else {
0056         d->sessionInternal()->setSocketTimeout(d->timeout);
0057         d->tags << d->sessionInternal()->sendCommand(d->command);
0058     }
0059 }
0060 
0061 void MockJob::done()
0062 {
0063     emitResult();
0064 }
0065 
0066 void MockJob::setCommand(const QByteArray &command)
0067 {
0068     Q_D(MockJob);
0069     d->command = command;
0070 }
0071 
0072 QByteArray MockJob::command() const
0073 {
0074     Q_D(const MockJob);
0075     return d->command;
0076 }
0077 
0078 void MockJob::setTimeout(int timeout)
0079 {
0080     Q_D(MockJob);
0081     d->timeout = timeout;
0082 }
0083 
0084 int MockJob::timeout() const
0085 {
0086     Q_D(const MockJob);
0087     return d->timeout;
0088 }
0089 
0090 bool MockJob::isNull() const
0091 {
0092     Q_D(const MockJob);
0093     return d->command.isEmpty();
0094 }