diff --git a/src/frontend/frontend.pri b/src/frontend/frontend.pri index ec60ca6c..b7703595 100644 --- a/src/frontend/frontend.pri +++ b/src/frontend/frontend.pri @@ -5,6 +5,7 @@ include(tab-pages/tab-pages.pri) include(list-items/list-items.pri) include(netdetails/netdetails.pri) include(enterprise-wlan/enterprise-wlan.pri) +include(networkmode/networkmode.pri) FORMS += \ $$PWD/wificonfigdialog.ui @@ -18,3 +19,6 @@ SOURCES += \ $$PWD/customstyle.cpp \ $$PWD/mainwindow.cpp \ $$PWD/wificonfigdialog.cpp + +DISTFILES += \ + $$PWD/networkmode/networkmode.pri diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index ea318847..206c4b28 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -21,6 +21,7 @@ #include "backend/kylinipv4arping.h" #include "backend/kylinipv6arping.h" //#include "xatom/xatom-helper.h" +#include "networkmodeconfig.h" #define THEME_SCHAME "org.ukui.style" @@ -454,7 +455,7 @@ void NetDetail::pagePadding(QString netName, bool isWlan) //配置页面 if (isActive) { - int configType = getNetworkModeConfig(m_uuid); + int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(m_uuid); if (configType == -1) { configPage->setConfigState(KSC_FIREWALL_PUBLIC); } else { @@ -976,13 +977,13 @@ bool NetDetail::updateConnect() } if (configPage != nullptr) { - int configType = getNetworkModeConfig(m_uuid); + int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(m_uuid); bool configPageChange = configPage->checkIsChanged(configType); int currentConfigType = configPage->getConfigState(); // qDebug () << Q_FUNC_INFO << __LINE__<< configPageChange; if (configPageChange) { - setNetworkModeConfig(m_uuid, m_deviceName, m_name, currentConfigType); + NetworkModeConfig::getInstance()->setNetworkModeConfig(m_uuid, m_deviceName, m_name, currentConfigType); // qDebug () < reply = dbusInterface.call("get_networkModeConfig", uuid); - if (reply.isValid()) { - return reply.value(); - } else { - qWarning() << "call get_networkModeConfig failed" << reply.error().message(); - } - return -1; -} - -void NetDetail::setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode) -{ - QDBusInterface dbusInterface("com.ksc.defender", - "/firewall", - "com.ksc.defender.firewall", - QDBusConnection::systemBus()); - - - QDBusReply reply = dbusInterface.call("set_networkModeConfig", uuid, cardName, ssid, mode); - if (reply.isValid()) { - qDebug() << "set_networkModeConfig" << ssid << uuid << cardName << mode << ",result" << reply.value(); - } else { - qWarning() << "call set_networkModeConfig" << reply.error().message(); - } -} - -int NetDetail::breakNetworkConnect(QString uuid, QString cardName, QString ssid) -{ - QDBusInterface dbusInterface("com.ksc.defender", - "/firewall", - "com.ksc.defender.firewall", - QDBusConnection::systemBus()); - - - QDBusReply reply = dbusInterface.call("break_networkConnect", uuid, cardName, ssid); - if (reply.isValid()) { - qDebug() << "break_networkConnect" << ssid << uuid << cardName << ",result" << reply.value(); - return reply.value(); - } else { - qWarning() << "call break_networkConnect failed" << reply.error().message(); - return -1; - } -} - - bool NetDetail::eventFilter(QObject *w, QEvent *event) { // 回车键触发确定按钮点击事件 diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index 0e854477..6f2e1885 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -74,13 +74,6 @@ public: NetDetail(QString interface, QString name, QString uuid, bool isActive, bool isWlan, bool isCreateNet, QWidget *parent = nullptr); ~NetDetail(); - //安全中心-获取网络模式配置 - int getNetworkModeConfig(QString uuid); - //安全中心-设置网络模式配置 - void setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode); - //安全中心-解除连接(用于防火墙处从正在使用的网络中删除) - int breakNetworkConnect(QString uuid, QString cardName, QString ssid); -protected: void paintEvent(QPaintEvent *event); void closeEvent(QCloseEvent *event); bool eventFilter(QObject *w, QEvent *event); diff --git a/src/frontend/networkmode/firewalldialog.cpp b/src/frontend/networkmode/firewalldialog.cpp new file mode 100644 index 00000000..e215eab8 --- /dev/null +++ b/src/frontend/networkmode/firewalldialog.cpp @@ -0,0 +1,89 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include "firewalldialog.h" + +#define ICON_SIZE 16,16 + +FirewallDialog::FirewallDialog(KDialog *parent) +{ + initUI(); + this->setWindowIcon(QIcon::fromTheme("kylin-network")); + this->setFixedSize(480, 204); + setAttribute(Qt::WA_DeleteOnClose); +} + +FirewallDialog::~FirewallDialog() +{ + +} + +void FirewallDialog::initUI() +{ + m_iconLabel = new QLabel(this); + m_contentLabel = new QLabel(this); + m_suggestLabel = new QLabel(this); + m_YesBtn = new QPushButton(this); + m_NoBtn = new QPushButton(this); + m_dialogLayout = new QVBoxLayout(this); + + QWidget *contentWidget = new QWidget(this); + QGridLayout *contentLayout = new QGridLayout(contentWidget); + contentLayout->setContentsMargins(0, 0, 0, 0); + contentLayout->addWidget(m_iconLabel, 0, 0, Qt::AlignTop); + contentLayout->addWidget(m_contentLabel, 0, 1); + contentLayout->addWidget(m_suggestLabel, 1, 1); + m_iconLabel->setFixedWidth(16); + + QWidget *btnWidget = new QWidget(this); + QHBoxLayout *btnLayout = new QHBoxLayout(btnWidget); + btnLayout->setContentsMargins(0, 0, 0, 0); + btnLayout->setSpacing(16); + btnLayout->addStretch(); + btnLayout->addWidget(m_YesBtn); + btnLayout->addWidget(m_NoBtn); + + m_dialogLayout->setContentsMargins(24, 0, 24, 24); + m_dialogLayout->setSpacing(0); + m_dialogLayout->addWidget(contentWidget); + m_dialogLayout->addStretch(); + m_dialogLayout->addWidget(btnWidget); + + QIcon icon = QIcon::fromTheme("dialog-info"); + m_iconLabel->setPixmap(icon.pixmap(ICON_SIZE)); + + QFont font = m_contentLabel->font(); + font.setWeight(75); + m_contentLabel->setFont(font); + //是否允许你的电脑被此网络上的其他电脑和设备发现? + m_contentLabel->setText(tr("Allow your computer to be discovered by other computers and devices on this network?")); + m_contentLabel->setWordWrap(true); + //建议你在家庭和工作网络上而非公共网络上启用此功能。 + m_suggestLabel->setText(tr("It is recommended that you enable this feature on your home and work networks rather than public networks.")); + m_suggestLabel->setWordWrap(true); + + m_YesBtn->setText(tr("Yse")); + m_NoBtn->setText(tr("No")); + + this->closeButton(); + this->mainWidget()->setLayout(m_dialogLayout); + + connect(m_YesBtn, &QPushButton::clicked, this, &FirewallDialog::setPrivateNetMode); + connect(m_NoBtn, &QPushButton::clicked, this, &FirewallDialog::setPublicNetMode); +} diff --git a/src/frontend/networkmode/firewalldialog.h b/src/frontend/networkmode/firewalldialog.h new file mode 100644 index 00000000..154275e3 --- /dev/null +++ b/src/frontend/networkmode/firewalldialog.h @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#ifndef FIREWALLDIALOG_H +#define FIREWALLDIALOG_H + +#include +#include +#include +#include +#include "kwidget.h" +#include "kdialog.h" + +using namespace kdk; + +class FirewallDialog : public KDialog +{ + Q_OBJECT +public: + explicit FirewallDialog(KDialog *parent = nullptr); + ~FirewallDialog(); + +private: + void initUI(); + + QLabel * m_iconLabel = nullptr; + QLabel * m_contentLabel = nullptr; + QLabel * m_suggestLabel = nullptr; + QVBoxLayout *m_dialogLayout = nullptr; + QPushButton *m_YesBtn = nullptr; + QPushButton *m_NoBtn = nullptr; + +signals: + void setPublicNetMode(); + void setPrivateNetMode(); +}; +#endif // FIREWALLDIALOG_H diff --git a/src/frontend/networkmode/networkmode.pri b/src/frontend/networkmode/networkmode.pri new file mode 100644 index 00000000..6459b81c --- /dev/null +++ b/src/frontend/networkmode/networkmode.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/firewalldialog.h \ + $$PWD/networkmodeconfig.h + +SOURCES += \ + $$PWD/firewalldialog.cpp \ + $$PWD/networkmodeconfig.cpp + diff --git a/src/frontend/networkmode/networkmodeconfig.cpp b/src/frontend/networkmode/networkmodeconfig.cpp new file mode 100644 index 00000000..fa19cc6c --- /dev/null +++ b/src/frontend/networkmode/networkmodeconfig.cpp @@ -0,0 +1,90 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include "networkmodeconfig.h" +#include + +NetworkModeConfig *NetworkModeConfig::m_netModeInstance = nullptr; + +NetworkModeConfig *NetworkModeConfig::getInstance() +{ + if (m_netModeInstance == NULL) { + m_netModeInstance = new NetworkModeConfig(); + } + return m_netModeInstance; +} + + +NetworkModeConfig::NetworkModeConfig(QObject *parent) : QObject(parent) +{ + m_dbusInterface = new QDBusInterface("com.ksc.defender", + "/firewall", + "com.ksc.defender.firewall", + QDBusConnection::systemBus()); +} + +int NetworkModeConfig::getNetworkModeConfig(QString uuid) +{ + if (uuid.isEmpty()) { + qWarning()<< /*LOG_FLAG <<*/ "uuid is empty, so can not get network mode config"; + return -1; + } + + if(!m_dbusInterface->isValid()) { + qWarning ()<< "init com.ksc.defender dbus error"; + } + + QDBusReply reply = m_dbusInterface->call("get_networkModeConfig", uuid); + if (reply.isValid()) { + return reply.value(); + } else { + qWarning() << "call get_networkModeConfig failed" << reply.error().message(); + } + return -1; +} + +void NetworkModeConfig::setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode) +{ + if(!m_dbusInterface->isValid()) { + qWarning ()<< "init com.ksc.defender dbus error"; + } + + QDBusReply reply = m_dbusInterface->call("set_networkModeConfig", uuid, cardName, ssid, mode); + if (reply.isValid()) { + qDebug() << "set_networkModeConfig" << ssid << uuid << cardName << mode << ",result" << reply.value(); + } else { + qWarning() << "call set_networkModeConfig" << reply.error().message(); + } +} + +int NetworkModeConfig::breakNetworkConnect(QString uuid, QString cardName, QString ssid) +{ + if(!m_dbusInterface->isValid()) { + qWarning ()<< "init com.ksc.defender dbus error"; + } + + QDBusReply reply = m_dbusInterface->call("break_networkConnect", uuid, cardName, ssid); + if (reply.isValid()) { + qDebug() << "break_networkConnect" << ssid << uuid << cardName << ",result" << reply.value(); + return reply.value(); + } else { + qWarning() << "call break_networkConnect failed" << reply.error().message(); + return -1; + } +} diff --git a/src/frontend/networkmode/networkmodeconfig.h b/src/frontend/networkmode/networkmodeconfig.h new file mode 100644 index 00000000..e3ed69f2 --- /dev/null +++ b/src/frontend/networkmode/networkmodeconfig.h @@ -0,0 +1,46 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#ifndef NETWORKMODECONFIG_H +#define NETWORKMODECONFIG_H + +#include +#include +#include + +class NetworkModeConfig : public QObject +{ + Q_OBJECT +public: + static NetworkModeConfig *getInstance(); + //安全中心-获取网络模式配置 + int getNetworkModeConfig(QString uuid); + //安全中心-设置网络模式配置 + void setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode); + //安全中心-解除连接(用于防火墙处从正在使用的网络中删除) + int breakNetworkConnect(QString uuid, QString cardName, QString ssid); + + static NetworkModeConfig *m_netModeInstance; + +private: + explicit NetworkModeConfig(QObject *parent = nullptr); + QDBusInterface *m_dbusInterface = nullptr; +}; + +#endif // NETWORKMODECONFIG_H diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 59b691d6..93a6d787 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -18,6 +18,7 @@ * */ #include "lanpage.h" +#include "networkmodeconfig.h" #include #include @@ -944,7 +945,7 @@ void LanPage::onConnectionStateChange(QString uuid, deviceName = p_newItem->m_ifaceName; ssid = p_newItem->m_connectName; - int configType = getNetworkModeConfig(uuid); + int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(uuid); if (configType == -1) { FirewallDialog *fireWallDiaglog = new FirewallDialog(); @@ -952,22 +953,22 @@ void LanPage::onConnectionStateChange(QString uuid, connect(fireWallDiaglog, &FirewallDialog::setPrivateNetMode, this, [=](){ fireWallDiaglog->close(); - setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PRIVATE); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PRIVATE); }); connect(fireWallDiaglog, &FirewallDialog::setPublicNetMode, this, [=](){ fireWallDiaglog->close(); - setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); }); connect(fireWallDiaglog, &FirewallDialog::close, this, [=](){ - setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); }); fireWallDiaglog->show(); } else if (configType == KSC_FIREWALL_PUBLIC) { - setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); } else if (configType == KSC_FIREWALL_PRIVATE) { - setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PRIVATE); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PRIVATE); } updateActivatedConnectionArea(p_newItem); @@ -984,7 +985,7 @@ void LanPage::onConnectionStateChange(QString uuid, ssid = p_newItem->m_connectName; updateConnectionArea(p_newItem); updateConnectionState(m_inactiveConnectionMap, m_inactivatedLanListWidget, uuid, (ConnectState)state); - breakNetworkConnect(uuid, deviceName, ssid); + NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, deviceName, ssid); } else if (state == NetworkManager::ActiveConnection::State::Activating) { deviceName = getConnectionDevice(uuid); if (deviceName == m_currentDeviceName) { diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index 99279e6f..c71e772b 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -331,130 +331,3 @@ void getDeviceEnableState(int type, QMap &map) kdr = nullptr; return; } - - -#define ICON_SIZE 16,16 - -FirewallDialog::FirewallDialog(KDialog *parent) -{ - initUI(); - this->setWindowIcon(QIcon::fromTheme("kylin-network")); - this->setFixedSize(480, 204); - setAttribute(Qt::WA_DeleteOnClose); -} - -FirewallDialog::~FirewallDialog() -{ - -} - -void FirewallDialog::initUI() -{ - m_iconLabel = new QLabel(this); - m_contentLabel = new QLabel(this); - m_suggestLabel = new QLabel(this); - m_YesBtn = new QPushButton(this); - m_NoBtn = new QPushButton(this); - m_dialogLayout = new QVBoxLayout(this); - - QWidget *contentWidget = new QWidget(this); - QGridLayout *contentLayout = new QGridLayout(contentWidget); - contentLayout->setContentsMargins(0, 0, 0, 0); - contentLayout->addWidget(m_iconLabel, 0, 0, Qt::AlignTop); - contentLayout->addWidget(m_contentLabel, 0, 1); - contentLayout->addWidget(m_suggestLabel, 1, 1); - m_iconLabel->setFixedWidth(16); - - QWidget *btnWidget = new QWidget(this); - QHBoxLayout *btnLayout = new QHBoxLayout(btnWidget); - btnLayout->setContentsMargins(0, 0, 0, 0); - btnLayout->setSpacing(16); - btnLayout->addStretch(); - btnLayout->addWidget(m_YesBtn); - btnLayout->addWidget(m_NoBtn); - - m_dialogLayout->setContentsMargins(24, 0, 24, 24); - m_dialogLayout->setSpacing(0); - m_dialogLayout->addWidget(contentWidget); - m_dialogLayout->addStretch(); - m_dialogLayout->addWidget(btnWidget); - - QIcon icon = QIcon::fromTheme("dialog-info"); - m_iconLabel->setPixmap(icon.pixmap(ICON_SIZE)); - - QFont font = m_contentLabel->font(); - font.setWeight(75); - m_contentLabel->setFont(font); - //是否允许你的电脑被此网络上的其他电脑和设备发现? - m_contentLabel->setText(tr("Allow your computer to be discovered by other computers and devices on this network?")); - m_contentLabel->setWordWrap(true); - //建议你在家庭和工作网络上而非公共网络上启用此功能。 - m_suggestLabel->setText(tr("It is recommended that you enable this feature on your home and work networks rather than public networks.")); - m_suggestLabel->setWordWrap(true); - - m_YesBtn->setText(tr("Yse")); - m_NoBtn->setText(tr("No")); - - this->closeButton(); - this->mainWidget()->setLayout(m_dialogLayout); - - connect(m_YesBtn, &QPushButton::clicked, this, &FirewallDialog::setPrivateNetMode); - connect(m_NoBtn, &QPushButton::clicked, this, &FirewallDialog::setPublicNetMode); -} - -int TabPage::getNetworkModeConfig(QString uuid) -{ - if (uuid.isEmpty()) { - qWarning()<< /*LOG_FLAG <<*/ "uuid is empty, so can not get network mode config"; - return -1; - } - - - QDBusInterface dbusInterface("com.ksc.defender", - "/firewall", - "com.ksc.defender.firewall", - QDBusConnection::systemBus()); - - - QDBusReply reply = dbusInterface.call("get_networkModeConfig", uuid); - if (reply.isValid()) { - return reply.value(); - } else { - qWarning() << "call get_networkModeConfig failed" << reply.error().message(); - } - return -1; -} - -void TabPage::setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode) -{ - QDBusInterface dbusInterface("com.ksc.defender", - "/firewall", - "com.ksc.defender.firewall", - QDBusConnection::systemBus()); - - - QDBusReply reply = dbusInterface.call("set_networkModeConfig", uuid, cardName, ssid, mode); - if (reply.isValid()) { - qDebug() << "set_networkModeConfig" << ssid << uuid << cardName << mode << ",result" << reply.value(); - } else { - qWarning() << "call set_networkModeConfig" << reply.error().message(); - } -} - -int TabPage::breakNetworkConnect(QString uuid, QString cardName, QString ssid) -{ - QDBusInterface dbusInterface("com.ksc.defender", - "/firewall", - "com.ksc.defender.firewall", - QDBusConnection::systemBus()); - - - QDBusReply reply = dbusInterface.call("break_networkConnect", uuid, cardName, ssid); - if (reply.isValid()) { - qDebug() << "break_networkConnect" << ssid << uuid << cardName << ",result" << reply.value(); - return reply.value(); - } else { - qWarning() << "call break_networkConnect failed" << reply.error().message(); - return -1; - } -} diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index b3a6b0d0..d69ab1cd 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -33,10 +33,10 @@ #include #include #include "kylinnetworkdeviceresource.h" +#include "firewalldialog.h" #include "kwidget.h" #include "kswitchbutton.h" #include "kborderlessbutton.h" -#include "kdialog.h" using namespace kdk; @@ -108,13 +108,6 @@ public: } } - //安全中心-获取网络模式配置 - int getNetworkModeConfig(QString uuid); - //安全中心-设置网络模式配置 - void setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode); - //安全中心-解除连接(用于防火墙处从正在使用的网络中删除) - int breakNetworkConnect(QString uuid, QString cardName, QString ssid); - signals: void deviceStatusChanged(); void deviceNameChanged(QString oldName, QString newName, int type); @@ -162,27 +155,4 @@ public slots: }; - -class FirewallDialog : public KDialog -{ - Q_OBJECT -public: - explicit FirewallDialog(KDialog *parent = nullptr); - ~FirewallDialog(); - -private: - void initUI(); - - QLabel * m_iconLabel = nullptr; - QLabel * m_contentLabel = nullptr; - QLabel * m_suggestLabel = nullptr; - QVBoxLayout *m_dialogLayout = nullptr; - QPushButton *m_YesBtn = nullptr; - QPushButton *m_NoBtn = nullptr; - -signals: - void setPublicNetMode(); - void setPrivateNetMode(); -}; - #endif // TABPAGE_H diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index b0cc175c..8411236d 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -19,6 +19,7 @@ */ #include "wlanpage.h" #include "kywirelessnetitem.h" +#include "networkmodeconfig.h" #include #include #include @@ -940,31 +941,30 @@ void WlanPage::onConnectionStateChanged(QString uuid, m_updateStrength = true; if (!isApConnection) { - int configType = getNetworkModeConfig(uuid); - - if (configType == -1) { - FirewallDialog *fireWallDiaglog = new FirewallDialog(); - fireWallDiaglog->setWindowTitle(ssid); - + int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(uuid); + if (configType == -1) { + FirewallDialog *fireWallDiaglog = new FirewallDialog(); + fireWallDiaglog->setWindowTitle(ssid); connect(fireWallDiaglog, &FirewallDialog::setPrivateNetMode, this, [=](){ fireWallDiaglog->close(); - setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PRIVATE); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PRIVATE); }); connect(fireWallDiaglog, &FirewallDialog::setPublicNetMode, this, [=](){ fireWallDiaglog->close(); - setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PUBLIC); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PUBLIC); }); connect(fireWallDiaglog, &FirewallDialog::close, this, [=](){ - setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PUBLIC); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PUBLIC); }); fireWallDiaglog->show(); + } else if (configType == KSC_FIREWALL_PUBLIC) { - setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PUBLIC); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PUBLIC); } else if (configType == KSC_FIREWALL_PRIVATE) { - setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PRIVATE); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PRIVATE); } } @@ -980,7 +980,7 @@ void WlanPage::onConnectionStateChanged(QString uuid, QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid); updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated); } - breakNetworkConnect(uuid, devName, ssid); + NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, devName, ssid); } else if (state == NetworkManager::ActiveConnection::State::Deactivating){ m_updateStrength = false; if (m_activateConnectionItemMap.contains(ssid)) {