summaryrefslogtreecommitdiffstats
path: root/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp
diff options
context:
space:
mode:
authorJan Grulich <jgrulich@redhat.com>2020-04-21 21:42:51 +0200
committerJan Grulich <jgrulich@redhat.com>2020-05-14 07:03:55 +0200
commit844967d297327dc72a1aa67644c1b2fa3fe6839c (patch)
treecef975f47c4b1fbfd954d17635989047a19a89e3 /src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp
parent17367462289d73404257967e3af81b1a0f953af5 (diff)
Support opening directories over portal
Recent version of xdg-desktop-portal got support for opening directories through the portal, which means we no longer need to rely on opening the dialog inside sandbox, hoping we have permissions to user directories. [ChangeLog][Linux] QFileDialog will open directories through the portal if required version of xdg-desktop-portal is running on the system. Change-Id: Ifc9035e268f1cc8d9d6a93480e651e0d9e1e9929 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp')
-rw-r--r--src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp
index fb65f6d909..30c43b67dc 100644
--- a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp
+++ b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp
@@ -45,6 +45,12 @@
#include <qpa/qplatformthemefactory_p.h>
#include <qpa/qplatformintegration.h>
+#include <QDBusConnection>
+#include <QDBusMessage>
+#include <QDBusPendingCall>
+#include <QDBusPendingCallWatcher>
+#include <QDBusPendingReply>
+
QT_BEGIN_NAMESPACE
class QXdgDesktopPortalThemePrivate : public QPlatformThemePrivate
@@ -60,6 +66,7 @@ public:
}
QPlatformTheme *baseTheme;
+ uint fileChooserPortalVersion = 0;
};
QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
@@ -90,6 +97,21 @@ QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
// 3) Fall back on the built-in "null" platform theme.
if (!d->baseTheme)
d->baseTheme = new QPlatformTheme;
+
+ // Get information about portal version
+ QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.portal.Desktop"),
+ QLatin1String("/org/freedesktop/portal/desktop"),
+ QLatin1String("org.freedesktop.DBus.Properties"),
+ QLatin1String("Get"));
+ message << QLatin1String("org.freedesktop.portal.FileChooser") << QLatin1String("version");
+ QDBusPendingCall pendingCall = QDBusConnection::sessionBus().asyncCall(message);
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall);
+ QObject::connect(watcher, &QDBusPendingCallWatcher::finished, [d] (QDBusPendingCallWatcher *watcher) {
+ QDBusPendingReply<QVariant> reply = *watcher;
+ if (reply.isValid()) {
+ d->fileChooserPortalVersion = reply.value().toUInt();
+ }
+ });
}
QPlatformMenuItem* QXdgDesktopPortalTheme::createPlatformMenuItem() const
@@ -131,7 +153,9 @@ QPlatformDialogHelper* QXdgDesktopPortalTheme::createPlatformDialogHelper(Dialog
Q_D(const QXdgDesktopPortalTheme);
if (type == FileDialog) {
- if (d->baseTheme->usePlatformNativeDialog(type))
+ // Older versions of FileChooser portal don't support opening directories, therefore we fallback
+ // to native file dialog opened inside the sandbox to open a directory.
+ if (d->fileChooserPortalVersion < 3 && d->baseTheme->usePlatformNativeDialog(type))
return new QXdgDesktopPortalFileDialog(static_cast<QPlatformFileDialogHelper*>(d->baseTheme->createPlatformDialogHelper(type)));
return new QXdgDesktopPortalFileDialog;