fix(app-database):can not find the currect desktop file by pid
use ProcessManager's dbus interface instead.
This commit is contained in:
parent
806aa95930
commit
4f8899810d
|
@ -32,22 +32,22 @@ public:
|
||||||
explicit ApplicationInfo(QObject *parent = nullptr);
|
explicit ApplicationInfo(QObject *parent = nullptr);
|
||||||
~ApplicationInfo();
|
~ApplicationInfo();
|
||||||
/**
|
/**
|
||||||
* @brief getInfo 查询单个应用的单个属性
|
* @brief ApplicationInfo::getInfo 查询单个应用的单个属性
|
||||||
* @param desktopFile
|
* @param desktopFile: 要查询的应用的desktop文件路径
|
||||||
* @param property
|
* @param property: 要查询的属性
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
QVariant getInfo(const QString &desktopFile, ApplicationProperty::Property property);
|
QVariant getInfo(const QString &desktopFile, ApplicationProperty::Property property);
|
||||||
/**
|
/**
|
||||||
* @brief getInfo 查询单个应用的多个属性
|
* @brief ApplicationInfo::getInfo 查询单个应用的多个属性
|
||||||
* @param desktopFile
|
* @param desktopFile: 要查询的应用的desktop文件路径
|
||||||
* @param properties
|
* @param properties: 要查询的属性
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ApplicationPropertyMap getInfo(const QString &desktopFile, ApplicationProperties properties);
|
ApplicationPropertyMap getInfo(const QString &desktopFile, ApplicationProperties properties);
|
||||||
/**
|
/**
|
||||||
* @brief getInfo 查询所有应用的多个属性
|
* @brief ApplicationInfo::getInfo 查询所有应用的多个属性
|
||||||
* @param property
|
* @param properties: 要查询的属性
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ApplicationInfoMap getInfo(ApplicationProperties properties);
|
ApplicationInfoMap getInfo(ApplicationProperties properties);
|
||||||
|
@ -63,8 +63,9 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ApplicationInfo::searchApp
|
* @brief ApplicationInfo::searchApp
|
||||||
* @param keyWord: the keyword of this search for applications
|
* @param properties: Each application's information should contain these properties
|
||||||
* @param installAppInfoRes: the search results of applications
|
* @param keyword: the keyword of this search for applications
|
||||||
|
* @param restrictions: The restrictions that the search results should meet(e.g. u want get the app infos whose top state is 0)
|
||||||
* @return ApplicationInfoMap: the search result
|
* @return ApplicationInfoMap: the search result
|
||||||
*/
|
*/
|
||||||
ApplicationInfoMap searchApp(ApplicationProperties properties, const QString &keyword, ApplicationPropertyMap restrictions);
|
ApplicationInfoMap searchApp(ApplicationProperties properties, const QString &keyword, ApplicationPropertyMap restrictions);
|
||||||
|
@ -73,14 +74,14 @@ public:
|
||||||
/**
|
/**
|
||||||
* @brief AppInfoTable::setAppToFavorites
|
* @brief AppInfoTable::setAppToFavorites
|
||||||
* set the app to favorites apps(default is at 1)
|
* set the app to favorites apps(default is at 1)
|
||||||
* @param desktopfp: the desktop file path of app
|
* @param desktopFilePath: the desktop file path of app
|
||||||
*/
|
*/
|
||||||
void setAppToFavorites(const QString &desktopFilePath);
|
void setAppToFavorites(const QString &desktopFilePath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief AppInfoTable::setFavoritesTo
|
* @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
|
* set the favorites state of the app to num, you can also use to change the position of the app which is one of the Favorites Apps
|
||||||
* @param desktopfp: the desktop file path of app
|
* @param 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
|
* @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);
|
void setFavoritesOfApp(const QString &desktopFilePath, size_t num);
|
||||||
|
@ -88,14 +89,14 @@ public:
|
||||||
/**
|
/**
|
||||||
* @brief AppInfoTable::setAppToTop
|
* @brief AppInfoTable::setAppToTop
|
||||||
* set the app to top apps(default is at 1)
|
* set the app to top apps(default is at 1)
|
||||||
* @param desktopfp: desktop file path of app
|
* @param desktopFilePath: desktop file path of app
|
||||||
*/
|
*/
|
||||||
void setAppToTop(const QString &desktopFilePath);
|
void setAppToTop(const QString &desktopFilePath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief AppInfoTable::setAppTopTo
|
* @brief AppInfoTable::setAppTopTo
|
||||||
* set the top state of the app to num, you can also use to change the position of the app which is one of the Top Apps
|
* set the top state of the app to num, you can also use to change the position of the app which is one of the Top Apps
|
||||||
* @param desktopfp: the desktop file path of app
|
* @param 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
|
* @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);
|
void setTopOfApp(const QString &desktopFilePath, size_t num);
|
||||||
|
@ -125,7 +126,7 @@ public:
|
||||||
* @brief ApplicationInfo::tranWinIdToDesktopFilePath
|
* @brief ApplicationInfo::tranWinIdToDesktopFilePath
|
||||||
* find the desktop file path of the process which corresponds to the winId.
|
* find the desktop file path of the process which corresponds to the winId.
|
||||||
* it will find through tranPidToDesktopFp method first, and then use the winId if the desktop file can not be found by pid;
|
* it will find through tranPidToDesktopFp method first, and then use the winId if the desktop file can not be found by pid;
|
||||||
* @param winId: the winId of the process which need to get its desktop file path
|
* @param winId: the winId of the process which need to get its desktop file path(Only for X)
|
||||||
* @param desktopFilePath: the desktop file path of the process corresponding to pid
|
* @param desktopFilePath: the desktop file path of the process corresponding to pid
|
||||||
* @return bool:true if success,else false
|
* @return bool:true if success,else false
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1342,85 +1342,15 @@ bool AppDBManager::handleValueSet(const ApplicationInfoMap appInfoMap)
|
||||||
|
|
||||||
QString AppDBManager::tranPidToDesktopFp(uint pid)
|
QString AppDBManager::tranPidToDesktopFp(uint pid)
|
||||||
{
|
{
|
||||||
QFile file("/proc/" + QString::number(pid) + "/cmdline");
|
|
||||||
file.open(QFile::ReadOnly);
|
|
||||||
QList<QByteArray> cmdlist = file.readAll().split('\0');
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
cmdlist.removeAll("");
|
|
||||||
QString exePath;
|
|
||||||
for (int i = cmdlist.size() - 1; i >= 0; i--) {
|
|
||||||
if (cmdlist.at(i).startsWith("-") || cmdlist.at(i).contains("%")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!QUrl(cmdlist.at(i)).isRelative()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
exePath = cmdlist.at(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString desktopFilePath;
|
QString desktopFilePath;
|
||||||
if (exePath.isEmpty()) {
|
QDBusReply<QString> reply = m_processManagerInterface->call("GetDesktopFileByPid", pid);
|
||||||
qWarning() << "Can not find the desktop file by pid:" << pid << "because of empty exePath.";
|
if (reply.isValid()) {
|
||||||
return desktopFilePath;
|
desktopFilePath = reply.value();
|
||||||
}
|
qDebug() << "PID: " << pid << "Desktop file path: " << desktopFilePath;
|
||||||
|
|
||||||
QSqlQuery query(m_database);
|
|
||||||
query.setForwardOnly(true);
|
|
||||||
query.prepare("SELECT DESKTOP_FILE_PATH, EXEC FROM APPINFO WHERE EXEC LIKE :exePath");
|
|
||||||
query.bindValue(":exePath", "%" + exePath.section('/', -1) + "%");
|
|
||||||
|
|
||||||
if (query.exec()) {
|
|
||||||
QMap<QString, QString> execInfos;
|
|
||||||
while (query.next()) {
|
|
||||||
execInfos[query.value("DESKTOP_FILE_PATH").toString()] = query.value("EXEC").toString();
|
|
||||||
desktopFilePath = query.value("DESKTOP_FILE_PATH").toString();
|
|
||||||
}
|
|
||||||
//筛选后有多个结果时进一步过滤
|
|
||||||
if (execInfos.size() > 1) {
|
|
||||||
desktopFilePath.clear();
|
|
||||||
for (auto it = execInfos.constBegin(); it != execInfos.constEnd(); it++) {
|
|
||||||
if (it.key().startsWith(AUTOSTART_APP_DESKTOP_PATH + "/")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QStringList execlist = it.value().split(" ", QString::SkipEmptyParts);
|
|
||||||
for (QString &partOfExec : execlist) {
|
|
||||||
//remove the cmd option
|
|
||||||
if (partOfExec.contains("%")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//remove the " in cmd
|
|
||||||
if (partOfExec.contains("\"")) {
|
|
||||||
partOfExec.remove("\"");
|
|
||||||
}
|
|
||||||
//compare the binary path
|
|
||||||
if (partOfExec.contains("/") && exePath.contains("/")) {
|
|
||||||
if (partOfExec == exePath) {
|
|
||||||
desktopFilePath = it.key();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ((partOfExec == exePath.section("/", -1)) || (partOfExec.section("/", -1) == exePath)) {
|
|
||||||
desktopFilePath = it.key();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!desktopFilePath.isEmpty()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!desktopFilePath.isEmpty()) {
|
|
||||||
qDebug() << "PID: " << pid << "Desktop file path: " << desktopFilePath;
|
|
||||||
} else {
|
|
||||||
qWarning() << "Can not find the desktop file of" << exePath << "by pid:" << pid;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Fail to exec cmd" << query.lastQuery() << m_database.lastError();
|
qWarning() << "Cannot find desktop file by pid:" << pid << "because of " << reply.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
return desktopFilePath;
|
return desktopFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue