summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/services/genericunix/qgenericunixservices.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/platformsupport/services/genericunix/qgenericunixservices.cpp')
-rw-r--r--src/platformsupport/services/genericunix/qgenericunixservices.cpp59
1 files changed, 50 insertions, 9 deletions
diff --git a/src/platformsupport/services/genericunix/qgenericunixservices.cpp b/src/platformsupport/services/genericunix/qgenericunixservices.cpp
index cb1e367b9f..67884cef92 100644
--- a/src/platformsupport/services/genericunix/qgenericunixservices.cpp
+++ b/src/platformsupport/services/genericunix/qgenericunixservices.cpp
@@ -50,7 +50,7 @@
#include <QtCore/QUrl>
#if QT_CONFIG(dbus)
-// These QtCore includes are needed for flatpak support
+// These QtCore includes are needed for xdg-desktop-portal support
#include <QtCore/private/qcore_unix_p.h>
#include <QtCore/QFileInfo>
@@ -172,12 +172,47 @@ static inline bool launch(const QString &launcher, const QUrl &url)
}
#if QT_CONFIG(dbus)
-static inline bool checkRunningUnderFlatpak()
+static inline bool checkNeedPortalSupport()
{
- return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QLatin1String("flatpak-info")).isEmpty();
+ return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QLatin1String("flatpak-info")).isEmpty() || qEnvironmentVariableIsSet("SNAP");
}
-static inline bool flatpakOpenUrl(const QUrl &url)
+static inline bool xdgDesktopPortalOpenFile(const QUrl &url)
+{
+ // DBus signature:
+ // OpenFile (IN s parent_window,
+ // IN h fd,
+ // IN a{sv} options,
+ // OUT o handle)
+ // Options:
+ // handle_token (s) - A string that will be used as the last element of the @handle.
+ // writable (b) - Whether to allow the chosen application to write to the file.
+
+#ifdef O_PATH
+ const int fd = qt_safe_open(QFile::encodeName(url.toLocalFile()), O_PATH);
+ if (fd != -1) {
+ QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.portal.Desktop"),
+ QLatin1String("/org/freedesktop/portal/desktop"),
+ QLatin1String("org.freedesktop.portal.OpenURI"),
+ QLatin1String("OpenFile"));
+
+ QDBusUnixFileDescriptor descriptor(fd);
+ qt_safe_close(fd);
+
+ // FIXME parent_window_id and handle writable option
+ message << QString() << QVariant::fromValue(descriptor) << QVariantMap();
+
+ QDBusPendingReply<QDBusObjectPath> reply = QDBusConnection::sessionBus().call(message);
+ return !reply.isError();
+ }
+#else
+ Q_UNUSED(url)
+#endif
+
+ return false;
+}
+
+static inline bool xdgDesktopPortalOpenUrl(const QUrl &url)
{
// DBus signature:
// OpenURI (IN s parent_window,
@@ -185,6 +220,7 @@ static inline bool flatpakOpenUrl(const QUrl &url)
// IN a{sv} options,
// OUT o handle)
// Options:
+ // handle_token (s) - A string that will be used as the last element of the @handle.
// writable (b) - Whether to allow the chosen application to write to the file.
// This key only takes effect the uri points to a local file that is exported in the document portal,
// and the chosen application is sandboxed itself.
@@ -200,7 +236,7 @@ static inline bool flatpakOpenUrl(const QUrl &url)
return !reply.isError();
}
-static inline bool flatpakSendEmail(const QUrl &url)
+static inline bool xdgDesktopPortalSendEmail(const QUrl &url)
{
// DBus signature:
// ComposeEmail (IN s parent_window,
@@ -258,15 +294,15 @@ bool QGenericUnixServices::openUrl(const QUrl &url)
{
if (url.scheme() == QLatin1String("mailto")) {
#if QT_CONFIG(dbus)
- if (checkRunningUnderFlatpak())
- return flatpakSendEmail(url);
+ if (checkNeedPortalSupport())
+ return xdgDesktopPortalSendEmail(url);
#endif
return openDocument(url);
}
#if QT_CONFIG(dbus)
- if (checkRunningUnderFlatpak())
- return flatpakOpenUrl(url);
+ if (checkNeedPortalSupport())
+ return xdgDesktopPortalOpenUrl(url);
#endif
if (m_webBrowser.isEmpty() && !detectWebBrowser(desktopEnvironment(), true, &m_webBrowser)) {
@@ -278,6 +314,11 @@ bool QGenericUnixServices::openUrl(const QUrl &url)
bool QGenericUnixServices::openDocument(const QUrl &url)
{
+#if QT_CONFIG(dbus)
+ if (checkNeedPortalSupport())
+ return xdgDesktopPortalOpenFile(url);
+#endif
+
if (m_documentLauncher.isEmpty() && !detectWebBrowser(desktopEnvironment(), false, &m_documentLauncher)) {
qWarning("Unable to detect a launcher for '%s'", qPrintable(url.toString()));
return false;