Add a interface to set launched state.
Add a method to set value of field in database.
This commit is contained in:
parent
fbd391d110
commit
8f03c44ef4
|
@ -41,6 +41,7 @@ public:
|
|||
void setAppFavoritesState(const QString &desktopfp, uint num);
|
||||
void setAppTopState(const QString &desktopfp);
|
||||
void setAppTopState(const QString &desktopfp, uint num);
|
||||
void setAppLaunchedState(const QString &desktopFilePath, bool launched);
|
||||
|
||||
//搜索接口
|
||||
bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes);
|
||||
|
|
|
@ -83,6 +83,15 @@ void AppInfoTablePrivate::setAppTopState(const QString &desktopfp, uint num)
|
|||
m_appDBInterface->call("updateTopState", desktopfp, num);
|
||||
}
|
||||
|
||||
void AppInfoTablePrivate::setAppLaunchedState(const QString &desktopFilePath, bool launched)
|
||||
{
|
||||
ApplicationInfoMap infoMap;
|
||||
infoMap[desktopFilePath].insert(ApplicationProperty::Launched, launched);
|
||||
QVariant var;
|
||||
var.setValue(infoMap);
|
||||
m_appDBInterface->call("setValue", var);
|
||||
}
|
||||
|
||||
bool AppInfoTablePrivate::searchInstallApp(QString &keyWord, QStringList &installAppInfoRes)
|
||||
{
|
||||
bool res(true);
|
||||
|
@ -522,6 +531,11 @@ void AppInfoTable::setAppTopState(const QString &desktopfp, size_t num)
|
|||
return d->setAppTopState(desktopfp, num);
|
||||
}
|
||||
|
||||
void AppInfoTable::setAppLaunchedState(const QString &desktopFilePath, bool launched)
|
||||
{
|
||||
return d->setAppLaunchedState(desktopFilePath, launched);
|
||||
}
|
||||
|
||||
void AppInfoTable::setAppTopState(const QString &desktopfp)
|
||||
{
|
||||
return d->setAppTopState(desktopfp);
|
||||
|
|
|
@ -75,6 +75,8 @@ public:
|
|||
*/
|
||||
void setAppTopState(const QString &desktopfp, size_t num);
|
||||
|
||||
void setAppLaunchedState(const QString &desktopFilePath, bool launched);
|
||||
|
||||
bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes);
|
||||
bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes);
|
||||
|
||||
|
|
|
@ -87,6 +87,11 @@ void ApplicationInfo::setTopOfApp(const QString &desktopFilePath, size_t num)
|
|||
AppInfoTable::self()->setAppTopState(desktopFilePath, num);
|
||||
}
|
||||
|
||||
void ApplicationInfo::setAppLaunchedState(const QString &desktopFilePath, bool launched)
|
||||
{
|
||||
AppInfoTable::self()->setAppLaunchedState(desktopFilePath, launched);
|
||||
}
|
||||
|
||||
bool ApplicationInfo::tranPidToDesktopFp(int pid, QString &desktopFilePath)
|
||||
{
|
||||
return AppInfoTable::self()->tranPidToDesktopFp(pid, desktopFilePath);
|
||||
|
|
|
@ -100,6 +100,8 @@ public:
|
|||
*/
|
||||
void setTopOfApp(const QString &desktopFilePath, size_t num);
|
||||
|
||||
void setAppLaunchedState(const QString &desktopFilePath, bool launched = true);
|
||||
|
||||
/**
|
||||
* @brief ApplicationInfo::tranPid2DesktopFp
|
||||
* find the desktop file path of the process which corresponds to the pid
|
||||
|
|
|
@ -60,4 +60,5 @@ typedef QMap<ApplicationProperty::Property, QVariant> ApplicationPropertyMap;
|
|||
typedef QMap<QString, ApplicationPropertyMap> ApplicationInfoMap; // desktopFile->ApplicationPropertyMap
|
||||
}
|
||||
Q_DECLARE_METATYPE(UkuiSearch::ApplicationProperty::Property)
|
||||
Q_DECLARE_METATYPE(UkuiSearch::ApplicationInfoMap)
|
||||
#endif // APPLICATIONPROPERTY_H
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "app-db-manager.h"
|
||||
#include "file-utils.h"
|
||||
#include "convert-winid-to-desktop.h"
|
||||
#include "application-property-helper.h"
|
||||
|
||||
#include <qt5xdg/XdgDesktopFile>
|
||||
#include <QMutexLocker>
|
||||
|
@ -1355,6 +1356,46 @@ void AppDBManager::handleDataBaseRefresh(const QStringList &appPaths, bool dbVer
|
|||
}
|
||||
}
|
||||
|
||||
bool AppDBManager::handleValueSet(const ApplicationInfoMap appInfoMap)
|
||||
{
|
||||
bool res(true);
|
||||
QSqlQuery query(m_database);
|
||||
|
||||
for (auto iter = appInfoMap.constBegin(); iter != appInfoMap.constEnd(); iter++) {
|
||||
QString desktopFilePath = iter.key();
|
||||
ApplicationPropertyMap propMap = iter.value();
|
||||
for (auto propIter = propMap.constBegin(); propIter != propMap.constEnd(); ++propIter) {
|
||||
QString field = ApplicationPropertyHelper(propIter.key()).dataBaseField();
|
||||
|
||||
query.prepare(QString("UPDATE appInfo SET MODIFYED_TIME='%0', %1=:value WHERE DESKTOP_FILE_PATH=:desktopFilePath")
|
||||
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
|
||||
.arg(field));
|
||||
query.bindValue(":value", propIter.value());
|
||||
query.bindValue(":desktopFilePath", desktopFilePath);
|
||||
|
||||
if (!this->startTransaction()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << "Set state failed!" << query.lastError();
|
||||
res = false;
|
||||
m_database.rollback();
|
||||
} else {
|
||||
if (this->startCommit()) {
|
||||
ApplicationInfoMap infos2BSend;
|
||||
infos2BSend[desktopFilePath].insert(propIter.key(), propIter.value());
|
||||
Q_EMIT this->appDBItemUpdate(infos2BSend);
|
||||
qDebug() << "app database update " << desktopFilePath << field << propIter.value() << "success!";
|
||||
} else {
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
QString AppDBManager::tranPidToDesktopFp(int pid)
|
||||
{
|
||||
QString exePath = QFile::symLinkTarget("/proc/" + QString::number(pid) + "/exe");
|
||||
|
@ -1455,9 +1496,11 @@ void AppDBManager::updateTopState(const QString &desktopFilePath, uint num)
|
|||
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
|
||||
}
|
||||
|
||||
void AppDBManager::udpateLockState(const QString &desktopFilePath, int num)
|
||||
void AppDBManager::setValue(const ApplicationInfoMap &infos2BSet)
|
||||
{
|
||||
PendingAppInfo item(desktopFilePath, PendingAppInfo::HandleType::UpdateTop);
|
||||
item.setLock(num);
|
||||
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
|
||||
for (const QString &desktopFilePath : infos2BSet.keys()) {
|
||||
PendingAppInfo item(desktopFilePath, PendingAppInfo::SetValue);
|
||||
item.setValue(infos2BSet);
|
||||
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,8 @@ public:
|
|||
bool handleLockStateUpdate(const QString &desktopFilePath, int num);
|
||||
void handleDataBaseRefresh(const QStringList &appPaths, bool dbVersionNeedUpdate);
|
||||
|
||||
bool handleValueSet(const ApplicationInfoMap appInfoMap);
|
||||
|
||||
public Q_SLOTS:
|
||||
//通过pid查找对应的desktop文件
|
||||
QString tranPidToDesktopFp(int pid);
|
||||
|
@ -94,7 +96,8 @@ public Q_SLOTS:
|
|||
void updateLaunchTimes(const QString &desktopFilePath);
|
||||
void updateFavoritesState(const QString &desktopFilePath, uint num = 1);
|
||||
void updateTopState(const QString &desktopFilePath, uint num = 1);
|
||||
void udpateLockState(const QString &desktopFilePath, int num);
|
||||
|
||||
void setValue(const ApplicationInfoMap &infos2BSet);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
|
|
@ -50,6 +50,8 @@ void PendingAppInfoQueue::enqueue(const PendingAppInfo &appInfo)
|
|||
if (appInfo.handleType() == PendingAppInfo::Insert) {
|
||||
m_cache << appInfo;
|
||||
}
|
||||
} else if (appInfo.handleType() == PendingAppInfo::SetValue) {
|
||||
m_cache << appInfo;
|
||||
} else if (m_cache[index].handleType() <= PendingAppInfo::UpdateLocaleData
|
||||
and appInfo.handleType() <= PendingAppInfo::UpdateLocaleData) {
|
||||
//类型为insert, updateall, updatelocaledata时,设置为优先级高的操作类型
|
||||
|
@ -148,7 +150,7 @@ void PendingAppInfoQueue::processCache()
|
|||
|
||||
for (const PendingAppInfo &info : m_pendingAppInfos) {
|
||||
PendingAppInfo::HandleTypes handleTypes = info.handleType();
|
||||
if (handleTypes <= PendingAppInfo::UpdateLocaleData || handleTypes == PendingAppInfo::RefreshDataBase) {
|
||||
if (handleTypes <= PendingAppInfo::UpdateLocaleData || handleTypes == PendingAppInfo::RefreshDataBase || handleTypes == PendingAppInfo::SetValue) {
|
||||
switch (handleTypes) {
|
||||
case PendingAppInfo::Delete:
|
||||
AppDBManager::getInstance()->handleDBItemDelete(info.path());
|
||||
|
@ -165,6 +167,9 @@ void PendingAppInfoQueue::processCache()
|
|||
case PendingAppInfo::RefreshDataBase:
|
||||
AppDBManager::getInstance()->handleDataBaseRefresh(info.pathsNeedRefreshData(), info.dbVersionNeedUpdate());
|
||||
break;
|
||||
case PendingAppInfo::SetValue:
|
||||
AppDBManager::getInstance()->handleValueSet(info.value2BSet());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -187,9 +192,6 @@ void PendingAppInfoQueue::processCache()
|
|||
if (handleTypes & PendingAppInfo::UpdateTop) {
|
||||
AppDBManager::getInstance()->handleTopStateUpdate(info.path(), info.topState());
|
||||
}
|
||||
if (handleTypes & PendingAppInfo::UpdateLock) {
|
||||
AppDBManager::getInstance()->handleLockStateUpdate(info.path(), info.lockState());
|
||||
}
|
||||
}
|
||||
}
|
||||
Q_EMIT AppDBManager::getInstance()->finishHandleAppDB();
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QFlags>
|
||||
#include "application-property.h"
|
||||
|
||||
namespace UkuiSearch {
|
||||
|
||||
|
@ -37,20 +38,19 @@ public:
|
|||
UpdateLaunchTimes = 1u << 3,
|
||||
UpdateFavorites = 1u << 4,
|
||||
UpdateTop = 1u << 5,
|
||||
UpdateLock = 1u << 6,
|
||||
RefreshDataBase = 1u << 7
|
||||
RefreshDataBase = 1u << 6,
|
||||
SetValue = 1u << 7
|
||||
};
|
||||
Q_DECLARE_FLAGS(HandleTypes, HandleType)
|
||||
|
||||
PendingAppInfo() = default;
|
||||
PendingAppInfo(QString desktopfp, HandleTypes type,
|
||||
int favorites = -1, int top = -1, int lock = -1,
|
||||
int favorites = -1, int top = -1,
|
||||
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) {}
|
||||
|
||||
|
@ -59,21 +59,21 @@ public:
|
|||
HandleTypes handleType() const {return m_handleType;}
|
||||
int favoritesState() const {return m_favoritesState;}
|
||||
int topState() const {return m_topState;}
|
||||
int lockState() const {return m_lockState;}
|
||||
int launchTimes() const {return m_launchTimes;}
|
||||
bool willAddLunchTimes() const {return m_willAddLaunch;}
|
||||
bool dbVersionNeedUpdate() const {return m_dbVersionNeedUpdate;}
|
||||
ApplicationInfoMap value2BSet() const {return m_appInfoMap;}
|
||||
|
||||
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 setPathsNeedRefreshData (const QStringList& paths) {m_pathsNeedRefreshData = paths;}
|
||||
void setDBUpdate(bool versionNeedUpdate) {m_dbVersionNeedUpdate = versionNeedUpdate;}
|
||||
void setValue(const ApplicationInfoMap infoMap) {m_appInfoMap = infoMap;}
|
||||
void merge(const PendingAppInfo& info)
|
||||
{
|
||||
m_handleType |= info.handleType();
|
||||
|
@ -86,9 +86,6 @@ public:
|
|||
m_topState = info.topState();
|
||||
}
|
||||
|
||||
if (info.lockState() != -1) {
|
||||
m_lockState = info.lockState();
|
||||
}
|
||||
if (info.willAddLunchTimes()) {
|
||||
m_launchTimes++;
|
||||
}
|
||||
|
@ -102,11 +99,11 @@ private:
|
|||
HandleTypes m_handleType;
|
||||
int m_favoritesState = -1;
|
||||
int m_topState = -1;
|
||||
int m_lockState = -1;
|
||||
bool m_willAddLaunch = false;
|
||||
int m_launchTimes = 0;
|
||||
QStringList m_pathsNeedRefreshData;
|
||||
bool m_dbVersionNeedUpdate = false;
|
||||
ApplicationInfoMap m_appInfoMap;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue