From a174a4237a70d90c5ca71edae84e168f1812a153 Mon Sep 17 00:00:00 2001 From: iaom Date: Tue, 5 Mar 2024 16:15:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(frontend&searchPlugin):=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E7=B1=BB=E5=9E=8B=EF=BC=8C=E6=9C=80=E4=BD=B3?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E4=B8=AD=E6=AF=8F=E7=A7=8D=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=8F=AA=E6=98=BE=E7=A4=BA1=E7=A7=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/model/best-list-model.cpp | 8 +++++++- frontend/model/best-list-model.h | 2 +- libsearch/appsearch/app-search-plugin.cpp | 1 + libsearch/index/search-manager.cpp | 1 + libsearch/notesearch/note-search-plugin.cpp | 1 + .../plugininterface/search-plugin-iface.h | 18 +++++++++++------- .../settingsearch/settings-search-plugin.cpp | 1 + libsearch/websearch/web-search-plugin.cpp | 3 ++- 8 files changed, 25 insertions(+), 10 deletions(-) diff --git a/frontend/model/best-list-model.cpp b/frontend/model/best-list-model.cpp index 8fd7a82..3d4e743 100644 --- a/frontend/model/best-list-model.cpp +++ b/frontend/model/best-list-model.cpp @@ -97,6 +97,12 @@ const bool &BestListModel::isExpanded() void BestListModel::appendInfo(const QString &pluginId, const SearchPluginIface::ResultInfo &info) { + + if (m_resourceTypes.contains(info.resourceType)) { + return; + } else { + m_resourceTypes.append(info.resourceType); + } if (m_pluginIdList.contains(pluginId)) { if (info.actionKey == m_items.at(m_pluginIdList.lastIndexOf(pluginId))->info().actionKey) { return; @@ -186,7 +192,7 @@ void BestListModel::startSearch(const QString &keyword) if (!m_items.isEmpty()) { this->beginResetModel(); m_pluginIdList.clear(); - m_pluginActionKeyList.clear(); + m_resourceTypes.clear(); qDeleteAll(m_items); m_items.clear(); this->endResetModel(); diff --git a/frontend/model/best-list-model.h b/frontend/model/best-list-model.h index dc745fb..a11c1fa 100644 --- a/frontend/model/best-list-model.h +++ b/frontend/model/best-list-model.h @@ -61,7 +61,7 @@ Q_SIGNALS: private: QVector m_items; QVector m_pluginIdList; - QVector m_pluginActionKeyList; + QVector m_resourceTypes; bool m_isExpanded = false; }; } diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index 1df092d..e2bc217 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -193,6 +193,7 @@ void AppSearchPlugin::run() ri.name = data.value(SearchProperty::SearchResultProperty::ApplicationLocalName).toString(); ri.toolTip = ri.name; + ri.resourceType = QStringLiteral("app"); ri.icon = IconLoader::loadIconXdg(data.value(SearchProperty::SearchResultProperty::ApplicationIconName).toString(), QIcon(":/res/icons/unknown.svg")); SearchPluginIface::DescriptionInfo description; description.key = QString(tr("Application Description:")); diff --git a/libsearch/index/search-manager.cpp b/libsearch/index/search-manager.cpp index ba3c7da..e5953fb 100644 --- a/libsearch/index/search-manager.cpp +++ b/libsearch/index/search-manager.cpp @@ -67,6 +67,7 @@ bool SearchManager::creatResultInfo(SearchPluginIface::ResultInfo &ri, const QSt ri.icon = FileUtils::getFileIcon(QUrl::fromLocalFile(path).toString(), false); ri.name = info.fileName().replace("\r", " ").replace("\n", " "); ri.toolTip = info.fileName(); + ri.resourceType = QStringLiteral("file"); ri.description = QVector() \ << SearchPluginIface::DescriptionInfo{tr("Path:"), path} \ << SearchPluginIface::DescriptionInfo{tr("Modified time:"), info.lastModified().toString("yyyy/MM/dd hh:mm:ss")}; diff --git a/libsearch/notesearch/note-search-plugin.cpp b/libsearch/notesearch/note-search-plugin.cpp index 0d39aef..2d927bb 100644 --- a/libsearch/notesearch/note-search-plugin.cpp +++ b/libsearch/notesearch/note-search-plugin.cpp @@ -238,6 +238,7 @@ void NoteSearch::run() { IconLoader::loadIconQt("kylin-notebook", QIcon(":/res/icons/desktop.png")), name.replace("\r", " ").replace("\n", " "), name, + QStringLiteral("ukui-note"), QVector() << SearchPluginIface::DescriptionInfo { key : QString(tr("Note Description:")), value : str.at(0) diff --git a/libsearch/plugininterface/search-plugin-iface.h b/libsearch/plugininterface/search-plugin-iface.h index 96c1eba..c9c3aef 100644 --- a/libsearch/plugininterface/search-plugin-iface.h +++ b/libsearch/plugininterface/search-plugin-iface.h @@ -21,9 +21,10 @@ #define SEARCHPLUGINIFACE_H #define SearchPluginIface_iid "org.ukui.ukui-search.plugin-iface.SearchPluginInterface" /** + * changelog:1.3.0 增加resourceType * changelog:1.2.0 增加toolTip */ -#define SEARCH_PLUGIN_IFACE_VERSION "1.2.0" +#define SEARCH_PLUGIN_IFACE_VERSION "1.3.0" #include #include @@ -59,21 +60,24 @@ public: */ struct ResultInfo { - QIcon icon; - QString name; - QString toolTip; - QVector description; - QString actionKey; + QIcon icon; //要显示的图标 + QString name; //要显示的名称 + QString toolTip; //要先显示的tooltip + QVector description; //详情页中使用的描述 + QString actionKey; //执行action时的key + QString resourceType; //资源类型,可定义,例如“file, app” int type; - ResultInfo(const QIcon &iconToSet = QIcon(), + explicit ResultInfo(const QIcon &iconToSet = QIcon(), const QString &nameToSet = QString(), const QString &toolTipToSet = QString(), + const QString &resourceTypeToSet = QString(), const QVector &descriptionToSet = QVector(), const QString &actionKeyToSet = QString(), const int &typeToSet = 0) { icon = iconToSet; name = nameToSet; toolTip = toolTipToSet; + resourceType = resourceTypeToSet; description = descriptionToSet; actionKey = actionKeyToSet; type = typeToSet; diff --git a/libsearch/settingsearch/settings-search-plugin.cpp b/libsearch/settingsearch/settings-search-plugin.cpp index 8cf7306..2697893 100644 --- a/libsearch/settingsearch/settings-search-plugin.cpp +++ b/libsearch/settingsearch/settings-search-plugin.cpp @@ -477,6 +477,7 @@ void SettingsMatch::createResultInfo(SearchPluginIface::ResultInfo &resultInfo, resultInfo.name.prepend(ql.language() == QLocale::English ? topInfo.at(0) : topInfo.at(1)); } resultInfo.toolTip = resultInfo.name; + resultInfo.resourceType = QStringLiteral("setting"); resultInfo.icon = FileUtils::getSettingIcon(); resultInfo.actionKey = path.section("/", 1, 1); } diff --git a/libsearch/websearch/web-search-plugin.cpp b/libsearch/websearch/web-search-plugin.cpp index 3f2a802..c89411d 100644 --- a/libsearch/websearch/web-search-plugin.cpp +++ b/libsearch/websearch/web-search-plugin.cpp @@ -68,7 +68,8 @@ void UkuiSearch::WebSearchPlugin::KeywordSearch(QString keyword, DataQueue