From 6467f0ef89c5e7591ab996e932edf46f48e47c48 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Mon, 27 Mar 2023 17:00:45 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8Dfolder-helper=E6=96=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appdata/app-data-manager.cpp | 11 +++++++++ src/appdata/app-data-manager.h | 1 + src/appdata/plugin/all-app-data-provider.cpp | 24 ++++++++------------ src/appdata/plugin/all-app-data-provider.h | 3 +-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/appdata/app-data-manager.cpp b/src/appdata/app-data-manager.cpp index 88627e7..59a1d9e 100644 --- a/src/appdata/app-data-manager.cpp +++ b/src/appdata/app-data-manager.cpp @@ -318,6 +318,17 @@ QVector AppDataManager::favoriteApps() return m_favoriteApps; } +bool AppDataManager::getApp(const QString &appId, DataEntity &app) +{ + QMutexLocker locker(&m_mutex); + if (!m_normalApps.contains(appId)) { + return false; + } + + app = m_normalApps[appId]; + return true; +} + } // UkuiMenu #include "app-data-manager.moc" diff --git a/src/appdata/app-data-manager.h b/src/appdata/app-data-manager.h index 88b2ec5..b5e2afc 100644 --- a/src/appdata/app-data-manager.h +++ b/src/appdata/app-data-manager.h @@ -44,6 +44,7 @@ public: AppDataManager(AppDataManager&& obj) = delete; AppDataManager &operator=(AppDataManager&& obj) = delete; + bool getApp(const QString &appId, DataEntity &app); QList normalApps(); QVector favoriteApps(); diff --git a/src/appdata/plugin/all-app-data-provider.cpp b/src/appdata/plugin/all-app-data-provider.cpp index aa0dcdf..d00c2f3 100644 --- a/src/appdata/plugin/all-app-data-provider.cpp +++ b/src/appdata/plugin/all-app-data-provider.cpp @@ -84,16 +84,17 @@ void AllAppDataProvider::reloadAppData() QMutexLocker locker(&m_mutex); m_appData.clear(); - // TODO 验证多线程间隐式共享数复制后导致迭代器实现问题 QList apps = AppDataManager::instance()->normalApps(); if (apps.isEmpty()) { return; } + Folder folder; for (const auto &app : apps) { - if (!m_folderApps.contains(app.id())) { - m_appData.append(app); + if (AppFolderHelper::instance()->searchFolderByAppName(app.id(), folder)) { + continue; } + m_appData.append(app); } std::sort(m_appData.begin(), m_appData.end(), [](const DataEntity &a, const DataEntity &b) { @@ -104,8 +105,6 @@ void AllAppDataProvider::reloadAppData() void AllAppDataProvider::reloadFolderData() { QMutexLocker locker(&m_mutex); - - m_folderApps.clear(); m_folderData.clear(); QList folders = AppFolderHelper::instance()->folderData(); @@ -113,17 +112,13 @@ void AllAppDataProvider::reloadFolderData() return; } - std::sort(folders.begin(), folders.end(), [](const Folder &a, const Folder &b) { - return a.getId() < b.getId(); - }); - DataEntity folderItem; for (const auto &folder : folders) { + folderItem.setId(QString::number(folder.getId())); folderItem.setType(DataType::Folder); folderItem.setIcon("image://appicon/text-plain"); folderItem.setName(folder.getName()); - m_folderApps.unite(folder.getApps().toSet()); m_folderData.append(folderItem); } } @@ -132,7 +127,7 @@ void AllAppDataProvider::mergeData(QVector &data) { QMutexLocker locker(&m_mutex); data.append(m_folderData); - data.append(m_appData.toVector()); + data.append(m_appData); } void AllAppDataProvider::sendData() @@ -144,15 +139,14 @@ void AllAppDataProvider::sendData() void AllAppDataProvider::onAppFolderChanged() { - reloadFolderData(); - sendData(); + forceUpdate(); } void AllAppDataProvider::onAppAdded(const QList& apps) { { QMutexLocker locker(&m_mutex); - m_appData.append(apps); + m_appData.append(apps.toVector()); } sendData(); } @@ -167,7 +161,7 @@ void AllAppDataProvider::removeApps(QStringList &idList) { QMutexLocker locker(&m_mutex); - QList::iterator iterator = m_appData.begin(); + QVector::iterator iterator = m_appData.begin(); while (iterator != m_appData.end() && !idList.isEmpty()) { if (idList.removeOne((*iterator).id())) { iterator = m_appData.erase(iterator); diff --git a/src/appdata/plugin/all-app-data-provider.h b/src/appdata/plugin/all-app-data-provider.h index 4aa3b1b..7073069 100644 --- a/src/appdata/plugin/all-app-data-provider.h +++ b/src/appdata/plugin/all-app-data-provider.h @@ -55,8 +55,7 @@ private: private: QMutex m_mutex; - QSet m_folderApps; - QList m_appData; + QVector m_appData; QVector m_folderData; };