Commit 8f7a12d7 authored by Alexander Lohnau's avatar Alexander Lohnau 💬

Optimize runners using new properties

parent 73711583
......@@ -40,6 +40,7 @@ ActivityRunner::ActivityRunner(QObject *parent, const QVariantList &args)
qRegisterMetaType<KActivities::Consumer::ServiceStatus>();
connect(m_consumer, &KActivities::Consumer::serviceStatusChanged, this, &ActivityRunner::serviceStatusChanged);
serviceStatusChanged(m_activities->serviceStatus());
setTriggerWords({m_keyword, m_keywordi18n});
}
void ActivityRunner::serviceStatusChanged(KActivities::Consumer::ServiceStatus status)
......
......@@ -42,6 +42,7 @@ InstallerRunner::InstallerRunner(QObject *parent, const QVariantList &args)
setPriority(AbstractRunner::HighestPriority);
addSyntax(Plasma::RunnerSyntax(":q:", i18n("Looks for non-installed components according to :q:")));
setMinLetterCount(3);
}
InstallerRunner::~InstallerRunner()
......@@ -78,9 +79,6 @@ static QIcon componentIcon(const AppStream::Component &comp)
void InstallerRunner::match(Plasma::RunnerContext &context)
{
if(context.query().size() <= 2)
return;
const auto components = findComponentsByString(context.query()).mid(0, 3);
for (const AppStream::Component &component : components) {
......
......@@ -48,6 +48,7 @@ BookmarksRunner::BookmarksRunner( QObject* parent, const QVariantList &args )
i18n("List all web browser bookmarks")));
connect(this, &Plasma::AbstractRunner::prepare, this, &BookmarksRunner::prep);
setMinLetterCount(3);
}
BookmarksRunner::~BookmarksRunner() = default;
......@@ -66,10 +67,6 @@ void BookmarksRunner::prep()
void BookmarksRunner::match(Plasma::RunnerContext &context)
{
const QString term = context.query();
if ((term.length() < 3) && (!context.singleRunnerQueryMode())) {
return;
}
bool allBookmarks = term.compare(i18nc("list of all konqueror bookmarks", "bookmarks"),
Qt::CaseInsensitive) == 0;
......
......@@ -58,6 +58,7 @@ CalculatorRunner::CalculatorRunner(QObject *parent, const QVariantList &args)
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:="), description));
addAction(QStringLiteral("copyToClipboard"), QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy to Clipboard"));
setMinLetterCount(3);
}
CalculatorRunner::~CalculatorRunner()
......
......@@ -67,6 +67,13 @@ void KillRunner::reloadConfiguration()
syntaxes << Plasma::RunnerSyntax(m_triggerWord + QStringLiteral(":q:"),
i18n("Terminate running applications whose names match the query."));
setSyntaxes(syntaxes);
if (m_hasTrigger) {
setTriggerWords({m_triggerWord});
setMinLetterCount(minLetterCount() + 2); // Requires two characters after trigger word
} else {
setMinLetterCount(2);
setMatchRegex(QRegularExpression());
}
}
void KillRunner::prep()
......@@ -93,10 +100,6 @@ void KillRunner::cleanup()
void KillRunner::match(Plasma::RunnerContext &context)
{
QString term = context.query();
if (m_hasTrigger && !term.startsWith(m_triggerWord, Qt::CaseInsensitive)) {
return;
}
m_prepLock.lockForRead();
if (!m_processes) {
m_prepLock.unlock();
......@@ -112,10 +115,6 @@ void KillRunner::match(Plasma::RunnerContext &context)
term = term.right(term.length() - m_triggerWord.length());
if (term.length() < 2) {
return;
}
QList<Plasma::QueryMatch> matches;
const QList<KSysGuard::Process *> processlist = m_processes->getAllProcesses();
for (const KSysGuard::Process *process : processlist) {
......
......@@ -44,6 +44,7 @@ PlacesRunner::PlacesRunner(QObject* parent, const QVariantList &args)
// ensure the bookmarkmanager, etc. in the places model gets creates created in the main thread
// otherwise crashes ensue
m_helper = new PlacesRunnerHelper(this);
setMinLetterCount(3);
}
PlacesRunner::~PlacesRunner()
......@@ -88,11 +89,6 @@ void PlacesRunnerHelper::match(Plasma::RunnerContext *c)
}
const QString term = context.query();
if (term.length() < 3) {
return;
}
QList<Plasma::QueryMatch> matches;
const bool all = term.compare(i18n("places"), Qt::CaseInsensitive) == 0;
for (int i = 0; i <= m_places.rowCount(); i++) {
......
......@@ -35,8 +35,7 @@
K_EXPORT_PLASMA_RUNNER_WITH_JSON(PowerDevilRunner, "plasma-runner-powerdevil.json")
PowerDevilRunner::PowerDevilRunner(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args),
m_shortestCommand(1000)
: Plasma::AbstractRunner(parent, args)
{
qDBusRegisterMetaType< StringStringMap >();
......@@ -58,12 +57,7 @@ PowerDevilRunner::PowerDevilRunner(QObject *parent, const QVariantList &args)
<< i18nc("Note this is a KRunner keyword", "to ram")
<< i18nc("Note this is a KRunner keyword", "screen brightness")
<< i18nc("Note this is a KRunner keyword", "dim screen");
for (const QString &command : qAsConst(commands)) {
if (command.length() < m_shortestCommand) {
m_shortestCommand = command.length();
}
}
setTriggerWords(commands);
}
void PowerDevilRunner::updateSyntaxes()
......@@ -135,10 +129,6 @@ bool PowerDevilRunner::parseQuery(const QString& query, const QList<QRegExp>& rx
void PowerDevilRunner::match(Plasma::RunnerContext &context)
{
const QString term = context.query();
if (term.length() < m_shortestCommand) {
return;
}
QList<Plasma::QueryMatch> matches;
QString parameter;
......
......@@ -44,8 +44,6 @@ class PowerDevilRunner : public Plasma::AbstractRunner
void updateSyntaxes();
void addSuspendMatch(int value, QList<Plasma::QueryMatch> &matches);
bool parseQuery(const QString& query, const QList<QRegExp>& rxList, QString& parameter) const;
int m_shortestCommand;
};
Q_DECLARE_METATYPE(StringStringMap)
......
......@@ -46,6 +46,7 @@ RecentDocuments::RecentDocuments(QObject *parent, const QVariantList &args)
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Looks for documents recently used with names matching :q:.")));
addAction(QStringLiteral("openParentDir"), QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"));
setMinLetterCount(3);
}
RecentDocuments::~RecentDocuments()
......@@ -59,10 +60,6 @@ void RecentDocuments::match(Plasma::RunnerContext &context)
}
const QString term = context.query();
if (term.length() < 3) {
return;
}
auto query = UsedResources
| Activity::current()
| Order::RecentlyUsedFirst
......
......@@ -66,7 +66,7 @@ SessionRunner::SessionRunner(QObject *parent, const QVariantList &args)
//"SESSIONS" should not be translated; it's used programmaticaly
addSyntax(Plasma::RunnerSyntax(QStringLiteral("SESSIONS"), i18n("Lists all sessions")));
setMinLetterCount(3);
}
SessionRunner::~SessionRunner()
......@@ -127,10 +127,6 @@ void SessionRunner::match(Plasma::RunnerContext &context)
QList<Plasma::QueryMatch> matches;
if (term.size() < 3) {
return;
}
// first compare with SESSIONS. this must *NOT* be translated (i18n)
// as it is used as an internal command trigger (e.g. via d-bus),
// not as a user supplied query. and yes, "Ugh, magic strings"
......
......@@ -45,6 +45,7 @@ WebshortcutRunner::WebshortcutRunner(QObject *parent, const QVariantList& args)
loadSyntaxes();
configurePrivateBrowsingActions();
connect(KSycoca::self(), QOverload<>::of(&KSycoca::databaseChanged), this, &WebshortcutRunner::configurePrivateBrowsingActions);
setMinLetterCount(3);
}
WebshortcutRunner::~WebshortcutRunner()
......@@ -104,11 +105,6 @@ void WebshortcutRunner::configurePrivateBrowsingActions()
void WebshortcutRunner::match(Plasma::RunnerContext &context)
{
const QString term = context.query();
if (term.length() < 3 || !context.isValid()){
return;
}
const int delimIndex = term.indexOf(m_delimiter);
if (delimIndex == -1 || delimIndex == term.length() - 1) {
return;
......
......@@ -41,6 +41,7 @@ WindowedWidgetsRunner::WindowedWidgetsRunner(QObject *parent, const QVariantList
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds Plasma widgets whose name or description match :q:")));
addSyntax(Plasma::RunnerSyntax(i18nc("Note this is a KRunner keyword", "mobile applications"), i18n("list all Plasma widgets that can run as standalone applications")));
setMinLetterCount(3);
}
WindowedWidgetsRunner::~WindowedWidgetsRunner()
......@@ -50,11 +51,6 @@ WindowedWidgetsRunner::~WindowedWidgetsRunner()
void WindowedWidgetsRunner::match(Plasma::RunnerContext &context)
{
const QString term = context.query();
if (!context.singleRunnerQueryMode() && term.length() < 3) {
return;
}
QList<Plasma::QueryMatch> matches;
const auto &listMetadata = Plasma::PluginLoader::self()->listAppletMetaData(QString());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment