Commit 72cebd84 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Cleanup runners

parent 73f96c83
......@@ -37,9 +37,7 @@ K_EXPORT_PLASMA_RUNNER(installer, InstallerRunner)
InstallerRunner::InstallerRunner(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
Q_UNUSED(args)
setObjectName("Installation Suggestions");
setObjectName(QStringLiteral("Installation Suggestions"));
setPriority(AbstractRunner::HighestPriority);
addSyntax(Plasma::RunnerSyntax(":q:", i18n("Looks for non-installed components according to :q:")));
......
......@@ -43,9 +43,7 @@ K_EXPORT_PLASMA_RUNNER(bookmarksrunner, BookmarksRunner)
BookmarksRunner::BookmarksRunner( QObject* parent, const QVariantList &args )
: Plasma::AbstractRunner(parent, args), m_browser(nullptr), m_browserFactory(new BrowserFactory(this))
{
Q_UNUSED(args)
//qDebug() << "Creating BookmarksRunner";
setObjectName( QStringLiteral("Bookmarks" ));
setObjectName(QStringLiteral("Bookmarks"));
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds web browser bookmarks matching :q:.")));
setDefaultSyntax(Plasma::RunnerSyntax(i18nc("list of all web browser bookmarks", "bookmarks"),
i18n("List all web browser bookmarks")));
......@@ -53,10 +51,7 @@ BookmarksRunner::BookmarksRunner( QObject* parent, const QVariantList &args )
connect(this, &Plasma::AbstractRunner::prepare, this, &BookmarksRunner::prep);
}
BookmarksRunner::~BookmarksRunner()
{
}
BookmarksRunner::~BookmarksRunner() = default;
void BookmarksRunner::prep()
{
......@@ -69,11 +64,8 @@ void BookmarksRunner::prep()
m_browser->prepare();
}
void BookmarksRunner::match(Plasma::RunnerContext &context)
{
if(! m_browser) return;
const QString term = context.query();
if ((term.length() < 3) && (!context.singleRunnerQueryMode())) {
return;
......
......@@ -26,9 +26,9 @@
#include "browsers/chromefindprofile.h"
#include "browsers/chrome.h"
Browser *BrowserFactory::find(const QString& browserName, QObject* parent)
Browser *BrowserFactory::find(const QString &browserName, QObject *parent)
{
if(m_previousBrowserName == browserName) {
if (m_previousBrowserName == browserName) {
return m_previousBrowser;
}
delete m_previousBrowser;
......
......@@ -45,10 +45,9 @@ void FetchSqlite::prepare()
void FetchSqlite::teardown()
{
QString connectionPrefix = m_databaseFile + "-";
const QString connectionPrefix = m_databaseFile + "-";
const auto connections = QSqlDatabase::connectionNames();
for (auto c : connections) {
for (const auto &c : connections) {
if (c.startsWith(connectionPrefix)) {
qCDebug(RUNNER_BOOKMARKS) << "Closing connection" << c;
QSqlDatabase::removeDatabase(c);
......
......@@ -36,21 +36,17 @@
#include <KLocalizedString>
#include <krunner/querymatch.h>
static const QString s_copyToClipboardId = QStringLiteral("copyToClipboard");
K_EXPORT_PLASMA_RUNNER(calculatorrunner, CalculatorRunner)
CalculatorRunner::CalculatorRunner( QObject* parent, const QVariantList &args )
CalculatorRunner::CalculatorRunner(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
Q_UNUSED(args)
#ifdef ENABLE_QALCULATE
m_engine = new QalculateEngine;
setSpeed(SlowSpeed);
#endif
setObjectName( QStringLiteral("Calculator" ));
setObjectName(QStringLiteral("Calculator"));
setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File |
Plasma::RunnerContext::NetworkLocation | Plasma::RunnerContext::Executable |
Plasma::RunnerContext::ShellCommand);
......@@ -61,7 +57,7 @@ CalculatorRunner::CalculatorRunner( QObject* parent, const QVariantList &args )
addSyntax(Plasma::RunnerSyntax(QStringLiteral("=:q:"), description));
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:="), description));
addAction(s_copyToClipboardId, QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy to Clipboard"));
addAction(QStringLiteral("copyToClipboard"), QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy to Clipboard"));
}
CalculatorRunner::~CalculatorRunner()
......@@ -71,7 +67,7 @@ CalculatorRunner::~CalculatorRunner()
#endif
}
void CalculatorRunner::powSubstitutions(QString& cmd)
void CalculatorRunner::powSubstitutions(QString &cmd)
{
if (cmd.contains(QLatin1String("e+"), Qt::CaseInsensitive)) {
cmd.replace(QLatin1String("e+"), QLatin1String("*10^"), Qt::CaseInsensitive);
......@@ -328,8 +324,8 @@ QString CalculatorRunner::calculate(const QString& term, bool *isApproximate)
void CalculatorRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
{
Q_UNUSED(context);
if (match.selectedAction() == action(s_copyToClipboardId)) {
Q_UNUSED(context)
if (match.selectedAction()) {
#ifdef ENABLE_QALCULATE
m_engine->copyToClipboard();
#else
......@@ -342,7 +338,7 @@ QList<QAction *> CalculatorRunner::actionsForMatch(const Plasma::QueryMatch &mat
{
Q_UNUSED(match)
return {action(s_copyToClipboardId)};
return actions().values();
}
QMimeData * CalculatorRunner::mimeDataForMatch(const Plasma::QueryMatch &match)
......
......@@ -36,7 +36,7 @@ class CalculatorRunner : public Plasma::AbstractRunner
Q_OBJECT
public:
CalculatorRunner(QObject* parent, const QVariantList &args);
CalculatorRunner(QObject *parent, const QVariantList &args);
~CalculatorRunner() override;
void match(Plasma::RunnerContext &context) override;
......@@ -47,10 +47,10 @@ class CalculatorRunner : public Plasma::AbstractRunner
QMimeData * mimeDataForMatch(const Plasma::QueryMatch &match) override;
private:
QString calculate(const QString& term, bool *isApproximate);
void userFriendlySubstitutions(QString& cmd);
void powSubstitutions(QString& cmd);
void hexSubstitutions(QString& cmd);
QString calculate(const QString &term, bool *isApproximate);
void userFriendlySubstitutions(QString &cmd);
void powSubstitutions(QString &cmd);
void hexSubstitutions(QString &cmd);
#ifdef ENABLE_QALCULATE
QalculateEngine* m_engine;
......
......@@ -40,7 +40,6 @@ QAtomicInt QalculateEngine::s_counter;
QalculateEngine::QalculateEngine(QObject* parent):
QObject(parent)
{
m_lastResult = "";
s_counter.ref();
if (!CALCULATOR) {
new Calculator();
......@@ -66,7 +65,7 @@ void QalculateEngine::updateExchangeRates()
QUrl dest = QUrl::fromLocalFile(QFile::decodeName(CALCULATOR->getExchangeRatesFileName().c_str()));
KIO::Job* getJob = KIO::file_copy(source, dest, -1, KIO::Overwrite | KIO::HideProgressInfo);
connect( getJob, &KJob::result, this, &QalculateEngine::updateResult );
connect(getJob, &KJob::result, this, &QalculateEngine::updateResult);
}
void QalculateEngine::updateResult(KJob* job)
......@@ -79,10 +78,10 @@ void QalculateEngine::updateResult(KJob* job)
}
}
QString QalculateEngine::evaluate(const QString& expression, bool *isApproximate)
QString QalculateEngine::evaluate(const QString &expression, bool *isApproximate)
{
if (expression.isEmpty()) {
return "";
return QString();
}
QString input = expression;
......
......@@ -35,7 +35,7 @@ public:
QString lastResult() const { return m_lastResult; }
public Q_SLOTS:
QString evaluate(const QString& expression, bool *isApproximate = nullptr);
QString evaluate(const QString &expression, bool *isApproximate = nullptr);
void updateExchangeRates();
void copyToClipboard(bool flag = true);
......
......@@ -88,7 +88,7 @@ void KillRunnerConfig::defaults()
m_ui->triggerWord->setText(i18n("kill"));
m_ui->sorting->setCurrentIndex(m_ui->sorting->findData((int) NONE));
emit markAsChanged();
markAsChanged();
}
#include "killrunner_config.moc"
......@@ -38,7 +38,6 @@ K_EXPORT_PLASMA_RUNNER(locations, LocationsRunner)
LocationsRunner::LocationsRunner(QObject *parent, const QVariantList& args)
: Plasma::AbstractRunner(parent, args)
{
Q_UNUSED(args);
// set the name shown after the result in krunner window
setObjectName(QStringLiteral("Locations"));
setIgnoredTypes(Plasma::RunnerContext::Executable | Plasma::RunnerContext::ShellCommand);
......@@ -183,9 +182,6 @@ void LocationsRunner::run(const Plasma::RunnerContext &context, const Plasma::Qu
location = convertCaseInsensitivePath(location);
//qDebug() << "command: " << context.query();
//qDebug() << "url: " << location << data;
QUrl urlToRun(KUriFilter::self()->filteredUri(location, {QStringLiteral("kshorturifilter")}));
new KRun(urlToRun, nullptr);
......
......@@ -36,9 +36,7 @@ K_EXPORT_PLASMA_RUNNER(placesrunner, PlacesRunner)
PlacesRunner::PlacesRunner(QObject* parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
// qRegisterMetaType
Q_UNUSED(args)
setObjectName( QStringLiteral("Places" ));
setObjectName(QStringLiteral("Places"));
Plasma::RunnerSyntax defaultSyntax(i18n("places"), i18n("Lists all file manager locations"));
setDefaultSyntax(defaultSyntax);
addSyntax(defaultSyntax);
......
......@@ -40,7 +40,7 @@ PowerDevilRunner::PowerDevilRunner(QObject *parent, const QVariantList &args)
{
qDBusRegisterMetaType< StringStringMap >();
setObjectName( QLatin1String("PowerDevil" ));
setObjectName(QStringLiteral("PowerDevil"));
setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File |
Plasma::RunnerContext::NetworkLocation | Plasma::RunnerContext::Help);
updateStatus();
......
......@@ -38,17 +38,14 @@ using namespace KActivities::Stats::Terms;
K_EXPORT_PLASMA_RUNNER(recentdocuments, RecentDocuments)
static const QString s_openParentDirId = QStringLiteral("openParentDir");
RecentDocuments::RecentDocuments(QObject *parent, const QVariantList& args)
RecentDocuments::RecentDocuments(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
Q_UNUSED(args);
setObjectName( QStringLiteral("Recent Documents" ));
setObjectName(QStringLiteral("Recent Documents"));
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Looks for documents recently used with names matching :q:.")));
addAction(s_openParentDirId, QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"));
addAction(QStringLiteral("openParentDir"), QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"));
}
RecentDocuments::~RecentDocuments()
......@@ -72,11 +69,11 @@ void RecentDocuments::match(Plasma::RunnerContext &context)
| Agent::any()
// we search only on file name, as KActivity does not support better options
| Url("/*/" + term + "*")
| Limit(30);
| Limit(20);
const auto result = new ResultModel(query);
for (int i = 0; i < result->rowCount(); i++) {
for (int i = 0; i < result->rowCount(); ++i) {
const auto index = result->index(i, 0);
const auto url = QUrl::fromUserInput(result->data(index, ResultModel::ResourceRole).toString(),
......@@ -92,7 +89,7 @@ void RecentDocuments::match(Plasma::RunnerContext &context)
if (url.fileName() == term) {
relevance = 1.0;
match.setType(Plasma::QueryMatch::ExactMatch);
} else if(url.fileName().startsWith(term)) {
} else if (url.fileName().startsWith(term)) {
relevance = 0.9;
match.setType(Plasma::QueryMatch::PossibleMatch);
}
......@@ -114,7 +111,7 @@ void RecentDocuments::run(const Plasma::RunnerContext &context, const Plasma::Qu
const QUrl url = match.data().toUrl();
if (match.selectedAction() == action(s_openParentDirId)) {
if (match.selectedAction()) {
KIO::highlightInFileManager({url});
return;
}
......@@ -125,17 +122,12 @@ void RecentDocuments::run(const Plasma::RunnerContext &context, const Plasma::Qu
QList<QAction *> RecentDocuments::actionsForMatch(const Plasma::QueryMatch &match)
{
Q_UNUSED(match)
QList<QAction *> actions;
const QUrl url = match.data().toUrl();
if (url.isLocalFile()) {
actions << action(s_openParentDirId);
return actions().values();
}
return actions;
return {};
}
QMimeData * RecentDocuments::mimeDataForMatch(const Plasma::QueryMatch& match)
......
......@@ -51,7 +51,8 @@ void ServiceRunnerTest::initTestCase()
QDir(appsPath).removeRecursively();
QVERIFY(QDir().mkpath(appsPath));
auto fixtureDir = QDir(QFINDTESTDATA("fixtures"));
for(auto fileInfo : fixtureDir.entryInfoList(QDir::Files)) {
const auto infoList = fixtureDir.entryInfoList(QDir::Files);
for (const auto &fileInfo : infoList) {
auto source = fileInfo.absoluteFilePath();
auto target = appsPath + QDir::separator() + fileInfo.fileName();
QVERIFY2(QFile::copy(fileInfo.absoluteFilePath(), target),
......@@ -82,7 +83,8 @@ void ServiceRunnerTest::testChromeAppsRelevance()
bool chromeFound = false;
bool signalFound = false;
for (auto match : context.matches()) {
const auto matches = context.matches();
for (const auto &match : matches) {
qDebug() << "matched" << match.text();
if (!match.text().contains(QLatin1String("ServiceRunnerTest"))) {
continue;
......@@ -112,7 +114,8 @@ void ServiceRunnerTest::testKonsoleVsYakuakeComment()
bool konsoleFound = false;
bool yakuakeFound = false;
for (auto match : context.matches()) {
const auto matches = context.matches();
for (const auto &match : matches) {
qDebug() << "matched" << match.text();
if (!match.text().contains(QLatin1String("ServiceRunnerTest"))) {
continue;
......@@ -146,7 +149,8 @@ void ServiceRunnerTest::testSystemSettings()
bool systemSettingsFound = false;
bool foreignSystemSettingsFound = false;
for (auto match : context.matches()) {
const auto matches = context.matches();
for (const auto &match : matches) {
qDebug() << "matched" << match.text();
if (match.text() == QLatin1String("System Settings ServiceRunnerTest")) {
systemSettingsFound = true;
......
......@@ -404,9 +404,7 @@ private:
ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
Q_UNUSED(args)
setObjectName( QStringLiteral("Application" ));
setObjectName(QStringLiteral("Application"));
setPriority(AbstractRunner::HighestPriority);
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds applications whose name or description match :q:")));
......@@ -416,10 +414,7 @@ ServiceRunner::~ServiceRunner() = default;
QStringList ServiceRunner::categories() const
{
QStringList cat;
cat << i18n("Applications") << i18n("System Settings");
return cat;
return {i18n("Applications"), i18n("System Settings")};
}
QIcon ServiceRunner::categoryIcon(const QString& category) const
......@@ -444,7 +439,7 @@ void ServiceRunner::match(Plasma::RunnerContext &context)
void ServiceRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
{
Q_UNUSED(context);
Q_UNUSED(context)
const QUrl dataUrl = match.data().toUrl();
......
......@@ -32,7 +32,7 @@ K_EXPORT_PLASMA_RUNNER(calculatorrunner, SessionRunner)
SessionRunner::SessionRunner(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
setObjectName( QLatin1String("Sessions" ));
setObjectName(QStringLiteral("Sessions"));
setPriority(LowPriority);
setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File |
Plasma::RunnerContext::NetworkLocation);
......
......@@ -27,7 +27,6 @@ WebshortcutRunner::WebshortcutRunner(QObject *parent, const QVariantList& args)
: Plasma::AbstractRunner(parent, args),
m_match(this), m_filterBeforeRun(false)
{
Q_UNUSED(args);
setObjectName(QStringLiteral("Web Shortcut"));
setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File | Plasma::RunnerContext::Executable);
......
......@@ -36,9 +36,7 @@ K_EXPORT_PLASMA_RUNNER(windowedwidgets, WindowedWidgetsRunner)
WindowedWidgetsRunner::WindowedWidgetsRunner(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
Q_UNUSED(args)
setObjectName( QLatin1String("WindowedWidgets" ));
setObjectName(QStringLiteral("WindowedWidgets"));
setPriority(AbstractRunner::HighestPriority);
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds Plasma widgets whose name or description match :q:")));
......
......@@ -39,8 +39,7 @@ WindowsRunner::WindowsRunner(QObject* parent, const QVariantList& args)
: AbstractRunner(parent, args),
m_inSession(false)
{
Q_UNUSED(args)
setObjectName( QLatin1String("Windows") );
setObjectName(QStringLiteral("Windows"));
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds windows whose name, window class or window role match :q:. "
"It is possible to interact with the windows by using one of the following keywords: "
......@@ -125,14 +124,14 @@ void WindowsRunner::matchSessionComplete()
// Called in the secondary thread
void WindowsRunner::match(Plasma::RunnerContext& context)
{
// will run block as long as gatherInfo has not finished
QMutexLocker locker(&m_mutex);
QString term = context.query();
if (!context.singleRunnerQueryMode() && (term.length() < 3)) {
return;
}
// will run block as long as gatherInfo has not finished
QMutexLocker locker(&m_mutex);
QList<Plasma::QueryMatch> matches;
// check if the search term ends with an action keyword
......
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