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 "sessionscreenshoter.h"
22#include <QQuickItemGrabResult>
23#include <QtConcurrent>
25static QString cachePath()
27 return QDir::homePath() + "/.cache/app_shots/";
30SessionScreenshoter::SessionScreenshoter(QObject *parent)
37QString SessionScreenshoter::appId() const
42void SessionScreenshoter::setAppdId(const QString &appId)
44 if (appId != m_appId) {
46 const QString path = cachePath() + appId + ".png";
47 if (QFile::exists(path)) {
53QQuickItem *SessionScreenshoter::target() const
58void SessionScreenshoter::setTarget(QQuickItem *target)
60 if (target != m_target) {
62 Q_EMIT targetChanged();
66QString SessionScreenshoter::path() const
71void SessionScreenshoter::setPath(const QString &path)
79static QString saveScreenshot(const QString &appId, const QSharedPointer<QQuickItemGrabResult> grabResult)
81 const QImage image = grabResult->image();
82 const QString cPath = cachePath();
85 const QString path = cPath + appId + ".png";
86 bool b = image.save(path);
94void SessionScreenshoter::take()
96 if (!m_grabResult.isNull()) {
97 qWarning() << "Asked to take a screenshot when there's one already being taken, ignoring";
101 if (m_target && !m_appId.isEmpty()) {
102 // grabToImage runs in a separate thread
103 m_grabResult = m_target->grabToImage();
104 connect(m_grabResult.data(), &QQuickItemGrabResult::ready, this, &SessionScreenshoter::grabReady);
106 qWarning() << "Can't take screnshot: appId:" << m_appId << " target:" << m_target;
110void SessionScreenshoter::removeScreenshot()
112 const QString path = cachePath() + m_appId + ".png";
116void SessionScreenshoter::grabReady()
118 QFuture<QString> f = QtConcurrent::run(saveScreenshot, m_appId, m_grabResult);
119 m_watcher.reset(new QFutureWatcher<QString>(this));
120 m_watcher->setFuture(f);
121 connect(m_watcher.data(), &QFutureWatcher<QString>::finished, this, &SessionScreenshoter::saveFinished);
124void SessionScreenshoter::saveFinished()
126 setPath(m_watcher->future().result());
128 m_grabResult.clear();
129 Q_EMIT screenshotTaken();
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