2 * Copyright (C) 2013 Canonical, Ltd.
5 * Michael Zanetti <michael.zanetti@canonical.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include "launcherbackend.h"
25LauncherBackend::LauncherBackendItem::~LauncherBackendItem()
30LauncherBackend::LauncherBackend(QObject *parent):
33 m_accounts = new AccountsService(this);
34 setUser(qgetenv("USER"));
37LauncherBackend::~LauncherBackend()
42QStringList LauncherBackend::storedApplications() const
44 auto files = QStringList();
45 for (int i = 0; i < m_storedApps.size(); i++) {
46 files << m_storedApps[i].settings->fileName();
51void LauncherBackend::setStoredApplications(const QStringList &appIds)
53 // Are we dropping any pinned apps?
54 auto needToSync = false;
55 for (int i = 0; i < m_storedApps.size(); i++) {
56 if (m_storedApps[i].pinned) {
58 for (int j = 0; j < appIds.size(); j++) {
59 auto fullAppId = desktopFile(appIds[j]);
60 if (m_storedApps[i].settings->fileName() == fullAppId) {
73 for (auto appId: appIds) {
74 loadDesktopFile(appId);
82QString LauncherBackend::desktopFile(const QString &appId) const
84 auto fileInfo = QFileInfo(QDir("/usr/share/applications"), appId);
85 return fileInfo.canonicalFilePath();
88QString LauncherBackend::displayName(const QString &appId) const
90 auto index = findItem(appId);
94 return m_storedApps[index].settings->value("Desktop Entry/Name").toString();
98QString LauncherBackend::icon(const QString &appId) const
100 auto index = findItem(appId);
104 return m_storedApps[index].settings->value("Desktop Entry/Icon").toString();
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();
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);
192void LauncherBackend::syncToAccounts()
194 auto pinnedItems = QStringList();
195 for (int i = 0; i < m_storedApps.size(); i++) {
196 if (m_storedApps[i].pinned) {
197 pinnedItems.append(m_storedApps[i].settings->fileName());
202 m_accounts->setUserProperty(m_user, "launcher-items", QVariant(pinnedItems));
206bool LauncherBackend::loadDesktopFile(const QString &appId)
208 auto item = LauncherBackendItem();
209 auto fullAppId = desktopFile(appId);
210 item.settings = new QSettings(fullAppId, QSettings::IniFormat);
211 m_storedApps.append(item);
212 return true; // QSettings doesn't really indicate a failure mode right now
215int LauncherBackend::findItem(const QString &appId) const
217 auto fullAppId = desktopFile(appId);
218 for (int i = 0; i < m_storedApps.size(); i++) {
219 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