From ad8c64db660a3fa717b101fef4eac68923c6072b Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Thu, 6 Apr 2023 14:09:59 +0800 Subject: [PATCH 01/10] import 2303 --- kylin-nm.pro | 9 + nmqrc.qrc | 4 - plugins/component/AddBtn/addnetbtn.cpp | 27 +- plugins/component/AddBtn/addnetbtn.h | 8 - plugins/mobilehotspot/blacklistpage.cpp | 16 +- plugins/mobilehotspot/blacklistpage.h | 15 +- plugins/mobilehotspot/connectdevpage.cpp | 16 +- plugins/mobilehotspot/connectdevpage.h | 15 +- plugins/mobilehotspot/mobilehotspot.pro | 3 +- plugins/mobilehotspot/mobilehotspotwidget.cpp | 28 +- plugins/mobilehotspot/mobilehotspotwidget.h | 2 +- plugins/mobilehotspot/translations/bo.ts | 48 +-- plugins/mobilehotspot/translations/bo_CN.ts | 44 +- plugins/mobilehotspot/translations/en_US.ts | 126 ++++++ plugins/mobilehotspot/translations/tr.ts | 48 +-- plugins/mobilehotspot/translations/zh_CN.ts | 44 +- plugins/netconnect/lanitem.cpp | 87 +--- plugins/netconnect/lanitem.h | 21 +- plugins/netconnect/netconnect.cpp | 95 ++--- plugins/netconnect/netconnect.h | 4 +- plugins/netconnect/netconnect.pro | 3 +- plugins/netconnect/translations/bo.ts | 29 +- plugins/netconnect/translations/bo_CN.qm | Bin 1440 -> 1159 bytes plugins/netconnect/translations/bo_CN.ts | 48 +-- plugins/netconnect/translations/en_US.ts | 71 ++++ plugins/netconnect/translations/tr.ts | 29 +- plugins/netconnect/translations/zh_CN.qm | Bin 922 -> 711 bytes plugins/netconnect/translations/zh_CN.ts | 46 +- plugins/plugin.pro | 3 +- plugins/proxy/applistwidget.cpp | 12 +- plugins/proxy/aptproxydialog.cpp | 20 +- plugins/proxy/proxy.cpp | 94 +++-- plugins/proxy/proxy.h | 6 +- plugins/wlanconnect/translations/bo.ts | 14 +- plugins/wlanconnect/translations/bo_CN.ts | 14 +- plugins/wlanconnect/translations/en_US.ts | 73 ++++ plugins/wlanconnect/translations/tr.ts | 14 +- plugins/wlanconnect/translations/zh_CN.ts | 14 +- plugins/wlanconnect/wlanconnect.cpp | 74 ++-- plugins/wlanconnect/wlanconnect.h | 5 +- plugins/wlanconnect/wlanconnect.pro | 3 +- plugins/wlanconnect/wlanconnect.ui | 2 +- plugins/wlanconnect/wlanitem.cpp | 19 +- src/backend/backend.pri | 2 - .../kylinactiveconnectresource.cpp | 32 ++ .../kylinactiveconnectresource.h | 1 + .../dbus-interface/kylinagentinterface.c | 16 +- .../dbus-interface/kylinconnectresource.cpp | 111 +---- .../dbus-interface/kylinconnectresource.h | 2 - .../kylinnetworkdeviceresource.cpp | 46 +- .../kylinnetworkdeviceresource.h | 3 + .../kylinnetworkresourcemanager.cpp | 85 ++-- .../kylinnetworkresourcemanager.h | 4 +- .../kywirelessconnectoperation.cpp | 44 +- .../kywirelessconnectoperation.h | 5 + .../dbus-interface/kywirelessnetitem.cpp | 79 ++-- .../dbus-interface/kywirelessnetitem.h | 3 +- .../dbus-interface/kywirelessnetresource.cpp | 72 ++-- .../dbus-interface/kywirelessnetresource.h | 2 +- src/backend/dbusadaptor.cpp | 12 - src/backend/dbusadaptor.h | 2 - src/backend/kylinipv6arping.cpp | 15 + .../enterprise-wlan/enterprisewlandialog.cpp | 51 ++- src/frontend/frontend.pri | 3 - src/frontend/list-items/lanlistitem.cpp | 72 +++- src/frontend/list-items/lanlistitem.h | 2 + src/frontend/list-items/list-items.pri | 6 +- src/frontend/list-items/listitem.cpp | 186 ++++++++- src/frontend/list-items/listitem.h | 64 ++- src/frontend/list-items/wlanlistitem.cpp | 104 ++++- src/frontend/list-items/wlanlistitem.h | 6 +- src/frontend/list-items/wlanmoreitem.cpp | 3 +- src/frontend/mainwindow.cpp | 163 ++++---- src/frontend/mainwindow.h | 10 +- src/frontend/netdetails/configpage.cpp | 4 +- src/frontend/netdetails/coninfo.h | 58 +-- src/frontend/netdetails/creatnetpage.cpp | 126 +++++- src/frontend/netdetails/creatnetpage.h | 12 +- src/frontend/netdetails/detailpage.cpp | 4 +- src/frontend/netdetails/detailwidget.cpp | 41 -- src/frontend/netdetails/detailwidget.h | 18 +- src/frontend/netdetails/ipv4page.cpp | 76 +++- src/frontend/netdetails/ipv4page.h | 15 +- src/frontend/netdetails/ipv6page.cpp | 72 +++- src/frontend/netdetails/ipv6page.h | 22 +- .../netdetails/joinhiddenwifipage.cpp | 51 +-- src/frontend/netdetails/joinhiddenwifipage.h | 5 +- src/frontend/netdetails/netdetail.cpp | 392 ++++++------------ src/frontend/netdetails/netdetail.h | 21 +- src/frontend/netdetails/netdetails.pri | 2 - src/frontend/netdetails/securitypage.cpp | 10 +- src/frontend/netdetails/securitypage.h | 3 +- src/frontend/networkmode/firewalldialog.cpp | 63 ++- src/frontend/networkmode/firewalldialog.h | 15 +- .../networkmode/networkmodeconfig.cpp | 179 +++++++- src/frontend/networkmode/networkmodeconfig.h | 33 ++ src/frontend/tab-pages/lanpage.cpp | 163 ++++---- src/frontend/tab-pages/lanpage.h | 5 +- src/frontend/tab-pages/tabpage.cpp | 143 ++++++- src/frontend/tab-pages/tabpage.h | 21 +- src/frontend/tab-pages/wlanpage.cpp | 218 ++++++---- src/frontend/tab-pages/wlanpage.h | 14 +- src/frontend/tools/kylable.cpp | 40 ++ src/frontend/tools/kylable.h | 17 + src/frontend/tools/radioitembutton.cpp | 2 +- src/frontend/tools/tools.pri | 2 - src/main.cpp | 26 +- src/org.ukui.kylin-nm.switch.gschema.xml | 7 - translate_generation.sh | 15 + translations/kylin-nm_bo.ts | 380 ++++++++--------- translations/kylin-nm_bo_CN.ts | 365 ++++++++-------- translations/kylin-nm_tr.ts | 350 ++++++++-------- translations/kylin-nm_zh_CN.ts | 369 ++++++++--------- 113 files changed, 3354 insertions(+), 2464 deletions(-) create mode 100644 plugins/mobilehotspot/translations/en_US.ts create mode 100644 plugins/netconnect/translations/en_US.ts create mode 100644 plugins/wlanconnect/translations/en_US.ts create mode 100755 translate_generation.sh diff --git a/kylin-nm.pro b/kylin-nm.pro index 7b52af76..1f13a7c2 100644 --- a/kylin-nm.pro +++ b/kylin-nm.pro @@ -12,3 +12,12 @@ TRANSLATIONS += \ translations/kylin-nm_tr.ts \ translations/kylin-nm_bo.ts \ translations/kylin-nm_bo_CN.ts + +CONFIG(release, debug|release) { + !system($$PWD/translate_generation.sh): error("Failed to generate translation") +} + +qm_files.path = $${PREFIX}/share/kylin-nm/kylin-nm/ +qm_files.files = translations/*.qm + +INSTALLS += qm_files \ diff --git a/nmqrc.qrc b/nmqrc.qrc index c379b198..aea1ec48 100644 --- a/nmqrc.qrc +++ b/nmqrc.qrc @@ -17,9 +17,6 @@ res/h/right-pwd.png res/h/show-pwd.png res/h/no-pwd-wifi.png - translations/kylin-nm_bo.qm - translations/kylin-nm_tr.qm - translations/kylin-nm_zh_CN.qm res/x/fly-mode-off.svg res/x/fly-mode-on.svg res/x/hot-spot-off.svg @@ -128,6 +125,5 @@ res/s/conning-b/10.png res/s/conning-b/11.png res/s/conning-b/12.png - translations/kylin-nm_bo_CN.qm diff --git a/plugins/component/AddBtn/addnetbtn.cpp b/plugins/component/AddBtn/addnetbtn.cpp index eb1bc6fb..811a0c99 100644 --- a/plugins/component/AddBtn/addnetbtn.cpp +++ b/plugins/component/AddBtn/addnetbtn.cpp @@ -20,6 +20,7 @@ #include "addnetbtn.h" #include #include +#include #include #include #include @@ -33,15 +34,11 @@ AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent) this->setMaximumSize(QSize(16777215, 60)); this->setProperty("useButtonPalette", true); this->setFlat(true); - QPalette pal = this->palette(); - QColor color = pal.color(QPalette::Button); - color.setAlphaF(0.5); - pal.setColor(QPalette::Button, color); - this->setPalette(pal); - QHBoxLayout *addLyt = new QHBoxLayout(this); - QLabel *iconLabel = new QLabel(this); - textLabel = new QLabel(this); + QHBoxLayout *addLyt = new QHBoxLayout; + + QLabel *iconLabel = new QLabel(); + QLabel *textLabel = new QLabel(); if (isWlan) { textLabel->setText(tr("Add Others")); @@ -51,8 +48,8 @@ AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent) textLabel->setText(tr("Add WiredNetork")); QIcon mAddIcon = QIcon::fromTheme("list-add-symbolic"); iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(24, 24)))); - iconLabel->setProperty("useIconHighlightEffect", true); - iconLabel->setProperty("iconHighlightEffectMode", 1); + iconLabel->setProperty("useIconHighlightEffect", 0x2); +// iconLabel->setProperty("iconHighlightEffectMode", 1); addLyt->addStretch(); addLyt->addWidget(iconLabel); @@ -61,7 +58,6 @@ AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent) addLyt->addStretch(); this->setLayout(addLyt); - } AddNetBtn::~AddNetBtn() @@ -83,12 +79,17 @@ void AddNetBtn::leaveEvent(QEvent *event){ void AddNetBtn::paintEvent(QPaintEvent *event) { - QPalette pal = this->palette(); + QPalette pal = qApp->palette(); QPainter painter(this); painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿 painter.setPen(Qt::NoPen); - painter.setBrush(pal.color(QPalette::Base)); + painter.setBrush(this->palette().base().color()); + + QColor color = pal.color(QPalette::Button); + color.setAlphaF(0.5); + pal.setColor(QPalette::Button, color); + this->setPalette(pal); QRect rect = this->rect(); QPainterPath path; diff --git a/plugins/component/AddBtn/addnetbtn.h b/plugins/component/AddBtn/addnetbtn.h index 60ba8028..959d2d09 100644 --- a/plugins/component/AddBtn/addnetbtn.h +++ b/plugins/component/AddBtn/addnetbtn.h @@ -25,7 +25,6 @@ #include #include #include -#include class AddNetBtn : public QPushButton { @@ -34,18 +33,11 @@ public: AddNetBtn(bool isWlan, QWidget *parent = nullptr); ~AddNetBtn(); - void setTextLabel(QString str) { - textLabel->setText(str); - } - protected: virtual void leaveEvent(QEvent * event); virtual void enterEvent(QEvent * event); void paintEvent(QPaintEvent *event); -private: - QLabel* textLabel; - Q_SIGNALS: void enterWidget(); void leaveWidget(); diff --git a/plugins/mobilehotspot/blacklistpage.cpp b/plugins/mobilehotspot/blacklistpage.cpp index 1b82d8bd..d923749c 100644 --- a/plugins/mobilehotspot/blacklistpage.cpp +++ b/plugins/mobilehotspot/blacklistpage.cpp @@ -34,12 +34,12 @@ BlacklistPage::BlacklistPage(QWidget *parent) : QWidget(parent) Vlayout->setContentsMargins(CONTENTS_MARGINS); Vlayout->setSpacing(0); - QFrame *blacklistFrame = new QFrame(this); - blacklistFrame->setMinimumSize(FRAME_MIN_SIZE); - blacklistFrame->setMaximumSize(FRAME_MAX_SIZE); - blacklistFrame->setFrameShape(QFrame::Box); + m_blacklistFrame = new QFrame(this); + m_blacklistFrame->setMinimumSize(FRAME_MIN_SIZE); + m_blacklistFrame->setMaximumSize(FRAME_MAX_SIZE); + m_blacklistFrame->setFrameShape(QFrame::Box); - m_blacklistLayout = new QVBoxLayout(blacklistFrame); + m_blacklistLayout = new QVBoxLayout(m_blacklistFrame); m_blacklistLayout->setContentsMargins(0, 0, 0, 0); m_blacklistLayout->setSpacing(0); @@ -48,7 +48,7 @@ BlacklistPage::BlacklistPage(QWidget *parent) : QWidget(parent) Vlayout->addWidget(m_titleLabel); Vlayout->addSpacing(8); - Vlayout->addWidget(blacklistFrame); + Vlayout->addWidget(m_blacklistFrame); } QFrame* BlacklistPage::myLine() @@ -87,7 +87,7 @@ void BlacklistPage::getBlacklistDevice(QMap &blacklistMap) for (int index = 0; index < macList.count() && macList.at(index) != nullptr; index ++) { QString macTemp = macList.at(index); macTemp = macTemp.trimmed(); - if (!blacklistMap.contains(macTemp)) { + if (!blacklistMap.contains(macTemp) && hostNameList.at(index) != nullptr) { blacklistMap[macTemp] = hostNameList.at(index); } } @@ -166,7 +166,7 @@ void BlacklistPage::resetLayoutHight() height += w->height(); } } - this->setFixedHeight(height + m_titleLabel->height() + 8); + m_blacklistFrame->setFixedHeight(height); if (m_blacklistMap.isEmpty()) { this->hide(); diff --git a/plugins/mobilehotspot/blacklistpage.h b/plugins/mobilehotspot/blacklistpage.h index a1e3f01d..8a511c1d 100644 --- a/plugins/mobilehotspot/blacklistpage.h +++ b/plugins/mobilehotspot/blacklistpage.h @@ -49,15 +49,8 @@ public: } private: - QFrame* myLine(); - TitleLabel *m_titleLabel = nullptr; - QVBoxLayout *m_blacklistLayout = nullptr; - QMap m_blacklistMap; - - QDBusInterface *m_settingPathInterface = nullptr; - void getBlacklistDevice(QMap &blacklistMap); bool removeStaFromBlacklist(QString staMac, QString staName); void initBlacklistDev(); @@ -65,6 +58,14 @@ private: void clearBlacklistLayout(); void resetLayoutHight(); +private: + QFrame *m_blacklistFrame = nullptr; + TitleLabel *m_titleLabel = nullptr; + QVBoxLayout *m_blacklistLayout = nullptr; + QMap m_blacklistMap; + + QDBusInterface *m_settingPathInterface = nullptr; + private slots: void onsetStaIntoBlacklist(QString staMac, QString staName); void onRemoveFromBlacklistBtnClicked(QString staMac, QString staName); diff --git a/plugins/mobilehotspot/connectdevpage.cpp b/plugins/mobilehotspot/connectdevpage.cpp index f8862e01..473a4c69 100644 --- a/plugins/mobilehotspot/connectdevpage.cpp +++ b/plugins/mobilehotspot/connectdevpage.cpp @@ -35,12 +35,12 @@ ConnectdevPage::ConnectdevPage(QWidget *parent) : Vlayout->setContentsMargins(CONTENTS_MARGINS); Vlayout->setSpacing(0); - QFrame *staistFrame = new QFrame(this); - staistFrame->setMinimumSize(FRAME_MIN_SIZE); - staistFrame->setMaximumSize(FRAME_MAX_SIZE); - staistFrame->setFrameShape(QFrame::Box); + m_staistFrame = new QFrame(this); + m_staistFrame->setMinimumSize(FRAME_MIN_SIZE); + m_staistFrame->setMaximumSize(FRAME_MAX_SIZE); + m_staistFrame->setFrameShape(QFrame::Box); - m_staListLayout = new QVBoxLayout(staistFrame); + m_staListLayout = new QVBoxLayout(m_staistFrame); m_staListLayout->setContentsMargins(0, 0, 0, 0); m_staListLayout->setSpacing(0); @@ -49,7 +49,7 @@ ConnectdevPage::ConnectdevPage(QWidget *parent) : Vlayout->addWidget(m_titleLabel); Vlayout->addSpacing(8); - Vlayout->addWidget(staistFrame); + Vlayout->addWidget(m_staistFrame); } QFrame* ConnectdevPage::myLine() @@ -90,7 +90,7 @@ void ConnectdevPage::getConnectStaDevice(QMap &staMap) QStringList macList = reply.arguments().at(0).toString().split(";"); QStringList hostNameList = reply.arguments().at(1).toString().split(";"); for (int index = 0; index < macList.count() && macList.at(index) != nullptr; index ++) { - if (!staMap.contains(macList.at(index))) { + if (!staMap.contains(macList.at(index)) && hostNameList.at(index) != nullptr) { staMap[macList.at(index)] = hostNameList.at(index); } } @@ -158,7 +158,7 @@ void ConnectdevPage::resetLayoutHight() height += w->height(); } } - this->setFixedHeight(height + m_titleLabel->height() + 8); + m_staistFrame->setFixedHeight(height); if (m_staMap.isEmpty()) { this->hide(); diff --git a/plugins/mobilehotspot/connectdevpage.h b/plugins/mobilehotspot/connectdevpage.h index 944fc995..ce9abb09 100644 --- a/plugins/mobilehotspot/connectdevpage.h +++ b/plugins/mobilehotspot/connectdevpage.h @@ -50,12 +50,6 @@ public: private: QFrame* myLine(); - TitleLabel *m_titleLabel = nullptr; - QVBoxLayout *m_staListLayout = nullptr; - QMap m_staMap; - - QDBusInterface *m_activePathInterface = nullptr; - void getConnectStaDevice(QMap &blacklistMap); bool removeStaFromBlacklist(QString staMac); void initStaDev(); @@ -67,6 +61,15 @@ private: void onStaDevChanged(bool istrue, QString staMac, QString staName); void resetLayoutHight(); +private: + QFrame *m_staistFrame = nullptr; + + TitleLabel *m_titleLabel = nullptr; + QVBoxLayout *m_staListLayout = nullptr; + QMap m_staMap; + + QDBusInterface *m_activePathInterface = nullptr; + signals: void setStaIntoBlacklist(QString staMac, QString staName); diff --git a/plugins/mobilehotspot/mobilehotspot.pro b/plugins/mobilehotspot/mobilehotspot.pro index 0bb86a93..90c84dab 100644 --- a/plugins/mobilehotspot/mobilehotspot.pro +++ b/plugins/mobilehotspot/mobilehotspot.pro @@ -49,4 +49,5 @@ TRANSLATIONS += \ translations/zh_CN.ts \ translations/tr.ts \ translations/bo.ts\ - translations/bo_CN.ts + translations/bo_CN.ts \ + translations/en_US.ts diff --git a/plugins/mobilehotspot/mobilehotspotwidget.cpp b/plugins/mobilehotspot/mobilehotspotwidget.cpp index a5a35240..a03a2af1 100644 --- a/plugins/mobilehotspot/mobilehotspotwidget.cpp +++ b/plugins/mobilehotspot/mobilehotspotwidget.cpp @@ -264,13 +264,10 @@ void MobileHotspotWidget::initDbusConnect() connect(m_interface,SIGNAL(hotspotActivated(QString, QString, QString, QString, QString)), this, SLOT(onHotspotActivated(QString, QString, QString, QString, QString)), Qt::QueuedConnection); connect(m_interface, SIGNAL(wlanactiveConnectionStateChanged(QString, QString, QString, int)), this, SLOT(onActiveConnectionChanged(QString, QString, QString, int)), Qt::QueuedConnection); + + connect(m_interface, SIGNAL(wirelessSwitchBtnChanged(bool)), this, SLOT(onWirelessBtnChanged(bool)), Qt::QueuedConnection); } - if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { - m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); - onGsettingChanged(WIRELESS_SWITCH); - connect(m_switchGsettings, &QGSettings::changed, this, &MobileHotspotWidget::onGsettingChanged, Qt::QueuedConnection); - } connect(m_apNameLine, &QLineEdit::textEdited, this, &MobileHotspotWidget::onApLineEditTextEdit); #ifdef HOTSPOT_CONTROL @@ -317,17 +314,14 @@ void MobileHotspotWidget::onActiveConnectionChanged(QString deviceName, QString } } -void MobileHotspotWidget::onGsettingChanged(const QString &key) +void MobileHotspotWidget::onWirelessBtnChanged(bool state) { - if (key == WIRELESS_SWITCH) { - bool status = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); - if (!status) { - m_switchBtn->setChecked(status); - m_uuid.clear(); - m_switchBtn->setCheckable(false); - } else { - m_switchBtn->setCheckable(true); - } + if (!state) { + m_switchBtn->setChecked(state); + m_uuid.clear(); + m_switchBtn->setCheckable(false); + } else { + m_switchBtn->setCheckable(true); } } @@ -720,7 +714,9 @@ void MobileHotspotWidget::setWidgetHidden(bool isHidden) m_uuid = ""; } else { m_switchBtn->setCheckable(true); - onGsettingChanged(WIRELESS_SWITCH); + QDBusReply reply = m_interface->call("getWirelessSwitchBtnState"); + bool state = reply.value(); + onWirelessBtnChanged(state); } resetFrameSize(); diff --git a/plugins/mobilehotspot/mobilehotspotwidget.h b/plugins/mobilehotspot/mobilehotspotwidget.h index 7b6fe876..13b29d9d 100644 --- a/plugins/mobilehotspot/mobilehotspotwidget.h +++ b/plugins/mobilehotspot/mobilehotspotwidget.h @@ -151,7 +151,7 @@ private slots: //热点连接 void onHotspotActivated(QString devName, QString ssid, QString uuid, QString activePath, QString settingPath); - void onGsettingChanged(const QString &key); + void onWirelessBtnChanged(bool state); void onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, int status); diff --git a/plugins/mobilehotspot/translations/bo.ts b/plugins/mobilehotspot/translations/bo.ts index 70f2c4b7..2c1f8b3d 100644 --- a/plugins/mobilehotspot/translations/bo.ts +++ b/plugins/mobilehotspot/translations/bo.ts @@ -4,7 +4,7 @@ BlacklistItem - + Remove @@ -12,7 +12,7 @@ BlacklistPage - + Blacklist @@ -20,7 +20,7 @@ ConnectDevListItem - + drag into blacklist @@ -28,7 +28,7 @@ ConnectdevPage - + Connect device @@ -56,79 +56,69 @@ MobileHotspotWidget - + ukui control center - + ukui control center desktop message - + wirless switch is close or no wireless device - - start to close hotspot - - - - + hotpots name or device is invalid - - start to open hotspot - - - - + Contains at least 8 characters - + Hotspot - - + + hotspot already close - + Open - + Wi-Fi Name - + Password - + Frequency band - + Net card - - + + hotspot already open diff --git a/plugins/mobilehotspot/translations/bo_CN.ts b/plugins/mobilehotspot/translations/bo_CN.ts index 2e4fb436..f2f82810 100644 --- a/plugins/mobilehotspot/translations/bo_CN.ts +++ b/plugins/mobilehotspot/translations/bo_CN.ts @@ -4,7 +4,7 @@ BlacklistItem - + Remove སྤོ་སྐྱོད་བྱས་པ། @@ -12,7 +12,7 @@ BlacklistPage - + Blacklist སྒྲིག་ཆས་ཀྱི་མིང་ཐོ་ནག་པོ། @@ -20,7 +20,7 @@ ConnectDevListItem - + drag into blacklist མིང་ཐོ་ནག་པོའི་ཁ་སྣོན་རྒྱག་པ། @@ -28,7 +28,7 @@ ConnectdevPage - + Connect device འབྲེལ་མཐུད་སྒྲིག་ཆས། @@ -56,27 +56,26 @@ MobileHotspotWidget - + ukui control center ཝུའུ་ཁི་ལན་གྱི་ཚོད་འཛིན་ལྟེ་གནས། - + ukui control center desktop message ukui ཚོད་འཛིན་ལྟེ་གནས་ཀྱི་ཅོག་ངོས་ཆ་འཕྲིན། - + wirless switch is close or no wireless device སྐུད་མེད་གློག་སྒོ་རྒྱག་པའམ་ཡང་ན་སྐུད་མེད་སྒྲིག་ཆས་མེད་པ། - start to close hotspot - སྒོ་རྒྱག་འགོ་བརྩམས། + སྒོ་རྒྱག་འགོ་བརྩམས། - + hotpots name or device is invalid ཚ་བ་ཆེ་བའི་མིང་ངམ་སྒྲིག་ཆས་ལ་ནུས་པ་མེད། @@ -85,54 +84,53 @@ གསང་གྲངས་ཀྱི་རིང་ཚད་ནི་གླེང་མང་བའི་གནད་དོན་བརྒྱད་ལས་ཆུང་བ་བྱེད་མི་རུང་།! - start to open hotspot - ཀུན་གྱིས་དོ་སྣང་བྱེད་ཡུལ་གསར་སྐྲུན་བྱེད་འགོ་ + ཀུན་གྱིས་དོ་སྣང་བྱེད་ཡུལ་གསར་སྐྲུན་བྱེད་འགོ་ - + Contains at least 8 characters མ་མཐར་ཡང་ཡིག་རྟགས་བརྒྱད་འདུས་ཡོད། - + Hotspot ཚ་བ་ཆེ་བ། - - + + hotspot already close ཚ་བ་ཆེ་བའི་གནད་དོན་ཐག་ཉེ་རུ་སོང་ཡོད། - + Open སྒོ་ཕྱེ་བ། - + Wi-Fi Name Wi-Fiཡི་མིང་། - + Password གསང་གྲངས། - + Frequency band ཐེངས་གྲངས་ཀྱི་རོལ་ཆའི་རུ་ཁག - + Net card དྲ་རྒྱའི་བྱང་བུ། - - + + hotspot already open ཚ་བ་ཆེ་བའི་གནད་དོན་དེ་སྒོ་ཕྱེ་ཟིན། diff --git a/plugins/mobilehotspot/translations/en_US.ts b/plugins/mobilehotspot/translations/en_US.ts new file mode 100644 index 00000000..bb4f55f3 --- /dev/null +++ b/plugins/mobilehotspot/translations/en_US.ts @@ -0,0 +1,126 @@ + + + + + BlacklistItem + + + Remove + Remove + + + + BlacklistPage + + + Blacklist + Blacklist + + + + ConnectDevListItem + + + drag into blacklist + drag into blacklist + + + + ConnectdevPage + + + Connect device + Connect device + + + + MobileHotspot + + + MobileHotspot + MobileHotspot + + + + mobilehotspot + mobilehotspot + /mobilehotspot/mobilehotspot + + + + mobilehotspot open + mobilehotspot open + /mobilehotspot/mobilehotspot open + + + + MobileHotspotWidget + + + ukui control center + ukui control center + + + + ukui control center desktop message + ukui control center desktop message + + + + wirless switch is close or no wireless device + wirless switch is close or no wireless device + + + + hotpots name or device is invalid + hotpots name or device is invalid + + + + Hotspot + Hotspot + + + + + hotspot already close + hotspot already close + + + + Open + Open + + + + Wi-Fi Name + Wi-Fi Name + + + + Password + Password + + + + Contains at least 8 characters + Contains at least 8 characters + + + + Frequency band + Frequency band + + + + Net card + Net card + + + + + hotspot already open + hotspot already open + + + diff --git a/plugins/mobilehotspot/translations/tr.ts b/plugins/mobilehotspot/translations/tr.ts index 70f2c4b7..2c1f8b3d 100644 --- a/plugins/mobilehotspot/translations/tr.ts +++ b/plugins/mobilehotspot/translations/tr.ts @@ -4,7 +4,7 @@ BlacklistItem - + Remove @@ -12,7 +12,7 @@ BlacklistPage - + Blacklist @@ -20,7 +20,7 @@ ConnectDevListItem - + drag into blacklist @@ -28,7 +28,7 @@ ConnectdevPage - + Connect device @@ -56,79 +56,69 @@ MobileHotspotWidget - + ukui control center - + ukui control center desktop message - + wirless switch is close or no wireless device - - start to close hotspot - - - - + hotpots name or device is invalid - - start to open hotspot - - - - + Contains at least 8 characters - + Hotspot - - + + hotspot already close - + Open - + Wi-Fi Name - + Password - + Frequency band - + Net card - - + + hotspot already open diff --git a/plugins/mobilehotspot/translations/zh_CN.ts b/plugins/mobilehotspot/translations/zh_CN.ts index 4d44a72a..a9fb2288 100644 --- a/plugins/mobilehotspot/translations/zh_CN.ts +++ b/plugins/mobilehotspot/translations/zh_CN.ts @@ -4,7 +4,7 @@ BlacklistItem - + Remove 移出 @@ -12,7 +12,7 @@ BlacklistPage - + Blacklist 设备黑名单 @@ -20,7 +20,7 @@ ConnectDevListItem - + drag into blacklist 添加进黑名单 @@ -28,7 +28,7 @@ ConnectdevPage - + Connect device 连接设备 @@ -56,27 +56,26 @@ MobileHotspotWidget - + ukui control center 控制面板 - + ukui control center desktop message 控制面板桌面通知 - + wirless switch is close or no wireless device 无线开关已关闭或不存在有热点功能的无线网卡 - start to close hotspot - 开始关闭热点 + 开始关闭热点 - + hotpots name or device is invalid 热点名称或设备错误 @@ -85,54 +84,53 @@ 不能创建密码长度小于八位的热点! - start to open hotspot - 开始创建热点 + 开始创建热点 - + Contains at least 8 characters 至少包含8个字符 - + Hotspot 移动热点 - - + + hotspot already close 热点已关闭 - + Open 开启 - + Wi-Fi Name Wi-Fi名称 - + Password 网络密码 - + Frequency band 网络频带 - + Net card 共享网卡端口 - - + + hotspot already open 热点已开启 diff --git a/plugins/netconnect/lanitem.cpp b/plugins/netconnect/lanitem.cpp index ad0aad0c..2df49237 100644 --- a/plugins/netconnect/lanitem.cpp +++ b/plugins/netconnect/lanitem.cpp @@ -18,6 +18,8 @@ * */ #include "lanitem.h" +#include + #define FRAME_SPEED 150 #define LIMIT_TIME 60*1000 #define TOTAL_PAGE 8 @@ -31,11 +33,6 @@ LanItem::LanItem(bool isAcitve, QWidget *parent) this->setMinimumSize(550, 58); this->setProperty("useButtonPalette", true); this->setFlat(true); - QPalette pal = this->palette(); - QColor color = pal.color(QPalette::Button); - color.setAlphaF(0.5); - pal.setColor(QPalette::Button, color); - this->setPalette(pal); // setStyleSheet("QPushButton:!checked{background-color: palette(base)}"); QHBoxLayout *mLanLyt = new QHBoxLayout(this); mLanLyt->setContentsMargins(16,0,16,0); @@ -44,31 +41,15 @@ LanItem::LanItem(bool isAcitve, QWidget *parent) iconLabel->setProperty("useIconHighlightEffect", 0x2); titileLabel = new FixLabel(this); statusLabel = new QLabel(this); + statusLabel->setProperty("useIconHighlightEffect", 0x2); statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // statusLabel->setMinimumSize(36,36); infoLabel = new GrayInfoButton(this); - - //【更多】菜单 - m_moreButton = new QToolButton(this); - m_moreButton->setProperty("useButtonPalette", true); - m_moreButton->setPopupMode(QToolButton::InstantPopup); - m_moreButton->setAutoRaise(true); - m_moreButton->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic")); - m_moreMenu = new QMenu(m_moreButton); - m_connectAction = new QAction(m_moreMenu); - m_deleteAction = new QAction(tr("Delete"), m_moreMenu); - setConnectActionText(isAcitve); - - m_moreMenu->addAction(m_connectAction); - m_moreMenu->addAction(m_deleteAction); - m_moreButton->setMenu(m_moreMenu); - mLanLyt->addWidget(iconLabel); mLanLyt->addWidget(titileLabel,Qt::AlignLeft); mLanLyt->addStretch(); mLanLyt->addWidget(statusLabel); mLanLyt->addWidget(infoLabel); - mLanLyt->addWidget(m_moreButton); loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic")); loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic")); @@ -79,10 +60,6 @@ LanItem::LanItem(bool isAcitve, QWidget *parent) loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic")); waitTimer = new QTimer(this); connect(waitTimer, &QTimer::timeout, this, &LanItem::updateIcon); - - connect(m_connectAction, &QAction::triggered, this, &LanItem::onConnectTriggered); - connect(m_deleteAction, &QAction::triggered, this, &LanItem::onDeletetTriggered); - m_moreMenu->installEventFilter(this); } LanItem::~LanItem() @@ -110,48 +87,19 @@ void LanItem::stopLoading(){ loading = false; } -/** - * @brief LanItem::setConnectActionText - * 【更多】菜单状态切换 连接/断开 - * @param isAcitve - */ -void LanItem::setConnectActionText(bool isAcitve) -{ - if (isAcitve) { - m_connectAction->setText(tr("Disconnect")); - } else { - m_connectAction->setText(tr("Connect")); - } -} - -void LanItem::onConnectTriggered() -{ - if (!m_connectAction) { - return; - } - if (m_connectAction->text() == tr("Connect")) { - Q_EMIT connectActionTriggered(); - } else if (m_connectAction->text() == tr("Disconnect")) { - Q_EMIT disconnectActionTriggered(); - } -} - -void LanItem::onDeletetTriggered() -{ - if (!m_deleteAction) { - return; - } - Q_EMIT deleteActionTriggered(); -} - void LanItem::paintEvent(QPaintEvent *event) { - QPalette pal = this->palette(); + QPalette pal = qApp->palette(); QPainter painter(this); painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿 painter.setPen(Qt::NoPen); - painter.setBrush(pal.color(QPalette::Base)); + painter.setBrush(this->palette().base().color()); + + QColor color = pal.color(QPalette::Button); + color.setAlphaF(0.5); + pal.setColor(QPalette::Button, color); + this->setPalette(pal); QRect rect = this->rect(); @@ -159,18 +107,3 @@ void LanItem::paintEvent(QPaintEvent *event) QPushButton::paintEvent(event); } -bool LanItem::eventFilter(QObject *watched, QEvent *event) -{ - //菜单右边界与按钮右边界对齐 - if (event->type() == QEvent::Show && watched == m_moreMenu) { - int menuXPos = m_moreMenu->pos().x(); - int menuWidth = m_moreMenu->size().width(); - int btnWidth = m_moreButton->size().width(); - - QPoint pos = QPoint (menuXPos - menuWidth + btnWidth, m_moreMenu->pos().y()); - m_moreMenu->move(pos); - return true; - } - return false; -} - diff --git a/plugins/netconnect/lanitem.h b/plugins/netconnect/lanitem.h index b27a9df2..ea1b1355 100644 --- a/plugins/netconnect/lanitem.h +++ b/plugins/netconnect/lanitem.h @@ -29,16 +29,12 @@ #include #include #include -#include -#include -#include #include "fixlabel.h" //#include "infobutton.h" #include "../component/AddBtn/grayinfobutton.h" class LanItem : public QPushButton { - Q_OBJECT public: LanItem(bool isAcitve, QWidget *parent = nullptr); ~LanItem(); @@ -47,15 +43,10 @@ public: GrayInfoButton * infoLabel = nullptr; FixLabel * titileLabel = nullptr; QLabel * statusLabel = nullptr; - QToolButton* m_moreButton = nullptr; - QMenu* m_moreMenu = nullptr; - QAction* m_connectAction = nullptr; - QAction* m_deleteAction = nullptr; public: void startLoading(); void stopLoading(); - void setConnectActionText(bool isAcitve); bool loading = false; bool isAcitve = false; @@ -65,23 +56,15 @@ public: protected: void paintEvent(QPaintEvent *); - bool eventFilter(QObject *watched, QEvent *event); private: QTimer *waitTimer = nullptr; QGSettings *themeGsettings = nullptr; QList loadIcons; - int currentIconIndex=0; + int currentIconIndex=0; private slots: - void updateIcon(); - void onConnectTriggered(); - void onDeletetTriggered(); - -Q_SIGNALS: - void connectActionTriggered(); - void disconnectActionTriggered(); - void deleteActionTriggered(); + void updateIcon(); }; diff --git a/plugins/netconnect/netconnect.cpp b/plugins/netconnect/netconnect.cpp index 21fbe697..71bb66ee 100644 --- a/plugins/netconnect/netconnect.cpp +++ b/plugins/netconnect/netconnect.cpp @@ -32,9 +32,6 @@ #define ITEMHEIGH 50 #define LAN_TYPE 0 #define CONTROL_CENTER_WIFI "org.ukui.control-center.wifi.switch" -#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" -#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" -#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" const QString KLanSymbolic = "network-wired-connected-symbolic"; const QString NoNetSymbolic = "network-wired-disconnected-symbolic"; @@ -81,7 +78,7 @@ NetConnect::NetConnect() : mFirstLoad(true) { translator->load("/usr/share/kylin-nm/netconnect/" + QLocale::system().name()); QApplication::installTranslator(translator); - pluginName = tr("WiredConnect"); + pluginName = tr("LAN"); pluginType = NETWORK; } @@ -153,7 +150,7 @@ QString NetConnect::translationPath() const void NetConnect::initSearchText() { //~ contents_path /netconnect/Advanced settings" ui->detailBtn->setText(tr("Advanced settings")); - ui->titleLabel->setText(tr("Wired Network")); + ui->titleLabel->setText(tr("LAN")); //~ contents_path /netconnect/open ui->openLabel->setText(tr("open")); } @@ -171,7 +168,9 @@ bool NetConnect::eventFilter(QObject *w, QEvent *e) { if (!wiredSwitch->isCheckable()) { showDesktopNotify(tr("No ethernet device avaliable")); } else { - m_interface->call(QStringLiteral("setWiredSwitchEnable"), !wiredSwitch->isChecked()); + if (m_interface != nullptr && m_interface->isValid()) { + m_interface->call(QStringLiteral("setWiredSwitchEnable"), !wiredSwitch->isChecked()); + } return true; } } @@ -245,7 +244,7 @@ void NetConnect::initComponent() { //获取网卡列表 void NetConnect::getDeviceStatusMap(QMap &map) { - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } qDebug() << "[NetConnect]call getDeviceListAndEnabled" << __LINE__; @@ -353,22 +352,16 @@ void NetConnect::initNet() } void NetConnect::runExternalApp() { -// QString cmd = "nm-connection-editor"; -// QProcess process(this); -// process.startDetached(cmd); - LaunchApp("nm-connection-editor.desktop"); -} - -//刪除 -void NetConnect::deleteOneLan(QString ssid, int type) -{ - qDebug() << "[NetConnect]call deleteConnect" << __LINE__; - m_interface->call(QStringLiteral("deleteConnect"), type, ssid); - qDebug() << "[NetConnect]call deleteConnect respond" << __LINE__; + QString cmd = "nm-connection-editor"; + QProcess process(this); + process.startDetached(cmd); } //激活 void NetConnect::activeConnect(QString ssid, QString deviceName, int type) { + if (m_interface == nullptr || !m_interface->isValid()) { + return; + } qDebug() << "[NetConnect]call activateConnect" << __LINE__; m_interface->call(QStringLiteral("activateConnect"),type, deviceName, ssid); qDebug() << "[NetConnect]call activateConnect respond" << __LINE__; @@ -376,6 +369,9 @@ void NetConnect::activeConnect(QString ssid, QString deviceName, int type) { //断开 void NetConnect::deActiveConnect(QString ssid, QString deviceName, int type) { + if (m_interface == nullptr || !m_interface->isValid()) { + return; + } qDebug() << "[NetConnect]call deActivateConnect" << __LINE__; m_interface->call(QStringLiteral("deActivateConnect"),type, deviceName, ssid); qDebug() << "[NetConnect]call deActivateConnect respond" << __LINE__; @@ -389,7 +385,7 @@ void NetConnect::initNetListFromDevice(QString deviceName) qDebug() << "[NetConnect]initNetListFromDevice " << deviceName << " not exist"; return; } - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } qDebug() << "[NetConnect]call getWiredList" << __LINE__; @@ -435,12 +431,12 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL return; } - LanItem * lanItem = new LanItem(isActived, pluginWidget); + LanItem * lanItem = new LanItem(pluginWidget); QString iconPath = KLanSymbolic; if (isActived) { lanItem->statusLabel->setText(tr("connected")); } else { - lanItem->statusLabel->setText(tr("not connected")); + lanItem->statusLabel->setText(""); } QIcon searchIcon = QIcon::fromTheme(iconPath); // if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) { @@ -454,7 +450,7 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL connect(lanItem->infoLabel, &GrayInfoButton::clicked, this, [=]{ // open landetail page - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } qDebug() << "[NetConnect]call showPropertyWidget" << __LINE__; @@ -463,7 +459,6 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL }); lanItem->isAcitve = isActived; - lanItem->setConnectActionText(lanItem->isAcitve); connect(lanItem, &QPushButton::clicked, this, [=] { if (lanItem->isAcitve || lanItem->loading) { @@ -473,16 +468,6 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL } }); - connect(lanItem, &LanItem::connectActionTriggered, this, [=] { - activeConnect(lanItem->uuid, devName, WIRED_TYPE); - }); - connect(lanItem, &LanItem::disconnectActionTriggered, this, [=] { - deActiveConnect(lanItem->uuid, devName, WIRED_TYPE); - }); - connect(lanItem, &LanItem::deleteActionTriggered, this, [=] { - deleteOneLan(lanItem->uuid, WIRED_TYPE); - }); - //记录到deviceFrame的itemMap中 deviceFrameMap[devName]->itemMap.insert(infoList.at(1), lanItem); qDebug()<<"insert " << infoList.at(1) << " to " << devName << " list"; @@ -492,6 +477,9 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL //增加设备 void NetConnect::addDeviceFrame(QString devName) { + if (m_interface == nullptr || !m_interface->isValid()) { + return; + } qDebug() << "[NetConnect]addDeviceFrame " << devName; qDebug() << "[NetConnect]call getDeviceListAndEnabled" << __LINE__; @@ -538,18 +526,20 @@ void NetConnect::addDeviceFrame(QString devName) qDebug() << "[NetConnect]set " << devName << "status" << true; itemFrame->lanItemFrame->show(); itemFrame->deviceFrame->dropDownLabel->show(); + itemFrame->addLanWidget->show(); itemFrame->deviceFrame->dropDownLabel->setDropDownStatus(true); deviceStatusMap[devName] = true; } else { qDebug() << "[NetConnect]set " << devName << "status" << false; itemFrame->lanItemFrame->hide(); itemFrame->deviceFrame->dropDownLabel->hide(); + itemFrame->addLanWidget->hide(); deviceStatusMap[devName] = false; } }); connect(itemFrame->addLanWidget, &AddNetBtn::clicked, this, [=](){ - if (m_interface->isValid()) { + if (m_interface != nullptr && m_interface->isValid()) { qDebug() << "[NetConnect]call showCreateWiredConnectWidget" << devName << __LINE__; m_interface->call(QStringLiteral("showCreateWiredConnectWidget"), devName); qDebug() << "[NetConnect]call setDeviceEnable Respond" << __LINE__; @@ -732,7 +722,7 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis QString iconPath; iconPath = KLanSymbolic; - lanItem->statusLabel->setText(tr("not connected")); + lanItem->statusLabel->setText(""); QIcon searchIcon = QIcon::fromTheme(iconPath); // if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) { @@ -746,7 +736,7 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis connect(lanItem->infoLabel, &GrayInfoButton::clicked, this, [=]{ // open landetail page - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } qDebug() << "[NetConnect]call showPropertyWidget" << deviceName << connUuid << __LINE__; @@ -755,7 +745,6 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis }); lanItem->isAcitve = false; - lanItem->setConnectActionText(lanItem->isAcitve); connect(lanItem, &QPushButton::clicked, this, [=] { if (lanItem->isAcitve || lanItem->loading) { @@ -765,16 +754,6 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis } }); - connect(lanItem, &LanItem::connectActionTriggered, this, [=] { - activeConnect(lanItem->uuid, deviceName, WIRED_TYPE); - }); - connect(lanItem, &LanItem::disconnectActionTriggered, this, [=] { - deActiveConnect(lanItem->uuid, deviceName, WIRED_TYPE); - }); - connect(lanItem, &LanItem::deleteActionTriggered, this, [=] { - deleteOneLan(lanItem->uuid, WIRED_TYPE); - }); - //记录到deviceFrame的itemMap中 deviceFrameMap[deviceName]->itemMap.insert(connUuid, lanItem); int index = getInsertPos(connName, deviceName); @@ -889,9 +868,7 @@ void NetConnect::itemActiveConnectionStatusChanged(LanItem *item, int status) item->statusLabel->setMaximumSize(16777215,16777215); item->statusLabel->clear(); item->isAcitve = false; - item->statusLabel->setText(tr("not connected")); } - item->setConnectActionText(item->isAcitve); // QIcon searchIcon = QIcon::fromTheme(iconPath); // item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(24, 24)))); @@ -901,7 +878,7 @@ int NetConnect::getInsertPos(QString connName, QString deviceName) { qDebug() << "[NetConnect]getInsertPos" << connName << deviceName; int index = 0; - if(!m_interface->isValid()) { + if(m_interface == nullptr || !m_interface->isValid()) { index = 0; } else { qDebug() << "[NetConnect]call getWiredList" << __LINE__; @@ -932,19 +909,3 @@ int NetConnect::getInsertPos(QString connName, QString deviceName) } return index; } - -bool NetConnect::LaunchApp(QString desktopFile) -{ - QDBusInterface m_appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, - KYLIN_APP_MANAGER_PATH, - KYLIN_APP_MANAGER_INTERFACE, - QDBusConnection::sessionBus());//局部变量 - - if (!m_appManagerDbusInterface.isValid()) { - qWarning()<<"m_appManagerDbusInterface init error"; - return false; - } else { - QDBusReply reply =m_appManagerDbusInterface.call("LaunchApp",desktopFile); - return reply; - } -} diff --git a/plugins/netconnect/netconnect.h b/plugins/netconnect/netconnect.h index 99ce6855..f991540f 100644 --- a/plugins/netconnect/netconnect.h +++ b/plugins/netconnect/netconnect.h @@ -101,7 +101,7 @@ private: int getInsertPos(QString connName, QString deviceName); - void deleteOneLan(QString ssid, int type); + void deleteOneLan(QString ssid); void activeConnect(QString ssid, QString deviceName, int type); void deActiveConnect(QString ssid, QString deviceName, int type); @@ -123,7 +123,6 @@ private: //单个lan连接状态变化 void itemActiveConnectionStatusChanged(LanItem *item, int status); - bool LaunchApp(QString desktopFile); protected: bool eventFilter(QObject *w,QEvent *e); @@ -153,7 +152,6 @@ private slots: void onDeviceStatusChanged(); void onDeviceNameChanged(QString, QString, int); - }; Q_DECLARE_METATYPE(QList); diff --git a/plugins/netconnect/netconnect.pro b/plugins/netconnect/netconnect.pro index be66275c..500a3b7e 100644 --- a/plugins/netconnect/netconnect.pro +++ b/plugins/netconnect/netconnect.pro @@ -51,4 +51,5 @@ TRANSLATIONS += \ translations/zh_CN.ts \ translations/tr.ts \ translations/bo.ts \ - translations/bo_CN.ts + translations/bo_CN.ts \ + translations/en_US.ts diff --git a/plugins/netconnect/translations/bo.ts b/plugins/netconnect/translations/bo.ts index 16910853..dce9ee13 100644 --- a/plugins/netconnect/translations/bo.ts +++ b/plugins/netconnect/translations/bo.ts @@ -4,7 +4,12 @@ AddNetBtn - + + Add Others + + + + Add WiredNetork @@ -13,52 +18,52 @@ NetConnect - Wired Network - + open /netconnect/open - + Advanced settings /netconnect/Advanced settings" - + ukui control center - + ukui control center desktop message - - WiredConnect + + + LAN - + No ethernet device avaliable - - + + connected - + card diff --git a/plugins/netconnect/translations/bo_CN.qm b/plugins/netconnect/translations/bo_CN.qm index 22c45a00425af355193733d71d9b8f950e01f60b..f41e3534efdcb889e7081dd17f84ec6fa044b0d4 100644 GIT binary patch delta 164 zcmZ3$-Of2dBrbx1As~){f#EU(+l&?l2Bt^`_OyLK`WlmEu_yxrb3Lo~fh$0M7e|`? zXP~-b&Qf(&1_nk!uEPbZf%FQVHUepN9#8?QW8)Y4IUA^sA(MfDMRek`@<~hy zS~C1;{1f;~_yhU5`4jnTz;q!0CLk}2pO*uqnhl7VeH{HJJ2H!GPGCCDxH+B0k`VwC C>m&*Q delta 437 zcmZqYT);g+q`rcIZAJ?N1G5kVd)huAeV$480EpkuWLYfAz`#<$vPNeq0|Ub^R__B> zfa1=qdDA`v`3xLs_CT63i?dXn6-b}rO8jjCq|LZey`KQ3k8>R^Sk1t|l*sc&@)FP- zHr}HLRDk^b{6arx1LZ?985mgkm?MBp9sWT6P5j*aN&J)eHv(xV{y6?%ARP!~aq}kw zaU6dMkevo(@p1q)Ft7nJmt#tbf`3UyYEdyekjn|=`lXgQmEcAvyN&yv(!uwE(t2%z#nplu;QH*xca@yGMm zfN6wgHkZ_#)RI&Ty?j7-x&l>0baQja0}Y2b*Cn$!8PmdvPf|CxGahGDi~w4I%cZ<| M`6UXQ^_e3W0c$>4+yDRo diff --git a/plugins/netconnect/translations/bo_CN.ts b/plugins/netconnect/translations/bo_CN.ts index 897b2285..e31cef7e 100644 --- a/plugins/netconnect/translations/bo_CN.ts +++ b/plugins/netconnect/translations/bo_CN.ts @@ -4,41 +4,20 @@ AddNetBtn - + Add Others - དྲ་རྒྱ་གཞན་དག་ལ་ཞུགས་། + - + Add WiredNetork སྐུད་ཡོད་བརྙན་འཕྲིན་ཁ་སྣོན་བྱས་ཡོད། - - LanItem - - - Delete - མེད་པར་བཟོ་བ་ - - - - - Disconnect - གཅོད་པ་ - - - - - Connect - སྦྲེལ་བ་ - - NetConnect - Wired Network སྐུད་ཡོད་བརྙན་འཕྲིན་དྲ་བ། @@ -67,9 +46,14 @@ ukui ཚོད་འཛིན་ལྟེ་གནས་ཀྱི་ཅོག་ངོས་ཆ་འཕྲིན། - WiredConnect - སྐུད་ཡོད་སྦྲེལ་མཐུད། + སྐུད་ཡོད་སྦྲེལ་མཐུད། + + + + + LAN + སྐུད་ཡོད་དྲ་བ། @@ -77,21 +61,15 @@ ཨེ་ཙི་དྲ་རྒྱའི་སྒྲིག་ཆས་ལ་བཙན་འཛུལ་བྱས་མི་ཆོག། - - + + connected འབྲེལ་མཐུད་བྱེད་པ། - + card བྱང་བུ། - - - - not connected - མ་སྦྲེལ་བ་ - diff --git a/plugins/netconnect/translations/en_US.ts b/plugins/netconnect/translations/en_US.ts new file mode 100644 index 00000000..43e8a786 --- /dev/null +++ b/plugins/netconnect/translations/en_US.ts @@ -0,0 +1,71 @@ + + + + + AddNetBtn + + + Add Others + Add Others + + + + Add WiredNetork + Add WiredNetork + + + + NetConnect + + + Wired Network + Wired Network + + + + + open + open + /netconnect/open + + + + + Advanced settings + Advanced settings + /netconnect/Advanced settings" + + + + ukui control center + ukui control center + + + + ukui control center desktop message + ukui control center desktop message + + + + + LAN + LAN + + + + No ethernet device avaliable + No ethernet device avaliable + + + + + connected + connected + + + + card + card + + + diff --git a/plugins/netconnect/translations/tr.ts b/plugins/netconnect/translations/tr.ts index 16910853..dce9ee13 100644 --- a/plugins/netconnect/translations/tr.ts +++ b/plugins/netconnect/translations/tr.ts @@ -4,7 +4,12 @@ AddNetBtn - + + Add Others + + + + Add WiredNetork @@ -13,52 +18,52 @@ NetConnect - Wired Network - + open /netconnect/open - + Advanced settings /netconnect/Advanced settings" - + ukui control center - + ukui control center desktop message - - WiredConnect + + + LAN - + No ethernet device avaliable - - + + connected - + card diff --git a/plugins/netconnect/translations/zh_CN.qm b/plugins/netconnect/translations/zh_CN.qm index 93f01012ac811386415117a8204ddcc5caee79f8..f8fe4d7bbb6520cb61929cde1055dc42171c755b 100644 GIT binary patch delta 130 zcmbQmew=lJNL&O1LqHq@14AJL+l&?l21Z{7_OyLKdJ&Ulu_yxr6Emy#fh$0M2}hd! zXP`Pu&Qf(&AU&JwaKUOI{fy_0ual)&l^{`5_tr delta 351 zcmX@kI*WaRNPPtZ+l&?l2F7y?>}mTL7??ttbPoXeOv+4_#iBrZ8_OD4%9=OrGmy`~k!BB~pKz9{vjW9sxDtPx0QtMPQoWx5>0GYE1*?JL={#>FF9FS| z;XQgl1<0SxFZ6RZP~Ieyfq|KW*%-*=30e@C8dw(HTpw6>hXW|Uzy`!zjwvY${v{cy zMaAquE+>%dms;XflE*l)$hMxP|6cM^xLS7S{Jgx> AddNetBtn - + Add Others - 加入其它网络 + - + Add WiredNetork 添加有线网络 - - LanItem - - - Delete - 删除 - - - - - Disconnect - 断开 - - - - - Connect - 连接 - - NetConnect - Wired Network 有线网络 @@ -67,8 +46,13 @@ 控制面板桌面通知 - WiredConnect + 有线网络 + + + + + LAN 有线网络 @@ -77,21 +61,15 @@ 未检测到有线设备 - - + + connected 已连接 - + card 网卡 - - - - not connected - 未连接 - diff --git a/plugins/plugin.pro b/plugins/plugin.pro index 1ef03f43..cee11d57 100644 --- a/plugins/plugin.pro +++ b/plugins/plugin.pro @@ -3,5 +3,4 @@ SUBDIRS = \ netconnect \ wlanconnect \ mobilehotspot \ - proxy \ - vpn + proxy diff --git a/plugins/proxy/applistwidget.cpp b/plugins/proxy/applistwidget.cpp index c3c87109..dc2e5cd3 100644 --- a/plugins/proxy/applistwidget.cpp +++ b/plugins/proxy/applistwidget.cpp @@ -29,7 +29,7 @@ AppListWidget::AppListWidget(QString path, QWidget *parent) AppListWidget::~AppListWidget() { - + delete m_dbusInterface; } /** @@ -79,8 +79,9 @@ void AppListWidget::onAppCheckStateChanged() */ void AppListWidget::AddAppProxyConfig() { - if(!m_dbusInterface->isValid()) { + if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) { qWarning ()<< "init AppProxy dbus error"; + return; } qDebug() << "call QDBusInterface addAppIntoProxy"; @@ -93,8 +94,9 @@ void AppListWidget::AddAppProxyConfig() */ void AppListWidget::RemoveAppProxyConfig() { - if(!m_dbusInterface->isValid()) { + if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) { qWarning ()<< "init AppProxy dbus error"; + return; } qDebug() << "call QDBusInterface delAppIntoProxy"; @@ -116,7 +118,6 @@ void AppListWidget::initUI() mainLayout->setContentsMargins(17, 0, 17, 0); mainLayout->setSpacing(8); m_checkBox = new QCheckBox(this); - m_checkBox->setFixedSize(16, 16); m_checkBox->setAttribute(Qt::WA_TransparentForMouseEvents, true); //m_checkBox不响应鼠标事件,将其传递给父窗口 m_iconLabel = new QLabel(this); m_iconLabel->setFixedSize(24, 24); @@ -135,4 +136,7 @@ void AppListWidget::initDbus() "/org/ukui/SettingsDaemon/AppProxy", "org.ukui.SettingsDaemon.AppProxy", QDBusConnection::sessionBus()); + if(!m_dbusInterface->isValid()) { + qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); + } } diff --git a/plugins/proxy/aptproxydialog.cpp b/plugins/proxy/aptproxydialog.cpp index eb87e779..2c1cc21a 100644 --- a/plugins/proxy/aptproxydialog.cpp +++ b/plugins/proxy/aptproxydialog.cpp @@ -22,14 +22,14 @@ AptProxyDialog::~AptProxyDialog() void AptProxyDialog::initUi() { setWindowTitle(tr("Set Apt Proxy")); - this->setFixedSize(480, 204); + this->setFixedSize(480, 200); QVBoxLayout *mAptProxyLyt = new QVBoxLayout(this); mAptProxyLyt->setContentsMargins(24, 24, 24, 24); - mAptProxyLyt->setSpacing(8); + mAptProxyLyt->setSpacing(16); QFrame *mHostFrame = new QFrame(this); - mHostFrame->setFixedWidth(432); + mHostFrame->setFixedSize(432, 36); mHostFrame->setFrameShape(QFrame::NoFrame); QHBoxLayout *mLyt_1= new QHBoxLayout(mHostFrame); @@ -37,19 +37,19 @@ void AptProxyDialog::initUi() mLyt_1->setSpacing(8); FixLabel *mSetHostLabel = new FixLabel(mHostFrame); - mSetHostLabel->setFixedWidth(92); + mSetHostLabel->setFixedSize(92, 36); mSetHostLabel->setText(tr("Server Address")); mHostEdit = new QLineEdit(mHostFrame); mHostEdit->setAttribute(Qt::WA_InputMethodEnabled, false); //限制中文输入法 - mHostEdit->setFixedWidth(332); + mHostEdit->setFixedSize(332, 36); mHostEdit->installEventFilter(this); mLyt_1->addWidget(mSetHostLabel); mLyt_1->addWidget(mHostEdit); QFrame *mPortFrame = new QFrame(this); - mPortFrame->setFixedWidth(432); + mPortFrame->setFixedSize(432, 36); mPortFrame->setFrameShape(QFrame::NoFrame); QHBoxLayout *mLyt_2= new QHBoxLayout(mPortFrame); @@ -57,11 +57,11 @@ void AptProxyDialog::initUi() mLyt_2->setSpacing(8); QLabel *mSetPortLabel = new QLabel(tr("Port") ,mPortFrame); - mSetPortLabel->setFixedWidth(92); + mSetPortLabel->setFixedSize(92, 36); mPortEdit = new QLineEdit(mPortFrame); mPortEdit->setAttribute(Qt::WA_InputMethodEnabled, false); //限制中文输入法 - mPortEdit->setFixedWidth(332); + mPortEdit->setFixedSize(332, 36); mPortEdit->installEventFilter(this); mLyt_2->addWidget(mSetPortLabel); @@ -76,9 +76,11 @@ void AptProxyDialog::initUi() mLyt_3->setSpacing(16); mCancelBtn = new QPushButton(mChooseFrame); + mCancelBtn->setMinimumWidth(96); mCancelBtn->setText(tr("Cancel")); mConfirmBtn = new QPushButton(mChooseFrame); + mConfirmBtn->setMinimumWidth(96); mConfirmBtn->setText(tr("Confirm")); mLyt_3->addStretch(); @@ -87,7 +89,7 @@ void AptProxyDialog::initUi() mAptProxyLyt->addWidget(mHostFrame); mAptProxyLyt->addWidget(mPortFrame); - mAptProxyLyt->addStretch(); + mAptProxyLyt->addSpacing(16); mAptProxyLyt->addWidget(mChooseFrame); } diff --git a/plugins/proxy/proxy.cpp b/plugins/proxy/proxy.cpp index 6a009a3f..33032fd4 100644 --- a/plugins/proxy/proxy.cpp +++ b/plugins/proxy/proxy.cpp @@ -45,11 +45,11 @@ #define PROXY_HOST_KEY "host" #define PROXY_PORT_KEY "port" - +#define THEME_SCHAME "org.ukui.style" #define FRAME_LAYOUT_MARGINS 16,0,16,0 #define FRAME_LAYOUT_SPACING 8 #define LABEL_WIDTH 136 -#define IP_FRAME_MAX_HEIGHT 76 +#define LINE_EDIT_HEIGHT 36 Proxy::Proxy() : mFirstLoad(true) { @@ -67,7 +67,8 @@ Proxy::Proxy() : mFirstLoad(true) Proxy::~Proxy() { if (!mFirstLoad) { - plugin_leave(); + plugin_leave(); + delete m_appProxyDbus; } } @@ -162,6 +163,11 @@ QIcon Proxy::icon() const return QIcon::fromTheme("ukui-network-agent-symbolic"); } +QString Proxy::translationPath() const +{ + return "/usr/share/kylin-nm/proxy/%1.ts"; +} + bool Proxy::isEnable() const { return true; @@ -233,6 +239,7 @@ void Proxy::initUi(QWidget *widget) mUrlLabel->setFixedWidth(136); mUrlLineEdit = new QLineEdit(mUrlFrame); + mUrlLineEdit->setFixedHeight(36); mUrlLayout->addWidget(mUrlLabel); mUrlLayout->addWidget(mUrlLineEdit); @@ -254,6 +261,7 @@ void Proxy::initUi(QWidget *widget) mHTTPLineEdit_1 = new QLineEdit(mHTTPFrame); mHTTPLineEdit_1->resize(300, 36); mHTTPLineEdit_2 = new QLineEdit(mHTTPFrame); + mHTTPLineEdit_2->setFixedHeight(36); mHTTPLineEdit_2->setValidator(new QRegExpValidator(QRegExp("[0-9]*") , this)); mHTTPLayout_1->addWidget(mHTTPLabel); mHTTPLayout_1->addWidget(mHTTPLineEdit_1); @@ -276,6 +284,7 @@ void Proxy::initUi(QWidget *widget) mHTTPSLineEdit_1 = new QLineEdit(mHTTPSFrame); mHTTPSLineEdit_1->resize(300, 36); mHTTPSLineEdit_2 = new QLineEdit(mHTTPSFrame); + mHTTPSLineEdit_2->setFixedHeight(36); mHTTPSLineEdit_2->setValidator(new QRegExpValidator(QRegExp("[0-9]*") , this)); mHTTPSLayout->addWidget(mHTTPSLabel); mHTTPSLayout->addWidget(mHTTPSLineEdit_1); @@ -298,6 +307,7 @@ void Proxy::initUi(QWidget *widget) mFTPLineEdit_1 = new QLineEdit(mFTPFrame); mFTPLineEdit_1->resize(300, 36); mFTPLineEdit_2 = new QLineEdit(mFTPFrame); + mFTPLineEdit_2->setFixedHeight(36); mFTPLineEdit_2->setValidator(new QRegExpValidator(QRegExp("[0-9]*") , this)); mFTPLayout->addWidget(mFTPLabel); mFTPLayout->addWidget(mFTPLineEdit_1); @@ -320,6 +330,7 @@ void Proxy::initUi(QWidget *widget) mSOCKSLineEdit_1 = new QLineEdit(mSOCKSFrame); mSOCKSLineEdit_1->resize(300, 36); mSOCKSLineEdit_2 = new QLineEdit(mSOCKSFrame); + mSOCKSLineEdit_2->setFixedHeight(36); mSOCKSLineEdit_2->setValidator(new QRegExpValidator(QRegExp("[0-9]*") , this)); mSOCKSLayout->addWidget(mSOCKSLabel); mSOCKSLayout->addWidget(mSOCKSLineEdit_1); @@ -697,6 +708,9 @@ void Proxy::initDbus() "/org/ukui/SettingsDaemon/AppProxy", "org.ukui.SettingsDaemon.AppProxy", QDBusConnection::sessionBus()); + if(!m_appProxyDbus->isValid()) { + qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); + } } void Proxy::initAppProxyStatus() @@ -747,8 +761,11 @@ void Proxy::setAptProxy(QString host, QString port, bool status) "/", "com.control.center.interface", QDBusConnection::systemBus()); - if (mAptproxyDbus->isValid()) + if (mAptproxyDbus->isValid()) { QDBusReply reply = mAptproxyDbus->call("setaptproxy", host, port , status); + } + delete mAptproxyDbus; + mAptproxyDbus = nullptr; } QHash Proxy::getAptProxy() @@ -781,6 +798,8 @@ QHash Proxy::getAptProxy() mAptInfo.insert(it.arg, it.out.variant()); } } + delete mAptproxyDbus; + mAptproxyDbus = nullptr; return mAptInfo; } @@ -809,8 +828,9 @@ void Proxy::reboot() "/org/gnome/SessionManager", "org.gnome.SessionManager", QDBusConnection::sessionBus()); - - rebootDbus->call("reboot"); + if (rebootDbus->isValid()) { + rebootDbus->call("reboot"); + } delete rebootDbus; rebootDbus = nullptr; } @@ -836,8 +856,9 @@ QFrame *Proxy::setLine(QFrame *frame) bool Proxy::getAppProxyState() { bool state = true; - if(!m_appProxyDbus->isValid()) { + if(m_appProxyDbus == nullptr || !m_appProxyDbus->isValid()) { qWarning ()<< "init AppProxy dbus error"; + return false; } //获取应用代理开启状态 @@ -854,7 +875,7 @@ bool Proxy::getAppProxyState() void Proxy::setAppProxyState(bool state) { - if(!m_appProxyDbus->isValid()) { + if(m_appProxyDbus == nullptr || !m_appProxyDbus->isValid()) { qWarning ()<< "init AppProxy dbus error"; return; } @@ -876,6 +897,7 @@ QStringList Proxy::getAppProxyConf() if(!dbusInterface.isValid()) { qWarning ()<< "init AppProxy dbus error"; + return info; } //获取应用代理配置信息 @@ -898,11 +920,12 @@ QStringList Proxy::getAppProxyConf() void Proxy::setAppProxyConf(QStringList list) { + //AppProxyConf 必填项数量为3 if (list.count() < 3) { return; } - if(!m_appProxyDbus->isValid()) { + if(m_appProxyDbus == nullptr || !m_appProxyDbus->isValid()) { qWarning ()<< "init AppProxy dbus error"; return; } @@ -1003,23 +1026,27 @@ void Proxy::setAppProxyFrameUi(QWidget *widget) //IP地址ui布局 m_ipAddressFrame = new QFrame(m_appProxyFrame); m_ipAddressFrame->setMinimumSize(QSize(550, 60)); - m_ipAddressFrame->setMaximumSize(QSize(16777215, IP_FRAME_MAX_HEIGHT)); + m_ipAddressFrame->setMaximumSize(QSize(16777215, 88)); m_ipAddressFrame->setFrameShape(QFrame::NoFrame); m_ipAddressLabel = new QLabel(tr("IP address"), m_ipAddressFrame); m_ipAddressLabel->setFixedWidth(LABEL_WIDTH); m_ipHintsLabel = new QLabel(m_ipAddressFrame); - m_ipHintsLabel->setFixedHeight(20); m_ipHintsLabel->setContentsMargins(8, 0, 0, 0); m_ipAddressLineEdit = new QLineEdit(m_ipAddressFrame); - m_ipAddressLineEdit->setMinimumHeight(36); + m_ipAddressLineEdit->setFixedHeight(LINE_EDIT_HEIGHT); m_ipAddressLineEdit->setPlaceholderText(tr("Required")); //必填 - QGridLayout *ipAddressLayout = new QGridLayout(m_ipAddressFrame); - ipAddressLayout->setContentsMargins(16, 0, 16, 0); - ipAddressLayout->setVerticalSpacing(0); - ipAddressLayout->addWidget(m_ipAddressLabel, 0, 0); - ipAddressLayout->addWidget(m_ipAddressLineEdit, 0, 1); - ipAddressLayout->addWidget(m_ipHintsLabel, 1, 1); + QWidget *ipInputWidget = new QWidget(m_ipAddressFrame); + QVBoxLayout *ipVLayout = new QVBoxLayout(ipInputWidget); + ipVLayout->setContentsMargins(0, 0, 0, 0); + ipVLayout->setSpacing(3); + ipVLayout->addWidget(m_ipAddressLineEdit); + ipVLayout->addWidget(m_ipHintsLabel); + + QFormLayout *ipAddressLayout = new QFormLayout(m_ipAddressFrame); + ipAddressLayout->setContentsMargins(16, 12, 16, 12); + ipAddressLayout->setSpacing(FRAME_LAYOUT_SPACING); + ipAddressLayout->addRow(m_ipAddressLabel, ipInputWidget); // IP的正则格式限制 QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); @@ -1151,18 +1178,22 @@ void Proxy::setAppListFrameUi(QWidget *widget) m_allowAppProxyLabel->setText(tr("The following applications are allowed to use this configuration:")); //允许以下应用使用该配置: m_appListWidget = new QListWidget(m_appListFrame); m_appListWidget->setMinimumHeight(240); - m_appListWidget->setBackgroundRole(QPalette::Base); m_appListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus); m_appListWidget->setFrameShape(QFrame::Shape::Panel); appListLayout->addWidget(m_allowAppProxyLabel); appListLayout->addWidget(m_appListWidget); - QPalette mpal(m_appListWidget->palette()); - mpal.setColor(QPalette::Base, qApp->palette().base().color()); - mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color()); - m_appListWidget->setAlternatingRowColors(true); - m_appListWidget->setPalette(mpal); + onPaletteChanged(); + const QByteArray style_id(THEME_SCHAME); + if (QGSettings::isSchemaInstalled(style_id)) { + QGSettings * styleGsettings = new QGSettings(style_id, QByteArray(), this); + connect(styleGsettings, &QGSettings::changed, this, [=](QString key){ + if ("styleName" == key) { + onPaletteChanged(); + } + }); + } } void Proxy::appProxyInfoPadding() @@ -1219,7 +1250,7 @@ bool Proxy::getipEditState(QString text) void Proxy::onipEditStateChanged() { if (!getipEditState(m_ipAddressLineEdit->text())) { - m_ipAddressFrame->setFixedHeight(IP_FRAME_MAX_HEIGHT); + m_ipAddressFrame->setFixedHeight(88); m_ipHintsLabel->show(); } else { m_ipHintsLabel->hide(); @@ -1231,7 +1262,6 @@ void Proxy::onAppProxyConfChanged() { if (!getipEditState(m_ipAddressLineEdit->text()) || m_portLineEdit->text().isEmpty()) { return; - qDebug() << "onAppProxyConfChanged return"; } if (m_ipAddressLineEdit->text().isEmpty()) { @@ -1248,8 +1278,6 @@ void Proxy::onAppProxyConfChanged() m_appProxyInfo.append(""); m_appProxyInfo.append(""); } - - qDebug() << m_appProxyInfo << Q_FUNC_INFO << __LINE__; } } @@ -1260,6 +1288,16 @@ void Proxy::onAppProxyConfEditFinished() } } +void Proxy::onPaletteChanged() +{ + QPalette mpal(m_appListWidget->palette()); + mpal.setColor(QPalette::Base, qApp->palette().base().color()); + mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color()); + m_appListWidget->setBackgroundRole(QPalette::Base); + m_appListWidget->setAlternatingRowColors(true); + m_appListWidget->setPalette(mpal); +} + void Proxy::onappProxyEnableChanged(bool enable) { m_proxyTypeFrame->setVisible(enable); diff --git a/plugins/proxy/proxy.h b/plugins/proxy/proxy.h index 48d9cc30..6d690847 100644 --- a/plugins/proxy/proxy.h +++ b/plugins/proxy/proxy.h @@ -103,6 +103,7 @@ public: bool isShowOnHomePage() const Q_DECL_OVERRIDE; QIcon icon() const Q_DECL_OVERRIDE; bool isEnable() const Q_DECL_OVERRIDE; + QString translationPath() const Q_DECL_OVERRIDE; public: void initUi(QWidget *widget); @@ -262,8 +263,8 @@ private: QFileSystemWatcher *mfileWatch_1; QFileSystemWatcher *mfileWatch_2; - QDBusInterface *mAptproxyDbus; - QDBusInterface *m_appProxyDbus; +// QDBusInterface *mAptproxyDbus; + QDBusInterface *m_appProxyDbus = nullptr; bool isExistSettings = false; bool settingsCreate; @@ -277,6 +278,7 @@ private slots: void onipEditStateChanged(); //IP地址无效提示 void onAppProxyConfChanged(); //应用代理配置信息变化 void onAppProxyConfEditFinished(); + void onPaletteChanged(); // void onCancelBtnClicked(); // void onSaveBtnClicked(); // void setBtnEnable(); diff --git a/plugins/wlanconnect/translations/bo.ts b/plugins/wlanconnect/translations/bo.ts index f8fab3a1..c678f22f 100644 --- a/plugins/wlanconnect/translations/bo.ts +++ b/plugins/wlanconnect/translations/bo.ts @@ -4,12 +4,12 @@ AddNetBtn - + Add Others - + Add WiredNetork @@ -18,12 +18,12 @@ WlanConnect - WlanConnect + WLAN @@ -58,14 +58,14 @@ - - - + + + connected - + card diff --git a/plugins/wlanconnect/translations/bo_CN.ts b/plugins/wlanconnect/translations/bo_CN.ts index 0d7ff07a..47de7db1 100644 --- a/plugins/wlanconnect/translations/bo_CN.ts +++ b/plugins/wlanconnect/translations/bo_CN.ts @@ -4,12 +4,12 @@ AddNetBtn - + Add Others དྲ་རྒྱ་གཞན་དག་ནང་ཞུགས་དགོས། - + Add WiredNetork @@ -18,12 +18,12 @@ WlanConnect - WlanConnect ཝུའུ་ལན་འབྲེལ་མཐུད། + WLAN སྐུད་མེད་ཅུས་ཁོངས་ཀྱི་དྲ་བ། @@ -58,14 +58,14 @@ སྐུད་མེད་དྲ་རྒྱའི་བྱང་བུ་མ་རྙེད་པ། - - - + + + connected འབྲེལ་མཐུད་བྱེད་པ། - + card བྱང་བུ། diff --git a/plugins/wlanconnect/translations/en_US.ts b/plugins/wlanconnect/translations/en_US.ts new file mode 100644 index 00000000..801e684f --- /dev/null +++ b/plugins/wlanconnect/translations/en_US.ts @@ -0,0 +1,73 @@ + + + + + AddNetBtn + + + Add Others + Add Others + + + + Add WiredNetork + Add WiredNetork + + + + WlanConnect + + + WlanConnect + WlanConnect + + + + + + WLAN + WLAN + + + + + open + open + /wlanconnect/open + + + + + Advanced settings + Advanced settings + /wlanconnect/Advanced settings" + + + + ukui control center + ukui control center + + + + ukui control center desktop message + ukui control center desktop message + + + + No wireless network card detected + No wireless network card detected + + + + + + connected + connected + + + + card + card + + + diff --git a/plugins/wlanconnect/translations/tr.ts b/plugins/wlanconnect/translations/tr.ts index f8fab3a1..c678f22f 100644 --- a/plugins/wlanconnect/translations/tr.ts +++ b/plugins/wlanconnect/translations/tr.ts @@ -4,12 +4,12 @@ AddNetBtn - + Add Others - + Add WiredNetork @@ -18,12 +18,12 @@ WlanConnect - WlanConnect + WLAN @@ -58,14 +58,14 @@ - - - + + + connected - + card diff --git a/plugins/wlanconnect/translations/zh_CN.ts b/plugins/wlanconnect/translations/zh_CN.ts index a62ddac2..216d188b 100644 --- a/plugins/wlanconnect/translations/zh_CN.ts +++ b/plugins/wlanconnect/translations/zh_CN.ts @@ -4,12 +4,12 @@ AddNetBtn - + Add Others 加入其它网络 - + Add WiredNetork @@ -18,12 +18,12 @@ WlanConnect - WlanConnect 无线局域网 + WLAN 无线局域网 @@ -58,14 +58,14 @@ 未检测到无线网卡 - - - + + + connected 已连接 - + card 网卡 diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp index bfbc6dd0..0e2402c5 100644 --- a/plugins/wlanconnect/wlanconnect.cpp +++ b/plugins/wlanconnect/wlanconnect.cpp @@ -99,9 +99,6 @@ const QString KApSymbolic = "network-wireless-hotspot-symbolic"; const QString IsApConnection = "1"; -#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" -#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" -#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" #define ACTIVATING 1 #define ACTIVATED 2 @@ -140,7 +137,7 @@ WlanConnect::WlanConnect() : m_firstLoad(true) { translator->load("/usr/share/kylin-nm/wlanconnect/" + QLocale::system().name()); QApplication::installTranslator(translator); - pluginName = tr("WlanConnect"); + pluginName = tr("WLAN"); pluginType = NETWORK; } @@ -230,7 +227,9 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) { if (!getSwitchBtnEnable()) { showDesktopNotify(tr("No wireless network card detected")); } else { - m_interface->call(QStringLiteral("setWirelessSwitchEnable"), !getSwitchBtnState()); + if (m_interface != nullptr && m_interface->isValid()) { + m_interface->call(QStringLiteral("setWirelessSwitchEnable"), !getSwitchBtnState()); + } return true; } } @@ -301,7 +300,7 @@ void WlanConnect::initComponent() { void WlanConnect::reScan() { qDebug() << "time to rescan wifi"; - if (m_interface->isValid()) { + if (m_interface != nullptr && m_interface->isValid()) { qDebug() << "[WlanConnect]call reScan" << __LINE__; m_interface->call("reScan"); qDebug() << "[WlanConnect]call reScan respond" << __LINE__; @@ -315,7 +314,7 @@ void WlanConnect::updateList() return; } qDebug() << "update list"; - if(m_interface->isValid()) { + if(m_interface != nullptr && m_interface->isValid()) { qDebug() << "[WlanConnect]call getWirelessList" << __LINE__; QDBusMessage result = m_interface->call(QStringLiteral("getWirelessList")); qDebug() << "[WlanConnect]call getWirelessList respond" << __LINE__; @@ -429,9 +428,9 @@ void WlanConnect::updateIcon(WlanItem *item, QString signalStrength, QString sec iconamePath = wifiIcon(isLock, sign, category); } QIcon searchIcon = QIcon::fromTheme(iconamePath); - if (iconamePath != KLanSymbolic && iconamePath != NoNetSymbolic) { - item->iconLabel->setProperty("useIconHighlightEffect", 0x10); - } +// if (iconamePath != KLanSymbolic && iconamePath != NoNetSymbolic) { +// item->iconLabel->setProperty("useIconHighlightEffect", 0x10); +// } item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE)))); qDebug() << "updateIcon" << item->titileLabel->text() << " finish"; } @@ -522,6 +521,12 @@ void WlanConnect::onDeviceStatusChanged() setSwitchBtnEnable(true); initSwtichState(); } + + if (!getSwitchBtnState()) { + hideLayout(ui->availableLayout); + } else { + showLayout(ui->availableLayout); + } } void WlanConnect::onDeviceNameChanged(QString oldName, QString newName, int type) @@ -554,7 +559,7 @@ void WlanConnect::onSwitchBtnChanged(bool state) if (getSwitchBtnState() == state) { return; } - + setSwitchBtnEnable(true); setSwitchBtnState(state); if (!getSwitchBtnState()) { hideLayout(ui->availableLayout); @@ -681,7 +686,7 @@ void WlanConnect::onNetworkRemove(QString deviceName, QString wlannName) //获取设备列表======================================================= void WlanConnect::getDeviceList(QStringList &list) { - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } qDebug() << "[WlanConnect]call getDeviceListAndEnabled" << __LINE__; @@ -700,7 +705,7 @@ void WlanConnect::getDeviceList(QStringList &list) void WlanConnect::initSwtichState() { - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } @@ -713,25 +718,10 @@ void WlanConnect::initSwtichState() } bool state = result.arguments().at(0).toBool(); + setSwitchBtnEnable(true); setSwitchBtnState(state); } -bool WlanConnect::LaunchApp(QString desktopFile) -{ - QDBusInterface m_appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, - KYLIN_APP_MANAGER_PATH, - KYLIN_APP_MANAGER_INTERFACE, - QDBusConnection::sessionBus());//局部变量 - - if (!m_appManagerDbusInterface.isValid()) { - qWarning()<<"m_appManagerDbusInterface init error"; - return false; - } else { - QDBusReply reply =m_appManagerDbusInterface.call("LaunchApp",desktopFile); - return reply; - } -} - //初始化整体列表和单设备列表 void WlanConnect::initNet() { // int count = 1; @@ -757,7 +747,7 @@ void WlanConnect::initNetListFromDevice(QString deviceName) qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName << " not exist"; return; } - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } qDebug() << "[WlanConnect]call getWirelessList" << __LINE__; @@ -795,10 +785,9 @@ void WlanConnect::initNetListFromDevice(QString deviceName) //高级设置 void WlanConnect::runExternalApp() { -// QString cmd = "nm-connection-editor"; -// QProcess process(this); -// process.startDetached(cmd); - LaunchApp("nm-connection-editor.desktop"); + QString cmd = "nm-connection-editor"; + QProcess process(this); + process.startDetached(cmd); } //根据信号强度分级+安全性分图标 @@ -891,6 +880,9 @@ void WlanConnect::showLayout(QVBoxLayout * layout) { //获取应该插入哪个位置 int WlanConnect::sortWlanNet(QString deviceName, QString name, QString signal) { + if (m_interface == nullptr || !m_interface->isValid()) { + return 0; + } qDebug() << "[WlanConnect]call getWirelessList" << __LINE__; QDBusMessage result = m_interface->call(QStringLiteral("getWirelessList")); qDebug() << "[WlanConnect]call getWirelessList respond" << __LINE__; @@ -917,7 +909,7 @@ int WlanConnect::sortWlanNet(QString deviceName, QString name, QString signal) } void WlanConnect::activeConnect(QString netName, QString deviceName, int type) { - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } qDebug() << "[WlanConnect]call activateConnect" << __LINE__; @@ -926,7 +918,7 @@ void WlanConnect::activeConnect(QString netName, QString deviceName, int type) { } void WlanConnect::deActiveConnect(QString netName, QString deviceName, int type) { - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } qDebug() << "[WlanConnect]call deActivateConnect" << __LINE__; @@ -979,7 +971,7 @@ void WlanConnect::addDeviceFrame(QString devName) deviceFrameMap.insert(devName, itemFrame); connect(itemFrame->addWlanWidget, &AddNetBtn::clicked, this, [=](){ - if (m_interface->isValid()) { + if (m_interface != nullptr && m_interface->isValid()) { qDebug() << "[NetConnect]call showAddOtherWlanWidget" << devName << __LINE__; m_interface->call(QStringLiteral("showAddOtherWlanWidget"), devName); qDebug() << "[NetConnect]call setDeviceEnable Respond" << __LINE__; @@ -1031,9 +1023,9 @@ void WlanConnect::addOneWlanFrame(ItemFrame *frame, QString deviceName, QString } else { iconamePath = wifiIcon(isLock, sign, category); } - if (iconamePath != KLanSymbolic && iconamePath != NoNetSymbolic) { - wlanItem->iconLabel->setProperty("useIconHighlightEffect", 0x10); - } +// if (iconamePath != KLanSymbolic && iconamePath != NoNetSymbolic) { +// wlanItem->iconLabel->setProperty("useIconHighlightEffect", 0x10); +// } QIcon searchIcon = QIcon::fromTheme(iconamePath); wlanItem->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE)))); wlanItem->titileLabel->setText(name); @@ -1047,7 +1039,7 @@ void WlanConnect::addOneWlanFrame(ItemFrame *frame, QString deviceName, QString connect(wlanItem->infoLabel, &GrayInfoButton::clicked, this, [=]{ // open detail page - if (!m_interface->isValid()) { + if (m_interface == nullptr || !m_interface->isValid()) { return; } qDebug() << "[WlanConnect]call showPropertyWidget" << __LINE__; diff --git a/plugins/wlanconnect/wlanconnect.h b/plugins/wlanconnect/wlanconnect.h index 45983aeb..38bff337 100644 --- a/plugins/wlanconnect/wlanconnect.h +++ b/plugins/wlanconnect/wlanconnect.h @@ -127,12 +127,12 @@ private: void initSwtichState(); inline void setSwitchBtnEnable(bool state) { if (m_wifiSwitch != nullptr) { - m_wifiSwitch->setCheckable(state); + m_wifiSwitch->setEnabled(state); } } inline bool getSwitchBtnEnable() { if (m_wifiSwitch != nullptr) { - return m_wifiSwitch->isCheckable(); + return m_wifiSwitch->isEnabled(); } } @@ -149,7 +149,6 @@ private: } } - bool LaunchApp(QString desktopFile); protected: bool eventFilter(QObject *w,QEvent *e); diff --git a/plugins/wlanconnect/wlanconnect.pro b/plugins/wlanconnect/wlanconnect.pro index 0864f9f6..d558656a 100644 --- a/plugins/wlanconnect/wlanconnect.pro +++ b/plugins/wlanconnect/wlanconnect.pro @@ -51,4 +51,5 @@ TRANSLATIONS += \ translations/zh_CN.ts \ translations/tr.ts \ translations/bo.ts \ - translations/bo_CN.ts + translations/bo_CN.ts \ + translations/en_US.ts diff --git a/plugins/wlanconnect/wlanconnect.ui b/plugins/wlanconnect/wlanconnect.ui index 99b9e7c2..fa8cfe41 100644 --- a/plugins/wlanconnect/wlanconnect.ui +++ b/plugins/wlanconnect/wlanconnect.ui @@ -184,7 +184,7 @@ TitleLabel QLabel -
titlelabel.h
+
titlelabel.h
diff --git a/plugins/wlanconnect/wlanitem.cpp b/plugins/wlanconnect/wlanitem.cpp index 01d8b269..539e454c 100644 --- a/plugins/wlanconnect/wlanitem.cpp +++ b/plugins/wlanconnect/wlanitem.cpp @@ -19,6 +19,7 @@ */ #include "wlanitem.h" #include +#include #define FRAME_SPEED 150 #define LIMIT_TIME 60*1000 #define TOTAL_PAGE 8 @@ -33,17 +34,15 @@ WlanItem::WlanItem(bool bAcitve, bool isLock, QWidget *parent) this->setMinimumSize(550, 58); this->setProperty("useButtonPalette", true); this->setFlat(true); - QPalette pal = this->palette(); - QColor color = pal.color(QPalette::Button); - color.setAlphaF(0.5); - pal.setColor(QPalette::Button, color); - this->setPalette(pal); + QHBoxLayout *mLanLyt = new QHBoxLayout(this); mLanLyt->setContentsMargins(16,0,16,0); mLanLyt->setSpacing(16); iconLabel = new QLabel(this); + iconLabel->setProperty("useIconHighlightEffect", 0x2); titileLabel = new FixLabel(this); statusLabel = new QLabel(this); + statusLabel->setProperty("useIconHighlightEffect", 0x2); statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // statusLabel->setMinimumSize(36,36); infoLabel = new GrayInfoButton(this); @@ -63,7 +62,6 @@ WlanItem::WlanItem(bool bAcitve, bool isLock, QWidget *parent) waitTimer = new QTimer(this); connect(waitTimer, &QTimer::timeout, this, &WlanItem::updateIcon); - } WlanItem::~WlanItem() @@ -93,12 +91,17 @@ void WlanItem::stopLoading(){ void WlanItem::paintEvent(QPaintEvent *event) { - QPalette pal = this->palette(); + QPalette pal = qApp->palette(); QPainter painter(this); painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿 painter.setPen(Qt::NoPen); - painter.setBrush(pal.color(QPalette::Base)); + painter.setBrush(this->palette().base().color()); + + QColor color = pal.color(QPalette::Button); + color.setAlphaF(0.5); + pal.setColor(QPalette::Button, color); + this->setPalette(pal); QRect rect = this->rect(); diff --git a/src/backend/backend.pri b/src/backend/backend.pri index 10314e58..feb4853f 100644 --- a/src/backend/backend.pri +++ b/src/backend/backend.pri @@ -4,7 +4,6 @@ include(dbus-interface/dbus-interface.pri) HEADERS += \ $$PWD/dbusadaptor.h \ - $$PWD/vpndbusadaptor.h \ $$PWD/kylinarping.h \ $$PWD/kylinipv4arping.h \ $$PWD/kylinipv6arping.h \ @@ -14,7 +13,6 @@ HEADERS += \ SOURCES += \ $$PWD/dbusadaptor.cpp \ - $$PWD/vpndbusadaptor.cpp \ $$PWD/kylinipv4arping.cpp \ $$PWD/kylinipv6arping.cpp \ $$PWD/sysdbusregister.cpp \ diff --git a/src/backend/dbus-interface/kylinactiveconnectresource.cpp b/src/backend/dbus-interface/kylinactiveconnectresource.cpp index 0a613f75..07b13d09 100644 --- a/src/backend/dbus-interface/kylinactiveconnectresource.cpp +++ b/src/backend/dbus-interface/kylinactiveconnectresource.cpp @@ -747,3 +747,35 @@ QString KyActiveConnectResourse::getAcitveConnectionPathByUuid(QString connectUu return activeAonnectPtr->path(); } + +int KyActiveConnectResourse::getAcivateWifiSignal() +{ + int signalStrength = 0; + KyNetworkDeviceResourse devResource; + QStringList devList; + devResource.getNetworkDeviceList(NetworkManager::Device::Type::Wifi, devList); + + for (int i = 0; i < devList.size(); ++i) { + + NetworkManager::Device::Ptr connectDevice = + m_networkResourceInstance->findDeviceInterface(devList.at(i)); + + if (nullptr == connectDevice || !connectDevice->isValid()) { + qWarning()<< LOG_FLAG <<"getDeviceActiveAPInfo failed, the device" << devList.at(i) << "is not existed"; + continue; + } + + if (connectDevice->type() == NetworkManager::Device::Wifi) { + NetworkManager::WirelessDevice *wirelessDevicePtr = + qobject_cast(connectDevice.data()); + NetworkManager::AccessPoint::Ptr apPtr = wirelessDevicePtr->activeAccessPoint(); + if (apPtr.isNull()) { + continue; + } + signalStrength = apPtr->signalStrength(); + break; + } + } + + return signalStrength; +} diff --git a/src/backend/dbus-interface/kylinactiveconnectresource.h b/src/backend/dbus-interface/kylinactiveconnectresource.h index d38196a9..6c648fa6 100644 --- a/src/backend/dbus-interface/kylinactiveconnectresource.h +++ b/src/backend/dbus-interface/kylinactiveconnectresource.h @@ -60,6 +60,7 @@ public: bool wiredConnectIsActived(); bool checkWirelessStatus(NetworkManager::ActiveConnection::State state); QString getAcitveConnectionPathByUuid(QString uuid); + int getAcivateWifiSignal(); private: void getActiveConnectIp(NetworkManager::ActiveConnection::Ptr activeConnectPtr, diff --git a/src/backend/dbus-interface/kylinagentinterface.c b/src/backend/dbus-interface/kylinagentinterface.c index d8c21c0b..35a7d41a 100644 --- a/src/backend/dbus-interface/kylinagentinterface.c +++ b/src/backend/dbus-interface/kylinagentinterface.c @@ -212,6 +212,14 @@ wifi_get_secrets (SecretsRequest *req, GError **error) g_return_val_if_fail (!info->dialog, FALSE); +#if GTK_CHECK_VERSION(3,90,0) + gtk_init (); +#else + int argc = 0; + char ***argv = NULL; + gtk_init (&argc, &argv); +#endif + NMClient *nm_client = nm_client_new (NULL, NULL); if (!nm_client) { g_set_error (error, @@ -401,14 +409,6 @@ void agent_init() GError *error = NULL; kylinAgent = applet_agent_new (&error); -#if GTK_CHECK_VERSION(3,90,0) - gtk_init (); -#else - int argc = 0; - char ***argv = NULL; - gtk_init (&argc, &argv); -#endif - g_signal_connect (kylinAgent, APPLET_AGENT_GET_SECRETS, G_CALLBACK (applet_agent_get_secrets_cb), NULL); g_signal_connect (kylinAgent, APPLET_AGENT_CANCEL_SECRETS, diff --git a/src/backend/dbus-interface/kylinconnectresource.cpp b/src/backend/dbus-interface/kylinconnectresource.cpp index dfdfb1cb..7de89382 100644 --- a/src/backend/dbus-interface/kylinconnectresource.cpp +++ b/src/backend/dbus-interface/kylinconnectresource.cpp @@ -42,36 +42,11 @@ static bool subLanListSort(const KyConnectItem* info1, const KyConnectItem* info return result; } -static bool subVpnListSort(const KyConnectItem* info1, const KyConnectItem* info2) -{ - if (info1->m_connectState != info2->m_connectState) { - if (info1->m_connectState == 2) { - return true; - } - - if (info2->m_connectState == 2) { - return false; - } - } - QString name1 = info1->m_connectName; - QString name2 = info2->m_connectName; - bool result = true; - if (QString::compare(name1, name2, Qt::CaseInsensitive) > 0) { - result = false; - } - return result; -} - static void lanListSort(QList &list) { qSort(list.begin(), list.end(), subLanListSort); } -static void vpnListSort(QList &list) -{ - qSort(list.begin(), list.end(), subVpnListSort); -} - KyConnectResourse::KyConnectResourse(QObject *parent) : QObject(parent) { m_networkResourceInstance = KyNetworkResourceManager::getInstance(); @@ -225,61 +200,6 @@ KyConnectItem * KyConnectResourse::getConnectionItemByUuid(QString connectUuid, return nullptr; } -void KyConnectResourse::getVpnAndVirtualConnections(QList &connectItemList) -{ - int index = 0; - NetworkManager::Connection::List connectList; - - qDebug()<<"[KyConnectResourse]"<<"get vpn && virtual connections"; - - connectList.clear(); - connectList = m_networkResourceInstance->getConnectList(); - - if (connectList.empty()) { - qWarning()<<"[KyConnectResourse]"<<"get vpn connections failed, the connect list is empty"; - return; - } - - NetworkManager::Connection::Ptr connectPtr = nullptr; - for (index = 0; index < connectList.size(); index++) { - connectPtr = connectList.at(index); - if (connectPtr.isNull()) { - continue; - } - if (NetworkManager::ConnectionSettings::ConnectionType::Vpn != connectPtr->settings()->connectionType() - && NetworkManager::ConnectionSettings::ConnectionType::Bond != connectPtr->settings()->connectionType() - && NetworkManager::ConnectionSettings::ConnectionType::Bridge != connectPtr->settings()->connectionType() - && NetworkManager::ConnectionSettings::ConnectionType::Vlan != connectPtr->settings()->connectionType() - && NetworkManager::ConnectionSettings::ConnectionType::Team != connectPtr->settings()->connectionType() - && NetworkManager::ConnectionSettings::ConnectionType::IpTunnel != connectPtr->settings()->connectionType() - && NetworkManager::ConnectionSettings::ConnectionType::Wired != connectPtr->settings()->connectionType()) { - continue; - } - NetworkManager::Device::Ptr devicePtr = nullptr; - devicePtr = m_networkResourceInstance->findDeviceInterface(connectPtr->settings()->interfaceName()); - if (NetworkManager::ConnectionSettings::ConnectionType::Wired == connectPtr->settings()->connectionType()) { - if (devicePtr == nullptr || !devicePtr->udi().startsWith("/sys/devices/virtual/net")) { - continue; - } - } - QString devName = ""; - if (!devicePtr.isNull()) { - devName = devicePtr->interfaceName(); - } - - KyConnectItem *connectItem = getConnectionItem(connectPtr, devName); - if (nullptr != connectItem) { - connectItemList << connectItem; - } - - connectPtr = nullptr; - } - - if (connectItemList.size() > 1) { - vpnListSort(connectItemList); - } -} - void KyConnectResourse::getConnectionList(QString deviceName, NetworkManager::ConnectionSettings::ConnectionType connectionType, QList &connectItemList) @@ -721,11 +641,13 @@ KyApConnectItem *KyConnectResourse::getApConnectItem(NetworkManager::Connection: return nullptr; } +#ifdef CHECKDEVICE KyNetworkDeviceResourse deviceResource; if (!deviceResource.wirelessDeviceIsExist(settingPtr->interfaceName())) { qDebug() << "[KyConnectResourse]" <<"get ap item failed, the ap device is not exist yet"; return nullptr; } +#endif QByteArray rawSsid = wirelessSetting->ssid(); @@ -824,35 +746,6 @@ void KyConnectResourse::getApConnections(QList &apConnectItem return; } -bool KyConnectResourse::isVirtualConncection(QString uuid) -{ - NetworkManager::Connection::Ptr connectPtr = nullptr; - - connectPtr = m_networkResourceInstance->getConnect(uuid); - if (nullptr == connectPtr) { - return false; - } - - if (NetworkManager::ConnectionSettings::ConnectionType::Vpn == connectPtr->settings()->connectionType() - ||NetworkManager::ConnectionSettings::ConnectionType::Bond == connectPtr->settings()->connectionType() - ||NetworkManager::ConnectionSettings::ConnectionType::Bridge == connectPtr->settings()->connectionType() - ||NetworkManager::ConnectionSettings::ConnectionType::Vlan == connectPtr->settings()->connectionType() - ||NetworkManager::ConnectionSettings::ConnectionType::Team == connectPtr->settings()->connectionType() - ||NetworkManager::ConnectionSettings::ConnectionType::IpTunnel == connectPtr->settings()->connectionType()) { - return true; - } - - NetworkManager::Device::Ptr devicePtr = nullptr; - devicePtr = m_networkResourceInstance->findDeviceInterface(connectPtr->settings()->interfaceName()); - if (devicePtr.isNull()) { - return false; - } - if (devicePtr->udi().startsWith("/sys/devices/virtual/net")) { - return true; - } - - return false; -} bool KyConnectResourse::isWiredConnection(QString uuid) { diff --git a/src/backend/dbus-interface/kylinconnectresource.h b/src/backend/dbus-interface/kylinconnectresource.h index 8c1228a2..9b334d34 100644 --- a/src/backend/dbus-interface/kylinconnectresource.h +++ b/src/backend/dbus-interface/kylinconnectresource.h @@ -40,7 +40,6 @@ public: KyConnectItem *getConnectionItemByUuid(QString connectUuid); KyConnectItem *getConnectionItemByUuidWithoutActivateChecking(QString connectUuid); KyConnectItem *getConnectionItemByUuid(QString connectUuid, QString deviceName); - void getVpnAndVirtualConnections(QList &connectItemList); void getConnectionList(QString deviceName, NetworkManager::ConnectionSettings::ConnectionType connectionType, QList &connectItemList); @@ -56,7 +55,6 @@ public: bool getInterfaceByUuid(QString &deviceName, const QString connUuid); void getConnectivity(NetworkManager::Connectivity &connectivity); - bool isVirtualConncection(QString uuid); bool isWiredConnection(QString uuid); bool isWirelessConnection(QString uuid); bool isActivatedConnection(QString uuid); diff --git a/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp b/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp index 73adbd15..fb7f8a62 100644 --- a/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp +++ b/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp @@ -36,14 +36,14 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(pare initDeviceMap(); connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceAdd, - this, &KyNetworkDeviceResourse::onDeviceAdd, Qt::ConnectionType::DirectConnection); + this, &KyNetworkDeviceResourse::onDeviceAdd/*, Qt::ConnectionType::DirectConnection*/); connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceRemove, - this, &KyNetworkDeviceResourse::onDeviceRemove, Qt::ConnectionType::DirectConnection); + this, &KyNetworkDeviceResourse::onDeviceRemove/*, Qt::ConnectionType::DirectConnection*/); connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceUpdate, - this, &KyNetworkDeviceResourse::onDeviceUpdate, Qt::ConnectionType::DirectConnection); + this, &KyNetworkDeviceResourse::onDeviceUpdate/*, Qt::ConnectionType::DirectConnection*/); connect(m_networkResourceInstance, &KyNetworkResourceManager::stateChanged, - this, &KyNetworkDeviceResourse::stateChanged, Qt::ConnectionType::DirectConnection); + this, &KyNetworkDeviceResourse::stateChanged/*, Qt::ConnectionType::DirectConnection*/); connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceCarrierChanage, this, &KyNetworkDeviceResourse::carrierChanage); @@ -213,6 +213,42 @@ void KyNetworkDeviceResourse::setDeviceRefreshRate(QString deviceName, int ms) return; } +qulonglong KyNetworkDeviceResourse::getDeviceRxRefreshRate(QString deviceName) +{ + NetworkManager::Device::Ptr connectDevice = + m_networkResourceInstance->findDeviceInterface(deviceName); + if (connectDevice->isValid()) { + NetworkManager::DeviceStatistics::Ptr deviceStatistics = connectDevice->deviceStatistics(); + qulonglong rx = 0; + rx = deviceStatistics->rxBytes(); + if (rx != 0) { + return rx; + } else { + qDebug() << "connectDevice is invalid we do not get rxrate"; + } + } + + return 0; +} + +qulonglong KyNetworkDeviceResourse::getDeviceTxRefreshRate(QString deviceName) +{ + NetworkManager::Device::Ptr connectDevice = + m_networkResourceInstance->findDeviceInterface(deviceName); + if (connectDevice->isValid()) { + NetworkManager::DeviceStatistics::Ptr deviceStatistics = connectDevice->deviceStatistics(); + qulonglong tx = 0; + tx = deviceStatistics->txBytes(); + if (tx != 0){ + return tx; + } else { + qDebug() << "connectDevice is invalid we do not get txrate"; + } + } + + return 0; +} + bool KyNetworkDeviceResourse::getActiveConnectionInfo(const QString devName, int &signalStrength, QString &uni, QString &secuType) { signalStrength = 0; @@ -385,7 +421,7 @@ bool KyNetworkDeviceResourse::getDeviceManaged(QString deviceName) { NetworkManager::Device::Ptr connectDevice = m_networkResourceInstance->findDeviceInterface(deviceName); - if (connectDevice->isValid()) { + if (connectDevice != nullptr && connectDevice->isValid()) { return connectDevice->managed(); } else { qWarning()<<"[KyNetworkDeviceResourse] can not find device " << deviceName; diff --git a/src/backend/dbus-interface/kylinnetworkdeviceresource.h b/src/backend/dbus-interface/kylinnetworkdeviceresource.h index 32639803..4ad5881a 100644 --- a/src/backend/dbus-interface/kylinnetworkdeviceresource.h +++ b/src/backend/dbus-interface/kylinnetworkdeviceresource.h @@ -69,6 +69,9 @@ public: void setDeviceManaged(QString devName, bool managed); bool getDeviceManaged(QString devName); + qulonglong getDeviceRxRefreshRate(QString deviceName); + qulonglong getDeviceTxRefreshRate(QString deviceName); + private: KyWiredConnectOperation wiredOperation; KyNetworkResourceManager *m_networkResourceInstance = nullptr; diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp index 084f600e..d38ee6d2 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp @@ -26,6 +26,32 @@ #define LOG_FLAG "[KyNetworkResourceManager]" + +QString enumToQstring(NetworkManager::AccessPoint::Capabilities cap, NetworkManager::AccessPoint::WpaFlags wpa_flags,NetworkManager::AccessPoint::WpaFlags rsn_flags) +{ + QString out; + if ( (cap & NM_802_11_AP_FLAGS_PRIVACY) + && (wpa_flags == NM_802_11_AP_SEC_NONE) + && (rsn_flags == NM_802_11_AP_SEC_NONE)) { + out += "WEP "; + } + if (wpa_flags != NM_802_11_AP_SEC_NONE) { + out += "WPA1 "; + } + if ((rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK) + || (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) { + out += "WPA2 "; + } + if (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_SAE) { + out += "WPA3 "; + } + if ( (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) + || (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) { + out += "802.1X "; + } + return out; +} + KyNetworkResourceManager* KyNetworkResourceManager::m_pInstance = nullptr; KyNetworkResourceManager* KyNetworkResourceManager::getInstance() @@ -52,8 +78,6 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa qRegisterMetaType("NetworkManager::Device::Type"); qRegisterMetaType("NetworkManager::Device::State"); qRegisterMetaType("NetworkManager::Device::StateChangeReason"); - qRegisterMetaType("NetworkManager::VpnConnection::State"); - qRegisterMetaType("NetworkManager::VpnConnection::StateChangeReason"); QDBusConnection::systemBus().connect(QString("org.freedesktop.DBus"), QString("/org/freedesktop/DBus"), @@ -780,37 +804,46 @@ void KyNetworkResourceManager::onWifiNetworkUpdate(NetworkManager::WirelessNetwo return; } + bool bFlag = false; + QString devIface; + NetworkManager::Device::Ptr dev = findDeviceUni(net->device()); + if(dev.isNull()) { + qDebug()<< LOG_FLAG << "device invalid"; + bFlag = true; + } else { + devIface = dev->interfaceName(); + } + if(bFlag) { + //device invalid + qDebug() << LOG_FLAG << "wifiNetworkDeviceDisappear"; + Q_EMIT wifiNetworkDeviceDisappear(); + return; + } + + auto index = std::find(m_wifiNets.cbegin(), m_wifiNets.cend(), net); if (m_wifiNets.cend() != index) { if (net->accessPoints().isEmpty()) { - //Q_EMIT - bool bFlag = false; - QString devIface; - NetworkManager::Device::Ptr dev = findDeviceUni(net->device()); - if(dev.isNull()) { - qDebug()<< LOG_FLAG << "device invalid"; - bFlag = true; - } else { - devIface = dev->interfaceName(); - } - //remove auto pos = index - m_wifiNets.cbegin(); removeWifiNetwork(pos); - if(bFlag) { - //device invalid - qDebug() << LOG_FLAG << "wifiNetworkDeviceDisappear"; - Q_EMIT wifiNetworkDeviceDisappear(); - } else { - qDebug()<< LOG_FLAG << "wifiNetwork disappear" << net << net->ssid(); - NetworkManager::AccessPoint::Ptr accessPoitPtr = net->referenceAccessPoint(); - QByteArray rawSsid = accessPoitPtr->rawSsid(); - QString wifiSsid = getSsidFromByteArray(rawSsid); - Q_EMIT wifiNetworkRemoved(devIface, wifiSsid); - } + qDebug()<< LOG_FLAG << "wifiNetwork disappear" << net << net->ssid(); + NetworkManager::AccessPoint::Ptr accessPoitPtr = net->referenceAccessPoint(); + QByteArray rawSsid = accessPoitPtr->rawSsid(); + QString wifiSsid = getSsidFromByteArray(rawSsid); + Q_EMIT wifiNetworkRemoved(devIface, wifiSsid); } else { - qDebug()<< LOG_FLAG << "wifiNetworkPropertyChange " << net << net->ssid(); - Q_EMIT wifiNetworkPropertyChange(net); + NetworkManager::AccessPoint::Ptr accessPointPtr = net->referenceAccessPoint(); + if (accessPointPtr.isNull()) { + return; + } + QByteArray rawSsid = accessPointPtr->rawSsid(); + QString wifiSsid = getSsidFromByteArray(rawSsid); + QString bssid = accessPointPtr->hardwareAddress(); + QString secuType = enumToQstring(accessPointPtr->capabilities(), + accessPointPtr->wpaFlags(), + accessPointPtr->rsnFlags()); + Q_EMIT wifiNetworkPropertyChange(devIface, wifiSsid, net->signalStrength(), bssid, secuType); } } diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.h b/src/backend/dbus-interface/kylinnetworkresourcemanager.h index 0de8ce9a..b43b0dcf 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.h +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.h @@ -45,6 +45,8 @@ #include #include +QString enumToQstring(NetworkManager::AccessPoint::Capabilities cap, NetworkManager::AccessPoint::WpaFlags wpa_flags,NetworkManager::AccessPoint::WpaFlags rsn_flags); + class KyNetworkResourceManager : public QObject { Q_OBJECT @@ -122,7 +124,7 @@ Q_SIGNALS: //to KyWirelessNetResource void wifiNetworkRemoved(QString, QString); void wifiNetworkAdded(QString, QString); - void wifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net); + void wifiNetworkPropertyChange(QString, QString, int, QString, QString); void wifiNetworkSecuChange(NetworkManager::AccessPoint *); void wifiNetworkDeviceDisappear(); void wifiEnabledChanged(bool); diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index 9f4b2bea..38f46afe 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -826,6 +826,40 @@ NetworkManager::ConnectionSettings::Ptr return connectionSettings; } +QStringList KyWirelessConnectOperation::getBlackListHostName(QString apConnectPath) +{ + QStringList blackList; + blackList.clear(); + + QDBusInterface dbusInterface("org.freedesktop.NetworkManager", + apConnectPath, + "org.freedesktop.NetworkManager.Settings.Connection", + QDBusConnection::systemBus()); + if (!dbusInterface.isValid()) { + qWarning()<(); + QMap> map; + dbusArg1st >> map; + if (map.isEmpty()) { + qWarning() << Q_FUNC_INFO << __LINE__ <<"map is empty!"; + return blackList; + } + + QMap wirelessMap = map.value(KEY_802_11_WIRELESS); + if (wirelessMap.isEmpty()) { + qWarning() << Q_FUNC_INFO << __LINE__ <<"wirelessMap is empty!"; + return blackList; + } + if (wirelessMap.contains(KEY_BLACKLIST_HOSTNAME)) { + blackList = wirelessMap.value(KEY_BLACKLIST_HOSTNAME).toStringList(); + } + return blackList; +} + void KyWirelessConnectOperation::updateWirelessApSetting( NetworkManager::Connection::Ptr apConnectPtr, const QString apName, const QString apPassword, @@ -850,7 +884,6 @@ void KyWirelessConnectOperation::updateWirelessApSetting( wirelessSetting->setBand(NetworkManager::WirelessSetting::FrequencyBand::Automatic); } - NetworkManager::WirelessSecuritySetting::Ptr wirelessSecuritySetting = apConnectSettingPtr->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); if (apPassword.isEmpty()) { @@ -861,7 +894,12 @@ void KyWirelessConnectOperation::updateWirelessApSetting( wirelessSecuritySetting->setPsk(apPassword); } - apConnectPtr->update(apConnectSettingPtr->toMap()); + QStringList blackList = getBlackListHostName(apConnectPtr->path()); + NMVariantMapMap newMap = apConnectSettingPtr->toMap(); + if (newMap.contains(KEY_802_11_WIRELESS)) { + newMap[KEY_802_11_WIRELESS].insert(KEY_BLACKLIST_HOSTNAME, blackList); + } + apConnectPtr->update(newMap); } void KyWirelessConnectOperation::activeWirelessAp(const QString apUuid, const QString apName, @@ -999,7 +1037,7 @@ void KyWirelessConnectOperation::activateApConnectionByUuid(const QString apUuid QString connectPath = ""; QString deviceIdentifier = ""; QString connectName = ""; - QString specificObject = ""; + QString specificObject = "/"; qDebug()<<"it will activate hotspot connect"<referenceAccessPoint()->hardwareAddress(); m_device = net->device(); m_uni = net->referenceAccessPoint()->uni(); + + NetworkManager::Device::Ptr devicePtr = nullptr; + devicePtr = m_networkResourceInstance->findDeviceInterface(m_device); + if (!devicePtr.isNull()) { + QString devUni = devicePtr->uni(); + NetworkManager::WirelessNetwork::Ptr wirelessPtr = nullptr; + wirelessPtr = m_networkResourceInstance->findWifiNetwork(m_NetSsid, devUni); + if (!wirelessPtr.isNull()) { + NetworkManager::AccessPoint::List apList = wirelessPtr->accessPoints(); + bool b2G = false; + bool b5G = false; + if (!apList.empty()) { + for (int i = 0; i < apList.count(); ++i) { + if (apList.at(i)->frequency() < FREQ_5GHZ) { + b2G = true; + } + if (apList.at(i)->frequency() >= FREQ_5GHZ) { + b5G = true; + } + if (b2G && b5G) { + m_isMix = true; + break; + } + } + } + devicePtr = m_networkResourceInstance->findDeviceInterface(m_device); + if (!devicePtr.isNull()) { + QString devUni = devicePtr->uni(); + NetworkManager::WirelessNetwork::Ptr wirelessPtr = nullptr; + wirelessPtr = m_networkResourceInstance->findWifiNetwork(m_NetSsid, devUni); + if (!wirelessPtr.isNull()) { + NetworkManager::AccessPoint::List apList = wirelessPtr->accessPoints(); + bool b2G = false; + bool b5G = false; + if (!apList.empty()) { + for (int i = 0; i < apList.count(); ++i) { + if (apList.at(i)->frequency() < FREQ_5GHZ) { + b2G = true; + } + if (apList.at(i)->frequency() >= FREQ_5GHZ) { + b5G = true; + } + if (b2G && b5G) { + m_isMix = true; + break; + } + + } + } + } + } + } + } initInfoBySsid(); } diff --git a/src/backend/dbus-interface/kywirelessnetitem.h b/src/backend/dbus-interface/kywirelessnetitem.h index 36eecc76..533e6ca6 100644 --- a/src/backend/dbus-interface/kywirelessnetitem.h +++ b/src/backend/dbus-interface/kywirelessnetitem.h @@ -25,8 +25,6 @@ #include "kylinnetworkresourcemanager.h" #include "kywirelessconnectoperation.h" -QString enumToQstring(NetworkManager::AccessPoint::Capabilities, NetworkManager::AccessPoint::WpaFlags, NetworkManager::AccessPoint::WpaFlags); - class KyWirelessNetItem { public: @@ -47,6 +45,7 @@ public: QString m_secuType; KySecuType m_kySecuType; QString m_uni; + bool m_isMix; //only for m_isConfiged = true bool m_isConfigured; diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index e851b539..2ec9bcf0 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -61,15 +61,15 @@ KyWirelessNetResource::KyWirelessNetResource(QObject *parent) //TODO:connect device signal connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkAdded, - this, &KyWirelessNetResource::onWifiNetworkAdded, Qt::ConnectionType::DirectConnection); + this, &KyWirelessNetResource::onWifiNetworkAdded/*, Qt::ConnectionType::DirectConnection*/); connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkRemoved, - this, &KyWirelessNetResource::onWifiNetworkRemoved, Qt::ConnectionType::DirectConnection); + this, &KyWirelessNetResource::onWifiNetworkRemoved/*, Qt::ConnectionType::DirectConnection*/); connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkPropertyChange, - this, &KyWirelessNetResource::onWifiNetworkPropertyChange, Qt::ConnectionType::DirectConnection); + this, &KyWirelessNetResource::onWifiNetworkPropertyChange/*, Qt::ConnectionType::DirectConnection*/); connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkSecuChange, - this, &KyWirelessNetResource::onWifiNetworkSecuChange, Qt::ConnectionType::DirectConnection); + this, &KyWirelessNetResource::onWifiNetworkSecuChange/*, Qt::ConnectionType::DirectConnection*/); connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkDeviceDisappear, - this, &KyWirelessNetResource::onWifiNetworkDeviceDisappear, Qt::ConnectionType::DirectConnection); + this, &KyWirelessNetResource::onWifiNetworkDeviceDisappear/*, Qt::ConnectionType::DirectConnection*/); connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionAdd, this, &KyWirelessNetResource::onConnectionAdd); @@ -457,50 +457,36 @@ void KyWirelessNetResource::onWifiNetworkSecuChange(NetworkManager::AccessPoint } -void KyWirelessNetResource::onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net) +void KyWirelessNetResource::onWifiNetworkPropertyChange(QString interface, QString ssid, int signal, QString bssid, QString sec) { - if (nullptr == net) { - return; - } - qDebug() << "onWifiNetworkPropertyChange" << net->ssid(); - NetworkManager::AccessPoint::Ptr accessPointPtr = net->referenceAccessPoint(); - QByteArray rawSsid = accessPointPtr->rawSsid(); - QString wifiSsid = getSsidFromByteArray(rawSsid); + if (m_WifiNetworkList.contains(interface)) { + QList::iterator iter = m_WifiNetworkList[interface].begin(); + while (iter != m_WifiNetworkList[interface].end()) { + qDebug() << iter->m_NetSsid; + if (iter->m_NetSsid == ssid) { + // qDebug()<< LOG_FLAG <<"recive properity changed signal, sender is" << iter->m_NetSsid; + if (iter->m_signalStrength != signal) { + iter->m_signalStrength = signal; + Q_EMIT signalStrengthChange(interface, ssid, iter->m_signalStrength); + } - if (net->device().isEmpty()) { - return; - } + if (iter->m_bssid != bssid) { + qDebug() << "bssid"; + iter->m_bssid = bssid; + Q_EMIT bssidChange(interface, ssid, iter->m_bssid); + } - QString devIface = m_networkResourceInstance->findDeviceUni(net->device())->interfaceName(); - if (m_WifiNetworkList.contains(devIface)) { - QList::iterator iter = m_WifiNetworkList[devIface].begin(); - while (iter != m_WifiNetworkList[devIface].end()) { - if (iter->m_NetSsid == wifiSsid) { -// qDebug()<< LOG_FLAG <<"recive properity changed signal, sender is" << iter->m_NetSsid; - if (iter->m_signalStrength != net->signalStrength()) { - iter->m_signalStrength = net->signalStrength(); - Q_EMIT signalStrengthChange(devIface, wifiSsid, iter->m_signalStrength); - } + if (iter->m_secuType != sec) { + iter->setKySecuType(sec); + Q_EMIT secuTypeChange(interface, ssid, sec); + } - if (iter->m_bssid != accessPointPtr->hardwareAddress()) { - iter->m_bssid = accessPointPtr->hardwareAddress(); - Q_EMIT bssidChange(devIface, wifiSsid, iter->m_bssid); - } + break; + } - QString secuType = enumToQstring(accessPointPtr->capabilities(), - accessPointPtr->wpaFlags(), - accessPointPtr->rsnFlags()); - if (iter->m_secuType != secuType) { - //qDebug() << "!!!!secuTypeChange" << wifiSsid << iter->m_secuType << "change to " << secuType; - iter->setKySecuType(secuType); - Q_EMIT secuTypeChange(devIface, wifiSsid, secuType); - } - - break; - } - iter++; - } + iter++; + } } } diff --git a/src/backend/dbus-interface/kywirelessnetresource.h b/src/backend/dbus-interface/kywirelessnetresource.h index 807746d0..7afe52fe 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.h +++ b/src/backend/dbus-interface/kywirelessnetresource.h @@ -63,7 +63,7 @@ private: public Q_SLOTS: void onWifiNetworkAdded(QString, QString); void onWifiNetworkRemoved(QString, QString); - void onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net); + void onWifiNetworkPropertyChange(QString interface, QString ssid, int signal, QString bssid, QString sec); void onWifiNetworkSecuChange(NetworkManager::AccessPoint *accessPointPtr); void onWifiNetworkDeviceDisappear(); diff --git a/src/backend/dbusadaptor.cpp b/src/backend/dbusadaptor.cpp index d3325af3..0f22c845 100644 --- a/src/backend/dbusadaptor.cpp +++ b/src/backend/dbusadaptor.cpp @@ -147,18 +147,6 @@ void DbusAdaptor::setDeviceEnable(QString devName, bool enable) // return deviceName; //} -//删除 -void DbusAdaptor::deleteConnect(int type, QString ssid) -{ - if (type == WIRED) { - parent()->deleteWired(ssid); - } else if (type == WIRELESS) { - //待实现 - } else { - qDebug() << "[DbusAdaptor] deleteConnect type is invalid"; - } -} - //连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid void DbusAdaptor::activateConnect(int type, QString devName, QString ssid) { diff --git a/src/backend/dbusadaptor.h b/src/backend/dbusadaptor.h index 500ebfa3..6cb0f411 100644 --- a/src/backend/dbusadaptor.h +++ b/src/backend/dbusadaptor.h @@ -62,8 +62,6 @@ public Q_SLOTS: // METHODS // QString getDefaultWiredDevice(); // Q_NOREPLY void setDefaultWirelessDevice(QString deviceName); // QString getDefaultWirelessDevice(); - //刪除 根据网络名称 参数1 0:lan 1:wlan 参数2 为ssid/uuid - Q_NOREPLY void deleteConnect(int type, QString ssid); //连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid Q_NOREPLY void activateConnect(int type, QString devName, QString ssid); //断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid diff --git a/src/backend/kylinipv6arping.cpp b/src/backend/kylinipv6arping.cpp index bb4d78e3..a6969a6b 100644 --- a/src/backend/kylinipv6arping.cpp +++ b/src/backend/kylinipv6arping.cpp @@ -187,6 +187,18 @@ int KyIpv6Arping::parseIpv6Packet(const uint8_t *buf, size_t len, const struct s /* looks for Target Link-layer address option */ ptr = buf + sizeof (struct nd_neighbor_advert); + int index; + char macAddress[64] = {0}; + uint8_t hw_addr[6] = {0}; + getLocalMacAddress(m_ifaceName.toUtf8().constData(), hw_addr); + for (index = 0; index < 6; index++) { + snprintf(&macAddress[strlen(macAddress)], sizeof(macAddress) - strlen(macAddress), "%02X", hw_addr[index]); + if (index != 5) { + snprintf(&macAddress[strlen(macAddress)], sizeof(macAddress) - strlen(macAddress), "%s", ":"); + } + } + QString localAddr(macAddress); + while (len >= 8) { uint16_t optlen; @@ -212,6 +224,9 @@ int KyIpv6Arping::parseIpv6Packet(const uint8_t *buf, size_t len, const struct s optlen -= 2; saveMacAddress (ptr, optlen); + if (!localAddr.isEmpty() && getConflictMacAddress() == localAddr) { + break; + } setIpv6ConflictFlag(true); return 0; } diff --git a/src/frontend/enterprise-wlan/enterprisewlandialog.cpp b/src/frontend/enterprise-wlan/enterprisewlandialog.cpp index 7b772076..3a589886 100644 --- a/src/frontend/enterprise-wlan/enterprisewlandialog.cpp +++ b/src/frontend/enterprise-wlan/enterprisewlandialog.cpp @@ -23,7 +23,8 @@ #include "xatom-helper.h" #define MAIN_SIZE_EXPAND 480,580 #define MAIN_SIZE_NARROW 480,484 -#define SCROAREA_WIDTH 480 +#define PEAP_SCRO_HEIGHT 390 +#define TLS_SCRO_HEIGHT 590 #define MAIN_LAYOUT_MARGINS 0,0,0,0 #define CENTER_LAYOUT_MARGINS 24, 16, 24, 8 #define BUTTON_LAYOUT_MARGINS 24, 24, 24, 24 @@ -81,11 +82,11 @@ void EnterpriseWlanDialog::closeEvent(QCloseEvent *event) void EnterpriseWlanDialog::paintEvent(QPaintEvent *event) { - QPalette pal = qApp->palette(); - QPainter painter(this); - painter.setBrush(pal.color(QPalette::Base)); - painter.drawRect(this->rect()); - painter.fillRect(rect(), QBrush(pal.color(QPalette::Base))); +// QPalette pal = qApp->palette(); +// QPainter painter(this); +// painter.setBrush(pal.color(QPalette::Base)); +// painter.drawRect(this->rect()); +// painter.fillRect(rect(), QBrush(pal.color(QPalette::Base))); return QWidget::paintEvent(event); } @@ -126,15 +127,11 @@ void EnterpriseWlanDialog::initUI() m_enterWlanScrollArea = new QScrollArea(this); m_enterWlanScrollArea->setFrameShape(QFrame::NoFrame); m_enterWlanScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - m_centerWidget->setFixedWidth(SCROAREA_WIDTH); - m_enterWlanScrollArea->setFixedWidth(SCROAREA_WIDTH); m_enterWlanScrollArea->setWidget(m_centerWidget); - m_enterWlanScrollArea->setWidgetResizable(true); - QPalette pal = m_enterWlanScrollArea->palette(); - pal.setBrush(QPalette::Window, Qt::transparent); + pal.setBrush(QPalette::Base, QColor(0,0,0,0)); m_enterWlanScrollArea->setPalette(pal); + m_enterWlanScrollArea->setWidgetResizable(true); m_bottomDivider = new Divider(this); @@ -199,19 +196,24 @@ void EnterpriseWlanDialog::onPaletteChanged() { QPalette pal = qApp->palette(); -// QGSettings * styleGsettings = nullptr; -// const QByteArray style_id(THEME_SCHAME); -// if (QGSettings::isSchemaInstalled(style_id)) { -// styleGsettings = new QGSettings(style_id); -// QString currentTheme = styleGsettings->get(COLOR_THEME).toString(); -// if(currentTheme == "ukui-default"){ -// pal = lightPalette(this); -// } -// } - + QGSettings * styleGsettings = nullptr; + const QByteArray style_id(THEME_SCHAME); + if (QGSettings::isSchemaInstalled(style_id)) { + styleGsettings = new QGSettings(style_id); + QString currentTheme = styleGsettings->get(COLOR_THEME).toString(); + if(currentTheme == "ukui-default"){ + pal = lightPalette(this); + } + } + pal.setColor(QPalette::Background, pal.base().color()); this->setPalette(pal); setFramePalette(m_securityPage, pal); + + if (styleGsettings != nullptr) { + delete styleGsettings; + styleGsettings = nullptr; + } } void EnterpriseWlanDialog::initData() @@ -238,7 +240,7 @@ void EnterpriseWlanDialog::onBtnConnectClicked() KyWirelessConnectSetting connetSetting; connetSetting.setConnectName(m_wirelessNetItem.m_NetSsid); connetSetting.setIfaceName(m_deviceName); -// connetSetting.isAutoConnect = true; //ZJP_TODO 自动连接选项 + connetSetting.isAutoConnect = m_securityPage->getAutoConnectState(); //ZJP_TODO 自动连接选项 connetSetting.m_type = KyKeyMgmt::WpaEap; connetSetting.m_ssid = m_wirelessNetItem.m_NetSsid; connetSetting.m_secretFlag = 0; @@ -268,18 +270,21 @@ void EnterpriseWlanDialog::onEapTypeChanged(const KyEapMethodType &type) m_resource->getEnterPriseInfoTls(m_wirelessNetItem.m_connectUuid, m_info.tlsInfo); } this->setFixedSize(MAIN_SIZE_EXPAND); +// m_centerWidget->setFixedHeight(TLS_SCRO_HEIGHT); break; case KyEapMethodType::PEAP: if (m_wirelessNetItem.m_connectUuid.isEmpty()) { m_resource->getEnterPriseInfoPeap(m_wirelessNetItem.m_connectUuid, m_info.peapInfo); } this->setFixedSize(MAIN_SIZE_NARROW); +// m_centerWidget->setFixedHeight(PEAP_SCRO_HEIGHT); break; case KyEapMethodType::TTLS: if (!m_wirelessNetItem.m_connectUuid.isEmpty()) { m_resource->getEnterPriseInfoTtls(m_wirelessNetItem.m_connectUuid, m_info.ttlsInfo); } this->setFixedSize(MAIN_SIZE_NARROW); +// m_centerWidget->setFixedHeight(PEAP_SCRO_HEIGHT); break; default: break; diff --git a/src/frontend/frontend.pri b/src/frontend/frontend.pri index c8eb1cd7..b7703595 100644 --- a/src/frontend/frontend.pri +++ b/src/frontend/frontend.pri @@ -6,7 +6,6 @@ include(list-items/list-items.pri) include(netdetails/netdetails.pri) include(enterprise-wlan/enterprise-wlan.pri) include(networkmode/networkmode.pri) -include(single-pages/single-pages.pri) FORMS += \ $$PWD/wificonfigdialog.ui @@ -14,13 +13,11 @@ FORMS += \ HEADERS += \ $$PWD/customstyle.h \ $$PWD/mainwindow.h \ - $$PWD/vpnmainwindow.h \ $$PWD/wificonfigdialog.h SOURCES += \ $$PWD/customstyle.cpp \ $$PWD/mainwindow.cpp \ - $$PWD/vpnmainwindow.cpp \ $$PWD/wificonfigdialog.cpp DISTFILES += \ diff --git a/src/frontend/list-items/lanlistitem.cpp b/src/frontend/list-items/lanlistitem.cpp index 1560d668..ab9a7a01 100644 --- a/src/frontend/list-items/lanlistitem.cpp +++ b/src/frontend/list-items/lanlistitem.cpp @@ -23,6 +23,9 @@ #include #define LOG_FLAG "[LanListItem]" +#define NAMELABLE_MAX_WIDTH_HOVER 220 +#define NAMELABLE_MAX_WIDTH_ACTIVATED 190 +#define NAMELABLE_MAX_WIDTH_DEACTIVATED 326 LanListItem::LanListItem(const KyConnectItem *lanConnectItem, const QString &deviceName, QWidget *parent):ListItem(parent) @@ -42,16 +45,19 @@ LanListItem::LanListItem(const KyConnectItem *lanConnectItem, m_netButton->stopLoading(); if (m_lanConnectItem.m_connectState == Activated) { setIcon(true); + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_ACTIVATED); } else { setIcon(false); + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_DEACTIVATED); } } else { m_netButton->startLoading(); } m_itemFrame->installEventFilter(this); - connect(this->m_infoButton, &InfoButton::clicked, this, &LanListItem::onInfoButtonClicked); +// connect(this->m_infoButton, &InfoButton::clicked, this, &LanListItem::onInfoButtonClicked); connect(m_menu, &QMenu::triggered, this, &LanListItem::onMenuTriggered); + connect(m_hoverButton, &FixPushButton::clicked, this, &LanListItem::onNetButtonClicked); } @@ -62,7 +68,7 @@ LanListItem::LanListItem(QWidget *parent) : ListItem(parent) setIcon(false); const QString str=tr("Not connected"); m_nameLabel->setLabelText(str); - this->m_infoButton->hide(); +// this->m_infoButton->hide(); } LanListItem::~LanListItem() @@ -120,8 +126,7 @@ void LanListItem::onNetButtonClicked() this->showDesktopNotify(tr("Wired Device not carried"), "networkwrong"); } } else { - qDebug() << LOG_FLAG <<"the connection" << m_lanConnectItem.m_connectName - << "is not deactived, so it can not be operation."; + m_connectOperation->deactivateWiredConnection(m_lanConnectItem.m_connectName, m_lanConnectItem.m_connectUuid); } return; @@ -144,9 +149,10 @@ void LanListItem::onRightButtonClicked() } else { return; } + m_menu->addAction(new QAction(tr("Property"), this)); + m_menu->addAction(new QAction(tr("Delete"), this)); - m_menu->move(cursor().pos()); - m_menu->show(); + m_menu->popup(cursor().pos()); return; } @@ -159,6 +165,10 @@ void LanListItem::onMenuTriggered(QAction *action) qDebug() << LOG_FLAG << "it will disconnect connection" << m_lanConnectItem.m_connectName << ". it's device is" << m_deviceName; m_netButton->startLoading(); + } else if (action->text() == tr("Property")) { + onInfoButtonClicked(); + } else if (action->text() == tr("Delete")) { + m_connectOperation->deleteConnect(m_lanConnectItem.m_connectUuid); } return; } @@ -171,15 +181,15 @@ void LanListItem::onInfoButtonClicked() return; } - if(netDetail != nullptr){ - netDetail->activateWindow(); - return; - } +// if(netDetail != nullptr){ +// netDetail->activateWindow(); +// return; +// } qDebug()<< LOG_FLAG << "the info button of lan is clicked! uuid = " << m_lanConnectItem.m_connectUuid << "; name = " << m_lanConnectItem.m_connectName << "." <show(); - Q_EMIT this->detailShow(true); +#endif + Q_EMIT this->detailShow(m_deviceName, m_lanConnectItem.m_connectUuid); return; } @@ -239,3 +250,40 @@ void LanListItem::updateConnectionPath(QString connectionPath) { m_lanConnectItem.m_connectPath = connectionPath; } + +void LanListItem::enterEvent(QEvent *event) +{ + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_HOVER); + if (m_lanConnectItem.m_connectState != UnknownState) { + if (Deactivated != m_lanConnectItem.m_connectState) { + m_hoverButton->setProperty("useButtonPalette", true); + m_hoverButton->setProperty("isImportant", false); + m_hoverButton->setButtonText(tr("Disconnect")); + } else { + m_hoverButton->setProperty("isImportant", true); + m_hoverButton->setProperty("useButtonPalette", false); + m_hoverButton->setButtonText(tr("Connect")); + } + m_hoverButton->show(); + m_lbLoadUp->hide(); + m_lbLoadDown->hide(); + m_lbLoadDownImg->hide(); + m_lbLoadUpImg->hide(); + } + return ListItem::enterEvent(event); +} + +void LanListItem::leaveEvent(QEvent *event) +{ + m_hoverButton->hide(); + if (m_lanConnectItem.m_connectState == Activated) { + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_ACTIVATED); + m_lbLoadUp->show(); + m_lbLoadDown->show(); + m_lbLoadDownImg->show(); + m_lbLoadUpImg->show(); + } else { + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_DEACTIVATED); + } + return ListItem::leaveEvent(event); +} diff --git a/src/frontend/list-items/lanlistitem.h b/src/frontend/list-items/lanlistitem.h index e0209494..d6acd958 100644 --- a/src/frontend/list-items/lanlistitem.h +++ b/src/frontend/list-items/lanlistitem.h @@ -48,6 +48,8 @@ public: protected: void setIcon(bool isOn); void onRightButtonClicked(); + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); private: void connectItemCopy(const KyConnectItem *lanConnectItem); diff --git a/src/frontend/list-items/list-items.pri b/src/frontend/list-items/list-items.pri index 42550113..8fdc468e 100644 --- a/src/frontend/list-items/list-items.pri +++ b/src/frontend/list-items/list-items.pri @@ -8,13 +8,11 @@ HEADERS += \ $$PWD/lanlistitem.h \ $$PWD/listitem.h \ $$PWD/wlanlistitem.h \ - $$PWD/wlanmoreitem.h \ - $$PWD/vpnlistitem.h + $$PWD/wlanmoreitem.h SOURCES += \ $$PWD/lanlistitem.cpp \ $$PWD/listitem.cpp \ $$PWD/wlanlistitem.cpp \ - $$PWD/wlanmoreitem.cpp \ - $$PWD/vpnlistitem.cpp + $$PWD/wlanmoreitem.cpp diff --git a/src/frontend/list-items/listitem.cpp b/src/frontend/list-items/listitem.cpp index 52b86ebd..cd42a724 100644 --- a/src/frontend/list-items/listitem.cpp +++ b/src/frontend/list-items/listitem.cpp @@ -31,6 +31,85 @@ #define LIGHT_HOVER_COLOR QColor(240,240,240,255) #define DARK_HOVER_COLOR QColor(15,15,15,255) +#define CONNECT_BUTTON_WIDTH 96 +#define PWD_AREA_HEIGHT 36 + +#define FREQLABLE_HIGHT 18 +#define FREQLABLE_MARGINS 4,0,4,0 +#define LOADIMG_SIZE 16,16 + +FreqLabel::FreqLabel(QWidget *parent) : QLabel(parent) +{ + const QByteArray id("org.ukui.style"); + QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); + if(QGSettings::isSchemaInstalled(id)){ + connect(fontSetting, &QGSettings::changed,[=](QString key) { + if ("systemFontSize" ==key) { + changedFontSlot(); + } + }); + } + changedFontSlot(); +} + +void FreqLabel::changedFontSlot() +{ + const QByteArray id("org.ukui.style"); + if(QGSettings::isSchemaInstalled(id)){ + QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); + QVariant fontVariant = fontSetting->get("systemFontSize"); + QFont font; + font.setPointSize(fontVariant.toInt()*0.85); + this->setFont(font); + } +} + +void FreqLabel::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); //抗锯齿效果 + auto rect = this->rect(); + painter.drawRoundedRect(rect, 6, 6); + QLabel::paintEvent(event); +} + +FixPushButton::FixPushButton(QWidget *parent) : + QPushButton(parent) +{ + const QByteArray id("org.ukui.style"); + QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); + if(QGSettings::isSchemaInstalled(id)){ + connect(fontSetting, &QGSettings::changed,[=](QString key) { + if ("systemFont" == key || "systemFontSize" ==key) { + changedLabelSlot(); + } + }); + } +} + + +void FixPushButton::setButtonText(QString text) { + + mStr = text; + changedLabelSlot(); +} + +QString FixPushButton::getText(){ + return mStr; +} + +void FixPushButton::changedLabelSlot() { + QFontMetrics fontMetrics(this->font()); + int fontSize = fontMetrics.width(mStr); + if (fontSize > 65) { + setText(fontMetrics.elidedText(mStr, Qt::ElideRight, 65)); + setToolTip(mStr); + } else { + setText(mStr); + setToolTip(""); + } +} + ListItem::ListItem(QWidget *parent) : QFrame(parent) { m_connectState = UnknownState; @@ -48,10 +127,10 @@ ListItem::~ListItem() m_netButton = nullptr; } - if (nullptr != m_infoButton) { - delete m_infoButton; - m_infoButton = nullptr; - } +// if (nullptr != m_infoButton) { +// delete m_infoButton; +// m_infoButton = nullptr; +// } } @@ -156,22 +235,66 @@ void ListItem::initUI() m_hItemLayout = new QHBoxLayout(m_itemFrame); m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS); - m_hItemLayout->setSpacing(ITEM_FRAME_SPACING); + m_hItemLayout->setSpacing(0); m_hItemLayout->setAlignment(Qt::AlignHCenter); m_netButton = new RadioItemButton(m_itemFrame); - m_nameLabel = new FixLabel(m_itemFrame); - m_nameLabel->setMinimumWidth(262); - m_infoButton = new InfoButton(m_itemFrame); - m_infoButton->setIconSize(QSize(INFO_ICON_WIDTH,INFO_ICON_HEIGHT)); + m_freq = new FreqLabel(m_itemFrame); + m_freq->setEnabled(false); + m_freq->setText("..."); + m_freq->setAlignment(Qt::AlignCenter); + m_freq->hide(); + m_freq->setFixedHeight(FREQLABLE_HIGHT); + m_freq->setContentsMargins(FREQLABLE_MARGINS); + m_nameLabel = new NameLabel(m_itemFrame); + m_hoverButton = new FixPushButton(m_itemFrame); + m_hoverButton->setProperty("needTranslucent", true); + m_hoverButton->setFixedSize(CONNECT_BUTTON_WIDTH, PWD_AREA_HEIGHT); +// m_infoButton = new InfoButton(m_itemFrame); +// m_infoButton->setIconSize(QSize(INFO_ICON_WIDTH,INFO_ICON_HEIGHT)); + + m_lbLoadUp = new QLabel(m_itemFrame); + m_lbLoadUp->setAlignment(Qt::AlignCenter); + m_lbLoadDown = new QLabel(m_itemFrame); + m_lbLoadDown->setAlignment(Qt::AlignCenter); + m_lbLoadDownImg = new QLabel(m_itemFrame); + m_lbLoadUpImg = new QLabel(m_itemFrame); + m_lbLoadUp->hide(); + m_lbLoadDown->hide(); + m_lbLoadDownImg->hide(); + m_lbLoadUpImg->hide(); + m_lbLoadDownImg->setFixedSize(LOADIMG_SIZE); + m_lbLoadDownImg->setAlignment(Qt::AlignCenter); + m_lbLoadUpImg->setFixedSize(LOADIMG_SIZE); + m_lbLoadUpImg->setAlignment(Qt::AlignCenter); + QFont font; + font.setPointSize(10); + m_lbLoadUp->setFont(font); + m_lbLoadDown->setFont(font); + m_lbLoadUp->setText("0KB/s"); + m_lbLoadDown->setText("0KB/s"); + m_lbLoadDownImg->setPixmap(QPixmap(QLatin1String(":/res/x/load-down.png"))); + m_lbLoadUpImg->setPixmap(QPixmap(QLatin1String(":/res/x/load-up.png"))); m_hItemLayout->addWidget(m_netButton); + m_hItemLayout->addSpacing(10); m_hItemLayout->addWidget(m_nameLabel); + m_hItemLayout->addSpacing(8); + m_hItemLayout->addWidget(m_freq); m_hItemLayout->addStretch(); - m_hItemLayout->addWidget(m_infoButton); + m_hItemLayout->addWidget(m_lbLoadUpImg); + m_hItemLayout->addWidget(m_lbLoadUp); + m_hItemLayout->addSpacing(2); + m_hItemLayout->addWidget(m_lbLoadDownImg); + m_hItemLayout->addWidget(m_lbLoadDown); + m_hItemLayout->addSpacing(2); + m_hItemLayout->addWidget(m_hoverButton); +// m_hItemLayout->addWidget(m_infoButton); m_mainLayout->addWidget(m_itemFrame); + m_hoverButton->hide(); + // this->setAutoFillBackground(true); // this->setBackgroundRole(QPalette::Base); // QPalette pal = qApp->palette(); @@ -193,3 +316,46 @@ void ListItem::onPaletteChanged() // this->setPalette(pal); } + +NameLabel::NameLabel(QWidget *parent) + :QLabel(parent) +{ + const QByteArray id("org.ukui.style"); + QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); + if(QGSettings::isSchemaInstalled(id)){ + connect(fontSetting, &QGSettings::changed,[=](QString key) { + if ("systemFont" == key || "systemFontSize" ==key) { + changedLabelSlot(); + } + }); + } +} + +void NameLabel::setLabelText(QString text) +{ + m_name = text; + changedLabelSlot(); +} + +void NameLabel::setLabelMaximumWidth(int width) +{ + m_maximumWidth = width; + this->setMaximumWidth(m_maximumWidth); + if (m_name != nullptr) { + changedLabelSlot(); + } +} + +void NameLabel::changedLabelSlot() +{ + QFontMetrics fontMetrics(this->font()); + int fontSize = fontMetrics.width(m_name); + if (fontSize > m_maximumWidth) { + setText(fontMetrics.elidedText(m_name, Qt::ElideRight, m_maximumWidth)); + setToolTip(m_name); + } else { + this->setFixedWidth(fontMetrics.width(m_name)); + setText(m_name); + setToolTip(""); + } +} diff --git a/src/frontend/list-items/listitem.h b/src/frontend/list-items/listitem.h index df59b9b4..7789e3b3 100644 --- a/src/frontend/list-items/listitem.h +++ b/src/frontend/list-items/listitem.h @@ -37,6 +37,54 @@ typedef enum{ Deactivated /**< The connection is no longer active */ }ConnectState; +class FreqLabel : public QLabel +{ + Q_OBJECT +public: + FreqLabel(QWidget *parent = nullptr); + ~FreqLabel() = default; +protected: + void paintEvent(QPaintEvent *event); + +private Q_SLOTS: + void changedFontSlot(); +}; + +class FixPushButton : public QPushButton +{ + Q_OBJECT +public: + explicit FixPushButton(QWidget *parent = 0); + +public: + void setButtonText(QString text); + QString getText(); + +private Q_SLOTS: + void changedLabelSlot(); +private: + QString mStr; + +}; + +class NameLabel : public QLabel +{ + Q_OBJECT +public: + explicit NameLabel(QWidget *parent = 0); + ~NameLabel() = default; + void setLabelText(QString text); + void setLabelMaximumWidth(int width); + +private: + QString m_name; + int m_maximumWidth = 120; + +private Q_SLOTS: + void changedLabelSlot(); + +}; + class ListItem : public QFrame { Q_OBJECT @@ -58,19 +106,29 @@ protected: protected: QFrame * m_itemFrame = nullptr; - FixLabel * m_nameLabel = nullptr; + NameLabel * m_nameLabel = nullptr; RadioItemButton * m_netButton = nullptr; - InfoButton * m_infoButton = nullptr; +// InfoButton * m_infoButton = nullptr; bool m_isActive = false; ConnectState m_connectState; QMenu *m_menu = nullptr; + + public: QVBoxLayout * m_mainLayout = nullptr; QHBoxLayout * m_hItemLayout = nullptr; + QLabel *m_lbLoadDown = nullptr; + QLabel *m_lbLoadUp = nullptr; + QLabel *m_lbLoadDownImg = nullptr; + QLabel *m_lbLoadUpImg = nullptr; + QLabel *m_freq = nullptr; + NetDetail *netDetail = nullptr; + + FixPushButton *m_hoverButton = nullptr; private: void initUI(); void initConnection(); @@ -81,7 +139,7 @@ public Q_SLOTS: virtual void onMenuTriggered(QAction *action)=0; Q_SIGNALS: - void detailShow(bool isShow); + void detailShow(QString, QString); }; #endif // LISTITEM_H diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index 61dbe675..4b5ef274 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -27,6 +27,9 @@ #define WAIT_US 10*1000 #define ENABLE_BUTTON_COLOR qApp->palette().highlight().color() #define UNABLE_BUTTON_COLOR qApp->palette().button().color() +#define NAMELABLE_MAX_WIDTH_HOVER 176 +#define NAMELABLE_MAX_WIDTH_ACTIVATED 142 +#define NAMELABLE_MAX_WIDTH_DEACTIVATED 276 const QString ENTERPRICE_TYPE = "802.1X"; const QString WPA1_AND_WPA2 = "WPA"; @@ -49,8 +52,9 @@ WlanListItem::WlanListItem(KyWirelessNetItem &wirelessNetItem, QString device, Q initWlanUI(); setExpanded(false); - connect(this->m_infoButton, &InfoButton::clicked, this, &WlanListItem::onInfoButtonClicked); +// connect(this->m_infoButton, &InfoButton::clicked, this, &WlanListItem::onInfoButtonClicked); connect(m_menu, &QMenu::triggered, this, &WlanListItem::onMenuTriggered); + connect(m_hoverButton, &FixPushButton::clicked, this, &WlanListItem::onNetButtonClicked); m_wirelessConnectOperation = new KyWirelessConnectOperation(this); m_deviceResource = new KyNetworkDeviceResourse(this); @@ -69,7 +73,7 @@ WlanListItem::WlanListItem(QWidget *parent) : ListItem(parent) setExpanded(false); this->setName(name); // this->m_netButton->setEnabled(false); - this->m_infoButton->hide(); +// this->m_infoButton->hide(); } WlanListItem::~WlanListItem() @@ -133,6 +137,8 @@ void WlanListItem::setExpanded(const bool &expanded) if (expanded) { m_pwdLineEdit->setFocus(); setFixedHeight(EXPANDED_HEIGHT); + m_hoverButton->hide(); + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_DEACTIVATED); } else { setFixedHeight(NORMAL_HEIGHT); } @@ -176,12 +182,14 @@ void WlanListItem::onRightButtonClicked() return; } + if (m_wirelessNetItem.m_isConfigured) { + m_menu->addAction(new QAction(tr("Property"), this)); m_menu->addAction(new QAction(tr("Forget"), this)); } - m_menu->move(cursor().pos()); - m_menu->show(); +// m_menu->move(cursor().pos()); + m_menu->popup(cursor().pos()); return; } @@ -190,6 +198,23 @@ void WlanListItem::enterEvent(QEvent *event) { //qDebug()<< LOG_FLAG <<"enterEvent" << m_wirelessNetItem.m_NetSsid; m_mouseIsOut = false; + if (m_pwdFrame != nullptr && !m_pwdFrame->isVisible()) { + if (Deactivated != m_connectState) { + m_hoverButton->setProperty("useButtonPalette", true); + m_hoverButton->setProperty("isImportant", false); + m_hoverButton->setButtonText(tr("Disconnect")); + } else { + m_hoverButton->setProperty("isImportant", true); + m_hoverButton->setProperty("useButtonPalette", false); + m_hoverButton->setButtonText(tr("Connect")); + } + m_hoverButton->show(); + m_lbLoadUp->hide(); + m_lbLoadDown->hide(); + m_lbLoadDownImg->hide(); + m_lbLoadUpImg->hide(); + } + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_HOVER); return ListItem::enterEvent(event); } @@ -197,6 +222,16 @@ void WlanListItem::leaveEvent(QEvent *event) { //qDebug()<< LOG_FLAG <<"leaveEvent"<< m_wirelessNetItem.m_NetSsid; m_mouseIsOut = true; + m_hoverButton->hide(); + if (m_connectState == Activated) { + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_ACTIVATED); + m_lbLoadUp->show(); + m_lbLoadDown->show(); + m_lbLoadDownImg->show(); + m_lbLoadUpImg->show(); + } else { + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_DEACTIVATED); + } if (m_pwdFrame && m_pwdFrame->isVisible()) { if (m_focusIsOut) { setExpanded(false); @@ -245,6 +280,7 @@ void WlanListItem::paintEvent(QPaintEvent *event) { QPalette pal = qApp->palette(); if (m_pwdLineEdit != nullptr) { + pal.setColor(QPalette::Base, pal.color(QPalette::Base)); m_pwdLineEdit->setPalette(pal); } @@ -293,11 +329,11 @@ void WlanListItem::initWlanUI() m_pwdLineEdit->setFixedHeight(PWD_AREA_HEIGHT); m_pwdFrameLyt->addWidget(m_pwdLineEdit); - m_connectButton = new QPushButton(m_pwdFrame); + m_connectButton = new FixPushButton(m_pwdFrame); m_connectButton->setProperty("isImportant", true); m_connectButton->setProperty("needTranslucent", true); m_connectButton->setFixedSize(CONNECT_BUTTON_WIDTH, PWD_AREA_HEIGHT); - m_connectButton->setText(tr("Connect")); + m_connectButton->setButtonText(tr("Connect")); m_connectButton->setEnabled(false); connect(m_connectButton, &QPushButton::clicked, this, &WlanListItem::onConnectButtonClicked); m_pwdFrameLyt->addWidget(m_connectButton); @@ -328,6 +364,9 @@ void WlanListItem::initWlanUI() m_pwdFrame->hide(); m_autoConnectFrame->hide(); + + this->m_freq->show(); + this->setFrequency(); } QString getIcon(bool isEncrypted, int signalStrength, int category) { @@ -435,17 +474,17 @@ void WlanListItem::refreshIcon(bool isActivated) void WlanListItem::onInfoButtonClicked() { //ZJP_TODO 呼出无线详情页 - if(netDetail != nullptr){ - netDetail->activateWindow(); - return; - } +// if(netDetail != nullptr){ +// netDetail->activateWindow(); +// return; +// } qDebug() << LOG_FLAG << "Net active or not:"<< m_connectState; qDebug() << LOG_FLAG << "On wlan info button clicked! ssid = " << m_wirelessNetItem.m_NetSsid << "; name = " << m_wirelessNetItem.m_connName << "." <show(); - Q_EMIT this->detailShow(true); +#endif + Q_EMIT this->detailShow(m_wlanDevice, m_wirelessNetItem.m_NetSsid); } void WlanListItem::onNetButtonClicked() @@ -471,8 +511,7 @@ void WlanListItem::onNetButtonClicked() } if (Deactivated != m_connectState) { - qDebug() << LOG_FLAG <<"the connection" << m_wirelessNetItem.m_connName - << "is not deactived, so it can not be operation." << Q_FUNC_INFO << __LINE__; + m_wirelessConnectOperation->deActivateWirelessConnection(m_wlanDevice, m_wirelessNetItem.m_connectUuid); return; } @@ -510,6 +549,7 @@ void WlanListItem::onNetButtonClicked() if (m_wirelessNetItem.m_secuType.contains("802.1x", Qt::CaseInsensitive)) { if (isEnterpriseWlanDialogShow && enterpriseWlanDialog != nullptr) { qDebug() << LOG_FLAG <<"EnterpriseWlanDialog is show do not show again!"; + KWindowSystem::activateWindow(enterpriseWlanDialog->winId()); KWindowSystem::raiseWindow(enterpriseWlanDialog->winId()); return; } else { @@ -619,13 +659,28 @@ void WlanListItem::updateConnectState(ConnectState state) if (Activated == state) { m_netButton->stopLoading(); m_netButton->setActive(true); + m_hoverButton->setProperty("useButtonPalette", true); + m_hoverButton->setProperty("isImportant", false); + m_hoverButton->setButtonText(tr("Disconnect")); + if (m_hoverButton->isHidden()) { + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_ACTIVATED); + } } else if(Deactivated == state) { qDebug() << "[WlanListItem] stop loading connect state:" << state; m_netButton->stopLoading(); m_netButton->setActive(false); + m_hoverButton->setProperty("isImportant", true); + m_hoverButton->setProperty("useButtonPalette", false); + m_hoverButton->setButtonText(tr("Connect")); + if (m_hoverButton->isHidden()) { + m_nameLabel->setLabelMaximumWidth(NAMELABLE_MAX_WIDTH_DEACTIVATED); + } } else { qDebug() << "[WlanListItem] start loading connect state:" << state; m_netButton->startLoading(); + m_hoverButton->setProperty("useButtonPalette", true); + m_hoverButton->setProperty("isImportant", false); + m_hoverButton->setButtonText(tr("Disconnect")); } return; @@ -645,6 +700,8 @@ void WlanListItem::onMenuTriggered(QAction *action) m_pwdLineEdit->clear(); } m_wirelessConnectOperation->deleteWirelessConnect(m_wirelessNetItem.m_connectUuid); + } else if (action->text() == tr("Property")) { + onInfoButtonClicked(); } return; @@ -664,3 +721,22 @@ void WlanListItem::forgetPwd() return; } } + + +void WlanListItem::setFrequency() +{ + uint freq = m_wirelessNetItem.m_frequency; + bool isMix = m_wirelessNetItem.m_isMix; + + if (isMix) { + this->m_freq->setText("2.4/5G"); + return; + } + if (freq < FREQ_5GHZ) { + this->m_freq->setText("2.4G"); + } else { + this->m_freq->setText("5G"); + } + + return; +} diff --git a/src/frontend/list-items/wlanlistitem.h b/src/frontend/list-items/wlanlistitem.h index 4427ad24..5325d3e1 100644 --- a/src/frontend/list-items/wlanlistitem.h +++ b/src/frontend/list-items/wlanlistitem.h @@ -48,6 +48,8 @@ using namespace kdk; #define LOW_SIGNAL 5 #define NONE_SIGNAL 0 +#define FREQ_5GHZ 5000 + class WlanListItem : public ListItem { Q_OBJECT @@ -79,6 +81,8 @@ public: void forgetPwd(); + void setFrequency(); + protected: void resizeEvent(QResizeEvent *event); void onRightButtonClicked(); @@ -110,7 +114,7 @@ private: QFrame *m_pwdFrame = nullptr; QHBoxLayout *m_pwdFrameLyt = nullptr; KPasswordEdit *m_pwdLineEdit = nullptr; - QPushButton *m_connectButton = nullptr; + FixPushButton *m_connectButton = nullptr; //自动连接选择区域UI QFrame *m_autoConnectFrame = nullptr; diff --git a/src/frontend/list-items/wlanmoreitem.cpp b/src/frontend/list-items/wlanmoreitem.cpp index 450d40b6..576e3363 100644 --- a/src/frontend/list-items/wlanmoreitem.cpp +++ b/src/frontend/list-items/wlanmoreitem.cpp @@ -23,7 +23,8 @@ WlanMoreItem::WlanMoreItem(QWidget *parent) : ListItem(parent) { setObjectName(WMI_OB_NAME); m_netButton->setVisible(false); - m_infoButton->setVisible(false); +// m_infoButton->setVisible(false); + m_nameLabel->setLabelMaximumWidth(326); m_nameLabel->setLabelText(tr("Add Others...")); } diff --git a/src/frontend/mainwindow.cpp b/src/frontend/mainwindow.cpp index 7c98d89a..56fcf996 100644 --- a/src/frontend/mainwindow.cpp +++ b/src/frontend/mainwindow.cpp @@ -49,6 +49,24 @@ const QString intel = "V10SP1-edu"; #define KEY_PRODUCT_FEATURES "PRODUCT_FEATURES" +#define MW_EXCELLENT_SIGNAL 80 +#define MW_GOOD_SIGNAL 55 +#define MW_OK_SIGNAL 30 +#define MW_LOW_SIGNAL 5 +#define MW_NONE_SIGNAL 0 + +#define EXCELLENT_SIGNAL_ICON "network-wireless-signal-excellent-symbolic" +#define GOOD_SIGNAL_ICON "network-wireless-signal-good-symbolic" +#define OK_SIGNAL_ICON "network-wireless-signal-ok-symbolic" +#define LOW_SIGNAL_ICON "network-wireless-signal-weak-symbolic" +#define NONE_SIGNAL_ICON "network-wireless-signal-none-symbolic" + +#define EXCELLENT_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-excellent-error-symbolic" +#define GOOD_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-good-error-symbolic" +#define OK_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-ok-error-symbolic" +#define LOW_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-weak-error-symbolic" +#define NONE_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-none-error-symbolic" + #include #include @@ -139,6 +157,7 @@ void MainWindow::firstlyStart() initDbusConnnect(); initWindowTheme(); initTrayIcon(); + initPlatform(); m_secondaryStartTimer = new QTimer(this); connect(m_secondaryStartTimer, &QTimer::timeout, this, [ = ]() { m_secondaryStartTimer->stop(); @@ -148,6 +167,10 @@ void MainWindow::firstlyStart() m_createPagePtrMap.clear(); + m_networkMode = new NetworkMode(this); + m_networkMode->initWiredNetworkMode(); + m_networkMode->initWirelessNetworkMode(); + //加载key ring agent_init(); } @@ -167,19 +190,19 @@ void MainWindow::secondaryStart() */ void MainWindow::initPlatform() { -// char* projectName = kdk_system_get_projectName(); -// QString strProjectName(projectName); -// free(projectName); -// projectName = NULL; -// if(v10Sp1.compare(strProjectName,Qt::CaseInsensitive) == 0) { -// unsigned int feature = kdk_system_get_productFeatures(); -// if (feature == 3) { -// m_isShowInCenter = true; -// } -// } else if (intel.compare(strProjectName,Qt::CaseInsensitive) == 0) { -// m_isShowInCenter = true; -// } -// qDebug() << "projectName" << projectName << m_isShowInCenter; + char* projectName = kdk_system_get_projectName(); + QString strProjectName(projectName); + free(projectName); + projectName = NULL; + if(v10Sp1.compare(strProjectName,Qt::CaseInsensitive) == 0) { + unsigned int feature = kdk_system_get_productFeatures(); + if (feature == 3) { + m_isShowInCenter = true; + } + } else if (intel.compare(strProjectName,Qt::CaseInsensitive) == 0) { + m_isShowInCenter = true; + } + qDebug() << "projectName" << projectName << m_isShowInCenter; } /** @@ -289,18 +312,14 @@ void MainWindow::initUI() */ void MainWindow::initTrayIcon() { - loadIcons.append(QIcon::fromTheme("kylin-network-1")); - loadIcons.append(QIcon::fromTheme("kylin-network-2")); - loadIcons.append(QIcon::fromTheme("kylin-network-3")); - loadIcons.append(QIcon::fromTheme("kylin-network-4")); - loadIcons.append(QIcon::fromTheme("kylin-network-5")); - loadIcons.append(QIcon::fromTheme("kylin-network-6")); - loadIcons.append(QIcon::fromTheme("kylin-network-7")); - loadIcons.append(QIcon::fromTheme("kylin-network-8")); - loadIcons.append(QIcon::fromTheme("kylin-network-9")); - loadIcons.append(QIcon::fromTheme("kylin-network-10")); - loadIcons.append(QIcon::fromTheme("kylin-network-11")); - loadIcons.append(QIcon::fromTheme("kylin-network-12")); + loadIcons.append(QIcon::fromTheme("ukui-loading-0-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-3-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-4-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-5-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-6-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic")); iconTimer = new QTimer(this); connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading); @@ -357,7 +376,7 @@ void MainWindow::initDbusConnnect() connect(m_wlanWidget, &WlanPage::connectivityChanged, this, &MainWindow::onConnectivityChanged); //模式切换 - QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), + QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interfacer"), QString("/"), QString("com.kylin.statusmanager.interface"), QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool))); @@ -514,7 +533,6 @@ void MainWindow::showByWaylandHelper() //去除窗管标题栏,传入参数为QWidget* kdk::UkuiStyleHelper::self()->removeHeader(this); this->show(); - getTabletMode(); resetWindowPosition(); //设置窗体位置,传入参数为QWindow*,QRect @@ -535,24 +553,6 @@ void MainWindow::setCentralWidgetType(IconActiveType iconStatus) } } -void MainWindow::getTabletMode() -{ -// QDBusInterface interface(QString("com.kylin.statusmanager.interface"), -// QString("/"), -// QString("com.kylin.statusmanager.interface"), -// QDBusConnection::sessionBus()); -// if(!interface.isValid()) { -// m_isShowInCenter = true; -// return; -// } -// QDBusReply reply = interface.call("get_current_tabletmode"); -// if (!reply.isValid()) { -// m_isShowInCenter = true; -// return; -// } -// m_isShowInCenter = reply.value(); -} - /** * @brief MainWindow::onTrayIconActivated 点击托盘图标的槽函数 */ @@ -597,12 +597,14 @@ void MainWindow::onThemeChanged(const QString &key) void MainWindow::onRefreshTrayIcon() { //更新托盘图标显示 + int signalStrength = 0; iconTimer->stop(); if (m_lanWidget->lanIsConnected()) { m_trayIcon->setIcon(QIcon::fromTheme("network-wired-connected-symbolic")); iconStatus = IconActiveType::LAN_CONNECTED; } else if (m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activated)){ - m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-connected-symbolic")); +// m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-connected-symbolic")); + signalStrength = m_wlanWidget->getAcivateWifiSignal(); iconStatus = IconActiveType::WLAN_CONNECTED; } else { m_trayIcon->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic")); @@ -617,15 +619,42 @@ void MainWindow::onRefreshTrayIcon() iconStatus = IconActiveType::LAN_CONNECTED_LIMITED; } else if (iconStatus == IconActiveType::WLAN_CONNECTED) { //todo 信号强度 - m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-error-symbolic")); +// m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-error-symbolic")); iconStatus = IconActiveType::WLAN_CONNECTED_LIMITED; } } + + if (iconStatus == IconActiveType::WLAN_CONNECTED + || iconStatus == IconActiveType::WLAN_CONNECTED_LIMITED) { + if (signalStrength > MW_EXCELLENT_SIGNAL){ + m_trayIcon->setIcon(QIcon::fromTheme(EXCELLENT_SIGNAL_ICON)); + } else if (signalStrength > MW_GOOD_SIGNAL) { + m_trayIcon->setIcon(QIcon::fromTheme(GOOD_SIGNAL_ICON)); + } else if (signalStrength > MW_OK_SIGNAL) { + m_trayIcon->setIcon(QIcon::fromTheme(OK_SIGNAL_ICON)); + } else if (signalStrength > MW_LOW_SIGNAL) { + m_trayIcon->setIcon(QIcon::fromTheme(LOW_SIGNAL_ICON)); + } else { + m_trayIcon->setIcon(QIcon::fromTheme(NONE_SIGNAL_ICON)); + } + } else if (iconStatus == IconActiveType::WLAN_CONNECTED_LIMITED) { + if (signalStrength > MW_EXCELLENT_SIGNAL){ + m_trayIcon->setIcon(QIcon::fromTheme(EXCELLENT_SIGNAL_LIMIT_ICON)); + } else if (signalStrength > MW_GOOD_SIGNAL) { + m_trayIcon->setIcon(QIcon::fromTheme(GOOD_SIGNAL_LIMIT_ICON)); + } else if (signalStrength > MW_OK_SIGNAL) { + m_trayIcon->setIcon(QIcon::fromTheme(OK_SIGNAL_LIMIT_ICON)); + } else if (signalStrength > MW_LOW_SIGNAL) { + m_trayIcon->setIcon(QIcon::fromTheme(LOW_SIGNAL_LIMIT_ICON)); + } else { + m_trayIcon->setIcon(QIcon::fromTheme(NONE_SIGNAL_LIMIT_ICON)); + } + } } void MainWindow::onSetTrayIconLoading() { - if (currentIconIndex > 11) { + if (currentIconIndex > 7) { currentIconIndex = 0; } m_trayIcon->setIcon(loadIcons.at(currentIconIndex)); @@ -833,7 +862,7 @@ void MainWindow::showCreateWiredConnectWidget(const QString devName) if (m_createPagePtrMap.contains(devName)) { if (m_createPagePtrMap[devName] != nullptr) { qDebug() << "showCreateWiredConnectWidget" << devName << "already create,just raise"; - + KWindowSystem::activateWindow(m_createPagePtrMap[devName]->winId()); KWindowSystem::raiseWindow(m_createPagePtrMap[devName]->winId()); return; } @@ -851,35 +880,7 @@ void MainWindow::showCreateWiredConnectWidget(const QString devName) void MainWindow::showAddOtherWlanWidget(QString devName) { qDebug() << "showAddOtherWlanWidget! devName = " << devName; - if (m_addOtherPagePtrMap.contains(devName)) { - if (m_addOtherPagePtrMap[devName] != nullptr) { - qDebug() << "showAddOtherWlanWidget" << devName << "already create,just raise"; - - KWindowSystem::raiseWindow(m_addOtherPagePtrMap[devName]->winId()); - return; - } - } - -#if 0 - NetDetail *netDetail = new NetDetail(devName, "", "", false, true, true, this); - connect(netDetail, &NetDetail::createPageClose, [&](QString interfaceName){ - if (m_addOtherPagePtrMap.contains(interfaceName)) { - m_addOtherPagePtrMap[interfaceName] = nullptr; - } - }); - m_addOtherPagePtrMap.insert(devName, netDetail); - netDetail->show(); -#endif - - JoinHiddenWiFiPage *hiddenWiFi =new JoinHiddenWiFiPage(devName); - connect(hiddenWiFi, &JoinHiddenWiFiPage::hiddenWiFiPageClose, [&](QString interfaceName){ - if (m_addOtherPagePtrMap.contains(interfaceName)) { - m_addOtherPagePtrMap[interfaceName] = nullptr; - } - }); - m_addOtherPagePtrMap.insert(devName, hiddenWiFi); - connect(hiddenWiFi, &JoinHiddenWiFiPage::showWlanList, this, &MainWindow::onShowMainWindow); - hiddenWiFi->show(); + m_wlanWidget->showAddOtherPage(devName); } void MainWindow::getWirelessDeviceCap(QMap &map) @@ -887,12 +888,6 @@ void MainWindow::getWirelessDeviceCap(QMap &map) m_wlanWidget->getWirelessDeviceCap(map); } -//有线连接删除 -void MainWindow::deleteWired(const QString &connUuid) -{ - m_lanWidget->deleteWired(connUuid); -} - //有线连接断开 void MainWindow::activateWired(const QString& devName, const QString& connUuid) { diff --git a/src/frontend/mainwindow.h b/src/frontend/mainwindow.h index fe5d5691..b7bcb591 100644 --- a/src/frontend/mainwindow.h +++ b/src/frontend/mainwindow.h @@ -34,6 +34,8 @@ #include "wlanpage.h" #include "netdetails/netdetail.h" #include "netdetails/joinhiddenwifipage.h" +//安全中心-网络防火墙模式配置 +#include "networkmodeconfig.h" //删除此头文件,别在添加 //#include @@ -81,8 +83,6 @@ public: void getApConnectionPath(QString &path, QString uuid); //获取热点ActivePath void getActiveConnectionPath(QString &path, QString uuid); - //删除有线连接 - void deleteWired(const QString& connUuid); //有线连接断开 void activateWired(const QString& devName, const QString& connUuid); void deactivateWired(const QString& devName, const QString& connUuid); @@ -154,13 +154,13 @@ private: void initUI(); void initDbusConnnect(); void initTrayIcon(); + void resetTrayIconTool(); void initWindowTheme(); void resetWindowTheme(); void showControlCenter(); void showByWaylandHelper(); void setCentralWidgetType(IconActiveType iconStatus); - void getTabletMode(); double m_transparency=1.0; //透明度 QGSettings * m_transGsettings; //透明度配置文件 int currentIconIndex=0; @@ -197,8 +197,8 @@ private: IconActiveType iconStatus = IconActiveType::NOT_CONNECTED; QMap m_createPagePtrMap; -// QMap m_addOtherPagePtrMap; - QMap m_addOtherPagePtrMap; + + NetworkMode *m_networkMode; public Q_SLOTS: void onShowMainWindow(int type); diff --git a/src/frontend/netdetails/configpage.cpp b/src/frontend/netdetails/configpage.cpp index 0218480a..ebb5fb94 100644 --- a/src/frontend/netdetails/configpage.cpp +++ b/src/frontend/netdetails/configpage.cpp @@ -22,6 +22,7 @@ #include #define VERTICAL_SPACING 24 +#define KSC_FIREWALL_NOCONFIG -1 #define KSC_FIREWALL_PUBLIC 0 #define KSC_FIREWALL_PRIVATE 1 @@ -65,7 +66,7 @@ void ConfigPage::initUi() "it is suitable for networks in public places, such as airports or coffee shops, etc.")); m_publicLabel->setWordWrap(true); //专用 网络中的设备可发现此电脑。一般情况下适用于家庭或工作单位的网络,您认识并信任网络上的个人和设备。 - m_privateLabel->setText(tr("Devices on the network can discover this computer. Generally applicable to a network " + m_privateLabel->setText(tr("Private Devices on the network can discover this computer. Generally applicable to a network " "at home or work where you know and trust the individuals and devices on the network.")); m_privateLabel->setWordWrap(true); //配置防火墙和安全设置 @@ -111,6 +112,7 @@ int ConfigPage::getConfigState() } else if (m_privateButton->isChecked()) { return KSC_FIREWALL_PRIVATE; } + return KSC_FIREWALL_NOCONFIG; } diff --git a/src/frontend/netdetails/coninfo.h b/src/frontend/netdetails/coninfo.h index a2b8cce2..1aef5fb4 100644 --- a/src/frontend/netdetails/coninfo.h +++ b/src/frontend/netdetails/coninfo.h @@ -20,6 +20,7 @@ #ifndef CONINFO_H #define CONINFO_H +#include #include #include #include @@ -93,7 +94,6 @@ public: QString strIPV4FirDns; QString strIPV4SecDns; QString strIPV4GateWay; - QList ipv4DnsList; KyIpConfigType ipv6ConfigType = CONFIG_IP_DHCP; QString strIPV6Address; @@ -101,7 +101,6 @@ public: QString strIPV6FirDns; QString strIPV6SecDns; QString strIPV6GateWay; - QList ipv6DnsList; KyEapMethodType enterpriseType; KyEapMethodTlsInfo tlsInfo; @@ -126,11 +125,12 @@ static void setFramePalette(QFrame *widget, QPalette &pal) { static QPalette lightPalette(QWidget *widget) { - auto palette = widget->palette(); - //ukui-light palette UKUI3.1 + QPalette palette = qApp->palette(); + + //ukui-light palette UKUI3.1 亮主题色板 QColor windowText_at(38, 38, 38), - windowText_iat(38, 38, 38), - windowText_dis(166, 166, 166), + windowText_iat(0, 0, 0, 255 * 0.55), + windowText_dis(0, 0, 0, 255 * 0.3), button_at(230, 230, 230), button_iat(230, 230, 230), button_dis(233, 233, 233), @@ -148,10 +148,10 @@ static QPalette lightPalette(QWidget *widget) mid_dis(102, 102, 102), text_at(38, 38, 38), text_iat(38, 38, 38), - text_dis(140, 140, 140), - brightText_at(89, 89, 89), - brightText_iat(89, 89, 89), - brightText_dis(77, 77, 77), + text_dis(0, 0, 0, 255 * 0.3), + brightText_at(0, 0, 0), + brightText_iat(0, 0, 0), + brightText_dis(0, 0, 0), buttonText_at(38, 38, 38), buttonText_iat(38, 38, 38), buttonText_dis(179, 179, 179), @@ -161,24 +161,12 @@ static QPalette lightPalette(QWidget *widget) window_at(245, 245, 245), window_iat(237, 237, 237), window_dis(230, 230, 230), - shadow_at(0, 0, 0, 16), - shadow_iat(0, 0, 0, 16), - shadow_dis(0, 0, 0, 21), -// shadow_at(214, 214, 214), -// shadow_iat(214, 214, 214), -// shadow_dis(201, 201, 201), - highLight_at(55, 144, 250), - highLight_iat(55, 144, 250), - highLight_dis(233, 233, 233), + shadow_at(0, 0, 0, 255 * 0.16), + shadow_iat(0, 0, 0, 255 * 0.16), + shadow_dis(0, 0, 0, 255 * 0.21), highLightText_at(255, 255, 255), highLightText_iat(255, 255, 255), highLightText_dis(179, 179, 179), - link_at(55, 144, 250), - link_iat(55, 144, 250), - link_dis(55, 144, 250), - linkVisited_at(114, 46, 209), - linkVisited_iat(114, 46, 209), - linkVisited_dis(114, 46, 209), alternateBase_at(245, 245, 245), alternateBase_iat(245, 245, 245), alternateBase_dis(245, 245, 245), @@ -191,11 +179,9 @@ static QPalette lightPalette(QWidget *widget) toolTipText_at(38, 38, 38), toolTipText_iat(38, 38, 38), toolTipText_dis(38, 38, 38), - placeholderText_at(38, 38, 38), - placeholderText_iat(38, 38, 38), - placeholderText_dis(38, 38, 38); - - + placeholderText_at(0, 0, 0, 255 * 0.35), + placeholderText_iat(0, 0, 0, 255 * 0.35), + placeholderText_dis(0, 0, 0, 255 * 0.3); palette.setColor(QPalette::Active, QPalette::WindowText, windowText_at); palette.setColor(QPalette::Inactive, QPalette::WindowText, windowText_iat); @@ -245,22 +231,10 @@ static QPalette lightPalette(QWidget *widget) palette.setColor(QPalette::Inactive, QPalette::Shadow, shadow_iat); palette.setColor(QPalette::Disabled, QPalette::Shadow, shadow_dis); - palette.setColor(QPalette::Active, QPalette::Highlight, highLight_at); - palette.setColor(QPalette::Inactive, QPalette::Highlight, highLight_iat); - palette.setColor(QPalette::Disabled, QPalette::Highlight, highLight_dis); - palette.setColor(QPalette::Active, QPalette::HighlightedText, highLightText_at); palette.setColor(QPalette::Inactive, QPalette::HighlightedText, highLightText_iat); palette.setColor(QPalette::Disabled, QPalette::HighlightedText, highLightText_dis); - palette.setColor(QPalette::Active, QPalette::Link, link_at); - palette.setColor(QPalette::Inactive, QPalette::Link, link_iat); - palette.setColor(QPalette::Disabled, QPalette::Link, link_dis); - - palette.setColor(QPalette::Active, QPalette::LinkVisited, linkVisited_at); - palette.setColor(QPalette::Inactive, QPalette::LinkVisited, linkVisited_iat); - palette.setColor(QPalette::Disabled, QPalette::LinkVisited, linkVisited_dis); - palette.setColor(QPalette::Active, QPalette::AlternateBase, alternateBase_at); palette.setColor(QPalette::Inactive, QPalette::AlternateBase, alternateBase_iat); palette.setColor(QPalette::Disabled, QPalette::AlternateBase, alternateBase_dis); diff --git a/src/frontend/netdetails/creatnetpage.cpp b/src/frontend/netdetails/creatnetpage.cpp index ba5d0f98..7f242c5e 100644 --- a/src/frontend/netdetails/creatnetpage.cpp +++ b/src/frontend/netdetails/creatnetpage.cpp @@ -21,6 +21,8 @@ #include "math.h" #define MAX_NAME_LENGTH 32 +#define HINT_TEXT_MARGINS 8, 1, 0, 3 +#define LABEL_HEIGHT 24 CreatNetPage::CreatNetPage(QWidget *parent):QFrame(parent) { @@ -36,39 +38,87 @@ void CreatNetPage::initUI() ipv4addressEdit = new LineEdit(this); netMaskEdit = new LineEdit(this); gateWayEdit = new LineEdit(this); + firstDnsEdit = new LineEdit(this); + secondDnsEdit = new LineEdit(this); m_connNameLabel = new QLabel(this); m_configLabel = new QLabel(this); m_addressLabel = new QLabel(this); m_maskLabel = new QLabel(this); m_gateWayLabel = new QLabel(this); + m_dnsLabel = new QLabel(this); + m_secDnsLabel = new QLabel(this); - // IP的正则格式限制 - QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); - m_dnsWidget = new MultipleDnsWidget(rx, this); + QLabel *nameEmptyLabel = new QLabel(this); + QLabel *configEmptyLabel = new QLabel(this); + QLabel *gateWayEmptyLabel = new QLabel(this); + QLabel *firstDnsEmptyLabel = new QLabel(this); + nameEmptyLabel->setFixedHeight(LABEL_HEIGHT); + configEmptyLabel->setFixedHeight(LABEL_HEIGHT); + gateWayEmptyLabel->setFixedHeight(LABEL_HEIGHT); + firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT); + + m_addressHintLabel = new QLabel(this); + m_maskHintLabel = new QLabel(this); + m_addressHintLabel->setFixedHeight(LABEL_HEIGHT); + m_maskHintLabel->setFixedHeight(LABEL_HEIGHT); + m_addressHintLabel->setContentsMargins(HINT_TEXT_MARGINS); + m_maskHintLabel->setContentsMargins(HINT_TEXT_MARGINS); + + QPalette hintTextColor; + hintTextColor.setColor(QPalette::WindowText, Qt::red); + m_addressHintLabel->setPalette(hintTextColor); + m_maskHintLabel->setPalette(hintTextColor); + + QWidget *addressWidget = new QWidget(this); + QVBoxLayout *addressLayout = new QVBoxLayout(addressWidget); + addressLayout->setContentsMargins(0, 0, 0, 0); + addressLayout->setSpacing(0); + addressLayout->addWidget(ipv4addressEdit); + addressLayout->addWidget(m_addressHintLabel); + + QWidget *maskWidget = new QWidget(this); + QVBoxLayout *maskLayout = new QVBoxLayout(maskWidget); + maskLayout->setContentsMargins(0, 0, 0, 0); + maskLayout->setSpacing(0); + maskLayout->addWidget(netMaskEdit); + maskLayout->addWidget(m_maskHintLabel); m_connNameLabel->setText(tr("Connection Name")); m_configLabel->setText(tr("IPv4Config")); m_addressLabel->setText(tr("Address")); m_maskLabel->setText(tr("Netmask")); m_gateWayLabel->setText(tr("Default Gateway")); + m_dnsLabel->setText(tr("Prefs DNS")); + m_secDnsLabel->setText(tr("Alternative DNS")); m_detailLayout = new QFormLayout(this); + m_detailLayout->setVerticalSpacing(0); m_detailLayout->setContentsMargins(0, 0, 0, 0); - m_detailLayout->setSpacing(24); m_detailLayout->addRow(m_connNameLabel,connNameEdit); + m_detailLayout->addRow(nameEmptyLabel); m_detailLayout->addRow(m_configLabel,ipv4ConfigCombox); - m_detailLayout->addRow(m_addressLabel,ipv4addressEdit); - m_detailLayout->addRow(m_maskLabel,netMaskEdit); + m_detailLayout->addRow(configEmptyLabel); + m_detailLayout->addRow(m_addressLabel, addressWidget); + m_detailLayout->addRow(m_maskLabel, maskWidget); m_detailLayout->addRow(m_gateWayLabel,gateWayEdit); - m_detailLayout->addRow(m_dnsWidget); + m_detailLayout->addRow(gateWayEmptyLabel); + m_detailLayout->addRow(m_dnsLabel,firstDnsEdit); + m_detailLayout->addRow(firstDnsEmptyLabel); + m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit); ipv4ConfigCombox->addItem(tr("Auto(DHCP)"), AUTO_CONFIG); //"自动(DHCP)" ipv4ConfigCombox->addItem(tr("Manual"), MANUAL_CONFIG); //"手动" + + // IP的正则格式限制 + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + ipv4addressEdit->setValidator(new QRegExpValidator(rx, this)); gateWayEdit->setValidator(new QRegExpValidator(rx, this)); netMaskEdit->setValidator(new QRegExpValidator(rx, this)); + firstDnsEdit->setValidator(new QRegExpValidator(rx, this)); + secondDnsEdit->setValidator(new QRegExpValidator(rx, this)); } void CreatNetPage::initComponent() { @@ -83,6 +133,11 @@ void CreatNetPage::initComponent() { connect(ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn())); connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + + connect(ipv4addressEdit, SIGNAL(textChanged(QString)), this, SLOT(onAddressTextChanged())); + connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(onNetMaskTextChanged())); } bool CreatNetPage::checkConnectBtnIsEnabled() @@ -104,6 +159,26 @@ bool CreatNetPage::checkConnectBtnIsEnabled() qDebug() << "create ipv4 netMask empty or invalid"; return false; } + +// if (gateWayEdit->text().isEmpty() || !getTextEditState(gateWayEdit->text())) { +// qDebug() << "create ipv4 gateway empty or invalid"; +// return false; +// } + + if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) { + qDebug() << "create ipv4 dns sort invalid"; + return false; + } + + if (!getTextEditState(firstDnsEdit->text())) { + qDebug() << "create ipv4 first dns invalid"; + return false; + } + + if (!getTextEditState(secondDnsEdit->text())) { + qDebug() << "create ipv4 second dns invalid"; + return false; + } } return true; } @@ -117,17 +192,38 @@ void CreatNetPage::configChanged(int index) { } } +void CreatNetPage::onAddressTextChanged() +{ + if (!getTextEditState(ipv4addressEdit->text())) { + m_addressHintLabel->setText(tr("Invalid address")); + } else { + m_addressHintLabel->clear(); + } +} + +void CreatNetPage::onNetMaskTextChanged() +{ + if (!netMaskIsValide(netMaskEdit->text())) { + m_maskHintLabel->setText(tr("Invalid subnet mask")); + } else { + m_maskHintLabel->clear(); + } +} + void CreatNetPage::setLineEnabled(bool check) { ipv4addressEdit->setEnabled(check); netMaskEdit->setEnabled(check); gateWayEdit->setEnabled(check); - m_dnsWidget->setEditEnabled(check); + firstDnsEdit->setEnabled(check); + secondDnsEdit->setEnabled(check); if (!check) { ipv4addressEdit->clear(); netMaskEdit->clear(); gateWayEdit->clear(); + firstDnsEdit->clear(); + secondDnsEdit->clear(); ipv4addressEdit->setPlaceholderText(" "); netMaskEdit->setPlaceholderText(" "); @@ -165,17 +261,13 @@ void CreatNetPage::constructIpv4Info(KyConnectSetting &setting) << " gateWay " << gateWay; QStringList dnsList; - dnsList.clear(); - - QList ipv4dnsList; - ipv4dnsList.clear(); - ipv4dnsList = m_dnsWidget->getDns(); - for (QHostAddress str: ipv4dnsList) { - if (!dnsList.contains(str.toString())) { - dnsList << str.toString(); + dnsList.empty(); + if (!firstDnsEdit->text().isEmpty()) { + dnsList << firstDnsEdit->text(); + if (!secondDnsEdit->text().isEmpty()) { + dnsList << secondDnsEdit->text(); } } - if (ipv4ConfigCombox->currentData() == AUTO_CONFIG) { setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP); } else { diff --git a/src/frontend/netdetails/creatnetpage.h b/src/frontend/netdetails/creatnetpage.h index 31885b3b..71ccefd7 100644 --- a/src/frontend/netdetails/creatnetpage.h +++ b/src/frontend/netdetails/creatnetpage.h @@ -32,7 +32,6 @@ #include #include "coninfo.h" -#include "multiplednswidget.h" class CreatNetPage : public QFrame { @@ -47,7 +46,10 @@ private: LineEdit *ipv4addressEdit; LineEdit *netMaskEdit; LineEdit *gateWayEdit; + LineEdit *firstDnsEdit; + LineEdit *secondDnsEdit; +private: QFormLayout *m_detailLayout; QVBoxLayout *mvBoxLayout; QLabel *m_connNameLabel; @@ -55,8 +57,11 @@ private: QLabel *m_addressLabel; QLabel *m_maskLabel; QLabel *m_gateWayLabel; - MultipleDnsWidget *m_dnsWidget = nullptr; + QLabel *m_dnsLabel; + QLabel *m_secDnsLabel; + QLabel *m_addressHintLabel; + QLabel *m_maskHintLabel; private: void initUI(); void initComponent(); @@ -71,6 +76,9 @@ private: private Q_SLOTS: void setEnableOfSaveBtn(); void configChanged(int index); + void onAddressTextChanged(); + void onNetMaskTextChanged(); + Q_SIGNALS: void setCreatePageState(bool); diff --git a/src/frontend/netdetails/detailpage.cpp b/src/frontend/netdetails/detailpage.cpp index 9356f1c1..159dbb2a 100644 --- a/src/frontend/netdetails/detailpage.cpp +++ b/src/frontend/netdetails/detailpage.cpp @@ -248,7 +248,7 @@ void DetailPage::initUI() { m_IPV4Dns = new QLabel(this); m_ipv4DnsWidget = new DetailWidget(qobject_cast(m_IPV4Dns), m_listWidget); - m_ipv4DnsWidget->setKey(tr("IPv4 Dns:")); + m_ipv4DnsWidget->setKey(tr("IPv4 DNS:")); m_IPV6 = new FixLabel(this); m_IPV6->setFixedWidth(MAX_LABEL_WIDTH); @@ -324,7 +324,7 @@ void DetailPage::on_btnCopyNetDetail_clicked() QString chanCopy= tr ("Chan:"); QString bandwithCopy = tr("BandWidth:"); QString ipv4Copy = tr("IPv4:"); - QString ipv4dnsCopy = tr("IPv4 Dns:"); + QString ipv4dnsCopy = tr("IPv4 DNS:"); QString ipv6Copy = tr("IPv6:"); QString macCopy = tr("Mac:"); QString netDetailCopyText; diff --git a/src/frontend/netdetails/detailwidget.cpp b/src/frontend/netdetails/detailwidget.cpp index 2c0d1864..8a02c59a 100644 --- a/src/frontend/netdetails/detailwidget.cpp +++ b/src/frontend/netdetails/detailwidget.cpp @@ -18,9 +18,7 @@ * */ #include "detailwidget.h" -#include #include -#include #define ITEM_HEIGHT 36 #define ITEM_MARGINS 18,0,16,0 @@ -28,45 +26,6 @@ #define MAX_LABEL_WIDTH 154 #define MAX_WIDGET_WIDTH 270 -FixLabel::FixLabel(QWidget *parent) : - QLabel(parent) -{ - const QByteArray id("org.ukui.style"); - QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); - if(QGSettings::isSchemaInstalled(id)){ - connect(fontSetting, &QGSettings::changed,[=](QString key) { - if ("systemFont" == key || "systemFontSize" ==key) { - changedLabelSlot(); - } - }); - } -} - - -void FixLabel::setLabelText(QString text) { - - mStr = text; - changedLabelSlot(); -} - -QString FixLabel::getText(){ - return mStr; -} - -void FixLabel::changedLabelSlot() { - QFontMetrics fontMetrics(this->font()); - int fontSize = fontMetrics.width(mStr); - if (fontSize > this->width()) { - setText(fontMetrics.elidedText(mStr, Qt::ElideRight, this->width())); - setToolTip(mStr); - } else { - setText(mStr); - setToolTip(""); - } -} - - - DetailWidget::DetailWidget(QWidget *valueWidget, QWidget *parent, QWidget *buttonWidget) : m_valueWidget(valueWidget) , QWidget(parent) , m_copyButton(buttonWidget) { diff --git a/src/frontend/netdetails/detailwidget.h b/src/frontend/netdetails/detailwidget.h index c82a5eb5..dcfa6c28 100644 --- a/src/frontend/netdetails/detailwidget.h +++ b/src/frontend/netdetails/detailwidget.h @@ -23,23 +23,7 @@ #include #include #include - -class FixLabel : public QLabel -{ - Q_OBJECT -public: - explicit FixLabel(QWidget *parent = 0); - -public: - void setLabelText(QString text); - QString getText(); - -private Q_SLOTS: - void changedLabelSlot(); -private: - QString mStr; - -}; +#include "kylable.h" class DetailWidget : public QWidget { diff --git a/src/frontend/netdetails/ipv4page.cpp b/src/frontend/netdetails/ipv4page.cpp index 8e0bae39..6e2ca81c 100644 --- a/src/frontend/netdetails/ipv4page.cpp +++ b/src/frontend/netdetails/ipv4page.cpp @@ -39,11 +39,15 @@ void Ipv4Page::initUI() { ipv4addressEdit = new LineEdit(this); netMaskEdit = new LineEdit(this); gateWayEdit = new LineEdit(this); + firstDnsEdit = new LineEdit(this); + secondDnsEdit = new LineEdit(this); m_configLabel = new QLabel(this); m_addressLabel = new QLabel(this); m_maskLabel = new QLabel(this); m_gateWayLabel = new QLabel(this); + m_dnsLabel = new QLabel(this); + m_secDnsLabel = new QLabel(this); m_configEmptyLabel = new QLabel(this); m_configEmptyLabel->setFixedHeight(LABEL_HEIGHT); @@ -60,10 +64,16 @@ void Ipv4Page::initUI() { m_gateWayEmptyLabel = new QLabel(this); m_gateWayEmptyLabel->setFixedHeight(LABEL_HEIGHT); + m_firstDnsEmptyLabel = new QLabel(this); + m_firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT); + + m_configLabel->setText(tr("IPv4Config")); m_addressLabel->setText(tr("Address")); m_maskLabel->setText(tr("Netmask")); m_gateWayLabel->setText(tr("Default Gateway")); + m_dnsLabel->setText(tr("Prefs DNS")); + m_secDnsLabel->setText(tr("Alternative DNS")); m_statusLabel = new QLabel(this); m_statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); @@ -90,10 +100,6 @@ void Ipv4Page::initUI() { maskLayout->addWidget(netMaskEdit); maskLayout->addWidget(m_maskHintLabel); - // IP的正则格式限制 - QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); - m_dnsWidget = new MultipleDnsWidget(rx, this); - m_detailLayout = new QFormLayout(this); m_detailLayout->setVerticalSpacing(0); m_detailLayout->setContentsMargins(LAYOUT_MARGINS); @@ -103,7 +109,9 @@ void Ipv4Page::initUI() { m_detailLayout->addRow(m_maskLabel,maskWidget); m_detailLayout->addRow(m_gateWayLabel,gateWayEdit); m_detailLayout->addRow(m_gateWayEmptyLabel); - m_detailLayout->addRow(m_dnsWidget); + m_detailLayout->addRow(m_dnsLabel,firstDnsEdit); + m_detailLayout->addRow(m_firstDnsEmptyLabel); + m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit); ipv4ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)" ipv4ConfigCombox->addItem(tr("Manual")); //"手动" @@ -116,9 +124,14 @@ void Ipv4Page::initUI() { // netMaskCombox->addItem("255.0.0.0"); //8 + // IP的正则格式限制 + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + ipv4addressEdit->setValidator(new QRegExpValidator(rx, this)); gateWayEdit->setValidator(new QRegExpValidator(rx, this)); netMaskEdit->setValidator(new QRegExpValidator(rx, this)); + firstDnsEdit->setValidator(new QRegExpValidator(rx, this)); + secondDnsEdit->setValidator(new QRegExpValidator(rx, this)); initLoadingIcon(); } @@ -139,6 +152,8 @@ void Ipv4Page::initComponent() { connect(ipv4addressEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); } void Ipv4Page::setIpv4Config(KyIpConfigType ipv4Config) @@ -160,9 +175,14 @@ void Ipv4Page::setNetMask(const QString &netMask) netMaskEdit->setText(netMask); } -void Ipv4Page::setMulDns(const QList &dns) +void Ipv4Page::setIpv4FirDns(const QString &ipv4FirDns) { - m_dnsWidget->setDnsListText(dns); + firstDnsEdit->setText(ipv4FirDns); +} + +void Ipv4Page::setIpv4SecDns(const QString &ipv4SecDns) +{ + secondDnsEdit->setText(ipv4SecDns); } void Ipv4Page::setGateWay(const QString &gateWay) @@ -193,22 +213,19 @@ bool Ipv4Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) isChanged = true; } qDebug() << "ipv4 netmask " << getNetMaskText(netMaskEdit->text()); - - QList ipv4dnsList; - ipv4dnsList.clear(); - ipv4dnsList = m_dnsWidget->getDns(); - if(info.strIPV4Address != ipv4addressEdit->text() || info.strIPV4NetMask != /*netMaskEdit->text()*/getNetMaskText(netMaskEdit->text()) || info.strIPV4GateWay != gateWayEdit->text() - || info.ipv4DnsList != ipv4dnsList) { + || info.strIPV4FirDns != firstDnsEdit->text() + || info.strIPV4SecDns != secondDnsEdit->text()) { qDebug() << "ipv4 info changed"; QStringList dnsList; - dnsList.clear(); - for (QHostAddress str: ipv4dnsList) { - if (!dnsList.contains(str.toString())) { - dnsList << str.toString(); + dnsList.empty(); + if (!firstDnsEdit->text().isEmpty()) { + dnsList << firstDnsEdit->text(); + if (!secondDnsEdit->text().isEmpty()) { + dnsList << secondDnsEdit->text(); } } @@ -239,6 +256,26 @@ bool Ipv4Page::checkConnectBtnIsEnabled() qDebug() << "ipv4 netMask empty or invalid"; return false; } + +// if (gateWayEdit->text().isEmpty() || !getTextEditState(gateWayEdit->text())) { +// qDebug() << "ipv4 gateway empty or invalid"; +// return false; +// } + + if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) { + qDebug() << "ipv4 dns sort invalid"; + return false; + } + + if (!getTextEditState(firstDnsEdit->text())) { + qDebug() << "ipv4 first dns invalid"; + return false; + } + + if (!getTextEditState(secondDnsEdit->text())) { + qDebug() << "ipv4 second dns invalid"; + return false; + } } return true; } @@ -288,6 +325,8 @@ void Ipv4Page::setLineEnabled(bool check) { ipv4addressEdit->clear(); netMaskEdit->clear(); gateWayEdit->clear(); + firstDnsEdit->clear(); + secondDnsEdit->clear(); ipv4addressEdit->setPlaceholderText(" "); netMaskEdit->setPlaceholderText(" "); @@ -300,7 +339,8 @@ void Ipv4Page::setLineEnabled(bool check) { ipv4addressEdit->setEnabled(check); netMaskEdit->setEnabled(check); gateWayEdit->setEnabled(check); - m_dnsWidget->setEditEnabled(check); + firstDnsEdit->setEnabled(check); + secondDnsEdit->setEnabled(check); } void Ipv4Page::setEnableOfSaveBtn() { diff --git a/src/frontend/netdetails/ipv4page.h b/src/frontend/netdetails/ipv4page.h index fbb5422e..f5e9a779 100644 --- a/src/frontend/netdetails/ipv4page.h +++ b/src/frontend/netdetails/ipv4page.h @@ -33,7 +33,6 @@ //#include "kylinconnectsetting.h" #include "coninfo.h" -#include "multiplednswidget.h" class Ipv4Page : public QFrame { @@ -43,11 +42,10 @@ public: void setIpv4Config(KyIpConfigType ipv4Config); void setIpv4(const QString &ipv4); void setNetMask(const QString &netMask); - void setMulDns(const QList &dns); + void setIpv4FirDns(const QString &ipv4FirDns); + void setIpv4SecDns(const QString &ipv4SecDns); void setGateWay(const QString &gateWay); - QString getNetMaskText(QString text); - bool checkIsChanged(const ConInfo info, KyConnectSetting &setting); void startLoading(); @@ -59,6 +57,8 @@ private: LineEdit *ipv4addressEdit; LineEdit *netMaskEdit; LineEdit *gateWayEdit; + LineEdit *firstDnsEdit; + LineEdit *secondDnsEdit; QFormLayout *m_detailLayout; QVBoxLayout *mvBoxLayout; @@ -66,13 +66,14 @@ private: QLabel *m_addressLabel; QLabel *m_maskLabel; QLabel *m_gateWayLabel; + QLabel *m_dnsLabel; + QLabel *m_secDnsLabel; QLabel *m_configEmptyLabel; QLabel *m_addressHintLabel; QLabel *m_maskHintLabel; QLabel *m_gateWayEmptyLabel; - - MultipleDnsWidget *m_dnsWidget = nullptr; + QLabel *m_firstDnsEmptyLabel; QLabel *m_statusLabel = nullptr; QList m_loadIcons; @@ -89,7 +90,7 @@ private: void configSave(); bool getTextEditState(QString text); bool netMaskIsValide(QString text); - + QString getNetMaskText(QString text); bool checkConnectBtnIsEnabled(); void initConflictHintLable(); void initLoadingIcon(); diff --git a/src/frontend/netdetails/ipv6page.cpp b/src/frontend/netdetails/ipv6page.cpp index a08fa73b..ed34bce8 100644 --- a/src/frontend/netdetails/ipv6page.cpp +++ b/src/frontend/netdetails/ipv6page.cpp @@ -52,9 +52,14 @@ void Ipv6Page::setIpv6Perfix(const int &ipv6Perfix) lengthEdit->setText(QString::number(ipv6Perfix)); } -void Ipv6Page::setMulDns(const QList &dns) +void Ipv6Page::setIpv6FirDns(const QString &ipv6FirDns) { - m_dnsWidget->setDnsListText(dns); + firstDnsEdit->setText(ipv6FirDns); +} + +void Ipv6Page::setIpv6SecDns(const QString &ipv6SecDns) +{ + secondDnsEdit->setText(ipv6SecDns); } void Ipv6Page::setGateWay(const QString &gateWay) @@ -83,21 +88,19 @@ bool Ipv6Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) setting.setIpConfigType(IPADDRESS_V6, CONFIG_IP_MANUAL); isChanged = true; } - - QList ipv6dnsList; - ipv6dnsList.clear(); - ipv6dnsList = m_dnsWidget->getDns(); if(info.strIPV6Address != ipv6AddressEdit->text() || info.iIPV6Prefix != lengthEdit->text().toInt() || info.strIPV6GateWay != gateWayEdit->text() - || info.ipv6DnsList != ipv6dnsList) { + || info.strIPV6FirDns != firstDnsEdit->text() + || info.strIPV6SecDns != secondDnsEdit->text()) { qDebug() << "ipv6 info changed"; QStringList dnsList; - dnsList.clear(); - for (QHostAddress str: ipv6dnsList) { - if (!dnsList.contains(str.toString())) { - dnsList << str.toString(); + dnsList.empty(); + if (!firstDnsEdit->text().isEmpty()) { + dnsList << firstDnsEdit->text(); + if (!secondDnsEdit->text().isEmpty()) { + dnsList << secondDnsEdit->text(); } } @@ -117,11 +120,15 @@ void Ipv6Page::initUI() { ipv6AddressEdit = new LineEdit(this); lengthEdit = new LineEdit(this); gateWayEdit = new LineEdit(this); + firstDnsEdit = new LineEdit(this); + secondDnsEdit = new LineEdit(this); m_configLabel = new QLabel(this); m_addressLabel = new QLabel(this); m_subnetLabel = new QLabel(this); m_gateWayLabel = new QLabel(this); + m_dnsLabel = new QLabel(this); + m_secDnsLabel = new QLabel(this); m_configEmptyLabel = new QLabel(this); m_configEmptyLabel->setFixedHeight(LABEL_HEIGHT); @@ -138,10 +145,16 @@ void Ipv6Page::initUI() { m_subnetEmptyLabel = new QLabel(this); m_subnetEmptyLabel->setFixedHeight(LABEL_HEIGHT); + m_firstDnsEmptyLabel = new QLabel(this); + m_firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT); + + m_configLabel->setText(tr("IPv6Config")); m_addressLabel->setText(tr("Address")); m_subnetLabel->setText(tr("Subnet prefix Length")); m_gateWayLabel->setText(tr("Default Gateway")); + m_dnsLabel->setText(tr("Prefs DNS")); + m_secDnsLabel->setText(tr("Alternative DNS")); m_statusLabel = new QLabel(this); m_statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); @@ -168,9 +181,6 @@ void Ipv6Page::initUI() { gateWayLayout->addWidget(gateWayEdit); gateWayLayout->addWidget(m_gateWayHintLabel); - QRegExp ipv6_rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); - m_dnsWidget = new MultipleDnsWidget(ipv6_rx, this); - m_detailLayout = new QFormLayout(this); m_detailLayout->setContentsMargins(0, 0, 0, 0); m_detailLayout->setVerticalSpacing(0); @@ -180,13 +190,18 @@ void Ipv6Page::initUI() { m_detailLayout->addRow(m_subnetLabel,lengthEdit); m_detailLayout->addRow(m_subnetEmptyLabel); m_detailLayout->addRow(m_gateWayLabel,gateWayWidget); - m_detailLayout->addRow(m_dnsWidget); + m_detailLayout->addRow(m_dnsLabel,firstDnsEdit); + m_detailLayout->addRow(m_firstDnsEmptyLabel); + m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit); ipv6ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)" ipv6ConfigCombox->addItem(tr("Manual")); //"手动" + QRegExp ipv6_rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); ipv6AddressEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); gateWayEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); + firstDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); + secondDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); QRegExp prefix_rx("\\b(?:(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\.){3}(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\b"); lengthEdit->setValidator(new QRegExpValidator(prefix_rx,this)); @@ -210,6 +225,8 @@ void Ipv6Page::initComponent() { connect(ipv6AddressEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(lengthEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); } void Ipv6Page::configChanged(int index) { @@ -227,6 +244,8 @@ void Ipv6Page::setControlEnabled(bool check) ipv6AddressEdit->clear(); lengthEdit->clear(); gateWayEdit->clear(); + firstDnsEdit->clear(); + secondDnsEdit->clear(); ipv6AddressEdit->setPlaceholderText(" "); lengthEdit->setPlaceholderText(" "); @@ -234,13 +253,13 @@ void Ipv6Page::setControlEnabled(bool check) } else { ipv6AddressEdit->setPlaceholderText(tr("Required")); //必填 lengthEdit->setPlaceholderText(tr("Required")); //必填 - gateWayEdit->setPlaceholderText(tr("Required")); //必填 } ipv6AddressEdit->setEnabled(check); lengthEdit->setEnabled(check); gateWayEdit->setEnabled(check); - m_dnsWidget->setEditEnabled(check); + firstDnsEdit->setEnabled(check); + secondDnsEdit->setEnabled(check); } void Ipv6Page::setEnableOfSaveBtn() @@ -293,8 +312,23 @@ bool Ipv6Page::checkConnectBtnIsEnabled() return false; } - if (gateWayEdit->text().isEmpty() || !getIpv6EditState(gateWayEdit->text())) { - qDebug() << "ipv6 gateway empty or invalid"; +// if (gateWayEdit->text().isEmpty() || !getIpv6EditState(gateWayEdit->text())) { +// qDebug() << "ipv6 gateway empty or invalid"; +// return false; +// } + + if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) { + qDebug() << "ipv6 dns sort invalid"; + return false; + } + + if (!getIpv6EditState(firstDnsEdit->text())) { + qDebug() << "ipv6 first dns invalid"; + return false; + } + + if (!getIpv6EditState(secondDnsEdit->text())) { + qDebug() << "ipv6 second dns invalid"; return false; } } diff --git a/src/frontend/netdetails/ipv6page.h b/src/frontend/netdetails/ipv6page.h index 8097b6f5..a36265df 100644 --- a/src/frontend/netdetails/ipv6page.h +++ b/src/frontend/netdetails/ipv6page.h @@ -33,7 +33,6 @@ //#include "kylinconnectsetting.h" #include "coninfo.h" -#include "multiplednswidget.h" class Ipv6Page : public QFrame { @@ -43,9 +42,8 @@ public: void setIpv6Config(KyIpConfigType ipv6Config); void setIpv6(const QString &ipv4); void setIpv6Perfix(const int &ipv6Perfix); -// void setIpv6FirDns(const QString &ipv6FirDns); -// void setIpv6SecDns(const QString &ipv6SecDns); - void setMulDns(const QList &dns); + void setIpv6FirDns(const QString &ipv6FirDns); + void setIpv6SecDns(const QString &ipv6SecDns); void setGateWay(const QString &gateWay); bool checkIsChanged(const ConInfo info, KyConnectSetting &setting); @@ -56,28 +54,27 @@ public: void stopLoading(); void showIpv6AddressConflict(bool isConflict); -private: +public: QComboBox *ipv6ConfigCombox; LineEdit *ipv6AddressEdit; LineEdit *lengthEdit; LineEdit *gateWayEdit; -// LineEdit *firstDnsEdit; -// LineEdit *secondDnsEdit; - + LineEdit *firstDnsEdit; + LineEdit *secondDnsEdit; +private: QFormLayout *m_detailLayout; QLabel *m_configLabel; QLabel *m_addressLabel; QLabel *m_subnetLabel; QLabel *m_gateWayLabel; -// QLabel *m_dnsLabel; -// QLabel *m_secDnsLabel; + QLabel *m_dnsLabel; + QLabel *m_secDnsLabel; QLabel *m_configEmptyLabel; QLabel *m_addressHintLabel; QLabel *m_subnetEmptyLabel; QLabel *m_gateWayHintLabel; - - MultipleDnsWidget *m_dnsWidget = nullptr; + QLabel *m_firstDnsEmptyLabel; QLabel *m_statusLabel = nullptr; QList m_loadIcons; @@ -86,7 +83,6 @@ private: QLabel *m_iconLabel; QLabel *m_textLabel; - private: void initUI(); void initComponent(); diff --git a/src/frontend/netdetails/joinhiddenwifipage.cpp b/src/frontend/netdetails/joinhiddenwifipage.cpp index 9363dd45..4581e84f 100644 --- a/src/frontend/netdetails/joinhiddenwifipage.cpp +++ b/src/frontend/netdetails/joinhiddenwifipage.cpp @@ -33,12 +33,13 @@ #define BOTTOM_LAYOUT_MARGINS 24, 24, 24, 24 #define LAYOUT_SPACING 16 #define LABEL_MIN_WIDTH 146 +#define LABEL_MAX_WIDTH 434 #define MAX_NAME_LENGTH 32 -#define SCROAREA_WIDTH 480 +#define PSK_SCRO_HEIGHT 182 +#define PEAP_SCRO_HEIGHT 340 +#define TLS_SCRO_HEIGHT 560 #define MEDIUM_WEIGHT_VALUE 57 -bool LaunchApp(QString desktopFile); - JoinHiddenWiFiPage::JoinHiddenWiFiPage(QString devName, KDialog *parent) :m_devName(devName), KDialog(parent) @@ -48,6 +49,7 @@ JoinHiddenWiFiPage::JoinHiddenWiFiPage(QString devName, KDialog *parent) initUI(); initComponent(); + setFixedWidth(WINDOW_WIDTH); setAttribute(Qt::WA_DeleteOnClose); setJoinBtnEnable(); @@ -58,19 +60,9 @@ JoinHiddenWiFiPage::~JoinHiddenWiFiPage() } -void JoinHiddenWiFiPage::setJoinHiddenWiFiShowed(bool state) -{ - m_joinHiddenWiFiShowed = state; -} - void JoinHiddenWiFiPage::closeEvent(QCloseEvent *event) { Q_EMIT this->hiddenWiFiPageClose(m_devName); - - if (m_joinHiddenWiFiShowed) { - LaunchApp("ukui-control-center.desktop"); - m_joinHiddenWiFiShowed = false; - } return QWidget::closeEvent(event); } @@ -82,7 +74,8 @@ void JoinHiddenWiFiPage::initUI() m_secuWidget = new SecurityPage(false, this); m_secuWidget->setSecurity(KySecuType::WPA_AND_WPA2_PERSONAL); - m_descriptionLabel = new QLabel(this); + m_descriptionLabel = new FixLabel(this); + m_descriptionLabel->setFixedWidth(LABEL_MAX_WIDTH); m_nameLabel = new FixLabel(this); m_nameLabel->setFixedWidth(LABEL_MIN_WIDTH); m_nameEdit =new LineEdit(this); @@ -128,11 +121,8 @@ void JoinHiddenWiFiPage::initUI() m_centerVBoxLayout->addWidget(ssidWidget); m_centerVBoxLayout->addSpacing(LAYOUT_SPACING); m_centerVBoxLayout->addWidget(m_secuWidget); - - m_centerWidget->setFixedWidth(SCROAREA_WIDTH); - m_hiddenWifiScrollArea->setFixedWidth(SCROAREA_WIDTH); + m_centerVBoxLayout->addStretch(); m_hiddenWifiScrollArea->setWidget(m_centerWidget); - m_hiddenWifiScrollArea->setWidgetResizable(true); //底部按钮 m_bottomLayout = new QHBoxLayout(m_bottomWidget); @@ -144,7 +134,7 @@ void JoinHiddenWiFiPage::initUI() m_bottomLayout->addWidget(m_joinBtn); //请输入您想要加入网络的名称和安全类型 - m_descriptionLabel->setText(tr("Please enter the network name and security type")); + m_descriptionLabel->setLabelText(tr("Please enter the network name and security type")); QFont font = m_descriptionLabel->font(); font.setWeight(MEDIUM_WEIGHT_VALUE); m_descriptionLabel->setFont(font); @@ -159,8 +149,9 @@ void JoinHiddenWiFiPage::initUI() this->setWindowTitle(tr("Find and Join Wi-Fi")); this->setWindowIcon(QIcon::fromTheme("kylin-network")); - this->setFixedWidth(WINDOW_WIDTH); + this->setFixedHeight(MIN_WINDOW_HEIGHT); + onPaletteChanged(); } void JoinHiddenWiFiPage::initComponent() @@ -245,6 +236,7 @@ void JoinHiddenWiFiPage::onSecuTypeChanged(const KySecuType &type) { if (type != KySecuType::WPA_AND_WPA2_ENTERPRISE) { this->setFixedHeight(MIN_WINDOW_HEIGHT); + m_centerWidget->setFixedSize(WINDOW_WIDTH, PSK_SCRO_HEIGHT); } } @@ -252,8 +244,10 @@ void JoinHiddenWiFiPage::onEapTypeChanged(const KyEapMethodType &type) { if (type == KyEapMethodType::TLS) { this->setFixedHeight(TLS_WINDOW_HEIGHT); + m_centerWidget->setFixedSize(WINDOW_WIDTH, TLS_SCRO_HEIGHT); } else if (type == KyEapMethodType::PEAP || type == KyEapMethodType::TTLS) { this->setFixedHeight(PEAP_WINDOW_HEIGHT); + m_centerWidget->setFixedSize(WINDOW_WIDTH, PEAP_SCRO_HEIGHT); } } @@ -262,14 +256,14 @@ void JoinHiddenWiFiPage::onPaletteChanged() QPalette pal = qApp->palette(); QGSettings * styleGsettings = nullptr; -// const QByteArray style_id(THEME_SCHAME); -// if (QGSettings::isSchemaInstalled(style_id)) { -// styleGsettings = new QGSettings(style_id); -// QString currentTheme = styleGsettings->get(COLOR_THEME).toString(); -// if(currentTheme == "ukui-default"){ -// pal = lightPalette(this); -// } -// } + const QByteArray style_id(THEME_SCHAME); + if (QGSettings::isSchemaInstalled(style_id)) { + styleGsettings = new QGSettings(style_id); + QString currentTheme = styleGsettings->get(COLOR_THEME).toString(); + if(currentTheme == "ukui-default"){ + pal = lightPalette(this); + } + } this->setPalette(pal); setFramePalette(m_secuWidget, pal); setFramePalette(m_hiddenWifiScrollArea, pal); @@ -279,3 +273,4 @@ void JoinHiddenWiFiPage::onPaletteChanged() styleGsettings = nullptr; } } + diff --git a/src/frontend/netdetails/joinhiddenwifipage.h b/src/frontend/netdetails/joinhiddenwifipage.h index bea8be80..1a9806d1 100644 --- a/src/frontend/netdetails/joinhiddenwifipage.h +++ b/src/frontend/netdetails/joinhiddenwifipage.h @@ -43,8 +43,6 @@ public: JoinHiddenWiFiPage(QString devName, KDialog *parent = nullptr); ~JoinHiddenWiFiPage(); - void setJoinHiddenWiFiShowed(bool state); - protected: void closeEvent(QCloseEvent *event); @@ -63,7 +61,7 @@ private: QWidget *m_bottomWidget; SecurityPage *m_secuWidget; - QLabel *m_descriptionLabel; + FixLabel *m_descriptionLabel; FixLabel *m_nameLabel; LineEdit *m_nameEdit; @@ -80,7 +78,6 @@ private: bool m_isJoinBtnEnable = false; bool m_isSecuOk = false; - bool m_joinHiddenWiFiShowed = false; ConInfo m_info; private Q_SLOTS: diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index fa12a26b..9d727c8f 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -21,8 +21,6 @@ #include "backend/kylinipv4arping.h" #include "backend/kylinipv6arping.h" //#include "xatom/xatom-helper.h" -#include "networkmodeconfig.h" - #define THEME_SCHAME "org.ukui.style" #define COLOR_THEME "styleName" @@ -41,6 +39,7 @@ #define CENTER_LAYOUT_MARGINS 24,0,0,0 #define BOTTOM_LAYOUT_MARGINS 24,0,24,0 #define BOTTOM_LAYOUT_SPACING 16 +#define PAGE_LAYOUT_SPACING 1 #define DETAIL_PAGE_NUM 0 #define IPV4_PAGE_NUM 1 #define IPV6_PAGE_NUM 2 @@ -48,36 +47,15 @@ #define CONFIG_PAGE_NUM 4 #define CREATE_NET_PAGE_NUM 5 #define PAGE_MIN_HEIGHT 40 -#define PAGE_WIDTH 472 #define LAN_TAB_WIDTH 180 #define WLAN_TAB_WIDTH 240 -#define SCRO_WIDTH 496 -#define SCRO_HEIGHT 600 +#define SCRO_WIDTH 472 #define PEAP_SCRO_HEIGHT 300 #define TLS_SCRO_HEIGHT 480 #define MAX_TAB_TEXT_LENGTH 44 -#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" -#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" -#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" //extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); -bool LaunchApp(QString desktopFile) -{ - QDBusInterface m_appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, - KYLIN_APP_MANAGER_PATH, - KYLIN_APP_MANAGER_INTERFACE, - QDBusConnection::sessionBus());//局部变量 - - if (!m_appManagerDbusInterface.isValid()) { - qWarning()<<"m_appManagerDbusInterface init error"; - return false; - } else { - QDBusReply reply =m_appManagerDbusInterface.call("LaunchApp",desktopFile); - return reply; - } -} - void NetDetail::showDesktopNotify(const QString &message, QString soundName) { QDBusInterface iface("org.freedesktop.Notifications", @@ -189,7 +167,7 @@ NetDetail::NetDetail(QString interface, QString name, QString uuid, bool isActiv getConInfo(m_info); startObjectThread(); pagePadding(name,isWlan); - + setSecuPageHeight(); connect(qApp, &QApplication::paletteChanged, this, &NetDetail::onPaletteChanged); isCreateOk = !(m_isCreateNet && !isWlan); @@ -218,16 +196,16 @@ void NetDetail::onPaletteChanged() { QPalette pal = qApp->palette(); -// QGSettings * styleGsettings = nullptr; -// const QByteArray style_id(THEME_SCHAME); -// if (QGSettings::isSchemaInstalled(style_id)) { -// styleGsettings = new QGSettings(style_id); -// QString currentTheme = styleGsettings->get(COLOR_THEME).toString(); -// if(currentTheme == "ukui-default"){ -// pal = lightPalette(this); -// } -// } - + QGSettings * styleGsettings = nullptr; + const QByteArray style_id(THEME_SCHAME); + if (QGSettings::isSchemaInstalled(style_id)) { + styleGsettings = new QGSettings(style_id); + QString currentTheme = styleGsettings->get(COLOR_THEME).toString(); + if(currentTheme == "ukui-default"){ + pal = lightPalette(this); + } + } + pal.setColor(QPalette::Background, pal.base().color()); this->setPalette(pal); setFramePalette(detailPage, pal); @@ -238,18 +216,15 @@ void NetDetail::onPaletteChanged() QToolTip::setPalette(pal); QPalette listwidget_pal(detailPage->m_listWidget->palette()); - listwidget_pal.setColor(QPalette::Base, this->palette().base().color()); - listwidget_pal.setColor(QPalette::AlternateBase, this->palette().alternateBase().color()); + listwidget_pal.setColor(QPalette::Base, pal.base().color()); + listwidget_pal.setColor(QPalette::AlternateBase, pal.alternateBase().color()); detailPage->m_listWidget->setAlternatingRowColors(true); detailPage->m_listWidget->setPalette(listwidget_pal); -// if (styleGsettings != nullptr) { -// delete styleGsettings; -// styleGsettings = nullptr; -// } - - QColor colorTabBar = pal.color(QPalette::Disabled, QPalette::Highlight); - m_netTabBar->setBackgroundColor(colorTabBar); + if (styleGsettings != nullptr) { + delete styleGsettings; + styleGsettings = nullptr; + } } void NetDetail::currentRowChangeSlot(int row) @@ -271,24 +246,19 @@ void NetDetail::currentRowChangeSlot(int row) void NetDetail::paintEvent(QPaintEvent *event) { - QPalette pal = qApp->palette(); - QPainter painter(this); - painter.setBrush(pal.color(QPalette::Base)); - painter.drawRect(this->rect()); - painter.fillRect(rect(), QBrush(pal.color(QPalette::Base))); +// QPalette pal = qApp->palette(); +// QPainter painter(this); +// painter.setBrush(pal.color(QPalette::Base)); +// painter.drawRect(this->rect()); +// painter.fillRect(rect(), QBrush(pal.color(QPalette::Base))); return QWidget::paintEvent(event); } void NetDetail::closeEvent(QCloseEvent *event) { - Q_EMIT this->detailPageClose(false); + Q_EMIT this->detailPageClose(m_deviceName, m_name, m_uuid); Q_EMIT this->createPageClose(m_deviceName); - - if (m_hasDetailPageShowed) { - LaunchApp("ukui-control-center.desktop"); - m_hasDetailPageShowed = false; - } return QWidget::closeEvent(event); } @@ -311,79 +281,69 @@ void NetDetail::initUI() { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0,9,0,24); - mainLayout->setSpacing(22); - - this->installEventFilter(this); - pageFrame = new QFrame(this); - centerWidget = new QWidget(this); - bottomWidget = new QWidget(this); + mainLayout->setSpacing(24); detailPage = new DetailPage(isWlan, m_name.isEmpty(), this); + ipv4Page = new Ipv4Page(this); ipv6Page = new Ipv6Page(this); securityPage = new SecurityPage(this); createNetPage = new CreatNetPage(this); configPage = new ConfigPage(this); - detailPage->setFixedWidth(PAGE_WIDTH); - ipv4Page->setFixedWidth(PAGE_WIDTH); - ipv6Page->setFixedWidth(PAGE_WIDTH); - securityPage->setFixedWidth(PAGE_WIDTH); - createNetPage->setFixedWidth(PAGE_WIDTH); - configPage->setFixedWidth(PAGE_WIDTH); + this->installEventFilter(this); + centerWidget = new QWidget(this); + bottomWidget = new QWidget(this); - // 滚动区域 - m_secuPageScrollArea = new QScrollArea(centerWidget); - m_secuPageScrollArea->setFixedWidth(SCRO_WIDTH); + m_secuPageScrollArea = new QScrollArea(this); m_secuPageScrollArea->setFrameShape(QFrame::NoFrame); m_secuPageScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_secuPageScrollArea->setWidget(securityPage); - m_secuPageScrollArea->setWidgetResizable(true); - - m_ipv4ScrollArea = new QScrollArea(centerWidget); - m_ipv4ScrollArea->setFixedWidth(SCRO_WIDTH); - m_ipv4ScrollArea->setFrameShape(QFrame::NoFrame); - m_ipv4ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_ipv4ScrollArea->setWidget(ipv4Page); - m_ipv4ScrollArea->setWidgetResizable(true); - - m_ipv6ScrollArea = new QScrollArea(centerWidget); - m_ipv6ScrollArea->setFixedWidth(SCRO_WIDTH); - m_ipv6ScrollArea->setFrameShape(QFrame::NoFrame); - m_ipv6ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_ipv6ScrollArea->setWidget(ipv6Page); - m_ipv6ScrollArea->setWidgetResizable(true); - QPalette pal = m_secuPageScrollArea->palette(); - pal.setBrush(QPalette::Window, Qt::transparent); + pal.setBrush(QPalette::Base, QColor(0,0,0,0)); m_secuPageScrollArea->setPalette(pal); - m_ipv4ScrollArea->setPalette(pal); - m_ipv6ScrollArea->setPalette(pal); + + detailPage->setFixedWidth(SCRO_WIDTH); + ipv4Page->setFixedWidth(SCRO_WIDTH); + ipv6Page->setFixedWidth(SCRO_WIDTH); + createNetPage->setFixedWidth(SCRO_WIDTH); + configPage->setFixedWidth(SCRO_WIDTH); stackWidget = new QStackedWidget(centerWidget); stackWidget->addWidget(detailPage); - stackWidget->addWidget(m_ipv4ScrollArea); - stackWidget->addWidget(m_ipv6ScrollArea); + stackWidget->addWidget(ipv4Page); + stackWidget->addWidget(ipv6Page); stackWidget->addWidget(m_secuPageScrollArea); stackWidget->addWidget(configPage); stackWidget->addWidget(createNetPage); + mainLayout->addWidget(centerWidget); + mainLayout->addWidget(bottomWidget); + + bottomWidget->setMinimumHeight(PAGE_MIN_HEIGHT); + + pageFrame = new QFrame(this); + QHBoxLayout *pageLayout = new QHBoxLayout(pageFrame); +// pageLayout->setSpacing(PAGE_LAYOUT_SPACING); + // TabBar + onPaletteChanged(); + m_networkMode = NetworkModeType(NetworkModeConfig::getInstance()->getNetworkModeConfig(m_uuid)); m_netTabBar = new NetTabBar(this); m_netTabBar->addTab(tr("Detail")); //详情 m_netTabBar->addTab(tr("IPv4"));//Ipv4 m_netTabBar->addTab(tr("IPv6"));//Ipv6 if (isWlan) { m_netTabBar->addTab(tr("Security"));//安全 - if (isActive) { + if (isActive && m_networkMode != DBUS_INVAILD && m_networkMode != NO_CONFIG) { m_netTabBar->addTab(tr("Config")); //配置 m_netTabBar->setFixedWidth(WLAN_TAB_WIDTH + TAB_WIDTH); } else { m_netTabBar->setFixedWidth(WLAN_TAB_WIDTH); } } else { - if (isActive) { + if (isActive && m_networkMode != DBUS_INVAILD && m_networkMode != NO_CONFIG) { m_netTabBar->addTab(tr("Config")); //配置 m_netTabBar->setFixedWidth(LAN_TAB_WIDTH + TAB_WIDTH); } else { @@ -391,26 +351,27 @@ void NetDetail::initUI() } } + pageLayout->addWidget(m_netTabBar, Qt::AlignCenter); + pageLayout->addSpacing(24); + // TabBar关联选项卡页面 connect(m_netTabBar, SIGNAL(currentChanged(int)), this, SLOT(currentRowChangeSlot(int))); setNetTabToolTip(); confimBtn = new QPushButton(this); confimBtn->setText(tr("Confirm")); + cancelBtn = new QPushButton(this); cancelBtn->setText(tr("Cancel")); - forgetBtn = new QPushButton(this); - QHBoxLayout *pageLayout = new QHBoxLayout(pageFrame); - pageLayout->setContentsMargins(0, 0, 0, 0); - pageLayout->addWidget(m_netTabBar, Qt::AlignCenter); + forgetBtn = new QPushButton(this); QVBoxLayout *centerlayout = new QVBoxLayout(centerWidget); centerlayout->setContentsMargins(CENTER_LAYOUT_MARGINS); // 右边距为0,为安全页滚动区域留出空间 + centerlayout->addWidget(pageFrame); + centerlayout->addSpacing(4); centerlayout->addWidget(stackWidget); -// centerWidget->setStyleSheet("QWidget{border:1px solid rgba(255,0,0,1);}");//测试用, 画出边界线 - QHBoxLayout *bottomLayout = new QHBoxLayout(bottomWidget); bottomLayout->setContentsMargins(BOTTOM_LAYOUT_MARGINS); bottomLayout->setSpacing(BOTTOM_LAYOUT_SPACING); @@ -418,14 +379,11 @@ void NetDetail::initUI() bottomLayout->addStretch(); bottomLayout->addWidget(cancelBtn); bottomLayout->addWidget(confimBtn); - bottomWidget->setMinimumHeight(PAGE_MIN_HEIGHT); - - mainLayout->addWidget(pageFrame); - mainLayout->addWidget(centerWidget); - mainLayout->addWidget(bottomWidget); +// QPalette pal(this->palette()); +// pal.setColor(QPalette::Background, qApp->palette().base().color()); this->setAutoFillBackground(true); - onPaletteChanged(); +// this->setPalette(pal); } void NetDetail::loadPage() @@ -434,13 +392,12 @@ void NetDetail::loadPage() if (m_isCreateNet && !isWlan) { pageFrame->hide(); stackWidget->setCurrentIndex(CREATE_NET_PAGE_NUM); - this->setWindowTitle(tr("Add Lan Connect")); - setDetailPageShowed(true); + this->setWindowTitle(tr("Add LAN Connect")); } else { stackWidget->setCurrentIndex(DETAIL_PAGE_NUM); this->setWindowTitle(m_name); if (isWlan && m_name.isEmpty()) { - this->setWindowTitle(tr("connect hiddin wlan")); + this->setWindowTitle(tr("Connect Hidden WLAN")); } } } @@ -489,6 +446,13 @@ void NetDetail::initComponent() setConfirmEnable(); }); + connect(securityPage, &SecurityPage::secuTypeChanged, this, [=]() { + setSecuPageHeight(); + }); + connect(securityPage, &SecurityPage::eapTypeChanged, this, [=]() { + setSecuPageHeight(); + }); + const QByteArray id(THEME_SCHAME); if(QGSettings::isSchemaInstalled(id)){ QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); @@ -527,9 +491,8 @@ void NetDetail::pagePadding(QString netName, bool isWlan) ipv4Page->setIpv4Config(m_info.ipv4ConfigType); ipv4Page->setIpv4(m_info.strIPV4Address); ipv4Page->setNetMask(m_info.strIPV4NetMask); -// ipv4Page->setIpv4FirDns(m_info.strIPV4FirDns); -// ipv4Page->setIpv4SecDns(m_info.strIPV4SecDns); - ipv4Page->setMulDns(m_info.ipv4DnsList); + ipv4Page->setIpv4FirDns(m_info.strIPV4FirDns); + ipv4Page->setIpv4SecDns(m_info.strIPV4SecDns); ipv4Page->setGateWay(m_info.strIPV4GateWay); } else { ipv4Page->setIpv4Config(m_info.ipv4ConfigType); @@ -540,9 +503,8 @@ void NetDetail::pagePadding(QString netName, bool isWlan) ipv6Page->setIpv6Config(m_info.ipv6ConfigType); ipv6Page->setIpv6(m_info.strIPV6Address); ipv6Page->setIpv6Perfix(m_info.iIPV6Prefix); -// ipv6Page->setIpv6FirDns(m_info.strIPV6FirDns); -// ipv6Page->setIpv6SecDns(m_info.strIPV6SecDns); - ipv6Page->setMulDns(m_info.ipv6DnsList); + ipv6Page->setIpv6FirDns(m_info.strIPV6FirDns); + ipv6Page->setIpv6SecDns(m_info.strIPV6SecDns); ipv6Page->setGateWay(m_info.strIPV6GateWay); } else { ipv6Page->setIpv6Config(m_info.ipv6ConfigType); @@ -564,8 +526,8 @@ void NetDetail::pagePadding(QString netName, bool isWlan) } //配置页面 - if (isActive) { - configPage->setConfigState(NetworkModeConfig::getInstance()->getNetworkModeConfig(m_uuid)); + if (isActive && m_networkMode != DBUS_INVAILD && m_networkMode != NO_CONFIG) { + configPage->setConfigState(m_networkMode); } } @@ -689,16 +651,22 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived) kyConnectResourse->getConnectionSetting(m_uuid,connetSetting); connetSetting.dumpInfo(); -// conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType; + conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType; conInfo.ipv6ConfigType = connetSetting.m_ipv6ConfigIpType; conInfo.isAutoConnect = connetSetting.m_isAutoConnect; - //openkylin从第三方库读取有问题 改为ipv4信息直接通过dbus获取 - KyConnectItem* item = kyConnectResourse->getConnectionItemByUuidWithoutActivateChecking(m_uuid); - if (item == nullptr) { - conInfo.ipv4ConfigType = CONFIG_IP_DHCP; - } else { - getIpv4Info(item->m_connectPath, conInfo); + if (connetSetting.m_ipv4ConfigIpType == CONFIG_IP_MANUAL) { + if (connetSetting.m_ipv4Address.size() > 0) { + conInfo.strIPV4Address = connetSetting.m_ipv4Address.at(0).ip().toString(); + conInfo.strIPV4NetMask = connetSetting.m_ipv4Address.at(0).netmask().toString(); + conInfo.strIPV4GateWay = connetSetting.m_ipv4Address.at(0).gateway().toString(); + } + if (connetSetting.m_ipv4Dns.size() == 1) { + conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString(); + } else if (connetSetting.m_ipv4Dns.size() > 1) { + conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString(); + conInfo.strIPV4SecDns = connetSetting.m_ipv4Dns.at(1).toString(); + } } if (connetSetting.m_ipv6ConfigIpType == CONFIG_IP_MANUAL) { @@ -707,29 +675,19 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived) conInfo.iIPV6Prefix = ipv6Page->getPerfixLength(connetSetting.m_ipv6Address.at(0).netmask().toString()); conInfo.strIPV6GateWay = connetSetting.m_ipv6Address.at(0).gateway().toString(); } -#if 0 + if (connetSetting.m_ipv6Dns.size() == 1) { conInfo.strIPV6FirDns = connetSetting.m_ipv6Dns.at(0).toString(); } else if (connetSetting.m_ipv4Dns.size() > 1) { conInfo.strIPV6FirDns = connetSetting.m_ipv6Dns.at(0).toString(); conInfo.strIPV6SecDns = connetSetting.m_ipv6Dns.at(1).toString(); } -#endif - - conInfo.ipv6DnsList = connetSetting.m_ipv6Dns; } if (!bActived) { conInfo.strDynamicIpv4 = conInfo.strIPV4Address.isEmpty() ? tr("Auto") : conInfo.strIPV4Address; conInfo.strDynamicIpv6 = conInfo.strIPV6Address.isEmpty() ? tr("Auto") : conInfo.strIPV6Address; - QString dns(" "); - for (int i = 0; i < conInfo.ipv4DnsList.size(); ++i) { - dns.append(conInfo.ipv4DnsList.at(i).toString()); - if (i != conInfo.ipv4DnsList.size()-1) { - dns.append(" "); - } - } - conInfo.strDynamicIpv4Dns = dns.isEmpty() ? tr("Auto") : dns; + conInfo.strDynamicIpv4Dns = conInfo.strIPV4FirDns.isEmpty() ? tr("Auto") : conInfo.strIPV4FirDns; } } @@ -769,6 +727,22 @@ void NetDetail::initSecuData() } } +void NetDetail::setSecuPageHeight() +{ + KySecuType secuType; + KyEapMethodType eapType; + securityPage->getSecuType(secuType, eapType); + if (secuType == WPA_AND_WPA2_ENTERPRISE) { + if (eapType == TLS) { + securityPage->setFixedSize(SCRO_WIDTH, TLS_SCRO_HEIGHT); + } else { + securityPage->setFixedSize(SCRO_WIDTH, PEAP_SCRO_HEIGHT); + } + } else { + securityPage->setFixedSize(SCRO_WIDTH, PEAP_SCRO_HEIGHT); + } +} + void NetDetail::initTlsInfo(ConInfo &conInfo) { m_resource->getEnterPriseInfoTls(m_uuid, conInfo.tlsInfo); @@ -1087,7 +1061,7 @@ bool NetDetail::updateConnect() } } - if (configPage != nullptr) { + if (m_networkMode != DBUS_INVAILD && m_networkMode != NO_CONFIG) { int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(m_uuid); bool configPageChange = configPage->checkIsChanged(configType); int currentConfigType = configPage->getConfigState(); @@ -1144,11 +1118,6 @@ bool NetDetail::eventFilter(QObject *w, QEvent *event) return QWidget::eventFilter(w, event); } -void NetDetail::setDetailPageShowed(bool state) -{ - m_hasDetailPageShowed = state; -} - void NetDetail::setNetTabToolTip() { int tabCount = m_netTabBar->count(); @@ -1166,26 +1135,7 @@ void NetDetail::setNetTabToolTip() NetTabBar::NetTabBar(QWidget *parent) :KTabBar(KTabBarStyle::SegmentDark, parent) { - //模式切换 - QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), - QString("/"), - QString("com.kylin.statusmanager.interface"), - QString("mode_change_signal"), this, SLOT(onModeChanged(bool))); - //模式获取 - QDBusInterface interface(QString("com.kylin.statusmanager.interface"), - QString("/"), - QString("com.kylin.statusmanager.interface"), - QDBusConnection::sessionBus()); - if(!interface.isValid()) { - this->setFixedHeight(TAB_HEIGHT); - return; - } - QDBusReply reply = interface.call("get_current_tabletmode"); - if (!reply.isValid()) { - this->setFixedHeight(TAB_HEIGHT); - return; - } - onModeChanged(reply.value()); + } NetTabBar::~NetTabBar() @@ -1195,27 +1145,15 @@ NetTabBar::~NetTabBar() QSize NetTabBar::sizeHint() const { - QSize size = KTabBar::sizeHint(); - size.setWidth(TAB_WIDTH); - return size; + return QSize(TAB_WIDTH, TAB_HEIGHT); } QSize NetTabBar::minimumTabSizeHint(int index) const { Q_UNUSED(index) - QSize size = KTabBar::minimumTabSizeHint(index); - size.setWidth(TAB_WIDTH); - return size; + return QSize(TAB_WIDTH, TAB_HEIGHT); } -void NetTabBar::onModeChanged(bool mode) -{ - if (mode) { - this->setFixedHeight(TAB_HEIGHT_TABLET); // 平板模式 - } else { - this->setFixedHeight(TAB_HEIGHT); // PC模式 - } -} ThreadObject::ThreadObject(QString deviceName, QObject *parent) :m_devName(deviceName), QObject(parent) @@ -1242,6 +1180,24 @@ void ThreadObject::checkIpv4ConflictThread(const QString &ipv4Address) KyIpv4Arping* ipv4Arping = new KyIpv4Arping(m_devName, ipv4Address); if (ipv4Arping->ipv4ConflictCheck() >= 0) { isConflict = ipv4Arping->ipv4IsConflict(); + if (isConflict) { + QString mac = ipv4Arping->getMacAddress(); + qDebug() << "conflict mac" << mac; + KyNetworkDeviceResourse resource; + QStringList devList,devList1,devList2; + resource.getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, devList1); + resource.getNetworkDeviceList(NetworkManager::Device::Type::Wifi, devList2); + devList << devList1 << devList2; + for(int i = 0; i < devList.size(); ++i){ + QString hardAddress; + int band; + resource.getHardwareInfo(devList.at(i), hardAddress, band); + if (hardAddress == mac) { + qDebug() << "conflict local card" << devList.at(i); + isConflict = false; + } + } + } } else { qWarning() << "checkIpv4Conflict internal error"; } @@ -1258,7 +1214,6 @@ void ThreadObject::checkIpv6ConflictThread(const QString &ipv6Address) } bool isConflict = false; KyIpv6Arping* ipv6rping = new KyIpv6Arping(m_devName, ipv6Address); - if (ipv6rping->ipv6ConflictCheck() >= 0) { isConflict = ipv6rping->ipv6IsConflict(); } else { @@ -1269,88 +1224,3 @@ void ThreadObject::checkIpv6ConflictThread(const QString &ipv6Address) ipv6rping = nullptr; Q_EMIT ipv6IsConflict(isConflict); } - -void NetDetail::getIpv4Info(QString objPath, ConInfo &conInfo) -{ - QDBusInterface m_interface("org.freedesktop.NetworkManager", - objPath, - "org.freedesktop.NetworkManager.Settings.Connection", - QDBusConnection::systemBus()); - QDBusMessage result = m_interface.call("GetSettings"); - - if (result.arguments().isEmpty()) { return; } - const QDBusArgument &dbusArg1st = result.arguments().at( 0 ).value(); - QMap> map; - dbusArg1st >> map; - - for (QString key : map.keys() ) { - QMap innerMap = map.value(key); - if (key == "ipv4") { - for (QString inner_key : innerMap.keys()) { - if (inner_key == "address-data") { - //ipv4地址 ipv4子网掩码 - const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value(); - QVector> addressVector; - - dbusArg2nd.beginArray(); - - while (!dbusArg2nd.atEnd()) { - QMap tempMap; - dbusArg2nd >> tempMap; - addressVector.append(tempMap); - } - dbusArg2nd.endArray(); - if (addressVector.size() >= 1) { - conInfo.strIPV4Address = addressVector.at(0).value("address").toString(); - conInfo.strIPV4NetMask = ipv4Page->getNetMaskText(addressVector.at(0).value("prefix").toString()); - } - } else if (inner_key == "method") { - //ipv4 method - if (innerMap.value(inner_key).toString() == "auto") - conInfo.ipv4ConfigType = CONFIG_IP_DHCP; - else { - conInfo.ipv4ConfigType = CONFIG_IP_MANUAL; - } - } else if (inner_key == "dns") { - //dns - const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value(); - QList addressVector; - - dbusArg2nd.beginArray(); - while (!dbusArg2nd.atEnd()) { - uint tempMap; - dbusArg2nd >> tempMap; - addressVector.append(tempMap); - } - dbusArg2nd.endArray(); - for (int i = 0; i < addressVector.size(); ++i) { - QString dns(inet_ntoa(*(struct in_addr *)&addressVector.at(i))); - conInfo.ipv4DnsList << QHostAddress(dns); - } - - } else if (inner_key == "gateway") { - //gateway - conInfo.strIPV4GateWay = innerMap.value(inner_key).toString(); - } - } - } - // if (key == "ipv6") { - // for (QString inner_key : innerMap.keys()) { - // if (inner_key == "address-data"){ - // const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value(); - // QMap m_map; - - // dbusArg2nd.beginArray(); - // while (!dbusArg2nd.atEnd()) { - // dbusArg2nd >> m_map;// append map to a vector here if you want to keep it - // } - // dbusArg2nd.endArray(); - - // dbusWifiIpv6 = m_map.value("address").toString(); - // } else if (inner_key == "method") { - // dbusWifiIpv6Method = innerMap.value(inner_key).toString(); - // } - // } - // } - } -} diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index 6e6b2d32..b7db854b 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -50,13 +50,12 @@ #include "tab-pages/tabpage.h" #include "kwidget.h" #include "ktabbar.h" +#include "networkmodeconfig.h" -#include using namespace kdk; #define TAB_WIDTH 60 #define TAB_HEIGHT 36 -#define TAB_HEIGHT_TABLET 48 class NetTabBar : public KTabBar { @@ -64,15 +63,10 @@ class NetTabBar : public KTabBar public: explicit NetTabBar(QWidget *parent = nullptr); ~NetTabBar(); -protected: + QSize sizeHint() const; QSize minimumTabSizeHint(int index) const; - -private Q_SLOTS: - void onModeChanged(bool mode); - }; - class ThreadObject : public QObject { Q_OBJECT @@ -105,8 +99,6 @@ public: void closeEvent(QCloseEvent *event); bool eventFilter(QObject *w, QEvent *event); - void setDetailPageShowed(bool state); - private: void initUI(); void centerToScreen(); @@ -115,6 +107,7 @@ private: void loadPage(); void pagePadding(QString netName, bool isWlan); void initSecuData(); + void setSecuPageHeight(); void initTlsInfo(ConInfo &conInfo); void initPeapInfo(ConInfo &conInfo); @@ -147,7 +140,6 @@ private: void startObjectThread(); void setNetTabToolTip(); - void getIpv4Info(QString objPath, ConInfo &conInfo); private: KyNetworkDeviceResourse *m_netDeviceResource = nullptr; KyConnectOperation* m_connectOperation = nullptr; @@ -167,8 +159,6 @@ private: QWidget * centerWidget; QWidget * bottomWidget; QScrollArea * m_secuPageScrollArea; - QScrollArea * m_ipv4ScrollArea; - QScrollArea * m_ipv6ScrollArea; QPushButton * cancelBtn; QPushButton * forgetBtn; @@ -192,11 +182,12 @@ private: bool isIpv6Ok; bool isSecuOk; bool isConfirmBtnEnable; - bool m_hasDetailPageShowed = false; + ConInfo m_info; ThreadObject *m_object; QThread *m_objectThread; + NetworkModeType m_networkMode = DBUS_INVAILD; private Q_SLOTS: void on_btnConfirm_clicked(); @@ -207,7 +198,7 @@ protected Q_SLOTS: void currentRowChangeSlot(int row); Q_SIGNALS: - void detailPageClose(bool on); + void detailPageClose(QString, QString, QString); void createPageClose(QString); void currentChanged(int); void checkCurrentIpv4Conflict(const QString &address); diff --git a/src/frontend/netdetails/netdetails.pri b/src/frontend/netdetails/netdetails.pri index f06fe245..75657d5d 100644 --- a/src/frontend/netdetails/netdetails.pri +++ b/src/frontend/netdetails/netdetails.pri @@ -10,7 +10,6 @@ HEADERS += \ $$PWD/ipv4page.h \ $$PWD/ipv6page.h \ $$PWD/joinhiddenwifipage.h \ - $$PWD/multiplednswidget.h \ $$PWD/netdetail.h \ $$PWD/securitypage.h @@ -23,6 +22,5 @@ SOURCES += \ $$PWD/ipv4page.cpp \ $$PWD/ipv6page.cpp \ $$PWD/joinhiddenwifipage.cpp \ - $$PWD/multiplednswidget.cpp \ $$PWD/netdetail.cpp \ $$PWD/securitypage.cpp diff --git a/src/frontend/netdetails/securitypage.cpp b/src/frontend/netdetails/securitypage.cpp index ddcf1d13..f4968ec2 100644 --- a/src/frontend/netdetails/securitypage.cpp +++ b/src/frontend/netdetails/securitypage.cpp @@ -25,7 +25,7 @@ #define DETAIL_MIN_LABEL_WIDTH 80 #define DETAIL_MIN_EDIT_WIDTH 390 #define MIN_LABEL_WIDTH 146 -#define MIN_EDIT_WIDTH 286 +#define MIN_EDIT_WIDTH 278 SecurityPage::SecurityPage(bool isNetDetailPage, QWidget *parent) : isDetailPage(isNetDetailPage), QFrame(parent) { @@ -223,7 +223,7 @@ void SecurityPage::initUI() //PEAP TTLS共有 eapMethodLabel->setLabelText(tr("Ineer authentication")); - userNameLabel->setText(tr("Usename")); + userNameLabel->setText(tr("Username")); userPwdLabel->setText(tr("Password")); userPwdFlagLabel->setText(tr("Ask pwd each query")); userNameEdit->setPlaceholderText(tr("Required")); @@ -467,6 +467,12 @@ void SecurityPage::getSecuType(KySecuType &secuType, KyEapMethodType &enterprise enterpriseType = (KyEapMethodType)eapTypeCombox->currentData().toInt(); } +bool SecurityPage::getAutoConnectState() +{ + bool state = m_rememberCheckBox->isChecked(); + return state; +} + bool SecurityPage::checkIsChanged(const ConInfo info) { if (info.secType != secuTypeCombox->currentData().toInt()) { diff --git a/src/frontend/netdetails/securitypage.h b/src/frontend/netdetails/securitypage.h index 294880e9..0bc2b84e 100644 --- a/src/frontend/netdetails/securitypage.h +++ b/src/frontend/netdetails/securitypage.h @@ -28,7 +28,7 @@ #include #include "coninfo.h" -#include "detailwidget.h" +#include "kylable.h" #include "kwidget.h" #include "kpasswordedit.h" @@ -54,6 +54,7 @@ public: void updateTtlsChange(KyEapMethodTtlsInfo &info); void getSecuType(KySecuType &secuType, KyEapMethodType &enterpriseType); + bool getAutoConnectState(); private: bool isDetailPage; diff --git a/src/frontend/networkmode/firewalldialog.cpp b/src/frontend/networkmode/firewalldialog.cpp index 4f02c024..749d4efb 100644 --- a/src/frontend/networkmode/firewalldialog.cpp +++ b/src/frontend/networkmode/firewalldialog.cpp @@ -19,6 +19,10 @@ */ #include "firewalldialog.h" +#include + +#define THEME_SCHAME "org.ukui.style" +#define COLOR_THEME "styleName" #define ICON_SIZE 16,16 FirewallDialog::FirewallDialog(QWidget *parent): KDialog(parent) @@ -28,6 +32,7 @@ FirewallDialog::FirewallDialog(QWidget *parent): KDialog(parent) this->setFixedSize(480, 204); setAttribute(Qt::WA_DeleteOnClose); // centerToScreen(); + connect(qApp, &QApplication::paletteChanged, this, &FirewallDialog::onPaletteChanged); } FirewallDialog::~FirewallDialog() @@ -38,29 +43,33 @@ 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_contentLabel = new FixLabel(this); + m_suggestLabel = new FixLabel(this); + m_PublicBtn = new QPushButton(this); + m_PrivateBtn = new QPushButton(this); m_dialogLayout = new QVBoxLayout(this); + m_contentLabel->setFixedWidth(405); + m_suggestLabel->setFixedWidth(405); + QWidget *contentWidget = new QWidget(this); QGridLayout *contentLayout = new QGridLayout(contentWidget); + contentLayout->setHorizontalSpacing(0); contentLayout->setContentsMargins(0, 0, 0, 0); - contentLayout->addWidget(m_iconLabel, 0, 0, Qt::AlignVCenter); + contentLayout->addWidget(m_iconLabel, 0, 0); contentLayout->addWidget(m_contentLabel, 0, 1); contentLayout->addWidget(m_suggestLabel, 1, 1); - m_iconLabel->setFixedWidth(16); + m_iconLabel->setFixedWidth(24); 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); + btnLayout->addWidget(m_PublicBtn); + btnLayout->addWidget(m_PrivateBtn); - m_dialogLayout->setContentsMargins(24, 16, 24, 24); + m_dialogLayout->setContentsMargins(22, 16, 22, 24); m_dialogLayout->setSpacing(0); m_dialogLayout->addWidget(contentWidget); m_dialogLayout->addStretch(); @@ -73,20 +82,19 @@ void FirewallDialog::initUI() font.setWeight(57); m_contentLabel->setFont(font); //是否允许此网络上的其他设备发现这台电脑? - m_contentLabel->setText(tr("Allow other devices on this network to discover this computer?")); - m_contentLabel->setWordWrap(true); + m_contentLabel->setLabelText(tr("Allow other devices on this network to discover this computer?")); //不建议在公共网络上开启此功能 - m_suggestLabel->setText(tr("It is not recommended to enable this feature on public networks")); - m_suggestLabel->setWordWrap(true); + m_suggestLabel->setLabelText(tr("It is not recommended to enable this feature on public networks")); - m_YesBtn->setText(tr("Not allowed (recommended)")); - m_NoBtn->setText(tr("Allowed")); + m_PublicBtn->setText(tr("Not allowed (recommended)")); + m_PrivateBtn->setText(tr("Allowed")); this->closeButton(); this->mainWidget()->setLayout(m_dialogLayout); + onPaletteChanged(); - connect(m_YesBtn, &QPushButton::clicked, this, &FirewallDialog::setPublicNetMode); - connect(m_NoBtn, &QPushButton::clicked, this, &FirewallDialog::setPrivateNetMode); + connect(m_PublicBtn, &QPushButton::clicked, this, &FirewallDialog::setPublicNetMode); + connect(m_PrivateBtn, &QPushButton::clicked, this, &FirewallDialog::setPrivateNetMode); } void FirewallDialog::centerToScreen() @@ -99,3 +107,24 @@ void FirewallDialog::centerToScreen() int y = this->height(); this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); } + +void FirewallDialog::onPaletteChanged() +{ + QPalette pal = qApp->palette(); + + QGSettings * styleGsettings = nullptr; + const QByteArray style_id(THEME_SCHAME); + if (QGSettings::isSchemaInstalled(style_id)) { + styleGsettings = new QGSettings(style_id); + QString currentTheme = styleGsettings->get(COLOR_THEME).toString(); + if(currentTheme == "ukui-default"){ + pal = lightPalette(this); + } + } + this->setPalette(pal); + + if (styleGsettings != nullptr) { + delete styleGsettings; + styleGsettings = nullptr; + } +} diff --git a/src/frontend/networkmode/firewalldialog.h b/src/frontend/networkmode/firewalldialog.h index b832498f..4a16d315 100644 --- a/src/frontend/networkmode/firewalldialog.h +++ b/src/frontend/networkmode/firewalldialog.h @@ -26,8 +26,11 @@ #include #include #include + +#include "coninfo.h" #include "kwidget.h" #include "kdialog.h" +#include "kylable.h" using namespace kdk; @@ -48,16 +51,20 @@ private: QString m_uuid; QLabel * m_iconLabel = nullptr; - QLabel * m_contentLabel = nullptr; - QLabel * m_suggestLabel = nullptr; + FixLabel * m_contentLabel = nullptr; + FixLabel * m_suggestLabel = nullptr; QVBoxLayout *m_dialogLayout = nullptr; - QPushButton *m_YesBtn = nullptr; - QPushButton *m_NoBtn = nullptr; + QPushButton *m_PublicBtn = nullptr; + QPushButton *m_PrivateBtn = nullptr; Q_SIGNALS: void setPublicNetMode(); void setPrivateNetMode(); +private Q_SLOTS: + void onPaletteChanged(); + + public Q_SLOTS: void closeMyself(QString uuid, int status) { if (uuid == m_uuid && status == 4) { diff --git a/src/frontend/networkmode/networkmodeconfig.cpp b/src/frontend/networkmode/networkmodeconfig.cpp index fa19cc6c..d5ca8a57 100644 --- a/src/frontend/networkmode/networkmodeconfig.cpp +++ b/src/frontend/networkmode/networkmodeconfig.cpp @@ -18,8 +18,11 @@ * */ #include "networkmodeconfig.h" +#include "firewalldialog.h" #include +#define LOG_FLAG "[NetworkMode]" + NetworkModeConfig *NetworkModeConfig::m_netModeInstance = nullptr; NetworkModeConfig *NetworkModeConfig::getInstance() @@ -37,17 +40,21 @@ NetworkModeConfig::NetworkModeConfig(QObject *parent) : QObject(parent) "/firewall", "com.ksc.defender.firewall", QDBusConnection::systemBus()); + if(!m_dbusInterface->isValid()) { + qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); + } } int NetworkModeConfig::getNetworkModeConfig(QString uuid) { if (uuid.isEmpty()) { qWarning()<< /*LOG_FLAG <<*/ "uuid is empty, so can not get network mode config"; - return -1; + return NO_CONFIG; } - if(!m_dbusInterface->isValid()) { - qWarning ()<< "init com.ksc.defender dbus error"; + if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) { + qWarning () << "com.ksc.defender dbus is invalid"; + return DBUS_INVAILD; } QDBusReply reply = m_dbusInterface->call("get_networkModeConfig", uuid); @@ -56,13 +63,14 @@ int NetworkModeConfig::getNetworkModeConfig(QString uuid) } else { qWarning() << "call get_networkModeConfig failed" << reply.error().message(); } - return -1; + return NO_CONFIG; } void NetworkModeConfig::setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode) { - if(!m_dbusInterface->isValid()) { - qWarning ()<< "init com.ksc.defender dbus error"; + if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) { + qWarning () << "com.ksc.defender dbus is invalid"; + return; } QDBusReply reply = m_dbusInterface->call("set_networkModeConfig", uuid, cardName, ssid, mode); @@ -75,8 +83,9 @@ void NetworkModeConfig::setNetworkModeConfig(QString uuid, QString cardName, QSt int NetworkModeConfig::breakNetworkConnect(QString uuid, QString cardName, QString ssid) { - if(!m_dbusInterface->isValid()) { - qWarning ()<< "init com.ksc.defender dbus error"; + if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) { + qWarning () << "com.ksc.defender dbus is invalid"; + return -1; } QDBusReply reply = m_dbusInterface->call("break_networkConnect", uuid, cardName, ssid); @@ -88,3 +97,157 @@ int NetworkModeConfig::breakNetworkConnect(QString uuid, QString cardName, QStri return -1; } } + +//安全中心-网络防火墙模式配置 +NetworkMode::NetworkMode(QObject *parent) + :QObject(parent) +{ + qRegisterMetaType("NetworkManager::Device::State"); + qRegisterMetaType("NetworkManager::Device::StateChangeReason"); + m_deviceResource = new KyNetworkDeviceResourse(this); + m_activatedConnectResource = new KyActiveConnectResourse(this); + m_connectResource = new KyConnectResourse(this); + m_wirelessNetResource = new KyWirelessNetResource(this); + connect(m_activatedConnectResource, &KyActiveConnectResourse::stateChangeReason, + this, &NetworkMode::onConnectionStateChanged); +} + +void NetworkMode::initWiredNetworkMode() +{ + qDebug()<< LOG_FLAG << "initWiredNetworkMode"; + QStringList wiredDevList; + m_deviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDevList); + if (wiredDevList.isEmpty()) { + return; + } + + for (auto devName : wiredDevList) { + QList activedList; + m_activatedConnectResource->getActiveConnectionList(devName, + NetworkManager::ConnectionSettings::Wired, + activedList); + if (activedList.isEmpty()) { + continue; + } + + int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(activedList.at(0)->m_connectUuid); + if (configType == DBUS_INVAILD) { + return; + } else if (configType == NO_CONFIG) { + //已连接网络无配置 默认公有配置 + NetworkModeConfig::getInstance()->setNetworkModeConfig(activedList.at(0)->m_connectUuid, devName, + activedList.at(0)->m_connectName, KSC_FIREWALL_PUBLIC); + } else { + NetworkModeConfig::getInstance()->setNetworkModeConfig(activedList.at(0)->m_connectUuid, devName, + activedList.at(0)->m_connectName, configType); + } + } +} + +void NetworkMode::initWirelessNetworkMode() +{ + qDebug()<< LOG_FLAG << "initWirelessNetworkMode"; + QStringList wirelessDevList; + m_deviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDevList); + if (wirelessDevList.isEmpty()) { + return; + } + + for (auto devName : wirelessDevList) { + KyWirelessNetItem wirelessNetItem; + bool ret = m_wirelessNetResource->getActiveWirelessNetItem(devName, wirelessNetItem); + + if (ret == true) { + int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(wirelessNetItem.m_connectUuid); + if (configType == DBUS_INVAILD) { + return; + } else if (configType == NO_CONFIG) { + //已连接网络无配置 默认公有配置 + NetworkModeConfig::getInstance()->setNetworkModeConfig(wirelessNetItem.m_connectUuid, devName, + wirelessNetItem.m_connName, KSC_FIREWALL_PUBLIC); + } else { + NetworkModeConfig::getInstance()->setNetworkModeConfig(wirelessNetItem.m_connectUuid, devName, + wirelessNetItem.m_connName, configType); + } + } + } +} + +void NetworkMode::setFirstConnectNetworkMode(QString uuid, QString deviceName, QString ssid) +{ + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); //默认公有配置 + FirewallDialog *fireWallDialog = new FirewallDialog(); + fireWallDialog->setUuid(uuid); + fireWallDialog->setWindowTitle(ssid); + + connect(fireWallDialog, &FirewallDialog::setPrivateNetMode, this, [=](){ + fireWallDialog->hide(); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PRIVATE); + }); + + connect(fireWallDialog, &FirewallDialog::setPublicNetMode, this, [=](){ + fireWallDialog->hide(); + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); + }); + + connect(m_activatedConnectResource, &KyActiveConnectResourse::stateChangeReason, fireWallDialog, &FirewallDialog::closeMyself); + + fireWallDialog->show(); + fireWallDialog->centerToScreen(); +} + +void NetworkMode::onConnectionStateChanged(QString uuid, + NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason) +{ + if (state == NetworkManager::ActiveConnection::State::Activated) { + QString deviceName = ""; + QString ssid = ""; + + int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(uuid); + + //有线网络连接 + if (m_connectResource->isWiredConnection(uuid)) { + KyConnectItem *p_newItem = nullptr; + p_newItem = m_activatedConnectResource->getActiveConnectionByUuid(uuid); + if (nullptr == p_newItem) { + //删除此网络 + qDebug()<< LOG_FLAG << "delete wired connect:" << uuid << ", call break_networkConnect"; + NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, "", ""); + return; + } + + deviceName = p_newItem->m_ifaceName; + ssid = p_newItem->m_connectName; + if (configType == NO_CONFIG) { + //首次连接的网络 + setFirstConnectNetworkMode(uuid, deviceName, ssid); + } else if (configType == KSC_FIREWALL_PUBLIC) { + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); + } else if (configType == KSC_FIREWALL_PRIVATE) { + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PRIVATE); + } + } + //无线网络连接 + if (m_connectResource->isWirelessConnection(uuid)) { + m_wirelessNetResource->getSsidByUuid(uuid, ssid); + m_wirelessNetResource->getDeviceByUuid(uuid, deviceName); + if (ssid.isEmpty()) { + //忘记此网络 + qDebug()<< LOG_FLAG << "forgrt wireless connect:" << uuid <<", call break_networkConnect"; + NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, "", ""); + } + + if (configType == NO_CONFIG) { + setFirstConnectNetworkMode(uuid, deviceName, ssid); + } else if (configType == KSC_FIREWALL_PUBLIC) { + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); + } else if (configType == KSC_FIREWALL_PRIVATE) { + NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PRIVATE); + } + } + + } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { + NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, "", ""); + } +} diff --git a/src/frontend/networkmode/networkmodeconfig.h b/src/frontend/networkmode/networkmodeconfig.h index e3ed69f2..c4af58ee 100644 --- a/src/frontend/networkmode/networkmodeconfig.h +++ b/src/frontend/networkmode/networkmodeconfig.h @@ -23,6 +23,16 @@ #include #include #include +#include "kylinactiveconnectresource.h" +#include "kylinconnectresource.h" +#include "kywirelessnetresource.h" + +enum NetworkModeType { + DBUS_INVAILD = -2, + NO_CONFIG = -1, + KSC_FIREWALL_PUBLIC = 0, + KSC_FIREWALL_PRIVATE +}; class NetworkModeConfig : public QObject { @@ -43,4 +53,27 @@ private: QDBusInterface *m_dbusInterface = nullptr; }; + +class NetworkMode : public QObject +{ + Q_OBJECT +public: + NetworkMode(QObject *parent = 0); + ~NetworkMode() = default; + void initWiredNetworkMode(); + void initWirelessNetworkMode(); + +private: + KyNetworkDeviceResourse *m_deviceResource = nullptr; + KyActiveConnectResourse *m_activatedConnectResource = nullptr; + KyConnectResourse * m_connectResource = nullptr; + KyWirelessNetResource *m_wirelessNetResource = nullptr; + void setFirstConnectNetworkMode(QString uuid, QString deviceName, QString ssid); + +private Q_SLOTS: + void onConnectionStateChanged(QString uuid, + NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason); +}; + #endif // NETWORKMODECONFIG_H diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 39b4225a..0fbacef9 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -18,7 +18,8 @@ * */ #include "lanpage.h" -#include "networkmodeconfig.h" +#include "kwindowsystem.h" +#include "kwindowsystem_export.h" #include #include @@ -77,6 +78,7 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) m_netSwitch->setChecked(!checked); m_wiredConnectOperation->setWiredEnabled(checked); }); + m_lanPagePtrMap.clear(); } LanPage::~LanPage() @@ -138,28 +140,28 @@ void LanPage::initLanDeviceState() void LanPage::initNetSwitch() { - bool wiredSwitch = true; + bool wiredGsetting = true; bool wiredEnable = m_wiredConnectOperation->getWiredEnabled(); if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); if (m_switchGsettings->keys().contains(WIRED_SWITCH)) { - wiredSwitch = m_switchGsettings->get(WIRED_SWITCH).toBool(); + wiredGsetting = m_switchGsettings->get(WIRED_SWITCH).toBool(); connect(m_switchGsettings, &QGSettings::changed, this, &LanPage::onSwithGsettingsChanged); + if (wiredEnable != wiredGsetting) { + wiredEnable = wiredGsetting; + m_wiredConnectOperation->setWiredEnabled(wiredGsetting); + } } } else { qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!"; } - if (m_switchGsettings != nullptr - &&wiredSwitch != wiredEnable) { - m_switchGsettings->set(WIRED_SWITCH, wiredEnable); - } - //从3.0升级上来 先读取老的配置文件来保证和升级前状态一致 - bool oldVersionState; + bool oldVersionState = true; if (getOldVersionWiredSwitchState(oldVersionState)) { if (wiredEnable != oldVersionState) { + wiredEnable = oldVersionState; m_wiredConnectOperation->setWiredEnabled(oldVersionState); } } @@ -342,22 +344,10 @@ void LanPage::constructActiveConnectionArea() QListWidgetItem *p_listWidgetItem = addNewItem(p_activeConnectionItem, m_activatedLanListWidget); m_activeConnectionMap.insert(p_activeConnectionItem->m_connectUuid, p_listWidgetItem); - int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(p_activeConnectionItem->m_connectUuid); - if (configType == -1) { - NetworkModeConfig::getInstance()->setNetworkModeConfig(p_activeConnectionItem->m_connectUuid, - m_currentDeviceName, - p_activeConnectionItem->m_connectName, - KSC_FIREWALL_PUBLIC); - } else { - NetworkModeConfig::getInstance()->setNetworkModeConfig(p_activeConnectionItem->m_connectUuid, - m_currentDeviceName, - p_activeConnectionItem->m_connectName, - configType); - } - delete p_activeConnectionItem; p_activeConnectionItem = nullptr; } + setNetSpeed->start(REFRESH_NETWORKSPEED_TIMER); } else { qDebug()<<"[LanPage] there is not active"; addEmptyConnectItem(m_activeConnectionMap, m_activatedLanListWidget); @@ -452,6 +442,13 @@ void LanPage::onRemoveConnection(QString path) //删除时后端会 qDebug() << "[LanPage] Q_EMIT lanRemove because onRemoveConnection " << path; Q_EMIT lanRemove(path); + if (m_lanPagePtrMap.contains(path)) { + if (m_lanPagePtrMap[path] != nullptr) { + delete m_lanPagePtrMap[path]; + m_lanPagePtrMap[path] = nullptr; + } + } + if (removeConnectionItem(m_inactiveConnectionMap, m_inactivatedLanListWidget, path)) { return; } else { @@ -459,7 +456,7 @@ void LanPage::onRemoveConnection(QString path) //删除时后端会 if (m_activeConnectionMap.count() <= 0) { addEmptyConnectItem(m_activeConnectionMap, m_activatedLanListWidget); } - + setNetSpeed->stop(); return; } } @@ -758,6 +755,12 @@ void LanPage::initUI() m_inactivatedLanListWidget->setProperty("needTranslucent", true); m_inactivatedAreaLayout->addWidget(m_inactivatedLanListWidget); + connect(m_inactivatedLanListWidget, &QListWidget::currentItemChanged, this, [=]() { + if (m_inactivatedLanListWidget->currentItem() != nullptr) { + m_inactivatedLanListWidget->currentItem()->setSelected(false); + } + }); + QPalette pal = m_activatedLanListWidget->palette(); pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明 m_activatedLanListWidget->setPalette(pal); @@ -765,6 +768,10 @@ void LanPage::initUI() m_settingsLabel->installEventFilter(this); m_netSwitch->installEventFilter(this); + m_activatedLanListWidget->installEventFilter(this); + m_inactivatedLanListWidget->installEventFilter(this); + + showRate(); } QListWidgetItem *LanPage::insertNewItem(KyConnectItem *itemData, QListWidget *listWidget) @@ -782,7 +789,7 @@ QListWidgetItem *LanPage::insertNewItem(KyConnectItem *itemData, QListWidget *li } QListWidgetItem *p_sortListWidgetItem = new QListWidgetItem(); - p_sortListWidgetItem->setFlags(p_sortListWidgetItem->flags() & (~Qt::ItemIsSelectable)); //设置不可被选中 +// p_sortListWidgetItem->setFlags(p_sortListWidgetItem->flags() & (~Qt::ItemIsSelectable)); //设置不可被选中 p_sortListWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT)); listWidget->insertItem(index, p_sortListWidgetItem); @@ -790,14 +797,14 @@ QListWidgetItem *LanPage::insertNewItem(KyConnectItem *itemData, QListWidget *li LanListItem *p_sortLanItem = nullptr; p_sortLanItem = new LanListItem(itemData, m_currentDeviceName); listWidget->setItemWidget(p_sortListWidgetItem, p_sortLanItem); - + connect(p_sortLanItem, &LanListItem::detailShow, this, &LanPage::showDetailPage); return p_sortListWidgetItem; } QListWidgetItem *LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget) { QListWidgetItem *p_listWidgetItem = new QListWidgetItem(); - p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); +// p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); p_listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT)); listWidget->addItem(p_listWidgetItem); LanListItem *p_lanItem = nullptr; @@ -811,6 +818,7 @@ QListWidgetItem *LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listW } listWidget->setItemWidget(p_listWidgetItem, p_lanItem); + connect(p_lanItem, &LanListItem::detailShow, this, &LanPage::showDetailPage); return p_listWidgetItem; } @@ -921,7 +929,6 @@ void LanPage::onConnectionStateChange(QString uuid, KyConnectItem *p_newItem = nullptr; QString deviceName = ""; - QString ssid = ""; if (state == NetworkManager::ActiveConnection::State::Activated) { p_newItem = m_activeResourse->getActiveConnectionByUuid(uuid); @@ -929,41 +936,10 @@ void LanPage::onConnectionStateChange(QString uuid, qWarning()<<"[LanPage] get active connection failed, connection uuid" << uuid; return; } - - deviceName = p_newItem->m_ifaceName; - ssid = p_newItem->m_connectName; - - int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(uuid); - - if (configType == -1) { - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); //默认公有配置 - FirewallDialog *fireWallDialog = new FirewallDialog(); - fireWallDialog->setUuid(uuid); - fireWallDialog->setWindowTitle(ssid); - - connect(fireWallDialog, &FirewallDialog::setPrivateNetMode, this, [=](){ - fireWallDialog->hide(); - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PRIVATE); - }); - - connect(fireWallDialog, &FirewallDialog::setPublicNetMode, this, [=](){ - fireWallDialog->hide(); - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); - }); - - connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, fireWallDialog, &FirewallDialog::closeMyself); - - fireWallDialog->show(); - fireWallDialog->centerToScreen(); - - } else if (configType == KSC_FIREWALL_PUBLIC) { - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PUBLIC); - } else if (configType == KSC_FIREWALL_PRIVATE) { - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, deviceName, ssid, KSC_FIREWALL_PRIVATE); - } - updateActivatedConnectionArea(p_newItem); updateConnectionState(m_activeConnectionMap, m_activatedLanListWidget, uuid, (ConnectState)state); + deviceName = p_newItem->m_ifaceName; + setNetSpeed->start(REFRESH_NETWORKSPEED_TIMER); } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { p_newItem = m_connectResourse->getConnectionItemByUuidWithoutActivateChecking(uuid); qDebug() << "[LanPage] deactivated reason" << reason; @@ -973,10 +949,9 @@ void LanPage::onConnectionStateChange(QString uuid, } deviceName = p_newItem->m_ifaceName; - ssid = p_newItem->m_connectName; updateConnectionArea(p_newItem); updateConnectionState(m_inactiveConnectionMap, m_inactivatedLanListWidget, uuid, (ConnectState)state); - NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, deviceName, ssid); + setNetSpeed->stop(); } else if (state == NetworkManager::ActiveConnection::State::Activating) { deviceName = getConnectionDevice(uuid); if (deviceName == m_currentDeviceName) { @@ -1204,20 +1179,25 @@ bool LanPage::eventFilter(QObject *watched, QEvent *event) } } + } else if (watched == m_activatedLanListWidget) { + //去掉无右键菜单显示时的选中效果 + if (event->type() == QEvent::FocusIn) { + if (m_activatedLanListWidget->currentItem() != nullptr) { + m_activatedLanListWidget->currentItem()->setSelected(false); + } + } + } else if (watched == m_inactivatedLanListWidget) { + //去掉无右键菜单显示时的选中效果 + if (event->type() == QEvent::FocusIn) { + if (m_inactivatedLanListWidget->currentItem() != nullptr) { + m_inactivatedLanListWidget->currentItem()->setSelected(false); + } + } } return QWidget::eventFilter(watched, event); } -void LanPage::deleteWired(const QString &connUuid) -{ - qDebug() << "[LanPage] deleteWired" << connUuid; - if (connUuid == nullptr) { - return; - } - m_wiredConnectOperation->deleteWiredConnect(connUuid); -} - void LanPage::onWiredEnabledChanged(bool enabled) { if (m_devList.isEmpty()) { @@ -1270,9 +1250,38 @@ void LanPage::showDetailPage(QString devName, QString uuid) return; } + if (m_lanPagePtrMap.contains(p_item->m_connectPath)) { + if (m_lanPagePtrMap[p_item->m_connectPath] != nullptr) { + qDebug() << "[LanPage] ShowLanDetailPage" << uuid << "already create,just raise"; + KWindowSystem::activateWindow(m_lanPagePtrMap[p_item->m_connectPath]->winId()); + KWindowSystem::raiseWindow(m_lanPagePtrMap[p_item->m_connectPath]->winId()); + return; + } + } + NetDetail *netDetail = new NetDetail(devName, p_item->m_connectName, uuid, isActive, false, false); + m_lanPagePtrMap.insert(p_item->m_connectPath, netDetail); netDetail->show(); - netDetail->setDetailPageShowed(true); + + connect(netDetail, &NetDetail::detailPageClose, [&](QString deviceName, QString lanName, QString lanUuid){ + if (lanUuid.isEmpty()) { + return; + } + KyConnectItem *currentItem = nullptr; + if (m_connectResourse->isActivatedConnection(lanUuid)) { + currentItem = m_activeResourse->getActiveConnectionByUuid(lanUuid); + } else { + currentItem = m_connectResourse->getConnectionItemByUuid(lanUuid); + } + if (currentItem == nullptr) { + return; + } + if (m_lanPagePtrMap.contains(currentItem->m_connectPath)) { + m_lanPagePtrMap[currentItem->m_connectPath] = nullptr; + } + delete currentItem; + currentItem = nullptr; + }); delete p_item; p_item = nullptr; @@ -1287,3 +1296,13 @@ bool LanPage::lanIsConnected() } } +void LanPage::showRate() +{ + //定时获取网速 + setNetSpeed = new QTimer(this); + setNetSpeed->setTimerType(Qt::PreciseTimer); + connect(setNetSpeed, &QTimer::timeout, [&]() { + onSetNetSpeed(m_activatedLanListWidget, m_activeConnectionMap.contains(EMPTY_SSID), m_currentDeviceName); + }); +} + diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index 5b6ecade..d8ed6eba 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -44,7 +44,6 @@ public: //for dbus void getWiredList(QMap > &map); - void deleteWired(const QString& connUuid); void activateWired(const QString& devName, const QString& connUuid); void deactivateWired(const QString& devName, const QString& connUuid); void showDetailPage(QString devName, QString uuid); @@ -99,6 +98,7 @@ private: QListWidget *lanListWidget, QString uuid); void updateCurrentDevice(QString deviceName); + void showRate(); Q_SIGNALS: void lanAdd(QString devName, QStringList info); @@ -108,6 +108,8 @@ Q_SIGNALS: void lanActiveConnectionStateChanged(QString interface, QString uuid, int status); void lanConnectChanged(int state); + void showLanRate(QListWidget *widget, QMap &map, QString dev, bool isLan); + private Q_SLOTS: void onConnectionStateChange(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason); @@ -150,6 +152,7 @@ private: QStringList m_disableDeviceList; QGSettings *m_switchGsettings = nullptr; + QMap m_lanPagePtrMap; }; diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index 342e8f67..03d4f92c 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -23,6 +23,12 @@ #include #include #include +#include +#include + +#include"listitem.h" + +#define LOG_FLAG "[tabPage]" TabPage::TabPage(QWidget *parent) : QWidget(parent) { @@ -167,6 +173,141 @@ void TabPage::onPaletteChanged() } } +int TabPage::getCurrentLoadRate(QString dev, long *save_rate, long *tx_rate) +{ + FILE * net_dev_file; //文件指针 + char buffer[1024]; //文件中的内容暂存在字符缓冲区里 + //size_t bytes_read; //实际读取的内容大小 + char * match; //用以保存所匹配字符串及之后的内容 + char * device;//将QString转为Char * + QByteArray ba = dev.toLatin1(); // must + device = ba.data(); + int counter = 0; + //int i = 0; + char tmp_value[128]; + + if ((NULL == device) || (NULL == save_rate) || (NULL == tx_rate)) { + qDebug() << LOG_FLAG << "parameter pass error" ; + return -1; + } + + if ((net_dev_file = fopen("/proc/net/dev", "r")) == NULL) { + //打开文件/pro/net/dev/,从中读取流量数据 + qDebug() << LOG_FLAG << "error occurred when try to open file /proc/net/dev/"; + return -1; + } + memset(buffer, 0, sizeof(buffer)); + + while (fgets(buffer, sizeof(buffer), net_dev_file) != NULL) { + match = strstr(buffer, device); + + if (NULL == match) { + // qDebug()<<"No eth0 keyword to find!"; + continue; + } else { + match = match + strlen(device) + strlen(":"); //地址偏移到冒号 + sscanf(match, "%ld ", save_rate); + memset(tmp_value, 0, sizeof(tmp_value)); + sscanf(match, "%s ", tmp_value); + match = match + strlen(tmp_value); + for (size_t i=0; iitem(0); + ListItem *p_item = (ListItem *)m_activatedNetListWidget->itemWidget(activeitem); + if (isEmpty) { + p_item->m_lbLoadUp->hide(); + p_item->m_lbLoadDown->hide(); + p_item->m_lbLoadDownImg->hide(); + p_item->m_lbLoadUpImg->hide(); + return; + } + + if (this->isVisible()) { + + if (getCurrentLoadRate(dev, &start_rcv_rates, &start_tx_rates) == -1) { + start_rcv_rates = end_rcv_rates; + return; + } + + long int delta_rcv = (start_rcv_rates - end_rcv_rates) / 1024; + long int delta_tx = (start_tx_rates - end_tx_rates) / 1024; + + //简易滤波 + if (delta_rcv < 0 || delta_tx < 0) { + delta_rcv = 0; + delta_tx = 0; + } + else if (end_rcv_rates == 0 || end_tx_rates == 0){ + delta_rcv = 0; + delta_tx = 0; + } + + end_rcv_rates = start_rcv_rates; + end_tx_rates = start_tx_rates; + + int rcv_num = delta_rcv; + int tx_num = delta_tx; + + QString str_rcv = 0; + QString str_tx = 0; + + if (rcv_num < 1024) { + str_rcv = QString::number(rcv_num) + "KB/s"; + } else { + int remainder; + if (rcv_num % 1024 < 100) { + remainder = 0; + } else { + remainder = (rcv_num % 1024) / 100; + } + str_rcv = QString::number(rcv_num / 1024) + "." + QString::number(remainder) + "MB/s"; + } + + if (tx_num < 1024) { + str_tx = QString::number(tx_num) + "KB/s"; + } else { + int remainder; + if (tx_num % 1024 < 100) { + remainder = 0; + } else { + remainder = (tx_num % 1024)/100; + } + str_tx = QString::number(tx_num / 1024) + "." + QString::number(remainder) + "MB/s"; + } + p_item->m_lbLoadDown->setText(str_rcv); + p_item->m_lbLoadUp->setText(str_tx); + if (!p_item->m_hoverButton->isVisible()) { + p_item->m_lbLoadDown->show(); + p_item->m_lbLoadUp->show(); + p_item->m_lbLoadDownImg->show(); + p_item->m_lbLoadUpImg->show(); + } + } +} + void TabPage::showDesktopNotify(const QString &message, QString soundName) { QDBusInterface iface("org.freedesktop.Notifications", @@ -302,7 +443,7 @@ void getDeviceEnableState(int type, QMap &map) kdr = nullptr; } -bool getOldVersionWiredSwitchState(bool state) +bool getOldVersionWiredSwitchState(bool &state) { QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); QVariant value = m_settings->value("lan_switch_opened"); diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index 97a981df..1fc76eea 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -34,17 +34,15 @@ #include #include #include "kylinnetworkdeviceresource.h" -#include "firewalldialog.h" #include "kwidget.h" #include "kswitchbutton.h" //#include "kborderlessbutton.h" -using namespace kdk; +#define EMPTY_SSID "emptyssid" -enum network_mode { - KSC_FIREWALL_PUBLIC = 0, - KSC_FIREWALL_PRIVATE -}; +#define REFRESH_NETWORKSPEED_TIMER 1000 + +using namespace kdk; #define MAIN_LAYOUT_MARGINS 0,0,0,0 #define MAIN_LAYOUT_SPACING 0 @@ -81,7 +79,7 @@ bool checkDeviceExist(KyDeviceType deviceType, QString deviceName); QString getDefaultDeviceName(KyDeviceType deviceType); void setDefaultDevice(KyDeviceType deviceType, QString deviceName); void getDeviceEnableState(int type, QMap &map); -bool getOldVersionWiredSwitchState(bool state); +bool getOldVersionWiredSwitchState(bool &state); class TabPage : public QWidget { @@ -117,8 +115,10 @@ Q_SIGNALS: protected: void initUI(); + int getCurrentLoadRate(QString dev, long *save_rate, long *tx_rate); // virtual void initDevice() = 0;//初始化默认设备 virtual void initDeviceCombox() = 0;//初始化设备选择下拉框 + QTimer *setNetSpeed = nullptr; QVBoxLayout * m_mainLayout = nullptr; QFrame * m_titleFrame = nullptr; QHBoxLayout * m_titleLayout = nullptr; @@ -152,10 +152,17 @@ protected: QComboBox * m_deviceComboBox = nullptr; QLabel * m_tipsLabel = nullptr; + long int start_rcv_rates = 0; //保存开始时的流量计数 + long int end_rcv_rates = 0; //保存结束时的流量计数 + long int start_tx_rates = 0; //保存开始时的流量计数 + long int end_tx_rates = 0; //保存结束时的流量计数 + public Q_SLOTS: virtual void onDeviceComboxIndexChanged(int currentIndex) = 0; void onPaletteChanged(); +protected Q_SLOTS: + void onSetNetSpeed(QListWidget* m_activatedNetListWidget, bool isActive, QString dev); }; #endif // TABPAGE_H diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index c55f7ba2..9b241d3e 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -19,7 +19,8 @@ */ #include "wlanpage.h" #include "kywirelessnetitem.h" -#include "networkmodeconfig.h" +#include "kwindowsystem.h" +#include "kwindowsystem_export.h" #include #include #include @@ -28,7 +29,6 @@ #define AP_SCAN_INTERVAL (20*1000) #define ICON_REFRESH_INTERVAL (5*1000) -#define EMPTY_SSID "emptyssid" #define LOG_FLAG "[WlanPage]" #define LAN_PAGE_INDEX 0 @@ -79,9 +79,14 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent) connect(m_connectResource, &KyConnectResourse::connectivityChanged, this, &WlanPage::connectivityChanged); connect(m_netSwitch, &KSwitchButton::clicked, this, [=](bool checked) { - m_netSwitch->setChecked(!checked); - setWirelessEnable(checked); + //解决 switchBtn不支持点击的情况下,点击按钮,有无线网卡后不自动开启的问题 + if (getSwitchBtnEnable()) { + setSwitchBtnState(!checked); + setWirelessEnable(checked); + } }); + m_wlanPagePtrMap.clear(); + m_joinHiddenWiFiPagePtrMap.clear(); } bool WlanPage::eventFilter(QObject *w, QEvent *e) @@ -99,6 +104,20 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e) //检测不到无线网卡不再触发click信号 } } + } else if (w == m_activatedNetListWidget) { + //去掉无右键菜单显示时的选中效果 + if (e->type() == QEvent::FocusIn) { + if (m_activatedNetListWidget->currentItem() != nullptr) { + m_activatedNetListWidget->currentItem()->setSelected(false); + } + } + } else if (w == m_inactivatedNetListWidget) { + //去掉无右键菜单显示时的选中效果 + if (e->type() == QEvent::FocusIn) { + if (m_inactivatedNetListWidget->currentItem() != nullptr) { + m_inactivatedNetListWidget->currentItem()->setSelected(false); + } + } } return QWidget::eventFilter(w,e); } @@ -133,6 +152,12 @@ void WlanPage::initWlanUI() addWlanMoreItem(); m_inactivatedAreaLayout->addWidget(m_inactivatedNetListWidget); + connect(m_inactivatedNetListWidget, &QListWidget::currentItemChanged, this, [=]() { + if (m_inactivatedNetListWidget->currentItem() != nullptr) { + m_inactivatedNetListWidget->currentItem()->setSelected(false); + } + }); + QPalette pal = m_activatedNetListWidget->palette(); pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明 m_activatedNetListWidget->setPalette(pal); @@ -140,6 +165,10 @@ void WlanPage::initWlanUI() m_settingsLabel->installEventFilter(this); m_netSwitch->installEventFilter(this); + m_activatedNetListWidget->installEventFilter(this); + m_inactivatedNetListWidget->installEventFilter(this); + + showRate(); } bool WlanPage::getWirelessDevieceUseable() @@ -235,8 +264,9 @@ void WlanPage::initDeviceCombox() } } else { m_deviceFrame->hide(); - m_currentDevice = ""; - setDefaultDevice(WIRELESS, m_currentDevice); + //解决因m_currentDevice被置空,安全中心网络显示BUG +// m_currentDevice = ""; +// setDefaultDevice(WIRELESS, m_currentDevice); } connect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), @@ -248,7 +278,7 @@ QListWidgetItem *WlanPage::addEmptyItem(QListWidget *wirelessListWidget) { WlanListItem *p_wlanItem = new WlanListItem(); QListWidgetItem *p_listWidgetItem = new QListWidgetItem(); - p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); //设置不可被选中 +// p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); //设置不可被选中 p_listWidgetItem->setSizeHint(QSize(wirelessListWidget->width(), p_wlanItem->height())); wirelessListWidget->addItem(p_listWidgetItem); wirelessListWidget->setItemWidget(p_listWidgetItem, p_wlanItem); @@ -264,9 +294,10 @@ QListWidgetItem *WlanPage::addNewItem(KyWirelessNetItem &wirelessNetItem, m_currentDevice, m_connectResource->isApConnection(wirelessNetItem.m_connectUuid)); connect(p_wlanItem, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); + connect(p_wlanItem, &WlanListItem::detailShow, this, &WlanPage::showDetailPage); QListWidgetItem *p_listWidgetItem = new QListWidgetItem(); - p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); +// p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); p_listWidgetItem->setSizeHint(QSize(wirelessListWidget->width(), p_wlanItem->height())); wirelessListWidget->addItem(p_listWidgetItem); wirelessListWidget->setItemWidget(p_listWidgetItem, p_wlanItem); @@ -280,9 +311,10 @@ QListWidgetItem *WlanPage::insertNewItem(KyWirelessNetItem &wirelessNetItem, { WlanListItem *p_wlanItem = new WlanListItem(wirelessNetItem, m_currentDevice); connect(p_wlanItem, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); + connect(p_wlanItem, &WlanListItem::detailShow, this, &WlanPage::showDetailPage); QListWidgetItem *p_listWidgetItem = new QListWidgetItem(); - p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); +// p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); p_listWidgetItem->setSizeHint(QSize(wirelessListWidget->width(), p_wlanItem->height())); wirelessListWidget->insertItem(row, p_listWidgetItem); wirelessListWidget->setItemWidget(p_listWidgetItem, p_wlanItem); @@ -300,9 +332,10 @@ QListWidgetItem *WlanPage::insertNewItemWithSort(KyWirelessNetItem &wirelessNetI // << "signal strength" << wirelessNetItem.m_signalStrength; WlanListItem *p_sortWlanItem = new WlanListItem(wirelessNetItem, m_currentDevice); connect(p_sortWlanItem, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); + connect(p_sortWlanItem, &WlanListItem::detailShow, this, &WlanPage::showDetailPage); QListWidgetItem *p_sortListWidgetItem = new QListWidgetItem(); - p_sortListWidgetItem->setFlags(p_sortListWidgetItem->flags() & (~Qt::ItemIsSelectable)); +// p_sortListWidgetItem->setFlags(p_sortListWidgetItem->flags() & (~Qt::ItemIsSelectable)); p_sortListWidgetItem->setSizeHint(QSize(p_ListWidget->width(), p_sortWlanItem->height())); // qDebug() << "insertNewItemWithSort, count" << p_ListWidget->count(); @@ -353,10 +386,8 @@ void WlanPage::clearWirelessNetItemMap(QMap &wireless wirelessListWidget->removeItemWidget(p_listWidgetItem); delete p_wlanItem; - p_wlanItem = nullptr; delete p_listWidgetItem; - p_listWidgetItem = nullptr; iter = wirelessNetItem.erase(iter); } @@ -384,10 +415,8 @@ void WlanPage::deleteWirelessItemFormMap(QMap &wirele wirelessListWidget->takeItem(wirelessListWidget->row(p_listWidgetItem)); delete p_wlanItem; - p_wlanItem = nullptr; delete p_listWidgetItem; - p_listWidgetItem = nullptr; if (m_inactivatedNetListWidget->count() <= MAX_ITEMS) { m_inactivatedNetListWidget->setFixedWidth(MIN_WIDTH); @@ -421,20 +450,8 @@ void WlanPage::constructActivateConnectionArea() m_activateConnectionItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem); updateWlanItemState(m_activatedNetListWidget, p_listWidgetItem, Activated); - int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(wirelessNetItem.m_connectUuid); - if (configType == -1) { - NetworkModeConfig::getInstance()->setNetworkModeConfig(wirelessNetItem.m_connectUuid, - m_currentDevice, - wirelessNetItem.m_connName, - KSC_FIREWALL_PUBLIC); - } else { - NetworkModeConfig::getInstance()->setNetworkModeConfig(wirelessNetItem.m_connectUuid, - m_currentDevice, - wirelessNetItem.m_connName, - configType); - } - height += p_listWidgetItem->sizeHint().height(); + setNetSpeed->start(REFRESH_NETWORKSPEED_TIMER); } } @@ -545,6 +562,12 @@ void WlanPage::onWlanRemoved(QString interface, QString ssid) { Q_EMIT wlanRemove(interface, ssid); + if (m_wlanPagePtrMap.contains(interface) && m_wlanPagePtrMap[interface].contains(ssid)) { + if (m_wlanPagePtrMap[interface][ssid] != nullptr) { + m_wlanPagePtrMap[interface][ssid]->close(); + } + } + if (interface != m_currentDevice) { qDebug()<<"[WlanPage] the device is not current device," <<"current device" << m_currentDevice @@ -740,6 +763,12 @@ void WlanPage::onDeviceRemove(QString deviceName) QString originalDeviceName = m_currentDevice; + if (m_joinHiddenWiFiPagePtrMap.contains(deviceName)) { + if (m_joinHiddenWiFiPagePtrMap[deviceName] != nullptr) { + m_joinHiddenWiFiPagePtrMap[deviceName]->close(); + } + } + m_devList.removeOne(deviceName); deleteDeviceFromCombox(deviceName); @@ -797,6 +826,7 @@ void WlanPage::onWlanStateChanged(NetworkManager::Device::State newstate, Networ if (getSwitchBtnState() == getWirelessDevieceUseable()) { return ; } + setSwitchBtnEnable(true); setSwitchBtnState(getWirelessDevieceUseable()); initDeviceCombox(); initWlanArea(); @@ -932,11 +962,6 @@ void WlanPage::onConnectionStateChanged(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) { - if (!m_connectResource->isWirelessConnection(uuid)) { - qDebug()<< LOG_FLAG << "it is not wireless connection" << uuid; - return; - } - QString devName, ssid; m_wirelessNetResource->getSsidByUuid(uuid, ssid); m_wirelessNetResource->getDeviceByUuid(uuid, devName); @@ -944,10 +969,8 @@ void WlanPage::onConnectionStateChanged(QString uuid, qDebug()<< LOG_FLAG << "Q_EMIT wlanActiveConnectionStateChanged" << devName << ssid << state; Q_EMIT wlanActiveConnectionStateChanged(devName, ssid, uuid, state); - //解决通过高级设置添加的未指定网卡的无线连接无法断开的问题,去掉设备为空的判断 - if (ssid.isEmpty()) { - qDebug()<< LOG_FLAG << "ssid or devicename is empty" - << "devicename"<< devName <<"ssid"<isWirelessConnection(uuid)) { + qDebug()<< LOG_FLAG << "it is not wireless connection" << uuid; return; } @@ -974,38 +997,8 @@ void WlanPage::onConnectionStateChanged(QString uuid, << "; state = " << state << "; reason = " << reason << Q_FUNC_INFO <<__LINE__; if (state == NetworkManager::ActiveConnection::State::Activated) { m_updateStrength = true; - - if (!isApConnection) { - int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(uuid); - if (configType == -1) { - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PUBLIC); //默认公有配置 - FirewallDialog *fireWallDialog = new FirewallDialog(); //弹窗 供用户配置 - fireWallDialog->setUuid(uuid); - fireWallDialog->setWindowTitle(ssid); - - connect(fireWallDialog, &FirewallDialog::setPrivateNetMode, this, [=](){ - fireWallDialog->hide(); - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PRIVATE); - }); - - connect(fireWallDialog, &FirewallDialog::setPublicNetMode, this, [=](){ - fireWallDialog->hide(); - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PUBLIC); - }); - - connect(m_activatedConnectResource, &KyActiveConnectResourse::stateChangeReason, fireWallDialog, &FirewallDialog::closeMyself); - - fireWallDialog->show(); - fireWallDialog->centerToScreen(); - - } else if (configType == KSC_FIREWALL_PUBLIC) { - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PUBLIC); - } else if (configType == KSC_FIREWALL_PRIVATE) { - NetworkModeConfig::getInstance()->setNetworkModeConfig(uuid, devName, ssid, KSC_FIREWALL_PRIVATE); - } - } - updateActivatedArea(uuid, ssid, devName); + setNetSpeed->start(REFRESH_NETWORKSPEED_TIMER); if (m_activateConnectionItemMap.contains(ssid)) { QListWidgetItem *p_listWidgetItem = m_activateConnectionItemMap.value(ssid); updateWlanItemState(m_activatedNetListWidget, p_listWidgetItem, Activated); @@ -1017,12 +1010,12 @@ void WlanPage::onConnectionStateChanged(QString uuid, } updateWirelessNetArea(uuid, ssid, devName,""); + setNetSpeed->stop(); if (m_wirelessNetItemMap.contains(ssid)) { QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid); updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated); } - NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, devName, ssid); } else if (state == NetworkManager::ActiveConnection::State::Deactivating){ m_updateStrength = false; if (m_activateConnectionItemMap.contains(ssid)) { @@ -1104,23 +1097,7 @@ void WlanPage::requestScan() void WlanPage::onHiddenWlanClicked() { qDebug() << "[wlanPage] AddHideWifi Clicked! " << Q_FUNC_INFO << __LINE__ ; -// NetDetail *netDetail = new NetDetail(m_currentDevice, "", "", false, true, true); -// netDetail->show(); - if(m_hiddenWiFi != nullptr){ - m_hiddenWiFi->activateWindow(); - return; - } - - m_hiddenWiFi = new JoinHiddenWiFiPage(m_currentDevice); - - connect(m_hiddenWiFi, &JoinHiddenWiFiPage::showWlanList, this, &WlanPage::showMainWindow); - connect(m_hiddenWiFi, &JoinHiddenWiFiPage::destroyed, [&](){ - if (m_hiddenWiFi != nullptr) { - m_hiddenWiFi = nullptr; - } - }); - - m_hiddenWiFi->show(); + showHiddenWlanPage(m_currentDevice); } void WlanPage::showControlCenter() @@ -1175,7 +1152,10 @@ void WlanPage::onRefreshIconTimer() return; } - + //解决没有无线设备且m_currentDevice不清空的情况下,m_activateConnectionItemMap为空造成的段错误 + if (m_activateConnectionItemMap.isEmpty()) { + return ; + } QString activateSsid = m_activateConnectionItemMap.firstKey(); int sortRow = 0; for (int index = 0; index < wlanList.length(); index++) { @@ -1226,6 +1206,7 @@ void WlanPage::onRefreshIconTimer() WlanListItem *p_sortWlanItem = new WlanListItem(sortItem, m_currentDevice); connect(p_sortWlanItem, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); + connect(p_sortWlanItem, &WlanListItem::detailShow, this, &WlanPage::showDetailPage); m_inactivatedNetListWidget->insertItem(sortRow, p_sortListWidgetItem); m_inactivatedNetListWidget->setItemWidget(p_sortListWidgetItem, p_sortWlanItem); updateWlanItemState(m_inactivatedNetListWidget, p_sortListWidgetItem, Deactivated); @@ -1438,7 +1419,8 @@ void WlanPage::deactivateWirelessConnection(const QString& devName, const QStrin void WlanPage::onMainWindowVisibleChanged(const bool &visible) { qDebug() << "[WlanPage] Received signal of mainwindow visible changed. cur_state = " << visible << Q_FUNC_INFO << __LINE__; - if (visible) { + //开关关闭状态不刷新 + if (visible && getSwitchBtnState()) { //打开页面时先触发一次扫描,然后定时扫描wifi热点和刷新icon requestScan(); m_scanTimer->start(AP_SCAN_INTERVAL); @@ -1478,6 +1460,40 @@ void WlanPage::showNonePwd() return; } + +void WlanPage::showRate() +{ + //定时获取网速 + setNetSpeed = new QTimer(this); + setNetSpeed->setTimerType(Qt::PreciseTimer); + connect(setNetSpeed, &QTimer::timeout, [&](){ + onSetNetSpeed(m_activatedNetListWidget, m_activateConnectionItemMap.contains(EMPTY_SSID), m_currentDevice); + }); +} + +void WlanPage::showHiddenWlanPage(QString devName) +{ + if (m_joinHiddenWiFiPagePtrMap.contains(devName)) { + if (m_joinHiddenWiFiPagePtrMap[devName] != nullptr) { + qDebug() << "[WlanPage] showAddOtherWlanWidget" << devName << "already create,just raise"; + KWindowSystem::activateWindow(m_joinHiddenWiFiPagePtrMap[devName]->winId()); + KWindowSystem::raiseWindow(m_joinHiddenWiFiPagePtrMap[devName]->winId()); + return; + } + } + + JoinHiddenWiFiPage *hiddenWiFi =new JoinHiddenWiFiPage(devName); + connect(hiddenWiFi, &JoinHiddenWiFiPage::hiddenWiFiPageClose, [&](QString interfaceName){ + if (m_joinHiddenWiFiPagePtrMap.contains(interfaceName)) { + m_joinHiddenWiFiPagePtrMap[interfaceName] = nullptr; + } + }); + connect(hiddenWiFi, &JoinHiddenWiFiPage::showWlanList, this, &WlanPage::showMainWindow); + + m_joinHiddenWiFiPagePtrMap.insert(devName, hiddenWiFi); + hiddenWiFi->show(); +} + void WlanPage::showDetailPage(QString devName, QString ssid) { KyWirelessNetItem wirelessNetItem; @@ -1488,12 +1504,32 @@ void WlanPage::showDetailPage(QString devName, QString ssid) bool isActive = m_connectResource->isActivatedConnection(wirelessNetItem.m_connectUuid); + if (m_wlanPagePtrMap.contains(devName) && m_wlanPagePtrMap[devName].contains(ssid)) { + if (m_wlanPagePtrMap[devName][ssid] != nullptr) { + qDebug() << "[WlanPage] ShowWlanDetailPage" << ssid << "already create,just raise"; + KWindowSystem::activateWindow(m_wlanPagePtrMap[devName][ssid]->winId()); + KWindowSystem::raiseWindow(m_wlanPagePtrMap[devName][ssid]->winId()); + return; + } + } + NetDetail *netDetail = new NetDetail(devName, ssid, wirelessNetItem.m_connectUuid, isActive, true, !wirelessNetItem.m_isConfigured); + m_wlanPagePtrMap[devName].insert(ssid, netDetail); + connect(netDetail, &NetDetail::detailPageClose, [&](QString deviceName, QString wlanSsid){ + if (m_wlanPagePtrMap.contains(deviceName) && m_wlanPagePtrMap[deviceName].contains(wlanSsid)) { + m_wlanPagePtrMap[deviceName][wlanSsid] = nullptr; + } + }); netDetail->show(); - netDetail->setDetailPageShowed(true); + return; } +void WlanPage::showAddOtherPage(QString devName) +{ + showHiddenWlanPage(devName); +} + bool WlanPage::checkWlanStatus(NetworkManager::ActiveConnection::State state) { if (m_activatedConnectResource->checkWirelessStatus(state)) { @@ -1550,5 +1586,11 @@ void WlanPage::addWlanMoreItem() m_hiddenItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), m_hiddenWlanWidget->height())); m_inactivatedNetListWidget->addItem(m_hiddenItem); m_inactivatedNetListWidget->setItemWidget(m_hiddenItem, m_hiddenWlanWidget); + m_hiddenWlanWidget->m_freq->hide(); return; } + +int WlanPage::getAcivateWifiSignal() +{ + return m_activatedConnectResource->getAcivateWifiSignal(); +} diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 95450ca1..d7453722 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -66,6 +66,7 @@ public: void deactivateWirelessConnection(const QString& devName, const QString& ssid); void showDetailPage(QString devName, QString uuid); + void showAddOtherPage(QString devName); bool checkWlanStatus(NetworkManager::ActiveConnection::State state); @@ -78,6 +79,8 @@ public: bool getWirelessSwitchBtnState(); + int getAcivateWifiSignal(); + Q_SIGNALS: void oneItemExpanded(const QString &ssid); void wlanAdd(QString devName, QStringList info); @@ -143,6 +146,10 @@ private: void showNonePwd(); + void showRate(); + + void showHiddenWlanPage(QString devName); + QListWidgetItem *addEmptyItem(QListWidget *wirelessListWidget); QListWidgetItem *addNewItem(KyWirelessNetItem &wirelessNetItem, QListWidget *wirelessListWidget); @@ -194,12 +201,12 @@ private: } inline void setSwitchBtnEnable(bool state) { if (m_netSwitch != nullptr) { - m_netSwitch->setCheckable(state); + m_netSwitch->setEnabled(state); } } inline bool getSwitchBtnEnable() { if (m_netSwitch != nullptr) { - return m_netSwitch->isCheckable(); + return m_netSwitch->isEnabled(); } } @@ -229,7 +236,8 @@ private: QTimer *m_scanTimer = nullptr; QTimer *m_refreshIconTimer = nullptr; - JoinHiddenWiFiPage *m_hiddenWiFi = nullptr; + QMap> m_wlanPagePtrMap; + QMap m_joinHiddenWiFiPagePtrMap; }; #endif // WLANPAGE_H diff --git a/src/frontend/tools/kylable.cpp b/src/frontend/tools/kylable.cpp index a734877b..b821dbca 100644 --- a/src/frontend/tools/kylable.cpp +++ b/src/frontend/tools/kylable.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #define FOREGROUND_COLOR_NORMAL qApp->palette().text().color() @@ -50,6 +52,44 @@ QColor mixColor(const QColor &c1, const QColor &c2, qreal bias) return QColor::fromRgbF(r, g, b, a); } +FixLabel::FixLabel(QWidget *parent) : + QLabel(parent) +{ + const QByteArray id("org.ukui.style"); + QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); + if(QGSettings::isSchemaInstalled(id)){ + connect(fontSetting, &QGSettings::changed,[=](QString key) { + if ("systemFont" == key || "systemFontSize" ==key) { + changedLabelSlot(); + } + }); + } +} + + +void FixLabel::setLabelText(QString text) { + + mStr = text; + changedLabelSlot(); +} + +QString FixLabel::getText(){ + return mStr; +} + +void FixLabel::changedLabelSlot() { + QFontMetrics fontMetrics(this->font()); + int fontSize = fontMetrics.width(mStr); + if (fontSize > this->width()) { + setText(fontMetrics.elidedText(mStr, Qt::ElideRight, this->width())); + setToolTip(mStr); + } else { + setText(mStr); + setToolTip(""); + } +} + + KyLable::KyLable(QWidget *parent) : QLabel(parent) { connect(qApp, &QApplication::paletteChanged, this, &KyLable::onPaletteChanged); diff --git a/src/frontend/tools/kylable.h b/src/frontend/tools/kylable.h index 3a3cb24a..c45eb8bd 100644 --- a/src/frontend/tools/kylable.h +++ b/src/frontend/tools/kylable.h @@ -23,6 +23,23 @@ #include #include +class FixLabel : public QLabel +{ + Q_OBJECT +public: + explicit FixLabel(QWidget *parent = 0); + +public: + void setLabelText(QString text); + QString getText(); + +private Q_SLOTS: + void changedLabelSlot(); +private: + QString mStr; + +}; + class KyLable : public QLabel { Q_OBJECT diff --git a/src/frontend/tools/radioitembutton.cpp b/src/frontend/tools/radioitembutton.cpp index 02cd9a70..981e7569 100644 --- a/src/frontend/tools/radioitembutton.cpp +++ b/src/frontend/tools/radioitembutton.cpp @@ -231,7 +231,7 @@ void RadioItemButton::refreshButtonIcon() m_iconLabel->setPixmap(loadSvg(m_pixmap, PixmapColor::WHITE)); } else { m_backgroundColor = COLOR_BRIGHT_TEXT; - m_backgroundColor.setAlphaF(0.18); + m_backgroundColor.setAlphaF(0.12); if (qApp->palette().base().color().red() > MIDDLE_COLOR) { m_iconLabel->setPixmap(m_pixmap); } else { diff --git a/src/frontend/tools/tools.pri b/src/frontend/tools/tools.pri index 9c261260..7863428b 100644 --- a/src/frontend/tools/tools.pri +++ b/src/frontend/tools/tools.pri @@ -3,7 +3,6 @@ INCLUDEPATH += $$PWD HEADERS += \ $$PWD/divider.h \ $$PWD/infobutton.h \ - $$PWD/listitemedit.h \ $$PWD/loadingdiv.h \ $$PWD/radioitembutton.h \ $$PWD/switchbutton.h \ @@ -13,7 +12,6 @@ HEADERS += \ SOURCES += \ $$PWD/divider.cpp \ $$PWD/infobutton.cpp \ - $$PWD/listitemedit.cpp \ $$PWD/loadingdiv.cpp \ $$PWD/radioitembutton.cpp \ $$PWD/switchbutton.cpp \ diff --git a/src/main.cpp b/src/main.cpp index 0b6bd839..e8660476 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,10 +16,9 @@ * */ +//#include "mainwindow.h" #include "mainwindow.h" -#include "vpnmainwindow.h" #include "dbusadaptor.h" -#include "vpndbusadaptor.h" #include #include #include "qt-single-application.h" @@ -81,7 +80,7 @@ void messageOutput(QtMsgType type, const QMessageLogContext &context, const QStr int main(int argc, char *argv[]) { -// initUkuiLog4qt("kylin-nm"); + initUkuiLog4qt("kylin-nm"); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); @@ -128,7 +127,7 @@ int main(int argc, char *argv[]) QString locale = QLocale::system().name(); QTranslator trans_global; qDebug() << "QLocale " << QLocale(); - if (trans_global.load(QLocale(), "kylin-nm", "_", ":/translations/")) + if (trans_global.load(QLocale(), "kylin-nm", "_", "/usr/share/kylin-nm/kylin-nm/")) { a.installTranslator(&trans_global); qDebug()<<"Translations load success"; @@ -145,13 +144,19 @@ int main(int argc, char *argv[]) qWarning() << "QtBase Translations load fail"; } + QTranslator sdkTranslator; + if (sdkTranslator.load(QLocale(), "gui", "_", ":/translations/")) + { + a.installTranslator(&sdkTranslator); + qDebug()<<"SDK Translations load success"; + } else { + qWarning() << "SDK Translations load fail"; + } + while (!p_networkResource->NetworkManagerIsInited()) { ::usleep(1000); } - vpnMainWindow vpnwindow; - vpnwindow.setProperty("useStyleWindowManager", false); //禁用拖动 - MainWindow w; a.setActivationWindow(&w); w.setProperty("useStyleWindowManager", false); //禁用拖动 @@ -170,13 +175,8 @@ int main(int argc, char *argv[]) DbusAdaptor adaptor(&w); Q_UNUSED(adaptor); - VpnDbusAdaptor vpnAdaptor(&vpnwindow); - Q_UNUSED(vpnAdaptor); - auto connection = QDBusConnection::sessionBus(); - if (!connection.registerService("com.kylin.network") - || !connection.registerObject("/com/kylin/network", &w) - || !connection.registerObject("/com/kylin/vpnTool", &vpnwindow)) { + if (!connection.registerService("com.kylin.network") || !connection.registerObject("/com/kylin/network", &w)) { qCritical() << "QDbus register service failed reason:" << connection.lastError(); } diff --git a/src/org.ukui.kylin-nm.switch.gschema.xml b/src/org.ukui.kylin-nm.switch.gschema.xml index f7fa75de..544f2cd0 100644 --- a/src/org.ukui.kylin-nm.switch.gschema.xml +++ b/src/org.ukui.kylin-nm.switch.gschema.xml @@ -11,11 +11,4 @@ Wired switch.true is open,false is close. - - - false - vpnicon visible - vpnicon visible.true is visible,false is invisible. - - diff --git a/translate_generation.sh b/translate_generation.sh new file mode 100755 index 00000000..72f748b9 --- /dev/null +++ b/translate_generation.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +ts_list=(`ls translations/*.ts`) +source /etc/os-release +version=(`echo $ID`) + +for ts in "${ts_list[@]}" +do + printf "\nprocess ${ts}\n" + if [ "$version" == "fedora" ] || [ "$version" == "opensuse-leap" ] || [ "$version" == "opensuse-tumbleweed" ];then + lrelease-qt5 "${ts}" + else + lrelease "${ts}" + fi +done diff --git a/translations/kylin-nm_bo.ts b/translations/kylin-nm_bo.ts index 82bbeb73..fa557feb 100644 --- a/translations/kylin-nm_bo.ts +++ b/translations/kylin-nm_bo.ts @@ -27,43 +27,47 @@ CreatNetPage - + Connection Name - - IPv4Config + + Ipv4Config - + Address - + Netmask - + Default Gateway - - - Required + + Prefs DNS - + + Alternative DNS + + + + Auto(DHCP) - + Manual @@ -71,82 +75,82 @@ DetailPage - + Auto Connection - - + + SSID: - + Copied successfully! - + Copy all - + Please input SSID: - - + + Protocol: - - + + Security Type: - - + + Hz: - - + + Chan: - - + + BandWidth: - - - IPv4: - - - - + - IPv4 Dns: + IPV6: - + + + IPV4: + + + + + + IPV4 Dns: + + + + - IPv6: - - - - - Mac: @@ -182,22 +186,22 @@ FirewallDialog - + Allow other devices on this network to discover this computer? - + It is not recommended to enable this feature on public networks - + Not allowed (recommended) - + Allowed @@ -205,23 +209,33 @@ Ipv4Page - + + Ipv4Config + + + + Address - + Netmask - + Default Gateway - - IPv4Config + + Prefs DNS + + + + + Alternative DNS @@ -235,23 +249,23 @@ - + Invalid address - + Invalid subnet mask - - + + Required - + Address conflict @@ -259,54 +273,64 @@ Ipv6Page - + + Ipv6Config + + + + Address - + Subnet prefix Length - + Default Gateway - - IPv6Config + + Prefs DNS - + + Alternative DNS + + + + Auto(DHCP) - + Manual - - - + + + Required - + Invalid address - + Invalid gateway - + Address conflict @@ -377,27 +401,27 @@ LanPage - + No ethernet device avaliable - + LAN - + Activated LAN - + Inactivated LAN - + Wired Device not carried @@ -405,12 +429,12 @@ ListItem - + Kylin NM - + kylin network applet desktop message @@ -418,153 +442,140 @@ MainWindow - + kylin-nm - + LAN - + WLAN - + Settings - + Network tool - + Show MainWindow - - MultipleDnsWidget - - - DNS server: - - - NetDetail - + Kylin NM - + kylin network desktop message - + Detail - - Security + + Ipv4 - - - Config - - - - - Confirm - - - - - Cancel - - - - - Forget this network - - - - - Add Lan Connect - - - - - IPv4 + + Ipv6 - IPv6 + Security - + + + Config + + + + + Confirm + + + + + Cancel + + + + + Forget this network + + + + + Add Lan Connect + + + + connect hiddin wlan - - Delete this network - - - - - - + + + None - - - + + + Auto - + start check ipv4 address conflict - + start check ipv6 address conflict - + this wifi no support enterprise type - + this wifi no support None type - + this wifi no support WPA2 type - + this wifi no support WPA3 type @@ -755,24 +766,6 @@ - - SinglePage - - - Settings - - - - - Kylin NM - - - - - kylin network applet desktop message - - - TabPage @@ -786,51 +779,36 @@ - + Settings - + Kylin NM - + kylin network applet desktop message - - VpnListItem - - - Not connected - - - - - - Disconnect - - - - - - Connect - - - VpnPage - - VPN Connection + + Activated VPN - - VPN Settings + + Inactivated VPN + + + + + Wired Device not carried @@ -880,31 +858,31 @@ WlanListItem - + Not connected - - + + Disconnect - - - + + + Connect - - + + Forget - + Auto Connect @@ -953,17 +931,17 @@ main - + kylinnm - + show kylin-nm wifi page - + show kylin-nm lan page @@ -971,12 +949,12 @@ vpnMainWindow - + kylin-vpn - + vpn tool diff --git a/translations/kylin-nm_bo_CN.ts b/translations/kylin-nm_bo_CN.ts index e418f289..85826f43 100644 --- a/translations/kylin-nm_bo_CN.ts +++ b/translations/kylin-nm_bo_CN.ts @@ -46,17 +46,9 @@ - Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. + Private Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. ཆེད་སྤྱོད། དྲ་རྒྱའི་སྒྲིག་ཆས་ཀྱིས་གློག་ཀླད་འདི་མཐོང་ཐུབ། སྤྱིར་བཏང་གི་གནས་ཚུལ་འོག་ཁྱིམ་ཚང་ངམ་ལས་དོན་ཚན་པའི་དྲ་བ་དང་འཚམ་པས།ཁྱེད་ཀྱིས་དྲ་ཐོག་གི་མི་སྒེར་དང་སྒྲིག་ཆས་ལ་ངོས་འཛིན་དང་ཡིད་ཆེས་བྱེད་དགོས།. - - Public(recommended) Your device can not be discovered on the network. In most cases, use this feature when connected to a network at home, work, or a public location. - སྤྱི་སྤྱོད་(འོས་སྦྱོར་)དྲ་རྒྱའི་ཐོག་ནས་ཁྱོད་ཀྱི་སྒྲིག་ཆས་རྙེད་མི་ཐུབ། གནས་ཚུལ་མང་ཆེ་བའི་འོག་ཏུ་ཁྱིམ་ཚང་དང་བྱ་བ་འམ་ཡང་ན་སྤྱི་པའི་གོ་གནས་སུ་དྲ་རྒྱའི་དུས་སུ་ནུས་པ་འདི་བཀོལ་སྤྱོད་བྱེད་དགོས།. - - - Private Your device can be discovered on the network. Select this if you require file sharing or use applications that communicate over this network. You should know and trust the people and devices on the network. - ཆེད་སྤྱོད་དྲ་རྒྱའི་སྟེང་ནས་ཁྱོད་ཀྱི་སྒྲིག་ཆས་རྙེད་ཐུབ། གལ་ཏེ་ཡིག་ཆ་མཉམ་སྤྱོད་བྱེད་དགོས་པའམ་ཡང་ན་དྲ་རྒྱའི་འཕྲིན་གཏོང་བཀོལ་སྤྱོད་བྱེད་པར་བརྟེན་ནས་རྣམ་གྲངས་འདི་འདེམས་རོགས་གནང། ཁྱོད་ཀྱིས་དྲ་རྒྱའི་སྟེང་གི་མི་སྣ་དང་སྒྲིག་ཆས་ལ་རྒྱུས་ལོན་དང་ཡིད་ཆེས་བྱེད་དགོས།. - Config firewall and security settings @@ -81,51 +73,63 @@ CreatNetPage - + Connection Name འབྲེལ་མཐུད་ཀྱི་མིང་། - + IPv4Config IPv4ཁུང་ཙི། - + Address སྡོད་གནས། - + Netmask དྲ་རྒྱའི་མ་ལག - + Default Gateway ཁ་ཆད་བཞག་པའི་སྒོ་ཆེན། + Prefs DNS - སྔོན་གྲབས་DNS + སྔོན་གྲབས་DNS + Alternative DNS - ཚབ་བྱེད་རང་བཞིན་གྱི་DNS + ཚབ་བྱེད་རང་བཞིན་གྱི་DNS - + Auto(DHCP) རང་འགུལ་(DHCP) - + Manual ལག་དེབ། - - + + Invalid address + རྩིས་འགྲོ་མེད་པའི་ས་གནས། + + + + Invalid subnet mask + རྩིས་འགྲོ་མེད་པའི་དྲ་བ་འགེབས་སྲུང་བྱེད་པ། + + + + Required ངེས་པར་དུ་སྐོང་དགོས། @@ -133,82 +137,82 @@ DetailPage - + Auto Connection རང་འགུལ་གྱིས་འབྲེལ་མཐུད་བྱེད - - + + SSID: SSID: - + Copied successfully! འདྲ་བཟོ་བྱས་ནས་གྲུབ་འབྲས་ཐོབ་! - + Copy all ཚང་མ་འདྲ་བཤུས་བྱེད་ - + Please input SSID: SSID:ནང་འཇུག་གནང་རོགས།: - - + + Protocol: གྲོས་ཆོད་ནང་དུ།: - - + + Security Type: བདེ་འཇགས་ཀྱི་རིགས་དབྱིབས་ནི།: - - + + Hz: དྲ་རྒྱའི་འཕྲིན་ལམ།: - - + + Chan: དྲ་བའི་བགྲོད་ལམ།: - - + + BandWidth: ཞེང་ཆེ་བ།: - - + + IPv6: IPv6: - - + + IPv4: IPv4: - - - IPv4 Dns: - IPv4 Dns: + + + IPv4 DNS: + IPv4 DNS: - - + + Mac: ཨའོ་མོན་ནི།: @@ -498,22 +502,22 @@ དེ་ལྟར་མ་བྱས་ - + Allow other devices on this network to discover this computer? དྲ་རྒྱའི་སྟེང་གི་སྒྲིག་ཆས་གཞན་པས་གློག་ཀླད་འདི་རྙེད་དུ་འཇུག་གམ།? - + It is not recommended to enable this feature on public networks བསམ་འཆར་མེད་།སྤྱི་པའི་དྲ་རྒྱའི་སྟེང་ནས་ནུས་པ་འདི་མགོ་བརྩམས་། - + Not allowed (recommended) - མི་ཆོག་(འོས་སྦྱོར་)། + མི་ཆོག་པ་(འོས་སྦྱོར།) - + Allowed ཆོག་པ་ @@ -521,32 +525,34 @@ Ipv4Page - + IPv4Config IPv4ཁུང་ཙི། - + Address སྡོད་གནས། - + Netmask དྲ་རྒྱའི་མ་ལག - + Default Gateway ཁ་ཆད་བཞག་པའི་སྒོ་ཆེན། + Prefs DNS - སྔོན་གྲབས་DNS + སྔོན་གྲབས་DNS + Alternative DNS - ཚབ་བྱེད་རང་བཞིན་གྱི་DNS + ཚབ་བྱེད་རང་བཞིན་གྱི་DNS @@ -559,23 +565,23 @@ ལག་དེབ། - + Invalid address རྩིས་འགྲོ་མེད་པའི་ས་གནས། - + Invalid subnet mask རྩིས་འགྲོ་མེད་པའི་དྲ་བ་འགེབས་སྲུང་བྱེད་པ། - - + + Required ངེས་པར་དུ་སྐོང་དགོས། - + Address conflict ཤག་གནས་གདོང་གཏུག་ @@ -583,62 +589,64 @@ Ipv6Page - + IPv6Config IPv6ཁུང་ཙི། - + Address སྡོད་གནས། - + Subnet prefix Length ཡན་ལག་དྲ་རྒྱའི་སྔོན་སྒྲིག་གི་རིང་ཚད། - + Default Gateway ཁ་ཆད་བཞག་པའི་སྒོ་ཆེན། + Prefs DNS - སྔོན་གྲབས་DNS + སྔོན་གྲབས་DNS + Alternative DNS - ཚབ་བྱེད་རང་བཞིན་གྱི་DNS + ཚབ་བྱེད་རང་བཞིན་གྱི་DNS - + Auto(DHCP) རང་འགུལ་(DHCP) - + Manual ལག་དེབ། - - - + + + Required ངེས་པར་དུ་སྐོང་དགོས། - + Invalid address རྩིས་འགྲོ་མེད་པའི་ས་གནས། - + Invalid gateway རྩིས་འགྲོ་མེད་པའི་དྲ་བའི་འགག་སྒོ། - + Address conflict ཤག་གནས་གདོང་གཏུག་ @@ -709,26 +717,34 @@ Connect སྦྲེལ་མཐུད་བྱེད་པ + + Property + ངོ་བོ། + + + Delete + དྲ་རྒྱ་དེ་བསུབ་དགོས། + LanPage - + No ethernet device avaliable ཨེ་ཙི་དྲ་རྒྱའི་སྒྲིག་ཆས་ལ་བཙན་འཛུལ་བྱས་མི་ཆོག། - + LAN སྐུད་ཡོད་དྲ་བ། - + Activated LAN ངའི་དྲ་རྒྱ། - + Inactivated LAN དྲ་བ་གཞན་དག @@ -737,7 +753,7 @@ སྐུད་ཡོད་དྲ་བ་ཆད་སོང་། - + Wired Device not carried སྐུད་ཡོད་སྒྲིག་ཆས་འཁྱེར་མེད་པ། @@ -749,12 +765,12 @@ ListItem - + Kylin NM དྲ་རྒྱའི་ཡོ་བྱད། - + kylin network applet desktop message དྲ་རྒྱའི་གསལ་འདེབས་གནས་ཚུལ། @@ -762,76 +778,68 @@ MainWindow - + kylin-nm དྲ་རྒྱའི་ཡོ་བྱད། - + LAN 有线网络 སྐུད་ཡོད་དྲ་བ། - + WLAN 无线局域网 སྐུད་མེད་ཅུས་ཁོངས་ཀྱི་དྲ་བ། - + Show MainWindow རླུང་གཙོ་བོ་མངོན་པར་བྱས་ཡོད། - + Settings 设置网络项 སྒྲིག་བཀོད། - + Network tool དྲ་རྒྱའི་ལག་ཆ་ - - MultipleDnsWidget - - - DNS server: - DNSཞབས་ཞུ་བ།: - - NetDetail - + Kylin NM ཅིན་ལིན་NM - + kylin network desktop message དྲ་རྒྱའི་གསལ་འདེབས་གནས་ཚུལ། - + Detail ཞིབ་ཕྲའི་གནས་ཚུལ། - + IPv4 IPv4 - + IPv6 IPv6 - + Security བདེ་འཇགས། @@ -840,62 +848,61 @@ 关闭 - - + + Config བཀོད་སྒྲིག་བཅས་བྱ་དགོས། - + Confirm གཏན་འཁེལ་བྱ་དགོས། - + Cancel ཕྱིར་འཐེན། - + Forget this network དྲ་རྒྱ་འདི་བརྗེད་སོང་། - Delete this network དྲ་རྒྱ་དེ་བསུབ་དགོས། - - Add Lan Connect + + Add LAN Connect སྐུད་ཡོད་དྲ་བ་ཁ་སྣོན་བྱ་དགོས། - - connect hiddin wlan + + Connect Hidden WLAN ཧའེ་ཏེན་ཝེ་ལན་དང་འབྲེལ་མཐུད་བྱེད་པ། - - - + + + None གཅིག་ཀྱང་མེད། - - - + + + Auto རང་འགུལ་གྱིས་རླངས་ - + start check ipv4 address conflict ipv4ས་གནས་ཀྱི་འགལ་བ་ལ་ཞིབ་བཤེར་བྱེད་འགོ་ཚུགས། - + start check ipv6 address conflict ipv6གནས་ཡུལ་དང་འགལ་བར་ཞིབ་བཤེར་བྱེད་འགོ་ཚུགས། @@ -908,22 +915,22 @@ ipv6ཐག་གཅོད་གདོང་གཏུག་བྱུང་བ་རེད།! - + this wifi no support enterprise type wifiལ་རྒྱབ་སྐྱོར་མེད་པའི་ཁེ་ལས་ཀྱི་རིགས་དབྱིབས། - + this wifi no support None type wifiལ་རྒྱབ་སྐྱོར་མི་བྱེད་པར་རིགས་དབྱིབས་གཅིག་ཀྱང་མེད། - + this wifi no support WPA2 type wifiལ་རྒྱབ་སྐྱོར་མི་བྱེད་པའི་WPA2རིགས་དབྱིབས་ - + this wifi no support WPA3 type wifiལ་རྒྱབ་སྐྱོར་མི་བྱེད་པའི་WPA3རིགས་དབྱིབས་ @@ -952,7 +959,7 @@ IPv4地址: - IPv4 Dns: + IPv4 DNS: IPv4 DNS服务器: @@ -1108,13 +1115,8 @@ - Usename - བཀོལ་སྤྱོད་ཀྱི་མིང་། - - Username - Usename - 用户名 + བཀོལ་སྤྱོད་ཀྱི་མིང་། @@ -1206,24 +1208,6 @@ - - SinglePage - - - Settings - སྒྲིག་བཀོད། - - - - Kylin NM - - - - - kylin network applet desktop message - - - TabPage @@ -1237,56 +1221,37 @@ སྒྲིག་ཆས་སྒོ་རྒྱག་པ།! - + Settings སྒྲིག་བཀོད། - + Kylin NM ཅིན་ལིན་NM - + kylin network applet desktop message kylinདྲ་རྒྱའི་ཀུ་ཤུའི་ཅོག་ཙེའི་ཆ་འཕྲིན། - - VpnListItem - - - Not connected - - - - - - Disconnect - - - - - - Connect - - - VpnPage + + Activated VPN + + + + + Inactivated VPN + + + + Wired Device not carried - སྐུད་ཡོད་སྒྲིག་ཆས་འཁྱེར་མེད་པ། - - - - VPN Connection - - - - - VPN Settings - + སྐུད་ཡོད་སྒྲིག་ཆས་འཁྱེར་མེད་པ། @@ -1335,31 +1300,35 @@ WlanListItem - + Not connected འབྲེལ་མཐུད་མི་བྱེད་པ། - - + + Disconnect འབྲེལ་ཐག་ཆད་པ། - - - + + + Connect སྦྲེལ་མཐུད་བྱེད་པ - - + + Forget བརྗེད་པ། + + + Property + ངོ་བོ། - + Auto Connect རང་འགུལ་གྱིས་སྦྲེལ་མཐུད་ @@ -1471,17 +1440,17 @@ main - + kylinnm - + show kylin-nm wifi page སྐུད་མེད་དྲ་རྒྱའི་ངོས་མངོན་པར་བྱས་ཡོད། - + show kylin-nm lan page སྐུད་ཡོད་དྲ་རྒྱའི་ཤོག་ངོས་མངོན་པར་བྱས་ཡོད། @@ -1489,12 +1458,12 @@ vpnMainWindow - + kylin-vpn - + vpn tool diff --git a/translations/kylin-nm_tr.ts b/translations/kylin-nm_tr.ts index 5009f886..bca72f95 100644 --- a/translations/kylin-nm_tr.ts +++ b/translations/kylin-nm_tr.ts @@ -125,43 +125,47 @@ CreatNetPage - + Connection Name - - IPv4Config + + Ipv4Config - + Address - + Netmask - + Default Gateway - - - Required + + Prefs DNS - + + Alternative DNS + + + + Auto(DHCP) Oto(DHCP) - + Manual Elle @@ -169,82 +173,82 @@ DetailPage - + Auto Connection - - + + SSID: - + Copied successfully! - + Copy all - + Please input SSID: - - + + Protocol: - - + + Security Type: - - + + Hz: - - + + Chan: - - + + BandWidth: - - - IPv4: - IPv6 adresi: {4:?} - - - + - IPv4 Dns: + IPV6: - - - IPv6: - IPv6 adresi: {6:?} + + + IPV4: + - - + + + IPV4 Dns: + + + + + Mac: @@ -1201,22 +1205,22 @@ FirewallDialog - + Allow other devices on this network to discover this computer? - + It is not recommended to enable this feature on public networks - + Not allowed (recommended) - + Allowed @@ -1224,23 +1228,33 @@ Ipv4Page - + + Ipv4Config + + + + Address - + Netmask - + Default Gateway - - IPv4Config + + Prefs DNS + + + + + Alternative DNS @@ -1254,23 +1268,23 @@ Elle - + Invalid address - + Invalid subnet mask - - + + Required - + Address conflict @@ -1278,54 +1292,64 @@ Ipv6Page - + + Ipv6Config + + + + Address - + Subnet prefix Length - + Default Gateway - - IPv6Config + + Prefs DNS - + + Alternative DNS + + + + Auto(DHCP) Oto(DHCP) - + Manual Elle - - - + + + Required - + Invalid address - + Invalid gateway - + Address conflict @@ -1403,27 +1427,27 @@ LanPage - + No ethernet device avaliable - + LAN - + Activated LAN - + Inactivated LAN - + Wired Device not carried @@ -1431,12 +1455,12 @@ ListItem - + Kylin NM - + kylin network applet desktop message Kylin ağ uygulaması masaüstü mesajı @@ -1444,7 +1468,7 @@ MainWindow - + kylin-nm @@ -1465,22 +1489,22 @@ Gizli Ağı Bağlan - + LAN - + WLAN WLAN - + Settings - + Network tool @@ -1497,7 +1521,7 @@ HotSpot - + Show MainWindow Ana Pencereyi Göster @@ -1590,123 +1614,110 @@ WLAN Bağlantısı Başarılı - - MultipleDnsWidget - - - DNS server: - - - NetDetail - + Kylin NM - + kylin network desktop message - + Detail - + + Ipv4 + + + + + Ipv6 + + + + Security - - + + Config Ayar - + Confirm - + Cancel - + Forget this network - + Add Lan Connect - - IPv4 - IPv6 adresi: {4?} - - - - IPv6 - IPv6 adresi: {6?} - - - + connect hiddin wlan - - Delete this network - - - - - - + + + None Yok - - - + + + Auto Oto - + start check ipv4 address conflict - + start check ipv6 address conflict - + this wifi no support enterprise type - + this wifi no support None type - + this wifi no support WPA2 type - + this wifi no support WPA3 type @@ -2095,24 +2106,6 @@ - - SinglePage - - - Settings - - - - - Kylin NM - - - - - kylin network applet desktop message - Kylin ağ uygulaması masaüstü mesajı - - TabPage @@ -2126,17 +2119,17 @@ - + Settings - + Kylin NM - + kylin network applet desktop message Kylin ağ uygulaması masaüstü mesajı @@ -2148,36 +2141,21 @@ Kylin ağ uygulaması masaüstü mesajı - - VpnListItem - - - Not connected - Bağlanamadı - - - - - Disconnect - Bağlantıyı Kes - - - - - Connect - - - VpnPage - - VPN Connection + + Activated VPN - - VPN Settings + + Inactivated VPN + + + + + Wired Device not carried @@ -2227,31 +2205,31 @@ WlanListItem - + Not connected Bağlanamadı - - + + Disconnect Bağlantıyı Kes - - - + + + Connect - - + + Forget - + Auto Connect @@ -2315,17 +2293,17 @@ main - + kylinnm - + show kylin-nm wifi page - + show kylin-nm lan page @@ -2333,12 +2311,12 @@ vpnMainWindow - + kylin-vpn - + vpn tool diff --git a/translations/kylin-nm_zh_CN.ts b/translations/kylin-nm_zh_CN.ts index 9fb0d6df..d78db51d 100644 --- a/translations/kylin-nm_zh_CN.ts +++ b/translations/kylin-nm_zh_CN.ts @@ -42,21 +42,13 @@ Public(recommended) Devices on the network cannot discover this computer. Generally, it is suitable for networks in public places, such as airports or coffee shops, etc. - 公用(推荐) 网络中的设备不可发现此电脑。一般情况下适用于公共场所中的网络,如机场或咖啡店等等。 + 公用(推荐) 网络中的设备不可发现此电脑。一般情况下适用于公共场所中的网络,如机场或咖啡店等等。 - Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. + Private Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. 专用 网络中的设备可发现此电脑。一般情况下适用于家庭或工作单位的网络,您认识并信任网络上的个人和设备。 - - Public(recommended) Your device can not be discovered on the network. In most cases, use this feature when connected to a network at home, work, or a public location. - 公用(推荐)无法在网络上发现你的设备。在大多数情况下,在家庭、工作或公共位置连接到网络时使用此功能。 - - - Private Your device can be discovered on the network. Select this if you require file sharing or use applications that communicate over this network. You should know and trust the people and devices on the network. - 专用 可在网络上发现你的设备。如果需要文件共享或使用通过此网络通信的应用,请选择此项。你应该了解并信任网络上的人员和设备。 - Config firewall and security settings @@ -81,51 +73,63 @@ CreatNetPage - + Connection Name 网络名称 - + IPv4Config IPv4配置 - + Address IPv4地址 - + Netmask 子网掩码 - + Default Gateway 默认网关 + Prefs DNS - 首选DNS + 首选DNS + Alternative DNS - 备选DNS + 备选DNS - + Auto(DHCP) 自动(DHCP) - + Manual 手动 - - + + Invalid address + 无效地址 + + + + Invalid subnet mask + 无效子网掩码 + + + + Required 必填 @@ -133,82 +137,82 @@ DetailPage - + Auto Connection 自动连接 - - + + SSID: SSID: - + Copied successfully! 复制成功! - + Copy all 复制全部 - + Please input SSID: 请输入SSID: - - + + Protocol: 协议: - - + + Security Type: 安全类型: - - + + Hz: 网络频带: - - + + Chan: 网络通道: - - + + BandWidth: 带宽: - - + + IPv6: 本地链接IPv6地址: - - + + IPv4: IPv4地址: - - - IPv4 Dns: + + + IPv4 DNS: IPv4 DNS服务器: - - + + Mac: 物理地址: @@ -498,22 +502,22 @@ - + Allow other devices on this network to discover this computer? 是否允许此网络上的其他设备发现这台电脑? - + It is not recommended to enable this feature on public networks 不建议在公共网络上开启此功能 - + Not allowed (recommended) 不允许(推荐) - + Allowed 允许 @@ -521,32 +525,34 @@ Ipv4Page - + IPv4Config IPv4配置 - + Address 地址 - + Netmask 子网掩码 - + Default Gateway 默认网关 + Prefs DNS - 首选DNS + 首选DNS + Alternative DNS - 备选DNS + 备选DNS @@ -559,23 +565,23 @@ 手动 - + Invalid address 无效地址 - + Invalid subnet mask 无效子网掩码 - - + + Required 必填 - + Address conflict 地址冲突 @@ -583,62 +589,64 @@ Ipv6Page - + IPv6Config IPv6配置 - + Address 地址 - + Subnet prefix Length 子网前缀长度 - + Default Gateway 默认网关 + Prefs DNS - 首选DNS + 首选DNS + Alternative DNS - 备选DNS + 备选DNS - + Auto(DHCP) 自动 - + Manual 手动 - - - + + + Required 必填 - + Invalid address 无效地址 - + Invalid gateway 无效网关 - + Address conflict 地址冲突 @@ -709,26 +717,34 @@ Connect 连接 + + Property + 属性 + + + Delete + 删除此网络 + LanPage - + No ethernet device avaliable 未检测到有线设备 - + LAN 有线网络 - + Activated LAN 我的网络 - + Inactivated LAN 其他网络 @@ -737,7 +753,7 @@ 有线网络已断开 - + Wired Device not carried 未插入网线 @@ -749,12 +765,12 @@ ListItem - + Kylin NM 麒麟网络设置工具 - + kylin network applet desktop message 网络提示消息 @@ -762,76 +778,68 @@ MainWindow - + kylin-nm 网络工具 - + LAN 有线网络 有线网络 - + WLAN 无线局域网 无线局域网 - + Show MainWindow 打开网络工具 - + Settings 设置网络项 设置网络项 - + Network tool 网络工具 - - MultipleDnsWidget - - - DNS server: - DNS服务器: - - NetDetail - + Kylin NM 麒麟网络设置工具 - + kylin network desktop message 网络提示消息 - + Detail 详情 - + IPv4 IPv4 - + IPv6 IPv6 - + Security 安全 @@ -840,62 +848,61 @@ 关闭 - - + + Config 配置 - + Confirm 确定 - + Cancel 取消 - + Forget this network 忘记此网络 - - + Delete this network 删除此网络 - - Add Lan Connect + + Add LAN Connect 添加有线网络 - - connect hiddin wlan + + Connect Hidden WLAN 连接到隐藏WLAN - - - + + + None - - - + + + Auto 自动 - + start check ipv4 address conflict 开始检测ipv4地址冲突 - + start check ipv6 address conflict 开始检测ipv6地址冲突 @@ -908,22 +915,22 @@ ipv6地址冲突! - + this wifi no support enterprise type 此wifi不支持企业网类型 - + this wifi no support None type 此wifi不支持空类型 - + this wifi no support WPA2 type 此wifi不支持WPA2类型 - + this wifi no support WPA3 type 此wifi不支持WPA3类型 @@ -952,7 +959,7 @@ IPv4地址: - IPv4 Dns: + IPv4 DNS: IPv4 DNS服务器: @@ -1108,13 +1115,8 @@ - Usename - 用户名 - - Username - Usename - 用户名 + 用户名 @@ -1206,24 +1208,6 @@ - - SinglePage - - - Settings - 设置 - - - - Kylin NM - 网络工具 - - - - kylin network applet desktop message - 网络提示消息 - - TabPage @@ -1237,56 +1221,37 @@ 设备关闭! - + Settings 网络设置 - + Kylin NM 麒麟网络设置工具 - + kylin network applet desktop message 网络提示消息 - - VpnListItem - - - Not connected - 未连接 - - - - - Disconnect - 断开 - - - - - Connect - 连接 - - VpnPage + + Activated VPN + + + + + Inactivated VPN + + + + Wired Device not carried - 未插入网线 - - - - VPN Connection - VPN连接 - - - - VPN Settings - VPN设置 + 未插入网线 @@ -1335,31 +1300,35 @@ WlanListItem - + Not connected 未连接 - - + + Disconnect 断开 - - - + + + Connect 连接 - - + + Forget 忘记此网络 + + + Property + 属性 - + Auto Connect 自动加入该网络 @@ -1471,17 +1440,17 @@ main - + kylinnm - + show kylin-nm wifi page - + show kylin-nm lan page @@ -1489,14 +1458,14 @@ vpnMainWindow - + kylin-vpn - VPN工具 + - + vpn tool - VPN工具 + From bc2276f64643e1f88e1bbfa4c6cd64373df34cfb Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Fri, 7 Apr 2023 10:03:38 +0800 Subject: [PATCH 02/10] =?UTF-8?q?openkylin=20=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/vpndbusadaptor.cpp | 72 -- src/backend/vpndbusadaptor.h | 71 -- src/frontend/list-items/vpnlistitem.cpp | 244 ------- src/frontend/list-items/vpnlistitem.h | 77 --- src/frontend/mainwindow.cpp | 29 +- src/frontend/mainwindow.h | 4 + src/frontend/netdetails/ipv4page.h | 3 +- .../netdetails/joinhiddenwifipage.cpp | 14 + src/frontend/netdetails/joinhiddenwifipage.h | 3 + src/frontend/netdetails/netdetail.cpp | 134 +++- src/frontend/netdetails/netdetail.h | 6 +- src/frontend/single-pages/single-pages.pri | 10 - src/frontend/single-pages/singlepage.cpp | 108 --- src/frontend/single-pages/singlepage.h | 109 --- src/frontend/single-pages/vpnpage.cpp | 645 ------------------ src/frontend/single-pages/vpnpage.h | 126 ---- src/frontend/tab-pages/lanpage.cpp | 1 + src/frontend/tab-pages/wlanpage.cpp | 2 + src/frontend/vpnmainwindow.cpp | 495 -------------- src/frontend/vpnmainwindow.h | 127 ---- src/main.cpp | 2 +- 21 files changed, 174 insertions(+), 2108 deletions(-) delete mode 100644 src/backend/vpndbusadaptor.cpp delete mode 100644 src/backend/vpndbusadaptor.h delete mode 100644 src/frontend/list-items/vpnlistitem.cpp delete mode 100644 src/frontend/list-items/vpnlistitem.h delete mode 100644 src/frontend/single-pages/single-pages.pri delete mode 100644 src/frontend/single-pages/singlepage.cpp delete mode 100644 src/frontend/single-pages/singlepage.h delete mode 100644 src/frontend/single-pages/vpnpage.cpp delete mode 100644 src/frontend/single-pages/vpnpage.h delete mode 100644 src/frontend/vpnmainwindow.cpp delete mode 100644 src/frontend/vpnmainwindow.h diff --git a/src/backend/vpndbusadaptor.cpp b/src/backend/vpndbusadaptor.cpp deleted file mode 100644 index 1b43deb0..00000000 --- a/src/backend/vpndbusadaptor.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp com.kylin.weather.xml -a VpnDbusAdaptor -c VpnDbusAdaptor -l MainWindow - * - * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. - * - * This is an auto-generated file. - * Do not edit! All changes made to it will be lost. - */ - -#include "vpndbusadaptor.h" -#include -#include -#include -#include -#include -#include -#include - -/* - * Implementation of adaptor class VpnDbusAdaptor - */ - -VpnDbusAdaptor::VpnDbusAdaptor(vpnMainWindow *parent) - : QDBusAbstractAdaptor(parent) -{ - // constructor - qDBusRegisterMetaType >(); - qDBusRegisterMetaType >(); - qDBusRegisterMetaType >(); - //setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发 - setAutoRelaySignals(true); -} - -VpnDbusAdaptor::~VpnDbusAdaptor() -{ - // destructor -} - -//虚拟连接列表 -QVector VpnDbusAdaptor::getVirtualList() -{ - QVector vector; - parent()->getVirtualList(vector); - return vector; -} - -//删除 -void VpnDbusAdaptor::deleteVpn(QString uuid) -{ - qDebug() << "delete vpn" << uuid; - parent()->deleteVpn(uuid); -} - -//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid -void VpnDbusAdaptor::activateVpn(const QString& connUuid) -{ - qDebug() << "activate vpn" << connUuid; - parent()->activateVpn(connUuid); -} - -//断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid -void VpnDbusAdaptor::deactivateVpn(const QString& connUuid) -{ - qDebug() << "deactivate vpn" << connUuid; - parent()->deactivateVpn(connUuid); -} - -void VpnDbusAdaptor::showKylinVpn() -{ - parent()->onShowMainWindow(); -} diff --git a/src/backend/vpndbusadaptor.h b/src/backend/vpndbusadaptor.h deleted file mode 100644 index 2fba0c84..00000000 --- a/src/backend/vpndbusadaptor.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp com.kylin.weather.xml -a dbusadaptor -c DbusAdaptor -l MainWindow - * - * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. - * - * This is an auto-generated file. - * This file may have been hand-edited. Look for HAND-EDIT comments - * before re-generating it. - */ - -#ifndef VPNDBUSADAPTOR_H -#define VPNDBUSADAPTOR_H - -#include -#include -#include - -#include "singlepage.h" -#include "../dbus-interface/kylinnetworkdeviceresource.h" -QT_BEGIN_NAMESPACE -class QByteArray; -//template class QList; -template class QMap; -class QString; -class QStringList; -class QVariant; -template class QVector; -QT_END_NAMESPACE - -/* - * Adaptor class for interface com.kylin.weather - */ - -#include "vpnmainwindow.h" - -class VpnDbusAdaptor: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "com.kylin.vpnTool") -public: - VpnDbusAdaptor(vpnMainWindow *parent); - virtual ~VpnDbusAdaptor(); - - inline vpnMainWindow *parent() const - { return static_cast(QObject::parent()); } - -public: // PROPERTIES -public Q_SLOTS: // METHODS - //虚拟连接列表 - QVector getVirtualList(); - //刪除 根据网络名称 参数1 0:lan 1:wlan 参数2 为ssid/uuid - Q_NOREPLY void deleteVpn(QString uuid); - //连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid - Q_NOREPLY void activateVpn(const QString& connUuid); - //断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid - Q_NOREPLY void deactivateVpn(const QString& connUuid); - //just show - void showKylinVpn(); - -Q_SIGNALS: // SIGNALS - void vpnAdd(QStringList info); - void vpnRemove(QString dbusPath); - void vpnUpdate(QStringList info); - void vpnActiveConnectionStateChanged(QString uuid, int status); - - void activateFailed(QString errorMessage); - void deactivateFailed(QString errorMessage); -}; - -#endif diff --git a/src/frontend/list-items/vpnlistitem.cpp b/src/frontend/list-items/vpnlistitem.cpp deleted file mode 100644 index 0a1541d1..00000000 --- a/src/frontend/list-items/vpnlistitem.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/* -*- 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 "vpnlistitem.h" -#include "backend/dbus-interface/kylinconnectitem.h" - -#include - -#define LOG_FLAG "[VpnListItem]" - -VpnListItem::VpnListItem(const KyConnectItem *lanConnectItem, QWidget *parent):ListItem(parent) -{ - m_connectOperation = new KyWiredConnectOperation(this); - m_deviceResource = new KyNetworkDeviceResourse(this); - - connectItemCopy(lanConnectItem); - - m_nameLabel->setLabelText(m_vpnConnectItem.m_connectName); - m_netButton->setButtonIcon(QIcon::fromTheme("ukui-vpn-symbolic")); - - qDebug() << "VpnListItem init:" << m_vpnConnectItem.m_connectName << m_vpnConnectItem.m_connectState << m_vpnConnectItem.m_ifaceName; - - if (Deactivated == m_vpnConnectItem.m_connectState || Activated == m_vpnConnectItem.m_connectState) { - m_netButton->stopLoading(); - if (m_vpnConnectItem.m_connectState == Activated) { - setIcon(true); - } else { - setIcon(false); - } - } else { - m_netButton->startLoading(); - } - - m_itemFrame->installEventFilter(this); - connect(this->m_infoButton, &InfoButton::clicked, this, &VpnListItem::onInfoButtonClicked); - connect(m_menu, &QMenu::triggered, this, &VpnListItem::onMenuTriggered); -} - - -VpnListItem::VpnListItem(QWidget *parent) : ListItem(parent) -{ - m_isActive = false; - m_netButton->setButtonIcon(QIcon::fromTheme("ukui-vpn-symbolic")); - setIcon(false); - const QString str=tr("Not connected"); - m_nameLabel->setLabelText(str); - this->m_infoButton->hide(); -} - -VpnListItem::~VpnListItem() -{ - qDebug()<<"[LanPage] lan list item is deleted." << m_vpnConnectItem.m_connectName; -} - -void VpnListItem::setIcon(bool isOn) -{ - if (isOn) { - m_netButton->setActive(true); //设置图标显示不同颜色 - } else { - m_netButton->setActive(false); - } -} - -void VpnListItem::connectItemCopy(const KyConnectItem *lanConnectItem) -{ - if (lanConnectItem) { - m_vpnConnectItem.m_connectName = lanConnectItem->m_connectName; - m_vpnConnectItem.m_connectPath = lanConnectItem->m_connectPath; - m_vpnConnectItem.m_connectState = lanConnectItem->m_connectState; - m_vpnConnectItem.m_connectUuid = lanConnectItem->m_connectUuid; - m_vpnConnectItem.m_ifaceName = lanConnectItem->m_ifaceName; - m_vpnConnectItem.m_itemType = lanConnectItem->m_itemType; - } else { - qDebug() << LOG_FLAG <<"the connect item is nullptr"; - m_vpnConnectItem.m_connectName = ""; - m_vpnConnectItem.m_connectPath = ""; - m_vpnConnectItem.m_connectState = NetworkManager::ActiveConnection::State::Unknown; - m_vpnConnectItem.m_connectUuid = ""; - m_vpnConnectItem.m_ifaceName = ""; - m_vpnConnectItem.m_itemType = NetworkManager::ConnectionSettings::ConnectionType::Unknown; - } - - return; -} - -//void VpnListItem::changeState(QString uuid, -// NetworkManager::ActiveConnection::State state, -// NetworkManager::ActiveConnection::Reason reason) -//{ - -//} - -void VpnListItem::activeConnection() -{ - if (m_vpnConnectItem.m_connectUuid.isEmpty()) { - qDebug() << LOG_FLAG << "connect is empty, so can not connect or disconnect."; - return; - } - - if (Deactivated == m_vpnConnectItem.m_connectState) { - //断开的连接,点击激活连接 - m_connectOperation->activateVpnConnection(m_vpnConnectItem.m_connectUuid); - qDebug() << LOG_FLAG << "it will activate connection" << m_vpnConnectItem.m_connectName; - m_netButton->startLoading(); - } else { - qDebug() << LOG_FLAG <<"the connection" << m_vpnConnectItem.m_connectName - << "is not deactived, so it can not be operation."; - } - - return; -} - -void VpnListItem::onNetButtonClicked() -{ - if (m_vpnConnectItem.m_connectUuid.isEmpty()) { - qDebug() << LOG_FLAG << "connect is empty, so can not connect or disconnect."; - return; - } - - if (Deactivated == m_vpnConnectItem.m_connectState) { - //断开的连接,点击激活连接 - m_connectOperation->activateVpnConnection(m_vpnConnectItem.m_connectUuid); - qDebug() << LOG_FLAG << "it will activate connection" << m_vpnConnectItem.m_connectName; - m_netButton->startLoading(); - } else { - qDebug() << LOG_FLAG <<"the connection" << m_vpnConnectItem.m_connectName - << "is not deactived, so it can not be operation."; - } - - return; - -} - -void VpnListItem::onRightButtonClicked() -{ - //右键点击事件 - qDebug()<< LOG_FLAG <<"onRightButtonClicked"; - if (!m_menu) { - return; - } - - m_menu->clear(); - if (Activated == m_vpnConnectItem.m_connectState || Activating == m_vpnConnectItem.m_connectState) { - m_menu->addAction(new QAction(tr("Disconnect"), this)); - } else if (Deactivated == m_vpnConnectItem.m_connectState) { - m_menu->addAction(new QAction(tr("Connect"), this)); - } else { - return; - } - - m_menu->move(cursor().pos()); - m_menu->show(); - return; -} - -void VpnListItem::onMenuTriggered(QAction *action) -{ - if (action->text() == tr("Connect")) { - this->onNetButtonClicked(); - } else if (action->text() == tr("Disconnect")) { - m_connectOperation->deactivateWiredConnection(m_vpnConnectItem.m_connectName, m_vpnConnectItem.m_connectUuid); - qDebug() << LOG_FLAG << "it will disconnect connection" << m_vpnConnectItem.m_connectName; - m_netButton->startLoading(); - } - return; -} - -bool VpnListItem::launchApp(QString desktopFile) -{ - QDBusInterface appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, - KYLIN_APP_MANAGER_PATH, - KYLIN_APP_MANAGER_INTERFACE, - QDBusConnection::sessionBus()); - - if (!appManagerDbusInterface.isValid()) { - qWarning()<<"appManagerDbusInterface init error"; - return false; - } else { - QDBusReply reply = appManagerDbusInterface.call("LaunchApp", desktopFile); - return reply; - } -} - -void VpnListItem::onInfoButtonClicked() -{ - launchApp("nm-connection-editor.desktop"); - return; -} - -void VpnListItem::updateConnectionState(ConnectState state) -{ - m_vpnConnectItem.m_connectState = (NetworkManager::ActiveConnection::State)state; - - if (Deactivated == state || Activated == state) { - m_netButton->stopLoading(); - if (state == Activated) { - setIcon(true); - } else { - setIcon(false); - } - } else { - m_netButton->startLoading(); - } - - return; -} - -QString VpnListItem::getConnectionName() -{ - return m_vpnConnectItem.m_connectName; -} - -void VpnListItem::updateConnectionName(QString connectionName) -{ - m_vpnConnectItem.m_connectName = connectionName; - m_nameLabel->setLabelText(m_vpnConnectItem.m_connectName); - return; -} - -QString VpnListItem::getConnectionPath() -{ - return m_vpnConnectItem.m_connectPath; -} - -void VpnListItem::updateConnectionPath(QString connectionPath) -{ - m_vpnConnectItem.m_connectPath = connectionPath; -} diff --git a/src/frontend/list-items/vpnlistitem.h b/src/frontend/list-items/vpnlistitem.h deleted file mode 100644 index b65d22dc..00000000 --- a/src/frontend/list-items/vpnlistitem.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- 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 VPNLISTITEM_H -#define VPNLISTITEM_H -#include "listitem.h" -#include "kylinactiveconnectresource.h" - -#include -#include -#include - -#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" -#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" -#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" - -class VpnListItem : public ListItem -{ - Q_OBJECT - -public: - VpnListItem(const KyConnectItem *lanConnectItem, QWidget *parent = nullptr); - VpnListItem(QWidget *parent = nullptr); - - ~VpnListItem(); - -public: - void updateConnectionState(ConnectState state); - - QString getConnectionName(); - void updateConnectionName(QString connectionName); - - QString getConnectionPath(); - void updateConnectionPath(QString connectionPath); - - void activeConnection(); - -protected: - void setIcon(bool isOn); - void onRightButtonClicked(); - bool launchApp(QString desktopFile); - -private: - void connectItemCopy(const KyConnectItem *lanConnectItem); - -private Q_SLOTS: - void onInfoButtonClicked(); - void onNetButtonClicked(); - void onMenuTriggered(QAction *action); - -private: - KyConnectItem m_vpnConnectItem; -// QDBusInterface m_appManagerDbusInterface; - - KyWiredConnectOperation *m_connectOperation = nullptr; - KyNetworkDeviceResourse *m_deviceResource = nullptr; - - QString m_deviceName = ""; -}; - -#endif // VPNLISTITEM_H diff --git a/src/frontend/mainwindow.cpp b/src/frontend/mainwindow.cpp index 56fcf996..19a0ff29 100644 --- a/src/frontend/mainwindow.cpp +++ b/src/frontend/mainwindow.cpp @@ -153,6 +153,7 @@ void MainWindow::firstlyStart() { initWindowProperties(); initTransparency(); + registerTrayIcon(); initUI(); initDbusConnnect(); initWindowTheme(); @@ -228,6 +229,30 @@ void MainWindow::initWindowProperties() } } +/** + * @brief MainWindow::registerTrayIcon 注册托盘图标 + */ +void MainWindow::registerTrayIcon() +{ + m_registerCount++; + if (QSystemTrayIcon::isSystemTrayAvailable() || m_registerCount > 10) { + m_trayIcon = new QSystemTrayIcon(); + if (nullptr == m_trayIcon) { + qWarning()<< "分配空间trayIcon失败"; + return ; + } + m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); + m_trayIcon->setToolTip(QString(tr("kylin-nm"))); + + } else { + if (m_registerCount <= 10) { + QTimer::singleShot(m_intervalTime,[this] { + registerTrayIcon(); + }); + } + } +} + void MainWindow::paintEvent(QPaintEvent *event) { QPainter painter(this); @@ -323,17 +348,14 @@ void MainWindow::initTrayIcon() iconTimer = new QTimer(this); connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading); - m_trayIcon = new QSystemTrayIcon(); m_trayIconMenu = new QMenu(); m_showMainwindowAction = new QAction(tr("Show MainWindow"),this); m_showSettingsAction = new QAction(tr("Settings"),this); - m_trayIcon->setToolTip(QString(tr("Network tool"))); m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) ); // m_trayIconMenu->addAction(m_showMainwindowAction); m_trayIconMenu->addAction(m_showSettingsAction); m_trayIcon->setContextMenu(m_trayIconMenu); - m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); iconStatus = IconActiveType::LAN_CONNECTED; onRefreshTrayIcon(); @@ -875,6 +897,7 @@ void MainWindow::showCreateWiredConnectWidget(const QString devName) }); m_createPagePtrMap.insert(devName, netDetail); netDetail->show(); + netDetail->centerToScreen(); } void MainWindow::showAddOtherWlanWidget(QString devName) diff --git a/src/frontend/mainwindow.h b/src/frontend/mainwindow.h index b7bcb591..d16533b8 100644 --- a/src/frontend/mainwindow.h +++ b/src/frontend/mainwindow.h @@ -153,6 +153,7 @@ private: void paintWithTrans(); void initUI(); void initDbusConnnect(); + void registerTrayIcon(); void initTrayIcon(); void resetTrayIconTool(); @@ -200,6 +201,9 @@ private: NetworkMode *m_networkMode; + uint m_intervalTime = 100; + uint m_registerCount = 0; + public Q_SLOTS: void onShowMainWindow(int type); diff --git a/src/frontend/netdetails/ipv4page.h b/src/frontend/netdetails/ipv4page.h index f5e9a779..55c2be09 100644 --- a/src/frontend/netdetails/ipv4page.h +++ b/src/frontend/netdetails/ipv4page.h @@ -52,6 +52,8 @@ public: void stopLoading(); void showIpv4AddressConflict(bool isConflict); + QString getNetMaskText(QString text); + private: QComboBox *ipv4ConfigCombox; LineEdit *ipv4addressEdit; @@ -90,7 +92,6 @@ private: void configSave(); bool getTextEditState(QString text); bool netMaskIsValide(QString text); - QString getNetMaskText(QString text); bool checkConnectBtnIsEnabled(); void initConflictHintLable(); void initLoadingIcon(); diff --git a/src/frontend/netdetails/joinhiddenwifipage.cpp b/src/frontend/netdetails/joinhiddenwifipage.cpp index 4581e84f..51c0900b 100644 --- a/src/frontend/netdetails/joinhiddenwifipage.cpp +++ b/src/frontend/netdetails/joinhiddenwifipage.cpp @@ -274,3 +274,17 @@ void JoinHiddenWiFiPage::onPaletteChanged() } } +void JoinHiddenWiFiPage::centerToScreen() +{ + QDesktopWidget* m = QApplication::desktop(); + QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos())); + int desk_x = desk_rect.width(); + int desk_y = desk_rect.height(); + int x = this->width(); + int y = this->height(); +// this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); + kdk::WindowManager::setGeometry(this->windowHandle(), QRect(desk_x / 2 - x / 2 + desk_rect.left(), + desk_y / 2 - y / 2 + desk_rect.top(), + this->width(), + this->height())); +} diff --git a/src/frontend/netdetails/joinhiddenwifipage.h b/src/frontend/netdetails/joinhiddenwifipage.h index 1a9806d1..5f97b56b 100644 --- a/src/frontend/netdetails/joinhiddenwifipage.h +++ b/src/frontend/netdetails/joinhiddenwifipage.h @@ -24,7 +24,9 @@ #include #include #include +#include +#include "windowmanager/windowmanager.h" #include "coninfo.h" #include "kywirelessconnectoperation.h" #include "securitypage.h" @@ -43,6 +45,7 @@ public: JoinHiddenWiFiPage(QString devName, KDialog *parent = nullptr); ~JoinHiddenWiFiPage(); + void centerToScreen(); protected: void closeEvent(QCloseEvent *event); diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index 9d727c8f..d470b264 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -270,11 +270,11 @@ void NetDetail::centerToScreen() int desk_y = desk_rect.height(); int x = this->width(); int y = this->height(); - this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); -// kdk::WindowManager::setGeometry(this->windowHandle(), QRect(desk_x / 2 - x / 2 + desk_rect.left(), -// desk_y / 2 - y / 2 + desk_rect.top(), -// this->width(), -// this->height())); +// this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); + kdk::WindowManager::setGeometry(this->windowHandle(), QRect(desk_x / 2 - x / 2 + desk_rect.left(), + desk_y / 2 - y / 2 + desk_rect.top(), + this->width(), + this->height())); } void NetDetail::initUI() @@ -651,22 +651,29 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived) kyConnectResourse->getConnectionSetting(m_uuid,connetSetting); connetSetting.dumpInfo(); - conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType; +// conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType; conInfo.ipv6ConfigType = connetSetting.m_ipv6ConfigIpType; conInfo.isAutoConnect = connetSetting.m_isAutoConnect; - if (connetSetting.m_ipv4ConfigIpType == CONFIG_IP_MANUAL) { - if (connetSetting.m_ipv4Address.size() > 0) { - conInfo.strIPV4Address = connetSetting.m_ipv4Address.at(0).ip().toString(); - conInfo.strIPV4NetMask = connetSetting.m_ipv4Address.at(0).netmask().toString(); - conInfo.strIPV4GateWay = connetSetting.m_ipv4Address.at(0).gateway().toString(); - } - if (connetSetting.m_ipv4Dns.size() == 1) { - conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString(); - } else if (connetSetting.m_ipv4Dns.size() > 1) { - conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString(); - conInfo.strIPV4SecDns = connetSetting.m_ipv4Dns.at(1).toString(); - } +// if (connetSetting.m_ipv4ConfigIpType == CONFIG_IP_MANUAL) { +// if (connetSetting.m_ipv4Address.size() > 0) { +// conInfo.strIPV4Address = connetSetting.m_ipv4Address.at(0).ip().toString(); +// conInfo.strIPV4NetMask = connetSetting.m_ipv4Address.at(0).netmask().toString(); +// conInfo.strIPV4GateWay = connetSetting.m_ipv4Address.at(0).gateway().toString(); +// } +// if (connetSetting.m_ipv4Dns.size() == 1) { +// conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString(); +// } else if (connetSetting.m_ipv4Dns.size() > 1) { +// conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString(); +// conInfo.strIPV4SecDns = connetSetting.m_ipv4Dns.at(1).toString(); +// } +// } + //openkylin从第三方库读取有问题 改为ipv4信息直接通过dbus获取 + KyConnectItem* item = kyConnectResourse->getConnectionItemByUuidWithoutActivateChecking(m_uuid); + if (item == nullptr) { + conInfo.ipv4ConfigType = CONFIG_IP_DHCP; + } else { + getIpv4Info(item->m_connectPath, conInfo); } if (connetSetting.m_ipv6ConfigIpType == CONFIG_IP_MANUAL) { @@ -1224,3 +1231,94 @@ void ThreadObject::checkIpv6ConflictThread(const QString &ipv6Address) ipv6rping = nullptr; Q_EMIT ipv6IsConflict(isConflict); } + +void NetDetail::getIpv4Info(QString objPath, ConInfo &conInfo) +{ + QDBusInterface m_interface("org.freedesktop.NetworkManager", + objPath, + "org.freedesktop.NetworkManager.Settings.Connection", + QDBusConnection::systemBus()); + QDBusMessage result = m_interface.call("GetSettings"); + + if (result.arguments().isEmpty()) { return; } + const QDBusArgument &dbusArg1st = result.arguments().at( 0 ).value(); + QMap> map; + dbusArg1st >> map; + + for (QString key : map.keys() ) { + QMap innerMap = map.value(key); + if (key == "ipv4") { + for (QString inner_key : innerMap.keys()) { + if (inner_key == "address-data") { + //ipv4地址 ipv4子网掩码 + const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value(); + QVector> addressVector; + + dbusArg2nd.beginArray(); + + while (!dbusArg2nd.atEnd()) { + QMap tempMap; + dbusArg2nd >> tempMap; + addressVector.append(tempMap); + } + dbusArg2nd.endArray(); + if (addressVector.size() >= 1) { + conInfo.strIPV4Address = addressVector.at(0).value("address").toString(); + conInfo.strIPV4NetMask = ipv4Page->getNetMaskText(addressVector.at(0).value("prefix").toString()); + } + } else if (inner_key == "method") { + //ipv4 method + if (innerMap.value(inner_key).toString() == "auto") + conInfo.ipv4ConfigType = CONFIG_IP_DHCP; + else { + conInfo.ipv4ConfigType = CONFIG_IP_MANUAL; + } + } else if (inner_key == "dns") { + //dns + const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value(); + QList addressVector; + + dbusArg2nd.beginArray(); + while (!dbusArg2nd.atEnd()) { + uint tempMap; + dbusArg2nd >> tempMap; + addressVector.append(tempMap); + } + dbusArg2nd.endArray(); + if (addressVector.size() == 1) { + QString dns(inet_ntoa(*(struct in_addr *)&addressVector.at(0))); + conInfo.strIPV4FirDns = dns; + } else if (addressVector.size() > 1) { + QString dns1(inet_ntoa(*(struct in_addr *)&addressVector.at(0))); + QString dns2(inet_ntoa(*(struct in_addr *)&addressVector.at(1))); + conInfo.strIPV4FirDns = dns1; + conInfo.strIPV4SecDns = dns2; + } + + } else if (inner_key == "gateway") { + //gateway + conInfo.strIPV4GateWay = innerMap.value(inner_key).toString(); + } + } + } + // if (key == "ipv6") { + // for (QString inner_key : innerMap.keys()) { + // if (inner_key == "address-data"){ + // const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value(); + // QMap m_map; + + // dbusArg2nd.beginArray(); + // while (!dbusArg2nd.atEnd()) { + // dbusArg2nd >> m_map;// append map to a vector here if you want to keep it + // } + // dbusArg2nd.endArray(); + + // dbusWifiIpv6 = m_map.value("address").toString(); + // } else if (inner_key == "method") { + // dbusWifiIpv6Method = innerMap.value(inner_key).toString(); + // } + // } + // } + } + +} diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index b7db854b..386a539d 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -51,6 +51,7 @@ #include "kwidget.h" #include "ktabbar.h" #include "networkmodeconfig.h" +#include using namespace kdk; @@ -95,13 +96,14 @@ public: NetDetail(QString interface, QString name, QString uuid, bool isActive, bool isWlan, bool isCreateNet, QWidget *parent = nullptr); ~NetDetail(); + void centerToScreen(); + void paintEvent(QPaintEvent *event); void closeEvent(QCloseEvent *event); bool eventFilter(QObject *w, QEvent *event); private: void initUI(); - void centerToScreen(); void initComponent(); void getConInfo(ConInfo &conInfo); void loadPage(); @@ -140,6 +142,8 @@ private: void startObjectThread(); void setNetTabToolTip(); + void getIpv4Info(QString objPath, ConInfo &conInfo); + private: KyNetworkDeviceResourse *m_netDeviceResource = nullptr; KyConnectOperation* m_connectOperation = nullptr; diff --git a/src/frontend/single-pages/single-pages.pri b/src/frontend/single-pages/single-pages.pri deleted file mode 100644 index 96c70dc5..00000000 --- a/src/frontend/single-pages/single-pages.pri +++ /dev/null @@ -1,10 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/vpnpage.h \ - $$PWD/singlepage.h - -SOURCES += \ - $$PWD/vpnpage.cpp \ - $$PWD/singlepage.cpp - diff --git a/src/frontend/single-pages/singlepage.cpp b/src/frontend/single-pages/singlepage.cpp deleted file mode 100644 index f3293a5e..00000000 --- a/src/frontend/single-pages/singlepage.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- 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 "singlepage.h" -#include -#include -#include -#include -#include - -SinglePage::SinglePage(QWidget *parent) : QWidget(parent) -{ - initUI(); -} - -SinglePage::~SinglePage() -{ - delete m_netDivider; -} - -void SinglePage::initUI() -{ - m_mainLayout = new QVBoxLayout(this); - m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); - m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING); - this->setLayout(m_mainLayout); - - m_netFrame = new QFrame(this); - m_netFrame->setMinimumHeight(TEXT_HEIGHT + 17); - m_netLayout = new QVBoxLayout(m_netFrame); - m_netLayout->setContentsMargins(NET_LAYOUT_MARGINS); - m_netFrame->setLayout(m_netLayout); - - m_netLabel = new QLabel(m_netFrame); - m_netLabel->setContentsMargins(TEXT_MARGINS); - m_netLabel->setFixedHeight(TEXT_HEIGHT); - - m_netListArea = new QWidget(m_netFrame); - m_netAreaLayout = new QVBoxLayout(m_netListArea); - m_netAreaLayout->setSpacing(MAIN_LAYOUT_SPACING); - m_netAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); - - m_netLayout->addWidget(m_netLabel); - m_netLayout->addWidget(m_netListArea); - - m_netDivider = new Divider(this); - m_settingsFrame = new QFrame(this); - m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT); - - m_settingsLayout = new QHBoxLayout(m_settingsFrame); - m_settingsLayout->setContentsMargins(SETTINGS_LAYOUT_MARGINS); - - m_settingsLabel = new KyLable(m_settingsFrame); - m_settingsLabel->setCursor(Qt::PointingHandCursor); - m_settingsLabel->setText(tr("Settings")); - m_settingsLabel->setScaledContents(true); - - m_settingsLayout->addWidget(m_settingsLabel); - m_settingsLayout->addStretch(); - m_settingsFrame->setLayout(m_settingsLayout); - - m_mainLayout->addWidget(m_netFrame); - m_mainLayout->addStretch(); - m_mainLayout->addWidget(m_netDivider); - m_mainLayout->addWidget(m_settingsFrame); -} - -void SinglePage::showDesktopNotify(const QString &message, QString soundName) -{ - QDBusInterface iface("org.freedesktop.Notifications", - "/org/freedesktop/Notifications", - "org.freedesktop.Notifications", - QDBusConnection::sessionBus()); - QStringList actions; //跳转动作 - actions.append("kylin-nm"); - actions.append("default"); //默认动作:点击消息体时打开麒麟录音 - QMap hints; - if (!soundName.isEmpty()) { - hints.insert("sound-name",soundName); //添加声音 - } - QList args; - args<<(tr("Kylin NM")) - <<((unsigned int) 0) - < -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "kylinnetworkdeviceresource.h" -#include "firewalldialog.h" -#include "kwidget.h" -#include "kswitchbutton.h" -//#include "kborderlessbutton.h" - -using namespace kdk; - -#define MAIN_LAYOUT_MARGINS 0,0,0,0 -#define MAIN_LAYOUT_SPACING 0 -#define TITLE_FRAME_HEIGHT 50 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度 -#define NET_LAYOUT_MARGINS 8,8,0,1 -#define NET_LAYOUT_SPACING 8 -#define NET_LIST_SPACING 0 -#define TEXT_MARGINS 16,0,0,0 -#define TEXT_HEIGHT 20 -//#define SCROLL_AREA_HEIGHT 200 -#define SETTINGS_LAYOUT_MARGINS 23,0,24,0 -#define TRANSPARENT_COLOR QColor(0,0,0,0) -#define INACTIVE_AREA_MIN_HEIGHT 170 - -#define MAX_ITEMS 4 -#define MAX_WIDTH 412 -#define MIN_WIDTH 404 - -#define SCROLL_STEP 4 - -class SinglePage : public QWidget -{ - Q_OBJECT -public: - explicit SinglePage(QWidget *parent = nullptr); - ~SinglePage(); - - static void showDesktopNotify(const QString &message, QString soundName); - - void hideSetting() { - if (nullptr != m_settingsFrame) { - m_settingsFrame->hide(); - m_netDivider->hide(); - m_netFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT + 100); - } - } - void showSetting() { - if (nullptr != m_settingsFrame) { - m_netFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT); - m_settingsFrame->show(); - m_netDivider->show(); - } - } - -Q_SIGNALS: - void activateFailed(QString errorMessage); - void deactivateFailed(QString errorMessage); - -protected: - void initUI(); - QVBoxLayout * m_mainLayout = nullptr; - - QFrame * m_netFrame = nullptr; - QVBoxLayout * m_netLayout = nullptr; - QLabel * m_netLabel = nullptr; - QWidget * m_netListArea = nullptr; - QVBoxLayout * m_netAreaLayout = nullptr; - - Divider * m_netDivider = nullptr; - - QFrame * m_settingsFrame = nullptr; - QHBoxLayout * m_settingsLayout = nullptr; - KyLable * m_settingsLabel = nullptr; - -}; - -#endif // TABPAGE_H diff --git a/src/frontend/single-pages/vpnpage.cpp b/src/frontend/single-pages/vpnpage.cpp deleted file mode 100644 index 36d21c69..00000000 --- a/src/frontend/single-pages/vpnpage.cpp +++ /dev/null @@ -1,645 +0,0 @@ -/* -*- 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 "vpnpage.h" -#include "networkmodeconfig.h" -#include -#include - -#define VPN_LIST_SPACING 0 -#define ITEM_HEIGHT 48 - - -#define LOG_FLAG "[VpnPage]" - -const QString EMPTY_CONNECT_UUID = "emptyconnect"; - -const QString WIRED_SWITCH = "wiredswitch"; - -VpnPage::VpnPage(QWidget *parent) : SinglePage(parent) -{ - m_activeResourse = new KyActiveConnectResourse(this); - m_connectResourse = new KyConnectResourse(this); -// m_deviceResource = new KyNetworkDeviceResourse(this); - m_wiredConnectOperation = new KyWiredConnectOperation(this); - - initUI(); - initVpnArea(); - - connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &VpnPage::onConnectionStateChange); - connect(m_activeResourse, &KyActiveConnectResourse::activeConnectRemove, this, [=] (QString activeConnectUuid) { - sendVpnStateChangeSignal(activeConnectUuid,Deactivated); - } ); - - connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &VpnPage::onAddConnection); - connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &VpnPage::onRemoveConnection); - connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &VpnPage::onUpdateConnection); - - connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &VpnPage::activateFailed); - connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &VpnPage::deactivateFailed); -} - -VpnPage::~VpnPage() -{ - -} - -void VpnPage::deleteConnectionMapItem(QMap &connectMap, - QListWidget *lanListWidget, QString uuid) -{ - QListWidgetItem *p_listWidgetItem = connectMap.value(uuid); - if (p_listWidgetItem) { - connectMap.remove(uuid); - VpnListItem *p_lanItem = (VpnListItem *)lanListWidget->itemWidget(p_listWidgetItem); - lanListWidget->removeItemWidget(p_listWidgetItem); - - delete p_lanItem; - p_lanItem = nullptr; - - delete p_listWidgetItem; - p_listWidgetItem = nullptr; - } - - return; -} - -void VpnPage::clearConnectionMap(QMap &connectMap, - QListWidget *lanListWidget) -{ - QMap::iterator iter; - - iter = connectMap.begin(); - while (iter != connectMap.end()) { - qDebug()<<"[VpnPage] clear connection map item"<< iter.key(); - - QListWidgetItem *p_widgetItem = iter.value(); - VpnListItem *p_lanItem = (VpnListItem *)lanListWidget->itemWidget(p_widgetItem); - lanListWidget->removeItemWidget(p_widgetItem); - - delete p_lanItem; - p_lanItem = nullptr; - - delete p_widgetItem; - p_widgetItem = nullptr; - - iter = connectMap.erase(iter); - } - - return; -} - -void VpnPage::constructActiveConnectionArea() -{ - QList activedList; - QList netList; - QGSettings* vpnGsettings = nullptr; - if (QGSettings::isSchemaInstalled(GSETTINGS_VPNICON_VISIBLE)) { - vpnGsettings = new QGSettings(GSETTINGS_VPNICON_VISIBLE); - } - activedList.clear(); - netList.clear(); - clearConnectionMap(m_activeConnectionMap, m_vpnListWidget); - - m_connectResourse->getVpnAndVirtualConnections(netList); - KyConnectItem *p_newItem = nullptr; - if (!netList.isEmpty()) { - for (int index = 0; index < netList.size(); index++) { - KyConnectItem *p_netConnectionItem = netList.at(index); - p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid); - if (p_newItem == nullptr) { - if (m_netConnectionMap.contains(p_netConnectionItem->m_connectUuid)) { - qDebug()<m_connectUuid; - } - QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_vpnListWidget); - m_netConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); - } else { - if (m_activeConnectionMap.contains(p_netConnectionItem->m_connectUuid)) { - qDebug()<m_connectUuid; - } - QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_vpnListWidget); - m_activeConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); - } - - delete p_netConnectionItem; - p_netConnectionItem = nullptr; - } - if (vpnGsettings != nullptr - && vpnGsettings->keys().contains(QString(VISIBLE))) { - vpnGsettings->set(VISIBLE, true); - } - } else { - if (vpnGsettings != nullptr - && vpnGsettings->keys().contains(QString(VISIBLE))) { - vpnGsettings->set(VISIBLE, false); - } - } - - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); - m_netListArea->setFixedHeight(m_vpnListWidget->count() * ITEM_HEIGHT); - } else { - m_vpnListWidget->setFixedWidth(MAX_WIDTH); - m_netListArea->setFixedHeight(MAX_ITEMS * ITEM_HEIGHT); - } - m_netFrame->setFixedHeight(37 + m_netListArea->height()); - - delete vpnGsettings; - vpnGsettings = nullptr; -} - -void VpnPage::initVpnArea() -{ - m_netFrame->show(); - constructActiveConnectionArea(); -} - -bool VpnPage::removeConnectionItem(QMap &connectMap, - QListWidget *lanListWidget, QString path) -{ - QMap::iterator iter; - for (iter = connectMap.begin(); iter != connectMap.end(); ++iter) { - QListWidgetItem *p_listWidgetItem = iter.value(); - VpnListItem *p_lanItem = (VpnListItem*)lanListWidget->itemWidget(p_listWidgetItem); - if (p_lanItem->getConnectionPath() == path) { - qDebug()<<"[VpnPage] Remove a connection from list"; - - lanListWidget->removeItemWidget(p_listWidgetItem); - - delete p_lanItem; - p_lanItem = nullptr; - - delete p_listWidgetItem; - p_listWidgetItem = nullptr; - - iter = connectMap.erase(iter); - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); - m_netListArea->setFixedHeight(m_vpnListWidget->count() * ITEM_HEIGHT); - } - return true; - } - } - - return false; -} - -void VpnPage::onRemoveConnection(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除 -{ - //for dbus - qDebug() << "[VpnPage] emit lanRemove because onRemoveConnection " << path; - Q_EMIT vpnRemove(path); - - if (removeConnectionItem(m_netConnectionMap, m_vpnListWidget, path)) { - m_netFrame->setFixedHeight(37 + m_netListArea->height()); - return; - } -} - -void VpnPage::onAddConnection(QString uuid) //新增一个有线连接,将其加入到激活列表 -{ - if (!m_connectResourse->isVirtualConncection(uuid)) { - return; - } - - KyConnectItem *p_newItem = nullptr; - p_newItem = m_connectResourse->getConnectionItemByUuid(uuid); - if (nullptr == p_newItem) { - return; - } - - sendVpnAddSignal(p_newItem); - - qDebug()<<"[VpnPage] Add a new connection, name:"<m_connectName; - QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_vpnListWidget); - if (m_netConnectionMap.contains(p_newItem->m_connectUuid)) { - qDebug()<m_connectUuid; - } - m_netConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); - - delete p_newItem; - p_newItem = nullptr; - if (m_vpnListWidget->count() >= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MAX_WIDTH); - m_netListArea->setFixedHeight(MAX_ITEMS * ITEM_HEIGHT); - } else { - m_netListArea->setFixedHeight(m_vpnListWidget->count() * ITEM_HEIGHT); - } - m_netFrame->setFixedHeight(37 + m_netListArea->height()); - return; -} - -void VpnPage::onShowControlCenter() -{ - QProcess process; - process.startDetached("ukui-control-center -m vpn"); -} - -void VpnPage::initUI() -{ - m_netLabel->setText(tr("VPN Connection")); - m_vpnListWidget = new QListWidget(m_netListArea); - m_vpnListWidget->setFrameShape(QFrame::Shape::NoFrame); - m_vpnListWidget->setSpacing(VPN_LIST_SPACING); - m_vpnListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_vpnListWidget->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel); - m_vpnListWidget->verticalScrollBar()->setProperty("drawScrollBarGroove",false); //去除滚动条的外侧黑框 - m_vpnListWidget->verticalScrollBar()->setSingleStep(SCROLL_STEP); - m_vpnListWidget->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu); - m_netAreaLayout->addWidget(m_vpnListWidget); - m_netListArea->setFixedHeight(0); - - QPalette pal = m_vpnListWidget->palette(); - pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明 - m_vpnListWidget->setPalette(pal); - - m_settingsLabel->setText(tr("VPN Settings")); - m_settingsLabel->installEventFilter(this); -} - -QListWidgetItem *VpnPage::insertNewItem(KyConnectItem *itemData, QListWidget *listWidget) -{ - int index = 0; - - for(index = 0; index < m_vpnListWidget->count(); index++) { - QListWidgetItem *p_listWidgetItem = m_vpnListWidget->item(index); - VpnListItem *p_lanItem = (VpnListItem *)m_vpnListWidget->itemWidget(p_listWidgetItem); - QString name1 = p_lanItem->getConnectionName(); - QString name2 = itemData->m_connectName; - if (QString::compare(name1, name2, Qt::CaseInsensitive) > 0) { - break; - } - } - - QListWidgetItem *p_sortListWidgetItem = new QListWidgetItem(); - p_sortListWidgetItem->setFlags(p_sortListWidgetItem->flags() & (~Qt::ItemIsSelectable)); //设置不可被选中 - p_sortListWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT)); - - listWidget->insertItem(index, p_sortListWidgetItem); - - VpnListItem *p_sortLanItem = nullptr; - p_sortLanItem = new VpnListItem(itemData); - listWidget->setItemWidget(p_sortListWidgetItem, p_sortLanItem); - - return p_sortListWidgetItem; -} - -QListWidgetItem *VpnPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget) -{ - QListWidgetItem *p_listWidgetItem = new QListWidgetItem(); - p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); - p_listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT)); - listWidget->addItem(p_listWidgetItem); - VpnListItem *p_lanItem = nullptr; - if (itemData != nullptr) { - p_lanItem = new VpnListItem(itemData); - qDebug() << "[VpnPage] addNewItem, connection: " << itemData->m_connectName; - } else { - p_lanItem = new VpnListItem(); - qDebug() << "[VpnPage] Add nullItem!"; - } - - listWidget->setItemWidget(p_listWidgetItem, p_lanItem); - return p_listWidgetItem; -} - -void VpnPage::updateActivatedConnectionArea(KyConnectItem *p_newItem) -{ - if (m_activeConnectionMap.contains(p_newItem->m_connectUuid)) { - return; - } - - deleteConnectionMapItem(m_netConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid); - qDebug()<<"[VpnPage]update active connection item"<m_connectName; - deleteConnectionMapItem(m_activeConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid); - QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_vpnListWidget); - m_activeConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); - } - - return; -} - -void VpnPage::updateConnectionArea(KyConnectItem *p_newItem) -{ - if (m_netConnectionMap.contains(p_newItem->m_connectUuid)) { - return; - } - - deleteConnectionMapItem(m_activeConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid); - qDebug()<<"[VpnPage] update connection item"<m_connectName; - QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_vpnListWidget); - m_netConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); - - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); - } else { - m_vpnListWidget->setFixedWidth(MAX_WIDTH); - } -} - -void VpnPage::updateConnectionState(QMap &connectMap, - QListWidget *lanListWidget, QString uuid, ConnectState state) -{ - qDebug() << LOG_FLAG << "update connection state"; - - QListWidgetItem *p_listWidgetItem = connectMap.value(uuid); - if (p_listWidgetItem) { - VpnListItem *p_lanItem = (VpnListItem *)lanListWidget->itemWidget(p_listWidgetItem); - p_lanItem->updateConnectionState(state); - } - -} - -void VpnPage::onConnectionStateChange(QString uuid, - NetworkManager::ActiveConnection::State state, - NetworkManager::ActiveConnection::Reason reason) -{ - //VpnPage函数内持续监听连接状态的变化并记录供其他函数调用获取状态 - if (!m_connectResourse->isVirtualConncection(uuid)) { - qDebug() << "[VpnPage] connection state change signal but not vpn"; - return; - } - - sendVpnStateChangeSignal(uuid, (ConnectState)state); - - if (m_activeConnectionMap.keys().contains(uuid) && state == NetworkManager::ActiveConnection::State::Activated) { - return; - } - - qDebug()<<"[VpnPage] connection uuid"<< uuid - << "state change slot:"<< state; - - KyConnectItem *p_newItem = nullptr; - QString deviceName = ""; - QString ssid = ""; - - if (state == NetworkManager::ActiveConnection::State::Activated) { - p_newItem = m_activeResourse->getActiveConnectionByUuid(uuid); - if (nullptr == p_newItem) { - qWarning()<<"[VpnPage] get active connection failed, connection uuid" << uuid; - return; - } - - ssid = p_newItem->m_connectName; - updateActivatedConnectionArea(p_newItem); - updateConnectionState(m_activeConnectionMap, m_vpnListWidget, uuid, (ConnectState)state); - } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { - p_newItem = m_connectResourse->getConnectionItemByUuid(uuid); - qDebug() << "[VpnPage] deactivated reason" << reason; - if (nullptr == p_newItem) { - qWarning()<<"[VpnPage] get active connection failed, connection uuid" << uuid; - return; - } - - ssid = p_newItem->m_connectName; - updateConnectionArea(p_newItem); - updateConnectionState(m_netConnectionMap, m_vpnListWidget, uuid, (ConnectState)state); - NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, deviceName, ssid); - } else if (state == NetworkManager::ActiveConnection::State::Activating) { - updateConnectionState(m_netConnectionMap, m_vpnListWidget, uuid, (ConnectState)state); - } else if (state == NetworkManager::ActiveConnection::State::Deactivating) { - updateConnectionState(m_activeConnectionMap, m_vpnListWidget, uuid, (ConnectState)state); - } - - Q_EMIT vpnActiveConnectionStateChanged(uuid, state); - - if (p_newItem) { - delete p_newItem; - p_newItem = nullptr; - } - - return; -} - -void VpnPage::getVirtualList(QVector &vector) -{ - QList netConnectList; - vector.clear(); - m_connectResourse->getVpnAndVirtualConnections(netConnectList); //未激活列表的显示 - if (!netConnectList.isEmpty()) { - for (int i = 0; i < netConnectList.size(); i++) { - KyConnectItem *p_newItem = nullptr; - KyConnectItem *p_netConnectionItem = netConnectList.at(i); - p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid); - NetworkManager::ActiveConnection::State state = p_netConnectionItem->m_connectState; - if (p_newItem != nullptr) { - state = NetworkManager::ActiveConnection::Activated; - } - vector.append(QStringList() << netConnectList.at(i)->m_connectName - << netConnectList.at(i)->m_connectUuid - << netConnectList.at(i)->m_connectPath - << QString::number(state)); - } - } - return; -} - -void VpnPage::sendVpnUpdateSignal(KyConnectItem *p_connectItem) -{ - QStringList info; - info << p_connectItem->m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath; - Q_EMIT vpnUpdate(info); - - return; -} - -void VpnPage::sendVpnAddSignal(KyConnectItem *p_connectItem) -{ - QStringList info; - KyConnectItem *p_newItem = nullptr; - p_newItem = m_activeResourse->getActiveConnectionByUuid(p_connectItem->m_connectUuid); - NetworkManager::ActiveConnection::State state = p_connectItem->m_connectState; - if (p_newItem != nullptr) { - state = NetworkManager::ActiveConnection::Activated; - } - info << p_connectItem->m_connectName - << p_connectItem->m_connectUuid - << p_connectItem->m_connectPath - << QString::number(state); - qDebug() << "[VpnPage] emit vpnAdd because addConnection "; - Q_EMIT vpnAdd(info); - - return; -} - -void VpnPage::sendVpnStateChangeSignal(QString uuid, ConnectState state) -{ - if (state == Activating || state == Deactivating) { - if (m_activeResourse->connectionIsVirtual(uuid)) { - return; - } - } - - Q_EMIT this->vpnConnectChanged(state); - - return; -} - -void VpnPage::updateConnectionProperty(KyConnectItem *p_connectItem) -{ - QString newUuid = p_connectItem->m_connectUuid; - - if (m_netConnectionMap.contains(newUuid)) { - QListWidgetItem *p_listWidgetItem = m_netConnectionMap.value(newUuid); - VpnListItem *p_lanItem = (VpnListItem*)m_vpnListWidget->itemWidget(p_listWidgetItem); - if (p_connectItem->m_connectName != p_lanItem->getConnectionName()){ - //只要名字改变就要删除,重新插入,主要是为了排序 - deleteConnectionMapItem(m_netConnectionMap, m_vpnListWidget, newUuid); - QListWidgetItem *p_sortListWidgetItem = insertNewItem(p_connectItem, m_vpnListWidget); - if (m_netConnectionMap.contains(newUuid)) { - qDebug()<m_connectPath != p_lanItem->getConnectionPath()) { - p_lanItem->updateConnectionPath(p_connectItem->m_connectPath); - } - } else if (!m_activeConnectionMap.contains(newUuid)){ - if (p_connectItem->m_ifaceName.isEmpty()) { - QListWidgetItem *p_listWidgetItem = insertNewItem(p_connectItem, m_vpnListWidget); - if (m_netConnectionMap.contains(newUuid)) { - qDebug()<m_connectUuid; - - if (m_activeConnectionMap.contains(newUuid)) { - QListWidgetItem *p_listWidgetItem = m_activeConnectionMap.value(newUuid); - VpnListItem *p_lanItem = (VpnListItem *)m_vpnListWidget->itemWidget(p_listWidgetItem); - if (p_lanItem->getConnectionName() != p_connectItem->m_connectName) { - p_lanItem->updateConnectionName(p_connectItem->m_connectName); - } - - if (p_lanItem->getConnectionName() != p_connectItem->m_connectPath) { - p_lanItem->updateConnectionPath(p_connectItem->m_connectPath); - } - } - return; -} - -void VpnPage::onUpdateConnection(QString uuid) -{ - if (!m_connectResourse->isVirtualConncection(uuid)) { - return; - } - - qDebug() << "[VpnPage]:Connection property Changed." << Q_FUNC_INFO << __LINE__; - - KyConnectItem *p_newItem = nullptr; - if (m_connectResourse->isActivatedConnection(uuid)) { - p_newItem = m_activeResourse->getActiveConnectionByUuid(uuid); - if (nullptr == p_newItem) { - qWarning()<<"[VpnPage] get item failed, when update activate connection." - <<"connection uuid" << uuid; - return; - } - - updateActiveConnectionProperty(p_newItem); - } else { - p_newItem = m_connectResourse->getConnectionItemByUuid(uuid); - if (nullptr == p_newItem) { - qWarning()<<"[VpnPage] get item failed, when update connection." - <<"connection uuid"<type() == QEvent::MouseButtonRelease) { - onShowControlCenter(); - } - } - - return QWidget::eventFilter(watched, event); -} - -void VpnPage::deleteVpn(const QString &connUuid) -{ - qDebug() << "[VpnPage] deleteVpn" << connUuid; - if (connUuid == nullptr) { - return; - } - m_wiredConnectOperation->deleteWiredConnect(connUuid); -} - -void VpnPage::activateVpn(const QString& connUuid) -{ - if (m_netConnectionMap.contains(connUuid)) { - qDebug() << "[VpnPage] activateVpn" << connUuid; - m_wiredConnectOperation->activateVpnConnection(connUuid); - } -} - -void VpnPage::deactivateVpn(const QString& connUuid) -{ - qDebug() << "[VpnPage] deactivateVpn" << connUuid; - QString name(""); - m_wiredConnectOperation->deactivateWiredConnection(name, connUuid); -} - -void VpnPage::showDetailPage(QString devName, QString uuid) -{ -#ifdef VPN_DETAIL - KyConnectItem *p_item = nullptr; - bool isActive = true; - - if (m_connectResourse->isActivatedConnection(uuid)) { - p_item = m_activeResourse->getActiveConnectionByUuid(uuid); - isActive = true; - } else { - p_item = m_connectResourse->getConnectionItemByUuid(uuid); - isActive = false; - } - - if (nullptr == p_item) { - qWarning()<<"[VpnPage] GetConnectionItemByUuid is empty when showDetailPage." - <<"device name"<m_connectName, uuid, isActive, false, false); - netDetail->show(); - - delete p_item; - p_item = nullptr; -#endif -} diff --git a/src/frontend/single-pages/vpnpage.h b/src/frontend/single-pages/vpnpage.h deleted file mode 100644 index 0b3c5fd8..00000000 --- a/src/frontend/single-pages/vpnpage.h +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- 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 VPNPAGE_H -#define VPNPAGE_H - -#include "divider.h" -#include -#include -#include -#include -#include -#include -#include - -#include "list-items/listitem.h" -#include "list-items/vpnlistitem.h" -#include "single-pages/singlepage.h" - -#define VPNPAGE_LAYOUT_MARGINS 0,0,0,0 - -#define VISIBLE "visible" -const QByteArray GSETTINGS_VPNICON_VISIBLE = "org.ukui.kylin-nm.vpnicon"; - -class VpnListItem; - -class VpnPage : public SinglePage -{ - Q_OBJECT -public: - explicit VpnPage(QWidget *parent = nullptr); - ~VpnPage(); - - //for dbus - void getVirtualList(QVector &vector); - void deleteVpn(const QString &connUuid); - void activateVpn(const QString& connUuid); - void deactivateVpn(const QString& connUuid); - void showDetailPage(QString devName, QString uuid); - -protected: - bool eventFilter(QObject *watched, QEvent *event); - -private: - void initUI(); - void initVpnArea(); - - inline void initDeviceCombox() { return; } - - QListWidgetItem *insertNewItem(KyConnectItem *itemData, QListWidget *listWidget); - QListWidgetItem *addNewItem(KyConnectItem *itemData, QListWidget *listWidget); - bool removeConnectionItem(QMap &connectMap, - QListWidget *lanListWidget, QString path); - - void constructActiveConnectionArea(); - - void updateConnectionArea(KyConnectItem *p_newItem); - void updateActivatedConnectionArea(KyConnectItem *p_newItem); - void updateConnectionState(QMap &connectMap, - QListWidget *lanListWidget, QString uuid, ConnectState state); - - void updateActiveConnectionProperty(KyConnectItem *p_connectItem); - void updateConnectionProperty(KyConnectItem *p_connectItem); - - void sendVpnUpdateSignal(KyConnectItem *p_connectItem); - void sendVpnAddSignal(KyConnectItem *p_connectItem); - void sendVpnStateChangeSignal(QString uuid, ConnectState state); - - void clearConnectionMap(QMap &connectMap, - QListWidget *lanListWidget); - void deleteConnectionMapItem(QMap &connectMap, - QListWidget *lanListWidget, QString uuid); - -Q_SIGNALS: - void vpnAdd(QStringList info); - void vpnRemove(QString dbusPath); - void vpnUpdate(QStringList info); - - void vpnActiveConnectionStateChanged(QString uuid, int status); - void vpnConnectChanged(int state); - -private Q_SLOTS: - void onConnectionStateChange(QString uuid, - NetworkManager::ActiveConnection::State state, - NetworkManager::ActiveConnection::Reason reason); - - void onAddConnection(QString uuid); - void onRemoveConnection(QString path); - void onUpdateConnection(QString uuid); - - void onShowControlCenter(); - -// void onStateChange(); - -private: - QListWidget * m_vpnListWidget = nullptr; - -// KyNetworkDeviceResourse *m_deviceResource = nullptr; - KyWiredConnectOperation *m_wiredConnectOperation = nullptr; - KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接 - KyConnectResourse *m_connectResourse = nullptr; //未激活的连接 - - QMap m_netConnectionMap; - QMap m_activeConnectionMap; - -public Q_SLOTS: - inline void onDeviceComboxIndexChanged(int currentIndex) { return; } -}; - -#endif // LANPAGE_H diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 0fbacef9..b8d0c94a 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -1262,6 +1262,7 @@ void LanPage::showDetailPage(QString devName, QString uuid) NetDetail *netDetail = new NetDetail(devName, p_item->m_connectName, uuid, isActive, false, false); m_lanPagePtrMap.insert(p_item->m_connectPath, netDetail); netDetail->show(); + netDetail->centerToScreen(); connect(netDetail, &NetDetail::detailPageClose, [&](QString deviceName, QString lanName, QString lanUuid){ if (lanUuid.isEmpty()) { diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 9b241d3e..bb1ea1f5 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -1492,6 +1492,7 @@ void WlanPage::showHiddenWlanPage(QString devName) m_joinHiddenWiFiPagePtrMap.insert(devName, hiddenWiFi); hiddenWiFi->show(); + hiddenWiFi->centerToScreen(); } void WlanPage::showDetailPage(QString devName, QString ssid) @@ -1521,6 +1522,7 @@ void WlanPage::showDetailPage(QString devName, QString ssid) } }); netDetail->show(); + netDetail->centerToScreen(); return; } diff --git a/src/frontend/vpnmainwindow.cpp b/src/frontend/vpnmainwindow.cpp deleted file mode 100644 index 4db5463d..00000000 --- a/src/frontend/vpnmainwindow.cpp +++ /dev/null @@ -1,495 +0,0 @@ -/* -*- 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 "vpnmainwindow.h" -#include "customstyle.h" -#include -#include -#include -#include -#include -#include - -#include "kylinnetworkdeviceresource.h" -#include "../backend/dbus-interface/kylinagentinterface.h" - -#include "ukuistylehelper/ukuistylehelper.h" -#include "windowmanager/windowmanager.h" -#include "kysdk/kysdk-system/libkysysinfo.h" - -#define MAINWINDOW_WIDTH 420 -#define MAINWINDOW_HEIGHT 300 -#define VPN_LAYOUT_MARGINS 0,12,0,12 -#define THEME_SCHAME "org.ukui.style" -#define COLOR_THEME "styleName" - -const QString v10Sp1 = "V10SP1"; -const QString intel = "V10SP1-edu"; - -#define KEY_PRODUCT_FEATURES "PRODUCT_FEATURES" - -#include -#include - -vpnMainWindow::vpnMainWindow(QWidget *parent): QMainWindow(parent) -{ - firstlyStart(); -} - -/** - * @brief vpnMainWindow::showMainwindow show主窗口,同时也作为dbus接口提供给外部组件调用 - */ -void vpnMainWindow::showMainwindow() -{ - if (!m_loadFinished) { - m_secondaryStartTimer->stop(); - secondaryStart(); - } - - /** - * 设置主界面跳过任务栏和分页器的属性,隐藏再次展示有可能辉冲刷掉该属性,需要展示时重新设置 - */ - QString platform = QGuiApplication::platformName(); - if(!platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) - { - const KWindowInfo info(this->winId(), NET::WMState); - if (!info.hasState(NET::SkipTaskbar) || !info.hasState(NET::SkipPager)) { - KWindowSystem::setState(this->winId(), NET::SkipTaskbar | NET::SkipPager); - } - } - this->showByWaylandHelper(); - this->raise(); - this->activateWindow(); -// Q_EMIT this->mainWindowVisibleChanged(true); -} - -/** - * @brief vpnMainWindow::hideMainwindow 隐藏主页面时要进行的操作,后续可以添加到此函数 - */ -void vpnMainWindow::hideMainwindow() -{ - this->hide(); -// Q_EMIT this->mainWindowVisibleChanged(false); -} - -///** -// * @brief vpnMainWindow::setWiredDefaultDevice 设置有线设备默认网卡 -// */ -//void vpnMainWindow::setWiredDefaultDevice(QString deviceName) -//{ -//// m_vpnPage->updateDefaultDevice(deviceName); -//} - -/** - * @brief MainWindow::firstlyStart 一级启动,执行重要且不耗时的启动操作 - */ -void vpnMainWindow::firstlyStart() -{ - initWindowProperties(); - initTransparency(); - initUI(); - initDbusConnnect(); - initWindowTheme(); - initTrayIcon(); - installEventFilter(this); - m_secondaryStartTimer = new QTimer(this); - connect(m_secondaryStartTimer, &QTimer::timeout, this, [ = ]() { - m_secondaryStartTimer->stop(); - secondaryStart();//满足条件后执行比较耗时的二级启动 - }); - m_secondaryStartTimer->start(5 * 1000); - - m_createPagePtrMap.clear(); -} - -/** - * @brief vpnMainWindow::secondaryStart 二级启动,可以将较耗时的初始化操作放到此处执行 - */ -void vpnMainWindow::secondaryStart() -{ - if (m_loadFinished) - return; - m_loadFinished = true; -} - -/** - * @brief vpnMainWindow::initPlatform 初始化平台信息 - */ -void vpnMainWindow::initPlatform() -{ - char* projectName = kdk_system_get_projectName(); - QString strProjectName(projectName); - free(projectName); - projectName = NULL; - if(v10Sp1.compare(strProjectName,Qt::CaseInsensitive) == 0) { - unsigned int feature = kdk_system_get_productFeatures(); - if (feature == 3) { - m_isShowInCenter = true; - } - } else if (intel.compare(strProjectName,Qt::CaseInsensitive) == 0) { - m_isShowInCenter = true; - } - qDebug() << "projectName" << projectName << m_isShowInCenter; -} - -/** - * @brief vpnMainWindow::initWindowProperties 初始化一些窗口属性 - */ -void vpnMainWindow::initWindowProperties() -{ - this->setWindowTitle(tr("kylin-vpn")); -// this->setFixedSize(MAINWINDOW_WIDTH, MAINWINDOW_HEIGHT); -// //绘制毛玻璃特效 -// this->setAttribute(Qt::WA_TranslucentBackground, true); //透明 - this->setProperty("needTranslucent", true); - this->setFocusPolicy(Qt::NoFocus); - - QString platform = QGuiApplication::platformName(); - if(!platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) - { - QPainterPath path; - auto rect = this->rect(); - // path.addRoundedRect(rect, 12, 12); - path.addRect(rect); - KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); //背景模糊 - } -} - -void vpnMainWindow::paintEvent(QPaintEvent *event) -{ - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; - painter.setPen(Qt::transparent); -} - -void vpnMainWindow::initTransparency() -{ - if(QGSettings::isSchemaInstalled(TRANSPARENCY_GSETTINGS)) { - m_transGsettings = new QGSettings(TRANSPARENCY_GSETTINGS); - if(m_transGsettings->keys().contains(QString("transparency"))) { - m_transparency = m_transGsettings->get("transparency").toDouble() + 0.15; - m_transparency = (m_transparency > 1) ? 1 : m_transparency; - connect(m_transGsettings, &QGSettings::changed, this, &vpnMainWindow::onTransChanged); - } - } -} - -void vpnMainWindow::onTransChanged() -{ - m_transparency = m_transGsettings->get("transparency").toDouble() + 0.15; - m_transparency = (m_transparency > 1) ? 1 : m_transparency; - paintWithTrans(); -} - -void vpnMainWindow::paintWithTrans() -{ - QPalette pal = this->palette(); - QColor color = qApp->palette().base().color(); - color.setAlphaF(m_transparency); - pal.setColor(QPalette::Window, color); - this->setPalette(pal); -} - -/** - * @brief vpnMainWindow::initUI 初始化窗口内控件 - */ -void vpnMainWindow::initUI() -{ - m_vpnWidget = new QWidget(this); - this->setCentralWidget(m_vpnWidget); - m_vpnLayout = new QVBoxLayout(m_vpnWidget); - m_vpnLayout->setContentsMargins(VPN_LAYOUT_MARGINS); - m_vpnWidget->setLayout(m_vpnLayout); - m_vpnWidget->setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明 解决切换黑屏问题 - - m_vpnPage = new VpnPage(m_vpnWidget); - m_vpnLayout->addWidget(m_vpnPage); - - paintWithTrans(); -} - -/** - * @brief vpnMainWindow::initTrayIcon 初始化托盘图标和托盘右键菜单 - */ -void vpnMainWindow::initTrayIcon() -{ - m_vpnTrayIcon = new QSystemTrayIcon(this); - m_vpnTrayIcon->setToolTip(QString(tr("vpn tool"))); - m_vpnTrayIcon->setIcon(QIcon::fromTheme("ukui-vpn-symbolic")); - initVpnIconVisible(); - connect(m_vpnTrayIcon, &QSystemTrayIcon::activated, this, &vpnMainWindow::onTrayIconActivated); -} - -void vpnMainWindow::initDbusConnnect() -{ - connect(m_vpnPage, &VpnPage::activateFailed, this, &vpnMainWindow::activateFailed); - connect(m_vpnPage, &VpnPage::deactivateFailed, this, &vpnMainWindow::deactivateFailed); - - connect(m_vpnPage, &VpnPage::vpnAdd, this, &vpnMainWindow::vpnAdd); - connect(m_vpnPage, &VpnPage::vpnRemove, this, &vpnMainWindow::vpnRemove); - connect(m_vpnPage, &VpnPage::vpnUpdate, this, &vpnMainWindow::vpnUpdate); - connect(m_vpnPage, &VpnPage::vpnActiveConnectionStateChanged, this, &vpnMainWindow::vpnActiveConnectionStateChanged); - //模式切换 - QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), - QString("/"), - QString("com.kylin.statusmanager.interface"), - QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool))); -} - -/** - * @brief vpnMainWindow::resetWindowPosition 重新计算窗口位置 - */ -void vpnMainWindow::resetWindowPosition() -{ - - if (m_isShowInCenter) { - QRect availableGeometry = qApp->primaryScreen()->availableGeometry(); - QRect rect((availableGeometry.width() - this->width())/2, (availableGeometry.height() - this->height())/2, - this->width(), this->height()); - kdk::WindowManager::setGeometry(this->windowHandle(), rect); - - return; - } - -#define MARGIN 4 -#define PANEL_TOP 1 -#define PANEL_LEFT 2 -#define PANEL_RIGHT 3 -//#define PANEL_BOTTOM 4 - if (!m_positionInterface) { - m_positionInterface = new QDBusInterface("org.ukui.panel", - "/panel/position", - "org.ukui.panel", - QDBusConnection::sessionBus()); - } - QRect rect; - QDBusReply reply = m_positionInterface->call("GetPrimaryScreenGeometry"); - //reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置 - if (!m_positionInterface->isValid() || !reply.isValid() || reply.value().size() < 5) { - qCritical() << QDBusConnection::sessionBus().lastError().message(); - kdk::WindowManager::setGeometry(this->windowHandle(), QRect(0, 0, this->width(), this->height())); - return; - } - QVariantList position_list = reply.value(); - int position = position_list.at(4).toInt(); - switch(position){ - case PANEL_TOP: - //任务栏位于上方 - rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, - position_list.at(1).toInt() + MARGIN, - this->width(), this->height()); - break; - //任务栏位于左边 - case PANEL_LEFT: - rect = QRect(position_list.at(0).toInt() + MARGIN, - position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, - this->width(), this->height()); - break; - //任务栏位于右边 - case PANEL_RIGHT: - rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, - position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, - this->width(), this->height()); - break; - //任务栏位于下方 - default: - rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, - position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, - this->width(), this->height()); - break; - } - kdk::WindowManager::setGeometry(this->windowHandle(), rect); - qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__; -} - -/** - * @brief vpnMainWindow::initWindowTheme 初始化窗口主题并创建信号槽 - */ -void vpnMainWindow::initWindowTheme() -{ - const QByteArray style_id(THEME_SCHAME); - if (QGSettings::isSchemaInstalled(style_id)) { - m_styleGsettings = new QGSettings(style_id); - connect(m_styleGsettings, &QGSettings::changed, this, &vpnMainWindow::onThemeChanged); - } else { - qWarning() << "Gsettings interface \"org.ukui.style\" is not exist!" << Q_FUNC_INFO << __LINE__; - } -} - -///** -// * @brief vpnMainWindow::showControlCenter 打开控制面板网络界面 -// */ -//void vpnMainWindow::showControlCenter() -//{ -// QProcess process; -// if (!m_vpnPage->lanIsConnected() && m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activated)){ -// process.startDetached("ukui-control-center -m wlanconnect"); -// } else { -// process.startDetached("ukui-control-center -m netconnect"); -// } -//} - -void vpnMainWindow::showByWaylandHelper() -{ - //去除窗管标题栏,传入参数为QWidget* - kdk::UkuiStyleHelper::self()->removeHeader(this); - this->show(); - getTabletMode(); - resetWindowPosition(); - //设置窗体位置,传入参数为QWindow*,QRect - -} - -void vpnMainWindow::getTabletMode() -{ -// QDBusInterface interface(QString("com.kylin.statusmanager.interface"), -// QString("/"), -// QString("com.kylin.statusmanager.interface"), -// QDBusConnection::sessionBus()); -// if(!interface.isValid()) { -// m_isShowInCenter = true; -// return; -// } -// QDBusReply reply = interface.call("get_current_tabletmode"); -// if (!reply.isValid()) { -// m_isShowInCenter = true; -// return; -// } -// m_isShowInCenter = reply.value(); -} - -/** - * @brief vpnMainWindow::onTrayIconActivated 点击托盘图标的槽函数 - */ -void vpnMainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason) -{ - switch(reason) { -// case QSystemTrayIcon::Context: -// m_vpnTrayIconMenu->popup(QCursor::pos()); -// break; - case QSystemTrayIcon::Trigger: - if (this->isVisible()) { - qDebug() << "Received signal of tray icon activated, will hide mainwindow." << Q_FUNC_INFO << __LINE__; - hideMainwindow(); - return; - } - qDebug() << "Received signal of tray icon activated, will show mainwindow." << Q_FUNC_INFO << __LINE__; - this->showMainwindow(); - break; - - default: - break; - } -} - -void vpnMainWindow::onThemeChanged(const QString &key) -{ - if (key == COLOR_THEME) { - qDebug() << "Received signal of theme changed, will reset theme." << Q_FUNC_INFO << __LINE__; - paintWithTrans(); - Q_EMIT qApp->paletteChanged(qApp->palette()); - } else { - qDebug() << "Received signal of theme changed, key=" << key << " will do nothing." << Q_FUNC_INFO << __LINE__; - } -} - -void vpnMainWindow::onTabletModeChanged(bool mode) -{ - qDebug() << "TabletMode change" << mode; - Q_UNUSED(mode) - //模式切换时,隐藏主界面 - hideMainwindow(); -} - -void vpnMainWindow::onShowMainWindow() -{ - if(QApplication::activeWindow() != this) { - this->showMainwindow(); - } -} - -/** - * @brief vpnMainWindow::keyPressEvent 按esc键关闭主界面 - * @param event - */ -void vpnMainWindow::keyPressEvent(QKeyEvent *event) -{ - if (event->key() == Qt::Key_Escape) { - hideMainwindow(); - } - return QWidget::keyPressEvent(event); -} - -/** - * @brief vpnMainWindow::eventFilter 事件过滤器 - * @param watched - * @param event - * @return - */ -bool vpnMainWindow::eventFilter(QObject *watched, QEvent *event) -{ - if (event->type() == QEvent::ActivationChange) { - if(QApplication::activeWindow() != this) { - hideMainwindow(); - } - } - return QMainWindow::eventFilter(watched,event); -} - -void vpnMainWindow::getVirtualList(QVector &vector) -{ - vector.clear(); - if (nullptr != m_vpnPage) { - m_vpnPage->getVirtualList(vector); - } -} - -//Vpn连接删除 -void vpnMainWindow::deleteVpn(const QString &connUuid) -{ - m_vpnPage->deleteVpn(connUuid); -} - -//Vpn连接断开 -void vpnMainWindow::activateVpn(const QString& connUuid) -{ - m_vpnPage->activateVpn(connUuid); -} -void vpnMainWindow::deactivateVpn(const QString& connUuid) -{ - m_vpnPage->deactivateVpn(connUuid); -} - -void vpnMainWindow::onVpnIconVisibleChanged() -{ - m_vpnTrayIcon->setVisible(m_vpnGsettings->get("visible").toBool()); -} - -void vpnMainWindow::initVpnIconVisible() -{ - if(QGSettings::isSchemaInstalled(GSETTINGS_VPNICON_VISIBLE)) { - m_vpnGsettings = new QGSettings(GSETTINGS_VPNICON_VISIBLE); - if(m_vpnGsettings->keys().contains(QString(VISIBLE))) { - connect(m_vpnGsettings, &QGSettings::changed, this, &vpnMainWindow::onVpnIconVisibleChanged); - m_vpnTrayIcon->setVisible(m_vpnGsettings->get("visible").toBool()); - } - } -} - - diff --git a/src/frontend/vpnmainwindow.h b/src/frontend/vpnmainwindow.h deleted file mode 100644 index 8630d8dc..00000000 --- a/src/frontend/vpnmainwindow.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- 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 VPNMAINWINDOW_H -#define VPNMAINWINDOW_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "vpnpage.h" -#include "mainwindow.h" - -class VpnPage; - -class vpnMainWindow : public QMainWindow -{ - Q_OBJECT -public: - explicit vpnMainWindow(QWidget *parent = nullptr); - void showMainwindow(); - void hideMainwindow(); - - void getVirtualList(QVector &vector); - - - //Vpn连接删除 - void deleteVpn(const QString &connUuid); -// //有线连接断开 - void activateVpn(const QString& connUuid); - void deactivateVpn(const QString& connUuid); - - void initVpnIconVisible(); - - //唤起新建有线连接界面 -// void showCreateWiredConnectWidget(const QString devName); - -Q_SIGNALS: - void vpnAdd(QStringList info); - void vpnRemove(QString dbusPath); - void vpnUpdate(QStringList info); - void vpnActiveConnectionStateChanged(QString uuid, int status); - void activateFailed(QString errorMessage); - void deactivateFailed(QString errorMessage); - void mainWindowVisibleChanged(const bool &visible); - -protected: - void keyPressEvent(QKeyEvent *event); - bool eventFilter(QObject *watched, QEvent *event) override; - void paintEvent(QPaintEvent *event); - -private: - void firstlyStart(); //一级启动 - void secondaryStart(); //二级启动 - bool m_loadFinished = false; //是否二级启动已执行完 - QTimer * m_secondaryStartTimer = nullptr; //执行二级启动的倒计时 - void initPlatform(); - void initWindowProperties(); - void initTransparency(); - void paintWithTrans(); - void initUI(); - void initDbusConnnect(); - void initTrayIcon(); - void initWindowTheme(); - void showByWaylandHelper(); - void getTabletMode(); - - double m_transparency=1.0; //透明度 - QGSettings * m_transGsettings; //透明度配置文件 - QGSettings * m_vpnGsettings; //VPN配置文件 - -// //主窗口的主要构成控件 - QWidget * m_vpnWidget = nullptr; - VpnPage * m_vpnPage = nullptr; - QVBoxLayout * m_vpnLayout = nullptr; - - //监听主题的Gsettings - QGSettings * m_styleGsettings = nullptr; - -// //获取和重置窗口位置 - void resetWindowPosition(); - QDBusInterface * m_positionInterface = nullptr; - -// //托盘图标,托盘图标右键菜单 - QSystemTrayIcon * m_vpnTrayIcon = nullptr; - QMenu * m_vpnTrayIconMenu = nullptr; - - bool m_isShowInCenter = false; - - IconActiveType m_iconStatus = IconActiveType::NOT_CONNECTED; - - QMap m_createPagePtrMap; - -public Q_SLOTS: - void onShowMainWindow(); - -private Q_SLOTS: - void onTransChanged(); - void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason); - void onThemeChanged(const QString &key); - void onTabletModeChanged(bool mode); - void onVpnIconVisibleChanged(); -}; - -#endif // MAINWINDOW_H diff --git a/src/main.cpp b/src/main.cpp index e8660476..1eff8ac7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) // window_hints.decorations = MWM_DECOR_BORDER; // XAtomHelper::getInstance()->setWindowMotifHint(w.winId(), window_hints); -// w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint /*| Qt::X11BypassWindowManagerHint*/); + w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint /*| Qt::X11BypassWindowManagerHint*/); DbusAdaptor adaptor(&w); From 7e19f3e51df586990670728a39cdad194dd7607e Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Fri, 7 Apr 2023 14:20:19 +0800 Subject: [PATCH 03/10] =?UTF-8?q?tablet=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/component/InfoButton/infobutton.cpp | 1 + plugins/netconnect/deviceframe.cpp | 1 + plugins/netconnect/lanitem.cpp | 71 +++ plugins/netconnect/lanitem.h | 21 +- plugins/netconnect/netconnect.cpp | 65 ++- plugins/netconnect/netconnect.h | 3 +- plugins/vpn/itemframe.cpp | 63 --- plugins/vpn/itemframe.h | 47 -- plugins/vpn/translations/zh_CN.qm | Bin 594 -> 0 bytes plugins/vpn/translations/zh_CN.ts | 80 --- plugins/vpn/vpn.cpp | 497 ------------------ plugins/vpn/vpn.h | 119 ----- plugins/vpn/vpn.pro | 50 -- plugins/vpn/vpn.ui | 112 ---- plugins/vpn/vpnitem.cpp | 187 ------- plugins/vpn/vpnitem.h | 88 ---- plugins/wlanconnect/deviceframe.cpp | 1 + plugins/wlanconnect/wlanconnect.cpp | 27 +- plugins/wlanconnect/wlanconnect.h | 2 +- plugins/wlanconnect/wlanitem.cpp | 1 + .../kyenterpricesettinginfo.cpp | 144 +++++ .../dbus-interface/kyenterpricesettinginfo.h | 90 ++++ .../dbus-interface/kylinconnectresource.cpp | 2 + .../dbus-interface/kylinconnectsetting.cpp | 23 +- .../dbus-interface/kylinconnectsetting.h | 6 +- .../kywirelessconnectoperation.cpp | 319 +++++++++++ .../kywirelessconnectoperation.h | 15 + .../dbus-interface/kywirelessnetresource.cpp | 113 ++++ .../dbus-interface/kywirelessnetresource.h | 3 + src/backend/dbusadaptor.cpp | 12 + src/backend/dbusadaptor.h | 2 + .../enterprise-wlan/enterprisewlandialog.cpp | 29 +- src/frontend/mainwindow.cpp | 33 +- src/frontend/mainwindow.h | 2 + src/frontend/netdetails/coninfo.h | 22 +- src/frontend/netdetails/creatnetpage.cpp | 63 +-- src/frontend/netdetails/creatnetpage.h | 5 +- src/frontend/netdetails/detailpage.cpp | 6 +- src/frontend/netdetails/detailpage.h | 2 +- src/frontend/netdetails/ipv4page.cpp | 88 +--- src/frontend/netdetails/ipv4page.h | 11 +- src/frontend/netdetails/ipv6page.cpp | 87 +-- src/frontend/netdetails/ipv6page.h | 11 +- src/frontend/netdetails/netdetail.cpp | 110 +++- src/frontend/netdetails/netdetail.h | 3 + src/frontend/netdetails/netdetails.pri | 2 + src/frontend/netdetails/securitypage.cpp | 438 +++++++++++++-- src/frontend/netdetails/securitypage.h | 23 + src/frontend/tab-pages/lanpage.cpp | 9 + src/frontend/tab-pages/lanpage.h | 1 + src/frontend/tools/infobutton.cpp | 1 + src/frontend/tools/radioitembutton.cpp | 1 + src/frontend/tools/tools.pri | 2 + src/frontend/wificonfigdialog.cpp | 1 + 54 files changed, 1562 insertions(+), 1553 deletions(-) delete mode 100644 plugins/vpn/itemframe.cpp delete mode 100644 plugins/vpn/itemframe.h delete mode 100644 plugins/vpn/translations/zh_CN.qm delete mode 100644 plugins/vpn/translations/zh_CN.ts delete mode 100644 plugins/vpn/vpn.cpp delete mode 100644 plugins/vpn/vpn.h delete mode 100644 plugins/vpn/vpn.pro delete mode 100644 plugins/vpn/vpn.ui delete mode 100644 plugins/vpn/vpnitem.cpp delete mode 100644 plugins/vpn/vpnitem.h diff --git a/plugins/component/InfoButton/infobutton.cpp b/plugins/component/InfoButton/infobutton.cpp index 27a33f98..edb8b2db 100644 --- a/plugins/component/InfoButton/infobutton.cpp +++ b/plugins/component/InfoButton/infobutton.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #define BUTTON_SIZE 36,36 #define ICON_SIZE 16,16 diff --git a/plugins/netconnect/deviceframe.cpp b/plugins/netconnect/deviceframe.cpp index 31a3ea5a..a90e9f67 100644 --- a/plugins/netconnect/deviceframe.cpp +++ b/plugins/netconnect/deviceframe.cpp @@ -18,6 +18,7 @@ * */ #include "deviceframe.h" +#include #define LAYOUT_MARGINS 16,0,16,0 #define FRAME_HEIGHT 58 diff --git a/plugins/netconnect/lanitem.cpp b/plugins/netconnect/lanitem.cpp index 2df49237..70a845c8 100644 --- a/plugins/netconnect/lanitem.cpp +++ b/plugins/netconnect/lanitem.cpp @@ -45,11 +45,28 @@ LanItem::LanItem(bool isAcitve, QWidget *parent) statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // statusLabel->setMinimumSize(36,36); infoLabel = new GrayInfoButton(this); + + //【更多】菜单 + m_moreButton = new QToolButton(this); + m_moreButton->setProperty("useButtonPalette", true); + m_moreButton->setPopupMode(QToolButton::InstantPopup); + m_moreButton->setAutoRaise(true); + m_moreButton->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic")); + m_moreMenu = new QMenu(m_moreButton); + m_connectAction = new QAction(m_moreMenu); + m_deleteAction = new QAction(tr("Delete"), m_moreMenu); + setConnectActionText(isAcitve); + + m_moreMenu->addAction(m_connectAction); + m_moreMenu->addAction(m_deleteAction); + m_moreButton->setMenu(m_moreMenu); + mLanLyt->addWidget(iconLabel); mLanLyt->addWidget(titileLabel,Qt::AlignLeft); mLanLyt->addStretch(); mLanLyt->addWidget(statusLabel); mLanLyt->addWidget(infoLabel); + mLanLyt->addWidget(m_moreButton); loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic")); loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic")); @@ -60,6 +77,9 @@ LanItem::LanItem(bool isAcitve, QWidget *parent) loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic")); waitTimer = new QTimer(this); connect(waitTimer, &QTimer::timeout, this, &LanItem::updateIcon); + connect(m_connectAction, &QAction::triggered, this, &LanItem::onConnectTriggered); + connect(m_deleteAction, &QAction::triggered, this, &LanItem::onDeletetTriggered); + m_moreMenu->installEventFilter(this); } LanItem::~LanItem() @@ -67,6 +87,8 @@ LanItem::~LanItem() } + + void LanItem::updateIcon() { if (currentIconIndex > 6) { @@ -87,6 +109,40 @@ void LanItem::stopLoading(){ loading = false; } +/** + * @brief LanItem::setConnectActionText + * 【更多】菜单状态切换 连接/断开 + * @param isAcitve + */ +void LanItem::setConnectActionText(bool isAcitve) +{ + if (isAcitve) { + m_connectAction->setText(tr("Disconnect")); + } else { + m_connectAction->setText(tr("Connect")); + } +} + +void LanItem::onConnectTriggered() +{ + if (!m_connectAction) { + return; + } + if (m_connectAction->text() == tr("Connect")) { + Q_EMIT connectActionTriggered(); + } else if (m_connectAction->text() == tr("Disconnect")) { + Q_EMIT disconnectActionTriggered(); + } +} + +void LanItem::onDeletetTriggered() +{ + if (!m_deleteAction) { + return; + } + Q_EMIT deleteActionTriggered(); +} + void LanItem::paintEvent(QPaintEvent *event) { QPalette pal = qApp->palette(); @@ -107,3 +163,18 @@ void LanItem::paintEvent(QPaintEvent *event) QPushButton::paintEvent(event); } +bool LanItem::eventFilter(QObject *watched, QEvent *event) +{ + //菜单右边界与按钮右边界对齐 + if (event->type() == QEvent::Show && watched == m_moreMenu) { + int menuXPos = m_moreMenu->pos().x(); + int menuWidth = m_moreMenu->size().width(); + int btnWidth = m_moreButton->size().width(); + + QPoint pos = QPoint (menuXPos - menuWidth + btnWidth, m_moreMenu->pos().y()); + m_moreMenu->move(pos); + return true; + } + return false; +} + diff --git a/plugins/netconnect/lanitem.h b/plugins/netconnect/lanitem.h index ea1b1355..b27a9df2 100644 --- a/plugins/netconnect/lanitem.h +++ b/plugins/netconnect/lanitem.h @@ -29,12 +29,16 @@ #include #include #include +#include +#include +#include #include "fixlabel.h" //#include "infobutton.h" #include "../component/AddBtn/grayinfobutton.h" class LanItem : public QPushButton { + Q_OBJECT public: LanItem(bool isAcitve, QWidget *parent = nullptr); ~LanItem(); @@ -43,10 +47,15 @@ public: GrayInfoButton * infoLabel = nullptr; FixLabel * titileLabel = nullptr; QLabel * statusLabel = nullptr; + QToolButton* m_moreButton = nullptr; + QMenu* m_moreMenu = nullptr; + QAction* m_connectAction = nullptr; + QAction* m_deleteAction = nullptr; public: void startLoading(); void stopLoading(); + void setConnectActionText(bool isAcitve); bool loading = false; bool isAcitve = false; @@ -56,15 +65,23 @@ public: protected: void paintEvent(QPaintEvent *); + bool eventFilter(QObject *watched, QEvent *event); private: QTimer *waitTimer = nullptr; QGSettings *themeGsettings = nullptr; QList loadIcons; - int currentIconIndex=0; + int currentIconIndex=0; private slots: - void updateIcon(); + void updateIcon(); + void onConnectTriggered(); + void onDeletetTriggered(); + +Q_SIGNALS: + void connectActionTriggered(); + void disconnectActionTriggered(); + void deleteActionTriggered(); }; diff --git a/plugins/netconnect/netconnect.cpp b/plugins/netconnect/netconnect.cpp index 71bb66ee..fe8ae7b2 100644 --- a/plugins/netconnect/netconnect.cpp +++ b/plugins/netconnect/netconnect.cpp @@ -32,6 +32,9 @@ #define ITEMHEIGH 50 #define LAN_TYPE 0 #define CONTROL_CENTER_WIFI "org.ukui.control-center.wifi.switch" +#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" +#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" +#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" const QString KLanSymbolic = "network-wired-connected-symbolic"; const QString NoNetSymbolic = "network-wired-disconnected-symbolic"; @@ -351,10 +354,20 @@ void NetConnect::initNet() } } +//刪除 +void NetConnect::deleteOneLan(QString ssid, int type) +{ + qDebug() << "[NetConnect]call deleteConnect" << __LINE__; + m_interface->call(QStringLiteral("deleteConnect"), type, ssid); + qDebug() << "[NetConnect]call deleteConnect respond" << __LINE__; +} + void NetConnect::runExternalApp() { - QString cmd = "nm-connection-editor"; - QProcess process(this); - process.startDetached(cmd); + if (!LaunchApp("nm-connection-editor.desktop")){ + QString cmd = "nm-connection-editor"; + QProcess process(this); + process.startDetached(cmd); + } } //激活 @@ -431,12 +444,12 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL return; } - LanItem * lanItem = new LanItem(pluginWidget); + LanItem * lanItem = new LanItem(isActived, pluginWidget); QString iconPath = KLanSymbolic; if (isActived) { lanItem->statusLabel->setText(tr("connected")); } else { - lanItem->statusLabel->setText(""); + lanItem->statusLabel->setText(tr("not connected")); } QIcon searchIcon = QIcon::fromTheme(iconPath); // if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) { @@ -459,6 +472,7 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL }); lanItem->isAcitve = isActived; + lanItem->setConnectActionText(lanItem->isAcitve); connect(lanItem, &QPushButton::clicked, this, [=] { if (lanItem->isAcitve || lanItem->loading) { @@ -468,6 +482,16 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL } }); + connect(lanItem, &LanItem::connectActionTriggered, this, [=] { + activeConnect(lanItem->uuid, devName, WIRED_TYPE); + }); + connect(lanItem, &LanItem::disconnectActionTriggered, this, [=] { + deActiveConnect(lanItem->uuid, devName, WIRED_TYPE); + }); + connect(lanItem, &LanItem::deleteActionTriggered, this, [=] { + deleteOneLan(lanItem->uuid, WIRED_TYPE); + }); + //记录到deviceFrame的itemMap中 deviceFrameMap[devName]->itemMap.insert(infoList.at(1), lanItem); qDebug()<<"insert " << infoList.at(1) << " to " << devName << " list"; @@ -722,7 +746,7 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis QString iconPath; iconPath = KLanSymbolic; - lanItem->statusLabel->setText(""); + lanItem->statusLabel->setText(tr("not connected")); QIcon searchIcon = QIcon::fromTheme(iconPath); // if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) { @@ -745,6 +769,7 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis }); lanItem->isAcitve = false; + lanItem->setConnectActionText(lanItem->isAcitve); connect(lanItem, &QPushButton::clicked, this, [=] { if (lanItem->isAcitve || lanItem->loading) { @@ -754,6 +779,16 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis } }); + connect(lanItem, &LanItem::connectActionTriggered, this, [=] { + activeConnect(lanItem->uuid, deviceName, WIRED_TYPE); + }); + connect(lanItem, &LanItem::disconnectActionTriggered, this, [=] { + deActiveConnect(lanItem->uuid, deviceName, WIRED_TYPE); + }); + connect(lanItem, &LanItem::deleteActionTriggered, this, [=] { + deleteOneLan(lanItem->uuid, WIRED_TYPE); + }); + //记录到deviceFrame的itemMap中 deviceFrameMap[deviceName]->itemMap.insert(connUuid, lanItem); int index = getInsertPos(connName, deviceName); @@ -868,7 +903,9 @@ void NetConnect::itemActiveConnectionStatusChanged(LanItem *item, int status) item->statusLabel->setMaximumSize(16777215,16777215); item->statusLabel->clear(); item->isAcitve = false; + item->statusLabel->setText(tr("not connected")); } + item->setConnectActionText(item->isAcitve); // QIcon searchIcon = QIcon::fromTheme(iconPath); // item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(24, 24)))); @@ -909,3 +946,19 @@ int NetConnect::getInsertPos(QString connName, QString deviceName) } return index; } + +bool NetConnect::LaunchApp(QString desktopFile) +{ + QDBusInterface m_appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, + KYLIN_APP_MANAGER_PATH, + KYLIN_APP_MANAGER_INTERFACE, + QDBusConnection::sessionBus());//局部变量 + + if (!m_appManagerDbusInterface.isValid()) { + qWarning()<<"m_appManagerDbusInterface init error"; + return false; + } else { + QDBusReply reply =m_appManagerDbusInterface.call("LaunchApp",desktopFile); + return reply; + } +} diff --git a/plugins/netconnect/netconnect.h b/plugins/netconnect/netconnect.h index f991540f..e8858614 100644 --- a/plugins/netconnect/netconnect.h +++ b/plugins/netconnect/netconnect.h @@ -101,7 +101,7 @@ private: int getInsertPos(QString connName, QString deviceName); - void deleteOneLan(QString ssid); + void deleteOneLan(QString ssid, int type); void activeConnect(QString ssid, QString deviceName, int type); void deActiveConnect(QString ssid, QString deviceName, int type); @@ -123,6 +123,7 @@ private: //单个lan连接状态变化 void itemActiveConnectionStatusChanged(LanItem *item, int status); + bool LaunchApp(QString desktopFile); protected: bool eventFilter(QObject *w,QEvent *e); diff --git a/plugins/vpn/itemframe.cpp b/plugins/vpn/itemframe.cpp deleted file mode 100644 index 816828f7..00000000 --- a/plugins/vpn/itemframe.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- 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 "itemframe.h" -#include - -#define LAYOUT_MARGINS 0,0,0,0 -#define MAIN_LAYOUT_MARGINS 0,0,0,0 -ItemFrame::ItemFrame(QWidget *parent) - :QFrame(parent) -{ - deviceLanLayout = new QVBoxLayout(this); - deviceLanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); - lanItemFrame = new QFrame(this); - lanItemFrame->setFrameShape(QFrame::Shape::NoFrame); - lanItemFrame->setContentsMargins(LAYOUT_MARGINS); - - lanItemLayout = new QVBoxLayout(this); - lanItemLayout->setContentsMargins(LAYOUT_MARGINS); - lanItemLayout->setSpacing(1); - addWlanWidget = new AddNetBtn(false, this); - addWlanWidget->setTextLabel(tr("Add Vpn")); - - deviceLanLayout->setSpacing(1); - setLayout(deviceLanLayout); - lanItemFrame->setLayout(lanItemLayout); - - deviceLanLayout->addWidget(lanItemFrame); - deviceLanLayout->addWidget(addWlanWidget); -} - -void ItemFrame::filletStyleChange() -{ - if (lanItemLayout->isEmpty()) { - return; - } - - for (int i = 0; i < lanItemLayout->count(); ++i) { - QLayoutItem *it = lanItemLayout->itemAt(i); - VpnItem *itemFrame = (VpnItem*)(it->widget()); - if (i != lanItemLayout->count()-1) { - itemFrame->setHalfFillet(false); - } else { - itemFrame->setHalfFillet(true); - } - } -} diff --git a/plugins/vpn/itemframe.h b/plugins/vpn/itemframe.h deleted file mode 100644 index b41153fa..00000000 --- a/plugins/vpn/itemframe.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- 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 ITEMFRAME_H -#define ITEMFRAME_H -#include -#include -#include "../component/AddBtn/addnetbtn.h" -#include "vpnitem.h" - -class ItemFrame : public QFrame -{ - Q_OBJECT -public: - ItemFrame(QWidget *parent = nullptr); - //单设备整体layout - QVBoxLayout * deviceLanLayout = nullptr; - //单设备列表Frame - QFrame * lanItemFrame = nullptr; - //单设备列表layout - QVBoxLayout * lanItemLayout = nullptr; - //item列表 - QMap itemMap; -// //已激活uuid -// QString uuid = ""; - //新建无线连接 - AddNetBtn * addWlanWidget = nullptr; - void filletStyleChange(); -}; - -#endif // ITEMFRAME_H diff --git a/plugins/vpn/translations/zh_CN.qm b/plugins/vpn/translations/zh_CN.qm deleted file mode 100644 index 56074df7001ff23cc82b4642556a596316b3c298..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 594 zcmcE7ks@*G{hX<16=n7(EZlq7iGhJ3fq@~~4@mE3V2I5F($|=D5412aFq*Nf(OC+l zJ6OFBTmg!IWX+rQ8Avm*vy@E%ic7FBi`4^iL%9-vn*jOixKh2J0O>>?c}69mcniPK z&)Gm)BNHfigZV!YZ~(asY(UKAn3AI4Uy_kpRLlP5i+b`Q-}vc?uzk#o0-TMIg=0Kts@+#2gmjhf@k-B}5lcJ6r6h{(H$w z;Z|@a=jY|6CYPk9;4pzLGq)hWs01MkG9+CK#Sq@S{1OE$1_70_peST_hS&x&jUDI_ oP(XmgfF(#_S_<4zY%ZxesU@kHs#4d+Gr(1GxnveYEk#iY0QPo`1^@s6 diff --git a/plugins/vpn/translations/zh_CN.ts b/plugins/vpn/translations/zh_CN.ts deleted file mode 100644 index ed7ce029..00000000 --- a/plugins/vpn/translations/zh_CN.ts +++ /dev/null @@ -1,80 +0,0 @@ - - - - - AddNetBtn - - - Add Others - - - - - Add WiredNetork - - - - - ItemFrame - - - Add Vpn - 添加VPN - - - - Vpn - - - VPN - - - - - import - - - - - Vpn - - - - - Show on Taskbar - 在任务栏显示图标 - - - - - connected - 已连接 - - - - - not connected - 未连接 - - - - VpnItem - - - Delete - 删除 - - - - - Disconnect - 断开 - - - - - Connect - 连接 - - - diff --git a/plugins/vpn/vpn.cpp b/plugins/vpn/vpn.cpp deleted file mode 100644 index f4c13273..00000000 --- a/plugins/vpn/vpn.cpp +++ /dev/null @@ -1,497 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * Copyright (C) 2019 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 "vpn.h" -#include "ui_vpn.h" - -#include -#include -#include -#include -#include - -#define ACTIVATING 1 -#define ACTIVATED 2 -#define DEACTIVATING 3 -#define DEACTIVATED 4 - -#define LABEL_RECT 17, 0, 105, 23 -#define CONTENTS_MARGINS 0, 0, 0, 0 -#define ITEM_MARGINS 16, 0, 16, 0 -#define FRAME_MIN_SIZE 550, 60 -#define FRAME_MAX_SIZE 16777215, 16777215 -#define CONTECT_FRAME_MAX_SIZE 16777215, 60 -#define HINT_TEXT_MARGINS 8, 0, 0, 0 -#define FRAME_MIN_SIZE 550, 60 -#define LABLE_MIN_WIDTH 188 -#define COMBOBOX_MIN_WIDTH 200 -#define LINE_MAX_SIZE 16777215, 1 -#define LINE_MIN_SIZE 0, 1 -#define ICON_SIZE 24,24 -#define PASSWORD_FRAME_MIN_HIGHT 60 -#define PASSWORD_FRAME_FIX_HIGHT 80 -#define PASSWORD_FRAME_MIN_SIZE 550, 60 -#define PASSWORD_FRAME_MAX_SIZE 16777215, 86 -#define PASSWORD_ITEM_MARGINS 16, 12, 16, 14 - -#define KVpnSymbolic "ukui-vpn-symbolic" - -#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" -#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" -#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" - -const QString VISIBLE = "visible"; -const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.vpnicon"; - -Vpn::Vpn() : mFirstLoad(true) -{ - QTranslator* translator = new QTranslator(this); - translator->load("/usr/share/kylin-nm/vpn/" + QLocale::system().name()); - QApplication::installTranslator(translator); - - pluginName = tr("Vpn"); - pluginType = NETWORK; -} - -Vpn::~Vpn() -{ - if (!mFirstLoad) { - delete ui; - ui = nullptr; - delete m_interface; - delete m_switchGsettings; - } -} - -QString Vpn::plugini18nName(){ - return pluginName; -} - -int Vpn::pluginTypes(){ - return pluginType; -} - -QWidget *Vpn::pluginUi(){ - if (mFirstLoad) { - mFirstLoad = false; - ui = new Ui::Vpn; - pluginWidget = new QWidget; - pluginWidget->setAttribute(Qt::WA_DeleteOnClose); - ui->setupUi(pluginWidget); - - qDBusRegisterMetaType>(); - m_interface = new QDBusInterface("com.kylin.network", - "/com/kylin/vpnTool", - "com.kylin.vpnTool", - QDBusConnection::sessionBus()); - if(!m_interface->isValid()) { - qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); - } - - initComponent(); - initConnect(); - initNet(); - } - return pluginWidget; -} - -const QString Vpn::name() const { - - return QStringLiteral("Vpn"); -} - -bool Vpn::isShowOnHomePage() const -{ - return true; -} - -QIcon Vpn::icon() const -{ - return QIcon::fromTheme("ukui-vpn-symbolic"); -} - -bool Vpn::isEnable() const -{ - return true; -} - -void Vpn::initComponent(){ - //在任务栏上显示图标 - //显示已连接时间 - m_topFrame = new QFrame(pluginWidget); - m_topFrame->setMinimumSize(FRAME_MIN_SIZE); - m_topFrame->setMaximumSize(FRAME_MAX_SIZE); - m_topFrame->setFrameShape(QFrame::Box); - - QVBoxLayout *hotspotLyt = new QVBoxLayout(pluginWidget); - hotspotLyt->setContentsMargins(0, 0, 0, 0); - m_topFrame->setLayout(hotspotLyt); - - m_showFrame = new QFrame(m_topFrame); - m_showFrame->setFrameShape(QFrame::Shape::NoFrame); - m_showFrame->setMinimumSize(FRAME_MIN_SIZE); - m_showFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE); - QHBoxLayout *showLayout = new QHBoxLayout(m_showFrame); - m_showLabel = new QLabel(tr("Show on Taskbar"), m_showFrame); - m_showLabel->setMinimumWidth(LABLE_MIN_WIDTH); - m_showBtn = new KSwitchButton(m_showFrame); - showLayout->setContentsMargins(ITEM_MARGINS); - showLayout->addWidget(m_showLabel); - showLayout->addStretch(); - showLayout->addWidget(m_showBtn); - - m_showFrame->setLayout(showLayout); - -// m_Line = myLine(); - -// m_timeFrame = new QFrame(m_topFrame); -// m_timeFrame->setFrameShape(QFrame::Shape::NoFrame); -// m_timeFrame->setMinimumSize(FRAME_MIN_SIZE); -// m_timeFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE); -// QHBoxLayout *timeLayout = new QHBoxLayout(m_timeFrame); -// m_timeLabel = new QLabel(tr("Open"), m_timeFrame); -// m_timeLabel->setMinimumWidth(LABLE_MIN_WIDTH); -// m_timeBtn = new KSwitchButton(m_timeFrame); -// timeLayout->setContentsMargins(ITEM_MARGINS); -// timeLayout->addWidget(m_timeLabel); -// timeLayout->addStretch(); -// timeLayout->addWidget(m_timeBtn); - -// m_timeFrame->setLayout(timeLayout); - - hotspotLyt->addWidget(m_showFrame); -// hotspotLyt->addWidget(m_Line); -// hotspotLyt->addWidget(m_timeFrame); - hotspotLyt->setSpacing(0); - - //列表 - m_listFrame = new ItemFrame(pluginWidget); - - ui->verticalLayout_4->addWidget(m_topFrame); - ui->verticalLayout_3->addWidget(m_listFrame); - - connect(m_listFrame->addWlanWidget, &AddNetBtn::clicked, this, [=]() { - runExternalApp(); - }); - - if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { - m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); - setShowSwitchStatus(); - - connect(m_switchGsettings, &QGSettings::changed, this, [=] (const QString &key) { - if (key == VISIBLE) { - setShowSwitchStatus(); - } - }); - } else { - m_showBtn->setChecked(false); - m_showBtn->setCheckable(false); - qDebug()<<"[Vpn] org.ukui.kylin-nm.visible is not installed!"; - } - - connect(m_showBtn, &KSwitchButton::stateChanged, this, [=](bool state){ - if (m_switchGsettings != nullptr) { - m_switchGsettings->set(VISIBLE, state); - } - }); - -// connect(m_timeBtn, &KSwitchButton::stateChanged, this, [=](bool state){ -// if (m_switchGsettings != nullptr) { -// m_switchGsettings->set(VISIBLE, state); -// } -// }); - ui->pushButton->hide(); -} - -void Vpn::initConnect() -{ - connect(m_interface, SIGNAL(vpnAdd(QStringList)), this, SLOT(onVpnAdd(QStringList))); - connect(m_interface, SIGNAL(vpnRemove(QString)), this, SLOT(onVpnRemove(QString))); - connect(m_interface, SIGNAL(vpnUpdate(QStringList)), this, SLOT(onVpnUpdate(QStringList))); - connect(m_interface, SIGNAL(vpnActiveConnectionStateChanged(QString, int)), - this, SLOT(onVpnActiveConnectionStateChanged(QString, int))); -} - -//初始化列表 -void Vpn::initNet() -{ - qDebug() << "[Vpn]initNet"; - if (!m_interface->isValid()) { - return; - } - QDBusMessage result = m_interface->call(QStringLiteral("getVirtualList")); - if(result.type() == QDBusMessage::ErrorMessage) - { - qWarning() << "getVirtualList error:" << result.errorMessage(); - return; - } - auto dbusArg = result.arguments().at(0).value(); - QVector variantList; - dbusArg >> variantList; - if (variantList.size() == 0) { - qDebug() << "[Vpn]initNet list empty"; - return; - } - - for (int i = 0; i < variantList.size(); ++i) { - QStringList vpnInfo = variantList.at(i); - addOneVirtualItem(vpnInfo); - } - return; -} - -void Vpn::setShowSwitchStatus() -{ - if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { - bool status = m_switchGsettings->get(VISIBLE).toBool(); - m_showBtn->setChecked(status); - } else { - qDebug()<<"[Vpn] org.ukui.kylin-nm.switch is not installed!"; - } -} - -void Vpn::runExternalApp(){ - QString cmd = "nm-connection-editor"; - QProcess process(this); - process.startDetached(cmd); -} - -QFrame* Vpn::myLine() -{ - QFrame *line = new QFrame(pluginWidget); - line->setMinimumSize(QSize(LINE_MIN_SIZE)); - line->setMaximumSize(QSize(LINE_MAX_SIZE)); - line->setLineWidth(0); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - - return line; -} - -//刪除 -void Vpn::deleteVpn(QString uuid) -{ - m_interface->call(QStringLiteral("deleteVpn"), uuid); -} - -//激活 -void Vpn::activeConnect(QString uuid) { - m_interface->call(QStringLiteral("activateVpn"), uuid); -} - -//断开 -void Vpn::deActiveConnect(QString uuid) { - m_interface->call(QStringLiteral("deactivateVpn"), uuid); -} - - -//增加一项 -void Vpn::addOneVirtualItem(QStringList infoList) -{ - if (m_listFrame->itemMap.contains(infoList.at(1))) { - qDebug() << "[Vpn]Already exist a virtual " << infoList.at(1); - return; - } - - qDebug() << "[Vpn]addOneVitualItem" << infoList.at(0) << infoList.at(3) ; - QString connName = infoList.at(0); - QString connUuid = infoList.at(1); - QString connDbusPath = infoList.at(2); - int status = infoList.at(3).toInt(); //1-连接中 2-已连接 3-断开中 4-已断开 - VpnItem * item = new VpnItem(pluginWidget); - - QIcon searchIcon = QIcon::fromTheme(KVpnSymbolic); - item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE)))); - item->titileLabel->setText(connName); - - item->uuid = connUuid; - item->dbusPath = connDbusPath; - - if (status == 1 || status == 3) { - item->startLoading(); - } - - connect(item->infoLabel, &GrayInfoButton::clicked, this, [=]{ - QDBusInterface appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, - KYLIN_APP_MANAGER_PATH, - KYLIN_APP_MANAGER_INTERFACE, - QDBusConnection::sessionBus()); - - if (!appManagerDbusInterface.isValid()) { - qWarning()<<"appManagerDbusInterface init error"; - } else { - QDBusReply reply = appManagerDbusInterface.call("LaunchApp", "nm-connection-editor.desktop"); - } - }); - - item->isAcitve = (status == 2); - item->setConnectActionText(item->isAcitve); - - if (item->isAcitve) { - item->statusLabel->setText(tr("connected")); - } else { - item->statusLabel->setText(tr("not connected")); - } - - connect(item, &QPushButton::clicked, this, [=] { - if (item->isAcitve || item->loading) { - deActiveConnect(item->uuid); - } else { - activeConnect(item->uuid); - } - }); - - connect(item, &VpnItem::connectActionTriggered, this, [=] { - activeConnect(item->uuid); - }); - connect(item, &VpnItem::disconnectActionTriggered, this, [=] { - deActiveConnect(item->uuid); - }); - connect(item, &VpnItem::deleteActionTriggered, this, [=] { - deleteVpn(item->uuid); - }); - - //记录到deviceFrame的itemMap中 - m_listFrame->itemMap.insert(connUuid, item); - int index = getInsertPos(connName); - qDebug()<<"[Vpn]addOneVirtualItem " << connName << " at pos:" << index; - m_listFrame->lanItemLayout->insertWidget(index, item); -} - -void Vpn::removeOneVirtualItem(QString dbusPath) -{ - qDebug()<<"[Vpn]vpn remove dbus path:" << dbusPath; - - QMap::iterator itemIter; - for (itemIter = m_listFrame->itemMap.begin(); itemIter != m_listFrame->itemMap.end(); itemIter++) { - if (itemIter.value()->dbusPath == dbusPath) { - qDebug()<<"[Vpn]vpn remove " << dbusPath << " find in " << itemIter.value()->titileLabel->text(); - QString key = itemIter.key(); - m_listFrame->lanItemLayout->removeWidget(itemIter.value()); - delete itemIter.value(); - m_listFrame->itemMap.remove(key); - break; - } - } -} - -//增加 -void Vpn::onVpnAdd(QStringList infoList) -{ - addOneVirtualItem(infoList); -} - -//移出 -void Vpn::onVpnRemove(QString uuid) -{ - removeOneVirtualItem(uuid); -} - -//名称变化 -void Vpn::onVpnUpdate(QStringList info) -{ - if (m_listFrame->itemMap.contains(info.at(1))) { - qDebug() << "[Vpn]" << m_listFrame->itemMap[info.at(1)]->titileLabel->text() << "change to" << info.at(0); - if (m_listFrame->itemMap[info.at(1)]->titileLabel->text() != info.at(0)) { - m_listFrame->itemMap[info.at(1)]->titileLabel->setText(info.at(0)); - } - } -} - -void Vpn::onVpnActiveConnectionStateChanged(QString uuid, int status) -{ - if (uuid.isEmpty()) { - qDebug() << "[Vpn]onActiveConnectionChanged but uuid is empty"; - return; - } - qDebug() << "[Vpn]onActiveConnectionChanged " << uuid << status; - VpnItem * item= nullptr; - - if (m_listFrame->itemMap.contains(uuid)) { - item = m_listFrame->itemMap[uuid]; - if (status == ACTIVATED) { - //为已连接则放到第一个 - m_listFrame->lanItemLayout->removeWidget(item); - m_listFrame->lanItemLayout->insertWidget(0,item); - } else if (status == DEACTIVATED) { - //为断开则重新插入 - int index = getInsertPos(item->titileLabel->text()); - qDebug() << "[Vpn]reinsert" << item->titileLabel->text() << "pos" << index << "because status changes to deactive"; - m_listFrame->lanItemLayout->removeWidget(item); - m_listFrame->lanItemLayout->insertWidget(index,item); - } - itemActiveConnectionStatusChanged(item, status); - } -} - -void Vpn::itemActiveConnectionStatusChanged(VpnItem *item, int status) -{ -// QString iconPath = NoNetSymbolic; - if (status == ACTIVATING) { - item->startLoading(); - } else if (status == ACTIVATED) { - item->stopLoading(); -// iconPath = KLanSymbolic; - item->statusLabel->clear(); - item->statusLabel->setMinimumSize(36,36); - item->statusLabel->setMaximumSize(16777215,16777215); - item->statusLabel->setText(tr("connected")); - item->isAcitve = true; - } else if (status == DEACTIVATING) { - item->startLoading(); - } else { - item->stopLoading(); - item->statusLabel->setMinimumSize(36,36); - item->statusLabel->setMaximumSize(16777215,16777215); - item->statusLabel->clear(); - item->isAcitve = false; - item->statusLabel->setText(tr("not connected")); - } - item->setConnectActionText(item->isAcitve); -} - -int Vpn::getInsertPos(QString connName) -{ - qDebug() << "[Vpn]getInsertPos" << connName; - int index = 0; - if(!m_interface->isValid()) { - index = 0; - } else { - QDBusMessage result = m_interface->call(QStringLiteral("getVirtualList")); - if(result.type() == QDBusMessage::ErrorMessage) - { - qWarning() << "getVirtualList error:" << result.errorMessage(); - return 0; - } - auto dbusArg = result.arguments().at(0).value(); - QVector variantList; - dbusArg >> variantList; - for (int i = 0; i < variantList.size(); ++i ) { - if (variantList.at(i).at(0) == connName) { - qDebug() << "pos in kylin-nm is " << i; - index = i; - break; - } - } - if (variantList.at(0).size() == 1) { - index--; - } - } - return index; -} diff --git a/plugins/vpn/vpn.h b/plugins/vpn/vpn.h deleted file mode 100644 index 941f8f4f..00000000 --- a/plugins/vpn/vpn.h +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * Copyright (C) 2019 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 VPN_H -#define VPN_H - -#include -#include -#include -#include -#include - -#include "interface.h" -#include "addbtn.h" -#include "imageutil.h" -#include "kwidget.h" -#include "kswitchbutton.h" -#include "itemframe.h" - -using namespace kdk; - -namespace Ui { -class Vpn; -} - -class Vpn : public QObject, CommonInterface -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface") - Q_INTERFACES(CommonInterface) - -public: - Vpn(); - ~Vpn(); - - QString plugini18nName() Q_DECL_OVERRIDE; - int pluginTypes() Q_DECL_OVERRIDE; - QWidget * pluginUi() Q_DECL_OVERRIDE; - const QString name() const Q_DECL_OVERRIDE; - bool isShowOnHomePage() const Q_DECL_OVERRIDE; - QIcon icon() const Q_DECL_OVERRIDE; - bool isEnable() const Q_DECL_OVERRIDE; - -public: - void initComponent(); - void initConnect(); - - void runExternalApp(); - -protected: -// bool eventFilter(QObject *watched, QEvent *event); - -private: - Ui::Vpn *ui; - - QString pluginName; - int pluginType; - QWidget * pluginWidget; - - QDBusInterface *m_interface = nullptr; - - QFrame *m_topFrame; - QFrame *m_showFrame; - QLabel *m_showLabel; - KSwitchButton *m_showBtn; - QFrame *m_Line; - QFrame *m_timeFrame; - QLabel *m_timeLabel; - KSwitchButton *m_timeBtn; - ItemFrame *m_listFrame; - - bool mFirstLoad; - QGSettings *m_switchGsettings; - - QFrame* myLine(); - - int getInsertPos(QString connName); - - void deleteVpn(QString uuid); - void activeConnect(QString uuid); - void deActiveConnect(QString uuid); - - //获取设备列表 - void initNet(); - //增加一项 - void addOneVirtualItem(QStringList infoList); - //减少一项 - void removeOneVirtualItem(QString uuid); - //单个lan连接状态变化 - void itemActiveConnectionStatusChanged(VpnItem *item, int status); - - - void setShowSwitchStatus(); - -private slots: - void onVpnAdd(QStringList); - void onVpnRemove(QString); - void onVpnUpdate(QStringList); - void onVpnActiveConnectionStateChanged(QString, int); - -}; - -#endif // VPN_H diff --git a/plugins/vpn/vpn.pro b/plugins/vpn/vpn.pro deleted file mode 100644 index 957517c6..00000000 --- a/plugins/vpn/vpn.pro +++ /dev/null @@ -1,50 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2019-06-29T13:53:10 -# -#------------------------------------------------- - -QT += widgets dbus - -TEMPLATE = lib -CONFIG += plugin \ - c++11 \ - link_pkgconfig - -include(../component/addbtn.pri) - -PKGCONFIG += gsettings-qt \ - kysdk-qtwidgets \ - -TARGET = $$qtLibraryTarget(vpn) -DESTDIR = ../.. -target.path = $$[QT_INSTALL_LIBS]/ukui-control-center -trans.files = translations/* -trans.path = /usr/share/kylin-nm/vpn/ - -INCLUDEPATH += \ - $$PROJECT_COMPONENTSOURCE \ - $$PROJECT_ROOTDIR \ - /usr/include/ukcc/interface \ - /usr/include/ukcc/widgets - -LIBS += -L$$[QT_INSTALL_LIBS] -lukcc - -SOURCES += \ - vpn.cpp \ - itemframe.cpp \ - vpnitem.cpp - -HEADERS += \ - vpn.h \ - itemframe.h \ - vpnitem.h - -FORMS += \ - vpn.ui - -INSTALLS += target \ - trans - -TRANSLATIONS += \ - translations/zh_CN.ts diff --git a/plugins/vpn/vpn.ui b/plugins/vpn/vpn.ui deleted file mode 100644 index bd1de4af..00000000 --- a/plugins/vpn/vpn.ui +++ /dev/null @@ -1,112 +0,0 @@ - - - Vpn - - - - 0 - 0 - 800 - 710 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Vpn - - - - 8 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - VPN - - - - - - - - - - - - - - - import - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - TitleLabel - QLabel -
titlelabel.h
-
-
- - -
diff --git a/plugins/vpn/vpnitem.cpp b/plugins/vpn/vpnitem.cpp deleted file mode 100644 index 28ff57eb..00000000 --- a/plugins/vpn/vpnitem.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* -*- 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 "vpnitem.h" -#include -#define FRAME_SPEED 150 -#define LIMIT_TIME 60*1000 -#define TOTAL_PAGE 8 -#define RADIUS 6.0 - -#define THEME_QT_SCHEMA "org.ukui.style" -#define MODE_QT_KEY "style-name" - -VpnItem::VpnItem(bool bAcitve, QWidget *parent) - : isAcitve(bAcitve), QPushButton(parent) -{ - this->setMinimumSize(550, 58); - this->setProperty("useButtonPalette", true); - this->setFlat(true); - QPalette pal = this->palette(); - QColor color = pal.color(QPalette::Button); - color.setAlphaF(0.5); - pal.setColor(QPalette::Button, color); - this->setPalette(pal); - QHBoxLayout *mLanLyt = new QHBoxLayout(this); - mLanLyt->setContentsMargins(16,0,16,0); - mLanLyt->setSpacing(16); - iconLabel = new QLabel(this); - iconLabel->setProperty("useIconHighlightEffect", 0x2); - titileLabel = new FixLabel(this); - statusLabel = new QLabel(this); - statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); - infoLabel = new GrayInfoButton(this); - - m_moreButton = new QToolButton(this); - m_moreButton->setProperty("useButtonPalette", true); - m_moreButton->setPopupMode(QToolButton::InstantPopup); - m_moreButton->setAutoRaise(true); - m_moreButton->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic")); - m_moreMenu = new QMenu(m_moreButton); - m_connectAction = new QAction(m_moreMenu); - m_deleteAction = new QAction(tr("Delete"), m_moreMenu); - setConnectActionText(isAcitve); - - m_moreMenu->addAction(m_connectAction); - m_moreMenu->addAction(m_deleteAction); - m_moreButton->setMenu(m_moreMenu); - - mLanLyt->addWidget(iconLabel); - mLanLyt->addWidget(titileLabel,Qt::AlignLeft); - mLanLyt->addStretch(); - mLanLyt->addWidget(statusLabel); - mLanLyt->addWidget(infoLabel); - mLanLyt->addWidget(m_moreButton); - - loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic")); - loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic")); - loadIcons.append(QIcon::fromTheme("ukui-loading-3-symbolic")); - loadIcons.append(QIcon::fromTheme("ukui-loading-4-symbolic")); - loadIcons.append(QIcon::fromTheme("ukui-loading-5-symbolic")); - loadIcons.append(QIcon::fromTheme("ukui-loading-6-symbolic")); - loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic")); - - waitTimer = new QTimer(this); - connect(waitTimer, &QTimer::timeout, this, &VpnItem::updateIcon); - - connect(m_connectAction, &QAction::triggered, this, &VpnItem::onConnectTriggered); - connect(m_deleteAction, &QAction::triggered, this, &VpnItem::onDeletetTriggered); - m_moreMenu->installEventFilter(this); -} - -void VpnItem::updateIcon() -{ - if (currentIconIndex > 6) { - currentIconIndex = 0; - } - statusLabel->setPixmap(loadIcons.at(currentIconIndex).pixmap(16,16)); - currentIconIndex ++; -} - -void VpnItem::startLoading() -{ - waitTimer->start(FRAME_SPEED); - loading = true; -} - -void VpnItem::stopLoading(){ - waitTimer->stop(); - loading = false; -} - -void VpnItem::setConnectActionText(bool isAcitve) -{ - if (isAcitve) { - m_connectAction->setText(tr("Disconnect")); - } else { - m_connectAction->setText(tr("Connect")); - } -} - -void VpnItem::onConnectTriggered() -{ - if (!m_connectAction) { - return; - } - if (m_connectAction->text() == tr("Connect")) { - Q_EMIT connectActionTriggered(); - } else if (m_connectAction->text() == tr("Disconnect")) { - Q_EMIT disconnectActionTriggered(); - } -} - -void VpnItem::onDeletetTriggered() -{ - if (!m_deleteAction) { - return; - } - Q_EMIT deleteActionTriggered(); -} - -void VpnItem::paintEvent(QPaintEvent *event) -{ - QPalette pal = this->palette(); - - QPainter painter(this); - painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿 - painter.setPen(Qt::NoPen); - painter.setBrush(pal.color(QPalette::Base)); - - QRect rect = this->rect(); - -#if 0 - if (!useHalfFillet) { - painter.drawRect(rect); - } else { - QPainterPath path; -// path.addRoundedRect (rect, RADIUS, RADIUS); -// QRect temp_rect(rect.left(), rect.top(), rect.width(), rect.height()/2); -// path.addRect(temp_rect); - //设置起点 - path.moveTo(rect.topLeft().x(), rect.topLeft().y()); - path.lineTo(rect.bottomLeft().x(), rect.bottomLeft().y() - RADIUS); - //绘制圆角 圆弧以外切圆的270度位置为起点,逆时针画圆弧运行90度结束 - path.arcTo(QRect(QPoint(rect.bottomLeft().x(), rect.bottomLeft().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 180, 90); - path.lineTo(rect.bottomRight().x() - RADIUS, rect.bottomRight().y()); - //画圆弧 - path.arcTo(QRect(QPoint(rect.bottomRight().x() - (RADIUS * 2), rect.bottomRight().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 270, 90); - path.lineTo(rect.topRight()); - path.lineTo(rect.topLeft()); - painter.drawPath(path); - } -#endif - - painter.drawRect(rect); - QPushButton::paintEvent(event); -} - -bool VpnItem::eventFilter(QObject *watched, QEvent *event) -{ - //菜单右边界与按钮右边界对齐 - if (event->type() == QEvent::Show && watched == m_moreMenu) { - int menuXPos = m_moreMenu->pos().x(); - int menuWidth = m_moreMenu->size().width(); - int btnWidth = m_moreButton->size().width(); - - QPoint pos = QPoint (menuXPos - menuWidth + btnWidth, m_moreMenu->pos().y()); - m_moreMenu->move(pos); - return true; - } - return false; -} diff --git a/plugins/vpn/vpnitem.h b/plugins/vpn/vpnitem.h deleted file mode 100644 index 6947d60f..00000000 --- a/plugins/vpn/vpnitem.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- 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 VPNITEM_H -#define VPNITEM_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fixlabel.h" -#include "../component/AddBtn/grayinfobutton.h" - -class VpnItem : public QPushButton -{ - Q_OBJECT -public: - VpnItem(bool bAcitve, QWidget *parent = nullptr); -public: - QLabel * iconLabel = nullptr; - GrayInfoButton * infoLabel = nullptr; - FixLabel * titileLabel = nullptr; - QLabel * statusLabel = nullptr; - QToolButton* m_moreButton = nullptr; - QMenu* m_moreMenu = nullptr; - QAction* m_connectAction = nullptr; - QAction* m_deleteAction = nullptr; - - QString uuid = ""; - QString dbusPath = ""; - - void setHalfFillet(bool flag) {useHalfFillet = flag; repaint();} -public: - void startLoading(); - void stopLoading(); - void setConnectActionText(bool isAcitve); - - bool isAcitve = false; - bool loading = false; - -protected: - void paintEvent(QPaintEvent *event); - bool eventFilter(QObject *watched, QEvent *event); - -private: - QTimer *waitTimer = nullptr; - QGSettings *themeGsettings = nullptr; - bool useHalfFillet = false; - QList loadIcons; - int currentIconIndex=0; - -private slots: - void updateIcon(); - void onConnectTriggered(); - void onDeletetTriggered(); - -Q_SIGNALS: - void connectActionTriggered(); - void disconnectActionTriggered(); - void deleteActionTriggered(); - -}; - -#endif // VPNITEM_H diff --git a/plugins/wlanconnect/deviceframe.cpp b/plugins/wlanconnect/deviceframe.cpp index be13ca78..a7822712 100644 --- a/plugins/wlanconnect/deviceframe.cpp +++ b/plugins/wlanconnect/deviceframe.cpp @@ -19,6 +19,7 @@ */ #include "deviceframe.h" #include +#include #define LAYOUT_MARGINS 18,0,8,0 #define FRAME_HEIGHT 58 diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp index 0e2402c5..907fc4a3 100644 --- a/plugins/wlanconnect/wlanconnect.cpp +++ b/plugins/wlanconnect/wlanconnect.cpp @@ -48,6 +48,10 @@ #define SIGNAL_NONE 5 #define ICON_SIZE 16,16 +#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" +#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" +#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" + const QString WIRELESS_SWITCH = "wirelessswitch"; const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch"; @@ -785,9 +789,11 @@ void WlanConnect::initNetListFromDevice(QString deviceName) //高级设置 void WlanConnect::runExternalApp() { - QString cmd = "nm-connection-editor"; - QProcess process(this); - process.startDetached(cmd); + if (!LaunchApp("nm-connection-editor.desktop")){ + QString cmd = "nm-connection-editor"; + QProcess process(this); + process.startDetached(cmd); + } } //根据信号强度分级+安全性分图标 @@ -1105,3 +1111,18 @@ void WlanConnect::itemActiveConnectionStatusChanged(WlanItem *item, int status) } } +bool WlanConnect::LaunchApp(QString desktopFile) +{ + QDBusInterface m_appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, + KYLIN_APP_MANAGER_PATH, + KYLIN_APP_MANAGER_INTERFACE, + QDBusConnection::sessionBus());//局部变量 + + if (!m_appManagerDbusInterface.isValid()) { + qWarning()<<"m_appManagerDbusInterface init error"; + return false; + } else { + QDBusReply reply =m_appManagerDbusInterface.call("LaunchApp",desktopFile); + return reply; + } +} diff --git a/plugins/wlanconnect/wlanconnect.h b/plugins/wlanconnect/wlanconnect.h index 38bff337..abb2c8c0 100644 --- a/plugins/wlanconnect/wlanconnect.h +++ b/plugins/wlanconnect/wlanconnect.h @@ -149,7 +149,7 @@ private: } } - + bool LaunchApp(QString desktopFile); protected: bool eventFilter(QObject *w,QEvent *e); diff --git a/plugins/wlanconnect/wlanitem.cpp b/plugins/wlanconnect/wlanitem.cpp index 539e454c..f4576426 100644 --- a/plugins/wlanconnect/wlanitem.cpp +++ b/plugins/wlanconnect/wlanitem.cpp @@ -19,6 +19,7 @@ */ #include "wlanitem.h" #include +#include #include #define FRAME_SPEED 150 #define LIMIT_TIME 60*1000 diff --git a/src/backend/dbus-interface/kyenterpricesettinginfo.cpp b/src/backend/dbus-interface/kyenterpricesettinginfo.cpp index c1cc1c0a..9ff68dd5 100644 --- a/src/backend/dbus-interface/kyenterpricesettinginfo.cpp +++ b/src/backend/dbus-interface/kyenterpricesettinginfo.cpp @@ -193,3 +193,147 @@ void modifyEapMethodTtlsSettings(NetworkManager::ConnectionSettings::Ptr connSet wifi_8021x_sett->setCaCertificate(caCerEndWithNull); return; } + +void assembleEapMethodLeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodLeapInfo &leapInfo) +{ + NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett + = connSettingPtr->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + + QList list; + list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodLeap); + wifi_8021x_sett->setInitialized(true); + wifi_8021x_sett->setEapMethods(list); + wifi_8021x_sett->setIdentity(leapInfo.m_userName); + wifi_8021x_sett->setPassword(leapInfo.m_userPwd); + wifi_8021x_sett->setPasswordFlags(leapInfo.m_passwdFlag); + + + NetworkManager::WirelessSecuritySetting::Ptr security_sett + = connSettingPtr->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); + security_sett->setInitialized(true); + security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap); + return; +} + +void assembleEapMethodPwdSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPwdInfo &pwdInfo) +{ + NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett + = connSettingPtr->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + + QList list; + list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodPwd); + wifi_8021x_sett->setInitialized(true); + wifi_8021x_sett->setEapMethods(list); + wifi_8021x_sett->setIdentity(pwdInfo.m_userName); + wifi_8021x_sett->setPassword(pwdInfo.m_userPwd); + wifi_8021x_sett->setPasswordFlags(pwdInfo.m_passwdFlag); + + + NetworkManager::WirelessSecuritySetting::Ptr security_sett + = connSettingPtr->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); + security_sett->setInitialized(true); + security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap); + return; +} + +void assembleEapMethodFastSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodFastInfo &fastInfo) +{ + NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett + = connSettingPtr->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + + QList list; + list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodFast); + wifi_8021x_sett->setInitialized(true); + wifi_8021x_sett->setEapMethods(list); + wifi_8021x_sett->setAnonymousIdentity(fastInfo.m_anonIdentity); + if (fastInfo.m_allowAutoPacFlag) { + wifi_8021x_sett->setPhase1FastProvisioning((NetworkManager::Security8021xSetting::FastProvisioning)fastInfo.m_pacProvisioning); + } else { + wifi_8021x_sett->setPhase1FastProvisioning(NetworkManager::Security8021xSetting::FastProvisioning::FastProvisioningDisabled); + } + QByteArray pacEndWithNull("file://" + fastInfo.m_pacFilePath.toUtf8() + '\0'); + wifi_8021x_sett->setPacFile(pacEndWithNull); + wifi_8021x_sett->setPhase2AuthMethod((NetworkManager::Security8021xSetting::AuthMethod)fastInfo.m_authMethod); + wifi_8021x_sett->setIdentity(fastInfo.m_userName); + wifi_8021x_sett->setPassword(fastInfo.m_userPwd); + wifi_8021x_sett->setPasswordFlags(fastInfo.m_passwdFlag); + + NetworkManager::WirelessSecuritySetting::Ptr security_sett + = connSettingPtr->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); + security_sett->setInitialized(true); + security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap); + + return; +} + +void modifyEapMethodLeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodLeapInfo &leapInfo) +{ + NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett + = connSettingPtr->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + wifi_8021x_sett->setInitialized(true); + + QList list; + list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodLeap); + wifi_8021x_sett->setEapMethods(list); + wifi_8021x_sett->setIdentity(leapInfo.m_userName); + if(leapInfo.bChanged) + { + wifi_8021x_sett->setPassword(leapInfo.m_userPwd); + } + wifi_8021x_sett->setPasswordFlags(leapInfo.m_passwdFlag); + + QByteArray caCerEndWithNull(""); + wifi_8021x_sett->setCaCertificate(caCerEndWithNull); + + return; +} + +void modifyEapMethodPwdSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPwdInfo &pwdInfo) +{ + NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett + = connSettingPtr->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + wifi_8021x_sett->setInitialized(true); + + QList list; + list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodPwd); + wifi_8021x_sett->setEapMethods(list); + wifi_8021x_sett->setIdentity(pwdInfo.m_userName); + if(pwdInfo.bChanged) + { + wifi_8021x_sett->setPassword(pwdInfo.m_userPwd); + } + wifi_8021x_sett->setPasswordFlags(pwdInfo.m_passwdFlag); + + QByteArray caCerEndWithNull(""); + wifi_8021x_sett->setCaCertificate(caCerEndWithNull); + + return; +} + +void modifyEapMethodFastSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodFastInfo &fastInfo) +{ + NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett + = connSettingPtr->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + wifi_8021x_sett->setInitialized(true); + + QList list; + list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodFast); + wifi_8021x_sett->setEapMethods(list); + wifi_8021x_sett->setAnonymousIdentity(fastInfo.m_anonIdentity); + if (fastInfo.m_allowAutoPacFlag) { + wifi_8021x_sett->setPhase1FastProvisioning((NetworkManager::Security8021xSetting::FastProvisioning)fastInfo.m_pacProvisioning); + } else { + wifi_8021x_sett->setPhase1FastProvisioning(NetworkManager::Security8021xSetting::FastProvisioning::FastProvisioningDisabled); + } + QByteArray pacEndWithNull("file://" + fastInfo.m_pacFilePath.toUtf8() + '\0'); + wifi_8021x_sett->setPacFile(pacEndWithNull); + + wifi_8021x_sett->setPhase2AuthMethod((NetworkManager::Security8021xSetting::AuthMethod)fastInfo.m_authMethod); + wifi_8021x_sett->setIdentity(fastInfo.m_userName); + if(fastInfo.bChanged) + { + wifi_8021x_sett->setPassword(fastInfo.m_userPwd); + } + wifi_8021x_sett->setPasswordFlags(fastInfo.m_passwdFlag); + return; +} diff --git a/src/backend/dbus-interface/kyenterpricesettinginfo.h b/src/backend/dbus-interface/kyenterpricesettinginfo.h index f95edb49..593b504a 100644 --- a/src/backend/dbus-interface/kyenterpricesettinginfo.h +++ b/src/backend/dbus-interface/kyenterpricesettinginfo.h @@ -30,6 +30,9 @@ enum KyEapMethodType { TLS = 0, PEAP, TTLS, + LEAP, + PWD, + FAST, }; class KyEapMethodTlsInfo @@ -154,12 +157,99 @@ public: } }; +typedef enum { + KyFastProvisioningUnknown = -1, + KyFastProvisioningDisabled, + KyFastProvisioningAllowUnauthenticated, + KyFastProvisioningAllowAuthenticated, + KyFastProvisioningAllowBoth +}KyFastProvisioning; + +class KyEapMethodLeapInfo +{ +public: + QString m_userName; + QString m_userPwd; + NetworkManager::Setting::SecretFlags m_passwdFlag; + // only valid when update + bool bChanged; + + inline bool operator == (const KyEapMethodLeapInfo& info) const + { + if (this->m_userName == info.m_userName + && this->m_userPwd == info.m_userPwd + && this->m_passwdFlag == info.m_passwdFlag) { + return true; + } else { + return false; + } + } +}; + +class KyEapMethodPwdInfo +{ +public: + QString m_userName; + QString m_userPwd; + NetworkManager::Setting::SecretFlags m_passwdFlag; + // only valid when update + bool bChanged; + + inline bool operator == (const KyEapMethodPwdInfo& info) const + { + if (this->m_userName == info.m_userName + && this->m_userPwd == info.m_userPwd + && this->m_passwdFlag == info.m_passwdFlag) { + return true; + } else { + return false; + } + } +}; + +class KyEapMethodFastInfo +{ +public: + QString m_anonIdentity; + KyFastProvisioning m_pacProvisioning; + bool m_allowAutoPacFlag; + QString m_pacFilePath; + KyNoEapMethodAuth m_authMethod; + QString m_userName; + QString m_userPwd; + NetworkManager::Setting::SecretFlags m_passwdFlag; + // only valid when update + bool bChanged; + + inline bool operator == (const KyEapMethodFastInfo& info) const + { + if (this->m_anonIdentity == info.m_anonIdentity + && this->m_pacProvisioning == info.m_pacProvisioning + && this->m_allowAutoPacFlag == info.m_allowAutoPacFlag + && this->m_pacFilePath == info.m_pacFilePath + && this->m_authMethod == info.m_authMethod + && this->m_userName == info.m_userName + && this->m_userPwd == info.m_userPwd + && this->m_passwdFlag == info.m_passwdFlag) { + return true; + } else { + return false; + } + } +}; + void assembleEapMethodTlsSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodTlsInfo &tlsInfo); void assembleEapMethodPeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPeapInfo &peapInfo); void assembleEapMethodTtlsSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodTtlsInfo &ttlsInfo); +void assembleEapMethodLeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodLeapInfo &leapInfo); +void assembleEapMethodPwdSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPwdInfo &pwdInfo); +void assembleEapMethodFastSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodFastInfo &fastInfo); void modifyEapMethodTlsSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodTlsInfo &tlsInfo); void modifyEapMethodPeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPeapInfo &peapInfo); void modifyEapMethodTtlsSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodTtlsInfo &ttlsInfo); +void modifyEapMethodLeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodLeapInfo &leapInfo); +void modifyEapMethodPwdSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPwdInfo &pwdInfo); +void modifyEapMethodFastSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodFastInfo &fastInfo); #endif // KYENTERPRICESETTINGINFO_H diff --git a/src/backend/dbus-interface/kylinconnectresource.cpp b/src/backend/dbus-interface/kylinconnectresource.cpp index 7de89382..eb757490 100644 --- a/src/backend/dbus-interface/kylinconnectresource.cpp +++ b/src/backend/dbus-interface/kylinconnectresource.cpp @@ -373,6 +373,7 @@ void KyConnectResourse::getIpv4ConnectSetting( { if (NetworkManager::Ipv4Setting::Automatic == ipv4Setting->method()) { connectSetting.m_ipv4ConfigIpType = CONFIG_IP_DHCP; + connectSetting.m_ipv4Dns = ipv4Setting->dns(); return; } @@ -391,6 +392,7 @@ void KyConnectResourse::getIpv6ConnectSetting( if (NetworkManager::Ipv6Setting::Automatic == ipv6Setting->method()) { connectSetting.m_ipv6ConfigIpType = CONFIG_IP_DHCP; + connectSetting.m_ipv6Dns = ipv6Setting->dns(); return; } diff --git a/src/backend/dbus-interface/kylinconnectsetting.cpp b/src/backend/dbus-interface/kylinconnectsetting.cpp index 88aeb57d..22700aad 100644 --- a/src/backend/dbus-interface/kylinconnectsetting.cpp +++ b/src/backend/dbus-interface/kylinconnectsetting.cpp @@ -69,7 +69,7 @@ int KyConnectSetting::setIpConfigType(KyIpAddressType ipType, KyIpConfigType ipC return 0; } -void KyConnectSetting::ipv4AddressConstruct(QString &ipv4Address, QString &ipv4NetMask, QString &ipv4GateWay, QStringList &ipv4Dns) +void KyConnectSetting::ipv4AddressConstruct(QString &ipv4Address, QString &ipv4NetMask, QString &ipv4GateWay) { qDebug()<<"ipv4 address"< &ipv4DnsList) +{ + m_ipv4Dns = ipv4DnsList; +} - return ; +void KyConnectSetting::ipv6DnsConstruct(QList &ipv6DnsList) +{ + m_ipv6Dns = ipv6DnsList; } void KyConnectSetting::dumpInfo() diff --git a/src/backend/dbus-interface/kylinconnectsetting.h b/src/backend/dbus-interface/kylinconnectsetting.h index f2e967e6..c8ae8f8c 100644 --- a/src/backend/dbus-interface/kylinconnectsetting.h +++ b/src/backend/dbus-interface/kylinconnectsetting.h @@ -50,8 +50,10 @@ public: void setIfaceName(QString &ifaceName); void setConnectName(QString &connectName); int setIpConfigType(KyIpAddressType ipType, KyIpConfigType configType); - void ipv4AddressConstruct(QString &ipv4Address, QString &ipv4NetMask, QString &ipv4GateWay, QStringList &ipv4Dns); - void ipv6AddressConstruct(QString &ipv6Address, QString &ipv6NetMask, QString &ipv6GateWay, QStringList &ipv6Dns); + void ipv4AddressConstruct(QString &ipv4Address, QString &ipv4NetMask, QString &ipv4GateWay); + void ipv6AddressConstruct(QString &ipv6Address, QString &ipv6NetMask, QString &ipv6GateWay); + void ipv4DnsConstruct(QList &ipv4DnsList); + void ipv6DnsConstruct(QList &ipv6DnsList); void dumpInfo(); public: diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index 38f46afe..8cde9ded 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -297,6 +297,109 @@ void KyWirelessConnectOperation::addTtlsConnect(const KyWirelessConnectSetting & return; } +//leap +void KyWirelessConnectOperation::addLeapConnect(const KyWirelessConnectSetting &connSettingInfo, const KyEapMethodLeapInfo &leapInfo) +{ + NetworkManager::WirelessNetwork::Ptr wifiNet = + checkWifiNetExist(connSettingInfo.m_ssid, connSettingInfo.m_ifaceName); + if (wifiNet.isNull()) { + QString errorMessage = "the ssid " + connSettingInfo.m_ssid + + " is not exsit in " + connSettingInfo.m_ifaceName; + qWarning() << errorMessage; + Q_EMIT createConnectionError(errorMessage); + return; + } + + NetworkManager::AccessPoint::Ptr accessPointPtr = wifiNet->referenceAccessPoint(); + NetworkManager::ConnectionSettings::Ptr connSetting = + assembleWirelessSettings(accessPointPtr, connSettingInfo, false); + setIpv4AndIpv6Setting(connSetting, connSettingInfo); + assembleEapMethodLeapSettings(connSetting, leapInfo); + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::addConnection(connSetting->toMap()), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = tr("create wireless leap connection failed: ") + watcher->error().message(); + qWarning()<createConnectionError(errorMessage); + } else { + qDebug()<<"create wireless connect complete"; + } + watcher->deleteLater(); + }); + + return; +} + +//pwd +void KyWirelessConnectOperation::addPwdConnect(const KyWirelessConnectSetting &connSettingInfo, const KyEapMethodPwdInfo &pwdInfo) +{ + NetworkManager::WirelessNetwork::Ptr wifiNet = + checkWifiNetExist(connSettingInfo.m_ssid, connSettingInfo.m_ifaceName); + if (wifiNet.isNull()) { + QString errorMessage = "the ssid " + connSettingInfo.m_ssid + + " is not exsit in " + connSettingInfo.m_ifaceName; + qWarning() << errorMessage; + Q_EMIT createConnectionError(errorMessage); + return; + } + + NetworkManager::AccessPoint::Ptr accessPointPtr = wifiNet->referenceAccessPoint(); + NetworkManager::ConnectionSettings::Ptr connSetting = + assembleWirelessSettings(accessPointPtr, connSettingInfo, false); + setIpv4AndIpv6Setting(connSetting, connSettingInfo); + assembleEapMethodPwdSettings(connSetting, pwdInfo); + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::addConnection(connSetting->toMap()), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = tr("create wireless pwd connection failed: ") + watcher->error().message(); + qWarning()<createConnectionError(errorMessage); + } else { + qDebug()<<"create wireless connect complete"; + } + watcher->deleteLater(); + }); + + return; +} + +//fast +void KyWirelessConnectOperation::addFastConnect(const KyWirelessConnectSetting &connSettingInfo, const KyEapMethodFastInfo &fastInfo) +{ + NetworkManager::WirelessNetwork::Ptr wifiNet = + checkWifiNetExist(connSettingInfo.m_ssid, connSettingInfo.m_ifaceName); + if (wifiNet.isNull()) { + QString errorMessage = "the ssid " + connSettingInfo.m_ssid + + " is not exsit in " + connSettingInfo.m_ifaceName; + qWarning() << errorMessage; + Q_EMIT createConnectionError(errorMessage); + return; + } + + NetworkManager::AccessPoint::Ptr accessPointPtr = wifiNet->referenceAccessPoint(); + NetworkManager::ConnectionSettings::Ptr connSetting = + assembleWirelessSettings(accessPointPtr, connSettingInfo, false); + setIpv4AndIpv6Setting(connSetting, connSettingInfo); + assembleEapMethodFastSettings(connSetting, fastInfo); + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::addConnection(connSetting->toMap()), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = tr("create wireless fast connection failed: ") + watcher->error().message(); + qWarning()<createConnectionError(errorMessage); + } else { + qDebug()<<"create wireless connect complete"; + } + watcher->deleteLater(); + }); +} + void KyWirelessConnectOperation::setWirelessAutoConnect(const QString &uuid, bool bAutoConnect) { NetworkManager::Connection::Ptr connectPtr = @@ -482,6 +585,60 @@ void KyWirelessConnectOperation::updateWirelessEnterPriseTtlsConnect(const QStri return; } +void KyWirelessConnectOperation::updateWirelessEnterPriseLeapConnect(const QString &uuid, const KyEapMethodLeapInfo &leapInfo) +{ + NetworkManager::Connection::Ptr connectPtr = + NetworkManager::findConnectionByUuid(uuid); + if (nullptr == connectPtr) { + QString errorMessage = tr("it can not find connection") + uuid; + qWarning()<settings(); + + setWirelessSecuWpaXEap(connectionSettings); + modifyEapMethodLeapSettings(connectionSettings, leapInfo); + connectPtr->update(connectionSettings->toMap()); + return; +} + +void KyWirelessConnectOperation::updateWirelessEnterPrisePwdConnect(const QString &uuid, const KyEapMethodPwdInfo &pwdInfo) +{ + NetworkManager::Connection::Ptr connectPtr = + NetworkManager::findConnectionByUuid(uuid); + if (nullptr == connectPtr) { + QString errorMessage = tr("it can not find connection") + uuid; + qWarning()<settings(); + + setWirelessSecuWpaXEap(connectionSettings); + modifyEapMethodPwdSettings(connectionSettings, pwdInfo); + connectPtr->update(connectionSettings->toMap()); + return; +} + +void KyWirelessConnectOperation::updateWirelessEnterPriseFastConnect(const QString &uuid, const KyEapMethodFastInfo &fastInfo) +{ + NetworkManager::Connection::Ptr connectPtr = + NetworkManager::findConnectionByUuid(uuid); + if (nullptr == connectPtr) { + QString errorMessage = tr("it can not find connection") + uuid; + qWarning()<settings(); + + setWirelessSecuWpaXEap(connectionSettings); + modifyEapMethodFastSettings(connectionSettings, fastInfo); + connectPtr->update(connectionSettings->toMap()); + return; +} + void KyWirelessConnectOperation::addAndActiveWirelessConnect(QString & devIface,KyWirelessConnectSetting &connSettingInfo,bool isHidden) { qDebug() << "addAndActiveWirelessConnect" << connSettingInfo.m_ssid << devIface <referenceAccessPoint(); + conn_uni = accessPointPtr->uni(); + spec_object = conn_uni; + } + + auto dev = m_networkResourceInstance->findDeviceInterface(devIface); + if (dev.isNull()) { + Q_EMIT addAndActivateConnectionError("can not find device"); + return; + } + dev_uni = dev->uni(); + + NetworkManager::ConnectionSettings::Ptr settings = + assembleWirelessSettings(accessPointPtr, connSettingInfo, isHidden); + assembleEapMethodLeapSettings(settings, info); + + if(settings.isNull()) { + qDebug() << "assembleEapMethodLeapSettings failed"; + return; + } + + map_settings = settings->toMap(); + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(map_settings, dev_uni, spec_object), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = watcher->error().message(); + qDebug() << "addAndActiveWirelessEnterPriseLeapConnect failed " << errorMessage; + Q_EMIT addAndActivateConnectionError(errorMessage); + } + watcher->deleteLater(); + }); +} + +void KyWirelessConnectOperation::addAndActiveWirelessEnterPrisePwdConnect(KyEapMethodPwdInfo &info, KyWirelessConnectSetting &connSettingInfo, QString &devIface, bool isHidden) +{ + QString conn_uni; + QString dev_uni; + QString spec_object; + NMVariantMapMap map_settings; + NetworkManager::AccessPoint::Ptr accessPointPtr = nullptr; + + if (!isHidden) { + NetworkManager::WirelessNetwork::Ptr wifiNet = checkWifiNetExist(connSettingInfo.m_ssid, devIface); + if (wifiNet.isNull()) { + QString errorMessage = "the ssid " + connSettingInfo.m_ssid + " is not exsit in " + devIface; + qWarning()<referenceAccessPoint(); + conn_uni = accessPointPtr->uni(); + spec_object = conn_uni; + } + + auto dev = m_networkResourceInstance->findDeviceInterface(devIface); + if (dev.isNull()) { + Q_EMIT addAndActivateConnectionError("can not find device"); + return; + } + dev_uni = dev->uni(); + + NetworkManager::ConnectionSettings::Ptr settings = + assembleWirelessSettings(accessPointPtr, connSettingInfo, isHidden); + assembleEapMethodPwdSettings(settings, info); + + if(settings.isNull()) { + qDebug() << "assembleEapMethodPwdSettings failed"; + return; + } + + map_settings = settings->toMap(); + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(map_settings, dev_uni, spec_object), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = watcher->error().message(); + qDebug() << "addAndActiveWirelessEnterPrisePwdConnect failed " << errorMessage; + Q_EMIT addAndActivateConnectionError(errorMessage); + } + watcher->deleteLater(); + }); +} + +void KyWirelessConnectOperation::addAndActiveWirelessEnterPriseFastConnect(KyEapMethodFastInfo &info, KyWirelessConnectSetting &connSettingInfo, QString &devIface, bool isHidden) +{ + QString conn_uni; + QString dev_uni; + QString spec_object; + NMVariantMapMap map_settings; + NetworkManager::AccessPoint::Ptr accessPointPtr = nullptr; + + if (!isHidden) { + NetworkManager::WirelessNetwork::Ptr wifiNet = checkWifiNetExist(connSettingInfo.m_ssid, devIface); + if (wifiNet.isNull()) { + QString errorMessage = "the ssid " + connSettingInfo.m_ssid + " is not exsit in " + devIface; + qWarning()<referenceAccessPoint(); + conn_uni = accessPointPtr->uni(); + spec_object = conn_uni; + } + + auto dev = m_networkResourceInstance->findDeviceInterface(devIface); + if (dev.isNull()) { + Q_EMIT addAndActivateConnectionError("can not find device"); + return; + } + dev_uni = dev->uni(); + + NetworkManager::ConnectionSettings::Ptr settings = + assembleWirelessSettings(accessPointPtr, connSettingInfo, isHidden); + assembleEapMethodFastSettings(settings, info); + + if(settings.isNull()) { + qDebug() << "assembleEapMethodFastSettings failed"; + return; + } + + map_settings = settings->toMap(); + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(map_settings, dev_uni, spec_object), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = watcher->error().message(); + qDebug() << "addAndActiveWirelessEnterPriseFastConnect failed " << errorMessage; + Q_EMIT addAndActivateConnectionError(errorMessage); + } + watcher->deleteLater(); + }); +} + //无线网络开关设置 void KyWirelessConnectOperation::setWirelessEnabled(bool enabled) { @@ -1109,6 +1422,12 @@ bool KyWirelessConnectOperation::getEnterpiseEapMethod(const QString &uuid, KyEa type = PEAP; } else if (list.contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodTtls)) { type = TTLS; + } else if (list.contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodLeap)) { + type = LEAP; + } else if (list.contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodPwd)) { + type = PWD; + } else if (list.contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodFast)) { + type = FAST; } return true; diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.h b/src/backend/dbus-interface/kywirelessconnectoperation.h index a6d551e0..94d91858 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.h +++ b/src/backend/dbus-interface/kywirelessconnectoperation.h @@ -99,6 +99,12 @@ public: void addPeapConnect(const KyWirelessConnectSetting &connSettingInfo, const KyEapMethodPeapInfo &peapInfo); //新增TTLS连接 void addTtlsConnect(const KyWirelessConnectSetting &connSettingInfo, const KyEapMethodTtlsInfo &ttlsInfo); + //新增LEAP连接 + void addLeapConnect(const KyWirelessConnectSetting &connSettingInfo, const KyEapMethodLeapInfo &leapInfo); + //新增PWD连接 + void addPwdConnect(const KyWirelessConnectSetting &connSettingInfo, const KyEapMethodPwdInfo &pwdInfo); + //新增FAST连接 + void addFastConnect(const KyWirelessConnectSetting &connSettingInfo, const KyEapMethodFastInfo &fastInfo); //新增连接并激活(普通wifi) void addAndActiveWirelessConnect(QString & devIface,KyWirelessConnectSetting &connSettingInfo,bool isHidden); @@ -109,6 +115,12 @@ public: QString & devIface, bool isHidden); void addAndActiveWirelessEnterPriseTtlsConnect(KyEapMethodTtlsInfo &info, KyWirelessConnectSetting &connSettingInfo, QString & devIface, bool isHidden); + void addAndActiveWirelessEnterPriseLeapConnect(KyEapMethodLeapInfo &info, KyWirelessConnectSetting &connSettingInfo, + QString & devIface, bool isHidden); + void addAndActiveWirelessEnterPrisePwdConnect(KyEapMethodPwdInfo &info, KyWirelessConnectSetting &connSettingInfo, + QString & devIface, bool isHidden); + void addAndActiveWirelessEnterPriseFastConnect(KyEapMethodFastInfo &info, KyWirelessConnectSetting &connSettingInfo, + QString & devIface, bool isHidden); //属性页 page1 AutoConnect void setWirelessAutoConnect(const QString &uuid, bool bAutoConnect); //属性页 page2 page3 ipv6 @@ -120,6 +132,9 @@ public: void updateWirelessEnterPriseTlsConnect(const QString &uuid, const KyEapMethodTlsInfo &tlsinfo); void updateWirelessEnterPrisePeapConnect(const QString &uuid, const KyEapMethodPeapInfo &peapInfo); void updateWirelessEnterPriseTtlsConnect(const QString &uuid, const KyEapMethodTtlsInfo &ttlsInfo); + void updateWirelessEnterPriseLeapConnect(const QString &uuid, const KyEapMethodLeapInfo &leapInfo); + void updateWirelessEnterPrisePwdConnect(const QString &uuid, const KyEapMethodPwdInfo &pwdInfo); + void updateWirelessEnterPriseFastConnect(const QString &uuid, const KyEapMethodFastInfo &fastInfo); //忘记 void deleteWirelessConnect(const QString &connectUuid); //获取密码 diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index 2ec9bcf0..bee368d8 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -626,6 +626,119 @@ bool KyWirelessNetResource::getEnterPriseInfoTtls(QString &uuid, KyEapMethodTtls return true; } +bool KyWirelessNetResource::getEnterPriseInfoLeap(QString &uuid, KyEapMethodLeapInfo &info) +{ + NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid); + if (conn.isNull()) { + qDebug()<< LOG_FLAG << "getEnterPriseInfoLeap connection missing"; + return false; + } + NetworkManager::WirelessSecuritySetting::Ptr security_sett + = conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); + if (security_sett.isNull()) { + qDebug()<< LOG_FLAG << "don't have WirelessSecurity connection"; + return false; + } + + if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap) { + qDebug()<< LOG_FLAG << "keyMgmt not WpaEap " << security_sett->keyMgmt(); + return false; + } + + NetworkManager::Security8021xSetting::Ptr setting = + conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodLeap)) { + qDebug()<< LOG_FLAG << "don't have Security8021x connection"; + return false; + } + + info.m_userName = setting->identity(); + info.m_passwdFlag = setting->passwordFlags(); + if (!info.m_passwdFlag) { + info.m_userPwd = m_operation->get8021xPassword(conn->uuid()); + } + + return true; +} + +bool KyWirelessNetResource::getEnterPriseInfoPwd(QString &uuid, KyEapMethodPwdInfo &info) +{ + NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid); + if (conn.isNull()) { + qDebug()<< LOG_FLAG << "getEnterPriseInfoPwd connection missing"; + return false; + } + NetworkManager::WirelessSecuritySetting::Ptr security_sett + = conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); + if (security_sett.isNull()) { + qDebug()<< LOG_FLAG << "don't have WirelessSecurity connection"; + return false; + } + + if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap) { + qDebug()<< LOG_FLAG << "keyMgmt not WpaEap " << security_sett->keyMgmt(); + return false; + } + + NetworkManager::Security8021xSetting::Ptr setting = + conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodPwd)) { + qDebug()<< LOG_FLAG << "don't have Security8021x connection"; + return false; + } + + info.m_userName = setting->identity(); + info.m_passwdFlag = setting->passwordFlags(); + if (!info.m_passwdFlag) { + info.m_userPwd = m_operation->get8021xPassword(conn->uuid()); + } + + return true; +} + +bool KyWirelessNetResource::getEnterPriseInfoFast(QString &uuid, KyEapMethodFastInfo &info) +{ + NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid); + if (conn.isNull()) { + qDebug()<< LOG_FLAG << "getEnterPriseInfoFast connection missing"; + return false; + } + NetworkManager::WirelessSecuritySetting::Ptr security_sett + = conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); + if (security_sett.isNull()) { + qDebug()<< LOG_FLAG << "don't have WirelessSecurity connection"; + return false; + } + + if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap) { + qDebug()<< LOG_FLAG << "keyMgmt not WpaEap " << security_sett->keyMgmt(); + return false; + } + + NetworkManager::Security8021xSetting::Ptr setting = + conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodFast)) { + qDebug()<< LOG_FLAG << "don't have Security8021x connection"; + return false; + } + + info.m_anonIdentity = setting->anonymousIdentity(); + info.m_pacProvisioning = (KyFastProvisioning)setting->phase1FastProvisioning(); + info.m_pacFilePath = setting->caPath(); + if (info.m_pacFilePath.left(7) == "file://") { + info.m_pacFilePath = info.m_pacFilePath.mid(7); + } + info.m_authMethod = (KyNoEapMethodAuth)setting->phase2AuthMethod(); + + info.m_userName = setting->identity(); + info.m_passwdFlag = setting->passwordFlags(); + if (!info.m_passwdFlag) { + info.m_userPwd = m_operation->get8021xPassword(conn->uuid()); + } + + return true; +} + void KyWirelessNetResource::onConnectionAdd(QString uuid) { qDebug() << LOG_FLAG << "onConnectionAdd " << uuid; diff --git a/src/backend/dbus-interface/kywirelessnetresource.h b/src/backend/dbus-interface/kywirelessnetresource.h index 7afe52fe..ac1e5f5b 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.h +++ b/src/backend/dbus-interface/kywirelessnetresource.h @@ -46,6 +46,9 @@ public: bool getEnterPriseInfoTls(QString &uuid, KyEapMethodTlsInfo &info); bool getEnterPriseInfoPeap(QString &uuid, KyEapMethodPeapInfo &info); bool getEnterPriseInfoTtls(QString &uuid, KyEapMethodTtlsInfo &info); + bool getEnterPriseInfoLeap(QString &uuid, KyEapMethodLeapInfo &info); + bool getEnterPriseInfoPwd(QString &uuid, KyEapMethodPwdInfo &info); + bool getEnterPriseInfoFast(QString &uuid, KyEapMethodFastInfo &info); void getWirelessActiveConnection(NetworkManager::ActiveConnection::State state, QMap &map); bool getActiveWirelessNetItem(QString deviceName, KyWirelessNetItem &wirelessNetItem); diff --git a/src/backend/dbusadaptor.cpp b/src/backend/dbusadaptor.cpp index 0f22c845..d3325af3 100644 --- a/src/backend/dbusadaptor.cpp +++ b/src/backend/dbusadaptor.cpp @@ -147,6 +147,18 @@ void DbusAdaptor::setDeviceEnable(QString devName, bool enable) // return deviceName; //} +//删除 +void DbusAdaptor::deleteConnect(int type, QString ssid) +{ + if (type == WIRED) { + parent()->deleteWired(ssid); + } else if (type == WIRELESS) { + //待实现 + } else { + qDebug() << "[DbusAdaptor] deleteConnect type is invalid"; + } +} + //连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid void DbusAdaptor::activateConnect(int type, QString devName, QString ssid) { diff --git a/src/backend/dbusadaptor.h b/src/backend/dbusadaptor.h index 6cb0f411..500ebfa3 100644 --- a/src/backend/dbusadaptor.h +++ b/src/backend/dbusadaptor.h @@ -62,6 +62,8 @@ public Q_SLOTS: // METHODS // QString getDefaultWiredDevice(); // Q_NOREPLY void setDefaultWirelessDevice(QString deviceName); // QString getDefaultWirelessDevice(); + //刪除 根据网络名称 参数1 0:lan 1:wlan 参数2 为ssid/uuid + Q_NOREPLY void deleteConnect(int type, QString ssid); //连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid Q_NOREPLY void activateConnect(int type, QString devName, QString ssid); //断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid diff --git a/src/frontend/enterprise-wlan/enterprisewlandialog.cpp b/src/frontend/enterprise-wlan/enterprisewlandialog.cpp index 3a589886..332f45d1 100644 --- a/src/frontend/enterprise-wlan/enterprisewlandialog.cpp +++ b/src/frontend/enterprise-wlan/enterprisewlandialog.cpp @@ -256,7 +256,16 @@ void EnterpriseWlanDialog::onBtnConnectClicked() } else if (eapType == KyEapMethodType::TTLS) { m_securityPage->updateTtlsChange(m_info.ttlsInfo); m_connectOperation->addAndActiveWirelessEnterPriseTtlsConnect(m_info.ttlsInfo, connetSetting, m_deviceName, false); - } else { + } else if (eapType == KyEapMethodType::LEAP) { + m_securityPage->updateLeapChange(m_info.leapInfo); + m_connectOperation->addAndActiveWirelessEnterPriseLeapConnect(m_info.leapInfo, connetSetting, m_deviceName, false); + } else if (eapType == KyEapMethodType::PWD) { + m_securityPage->updatePwdChange(m_info.pwdInfo); + m_connectOperation->addAndActiveWirelessEnterPrisePwdConnect(m_info.pwdInfo, connetSetting, m_deviceName, false); + } else if (eapType == KyEapMethodType::FAST) { + m_securityPage->updateFastChange(m_info.fastInfo); + m_connectOperation->addAndActiveWirelessEnterPriseFastConnect(m_info.fastInfo, connetSetting, m_deviceName, false); + } else { qWarning() << "Connect enterprise wlan failed!(Unknown eap type)" << Q_FUNC_INFO << __LINE__; } close(); @@ -286,6 +295,24 @@ void EnterpriseWlanDialog::onEapTypeChanged(const KyEapMethodType &type) this->setFixedSize(MAIN_SIZE_NARROW); // m_centerWidget->setFixedHeight(PEAP_SCRO_HEIGHT); break; + case KyEapMethodType::LEAP: + if (!m_wirelessNetItem.m_connectUuid.isEmpty()) { + m_resource->getEnterPriseInfoLeap(m_wirelessNetItem.m_connectUuid, m_info.leapInfo); + } + this->setFixedSize(MAIN_SIZE_NARROW); + break; + case KyEapMethodType::PWD: + if (!m_wirelessNetItem.m_connectUuid.isEmpty()) { + m_resource->getEnterPriseInfoPwd(m_wirelessNetItem.m_connectUuid, m_info.pwdInfo); + } + this->setFixedSize(MAIN_SIZE_NARROW); + break; + case KyEapMethodType::FAST: + if (!m_wirelessNetItem.m_connectUuid.isEmpty()) { + m_resource->getEnterPriseInfoFast(m_wirelessNetItem.m_connectUuid, m_info.fastInfo); + } + this->setFixedSize(MAIN_SIZE_EXPAND); + break; default: break; } diff --git a/src/frontend/mainwindow.cpp b/src/frontend/mainwindow.cpp index 19a0ff29..0a90a030 100644 --- a/src/frontend/mainwindow.cpp +++ b/src/frontend/mainwindow.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "kylinnetworkdeviceresource.h" #include "../backend/dbus-interface/kylinagentinterface.h" @@ -191,19 +192,19 @@ void MainWindow::secondaryStart() */ void MainWindow::initPlatform() { - char* projectName = kdk_system_get_projectName(); - QString strProjectName(projectName); - free(projectName); - projectName = NULL; - if(v10Sp1.compare(strProjectName,Qt::CaseInsensitive) == 0) { - unsigned int feature = kdk_system_get_productFeatures(); - if (feature == 3) { - m_isShowInCenter = true; - } - } else if (intel.compare(strProjectName,Qt::CaseInsensitive) == 0) { - m_isShowInCenter = true; - } - qDebug() << "projectName" << projectName << m_isShowInCenter; +// char* projectName = kdk_system_get_projectName(); +// QString strProjectName(projectName); +// free(projectName); +// projectName = NULL; +// if(v10Sp1.compare(strProjectName,Qt::CaseInsensitive) == 0) { +// unsigned int feature = kdk_system_get_productFeatures(); +// if (feature == 3) { +// m_isShowInCenter = true; +// } +// } else if (intel.compare(strProjectName,Qt::CaseInsensitive) == 0) { +// m_isShowInCenter = true; +// } +// qDebug() << "projectName" << projectName << m_isShowInCenter; } /** @@ -911,6 +912,12 @@ void MainWindow::getWirelessDeviceCap(QMap &map) m_wlanWidget->getWirelessDeviceCap(map); } +//有线连接删除 +void MainWindow::deleteWired(const QString &connUuid) +{ + m_lanWidget->deleteWired(connUuid); +} + //有线连接断开 void MainWindow::activateWired(const QString& devName, const QString& connUuid) { diff --git a/src/frontend/mainwindow.h b/src/frontend/mainwindow.h index d16533b8..ab30866b 100644 --- a/src/frontend/mainwindow.h +++ b/src/frontend/mainwindow.h @@ -83,6 +83,8 @@ public: void getApConnectionPath(QString &path, QString uuid); //获取热点ActivePath void getActiveConnectionPath(QString &path, QString uuid); + //删除有线连接 + void deleteWired(const QString& connUuid); //有线连接断开 void activateWired(const QString& devName, const QString& connUuid); void deactivateWired(const QString& devName, const QString& connUuid); diff --git a/src/frontend/netdetails/coninfo.h b/src/frontend/netdetails/coninfo.h index 1aef5fb4..330165e6 100644 --- a/src/frontend/netdetails/coninfo.h +++ b/src/frontend/netdetails/coninfo.h @@ -55,6 +55,19 @@ enum TtlsInnerType GTC_EAP }; +enum FastInnerType +{ + GTC_FAST = 0, + MSCHAPV2_FAST, +}; + +enum PacProvisioningInnerType +{ + ANON = 0, + AUTHEN, + BOTH, +}; + class LineEdit : public QLineEdit { Q_OBJECT @@ -91,21 +104,22 @@ public: KyIpConfigType ipv4ConfigType = CONFIG_IP_DHCP; QString strIPV4Address; QString strIPV4NetMask; - QString strIPV4FirDns; - QString strIPV4SecDns; QString strIPV4GateWay; + QList ipv4DnsList; KyIpConfigType ipv6ConfigType = CONFIG_IP_DHCP; QString strIPV6Address; int iIPV6Prefix; - QString strIPV6FirDns; - QString strIPV6SecDns; QString strIPV6GateWay; + QList ipv6DnsList; KyEapMethodType enterpriseType; KyEapMethodTlsInfo tlsInfo; KyEapMethodPeapInfo peapInfo; KyEapMethodTtlsInfo ttlsInfo; + KyEapMethodLeapInfo leapInfo; + KyEapMethodPwdInfo pwdInfo; + KyEapMethodFastInfo fastInfo; }; static void setFramePalette(QFrame *widget, QPalette &pal) { diff --git a/src/frontend/netdetails/creatnetpage.cpp b/src/frontend/netdetails/creatnetpage.cpp index 7f242c5e..33153c52 100644 --- a/src/frontend/netdetails/creatnetpage.cpp +++ b/src/frontend/netdetails/creatnetpage.cpp @@ -38,25 +38,23 @@ void CreatNetPage::initUI() ipv4addressEdit = new LineEdit(this); netMaskEdit = new LineEdit(this); gateWayEdit = new LineEdit(this); - firstDnsEdit = new LineEdit(this); - secondDnsEdit = new LineEdit(this); m_connNameLabel = new QLabel(this); m_configLabel = new QLabel(this); m_addressLabel = new QLabel(this); m_maskLabel = new QLabel(this); m_gateWayLabel = new QLabel(this); - m_dnsLabel = new QLabel(this); - m_secDnsLabel = new QLabel(this); + + // IP的正则格式限制 + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + m_dnsWidget = new MultipleDnsWidget(rx, this); QLabel *nameEmptyLabel = new QLabel(this); QLabel *configEmptyLabel = new QLabel(this); QLabel *gateWayEmptyLabel = new QLabel(this); - QLabel *firstDnsEmptyLabel = new QLabel(this); nameEmptyLabel->setFixedHeight(LABEL_HEIGHT); configEmptyLabel->setFixedHeight(LABEL_HEIGHT); gateWayEmptyLabel->setFixedHeight(LABEL_HEIGHT); - firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT); m_addressHintLabel = new QLabel(this); m_maskHintLabel = new QLabel(this); @@ -89,8 +87,6 @@ void CreatNetPage::initUI() m_addressLabel->setText(tr("Address")); m_maskLabel->setText(tr("Netmask")); m_gateWayLabel->setText(tr("Default Gateway")); - m_dnsLabel->setText(tr("Prefs DNS")); - m_secDnsLabel->setText(tr("Alternative DNS")); m_detailLayout = new QFormLayout(this); m_detailLayout->setVerticalSpacing(0); @@ -103,22 +99,14 @@ void CreatNetPage::initUI() m_detailLayout->addRow(m_maskLabel, maskWidget); m_detailLayout->addRow(m_gateWayLabel,gateWayEdit); m_detailLayout->addRow(gateWayEmptyLabel); - m_detailLayout->addRow(m_dnsLabel,firstDnsEdit); - m_detailLayout->addRow(firstDnsEmptyLabel); - m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit); + m_detailLayout->addRow(m_dnsWidget); ipv4ConfigCombox->addItem(tr("Auto(DHCP)"), AUTO_CONFIG); //"自动(DHCP)" ipv4ConfigCombox->addItem(tr("Manual"), MANUAL_CONFIG); //"手动" - - // IP的正则格式限制 - QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); - ipv4addressEdit->setValidator(new QRegExpValidator(rx, this)); gateWayEdit->setValidator(new QRegExpValidator(rx, this)); netMaskEdit->setValidator(new QRegExpValidator(rx, this)); - firstDnsEdit->setValidator(new QRegExpValidator(rx, this)); - secondDnsEdit->setValidator(new QRegExpValidator(rx, this)); } void CreatNetPage::initComponent() { @@ -133,8 +121,6 @@ void CreatNetPage::initComponent() { connect(ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn())); connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); - connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); - connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(ipv4addressEdit, SIGNAL(textChanged(QString)), this, SLOT(onAddressTextChanged())); connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(onNetMaskTextChanged())); @@ -159,26 +145,6 @@ bool CreatNetPage::checkConnectBtnIsEnabled() qDebug() << "create ipv4 netMask empty or invalid"; return false; } - -// if (gateWayEdit->text().isEmpty() || !getTextEditState(gateWayEdit->text())) { -// qDebug() << "create ipv4 gateway empty or invalid"; -// return false; -// } - - if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) { - qDebug() << "create ipv4 dns sort invalid"; - return false; - } - - if (!getTextEditState(firstDnsEdit->text())) { - qDebug() << "create ipv4 first dns invalid"; - return false; - } - - if (!getTextEditState(secondDnsEdit->text())) { - qDebug() << "create ipv4 second dns invalid"; - return false; - } } return true; } @@ -215,15 +181,11 @@ void CreatNetPage::setLineEnabled(bool check) { ipv4addressEdit->setEnabled(check); netMaskEdit->setEnabled(check); gateWayEdit->setEnabled(check); - firstDnsEdit->setEnabled(check); - secondDnsEdit->setEnabled(check); if (!check) { ipv4addressEdit->clear(); netMaskEdit->clear(); gateWayEdit->clear(); - firstDnsEdit->clear(); - secondDnsEdit->clear(); ipv4addressEdit->setPlaceholderText(" "); netMaskEdit->setPlaceholderText(" "); @@ -260,19 +222,16 @@ void CreatNetPage::constructIpv4Info(KyConnectSetting &setting) << " netMask " << netMask << " gateWay " << gateWay; - QStringList dnsList; - dnsList.empty(); - if (!firstDnsEdit->text().isEmpty()) { - dnsList << firstDnsEdit->text(); - if (!secondDnsEdit->text().isEmpty()) { - dnsList << secondDnsEdit->text(); - } - } + QList ipv4dnsList; + ipv4dnsList.clear(); + ipv4dnsList = m_dnsWidget->getDns(); + if (ipv4ConfigCombox->currentData() == AUTO_CONFIG) { setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP); } else { setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_MANUAL); - setting.ipv4AddressConstruct(ipv4address, netMask, gateWay, dnsList); + setting.ipv4AddressConstruct(ipv4address, netMask, gateWay); + setting.ipv4DnsConstruct(ipv4dnsList); } } diff --git a/src/frontend/netdetails/creatnetpage.h b/src/frontend/netdetails/creatnetpage.h index 71ccefd7..1eb2934f 100644 --- a/src/frontend/netdetails/creatnetpage.h +++ b/src/frontend/netdetails/creatnetpage.h @@ -32,6 +32,7 @@ #include #include "coninfo.h" +#include "multiplednswidget.h" class CreatNetPage : public QFrame { @@ -57,11 +58,11 @@ private: QLabel *m_addressLabel; QLabel *m_maskLabel; QLabel *m_gateWayLabel; - QLabel *m_dnsLabel; - QLabel *m_secDnsLabel; QLabel *m_addressHintLabel; QLabel *m_maskHintLabel; + + MultipleDnsWidget *m_dnsWidget = nullptr; private: void initUI(); void initComponent(); diff --git a/src/frontend/netdetails/detailpage.cpp b/src/frontend/netdetails/detailpage.cpp index 159dbb2a..48b36a3e 100644 --- a/src/frontend/netdetails/detailpage.cpp +++ b/src/frontend/netdetails/detailpage.cpp @@ -246,9 +246,11 @@ void DetailPage::initUI() { m_ipv4Widget = new DetailWidget(qobject_cast(m_IPV4), m_listWidget); m_ipv4Widget->setKey(tr("IPv4:")); - m_IPV4Dns = new QLabel(this); + m_IPV4Dns = new FixLabel(this); + m_IPV4Dns->setFixedWidth(MAX_LABEL_WIDTH); + m_IPV4Dns->setAlignment(Qt::AlignRight | Qt::AlignVCenter); m_ipv4DnsWidget = new DetailWidget(qobject_cast(m_IPV4Dns), m_listWidget); - m_ipv4DnsWidget->setKey(tr("IPv4 DNS:")); + m_ipv4DnsWidget->setKey(tr("IPv4 Dns:")); m_IPV6 = new FixLabel(this); m_IPV6->setFixedWidth(MAX_LABEL_WIDTH); diff --git a/src/frontend/netdetails/detailpage.h b/src/frontend/netdetails/detailpage.h index 75aaa61e..208b15d1 100644 --- a/src/frontend/netdetails/detailpage.h +++ b/src/frontend/netdetails/detailpage.h @@ -91,7 +91,7 @@ public: QLabel *m_Chan; QLabel *m_BandWidth; QLabel *m_IPV4; - QLabel *m_IPV4Dns; + FixLabel *m_IPV4Dns; FixLabel *m_IPV6; QLabel *m_Mac; QLabel *m_autoConnect; diff --git a/src/frontend/netdetails/ipv4page.cpp b/src/frontend/netdetails/ipv4page.cpp index 6e2ca81c..7877b5bf 100644 --- a/src/frontend/netdetails/ipv4page.cpp +++ b/src/frontend/netdetails/ipv4page.cpp @@ -39,15 +39,11 @@ void Ipv4Page::initUI() { ipv4addressEdit = new LineEdit(this); netMaskEdit = new LineEdit(this); gateWayEdit = new LineEdit(this); - firstDnsEdit = new LineEdit(this); - secondDnsEdit = new LineEdit(this); m_configLabel = new QLabel(this); m_addressLabel = new QLabel(this); m_maskLabel = new QLabel(this); m_gateWayLabel = new QLabel(this); - m_dnsLabel = new QLabel(this); - m_secDnsLabel = new QLabel(this); m_configEmptyLabel = new QLabel(this); m_configEmptyLabel->setFixedHeight(LABEL_HEIGHT); @@ -64,16 +60,10 @@ void Ipv4Page::initUI() { m_gateWayEmptyLabel = new QLabel(this); m_gateWayEmptyLabel->setFixedHeight(LABEL_HEIGHT); - m_firstDnsEmptyLabel = new QLabel(this); - m_firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT); - - m_configLabel->setText(tr("IPv4Config")); m_addressLabel->setText(tr("Address")); m_maskLabel->setText(tr("Netmask")); m_gateWayLabel->setText(tr("Default Gateway")); - m_dnsLabel->setText(tr("Prefs DNS")); - m_secDnsLabel->setText(tr("Alternative DNS")); m_statusLabel = new QLabel(this); m_statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); @@ -100,6 +90,10 @@ void Ipv4Page::initUI() { maskLayout->addWidget(netMaskEdit); maskLayout->addWidget(m_maskHintLabel); + // IP的正则格式限制 + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + m_dnsWidget = new MultipleDnsWidget(rx, this); + m_detailLayout = new QFormLayout(this); m_detailLayout->setVerticalSpacing(0); m_detailLayout->setContentsMargins(LAYOUT_MARGINS); @@ -109,9 +103,7 @@ void Ipv4Page::initUI() { m_detailLayout->addRow(m_maskLabel,maskWidget); m_detailLayout->addRow(m_gateWayLabel,gateWayEdit); m_detailLayout->addRow(m_gateWayEmptyLabel); - m_detailLayout->addRow(m_dnsLabel,firstDnsEdit); - m_detailLayout->addRow(m_firstDnsEmptyLabel); - m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit); + m_detailLayout->addRow(m_dnsWidget); ipv4ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)" ipv4ConfigCombox->addItem(tr("Manual")); //"手动" @@ -123,15 +115,9 @@ void Ipv4Page::initUI() { // netMaskCombox->addItem("255.255.0.0"); //16 // netMaskCombox->addItem("255.0.0.0"); //8 - - // IP的正则格式限制 - QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); - ipv4addressEdit->setValidator(new QRegExpValidator(rx, this)); gateWayEdit->setValidator(new QRegExpValidator(rx, this)); netMaskEdit->setValidator(new QRegExpValidator(rx, this)); - firstDnsEdit->setValidator(new QRegExpValidator(rx, this)); - secondDnsEdit->setValidator(new QRegExpValidator(rx, this)); initLoadingIcon(); } @@ -152,8 +138,6 @@ void Ipv4Page::initComponent() { connect(ipv4addressEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); - connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); - connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); } void Ipv4Page::setIpv4Config(KyIpConfigType ipv4Config) @@ -175,14 +159,9 @@ void Ipv4Page::setNetMask(const QString &netMask) netMaskEdit->setText(netMask); } -void Ipv4Page::setIpv4FirDns(const QString &ipv4FirDns) +void Ipv4Page::setMulDns(const QList &dns) { - firstDnsEdit->setText(ipv4FirDns); -} - -void Ipv4Page::setIpv4SecDns(const QString &ipv4SecDns) -{ - secondDnsEdit->setText(ipv4SecDns); + m_dnsWidget->setDnsListText(dns); } void Ipv4Page::setGateWay(const QString &gateWay) @@ -193,6 +172,16 @@ void Ipv4Page::setGateWay(const QString &gateWay) bool Ipv4Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) { bool isChanged = false; + + QList ipv4DnsList; + ipv4DnsList.clear(); + ipv4DnsList = m_dnsWidget->getDns(); + if (info.ipv4DnsList != ipv4DnsList) { + qDebug() << "ipv4 dns changed"; + setting.ipv4DnsConstruct(ipv4DnsList); + isChanged = true; + } + if (ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { if (info.ipv4ConfigType != CONFIG_IP_DHCP) { qDebug() << "ipv4ConfigType change to Auto"; @@ -200,10 +189,9 @@ bool Ipv4Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) QString ipv4address(""); QString netMask(""); QString gateWay(""); - QStringList dnsList; - dnsList.empty(); + qDebug() << ipv4address << netMask << gateWay; - setting.ipv4AddressConstruct(ipv4address, netMask, gateWay, dnsList); + setting.ipv4AddressConstruct(ipv4address, netMask, gateWay); isChanged = true; } } else { @@ -215,25 +203,15 @@ bool Ipv4Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) qDebug() << "ipv4 netmask " << getNetMaskText(netMaskEdit->text()); if(info.strIPV4Address != ipv4addressEdit->text() || info.strIPV4NetMask != /*netMaskEdit->text()*/getNetMaskText(netMaskEdit->text()) - || info.strIPV4GateWay != gateWayEdit->text() - || info.strIPV4FirDns != firstDnsEdit->text() - || info.strIPV4SecDns != secondDnsEdit->text()) { + || info.strIPV4GateWay != gateWayEdit->text()) { qDebug() << "ipv4 info changed"; - QStringList dnsList; - dnsList.empty(); - if (!firstDnsEdit->text().isEmpty()) { - dnsList << firstDnsEdit->text(); - if (!secondDnsEdit->text().isEmpty()) { - dnsList << secondDnsEdit->text(); - } - } QString ipv4address =ipv4addressEdit->text(); QString netMask = getNetMaskText(netMaskEdit->text()); QString gateWay = gateWayEdit->text(); qDebug() << ipv4address << netMask << gateWay; - setting.ipv4AddressConstruct(ipv4address, netMask, gateWay, dnsList); + setting.ipv4AddressConstruct(ipv4address, netMask, gateWay); setting.dumpInfo(); isChanged = true; } @@ -256,26 +234,6 @@ bool Ipv4Page::checkConnectBtnIsEnabled() qDebug() << "ipv4 netMask empty or invalid"; return false; } - -// if (gateWayEdit->text().isEmpty() || !getTextEditState(gateWayEdit->text())) { -// qDebug() << "ipv4 gateway empty or invalid"; -// return false; -// } - - if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) { - qDebug() << "ipv4 dns sort invalid"; - return false; - } - - if (!getTextEditState(firstDnsEdit->text())) { - qDebug() << "ipv4 first dns invalid"; - return false; - } - - if (!getTextEditState(secondDnsEdit->text())) { - qDebug() << "ipv4 second dns invalid"; - return false; - } } return true; } @@ -325,8 +283,6 @@ void Ipv4Page::setLineEnabled(bool check) { ipv4addressEdit->clear(); netMaskEdit->clear(); gateWayEdit->clear(); - firstDnsEdit->clear(); - secondDnsEdit->clear(); ipv4addressEdit->setPlaceholderText(" "); netMaskEdit->setPlaceholderText(" "); @@ -339,8 +295,6 @@ void Ipv4Page::setLineEnabled(bool check) { ipv4addressEdit->setEnabled(check); netMaskEdit->setEnabled(check); gateWayEdit->setEnabled(check); - firstDnsEdit->setEnabled(check); - secondDnsEdit->setEnabled(check); } void Ipv4Page::setEnableOfSaveBtn() { diff --git a/src/frontend/netdetails/ipv4page.h b/src/frontend/netdetails/ipv4page.h index 55c2be09..88af57df 100644 --- a/src/frontend/netdetails/ipv4page.h +++ b/src/frontend/netdetails/ipv4page.h @@ -33,6 +33,7 @@ //#include "kylinconnectsetting.h" #include "coninfo.h" +#include "multiplednswidget.h" class Ipv4Page : public QFrame { @@ -42,8 +43,7 @@ public: void setIpv4Config(KyIpConfigType ipv4Config); void setIpv4(const QString &ipv4); void setNetMask(const QString &netMask); - void setIpv4FirDns(const QString &ipv4FirDns); - void setIpv4SecDns(const QString &ipv4SecDns); + void setMulDns(const QList &dns); void setGateWay(const QString &gateWay); bool checkIsChanged(const ConInfo info, KyConnectSetting &setting); @@ -59,8 +59,6 @@ private: LineEdit *ipv4addressEdit; LineEdit *netMaskEdit; LineEdit *gateWayEdit; - LineEdit *firstDnsEdit; - LineEdit *secondDnsEdit; QFormLayout *m_detailLayout; QVBoxLayout *mvBoxLayout; @@ -68,14 +66,13 @@ private: QLabel *m_addressLabel; QLabel *m_maskLabel; QLabel *m_gateWayLabel; - QLabel *m_dnsLabel; - QLabel *m_secDnsLabel; QLabel *m_configEmptyLabel; QLabel *m_addressHintLabel; QLabel *m_maskHintLabel; QLabel *m_gateWayEmptyLabel; - QLabel *m_firstDnsEmptyLabel; + + MultipleDnsWidget *m_dnsWidget = nullptr; QLabel *m_statusLabel = nullptr; QList m_loadIcons; diff --git a/src/frontend/netdetails/ipv6page.cpp b/src/frontend/netdetails/ipv6page.cpp index ed34bce8..22e106bb 100644 --- a/src/frontend/netdetails/ipv6page.cpp +++ b/src/frontend/netdetails/ipv6page.cpp @@ -52,14 +52,9 @@ void Ipv6Page::setIpv6Perfix(const int &ipv6Perfix) lengthEdit->setText(QString::number(ipv6Perfix)); } -void Ipv6Page::setIpv6FirDns(const QString &ipv6FirDns) +void Ipv6Page::setMulDns(const QList &dns) { - firstDnsEdit->setText(ipv6FirDns); -} - -void Ipv6Page::setIpv6SecDns(const QString &ipv6SecDns) -{ - secondDnsEdit->setText(ipv6SecDns); + m_dnsWidget->setDnsListText(dns); } void Ipv6Page::setGateWay(const QString &gateWay) @@ -70,6 +65,16 @@ void Ipv6Page::setGateWay(const QString &gateWay) bool Ipv6Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) { bool isChanged = false; + + QList ipv6DnsList; + ipv6DnsList.clear(); + ipv6DnsList = m_dnsWidget->getDns(); + if (info.ipv6DnsList != ipv6DnsList) { + qDebug() << "ipv6 dns changed"; + setting.ipv6DnsConstruct(ipv6DnsList); + isChanged = true; + } + if (ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { if (info.ipv6ConfigType != CONFIG_IP_DHCP) { qDebug() << "ipv6ConfigType change to Auto"; @@ -77,9 +82,7 @@ bool Ipv6Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) QString ipv6address(""); QString prefix(""); QString gateWay(""); - QStringList dnsList; - dnsList.empty(); - setting.ipv6AddressConstruct(ipv6address, prefix, gateWay, dnsList); + setting.ipv6AddressConstruct(ipv6address, prefix, gateWay); isChanged = true; } } else { @@ -88,26 +91,20 @@ bool Ipv6Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) setting.setIpConfigType(IPADDRESS_V6, CONFIG_IP_MANUAL); isChanged = true; } + + QList ipv6dnsList; + ipv6dnsList.clear(); + ipv6dnsList = m_dnsWidget->getDns(); if(info.strIPV6Address != ipv6AddressEdit->text() || info.iIPV6Prefix != lengthEdit->text().toInt() - || info.strIPV6GateWay != gateWayEdit->text() - || info.strIPV6FirDns != firstDnsEdit->text() - || info.strIPV6SecDns != secondDnsEdit->text()) { + || info.strIPV6GateWay != gateWayEdit->text()) { qDebug() << "ipv6 info changed"; - QStringList dnsList; - dnsList.empty(); - if (!firstDnsEdit->text().isEmpty()) { - dnsList << firstDnsEdit->text(); - if (!secondDnsEdit->text().isEmpty()) { - dnsList << secondDnsEdit->text(); - } - } QString ipv6address =ipv6AddressEdit->text(); QString prefix = lengthEdit->text(); QString gateWay = gateWayEdit->text(); - setting.ipv6AddressConstruct(ipv6address, prefix, gateWay, dnsList); + setting.ipv6AddressConstruct(ipv6address, prefix, gateWay); setting.dumpInfo(); isChanged = true; } @@ -120,15 +117,11 @@ void Ipv6Page::initUI() { ipv6AddressEdit = new LineEdit(this); lengthEdit = new LineEdit(this); gateWayEdit = new LineEdit(this); - firstDnsEdit = new LineEdit(this); - secondDnsEdit = new LineEdit(this); m_configLabel = new QLabel(this); m_addressLabel = new QLabel(this); m_subnetLabel = new QLabel(this); m_gateWayLabel = new QLabel(this); - m_dnsLabel = new QLabel(this); - m_secDnsLabel = new QLabel(this); m_configEmptyLabel = new QLabel(this); m_configEmptyLabel->setFixedHeight(LABEL_HEIGHT); @@ -145,16 +138,10 @@ void Ipv6Page::initUI() { m_subnetEmptyLabel = new QLabel(this); m_subnetEmptyLabel->setFixedHeight(LABEL_HEIGHT); - m_firstDnsEmptyLabel = new QLabel(this); - m_firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT); - - m_configLabel->setText(tr("IPv6Config")); m_addressLabel->setText(tr("Address")); m_subnetLabel->setText(tr("Subnet prefix Length")); m_gateWayLabel->setText(tr("Default Gateway")); - m_dnsLabel->setText(tr("Prefs DNS")); - m_secDnsLabel->setText(tr("Alternative DNS")); m_statusLabel = new QLabel(this); m_statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); @@ -181,6 +168,9 @@ void Ipv6Page::initUI() { gateWayLayout->addWidget(gateWayEdit); gateWayLayout->addWidget(m_gateWayHintLabel); + QRegExp ipv6_rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); + m_dnsWidget = new MultipleDnsWidget(ipv6_rx, this); + m_detailLayout = new QFormLayout(this); m_detailLayout->setContentsMargins(0, 0, 0, 0); m_detailLayout->setVerticalSpacing(0); @@ -190,18 +180,13 @@ void Ipv6Page::initUI() { m_detailLayout->addRow(m_subnetLabel,lengthEdit); m_detailLayout->addRow(m_subnetEmptyLabel); m_detailLayout->addRow(m_gateWayLabel,gateWayWidget); - m_detailLayout->addRow(m_dnsLabel,firstDnsEdit); - m_detailLayout->addRow(m_firstDnsEmptyLabel); - m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit); + m_detailLayout->addRow(m_dnsWidget); ipv6ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)" ipv6ConfigCombox->addItem(tr("Manual")); //"手动" - QRegExp ipv6_rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); ipv6AddressEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); gateWayEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); - firstDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); - secondDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); QRegExp prefix_rx("\\b(?:(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\.){3}(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\b"); lengthEdit->setValidator(new QRegExpValidator(prefix_rx,this)); @@ -225,8 +210,6 @@ void Ipv6Page::initComponent() { connect(ipv6AddressEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(lengthEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); - connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); - connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); } void Ipv6Page::configChanged(int index) { @@ -244,8 +227,6 @@ void Ipv6Page::setControlEnabled(bool check) ipv6AddressEdit->clear(); lengthEdit->clear(); gateWayEdit->clear(); - firstDnsEdit->clear(); - secondDnsEdit->clear(); ipv6AddressEdit->setPlaceholderText(" "); lengthEdit->setPlaceholderText(" "); @@ -258,8 +239,6 @@ void Ipv6Page::setControlEnabled(bool check) ipv6AddressEdit->setEnabled(check); lengthEdit->setEnabled(check); gateWayEdit->setEnabled(check); - firstDnsEdit->setEnabled(check); - secondDnsEdit->setEnabled(check); } void Ipv6Page::setEnableOfSaveBtn() @@ -311,26 +290,6 @@ bool Ipv6Page::checkConnectBtnIsEnabled() qDebug() << "ipv6 prefix length empty"; return false; } - -// if (gateWayEdit->text().isEmpty() || !getIpv6EditState(gateWayEdit->text())) { -// qDebug() << "ipv6 gateway empty or invalid"; -// return false; -// } - - if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) { - qDebug() << "ipv6 dns sort invalid"; - return false; - } - - if (!getIpv6EditState(firstDnsEdit->text())) { - qDebug() << "ipv6 first dns invalid"; - return false; - } - - if (!getIpv6EditState(secondDnsEdit->text())) { - qDebug() << "ipv6 second dns invalid"; - return false; - } } return true; } diff --git a/src/frontend/netdetails/ipv6page.h b/src/frontend/netdetails/ipv6page.h index a36265df..d3ec09d2 100644 --- a/src/frontend/netdetails/ipv6page.h +++ b/src/frontend/netdetails/ipv6page.h @@ -33,6 +33,7 @@ //#include "kylinconnectsetting.h" #include "coninfo.h" +#include "multiplednswidget.h" class Ipv6Page : public QFrame { @@ -42,8 +43,7 @@ public: void setIpv6Config(KyIpConfigType ipv6Config); void setIpv6(const QString &ipv4); void setIpv6Perfix(const int &ipv6Perfix); - void setIpv6FirDns(const QString &ipv6FirDns); - void setIpv6SecDns(const QString &ipv6SecDns); + void setMulDns(const QList &dns); void setGateWay(const QString &gateWay); bool checkIsChanged(const ConInfo info, KyConnectSetting &setting); @@ -59,22 +59,19 @@ public: LineEdit *ipv6AddressEdit; LineEdit *lengthEdit; LineEdit *gateWayEdit; - LineEdit *firstDnsEdit; - LineEdit *secondDnsEdit; private: QFormLayout *m_detailLayout; QLabel *m_configLabel; QLabel *m_addressLabel; QLabel *m_subnetLabel; QLabel *m_gateWayLabel; - QLabel *m_dnsLabel; - QLabel *m_secDnsLabel; QLabel *m_configEmptyLabel; QLabel *m_addressHintLabel; QLabel *m_subnetEmptyLabel; QLabel *m_gateWayHintLabel; - QLabel *m_firstDnsEmptyLabel; + + MultipleDnsWidget *m_dnsWidget = nullptr; QLabel *m_statusLabel = nullptr; QList m_loadIcons; diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index d470b264..ec5605fb 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -486,28 +486,22 @@ void NetDetail::pagePadding(QString netName, bool isWlan) detailPage->setAutoConnect(m_info.isAutoConnect); //ipv4页面填充 + ipv4Page->setIpv4Config(m_info.ipv4ConfigType); + ipv4Page->setMulDns(m_info.ipv4DnsList); if (m_info.ipv4ConfigType == CONFIG_IP_MANUAL) { Q_EMIT checkCurrentIpv4Conflict(m_info.strIPV4Address); - ipv4Page->setIpv4Config(m_info.ipv4ConfigType); ipv4Page->setIpv4(m_info.strIPV4Address); ipv4Page->setNetMask(m_info.strIPV4NetMask); - ipv4Page->setIpv4FirDns(m_info.strIPV4FirDns); - ipv4Page->setIpv4SecDns(m_info.strIPV4SecDns); ipv4Page->setGateWay(m_info.strIPV4GateWay); - } else { - ipv4Page->setIpv4Config(m_info.ipv4ConfigType); } //ipv6页面填充 + ipv6Page->setIpv6Config(m_info.ipv6ConfigType); + ipv6Page->setMulDns(m_info.ipv6DnsList); if (m_info.ipv6ConfigType == CONFIG_IP_MANUAL) { Q_EMIT checkCurrentIpv6Conflict(m_info.strIPV6Address); - ipv6Page->setIpv6Config(m_info.ipv6ConfigType); ipv6Page->setIpv6(m_info.strIPV6Address); ipv6Page->setIpv6Perfix(m_info.iIPV6Prefix); - ipv6Page->setIpv6FirDns(m_info.strIPV6FirDns); - ipv6Page->setIpv6SecDns(m_info.strIPV6SecDns); ipv6Page->setGateWay(m_info.strIPV6GateWay); - } else { - ipv6Page->setIpv6Config(m_info.ipv6ConfigType); } //安全页面 @@ -521,6 +515,12 @@ void NetDetail::pagePadding(QString netName, bool isWlan) securityPage->setPeapInfo(m_info.peapInfo); } else if (m_info.enterpriseType == TTLS) { securityPage->setTtlsInfo(m_info.ttlsInfo); + } else if (m_info.enterpriseType == LEAP) { + securityPage->setLeapInfo(m_info.leapInfo); + } else if (m_info.enterpriseType == PWD) { + securityPage->setPwdInfo(m_info.pwdInfo); + } else if (m_info.enterpriseType == FAST) { + securityPage->setFastInfo(m_info.fastInfo); } } } @@ -653,6 +653,8 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived) // conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType; conInfo.ipv6ConfigType = connetSetting.m_ipv6ConfigIpType; + conInfo.ipv4DnsList = connetSetting.m_ipv4Dns; + conInfo.ipv6DnsList = connetSetting.m_ipv6Dns; conInfo.isAutoConnect = connetSetting.m_isAutoConnect; // if (connetSetting.m_ipv4ConfigIpType == CONFIG_IP_MANUAL) { @@ -682,19 +684,23 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived) conInfo.iIPV6Prefix = ipv6Page->getPerfixLength(connetSetting.m_ipv6Address.at(0).netmask().toString()); conInfo.strIPV6GateWay = connetSetting.m_ipv6Address.at(0).gateway().toString(); } + } - if (connetSetting.m_ipv6Dns.size() == 1) { - conInfo.strIPV6FirDns = connetSetting.m_ipv6Dns.at(0).toString(); - } else if (connetSetting.m_ipv4Dns.size() > 1) { - conInfo.strIPV6FirDns = connetSetting.m_ipv6Dns.at(0).toString(); - conInfo.strIPV6SecDns = connetSetting.m_ipv6Dns.at(1).toString(); + QString dnsList; + dnsList.clear(); + if (!conInfo.ipv4DnsList.isEmpty()) { + for (QHostAddress str: conInfo.ipv4DnsList) { + dnsList.append(str.toString()); + dnsList.append("; "); } + dnsList.chop(2); + conInfo.strDynamicIpv4Dns = dnsList; } if (!bActived) { conInfo.strDynamicIpv4 = conInfo.strIPV4Address.isEmpty() ? tr("Auto") : conInfo.strIPV4Address; conInfo.strDynamicIpv6 = conInfo.strIPV6Address.isEmpty() ? tr("Auto") : conInfo.strIPV6Address; - conInfo.strDynamicIpv4Dns = conInfo.strIPV4FirDns.isEmpty() ? tr("Auto") : conInfo.strIPV4FirDns; + conInfo.strDynamicIpv4Dns = conInfo.ipv4DnsList.isEmpty() ? tr("Auto") : conInfo.strDynamicIpv4Dns; } } @@ -725,8 +731,14 @@ void NetDetail::initSecuData() initTlsInfo(m_info); } else if (m_info.enterpriseType == PEAP){ initPeapInfo(m_info); - } else { + } else if (m_info.enterpriseType == TTLS){ initTtlsInfo(m_info); + } else if (m_info.enterpriseType == LEAP){ + initLeapInfo(m_info); + } else if (m_info.enterpriseType == PWD){ + initPwdInfo(m_info); + } else if (m_info.enterpriseType == FAST){ + initFastInfo(m_info); } break; default: @@ -765,6 +777,21 @@ void NetDetail::initTtlsInfo(ConInfo &conInfo) m_resource->getEnterPriseInfoTtls(m_uuid, conInfo.ttlsInfo); } +void NetDetail::initLeapInfo(ConInfo &conInfo) +{ + m_resource->getEnterPriseInfoLeap(m_uuid, conInfo.leapInfo); +} + +void NetDetail::initPwdInfo(ConInfo &conInfo) +{ + m_resource->getEnterPriseInfoPwd(m_uuid, conInfo.pwdInfo); +} + +void NetDetail::initFastInfo(ConInfo &conInfo) +{ + m_resource->getEnterPriseInfoFast(m_uuid, conInfo.fastInfo); +} + //点击了保存更改网络设置的按钮 void NetDetail::on_btnConfirm_clicked() { @@ -880,6 +907,15 @@ void NetDetail::updateWirelessEnterPriseConnect(KyEapMethodType enterpriseType) } else if (enterpriseType == TTLS) { securityPage->updateTtlsChange(m_info.ttlsInfo); m_wirelessConnOpration->updateWirelessEnterPriseTtlsConnect(m_uuid, m_info.ttlsInfo); + } else if (enterpriseType == LEAP) { + securityPage->updateLeapChange(m_info.leapInfo); + m_wirelessConnOpration->updateWirelessEnterPriseLeapConnect(m_uuid, m_info.leapInfo); + } else if (enterpriseType == PWD) { + securityPage->updatePwdChange(m_info.pwdInfo); + m_wirelessConnOpration->updateWirelessEnterPrisePwdConnect(m_uuid, m_info.pwdInfo); + } else if (enterpriseType == FAST) { + securityPage->updateFastChange(m_info.fastInfo); + m_wirelessConnOpration->updateWirelessEnterPriseFastConnect(m_uuid, m_info.fastInfo); } } @@ -985,6 +1021,33 @@ bool NetDetail::createWirelessConnect() qDebug() << "addAndConnect TTLS connect"; m_wirelessConnOpration->addAndActiveWirelessEnterPriseTtlsConnect(m_info.ttlsInfo, connetSetting, m_deviceName, true); } + } else if (enterpriseType == LEAP) { + securityPage->updateLeapChange(m_info.leapInfo); + if (!m_name.isEmpty()) { + qDebug() << "add new LEAP connect"; + m_wirelessConnOpration->addLeapConnect(connetSetting, m_info.leapInfo); + } else { + qDebug() << "addAndConnect LEAP connect"; + m_wirelessConnOpration->addAndActiveWirelessEnterPriseLeapConnect(m_info.leapInfo, connetSetting, m_deviceName, true); + } + } else if (enterpriseType == PWD) { + securityPage->updatePwdChange(m_info.pwdInfo); + if (!m_name.isEmpty()) { + qDebug() << "add new PWD connect"; + m_wirelessConnOpration->addPwdConnect(connetSetting, m_info.pwdInfo); + } else { + qDebug() << "addAndConnect PWD connect"; + m_wirelessConnOpration->addAndActiveWirelessEnterPrisePwdConnect(m_info.pwdInfo, connetSetting, m_deviceName, true); + } + } else if (enterpriseType == FAST) { + securityPage->updateFastChange(m_info.fastInfo); + if (!m_name.isEmpty()) { + qDebug() << "add new FAST connect"; + m_wirelessConnOpration->addFastConnect(connetSetting, m_info.fastInfo); + } else { + qDebug() << "addAndConnect FAST connect"; + m_wirelessConnOpration->addAndActiveWirelessEnterPriseFastConnect(m_info.fastInfo, connetSetting, m_deviceName, true); + } } } else { securityPage->updateSecurityChange(connetSetting); @@ -1282,19 +1345,10 @@ void NetDetail::getIpv4Info(QString objPath, ConInfo &conInfo) while (!dbusArg2nd.atEnd()) { uint tempMap; dbusArg2nd >> tempMap; - addressVector.append(tempMap); + QString dns(inet_ntoa(*(struct in_addr *)&tempMap)); + conInfo.ipv4DnsList << QHostAddress(dns); } dbusArg2nd.endArray(); - if (addressVector.size() == 1) { - QString dns(inet_ntoa(*(struct in_addr *)&addressVector.at(0))); - conInfo.strIPV4FirDns = dns; - } else if (addressVector.size() > 1) { - QString dns1(inet_ntoa(*(struct in_addr *)&addressVector.at(0))); - QString dns2(inet_ntoa(*(struct in_addr *)&addressVector.at(1))); - conInfo.strIPV4FirDns = dns1; - conInfo.strIPV4SecDns = dns2; - } - } else if (inner_key == "gateway") { //gateway conInfo.strIPV4GateWay = innerMap.value(inner_key).toString(); diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index 386a539d..13391dfb 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -114,6 +114,9 @@ private: void initTlsInfo(ConInfo &conInfo); void initPeapInfo(ConInfo &conInfo); void initTtlsInfo(ConInfo &conInfo); + void initLeapInfo(ConInfo &conInfo); + void initPwdInfo(ConInfo &conInfo); + void initFastInfo(ConInfo &conInfo); void updateWirelessPersonalConnect(); void updateWirelessEnterPriseConnect(KyEapMethodType enterpriseType); diff --git a/src/frontend/netdetails/netdetails.pri b/src/frontend/netdetails/netdetails.pri index 75657d5d..f06fe245 100644 --- a/src/frontend/netdetails/netdetails.pri +++ b/src/frontend/netdetails/netdetails.pri @@ -10,6 +10,7 @@ HEADERS += \ $$PWD/ipv4page.h \ $$PWD/ipv6page.h \ $$PWD/joinhiddenwifipage.h \ + $$PWD/multiplednswidget.h \ $$PWD/netdetail.h \ $$PWD/securitypage.h @@ -22,5 +23,6 @@ SOURCES += \ $$PWD/ipv4page.cpp \ $$PWD/ipv6page.cpp \ $$PWD/joinhiddenwifipage.cpp \ + $$PWD/multiplednswidget.cpp \ $$PWD/netdetail.cpp \ $$PWD/securitypage.cpp diff --git a/src/frontend/netdetails/securitypage.cpp b/src/frontend/netdetails/securitypage.cpp index f4968ec2..82fabb95 100644 --- a/src/frontend/netdetails/securitypage.cpp +++ b/src/frontend/netdetails/securitypage.cpp @@ -84,6 +84,14 @@ void SecurityPage::initUI() userPwdEdit->setUseCustomPalette(true); userPwdFlagBox = new QCheckBox(this); + //FAST + m_pacCheckBox = new QCheckBox(this); + m_pacProvisionComboBox = new QComboBox(this); + m_pacFilePathComboBox = new QComboBox(this); + m_pacProvisionLabel = new FixLabel(this); + m_pacFlagLabel = new FixLabel(this); + m_pacFileLabel = new QLabel(this); + QWidget *queryWidget = new QWidget(this); QHBoxLayout *queryLayout = new QHBoxLayout(queryWidget); queryLayout->setContentsMargins(0, 0, 0, 0); @@ -106,22 +114,22 @@ void SecurityPage::initUI() rememberLayout->addWidget(m_checkLabel); rememberLayout->addStretch(); -// mSecuLayout = new QFormLayout(this); -// mSecuLayout->setContentsMargins(0, 0, 0, 0); -// mSecuLayout->addRow(secuTypeLabel, secuTypeCombox); -// mSecuLayout->addRow(pwdLabel, pwdEdit); -// mSecuLayout->addRow(eapTypeLabel, eapTypeCombox); -// mSecuLayout->addRow(identityLable, identityEdit); -// mSecuLayout->addRow(domainLable, domainEdit); -// mSecuLayout->addRow(caCertPathLabel, caCertPathCombox); -// mSecuLayout->addRow(caNeedBox, caNeedFlagLabel); -// mSecuLayout->addRow(clientCertPathLabel, clientCertPathCombox); -// mSecuLayout->addRow(clientPrivateKeyLabel, clientPrivateKeyCombox); -// mSecuLayout->addRow(clientPrivateKeyPwdLabel,clientPrivateKeyPwdEdit); -// mSecuLayout->addRow(eapMethodLabel, eapMethodCombox); -// mSecuLayout->addRow(userNameLabel, userNameEdit); -// mSecuLayout->addRow(userPwdLabel, userPwdEdit); -// mSecuLayout->addRow(userPwdFlagBox, userPwdFlagLabel); + // mSecuLayout = new QFormLayout(this); + // mSecuLayout->setContentsMargins(0, 0, 0, 0); + // mSecuLayout->addRow(secuTypeLabel, secuTypeCombox); + // mSecuLayout->addRow(pwdLabel, pwdEdit); + // mSecuLayout->addRow(eapTypeLabel, eapTypeCombox); + // mSecuLayout->addRow(identityLable, identityEdit); + // mSecuLayout->addRow(domainLable, domainEdit); + // mSecuLayout->addRow(caCertPathLabel, caCertPathCombox); + // mSecuLayout->addRow(caNeedBox, caNeedFlagLabel); + // mSecuLayout->addRow(clientCertPathLabel, clientCertPathCombox); + // mSecuLayout->addRow(clientPrivateKeyLabel, clientPrivateKeyCombox); + // mSecuLayout->addRow(clientPrivateKeyPwdLabel,clientPrivateKeyPwdEdit); + // mSecuLayout->addRow(eapMethodLabel, eapMethodCombox); + // mSecuLayout->addRow(userNameLabel, userNameEdit); + // mSecuLayout->addRow(userPwdLabel, userPwdEdit); + // mSecuLayout->addRow(userPwdFlagBox, userPwdFlagLabel); topLayout = new QGridLayout(); topLayout->setContentsMargins(0, 0, 0, 0); @@ -135,18 +143,27 @@ void SecurityPage::initUI() // EAP认证 Label和选项框 第2行,第0列,第1列 topLayout->addWidget(eapTypeLabel, 2, 0); topLayout->addWidget(eapTypeCombox, 2, 1); - //内部认证 Label和选项框 第3行,第0列,第1列 - topLayout->addWidget(eapMethodLabel, 3, 0); - topLayout->addWidget(eapMethodCombox, 3, 1); - //用户名 Label和输入框 第4行,第0列,第1列 - topLayout->addWidget(userNameLabel, 4, 0); - topLayout->addWidget(userNameEdit, 4, 1); - //密码 Label和密码框 第5行,第0列,第1列 - topLayout->addWidget(userPwdLabel, 5, 0); - topLayout->addWidget(userPwdEdit, 5, 1); - // 匿名身份 Label和输入框 第6行,第0列,第1列 - topLayout->addWidget(identityLable, 6, 0); - topLayout->addWidget(identityEdit, 6, 1); + // EAP认证 Label和选项框 第3行,第0列,第1列 + topLayout->addWidget(m_pacProvisionLabel, 3, 0); + topLayout->addWidget(m_pacProvisionComboBox, 3, 1); + // pac CheckBox和Label 第4行,第0列,第1列 + topLayout->addWidget(m_pacCheckBox, 4, 0); + topLayout->addWidget(m_pacFlagLabel, 4, 1); + // EAP认证 Label和选项框 第5行,第0列,第1列 + topLayout->addWidget(m_pacFileLabel, 5, 0); + topLayout->addWidget(m_pacFilePathComboBox, 5, 1); + //内部认证 Label和选项框 第6行,第0列,第1列 + topLayout->addWidget(eapMethodLabel, 6, 0); + topLayout->addWidget(eapMethodCombox, 6, 1); + //用户名 Label和输入框 第7行,第0列,第1列 + topLayout->addWidget(userNameLabel, 7, 0); + topLayout->addWidget(userNameEdit, 7, 1); + //密码 Label和密码框 第8行,第0列,第1列 + topLayout->addWidget(userPwdLabel, 8, 0); + topLayout->addWidget(userPwdEdit, 8, 1); + // 匿名身份 Label和输入框 第9行,第0列,第1列 + topLayout->addWidget(identityLable, 9, 0); + topLayout->addWidget(identityEdit, 9, 1); // CA证书选项框及CheckBox布局 @@ -186,7 +203,7 @@ void SecurityPage::initUI() if (isDetailPage) { checkWidget->hide(); - topLayout->addWidget(queryWidget, 7, 1); + topLayout->addWidget(queryWidget, 10, 1); changeColumnWidthWithSecuType(); } else { queryWidget->hide(); @@ -237,6 +254,9 @@ void SecurityPage::initUI() eapTypeCombox->addItem("TLS", TLS); eapTypeCombox->addItem("PEAP", PEAP); eapTypeCombox->addItem("TTLS", TTLS); + eapTypeCombox->addItem("LEAP", LEAP); + eapTypeCombox->addItem("PWD", PWD); + eapTypeCombox->addItem("FAST", FAST); eapTypeCombox->setCurrentIndex(TLS); //TLS caCertPathCombox->addItem(tr("None"), QString(tr("None"))); //无 @@ -248,6 +268,18 @@ void SecurityPage::initUI() clientPrivateKeyCombox->addItem(tr("None"), QString(tr("None"))); //无 clientPrivateKeyCombox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择... + //FAST + m_pacCheckBox->setChecked(true); + m_pacProvisionLabel->setText(tr("PAC provisioning")); //PAC配置 + m_pacFlagLabel->setText(tr("Allow automatic PAC provisioning")); //允许自动PAC配置 + m_pacFileLabel->setText(tr("PAC file")); //PAC文件 + m_pacProvisionComboBox->addItem(tr("Anonymous"), ANON); //匿名 + m_pacProvisionComboBox->addItem(tr("Authenticated"), AUTHEN); //已认证 + m_pacProvisionComboBox->addItem(tr("Both"), BOTH); //两者兼用 + m_pacProvisionComboBox->setCurrentIndex(ANON); + m_pacFilePathComboBox->addItem(tr("None"), QString(tr("None"))); //无 + m_pacFilePathComboBox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择... + //仅为该用户存储密码 pwdOptionCombox->addItem(tr("Store passwords only for this user"), QString(tr("Store password only for this user"))); //存储所有用户的密码 @@ -273,13 +305,13 @@ void SecurityPage::initUI() void SecurityPage::initConnect() { //安全类型变化 -// connect(secuTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onSecuTypeComboxIndexChanged); + // connect(secuTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onSecuTypeComboxIndexChanged); connect(secuTypeCombox, QOverload::of(&QComboBox::currentIndexChanged), this, &SecurityPage::onSecuTypeComboxIndexChanged); connect(secuTypeCombox, QOverload::of(&QComboBox::currentIndexChanged), this, &SecurityPage::changeColumnWidthWithSecuType); //EAP方式变化 -// connect(eapTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onEapTypeComboxIndexChanged); + // connect(eapTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onEapTypeComboxIndexChanged); connect(eapTypeCombox, QOverload::of(&QComboBox::currentIndexChanged), this, &SecurityPage::onEapTypeComboxIndexChanged); connect(caNeedBox, &QCheckBox::clicked, this, &SecurityPage::onCaNeedBoxClicked); @@ -308,7 +340,13 @@ void SecurityPage::initConnect() connect(eapMethodCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn())); connect(userNameEdit, &LineEdit::textChanged, this, &SecurityPage::setEnableOfSaveBtn); connect(userPwdEdit, &LineEdit::textChanged, this, &SecurityPage::setEnableOfSaveBtn); + connect(m_pacCheckBox, &QCheckBox::stateChanged, this, &SecurityPage::setEnableOfSaveBtn); + connect(m_pacProvisionComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(m_pacFilePathComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(m_pacCheckBox, &QCheckBox::clicked, this, &SecurityPage::onPacBoxClicked); + connect(m_pacFilePathComboBox, static_cast(&QComboBox::currentIndexChanged), + this, &SecurityPage::onPacFilePathComboxIndexChanged); } void SecurityPage::setSecurity(KySecuType index) @@ -419,6 +457,71 @@ void SecurityPage::setTtlsInfo(KyEapMethodTtlsInfo &info) } } +void SecurityPage::setLeapInfo(KyEapMethodLeapInfo &info) +{ + showLeapOrPwd(); + eapTypeCombox->setCurrentIndex(LEAP); + userNameEdit->setText(info.m_userName); + userPwdEdit->setText(info.m_userPwd); + if (info.m_passwdFlag) { + userPwdFlagBox->setChecked(true); + } else { + userPwdFlagBox->setChecked(false); + } +} + +void SecurityPage::setPwdInfo(KyEapMethodPwdInfo &info) +{ + showLeapOrPwd(); + eapTypeCombox->setCurrentIndex(PWD); + userNameEdit->setText(info.m_userName); + userPwdEdit->setText(info.m_userPwd); + if (info.m_passwdFlag) { + userPwdFlagBox->setChecked(true); + } else { + userPwdFlagBox->setChecked(false); + } +} + +void SecurityPage::setFastInfo(KyEapMethodFastInfo &info) +{ + showFast(); + eapTypeCombox->setCurrentIndex(FAST); + onEapTypeComboxIndexChanged(); + + identityEdit->setText(info.m_anonIdentity); + if (info.m_pacProvisioning == KyFastProvisioningAllowUnauthenticated) { + m_pacProvisionComboBox->setCurrentIndex(ANON); + } else if (info.m_pacProvisioning == KyFastProvisioningAllowAuthenticated) { + m_pacProvisionComboBox->setCurrentIndex(AUTHEN); + } else if (info.m_pacProvisioning == KyFastProvisioningAllowBoth) { + m_pacProvisionComboBox->setCurrentIndex(BOTH); + } + + if (info.m_pacFilePath.isEmpty()) { + m_pacFilePathComboBox->setItemText(0, QString(tr("None"))); + m_pacCheckBox->setChecked(true); + m_pacFilePathComboBox->setEnabled(false); + } else { + m_pacFilePathComboBox->setItemText(0, info.m_pacFilePath); + m_pacCheckBox->setChecked(false); + m_pacFilePathComboBox->setEnabled(true); + } + + if (info.m_authMethod == KyAuthMethodGtc) { + eapMethodCombox->setCurrentIndex(GTC_FAST); + } else if (info.m_authMethod == KyAuthMethodMschapv2) { + eapMethodCombox->setCurrentIndex(MSCHAPV2_FAST); + } + userNameEdit->setText(info.m_userName); + userPwdEdit->setText(info.m_userPwd); + if (info.m_passwdFlag) { + userPwdFlagBox->setChecked(true); + } else { + userPwdFlagBox->setChecked(false); + } +} + void SecurityPage::setSecurityVisible(const bool &visible) { if (secuTypeLabel) { @@ -461,6 +564,33 @@ void SecurityPage::updateTtlsChange(KyEapMethodTtlsInfo &info) info = ttlsInfo; } +void SecurityPage::updateLeapChange(KyEapMethodLeapInfo &info) +{ + KyEapMethodLeapInfo leapInfo = assembleLeapInfo(); + if (leapInfo.m_userPwd != info.m_userPwd) { + leapInfo.bChanged = true; + } + info = leapInfo; +} + +void SecurityPage::updatePwdChange(KyEapMethodPwdInfo &info) +{ + KyEapMethodPwdInfo pwdInfo = assemblePwdInfo(); + if (pwdInfo.m_userPwd != info.m_userPwd) { + pwdInfo.bChanged = true; + } + info = pwdInfo; +} + +void SecurityPage::updateFastChange(KyEapMethodFastInfo &info) +{ + KyEapMethodFastInfo pwdInfo = assembleFastInfo(); + if (pwdInfo.m_userPwd != info.m_userPwd) { + pwdInfo.bChanged = true; + } + info = pwdInfo; +} + void SecurityPage::getSecuType(KySecuType &secuType, KyEapMethodType &enterpriseType) { secuType = (KySecuType)secuTypeCombox->currentData().toInt(); @@ -481,7 +611,7 @@ bool SecurityPage::checkIsChanged(const ConInfo info) if (info.secType == NONE) { return false; } else if (info.secType == WPA_AND_WPA2_PERSONAL || info.secType == WPA3_PERSONAL) { - return !(info.strPassword == pwdEdit->text()); + return !(info.strPassword == pwdEdit->text()); } else { if (info.enterpriseType != eapTypeCombox->currentData().toInt()) { return true; @@ -492,6 +622,12 @@ bool SecurityPage::checkIsChanged(const ConInfo info) return !(info.peapInfo == assemblePeapInfo()); } else if (info.enterpriseType == TTLS) { return !(info.ttlsInfo == assembleTtlsInfo()); + } else if (info.enterpriseType == LEAP) { + return !(info.leapInfo == assembleLeapInfo()); + } else if (info.enterpriseType == PWD) { + return !(info.pwdInfo == assemblePwdInfo()); + } else if (info.enterpriseType == FAST) { + return !(info.fastInfo == assembleFastInfo()); } } } @@ -521,6 +657,14 @@ void SecurityPage::showNone() userNameEdit->hide(); userPwdEdit->hide(); userPwdFlagLabel->hide(); + + //FAST + m_pacCheckBox->hide(); + m_pacProvisionComboBox->hide(); + m_pacFilePathComboBox->hide(); + m_pacProvisionLabel->hide(); + m_pacFlagLabel->hide(); + m_pacFileLabel->hide(); } void SecurityPage::showPsk() @@ -546,6 +690,14 @@ void SecurityPage::showPsk() userNameEdit->hide(); userPwdEdit->hide(); userPwdFlagLabel->hide(); + + //FAST + m_pacCheckBox->hide(); + m_pacProvisionComboBox->hide(); + m_pacFilePathComboBox->hide(); + m_pacProvisionLabel->hide(); + m_pacFlagLabel->hide(); + m_pacFileLabel->hide(); } void SecurityPage::showTls() @@ -570,6 +722,14 @@ void SecurityPage::showTls() userNameEdit->hide(); userPwdEdit->hide(); userPwdFlagLabel->hide(); + + //FAST + m_pacCheckBox->hide(); + m_pacProvisionComboBox->hide(); + m_pacFilePathComboBox->hide(); + m_pacProvisionLabel->hide(); + m_pacFlagLabel->hide(); + m_pacFileLabel->hide(); } void SecurityPage::showPeapOrTtls() @@ -586,6 +746,14 @@ void SecurityPage::showPeapOrTtls() identityEdit->hide(); tlsWidget->hide(); + //FAST + m_pacCheckBox->hide(); + m_pacProvisionComboBox->hide(); + m_pacFilePathComboBox->hide(); + m_pacProvisionLabel->hide(); + m_pacFlagLabel->hide(); + m_pacFileLabel->hide(); + //PEAP TTLS共有 eapMethodLabel->show(); userNameLabel->show(); @@ -598,6 +766,96 @@ void SecurityPage::showPeapOrTtls() userPwdFlagLabel->show(); } +void SecurityPage::showLeapOrPwd() +{ + pwdEdit->hide(); + eapTypeCombox->show(); + + identityEdit->hide(); + domainEdit->hide(); + caCertPathCombox->hide(); + caNeedBox->hide(); + clientCertPathCombox->hide(); + clientPrivateKeyCombox->hide(); + clientPrivateKeyPwdEdit->hide(); + + eapMethodCombox->hide(); + userNameEdit->show(); + userPwdEdit->show(); + userPwdFlagBox->show(); + + pwdLabel->hide(); + //企业wifi共有 + eapTypeLabel->show(); + //TLS + identityLable->hide(); + domainLable->hide(); + caCertPathLabel->hide(); + caNeedFlagLabel->hide(); + clientCertPathLabel->hide(); + clientPrivateKeyLabel->hide(); + clientPrivateKeyPwdLabel->hide(); + + //PEAP TTLS共有 + eapMethodLabel->hide(); + userNameLabel->show(); + userPwdLabel->show(); + userPwdFlagLabel->show(); + + //FAST + m_pacCheckBox->hide(); + m_pacProvisionComboBox->hide(); + m_pacFilePathComboBox->hide(); + m_pacProvisionLabel->hide(); + m_pacFlagLabel->hide(); + m_pacFileLabel->hide(); +} + +void SecurityPage::showFast() +{ + pwdEdit->hide(); + eapTypeCombox->show(); + + identityEdit->show(); + domainEdit->hide(); + caCertPathCombox->hide(); + caNeedBox->hide(); + clientCertPathCombox->hide(); + clientPrivateKeyCombox->hide(); + clientPrivateKeyPwdEdit->hide(); + + eapMethodCombox->show(); + userNameEdit->show(); + userPwdEdit->show(); + userPwdFlagBox->hide(); + + pwdLabel->hide(); + //企业wifi共有 + eapTypeLabel->show(); + //TLS + identityLable->show(); + domainLable->hide(); + caCertPathLabel->hide(); + caNeedFlagLabel->hide(); + clientCertPathLabel->hide(); + clientPrivateKeyLabel->hide(); + clientPrivateKeyPwdLabel->hide(); + + //PEAP TTLS共有 + eapMethodLabel->show(); + userNameLabel->show(); + userPwdLabel->show(); + userPwdFlagLabel->hide(); + + //FAST + m_pacCheckBox->show(); + m_pacProvisionComboBox->show(); + m_pacFilePathComboBox->show(); + m_pacProvisionLabel->show(); + m_pacFlagLabel->show(); + m_pacFileLabel->show(); +} + KyEapMethodTlsInfo SecurityPage::assembleTlsInfo() { KyEapMethodTlsInfo info; @@ -627,7 +885,7 @@ KyEapMethodTlsInfo SecurityPage::assembleTlsInfo() KyEapMethodPeapInfo SecurityPage::assemblePeapInfo() { KyEapMethodPeapInfo info; -// info.phase2AuthMethod = (KyNoEapMethodAuth)eapMethodCombox->currentData().toInt(); + // info.phase2AuthMethod = (KyNoEapMethodAuth)eapMethodCombox->currentData().toInt(); switch (eapMethodCombox->currentIndex()) { case 0: info.phase2AuthMethod = KyAuthMethodMschapv2; @@ -688,6 +946,60 @@ KyEapMethodTtlsInfo SecurityPage::assembleTtlsInfo() return info; } +KyEapMethodLeapInfo SecurityPage::assembleLeapInfo() +{ + KyEapMethodLeapInfo info; + info.m_userName = userNameEdit->text(); + info.m_userPwd = userPwdEdit->text(); + info.m_passwdFlag = (userPwdFlagBox->isChecked() ? NetworkManager::Setting::NotSaved : NetworkManager::Setting::None); + return info; +} + +KyEapMethodPwdInfo SecurityPage::assemblePwdInfo() +{ + KyEapMethodPwdInfo info; + info.m_userName = userNameEdit->text(); + info.m_userPwd = userPwdEdit->text(); + info.m_passwdFlag = (userPwdFlagBox->isChecked() ? NetworkManager::Setting::NotSaved : NetworkManager::Setting::None); + return info; +} + +KyEapMethodFastInfo SecurityPage::assembleFastInfo() +{ + KyEapMethodFastInfo info; + info.m_anonIdentity = identityEdit->text(); + switch (m_pacProvisionComboBox->currentIndex()) { + case ANON: + info.m_pacProvisioning = KyFastProvisioningAllowUnauthenticated; + break; + case AUTHEN: + info.m_pacProvisioning = KyFastProvisioningAllowAuthenticated; + break; + case BOTH: + info.m_pacProvisioning = KyFastProvisioningAllowBoth; + break; + default: + break; + } + info.m_allowAutoPacFlag = m_pacCheckBox->isChecked(); + info.m_pacFilePath = m_pacFilePathComboBox->currentText(); + + switch (eapMethodCombox->currentIndex()) { + case GTC_FAST: + info.m_authMethod = KyAuthMethodGtc; + break; + case MSCHAPV2_FAST: + info.m_authMethod = KyAuthMethodMschapv2; + break; + default: + break; + } + info.m_userName = userNameEdit->text(); + info.m_userPwd = userPwdEdit->text(); + info.m_passwdFlag = (userPwdFlagBox->isChecked() ? NetworkManager::Setting::NotSaved : NetworkManager::Setting::None); + return info; +} + void SecurityPage::updateSecurityChange(KyWirelessConnectSetting &setting) { qDebug() << "secuTypeCombox->currentData()" << secuTypeCombox->currentData().toInt() << pwdEdit->text(); @@ -746,7 +1058,20 @@ bool SecurityPage::checkConnectBtnIsEnabled() qDebug() << "client Private Key password is empty"; return false; } - } else if (type == PEAP || type == TTLS) { + } else if (type == PEAP || type == TTLS || type == LEAP || type == PWD) { + if(userNameEdit->text().isEmpty() || userPwdEdit->text().isEmpty()) { + qDebug() << "user name or user password is empty"; + return false; + } + } else if (type == FAST) { + if (identityEdit->text().isEmpty()) { + qDebug() << "fast anonymous identity is empty"; + return false; + } + if(!m_pacCheckBox->isChecked()) { + qDebug() << "Not allow automatic PAC provisioning "; + return false; + } if(userNameEdit->text().isEmpty() || userPwdEdit->text().isEmpty()) { qDebug() << "user name or user password is empty"; return false; @@ -805,6 +1130,18 @@ void SecurityPage::onEapTypeComboxIndexChanged() eapMethodCombox->addItem("md5(eap)", MD5_EAP); eapMethodCombox->addItem("gtc(eap)", GTC_EAP); Q_EMIT this->eapTypeChanged(TTLS); + } else if (index == LEAP) { + showLeapOrPwd(); + Q_EMIT this->eapTypeChanged(LEAP); + } else if (index == PWD) { + showLeapOrPwd(); + Q_EMIT this->eapTypeChanged(PWD); + } else if (index == FAST) { + showFast(); + eapMethodCombox->clear(); + eapMethodCombox->addItem("GTC", GTC_FAST); + eapMethodCombox->addItem("MSCHAPv2", MSCHAPV2_FAST); + Q_EMIT this->eapTypeChanged(FAST); } } @@ -818,6 +1155,16 @@ void SecurityPage::onCaNeedBoxClicked() } } +void SecurityPage::onPacBoxClicked() +{ + if (!m_pacCheckBox->isChecked()) { + m_pacProvisionComboBox->setCurrentIndex(ANON); + m_pacProvisionComboBox->setEnabled(false); + } else { + m_pacProvisionComboBox->setEnabled(true); + } +} + void SecurityPage::onCaCertPathComboxIndexChanged(QString str) { if (str.contains("Choose from file...") || str.contains("从文件选择...")) @@ -886,6 +1233,29 @@ void SecurityPage::onClientPrivateKeyComboxIndexChanged(QString str) } } +void SecurityPage::onPacFilePathComboxIndexChanged(QString str) +{ + if (str.contains("Choose from file...") || str.contains("从文件选择...")) + { + QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a PAC file"), "recent:///", + tr("PAC Files (*.pac)")); + if (!fileName.isNull()) { + QStringList nameList = fileName.split("/"); + m_pacFilePathComboBox->blockSignals(true); + m_pacFilePathComboBox->setItemText(0, fileName); + m_pacFilePathComboBox->setCurrentIndex(0); + m_pacFilePathComboBox->blockSignals(false); + } else { + m_pacFilePathComboBox->blockSignals(true); + m_pacFilePathComboBox->setItemText(0, tr("None")); + m_pacFilePathComboBox->setCurrentIndex(0); + m_pacFilePathComboBox->blockSignals(false); + } + } else { + qWarning() << "Choose file is null or unvalible"; + } +} + void SecurityPage::onPwdOptionComboxIndexChanged(QString str) { KyEapMethodTlsInfo info; diff --git a/src/frontend/netdetails/securitypage.h b/src/frontend/netdetails/securitypage.h index 0bc2b84e..82c4b407 100644 --- a/src/frontend/netdetails/securitypage.h +++ b/src/frontend/netdetails/securitypage.h @@ -31,6 +31,7 @@ #include "kylable.h" #include "kwidget.h" #include "kpasswordedit.h" +#include "detailwidget.h" using namespace kdk; @@ -45,6 +46,9 @@ public: void setTlsInfo(KyEapMethodTlsInfo &info); void setPeapInfo(KyEapMethodPeapInfo &info); void setTtlsInfo(KyEapMethodTtlsInfo &info); + void setLeapInfo(KyEapMethodLeapInfo &info); + void setPwdInfo(KyEapMethodPwdInfo &info); + void setFastInfo(KyEapMethodFastInfo &info); void setSecurityVisible(const bool &visible); bool checkIsChanged(const ConInfo info); @@ -52,6 +56,9 @@ public: void updateTlsChange(KyEapMethodTlsInfo &info); void updatePeapChange(KyEapMethodPeapInfo &info); void updateTtlsChange(KyEapMethodTtlsInfo &info); + void updateLeapChange(KyEapMethodLeapInfo &info); + void updatePwdChange(KyEapMethodPwdInfo &info); + void updateFastChange(KyEapMethodFastInfo &info); void getSecuType(KySecuType &secuType, KyEapMethodType &enterpriseType); bool getAutoConnectState(); @@ -103,6 +110,15 @@ private: KPasswordEdit *userPwdEdit = nullptr; QCheckBox *userPwdFlagBox; + //FAST + QCheckBox *m_pacCheckBox; + QComboBox *m_pacProvisionComboBox; + QComboBox *m_pacFilePathComboBox; + FixLabel *m_pacProvisionLabel; + FixLabel *m_pacFlagLabel; + QLabel *m_pacFileLabel; + QWidget *m_pacCheckWidget; + QLabel *m_emptyLabel = nullptr; QLabel *m_checkLabel = nullptr; QCheckBox *m_rememberCheckBox = nullptr; @@ -115,12 +131,17 @@ private: void showPsk(); void showTls(); void showPeapOrTtls(); + void showLeapOrPwd(); + void showFast(); void initUI(); void initConnect(); KyEapMethodTlsInfo assembleTlsInfo(); KyEapMethodPeapInfo assemblePeapInfo(); KyEapMethodTtlsInfo assembleTtlsInfo(); + KyEapMethodLeapInfo assembleLeapInfo(); + KyEapMethodPwdInfo assemblePwdInfo(); + KyEapMethodFastInfo assembleFastInfo(); bool checkConnectBtnIsEnabled(); @@ -131,12 +152,14 @@ private Q_SLOTS: void setEnableOfSaveBtn(); void onCaNeedBoxClicked(); + void onPacBoxClicked(); void onCaCertPathComboxIndexChanged(QString str); void onClientCertPathComboxIndexChanged(QString str); void onClientPrivateKeyComboxIndexChanged(QString str); void onPwdOptionComboxIndexChanged(QString str); void changeColumnWidthWithSecuType(); + void onPacFilePathComboxIndexChanged(QString str); Q_SIGNALS: void setSecuPageState(bool); diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index b8d0c94a..8d6a1a68 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -1161,6 +1161,15 @@ void LanPage::setWiredDeviceEnable(const QString& devName, bool enable) m_deviceResource->setDeviceManaged(devName, enable); } +void LanPage::deleteWired(const QString &connUuid) +{ + qDebug() << "[LanPage] deleteWired" << connUuid; + if (connUuid == nullptr) { + return; + } + m_wiredConnectOperation->deleteWiredConnect(connUuid); +} + bool LanPage::eventFilter(QObject *watched, QEvent *event) { if (watched == m_settingsLabel) { diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index d8ed6eba..0bae5fb5 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -44,6 +44,7 @@ public: //for dbus void getWiredList(QMap > &map); + void deleteWired(const QString& connUuid); void activateWired(const QString& devName, const QString& connUuid); void deactivateWired(const QString& devName, const QString& connUuid); void showDetailPage(QString devName, QString uuid); diff --git a/src/frontend/tools/infobutton.cpp b/src/frontend/tools/infobutton.cpp index 62ff0d01..8e462343 100644 --- a/src/frontend/tools/infobutton.cpp +++ b/src/frontend/tools/infobutton.cpp @@ -20,6 +20,7 @@ #include "infobutton.h" #include #include +#include #include #define BUTTON_SIZE 36,36 diff --git a/src/frontend/tools/radioitembutton.cpp b/src/frontend/tools/radioitembutton.cpp index 981e7569..6cb4b2fa 100644 --- a/src/frontend/tools/radioitembutton.cpp +++ b/src/frontend/tools/radioitembutton.cpp @@ -19,6 +19,7 @@ */ #include "radioitembutton.h" #include +#include #include #include #include diff --git a/src/frontend/tools/tools.pri b/src/frontend/tools/tools.pri index 7863428b..9c261260 100644 --- a/src/frontend/tools/tools.pri +++ b/src/frontend/tools/tools.pri @@ -3,6 +3,7 @@ INCLUDEPATH += $$PWD HEADERS += \ $$PWD/divider.h \ $$PWD/infobutton.h \ + $$PWD/listitemedit.h \ $$PWD/loadingdiv.h \ $$PWD/radioitembutton.h \ $$PWD/switchbutton.h \ @@ -12,6 +13,7 @@ HEADERS += \ SOURCES += \ $$PWD/divider.cpp \ $$PWD/infobutton.cpp \ + $$PWD/listitemedit.cpp \ $$PWD/loadingdiv.cpp \ $$PWD/radioitembutton.cpp \ $$PWD/switchbutton.cpp \ diff --git a/src/frontend/wificonfigdialog.cpp b/src/frontend/wificonfigdialog.cpp index 3207eca7..f91a524b 100644 --- a/src/frontend/wificonfigdialog.cpp +++ b/src/frontend/wificonfigdialog.cpp @@ -27,6 +27,7 @@ #include #include +#include WiFiConfigDialog::WiFiConfigDialog(QWidget *parent) : QDialog(parent), From b500b1679b2747a80e98a7f3519cdaa35cda2039 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Fri, 7 Apr 2023 16:34:09 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=BB=91=E5=8A=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/list-items/listitem.cpp | 13 ++++++++++--- src/frontend/list-items/listitem.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/frontend/list-items/listitem.cpp b/src/frontend/list-items/listitem.cpp index cd42a724..40edfeec 100644 --- a/src/frontend/list-items/listitem.cpp +++ b/src/frontend/list-items/listitem.cpp @@ -179,14 +179,21 @@ void ListItem::showDesktopNotify(const QString &message, QString soundName) void ListItem::mousePressEvent(QMouseEvent *event) { qDebug()<<"[ListItem]"<<"mousePressEvent"; - if (event->button() == Qt::LeftButton) { - onNetButtonClicked(); - } else if (event->button() == Qt::RightButton) { + if (event->button() == Qt::RightButton) { onRightButtonClicked(); } return QFrame::mousePressEvent(event); } +void ListItem::mouseReleaseEvent(QMouseEvent *event) +{ + qDebug()<<"[ListItem]"<<"mouseReleaseEvent"; + if (event->button() == Qt::LeftButton) { + onNetButtonClicked(); + } + return QFrame::mouseReleaseEvent(event); +} + void ListItem::enterEvent(QEvent *event) { // QPalette pal = qApp->palette(); diff --git a/src/frontend/list-items/listitem.h b/src/frontend/list-items/listitem.h index 7789e3b3..598ad1c9 100644 --- a/src/frontend/list-items/listitem.h +++ b/src/frontend/list-items/listitem.h @@ -98,6 +98,7 @@ public: protected: void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); void enterEvent(QEvent *event); void leaveEvent(QEvent *event); void paintEvent(QPaintEvent *event); From d95f6e9a5d4e5bccfd9ec6516136b6b61cb931cf Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Fri, 7 Apr 2023 16:58:35 +0800 Subject: [PATCH 05/10] update translate --- plugins/netconnect/translations/bo.ts | 47 +- plugins/netconnect/translations/bo_CN.ts | 47 +- plugins/netconnect/translations/en_US.ts | 47 +- plugins/netconnect/translations/tr.ts | 47 +- plugins/netconnect/translations/zh_CN.qm | Bin 711 -> 853 bytes plugins/netconnect/translations/zh_CN.ts | 47 +- plugins/wlanconnect/translations/bo.ts | 22 +- plugins/wlanconnect/translations/bo_CN.ts | 22 +- plugins/wlanconnect/translations/en_US.ts | 22 +- plugins/wlanconnect/translations/tr.ts | 22 +- plugins/wlanconnect/translations/zh_CN.ts | 22 +- src/frontend/netdetails/detailpage.cpp | 2 +- translations/kylin-nm_bo.qm | 1 - translations/kylin-nm_bo.ts | 576 +++++++++++---------- translations/kylin-nm_bo_CN.qm | Bin 17062 -> 0 bytes translations/kylin-nm_bo_CN.ts | 505 ++++++++++--------- translations/kylin-nm_tr.qm | Bin 2010 -> 0 bytes translations/kylin-nm_tr.ts | 580 ++++++++++++---------- translations/kylin-nm_zh_CN.qm | Bin 11167 -> 0 bytes translations/kylin-nm_zh_CN.ts | 507 ++++++++++--------- 20 files changed, 1392 insertions(+), 1124 deletions(-) delete mode 100644 translations/kylin-nm_bo.qm delete mode 100644 translations/kylin-nm_bo_CN.qm delete mode 100644 translations/kylin-nm_tr.qm delete mode 100644 translations/kylin-nm_zh_CN.qm diff --git a/plugins/netconnect/translations/bo.ts b/plugins/netconnect/translations/bo.ts index dce9ee13..9841010e 100644 --- a/plugins/netconnect/translations/bo.ts +++ b/plugins/netconnect/translations/bo.ts @@ -14,6 +14,26 @@
+ + LanItem + + + Delete + + + + + + Disconnect + + + + + + Connect + + + NetConnect @@ -23,47 +43,54 @@ - + open /netconnect/open - + Advanced settings /netconnect/Advanced settings" - + ukui control center - + ukui control center desktop message - - + + LAN - + No ethernet device avaliable - - + + connected - + + + + not connected + + + + card diff --git a/plugins/netconnect/translations/bo_CN.ts b/plugins/netconnect/translations/bo_CN.ts index e31cef7e..895a44e9 100644 --- a/plugins/netconnect/translations/bo_CN.ts +++ b/plugins/netconnect/translations/bo_CN.ts @@ -14,6 +14,26 @@ སྐུད་ཡོད་བརྙན་འཕྲིན་ཁ་སྣོན་བྱས་ཡོད། + + LanItem + + + Delete + སུབ་དགོས། + + + + + Disconnect + བར་མཚམས་ཆད་པ་རེད། + + + + + Connect + འབྲེལ་མཐུད་བཅས་བྱ་དགོས། + + NetConnect @@ -23,25 +43,25 @@ - + open སྒོ་ཕྱེ་བ། /netconnect/open - + Advanced settings སྔོན་ཐོན་གྱི་སྒྲིག་བཀོད། /netconnect/Advanced settings" - + ukui control center ཝུའུ་ཁི་ལན་གྱི་ཚོད་འཛིན་ལྟེ་གནས། - + ukui control center desktop message ukui ཚོད་འཛིན་ལྟེ་གནས་ཀྱི་ཅོག་ངོས་ཆ་འཕྲིན། @@ -50,24 +70,31 @@ སྐུད་ཡོད་སྦྲེལ་མཐུད། - - + + LAN སྐུད་ཡོད་དྲ་བ། - + No ethernet device avaliable ཨེ་ཙི་དྲ་རྒྱའི་སྒྲིག་ཆས་ལ་བཙན་འཛུལ་བྱས་མི་ཆོག། - - + + connected འབྲེལ་མཐུད་བྱེད་པ། - + + + + not connected + འབྲེལ་མཐུད་མ་བྱས་པ། + + + card བྱང་བུ། diff --git a/plugins/netconnect/translations/en_US.ts b/plugins/netconnect/translations/en_US.ts index 43e8a786..67be9443 100644 --- a/plugins/netconnect/translations/en_US.ts +++ b/plugins/netconnect/translations/en_US.ts @@ -14,6 +14,26 @@ Add WiredNetork + + LanItem + + + Delete + + + + + + Disconnect + + + + + + Connect + + + NetConnect @@ -23,47 +43,54 @@ - + open open /netconnect/open - + Advanced settings Advanced settings /netconnect/Advanced settings" - + ukui control center ukui control center - + ukui control center desktop message ukui control center desktop message - - + + LAN LAN - + No ethernet device avaliable No ethernet device avaliable - - + + connected connected - + + + + not connected + + + + card card diff --git a/plugins/netconnect/translations/tr.ts b/plugins/netconnect/translations/tr.ts index dce9ee13..9841010e 100644 --- a/plugins/netconnect/translations/tr.ts +++ b/plugins/netconnect/translations/tr.ts @@ -14,6 +14,26 @@ + + LanItem + + + Delete + + + + + + Disconnect + + + + + + Connect + + + NetConnect @@ -23,47 +43,54 @@ - + open /netconnect/open - + Advanced settings /netconnect/Advanced settings" - + ukui control center - + ukui control center desktop message - - + + LAN - + No ethernet device avaliable - - + + connected - + + + + not connected + + + + card diff --git a/plugins/netconnect/translations/zh_CN.qm b/plugins/netconnect/translations/zh_CN.qm index f8fe4d7bbb6520cb61929cde1055dc42171c755b..6ac7d043b45399960ad587c4633131ae89b78564 100644 GIT binary patch delta 298 zcmX@kdX;U0NPPhVLqHq@1H%gjwizu942%;Q*wgkgFfd6l=^g;_pD|e$ivszTENgU@ z0@Wq3dLOs~6yL#-X8#$;-@sX_&I;rUaV7pX0rK0pQoWx5X-lrd1*?JLu{>`iF9G%2 z^9%i)4HRd{1aeL@0~tKIzk?P`tTw4<>A#n}lmjHk2E^>n`FVM%$tCO{wohW7XGv-< zBS<|P-i<5Df$1&?h-SX~z^%J+>oP3xuRFo}U R3&kP4dHE#@lYcXw0RTN^NS6Qr delta 138 zcmcc0cARyBNL&O1LqHq@14AJL+l&?l21Z{7_OyLKdJ&Ulu_yxr6Emy#fh$0M2}hd! zXP`Pu&Qf(&AU&JwaKUOI{fy_0j4skB-H=_ diff --git a/plugins/netconnect/translations/zh_CN.ts b/plugins/netconnect/translations/zh_CN.ts index 04e23907..da195eef 100644 --- a/plugins/netconnect/translations/zh_CN.ts +++ b/plugins/netconnect/translations/zh_CN.ts @@ -14,6 +14,26 @@ 添加有线网络 + + LanItem + + + Delete + 删除 + + + + + Disconnect + 断开 + + + + + Connect + 连接 + + NetConnect @@ -23,25 +43,25 @@ - + open 开启 /netconnect/open - + Advanced settings 高级设置 /netconnect/Advanced settings" - + ukui control center 控制面板 - + ukui control center desktop message 控制面板桌面通知 @@ -50,24 +70,31 @@ 有线网络 - - + + LAN 有线网络 - + No ethernet device avaliable 未检测到有线设备 - - + + connected 已连接 - + + + + not connected + 未连接 + + + card 网卡 diff --git a/plugins/wlanconnect/translations/bo.ts b/plugins/wlanconnect/translations/bo.ts index c678f22f..824aac8c 100644 --- a/plugins/wlanconnect/translations/bo.ts +++ b/plugins/wlanconnect/translations/bo.ts @@ -23,49 +23,49 @@ - - + + WLAN - + open /wlanconnect/open - + Advanced settings /wlanconnect/Advanced settings" - + ukui control center - + ukui control center desktop message - + No wireless network card detected - - - + + + connected - + card diff --git a/plugins/wlanconnect/translations/bo_CN.ts b/plugins/wlanconnect/translations/bo_CN.ts index 47de7db1..7be28fd3 100644 --- a/plugins/wlanconnect/translations/bo_CN.ts +++ b/plugins/wlanconnect/translations/bo_CN.ts @@ -23,49 +23,49 @@ - - + + WLAN སྐུད་མེད་ཅུས་ཁོངས་ཀྱི་དྲ་བ། - + open སྒོ་ཕྱེ་བ། /wlanconnect/open - + Advanced settings སྔོན་ཐོན་གྱི་སྒྲིག་བཀོད། /wlanconnect/Advanced settings" - + ukui control center ཝུའུ་ཁི་ལན་གྱི་ཚོད་འཛིན་ལྟེ་གནས། - + ukui control center desktop message ངོས་ལེབ་ངོས་ཀྱི་བརྡ་ཐོ་ཚོད་འཛིན་བྱ་དགོས། - + No wireless network card detected སྐུད་མེད་དྲ་རྒྱའི་བྱང་བུ་མ་རྙེད་པ། - - - + + + connected འབྲེལ་མཐུད་བྱེད་པ། - + card བྱང་བུ། diff --git a/plugins/wlanconnect/translations/en_US.ts b/plugins/wlanconnect/translations/en_US.ts index 801e684f..01b3915e 100644 --- a/plugins/wlanconnect/translations/en_US.ts +++ b/plugins/wlanconnect/translations/en_US.ts @@ -23,49 +23,49 @@ - - + + WLAN WLAN - + open open /wlanconnect/open - + Advanced settings Advanced settings /wlanconnect/Advanced settings" - + ukui control center ukui control center - + ukui control center desktop message ukui control center desktop message - + No wireless network card detected No wireless network card detected - - - + + + connected connected - + card card diff --git a/plugins/wlanconnect/translations/tr.ts b/plugins/wlanconnect/translations/tr.ts index c678f22f..824aac8c 100644 --- a/plugins/wlanconnect/translations/tr.ts +++ b/plugins/wlanconnect/translations/tr.ts @@ -23,49 +23,49 @@ - - + + WLAN - + open /wlanconnect/open - + Advanced settings /wlanconnect/Advanced settings" - + ukui control center - + ukui control center desktop message - + No wireless network card detected - - - + + + connected - + card diff --git a/plugins/wlanconnect/translations/zh_CN.ts b/plugins/wlanconnect/translations/zh_CN.ts index 216d188b..52d7a5cc 100644 --- a/plugins/wlanconnect/translations/zh_CN.ts +++ b/plugins/wlanconnect/translations/zh_CN.ts @@ -23,49 +23,49 @@ - - + + WLAN 无线局域网 - + open 开启 /wlanconnect/open - + Advanced settings 高级设置 /wlanconnect/Advanced settings" - + ukui control center 控制面板 - + ukui control center desktop message 控制面板桌面通知 - + No wireless network card detected 未检测到无线网卡 - - - + + + connected 已连接 - + card 网卡 diff --git a/src/frontend/netdetails/detailpage.cpp b/src/frontend/netdetails/detailpage.cpp index 48b36a3e..21517fb0 100644 --- a/src/frontend/netdetails/detailpage.cpp +++ b/src/frontend/netdetails/detailpage.cpp @@ -250,7 +250,7 @@ void DetailPage::initUI() { m_IPV4Dns->setFixedWidth(MAX_LABEL_WIDTH); m_IPV4Dns->setAlignment(Qt::AlignRight | Qt::AlignVCenter); m_ipv4DnsWidget = new DetailWidget(qobject_cast(m_IPV4Dns), m_listWidget); - m_ipv4DnsWidget->setKey(tr("IPv4 Dns:")); + m_ipv4DnsWidget->setKey(tr("IPv4 DNS:")); m_IPV6 = new FixLabel(this); m_IPV6->setFixedWidth(MAX_LABEL_WIDTH); diff --git a/translations/kylin-nm_bo.qm b/translations/kylin-nm_bo.qm deleted file mode 100644 index be651eed..00000000 --- a/translations/kylin-nm_bo.qm +++ /dev/null @@ -1 +0,0 @@ - ConfigPage - + Network profile type - + Public(recommended) Devices on the network cannot discover this computer. Generally, it is suitable for networks in public places, such as airports or coffee shops, etc. - - Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. + + Private Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. - + Config firewall and security settings @@ -27,47 +27,53 @@ CreatNetPage - + Connection Name - - Ipv4Config + + IPv4Config - + Address - + Netmask - + Default Gateway - - Prefs DNS + + Invalid address - - Alternative DNS + + Invalid subnet mask - + + + Required + + + + Auto(DHCP) - + Manual @@ -75,82 +81,82 @@ DetailPage - + Auto Connection - - + + SSID: - + Copied successfully! - + Copy all - + Please input SSID: - - + + Protocol: - - + + Security Type: - - + + Hz: - - + + Chan: - - + + BandWidth: - - - IPV6: - - - - - - IPV4: - - - - - - IPV4 Dns: - - - - + + IPv4: + + + + + + IPv6: + + + + + + IPv4 DNS: + + + + + Mac: @@ -173,12 +179,12 @@ - + Cancel - + Connect @@ -186,22 +192,22 @@ FirewallDialog - + Allow other devices on this network to discover this computer? - + It is not recommended to enable this feature on public networks - + Not allowed (recommended) - + Allowed @@ -209,63 +215,53 @@ Ipv4Page - - Ipv4Config - - - - + Address - + Netmask - + Default Gateway - - Prefs DNS + + IPv4Config - - Alternative DNS - - - - + Auto(DHCP) - + Manual - + Invalid address - + Invalid subnet mask - - + + Required - + Address conflict @@ -273,64 +269,53 @@ Ipv6Page - - Ipv6Config - - - - + Address - + Subnet prefix Length - + Default Gateway - - Prefs DNS + + IPv6Config - - Alternative DNS - - - - + Auto(DHCP) - + Manual - - - + + Required - + Invalid address - + Invalid gateway - + Address conflict @@ -338,37 +323,37 @@ JoinHiddenWiFiPage - + Please enter the network name and security type - + Network name(SSID) - + Show Network List - + Cancel - + Join - + Required - + Find and Join Wi-Fi @@ -376,52 +361,66 @@ LanListItem - + Not connected - + Wired Device not carried - - + + + Disconnect - - + + + Connect + + + + Property + + + + + + Delete + + LanPage - + No ethernet device avaliable - + LAN - + Activated LAN - + Inactivated LAN - + Wired Device not carried @@ -429,12 +428,12 @@ ListItem - + Kylin NM - + kylin network applet desktop message @@ -442,33 +441,37 @@ MainWindow - + + kylin-nm - + LAN - + WLAN - + Settings - - Network tool + + Show MainWindow + + + MultipleDnsWidget - - Show MainWindow + + DNS server: @@ -485,97 +488,102 @@ - + Detail - Ipv4 - - - - - Ipv6 - - - - Security - - + + Config - + Confirm - + Cancel - + Forget this network - - Add Lan Connect + + IPv4 - - connect hiddin wlan + + IPv6 - - - + + Add LAN Connect + + + + + Connect Hidden WLAN + + + + + Delete this network + + + + + + None - - - + + + Auto - + start check ipv4 address conflict - + start check ipv6 address conflict - + this wifi no support enterprise type - + this wifi no support None type - + this wifi no support WPA2 type - + this wifi no support WPA3 type @@ -599,169 +607,213 @@ SecurityPage - + Remember the Network - + Security - + Password - + EAP type - + Identity - + Domain - + CA certficate - + no need for CA certificate - + User certificate - + User private key - + User key password - + Password options - - - + + + Required - + Ineer authentication - - Usename + + Username - + Ask pwd each query - - - - - - - - - + + + + + + + + + + + + None - + WPA&WPA2 Personal - + WPA&WPA2 Enterprise - + WPA3 Personal - - - + + + + Choose from file... - + + PAC provisioning + + + + + Allow automatic PAC provisioning + + + + + PAC file + + + + + Anonymous + + + + + Authenticated + + + + + Both + + + + Store passwords only for this user - + Store password only for this user - + Store passwords for all users - + Store password for all users - + Ask this password every time - + Ask password every time - - - + + + Choose a CA certificate - - - + + + CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx) - + + Choose a PAC file + + + + + PAC Files (*.pac) + + + + @@ -769,49 +821,31 @@ TabPage - + Current Device - + Devices Closed! - + Settings - + Kylin NM - + kylin network applet desktop message - - VpnPage - - - Activated VPN - - - - - Inactivated VPN - - - - - Wired Device not carried - - - WiFiConfigDialog @@ -820,37 +854,37 @@ - + WLAN Authentication - + Input WLAN Information Please - + WLAN ID: - + WLAN Name: - + Password: - + Cancl - + Ok @@ -858,31 +892,42 @@ WlanListItem - + Not connected - - + + + + + Disconnect - - - + + + + + Connect - - + + + Property + + + + + Forget - + Auto Connect @@ -890,7 +935,7 @@ WlanMoreItem - + Add Others... @@ -898,32 +943,32 @@ WlanPage - + WLAN - + Activated WLAN - + Other WLAN - + No wireless network card detected - + WLAN Connected Successfully - + WLAN Disconnected Successfully @@ -931,32 +976,19 @@ main - + kylinnm - + show kylin-nm wifi page - + show kylin-nm lan page - - vpnMainWindow - - - kylin-vpn - - - - - vpn tool - - - diff --git a/translations/kylin-nm_bo_CN.qm b/translations/kylin-nm_bo_CN.qm deleted file mode 100644 index 31a2c8c61c1651ad455f98ee99036a85ac8ffc49..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17062 zcmd5@3vgW3c|JlbX|>Yo+LCNz;m5UVgRI!X_#upOvGuTQ)wU#CvSe%?y4t;KEn4l0 z-75JDSC(uiEgp3CanJw%=YK!WZvE5v`G5P)L-)SCV#(KrKmQm1+Ac&{SO}pD(R2k~ z9~R=$Dj|CRS%}Kt6Qb`LAujkHuS;JQq2o{C(E}p%k9P=h(Yw4hHHgrE-XlcgDAxP1 z-X+Qw{7Q&LCq&t$*9j3B7iEJx@cFyEu6a+CJqNhUOL@Kguvk<*fcHNZ>&{y$#M0%w zHa^Sire$K?f}8RERigX0hlFTdCc58f5F&hs=>A{}=zUl8OdkWD`B*=Lb(`4t*KZ23 zd6PJJGd{2C6(1XUQiu)9#i>=xg{T=8ug%|s_jik*v~Ln(wJF}e`*A#Xb4mHr(?XPg zg4g*s@>)Mp5+3`i5DTs?>3i&6e1CDt9rrB&opD|_-C6SF*Xo35`A*3=^guM1u-+r4T^h-H6Jc4X;d@a>mnw|w$8oa>>o2kr(xntxjMlkdI& zJhzu$^!)z_u_jc0Rqm%ktg9)%F@7BS)L#DOZ$TfbD$3ufe_e=;FILp`|2xh*T=A*L zKZ@r+Uh%~7AAo;fVFbq;qJ<<->QUu&aaGr&;Yu= zQ<+)xW1RoP%E^n$gjjMxbcv6`0a4zmwq3g zpZ9*{i(#y*ZmWEC{V%|`zREYA!ut!Kt9)Os&6OX1{59CtBayb!8-=L7F4FOd%YgSk zBE|raYIXD7z*EEPg3_w46JHf#YeQB1v?T?sCxUGe<{S}%c_q@L082Cyw)A&b-}NAUA&3cmfh8NEO`)o{a*D0Yi`AQ zef2}TOu*e){pTe)=*KXx8?WGX(_r;0yP&`8hpXS|$M@P~bm`r?weGc=AN>OS+x#(YU8V)keNx;1HuMmfzu5kFINzJvm;QJq`2RMq zOPE_XFs_U zpC<6cptc=*_Tg1RyGuJ|KRt;3Rrr+PCA28HTv3kyS9N64iR2MIk<6M?Mk=Kn>A0RV zW0TpWHH{aRl}sPWRp7}8KiOv-F-t&W$#JaJI_fKE80@Z<6yUZ0ZG-i2?5L4%)~ zE=lQje3zB4+O=owb8g2gf;o)8wCkYOhi~ZQeVT={0RwgrzASh_r|p&Bw#%p6wSEcj z5T1=mD9pV!`TRkAa!5Yi3Aj~wg7~!$@cZRA^mo9fmgygq-xKy>?4&&d*b~(V9-rMk z1MeVeSzb)NI{7h4Ez8U+7v==f+KHV+&#-nFXCYenX#?+wBgAc%ufpv}Q?xkpJlSa; zO~%Zeo=NN0sHvw-Ybui+(_=}>=GTKPpo!q zI?^_2Wtuv7b@Z(!{VfF31a1#P9>=89BbRAOVp#K77YL0@mIh~@He*&2ZlcE+mv&JI zw;7I(OpFdTs9hrsPB}=@^PA+i$Dk1&$em`wm`qvvPQyY(nGU9Sq3FgDkBW`JU`ZBS z3C(e#M7sNqZsdRy44?)_CHtr7hp6E2s(i1JhUW?1)PTqH-3teTb_YNOoGUe!5J%o2m5=c>mgc%iE90-wi1pT38+#1~yw7Jpd+MsRIgCOygt?n`S0xzht zj!`2W2xTjFD_?W1)Eqhp`2-Hx>`y4*^0Da~3a0o(tZ+!J@5oFfO=KvOF&J$wF^Q

58q4cFg#6s|P+k-5U7x`PwL0M7Deof62%9lP!AohV~k< zz^yH!AOE^>m@U}Eo@^(0%oz}WG6JBKnR)@%_N7cCXTl331=0KayE_BH>$awm$hrWA z{15{ryYm99?8|1XOe~WMgcEVebOc^j6zdk~9Jv)z9FF3AHX&JuicchW_O=Ocfb0}q`JCjB#bA(cQv0n^{B>t@xT_Oqe6!X~~ z(Rp3ZNuP5%Go{fM2hj+AJ__>l!=vpx2FK~^D=aUc%bbpx25kh$$J_LGiN5l%iQiqBPr zpz)ZxBU(QWO^gB!(ng4>2f;S-v}9W+@s7TCMZ2wAW~`LndQxFxfSKl^j0(2| zlE_JvUr62T6jo)m#rV+#OoW|$D7X?_*`S(nDOubD8W0ULQwX-cyu28W*(Sl^?unxt zoy4S3ixWloUu6MQjrNjvQpvb(xK)TB_WoJHR*4%aayyKIgI)rZaPsc) zq#o>b3VUvH1S+blwAxR>EHZijhPh_({@rJp!TW*DMd@45t(?_gP<%?a!x)VOR zR36m0>?4XC0zk(`c-uT zS+~qzyX|KwhN!3VbJDsl^eSbKlF)KqN(U)M#Y$i}21+QFx^)OqBUFsu`#p_nZZs7l3_b_t^jvSL@S+Ig z5~Z+0aw{W-=q7z`aBxaNC#GL)7lKG!WnbEDSknpp!wA*CEq2gRK|?5f24{!yg6N{D-sIhn&0!+fT7OVu7DO|ZKyb6nPSOF*pK zAMBHUjJta1Vmq>kbkcl4wgpLR3!pUnptxN|&MjRjdtpW?kF!#2cu9#i z*E)Vz#1oQXTa}r&oR)hLoj*i9HoIr6QwAL~vRSl>0*|r~HpXV`H3*j#(KfV3kHVqH z^*wDp1fl{wb-d9++i=MXsiFvO&EX`{E@MUjO9IZUax9mM(jeSdp<6@E0P2?pm7QKM z?hcm*@jNLb4VQQ{ro5-OGH_8Z=|RmwRT<@NT$t$wrIJ*J6!7CWAVMGi^#I37s>3nC z+jR)9?CHl0J&T#EYyr;S zi@`_|dV)4D`t3(dOA2+1=cvj9ssqts$say!M-yTxnSFi-P(yL7!$+w>0Fhh?HQ+&j zM6(idBbiYq%RayzHIPIlM;#v)qOn2%lv(%V^02pnH^CPZc1W2PJ6O3}Aml-8#5sCx zuhs^0rSMw}3bplc#X(9k4~#zxBi{0aBmpLogD>QDU8f0C$3U67F}D2&aH`SCRB2Mc zwpz@Yl(U=ypsWD_Zj$JBlBk1p0;E#dr1`2$8Xf7?b!D?LcUvU=!mNX0q4W<#Wh+l4yWHX)l#oWY}~hHhtGKg?ch+=~eUg)_;=TAwR9`LM#pG)>)^?L8H|-%+E6hXc>|{qDMG=F@GnF!A z4Uk9f*#@7b{@@cg3!+XQ!b525Pso8QIZ&mB%6*bcVDllVc}uJ~&Zt~DpO&5_XHW5v z;-$;y6*4+QG^| zDasO8PTd0O`w;&*91p>L%UD&_n>G=;()7NhwD>cK{IP&%N_290)yn@l1^D>Kp|kz_AiE zoaDPk1#p@Pjyx=-T%M!bYIw|^mU%_JsADvf!8HOyw-LZ`7RS)etOPuDX^=Zr?&OK@ zwJB%cjwhYu5A4Q2=R|cj=0r9#j=Qrdv!$gaSj%c<JDTT&9Pu-)z>dz9x-RQGgxab>9!B!lf?47eY@10%p5|nLGzNCaj zKEyNQc34&4oi?FEM!|TxkkUCNfQ8#@9UrD{RJg1T_t}>sf{%KIvsGQXP#1YwJ4R4| zv397d8pHse-+DE2okJv3! zyV?&v*;#f)gSgDHCkpv`jEBqWq`|c8mkL736ICq-VG*Q2d?ouJz)_&_h9P>**QvW@ zh;oCEW0#JaE$O#17>YY?Hi6487+~v@sK1LyArVLp%YuxRn*2VTf-k{0}$@^3O>%s0|<_jRZ!E|gWp4(EbeFvRwJh*FXy<9x!^k1E)U58}27c^+??I^V(C z2S<@f+jobRBXd&b^KG0P@^Lxrhyv0EeP$@$EXS`etc{+G!-3m?QV=0DE=_YbiO$@* zyZ!iqPs()8xl*2wavz!uv-|Tlizy9oWmeNMnav`Hum>+Bu8IL;#DUfBKpA+=3IflfKZGkdn9 zVNnIuvTSzku!Gi>up$*dC|aru!!G+~JwxzOLn$Q%PGv-1buOa|k+SDMj|S-6JXKfY zeDz~Fe@Y??cod&fai<1zssoQHgXbV>3hvH&sj);kX5plFX}7%VOI>-rJB=taF7GMo zJOD0EMGf##pry8;SM$#6l~?qGNvA}Tt64Wj=U-~BQmNWI&wi#j`i%ihI9=}R%C}A) z7oGIHo0-8>&x4EEgPgxd=zOQzaRCu#Tjz|VE(;*liEy6V+zgC<^&y86!L-oz8xmyD zupsa@twU?I_xA|I*lN0E>>Ir`g3>d&kXs1pj3(QKVCErFaNFtLguc8>HqwL7ac(B! zh2*qAebrUlpaBpimolQ|Ri#lH0`=0^HmB-Q;{9GE#?D=U(~Z7s+|jq1poIyDyQ&FuL zg@VA*z=&jl9!&l@n=AThS{Gn^%oXk#yXu}_6 ConfigPage - + Network profile type དྲ་རྒྱའི་བཀོད་སྒྲིག་ཡིག་ཆའི་རིགས། - + Public(recommended) Devices on the network cannot discover this computer. Generally, it is suitable for networks in public places, such as airports or coffee shops, etc. སྤྱི་སྤྱོད།(འོས་སྦྱོར་བྱས་པ།)དྲ་རྒྱའི་སྒྲིག་ཆས་ཀྱིས་གློག་ཀླད་འདི་མཐོང་མི་ཐུབ། སྤྱིར་བཏང་གི་གནས་ཚུལ་འོག་ཏུ་མི་མང་འདུ་སའི་ནང་གི་དྲ་བ་ལ་འཚམ་པ་སྟེ།དཔེར་ན་གནམ་གྲུ་ཐང་དང་འཚིག་ཇའི་ཁང་སོགས་ལྟ་བུ།. - + Private Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. ཆེད་སྤྱོད། དྲ་རྒྱའི་སྒྲིག་ཆས་ཀྱིས་གློག་ཀླད་འདི་མཐོང་ཐུབ། སྤྱིར་བཏང་གི་གནས་ཚུལ་འོག་ཁྱིམ་ཚང་ངམ་ལས་དོན་ཚན་པའི་དྲ་བ་དང་འཚམ་པས།ཁྱེད་ཀྱིས་དྲ་ཐོག་གི་མི་སྒེར་དང་སྒྲིག་ཆས་ལ་ངོས་འཛིན་དང་ཡིད་ཆེས་བྱེད་དགོས།. - + Config firewall and security settings མེ་འགོག་གྱང་རྩིག་དང་བདེ་འཇགས་བཀོད་སྒྲིག་བྱ་དགོས། @@ -73,63 +73,61 @@ CreatNetPage - + Connection Name འབྲེལ་མཐུད་ཀྱི་མིང་། - + IPv4Config IPv4ཁུང་ཙི། - + Address སྡོད་གནས། - + Netmask དྲ་རྒྱའི་མ་ལག - + Default Gateway ཁ་ཆད་བཞག་པའི་སྒོ་ཆེན། - Prefs DNS - སྔོན་གྲབས་DNS + སྔོན་གྲབས་DNS - Alternative DNS - ཚབ་བྱེད་རང་བཞིན་གྱི་DNS + ཚབ་བྱེད་རང་བཞིན་གྱི་DNS - + Auto(DHCP) རང་འགུལ་(DHCP) - + Manual ལག་དེབ། - + Invalid address རྩིས་འགྲོ་མེད་པའི་ས་གནས། - + Invalid subnet mask རྩིས་འགྲོ་མེད་པའི་དྲ་བ་འགེབས་སྲུང་བྱེད་པ། - - + + Required ངེས་པར་དུ་སྐོང་དགོས། @@ -137,82 +135,82 @@ DetailPage - + Auto Connection རང་འགུལ་གྱིས་འབྲེལ་མཐུད་བྱེད - - + + SSID: SSID: - + Copied successfully! འདྲ་བཟོ་བྱས་ནས་གྲུབ་འབྲས་ཐོབ་! - + Copy all ཚང་མ་འདྲ་བཤུས་བྱེད་ - + Please input SSID: SSID:ནང་འཇུག་གནང་རོགས།: - - + + Protocol: གྲོས་ཆོད་ནང་དུ།: - - + + Security Type: བདེ་འཇགས་ཀྱི་རིགས་དབྱིབས་ནི།: - - + + Hz: དྲ་རྒྱའི་འཕྲིན་ལམ།: - - + + Chan: དྲ་བའི་བགྲོད་ལམ།: - - + + BandWidth: ཞེང་ཆེ་བ།: - - + + IPv6: IPv6: - - + + IPv4: IPv4: - - + + IPv4 DNS: IPv4 DNS: - - + + Mac: ཨའོ་མོན་ནི།: @@ -473,12 +471,12 @@ གསང་གྲངས་དང་གསང་བའི་ལྡེ་མིག་དགོས། - + Cancel ཕྱིར་འཐེན། - + Connect སྦྲེལ་མཐུད་བྱེད་པ @@ -502,22 +500,22 @@ དེ་ལྟར་མ་བྱས་ - + Allow other devices on this network to discover this computer? དྲ་རྒྱའི་སྟེང་གི་སྒྲིག་ཆས་གཞན་པས་གློག་ཀླད་འདི་རྙེད་དུ་འཇུག་གམ།? - + It is not recommended to enable this feature on public networks བསམ་འཆར་མེད་།སྤྱི་པའི་དྲ་རྒྱའི་སྟེང་ནས་ནུས་པ་འདི་མགོ་བརྩམས་། - + Not allowed (recommended) མི་ཆོག་པ་(འོས་སྦྱོར།) - + Allowed ཆོག་པ་ @@ -525,63 +523,61 @@ Ipv4Page - + IPv4Config IPv4ཁུང་ཙི། - + Address སྡོད་གནས། - + Netmask དྲ་རྒྱའི་མ་ལག - + Default Gateway ཁ་ཆད་བཞག་པའི་སྒོ་ཆེན། - Prefs DNS - སྔོན་གྲབས་DNS + སྔོན་གྲབས་DNS - Alternative DNS - ཚབ་བྱེད་རང་བཞིན་གྱི་DNS + ཚབ་བྱེད་རང་བཞིན་གྱི་DNS - + Auto(DHCP) རང་འགུལ་(DHCP) - + Manual ལག་དེབ། - + Invalid address རྩིས་འགྲོ་མེད་པའི་ས་གནས། - + Invalid subnet mask རྩིས་འགྲོ་མེད་པའི་དྲ་བ་འགེབས་སྲུང་བྱེད་པ། - - + + Required ངེས་པར་དུ་སྐོང་དགོས། - + Address conflict ཤག་གནས་གདོང་གཏུག་ @@ -589,64 +585,61 @@ Ipv6Page - + IPv6Config IPv6ཁུང་ཙི། - + Address སྡོད་གནས། - + Subnet prefix Length ཡན་ལག་དྲ་རྒྱའི་སྔོན་སྒྲིག་གི་རིང་ཚད། - + Default Gateway ཁ་ཆད་བཞག་པའི་སྒོ་ཆེན། - Prefs DNS - སྔོན་གྲབས་DNS + སྔོན་གྲབས་DNS - Alternative DNS - ཚབ་བྱེད་རང་བཞིན་གྱི་DNS + ཚབ་བྱེད་རང་བཞིན་གྱི་DNS - + Auto(DHCP) རང་འགུལ་(DHCP) - + Manual ལག་དེབ། - - - + + Required ངེས་པར་དུ་སྐོང་དགོས། - + Invalid address རྩིས་འགྲོ་མེད་པའི་ས་གནས། - + Invalid gateway རྩིས་འགྲོ་མེད་པའི་དྲ་བའི་འགག་སྒོ། - + Address conflict ཤག་གནས་གདོང་གཏུག་ @@ -654,12 +647,12 @@ JoinHiddenWiFiPage - + Please enter the network name and security type ཁྱེད་རང་དྲ་རྒྱའི་ནང་དུ་ཞུགས་འདོད་པའི་མིང་དང་བདེ་འཇགས་རིགས་ནང་འཇུག་བྱེད་རོགས། - + Network name(SSID) དྲ་རྒྱའི་མིང་། (SID) @@ -668,27 +661,27 @@ དྲ་རྒྱ་དེ་སེམས་ལ་འཛིན་དགོས། - + Show Network List དྲ་རྒྱའི་རེའུ་མིག་གསལ་པོར་མངོན་པ། - + Cancel མེད་པར་བཟོ་དགོས། - + Join དེའི་ནང་དུ་ཞུགས་པ། - + Required ངེས་པར་དུ་སྐོང་དགོས། - + Find and Join Wi-Fi འཚོལ་ཞིབ་བྱས་པ་མ་ཟད་WI-FIལ་ཞུགས་པ་རེད། @@ -696,32 +689,38 @@ LanListItem - + Not connected འབྲེལ་མཐུད་མི་བྱེད་པ། - + Wired Device not carried སྐུད་ཡོད་སྒྲིག་ཆས་འཁྱེར་མེད་པ། - - + + + Disconnect འབྲེལ་ཐག་ཆད་པ། - - + + + Connect སྦྲེལ་མཐུད་བྱེད་པ - + + + Property ངོ་བོ། - + + + Delete དྲ་རྒྱ་དེ་བསུབ་དགོས། @@ -729,22 +728,22 @@ LanPage - + No ethernet device avaliable ཨེ་ཙི་དྲ་རྒྱའི་སྒྲིག་ཆས་ལ་བཙན་འཛུལ་བྱས་མི་ཆོག། - + LAN སྐུད་ཡོད་དྲ་བ། - + Activated LAN ངའི་དྲ་རྒྱ། - + Inactivated LAN དྲ་བ་གཞན་དག @@ -753,7 +752,7 @@ སྐུད་ཡོད་དྲ་བ་ཆད་སོང་། - + Wired Device not carried སྐུད་ཡོད་སྒྲིག་ཆས་འཁྱེར་མེད་པ། @@ -765,12 +764,12 @@ ListItem - + Kylin NM དྲ་རྒྱའི་ཡོ་བྱད། - + kylin network applet desktop message དྲ་རྒྱའི་གསལ་འདེབས་གནས་ཚུལ། @@ -778,37 +777,45 @@ MainWindow - + + kylin-nm དྲ་རྒྱའི་ཡོ་བྱད། - + LAN 有线网络 སྐུད་ཡོད་དྲ་བ། - + WLAN 无线局域网 སྐུད་མེད་ཅུས་ཁོངས་ཀྱི་དྲ་བ། - + Show MainWindow རླུང་གཙོ་བོ་མངོན་པར་བྱས་ཡོད། - + Settings 设置网络项 སྒྲིག་བཀོད། - Network tool - དྲ་རྒྱའི་ལག་ཆ་ + དྲ་རྒྱའི་ལག་ཆ་ + + + + MultipleDnsWidget + + + DNS server: + DNSཞབས་ཞུའི་ཡོ་བྱད།: @@ -824,22 +831,22 @@ དྲ་རྒྱའི་གསལ་འདེབས་གནས་ཚུལ། - + Detail ཞིབ་ཕྲའི་གནས་ཚུལ། - + IPv4 IPv4 - + IPv6 IPv6 - + Security བདེ་འཇགས། @@ -848,61 +855,62 @@ 关闭 - - + + Config བཀོད་སྒྲིག་བཅས་བྱ་དགོས། - + Confirm གཏན་འཁེལ་བྱ་དགོས། - + Cancel ཕྱིར་འཐེན། - + Forget this network དྲ་རྒྱ་འདི་བརྗེད་སོང་། + Delete this network དྲ་རྒྱ་དེ་བསུབ་དགོས། - + Add LAN Connect སྐུད་ཡོད་དྲ་བ་ཁ་སྣོན་བྱ་དགོས། - + Connect Hidden WLAN ཧའེ་ཏེན་ཝེ་ལན་དང་འབྲེལ་མཐུད་བྱེད་པ། - - - + + + None གཅིག་ཀྱང་མེད། - - - + + + Auto རང་འགུལ་གྱིས་རླངས་ - + start check ipv4 address conflict ipv4ས་གནས་ཀྱི་འགལ་བ་ལ་ཞིབ་བཤེར་བྱེད་འགོ་ཚུགས། - + start check ipv6 address conflict ipv6གནས་ཡུལ་དང་འགལ་བར་ཞིབ་བཤེར་བྱེད་འགོ་ཚུགས། @@ -915,22 +923,22 @@ ipv6ཐག་གཅོད་གདོང་གཏུག་བྱུང་བ་རེད།! - + this wifi no support enterprise type wifiལ་རྒྱབ་སྐྱོར་མེད་པའི་ཁེ་ལས་ཀྱི་རིགས་དབྱིབས། - + this wifi no support None type wifiལ་རྒྱབ་སྐྱོར་མི་བྱེད་པར་རིགས་དབྱིབས་གཅིག་ཀྱང་མེད། - + this wifi no support WPA2 type wifiལ་རྒྱབ་སྐྱོར་མི་བྱེད་པའི་WPA2རིགས་དབྱིབས་ - + this wifi no support WPA3 type wifiལ་རྒྱབ་སྐྱོར་མི་བྱེད་པའི་WPA3རིགས་དབྱིབས་ @@ -1041,169 +1049,213 @@ SecurityPage - + Remember the Network དྲ་རྒྱ་དེ་སེམས་ལ་འཛིན་དགོས། - + Security བདེ་འཇགས། - + Password གསང་གྲངས། - + EAP type EAP རིགས་དབྱིབས། - + Identity ཐོབ་ཐང་། - + Domain ཁྱབ་ཁོངས། - + CA certficate CA certficate - + no need for CA certificate CAཡི་ལག་ཁྱེར་མི་དགོས། - + User certificate སྤྱོད་མཁན་གྱི་ལག་ཁྱེར། - + User private key སྤྱོད་མཁན་གྱི་སྒེར་གྱི་ལྡེ་མིག - + User key password སྤྱོད་མཁན་གྱི་ལྡེ་མིག་གི་གསང་ - + Password options གསང་བའི་ཐོག་ནས་རྣམ་གྲངས་བདམས་པ། - - - + + + Required ངེས་པར་དུ་སྐོང་དགོས། - + Ineer authentication དབྱིན་ཆས་ཀྱི་བདེན་དཔང་ར་སྤྲོད་ - + Username བཀོལ་སྤྱོད་ཀྱི་མིང་། - + Ask pwd each query འདྲི་རྩད་རེ་རེར་འདྲི་རྩད་བྱེད་པ། - - - - - - - - - + + + + + + + + + + + + None གཅིག་ཀྱང་མེད། - + WPA&WPA2 Personal WPA&WPA2མི་སྒེར་གྱི་ངོས་ནས་བཤད་ན། - + WPA&WPA2 Enterprise WPA&WPA2 ཁེ་ལས། - + WPA3 Personal WPA3མི་སྒེར་ - - - + + + + Choose from file... ཡིག་ཆའི་ནང་ནས་གདམ་ག་རྒྱག་དགོས།... - + + PAC provisioning + PACབཀོད་སྒྲིག་བྱས་པ། + + + + Allow automatic PAC provisioning + རང་འགུལ་PACབཀོད་སྒྲིག་བྱས་ཆོག + + + + PAC file + PACཡི་ཡིག་ཆ། + + + + Anonymous + མིང་མི་འགོད་པ། + + + + Authenticated + དཔང་དངོས་བདེན་པ་ཡིན་པའི་ར་ + + + + Both + དེ་གཉིས་ཀ་མཉམ་དུ་སྤྱོད་དགོས། + + + Store passwords only for this user སྤྱོད་མཁན་དེ་ཁོ་ནའི་ཆེད་དུ་གསང་གྲངས་ཉར་ཚགས་བྱས་ཡོད། - + Store password only for this user སྤྱོད་མཁན་དེ་ཁོ་ནའི་ཆེད་དུ་གསང་གྲངས་ཉར་ཚགས་བྱས་ཡོད། - + Store passwords for all users སྤྱོད་མཁན་ཚང་མའི་གསང་བ་གསོག་ཉར་བྱེད་དགོས། - + Store password for all users སྤྱོད་མཁན་ཚང་མའི་གསང་བ་གསོག་ཉར་བྱེད་དགོས། - + Ask this password every time ཐེངས་རེར་གསང་བ་འདི་འདྲི་རྩད་བྱེད་ཐེངས་རེ་ཡིན། - + Ask password every time ཐེངས་རེར་གསང་བ་འདི་འདྲི་རྩད་བྱེད་ཐེངས་རེ་ཡིན། - - - + + + Choose a CA certificate CAཡི་དཔང་ཡིག་འདེམས་པ། - - - + + + CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx) CA དཔང་ཡིག (*.pem *.der *.p12 *.crt *.cer *.pfx) - + + Choose a PAC file + ཡིག་ཆ་PACབདམས་པ་རེད། + + + + PAC Files (*.pac) + PACཡི་ཡིག་ཆ། (*.pac) + + + @@ -1211,27 +1263,27 @@ TabPage - + Current Device མིག་སྔའི་སྒྲིག་ཆས། - + Devices Closed! སྒྲིག་ཆས་སྒོ་རྒྱག་པ།! - + Settings སྒྲིག་བཀོད། - + Kylin NM ཅིན་ལིན་NM - + kylin network applet desktop message kylinདྲ་རྒྱའི་ཀུ་ཤུའི་ཅོག་ཙེའི་ཆ་འཕྲིན། @@ -1239,19 +1291,8 @@ VpnPage - - Activated VPN - - - - - Inactivated VPN - - - - Wired Device not carried - སྐུད་ཡོད་སྒྲིག་ཆས་འཁྱེར་མེད་པ། + སྐུད་ཡོད་སྒྲིག་ཆས་འཁྱེར་མེད་པ། @@ -1262,37 +1303,37 @@ - + WLAN Authentication སྐུད་མེད་བདེན་དཔང་ར་སྤྲོད། - + Input WLAN Information Please སྐུད་མེད་ཆ་འཕྲིན་ནང་འཇུག་གནང་རོགས། - + WLAN ID: WLAN ID: - + WLAN Name: སྐུད་མེད་མིང་།: - + Password: གསང་གྲངས་ནི།: - + Cancl ཁན་ཁེ་ལན། - + Ok འགྲིགས། @@ -1300,35 +1341,42 @@ WlanListItem - + Not connected འབྲེལ་མཐུད་མི་བྱེད་པ། - - + + + + + Disconnect འབྲེལ་ཐག་ཆད་པ། - - - + + + + + Connect སྦྲེལ་མཐུད་བྱེད་པ - - + + Forget བརྗེད་པ། - + + + Property ངོ་བོ། - + Auto Connect རང་འགུལ་གྱིས་སྦྲེལ་མཐུད་ @@ -1340,7 +1388,7 @@ 更多... - + Add Others... གཞན་པ་ཁ་སྣོན་བྱས་ནས་... @@ -1348,22 +1396,22 @@ WlanPage - + WLAN སྐུད་མེད་ཅུས་ཁོངས་ཀྱི་དྲ་བ། - + No wireless network card detected སྐུད་མེད་དྲ་རྒྱའི་བྱང་བུ་མ་རྙེད་པ། - + Activated WLAN ངའི་དྲ་རྒྱ། - + Other WLAN དྲ་བ་གཞན་དག @@ -1372,12 +1420,12 @@ 更多... - + WLAN Connected Successfully སྐུད་མེད་དྲ་བ་སྦྲེལ་ཡོད། - + WLAN Disconnected Successfully སྐུད་མེད་དྲ་རྒྱ་ཆད་སོང་། @@ -1440,32 +1488,19 @@ main - + kylinnm - + show kylin-nm wifi page སྐུད་མེད་དྲ་རྒྱའི་ངོས་མངོན་པར་བྱས་ཡོད། - + show kylin-nm lan page སྐུད་ཡོད་དྲ་རྒྱའི་ཤོག་ངོས་མངོན་པར་བྱས་ཡོད། - - vpnMainWindow - - - kylin-vpn - - - - - vpn tool - - - diff --git a/translations/kylin-nm_tr.qm b/translations/kylin-nm_tr.qm deleted file mode 100644 index 67ee71e84e40a9877474ba9e57722ceff1c227d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2010 zcmc&!&ubGw6n@)owrQIFP+IX&aD@sL8fc+Z5e3t1YeUnd&}xu^IwsR}%w{)aCk-k3 zA6W3BsCW^7oCGhTy%c-tK~eCcH=%bGZ}rfkzL^c1wn?Scg9*EDXL#@XzBlvDoL)*F ze*68w?e|B!Utf8+{COAv)&P7n_-ufB^Ep7nS5QAK0yNH5;w|u97{T#bH>y40Te*aJ z_uZ(yg8r@>I9^p2?{onu%Wm`)m3PKH#D_{WEAc}^Xyq}^F1S&1)Tgl@h~KHcJn<9b zlJDfqbu2qmiBH_9H2cPnm5|2>kc~mCA9SPE7g&7}#ky}TkM6DlsEOdmu{YRHXZx2{ z&YV^)z*| z+|KJc>NvRbLWzG{C%q6x0R%xO5!8Ydz6 zlP!9+h;7ZXOr2Z}F5>CQRx#tYC6{OirV1elRkKFzf|S^juqa|%Vl27;kcS3Jd3kMk zUTwL-V)IXV$eLm2a9M@Y;1o?23yhaNkGG*;7#0b~WVaOgqiJe!%&cFwYmc=IeaIlZ zCyxd?FD2dQNJDUBot4b4E32YA&O5ZAr)Yt*S(YMPE?_PAP+f3w1_{iet#QW$opM#pS80<>{}>vknW0Xo`cjgR#osHj*!}d2B*Qruqx|-_C8* zG`Z@zApq0Zintkao_!h;Ss}S2$wry$d4mzt&PZ?m)x8%?n*V(9)nfQz*UP~#2xXJM E0d&EWGynhq diff --git a/translations/kylin-nm_tr.ts b/translations/kylin-nm_tr.ts index bca72f95..7a973305 100644 --- a/translations/kylin-nm_tr.ts +++ b/translations/kylin-nm_tr.ts @@ -102,22 +102,22 @@ ConfigPage - + Network profile type - + Public(recommended) Devices on the network cannot discover this computer. Generally, it is suitable for networks in public places, such as airports or coffee shops, etc. - - Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. + + Private Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. - + Config firewall and security settings @@ -125,47 +125,53 @@ CreatNetPage - + Connection Name - - Ipv4Config + + IPv4Config - + Address - + Netmask - + Default Gateway - - Prefs DNS + + Invalid address - - Alternative DNS + + Invalid subnet mask - + + + Required + + + + Auto(DHCP) Oto(DHCP) - + Manual Elle @@ -173,82 +179,82 @@ DetailPage - + Auto Connection - - + + SSID: - + Copied successfully! - + Copy all - + Please input SSID: - - + + Protocol: - - + + Security Type: - - + + Hz: - - + + Chan: - - + + BandWidth: - - - IPV6: - - - - - - IPV4: - - - - - - IPV4 Dns: - - - - + + IPv4: + IPv6 adresi: {4:?} + + + + + IPv6: + IPv6 adresi: {6:?} + + + + + IPv4 DNS: + + + + + Mac: @@ -1192,12 +1198,12 @@ - + Cancel - + Connect @@ -1205,22 +1211,22 @@ FirewallDialog - + Allow other devices on this network to discover this computer? - + It is not recommended to enable this feature on public networks - + Not allowed (recommended) - + Allowed @@ -1228,63 +1234,53 @@ Ipv4Page - - Ipv4Config - - - - + Address - + Netmask - + Default Gateway - - Prefs DNS + + IPv4Config - - Alternative DNS - - - - + Auto(DHCP) Oto(DHCP) - + Manual Elle - + Invalid address - + Invalid subnet mask - - + + Required - + Address conflict @@ -1292,64 +1288,53 @@ Ipv6Page - - Ipv6Config - - - - + Address - + Subnet prefix Length - + Default Gateway - - Prefs DNS + + IPv6Config - - Alternative DNS - - - - + Auto(DHCP) Oto(DHCP) - + Manual Elle - - - + + Required - + Invalid address - + Invalid gateway - + Address conflict @@ -1357,37 +1342,37 @@ JoinHiddenWiFiPage - + Please enter the network name and security type - + Network name(SSID) - + Show Network List - + Cancel - + Join - + Required - + Find and Join Wi-Fi @@ -1402,52 +1387,66 @@ LanListItem - + Not connected Bağlanamadı - + Wired Device not carried - - + + + Disconnect Bağlantıyı Kes - - + + + Connect + + + + Property + + + + + + Delete + + LanPage - + No ethernet device avaliable - + LAN - + Activated LAN - + Inactivated LAN - + Wired Device not carried @@ -1455,12 +1454,12 @@ ListItem - + Kylin NM - + kylin network applet desktop message Kylin ağ uygulaması masaüstü mesajı @@ -1468,7 +1467,8 @@ MainWindow - + + kylin-nm @@ -1489,25 +1489,20 @@ Gizli Ağı Bağlan - + LAN - + WLAN WLAN - + Settings - - - Network tool - - Enabled Aktif @@ -1521,7 +1516,7 @@ HotSpot - + Show MainWindow Ana Pencereyi Göster @@ -1614,6 +1609,14 @@ WLAN Bağlantısı Başarılı + + MultipleDnsWidget + + + DNS server: + + + NetDetail @@ -1627,97 +1630,102 @@ - + Detail - Ipv4 - - - - - Ipv6 - - - - Security - - + + Config Ayar - + Confirm - + Cancel - + Forget this network - - Add Lan Connect + + IPv4 + IPv6 adresi: {4?} + + + + IPv6 + IPv6 adresi: {6?} + + + + Add LAN Connect - - connect hiddin wlan + + Connect Hidden WLAN - - - + + Delete this network + + + + + + None Yok - - - + + + Auto Oto - + start check ipv4 address conflict - + start check ipv6 address conflict - + this wifi no support enterprise type - + this wifi no support None type - + this wifi no support WPA2 type - + this wifi no support WPA3 type @@ -1939,169 +1947,213 @@ SecurityPage - + Remember the Network - + Security - + Password - + EAP type - + Identity Kimlik: - + Domain Domain: - + CA certficate - + no need for CA certificate - + User certificate Kullanıcı sertifikası: - + User private key Kullanıcı özel anahtarı: - + User key password Kullanıcı anahtarı şifresi: - + Password options - - - + + + Required - + Ineer authentication - - Usename + + Username - + Ask pwd each query - - - - - - - - - + + + + + + + + + + + + None Yok - + WPA&WPA2 Personal - + WPA&WPA2 Enterprise - + WPA3 Personal - - - + + + + Choose from file... - + + PAC provisioning + + + + + Allow automatic PAC provisioning + + + + + PAC file + PAC dosyası + + + + Anonymous + Anonim + + + + Authenticated + Doğrulanmış + + + + Both + Her ikisi de + + + Store passwords only for this user - + Store password only for this user - + Store passwords for all users - + Store password for all users - + Ask this password every time - + Ask password every time - - - + + + Choose a CA certificate - - - + + + CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx) - + + Choose a PAC file + + + + + PAC Files (*.pac) + + + + @@ -2109,27 +2161,27 @@ TabPage - + Current Device - + Devices Closed! - + Settings - + Kylin NM - + kylin network applet desktop message Kylin ağ uygulaması masaüstü mesajı @@ -2141,24 +2193,6 @@ Kylin ağ uygulaması masaüstü mesajı - - VpnPage - - - Activated VPN - - - - - Inactivated VPN - - - - - Wired Device not carried - - - WiFiConfigDialog @@ -2167,37 +2201,37 @@ - + WLAN Authentication - + Input WLAN Information Please - + WLAN ID: - + WLAN Name: - + Password: - + Cancl - + Ok Tamam @@ -2205,31 +2239,42 @@ WlanListItem - + Not connected Bağlanamadı - - + + + + + Disconnect Bağlantıyı Kes - - - + + + + + Connect - - + + + Property + + + + + Forget - + Auto Connect @@ -2237,7 +2282,7 @@ WlanMoreItem - + Add Others... @@ -2245,32 +2290,32 @@ WlanPage - + WLAN WLAN - + Activated WLAN - + Other WLAN - + No wireless network card detected - + WLAN Connected Successfully - + WLAN Disconnected Successfully @@ -2293,32 +2338,19 @@ main - + kylinnm - + show kylin-nm wifi page - + show kylin-nm lan page - - vpnMainWindow - - - kylin-vpn - - - - - vpn tool - - - diff --git a/translations/kylin-nm_zh_CN.qm b/translations/kylin-nm_zh_CN.qm deleted file mode 100644 index 6ae0c2c7b63db7951b5f4be03bb4b8b8f9dee7b0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11167 zcmbt44R}-KxnF3SoSY`8Q}t{8R$BS~y8glCvb|gyf_p zpi~q$yg{wXpZignsEEJY)MxJA0qzbT9Zol&3y)6boEy9DPq^1@Ox^5#zjKl=Imt;| z?&w3`{JekP`@Y}%cY5{r{4;-i{u}##($sK#^PwO7ViiK=6heqWXcoZ!pTqn65ONG5 zRDGQaYf{L#=NW|RrX%B-I}w_BA_ISejQ_nCq3JGw`vKmB%BO#Zko_rCe$|%|GKEq3 z`ql9HSrs;1fyz$+-`Y+Uw)`uqw+_JjvuMe*Mv!+=h0`BZA+ukFP4IsD&44GO-VbIY zWc(PhscoR=IKZ!goGZ|Vo8i6LjBfQliO`%^(RW(rAVgh2?^dsaqgA5|tFDCeeH;Dl zzN3J5rNQ*=6hdX+R3Uv)h1NF>RQN@NY*B;b$UgX&n)8o=0d#v@HDsyf>UGJ8%~Cn-wqnlLz>JZm!XqxD38;Gj?Bm6(PFC*mG|ioco}0 z?C};j@2K%$?|;B~TU2OoS7F`17$04C5&Y&eKKa<+0iHKLbDIaDx!uMWuKEo4292k_ za0={sl?p5V0`C10=v!WHZ+r>tyP*6FgEztVRuxvfu0q?P^0h4^;16?ouyGdX`C0ib z|F#S0eo=n^ePFNI@0b?+=r6#3%ydKIBe2uoP22r@fS=#={F^u~-Zq`D`xQb>Tg>L~ z!sqjQ&9&}xz^BceKDqRV3)!4IcZSn+x4;n$i${t@cvuYZG3!v^Y)m~O^%mMTL6>`-I5^2WEo z-~VH|`b`VO?Iw%=Q;4tf;})s@LpaZuEy)Gt5SLplw|ortuKlKE|7kd1NJelmR( z4<9@UbZ=BVxo;uZ2dS{J&ARgU#{lp1);%`R(->5twMm7xS5#PeNQDjmu-@75b+Gd> z>-~#v19-dj8*6yrd&v6l*xof~RLGoEVbjm8r`JF{&*`zAcf@mFjyMLB=HtbJcxwCr7G#1^u zX!A+u^K8Y~v}7xL*We37PkCqDc&`5j_x1gK!@Dr$xOMZ9^x^c&L&N>QVn0=Q(Zjpg zHun1idoaf((}=E*ck{!7k54d?$jBj{5qWt;iia5=Co+B^;gg2>ID8=_7@ri4C1pO| z&U}d%`8b>_#c;7$MDTIm2+zn8!x3suWc8F6m$tnjYHu2K!Z@z&r9_+-Yw{_DA+1KWGI_vRV505&Xi5y)wAK;P^nfVeY!;MVo%Ol6b0Yzx(UdQlq^_uFF8NF*= zM+my9j}sx1^--xo$Eefy_*Mf!H-oLBTq3NGZ`^cpLzv)FE`CcAQi@+6nZlO7`(587 zgrE{zn911;)6w0$%n1?VAJfqM!5@szCN%UaNLC)fFNap>q0`tWW3$KHc_igsAx_lC z-e_}mc&l6wj^|EX*CoXS9`a$*2jQ3qBq5J9>4~B+u`@LG0nv>DQphuEr7JxdadS0FpT4 zcK3GcGBCOO(@*D}$l{1gvgDH@y4ZA9P##5jN!~OrlsHM}VcXr=vN!@CQfg~66IZVVWHctmB@$3@{5YraqA#9`DY+udr<8u0W5P6V*7NZ^{;3y}io7JgADz0!IVR4U;O|DEc4%^Z^ zjqWqi-Gqy&ixYjk61o$RXzs5$b9E;cGefKP9Xlhdp!UB+1h;6F&RHu7^rd}A9; zETc7W`M`WKyB2eiikP&Az6&*@d zraEDZ>h~DeVs-32nf@uyPe!Z+5n@(^s0mRIyMeV0eUg6K(~9e~s`w@}aCzA8dhnKi z5H8pDD)kc=+q}YzmE%RVwZZLA018_YniwcOnSz?Fv88mivo@@4wznYiX0ad%vY0di zX;9M(l;UJ8S#YV|*zj_a%qfiL{LZ$WL{?R%I75XO1JHWNScI0yi0cL+D5%O>RBB3< zRZBCas;VWS`1klVnj=^Cio;w)@H1Sl*U-{fF-=ia2gssdvUJS~i>)&*l#`l7q}KMp#H370m|U$%SZFD3M$Cs$8!^#D z=ruS|4%kp@wz%i@>^0D?Dg&Je-FGXl^h)nuO7c9l9oc+j^GA2=#9Cn1!@F=#ua3={ zk?rzKivmSSnK^UAD3+!jqO;RnDajK!wiJmqa7}6jR?t^}AvnCt~VenU5+Rhmn736Cz^hZaix%!wvRL5wrUI9CPRLMNhYT}v=JZaavC1{Ufx?lN$GR~rq6!^HxZ?jj8@ z*(jRxRXuR;0}o1+_L6fxF1|VTqK+(N;|0`)O)LboXY75X=iJ1faBX zpYS3@(LWKEr5F>1$q05r#muOZ=A!#J0kVkbmqwKMQl@8(j@E1x%aWvyPz5A3J{H#Y zV2bETx%1am1q4>FdlSM08ab89mC2#vQxs}P^Y86Ae#1)7FGrn3l+ly%d?9l2Q7FZF zi^ZrOZ+nTEuA-ZD!}cu>8!ctfsP2Q6fB<%fF%Kr*ATKM1vqnF4Jyc}oN@%1Qi1q9^ zjRjl4pz1iS-e^rDWyHg`9#*NTppcuUsG4#GwGeNsIQTVULp(CT+EKAf0V3^U_WRZT zouJot^AL8h9K#)MCKmN{PXBiENkU{&&#Z$-Z+a^Yi%J|31iQ9Jii2q<6G3H1YC>ql z!?cc&EM|uWvqJ}Sir2NkPSg1Ja-3O7RBmAbjuDTt1Pktny4%&!p$4aI*OL8Xx4!|U zd>!gUETOB-Byc7KEdXSXkqD<$<^o~*38Yb*K>U1B<|tq@a}(Nl3MWw*a%0&oo@Q8R zO2}LsNWlG47 z2mu(!C0HiK@Gg_V?joDs0!14NIf6eN;E$zK;OlX8F1=K~%cjP6St-7=3-#?cu(L;< z8m{wnt)Mhe%9cZy_c;6`F=&MAsbq_aevyadA>#LjveGz^1ARI;1_lSeHG30COHdVl zBixjJf8U39zsI5IH8p1}@(OeAw6VLmA8sOaecI zPi=-zATCAW8CisHZ*SN4+BDBE36-f^ib98@k4U4{;1LJ^V&pU-pjLM}Nc&y}g z;j1ua$!pfCvILBzEI!p|GDR+?)6e$zr_X81be)Tj@=VWbZjof z*4*_fz=y|zkSiv<wF3@(o3w6##L=PNaPHCgyinG=3YPB>K)P7Vk%Nz6Ri%LXwibM}lT%MhcXw*mb! zW)fP~h97Yh<=ffN*g%5uD?v1sl&do*<&UMb8~*Gd!V{g1nm=054tfQs`Yq^`XV^l? z)FwCV(wuIN*xBBdjK?ASW>yo}S>^%GOLT?Nbfejs*!QQrCyABW2j^W8C`*3jA)lK1U87!nv!(^-XQv6@g~FHWvF{ZEw|#GAg!p( z=nJ24F{I^eSM`JK)BkEh^>dhWHdY~hy7T_h06V567mfQbQ@G^TvXe5(+#1a)%%bk8 chGR ConfigPage - + Network profile type 网络配置文件类型 - + Public(recommended) Devices on the network cannot discover this computer. Generally, it is suitable for networks in public places, such as airports or coffee shops, etc. 公用(推荐) 网络中的设备不可发现此电脑。一般情况下适用于公共场所中的网络,如机场或咖啡店等等。 - + Private Devices on the network can discover this computer. Generally applicable to a network at home or work where you know and trust the individuals and devices on the network. 专用 网络中的设备可发现此电脑。一般情况下适用于家庭或工作单位的网络,您认识并信任网络上的个人和设备。 - + Config firewall and security settings 配置防火墙和安全设置 @@ -73,63 +73,61 @@ CreatNetPage - + Connection Name 网络名称 - + IPv4Config IPv4配置 - + Address IPv4地址 - + Netmask 子网掩码 - + Default Gateway 默认网关 - Prefs DNS - 首选DNS + 首选DNS - Alternative DNS - 备选DNS + 备选DNS - + Auto(DHCP) 自动(DHCP) - + Manual 手动 - + Invalid address 无效地址 - + Invalid subnet mask 无效子网掩码 - - + + Required 必填 @@ -137,82 +135,82 @@ DetailPage - + Auto Connection 自动连接 - - + + SSID: SSID: - + Copied successfully! 复制成功! - + Copy all 复制全部 - + Please input SSID: 请输入SSID: - - + + Protocol: 协议: - - + + Security Type: 安全类型: - - + + Hz: 网络频带: - - + + Chan: 网络通道: - - + + BandWidth: 带宽: - - + + IPv6: 本地链接IPv6地址: - - + + IPv4: IPv4地址: - - + + IPv4 DNS: IPv4 DNS服务器: - - + + Mac: 物理地址: @@ -473,12 +471,12 @@ 需要密码或加密密钥。 - + Cancel 取消 - + Connect 连接 @@ -502,22 +500,22 @@ - + Allow other devices on this network to discover this computer? 是否允许此网络上的其他设备发现这台电脑? - + It is not recommended to enable this feature on public networks 不建议在公共网络上开启此功能 - + Not allowed (recommended) 不允许(推荐) - + Allowed 允许 @@ -525,63 +523,61 @@ Ipv4Page - + IPv4Config IPv4配置 - + Address 地址 - + Netmask 子网掩码 - + Default Gateway 默认网关 - Prefs DNS - 首选DNS + 首选DNS - Alternative DNS - 备选DNS + 备选DNS - + Auto(DHCP) 自动 - + Manual 手动 - + Invalid address 无效地址 - + Invalid subnet mask 无效子网掩码 - - + + Required 必填 - + Address conflict 地址冲突 @@ -589,64 +585,61 @@ Ipv6Page - + IPv6Config IPv6配置 - + Address 地址 - + Subnet prefix Length 子网前缀长度 - + Default Gateway 默认网关 - Prefs DNS - 首选DNS + 首选DNS - Alternative DNS - 备选DNS + 备选DNS - + Auto(DHCP) 自动 - + Manual 手动 - - - + + Required 必填 - + Invalid address 无效地址 - + Invalid gateway 无效网关 - + Address conflict 地址冲突 @@ -654,12 +647,12 @@ JoinHiddenWiFiPage - + Please enter the network name and security type 请输入您想要加入网络的名称和安全类型 - + Network name(SSID) 网络名(SSID) @@ -668,27 +661,27 @@ 记住该网络 - + Show Network List 显示网络列表 - + Cancel 取消 - + Join 加入 - + Required 必填 - + Find and Join Wi-Fi 查找并加入Wi-Fi @@ -696,32 +689,38 @@ LanListItem - + Not connected 未连接 - + Wired Device not carried 未插入网线 - - + + + Disconnect 断开 - - + + + Connect 连接 - + + + Property 属性 - + + + Delete 删除此网络 @@ -729,22 +728,22 @@ LanPage - + No ethernet device avaliable 未检测到有线设备 - + LAN 有线网络 - + Activated LAN 我的网络 - + Inactivated LAN 其他网络 @@ -753,7 +752,7 @@ 有线网络已断开 - + Wired Device not carried 未插入网线 @@ -765,12 +764,12 @@ ListItem - + Kylin NM 麒麟网络设置工具 - + kylin network applet desktop message 网络提示消息 @@ -778,37 +777,45 @@ MainWindow - + + kylin-nm 网络工具 - + LAN 有线网络 有线网络 - + WLAN 无线局域网 无线局域网 - + Show MainWindow 打开网络工具 - + Settings 设置网络项 设置网络项 - Network tool - 网络工具 + 网络工具 + + + + MultipleDnsWidget + + + DNS server: + DNS服务器: @@ -824,22 +831,22 @@ 网络提示消息 - + Detail 详情 - + IPv4 IPv4 - + IPv6 IPv6 - + Security 安全 @@ -848,61 +855,62 @@ 关闭 - - + + Config 配置 - + Confirm 确定 - + Cancel 取消 - + Forget this network 忘记此网络 - + + Delete this network 删除此网络 - + Add LAN Connect 添加有线网络 - + Connect Hidden WLAN 连接到隐藏WLAN - - - + + + None - - - + + + Auto 自动 - + start check ipv4 address conflict 开始检测ipv4地址冲突 - + start check ipv6 address conflict 开始检测ipv6地址冲突 @@ -915,22 +923,22 @@ ipv6地址冲突! - + this wifi no support enterprise type 此wifi不支持企业网类型 - + this wifi no support None type 此wifi不支持空类型 - + this wifi no support WPA2 type 此wifi不支持WPA2类型 - + this wifi no support WPA3 type 此wifi不支持WPA3类型 @@ -1041,169 +1049,213 @@ SecurityPage - + Remember the Network 记住该网络 - + Security 安全性 - + Password 密钥 - + EAP type EAP方法 - + Identity 匿名身份 - + Domain - + CA certficate CA 证书 - + no need for CA certificate 不需要CA证书 - + User certificate 用户证书 - + User private key 用户私钥 - + User key password 用户密钥密码 - + Password options 密码选项 - - - + + + Required 必填 - + Ineer authentication 内部认证 - + Username 用户名 - + Ask pwd each query 每次询问密码 - - - - - - - - - + + + + + + + + + + + + None - + WPA&WPA2 Personal WPA&WPA2 个人 - + WPA&WPA2 Enterprise WPA&WPA2 企业 - + WPA3 Personal WPA3 个人 - - - + + + + Choose from file... 从文件选择... - + + PAC provisioning + PAC配置 + + + + Allow automatic PAC provisioning + 允许自动PAC配置 + + + + PAC file + PAC文件 + + + + Anonymous + 匿名 + + + + Authenticated + 已认证 + + + + Both + 两者兼用 + + + Store passwords only for this user 仅为该用户存储密码 - + Store password only for this user 仅为该用户存储密码 - + Store passwords for all users 存储所有用户的密码 - + Store password for all users 存储所有用户的密码 - + Ask this password every time 每次询问这个密码 - + Ask password every time 每次询问这个密码 - - - + + + Choose a CA certificate 选择一个CA证书 - - - + + + CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx) CA 证书 (*.pem *.der *.p12 *.crt *.cer *.pfx) - + + Choose a PAC file + 选择一个PAC文件 + + + + PAC Files (*.pac) + PAC 文件 (*.pac) + + + @@ -1211,27 +1263,27 @@ TabPage - + Current Device 当前网卡 - + Devices Closed! 设备关闭! - + Settings 网络设置 - + Kylin NM 麒麟网络设置工具 - + kylin network applet desktop message 网络提示消息 @@ -1239,19 +1291,8 @@ VpnPage - - Activated VPN - - - - - Inactivated VPN - - - - Wired Device not carried - 未插入网线 + 未插入网线 @@ -1262,37 +1303,37 @@ - + WLAN Authentication - + Input WLAN Information Please - + WLAN ID: - + WLAN Name: - + Password: - + Cancl - + Ok @@ -1300,35 +1341,42 @@ WlanListItem - + Not connected 未连接 - - + + + + + Disconnect 断开 - - - + + + + + Connect 连接 - - + + Forget 忘记此网络 - + + + Property 属性 - + Auto Connect 自动加入该网络 @@ -1340,7 +1388,7 @@ 更多... - + Add Others... 加入其他网络... @@ -1348,22 +1396,22 @@ WlanPage - + WLAN 无线局域网 - + No wireless network card detected 未检测到无线网卡 - + Activated WLAN 我的网络 - + Other WLAN 其他网络 @@ -1372,12 +1420,12 @@ 更多... - + WLAN Connected Successfully 无线网络已连接 - + WLAN Disconnected Successfully 无线网络已断开 @@ -1440,32 +1488,19 @@ main - + kylinnm - + show kylin-nm wifi page - + show kylin-nm lan page - - vpnMainWindow - - - kylin-vpn - - - - - vpn tool - - - From a9a352bfc6a2cb7d212ab8c05db5d50c8c10a620 Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Fri, 7 Apr 2023 17:59:55 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E9=A1=B5ui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enterprise-wlan/enterprisewlandialog.cpp | 10 +- .../netdetails/joinhiddenwifipage.cpp | 14 +- src/frontend/netdetails/netdetail.cpp | 111 +++-- src/frontend/netdetails/netdetail.h | 6 +- src/frontend/netdetails/securitypage.cpp | 402 ++++++++---------- 5 files changed, 250 insertions(+), 293 deletions(-) diff --git a/src/frontend/enterprise-wlan/enterprisewlandialog.cpp b/src/frontend/enterprise-wlan/enterprisewlandialog.cpp index 332f45d1..e7e41087 100644 --- a/src/frontend/enterprise-wlan/enterprisewlandialog.cpp +++ b/src/frontend/enterprise-wlan/enterprisewlandialog.cpp @@ -23,8 +23,7 @@ #include "xatom-helper.h" #define MAIN_SIZE_EXPAND 480,580 #define MAIN_SIZE_NARROW 480,484 -#define PEAP_SCRO_HEIGHT 390 -#define TLS_SCRO_HEIGHT 590 +#define SCROAREA_WIDTH 480 #define MAIN_LAYOUT_MARGINS 0,0,0,0 #define CENTER_LAYOUT_MARGINS 24, 16, 24, 8 #define BUTTON_LAYOUT_MARGINS 24, 24, 24, 24 @@ -127,7 +126,11 @@ void EnterpriseWlanDialog::initUI() m_enterWlanScrollArea = new QScrollArea(this); m_enterWlanScrollArea->setFrameShape(QFrame::NoFrame); m_enterWlanScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_centerWidget->setFixedWidth(SCROAREA_WIDTH); + m_enterWlanScrollArea->setFixedWidth(SCROAREA_WIDTH); m_enterWlanScrollArea->setWidget(m_centerWidget); + m_enterWlanScrollArea->setWidgetResizable(true); + QPalette pal = m_enterWlanScrollArea->palette(); pal.setBrush(QPalette::Base, QColor(0,0,0,0)); m_enterWlanScrollArea->setPalette(pal); @@ -279,21 +282,18 @@ void EnterpriseWlanDialog::onEapTypeChanged(const KyEapMethodType &type) m_resource->getEnterPriseInfoTls(m_wirelessNetItem.m_connectUuid, m_info.tlsInfo); } this->setFixedSize(MAIN_SIZE_EXPAND); -// m_centerWidget->setFixedHeight(TLS_SCRO_HEIGHT); break; case KyEapMethodType::PEAP: if (m_wirelessNetItem.m_connectUuid.isEmpty()) { m_resource->getEnterPriseInfoPeap(m_wirelessNetItem.m_connectUuid, m_info.peapInfo); } this->setFixedSize(MAIN_SIZE_NARROW); -// m_centerWidget->setFixedHeight(PEAP_SCRO_HEIGHT); break; case KyEapMethodType::TTLS: if (!m_wirelessNetItem.m_connectUuid.isEmpty()) { m_resource->getEnterPriseInfoTtls(m_wirelessNetItem.m_connectUuid, m_info.ttlsInfo); } this->setFixedSize(MAIN_SIZE_NARROW); -// m_centerWidget->setFixedHeight(PEAP_SCRO_HEIGHT); break; case KyEapMethodType::LEAP: if (!m_wirelessNetItem.m_connectUuid.isEmpty()) { diff --git a/src/frontend/netdetails/joinhiddenwifipage.cpp b/src/frontend/netdetails/joinhiddenwifipage.cpp index 51c0900b..313be9eb 100644 --- a/src/frontend/netdetails/joinhiddenwifipage.cpp +++ b/src/frontend/netdetails/joinhiddenwifipage.cpp @@ -35,9 +35,7 @@ #define LABEL_MIN_WIDTH 146 #define LABEL_MAX_WIDTH 434 #define MAX_NAME_LENGTH 32 -#define PSK_SCRO_HEIGHT 182 -#define PEAP_SCRO_HEIGHT 340 -#define TLS_SCRO_HEIGHT 560 +#define SCROAREA_WIDTH 480 #define MEDIUM_WEIGHT_VALUE 57 JoinHiddenWiFiPage::JoinHiddenWiFiPage(QString devName, KDialog *parent) @@ -49,7 +47,6 @@ JoinHiddenWiFiPage::JoinHiddenWiFiPage(QString devName, KDialog *parent) initUI(); initComponent(); - setFixedWidth(WINDOW_WIDTH); setAttribute(Qt::WA_DeleteOnClose); setJoinBtnEnable(); @@ -121,8 +118,11 @@ void JoinHiddenWiFiPage::initUI() m_centerVBoxLayout->addWidget(ssidWidget); m_centerVBoxLayout->addSpacing(LAYOUT_SPACING); m_centerVBoxLayout->addWidget(m_secuWidget); - m_centerVBoxLayout->addStretch(); + + m_centerWidget->setFixedWidth(SCROAREA_WIDTH); + m_hiddenWifiScrollArea->setFixedWidth(SCROAREA_WIDTH); m_hiddenWifiScrollArea->setWidget(m_centerWidget); + m_hiddenWifiScrollArea->setWidgetResizable(true); //底部按钮 m_bottomLayout = new QHBoxLayout(m_bottomWidget); @@ -151,6 +151,7 @@ void JoinHiddenWiFiPage::initUI() this->setWindowIcon(QIcon::fromTheme("kylin-network")); this->setFixedHeight(MIN_WINDOW_HEIGHT); + this->setFixedWidth(WINDOW_WIDTH); onPaletteChanged(); } @@ -236,7 +237,6 @@ void JoinHiddenWiFiPage::onSecuTypeChanged(const KySecuType &type) { if (type != KySecuType::WPA_AND_WPA2_ENTERPRISE) { this->setFixedHeight(MIN_WINDOW_HEIGHT); - m_centerWidget->setFixedSize(WINDOW_WIDTH, PSK_SCRO_HEIGHT); } } @@ -244,10 +244,8 @@ void JoinHiddenWiFiPage::onEapTypeChanged(const KyEapMethodType &type) { if (type == KyEapMethodType::TLS) { this->setFixedHeight(TLS_WINDOW_HEIGHT); - m_centerWidget->setFixedSize(WINDOW_WIDTH, TLS_SCRO_HEIGHT); } else if (type == KyEapMethodType::PEAP || type == KyEapMethodType::TTLS) { this->setFixedHeight(PEAP_WINDOW_HEIGHT); - m_centerWidget->setFixedSize(WINDOW_WIDTH, PEAP_SCRO_HEIGHT); } } diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index ec5605fb..32cc3f89 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -47,9 +47,11 @@ #define CONFIG_PAGE_NUM 4 #define CREATE_NET_PAGE_NUM 5 #define PAGE_MIN_HEIGHT 40 +#define PAGE_WIDTH 472 #define LAN_TAB_WIDTH 180 #define WLAN_TAB_WIDTH 240 -#define SCRO_WIDTH 472 +#define SCRO_WIDTH 496 +#define SCRO_HEIGHT 600 #define PEAP_SCRO_HEIGHT 300 #define TLS_SCRO_HEIGHT 480 #define MAX_TAB_TEXT_LENGTH 44 @@ -167,7 +169,6 @@ NetDetail::NetDetail(QString interface, QString name, QString uuid, bool isActiv getConInfo(m_info); startObjectThread(); pagePadding(name,isWlan); - setSecuPageHeight(); connect(qApp, &QApplication::paletteChanged, this, &NetDetail::onPaletteChanged); isCreateOk = !(m_isCreateNet && !isWlan); @@ -281,52 +282,64 @@ void NetDetail::initUI() { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0,9,0,24); - mainLayout->setSpacing(24); + mainLayout->setSpacing(22); + + this->installEventFilter(this); + pageFrame = new QFrame(this); + centerWidget = new QWidget(this); + bottomWidget = new QWidget(this); detailPage = new DetailPage(isWlan, m_name.isEmpty(), this); - ipv4Page = new Ipv4Page(this); ipv6Page = new Ipv6Page(this); securityPage = new SecurityPage(this); createNetPage = new CreatNetPage(this); configPage = new ConfigPage(this); - this->installEventFilter(this); + detailPage->setFixedWidth(PAGE_WIDTH); + ipv4Page->setFixedWidth(PAGE_WIDTH); + ipv6Page->setFixedWidth(PAGE_WIDTH); + securityPage->setFixedWidth(PAGE_WIDTH); + createNetPage->setFixedWidth(PAGE_WIDTH); + configPage->setFixedWidth(PAGE_WIDTH); - centerWidget = new QWidget(this); - bottomWidget = new QWidget(this); - - m_secuPageScrollArea = new QScrollArea(this); + m_secuPageScrollArea = new QScrollArea(centerWidget); + m_secuPageScrollArea->setFixedWidth(SCRO_WIDTH); m_secuPageScrollArea->setFrameShape(QFrame::NoFrame); m_secuPageScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_secuPageScrollArea->setWidget(securityPage); + + m_secuPageScrollArea->setWidgetResizable(true); + + m_ipv4ScrollArea = new QScrollArea(centerWidget); + m_ipv4ScrollArea->setFixedWidth(SCRO_WIDTH); + m_ipv4ScrollArea->setFrameShape(QFrame::NoFrame); + m_ipv4ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_ipv4ScrollArea->setWidget(ipv4Page); + m_ipv4ScrollArea->setWidgetResizable(true); + + m_ipv6ScrollArea = new QScrollArea(centerWidget); + m_ipv6ScrollArea->setFixedWidth(SCRO_WIDTH); + m_ipv6ScrollArea->setFrameShape(QFrame::NoFrame); + m_ipv6ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_ipv6ScrollArea->setWidget(ipv6Page); + m_ipv6ScrollArea->setWidgetResizable(true); + QPalette pal = m_secuPageScrollArea->palette(); pal.setBrush(QPalette::Base, QColor(0,0,0,0)); m_secuPageScrollArea->setPalette(pal); + m_ipv4ScrollArea->setPalette(pal); + m_ipv6ScrollArea->setPalette(pal); - detailPage->setFixedWidth(SCRO_WIDTH); - ipv4Page->setFixedWidth(SCRO_WIDTH); - ipv6Page->setFixedWidth(SCRO_WIDTH); - createNetPage->setFixedWidth(SCRO_WIDTH); - configPage->setFixedWidth(SCRO_WIDTH); stackWidget = new QStackedWidget(centerWidget); stackWidget->addWidget(detailPage); - stackWidget->addWidget(ipv4Page); - stackWidget->addWidget(ipv6Page); + stackWidget->addWidget(m_ipv4ScrollArea); + stackWidget->addWidget(m_ipv6ScrollArea); stackWidget->addWidget(m_secuPageScrollArea); stackWidget->addWidget(configPage); stackWidget->addWidget(createNetPage); - mainLayout->addWidget(centerWidget); - mainLayout->addWidget(bottomWidget); - - bottomWidget->setMinimumHeight(PAGE_MIN_HEIGHT); - - pageFrame = new QFrame(this); - QHBoxLayout *pageLayout = new QHBoxLayout(pageFrame); -// pageLayout->setSpacing(PAGE_LAYOUT_SPACING); - // TabBar onPaletteChanged(); m_networkMode = NetworkModeType(NetworkModeConfig::getInstance()->getNetworkModeConfig(m_uuid)); @@ -351,9 +364,6 @@ void NetDetail::initUI() } } - pageLayout->addWidget(m_netTabBar, Qt::AlignCenter); - pageLayout->addSpacing(24); - // TabBar关联选项卡页面 connect(m_netTabBar, SIGNAL(currentChanged(int)), this, SLOT(currentRowChangeSlot(int))); setNetTabToolTip(); @@ -366,10 +376,12 @@ void NetDetail::initUI() forgetBtn = new QPushButton(this); + QHBoxLayout *pageLayout = new QHBoxLayout(pageFrame); + pageLayout->setContentsMargins(0, 0, 0, 0); + pageLayout->addWidget(m_netTabBar, Qt::AlignCenter); + QVBoxLayout *centerlayout = new QVBoxLayout(centerWidget); centerlayout->setContentsMargins(CENTER_LAYOUT_MARGINS); // 右边距为0,为安全页滚动区域留出空间 - centerlayout->addWidget(pageFrame); - centerlayout->addSpacing(4); centerlayout->addWidget(stackWidget); QHBoxLayout *bottomLayout = new QHBoxLayout(bottomWidget); @@ -379,11 +391,13 @@ void NetDetail::initUI() bottomLayout->addStretch(); bottomLayout->addWidget(cancelBtn); bottomLayout->addWidget(confimBtn); + bottomWidget->setMinimumHeight(PAGE_MIN_HEIGHT); + + mainLayout->addWidget(pageFrame); + mainLayout->addWidget(centerWidget); + mainLayout->addWidget(bottomWidget); -// QPalette pal(this->palette()); -// pal.setColor(QPalette::Background, qApp->palette().base().color()); this->setAutoFillBackground(true); -// this->setPalette(pal); } void NetDetail::loadPage() @@ -446,13 +460,6 @@ void NetDetail::initComponent() setConfirmEnable(); }); - connect(securityPage, &SecurityPage::secuTypeChanged, this, [=]() { - setSecuPageHeight(); - }); - connect(securityPage, &SecurityPage::eapTypeChanged, this, [=]() { - setSecuPageHeight(); - }); - const QByteArray id(THEME_SCHAME); if(QGSettings::isSchemaInstalled(id)){ QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); @@ -746,22 +753,6 @@ void NetDetail::initSecuData() } } -void NetDetail::setSecuPageHeight() -{ - KySecuType secuType; - KyEapMethodType eapType; - securityPage->getSecuType(secuType, eapType); - if (secuType == WPA_AND_WPA2_ENTERPRISE) { - if (eapType == TLS) { - securityPage->setFixedSize(SCRO_WIDTH, TLS_SCRO_HEIGHT); - } else { - securityPage->setFixedSize(SCRO_WIDTH, PEAP_SCRO_HEIGHT); - } - } else { - securityPage->setFixedSize(SCRO_WIDTH, PEAP_SCRO_HEIGHT); - } -} - void NetDetail::initTlsInfo(ConInfo &conInfo) { m_resource->getEnterPriseInfoTls(m_uuid, conInfo.tlsInfo); @@ -1215,13 +1206,17 @@ NetTabBar::~NetTabBar() QSize NetTabBar::sizeHint() const { - return QSize(TAB_WIDTH, TAB_HEIGHT); + QSize size = KTabBar::sizeHint(); + size.setWidth(TAB_WIDTH); + return size; } QSize NetTabBar::minimumTabSizeHint(int index) const { Q_UNUSED(index) - return QSize(TAB_WIDTH, TAB_HEIGHT); + QSize size = KTabBar::minimumTabSizeHint(index); + size.setWidth(TAB_WIDTH); + return size; } diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index 13391dfb..1bdaadd4 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -57,6 +57,7 @@ using namespace kdk; #define TAB_WIDTH 60 #define TAB_HEIGHT 36 +#define TAB_HEIGHT_TABLET 48 class NetTabBar : public KTabBar { @@ -64,7 +65,7 @@ class NetTabBar : public KTabBar public: explicit NetTabBar(QWidget *parent = nullptr); ~NetTabBar(); - +protected: QSize sizeHint() const; QSize minimumTabSizeHint(int index) const; }; @@ -109,7 +110,6 @@ private: void loadPage(); void pagePadding(QString netName, bool isWlan); void initSecuData(); - void setSecuPageHeight(); void initTlsInfo(ConInfo &conInfo); void initPeapInfo(ConInfo &conInfo); @@ -166,6 +166,8 @@ private: QWidget * centerWidget; QWidget * bottomWidget; QScrollArea * m_secuPageScrollArea; + QScrollArea * m_ipv4ScrollArea; + QScrollArea * m_ipv6ScrollArea; QPushButton * cancelBtn; QPushButton * forgetBtn; diff --git a/src/frontend/netdetails/securitypage.cpp b/src/frontend/netdetails/securitypage.cpp index 82fabb95..182c06de 100644 --- a/src/frontend/netdetails/securitypage.cpp +++ b/src/frontend/netdetails/securitypage.cpp @@ -25,7 +25,7 @@ #define DETAIL_MIN_LABEL_WIDTH 80 #define DETAIL_MIN_EDIT_WIDTH 390 #define MIN_LABEL_WIDTH 146 -#define MIN_EDIT_WIDTH 278 +#define MIN_EDIT_WIDTH 286 SecurityPage::SecurityPage(bool isNetDetailPage, QWidget *parent) : isDetailPage(isNetDetailPage), QFrame(parent) { @@ -84,14 +84,6 @@ void SecurityPage::initUI() userPwdEdit->setUseCustomPalette(true); userPwdFlagBox = new QCheckBox(this); - //FAST - m_pacCheckBox = new QCheckBox(this); - m_pacProvisionComboBox = new QComboBox(this); - m_pacFilePathComboBox = new QComboBox(this); - m_pacProvisionLabel = new FixLabel(this); - m_pacFlagLabel = new FixLabel(this); - m_pacFileLabel = new QLabel(this); - QWidget *queryWidget = new QWidget(this); QHBoxLayout *queryLayout = new QHBoxLayout(queryWidget); queryLayout->setContentsMargins(0, 0, 0, 0); @@ -99,6 +91,15 @@ void SecurityPage::initUI() queryLayout->addWidget(userPwdFlagLabel); queryLayout->addStretch(); + //FAST + m_pacCheckBox = new QCheckBox(this); + m_pacProvisionComboBox = new QComboBox(this); + m_pacFilePathComboBox = new QComboBox(this); + m_pacProvisionLabel = new FixLabel(this); + m_pacProvisionLabel->setFixedWidth(MIN_LABEL_WIDTH); + m_pacFlagLabel = new FixLabel(this); + m_pacFileLabel = new QLabel(this); + //记住该网络复选框 m_emptyLabel = new QLabel(this); m_emptyLabel->setMinimumWidth(MIN_LABEL_WIDTH - 8); @@ -114,22 +115,15 @@ void SecurityPage::initUI() rememberLayout->addWidget(m_checkLabel); rememberLayout->addStretch(); - // mSecuLayout = new QFormLayout(this); - // mSecuLayout->setContentsMargins(0, 0, 0, 0); - // mSecuLayout->addRow(secuTypeLabel, secuTypeCombox); - // mSecuLayout->addRow(pwdLabel, pwdEdit); - // mSecuLayout->addRow(eapTypeLabel, eapTypeCombox); - // mSecuLayout->addRow(identityLable, identityEdit); - // mSecuLayout->addRow(domainLable, domainEdit); - // mSecuLayout->addRow(caCertPathLabel, caCertPathCombox); - // mSecuLayout->addRow(caNeedBox, caNeedFlagLabel); - // mSecuLayout->addRow(clientCertPathLabel, clientCertPathCombox); - // mSecuLayout->addRow(clientPrivateKeyLabel, clientPrivateKeyCombox); - // mSecuLayout->addRow(clientPrivateKeyPwdLabel,clientPrivateKeyPwdEdit); - // mSecuLayout->addRow(eapMethodLabel, eapMethodCombox); - // mSecuLayout->addRow(userNameLabel, userNameEdit); - // mSecuLayout->addRow(userPwdLabel, userPwdEdit); - // mSecuLayout->addRow(userPwdFlagBox, userPwdFlagLabel); + //允许自动PAC配置复选框 + m_pacCheckWidget = new QWidget(this); + QGridLayout *pacCheckLayout = new QGridLayout(m_pacCheckWidget); + pacCheckLayout->setContentsMargins(0, 0, 0, 0); + pacCheckLayout->setVerticalSpacing(0); + pacCheckLayout->setColumnMinimumWidth(0, 16); + pacCheckLayout->addWidget(m_pacProvisionComboBox, 0, 0, 1, 2); + pacCheckLayout->addWidget(m_pacCheckBox, 1, 0); + pacCheckLayout->addWidget(m_pacFlagLabel, 1, 1); topLayout = new QGridLayout(); topLayout->setContentsMargins(0, 0, 0, 0); @@ -143,27 +137,24 @@ void SecurityPage::initUI() // EAP认证 Label和选项框 第2行,第0列,第1列 topLayout->addWidget(eapTypeLabel, 2, 0); topLayout->addWidget(eapTypeCombox, 2, 1); - // EAP认证 Label和选项框 第3行,第0列,第1列 - topLayout->addWidget(m_pacProvisionLabel, 3, 0); - topLayout->addWidget(m_pacProvisionComboBox, 3, 1); - // pac CheckBox和Label 第4行,第0列,第1列 - topLayout->addWidget(m_pacCheckBox, 4, 0); - topLayout->addWidget(m_pacFlagLabel, 4, 1); - // EAP认证 Label和选项框 第5行,第0列,第1列 - topLayout->addWidget(m_pacFileLabel, 5, 0); - topLayout->addWidget(m_pacFilePathComboBox, 5, 1); - //内部认证 Label和选项框 第6行,第0列,第1列 - topLayout->addWidget(eapMethodLabel, 6, 0); - topLayout->addWidget(eapMethodCombox, 6, 1); - //用户名 Label和输入框 第7行,第0列,第1列 - topLayout->addWidget(userNameLabel, 7, 0); - topLayout->addWidget(userNameEdit, 7, 1); - //密码 Label和密码框 第8行,第0列,第1列 - topLayout->addWidget(userPwdLabel, 8, 0); - topLayout->addWidget(userPwdEdit, 8, 1); - // 匿名身份 Label和输入框 第9行,第0列,第1列 - topLayout->addWidget(identityLable, 9, 0); - topLayout->addWidget(identityEdit, 9, 1); + // 匿名身份 Label和输入框 第3行,第0列,第1列 + topLayout->addWidget(identityLable, 3, 0); + topLayout->addWidget(identityEdit, 3, 1); + //PAC配置 允许自动PAC配置 第4行,第0列;第4行,第1列,占2行1列 + topLayout->addWidget(m_pacProvisionLabel, 4, 0, Qt::AlignTop); + topLayout->addWidget(m_pacCheckWidget, 4, 1); + // PAC文件 + topLayout->addWidget(m_pacFileLabel, 6, 0); + topLayout->addWidget(m_pacFilePathComboBox, 6, 1); + //内部认证 Label和选项框 + topLayout->addWidget(eapMethodLabel, 7, 0); + topLayout->addWidget(eapMethodCombox, 7, 1); + //用户名 Label和输入框 + topLayout->addWidget(userNameLabel, 8, 0); + topLayout->addWidget(userNameEdit, 8, 1); + //密码 Label和密码框 + topLayout->addWidget(userPwdLabel, 9, 0); + topLayout->addWidget(userPwdEdit, 9, 1); // CA证书选项框及CheckBox布局 @@ -205,14 +196,16 @@ void SecurityPage::initUI() checkWidget->hide(); topLayout->addWidget(queryWidget, 10, 1); changeColumnWidthWithSecuType(); + m_pacFlagLabel->setMinimumWidth(MIN_EDIT_WIDTH); } else { queryWidget->hide(); topLayout->setColumnMinimumWidth(0, MIN_LABEL_WIDTH); topLayout->setColumnMinimumWidth(1, MIN_EDIT_WIDTH); bottomLayout->setColumnMinimumWidth(0, MIN_LABEL_WIDTH - 8); + m_pacFlagLabel->setMinimumWidth(MIN_EDIT_WIDTH - 36); } - topLayout->addWidget(tlsWidget, 7, 0, 6, 2); + topLayout->addWidget(tlsWidget, 10, 0, 6, 2); mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); @@ -268,18 +261,6 @@ void SecurityPage::initUI() clientPrivateKeyCombox->addItem(tr("None"), QString(tr("None"))); //无 clientPrivateKeyCombox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择... - //FAST - m_pacCheckBox->setChecked(true); - m_pacProvisionLabel->setText(tr("PAC provisioning")); //PAC配置 - m_pacFlagLabel->setText(tr("Allow automatic PAC provisioning")); //允许自动PAC配置 - m_pacFileLabel->setText(tr("PAC file")); //PAC文件 - m_pacProvisionComboBox->addItem(tr("Anonymous"), ANON); //匿名 - m_pacProvisionComboBox->addItem(tr("Authenticated"), AUTHEN); //已认证 - m_pacProvisionComboBox->addItem(tr("Both"), BOTH); //两者兼用 - m_pacProvisionComboBox->setCurrentIndex(ANON); - m_pacFilePathComboBox->addItem(tr("None"), QString(tr("None"))); //无 - m_pacFilePathComboBox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择... - //仅为该用户存储密码 pwdOptionCombox->addItem(tr("Store passwords only for this user"), QString(tr("Store password only for this user"))); //存储所有用户的密码 @@ -288,6 +269,18 @@ void SecurityPage::initUI() pwdOptionCombox->addItem(tr("Ask this password every time"), QString(tr("Ask password every time"))); pwdOptionCombox->setCurrentIndex(1); + //FAST + m_pacCheckBox->setChecked(true); + m_pacProvisionLabel->setLabelText(tr("PAC provisioning")); //PAC配置 + m_pacFlagLabel->setLabelText(tr("Allow automatic PAC provisioning")); //允许自动PAC配置 + m_pacFileLabel->setText(tr("PAC file")); //PAC文件 + m_pacProvisionComboBox->addItem(tr("Anonymous"), ANON); //匿名 + m_pacProvisionComboBox->addItem(tr("Authenticated"), AUTHEN); //已认证 + m_pacProvisionComboBox->addItem(tr("Both"), BOTH); //两者兼用 + m_pacProvisionComboBox->setCurrentIndex(ANON); + m_pacFilePathComboBox->addItem(tr("None"), QString(tr("None"))); //无 + m_pacFilePathComboBox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择... + //禁用ClearBtn按钮 pwdEdit->setClearButtonEnabled(false); clientPrivateKeyPwdEdit->setClearButtonEnabled(false); @@ -305,13 +298,13 @@ void SecurityPage::initUI() void SecurityPage::initConnect() { //安全类型变化 - // connect(secuTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onSecuTypeComboxIndexChanged); +// connect(secuTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onSecuTypeComboxIndexChanged); connect(secuTypeCombox, QOverload::of(&QComboBox::currentIndexChanged), this, &SecurityPage::onSecuTypeComboxIndexChanged); connect(secuTypeCombox, QOverload::of(&QComboBox::currentIndexChanged), this, &SecurityPage::changeColumnWidthWithSecuType); //EAP方式变化 - // connect(eapTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onEapTypeComboxIndexChanged); +// connect(eapTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onEapTypeComboxIndexChanged); connect(eapTypeCombox, QOverload::of(&QComboBox::currentIndexChanged), this, &SecurityPage::onEapTypeComboxIndexChanged); connect(caNeedBox, &QCheckBox::clicked, this, &SecurityPage::onCaNeedBoxClicked); @@ -490,22 +483,28 @@ void SecurityPage::setFastInfo(KyEapMethodFastInfo &info) onEapTypeComboxIndexChanged(); identityEdit->setText(info.m_anonIdentity); - if (info.m_pacProvisioning == KyFastProvisioningAllowUnauthenticated) { + m_pacCheckBox->setChecked(false); + m_pacProvisionComboBox->setCurrentIndex(ANON); + if (info.m_pacProvisioning == KyFastProvisioningDisabled) { + m_pacCheckBox->setChecked(false); + m_pacProvisionComboBox->setCurrentIndex(ANON); + m_pacProvisionComboBox->setEnabled(false); + } else if (info.m_pacProvisioning == KyFastProvisioningAllowUnauthenticated) { m_pacProvisionComboBox->setCurrentIndex(ANON); } else if (info.m_pacProvisioning == KyFastProvisioningAllowAuthenticated) { m_pacProvisionComboBox->setCurrentIndex(AUTHEN); } else if (info.m_pacProvisioning == KyFastProvisioningAllowBoth) { m_pacProvisionComboBox->setCurrentIndex(BOTH); + } else { + qWarning() << "Unknown fastProvisioning type" << Q_FUNC_INFO << __LINE__; + m_pacCheckBox->setChecked(false); + m_pacProvisionComboBox->setEnabled(false); } if (info.m_pacFilePath.isEmpty()) { m_pacFilePathComboBox->setItemText(0, QString(tr("None"))); - m_pacCheckBox->setChecked(true); - m_pacFilePathComboBox->setEnabled(false); } else { m_pacFilePathComboBox->setItemText(0, info.m_pacFilePath); - m_pacCheckBox->setChecked(false); - m_pacFilePathComboBox->setEnabled(true); } if (info.m_authMethod == KyAuthMethodGtc) { @@ -611,7 +610,7 @@ bool SecurityPage::checkIsChanged(const ConInfo info) if (info.secType == NONE) { return false; } else if (info.secType == WPA_AND_WPA2_PERSONAL || info.secType == WPA3_PERSONAL) { - return !(info.strPassword == pwdEdit->text()); + return !(info.strPassword == pwdEdit->text()); } else { if (info.enterpriseType != eapTypeCombox->currentData().toInt()) { return true; @@ -659,12 +658,10 @@ void SecurityPage::showNone() userPwdFlagLabel->hide(); //FAST - m_pacCheckBox->hide(); - m_pacProvisionComboBox->hide(); - m_pacFilePathComboBox->hide(); m_pacProvisionLabel->hide(); - m_pacFlagLabel->hide(); + m_pacCheckWidget->hide(); m_pacFileLabel->hide(); + m_pacFilePathComboBox->hide(); } void SecurityPage::showPsk() @@ -692,12 +689,10 @@ void SecurityPage::showPsk() userPwdFlagLabel->hide(); //FAST - m_pacCheckBox->hide(); - m_pacProvisionComboBox->hide(); - m_pacFilePathComboBox->hide(); m_pacProvisionLabel->hide(); - m_pacFlagLabel->hide(); + m_pacCheckWidget->hide(); m_pacFileLabel->hide(); + m_pacFilePathComboBox->hide(); } void SecurityPage::showTls() @@ -724,12 +719,10 @@ void SecurityPage::showTls() userPwdFlagLabel->hide(); //FAST - m_pacCheckBox->hide(); - m_pacProvisionComboBox->hide(); - m_pacFilePathComboBox->hide(); m_pacProvisionLabel->hide(); - m_pacFlagLabel->hide(); + m_pacCheckWidget->hide(); m_pacFileLabel->hide(); + m_pacFilePathComboBox->hide(); } void SecurityPage::showPeapOrTtls() @@ -746,14 +739,6 @@ void SecurityPage::showPeapOrTtls() identityEdit->hide(); tlsWidget->hide(); - //FAST - m_pacCheckBox->hide(); - m_pacProvisionComboBox->hide(); - m_pacFilePathComboBox->hide(); - m_pacProvisionLabel->hide(); - m_pacFlagLabel->hide(); - m_pacFileLabel->hide(); - //PEAP TTLS共有 eapMethodLabel->show(); userNameLabel->show(); @@ -764,96 +749,74 @@ void SecurityPage::showPeapOrTtls() userNameEdit->show(); userPwdEdit->show(); userPwdFlagLabel->show(); + + //FAST + m_pacProvisionLabel->hide(); + m_pacCheckWidget->hide(); + m_pacFileLabel->hide(); + m_pacFilePathComboBox->hide(); } void SecurityPage::showLeapOrPwd() { - pwdEdit->hide(); - eapTypeCombox->show(); - - identityEdit->hide(); - domainEdit->hide(); - caCertPathCombox->hide(); - caNeedBox->hide(); - clientCertPathCombox->hide(); - clientPrivateKeyCombox->hide(); - clientPrivateKeyPwdEdit->hide(); - - eapMethodCombox->hide(); - userNameEdit->show(); - userPwdEdit->show(); - userPwdFlagBox->show(); - pwdLabel->hide(); + pwdEdit->hide(); + //企业wifi共有 eapTypeLabel->show(); + eapTypeCombox->show(); + //TLS identityLable->hide(); - domainLable->hide(); - caCertPathLabel->hide(); - caNeedFlagLabel->hide(); - clientCertPathLabel->hide(); - clientPrivateKeyLabel->hide(); - clientPrivateKeyPwdLabel->hide(); - - //PEAP TTLS共有 - eapMethodLabel->hide(); - userNameLabel->show(); - userPwdLabel->show(); - userPwdFlagLabel->show(); + identityEdit->hide(); + tlsWidget->hide(); //FAST - m_pacCheckBox->hide(); - m_pacProvisionComboBox->hide(); - m_pacFilePathComboBox->hide(); m_pacProvisionLabel->hide(); - m_pacFlagLabel->hide(); + m_pacCheckWidget->hide(); m_pacFileLabel->hide(); + m_pacFilePathComboBox->hide(); + + eapMethodLabel->hide(); + eapMethodCombox->hide(); + userPwdFlagBox->show(); + userPwdFlagLabel->show(); + + userNameLabel->show(); + userNameEdit->show(); + userPwdLabel->show(); + userPwdEdit->show(); } void SecurityPage::showFast() { - pwdEdit->hide(); - eapTypeCombox->show(); - - identityEdit->show(); - domainEdit->hide(); - caCertPathCombox->hide(); - caNeedBox->hide(); - clientCertPathCombox->hide(); - clientPrivateKeyCombox->hide(); - clientPrivateKeyPwdEdit->hide(); - - eapMethodCombox->show(); - userNameEdit->show(); - userPwdEdit->show(); - userPwdFlagBox->hide(); - pwdLabel->hide(); + pwdEdit->hide(); + //企业wifi共有 eapTypeLabel->show(); + eapTypeCombox->show(); + //TLS identityLable->show(); - domainLable->hide(); - caCertPathLabel->hide(); - caNeedFlagLabel->hide(); - clientCertPathLabel->hide(); - clientPrivateKeyLabel->hide(); - clientPrivateKeyPwdLabel->hide(); - - //PEAP TTLS共有 - eapMethodLabel->show(); - userNameLabel->show(); - userPwdLabel->show(); - userPwdFlagLabel->hide(); + identityEdit->show(); + tlsWidget->hide(); //FAST - m_pacCheckBox->show(); - m_pacProvisionComboBox->show(); - m_pacFilePathComboBox->show(); m_pacProvisionLabel->show(); - m_pacFlagLabel->show(); + m_pacCheckWidget->show(); m_pacFileLabel->show(); + m_pacFilePathComboBox->show(); + + eapMethodLabel->show(); + eapMethodCombox->show(); + userPwdFlagBox->show(); + userPwdFlagLabel->show(); + + userNameLabel->show(); + userNameEdit->show(); + userPwdLabel->show(); + userPwdEdit->show(); } KyEapMethodTlsInfo SecurityPage::assembleTlsInfo() @@ -885,7 +848,7 @@ KyEapMethodTlsInfo SecurityPage::assembleTlsInfo() KyEapMethodPeapInfo SecurityPage::assemblePeapInfo() { KyEapMethodPeapInfo info; - // info.phase2AuthMethod = (KyNoEapMethodAuth)eapMethodCombox->currentData().toInt(); +// info.phase2AuthMethod = (KyNoEapMethodAuth)eapMethodCombox->currentData().toInt(); switch (eapMethodCombox->currentIndex()) { case 0: info.phase2AuthMethod = KyAuthMethodMschapv2; @@ -967,37 +930,37 @@ KyEapMethodPwdInfo SecurityPage::assemblePwdInfo() KyEapMethodFastInfo SecurityPage::assembleFastInfo() { KyEapMethodFastInfo info; - info.m_anonIdentity = identityEdit->text(); - switch (m_pacProvisionComboBox->currentIndex()) { - case ANON: - info.m_pacProvisioning = KyFastProvisioningAllowUnauthenticated; - break; - case AUTHEN: - info.m_pacProvisioning = KyFastProvisioningAllowAuthenticated; - break; - case BOTH: - info.m_pacProvisioning = KyFastProvisioningAllowBoth; - break; - default: - break; - } - info.m_allowAutoPacFlag = m_pacCheckBox->isChecked(); - info.m_pacFilePath = m_pacFilePathComboBox->currentText(); + info.m_anonIdentity = identityEdit->text(); + switch (m_pacProvisionComboBox->currentIndex()) { + case ANON: + info.m_pacProvisioning = KyFastProvisioningAllowUnauthenticated; + break; + case AUTHEN: + info.m_pacProvisioning = KyFastProvisioningAllowAuthenticated; + break; + case BOTH: + info.m_pacProvisioning = KyFastProvisioningAllowBoth; + break; + default: + break; + } + info.m_allowAutoPacFlag = m_pacCheckBox->isChecked(); + info.m_pacFilePath = m_pacFilePathComboBox->currentText(); - switch (eapMethodCombox->currentIndex()) { - case GTC_FAST: - info.m_authMethod = KyAuthMethodGtc; - break; - case MSCHAPV2_FAST: - info.m_authMethod = KyAuthMethodMschapv2; - break; - default: - break; - } - info.m_userName = userNameEdit->text(); - info.m_userPwd = userPwdEdit->text(); - info.m_passwdFlag = (userPwdFlagBox->isChecked() ? NetworkManager::Setting::NotSaved : NetworkManager::Setting::None); - return info; + switch (eapMethodCombox->currentIndex()) { + case GTC_FAST: + info.m_authMethod = KyAuthMethodGtc; + break; + case MSCHAPV2_FAST: + info.m_authMethod = KyAuthMethodMschapv2; + break; + default: + break; + } + info.m_userName = userNameEdit->text(); + info.m_userPwd = userPwdEdit->text(); + info.m_passwdFlag = (userPwdFlagBox->isChecked() ? NetworkManager::Setting::NotSaved : NetworkManager::Setting::None); + return info; } void SecurityPage::updateSecurityChange(KyWirelessConnectSetting &setting) @@ -1064,13 +1027,11 @@ bool SecurityPage::checkConnectBtnIsEnabled() return false; } } else if (type == FAST) { - if (identityEdit->text().isEmpty()) { - qDebug() << "fast anonymous identity is empty"; - return false; - } if(!m_pacCheckBox->isChecked()) { - qDebug() << "Not allow automatic PAC provisioning "; - return false; + if (m_pacFilePathComboBox->currentText() == QString(tr("None"))) { + qDebug() << "Not allow automatic PAC provisioning && pac file is empty"; + return false; + } } if(userNameEdit->text().isEmpty() || userPwdEdit->text().isEmpty()) { qDebug() << "user name or user password is empty"; @@ -1233,6 +1194,39 @@ void SecurityPage::onClientPrivateKeyComboxIndexChanged(QString str) } } +void SecurityPage::onPwdOptionComboxIndexChanged(QString str) +{ + KyEapMethodTlsInfo info; + if (str.contains("Store passwords only for this user") || str.contains("仅为该用户存储密码")) { + info.m_privateKeyPWDFlag = NetworkManager::Setting::AgentOwned; + clientPrivateKeyPwdEdit->setPlaceholderText(emptyhint); + } else if (str.contains("Store passwords for all users") || str.contains("存储所有用户的密码")) { + info.m_privateKeyPWDFlag = NetworkManager::Setting::None; + clientPrivateKeyPwdEdit->setPlaceholderText(hintRequired); + } else { + info.m_privateKeyPWDFlag = NetworkManager::Setting::NotSaved; + clientPrivateKeyPwdEdit->setPlaceholderText(emptyhint); + } +} + +void SecurityPage::changeColumnWidthWithSecuType() +{ + if (!isDetailPage) { + return; + } + if (secuTypeCombox->currentData().toInt() == WPA_AND_WPA2_ENTERPRISE) { + if (eapMethodCombox->currentData().toInt() == TLS || eapMethodCombox->currentData().toInt() == FAST) { + topLayout->setColumnMinimumWidth(0, MIN_LABEL_WIDTH); + topLayout->setColumnMinimumWidth(1, MIN_EDIT_WIDTH); + bottomLayout->setColumnMinimumWidth(0, MIN_LABEL_WIDTH - 8); + + } + }else { + topLayout->setColumnMinimumWidth(0, DETAIL_MIN_LABEL_WIDTH); + topLayout->setColumnMinimumWidth(1, DETAIL_MIN_EDIT_WIDTH); + } +} + void SecurityPage::onPacFilePathComboxIndexChanged(QString str) { if (str.contains("Choose from file...") || str.contains("从文件选择...")) @@ -1256,35 +1250,3 @@ void SecurityPage::onPacFilePathComboxIndexChanged(QString str) } } -void SecurityPage::onPwdOptionComboxIndexChanged(QString str) -{ - KyEapMethodTlsInfo info; - if (str.contains("Store passwords only for this user") || str.contains("仅为该用户存储密码")) { - info.m_privateKeyPWDFlag = NetworkManager::Setting::AgentOwned; - clientPrivateKeyPwdEdit->setPlaceholderText(emptyhint); - } else if (str.contains("Store passwords for all users") || str.contains("存储所有用户的密码")) { - info.m_privateKeyPWDFlag = NetworkManager::Setting::None; - clientPrivateKeyPwdEdit->setPlaceholderText(hintRequired); - } else { - info.m_privateKeyPWDFlag = NetworkManager::Setting::NotSaved; - clientPrivateKeyPwdEdit->setPlaceholderText(emptyhint); - } -} - -void SecurityPage::changeColumnWidthWithSecuType() -{ - if (!isDetailPage) { - return; - } - if (secuTypeCombox->currentData().toInt() == WPA_AND_WPA2_ENTERPRISE && - eapMethodCombox->currentData().toInt() == TLS) { - topLayout->setColumnMinimumWidth(0, MIN_LABEL_WIDTH); - topLayout->setColumnMinimumWidth(1, MIN_EDIT_WIDTH); - bottomLayout->setColumnMinimumWidth(0, MIN_LABEL_WIDTH - 8); - - } else { - topLayout->setColumnMinimumWidth(0, DETAIL_MIN_LABEL_WIDTH); - topLayout->setColumnMinimumWidth(1, DETAIL_MIN_EDIT_WIDTH); - } -} - From fa5d3ab630a124102601edbe650cb0d686f9bb5e Mon Sep 17 00:00:00 2001 From: chenxuechao Date: Mon, 10 Apr 2023 15:50:59 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E6=96=B0=E5=A2=9EVPN=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E9=87=8D=E6=96=B0=E6=8F=90=E4=BA=A4?= =?UTF-8?q?PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kylin-nm.pro | 10 +- plugins/plugin.pro | 3 +- plugins/vpn/itemframe.cpp | 63 + plugins/vpn/itemframe.h | 47 + plugins/vpn/translations/zh_CN.ts | 80 + plugins/vpn/vpn.cpp | 502 ++++++ plugins/vpn/vpn.h | 120 ++ plugins/vpn/vpn.pro | 50 + plugins/vpn/vpn.ui | 112 ++ plugins/vpn/vpnitem.cpp | 187 ++ plugins/vpn/vpnitem.h | 87 + src-vpn/backend/backend.pri | 10 + src-vpn/backend/vpndbusadaptor.cpp | 78 + src-vpn/backend/vpndbusadaptor.h | 64 + src-vpn/frontend/frontend.pri | 11 + src-vpn/frontend/list-items/list-items.pri | 10 + src-vpn/frontend/list-items/listitem.cpp | 151 ++ src-vpn/frontend/list-items/listitem.h | 87 + src-vpn/frontend/list-items/vpnlistitem.cpp | 248 +++ src-vpn/frontend/list-items/vpnlistitem.h | 88 + .../frontend/single-pages/single-pages.pri | 10 + src-vpn/frontend/single-pages/singlepage.cpp | 185 ++ src-vpn/frontend/single-pages/singlepage.h | 112 ++ src-vpn/frontend/single-pages/vpnpage.cpp | 702 ++++++++ src-vpn/frontend/single-pages/vpnpage.h | 137 ++ src-vpn/frontend/vpnobject.cpp | 138 ++ src-vpn/frontend/vpnobject.h | 75 + src-vpn/kylin-vpn.desktop | 18 + src-vpn/main.cpp | 137 ++ src-vpn/org.ukui.kylin-vpn.switch.gschema.xml | 9 + src-vpn/singleapplication/qt-local-peer.cpp | 205 +++ src-vpn/singleapplication/qt-local-peer.h | 80 + .../singleapplication/qt-locked-file-unix.cpp | 113 ++ src-vpn/singleapplication/qt-locked-file.cpp | 189 ++ src-vpn/singleapplication/qt-locked-file.h | 97 ++ .../qt-single-application.cpp | 351 ++++ .../singleapplication/qt-single-application.h | 109 ++ .../qt-single-application.pri | 27 + src-vpn/src-vpn.pro | 73 + src-vpn/translations/kylin-vpn_bo_CN.ts | 147 ++ src-vpn/translations/kylin-vpn_zh_CN.ts | 838 +++++++++ src-vpn/vpnqrc.qrc | 6 + src/backend/dbus-interface/dbus-interface.pri | 2 + .../dbus-interface/kylinconnectresource.cpp | 109 ++ .../dbus-interface/kylinconnectresource.h | 2 + .../kylinwiredconnectoperation.cpp | 55 - .../kylinwiredconnectoperation.h | 1 - .../dbus-interface/kyvpnconnectoperation.cpp | 1530 +++++++++++++++++ .../dbus-interface/kyvpnconnectoperation.h | 515 ++++++ 49 files changed, 7919 insertions(+), 61 deletions(-) create mode 100644 plugins/vpn/itemframe.cpp create mode 100644 plugins/vpn/itemframe.h create mode 100644 plugins/vpn/translations/zh_CN.ts create mode 100644 plugins/vpn/vpn.cpp create mode 100644 plugins/vpn/vpn.h create mode 100644 plugins/vpn/vpn.pro create mode 100644 plugins/vpn/vpn.ui create mode 100644 plugins/vpn/vpnitem.cpp create mode 100644 plugins/vpn/vpnitem.h create mode 100644 src-vpn/backend/backend.pri create mode 100644 src-vpn/backend/vpndbusadaptor.cpp create mode 100644 src-vpn/backend/vpndbusadaptor.h create mode 100644 src-vpn/frontend/frontend.pri create mode 100644 src-vpn/frontend/list-items/list-items.pri create mode 100644 src-vpn/frontend/list-items/listitem.cpp create mode 100644 src-vpn/frontend/list-items/listitem.h create mode 100644 src-vpn/frontend/list-items/vpnlistitem.cpp create mode 100644 src-vpn/frontend/list-items/vpnlistitem.h create mode 100644 src-vpn/frontend/single-pages/single-pages.pri create mode 100644 src-vpn/frontend/single-pages/singlepage.cpp create mode 100644 src-vpn/frontend/single-pages/singlepage.h create mode 100644 src-vpn/frontend/single-pages/vpnpage.cpp create mode 100644 src-vpn/frontend/single-pages/vpnpage.h create mode 100644 src-vpn/frontend/vpnobject.cpp create mode 100644 src-vpn/frontend/vpnobject.h create mode 100644 src-vpn/kylin-vpn.desktop create mode 100644 src-vpn/main.cpp create mode 100644 src-vpn/org.ukui.kylin-vpn.switch.gschema.xml create mode 100644 src-vpn/singleapplication/qt-local-peer.cpp create mode 100644 src-vpn/singleapplication/qt-local-peer.h create mode 100644 src-vpn/singleapplication/qt-locked-file-unix.cpp create mode 100644 src-vpn/singleapplication/qt-locked-file.cpp create mode 100644 src-vpn/singleapplication/qt-locked-file.h create mode 100644 src-vpn/singleapplication/qt-single-application.cpp create mode 100644 src-vpn/singleapplication/qt-single-application.h create mode 100644 src-vpn/singleapplication/qt-single-application.pri create mode 100644 src-vpn/src-vpn.pro create mode 100644 src-vpn/translations/kylin-vpn_bo_CN.ts create mode 100644 src-vpn/translations/kylin-vpn_zh_CN.ts create mode 100644 src-vpn/vpnqrc.qrc create mode 100644 src/backend/dbus-interface/kyvpnconnectoperation.cpp create mode 100644 src/backend/dbus-interface/kyvpnconnectoperation.h diff --git a/kylin-nm.pro b/kylin-nm.pro index 1f13a7c2..eaf4ac69 100644 --- a/kylin-nm.pro +++ b/kylin-nm.pro @@ -1,11 +1,13 @@ TEMPLATE = subdirs -CONFIG += ordered \ - qt +CONFIG += \ + ordered \ + qt SUBDIRS = \ - plugins/plugin.pro \ - src \ + plugins/plugin.pro \ + src-vpn/src-vpn.pro \ + src TRANSLATIONS += \ translations/kylin-nm_zh_CN.ts \ diff --git a/plugins/plugin.pro b/plugins/plugin.pro index cee11d57..1ef03f43 100644 --- a/plugins/plugin.pro +++ b/plugins/plugin.pro @@ -3,4 +3,5 @@ SUBDIRS = \ netconnect \ wlanconnect \ mobilehotspot \ - proxy + proxy \ + vpn diff --git a/plugins/vpn/itemframe.cpp b/plugins/vpn/itemframe.cpp new file mode 100644 index 00000000..29b6bf9c --- /dev/null +++ b/plugins/vpn/itemframe.cpp @@ -0,0 +1,63 @@ +/* -*- 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 "itemframe.h" +#include + +#define LAYOUT_MARGINS 0,0,0,0 +#define MAIN_LAYOUT_MARGINS 0,0,0,0 +ItemFrame::ItemFrame(QWidget *parent) + :QFrame(parent) +{ + m_mainVLayout = new QVBoxLayout(this); + m_mainVLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); + m_vpnFrame = new QFrame(this); + m_vpnFrame->setFrameShape(QFrame::Shape::NoFrame); + m_vpnFrame->setContentsMargins(LAYOUT_MARGINS); + + m_vpnVLayout = new QVBoxLayout(this); + m_vpnVLayout->setContentsMargins(LAYOUT_MARGINS); + m_vpnVLayout->setSpacing(1); + m_addVpnWidget = new AddNetBtn(false, this); + m_addVpnWidget->setTextLabel(tr("Add Vpn")); + + m_mainVLayout->setSpacing(1); + setLayout(m_mainVLayout); + m_vpnFrame->setLayout(m_vpnVLayout); + + m_mainVLayout->addWidget(m_vpnFrame); + m_mainVLayout->addWidget(m_addVpnWidget); +} + +void ItemFrame::filletStyleChange() +{ + if (m_vpnVLayout->isEmpty()) { + return; + } + + for (int i = 0; i < m_vpnVLayout->count(); ++i) { + QLayoutItem *it = m_vpnVLayout->itemAt(i); + VpnItem *itemFrame = (VpnItem*)(it->widget()); + if (i != m_vpnVLayout->count()-1) { + itemFrame->setHalfFillet(false); + } else { + itemFrame->setHalfFillet(true); + } + } +} diff --git a/plugins/vpn/itemframe.h b/plugins/vpn/itemframe.h new file mode 100644 index 00000000..18595863 --- /dev/null +++ b/plugins/vpn/itemframe.h @@ -0,0 +1,47 @@ +/* -*- 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 ITEMFRAME_H +#define ITEMFRAME_H +#include +#include +#include "../component/AddBtn/addnetbtn.h" +#include "vpnitem.h" + +class ItemFrame : public QFrame +{ + Q_OBJECT +public: + ItemFrame(QWidget *parent = nullptr); + //VPN整体layout + QVBoxLayout * m_mainVLayout = nullptr; + //vpn列表Frame + QFrame * m_vpnFrame = nullptr; + //单设备列表layout + QVBoxLayout * m_vpnVLayout = nullptr; + //item列表 + QMap m_itemMap; +// //已激活uuid +// QString uuid = ""; + //新建无线连接 + AddNetBtn * m_addVpnWidget = nullptr; + void filletStyleChange(); +}; + +#endif // ITEMFRAME_H diff --git a/plugins/vpn/translations/zh_CN.ts b/plugins/vpn/translations/zh_CN.ts new file mode 100644 index 00000000..ed7ce029 --- /dev/null +++ b/plugins/vpn/translations/zh_CN.ts @@ -0,0 +1,80 @@ + + + + + AddNetBtn + + + Add Others + + + + + Add WiredNetork + + + + + ItemFrame + + + Add Vpn + 添加VPN + + + + Vpn + + + VPN + + + + + import + + + + + Vpn + + + + + Show on Taskbar + 在任务栏显示图标 + + + + + connected + 已连接 + + + + + not connected + 未连接 + + + + VpnItem + + + Delete + 删除 + + + + + Disconnect + 断开 + + + + + Connect + 连接 + + + diff --git a/plugins/vpn/vpn.cpp b/plugins/vpn/vpn.cpp new file mode 100644 index 00000000..a453263d --- /dev/null +++ b/plugins/vpn/vpn.cpp @@ -0,0 +1,502 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2019 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 "vpn.h" +#include "ui_vpn.h" + +#include +#include +#include +#include +#include + +#define ACTIVATING 1 +#define ACTIVATED 2 +#define DEACTIVATING 3 +#define DEACTIVATED 4 + +#define LABEL_RECT 17, 0, 105, 23 +#define CONTENTS_MARGINS 0, 0, 0, 0 +#define ITEM_MARGINS 16, 0, 16, 0 +#define FRAME_MIN_SIZE 550, 60 +#define FRAME_MAX_SIZE 16777215, 16777215 +#define CONTECT_FRAME_MAX_SIZE 16777215, 60 +#define HINT_TEXT_MARGINS 8, 0, 0, 0 +#define FRAME_MIN_SIZE 550, 60 +#define LABLE_MIN_WIDTH 188 +#define COMBOBOX_MIN_WIDTH 200 +#define LINE_MAX_SIZE 16777215, 1 +#define LINE_MIN_SIZE 0, 1 +#define ICON_SIZE 24,24 +#define PASSWORD_FRAME_MIN_HIGHT 60 +#define PASSWORD_FRAME_FIX_HIGHT 80 +#define PASSWORD_FRAME_MIN_SIZE 550, 60 +#define PASSWORD_FRAME_MAX_SIZE 16777215, 86 +#define PASSWORD_ITEM_MARGINS 16, 12, 16, 14 + +#define KVpnSymbolic "ukui-vpn-symbolic" + +#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" +#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" +#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" + +const QString VISIBLE = "visible"; +const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.vpnicon"; + +Vpn::Vpn() : m_firstLoad(true) +{ + QTranslator* translator = new QTranslator(this); + translator->load("/usr/share/kylin-nm/vpn/" + QLocale::system().name()); + QApplication::installTranslator(translator); + + m_pluginName = tr("Vpn"); + m_pluginType = NETWORK; +} + +Vpn::~Vpn() +{ + if (!m_firstLoad) { + delete ui; + ui = nullptr; + delete m_interface; + delete m_switchGsettings; + } +} + +QString Vpn::plugini18nName(){ + return m_pluginName; +} + +int Vpn::pluginTypes(){ + return m_pluginType; +} + +QWidget *Vpn::pluginUi(){ + if (m_firstLoad) { + m_firstLoad = false; + ui = new Ui::Vpn; + m_pluginWidget = new QWidget; + m_pluginWidget->setAttribute(Qt::WA_DeleteOnClose); + ui->setupUi(m_pluginWidget); + + qDBusRegisterMetaType>(); + m_interface = new QDBusInterface("com.kylin.kylinvpn", + "/com/kylin/kylinvpn", + "com.kylin.kylinvpn", + QDBusConnection::sessionBus()); + if(!m_interface->isValid()) { + qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); + } + + initComponent(); + initConnect(); + initNet(); + } + return m_pluginWidget; +} + +const QString Vpn::name() const { + + return QStringLiteral("Vpn"); +} + +bool Vpn::isShowOnHomePage() const +{ + return true; +} + +QIcon Vpn::icon() const +{ + return QIcon::fromTheme("ukui-vpn-symbolic"); +} + +bool Vpn::isEnable() const +{ + return true; +} + +void Vpn::initComponent(){ + //在任务栏上显示图标 + //显示已连接时间 + m_topFrame = new QFrame(m_pluginWidget); + m_topFrame->setMinimumSize(FRAME_MIN_SIZE); + m_topFrame->setMaximumSize(FRAME_MAX_SIZE); + m_topFrame->setFrameShape(QFrame::Box); + + QVBoxLayout *hotspotLyt = new QVBoxLayout(m_pluginWidget); + hotspotLyt->setContentsMargins(0, 0, 0, 0); + m_topFrame->setLayout(hotspotLyt); + + m_showFrame = new QFrame(m_topFrame); + m_showFrame->setFrameShape(QFrame::Shape::NoFrame); + m_showFrame->setMinimumSize(FRAME_MIN_SIZE); + m_showFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE); + QHBoxLayout *showLayout = new QHBoxLayout(m_showFrame); + m_showLabel = new QLabel(tr("Show on Taskbar"), m_showFrame); + m_showLabel->setMinimumWidth(LABLE_MIN_WIDTH); + m_showBtn = new KSwitchButton(m_showFrame); + showLayout->setContentsMargins(ITEM_MARGINS); + showLayout->addWidget(m_showLabel); + showLayout->addStretch(); + showLayout->addWidget(m_showBtn); + + m_showFrame->setLayout(showLayout); + +// m_Line = myLine(); + +// m_timeFrame = new QFrame(m_topFrame); +// m_timeFrame->setFrameShape(QFrame::Shape::NoFrame); +// m_timeFrame->setMinimumSize(FRAME_MIN_SIZE); +// m_timeFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE); +// QHBoxLayout *timeLayout = new QHBoxLayout(m_timeFrame); +// m_timeLabel = new QLabel(tr("Open"), m_timeFrame); +// m_timeLabel->setMinimumWidth(LABLE_MIN_WIDTH); +// m_timeBtn = new KSwitchButton(m_timeFrame); +// timeLayout->setContentsMargins(ITEM_MARGINS); +// timeLayout->addWidget(m_timeLabel); +// timeLayout->addStretch(); +// timeLayout->addWidget(m_timeBtn); + +// m_timeFrame->setLayout(timeLayout); + + hotspotLyt->addWidget(m_showFrame); +// hotspotLyt->addWidget(m_Line); +// hotspotLyt->addWidget(m_timeFrame); + hotspotLyt->setSpacing(0); + + //列表 + m_listFrame = new ItemFrame(m_pluginWidget); + + ui->verticalLayout_4->addWidget(m_topFrame); + ui->verticalLayout_3->addWidget(m_listFrame); + + connect(m_listFrame->m_addVpnWidget, &AddNetBtn::clicked, this, [=]() { + runExternalApp(); + }); + + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { + m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); + setShowSwitchStatus(); + + connect(m_switchGsettings, &QGSettings::changed, this, [=] (const QString &key) { + if (key == VISIBLE) { + setShowSwitchStatus(); + } + }); + } else { + m_showBtn->setChecked(false); + m_showBtn->setCheckable(false); + qDebug()<<"[Vpn] org.ukui.kylin-nm.visible is not installed!"; + } + + connect(m_showBtn, &KSwitchButton::stateChanged, this, [=](bool state){ + if (m_switchGsettings != nullptr) { + m_switchGsettings->set(VISIBLE, state); + } + }); + +// connect(m_timeBtn, &KSwitchButton::stateChanged, this, [=](bool state){ +// if (m_switchGsettings != nullptr) { +// m_switchGsettings->set(VISIBLE, state); +// } +// }); + ui->pushButton->hide(); +} + +void Vpn::initConnect() +{ + connect(m_interface, SIGNAL(vpnAdd(QStringList)), this, SLOT(onVpnAdd(QStringList))); + connect(m_interface, SIGNAL(vpnRemove(QString)), this, SLOT(onVpnRemove(QString))); + connect(m_interface, SIGNAL(vpnUpdate(QStringList)), this, SLOT(onVpnUpdate(QStringList))); + connect(m_interface, SIGNAL(vpnActiveConnectionStateChanged(QString, int)), + this, SLOT(onVpnActiveConnectionStateChanged(QString, int))); +} + +//初始化列表 +void Vpn::initNet() +{ + qDebug() << "[Vpn]initNet"; + if (!m_interface->isValid()) { + return; + } + QDBusMessage result = m_interface->call(QStringLiteral("getVirtualList")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getVirtualList error:" << result.errorMessage(); + return; + } + auto dbusArg = result.arguments().at(0).value(); + QVector variantList; + dbusArg >> variantList; + if (variantList.size() == 0) { + qDebug() << "[Vpn]initNet list empty"; + return; + } + + for (int i = 0; i < variantList.size(); ++i) { + QStringList vpnInfo = variantList.at(i); + addOneVirtualItem(vpnInfo); + } + return; +} + +void Vpn::setShowSwitchStatus() +{ + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { + bool status = m_switchGsettings->get(VISIBLE).toBool(); + m_showBtn->setChecked(status); + } else { + qDebug()<<"[Vpn] org.ukui.kylin-nm.switch is not installed!"; + } +} + +void Vpn::runExternalApp(){ +// QString cmd = "nm-connection-editor"; +// QProcess process(this); +// process.startDetached(cmd); + + if (m_interface->isValid()) { + m_interface->call(QStringLiteral("showVpnAddWidget")); + } +} + +QFrame* Vpn::myLine() +{ + QFrame *line = new QFrame(m_pluginWidget); + line->setMinimumSize(QSize(LINE_MIN_SIZE)); + line->setMaximumSize(QSize(LINE_MAX_SIZE)); + line->setLineWidth(0); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + + return line; +} + +//刪除 +void Vpn::deleteVpn(QString uuid) +{ + m_interface->call(QStringLiteral("deleteVpn"), uuid); +} + +//激活 +void Vpn::activeConnect(QString uuid) { + m_interface->call(QStringLiteral("activateVpn"), uuid); +} + +//详情页 +void Vpn::showDetailPage(QString uuid) { + m_interface->call(QStringLiteral("showDetailPage"), uuid); +} + +//断开 +void Vpn::deActiveConnect(QString uuid) { + m_interface->call(QStringLiteral("deactivateVpn"), uuid); +} + + +//增加一项 +void Vpn::addOneVirtualItem(QStringList infoList) +{ + if (infoList.size() < 4) { + qDebug() << "[Vpn]QStringList size less"; + return; + } + + if (m_listFrame->m_itemMap.contains(infoList.at(1))) { + qDebug() << "[Vpn]Already exist a virtual " << infoList.at(1); + return; + } + + qDebug() << "[Vpn]addOneVitualItem" << infoList.at(0) << infoList.at(3) ; + QString connName = infoList.at(0); + QString connUuid = infoList.at(1); + QString connDbusPath = infoList.at(2); + int status = infoList.at(3).toInt(); //1-连接中 2-已连接 3-断开中 4-已断开 + VpnItem * item = new VpnItem(m_pluginWidget); + + QIcon searchIcon = QIcon::fromTheme(KVpnSymbolic); + item->m_iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE)))); + item->m_titileLabel->setText(connName); + + item->m_uuid = connUuid; + item->m_dbusPath = connDbusPath; + + if (status == 1 || status == 3) { + item->startLoading(); + } + + connect(item->m_infoLabel, &GrayInfoButton::clicked, this, [=]{ + showDetailPage(item->m_uuid); + }); + + item->m_isAcitve = (status == 2); + item->setConnectActionText(item->m_isAcitve); + + if (item->m_isAcitve) { + item->m_statusLabel->setText(tr("connected")); + } else { + item->m_statusLabel->setText(tr("not connected")); + } + + connect(item, &QPushButton::clicked, this, [=] { + if (item->m_isAcitve || item->m_loading) { + deActiveConnect(item->m_uuid); + } else { + activeConnect(item->m_uuid); + } + }); + + connect(item, &VpnItem::connectActionTriggered, this, [=] { + activeConnect(item->m_uuid); + }); + connect(item, &VpnItem::disconnectActionTriggered, this, [=] { + deActiveConnect(item->m_uuid); + }); + connect(item, &VpnItem::deleteActionTriggered, this, [=] { + deleteVpn(item->m_uuid); + }); + + //记录到deviceFrame的m_itemMap中 + m_listFrame->m_itemMap.insert(connUuid, item); + int index = getInsertPos(connName); + qDebug()<<"[Vpn]addOneVirtualItem " << connName << " at pos:" << index; + m_listFrame->m_vpnVLayout->insertWidget(index, item); +} + +void Vpn::removeOneVirtualItem(QString dbusPath) +{ + qDebug()<<"[Vpn]vpn remove dbus path:" << dbusPath; + + QMap::iterator itemIter; + for (itemIter = m_listFrame->m_itemMap.begin(); itemIter != m_listFrame->m_itemMap.end(); itemIter++) { + if (itemIter.value()->m_dbusPath == dbusPath) { + qDebug()<<"[Vpn]vpn remove " << dbusPath << " find in " << itemIter.value()->m_titileLabel->text(); + QString key = itemIter.key(); + m_listFrame->m_vpnVLayout->removeWidget(itemIter.value()); + delete itemIter.value(); + m_listFrame->m_itemMap.remove(key); + break; + } + } +} + +//增加 +void Vpn::onVpnAdd(QStringList infoList) +{ + addOneVirtualItem(infoList); +} + +//移出 +void Vpn::onVpnRemove(QString path) +{ + removeOneVirtualItem(path); +} + +//名称变化 +void Vpn::onVpnUpdate(QStringList info) +{ + if (m_listFrame->m_itemMap.contains(info.at(1))) { + qDebug() << "[Vpn]" << m_listFrame->m_itemMap[info.at(1)]->m_titileLabel->text() << "change to" << info.at(0); + if (m_listFrame->m_itemMap[info.at(1)]->m_titileLabel->text() != info.at(0)) { + m_listFrame->m_itemMap[info.at(1)]->m_titileLabel->setText(info.at(0)); + } + } +} + +void Vpn::onVpnActiveConnectionStateChanged(QString uuid, int status) +{ + if (uuid.isEmpty()) { + qDebug() << "[Vpn]onActiveConnectionChanged but uuid is empty"; + return; + } + qDebug() << "[Vpn]onActiveConnectionChanged " << uuid << status; + VpnItem * item= nullptr; + + if (m_listFrame->m_itemMap.contains(uuid)) { + item = m_listFrame->m_itemMap[uuid]; + if (status == ACTIVATED) { + //为已连接则放到第一个 + m_listFrame->m_vpnVLayout->removeWidget(item); + m_listFrame->m_vpnVLayout->insertWidget(0,item); + } else if (status == DEACTIVATED) { + //为断开则重新插入 + int index = getInsertPos(item->m_titileLabel->text()); + qDebug() << "[Vpn]reinsert" << item->m_titileLabel->text() << "pos" << index << "because status changes to deactive"; + m_listFrame->m_vpnVLayout->removeWidget(item); + m_listFrame->m_vpnVLayout->insertWidget(index,item); + } + itemActiveConnectionStatusChanged(item, status); + } +} + +void Vpn::itemActiveConnectionStatusChanged(VpnItem *item, int status) +{ +// QString iconPath = NoNetSymbolic; + if (status == ACTIVATING) { + item->startLoading(); + } else if (status == ACTIVATED) { + item->stopLoading(); +// iconPath = KLanSymbolic; + item->m_statusLabel->clear(); + item->m_statusLabel->setMinimumSize(36,36); + item->m_statusLabel->setMaximumSize(16777215,16777215); + item->m_statusLabel->setText(tr("connected")); + item->m_isAcitve = true; + } else if (status == DEACTIVATING) { + item->startLoading(); + } else { + item->stopLoading(); + item->m_statusLabel->setMinimumSize(36,36); + item->m_statusLabel->setMaximumSize(16777215,16777215); + item->m_statusLabel->clear(); + item->m_isAcitve = false; + item->m_statusLabel->setText(tr("not connected")); + } + item->setConnectActionText(item->m_isAcitve); +} + +int Vpn::getInsertPos(QString connName) +{ + qDebug() << "[Vpn]getInsertPos" << connName; + int index = 0; + if(!m_interface->isValid()) { + index = 0; + } else { + QDBusMessage result = m_interface->call(QStringLiteral("getVirtualList")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getVirtualList error:" << result.errorMessage(); + return 0; + } + auto dbusArg = result.arguments().at(0).value(); + QVector variantList; + dbusArg >> variantList; + for (int i = 0; i < variantList.size(); ++i ) { + if (variantList.at(i).at(0) == connName) { + qDebug() << "pos in kylin-nm is " << i; + index = i; + break; + } + } + if (variantList.at(0).size() == 1) { + index--; + } + } + return index; +} diff --git a/plugins/vpn/vpn.h b/plugins/vpn/vpn.h new file mode 100644 index 00000000..82d89ea2 --- /dev/null +++ b/plugins/vpn/vpn.h @@ -0,0 +1,120 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2019 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 VPN_H +#define VPN_H + +#include +#include +#include +#include +#include + +#include "interface.h" +#include "addbtn.h" +#include "imageutil.h" +#include "kwidget.h" +#include "kswitchbutton.h" +#include "itemframe.h" + +using namespace kdk; + +namespace Ui { +class Vpn; +} + +class Vpn : public QObject, CommonInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface") + Q_INTERFACES(CommonInterface) + +public: + Vpn(); + ~Vpn(); + + QString plugini18nName() Q_DECL_OVERRIDE; + int pluginTypes() Q_DECL_OVERRIDE; + QWidget * pluginUi() Q_DECL_OVERRIDE; + const QString name() const Q_DECL_OVERRIDE; + bool isShowOnHomePage() const Q_DECL_OVERRIDE; + QIcon icon() const Q_DECL_OVERRIDE; + bool isEnable() const Q_DECL_OVERRIDE; + +public: + void initComponent(); + void initConnect(); + + void runExternalApp(); + +protected: +// bool eventFilter(QObject *watched, QEvent *event); + +private: + Ui::Vpn *ui; + + QString m_pluginName; + int m_pluginType; + QWidget * m_pluginWidget; + + QDBusInterface *m_interface = nullptr; + + QFrame *m_topFrame; + QFrame *m_showFrame; + QLabel *m_showLabel; + KSwitchButton *m_showBtn; + QFrame *m_Line; + QFrame *m_timeFrame; + QLabel *m_timeLabel; + KSwitchButton *m_timeBtn; + ItemFrame *m_listFrame; + + bool m_firstLoad; + QGSettings *m_switchGsettings; + + QFrame* myLine(); + + int getInsertPos(QString connName); + + void deleteVpn(QString uuid); + void activeConnect(QString uuid); + void deActiveConnect(QString uuid); + void showDetailPage(QString uuid); + + //获取设备列表 + void initNet(); + //增加一项 + void addOneVirtualItem(QStringList infoList); + //减少一项 + void removeOneVirtualItem(QString uuid); + //单个lan连接状态变化 + void itemActiveConnectionStatusChanged(VpnItem *item, int status); + + + void setShowSwitchStatus(); + +private slots: + void onVpnAdd(QStringList); + void onVpnRemove(QString); + void onVpnUpdate(QStringList); + void onVpnActiveConnectionStateChanged(QString, int); + +}; + +#endif // VPN_H diff --git a/plugins/vpn/vpn.pro b/plugins/vpn/vpn.pro new file mode 100644 index 00000000..957517c6 --- /dev/null +++ b/plugins/vpn/vpn.pro @@ -0,0 +1,50 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2019-06-29T13:53:10 +# +#------------------------------------------------- + +QT += widgets dbus + +TEMPLATE = lib +CONFIG += plugin \ + c++11 \ + link_pkgconfig + +include(../component/addbtn.pri) + +PKGCONFIG += gsettings-qt \ + kysdk-qtwidgets \ + +TARGET = $$qtLibraryTarget(vpn) +DESTDIR = ../.. +target.path = $$[QT_INSTALL_LIBS]/ukui-control-center +trans.files = translations/* +trans.path = /usr/share/kylin-nm/vpn/ + +INCLUDEPATH += \ + $$PROJECT_COMPONENTSOURCE \ + $$PROJECT_ROOTDIR \ + /usr/include/ukcc/interface \ + /usr/include/ukcc/widgets + +LIBS += -L$$[QT_INSTALL_LIBS] -lukcc + +SOURCES += \ + vpn.cpp \ + itemframe.cpp \ + vpnitem.cpp + +HEADERS += \ + vpn.h \ + itemframe.h \ + vpnitem.h + +FORMS += \ + vpn.ui + +INSTALLS += target \ + trans + +TRANSLATIONS += \ + translations/zh_CN.ts diff --git a/plugins/vpn/vpn.ui b/plugins/vpn/vpn.ui new file mode 100644 index 00000000..bd1de4af --- /dev/null +++ b/plugins/vpn/vpn.ui @@ -0,0 +1,112 @@ + + + Vpn + + + + 0 + 0 + 800 + 710 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Vpn + + + + 8 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + VPN + + + + + + + + + + + + + + + import + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + TitleLabel + QLabel +

titlelabel.h
+ + + + + diff --git a/plugins/vpn/vpnitem.cpp b/plugins/vpn/vpnitem.cpp new file mode 100644 index 00000000..ec287431 --- /dev/null +++ b/plugins/vpn/vpnitem.cpp @@ -0,0 +1,187 @@ +/* -*- 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 "vpnitem.h" +#include +#define FRAME_SPEED 150 +#define LIMIT_TIME 60*1000 +#define TOTAL_PAGE 8 +#define RADIUS 6.0 + +#define THEME_QT_SCHEMA "org.ukui.style" +#define MODE_QT_KEY "style-name" + +VpnItem::VpnItem(bool bAcitve, QWidget *parent) + : m_isAcitve(bAcitve), QPushButton(parent) +{ + this->setMinimumSize(550, 58); + this->setProperty("useButtonPalette", true); + this->setFlat(true); + QPalette pal = this->palette(); + QColor color = pal.color(QPalette::Button); + color.setAlphaF(0.5); + pal.setColor(QPalette::Button, color); + this->setPalette(pal); + QHBoxLayout *mLanLyt = new QHBoxLayout(this); + mLanLyt->setContentsMargins(16,0,16,0); + mLanLyt->setSpacing(16); + m_iconLabel = new QLabel(this); + m_iconLabel->setProperty("useIconHighlightEffect", 0x2); + m_titileLabel = new FixLabel(this); + m_statusLabel = new QLabel(this); + m_statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + m_infoLabel = new GrayInfoButton(this); + + m_moreButton = new QToolButton(this); + m_moreButton->setProperty("useButtonPalette", true); + m_moreButton->setPopupMode(QToolButton::InstantPopup); + m_moreButton->setAutoRaise(true); + m_moreButton->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic")); + m_moreMenu = new QMenu(m_moreButton); + m_connectAction = new QAction(m_moreMenu); + m_deleteAction = new QAction(tr("Delete"), m_moreMenu); + setConnectActionText(m_isAcitve); + + m_moreMenu->addAction(m_connectAction); + m_moreMenu->addAction(m_deleteAction); + m_moreButton->setMenu(m_moreMenu); + + mLanLyt->addWidget(m_iconLabel); + mLanLyt->addWidget(m_titileLabel,Qt::AlignLeft); + mLanLyt->addStretch(); + mLanLyt->addWidget(m_statusLabel); + mLanLyt->addWidget(m_infoLabel); + mLanLyt->addWidget(m_moreButton); + + 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_waitTimer = new QTimer(this); + connect(m_waitTimer, &QTimer::timeout, this, &VpnItem::updateIcon); + + connect(m_connectAction, &QAction::triggered, this, &VpnItem::onConnectTriggered); + connect(m_deleteAction, &QAction::triggered, this, &VpnItem::onDeletetTriggered); + m_moreMenu->installEventFilter(this); +} + +void VpnItem::updateIcon() +{ + if (m_currentIconIndex > 6) { + m_currentIconIndex = 0; + } + m_statusLabel->setPixmap(m_loadIcons.at(m_currentIconIndex).pixmap(16,16)); + m_currentIconIndex ++; +} + +void VpnItem::startLoading() +{ + m_waitTimer->start(FRAME_SPEED); + m_loading = true; +} + +void VpnItem::stopLoading(){ + m_waitTimer->stop(); + m_loading = false; +} + +void VpnItem::setConnectActionText(bool isAcitve) +{ + if (isAcitve) { + m_connectAction->setText(tr("Disconnect")); + } else { + m_connectAction->setText(tr("Connect")); + } +} + +void VpnItem::onConnectTriggered() +{ + if (!m_connectAction) { + return; + } + if (m_connectAction->text() == tr("Connect")) { + Q_EMIT connectActionTriggered(); + } else if (m_connectAction->text() == tr("Disconnect")) { + Q_EMIT disconnectActionTriggered(); + } +} + +void VpnItem::onDeletetTriggered() +{ + if (!m_deleteAction) { + return; + } + Q_EMIT deleteActionTriggered(); +} + +void VpnItem::paintEvent(QPaintEvent *event) +{ + QPalette pal = this->palette(); + + QPainter painter(this); + painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿 + painter.setPen(Qt::NoPen); + painter.setBrush(pal.color(QPalette::Base)); + + QRect rect = this->rect(); + +#if 0 + if (!m_useHalfFillet) { + painter.drawRect(rect); + } else { + QPainterPath path; +// path.addRoundedRect (rect, RADIUS, RADIUS); +// QRect temp_rect(rect.left(), rect.top(), rect.width(), rect.height()/2); +// path.addRect(temp_rect); + //设置起点 + path.moveTo(rect.topLeft().x(), rect.topLeft().y()); + path.lineTo(rect.bottomLeft().x(), rect.bottomLeft().y() - RADIUS); + //绘制圆角 圆弧以外切圆的270度位置为起点,逆时针画圆弧运行90度结束 + path.arcTo(QRect(QPoint(rect.bottomLeft().x(), rect.bottomLeft().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 180, 90); + path.lineTo(rect.bottomRight().x() - RADIUS, rect.bottomRight().y()); + //画圆弧 + path.arcTo(QRect(QPoint(rect.bottomRight().x() - (RADIUS * 2), rect.bottomRight().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 270, 90); + path.lineTo(rect.topRight()); + path.lineTo(rect.topLeft()); + painter.drawPath(path); + } +#endif + + painter.drawRect(rect); + QPushButton::paintEvent(event); +} + +bool VpnItem::eventFilter(QObject *watched, QEvent *event) +{ + //菜单右边界与按钮右边界对齐 + if (event->type() == QEvent::Show && watched == m_moreMenu) { + int menuXPos = m_moreMenu->pos().x(); + int menuWidth = m_moreMenu->size().width(); + int btnWidth = m_moreButton->size().width(); + + QPoint pos = QPoint (menuXPos - menuWidth + btnWidth, m_moreMenu->pos().y()); + m_moreMenu->move(pos); + return true; + } + return false; +} diff --git a/plugins/vpn/vpnitem.h b/plugins/vpn/vpnitem.h new file mode 100644 index 00000000..bbe8a3ec --- /dev/null +++ b/plugins/vpn/vpnitem.h @@ -0,0 +1,87 @@ +/* -*- 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 VPNITEM_H +#define VPNITEM_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "fixlabel.h" +#include "../component/AddBtn/grayinfobutton.h" + +class VpnItem : public QPushButton +{ + Q_OBJECT +public: + VpnItem(bool bAcitve, QWidget *parent = nullptr); +public: + QLabel * m_iconLabel = nullptr; + GrayInfoButton * m_infoLabel = nullptr; + FixLabel * m_titileLabel = nullptr; + QLabel * m_statusLabel = nullptr; + QToolButton* m_moreButton = nullptr; + QMenu* m_moreMenu = nullptr; + QAction* m_connectAction = nullptr; + QAction* m_deleteAction = nullptr; + + QString m_uuid = ""; + QString m_dbusPath = ""; + + void setHalfFillet(bool flag) {m_useHalfFillet = flag; repaint();} +public: + void startLoading(); + void stopLoading(); + void setConnectActionText(bool isAcitve); + + bool m_isAcitve = false; + bool m_loading = false; + +protected: + void paintEvent(QPaintEvent *event); + bool eventFilter(QObject *watched, QEvent *event); + +private: + QTimer *m_waitTimer = nullptr; + bool m_useHalfFillet = false; + QList m_loadIcons; + int m_currentIconIndex=0; + +private slots: + void updateIcon(); + void onConnectTriggered(); + void onDeletetTriggered(); + +Q_SIGNALS: + void connectActionTriggered(); + void disconnectActionTriggered(); + void deleteActionTriggered(); + +}; + +#endif // VPNITEM_H diff --git a/src-vpn/backend/backend.pri b/src-vpn/backend/backend.pri new file mode 100644 index 00000000..3419c1f0 --- /dev/null +++ b/src-vpn/backend/backend.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$PWD +include(../../src/backend/dbus-interface/dbus-interface.pri) + +HEADERS += \ + $$PWD/vpndbusadaptor.h + +SOURCES += \ + $$PWD/vpndbusadaptor.cpp + +DISTFILES += diff --git a/src-vpn/backend/vpndbusadaptor.cpp b/src-vpn/backend/vpndbusadaptor.cpp new file mode 100644 index 00000000..e94ab43b --- /dev/null +++ b/src-vpn/backend/vpndbusadaptor.cpp @@ -0,0 +1,78 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp com.kylin.weather.xml -a VpnDbusAdaptor -c VpnDbusAdaptor -l MainWindow + * + * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#include "vpndbusadaptor.h" +#include +#include +#include +#include +#include +#include +#include + +/* + * Implementation of adaptor class VpnDbusAdaptor + */ + +VpnDbusAdaptor::VpnDbusAdaptor(vpnObject *parent) + : QDBusAbstractAdaptor(parent) +{ + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); + setAutoRelaySignals(true); +} + +//虚拟连接列表 +QVector VpnDbusAdaptor::getVirtualList() +{ + QVector vector; + parent()->getVirtualList(vector); + return vector; +} + +//删除 +void VpnDbusAdaptor::deleteVpn(QString uuid) +{ + qDebug() << "delete vpn" << uuid; + parent()->deleteVpn(uuid); +} + +//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid +void VpnDbusAdaptor::activateVpn(const QString& connUuid) +{ + qDebug() << "activate vpn" << connUuid; + parent()->activateVpn(connUuid); +} + +//断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid +void VpnDbusAdaptor::deactivateVpn(const QString& connUuid) +{ + qDebug() << "deactivate vpn" << connUuid; + parent()->deactivateVpn(connUuid); +} + +void VpnDbusAdaptor::showKylinVpn() +{ + parent()->onShowMainWindow(); +} + +void VpnDbusAdaptor::showVpnAddWidget() +{ + qDebug() << "showVpnAddWidget"; + parent()->showVpnAddWidget(); +} + +void VpnDbusAdaptor::showDetailPage(const QString& connUuid) +{ + qDebug() << "showDetailPage vpn" << connUuid; + parent()->showDetailPage(connUuid); +} + diff --git a/src-vpn/backend/vpndbusadaptor.h b/src-vpn/backend/vpndbusadaptor.h new file mode 100644 index 00000000..919f092e --- /dev/null +++ b/src-vpn/backend/vpndbusadaptor.h @@ -0,0 +1,64 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp com.kylin.weather.xml -a dbusadaptor -c DbusAdaptor -l MainWindow + * + * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#ifndef VPNDBUSADAPTOR_H +#define VPNDBUSADAPTOR_H + +#include +#include +#include + +#include "singlepage.h" +#include "kylinnetworkdeviceresource.h" +#include "kyvpnconnectoperation.h" + +QT_BEGIN_NAMESPACE +class QByteArray; +template class QMap; +class QString; +class QStringList; +class QVariant; +template class QVector; +QT_END_NAMESPACE + +#include "vpnobject.h" + +class VpnDbusAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "com.kylin.kylinvpn") +public: + VpnDbusAdaptor(vpnObject *parent); + + inline vpnObject *parent() const + { return static_cast(QObject::parent()); } + +public Q_SLOTS: + QVector getVirtualList(); + Q_NOREPLY void deleteVpn(QString uuid); + Q_NOREPLY void activateVpn(const QString& connUuid); + Q_NOREPLY void deactivateVpn(const QString& connUuid); + Q_NOREPLY void showVpnAddWidget(); + Q_NOREPLY void showDetailPage(const QString& connUuid); + + void showKylinVpn(); + +Q_SIGNALS: + void vpnAdd(QStringList info); + void vpnRemove(QString dbusPath); + void vpnUpdate(QStringList info); + void vpnActiveConnectionStateChanged(QString uuid, int status); + + void activateFailed(QString errorMessage); + void deactivateFailed(QString errorMessage); +}; + +#endif diff --git a/src-vpn/frontend/frontend.pri b/src-vpn/frontend/frontend.pri new file mode 100644 index 00000000..0d131ba1 --- /dev/null +++ b/src-vpn/frontend/frontend.pri @@ -0,0 +1,11 @@ +INCLUDEPATH += $$PWD +include(../../src/frontend/tools/tools.pri) +include(list-items/list-items.pri) +include(vpndetails/vpndetails.pri) +include(single-pages/single-pages.pri) + +HEADERS += \ + $$PWD/vpnobject.h + +SOURCES += \ + $$PWD/vpnobject.cpp diff --git a/src-vpn/frontend/list-items/list-items.pri b/src-vpn/frontend/list-items/list-items.pri new file mode 100644 index 00000000..fefdcbe8 --- /dev/null +++ b/src-vpn/frontend/list-items/list-items.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/listitem.h \ + $$PWD/vpnlistitem.h + +SOURCES += \ + $$PWD/listitem.cpp \ + $$PWD/vpnlistitem.cpp + diff --git a/src-vpn/frontend/list-items/listitem.cpp b/src-vpn/frontend/list-items/listitem.cpp new file mode 100644 index 00000000..6ed14804 --- /dev/null +++ b/src-vpn/frontend/list-items/listitem.cpp @@ -0,0 +1,151 @@ +/* -*- 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 "listitem.h" +#include + +#define MAIN_LAYOUT_MARGINS 0,0,0,0 +#define MAIN_LAYOUT_SPACING 0 +#define ITEM_FRAME_MARGINS 12,6,16,6 + +#define ITEM_FRAME_SPACING 8 +#define FRAME_WIDTH 404 +#define INFO_ICON_WIDTH 16 +#define INFO_ICON_HEIGHT 16 +#define LIGHT_HOVER_COLOR QColor(240,240,240,255) +#define DARK_HOVER_COLOR QColor(15,15,15,255) + +ListItem::ListItem(QWidget *parent) : QFrame(parent) +{ + m_connectState = UnknownState; + + initUI(); + initConnection(); + connect(qApp, &QApplication::paletteChanged, this, &ListItem::onPaletteChanged); +// m_itemFrame->installEventFilter(this); +} + +ListItem::~ListItem() +{ + if (nullptr != m_netButton) { + delete m_netButton; + m_netButton = nullptr; + } + + if (nullptr != m_infoButton) { + delete m_infoButton; + m_infoButton = nullptr; + } + +} + +void ListItem::setName(const QString &name) +{ + m_nameLabel->setText(name); +} + +//仅无线调用,有线自己获取 +void ListItem::setActive(const bool &isActive) +{ + m_netButton->setActive(isActive); + m_isActive = isActive; +} + +void ListItem::setConnectState(ConnectState state) +{ + m_connectState = state; +} + +void ListItem::mousePressEvent(QMouseEvent *event) +{ + qDebug()<<"[ListItem]"<<"mousePressEvent"; + if (event->button() == Qt::LeftButton) { + onNetButtonClicked(); + } else if (event->button() == Qt::RightButton) { + onRightButtonClicked(); + } + return QFrame::mousePressEvent(event); +} + +void ListItem::enterEvent(QEvent *event) +{ +} + +void ListItem::leaveEvent(QEvent *event) +{ +} + +void ListItem::paintEvent(QPaintEvent *event) +{ +} + +void ListItem::initUI() +{ + m_menu = new QMenu(this);//右键菜单 +// m_menu->setStyleSheet("QMenu::item{border:3px; border-radius:3px}"); +// m_menu->setStyleSheet("QMenu{border-radius:6px; margin:6px 6px 6px 6px}"); + connect(m_menu, &QMenu::triggered, this, &ListItem::onMenuTriggered); + + m_mainLayout = new QVBoxLayout(this); + m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); + m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING); + this->setLayout(m_mainLayout); + + m_itemFrame = new QFrame(this); + m_itemFrame->setFixedWidth(FRAME_WIDTH); + + m_hItemLayout = new QHBoxLayout(m_itemFrame); + m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS); + m_hItemLayout->setSpacing(ITEM_FRAME_SPACING); + m_hItemLayout->setAlignment(Qt::AlignHCenter); + + m_netButton = new RadioItemButton(m_itemFrame); + m_nameLabel = new QLabel(m_itemFrame); + m_nameLabel->setMinimumWidth(262); + m_infoButton = new InfoButton(m_itemFrame); + m_infoButton->setIconSize(QSize(INFO_ICON_WIDTH,INFO_ICON_HEIGHT)); + + m_hItemLayout->addWidget(m_netButton); + m_hItemLayout->addWidget(m_nameLabel); + m_hItemLayout->addStretch(); + m_hItemLayout->addWidget(m_infoButton); + + m_mainLayout->addWidget(m_itemFrame); + +// this->setAutoFillBackground(true); +// this->setBackgroundRole(QPalette::Base); +// QPalette pal = qApp->palette(); +// pal.setColor(QPalette::Window, qApp->palette().base().color()); +// this->setPalette(pal); +} + + +void ListItem::initConnection() +{ + connect(this->m_netButton, &RadioItemButton::clicked, this, &ListItem::onNetButtonClicked); + // connect(this->m_infoButton, &InfoButton::clicked, this, &ListItem::onInfoButtonClicked); +} + +void ListItem::onPaletteChanged() +{ +// QPalette pal = qApp->palette(); +// pal.setColor(QPalette::Window, qApp->palette().base().color()); +// this->setPalette(pal); +} + diff --git a/src-vpn/frontend/list-items/listitem.h b/src-vpn/frontend/list-items/listitem.h new file mode 100644 index 00000000..8b6c843a --- /dev/null +++ b/src-vpn/frontend/list-items/listitem.h @@ -0,0 +1,87 @@ +/* -*- 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 LISTITEM_H +#define LISTITEM_H +#include +#include +#include +#include +#include +#include +#include +#include "radioitembutton.h" +#include "infobutton.h" + + +typedef enum{ + UnknownState = 0, /**< The active connection is in an unknown state */ + Activating, /**< The connection is activating */ + Activated, /**< The connection is activated */ + Deactivating, /**< The connection is being torn down and cleaned up */ + Deactivated /**< The connection is no longer active */ +}ConnectState; + +class ListItem : public QFrame +{ + Q_OBJECT +public: + ListItem(QWidget *parent = nullptr); + ~ListItem(); + void setName(const QString &name); + void setActive(const bool &isActive); + void setConnectState(ConnectState state); + static void showDesktopNotify(const QString &message, QString soundName); + +protected: + void mousePressEvent(QMouseEvent *event); + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); + void paintEvent(QPaintEvent *event); + virtual void onRightButtonClicked() = 0; + +protected: + QFrame * m_itemFrame = nullptr; + + QLabel * m_nameLabel = nullptr; + RadioItemButton * m_netButton = nullptr; + InfoButton * m_infoButton = nullptr; + + bool m_isActive = false; + ConnectState m_connectState; + + QMenu *m_menu = nullptr; +public: + QVBoxLayout * m_mainLayout = nullptr; + QHBoxLayout * m_hItemLayout = nullptr; + +private: + void initUI(); + void initConnection(); + +public Q_SLOTS: + virtual void onNetButtonClicked() = 0; + void onPaletteChanged(); + virtual void onMenuTriggered(QAction *action)=0; + +Q_SIGNALS: + void detailShow(bool isShow); +}; + +#endif // LISTITEM_H diff --git a/src-vpn/frontend/list-items/vpnlistitem.cpp b/src-vpn/frontend/list-items/vpnlistitem.cpp new file mode 100644 index 00000000..eb251470 --- /dev/null +++ b/src-vpn/frontend/list-items/vpnlistitem.cpp @@ -0,0 +1,248 @@ +/* -*- 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 "vpnlistitem.h" +#include "kylinconnectitem.h" + +#include + +#define LOG_FLAG "[VpnListItem]" + +VpnListItem::VpnListItem(const KyConnectItem *vpnConnectItem, QWidget *parent):ListItem(parent) +{ + m_connectOperation = new KyVpnConnectOperation(this); + m_deviceResource = new KyNetworkDeviceResourse(this); + + connectItemCopy(vpnConnectItem); + + m_nameLabel->setText(m_vpnConnectItem.m_connectName); + m_netButton->setButtonIcon(QIcon::fromTheme("ukui-vpn-symbolic")); + + qDebug() << "VpnListItem init:" << m_vpnConnectItem.m_connectName << m_vpnConnectItem.m_connectState << m_vpnConnectItem.m_ifaceName; + + if (Deactivated == m_vpnConnectItem.m_connectState || Activated == m_vpnConnectItem.m_connectState) { + m_netButton->stopLoading(); + if (m_vpnConnectItem.m_connectState == Activated) { + setIcon(true); + } else { + setIcon(false); + } + } else { + m_netButton->startLoading(); + } + + m_itemFrame->installEventFilter(this); + connect(this->m_infoButton, &InfoButton::clicked, this, &VpnListItem::onInfoButtonClicked); + connect(m_menu, &QMenu::triggered, this, &VpnListItem::onMenuTriggered); +} + + +VpnListItem::VpnListItem(QWidget *parent) : ListItem(parent) +{ + m_isActive = false; + m_netButton->setButtonIcon(QIcon::fromTheme("ukui-vpn-symbolic")); + setIcon(false); + const QString str=tr("Not connected"); + m_nameLabel->setText(str); + this->m_infoButton->hide(); +} + +VpnListItem::~VpnListItem() +{ + qDebug()<<"[LanPage] lan list item is deleted." << m_vpnConnectItem.m_connectName; +} + +void VpnListItem::setIcon(bool isOn) +{ + if (isOn) { + m_netButton->setActive(true); //设置图标显示不同颜色 + } else { + m_netButton->setActive(false); + } +} + +void VpnListItem::connectItemCopy(const KyConnectItem *vpnConnectItem) +{ + if (vpnConnectItem) { + m_vpnConnectItem.m_connectName = vpnConnectItem->m_connectName; + m_vpnConnectItem.m_connectPath = vpnConnectItem->m_connectPath; + m_vpnConnectItem.m_connectState = vpnConnectItem->m_connectState; + m_vpnConnectItem.m_connectUuid = vpnConnectItem->m_connectUuid; + m_vpnConnectItem.m_ifaceName = vpnConnectItem->m_ifaceName; + m_vpnConnectItem.m_itemType = vpnConnectItem->m_itemType; + } else { + qDebug() << LOG_FLAG <<"the connect item is nullptr"; + m_vpnConnectItem.m_connectName = ""; + m_vpnConnectItem.m_connectPath = ""; + m_vpnConnectItem.m_connectState = NetworkManager::ActiveConnection::State::Unknown; + m_vpnConnectItem.m_connectUuid = ""; + m_vpnConnectItem.m_ifaceName = ""; + m_vpnConnectItem.m_itemType = NetworkManager::ConnectionSettings::ConnectionType::Unknown; + } +} + +void VpnListItem::activeConnection() +{ + if (m_vpnConnectItem.m_connectUuid.isEmpty()) { + qDebug() << LOG_FLAG << "connect is empty, so can not connect or disconnect."; + return; + } + + if (Deactivated == m_vpnConnectItem.m_connectState) { + //断开的连接,点击激活连接 + m_connectOperation->activateVpnConnection(m_vpnConnectItem.m_connectUuid); + qDebug() << LOG_FLAG << "it will activate connection" << m_vpnConnectItem.m_connectName; + m_netButton->startLoading(); + } else { + qDebug() << LOG_FLAG <<"the connection" << m_vpnConnectItem.m_connectName + << "is not deactived, so it can not be operation."; + } +} + +void VpnListItem::onNetButtonClicked() +{ + if (m_vpnConnectItem.m_connectUuid.isEmpty()) { + qDebug() << LOG_FLAG << "connect is empty, so can not connect or disconnect."; + return; + } + + if (Deactivated == m_vpnConnectItem.m_connectState) { + //断开的连接,点击激活连接 + m_connectOperation->activateVpnConnection(m_vpnConnectItem.m_connectUuid); + qDebug() << LOG_FLAG << "it will activate connection" << m_vpnConnectItem.m_connectName; + m_netButton->startLoading(); + } else { + qDebug() << LOG_FLAG <<"the connection" << m_vpnConnectItem.m_connectName + << "is not deactived, so it can not be operation."; + } +} + +void VpnListItem::onRightButtonClicked() +{ + //右键点击事件 + qDebug()<< LOG_FLAG <<"onRightButtonClicked"; + if (!m_menu) { + return; + } + + m_menu->clear(); + if (Activated == m_vpnConnectItem.m_connectState || Activating == m_vpnConnectItem.m_connectState) { + m_menu->addAction(new QAction(tr("Disconnect"), this)); + } else if (Deactivated == m_vpnConnectItem.m_connectState) { + m_menu->addAction(new QAction(tr("Connect"), this)); + } else { + return; + } + + m_menu->move(cursor().pos()); + m_menu->show(); +} + +void VpnListItem::onMenuTriggered(QAction *action) +{ + if (action->text() == tr("Connect")) { + this->onNetButtonClicked(); + } else if (action->text() == tr("Disconnect")) { + m_connectOperation->deactivateVpnConnection(m_vpnConnectItem.m_connectName, m_vpnConnectItem.m_connectUuid); + qDebug() << LOG_FLAG << "it will disconnect connection" << m_vpnConnectItem.m_connectName; + m_netButton->startLoading(); + } +} + +bool VpnListItem::launchApp(QString desktopFile) +{ + QDBusInterface appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, + KYLIN_APP_MANAGER_PATH, + KYLIN_APP_MANAGER_INTERFACE, + QDBusConnection::sessionBus()); + + if (!appManagerDbusInterface.isValid()) { + qWarning()<<"appManagerDbusInterface init error"; + return false; + } else { + QDBusReply reply = appManagerDbusInterface.call("LaunchApp", desktopFile); + return reply; + } +} + +void VpnListItem::runExternalApp() { + if (!launchApp("nm-connection-editor.desktop")){ + QString cmd = "nm-connection-editor"; + QProcess process(this); + process.startDetached(cmd); + } +} + +void VpnListItem::onInfoButtonClicked() +{ + if (m_vpnConnectItem.m_itemType != NetworkManager::ConnectionSettings::ConnectionType::Vpn) { + runExternalApp(); + return; + } + + if(m_vpnDetail != nullptr){ + m_vpnDetail->activateWindow(); + return; + } + m_vpnDetail = new vpnDetail(m_vpnConnectItem.m_connectUuid, getConnectionName()); + connect(m_vpnDetail, &vpnDetail::destroyed, [&](){ + if (m_vpnDetail != nullptr) { + m_vpnDetail = nullptr; + } + }); + + m_vpnDetail->show(); +} + +void VpnListItem::updateConnectionState(ConnectState state) +{ + m_vpnConnectItem.m_connectState = (NetworkManager::ActiveConnection::State)state; + + if (Deactivated == state || Activated == state) { + m_netButton->stopLoading(); + if (state == Activated) { + setIcon(true); + } else { + setIcon(false); + } + } else { + m_netButton->startLoading(); + } +} + +QString VpnListItem::getConnectionName() +{ + return m_vpnConnectItem.m_connectName; +} + +void VpnListItem::updateConnectionName(QString connectionName) +{ + m_vpnConnectItem.m_connectName = connectionName; + m_nameLabel->setText(m_vpnConnectItem.m_connectName); +} + +QString VpnListItem::getConnectionPath() +{ + return m_vpnConnectItem.m_connectPath; +} + +void VpnListItem::updateConnectionPath(QString connectionPath) +{ + m_vpnConnectItem.m_connectPath = connectionPath; +} diff --git a/src-vpn/frontend/list-items/vpnlistitem.h b/src-vpn/frontend/list-items/vpnlistitem.h new file mode 100644 index 00000000..95fcfcd7 --- /dev/null +++ b/src-vpn/frontend/list-items/vpnlistitem.h @@ -0,0 +1,88 @@ +/* -*- 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 VPNLISTITEM_H +#define VPNLISTITEM_H +#include "listitem.h" +#include "kylinactiveconnectresource.h" + +#include +#include +#include +#include + +#include "vpndetails/vpndetail.h" +#include "kylinconnectresource.h" +//#include "kylinwiredconnectoperation.h" +#include "kyvpnconnectoperation.h" + + +#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" +#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" +#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" + +class VpnListItem : public ListItem +{ + Q_OBJECT + +public: + VpnListItem(const KyConnectItem *vpnConnectItem, QWidget *parent = nullptr); + VpnListItem(QWidget *parent = nullptr); + + ~VpnListItem(); + +public: + void updateConnectionState(ConnectState state); + + QString getConnectionName(); + void updateConnectionName(QString connectionName); + + QString getConnectionPath(); + void updateConnectionPath(QString connectionPath); + + void activeConnection(); + +protected: + void setIcon(bool isOn); + void onRightButtonClicked(); + bool launchApp(QString desktopFile); + void runExternalApp(); + +private: + void connectItemCopy(const KyConnectItem *vpnConnectItem); + +public Q_SLOTS: + void onInfoButtonClicked(); + +private Q_SLOTS: + void onNetButtonClicked(); + void onMenuTriggered(QAction *action); + +private: + KyConnectItem m_vpnConnectItem; + + KyVpnConnectOperation *m_connectOperation = nullptr; + KyNetworkDeviceResourse *m_deviceResource = nullptr; + + QString m_deviceName = ""; + + vpnDetail *m_vpnDetail = nullptr; +}; + +#endif // VPNLISTITEM_H diff --git a/src-vpn/frontend/single-pages/single-pages.pri b/src-vpn/frontend/single-pages/single-pages.pri new file mode 100644 index 00000000..96c70dc5 --- /dev/null +++ b/src-vpn/frontend/single-pages/single-pages.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/vpnpage.h \ + $$PWD/singlepage.h + +SOURCES += \ + $$PWD/vpnpage.cpp \ + $$PWD/singlepage.cpp + diff --git a/src-vpn/frontend/single-pages/singlepage.cpp b/src-vpn/frontend/single-pages/singlepage.cpp new file mode 100644 index 00000000..695e75e2 --- /dev/null +++ b/src-vpn/frontend/single-pages/singlepage.cpp @@ -0,0 +1,185 @@ +/* -*- 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 "singlepage.h" +#include +#include +#include +#include +#include + +#include + +SinglePage::SinglePage(QWidget *parent) : QWidget(parent) +{ + initUI(); + initWindowProperties(); + initTransparency(); +} + +SinglePage::~SinglePage() +{ +} + +void SinglePage::initUI() +{ + m_mainLayout = new QVBoxLayout(this); + m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); + m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING); + this->setLayout(m_mainLayout); + + m_titleFrame = new QFrame(this); + m_titleFrame->setFixedHeight(TITLE_FRAME_HEIGHT); + m_titleLayout = new QHBoxLayout(m_titleFrame); + m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS); + m_titleFrame->setLayout(m_titleLayout); + m_titleLabel = new QLabel(m_titleFrame); + m_titleLayout->addWidget(m_titleLabel); + m_titleLayout->addStretch(); + + m_netDivider = new Divider(this); + + m_listFrame = new QFrame(this); + m_listLayout = new QVBoxLayout(m_listFrame); + m_listLayout->setContentsMargins(NET_LAYOUT_MARGINS); + m_listFrame->setLayout(m_listLayout); + m_listWidget = new QListWidget(m_listFrame); + m_listLayout->addWidget(m_listWidget); + + m_setDivider = new Divider(this); + + m_settingsFrame = new QFrame(this); + m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT); + m_settingsLayout = new QHBoxLayout(m_settingsFrame); + m_settingsLayout->setContentsMargins(SETTINGS_LAYOUT_MARGINS); + m_settingsLabel = new KyLable(m_settingsFrame); + m_settingsLabel->setCursor(Qt::PointingHandCursor); + m_settingsLabel->setText(tr("Settings")); + m_settingsLabel->setScaledContents(true); + m_settingsLayout->addWidget(m_settingsLabel); + m_settingsLayout->addStretch(); + m_settingsFrame->setLayout(m_settingsLayout); + + m_mainLayout->addWidget(m_titleFrame); + m_mainLayout->addWidget(m_netDivider); + m_mainLayout->addWidget(m_listFrame); + m_mainLayout->addWidget(m_setDivider); + m_mainLayout->addWidget(m_settingsFrame); +} + +void SinglePage::initWindowProperties() +{ + QPalette pal = m_listFrame->palette(); + pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明 + m_listFrame->setPalette(pal); + + this->setFixedWidth(MAX_WIDTH); + this->setAttribute(Qt::WA_TranslucentBackground); + this->setProperty("useStyleWindowManager", false); //禁用拖动 + //绘制毛玻璃特效 + QString platform = QGuiApplication::platformName(); + if(!platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) + { + QPainterPath path; + auto rect = this->rect(); + path.addRoundedRect(rect, 12, 12); + path.addRect(rect); + KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); //背景模糊 + } +} + +void SinglePage::showDesktopNotify(const QString &message, QString soundName) +{ + QDBusInterface iface("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", + QDBusConnection::sessionBus()); + QStringList actions; //跳转动作 + actions.append("kylin-vpn"); + actions.append("default"); //默认动作:点击消息体时打开麒麟录音 + QMap hints; + if (!soundName.isEmpty()) { + hints.insert("sound-name",soundName); //添加声音 + } + QList args; + args<<(tr("Kylin VPN")) + <<((unsigned int) 0) + <palette().window().color(); + + QPainterPath rectPath; + + col.setAlphaF(m_transparency); + rectPath.addRoundedRect(this->rect(),12,12); + + painter.setBrush(col); + painter.drawPath(rectPath); + KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(rectPath.toFillPolygon().toPolygon())); //背景模糊 +} + +void SinglePage::initTransparency() +{ + if(QGSettings::isSchemaInstalled(QByteArray(TRANSPARENCY_GSETTINGS))) { + m_transGsettings = new QGSettings(QByteArray(TRANSPARENCY_GSETTINGS)); + if(m_transGsettings->keys().contains(TRANSPARENCY)) { + m_transparency = m_transGsettings->get(TRANSPARENCY).toDouble() + 0.15; + m_transparency = (m_transparency > 1) ? 1 : m_transparency; + connect(m_transGsettings, &QGSettings::changed, this, &SinglePage::onTransChanged); + } + } +} + +void SinglePage::onTransChanged() +{ + m_transparency = m_transGsettings->get("transparency").toDouble() + 0.15; + m_transparency = (m_transparency > 1) ? 1 : m_transparency; + paintWithTrans(); +} + +void SinglePage::paintWithTrans() +{ + QPalette pal = this->palette(); + QColor color = qApp->palette().base().color(); + color.setAlphaF(m_transparency); + pal.setColor(QPalette::Window, color); + this->setPalette(pal); +} + +void SinglePage::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape) { + this->hide(); + } + return QWidget::keyPressEvent(event); +} + + diff --git a/src-vpn/frontend/single-pages/singlepage.h b/src-vpn/frontend/single-pages/singlepage.h new file mode 100644 index 00000000..c822c4f4 --- /dev/null +++ b/src-vpn/frontend/single-pages/singlepage.h @@ -0,0 +1,112 @@ +/* -*- 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 SINGLEPAGE_H +#define SINGLEPAGE_H + +#include "divider.h" +#include "kylable.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kylinnetworkdeviceresource.h" +#include "kwidget.h" +#include "kswitchbutton.h" + +using namespace kdk; + +#define MAIN_LAYOUT_MARGINS 0,0,0,0 +#define MAIN_LAYOUT_SPACING 0 +#define TITLE_FRAME_HEIGHT 60 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度 +#define TITLE_LAYOUT_MARGINS 24,0,24,0 +#define NET_LAYOUT_MARGINS 8,8,8,8 +#define TEXT_HEIGHT 20 +#define SETTINGS_LAYOUT_MARGINS 23,0,24,0 + +#define MAX_ITEMS 4 +#define MAX_WIDTH 412 +#define MIN_WIDTH 404 + +#define SCROLL_STEP 4 + +#define TRANSPARENCY "transparency" +#define TRANSPARENCY_GSETTINGS "org.ukui.control-center.personalise" + +class SinglePage : public QWidget +{ + Q_OBJECT +public: + explicit SinglePage(QWidget *parent = nullptr); + ~SinglePage(); + + static void showDesktopNotify(const QString &message, QString soundName); + +Q_SIGNALS: + void activateFailed(QString errorMessage); + void deactivateFailed(QString errorMessage); + +private Q_SLOTS: + void onTransChanged(); + +protected: + void paintEvent(QPaintEvent *event); + void keyPressEvent(QKeyEvent *event); + +protected: + void initUI(); + void initTransparency(); + void paintWithTrans(); + + +private: + void initWindowProperties(); + +protected: + QVBoxLayout * m_mainLayout = nullptr; + + QLabel * m_titleLabel = nullptr; + QFrame * m_titleFrame = nullptr; + QHBoxLayout * m_titleLayout = nullptr; + + QFrame * m_listFrame = nullptr; + QListWidget * m_listWidget = nullptr; + QVBoxLayout * m_listLayout = nullptr; + + QFrame * m_settingsFrame = nullptr; + QHBoxLayout * m_settingsLayout = nullptr; + KyLable * m_settingsLabel = nullptr; + + Divider * m_netDivider = nullptr; + Divider * m_setDivider = nullptr; + + + QGSettings * m_transGsettings = nullptr; + double m_transparency = 1.0; //透明度 + +}; + +#endif // TABPAGE_H diff --git a/src-vpn/frontend/single-pages/vpnpage.cpp b/src-vpn/frontend/single-pages/vpnpage.cpp new file mode 100644 index 00000000..41c8cb70 --- /dev/null +++ b/src-vpn/frontend/single-pages/vpnpage.cpp @@ -0,0 +1,702 @@ +/* -*- 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 "vpnpage.h" +#include +#include +#include "windowmanager/windowmanager.h" + + +VpnPage::VpnPage(QWidget *parent) : SinglePage(parent) +{ + m_activeResourse = new KyActiveConnectResourse(this); + m_connectResourse = new KyConnectResourse(this); + m_vpnConnectOperation = new KyVpnConnectOperation(this); + + initUI(); + initVpnArea(); + installEventFilter(this); + + connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &VpnPage::onConnectionStateChange); + connect(m_activeResourse, &KyActiveConnectResourse::activeConnectRemove, this, [=] (QString activeConnectUuid) { + sendVpnStateChangeSignal(activeConnectUuid,Deactivated); + } ); + + connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &VpnPage::onAddConnection); + connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &VpnPage::onRemoveConnection); + connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &VpnPage::onUpdateConnection); + + connect(m_vpnConnectOperation, &KyVpnConnectOperation::activateConnectionError, this, &VpnPage::activateFailed); + connect(m_vpnConnectOperation, &KyVpnConnectOperation::deactivateConnectionError, this, &VpnPage::deactivateFailed); + + connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, [&](WId activeWindowId){ + if (activeWindowId != this->winId() && activeWindowId != 0) { + hide(); + } + }); +} + +VpnPage::~VpnPage() +{ + +} + +void VpnPage::deleteConnectionMapItem(QMap &connectMap, + QListWidget *vpnListWidget, QString uuid) +{ + QListWidgetItem *p_listWidgetItem = connectMap.value(uuid); + if (p_listWidgetItem) { + connectMap.remove(uuid); + VpnListItem *p_vpnItem = (VpnListItem *)vpnListWidget->itemWidget(p_listWidgetItem); + vpnListWidget->removeItemWidget(p_listWidgetItem); + + delete p_vpnItem; + p_vpnItem = nullptr; + + delete p_listWidgetItem; + p_listWidgetItem = nullptr; + } + + return; +} + +void VpnPage::clearConnectionMap(QMap &connectMap, + QListWidget *vpnListWidget) +{ + QMap::iterator iter; + + iter = connectMap.begin(); + while (iter != connectMap.end()) { + qDebug()<<"[VpnPage] clear connection map item"<< iter.key(); + + QListWidgetItem *p_widgetItem = iter.value(); + VpnListItem *p_vpnItem = (VpnListItem *)vpnListWidget->itemWidget(p_widgetItem); + vpnListWidget->removeItemWidget(p_widgetItem); + + delete p_vpnItem; + p_vpnItem = nullptr; + + delete p_widgetItem; + p_widgetItem = nullptr; + + iter = connectMap.erase(iter); + } + + return; +} + +void VpnPage::constructItemArea() +{ + QList activedList; + QList netList; + + activedList.clear(); + netList.clear(); + clearConnectionMap(m_activeItemMap, m_listWidget); + clearConnectionMap(m_vpnItemMap, m_listWidget); + + m_connectResourse->getVpnAndVirtualConnections(netList); + KyConnectItem *p_newItem = nullptr; + if (!netList.isEmpty()) { + for (int index = 0; index < netList.size(); index++) { + KyConnectItem *p_netConnectionItem = netList.at(index); + p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid); + if (p_newItem == nullptr) { + if (m_vpnItemMap.contains(p_netConnectionItem->m_connectUuid)) { + qDebug()<m_connectUuid; + } + QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_listWidget); + m_vpnItemMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); + } else { + if (m_activeItemMap.contains(p_netConnectionItem->m_connectUuid)) { + qDebug()<m_connectUuid; + } + QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_listWidget); + m_activeItemMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); + } + + delete p_netConnectionItem; + p_netConnectionItem = nullptr; + } + } + + if (QGSettings::isSchemaInstalled(GSETTINGS_VPNICON_VISIBLE)) { + QGSettings vpnGsettings(GSETTINGS_VPNICON_VISIBLE); + if (vpnGsettings.keys().contains(QString(VISIBLE))) { + if (!netList.isEmpty()) { + vpnGsettings.set(VISIBLE, true); + } else { + vpnGsettings.set(VISIBLE, false); + } + } + } + + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); + } else { + m_listFrame->setFixedWidth(MAX_WIDTH); + } +} + +void VpnPage::initVpnArea() +{ + constructItemArea(); +} + +void VpnPage::resetPageHeight() +{ + int height = 0; + int count = m_listWidget->count(); + m_listFrame->setFixedHeight((count >= 4) ? (MAX_ITEMS * ITEM_HEIGHT + ITEM_SPACE) : (count * ITEM_HEIGHT + ITEM_SPACE)); + + if (count == 0) { + m_listWidget->setHidden(true); + m_listFrame->setHidden(true); + m_netDivider->setHidden(true); + } else { + m_listWidget->show(); + m_listFrame->show(); + m_netDivider->show(); + } + + for (int i = 0; i < m_mainLayout->count(); i ++) { + QWidget *w = m_mainLayout->itemAt(i)->widget(); + if (w != nullptr && w->isHidden() != true) { + height += w->height(); + } + } + this->setFixedHeight(height + PAGE_SPACE); +} + +bool VpnPage::removeConnectionItem(QMap &connectMap, + QListWidget *vpnListWidget, QString path) +{ + QMap::iterator iter; + for (iter = connectMap.begin(); iter != connectMap.end(); ++iter) { + QListWidgetItem *p_listWidgetItem = iter.value(); + VpnListItem *p_vpnItem = (VpnListItem*)vpnListWidget->itemWidget(p_listWidgetItem); + if (p_vpnItem->getConnectionPath() == path) { + qDebug()<<"[VpnPage] Remove a connection from list"; + + vpnListWidget->removeItemWidget(p_listWidgetItem); + + delete p_vpnItem; + p_vpnItem = nullptr; + + delete p_listWidgetItem; + p_listWidgetItem = nullptr; + + iter = connectMap.erase(iter); + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); + } + return true; + } + } + + return false; +} + +void VpnPage::onRemoveConnection(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除 +{ + //for dbus + qDebug() << "[VpnPage] emit lanRemove because onRemoveConnection " << path; + Q_EMIT vpnRemove(path); + + removeConnectionItem(m_vpnItemMap, m_listWidget, path); + removeConnectionItem(m_activeItemMap, m_listWidget, path); + resetPageHeight(); + resetWindowPosition(); + this->update(); +} + +void VpnPage::onAddConnection(QString uuid) //新增一个有线连接,将其加入到激活列表 +{ + if (!m_connectResourse->isVirtualConncection(uuid)) { + return; + } + + KyConnectItem *p_newItem = nullptr; + p_newItem = m_connectResourse->getConnectionItemByUuid(uuid); + if (nullptr == p_newItem) { + return; + } + + sendVpnAddSignal(p_newItem); + + qDebug()<<"[VpnPage] Add a new connection, name:"<m_connectName; + QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget); + if (m_vpnItemMap.contains(p_newItem->m_connectUuid)) { + qDebug()<m_connectUuid; + } + m_vpnItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); + + delete p_newItem; + p_newItem = nullptr; + if (m_listWidget->count() >= MAX_ITEMS) { + m_listFrame->setFixedWidth(MAX_WIDTH); + } + resetPageHeight(); + resetWindowPosition(); + this->update(); + return; +} + +void VpnPage::onShowControlCenter() +{ + QProcess process; + process.startDetached("ukui-control-center -m vpn"); +} + +void VpnPage::initUI() +{ + m_titleLabel->setText(tr("VPN")); + +// m_listFrame->setMaximumHeight(MAX_ITEMS * ITEM_HEIGHT + ITEM_SPACE); + + m_listWidget->setFrameShape(QFrame::Shape::NoFrame); + m_listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_listWidget->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel); + m_listWidget->verticalScrollBar()->setProperty("drawScrollBarGroove",false); //去除滚动条的外侧黑框 + m_listWidget->verticalScrollBar()->setSingleStep(SCROLL_STEP); + m_listWidget->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu); + + m_settingsLabel->setText(tr("VPN Settings")); + m_settingsLabel->installEventFilter(this); +} + +QListWidgetItem *VpnPage::insertNewItem(KyConnectItem *itemData, QListWidget *listWidget) +{ + int index = 0; + + for(index = 0; index < m_listWidget->count(); index++) { + QListWidgetItem *p_listWidgetItem = m_listWidget->item(index); + VpnListItem *p_vpnItem = (VpnListItem *)m_listWidget->itemWidget(p_listWidgetItem); + QString name1 = p_vpnItem->getConnectionName(); + QString name2 = itemData->m_connectName; + if (QString::compare(name1, name2, Qt::CaseInsensitive) > 0) { + break; + } + } + + QListWidgetItem *p_sortListWidgetItem = new QListWidgetItem(); + p_sortListWidgetItem->setFlags(p_sortListWidgetItem->flags() & (~Qt::ItemIsSelectable)); //设置不可被选中 + p_sortListWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT)); + + listWidget->insertItem(index, p_sortListWidgetItem); + + VpnListItem *p_sortLanItem = nullptr; + p_sortLanItem = new VpnListItem(itemData); + listWidget->setItemWidget(p_sortListWidgetItem, p_sortLanItem); + + return p_sortListWidgetItem; +} + +QListWidgetItem *VpnPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget) +{ + QListWidgetItem *p_listWidgetItem = new QListWidgetItem(); + p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); + p_listWidgetItem->setSizeHint(QSize(listWidget->width() - 16, ITEM_HEIGHT)); + listWidget->addItem(p_listWidgetItem); + VpnListItem *p_vpnItem = nullptr; + if (itemData != nullptr) { + p_vpnItem = new VpnListItem(itemData); + qDebug() << "[VpnPage] addNewItem, connection: " << itemData->m_connectName; + } else { + p_vpnItem = new VpnListItem(); + qDebug() << "[VpnPage] Add nullItem!"; + } + + listWidget->setItemWidget(p_listWidgetItem, p_vpnItem); + return p_listWidgetItem; +} + +void VpnPage::updateActivatedConnectionArea(KyConnectItem *p_newItem) +{ + if (m_activeItemMap.contains(p_newItem->m_connectUuid)) { + return; + } + + deleteConnectionMapItem(m_vpnItemMap, m_listWidget, p_newItem->m_connectUuid); + qDebug()<<"[VpnPage]update active connection item"<m_connectName; + deleteConnectionMapItem(m_activeItemMap, m_listWidget, p_newItem->m_connectUuid); + QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_listWidget); + m_activeItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); + } + + return; +} + +void VpnPage::updateConnectionArea(KyConnectItem *p_newItem) +{ + if (m_vpnItemMap.contains(p_newItem->m_connectUuid)) { + return; + } + + deleteConnectionMapItem(m_activeItemMap, m_listWidget, p_newItem->m_connectUuid); + qDebug()<<"[VpnPage] update connection item"<m_connectName; + QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget); + m_vpnItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); + + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); + } else { + m_listFrame->setFixedWidth(MAX_WIDTH); + } +} + +void VpnPage::updateConnectionState(QMap &connectMap, + QListWidget *vpnListWidget, QString uuid, ConnectState state) +{ + qDebug() << LOG_FLAG << "update connection state"; + + QListWidgetItem *p_listWidgetItem = connectMap.value(uuid); + if (p_listWidgetItem) { + VpnListItem *p_vpnItem = (VpnListItem *)vpnListWidget->itemWidget(p_listWidgetItem); + p_vpnItem->updateConnectionState(state); + } + +} + +void VpnPage::onConnectionStateChange(QString uuid, + NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason) +{ + //VpnPage函数内持续监听连接状态的变化并记录供其他函数调用获取状态 + if (!m_connectResourse->isVirtualConncection(uuid)) { + qDebug() << "[VpnPage] connection state change signal but not vpn"; + return; + } + + sendVpnStateChangeSignal(uuid, (ConnectState)state); + + if (m_activeItemMap.keys().contains(uuid) && state == NetworkManager::ActiveConnection::State::Activated) { + return; + } + + qDebug()<<"[VpnPage] connection uuid"<< uuid + << "state change slot:"<< state; + + KyConnectItem *p_newItem = nullptr; + QString deviceName = ""; + QString ssid = ""; + + if (state == NetworkManager::ActiveConnection::State::Activated) { + p_newItem = m_activeResourse->getActiveConnectionByUuid(uuid); + if (nullptr == p_newItem) { + qWarning()<<"[VpnPage] get active connection failed, connection uuid" << uuid; + return; + } + + ssid = p_newItem->m_connectName; + updateActivatedConnectionArea(p_newItem); + updateConnectionState(m_activeItemMap, m_listWidget, uuid, (ConnectState)state); + } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { + p_newItem = m_connectResourse->getConnectionItemByUuid(uuid); + qDebug() << "[VpnPage] deactivated reason" << reason; + if (nullptr == p_newItem) { + qWarning()<<"[VpnPage] get active connection failed, connection uuid" << uuid; + return; + } + + ssid = p_newItem->m_connectName; + updateConnectionArea(p_newItem); + updateConnectionState(m_vpnItemMap, m_listWidget, uuid, (ConnectState)state); + } else if (state == NetworkManager::ActiveConnection::State::Activating) { + updateConnectionState(m_vpnItemMap, m_listWidget, uuid, (ConnectState)state); + } else if (state == NetworkManager::ActiveConnection::State::Deactivating) { + updateConnectionState(m_activeItemMap, m_listWidget, uuid, (ConnectState)state); + } + + Q_EMIT vpnActiveConnectionStateChanged(uuid, state); + + if (p_newItem) { + delete p_newItem; + p_newItem = nullptr; + } + + return; +} + +void VpnPage::getVirtualList(QVector &vector) +{ + QList netConnectList; + vector.clear(); + m_connectResourse->getVpnAndVirtualConnections(netConnectList); //未激活列表的显示 + if (!netConnectList.isEmpty()) { + for (int i = 0; i < netConnectList.size(); i++) { + KyConnectItem *p_newItem = nullptr; + KyConnectItem *p_netConnectionItem = netConnectList.at(i); + p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid); + NetworkManager::ActiveConnection::State state = p_netConnectionItem->m_connectState; + if (p_newItem != nullptr) { + state = NetworkManager::ActiveConnection::Activated; + } + vector.append(QStringList() << netConnectList.at(i)->m_connectName + << netConnectList.at(i)->m_connectUuid + << netConnectList.at(i)->m_connectPath + << QString::number(state)); + } + } + return; +} + +void VpnPage::sendVpnUpdateSignal(KyConnectItem *p_connectItem) +{ + QStringList info; + info << p_connectItem->m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath; + Q_EMIT vpnUpdate(info); + + return; +} + +void VpnPage::sendVpnAddSignal(KyConnectItem *p_connectItem) +{ + QStringList info; + KyConnectItem *p_newItem = nullptr; + p_newItem = m_activeResourse->getActiveConnectionByUuid(p_connectItem->m_connectUuid); + NetworkManager::ActiveConnection::State state = p_connectItem->m_connectState; + if (p_newItem != nullptr) { + state = NetworkManager::ActiveConnection::Activated; + } + info << p_connectItem->m_connectName + << p_connectItem->m_connectUuid + << p_connectItem->m_connectPath + << QString::number(state); + qDebug() << "[VpnPage] emit vpnAdd because addConnection "; + Q_EMIT vpnAdd(info); + + return; +} + +void VpnPage::sendVpnStateChangeSignal(QString uuid, ConnectState state) +{ + if (state == Activating || state == Deactivating) { + if (m_activeResourse->connectionIsVirtual(uuid)) { + return; + } + } + + Q_EMIT this->vpnConnectChanged(state); + + return; +} + +void VpnPage::updateConnectionProperty(KyConnectItem *p_connectItem) +{ + QString newUuid = p_connectItem->m_connectUuid; + + if (m_vpnItemMap.contains(newUuid)) { + QListWidgetItem *p_listWidgetItem = m_vpnItemMap.value(newUuid); + VpnListItem *p_vpnItem = (VpnListItem*)m_listWidget->itemWidget(p_listWidgetItem); + if (p_connectItem->m_connectName != p_vpnItem->getConnectionName()){ + //只要名字改变就要删除,重新插入,主要是为了排序 + deleteConnectionMapItem(m_vpnItemMap, m_listWidget, newUuid); + QListWidgetItem *p_sortListWidgetItem = insertNewItem(p_connectItem, m_listWidget); + if (m_vpnItemMap.contains(newUuid)) { + qDebug()<m_connectPath != p_vpnItem->getConnectionPath()) { + p_vpnItem->updateConnectionPath(p_connectItem->m_connectPath); + } + } else if (!m_activeItemMap.contains(newUuid)){ + if (p_connectItem->m_ifaceName.isEmpty()) { + QListWidgetItem *p_listWidgetItem = insertNewItem(p_connectItem, m_listWidget); + if (m_vpnItemMap.contains(newUuid)) { + qDebug()<m_connectUuid; + + if (m_activeItemMap.contains(newUuid)) { + QListWidgetItem *p_listWidgetItem = m_activeItemMap.value(newUuid); + VpnListItem *p_vpnItem = (VpnListItem *)m_listWidget->itemWidget(p_listWidgetItem); + if (p_vpnItem->getConnectionName() != p_connectItem->m_connectName) { + p_vpnItem->updateConnectionName(p_connectItem->m_connectName); + } + + if (p_vpnItem->getConnectionName() != p_connectItem->m_connectPath) { + p_vpnItem->updateConnectionPath(p_connectItem->m_connectPath); + } + } + return; +} + +void VpnPage::onUpdateConnection(QString uuid) +{ + if (!m_connectResourse->isVirtualConncection(uuid)) { + return; + } + + qDebug() << "[VpnPage]:Connection property Changed." << Q_FUNC_INFO << __LINE__; + + KyConnectItem *p_newItem = nullptr; + if (m_connectResourse->isActivatedConnection(uuid)) { + p_newItem = m_activeResourse->getActiveConnectionByUuid(uuid); + if (nullptr == p_newItem) { + qWarning()<<"[VpnPage] get item failed, when update activate connection." + <<"connection uuid" << uuid; + return; + } + + updateActiveConnectionProperty(p_newItem); + } else { + p_newItem = m_connectResourse->getConnectionItemByUuid(uuid); + if (nullptr == p_newItem) { + qWarning()<<"[VpnPage] get item failed, when update connection." + <<"connection uuid"<type() == QEvent::MouseButtonRelease) { + onShowControlCenter(); + } + } + + return QWidget::eventFilter(watched, event); +} + +void VpnPage::deleteVpn(const QString &connUuid) +{ + qDebug() << "[VpnPage] deleteVpn" << connUuid; + if (connUuid == nullptr) { + return; + } + m_vpnConnectOperation->deleteVpnConnect(connUuid); +} + +void VpnPage::activateVpn(const QString& connUuid) +{ + if (m_vpnItemMap.contains(connUuid)) { + qDebug() << "[VpnPage] activateVpn" << connUuid; + m_vpnConnectOperation->activateVpnConnection(connUuid); + } +} + +void VpnPage::deactivateVpn(const QString& connUuid) +{ + qDebug() << "[VpnPage] deactivateVpn" << connUuid; + QString name(""); + m_vpnConnectOperation->deactivateVpnConnection(name, connUuid); +} + +void VpnPage::showDetailPage(QString uuid) +{ + QListWidgetItem * vpnlistItem = m_vpnItemMap.value(uuid); + VpnListItem *vpnItem = (VpnListItem *)m_listWidget->itemWidget(vpnlistItem); + vpnItem->onInfoButtonClicked(); +} + +void VpnPage::showUI() +{ + //2209中窗管在hide界面时会刷新属性,需要重新设置无图标属性 + const KWindowInfo info(this->winId(), NET::WMState); + if (!info.hasState(NET::SkipTaskbar) || !info.hasState(NET::SkipPager)) { + KWindowSystem::setState(this->winId(), NET::SkipTaskbar | NET::SkipPager); + } + + resetPageHeight(); + + showNormal(); + raise(); + activateWindow(); + resetWindowPosition(); + return; +} + +void VpnPage::resetWindowPosition() +{ + +#define MARGIN 4 +#define PANEL_TOP 1 +#define PANEL_LEFT 2 +#define PANEL_RIGHT 3 +//#define PANEL_BOTTOM 4 + if (!m_positionInterface) { + m_positionInterface = new QDBusInterface("org.ukui.panel", + "/panel/position", + "org.ukui.panel", + QDBusConnection::sessionBus()); + } + QRect rect; + QDBusReply reply = m_positionInterface->call("GetPrimaryScreenGeometry"); + //reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置 + if (!m_positionInterface->isValid() || !reply.isValid() || reply.value().size() < 5) { + qCritical() << QDBusConnection::sessionBus().lastError().message(); + kdk::WindowManager::setGeometry(this->windowHandle(), QRect(0, 0, this->width(), this->height())); + return; + } + QVariantList position_list = reply.value(); + int position = position_list.at(4).toInt(); + switch(position){ + case PANEL_TOP: + //任务栏位于上方 + rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, + position_list.at(1).toInt() + MARGIN, + this->width(), this->height()); + break; + //任务栏位于左边 + case PANEL_LEFT: + rect = QRect(position_list.at(0).toInt() + MARGIN, + position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, + this->width(), this->height()); + break; + //任务栏位于右边 + case PANEL_RIGHT: + rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, + position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, + this->width(), this->height()); + break; + //任务栏位于下方 + default: + rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, + position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, + this->width(), this->height()); + break; + } + kdk::WindowManager::setGeometry(this->windowHandle(), rect); + qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__; +} diff --git a/src-vpn/frontend/single-pages/vpnpage.h b/src-vpn/frontend/single-pages/vpnpage.h new file mode 100644 index 00000000..0b7dec31 --- /dev/null +++ b/src-vpn/frontend/single-pages/vpnpage.h @@ -0,0 +1,137 @@ +/* -*- 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 VPNPAGE_H +#define VPNPAGE_H + +#include "divider.h" +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "list-items/listitem.h" +#include "list-items/vpnlistitem.h" +#include "single-pages/singlepage.h" + +#define VPNPAGE_LAYOUT_MARGINS 0,0,0,0 +#define VPN_LIST_SPACING 0 +#define ITEM_HEIGHT 50 +#define ITEM_SPACE 16 +#define PAGE_SPACE 22 + +#define LOG_FLAG "[VpnPage]" + +#define VISIBLE "visible" +const QByteArray GSETTINGS_VPNICON_VISIBLE = "org.ukui.kylin-nm.vpnicon"; + +class VpnListItem; + +class VpnPage : public SinglePage +{ + Q_OBJECT +public: + explicit VpnPage(QWidget *parent = nullptr); + ~VpnPage(); + + //for dbus + void getVirtualList(QVector &vector); + void deleteVpn(const QString &connUuid); + void activateVpn(const QString& connUuid); + void deactivateVpn(const QString& connUuid); + void showDetailPage(QString uuid); + +protected: + bool eventFilter(QObject *watched, QEvent *event); + +private: + void initUI(); + void initVpnArea(); + void resetPageHeight(); + + inline void initDeviceCombox() { return; } + + QListWidgetItem *insertNewItem(KyConnectItem *itemData, QListWidget *listWidget); + QListWidgetItem *addNewItem(KyConnectItem *itemData, QListWidget *listWidget); + bool removeConnectionItem(QMap &connectMap, + QListWidget *vpnListWidget, QString path); + + void constructItemArea(); + + void updateConnectionArea(KyConnectItem *p_newItem); + void updateActivatedConnectionArea(KyConnectItem *p_newItem); + void updateConnectionState(QMap &connectMap, + QListWidget *vpnListWidget, QString uuid, ConnectState state); + + void updateActiveConnectionProperty(KyConnectItem *p_connectItem); + void updateConnectionProperty(KyConnectItem *p_connectItem); + + void sendVpnUpdateSignal(KyConnectItem *p_connectItem); + void sendVpnAddSignal(KyConnectItem *p_connectItem); + void sendVpnStateChangeSignal(QString uuid, ConnectState state); + + void clearConnectionMap(QMap &connectMap, + QListWidget *vpnListWidget); + void deleteConnectionMapItem(QMap &connectMap, + QListWidget *vpnListWidget, QString uuid); + + void resetWindowPosition(); + + +Q_SIGNALS: + void vpnAdd(QStringList info); + void vpnRemove(QString dbusPath); + void vpnUpdate(QStringList info); + + void vpnActiveConnectionStateChanged(QString uuid, int status); + void vpnConnectChanged(int state); + +private Q_SLOTS: + void onConnectionStateChange(QString uuid, + NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason); + + void onAddConnection(QString uuid); + void onRemoveConnection(QString path); + void onUpdateConnection(QString uuid); + + void onShowControlCenter(); + +private: + KyVpnConnectOperation *m_vpnConnectOperation = nullptr; + KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接 + KyConnectResourse *m_connectResourse = nullptr; //未激活的连接 + + QMap m_vpnItemMap; + QMap m_activeItemMap; + + QDBusInterface * m_positionInterface = nullptr; + + + +public Q_SLOTS: + void showUI(); +}; + +#endif // LANPAGE_H diff --git a/src-vpn/frontend/vpnobject.cpp b/src-vpn/frontend/vpnobject.cpp new file mode 100644 index 00000000..9b163f20 --- /dev/null +++ b/src-vpn/frontend/vpnobject.cpp @@ -0,0 +1,138 @@ +#include "vpnobject.h" +#include + +#include "ukuistylehelper/ukuistylehelper.h" + +vpnObject::vpnObject(QMainWindow *parent) : QMainWindow(parent) +{ + initUI(); + initTrayIcon(); + initDbusConnnect(); +} + +vpnObject::~vpnObject() +{ + if (m_vpnGsettings != nullptr) { + delete m_vpnGsettings; + m_vpnGsettings = nullptr; + } +} + +void vpnObject::initUI() +{ + m_vpnPage = new VpnPage(nullptr); + m_vpnPage->update(); + +} + +void vpnObject::initTrayIcon() +{ + m_vpnTrayIcon = new QSystemTrayIcon(this); + m_vpnTrayIcon->setToolTip(QString(tr("vpn tool"))); + m_vpnTrayIcon->setIcon(QIcon::fromTheme("ukui-vpn-symbolic")); + m_vpnTrayIcon->setVisible(true); + initVpnIconVisible(); + connect(m_vpnTrayIcon, &QSystemTrayIcon::activated, this, &vpnObject::onTrayIconActivated); +} + +void vpnObject::initVpnIconVisible() +{ + if (QGSettings::isSchemaInstalled(QByteArray(GSETTINGS_VPNICON_VISIBLE))) { + m_vpnGsettings = new QGSettings(QByteArray(GSETTINGS_VPNICON_VISIBLE)); + if (m_vpnGsettings->keys().contains(QString(VISIBLE))) { + m_vpnTrayIcon->setVisible(m_vpnGsettings->get(VISIBLE).toBool()); + connect(m_vpnGsettings, &QGSettings::changed, this, [=]() { + m_vpnTrayIcon->setVisible(m_vpnGsettings->get(VISIBLE).toBool()); + }); + } + } +} + +/** + * @brief vpnObject::onTrayIconActivated 点击托盘图标的槽函数 + */ +void vpnObject::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason) +{ + switch(reason) { + case QSystemTrayIcon::Trigger: + if(m_vpnPage->isActiveWindow()) { + m_vpnPage->hide(); + } else { + onShowMainWindow(); + } + break; + + default: + break; + } +} + +void vpnObject::getVirtualList(QVector &vector) +{ + vector.clear(); + if (nullptr != m_vpnPage) { + m_vpnPage->getVirtualList(vector); + } +} + +//Vpn连接删除 +void vpnObject::deleteVpn(const QString &connUuid) +{ + m_vpnPage->deleteVpn(connUuid); +} + +//Vpn连接断开 +void vpnObject::activateVpn(const QString& connUuid) +{ + m_vpnPage->activateVpn(connUuid); +} +void vpnObject::deactivateVpn(const QString& connUuid) +{ + m_vpnPage->deactivateVpn(connUuid); +} + +void vpnObject::showDetailPage(const QString& connUuid) +{ + m_vpnPage->showDetailPage(connUuid); +} + + +void vpnObject::onShowMainWindow() +{ + kdk::UkuiStyleHelper::self()->removeHeader(m_vpnPage); + m_vpnPage->showUI(); +} + +void vpnObject::initDbusConnnect() +{ + connect(m_vpnPage, &VpnPage::activateFailed, this, &vpnObject::activateFailed); + connect(m_vpnPage, &VpnPage::deactivateFailed, this, &vpnObject::deactivateFailed); + + connect(m_vpnPage, &VpnPage::vpnAdd, this, &vpnObject::vpnAdd); + connect(m_vpnPage, &VpnPage::vpnRemove, this, &vpnObject::vpnRemove); + connect(m_vpnPage, &VpnPage::vpnUpdate, this, &vpnObject::vpnUpdate); + connect(m_vpnPage, &VpnPage::vpnActiveConnectionStateChanged, this, &vpnObject::vpnActiveConnectionStateChanged); + //模式切换 + QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), + QString("/"), + QString("com.kylin.statusmanager.interface"), + QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool))); +} + +void vpnObject::onTabletModeChanged(bool mode) +{ + qDebug() << "TabletMode change" << mode; + Q_UNUSED(mode) + //模式切换时,隐藏主界面 + m_vpnPage->hide(); +} + +void vpnObject::showVpnAddWidget() +{ + if (m_vpnAddPage == nullptr) { + m_vpnAddPage = new vpnAddPage(); + connect(m_vpnAddPage, &vpnAddPage::closed, [&] () {m_vpnAddPage = nullptr;}); + m_vpnAddPage->show(); + } + m_vpnAddPage->raise(); +} diff --git a/src-vpn/frontend/vpnobject.h b/src-vpn/frontend/vpnobject.h new file mode 100644 index 00000000..20c3ab57 --- /dev/null +++ b/src-vpn/frontend/vpnobject.h @@ -0,0 +1,75 @@ +#ifndef VPNOBJECT_H +#define VPNOBJECT_H + +#include +#include +#include +#include +#include + +#include "vpnpage.h" +#include "vpnaddpage.h" +class VpnPage; + +#define VISIBLE "visible" +#define GSETTINGS_VPNICON_VISIBLE "org.ukui.kylin-nm.vpnicon" +//const QByteArray GSETTINGS_VPNICON_VISIBLE = "org.ukui.kylin-nm.vpnicon"; + + +class vpnObject : public QMainWindow +{ + Q_OBJECT +public: + explicit vpnObject(QMainWindow *parent = nullptr); + ~vpnObject(); + + void getVirtualList(QVector &vector); + //Vpn连接删除 + void deleteVpn(const QString &connUuid); + //有线连接断开 + void activateVpn(const QString& connUuid); + void deactivateVpn(const QString& connUuid); + + void showDetailPage(const QString& connUuid); + + void showVpnAddWidget(); + +private: + void initUI(); + void initTrayIcon(); + void initVpnIconVisible(); + void initDbusConnnect(); + + +private: + VpnPage *m_vpnPage = nullptr; + QSystemTrayIcon * m_vpnTrayIcon = nullptr; + QGSettings * m_vpnGsettings; //VPN配置文件 + double tran =1; + QGSettings *StyleSettings = nullptr; + QWidget * vpnWidget = nullptr; + + QDBusInterface * m_positionInterface = nullptr; + bool m_isShowInCenter = false; + + vpnAddPage *m_vpnAddPage = nullptr; + +public Q_SLOTS: + void onShowMainWindow(); + +private Q_SLOTS: + void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason); + void onTabletModeChanged(bool mode); + + +Q_SIGNALS: + void vpnAdd(QStringList info); + void vpnRemove(QString dbusPath); + void vpnUpdate(QStringList info); + void vpnActiveConnectionStateChanged(QString uuid, int status); + void activateFailed(QString errorMessage); + void deactivateFailed(QString errorMessage); + void mainWindowVisibleChanged(const bool &visible); +}; + +#endif // VPNOBJECT_H diff --git a/src-vpn/kylin-vpn.desktop b/src-vpn/kylin-vpn.desktop new file mode 100644 index 00000000..464e2869 --- /dev/null +++ b/src-vpn/kylin-vpn.desktop @@ -0,0 +1,18 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Kylin VPN +Name[zh_CN]=麒麟VPN设置工具 +Name[zh_HK]=麒麟VPN設置工具 +Name[zh_TW]=麒麟VPN設置工具 +Icon=gnome-dev-ethernet +Comment=Beautiful Network Config Applet +Comment[zh_CN]=麒麟VPN设置工具,提供查看和简单设置功能,拥有美观的界面和舒适的操作. +Keywords=applet;vpn;network;network-manager; +Exec=/usr/bin/kylin-vpn +StartupNotify=false +Terminal=false +Type=Application +OnlyShowIn=UKUI +X-UKUI-AutoRestart=true +NoDisplay=true +X-UKUI-Autostart-Phase=Application diff --git a/src-vpn/main.cpp b/src-vpn/main.cpp new file mode 100644 index 00000000..f7f309e7 --- /dev/null +++ b/src-vpn/main.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2020 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 3, 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, see +#include +#include "qt-single-application.h" +#include +#include +#include +#include +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) +#include "xatom-helper.h" +#endif + +#include "vpnobject.h" + +#define LOG_IDENT "kylin_vpn" + +const QString QT_TRANSLATE_FILE = "/usr/share/qt5/translations/qt_zh_CN.qm"; + +void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + QByteArray localMsg = msg.toLocal8Bit(); + QByteArray currentDateTime = QDateTime::currentDateTime().toString().toLocal8Bit(); + + bool showDebug = true; + QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/ukui/kylin-nm.log"; + FILE *log_file = nullptr; + + if (showDebug) { + log_file = fopen(logFilePath.toLocal8Bit().constData(), "a+"); + } + + const char *file = context.file ? context.file : ""; + const char *function = context.function ? context.function : ""; + switch (type) { + case QtDebugMsg: + if (!log_file) { + break; + } + fprintf(log_file, "Debug: %s: %s (%s:%u, %s)\n", currentDateTime.constData(), localMsg.constData(), file, context.line, function); + break; + case QtInfoMsg: + fprintf(log_file? log_file: stdout, "Info: %s: %s (%s:%u, %s)\n", currentDateTime.constData(), localMsg.constData(), file, context.line, function); + break; + case QtWarningMsg: + fprintf(log_file? log_file: stderr, "Warning: %s: %s (%s:%u, %s)\n", currentDateTime.constData(), localMsg.constData(), file, context.line, function); + break; + case QtCriticalMsg: + fprintf(log_file? log_file: stderr, "Critical: %s: %s (%s:%u, %s)\n", currentDateTime.constData(), localMsg.constData(), file, context.line, function); + break; + case QtFatalMsg: + fprintf(log_file? log_file: stderr, "Fatal: %s: %s (%s:%u, %s)\n", currentDateTime.constData(), localMsg.constData(), file, context.line, function); + break; + } + + if (log_file) + fclose(log_file); +} + +int main(int argc, char *argv[]) +{ + initUkuiLog4qt("kylin-vpn"); + + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + + QString id = QString("kylin-vpn"+ QLatin1String(getenv("DISPLAY"))); + QtSingleApplication a(id, argc, argv); + + QApplication::setQuitOnLastWindowClosed(false); + + QThread thread; + KyNetworkResourceManager *p_networkResource = KyNetworkResourceManager::getInstance(); + p_networkResource->moveToThread(&thread); + QObject::connect(&thread, SIGNAL(started()), p_networkResource, SLOT(onInitNetwork())); + thread.start(); + + // Internationalization + QString locale = QLocale::system().name(); + QTranslator trans_global; + qDebug() << "QLocale " << QLocale(); + if (trans_global.load(QLocale(), "kylin-vpn", "_", ":/translations/")) + { + a.installTranslator(&trans_global); + qDebug()<<"Translations load success"; + } else { + qWarning() << "Translations load fail"; + } + + QTranslator qtBaseTranslator; + if (qtBaseTranslator.load(QLocale(), "qt", "_", "/usr/share/qt5/translations/")) + { + a.installTranslator(&qtBaseTranslator); + qDebug()<<"QtBase Translations load success"; + } else { + qWarning() << "QtBase Translations load fail"; + } + + while (!p_networkResource->NetworkManagerIsInited()) { + ::usleep(1000); + } + + vpnObject vpnobject; + a.setActivationWindow(&vpnobject); + vpnobject.setProperty("useStyleWindowManager", false); //禁用拖动 + a.setWindowIcon(QIcon::fromTheme("ukui-vpn-symbolic")); + + VpnDbusAdaptor vpnAdaptor(&vpnobject); + Q_UNUSED(vpnAdaptor); + + auto connection = QDBusConnection::sessionBus(); + if (!connection.registerService("com.kylin.kylinvpn") + || !connection.registerObject("/com/kylin/kylinvpn", &vpnobject)) { + qCritical() << "QDbus register service failed reason:" << connection.lastError(); + } + + return a.exec(); +} diff --git a/src-vpn/org.ukui.kylin-vpn.switch.gschema.xml b/src-vpn/org.ukui.kylin-vpn.switch.gschema.xml new file mode 100644 index 00000000..47add632 --- /dev/null +++ b/src-vpn/org.ukui.kylin-vpn.switch.gschema.xml @@ -0,0 +1,9 @@ + + + + false + vpnicon visible + vpnicon visible.true is visible,false is invisible. + + + diff --git a/src-vpn/singleapplication/qt-local-peer.cpp b/src-vpn/singleapplication/qt-local-peer.cpp new file mode 100644 index 00000000..4a62537c --- /dev/null +++ b/src-vpn/singleapplication/qt-local-peer.cpp @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies) +** 2020 KylinSoft Co., Ltd. +** Contact: http://www.qt-project.org/legal +** +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +** +****************************************************************************/ + + +#include "qt-local-peer.h" +#include +#include +#include + +#if defined(Q_OS_UNIX) +#include +#include +#include +#endif + +namespace QtLP_Private { +#include "qt-locked-file.cpp" +#include "qt-locked-file-unix.cpp" +} + +const char* QtLocalPeer::ack = "ack"; + +QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) + : QObject(parent), id(appId) { + QString prefix = id; + if(id.isEmpty()) { + id = QCoreApplication::applicationFilePath(); +#if defined(Q_OS_WIN) + id = id.toLower(); +#endif + prefix = id.section(QLatin1Char('/'), -1); //完整路径按‘/’分隔后取最后一个字段 + } + prefix.remove(QRegExp("[^a-zA-Z]")); //去掉名称中的非字母 + prefix.truncate(6); //取前六位 + + QByteArray idc = id.toUtf8(); + quint16 idNum = qChecksum(idc.constData(), idc.size()); + socketName = QLatin1String("qtsingleapp-") + prefix + + QLatin1Char('-') + QString::number(idNum, 16); + +#if defined(Q_OS_WIN) + if(!pProcessIdToSessionId) { + QLibrary lib("kernel32"); + pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId"); + } + if(pProcessIdToSessionId) { + DWORD sessionId = 0; + pProcessIdToSessionId(GetCurrentProcessId(), &sessionId); + socketName += QLatin1Char('-') + QString::number(sessionId, 16); + } +#else + socketName += QLatin1Char('-') + QString::number(::getuid(), 16); +#endif + + server = new QLocalServer(this); + QString lockName = QDir(QDir::tempPath()).absolutePath() + + QLatin1Char('/') + socketName + + QLatin1String("-lockfile"); //tmp目录下的锁文件 + lockFile.setFileName(lockName); + lockFile.open(QIODevice::ReadWrite); +} + + + +bool QtLocalPeer::isClient() { + if(lockFile.isLocked()) + return false; + + if(!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) + return true; + + //由于文件锁的存在,仅当本进程第一次启动时能执行到此并使server进行监听和关联槽函数 + bool res = server->listen(socketName); +#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) + // ### Workaround + if(!res && server->serverError() == QAbstractSocket::AddressInUseError) { + QFile::remove(QDir::cleanPath(QDir::tempPath()) + QLatin1Char('/') + socketName); + res = server->listen(socketName); + } +#endif + if(!res) + qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString())); + QObject::connect(server, &QLocalServer::newConnection, this, &QtLocalPeer::receiveConnection); + return false; +} + + +bool QtLocalPeer::sendMessage(const QString &message, int timeout) { + if(!isClient()) + return false; + + QLocalSocket socket; + bool connOk = false; + for(int i = 0; i < 2; i++) { + // Try twice, in case the other instance is just starting up + socket.connectToServer(socketName); + connOk = socket.waitForConnected(timeout / 2); + if(connOk || i) + break; + int ms = 250; +#if defined(Q_OS_WIN) + Sleep(DWORD(ms)); +#else + struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; + nanosleep(&ts, NULL); +#endif + } + if(!connOk) + return false; + + QByteArray uMsg(message.toUtf8()); + QDataStream ds(&socket); + ds.writeBytes(uMsg.constData(), uMsg.size()); + bool res = socket.waitForBytesWritten(timeout); + if(res) { + res &= socket.waitForReadyRead(timeout); // wait for ack + if(res) + res &= (socket.read(qstrlen(ack)) == ack); + } + return res; +} + +/** + * @brief QtLocalPeer::receiveConnection 当新进程启动时,会尝试连接此进程server,server接收到newConnection信号并触发此槽函数 + */ +void QtLocalPeer::receiveConnection() { + QLocalSocket* socket = server->nextPendingConnection(); //获取新进程的socket + if(!socket) + return; + + while(true) { + if(socket->state() == QLocalSocket::UnconnectedState) { + qWarning("QtLocalPeer: Peer disconnected"); + delete socket; + return; + } + if(socket->bytesAvailable() >= qint64(sizeof(quint32))) + break; + socket->waitForReadyRead(); + } + + QDataStream ds(socket); + QByteArray uMsg; + quint32 remaining; + ds >> remaining; + uMsg.resize(remaining); + int got = 0; + char* uMsgBuf = uMsg.data(); + do { + got = ds.readRawData(uMsgBuf, remaining); + remaining -= got; + uMsgBuf += got; + } while(remaining && got >= 0 && socket->waitForReadyRead(2000)); + if(got < 0) { + qWarning("QtLocalPeer: Message reception failed %s", socket->errorString().toLatin1().constData()); + delete socket; + return; + } + QString message(QString::fromUtf8(uMsg)); + socket->write(ack, qstrlen(ack)); + socket->waitForBytesWritten(1000); + socket->waitForDisconnected(1000); // make sure client reads ack + delete socket; + Q_EMIT messageReceived(message); //获取新进程的启动信息并作为信号发送给前端 +} diff --git a/src-vpn/singleapplication/qt-local-peer.h b/src-vpn/singleapplication/qt-local-peer.h new file mode 100644 index 00000000..883aec2a --- /dev/null +++ b/src-vpn/singleapplication/qt-local-peer.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies) +** 2020 KylinSoft Co., Ltd. +** Contact: http://www.qt-project.org/legal +** +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +** +****************************************************************************/ + +#ifndef QTLOCALPEER_H +#define QTLOCALPEER_H + +#include +#include +#include + +#include "qt-locked-file.h" + +class QtLocalPeer : public QObject { + Q_OBJECT + +public: + QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); + bool isClient(); + bool sendMessage(const QString &message, int timeout); + QString applicationId() const { + return id; + } + +Q_SIGNALS: + void messageReceived(const QString &message); + +protected Q_SLOTS: + void receiveConnection(); + +protected: + QString id; + QString socketName; + QLocalServer* server; + QtLP_Private::QtLockedFile lockFile; + +private: + static const char* ack; +}; + +#endif // QTLOCALPEER_H diff --git a/src-vpn/singleapplication/qt-locked-file-unix.cpp b/src-vpn/singleapplication/qt-locked-file-unix.cpp new file mode 100644 index 00000000..51472520 --- /dev/null +++ b/src-vpn/singleapplication/qt-locked-file-unix.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies) +** 2020 KylinSoft Co., Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#include "qt-locked-file.h" + +bool QtLockedFile::lock(LockMode mode, bool block) { + if(!isOpen()) { + qWarning("QtLockedFile::lock(): file is not opened"); + return false; + } + + if(mode == NoLock) + return unlock(); + + if(mode == m_lock_mode) + return true; + + if(m_lock_mode != NoLock) + unlock(); + + struct flock fl; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK; + int cmd = block ? F_SETLKW : F_SETLK; + int ret = fcntl(handle(), cmd, &fl); + + if(ret == -1) { + if(errno != EINTR && errno != EAGAIN) + qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); + return false; + } + + + m_lock_mode = mode; + return true; +} + + +bool QtLockedFile::unlock() { + if(!isOpen()) { + qWarning("QtLockedFile::unlock(): file is not opened"); + return false; + } + + if(!isLocked()) + return true; + + struct flock fl; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + fl.l_type = F_UNLCK; + int ret = fcntl(handle(), F_SETLKW, &fl); + + if(ret == -1) { + qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); + return false; + } + + m_lock_mode = NoLock; + return true; +} + +QtLockedFile::~QtLockedFile() { + if(isOpen()) + unlock(); +} + diff --git a/src-vpn/singleapplication/qt-locked-file.cpp b/src-vpn/singleapplication/qt-locked-file.cpp new file mode 100644 index 00000000..707b4cfa --- /dev/null +++ b/src-vpn/singleapplication/qt-locked-file.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies) +** 2020 KylinSoft Co., Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qt-locked-file.h" + +/*! + \class QtLockedFile + + \brief The QtLockedFile class extends QFile with advisory locking + functions. + + A file may be locked in read or write mode. Multiple instances of + \e QtLockedFile, created in multiple processes running on the same + machine, may have a file locked in read mode. Exactly one instance + may have it locked in write mode. A read and a write lock cannot + exist simultaneously on the same file. + + The file locks are advisory. This means that nothing prevents + another process from manipulating a locked file using QFile or + file system functions offered by the OS. Serialization is only + guaranteed if all processes that access the file use + QLockedFile. Also, while holding a lock on a file, a process + must not open the same file again (through any API), or locks + can be unexpectedly lost. + + The lock provided by an instance of \e QtLockedFile is released + whenever the program terminates. This is true even when the + program crashes and no destructors are called. +*/ + +/*! \enum QtLockedFile::LockMode + + This enum describes the available lock modes. + + \value ReadLock A read lock. + \value WriteLock A write lock. + \value NoLock Neither a read lock nor a write lock. +*/ + +/*! + Constructs an unlocked \e QtLockedFile object. This constructor + behaves in the same way as \e QFile::QFile(). + + \sa QFile::QFile() +*/ +QtLockedFile::QtLockedFile() + : QFile() { +#ifdef Q_OS_WIN + wmutex = 0; + rmutex = 0; +#endif + m_lock_mode = NoLock; +} + +/*! + Constructs an unlocked QtLockedFile object with file \a name. This + constructor behaves in the same way as \e QFile::QFile(const + QString&). + + \sa QFile::QFile() +*/ +QtLockedFile::QtLockedFile(const QString &name) + : QFile(name) { +#ifdef Q_OS_WIN + wmutex = 0; + rmutex = 0; +#endif + m_lock_mode = NoLock; +} + +/*! + Opens the file in OpenMode \a mode. + + This is identical to QFile::open(), with the one exception that the + Truncate mode flag is disallowed. Truncation would conflict with the + advisory file locking, since the file would be modified before the + write lock is obtained. If truncation is required, use resize(0) + after obtaining the write lock. + + Returns true if successful; otherwise false. + + \sa QFile::open(), QFile::resize() +*/ +bool QtLockedFile::open(OpenMode mode) { + if(mode & QIODevice::Truncate) { + qWarning("QtLockedFile::open(): Truncate mode not allowed."); + return false; + } + return QFile::open(mode); +} + +/*! + Returns \e true if this object has a in read or write lock; + otherwise returns \e false. + + \sa lockMode() +*/ +bool QtLockedFile::isLocked() const { + return m_lock_mode != NoLock; +} + +/*! + Returns the type of lock currently held by this object, or \e + QtLockedFile::NoLock. + + \sa isLocked() +*/ +QtLockedFile::LockMode QtLockedFile::lockMode() const { + return m_lock_mode; +} + +/*! + \fn bool QtLockedFile::lock(LockMode mode, bool block = true) + + Obtains a lock of type \a mode. The file must be opened before it + can be locked. + + If \a block is true, this function will block until the lock is + aquired. If \a block is false, this function returns \e false + immediately if the lock cannot be aquired. + + If this object already has a lock of type \a mode, this function + returns \e true immediately. If this object has a lock of a + different type than \a mode, the lock is first released and then a + new lock is obtained. + + This function returns \e true if, after it executes, the file is + locked by this object, and \e false otherwise. + + \sa unlock(), isLocked(), lockMode() +*/ + +/*! + \fn bool QtLockedFile::unlock() + + Releases a lock. + + If the object has no lock, this function returns immediately. + + This function returns \e true if, after it executes, the file is + not locked by this object, and \e false otherwise. + + \sa lock(), isLocked(), lockMode() +*/ + +/*! + \fn QtLockedFile::~QtLockedFile() + + Destroys the \e QtLockedFile object. If any locks were held, they + are released. +*/ diff --git a/src-vpn/singleapplication/qt-locked-file.h b/src-vpn/singleapplication/qt-locked-file.h new file mode 100644 index 00000000..332d648e --- /dev/null +++ b/src-vpn/singleapplication/qt-locked-file.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies) +** 2020 KylinSoft Co., Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTLOCKEDFILE_H +#define QTLOCKEDFILE_H + +#include +#ifdef Q_OS_WIN +#include +#endif + +#if defined(Q_OS_WIN) +# if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT) +# define QT_QTLOCKEDFILE_EXPORT +# elif defined(QT_QTLOCKEDFILE_IMPORT) +# if defined(QT_QTLOCKEDFILE_EXPORT) +# undef QT_QTLOCKEDFILE_EXPORT +# endif +# define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport) +# elif defined(QT_QTLOCKEDFILE_EXPORT) +# undef QT_QTLOCKEDFILE_EXPORT +# define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport) +# endif +#else +# define QT_QTLOCKEDFILE_EXPORT +#endif + +namespace QtLP_Private { + +class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile { +public: + enum LockMode { NoLock = 0, ReadLock, WriteLock }; + + QtLockedFile(); + QtLockedFile(const QString &name); + ~QtLockedFile(); + + bool open(OpenMode mode); + + bool lock(LockMode mode, bool block = true); + bool unlock(); + bool isLocked() const; + LockMode lockMode() const; + +private: +#ifdef Q_OS_WIN + Qt::HANDLE wmutex; + Qt::HANDLE rmutex; + QVector rmutexes; + QString mutexname; + + Qt::HANDLE getMutexHandle(int idx, bool doCreate); + bool waitMutex(Qt::HANDLE mutex, bool doBlock); + +#endif + LockMode m_lock_mode; +}; +} +#endif diff --git a/src-vpn/singleapplication/qt-single-application.cpp b/src-vpn/singleapplication/qt-single-application.cpp new file mode 100644 index 00000000..b829be13 --- /dev/null +++ b/src-vpn/singleapplication/qt-single-application.cpp @@ -0,0 +1,351 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies) +** 2020 KylinSoft Co., Ltd. +** Contact: http://www.qt-project.org/legal +** +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +** +****************************************************************************/ + + +#include "qt-single-application.h" +#include "qt-local-peer.h" +#include +#include +#include +#include +#include +#include +#include "../vpnobject.h" + + +/*! + \class QtSingleApplication qtsingleapplication.h + \brief The QtSingleApplication class provides an API to detect and + communicate with running instances of an application. + + This class allows you to create applications where only one + instance should be running at a time. I.e., if the user tries to + launch another instance, the already running instance will be + activated instead. Another usecase is a client-server system, + where the first started instance will assume the role of server, + and the later instances will act as clients of that server. + + By default, the full path of the executable file is used to + determine whether two processes are instances of the same + application. You can also provide an explicit identifier string + that will be compared instead. + + The application should create the QtSingleApplication object early + in the startup phase, and call isRunning() to find out if another + instance of this application is already running. If isRunning() + returns false, it means that no other instance is running, and + this instance has assumed the role as the running instance. In + this case, the application should continue with the initialization + of the application user interface before entering the event loop + with exec(), as normal. + + The messageReceived() signal will be emitted when the running + application receives messages from another instance of the same + application. When a message is received it might be helpful to the + user to raise the application so that it becomes visible. To + facilitate this, QtSingleApplication provides the + setActivationWindow() function and the activateWindow() slot. + + If isRunning() returns true, another instance is already + running. It may be alerted to the fact that another instance has + started by using the sendMessage() function. Also data such as + startup parameters (e.g. the name of the file the user wanted this + new instance to open) can be passed to the running instance with + this function. Then, the application should terminate (or enter + client mode). + + If isRunning() returns true, but sendMessage() fails, that is an + indication that the running instance is frozen. + + Here's an example that shows how to convert an existing + application to use QtSingleApplication. It is very simple and does + not make use of all QtSingleApplication's functionality (see the + examples for that). + + \code + // Original + int main(int argc, char **argv) + { + QApplication app(argc, argv); + + MyMainWidget mmw; + mmw.show(); + return app.exec(); + } + + // Single instance + int main(int argc, char **argv) + { + QtSingleApplication app(argc, argv); + + if (app.isRunning()) + return !app.sendMessage(someDataString); + + MyMainWidget mmw; + app.setActivationWindow(&mmw); + mmw.show(); + return app.exec(); + } + \endcode + + Once this QtSingleApplication instance is destroyed (normally when + the process exits or crashes), when the user next attempts to run the + application this instance will not, of course, be encountered. The + next instance to call isRunning() or sendMessage() will assume the + role as the new running instance. + + For console (non-GUI) applications, QtSingleCoreApplication may be + used instead of this class, to avoid the dependency on the QtGui + library. + + \sa QtSingleCoreApplication +*/ + + +void QtSingleApplication::sysInit(const QString &appId) { + m_activateWindow = 0; + m_peer = new QtLocalPeer(this, appId); + connect(m_peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::messageReceived); +} + + +/*! + Creates a QtSingleApplication object. The application identifier + will be QCoreApplication::applicationFilePath(). \a argc, \a + argv, and \a GUIenabled are passed on to the QAppliation constructor. + + If you are creating a console application (i.e. setting \a + GUIenabled to false), you may consider using + QtSingleCoreApplication instead. +*/ + +QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled) + : QApplication(argc, argv, GUIenabled) { + sysInit(); +} + + +/*! + Creates a QtSingleApplication object with the application + identifier \a appId. \a argc and \a argv are passed on to the + QAppliation constructor. +*/ + +QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv) + : QApplication(argc, argv) { + sysInit(appId); +} + +#if QT_VERSION < 0x050000 + +/*! + Creates a QtSingleApplication object. The application identifier + will be QCoreApplication::applicationFilePath(). \a argc, \a + argv, and \a type are passed on to the QAppliation constructor. +*/ +QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) + : QApplication(argc, argv, type) { + sysInit(); +} + + +# if defined(Q_WS_X11) +/*! + Special constructor for X11, ref. the documentation of + QApplication's corresponding constructor. The application identifier + will be QCoreApplication::applicationFilePath(). \a dpy, \a visual, + and \a cmap are passed on to the QApplication constructor. +*/ +QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap) + : QApplication(dpy, visual, cmap) { + sysInit(); +} + +/*! + Special constructor for X11, ref. the documentation of + QApplication's corresponding constructor. The application identifier + will be QCoreApplication::applicationFilePath(). \a dpy, \a argc, \a + argv, \a visual, and \a cmap are passed on to the QApplication + constructor. +*/ +QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) + : QApplication(dpy, argc, argv, visual, cmap) { + sysInit(); +} + +/*! + Special constructor for X11, ref. the documentation of + QApplication's corresponding constructor. The application identifier + will be \a appId. \a dpy, \a argc, \a + argv, \a visual, and \a cmap are passed on to the QApplication + constructor. +*/ +QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) + : QApplication(dpy, argc, argv, visual, cmap) { + sysInit(appId); +} +# endif // Q_WS_X11 +#endif // QT_VERSION < 0x050000 + + +/*! + Returns true if another instance of this application is running; + otherwise false. + + This function does not find instances of this application that are + being run by a different user (on Windows: that are running in + another session). + + \sa sendMessage() +*/ + +bool QtSingleApplication::isRunning() { + return m_peer->isClient(); +} + + +/*! + Tries to send the text \a message to the currently running + instance. The QtSingleApplication object in the running instance + will emit the messageReceived() signal when it receives the + message. + + This function returns true if the message has been sent to, and + processed by, the current instance. If there is no instance + currently running, or if the running instance fails to process the + message within \a timeout milliseconds, this function return false. + + \sa isRunning(), messageReceived() +*/ +bool QtSingleApplication::sendMessage(const QString &message, int timeout) { + return m_peer->sendMessage(message, timeout); +} + + +/*! + Returns the application identifier. Two processes with the same + identifier will be regarded as instances of the same application. +*/ +QString QtSingleApplication::id() const { + return m_peer->applicationId(); +} + + +/*! + Sets the activation window of this application to \a aw. The + activation window is the widget that will be activated by + activateWindow(). This is typically the application's main window. + + If \a activateOnMessage is true (the default), the window will be + activated automatically every time a message is received, just prior + to the messageReceived() signal being emitted. + + \sa activateWindow(), messageReceived() +*/ + +void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) { + m_activateWindow = aw; + if (activateOnMessage) + connect(m_peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow); + else + disconnect(m_peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow); +} + + +/*! + Returns the applications activation window if one has been set by + calling setActivationWindow(), otherwise returns 0. + + \sa setActivationWindow() +*/ +QWidget* QtSingleApplication::activationWindow() const { + return m_activateWindow; +} + + +/*! + De-minimizes, raises, and activates this application's activation window. + This function does nothing if no activation window has been set. + + This is a convenience function to show the user that this + application instance has been activated when he has tried to start + another instance. + + This function should typically be called in response to the + messageReceived() signal. By default, that will happen + automatically, if an activation window has been set. + + \sa setActivationWindow(), messageReceived(), initialize() +*/ +void QtSingleApplication::activateWindow() { + if (m_activateWindow) { + if(this->applicationState() & Qt::ApplicationInactive) + { + m_activateWindow->setWindowState(m_activateWindow->windowState() & ~Qt::WindowMinimized); + m_activateWindow->raise(); + m_activateWindow->showNormal(); + m_activateWindow->activateWindow(); + } + else { + m_activateWindow->setWindowState(m_activateWindow->windowState() & Qt::WindowMinimized); + m_activateWindow->hide(); + } + } +} + + +/*! + \fn void QtSingleApplication::messageReceived(const QString& message) + + This signal is emitted when the current instance receives a \a + message from another instance of this application. + + \sa sendMessage(), setActivationWindow(), activateWindow() +*/ + + +/*! + \fn void QtSingleApplication::initialize(bool dummy = true) + + \obsolete +*/ diff --git a/src-vpn/singleapplication/qt-single-application.h b/src-vpn/singleapplication/qt-single-application.h new file mode 100644 index 00000000..084b9b7c --- /dev/null +++ b/src-vpn/singleapplication/qt-single-application.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies) +** 2020 KylinSoft Co., Ltd. +** Contact: http://www.qt-project.org/legal +** +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +** +****************************************************************************/ + +#ifndef QTSINGLEAPPLICATION_H +#define QTSINGLEAPPLICATION_H + +#include + +class QtLocalPeer; + +#if defined(Q_OS_WIN) +# if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT) +# define QT_QTSINGLEAPPLICATION_EXPORT +# elif defined(QT_QTSINGLEAPPLICATION_IMPORT) +# if defined(QT_QTSINGLEAPPLICATION_EXPORT) +# undef QT_QTSINGLEAPPLICATION_EXPORT +# endif +# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport) +# elif defined(QT_QTSINGLEAPPLICATION_EXPORT) +# undef QT_QTSINGLEAPPLICATION_EXPORT +# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport) +# endif +#else +# define QT_QTSINGLEAPPLICATION_EXPORT +#endif + +class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication { + Q_OBJECT + +public: + QtSingleApplication(int &argc, char **argv, bool GUIenabled = true); + QtSingleApplication(const QString &id, int &argc, char **argv); +#if QT_VERSION < 0x050000 + QtSingleApplication(int &argc, char **argv, Type type); +# if defined(Q_WS_X11) + QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); + QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0); + QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); +# endif // Q_WS_X11 +#endif // QT_VERSION < 0x050000 + + bool isRunning(); + QString id() const; + + void setActivationWindow(QWidget* aw, bool activateOnMessage = true); + QWidget* activationWindow() const; + + // Obsolete: + void initialize(bool dummy = true) { + isRunning(); + Q_UNUSED(dummy) + } + +public Q_SLOTS: + bool sendMessage(const QString &message, int timeout = 5000); + void activateWindow(); + + +Q_SIGNALS: + void messageReceived(const QString &message); + + +private: + void sysInit(const QString &appId = QString()); + QtLocalPeer *m_peer; + QWidget *m_activateWindow; +}; + +#endif // QTSINGLEAPPLICATION_H diff --git a/src-vpn/singleapplication/qt-single-application.pri b/src-vpn/singleapplication/qt-single-application.pri new file mode 100644 index 00000000..0a4ca9ae --- /dev/null +++ b/src-vpn/singleapplication/qt-single-application.pri @@ -0,0 +1,27 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD +QT *= network +greaterThan(QT_MAJOR_VERSION, 4): QT *= widgets + +qtsingleapplication-uselib:!qtsingleapplication-buildlib { + LIBS += -L$$QTSINGLEAPPLICATION_LIBDIR -l$$QTSINGLEAPPLICATION_LIBNAME +} else { + SOURCES += + HEADERS += +} + +win32 { + contains(TEMPLATE, lib):contains(CONFIG, shared):DEFINES += QT_QTSINGLEAPPLICATION_EXPORT + else:qtsingleapplication-uselib:DEFINES += QT_QTSINGLEAPPLICATION_IMPORT +} + +HEADERS += \ + $$PWD/qt-local-peer.h \ + $$PWD/qt-locked-file.h \ + $$PWD/qt-single-application.h + +SOURCES += \ + $$PWD/qt-local-peer.cpp \ + $$PWD/qt-locked-file-unix.cpp \ + $$PWD/qt-single-application.cpp \ + $$PWD/qt-locked-file.cpp diff --git a/src-vpn/src-vpn.pro b/src-vpn/src-vpn.pro new file mode 100644 index 00000000..a03ca247 --- /dev/null +++ b/src-vpn/src-vpn.pro @@ -0,0 +1,73 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-10-19T15:29:47 +# +#------------------------------------------------- + +QT += core gui x11extras dbus KWindowSystem svg concurrent network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = kylin-vpn +TEMPLATE = app + +CONFIG += c++14 qt warn_on link_pkgconfig no_keywords +#CONFIG += release + +PKGCONFIG +=gio-2.0 glib-2.0 gio-unix-2.0 libnm libnma libsecret-1 gtk+-3.0 gsettings-qt libcap kysdk-qtwidgets kysdk-waylandhelper +PKGCONFIG +=kysdk-sysinfo + +INCLUDEPATH += /usr/include/KF5/NetworkManagerQt + +LIBS += -L/usr/lib/ -lgsettings-qt -lX11 -lKF5NetworkManagerQt -lukui-log4qt -lkysec + +target.path = /usr/bin +target.source += $$TARGET +desktop.path = /etc/xdg/autostart/ +desktop.files = kylin-vpn.desktop +gschema.files = org.ukui.kylin-vpn.switch.gschema.xml +gschema.path = /usr/share/glib-2.0/schemas/ + +INSTALLS += target \ + desktop \ + gschema \ + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +# QMAKE_CXXFLAGS += -Wno-unused-parameter +QMAKE_CPPFLAGS *= $(shell dpkg-buildflags --get CPPFLAGS) +QMAKE_CFLAGS *= $(shell dpkg-buildflags --get CFLAGS) +QMAKE_CXXFLAGS *= $(shell dpkg-buildflags --get CXXFLAGS) +QMAKE_LFLAGS *= $(shell dpkg-buildflags --get LDFLAGS) + +include(singleapplication/qt-single-application.pri) +include(backend/backend.pri) +include(frontend/frontend.pri) + +RESOURCES += \ + vpnqrc.qrc + +SOURCES += \ + main.cpp + +unix { + UI_DIR = .ui + MOC_DIR = .moc + OBJECTS_DIR = .obj +} + +DISTFILES += \ + org.ukui.kylin-vpn.switch.gschema.xml + +TRANSLATIONS += \ + translations/kylin-vpn_zh_CN.ts \ + translations/kylin-vpn_bo_CN.ts diff --git a/src-vpn/translations/kylin-vpn_bo_CN.ts b/src-vpn/translations/kylin-vpn_bo_CN.ts new file mode 100644 index 00000000..e894fb83 --- /dev/null +++ b/src-vpn/translations/kylin-vpn_bo_CN.ts @@ -0,0 +1,147 @@ + + + + + SinglePage + + + Settings + + + + + Kylin VPN + + + + + kylin vpn applet desktop message + + + + + VpnListItem + + + Not connected + + + + + + Disconnect + + + + + + Connect + + + + + VpnPage + + + VPN + + + + + VPN Settings + + + + + vpnAddPage + + + create VPN + + + + + VPN Type + + + + + VPN Name + + + + + + Required + + + + + VPN Server + + + + + vpnConfigPage + + + VPN Type + + + + + vpnDetail + + + + VPN + + + + + IPv4 + + + + + IPv6 + + + + + Advanced + + + + + vpnDetailPage + + + VPN + + + + + Auto Connection + + + + + Confirm + + + + + Cancel + + + + + vpnObject + + + vpn tool + + + + diff --git a/src-vpn/translations/kylin-vpn_zh_CN.ts b/src-vpn/translations/kylin-vpn_zh_CN.ts new file mode 100644 index 00000000..d0afe821 --- /dev/null +++ b/src-vpn/translations/kylin-vpn_zh_CN.ts @@ -0,0 +1,838 @@ + + + + + SinglePage + + + Settings + 设置 + + + + Kylin VPN + VPN工具 + + + + kylin vpn applet desktop message + vpn配置桌面提示 + + + + VpnAdvancedPage + + + MPPE encryption algorithm: + MPPE加密算法: + + + + Use Stateful encryption + 使用有状态加密 + + + + Send PPP echo packets + 发送PPP回显包 + + + + Authentication Mode: + 认证方式: + + + + PAP authentication + PAP认证 + + + + CHAP authentication + CHAP认证 + + + + MSCHAP authentication + MSCHAP认证 + + + + MSCHAP2 authentication + MSCHAP2认证 + + + + EAP authentication + EAP认证 + + + + Compression Mode: + 压缩方式: + + + + Allow BSD data compression + 允许BSD压缩 + + + + Allow Default data compression + 允许Default压缩 + + + + Allow TCP header compression + 允许TCP头压缩 + + + + Use protocol field compression negotiation + 使用协议域压缩协商 + + + + Use Address/Control compression + 使用地址/控制压缩 + + + + All Available + 任意 + + + + 128-bit + 128位 + + + + 40-bit + 40位 + + + + Use custom gateway port + 使用自定义网关端口 + + + + Use compression + 使用压缩 + + + + Use a TCP connection + 使用TCP连接 + + + + Set virtual device type + 设置虚拟设备类型 + + + + Set virtual device name + 设置虚拟设备名称 + + + + Limit TCP Maximum Segment Size(MSS) + 限制TCP最大段尺寸(MSS) + + + + Randomize remote hosts + 随机化远程主机 + + + + IPv6 tun link + IPv6 tun连接 + + + + Specify ping interval + 指定Ping周期 + + + + Specify exit or restart ping + 指定退出或重启的Ping + + + + Specify max routes + 指定路由上限 + + + + Infinite retry on error + 出错时无限重试 + + + + Use custom key size + 使用自定义密钥大小 + + + + Choose + 选择 + + + + Use custom renegotiation interval + 使用自定义重协商间隔 + + + + Use custom tunnel Maximum Transmission Umit(MTU) + 使用自定义隧道最大单元传输(MTU) + + + + Use custom UDP fragment size + 使用自定义UDP分片大小 + + + + Accept authenticated packets from any address (Float) + 接受来自任何地址(Float)已通过身份验证的数据包 + + + + Subject Match + 主题匹配 + + + + Key File + 密钥文件 + + + + Key Direction + 密钥方向 + + + + Server Address + 服务器地址 + + + + Port + 端口 + + + + Proxy USername + 代理用户名 + + + + Proxy Password + 代理密码 + + + + General + 常规 + + + + TLS settings + TLS设置 + + + + Server Certificate Check + 服务器证书检验 + + + + Use the previous authentication end (server) certificate + 使用前面验证端(服务器)证书 + + + + Verify peer (server) certificate nsCertType specification + 验证对等点(服务器)证书nsCertType指定 + + + + Mode + 模式 + + + + Proxies + 代理 + + + + Proxy Type + 代理类型 + + + + Security + 安全 + + + + HMAC Authentication + HMAC认证 + + + + Input content + 输入内容 + + + + No + + + + + Self-adaption + 自适应 + + + + Automatic + 自动 + + + + Exit + 退出 + + + + Restart + 重启 + + + + Don't verify certificate identification + 不验证证书标识 + + + + Verify the entire subject exactly + 确切地验证整个主题 + + + + Verify name exactly + 精确验证名称 + + + + Verify name by prefix + 按前缀验证名称 + + + + + Server + 服务器 + + + + + Client + 客户端 + + + + + + None + + + + + TLS-Certification + TLS-认证 + + + + TLS-Encryption + TLS-加密 + + + + Not Required + 不需要 + + + + Default + 默认 + + + + Options: + 选项: + + + + Request an inner IP address + 请求内部IP地址 + + + + Enforce UDP encapsulation + 强制UDP封装 + + + + Use IP compression + 使用IP压缩 + + + + Enable custom password suggestions + 启用自定义密码建议 + + + + VpnConfigPage + + + Type + 类型 + + + + Name + 名称 + + + + Static Key + 静态密钥 + + + + Local IP + 本地IP地址 + + + + Remote IP + 远程IP地址 + + + + PIN Code + PIN码 + + + + + + Password + 密码 + + + + NT Domain + NT域 + + + + Server Address + 服务器地址 + + + + Authentication Mode + 认证方式 + + + + CA Certificate + CA证书 + + + + User Certificate + 用户证书 + + + + Key Direction + 密钥方向 + + + + Private Key + 私钥 + + + + Private Key Password + 私有密钥密码 + + + + + Password Options + 密码选项 + + + + Username + 用户名 + + + + Notice: +If key direction is used, it must be opposite to the VPN side used. If '1' is used, the connection must use '0'. If you are not sure which value to use, please contact your system administrator. + 注意: +如果使用了密钥方向,它必须和使用的VPN端相反。如果使用了“1”,连接必须要使用“0”。如果不确定使用哪个值,请联系您的系统管理员。 + + + + + + + Choose + 选择 + + + + None + + + + + + Save password only for this user + 仅对当前用户保存密码 + + + + + Save password for all users + 为所有用户保存密码 + + + + + Ask password every time + 每次都询问 + + + + + Don't require a password + 不需要密码 + + + + + Required + 必填 + + + + Certificate(TLS) + 证书(TLS) + + + + Static key + 静态密钥 + + + + Password and certificate(TLS) + 密码和证书(TLS) + + + + Certificate/Private key + 证书/私钥 + + + + Certificate/ssh-agent + 证书/ssh-agent + + + + Smart card + 智能卡 + + + + Choose a private key + 选择私钥 + + + + + Key Files (*.key *.pem *.der *.p12 *.pfx) + 私钥文件(*.key *.pem *.der *.p12 *.pfx) + + + + Choose a CA certificate + 选择CA证书 + + + + + CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx) + CA文件 (*.pem *.der *.p12 *.crt *.cer *.pfx) + + + + Choose a User certificate + 选择用户证书 + + + + Choose a Static key + 选择静态密钥 + + + + VpnIpv4Page + + + IPv4 Config + IPv4配置 + + + + Address + 地址 + + + + Netmask + 子网掩码 + + + + Default Gateway + 默认网关 + + + + DNS Server + DNS服务器 + + + + Search Domain + 搜索域 + + + + DHCP Client ID + DHCP客户端ID + + + + Auto(DHCP) + 自动(DHCP) + + + + Manual + 手动 + + + + VpnIpv6Page + + + IPv6 Config + IPv6配置 + + + + Address + 地址 + + + + Netmask + 子网掩码 + + + + Default Gateway + 默认网关 + + + + DNS Server + DNS服务器 + + + + Search Domain + 搜索域 + + + + Auto(DHCP) + 自动(DHCP) + + + + Manual + 手动 + + + + VpnListItem + + + Not connected + 未连接 + + + + + Disconnect + 断开 + + + + + Connect + 连接 + + + + VpnPage + + + VPN + + + + + VPN Settings + VPN设置 + + + + vpnAddPage + + + create VPN + 创建VPN + + + + VPN Type + VPN类型 + + + + VPN Name + VPN名称 + + + + + Required + 必填 + + + + VPN Server + 服务器地址 + + + + vpnConfigPage + + VPN Type + VPN类型 + + + + vpnDetail + + + + VPN + + + + + IPv4 + + + + + + IPv6 + + + + + Advanced + 高级 + + + + Auto Connection + 自动连接 + + + + Cancel + 取消 + + + + Confirm + 确定 + + + + vpnDetailPage + + + VPN + + + + + Auto Connection + 自动连接 + + + + Confirm + 确定 + + + + Cancel + 取消 + + + + vpnObject + + + vpn tool + VPN工具 + + + diff --git a/src-vpn/vpnqrc.qrc b/src-vpn/vpnqrc.qrc new file mode 100644 index 00000000..13fa41d8 --- /dev/null +++ b/src-vpn/vpnqrc.qrc @@ -0,0 +1,6 @@ + + + translations/kylin-vpn_zh_CN.qm + translations/kylin-vpn_bo_CN.qm + + diff --git a/src/backend/dbus-interface/dbus-interface.pri b/src/backend/dbus-interface/dbus-interface.pri index 056901df..679a1934 100644 --- a/src/backend/dbus-interface/dbus-interface.pri +++ b/src/backend/dbus-interface/dbus-interface.pri @@ -21,6 +21,7 @@ HEADERS += \ $$PWD/kywirelessconnectoperation.h \ $$PWD/kywirelessnetitem.h \ $$PWD/kywirelessnetresource.h \ + $$PWD/kyvpnconnectoperation.h \ $$PWD/nm-macros-internal.h SOURCES += \ @@ -42,5 +43,6 @@ SOURCES += \ $$PWD/kylinwiredconnectoperation.cpp \ $$PWD/kywirelessconnectoperation.cpp \ $$PWD/kywirelessnetitem.cpp \ + $$PWD/kyvpnconnectoperation.cpp \ $$PWD/kywirelessnetresource.cpp diff --git a/src/backend/dbus-interface/kylinconnectresource.cpp b/src/backend/dbus-interface/kylinconnectresource.cpp index eb757490..489cded3 100644 --- a/src/backend/dbus-interface/kylinconnectresource.cpp +++ b/src/backend/dbus-interface/kylinconnectresource.cpp @@ -42,11 +42,36 @@ static bool subLanListSort(const KyConnectItem* info1, const KyConnectItem* info return result; } +static bool subVpnListSort(const KyConnectItem* info1, const KyConnectItem* info2) +{ + if (info1->m_connectState != info2->m_connectState) { + if (info1->m_connectState == 2) { + return true; + } + + if (info2->m_connectState == 2) { + return false; + } + } + QString name1 = info1->m_connectName; + QString name2 = info2->m_connectName; + bool result = true; + if (QString::compare(name1, name2, Qt::CaseInsensitive) > 0) { + result = false; + } + return result; +} + static void lanListSort(QList &list) { qSort(list.begin(), list.end(), subLanListSort); } +static void vpnListSort(QList &list) +{ + qSort(list.begin(), list.end(), subVpnListSort); +} + KyConnectResourse::KyConnectResourse(QObject *parent) : QObject(parent) { m_networkResourceInstance = KyNetworkResourceManager::getInstance(); @@ -200,6 +225,61 @@ KyConnectItem * KyConnectResourse::getConnectionItemByUuid(QString connectUuid, return nullptr; } +void KyConnectResourse::getVpnAndVirtualConnections(QList &connectItemList) +{ + int index = 0; + NetworkManager::Connection::List connectList; + + qDebug()<<"[KyConnectResourse]"<<"get vpn && virtual connections"; + + connectList.clear(); + connectList = m_networkResourceInstance->getConnectList(); + + if (connectList.empty()) { + qWarning()<<"[KyConnectResourse]"<<"get vpn connections failed, the connect list is empty"; + return; + } + + NetworkManager::Connection::Ptr connectPtr = nullptr; + for (index = 0; index < connectList.size(); index++) { + connectPtr = connectList.at(index); + if (connectPtr.isNull()) { + continue; + } + if (NetworkManager::ConnectionSettings::ConnectionType::Vpn != connectPtr->settings()->connectionType() + && NetworkManager::ConnectionSettings::ConnectionType::Bond != connectPtr->settings()->connectionType() + && NetworkManager::ConnectionSettings::ConnectionType::Bridge != connectPtr->settings()->connectionType() + && NetworkManager::ConnectionSettings::ConnectionType::Vlan != connectPtr->settings()->connectionType() + && NetworkManager::ConnectionSettings::ConnectionType::Team != connectPtr->settings()->connectionType() + && NetworkManager::ConnectionSettings::ConnectionType::IpTunnel != connectPtr->settings()->connectionType() + && NetworkManager::ConnectionSettings::ConnectionType::Wired != connectPtr->settings()->connectionType()) { + continue; + } + NetworkManager::Device::Ptr devicePtr = nullptr; + devicePtr = m_networkResourceInstance->findDeviceInterface(connectPtr->settings()->interfaceName()); + if (NetworkManager::ConnectionSettings::ConnectionType::Wired == connectPtr->settings()->connectionType()) { + if (devicePtr == nullptr || !devicePtr->udi().startsWith("/sys/devices/virtual/net")) { + continue; + } + } + QString devName = ""; + if (!devicePtr.isNull()) { + devName = devicePtr->interfaceName(); + } + + KyConnectItem *connectItem = getConnectionItem(connectPtr, devName); + if (nullptr != connectItem) { + connectItemList << connectItem; + } + + connectPtr = nullptr; + } + + if (connectItemList.size() > 1) { + vpnListSort(connectItemList); + } +} + void KyConnectResourse::getConnectionList(QString deviceName, NetworkManager::ConnectionSettings::ConnectionType connectionType, QList &connectItemList) @@ -748,6 +828,35 @@ void KyConnectResourse::getApConnections(QList &apConnectItem return; } +bool KyConnectResourse::isVirtualConncection(QString uuid) +{ + NetworkManager::Connection::Ptr connectPtr = nullptr; + + connectPtr = m_networkResourceInstance->getConnect(uuid); + if (nullptr == connectPtr) { + return false; + } + + if (NetworkManager::ConnectionSettings::ConnectionType::Vpn == connectPtr->settings()->connectionType() + ||NetworkManager::ConnectionSettings::ConnectionType::Bond == connectPtr->settings()->connectionType() + ||NetworkManager::ConnectionSettings::ConnectionType::Bridge == connectPtr->settings()->connectionType() + ||NetworkManager::ConnectionSettings::ConnectionType::Vlan == connectPtr->settings()->connectionType() + ||NetworkManager::ConnectionSettings::ConnectionType::Team == connectPtr->settings()->connectionType() + ||NetworkManager::ConnectionSettings::ConnectionType::IpTunnel == connectPtr->settings()->connectionType()) { + return true; + } + + NetworkManager::Device::Ptr devicePtr = nullptr; + devicePtr = m_networkResourceInstance->findDeviceInterface(connectPtr->settings()->interfaceName()); + if (devicePtr.isNull()) { + return false; + } + if (devicePtr->udi().startsWith("/sys/devices/virtual/net")) { + return true; + } + + return false; +} bool KyConnectResourse::isWiredConnection(QString uuid) { diff --git a/src/backend/dbus-interface/kylinconnectresource.h b/src/backend/dbus-interface/kylinconnectresource.h index 9b334d34..8c1228a2 100644 --- a/src/backend/dbus-interface/kylinconnectresource.h +++ b/src/backend/dbus-interface/kylinconnectresource.h @@ -40,6 +40,7 @@ public: KyConnectItem *getConnectionItemByUuid(QString connectUuid); KyConnectItem *getConnectionItemByUuidWithoutActivateChecking(QString connectUuid); KyConnectItem *getConnectionItemByUuid(QString connectUuid, QString deviceName); + void getVpnAndVirtualConnections(QList &connectItemList); void getConnectionList(QString deviceName, NetworkManager::ConnectionSettings::ConnectionType connectionType, QList &connectItemList); @@ -55,6 +56,7 @@ public: bool getInterfaceByUuid(QString &deviceName, const QString connUuid); void getConnectivity(NetworkManager::Connectivity &connectivity); + bool isVirtualConncection(QString uuid); bool isWiredConnection(QString uuid); bool isWirelessConnection(QString uuid); bool isActivatedConnection(QString uuid); diff --git a/src/backend/dbus-interface/kylinwiredconnectoperation.cpp b/src/backend/dbus-interface/kylinwiredconnectoperation.cpp index f3231949..03c7f1ba 100644 --- a/src/backend/dbus-interface/kylinwiredconnectoperation.cpp +++ b/src/backend/dbus-interface/kylinwiredconnectoperation.cpp @@ -165,61 +165,6 @@ void KyWiredConnectOperation::deactivateWiredConnection(const QString activeConn return; } -void KyWiredConnectOperation::activateVpnConnection(const QString connectUuid) -{ - QString connectPath = ""; - QString deviceIdentifier = ""; - QString connectName = ""; - //QString deviceName = ""; - QString specificObject = ""; - NetworkManager::Connection::Ptr connectPtr = nullptr; - - qDebug()<<"it will activate vpn connect"<settings()->connectionType()) { - QString errorMessage = tr("the connect type is") - + connectPtr->settings()->connectionType() - + tr(", but it is not vpn"); - qWarning()<path(); - connectName = connectPtr->name(); - //deviceName = connectPtr->settings()->interfaceName(); - specificObject = deviceIdentifier = QStringLiteral("/"); - - qDebug() <<"active wired connect: path "<< connectPath - << "device identify " << deviceIdentifier - << "connect name " << connectName - // << "device name" << deviceName - << "specific parameter"<< specificObject; - - QDBusPendingCallWatcher * watcher; - watcher = new QDBusPendingCallWatcher{NetworkManager::activateConnection(connectPath, deviceIdentifier, specificObject), this}; - connect(watcher, &QDBusPendingCallWatcher::finished, [this, connectName] (QDBusPendingCallWatcher * watcher) { - if (watcher->isError() || !watcher->isValid()) { - QString errorMessage = tr("activate vpn connection failed: ") + watcher->error().message(); - qWarning()<activateConnectionError(errorMessage); - } else { - qWarning()<<"active vpn connect complete."; - } - - watcher->deleteLater(); - }); - - return; -} - void KyWiredConnectOperation::saveActiveConnection(QString &deviceName, QString &connectUuid) { QSettings *p_settings = new QSettings(WIRED_NETWORK_STATE_CONF_FILE, QSettings::IniFormat); diff --git a/src/backend/dbus-interface/kylinwiredconnectoperation.h b/src/backend/dbus-interface/kylinwiredconnectoperation.h index 67f416c6..a2bbd6e6 100644 --- a/src/backend/dbus-interface/kylinwiredconnectoperation.h +++ b/src/backend/dbus-interface/kylinwiredconnectoperation.h @@ -45,7 +45,6 @@ public: void updateWiredConnect(const QString &connectUuid, const KyConnectSetting &connectSettingsInfo); void deleteWiredConnect(const QString &connectUuid); void activateWiredConnection(const QString connectUuid, const QString devName); - void activateVpnConnection(const QString connectUuid); void deactivateWiredConnection(const QString activeConnectName, const QString &activeConnectUuid); int closeWiredNetworkWithDevice(QString deviceName); diff --git a/src/backend/dbus-interface/kyvpnconnectoperation.cpp b/src/backend/dbus-interface/kyvpnconnectoperation.cpp new file mode 100644 index 00000000..adee3ffb --- /dev/null +++ b/src/backend/dbus-interface/kyvpnconnectoperation.cpp @@ -0,0 +1,1530 @@ +/* + * Copyright (C) 2020 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 3, 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, see toMap()), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = tr("create vpn connection failed: ") + watcher->error().message(); + qWarning()<createConnectionError(errorMessage); + } else { + qDebug()<<"create vpn connect complete"; + } + watcher->deleteLater(); + }); + + return; +} + +void KyVpnConnectOperation::getConnectionSetting(QString connectUuid, KyVpnConfig &connectSetting) +{ + qDebug() <<"[KyConnectResourse]" << connectUuid <<"get connect setting info, connect uuid"; + KyNetworkResourceManager *networkResourceInstance = KyNetworkResourceManager::getInstance(); + + NetworkManager::Connection::Ptr connectPtr = + networkResourceInstance->getConnect(connectUuid); + + if (nullptr == connectPtr || !connectPtr->isValid()) { + qWarning() <<"[KyConnectResourse]" << "it can not find valid connection" << connectUuid; + return; + } + + connectSetting.m_connectName = connectPtr->name(); + + NetworkManager::ConnectionSettings::Ptr connectionSettings = connectPtr->settings(); + connectSetting.m_ifaceName = connectionSettings->interfaceName(); + connectSetting.m_isAutoConnect = connectionSettings->autoconnect(); + + if (connectionSettings->connectionType() != NetworkManager::ConnectionSettings::Vpn) { + return ; + } + + QDBusPendingReply reply = connectPtr->secrets(KYVPN_VPN_KEY); + QMap secretMap(reply.value()); + QVariantMap vpnSecretMap; + vpnSecretMap.clear(); + if (secretMap.contains(KYVPN_VPN_KEY)) { + vpnSecretMap = secretMap.value(KYVPN_VPN_KEY); + } + + connectSetting.m_vpnName = connectionSettings->id(); + NetworkManager::VpnSetting::Ptr vpnSettings = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast(); + m_vpnData.clear(); + m_vpnData = vpnSettings->data(); + m_vpnSecrets.clear(); + if (!vpnSecretMap.isEmpty()) { + vpnSettings->secretsFromMap(vpnSecretMap); + } + m_vpnSecrets = vpnSettings->secrets(); + connectSetting.m_gateway.clear(); + if (vpnSettings->serviceType() == VPN_SERVERTYPE_L2TP) { + connectSetting.m_vpnType = KYVPNTYPE_L2TP; + if (m_vpnData.contains(KYVPN_GATEWAY_KEY)) { + connectSetting.m_gateway = m_vpnData.value(KYVPN_GATEWAY_KEY); + } + } else if (vpnSettings->serviceType() == VPN_SERVERTYPE_PPTP) { + connectSetting.m_vpnType = KYVPNTYPE_PPTP; + if (m_vpnData.contains(KYVPN_GATEWAY_KEY)) { + connectSetting.m_gateway = m_vpnData.value(KYVPN_GATEWAY_KEY); + } + } else if (vpnSettings->serviceType() == VPN_SERVERTYPE_OPENVPN) { + connectSetting.m_vpnType = KYVPNTYPE_OPENVPN; + if (m_vpnData.contains(KYVPN_REMOTE_KEY)) { + connectSetting.m_gateway = m_vpnData.value(KYVPN_REMOTE_KEY); + } + } else if (vpnSettings->serviceType() == VPN_SERVERTYPE_STRONGSWAN) { + connectSetting.m_vpnType = KYVPNTYPE_STRONGSWAN; + if (m_vpnData.contains(KYVPN_ADDRESS_KEY)) { + connectSetting.m_gateway = m_vpnData.value(KYVPN_ADDRESS_KEY); + } + } else { + connectSetting.m_vpnType = KYVPNTYPE_UNKNOWN; + } + + NetworkManager::Ipv4Setting::Ptr ipv4Settings = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); + connectSetting.m_ipv4DnsSearch = ipv4Settings->dnsSearch(); + connectSetting.m_ipv4DhcpClientId = ipv4Settings->dhcpClientId(); + if (NetworkManager::Ipv4Setting::Automatic == ipv4Settings->method()) { + connectSetting.m_ipv4ConfigIpType = CONFIG_IP_DHCP; + connectSetting.m_ipv4Dns = ipv4Settings->dns(); + } else { + connectSetting.m_ipv4ConfigIpType = CONFIG_IP_MANUAL; + connectSetting.m_ipv4Address = ipv4Settings->addresses(); + connectSetting.m_ipv4Dns = ipv4Settings->dns(); + } + + NetworkManager::Ipv6Setting::Ptr ipv6Settings = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast(); + connectSetting.m_ipv6DnsSearch = ipv6Settings->dnsSearch(); + if (NetworkManager::Ipv6Setting::Automatic == ipv6Settings->method()) { + connectSetting.m_ipv6ConfigIpType = CONFIG_IP_DHCP; + connectSetting.m_ipv6Dns = ipv6Settings->dns(); + } else { + connectSetting.m_ipv6ConfigIpType = CONFIG_IP_MANUAL; + connectSetting.m_ipv6Address = ipv6Settings->addresses(); + connectSetting.m_ipv6Dns = ipv6Settings->dns(); + } + + return; +} + +KyVpnConfig KyVpnConnectOperation::getVpnConfig(QString connectUuid) +{ + KyVpnConfig vpnConfig; + getConnectionSetting(connectUuid, vpnConfig); + + switch (vpnConfig.m_vpnType) { + case KYVPNTYPE_L2TP: + getL2tpConfig(vpnConfig); + break; + case KYVPNTYPE_PPTP: + getPptpConfig(vpnConfig); + break; + case KYVPNTYPE_STRONGSWAN: + getStrongswanConfig(vpnConfig); + break; + case KYVPNTYPE_OPENVPN: + getOpenvpnConfig(vpnConfig); + break; + default : + break; + } + return vpnConfig; +} + +NMVariantMapMap KyVpnConnectOperation::setIpConfig(NetworkManager::ConnectionSettings::Ptr connectionSettings, KyVpnConfig &vpnConfig) +{ + NetworkManager::Ipv4Setting::Ptr ipv4Settings = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); + ipv4SettingSet(ipv4Settings, vpnConfig); + if (!vpnConfig.m_ipv4DnsSearch.isEmpty()) { + ipv4Settings->setDnsSearch(vpnConfig.m_ipv4DnsSearch); + } else { + QStringList emptyList; + emptyList.clear(); + ipv4Settings->setDnsSearch({""}); + } + if (!vpnConfig.m_ipv4DhcpClientId.isEmpty()) { + ipv4Settings->setDhcpClientId(vpnConfig.m_ipv4DhcpClientId); + } else { + ipv4Settings->setDhcpClientId(""); + } + + NetworkManager::Ipv6Setting::Ptr ipv6Settings = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast(); + ipv6SettingSet(ipv6Settings, vpnConfig); + if (!vpnConfig.m_ipv6DnsSearch.isEmpty()) { + ipv6Settings->setDnsSearch(vpnConfig.m_ipv6DnsSearch); + } + + NMVariantMapMap connectionSettingMap = connectionSettings->toMap(); + if (connectionSettingMap.contains("ipv4")) { + QVariantMap ipv4Map = connectionSettingMap.value(QLatin1String("ipv4")); + bool isAuto = false; + if (ipv4Map.contains("method") && ipv4Map["method"] == "auto") { + qDebug() << "[KyVpnConnectOperation] set ipv4 method auto, clear address-data && addresses && gateway"; + isAuto = true; + } + if (isAuto) { + if (ipv4Map.contains("address-data")) { + ipv4Map.remove("address-data"); + } + if (ipv4Map.contains("addresses")) { + ipv4Map.remove("addresses"); + } + if (ipv4Map.contains("gateway")) { + ipv4Map.remove("gateway"); + } + connectionSettingMap["ipv4"] = ipv4Map; + } + } + + if (connectionSettingMap.contains("ipv6")) { + QVariantMap ipv6Map = connectionSettingMap.value(QLatin1String("ipv6")); + bool isAuto = false; + if (ipv6Map.contains("method") && ipv6Map["method"] == "auto") { + qDebug() << "[KyVpnConnectOperation] set ipv6 method auto, clear address-data && addresses && gateway"; + isAuto = true; + } + if (isAuto) { + if (ipv6Map.contains("address-data")) { + ipv6Map.remove("address-data"); + } + if (ipv6Map.contains("addresses")) { + ipv6Map.remove("addresses"); + } + if (ipv6Map.contains("gateway")) { + ipv6Map.remove("gateway"); + } + connectionSettingMap["ipv6"] = ipv6Map; + } + } + + return connectionSettingMap; +} + +void KyVpnConnectOperation::setVpnConfig(QString connectUuid, KyVpnConfig &vpnConfig) +{ + qDebug() <<"[KyVpnConnectOperation]" << connectUuid <<"get connect setting info, connect uuid"; + KyNetworkResourceManager *networkResourceInstance = KyNetworkResourceManager::getInstance(); + + NetworkManager::Connection::Ptr connectPtr = + networkResourceInstance->getConnect(connectUuid); + + if (nullptr == connectPtr || !connectPtr->isValid()) { + qWarning() <<"[KyVpnConnectOperation]" << "it can not find valid connection" << connectUuid; + return; + } + NetworkManager::ConnectionSettings::Ptr connectionSettings = connectPtr->settings(); + setConnectionSetting(connectionSettings, vpnConfig); + NMVariantMapMap connectionSettingMap = setIpConfig(connectionSettings, vpnConfig); + connectPtr->update(connectionSettingMap); + return ; +} + +void KyVpnConnectOperation::setConnectionSetting(NetworkManager::ConnectionSettings::Ptr connectionSettings, KyVpnConfig &vpnConfig) +{ + connectionSettings->setId(vpnConfig.m_connectName); + connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); + if (!vpnConfig.m_ifaceName.isEmpty()) { + connectionSettings->setInterfaceName(vpnConfig.m_ifaceName); + } + connectionSettings->setAutoconnect(vpnConfig.m_isAutoConnect); + + NetworkManager::VpnSetting::Ptr vpnSettings = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast(); + vpnSettings->setInitialized(true); + m_vpnData.clear(); + m_vpnSecrets.clear(); + + switch (vpnConfig.m_vpnType) { + case KYVPNTYPE_L2TP: + vpnSettings->setServiceType(VPN_SERVERTYPE_L2TP); + setL2tpConfig(vpnConfig); + break; + case KYVPNTYPE_PPTP: + vpnSettings->setServiceType(VPN_SERVERTYPE_PPTP); + setPptpConfig(vpnConfig); + break; + case KYVPNTYPE_STRONGSWAN: + vpnSettings->setServiceType(VPN_SERVERTYPE_STRONGSWAN); + setStrongswanConfig(vpnConfig); + break; + case KYVPNTYPE_OPENVPN: + vpnSettings->setServiceType(VPN_SERVERTYPE_OPENVPN); + setOpenvpnConfig(vpnConfig); + break; + default : + break; + } + + vpnSettings->setData(m_vpnData); + vpnSettings->setSecrets(m_vpnSecrets); + return; +} + +void KyVpnConnectOperation::getL2tpConfig(KyVpnConfig &vpnConfig) +{ + vpnConfig.m_authMethod = KYAUTH_PASSWD; + + //获取用户名 + vpnConfig.m_userName.clear(); + if (m_vpnData.contains(KYVPN_USER_KEY)) { + vpnConfig.m_userName = m_vpnData.value(KYVPN_USER_KEY); + } + //获取密码和加密策略 + getUsrPasswdAndPolicy(vpnConfig); + //获取NT域 + vpnConfig.m_ntDomain.clear(); + if (m_vpnData.contains(KYVPN_DOMAIN_KEY) && !m_vpnData.value(KYVPN_DOMAIN_KEY).isEmpty()) { + vpnConfig.m_ntDomain = m_vpnData.value(KYVPN_DOMAIN_KEY); + } + + if (m_vpnData.contains(KYVPN_MRU_KEY) && !m_vpnData.value(KYVPN_MRU_KEY).isEmpty()) { + vpnConfig.m_mru = m_vpnData.value(KYVPN_MRU_KEY); + } + if (m_vpnData.contains(KYVPN_MTU_KEY) && !m_vpnData.value(KYVPN_MTU_KEY).isEmpty()) { + vpnConfig.m_mtu = m_vpnData.value(KYVPN_MTU_KEY); + } + + vpnConfig.m_authMethods.setFlag(KYAUTH2_ALL); + if (m_vpnData.contains(KYVPN_REFUSEPAP_KEY) && m_vpnData.value(KYVPN_REFUSEPAP_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_PAP, false); + } + if (m_vpnData.contains(KYVPN_REFUSECHAP_KEY) && m_vpnData.value(KYVPN_REFUSECHAP_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_CHAP, false); + } + if (m_vpnData.contains(KYVPN_REFUSEMSCHAP_KEY) && m_vpnData.value(KYVPN_REFUSEMSCHAP_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_MSCHAP, false); + } + if (m_vpnData.contains(KYVPN_REFUSEMSCHAPV2_KEY) && m_vpnData.value(KYVPN_REFUSEMSCHAPV2_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_MSCHAPV2, false); + } + if (m_vpnData.contains(KYVPN_REFUSEEAP_KEY) && m_vpnData.value(KYVPN_REFUSEEAP_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_EAP, false); + } + + vpnConfig.m_compressMethods.setFlag(KYCOMP_ALL); + if (m_vpnData.contains(KYVPN_NOBSDCOMP_KEY) && m_vpnData.value(KYVPN_NOBSDCOMP_KEY) == KYVPN_YES) { + vpnConfig.m_compressMethods.setFlag(KYCOMP_BSD, false); + } + if (m_vpnData.contains(KYVPN_NODEFLATE_KEY) && m_vpnData.value(KYVPN_NODEFLATE_KEY) == KYVPN_YES) { + vpnConfig.m_compressMethods.setFlag(KYCOMP_DEFLATE, false); + } + if (m_vpnData.contains(KYVPN_NOVJCOMP_KEY) && m_vpnData.value(KYVPN_NOVJCOMP_KEY) == KYVPN_YES) { + vpnConfig.m_compressMethods.setFlag(KYCOMP_TCP, false); + } + if (m_vpnData.contains(KYVPN_NOPCOMP_KEY) && m_vpnData.value(KYVPN_NOPCOMP_KEY) == KYVPN_YES) { + vpnConfig.m_compressMethods.setFlag(KYCOMP_PROTO, false); + } + if (m_vpnData.contains(KYVPN_NOACCOMP_KEY) && m_vpnData.value(KYVPN_NOACCOMP_KEY) == KYVPN_YES) { + vpnConfig.m_compressMethods.setFlag(KYCOMP_ADDR, false); + } + + vpnConfig.m_mppeEnable = false; + if (m_vpnData.contains(KYVPN_REQUIREMPPE_KEY)) { + vpnConfig.m_mppeEnable = true; + if (m_vpnData.contains(KYVPN_REQUIREMPPE128_KEY)) { + vpnConfig.m_mppeEncryptMethod = KYMPPE_REQUIRE128; + } else if (m_vpnData.contains(KYVPN_REQUIREMPPE40_KEY)) { + vpnConfig.m_mppeEncryptMethod = KYMPPE_REQUIRE40; + } else { + vpnConfig.m_mppeEncryptMethod = KYMPPE_DEFAULT; + } + vpnConfig.m_authMethods.setFlag(KYAUTH2_EAP, false); + vpnConfig.m_authMethods.setFlag(KYAUTH2_PAP, false); + vpnConfig.m_authMethods.setFlag(KYAUTH2_CHAP, false); + } + + vpnConfig.m_isAllowStatefulEncryption = false; + if (m_vpnData.contains(KYVPN_MPPESTATEFUL_KEY)) { + vpnConfig.m_isAllowStatefulEncryption = true; + } + + vpnConfig.m_sendPppPackage = false; + if (m_vpnData.contains(KYVPN_LCPECHOFAILURE_KEY) && m_vpnData.contains(KYVPN_LCPECHOINTERVAL_KEY)) { + vpnConfig.m_sendPppPackage = true; + } +} + +void KyVpnConnectOperation::setL2tpConfig(KyVpnConfig &vpnConfig) +{ + //设置用户名 + if (!vpnConfig.m_userName.isEmpty()) { + m_vpnData.insert(KYVPN_USER_KEY, vpnConfig.m_userName); + } + //设置密码和密码策略 + setUsrPasswdAndPolicy(vpnConfig); + //设置地址 + if (!vpnConfig.m_gateway.isEmpty()) { + m_vpnData.insert(KYVPN_GATEWAY_KEY, vpnConfig.m_gateway); + } + //设置NT域 + if (!vpnConfig.m_ntDomain.isEmpty()) { + m_vpnData.insert(KYVPN_DOMAIN_KEY, vpnConfig.m_ntDomain); + } + + //设置MRU 最大接收单元 + if (!vpnConfig.m_mru.isEmpty()) { + m_vpnData.insert(KYVPN_MRU_KEY, vpnConfig.m_mru); + } + //设置MTU 最大传输单元 + if (!vpnConfig.m_mtu.isEmpty()) { + m_vpnData.insert(KYVPN_MTU_KEY, vpnConfig.m_mtu); + } + + //设置认证方式 + //不设置PAP认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_PAP)) { + m_vpnData.insert(KYVPN_REFUSEPAP_KEY, KYVPN_YES); + } + //不设置CHAP认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_CHAP)) { + m_vpnData.insert(KYVPN_REFUSECHAP_KEY, KYVPN_YES); + } + //不设置MSCHAP认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_MSCHAP)) { + m_vpnData.insert(KYVPN_REFUSEMSCHAP_KEY, KYVPN_YES); + } + //不设置MSCHAPV2认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_MSCHAPV2)) { + m_vpnData.insert(KYVPN_REFUSEMSCHAPV2_KEY, KYVPN_YES); + } + //不设置EAP认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_EAP)) { + m_vpnData.insert(KYVPN_REFUSEEAP_KEY, KYVPN_YES); + } + + //设置压缩方式 + //不允许BSD压缩,若未勾选,则对应字段设置YES + if (!vpnConfig.m_compressMethods.testFlag(KYCOMP_BSD)) { + m_vpnData.insert(KYVPN_NOBSDCOMP_KEY, KYVPN_YES); + } + //不允许Deflate压缩,若未勾选,则对应字段设置YES + if (!vpnConfig.m_compressMethods.testFlag(KYCOMP_DEFLATE)) { + m_vpnData.insert(KYVPN_NODEFLATE_KEY, KYVPN_YES); + } + //不允许TCP头压缩,若未勾选,则对应字段设置YES + if (!vpnConfig.m_compressMethods.testFlag(KYCOMP_TCP)) { + m_vpnData.insert(KYVPN_NOVJCOMP_KEY, KYVPN_YES); + } + //不使用协议域压缩协商,若未勾选,则对应字段设置YES + if (!vpnConfig.m_compressMethods.testFlag(KYCOMP_PROTO)) { + m_vpnData.insert(KYVPN_NOPCOMP_KEY, KYVPN_YES); + } + //不使用地址/控制压缩,若未勾选,则对应字段设置YES + if (!vpnConfig.m_compressMethods.testFlag(KYCOMP_ADDR)) { + m_vpnData.insert(KYVPN_NOACCOMP_KEY, KYVPN_YES); + } + + //设置MPPE加密算法 + if (vpnConfig.m_mppeEnable) { + //设置MPPE加密算法方法为默认加密 + m_vpnData.insert(KYVPN_REQUIREMPPE_KEY, KYVPN_YES); + switch (vpnConfig.m_mppeEncryptMethod) { + case KYMPPE_REQUIRE128: + //设置MPPE加密算法方法为128位加密 + m_vpnData.insert(KYVPN_REQUIREMPPE128_KEY, KYVPN_YES); + break; + case KYMPPE_REQUIRE40: + //设置MPPE加密算法方法为40位加密 + m_vpnData.insert(KYVPN_REQUIREMPPE40_KEY, KYVPN_YES); + break; + case KYMPPE_DEFAULT: + default: + break; + } + + //若使用MPPE加密算法,则不设置PAP认证、不设置CHAP认证、不设置EAP认证 + m_vpnData.insert(KYVPN_REFUSEPAP_KEY, KYVPN_YES); + m_vpnData.insert(KYVPN_REFUSECHAP_KEY, KYVPN_YES); + m_vpnData.insert(KYVPN_REFUSEEAP_KEY, KYVPN_YES); + } + + //允许有状态的加密 + if (vpnConfig.m_isAllowStatefulEncryption) { + m_vpnData.insert(KYVPN_MPPESTATEFUL_KEY, KYVPN_YES); + } + //发送PPP回显包 + if (vpnConfig.m_sendPppPackage) { + m_vpnData.insert(KYVPN_LCPECHOFAILURE_KEY, "5"); + m_vpnData.insert(KYVPN_LCPECHOINTERVAL_KEY, "30"); + } +} + +void KyVpnConnectOperation::getPptpConfig(KyVpnConfig &vpnConfig) +{ + vpnConfig.m_authMethod = KYAUTH_PASSWD; + + vpnConfig.m_userName.clear(); + if (m_vpnData.contains(KYVPN_USER_KEY)) { + vpnConfig.m_userName = m_vpnData.value(KYVPN_USER_KEY); + } + + getUsrPasswdAndPolicy(vpnConfig); + + vpnConfig.m_ntDomain.clear(); + if (m_vpnData.contains(KYVPN_DOMAIN_KEY)) { + vpnConfig.m_ntDomain = m_vpnData.value(KYVPN_DOMAIN_KEY); + } + + vpnConfig.m_authMethods.setFlag(KYAUTH2_ALL); + if (m_vpnData.contains(KYVPN_REFUSEPAP_KEY) && m_vpnData.value(KYVPN_REFUSEPAP_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_PAP, false); + } + if (m_vpnData.contains(KYVPN_REFUSECHAP_KEY) && m_vpnData.value(KYVPN_REFUSECHAP_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_CHAP, false); + } + if (m_vpnData.contains(KYVPN_REFUSEMSCHAP_KEY) && m_vpnData.value(KYVPN_REFUSEMSCHAP_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_MSCHAP, false); + } + if (m_vpnData.contains(KYVPN_REFUSEMSCHAPV2_KEY) && m_vpnData.value(KYVPN_REFUSEMSCHAPV2_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_MSCHAPV2, false); + } + if (m_vpnData.contains(KYVPN_REFUSEEAP_KEY) && m_vpnData.value(KYVPN_REFUSEEAP_KEY) == KYVPN_YES) { + vpnConfig.m_authMethods.setFlag(KYAUTH2_EAP, false); + } + + vpnConfig.m_compressMethods.setFlag(KYCOMP_ALL); + vpnConfig.m_compressMethods.setFlag(KYCOMP_PROTO, false); + vpnConfig.m_compressMethods.setFlag(KYCOMP_ADDR, false); + if (m_vpnData.contains(KYVPN_NOBSDCOMP_KEY) && m_vpnData.value(KYVPN_NOBSDCOMP_KEY) == KYVPN_YES) { + vpnConfig.m_compressMethods.setFlag(KYCOMP_BSD, false); + } + if (m_vpnData.contains(KYVPN_NODEFLATE_KEY) && m_vpnData.value(KYVPN_NODEFLATE_KEY) == KYVPN_YES) { + vpnConfig.m_compressMethods.setFlag(KYCOMP_DEFLATE, false); + } + if (m_vpnData.contains(KYVPN_NOVJCOMP_KEY) && m_vpnData.value(KYVPN_NOVJCOMP_KEY) == KYVPN_YES) { + vpnConfig.m_compressMethods.setFlag(KYCOMP_TCP, false); + } + + vpnConfig.m_mppeEnable = false; + if (m_vpnData.contains(KYVPN_REQUIREMPPE_KEY)) { + vpnConfig.m_mppeEnable = true; + if (m_vpnData.contains(KYVPN_REQUIREMPPE128_KEY)) { + vpnConfig.m_mppeEncryptMethod = KYMPPE_REQUIRE128; + } else if (m_vpnData.contains(KYVPN_REQUIREMPPE40_KEY)) { + vpnConfig.m_mppeEncryptMethod = KYMPPE_REQUIRE40; + } else { + vpnConfig.m_mppeEncryptMethod = KYMPPE_DEFAULT; + } + vpnConfig.m_authMethods.setFlag(KYAUTH2_EAP, false); + vpnConfig.m_authMethods.setFlag(KYAUTH2_PAP, false); + vpnConfig.m_authMethods.setFlag(KYAUTH2_CHAP, false); + } + + vpnConfig.m_isAllowStatefulEncryption = false; + if (m_vpnData.contains(KYVPN_MPPESTATEFUL_KEY)) { + vpnConfig.m_isAllowStatefulEncryption = true; + } + + vpnConfig.m_sendPppPackage = false; + if (m_vpnData.contains(KYVPN_LCPECHOFAILURE_KEY) && m_vpnData.contains(KYVPN_LCPECHOINTERVAL_KEY)) { + vpnConfig.m_sendPppPackage = true; + } +} + +void KyVpnConnectOperation::setPptpConfig(KyVpnConfig &vpnConfig) +{ + //设置用户名 + if (!vpnConfig.m_userName.isEmpty()) { + m_vpnData.insert(KYVPN_USER_KEY, vpnConfig.m_userName); + } + //设置密码和密码策略 + setUsrPasswdAndPolicy(vpnConfig); + //设置地址 + if (!vpnConfig.m_gateway.isEmpty()) { + m_vpnData.insert(KYVPN_GATEWAY_KEY, vpnConfig.m_gateway); + } + //设置NT域 + if (!vpnConfig.m_ntDomain.isEmpty()) { + m_vpnData.insert(KYVPN_DOMAIN_KEY, vpnConfig.m_ntDomain); + } + + //设置认证方式 + //不设置PAP认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_PAP)) { + m_vpnData.insert(KYVPN_REFUSEPAP_KEY, KYVPN_YES); + } + //不设置CHAP认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_CHAP)) { + m_vpnData.insert(KYVPN_REFUSECHAP_KEY, KYVPN_YES); + } + //不设置MSCHAP认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_MSCHAP)) { + m_vpnData.insert(KYVPN_REFUSEMSCHAP_KEY, KYVPN_YES); + } + //不设置MSCHAPV2认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_MSCHAPV2)) { + m_vpnData.insert(KYVPN_REFUSEMSCHAPV2_KEY, KYVPN_YES); + } + //不设置EAP认证,若未勾选,则对应字段设置YES + if (!vpnConfig.m_authMethods.testFlag(KYAUTH2_EAP)) { + m_vpnData.insert(KYVPN_REFUSEEAP_KEY, KYVPN_YES); + } + + //设置压缩方式 + //不允许BSD压缩,若未勾选,则对应字段设置YES + if (!vpnConfig.m_compressMethods.testFlag(KYCOMP_BSD)) { + m_vpnData.insert(KYVPN_NOBSDCOMP_KEY, KYVPN_YES); + } + //不允许Deflate压缩,若未勾选,则对应字段设置YES + if (!vpnConfig.m_compressMethods.testFlag(KYCOMP_DEFLATE)) { + m_vpnData.insert(KYVPN_NODEFLATE_KEY, KYVPN_YES); + } + //不允许TCP头压缩,若未勾选,则对应字段设置YES + if (!vpnConfig.m_compressMethods.testFlag(KYCOMP_TCP)) { + m_vpnData.insert(KYVPN_NOVJCOMP_KEY, KYVPN_YES); + } + + //设置MPPE加密算法 + if (vpnConfig.m_mppeEnable) { + //设置MPPE加密算法方法为默认加密 + m_vpnData.insert(KYVPN_REQUIREMPPE_KEY, KYVPN_YES); + switch (vpnConfig.m_mppeEncryptMethod) { + case KYMPPE_REQUIRE128: + //设置MPPE加密算法方法为128位加密 + m_vpnData.insert(KYVPN_REQUIREMPPE128_KEY, KYVPN_YES); + break; + case KYMPPE_REQUIRE40: + //设置MPPE加密算法方法为40位加密 + m_vpnData.insert(KYVPN_REQUIREMPPE40_KEY, KYVPN_YES); + break; + case KYMPPE_DEFAULT: + default: + break; + } + + //若使用MPPE加密算法,则不设置PAP认证、不设置CHAP认证、不设置EAP认证 + m_vpnData.insert(KYVPN_REFUSEPAP_KEY, KYVPN_YES); + m_vpnData.insert(KYVPN_REFUSECHAP_KEY, KYVPN_YES); + m_vpnData.insert(KYVPN_REFUSEEAP_KEY, KYVPN_YES); + } + + //允许有状态的加密 + if (vpnConfig.m_isAllowStatefulEncryption) { + m_vpnData.insert(KYVPN_MPPESTATEFUL_KEY, KYVPN_YES); + } + //发送PPP回显包 + if (vpnConfig.m_sendPppPackage) { + m_vpnData.insert(KYVPN_LCPECHOFAILURE_KEY, "5"); + m_vpnData.insert(KYVPN_LCPECHOINTERVAL_KEY, "30"); + } +} + +void KyVpnConnectOperation::getStrongswanConfig(KyVpnConfig &vpnConfig) +{ + vpnConfig.m_authMethod = KYAUTH_ERROR; + if (m_vpnData.contains(KYVPN_METHOD_KEY)) { + vpnConfig.m_authMethod = getAuthMethod(m_vpnData.value(KYVPN_METHOD_KEY)); + } + + vpnConfig.m_userCertificate.clear(); + vpnConfig.m_userKey.clear(); + vpnConfig.m_userName.clear(); + vpnConfig.m_pinId.clear(); + switch (vpnConfig.m_authMethod) { + case KYAUTH_KEY: + if (m_vpnData.contains(KYVPN_USERCERT_KEY)) { + vpnConfig.m_userCertificate = m_vpnData.value(KYVPN_USERCERT_KEY); + } + if (m_vpnData.contains(KYVPN_USERKEY_KEY)) { + vpnConfig.m_userKey = m_vpnData.value(KYVPN_USERKEY_KEY); + } + getCertPasswdAndPolicy(vpnConfig); + break; + case KYAUTH_AGENT: + if (m_vpnData.contains(KYVPN_USERCERT_KEY)) { + vpnConfig.m_userCertificate = m_vpnData.value(KYVPN_USERCERT_KEY); + } + break; + case KYAUTH_SMARTCARD: + if (m_vpnData.contains(KYVPN_PIN_KEY)) { + vpnConfig.m_pinId = m_vpnData.value(KYVPN_PIN_KEY); + } + break; + case KYAUTH_EAP: + if (m_vpnData.contains(KYVPN_USER_KEY)) { + vpnConfig.m_userName = m_vpnData.value(KYVPN_USER_KEY); + } + getUsrPasswdAndPolicy(vpnConfig); + break; + default : + break; + } + + vpnConfig.m_virtual = false; + if (m_vpnData.contains(KYVPN_VIRTUAL_KEY) && m_vpnData.value(KYVPN_VIRTUAL_KEY) == KYVPN_YES) { + vpnConfig.m_virtual = true; + } + + vpnConfig.m_encap = false; + if (m_vpnData.contains(KYVPN_ENCAP_KEY) && m_vpnData.value(KYVPN_ENCAP_KEY) == KYVPN_YES) { + vpnConfig.m_encap = true; + } + + vpnConfig.m_ipcomp = false; + if (m_vpnData.contains(KYVPN_IPCOMP_KEY) && m_vpnData.value(KYVPN_IPCOMP_KEY) == KYVPN_YES) { + vpnConfig.m_ipcomp = true; + } + + vpnConfig.m_proposal = false; + if (m_vpnData.contains(KYVPN_PROPOSAL_KEY) && m_vpnData.value(KYVPN_PROPOSAL_KEY) == KYVPN_YES) { + vpnConfig.m_proposal = true; + } + + vpnConfig.m_ike.clear(); + if (m_vpnData.contains(KYVPN_IKE_KEY)) { + vpnConfig.m_ike = m_vpnData.value(KYVPN_IKE_KEY); + } + + vpnConfig.m_esp.clear(); + if (m_vpnData.contains(KYVPN_ESP_KEY)) { + vpnConfig.m_esp = m_vpnData.value(KYVPN_ESP_KEY); + } +} + +void KyVpnConnectOperation::setStrongswanConfig(KyVpnConfig &vpnConfig) +{ + m_vpnData.insert(KYVPN_METHOD_KEY, m_authMethodMap.key(vpnConfig.m_authMethod)); + + if (!vpnConfig.m_gateway.isEmpty()) { + m_vpnData.insert(KYVPN_ADDRESS_KEY, vpnConfig.m_gateway); + } + + switch (vpnConfig.m_authMethod) { + case KYAUTH_KEY: + if (!vpnConfig.m_userCertificate.isEmpty()) { + m_vpnData.insert(KYVPN_USERCERT_KEY, vpnConfig.m_userCertificate); + } else { + m_vpnData.remove(KYVPN_USERCERT_KEY); + } + if (!vpnConfig.m_userKey.isEmpty()) { + m_vpnData.insert(KYVPN_USERKEY_KEY, vpnConfig.m_userKey); + } else { + m_vpnData.remove(KYVPN_USERKEY_KEY); + } + setCertPasswdAndPolicy(vpnConfig); + break; + case KYAUTH_AGENT: + if (!vpnConfig.m_userCertificate.isEmpty()) { + m_vpnData.insert(KYVPN_USERCERT_KEY, vpnConfig.m_userCertificate); + } + break; + case KYAUTH_SMARTCARD: + if (!vpnConfig.m_pinId.isEmpty()) { + m_vpnData.insert(KYVPN_PIN_KEY, vpnConfig.m_pinId); + } + break; + case KYAUTH_EAP: + if (!vpnConfig.m_userName.isEmpty()) { + m_vpnData.insert(KYVPN_USER_KEY, vpnConfig.m_userName); + } + vpnConfig.m_passwdPolicy = KYPASSWD_FORALLUSER; + setUsrPasswdAndPolicy(vpnConfig); + break; + default : + break; + } + + if (vpnConfig.m_virtual) { + m_vpnData.insert(KYVPN_VIRTUAL_KEY, KYVPN_YES); + } else { + m_vpnData.insert(KYVPN_VIRTUAL_KEY, KYVPN_NO); + } + + if (vpnConfig.m_encap) { + m_vpnData.insert(KYVPN_ENCAP_KEY, KYVPN_YES); + } else { + m_vpnData.insert(KYVPN_ENCAP_KEY, KYVPN_NO); + } + + if (vpnConfig.m_ipcomp) { + m_vpnData.insert(KYVPN_IPCOMP_KEY, KYVPN_YES); + } else { + m_vpnData.insert(KYVPN_IPCOMP_KEY, KYVPN_NO); + } + + if (vpnConfig.m_proposal) { + m_vpnData.insert(KYVPN_PROPOSAL_KEY, KYVPN_YES); + if (!vpnConfig.m_ike.isEmpty()) { + m_vpnData.insert(KYVPN_IKE_KEY, vpnConfig.m_ike); + } + + if (!vpnConfig.m_esp.isEmpty()) { + m_vpnData.insert(KYVPN_ESP_KEY, vpnConfig.m_esp); + } + } else { + m_vpnData.insert(KYVPN_PROPOSAL_KEY, KYVPN_NO); + m_vpnData.remove(KYVPN_IKE_KEY); + m_vpnData.remove(KYVPN_ESP_KEY); + } +} + +void KyVpnConnectOperation::getOpenvpnConfig(KyVpnConfig &vpnConfig) +{ + vpnConfig.m_authMethod = KYAUTH_ERROR; + if (m_vpnData.contains(KYVPN_CONNECTIONTYPE_KEY)) { + vpnConfig.m_authMethod = getAuthMethod(m_vpnData.value(KYVPN_CONNECTIONTYPE_KEY)); + } + + vpnConfig.m_caCertificate.clear(); + vpnConfig.m_userCertificate.clear(); + vpnConfig.m_userKey.clear(); + vpnConfig.m_userName.clear(); + vpnConfig.m_staticKey.clear(); + vpnConfig.m_vpnKeyDir.clear(); + vpnConfig.m_localAddress.clear(); + vpnConfig.m_remoteAddress.clear(); + switch (vpnConfig.m_authMethod) { + case KYAUTH_CERTIFICATE: + if (m_vpnData.contains(KYVPN_CA_KEY)) { + vpnConfig.m_caCertificate = m_vpnData.value(KYVPN_CA_KEY); + } + if (m_vpnData.contains(KYVPN_CERT_KEY)) { + vpnConfig.m_userCertificate = m_vpnData.value(KYVPN_CERT_KEY); + } + if (m_vpnData.contains(KYVPN_USERKEY_KEY)) { + vpnConfig.m_userKey = m_vpnData.value(KYVPN_USERKEY_KEY); + } + getCertPasswdAndPolicy(vpnConfig); + break; + + case KYAUTH_PASSWD: + if (m_vpnData.contains(KYVPN_CA_KEY)) { + vpnConfig.m_caCertificate = m_vpnData.value(KYVPN_CA_KEY); + } + if (m_vpnData.contains(KYVPN_USERNAME_KEY)) { + vpnConfig.m_userName = m_vpnData.value(KYVPN_USERNAME_KEY); + } + getUsrPasswdAndPolicy(vpnConfig); + break; + + case KYAUTH_CERTIFICATEANDPASSWD: + if (m_vpnData.contains(KYVPN_CA_KEY)) { + vpnConfig.m_caCertificate = m_vpnData.value(KYVPN_CA_KEY); + } + if (m_vpnData.contains(KYVPN_CERT_KEY)) { + vpnConfig.m_userCertificate = m_vpnData.value(KYVPN_CERT_KEY); + } + if (m_vpnData.contains(KYVPN_USERKEY_KEY)) { + vpnConfig.m_userKey = m_vpnData.value(KYVPN_USERKEY_KEY); + } + if (m_vpnData.contains(KYVPN_USERNAME_KEY)) { + vpnConfig.m_userName = m_vpnData.value(KYVPN_USERNAME_KEY); + } + getUsrPasswdAndPolicy(vpnConfig); + getCertPasswdAndPolicy(vpnConfig); + break; + + case KYAUTH_STATICPASSWD: + if (m_vpnData.contains(KYVPN_STATICKEY_KEY)) { + vpnConfig.m_staticKey = m_vpnData.value(KYVPN_STATICKEY_KEY); + } + if (m_vpnData.contains(KYVPN_STATICKEYDIR_KEY)) { + vpnConfig.m_vpnKeyDir = m_vpnData.value(KYVPN_STATICKEYDIR_KEY); + } + if (m_vpnData.contains(KYVPN_LOCALIP_KEY)) { + vpnConfig.m_localAddress = m_vpnData.value(KYVPN_LOCALIP_KEY); + } + if (m_vpnData.contains(KYVPN_REMOTEIP_KEY)) { + vpnConfig.m_remoteAddress = m_vpnData.value(KYVPN_REMOTEIP_KEY); + } + break; + + default : + break; + } + + vpnConfig.m_useAssignPort = false; + vpnConfig.m_assignPort.clear(); + if (m_vpnData.contains(KYVPN_PORT_KEY)) { + vpnConfig.m_useAssignPort = true; + vpnConfig.m_assignPort = m_vpnData.value(KYVPN_PORT_KEY); + } + + vpnConfig.m_useRenegSeconds = false; + vpnConfig.m_renegSeconds.clear(); + if (m_vpnData.contains(KYVPN_RENEGSEC_KEY)) { + vpnConfig.m_useRenegSeconds = true; + vpnConfig.m_renegSeconds = m_vpnData.value(KYVPN_RENEGSEC_KEY); + } + + vpnConfig.m_useCompress = false; + vpnConfig.m_openvpnCompress = KYCOMP2_LZODISABLE; + if (m_vpnData.contains(KYVPN_COMPLZO_KEY)) { + vpnConfig.m_useCompress = true; + if (m_vpnData.value(KYVPN_COMPLZO_KEY) == COMPLZO_LZODISABLE) { + vpnConfig.m_openvpnCompress = KYCOMP2_LZODISABLE; + } else if (m_vpnData.value(KYVPN_COMPLZO_KEY) == COMPLZO_ADAPTIVE) { + vpnConfig.m_openvpnCompress = KYCOMP2_LZOADAPTIVE; + } + } else if (m_vpnData.contains(KYVPN_COMPRESS_KEY)) { + vpnConfig.m_useCompress = true; + if (m_vpnData.value(KYVPN_COMPRESS_KEY) == COMPRESS_LZO) { + vpnConfig.m_openvpnCompress = KYCOMP2_LZO; + } else if (m_vpnData.value(KYVPN_COMPRESS_KEY) == COMPRESS_LZ4) { + vpnConfig.m_openvpnCompress = KYCOMP2_LZ4; + } else if (m_vpnData.value(KYVPN_COMPRESS_KEY) == COMPRESS_LZ4V2) { + vpnConfig.m_openvpnCompress = KYCOMP2_LZ4V2; + } else if (m_vpnData.value(KYVPN_COMPRESS_KEY) == KYVPN_YES) { + vpnConfig.m_openvpnCompress = KYCOMP2_AUTO; + } + } + + vpnConfig.m_useTcpLink = false; + if (m_vpnData.contains(KYVPN_PROTOTCP_KEY) && m_vpnData.value(KYVPN_PROTOTCP_KEY) == KYVPN_YES) { + vpnConfig.m_useTcpLink = true; + } + + vpnConfig.m_setDevType = false; + if (m_vpnData.contains(KYVPN_DEVTYPE_KEY)) { + vpnConfig.m_setDevType = true; + if (m_vpnData.value(KYVPN_DEVTYPE_KEY) == DEVTYPE_TUN) { + vpnConfig.m_devType = KYVIRDEVTYPE_TUN; + } else if (m_vpnData.value(KYVPN_DEVTYPE_KEY) == DEVTYPE_TAP) { + vpnConfig.m_devType = KYVIRDEVTYPE_TAP; + } + } + + vpnConfig.m_setDevName = false; + vpnConfig.m_devName.clear(); + if (m_vpnData.contains(KYVPN_DEV_KEY)) { + vpnConfig.m_setDevName = true; + vpnConfig.m_devName = m_vpnData.value(KYVPN_DEV_KEY); + } + + vpnConfig.m_useTunnelMtu = false; + vpnConfig.m_tunnelMtu.clear(); + if (m_vpnData.contains(KYVPN_TUNNELMTU_KEY)) { + vpnConfig.m_useTunnelMtu = true; + vpnConfig.m_tunnelMtu = m_vpnData.value(KYVPN_TUNNELMTU_KEY); + } + + vpnConfig.m_useFragmentSize = false; + vpnConfig.m_fragmentSize.clear(); + if (m_vpnData.contains(KYVPN_FRAGMENTSIZE_KEY)) { + vpnConfig.m_useFragmentSize = true; + vpnConfig.m_fragmentSize = m_vpnData.value(KYVPN_FRAGMENTSIZE_KEY); + } + + vpnConfig.m_mssfix = false; + if (m_vpnData.contains(KYVPN_MSSFIX_KEY) && m_vpnData.value(KYVPN_MSSFIX_KEY) == KYVPN_YES) { + vpnConfig.m_mssfix = true; + } + + vpnConfig.m_remoteRandom = false; + if (m_vpnData.contains(KYVPN_REMOTERANDOM_KEY) && m_vpnData.value(KYVPN_REMOTERANDOM_KEY) == KYVPN_YES) { + vpnConfig.m_remoteRandom = true; + } + + vpnConfig.m_ipv6TunLink = false; + if (m_vpnData.contains(KYVPN_TUNIPV6_KEY) && m_vpnData.value(KYVPN_TUNIPV6_KEY) == KYVPN_YES) { + vpnConfig.m_ipv6TunLink = true; + } + + vpnConfig.m_setPingCycle = false; + vpnConfig.m_pingCycle.clear(); + if (m_vpnData.contains(KYVPN_PING_KEY)) { + vpnConfig.m_setPingCycle = true; + vpnConfig.m_pingCycle = m_vpnData.value(KYVPN_PING_KEY); + } + + vpnConfig.m_usePingMethod = false; + vpnConfig.m_pingMethod = KYVPNPING_EXIT; + vpnConfig.m_pingMethodTime.clear(); + if (m_vpnData.contains(KYVPN_PINGEXIT_KEY)) { + vpnConfig.m_usePingMethod = true; + vpnConfig.m_pingMethod = KYVPNPING_EXIT; + vpnConfig.m_pingMethodTime = m_vpnData.value(KYVPN_PINGEXIT_KEY); + } else if (m_vpnData.contains(KYVPN_PINGRESTART_KEY)) { + vpnConfig.m_usePingMethod = true; + vpnConfig.m_pingMethod = KYVPNPING_RESTART; + vpnConfig.m_pingMethodTime = m_vpnData.value(KYVPN_PINGRESTART_KEY); + } + + vpnConfig.m_float = false; + if (m_vpnData.contains(KYVPN_FLOAT_KEY) && m_vpnData.value(KYVPN_FLOAT_KEY) == KYVPN_YES) { + vpnConfig.m_float = true; + } + + vpnConfig.m_setMaxRoute = false; + vpnConfig.m_maxRoute.clear(); + if (m_vpnData.contains(KYVPN_MAXROUTES_KEY)) { + vpnConfig.m_setMaxRoute = true; + vpnConfig.m_maxRoute = m_vpnData.value(KYVPN_MAXROUTES_KEY); + } + + vpnConfig.m_checkServerCa = KYCHECKSERVER_NONE; + vpnConfig.m_verifyName.clear(); + if (m_vpnData.contains(KYVPN_VERIFYX509NAME_KEY)) { + QString nameValue = m_vpnData.value(KYVPN_VERIFYX509NAME_KEY); + QString nameType = nameValue.section(":", 0, 0); + if (nameType == X509NAME_SUBJECT) { + vpnConfig.m_checkServerCa = KYCHECKSERVER_ENTIRETHEME; + } else if (nameType == X509NAME_NAME) { + vpnConfig.m_checkServerCa = KYCHECKSERVER_ENTIRENAME; + } else if (nameType == X509NAME_NAMEPREFIX) { + vpnConfig.m_checkServerCa = KYCHECKSERVER_PRENAME; + } + vpnConfig.m_verifyName = nameValue.section(":", 1, 1); + } + + vpnConfig.m_useRemoteCertTls = false; + vpnConfig.m_remoteCertType = KYVPNCERT_SERVER; + if (m_vpnData.contains(KYVPN_REMOTECERTTLS_KEY)) { + vpnConfig.m_useRemoteCertTls = true; + if (m_vpnData.value(KYVPN_REMOTECERTTLS_KEY) == KYVPN_SERVER) { + vpnConfig.m_remoteCertType = KYVPNCERT_SERVER; + } else if (m_vpnData.value(KYVPN_REMOTECERTTLS_KEY) == KYVPN_CLIENT) { + vpnConfig.m_remoteCertType = KYVPNCERT_CLIENT; + } + } + + vpnConfig.m_useNsCertTls = false; + vpnConfig.m_nsCertType = KYVPNCERT_SERVER; + if (m_vpnData.contains(KYVPN_NSCERTTYPE_KEY)) { + vpnConfig.m_useNsCertTls = true; + if (m_vpnData.value(KYVPN_NSCERTTYPE_KEY) == KYVPN_SERVER) { + vpnConfig.m_nsCertType = KYVPNCERT_SERVER; + } else if (m_vpnData.value(KYVPN_NSCERTTYPE_KEY) == KYVPN_CLIENT) { + vpnConfig.m_nsCertType = KYVPNCERT_CLIENT; + } + } + + vpnConfig.m_vpnTlsMode = KYVPNTLS_NONE; + if (m_vpnData.contains(KYVPN_TA_KEY)) { + vpnConfig.m_vpnTlsMode = KYVPNTLS_AUTHENTICATION; + vpnConfig.m_vpnKeyFile = m_vpnData.value(KYVPN_TA_KEY); + } else if (m_vpnData.contains(KYVPN_TLSCRYPT_KEY)) { + vpnConfig.m_vpnTlsMode = KYVPNTLS_CRYPT; + vpnConfig.m_vpnKeyFile = m_vpnData.value(KYVPN_TLSCRYPT_KEY); + } + + vpnConfig.m_vpnTlsTaDir.clear(); + if (m_vpnData.contains(KYVPN_TADIR_KEY)) { + vpnConfig.m_vpnTlsTaDir = m_vpnData.value(KYVPN_TADIR_KEY); + } + + vpnConfig.m_vpnProxyType = KYVPNPROXY_NONE; + vpnConfig.m_vpnProxyServer.clear(); + vpnConfig.m_vpnProxyPort.clear(); + vpnConfig.m_vpnProxyRetry = false; + vpnConfig.m_vpnProxyName.clear(); + if (m_vpnData.contains(KYVPN_PROXYTYPE_KEY)) { + if (m_vpnData.value(KYVPN_PROXYTYPE_KEY) == PROXYTYPE_HTTP) { + vpnConfig.m_vpnProxyType = KYVPNPROXY_HTTP; + } else if (m_vpnData.value(KYVPN_PROXYTYPE_KEY) == PROXYTYPE_SOCKS) { + vpnConfig.m_vpnProxyType = KYVPNPROXY_SOCKS; + } + if (m_vpnData.contains(KYVPN_PROXYSERVER_KEY)) { + vpnConfig.m_vpnProxyServer = m_vpnData.value(KYVPN_PROXYSERVER_KEY); + } + if (m_vpnData.contains(KYVPN_PROXYPORT_KEY)) { + vpnConfig.m_vpnProxyPort = m_vpnData.value(KYVPN_PROXYPORT_KEY); + } + if (m_vpnData.contains(KYVPN_PROXYRETRY_KEY) && m_vpnData.value(KYVPN_PROXYRETRY_KEY) == KYVPN_YES) { + vpnConfig.m_vpnProxyRetry = true; + } + if (m_vpnData.contains(KYVPN_HTTPPROXYUSERNAME_KEY)) { + vpnConfig.m_vpnProxyName = m_vpnData.value(KYVPN_HTTPPROXYUSERNAME_KEY); + } + if (m_vpnData.contains(KYVPN_HTTPPROXYPASSWDFLAGS_KEY)) { + switch (m_vpnData.value(KYVPN_HTTPPROXYPASSWDFLAGS_KEY).toInt()) { + case 1: + vpnConfig.m_vpnProxyPasswdPolicy = KYPASSWD_FORTHISUSER; + break; + case 2: + vpnConfig.m_vpnProxyPasswdPolicy = KYPASSWD_ASKEVERYTIME; + break; + case 4: + vpnConfig.m_vpnProxyPasswdPolicy = KYPASSWD_ISNOTREQUIRED; + break; + default : + break; + } + } + if (m_vpnSecrets.contains(KYVPN_HTTPPROXYPASSWD_KEY)) { + vpnConfig.m_vpnProxyPasswd = m_vpnSecrets.value(KYVPN_HTTPPROXYPASSWD_KEY); + } + } + + vpnConfig.m_useKeysize = false; + vpnConfig.m_keySize.clear(); + vpnConfig.m_hmacAuthMethod = KYHMACAUTH_DEFAULT; + if (m_vpnData.contains(KYVPN_KEYSIZE_KEY)) { + vpnConfig.m_useKeysize = true; + vpnConfig.m_keySize = m_vpnData.value(KYVPN_KEYSIZE_KEY); + if (m_vpnData.contains(KYVPN_AUTH_KEY)) { + vpnConfig.m_hmacAuthMethod = getHmacAuthMethod(m_vpnData.value(KYVPN_AUTH_KEY)); + + } + } +} + +void KyVpnConnectOperation::setOpenvpnConfig(KyVpnConfig &vpnConfig) +{ + m_vpnData.insert(KYVPN_CONNECTIONTYPE_KEY, m_authMethodMap.key(vpnConfig.m_authMethod)); + + if (!vpnConfig.m_gateway.isEmpty()) { + m_vpnData.insert(KYVPN_REMOTE_KEY, vpnConfig.m_gateway); + } + + switch (vpnConfig.m_authMethod) { + case KYAUTH_CERTIFICATE: + if (!vpnConfig.m_caCertificate.isEmpty()) { + m_vpnData.insert(KYVPN_CA_KEY, vpnConfig.m_caCertificate); + } + if (!vpnConfig.m_userCertificate.isEmpty()) { + m_vpnData.insert(KYVPN_CERT_KEY, vpnConfig.m_userCertificate); + } + if (!vpnConfig.m_userKey.isEmpty()) { + m_vpnData.insert(KYVPN_USERKEY_KEY, vpnConfig.m_userKey); + } + setCertPasswdAndPolicy(vpnConfig); + break; + case KYAUTH_PASSWD: + if (!vpnConfig.m_caCertificate.isEmpty()) { + m_vpnData.insert(KYVPN_CA_KEY, vpnConfig.m_caCertificate); + } + if (!vpnConfig.m_userName.isEmpty()) { + m_vpnData.insert(KYVPN_USERNAME_KEY, vpnConfig.m_userName); + } + setUsrPasswdAndPolicy(vpnConfig); + break; + case KYAUTH_CERTIFICATEANDPASSWD: + if (!vpnConfig.m_caCertificate.isEmpty()) { + m_vpnData.insert(KYVPN_CA_KEY, vpnConfig.m_caCertificate); + } + if (!vpnConfig.m_userCertificate.isEmpty()) { + m_vpnData.insert(KYVPN_CERT_KEY, vpnConfig.m_userCertificate); + } + if (!vpnConfig.m_userKey.isEmpty()) { + m_vpnData.insert(KYVPN_USERKEY_KEY, vpnConfig.m_userKey); + } + if (!vpnConfig.m_userName.isEmpty()) { + m_vpnData.insert(KYVPN_USERNAME_KEY, vpnConfig.m_userName); + } + setUsrPasswdAndPolicy(vpnConfig); + setCertPasswdAndPolicy(vpnConfig); + break; + case KYAUTH_STATICPASSWD: + if (!vpnConfig.m_staticKey.isEmpty()) { + m_vpnData.insert(KYVPN_STATICKEY_KEY, vpnConfig.m_staticKey); + } + if (!vpnConfig.m_vpnKeyDir.isEmpty()) { + m_vpnData.insert(KYVPN_STATICKEYDIR_KEY, vpnConfig.m_vpnKeyDir); + } + if (!vpnConfig.m_localAddress.isEmpty()) { + m_vpnData.insert(KYVPN_LOCALIP_KEY, vpnConfig.m_localAddress); + } + if (!vpnConfig.m_remoteAddress.isEmpty()) { + m_vpnData.insert(KYVPN_REMOTEIP_KEY, vpnConfig.m_remoteAddress); + } + break; + + default : + break; + } + + if (vpnConfig.m_useAssignPort && !vpnConfig.m_assignPort.isEmpty()) { + m_vpnData.insert(KYVPN_PORT_KEY, vpnConfig.m_assignPort); + } + + if (vpnConfig.m_useRenegSeconds && !vpnConfig.m_renegSeconds.isEmpty()) { + m_vpnData.insert(KYVPN_RENEGSEC_KEY, vpnConfig.m_renegSeconds); + } + + if (vpnConfig.m_useCompress) { + switch (vpnConfig.m_openvpnCompress) { + case KYCOMP2_LZODISABLE: + m_vpnData.insert(KYVPN_COMPLZO_KEY, COMPLZO_LZODISABLE); + break; + case KYCOMP2_LZOADAPTIVE: + m_vpnData.insert(KYVPN_COMPLZO_KEY, COMPLZO_ADAPTIVE); + break; + case KYCOMP2_LZO: + m_vpnData.insert(KYVPN_COMPRESS_KEY, COMPRESS_LZO); + break; + case KYCOMP2_LZ4: + m_vpnData.insert(KYVPN_COMPRESS_KEY, COMPRESS_LZ4); + break; + case KYCOMP2_LZ4V2: + m_vpnData.insert(KYVPN_COMPRESS_KEY, COMPRESS_LZ4V2); + break; + case KYCOMP2_AUTO: + m_vpnData.insert(KYVPN_COMPRESS_KEY, KYVPN_YES); + break; + } + } + + if (vpnConfig.m_useTcpLink) { + m_vpnData.insert(KYVPN_PROTOTCP_KEY, KYVPN_YES); + } + + if (vpnConfig.m_setDevType) { + switch (vpnConfig.m_devType) { + case KYVIRDEVTYPE_TUN: + m_vpnData.insert(KYVPN_DEVTYPE_KEY, DEVTYPE_TUN); + break; + case KYVIRDEVTYPE_TAP: + m_vpnData.insert(KYVPN_DEVTYPE_KEY, DEVTYPE_TAP); + break; + default : + break; + } + } + + if (vpnConfig.m_setDevName && !vpnConfig.m_devName.isEmpty()) { + m_vpnData.insert(KYVPN_DEV_KEY, vpnConfig.m_devName); + } + + if (vpnConfig.m_useTunnelMtu && !vpnConfig.m_tunnelMtu.isEmpty()) { + m_vpnData.insert(KYVPN_TUNNELMTU_KEY, vpnConfig.m_tunnelMtu); + } + + if (vpnConfig.m_useFragmentSize && !vpnConfig.m_fragmentSize.isEmpty()) { + m_vpnData.insert(KYVPN_FRAGMENTSIZE_KEY, vpnConfig.m_fragmentSize); + } + + if (vpnConfig.m_mssfix) { + m_vpnData.insert(KYVPN_MSSFIX_KEY, KYVPN_YES); + } + + if (vpnConfig.m_remoteRandom) { + m_vpnData.insert(KYVPN_REMOTERANDOM_KEY, KYVPN_YES); + } + + if (vpnConfig.m_ipv6TunLink) { + m_vpnData.insert(KYVPN_TUNIPV6_KEY, KYVPN_YES); + } + + if (vpnConfig.m_setPingCycle && !vpnConfig.m_pingCycle.isEmpty()) { + m_vpnData.insert(KYVPN_PING_KEY, vpnConfig.m_pingCycle); + } + + if (vpnConfig.m_usePingMethod) { + switch (vpnConfig.m_pingMethod) { + case KYVPNPING_EXIT: + m_vpnData.insert(KYVPN_PINGEXIT_KEY, vpnConfig.m_pingMethodTime); + break; + case KYVPNPING_RESTART: + m_vpnData.insert(KYVPN_PINGRESTART_KEY, vpnConfig.m_pingMethodTime); + break; + default : + break; + } + } + + if (vpnConfig.m_float) { + m_vpnData.insert(KYVPN_FLOAT_KEY, KYVPN_YES); + } + + if (vpnConfig.m_setMaxRoute && !vpnConfig.m_maxRoute.isEmpty()) { + m_vpnData.insert(KYVPN_MAXROUTES_KEY, vpnConfig.m_maxRoute); + } + + if (vpnConfig.m_checkServerCa != KYCHECKSERVER_NONE && !vpnConfig.m_verifyName.isEmpty()) { + QString nameStr; + nameStr.clear(); + switch (vpnConfig.m_checkServerCa) { + case KYCHECKSERVER_ENTIRETHEME: + nameStr = X509NAME_SUBJECT + QString(":") + vpnConfig.m_verifyName; + break; + case KYCHECKSERVER_ENTIRENAME: + nameStr = X509NAME_NAME + QString(":") + vpnConfig.m_verifyName; + break; + case KYCHECKSERVER_PRENAME: + nameStr = X509NAME_NAMEPREFIX + QString(":") + vpnConfig.m_verifyName; + break; + default : + break; + } + m_vpnData.insert(KYVPN_VERIFYX509NAME_KEY, nameStr); + } + + if (vpnConfig.m_useRemoteCertTls) { + switch (vpnConfig.m_remoteCertType) { + case KYVPNCERT_SERVER: + m_vpnData.insert(KYVPN_REMOTECERTTLS_KEY, KYVPN_SERVER); + break; + case KYVPNCERT_CLIENT: + m_vpnData.insert(KYVPN_REMOTECERTTLS_KEY, KYVPN_CLIENT); + break; + default : + break; + } + } + + if (vpnConfig.m_useNsCertTls) { + switch (vpnConfig.m_nsCertType) { + case KYVPNCERT_SERVER: + m_vpnData.insert(KYVPN_NSCERTTYPE_KEY, KYVPN_SERVER); + break; + case KYVPNCERT_CLIENT: + m_vpnData.insert(KYVPN_NSCERTTYPE_KEY, KYVPN_CLIENT); + break; + default : + break; + } + } + + switch (vpnConfig.m_vpnTlsMode) { + case KYVPNTLS_AUTHENTICATION: + m_vpnData.insert(KYVPN_TA_KEY, vpnConfig.m_vpnKeyFile); + break; + case KYVPNTLS_CRYPT: + m_vpnData.insert(KYVPN_TLSCRYPT_KEY, vpnConfig.m_vpnKeyFile); + break; + default : + break; + } + + if (!vpnConfig.m_vpnTlsTaDir.isEmpty() && vpnConfig.m_vpnTlsTaDir != "None") { + m_vpnData.insert(KYVPN_TADIR_KEY, vpnConfig.m_vpnTlsTaDir); + } + + switch (vpnConfig.m_vpnProxyType) { + case KYVPNPROXY_HTTP: + m_vpnData.insert(KYVPN_PROXYTYPE_KEY, PROXYTYPE_HTTP); + break; + case KYVPNPROXY_SOCKS: + m_vpnData.insert(KYVPN_PROXYTYPE_KEY, PROXYTYPE_SOCKS); + break; + default : + break; + } + if (!vpnConfig.m_vpnProxyServer.isEmpty()) { + m_vpnData.insert(KYVPN_PROXYSERVER_KEY, vpnConfig.m_vpnProxyServer); + } + if (!vpnConfig.m_vpnProxyPort.isEmpty()) { + m_vpnData.insert(KYVPN_PROXYPORT_KEY, vpnConfig.m_vpnProxyPort); + } + if (vpnConfig.m_vpnProxyRetry) { + m_vpnData.insert(KYVPN_PROXYRETRY_KEY, KYVPN_YES); + } + if (!vpnConfig.m_vpnProxyName.isEmpty()) { + m_vpnData.insert(KYVPN_HTTPPROXYUSERNAME_KEY, vpnConfig.m_vpnProxyName); + } + + vpnConfig.m_vpnProxyPasswdPolicy = KYPASSWD_FORALLUSER; + if (vpnConfig.m_vpnProxyPasswdPolicy == KYPASSWD_FORALLUSER && !vpnConfig.m_vpnProxyPasswd.isEmpty()) { + m_vpnData.insert(KYVPN_HTTPPROXYPASSWDFLAGS_KEY, "0"); + m_vpnSecrets.insert(KYVPN_HTTPPROXYPASSWD_KEY, vpnConfig.m_vpnProxyPasswd); + } + + if (vpnConfig.m_useKeysize) { + m_vpnData.insert(KYVPN_KEYSIZE_KEY, vpnConfig.m_keySize); + m_vpnData.insert(KYVPN_AUTH_KEY, m_hmacMap.key(vpnConfig.m_hmacAuthMethod)); + } +} + +KyHMACAuthMethod KyVpnConnectOperation::getHmacAuthMethod(const QString method) +{ + if (m_hmacMap.contains(method)) { + return m_hmacMap.value(method); + } + return KYHMACAUTH_DEFAULT; +} + +KyAuthMethod KyVpnConnectOperation::getAuthMethod(const QString method) +{ + if (m_authMethodMap.contains(method)) { + return m_authMethodMap.value(method); + } + return KYAUTH_ERROR; +} + +void KyVpnConnectOperation::getUsrPasswdAndPolicy(KyVpnConfig &vpnConfig) +{ + vpnConfig.m_userPasswd.clear(); + vpnConfig.m_passwdPolicy = KYPASSWD_ASKEVERYTIME; + if (m_vpnData.contains(KYVPN_PASSWDFLAGS_KEY)) { + switch (m_vpnData.value(KYVPN_PASSWDFLAGS_KEY).toInt()) { + case 0: + vpnConfig.m_passwdPolicy = KYPASSWD_FORALLUSER; + if (m_vpnSecrets.contains(KYVPN_PASSWD_KEY)) { + vpnConfig.m_userPasswd = m_vpnSecrets.value(KYVPN_PASSWD_KEY); + } + break; + case 1: + vpnConfig.m_passwdPolicy = KYPASSWD_FORTHISUSER; + break; + case 2: + vpnConfig.m_passwdPolicy = KYPASSWD_ASKEVERYTIME; + break; + case 4: + vpnConfig.m_passwdPolicy = KYPASSWD_ISNOTREQUIRED; + break; + default : + break; + } + } +} + +void KyVpnConnectOperation::setUsrPasswdAndPolicy(KyVpnConfig &vpnConfig) +{ + switch (vpnConfig.m_passwdPolicy) { + case KYPASSWD_FORTHISUSER: + m_vpnData.insert(KYVPN_PASSWDFLAGS_KEY, "1"); + break ; + case KYPASSWD_FORALLUSER: + m_vpnData.insert(KYVPN_PASSWDFLAGS_KEY, "0"); + break ; + case KYPASSWD_ASKEVERYTIME: + m_vpnData.insert(KYVPN_PASSWDFLAGS_KEY, "2"); + break ; + case KYPASSWD_ISNOTREQUIRED: + m_vpnData.insert(KYVPN_PASSWDFLAGS_KEY, "4"); + break ; + default : + break; + } + if (vpnConfig.m_passwdPolicy == KYPASSWD_FORALLUSER && !vpnConfig.m_userPasswd.isEmpty()) { + m_vpnSecrets.insert(KYVPN_PASSWD_KEY, vpnConfig.m_userPasswd); + } +} + +void KyVpnConnectOperation::getCertPasswdAndPolicy(KyVpnConfig &vpnConfig) +{ + vpnConfig.m_privatePasswd.clear(); + vpnConfig.m_privatePasswdPolicy = KYPASSWD_ASKEVERYTIME; + if (m_vpnData.contains(KYVPN_CERTPASSWDFLAGS_KEY)) { + switch (m_vpnData.value(KYVPN_CERTPASSWDFLAGS_KEY).toInt()) { + case 0: + vpnConfig.m_privatePasswdPolicy = KYPASSWD_FORALLUSER; + if (m_vpnSecrets.contains(KYVPN_CERTPASSWD_KEY)) { + vpnConfig.m_privatePasswd = m_vpnSecrets.value(KYVPN_CERTPASSWD_KEY); + } + break; + case 1: + vpnConfig.m_privatePasswdPolicy = KYPASSWD_FORTHISUSER; + break; + case 2: + vpnConfig.m_privatePasswdPolicy = KYPASSWD_ASKEVERYTIME; + break; + case 4: + vpnConfig.m_privatePasswdPolicy = KYPASSWD_ISNOTREQUIRED; + break; + default : + break; + } + } +} + +void KyVpnConnectOperation::setCertPasswdAndPolicy(KyVpnConfig &vpnConfig) +{ + switch (vpnConfig.m_privatePasswdPolicy) { + case KYPASSWD_FORTHISUSER: + m_vpnData.insert(KYVPN_CERTPASSWDFLAGS_KEY, "1"); + break ; + case KYPASSWD_FORALLUSER: + m_vpnData.insert(KYVPN_CERTPASSWDFLAGS_KEY, "0"); + break ; + case KYPASSWD_ASKEVERYTIME: + m_vpnData.insert(KYVPN_CERTPASSWDFLAGS_KEY, "2"); + break ; + case KYPASSWD_ISNOTREQUIRED: + m_vpnData.insert(KYVPN_CERTPASSWDFLAGS_KEY, "4"); + break ; + default : + break; + } + + if (vpnConfig.m_privatePasswdPolicy == KYPASSWD_FORALLUSER && !vpnConfig.m_privatePasswd.isEmpty()) { + m_vpnSecrets.insert(KYVPN_CERTPASSWD_KEY, vpnConfig.m_privatePasswd); + } +} + + +void KyVpnConnectOperation::activateVpnConnection(const QString connectUuid) +{ + QString connectPath = ""; + QString deviceIdentifier = ""; + QString connectName = ""; + QString specificObject = ""; + NetworkManager::Connection::Ptr connectPtr = nullptr; + + qDebug()<<"it will activate vpn connect"<settings()->connectionType()) { + QString errorMessage = tr("the connect type is") + + connectPtr->settings()->connectionType() + + tr(", but it is not vpn"); + qWarning()<path(); + connectName = connectPtr->name(); + specificObject = deviceIdentifier = QStringLiteral("/"); + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::activateConnection(connectPath, deviceIdentifier, specificObject), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [this, connectName] (QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = tr("activate vpn connection failed: ") + watcher->error().message(); + qWarning()<activateConnectionError(errorMessage); + } else { + qWarning()<<"active vpn connect complete."; + } + + watcher->deleteLater(); + }); + + return; +} + +void KyVpnConnectOperation::deactivateVpnConnection(const QString activeConnectName, const QString &activeConnectUuid) +{ + qDebug()<<"deactivetate connect name"< +#include + +#include "kylinnetworkresourcemanager.h" +#include "kylinconnectsetting.h" +#include "kylinconnectoperation.h" +#include "kylinconnectresource.h" +#include "kyenterpricesettinginfo.h" +#include + + +#define VPN_SERVERTYPE_L2TP "org.freedesktop.NetworkManager.l2tp" +#define VPN_SERVERTYPE_PPTP "org.freedesktop.NetworkManager.pptp" +#define VPN_SERVERTYPE_OPENVPN "org.freedesktop.NetworkManager.openvpn" +#define VPN_SERVERTYPE_STRONGSWAN "org.freedesktop.NetworkManager.strongswan" + +#define KYVPN_VPN_KEY "vpn" + +#define KYVPN_GATEWAY_KEY "gateway" +#define KYVPN_REMOTE_KEY "remote" +#define KYVPN_ADDRESS_KEY "address" + +#define KYVPN_USER_KEY "user" +#define KYVPN_PASSWD_KEY "password" +#define KYVPN_SECRETS_KEY "secrets" +#define KYVPN_PASSWDFLAGS_KEY "password-flags" + +#define KYVPN_REFUSEPAP_KEY "refuse-pap" +#define KYVPN_REFUSECHAP_KEY "refuse-chap" +#define KYVPN_REFUSEEAP_KEY "refuse-eap" +#define KYVPN_REFUSEMSCHAP_KEY "refuse-mschap" +#define KYVPN_REFUSEMSCHAPV2_KEY "refuse-mschapv2" + +#define KYVPN_NOVJCOMP_KEY "no-vj-comp" +#define KYVPN_NOACCOMP_KEY "noaccomp" +#define KYVPN_NOBSDCOMP_KEY "nobsdcomp" +#define KYVPN_NODEFLATE_KEY "nodeflate" +#define KYVPN_NOPCOMP_KEY "nopcomp" + +#define KYVPN_DOMAIN_KEY "domain" +#define KYVPN_REQUIREMPPE_KEY "require-mppe" +#define KYVPN_MPPESTATEFUL_KEY "mppe-stateful" +#define KYVPN_LCPECHOFAILURE_KEY "lcp-echo-failure" +#define KYVPN_LCPECHOINTERVAL_KEY "lcp-echo-interval" +#define KYVPN_MRU_KEY "mru" +#define KYVPN_MTU_KEY "mtu" + +#define KYVPN_REQUIREMPPE128_KEY "require-mppe-128" +#define KYVPN_REQUIREMPPE40_KEY "require-mppe-40" + +#define KYVPN_USERCERT_KEY "usercert" +#define KYVPN_USERKEY_KEY "userkey" +#define KYVPN_CERTPASSWD_KEY "cert-pass" +#define KYVPN_CERTPASSWDFLAGS_KEY "cert-pass-flags" +#define KYVPN_PIN_KEY "pin" +#define KYVPN_VIRTUAL_KEY "virtual" +#define KYVPN_ENCAP_KEY "encap" +#define KYVPN_IPCOMP_KEY "ipcomp" +#define KYVPN_PROPOSAL_KEY "proposal" +#define KYVPN_IKE_KEY "ike" +#define KYVPN_ESP_KEY "esp" + +//openvpn +#define KYVPN_CONNECTIONTYPE_KEY "connection-type" + +#define KYVPN_CA_KEY "ca" +#define KYVPN_CERT_KEY "cert" +#define KYVPN_KEY_KEY "key" + +#define KYVPN_USERNAME_KEY "username" +#define KYVPN_STATICKEY_KEY "static-key" +#define KYVPN_STATICKEYDIR_KEY "static-key-direction" +#define KYVPN_LOCALIP_KEY "local-ip" +#define KYVPN_REMOTEIP_KEY "remote-ip" + +#define KYVPN_PORT_KEY "port" +#define KYVPN_RENEGSEC_KEY "reneg-seconds" +#define KYVPN_COMPLZO_KEY "comp-lzo" +#define KYVPN_COMPRESS_KEY "compress" +#define COMPLZO_LZODISABLE "no-by-default" +#define COMPLZO_ADAPTIVE "adaptive" +#define COMPRESS_LZO "lzo" +#define COMPRESS_LZ4 "lz4" +#define COMPRESS_LZ4V2 "lz4-v2" + +#define KYVPN_PROTOTCP_KEY "proto-tcp" +#define KYVPN_DEVTYPE_KEY "dev-type" +#define DEVTYPE_TUN "tun" +#define DEVTYPE_TAP "tap" +#define KYVPN_DEV_KEY "dev" +#define KYVPN_TUNNELMTU_KEY "tunnel-mtu" +#define KYVPN_FRAGMENTSIZE_KEY "fragment-size" +#define KYVPN_MSSFIX_KEY "mssfix" +#define KYVPN_REMOTERANDOM_KEY "remote-random" +#define KYVPN_TUNIPV6_KEY "tun-ipv6" +#define KYVPN_PING_KEY "ping" +#define KYVPN_PINGEXIT_KEY "ping-exit" +#define KYVPN_PINGRESTART_KEY "ping-restart" +#define KYVPN_FLOAT_KEY "float" +#define KYVPN_MAXROUTES_KEY "max-routes" +#define KYVPN_VERIFYX509NAME_KEY "verify-x509-name" +#define X509NAME_SUBJECT "subject" +#define X509NAME_NAME "name" +#define X509NAME_NAMEPREFIX "name-prefix" + +#define KYVPN_REMOTECERTTLS_KEY "remote-cert-tls" +#define KYVPN_NSCERTTYPE_KEY "ns-cert-type" +#define KYVPN_SERVER "server" +#define KYVPN_CLIENT "client" + +#define KYVPN_TA_KEY "ta" +#define KYVPN_TLSCRYPT_KEY "tls-crypt" +#define KYVPN_TADIR_KEY "ta-dir" + +#define KYVPN_PROXYTYPE_KEY "proxy-type" +#define PROXYTYPE_HTTP "http" +#define PROXYTYPE_SOCKS "socks" +#define KYVPN_PROXYSERVER_KEY "proxy-server" +#define KYVPN_PROXYPORT_KEY "proxy-port" +#define KYVPN_PROXYRETRY_KEY "proxy-retry" +#define KYVPN_HTTPPROXYUSERNAME_KEY "http-proxy-username" +#define KYVPN_HTTPPROXYPASSWD_KEY "http-proxy-password" +#define KYVPN_HTTPPROXYPASSWDFLAGS_KEY "http-proxy-password-flags" + +#define KYVPN_KEYSIZE_KEY "keysize" +#define KYVPN_AUTH_KEY "auth" + +#define KYVPN_METHOD_KEY "method" + +#define KYVPN_YES "yes" +#define KYVPN_NO "no" + +//VPN类型 +enum KyVpnType{ + KYVPNTYPE_UNKNOWN = -1, + KYVPNTYPE_L2TP = 0, + KYVPNTYPE_OPENVPN, + KYVPNTYPE_PPTP, + KYVPNTYPE_STRONGSWAN +}; + +//密码策略 +enum KyPasswdPolicy{ + KYPASSWD_FORTHISUSER = 0, + KYPASSWD_FORALLUSER, + KYPASSWD_ASKEVERYTIME, + KYPASSWD_ISNOTREQUIRED = 4 +}; + +//认证方式 +enum KyAuthMethod2 { + KYAUTH2_PAP = 1u << 0, //PAP认证 + KYAUTH2_CHAP = 1u << 1, //CHAP认证 + KYAUTH2_MSCHAP = 1u << 2, //MSCHAP认证 + KYAUTH2_MSCHAPV2 = 1u << 3, //MSCHAPV2认证 + KYAUTH2_EAP = 1u << 4, //EAP认证 + KYAUTH2_ALL = KYAUTH2_PAP | KYAUTH2_CHAP | KYAUTH2_MSCHAP | KYAUTH2_MSCHAPV2 | KYAUTH2_EAP +}; +Q_DECLARE_FLAGS(KyAuthMethods, KyAuthMethod2) + +//压缩方式 +enum KyCompressMethod { + KYCOMP_BSD = 1u << 0, //允许BSD压缩 + KYCOMP_DEFLATE = 1u << 1, //允许Deflate压缩 + KYCOMP_TCP = 1u << 2, //允许TCP头压缩 + KYCOMP_PROTO = 1u << 3, //使用协议域压缩协商 + KYCOMP_ADDR = 1u << 4, //使用地址/控制压缩 + KYCOMP_ALL = KYCOMP_BSD | KYCOMP_DEFLATE | KYCOMP_TCP | KYCOMP_PROTO | KYCOMP_ADDR +}; +Q_DECLARE_FLAGS(KyCompressMethods, KyCompressMethod) + +//高级设置 +enum KyMPPEMethod { + KYMPPE_DEFAULT = 0, //默认MPPE加密 + KYMPPE_REQUIRE128, //128位加密 + KYMPPE_REQUIRE40 //40位加密 +}; + +enum KyAuthMethod{ + KYAUTH_ERROR = -1, + KYAUTH_PASSWD = 0, + KYAUTH_KEY, + KYAUTH_AGENT, + KYAUTH_SMARTCARD, + KYAUTH_EAP, + KYAUTH_CERTIFICATE, + KYAUTH_CERTIFICATEANDPASSWD, + KYAUTH_STATICPASSWD +}; + +enum KyCompressMethod2{ + KYCOMP2_LZODISABLE = 0, + KYCOMP2_LZO, + KYCOMP2_LZ4, + KYCOMP2_LZ4V2, + KYCOMP2_LZOADAPTIVE, + KYCOMP2_AUTO +}; + +enum KyVirtualDeviceType{ + KYVIRDEVTYPE_TUN = 0, + KYVIRDEVTYPE_TAP +}; + +enum KyVpnPingMethod{ + KYVPNPING_EXIT = 0, + KYVPNPING_RESTART +}; + +enum KyVpnCheckServerMethod{ + KYCHECKSERVER_NONE = 0, + KYCHECKSERVER_ENTIRETHEME, + KYCHECKSERVER_ENTIRENAME, + KYCHECKSERVER_PRENAME +}; + +enum KyVpnCertType{ + KYVPNCERT_SERVER = 0, + KYVPNCERT_CLIENT +}; + +enum KyVpnTlsMode{ + KYVPNTLS_NONE = 0, + KYVPNTLS_AUTHENTICATION, + KYVPNTLS_CRYPT +}; + +enum KyVpnProxyType{ + KYVPNPROXY_NONE = 0, + KYVPNPROXY_HTTP, + KYVPNPROXY_SOCKS +}; + +enum KyHMACAuthMethod{ + KYHMACAUTH_DEFAULT = 0, + KYHMACAUTH_NONE, + KYHMACAUTH_MD4, + KYHMACAUTH_MD5, + KYHMACAUTH_SHA1, + KYHMACAUTH_SHA224, + KYHMACAUTH_SHA256, + KYHMACAUTH_SHA384, + KYHMACAUTH_SHA512, + KYHMACAUTH_RIPEMD160 +}; + +class KyVpnConfig : public KyConnectSetting +{ +public: + KyVpnType m_vpnType; + QString m_vpnName; + QString m_gateway; + + //认证方式 + KyAuthMethod m_authMethod; + //VPN用户密码信息 + QString m_userName; + //用户密码 + QString m_userPasswd; + //密码策略 + KyPasswdPolicy m_passwdPolicy = KYPASSWD_ASKEVERYTIME; + //NT域 + QString m_ntDomain; + + //CA证书 + QString m_caCertificate; + //用户证书 + QString m_userCertificate; + //用户私钥 + QString m_userKey; + //静态密钥 + QString m_staticKey; + //用户私有密钥密码 + QString m_privatePasswd; + //用户私有密码策略 + KyPasswdPolicy m_privatePasswdPolicy = KYPASSWD_ASKEVERYTIME; + //密钥方向 + QString m_vpnKeyDir; + //本地IP地址 + QString m_localAddress; + //远程IP地址 + QString m_remoteAddress; + //PIN码 + QString m_pinId; + + //MPPE加密开关 + bool m_mppeEnable = false; + //MPPE加密算法 + KyMPPEMethod m_mppeEncryptMethod = KYMPPE_DEFAULT; + //使用有状态加密 + bool m_isAllowStatefulEncryption = false; + //发送PPP回显包 + bool m_sendPppPackage = false; + //认证方式 + KyAuthMethods m_authMethods = KYAUTH2_ALL; + //压缩方式 + KyCompressMethods m_compressMethods = KYCOMP_ALL; + //MRU 最大接收单元 + QString m_mru; + //MTU 最大传输单元 + QString m_mtu; + //请求使用内部IP + bool m_virtual; + //强制UDP封装 + bool m_encap; + //使用IP压缩 + bool m_ipcomp; + //启用自定义密码建议 + bool m_proposal; + //IKE + QString m_ike; + //ESP + QString m_esp; + + //使用自定义网关端口 + bool m_useAssignPort; + QString m_assignPort; + + //使用自定义重协商间隔 + bool m_useRenegSeconds; + QString m_renegSeconds; + + //使用压缩 + bool m_useCompress; + KyCompressMethod2 m_openvpnCompress; + + //使用TCP连接 + bool m_useTcpLink; + + //设置虚拟设备类型 + bool m_setDevType; + KyVirtualDeviceType m_devType; + + //设置虚拟设备名称 + bool m_setDevName; + QString m_devName; + + //使用自定义隧道最大单元传输 + bool m_useTunnelMtu; + QString m_tunnelMtu; + + //使用自定义UDP分片大小 + bool m_useFragmentSize; + QString m_fragmentSize; + + //限制TCP最大段尺寸 + bool m_mssfix; + + //随机化远程主机 + bool m_remoteRandom; + + //IPv6 tun link + bool m_ipv6TunLink; + + //指定Ping周期 + bool m_setPingCycle; + QString m_pingCycle; + + //指定退出或重启Ping + bool m_usePingMethod; + KyVpnPingMethod m_pingMethod; + QString m_pingMethodTime; + + //接受来自任何地址(Float)已通过身份验证的数据包 + bool m_float; + + //指定路由上限 + bool m_setMaxRoute; + QString m_maxRoute; + + //服务器证书检验 + KyVpnCheckServerMethod m_checkServerCa; + + //主题匹配 + QString m_verifyName; + + //验证对等(服务器)证书用法签名 + bool m_useRemoteCertTls; + KyVpnCertType m_remoteCertType; + + //验证对等(服务器)证书nsCertType签名 + bool m_useNsCertTls; + KyVpnCertType m_nsCertType; + + //其他TLS身份验证 + //模式 + KyVpnTlsMode m_vpnTlsMode; + //密钥文件 + QString m_vpnKeyFile; + //密钥方向 + QString m_vpnTlsTaDir; + + //代理 + //代理类型 + KyVpnProxyType m_vpnProxyType; + //服务器地址 + QString m_vpnProxyServer; + //端口 + QString m_vpnProxyPort; + //出错时无限重试 + bool m_vpnProxyRetry; + //代理用户名 + QString m_vpnProxyName; + //代理用户名 + QString m_vpnProxyPasswd; + //代理密码策略 + KyPasswdPolicy m_vpnProxyPasswdPolicy = KYPASSWD_ASKEVERYTIME; + + //安全 + //使用自定义密钥大小 + bool m_useKeysize; + QString m_keySize; + //HMAC认证 + KyHMACAuthMethod m_hmacAuthMethod; + + //IPv4Setting + QStringList m_ipv4DnsSearch; + QString m_ipv4DhcpClientId; + + //IPv6Setting + QStringList m_ipv6DnsSearch; +}; + + + +class KyVpnConnectOperation : public KyConnectOperation +{ + Q_OBJECT +public: + explicit KyVpnConnectOperation(QObject *parent = nullptr); + +public: + void createVpnConnect(KyVpnConfig &vpnSettings); + void setVpnConfig(QString connectUuid, KyVpnConfig &vpnConfig); + KyVpnConfig getVpnConfig(QString connectUuid); + + void activateVpnConnection(const QString connectUuid); + void deactivateVpnConnection(const QString activeConnectName, const QString &activeConnectUuid); + void deleteVpnConnect(const QString &connectUuid); + +private: + KyHMACAuthMethod getHmacAuthMethod(const QString method); + KyAuthMethod getAuthMethod(const QString method); + + void getConnectionSetting(QString connectUuid, KyVpnConfig &vpnConfig); + void setConnectionSetting(NetworkManager::ConnectionSettings::Ptr connectionSettings, KyVpnConfig &vpnConfig); + + void getL2tpConfig(KyVpnConfig &vpnConfig); + void setL2tpConfig(KyVpnConfig &vpnConfig); + void getPptpConfig(KyVpnConfig &vpnConfig); + void setPptpConfig(KyVpnConfig &vpnConfig); + void getStrongswanConfig(KyVpnConfig &vpnConfig); + void setStrongswanConfig(KyVpnConfig &vpnConfig); + void getOpenvpnConfig(KyVpnConfig &vpnConfig); + void setOpenvpnConfig(KyVpnConfig &vpnConfig); + + void getUsrPasswdAndPolicy(KyVpnConfig &vpnConfig); + void setUsrPasswdAndPolicy(KyVpnConfig &vpnConfig); + + void getCertPasswdAndPolicy(KyVpnConfig &vpnConfig); + void setCertPasswdAndPolicy(KyVpnConfig &vpnConfig); + + NMVariantMapMap setIpConfig(NetworkManager::ConnectionSettings::Ptr connectionSettings, KyVpnConfig &vpnConfig); + +private: + QMap m_authMethodMap = { + {"password" , KYAUTH_PASSWD }, + {"key" , KYAUTH_KEY }, + {"agent" , KYAUTH_AGENT }, + {"smartcard" , KYAUTH_SMARTCARD }, + {"eap" , KYAUTH_EAP }, + {"tls" , KYAUTH_CERTIFICATE }, + {"password-tls" , KYAUTH_CERTIFICATEANDPASSWD }, + {"static-password" , KYAUTH_STATICPASSWD } + }; + + QMap m_hmacMap = { + {"none" , KYHMACAUTH_NONE }, + {"RSA-MD4" , KYHMACAUTH_MD4 }, + {"MD5" , KYHMACAUTH_MD5 }, + {"SHA1" , KYHMACAUTH_SHA1 }, + {"SHA224" , KYHMACAUTH_SHA224 }, + {"SHA256" , KYHMACAUTH_SHA256 }, + {"SHA384" , KYHMACAUTH_SHA384 }, + {"SHA512" , KYHMACAUTH_SHA512 }, + {"RIPEMD160" , KYHMACAUTH_RIPEMD160 } + }; + + NMStringMap m_vpnData; + NMStringMap m_vpnSecrets; +}; + +#endif // KYVPNCONNECTOPERATION_H From c87184a139add518327e2bd92dfc4f6a1d15f3f1 Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Mon, 10 Apr 2023 17:38:17 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E6=96=B0=E5=A2=9EVPN=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/component/AddBtn/addnetbtn.cpp | 14 +- plugins/component/AddBtn/addnetbtn.h | 8 + src-vpn/frontend/list-items/vpnlistitem.cpp | 5 +- src-vpn/frontend/list-items/vpnlistitem.h | 2 +- src-vpn/frontend/vpndetails/vpnaddpage.cpp | 234 +++ src-vpn/frontend/vpndetails/vpnaddpage.h | 90 + .../frontend/vpndetails/vpnadvancedpage.cpp | 1508 +++++++++++++++++ src-vpn/frontend/vpndetails/vpnadvancedpage.h | 197 +++ src-vpn/frontend/vpndetails/vpnconfigpage.cpp | 1055 ++++++++++++ src-vpn/frontend/vpndetails/vpnconfigpage.h | 198 +++ src-vpn/frontend/vpndetails/vpndetail.cpp | 439 +++++ src-vpn/frontend/vpndetails/vpndetail.h | 111 ++ src-vpn/frontend/vpndetails/vpndetails.pri | 17 + src-vpn/frontend/vpndetails/vpnipv4page.cpp | 284 ++++ src-vpn/frontend/vpndetails/vpnipv4page.h | 62 + src-vpn/frontend/vpndetails/vpnipv6page.cpp | 240 +++ src-vpn/frontend/vpndetails/vpnipv6page.h | 57 + 17 files changed, 4511 insertions(+), 10 deletions(-) create mode 100644 src-vpn/frontend/vpndetails/vpnaddpage.cpp create mode 100644 src-vpn/frontend/vpndetails/vpnaddpage.h create mode 100644 src-vpn/frontend/vpndetails/vpnadvancedpage.cpp create mode 100644 src-vpn/frontend/vpndetails/vpnadvancedpage.h create mode 100644 src-vpn/frontend/vpndetails/vpnconfigpage.cpp create mode 100644 src-vpn/frontend/vpndetails/vpnconfigpage.h create mode 100644 src-vpn/frontend/vpndetails/vpndetail.cpp create mode 100644 src-vpn/frontend/vpndetails/vpndetail.h create mode 100644 src-vpn/frontend/vpndetails/vpndetails.pri create mode 100644 src-vpn/frontend/vpndetails/vpnipv4page.cpp create mode 100644 src-vpn/frontend/vpndetails/vpnipv4page.h create mode 100644 src-vpn/frontend/vpndetails/vpnipv6page.cpp create mode 100644 src-vpn/frontend/vpndetails/vpnipv6page.h diff --git a/plugins/component/AddBtn/addnetbtn.cpp b/plugins/component/AddBtn/addnetbtn.cpp index 811a0c99..858d85a9 100644 --- a/plugins/component/AddBtn/addnetbtn.cpp +++ b/plugins/component/AddBtn/addnetbtn.cpp @@ -37,23 +37,23 @@ AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent) QHBoxLayout *addLyt = new QHBoxLayout; - QLabel *iconLabel = new QLabel(); - QLabel *textLabel = new QLabel(); + QLabel *iconLabel = new QLabel(this); + m_textLabel = new QLabel(this); if (isWlan) { - textLabel->setText(tr("Add Others")); + m_textLabel->setText(tr("Add Others")); addLyt->addSpacing(8); - addLyt->addWidget(textLabel); + addLyt->addWidget(m_textLabel); } else { - textLabel->setText(tr("Add WiredNetork")); + m_textLabel->setText(tr("Add WiredNetork")); QIcon mAddIcon = QIcon::fromTheme("list-add-symbolic"); - iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(24, 24)))); + iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(16, 16)))); iconLabel->setProperty("useIconHighlightEffect", 0x2); // iconLabel->setProperty("iconHighlightEffectMode", 1); addLyt->addStretch(); addLyt->addWidget(iconLabel); - addLyt->addWidget(textLabel); + addLyt->addWidget(m_textLabel); } addLyt->addStretch(); diff --git a/plugins/component/AddBtn/addnetbtn.h b/plugins/component/AddBtn/addnetbtn.h index 959d2d09..85876755 100644 --- a/plugins/component/AddBtn/addnetbtn.h +++ b/plugins/component/AddBtn/addnetbtn.h @@ -25,6 +25,7 @@ #include #include #include +#include class AddNetBtn : public QPushButton { @@ -33,11 +34,18 @@ public: AddNetBtn(bool isWlan, QWidget *parent = nullptr); ~AddNetBtn(); + void setTextLabel(const QString str) { + m_textLabel->setText(str); + } + protected: virtual void leaveEvent(QEvent * event); virtual void enterEvent(QEvent * event); void paintEvent(QPaintEvent *event); +private: + QLabel *m_textLabel; + Q_SIGNALS: void enterWidget(); void leaveWidget(); diff --git a/src-vpn/frontend/list-items/vpnlistitem.cpp b/src-vpn/frontend/list-items/vpnlistitem.cpp index eb251470..64679857 100644 --- a/src-vpn/frontend/list-items/vpnlistitem.cpp +++ b/src-vpn/frontend/list-items/vpnlistitem.cpp @@ -200,14 +200,15 @@ void VpnListItem::onInfoButtonClicked() m_vpnDetail->activateWindow(); return; } - m_vpnDetail = new vpnDetail(m_vpnConnectItem.m_connectUuid, getConnectionName()); - connect(m_vpnDetail, &vpnDetail::destroyed, [&](){ + m_vpnDetail = new VpnDetail(m_vpnConnectItem.m_connectUuid, getConnectionName()); + connect(m_vpnDetail, &VpnDetail::destroyed, [&](){ if (m_vpnDetail != nullptr) { m_vpnDetail = nullptr; } }); m_vpnDetail->show(); + m_vpnDetail->centerToScreen(); } void VpnListItem::updateConnectionState(ConnectState state) diff --git a/src-vpn/frontend/list-items/vpnlistitem.h b/src-vpn/frontend/list-items/vpnlistitem.h index 95fcfcd7..b2be2edc 100644 --- a/src-vpn/frontend/list-items/vpnlistitem.h +++ b/src-vpn/frontend/list-items/vpnlistitem.h @@ -82,7 +82,7 @@ private: QString m_deviceName = ""; - vpnDetail *m_vpnDetail = nullptr; + VpnDetail *m_vpnDetail = nullptr; }; #endif // VPNLISTITEM_H diff --git a/src-vpn/frontend/vpndetails/vpnaddpage.cpp b/src-vpn/frontend/vpndetails/vpnaddpage.cpp new file mode 100644 index 00000000..087470d1 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnaddpage.cpp @@ -0,0 +1,234 @@ +#include "vpnaddpage.h" +#include +#include "vpnconfigpage.h" + +vpnAddPage::vpnAddPage(QWidget *parent) : QWidget(parent) +{ + m_vpnConnOperation = new KyVpnConnectOperation(this); + initWindow(); + initUI(); + initConnection(); + centerToScreen(); +} + +void vpnAddPage::centerToScreen() +{ + QDesktopWidget* m = QApplication::desktop(); + QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos())); + int desk_x = desk_rect.width(); + int desk_y = desk_rect.height(); + int x = this->width(); + int y = this->height(); + this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); +} + +void vpnAddPage::initWindow() +{ + this->setFixedSize(VPNADDPAGE_SIZE); + this->setWindowTitle(tr("create VPN")); + this->setWindowFlag(Qt::WindowMinMaxButtonsHint,false); + this->setAttribute(Qt::WA_DeleteOnClose); +} + +void vpnAddPage::initUI() +{ + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(VPNADDPAGE_MAINLAYOUT_MARGINS); + mainLayout->setSpacing(VPNADDPAGE_NULLSPACE); + + initVpnTypeFrame(); + initVpnNameFrame(); + initVpnServerFrame(); + initButtonFrame(); + onSetConfimBtnEnable(); + + mainLayout->addWidget(m_vpnTypeFrame); + mainLayout->addWidget(m_vpnNameFrame); + mainLayout->addWidget(m_vpnServerFrame); + mainLayout->addStretch(); + mainLayout->addWidget(m_buttonFrame); + this->setLayout(mainLayout); +} + +void vpnAddPage::initVpnTypeFrame() +{ + m_vpnTypeFrame = new QFrame(this); + m_vpnTypeFrame->setFrameShape(QFrame::Shape::NoFrame); + m_vpnTypeFrame->setFixedSize(VPNADDPAGE_FRAME_FIXEDSIZE); + + QHBoxLayout *typeLayout = new QHBoxLayout(m_vpnTypeFrame); + typeLayout->setContentsMargins(VPNADDPAGE_ITEM_MARGINS); + typeLayout->setSpacing(VPNADDPAGE_NULLSPACE); + + QLabel *vpnTypeLabel = new QLabel(tr("VPN Type"), this); + vpnTypeLabel->setFixedWidth(VPNADDPAGE_LABLE_FIXEDWIDTH); + + m_vpnTypeComboBox = new QComboBox(this); + m_vpnTypeComboBox->setInsertPolicy(QComboBox::NoInsert); + m_vpnTypeComboBox->setFixedWidth(VPNADDPAGE_COMBOBOX_FIXEDWIDTH); + m_vpnTypeComboBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); + + m_vpnTypeComboBox->addItem("L2TP", L2TP); + m_vpnTypeComboBox->addItem("open VPN", OPEN_VPN); + m_vpnTypeComboBox->addItem("PPTP", PPTP); + m_vpnTypeComboBox->addItem("strong-swan", STRONG_SWAN); + + + typeLayout->addWidget(vpnTypeLabel); + typeLayout->addWidget(m_vpnTypeComboBox); + m_vpnTypeFrame->setLayout(typeLayout); +} + +void vpnAddPage::initVpnNameFrame() +{ + m_vpnNameFrame = new QFrame(this); + m_vpnNameFrame->setFrameShape(QFrame::Shape::NoFrame); + m_vpnNameFrame->setFixedSize(VPNADDPAGE_FRAME_FIXEDSIZE); + + QHBoxLayout *nameLayout = new QHBoxLayout(m_vpnNameFrame); + nameLayout->setContentsMargins(VPNADDPAGE_ITEM_MARGINS); + nameLayout->setSpacing(VPNADDPAGE_NULLSPACE); + + QLabel *vpnNameLabel = new QLabel(tr("VPN Name"), this); + vpnNameLabel->setFixedWidth(VPNADDPAGE_LABLE_FIXEDWIDTH); + + m_vpnNameLineEdit = new QLineEdit(this); + m_vpnNameLineEdit->setFixedWidth(VPNADDPAGE_INPUTBOX_FIXEDWIDTH); + m_vpnNameLineEdit->setMaxLength(VPNADDPAGE_NAME_MAX_LENGTH); + m_vpnNameLineEdit->setPlaceholderText(tr("Required")); //必填 + + nameLayout->addWidget(vpnNameLabel); + nameLayout->addWidget(m_vpnNameLineEdit); + m_vpnNameFrame->setLayout(nameLayout); +} + +void vpnAddPage::initVpnServerFrame() +{ + m_vpnServerFrame = new QFrame(this); + m_vpnServerFrame->setFrameShape(QFrame::Shape::NoFrame); + m_vpnServerFrame->setFixedSize(VPNADDPAGE_FRAME_FIXEDSIZE); + + QHBoxLayout *serverLayout = new QHBoxLayout(m_vpnServerFrame); + serverLayout->setContentsMargins(VPNADDPAGE_ITEM_MARGINS); + serverLayout->setSpacing(VPNADDPAGE_NULLSPACE); + + QLabel *vpnServerLabel = new QLabel(tr("VPN Server"), this); + vpnServerLabel->setFixedWidth(VPNADDPAGE_LABLE_FIXEDWIDTH); + + m_vpnServerLineEdit = new QLineEdit(this); + m_vpnServerLineEdit->setFixedWidth(VPNADDPAGE_INPUTBOX_FIXEDWIDTH); + m_vpnServerLineEdit->setPlaceholderText(tr("Required")); //必填 + + serverLayout->addWidget(vpnServerLabel); + serverLayout->addWidget(m_vpnServerLineEdit); + m_vpnServerFrame->setLayout(serverLayout); + + // IP的正则格式限制 + QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + QRegExpValidator *ipExpVal = new QRegExpValidator(rxIp, this); + m_vpnServerLineEdit->setValidator(ipExpVal); +} + +void vpnAddPage::initButtonFrame() +{ + m_buttonFrame = new QFrame(this); + m_buttonFrame->setFixedSize(VPNDETAILPAGE_FRAME_FIXEDSIZE); + + QHBoxLayout *buttonLayout = new QHBoxLayout(m_buttonFrame); + buttonLayout->setContentsMargins(VPNDETAILPAGE_ITEM_MARGINS); + buttonLayout->setSpacing(VPNDETAILPAGE_NULLSPACE); + + QLabel *autoConnectLabel = new QLabel(this); + m_autoConnectBox = new QCheckBox(this); + autoConnectLabel->setText(tr("Auto Connection")); + QWidget *autoConWidget = new QWidget(this); + QHBoxLayout *autoLayout = new QHBoxLayout(autoConWidget); + + autoLayout->setContentsMargins(VPNDETAILPAGE_NULLMAGINS); + autoLayout->setSpacing(VPNDETAILPAGE_NULLSPACE); + autoLayout->addWidget(m_autoConnectBox); + autoLayout->addWidget(autoConnectLabel); + autoConWidget->setLayout(autoLayout); + + m_confimBtn = new QPushButton(this); + m_confimBtn->setFixedSize(VPNDETAILPAGE_BUTTON_FIXEDSIZE); + m_confimBtn->setText(tr("Confirm")); + m_cancelBtn = new QPushButton(this); + m_cancelBtn->setFixedSize(VPNDETAILPAGE_BUTTON_FIXEDSIZE); + m_cancelBtn->setText(tr("Cancel")); + + buttonLayout->addWidget(autoConWidget); + buttonLayout->addStretch(); + buttonLayout->addWidget(m_cancelBtn); + buttonLayout->addSpacing(VPNDETAILPAGE_BUTTON_SPACE); + buttonLayout->addWidget(m_confimBtn); + m_buttonFrame->setLayout(buttonLayout); +} + +void vpnAddPage::initConnection() +{ + if (m_vpnNameLineEdit != nullptr) { + connect(m_vpnNameLineEdit, &QLineEdit::textChanged, this, &vpnAddPage::onSetConfimBtnEnable); + } + + if (m_vpnServerLineEdit != nullptr) { + connect(m_vpnServerLineEdit, &QLineEdit::textChanged, this, &vpnAddPage::onSetConfimBtnEnable); + } + + if (m_cancelBtn != nullptr) { + connect(m_cancelBtn, &QPushButton::clicked, [&] () {this->close();}); + } + + if (m_confimBtn != nullptr) { + connect(m_confimBtn, &QPushButton::clicked, this, &vpnAddPage::onConfimBtnClicked); + } +} + +bool vpnAddPage::checkConfimBtnIsEnabled() +{ + if (m_vpnNameLineEdit->text().isEmpty()) { + qDebug() << "ipv4address empty or invalid"; + return false; + } + + if (m_vpnServerLineEdit->text().isEmpty()) { + qDebug() << "ipv4 netMask empty or invalid"; + return false; + } + return true; +} + +void vpnAddPage::onSetConfimBtnEnable() +{ + m_confimBtn->setEnabled(checkConfimBtnIsEnabled()); +} + +void vpnAddPage::onConfimBtnClicked() +{ + //新建有线连接 + qDebug() << "Confirm create vpn connect"; + if (!createVpnConnect()) { +// setNetdetailSomeEnable(true); +// return; + } + close(); +} + +bool vpnAddPage::createVpnConnect() +{ + KyVpnConfig vpnSetting; + QString connectName = m_vpnNameLineEdit->text(); + vpnSetting.m_gateway = m_vpnServerLineEdit->text(); + vpnSetting.setConnectName(connectName); + vpnSetting.m_vpnName = connectName; + vpnSetting.m_isAutoConnect = m_autoConnectBox->isChecked(); + vpnSetting.m_vpnType = (KyVpnType)m_vpnTypeComboBox->currentData().toInt(); + + m_vpnConnOperation->createVpnConnect(vpnSetting); + return true; +} + +vpnAddPage::~vpnAddPage() +{ + Q_EMIT this->closed(); +} diff --git a/src-vpn/frontend/vpndetails/vpnaddpage.h b/src-vpn/frontend/vpndetails/vpnaddpage.h new file mode 100644 index 00000000..19fe9c64 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnaddpage.h @@ -0,0 +1,90 @@ +#ifndef VPNADDPAGE_H +#define VPNADDPAGE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kyvpnconnectoperation.h" + +#define VPNADDPAGE_MAINLAYOUT_MARGINS 0, 12, 0, 12 +#define VPNADDPAGE_ITEM_MARGINS 24, 0, 24, 0 +#define VPNADDPAGE_NULLMAGINS 0, 0, 0, 0 + +#define VPNADDPAGE_SIZE 520,312 +#define VPNADDPAGE_FRAME_FIXEDSIZE 520, 60 +#define VPNADDPAGE_BUTTON_FIXEDSIZE 96, 36 + +#define VPNADDPAGE_NULLSPACE 0 +#define VPNADDPAGE_BUTTON_SPACE 16 +#define VPNADDPAGE_NAME_MAX_LENGTH 32 +#define VPNADDPAGE_LABLE_FIXEDWIDTH 112 +#define VPNADDPAGE_COMBOBOX_FIXEDWIDTH 360 +#define VPNADDPAGE_INPUTBOX_FIXEDWIDTH 360 + +#define VPNDETAILPAGE_ITEM_MARGINS 24, 0, 24, 0 +#define VPNDETAILPAGE_NULLMAGINS 0, 0, 0, 0 + +#define VPNDETAILPAGE_FRAME_FIXEDSIZE 520, 60 +#define VPNDETAILPAGE_BUTTON_FIXEDSIZE 96, 36 + +#define VPNDETAILPAGE_NULLSPACE 0 +#define VPNDETAILPAGE_BUTTON_SPACE 16 + + + +class vpnAddPage : public QWidget +{ + Q_OBJECT +public: + explicit vpnAddPage(QWidget *parent = nullptr); + void centerToScreen(); + ~vpnAddPage(); + +private: + void initWindow(); + void initUI(); + void initVpnTypeFrame(); + void initVpnNameFrame(); + void initVpnServerFrame(); + void initButtonFrame(); + + void initConnection(); + + bool checkConfimBtnIsEnabled(); + bool createVpnConnect(); + +private: + QFrame *m_vpnTypeFrame = nullptr; + QFrame *m_vpnNameFrame = nullptr; + QFrame *m_vpnServerFrame = nullptr; + QFrame *m_buttonFrame = nullptr; + + QComboBox *m_vpnTypeComboBox = nullptr; + QLineEdit *m_vpnNameLineEdit = nullptr; + QLineEdit *m_vpnServerLineEdit = nullptr; + + QPushButton *m_confimBtn = nullptr; + QPushButton *m_cancelBtn = nullptr; + QCheckBox *m_autoConnectBox = nullptr; + + KyVpnConnectOperation *m_vpnConnOperation = nullptr; + +private Q_SLOTS: + void onConfimBtnClicked(); + void onSetConfimBtnEnable(); + +Q_SIGNALS: + void closed(); +}; + +#endif // VPNADDPAGE_H diff --git a/src-vpn/frontend/vpndetails/vpnadvancedpage.cpp b/src-vpn/frontend/vpndetails/vpnadvancedpage.cpp new file mode 100644 index 00000000..c8a3b08d --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnadvancedpage.cpp @@ -0,0 +1,1508 @@ +#include "vpnadvancedpage.h" + +#include +#include +#include +#define NO_LAYOUT_MARGINS 0, 0, 0, 0 +#define NO_SPACE 0 +#define LAYOUT_SPACING_SMALL 8 +#define HOR_LAYOUT_SPACING 24 +#define LAYOUT_ADD_SPACING 16 +#define VLAYOUT_ADD_SPACING 24 +#define LISTWIDGET_HEIGHT 184 +#define LISTWIDGET_HEIGHT_SMALL 112 +#define MIN_EDIT_WIDTH 150 +#define FIX_EDIT_WIDTH 200 +#define MIN_LABEL_WIDTH 140 +#define MAX_LABEL_WIDTH 240 +#define ONE_LABEL_WIDTH 440 +#define MAX_MRU_LENGTH 4 +#define ITEM_HEIGHT 36 +#define COMP_MODE_PROTOCOL 3 +#define COMP_MODE_ADDRESS 4 +#define LOG_FLAG "[VPN AdvancedPage]" + +VpnAdvancedPage::VpnAdvancedPage(QWidget *parent) : QFrame(parent) +{ + initUi(); + initConnect(); + initDefalutCheckState(); +} + +void VpnAdvancedPage::setL2tpOrPptpAdiaInfo(const KyVpnConfig &vpnInfo) +{ + //L2TP PPTP共有 + m_mppeECheckbox->setChecked(vpnInfo.m_mppeEnable); + if (m_mppeECheckbox->isChecked()) { + m_mppeECombox->setCurrentIndex((int)vpnInfo.m_mppeEncryptMethod); + } else { + m_mppeECombox->setEnabled(false); + } + m_useStatefulECheckbox->setChecked(vpnInfo.m_isAllowStatefulEncryption); + m_useStatefulECheckbox->setEnabled(vpnInfo.m_mppeEnable); + m_papAuthCheckbox->setEnabled(!vpnInfo.m_mppeEnable); + m_chapAuthCheckbox->setEnabled(!vpnInfo.m_mppeEnable); + m_eapAuthCheckbox->setEnabled(!vpnInfo.m_mppeEnable); + + m_sendPppEchoPkgCheckbox->setChecked(vpnInfo.m_sendPppPackage); + + //Auth Methods + m_papAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_PAP)); + m_chapAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_CHAP)); + m_mschapAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAP)); + m_mschap2AuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAPV2)); + m_eapAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_EAP)); + + //Compress Methods + m_bsdCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_BSD)); + m_defaultCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_DEFLATE)); + m_tcpCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_TCP)); + + + //L2TP + if (vpnInfo.m_vpnType == KYVPNTYPE_L2TP) { + m_protocolCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_PROTO)); + m_addressCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_ADDR)); + + m_mruEdit->setText(vpnInfo.m_mru); + m_mtuEdit->setText(vpnInfo.m_mtu); + } +} + +void VpnAdvancedPage::setOpenVpnAdiaInfo(const KyVpnConfig &vpnInfo) +{ + //General + m_customGatewayPortCheckbox->setChecked(vpnInfo.m_useAssignPort); + m_gatewayPortEdit->setText(vpnInfo.m_assignPort); + + m_customRenegotiaInrCheckbox->setChecked(vpnInfo.m_useRenegSeconds); + m_renogotiaInrEdit->setText(vpnInfo.m_renegSeconds); + + m_compressionCheckbox->setChecked(vpnInfo.m_useCompress); + m_compressionCombox->setCurrentIndex((int)vpnInfo.m_openvpnCompress); + + m_tcpConnCheckbox->setChecked(vpnInfo.m_useTcpLink); + + m_setVDevTypeCheckbox->setChecked(vpnInfo.m_setDevType); + m_setVDevTypeCombox->setCurrentIndex((int)vpnInfo.m_devType); + + m_setVDevNameCheckbox->setChecked(vpnInfo.m_setDevName); + m_setVDevNameEdit->setText(vpnInfo.m_devName); + + m_customMtuCheckbox->setChecked(vpnInfo.m_useTunnelMtu); + m_customMtuEdit->setText(vpnInfo.m_tunnelMtu); + + m_customUdpFragSizeCheckbox->setChecked(vpnInfo.m_useFragmentSize); + m_customUdpFragSizeEdit->setText(vpnInfo.m_fragmentSize); + + m_tcpMssCheckbox->setChecked(vpnInfo.m_mssfix); + + m_randomRemoteHostCheckbox->setChecked(vpnInfo.m_remoteRandom); + + m_ipv6TunLinkCheckbox->setChecked(vpnInfo.m_ipv6TunLink); + + m_specPingInrCheckbox->setChecked(vpnInfo.m_setPingCycle); + m_specPingInrEdit->setText(vpnInfo.m_pingCycle); + + m_specExitPingCheckbox->setChecked(vpnInfo.m_usePingMethod); + m_specExitRestarCombox->setCurrentIndex((int)vpnInfo.m_pingMethod); + m_specExRePingEdit->setText(vpnInfo.m_pingMethodTime); + + m_acceptAuthedPaksCheckbox->setChecked(vpnInfo.m_float); + + m_specMaxRouteCheckbox->setChecked(vpnInfo.m_setMaxRoute); + m_specMaxRouteEdit->setText(vpnInfo.m_maxRoute); + + + //TLS settings + m_serverCertCheckCombox->setCurrentIndex((int)vpnInfo.m_checkServerCa); + + m_subjectMatchEdit->setText(vpnInfo.m_verifyName); + + m_usePreviousCertCheckbox->setChecked(vpnInfo.m_useRemoteCertTls); + m_usePreviousCertCombox->setCurrentIndex((int)vpnInfo.m_remoteCertType); + + m_verifyPeerCertCheckbox->setChecked(vpnInfo.m_useNsCertTls); + m_verifyPeerCertCombox->setCurrentIndex((int)vpnInfo.m_nsCertType); + + m_tlsModeCombox->setCurrentIndex(vpnInfo.m_vpnTlsMode); + m_keyPathEdit->setText(vpnInfo.m_vpnKeyFile); + if (vpnInfo.m_vpnTlsMode == KYVPNTLS_AUTHENTICATION) { + if (vpnInfo.m_vpnTlsTaDir == KEY_DIRECTION_ZERO) { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ZERO_INDEX); + } else if (vpnInfo.m_vpnTlsTaDir == KEY_DIRECTION_ONE) { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ONE_INDEX); + } else { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_NONE_INDEX); + } + } else { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_NONE_INDEX); + } + + //Proxies + m_proxyTypeCombox->setCurrentIndex((int)vpnInfo.m_vpnProxyType); + m_proxyServerAddEdit->setText(vpnInfo.m_vpnProxyServer); + m_proxyPortEdit->setText(vpnInfo.m_vpnProxyPort); + m_infiniteRetryCheckbox->setChecked(vpnInfo.m_vpnProxyRetry); + m_proxyUsernameEdit->setText(vpnInfo.m_vpnProxyName); + m_proxyPwdEdit->setText(vpnInfo.m_vpnProxyPasswd); + + //Security + m_customKeySizeCheckbox->setChecked(vpnInfo.m_useKeysize); + m_customKeySizeEdit->setText(vpnInfo.m_keySize); + m_hmacAuthCombox->setCurrentIndex((int)vpnInfo.m_hmacAuthMethod); +} + +void VpnAdvancedPage::setStrongSwanAdiaInfo(const KyVpnConfig &vpnInfo) +{ + m_requestInIPCheckbox->setChecked(vpnInfo.m_virtual); + m_udpEncapCheckbox->setChecked(vpnInfo.m_encap); + m_ipCompCheckbox->setChecked(vpnInfo.m_ipcomp); + m_enablCustomCheckbox->setChecked(vpnInfo.m_proposal); + + if (vpnInfo.m_proposal) { + m_ikeEdit->setText(vpnInfo.m_ike); + m_espEdit->setText(vpnInfo.m_esp); + } +} + +bool VpnAdvancedPage::checkIsChanged(const KyVpnConfig &vpnInfo, VpnType &vpnType) +{ + bool isChanged = false; + switch (vpnType) { + case L2TP: + if (checkL2tpIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case PPTP: + if (checkPptpIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case OPEN_VPN: + if (checkOpenVpnIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case STRONG_SWAN: + if (checkStrongSwanIsChanged(vpnInfo)) { + isChanged = true; + } + break; + default: + qDebug() << LOG_FLAG << "Unknow VPN Type" << vpnType; + break; + } + return isChanged; +} + +bool VpnAdvancedPage::checkL2tpIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_mppeEnable != m_mppeECheckbox->isChecked() + || m_mppeECombox->currentData().toInt() != vpnInfo.m_mppeEncryptMethod + || vpnInfo.m_isAllowStatefulEncryption != m_useStatefulECheckbox->isChecked() + || vpnInfo.m_sendPppPackage != m_sendPppEchoPkgCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_authMethods.testFlag(KYAUTH2_PAP) != m_papAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_CHAP) != m_chapAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAP) != m_mschapAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAPV2) != m_mschap2AuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_EAP) != m_eapAuthCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_compressMethods.testFlag(KYCOMP_BSD) != m_bsdCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_DEFLATE) != m_defaultCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_TCP) != m_tcpCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_PROTO) != m_protocolCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_ADDR) != m_addressCompModeCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_mru != m_mruEdit->text() || vpnInfo.m_mtu != m_mtuEdit->text()) { + isChanged = true; + } + + return isChanged; +} + +bool VpnAdvancedPage::checkPptpIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_mppeEnable != m_mppeECheckbox->isChecked() + || m_mppeECombox->currentData().toInt() != vpnInfo.m_mppeEncryptMethod + || vpnInfo.m_isAllowStatefulEncryption != m_useStatefulECheckbox->isChecked() + || vpnInfo.m_sendPppPackage != m_sendPppEchoPkgCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_authMethods.testFlag(KYAUTH2_PAP) != m_papAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_CHAP) != m_chapAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAP) != m_mschapAuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAPV2) != m_mschap2AuthCheckbox->isChecked() + || vpnInfo.m_authMethods.testFlag(KYAUTH2_EAP) != m_eapAuthCheckbox->isChecked()) { + + isChanged = true; + } + + if (vpnInfo.m_compressMethods.testFlag(KYCOMP_BSD) != m_bsdCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_DEFLATE) != m_defaultCompModeCheckbox->isChecked() + || vpnInfo.m_compressMethods.testFlag(KYCOMP_TCP) != m_tcpCompModeCheckbox->isChecked()) { + + isChanged = true; + } + + return isChanged; +} + +bool VpnAdvancedPage::checkOpenVpnIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + //General + if (vpnInfo.m_useAssignPort != m_customGatewayPortCheckbox->isChecked() + || vpnInfo.m_assignPort != m_gatewayPortEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useRenegSeconds != m_customRenegotiaInrCheckbox->isChecked() + || vpnInfo.m_renegSeconds != m_renogotiaInrEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useCompress != m_compressionCheckbox->isChecked() + || vpnInfo.m_openvpnCompress != m_compressionCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_useTcpLink != m_tcpConnCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_setDevType != m_setVDevTypeCheckbox->isChecked() + || vpnInfo.m_devType != m_setVDevTypeCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_setDevName != m_setVDevNameCheckbox->isChecked() + || vpnInfo.m_devName != m_setVDevNameEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useTunnelMtu != m_customMtuCheckbox->isChecked() + || vpnInfo.m_tunnelMtu != m_customMtuEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useFragmentSize != m_customUdpFragSizeCheckbox->isChecked() + || vpnInfo.m_fragmentSize != m_customUdpFragSizeEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_mssfix != m_tcpMssCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_remoteRandom != m_randomRemoteHostCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_ipv6TunLink != m_ipv6TunLinkCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_setPingCycle != m_specPingInrCheckbox->isChecked() + || vpnInfo.m_pingCycle != m_specPingInrEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_usePingMethod != m_specExitPingCheckbox->isChecked() + || vpnInfo.m_pingMethod != m_specExitRestarCombox->currentData().toInt() + || vpnInfo.m_pingMethodTime != m_specExRePingEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_float != m_acceptAuthedPaksCheckbox->isChecked()) { + isChanged = true; + } + + if (vpnInfo.m_setMaxRoute != m_specMaxRouteCheckbox->isChecked() + || vpnInfo.m_maxRoute != m_specMaxRouteEdit->text()) { + isChanged = true; + } + + + //TLS settings + if (vpnInfo.m_checkServerCa != m_serverCertCheckCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_verifyName != m_subjectMatchEdit->text()) { + isChanged = true; + } + + if (vpnInfo.m_useRemoteCertTls != m_usePreviousCertCheckbox->isChecked() + || vpnInfo.m_remoteCertType != m_usePreviousCertCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_useNsCertTls != m_verifyPeerCertCheckbox->isChecked() + || vpnInfo.m_nsCertType != m_verifyPeerCertCombox->currentData().toInt()) { + isChanged = true; + } + + if (vpnInfo.m_vpnTlsMode != m_tlsModeCombox->currentData().toInt() + || vpnInfo.m_vpnKeyFile != m_keyPathEdit->text() + || vpnInfo.m_vpnTlsTaDir != m_keyDirectionCombox->currentData().toString()) { + isChanged = true; + } + + + //Proxies + int currentProxyType = m_proxyTypeCombox->currentData().toInt(); + if (vpnInfo.m_vpnProxyType != currentProxyType) { + isChanged = true; + } + + if (currentProxyType == HTTP || currentProxyType == SOCKS) { + if (vpnInfo.m_vpnProxyServer != m_proxyServerAddEdit->text() + || vpnInfo.m_vpnProxyPort != m_proxyPortEdit->text() + || vpnInfo.m_vpnProxyRetry != m_infiniteRetryCheckbox->isChecked()) { + isChanged = true; + } + + if (currentProxyType == HTTP) { + if (vpnInfo.m_vpnProxyName != m_proxyUsernameEdit->text() + || vpnInfo.m_vpnProxyPasswd != m_proxyPwdEdit->text()) { + isChanged = true; + } + } + } + + + //Security + if (vpnInfo.m_useKeysize != m_customKeySizeCheckbox->isChecked() + || vpnInfo.m_keySize != m_customKeySizeEdit->text() + || vpnInfo.m_hmacAuthMethod != m_hmacAuthCombox->currentData().toInt()) { + isChanged = true; + } + + + return isChanged; +} + +bool VpnAdvancedPage::checkStrongSwanIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_virtual != m_requestInIPCheckbox->isChecked() + || vpnInfo.m_encap != m_udpEncapCheckbox->isChecked() + || vpnInfo.m_ipcomp != m_ipCompCheckbox->isChecked() + || vpnInfo.m_proposal != m_enablCustomCheckbox->isChecked()) { + + isChanged = true; + } + + if (m_enablCustomCheckbox->isChecked()) { + if (vpnInfo.m_ike != m_ikeEdit->text() || vpnInfo.m_esp != m_espEdit->text()) { + isChanged = true; + } + } + + return isChanged; +} + +void VpnAdvancedPage::updateL2tpOrPptpAdiaInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_mppeEnable = m_mppeECheckbox->isChecked(); + vpnInfo.m_mppeEncryptMethod = (KyMPPEMethod)m_mppeECombox->currentData().toInt(); + vpnInfo.m_isAllowStatefulEncryption = m_useStatefulECheckbox->isChecked(); + vpnInfo.m_sendPppPackage = m_sendPppEchoPkgCheckbox->isChecked(); + + vpnInfo.m_authMethods.setFlag(KYAUTH2_PAP, m_papAuthCheckbox->isChecked()); + vpnInfo.m_authMethods.setFlag(KYAUTH2_CHAP, m_chapAuthCheckbox->isChecked()); + vpnInfo.m_authMethods.setFlag(KYAUTH2_MSCHAP, m_mschapAuthCheckbox->isChecked()); + vpnInfo.m_authMethods.setFlag(KYAUTH2_MSCHAPV2, m_mschap2AuthCheckbox->isChecked()); + vpnInfo.m_authMethods.setFlag(KYAUTH2_EAP, m_eapAuthCheckbox->isChecked()); + + vpnInfo.m_compressMethods.setFlag(KYCOMP_BSD, m_bsdCompModeCheckbox->isChecked()); + vpnInfo.m_compressMethods.setFlag(KYCOMP_DEFLATE, m_defaultCompModeCheckbox->isChecked()); + vpnInfo.m_compressMethods.setFlag(KYCOMP_TCP, m_tcpCompModeCheckbox->isChecked()); + + if (!m_compModeListWidget->item(COMP_MODE_PROTOCOL)->isHidden() + && !m_compModeListWidget->item(COMP_MODE_ADDRESS)->isHidden()) { + vpnInfo.m_compressMethods.setFlag(KYCOMP_PROTO, m_protocolCompModeCheckbox->isChecked()); + vpnInfo.m_compressMethods.setFlag(KYCOMP_ADDR, m_addressCompModeCheckbox->isChecked()); + vpnInfo.m_mru = m_mruEdit->text(); + vpnInfo.m_mtu = m_mtuEdit->text(); + qDebug() << LOG_FLAG << "Update L2TP advanced info finished"; + + } else { + qDebug() << LOG_FLAG << "Update PPTP advanced info finished"; + } +} + +void VpnAdvancedPage::updateOpenVpnAdiaInfo(KyVpnConfig &vpnInfo) +{ + //General + vpnInfo.m_useAssignPort = m_customGatewayPortCheckbox->isChecked(); + vpnInfo.m_assignPort = m_gatewayPortEdit->text(); + + vpnInfo.m_useRenegSeconds = m_customRenegotiaInrCheckbox->isChecked(); + vpnInfo.m_renegSeconds = m_renogotiaInrEdit->text(); + + vpnInfo.m_useCompress = m_compressionCheckbox->isChecked(); + vpnInfo.m_openvpnCompress = (KyCompressMethod2)m_compressionCombox->currentData().toInt(); + + vpnInfo.m_useTcpLink = m_tcpConnCheckbox->isChecked(); + + vpnInfo.m_setDevType = m_setVDevTypeCheckbox->isChecked(); + vpnInfo.m_devType = (KyVirtualDeviceType)m_setVDevTypeCombox->currentData().toInt(); + + vpnInfo.m_setDevName = m_setVDevNameCheckbox->isChecked(); + vpnInfo.m_devName = m_setVDevNameEdit->text(); + + vpnInfo.m_useTunnelMtu = m_customMtuCheckbox->isChecked(); + vpnInfo.m_tunnelMtu = m_customMtuEdit->text(); + + vpnInfo.m_useFragmentSize = m_customUdpFragSizeCheckbox->isChecked(); + vpnInfo.m_fragmentSize = m_customUdpFragSizeEdit->text(); + + vpnInfo.m_mssfix = m_tcpMssCheckbox->isChecked(); + vpnInfo.m_remoteRandom = m_randomRemoteHostCheckbox->isChecked(); + vpnInfo.m_ipv6TunLink = m_ipv6TunLinkCheckbox->isChecked(); + + vpnInfo.m_setPingCycle = m_specPingInrCheckbox->isChecked(); + vpnInfo.m_pingCycle = m_specPingInrEdit->text(); + + vpnInfo.m_usePingMethod = m_specExitPingCheckbox->isChecked(); + vpnInfo.m_pingMethod = (KyVpnPingMethod)m_specExitRestarCombox->currentData().toInt(); + vpnInfo.m_pingMethodTime = m_specExRePingEdit->text(); + + vpnInfo.m_float = m_acceptAuthedPaksCheckbox->isChecked(); + + vpnInfo.m_setMaxRoute = m_specMaxRouteCheckbox->isChecked(); + vpnInfo.m_maxRoute = m_specMaxRouteEdit->text(); + + + //TLS settings + vpnInfo.m_checkServerCa = (KyVpnCheckServerMethod)m_serverCertCheckCombox->currentData().toInt(); + vpnInfo.m_verifyName = m_subjectMatchEdit->text(); + + vpnInfo.m_useRemoteCertTls = m_usePreviousCertCheckbox->isChecked(); + vpnInfo.m_remoteCertType = (KyVpnCertType)m_usePreviousCertCombox->currentData().toInt(); + + vpnInfo.m_useNsCertTls = m_verifyPeerCertCheckbox->isChecked(); + vpnInfo.m_nsCertType = (KyVpnCertType)m_verifyPeerCertCombox->currentData().toInt(); + + vpnInfo.m_vpnTlsMode = (KyVpnTlsMode)m_tlsModeCombox->currentData().toInt(); + vpnInfo.m_vpnKeyFile = m_keyPathEdit->text(); + vpnInfo.m_vpnTlsTaDir = m_keyDirectionCombox->currentData().toString(); + + + //Proxies + vpnInfo.m_vpnProxyType = (KyVpnProxyType)m_proxyTypeCombox->currentData().toInt(); + vpnInfo.m_vpnProxyServer = m_proxyServerAddEdit->text(); + vpnInfo.m_vpnProxyPort = m_proxyPortEdit->text(); + vpnInfo.m_vpnProxyRetry = m_infiniteRetryCheckbox->isChecked(); + vpnInfo.m_vpnProxyName = m_proxyUsernameEdit->text(); + vpnInfo.m_vpnProxyPasswd = m_proxyPwdEdit->text(); + + + //Security + vpnInfo.m_useKeysize = m_customKeySizeCheckbox->isChecked(); + vpnInfo.m_keySize = m_customKeySizeEdit->text(); + vpnInfo.m_hmacAuthMethod = (KyHMACAuthMethod)m_hmacAuthCombox->currentData().toInt(); + + qDebug() << LOG_FLAG << "Update open VPN advanced info finished"; +} + +void VpnAdvancedPage::updateStrongSwanAdiaInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_virtual = m_requestInIPCheckbox->isChecked(); + vpnInfo.m_encap = m_udpEncapCheckbox->isChecked(); + vpnInfo.m_ipcomp = m_ipCompCheckbox->isChecked(); + vpnInfo.m_proposal = m_enablCustomCheckbox->isChecked(); + + vpnInfo.m_ike = m_ikeEdit->text(); + vpnInfo.m_esp = m_espEdit->text(); + + qDebug() << LOG_FLAG << "update strong-swan advanced info finished"; +} + +void VpnAdvancedPage::setVpnAdvancedPage(const VpnType &type) +{ + switch (type) { + case L2TP: + showL2tpAdiaPage(); + break; + case OPEN_VPN: + showOpenVpnAdiaPage(); + break; + case PPTP: + showPptpAdiaPage(); + break; + case STRONG_SWAN: + showSSwanAdiaPage(); + break; + default: + break; + } +} + +void VpnAdvancedPage::paintEvent(QPaintEvent *event) +{ + if (m_authModeListWidget) { + QPalette mpal(m_authModeListWidget->palette()); + mpal.setColor(QPalette::Base, qApp->palette().base().color()); + mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color()); + m_authModeListWidget->setBackgroundRole(QPalette::Base); + m_authModeListWidget->setAlternatingRowColors(true); + m_authModeListWidget->setPalette(mpal); + } + if (m_compModeListWidget) { + QPalette mpal(m_compModeListWidget->palette()); + mpal.setColor(QPalette::Base, qApp->palette().base().color()); + mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color()); + m_compModeListWidget->setBackgroundRole(QPalette::Base); + m_compModeListWidget->setAlternatingRowColors(true); + m_compModeListWidget->setPalette(mpal); + } + if (m_optionsListWidget) { + QPalette mpal(m_optionsListWidget->palette()); + mpal.setColor(QPalette::Base, qApp->palette().base().color()); + mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color()); + m_optionsListWidget->setBackgroundRole(QPalette::Base); + m_optionsListWidget->setAlternatingRowColors(true); + m_optionsListWidget->setPalette(mpal); + } +} + +void VpnAdvancedPage::initUi() +{ + m_defaultAdiaFrame = new QFrame(this); + m_openVpnAdiaFrame = new QFrame(this); + m_sSwanAdiaFrame = new QFrame(this); + + initDefaultAdiaFrame(); + initOpenVpnAdiaFrame(); + initSSwanAdiaFrame(); + + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setSpacing(NO_SPACE); + mainLayout->addWidget(m_defaultAdiaFrame); + mainLayout->addWidget(m_openVpnAdiaFrame); + mainLayout->addWidget(m_sSwanAdiaFrame); + mainLayout->addSpacing(3); + mainLayout->addStretch(); +} + +void VpnAdvancedPage::initConnect() +{ + connect(m_mppeECheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_mppeECombox->setEnabled(state); + m_useStatefulECheckbox->setEnabled(state); + + m_papAuthCheckbox->setEnabled(!state); + m_chapAuthCheckbox->setEnabled(!state); + m_eapAuthCheckbox->setEnabled(!state); + }); + + //strong-Swan + connect(m_enablCustomCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_ikeEspFrame->setEnabled(state); + }); + + //open VPN General + connect(m_customGatewayPortCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_gatewayPortEdit->setEnabled(state); + }); + connect(m_customRenegotiaInrCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_renogotiaInrEdit->setEnabled(state); + }); + connect(m_compressionCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_compressionCombox->setEnabled(state); + }); + connect(m_compressionCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + if (state == Qt::CheckState::Unchecked) { + m_compressionCombox->setCurrentIndex(KYCOMP2_LZODISABLE); + } + }); + connect(m_setVDevTypeCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_setVDevTypeCombox->setEnabled(state); + }); + connect(m_setVDevNameCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_setVDevNameEdit->setEnabled(state); + }); + connect(m_customMtuCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_customMtuEdit->setEnabled(state); + }); + connect(m_customUdpFragSizeCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_customUdpFragSizeEdit->setEnabled(state); + }); + connect(m_specPingInrCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_specPingInrEdit->setEnabled(state); + }); + connect(m_specExitPingCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_specExitRestarCombox->setEnabled(state); + }); + connect(m_specExitPingCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_specExRePingEdit->setEnabled(state); + }); + connect(m_specMaxRouteCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_specMaxRouteEdit->setEnabled(state); + }); + + //open VPN TLS settings + connect(m_serverCertCheckCombox, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) { + if (index == (int)KYCHECKSERVER_NONE) { + m_subjectMatchEdit->setEnabled(false); + } else { + m_subjectMatchEdit->setEnabled(true); + } + }); + connect(m_tlsModeCombox, QOverload::of(&QComboBox::currentIndexChanged), + this, &VpnAdvancedPage::onTlsModeComboxIndexChanged); + connect(m_usePreviousCertCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_usePreviousCertCombox->setEnabled(state); + }); + connect(m_verifyPeerCertCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_verifyPeerCertCombox->setEnabled(state); + }); + //open VPN proxies + connect(m_proxyTypeCombox, QOverload::of(&QComboBox::currentIndexChanged), + this, &VpnAdvancedPage::onProxyTypeComboxIndexChanged); + //open VPN security + connect(m_customKeySizeCheckbox, &QCheckBox::stateChanged, this, [=](int state) { + m_customKeySizeEdit->setEnabled(state); + }); + + connect(m_mruEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_mtuEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_gatewayPortEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_renogotiaInrEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_setVDevNameEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customMtuEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customUdpFragSizeEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specPingInrEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specExRePingEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_subjectMatchEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specMaxRouteEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_keyPathEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_proxyServerAddEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_proxyPortEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_proxyUsernameEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_proxyPwdEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customKeySizeEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_ikeEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_espEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + + connect(m_customGatewayPortCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customRenegotiaInrCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_setVDevNameCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customMtuCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customUdpFragSizeCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specPingInrCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specExitPingCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_specMaxRouteCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_customKeySizeCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + connect(m_enablCustomCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn); + + connect(m_serverCertCheckCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_tlsModeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_proxyTypeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_keyPathChooseBtn, &QPushButton::clicked, this, &VpnAdvancedPage::onKeyPathButtonClicked); +} + +void VpnAdvancedPage::initDefaultAdiaFrame() +{ + /**********控件**********/ + m_mppeECheckbox = new QCheckBox(this); + m_useStatefulECheckbox = new QCheckBox(this); + m_sendPppEchoPkgCheckbox = new QCheckBox(this); + m_authModeLabel = new QLabel(this); + m_compModeLabel = new QLabel(this); + m_mruLabel = new QLabel(this); + m_mtuLabel = new QLabel(this); + + m_mppeECombox = new QComboBox(this); + m_authModeListWidget = new QListWidget(this); + m_papAuthCheckbox = new QCheckBox(this); + m_chapAuthCheckbox = new QCheckBox(this); + m_mschapAuthCheckbox = new QCheckBox(this); + m_mschap2AuthCheckbox = new QCheckBox(this); + m_eapAuthCheckbox = new QCheckBox(this); + + m_compModeListWidget = new QListWidget(this); + m_bsdCompModeCheckbox = new QCheckBox(this); + m_defaultCompModeCheckbox = new QCheckBox(this); + m_tcpCompModeCheckbox = new QCheckBox(this); + m_protocolCompModeCheckbox = new QCheckBox(this); + m_addressCompModeCheckbox = new QCheckBox(this); + + m_mruFrame = new QFrame(this); + m_mruEdit = new QLineEdit(this); + m_mtuEdit = new QLineEdit(this); + + m_authModeListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus); + m_authModeListWidget->setFrameShape(QFrame::Shape::StyledPanel); + addListItem(m_authModeListWidget, m_papAuthCheckbox); + addListItem(m_authModeListWidget, m_chapAuthCheckbox); + addListItem(m_authModeListWidget, m_mschapAuthCheckbox); + addListItem(m_authModeListWidget, m_mschap2AuthCheckbox); + addListItem(m_authModeListWidget, m_eapAuthCheckbox); + + m_compModeListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus); + m_compModeListWidget->setFrameShape(QFrame::Shape::StyledPanel); + addListItem(m_compModeListWidget, m_bsdCompModeCheckbox); + addListItem(m_compModeListWidget, m_defaultCompModeCheckbox); + addListItem(m_compModeListWidget, m_tcpCompModeCheckbox); + addListItem(m_compModeListWidget, m_protocolCompModeCheckbox); + addListItem(m_compModeListWidget, m_addressCompModeCheckbox); + + /**********布局**********/ + QVBoxLayout *defaultAdiaVLayout = new QVBoxLayout(m_defaultAdiaFrame); + defaultAdiaVLayout->setContentsMargins(NO_LAYOUT_MARGINS); + defaultAdiaVLayout->setSpacing(LAYOUT_SPACING_SMALL); + + QFrame *secuFrame= new QFrame(m_defaultAdiaFrame); + QFormLayout *secuLayout = new QFormLayout(secuFrame); + secuLayout->setContentsMargins(NO_LAYOUT_MARGINS); + secuLayout->setVerticalSpacing(LAYOUT_SPACING_SMALL); + secuLayout->setHorizontalSpacing(HOR_LAYOUT_SPACING); + secuLayout->addRow(m_mppeECheckbox, m_mppeECombox); + secuLayout->addRow(m_useStatefulECheckbox); + secuLayout->addRow(m_sendPppEchoPkgCheckbox); + m_mppeECheckbox->setMinimumWidth(MIN_LABEL_WIDTH); + + QHBoxLayout *mruHLayout = new QHBoxLayout(m_mruFrame); + mruHLayout->setContentsMargins(0, 16, 0, 0); + mruHLayout->setSpacing(HOR_LAYOUT_SPACING); + mruHLayout->addWidget(m_mruLabel); + mruHLayout->addWidget(m_mruEdit); + mruHLayout->addStretch(); + mruHLayout->addWidget(m_mtuLabel); + mruHLayout->addWidget(m_mtuEdit); + m_mruEdit->setFixedWidth(MIN_EDIT_WIDTH); + m_mtuEdit->setFixedWidth(MIN_EDIT_WIDTH); + + defaultAdiaVLayout->addWidget(secuFrame); + defaultAdiaVLayout->addSpacing(4); + defaultAdiaVLayout->addWidget(m_authModeLabel); + defaultAdiaVLayout->addWidget(m_authModeListWidget); + defaultAdiaVLayout->addSpacing(LAYOUT_ADD_SPACING); + defaultAdiaVLayout->addWidget(m_compModeLabel); + defaultAdiaVLayout->addWidget(m_compModeListWidget); + defaultAdiaVLayout->addWidget(m_mruFrame); + m_authModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT); + m_compModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT); + + /**********控件显示**********/ + m_mppeECheckbox->setText(tr("MPPE encryption algorithm:")); //MPPE加密算法: + m_useStatefulECheckbox->setText(tr("Use Stateful encryption")); //使用有状态加密 + m_sendPppEchoPkgCheckbox->setText(tr("Send PPP echo packets")); //发送PPP回显包 + m_authModeLabel->setText(tr("Authentication Mode:")); //认证方式: + m_papAuthCheckbox->setText(tr("PAP authentication")); //PAP认证 + m_chapAuthCheckbox->setText(tr("CHAP authentication")); //CHAP认证 + m_mschapAuthCheckbox->setText(tr("MSCHAP authentication")); //MSCHAP认证 + m_mschap2AuthCheckbox->setText(tr("MSCHAP2 authentication")); //MSCHAP2认证 + m_eapAuthCheckbox->setText(tr("EAP authentication")); //EAP认证 + m_compModeLabel->setText(tr("Compression Mode:")); //压缩方式: + m_bsdCompModeCheckbox->setText(tr("Allow BSD data compression")); //允许BSD压缩 + m_defaultCompModeCheckbox->setText(tr("Allow Default data compression")); //允许Default压缩 + m_tcpCompModeCheckbox->setText(tr("Allow TCP header compression")); //允许TCP头压缩 + m_protocolCompModeCheckbox->setText(tr("Use protocol field compression negotiation")); //使用协议域压缩协商 + m_addressCompModeCheckbox->setText(tr("Use Address/Control compression")); //使用地址/控制压缩 + m_mruLabel->setText("MRU"); + m_mtuLabel->setText("MTU"); + m_mruEdit->setText("0"); + m_mtuEdit->setText("0"); + + m_mppeECombox->addItem(tr("All Available"), KYMPPE_DEFAULT); //任意 + m_mppeECombox->addItem(tr("128-bit"), KYMPPE_REQUIRE128); //128位 + m_mppeECombox->addItem(tr("40-bit"), KYMPPE_REQUIRE40); //40位 + + //控件输入格式限制 + QRegExp rxNumber("^[0-9]+$"); + m_mruEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_mtuEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_mruEdit->setMaxLength(MAX_MRU_LENGTH); + m_mtuEdit->setMaxLength(MAX_MRU_LENGTH); +} + +void VpnAdvancedPage::initOpenVpnAdiaFrame() +{ + /**********控件**********/ + //General + QLabel *generalLabel = new QLabel(m_openVpnAdiaFrame); + m_customGatewayPortCheckbox = new QCheckBox(this); + m_customRenegotiaInrCheckbox = new QCheckBox(this); + m_compressionCheckbox = new QCheckBox(this); + m_tcpConnCheckbox = new QCheckBox(this); + m_setVDevTypeCheckbox = new QCheckBox(this); + m_setVDevNameCheckbox = new QCheckBox(this); + m_customMtuCheckbox = new QCheckBox(this); + m_customUdpFragSizeCheckbox = new QCheckBox(this); + m_tcpMssCheckbox = new QCheckBox(this); + m_randomRemoteHostCheckbox = new QCheckBox(this); + m_ipv6TunLinkCheckbox = new QCheckBox(this); + m_specPingInrCheckbox = new QCheckBox(this); + m_specExitPingCheckbox = new QCheckBox(this); + m_acceptAuthedPaksCheckbox = new QCheckBox(this); + m_specMaxRouteCheckbox = new QCheckBox(this); + + m_gatewayPortEdit = new QLineEdit(this); + m_renogotiaInrEdit = new QLineEdit(this); + m_setVDevNameEdit = new QLineEdit(this); + m_customMtuEdit = new QLineEdit(this); + m_customUdpFragSizeEdit = new QLineEdit(this); + m_specPingInrEdit = new QLineEdit(this); + m_specExRePingEdit = new QLineEdit(this); + m_specMaxRouteEdit = new QLineEdit(this); + m_compressionCombox = new QComboBox(this); + m_setVDevTypeCombox = new QComboBox(this); + m_specExitRestarCombox = new QComboBox(this); + m_customRenoInrLabel = new FixLabel(this); + m_customMtuLabel = new FixLabel(this); + m_acceptAuthedPaksLabel = new FixLabel(this); + m_customUdpLabel = new FixLabel(this); + + //TLS settings + QLabel *tlsSettingLabel = new QLabel(m_openVpnAdiaFrame); + QLabel *serverCertCheckLabel = new QLabel(m_openVpnAdiaFrame); + QLabel *tlsModeLabel = new QLabel(m_openVpnAdiaFrame); + + FixLabel *usePreviousCertLabel = new FixLabel(m_openVpnAdiaFrame); + FixLabel *verifyPeerCertLabel = new FixLabel(m_openVpnAdiaFrame); + + m_subjectMatchLabel = new QLabel(this); + m_keyPathLabel = new QLabel(this); + m_keyDirectionLabel = new QLabel(this); + m_subjectMatchEdit = new QLineEdit(this); + m_keyPathEdit = new QLineEdit(this); + m_keyPathChooseBtn = new QPushButton(this); + m_usePreviousCertCheckbox = new QCheckBox(this); + m_verifyPeerCertCheckbox = new QCheckBox(this); + m_serverCertCheckCombox = new QComboBox(this); + m_usePreviousCertCombox = new QComboBox(this); + m_verifyPeerCertCombox = new QComboBox(this); + m_tlsModeCombox = new QComboBox(this); + m_keyDirectionCombox = new QComboBox(this); + + //Proxies + QLabel *proxiesLabel = new QLabel(m_openVpnAdiaFrame); + QLabel *proxyTypeLabel = new QLabel(m_openVpnAdiaFrame); + m_proxyServerAddLabel = new QLabel(this); + m_proxyPortLabel = new QLabel(this); + m_proxyUsernameLabel = new QLabel(this); + m_proxyPwdLabel = new QLabel(this); + m_proxyTypeCombox = new QComboBox(this); + m_infiniteRetryCheckbox = new QCheckBox(this); + m_proxyServerAddEdit = new QLineEdit(this); + m_proxyPortEdit = new QLineEdit(this); + m_proxyUsernameEdit = new QLineEdit(this); + m_proxyPwdEdit = new KPasswordEdit(this); + m_proxyPwdEdit->setClearButtonEnabled(false); + + //Security + QLabel *securityLabel = new QLabel(m_openVpnAdiaFrame); + QLabel *hmacLabel = new QLabel(m_openVpnAdiaFrame); + m_customKeySizeCheckbox = new QCheckBox(this); + m_customKeySizeEdit = new QLineEdit(this); + m_hmacAuthCombox = new QComboBox(this); + + + /**********布局**********/ + QVBoxLayout *openVpnAdiaVLayout = new QVBoxLayout(m_openVpnAdiaFrame); + openVpnAdiaVLayout->setContentsMargins(NO_LAYOUT_MARGINS); + + //General + QFrame *generalFrame = new QFrame(m_openVpnAdiaFrame); + QFormLayout *generalLayout = new QFormLayout(generalFrame); + + QWidget *customRenoInrWidget = new QWidget(this); + initCheckWidget(m_customRenegotiaInrCheckbox, m_customRenoInrLabel, customRenoInrWidget); + + QWidget *customMtuWidget = new QWidget(this); + initCheckWidget(m_customMtuCheckbox, m_customMtuLabel, customMtuWidget); + + QWidget *customUdpWidget = new QWidget(this); + initCheckWidget(m_customUdpFragSizeCheckbox, m_customUdpLabel, customUdpWidget); + + QWidget *acceptAuthWidget = new QWidget(this); + initCheckWidget(m_acceptAuthedPaksCheckbox, m_acceptAuthedPaksLabel, acceptAuthWidget); + + QWidget *exitRestarWidget = new QWidget(this); + QHBoxLayout *exitRestarLayout = new QHBoxLayout(exitRestarWidget); + exitRestarLayout->setContentsMargins(NO_LAYOUT_MARGINS); + exitRestarLayout->addWidget(m_specExitRestarCombox); + exitRestarLayout->addWidget(m_specExRePingEdit); + + generalLayout->setContentsMargins(NO_LAYOUT_MARGINS); + generalLayout->addRow(m_customGatewayPortCheckbox, m_gatewayPortEdit); + generalLayout->addRow(customRenoInrWidget, m_renogotiaInrEdit); + generalLayout->addRow(m_compressionCheckbox, m_compressionCombox); + generalLayout->addRow(m_tcpConnCheckbox); + generalLayout->addRow(m_setVDevTypeCheckbox, m_setVDevTypeCombox); + generalLayout->addRow(m_setVDevNameCheckbox, m_setVDevNameEdit); + generalLayout->addRow(customMtuWidget, m_customMtuEdit); + generalLayout->addRow(customUdpWidget, m_customUdpFragSizeEdit); + generalLayout->addRow(m_tcpMssCheckbox); + generalLayout->addRow(m_randomRemoteHostCheckbox); + generalLayout->addRow(m_ipv6TunLinkCheckbox); + generalLayout->addRow(m_specPingInrCheckbox, m_specPingInrEdit); + generalLayout->addRow(m_specExitPingCheckbox, exitRestarWidget); + generalLayout->addRow(acceptAuthWidget); + generalLayout->addRow(m_specMaxRouteCheckbox, m_specMaxRouteEdit); + + //TLS settings + QFrame *tlsSettingsFrame = new QFrame(m_openVpnAdiaFrame); + QFormLayout *tlsLayout = new QFormLayout(tlsSettingsFrame); + + QWidget *usePreviousCertWidget = new QWidget(this); + initCheckWidget(m_usePreviousCertCheckbox, usePreviousCertLabel, usePreviousCertWidget); + + QWidget *verifyPeerCertWidget = new QWidget(this); + initCheckWidget(m_verifyPeerCertCheckbox, verifyPeerCertLabel, verifyPeerCertWidget); + + QWidget *keyfileWidget = new QWidget(this); + QGridLayout *keyfileLayout = new QGridLayout(keyfileWidget); + keyfileLayout->setContentsMargins(NO_LAYOUT_MARGINS); + keyfileLayout->addWidget(m_keyPathLabel, 0, 0); + keyfileLayout->addWidget(m_keyPathEdit, 0, 1); + keyfileLayout->addWidget(m_keyPathChooseBtn, 0, 2); + keyfileLayout->addWidget(m_keyDirectionLabel, 1, 0); + keyfileLayout->addWidget(m_keyDirectionCombox, 1, 1, 1, 2); + m_keyDirectionLabel->setMinimumWidth(MIN_LABEL_WIDTH); + + tlsLayout->setContentsMargins(NO_LAYOUT_MARGINS); + tlsLayout->addRow(serverCertCheckLabel, m_serverCertCheckCombox); + tlsLayout->addRow(m_subjectMatchLabel, m_subjectMatchEdit); + tlsLayout->addRow(usePreviousCertWidget, m_usePreviousCertCombox); + tlsLayout->addRow(verifyPeerCertWidget, m_verifyPeerCertCombox); + tlsLayout->addRow(tlsModeLabel, m_tlsModeCombox); + tlsLayout->addRow(keyfileWidget); + + //Proxies + QFrame *proxiesFrame = new QFrame(m_openVpnAdiaFrame); + QFormLayout *proxiesLayout = new QFormLayout(proxiesFrame); + proxiesLayout->setContentsMargins(NO_LAYOUT_MARGINS); + proxiesLayout->addRow(proxyTypeLabel, m_proxyTypeCombox); + proxiesLayout->addRow(m_proxyServerAddLabel, m_proxyServerAddEdit); + proxiesLayout->addRow(m_proxyPortLabel, m_proxyPortEdit); + proxiesLayout->addRow(nullptr, m_infiniteRetryCheckbox); + proxiesLayout->addRow(m_proxyUsernameLabel, m_proxyUsernameEdit); + proxiesLayout->addRow(m_proxyPwdLabel, m_proxyPwdEdit); + m_proxyUsernameLabel->setMinimumWidth(MIN_LABEL_WIDTH); + + //Security + QFrame *securityFrame = new QFrame(m_openVpnAdiaFrame); + QFormLayout *securityLayout = new QFormLayout(securityFrame); + securityLayout->setContentsMargins(NO_LAYOUT_MARGINS); + securityLayout->addRow(m_customKeySizeCheckbox, m_customKeySizeEdit); + securityLayout->addRow(hmacLabel, m_hmacAuthCombox); + + //all + openVpnAdiaVLayout->setSpacing(LAYOUT_SPACING_SMALL); + openVpnAdiaVLayout->addWidget(generalLabel); + openVpnAdiaVLayout->addWidget(generalFrame); + openVpnAdiaVLayout->addSpacing(VLAYOUT_ADD_SPACING); + openVpnAdiaVLayout->addWidget(tlsSettingLabel); + openVpnAdiaVLayout->addWidget(tlsSettingsFrame); + openVpnAdiaVLayout->addSpacing(VLAYOUT_ADD_SPACING); + openVpnAdiaVLayout->addWidget(proxiesLabel); + openVpnAdiaVLayout->addWidget(proxiesFrame); + openVpnAdiaVLayout->addSpacing(VLAYOUT_ADD_SPACING); + openVpnAdiaVLayout->addWidget(securityLabel); + openVpnAdiaVLayout->addWidget(securityFrame); + + /**********控件显示**********/ + m_customGatewayPortCheckbox->setText(tr("Use custom gateway port")); //使用自定义网关端口 + m_compressionCheckbox->setText(tr("Use compression")); //使用压缩 + m_tcpConnCheckbox->setText(tr("Use a TCP connection")); //使用TCP连接 + m_setVDevTypeCheckbox->setText(tr("Set virtual device type")); //设置虚拟设备类型 + m_setVDevNameCheckbox->setText(tr("Set virtual device name")); //设置虚拟设备名称 + m_tcpMssCheckbox->setText(tr("Limit TCP Maximum Segment Size(MSS)")); //限制TCP最大段尺寸(MSS) + m_randomRemoteHostCheckbox->setText(tr("Randomize remote hosts")); //随机化远程主机 + m_ipv6TunLinkCheckbox->setText(tr("IPv6 tun link")); //IPv6 tun连接 + m_specPingInrCheckbox->setText(tr("Specify ping interval")); //指定ping周期 + m_specExitPingCheckbox->setText(tr("Specify exit or restart ping")); //指定退出或重启的Ping + m_specMaxRouteCheckbox->setText(tr("Specify max routes")); //指定路由上限 + m_infiniteRetryCheckbox->setText(tr("Infinite retry on error")); //出错时无限重试 + m_customKeySizeCheckbox->setText(tr("Use custom key size")); //使用自定义密钥大小 + m_keyPathChooseBtn->setText(tr("Choose")); //选择 + + m_customRenoInrLabel->setFixedWidth(MAX_LABEL_WIDTH); + m_customRenoInrLabel->setLabelText(tr("Use custom renegotiation interval")); //使用自定义重协商间隔 + m_customMtuLabel->setFixedWidth(MAX_LABEL_WIDTH); + m_customMtuLabel->setLabelText(tr("Use custom tunnel Maximum Transmission Umit(MTU)")); //使用自定义隧道最大单元传输(MTU) + m_customUdpLabel->setFixedWidth(MAX_LABEL_WIDTH); + m_customUdpLabel->setLabelText(tr("Use custom UDP fragment size")); //使用自定义UDP分片大小 + m_acceptAuthedPaksLabel->setFixedWidth(440);//文本显示宽度 + m_acceptAuthedPaksLabel->setLabelText(tr("Accept authenticated packets from any address (Float)")); //接受来自任何地址(Float)已通过身份验证的数据包 + + m_subjectMatchLabel->setText(tr("Subject Match")); //主题匹配 + m_keyPathLabel->setText(tr("Key File")); //密钥文件 + m_keyDirectionLabel->setText(tr("Key Direction")); //密钥方向 + + m_proxyServerAddLabel->setText(tr("Server Address")); //服务器地址 + m_proxyPortLabel->setText(tr("Port")); //端口 + m_proxyUsernameLabel->setText(tr("Proxy USername")); //代理用户名 + m_proxyPwdLabel->setText(tr("Proxy Password")); //代理密码 + + generalLabel->setText(tr("General")); //常规 + tlsSettingLabel->setText(tr("TLS settings")); + serverCertCheckLabel->setText(tr("Server Certificate Check")); //服务器证书检验 + usePreviousCertLabel->setFixedWidth(MAX_LABEL_WIDTH); + usePreviousCertLabel->setLabelText(tr("Use the previous authentication end (server) certificate")); //使用前面验证端(服务器)证书 + verifyPeerCertLabel->setFixedWidth(MAX_LABEL_WIDTH); + verifyPeerCertLabel->setLabelText(tr("Verify peer (server) certificate nsCertType specification")); //验证对等点(服务器)证书nsCertType指定 + tlsModeLabel->setText(tr("Mode")); + proxiesLabel->setText(tr("Proxies")); + proxyTypeLabel->setText(tr("Proxy Type")); + securityLabel->setText(tr("Security")); + hmacLabel->setText(tr("HMAC Authentication")); //HMAC认证 + hmacLabel->setFixedWidth(268); //调整控件对齐=MAX_LABEL_WIDTH+28 + + QFont font = generalLabel->font(); + font.setWeight(QFont::Weight::Medium); + generalLabel->setFont(font); + tlsSettingLabel->setFont(font); + proxiesLabel->setFont(font); + securityLabel->setFont(font); + + m_setVDevNameEdit->setPlaceholderText(tr("Input content")); //输入内容 + + m_compressionCombox->addItem(tr("No"), KYCOMP2_LZODISABLE); //否 + m_compressionCombox->addItem("LZO", KYCOMP2_LZO); + m_compressionCombox->addItem("LZ4", KYCOMP2_LZ4); + m_compressionCombox->addItem("LZ4 v2", KYCOMP2_LZ4V2); + m_compressionCombox->addItem(tr("Self-adaption"), KYCOMP2_LZOADAPTIVE); //自适应 + m_compressionCombox->addItem(tr("Automatic"), KYCOMP2_AUTO); //自动 + + m_setVDevTypeCombox->addItem("TUN", KYVIRDEVTYPE_TUN); + m_setVDevTypeCombox->addItem("TAP", KYVIRDEVTYPE_TAP); + + m_specExitRestarCombox->addItem(tr("Exit"), KYVPNPING_EXIT); //退出 + m_specExitRestarCombox->addItem(tr("Restart"), KYVPNPING_RESTART); //重启 + + m_serverCertCheckCombox->addItem(tr("Don't verify certificate identification"), KYCHECKSERVER_NONE); //不验证证书标识 + m_serverCertCheckCombox->addItem(tr("Verify the entire subject exactly"), KYCHECKSERVER_ENTIRETHEME); //确切地验证整个主题 + m_serverCertCheckCombox->addItem(tr("Verify name exactly"), KYCHECKSERVER_ENTIRENAME); //精确验证名称 + m_serverCertCheckCombox->addItem(tr("Verify name by prefix"), KYCHECKSERVER_PRENAME); //按前缀验证名称 + + m_usePreviousCertCombox->addItem(tr("Server"), KYVPNCERT_SERVER); + m_usePreviousCertCombox->addItem(tr("Client"), KYVPNCERT_CLIENT); + + m_verifyPeerCertCombox->addItem(tr("Server"), KYVPNCERT_SERVER); + m_verifyPeerCertCombox->addItem(tr("Client"), KYVPNCERT_CLIENT); + + m_tlsModeCombox->addItem(tr("None"), NONE); //无 + m_tlsModeCombox->addItem(tr("TLS-Certification"), TLS_CERT); //TLS-认证 + m_tlsModeCombox->addItem(tr("TLS-Encryption"), TLS_ENCRYPTION); //TLS-加密 + + m_keyDirectionCombox->addItem(tr("None"), KEY_DIRECTION_NONE); //无 + m_keyDirectionCombox->addItem("0", KEY_DIRECTION_ZERO); + m_keyDirectionCombox->addItem("1", KEY_DIRECTION_ONE); + + m_proxyTypeCombox->addItem(tr("Not Required"), NO); //不需要 + m_proxyTypeCombox->addItem("HTTP", HTTP); + m_proxyTypeCombox->addItem("SOCKS", SOCKS); + + m_hmacAuthCombox->addItem(tr("Default"), KYHMACAUTH_DEFAULT); //默认 + m_hmacAuthCombox->addItem(tr("None"), KYHMACAUTH_NONE); //无 + m_hmacAuthCombox->addItem("MD-4", KYHMACAUTH_MD4); + m_hmacAuthCombox->addItem("MD-5", KYHMACAUTH_MD5); + m_hmacAuthCombox->addItem("SHA-1", KYHMACAUTH_SHA1); + m_hmacAuthCombox->addItem("SHA-224", KYHMACAUTH_SHA224); + m_hmacAuthCombox->addItem("SHA-256", KYHMACAUTH_SHA256); + m_hmacAuthCombox->addItem("SHA-384", KYHMACAUTH_SHA384); + m_hmacAuthCombox->addItem("SHA-512", KYHMACAUTH_SHA512); + m_hmacAuthCombox->addItem("RIPEMD-160", KYHMACAUTH_RIPEMD160); + + //控件输入格式限制 + QRegExp rxNumber("^[0-9]+$"); + m_gatewayPortEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_renogotiaInrEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_customMtuEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_customUdpFragSizeEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_specPingInrEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_specExRePingEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_specMaxRouteEdit->setValidator(new QRegExpValidator(rxNumber, this)); + + // IP的正则格式限制 + QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + m_proxyServerAddEdit->setValidator(new QRegExpValidator(rxIp, this)); + + //default + m_gatewayPortEdit->setText("1194"); + m_renogotiaInrEdit->setText("0"); + m_customMtuEdit->setText("1500"); + m_customUdpFragSizeEdit->setText("1500"); + m_specPingInrEdit->setText("30"); + m_specExRePingEdit->setText("30"); + m_specMaxRouteEdit->setText("30"); + if (m_serverCertCheckCombox->currentData().toInt() == (int)KYCHECKSERVER_NONE) { + m_subjectMatchEdit->setEnabled(false); + } else { + m_subjectMatchEdit->setEnabled(true); + } + onTlsModeComboxIndexChanged(); + onProxyTypeComboxIndexChanged(); +} + +void VpnAdvancedPage::initSSwanAdiaFrame() +{ + /**********控件**********/ + QLabel *optionsLabel = new QLabel(this); + QLabel *ikeLabel = new QLabel(this); + QLabel *espLabel = new QLabel(this); + m_optionsListWidget = new QListWidget(this); + m_requestInIPCheckbox = new QCheckBox(this); + m_udpEncapCheckbox = new QCheckBox(this); + m_ipCompCheckbox = new QCheckBox(this); + m_enablCustomCheckbox = new QCheckBox(this); + m_ikeEdit = new QLineEdit(this); + m_espEdit = new QLineEdit(this); + m_ikeEspFrame = new QFrame(m_sSwanAdiaFrame); + + /**********布局**********/ + QVBoxLayout *sSwanAdiaVLayout = new QVBoxLayout(m_sSwanAdiaFrame); + sSwanAdiaVLayout->setContentsMargins(NO_LAYOUT_MARGINS); + sSwanAdiaVLayout->setSpacing(LAYOUT_SPACING_SMALL); + + QFormLayout *ikeEspFrameLayout = new QFormLayout(m_ikeEspFrame); + ikeEspFrameLayout->setContentsMargins(NO_LAYOUT_MARGINS); + ikeEspFrameLayout->setHorizontalSpacing(HOR_LAYOUT_SPACING); + ikeEspFrameLayout->setVerticalSpacing(LAYOUT_ADD_SPACING); + ikeEspFrameLayout->addRow(ikeLabel, m_ikeEdit); + ikeEspFrameLayout->addRow(espLabel, m_espEdit); + + sSwanAdiaVLayout->addWidget(optionsLabel); + sSwanAdiaVLayout->addWidget(m_optionsListWidget); + sSwanAdiaVLayout->addSpacing(LAYOUT_ADD_SPACING); + sSwanAdiaVLayout->addWidget(m_enablCustomCheckbox); + sSwanAdiaVLayout->addWidget(m_ikeEspFrame); + sSwanAdiaVLayout->addStretch(); + m_optionsListWidget->setFixedHeight(LISTWIDGET_HEIGHT_SMALL); + + /**********控件显示**********/ + optionsLabel->setText(tr("Options:")); //选项: + ikeLabel->setText("IKE"); + espLabel->setText("ESP"); + m_requestInIPCheckbox->setText(tr("Request an inner IP address")); //请求内部IP地址 + m_udpEncapCheckbox->setText(tr("Enforce UDP encapsulation")); //强制UDP封装 + m_ipCompCheckbox->setText(tr("Use IP compression")); //使用IP压缩 + m_enablCustomCheckbox->setText(tr("Enable custom password suggestions")); //启用自定义密码建议 + + m_optionsListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus); + m_optionsListWidget->setFrameShape(QFrame::Shape::StyledPanel); + addListItem(m_optionsListWidget, m_requestInIPCheckbox); + addListItem(m_optionsListWidget, m_udpEncapCheckbox); + addListItem(m_optionsListWidget, m_ipCompCheckbox); + + //strong-Swan default + m_enablCustomCheckbox->setChecked(false); + m_ikeEspFrame->setEnabled(false); +} + +void VpnAdvancedPage::initDefalutCheckState() +{ + m_mppeECheckbox->setChecked(false); + m_mppeECombox->setEnabled(m_mppeECheckbox->isChecked()); + + //openVPN + m_customGatewayPortCheckbox->setChecked(true); + m_customRenegotiaInrCheckbox->setChecked(true); + m_compressionCheckbox->setChecked(true); + m_tcpConnCheckbox->setChecked(true); + m_setVDevTypeCheckbox->setChecked(true); + m_setVDevNameCheckbox->setChecked(true); + m_customMtuCheckbox->setChecked(true); + m_customUdpFragSizeCheckbox->setChecked(true); + m_tcpMssCheckbox->setChecked(true); + m_randomRemoteHostCheckbox->setChecked(true); + m_ipv6TunLinkCheckbox->setChecked(true); + m_specPingInrCheckbox->setChecked(true); + m_specExitPingCheckbox->setChecked(true); + m_acceptAuthedPaksCheckbox->setChecked(true); + m_specMaxRouteCheckbox->setChecked(true); + + m_gatewayPortEdit->setEnabled(m_customGatewayPortCheckbox->isChecked()); + m_renogotiaInrEdit->setEnabled(m_customRenegotiaInrCheckbox->isChecked()); + m_setVDevNameEdit->setEnabled(m_setVDevNameCheckbox->isChecked()); + m_customMtuEdit->setEnabled(m_customMtuCheckbox->isChecked()); + m_customUdpFragSizeEdit->setEnabled(m_customUdpFragSizeCheckbox->isChecked()); + m_specPingInrEdit->setEnabled(m_specPingInrCheckbox->isChecked()); + m_specExRePingEdit->setEnabled(m_specExitPingCheckbox->isChecked()); + m_specMaxRouteEdit->setEnabled(m_specMaxRouteCheckbox->isChecked()); + m_compressionCombox->setEnabled(m_compressionCheckbox->isChecked()); + m_setVDevTypeCombox->setEnabled(m_setVDevTypeCheckbox->isChecked()); + m_specExitRestarCombox->setEnabled(m_specExitPingCheckbox->isChecked()); + + m_usePreviousCertCombox->setEnabled(m_usePreviousCertCheckbox->isChecked()); + m_verifyPeerCertCombox->setEnabled(m_verifyPeerCertCheckbox->isChecked()); + + m_customKeySizeEdit->setEnabled(m_customKeySizeCheckbox->isChecked()); +} + +void VpnAdvancedPage::addListItem(QListWidget *listWidget, QWidget *widget) +{ + QListWidgetItem *listWidgetItem = new QListWidgetItem(listWidget); + QWidget *itemWidget = new QWidget(listWidget); + QHBoxLayout *hLayout = new QHBoxLayout(itemWidget); + hLayout->setContentsMargins(16, 0, 0, 0); + hLayout->addWidget(widget); + listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT)); + listWidgetItem->setFlags(Qt::NoItemFlags); + listWidget->addItem(listWidgetItem); + listWidget->setItemWidget(listWidgetItem, itemWidget); +} + +void VpnAdvancedPage::initCheckWidget(QCheckBox *checkBox, FixLabel *label, QWidget *widget) +{ + QHBoxLayout *hLayout = new QHBoxLayout(widget); + hLayout->setContentsMargins(NO_LAYOUT_MARGINS); + hLayout->setSpacing(4); + hLayout->addWidget(checkBox); + hLayout->addWidget(label); + hLayout->addStretch(); +} + +void VpnAdvancedPage::onProxyTypeComboxIndexChanged() +{ + switch (m_proxyTypeCombox->currentData().toInt()) { + case NO: + m_proxyServerAddEdit->clear(); + m_proxyPortEdit->clear(); + m_proxyUsernameEdit->clear(); + m_proxyPwdEdit->clear(); + m_infiniteRetryCheckbox->setChecked(false); + + m_proxyServerAddLabel->setEnabled(false); + m_proxyPortLabel->setEnabled(false); + m_proxyUsernameLabel->setEnabled(false); + m_proxyPwdLabel->setEnabled(false); + m_infiniteRetryCheckbox->setEnabled(false); + m_proxyServerAddEdit->setEnabled(false); + m_proxyPortEdit->setEnabled(false); + m_proxyUsernameEdit->setEnabled(false); + m_proxyPwdEdit->setEnabled(false); + break; + case HTTP: + m_proxyServerAddLabel->setEnabled(true); + m_proxyPortLabel->setEnabled(true); + m_proxyUsernameLabel->setEnabled(true); + m_proxyPwdLabel->setEnabled(true); + m_infiniteRetryCheckbox->setEnabled(true); + m_proxyServerAddEdit->setEnabled(true); + m_proxyPortEdit->setEnabled(true); + m_proxyUsernameEdit->setEnabled(true); + m_proxyPwdEdit->setEnabled(true); + break; + case SOCKS: + m_proxyServerAddLabel->setEnabled(true); + m_proxyPortLabel->setEnabled(true); + m_infiniteRetryCheckbox->setEnabled(true); + m_proxyServerAddEdit->setEnabled(true); + m_proxyPortEdit->setEnabled(true); + m_proxyUsernameLabel->setEnabled(false); + m_proxyPwdLabel->setEnabled(false); + m_proxyUsernameEdit->setEnabled(false); + m_proxyPwdEdit->setEnabled(false); + break; + default: + break; + } +} + +void VpnAdvancedPage::onTlsModeComboxIndexChanged() +{ + switch (m_tlsModeCombox->currentData().toInt()) { + case NONE: + m_keyPathLabel->setEnabled(false); + m_keyPathEdit->setEnabled(false); + m_keyPathChooseBtn->setEnabled(false); + m_keyDirectionLabel->setEnabled(false); + m_keyDirectionCombox->setEnabled(false); + break; + case TLS_CERT: + m_keyPathLabel->setEnabled(true); + m_keyPathEdit->setEnabled(true); + m_keyPathChooseBtn->setEnabled(true); + m_keyDirectionLabel->setEnabled(true); + m_keyDirectionCombox->setEnabled(true); + break; + case TLS_ENCRYPTION: + m_keyPathLabel->setEnabled(true); + m_keyPathEdit->setEnabled(true); + m_keyPathChooseBtn->setEnabled(true); + m_keyDirectionLabel->setEnabled(false); + m_keyDirectionCombox->setEnabled(false); + break; + default: + break; + } +} + +void VpnAdvancedPage::setEnableOfConfirmBtn() +{ + Q_EMIT setAdvancedPageState(checkConfirmBtnIsEnabled()); +} + +void VpnAdvancedPage::onKeyPathButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a private key"), + "recent:///", + tr("Key Files (*.key *.pem *.der *.p12 *.pfx)")); + if (!fileName.isNull()) { + m_keyPathEdit->blockSignals(true); + m_keyPathEdit->setText(fileName); + m_keyPathEdit->blockSignals(false); + } +} + +void VpnAdvancedPage::showL2tpAdiaPage() +{ + m_defaultAdiaFrame->setHidden(false); + m_mruFrame->setHidden(false); + m_compModeListWidget->item(COMP_MODE_PROTOCOL)->setHidden(false); + m_compModeListWidget->item(COMP_MODE_ADDRESS)->setHidden(false); + m_compModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT); + + m_openVpnAdiaFrame->setHidden(true); + m_sSwanAdiaFrame->setHidden(true); +} + +void VpnAdvancedPage::showPptpAdiaPage() +{ + m_defaultAdiaFrame->setHidden(false); + m_compModeListWidget->item(COMP_MODE_PROTOCOL)->setHidden(true); + m_compModeListWidget->item(COMP_MODE_ADDRESS)->setHidden(true); + m_compModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT_SMALL); + + m_mruFrame->setHidden(true); + m_openVpnAdiaFrame->setHidden(true); + m_sSwanAdiaFrame->setHidden(true); +} + +void VpnAdvancedPage::showOpenVpnAdiaPage() +{ + m_openVpnAdiaFrame->setHidden(false); + + m_defaultAdiaFrame->setHidden(true); + m_mruFrame->setHidden(true); + m_sSwanAdiaFrame->setHidden(true); +} + +void VpnAdvancedPage::showSSwanAdiaPage() +{ + m_sSwanAdiaFrame->setHidden(false); + + m_defaultAdiaFrame->setHidden(true); + m_mruFrame->setHidden(true); + m_openVpnAdiaFrame->setHidden(true); +} + +bool VpnAdvancedPage::checkConfirmBtnIsEnabled() +{ + //L2TP + if (!m_mruFrame->isHidden()) { + if (m_mruEdit->text().isEmpty() || m_mtuEdit->text().isEmpty()) { + qDebug() << LOG_FLAG << "MRU or MTU is empty"; + return false; + } + } + + //PPTP 无必填项 + + //OPEN VPN + if (!m_openVpnAdiaFrame->isHidden()) { + if (m_customGatewayPortCheckbox->isChecked() && m_gatewayPortEdit->text().isEmpty()) { + return false; + } + + if (m_customRenegotiaInrCheckbox->isChecked() && m_renogotiaInrEdit->text().isEmpty()) { + return false; + } + + if (m_setVDevNameCheckbox->isChecked() && m_setVDevNameEdit->text().isEmpty()) { + return false; + } + + if (m_customMtuCheckbox->isChecked() && m_customMtuEdit->text().isEmpty()) { + return false; + } + + if (m_customUdpFragSizeCheckbox->isChecked() && m_customUdpFragSizeEdit->text().isEmpty()) { + return false; + } + + if (m_specPingInrCheckbox->isChecked() && m_specPingInrEdit->text().isEmpty()) { + return false; + } + + if (m_specExitPingCheckbox->isChecked() && m_specExRePingEdit->text().isEmpty()) { + return false; + } + + if (m_specMaxRouteCheckbox->isChecked() && m_specMaxRouteEdit->text().isEmpty()) { + return false; + } + + if (m_serverCertCheckCombox->currentData().toInt() != (int)KYCHECKSERVER_NONE + && m_subjectMatchEdit->text().isEmpty()) { + return false; + } + + if (m_tlsModeCombox->currentData().toInt() == TLS_CERT || m_tlsModeCombox->currentData().toInt() == TLS_ENCRYPTION) { + if (m_keyPathEdit->text().isEmpty()) { + return false; + } + } + + if (m_proxyTypeCombox->currentData().toInt() == HTTP || m_proxyTypeCombox->currentData().toInt() == SOCKS) { + if (m_proxyServerAddEdit->text().isEmpty() || !getTextEditState(m_proxyServerAddEdit->text())) { + return false; + } + if (m_proxyPortEdit->text().isEmpty()) { + return false; + } + } + + if(m_customKeySizeCheckbox->isChecked() && m_customKeySizeEdit->text().isEmpty()) { + return false; + } + } + + //strong-swan + if (!m_sSwanAdiaFrame->isHidden()) { + if (m_enablCustomCheckbox->isChecked()) { + if (m_ikeEdit->text().isEmpty() || m_espEdit->text().isEmpty()) { + return false; + } + } + } + return true; +} + +bool VpnAdvancedPage::getTextEditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} diff --git a/src-vpn/frontend/vpndetails/vpnadvancedpage.h b/src-vpn/frontend/vpndetails/vpnadvancedpage.h new file mode 100644 index 00000000..4c6be900 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnadvancedpage.h @@ -0,0 +1,197 @@ +#ifndef VPNADVANCEDPAGE_H +#define VPNADVANCEDPAGE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kylable.h" +#include "kwidget.h" +#include "kpasswordedit.h" +#include "vpnconfigpage.h" +#include "kyvpnconnectoperation.h" + +using namespace kdk; + +enum TlsMode { + NONE = 0, + TLS_CERT, + TLS_ENCRYPTION +}; + +enum ProxyType { + NO = 0, + HTTP, + SOCKS +}; + +class VpnAdvancedPage : public QFrame +{ + Q_OBJECT +public: + VpnAdvancedPage(QWidget *parent = nullptr); + ~VpnAdvancedPage() = default; + + //Adia: Advanced + void setL2tpOrPptpAdiaInfo(const KyVpnConfig &vpnInfo); + void setOpenVpnAdiaInfo(const KyVpnConfig &vpnInfo); + void setStrongSwanAdiaInfo(const KyVpnConfig &vpnInfo); + + bool checkIsChanged(const KyVpnConfig &vpnInfo, VpnType &vpnType); + bool checkL2tpIsChanged(const KyVpnConfig &vpnInfo); + bool checkPptpIsChanged(const KyVpnConfig &vpnInfo); + bool checkOpenVpnIsChanged(const KyVpnConfig &vpnInfo); + bool checkStrongSwanIsChanged(const KyVpnConfig &vpnInfo); + + void updateL2tpOrPptpAdiaInfo(KyVpnConfig &vpnInfo); + void updateOpenVpnAdiaInfo(KyVpnConfig &vpnInfo); + void updateStrongSwanAdiaInfo(KyVpnConfig &vpnInfo); + +protected: + void paintEvent(QPaintEvent *event); + +private: + bool m_isOpenVpn; + + QFrame *m_defaultAdiaFrame; + QFrame *m_mruFrame; + QFrame *m_openVpnAdiaFrame; + QFrame *m_sSwanAdiaFrame; + + //L2TP PPTP Encryption(E) + QCheckBox *m_mppeECheckbox = nullptr; + QCheckBox *m_useStatefulECheckbox = nullptr; + QCheckBox *m_sendPppEchoPkgCheckbox = nullptr; + + QLabel *m_authModeLabel; + QLabel *m_compModeLabel; + QLabel *m_mruLabel; + QLabel *m_mtuLabel; + QLineEdit *m_mruEdit; + QLineEdit *m_mtuEdit; + QComboBox *m_mppeECombox = nullptr; + //认证方式 + QListWidget *m_authModeListWidget = nullptr; + QCheckBox *m_papAuthCheckbox = nullptr; + QCheckBox *m_chapAuthCheckbox = nullptr; + QCheckBox *m_mschapAuthCheckbox = nullptr; + QCheckBox *m_mschap2AuthCheckbox = nullptr; + QCheckBox *m_eapAuthCheckbox = nullptr; + //压缩方式 + QListWidget *m_compModeListWidget = nullptr; + QCheckBox *m_bsdCompModeCheckbox = nullptr; + QCheckBox *m_defaultCompModeCheckbox = nullptr; + QCheckBox *m_tcpCompModeCheckbox = nullptr; + QCheckBox *m_protocolCompModeCheckbox = nullptr; + QCheckBox *m_addressCompModeCheckbox = nullptr; + + //Open VPN + //general + QCheckBox *m_customGatewayPortCheckbox = nullptr; + QCheckBox *m_customRenegotiaInrCheckbox = nullptr; + QCheckBox *m_compressionCheckbox = nullptr; + QCheckBox *m_tcpConnCheckbox = nullptr; + QCheckBox *m_setVDevTypeCheckbox = nullptr; + QCheckBox *m_setVDevNameCheckbox = nullptr; + QCheckBox *m_customMtuCheckbox = nullptr; + QCheckBox *m_customUdpFragSizeCheckbox = nullptr; + QCheckBox *m_tcpMssCheckbox = nullptr; + QCheckBox *m_randomRemoteHostCheckbox = nullptr; + QCheckBox *m_ipv6TunLinkCheckbox = nullptr; + QCheckBox *m_specPingInrCheckbox = nullptr; + QCheckBox *m_specExitPingCheckbox = nullptr; + QCheckBox *m_acceptAuthedPaksCheckbox = nullptr; + QCheckBox *m_specMaxRouteCheckbox = nullptr; + + QLineEdit *m_gatewayPortEdit; + QLineEdit *m_renogotiaInrEdit; + QLineEdit *m_setVDevNameEdit; + QLineEdit *m_customMtuEdit; + QLineEdit *m_customUdpFragSizeEdit; + QLineEdit *m_specPingInrEdit; + QLineEdit *m_specExRePingEdit; + QLineEdit *m_specMaxRouteEdit; + QComboBox *m_compressionCombox = nullptr; + QComboBox *m_setVDevTypeCombox = nullptr; + QComboBox *m_specExitRestarCombox = nullptr; + FixLabel *m_customRenoInrLabel; + FixLabel *m_customMtuLabel; + FixLabel *m_customUdpLabel; + FixLabel *m_acceptAuthedPaksLabel; + //TLS settings + QLabel *m_subjectMatchLabel; + QLabel *m_keyPathLabel; + QLabel *m_keyDirectionLabel; + QLineEdit *m_subjectMatchEdit; + QLineEdit *m_keyPathEdit; + QPushButton *m_keyPathChooseBtn; + QCheckBox *m_usePreviousCertCheckbox = nullptr; + QCheckBox *m_verifyPeerCertCheckbox = nullptr; + QComboBox *m_serverCertCheckCombox = nullptr; + QComboBox *m_usePreviousCertCombox = nullptr; + QComboBox *m_verifyPeerCertCombox = nullptr; + QComboBox *m_tlsModeCombox = nullptr; + QComboBox *m_keyDirectionCombox = nullptr; + //proxies + QLabel *m_proxyServerAddLabel; + QLabel *m_proxyPortLabel; + QLabel *m_proxyUsernameLabel; + QLabel *m_proxyPwdLabel; + QComboBox *m_proxyTypeCombox = nullptr; + QCheckBox *m_infiniteRetryCheckbox = nullptr; + QLineEdit *m_proxyServerAddEdit; + QLineEdit *m_proxyPortEdit; + QLineEdit *m_proxyUsernameEdit; + KPasswordEdit *m_proxyPwdEdit; + //security + QCheckBox *m_customKeySizeCheckbox = nullptr; + QLineEdit *m_customKeySizeEdit; + QComboBox *m_hmacAuthCombox = nullptr; + + //strongswan + QListWidget *m_optionsListWidget = nullptr; + QCheckBox *m_requestInIPCheckbox = nullptr; + QCheckBox *m_udpEncapCheckbox = nullptr; + QCheckBox *m_ipCompCheckbox = nullptr; + QCheckBox *m_enablCustomCheckbox = nullptr; + QFrame *m_ikeEspFrame; + QLineEdit *m_ikeEdit; + QLineEdit *m_espEdit; + + void initUi(); + void initConnect(); + void initDefaultAdiaFrame(); //L2TP PPTP + void initOpenVpnAdiaFrame(); //Open VPN + void initSSwanAdiaFrame(); //strong-swan + void initDefalutCheckState(); + void addListItem(QListWidget *listWidget, QWidget *widget); + void initCheckWidget(QCheckBox *checkBox, FixLabel *label, QWidget *widget); + + void showL2tpAdiaPage(); + void showPptpAdiaPage(); + void showOpenVpnAdiaPage(); + void showSSwanAdiaPage(); + bool checkConfirmBtnIsEnabled(); + bool getTextEditState(QString text); + +private Q_SLOTS: + void onProxyTypeComboxIndexChanged(); + void onTlsModeComboxIndexChanged(); + void setEnableOfConfirmBtn(); + void onKeyPathButtonClicked(); + +public Q_SLOTS: + void setVpnAdvancedPage(const VpnType &type); + +Q_SIGNALS: + void setAdvancedPageState(bool); +}; + +#endif // VPNADVANCEDPAGE_H diff --git a/src-vpn/frontend/vpndetails/vpnconfigpage.cpp b/src-vpn/frontend/vpndetails/vpnconfigpage.cpp new file mode 100644 index 00000000..eeb4e4da --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnconfigpage.cpp @@ -0,0 +1,1055 @@ +#include "vpnconfigpage.h" +#include +#include + +#define NO_LAYOUT_MARGINS 0, 0, 0, 0 +#define NO_SPACE 0 +#define HLAYOUT_SPACING 16 +#define VLAYOUT_SPACING 24 +#define LEFT_LABEL_WIDTH 100 +#define PIN_MAX_LENGTH 10 +#define PWD_OPTION_THISUSER_INDEX 0 +#define PWD_OPTION_ALLUSERS_INDEX 1 +#define PWD_OPTION_ASKEVERYTIME_INDEX 2 +#define PWD_OPTION_NOTREQUIRED_INDEX 3 +#define LOG_FLAG "[VPN ConfigPage]" + +VpnConfigPage::VpnConfigPage(QWidget *parent) : QFrame(parent) +{ + initUI(); + initConnect(); + onVpnTypeComboxIndexChanged(); +} + +VpnType VpnConfigPage::getVpnType() +{ + return VpnType(m_vpnTypeComboBox->currentData().toInt()); +} + +void VpnConfigPage::setVpnConfigInfo(const KyVpnConfig &vpnInfo) +{ + m_vpnNameEdit->setText(vpnInfo.m_vpnName); + m_serverAddressEdit->setText(vpnInfo.m_gateway); + m_vpnTypeComboBox->setCurrentIndex(vpnInfo.m_vpnType); + onVpnTypeComboxIndexChanged(); + + switch (vpnInfo.m_vpnType) { + case KYVPNTYPE_L2TP: + setL2tpConfigInfo(vpnInfo); + break; + case KYVPNTYPE_PPTP: + setPptpConfigInfo(vpnInfo); + break; + case KYVPNTYPE_OPENVPN: + setOpenVpnConfigInfo(vpnInfo); + break; + case KYVPNTYPE_STRONGSWAN: + setSSwanVpnConfigInfo(vpnInfo); + break; + default: + qDebug() << LOG_FLAG << "Unknow VPN Type" << vpnInfo.m_vpnType; + break; + } +} + +bool VpnConfigPage::checkIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + int currentVpnType = m_vpnTypeComboBox->currentData().toInt(); + + if (vpnInfo.m_vpnType != currentVpnType + || vpnInfo.m_vpnName != m_vpnNameEdit->text() + || vpnInfo.m_gateway != m_serverAddressEdit->text()) { + + isChanged = true; + } + + switch (currentVpnType) { + case L2TP: + if (checkL2tpIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case PPTP: + if (checkPptpIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case OPEN_VPN: + if (checkOpenVpnIsChanged(vpnInfo)) { + isChanged = true; + } + break; + case STRONG_SWAN: + if (checkStrongSwanIsChanged(vpnInfo)) { + isChanged = true; + } + default: + break; + } + + return isChanged; +} + +void VpnConfigPage::updateVpnConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_vpnType = (KyVpnType)m_vpnTypeComboBox->currentData().toInt(); + vpnInfo.m_vpnName = m_vpnNameEdit->text(); + vpnInfo.m_gateway = m_serverAddressEdit->text(); + switch (m_vpnTypeComboBox->currentData().toInt()) { + case L2TP: + updateL2tpConfigInfo(vpnInfo); + break; + case OPEN_VPN: + updateOpenVpnConfigInfo(vpnInfo); + break; + case PPTP: + updatePptpConfigInfo(vpnInfo); + break; + case STRONG_SWAN: + updateSSwanVpnConfigInfo(vpnInfo); + break; + default: + break; + } +} + +void VpnConfigPage::initUI() +{ + /**********控件**********/ + //公有 + m_vpnTypeLabel = new QLabel(this); + m_vpnNameLabel = new QLabel(this); + m_serverAddressLabel = new FixLabel(this); + m_vpnTypeComboBox = new QComboBox(this); + m_vpnNameEdit = new QLineEdit(this); + m_serverAddressEdit = new QLineEdit(this); + + //认证方式 Authentication Mode + m_authModeLabel = new FixLabel(this); + m_authModeComboBox = new QComboBox(this); + + //证书 私钥 + m_caCertLabel = new FixLabel(this); + m_userCertLabel = new FixLabel(this); + m_privateKeyLabel = new FixLabel(this); + m_privateKeyPwdLabel = new FixLabel(this); + m_pwdOptionLabel = new FixLabel(this); + + m_caCertPathEdit = new QLineEdit(this); + m_userCertPathEdit = new QLineEdit(this); + m_privateKeyEdit = new QLineEdit(this); + m_privateKeyPwdEdit = new KPasswordEdit(this); + m_pwdOptionCombox = new QComboBox(this); + + m_caCertButton = new QPushButton(this); + m_userCertButton = new QPushButton(this); + m_privateKeyButton = new QPushButton(this); + + //静态密钥 + m_staticKeyLabel = new QLabel(this); + m_keyDirectionLabel = new FixLabel(this); + m_noticesLabel = new QLabel(this); + m_localIpLabel = new QLabel(this); + m_remoteIpLabel = new QLabel(this); + + m_staticKeyPathEdit = new QLineEdit(this); + m_staticKeyButton = new QPushButton(this); + m_keyDirectionCombox = new QComboBox(this); + m_localIpEdit = new QLineEdit(this); + m_remoteIpEdit = new QLineEdit(this); + + //智能卡 PIN码 + m_pinLabel = new QLabel(this); + m_pinEdit = new QLineEdit(this); + + //密码 + m_usernameLabel = new FixLabel(this); + m_userPwdLabel = new QLabel(this); + m_userPwdOptionLabel = new FixLabel(this); + m_usernameEdit = new QLineEdit(this); + m_userPwdEdit = new KPasswordEdit(this); + m_userPwdOptionCombox = new QComboBox(this); + + //L2TP PPTP公有 + m_ntDomainLabel = new QLabel(this); + m_ntDomainEdit = new QLineEdit(this); + + + /**********布局**********/ + m_vpnCommunalFrame = new QFrame(this); + m_authModeFrame = new QFrame(this); + m_caCertFrame = new QFrame(this); + m_userCertFrame = new QFrame(this); + m_staticKeysFrame = new QFrame(this); + m_pinFrame = new QFrame(this); + m_PrivateKeysFrame = new QFrame(this); + m_usersFrame = new QFrame(this); + m_userPwdOpFrame = new QFrame(this); + m_ntFrame = new QFrame(this); + + //布局 + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setSpacing(VLAYOUT_SPACING); + mainLayout->addWidget(m_vpnCommunalFrame); + mainLayout->addWidget(m_authModeFrame); + mainLayout->addWidget(m_caCertFrame); + mainLayout->addWidget(m_userCertFrame); + mainLayout->addWidget(m_staticKeysFrame); + mainLayout->addWidget(m_pinFrame); + mainLayout->addWidget(m_PrivateKeysFrame); + mainLayout->addWidget(m_usersFrame); + mainLayout->addWidget(m_userPwdOpFrame); + mainLayout->addWidget(m_ntFrame); + mainLayout->addSpacing(3); + mainLayout->addStretch(); + + QGridLayout *vpnCommLayout = new QGridLayout(m_vpnCommunalFrame); + vpnCommLayout->setContentsMargins(NO_LAYOUT_MARGINS); + vpnCommLayout->setHorizontalSpacing(HLAYOUT_SPACING); + vpnCommLayout->setVerticalSpacing(VLAYOUT_SPACING); + vpnCommLayout->addWidget(m_vpnTypeLabel, 0, 0); + vpnCommLayout->addWidget(m_vpnNameLabel, 1, 0); + vpnCommLayout->addWidget(m_serverAddressLabel, 2, 0); + vpnCommLayout->addWidget(m_vpnTypeComboBox, 0, 1); + vpnCommLayout->addWidget(m_vpnNameEdit, 1, 1); + vpnCommLayout->addWidget(m_serverAddressEdit, 2, 1); + m_vpnTypeLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_vpnNameLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_serverAddressLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *authMdLayout = new QHBoxLayout(m_authModeFrame); + authMdLayout->setContentsMargins(NO_LAYOUT_MARGINS); + authMdLayout->setSpacing(HLAYOUT_SPACING); + authMdLayout->addWidget(m_authModeLabel); + authMdLayout->addWidget(m_authModeComboBox); + m_authModeLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *caCertLayout = new QHBoxLayout(m_caCertFrame); + caCertLayout->setContentsMargins(NO_LAYOUT_MARGINS); + caCertLayout->setSpacing(HLAYOUT_SPACING); + caCertLayout->addWidget(m_caCertLabel); + caCertLayout->addWidget(m_caCertPathEdit); + caCertLayout->addWidget(m_caCertButton); + m_caCertLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *userLayout = new QHBoxLayout(m_userCertFrame); + userLayout->setContentsMargins(NO_LAYOUT_MARGINS); + userLayout->setSpacing(HLAYOUT_SPACING); + userLayout->addWidget(m_userCertLabel); + userLayout->addWidget(m_userCertPathEdit); + userLayout->addWidget(m_userCertButton); + m_userCertLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QGridLayout *staticKeyLayout = new QGridLayout(m_staticKeysFrame); + staticKeyLayout->setContentsMargins(NO_LAYOUT_MARGINS); + staticKeyLayout->setHorizontalSpacing(HLAYOUT_SPACING); + staticKeyLayout->setVerticalSpacing(VLAYOUT_SPACING); + staticKeyLayout->addWidget(m_staticKeyLabel, 0, 0); + staticKeyLayout->addWidget(m_staticKeyPathEdit, 0, 1); + staticKeyLayout->addWidget(m_staticKeyButton, 0, 2); + staticKeyLayout->addWidget(m_keyDirectionLabel, 1, 0); + staticKeyLayout->addWidget(m_keyDirectionCombox, 1, 1, 1, 2); + staticKeyLayout->addWidget(m_noticesLabel, 2, 0, 2, 3); + staticKeyLayout->addWidget(m_localIpLabel, 4, 0); + staticKeyLayout->addWidget(m_localIpEdit, 4, 1, 1, 2); + staticKeyLayout->addWidget(m_remoteIpLabel, 5, 0); + staticKeyLayout->addWidget(m_remoteIpEdit, 5, 1, 1, 2); + m_staticKeyLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_keyDirectionLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_localIpLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_remoteIpLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *pinLayout = new QHBoxLayout(m_pinFrame); + pinLayout->setContentsMargins(NO_LAYOUT_MARGINS); + pinLayout->setSpacing(HLAYOUT_SPACING); + pinLayout->addWidget(m_pinLabel); + pinLayout->addWidget(m_pinEdit); + m_pinLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QGridLayout *privateKeysLayout = new QGridLayout(m_PrivateKeysFrame); + privateKeysLayout->setContentsMargins(NO_LAYOUT_MARGINS); + privateKeysLayout->setHorizontalSpacing(HLAYOUT_SPACING); + privateKeysLayout->setVerticalSpacing(VLAYOUT_SPACING); + privateKeysLayout->addWidget(m_privateKeyLabel, 0, 0); + privateKeysLayout->addWidget(m_privateKeyPwdLabel, 1, 0); + privateKeysLayout->addWidget(m_pwdOptionLabel, 2, 0); + privateKeysLayout->addWidget(m_privateKeyEdit, 0, 1); + privateKeysLayout->addWidget(m_privateKeyButton, 0, 2); + privateKeysLayout->addWidget(m_privateKeyPwdEdit, 1, 1, 1, 2); + privateKeysLayout->addWidget(m_pwdOptionCombox, 2, 1, 1, 2); + m_privateKeyLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_privateKeyPwdLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_pwdOptionLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QGridLayout *usersLayout = new QGridLayout(m_usersFrame); + usersLayout->setContentsMargins(NO_LAYOUT_MARGINS); + usersLayout->setHorizontalSpacing(HLAYOUT_SPACING); + usersLayout->setVerticalSpacing(VLAYOUT_SPACING); + usersLayout->addWidget(m_usernameLabel, 0, 0); + usersLayout->addWidget(m_usernameEdit, 0, 1); + usersLayout->addWidget(m_userPwdLabel, 1, 0); + usersLayout->addWidget(m_userPwdEdit, 1, 1); + m_usernameLabel->setFixedWidth(LEFT_LABEL_WIDTH); + m_userPwdLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *userPwdOLayout = new QHBoxLayout(m_userPwdOpFrame); + userPwdOLayout->setContentsMargins(NO_LAYOUT_MARGINS); + userPwdOLayout->setSpacing(HLAYOUT_SPACING); + userPwdOLayout->addWidget(m_userPwdOptionLabel); + userPwdOLayout->addWidget(m_userPwdOptionCombox); + m_userPwdOptionLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + QHBoxLayout *ntLayout = new QHBoxLayout(m_ntFrame); + ntLayout->setContentsMargins(NO_LAYOUT_MARGINS); + ntLayout->setSpacing(HLAYOUT_SPACING); + ntLayout->addWidget(m_ntDomainLabel); + ntLayout->addWidget(m_ntDomainEdit); + m_ntDomainLabel->setFixedWidth(LEFT_LABEL_WIDTH); + + /**********控件显示**********/ + m_vpnTypeLabel->setText(tr("Type")); //类型 + m_vpnNameLabel->setText(tr("Name")); //名称 + m_staticKeyLabel->setText(tr("Static Key")); //静态密钥 + m_localIpLabel->setText(tr("Local IP")); //本地IP地址 + m_remoteIpLabel->setText(tr("Remote IP")); //远程IP地址 + m_pinLabel->setText(tr("PIN Code")); //PIN码 + m_userPwdLabel->setText(tr("Password")); //密码 + m_ntDomainLabel->setText(tr("NT Domain")); //NT域 + + m_serverAddressLabel->setLabelText(tr("Server Address")); //服务器地址 + m_authModeLabel->setLabelText(tr("Authentication Mode")); //认证方式 + m_caCertLabel->setLabelText(tr("CA Certificate")); //CA证书 + m_userCertLabel->setLabelText(tr("User Certificate")); //用户证书 + m_keyDirectionLabel->setLabelText(tr("Key Direction")); //密钥方向 + m_privateKeyLabel->setLabelText(tr("Private Key")); //私钥 + m_privateKeyPwdLabel->setLabelText(tr("Private Key Password")); //私有密钥密码 + m_pwdOptionLabel->setLabelText(tr("Password Options")); //密码选项 + m_usernameLabel->setLabelText(tr("Username")); //用户名 + m_userPwdOptionLabel->setLabelText(tr("Password Options")); //密码选项 + + m_noticesLabel->setWordWrap(true); + m_noticesLabel->setText(tr("Notice:\nIf key direction is used, it must be opposite to the VPN side used. " + "If '1' is used, the connection must use '0'. " + "If you are not sure which value to use, please contact your system administrator.")); + QPalette pal; + pal.setColor(QPalette::WindowText, qApp->palette().color(QPalette::Mid)); + m_noticesLabel->setPalette(pal); + + m_caCertButton->setText(tr("Choose")); //选择 + m_userCertButton->setText(tr("Choose")); + m_staticKeyButton->setText(tr("Choose")); + m_privateKeyButton->setText(tr("Choose")); + + m_vpnTypeComboBox->addItem("L2TP", L2TP); + m_vpnTypeComboBox->addItem("open VPN", OPEN_VPN); + m_vpnTypeComboBox->addItem("PPTP", PPTP); + m_vpnTypeComboBox->addItem("strong-swan", STRONG_SWAN); + + m_keyDirectionCombox->addItem(tr("None"), KEY_DIRECTION_NONE); + m_keyDirectionCombox->addItem("0", KEY_DIRECTION_ZERO); + m_keyDirectionCombox->addItem("1", KEY_DIRECTION_ONE); + + m_pwdOptionCombox->addItem(tr("Save password only for this user"), KYPASSWD_FORTHISUSER); //仅对当前用户保存密码 + m_pwdOptionCombox->addItem(tr("Save password for all users"), KYPASSWD_FORALLUSER); //为所有用户保存密码 + m_pwdOptionCombox->addItem(tr("Ask password every time"), KYPASSWD_ASKEVERYTIME); //每次都询问 + m_pwdOptionCombox->addItem(tr("Don't require a password"), KYPASSWD_ISNOTREQUIRED);//不需要密码 + m_pwdOptionCombox->setCurrentIndex(PWD_OPTION_ASKEVERYTIME_INDEX); + + m_userPwdOptionCombox->addItem(tr("Save password only for this user"), KYPASSWD_FORTHISUSER); + m_userPwdOptionCombox->addItem(tr("Save password for all users"), KYPASSWD_FORALLUSER); + m_userPwdOptionCombox->addItem(tr("Ask password every time"), KYPASSWD_ASKEVERYTIME); + m_userPwdOptionCombox->addItem(tr("Don't require a password"), KYPASSWD_ISNOTREQUIRED); + m_userPwdOptionCombox->setCurrentIndex(PWD_OPTION_ASKEVERYTIME_INDEX); + + m_vpnNameEdit->setPlaceholderText(tr("Required")); //必填 + m_serverAddressEdit->setPlaceholderText(tr("Required")); + m_privateKeyPwdEdit->setClearButtonEnabled(false); + m_userPwdEdit->setClearButtonEnabled(false); + + //控件输入格式限制 + QRegExp rxNumber("^[0-9]+$"); + m_pinEdit->setValidator(new QRegExpValidator(rxNumber, this)); + m_pinEdit->setMaxLength(PIN_MAX_LENGTH); + // IP的正则格式限制 + QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + QRegExpValidator *ipExpVal = new QRegExpValidator(rxIp, this); + m_serverAddressEdit->setValidator(ipExpVal); + m_localIpEdit->setValidator(ipExpVal); + m_remoteIpEdit->setValidator(ipExpVal); +} + +void VpnConfigPage::initConnect() +{ + connect(m_vpnTypeComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &VpnConfigPage::onVpnTypeComboxIndexChanged); + connect(m_authModeComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &VpnConfigPage::onAuthModeComboxIndexChanged); + + connect(m_vpnNameEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_serverAddressEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_caCertPathEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_userCertPathEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_privateKeyEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_staticKeyPathEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_localIpEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_remoteIpEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_pinEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_usernameEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_ntDomainEdit, &QLineEdit::textChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + + connect(m_vpnTypeComboBox, &QComboBox::currentTextChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_authModeComboBox, &QComboBox::currentTextChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_pwdOptionCombox, &QComboBox::currentTextChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + connect(m_userPwdOptionCombox, &QComboBox::currentTextChanged, this, &VpnConfigPage::setEnableOfConfirmBtn); + + connect(m_caCertButton, &QPushButton::clicked, this, &VpnConfigPage::onCaCertButtonClicked); + connect(m_userCertButton, &QPushButton::clicked, this, &VpnConfigPage::onUserCertButtonClicked); + connect(m_staticKeyButton, &QPushButton::clicked, this, &VpnConfigPage::onStaticKeyButtonClicked); + connect(m_privateKeyButton, &QPushButton::clicked, this, &VpnConfigPage::onPrivateKeyButtonClicked); +} + +void VpnConfigPage::showL2tpPwd() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_usersFrame->setHidden(false); + m_userPwdOpFrame->setHidden(false); + m_ntFrame->setHidden(false); + + m_PrivateKeysFrame->setHidden(true); + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); +} + +void VpnConfigPage::showPptpPwd() +{ + m_vpnCommunalFrame->setHidden(false); + m_usersFrame->setHidden(false); + m_userPwdOpFrame->setHidden(false); + m_ntFrame->setHidden(false); + + m_authModeFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); +} + +void VpnConfigPage::showOpenVpnTls() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_PrivateKeysFrame->setHidden(false); + m_caCertFrame->setHidden(false); + m_userCertFrame->setHidden(false); + + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showOpenVpnPwd() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_caCertFrame->setHidden(false); + m_usersFrame->setHidden(false); + m_userPwdOpFrame->setHidden(false); + + m_userCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showOpenVpnPwdTls() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_caCertFrame->setHidden(false); + m_userCertFrame->setHidden(false); + m_PrivateKeysFrame->setHidden(false); + m_usersFrame->setHidden(false); + m_userPwdOpFrame->setHidden(false); + + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showOpenVpnStaticKey() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_staticKeysFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showSswanCertPrivteKey() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_userCertFrame->setHidden(false); + m_PrivateKeysFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showSswanCertSsh() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_userCertFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showSswanSmartCard() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_pinFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_usersFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +void VpnConfigPage::showSswanEap() +{ + m_vpnCommunalFrame->setHidden(false); + m_authModeFrame->setHidden(false); + m_usersFrame->setHidden(false); + + m_caCertFrame->setHidden(true); + m_userCertFrame->setHidden(true); + m_PrivateKeysFrame->setHidden(true); + m_userPwdOpFrame->setHidden(true); + m_staticKeysFrame->setHidden(true); + m_pinFrame->setHidden(true); + m_ntFrame->setHidden(true); +} + +bool VpnConfigPage::getTextEditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} + +bool VpnConfigPage::checkConfirmBtnIsEnabled() +{ + if (m_vpnNameEdit->text().isEmpty()) { + qDebug() << LOG_FLAG << "VPN name empty or invalid"; + return false; + } + + if (m_serverAddressEdit->text().isEmpty() || !getTextEditState(m_serverAddressEdit->text())) { + qDebug() << LOG_FLAG << "VPN server address empty or invalid"; + return false; + } + + int currentAuthMethod = m_authModeComboBox->currentData().toInt(); + switch (currentAuthMethod) { + case KYAUTH_PASSWD: + case KYAUTH_EAP: + if (m_usernameEdit->text().isEmpty() && !m_userPwdEdit->text().isEmpty()) { + return false; + } + if (m_vpnTypeComboBox->currentData().toInt() == OPEN_VPN && m_caCertPathEdit->text().isEmpty()) { + return false; + } + break; + + case KYAUTH_CERTIFICATE: + if (m_caCertPathEdit->text().isEmpty() || m_userCertPathEdit->text().isEmpty() + || m_privateKeyEdit->text().isEmpty()) { + return false; + } + break; + + case KYAUTH_CERTIFICATEANDPASSWD: + if (m_caCertPathEdit->text().isEmpty() || m_userCertPathEdit->text().isEmpty() + || m_privateKeyEdit->text().isEmpty()) { + return false; + } + if (m_usernameEdit->text().isEmpty() && !m_userPwdEdit->text().isEmpty()) { + return false; + } + break; + + case KYAUTH_STATICPASSWD: + if (m_staticKeyPathEdit->text().isEmpty()) { + return false; + } + break; + + default: + break; + } + + return true; +} + +void VpnConfigPage::setPwdAuthInfo(const QString &username, const QString &userPwd, const KyPasswdPolicy &userPwdPolicy) +{ + m_usernameEdit->setText(username); + m_userPwdEdit->setText(userPwd); + if (userPwdPolicy == KYPASSWD_ISNOTREQUIRED) { + m_userPwdOptionCombox->setCurrentIndex(PWD_OPTION_NOTREQUIRED_INDEX); + } else { + m_userPwdOptionCombox->setCurrentIndex(userPwdPolicy); + } +} + +void VpnConfigPage::setCaCertAuthInfo(const QString &caCertificate) +{ + m_caCertPathEdit->setText(caCertificate); +} + +void VpnConfigPage::setKeyAuthInfo(const QString &userCert, const QString &privateKey, + const QString &privateKeyPwd, const KyPasswdPolicy &privatePwdPolicy) +{ + m_userCertPathEdit->setText(userCert); + m_privateKeyEdit->setText(privateKey); + m_privateKeyPwdEdit->setText(privateKeyPwd); + if (privatePwdPolicy == KYPASSWD_ISNOTREQUIRED) { + m_userPwdOptionCombox->setCurrentIndex(PWD_OPTION_NOTREQUIRED_INDEX); + } else { + m_userPwdOptionCombox->setCurrentIndex(privatePwdPolicy); + } +} + +void VpnConfigPage::setStaticKeyAuthInfo(const QString &staticKey, const QString &vpnKeyDirection, + const QString &localIp, const QString &remoteIp) +{ + m_staticKeyPathEdit->setText(staticKey); + m_localIpEdit->setText(localIp); + m_remoteIpEdit->setText(remoteIp); + if (vpnKeyDirection == KEY_DIRECTION_ZERO) { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ZERO_INDEX); + } else if (vpnKeyDirection == KEY_DIRECTION_ONE) { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ONE_INDEX); + } else { + m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_NONE_INDEX); + } +} + +void VpnConfigPage::setAgentAuthInfo(const QString &userCert) +{ + m_userCertPathEdit->setText(userCert); +} + +void VpnConfigPage::setSmartCardAuthInfo(const QString &pin) +{ + m_pinEdit->setText(pin); +} + +void VpnConfigPage::setEapAuthInfo(const QString &username, const QString &userPwd) +{ + m_usernameEdit->setText(username); + m_userPwdEdit->setText(userPwd); +} + +void VpnConfigPage::setNtDomain(const QString &ntDomain) +{ + m_ntDomainEdit->setText(ntDomain); +} + +void VpnConfigPage::setL2tpConfigInfo(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_PASSWD) { + m_authModeComboBox->setCurrentIndex(KYAUTH_PASSWD); + setPwdAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd, vpnInfo.m_passwdPolicy); + setNtDomain(vpnInfo.m_ntDomain); + } +} + +void VpnConfigPage::setPptpConfigInfo(const KyVpnConfig &vpnInfo) +{ + m_authModeComboBox->clear(); + setPwdAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd, vpnInfo.m_passwdPolicy); + setNtDomain(vpnInfo.m_ntDomain); +} + +void VpnConfigPage::setOpenVpnConfigInfo(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_PASSWD) { + m_authModeComboBox->setCurrentIndex(PASSWD_INDEX); + setCaCertAuthInfo(vpnInfo.m_caCertificate); + setPwdAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd, vpnInfo.m_passwdPolicy); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_CERTIFICATE) { + m_authModeComboBox->setCurrentIndex(CERTIFICATE_INDEX); + setCaCertAuthInfo(vpnInfo.m_caCertificate); + setKeyAuthInfo(vpnInfo.m_userCertificate, vpnInfo.m_userKey, + vpnInfo.m_privatePasswd, vpnInfo.m_privatePasswdPolicy); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_STATICPASSWD) { + m_authModeComboBox->setCurrentIndex(STATICPASSWD_INDEX); + setStaticKeyAuthInfo(vpnInfo.m_staticKey, vpnInfo.m_vpnKeyDir, + vpnInfo.m_localAddress, vpnInfo.m_remoteAddress); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_CERTIFICATEANDPASSWD) { + m_authModeComboBox->setCurrentIndex(CERTIFICATEANDPASSWD_INDEX); + setCaCertAuthInfo(vpnInfo.m_caCertificate); + setKeyAuthInfo(vpnInfo.m_userCertificate, vpnInfo.m_userKey, + vpnInfo.m_privatePasswd, vpnInfo.m_privatePasswdPolicy); + setPwdAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd, vpnInfo.m_passwdPolicy); + } +} + +void VpnConfigPage::setSSwanVpnConfigInfo(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_KEY) { + m_authModeComboBox->setCurrentIndex(KEY_INDEX); + setCaCertAuthInfo(vpnInfo.m_caCertificate); + setKeyAuthInfo(vpnInfo.m_userCertificate, vpnInfo.m_userKey, + vpnInfo.m_privatePasswd, vpnInfo.m_privatePasswdPolicy); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_AGENT) { + m_authModeComboBox->setCurrentIndex(AGENT_INDEX); + setAgentAuthInfo(vpnInfo.m_userCertificate); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_SMARTCARD) { + m_authModeComboBox->setCurrentIndex(SMARTCARD_INDEX); + setSmartCardAuthInfo(vpnInfo.m_pinId); + + } else if (vpnInfo.m_authMethod == KyAuthMethod::KYAUTH_EAP) { + m_authModeComboBox->setCurrentIndex(EAP_INDEX); + setEapAuthInfo(vpnInfo.m_userName, vpnInfo.m_userPasswd); + } +} + +void VpnConfigPage::updateL2tpConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_authMethod = (KyAuthMethod)m_authModeComboBox->currentData().toInt(); + vpnInfo.m_ntDomain = m_ntDomainEdit->text(); + vpnInfo.m_userName = m_usernameEdit->text(); + vpnInfo.m_userPasswd = m_userPwdEdit->text(); + vpnInfo.m_passwdPolicy = (KyPasswdPolicy)m_userPwdOptionCombox->currentData().toInt(); +} + +void VpnConfigPage::updatePptpConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_ntDomain = m_ntDomainEdit->text(); + vpnInfo.m_userName = m_usernameEdit->text(); + vpnInfo.m_userPasswd = m_userPwdEdit->text(); + vpnInfo.m_passwdPolicy = (KyPasswdPolicy)m_userPwdOptionCombox->currentData().toInt(); +} + +void VpnConfigPage::updateOpenVpnConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_authMethod = (KyAuthMethod)m_authModeComboBox->currentData().toInt(); + if (vpnInfo.m_authMethod == KYAUTH_CERTIFICATE || vpnInfo.m_authMethod == KYAUTH_CERTIFICATEANDPASSWD) { + vpnInfo.m_caCertificate = m_caCertPathEdit->text(); + vpnInfo.m_userCertificate = m_userCertPathEdit->text(); + vpnInfo.m_userKey = m_privateKeyEdit->text(); + vpnInfo.m_privatePasswd = m_privateKeyPwdEdit->text(); + vpnInfo.m_privatePasswdPolicy = (KyPasswdPolicy)m_pwdOptionCombox->currentData().toInt(); + } + + if (vpnInfo.m_authMethod == KYAUTH_CERTIFICATEANDPASSWD || vpnInfo.m_authMethod == KYAUTH_PASSWD) { + vpnInfo.m_userName = m_usernameEdit->text(); + vpnInfo.m_userPasswd = m_userPwdEdit->text(); + vpnInfo.m_passwdPolicy = (KyPasswdPolicy)m_userPwdOptionCombox->currentData().toInt(); + vpnInfo.m_caCertificate = m_caCertPathEdit->text(); + } + + if (vpnInfo.m_authMethod == KYAUTH_STATICPASSWD) { + vpnInfo.m_staticKey = m_staticKeyPathEdit->text(); + vpnInfo.m_vpnKeyDir = m_keyDirectionCombox->currentData().toString(); + vpnInfo.m_localAddress = m_localIpEdit->text(); + vpnInfo.m_remoteAddress = m_remoteIpEdit->text(); + } +} + +void VpnConfigPage::updateSSwanVpnConfigInfo(KyVpnConfig &vpnInfo) +{ + vpnInfo.m_authMethod = (KyAuthMethod)m_authModeComboBox->currentData().toInt(); + if (vpnInfo.m_authMethod == KYAUTH_KEY) { + vpnInfo.m_caCertificate = m_caCertPathEdit->text(); + vpnInfo.m_userCertificate = m_userCertPathEdit->text(); + vpnInfo.m_userKey = m_privateKeyEdit->text(); + vpnInfo.m_privatePasswd = m_privateKeyPwdEdit->text(); + vpnInfo.m_privatePasswdPolicy = (KyPasswdPolicy)m_pwdOptionCombox->currentData().toInt(); + + } else if (vpnInfo.m_authMethod == KYAUTH_AGENT) { + vpnInfo.m_userCertificate = m_userCertPathEdit->text(); + + } else if (vpnInfo.m_authMethod == KYAUTH_SMARTCARD) { + vpnInfo.m_pinId = m_pinEdit->text(); + + } else if (vpnInfo.m_authMethod == KYAUTH_EAP) { + vpnInfo.m_userName = m_usernameEdit->text(); + vpnInfo.m_userPasswd = m_userPwdEdit->text(); + } +} + +void VpnConfigPage::onVpnTypeComboxIndexChanged() +{ + switch (m_vpnTypeComboBox->currentData().toInt()) { + case L2TP: + m_authModeComboBox->clear(); + m_authModeComboBox->addItem(tr("Password"), KYAUTH_PASSWD); + onAuthModeComboxIndexChanged(); + break; + case OPEN_VPN: + m_authModeComboBox->clear(); + m_authModeComboBox->addItem(tr("Certificate(TLS)"), KYAUTH_CERTIFICATE); + m_authModeComboBox->addItem(tr("Static key"), KYAUTH_STATICPASSWD); + m_authModeComboBox->addItem(tr("Password"), KYAUTH_PASSWD); + m_authModeComboBox->addItem(tr("Password and certificate(TLS)"), KYAUTH_CERTIFICATEANDPASSWD); + onAuthModeComboxIndexChanged(); + break; + case PPTP: + m_authModeComboBox->clear(); + showPptpPwd(); + break; + case STRONG_SWAN: + m_authModeComboBox->clear(); + m_authModeComboBox->addItem(tr("Certificate/Private key"), KYAUTH_KEY); + m_authModeComboBox->addItem(tr("Certificate/ssh-agent"), KYAUTH_AGENT); + m_authModeComboBox->addItem(tr("Smart card"), KYAUTH_SMARTCARD); + m_authModeComboBox->addItem("EAP", KYAUTH_EAP); + onAuthModeComboxIndexChanged(); + break; + default: + break; + } + Q_EMIT vpnTypeChanged(VpnType(m_vpnTypeComboBox->currentData().toInt())); +} + +void VpnConfigPage::onAuthModeComboxIndexChanged() +{ + switch (m_authModeComboBox->currentData().toInt()) { + case KYAUTH_PASSWD: + if (m_vpnTypeComboBox->currentData().toInt() == L2TP) { + showL2tpPwd(); + } else if (m_vpnTypeComboBox->currentData().toInt() == OPEN_VPN) { + showOpenVpnPwd(); + } + break; + case KYAUTH_KEY: + showSswanCertPrivteKey(); + break; + case KYAUTH_AGENT: + showSswanCertSsh(); + break; + case KYAUTH_SMARTCARD: + showSswanSmartCard(); + break; + case KYAUTH_EAP: + showSswanEap(); + break; + case KYAUTH_CERTIFICATE: + showOpenVpnTls(); + break; + case KYAUTH_CERTIFICATEANDPASSWD: + showOpenVpnPwdTls(); + break; + case KYAUTH_STATICPASSWD: + showOpenVpnStaticKey(); + break; + default: + qDebug() << LOG_FLAG << "Unknow VPN auth mothod"; + break; + } +} + +void VpnConfigPage::setEnableOfConfirmBtn() +{ + Q_EMIT setConfigPageState(checkConfirmBtnIsEnabled()); +} + +void VpnConfigPage::onPrivateKeyButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a private key"), + "recent:///", + tr("Key Files (*.key *.pem *.der *.p12 *.pfx)")); + if (!fileName.isNull()) { + m_privateKeyEdit->blockSignals(true); + m_privateKeyEdit->setText(fileName); + m_privateKeyEdit->blockSignals(false); + } +} + +void VpnConfigPage::onCaCertButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a CA certificate"), + "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { + m_caCertPathEdit->blockSignals(true); + m_caCertPathEdit->setText(fileName); + m_caCertPathEdit->blockSignals(false); + } +} + +void VpnConfigPage::onUserCertButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a User certificate"), + "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { + m_userCertPathEdit->blockSignals(true); + m_userCertPathEdit->setText(fileName); + m_userCertPathEdit->blockSignals(false); + } +} + +void VpnConfigPage::onStaticKeyButtonClicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Choose a Static key"), + "recent:///", + tr("Key Files (*.key *.pem *.der *.p12 *.pfx)")); + if (!fileName.isNull()) { + m_staticKeyPathEdit->blockSignals(true); + m_staticKeyPathEdit->setText(fileName); + m_staticKeyPathEdit->blockSignals(false); + } +} + + +bool VpnConfigPage::checkL2tpIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_ntDomain != m_ntDomainEdit->text() + || vpnInfo.m_userName != m_usernameEdit->text() + || vpnInfo.m_userPasswd != m_userPwdEdit->text() + || vpnInfo.m_passwdPolicy != m_userPwdOptionCombox->currentData().toInt()) { + + isChanged = true; + } + return isChanged; +} + +bool VpnConfigPage::checkPptpIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + if (vpnInfo.m_ntDomain != m_ntDomainEdit->text() + || vpnInfo.m_userName != m_usernameEdit->text() + || vpnInfo.m_userPasswd != m_userPwdEdit->text() + || vpnInfo.m_passwdPolicy != m_userPwdOptionCombox->currentData().toInt()) { + + isChanged = true; + } + return isChanged; +} + +bool VpnConfigPage::checkOpenVpnIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + int currentAuthMethod = m_authModeComboBox->currentData().toInt(); + if (vpnInfo.m_authMethod != currentAuthMethod) { + isChanged = true; + } + + if (currentAuthMethod == KYAUTH_PASSWD || currentAuthMethod == KYAUTH_CERTIFICATEANDPASSWD) { + if (vpnInfo.m_userName != m_usernameEdit->text() + || vpnInfo.m_userPasswd != m_userPwdEdit->text() + || vpnInfo.m_passwdPolicy != m_userPwdOptionCombox->currentData().toInt() + || vpnInfo.m_caCertificate != m_caCertPathEdit->text()) { + + isChanged = true; + } + } + + if (currentAuthMethod == KYAUTH_CERTIFICATEANDPASSWD || currentAuthMethod == KYAUTH_CERTIFICATE) { + if (vpnInfo.m_caCertificate != m_caCertPathEdit->text() + || vpnInfo.m_userCertificate != m_userCertPathEdit->text() + || vpnInfo.m_userKey != m_privateKeyEdit->text() + || vpnInfo.m_privatePasswd != m_privateKeyPwdEdit->text() + || vpnInfo.m_privatePasswdPolicy != m_pwdOptionCombox->currentData().toInt()) { + + isChanged = true; + } + + } + if (currentAuthMethod == KYAUTH_STATICPASSWD) { + if (vpnInfo.m_staticKey != m_staticKeyPathEdit->text() + || vpnInfo.m_vpnKeyDir != m_keyDirectionCombox->currentData().toString() + || vpnInfo.m_localAddress != m_localIpEdit->text() + || vpnInfo.m_remoteAddress != m_localIpEdit->text()) { + + isChanged = true; + } + } + + return isChanged; +} + +bool VpnConfigPage::checkStrongSwanIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + int currentAuthMethod = m_authModeComboBox->currentData().toInt(); + + if (vpnInfo.m_authMethod != currentAuthMethod) { + isChanged = true; + } + + if (currentAuthMethod == KYAUTH_KEY) { + if (vpnInfo.m_caCertificate != m_caCertPathEdit->text() + || vpnInfo.m_userCertificate != m_userCertPathEdit->text() + || vpnInfo.m_userKey != m_privateKeyEdit->text() + || vpnInfo.m_privatePasswd != m_privateKeyPwdEdit->text() + || vpnInfo.m_privatePasswdPolicy != m_pwdOptionCombox->currentData().toInt()) { + + isChanged = true; + + } + }else if (currentAuthMethod == KYAUTH_AGENT) { + if (vpnInfo.m_userCertificate != m_userCertPathEdit->text()) { + isChanged = true; + } + } else if (currentAuthMethod == KYAUTH_SMARTCARD) { + if (vpnInfo.m_pinId != m_pinEdit->text()) { + isChanged = true; + } + } else if (currentAuthMethod == KYAUTH_EAP) { + if (vpnInfo.m_userName != m_usernameEdit->text() || vpnInfo.m_userPasswd != m_userPwdEdit->text()) { + isChanged = true; + } + } + return isChanged; +} diff --git a/src-vpn/frontend/vpndetails/vpnconfigpage.h b/src-vpn/frontend/vpndetails/vpnconfigpage.h new file mode 100644 index 00000000..e5d60ba5 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnconfigpage.h @@ -0,0 +1,198 @@ +#ifndef VPNCONFIGPAGE_H +#define VPNCONFIGPAGE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kylable.h" +#include "kwidget.h" +#include "kpasswordedit.h" +#include "kyvpnconnectoperation.h" + +using namespace kdk; + +#define KEY_DIRECTION_NONE_INDEX 0 +#define KEY_DIRECTION_ZERO_INDEX 1 +#define KEY_DIRECTION_ONE_INDEX 2 + +#define KEY_DIRECTION_NONE "None" +#define KEY_DIRECTION_ZERO "0" +#define KEY_DIRECTION_ONE "1" + +enum VpnType { + UNKNOW = -1, + L2TP = 0, + OPEN_VPN, + PPTP, + STRONG_SWAN +}; + +enum OpenVpnAuthMethodIndex { + CERTIFICATE_INDEX = 0, + STATICPASSWD_INDEX, + PASSWD_INDEX, + CERTIFICATEANDPASSWD_INDEX, +}; +enum StrongSwanAuthMethodIndex { + KEY_INDEX = 0, + AGENT_INDEX, + SMARTCARD_INDEX, + EAP_INDEX, +}; + +class VpnConfigPage : public QFrame +{ + Q_OBJECT +public: + explicit VpnConfigPage(QWidget *parent = nullptr); + ~VpnConfigPage() = default; + + VpnType getVpnType(); + void setVpnConfigInfo(const KyVpnConfig &vpnInfo); + bool checkIsChanged(const KyVpnConfig &vpnInfo); + + void updateVpnConfigInfo(KyVpnConfig &vpnInfo); + +private: + QFrame *m_vpnCommunalFrame; + QFrame *m_authModeFrame; + QFrame *m_caCertFrame; + QFrame *m_userCertFrame; + QFrame *m_staticKeysFrame; + QFrame *m_pinFrame; + QFrame *m_PrivateKeysFrame; + QFrame *m_usersFrame; + QFrame *m_userPwdOpFrame; + QFrame *m_ntFrame; + + //公有 + QLabel *m_vpnTypeLabel; + QLabel *m_vpnNameLabel; + FixLabel *m_serverAddressLabel; + QComboBox *m_vpnTypeComboBox = nullptr; + QLineEdit *m_vpnNameEdit = nullptr; + QLineEdit *m_serverAddressEdit = nullptr; + + //认证方式 Authentication Mode + FixLabel *m_authModeLabel; + QComboBox *m_authModeComboBox = nullptr; + + //证书 私钥 + FixLabel *m_caCertLabel; + FixLabel *m_userCertLabel; + FixLabel *m_privateKeyLabel; + FixLabel *m_privateKeyPwdLabel; + FixLabel *m_pwdOptionLabel; + + QLineEdit *m_caCertPathEdit; + QLineEdit *m_userCertPathEdit; + QLineEdit *m_privateKeyEdit; + KPasswordEdit *m_privateKeyPwdEdit; + QComboBox *m_pwdOptionCombox; + + QPushButton *m_caCertButton; + QPushButton *m_userCertButton; + QPushButton *m_privateKeyButton; + + //静态密钥 + QLabel *m_staticKeyLabel; + FixLabel *m_keyDirectionLabel; + QLabel *m_noticesLabel; + QLabel *m_localIpLabel; + QLabel *m_remoteIpLabel; + + QLineEdit *m_staticKeyPathEdit; + QPushButton *m_staticKeyButton; + QComboBox *m_keyDirectionCombox; + QLineEdit *m_localIpEdit; + QLineEdit *m_remoteIpEdit; + + //智能卡 PIN码 + QLabel *m_pinLabel; + QLineEdit *m_pinEdit; + + //密码 + FixLabel *m_usernameLabel; + QLabel *m_userPwdLabel; + FixLabel *m_userPwdOptionLabel; + QLineEdit *m_usernameEdit; + KPasswordEdit *m_userPwdEdit; + QComboBox *m_userPwdOptionCombox; + + //L2TP PPTP公有 + QLabel *m_ntDomainLabel; + QLineEdit *m_ntDomainEdit; + + + void initUI(); + void initConnect(); + void showL2tpPwd(); + void showPptpPwd(); + void showOpenVpnTls(); + void showOpenVpnPwd(); + void showOpenVpnPwdTls(); + void showOpenVpnStaticKey(); + void showSswanCertPrivteKey(); + void showSswanCertSsh(); + void showSswanSmartCard(); + void showSswanEap(); + + bool getTextEditState(QString text); + bool checkConfirmBtnIsEnabled(); + + + //填充VPN认证信息 + void setPwdAuthInfo(const QString &username, const QString &userPwd, const KyPasswdPolicy &userPwdPolicy); + void setCaCertAuthInfo(const QString &caCertificate); + + void setKeyAuthInfo(const QString &userCert, const QString &privateKey, + const QString &privateKeyPwd, const KyPasswdPolicy &privatePwdPolicy); + + void setStaticKeyAuthInfo(const QString &staticKey, const QString &vpnKeyDirection, + const QString &localIp, const QString &remoteIp); + + void setAgentAuthInfo(const QString &userCert); + void setSmartCardAuthInfo(const QString &pin); + void setEapAuthInfo(const QString &username, const QString &userPwd); + void setNtDomain(const QString &ntDomain); + + //set info + void setL2tpConfigInfo(const KyVpnConfig &vpnInfo); + void setPptpConfigInfo(const KyVpnConfig &vpnInfo); + void setOpenVpnConfigInfo(const KyVpnConfig &vpnInfo); + void setSSwanVpnConfigInfo(const KyVpnConfig &vpnInfo); + + //check change + bool checkL2tpIsChanged(const KyVpnConfig &vpnInfo); + bool checkPptpIsChanged(const KyVpnConfig &vpnInfo); + bool checkOpenVpnIsChanged(const KyVpnConfig &vpnInfo); + bool checkStrongSwanIsChanged(const KyVpnConfig &vpnInfo); + + //update + void updateL2tpConfigInfo(KyVpnConfig &vpnInfo); + void updatePptpConfigInfo(KyVpnConfig &vpnInfo); + void updateOpenVpnConfigInfo(KyVpnConfig &vpnInfo); + void updateSSwanVpnConfigInfo(KyVpnConfig &vpnInfo); + +private Q_SLOTS: + void onVpnTypeComboxIndexChanged(); + void onAuthModeComboxIndexChanged(); + void setEnableOfConfirmBtn(); + void onCaCertButtonClicked(); + void onUserCertButtonClicked(); + void onStaticKeyButtonClicked(); + void onPrivateKeyButtonClicked(); + +Q_SIGNALS: + void setConfigPageState(bool); + void vpnTypeChanged(VpnType type); +}; + +#endif // VPNCONFIGPAGE_H diff --git a/src-vpn/frontend/vpndetails/vpndetail.cpp b/src-vpn/frontend/vpndetails/vpndetail.cpp new file mode 100644 index 00000000..bc4150ee --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpndetail.cpp @@ -0,0 +1,439 @@ +#include "vpndetail.h" + +#define WINDOW_WIDTH 520 +#define WINDOW_HEIGHT 562 +#define NO_LAYOUT_MARGINS 0,0,0,0 +#define HLAYOUT_MARGINS 24,0,24,0 +#define CENTER_LAYOUT_MARGINS 24,0,0,0 +#define NO_SPACE 0 +#define HLAYOUT_SPACING 16 +#define VLAYOUT_SPACING 24 +#define BOTTOM_WIDGET_HEIGHT 85 +#define TAB_HEIGHT 36 +#define TAB_WIDTH 80 +#define MAX_TAB_TEXT_LENGTH 44 +#define VPNTAB_WIDTH 240 +#define PAGE_WIDTH 472 +#define SCRO_WIDTH 496 +#define CONFIG_PAGE_NUM 0 +#define IPV4_PAGE_NUM 1 +#define IPV6_PAGE_NUM 2 +#define ADVANCED_PAGE_NUM 3 +#define NORMAL_PAGE_COUNT 3 +#define LOG_FLAG "[VPN Detail]" +#define TAB_HEIGHT_TABLET 48 + +VpnDetail::VpnDetail(QString vpnUuid, QString vpnName, QWidget *parent) : + m_vpnName(vpnName), + m_uuid(vpnUuid), + QWidget(parent) +{ + initWindow(); + centerToScreen(); + getVpnConfig(m_uuid, m_vpnInfo); + + initUI(); + initConnection(); + pagePadding(m_isOpenVpn); + + m_isConfigOk = true; + m_isIpv4Ok = true; + m_isIpv6Ok = true; + m_isAdvancedOk = true; + setConfirmEnable(); +} + +void VpnDetail::paintEvent(QPaintEvent *event) +{ + QPalette pal = qApp->palette(); + QPainter painter(this); + painter.setBrush(pal.color(QPalette::Base)); + painter.drawRect(this->rect()); + painter.fillRect(rect(), QBrush(pal.color(QPalette::Base))); + + return QWidget::paintEvent(event); +} + + +void VpnDetail::initWindow() +{ + this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT); + this->setWindowTitle(tr("VPN")); + this->setAttribute(Qt::WA_DeleteOnClose); +} + +void VpnDetail::initTabBar() +{ + //文本长度超出显示区域设置tooltip + int tabCount = m_vpnTabBar->count(); + for (int i = 0; i< tabCount; ++i) { + QFontMetrics fontMetrics(m_vpnTabBar->font()); + int fontSize = fontMetrics.width(m_vpnTabBar->tabText(i)); + if (fontSize > MAX_TAB_TEXT_LENGTH) { + m_vpnTabBar->setTabToolTip(i, m_vpnTabBar->tabText(i)); + } else { + m_vpnTabBar->setTabToolTip(i, ""); + } + } +} + +void VpnDetail::initUI() +{ + //控件 + m_topWidget = new QWidget(this); + m_centerWidget = new QWidget(this); + m_bottomWidget = new QWidget(this); + m_divider = new Divider(this); + m_vpnTabBar = new VpnTabBar(this); + m_autoConnectBox = new QCheckBox(this); + m_autoConnectLabel = new QLabel(this); + m_cancelBtn = new QPushButton(this); + m_confimBtn = new QPushButton(this); + m_stackWidget = new QStackedWidget(m_centerWidget); + + m_configPage = new VpnConfigPage(this); + m_ipv4Page = new VpnIpv4Page(this); + m_ipv6Page = new VpnIpv6Page(this); + m_advancedPage = new VpnAdvancedPage(this); + + m_configScroArea = new QScrollArea(m_centerWidget); + m_configScroArea->setFrameShape(QFrame::NoFrame); + m_configScroArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_configScroArea->setWidget(m_configPage); + m_configScroArea->setWidgetResizable(true); + + m_ipv4ScroArea = new QScrollArea(m_centerWidget); + m_ipv4ScroArea->setFrameShape(QFrame::NoFrame); + m_ipv4ScroArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_ipv4ScroArea->setWidget(m_ipv4Page); + m_ipv4ScroArea->setWidgetResizable(true); + + m_ipv6ScroArea = new QScrollArea(m_centerWidget); + m_ipv6ScroArea->setFrameShape(QFrame::NoFrame); + m_ipv6ScroArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_ipv6ScroArea->setWidget(m_ipv6Page); + m_ipv6ScroArea->setWidgetResizable(true); + + m_advancedScroArea = new QScrollArea(m_centerWidget); + m_advancedScroArea->setFrameShape(QFrame::NoFrame); + m_advancedScroArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_advancedScroArea->setWidget(m_advancedPage); + m_advancedScroArea->setWidgetResizable(true); + + QPalette pal = m_configScroArea->palette(); + pal.setBrush(QPalette::Window, Qt::transparent); + m_configScroArea->setPalette(pal); + m_ipv4ScroArea->setPalette(pal); + m_ipv6ScroArea->setPalette(pal); + m_advancedScroArea->setPalette(pal); + + m_configPage->setFixedWidth(PAGE_WIDTH); + m_ipv4Page->setFixedWidth(PAGE_WIDTH); + m_ipv6Page->setFixedWidth(PAGE_WIDTH); + m_advancedPage->setFixedWidth(PAGE_WIDTH); + m_configScroArea->setFixedWidth(SCRO_WIDTH); + m_ipv4ScroArea->setFixedWidth(SCRO_WIDTH); + m_ipv6ScroArea->setFixedWidth(SCRO_WIDTH); + m_advancedScroArea->setFixedWidth(SCRO_WIDTH); + + m_stackWidget->addWidget(m_configScroArea); + m_stackWidget->addWidget(m_ipv4ScroArea); + m_stackWidget->addWidget(m_ipv6ScroArea); + m_stackWidget->addWidget(m_advancedScroArea); + + //控件显示文本 + m_vpnTabBar->addTab(tr("VPN")); + m_vpnTabBar->addTab(tr("IPv4")); + if (m_isOpenVpn) { + m_vpnTabBar->addTab(tr("IPv6")); + m_vpnTabBar->setFixedWidth(VPNTAB_WIDTH + TAB_WIDTH); + } else { + m_vpnTabBar->setFixedWidth(VPNTAB_WIDTH); + } + m_vpnTabBar->addTab(tr("Advanced")); + m_vpnTabBar->setFixedHeight(TAB_HEIGHT); + initTabBar(); + + m_autoConnectBox->setChecked(false); + m_autoConnectLabel->setText(tr("Auto Connection")); + m_cancelBtn->setText(tr("Cancel")); + m_confimBtn->setText(tr("Confirm")); + + //布局 + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setSpacing(NO_SPACE); + mainLayout->addSpacing(HLAYOUT_SPACING); + mainLayout->addWidget(m_topWidget); + mainLayout->addSpacing(VLAYOUT_SPACING); + mainLayout->addWidget(m_centerWidget); + mainLayout->addStretch(); + mainLayout->addWidget(m_divider); + mainLayout->addWidget(m_bottomWidget); + m_bottomWidget->setFixedHeight(BOTTOM_WIDGET_HEIGHT); + + QHBoxLayout *topLayout = new QHBoxLayout(m_topWidget); + topLayout->setContentsMargins(HLAYOUT_MARGINS); + topLayout->addWidget(m_vpnTabBar, Qt::AlignCenter); + + QVBoxLayout *centerlayout = new QVBoxLayout(m_centerWidget); + centerlayout->setContentsMargins(CENTER_LAYOUT_MARGINS); // 右边距为0,为安全页滚动区域留出空间 + centerlayout->addWidget(m_stackWidget); + + QHBoxLayout *bottomLayout = new QHBoxLayout(m_bottomWidget); + bottomLayout->setContentsMargins(HLAYOUT_MARGINS); + bottomLayout->setSpacing(NO_SPACE); + bottomLayout->addWidget(m_autoConnectBox); + bottomLayout->addSpacing(8); + bottomLayout->addWidget(m_autoConnectLabel); + bottomLayout->addStretch(); + bottomLayout->addWidget(m_cancelBtn); + bottomLayout->addSpacing(HLAYOUT_SPACING); + bottomLayout->addWidget(m_confimBtn); + + m_advancedPage->setVpnAdvancedPage(m_configPage->getVpnType()); +} + +void VpnDetail::initConnection() +{ + connect(m_vpnTabBar, &VpnTabBar::currentChanged, this, &VpnDetail::onTabCurrentRowChange); + connect(m_cancelBtn, &QPushButton::clicked, [&] () {this->close();}); + connect(m_confimBtn, &QPushButton::clicked, this, &VpnDetail::onConfimBtnClicked); + + connect(m_configPage, &VpnConfigPage::setConfigPageState, this, [=] (bool state) { + m_isConfigOk = state; + setConfirmEnable(); + }); + connect(m_ipv4Page, &VpnIpv4Page::setIpv4PageState, this, [=] (bool state) { + m_isIpv4Ok = state; + setConfirmEnable(); + }); + connect(m_ipv6Page, &VpnIpv6Page::setIpv6PageState, this, [=] (bool state) { + m_isIpv6Ok = state; + setConfirmEnable(); + }); + connect(m_advancedPage, &VpnAdvancedPage::setAdvancedPageState, this, [=] (bool state) { + m_isAdvancedOk = state; + setConfirmEnable(); + }); + + connect(m_configPage, &VpnConfigPage::vpnTypeChanged, m_advancedPage, &VpnAdvancedPage::setVpnAdvancedPage); + + connect(m_configPage, &VpnConfigPage::vpnTypeChanged, this, [=](VpnType type) { + if (type == OPEN_VPN) { + if (m_vpnTabBar->count() == NORMAL_PAGE_COUNT) { + m_vpnTabBar->insertTab(IPV6_PAGE_NUM, tr("IPv6")); + m_vpnTabBar->setFixedWidth(VPNTAB_WIDTH + TAB_WIDTH); + } + } else { + if (m_vpnTabBar->count() > NORMAL_PAGE_COUNT) { + m_vpnTabBar->removeTab(IPV6_PAGE_NUM); + m_vpnTabBar->setFixedWidth(VPNTAB_WIDTH); + } + } + }); +} + +void VpnDetail::centerToScreen() +{ + QDesktopWidget* m = QApplication::desktop(); + QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos())); + int desk_x = desk_rect.width(); + int desk_y = desk_rect.height(); + int x = this->width(); + int y = this->height(); + this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); +} + +void VpnDetail::setConfirmEnable() +{ + bool isConfirmBtnEnable = false; + if (m_isConfigOk && m_isIpv4Ok && m_isAdvancedOk) { + if (m_isOpenVpn && !m_isIpv6Ok) { + isConfirmBtnEnable = false; + } else { + isConfirmBtnEnable = true; + } + } + m_confimBtn->setEnabled(isConfirmBtnEnable); +} + +void VpnDetail::getVpnConfig(QString connectUuid, KyVpnConfig &vpnInfo) +{ + KyVpnConnectOperation vpnConnect(this); + vpnInfo = vpnConnect.getVpnConfig(connectUuid); + m_isOpenVpn = m_vpnInfo.m_vpnType == KYVPNTYPE_OPENVPN; +} + +void VpnDetail::pagePadding(bool isOpenVpn) +{ + m_autoConnectBox->setChecked(m_vpnInfo.m_isAutoConnect); + + //配置页面填充 + m_configPage->setVpnConfigInfo(m_vpnInfo); + + //IPv4页面填充 + m_ipv4Page->setVpnIpv4Info(m_vpnInfo); + if (!m_vpnInfo.m_ipv4Dns.isEmpty()) { + m_ipv4Page->setDns(m_vpnInfo.m_ipv4Dns.at(0).toString()); + } + if (!m_vpnInfo.m_ipv4DnsSearch.isEmpty()) { + m_ipv4Page->setSearchDomain(m_vpnInfo.m_ipv4DnsSearch.at(0)); + } + m_ipv4Page->setDhcpClientId(m_vpnInfo.m_ipv4DhcpClientId); + //IPv6页面填充 + if (isOpenVpn) { + m_ipv6Page->setVpnIpv6Info(m_vpnInfo); + if (!m_vpnInfo.m_ipv6Dns.isEmpty()) { + m_ipv6Page->setDns(m_vpnInfo.m_ipv6Dns.at(0).toString()); + } + if (!m_vpnInfo.m_ipv6DnsSearch.isEmpty()) { + m_ipv6Page->setSearchDomain(m_vpnInfo.m_ipv6DnsSearch.at(0)); + } + } + + //高级页面填充 + if (m_vpnInfo.m_vpnType == KYVPNTYPE_L2TP || m_vpnInfo.m_vpnType == KYVPNTYPE_PPTP) { + m_advancedPage->setL2tpOrPptpAdiaInfo(m_vpnInfo); + } else if (m_vpnInfo.m_vpnType == KYVPNTYPE_OPENVPN) { + m_advancedPage->setOpenVpnAdiaInfo(m_vpnInfo); + } else if (m_vpnInfo.m_vpnType == KYVPNTYPE_STRONGSWAN) { + m_advancedPage->setStrongSwanAdiaInfo(m_vpnInfo); + } +} + +bool VpnDetail::updateVpnCnofig() +{ + KyVpnConnectOperation vpnConnect(this); + KyVpnConfig vpnConfig = m_vpnInfo; + bool needUpdate = false; + VpnType vpnType = m_configPage->getVpnType(); + + if (m_vpnInfo.m_isAutoConnect != m_autoConnectBox->isChecked()) { + vpnConfig.m_isAutoConnect = m_autoConnectBox->isChecked(); + needUpdate = true; + } + + if (m_configPage->checkIsChanged(m_vpnInfo)) { + m_configPage->updateVpnConfigInfo(vpnConfig); + needUpdate = true; + } + + if (m_ipv4Page->checkIsChanged(m_vpnInfo)) { + m_ipv4Page->updateVpnIpv4Info(vpnConfig); + needUpdate = true; + } + + if (vpnType == OPEN_VPN) { + if (m_ipv6Page->checkIsChanged(m_vpnInfo)) { + m_ipv6Page->updateVpnIpv6Info(vpnConfig); + needUpdate = true; + } + } + + if (m_advancedPage->checkIsChanged(m_vpnInfo, vpnType)) { + if (vpnType == L2TP || vpnType == PPTP) { + m_advancedPage->updateL2tpOrPptpAdiaInfo(vpnConfig); + needUpdate = true; + } else if (vpnType == OPEN_VPN) { + m_advancedPage->updateOpenVpnAdiaInfo(vpnConfig); + needUpdate = true; + } else if (vpnType == STRONG_SWAN) { + m_advancedPage->updateStrongSwanAdiaInfo(vpnConfig); + needUpdate = true; + } + } + + if (needUpdate) { + vpnConnect.setVpnConfig(m_uuid, vpnConfig); + } + + return true; +} + +void VpnDetail::setVpndetailSomeEnable(bool on) +{ + m_configPage->setEnabled(on); + m_ipv4Page->setEnabled(on); + m_ipv6Page->setEnabled(on); + m_advancedPage->setEnabled(on); + m_cancelBtn->setEnabled(on); + m_confimBtn->setEnabled(on); +} + +void VpnDetail::onTabCurrentRowChange(int row) +{ + if (row < 2) { + m_stackWidget->setCurrentIndex(row); + } else { + if (m_configPage->getVpnType() == OPEN_VPN) { + m_stackWidget->setCurrentIndex(row); + } else { + m_stackWidget->setCurrentIndex(ADVANCED_PAGE_NUM); + } + } +} + +void VpnDetail::onConfimBtnClicked() +{ + qDebug() << "onConfimBtnClicked"; + setVpndetailSomeEnable(false); + //更新连接 + qDebug() << "Confirm update connect"; + if (!updateVpnCnofig()) { + setVpndetailSomeEnable(true); + return; + } + close(); +} + + +VpnTabBar::VpnTabBar(QWidget *parent) + :KTabBar(KTabBarStyle::SegmentDark, parent) +{ + //模式切换 + QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), + QString("/"), + QString("com.kylin.statusmanager.interface"), + QString("mode_change_signal"), this, SLOT(onModeChanged(bool))); + //模式获取 + QDBusInterface interface(QString("com.kylin.statusmanager.interface"), + QString("/"), + QString("com.kylin.statusmanager.interface"), + QDBusConnection::sessionBus()); + if(!interface.isValid()) { + this->setFixedHeight(TAB_HEIGHT); + return; + } + QDBusReply reply = interface.call("get_current_tabletmode"); + if (!reply.isValid()) { + this->setFixedHeight(TAB_HEIGHT); + return; + } + onModeChanged(reply.value()); +} + +QSize VpnTabBar::sizeHint() const +{ + QSize size = KTabBar::sizeHint(); + size.setWidth(TAB_WIDTH); + return size; +} + +QSize VpnTabBar::minimumTabSizeHint(int index) const +{ + Q_UNUSED(index) + QSize size = KTabBar::minimumTabSizeHint(index); + size.setWidth(TAB_WIDTH); + return size; +} + +void VpnTabBar::onModeChanged(bool mode) +{ + if (mode) { + this->setFixedHeight(TAB_HEIGHT_TABLET); // 平板模式 + } else { + this->setFixedHeight(TAB_HEIGHT); // PC模式 + } + +} diff --git a/src-vpn/frontend/vpndetails/vpndetail.h b/src-vpn/frontend/vpndetails/vpndetail.h new file mode 100644 index 00000000..c98585af --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpndetail.h @@ -0,0 +1,111 @@ +#ifndef VPNDETAIL_H +#define VPNDETAIL_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kwidget.h" +#include "ktabbar.h" +#include "../tools/divider.h" +#include "vpnconfigpage.h" +#include "vpnipv4page.h" +#include "vpnipv6page.h" +#include "vpnadvancedpage.h" + +#include "kyvpnconnectoperation.h" + + +using namespace kdk; + +class VpnTabBar : public KTabBar +{ + Q_OBJECT +public: + explicit VpnTabBar(QWidget *parent = nullptr); + ~VpnTabBar() = default; + +protected: + QSize sizeHint() const; + QSize minimumTabSizeHint(int index) const; + +private Q_SLOTS: + void onModeChanged(bool mode); + +}; + +class VpnDetail : public QWidget +{ + Q_OBJECT +public: + explicit VpnDetail(QString vpnUuid, QString vpnName, QWidget *parent = nullptr); + void centerToScreen(); + +protected: + void paintEvent(QPaintEvent *event); + +private: + void initUI(); + void initWindow(); + void initTabBar(); + + void initConnection(); + void setConfirmEnable(); + + void getVpnConfig(QString connectUuid, KyVpnConfig &vpnInfo); + void pagePadding(bool isOpenVpn); + + bool updateVpnCnofig(); + void setVpndetailSomeEnable(bool on); + + bool m_isOpenVpn = false; + QString m_vpnName; + QString m_uuid; + KyVpnConfig m_vpnInfo; + + QStackedWidget * m_stackWidget; + QWidget *m_topWidget; + QWidget *m_centerWidget; + Divider *m_divider = nullptr; + QWidget *m_bottomWidget; + + VpnConfigPage *m_configPage = nullptr; + VpnIpv4Page *m_ipv4Page = nullptr; + VpnIpv6Page *m_ipv6Page = nullptr; + VpnAdvancedPage *m_advancedPage = nullptr; + + QScrollArea *m_configScroArea = nullptr; + QScrollArea *m_ipv4ScroArea = nullptr; + QScrollArea *m_ipv6ScroArea = nullptr; + QScrollArea *m_advancedScroArea = nullptr; + VpnTabBar *m_vpnTabBar = nullptr; + QCheckBox *m_autoConnectBox = nullptr; + QLabel *m_autoConnectLabel; + QPushButton *m_cancelBtn; + QPushButton *m_confimBtn; + + bool m_isConfigOk = false; + bool m_isIpv4Ok = false; + bool m_isIpv6Ok = false; + bool m_isAdvancedOk = false; + +protected Q_SLOTS: + void onTabCurrentRowChange(int row); + void onConfimBtnClicked(); + +Q_SIGNALS: + void currentChanged(int); + +}; + +#endif // VPNDETAIL_H diff --git a/src-vpn/frontend/vpndetails/vpndetails.pri b/src-vpn/frontend/vpndetails/vpndetails.pri new file mode 100644 index 00000000..e80cdfa7 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpndetails.pri @@ -0,0 +1,17 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/vpnaddpage.h \ + $$PWD/vpnadvancedpage.h \ + $$PWD/vpnconfigpage.h \ + $$PWD/vpndetail.h \ + $$PWD/vpnipv4page.h \ + $$PWD/vpnipv6page.h + +SOURCES += \ + $$PWD/vpnaddpage.cpp \ + $$PWD/vpnadvancedpage.cpp \ + $$PWD/vpnconfigpage.cpp \ + $$PWD/vpndetail.cpp \ + $$PWD/vpnipv4page.cpp \ + $$PWD/vpnipv6page.cpp diff --git a/src-vpn/frontend/vpndetails/vpnipv4page.cpp b/src-vpn/frontend/vpndetails/vpnipv4page.cpp new file mode 100644 index 00000000..fa49a9cd --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnipv4page.cpp @@ -0,0 +1,284 @@ +#include "vpnipv4page.h" +#include "math.h" +#include + +#define NO_LAYOUT_MARGINS 0, 0, 0, 0 +#define NO_SPACE 0 +#define HLAYOUT_SPACING 16 +#define VLAYOUT_SPACING 24 +#define AUTO_CONFIG 0 +#define MANUAL_CONFIG 1 +#define LOG_FLAG "[VPN IPv4Page]" + +VpnIpv4Page::VpnIpv4Page(QWidget *parent) : QFrame(parent) +{ + initUI(); + initConnect(); +} + +void VpnIpv4Page::setVpnIpv4Info(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_ipv4ConfigIpType == CONFIG_IP_DHCP) { + m_ipv4ConfigCombox->setCurrentIndex(AUTO_CONFIG); + } else { + m_ipv4ConfigCombox->setCurrentIndex(MANUAL_CONFIG); + if (!vpnInfo.m_ipv4Address.isEmpty()) { + m_ipv4addressEdit->setText(vpnInfo.m_ipv4Address.at(0).ip().toString()); + m_netMaskEdit->setText(vpnInfo.m_ipv4Address.at(0).netmask().toString()); + m_gateWayEdit->setText(vpnInfo.m_ipv4Address.at(0).gateway().toString()); + } + } +} + +void VpnIpv4Page::setDns(const QString &firstDns) +{ + m_dnsServerEdit->setText(firstDns); +} + +void VpnIpv4Page::setSearchDomain(const QString &searchDomain) +{ + m_searchDomainEdit->setText(searchDomain); +} + +void VpnIpv4Page::setDhcpClientId(const QString &dhcpId) +{ + m_dhcpClientIdEdit->setText(dhcpId); +} + +bool VpnIpv4Page::checkIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + + if (m_ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + if (vpnInfo.m_ipv4ConfigIpType != CONFIG_IP_DHCP) { + qDebug() << LOG_FLAG << "ipv4ConfigType change to Auto"; + isChanged = true; + } + } else { + if (vpnInfo.m_ipv4ConfigIpType != CONFIG_IP_MANUAL) { + qDebug() << LOG_FLAG << "ipv4ConfigType change to Manual"; + isChanged = true; + } + + if (!vpnInfo.m_ipv4Address.isEmpty()) { + if(vpnInfo.m_ipv4Address.at(0).ip().toString() != m_ipv4addressEdit->text() + || vpnInfo.m_ipv4Address.at(0).netmask().toString() != getNetMaskText(m_netMaskEdit->text()) + || vpnInfo.m_ipv4Address.at(0).gateway().toString() != m_gateWayEdit->text()) { + + isChanged = true; + } + } + } + + if (!vpnInfo.m_ipv4Dns.isEmpty() && vpnInfo.m_ipv4Dns.at(0).toString() != m_dnsServerEdit->text()) { + isChanged = true; + } + + if (!vpnInfo.m_ipv4DnsSearch.isEmpty() && vpnInfo.m_ipv4DnsSearch.at(0) != m_searchDomainEdit->text()) { + isChanged = true; + } + if (vpnInfo.m_ipv4DhcpClientId != m_dhcpClientIdEdit->text()){ + isChanged = true; + } + return isChanged; +} + +void VpnIpv4Page::updateVpnIpv4Info(KyVpnConfig &vpnInfo) +{ + if (m_ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + QString ipv4address(""); + QString netMask(""); + QString gateWay(""); + vpnInfo.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP); + vpnInfo.ipv4AddressConstruct(ipv4address, netMask, gateWay); + qDebug() << LOG_FLAG << "IPv4 method" << vpnInfo.m_ipv4ConfigIpType; + qDebug() << LOG_FLAG << "Update IPv4 info finished"; + } else { + QString ipv4address =m_ipv4addressEdit->text(); + QString netMask = getNetMaskText(m_netMaskEdit->text()); + QString gateWay = m_gateWayEdit->text(); + qDebug() << ipv4address << netMask << gateWay; + vpnInfo.setIpConfigType(IPADDRESS_V4, CONFIG_IP_MANUAL); + vpnInfo.ipv4AddressConstruct(ipv4address, netMask, gateWay); + vpnInfo.dumpInfo(); + qDebug() << LOG_FLAG << "Update IPv4 info finished"; + } + + QList ipv4DnsList; + ipv4DnsList.clear(); + if (!m_dnsServerEdit->text().isEmpty()) { + ipv4DnsList.append(QHostAddress(m_dnsServerEdit->text())); + } + vpnInfo.ipv4DnsConstruct(ipv4DnsList); + + vpnInfo.m_ipv4DnsSearch.clear(); + vpnInfo.m_ipv4DnsSearch.append(m_searchDomainEdit->text()); + vpnInfo.m_ipv4DhcpClientId = m_dhcpClientIdEdit->text(); +} + +void VpnIpv4Page::initUI() +{ + /**********控件**********/ + m_configLabel = new QLabel(this); + m_addressLabel = new QLabel(this); + m_maskLabel = new QLabel(this); + m_gateWayLabel = new QLabel(this); + m_dnsServerLabel = new QLabel(this); + m_searchDomainLabel = new QLabel(this); + m_dhcpClientIdLabel = new QLabel(this); + + m_ipv4ConfigCombox =new QComboBox(this); + m_ipv4addressEdit = new QLineEdit(this); + m_netMaskEdit = new QLineEdit(this); + m_gateWayEdit = new QLineEdit(this); + m_dnsServerEdit = new QLineEdit(this); + m_searchDomainEdit = new QLineEdit(this); + m_dhcpClientIdEdit = new QLineEdit(this); + + + /**********布局**********/ + QFormLayout *mainLayout = new QFormLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setHorizontalSpacing(HLAYOUT_SPACING); + mainLayout->setVerticalSpacing(VLAYOUT_SPACING); + mainLayout->addRow(m_configLabel, m_ipv4ConfigCombox); + mainLayout->addRow(m_addressLabel, m_ipv4addressEdit); + mainLayout->addRow(m_maskLabel, m_netMaskEdit); + mainLayout->addRow(m_gateWayLabel, m_gateWayEdit); + mainLayout->addRow(m_dnsServerLabel, m_dnsServerEdit); + mainLayout->addRow(m_searchDomainLabel, m_searchDomainEdit); + mainLayout->addRow(m_dhcpClientIdLabel, m_dhcpClientIdEdit); + + + /**********控件显示**********/ + m_configLabel->setText(tr("IPv4 Config")); + m_addressLabel->setText(tr("Address")); + m_maskLabel->setText(tr("Netmask")); + m_gateWayLabel->setText(tr("Default Gateway")); + m_dnsServerLabel->setText(tr("DNS Server")); + m_searchDomainLabel->setText(tr("Search Domain")); //搜索域 + m_dhcpClientIdLabel->setText(tr("DHCP Client ID")); //DHCP客户端ID + + m_ipv4ConfigCombox->addItem(tr("Auto(DHCP)"), AUTO_CONFIG); //"自动(DHCP)" + m_ipv4ConfigCombox->addItem(tr("Manual"), MANUAL_CONFIG); //"手动" + + // IP的正则格式限制 + QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + QRegExpValidator *ipExpVal = new QRegExpValidator(rxIp, this); + m_ipv4addressEdit->setValidator(ipExpVal); + m_netMaskEdit->setValidator(ipExpVal); + m_gateWayEdit->setValidator(ipExpVal); + m_dnsServerEdit->setValidator(ipExpVal); +} + +void VpnIpv4Page::initConnect() +{ + if (m_ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + setManualEnabled(false); + } else if (m_ipv4ConfigCombox->currentIndex() == MANUAL_CONFIG) { + setManualEnabled(true); + } + connect(m_ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(onConfigChanged(int))); + connect(m_ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_ipv4addressEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_netMaskEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_gateWayEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_dnsServerEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_searchDomainEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); + connect(m_dhcpClientIdEdit, &QLineEdit::textChanged, this, &VpnIpv4Page::setEnableOfConfirmBtn); +} + +void VpnIpv4Page::setManualEnabled(bool state) +{ + m_addressLabel->setEnabled(state); + m_maskLabel->setEnabled(state); + m_gateWayLabel->setEnabled(state); + m_ipv4addressEdit->setEnabled(state); + m_netMaskEdit->setEnabled(state); + m_gateWayEdit->setEnabled(state); +} + +bool VpnIpv4Page::getTextEditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} + +bool VpnIpv4Page::netMaskIsValide(QString text) +{ + if (getTextEditState(text)) { + return true; + } else { + if (text.length() > 0 && text.length() < 3) { + int num = text.toInt(); + if (num > 0 && num < 33) { + return true; + } + } + } + return false; +} + +QString VpnIpv4Page::getNetMaskText(QString text) +{ + if (text.length() > 2) { + return text; + } + + int num = text.toInt(); + QStringList list; + list << "0" << "0" << "0" << "0"; + int count = 0; + while (num - 8 >= 0) { + list[count] = "255"; + num = num - 8; + count ++; + } + if (num > 0) { + int size = pow(2, 8) - pow(2,(8-num)); + list[count] = QString::number(size); + } + return QString("%1.%2.%3.%4").arg(list[0],list[1],list[2],list[3]); +} + +bool VpnIpv4Page::checkConfirmBtnIsEnabled() +{ + if (m_ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + return true; + } else { + if (m_ipv4addressEdit->text().isEmpty() || !getTextEditState(m_ipv4addressEdit->text())) { + qDebug() << LOG_FLAG << "IPv4 address empty or invalid"; + return false; + } + + if (m_netMaskEdit->text().isEmpty() || !netMaskIsValide(m_netMaskEdit->text())) { + qDebug() << LOG_FLAG << "IPv4 netMask empty or invalid"; + return false; + } + } + return true; +} + +void VpnIpv4Page::setEnableOfConfirmBtn() +{ + Q_EMIT setIpv4PageState(checkConfirmBtnIsEnabled()); +} + +void VpnIpv4Page::onConfigChanged(int index) +{ + if (index == AUTO_CONFIG) { + m_ipv4addressEdit->clear(); + m_netMaskEdit->clear(); + m_gateWayEdit->clear(); + setManualEnabled(false); + } else if (index == MANUAL_CONFIG) { + setManualEnabled(true); + } +} diff --git a/src-vpn/frontend/vpndetails/vpnipv4page.h b/src-vpn/frontend/vpndetails/vpnipv4page.h new file mode 100644 index 00000000..ee73d5fe --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnipv4page.h @@ -0,0 +1,62 @@ +#ifndef VPNIPV4PAGE_H +#define VPNIPV4PAGE_H + +#include +#include +#include +#include +#include +#include + +#include "kyvpnconnectoperation.h" + +class VpnIpv4Page : public QFrame +{ + Q_OBJECT +public: + VpnIpv4Page(QWidget *parent = nullptr); + ~VpnIpv4Page() = default; + + void setVpnIpv4Info(const KyVpnConfig &vpnInfo); + void setDns(const QString &firstDns); + void setSearchDomain(const QString &searchDomain); + void setDhcpClientId(const QString &dhcpId); + + bool checkIsChanged(const KyVpnConfig &vpnInfo); + void updateVpnIpv4Info(KyVpnConfig &vpnInfo); + +private: + QLabel *m_configLabel; + QLabel *m_addressLabel; + QLabel *m_maskLabel; + QLabel *m_gateWayLabel; + QLabel *m_dnsServerLabel; + QLabel *m_searchDomainLabel; + QLabel *m_dhcpClientIdLabel; + + QComboBox *m_ipv4ConfigCombox; + QLineEdit *m_ipv4addressEdit; + QLineEdit *m_netMaskEdit; + QLineEdit *m_gateWayEdit; + QLineEdit *m_dnsServerEdit; + QLineEdit *m_searchDomainEdit; + QLineEdit *m_dhcpClientIdEdit; + + void initUI(); + void initConnect(); + void setManualEnabled(bool state); + + bool getTextEditState(QString text); + bool netMaskIsValide(QString text); + QString getNetMaskText(QString text); + bool checkConfirmBtnIsEnabled(); + +private Q_SLOTS: + void setEnableOfConfirmBtn(); + void onConfigChanged(int index); + +Q_SIGNALS: + void setIpv4PageState(bool); +}; + +#endif // VPNIPV4PAGE_H diff --git a/src-vpn/frontend/vpndetails/vpnipv6page.cpp b/src-vpn/frontend/vpndetails/vpnipv6page.cpp new file mode 100644 index 00000000..87e921ab --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnipv6page.cpp @@ -0,0 +1,240 @@ +#include "vpnipv6page.h" +#include "math.h" +#include + +#define NO_LAYOUT_MARGINS 0, 0, 0, 0 +#define NO_SPACE 0 +#define HLAYOUT_SPACING 16 +#define VLAYOUT_SPACING 24 +#define AUTO_CONFIG 0 +#define MANUAL_CONFIG 1 +#define LOG_FLAG "[VPN IPv6Page]" + +VpnIpv6Page::VpnIpv6Page(QWidget *parent) : QFrame(parent) +{ + initUI(); + initConnect(); +} + +void VpnIpv6Page::setVpnIpv6Info(const KyVpnConfig &vpnInfo) +{ + if (vpnInfo.m_ipv6ConfigIpType == CONFIG_IP_DHCP) { + m_ipv6ConfigCombox->setCurrentIndex(AUTO_CONFIG); + } else { + m_ipv6ConfigCombox->setCurrentIndex(MANUAL_CONFIG); + if (!vpnInfo.m_ipv6Address.isEmpty()) { + m_ipv6addressEdit->setText(vpnInfo.m_ipv6Address.at(0).ip().toString()); + m_netMaskEdit->setText(vpnInfo.m_ipv6Address.at(0).netmask().toString()); + m_gateWayEdit->setText(vpnInfo.m_ipv6Address.at(0).gateway().toString()); + } + } +} + +void VpnIpv6Page::setDns(const QString &firstDns) +{ + m_dnsServerEdit->setText(firstDns); +} + +void VpnIpv6Page::setSearchDomain(const QString &searchDomain) +{ + m_searchDomainEdit->setText(searchDomain); +} + +bool VpnIpv6Page::checkIsChanged(const KyVpnConfig &vpnInfo) +{ + bool isChanged = false; + + if (m_ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + if (vpnInfo.m_ipv6ConfigIpType != CONFIG_IP_DHCP) { + qDebug() << LOG_FLAG << "ipv6ConfigType change to Auto"; + isChanged = true; + } + } else { + if (vpnInfo.m_ipv6ConfigIpType != CONFIG_IP_MANUAL) { + qDebug() << LOG_FLAG << "ipv6ConfigType change to Manual"; + isChanged = true; + } + + if (!vpnInfo.m_ipv6Address.isEmpty()) { + if(vpnInfo.m_ipv6Address.at(0).ip().toString() != m_ipv6addressEdit->text() + || vpnInfo.m_ipv6Address.at(0).netmask().toString() != m_netMaskEdit->text() + || vpnInfo.m_ipv6Address.at(0).gateway().toString() != m_gateWayEdit->text()) { + + isChanged = true; + } + } + } + + if (!vpnInfo.m_ipv6Dns.isEmpty() && vpnInfo.m_ipv6Dns.at(0).toString() != m_dnsServerEdit->text()) { + isChanged = true; + } + + if (!vpnInfo.m_ipv6DnsSearch.isEmpty() && vpnInfo.m_ipv6DnsSearch.at(0) != m_searchDomainEdit->text()) { + isChanged = true; + } + + return isChanged; +} + +void VpnIpv6Page::updateVpnIpv6Info(KyVpnConfig &vpnInfo) +{ + if (m_ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + QString ipv6address(""); + QString netMask(""); + QString gateWay(""); + vpnInfo.setIpConfigType(IPADDRESS_V6, CONFIG_IP_DHCP); + vpnInfo.ipv6AddressConstruct(ipv6address, netMask, gateWay); + qDebug() << LOG_FLAG << "IPv6 method" << vpnInfo.m_ipv6ConfigIpType; + qDebug() << LOG_FLAG << "Update IPv6 info finished"; + } else { + QString ipv6address =m_ipv6addressEdit->text(); + QString netMask = m_netMaskEdit->text(); + QString gateWay = m_gateWayEdit->text(); + qDebug() << ipv6address << netMask << gateWay; + vpnInfo.setIpConfigType(IPADDRESS_V6, CONFIG_IP_MANUAL); + vpnInfo.ipv6AddressConstruct(ipv6address, netMask, gateWay); + vpnInfo.dumpInfo(); + qDebug() << LOG_FLAG << "Update IPv6 info finished"; + } + + QList ipv6DnsList; + ipv6DnsList.clear(); + if (!m_dnsServerEdit->text().isEmpty()) { + ipv6DnsList.append(QHostAddress(m_dnsServerEdit->text())); + } + vpnInfo.ipv6DnsConstruct(ipv6DnsList); + + vpnInfo.m_ipv6DnsSearch.clear(); + vpnInfo.m_ipv6DnsSearch.append(m_searchDomainEdit->text()); +} + +void VpnIpv6Page::initUI() +{ + /**********控件**********/ + m_configLabel = new QLabel(this); + m_addressLabel = new QLabel(this); + m_maskLabel = new QLabel(this); + m_gateWayLabel = new QLabel(this); + m_dnsServerLabel = new QLabel(this); + m_searchDomainLabel = new QLabel(this); + + m_ipv6ConfigCombox =new QComboBox(this); + m_ipv6addressEdit = new QLineEdit(this); + m_netMaskEdit = new QLineEdit(this); + m_gateWayEdit = new QLineEdit(this); + m_dnsServerEdit = new QLineEdit(this); + m_searchDomainEdit = new QLineEdit(this); + + + /**********布局**********/ + QFormLayout *mainLayout = new QFormLayout(this); + mainLayout->setContentsMargins(NO_LAYOUT_MARGINS); + mainLayout->setHorizontalSpacing(HLAYOUT_SPACING); + mainLayout->setVerticalSpacing(VLAYOUT_SPACING); + mainLayout->addRow(m_configLabel, m_ipv6ConfigCombox); + mainLayout->addRow(m_addressLabel, m_ipv6addressEdit); + mainLayout->addRow(m_maskLabel, m_netMaskEdit); + mainLayout->addRow(m_gateWayLabel, m_gateWayEdit); + mainLayout->addRow(m_dnsServerLabel, m_dnsServerEdit); + mainLayout->addRow(m_searchDomainLabel, m_searchDomainEdit); + + + /**********控件显示**********/ + m_configLabel->setText(tr("IPv6 Config")); + m_addressLabel->setText(tr("Address")); + m_maskLabel->setText(tr("Netmask")); + m_gateWayLabel->setText(tr("Default Gateway")); + m_dnsServerLabel->setText(tr("DNS Server")); + m_searchDomainLabel->setText(tr("Search Domain")); //搜索域 + + m_ipv6ConfigCombox->addItem(tr("Auto(DHCP)"), AUTO_CONFIG); //"自动(DHCP)" + m_ipv6ConfigCombox->addItem(tr("Manual"), MANUAL_CONFIG); //"手动" + + // IP的正则格式限制 + QRegExp ipv6_rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); + QRegExpValidator *ipv6ExpVal = new QRegExpValidator(ipv6_rx, this); + m_ipv6addressEdit->setValidator(ipv6ExpVal); + m_gateWayEdit->setValidator(ipv6ExpVal); + m_dnsServerEdit->setValidator(ipv6ExpVal); + + QRegExp prefix_rx("\\b(?:(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\.){3}(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\b"); + m_netMaskEdit->setValidator(new QRegExpValidator(prefix_rx,this)); +} + +void VpnIpv6Page::initConnect() +{ + if (m_ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + setManualEnabled(false); + } else if (m_ipv6ConfigCombox->currentIndex() == MANUAL_CONFIG) { + setManualEnabled(true); + } + connect(m_ipv6ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(onConfigChanged(int))); + connect(m_ipv6ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn())); + connect(m_ipv6addressEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); + connect(m_netMaskEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); + connect(m_gateWayEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); + connect(m_dnsServerEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); + connect(m_searchDomainEdit, &QLineEdit::textChanged, this, &VpnIpv6Page::setEnableOfConfirmBtn); +} + +void VpnIpv6Page::setManualEnabled(bool state) +{ + m_addressLabel->setEnabled(state); + m_maskLabel->setEnabled(state); + m_gateWayLabel->setEnabled(state); + m_ipv6addressEdit->setEnabled(state); + m_netMaskEdit->setEnabled(state); + m_gateWayEdit->setEnabled(state); +} + +bool VpnIpv6Page::getIpv6EditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} + +bool VpnIpv6Page::checkConfirmBtnIsEnabled() +{ + if (m_ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + return true; + } else { + if (m_ipv6addressEdit->text().isEmpty() || !getIpv6EditState(m_ipv6addressEdit->text())) { + qDebug() << "IPv6 address empty or invalid"; + return false; + } + + if (m_netMaskEdit->text().isEmpty()) { + qDebug() << "IPv6 netMask empty or invalid"; + return false; + } + if (m_gateWayEdit->text().isEmpty() || !getIpv6EditState(m_gateWayEdit->text())) { + qDebug() << "IPv6 gateway empty or invalid"; + return false; + } + } + return true; +} + +void VpnIpv6Page::setEnableOfConfirmBtn() +{ + Q_EMIT setIpv6PageState(checkConfirmBtnIsEnabled()); +} + +void VpnIpv6Page::onConfigChanged(int index) +{ + if (index == AUTO_CONFIG) { + m_ipv6addressEdit->clear(); + m_netMaskEdit->clear(); + m_gateWayEdit->clear(); + setManualEnabled(false); + } else if (index == MANUAL_CONFIG) { + setManualEnabled(true); + } +} diff --git a/src-vpn/frontend/vpndetails/vpnipv6page.h b/src-vpn/frontend/vpndetails/vpnipv6page.h new file mode 100644 index 00000000..21debab3 --- /dev/null +++ b/src-vpn/frontend/vpndetails/vpnipv6page.h @@ -0,0 +1,57 @@ +#ifndef VPNIPV6PAGE_H +#define VPNIPV6PAGE_H + +#include +#include +#include +#include +#include +#include + +#include "kyvpnconnectoperation.h" + +class VpnIpv6Page : public QFrame +{ + Q_OBJECT +public: + VpnIpv6Page(QWidget *parent = nullptr); + ~VpnIpv6Page() = default; + + void setVpnIpv6Info(const KyVpnConfig &vpnInfo); + void setDns(const QString &firstDns); + void setSearchDomain(const QString &searchDomain); + bool checkIsChanged(const KyVpnConfig &vpnInfo); + + void updateVpnIpv6Info(KyVpnConfig &vpnInfo); + +private: + QLabel *m_configLabel; + QLabel *m_addressLabel; + QLabel *m_maskLabel; + QLabel *m_gateWayLabel; + QLabel *m_dnsServerLabel; + QLabel *m_searchDomainLabel; + + QComboBox *m_ipv6ConfigCombox; + QLineEdit *m_ipv6addressEdit; + QLineEdit *m_netMaskEdit; + QLineEdit *m_gateWayEdit; + QLineEdit *m_dnsServerEdit; + QLineEdit *m_searchDomainEdit; + + void initUI(); + void initConnect(); + void setManualEnabled(bool state); + + bool getIpv6EditState(QString text); + bool checkConfirmBtnIsEnabled(); + +private Q_SLOTS: + void setEnableOfConfirmBtn(); + void onConfigChanged(int index); + +Q_SIGNALS: + void setIpv6PageState(bool); +}; + +#endif // VPNIPV6PAGE_H From e46ba714e124b095f74c2d634eece0127465c58d Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Mon, 10 Apr 2023 17:39:08 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=89=98=E7=9B=98ui=E5=BE=AE=E8=B0=83=20?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/vpn/translations/zh_CN.qm | Bin 0 -> 594 bytes src-vpn/frontend/single-pages/singlepage.h | 2 +- src-vpn/frontend/single-pages/vpnpage.cpp | 42 +++++++------------ src-vpn/frontend/single-pages/vpnpage.h | 2 +- src-vpn/translations/kylin-vpn_bo_CN.qm | 1 + src-vpn/translations/kylin-vpn_bo_CN.ts | 45 ++++++++++----------- src-vpn/translations/kylin-vpn_zh_CN.qm | Bin 0 -> 11091 bytes src-vpn/translations/kylin-vpn_zh_CN.ts | 45 ++++++++++----------- 8 files changed, 60 insertions(+), 77 deletions(-) create mode 100644 plugins/vpn/translations/zh_CN.qm create mode 100644 src-vpn/translations/kylin-vpn_bo_CN.qm create mode 100644 src-vpn/translations/kylin-vpn_zh_CN.qm diff --git a/plugins/vpn/translations/zh_CN.qm b/plugins/vpn/translations/zh_CN.qm new file mode 100644 index 0000000000000000000000000000000000000000..56074df7001ff23cc82b4642556a596316b3c298 GIT binary patch literal 594 zcmcE7ks@*G{hX<16=n7(EZlq7iGhJ3fq@~~4@mE3V2I5F($|=D5412aFq*Nf(OC+l zJ6OFBTmg!IWX+rQ8Avm*vy@E%ic7FBi`4^iL%9-vn*jOixKh2J0O>>?c}69mcniPK z&)Gm)BNHfigZV!YZ~(asY(UKAn3AI4Uy_kpRLlP5i+b`Q-}vc?uzk#o0-TMIg=0Kts@+#2gmjhf@k-B}5lcJ6r6h{(H$w z;Z|@a=jY|6CYPk9;4pzLGq)hWs01MkG9+CK#Sq@S{1OE$1_70_peST_hS&x&jUDI_ oP(XmgfF(#_S_<4zY%ZxesU@kHs#4d+Gr(1GxnveYEk#iY0QPo`1^@s6 literal 0 HcmV?d00001 diff --git a/src-vpn/frontend/single-pages/singlepage.h b/src-vpn/frontend/single-pages/singlepage.h index c822c4f4..2855b96b 100644 --- a/src-vpn/frontend/single-pages/singlepage.h +++ b/src-vpn/frontend/single-pages/singlepage.h @@ -43,7 +43,7 @@ using namespace kdk; #define MAIN_LAYOUT_SPACING 0 #define TITLE_FRAME_HEIGHT 60 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度 #define TITLE_LAYOUT_MARGINS 24,0,24,0 -#define NET_LAYOUT_MARGINS 8,8,8,8 +#define NET_LAYOUT_MARGINS 8,8,0,8 #define TEXT_HEIGHT 20 #define SETTINGS_LAYOUT_MARGINS 23,0,24,0 diff --git a/src-vpn/frontend/single-pages/vpnpage.cpp b/src-vpn/frontend/single-pages/vpnpage.cpp index 41c8cb70..e2cb274b 100644 --- a/src-vpn/frontend/single-pages/vpnpage.cpp +++ b/src-vpn/frontend/single-pages/vpnpage.cpp @@ -147,11 +147,7 @@ void VpnPage::constructItemArea() } } - if (m_listWidget->count() <= MAX_ITEMS) { - m_listFrame->setFixedWidth(MIN_WIDTH); - } else { - m_listFrame->setFixedWidth(MAX_WIDTH); - } + resetListWidgetWidth(); } void VpnPage::initVpnArea() @@ -174,14 +170,6 @@ void VpnPage::resetPageHeight() m_listFrame->show(); m_netDivider->show(); } - - for (int i = 0; i < m_mainLayout->count(); i ++) { - QWidget *w = m_mainLayout->itemAt(i)->widget(); - if (w != nullptr && w->isHidden() != true) { - height += w->height(); - } - } - this->setFixedHeight(height + PAGE_SPACE); } bool VpnPage::removeConnectionItem(QMap &connectMap, @@ -203,9 +191,7 @@ bool VpnPage::removeConnectionItem(QMap &connectMap, p_listWidgetItem = nullptr; iter = connectMap.erase(iter); - if (m_listWidget->count() <= MAX_ITEMS) { - m_listFrame->setFixedWidth(MIN_WIDTH); - } + resetListWidgetWidth(); return true; } } @@ -249,9 +235,7 @@ void VpnPage::onAddConnection(QString uuid) //新增一个有线 delete p_newItem; p_newItem = nullptr; - if (m_listWidget->count() >= MAX_ITEMS) { - m_listFrame->setFixedWidth(MAX_WIDTH); - } + resetListWidgetWidth(); resetPageHeight(); resetWindowPosition(); this->update(); @@ -338,9 +322,8 @@ void VpnPage::updateActivatedConnectionArea(KyConnectItem *p_newItem) deleteConnectionMapItem(m_activeItemMap, m_listWidget, p_newItem->m_connectUuid); QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_listWidget); m_activeItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); - if (m_listWidget->count() <= MAX_ITEMS) { - m_listFrame->setFixedWidth(MIN_WIDTH); - } + + resetListWidgetWidth(); return; } @@ -356,11 +339,7 @@ void VpnPage::updateConnectionArea(KyConnectItem *p_newItem) QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget); m_vpnItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); - if (m_listWidget->count() <= MAX_ITEMS) { - m_listFrame->setFixedWidth(MIN_WIDTH); - } else { - m_listFrame->setFixedWidth(MAX_WIDTH); - } + resetListWidgetWidth(); } void VpnPage::updateConnectionState(QMap &connectMap, @@ -700,3 +679,12 @@ void VpnPage::resetWindowPosition() kdk::WindowManager::setGeometry(this->windowHandle(), rect); qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__; } + +void VpnPage::resetListWidgetWidth() +{ + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); + } else { + m_listFrame->setFixedWidth(MAX_WIDTH); + } +} diff --git a/src-vpn/frontend/single-pages/vpnpage.h b/src-vpn/frontend/single-pages/vpnpage.h index 0b7dec31..e5748723 100644 --- a/src-vpn/frontend/single-pages/vpnpage.h +++ b/src-vpn/frontend/single-pages/vpnpage.h @@ -97,7 +97,7 @@ private: QListWidget *vpnListWidget, QString uuid); void resetWindowPosition(); - + void resetListWidgetWidth(); Q_SIGNALS: void vpnAdd(QStringList info); diff --git a/src-vpn/translations/kylin-vpn_bo_CN.qm b/src-vpn/translations/kylin-vpn_bo_CN.qm new file mode 100644 index 00000000..be651eed --- /dev/null +++ b/src-vpn/translations/kylin-vpn_bo_CN.qm @@ -0,0 +1 @@ +VPN Server + + + VPN + + + + + Auto Connection + + + + + Confirm + + + + + Cancel + +
vpnConfigPage @@ -90,7 +110,7 @@ - vpnDetail + VpnDetail @@ -113,29 +133,6 @@ - - vpnDetailPage - - - VPN - - - - - Auto Connection - - - - - Confirm - - - - - Cancel - - - vpnObject diff --git a/src-vpn/translations/kylin-vpn_zh_CN.qm b/src-vpn/translations/kylin-vpn_zh_CN.qm new file mode 100644 index 0000000000000000000000000000000000000000..75c3ce3eeb33b3c82c7d390a8ecdccbfec254f57 GIT binary patch literal 11091 zcmbU{3v?6LmCtx2jmDDv!GQTcFvN!PF%$@pY+56m;04LDM}|<7z*ri|6H7D7%*a@f zhR{G7R%|fg8#bGUG&D)+a+0Q-EoqhwJwV!IY15OiX}4|uX;V(l!X_mINb0?B#u{mm zMs^ksj6V0?cmKbqn|~UvdF8?*`_4|8@E;ov|N9@8Aw<1~kgXLV`Yb}7euVJX_2;y| z*Pqi{5%p^dV74Rb&wCM?d;y;O0j?6+nvVe9VPspe5TUW(N4C|?@cxqi9D5eodI8?~ zGP1qIBQ)tK^7_vqRP`a+{?`_SM%SUIKK~FQ=Ajb%vnhn8%+;S$PnA^sn+>6gGbNFJ zC%{EZP7^xJ)RO;fdKk{#qCckwOFsVSb>RQK5wl-<0-k{)G%eBVI0jXY3M$s@2jzZQO=XO#{`rWC47CjN^<7eRP`l={KDwQ$}w>iPC7 zfd2{geE3n&i%h+`_*IbaW&K&Zj{0Dt2lTL=`gq|+gr;7D=K=UWLS1y<0(6#A7q`Io zw2QiO@C}42C)sS??Fdc3%Vs+b`kQ{vw&=$xpns=rap&ED_s{yXcD^k-aV$ck?z0_u z7i>EAX4}E?hd}Nt`g7`owufi@9Pl5vJ-lZW;7_+b@(8?lHQAo_eTvY;`L^@pKyMYz zc6!W%2zmZwANjQ};QXK1M>SnW$lY&GxIv%J@7nKu`ez8)Ywa(5@d4;3ZU5!Y9iYFX z4##sl5xQZCV(Vg!DUqSsjb%x`a4PXyv zhvUcJs0aAl9nZ;=fd5O5FB<{B%1tj0b%0zRdbR5q;J46+Km8k=W2b-kKAb=Pd-SP4 z0Ns&)reAsL6zHF)-}u1`pvT|SZ>E7C&rJHg2Ty>#C({?-1%I0GEoViE0{$X6M=b`t z@-LiUdk)@ve&l3t=mdQ{;|$$IfxlKdBa#T;*E#R{&;#T)ak}Ugpvy@Q2EtvKxKC zw@cNZ6W=WBNPZpUA6*vuIXp|9Wy#n55VuRq?mGzQPdZn&?G5lx=2vAu+BXB>_Llv^ z2l|@)4c9G;_d=Zg&~<-D67;;%wbKoJPNekb^l7e#XMG>^eAe}oR~JHj)w+I0^oQoV z-a7g>(CbDwv$Y%ar?}^w06k6lOn=s<-FN->KLGrT?o+?G8TfeCLp=t5F+T38tO32C z+dZ}GZ-LL>DG#gyJi4R2=b2xD{$40oUI#f#D$5@u`m9KoKe=)b=<%cSW6R+C$%6iz z_D|){{LTjQtSkR`-VuO*wEW@+_rUXY0h~i9g%cRG8U>L5_7B@O((o49;h%G5Dkg|{ zb-?c+5Ue0ZV|;*%@+Aa=N}t#w8n86Wt118}g+QxNFG?VBw{MHsz3M<$=(W^R0}=OV zhx8^y%q0>rUd3Tv=~1Nwj`NBFhZQ17qj_jPTHNY0$T;TBUp%`@PziMT>V()B?&ZV~ zA2!&vqXnoT2f@Cep(y-<&=K~{D8Kc*|5|Iunuays9H7y16hji?kUHSJ{geK2yIy|q zsQ=4DJJTn7xABRP$l45c7B+@Ld_u)sQtjqNRS0n^AI1qT)WfR^j>u9Rb7Bf};jj!+ z;`-$=iBo4-GEe!hapeYacVjGu8+$n+#&yLs{S=hg)7F^&DO!eD)WoK@%rMZ$0lKsi zFJqfKR42;%jH6b2FK>j4?K{e5wq|n$jfV+7v%*(^#lSx03KFJ?nUp_F-khi)qYXp!H`=l_x)KXGv>-qMl3|uGR zN^uShXo=tg=2xIb6d*?%h$Fo#8UwlJFQ#3p-`VvS1J&;BmL$d6uJ+EyyKdZcAqPGt zfR9-+$Pm3=r;|!=*62ei_j+A|id#AL(|a&lrexO_Err;$B`B zA}Ji=WmSl1VS$A(i4g5gF(ommIZw+~&BIr6Rd8;ye(U+pL;jY|Gkqm@TumP{n48)x zl2F2-qypxKI8~I5k{rfLG8*L-71+}9TH!ETzqEZ3>Of5>u&(5R(+174&0<87Lp<(i z3SeFgaS0_E15YXvWmG?EyJ`@in){06GwP1TJ5Cv}j$3(=m${gwSzO?wKG2`n?4>Jw zjb3by4@(l&s0B(yFIt2!QXvP3yWR>NF*tCy1bP=?H7R1K89kOnJZ)F^jpaY%-`OA7 zeKvj0Kp)d0Mg&n%c`Wm)oWc;NyevzyB_Vp(o;JR1d*^Y3gu6vdBvnWgqFO8*=*}~H zkMPHXm084l5P1IA-~19OS^Pu!*ntv8;7beM}pC0S6rEqFR8elzbgq|6Skyp z?{^+de*o)TRsU`v#X(K$5NN0_A^SwHvUGfGqV1ymg+V z2{_4|28xHEq;Oy`TUx3?!@PU*nzVt*=$OG&!dm4FIWJk?bz{(N;0>PG!Sb@m#jSBY z`*%f`vZHtXVN;p^rf9a=9No@|VJQv~1!*QOLAL3Z6xCYhiuC2!vbOF0ACc5Ynm~h- z@x=I08la8Cf(W@6w?Mhq+c`@`P`l3t=Ncp&?SRh}Gf?M_wr&F)I_yvqA~$78-oEvG z|A;&G8W?Vtk40v4VNUZpOSB61H~l4A0tu{sD{@Ot7dwjO#V`&8pniqArA+&3Nyr{` zw;x`e<=75pf_iTW&*<90X4ek|WHOa+bD(MxVm=|?B6DgC!7b2w=^ZuHUqw^4H2f9WR zr|I1W1`?2nq6T*p*aROUy%Y~^0+wX(Xw98)0>&^)ox2F#f4q>K=V$f@3|dtgT5+xq z%TiJ;k_RdXg$y^r?&xHL%BTz#!U05u3g$1;lFMF#V=1*5}6^oUe8MI)p=F&0IY*Q(!1l-wKhbh*f83ahFH3at%0?kH^wPd`i zbxX3IxI3B~da`|yY2KOKq3{{6pX-GlMwVj38hKoVD9KMIa#e&Jq@>{tcOF6^>Xe_~ zP+}5m457iQFuF#Pv78>lQa+84-tCxr!)ii^)4Chz&cvbmEW(aSm~w(Y97$>js@~)4 z9eKN5zIAQgx@_YxK_jKN`J^$A$eiA0DNqzF1=9?t)7{e6rkIMXrlrBbAqu+M$faw)I7C|A{4X?LGxTRWET`|JK}_MehNN`~nmDyf1teheL%)3Sv3 zKiSWc&Xw(G^S0t$d$is)h&pn5*M^*fp#K;7n9;)qWlmJ$g0@@09nj&{`+^-s8d=Tq zt?6TH-X``ZA{j9@lbn)}B~=PRU_=By7S44EoFky687C0>?Y;wDWJ29^VSv_)$bgfS z5#yxAO7KRwhN*Z?CW@v z=nbtb89XMzL$6avdMqj=hmxKSD_UtH<9)GYTGc1EJJx6{@v46&DF?=JQwEPCb|C8k z8Hf%RhoNL-dVbwArT@$Hd;9*!AUCE_>B)}ud@m0prYh(iq#M?SkZ>bH)L0hMq&|?9 zi9ukbc}UiFCd5#MkU@`)CXe!X8*#S2XlbSZ9+?swd6+L@zOF|z(Hvp}6o+@@by%~F z{yL$pKlRrk&0?9?#C{o=28;Ib^8@ujkE&|3k7${?|W= z^l33#fJYCJ3vz%~fOB#{MUHs&Pz|l{8G?`IrcUn7ZVtxe;LZ)mLN6py49U+zy)`-s za90I&quH>IjDl)Jq#Cvwl}k`jx@W@{S>KNpkjQfPRshyT_H=pH9i#8-pumBOL4%pa zmIePBkppWtl#t|a@I2BWLJF=BDxv_502z!-J~q}M0O<>sr9<*T6Jbn-s5VF>hO`2s z55%TT~3lYkv|Ze+~JY;m;E zAXT?efF!Jg!WEshrXg=aq*qBHm>XIG7Sh|19|hOEZFqpwAH+?tYZkOEd;z&BQ|+Mq zg9C5@$PtD18U^5X#y;X;Q;wLm--$j#YNP-D%yMkN)p_6g(+4*PcaqOx{Lrq4HeKlb zoITqxA`6cvpm})WfQ$5d1b)X>0uP@y;E6h%-`yv69wMIx&--TvZXR%@FW(!y``U)5 zdbizu?Vh(cA6D(b+Zsj~ig*QfD==y;Wm+O63UD~HnZtsDlL{Z6g<;@{Ll1|$cq}Cn zl0x=|s-zWdxUGV&Da>n-b1=}Tn^%{`B=scQgX&a(Ca!C!(|}V_5_3>&MA+{rNqDib zTL^Vym}8RK5db?2!!;GBb)=#SlIz$e*)H zp#v>`>>b=`6|fX#3N$)*mNIBGch}!<$9ri%v>YDJpk-oW5gw8ZP`?ST($pn=auzr zyRRTYY$hm)u@oj$)owi|v?WUcs>58d6u`7cHr@Lr%Ngom*f{K}aEOz&eP;m-I`4;{`nKmm_W{Fscqr56v(Lsu1PJdu=#`TLwn&4%2KLt*r4*m9?Ckqhuk6Wt1%Vu#J*Mp-c&d#64NEWjtgR z^dl|MoajH>;s0elGF*>o5|mI8XnS;~iL{&CdkrG!7hl9dvIm$_OC~Ki0K{;L!5z>% literal 0 HcmV?d00001 diff --git a/src-vpn/translations/kylin-vpn_zh_CN.ts b/src-vpn/translations/kylin-vpn_zh_CN.ts index d0afe821..29c04c79 100644 --- a/src-vpn/translations/kylin-vpn_zh_CN.ts +++ b/src-vpn/translations/kylin-vpn_zh_CN.ts @@ -756,6 +756,26 @@ If key direction is used, it must be opposite to the VPN side used. If '1&a VPN Server 服务器地址 + + + VPN + + + + + Auto Connection + 自动连接 + + + + Confirm + 确定 + + + + Cancel + 取消 + vpnConfigPage @@ -765,7 +785,7 @@ If key direction is used, it must be opposite to the VPN side used. If '1&a - vpnDetail + VpnDetail @@ -804,29 +824,6 @@ If key direction is used, it must be opposite to the VPN side used. If '1&a 确定 - - vpnDetailPage - - - VPN - - - - - Auto Connection - 自动连接 - - - - Confirm - 确定 - - - - Cancel - 取消 - - vpnObject From 94c345dda8b5e04a5014ad0410d4be1eae18864a Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Mon, 10 Apr 2023 17:52:34 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5IPv4=20DNS=E5=88=97=E8=A1=A8=20tab=E9=80=82=E9=85=8D?= =?UTF-8?q?=E9=AB=98=E5=88=86=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/netdetails/detailpage.cpp | 2 +- src/frontend/netdetails/netdetail.cpp | 32 ++++++++++++++++++++++++-- src/frontend/netdetails/netdetail.h | 4 ++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/frontend/netdetails/detailpage.cpp b/src/frontend/netdetails/detailpage.cpp index 21517fb0..a80cc0e8 100644 --- a/src/frontend/netdetails/detailpage.cpp +++ b/src/frontend/netdetails/detailpage.cpp @@ -87,7 +87,7 @@ void DetailPage::setIpv4(const QString &ipv4) { } void DetailPage::setIpv4Dns(const QString &ipv4Dns) { - this->m_IPV4Dns->setText(ipv4Dns); + this->m_IPV4Dns->setLabelText(ipv4Dns); } void DetailPage::setIpv6(const QString &ipv6) { diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index 32cc3f89..c3df56fc 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -660,7 +660,7 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived) // conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType; conInfo.ipv6ConfigType = connetSetting.m_ipv6ConfigIpType; - conInfo.ipv4DnsList = connetSetting.m_ipv4Dns; +// conInfo.ipv4DnsList = connetSetting.m_ipv4Dns; conInfo.ipv6DnsList = connetSetting.m_ipv6Dns; conInfo.isAutoConnect = connetSetting.m_isAutoConnect; @@ -1196,7 +1196,26 @@ void NetDetail::setNetTabToolTip() NetTabBar::NetTabBar(QWidget *parent) :KTabBar(KTabBarStyle::SegmentDark, parent) { - + //模式切换 + QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), + QString("/"), + QString("com.kylin.statusmanager.interface"), + QString("mode_change_signal"), this, SLOT(onModeChanged(bool))); + //模式获取 + QDBusInterface interface(QString("com.kylin.statusmanager.interface"), + QString("/"), + QString("com.kylin.statusmanager.interface"), + QDBusConnection::sessionBus()); + if(!interface.isValid()) { + this->setFixedHeight(TAB_HEIGHT); + return; + } + QDBusReply reply = interface.call("get_current_tabletmode"); + if (!reply.isValid()) { + this->setFixedHeight(TAB_HEIGHT); + return; + } + onModeChanged(reply.value()); } NetTabBar::~NetTabBar() @@ -1219,6 +1238,15 @@ QSize NetTabBar::minimumTabSizeHint(int index) const return size; } +void NetTabBar::onModeChanged(bool mode) +{ + if (mode) { + this->setFixedHeight(TAB_HEIGHT_TABLET); // 平板模式 + } else { + this->setFixedHeight(TAB_HEIGHT); // PC模式 + } +} + ThreadObject::ThreadObject(QString deviceName, QObject *parent) :m_devName(deviceName), QObject(parent) diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index 1bdaadd4..567afcab 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -68,6 +68,10 @@ public: protected: QSize sizeHint() const; QSize minimumTabSizeHint(int index) const; + +private Q_SLOTS: + void onModeChanged(bool mode); + }; class ThreadObject : public QObject {