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 cachePath()
27 return QDir::homePath() + "/.cache/app_shots/";
30SessionGrabber::SessionGrabber(QObject *parent)
36QString SessionGrabber::appId() const
41void SessionGrabber::setAppdId(const QString &appId)
43 if (appId != m_appId) {
45 const QString path = cachePath() + appId + ".png";
46 if (QFile::exists(path)) {
52QQuickItem *SessionGrabber::target() const
57void SessionGrabber::setTarget(QQuickItem *target)
59 if (target != m_target) {
61 Q_EMIT targetChanged();
65QString SessionGrabber::path() const
70void SessionGrabber::setPath(const QString &path)
78static QString saveScreenshot(const QString &appId, const QSharedPointer<QQuickItemGrabResult> grabResult)
80 const QImage image = grabResult->image();
81 const QString cPath = cachePath();
84 const QString path = cPath + appId + ".png";
85 bool b = image.save(path);
93void SessionGrabber::take()
95 if (!m_grabResult.isNull()) {
96 qWarning() << "Asked to take a screenshot when there's one already being taken, ignoring";
100 if (m_target && !m_appId.isEmpty()) {
101 // grabToImage runs in a separate thread
102 m_grabResult = m_target->grabToImage();
103 connect(m_grabResult.data(), &QQuickItemGrabResult::ready, this, &SessionGrabber::grabReady);
105 qWarning() << "Can't take screnshot: appId:" << m_appId << " target:" << m_target;
109void SessionGrabber::removeScreenshot()
111 const QString path = cachePath() + m_appId + ".png";
115void SessionGrabber::grabReady()
117 QFuture<QString> f = QtConcurrent::run(saveScreenshot, m_appId, m_grabResult);
118 m_watcher.reset(new QFutureWatcher<QString>(this));
119 m_watcher->setFuture(f);
120 connect(m_watcher.data(), &QFutureWatcher<QString>::finished, this, &SessionGrabber::saveFinished);
123void SessionGrabber::saveFinished()
125 setPath(m_watcher->future().result());
127 m_grabResult.clear();
128 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