fix(ipconflict):add ipv4 conflict detect on create net page(#190706)

This commit is contained in:
jzxc95 2023-09-06 17:14:37 +08:00
parent 45c1d17acb
commit b80e5a4016
5 changed files with 135 additions and 24 deletions

View File

@ -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();
}
}

View File

@ -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<QIcon> 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);
};

View File

@ -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())) {

View File

@ -105,7 +105,7 @@ private Q_SLOTS:
void configChanged(int index);
void onAddressTextChanged();
void onNetMaskTextChanged();
void onAddressEidtFinished();
void onAddressEditFinished();
void updateIcon();
Q_SIGNALS:

View File

@ -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);