2024-04-19 00:38:21 +03:00
|
|
|
/*
|
|
|
|
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"))) {
|
2024-04-19 00:41:37 +03:00
|
|
|
int sleeptime = term.mid(5).trimmed().toInt();
|
2024-04-19 00:38:21 +03:00
|
|
|
if (sleeptime <= 0) {
|
|
|
|
sleeptime = s_sleeptime;
|
|
|
|
}
|
|
|
|
Plasma::QueryMatch match(this);
|
2024-04-19 00:43:54 +03:00
|
|
|
match.setIcon(KIcon("applications-engineering"));
|
2024-04-19 00:38:21 +03:00
|
|
|
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"
|