perf(app-database-service):optimize the logic of the method which is used to find desktop file.
This commit is contained in:
parent
597be83dac
commit
a8c400cdb0
|
@ -1426,10 +1426,18 @@ QString AppDBManager::tranPidToDesktopFp(uint pid)
|
|||
if (cmdlist.at(i).startsWith("-") || cmdlist.at(i).contains("%")) {
|
||||
continue;
|
||||
}
|
||||
if (!QUrl(cmdlist.at(i)).isRelative()) {
|
||||
continue;
|
||||
}
|
||||
exePath = cmdlist.at(i);
|
||||
break;
|
||||
}
|
||||
|
||||
QString desktopFilePath;
|
||||
if (exePath.isEmpty()) {
|
||||
qWarning() << "Can not find the desktop file by pid:" << pid << "because of empty exePath.";
|
||||
return desktopFilePath;
|
||||
}
|
||||
|
||||
QSqlQuery query(m_database);
|
||||
query.setForwardOnly(true);
|
||||
|
@ -1535,43 +1543,45 @@ QString AppDBManager::tranWinIdToDesktopFilePath(const QDBusVariant &id)
|
|||
KWindowInfo info(id.variant().toULongLong(), NET::Properties(), NET::WM2AllProperties);
|
||||
QString desktopFilePath;
|
||||
if (info.valid()) {
|
||||
desktopFilePath = this->tranPidToDesktopFp(info.pid());
|
||||
if (desktopFilePath.isEmpty()) {
|
||||
QString classClass = info.windowClassClass(); //the 2nd part of WM_CLASS, specified by the application writer
|
||||
QSqlQuery query(m_database);
|
||||
query.setForwardOnly(true);
|
||||
query.prepare("SELECT DESKTOP_FILE_PATH, START_UP_WMCLASS FROM APPINFO WHERE EXEC LIKE :classClass OR DESKTOP_FILE_PATH LIKE :classClass OR LOWER(START_UP_WMCLASS)=:windowClassClass");
|
||||
query.bindValue(":classClass", "%" + classClass + "%");
|
||||
query.bindValue(":windowClassClass", classClass.toLower());
|
||||
QString classClass = info.windowClassClass(); //the 2nd part of WM_CLASS, specified by the application writer
|
||||
QSqlQuery query(m_database);
|
||||
query.setForwardOnly(true);
|
||||
query.prepare("SELECT DESKTOP_FILE_PATH, START_UP_WMCLASS FROM APPINFO WHERE EXEC LIKE :classClass OR DESKTOP_FILE_PATH LIKE :classClass "
|
||||
"OR LOWER(START_UP_WMCLASS)=:windowClassClass OR LOWER(LOCAL_NAME)=:windowClassClass");
|
||||
query.bindValue(":classClass", "%" + classClass + "%");
|
||||
query.bindValue(":windowClassClass", classClass.toLower());
|
||||
|
||||
if (query.exec()) {
|
||||
QMap<QString, QString> wmClassInfos;
|
||||
while (query.next()) {
|
||||
wmClassInfos[query.value("DESKTOP_FILE_PATH").toString()] = query.value("START_UP_WMCLASS").toString();
|
||||
desktopFilePath = query.value("DESKTOP_FILE_PATH").toString();
|
||||
}
|
||||
//筛选后有多个结果时进一步过滤
|
||||
if (wmClassInfos.size() > 1) {
|
||||
desktopFilePath.clear();
|
||||
for (auto it = wmClassInfos.constBegin(); it != wmClassInfos.constEnd(); it++) {
|
||||
if (it.key().startsWith(AUTOSTART_APP_DESKTOP_PATH)) {
|
||||
continue;
|
||||
}
|
||||
if (it.key().section("/", -1) == (classClass + ".desktop") || it.value().toLower() == classClass.toLower()) {
|
||||
desktopFilePath = it.key();
|
||||
break;
|
||||
}
|
||||
if (query.exec()) {
|
||||
QMap<QString, QString> wmClassInfos;
|
||||
while (query.next()) {
|
||||
wmClassInfos[query.value("DESKTOP_FILE_PATH").toString()] = query.value("START_UP_WMCLASS").toString();
|
||||
desktopFilePath = query.value("DESKTOP_FILE_PATH").toString();
|
||||
}
|
||||
//筛选后有多个结果时进一步过滤
|
||||
if (wmClassInfos.size() > 1) {
|
||||
desktopFilePath.clear();
|
||||
for (auto it = wmClassInfos.constBegin(); it != wmClassInfos.constEnd(); it++) {
|
||||
if (it.key().startsWith(AUTOSTART_APP_DESKTOP_PATH)) {
|
||||
continue;
|
||||
}
|
||||
if (it.key().section("/", -1) == (classClass + ".desktop") || it.value().toLower() == classClass.toLower()) {
|
||||
desktopFilePath = it.key();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!desktopFilePath.isEmpty()) {
|
||||
qDebug() << "WId:" << id.variant() << "Classclass of window:" << classClass << "Desktop file path:" << desktopFilePath;
|
||||
} else {
|
||||
qWarning() << "Can not find the desktop file by windowClassClass:" << classClass;
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Fail to exec cmd" << query.lastQuery();
|
||||
}
|
||||
|
||||
if (!desktopFilePath.isEmpty()) {
|
||||
qDebug() << "WId:" << id.variant() << "Classclass of window:" << classClass << "Desktop file path:" << desktopFilePath;
|
||||
} else {
|
||||
qWarning() << "Can not find the desktop file by windowClassClass:" << classClass;
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Fail to exec cmd" << query.lastQuery();
|
||||
}
|
||||
|
||||
if (desktopFilePath.isEmpty()) {
|
||||
desktopFilePath = this->tranPidToDesktopFp(info.pid());
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Cannot find desktop flie by WinId:" << id.variant() << "it is invalid" << id.variant().toULongLong();
|
||||
|
|
Loading…
Reference in New Issue