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);
36 // TODO: load default pinned ones from default config, instead of hardcoding here...
37 if (m_storedApps.isEmpty()) {
38 setStoredApplications(QStringList() <<
39 "phone-app.desktop" <<
40 "camera-app.desktop" <<
41 "gallery-app.desktop" <<
42 "facebook-webapp.desktop" <<
43 "webbrowser-app.desktop" <<
44 "twitter-webapp.desktop" <<
45 "gmail-webapp.desktop" <<
46 "ubuntu-weather-app.desktop" <<
47 "notes-app.desktop" <<
48 "calendar-app.desktop");
52LauncherBackend::~LauncherBackend()
57QStringList LauncherBackend::storedApplications() const
59 auto files = QStringList();
60 for (int i = 0; i < m_storedApps.size(); i++) {
61 files << m_storedApps[i].settings->fileName();
66void LauncherBackend::setStoredApplications(const QStringList &appIds)
68 // Are we dropping any pinned apps?
69 auto needToSync = false;
70 for (int i = 0; i < m_storedApps.size(); i++) {
71 if (m_storedApps[i].pinned) {
73 for (int j = 0; j < appIds.size(); j++) {
74 auto fullAppId = desktopFile(appIds[j]);
75 if (m_storedApps[i].settings->fileName() == fullAppId) {
88 for (auto appId: appIds) {
89 loadDesktopFile(appId);
97QString LauncherBackend::desktopFile(const QString &appId) const
99 auto fileInfo = QFileInfo(QDir("/usr/share/applications"), appId);
100 return fileInfo.canonicalFilePath();
103QString LauncherBackend::displayName(const QString &appId) const
105 auto index = findItem(appId);
109 return m_storedApps[index].settings->value("Desktop Entry/Name").toString();
113QString LauncherBackend::icon(const QString &appId) const
115 auto index = findItem(appId);
119 return m_storedApps[index].settings->value("Desktop Entry/Icon").toString();
123bool LauncherBackend::isPinned(const QString &appId) const
125 auto index = findItem(appId);
129 return m_storedApps[index].pinned;
133void LauncherBackend::setPinned(const QString &appId, bool pinned)
135 auto index = findItem(appId);
136 if (index >= 0 && !m_storedApps[index].pinned) {
137 m_storedApps[index].pinned = pinned;
142QList<QuickListEntry> LauncherBackend::quickList(const QString &appId) const
144 // TODO: Get static (from .desktop file) and dynamic (from the app itself)
145 // entries and return them here. Frontend related entries (like "Pin to launcher")
146 // don't matter here. This is just the backend part.
147 // TODO: emit quickListChanged() when the dynamic part changes
149 return QList<QuickListEntry>();
152int LauncherBackend::progress(const QString &appId) const
154 // TODO: Return value for progress emblem.
155 // TODO: emit progressChanged() when this value changes.
160int LauncherBackend::count(const QString &appId) const
162 // TODO: Return value for count emblem.
163 // TODO: emit countChanged() when this value changes.
168void LauncherBackend::triggerQuickListAction(const QString &appId, const QString &quickListId)
170 // TODO: execute the given quicklist action
172 Q_UNUSED(quickListId)
175void LauncherBackend::syncFromAccounts()
177 auto username = qgetenv("USER");
178 if (username != "") {
179 auto itemsVariant = m_accounts->getUserProperty(username, "launcher-items");
180 setStoredApplications(itemsVariant.toStringList());
184void LauncherBackend::syncToAccounts()
186 auto pinnedItems = QStringList();
187 for (int i = 0; i < m_storedApps.size(); i++) {
188 if (m_storedApps[i].pinned) {
189 pinnedItems.append(m_storedApps[i].settings->fileName());
193 auto username = qgetenv("USER");
194 if (username != "") {
195 m_accounts->setUserProperty(username, "launcher-items", QVariant(pinnedItems));
199bool LauncherBackend::loadDesktopFile(const QString &appId)
201 auto item = LauncherBackendItem();
202 auto fullAppId = desktopFile(appId);
203 item.settings = new QSettings(fullAppId, QSettings::IniFormat);
204 m_storedApps.append(item);
205 return true; // QSettings doesn't really indicate a failure mode right now
208int LauncherBackend::findItem(const QString &appId) const
210 auto fullAppId = desktopFile(appId);
211 for (int i = 0; i < m_storedApps.size(); i++) {
212 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