Skip to content

Commit 8ba54e2

Browse files
wjyrichdeepin-bot[bot]
authored andcommitted
feat: add package name search configuration
1. Added new DConfig setting "searchPackage" to control package name search functionality 2. Implemented package name search in SearchFilterProxyModel when enabled 3. Added DConfig monitoring to dynamically update search behavior when setting changes 4. Package name search includes exact match, starts with, and contains matching 5. Added desktopId comparison in calculateWeight method for package name matching The changes allow users to enable/disable package name searching through DConfig, providing more flexible search options. This is particularly useful for technical users who may want to search applications by their package names. feat: 添加包名搜索配置功能 1. 新增 DConfig 设置项 "searchPackage" 用于控制包名搜索功能 2. 在 SearchFilterProxyModel 中实现包名搜索功能(当启用时) 3. 添加 DConfig 监听以动态更新搜索行为 4. 包名搜索支持精确匹配、开头匹配和包含匹配 5. 在 calculateWeight 方法中添加 desktopId 比较用于包名匹配 这些改动允许用户通过 DConfig 启用/禁用包名搜索功能,提供更灵活的搜索选 项。对于技术用户来说特别有用,他们可能希望通过包名来搜索应用程序。
1 parent 4f45994 commit 8ba54e2

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/models/org.deepin.ds.launchpad.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@
7575
"description[zh_CN]": "在窗口模式下排序应用列表的类别。0: 首字母分组排序,1: DDE 风格分类,2: 自由排序",
7676
"permissions": "readwrite",
7777
"visibility": "private"
78+
},
79+
"searchByDesktopId": {
80+
"value": false,
81+
"serial": 0,
82+
"flags": [],
83+
"name": "searchByDesktopId",
84+
"name[zh_CN]": "按桌面条目 ID 搜索",
85+
"description": "Whether to allow the search for Desktop ID during the search.",
86+
"description[zh_CN]": "在搜索时候是否允许搜索Desktop ID。",
87+
"permissions": "readwrite",
88+
"visibility": "private"
7889
}
7990
}
8091
}

src/models/searchfilterproxymodel.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,33 @@
77

88
#include <QDebug>
99
#include <DPinyin>
10+
#include <DConfig>
1011
#include <QMap>
1112
#include <functional>
1213
#include <algorithm>
1314
DCORE_USE_NAMESPACE
1415

1516
SearchFilterProxyModel::SearchFilterProxyModel(QObject *parent)
1617
: QSortFilterProxyModel(parent)
18+
, m_dconfig(DConfig::create("org.deepin.dde.shell", "org.deepin.ds.launchpad"))
19+
, m_searchPackageEnabled(false)
1720
{
1821
setFilterCaseSensitivity(Qt::CaseInsensitive);
1922

2023
setSourceModel(&AppsModel::instance());
2124
sort(0, Qt::DescendingOrder);
25+
26+
Q_ASSERT_X(m_dconfig->isValid(), "DConfig", "DConfig file is missing or invalid");
27+
28+
m_searchPackageEnabled = m_dconfig->value("searchByDesktopId", false).toBool();
29+
QObject::connect(m_dconfig, &DConfig::valueChanged, this, [this](const QString &key) {
30+
if (key == "searchByDesktopId") {
31+
m_searchPackageEnabled = m_dconfig->value("searchByDesktopId", false).toBool();
32+
qDebug() << "searchByDesktopId配置已更新:" << m_searchPackageEnabled;
33+
// 触发重新过滤以应用新的搜索配置
34+
invalidateFilter();
35+
}
36+
});
2237
}
2338

2439
bool SearchFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
@@ -29,7 +44,6 @@ bool SearchFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &
2944
// 计算匹配索引
3045
int matchIndex = calculateWeight(modelIndex);
3146

32-
// 如果索引为0,表示不匹配
3347
return matchIndex >= 0;
3448
}
3549

@@ -70,6 +84,9 @@ int SearchFilterProxyModel::calculateWeight(const QModelIndex &modelIndex) const
7084
const QString & transliterated = modelIndex.data(AppsModel::AllTransliteratedRole).toString();
7185
const QString & jianpin = Dtk::Core::firstLetters(displayName).join(',');
7286

87+
//包名搜索使用
88+
const QString & desktopId = modelIndex.data(AppItem::DesktopIdRole).toString();
89+
7390
QString searchPatternDelBlank = searchPattern.pattern().toLower().remove(" ");
7491

7592
// Choose which name to use for matching based on search input and vendor
@@ -105,6 +122,7 @@ int SearchFilterProxyModel::calculateWeight(const QModelIndex &modelIndex) const
105122
QString transliteratedLower = transliterated.toLower();
106123
QString jianpinLower = jianpin.toLower();
107124
QString nameFirstLettersLower = nameFirstLetters.toLower();
125+
QString desktopIdLower = desktopId.toLower().remove(" ");
108126

109127
// 使用 QVector 存储匹配类型和对应的函数,按优先级顺序插入
110128
QVector<QPair<QString, std::function<bool()>>> matchTypes;
@@ -248,6 +266,13 @@ int SearchFilterProxyModel::calculateWeight(const QModelIndex &modelIndex) const
248266
return getCapitalizedWords().contains(searchPatternLower);
249267
}));
250268

269+
// 包名搜索(仅在配置启用时生效)
270+
if (m_searchPackageEnabled) {
271+
matchTypes.push_back(qMakePair(QString("desktopId"), [&]() -> bool {
272+
return desktopIdLower.contains(searchPatternLower);
273+
}));
274+
}
275+
251276
// 计算匹配索引(索引越小优先级越高)
252277
auto it = std::find_if(matchTypes.begin(), matchTypes.end(),
253278
[](const auto& matchType) { return matchType.second(); });

src/models/searchfilterproxymodel.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <QtQml/qqml.h>
88
#include <QSortFilterProxyModel>
99

10+
namespace Dtk::Core {
11+
class DConfig;
12+
}
13+
1014
class SearchFilterProxyModel : public QSortFilterProxyModel
1115
{
1216
Q_OBJECT
@@ -35,4 +39,7 @@ class SearchFilterProxyModel : public QSortFilterProxyModel
3539
explicit SearchFilterProxyModel(QObject *parent = nullptr);
3640

3741
int calculateWeight(const QModelIndex &modelIndex) const;
42+
43+
Dtk::Core::DConfig *m_dconfig;
44+
bool m_searchPackageEnabled;
3845
};

0 commit comments

Comments
 (0)