kde-playground/plasma/runners/sleeper/krunner_sleeper.cpp
Ivailo Monev 3f463fe412 generic: move plasma projects to plasma directory, new lsof applet
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2024-05-17 07:08:36 +03:00

68 lines
2 KiB
C++

/*
This file is part of the KDE project
Copyright (C) 2024 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <QThread>
#include <KIcon>
#include <KDebug>
#include "krunner_sleeper.h"
static const int s_sleeptime = 5;
SleeperRunner::SleeperRunner(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
setObjectName("Sleeper runner");
setSpeed(AbstractRunner::SlowSpeed);
addSyntax(Plasma::RunnerSyntax("sleep", i18n("Sleep for some time")));
}
void SleeperRunner::init()
{
QThread::msleep(s_sleeptime * 1000);
}
void SleeperRunner::match(Plasma::RunnerContext &context)
{
const QString term = context.query();
if (term.length() < 4) {
return;
}
if (term.startsWith(QLatin1String("sleep"))) {
int sleeptime = term.mid(5).trimmed().toInt();
if (sleeptime <= 0) {
sleeptime = s_sleeptime;
}
Plasma::QueryMatch match(this);
match.setIcon(KIcon("applications-engineering"));
match.setText(i18n("Sleepy time: %1", sleeptime));
match.setData(sleeptime);
context.addMatch(match);
}
}
void SleeperRunner::run(const Plasma::QueryMatch &match)
{
const int sleeptime = match.data().toInt();
QThread::msleep(sleeptime * 1000);
}
#include "moc_krunner_sleeper.cpp"