From 7c62cbc143a47fa47b432b5f8a57a5dda0d536eb Mon Sep 17 00:00:00 2001
From: niko_yhc <yinhongchang@kylinsec.com.cn>
Date: Tue, 12 Sep 2023 16:04:09 +0800
Subject: [PATCH] fix(kiran-control-panel):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/common-widgets/kiran-tips/kiran-tips.cpp  |  4 +++
 .../src/pages/face/face-page.cpp              |  1 -
 .../src/pages/finger/finger-page.cpp          | 11 ++++----
 .../src/pages/iris/iris-page.cpp              |  1 -
 .../src/pages/prefs/prefs-page.cpp            | 16 ++++++------
 .../src/pages/ukey/ukey-page.cpp              |  1 -
 .../src/widgets/general-bio-page.cpp          |  8 ++++++
 .../network/src/tray/wired-tray-widget.cpp    | 10 ++++----
 .../network/src/tray/wireless-tray-widget.cpp | 14 +++++------
 plugins/power/src/upower-interface.cpp        |  4 +++
 .../hardware-information.cpp                  |  6 ++---
 .../change-host-name-widget.cpp               |  5 ----
 .../system-information/system-information.cpp |  2 +-
 src/main.cpp                                  | 25 +++++++++++++++++++
 14 files changed, 70 insertions(+), 38 deletions(-)

diff --git a/lib/common-widgets/kiran-tips/kiran-tips.cpp b/lib/common-widgets/kiran-tips/kiran-tips.cpp
index 7a8dcab..34f0fa2 100644
--- a/lib/common-widgets/kiran-tips/kiran-tips.cpp
+++ b/lib/common-widgets/kiran-tips/kiran-tips.cpp
@@ -279,7 +279,11 @@ QSize KiranTips::getRightSize() const
     QFontMetrics fontMetrics(font);
     QMargins layoutContentMargins = this->layout()->contentsMargins();
 
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
     ui->label->setFixedWidth(fontMetrics.horizontalAdvance(ui->label->text()) + 10);
+#else
+    ui->label->setFixedWidth(fontMetrics.width(ui->label->text()) + 10);
+#endif
     ui->label->setFixedHeight(fontMetrics.height());
 
     QSize size;
diff --git a/plugins/authentication/src/pages/face/face-page.cpp b/plugins/authentication/src/pages/face/face-page.cpp
index 5e0a0db..4412631 100644
--- a/plugins/authentication/src/pages/face/face-page.cpp
+++ b/plugins/authentication/src/pages/face/face-page.cpp
@@ -23,7 +23,6 @@
 #include <QBoxLayout>
 #include <QLabel>
 #include <QPushButton>
-#include <QRandomGenerator>
 #include <QSpacerItem>
 #include <QStackedWidget>
 
diff --git a/plugins/authentication/src/pages/finger/finger-page.cpp b/plugins/authentication/src/pages/finger/finger-page.cpp
index 86513a6..069ab94 100644
--- a/plugins/authentication/src/pages/finger/finger-page.cpp
+++ b/plugins/authentication/src/pages/finger/finger-page.cpp
@@ -29,7 +29,6 @@
 #include <QComboBox>
 #include <QLabel>
 #include <QPushButton>
-#include <QRandomGenerator>
 #include <QStackedWidget>
 #include <QUuid>
 
@@ -43,11 +42,11 @@ enum FingerPageIndexEnum
 };
 
 const std::list<std::tuple<uint, QString>> FingerProgressRangePixmapList = {
-    {0, ":/kcp-authentication/images/finger-0.svg"},
-    {25, ":/kcp-authentication/images/finger-25.svg"},
-    {50, ":/kcp-authentication/images/finger-50.svg"},
-    {75, ":/kcp-authentication/images/finger-75.svg"},
-    {100, ":/kcp-authentication/images/finger-100.svg"}};
+    std::make_tuple(0, ":/kcp-authentication/images/finger-0.svg"),
+    std::make_tuple(25, ":/kcp-authentication/images/finger-25.svg"),
+    std::make_tuple(50, ":/kcp-authentication/images/finger-50.svg"),
+    std::make_tuple(75, ":/kcp-authentication/images/finger-75.svg"),
+    std::make_tuple(100, ":/kcp-authentication/images/finger-100.svg")};
 
 FingerPage::FingerPage(KiranAuthDBusProxy* proxy, FingerAuthType type, QWidget* parent)
     : QWidget(parent),
diff --git a/plugins/authentication/src/pages/iris/iris-page.cpp b/plugins/authentication/src/pages/iris/iris-page.cpp
index 714c9c0..cacc801 100644
--- a/plugins/authentication/src/pages/iris/iris-page.cpp
+++ b/plugins/authentication/src/pages/iris/iris-page.cpp
@@ -23,7 +23,6 @@
 #include <QBoxLayout>
 #include <QLabel>
 #include <QPushButton>
-#include <QRandomGenerator>
 #include <QSpacerItem>
 #include <QStackedWidget>
 
diff --git a/plugins/authentication/src/pages/prefs/prefs-page.cpp b/plugins/authentication/src/pages/prefs/prefs-page.cpp
index 8bad280..a50cc15 100644
--- a/plugins/authentication/src/pages/prefs/prefs-page.cpp
+++ b/plugins/authentication/src/pages/prefs/prefs-page.cpp
@@ -71,11 +71,11 @@ QWidget* PrefsPage::initAuthTypePage()
     authTypeLayout->addStretch();
 
     std::list<std::tuple<KADAuthType, QString>> authTypes = {
-        {KAD_AUTH_TYPE_FINGERPRINT, tr("fingerprint")},
-        {KAD_AUTH_TYPE_FINGERVEIN, tr("fingervein")},
-        {KAD_AUTH_TYPE_UKEY, tr("ukey")},
-        {KAD_AUTH_TYPE_IRIS, tr("iris")},
-        {KAD_AUTH_TYPE_FACE, tr("face")}};
+        std::make_tuple(KAD_AUTH_TYPE_FINGERPRINT, tr("fingerprint")),
+        std::make_tuple(KAD_AUTH_TYPE_FINGERVEIN, tr("fingervein")),
+        std::make_tuple(KAD_AUTH_TYPE_UKEY, tr("ukey")),
+        std::make_tuple(KAD_AUTH_TYPE_IRIS, tr("iris")),
+        std::make_tuple(KAD_AUTH_TYPE_FACE, tr("face"))};
 
     // fill auth types
     for (auto iter : authTypes)
@@ -134,9 +134,9 @@ QWidget* PrefsPage::initAuthApplicationPage()
     authAppLayout->addLayout(buttonLayout);
 
     std::list<std::tuple<KADAuthApplication, QString>> authTypes = {
-        {KAD_AUTH_APPLICATION_LOGIN, tr("login")},
-        {KAD_AUTH_APPLICATION_UNLOCK, tr("unlock")},
-        {KAD_AUTH_APPLICATION_EMPOWERMENT, tr("empowerment")}};
+        std::make_tuple(KAD_AUTH_APPLICATION_LOGIN, tr("login")),
+        std::make_tuple(KAD_AUTH_APPLICATION_UNLOCK, tr("unlock")),
+        std::make_tuple(KAD_AUTH_APPLICATION_EMPOWERMENT, tr("empowerment"))};
 
     // fill auth applications
     for (auto iter : authTypes)
diff --git a/plugins/authentication/src/pages/ukey/ukey-page.cpp b/plugins/authentication/src/pages/ukey/ukey-page.cpp
index 38051ca..bdf4033 100644
--- a/plugins/authentication/src/pages/ukey/ukey-page.cpp
+++ b/plugins/authentication/src/pages/ukey/ukey-page.cpp
@@ -27,7 +27,6 @@
 #include <QJsonValue>
 #include <QLabel>
 #include <QPushButton>
-#include <QRandomGenerator>
 #include <QSpacerItem>
 
 UKeyPage::UKeyPage(KiranAuthDBusProxy* proxy, QWidget* parent)
diff --git a/plugins/authentication/src/widgets/general-bio-page.cpp b/plugins/authentication/src/widgets/general-bio-page.cpp
index 36d0ef9..1047c3e 100644
--- a/plugins/authentication/src/widgets/general-bio-page.cpp
+++ b/plugins/authentication/src/widgets/general-bio-page.cpp
@@ -12,7 +12,10 @@
 #include <QComboBox>
 #include <QLabel>
 #include <QPushButton>
+#include <QTime>
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
 #include <QRandomGenerator>
+#endif
 
 #define MAX_FEATURE_NUMBER 1000
 
@@ -45,7 +48,12 @@ QString GeneralBioPage::autoGenerateFeatureName()
 
     for (int i = 0; i <= 10; ++i)
     {
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
         auto featureNumber = QRandomGenerator::global()->bounded(1, MAX_FEATURE_NUMBER);
+#else
+        qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
+        auto featureNumber = qrand() % MAX_FEATURE_NUMBER + 1;
+#endif
         auto temp = QString("%1 %2").arg(m_featureNamePrefix).arg(featureNumber);
 
         if (!m_featureNameSet.contains(temp))
diff --git a/plugins/network/src/tray/wired-tray-widget.cpp b/plugins/network/src/tray/wired-tray-widget.cpp
index 02fac75..67b2224 100644
--- a/plugins/network/src/tray/wired-tray-widget.cpp
+++ b/plugins/network/src/tray/wired-tray-widget.cpp
@@ -59,11 +59,11 @@ void WiredTrayWidget::initUI()
 
 void WiredTrayWidget::initConnection()
 {
-    connect(m_connectionList, &TrayConnectionList::connectionUpdated, this, &WiredTrayWidget::handleConnectionUpdated, Qt::UniqueConnection);
-    connect(m_connectionList, &TrayConnectionList::activateSelectedConnection, this, &WiredTrayWidget::handleActivateSelectedConnection, Qt::UniqueConnection);
-    connect(m_connectionList, &TrayConnectionList::disconnect, this, &WiredTrayWidget::handleDisconnect, Qt::UniqueConnection);
-    connect(m_connectionList, &TrayConnectionList::cancelConnection, this, &WiredTrayWidget::handleCancelConnection, Qt::UniqueConnection);
-    connect(m_connectionList, &TrayConnectionList::sizeChanged, this, &WiredTrayWidget::sizeChanged, Qt::UniqueConnection);
+    connect(m_connectionList.data(), &TrayConnectionList::connectionUpdated, this, &WiredTrayWidget::handleConnectionUpdated, Qt::UniqueConnection);
+    connect(m_connectionList.data(), &TrayConnectionList::activateSelectedConnection, this, &WiredTrayWidget::handleActivateSelectedConnection, Qt::UniqueConnection);
+    connect(m_connectionList.data(), &TrayConnectionList::disconnect, this, &WiredTrayWidget::handleDisconnect, Qt::UniqueConnection);
+    connect(m_connectionList.data(), &TrayConnectionList::cancelConnection, this, &WiredTrayWidget::handleCancelConnection, Qt::UniqueConnection);
+    connect(m_connectionList.data(), &TrayConnectionList::sizeChanged, this, &WiredTrayWidget::sizeChanged, Qt::UniqueConnection);
 
     connect(m_wiredDevice.data(), &WiredDevice::carrierChanged, this, &WiredTrayWidget::handleCarrierChanged, Qt::UniqueConnection);
     connect(m_wiredDevice.data(), &Device::stateChanged, this, &WiredTrayWidget::handleStateChanged, Qt::UniqueConnection);
diff --git a/plugins/network/src/tray/wireless-tray-widget.cpp b/plugins/network/src/tray/wireless-tray-widget.cpp
index 2054d99..7680376 100644
--- a/plugins/network/src/tray/wireless-tray-widget.cpp
+++ b/plugins/network/src/tray/wireless-tray-widget.cpp
@@ -55,19 +55,19 @@ void WirelessTrayWidget::initUI()
 
 void WirelessTrayWidget::initConnection()
 {
-    connect(m_connectionList, &TrayConnectionList::activateSelectedWirelessNetwork, this, &WirelessTrayWidget::handleActivateSelectedWirelessNetwork);
-    connect(m_connectionList, &TrayConnectionList::disconnect, this, &WirelessTrayWidget::handleDisconnect);
-    connect(m_connectionList, &TrayConnectionList::cancelConnection, this, &WirelessTrayWidget::handleCancelConnection);
-    connect(m_connectionList, &TrayConnectionList::ignoreConnection, this, &WirelessTrayWidget::handleIgnoreConnection);
+    connect(m_connectionList.data(), &TrayConnectionList::activateSelectedWirelessNetwork, this, &WirelessTrayWidget::handleActivateSelectedWirelessNetwork);
+    connect(m_connectionList.data(), &TrayConnectionList::disconnect, this, &WirelessTrayWidget::handleDisconnect);
+    connect(m_connectionList.data(), &TrayConnectionList::cancelConnection, this, &WirelessTrayWidget::handleCancelConnection);
+    connect(m_connectionList.data(), &TrayConnectionList::ignoreConnection, this, &WirelessTrayWidget::handleIgnoreConnection);
 
     connect(m_wirelessDevice.data(), &WirelessDevice::networkDisappeared, this, &WirelessTrayWidget::handleNetworkDisappeared);
     connect(m_wirelessDevice.data(), &WirelessDevice::networkAppeared, this, &WirelessTrayWidget::handleNetworkAppeared);
 
-    connect(m_connectionList, &TrayConnectionList::sendPasswordToWirelessSetting, this, &WirelessTrayWidget::setSecurityPskAndActivateWirelessConnection);
-    connect(m_connectionList, &TrayConnectionList::sendSsidToWireless, this, &WirelessTrayWidget::handleActivateHiddenNetwork);
+    connect(m_connectionList.data(), &TrayConnectionList::sendPasswordToWirelessSetting, this, &WirelessTrayWidget::setSecurityPskAndActivateWirelessConnection);
+    connect(m_connectionList.data(), &TrayConnectionList::sendSsidToWireless, this, &WirelessTrayWidget::handleActivateHiddenNetwork);
 
     connect(m_devicePtr.data(), &Device::stateChanged, this, &WirelessTrayWidget::handleDeviceStateChanged, Qt::UniqueConnection);
-    connect(m_connectionList, &TrayConnectionList::sizeChanged, this, &WirelessTrayWidget::sizeChanged);
+    connect(m_connectionList.data(), &TrayConnectionList::sizeChanged, this, &WirelessTrayWidget::sizeChanged);
 
     connect(SignalForward::instance(), &SignalForward::wirelessConnectionAdded, this, &WirelessTrayWidget::handleNotifierConnectionAdded);
     connect(SignalForward::instance(), &SignalForward::connectionRemoved, this, &WirelessTrayWidget::handleNotifierConnectionRemoved);
diff --git a/plugins/power/src/upower-interface.cpp b/plugins/power/src/upower-interface.cpp
index f929fbd..aa7960b 100644
--- a/plugins/power/src/upower-interface.cpp
+++ b/plugins/power/src/upower-interface.cpp
@@ -32,7 +32,11 @@ bool UPowerInterface::haveBattery()
     }
 #endif
 
+#if UP_CHECK_VERSION(0, 99, 8)
     auto devices = up_client_get_devices2(upClient);
+#else
+    auto devices = up_client_get_devices(upClient);
+#endif
     void *device = nullptr;
     UpDeviceKind kind;
     for (int i = 0; i < devices->len; i++)
diff --git a/plugins/system/src/pages/hardware-information/hardware-information.cpp b/plugins/system/src/pages/hardware-information/hardware-information.cpp
index 9e4ae2e..5232390 100644
--- a/plugins/system/src/pages/hardware-information/hardware-information.cpp
+++ b/plugins/system/src/pages/hardware-information/hardware-information.cpp
@@ -88,9 +88,9 @@ void HardwareInformation::initUI(void)
         ui->label_CPU_info->setToolTip(cpu);
 
         QList<std::tuple<QStringList, QGridLayout *> > hardwareMap = {
-            {disks, ui->gridLayout_hard_disk},
-            {graphics, ui->gridLayout_graphics_card},
-            {eths, ui->gridLayout_network_card}};
+            std::make_tuple(disks, ui->gridLayout_hard_disk),
+            std::make_tuple(graphics, ui->gridLayout_graphics_card),
+            std::make_tuple(eths, ui->gridLayout_network_card)};
         for (auto hardwareInitTuple : hardwareMap)
         {
             QStringList infos = std::get<0>(hardwareInitTuple);
diff --git a/plugins/system/src/pages/system-information/change-host-name-widget.cpp b/plugins/system/src/pages/system-information/change-host-name-widget.cpp
index c8ea9f6..7cad825 100644
--- a/plugins/system/src/pages/system-information/change-host-name-widget.cpp
+++ b/plugins/system/src/pages/system-information/change-host-name-widget.cpp
@@ -61,11 +61,6 @@ void ChangeHostNameWidget::initUI()
     setIcon(QIcon(":/images/kylin-about.png"));
 
     ui->btn_save->setEnabled(false);
-
-    auto screen = QApplication::screenAt(QCursor::pos());
-    auto screenGeometry = screen->geometry();
-    this->move(screenGeometry.x() + (screenGeometry.width() - this->width()) / 2,
-               screenGeometry.y() + (screenGeometry.height() - this->height()) / 2);
 }
 
 void ChangeHostNameWidget::setNewHostName()
diff --git a/plugins/system/src/pages/system-information/system-information.cpp b/plugins/system/src/pages/system-information/system-information.cpp
index c249b69..9866d01 100644
--- a/plugins/system/src/pages/system-information/system-information.cpp
+++ b/plugins/system/src/pages/system-information/system-information.cpp
@@ -268,7 +268,7 @@ void SystemInformation::handleChangeHostName()
 {
     if (hostNameWidget == nullptr)
     {
-        hostNameWidget = new ChangeHostNameWidget;
+        hostNameWidget = new ChangeHostNameWidget(this);
     }
     hostNameWidget->setAttribute(Qt::WA_QuitOnClose, false);
     hostNameWidget->installEventFilter(this);
diff --git a/src/main.cpp b/src/main.cpp
index 2e75c10..2ff2737 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -123,6 +123,27 @@ void dumpPluginManagerInfo()
 #endif
 }
 
+#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
+
 int main(int argc, char *argv[])
 {
     KiranSingleApplication app(argc,
@@ -165,7 +186,11 @@ int main(int argc, char *argv[])
     PanelWindow w;
     w.jump(defaultCategory,defaultSubItem);
 
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
     auto screen = QApplication::screenAt(QCursor::pos());
+#else
+    auto screen = screenAt(QCursor::pos());
+#endif
     QRect screenGeometry = screen->geometry();
     w.resize(1031, 742);
     w.move(screenGeometry.x() + (screenGeometry.width() - w.width()) / 2,
-- 
2.27.0

