2 * Copyright (C) 2015 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/>.
18#include "sessiongrabber.h"
22#include <QQuickItemGrabResult>
23#include <QtConcurrent>
25static QString cacheFolder()
27 return QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/app_shots/";
30static QString cachePath(const QString &appId)
32 return cacheFolder() + appId + ".png";
35SessionGrabber::SessionGrabber(QObject *parent)
42QString SessionGrabber::appId() const
47void SessionGrabber::setAppId(const QString &appId)
49 if (appId != m_appId) {
51 const QString path = cachePath(appId);
52 if (QFile::exists(path)) {
58QQuickItem *SessionGrabber::target() const
63void SessionGrabber::setTarget(QQuickItem *target)
65 if (target != m_target) {
67 Q_EMIT targetChanged();
71QString SessionGrabber::path() const
76void SessionGrabber::setPath(const QString &path)
84static QString saveScreenshot(const QString &appId, const QSharedPointer<QQuickItemGrabResult> grabResult)
86 const QImage image = grabResult->image();
87 const QString cPath = cacheFolder();
90 const QString path = cachePath(appId);
91 if (image.save(path)) {
98void SessionGrabber::grab()
100 if (!m_grabResult.isNull()) {
101 qWarning() << "Asked to grab a screenshot when there's one already being grabbed, ignoring";
105 if (m_target && !m_appId.isEmpty()) {
106 // grabToImage runs in a separate thread
107 m_grabResult = m_target->grabToImage();
108 connect(m_grabResult.data(), &QQuickItemGrabResult::ready, this, &SessionGrabber::grabReady);
110 qWarning() << "Can't grab screnshot: appId:" << m_appId << " target:" << m_target;
114void SessionGrabber::removeScreenshot()
116 const QString path = cachePath(m_appId);
120void SessionGrabber::grabReady()
122 QFuture<QString> f = QtConcurrent::run(saveScreenshot, m_appId, m_grabResult);
123 m_watcher = new QFutureWatcher<QString>(this);
124 m_watcher->setFuture(f);
125 connect(m_watcher, &QFutureWatcher<QString>::finished, this, &SessionGrabber::saveFinished);
128void SessionGrabber::saveFinished()
130 setPath(m_watcher->future().result());
133 m_grabResult.clear();
134 Q_EMIT screenshotGrabbed();
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