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: 11 additions & 0 deletions src/models/org.deepin.ds.launchpad.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@
"description[zh_CN]": "在窗口模式下排序应用列表的类别。0: 首字母分组排序,1: DDE 风格分类,2: 自由排序",
"permissions": "readwrite",
"visibility": "private"
},
"searchByDesktopId": {
"value": false,
"serial": 0,
"flags": [],
"name": "searchByDesktopId",
"name[zh_CN]": "按桌面条目 ID 搜索",
"description": "Whether to allow the search for Desktop ID during the search.",
"description[zh_CN]": "在搜索时候是否允许搜索Desktop ID。",
"permissions": "readwrite",
"visibility": "private"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visibility为private,表明它是私有的配置,仅当前应用设置,你这个之后可能由dde-control-center改写吧,是不是应该是public的,

}
}
}
27 changes: 26 additions & 1 deletion src/models/searchfilterproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,35 @@
#include "appsmodel.h"
#include "searchfilterproxymodel.h"

#include <QDebug>

Check warning on line 8 in src/models/searchfilterproxymodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 9 in src/models/searchfilterproxymodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 10 in src/models/searchfilterproxymodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 11 in src/models/searchfilterproxymodel.cpp

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 <functional>

Check warning on line 12 in src/models/searchfilterproxymodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 13 in src/models/searchfilterproxymodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

SearchFilterProxyModel::SearchFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
, m_dconfig(DConfig::create("org.deepin.dde.shell", "org.deepin.ds.launchpad"))
, m_searchPackageEnabled(false)
{
setFilterCaseSensitivity(Qt::CaseInsensitive);

setSourceModel(&AppsModel::instance());
sort(0, Qt::DescendingOrder);

Q_ASSERT_X(m_dconfig->isValid(), "DConfig", "DConfig file is missing or invalid");

m_searchPackageEnabled = m_dconfig->value("searchByDesktopId", false).toBool();
QObject::connect(m_dconfig, &DConfig::valueChanged, this, [this](const QString &key) {
if (key == "searchByDesktopId") {
m_searchPackageEnabled = m_dconfig->value("searchByDesktopId", false).toBool();
qDebug() << "searchByDesktopId配置已更新:" << m_searchPackageEnabled;
// 触发重新过滤以应用新的搜索配置
invalidateFilter();
}
});
}

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

// 如果索引为0,表示不匹配
return matchIndex >= 0;
}

Expand Down Expand Up @@ -70,6 +84,9 @@
const QString & transliterated = modelIndex.data(AppsModel::AllTransliteratedRole).toString();
const QString & jianpin = Dtk::Core::firstLetters(displayName).join(',');

//包名搜索使用
const QString & desktopId = modelIndex.data(AppItem::DesktopIdRole).toString();

QString searchPatternDelBlank = searchPattern.pattern().toLower().remove(" ");

// Choose which name to use for matching based on search input and vendor
Expand Down Expand Up @@ -105,6 +122,7 @@
QString transliteratedLower = transliterated.toLower();
QString jianpinLower = jianpin.toLower();
QString nameFirstLettersLower = nameFirstLetters.toLower();
QString desktopIdLower = desktopId.toLower().remove(" ");

// 使用 QVector 存储匹配类型和对应的函数,按优先级顺序插入
QVector<QPair<QString, std::function<bool()>>> matchTypes;
Expand Down Expand Up @@ -248,6 +266,13 @@
return getCapitalizedWords().contains(searchPatternLower);
}));

// 包名搜索(仅在配置启用时生效)
if (m_searchPackageEnabled) {
matchTypes.push_back(qMakePair(QString("desktopId"), [&]() -> bool {
return desktopIdLower.contains(searchPatternLower);
}));
}

// 计算匹配索引(索引越小优先级越高)
auto it = std::find_if(matchTypes.begin(), matchTypes.end(),
[](const auto& matchType) { return matchType.second(); });
Expand Down
7 changes: 7 additions & 0 deletions src/models/searchfilterproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

#pragma once

#include <QtQml/qqml.h>

Check warning on line 7 in src/models/searchfilterproxymodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtQml/qqml.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSortFilterProxyModel>

Check warning on line 8 in src/models/searchfilterproxymodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

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

namespace Dtk::Core {
class DConfig;
}

class SearchFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Expand Down Expand Up @@ -35,4 +39,7 @@
explicit SearchFilterProxyModel(QObject *parent = nullptr);

int calculateWeight(const QModelIndex &modelIndex) const;

Dtk::Core::DConfig *m_dconfig;
bool m_searchPackageEnabled;
};