fix(app-database-service):modify the time sequence of the transmitted signal.

This commit is contained in:
JunjieBai 2023-08-11 11:39:36 +08:00
parent ba31496a89
commit 87e6da7336
2 changed files with 57 additions and 1 deletions

View File

@ -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);
}

View File

@ -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&);