2023-04-11 10:19:35 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2022-06-28 11:20:36 +08:00
|
|
|
#include "signal-transformer.h"
|
|
|
|
|
|
|
|
QMutex SignalTransformer::s_mutex;
|
|
|
|
|
|
|
|
SignalTransformer *SignalTransformer::getTransformer()
|
|
|
|
{
|
|
|
|
static SignalTransformer *instance = new SignalTransformer();
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2023-08-11 11:39:36 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 17:47:04 +08:00
|
|
|
void SignalTransformer::handleItemInsert(const QString &desktopFilePath)
|
2022-06-28 11:20:36 +08:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&s_mutex);
|
2023-08-11 11:39:36 +08:00
|
|
|
if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::Insert)) {
|
|
|
|
transform();
|
|
|
|
}
|
|
|
|
m_signalType = SignalType::Insert;
|
2023-03-10 17:47:04 +08:00
|
|
|
m_items2BInsert.append(desktopFilePath);
|
2022-06-28 11:20:36 +08:00
|
|
|
}
|
|
|
|
|
2023-03-10 17:47:04 +08:00
|
|
|
void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item)
|
2022-06-28 11:20:36 +08:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&s_mutex);
|
2023-08-11 11:39:36 +08:00
|
|
|
if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::Update)) {
|
|
|
|
transform();
|
|
|
|
}
|
|
|
|
m_signalType = SignalType::Update;
|
2023-03-10 17:47:04 +08:00
|
|
|
for(auto it = item.constBegin(); it != item.constEnd(); it++) {
|
2023-03-15 16:39:38 +08:00
|
|
|
ApplicationPropertyMap propertyinfo = it.value();
|
2023-03-10 17:47:04 +08:00
|
|
|
for (auto i = propertyinfo.constBegin(); i != propertyinfo.constEnd(); i++) {
|
|
|
|
m_items2BUpdate[it.key()].insert(i.key(), i.value());
|
|
|
|
}
|
|
|
|
}
|
2022-06-28 11:20:36 +08:00
|
|
|
}
|
|
|
|
|
2023-03-10 17:47:04 +08:00
|
|
|
void SignalTransformer::handleItemUpdateAll(const QString &desktopFilePath)
|
2022-06-28 11:20:36 +08:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&s_mutex);
|
2023-08-11 11:39:36 +08:00
|
|
|
if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::UpdateAll)) {
|
|
|
|
transform();
|
|
|
|
}
|
|
|
|
m_signalType = SignalType::UpdateAll;
|
2023-03-10 17:47:04 +08:00
|
|
|
m_items2BUpdateAll.append(desktopFilePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SignalTransformer::handleItemDelete(const QString &desktopFilePath)
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&s_mutex);
|
2023-08-11 11:39:36 +08:00
|
|
|
if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::Delete)) {
|
|
|
|
transform();
|
|
|
|
}
|
|
|
|
m_signalType = SignalType::Delete;
|
2023-03-10 17:47:04 +08:00
|
|
|
m_items2BDelete.append(desktopFilePath);
|
2022-06-28 11:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SignalTransformer::handleSignalTransform()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&s_mutex);
|
2023-02-06 11:46:07 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2023-03-10 17:47:04 +08:00
|
|
|
if (!m_items2BUpdateAll.isEmpty()) {
|
|
|
|
Q_EMIT this->appDBItemsUpdateAll(m_items2BUpdateAll);
|
|
|
|
m_items2BUpdateAll.clear();
|
|
|
|
}
|
|
|
|
|
2023-02-06 11:46:07 +08:00
|
|
|
if (!m_items2BDelete.isEmpty()) {
|
|
|
|
Q_EMIT this->appDBItemsDelete(m_items2BDelete);
|
|
|
|
m_items2BDelete.clear();
|
|
|
|
}
|
2022-06-28 11:20:36 +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);
|
2023-03-10 17:47:04 +08:00
|
|
|
connect(AppDBManager::getInstance(), &AppDBManager::appDBItemUpdateAll, this, &SignalTransformer::handleItemUpdateAll);
|
2022-06-28 11:20:36 +08:00
|
|
|
connect(AppDBManager::getInstance(), &AppDBManager::finishHandleAppDB, this, &SignalTransformer::handleSignalTransform);
|
|
|
|
}
|
|
|
|
|