My Project
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Properties Macros
ApplicationManagerInterface.h
1 /*
2  * Copyright 2013 Canonical Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authors:
17  * Michael Zanetti <michael.zanetti@canonical.com>
18  */
19 
20 #ifndef UNITY_SHELL_APPLICATION_APPLICATIONMANAGERINTERFACE_H
21 #define UNITY_SHELL_APPLICATION_APPLICATIONMANAGERINTERFACE_H
22 
23 #include <unity/SymbolExport.h>
24 
25 #include <QtCore/QObject>
26 #include <QtCore/QAbstractListModel>
27 
28 namespace unity
29 {
30 namespace shell
31 {
32 namespace application
33 {
34 
35 class ApplicationInfoInterface;
36 
43 class UNITY_API ApplicationManagerInterface: public QAbstractListModel
44 {
45  Q_OBJECT
46  Q_ENUMS(Roles)
47 
48 
53  Q_PROPERTY(int count READ count NOTIFY countChanged)
54 
60  Q_PROPERTY(QString focusedApplicationId READ focusedApplicationId NOTIFY focusedApplicationIdChanged)
61 
62 protected:
64  ApplicationManagerInterface(QObject* parent = 0): QAbstractListModel(parent)
65  {
66  m_roleNames.insert(RoleAppId, "appId");
67  m_roleNames.insert(RoleName, "name");
68  m_roleNames.insert(RoleComment, "comment");
69  m_roleNames.insert(RoleIcon, "icon");
70  m_roleNames.insert(RoleStage, "stage");
71  m_roleNames.insert(RoleState, "state");
72  m_roleNames.insert(RoleFocused, "focused");
73 
74  connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SIGNAL(countChanged()));
75  connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SIGNAL(countChanged()));
76  connect(this, SIGNAL(modelReset()), SIGNAL(countChanged()));
77  connect(this, SIGNAL(layoutChanged()), SIGNAL(countChanged()));
78  }
80 
81 public:
87  enum Roles {
88  RoleAppId = Qt::UserRole,
89  RoleName,
90  RoleComment,
91  RoleIcon,
92  RoleStage,
93  RoleState,
94  RoleFocused,
95  };
96 
98  virtual ~ApplicationManagerInterface() {}
99 
100  virtual QHash<int, QByteArray> roleNames() const
101  {
102  return m_roleNames;
103  }
104 
105  int count() const {
106  return rowCount();
107  }
108 
109  virtual QString focusedApplicationId() const = 0;
111 
120  Q_INVOKABLE virtual unity::shell::application::ApplicationInfoInterface *get(int index) const = 0;
121 
130  Q_INVOKABLE virtual unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const = 0;
131 
138  Q_INVOKABLE virtual bool focusApplication(const QString &appId) = 0;
139 
143  Q_INVOKABLE virtual void unfocusCurrentApplication() = 0;
144 
152  Q_INVOKABLE virtual unity::shell::application::ApplicationInfoInterface *startApplication(const QString &appId, const QStringList &arguments) = 0;
153 
160  Q_INVOKABLE virtual bool stopApplication(const QString &appId) = 0;
161 
162 Q_SIGNALS:
164  void countChanged();
166 
170  void focusedApplicationIdChanged();
171 
172 protected:
174  QHash<int, QByteArray> m_roleNames;
176 };
177 
178 } // namespace application
179 } // namespace shell
180 } // namespace unity
181 
182 #endif // UNITY_SHELL_APPLICATIONMANAGER_APPLICATIONINFO_H