diff --git a/applets/dde-apps/amappitem.cpp b/applets/dde-apps/amappitem.cpp index 6c0606748..e77565a70 100644 --- a/applets/dde-apps/amappitem.cpp +++ b/applets/dde-apps/amappitem.cpp @@ -47,6 +47,7 @@ AMAppItem::AMAppItem(const QDBusObjectPath &path, const ObjectInterfaceMap &sour auto xDeepinVendor = appInfo.value(u8"X_Deepin_Vendor").toString(); // Keep the default generic name for launchpad's English search while NameRole remains localized. AppItem::setGenericName(genericNameMap.value(DEFAULT_KEY)); + AppItem::setKeywords(getLocaleOrDefaultValue(qdbus_cast(appInfo.value(u8"Keywords")), locale, DEFAULT_KEY)); AppItem::setVendor(xDeepinVendor); if (QStringLiteral("deepin") == xDeepinVendor && !localizedGenericName.isEmpty()) { @@ -124,12 +125,13 @@ void AMAppItem::setOnDesktop(bool on) AppItem::setOnDesktop(on); } -QString AMAppItem::getLocaleOrDefaultValue(const QStringMap &value, const QString &localeCode, const QString &fallbackKey) +template +T AMAppItem::getLocaleOrDefaultValue(const QMap &value, const QString &localeCode, const QString &fallbackKey) const { if (value.contains(localeCode)) { return value.value(localeCode); } else { - QString fallbackValue = value.value(fallbackKey); + T fallbackValue = value.value(fallbackKey); if (localeCode.contains('_')) { QString prefix = localeCode.split('_')[0]; return value.value(prefix, fallbackValue); @@ -178,6 +180,11 @@ void AMAppItem::onPropertyChanged(const QDBusMessage &msg) : localizedName); } + if (contains(QLatin1String("Keywords"))) { + const auto keywords = qdbus_cast(value(QLatin1String("Keywords"))); + AppItem::setKeywords(getLocaleOrDefaultValue(keywords, locale, DEFAULT_KEY)); + } + if (contains(QLatin1String("Icons"))) { const auto icons = qdbus_cast(value(QLatin1String("Icons"))); AppItem::setAppIconName(icons.value(DESKTOP_ENTRY_ICON_KEY)); diff --git a/applets/dde-apps/amappitem.h b/applets/dde-apps/amappitem.h index 05607233b..4ff4d11e4 100644 --- a/applets/dde-apps/amappitem.h +++ b/applets/dde-apps/amappitem.h @@ -22,7 +22,12 @@ class AMAppItem : public Application, public AppItem void setOnDesktop(bool on) override; private: - QString getLocaleOrDefaultValue(const QStringMap &value, const QString &localeCode, const QString &fallbackKey); + // Name/GenericName use QString values, while Keywords uses QStringList values. + // T lets both reuse the existing locale fallback policy, including stopping + // at an existing key with an empty value, instead of adding a separate chain + // for Keywords. + template + T getLocaleOrDefaultValue(const QMap &value, const QString &localeCode, const QString &fallbackKey) const; void updateActions(const QStringList &actions, const PropMap &actionName); private Q_SLOTS: diff --git a/applets/dde-apps/amappitemmodel.cpp b/applets/dde-apps/amappitemmodel.cpp index 967f3cc5d..e5760408f 100644 --- a/applets/dde-apps/amappitemmodel.cpp +++ b/applets/dde-apps/amappitemmodel.cpp @@ -24,6 +24,8 @@ AMAppItemModel::AMAppItemModel(QObject *parent) qDBusRegisterMetaType(); qDBusRegisterMetaType(); qRegisterMetaType(); + qDBusRegisterMetaType(); + qRegisterMetaType(); qRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); diff --git a/applets/dde-apps/api/types/am.h b/applets/dde-apps/api/types/am.h index 4bc7b57e5..1c718ed68 100644 --- a/applets/dde-apps/api/types/am.h +++ b/applets/dde-apps/api/types/am.h @@ -7,14 +7,18 @@ // from am global.h #include #include +#include #include using ObjectInterfaceMap = QMap; using ObjectMap = QMap; using QStringMap = QMap; +// Match AM's locale -> keyword list D-Bus type without flattening locale information. +using QStringListMap = QMap; using PropMap = QMap; Q_DECLARE_METATYPE(ObjectInterfaceMap) Q_DECLARE_METATYPE(ObjectMap) Q_DECLARE_METATYPE(QStringMap) +Q_DECLARE_METATYPE(QStringListMap) Q_DECLARE_METATYPE(PropMap) diff --git a/applets/dde-apps/appitem.cpp b/applets/dde-apps/appitem.cpp index 9dd1a6803..c401a6a80 100644 --- a/applets/dde-apps/appitem.cpp +++ b/applets/dde-apps/appitem.cpp @@ -250,4 +250,14 @@ void AppItem::setGenericName(const QString &genericName) { setData(genericName, AppItemModel::GenericNameRole); } + +QStringList AppItem::keywords() const +{ + return data(AppItemModel::KeywordsRole).toStringList(); +} + +void AppItem::setKeywords(const QStringList &keywords) +{ + setData(keywords, AppItemModel::KeywordsRole); +} } diff --git a/applets/dde-apps/appitem.h b/applets/dde-apps/appitem.h index 4a1ac5981..ece5b9339 100644 --- a/applets/dde-apps/appitem.h +++ b/applets/dde-apps/appitem.h @@ -82,7 +82,12 @@ class AppItem : public QStandardItem QString vendor() const; void setVendor(const QString &vendor); + // Share the fallback-selected GenericName with display and search consumers. QString genericName() const; void setGenericName(const QString &genericName); + + // Store locale-selected Keywords for model consumers, avoiding a second metadata reader. + QStringList keywords() const; + void setKeywords(const QStringList &keywords); }; } diff --git a/applets/dde-apps/appitemmodel.cpp b/applets/dde-apps/appitemmodel.cpp index e208f4d7c..bfb25e588 100644 --- a/applets/dde-apps/appitemmodel.cpp +++ b/applets/dde-apps/appitemmodel.cpp @@ -34,6 +34,7 @@ QHash AppItemModel::roleNames() const {AppItemModel::ExecsRole, QByteArrayLiteral("execs")}, {AppItemModel::DesktopSourcePathRole, QByteArrayLiteral("desktopSourcePath")}, {AppItemModel::VendorRole, QByteArrayLiteral("vendor")}, - {AppItemModel::GenericNameRole, QByteArrayLiteral("genericName")}}; + {AppItemModel::GenericNameRole, QByteArrayLiteral("genericName")}, + {AppItemModel::KeywordsRole, QByteArrayLiteral("keywords")}}; } } diff --git a/applets/dde-apps/appitemmodel.h b/applets/dde-apps/appitemmodel.h index 356b63c92..0db6bda39 100644 --- a/applets/dde-apps/appitemmodel.h +++ b/applets/dde-apps/appitemmodel.h @@ -36,6 +36,7 @@ class AppItemModel : public QStandardItemModel DesktopSourcePathRole, VendorRole, GenericNameRole, + KeywordsRole, // Expose parsed, locale-selected Keywords through the shared app model. }; Q_ENUM(Roles)