on 67fd442 help sign in
unity8/plugins/Unity/Launcher/backend/launcherbackend.h
196 lines 6.4 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>
27#include <QDBusVirtualObject>
29class AccountsServiceDBusAdaptor;
31/**
32 * @brief An interface that provides all the data needed by the launcher.
33 */
35class LauncherBackendItem;
36class LauncherBackendTest;
38class LauncherBackend : public QDBusVirtualObject
40 Q_OBJECT
42 friend LauncherBackendTest;
44public:
45 LauncherBackend(QObject *parent = 0);
46 virtual ~LauncherBackend();
48 /**
49 * @brief Returns a list of stored applications.
50 * @returns A list of application IDs.
51 */
52 QStringList storedApplications() const;
54 /**
55 * @brief Set the list of stored applications.
56 *
57 * Any previously stored information for apps not contained
58 * in the list any more, e.g. the pinned state, will be
59 * discarded.
60 *
61 * @param appIds The new list of stored applications.
62 */
63 void setStoredApplications(const QStringList &appIds);
65 /**
66 * @brief Get the full path to the .desktop file.
67 *
68 * The application does not need to be in the list of stored applications.
69 *
70 * @returns The full path to the .dekstop file.
71 */
72 QString desktopFile(const QString &appId) const;
74 /**
75 * @brief Get the user friendly name of an application.
76 *
77 * The application does not need to be in the list of stored applications.
78 *
79 * @param appId The ID of the application.
80 * @returns The user friendly name of the application.
81 */
82 QString displayName(const QString &appId) const;
84 /**
85 * @brief Get the icon of an application.
86 *
87 * The application does not need to be in the list of stored applications.
88 *
89 * @param appId The ID of the application.
90 * @returns The full path to the icon for the application.
91 */
92 QString icon(const QString &appId) const;
94 /**
95 * @brief Get the QuickList for an application.
96 * @param appId The ID of the application.
97 * @returns A QuickListModelInterface containing the QuickList.
98 */
99 QList<QuickListEntry> quickList(const QString &appId) const;
101 /**
102 * @brief Execute an action from the quickList
103 * @param appId The app ID for which the action was triggered
104 * @param the quicklist ID of the action that was triggered
105 */
106 void triggerQuickListAction(const QString &appId, const QString &entryId);
108 /**
109 * @brief Get the progress for the progress overlay of an application.
110 * @param appId The ID of the application.
111 * @returns The percentage of the overlay progress bar. -1 if no progress bar available.
112 */
113 int progress(const QString &appId) const;
115 /**
116 * @brief Get the count of the count overlay of an application.
117 * @param appId The ID of the application.
118 * @returns The number to be displayed in the overlay. -1 if no count overlay is available.
119 */
120 int count(const QString &appId) const;
122 /**
123 * @brief Set the count on an item
124 * @param appId The ID of the application
125 * @param count Count to show on the application
126 */
127 void setCount(const QString &appId, int count) const;
129 /**
130 * @brief Get whether the count should be visible
131 * @param appId The ID of the application.
132 * @returns Whether to show a count on the launcher
133 */
134 bool countVisible(const QString &appId) const;
136 /**
137 * @brief Set the visibility of the count item
138 * @param appId The ID of the application
139 * @param visible Whether the count should be visible
140 */
141 void setCountVisible(const QString &appId, bool visible) const;
143 /**
144 * @brief Sets the username for which to look up launcher items.
145 * @param username The username to use.
146 */
147 void setUser(const QString &username);
149 /**
150 * @brief Handle a message to an application node
151 * @param message DBus message to handle
152 * @param connection DBus connection that we're using
153 * @returns whether the message was handled
154 */
155 virtual bool handleMessage(const QDBusMessage& message, const QDBusConnection& connection);
157 /**
158 * @brief Get introspection information on the objects we're exporting
159 * @param path the dbus path containing the appid
160 * @returns Introspection information for that node in the tree
161 */
162 virtual QString introspect (const QString &path) const;
164Q_SIGNALS:
165 void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList) const;
166 void progressChanged(const QString &appId, int progress) const;
167 void countChanged(const QString &appId, int count) const;
168 void countVisibleChanged(const QString &appId, bool visible) const;
170private:
171 QString findDesktopFile(const QString &appId) const;
172 LauncherBackendItem* parseDesktopFile(const QString &desktopFile) const;
174 QVariantMap itemToVariant(const QString &appId) const;
175 void loadFromVariant(const QVariantMap &details);
177 bool isDefaultsItem(const QList<QVariantMap> &apps) const;
178 void syncFromAccounts();
179 void syncToAccounts();
181 QList<QString> m_storedApps;
182 mutable QHash<QString, LauncherBackendItem*> m_itemCache;
184 AccountsServiceDBusAdaptor *m_accounts;
185 QString m_user;
187 void emitPropChangedDbus(const QString& appId, const QString& property, QVariant &value) const;
189protected: /* Protected to allow testing */
190 LauncherBackendItem* getItem(const QString& appId) const;
192 static QString decodeAppId(const QString& path);
193 static QString encodeAppId(const QString& appId);
194};
196#endif // LAUNCHERBACKEND_H