Commit 40e20eb5 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Optimize runners using new properties

This will prevent unnecessary thread spawing.
parent 7c9f163f
......@@ -44,16 +44,13 @@ void CharacterRunner::reloadConfiguration()
addSyntax(Plasma::RunnerSyntax(m_triggerWord + QStringLiteral(":q:"),
i18n("Creates Characters from :q: if it is a hexadecimal code or defined alias.")));
setTriggerWords({m_triggerWord});
setMinLetterCount(minLetterCount() + 1);
}
void CharacterRunner::match(Plasma::RunnerContext &context)
{
QString term = context.query().remove(QLatin1Char(' '));
if (term.length() < 2 || !term.startsWith(m_triggerWord) || !context.isValid()) {
return;
}
term = term.remove(0, m_triggerWord.length()); //remove the triggerword
//replace aliases by their hex.-code
......
......@@ -50,6 +50,8 @@ void ConverterRunner::init()
addAction(copyUnitActionId, QIcon::fromTheme(QStringLiteral("edit-copy")),
QStringLiteral("Copy unit and number"));
actionList = {action(copyActionId), action(copyUnitActionId)};
setMinLetterCount(2);
setMatchRegex(valueRegex);
}
ConverterRunner::~ConverterRunner() = default;
......@@ -57,10 +59,6 @@ ConverterRunner::~ConverterRunner() = default;
void ConverterRunner::match(Plasma::RunnerContext &context)
{
const QString term = context.query();
if (term.size() < 2 || !context.isValid()) {
return;
}
const QRegularExpressionMatch valueRegexMatch = valueRegex.match(context.query());
if (!valueRegexMatch.hasMatch()) {
return;
......
......@@ -26,6 +26,7 @@ DateTimeRunner::DateTimeRunner(QObject *parent, const QVariantList &args)
addSyntax(Plasma::RunnerSyntax(dateWord + QLatin1String( " :q:" ), i18n("Displays the current date in a given timezone")));
addSyntax(Plasma::RunnerSyntax(timeWord, i18n("Displays the current time")));
addSyntax(Plasma::RunnerSyntax(timeWord + QLatin1String( " :q:" ), i18n("Displays the current time in a given timezone")));
setTriggerWords({timeWord, dateWord});
}
DateTimeRunner::~DateTimeRunner()
......
......@@ -32,24 +32,24 @@ void DictionaryRunner::reloadConfiguration()
{
KConfigGroup c = config();
m_triggerWord = c.readEntry(CONFIG_TRIGGERWORD, i18nc("Trigger word before word to define", "define"));
if (!m_triggerWord.isEmpty())
if (!m_triggerWord.isEmpty()) {
m_triggerWord.append(QLatin1Char(' '));
setTriggerWords({m_triggerWord});
} else {
setMatchRegex(QRegularExpression());
}
setSyntaxes(QList<Plasma::RunnerSyntax>() << Plasma::RunnerSyntax(Plasma::RunnerSyntax(i18nc("Dictionary keyword", "%1:q:", m_triggerWord), i18n("Finds the definition of :q:."))));
}
void DictionaryRunner::match(Plasma::RunnerContext &context)
{
QString query = context.query();
if (!query.startsWith(m_triggerWord, Qt::CaseInsensitive))
return;
query.remove(0, m_triggerWord.length());
if (query.startsWith(m_triggerWord, Qt::CaseInsensitive))
query.remove(0, m_triggerWord.length());
if (query.isEmpty())
return;
QString returnedQuery = m_engine->lookupWord(query);
if (!context.isValid())
return;
static const QRegExp removeHtml(QLatin1String("<[^>]*>"));
QString definitions(returnedQuery);
definitions.remove(QLatin1Char('\r')).remove(removeHtml);
......
......@@ -43,6 +43,7 @@ KateSessions::KateSessions(QObject *parent, const QVariantList &args)
connect(m_sessionWatch, &KDirWatch::created, this, &KateSessions::loadSessions);
connect(m_sessionWatch, &KDirWatch::deleted, this, &KateSessions::loadSessions);
loadSessions();
setTriggerWords({m_triggerWord});
}
KateSessions::~KateSessions()
......@@ -60,20 +61,12 @@ void KateSessions::loadSessions()
}
m_sessions = sessions;
suspendMatching(m_sessions.isEmpty());
}
void KateSessions::match(Plasma::RunnerContext &context)
{
QString term = context.query();
if (term.length() < 3 || m_sessions.isEmpty() || !context.isValid()) {
return;
}
// Kate writes sessions as desktop actions in the local .desktop file =>
// they are already available from the "Applications" Runner and in the normal launcher
if (!term.startsWith(m_triggerWord, Qt::CaseInsensitive)) {
return;
}
bool listAll = false;
if (term.trimmed().compare(m_triggerWord, Qt::CaseInsensitive) == 0) {
listAll = true;
......
......@@ -52,6 +52,7 @@ void KonsoleProfiles::init()
connect(m_profileFilesWatch, &KDirWatch::deleted, this, &KonsoleProfiles::loadProfiles);
loadProfiles();
setMinLetterCount(3);
}
void KonsoleProfiles::loadProfiles()
......@@ -89,10 +90,6 @@ void KonsoleProfiles::loadProfiles()
void KonsoleProfiles::match(Plasma::RunnerContext &context)
{
QString term = context.query();
if (term.length() < 3 || !context.isValid()) {
return;
}
term = term.remove(m_triggerWord).simplified();
for (const KonsoleProfileData &data: qAsConst(m_profiles)) {
if (data.displayName.contains(term, Qt::CaseInsensitive)) {
......
......@@ -113,6 +113,14 @@ void SpellCheckRunner::reloadConfiguration()
s.addExampleQuery(QStringLiteral(":q:"));
}
if (m_requireTriggerWord) {
setTriggerWords({m_triggerWord});
setMinLetterCount(minLetterCount() + 2); // We want at least two letters after the trigger word
} else {
setMinLetterCount(2);
setMatchRegex(QRegularExpression());
}
setSyntaxes({s});
}
......
Supports Markdown
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