on xenial help sign in
Review fixlets
df7050aAlbert Astals Cid
plugins/SessionGrabber/CMakeLists.txt+1−6
@@ -2,12 +2,7 @@ include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}
2 ${CMAKE_CURRENT_BINARY_DIR}
3)
3)
4
4
5−set(SOURCES
6− sessiongrabber.cpp
7− plugin.cpp
8−)
9−
10−add_library(SessionGrabber-qml MODULE ${SOURCES})
5+add_library(SessionGrabber-qml MODULE sessiongrabber.cpp plugin.cpp)
11qt5_use_modules(SessionGrabber-qml Qml Gui Quick Concurrent)
6qt5_use_modules(SessionGrabber-qml Qml Gui Quick Concurrent)
12
7
13add_unity8_plugin(SessionGrabber 0.1 SessionGrabber TARGETS SessionGrabber-qml)
8add_unity8_plugin(SessionGrabber 0.1 SessionGrabber TARGETS SessionGrabber-qml)
plugins/SessionGrabber/SessionGrabber.qmltypes+1−1
@@ -15,7 +15,7 @@ Module {
15 Property { name: "appId"; type: "string" }
15 Property { name: "appId"; type: "string" }
16 Property { name: "path"; type: "string"; isReadonly: true }
16 Property { name: "path"; type: "string"; isReadonly: true }
17 Property { name: "target"; type: "QQuickItem"; isPointer: true }
17 Property { name: "target"; type: "QQuickItem"; isPointer: true }
18− Signal { name: "appdIdChanged" }
18+ Signal { name: "appIdChanged" }
19 Signal { name: "screenshotTaken" }
19 Signal { name: "screenshotTaken" }
20 Method { name: "take" }
20 Method { name: "take" }
21 Method { name: "removeScreenshot" }
21 Method { name: "removeScreenshot" }
plugins/SessionGrabber/sessiongrabber.cpp+18−14
@@ -22,14 +22,19 @@
22#include <QQuickItemGrabResult>
22#include <QQuickItemGrabResult>
23#include <QtConcurrent>
23#include <QtConcurrent>
24
24
25−static QString cachePath()
25+static QString cacheFolder()
26{
26{
27 return QDir::homePath() + "/.cache/app_shots/";
27 return QDir::homePath() + "/.cache/app_shots/";
28}
28}
29
29
30+static QString cachePath(const QString &appId)
31+{
32+ return cacheFolder() + appId + ".png";
33+}
34+
30SessionGrabber::SessionGrabber(QObject *parent)
35SessionGrabber::SessionGrabber(QObject *parent)
31− : QObject(parent),
36+ : QObject(parent)
32− m_target(nullptr)
37+ , m_target(nullptr)
33{
38{
34}
39}
35
40
@@ -38,11 +43,11 @@ QString SessionGrabber::appId() const
38 return m_appId;
43 return m_appId;
39}
44}
40
45
41−void SessionGrabber::setAppdId(const QString &appId)
46+void SessionGrabber::setAppId(const QString &appId)
42{
47{
43 if (appId != m_appId) {
48 if (appId != m_appId) {
44 m_appId = appId;
49 m_appId = appId;
45− const QString path = cachePath() + appId + ".png";
50+ const QString path = cachePath(appId);
46 if (QFile::exists(path)) {
51 if (QFile::exists(path)) {
47 setPath(path);
52 setPath(path);
48 }
53 }
@@ -78,22 +83,21 @@ void SessionGrabber::setPath(const QString &path)
78static QString saveScreenshot(const QString &appId, const QSharedPointer<QQuickItemGrabResult> grabResult)
83static QString saveScreenshot(const QString &appId, const QSharedPointer<QQuickItemGrabResult> grabResult)
79{
84{
80 const QImage image = grabResult->image();
85 const QImage image = grabResult->image();
81− const QString cPath = cachePath();
86+ const QString cPath = cacheFolder();
82 QDir d;
87 QDir d;
83 d.mkpath(cPath);
88 d.mkpath(cPath);
84− const QString path = cPath + appId + ".png";
89+ const QString path = cachePath(appId);
85− bool b = image.save(path);
90+ if (image.save(path)) {
86− if (b) {
87 return path;
91 return path;
88 } else {
92 } else {
89 return QString();
93 return QString();
90 }
94 }
91}
95}
92
96
93−void SessionGrabber::take()
97+void SessionGrabber::grab()
94{
98{
95 if (!m_grabResult.isNull()) {
99 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";
97 return;
101 return;
98 }
102 }
99
103
@@ -102,13 +106,13 @@ void SessionGrabber::take()
102 m_grabResult = m_target->grabToImage();
106 m_grabResult = m_target->grabToImage();
103 connect(m_grabResult.data(), &QQuickItemGrabResult::ready, this, &SessionGrabber::grabReady);
107 connect(m_grabResult.data(), &QQuickItemGrabResult::ready, this, &SessionGrabber::grabReady);
104 } else {
108 } 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;
106 }
110 }
107}
111}
108
112
109void SessionGrabber::removeScreenshot()
113void SessionGrabber::removeScreenshot()
110{
114{
111− const QString path = cachePath() + m_appId + ".png";
115+ const QString path = cachePath(m_appId);
112 QFile::remove(path);
116 QFile::remove(path);
113}
117}
114
118
@@ -125,5 +129,5 @@ void SessionGrabber::saveFinished()
125 setPath(m_watcher->future().result());
129 setPath(m_watcher->future().result());
126 m_watcher.clear();
130 m_watcher.clear();
127 m_grabResult.clear();
131 m_grabResult.clear();
128− Q_EMIT screenshotTaken();
132+ Q_EMIT screenshotGrabbed();
129}
133}
plugins/SessionGrabber/sessiongrabber.h+9−9
@@ -35,38 +35,38 @@ class SessionGrabber : public QObject
35 Q_OBJECT
35 Q_OBJECT
36
36
37 /// appId is the key of the screenshot name.
37 /// appId is the key of the screenshot name.
38− Q_PROPERTY(QString appId READ appId WRITE setAppdId NOTIFY appdIdChanged)
38+ Q_PROPERTY(QString appId READ appId WRITE setAppId NOTIFY appIdChanged)
39
39
40− /// path where the screenshot is saved, can be empty if no screenshot has been taken yet.
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)
41 Q_PROPERTY(QString path READ path NOTIFY pathChanged)
42
42
43− /// target item for the screenshot taking.
43+ /// target item for the screenshot grabbing.
44 Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
44 Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
45
45
46public:
46public:
47 explicit SessionGrabber(QObject *parent = 0);
47 explicit SessionGrabber(QObject *parent = 0);
48
48
49 QString appId() const;
49 QString appId() const;
50− void setAppdId(const QString &appId);
50+ void setAppId(const QString &appId);
51
51
52 QQuickItem *target() const;
52 QQuickItem *target() const;
53 void setTarget(QQuickItem *target);
53 void setTarget(QQuickItem *target);
54
54
55 QString path() const;
55 QString path() const;
56
56
57− /// Starts taking a screenshot. Emits screenshotTaken when ready.
57+ /// Starts grabbing a screenshot. Emits screenshotGrabbed when ready.
58− Q_INVOKABLE void take();
58+ Q_INVOKABLE void grab();
59
59
60 /// Removes the existing screenshot
60 /// Removes the existing screenshot
61 Q_INVOKABLE void removeScreenshot();
61 Q_INVOKABLE void removeScreenshot();
62
62
63Q_SIGNALS:
63Q_SIGNALS:
64− void appdIdChanged();
64+ void appIdChanged();
65 void targetChanged();
65 void targetChanged();
66 void pathChanged();
66 void pathChanged();
67
67
68− /// Signals screenshot taking has finished.
68+ /// Signals screenshot grabbing has finished.
69− void screenshotTaken();
69+ void screenshotGrabbed();
70
70
71private Q_SLOTS:
71private Q_SLOTS:
72 void grabReady();
72 void grabReady();
qml/Stages/ApplicationWindow.qml+4−3
@@ -59,7 +59,7 @@ FocusScope {
59 && (d.applicationState === ApplicationInfoInterface.Stopped || d.applicationState === ApplicationInfoInterface.Suspended)
59 && (d.applicationState === ApplicationInfoInterface.Stopped || d.applicationState === ApplicationInfoInterface.Suspended)
60 onNeedToTakeScreenshotChanged: {
60 onNeedToTakeScreenshotChanged: {
61 if (needToTakeScreenshot) {
61 if (needToTakeScreenshot) {
62− sessionGrabber.take();
62+ sessionGrabber.grab();
63 }
63 }
64 }
64 }
65
65
@@ -79,7 +79,7 @@ FocusScope {
79 Image {
79 Image {
80 id: screenshotImage
80 id: screenshotImage
81 objectName: "screenshotImage"
81 objectName: "screenshotImage"
82− source: sessionGrabber.path != "" ? sessionGrabber.path : d.defaultScreenshot
82+ source: sessionGrabber.path || d.defaultScreenshot
83 anchors.fill: parent
83 anchors.fill: parent
84 antialiasing: !root.interactive
84 antialiasing: !root.interactive
85 cache: false
85 cache: false
@@ -103,7 +103,8 @@ FocusScope {
103 appId: d.appId
103 appId: d.appId
104 target: root
104 target: root
105
105
106− onScreenshotTaken: {
106+ onScreenshotGrabbed: {
107+ // Need to reset to "" and back since it may be the same path with new content
107 screenshotImage.source = "";
108 screenshotImage.source = "";
108 screenshotImage.source = sessionGrabber.path;
109 screenshotImage.source = sessionGrabber.path;
109 }
110 }
tests/plugins/SessionGrabber/sessiongrabbertest.cpp+4−4
@@ -38,14 +38,14 @@ private Q_SLOTS:
38 void testSessionGrabber()
38 void testSessionGrabber()
39 {
39 {
40 SessionGrabber s;
40 SessionGrabber s;
41− s.setAppdId("test-app-id");
41+ s.setAppId("test-app-id");
42 s.setTarget(view->rootObject());
42 s.setTarget(view->rootObject());
43− QSignalSpy spy(&s, &SessionGrabber::screenshotTaken);
43+ QSignalSpy spy(&s, &SessionGrabber::screenshotGrabbed);
44
44
45 QVERIFY(!QFile::exists(s.path()));
45 QVERIFY(!QFile::exists(s.path()));
46
46
47 view->rootObject()->setProperty("color", "red");
47 view->rootObject()->setProperty("color", "red");
48− s.take();
48+ s.grab();
49 spy.wait();
49 spy.wait();
50
50
51 QVERIFY(QFile::exists(s.path()));
51 QVERIFY(QFile::exists(s.path()));
@@ -53,7 +53,7 @@ private Q_SLOTS:
53 QCOMPARE(image.pixel(0, 0), qRgb(255, 0, 0));
53 QCOMPARE(image.pixel(0, 0), qRgb(255, 0, 0));
54
54
55 view->rootObject()->setProperty("color", "blue");
55 view->rootObject()->setProperty("color", "blue");
56− s.take();
56+ s.grab();
57 spy.wait();
57 spy.wait();
58
58
59 QVERIFY(QFile::exists(s.path()));
59 QVERIFY(QFile::exists(s.path()));