/* This file is part of the KDE project Copyright (C) 2024 Ivailo Monev 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 #include #include #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"