[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [plasmate/frameworks] plasmoidviewer: take the screenshots correctly
From: Antonis Tsiapaliokas <kok3rs () gmail ! com>
Date: 2014-02-20 16:52:24
Message-ID: E1WGWrI-0007TZ-VA () scm ! kde ! org
[Download RAW message or body]
Git commit 62e6878a0141008bb6eb2f32c4115c28cf6eb384 by Antonis Tsiapaliokas, on behalf of Giorgos Tsiapaliokas.
Committed on 24/11/2013 at 20:22.
Pushed by tsiapaliokas into branch 'frameworks'.
take the screenshots correctly
M +30 -8 plasmoidviewer/view.cpp
M +1 -1 plasmoidviewer/view.h
http://commits.kde.org/plasmate/62e6878a0141008bb6eb2f32c4115c28cf6eb384
diff --git a/plasmoidviewer/view.cpp b/plasmoidviewer/view.cpp
index 21c8713..a5a65a0 100644
--- a/plasmoidviewer/view.cpp
+++ b/plasmoidviewer/view.cpp
@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <QFileDialog>
#include <QQmlEngine>
#include <QQuickItem>
#include <QQmlContext>
@@ -23,6 +24,8 @@
#include <QDBusReply>
#include <QDebug>
+#include <KLocalizedString>
+
#include <Plasma/Package>
#include <Plasma/PluginLoader>
@@ -200,19 +203,38 @@ Plasma::Corona *View::createCorona()
return cor;
}
-QString View::takeScreenShot()
+void View::takeScreenShot()
{
QDBusInterface interface(QStringLiteral("org.kde.kwin"), QStringLiteral("/Screenshot"),
QStringLiteral("org.kde.kwin.Screenshot"));
- QDBusReply<QString> reply = interface.call(QStringLiteral("screenshotArea"), x(), y(), width(), height());
+ QDBusPendingCall async = interface.asyncCall(QStringLiteral("screenshotArea"), x(), y(),
+ width(), height());
- if (!reply.isValid()) {
- qDebug() << "The screenshot has failed, the reply is invalid with error" << reply.error().message();
- return QString();
- }
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);
- return reply.value();
-}
+ connect(watcher,&QDBusPendingCallWatcher::finished, [](QDBusPendingCallWatcher *call) {
+ QDBusPendingReply<QString> reply = *call;
+ call->deleteLater();
+
+ if (!reply.isValid()) {
+ qDebug() << "The screenshot has failed, the reply is invalid with error" << reply.error().message();
+ return;
+ }
+
+ QString dest = QFileDialog::getSaveFileName(0,i18n("Save Screenshot"),
+ QDir::homePath(), QStringLiteral("Images (.*png)"));
+ if (dest.isEmpty()) {
+ return;
+ }
+
+ if (!dest.endsWith(QStringLiteral(".png"))) {
+ dest.append(QStringLiteral(".png"));
+ }
+
+ QFile f(reply.value());
+ f.rename(dest);
+ });
+}
#include "moc_view.cpp"
diff --git a/plasmoidviewer/view.h b/plasmoidviewer/view.h
index 4692b28..c20d98e 100644
--- a/plasmoidviewer/view.h
+++ b/plasmoidviewer/view.h
@@ -35,7 +35,7 @@ public:
Q_INVOKABLE void changeFormFactor(int formFactor);
Q_INVOKABLE void changeLocation(int location);
- Q_INVOKABLE QString takeScreenShot();
+ Q_INVOKABLE void takeScreenShot();
static Plasma::Corona *createCorona();
private:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic