on xenial help sign in
Grab launcher icon information from ubuntu-app-launch, not directly from desktop files.

Approved by: Michael Zanetti

commit680b7ae0aa89e037f435783880ad7822b053e25f authorMichael Terry <michael.terry@canonical.com> dateMon 24 Oct 2016, 11:33 (10 years ago) parent29c2ac2bd2a24c
17 files changed+115−294
CMakeLists.txt+1−1 debian/control+1 plugins/Unity/Launcher/CMakeLists.txt+8−3 plugins/Unity/Launcher/desktopfilehandler.cpp−155 plugins/Unity/Launcher/desktopfilehandler.h−56 plugins/Unity/Launcher/launchermodel.cpp+53−26 plugins/Unity/Launcher/launchermodel.h+17−8 tests/plugins/Greeter/Unity/Launcher/CMakeLists.txt−1 tests/plugins/Unity/Launcher/CMakeLists.txt+12−20 tests/plugins/Unity/Launcher/abs-icon.desktop → tests/plugins/Unity/Launcher/applications/abs-icon.desktop+1 tests/plugins/Unity/Launcher/click-icon.desktop → tests/plugins/Unity/Launcher/applications/click-icon.desktop+1 tests/plugins/Unity/Launcher/click-icon.svg → tests/plugins/Unity/Launcher/applications/click-icon.svg tests/plugins/Unity/Launcher/no-name.desktop → tests/plugins/Unity/Launcher/applications/no-name.desktop+1 tests/plugins/Unity/Launcher/rel-icon.desktop → tests/plugins/Unity/Launcher/applications/rel-icon.desktop+1 tests/plugins/Unity/Launcher/rel-icon.svg → tests/plugins/Unity/Launcher/applications/rel-icon.svg tests/plugins/Unity/Launcher/launchermodeltest.cpp+19−22 tests/plugins/Unity/Launcher/no-icon.desktop−2
CMakeLists.txt+1−1
@@ -63,7 +63,7 @@ pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
6363pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
6464pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
6565pkg_check_modules(GD3 REQUIRED gnome-desktop-3.0)
66−
66+pkg_check_modules(UAL REQUIRED ubuntu-app-launch-2)
6767pkg_check_modules(UBUNTUGESTURES REQUIRED UbuntuGestures)
6868
6969### Check UbuntuGestures private headers. No pkg-config (.pc) file is provided for them
debian/control+1
@@ -32,6 +32,7 @@ Build-Depends: cmake,
3232 libqt5svg5-dev,
3333 libqt5xmlpatterns5-dev,
3434 libsystemsettings-dev,
35+ libubuntu-app-launch2-dev,
3536 libubuntu-download-manager-common-dev,
3637 libubuntugestures5-dev (>= 1.3.2030),
3738 libubuntugestures5-private-dev (>= 1.3.2030),
plugins/Unity/Launcher/CMakeLists.txt+8−3
@@ -6,11 +6,16 @@ add_definitions(-DSM_BUSNAME=systemBus)
66include_directories(
77 ${CMAKE_CURRENT_SOURCE_DIR}
88 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
9− ${GSETTINGS_QT_INCLUDE_DIRS}
10− ${GLIB_INCLUDE_DIRS}
119 ${libunity8-private_SOURCE_DIR}
1210)
1311
12+include_directories(
13+ SYSTEM
14+ ${GSETTINGS_QT_INCLUDE_DIRS}
15+ ${GLIB_INCLUDE_DIRS}
16+ ${UAL_INCLUDE_DIRS}
17+ )
18+
1419set(QMLLAUNCHERPLUGIN_SRC
1520 plugin.cpp
1621 launchermodel.cpp
@@ -19,7 +24,6 @@ set(QMLLAUNCHERPLUGIN_SRC
1924 quicklistentry.cpp
2025 dbusinterface.cpp
2126 gsettings.cpp
22− desktopfilehandler.cpp
2327 asadapter.cpp
2428 ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsServiceDBusAdaptor.cpp
2529 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
@@ -38,6 +42,7 @@ target_link_libraries(UnityLauncher-qml
3842 unity8-private
3943 ${GSETTINGS_QT_LDFLAGS}
4044 ${GLIB_LIBRARIES}
45+ ${UAL_LIBRARIES}
4146 )
4247
4348qt5_use_modules(UnityLauncher-qml DBus Qml Gui)
plugins/Unity/Launcher/desktopfilehandler.cppdeleted−155
@@ -1,155 +0,0 @@
1−/*
2− * Copyright 2014 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Michael Zanetti <michael.zanetti@canonical.com>
18− */
19−
20−#include "desktopfilehandler.h"
21−
22−#include <QStringList>
23−#include <QStandardPaths>
24−#include <QDir>
25−#include <QSettings>
26−#include <QLocale>
27−
28−#include <libintl.h>
29−
30−DesktopFileHandler::DesktopFileHandler(const QString &appId, QObject *parent):
31− QObject(parent),
32− m_appId(appId)
33−{
34− load();
35−}
36−
37−QString DesktopFileHandler::appId() const
38−{
39− return m_appId;
40−}
41−
42−void DesktopFileHandler::setAppId(const QString &appId)
43−{
44− if (m_appId != appId) {
45− m_appId = appId;
46− load();
47− }
48−}
49−
50−QString DesktopFileHandler::filename() const
51−{
52− return m_filename;
53−}
54−
55−bool DesktopFileHandler::isValid() const
56−{
57− return !m_filename.isEmpty();
58−}
59−
60−void DesktopFileHandler::load()
61−{
62− m_filename.clear();
63−
64− if (m_appId.isEmpty()) {
65− return;
66− }
67−
68− int dashPos = -1;
69− QString helper = m_appId;
70−
71− QStringList searchDirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
72−#ifdef LAUNCHER_TESTING
73− searchDirs << QStringLiteral(".");
74−#endif
75−
76− QString path;
77− do {
78− if (dashPos != -1) {
79− helper.replace(dashPos, 1, '/');
80− }
81−
82− if (helper.contains('/')) {
83− path += helper.split('/').at(0) + '/';
84− helper.remove(QRegExp("^" + path));
85− }
86−
87− Q_FOREACH(const QString &searchDirName, searchDirs) {
88− QDir searchDir(searchDirName + "/" + path);
89− const QString desktop = QStringLiteral("*.desktop");
90− Q_FOREACH(const QString &desktopFile, searchDir.entryList(QStringList() << desktop)) {
91− if (desktopFile.startsWith(helper)) {
92− QFileInfo fileInfo(searchDir, desktopFile);
93− m_filename = fileInfo.absoluteFilePath();
94− return;
95− }
96− }
97− }
98−
99− dashPos = helper.indexOf('-');
100− } while (dashPos != -1);
101−}
102−
103−QString DesktopFileHandler::displayName() const
104−{
105− if (!isValid()) {
106− return QString();
107− }
108−
109− QSettings settings(m_filename, QSettings::IniFormat);
110− settings.setIniCodec("UTF-8");
111− settings.beginGroup(QStringLiteral("Desktop Entry"));
112−
113− // First try to find Name[xx_YY] and Name[xx] in .desktop file
114− const QString locale = QLocale().name();
115− const QStringList splitLocale = locale.split(QLatin1Char('_'));
116− const QString shortLocale = splitLocale.first();
117−
118− if (locale != shortLocale && settings.contains(QStringLiteral("Name[%1]").arg(locale))) {
119− return settings.value(QStringLiteral("Name[%1]").arg(locale)).toString();
120− }
121−
122− if (settings.contains(QStringLiteral("Name[%1]").arg(shortLocale))) {
123− return settings.value(QStringLiteral("Name[%1]").arg(shortLocale)).toString();
124− }
125−
126− // No translation found in desktop file. Get the untranslated one and have a go with gettext.
127− QString displayName = settings.value(QStringLiteral("Name")).toString();
128−
129− if (settings.contains(QStringLiteral("X-Ubuntu-Gettext-Domain"))) {
130− const QString domain = settings.value(QStringLiteral("X-Ubuntu-Gettext-Domain")).toString();
131− return dgettext(domain.toUtf8().constData(), displayName.toUtf8().constData());
132− }
133−
134− return displayName;
135−}
136−
137−QString DesktopFileHandler::icon() const
138−{
139− if (!isValid()) {
140− return QString();
141− }
142−
143− QSettings settings(m_filename, QSettings::IniFormat);
144− settings.setIniCodec("UTF-8");
145− settings.beginGroup(QStringLiteral("Desktop Entry"));
146− QString iconString = settings.value(QStringLiteral("Icon")).toString();
147− QString pathString = settings.value(QStringLiteral("Path")).toString();
148−
149− if (QFileInfo::exists(iconString)) {
150− return QFileInfo(iconString).absoluteFilePath();
151− } else if (QFileInfo::exists(pathString + '/' + iconString)) {
152− return pathString + '/' + iconString;
153− }
154− return "image://theme/" + iconString;
155−}
plugins/Unity/Launcher/desktopfilehandler.hdeleted−56
@@ -1,56 +0,0 @@
1−/*
2− * Copyright 2014 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Michael Zanetti <michael.zanetti@canonical.com>
18− */
19−
20−#ifndef DESKTOPFILEHANDLER_H
21−#define DESKTOPFILEHANDLER_H
22−
23−#include <QObject>
24−
25−/**
26− * When an object of this class is created or whenever setAppId(appId) is called,
27− * this will search for a .desktop file matching the give appId. If a file is
28− * found, isValid() will return true and the other methods return the contents
29− * of the .desktop file.
30− *
31− * Note that this class will consider the user's locale and do a best effort
32− * to return localized values.
33− */
34−
35−class DesktopFileHandler: public QObject
36−{
37− Q_OBJECT
38−public:
39− DesktopFileHandler(const QString &appId = QString(), QObject *parent = nullptr);
40−
41− QString appId() const;
42− void setAppId(const QString &appId);
43−
44− bool isValid() const;
45− QString filename() const;
46− QString displayName() const;
47− QString icon() const;
48−
49−private:
50− void load();
51−
52− QString m_appId;
53− QString m_filename;
54−};
55−
56−#endif
plugins/Unity/Launcher/launchermodel.cpp+53−26
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013-2014 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -12,24 +12,25 @@
1212 *
1313 * You should have received a copy of the GNU Lesser General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Michael Zanetti <michael.zanetti@canonical.com>
1815 */
1916
2017#include "launchermodel.h"
2118#include "launcheritem.h"
2219#include "gsettings.h"
23−#include "desktopfilehandler.h"
2420#include "dbusinterface.h"
2521#include "asadapter.h"
2622
23+#include <ubuntu-app-launch/appid.h>
24+#include <ubuntu-app-launch/application.h>
25+#include <ubuntu-app-launch/registry.h>
2726#include <unity/shell/application/ApplicationInfoInterface.h>
2827#include <unity/shell/application/MirSurfaceListInterface.h>
2928
3029#include <QDesktopServices>
3130#include <QDebug>
3231
32+namespace ual = ubuntu::app_launch;
33+
3334using namespace unity::shell::application;
3435
3536LauncherModel::LauncherModel(QObject *parent):
@@ -37,7 +38,8 @@ LauncherModel::LauncherModel(QObject *parent):
3738 m_settings(new GSettings(this)),
3839 m_dbusIface(new DBusInterface(this)),
3940 m_asAdapter(new ASAdapter()),
40− m_appManager(nullptr)
41+ m_appManager(nullptr),
42+ m_ualRegistry(std::make_shared<ual::Registry>())
4143{
4244 connect(m_dbusIface, &DBusInterface::countChanged, this, &LauncherModel::countChanged);
4345 connect(m_dbusIface, &DBusInterface::countVisibleChanged, this, &LauncherModel::countVisibleChanged);
@@ -157,16 +159,16 @@ void LauncherModel::pin(const QString &appId, int index)
157159 index = m_list.count();
158160 }
159161
160− DesktopFileHandler desktopFile(appId);
161− if (!desktopFile.isValid()) {
162− qWarning() << "Can't pin this application, there is no .desktop file available.";
162+ auto appInfo = getApplicationInfo(appId);
163+ if (!appInfo.valid) {
164+ qWarning() << "Can't pin application, appId not found:" << appId;
163165 return;
164166 }
165167
166168 beginInsertRows(QModelIndex(), index, index);
167169 LauncherItem *item = new LauncherItem(appId,
168− desktopFile.displayName(),
169− desktopFile.icon(),
170+ appInfo.name,
171+ appInfo.icon,
170172 this);
171173 item->setPinned(true);
172174 m_list.insert(index, item);
@@ -333,6 +335,32 @@ int LauncherModel::findApplication(const QString &appId)
333335 return -1;
334336}
335337
338+LauncherModel::AppInfo LauncherModel::getApplicationInfo(const QString &appId)
339+{
340+ AppInfo info;
341+
342+ ual::AppID ualAppId = ual::AppID::find(m_ualRegistry, appId.toStdString());
343+ if (ualAppId.empty()) {
344+ return info;
345+ }
346+
347+ std::shared_ptr<ual::Application> ualApp;
348+ try
349+ {
350+ ualApp = ual::Application::create(ualAppId, m_ualRegistry);
351+ }
352+ catch (std::runtime_error &e)
353+ {
354+ qWarning() << "Couldn't find application info for" << appId << "-" << e.what();
355+ return info;
356+ }
357+
358+ info.valid = true;
359+ info.name = QString::fromStdString(ualApp->info()->name());
360+ info.icon = QString::fromStdString(ualApp->info()->iconPath());
361+ return info;
362+}
363+
336364void LauncherModel::progressChanged(const QString &appId, int progress)
337365{
338366 const int idx = findApplication(appId);
@@ -380,11 +408,11 @@ void LauncherModel::countVisibleChanged(const QString &appId, bool countVisible)
380408 }
381409 } else {
382410 // Need to create a new LauncherItem and show the highlight
383− DesktopFileHandler desktopFile(appId);
384− if (countVisible && desktopFile.isValid()) {
411+ auto appInfo = getApplicationInfo(appId);
412+ if (countVisible && appInfo.valid) {
385413 LauncherItem *item = new LauncherItem(appId,
386− desktopFile.displayName(),
387− desktopFile.icon(),
414+ appInfo.name,
415+ appInfo.icon,
388416 this);
389417 item->setCountVisible(true);
390418 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
@@ -400,28 +428,28 @@ void LauncherModel::refresh()
400428 // First walk through all the existing items and see if we need to remove something
401429 QList<LauncherItem*> toBeRemoved;
402430 Q_FOREACH (LauncherItem* item, m_list) {
403− DesktopFileHandler desktopFile(item->appId());
404− if (!desktopFile.isValid()) {
405− // Desktop file not available for this app => drop it!
431+ auto appInfo = getApplicationInfo(item->appId());
432+ if (!appInfo.valid) {
433+ // Application no longer available => drop it!
406434 toBeRemoved << item;
407435 } else if (!m_settings->storedApplications().contains(item->appId())) {
408436 // Item not in settings any more => drop it!
409437 toBeRemoved << item;
410438 } else {
411439 int idx = m_list.indexOf(item);
412− item->setName(desktopFile.displayName());
440+ item->setName(appInfo.name);
413441 item->setPinned(item->pinned()); // update pinned text if needed
414442 item->setRunning(item->running());
415443 Q_EMIT dataChanged(index(idx), index(idx), {RoleName, RoleRunning});
416444
417445 const QString oldIcon = item->icon();
418− if (oldIcon == desktopFile.icon()) { // same icon file, perhaps different contents, simulate changing the icon name to force reload
446+ if (oldIcon == appInfo.icon) { // same icon file, perhaps different contents, simulate changing the icon name to force reload
419447 item->setIcon(QString());
420448 Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
421449 }
422450
423451 // now set the icon for real
424− item->setIcon(desktopFile.icon());
452+ item->setIcon(appInfo.icon);
425453 Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
426454 }
427455 }
@@ -452,15 +480,14 @@ void LauncherModel::refresh()
452480 if (itemIndex == -1) {
453481 // Need to add it. Just add it into the addedIndex to keep same ordering as the list
454482 // in the settings.
455− DesktopFileHandler desktopFile(entry);
456− if (!desktopFile.isValid()) {
457− qWarning() << "Couldn't find a .desktop file for" << entry << ". Skipping...";
483+ auto appInfo = getApplicationInfo(entry);
484+ if (!appInfo.valid) {
458485 continue;
459486 }
460487
461488 LauncherItem *item = new LauncherItem(entry,
462− desktopFile.displayName(),
463− desktopFile.icon(),
489+ appInfo.name,
490+ appInfo.icon,
464491 this);
465492 item->setPinned(true);
466493 beginInsertRows(QModelIndex(), addedIndex, addedIndex);
plugins/Unity/Launcher/launchermodel.h+17−8
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013-2014 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -12,14 +12,11 @@
1212 *
1313 * You should have received a copy of the GNU Lesser General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Michael Zanetti <michael.zanetti@canonical.com>
1815 */
1916
20−#ifndef LAUNCHERMODEL_H
21−#define LAUNCHERMODEL_H
17+#pragma once
2218
19+#include <memory>
2320#include <unity/shell/launcher/LauncherModelInterface.h>
2421#include <unity/shell/application/ApplicationManagerInterface.h>
2522
@@ -30,6 +27,12 @@ class GSettings;
3027class DBusInterface;
3128class ASAdapter;
3229
30+namespace ubuntu {
31+ namespace app_launch {
32+ class Registry;
33+ }
34+}
35+
3336using namespace unity::shell::launcher;
3437using namespace unity::shell::application;
3538
@@ -70,6 +73,13 @@ private:
7073
7174 void unpin(const QString &appId);
7275
76+ struct AppInfo {
77+ bool valid = false;
78+ QString name;
79+ QString icon;
80+ };
81+ AppInfo getApplicationInfo(const QString &appId);
82+
7383private Q_SLOTS:
7484 void countChanged(const QString &appId, int count);
7585 void countVisibleChanged(const QString &appId, bool count);
@@ -88,8 +98,7 @@ private:
8898 ASAdapter *m_asAdapter;
8999
90100 ApplicationManagerInterface *m_appManager;
101+ std::shared_ptr<ubuntu::app_launch::Registry> m_ualRegistry;
91102
92103 friend class LauncherModelTest;
93104};
94−
95−#endif // LAUNCHERMODEL_H
tests/plugins/Greeter/Unity/Launcher/CMakeLists.txt−1
@@ -10,7 +10,6 @@ include_directories(
1010
1111add_definitions(-DSM_BUSNAME=sessionBus)
1212add_definitions(-DSRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
13−add_definitions(-DLAUNCHER_TESTING)
1413
1514### LauncherModelASTest
1615add_executable(launchermodelastestExec
tests/plugins/Unity/Launcher/CMakeLists.txt+12−20
@@ -6,14 +6,18 @@ include_directories(
66 ${CMAKE_CURRENT_BINARY_DIR}
77 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
88 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher
9+ ${libunity8-private_SOURCE_DIR}
10+ )
11+
12+include_directories(
13+ SYSTEM
914 ${GSETTINGS_QT_INCLUDE_DIRS}
1015 ${GLIB_INCLUDE_DIRS}
11− ${libunity8-private_SOURCE_DIR}
16+ ${UAL_INCLUDE_DIRS}
1217 )
1318
1419add_definitions(-DSM_BUSNAME=sessionBus)
1520add_definitions(-DSRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
16−add_definitions(-DLAUNCHER_TESTING)
1721
1822### LauncherModelTest
1923add_executable(launchermodeltestExec
@@ -25,7 +29,6 @@ add_executable(launchermodeltestExec
2529 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/launcheritem.cpp
2630 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/quicklistmodel.cpp
2731 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/dbusinterface.cpp
28− ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/desktopfilehandler.cpp
2932 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/quicklistentry.cpp
3033 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
3134 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
@@ -37,11 +40,13 @@ target_link_libraries(launchermodeltestExec
3740 unity8-private
3841 ${GSETTINGS_QT_LDFLAGS}
3942 ${GLIB_LIBRARIES}
43+ ${UAL_LIBRARIES}
4044 )
4145add_dependencies(launchermodeltestExec mock-server)
4246qt5_use_modules(launchermodeltestExec Test Core DBus Xml Gui)
4347
4448add_unity8_unittest(LauncherModel dbus-test-runner
49+ ENVIRONMENT "XDG_DATA_HOME=${CMAKE_CURRENT_BINARY_DIR}"
4550 ARG_PREFIX "--parameter"
4651 ARGS
4752 --task $<TARGET_FILE:mock-server>
@@ -50,20 +55,7 @@ add_unity8_unittest(LauncherModel dbus-test-runner
5055 --wait-for org.freedesktop.Accounts
5156)
5257
53−# copy .desktop files into build directory for shadow builds
54−file(GLOB DESKTOP_FILES *.desktop)
55−
56−foreach(DESKTOP_FILE ${DESKTOP_FILES})
57− file(COPY "${DESKTOP_FILE}"
58− DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
59− )
60−endforeach()
61−
62−# copy .svg files into build directory for shadow builds
63−file(GLOB DESKTOP_FILES *.svg)
64−
65−foreach(DESKTOP_FILE ${DESKTOP_FILES})
66− file(COPY "${DESKTOP_FILE}"
67− DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
68− )
69−endforeach()
58+# copy sample application files into build directory for shadow builds
59+file(COPY applications
60+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
61+ )
tests/plugins/Unity/Launcher/abs-icon.desktop → tests/plugins/Unity/Launcher/applications/abs-icon.desktoprenamed+1
@@ -1,3 +1,4 @@
11[Desktop Entry]
2+Type=Application
23Name=Absolute Icon
34Icon=/path/to/icon.png
tests/plugins/Unity/Launcher/click-icon.desktop → tests/plugins/Unity/Launcher/applications/click-icon.desktoprenamed+1
@@ -1,4 +1,5 @@
11[Desktop Entry]
2+Type=Application
23Name=Click Package Icon
34Icon=click-icon.svg
45Path=/path/to/some/click/app
tests/plugins/Unity/Launcher/click-icon.svg → tests/plugins/Unity/Launcher/applications/click-icon.svgrenamed

The content is the same.

tests/plugins/Unity/Launcher/no-name.desktop → tests/plugins/Unity/Launcher/applications/no-name.desktoprenamed+1
@@ -1,2 +1,3 @@
11[Desktop Entry]
2+Type=Application
23Icon=no-name
tests/plugins/Unity/Launcher/rel-icon.desktop → tests/plugins/Unity/Launcher/applications/rel-icon.desktoprenamed+1
@@ -1,3 +1,4 @@
11[Desktop Entry]
2+Type=Application
23Name=Relative Icon
34Icon=rel-icon.svg
tests/plugins/Unity/Launcher/rel-icon.svg → tests/plugins/Unity/Launcher/applications/rel-icon.svgrenamed

The content is the same.

tests/plugins/Unity/Launcher/launchermodeltest.cpp+19−22
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013-2015 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -12,9 +12,6 @@
1212 *
1313 * You should have received a copy of the GNU Lesser General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Michael Zanetti <michael.zanetti@canonical.com>
1815 */
1916
2017// unity-api
@@ -177,7 +174,7 @@ private Q_SLOTS:
177174 appManager->addApplication(new MockApp("abs-icon"));
178175 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
179176
180− appManager->addApplication(new MockApp("no-icon"));
177+ appManager->addApplication(new MockApp("rel-icon"));
181178 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
182179
183180 launcherModel->m_settings->setStoredApplications(QStringList());
@@ -199,6 +196,10 @@ private Q_SLOTS:
199196 QString::fromUtf8(g_get_user_name()));
200197 QVERIFY(removeReply.isValid());
201198 QCOMPARE(removeReply.value(), true);
199+
200+ // Some tests move the directory, so lets move it back if so.
201+ // But this will usually fail.
202+ QFile::rename("applications.old", "applications");
202203 }
203204
204205 void testMove() {
@@ -331,7 +332,7 @@ private Q_SLOTS:
331332
332333 void testApplicationRunning() {
333334 launcherModel->pin("abs-icon");
334− launcherModel->pin("no-icon");
335+ launcherModel->pin("rel-icon");
335336
336337 QCOMPARE(launcherModel->get(0)->running(), true);
337338 QCOMPARE(launcherModel->get(1)->running(), true);
@@ -340,7 +341,7 @@ private Q_SLOTS:
340341 QCOMPARE(launcherModel->get(0)->running(), false);
341342 QCOMPARE(launcherModel->get(1)->running(), true);
342343
343− appManager->stopApplication("no-icon");
344+ appManager->stopApplication("rel-icon");
344345 QCOMPARE(launcherModel->get(0)->running(), false);
345346 QCOMPARE(launcherModel->get(1)->running(), false);
346347 }
@@ -355,7 +356,7 @@ private Q_SLOTS:
355356 QCOMPARE(launcherModel->get(0)->focused(), true);
356357 QCOMPARE(launcherModel->get(1)->focused(), false);
357358
358− appManager->focusApplication("no-icon");
359+ appManager->focusApplication("rel-icon");
359360 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
360361 QCOMPARE(launcherModel->get(0)->focused(), false);
361362 QCOMPARE(launcherModel->get(1)->focused(), true);
@@ -377,8 +378,8 @@ private Q_SLOTS:
377378 QCOMPARE(launcherModel->rowCount(), 2);
378379
379380 // stop the second one keeping it pinned so that it doesn't go away
380− launcherModel->pin("no-icon");
381− appManager->stopApplication("no-icon");
381+ launcherModel->pin("rel-icon");
382+ appManager->stopApplication("rel-icon");
382383
383384 // find the first Quit item, should be there
384385 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
@@ -407,7 +408,7 @@ private Q_SLOTS:
407408 // first app should be gone...
408409 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
409410 // ... the second app (now at index 0) should still be there, pinned and stopped
410− QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("no-icon"));
411+ QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("rel-icon"));
411412 QCOMPARE(launcherModel->get(0)->pinned(), true);
412413 QCOMPARE(launcherModel->get(0)->running(), false);
413414 }
@@ -602,17 +603,16 @@ private Q_SLOTS:
602603
603604 // pin both apps
604605 launcherModel->pin("abs-icon");
605− launcherModel->pin("no-icon");
606+ launcherModel->pin("rel-icon");
606607 // close both apps
607608 appManager->removeApplication(0);
608609 appManager->removeApplication(0);
609610
610611 // "delete" the .desktop files
611− QString oldCurrent = QDir::currentPath();
612612 if (deleted) {
613613 // In testing mode, the launcher searches the current dir for the sample .desktop file
614− // We can make that fail by changing the current dir
615− QDir::setCurrent("..");
614+ // We can make that fail by moving the applications dir
615+ QFile::rename("applications", "applications.old");
616616 }
617617
618618 // Call refresh
@@ -623,9 +623,6 @@ private Q_SLOTS:
623623 QCOMPARE(reply.isValid(), true);
624624
625625 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
626−
627− // Restoring current dir
628− QDir::setCurrent(oldCurrent);
629626 }
630627
631628 void testSettings() {
@@ -637,7 +634,7 @@ private Q_SLOTS:
637634
638635 // pin both apps
639636 launcherModel->pin("abs-icon");
640− launcherModel->pin("no-icon");
637+ launcherModel->pin("rel-icon");
641638 QCOMPARE(spy.count(), 0);
642639
643640 // Now settings should have 2 apps
@@ -659,9 +656,9 @@ private Q_SLOTS:
659656 QCOMPARE(launcherModel->rowCount(), 1);
660657
661658 // Add them back but in reverse order
662− settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
659+ settings->simulateDConfChanged(QStringList() << "rel-icon" << "abs-icon");
663660 QCOMPARE(launcherModel->rowCount(), 2);
664− QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
661+ QCOMPARE(launcherModel->get(0)->appId(), QString("rel-icon"));
665662 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
666663 QCOMPARE(spy.count(), 2);
667664 }
@@ -671,7 +668,7 @@ private Q_SLOTS:
671668 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
672669
673670 int oldCount = launcherModel->rowCount();
674− appManager->addApplication(new MockApp("rel-icon"));
671+ appManager->addApplication(new MockApp("click-icon"));
675672 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
676673 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
677674 }
tests/plugins/Unity/Launcher/no-icon.desktopdeleted−2
@@ -1,2 +0,0 @@
1−[Desktop Entry]
2−Name=No Icon