on xenial help sign in
change how icons are searched

a) try to find it the Icon as is b) prepend with Path if a Path variable is given c) fall back to the image://theme/ with just the icon name . Fixes: https://bugs.launchpad.net/bugs/1225186. Approved by PS Jenkins bot, Nick Dedekind.

commit29181afd5e9f39eade54cb3f60ee825caa3f808a authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 16 Sep 2013, 14:18 (13 years ago) parentd1296e348a51f6
3 files changed+18−11
plugins/Unity/Launcher/backend/launcherbackend.cpp+8−9 tests/plugins/Unity/Launcher/click-icon.svg tests/plugins/Unity/Launcher/launcherbackendtest.cpp+10−2
plugins/Unity/Launcher/backend/launcherbackend.cpp+8−9
@@ -132,11 +132,7 @@ QString LauncherBackend::icon(const QString &appId) const
132132 }
133133 }
134134
135− QFileInfo info(iconName);
136− if (info.exists()) {
137− return info.absoluteFilePath();
138− }
139− return "image://theme/" + iconName;
135+ return iconName;
140136}
141137
142138bool LauncherBackend::isPinned(const QString &appId) const
@@ -296,15 +292,18 @@ LauncherBackendItem* LauncherBackend::parseDesktopFile(const QString &desktopFil
296292{
297293 QSettings settings(desktopFile, QSettings::IniFormat);
298294
299−
300295 LauncherBackendItem* item = new LauncherBackendItem();
301296 item->desktopFile = desktopFile;
302297 item->displayName = settings.value("Desktop Entry/Name").toString();
303298
304− if (settings.contains("Desktop Entry/Path")) {
305− item->icon = settings.value("Desktop Entry/Path").toString() + "/" + settings.value("Desktop Entry/Icon").toString();
299+ QString iconString = settings.value("Desktop Entry/Icon").toString();
300+ QString pathString = settings.value("Desktop Entry/Path").toString();
301+ if (QFileInfo(iconString).exists()) {
302+ item->icon = QFileInfo(iconString).absoluteFilePath();
303+ } else if (QFileInfo(pathString + '/' + iconString).exists()) {
304+ item->icon = pathString + '/' + iconString;
306305 } else {
307− item->icon = settings.value("Desktop Entry/Icon").toString();
306+ item->icon = "image://theme/" + iconString;
308307 }
309308 item->pinned = false;
310309 return item;
tests/plugins/Unity/Launcher/click-icon.svgnew file

No changes to the content.

tests/plugins/Unity/Launcher/launcherbackendtest.cpp+10−2
@@ -26,6 +26,15 @@ class LauncherBackendTest : public QObject
2626 Q_OBJECT
2727
2828private Q_SLOTS:
29+
30+ void initTestCase()
31+ {
32+ // As we want to test absolute file paths in the .desktop file, we need to modify the
33+ // sample file and replace the path in there with the current build dir.
34+ QSettings settings(QDir::currentPath() + "/click-icon.desktop", QSettings::IniFormat);
35+ settings.setValue("Desktop Entry/Path", QDir::currentPath());
36+ }
37+
2938 void testFileNames()
3039 {
3140 LauncherBackend backend(false);
@@ -66,8 +75,7 @@ private Q_SLOTS:
6675 QTest::newRow("fallback on theme") << "abs-icon" << "image://theme//path/to/icon.png";
6776
6877 // Click packages have a relative icon path but an absolute path as a separate entry
69− // As we don't want to rely on a click app being installed for the test, accept it with the image://theme fallback
70− QTest::newRow("click package icon") << "click-icon" << "image://theme//path/to/some/click/app/click-icon.svg";
78+ QTest::newRow("click package icon") << "click-icon" << QDir::currentPath() + "/click-icon.svg";
7179 }
7280
7381 void testIcon() {