@@ -22,14 +22,19 @@
2222#include <QQuickItemGrabResult>
2323#include <QtConcurrent>
2424
25−static QString cachePath()
25+static QString cacheFolder()
2626{
2727 return QDir::homePath() + "/.cache/app_shots/";
2828}
2929
30+static QString cachePath(const QString &appId)
31+{
32+ return cacheFolder() + appId + ".png";
33+}
34+
3035SessionGrabber::SessionGrabber(QObject *parent)
31− : QObject(parent),
32− m_target(nullptr)
36+ : QObject(parent)
37+ , m_target(nullptr)
3338{
3439}
3540
@@ -38,11 +43,11 @@ QString SessionGrabber::appId() const
3843 return m_appId;
3944}
4045
41−void SessionGrabber::setAppdId(const QString &appId)
46+void SessionGrabber::setAppId(const QString &appId)
4247{
4348 if (appId != m_appId) {
4449 m_appId = appId;
45− const QString path = cachePath() + appId + ".png";
50+ const QString path = cachePath(appId);
4651 if (QFile::exists(path)) {
4752 setPath(path);
4853 }
@@ -78,22 +83,21 @@ void SessionGrabber::setPath(const QString &path)
7883static QString saveScreenshot(const QString &appId, const QSharedPointer<QQuickItemGrabResult> grabResult)
7984{
8085 const QImage image = grabResult->image();
81− const QString cPath = cachePath();
86+ const QString cPath = cacheFolder();
8287 QDir d;
8388 d.mkpath(cPath);
84− const QString path = cPath + appId + ".png";
85− bool b = image.save(path);
86− if (b) {
89+ const QString path = cachePath(appId);
90+ if (image.save(path)) {
8791 return path;
8892 } else {
8993 return QString();
9094 }
9195}
9296
93−void SessionGrabber::take()
97+void SessionGrabber::grab()
9498{
9599 if (!m_grabResult.isNull()) {
96− qWarning() << "Asked to take a screenshot when there's one already being taken, ignoring";
100+ qWarning() << "Asked to grab a screenshot when there's one already being grabbed, ignoring";
97101 return;
98102 }
99103
@@ -102,13 +106,13 @@ void SessionGrabber::take()
102106 m_grabResult = m_target->grabToImage();
103107 connect(m_grabResult.data(), &QQuickItemGrabResult::ready, this, &SessionGrabber::grabReady);
104108 } else {
105− qWarning() << "Can't take screnshot: appId:" << m_appId << " target:" << m_target;
109+ qWarning() << "Can't grab screnshot: appId:" << m_appId << " target:" << m_target;
106110 }
107111}
108112
109113void SessionGrabber::removeScreenshot()
110114{
111− const QString path = cachePath() + m_appId + ".png";
115+ const QString path = cachePath(m_appId);
112116 QFile::remove(path);
113117}
114118
@@ -125,5 +129,5 @@ void SessionGrabber::saveFinished()
125129 setPath(m_watcher->future().result());
126130 m_watcher.clear();
127131 m_grabResult.clear();
128− Q_EMIT screenshotTaken();
132+ Q_EMIT screenshotGrabbed();
129133}