@@ -25,6 +25,7 @@
25#include <QDBusArgument>
25#include <QDBusArgument>
26#include <QFileInfo>
26#include <QFileInfo>
27#include <QGSettings>
27#include <QGSettings>
29class LauncherBackendItem
30class LauncherBackendItem
@@ -73,6 +74,19 @@ void LauncherBackend::setStoredApplications(const QStringList &appIds)
75 m_storedApps = appIds;
76 m_storedApps = appIds;
77+ Q_FOREACH(const QString &appId, appIds) {
78+ if (!m_itemCache.contains(appId)) {
79+ QString df = findDesktopFile(appId);
81+ LauncherBackendItem *item = parseDesktopFile(df);
82+ m_itemCache.insert(appId, item);
84+ // Cannot find any data for that app... ignoring it.
85+ qWarning() << "cannot find desktop file for" << appId << ". discarding app.";
86+ m_storedApps.removeAll(appId);
76 syncToAccounts();
90 syncToAccounts();
@@ -199,7 +213,7 @@ void LauncherBackend::syncFromAccounts()
200 m_storedApps.clear();
214 m_storedApps.clear();
202− if (m_accounts && m_user.isEmpty()) {
216+ if (m_accounts && !m_user.isEmpty()) {
203 QVariant variant = m_accounts->getUserProperty(m_user, "launcher-items");
217 QVariant variant = m_accounts->getUserProperty(m_user, "launcher-items");
204 apps = qdbus_cast<QList<QVariantMap>>(variant.value<QDBusArgument>());
218 apps = qdbus_cast<QList<QVariantMap>>(variant.value<QDBusArgument>());
205 defaults = isDefaultsItem(apps);
219 defaults = isDefaultsItem(apps);
@@ -248,14 +262,32 @@ QString LauncherBackend::findDesktopFile(const QString &appId) const
248 int dashPos = -1;
262 int dashPos = -1;
249 QString helper = appId;
263 QString helper = appId;
265+ QStringList searchDirs;
266+ searchDirs << "/usr/share/applications";
268+// FIXME: Right now the appId can be (or rather is) a full path
269+// to a .desktop file. This will change in the future.
270+// Once the ApplicationManager has been switched over to use appIds,
271+// remove this chop() and enable the ifdef to only search the current
272+// working dir for testing. Also, this is the place to add the search
273+// paths for click apps in the next step.
274+ if (helper.endsWith(".desktop")) {
277+//#ifdef LAUNCHER_TESTING
252 if (dashPos != -1) {
282 if (dashPos != -1) {
253 helper = helper.replace(dashPos, 1, '/');
283 helper = helper.replace(dashPos, 1, '/');
286+ Q_FOREACH(const QString &searchDir, searchDirs) {
256− QFileInfo fileInfo(QDir("/usr/share/applications"), helper);
287+ QFileInfo fileInfo(QDir(searchDir), helper + ".desktop");
257− if (fileInfo.exists()) {
288+ if (fileInfo.exists()) {
258− return fileInfo.absoluteFilePath();
289+ return fileInfo.absoluteFilePath();
261 dashPos = helper.indexOf("-");
293 dashPos = helper.indexOf("-");