summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2019-02-28 09:13:10 -0800
committerThiago Macieira <thiago.macieira@intel.com>2019-03-05 17:58:52 +0000
commit1bd3c17c46eb444a7079f3bd6fa5af5950355212 (patch)
tree45f5ecd97f83834a48874496faf8e47259e45450 /src
parent65d2f0d173cb89f028c409f2dc47c494dc9bf964 (diff)
XDG Portal: allow the portal not to be running
For some reason, it may be missing with SNAP. Fixes: QTBUG-74112 Change-Id: Ifa822ecdaaa241968ed7fffd1587966cbd30dcbd Reviewed-by: Jan Grulich <jgrulich@redhat.com> Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/platformsupport/services/genericunix/qgenericunixservices.cpp48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/platformsupport/services/genericunix/qgenericunixservices.cpp b/src/platformsupport/services/genericunix/qgenericunixservices.cpp
index 7fff50b2a1..1128f5d920 100644
--- a/src/platformsupport/services/genericunix/qgenericunixservices.cpp
+++ b/src/platformsupport/services/genericunix/qgenericunixservices.cpp
@@ -179,7 +179,15 @@ static inline bool checkNeedPortalSupport()
return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QLatin1String("flatpak-info")).isEmpty() || qEnvironmentVariableIsSet("SNAP");
}
-static inline bool xdgDesktopPortalOpenFile(const QUrl &url)
+static inline bool isPortalReturnPermanent(const QDBusError &error)
+{
+ // A service unknown error isn't permanent, it just indicates that we
+ // should fall back to the regular way. This check includes
+ // QDBusError::NoError.
+ return error.type() != QDBusError::ServiceUnknown;
+}
+
+static inline QDBusMessage xdgDesktopPortalOpenFile(const QUrl &url)
{
// DBus signature:
// OpenFile (IN s parent_window,
@@ -204,17 +212,16 @@ static inline bool xdgDesktopPortalOpenFile(const QUrl &url)
// FIXME parent_window_id and handle writable option
message << QString() << QVariant::fromValue(descriptor) << QVariantMap();
- QDBusPendingReply<QDBusObjectPath> reply = QDBusConnection::sessionBus().call(message);
- return !reply.isError();
+ return QDBusConnection::sessionBus().call(message);
}
#else
Q_UNUSED(url)
#endif
- return false;
+ return QDBusMessage::createError(QDBusError::InternalError, qt_error_string());
}
-static inline bool xdgDesktopPortalOpenUrl(const QUrl &url)
+static inline QDBusMessage xdgDesktopPortalOpenUrl(const QUrl &url)
{
// DBus signature:
// OpenURI (IN s parent_window,
@@ -234,11 +241,10 @@ static inline bool xdgDesktopPortalOpenUrl(const QUrl &url)
// FIXME parent_window_id and handle writable option
message << QString() << url.toString() << QVariantMap();
- QDBusPendingReply<QDBusObjectPath> reply = QDBusConnection::sessionBus().call(message);
- return !reply.isError();
+ return QDBusConnection::sessionBus().call(message);
}
-static inline bool xdgDesktopPortalSendEmail(const QUrl &url)
+static inline QDBusMessage xdgDesktopPortalSendEmail(const QUrl &url)
{
// DBus signature:
// ComposeEmail (IN s parent_window,
@@ -281,8 +287,7 @@ static inline bool xdgDesktopPortalSendEmail(const QUrl &url)
// FIXME parent_window_id
message << QString() << options;
- QDBusPendingReply<QDBusObjectPath> reply = QDBusConnection::sessionBus().call(message);
- return !reply.isError();
+ return QDBusConnection::sessionBus().call(message);
}
#endif // QT_CONFIG(dbus)
@@ -296,15 +301,23 @@ bool QGenericUnixServices::openUrl(const QUrl &url)
{
if (url.scheme() == QLatin1String("mailto")) {
#if QT_CONFIG(dbus)
- if (checkNeedPortalSupport())
- return xdgDesktopPortalSendEmail(url);
+ if (checkNeedPortalSupport()) {
+ QDBusError error = xdgDesktopPortalSendEmail(url);
+ if (isPortalReturnPermanent(error))
+ return !error.isValid();
+
+ // service not running, fall back
+ }
#endif
return openDocument(url);
}
#if QT_CONFIG(dbus)
- if (checkNeedPortalSupport())
- return xdgDesktopPortalOpenUrl(url);
+ if (checkNeedPortalSupport()) {
+ QDBusError error = xdgDesktopPortalOpenUrl(url);
+ if (isPortalReturnPermanent(error))
+ return !error.isValid();
+ }
#endif
if (m_webBrowser.isEmpty() && !detectWebBrowser(desktopEnvironment(), true, &m_webBrowser)) {
@@ -317,8 +330,11 @@ bool QGenericUnixServices::openUrl(const QUrl &url)
bool QGenericUnixServices::openDocument(const QUrl &url)
{
#if QT_CONFIG(dbus)
- if (checkNeedPortalSupport())
- return xdgDesktopPortalOpenFile(url);
+ if (checkNeedPortalSupport()) {
+ QDBusError error = xdgDesktopPortalOpenFile(url);
+ if (isPortalReturnPermanent(error))
+ return !error.isValid();
+ }
#endif
if (m_documentLauncher.isEmpty() && !detectWebBrowser(desktopEnvironment(), false, &m_documentLauncher)) {