@@ -17,15 +17,19 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20+#include "AccountsService.h"
20#include "launcherbackend.h"
21#include "launcherbackend.h"
22#include <QDir>
23#include <QDir>
23#include <QFileInfo>
24#include <QFileInfo>
25−LauncherBackend::LauncherBackend(QObject *parent):
26+LauncherBackend::LauncherBackend(bool useStorage, QObject *parent):
26− QObject(parent)
27+ QObject(parent),
28− m_accounts = new AccountsService(this);
31+ m_accounts = new AccountsService(this);
29 setUser(qgetenv("USER"));
33 setUser(qgetenv("USER"));
@@ -55,11 +59,12 @@ void LauncherBackend::setStoredApplications(const QStringList &appIds)
56 // Are we dropping any pinned apps?
60 // Are we dropping any pinned apps?
57 auto needToSync = false;
61 auto needToSync = false;
62+ auto pinnedItems = QStringList();
58 for (int i = 0; i < m_storedApps.size(); i++) {
63 for (int i = 0; i < m_storedApps.size(); i++) {
59 if (m_storedApps[i].pinned) {
64 if (m_storedApps[i].pinned) {
60 auto found = false;
65 auto found = false;
61 for (int j = 0; j < appIds.size(); j++) {
66 for (int j = 0; j < appIds.size(); j++) {
62− auto fullAppId = desktopFile(appIds[j]);
67+ auto fullAppId = resolveAppId(appIds[j]);
63 if (m_storedApps[i].settings->fileName() == fullAppId) {
68 if (m_storedApps[i].settings->fileName() == fullAppId) {
64 found = true;
69 found = true;
@@ -67,15 +72,15 @@ void LauncherBackend::setStoredApplications(const QStringList &appIds)
68 if (!found) {
73 if (!found) {
69 needToSync = true;
74 needToSync = true;
76+ pinnedItems.append(m_storedApps[i].settings->fileName());
75 clearItems();
80 clearItems();
77 for (auto appId: appIds) {
82 for (auto appId: appIds) {
78− loadDesktopFile(appId);
83+ loadDesktopFile(appId, pinnedItems.contains(resolveAppId(appId)));
81 if (needToSync) {
86 if (needToSync) {
@@ -85,8 +90,12 @@ void LauncherBackend::setStoredApplications(const QStringList &appIds)
86QString LauncherBackend::desktopFile(const QString &appId) const
91QString LauncherBackend::desktopFile(const QString &appId) const
88− auto fileInfo = QFileInfo(QDir("/usr/share/applications"), appId);
93+ auto index = findItem(appId);
89− return fileInfo.canonicalFilePath();
94+ if (index < 0) {
97+ return resolveAppId(appId);
92QString LauncherBackend::displayName(const QString &appId) const
101QString LauncherBackend::displayName(const QString &appId) const
@@ -174,11 +183,17 @@ void LauncherBackend::triggerQuickListAction(const QString &appId, const QString
174 Q_UNUSED(quickListId)
183 Q_UNUSED(quickListId)
186+QString LauncherBackend::resolveAppId(const QString &appId) const
188+ QFileInfo fileInfo(QDir("/usr/share/applications"), appId);
189+ return fileInfo.absoluteFilePath();
177void LauncherBackend::syncFromAccounts()
192void LauncherBackend::syncFromAccounts()
179 auto appIds = QStringList();
194 auto appIds = QStringList();
181− if (m_user != "") {
196+ if (m_user != "" && m_accounts != nullptr) {
182 appIds = m_accounts->getUserProperty(m_user, "launcher-items").toStringList();
197 appIds = m_accounts->getUserProperty(m_user, "launcher-items").toStringList();
@@ -214,23 +229,24 @@ void LauncherBackend::syncToAccounts()
217− if (m_user != "") {
232+ if (m_user != "" && m_accounts != nullptr) {
218 m_accounts->setUserProperty(m_user, "launcher-items", QVariant(pinnedItems));
233 m_accounts->setUserProperty(m_user, "launcher-items", QVariant(pinnedItems));
222−bool LauncherBackend::loadDesktopFile(const QString &appId)
237+bool LauncherBackend::loadDesktopFile(const QString &appId, bool isPinned)
224 auto item = LauncherBackendItem();
239 auto item = LauncherBackendItem();
225− auto fullAppId = desktopFile(appId);
240+ auto fullAppId = resolveAppId(appId);
226 item.settings = new QSettings(fullAppId, QSettings::IniFormat);
241 item.settings = new QSettings(fullAppId, QSettings::IniFormat);
242+ item.pinned = isPinned;
227 m_storedApps.append(item);
243 m_storedApps.append(item);
228 return true; // QSettings doesn't really indicate a failure mode right now
244 return true; // QSettings doesn't really indicate a failure mode right now
231int LauncherBackend::findItem(const QString &appId) const
247int LauncherBackend::findItem(const QString &appId) const
233− auto fullAppId = desktopFile(appId);
249+ auto fullAppId = resolveAppId(appId);
234 for (int i = 0; i < m_storedApps.size(); i++) {
250 for (int i = 0; i < m_storedApps.size(); i++) {
235 if (m_storedApps[i].settings->fileName() == fullAppId) {
251 if (m_storedApps[i].settings->fileName() == fullAppId) {
236 return i;
252 return i;