on xenial help sign in
add support for finding click package icons in launcher
6ed3ed9Michael Zanetti
plugins/Unity/Launcher/backend/launcherbackend.cpp+11−1
@@ -263,6 +263,7 @@ void LauncherBackend::syncToAccounts()
263
263
264QString LauncherBackend::findDesktopFile(const QString &appId) const
264QString LauncherBackend::findDesktopFile(const QString &appId) const
265{
265{
266+ qDebug() << "searching for desktop file for " << appId;
266 int dashPos = -1;
267 int dashPos = -1;
267 QString helper = appId;
268 QString helper = appId;
268
269
@@ -282,6 +283,7 @@ QString LauncherBackend::findDesktopFile(const QString &appId) const
282 Q_FOREACH(const QString &searchDir, searchDirs) {
283 Q_FOREACH(const QString &searchDir, searchDirs) {
283 QFileInfo fileInfo(QDir(searchDir), helper + ".desktop");
284 QFileInfo fileInfo(QDir(searchDir), helper + ".desktop");
284 if (fileInfo.exists()) {
285 if (fileInfo.exists()) {
286+ qDebug() << "found desktop file at" << fileInfo.absoluteFilePath();
285 return fileInfo.absoluteFilePath();
287 return fileInfo.absoluteFilePath();
286 }
288 }
287 }
289 }
@@ -289,18 +291,26 @@ QString LauncherBackend::findDesktopFile(const QString &appId) const
289 dashPos = helper.indexOf("-");
291 dashPos = helper.indexOf("-");
290 } while (dashPos != -1);
292 } while (dashPos != -1);
291
293
294+ qDebug() << "couldn't find the desktop file";
292 return QString();
295 return QString();
293}
296}
294
297
295LauncherBackendItem* LauncherBackend::parseDesktopFile(const QString &desktopFile) const
298LauncherBackendItem* LauncherBackend::parseDesktopFile(const QString &desktopFile) const
296{
299{
300+ qDebug() <<"parsing" << desktopFile;
297 QSettings settings(desktopFile, QSettings::IniFormat);
301 QSettings settings(desktopFile, QSettings::IniFormat);
298
302
299
303
300 LauncherBackendItem* item = new LauncherBackendItem();
304 LauncherBackendItem* item = new LauncherBackendItem();
301 item->desktopFile = desktopFile;
305 item->desktopFile = desktopFile;
302 item->displayName = settings.value("Desktop Entry/Name").toString();
306 item->displayName = settings.value("Desktop Entry/Name").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 {
303− item->icon = settings.value("Desktop Entry/Icon").toString();
312+ item->icon = settings.value("Desktop Entry/Icon").toString();
313+ }
304 item->pinned = false;
314 item->pinned = false;
305 return item;
315 return item;
306}
316}
tests/plugins/Unity/Launcher/CMakeLists.txt+9
@@ -57,3 +57,12 @@ foreach(DESKTOP_FILE ${DESKTOP_FILES})
57 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
57 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
58 )
58 )
59endforeach()
59endforeach()
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:
54 QCOMPARE(backend.isPinned("rel-icon"), true);
54 QCOMPARE(backend.isPinned("rel-icon"), true);
55 QCOMPARE(backend.isPinned("no-name"), false); // doesn't exist anymore!
55 QCOMPARE(backend.isPinned("no-name"), false); // doesn't exist anymore!
56 }
56 }
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+ }
57};
82};
58
83
59QTEST_GUILESS_MAIN(LauncherBackendTest)
84QTEST_GUILESS_MAIN(LauncherBackendTest)
tests/plugins/Unity/Launcher/rel-icon.desktop+1−1
@@ -1,3 +1,3 @@
1[Desktop Entry]
1[Desktop Entry]
2Name=Relative Icon
2Name=Relative Icon
3−Icon=rel-icon
3+Icon=rel-icon.svg
tests/plugins/Unity/Launcher/rel-icon.svgnew file

No changes to the content.