Fix the problem that the changePos interface cannot change top&favorites pos successful.

This commit is contained in:
JunjieBai 2023-02-15 17:17:11 +08:00
parent 7f2267d72a
commit 68a1fc4f43
4 changed files with 74 additions and 53 deletions

View File

@ -875,7 +875,7 @@ bool AppDBManager::handleLaunchTimesUpdate(const QString &desktopfp, int num)
return res;
}
bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopfp, int num)
bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopfp, int num, bool isOrderChanged)
{
if (num < 0) {
qWarning() << "Invalid favorite num, I quit!!!";
@ -884,26 +884,30 @@ bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopfp, int num)
bool res(true);
QSqlQuery sql(m_database);
QString cmd;
//查询要设置的favorites标志位是否被占用
QString 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() == desktopfp) {
qWarning() << "favorites state has no changes, I quit!";
return res;
} else {
qWarning() << "the favorites num:" << num << "has been used, fail to update favorites state of" << desktopfp;
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() == desktopfp) {
qWarning() << "favorites state has no changes, I quit!";
return res;
} else {
qWarning() << "the favorites num:" << num << "has been used, fail to update favorites state of" << desktopfp;
return res;
}
}
}
}
}
//更新favorites状态
cmd = QString("UPDATE APPINFO SET MODIFYED_TIME='%0', FAVORITES=%1 WHERE DESKTOP_FILE_PATH='%2'")
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
@ -922,7 +926,7 @@ bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopfp, int num)
return res;
}
bool AppDBManager::handleTopStateUpdate(const QString &desktopfp, int num)
bool AppDBManager::handleTopStateUpdate(const QString &desktopfp, int num, bool isOrderChanged)
{
if (num < 0) {
qWarning() << "Invalid top num, I quit!!!";
@ -932,20 +936,23 @@ bool AppDBManager::handleTopStateUpdate(const QString &desktopfp, int num)
bool res(true);
QSqlQuery sql(m_database);
//查询要设置的top标志位是否被占用
QString 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();
} else {
while (sql.next()) {
if (num && sql.value("TOP").toInt() == num) {
res = false;
if (sql.value("DESKTOP_FILE_PATH").toString() == desktopfp) {
qWarning() << "top state has no changes, I quit!";
return res;
} else {
qWarning() << "the top num:" << num << "has been used, fail to update top state of" << desktopfp;
return res;
//当直接设置的时候需要查询要设置的top标志位是否被占用
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();
} else {
while (sql.next()) {
if (num && sql.value("TOP").toInt() == num) {
res = false;
if (sql.value("DESKTOP_FILE_PATH").toString() == desktopfp) {
qWarning() << "top state has no changes, I quit!";
return res;
} else {
qWarning() << "the top num:" << num << "has been used, fail to update top state of" << desktopfp;
return res;
}
}
}
}
@ -1050,17 +1057,19 @@ void AppDBManager::updateLaunchTimes(const QString &desktopfp)
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
}
void AppDBManager::updateFavoritesState(const QString &desktopfp, int num)
void AppDBManager::updateFavoritesState(const QString &desktopfp, int num, bool isOrderChanged)
{
PendingAppInfo item(desktopfp, PendingAppInfo::HandleType::UpdateFavorites);
item.setFavorites(num);
item.setChangeFavoritePos(isOrderChanged);
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
}
void AppDBManager::updateTopState(const QString &desktopfp, int num)
void AppDBManager::updateTopState(const QString &desktopfp, int num, bool isOrderChanged)
{
PendingAppInfo item(desktopfp, PendingAppInfo::HandleType::UpdateTop);
item.setTop(num);
item.setChangeTopPos(isOrderChanged);
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
}
@ -1115,13 +1124,13 @@ bool AppDBManager::changeFavoriteAppPos(const QString &desktopfp, int pos)
} else {
while (sql.next()) {
if (sql.value("FAVORITES").toInt() == previousPos) {
this->updateFavoritesState(desktopfp, pos);
this->updateFavoritesState(desktopfp, pos, true);
continue;
}
if (previousPos > pos) {
this->updateFavoritesState(sql.value("DESKTOP_FILE_PATH").toString(), sql.value("FAVORITES").toInt() + 1);
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);
this->updateFavoritesState(sql.value("DESKTOP_FILE_PATH").toString(), sql.value("FAVORITES").toInt() - 1, true);
}
}
@ -1177,13 +1186,13 @@ bool AppDBManager::changeTopAppPos(const QString &desktopfp, int pos)
} else {
while (sql.next()) {
if (sql.value("TOP").toInt() == previousPos) {
this->updateTopState(desktopfp, pos);
this->updateTopState(desktopfp, pos, true);
continue;
}
if (previousPos > pos) {
this->updateTopState(sql.value("DESKTOP_FILE_PATH").toString(), sql.value("TOP").toInt() + 1);
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);
this->updateTopState(sql.value("DESKTOP_FILE_PATH").toString(), sql.value("TOP").toInt() - 1, true);
}
}

View File

@ -70,8 +70,8 @@ public:
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 handleFavoritesStateUpdate(const QString &desktopfp, int num, bool isOrderChanged = false);
bool handleTopStateUpdate(const QString &desktopfp, int num, bool isOrderChanged = false);
bool handleLockStateUpdate(const QString &desktopfp, int num);
bool createAppInfoResult(const QString &desktopfp, AppInfoResult &result);
@ -84,8 +84,8 @@ public Q_SLOTS:
//对数据库某字段进行update
void updateLocaleData(const QString &desktopfp);
void updateLaunchTimes(const QString &desktopfp);
void updateFavoritesState(const QString &desktopfp, int num);
void updateTopState(const QString &desktopfp, int num);
void updateFavoritesState(const QString &desktopfp, int num, bool isOrderChanged = false);
void updateTopState(const QString &desktopfp, int num, bool isOrderChanged = false);
void udpateLockState(const QString &desktopfp, int num);
//拖动改变置顶和收藏应用位置

View File

@ -158,10 +158,10 @@ void PendingAppInfoQueue::processCache()
AppDBManager::getInstance()->handleLaunchTimesUpdate(info.path(), info.launchTimes());
}
if (handleTypes & PendingAppInfo::UpdateFavorites) {
AppDBManager::getInstance()->handleFavoritesStateUpdate(info.path(), info.favoritesState());
AppDBManager::getInstance()->handleFavoritesStateUpdate(info.path(), info.favoritesState(), info.isFavoritePosChanged());
}
if (handleTypes & PendingAppInfo::UpdateTop) {
AppDBManager::getInstance()->handleTopStateUpdate(info.path(), info.topState());
AppDBManager::getInstance()->handleTopStateUpdate(info.path(), info.topState(), info.isTopPosChanged());
}
if (handleTypes & PendingAppInfo::UpdateLock) {
AppDBManager::getInstance()->handleLockStateUpdate(info.path(), info.lockState());

View File

@ -22,14 +22,19 @@ public:
Q_DECLARE_FLAGS(HandleTypes, HandleType)
PendingAppInfo() = default;
PendingAppInfo(QString desktopfp, HandleTypes type, int favorites = -1, int top = -1, int lock = -1, bool addLaunch = false, int launchTimes = 0)
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)
: m_desktopfp(desktopfp),
m_handleType(type),
m_favoritesState(favorites),
m_topState(top),
m_lockState(lock),
m_willAddLaunch(addLaunch),
m_launchTimes(launchTimes) {}
m_launchTimes(launchTimes),
m_isFavoritePosChanged(isChangeFavorite),
m_isTopPosChanged(isChangeTopPos) {}
QString path() const {return m_desktopfp;}
HandleTypes handleType() const {return m_handleType;}
@ -38,15 +43,20 @@ 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;}
void setHandleType(const PendingAppInfo & info) {m_handleType = info.handleType();}
void setDesktopFp(const QString& desktopfp) {m_desktopfp = desktopfp;}
void setHandleType(const PendingAppInfo& info) {m_handleType = info.handleType();}
void setHandleType(HandleTypes type) {m_handleType = type;}
void setFavorites(int favoritesState) {m_favoritesState = favoritesState;}
void setTop(int top) {m_topState = top;}
void setLock(int lock) {m_lockState = lock;}
void setLaunchWillAdd(bool willAdd) {m_willAddLaunch = willAdd;}
void setLaunchTimes(int times) {m_launchTimes = times;}
void merge(const PendingAppInfo &info)
void setChangeFavoritePos(bool isOrderChanged) {m_isFavoritePosChanged = isOrderChanged;}
void setChangeTopPos(bool isOrderChanged) {m_isTopPosChanged = isOrderChanged;}
void merge(const PendingAppInfo& info)
{
m_handleType |= info.handleType();
@ -72,11 +82,13 @@ public:
private:
QString m_desktopfp;
HandleTypes m_handleType;
int m_favoritesState;
int m_topState;
int m_lockState;
bool m_willAddLaunch;
int m_launchTimes;
int m_favoritesState = -1;
int m_topState = -1;
int m_lockState = -1;
bool m_willAddLaunch = false;
int m_launchTimes = 0;
bool m_isFavoritePosChanged = false;
bool m_isTopPosChanged = false;
};
}