Commit 366a5b2d authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Read keywords from applets in widgetexplorer

This allows for better searches that just the name and description.
This also takes the original keywords into account and not just the translated ones.
parent 92f60df6
Pipeline #211708 passed with stage
in 7 minutes and 17 seconds
......@@ -47,7 +47,13 @@ int AbstractItem::running() const
bool AbstractItem::matches(const QString &pattern) const
{
return name().contains(pattern, Qt::CaseInsensitive) || description().contains(pattern, Qt::CaseInsensitive);
if (name().contains(pattern, Qt::CaseInsensitive) || description().contains(pattern, Qt::CaseInsensitive)) {
return true;
}
const QStringList itemKeywords = keywords();
return std::any_of(itemKeywords.begin(), itemKeywords.end(), [&pattern](const QString &keyword) {
return keyword.startsWith(pattern, Qt::CaseInsensitive);
});
}
// DefaultFilterModel
......
......@@ -65,6 +65,11 @@ public:
*/
virtual bool passesFiltering(const Filter &filter) const = 0;
virtual QStringList keywords() const
{
return {};
};
private:
};
......
......@@ -151,6 +151,21 @@ bool PlasmaAppletItem::matches(const QString &pattern) const
return AbstractItem::matches(pattern);
}
QStringList PlasmaAppletItem::keywords() const
{
const static QString keywordsJsonKey = QStringLiteral("X-KDE-Keywords");
constexpr QLatin1Char separator(',');
const QJsonObject rawData = m_info.rawData();
if (rawData.contains(keywordsJsonKey)) {
QStringList keywords = m_info.value(keywordsJsonKey).split(separator);
keywords << KJsonUtils::readTranslatedString(rawData, keywordsJsonKey).split(separator);
keywords.removeDuplicates();
return keywords;
}
return {};
}
bool PlasmaAppletItem::isLocal() const
{
return m_local;
......
......@@ -34,6 +34,7 @@ public:
int running() const override;
bool isLocal() const;
bool matches(const QString &pattern) const override;
QStringList keywords() const override;
// set how many instances of this applet are running
void setRunning(int count) override;
......
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