优化代码方法调用

This commit is contained in:
zhangyuanyuan1 2022-07-22 16:13:19 +08:00
parent 011c09a7f4
commit 1dffddcd3b
6 changed files with 25 additions and 175 deletions

View File

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

View File

@ -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 () <<Q_FUNC_INFO << __LINE__ << m_uuid << m_deviceName << m_name << currentConfigType;
}
}

View File

@ -18,6 +18,7 @@
*
*/
#include "lanpage.h"
#include "networkmodeconfig.h"
#include <QDebug>
#include <QScrollBar>
@ -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) {

View File

@ -331,130 +331,3 @@ void getDeviceEnableState(int type, QMap<QString, bool> &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 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<int> reply = dbusInterface.call("get_networkModeConfig", uuid);
if (reply.isValid()) {
return reply.value();
} else {
qWarning() << "call get_networkModeConfig failed" << reply.error().message();
}
return -1;
}
void setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode)
{
QDBusInterface dbusInterface("com.ksc.defender",
"/firewall",
"com.ksc.defender.firewall",
QDBusConnection::systemBus());
QDBusReply<int> 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 breakNetworkConnect(QString uuid, QString cardName, QString ssid)
{
QDBusInterface dbusInterface("com.ksc.defender",
"/firewall",
"com.ksc.defender.firewall",
QDBusConnection::systemBus());
QDBusReply<int> 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;
}
}

View File

@ -33,10 +33,10 @@
#include <QProcess>
#include <QDebug>
#include "kylinnetworkdeviceresource.h"
#include "firewalldialog.h"
#include "kwidget.h"
#include "kswitchbutton.h"
#include "kborderlessbutton.h"
#include "kdialog.h"
using namespace kdk;
@ -82,13 +82,6 @@ void saveDeviceEnableState(QString deviceName, bool enable);
void deleteDeviceEnableState(QString deviceName);
void getDeviceEnableState(int type, QMap<QString, bool> &map);
//安全中心-获取网络模式配置
int getNetworkModeConfig(QString uuid);
//安全中心-设置网络模式配置
void setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode);
//安全中心-解除连接(用于防火墙处从正在使用的网络中删除)
int breakNetworkConnect(QString uuid, QString cardName, QString ssid);
class TabPage : public QWidget
{
Q_OBJECT
@ -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

View File

@ -19,6 +19,7 @@
*/
#include "wlanpage.h"
#include "kywirelessnetitem.h"
#include "networkmodeconfig.h"
#include <QEvent>
#include <QDateTime>
#include <QDebug>
@ -937,7 +938,7 @@ void WlanPage::onConnectionStateChanged(QString uuid,
if (state == NetworkManager::ActiveConnection::State::Activated) {
m_updateStrength = true;
int configType = getNetworkModeConfig(uuid);
int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(uuid);
if (configType == -1) {
FirewallDialog *fireWallDiaglog = new FirewallDialog();
@ -945,23 +946,23 @@ void WlanPage::onConnectionStateChanged(QString uuid,
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);
}
updateActivatedArea(uuid, ssid, devName);
@ -976,7 +977,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)) {