forked from openkylin/ukui-search
Optimize the logic which change position and set state of favorites/top.
Optimize the logic of the database transaction.
This commit is contained in:
parent
366201ddf9
commit
e09044dfee
|
@ -18,12 +18,10 @@ public:
|
||||||
AppInfoTablePrivate &operator =(const AppInfoTablePrivate &) = delete;
|
AppInfoTablePrivate &operator =(const AppInfoTablePrivate &) = delete;
|
||||||
|
|
||||||
//设置应用的置顶和收藏
|
//设置应用的置顶和收藏
|
||||||
void setAppFavoritesState(const QString &desktopfp, int num);
|
void setAppFavoritesState(const QString &desktopfp);
|
||||||
void setAppTopState(const QString &desktopfp, int num);
|
void setAppFavoritesState(const QString &desktopfp, uint num);
|
||||||
|
void setAppTopState(const QString &desktopfp);
|
||||||
//改变置顶和收藏应用位置
|
void setAppTopState(const QString &desktopfp, uint num);
|
||||||
bool changeFavoriteAppPos(const QString &desktopfp, int pos);
|
|
||||||
bool changeTopAppPos(const QString &desktopfp, int pos);
|
|
||||||
|
|
||||||
//搜索接口
|
//搜索接口
|
||||||
bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes);
|
bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes);
|
||||||
|
|
|
@ -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);
|
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);
|
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 AppInfoTablePrivate::searchInstallApp(QString &keyWord, QStringList &installAppInfoRes)
|
||||||
{
|
{
|
||||||
bool res(true);
|
bool res(true);
|
||||||
|
@ -519,6 +507,11 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, ApplicationProperties prop
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppInfoTable::setAppFavoritesState(const QString &desktopfp)
|
||||||
|
{
|
||||||
|
return d->setAppFavoritesState(desktopfp);
|
||||||
|
}
|
||||||
|
|
||||||
void AppInfoTable::setAppFavoritesState(const QString &desktopfp, size_t num)
|
void AppInfoTable::setAppFavoritesState(const QString &desktopfp, size_t num)
|
||||||
{
|
{
|
||||||
return d->setAppFavoritesState(desktopfp, num);
|
return d->setAppFavoritesState(desktopfp, num);
|
||||||
|
@ -529,14 +522,9 @@ void AppInfoTable::setAppTopState(const QString &desktopfp, size_t num)
|
||||||
return d->setAppTopState(desktopfp, 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);
|
return d->setAppTopState(desktopfp);
|
||||||
}
|
|
||||||
|
|
||||||
bool AppInfoTable::changeTopAppPos(const QString &desktopfp, size_t pos)
|
|
||||||
{
|
|
||||||
return d->changeTopAppPos(desktopfp, pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppInfoTable::searchInstallApp(QString &keyWord, QStringList &installAppInfoRes)
|
bool AppInfoTable::searchInstallApp(QString &keyWord, QStringList &installAppInfoRes)
|
||||||
|
|
|
@ -28,7 +28,14 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief AppInfoTable::setAppFavoritesState
|
* @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 desktopfp: the desktop file path of app
|
||||||
* @param num: the favorites app's order(from 1)
|
* @param num: the favorites app's order(from 1)
|
||||||
*/
|
*/
|
||||||
|
@ -36,29 +43,19 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief AppInfoTable::setAppTopState
|
* @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 desktopfp: the desktop file path of app
|
||||||
* @param num: the top app's order(from 1)
|
* @param num: the top app's order(from 1)
|
||||||
*/
|
*/
|
||||||
void setAppTopState(const QString &desktopfp, size_t num);
|
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(QString &keyWord, QStringList &installAppInfoRes);
|
||||||
bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes);
|
bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes);
|
||||||
|
|
||||||
|
|
|
@ -67,26 +67,26 @@ ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties,
|
||||||
return infoMap;
|
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);
|
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);
|
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)
|
bool ApplicationInfo::tranPidToDesktopFp(int pid, QString &desktopFilePath)
|
||||||
{
|
{
|
||||||
return AppInfoTable::self()->tranPidToDesktopFp(pid, desktopFilePath);
|
return AppInfoTable::self()->tranPidToDesktopFp(pid, desktopFilePath);
|
||||||
|
|
|
@ -52,37 +52,34 @@ public:
|
||||||
ApplicationInfoMap searchApp(ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions);
|
ApplicationInfoMap searchApp(ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ApplicationInfo::setAppFavoritesState
|
* @brief AppInfoTable::setAppToFavorites
|
||||||
* set the favorites state of the app
|
* set the app to favorites apps(default is at 1)
|
||||||
* @param desktopFilePath: the desktop file path of app
|
* @param desktopfp: the desktop file path of app
|
||||||
* @param num: the favorites app's order(from 1)
|
|
||||||
*/
|
*/
|
||||||
void setAppFavoritesState(const QString &desktopFilePath, size_t num);
|
void setAppToFavorites(const QString &desktopFilePath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ApplicationInfo::setAppTopState
|
* @brief AppInfoTable::setFavoritesTo
|
||||||
* set the top state of the app
|
* 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 desktopFilePath: the desktop file path of app
|
* @param desktopfp: the desktop file path of app
|
||||||
* @param num: the top app's order(from 1)
|
* @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
|
* @brief AppInfoTable::setAppToTop
|
||||||
* change the position of the app which is one of the Favorites Apps
|
* set the app to top apps(default is at 1)
|
||||||
* @param desktopFilePath: desktop file path of app
|
* @param desktopfp: desktop file path of app
|
||||||
* @param pos: the position which the app will be changed into
|
|
||||||
*/
|
*/
|
||||||
bool changeFavoriteAppPos(const QString &desktopFilePath, size_t pos);
|
void setAppToTop(const QString &desktopFilePath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ApplicationInfo::changeTopAppPos
|
* @brief AppInfoTable::setAppTopTo
|
||||||
* hange the position of the app which is one of the Top Apps
|
* 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 desktopFilePath: desktop file path of app
|
* @param desktopfp: the desktop file path of app
|
||||||
* @param pos: the position which the app will be changed into
|
* @param num: the top app's position(from 1). If num is 0, it will remove the app from the top apps
|
||||||
* @return bool: true if success, else false
|
|
||||||
*/
|
*/
|
||||||
bool changeTopAppPos(const QString &desktopFilePath, size_t pos);
|
void setTopOfApp(const QString &desktopFilePath, size_t num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ApplicationInfo::tranPid2DesktopFp
|
* @brief ApplicationInfo::tranPid2DesktopFp
|
||||||
|
|
|
@ -385,24 +385,31 @@ bool AppDBManager::handleLocaleDataUpdate(const QString &desktopFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QSqlQuery sql(m_database);
|
QSqlQuery query(m_database);
|
||||||
sql.prepare("UPDATE appInfo SET LOCAL_NAME=:localName, FIRST_LETTER_ALL=:firstOfLetter2All WHERE DESKTOP_FILE_PATH=:desktopFilePath");
|
query.prepare("UPDATE appInfo SET LOCAL_NAME=:localName, FIRST_LETTER_ALL=:firstOfLetter2All WHERE DESKTOP_FILE_PATH=:desktopFilePath");
|
||||||
sql.bindValue(":localName", localName);
|
query.bindValue(":localName", localName);
|
||||||
sql.bindValue(":firstOfLetter2All", firstLetter2All);
|
query.bindValue(":firstOfLetter2All", firstLetter2All);
|
||||||
sql.bindValue(":desktopFilePath", desktopFilePath);
|
query.bindValue(":desktopFilePath", desktopFilePath);
|
||||||
|
|
||||||
if (!sql.exec()) {
|
if (!this->startTransaction()) {
|
||||||
qWarning() << m_database.lastError() << sql.lastQuery();
|
return false;
|
||||||
res = false;
|
|
||||||
}
|
}
|
||||||
if (res) {
|
|
||||||
ApplicationInfoMap appInfo;
|
if (query.exec()) {
|
||||||
appInfo[desktopFilePath].insert(ApplicationProperty::LocalName, QVariant(localName));
|
if (this->startCommit()) {
|
||||||
appInfo[desktopFilePath].insert(ApplicationProperty::FirstLetterAll, QVariant(firstLetter2All));
|
ApplicationInfoMap appInfo;
|
||||||
Q_EMIT this->appDBItemUpdate(appInfo);
|
appInfo[desktopFilePath].insert(ApplicationProperty::LocalName, QVariant(localName));
|
||||||
qDebug() << "Update the locale data of " << desktopFilePath;
|
appInfo[desktopFilePath].insert(ApplicationProperty::FirstLetterAll, QVariant(firstLetter2All));
|
||||||
|
Q_EMIT this->appDBItemUpdate(appInfo);
|
||||||
|
qDebug() << "Update the locale data of " << desktopFilePath;
|
||||||
|
} else {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Fail to update the locale data of " << desktopFilePath;
|
qDebug() << "Fail to update the locale data of " << desktopFilePath;
|
||||||
|
qWarning() << query.lastError() << query.lastQuery();
|
||||||
|
m_database.rollback();
|
||||||
|
res = false;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -472,7 +479,7 @@ bool AppDBManager::startTransaction()
|
||||||
if (m_database.transaction()) {
|
if (m_database.transaction()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Failed to start transaction mode!!!";
|
qWarning() << "Failed to start transaction mode!!!" << m_database.lastError();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,7 +487,7 @@ bool AppDBManager::startTransaction()
|
||||||
bool AppDBManager::startCommit()
|
bool AppDBManager::startCommit()
|
||||||
{
|
{
|
||||||
if (!m_database.commit()) {
|
if (!m_database.commit()) {
|
||||||
qWarning() << "Failed to commit !";
|
qWarning() << "Failed to commit !" << m_database.lastError();
|
||||||
m_database.rollback();
|
m_database.rollback();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -560,64 +567,117 @@ bool AppDBManager::handleDBItemInsert(const QString &desktopFilePath)
|
||||||
sql.bindValue(":exec", desktopfile.value("Exec").toString());
|
sql.bindValue(":exec", desktopfile.value("Exec").toString());
|
||||||
sql.bindValue(":comment", desktopfile.value("Comment").toString());
|
sql.bindValue(":comment", desktopfile.value("Comment").toString());
|
||||||
|
|
||||||
if (!sql.exec()) {
|
if (!this->startTransaction()) {
|
||||||
qWarning() << m_database.lastError() << sql.lastQuery();
|
return false;
|
||||||
res = false;
|
|
||||||
}
|
}
|
||||||
if (res) {
|
|
||||||
Q_EMIT this->appDBItemAdd(desktopFilePath);
|
if (sql.exec()) {
|
||||||
qDebug() << "app database add " << desktopFilePath << "success!";
|
if (this->startCommit()) {
|
||||||
|
Q_EMIT this->appDBItemAdd(desktopFilePath);
|
||||||
|
qDebug() << "app database add " << desktopFilePath << "success!";
|
||||||
|
} else {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "app database add " << desktopFilePath << "failed!";
|
qDebug() << "app database add " << desktopFilePath << "failed!";
|
||||||
|
qWarning() << m_database.lastError() << sql.lastQuery();
|
||||||
|
m_database.rollback();
|
||||||
|
res = false;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppDBManager::handleDBItemDelete(const QString &desktopFilePath)
|
bool AppDBManager::handleDBItemDelete(const QString &desktopFilePath)
|
||||||
{
|
{
|
||||||
|
if (!this->startTransaction()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool res(true);
|
bool res(true);
|
||||||
QSqlQuery sql(m_database);
|
QSqlQuery query(m_database);
|
||||||
sql.setForwardOnly(true);
|
query.setForwardOnly(true);
|
||||||
QString cmd = "SELECT FAVORITES, TOP FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath";
|
QString cmd = "SELECT FAVORITES, TOP FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath";
|
||||||
sql.prepare(cmd);
|
query.prepare(cmd);
|
||||||
sql.bindValue(":desktopFilePath", desktopFilePath);
|
query.bindValue(":desktopFilePath", desktopFilePath);
|
||||||
|
|
||||||
//查询要删除信息的应用是否被收藏或顶置过
|
//查询要删除信息的应用是否被收藏或顶置过
|
||||||
if (!sql.exec()) {
|
if (!query.exec()) {
|
||||||
qWarning() << m_database.lastError() << sql.lastQuery();
|
res = false;
|
||||||
} else if (sql.next()) {
|
qWarning() << m_database.lastError() << query.lastQuery();
|
||||||
int favorites = sql.value("FAVORITES").toInt();
|
} else if (query.next()) {
|
||||||
int top = sql.value("TOP").toInt();
|
int favorites = query.value("FAVORITES").toInt();
|
||||||
|
int top = query.value("TOP").toInt();
|
||||||
if (favorites) {
|
if (favorites) {
|
||||||
cmd = QString("UPDATE appInfo SET FAVORITES = FAVORITES -1 WHERE FAVORITES > %1").arg(favorites);
|
query.prepare(QString("UPDATE appInfo SET FAVORITES = FAVORITES -1 WHERE FAVORITES > %1").arg(favorites));
|
||||||
if (!sql.exec(cmd)) {
|
if (query.exec()) {
|
||||||
qWarning() << "I'm going to delete item in db, fail to update the FAVORITES because:" << m_database.lastError() << cmd;
|
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) {
|
if (top) {
|
||||||
cmd = QString("UPDATE appInfo SET TOP = TOP -1 WHERE TOP > %1").arg(top);
|
query.prepare(QString("UPDATE appInfo SET TOP = TOP -1 WHERE TOP > %1").arg(top));
|
||||||
if (!sql.exec(cmd)) {
|
if (query.exec()) {
|
||||||
qWarning() << "I'm going to delete item in db, fail to update the TOP because:" << m_database.lastError() << cmd;
|
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 {
|
} 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";
|
cmd = "DELETE FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath";
|
||||||
sql.prepare(cmd);
|
query.prepare(cmd);
|
||||||
sql.bindValue(":desktopFilePath", desktopFilePath);
|
query.bindValue(":desktopFilePath", desktopFilePath);
|
||||||
if (!sql.exec()) {
|
if (query.exec()) {
|
||||||
qWarning() << m_database.lastError() << cmd;
|
if (this->startCommit()) {
|
||||||
res = false;
|
Q_EMIT this->appDBItemDelete(desktopFilePath);
|
||||||
}
|
qDebug() << "app database delete " << desktopFilePath << "success!";
|
||||||
|
} else {
|
||||||
if (res) {
|
res = false;
|
||||||
Q_EMIT this->appDBItemDelete(desktopFilePath);
|
}
|
||||||
qDebug() << "app database delete " << desktopFilePath << "success!";
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "app database delete " << desktopFilePath << "failed!";
|
qDebug() << "app database delete " << desktopFilePath << "failed!";
|
||||||
|
qWarning() << query.lastError() << cmd;
|
||||||
|
m_database.rollback();
|
||||||
|
res = false;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -696,15 +756,22 @@ bool AppDBManager::handleDBItemUpdate(const QString &desktopFilePath)
|
||||||
sql.bindValue(":exec", desktopfile.value("Exec").toString());
|
sql.bindValue(":exec", desktopfile.value("Exec").toString());
|
||||||
sql.bindValue(":comment", desktopfile.value("Comment").toString());
|
sql.bindValue(":comment", desktopfile.value("Comment").toString());
|
||||||
|
|
||||||
if (!sql.exec()) {
|
if (!this->startTransaction()) {
|
||||||
qWarning() << m_database.lastError() << sql.lastQuery();
|
return false;
|
||||||
res = false;
|
|
||||||
}
|
}
|
||||||
if (res) {
|
|
||||||
Q_EMIT this->appDBItemUpdateAll(desktopFilePath);
|
if (sql.exec()) {
|
||||||
qDebug() << "app database update all data of" << desktopFilePath << "success!";
|
if (this->startCommit()) {
|
||||||
|
Q_EMIT this->appDBItemUpdateAll(desktopFilePath);
|
||||||
|
qDebug() << "app database update all data of" << desktopFilePath << "success!";
|
||||||
|
} else {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "app database update " << desktopFilePath << "failed!";
|
qDebug() << "app database update " << desktopFilePath << "failed!";
|
||||||
|
qWarning() << m_database.lastError() << sql.lastQuery();
|
||||||
|
m_database.rollback();
|
||||||
|
res = false;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -713,145 +780,448 @@ bool AppDBManager::handleLaunchTimesUpdate(const QString &desktopFilePath, int n
|
||||||
{
|
{
|
||||||
qDebug() << "launch times will add:" << num;
|
qDebug() << "launch times will add:" << num;
|
||||||
bool res(true);
|
bool res(true);
|
||||||
QSqlQuery sql(m_database);
|
QSqlQuery query(m_database);
|
||||||
sql.setForwardOnly(true);
|
query.setForwardOnly(true);
|
||||||
sql.prepare("SELECT LAUNCH_TIMES FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath");
|
query.prepare("SELECT LAUNCH_TIMES FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFilePath");
|
||||||
sql.bindValue(":desktopFilePath", desktopFilePath);
|
query.bindValue(":desktopFilePath", desktopFilePath);
|
||||||
if (sql.exec()) {
|
if (query.exec()) {
|
||||||
if (sql.next()) {
|
if (query.next()) {
|
||||||
int launchTimes = sql.value(0).toInt() + num;
|
int launchTimes = query.value(0).toInt() + num;
|
||||||
sql.prepare(QString("UPDATE appInfo SET MODIFYED_TIME='%0', LAUNCH_TIMES=%1, LAUNCHED=%2 WHERE DESKTOP_FILE_PATH=:desktopFilePath")
|
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(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
|
||||||
.arg(launchTimes)
|
.arg(launchTimes)
|
||||||
.arg(1));
|
.arg(1));
|
||||||
sql.bindValue(":desktopFilePath", desktopFilePath);
|
query.bindValue(":desktopFilePath", desktopFilePath);
|
||||||
if (!sql.exec()) {
|
if (!query.exec()) {
|
||||||
qWarning() << "Set app favorites state failed!" << m_database.lastError();
|
qWarning() << "Set app launch times failed!" << m_database.lastError();
|
||||||
res = false;
|
res = false;
|
||||||
|
m_database.rollback();
|
||||||
} else {
|
} else {
|
||||||
ApplicationInfoMap appInfo;
|
if (this->startCommit()) {
|
||||||
appInfo[desktopFilePath].insert(ApplicationProperty::LaunchTimes, QVariant(launchTimes));
|
ApplicationInfoMap appInfo;
|
||||||
appInfo[desktopFilePath].insert(ApplicationProperty::Launched, QVariant(1));
|
appInfo[desktopFilePath].insert(ApplicationProperty::LaunchTimes, QVariant(launchTimes));
|
||||||
Q_EMIT this->appDBItemUpdate(appInfo);
|
appInfo[desktopFilePath].insert(ApplicationProperty::Launched, QVariant(1));
|
||||||
qDebug() << "app database update " << desktopFilePath << "launch times: " << launchTimes << "success!";
|
Q_EMIT this->appDBItemUpdate(appInfo);
|
||||||
|
qDebug() << "app database update " << desktopFilePath << "launch times: " << launchTimes << "success!";
|
||||||
|
} else {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Failed to exec next!" << sql.lastQuery();
|
qWarning() << "Failed to exec next!" << query.lastQuery() << query.lastError();
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Failed to exec:" << sql.lastQuery();
|
qWarning() << "Failed to exec:" << query.lastQuery();
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopFilePath, int num, bool isOrderChanged)
|
bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopFilePath, const uint num)
|
||||||
{
|
{
|
||||||
if (num < 0) {
|
bool res(true);
|
||||||
qWarning() << "Invalid favorite num, I quit!!!";
|
QSqlQuery query(m_database);
|
||||||
return false;
|
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);
|
if (previousPos == num) {
|
||||||
sql.setForwardOnly(true);
|
res = false;
|
||||||
QString cmd;
|
qWarning() << "favorites state has no changes, I quit!";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
//当直接设置的时候需要查询要设置的favorites标志位是否被占用
|
//查询目前favorites最大值
|
||||||
if (!isOrderChanged) {
|
int maxFavorite = -1;
|
||||||
cmd = QString("SELECT DESKTOP_FILE_PATH, FAVORITES FROM APPINFO WHERE FAVORITES = %1").arg(num);
|
query.prepare("SELECT max(FAVORITES) as max FROM APPINFO");
|
||||||
if (!sql.exec(cmd)) {
|
if (query.exec()) {
|
||||||
qWarning() << "Fail to exec:" << cmd << "because:" << m_database.lastError();
|
if (query.next()) {
|
||||||
} else {
|
maxFavorite = query.value("max").toInt();
|
||||||
while (sql.next()) {
|
if (maxFavorite + 1 < num) {
|
||||||
if (num && sql.value("FAVORITES").toInt() == num) {
|
qWarning() << QString("Max favorites pos is %0.To be moved to a invalid pos, I quit!!").arg(query.value("max").toInt());
|
||||||
res = false;
|
res = false;
|
||||||
if (sql.value("DESKTOP_FILE_PATH").toString() == desktopFilePath) {
|
}
|
||||||
qWarning() << "favorites state has no changes, I quit!";
|
}
|
||||||
return res;
|
} 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 {
|
} else {
|
||||||
qWarning() << "the favorites num:" << num << "has been used, fail to update favorites state of" << desktopFilePath;
|
cmd = QString("SELECT DESKTOP_FILE_PATH, FAVORITES FROM APPINFO WHERE FAVORITES >= %1").arg(num);
|
||||||
return res;
|
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状态
|
//更新favorites状态
|
||||||
cmd = QString("UPDATE APPINFO SET MODIFYED_TIME='%0', FAVORITES=%1 WHERE DESKTOP_FILE_PATH=:desktopFilePath")
|
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(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
|
||||||
.arg(num);
|
.arg(num);
|
||||||
sql.prepare(cmd);
|
query.prepare(cmd);
|
||||||
sql.bindValue(":desktopFilePath", desktopFilePath);
|
query.bindValue(":desktopFilePath", desktopFilePath);
|
||||||
if (!sql.exec()) {
|
if (!query.exec()) {
|
||||||
qWarning() << "Set app favorites state failed!" << m_database.lastError();
|
qWarning() << "Set app favorites state failed!" << m_database.lastError();
|
||||||
res = false;
|
res = false;
|
||||||
|
m_database.rollback();
|
||||||
} else {
|
} else {
|
||||||
ApplicationInfoMap appInfo;
|
if (this->startCommit()) {
|
||||||
appInfo[desktopFilePath].insert(ApplicationProperty::Favorites, QVariant(num));
|
infos[desktopFilePath].insert(ApplicationProperty::Favorites, QVariant(num));
|
||||||
Q_EMIT this->appDBItemUpdate(appInfo);
|
Q_EMIT this->appDBItemUpdate(infos);
|
||||||
qDebug() << "app database update " << desktopFilePath << "favorites state: " << num << "success!";
|
qDebug() << "app database update " << desktopFilePath << "favorites state: " << num << "success!";
|
||||||
|
} else {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res;
|
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) {
|
if (pos < 1) {
|
||||||
qWarning() << "Invalid top num, I quit!!!";
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool res(true);
|
bool res(true);
|
||||||
QSqlQuery sql(m_database);
|
QSqlQuery query(m_database);
|
||||||
sql.setForwardOnly(true);
|
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;
|
QString cmd;
|
||||||
if (!isOrderChanged) {
|
ApplicationInfoMap infos;
|
||||||
cmd = QString("SELECT DESKTOP_FILE_PATH, TOP FROM APPINFO WHERE TOP = %1").arg(num);
|
|
||||||
if (!sql.exec(cmd)) {
|
//获取应用在数据库中的top标志位
|
||||||
qWarning() << "Fail to exec:" << cmd << "because:" << m_database.lastError();
|
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 {
|
} else {
|
||||||
while (sql.next()) {
|
qWarning() << query.lastQuery() << query.lastError();
|
||||||
if (num && sql.value("TOP").toInt() == num) {
|
}
|
||||||
res = false;
|
} else {
|
||||||
if (sql.value("DESKTOP_FILE_PATH").toString() == desktopFilePath) {
|
qWarning() << query.lastQuery() << query.lastError();
|
||||||
qWarning() << "top state has no changes, I quit!";
|
}
|
||||||
return res;
|
|
||||||
|
//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 {
|
} else {
|
||||||
qWarning() << "the top num:" << num << "has been used, fail to update top state of" << desktopFilePath;
|
cmd = QString("SELECT DESKTOP_FILE_PATH, TOP FROM APPINFO WHERE TOP >= %1").arg(num);
|
||||||
return res;
|
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状态
|
//更新top状态
|
||||||
cmd = QString("UPDATE APPINFO SET MODIFYED_TIME='%0', TOP=%1 WHERE DESKTOP_FILE_PATH=:desktopFilePath")
|
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(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
|
||||||
.arg(num);
|
.arg(num);
|
||||||
sql.prepare(cmd);
|
query.prepare(cmd);
|
||||||
sql.bindValue(":desktopFilePath", desktopFilePath);
|
query.bindValue(":desktopFilePath", desktopFilePath);
|
||||||
|
if (!query.exec()) {
|
||||||
if (!sql.exec()) {
|
qWarning() << "Set app top state failed!" << query.lastError();
|
||||||
qWarning() << "Set app favorites state failed!" << m_database.lastError();
|
|
||||||
res = false;
|
res = false;
|
||||||
|
m_database.rollback();
|
||||||
} else {
|
} else {
|
||||||
ApplicationInfoMap appInfo;
|
if (this->startCommit()) {
|
||||||
appInfo[desktopFilePath].insert(ApplicationProperty::Top, QVariant(num));
|
infos[desktopFilePath].insert(ApplicationProperty::Top, QVariant(num));
|
||||||
Q_EMIT this->appDBItemUpdate(appInfo);
|
Q_EMIT this->appDBItemUpdate(infos);
|
||||||
qDebug() << "app database update " << desktopFilePath << "top state: " << num << "success!";
|
qDebug() << "app database update " << desktopFilePath << "top state: " << num << "success!";
|
||||||
|
} else {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res;
|
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)
|
bool AppDBManager::handleLockStateUpdate(const QString &desktopFilePath, int num)
|
||||||
{
|
{
|
||||||
|
if (!this->startTransaction()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool res(true);
|
bool res(true);
|
||||||
QSqlQuery sql(m_database);
|
QSqlQuery sql(m_database);
|
||||||
sql.prepare(QString("UPDATE appInfo SET MODIFYED_TIME='%0', LOCK=%1 WHERE DESKTOP_FILE_PATH=:desktopFilePath")
|
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));
|
.arg(num));
|
||||||
sql.bindValue(":desktopFilePath", desktopFilePath);
|
sql.bindValue(":desktopFilePath", desktopFilePath);
|
||||||
if (!sql.exec()) {
|
if (!sql.exec()) {
|
||||||
qWarning() << "Set app favorites state failed!" << m_database.lastError();
|
qWarning() << "Set app lock state failed!" << m_database.lastError();
|
||||||
res = false;
|
res = false;
|
||||||
|
m_database.rollback();
|
||||||
} else {
|
} else {
|
||||||
ApplicationInfoMap appInfo;
|
if (this->startCommit()) {
|
||||||
appInfo[desktopFilePath].insert(ApplicationProperty::Lock, QVariant(num));
|
ApplicationInfoMap appInfo;
|
||||||
Q_EMIT this->appDBItemUpdate(appInfo);
|
appInfo[desktopFilePath].insert(ApplicationProperty::Lock, QVariant(num));
|
||||||
qDebug() << "app database update " << desktopFilePath << "lock state: " << num << "success!";
|
Q_EMIT this->appDBItemUpdate(appInfo);
|
||||||
|
qDebug() << "app database update " << desktopFilePath << "lock state: " << num << "success!";
|
||||||
|
} else {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -1048,19 +1423,17 @@ void AppDBManager::updateLaunchTimes(const QString &desktopFilePath)
|
||||||
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
|
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);
|
PendingAppInfo item(desktopFilePath, PendingAppInfo::HandleType::UpdateFavorites);
|
||||||
item.setFavorites(num);
|
item.setFavorites(num);
|
||||||
item.setChangeFavoritePos(isOrderChanged);
|
|
||||||
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
|
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);
|
PendingAppInfo item(desktopFilePath, PendingAppInfo::HandleType::UpdateTop);
|
||||||
item.setTop(num);
|
item.setTop(num);
|
||||||
item.setChangeTopPos(isOrderChanged);
|
|
||||||
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
|
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1070,129 +1443,3 @@ void AppDBManager::udpateLockState(const QString &desktopFilePath, int num)
|
||||||
item.setLock(num);
|
item.setLock(num);
|
||||||
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -55,9 +55,9 @@ public:
|
||||||
bool handleDBItemDelete(const QString &desktopFilePath);
|
bool handleDBItemDelete(const QString &desktopFilePath);
|
||||||
|
|
||||||
bool handleLocaleDataUpdate(const QString &desktopFilePath);
|
bool handleLocaleDataUpdate(const QString &desktopFilePath);
|
||||||
bool handleLaunchTimesUpdate(const QString &desktopFilePath, int num);
|
bool handleLaunchTimesUpdate(const QString &desktopFilePath, int num = 1);
|
||||||
bool handleFavoritesStateUpdate(const QString &desktopFilePath, int num, bool isOrderChanged = false);
|
bool handleFavoritesStateUpdate(const QString &desktopFilePath, const uint num);
|
||||||
bool handleTopStateUpdate(const QString &desktopFilePath, int num, bool isOrderChanged = false);
|
bool handleTopStateUpdate(const QString &desktopFilePath, const uint num);
|
||||||
bool handleLockStateUpdate(const QString &desktopFilePath, int num);
|
bool handleLockStateUpdate(const QString &desktopFilePath, int num);
|
||||||
void handleDataBaseRefresh(const QStringList &appPaths, bool dbVersionNeedUpdate);
|
void handleDataBaseRefresh(const QStringList &appPaths, bool dbVersionNeedUpdate);
|
||||||
|
|
||||||
|
@ -73,14 +73,10 @@ public Q_SLOTS:
|
||||||
//对数据库某字段进行update
|
//对数据库某字段进行update
|
||||||
void updateLocaleData(const QString &desktopFilePath);
|
void updateLocaleData(const QString &desktopFilePath);
|
||||||
void updateLaunchTimes(const QString &desktopFilePath);
|
void updateLaunchTimes(const QString &desktopFilePath);
|
||||||
void updateFavoritesState(const QString &desktopFilePath, int num, bool isOrderChanged = false);
|
void updateFavoritesState(const QString &desktopFilePath, uint num = 1);
|
||||||
void updateTopState(const QString &desktopFilePath, int num, bool isOrderChanged = false);
|
void updateTopState(const QString &desktopFilePath, uint num = 1);
|
||||||
void udpateLockState(const QString &desktopFilePath, int num);
|
void udpateLockState(const QString &desktopFilePath, int num);
|
||||||
|
|
||||||
//拖动改变置顶和收藏应用位置
|
|
||||||
bool changeFavoriteAppPos(const QString &desktopFilePath, int pos);
|
|
||||||
bool changeTopAppPos(const QString &desktopFilePath, int pos);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
|
@ -107,6 +103,10 @@ private:
|
||||||
//初始化fileSystemWatcher
|
//初始化fileSystemWatcher
|
||||||
void initFileSystemWatcher();
|
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:
|
private:
|
||||||
static QMutex s_mutex;
|
static QMutex s_mutex;
|
||||||
bool m_localeChanged;
|
bool m_localeChanged;
|
||||||
|
|
|
@ -128,60 +128,55 @@ void PendingAppInfoQueue::processCache()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AppDBManager::getInstance()->startTransaction()) {
|
for (const PendingAppInfo &info : m_pendingAppInfos) {
|
||||||
for (const PendingAppInfo &info : m_pendingAppInfos) {
|
PendingAppInfo::HandleTypes handleTypes = info.handleType();
|
||||||
PendingAppInfo::HandleTypes handleTypes = info.handleType();
|
if (handleTypes <= PendingAppInfo::UpdateLocaleData || handleTypes == PendingAppInfo::RefreshDataBase) {
|
||||||
if (handleTypes <= PendingAppInfo::UpdateLocaleData || handleTypes == PendingAppInfo::RefreshDataBase) {
|
switch (handleTypes) {
|
||||||
switch (handleTypes) {
|
case PendingAppInfo::Delete:
|
||||||
case PendingAppInfo::Delete:
|
AppDBManager::getInstance()->handleDBItemDelete(info.path());
|
||||||
AppDBManager::getInstance()->handleDBItemDelete(info.path());
|
break;
|
||||||
break;
|
case PendingAppInfo::Insert:
|
||||||
case PendingAppInfo::Insert:
|
AppDBManager::getInstance()->handleDBItemInsert(info.path());
|
||||||
AppDBManager::getInstance()->handleDBItemInsert(info.path());
|
break;
|
||||||
break;
|
case PendingAppInfo::UpdateAll:
|
||||||
case PendingAppInfo::UpdateAll:
|
AppDBManager::getInstance()->handleDBItemUpdate(info.path());
|
||||||
AppDBManager::getInstance()->handleDBItemUpdate(info.path());
|
break;
|
||||||
break;
|
case PendingAppInfo::UpdateLocaleData:
|
||||||
case PendingAppInfo::UpdateLocaleData:
|
AppDBManager::getInstance()->handleLocaleDataUpdate(info.path());
|
||||||
AppDBManager::getInstance()->handleLocaleDataUpdate(info.path());
|
break;
|
||||||
break;
|
case PendingAppInfo::RefreshDataBase:
|
||||||
case PendingAppInfo::RefreshDataBase:
|
AppDBManager::getInstance()->handleDataBaseRefresh(info.pathsNeedRefreshData(), info.dbVersionNeedUpdate());
|
||||||
AppDBManager::getInstance()->handleDataBaseRefresh(info.pathsNeedRefreshData(), info.dbVersionNeedUpdate());
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
break;
|
||||||
break;
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
if (handleTypes & PendingAppInfo::Insert) {
|
||||||
if (handleTypes & PendingAppInfo::Insert) {
|
AppDBManager::getInstance()->handleDBItemInsert(info.path());
|
||||||
AppDBManager::getInstance()->handleDBItemInsert(info.path());
|
}
|
||||||
}
|
if (handleTypes & PendingAppInfo::UpdateAll) {
|
||||||
if (handleTypes & PendingAppInfo::UpdateAll) {
|
AppDBManager::getInstance()->handleDBItemUpdate(info.path());
|
||||||
AppDBManager::getInstance()->handleDBItemUpdate(info.path());
|
}
|
||||||
}
|
if (handleTypes & PendingAppInfo::UpdateLocaleData) {
|
||||||
if (handleTypes & PendingAppInfo::UpdateLocaleData) {
|
AppDBManager::getInstance()->handleLocaleDataUpdate(info.path());
|
||||||
AppDBManager::getInstance()->handleLocaleDataUpdate(info.path());
|
}
|
||||||
}
|
if (handleTypes & PendingAppInfo::UpdateLaunchTimes) {
|
||||||
if (handleTypes & PendingAppInfo::UpdateLaunchTimes) {
|
AppDBManager::getInstance()->handleLaunchTimesUpdate(info.path(), info.launchTimes());
|
||||||
AppDBManager::getInstance()->handleLaunchTimesUpdate(info.path(), info.launchTimes());
|
}
|
||||||
}
|
if (handleTypes & PendingAppInfo::UpdateFavorites) {
|
||||||
if (handleTypes & PendingAppInfo::UpdateFavorites) {
|
AppDBManager::getInstance()->handleFavoritesStateUpdate(info.path(), info.favoritesState());
|
||||||
AppDBManager::getInstance()->handleFavoritesStateUpdate(info.path(), info.favoritesState(), info.isFavoritePosChanged());
|
}
|
||||||
}
|
if (handleTypes & PendingAppInfo::UpdateTop) {
|
||||||
if (handleTypes & PendingAppInfo::UpdateTop) {
|
AppDBManager::getInstance()->handleTopStateUpdate(info.path(), info.topState());
|
||||||
AppDBManager::getInstance()->handleTopStateUpdate(info.path(), info.topState(), info.isTopPosChanged());
|
}
|
||||||
}
|
if (handleTypes & PendingAppInfo::UpdateLock) {
|
||||||
if (handleTypes & PendingAppInfo::UpdateLock) {
|
AppDBManager::getInstance()->handleLockStateUpdate(info.path(), info.lockState());
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,17 +26,14 @@ public:
|
||||||
PendingAppInfo() = default;
|
PendingAppInfo() = default;
|
||||||
PendingAppInfo(QString desktopfp, HandleTypes type,
|
PendingAppInfo(QString desktopfp, HandleTypes type,
|
||||||
int favorites = -1, int top = -1, int lock = -1,
|
int favorites = -1, int top = -1, int lock = -1,
|
||||||
bool addLaunch = false, int launchTimes = 0,
|
bool addLaunch = false, int launchTimes = 0)
|
||||||
bool isChangeFavorite = false, bool isChangeTopPos = false)
|
|
||||||
: m_desktopfp(desktopfp),
|
: m_desktopfp(desktopfp),
|
||||||
m_handleType(type),
|
m_handleType(type),
|
||||||
m_favoritesState(favorites),
|
m_favoritesState(favorites),
|
||||||
m_topState(top),
|
m_topState(top),
|
||||||
m_lockState(lock),
|
m_lockState(lock),
|
||||||
m_willAddLaunch(addLaunch),
|
m_willAddLaunch(addLaunch),
|
||||||
m_launchTimes(launchTimes),
|
m_launchTimes(launchTimes) {}
|
||||||
m_isFavoritePosChanged(isChangeFavorite),
|
|
||||||
m_isTopPosChanged(isChangeTopPos) {}
|
|
||||||
|
|
||||||
QString path() const {return m_desktopfp;}
|
QString path() const {return m_desktopfp;}
|
||||||
QStringList pathsNeedRefreshData() const {return m_pathsNeedRefreshData;}
|
QStringList pathsNeedRefreshData() const {return m_pathsNeedRefreshData;}
|
||||||
|
@ -46,8 +43,6 @@ public:
|
||||||
int lockState() const {return m_lockState;}
|
int lockState() const {return m_lockState;}
|
||||||
int launchTimes() const {return m_launchTimes;}
|
int launchTimes() const {return m_launchTimes;}
|
||||||
bool willAddLunchTimes() const {return m_willAddLaunch;}
|
bool willAddLunchTimes() const {return m_willAddLaunch;}
|
||||||
bool isFavoritePosChanged() const {return m_isFavoritePosChanged;}
|
|
||||||
bool isTopPosChanged() const {return m_isTopPosChanged;}
|
|
||||||
bool dbVersionNeedUpdate() const {return m_dbVersionNeedUpdate;}
|
bool dbVersionNeedUpdate() const {return m_dbVersionNeedUpdate;}
|
||||||
|
|
||||||
void setDesktopFp(const QString& desktopfp) {m_desktopfp = desktopfp;}
|
void setDesktopFp(const QString& desktopfp) {m_desktopfp = desktopfp;}
|
||||||
|
@ -58,8 +53,6 @@ public:
|
||||||
void setLock(int lock) {m_lockState = lock;}
|
void setLock(int lock) {m_lockState = lock;}
|
||||||
void setLaunchWillAdd(bool willAdd) {m_willAddLaunch = willAdd;}
|
void setLaunchWillAdd(bool willAdd) {m_willAddLaunch = willAdd;}
|
||||||
void setLaunchTimes(int times) {m_launchTimes = times;}
|
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 setPathsNeedRefreshData (const QStringList& paths) {m_pathsNeedRefreshData = paths;}
|
||||||
void setDBUpdate(bool versionNeedUpdate) {m_dbVersionNeedUpdate = versionNeedUpdate;}
|
void setDBUpdate(bool versionNeedUpdate) {m_dbVersionNeedUpdate = versionNeedUpdate;}
|
||||||
void merge(const PendingAppInfo& info)
|
void merge(const PendingAppInfo& info)
|
||||||
|
@ -93,8 +86,6 @@ private:
|
||||||
int m_lockState = -1;
|
int m_lockState = -1;
|
||||||
bool m_willAddLaunch = false;
|
bool m_willAddLaunch = false;
|
||||||
int m_launchTimes = 0;
|
int m_launchTimes = 0;
|
||||||
bool m_isFavoritePosChanged = false;
|
|
||||||
bool m_isTopPosChanged = false;
|
|
||||||
QStringList m_pathsNeedRefreshData;
|
QStringList m_pathsNeedRefreshData;
|
||||||
bool m_dbVersionNeedUpdate = false;
|
bool m_dbVersionNeedUpdate = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue