| 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 |
*/ |
| 16 |
|
| 17 |
#ifndef APPLICATION_MANAGER_H |
| 18 |
#define APPLICATION_MANAGER_H |
| 19 |
|
| 20 |
#include <QObject> |
| 21 |
#include <QList> |
| 22 |
#include <QStringList> |
| 23 |
#include <QTimer> |
| 24 |
#include "ApplicationInfo.h" |
| 25 |
|
| 26 |
// lomiri-api |
| 27 |
#include <lomiri/shell/application/ApplicationManagerInterface.h> |
| 28 |
|
| 29 |
namespace lomiri { |
| 30 |
namespace shell { |
| 31 |
namespace application { |
| 32 |
class MirSurfaceInterface; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
class QQuickItem; |
| 38 |
using namespace lomiri::shell::application; |
| 39 |
|
| 40 |
class ApplicationManager : public ApplicationManagerInterface { |
| 41 |
Q_OBJECT |
| 42 |
|
| 43 |
Q_PROPERTY(QStringList availableApplications READ availableApplications NOTIFY availableApplicationsChanged) |
| 44 |
|
| 45 |
public: |
| 46 |
ApplicationManager(QObject *parent = nullptr); |
| 47 |
virtual ~ApplicationManager(); |
| 48 |
|
| 49 |
// QAbstractItemModel methods. |
| 50 |
int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
| 51 |
QVariant data(const QModelIndex& index, int role) const override; |
| 52 |
|
| 53 |
// ApplicationManagerInterface methods |
| 54 |
Q_INVOKABLE ApplicationInfo *get(int index) const override; |
| 55 |
Q_INVOKABLE ApplicationInfo *findApplication(const QString &appId) const override; |
| 56 |
lomiri::shell::application::ApplicationInfoInterface *findApplicationWithSurface(lomiri::shell::application::MirSurfaceInterface* surface) const override; |
| 57 |
|
| 58 |
// Application control methods |
| 59 |
Q_INVOKABLE bool requestFocusApplication(const QString &appId) override; |
| 60 |
Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, const QStringList &arguments = QStringList()) override; |
| 61 |
Q_INVOKABLE bool stopApplication(const QString &appId) override; |
| 62 |
|
| 63 |
QString focusedApplicationId() const override; |
| 64 |
|
| 65 |
// Only for testing |
| 66 |
QStringList availableApplications(); |
| 67 |
Q_INVOKABLE ApplicationInfo* add(QString appId); |
| 68 |
|
| 69 |
QModelIndex findIndex(ApplicationInfo* application); |
| 70 |
|
| 71 |
Q_SIGNALS: |
| 72 |
void focusRequested(const QString &appId); |
| 73 |
void availableApplicationsChanged(QStringList list); |
| 74 |
|
| 75 |
private Q_SLOTS: |
| 76 |
void raiseApp(const QString &appId); |
| 77 |
|
| 78 |
private: |
| 79 |
void move(int from, int to); |
| 80 |
bool add(ApplicationInfo *application); |
| 81 |
void remove(ApplicationInfo* application); |
| 82 |
void buildListOfAvailableApplications(); |
| 83 |
QString toString(); |
| 84 |
ApplicationInfo *findApplication(MirSurface* surface); |
| 85 |
QList<ApplicationInfo*> m_runningApplications; |
| 86 |
QList<ApplicationInfo*> m_availableApplications; |
| 87 |
bool m_modelBusy{false}; |
| 88 |
}; |
| 89 |
|
| 90 |
/* |
| 91 |
Lifecycle of the ApplicationManager instance belongs to the QML plugin. |
| 92 |
So this guy here is used to notify other parts of the system when the plugin creates and destroys |
| 93 |
the ApplicationManager. |
| 94 |
|
| 95 |
Unlike ApplicationManager, we create ApplicationManagerNotifier whenever we want. |
| 96 |
*/ |
| 97 |
class ApplicationManagerNotifier : public QObject { |
| 98 |
Q_OBJECT |
| 99 |
public: |
| 100 |
static ApplicationManagerNotifier *instance(); |
| 101 |
|
| 102 |
ApplicationManager *applicationManager() { return m_applicationManager; } |
| 103 |
|
| 104 |
Q_SIGNALS: |
| 105 |
void applicationManagerChanged(ApplicationManager *applicationManager); |
| 106 |
|
| 107 |
private: |
| 108 |
void setApplicationManager(ApplicationManager *); |
| 109 |
static ApplicationManagerNotifier *m_instance; |
| 110 |
ApplicationManager *m_applicationManager{nullptr}; |
| 111 |
|
| 112 |
friend class ApplicationManager; |
| 113 |
}; |
| 114 |
|
| 115 |
Q_DECLARE_METATYPE(ApplicationManager*) |
| 116 |
|
| 117 |
#endif // APPLICATION_MANAGER_H |