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.
wilder-5.26
Alexander Lohnau 4 years ago
parent 92f60df666
commit 366a5b2dec
  1. 8
      components/shellprivate/widgetexplorer/kcategorizeditemsviewmodels.cpp
  2. 5
      components/shellprivate/widgetexplorer/kcategorizeditemsviewmodels_p.h
  3. 15
      components/shellprivate/widgetexplorer/plasmaappletitemmodel.cpp
  4. 1
      components/shellprivate/widgetexplorer/plasmaappletitemmodel_p.h

@ -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;

Loading…
Cancel
Save