From 40b24cb41e3a16cf68b664f212837eb26d7e1a27 Mon Sep 17 00:00:00 2001
From: Alessandro Astone <ales.astone@gmail.com>
Date: Mon, 28 Aug 2023 16:39:09 +0200
Subject: [PATCH] Allow Transaction::setHints before the transaction has
 started

---
 CMakeLists.txt             | 2 +-
 src/transaction.cpp        | 1 +
 src/transaction.h          | 7 +++++--
 src/transactionprivate.cpp | 2 +-
 src/transactionprivate.h   | 2 ++
 5 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 69c22f7..92c7d72 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,7 +66,7 @@ set (LOCALSTATEDIR "/var")
 set (CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/packagekitqt${QT_VERSION_MAJOR}/")
 
 add_definitions("-DLOCALSTATEDIR=\"${LOCALSTATEDIR}\"")
-set (CMAKE_CXX_STANDARD 11)
+set (CMAKE_CXX_STANDARD 17)
 
 configure_file(config.h.in ${CMAKE_BINARY_DIR}/config.h)
 
diff --git a/src/transaction.cpp b/src/transaction.cpp
index 9c733aa..48f07ed 100644
--- a/src/transaction.cpp
+++ b/src/transaction.cpp
@@ -300,6 +300,7 @@ Transaction::Role Transaction::role() const
 QDBusPendingReply<> Transaction::setHints(const QStringList &hints)
 {
     Q_D(Transaction);
+    d->hints = hints;
     if (d->p) {
         return d->p->SetHints(hints);
     }
diff --git a/src/transaction.h b/src/transaction.h
index 46a2fac..510773e 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -634,11 +634,14 @@ public:
      * the package manager which can change as the transaction runs.
      *
      * This method can be sent before the transaction has been run
-     * (by using Daemon::setHints) or whilst it is running
-     * (by using Transaction::setHints).
+     * or whilst it is running. If it is used before the transaction has
+     * been run, the return value is meaningless: the \p hints will be
+     * applied upon starting the transaction.
      * There is no limit to the number of times this
      * method can be sent, although some backends may only use the values
      * that were set before the transaction was started.
+     * This method will override the global hints previously set by
+     * Daemon::setHints, that are otherwise used by default.
      *
      * The \p hints can be filled with entries like these
      * ('locale=en_GB.utf8','idle=true','interactive=false').
diff --git a/src/transactionprivate.cpp b/src/transactionprivate.cpp
index b4b44b7..550e0ab 100644
--- a/src/transactionprivate.cpp
+++ b/src/transactionprivate.cpp
@@ -49,7 +49,7 @@ void TransactionPrivate::setup(const QDBusObjectPath &transactionId)
                                                          tid.path(),
                                                          QDBusConnection::systemBus(),
                                                          q);
-    QStringList hints = Daemon::global()->hints();
+    QStringList hints = this->hints ? *this->hints : Daemon::global()->hints();
     hints << QStringLiteral("supports-plural-signals=true");
     q->setHints(hints);
 
diff --git a/src/transactionprivate.h b/src/transactionprivate.h
index 69217a8..01463c7 100644
--- a/src/transactionprivate.h
+++ b/src/transactionprivate.h
@@ -26,6 +26,7 @@
 #include <QList>
 #include <QStringList>
 #include <QDBusPendingCallWatcher>
+#include <optional>
 
 #include "transaction.h"
 #include "transactionproxy.h"
@@ -84,6 +85,7 @@ protected:
     bool sentFinished = false;
     bool allowCancel = false;
     bool callerActive = false;
+    std::optional<QStringList> hints;
 
     // Queue params
     QString eulaId;
-- 
2.41.0

