on ae567d2 help sign in
unity8/tests/mocks/Unity/Application/ApplicationManager.h
139 lines 4.6 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_ENUMS(Role)
35 Q_ENUMS(StageHint)
36 Q_ENUMS(FormFactorHint)
37 Q_ENUMS(FavoriteApplication)
38 Q_FLAGS(ExecFlags)
40 Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
42 Q_PROPERTY(int sideStageWidth READ sideStageWidth)
43 Q_PROPERTY(StageHint stageHint READ stageHint)
44 Q_PROPERTY(FormFactorHint formFactorHint READ formFactorHint)
46 Q_PROPERTY(bool fake READ fake CONSTANT)
48 public:
49 ApplicationManager(QObject *parent = NULL);
50 virtual ~ApplicationManager();
52 static ApplicationManager *singleton();
54 enum MoreRoles {
55 RoleSurface = RoleFocused+1,
56 RoleFullscreen,
57 RoleApplication,
58 };
59 enum Role {
60 Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard,
61 ShutdownDialog
62 };
63 enum StageHint {
64 MainStage, IntegrationStage, ShareStage, ContentPickingStage,
65 SideStage, ConfigurationStage
66 };
67 enum FormFactorHint {
68 DesktopFormFactor, PhoneFormFactor, TabletFormFactor
69 };
70 enum FavoriteApplication {
71 CameraApplication, GalleryApplication, BrowserApplication, ShareApplication,
72 PhoneApplication, DialerApplication, MessagingApplication, AddressbookApplication
73 };
74 enum Flag {
75 NoFlag = 0x0,
76 ForceMainStage = 0x1,
77 };
78 Q_DECLARE_FLAGS(ExecFlags, Flag)
80 int sideStageWidth() const;
81 StageHint stageHint() const;
82 FormFactorHint formFactorHint() const;
84 bool fake() { return true; }
86 // QAbstractItemModel methods.
87 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
88 QVariant data(const QModelIndex& index, int role) const override;
89 Q_INVOKABLE ApplicationInfo *get(int index) const override;
90 Q_INVOKABLE ApplicationInfo *findApplication(const QString &appId) const override;
92 Q_INVOKABLE void move(int from, int to);
94 // Application control methods
95 Q_INVOKABLE bool requestFocusApplication(const QString &appId) override;
96 Q_INVOKABLE bool focusApplication(const QString &appId) override;
97 Q_INVOKABLE void unfocusCurrentApplication() override;
98 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, const QStringList &arguments = QStringList()) override;
99 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, ExecFlags flags, const QStringList &arguments = QStringList());
100 Q_INVOKABLE bool stopApplication(const QString &appId) override;
102 QString focusedApplicationId() const override;
103 bool suspended() const;
104 void setSuspended(bool suspended);
106 // Only for testing
107 Q_INVOKABLE QStringList availableApplications();
108 Q_INVOKABLE ApplicationInfo* add(QString appId);
110 QModelIndex findIndex(ApplicationInfo* application);
112 bool isEmpty() const;
114 Q_SIGNALS:
115 void focusRequested(FavoriteApplication favoriteApplication);
116 void focusRequested(const QString &appId);
117 void emptyChanged(bool empty);
119 private Q_SLOTS:
120 void onWindowCreatedTimerTimeout();
122 private:
123 void add(ApplicationInfo *application);
124 void remove(ApplicationInfo* application);
125 void buildListOfAvailableApplications();
126 void onWindowCreated();
127 bool m_suspended;
128 QList<ApplicationInfo*> m_runningApplications;
129 QList<ApplicationInfo*> m_availableApplications;
130 QTimer m_windowCreatedTimer;
132 static ApplicationManager *the_application_manager;
133};
135Q_DECLARE_OPERATORS_FOR_FLAGS(ApplicationManager::ExecFlags)
137Q_DECLARE_METATYPE(ApplicationManager*)
139#endif // APPLICATION_MANAGER_H