summaryrefslogtreecommitdiffstats
path: root/src/platformsupport
diff options
context:
space:
mode:
authorJan Grulich <jgrulich@redhat.com>2018-04-12 10:56:47 +0200
committerJan Grulich <jgrulich@redhat.com>2018-04-13 07:19:17 +0000
commit369e7572bac94bb5b83ef881012fdc4a86829496 (patch)
treeb89c603cd8377c9ef4e1d1073ab5063123d951c9 /src/platformsupport
parent8aa51e66274442a794ab0eafca5c1103f4da3525 (diff)
Add support for opening files in OpenURI flatpak portal
Adds support for opening files in applications outside sandbox. To prove we have access to given file, we have to pass it as file descriptor. The user then gets a dialog with list of application which can be used to open given file. Change-Id: Ifb4cf3dece15d0792b8eb1b90a240da2d3f3c89e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/platformsupport')
-rw-r--r--src/platformsupport/services/genericunix/qgenericunixservices.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/platformsupport/services/genericunix/qgenericunixservices.cpp b/src/platformsupport/services/genericunix/qgenericunixservices.cpp
index cb1e367b9f..adfa3121e0 100644
--- a/src/platformsupport/services/genericunix/qgenericunixservices.cpp
+++ b/src/platformsupport/services/genericunix/qgenericunixservices.cpp
@@ -177,6 +177,39 @@ static inline bool checkRunningUnderFlatpak()
return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QLatin1String("flatpak-info")).isEmpty();
}
+static inline bool flatpakOpenFile(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();
+ }
+#endif
+
+ return false;
+}
+
static inline bool flatpakOpenUrl(const QUrl &url)
{
// DBus signature:
@@ -185,6 +218,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.
@@ -278,6 +312,11 @@ bool QGenericUnixServices::openUrl(const QUrl &url)
bool QGenericUnixServices::openDocument(const QUrl &url)
{
+#if QT_CONFIG(dbus)
+ if (checkRunningUnderFlatpak())
+ return flatpakOpenFile(url);
+#endif
+
if (m_documentLauncher.isEmpty() && !detectWebBrowser(desktopEnvironment(), false, &m_documentLauncher)) {
qWarning("Unable to detect a launcher for '%s'", qPrintable(url.toString()));
return false;