Unity 8
 All Classes Functions Properties
launcherbackend.h
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  */
18 
19 #ifndef LAUNCHERBACKEND_H
20 #define LAUNCHERBACKEND_H
21 
22 #include "common/quicklistentry.h"
23 
24 #include <QObject>
25 #include <QSettings>
26 #include <QStringList>
27 #include <QDBusVirtualObject>
28 
29 class AccountsServiceDBusAdaptor;
30 
35 class LauncherBackendItem;
36 class LauncherBackendTest;
37 
38 class LauncherBackend : public QDBusVirtualObject
39 {
40  Q_OBJECT
41 
42  friend LauncherBackendTest;
43 
44 public:
45  LauncherBackend(QObject *parent = 0);
46  virtual ~LauncherBackend();
47 
52  QStringList storedApplications() const;
53 
63  void setStoredApplications(const QStringList &appIds);
64 
72  QString desktopFile(const QString &appId) const;
73 
82  QString displayName(const QString &appId) const;
83 
92  QString icon(const QString &appId) const;
93 
99  QList<QuickListEntry> quickList(const QString &appId) const;
100 
106  void triggerQuickListAction(const QString &appId, const QString &entryId);
107 
113  int progress(const QString &appId) const;
114 
120  int count(const QString &appId) const;
121 
127  void setCount(const QString &appId, int count) const;
128 
134  bool countVisible(const QString &appId) const;
135 
141  void setCountVisible(const QString &appId, bool visible) const;
142 
147  void setUser(const QString &username);
148 
155  virtual bool handleMessage(const QDBusMessage& message, const QDBusConnection& connection);
156 
162  virtual QString introspect (const QString &path) const;
163 
164 Q_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;
169 
170 private:
171  QString findDesktopFile(const QString &appId) const;
172  LauncherBackendItem* parseDesktopFile(const QString &desktopFile) const;
173 
174  QVariantMap itemToVariant(const QString &appId) const;
175  void loadFromVariant(const QVariantMap &details);
176 
177  bool isDefaultsItem(const QList<QVariantMap> &apps) const;
178  void syncFromAccounts();
179  void syncToAccounts();
180 
181  QList<QString> m_storedApps;
182  mutable QHash<QString, LauncherBackendItem*> m_itemCache;
183 
184  AccountsServiceDBusAdaptor *m_accounts;
185  QString m_user;
186 
187  void emitPropChangedDbus(const QString& appId, const QString& property, QVariant &value) const;
188 
189 protected: /* Protected to allow testing */
190  LauncherBackendItem* getItem(const QString& appId) const;
191 
192  static QString decodeAppId(const QString& path);
193  static QString encodeAppId(const QString& appId);
194 };
195 
196 #endif // LAUNCHERBACKEND_H