on a57ff95 help sign in
unity8/tests/mocks/Unity/Application/ApplicationScreenshotProvider.cpp
69 lines 2.4 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "ApplicationScreenshotProvider.h"
18#include "ApplicationManager.h"
19#include "ApplicationInfo.h"
21#include "paths.h"
23#include <QDebug>
24#include <QGuiApplication>
25#include <QWindow>
26#include <QQuickWindow>
28ApplicationScreenshotProvider::ApplicationScreenshotProvider(ApplicationManager *appManager)
29 : QQuickImageProvider(QQuickImageProvider::Image)
30 , m_appManager(appManager)
34QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize * size,
35 const QSize &requestedSize)
37 // We ignore requestedSize here intentionally to avoid keeping scaled copies around
38 Q_UNUSED(requestedSize)
40 QString appId = imageId.split('/').first();
42 ApplicationInfo* app = static_cast<ApplicationInfo*>(m_appManager->findApplication(appId));
43 if (app == NULL) {
44 qDebug() << "ApplicationScreenshotProvider - app not found:" << appId;
45 return QImage();
46 }
48 QString filePath = QString("%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory()).arg(app->icon().toString());
50 QImage image;
51 if (!image.load(filePath)) {
52 qDebug() << "failed loading app image" << filePath;
53 }
55 QGuiApplication *unity = qobject_cast<QGuiApplication*>(qApp);
57 Q_FOREACH (QWindow *win, unity->allWindows()) {
58 QQuickWindow *quickWin = qobject_cast<QQuickWindow*>(win);
59 if (quickWin) {
60 image = image.scaledToWidth(quickWin->width());
61 }
62 }
64 size->setWidth(image.width());
65 size->setHeight(image.height());
66 qDebug() << "got image of size" << size->width() << size->height() << requestedSize;
68 return image;