diff --git a/ukui-search-app-data-service/app-db-manager.cpp b/ukui-search-app-data-service/app-db-manager.cpp index 5012410..79ac926 100644 --- a/ukui-search-app-data-service/app-db-manager.cpp +++ b/ukui-search-app-data-service/app-db-manager.cpp @@ -501,11 +501,11 @@ void AppDBManager::refreshAllData2DB() } } -bool AppDBManager::handleLocaleDataUpdate(const QString &desktopPath) +bool AppDBManager::handleLocaleDataUpdate(const QString &desktopfp) { bool res(true); XdgDesktopFile desktopFile; - desktopFile.load(desktopPath); + desktopFile.load(desktopfp); QString localName = desktopFile.localizedValue("Name", "NULL").toString(); QString firstLetter2All = localName; @@ -520,7 +520,7 @@ bool AppDBManager::handleLocaleDataUpdate(const QString &desktopPath) "WHERE DESKTOP_FILE_PATH='%2'") .arg(localName) .arg(firstLetter2All) - .arg(desktopPath); + .arg(desktopfp); if (!sql.exec(cmd)) { qWarning() << m_database.lastError() << cmd; @@ -528,12 +528,14 @@ bool AppDBManager::handleLocaleDataUpdate(const QString &desktopPath) } if (res) { AppInfoResult result; - result.appLocalName = localName; - result.firstLetter = firstLetter2All; - Q_EMIT this->appDBItemUpdate(result); - qDebug() << "Already to update the locale app-data of " << desktopPath; + if (this->createAppInfoResult(desktopfp, result)) { + qDebug() << "Update the locale data of " << result.desktopPath; + Q_EMIT this->appDBItemUpdate(result); + } + + } else { - qDebug() << "Fail to update the locale app-data of " << desktopPath; + qDebug() << "Fail to update the locale data of " << desktopfp; } return res; } @@ -753,14 +755,14 @@ bool AppDBManager::handleDBItemDelete(const QString &desktopfd) return res; } -bool AppDBManager::handleDBItemUpdate(const QString &desktopfd) +bool AppDBManager::handleDBItemUpdate(const QString &desktopfp) { bool res(true); XdgDesktopFile desktopfile; - desktopfile.load(desktopfd); + desktopfile.load(desktopfp); if (desktopfile.value("NoDisplay").toString().contains("true") || desktopfile.value("NotShowIn").toString().contains("UKUI")) { - qDebug() << "app" << desktopfd << "is changed, but NoDisplay or NotShowIn is working!"; - return this->handleDBItemDelete(desktopfd); + qDebug() << "app" << desktopfp << "is changed, but NoDisplay or NotShowIn is working!"; + return this->handleDBItemDelete(desktopfp); } QString hanzi, pinyin, firstLetterOfPinyin; QString localName = desktopfile.localizedValue("Name", "NULL").toString(); @@ -820,23 +822,20 @@ bool AppDBManager::handleDBItemUpdate(const QString &desktopfd) .arg(desktopfile.value("Categories").toString()) .arg(desktopfile.value("Exec").toString()) .arg(desktopfile.value("Comment").toString().replace("'", "''")) - .arg(getAppDesktopMd5(desktopfd)) - .arg(desktopfd); + .arg(getAppDesktopMd5(desktopfp)) + .arg(desktopfp); if (!sql.exec(cmd)) { qWarning() << m_database.lastError() << cmd; res = false; } if (res) { AppInfoResult result; - result.desktopPath = desktopfd; - result.iconName = desktopfile.value("Icon").toString(); - result.appLocalName = localName; - result.firstLetter = firstLetter2All; - result.category = desktopfile.value("Categories").toString(); - Q_EMIT this->appDBItemUpdate(result); - qDebug() << "app database update " << desktopfd << "success!"; + if (this->createAppInfoResult(desktopfp, result)) { + qDebug() << "app database update " << result.desktopPath << "success!"; + Q_EMIT this->appDBItemUpdate(result); + } } else { - qDebug() << "app database update " << desktopfd << "failed!"; + qDebug() << "app database update " << desktopfp << "failed!"; } return res; } @@ -860,10 +859,10 @@ bool AppDBManager::handleLaunchTimesUpdate(const QString &desktopfp, int num) res = false; } else { AppInfoResult result; - result.desktopPath = desktopfp; - result.launchTimes = launchTimes; - Q_EMIT this->appDBItemUpdate(result); - qDebug() << "app database update:" << desktopfp << "launch times:" << launchTimes << "success!"; + if (this->createAppInfoResult(desktopfp, result)) { + qDebug() << "app database update " << result.desktopPath << "launch times: " << result.launchTimes << "success!"; + Q_EMIT this->appDBItemUpdate(result); + } } } else { qWarning() << "Failed to exec next!" << cmd; @@ -914,11 +913,11 @@ bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopfp, int num) qWarning() << "Set app favorites state failed!" << m_database.lastError(); res = false; } else { - AppInfoResult info; - info.desktopPath = desktopfp; - info.favorite = num; - Q_EMIT this->appDBItemUpdate(info); - qDebug() << "app database update " << desktopfp << "favorites state: " << num << "success!"; + AppInfoResult result; + if (this->createAppInfoResult(desktopfp, result)) { + qDebug() << "app database update " << result.desktopPath << "favorites state: " << result.favorite << "success!"; + Q_EMIT this->appDBItemUpdate(result); + } } return res; } @@ -961,11 +960,11 @@ bool AppDBManager::handleTopStateUpdate(const QString &desktopfp, int num) qWarning() << "Set app favorites state failed!" << m_database.lastError(); res = false; } else { - AppInfoResult info; - info.desktopPath = desktopfp; - info.top = num; - Q_EMIT this->appDBItemUpdate(info); - qDebug() << "app database update " << desktopfp << "top state: " << num << "success!"; + AppInfoResult result; + if (this->createAppInfoResult(desktopfp, result)) { + qDebug() << "app database update " << result.desktopPath << "top state: " << result.top << "success!"; + Q_EMIT this->appDBItemUpdate(result); + } } return res; } @@ -982,11 +981,39 @@ bool AppDBManager::handleLockStateUpdate(const QString &desktopfp, int num) qWarning() << "Set app favorites state failed!" << m_database.lastError(); res = false; } else { - AppInfoResult info; - info.desktopPath = desktopfp; - info.lock = num; - Q_EMIT this->appDBItemUpdate(info); - qDebug() << "app database update " << desktopfp << "lock state: " << num << "success!"; + AppInfoResult result; + if (this->createAppInfoResult(desktopfp, result)) { + qDebug() << "app database update " << result.desktopPath << "lock state: " << result.lock << "success!"; + Q_EMIT this->appDBItemUpdate(result); + } + } + return res; +} + +bool AppDBManager::createAppInfoResult(const QString &desktopfp, AppInfoResult &result) +{ + bool res(false); + QSqlQuery sql(m_database); + QString cmd = QString("SELECT ICON, LOCAL_NAME, FIRST_LETTER_ALL, CATEGORY, " + "TOP, FAVORITES, LAUNCH_TIMES, LOCK FROM APPINFO " + "WHERE DESKTOP_FILE_PATH='%1'").arg(desktopfp); + if(sql.exec(cmd)) { + if (sql.next()) { + result.desktopPath = desktopfp; + result.iconName = sql.value(0).toString(); + result.appLocalName = sql.value(1).toString(); + result.firstLetter = sql.value(2).toString(); + result.category = sql.value(3).toString(); + result.top = sql.value(4).toInt(); + result.favorite = sql.value(5).toInt(); + result.launchTimes = sql.value(6).toInt(); + result.lock = sql.value(7).toInt(); + res = true; + } else { + qWarning() << "Fail to exec next. " << cmd << m_database.lastError(); + } + } else { + qWarning() << "Fail to exec " << cmd << m_database.lastError(); } return res; } diff --git a/ukui-search-app-data-service/app-db-manager.h b/ukui-search-app-data-service/app-db-manager.h index f0ae476..bd4e9f4 100644 --- a/ukui-search-app-data-service/app-db-manager.h +++ b/ukui-search-app-data-service/app-db-manager.h @@ -65,14 +65,15 @@ public: bool startCommit(); bool handleDBItemInsert(const QString &desktopfd); - bool handleDBItemUpdate(const QString &desktopfd); + bool handleDBItemUpdate(const QString &desktopfp); bool handleDBItemDelete(const QString &desktopfd); - bool handleLocaleDataUpdate(const QString &desktopPath); + bool handleLocaleDataUpdate(const QString &desktopfp); bool handleLaunchTimesUpdate(const QString &desktopfp, int num); bool handleFavoritesStateUpdate(const QString &desktopfp, int num); bool handleTopStateUpdate(const QString &desktopfp, int num); bool handleLockStateUpdate(const QString &desktopfp, int num); + bool createAppInfoResult(const QString &desktopfp, AppInfoResult &result); public Q_SLOTS: //对数据库单条所有信息进行增删改 diff --git a/ukui-search-app-data-service/signal-transformer.cpp b/ukui-search-app-data-service/signal-transformer.cpp index 6cc081e..97bdbf6 100644 --- a/ukui-search-app-data-service/signal-transformer.cpp +++ b/ukui-search-app-data-service/signal-transformer.cpp @@ -29,12 +29,20 @@ void SignalTransformer::handleItemDelete(const QString &desktopfp) void SignalTransformer::handleSignalTransform() { QMutexLocker locker(&s_mutex); - Q_EMIT this->appDBItemsAdd(m_items2BInsert); - Q_EMIT this->appDBItemsUpdate(m_items2BUpdate); - Q_EMIT this->appDBItemsDelete(m_items2BDelete); - m_items2BInsert.clear(); - m_items2BUpdate.clear(); - m_items2BDelete.clear(); + 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_items2BDelete.isEmpty()) { + Q_EMIT this->appDBItemsDelete(m_items2BDelete); + m_items2BDelete.clear(); + } } SignalTransformer::SignalTransformer(QObject *parent) : QObject(parent)