on da009e4 help sign in
unity8/tests/mocks/Unity/Application/ApplicationManager.h
138 lines 4.5 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 = nullptr);
50 virtual ~ApplicationManager();
52 static ApplicationManager *singleton();
54 enum MoreRoles {
55 RoleSession = RoleFocused+1,
56 RoleFullscreen,
57 };
58 enum Role {
59 Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard,
60 ShutdownDialog
61 };
62 enum StageHint {
63 MainStage, IntegrationStage, ShareStage, ContentPickingStage,
64 SideStage, ConfigurationStage
65 };
66 enum FormFactorHint {
67 DesktopFormFactor, PhoneFormFactor, TabletFormFactor
68 };
69 enum FavoriteApplication {
70 CameraApplication, GalleryApplication, BrowserApplication, ShareApplication,
71 PhoneApplication, DialerApplication, MessagingApplication, AddressbookApplication
72 };
73 enum Flag {
74 NoFlag = 0x0,
75 ForceMainStage = 0x1,
76 };
77 Q_DECLARE_FLAGS(ExecFlags, Flag)
79 int sideStageWidth() const;
80 StageHint stageHint() const;
81 FormFactorHint formFactorHint() const;
83 bool fake() { return true; }
85 // QAbstractItemModel methods.
86 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
87 QVariant data(const QModelIndex& index, int role) const override;
88 Q_INVOKABLE ApplicationInfo *get(int index) const override;
89 Q_INVOKABLE ApplicationInfo *findApplication(const QString &appId) const override;
91 Q_INVOKABLE void move(int from, int to);
93 // Application control methods
94 Q_INVOKABLE bool requestFocusApplication(const QString &appId) override;
95 Q_INVOKABLE bool focusApplication(const QString &appId) override;
96 Q_INVOKABLE void unfocusCurrentApplication() override;
97 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, const QStringList &arguments = QStringList()) override;
98 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, ExecFlags flags, const QStringList &arguments = QStringList());
99 Q_INVOKABLE bool stopApplication(const QString &appId) override;
101 QString focusedApplicationId() const override;
102 bool suspended() const;
103 void setSuspended(bool suspended);
105 // Only for testing
106 Q_INVOKABLE QStringList availableApplications();
107 Q_INVOKABLE ApplicationInfo* add(QString appId);
109 QModelIndex findIndex(ApplicationInfo* application);
111 bool isEmpty() const;
113 Q_SIGNALS:
114 void focusRequested(FavoriteApplication favoriteApplication);
115 void focusRequested(const QString &appId);
116 void emptyChanged(bool empty);
118 private Q_SLOTS:
119 void onWindowCreatedTimerTimeout();
121 private:
122 void add(ApplicationInfo *application);
123 void remove(ApplicationInfo* application);
124 void buildListOfAvailableApplications();
125 void onWindowCreated();
126 bool m_suspended;
127 QList<ApplicationInfo*> m_runningApplications;
128 QList<ApplicationInfo*> m_availableApplications;
129 QTimer m_windowCreatedTimer;
131 static ApplicationManager *the_application_manager;
132};
134Q_DECLARE_OPERATORS_FOR_FLAGS(ApplicationManager::ExecFlags)
136Q_DECLARE_METATYPE(ApplicationManager*)
138#endif // APPLICATION_MANAGER_H