From af28157ad311c38ab8990b1abd2b1a3041c65a22 Mon Sep 17 00:00:00 2001
From: niko_yhc <yinhongchang@kylinsec.com.cn>
Date: Tue, 12 Sep 2023 19:20:14 +0800
Subject: [PATCH 7/7] fix(kiran-session-guard):fits the Qt5.9.7 interface
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 适配Qt5.9.7接口,修复编译报错

Closes:#15019
---
 lib/auth-proxy/auth-controller.cpp | 21 +++++++++++++++++++++
 src/polkit-agent/listener.cpp      | 26 ++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/lib/auth-proxy/auth-controller.cpp b/lib/auth-proxy/auth-controller.cpp
index ce574a2..9d7acd4 100644
--- a/lib/auth-proxy/auth-controller.cpp
+++ b/lib/auth-proxy/auth-controller.cpp
@@ -145,7 +145,12 @@ bool AuthController::processAuthDaemonCommand(const QString& msg)
     auto cmdStr = msg.midRef(strlen(KAP_PROTO_JSON_PREFIX), -1);
     QJsonDocument jsonDoc = QJsonDocument::fromJson(cmdStr.toUtf8());
 
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
     int protoID = jsonDoc[KAP_PJK_KEY_HEAD][KAP_PJK_KEY_CMD].toInt(-1);
+#else
+    QJsonValue val = jsonDoc.object()[KAP_PJK_KEY_HEAD];
+    int protoID = val.toObject()[KAP_PJK_KEY_CMD].toInt(-1);
+#endif
     if (protoID == -1)
     {
         return false;
@@ -155,7 +160,12 @@ bool AuthController::processAuthDaemonCommand(const QString& msg)
     {
     case KAP_REQ_CMD_NOTIFY_AUTH_MODE:
     {
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
         auto authMode = jsonDoc[KAP_PJK_KEY_BODY][KAP_PJK_KEY_AUTH_MODE].toInt(-1);
+#else
+        QJsonValue val = jsonDoc.object()[KAP_PJK_KEY_BODY];
+        auto authMode = val.toObject()[KAP_PJK_KEY_AUTH_MODE].toInt(-1);
+#endif
         if (authMode < KAD_AUTH_MODE_NONE || authMode > KAD_AUTH_MODE_LAST)
         {
             KLOG_WARNING() << "invalid auth mode" << authMode;
@@ -171,7 +181,13 @@ bool AuthController::processAuthDaemonCommand(const QString& msg)
     }
     case KAP_REQ_CMD_NOTIFY_SUPPORT_AUTH_TYPE:
     {
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
         auto authTypesArray = jsonDoc[KAP_PJK_KEY_BODY][KAP_PJK_KEY_AUTH_TYPES].toArray(QJsonArray());
+#else
+        QJsonValue val = jsonDoc.object()[KAP_PJK_KEY_BODY];
+        const QJsonObject object =  val.toObject();
+        auto authTypesArray = object[KAP_PJK_KEY_AUTH_TYPES].toArray(QJsonArray());
+#endif
         if (authTypesArray.isEmpty())
         {
             KLOG_WARNING() << "invalid auth types";
@@ -202,7 +218,12 @@ bool AuthController::processAuthDaemonCommand(const QString& msg)
     }
     case KAP_REQ_CMD_NOTIFY_AUTH_TYPE:
     {
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
         auto authType = jsonDoc[KAP_PJK_KEY_BODY][KAP_PJK_KEY_AUTH_TYPE].toInt(-1);
+#else
+        QJsonValue val = jsonDoc.object()[KAP_PJK_KEY_BODY];
+        auto authType = val.toObject()[KAP_PJK_KEY_AUTH_TYPES].toInt(-1);
+#endif
         if (authType <= KAD_AUTH_TYPE_NONE || authType >= KAD_AUTH_TYPE_LAST)
         {
             KLOG_WARNING() << "invalid auth types";
diff --git a/src/polkit-agent/listener.cpp b/src/polkit-agent/listener.cpp
index fbcd66a..7474329 100644
--- a/src/polkit-agent/listener.cpp
+++ b/src/polkit-agent/listener.cpp
@@ -38,6 +38,28 @@ Listener::~Listener()
 {
 }
 
+#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
+static QScreen *screenAt(const QPoint &point)
+{
+    QVarLengthArray<const QScreen *, 8> visitedScreens;
+    for (const QScreen *screen : QGuiApplication::screens()) {
+        if (visitedScreens.contains(screen))
+            continue;
+
+        // The virtual siblings include the screen itself, so iterate directly
+        for (QScreen *sibling : screen->virtualSiblings()) {
+            if (sibling->geometry().contains(point))
+                return sibling;
+
+            visitedScreens.append(sibling);
+        }
+    }
+
+    return nullptr;
+}
+#endif
+
+
 void Listener::initiateAuthentication(const QString &actionId,
                                       const QString &message,
                                       const QString &iconName,
@@ -83,7 +105,11 @@ void Listener::initiateAuthentication(const QString &actionId,
     connect(m_authDialog, &Dialog::completed, this, &Listener::onAuthDialogCompleted);
     connect(m_authDialog, &Dialog::cancelled, this, &Listener::onAuthDialogCancelled);
 
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
     auto screen = QApplication::screenAt(QCursor::pos());
+#else
+    auto screen = screenAt(QCursor::pos());
+#endif
     if (screen != nullptr)
     {
         QRect screenGeometry = screen->geometry();
-- 
2.27.0

