@@ -25,6 +25,7 @@
2525#include <QDBusArgument>
2626#include <QFileInfo>
2727#include <QGSettings>
28+#include <QDebug>
2829
2930class LauncherBackendItem
3031{
@@ -73,6 +74,19 @@ void LauncherBackend::setStoredApplications(const QStringList &appIds)
7374 }
7475 }
7576 m_storedApps = appIds;
77+ Q_FOREACH(const QString &appId, appIds) {
78+ if (!m_itemCache.contains(appId)) {
79+ QString df = findDesktopFile(appId);
80+ if (!df.isEmpty()) {
81+ LauncherBackendItem *item = parseDesktopFile(df);
82+ m_itemCache.insert(appId, item);
83+ } else {
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);
87+ }
88+ }
89+ }
7690 syncToAccounts();
7791}
7892
@@ -199,7 +213,7 @@ void LauncherBackend::syncFromAccounts()
199213
200214 m_storedApps.clear();
201215
202− if (m_accounts && m_user.isEmpty()) {
216+ if (m_accounts && !m_user.isEmpty()) {
203217 QVariant variant = m_accounts->getUserProperty(m_user, "launcher-items");
204218 apps = qdbus_cast<QList<QVariantMap>>(variant.value<QDBusArgument>());
205219 defaults = isDefaultsItem(apps);
@@ -248,14 +262,32 @@ QString LauncherBackend::findDesktopFile(const QString &appId) const
248262 int dashPos = -1;
249263 QString helper = appId;
250264
265+ QStringList searchDirs;
266+ searchDirs << "/usr/share/applications";
267+
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")) {
275+ helper.chop(8);
276+ }
277+//#ifdef LAUNCHER_TESTING
278+ searchDirs << "";
279+//#endif
280+
251281 do {
252282 if (dashPos != -1) {
253283 helper = helper.replace(dashPos, 1, '/');
254284 }
255285
256− QFileInfo fileInfo(QDir("/usr/share/applications"), helper);
257− if (fileInfo.exists()) {
258− return fileInfo.absoluteFilePath();
286+ Q_FOREACH(const QString &searchDir, searchDirs) {
287+ QFileInfo fileInfo(QDir(searchDir), helper + ".desktop");
288+ if (fileInfo.exists()) {
289+ return fileInfo.absoluteFilePath();
290+ }
259291 }
260292
261293 dashPos = helper.indexOf("-");