From b80e5a4016724a368b090438eede2f340c665be2 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Wed, 6 Sep 2023 17:14:37 +0800 Subject: [PATCH] fix(ipconflict):add ipv4 conflict detect on create net page(#190706) --- src/frontend/netdetails/creatnetpage.cpp | 84 ++++++++++++++++++++++++ src/frontend/netdetails/creatnetpage.h | 19 ++++++ src/frontend/netdetails/ipv4page.cpp | 4 +- src/frontend/netdetails/ipv4page.h | 2 +- src/frontend/netdetails/netdetail.cpp | 50 ++++++++------ 5 files changed, 135 insertions(+), 24 deletions(-) diff --git a/src/frontend/netdetails/creatnetpage.cpp b/src/frontend/netdetails/creatnetpage.cpp index beeaa366..b95ab72e 100644 --- a/src/frontend/netdetails/creatnetpage.cpp +++ b/src/frontend/netdetails/creatnetpage.cpp @@ -23,6 +23,8 @@ #define MAX_NAME_LENGTH 32 #define HINT_TEXT_MARGINS 8, 1, 0, 3 #define LABEL_HEIGHT 24 +#define FRAME_SPEED 150 +#define ICON_SIZE 16,16 CreatNetPage::CreatNetPage(QWidget *parent):QFrame(parent) { @@ -64,6 +66,12 @@ void CreatNetPage::initUI() m_addressHintLabel->setContentsMargins(HINT_TEXT_MARGINS); m_maskHintLabel->setContentsMargins(HINT_TEXT_MARGINS); + m_statusLabel = new QLabel(this); + m_statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + QHBoxLayout *pPwdLayout = new QHBoxLayout(ipv4addressEdit); + pPwdLayout->addStretch(); + pPwdLayout->addWidget(m_statusLabel); + QPalette hintTextColor; hintTextColor.setColor(QPalette::WindowText, Qt::red); m_addressHintLabel->setPalette(hintTextColor); @@ -75,6 +83,7 @@ void CreatNetPage::initUI() addressLayout->setSpacing(0); addressLayout->addWidget(ipv4addressEdit); addressLayout->addWidget(m_addressHintLabel); + initConflictHintLable(); QWidget *maskWidget = new QWidget(this); QVBoxLayout *maskLayout = new QVBoxLayout(maskWidget); @@ -115,6 +124,8 @@ void CreatNetPage::initUI() ipv4addressEdit->setValidator(new QRegExpValidator(rx, this)); gateWayEdit->setValidator(new QRegExpValidator(rx, this)); netMaskEdit->setValidator(new QRegExpValidator(rx, this)); + + initLoadingIcon(); } void CreatNetPage::initComponent() { @@ -130,6 +141,7 @@ void CreatNetPage::initComponent() { connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(ipv4addressEdit, SIGNAL(textChanged(QString)), this, SLOT(onAddressTextChanged())); + connect(ipv4addressEdit, SIGNAL(editingFinished()), this, SLOT(onAddressEditFinished())); connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(onNetMaskTextChanged())); } @@ -173,6 +185,9 @@ void CreatNetPage::configChanged(int index) { void CreatNetPage::onAddressTextChanged() { + m_iconLabel->hide(); + m_textLabel->hide(); + if (!getTextEditState(ipv4addressEdit->text())) { m_addressHintLabel->setText(tr("Invalid address")); } else { @@ -180,6 +195,15 @@ void CreatNetPage::onAddressTextChanged() } } +void CreatNetPage::onAddressEditFinished() +{ + if (ipv4addressEdit->isModified()) { + if (!ipv4addressEdit->text().isEmpty() && getTextEditState(ipv4addressEdit->text())) { + Q_EMIT ipv4EditFinished(ipv4addressEdit->text()); + } + } +} + void CreatNetPage::onNetMaskTextChanged() { if (!netMaskIsValide(netMaskEdit->text())) { @@ -297,3 +321,63 @@ QString CreatNetPage::getNetMaskText(QString text) return QString("%1.%2.%3.%4").arg(list[0],list[1],list[2],list[3]); } +void CreatNetPage::initConflictHintLable() +{ + QIcon icon = QIcon::fromTheme("dialog-warning"); + m_iconLabel = new QLabel(m_addressHintLabel); + m_iconLabel->setPixmap(icon.pixmap(ICON_SIZE)); + m_textLabel = new QLabel(m_addressHintLabel); + m_textLabel->setText(tr("Address conflict")); + QHBoxLayout *conflictHintLayout = new QHBoxLayout(m_addressHintLabel); + conflictHintLayout->setContentsMargins(0, 0, 0, 0); + conflictHintLayout->addWidget(m_iconLabel); + conflictHintLayout->addWidget(m_textLabel); + conflictHintLayout->addStretch(); + m_addressHintLabel->setLayout(conflictHintLayout); + m_iconLabel->hide(); + m_textLabel->hide(); +} + +void CreatNetPage::initLoadingIcon() +{ + m_loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic")); + m_loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic")); + m_loadIcons.append(QIcon::fromTheme("ukui-loading-3-symbolic")); + m_loadIcons.append(QIcon::fromTheme("ukui-loading-4-symbolic")); + m_loadIcons.append(QIcon::fromTheme("ukui-loading-5-symbolic")); + m_loadIcons.append(QIcon::fromTheme("ukui-loading-6-symbolic")); + m_loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic")); + m_iconTimer = new QTimer(this); + connect(m_iconTimer, &QTimer::timeout, this, &CreatNetPage::updateIcon); +} + +void CreatNetPage::updateIcon() +{ + if (m_currentIconIndex > 6) { + m_currentIconIndex = 0; + } + m_statusLabel->setPixmap(m_loadIcons.at(m_currentIconIndex).pixmap(ICON_SIZE)); + m_currentIconIndex ++; +} + +void CreatNetPage::startLoading() +{ + m_iconTimer->start(FRAME_SPEED); +} + +void CreatNetPage::stopLoading() +{ + m_iconTimer->stop(); + m_statusLabel->clear(); +} + +void CreatNetPage::showIpv4AddressConflict(bool isConflict) +{ + if (isConflict) { + m_iconLabel->show(); + m_textLabel->show(); + } else { + m_iconLabel->hide(); + m_textLabel->hide(); + } +} diff --git a/src/frontend/netdetails/creatnetpage.h b/src/frontend/netdetails/creatnetpage.h index 406b7f18..00da5ab4 100644 --- a/src/frontend/netdetails/creatnetpage.h +++ b/src/frontend/netdetails/creatnetpage.h @@ -41,6 +41,10 @@ public: CreatNetPage(QWidget *parent = nullptr); void constructIpv4Info(KyConnectSetting &setting); + + void startLoading(); + void stopLoading(); + void showIpv4AddressConflict(bool isConflict); private: LineEdit *connNameEdit; QComboBox *ipv4ConfigCombox; @@ -61,6 +65,14 @@ private: MultipleDnsWidget *m_dnsWidget = nullptr; + QLabel *m_statusLabel = nullptr; + QList m_loadIcons; + QTimer *m_iconTimer = nullptr; + int m_currentIconIndex =0; + + QLabel *m_iconLabel; + QLabel *m_textLabel; + private: void initUI(); void initComponent(); @@ -68,6 +80,8 @@ private: void configSave(); bool getTextEditState(QString text); bool checkConnectBtnIsEnabled(); + void initConflictHintLable(); + void initLoadingIcon(); bool netMaskIsValide(QString text); QString getNetMaskText(QString text); @@ -77,9 +91,14 @@ private Q_SLOTS: void configChanged(int index); void onAddressTextChanged(); void onNetMaskTextChanged(); + void onAddressEditFinished(); + +public Q_SLOTS: + void updateIcon(); Q_SIGNALS: void setCreatePageState(bool); + void ipv4EditFinished(QString); }; diff --git a/src/frontend/netdetails/ipv4page.cpp b/src/frontend/netdetails/ipv4page.cpp index 17e3bffe..6cfb863f 100644 --- a/src/frontend/netdetails/ipv4page.cpp +++ b/src/frontend/netdetails/ipv4page.cpp @@ -141,7 +141,7 @@ void Ipv4Page::initComponent() { connect(ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(configChanged(int))); connect(ipv4addressEdit, SIGNAL(textChanged(QString)), this, SLOT(onAddressTextChanged())); - connect(ipv4addressEdit, SIGNAL(editingFinished()), this, SLOT(onAddressEidtFinished())); + connect(ipv4addressEdit, SIGNAL(editingFinished()), this, SLOT(onAddressEditFinished())); connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(onNetMaskTextChanged())); connect(ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn())); @@ -286,7 +286,7 @@ void Ipv4Page::onNetMaskTextChanged() } } -void Ipv4Page::onAddressEidtFinished() +void Ipv4Page::onAddressEditFinished() { if (ipv4addressEdit->isModified()) { if (!ipv4addressEdit->text().isEmpty() && getTextEditState(ipv4addressEdit->text())) { diff --git a/src/frontend/netdetails/ipv4page.h b/src/frontend/netdetails/ipv4page.h index 43d824b3..54521908 100644 --- a/src/frontend/netdetails/ipv4page.h +++ b/src/frontend/netdetails/ipv4page.h @@ -105,7 +105,7 @@ private Q_SLOTS: void configChanged(int index); void onAddressTextChanged(); void onNetMaskTextChanged(); - void onAddressEidtFinished(); + void onAddressEditFinished(); void updateIcon(); Q_SIGNALS: diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index 3898bf52..edc0d636 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -105,27 +105,37 @@ void NetDetail::startObjectThread() m_object->moveToThread(m_objectThread); connect(m_objectThread, &QThread::finished, m_objectThread, &QObject::deleteLater); connect(m_objectThread, &QThread::finished, m_object, &QObject::deleteLater); - connect(ipv4Page, &Ipv4Page::ipv4EditFinished, this, [=](){ - ipv4Page->startLoading(); - }); - connect(ipv6Page, &Ipv6Page::ipv6EditFinished, this, [=](){ - ipv6Page->startLoading(); - }); + if (m_isCreateNet && !isWlan) { + connect(createNetPage, &CreatNetPage::ipv4EditFinished, this, [=](){ + createNetPage->startLoading(); + }); + connect(createNetPage, SIGNAL(ipv4EditFinished(const QString &)), m_object, SLOT(checkIpv4ConflictThread(const QString &))); + connect(m_object, &ThreadObject::ipv4IsConflict, this, [=](bool ipv4IsConf) { + createNetPage->stopLoading(); + createNetPage->showIpv4AddressConflict(ipv4IsConf); + }); + } else { + connect(ipv4Page, &Ipv4Page::ipv4EditFinished, this, [=](){ + ipv4Page->startLoading(); + }); + connect(ipv6Page, &Ipv6Page::ipv6EditFinished, this, [=](){ + ipv6Page->startLoading(); + }); - connect(ipv4Page, SIGNAL(ipv4EditFinished(const QString &)), m_object, SLOT(checkIpv4ConflictThread(const QString &))); - connect(ipv6Page, SIGNAL(ipv6EditFinished(const QString &)), m_object, SLOT(checkIpv6ConflictThread(const QString &))); - connect(this, SIGNAL(checkCurrentIpv4Conflict(const QString &)), m_object, SLOT(checkIpv4ConflictThread(const QString &))); - connect(this, SIGNAL(checkCurrentIpv6Conflict(const QString &)), m_object, SLOT(checkIpv6ConflictThread(const QString &))); - - connect(m_object, &ThreadObject::ipv4IsConflict, this, [=](bool ipv4IsConf) { - ipv4Page->stopLoading(); - ipv4Page->showIpv4AddressConflict(ipv4IsConf); - }); - connect(m_object, &ThreadObject::ipv6IsConflict, this, [=](bool ipv6IsConf) { - ipv6Page->stopLoading(); - ipv6Page->showIpv6AddressConflict(ipv6IsConf); - }); + connect(ipv4Page, SIGNAL(ipv4EditFinished(const QString &)), m_object, SLOT(checkIpv4ConflictThread(const QString &))); + connect(ipv6Page, SIGNAL(ipv6EditFinished(const QString &)), m_object, SLOT(checkIpv6ConflictThread(const QString &))); + connect(this, SIGNAL(checkCurrentIpv4Conflict(const QString &)), m_object, SLOT(checkIpv4ConflictThread(const QString &))); + connect(this, SIGNAL(checkCurrentIpv6Conflict(const QString &)), m_object, SLOT(checkIpv6ConflictThread(const QString &))); + connect(m_object, &ThreadObject::ipv4IsConflict, this, [=](bool ipv4IsConf) { + ipv4Page->stopLoading(); + ipv4Page->showIpv4AddressConflict(ipv4IsConf); + }); + connect(m_object, &ThreadObject::ipv6IsConflict, this, [=](bool ipv6IsConf) { + ipv6Page->stopLoading(); + ipv6Page->showIpv6AddressConflict(ipv6IsConf); + }); + } m_objectThread->start(); } @@ -157,11 +167,9 @@ NetDetail::NetDetail(QString interface, QString name, QString uuid, bool isActiv setFixedSize(WINDOW_WIDTH,WINDOW_HEIGHT); centerToScreen(); - qDebug() << m_isCreateNet << name; if (!m_isCreateNet && name.isEmpty()) { m_isCreateNet = true; } - qDebug() << m_isCreateNet; m_netDeviceResource = new KyNetworkDeviceResourse(this); m_wirelessConnOpration = new KyWirelessConnectOperation(this); m_resource = new KyWirelessNetResource(this);