2 * Copyright (C) 2013 Canonical, Ltd.
5 * Michael Terry <michael.terry@canonical.com>
6 * Michael Zanetti <michael.zanetti@canonical.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 3.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include "AccountsService.h"
22#include "launcherbackend.h"
27LauncherBackend::LauncherBackend(bool useStorage, QObject *parent):
32 m_accounts = new AccountsService(this);
34 setUser(qgetenv("USER"));
37LauncherBackend::~LauncherBackend()
42void LauncherBackend::clearItems()
44 for (LauncherBackendItem &app: m_storedApps) {
50QStringList LauncherBackend::storedApplications() const
52 auto files = QStringList();
53 for (const LauncherBackendItem &app: m_storedApps) {
54 files << app.settings->fileName();
59void LauncherBackend::setStoredApplications(const QStringList &appIds)
61 // Record all existing pinned apps, so we can notice them in new list
62 auto pinnedItems = QStringList();
63 for (LauncherBackendItem &app: m_storedApps) {
65 pinnedItems.append(app.settings->fileName());
71 for (const QString &appId: appIds) {
72 loadDesktopFile(appId, pinnedItems.contains(desktopFile(appId)));
78QString LauncherBackend::desktopFile(const QString &appId) const
80 QFileInfo fileInfo(QDir("/usr/share/applications"), appId);
81 return fileInfo.absoluteFilePath();
84QString LauncherBackend::displayName(const QString &appId) const
86 auto desktopFile = parseDesktopFile(appId);
87 auto displayName = desktopFile->value("Desktop Entry/Name").toString();
92QString LauncherBackend::icon(const QString &appId) const
94 auto desktopFile = parseDesktopFile(appId);
95 auto iconName = desktopFile->value("Desktop Entry/Icon").toString();
98 if (!iconName.isEmpty()) {
99 QFileInfo iconFileInfo(iconName);
100 if (iconFileInfo.isRelative()) {
101 iconName = "image://gicon/" + iconName;
108bool LauncherBackend::isPinned(const QString &appId) const
110 auto index = findItem(appId);
114 return m_storedApps[index].pinned;
118void LauncherBackend::setPinned(const QString &appId, bool pinned)
120 auto index = findItem(appId);
121 if (index >= 0 && !m_storedApps[index].pinned) {
122 m_storedApps[index].pinned = pinned;
127QList<QuickListEntry> LauncherBackend::quickList(const QString &appId) const
129 // TODO: Get static (from .desktop file) and dynamic (from the app itself)
130 // entries and return them here. Frontend related entries (like "Pin to launcher")
131 // don't matter here. This is just the backend part.
132 // TODO: emit quickListChanged() when the dynamic part changes
134 return QList<QuickListEntry>();
137int LauncherBackend::progress(const QString &appId) const
139 // TODO: Return value for progress emblem.
140 // TODO: emit progressChanged() when this value changes.
145int LauncherBackend::count(const QString &appId) const
147 // TODO: Return value for count emblem.
148 // TODO: emit countChanged() when this value changes.
153void LauncherBackend::setUser(const QString &username)
159void LauncherBackend::triggerQuickListAction(const QString &appId, const QString &quickListId)
161 // TODO: execute the given quicklist action
163 Q_UNUSED(quickListId)
166void LauncherBackend::syncFromAccounts()
168 auto appIds = QStringList();
170 if (m_user != "" && m_accounts != nullptr) {
171 appIds = m_accounts->getUserProperty(m_user, "launcher-items").toStringList();
174 // TODO: load default pinned ones from default config, instead of hardcoding here...
175 if (appIds.isEmpty()) {
177 "phone-app.desktop" <<
178 "camera-app.desktop" <<
179 "gallery-app.desktop" <<
180 "facebook-webapp.desktop" <<
181 "webbrowser-app.desktop" <<
182 "twitter-webapp.desktop" <<
183 "gmail-webapp.desktop" <<
184 "ubuntu-weather-app.desktop" <<
185 "notes-app.desktop" <<
186 "calendar-app.desktop";
189 setStoredApplications(appIds);
191 // Mark all apps as pinned (since we just refreshed the set)
192 for (LauncherBackendItem &app: m_storedApps) {
197void LauncherBackend::syncToAccounts()
199 auto pinnedItems = QStringList();
200 for (LauncherBackendItem &app: m_storedApps) {
202 pinnedItems.append(app.settings->fileName());
206 if (m_user != "" && m_accounts != nullptr) {
207 m_accounts->setUserProperty(m_user, "launcher-items", QVariant(pinnedItems));
211QSettings *LauncherBackend::parseDesktopFile(const QString &appId) const
213 auto fullAppId = desktopFile(appId);
214 return new QSettings(fullAppId, QSettings::IniFormat);
217bool LauncherBackend::loadDesktopFile(const QString &appId, bool isPinned)
219 auto item = LauncherBackendItem();
220 item.settings = parseDesktopFile(appId);
221 item.pinned = isPinned;
222 m_storedApps.append(item);
223 return true; // QSettings doesn't really indicate a failure mode right now
226int LauncherBackend::findItem(const QString &appId) const
228 auto fullAppId = desktopFile(appId);
229 for (int i = 0; i < m_storedApps.size(); ++i) {
230 if (m_storedApps[i].settings->fileName() == fullAppId) {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list