optimize the signal transformer, modify the data struct of the signals.

This commit is contained in:
JunjieBai 2023-02-06 11:46:07 +08:00
parent faf815f77e
commit 738f116b83
3 changed files with 85 additions and 49 deletions

View File

@ -501,11 +501,11 @@ void AppDBManager::refreshAllData2DB()
} }
} }
bool AppDBManager::handleLocaleDataUpdate(const QString &desktopPath) bool AppDBManager::handleLocaleDataUpdate(const QString &desktopfp)
{ {
bool res(true); bool res(true);
XdgDesktopFile desktopFile; XdgDesktopFile desktopFile;
desktopFile.load(desktopPath); desktopFile.load(desktopfp);
QString localName = desktopFile.localizedValue("Name", "NULL").toString(); QString localName = desktopFile.localizedValue("Name", "NULL").toString();
QString firstLetter2All = localName; QString firstLetter2All = localName;
@ -520,7 +520,7 @@ bool AppDBManager::handleLocaleDataUpdate(const QString &desktopPath)
"WHERE DESKTOP_FILE_PATH='%2'") "WHERE DESKTOP_FILE_PATH='%2'")
.arg(localName) .arg(localName)
.arg(firstLetter2All) .arg(firstLetter2All)
.arg(desktopPath); .arg(desktopfp);
if (!sql.exec(cmd)) { if (!sql.exec(cmd)) {
qWarning() << m_database.lastError() << cmd; qWarning() << m_database.lastError() << cmd;
@ -528,12 +528,14 @@ bool AppDBManager::handleLocaleDataUpdate(const QString &desktopPath)
} }
if (res) { if (res) {
AppInfoResult result; AppInfoResult result;
result.appLocalName = localName; if (this->createAppInfoResult(desktopfp, result)) {
result.firstLetter = firstLetter2All; qDebug() << "Update the locale data of " << result.desktopPath;
Q_EMIT this->appDBItemUpdate(result); Q_EMIT this->appDBItemUpdate(result);
qDebug() << "Already to update the locale app-data of " << desktopPath; }
} else { } else {
qDebug() << "Fail to update the locale app-data of " << desktopPath; qDebug() << "Fail to update the locale data of " << desktopfp;
} }
return res; return res;
} }
@ -753,14 +755,14 @@ bool AppDBManager::handleDBItemDelete(const QString &desktopfd)
return res; return res;
} }
bool AppDBManager::handleDBItemUpdate(const QString &desktopfd) bool AppDBManager::handleDBItemUpdate(const QString &desktopfp)
{ {
bool res(true); bool res(true);
XdgDesktopFile desktopfile; XdgDesktopFile desktopfile;
desktopfile.load(desktopfd); desktopfile.load(desktopfp);
if (desktopfile.value("NoDisplay").toString().contains("true") || desktopfile.value("NotShowIn").toString().contains("UKUI")) { if (desktopfile.value("NoDisplay").toString().contains("true") || desktopfile.value("NotShowIn").toString().contains("UKUI")) {
qDebug() << "app" << desktopfd << "is changed, but NoDisplay or NotShowIn is working!"; qDebug() << "app" << desktopfp << "is changed, but NoDisplay or NotShowIn is working!";
return this->handleDBItemDelete(desktopfd); return this->handleDBItemDelete(desktopfp);
} }
QString hanzi, pinyin, firstLetterOfPinyin; QString hanzi, pinyin, firstLetterOfPinyin;
QString localName = desktopfile.localizedValue("Name", "NULL").toString(); 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("Categories").toString())
.arg(desktopfile.value("Exec").toString()) .arg(desktopfile.value("Exec").toString())
.arg(desktopfile.value("Comment").toString().replace("'", "''")) .arg(desktopfile.value("Comment").toString().replace("'", "''"))
.arg(getAppDesktopMd5(desktopfd)) .arg(getAppDesktopMd5(desktopfp))
.arg(desktopfd); .arg(desktopfp);
if (!sql.exec(cmd)) { if (!sql.exec(cmd)) {
qWarning() << m_database.lastError() << cmd; qWarning() << m_database.lastError() << cmd;
res = false; res = false;
} }
if (res) { if (res) {
AppInfoResult result; AppInfoResult result;
result.desktopPath = desktopfd; if (this->createAppInfoResult(desktopfp, result)) {
result.iconName = desktopfile.value("Icon").toString(); qDebug() << "app database update " << result.desktopPath << "success!";
result.appLocalName = localName; Q_EMIT this->appDBItemUpdate(result);
result.firstLetter = firstLetter2All; }
result.category = desktopfile.value("Categories").toString();
Q_EMIT this->appDBItemUpdate(result);
qDebug() << "app database update " << desktopfd << "success!";
} else { } else {
qDebug() << "app database update " << desktopfd << "failed!"; qDebug() << "app database update " << desktopfp << "failed!";
} }
return res; return res;
} }
@ -860,10 +859,10 @@ bool AppDBManager::handleLaunchTimesUpdate(const QString &desktopfp, int num)
res = false; res = false;
} else { } else {
AppInfoResult result; AppInfoResult result;
result.desktopPath = desktopfp; if (this->createAppInfoResult(desktopfp, result)) {
result.launchTimes = launchTimes; qDebug() << "app database update " << result.desktopPath << "launch times: " << result.launchTimes << "success!";
Q_EMIT this->appDBItemUpdate(result); Q_EMIT this->appDBItemUpdate(result);
qDebug() << "app database update:" << desktopfp << "launch times:" << launchTimes << "success!"; }
} }
} else { } else {
qWarning() << "Failed to exec next!" << cmd; 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(); qWarning() << "Set app favorites state failed!" << m_database.lastError();
res = false; res = false;
} else { } else {
AppInfoResult info; AppInfoResult result;
info.desktopPath = desktopfp; if (this->createAppInfoResult(desktopfp, result)) {
info.favorite = num; qDebug() << "app database update " << result.desktopPath << "favorites state: " << result.favorite << "success!";
Q_EMIT this->appDBItemUpdate(info); Q_EMIT this->appDBItemUpdate(result);
qDebug() << "app database update " << desktopfp << "favorites state: " << num << "success!"; }
} }
return res; return res;
} }
@ -961,11 +960,11 @@ bool AppDBManager::handleTopStateUpdate(const QString &desktopfp, int num)
qWarning() << "Set app favorites state failed!" << m_database.lastError(); qWarning() << "Set app favorites state failed!" << m_database.lastError();
res = false; res = false;
} else { } else {
AppInfoResult info; AppInfoResult result;
info.desktopPath = desktopfp; if (this->createAppInfoResult(desktopfp, result)) {
info.top = num; qDebug() << "app database update " << result.desktopPath << "top state: " << result.top << "success!";
Q_EMIT this->appDBItemUpdate(info); Q_EMIT this->appDBItemUpdate(result);
qDebug() << "app database update " << desktopfp << "top state: " << num << "success!"; }
} }
return res; return res;
} }
@ -982,11 +981,39 @@ bool AppDBManager::handleLockStateUpdate(const QString &desktopfp, int num)
qWarning() << "Set app favorites state failed!" << m_database.lastError(); qWarning() << "Set app favorites state failed!" << m_database.lastError();
res = false; res = false;
} else { } else {
AppInfoResult info; AppInfoResult result;
info.desktopPath = desktopfp; if (this->createAppInfoResult(desktopfp, result)) {
info.lock = num; qDebug() << "app database update " << result.desktopPath << "lock state: " << result.lock << "success!";
Q_EMIT this->appDBItemUpdate(info); Q_EMIT this->appDBItemUpdate(result);
qDebug() << "app database update " << desktopfp << "lock state: " << num << "success!"; }
}
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; return res;
} }

View File

@ -65,14 +65,15 @@ public:
bool startCommit(); bool startCommit();
bool handleDBItemInsert(const QString &desktopfd); bool handleDBItemInsert(const QString &desktopfd);
bool handleDBItemUpdate(const QString &desktopfd); bool handleDBItemUpdate(const QString &desktopfp);
bool handleDBItemDelete(const QString &desktopfd); bool handleDBItemDelete(const QString &desktopfd);
bool handleLocaleDataUpdate(const QString &desktopPath); bool handleLocaleDataUpdate(const QString &desktopfp);
bool handleLaunchTimesUpdate(const QString &desktopfp, int num); bool handleLaunchTimesUpdate(const QString &desktopfp, int num);
bool handleFavoritesStateUpdate(const QString &desktopfp, int num); bool handleFavoritesStateUpdate(const QString &desktopfp, int num);
bool handleTopStateUpdate(const QString &desktopfp, int num); bool handleTopStateUpdate(const QString &desktopfp, int num);
bool handleLockStateUpdate(const QString &desktopfp, int num); bool handleLockStateUpdate(const QString &desktopfp, int num);
bool createAppInfoResult(const QString &desktopfp, AppInfoResult &result);
public Q_SLOTS: public Q_SLOTS:
//对数据库单条所有信息进行增删改 //对数据库单条所有信息进行增删改

View File

@ -29,12 +29,20 @@ void SignalTransformer::handleItemDelete(const QString &desktopfp)
void SignalTransformer::handleSignalTransform() void SignalTransformer::handleSignalTransform()
{ {
QMutexLocker locker(&s_mutex); QMutexLocker locker(&s_mutex);
Q_EMIT this->appDBItemsAdd(m_items2BInsert); if (!m_items2BInsert.isEmpty()) {
Q_EMIT this->appDBItemsUpdate(m_items2BUpdate); Q_EMIT this->appDBItemsAdd(m_items2BInsert);
Q_EMIT this->appDBItemsDelete(m_items2BDelete); m_items2BInsert.clear();
m_items2BInsert.clear(); }
m_items2BUpdate.clear();
m_items2BDelete.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) SignalTransformer::SignalTransformer(QObject *parent) : QObject(parent)