2 * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
17#include "ApplicationManager.h"
18#include "ApplicationInfo.h"
22#include <QGuiApplication>
25#include <QQmlComponent>
27ApplicationManager::ApplicationManager(QObject *parent)
28 : ApplicationManagerInterface(parent)
29 , m_mainStageComponent(0)
31 , m_sideStageComponent(0)
34 buildListOfAvailableApplications();
37ApplicationManager::~ApplicationManager()
41int ApplicationManager::rowCount(const QModelIndex& parent) const {
42 return !parent.isValid() ? m_runningApplications.size() : 0;
45QVariant ApplicationManager::data(const QModelIndex& index, int role) const {
46 if (index.row() < 0 || index.row() >= m_runningApplications.size())
49 auto app = m_runningApplications.at(index.row());
56 return app->comment();
64 return app->focused();
70ApplicationInfo *ApplicationManager::get(int row) const {
71 if (row < 0 || row >= m_runningApplications.size())
73 return m_runningApplications.at(row);
76ApplicationInfo *ApplicationManager::findApplication(const QString &appId) const {
77 for (ApplicationInfo *app : m_runningApplications) {
78 if (app->appId() == appId) {
85void ApplicationManager::add(ApplicationInfo *application) {
89 beginInsertRows(QModelIndex(), m_runningApplications.size(), m_runningApplications.size());
90 m_runningApplications.append(application);
92 Q_EMIT countChanged();
95void ApplicationManager::remove(ApplicationInfo *application) {
96 int i = m_runningApplications.indexOf(application);
98 beginRemoveRows(QModelIndex(), i, i);
99 m_runningApplications.removeAt(i);
101 Q_EMIT countChanged();
105void ApplicationManager::move(int from, int to) {
106 if (from == to) return;
108 if (from >= 0 && from < m_runningApplications.size() && to >= 0 && to < m_runningApplications.size()) {
110 /* When moving an item down, the destination index needs to be incremented
111 * by one, as explained in the documentation:
112 * http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */
113 beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
114 m_runningApplications.move(from, to);
119int ApplicationManager::keyboardHeight() const
124bool ApplicationManager::keyboardVisible() const
129int ApplicationManager::sideStageWidth() const
134ApplicationManager::StageHint ApplicationManager::stageHint() const
139ApplicationManager::FormFactorHint ApplicationManager::formFactorHint() const
141 return PhoneFormFactor;
144ApplicationInfo* ApplicationManager::startApplication(const QString &appId,
145 const QStringList &arguments)
147 return startApplication(appId, NoFlag, arguments);
150ApplicationInfo* ApplicationManager::startApplication(const QString &appId,
152 const QStringList &arguments)
155 ApplicationInfo *application = 0;
157 for (ApplicationInfo *availableApp : m_availableApplications) {
158 if (availableApp->appId() == appId) {
159 application = availableApp;
167 if (flags.testFlag(ApplicationManager::ForceMainStage)
168 && application->stage() == ApplicationInfo::SideStage) {
169 application->setStage(ApplicationInfo::MainStage);
176bool ApplicationManager::stopApplication(const QString &appId)
178 ApplicationInfo *application = findApplication(appId);
179 if (application == nullptr)
183 Q_EMIT focusedApplicationIdChanged();
187QString ApplicationManager::focusedApplicationId() const {
188 for (ApplicationInfo *app : m_runningApplications) {
189 if (app->focused()) {
196bool ApplicationManager::focusApplication(const QString &appId)
198 ApplicationInfo *application = findApplication(appId);
199 if (application == nullptr)
202 if (application->stage() == ApplicationInfo::MainStage) {
203 // unfocus currently focused mainstage app
204 for (ApplicationInfo *app : m_runningApplications) {
205 if (app->focused() && app->stage() == ApplicationInfo::MainStage) {
206 app->setFocused(false);
212 application->setFocused(true);
215 application->showWindow(m_mainStage);
216 m_mainStage->setZ(-1000);
218 m_sideStage->setZ(-2000);
219 } else if (application->stage() == ApplicationInfo::SideStage) {
220 // unfocus currently focused sidestage app
221 for (ApplicationInfo *app : m_runningApplications) {
222 if (app->focused() && app->stage() == ApplicationInfo::SideStage) {
223 app->setFocused(false);
229 application->setFocused(true);
232 application->showWindow(m_sideStage);
233 m_sideStage->setZ(-1000);
235 m_mainStage->setZ(-2000);
238 // move app to top of stack
239 move(m_runningApplications.indexOf(application), 0);
240 Q_EMIT focusedApplicationIdChanged();
244void ApplicationManager::unfocusCurrentApplication()
246 for (ApplicationInfo *app : m_runningApplications) {
247 if (app->focused()) {
249 app->setFocused(false);
252 Q_EMIT focusedApplicationIdChanged();
255void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
257 // TODO: Is there a better way of solving this fullscreen vs. regular
258 // application height?
260 if (application->fullscreen()) {
261 topMargin.append("0");
263 // Taken from Panel.panelHeight
264 topMargin.append("units.gu(3) + units.dp(2)");
267 QString windowQml = QString(
268 "import QtQuick 2.0\n"
270 " anchors.fill: parent\n"
271 " anchors.topMargin: %1\n"
272 " source: \"file://%2/Dash/graphics/phone/screenshots/%3.png\"\n"
274 " fillMode: Image.PreserveAspectCrop\n"
276 .arg(shellAppDirectory())
277 .arg(application->icon().toString());
278 application->setWindowQml(windowQml);
280 QString imageQml = QString(
281 "import QtQuick 2.0\n"
283 " anchors.fill: parent\n"
284 " source: \"file://%1/Dash/graphics/phone/screenshots/%2.png\"\n"
286 " fillMode: Image.PreserveAspectCrop\n"
287 "}").arg(shellAppDirectory())
288 .arg(application->icon().toString());
289 application->setImageQml(imageQml);
292void ApplicationManager::buildListOfAvailableApplications()
294 ApplicationInfo *application;
296 application = new ApplicationInfo(this);
297 application->setAppId("phone-app");
298 application->setName("Phone");
299 application->setIcon(QUrl("phone"));
300 application->setStage(ApplicationInfo::SideStage);
301 generateQmlStrings(application);
302 m_availableApplications.append(application);
304 application = new ApplicationInfo(this);
305 application->setAppId("camera-app");
306 application->setName("Camera");
307 application->setIcon(QUrl("camera"));
308 application->setFullscreen(true);
309 generateQmlStrings(application);
310 m_availableApplications.append(application);
312 application = new ApplicationInfo(this);
313 application->setAppId("gallery-app");
314 application->setName("Gallery");
315 application->setIcon(QUrl("gallery"));
316 generateQmlStrings(application);
317 m_availableApplications.append(application);
319 application = new ApplicationInfo(this);
320 application->setAppId("facebook-webapp");
321 application->setName("Facebook");
322 application->setIcon(QUrl("facebook"));
323 application->setStage(ApplicationInfo::SideStage);
324 generateQmlStrings(application);
325 m_availableApplications.append(application);
327 application = new ApplicationInfo(this);
328 application->setAppId("webbrowser-app");
329 application->setName("Browser");
330 application->setIcon(QUrl("browser"));
331 generateQmlStrings(application);
332 m_availableApplications.append(application);
334 application = new ApplicationInfo(this);
335 application->setAppId("twitter-webapp");
336 application->setName("Twitter");
337 application->setIcon(QUrl("twitter"));
338 application->setStage(ApplicationInfo::SideStage);
339 generateQmlStrings(application);
340 m_availableApplications.append(application);
342 application = new ApplicationInfo(this);
343 application->setAppId("gmail-webapp");
344 application->setName("GMail");
345 application->setIcon(QUrl("gmail"));
346 m_availableApplications.append(application);
348 application = new ApplicationInfo(this);
349 application->setAppId("ubuntu-weather-app");
350 application->setName("Weather");
351 application->setIcon(QUrl("weather"));
352 application->setStage(ApplicationInfo::SideStage);
353 generateQmlStrings(application);
354 m_availableApplications.append(application);
356 application = new ApplicationInfo(this);
357 application->setAppId("notes-app");
358 application->setName("Notepad");
359 application->setIcon(QUrl("notepad"));
360 application->setStage(ApplicationInfo::SideStage);
361 m_availableApplications.append(application);
363 application = new ApplicationInfo(this);
364 application->setAppId("calendar-app");
365 application->setName("Calendar");
366 application->setIcon(QUrl("calendar"));
367 application->setStage(ApplicationInfo::SideStage);
368 m_availableApplications.append(application);
370 application = new ApplicationInfo(this);
371 application->setAppId("mediaplayer-app");
372 application->setName("Media Player");
373 application->setIcon(QUrl("mediaplayer-app"));
374 application->setFullscreen(true);
375 m_availableApplications.append(application);
377 application = new ApplicationInfo(this);
378 application->setAppId("evernote");
379 application->setName("Evernote");
380 application->setIcon(QUrl("evernote"));
381 m_availableApplications.append(application);
383 application = new ApplicationInfo(this);
384 application->setAppId("map");
385 application->setName("Map");
386 application->setIcon(QUrl("map"));
387 generateQmlStrings(application);
388 m_availableApplications.append(application);
390 application = new ApplicationInfo(this);
391 application->setAppId("pinterest");
392 application->setName("Pinterest");
393 application->setIcon(QUrl("pinterest"));
394 m_availableApplications.append(application);
396 application = new ApplicationInfo(this);
397 application->setAppId("soundcloud");
398 application->setName("SoundCloud");
399 application->setIcon(QUrl("soundcloud"));
400 m_availableApplications.append(application);
402 application = new ApplicationInfo(this);
403 application->setAppId("wikipedia");
404 application->setName("Wikipedia");
405 application->setIcon(QUrl("wikipedia"));
406 m_availableApplications.append(application);
408 application = new ApplicationInfo(this);
409 application->setAppId("youtube");
410 application->setName("YouTube");
411 application->setIcon(QUrl("youtube"));
412 m_availableApplications.append(application);
415void ApplicationManager::createMainStageComponent()
417 // The assumptions I make here really should hold.
418 QQuickView *quickView =
419 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
421 QQmlEngine *engine = quickView->engine();
423 m_mainStageComponent = new QQmlComponent(engine, this);
424 QString mainStageQml =
425 "import QtQuick 2.0\n"
427 " anchors.fill: parent\n"
431 m_mainStageComponent->setData(mainStageQml.toLatin1(), QUrl());
434void ApplicationManager::createMainStage()
436 if (!m_mainStageComponent)
437 createMainStageComponent();
439 // The assumptions I make here really should hold.
440 QQuickView *quickView =
441 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
443 QQuickItem *shell = quickView->rootObject();
445 m_mainStage = qobject_cast<QQuickItem *>(m_mainStageComponent->create());
446 m_mainStage->setParentItem(shell);
449void ApplicationManager::createSideStageComponent()
451 // The assumptions I make here really should hold.
452 QQuickView *quickView =
453 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
455 QQmlEngine *engine = quickView->engine();
457 m_sideStageComponent = new QQmlComponent(engine, this);
458 QString sideStageQml =
459 "import QtQuick 2.0\n"
460 "import Ubuntu.Components 0.1\n"
462 " width: units.gu(40)\n" // from SideStage in Shell.qml
463 " anchors.top: parent.top\n"
464 " anchors.bottom: parent.bottom\n"
465 " anchors.right: parent.right\n"
468 m_sideStageComponent->setData(sideStageQml.toLatin1(), QUrl());
471void ApplicationManager::createSideStage()
473 if (!m_sideStageComponent)
474 createSideStageComponent();
476 // The assumptions I make here really should hold.
477 QQuickView *quickView =
478 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
480 QQuickItem *shell = quickView->rootObject();
482 m_sideStage = qobject_cast<QQuickItem *>(m_sideStageComponent->create());
483 m_sideStage->setParentItem(shell);
484 m_sideStage->setFlag(QQuickItem::ItemHasContents, false);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list