From 295e56201da69a6e719e093291ffc488e5b8eff3 Mon Sep 17 00:00:00 2001 From: Gleb Popov Date: Mon, 16 Oct 2023 19:52:11 +0300 Subject: [PATCH] Implement QDBusAbstractInterface::setInteractiveAuthorizationAllowed Task-number: QTBUG-100458 Change-Id: I48d6f17943a554c1173d16a2320eb460c3d5c387 Reviewed-by: Thiago Macieira --- src/dbus/qdbusabstractinterface.cpp | 27 +++++++++++++++++++++++++++ src/dbus/qdbusabstractinterface.h | 3 +++ src/dbus/qdbusabstractinterface_p.h | 1 + 3 files changed, 31 insertions(+) diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp index b2971b9d5f..423aca7b82 100644 --- a/src/dbus/qdbusabstractinterface.cpp +++ b/src/dbus/qdbusabstractinterface.cpp @@ -79,6 +79,7 @@ QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(const QString &serv lastError(checkIfValid(serv, p, iface, isDynamic, (connectionPrivate() && connectionPrivate()->mode == QDBusConnectionPrivate::PeerMode))), timeout(-1), + interactiveAuthorizationAllowed(false), isValid(!lastError.isValid()) { if (!isValid) @@ -396,6 +397,30 @@ int QDBusAbstractInterface::timeout() const return d_func()->timeout; } +/*! + When passed \a enable = \c true it causes all consecutive DBus calls made via + this interface to have the InteractiveAuthorizationAllowed flag set. Passing + false disables this behavior. + + \since 6.7 + \sa QDBusMessage::setInteractiveAuthorizationAllowed() +*/ +void QDBusAbstractInterface::setInteractiveAuthorizationAllowed(bool enable) +{ + d_func()->interactiveAuthorizationAllowed = enable; +} + +/*! + Returns the current value of the InteractiveAuthorizationAllowed flag. + + \since 6.7 + \sa QDBusMessage::setInteractiveAuthorizationAllowed() +*/ +bool QDBusAbstractInterface::isInteractiveAuthorizationAllowed() const +{ + return d_func()->interactiveAuthorizationAllowed; +} + /*! Places a call to the remote method specified by \a method on this interface, using \a args as arguments. This function returns the message that was received as a reply, which can be a normal @@ -488,6 +513,8 @@ QDBusPendingCall QDBusAbstractInterface::asyncCallWithArgumentList(const QString QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), method); QDBusMessagePrivate::setParametersValidated(msg, true); msg.setArguments(args); + if (d->interactiveAuthorizationAllowed) + msg.setInteractiveAuthorizationAllowed(true); return d->connection.asyncCall(msg, d->timeout); } diff --git a/src/dbus/qdbusabstractinterface.h b/src/dbus/qdbusabstractinterface.h index a87b377b0c..8d36fb3728 100644 --- a/src/dbus/qdbusabstractinterface.h +++ b/src/dbus/qdbusabstractinterface.h @@ -63,6 +63,9 @@ public: void setTimeout(int timeout); int timeout() const; + void setInteractiveAuthorizationAllowed(bool enable); + bool isInteractiveAuthorizationAllowed() const; + QDBusMessage call(const QString &method) { return doCall(QDBus::AutoDetect, method, nullptr, 0); diff --git a/src/dbus/qdbusabstractinterface_p.h b/src/dbus/qdbusabstractinterface_p.h index 531be7471c..1bd5e96f2d 100644 --- a/src/dbus/qdbusabstractinterface_p.h +++ b/src/dbus/qdbusabstractinterface_p.h @@ -42,6 +42,7 @@ public: QString interface; mutable QDBusError lastError; int timeout; + bool interactiveAuthorizationAllowed; // this is set during creation and never changed // it can't be const because QDBusInterfacePrivate has one more check