2
* Copyright (C) 2013 Canonical, Ltd.
2
* Copyright (C) 2013-2014 Canonical, Ltd.
4
4
* This program is free software: you can redistribute it and/or modify it under
5
5
* the terms of the GNU Lesser General Public License version 3, as published by
19
19
#include "application_manager.h"
20
20
#include "application.h"
23
23
#include "logging.h"
26
26
#include <mir/scene/session.h>
28
// fallback grid unit used if GRID_UNIT_PX is not in the environment.
29
const int defaultGridUnitPx = 8;
31
31
ApplicationScreenshotProvider::ApplicationScreenshotProvider(ApplicationManager *appManager)
32
32
: QQuickImageProvider(QQuickImageProvider::Image)
37
QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize * size,
38
const QSize &requestedSize)
37
QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize *size,
38
const QSize &requestedSize)
40
40
// We ignore requestedSize here intentionally to avoid keeping scaled copies around
41
41
Q_UNUSED(requestedSize)
43
DLOG("ApplicationScreenshotProvider::requestImage (this=%p, id=%s)", this, imageId.toLatin1().constData());
43
qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider::requestImage - appId=" << imageId;
45
45
QString appId = imageId.split('/').first();
47
47
Application* app = static_cast<Application*>(m_appManager->findApplication(appId));
48
48
if (app == nullptr) {
49
LOG("ApplicationScreenshotProvider - app with appId %s not found", appId.toLatin1().constData());
49
qWarning() << "ApplicationScreenshotProvider - app with appId" << appId << "not found";
53
53
// TODO: if app not ready, return an app-provided splash image. If app has been stopped with saved state
54
54
// return the screenshot that was saved to disk.
55
55
if (!app->session() || !app->session()->default_surface()) {
56
LOG("ApplicationScreenshotProvider - app session not found - asking for screenshot too early");
56
qWarning() << "ApplicationScreenshotProvider - app session not found - asking for screenshot too early";
60
60
QImage image = app->screenshotImage();
62
DLOG("ApplicationScreenshotProvider - working with size %d x %d", image.width(), image.height());
62
qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider - working with size" << image;
63
63
size->setWidth(image.width());
64
64
size->setHeight(image.height());