on 713e430 help sign in
unity8/tests/mocks/Unity/Application/ApplicationManager.h
150 lines 5.1 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 "ApplicationInfo.h"
25// unity-api
26#include <unity/shell/application/ApplicationManagerInterface.h>
28class QQuickItem;
29using namespace unity::shell::application;
31class ApplicationManager : public ApplicationManagerInterface {
32 Q_OBJECT
33 Q_ENUMS(Role)
34 Q_ENUMS(StageHint)
35 Q_ENUMS(FormFactorHint)
36 Q_ENUMS(FavoriteApplication)
37 Q_FLAGS(ExecFlags)
39 Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
41 Q_PROPERTY(int sideStageWidth READ sideStageWidth)
42 Q_PROPERTY(StageHint stageHint READ stageHint)
43 Q_PROPERTY(FormFactorHint formFactorHint READ formFactorHint)
45 Q_PROPERTY(bool fake READ fake CONSTANT)
47 // Only for testing
48 // This can be used to place some controls to right, like make tryPhoneStage for example
49 Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin)
51 public:
52 ApplicationManager(QObject *parent = NULL);
53 virtual ~ApplicationManager();
55 static ApplicationManager *singleton();
57 enum MoreRoles {
58 RoleSurface = RoleScreenshot+1,
59 RoleFullscreen,
60 };
61 enum Role {
62 Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard,
63 ShutdownDialog
64 };
65 enum StageHint {
66 MainStage, IntegrationStage, ShareStage, ContentPickingStage,
67 SideStage, ConfigurationStage
68 };
69 enum FormFactorHint {
70 DesktopFormFactor, PhoneFormFactor, TabletFormFactor
71 };
72 enum FavoriteApplication {
73 CameraApplication, GalleryApplication, BrowserApplication, ShareApplication,
74 PhoneApplication, DialerApplication, MessagingApplication, AddressbookApplication
75 };
76 enum Flag {
77 NoFlag = 0x0,
78 ForceMainStage = 0x1,
79 };
80 Q_DECLARE_FLAGS(ExecFlags, Flag)
82 int sideStageWidth() const;
83 StageHint stageHint() const;
84 FormFactorHint formFactorHint() const;
86 bool fake() { return true; }
88 // QAbstractItemModel methods.
89 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
90 QVariant data(const QModelIndex& index, int role) const override;
91 Q_INVOKABLE ApplicationInfo *get(int index) const override;
92 Q_INVOKABLE ApplicationInfo *findApplication(const QString &appId) const override;
94 Q_INVOKABLE void move(int from, int to);
96 // Application control methods
97 Q_INVOKABLE bool requestFocusApplication(const QString &appId) override;
98 Q_INVOKABLE bool focusApplication(const QString &appId) override;
99 Q_INVOKABLE void unfocusCurrentApplication() override;
100 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, const QStringList &arguments = QStringList()) override;
101 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, ExecFlags flags, const QStringList &arguments = QStringList());
102 Q_INVOKABLE bool stopApplication(const QString &appId) override;
103 Q_INVOKABLE bool updateScreenshot(const QString &appId) override;
105 QString focusedApplicationId() const override;
106 bool suspended() const;
107 void setSuspended(bool suspended);
109 // Only for testing
110 Q_INVOKABLE QStringList availableApplications();
111 int rightMargin() const;
112 void setRightMargin(int rightMargin);
114 QModelIndex findIndex(ApplicationInfo* application);
116 bool isEmpty() const;
118 Q_SIGNALS:
119 void focusRequested(FavoriteApplication favoriteApplication);
120 void focusRequested(const QString &appId);
121 void emptyChanged(bool empty);
123 private:
124 void add(ApplicationInfo *application);
125 void remove(ApplicationInfo* application);
126 void showApplicationWindow(ApplicationInfo *application);
127 void buildListOfAvailableApplications();
128 void generateQmlStrings(ApplicationInfo *application);
129 void createMainStageComponent();
130 void createMainStage();
131 void createSideStageComponent();
132 void createSideStage();
133 bool m_suspended;
134 QList<ApplicationInfo*> m_runningApplications;
135 QList<ApplicationInfo*> m_availableApplications;
136 QQmlComponent *m_mainStageComponent;
137 QQuickItem *m_mainStage;
138 QQmlComponent *m_sideStageComponent;
139 QQuickItem *m_sideStage;
141 int m_rightMargin;
143 static ApplicationManager *the_application_manager;
144};
146Q_DECLARE_OPERATORS_FOR_FLAGS(ApplicationManager::ExecFlags)
148Q_DECLARE_METATYPE(ApplicationManager*)
150#endif // APPLICATION_MANAGER_H