ukui-search/ukui-search-app-data-service/signal-transformer.cpp

73 lines
2.4 KiB
C++
Raw Normal View History

2022-10-21 11:21:35 +08:00
#include "signal-transformer.h"
QMutex SignalTransformer::s_mutex;
SignalTransformer *SignalTransformer::getTransformer()
{
static SignalTransformer *instance = new SignalTransformer();
return instance;
}
void SignalTransformer::handleItemInsert(const QString &desktopFilePath)
2022-10-21 11:21:35 +08:00
{
QMutexLocker locker(&s_mutex);
m_items2BInsert.append(desktopFilePath);
2022-10-21 11:21:35 +08:00
}
void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item)
2022-10-21 11:21:35 +08:00
{
QMutexLocker locker(&s_mutex);
for(auto it = item.constBegin(); it != item.constEnd(); it++) {
ApplicationPropertyMap propertyinfo = it.value();
for (auto i = propertyinfo.constBegin(); i != propertyinfo.constEnd(); i++) {
m_items2BUpdate[it.key()].insert(i.key(), i.value());
}
}
2022-10-21 11:21:35 +08:00
}
void SignalTransformer::handleItemUpdateAll(const QString &desktopFilePath)
2022-10-21 11:21:35 +08:00
{
QMutexLocker locker(&s_mutex);
m_items2BUpdateAll.append(desktopFilePath);
}
void SignalTransformer::handleItemDelete(const QString &desktopFilePath)
{
QMutexLocker locker(&s_mutex);
m_items2BDelete.append(desktopFilePath);
2022-10-21 11:21:35 +08:00
}
void SignalTransformer::handleSignalTransform()
{
QMutexLocker locker(&s_mutex);
if (!m_items2BInsert.isEmpty()) {
Q_EMIT this->appDBItemsAdd(m_items2BInsert);
m_items2BInsert.clear();
}
if (!m_items2BUpdate.isEmpty()) {
Q_EMIT this->appDBItemsUpdate(m_items2BUpdate);
m_items2BUpdate.clear();
}
if (!m_items2BUpdateAll.isEmpty()) {
Q_EMIT this->appDBItemsUpdateAll(m_items2BUpdateAll);
m_items2BUpdateAll.clear();
}
if (!m_items2BDelete.isEmpty()) {
Q_EMIT this->appDBItemsDelete(m_items2BDelete);
m_items2BDelete.clear();
}
2022-10-21 11:21:35 +08:00
}
SignalTransformer::SignalTransformer(QObject *parent) : QObject(parent)
{
connect(AppDBManager::getInstance(), &AppDBManager::appDBItemAdd, this, &SignalTransformer::handleItemInsert);
connect(AppDBManager::getInstance(), &AppDBManager::appDBItemUpdate, this, &SignalTransformer::handleItemUpdate);
connect(AppDBManager::getInstance(), &AppDBManager::appDBItemDelete, this, &SignalTransformer::handleItemDelete);
connect(AppDBManager::getInstance(), &AppDBManager::appDBItemUpdateAll, this, &SignalTransformer::handleItemUpdateAll);
2022-10-21 11:21:35 +08:00
connect(AppDBManager::getInstance(), &AppDBManager::finishHandleAppDB, this, &SignalTransformer::handleSignalTransform);
}