diff --git a/libsearch/appdata/application-info.cpp b/libsearch/appdata/application-info.cpp index 369a8bc..2917147 100644 --- a/libsearch/appdata/application-info.cpp +++ b/libsearch/appdata/application-info.cpp @@ -108,4 +108,8 @@ bool ApplicationInfo::tranWinIdToDesktopFilePath(const QVariant &winId, QString return d->m_infoTable->tranWinIdToDesktopFilePath(winId, desktopFilePath); } +void ApplicationInfo::removeAppFromFavorites(const QString &desktopFilePath) { + return d->m_infoTable->setAppFavoritesState(desktopFilePath, 0); +} + ApplicationInfo::~ApplicationInfo() = default; diff --git a/libsearch/appdata/application-info.h b/libsearch/appdata/application-info.h index 2776be3..93aa6ed 100644 --- a/libsearch/appdata/application-info.h +++ b/libsearch/appdata/application-info.h @@ -73,25 +73,33 @@ public: /** * @brief AppInfoTable::setAppToFavorites - * set the app to favorites apps(default is at 1) + * set the app to favorites apps * @param desktopFilePath: the desktop file path of app */ void setAppToFavorites(const QString &desktopFilePath); /** + * @brief AppInfoTable::removeAppFromFavorites + * remove the app from favorites apps + * @param desktopFilePath: the desktop file path of app + */ + void removeAppFromFavorites(const QString &desktopFilePath); + + /** + * this function has been deprecated, use setAppToFavorites and removeAppFromFavorites instead * @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 desktopFilePath: 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 setFavoritesOfApp(const QString &desktopFilePath, size_t num); + [[deprecated]] void setFavoritesOfApp(const QString &desktopFilePath, size_t num); /** * @brief AppInfoTable::setAppToTop * set the app to top apps(default is at 1) * @param desktopFilePath: desktop file path of app */ - void setAppToTop(const QString &desktopFilePath); + [[deprecated]] void setAppToTop(const QString &desktopFilePath); /** * @brief AppInfoTable::setAppTopTo @@ -99,7 +107,7 @@ public: * @param desktopFilePath: 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 */ - void setTopOfApp(const QString &desktopFilePath, size_t num); + [[deprecated]] void setTopOfApp(const QString &desktopFilePath, size_t num); void setAppLaunchedState(const QString &desktopFilePath, bool launched = true); @@ -110,7 +118,7 @@ public: * @param desktopFilePath: the desktop file path of the process corresponding to pid * @return bool:true if success,else false */ - bool tranPidToDesktopFp(int pid, QString &desktopFilePath);//obsolete + [[deprecated]] bool tranPidToDesktopFp(int pid, QString &desktopFilePath);//obsolete bool tranPidToDesktopFp(uint pid, QString &desktopFilePath); /** diff --git a/ukui-search-app-data-service/app-db-manager.cpp b/ukui-search-app-data-service/app-db-manager.cpp index 5e9a0b4..3a82525 100644 --- a/ukui-search-app-data-service/app-db-manager.cpp +++ b/ukui-search-app-data-service/app-db-manager.cpp @@ -790,123 +790,6 @@ bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopFilePath, co QString cmd; ApplicationInfoMap infos; - //获取应用在数据库中的favorites标志位 - uint previousPos = 0; - bool getPrevious(false); - 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").toUInt(); - getPrevious = true; - } else { - qWarning() << query.lastQuery() << query.lastError(); - } - } else { - qWarning() << query.lastQuery() << query.lastError(); - } - - //收藏位未改变 - if (getPrevious && previousPos == num) { - res = false; - qWarning() << "favorites state has no changes, I quit!"; - return res; - } - - //查询目前favorites最大值 - uint maxFavorite = 0; - query.prepare("SELECT max(FAVORITES) as max FROM APPINFO"); - if (query.exec()) { - if (query.next()) { - maxFavorite = query.value("max").toUInt(); - 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 (getPrevious && !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 { - 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"))