diff --git a/ukui-search-app-data-service/signal-transformer.cpp b/ukui-search-app-data-service/signal-transformer.cpp index 7947912..7068dcf 100644 --- a/ukui-search-app-data-service/signal-transformer.cpp +++ b/ukui-search-app-data-service/signal-transformer.cpp @@ -26,15 +26,55 @@ SignalTransformer *SignalTransformer::getTransformer() return instance; } +void SignalTransformer::transform() +{ + switch (m_signalType) { + case Delete: + if (!m_items2BDelete.isEmpty()) { + Q_EMIT this->appDBItemsDelete(m_items2BDelete); + m_items2BDelete.clear(); + } + break; + case Insert: + if (!m_items2BInsert.isEmpty()) { + Q_EMIT this->appDBItemsAdd(m_items2BInsert); + m_items2BInsert.clear(); + } + break; + case UpdateAll: + if (!m_items2BUpdateAll.isEmpty()) { + Q_EMIT this->appDBItemsUpdateAll(m_items2BUpdateAll); + m_items2BUpdateAll.clear(); + } + break; + case Update: + if (!m_items2BUpdate.isEmpty()) { + Q_EMIT this->appDBItemsUpdate(m_items2BUpdate); + m_items2BUpdate.clear(); + } + break; + default: + break; + } +} + void SignalTransformer::handleItemInsert(const QString &desktopFilePath) { QMutexLocker locker(&s_mutex); + if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::Insert)) { + transform(); + } + m_signalType = SignalType::Insert; m_items2BInsert.append(desktopFilePath); } void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item) { QMutexLocker locker(&s_mutex); + if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::Update)) { + transform(); + } + m_signalType = SignalType::Update; for(auto it = item.constBegin(); it != item.constEnd(); it++) { ApplicationPropertyMap propertyinfo = it.value(); for (auto i = propertyinfo.constBegin(); i != propertyinfo.constEnd(); i++) { @@ -46,12 +86,20 @@ void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item) void SignalTransformer::handleItemUpdateAll(const QString &desktopFilePath) { QMutexLocker locker(&s_mutex); + if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::UpdateAll)) { + transform(); + } + m_signalType = SignalType::UpdateAll; m_items2BUpdateAll.append(desktopFilePath); } void SignalTransformer::handleItemDelete(const QString &desktopFilePath) { QMutexLocker locker(&s_mutex); + if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::Delete)) { + transform(); + } + m_signalType = SignalType::Delete; m_items2BDelete.append(desktopFilePath); } diff --git a/ukui-search-app-data-service/signal-transformer.h b/ukui-search-app-data-service/signal-transformer.h index a5a2961..e513a64 100644 --- a/ukui-search-app-data-service/signal-transformer.h +++ b/ukui-search-app-data-service/signal-transformer.h @@ -34,10 +34,16 @@ class SignalTransformer : public QObject Q_OBJECT public: + enum SignalType{ + Invalid = -1, + Delete = 0, + Insert, + UpdateAll, + Update + }; static SignalTransformer *getTransformer(); static QMutex s_mutex; - public Q_SLOTS: void handleItemUpdate(const ApplicationInfoMap &item); void handleItemUpdateAll(const QString &desktopFilePath); @@ -49,11 +55,13 @@ private: SignalTransformer(QObject *parent = nullptr); SignalTransformer(const SignalTransformer &) = delete; SignalTransformer& operator = (const SignalTransformer&) = delete; + void transform(); ApplicationInfoMap m_items2BUpdate; QStringList m_items2BUpdateAll; QStringList m_items2BInsert; QStringList m_items2BDelete; + SignalType m_signalType = SignalType::Invalid; Q_SIGNALS: void appDBItemsUpdateAll(const QStringList&);