适配folder-helper新接口
This commit is contained in:
parent
ef6de37942
commit
6467f0ef89
|
@ -318,6 +318,17 @@ QVector<DataEntity> 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"
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
AppDataManager(AppDataManager&& obj) = delete;
|
||||
AppDataManager &operator=(AppDataManager&& obj) = delete;
|
||||
|
||||
bool getApp(const QString &appId, DataEntity &app);
|
||||
QList<DataEntity> normalApps();
|
||||
QVector<DataEntity> favoriteApps();
|
||||
|
||||
|
|
|
@ -84,16 +84,17 @@ void AllAppDataProvider::reloadAppData()
|
|||
QMutexLocker locker(&m_mutex);
|
||||
m_appData.clear();
|
||||
|
||||
// TODO 验证多线程间隐式共享数复制后导致迭代器实现问题
|
||||
QList<DataEntity> 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<Folder> 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<DataEntity> &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<DataEntity>& 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<DataEntity>::iterator iterator = m_appData.begin();
|
||||
QVector<DataEntity>::iterator iterator = m_appData.begin();
|
||||
while (iterator != m_appData.end() && !idList.isEmpty()) {
|
||||
if (idList.removeOne((*iterator).id())) {
|
||||
iterator = m_appData.erase(iterator);
|
||||
|
|
|
@ -55,8 +55,7 @@ private:
|
|||
|
||||
private:
|
||||
QMutex m_mutex;
|
||||
QSet<QString> m_folderApps;
|
||||
QList<DataEntity> m_appData;
|
||||
QVector<DataEntity> m_appData;
|
||||
QVector<DataEntity> m_folderData;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue