on xenial help sign in
Review fixlets
commitdf7050acb77f755aa0fee278e34c26f5794d01f2 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 28 Apr 2015, 13:24 (12 years ago) parentb63fa92
6 files changed+37−37
plugins/SessionGrabber/CMakeLists.txt+1−6 plugins/SessionGrabber/SessionGrabber.qmltypes+1−1 plugins/SessionGrabber/sessiongrabber.cpp+18−14 plugins/SessionGrabber/sessiongrabber.h+9−9 qml/Stages/ApplicationWindow.qml+4−3 tests/plugins/SessionGrabber/sessiongrabbertest.cpp+4−4
plugins/SessionGrabber/CMakeLists.txt+1−6
@@ -2,12 +2,7 @@ include_directories(
22 ${CMAKE_CURRENT_BINARY_DIR}
33)
44
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)
116qt5_use_modules(SessionGrabber-qml Qml Gui Quick Concurrent)
127
138add_unity8_plugin(SessionGrabber 0.1 SessionGrabber TARGETS SessionGrabber-qml)
plugins/SessionGrabber/SessionGrabber.qmltypes+1−1
@@ -15,7 +15,7 @@ Module {
1515 Property { name: "appId"; type: "string" }
1616 Property { name: "path"; type: "string"; isReadonly: true }
1717 Property { name: "target"; type: "QQuickItem"; isPointer: true }
18− Signal { name: "appdIdChanged" }
18+ Signal { name: "appIdChanged" }
1919 Signal { name: "screenshotTaken" }
2020 Method { name: "take" }
2121 Method { name: "removeScreenshot" }
plugins/SessionGrabber/sessiongrabber.cpp+18−14
@@ -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}
plugins/SessionGrabber/sessiongrabber.h+9−9
@@ -35,38 +35,38 @@ class SessionGrabber : public QObject
3535 Q_OBJECT
3636
3737 /// 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)
3939
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.
4141 Q_PROPERTY(QString path READ path NOTIFY pathChanged)
4242
43− /// target item for the screenshot taking.
43+ /// target item for the screenshot grabbing.
4444 Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
4545
4646public:
4747 explicit SessionGrabber(QObject *parent = 0);
4848
4949 QString appId() const;
50− void setAppdId(const QString &appId);
50+ void setAppId(const QString &appId);
5151
5252 QQuickItem *target() const;
5353 void setTarget(QQuickItem *target);
5454
5555 QString path() const;
5656
57− /// Starts taking a screenshot. Emits screenshotTaken when ready.
58− Q_INVOKABLE void take();
57+ /// Starts grabbing a screenshot. Emits screenshotGrabbed when ready.
58+ Q_INVOKABLE void grab();
5959
6060 /// Removes the existing screenshot
6161 Q_INVOKABLE void removeScreenshot();
6262
6363Q_SIGNALS:
64− void appdIdChanged();
64+ void appIdChanged();
6565 void targetChanged();
6666 void pathChanged();
6767
68− /// Signals screenshot taking has finished.
69− void screenshotTaken();
68+ /// Signals screenshot grabbing has finished.
69+ void screenshotGrabbed();
7070
7171private Q_SLOTS:
7272 void grabReady();
qml/Stages/ApplicationWindow.qml+4−3
@@ -59,7 +59,7 @@ FocusScope {
5959 && (d.applicationState === ApplicationInfoInterface.Stopped || d.applicationState === ApplicationInfoInterface.Suspended)
6060 onNeedToTakeScreenshotChanged: {
6161 if (needToTakeScreenshot) {
62− sessionGrabber.take();
62+ sessionGrabber.grab();
6363 }
6464 }
6565
@@ -79,7 +79,7 @@ FocusScope {
7979 Image {
8080 id: screenshotImage
8181 objectName: "screenshotImage"
82− source: sessionGrabber.path != "" ? sessionGrabber.path : d.defaultScreenshot
82+ source: sessionGrabber.path || d.defaultScreenshot
8383 anchors.fill: parent
8484 antialiasing: !root.interactive
8585 cache: false
@@ -103,7 +103,8 @@ FocusScope {
103103 appId: d.appId
104104 target: root
105105
106− onScreenshotTaken: {
106+ onScreenshotGrabbed: {
107+ // Need to reset to "" and back since it may be the same path with new content
107108 screenshotImage.source = "";
108109 screenshotImage.source = sessionGrabber.path;
109110 }
tests/plugins/SessionGrabber/sessiongrabbertest.cpp+4−4
@@ -38,14 +38,14 @@ private Q_SLOTS:
3838 void testSessionGrabber()
3939 {
4040 SessionGrabber s;
41− s.setAppdId("test-app-id");
41+ s.setAppId("test-app-id");
4242 s.setTarget(view->rootObject());
43− QSignalSpy spy(&s, &SessionGrabber::screenshotTaken);
43+ QSignalSpy spy(&s, &SessionGrabber::screenshotGrabbed);
4444
4545 QVERIFY(!QFile::exists(s.path()));
4646
4747 view->rootObject()->setProperty("color", "red");
48− s.take();
48+ s.grab();
4949 spy.wait();
5050
5151 QVERIFY(QFile::exists(s.path()));
@@ -53,7 +53,7 @@ private Q_SLOTS:
5353 QCOMPARE(image.pixel(0, 0), qRgb(255, 0, 0));
5454
5555 view->rootObject()->setProperty("color", "blue");
56− s.take();
56+ s.grab();
5757 spy.wait();
5858
5959 QVERIFY(QFile::exists(s.path()));