Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions applets/dde-apps/amappitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QStringListMap>(appInfo.value(u8"Keywords")), locale, DEFAULT_KEY));
AppItem::setVendor(xDeepinVendor);

if (QStringLiteral("deepin") == xDeepinVendor && !localizedGenericName.isEmpty()) {
Expand Down Expand Up @@ -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<typename T>
T AMAppItem::getLocaleOrDefaultValue(const QMap<QString, T> &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);
Expand Down Expand Up @@ -178,6 +180,11 @@ void AMAppItem::onPropertyChanged(const QDBusMessage &msg)
: localizedName);
}

if (contains(QLatin1String("Keywords"))) {
const auto keywords = qdbus_cast<QStringListMap>(value(QLatin1String("Keywords")));
AppItem::setKeywords(getLocaleOrDefaultValue(keywords, locale, DEFAULT_KEY));
}

if (contains(QLatin1String("Icons"))) {
const auto icons = qdbus_cast<QStringMap>(value(QLatin1String("Icons")));
AppItem::setAppIconName(icons.value(DESKTOP_ENTRY_ICON_KEY));
Expand Down
7 changes: 6 additions & 1 deletion applets/dde-apps/amappitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
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<typename T>
T getLocaleOrDefaultValue(const QMap<QString, T> &value, const QString &localeCode, const QString &fallbackKey) const;
void updateActions(const QStringList &actions, const PropMap &actionName);

private Q_SLOTS:

Check warning on line 33 in applets/dde-apps/amappitem.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it.
void onPropertyChanged(const QDBusMessage &msg);
};
}
2 changes: 2 additions & 0 deletions applets/dde-apps/amappitemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ AMAppItemModel::AMAppItemModel(QObject *parent)
qDBusRegisterMetaType<ObjectMap>();
qDBusRegisterMetaType<QStringMap>();
qRegisterMetaType<QStringMap>();
qDBusRegisterMetaType<QStringListMap>();
qRegisterMetaType<QStringListMap>();
qRegisterMetaType<PropMap>();
qDBusRegisterMetaType<PropMap>();
qDBusRegisterMetaType<QDBusObjectPath>();
Expand Down
4 changes: 4 additions & 0 deletions applets/dde-apps/api/types/am.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
#pragma once

// from am global.h
#include <QMap>

Check warning on line 8 in applets/dde-apps/api/types/am.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMap> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QString>

Check warning on line 9 in applets/dde-apps/api/types/am.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QString> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QStringList>

Check warning on line 10 in applets/dde-apps/api/types/am.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStringList> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusObjectPath>

Check warning on line 11 in applets/dde-apps/api/types/am.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusObjectPath> not found. Please note: Cppcheck does not need standard library headers to get proper results.

using ObjectInterfaceMap = QMap<QString, QVariantMap>;
using ObjectMap = QMap<QDBusObjectPath, ObjectInterfaceMap>;
using QStringMap = QMap<QString, QString>;
// Match AM's locale -> keyword list D-Bus type without flattening locale information.
using QStringListMap = QMap<QString, QStringList>;
using PropMap = QMap<QString, QStringMap>;

Q_DECLARE_METATYPE(ObjectInterfaceMap)
Q_DECLARE_METATYPE(ObjectMap)
Q_DECLARE_METATYPE(QStringMap)
Q_DECLARE_METATYPE(QStringListMap)
Q_DECLARE_METATYPE(PropMap)
10 changes: 10 additions & 0 deletions applets/dde-apps/appitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,14 @@
{
setData(genericName, AppItemModel::GenericNameRole);
}

QStringList AppItem::keywords() const

Check warning on line 254 in applets/dde-apps/appitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'keywords' is never used.
{
return data(AppItemModel::KeywordsRole).toStringList();
}

void AppItem::setKeywords(const QStringList &keywords)

Check warning on line 259 in applets/dde-apps/appitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setKeywords' is never used.
{
setData(keywords, AppItemModel::KeywordsRole);
}
}
5 changes: 5 additions & 0 deletions applets/dde-apps/appitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
3 changes: 2 additions & 1 deletion applets/dde-apps/appitemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ QHash<int, QByteArray> 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")}};
}
}
1 change: 1 addition & 0 deletions applets/dde-apps/appitemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading