Skip to content

Commit 312aa47

Browse files
committed
feat: improve the logic of obtaining icons
1. Added support for fetching icons from ApplicationManager DBus interface 2. Special handling for Linglong containerized apps where executable path isn't accessible 3. Added fallback to default icon when theme icon not available 4. Implemented DBus communication to get app icons from desktop entry 5. Added necessary header includes and DBus constants The changes were necessary because: 1. Linglong apps run in containers making their executable paths inaccessible 2. Previous implementation couldn't properly display icons for containerized apps 3. New solution uses ApplicationManager DBus interface as reliable icon source 4. Maintains backward compatibility with regular applications feat: 改进玲珑应用的图标处理 1. 添加从ApplicationManager DBus接口获取图标支持 2. 对玲珑容器化应用特殊处理,其可执行路径无法访问 3. 添加主题图标不可用时的默认图标回退机制 4. 实现通过DBus从桌面条目获取应用图标 5. 添加必要的头文件包含和DBus常量 修改原因: 1. 玲珑应用运行在容器中导致其可执行路径无法访问 2. 原实现无法正确显示容器化应用的图标 3. 新方案使用ApplicationManager DBus接口作为可靠图标来源 4. 保持对常规应用的向后兼容性 pms: BUG-315995 pms: BUG-281765
1 parent e10e61a commit 312aa47

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/widgets/inhibitwarnview.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@
99
#include <DSpinner>
1010
#include <DLabel>
1111
#include <DToolTip>
12+
#include <DSGApplication>
13+
#include <DUtil>
14+
#include <DDBusSender>
1215

1316
#include <QHBoxLayout>
1417

1518
DWIDGET_USE_NAMESPACE
1619

20+
#define AMDBUS_SERVICE "org.desktopspec.ApplicationManager1"
21+
#define AMDBUS_PATH_APP_PREFIX "/org/desktopspec/ApplicationManager1"
22+
#define AMDBUS_APP_INTERFACE "org.desktopspec.ApplicationManager1.Application"
23+
24+
1725
const int ButtonWidth = 200;
1826
const int ButtonHeight = 64;
1927
const int FIXED_INHIBITOR_WIDTH = 328;
@@ -92,10 +100,28 @@ void InhibitWarnView::setInhibitorList(const QList<InhibitorData> &list)
92100
#else
93101
QFileInfo executable_info(QFile::readLink(QString("/proc/%1/exe").arg(inhibitor.pid)));
94102
#endif
95-
96-
if (executable_info.exists()) {
97-
icon = QIcon::fromTheme(executable_info.fileName());
103+
// 玲珑应用的exe指向的路径是容器内的路径,在容器外无法访问,因此不能判断文件是否存在
104+
QString iconName = executable_info.fileName();
105+
#ifdef ENABLE_DSS_SNIPE
106+
if (!QIcon::hasThemeIcon(iconName)) {
107+
const auto appId = Dtk::Core::DSGApplication::getId(inhibitor.pid);
108+
const auto amDBusAppPath = QString("%1/%2").arg(AMDBUS_PATH_APP_PREFIX, DUtil::escapeToObjectPath(appId));
109+
QDBusReply<QDBusVariant> reply = DDBusSender()
110+
.service(AMDBUS_SERVICE)
111+
.path(amDBusAppPath)
112+
.interface(AMDBUS_APP_INTERFACE)
113+
.property("Icons")
114+
.get();
115+
if (reply.isValid()) {
116+
auto ret = qdbus_cast<QMap<QString, QString>>(reply.value().variant());
117+
iconName = ret.value("Desktop Entry");
118+
} else {
119+
qCWarning(DDE_SHELL) << "Get icon error:" << reply.error().message();
120+
}
98121
}
122+
#endif
123+
icon = QIcon::fromTheme(iconName);
124+
99125
} else {
100126
icon = QIcon::fromTheme(inhibitor.icon, QIcon::fromTheme("application-x-desktop"));
101127
}

0 commit comments

Comments
 (0)