on xenial help sign in
add support for finding click package icons in launcher
commit6ed3ed909fabe9118abca84da33b49e655957c80 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 9 Sep 2013, 18:30 (13 years ago) parent6fca692
6 files changed+50−2
plugins/Unity/Launcher/backend/launcherbackend.cpp+11−1 tests/plugins/Unity/Launcher/CMakeLists.txt+9 tests/plugins/Unity/Launcher/click-icon.desktop+4 tests/plugins/Unity/Launcher/launcherbackendtest.cpp+25 tests/plugins/Unity/Launcher/rel-icon.desktop+1−1 tests/plugins/Unity/Launcher/rel-icon.svg
plugins/Unity/Launcher/backend/launcherbackend.cpp+11−1
@@ -263,6 +263,7 @@ void LauncherBackend::syncToAccounts()
263263
264264QString LauncherBackend::findDesktopFile(const QString &appId) const
265265{
266+ qDebug() << "searching for desktop file for " << appId;
266267 int dashPos = -1;
267268 QString helper = appId;
268269
@@ -282,6 +283,7 @@ QString LauncherBackend::findDesktopFile(const QString &appId) const
282283 Q_FOREACH(const QString &searchDir, searchDirs) {
283284 QFileInfo fileInfo(QDir(searchDir), helper + ".desktop");
284285 if (fileInfo.exists()) {
286+ qDebug() << "found desktop file at" << fileInfo.absoluteFilePath();
285287 return fileInfo.absoluteFilePath();
286288 }
287289 }
@@ -289,18 +291,26 @@ QString LauncherBackend::findDesktopFile(const QString &appId) const
289291 dashPos = helper.indexOf("-");
290292 } while (dashPos != -1);
291293
294+ qDebug() << "couldn't find the desktop file";
292295 return QString();
293296}
294297
295298LauncherBackendItem* LauncherBackend::parseDesktopFile(const QString &desktopFile) const
296299{
300+ qDebug() <<"parsing" << desktopFile;
297301 QSettings settings(desktopFile, QSettings::IniFormat);
298302
299303
300304 LauncherBackendItem* item = new LauncherBackendItem();
301305 item->desktopFile = desktopFile;
302306 item->displayName = settings.value("Desktop Entry/Name").toString();
303− item->icon = settings.value("Desktop Entry/Icon").toString();
307+
308+ if (settings.contains("Desktop Entry/Path")) {
309+ qDebug() << "found a different specified path" << settings.value("Path");
310+ item->icon = settings.value("Desktop Entry/Path").toString() + "/" + settings.value("Desktop Entry/Icon").toString();
311+ } else {
312+ item->icon = settings.value("Desktop Entry/Icon").toString();
313+ }
304314 item->pinned = false;
305315 return item;
306316}
tests/plugins/Unity/Launcher/CMakeLists.txt+9
@@ -57,3 +57,12 @@ foreach(DESKTOP_FILE ${DESKTOP_FILES})
5757 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
5858 )
5959endforeach()
60+
61+# copy .svg files into build directory for shadow builds
62+file(GLOB DESKTOP_FILES *.svg)
63+
64+foreach(DESKTOP_FILE ${DESKTOP_FILES})
65+ file(COPY "${DESKTOP_FILE}"
66+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
67+ )
68+endforeach()
tests/plugins/Unity/Launcher/click-icon.desktopnew file+4
@@ -0,0 +1,4 @@
1+[Desktop Entry]
2+Name=Click Package Icon
3+Icon=click-icon.svg
4+Path=/path/to/some/click/app
tests/plugins/Unity/Launcher/launcherbackendtest.cpp+25
@@ -54,6 +54,31 @@ private Q_SLOTS:
5454 QCOMPARE(backend.isPinned("rel-icon"), true);
5555 QCOMPARE(backend.isPinned("no-name"), false); // doesn't exist anymore!
5656 }
57+
58+ void testIcon_data() {
59+ QTest::addColumn<QString>("appId");
60+ QTest::addColumn<QString>("expectedIcon");
61+
62+ // Needs to expand a relative icon to the absolute path
63+ QTest::newRow("relative icon path") << "rel-icon" << QDir::currentPath() + "/rel-icon.svg";
64+
65+ // In case an icon is not found on disk, it needs to fallback on image://theme/ for it
66+ QTest::newRow("fallback on theme") << "abs-icon" << "image://theme//path/to/icon.png";
67+
68+ // 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";
71+ }
72+
73+ void testIcon() {
74+ QFETCH(QString, appId);
75+ QFETCH(QString, expectedIcon);
76+
77+ LauncherBackend backend(false);
78+ backend.setStoredApplications(QStringList() << appId);
79+
80+ QCOMPARE(backend.icon(appId), expectedIcon);
81+ }
5782};
5883
5984QTEST_GUILESS_MAIN(LauncherBackendTest)
tests/plugins/Unity/Launcher/rel-icon.desktop+1−1
@@ -1,3 +1,3 @@
11[Desktop Entry]
22Name=Relative Icon
3−Icon=rel-icon
3+Icon=rel-icon.svg
tests/plugins/Unity/Launcher/rel-icon.svgnew file

No changes to the content.