on ba4ffba help sign in
unity8/tests/mocks/Unity/Application/ApplicationManager.h
112 lines 3.7 kB history raw
1/*
2 * Copyright (C) 2013-2014 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>
29class QQuickItem;
30using namespace unity::shell::application;
32class ApplicationManager : public ApplicationManagerInterface {
33 Q_OBJECT
34 Q_FLAGS(ExecFlags)
36 Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
37 Q_PROPERTY(QStringList availableApplications READ availableApplications NOTIFY availableApplicationsChanged)
39 public:
40 ApplicationManager(QObject *parent = nullptr);
41 virtual ~ApplicationManager();
43 static ApplicationManager *singleton();
45 enum MoreRoles {
46 RoleSession = RoleFocused+1,
47 RoleFullscreen,
48 };
49 enum Flag {
50 NoFlag = 0x0,
51 ForceMainStage = 0x1,
52 };
53 Q_DECLARE_FLAGS(ExecFlags, Flag)
55 // QAbstractItemModel methods.
56 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
57 QVariant data(const QModelIndex& index, int role) const override;
58 Q_INVOKABLE ApplicationInfo *get(int index) const override;
59 Q_INVOKABLE ApplicationInfo *findApplication(const QString &appId) const override;
61 Q_INVOKABLE void move(int from, int to);
63 // Application control methods
64 Q_INVOKABLE bool requestFocusApplication(const QString &appId) override;
65 Q_INVOKABLE bool focusApplication(const QString &appId) override;
66 Q_INVOKABLE void unfocusCurrentApplication() override;
67 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, const QStringList &arguments = QStringList()) override;
68 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, ExecFlags flags, const QStringList &arguments = QStringList());
69 Q_INVOKABLE bool stopApplication(const QString &appId) override;
71 QString focusedApplicationId() const override;
72 bool suspended() const override;
73 void setSuspended(bool suspended) override;
75 bool forceDashActive() const override;
76 void setForceDashActive(bool forceDashActive) override;
78 // Only for testing
79 QStringList availableApplications();
80 Q_INVOKABLE ApplicationInfo* add(QString appId);
82 QModelIndex findIndex(ApplicationInfo* application);
84 bool isEmpty() const;
86 Q_SIGNALS:
87 void focusRequested(const QString &appId);
88 void emptyChanged(bool empty);
89 void availableApplicationsChanged(QStringList list);
91 private Q_SLOTS:
92 void onWindowCreatedTimerTimeout();
94 private:
95 void add(ApplicationInfo *application);
96 void remove(ApplicationInfo* application);
97 void buildListOfAvailableApplications();
98 void onWindowCreated();
99 bool m_suspended;
100 bool m_forceDashActive;
101 QList<ApplicationInfo*> m_runningApplications;
102 QList<ApplicationInfo*> m_availableApplications;
103 QTimer m_windowCreatedTimer;
105 static ApplicationManager *the_application_manager;
106};
108Q_DECLARE_OPERATORS_FOR_FLAGS(ApplicationManager::ExecFlags)
110Q_DECLARE_METATYPE(ApplicationManager*)
112#endif // APPLICATION_MANAGER_H