<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hello Jan,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
finally I found some time to upgrade my OS and got a newer Plasma Version but I'm still struggling with the Screenshot Portal.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Here is my implementation, almost identical to yours from the test that you have linked me (pasting here only the relevant methods):</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<pre style="background-color:#2b2b2b; color:#a9b7c6; font-family:'JetBrains Mono',monospace; font-size:9.8pt"><span style="color:#cc7832">void </span><span style="color:#b5b6e3">WaylandImageGrabber</span>::<span style="color:#ffc66d">grab</span>()<br>{<br> <span style="color:#cc7832">auto </span>message = <span style="color:#b5b6e3">QDBusMessage</span>::createMethodCall(<span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"org.freedesktop.portal.Desktop"</span>)<span style="color:#cc7832">,<br></span><span style="color:#cc7832"> </span><span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"/org/freedesktop/portal/desktop"</span>)<span style="color:#cc7832">,<br></span><span style="color:#cc7832"> </span><span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"org.freedesktop.portal.Screenshot"</span>)<span style="color:#cc7832">,<br></span><span style="color:#cc7832"> </span><span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"Screenshot"</span>))<span style="color:#cc7832">;<br></span><span style="color:#cc7832"><br></span><span style="color:#cc7832"> </span>message <span style="color:#5f8c8a"><< </span><span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"wayland:"</span>) <span style="color:#5f8c8a"><< </span><span style="color:#b9bcd1">QVariantMap</span>{{<span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"interactive"</span>)<span style="color:#cc7832">, false</span>}<span style="color:#cc7832">, </span>{<span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"handle_token"</span>)<span style="color:#cc7832">, </span>getRequestToken()}}<span style="color:#cc7832">;<br></span><span style="color:#cc7832"><br></span><span style="color:#cc7832"> auto </span>pendingCall = <span style="color:#b5b6e3">QDBusConnection</span>::sessionBus().asyncCall(message)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> auto </span>watcher = <span style="color:#cc7832">new </span><span style="color:#b5b6e3">QDBusPendingCallWatcher</span>(pendingCall)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> </span>connect(watcher<span style="color:#cc7832">, </span>&<span style="color:#b5b6e3">QDBusPendingCallWatcher</span>::finished<span style="color:#cc7832">, </span>[<span style="color:#cc7832">this</span>] (<span style="color:#b5b6e3">QDBusPendingCallWatcher </span>*watcher) {<br> <span style="color:#b5b6e3">QDBusPendingReply</span><<span style="color:#b5b6e3">QDBusObjectPath</span>> reply = *watcher<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> if </span>(reply.isError()) {<br> <span style="color:#908b25">qDebug</span>(<span style="color:#6a8759">"Couldn't get reply"</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> </span><span style="color:#908b25">qWarning</span>(<span style="color:#6a8759">"Error: %s"</span><span style="color:#cc7832">, </span><span style="color:#908b25">qPrintable</span>(reply.error().message()))<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> </span>} <span style="color:#cc7832">else </span>{<br> <span style="color:#908b25">qDebug</span>(<span style="color:#6a8759">"Got reply"</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> </span><span style="color:#b5b6e3">QDBusConnection</span>::sessionBus().connect(<span style="color:#b5b6e3">QString</span>()<span style="color:#cc7832">,<br></span><span style="color:#cc7832"> </span>reply.value().path()<span style="color:#cc7832">,<br></span><span style="color:#cc7832"> </span><span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"org.freedesktop.portal.Request"</span>)<span style="color:#cc7832">,<br></span><span style="color:#cc7832"> </span><span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"Response"</span>)<span style="color:#cc7832">,<br></span><span style="color:#cc7832"> this,<br></span><span style="color:#cc7832"> </span><span style="color:#908b25">SLOT</span>(gotScreenshotResponse(uint<span style="color:#cc7832">,</span>QVariantMap)))<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> </span>}<br> })<span style="color:#cc7832">;<br></span>}</pre>
<pre style="background-color:#2b2b2b; color:#a9b7c6; font-family:'JetBrains Mono',monospace; font-size:9.8pt"><span style="color:#cc7832">void </span><span style="color:#b5b6e3">WaylandImageGrabber</span>::<span style="color:#ffc66d">gotScreenshotResponse</span>(<span style="color:#b9bcd1">uint </span>response<span style="color:#cc7832">, const </span><span style="color:#b9bcd1">QVariantMap</span>& results)<br>{<br> <span style="color:#908b25">qDebug</span>(<span style="color:#6a8759">"Response called"</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> if </span>(!response) {<br> <span style="color:#cc7832">if </span>(results.contains(<span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"uri"</span>))) {<br> <span style="color:#908b25">qDebug</span>(<span style="color:#6a8759">"Success"</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> </span><span style="color:#908b25">emit </span>finished(<span style="color:#b5b6e3">CaptureDto</span>(<span style="color:#b5b6e3">QPixmap</span>::fromImage(<span style="color:#b5b6e3">QImage</span>(results.value(<span style="color:#b5b6e3">QLatin1String</span>(<span style="color:#6a8759">"uri"</span>)).toString()))))<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> </span>}<br> } <span style="color:#cc7832">else </span>{<br> <span style="color:#908b25">qDebug</span>(<span style="color:#6a8759">"Failed to take screenshot"</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"> </span>}<br>}</pre>
<pre style="background-color:#2b2b2b; color:#a9b7c6; font-family:'JetBrains Mono',monospace; font-size:9.8pt"><span style="color:#b5b6e3">QString WaylandImageGrabber</span>::<span style="color:#ffc66d">getRequestToken</span>()<br>{<br> <span style="color:#9373a5">mRequestTokenCounter </span>+= <span style="color:#6897bb">1</span><span style="color:#cc7832">;<br></span><span style="color:#cc7832"> return </span><span style="color:#b5b6e3">QString</span>(<span style="color:#6a8759">"u%1"</span>).arg(<span style="color:#9373a5">mRequestTokenCounter</span>)<span style="color:#cc7832">;<br></span>}</pre>
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I get the dialog which asks me what type of screenshot I want to take I select it, a small image is show in the dialog and I can click on save (which saves the image in my home directory) but the gotScreenshotResponse is never called. Any idea why?</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Can I tell the dialog where to save those images? </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Can I tell the dialog right away what type of screenshot I want to take?</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Can I just share the screenshot with my application without saving it? </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Thanks in advance for your help!</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Best regards,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Damir</div>
<div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> kde-devel <kde-devel-bounces@kde.org> on behalf of Damir Porobic <damir_porobic@live.com><br>
<b>Sent:</b> Monday, August 31, 2020 13:22<br>
<b>To:</b> kde-devel@kde.org <kde-devel@kde.org><br>
<b>Subject:</b> Re: Using xdg-desktop-portal-kde to take screenshots</font>
<div> </div>
</div>
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Thanks, that helps. I'll upgrade my OS, the latest version seems to ship Plasma 5.18</div>
<div>
<div id="x_appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Best regards,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Damir</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> kde-devel <kde-devel-bounces@kde.org> on behalf of Jan Grulich <jgrulich@redhat.com><br>
<b>Sent:</b> Monday, August 31, 2020 11:04<br>
<b>To:</b> kde-devel@kde.org <kde-devel@kde.org><br>
<b>Subject:</b> Re: Using xdg-desktop-portal-kde to take screenshots</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div>Hi,</div>
<div><br>
</div>
<div>unfortunately the Screenshot portal doesn't seem to be present in Plasma 5.12, it was added into Plasma 5.13.</div>
<div><br>
</div>
<div>Regards,</div>
<div>Jan</div>
<br>
<div class="x_x_gmail_quote">
<div dir="ltr" class="x_x_gmail_attr">ne 30. 8. 2020 v 10:38 odesílatel Damir Porobic <<a href="mailto:damir_porobic@live.com">damir_porobic@live.com</a>> napsal:<br>
</div>
<blockquote class="x_x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hey Jan,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
thanks for the Feedback, that is indeed a good tip, I'll have a look at it. </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Another question, do I need to activate it or is it available only after a specific version? </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I'm using Plasma 5.12.8 and it doesn't seem to be available. </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Regards,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Damir</div>
<div>
<div id="x_x_gmail-m_8160184555874344254appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr style="display:inline-block; width:98%">
<div id="x_x_gmail-m_8160184555874344254divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> kde-devel <<a href="mailto:kde-devel-bounces@kde.org" target="_blank">kde-devel-bounces@kde.org</a>> on behalf
of Jan Grulich <<a href="mailto:jgrulich@redhat.com" target="_blank">jgrulich@redhat.com</a>><br>
<b>Sent:</b> Sunday, August 23, 2020 14:58<br>
<b>To:</b> <a href="mailto:kde-devel@kde.org" target="_blank">kde-devel@kde.org</a> <<a href="mailto:kde-devel@kde.org" target="_blank">kde-devel@kde.org</a>><br>
<b>Subject:</b> Re: Using xdg-desktop-portal-kde to take screenshots</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">Hi,
<div><br>
</div>
<div>you can check how we use it in xdg-portal-test-kde (a simple app to test various portals).</div>
<div><br>
</div>
<div>The code is here: <a href="https://invent.kde.org/libraries/xdg-portal-test-kde/-/blob/master/src/portaltest.cpp#L498" target="_blank">https://invent.kde.org/libraries/xdg-portal-test-kde/-/blob/master/src/portaltest.cpp#L498</a></div>
<div><br>
</div>
<div>Regards,</div>
<div>Jan</div>
</div>
<br>
<div>
<div dir="ltr">út 18. 8. 2020 v 12:59 odesílatel Méven <<a href="mailto:meven29@gmail.com" target="_blank">meven29@gmail.com</a>> napsal:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr">Le mar. 18 août 2020 à 12:04, <<a href="mailto:kde-devel-request@kde.org" target="_blank">kde-devel-request@kde.org</a>> a écrit :<br>
</div>
<div>
<blockquote style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
Date: Mon, 17 Aug 2020 12:44:35 +0000<br>
From: Damir Porobic <<a href="mailto:damir_porobic@live.com" target="_blank">damir_porobic@live.com</a>><br>
To: "<a href="mailto:kde-devel@kde.org" target="_blank">kde-devel@kde.org</a>" <<a href="mailto:kde-devel@kde.org" target="_blank">kde-devel@kde.org</a>><br>
Subject: Re: Using xdg-desktop-portal-kde to take screenshots<br>
Message-ID:<br>
<<a href="mailto:AM0PR09MB389099FAC1A15B22F0E6D4AFE55F0@AM0PR09MB3890.eurprd09.prod.outlook.com" target="_blank">AM0PR09MB389099FAC1A15B22F0E6D4AFE55F0@AM0PR09MB3890.eurprd09.prod.outlook.com</a>><br>
<br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Hello,<br>
<br>
has anyone experience with this portal?<br>
<br>
Best regards,<br>
Damir<br>
<br>
________________________________<br>
From: kde-devel <<a href="mailto:kde-devel-bounces@kde.org" target="_blank">kde-devel-bounces@kde.org</a>> on behalf of Damir Porobic <<a href="mailto:damir_porobic@live.com" target="_blank">damir_porobic@live.com</a>><br>
Sent: Thursday, August 13, 2020 16:16<br>
To: <a href="mailto:kde-devel@kde.org" target="_blank">kde-devel@kde.org</a> <<a href="mailto:kde-devel@kde.org" target="_blank">kde-devel@kde.org</a>><br>
Subject: Using xdg-desktop-portal-kde to take screenshots<br>
<br>
Hello,<br>
<br>
I'm trying use the xdg-desktop-portal-kde (<a href="https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/blob/master/src/screenshot.cpp" rel="noreferrer" target="_blank">https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/blob/master/src/screenshot.cpp</a>)
portal in order to take screenshots under Wayland.<br>
<br>
If I understand correctly, making a DBus Call like this should open a Dialog with a Screenshot that can be shared with my application.<br>
<br>
*********************************<br>
QDBusInterface interface(QStringLiteral("org.freedesktop.portal.Desktop"), QStringLiteral("/org/freedesktop/portal/Screenshot"), QStringLiteral("org.freedesktop.portal.Screenshot"));<br>
QDBusPendingReply<QDBusObjectPath> reply;<br>
<br>
reply = interface.call(QStringLiteral("Screenshot"), "", QVariantMap());<br>
<br>
if (reply.isError()) {<br>
qCritical("Invalid reply from DBus: %s", qPrintable(reply.error().message()));<br>
emit canceled();<br>
} else {<br>
qCritical("Dbus success: %s", qPrintable(reply.argumentAt<0>().path()));<br>
}<br>
*********************************<br>
<br>
But the path to the image is not returned in the result from this call. How am I supposed to get the result?<br>
<br>
Is there any example implementation that uses this portal? In Spectacle I have only seen the solution using org.kde.plasmashell, but not the portal solution.<br>
<br>
Thanks in advance!<br>
<br>
Best regards<br>
Damir<br>
</blockquote>
<div> </div>
</div>
<div>Hi Damir,</div>
<div><br>
</div>
<div></div>
<div>You need to pass an instance of QVariantMap that will be filled up with a uri field according to the code:</div>
<div><br>
</div>
<div>auto result = QVariantMap();</div>
<div>reply = interface.call(QStringLiteral("Screenshot"), "", &result);</div>
<div>result.value("uri");</div>
<div><br>
</div>
<div>But you might be missing parameters also :</div>
<div><br>
</div>
<div> uint Screenshot(const QDBusObjectPath &handle,<br>
const QString &app_id,<br>
const QString &parent_window,<br>
const QVariantMap &options,<br>
QVariantMap &results);</div>
<div><br>
</div>
<div>Also the file is saved in QStandardPaths::PicturesLocation with a timestamp.</div>
<div><br>
</div>
<div>Documentation is at <a href="https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#gdbus-org.freedesktop.impl.portal.Screenshot" target="_blank">
https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#gdbus-org.freedesktop.impl.portal.Screenshot</a></div>
<div><br>
</div>
<div>I hope this helps,</div>
<div><br>
</div>
<div>Kind regards,<br>
</div>
<div><br>
</div>
<div>
<div>-- </div>
<div dir="ltr">Méven</div>
</div>
</div>
</blockquote>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>