From 9da683c56605151eb3f8150b64e9a25a20a731d1 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 19 Apr 2024 00:38:21 +0300 Subject: [PATCH] plasma-runners: new sleeper runner for testing purporses only! Signed-off-by: Ivailo Monev --- plasma-runners/CMakeLists.txt | 12 ++++ plasma-runners/sleeper/CMakeLists.txt | 19 ++++++ plasma-runners/sleeper/krunner_sleeper.cpp | 68 +++++++++++++++++++ plasma-runners/sleeper/krunner_sleeper.h | 41 +++++++++++ .../sleeper/plasma-runner-sleeper.desktop | 13 ++++ 5 files changed, 153 insertions(+) create mode 100644 plasma-runners/CMakeLists.txt create mode 100644 plasma-runners/sleeper/CMakeLists.txt create mode 100644 plasma-runners/sleeper/krunner_sleeper.cpp create mode 100644 plasma-runners/sleeper/krunner_sleeper.h create mode 100644 plasma-runners/sleeper/plasma-runner-sleeper.desktop diff --git a/plasma-runners/CMakeLists.txt b/plasma-runners/CMakeLists.txt new file mode 100644 index 00000000..9c57001f --- /dev/null +++ b/plasma-runners/CMakeLists.txt @@ -0,0 +1,12 @@ +project(plasma-runners) + +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + include(FeatureSummary) + + find_package(KDELibs4 4.23.0 REQUIRED) + + include_directories(${KDE4_INCLUDES}) + add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) +endif() + +add_subdirectory(sleeper) diff --git a/plasma-runners/sleeper/CMakeLists.txt b/plasma-runners/sleeper/CMakeLists.txt new file mode 100644 index 00000000..839643d2 --- /dev/null +++ b/plasma-runners/sleeper/CMakeLists.txt @@ -0,0 +1,19 @@ +set(krunner_sleeper_SRCS + krunner_sleeper.cpp +) + +kde4_add_plugin(krunner_sleeper ${krunner_sleeper_SRCS}) +target_link_libraries(krunner_sleeper + KDE4::kdecore + KDE4::plasma +) + +install( + TARGETS krunner_sleeper + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} +) + +install( + FILES plasma-runner-sleeper.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR} +) diff --git a/plasma-runners/sleeper/krunner_sleeper.cpp b/plasma-runners/sleeper/krunner_sleeper.cpp new file mode 100644 index 00000000..cbe6345e --- /dev/null +++ b/plasma-runners/sleeper/krunner_sleeper.cpp @@ -0,0 +1,68 @@ +/* + 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(4).trimmed().toInt(); + if (sleeptime <= 0) { + sleeptime = s_sleeptime; + } + Plasma::QueryMatch match(this); + match.setIcon(KIcon("timer")); + 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" diff --git a/plasma-runners/sleeper/krunner_sleeper.h b/plasma-runners/sleeper/krunner_sleeper.h new file mode 100644 index 00000000..865e9e65 --- /dev/null +++ b/plasma-runners/sleeper/krunner_sleeper.h @@ -0,0 +1,41 @@ +/* + 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. +*/ + +#ifndef KRUNNER_SLEEPER_H +#define KRUNNER_SLEEPER_H + +#include + +class SleeperRunner : public Plasma::AbstractRunner +{ + Q_OBJECT + +public: + SleeperRunner(QObject *parent, const QVariantList &args); + + void match(Plasma::RunnerContext &context); + void run(const Plasma::QueryMatch &match); + +protected slots: + void init(); +}; + +K_EXPORT_PLASMA_RUNNER(sleeper, SleeperRunner) + +#endif // KRUNNER_SLEEPER_H diff --git a/plasma-runners/sleeper/plasma-runner-sleeper.desktop b/plasma-runners/sleeper/plasma-runner-sleeper.desktop new file mode 100644 index 00000000..7f2b5492 --- /dev/null +++ b/plasma-runners/sleeper/plasma-runner-sleeper.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +Name=Sleeper runner +Comment=Sleeps for some time +X-KDE-ServiceTypes=Plasma/Runner +Type=Service +Icon=applications-engineering +X-KDE-Library=krunner_sleeper +X-KDE-PluginInfo-Author=Ivailo Monev +X-KDE-PluginInfo-Email=xakepa10@gmail.com +X-KDE-PluginInfo-Name=Sleeper runner +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true