适配folder-helper新接口

This commit is contained in:
hewenfei 2023-03-27 17:00:45 +08:00
parent ef6de37942
commit 6467f0ef89
4 changed files with 22 additions and 17 deletions

View File

@ -318,6 +318,17 @@ QVector<DataEntity> AppDataManager::favoriteApps()
return m_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 } // UkuiMenu
#include "app-data-manager.moc" #include "app-data-manager.moc"

View File

@ -44,6 +44,7 @@ public:
AppDataManager(AppDataManager&& obj) = delete; AppDataManager(AppDataManager&& obj) = delete;
AppDataManager &operator=(AppDataManager&& obj) = delete; AppDataManager &operator=(AppDataManager&& obj) = delete;
bool getApp(const QString &appId, DataEntity &app);
QList<DataEntity> normalApps(); QList<DataEntity> normalApps();
QVector<DataEntity> favoriteApps(); QVector<DataEntity> favoriteApps();

View File

@ -84,16 +84,17 @@ void AllAppDataProvider::reloadAppData()
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
m_appData.clear(); m_appData.clear();
// TODO 验证多线程间隐式共享数复制后导致迭代器实现问题
QList<DataEntity> apps = AppDataManager::instance()->normalApps(); QList<DataEntity> apps = AppDataManager::instance()->normalApps();
if (apps.isEmpty()) { if (apps.isEmpty()) {
return; return;
} }
Folder folder;
for (const auto &app : apps) { for (const auto &app : apps) {
if (!m_folderApps.contains(app.id())) { if (AppFolderHelper::instance()->searchFolderByAppName(app.id(), folder)) {
m_appData.append(app); continue;
} }
m_appData.append(app);
} }
std::sort(m_appData.begin(), m_appData.end(), [](const DataEntity &a, const DataEntity &b) { std::sort(m_appData.begin(), m_appData.end(), [](const DataEntity &a, const DataEntity &b) {
@ -104,8 +105,6 @@ void AllAppDataProvider::reloadAppData()
void AllAppDataProvider::reloadFolderData() void AllAppDataProvider::reloadFolderData()
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
m_folderApps.clear();
m_folderData.clear(); m_folderData.clear();
QList<Folder> folders = AppFolderHelper::instance()->folderData(); QList<Folder> folders = AppFolderHelper::instance()->folderData();
@ -113,17 +112,13 @@ void AllAppDataProvider::reloadFolderData()
return; return;
} }
std::sort(folders.begin(), folders.end(), [](const Folder &a, const Folder &b) {
return a.getId() < b.getId();
});
DataEntity folderItem; DataEntity folderItem;
for (const auto &folder : folders) { for (const auto &folder : folders) {
folderItem.setId(QString::number(folder.getId()));
folderItem.setType(DataType::Folder); folderItem.setType(DataType::Folder);
folderItem.setIcon("image://appicon/text-plain"); folderItem.setIcon("image://appicon/text-plain");
folderItem.setName(folder.getName()); folderItem.setName(folder.getName());
m_folderApps.unite(folder.getApps().toSet());
m_folderData.append(folderItem); m_folderData.append(folderItem);
} }
} }
@ -132,7 +127,7 @@ void AllAppDataProvider::mergeData(QVector<DataEntity> &data)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
data.append(m_folderData); data.append(m_folderData);
data.append(m_appData.toVector()); data.append(m_appData);
} }
void AllAppDataProvider::sendData() void AllAppDataProvider::sendData()
@ -144,15 +139,14 @@ void AllAppDataProvider::sendData()
void AllAppDataProvider::onAppFolderChanged() void AllAppDataProvider::onAppFolderChanged()
{ {
reloadFolderData(); forceUpdate();
sendData();
} }
void AllAppDataProvider::onAppAdded(const QList<DataEntity>& apps) void AllAppDataProvider::onAppAdded(const QList<DataEntity>& apps)
{ {
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
m_appData.append(apps); m_appData.append(apps.toVector());
} }
sendData(); sendData();
} }
@ -167,7 +161,7 @@ void AllAppDataProvider::removeApps(QStringList &idList)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
QList<DataEntity>::iterator iterator = m_appData.begin(); QVector<DataEntity>::iterator iterator = m_appData.begin();
while (iterator != m_appData.end() && !idList.isEmpty()) { while (iterator != m_appData.end() && !idList.isEmpty()) {
if (idList.removeOne((*iterator).id())) { if (idList.removeOne((*iterator).id())) {
iterator = m_appData.erase(iterator); iterator = m_appData.erase(iterator);

View File

@ -55,8 +55,7 @@ private:
private: private:
QMutex m_mutex; QMutex m_mutex;
QSet<QString> m_folderApps; QVector<DataEntity> m_appData;
QList<DataEntity> m_appData;
QVector<DataEntity> m_folderData; QVector<DataEntity> m_folderData;
}; };