~dandrader/qtmir/keyState

« back to all changes in this revision

Viewing changes to src/modules/Unity/Application/applicationscreenshotprovider.cpp

  • Committer: Gerry Boland
  • Date: 2014-07-01 13:38:06 UTC
  • mto: This revision was merged to the branch mainline in revision 158.
  • Revision ID: gerry.boland@canonical.com-20140701133806-lwfnplkijthydzj4
Update QML plugin: rename to Unity.Application, merge latest unity-mir changes, add tests (not passing yet) and use category logging

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2013 Canonical, Ltd.
 
2
 * Copyright (C) 2013-2014 Canonical, Ltd.
3
3
 *
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"
21
21
 
22
 
// unity-mir
 
22
// QPA-mirserver
23
23
#include "logging.h"
24
24
 
25
25
// mir
26
26
#include <mir/scene/session.h>
27
27
 
28
 
// fallback grid unit used if GRID_UNIT_PX is not in the environment.
29
 
const int defaultGridUnitPx = 8;
 
28
namespace qtmir
 
29
{
30
30
 
31
31
ApplicationScreenshotProvider::ApplicationScreenshotProvider(ApplicationManager *appManager)
32
32
    : QQuickImageProvider(QQuickImageProvider::Image)
34
34
{
35
35
}
36
36
 
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)
39
39
{
40
40
    // We ignore requestedSize here intentionally to avoid keeping scaled copies around
41
41
    Q_UNUSED(requestedSize)
42
42
 
43
 
    DLOG("ApplicationScreenshotProvider::requestImage (this=%p, id=%s)", this, imageId.toLatin1().constData());
 
43
    qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider::requestImage - appId=" << imageId;
44
44
 
45
45
    QString appId = imageId.split('/').first();
46
46
 
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";
50
50
        return QImage();
51
51
    }
52
52
 
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";
57
57
        return QImage();
58
58
    }
59
59
 
60
60
    QImage image = app->screenshotImage();
61
61
 
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());
65
65
 
66
66
    return image;
67
67
}
 
68
 
 
69
} // namespace qtmir