Optimize the logic which change position and set state of favorites/top.

Optimize the logic of the database transaction.
This commit is contained in:
JunjieBai 2023-03-31 17:24:06 +08:00
parent 366201ddf9
commit e09044dfee
9 changed files with 637 additions and 424 deletions

View File

@ -18,12 +18,10 @@ public:
AppInfoTablePrivate &operator =(const AppInfoTablePrivate &) = delete;
//设置应用的置顶和收藏
void setAppFavoritesState(const QString &desktopfp, int num);
void setAppTopState(const QString &desktopfp, int num);
//改变置顶和收藏应用位置
bool changeFavoriteAppPos(const QString &desktopfp, int pos);
bool changeTopAppPos(const QString &desktopfp, int pos);
void setAppFavoritesState(const QString &desktopfp);
void setAppFavoritesState(const QString &desktopfp, uint num);
void setAppTopState(const QString &desktopfp);
void setAppTopState(const QString &desktopfp, uint num);
//搜索接口
bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes);

View File

@ -63,38 +63,26 @@ AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent)
}
}
void AppInfoTablePrivate::setAppFavoritesState(const QString &desktopfp, int num)
void AppInfoTablePrivate::setAppFavoritesState(const QString &desktopfp)
{
m_appDBInterface->call("updateFavoritesState", desktopfp);
}
void AppInfoTablePrivate::setAppFavoritesState(const QString &desktopfp, uint num)
{
m_appDBInterface->call("updateFavoritesState", desktopfp, num);
}
void AppInfoTablePrivate::setAppTopState(const QString &desktopfp, int num)
void AppInfoTablePrivate::setAppTopState(const QString &desktopfp)
{
m_appDBInterface->call("updateTopState", desktopfp);
}
void AppInfoTablePrivate::setAppTopState(const QString &desktopfp, uint num)
{
m_appDBInterface->call("updateTopState", desktopfp, num);
}
bool AppInfoTablePrivate::changeFavoriteAppPos(const QString &desktopfp, int pos)
{
QDBusReply<bool> reply = m_appDBInterface->call("changeFavoriteAppPos", desktopfp, pos);
if (reply.isValid()) {
return reply.value();
} else {
qDebug() << m_appDBInterface->lastError();
return false;
}
}
bool AppInfoTablePrivate::changeTopAppPos(const QString &desktopfp, int pos)
{
QDBusReply<bool> reply = m_appDBInterface->call("changeTopAppPos", desktopfp, pos);
if (reply.isValid()) {
return reply.value();
} else {
qDebug() << m_appDBInterface->lastError();
return false;
}
}
bool AppInfoTablePrivate::searchInstallApp(QString &keyWord, QStringList &installAppInfoRes)
{
bool res(true);
@ -519,6 +507,11 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, ApplicationProperties prop
return true;
}
void AppInfoTable::setAppFavoritesState(const QString &desktopfp)
{
return d->setAppFavoritesState(desktopfp);
}
void AppInfoTable::setAppFavoritesState(const QString &desktopfp, size_t num)
{
return d->setAppFavoritesState(desktopfp, num);
@ -529,14 +522,9 @@ void AppInfoTable::setAppTopState(const QString &desktopfp, size_t num)
return d->setAppTopState(desktopfp, num);
}
bool AppInfoTable::changeFavoriteAppPos(const QString &desktopfp, size_t pos)
void AppInfoTable::setAppTopState(const QString &desktopfp)
{
return d->changeFavoriteAppPos(desktopfp, pos);
}
bool AppInfoTable::changeTopAppPos(const QString &desktopfp, size_t pos)
{
return d->changeTopAppPos(desktopfp, pos);
return d->setAppTopState(desktopfp);
}
bool AppInfoTable::searchInstallApp(QString &keyWord, QStringList &installAppInfoRes)

View File

@ -28,7 +28,14 @@ public:
/**
* @brief AppInfoTable::setAppFavoritesState
* set the favorites state of the app
* set the app to favorites apps(default is at 1)
* @param desktopfp: the desktop file path of app
*/
void setAppFavoritesState(const QString &desktopfp);
/**
* @brief AppInfoTable::setAppFavoritesState
* set the favorites state of the app, you can also use to change the position of the app which is one of the Favorites Apps
* @param desktopfp: the desktop file path of app
* @param num: the favorites app's order(from 1)
*/
@ -36,29 +43,19 @@ public:
/**
* @brief AppInfoTable::setAppTopState
* set the top state of the app
* set the app to top apps(default is at 1)
* @param desktopfp: desktop file path of app
*/
void setAppTopState(const QString &desktopfp);
/**
* @brief AppInfoTable::setAppTopState
* set the top state of the app, you can also use to change the position of the app which is one of the Top Apps
* @param desktopfp: the desktop file path of app
* @param num: the top app's order(from 1)
*/
void setAppTopState(const QString &desktopfp, size_t num);
/**
* @brief AppInfoTable::changeFavoriteAppPos
* change the position of the app which is one of the Favorites Apps
* @param desktopfp: desktop file path of app
* @param pos: the position which the app will be changed into
*/
bool changeFavoriteAppPos(const QString &desktopfp, size_t pos);
/**
* @brief AppInfoTable::changeTopAppPos
* hange the position of the app which is one of the Top Apps
* @param desktopfp: desktop file path of app
* @param pos: the position which the app will be changed into
* @return bool: true if success, else false
*/
bool changeTopAppPos(const QString &desktopfp, size_t pos);
bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes);
bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes);

View File

@ -67,26 +67,26 @@ ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties,
return infoMap;
}
void ApplicationInfo::setAppFavoritesState(const QString &desktopFilePath, size_t num)
void ApplicationInfo::setAppToFavorites(const QString &desktopFilePath)
{
AppInfoTable::self()->setAppFavoritesState(desktopFilePath);
}
void ApplicationInfo::setFavoritesOfApp(const QString &desktopFilePath, size_t num)
{
AppInfoTable::self()->setAppFavoritesState(desktopFilePath, num);
}
void ApplicationInfo::setAppTopState(const QString &desktopFilePath, size_t num)
void ApplicationInfo::setAppToTop(const QString &desktopFilePath)
{
AppInfoTable::self()->setAppTopState(desktopFilePath);
}
void ApplicationInfo::setTopOfApp(const QString &desktopFilePath, size_t num)
{
AppInfoTable::self()->setAppTopState(desktopFilePath, num);
}
bool ApplicationInfo::changeFavoriteAppPos(const QString &desktopFilePath, size_t pos)
{
return AppInfoTable::self()->changeFavoriteAppPos(desktopFilePath, pos);
}
bool ApplicationInfo::changeTopAppPos(const QString &desktopFilePath, size_t pos)
{
return AppInfoTable::self()->changeTopAppPos(desktopFilePath, pos);
}
bool ApplicationInfo::tranPidToDesktopFp(int pid, QString &desktopFilePath)
{
return AppInfoTable::self()->tranPidToDesktopFp(pid, desktopFilePath);

View File

@ -52,37 +52,34 @@ public:
ApplicationInfoMap searchApp(ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions);
/**
* @brief ApplicationInfo::setAppFavoritesState
* set the favorites state of the app
* @param desktopFilePath: the desktop file path of app
* @param num: the favorites app's order(from 1)
* @brief AppInfoTable::setAppToFavorites
* set the app to favorites apps(default is at 1)
* @param desktopfp: the desktop file path of app
*/
void setAppFavoritesState(const QString &desktopFilePath, size_t num);
void setAppToFavorites(const QString &desktopFilePath);
/**
* @brief ApplicationInfo::setAppTopState
* set the top state of the app
* @param desktopFilePath: the desktop file path of app
* @param num: the top app's order(from 1)
* @brief AppInfoTable::setFavoritesTo
* set the favorites state of the app to num, you can also use to change the position of the app which is one of the Favorites Apps
* @param desktopfp: the desktop file path of app
* @param num: the favorites app's position(from 1). If num is 0, it will remove the app from the favorites apps
*/
void setAppTopState(const QString &desktopFilePath, size_t num);
void setFavoritesOfApp(const QString &desktopFilePath, size_t num);
/**
* @brief ApplicationInfo::changeFavoriteAppPos
* change the position of the app which is one of the Favorites Apps
* @param desktopFilePath: desktop file path of app
* @param pos: the position which the app will be changed into
* @brief AppInfoTable::setAppToTop
* set the app to top apps(default is at 1)
* @param desktopfp: desktop file path of app
*/
bool changeFavoriteAppPos(const QString &desktopFilePath, size_t pos);
void setAppToTop(const QString &desktopFilePath);
/**
* @brief ApplicationInfo::changeTopAppPos
* hange the position of the app which is one of the Top Apps
* @param desktopFilePath: desktop file path of app
* @param pos: the position which the app will be changed into
* @return bool: true if success, else false
* @brief AppInfoTable::setAppTopTo
* set the top state of the app to num, you can also use to change the position of the app which is one of the Top Apps
* @param desktopfp: the desktop file path of app
* @param num: the top app's position(from 1). If num is 0, it will remove the app from the top apps
*/
bool changeTopAppPos(const QString &desktopFilePath, size_t pos);
void setTopOfApp(const QString &desktopFilePath, size_t num);
/**
* @brief ApplicationInfo::tranPid2DesktopFp

View File

@ -385,24 +385,31 @@ bool AppDBManager::handleLocaleDataUpdate(const QString &desktopFilePath)
}
QSqlQuery sql(m_database);
sql.prepare("UPDATE appInfo SET LOCAL_NAME=:localName, FIRST_LETTER_ALL=:firstOfLetter2All WHERE DESKTOP_FILE_PATH=:desktopFilePath");
sql.bindValue(":localName", localName);
sql.bindValue(":firstOfLetter2All", firstLetter2All);
sql.bindValue(":desktopFilePath", desktopFilePath);
QSqlQuery query(m_database);
query.prepare("UPDATE appInfo SET LOCAL_NAME=:localName, FIRST_LETTER_ALL=:firstOfLetter2All WHERE DESKTOP_FILE_PATH=:desktopFilePath");
query.bindValue(":localName", localName);
query.bindValue(":firstOfLetter2All", firstLetter2All);
query.bindValue(":desktopFilePath", desktopFilePath);
if (!sql.exec()) {
qWarning() << m_database.lastError() << sql.lastQuery();
res = false;
if (!this->startTransaction()) {
return false;
}
if (res) {
ApplicationInfoMap appInfo;
appInfo[desktopFilePath].insert(ApplicationProperty::LocalName, QVariant(localName));
appInfo[desktopFilePath].insert(ApplicationProperty::FirstLetterAll, QVariant(firstLetter2All));
Q_EMIT this->appDBItemUpdate(appInfo);
qDebug() << "Update the locale data of " << desktopFilePath;
if (query.exec()) {
if (this->startCommit()) {
ApplicationInfoMap appInfo;
appInfo[desktopFilePath].insert(ApplicationProperty::LocalName, QVariant(localName));
appInfo[desktopFilePath].insert(ApplicationProperty::FirstLetterAll, QVariant(firstLetter2All));
Q_EMIT this->appDBItemUpdate(appInfo);
qDebug() << "Update the locale data of " << desktopFilePath;
} else {
res = false;
}
} else {
qDebug() << "Fail to update the locale data of " << desktopFilePath;
qWarning() << query.lastError() << query.lastQuery();
m_database.rollback();
res = false;
}
return res;
}
@ -472,7 +479,7 @@ bool AppDBManager::startTransaction()
if (m_database.transaction()) {
return true;
} else {
qWarning() << "Failed to start transaction mode!!!";
qWarning() << "Failed to start transaction mode!!!" << m_database.lastError();
return false;
}
}
@ -480,7 +487,7 @@ bool AppDBManager::startTransaction()
bool AppDBManager::startCommit()
{
if (!m_database.commit()) {
qWarning() << "Failed to commit !";
qWarning() << "Failed to commit !" << m_database.lastError();
m_database.rollback();
return false;
} else {
@ -560,64 +567,117 @@ bool AppDBManager::handleDBItemInsert(const QString &desktopFilePath)
sql.bindValue(":exec", desktopfile.value("Exec").toString());
sql.bindValue(":comment", desktopfile.value("Comment").toString());
if (!sql.exec()) {
qWarning() << m_database.lastError() << sql.lastQuery();
res = false;
if (!this->startTransaction()) {
return false;
}
if (res) {
Q_EMIT this->appDBItemAdd(desktopFilePath);
qDebug() << "app database add " << desktopFilePath << "success!";
if (sql.exec()) {
if (this->startCommit()) {
Q_EMIT this->appDBItemAdd(desktopFilePath);
qDebug() << "app database add " << desktopFilePath << "success!";
} else {
res = false;
}
} else {
qDebug() << "app database add " << desktopFilePath << "failed!";
qWarning() << m_database.lastError() << sql.lastQuery();
m_database.rollback();
res = false;
}
return res;
}
bool AppDBManager::handleDBItemDelete(const QString &desktopFilePath)
{
if (!this->startTransaction()) {
return false;
}
bool res(true);
QSqlQuery sql(m_database);
sql.setForwardOnly(true);
QSqlQuery query(m_database);
query.setForwardOnly(true);
QString cmd = "SELECT FAVORITES, TOP FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath";
sql.prepare(cmd);
sql.bindValue(":desktopFilePath", desktopFilePath);
query.prepare(cmd);
query.bindValue(":desktopFilePath", desktopFilePath);
//查询要删除信息的应用是否被收藏或顶置过
if (!sql.exec()) {
qWarning() << m_database.lastError() << sql.lastQuery();
} else if (sql.next()) {
int favorites = sql.value("FAVORITES").toInt();
int top = sql.value("TOP").toInt();
if (!query.exec()) {
res = false;
qWarning() << m_database.lastError() << query.lastQuery();
} else if (query.next()) {
int favorites = query.value("FAVORITES").toInt();
int top = query.value("TOP").toInt();
if (favorites) {
cmd = QString("UPDATE appInfo SET FAVORITES = FAVORITES -1 WHERE FAVORITES > %1").arg(favorites);
if (!sql.exec(cmd)) {
qWarning() << "I'm going to delete item in db, fail to update the FAVORITES because:" << m_database.lastError() << cmd;
query.prepare(QString("UPDATE appInfo SET FAVORITES = FAVORITES -1 WHERE FAVORITES > %1").arg(favorites));
if (query.exec()) {
cmd = QString("SELECT DESKTOP_FILE_PATH,FAVORITES FROM APPINFO WHERE FAVORITES >= %1").arg(favorites);
if (query.exec(cmd)) {
ApplicationInfoMap infos;
while (query.next()) {
if (query.value("DESKTOP_FILE_PATH").toString() == desktopFilePath) {
continue;
}
infos[query.value("DESKTOP_FILE_PATH").toString()].insert(ApplicationProperty::Favorites, query.value("FAVORITES"));
}
if (!infos.isEmpty()) {
Q_EMIT this->appDBItemUpdate(infos);
}
} else {
qWarning() << query.lastError() << query.lastQuery();
}
} else {
res = false;
qWarning() << "I'm going to delete item in db, fail to update the FAVORITES because:" << query.lastError() << cmd;
}
}
if (top) {
cmd = QString("UPDATE appInfo SET TOP = TOP -1 WHERE TOP > %1").arg(top);
if (!sql.exec(cmd)) {
qWarning() << "I'm going to delete item in db, fail to update the TOP because:" << m_database.lastError() << cmd;
query.prepare(QString("UPDATE appInfo SET TOP = TOP -1 WHERE TOP > %1").arg(top));
if (query.exec()) {
cmd = QString("SELECT DESKTOP_FILE_PATH,TOP FROM APPINFO WHERE TOP >= %1").arg(top);
if (query.exec(cmd)) {
ApplicationInfoMap infos;
while (query.next()) {
if (query.value("DESKTOP_FILE_PATH").toString() == desktopFilePath) {
continue;
}
infos[query.value("DESKTOP_FILE_PATH").toString()].insert(ApplicationProperty::Top, query.value("TOP"));
}
if (!infos.isEmpty()) {
Q_EMIT this->appDBItemUpdate(infos);
}
} else {
qWarning() << query.lastError() << query.lastQuery();
}
} else {
res = false;
qWarning() << "I'm going to delete item in db, fail to update the TOP because:" << query.lastError() << cmd;
}
}
} else {
qWarning() << "Fail to exec next, because" << m_database.lastError() << "while executing " << cmd;
qWarning() << "Fail to exec next, because" << query.lastError() << "while executing " << query.lastQuery();
}
if (!res) {
m_database.rollback();
return res;
}
//执行删除操作
cmd = "DELETE FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath";
sql.prepare(cmd);
sql.bindValue(":desktopFilePath", desktopFilePath);
if (!sql.exec()) {
qWarning() << m_database.lastError() << cmd;
res = false;
}
if (res) {
Q_EMIT this->appDBItemDelete(desktopFilePath);
qDebug() << "app database delete " << desktopFilePath << "success!";
query.prepare(cmd);
query.bindValue(":desktopFilePath", desktopFilePath);
if (query.exec()) {
if (this->startCommit()) {
Q_EMIT this->appDBItemDelete(desktopFilePath);
qDebug() << "app database delete " << desktopFilePath << "success!";
} else {
res = false;
}
} else {
qDebug() << "app database delete " << desktopFilePath << "failed!";
qWarning() << query.lastError() << cmd;
m_database.rollback();
res = false;
}
return res;
}
@ -696,15 +756,22 @@ bool AppDBManager::handleDBItemUpdate(const QString &desktopFilePath)
sql.bindValue(":exec", desktopfile.value("Exec").toString());
sql.bindValue(":comment", desktopfile.value("Comment").toString());
if (!sql.exec()) {
qWarning() << m_database.lastError() << sql.lastQuery();
res = false;
if (!this->startTransaction()) {
return false;
}
if (res) {
Q_EMIT this->appDBItemUpdateAll(desktopFilePath);
qDebug() << "app database update all data of" << desktopFilePath << "success!";
if (sql.exec()) {
if (this->startCommit()) {
Q_EMIT this->appDBItemUpdateAll(desktopFilePath);
qDebug() << "app database update all data of" << desktopFilePath << "success!";
} else {
res = false;
}
} else {
qDebug() << "app database update " << desktopFilePath << "failed!";
qWarning() << m_database.lastError() << sql.lastQuery();
m_database.rollback();
res = false;
}
return res;
}
@ -713,145 +780,448 @@ bool AppDBManager::handleLaunchTimesUpdate(const QString &desktopFilePath, int n
{
qDebug() << "launch times will add:" << num;
bool res(true);
QSqlQuery sql(m_database);
sql.setForwardOnly(true);
sql.prepare("SELECT LAUNCH_TIMES FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath");
sql.bindValue(":desktopFilePath", desktopFilePath);
if (sql.exec()) {
if (sql.next()) {
int launchTimes = sql.value(0).toInt() + num;
sql.prepare(QString("UPDATE appInfo SET MODIFYED_TIME='%0', LAUNCH_TIMES=%1, LAUNCHED=%2 WHERE DESKTOP_FILE_PATH=:desktopFilePath")
QSqlQuery query(m_database);
query.setForwardOnly(true);
query.prepare("SELECT LAUNCH_TIMES FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath");
query.bindValue(":desktopFilePath", desktopFilePath);
if (query.exec()) {
if (query.next()) {
int launchTimes = query.value(0).toInt() + num;
if (!this->startTransaction()) {
res = false;
return res;
}
query.prepare(QString("UPDATE appInfo SET MODIFYED_TIME='%0', LAUNCH_TIMES=%1, LAUNCHED=%2 WHERE DESKTOP_FILE_PATH=:desktopFilePath")
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
.arg(launchTimes)
.arg(1));
sql.bindValue(":desktopFilePath", desktopFilePath);
if (!sql.exec()) {
qWarning() << "Set app favorites state failed!" << m_database.lastError();
query.bindValue(":desktopFilePath", desktopFilePath);
if (!query.exec()) {
qWarning() << "Set app launch times failed!" << m_database.lastError();
res = false;
m_database.rollback();
} else {
ApplicationInfoMap appInfo;
appInfo[desktopFilePath].insert(ApplicationProperty::LaunchTimes, QVariant(launchTimes));
appInfo[desktopFilePath].insert(ApplicationProperty::Launched, QVariant(1));
Q_EMIT this->appDBItemUpdate(appInfo);
qDebug() << "app database update " << desktopFilePath << "launch times: " << launchTimes << "success!";
if (this->startCommit()) {
ApplicationInfoMap appInfo;
appInfo[desktopFilePath].insert(ApplicationProperty::LaunchTimes, QVariant(launchTimes));
appInfo[desktopFilePath].insert(ApplicationProperty::Launched, QVariant(1));
Q_EMIT this->appDBItemUpdate(appInfo);
qDebug() << "app database update " << desktopFilePath << "launch times: " << launchTimes << "success!";
} else {
res = false;
}
}
} else {
qWarning() << "Failed to exec next!" << sql.lastQuery();
qWarning() << "Failed to exec next!" << query.lastQuery() << query.lastError();
res = false;
}
} else {
qWarning() << "Failed to exec:" << sql.lastQuery();
qWarning() << "Failed to exec:" << query.lastQuery();
res = false;
}
return res;
}
bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopFilePath, int num, bool isOrderChanged)
bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopFilePath, const uint num)
{
if (num < 0) {
qWarning() << "Invalid favorite num, I quit!!!";
return false;
bool res(true);
QSqlQuery query(m_database);
query.setForwardOnly(true);
QString cmd;
ApplicationInfoMap infos;
//获取应用在数据库中的favorites标志位
int previousPos = -1;
cmd = "SELECT FAVORITES FROM APPINFO WHERE DESKTOP_FILE_PATH =:desktopFilePath";
query.prepare(cmd);
query.bindValue(":desktopFilePath", desktopFilePath);
if (query.exec()) {
if (query.next()) {
previousPos = query.value("FAVORITES").toInt();
} else {
qWarning() << query.lastQuery() << query.lastError();
}
} else {
qWarning() << query.lastQuery() << query.lastError();
}
bool res(true);
QSqlQuery sql(m_database);
sql.setForwardOnly(true);
QString cmd;
//收藏位未改变
if (previousPos == num) {
res = false;
qWarning() << "favorites state has no changes, I quit!";
return res;
}
//当直接设置的时候需要查询要设置的favorites标志位是否被占用
if (!isOrderChanged) {
cmd = QString("SELECT DESKTOP_FILE_PATH, FAVORITES FROM APPINFO WHERE FAVORITES = %1").arg(num);
if (!sql.exec(cmd)) {
qWarning() << "Fail to exec:" << cmd << "because:" << m_database.lastError();
} else {
while (sql.next()) {
if (num && sql.value("FAVORITES").toInt() == num) {
res = false;
if (sql.value("DESKTOP_FILE_PATH").toString() == desktopFilePath) {
qWarning() << "favorites state has no changes, I quit!";
return res;
//查询目前favorites最大值
int maxFavorite = -1;
query.prepare("SELECT max(FAVORITES) as max FROM APPINFO");
if (query.exec()) {
if (query.next()) {
maxFavorite = query.value("max").toInt();
if (maxFavorite + 1 < num) {
qWarning() << QString("Max favorites pos is %0.To be moved to a invalid pos, I quit!!").arg(query.value("max").toInt());
res = false;
}
}
} else {
qWarning() << query.lastError() << query.lastQuery();
res = false;
}
if (!res) {
return res;
}
//取消收藏时,将对应应用前移
if (!num) {
if (previousPos < 1) {
res = false;
}
if (res) {
if (!this->startTransaction()) {
res = false;
return res;
}
cmd = QString("UPDATE APPINFO SET MODIFYED_TIME='%0', FAVORITES=FAVORITES-1 WHERE FAVORITES > %1;")
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
.arg(previousPos);
if (query.exec(cmd)) {
cmd = QString("SELECT DESKTOP_FILE_PATH,FAVORITES FROM APPINFO WHERE FAVORITES >= %0;").arg(previousPos);
if (query.exec(cmd)) {
qDebug() << "Prepare to cancel the favorite state of" << desktopFilePath;
while (query.next()) {
infos[query.value("DESKTOP_FILE_PATH").toString()].insert(ApplicationProperty::Favorites, query.value("FAVORITES"));
}
} else {
qWarning() << query.lastQuery() << query.lastError();
}
} else {
res = false;
qWarning() << query.lastQuery() << query.lastError();
m_database.rollback();
}
}
} else {
//直接设置时(要设置的应用未被收藏查询要设置的favorites标志位是否被占用占用则将该应用及其之后的应用的favorites标志位后移
if (!previousPos) {
cmd = QString("SELECT DESKTOP_FILE_PATH FROM APPINFO WHERE FAVORITES = %1").arg(num);
if (!query.exec(cmd)) {
qWarning() << "Fail to exec:" << cmd << "because:" << query.lastError();
res = false;
} else {
if (!this->startTransaction()) {
return false;
}
if (query.next()) {
//默认收藏后顶到第一个,其余后移,若想直接收藏到对应位置则将该位置后的收藏应用后移
query.prepare(QString("UPDATE APPINFO SET MODIFYED_TIME='%0', FAVORITES=FAVORITES+1 WHERE FAVORITES >= %1;")
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
.arg(num));
if (!query.exec()) {
res = false;
qWarning() << query.lastError() << query.lastQuery();
m_database.rollback();
} else {
qWarning() << "the favorites num:" << num << "has been used, fail to update favorites state of" << desktopFilePath;
return res;
cmd = QString("SELECT DESKTOP_FILE_PATH, FAVORITES FROM APPINFO WHERE FAVORITES >= %1").arg(num);
if (!query.exec(cmd)) {
qWarning() << query.lastError() << query.lastQuery();
res = false;
} else {
while (query.next()) {
infos[query.value("DESKTOP_FILE_PATH").toString()].insert(ApplicationProperty::Favorites, query.value("FAVORITES"));
}
}
}
}
}
} else {
//触发修改位置逻辑
res = maxFavorite < num? false : this->handleChangeFavoritesPos(desktopFilePath, num, previousPos, infos);
qDebug() << "change favorites pos:" << res;
}
}
//移动位置执行不成功则不去更新对应应用的favorites标志位
if (!res) {
return res;
}
//更新favorites状态
cmd = QString("UPDATE APPINFO SET MODIFYED_TIME='%0', FAVORITES=%1 WHERE DESKTOP_FILE_PATH=:desktopFilePath")
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
.arg(num);
sql.prepare(cmd);
sql.bindValue(":desktopFilePath", desktopFilePath);
if (!sql.exec()) {
query.prepare(cmd);
query.bindValue(":desktopFilePath", desktopFilePath);
if (!query.exec()) {
qWarning() << "Set app favorites state failed!" << m_database.lastError();
res = false;
m_database.rollback();
} else {
ApplicationInfoMap appInfo;
appInfo[desktopFilePath].insert(ApplicationProperty::Favorites, QVariant(num));
Q_EMIT this->appDBItemUpdate(appInfo);
qDebug() << "app database update " << desktopFilePath << "favorites state: " << num << "success!";
if (this->startCommit()) {
infos[desktopFilePath].insert(ApplicationProperty::Favorites, QVariant(num));
Q_EMIT this->appDBItemUpdate(infos);
qDebug() << "app database update " << desktopFilePath << "favorites state: " << num << "success!";
} else {
res = false;
}
}
return res;
}
bool AppDBManager::handleTopStateUpdate(const QString &desktopFilePath, int num, bool isOrderChanged)
bool AppDBManager::handleChangeFavoritesPos(const QString &desktopFilePath, const uint pos, const int previousPos, ApplicationInfoMap updatedInfo)
{
if (num < 0) {
qWarning() << "Invalid top num, I quit!!!";
if (pos < 1) {
qWarning() << "To be moved to a invalid favorites pos , I quit!!";
return false;
}
if (previousPos < 1) {
qWarning() << QString("app: %1 is not a favorites app, I quit!!").arg(desktopFilePath);
return false;
}
bool res(true);
QSqlQuery sql(m_database);
sql.setForwardOnly(true);
QSqlQuery query(m_database);
query.setForwardOnly(true);
//当直接设置的时候需要查询要设置的top标志位是否被占用
QString condition;
if (previousPos > pos) {
condition = "FAVORITES=FAVORITES+1";
} else {
condition = "FAVORITES=FAVORITES-1";
}
query.prepare(QString("UPDATE APPINFO SET %0 WHERE FAVORITES BETWEEN MIN(%1, %2) AND MAX(%1, %2)")
.arg(condition)
.arg(previousPos)
.arg(pos));
if (!this->startTransaction()) {
return false;
}
//更新原位置和新位置之间的应用的位置
if (query.exec()) {
query.prepare(QString("SELECT DESKTOP_FILE_PATH,FAVORITES FROM APPINFO WHERE FAVORITES BETWEEN MIN(%1, %2) AND MAX(%1, %2)")
.arg(previousPos)
.arg(pos));
if (query.exec()) {
while (query.next()) {
updatedInfo[query.value("DESKTOP_FILE_PATH").toString()].insert(ApplicationProperty::Favorites, query.value("FAVORITES"));
}
}
} else {
res = false;
qWarning() << "Fail to change favorite-app pos, because: " << query.lastError() << " when exec :" << query.lastQuery();
m_database.rollback();
}
return res;
}
bool AppDBManager::handleTopStateUpdate(const QString &desktopFilePath, const uint num)
{
bool res(true);
QSqlQuery query(m_database);
query.setForwardOnly(true);
QString cmd;
if (!isOrderChanged) {
cmd = QString("SELECT DESKTOP_FILE_PATH, TOP FROM APPINFO WHERE TOP = %1").arg(num);
if (!sql.exec(cmd)) {
qWarning() << "Fail to exec:" << cmd << "because:" << m_database.lastError();
ApplicationInfoMap infos;
//获取应用在数据库中的top标志位
int previousPos = -1;
cmd = "SELECT TOP FROM APPINFO WHERE DESKTOP_FILE_PATH =:desktopFilePath";
query.prepare(cmd);
query.bindValue(":desktopFilePath", desktopFilePath);
if (query.exec()) {
if (query.next()) {
previousPos = query.value("TOP").toInt();
} else {
while (sql.next()) {
if (num && sql.value("TOP").toInt() == num) {
res = false;
if (sql.value("DESKTOP_FILE_PATH").toString() == desktopFilePath) {
qWarning() << "top state has no changes, I quit!";
return res;
qWarning() << query.lastQuery() << query.lastError();
}
} else {
qWarning() << query.lastQuery() << query.lastError();
}
//top位未改变
if (previousPos == num) {
res = false;
qWarning() << "Top state has no changes, I quit!";
return res;
}
//查询目前top最大值
int maxTop = -1;
query.prepare("SELECT max(TOP) as max FROM APPINFO");
if (query.exec()) {
if (query.next()) {
maxTop = query.value("max").toInt();
if (maxTop + 1 < num) {
qWarning() << QString("Max top pos is %0.To be moved to a invalid pos, I quit!!").arg(query.value("max").toInt());
res = false;
}
} else {
res = false;
}
} else {
qWarning() << query.lastError() << query.lastQuery();
res = false;
}
if (!res) {
return res;
}
//取消置顶时,将对应应用前移
if (!num) {
if (previousPos < 1) {
res = false;
}
if (res) {
if (!this->startTransaction()) {
res = false;
return res;
}
cmd = QString("UPDATE APPINFO SET MODIFYED_TIME='%0', TOP=TOP-1 WHERE TOP > %1;")
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
.arg(previousPos);
if (query.exec(cmd)) {
cmd = QString("SELECT DESKTOP_FILE_PATH,TOP FROM APPINFO WHERE TOP >= %0;").arg(previousPos);
if (query.exec(cmd)) {
qDebug() << "Prepare to cancel the top state of" << desktopFilePath;
while (query.next()) {
infos[query.value("DESKTOP_FILE_PATH").toString()].insert(ApplicationProperty::Top, query.value("TOP"));
}
} else {
qWarning() << query.lastQuery() << query.lastError();
}
} else {
res = false;
qWarning() << query.lastQuery() << query.lastError();
m_database.rollback();
}
}
} else {
//直接设置时查询要设置的top标志位是否被占用占用则将该应用及其之后的应用的top标志位后移
if (!previousPos) {
cmd = QString("SELECT DESKTOP_FILE_PATH FROM APPINFO WHERE TOP = %1").arg(num);
if (!query.exec(cmd)) {
qWarning() << "Fail to exec:" << cmd << "because:" << query.lastError();
} else {
if (!this->startTransaction()) {
return false;
}
if (query.next()) {
//默认置顶后顶到第一个,其余后移,若想直接置顶到对应位置则将该位置后的置顶应用后移
query.prepare(QString("UPDATE APPINFO SET MODIFYED_TIME='%0', TOP=TOP+1 WHERE TOP >= %1;")
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
.arg(num));
if (!query.exec()) {
qWarning() << query.lastError() << query.lastQuery();
res = false;
m_database.rollback();
} else {
qWarning() << "the top num:" << num << "has been used, fail to update top state of" << desktopFilePath;
return res;
cmd = QString("SELECT DESKTOP_FILE_PATH, TOP FROM APPINFO WHERE TOP >= %1").arg(num);
if (!query.exec(cmd)) {
qWarning() << query.lastError() << query.lastQuery();
res = false;
} else {
while (query.next()) {
infos[query.value("DESKTOP_FILE_PATH").toString()].insert(ApplicationProperty::Top, query.value("TOP"));
}
}
}
}
}
} else {
//触发修改位置逻辑
res = maxTop < num ? false : this->handleChangeTopPos(desktopFilePath, num, previousPos, infos);
qDebug() << "Change top pos:" << res;
}
}
//移动位置执行不成功则不去更新对应应用的top标志位
if (!res) {
return res;
}
//更新top状态
cmd = QString("UPDATE APPINFO SET MODIFYED_TIME='%0', TOP=%1 WHERE DESKTOP_FILE_PATH=:desktopFilePath")
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
.arg(num);
sql.prepare(cmd);
sql.bindValue(":desktopFilePath", desktopFilePath);
if (!sql.exec()) {
qWarning() << "Set app favorites state failed!" << m_database.lastError();
query.prepare(cmd);
query.bindValue(":desktopFilePath", desktopFilePath);
if (!query.exec()) {
qWarning() << "Set app top state failed!" << query.lastError();
res = false;
m_database.rollback();
} else {
ApplicationInfoMap appInfo;
appInfo[desktopFilePath].insert(ApplicationProperty::Top, QVariant(num));
Q_EMIT this->appDBItemUpdate(appInfo);
qDebug() << "app database update " << desktopFilePath << "top state: " << num << "success!";
if (this->startCommit()) {
infos[desktopFilePath].insert(ApplicationProperty::Top, QVariant(num));
Q_EMIT this->appDBItemUpdate(infos);
qDebug() << "app database update " << desktopFilePath << "top state: " << num << "success!";
} else {
res = false;
}
}
return res;
}
bool AppDBManager::handleChangeTopPos(const QString &desktopFilePath, uint pos, const int previousPos, ApplicationInfoMap updatedInfo)
{
if (pos < 1) {
qWarning() << "To be moved to a invalid top pos , I quit!!";
return false;
}
if (previousPos < 1) {
qWarning() << QString("app: %1 is not a top app, I quit!!").arg(desktopFilePath);
return false;
}
bool res(true);
QSqlQuery query(m_database);
query.setForwardOnly(true);
QString condition;
if (previousPos > pos) {
condition = "TOP=TOP+1";
} else {
condition = "TOP=TOP-1";
}
query.prepare(QString("UPDATE APPINFO SET %0 WHERE TOP BETWEEN MIN(%1, %2) AND MAX(%1, %2)")
.arg(condition)
.arg(previousPos)
.arg(pos));
if (!this->startTransaction()) {
res = false;
return res;
}
//更新原位置和新位置之间的应用的位置
if (query.exec()) {
query.prepare(QString("SELECT DESKTOP_FILE_PATH,TOP FROM APPINFO WHERE TOP BETWEEN MIN(%1, %2) AND MAX(%1, %2)")
.arg(previousPos)
.arg(pos));
if (query.exec()) {
while (query.next()) {
updatedInfo[query.value("DESKTOP_FILE_PATH").toString()].insert(ApplicationProperty::Top, query.value("TOP"));
}
}
} else {
qWarning() << "Fail to change favorite-app pos, because: " << query.lastError() << " when exec :" << query.lastQuery();
res = false;
m_database.rollback();
}
return res;
}
bool AppDBManager::handleLockStateUpdate(const QString &desktopFilePath, int num)
{
if (!this->startTransaction()) {
return false;
}
bool res(true);
QSqlQuery sql(m_database);
sql.prepare(QString("UPDATE appInfo SET MODIFYED_TIME='%0', LOCK=%1 WHERE DESKTOP_FILE_PATH=:desktopFilePath")
@ -859,13 +1229,18 @@ bool AppDBManager::handleLockStateUpdate(const QString &desktopFilePath, int num
.arg(num));
sql.bindValue(":desktopFilePath", desktopFilePath);
if (!sql.exec()) {
qWarning() << "Set app favorites state failed!" << m_database.lastError();
qWarning() << "Set app lock state failed!" << m_database.lastError();
res = false;
m_database.rollback();
} else {
ApplicationInfoMap appInfo;
appInfo[desktopFilePath].insert(ApplicationProperty::Lock, QVariant(num));
Q_EMIT this->appDBItemUpdate(appInfo);
qDebug() << "app database update " << desktopFilePath << "lock state: " << num << "success!";
if (this->startCommit()) {
ApplicationInfoMap appInfo;
appInfo[desktopFilePath].insert(ApplicationProperty::Lock, QVariant(num));
Q_EMIT this->appDBItemUpdate(appInfo);
qDebug() << "app database update " << desktopFilePath << "lock state: " << num << "success!";
} else {
res = false;
}
}
return res;
}
@ -1048,19 +1423,17 @@ void AppDBManager::updateLaunchTimes(const QString &desktopFilePath)
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
}
void AppDBManager::updateFavoritesState(const QString &desktopFilePath, int num, bool isOrderChanged)
void AppDBManager::updateFavoritesState(const QString &desktopFilePath, uint num)
{
PendingAppInfo item(desktopFilePath, PendingAppInfo::HandleType::UpdateFavorites);
item.setFavorites(num);
item.setChangeFavoritePos(isOrderChanged);
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
}
void AppDBManager::updateTopState(const QString &desktopFilePath, int num, bool isOrderChanged)
void AppDBManager::updateTopState(const QString &desktopFilePath, uint num)
{
PendingAppInfo item(desktopFilePath, PendingAppInfo::HandleType::UpdateTop);
item.setTop(num);
item.setChangeTopPos(isOrderChanged);
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
}
@ -1070,129 +1443,3 @@ void AppDBManager::udpateLockState(const QString &desktopFilePath, int num)
item.setLock(num);
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
}
bool AppDBManager::changeFavoriteAppPos(const QString &desktopFilePath, int pos)
{
if (pos < 1) {
qWarning() << "To be moved to a invalid favorites pos , I quit!!";
return false;
}
bool res(true);
QSqlQuery sql(m_database);
sql.setForwardOnly(true);
QString cmd = "SELECT FAVORITES FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath";
sql.prepare(cmd);
sql.bindValue(":desktopFilePath", desktopFilePath);
int previousPos = 0;
//记录应用原位置
if (!sql.exec()) {
qWarning() << "Fail to change favorite-app pos, because: " << m_database.lastError() << " when exec :" << cmd;
res = false;
} else {
if (sql.next()) {
previousPos = sql.value(0).toInt();
if (previousPos < 1) {
qWarning() << QString("app: %1 is not a favorites app, I quit!!").arg(desktopFilePath);
}
if (previousPos == pos) {
qDebug() << "favorite app's pos has no changes!";
return res;
}
cmd = QString("SELECT DESKTOP_FILE_PATH, FAVORITES FROM APPINFO WHERE FAVORITES BETWEEN MIN(%1, %2) AND MAX(%1, %2)")
.arg(previousPos)
.arg(pos);
} else {
qWarning() << "Fail to change favorite-app pos when exec next, because: " << m_database.lastError();
}
}
//更新原位置和新位置之间的应用的位置
if (!sql.exec(cmd)) {
qWarning() << "Fail to change favorite-app pos, because: " << m_database.lastError() << " when exec :" << cmd;
res = false;
} else {
while (sql.next()) {
if (sql.value("FAVORITES").toInt() == previousPos) {
this->updateFavoritesState(desktopFilePath, pos, true);
continue;
}
if (previousPos > pos) {
this->updateFavoritesState(sql.value("DESKTOP_FILE_PATH").toString(), sql.value("FAVORITES").toInt() + 1, true);
} else {
this->updateFavoritesState(sql.value("DESKTOP_FILE_PATH").toString(), sql.value("FAVORITES").toInt() - 1, true);
}
}
}
return res;
}
bool AppDBManager::changeTopAppPos(const QString &desktopFilePath, int pos)
{
if (pos < 1) {
qWarning() << "To be moved to a invalid top pos, I quit!!";
return false;
}
bool res(true);
QSqlQuery sql(m_database);
QString cmd = "SELECT TOP FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath";
sql.prepare(cmd);
sql.bindValue(":desktopFilePath", desktopFilePath);
int previousPos = 0;
//记录应用原位置
if (!sql.exec()) {
qWarning() << "Fail to change top-app pos, because: " << m_database.lastError() << " when exec :" << cmd;
res = false;
} else {
if (sql.next()) {
previousPos = sql.value(0).toInt();
if (previousPos < 1) {
qWarning() << QString("app: %1 is not a favorites app, I quit!!").arg(desktopFilePath);
res = false;
return res;
}
if (previousPos == pos) {
qDebug() << "top app's pos has no changes!";
res = false;
return res;
}
cmd = QString("SELECT DESKTOP_FILE_PATH, TOP FROM APPINFO WHERE TOP BETWEEN MIN(%1, %2) AND MAX(%1, %2)")
.arg(previousPos)
.arg(pos);
} else {
qWarning() << "Fail to change top-app pos when exec next, because: " << m_database.lastError();
}
}
//更新原位置和新位置之间的应用的位置
if (!sql.exec(cmd)) {
qWarning() << "Fail to change top-app pos, because: " << m_database.lastError() << " when exec :" << cmd;
res = false;
} else {
while (sql.next()) {
if (sql.value("TOP").toInt() == previousPos) {
this->updateTopState(desktopFilePath, pos, true);
continue;
}
if (previousPos > pos) {
this->updateTopState(sql.value("DESKTOP_FILE_PATH").toString(), sql.value("TOP").toInt() + 1, true);
} else {
this->updateTopState(sql.value("DESKTOP_FILE_PATH").toString(), sql.value("TOP").toInt() - 1, true);
}
}
}
return res;
}

View File

@ -55,9 +55,9 @@ public:
bool handleDBItemDelete(const QString &desktopFilePath);
bool handleLocaleDataUpdate(const QString &desktopFilePath);
bool handleLaunchTimesUpdate(const QString &desktopFilePath, int num);
bool handleFavoritesStateUpdate(const QString &desktopFilePath, int num, bool isOrderChanged = false);
bool handleTopStateUpdate(const QString &desktopFilePath, int num, bool isOrderChanged = false);
bool handleLaunchTimesUpdate(const QString &desktopFilePath, int num = 1);
bool handleFavoritesStateUpdate(const QString &desktopFilePath, const uint num);
bool handleTopStateUpdate(const QString &desktopFilePath, const uint num);
bool handleLockStateUpdate(const QString &desktopFilePath, int num);
void handleDataBaseRefresh(const QStringList &appPaths, bool dbVersionNeedUpdate);
@ -73,14 +73,10 @@ public Q_SLOTS:
//对数据库某字段进行update
void updateLocaleData(const QString &desktopFilePath);
void updateLaunchTimes(const QString &desktopFilePath);
void updateFavoritesState(const QString &desktopFilePath, int num, bool isOrderChanged = false);
void updateTopState(const QString &desktopFilePath, int num, bool isOrderChanged = false);
void updateFavoritesState(const QString &desktopFilePath, uint num = 1);
void updateTopState(const QString &desktopFilePath, uint num = 1);
void udpateLockState(const QString &desktopFilePath, int num);
//拖动改变置顶和收藏应用位置
bool changeFavoriteAppPos(const QString &desktopFilePath, int pos);
bool changeTopAppPos(const QString &desktopFilePath, int pos);
protected:
void run() override;
@ -107,6 +103,10 @@ private:
//初始化fileSystemWatcher
void initFileSystemWatcher();
//处理置顶收藏移动位置
bool handleChangeFavoritesPos(const QString &desktopFilePath, const uint pos, const int previousPos, ApplicationInfoMap updatedInfo);
bool handleChangeTopPos(const QString &desktopFilePath, uint pos, const int previousPos, ApplicationInfoMap updatedInfo);
private:
static QMutex s_mutex;
bool m_localeChanged;

View File

@ -128,60 +128,55 @@ void PendingAppInfoQueue::processCache()
return;
}
if (AppDBManager::getInstance()->startTransaction()) {
for (const PendingAppInfo &info : m_pendingAppInfos) {
PendingAppInfo::HandleTypes handleTypes = info.handleType();
if (handleTypes <= PendingAppInfo::UpdateLocaleData || handleTypes == PendingAppInfo::RefreshDataBase) {
switch (handleTypes) {
case PendingAppInfo::Delete:
AppDBManager::getInstance()->handleDBItemDelete(info.path());
break;
case PendingAppInfo::Insert:
AppDBManager::getInstance()->handleDBItemInsert(info.path());
break;
case PendingAppInfo::UpdateAll:
AppDBManager::getInstance()->handleDBItemUpdate(info.path());
break;
case PendingAppInfo::UpdateLocaleData:
AppDBManager::getInstance()->handleLocaleDataUpdate(info.path());
break;
case PendingAppInfo::RefreshDataBase:
AppDBManager::getInstance()->handleDataBaseRefresh(info.pathsNeedRefreshData(), info.dbVersionNeedUpdate());
break;
default:
break;
}
} else {
if (handleTypes & PendingAppInfo::Insert) {
AppDBManager::getInstance()->handleDBItemInsert(info.path());
}
if (handleTypes & PendingAppInfo::UpdateAll) {
AppDBManager::getInstance()->handleDBItemUpdate(info.path());
}
if (handleTypes & PendingAppInfo::UpdateLocaleData) {
AppDBManager::getInstance()->handleLocaleDataUpdate(info.path());
}
if (handleTypes & PendingAppInfo::UpdateLaunchTimes) {
AppDBManager::getInstance()->handleLaunchTimesUpdate(info.path(), info.launchTimes());
}
if (handleTypes & PendingAppInfo::UpdateFavorites) {
AppDBManager::getInstance()->handleFavoritesStateUpdate(info.path(), info.favoritesState(), info.isFavoritePosChanged());
}
if (handleTypes & PendingAppInfo::UpdateTop) {
AppDBManager::getInstance()->handleTopStateUpdate(info.path(), info.topState(), info.isTopPosChanged());
}
if (handleTypes & PendingAppInfo::UpdateLock) {
AppDBManager::getInstance()->handleLockStateUpdate(info.path(), info.lockState());
}
for (const PendingAppInfo &info : m_pendingAppInfos) {
PendingAppInfo::HandleTypes handleTypes = info.handleType();
if (handleTypes <= PendingAppInfo::UpdateLocaleData || handleTypes == PendingAppInfo::RefreshDataBase) {
switch (handleTypes) {
case PendingAppInfo::Delete:
AppDBManager::getInstance()->handleDBItemDelete(info.path());
break;
case PendingAppInfo::Insert:
AppDBManager::getInstance()->handleDBItemInsert(info.path());
break;
case PendingAppInfo::UpdateAll:
AppDBManager::getInstance()->handleDBItemUpdate(info.path());
break;
case PendingAppInfo::UpdateLocaleData:
AppDBManager::getInstance()->handleLocaleDataUpdate(info.path());
break;
case PendingAppInfo::RefreshDataBase:
AppDBManager::getInstance()->handleDataBaseRefresh(info.pathsNeedRefreshData(), info.dbVersionNeedUpdate());
break;
default:
break;
}
} else {
if (handleTypes & PendingAppInfo::Insert) {
AppDBManager::getInstance()->handleDBItemInsert(info.path());
}
if (handleTypes & PendingAppInfo::UpdateAll) {
AppDBManager::getInstance()->handleDBItemUpdate(info.path());
}
if (handleTypes & PendingAppInfo::UpdateLocaleData) {
AppDBManager::getInstance()->handleLocaleDataUpdate(info.path());
}
if (handleTypes & PendingAppInfo::UpdateLaunchTimes) {
AppDBManager::getInstance()->handleLaunchTimesUpdate(info.path(), info.launchTimes());
}
if (handleTypes & PendingAppInfo::UpdateFavorites) {
AppDBManager::getInstance()->handleFavoritesStateUpdate(info.path(), info.favoritesState());
}
if (handleTypes & PendingAppInfo::UpdateTop) {
AppDBManager::getInstance()->handleTopStateUpdate(info.path(), info.topState());
}
if (handleTypes & PendingAppInfo::UpdateLock) {
AppDBManager::getInstance()->handleLockStateUpdate(info.path(), info.lockState());
}
}
if (AppDBManager::getInstance()->startCommit()) {
Q_EMIT AppDBManager::getInstance()->finishHandleAppDB();
}
m_pendingAppInfos.clear();
m_pendingAppInfos.squeeze();
}
Q_EMIT AppDBManager::getInstance()->finishHandleAppDB();
m_pendingAppInfos.clear();
m_pendingAppInfos.squeeze();
}

View File

@ -26,17 +26,14 @@ public:
PendingAppInfo() = default;
PendingAppInfo(QString desktopfp, HandleTypes type,
int favorites = -1, int top = -1, int lock = -1,
bool addLaunch = false, int launchTimes = 0,
bool isChangeFavorite = false, bool isChangeTopPos = false)
bool addLaunch = false, int launchTimes = 0)
: m_desktopfp(desktopfp),
m_handleType(type),
m_favoritesState(favorites),
m_topState(top),
m_lockState(lock),
m_willAddLaunch(addLaunch),
m_launchTimes(launchTimes),
m_isFavoritePosChanged(isChangeFavorite),
m_isTopPosChanged(isChangeTopPos) {}
m_launchTimes(launchTimes) {}
QString path() const {return m_desktopfp;}
QStringList pathsNeedRefreshData() const {return m_pathsNeedRefreshData;}
@ -46,8 +43,6 @@ public:
int lockState() const {return m_lockState;}
int launchTimes() const {return m_launchTimes;}
bool willAddLunchTimes() const {return m_willAddLaunch;}
bool isFavoritePosChanged() const {return m_isFavoritePosChanged;}
bool isTopPosChanged() const {return m_isTopPosChanged;}
bool dbVersionNeedUpdate() const {return m_dbVersionNeedUpdate;}
void setDesktopFp(const QString& desktopfp) {m_desktopfp = desktopfp;}
@ -58,8 +53,6 @@ public:
void setLock(int lock) {m_lockState = lock;}
void setLaunchWillAdd(bool willAdd) {m_willAddLaunch = willAdd;}
void setLaunchTimes(int times) {m_launchTimes = times;}
void setChangeFavoritePos(bool isOrderChanged) {m_isFavoritePosChanged = isOrderChanged;}
void setChangeTopPos(bool isOrderChanged) {m_isTopPosChanged = isOrderChanged;}
void setPathsNeedRefreshData (const QStringList& paths) {m_pathsNeedRefreshData = paths;}
void setDBUpdate(bool versionNeedUpdate) {m_dbVersionNeedUpdate = versionNeedUpdate;}
void merge(const PendingAppInfo& info)
@ -93,8 +86,6 @@ private:
int m_lockState = -1;
bool m_willAddLaunch = false;
int m_launchTimes = 0;
bool m_isFavoritePosChanged = false;
bool m_isTopPosChanged = false;
QStringList m_pathsNeedRefreshData;
bool m_dbVersionNeedUpdate = false;
};