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