Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / runtime / kuiserver / tests / kuiservertest.cpp
blob061d0c4297cd6617fb59271cdcee5e7a42a36fad
1 /**
2 * This file is part of the KDE libraries
3 * Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "kuiservertest.h"
21 #include <kio/jobuidelegate.h>
22 #include <QTimer>
23 #include <kapplication.h>
24 #include <kcmdlineargs.h>
25 #include <klocale.h>
26 #include <kio/jobclasses.h>
27 #include <kuiserverjobtracker.h>
29 KJobTest::KJobTest(int numberOfSeconds)
30 : KIO::Job(), timer(new QTimer(this)), clockTimer(new QTimer(this)),
31 seconds(numberOfSeconds), total(numberOfSeconds)
33 setCapabilities(KJob::NoCapabilities);
36 KJobTest::~KJobTest()
40 void KJobTest::start()
42 connect(timer, SIGNAL(timeout()), this,
43 SLOT(timerTimeout()));
45 connect(clockTimer, SIGNAL(timeout()), this,
46 SLOT(updateMessage()));
48 timer->setSingleShot(true);
49 timer->start(seconds * 1000);
51 updateMessage();
53 clockTimer->start(1000);
56 void KJobTest::timerTimeout()
58 clockTimer->stop();
60 emitResult();
62 QTimer::singleShot(0, QCoreApplication::instance(), SLOT(quit()));
65 void KJobTest::updateMessage()
67 emit infoMessage(this, i18n("Testing kuiserver (%1 seconds remaining)", seconds), i18n("Testing kuiserver (%1 seconds remaining)", seconds));
68 emitPercent(total-seconds, total);
70 seconds--;
73 bool KJobTest::doSuspend()
75 clockTimer->stop();
77 Job::doSuspend();
79 return true;
82 #include "kuiservertest.moc"
84 int main(int argc, char **argv)
86 KCmdLineArgs::init(argc, argv, "kjobtest", 0, ki18n("KJobTest"), "0.01", ki18n("A KJob tester"));
88 KApplication app;
90 KJobTest *myJob = new KJobTest(10 /* 10 seconds before it gets removed */);
91 myJob->setUiDelegate(new KIO::JobUiDelegate());
92 KIO::getJobTracker()->registerJob(myJob);
93 myJob->start();
95 return app.exec();