mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 18:32:51 +00:00
plasma-runners: new sleeper runner
for testing purporses only! Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
722206baa4
commit
9da683c566
5 changed files with 153 additions and 0 deletions
12
plasma-runners/CMakeLists.txt
Normal file
12
plasma-runners/CMakeLists.txt
Normal file
|
@ -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)
|
19
plasma-runners/sleeper/CMakeLists.txt
Normal file
19
plasma-runners/sleeper/CMakeLists.txt
Normal file
|
@ -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}
|
||||
)
|
68
plasma-runners/sleeper/krunner_sleeper.cpp
Normal file
68
plasma-runners/sleeper/krunner_sleeper.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
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(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"
|
41
plasma-runners/sleeper/krunner_sleeper.h
Normal file
41
plasma-runners/sleeper/krunner_sleeper.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef KRUNNER_SLEEPER_H
|
||||
#define KRUNNER_SLEEPER_H
|
||||
|
||||
#include <plasma/abstractrunner.h>
|
||||
|
||||
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
|
13
plasma-runners/sleeper/plasma-runner-sleeper.desktop
Normal file
13
plasma-runners/sleeper/plasma-runner-sleeper.desktop
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue