on 2babb28 help sign in
unity8/plugins/Unity/Launcher/backend/launcherbackend.h
163 lines 5.1 kB history raw
1/* Copyright (C) 2013 Canonical, Ltd.
2 *
3 * Authors:
4 * Michael Zanetti <michael.zanetti@canonical.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
19#ifndef LAUNCHERBACKEND_H
20#define LAUNCHERBACKEND_H
22#include "common/quicklistentry.h"
24#include <QObject>
25#include <QSettings>
26#include <QStringList>
28class AccountsService;
30/**
31 * @brief An interface that provides all the data needed by the launcher.
32 */
34class LauncherBackendItem;
36class LauncherBackend : public QObject
38 Q_OBJECT
41public:
42 LauncherBackend(bool useStorage = true, QObject *parent = 0);
43 virtual ~LauncherBackend();
45 /**
46 * @brief Returns a list of stored applications.
47 * @returns A list of application IDs.
48 */
49 QStringList storedApplications() const;
51 /**
52 * @brief Set the list of stored applications.
53 *
54 * Any previously stored information for apps not contained
55 * in the list any more, e.g. the pinned state, will be
56 * discarded.
57 *
58 * @param appIds The new list of stored applications.
59 */
60 void setStoredApplications(const QStringList &appIds);
62 /**
63 * @brief Get the full path to the .desktop file.
64 *
65 * The application does not need to be in the list of stored applications.
66 *
67 * @returns The full path to the .dekstop file.
68 */
69 QString desktopFile(const QString &appId) const;
71 /**
72 * @brief Get the user friendly name of an application.
73 *
74 * The application does not need to be in the list of stored applications.
75 *
76 * @param appId The ID of the application.
77 * @returns The user friendly name of the application.
78 */
79 QString displayName(const QString &appId) const;
81 /**
82 * @brief Get the icon of an application.
83 *
84 * The application does not need to be in the list of stored applications.
85 *
86 * @param appId The ID of the application.
87 * @returns The full path to the icon for the application.
88 */
89 QString icon(const QString &appId) const;
91 /**
92 * @brief Is the app manually pinned?
93 * @returns true if pinned, otherwise false.
94 */
95 bool isPinned(const QString &appId) const;
97 /**
98 * @brief Change the pinned state of an application.
99 * @param appId The application where the pinned flag should be set.
100 * @param pinned true if pinned, otherwise false.
101 */
102 void setPinned(const QString &appId, bool pinned);
104 //TODO: Fill in getters for all the other things needed from the .desktop file.
106 /**
107 * @brief Get the QuickList for an application.
108 * @param appId The ID of the application.
109 * @returns A QuickListModelInterface containing the QuickList.
110 */
111 QList<QuickListEntry> quickList(const QString &appId) const;
113 /**
114 * @brief Execute an action from the quickList
115 * @param appId The app ID for which the action was triggered
116 * @param the quicklist ID of the action that was triggered
117 */
118 void triggerQuickListAction(const QString &appId, const QString &entryId);
120 /**
121 * @brief Get the progress for the progress overlay of an application.
122 * @param appId The ID of the application.
123 * @returns The percentage of the overlay progress bar. -1 if no progress bar available.
124 */
125 int progress(const QString &appId) const;
127 /**
128 * @brief Get the count of the count overlay of an application.
129 * @param appId The ID of the application.
130 * @returns The number to be displayed in the overlay. -1 if no count overlay is available.
131 */
132 int count(const QString &appId) const;
134 /**
135 * @brief Sets the username for which to look up launcher items.
136 * @param username The username to use.
137 */
138 void setUser(const QString &username);
140Q_SIGNALS:
141 void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList);
142 void progressChanged(const QString &appId, int progress);
143 void countChanged(const QString &appId, int count);
145private:
146 QString findDesktopFile(const QString &appId) const;
147 LauncherBackendItem* parseDesktopFile(const QString &desktopFile) const;
149 QVariantMap itemToVariant(const QString &appId) const;
150 void loadFromVariant(const QVariantMap &details);
152 bool isDefaultsItem(const QList<QVariantMap> &apps) const;
153 void syncFromAccounts();
154 void syncToAccounts();
156 QList<QString> m_storedApps;
157 mutable QHash<QString, LauncherBackendItem*> m_itemCache;
159 AccountsService *m_accounts;
160 QString m_user;
161};
163#endif // LAUNCHERBACKEND_H