on fe71e21 help sign in
unity8/tests/mocks/Unity/Application/ApplicationManager.h
122 lines 4.0 kB history raw
1/*
2 * Copyright (C) 2013-2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#ifndef APPLICATION_MANAGER_H
18#define APPLICATION_MANAGER_H
20#include <QObject>
21#include <QList>
22#include <QStringList>
23#include <QTimer>
24#include "ApplicationInfo.h"
26// unity-api
27#include <unity/shell/application/ApplicationManagerInterface.h>
29namespace unity {
30 namespace shell {
31 namespace application {
32 class MirSurfaceInterface;
33 }
34 }
37class QQuickItem;
38using namespace unity::shell::application;
40class ApplicationManager : public ApplicationManagerInterface {
41 Q_OBJECT
43 Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
44 Q_PROPERTY(QStringList availableApplications READ availableApplications NOTIFY availableApplicationsChanged)
46 public:
47 ApplicationManager(QObject *parent = nullptr);
48 virtual ~ApplicationManager();
50 // QAbstractItemModel methods.
51 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
52 QVariant data(const QModelIndex& index, int role) const override;
54 // ApplicationManagerInterface methods
55 Q_INVOKABLE ApplicationInfo *get(int index) const override;
56 Q_INVOKABLE ApplicationInfo *findApplication(const QString &appId) const override;
57 unity::shell::application::ApplicationInfoInterface *findApplicationWithSurface(unity::shell::application::MirSurfaceInterface* surface) const override;
59 Q_INVOKABLE void move(int from, int to);
61 // Application control methods
62 Q_INVOKABLE bool requestFocusApplication(const QString &appId) override;
63 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, const QStringList &arguments = QStringList()) override;
64 Q_INVOKABLE bool stopApplication(const QString &appId) override;
66 QString focusedApplicationId() const override;
68 // Only for testing
69 QStringList availableApplications();
70 Q_INVOKABLE ApplicationInfo* add(QString appId);
72 QModelIndex findIndex(ApplicationInfo* application);
74 bool isEmpty() const;
76 Q_SIGNALS:
77 void focusRequested(const QString &appId);
78 void emptyChanged(bool empty);
79 void availableApplicationsChanged(QStringList list);
81 private Q_SLOTS:
82 void raiseApp(const QString &appId);
84 private:
85 bool add(ApplicationInfo *application);
86 void remove(ApplicationInfo* application);
87 void buildListOfAvailableApplications();
88 QString toString();
89 ApplicationInfo *findApplication(MirSurface* surface);
90 QList<ApplicationInfo*> m_runningApplications;
91 QList<ApplicationInfo*> m_availableApplications;
92 bool m_modelBusy{false};
93};
95/*
96 Lifecycle of the ApplicationManager instance belongs to the QML plugin.
97 So this guy here is used to notify other parts of the system when the plugin creates and destroys
98 the ApplicationManager.
100 Unlike ApplicationManager, we create ApplicationManagerNotifier whenever we want.
101 */
102class ApplicationManagerNotifier : public QObject {
103 Q_OBJECT
104public:
105 static ApplicationManagerNotifier *instance();
107 ApplicationManager *applicationManager() { return m_applicationManager; }
109Q_SIGNALS:
110 void applicationManagerChanged(ApplicationManager *applicationManager);
112private:
113 void setApplicationManager(ApplicationManager *);
114 static ApplicationManagerNotifier *m_instance;
115 ApplicationManager *m_applicationManager{nullptr};
117friend class ApplicationManager;
118};
120Q_DECLARE_METATYPE(ApplicationManager*)
122#endif // APPLICATION_MANAGER_H