on 43b1644 help sign in
unity8/plugins/SessionGrabber/sessiongrabber.h
85 lines 2.4 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 */
18#ifndef SESSIONGRABBER_H
19#define SESSIONGRABBER_H
21#include <QObject>
22#include <QSharedPointer>
23#include <QFutureWatcher>
25class QQuickItem;
26class QQuickItemGrabResult;
28/**
29 * SessionGrabber saves to disk screenshots of the given item.
30 * Images are saved into $HOME/.cache/app_shots/appId.png
31 * It also handles giving back the screenshot path if it already exists (e.g. because a reboot)
32 */
33class SessionGrabber : public QObject
35 Q_OBJECT
37 /// appId is the key of the screenshot name.
38 Q_PROPERTY(QString appId READ appId WRITE setAppId NOTIFY appIdChanged)
40 /// path where the screenshot is saved, can be empty if no screenshot has been grabbed yet.
41 Q_PROPERTY(QString path READ path NOTIFY pathChanged)
43 /// target item for the screenshot grabbing.
44 Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
46public:
47 explicit SessionGrabber(QObject *parent = 0);
49 QString appId() const;
50 void setAppId(const QString &appId);
52 QQuickItem *target() const;
53 void setTarget(QQuickItem *target);
55 QString path() const;
57 /// Starts grabbing a screenshot. Emits screenshotGrabbed when ready.
58 Q_INVOKABLE void grab();
60 /// Removes the existing screenshot
61 Q_INVOKABLE void removeScreenshot();
63Q_SIGNALS:
64 void appIdChanged();
65 void targetChanged();
66 void pathChanged();
68 /// Signals screenshot grabbing has finished.
69 void screenshotGrabbed();
71private Q_SLOTS:
72 void grabReady();
73 void saveFinished();
75private:
76 void setPath(const QString &path);
78 QString m_appId;
79 QString m_path;
80 QQuickItem *m_target;
81 QFutureWatcher<QString> *m_watcher;
82 QSharedPointer<QQuickItemGrabResult> m_grabResult;
83};
85#endif