Commit fab5b5e2 authored by Harald Sitter's avatar Harald Sitter 🦄

some static analyzer improvements for service runner

Summary:
- be more consty (and don't risk detatching containers)
- init members
- don't ql1s to qstring
- use auto when newing an object

Test Plan: test passes

Reviewers: broulik

Reviewed By: broulik

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28138
parent 86f0e491
......@@ -29,7 +29,7 @@
#include "../servicerunner.h"
#include <locale.h>
#include <clocale>
class ServiceRunnerTest : public QObject
{
......
......@@ -105,27 +105,27 @@ private:
return ret;
}
qreal increaseMatchRelavance(const KService::Ptr &service, QVector<QStringRef> &strList, QString category)
qreal increaseMatchRelavance(const KService::Ptr &service, const QVector<QStringRef> &strList, const QString &category)
{
//Increment the relevance based on all the words (other than the first) of the query list
qreal relevanceIncrement = 0;
for(int i=1; i<strList.size(); i++)
{
for(int i = 1; i < strList.size(); ++i) {
const auto &str = strList.at(i);
if (category == QLatin1String("Name")) {
if (service->name().contains(strList[i], Qt::CaseInsensitive)) {
if (service->name().contains(str, Qt::CaseInsensitive)) {
relevanceIncrement += 0.01;
}
} else if (category == QLatin1String("GenericName")) {
if (service->genericName().contains(strList[i], Qt::CaseInsensitive)) {
if (service->genericName().contains(str, Qt::CaseInsensitive)) {
relevanceIncrement += 0.01;
}
} else if (category == QLatin1String("Exec")) {
if (service->exec().contains(strList[i], Qt::CaseInsensitive)) {
if (service->exec().contains(str, Qt::CaseInsensitive)) {
relevanceIncrement += 0.01;
}
} else if (category == QLatin1String("Comment")) {
if (service->comment().contains(strList[i], Qt::CaseInsensitive)) {
if (service->comment().contains(str, Qt::CaseInsensitive)) {
relevanceIncrement += 0.01;
}
}
......@@ -337,7 +337,8 @@ private:
continue;
}
for (const KServiceAction &action : service->actions()) {
const auto actions = service->actions();
for (const KServiceAction &action : actions) {
if (action.text().isEmpty() || action.exec().isEmpty() || hasSeen(action)) {
continue;
}
......@@ -377,7 +378,7 @@ private:
QList<Plasma::QueryMatch> matches;
QString query;
QString term;
int weightedTermLength;
int weightedTermLength = -1;
};
ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args)
......@@ -391,9 +392,7 @@ ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args)
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds applications whose name or description match :q:")));
}
ServiceRunner::~ServiceRunner()
{
}
ServiceRunner::~ServiceRunner() = default;
QStringList ServiceRunner::categories() const
{
......@@ -455,14 +454,14 @@ QMimeData * ServiceRunner::mimeDataForMatch(const Plasma::QueryMatch &match)
QString path = service->entryPath();
if (!QDir::isAbsolutePath(path)) {
path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kservices5/") + path);
path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kservices5/") + path);
}
if (path.isEmpty()) {
return nullptr;
}
QMimeData *data = new QMimeData();
auto *data = new QMimeData();
data->setUrls(QList<QUrl>{QUrl::fromLocalFile(path)});
return data;
}
......
......@@ -41,7 +41,7 @@ class ServiceRunner : public Plasma::AbstractRunner
~ServiceRunner() override;
void match(Plasma::RunnerContext &context) override;
void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &action) override;
void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) override;
QStringList categories() const override;
QIcon categoryIcon(const QString& category) const override;
......
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