From f0396447a7fafe3bdb31e8f17a296e43b355f2a7 Mon Sep 17 00:00:00 2001 From: qiqi49 Date: Wed, 11 Sep 2024 15:41:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(favorite):=E4=BF=AE=E5=A4=8D=E8=A2=AB?= =?UTF-8?q?=E6=94=B6=E8=97=8F=E5=BA=94=E7=94=A8=E5=9C=A8=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=BB=84=E4=B8=AD=E6=97=B6,=E4=BB=8D=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=A5=E5=BA=94=E7=94=A8=E5=88=B0=E6=94=B6?= =?UTF-8?q?=E8=97=8F=E5=8C=BA=E5=9F=9F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extension/favorite/app-favorite-model.cpp | 10 +++++++-- src/extension/favorite/app-favorite-model.h | 2 +- src/extension/favorite/favorites-config.cpp | 22 ++++++++++++------- src/extension/favorite/favorites-model.cpp | 8 +++++-- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/extension/favorite/app-favorite-model.cpp b/src/extension/favorite/app-favorite-model.cpp index ef3ddb8..1df03b2 100644 --- a/src/extension/favorite/app-favorite-model.cpp +++ b/src/extension/favorite/app-favorite-model.cpp @@ -219,9 +219,15 @@ void AppFavoritesModel::clearFavorites() FavoritesConfig::instance().clear(); } -bool AppFavoritesModel::getApp(const QString &appid, DataEntity &app) +bool AppFavoritesModel::isAppIncluded(const QString &appid) { - return m_sourceModel->databaseInterface()->getApp(appid, app); + QModelIndex sourceIndex = m_sourceModel->index(m_sourceModel->indexOfApp(appid), 0, {}); + if (!sourceIndex.isValid()) { + return false; + } + + QPersistentModelIndex index(sourceIndex); + return m_favoritesApps.contains(index); } void AppFavoritesModel::onAppRemoved(const QModelIndex &parent, int first, int last) diff --git a/src/extension/favorite/app-favorite-model.h b/src/extension/favorite/app-favorite-model.h index f5be780..a9ab31e 100644 --- a/src/extension/favorite/app-favorite-model.h +++ b/src/extension/favorite/app-favorite-model.h @@ -42,7 +42,7 @@ public: void addAppToFavorites(const QString &id, const int &index); void removeAppFromFavorites(const QString &id); void changeFileState(const QString &url, const bool &favorite); - bool getApp(const QString &appid, DataEntity &app); + bool isAppIncluded(const QString &appid); private: explicit AppFavoritesModel(QObject *parent = nullptr); diff --git a/src/extension/favorite/favorites-config.cpp b/src/extension/favorite/favorites-config.cpp index 0403a94..9e419ca 100644 --- a/src/extension/favorite/favorites-config.cpp +++ b/src/extension/favorite/favorites-config.cpp @@ -22,6 +22,7 @@ #include #include #include "favorites-config.h" +#include "favorite-folder-helper.h" #define FOLDER_FILE_PATH ".config/ukui-menu/" #define FOLDER_FILE_NAME "favorite.json" @@ -138,19 +139,24 @@ void FavoritesConfig::initConfig() m_favoritesList.clear(); QJsonArray array = jsonDocument.array(); - QJsonArray newArray; + bool needSync = false; for (int i = 0; i < array.size(); i++) { if (array.at(i).isString()) { - m_favoritesList.append(array.at(i).toString()); - newArray.append(array.at(i)); + QString id = array.at(i).toString(); + // 配置文件出现错误, 某一个应用 同时出现在了 应用组的内部和外部 + if (id.startsWith(APP_ID_SCHEME) && FavoriteFolderHelper::instance()->containApp(id.mid(APP_ID_SCHEME.length()))) { + needSync = true; + continue; + } + m_favoritesList.append(id); + } else { + needSync = true; } } - file.open(QFile::WriteOnly); - jsonDocument.setArray(newArray); - file.write(jsonDocument.toJson()); - file.flush(); - file.close(); + if (needSync) { + sync(); + } } } // UkuiMenu diff --git a/src/extension/favorite/favorites-model.cpp b/src/extension/favorite/favorites-model.cpp index 5cba398..cf890a4 100644 --- a/src/extension/favorite/favorites-model.cpp +++ b/src/extension/favorite/favorites-model.cpp @@ -80,6 +80,11 @@ void FavoritesModel::openMenu(const int &row) void FavoritesModel::addAppToFavorites(const QString &id, const int &index) { + if (AppFavoritesModel::instance().isAppIncluded(id) || FavoriteFolderHelper::instance()->containApp(id)) { + qWarning() << "This application is already included in the favorite apps!"; + return; + } + int appOrder; if (index == -1) { appOrder = FavoritesConfig::instance().configSize(); @@ -108,8 +113,7 @@ void FavoritesModel::addAppsToNewFolder(const QString &idFrom, const QString &id return; } - DataEntity app; - if (AppFavoritesModel::instance().getApp(idFrom, app) && AppFavoritesModel::instance().getApp(idTo, app)) { + if (AppFavoritesModel::instance().isAppIncluded(idFrom) && AppFavoritesModel::instance().isAppIncluded(idTo)) { FavoriteFolderHelper::instance()->addAppsToNewFolder(idFrom, idTo, ""); } } -- Gitee From bb6861fd2f73c2856763526e879c2fc1f98dc02d Mon Sep 17 00:00:00 2001 From: qiqi49 Date: Wed, 11 Sep 2024 17:53:21 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(search):=E4=BF=AE=E5=A4=8D=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=8A=B6=E6=80=81=E4=B8=8B,=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95=E5=A7=8B=E7=BB=88=E4=B8=BA?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B0=E6=94=B6=E8=97=8F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libappdata/app-search-plugin.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libappdata/app-search-plugin.cpp b/src/libappdata/app-search-plugin.cpp index 5df6f84..bd05991 100644 --- a/src/libappdata/app-search-plugin.cpp +++ b/src/libappdata/app-search-plugin.cpp @@ -19,6 +19,7 @@ */ #include "app-search-plugin.h" #include "data-entity.h" +#include "basic-app-model.h" #include #include @@ -60,9 +61,7 @@ AppSearchPluginPrivate::AppSearchPluginPrivate(QObject *parent) : QThread(parent m_appSearchTask->setSearchOnlineApps(false); UkuiSearch::SearchResultProperties searchResultProperties; - searchResultProperties << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationDesktopPath - << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationLocalName - << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationIconName; + searchResultProperties << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationDesktopPath; m_appSearchTask->setResultProperties(UkuiSearch::SearchProperty::SearchType::Application, searchResultProperties); m_timer = new QTimer; @@ -101,11 +100,10 @@ void AppSearchPluginPrivate::run() m_timer->stop(); if (result.getSearchId() == m_searchId) { DataEntity app; - app.setType(DataType::Normal); - app.setId(result.getValue(UkuiSearch::SearchProperty::ApplicationDesktopPath).toString()); - app.setName(result.getValue(UkuiSearch::SearchProperty::ApplicationLocalName).toString()); - app.setIcon(result.getValue(UkuiSearch::SearchProperty::ApplicationIconName).toString()); - + QString id = result.getValue(UkuiSearch::SearchProperty::ApplicationDesktopPath).toString(); + if (!BasicAppModel::instance()->getAppById(id, app)) { + BasicAppModel::instance()->databaseInterface()->getApp(id, app); + }; Q_EMIT this->searchedOne(app); } } -- Gitee