diff --git a/kylin-nm.pro b/kylin-nm.pro
index 7b52af76..eaf4ac69 100644
--- a/kylin-nm.pro
+++ b/kylin-nm.pro
@@ -1,14 +1,25 @@
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 \
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..858d85a9 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,35 +34,30 @@ 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);
+
+ QHBoxLayout *addLyt = new QHBoxLayout;
QLabel *iconLabel = new QLabel(this);
- textLabel = 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->setProperty("useIconHighlightEffect", true);
- iconLabel->setProperty("iconHighlightEffectMode", 1);
+ 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();
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..85876755 100644
--- a/plugins/component/AddBtn/addnetbtn.h
+++ b/plugins/component/AddBtn/addnetbtn.h
@@ -34,8 +34,8 @@ public:
AddNetBtn(bool isWlan, QWidget *parent = nullptr);
~AddNetBtn();
- void setTextLabel(QString str) {
- textLabel->setText(str);
+ void setTextLabel(const QString str) {
+ m_textLabel->setText(str);
}
protected:
@@ -44,7 +44,7 @@ protected:
void paintEvent(QPaintEvent *event);
private:
- QLabel* textLabel;
+ QLabel *m_textLabel;
Q_SIGNALS:
void enterWidget();
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/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
-
+
@@ -12,7 +12,7 @@
BlacklistPage
-
+
@@ -20,7 +20,7 @@
ConnectDevListItem
-
+
@@ -28,7 +28,7 @@
ConnectdevPage
-
+
@@ -56,79 +56,69 @@
MobileHotspotWidget
-
+
-
+
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
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
-
+
སྤོ་སྐྱོད་བྱས་པ།
@@ -12,7 +12,7 @@
BlacklistPage
-
+
སྒྲིག་ཆས་ཀྱི་མིང་ཐོ་ནག་པོ།
@@ -20,7 +20,7 @@
ConnectDevListItem
-
+
མིང་ཐོ་ནག་པོའི་ཁ་སྣོན་རྒྱག་པ།
@@ -28,7 +28,7 @@
ConnectdevPage
-
+
འབྲེལ་མཐུད་སྒྲིག་ཆས།
@@ -56,27 +56,26 @@
MobileHotspotWidget
-
+
ཝུའུ་ཁི་ལན་གྱི་ཚོད་འཛིན་ལྟེ་གནས།
-
+
ukui ཚོད་འཛིན་ལྟེ་གནས་ཀྱི་ཅོག་ངོས་ཆ་འཕྲིན།
-
+
སྐུད་མེད་གློག་སྒོ་རྒྱག་པའམ་ཡང་ན་སྐུད་མེད་སྒྲིག་ཆས་མེད་པ།
-
- སྒོ་རྒྱག་འགོ་བརྩམས།
+ སྒོ་རྒྱག་འགོ་བརྩམས།
-
+
ཚ་བ་ཆེ་བའི་མིང་ངམ་སྒྲིག་ཆས་ལ་ནུས་པ་མེད།
@@ -85,54 +84,53 @@
གསང་གྲངས་ཀྱི་རིང་ཚད་ནི་གླེང་མང་བའི་གནད་དོན་བརྒྱད་ལས་ཆུང་བ་བྱེད་མི་རུང་།!
-
- ཀུན་གྱིས་དོ་སྣང་བྱེད་ཡུལ་གསར་སྐྲུན་བྱེད་འགོ་
+ ཀུན་གྱིས་དོ་སྣང་བྱེད་ཡུལ་གསར་སྐྲུན་བྱེད་འགོ་
-
+
མ་མཐར་ཡང་ཡིག་རྟགས་བརྒྱད་འདུས་ཡོད།
-
+
ཚ་བ་ཆེ་བ།
-
-
+
+
ཚ་བ་ཆེ་བའི་གནད་དོན་ཐག་ཉེ་རུ་སོང་ཡོད།
-
+
སྒོ་ཕྱེ་བ།
-
+
Wi-Fiཡི་མིང་།
-
+
གསང་གྲངས།
-
+
ཐེངས་གྲངས་ཀྱི་རོལ་ཆའི་རུ་ཁག
-
+
དྲ་རྒྱའི་བྱང་བུ།
-
-
+
+
ཚ་བ་ཆེ་བའི་གནད་དོན་དེ་སྒོ་ཕྱེ་ཟིན།
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
+
+
+
+ BlacklistPage
+
+
+
+ Blacklist
+
+
+
+ ConnectDevListItem
+
+
+
+ drag into blacklist
+
+
+
+ ConnectdevPage
+
+
+
+ Connect device
+
+
+
+ MobileHotspot
+
+
+
+ MobileHotspot
+
+
+
+
+ mobilehotspot
+ /mobilehotspot/mobilehotspot
+
+
+
+
+ mobilehotspot open
+ /mobilehotspot/mobilehotspot open
+
+
+
+ MobileHotspotWidget
+
+
+
+ ukui control center
+
+
+
+
+ ukui control center desktop message
+
+
+
+
+ wirless switch is close or no wireless device
+
+
+
+
+ hotpots name or device is invalid
+
+
+
+
+ Hotspot
+
+
+
+
+
+ hotspot already close
+
+
+
+
+ Open
+
+
+
+
+ Wi-Fi Name
+
+
+
+
+ Password
+
+
+
+
+ Contains at least 8 characters
+
+
+
+
+ Frequency band
+
+
+
+
+ Net card
+
+
+
+
+
+ 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
-
+
@@ -12,7 +12,7 @@
BlacklistPage
-
+
@@ -20,7 +20,7 @@
ConnectDevListItem
-
+
@@ -28,7 +28,7 @@
ConnectdevPage
-
+
@@ -56,79 +56,69 @@
MobileHotspotWidget
-
+
-
+
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
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
-
+
移出
@@ -12,7 +12,7 @@
BlacklistPage
-
+
设备黑名单
@@ -20,7 +20,7 @@
ConnectDevListItem
-
+
添加进黑名单
@@ -28,7 +28,7 @@
ConnectdevPage
-
+
连接设备
@@ -56,27 +56,26 @@
MobileHotspotWidget
-
+
控制面板
-
+
控制面板桌面通知
-
+
无线开关已关闭或不存在有热点功能的无线网卡
-
- 开始关闭热点
+ 开始关闭热点
-
+
热点名称或设备错误
@@ -85,54 +84,53 @@
不能创建密码长度小于八位的热点!
-
- 开始创建热点
+ 开始创建热点
-
+
至少包含8个字符
-
+
移动热点
-
-
+
+
热点已关闭
-
+
开启
-
+
Wi-Fi名称
-
+
网络密码
-
+
网络频带
-
+
共享网卡端口
-
-
+
+
热点已开启
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 ad0aad0c..70a845c8 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,6 +41,7 @@ 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);
@@ -79,7 +77,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);
@@ -90,6 +87,8 @@ LanItem::~LanItem()
}
+
+
void LanItem::updateIcon()
{
if (currentIconIndex > 6) {
@@ -146,12 +145,17 @@ void LanItem::onDeletetTriggered()
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();
diff --git a/plugins/netconnect/netconnect.cpp b/plugins/netconnect/netconnect.cpp
index 21fbe697..fe8ae7b2 100644
--- a/plugins/netconnect/netconnect.cpp
+++ b/plugins/netconnect/netconnect.cpp
@@ -81,7 +81,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 +153,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 +171,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 +247,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__;
@@ -352,13 +354,6 @@ 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)
{
@@ -367,8 +362,19 @@ void NetConnect::deleteOneLan(QString ssid, int type)
qDebug() << "[NetConnect]call deleteConnect respond" << __LINE__;
}
+void NetConnect::runExternalApp() {
+ if (!LaunchApp("nm-connection-editor.desktop")){
+ 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 +382,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 +398,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__;
@@ -454,7 +463,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__;
@@ -474,13 +483,13 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL
});
connect(lanItem, &LanItem::connectActionTriggered, this, [=] {
- activeConnect(lanItem->uuid, devName, WIRED_TYPE);
+ activeConnect(lanItem->uuid, devName, WIRED_TYPE);
});
connect(lanItem, &LanItem::disconnectActionTriggered, this, [=] {
- deActiveConnect(lanItem->uuid, devName, WIRED_TYPE);
+ deActiveConnect(lanItem->uuid, devName, WIRED_TYPE);
});
connect(lanItem, &LanItem::deleteActionTriggered, this, [=] {
- deleteOneLan(lanItem->uuid, WIRED_TYPE);
+ deleteOneLan(lanItem->uuid, WIRED_TYPE);
});
//记录到deviceFrame的itemMap中
@@ -492,6 +501,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 +550,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__;
@@ -746,7 +760,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__;
@@ -766,13 +780,13 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis
});
connect(lanItem, &LanItem::connectActionTriggered, this, [=] {
- activeConnect(lanItem->uuid, deviceName, WIRED_TYPE);
+ activeConnect(lanItem->uuid, deviceName, WIRED_TYPE);
});
connect(lanItem, &LanItem::disconnectActionTriggered, this, [=] {
- deActiveConnect(lanItem->uuid, deviceName, WIRED_TYPE);
+ deActiveConnect(lanItem->uuid, deviceName, WIRED_TYPE);
});
connect(lanItem, &LanItem::deleteActionTriggered, this, [=] {
- deleteOneLan(lanItem->uuid, WIRED_TYPE);
+ deleteOneLan(lanItem->uuid, WIRED_TYPE);
});
//记录到deviceFrame的itemMap中
@@ -901,7 +915,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__;
diff --git a/plugins/netconnect/netconnect.h b/plugins/netconnect/netconnect.h
index 99ce6855..e8858614 100644
--- a/plugins/netconnect/netconnect.h
+++ b/plugins/netconnect/netconnect.h
@@ -153,7 +153,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..9841010e 100644
--- a/plugins/netconnect/translations/bo.ts
+++ b/plugins/netconnect/translations/bo.ts
@@ -4,61 +4,93 @@
AddNetBtn
-
+
+
+
+
+
+
+
+ LanItem
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
NetConnect
-
-
+
/netconnect/open
-
+
/netconnect/Advanced settings"
-
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
diff --git a/plugins/netconnect/translations/bo_CN.qm b/plugins/netconnect/translations/bo_CN.qm
index 22c45a00..f41e3534 100644
Binary files a/plugins/netconnect/translations/bo_CN.qm and b/plugins/netconnect/translations/bo_CN.qm differ
diff --git a/plugins/netconnect/translations/bo_CN.ts b/plugins/netconnect/translations/bo_CN.ts
index 897b2285..895a44e9 100644
--- a/plugins/netconnect/translations/bo_CN.ts
+++ b/plugins/netconnect/translations/bo_CN.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
- དྲ་རྒྱ་གཞན་དག་ལ་ཞུགས་།
+
-
+
སྐུད་ཡོད་བརྙན་འཕྲིན་ཁ་སྣོན་བྱས་ཡོད།
@@ -17,81 +17,86 @@
LanItem
-
+
- མེད་པར་བཟོ་བ་
+ སུབ་དགོས།
-
-
+
+
- གཅོད་པ་
+ བར་མཚམས་ཆད་པ་རེད།
-
-
+
+
- སྦྲེལ་བ་
+ འབྲེལ་མཐུད་བཅས་བྱ་དགོས།
NetConnect
-
སྐུད་ཡོད་བརྙན་འཕྲིན་དྲ་བ།
-
+
སྒོ་ཕྱེ་བ།
/netconnect/open
-
+
སྔོན་ཐོན་གྱི་སྒྲིག་བཀོད།
/netconnect/Advanced settings"
-
+
ཝུའུ་ཁི་ལན་གྱི་ཚོད་འཛིན་ལྟེ་གནས།
-
+
ukui ཚོད་འཛིན་ལྟེ་གནས་ཀྱི་ཅོག་ངོས་ཆ་འཕྲིན།
-
- སྐུད་ཡོད་སྦྲེལ་མཐུད།
+ སྐུད་ཡོད་སྦྲེལ་མཐུད།
-
+
+
+
+ སྐུད་ཡོད་དྲ་བ།
+
+
+
ཨེ་ཙི་དྲ་རྒྱའི་སྒྲིག་ཆས་ལ་བཙན་འཛུལ་བྱས་མི་ཆོག།
-
-
+
+
འབྲེལ་མཐུད་བྱེད་པ།
-
+
+
+
+
+ འབྲེལ་མཐུད་མ་བྱས་པ།
+
+
+
བྱང་བུ།
-
-
-
-
- མ་སྦྲེལ་བ་
-
diff --git a/plugins/netconnect/translations/en_US.ts b/plugins/netconnect/translations/en_US.ts
new file mode 100644
index 00000000..67be9443
--- /dev/null
+++ b/plugins/netconnect/translations/en_US.ts
@@ -0,0 +1,98 @@
+
+
+
+
+ AddNetBtn
+
+
+
+ Add Others
+
+
+
+
+ Add WiredNetork
+
+
+
+ LanItem
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NetConnect
+
+
+
+ Wired Network
+
+
+
+
+
+ open
+ /netconnect/open
+
+
+
+
+
+ Advanced settings
+ /netconnect/Advanced settings"
+
+
+
+
+ ukui control center
+
+
+
+
+ ukui control center desktop message
+
+
+
+
+
+ LAN
+
+
+
+
+ No ethernet device avaliable
+
+
+
+
+
+ connected
+
+
+
+
+
+
+
+
+
+
+
+ card
+
+
+
diff --git a/plugins/netconnect/translations/tr.ts b/plugins/netconnect/translations/tr.ts
index 16910853..9841010e 100644
--- a/plugins/netconnect/translations/tr.ts
+++ b/plugins/netconnect/translations/tr.ts
@@ -4,61 +4,93 @@
AddNetBtn
-
+
+
+
+
+
+
+
+ LanItem
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
NetConnect
-
-
+
/netconnect/open
-
+
/netconnect/Advanced settings"
-
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
diff --git a/plugins/netconnect/translations/zh_CN.qm b/plugins/netconnect/translations/zh_CN.qm
index 93f01012..6ac7d043 100644
Binary files a/plugins/netconnect/translations/zh_CN.qm and b/plugins/netconnect/translations/zh_CN.qm differ
diff --git a/plugins/netconnect/translations/zh_CN.ts b/plugins/netconnect/translations/zh_CN.ts
index e23bdd27..da195eef 100644
--- a/plugins/netconnect/translations/zh_CN.ts
+++ b/plugins/netconnect/translations/zh_CN.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
- 加入其它网络
+
-
+
添加有线网络
@@ -17,19 +17,19 @@
LanItem
-
+
删除
-
-
+
+
断开
-
-
+
+
连接
@@ -38,60 +38,65 @@
NetConnect
-
有线网络
-
+
开启
/netconnect/open
-
+
高级设置
/netconnect/Advanced settings"
-
+
控制面板
-
+
控制面板桌面通知
-
+ 有线网络
+
+
+
+
+
有线网络
-
+
未检测到有线设备
-
-
+
+
已连接
-
-
- 网卡
-
-
-
-
+
+
+
未连接
+
+
+
+ 网卡
+
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/vpn/itemframe.cpp b/plugins/vpn/itemframe.cpp
index 816828f7..29b6bf9c 100644
--- a/plugins/vpn/itemframe.cpp
+++ b/plugins/vpn/itemframe.cpp
@@ -25,36 +25,36 @@
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);
+ 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);
- lanItemLayout = new QVBoxLayout(this);
- lanItemLayout->setContentsMargins(LAYOUT_MARGINS);
- lanItemLayout->setSpacing(1);
- addWlanWidget = new AddNetBtn(false, this);
- addWlanWidget->setTextLabel(tr("Add Vpn"));
+ 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"));
- deviceLanLayout->setSpacing(1);
- setLayout(deviceLanLayout);
- lanItemFrame->setLayout(lanItemLayout);
+ m_mainVLayout->setSpacing(1);
+ setLayout(m_mainVLayout);
+ m_vpnFrame->setLayout(m_vpnVLayout);
- deviceLanLayout->addWidget(lanItemFrame);
- deviceLanLayout->addWidget(addWlanWidget);
+ m_mainVLayout->addWidget(m_vpnFrame);
+ m_mainVLayout->addWidget(m_addVpnWidget);
}
void ItemFrame::filletStyleChange()
{
- if (lanItemLayout->isEmpty()) {
+ if (m_vpnVLayout->isEmpty()) {
return;
}
- for (int i = 0; i < lanItemLayout->count(); ++i) {
- QLayoutItem *it = lanItemLayout->itemAt(i);
+ for (int i = 0; i < m_vpnVLayout->count(); ++i) {
+ QLayoutItem *it = m_vpnVLayout->itemAt(i);
VpnItem *itemFrame = (VpnItem*)(it->widget());
- if (i != lanItemLayout->count()-1) {
+ 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
index b41153fa..18595863 100644
--- a/plugins/vpn/itemframe.h
+++ b/plugins/vpn/itemframe.h
@@ -29,18 +29,18 @@ class ItemFrame : public QFrame
Q_OBJECT
public:
ItemFrame(QWidget *parent = nullptr);
- //单设备整体layout
- QVBoxLayout * deviceLanLayout = nullptr;
- //单设备列表Frame
- QFrame * lanItemFrame = nullptr;
+ //VPN整体layout
+ QVBoxLayout * m_mainVLayout = nullptr;
+ //vpn列表Frame
+ QFrame * m_vpnFrame = nullptr;
//单设备列表layout
- QVBoxLayout * lanItemLayout = nullptr;
+ QVBoxLayout * m_vpnVLayout = nullptr;
//item列表
- QMap itemMap;
+ QMap m_itemMap;
// //已激活uuid
// QString uuid = "";
//新建无线连接
- AddNetBtn * addWlanWidget = nullptr;
+ AddNetBtn * m_addVpnWidget = nullptr;
void filletStyleChange();
};
diff --git a/plugins/vpn/vpn.cpp b/plugins/vpn/vpn.cpp
index f4c13273..a453263d 100644
--- a/plugins/vpn/vpn.cpp
+++ b/plugins/vpn/vpn.cpp
@@ -59,19 +59,19 @@
const QString VISIBLE = "visible";
const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.vpnicon";
-Vpn::Vpn() : mFirstLoad(true)
+Vpn::Vpn() : m_firstLoad(true)
{
QTranslator* translator = new QTranslator(this);
translator->load("/usr/share/kylin-nm/vpn/" + QLocale::system().name());
QApplication::installTranslator(translator);
- pluginName = tr("Vpn");
- pluginType = NETWORK;
+ m_pluginName = tr("Vpn");
+ m_pluginType = NETWORK;
}
Vpn::~Vpn()
{
- if (!mFirstLoad) {
+ if (!m_firstLoad) {
delete ui;
ui = nullptr;
delete m_interface;
@@ -80,25 +80,25 @@ Vpn::~Vpn()
}
QString Vpn::plugini18nName(){
- return pluginName;
+ return m_pluginName;
}
int Vpn::pluginTypes(){
- return pluginType;
+ return m_pluginType;
}
QWidget *Vpn::pluginUi(){
- if (mFirstLoad) {
- mFirstLoad = false;
+ if (m_firstLoad) {
+ m_firstLoad = false;
ui = new Ui::Vpn;
- pluginWidget = new QWidget;
- pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
- ui->setupUi(pluginWidget);
+ m_pluginWidget = new QWidget;
+ m_pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
+ ui->setupUi(m_pluginWidget);
qDBusRegisterMetaType>();
- m_interface = new QDBusInterface("com.kylin.network",
- "/com/kylin/vpnTool",
- "com.kylin.vpnTool",
+ 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());
@@ -108,7 +108,7 @@ QWidget *Vpn::pluginUi(){
initConnect();
initNet();
}
- return pluginWidget;
+ return m_pluginWidget;
}
const QString Vpn::name() const {
@@ -134,12 +134,12 @@ bool Vpn::isEnable() const
void Vpn::initComponent(){
//在任务栏上显示图标
//显示已连接时间
- m_topFrame = new QFrame(pluginWidget);
+ 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(pluginWidget);
+ QVBoxLayout *hotspotLyt = new QVBoxLayout(m_pluginWidget);
hotspotLyt->setContentsMargins(0, 0, 0, 0);
m_topFrame->setLayout(hotspotLyt);
@@ -181,12 +181,12 @@ void Vpn::initComponent(){
hotspotLyt->setSpacing(0);
//列表
- m_listFrame = new ItemFrame(pluginWidget);
+ m_listFrame = new ItemFrame(m_pluginWidget);
ui->verticalLayout_4->addWidget(m_topFrame);
ui->verticalLayout_3->addWidget(m_listFrame);
- connect(m_listFrame->addWlanWidget, &AddNetBtn::clicked, this, [=]() {
+ connect(m_listFrame->m_addVpnWidget, &AddNetBtn::clicked, this, [=]() {
runExternalApp();
});
@@ -267,14 +267,18 @@ void Vpn::setShowSwitchStatus()
}
void Vpn::runExternalApp(){
- QString cmd = "nm-connection-editor";
- QProcess process(this);
- process.startDetached(cmd);
+// 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(pluginWidget);
+ QFrame *line = new QFrame(m_pluginWidget);
line->setMinimumSize(QSize(LINE_MIN_SIZE));
line->setMaximumSize(QSize(LINE_MAX_SIZE));
line->setLineWidth(0);
@@ -295,6 +299,11 @@ 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);
@@ -304,7 +313,12 @@ void Vpn::deActiveConnect(QString uuid) {
//增加一项
void Vpn::addOneVirtualItem(QStringList infoList)
{
- if (m_listFrame->itemMap.contains(infoList.at(1))) {
+ 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;
}
@@ -314,64 +328,55 @@ void Vpn::addOneVirtualItem(QStringList infoList)
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);
+ VpnItem * item = new VpnItem(m_pluginWidget);
QIcon searchIcon = QIcon::fromTheme(KVpnSymbolic);
- item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE))));
- item->titileLabel->setText(connName);
+ item->m_iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE))));
+ item->m_titileLabel->setText(connName);
- item->uuid = connUuid;
- item->dbusPath = connDbusPath;
+ item->m_uuid = connUuid;
+ item->m_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");
- }
+ connect(item->m_infoLabel, &GrayInfoButton::clicked, this, [=]{
+ showDetailPage(item->m_uuid);
});
- item->isAcitve = (status == 2);
- item->setConnectActionText(item->isAcitve);
+ item->m_isAcitve = (status == 2);
+ item->setConnectActionText(item->m_isAcitve);
- if (item->isAcitve) {
- item->statusLabel->setText(tr("connected"));
+ if (item->m_isAcitve) {
+ item->m_statusLabel->setText(tr("connected"));
} else {
- item->statusLabel->setText(tr("not connected"));
+ item->m_statusLabel->setText(tr("not connected"));
}
connect(item, &QPushButton::clicked, this, [=] {
- if (item->isAcitve || item->loading) {
- deActiveConnect(item->uuid);
+ if (item->m_isAcitve || item->m_loading) {
+ deActiveConnect(item->m_uuid);
} else {
- activeConnect(item->uuid);
+ activeConnect(item->m_uuid);
}
});
connect(item, &VpnItem::connectActionTriggered, this, [=] {
- activeConnect(item->uuid);
+ activeConnect(item->m_uuid);
});
connect(item, &VpnItem::disconnectActionTriggered, this, [=] {
- deActiveConnect(item->uuid);
+ deActiveConnect(item->m_uuid);
});
connect(item, &VpnItem::deleteActionTriggered, this, [=] {
- deleteVpn(item->uuid);
+ deleteVpn(item->m_uuid);
});
- //记录到deviceFrame的itemMap中
- m_listFrame->itemMap.insert(connUuid, item);
+ //记录到deviceFrame的m_itemMap中
+ m_listFrame->m_itemMap.insert(connUuid, item);
int index = getInsertPos(connName);
qDebug()<<"[Vpn]addOneVirtualItem " << connName << " at pos:" << index;
- m_listFrame->lanItemLayout->insertWidget(index, item);
+ m_listFrame->m_vpnVLayout->insertWidget(index, item);
}
void Vpn::removeOneVirtualItem(QString dbusPath)
@@ -379,13 +384,13 @@ 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();
+ 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->lanItemLayout->removeWidget(itemIter.value());
+ m_listFrame->m_vpnVLayout->removeWidget(itemIter.value());
delete itemIter.value();
- m_listFrame->itemMap.remove(key);
+ m_listFrame->m_itemMap.remove(key);
break;
}
}
@@ -398,18 +403,18 @@ void Vpn::onVpnAdd(QStringList infoList)
}
//移出
-void Vpn::onVpnRemove(QString uuid)
+void Vpn::onVpnRemove(QString path)
{
- removeOneVirtualItem(uuid);
+ removeOneVirtualItem(path);
}
//名称变化
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));
+ 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));
}
}
}
@@ -423,18 +428,18 @@ void Vpn::onVpnActiveConnectionStateChanged(QString uuid, int status)
qDebug() << "[Vpn]onActiveConnectionChanged " << uuid << status;
VpnItem * item= nullptr;
- if (m_listFrame->itemMap.contains(uuid)) {
- item = m_listFrame->itemMap[uuid];
+ if (m_listFrame->m_itemMap.contains(uuid)) {
+ item = m_listFrame->m_itemMap[uuid];
if (status == ACTIVATED) {
//为已连接则放到第一个
- m_listFrame->lanItemLayout->removeWidget(item);
- m_listFrame->lanItemLayout->insertWidget(0,item);
+ m_listFrame->m_vpnVLayout->removeWidget(item);
+ m_listFrame->m_vpnVLayout->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);
+ 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);
}
@@ -448,22 +453,22 @@ void Vpn::itemActiveConnectionStatusChanged(VpnItem *item, int status)
} 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;
+ 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->statusLabel->setMinimumSize(36,36);
- item->statusLabel->setMaximumSize(16777215,16777215);
- item->statusLabel->clear();
- item->isAcitve = false;
- item->statusLabel->setText(tr("not connected"));
+ 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->isAcitve);
+ item->setConnectActionText(item->m_isAcitve);
}
int Vpn::getInsertPos(QString connName)
diff --git a/plugins/vpn/vpn.h b/plugins/vpn/vpn.h
index 941f8f4f..82d89ea2 100644
--- a/plugins/vpn/vpn.h
+++ b/plugins/vpn/vpn.h
@@ -69,9 +69,9 @@ protected:
private:
Ui::Vpn *ui;
- QString pluginName;
- int pluginType;
- QWidget * pluginWidget;
+ QString m_pluginName;
+ int m_pluginType;
+ QWidget * m_pluginWidget;
QDBusInterface *m_interface = nullptr;
@@ -85,7 +85,7 @@ private:
KSwitchButton *m_timeBtn;
ItemFrame *m_listFrame;
- bool mFirstLoad;
+ bool m_firstLoad;
QGSettings *m_switchGsettings;
QFrame* myLine();
@@ -95,6 +95,7 @@ private:
void deleteVpn(QString uuid);
void activeConnect(QString uuid);
void deActiveConnect(QString uuid);
+ void showDetailPage(QString uuid);
//获取设备列表
void initNet();
diff --git a/plugins/vpn/vpnitem.cpp b/plugins/vpn/vpnitem.cpp
index 28ff57eb..ec287431 100644
--- a/plugins/vpn/vpnitem.cpp
+++ b/plugins/vpn/vpnitem.cpp
@@ -28,7 +28,7 @@
#define MODE_QT_KEY "style-name"
VpnItem::VpnItem(bool bAcitve, QWidget *parent)
- : isAcitve(bAcitve), QPushButton(parent)
+ : m_isAcitve(bAcitve), QPushButton(parent)
{
this->setMinimumSize(550, 58);
this->setProperty("useButtonPalette", true);
@@ -41,12 +41,12 @@ VpnItem::VpnItem(bool bAcitve, QWidget *parent)
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_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);
@@ -56,29 +56,29 @@ VpnItem::VpnItem(bool bAcitve, QWidget *parent)
m_moreMenu = new QMenu(m_moreButton);
m_connectAction = new QAction(m_moreMenu);
m_deleteAction = new QAction(tr("Delete"), m_moreMenu);
- setConnectActionText(isAcitve);
+ setConnectActionText(m_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->addWidget(m_iconLabel);
+ mLanLyt->addWidget(m_titileLabel,Qt::AlignLeft);
mLanLyt->addStretch();
- mLanLyt->addWidget(statusLabel);
- mLanLyt->addWidget(infoLabel);
+ mLanLyt->addWidget(m_statusLabel);
+ mLanLyt->addWidget(m_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"));
+ 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"));
- waitTimer = new QTimer(this);
- connect(waitTimer, &QTimer::timeout, this, &VpnItem::updateIcon);
+ 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);
@@ -87,22 +87,22 @@ VpnItem::VpnItem(bool bAcitve, QWidget *parent)
void VpnItem::updateIcon()
{
- if (currentIconIndex > 6) {
- currentIconIndex = 0;
+ if (m_currentIconIndex > 6) {
+ m_currentIconIndex = 0;
}
- statusLabel->setPixmap(loadIcons.at(currentIconIndex).pixmap(16,16));
- currentIconIndex ++;
+ m_statusLabel->setPixmap(m_loadIcons.at(m_currentIconIndex).pixmap(16,16));
+ m_currentIconIndex ++;
}
void VpnItem::startLoading()
{
- waitTimer->start(FRAME_SPEED);
- loading = true;
+ m_waitTimer->start(FRAME_SPEED);
+ m_loading = true;
}
void VpnItem::stopLoading(){
- waitTimer->stop();
- loading = false;
+ m_waitTimer->stop();
+ m_loading = false;
}
void VpnItem::setConnectActionText(bool isAcitve)
@@ -146,7 +146,7 @@ void VpnItem::paintEvent(QPaintEvent *event)
QRect rect = this->rect();
#if 0
- if (!useHalfFillet) {
+ if (!m_useHalfFillet) {
painter.drawRect(rect);
} else {
QPainterPath path;
diff --git a/plugins/vpn/vpnitem.h b/plugins/vpn/vpnitem.h
index 6947d60f..bbe8a3ec 100644
--- a/plugins/vpn/vpnitem.h
+++ b/plugins/vpn/vpnitem.h
@@ -41,37 +41,36 @@ class VpnItem : public QPushButton
public:
VpnItem(bool bAcitve, QWidget *parent = nullptr);
public:
- QLabel * iconLabel = nullptr;
- GrayInfoButton * infoLabel = nullptr;
- FixLabel * titileLabel = nullptr;
- QLabel * statusLabel = nullptr;
+ 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 uuid = "";
- QString dbusPath = "";
+ QString m_uuid = "";
+ QString m_dbusPath = "";
- void setHalfFillet(bool flag) {useHalfFillet = flag; repaint();}
+ void setHalfFillet(bool flag) {m_useHalfFillet = flag; repaint();}
public:
void startLoading();
void stopLoading();
void setConnectActionText(bool isAcitve);
- bool isAcitve = false;
- bool loading = false;
+ bool m_isAcitve = false;
+ bool m_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;
+ QTimer *m_waitTimer = nullptr;
+ bool m_useHalfFillet = false;
+ QList m_loadIcons;
+ int m_currentIconIndex=0;
private slots:
void updateIcon();
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/translations/bo.ts b/plugins/wlanconnect/translations/bo.ts
index f8fab3a1..824aac8c 100644
--- a/plugins/wlanconnect/translations/bo.ts
+++ b/plugins/wlanconnect/translations/bo.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
-
+
@@ -18,54 +18,54 @@
WlanConnect
-
-
+
+
-
+
/wlanconnect/open
-
+
/wlanconnect/Advanced settings"
-
+
-
+
-
+
-
-
-
+
+
+
-
+
diff --git a/plugins/wlanconnect/translations/bo_CN.ts b/plugins/wlanconnect/translations/bo_CN.ts
index 0d7ff07a..7be28fd3 100644
--- a/plugins/wlanconnect/translations/bo_CN.ts
+++ b/plugins/wlanconnect/translations/bo_CN.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
དྲ་རྒྱ་གཞན་དག་ནང་ཞུགས་དགོས།
-
+
@@ -18,54 +18,54 @@
WlanConnect
-
ཝུའུ་ལན་འབྲེལ་མཐུད།
-
+
+
སྐུད་མེད་ཅུས་ཁོངས་ཀྱི་དྲ་བ།
-
+
སྒོ་ཕྱེ་བ།
/wlanconnect/open
-
+
སྔོན་ཐོན་གྱི་སྒྲིག་བཀོད།
/wlanconnect/Advanced settings"
-
+
ཝུའུ་ཁི་ལན་གྱི་ཚོད་འཛིན་ལྟེ་གནས།
-
+
ངོས་ལེབ་ངོས་ཀྱི་བརྡ་ཐོ་ཚོད་འཛིན་བྱ་དགོས།
-
+
སྐུད་མེད་དྲ་རྒྱའི་བྱང་བུ་མ་རྙེད་པ།
-
-
-
+
+
+
འབྲེལ་མཐུད་བྱེད་པ།
-
+
བྱང་བུ།
diff --git a/plugins/wlanconnect/translations/en_US.ts b/plugins/wlanconnect/translations/en_US.ts
new file mode 100644
index 00000000..01b3915e
--- /dev/null
+++ b/plugins/wlanconnect/translations/en_US.ts
@@ -0,0 +1,73 @@
+
+
+
+
+ AddNetBtn
+
+
+
+ Add Others
+
+
+
+
+ Add WiredNetork
+
+
+
+ WlanConnect
+
+
+
+ WlanConnect
+
+
+
+
+
+
+ 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/tr.ts b/plugins/wlanconnect/translations/tr.ts
index f8fab3a1..824aac8c 100644
--- a/plugins/wlanconnect/translations/tr.ts
+++ b/plugins/wlanconnect/translations/tr.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
-
+
@@ -18,54 +18,54 @@
WlanConnect
-
-
+
+
-
+
/wlanconnect/open
-
+
/wlanconnect/Advanced settings"
-
+
-
+
-
+
-
-
-
+
+
+
-
+
diff --git a/plugins/wlanconnect/translations/zh_CN.ts b/plugins/wlanconnect/translations/zh_CN.ts
index a62ddac2..52d7a5cc 100644
--- a/plugins/wlanconnect/translations/zh_CN.ts
+++ b/plugins/wlanconnect/translations/zh_CN.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
加入其它网络
-
+
@@ -18,54 +18,54 @@
WlanConnect
-
无线局域网
-
+
+
无线局域网
-
+
开启
/wlanconnect/open
-
+
高级设置
/wlanconnect/Advanced settings"
-
+
控制面板
-
+
控制面板桌面通知
-
+
未检测到无线网卡
-
-
-
+
+
+
已连接
-
+
网卡
diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp
index bfbc6dd0..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";
@@ -99,9 +103,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 +141,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 +231,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 +304,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 +318,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 +432,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 +525,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 +563,7 @@ void WlanConnect::onSwitchBtnChanged(bool state)
if (getSwitchBtnState() == state) {
return;
}
-
+ setSwitchBtnEnable(true);
setSwitchBtnState(state);
if (!getSwitchBtnState()) {
hideLayout(ui->availableLayout);
@@ -681,7 +690,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 +709,7 @@ void WlanConnect::getDeviceList(QStringList &list)
void WlanConnect::initSwtichState()
{
- if (!m_interface->isValid()) {
+ if (m_interface == nullptr || !m_interface->isValid()) {
return;
}
@@ -713,25 +722,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 +751,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 +789,11 @@ void WlanConnect::initNetListFromDevice(QString deviceName)
//高级设置
void WlanConnect::runExternalApp() {
-// QString cmd = "nm-connection-editor";
-// QProcess process(this);
-// process.startDetached(cmd);
- LaunchApp("nm-connection-editor.desktop");
+ if (!LaunchApp("nm-connection-editor.desktop")){
+ QString cmd = "nm-connection-editor";
+ QProcess process(this);
+ process.startDetached(cmd);
+ }
}
//根据信号强度分级+安全性分图标
@@ -891,6 +886,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 +915,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 +924,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 +977,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 +1029,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 +1045,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__;
@@ -1113,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 45983aeb..abb2c8c0 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();
}
}
@@ -150,7 +150,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
-
+
diff --git a/plugins/wlanconnect/wlanitem.cpp b/plugins/wlanconnect/wlanitem.cpp
index 01d8b269..f4576426 100644
--- a/plugins/wlanconnect/wlanitem.cpp
+++ b/plugins/wlanconnect/wlanitem.cpp
@@ -19,6 +19,8 @@
*/
#include "wlanitem.h"
#include
+#include
+#include
#define FRAME_SPEED 150
#define LIMIT_TIME 60*1000
#define TOTAL_PAGE 8
@@ -33,17 +35,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 +63,6 @@ WlanItem::WlanItem(bool bAcitve, bool isLock, QWidget *parent)
waitTimer = new QTimer(this);
connect(waitTimer, &QTimer::timeout, this, &WlanItem::updateIcon);
-
}
WlanItem::~WlanItem()
@@ -93,12 +92,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-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/backend/vpndbusadaptor.cpp b/src-vpn/backend/vpndbusadaptor.cpp
similarity index 83%
rename from src/backend/vpndbusadaptor.cpp
rename to src-vpn/backend/vpndbusadaptor.cpp
index 1b43deb0..e94ab43b 100644
--- a/src/backend/vpndbusadaptor.cpp
+++ b/src-vpn/backend/vpndbusadaptor.cpp
@@ -21,22 +21,15 @@
* Implementation of adaptor class VpnDbusAdaptor
*/
-VpnDbusAdaptor::VpnDbusAdaptor(vpnMainWindow *parent)
+VpnDbusAdaptor::VpnDbusAdaptor(vpnObject *parent)
: QDBusAbstractAdaptor(parent)
{
- // constructor
qDBusRegisterMetaType >();
qDBusRegisterMetaType >();
qDBusRegisterMetaType >();
- //setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发
setAutoRelaySignals(true);
}
-VpnDbusAdaptor::~VpnDbusAdaptor()
-{
- // destructor
-}
-
//虚拟连接列表
QVector VpnDbusAdaptor::getVirtualList()
{
@@ -70,3 +63,16 @@ 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/backend/vpndbusadaptor.h b/src-vpn/backend/vpndbusadaptor.h
similarity index 63%
rename from src/backend/vpndbusadaptor.h
rename to src-vpn/backend/vpndbusadaptor.h
index 2fba0c84..919f092e 100644
--- a/src/backend/vpndbusadaptor.h
+++ b/src-vpn/backend/vpndbusadaptor.h
@@ -17,10 +17,11 @@
#include
#include "singlepage.h"
-#include "../dbus-interface/kylinnetworkdeviceresource.h"
+#include "kylinnetworkdeviceresource.h"
+#include "kyvpnconnectoperation.h"
+
QT_BEGIN_NAMESPACE
class QByteArray;
-//template class QList;
template class QMap;
class QString;
class QStringList;
@@ -28,37 +29,29 @@ class QVariant;
template class QVector;
QT_END_NAMESPACE
-/*
- * Adaptor class for interface com.kylin.weather
- */
-
-#include "vpnmainwindow.h"
+#include "vpnobject.h"
class VpnDbusAdaptor: public QDBusAbstractAdaptor
{
Q_OBJECT
- Q_CLASSINFO("D-Bus Interface", "com.kylin.vpnTool")
+ Q_CLASSINFO("D-Bus Interface", "com.kylin.kylinvpn")
public:
- VpnDbusAdaptor(vpnMainWindow *parent);
- virtual ~VpnDbusAdaptor();
+ VpnDbusAdaptor(vpnObject *parent);
- inline vpnMainWindow *parent() const
- { return static_cast(QObject::parent()); }
+ inline vpnObject *parent() const
+ { return static_cast(QObject::parent()); }
-public: // PROPERTIES
-public Q_SLOTS: // METHODS
- //虚拟连接列表
+public Q_SLOTS:
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
+ Q_NOREPLY void showVpnAddWidget();
+ Q_NOREPLY void showDetailPage(const QString& connUuid);
+
void showKylinVpn();
-Q_SIGNALS: // SIGNALS
+Q_SIGNALS:
void vpnAdd(QStringList info);
void vpnRemove(QString dbusPath);
void vpnUpdate(QStringList info);
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/frontend/list-items/vpnlistitem.cpp b/src-vpn/frontend/list-items/vpnlistitem.cpp
similarity index 79%
rename from src/frontend/list-items/vpnlistitem.cpp
rename to src-vpn/frontend/list-items/vpnlistitem.cpp
index 0a1541d1..64679857 100644
--- a/src/frontend/list-items/vpnlistitem.cpp
+++ b/src-vpn/frontend/list-items/vpnlistitem.cpp
@@ -18,20 +18,20 @@
*
*/
#include "vpnlistitem.h"
-#include "backend/dbus-interface/kylinconnectitem.h"
+#include "kylinconnectitem.h"
#include
#define LOG_FLAG "[VpnListItem]"
-VpnListItem::VpnListItem(const KyConnectItem *lanConnectItem, QWidget *parent):ListItem(parent)
+VpnListItem::VpnListItem(const KyConnectItem *vpnConnectItem, QWidget *parent):ListItem(parent)
{
- m_connectOperation = new KyWiredConnectOperation(this);
+ m_connectOperation = new KyVpnConnectOperation(this);
m_deviceResource = new KyNetworkDeviceResourse(this);
- connectItemCopy(lanConnectItem);
+ connectItemCopy(vpnConnectItem);
- m_nameLabel->setLabelText(m_vpnConnectItem.m_connectName);
+ 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;
@@ -59,7 +59,7 @@ VpnListItem::VpnListItem(QWidget *parent) : ListItem(parent)
m_netButton->setButtonIcon(QIcon::fromTheme("ukui-vpn-symbolic"));
setIcon(false);
const QString str=tr("Not connected");
- m_nameLabel->setLabelText(str);
+ m_nameLabel->setText(str);
this->m_infoButton->hide();
}
@@ -77,15 +77,15 @@ void VpnListItem::setIcon(bool isOn)
}
}
-void VpnListItem::connectItemCopy(const KyConnectItem *lanConnectItem)
+void VpnListItem::connectItemCopy(const KyConnectItem *vpnConnectItem)
{
- 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;
+ 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 = "";
@@ -95,17 +95,8 @@ void VpnListItem::connectItemCopy(const KyConnectItem *lanConnectItem)
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()) {
@@ -122,8 +113,6 @@ void VpnListItem::activeConnection()
qDebug() << LOG_FLAG <<"the connection" << m_vpnConnectItem.m_connectName
<< "is not deactived, so it can not be operation.";
}
-
- return;
}
void VpnListItem::onNetButtonClicked()
@@ -142,9 +131,6 @@ void VpnListItem::onNetButtonClicked()
qDebug() << LOG_FLAG <<"the connection" << m_vpnConnectItem.m_connectName
<< "is not deactived, so it can not be operation.";
}
-
- return;
-
}
void VpnListItem::onRightButtonClicked()
@@ -166,7 +152,6 @@ void VpnListItem::onRightButtonClicked()
m_menu->move(cursor().pos());
m_menu->show();
- return;
}
void VpnListItem::onMenuTriggered(QAction *action)
@@ -174,11 +159,10 @@ 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);
+ 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();
}
- return;
}
bool VpnListItem::launchApp(QString desktopFile)
@@ -197,10 +181,34 @@ bool VpnListItem::launchApp(QString desktopFile)
}
}
+void VpnListItem::runExternalApp() {
+ if (!launchApp("nm-connection-editor.desktop")){
+ QString cmd = "nm-connection-editor";
+ QProcess process(this);
+ process.startDetached(cmd);
+ }
+}
+
void VpnListItem::onInfoButtonClicked()
{
- launchApp("nm-connection-editor.desktop");
- return;
+ 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();
+ m_vpnDetail->centerToScreen();
}
void VpnListItem::updateConnectionState(ConnectState state)
@@ -217,8 +225,6 @@ void VpnListItem::updateConnectionState(ConnectState state)
} else {
m_netButton->startLoading();
}
-
- return;
}
QString VpnListItem::getConnectionName()
@@ -229,8 +235,7 @@ QString VpnListItem::getConnectionName()
void VpnListItem::updateConnectionName(QString connectionName)
{
m_vpnConnectItem.m_connectName = connectionName;
- m_nameLabel->setLabelText(m_vpnConnectItem.m_connectName);
- return;
+ m_nameLabel->setText(m_vpnConnectItem.m_connectName);
}
QString VpnListItem::getConnectionPath()
diff --git a/src/frontend/list-items/vpnlistitem.h b/src-vpn/frontend/list-items/vpnlistitem.h
similarity index 82%
rename from src/frontend/list-items/vpnlistitem.h
rename to src-vpn/frontend/list-items/vpnlistitem.h
index b65d22dc..b2be2edc 100644
--- a/src/frontend/list-items/vpnlistitem.h
+++ b/src-vpn/frontend/list-items/vpnlistitem.h
@@ -25,6 +25,13 @@
#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"
@@ -35,7 +42,7 @@ class VpnListItem : public ListItem
Q_OBJECT
public:
- VpnListItem(const KyConnectItem *lanConnectItem, QWidget *parent = nullptr);
+ VpnListItem(const KyConnectItem *vpnConnectItem, QWidget *parent = nullptr);
VpnListItem(QWidget *parent = nullptr);
~VpnListItem();
@@ -55,23 +62,27 @@ protected:
void setIcon(bool isOn);
void onRightButtonClicked();
bool launchApp(QString desktopFile);
+ void runExternalApp();
private:
- void connectItemCopy(const KyConnectItem *lanConnectItem);
+ void connectItemCopy(const KyConnectItem *vpnConnectItem);
+
+public Q_SLOTS:
+ void onInfoButtonClicked();
private Q_SLOTS:
- void onInfoButtonClicked();
void onNetButtonClicked();
void onMenuTriggered(QAction *action);
private:
KyConnectItem m_vpnConnectItem;
-// QDBusInterface m_appManagerDbusInterface;
- KyWiredConnectOperation *m_connectOperation = nullptr;
+ KyVpnConnectOperation *m_connectOperation = nullptr;
KyNetworkDeviceResourse *m_deviceResource = nullptr;
QString m_deviceName = "";
+
+ VpnDetail *m_vpnDetail = nullptr;
};
#endif // VPNLISTITEM_H
diff --git a/src/frontend/single-pages/single-pages.pri b/src-vpn/frontend/single-pages/single-pages.pri
similarity index 100%
rename from src/frontend/single-pages/single-pages.pri
rename to src-vpn/frontend/single-pages/single-pages.pri
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/frontend/single-pages/singlepage.h b/src-vpn/frontend/single-pages/singlepage.h
similarity index 68%
rename from src/frontend/single-pages/singlepage.h
rename to src-vpn/frontend/single-pages/singlepage.h
index 356cbacd..2855b96b 100644
--- a/src/frontend/single-pages/singlepage.h
+++ b/src-vpn/frontend/single-pages/singlepage.h
@@ -34,25 +34,18 @@
#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 TITLE_FRAME_HEIGHT 60 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度
+#define TITLE_LAYOUT_MARGINS 24,0,24,0
+#define NET_LAYOUT_MARGINS 8,8,0,8
#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
@@ -60,6 +53,9 @@ using namespace kdk;
#define SCROLL_STEP 4
+#define TRANSPARENCY "transparency"
+#define TRANSPARENCY_GSETTINGS "org.ukui.control-center.personalise"
+
class SinglePage : public QWidget
{
Q_OBJECT
@@ -69,41 +65,48 @@ public:
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);
+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;
- QFrame * m_netFrame = nullptr;
- QVBoxLayout * m_netLayout = nullptr;
- QLabel * m_netLabel = nullptr;
- QWidget * m_netListArea = nullptr;
- QVBoxLayout * m_netAreaLayout = nullptr;
+ QLabel * m_titleLabel = nullptr;
+ QFrame * m_titleFrame = nullptr;
+ QHBoxLayout * m_titleLayout = nullptr;
- Divider * m_netDivider = 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/frontend/single-pages/vpnpage.cpp b/src-vpn/frontend/single-pages/vpnpage.cpp
similarity index 58%
rename from src/frontend/single-pages/vpnpage.cpp
rename to src-vpn/frontend/single-pages/vpnpage.cpp
index 36d21c69..e2cb274b 100644
--- a/src/frontend/single-pages/vpnpage.cpp
+++ b/src-vpn/frontend/single-pages/vpnpage.cpp
@@ -18,29 +18,20 @@
*
*/
#include "vpnpage.h"
-#include "networkmodeconfig.h"
#include
#include
+#include "windowmanager/windowmanager.h"
-#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);
+ 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) {
@@ -51,8 +42,14 @@ VpnPage::VpnPage(QWidget *parent) : SinglePage(parent)
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);
+ 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()
@@ -61,16 +58,16 @@ VpnPage::~VpnPage()
}
void VpnPage::deleteConnectionMapItem(QMap &connectMap,
- QListWidget *lanListWidget, QString uuid)
+ QListWidget *vpnListWidget, 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);
+ VpnListItem *p_vpnItem = (VpnListItem *)vpnListWidget->itemWidget(p_listWidgetItem);
+ vpnListWidget->removeItemWidget(p_listWidgetItem);
- delete p_lanItem;
- p_lanItem = nullptr;
+ delete p_vpnItem;
+ p_vpnItem = nullptr;
delete p_listWidgetItem;
p_listWidgetItem = nullptr;
@@ -80,7 +77,7 @@ void VpnPage::deleteConnectionMapItem(QMap &connectM
}
void VpnPage::clearConnectionMap(QMap &connectMap,
- QListWidget *lanListWidget)
+ QListWidget *vpnListWidget)
{
QMap::iterator iter;
@@ -89,11 +86,11 @@ void VpnPage::clearConnectionMap(QMap &connectMap,
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);
+ VpnListItem *p_vpnItem = (VpnListItem *)vpnListWidget->itemWidget(p_widgetItem);
+ vpnListWidget->removeItemWidget(p_widgetItem);
- delete p_lanItem;
- p_lanItem = nullptr;
+ delete p_vpnItem;
+ p_vpnItem = nullptr;
delete p_widgetItem;
p_widgetItem = nullptr;
@@ -104,17 +101,15 @@ void VpnPage::clearConnectionMap(QMap &connectMap,
return;
}
-void VpnPage::constructActiveConnectionArea()
+void VpnPage::constructItemArea()
{
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);
+ clearConnectionMap(m_activeItemMap, m_listWidget);
+ clearConnectionMap(m_vpnItemMap, m_listWidget);
m_connectResourse->getVpnAndVirtualConnections(netList);
KyConnectItem *p_newItem = nullptr;
@@ -123,75 +118,80 @@ void VpnPage::constructActiveConnectionArea()
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)) {
+ if (m_vpnItemMap.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);
+ QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_listWidget);
+ m_vpnItemMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem);
} else {
- if (m_activeConnectionMap.contains(p_netConnectionItem->m_connectUuid)) {
+ if (m_activeItemMap.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);
+ QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_listWidget);
+ m_activeItemMap.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 (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_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;
+ resetListWidgetWidth();
}
void VpnPage::initVpnArea()
{
- m_netFrame->show();
- constructActiveConnectionArea();
+ 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();
+ }
}
bool VpnPage::removeConnectionItem(QMap &connectMap,
- QListWidget *lanListWidget, QString path)
+ QListWidget *vpnListWidget, 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) {
+ VpnListItem *p_vpnItem = (VpnListItem*)vpnListWidget->itemWidget(p_listWidgetItem);
+ if (p_vpnItem->getConnectionPath() == path) {
qDebug()<<"[VpnPage] Remove a connection from list";
- lanListWidget->removeItemWidget(p_listWidgetItem);
+ vpnListWidget->removeItemWidget(p_listWidgetItem);
- delete p_lanItem;
- p_lanItem = nullptr;
+ delete p_vpnItem;
+ p_vpnItem = 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);
- }
+ resetListWidgetWidth();
return true;
}
}
@@ -205,10 +205,11 @@ void VpnPage::onRemoveConnection(QString path) //删除时后端会
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;
- }
+ removeConnectionItem(m_vpnItemMap, m_listWidget, path);
+ removeConnectionItem(m_activeItemMap, m_listWidget, path);
+ resetPageHeight();
+ resetWindowPosition();
+ this->update();
}
void VpnPage::onAddConnection(QString uuid) //新增一个有线连接,将其加入到激活列表
@@ -226,21 +227,18 @@ void VpnPage::onAddConnection(QString uuid) //新增一个有线
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;
+ QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget);
+ if (m_vpnItemMap.contains(p_newItem->m_connectUuid)) {
+ qDebug()<m_connectUuid;
}
- m_netConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
+ m_vpnItemMap.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());
+ resetListWidgetWidth();
+ resetPageHeight();
+ resetWindowPosition();
+ this->update();
return;
}
@@ -252,21 +250,16 @@ void VpnPage::onShowControlCenter()
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);
+ m_titleLabel->setText(tr("VPN"));
- QPalette pal = m_vpnListWidget->palette();
- pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明
- m_vpnListWidget->setPalette(pal);
+// 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);
@@ -276,10 +269,10 @@ QListWidgetItem *VpnPage::insertNewItem(KyConnectItem *itemData, QListWidget *li
{
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();
+ 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;
@@ -303,66 +296,61 @@ QListWidgetItem *VpnPage::addNewItem(KyConnectItem *itemData, QListWidget *listW
{
QListWidgetItem *p_listWidgetItem = new QListWidgetItem();
p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable));
- p_listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT));
+ p_listWidgetItem->setSizeHint(QSize(listWidget->width() - 16, ITEM_HEIGHT));
listWidget->addItem(p_listWidgetItem);
- VpnListItem *p_lanItem = nullptr;
+ VpnListItem *p_vpnItem = nullptr;
if (itemData != nullptr) {
- p_lanItem = new VpnListItem(itemData);
+ p_vpnItem = new VpnListItem(itemData);
qDebug() << "[VpnPage] addNewItem, connection: " << itemData->m_connectName;
} else {
- p_lanItem = new VpnListItem();
+ p_vpnItem = new VpnListItem();
qDebug() << "[VpnPage] Add nullItem!";
}
- listWidget->setItemWidget(p_listWidgetItem, p_lanItem);
+ listWidget->setItemWidget(p_listWidgetItem, p_vpnItem);
return p_listWidgetItem;
}
void VpnPage::updateActivatedConnectionArea(KyConnectItem *p_newItem)
{
- if (m_activeConnectionMap.contains(p_newItem->m_connectUuid)) {
+ if (m_activeItemMap.contains(p_newItem->m_connectUuid)) {
return;
}
- deleteConnectionMapItem(m_netConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid);
+ deleteConnectionMapItem(m_vpnItemMap, m_listWidget, 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);
- }
+ 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);
+
+ resetListWidgetWidth();
return;
}
void VpnPage::updateConnectionArea(KyConnectItem *p_newItem)
{
- if (m_netConnectionMap.contains(p_newItem->m_connectUuid)) {
+ if (m_vpnItemMap.contains(p_newItem->m_connectUuid)) {
return;
}
- deleteConnectionMapItem(m_activeConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid);
+ deleteConnectionMapItem(m_activeItemMap, m_listWidget, 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);
+ QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget);
+ m_vpnItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
- if (m_vpnListWidget->count() <= MAX_ITEMS) {
- m_vpnListWidget->setFixedWidth(MIN_WIDTH);
- } else {
- m_vpnListWidget->setFixedWidth(MAX_WIDTH);
- }
+ resetListWidgetWidth();
}
void VpnPage::updateConnectionState(QMap &connectMap,
- QListWidget *lanListWidget, QString uuid, ConnectState state)
+ QListWidget *vpnListWidget, 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);
+ VpnListItem *p_vpnItem = (VpnListItem *)vpnListWidget->itemWidget(p_listWidgetItem);
+ p_vpnItem->updateConnectionState(state);
}
}
@@ -379,7 +367,7 @@ void VpnPage::onConnectionStateChange(QString uuid,
sendVpnStateChangeSignal(uuid, (ConnectState)state);
- if (m_activeConnectionMap.keys().contains(uuid) && state == NetworkManager::ActiveConnection::State::Activated) {
+ if (m_activeItemMap.keys().contains(uuid) && state == NetworkManager::ActiveConnection::State::Activated) {
return;
}
@@ -399,7 +387,7 @@ void VpnPage::onConnectionStateChange(QString uuid,
ssid = p_newItem->m_connectName;
updateActivatedConnectionArea(p_newItem);
- updateConnectionState(m_activeConnectionMap, m_vpnListWidget, uuid, (ConnectState)state);
+ 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;
@@ -410,12 +398,11 @@ void VpnPage::onConnectionStateChange(QString uuid,
ssid = p_newItem->m_connectName;
updateConnectionArea(p_newItem);
- updateConnectionState(m_netConnectionMap, m_vpnListWidget, uuid, (ConnectState)state);
- NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, deviceName, ssid);
+ updateConnectionState(m_vpnItemMap, m_listWidget, uuid, (ConnectState)state);
} else if (state == NetworkManager::ActiveConnection::State::Activating) {
- updateConnectionState(m_netConnectionMap, m_vpnListWidget, uuid, (ConnectState)state);
+ updateConnectionState(m_vpnItemMap, m_listWidget, uuid, (ConnectState)state);
} else if (state == NetworkManager::ActiveConnection::State::Deactivating) {
- updateConnectionState(m_activeConnectionMap, m_vpnListWidget, uuid, (ConnectState)state);
+ updateConnectionState(m_activeItemMap, m_listWidget, uuid, (ConnectState)state);
}
Q_EMIT vpnActiveConnectionStateChanged(uuid, state);
@@ -496,27 +483,27 @@ 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()){
+ 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_netConnectionMap, m_vpnListWidget, newUuid);
- QListWidgetItem *p_sortListWidgetItem = insertNewItem(p_connectItem, m_vpnListWidget);
- if (m_netConnectionMap.contains(newUuid)) {
+ deleteConnectionMapItem(m_vpnItemMap, m_listWidget, newUuid);
+ QListWidgetItem *p_sortListWidgetItem = insertNewItem(p_connectItem, m_listWidget);
+ if (m_vpnItemMap.contains(newUuid)) {
qDebug()<m_connectPath != p_lanItem->getConnectionPath()) {
- p_lanItem->updateConnectionPath(p_connectItem->m_connectPath);
+ m_vpnItemMap.insert(newUuid, p_sortListWidgetItem);
+ } else if (p_connectItem->m_connectPath != p_vpnItem->getConnectionPath()) {
+ p_vpnItem->updateConnectionPath(p_connectItem->m_connectPath);
}
- } else if (!m_activeConnectionMap.contains(newUuid)){
+ } else if (!m_activeItemMap.contains(newUuid)){
if (p_connectItem->m_ifaceName.isEmpty()) {
- QListWidgetItem *p_listWidgetItem = insertNewItem(p_connectItem, m_vpnListWidget);
- if (m_netConnectionMap.contains(newUuid)) {
+ QListWidgetItem *p_listWidgetItem = insertNewItem(p_connectItem, m_listWidget);
+ if (m_vpnItemMap.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 (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_lanItem->getConnectionName() != p_connectItem->m_connectPath) {
- p_lanItem->updateConnectionPath(p_connectItem->m_connectPath);
+ if (p_vpnItem->getConnectionName() != p_connectItem->m_connectPath) {
+ p_vpnItem->updateConnectionPath(p_connectItem->m_connectPath);
}
}
return;
@@ -597,14 +584,14 @@ void VpnPage::deleteVpn(const QString &connUuid)
if (connUuid == nullptr) {
return;
}
- m_wiredConnectOperation->deleteWiredConnect(connUuid);
+ m_vpnConnectOperation->deleteVpnConnect(connUuid);
}
void VpnPage::activateVpn(const QString& connUuid)
{
- if (m_netConnectionMap.contains(connUuid)) {
+ if (m_vpnItemMap.contains(connUuid)) {
qDebug() << "[VpnPage] activateVpn" << connUuid;
- m_wiredConnectOperation->activateVpnConnection(connUuid);
+ m_vpnConnectOperation->activateVpnConnection(connUuid);
}
}
@@ -612,34 +599,92 @@ void VpnPage::deactivateVpn(const QString& connUuid)
{
qDebug() << "[VpnPage] deactivateVpn" << connUuid;
QString name("");
- m_wiredConnectOperation->deactivateWiredConnection(name, connUuid);
+ m_vpnConnectOperation->deactivateVpnConnection(name, connUuid);
}
-void VpnPage::showDetailPage(QString devName, QString uuid)
+void VpnPage::showDetailPage(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
+ 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__;
+}
+
+void VpnPage::resetListWidgetWidth()
+{
+ if (m_listWidget->count() <= MAX_ITEMS) {
+ m_listFrame->setFixedWidth(MIN_WIDTH);
+ } else {
+ m_listFrame->setFixedWidth(MAX_WIDTH);
+ }
}
diff --git a/src/frontend/single-pages/vpnpage.h b/src-vpn/frontend/single-pages/vpnpage.h
similarity index 82%
rename from src/frontend/single-pages/vpnpage.h
rename to src-vpn/frontend/single-pages/vpnpage.h
index 0b3c5fd8..e5748723 100644
--- a/src/frontend/single-pages/vpnpage.h
+++ b/src-vpn/frontend/single-pages/vpnpage.h
@@ -29,11 +29,19 @@
#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";
@@ -52,7 +60,7 @@ public:
void deleteVpn(const QString &connUuid);
void activateVpn(const QString& connUuid);
void deactivateVpn(const QString& connUuid);
- void showDetailPage(QString devName, QString uuid);
+ void showDetailPage(QString uuid);
protected:
bool eventFilter(QObject *watched, QEvent *event);
@@ -60,20 +68,21 @@ protected:
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 *lanListWidget, QString path);
+ QListWidget *vpnListWidget, QString path);
- void constructActiveConnectionArea();
+ void constructItemArea();
void updateConnectionArea(KyConnectItem *p_newItem);
void updateActivatedConnectionArea(KyConnectItem *p_newItem);
void updateConnectionState(QMap &connectMap,
- QListWidget *lanListWidget, QString uuid, ConnectState state);
+ QListWidget *vpnListWidget, QString uuid, ConnectState state);
void updateActiveConnectionProperty(KyConnectItem *p_connectItem);
void updateConnectionProperty(KyConnectItem *p_connectItem);
@@ -83,9 +92,12 @@ private:
void sendVpnStateChangeSignal(QString uuid, ConnectState state);
void clearConnectionMap(QMap &connectMap,
- QListWidget *lanListWidget);
+ QListWidget *vpnListWidget);
void deleteConnectionMapItem(QMap &connectMap,
- QListWidget *lanListWidget, QString uuid);
+ QListWidget *vpnListWidget, QString uuid);
+
+ void resetWindowPosition();
+ void resetListWidgetWidth();
Q_SIGNALS:
void vpnAdd(QStringList info);
@@ -106,21 +118,20 @@ private Q_SLOTS:
void onShowControlCenter();
-// void onStateChange();
-
private:
- QListWidget * m_vpnListWidget = nullptr;
-
-// KyNetworkDeviceResourse *m_deviceResource = nullptr;
- KyWiredConnectOperation *m_wiredConnectOperation = nullptr;
+ KyVpnConnectOperation *m_vpnConnectOperation = nullptr;
KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接
KyConnectResourse *m_connectResourse = nullptr; //未激活的连接
- QMap m_netConnectionMap;
- QMap m_activeConnectionMap;
+ QMap m_vpnItemMap;
+ QMap m_activeItemMap;
+
+ QDBusInterface * m_positionInterface = nullptr;
+
+
public Q_SLOTS:
- inline void onDeviceComboxIndexChanged(int currentIndex) { return; }
+ void showUI();
};
#endif // LANPAGE_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
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/translations/kylin-nm_bo.qm b/src-vpn/translations/kylin-vpn_bo_CN.qm
similarity index 100%
rename from translations/kylin-nm_bo.qm
rename to src-vpn/translations/kylin-vpn_bo_CN.qm
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..ebebae3d
--- /dev/null
+++ b/src-vpn/translations/kylin-vpn_bo_CN.ts
@@ -0,0 +1,144 @@
+
+
+
+
+ SinglePage
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VpnListItem
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VpnPage
+
+
+
+
+
+
+
+
+
+
+
+
+ vpnAddPage
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vpnConfigPage
+
+
+
+
+
+
+
+ VpnDetail
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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 00000000..75c3ce3e
Binary files /dev/null and b/src-vpn/translations/kylin-vpn_zh_CN.qm differ
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..29c04c79
--- /dev/null
+++ b/src-vpn/translations/kylin-vpn_zh_CN.ts
@@ -0,0 +1,835 @@
+
+
+
+
+ SinglePage
+
+
+
+ 设置
+
+
+
+
+ VPN工具
+
+
+
+
+ vpn配置桌面提示
+
+
+
+ VpnAdvancedPage
+
+
+
+ MPPE加密算法:
+
+
+
+
+ 使用有状态加密
+
+
+
+
+ 发送PPP回显包
+
+
+
+
+ 认证方式:
+
+
+
+
+ PAP认证
+
+
+
+
+ CHAP认证
+
+
+
+
+ MSCHAP认证
+
+
+
+
+ MSCHAP2认证
+
+
+
+
+ EAP认证
+
+
+
+
+ 压缩方式:
+
+
+
+
+ 允许BSD压缩
+
+
+
+
+ 允许Default压缩
+
+
+
+
+ 允许TCP头压缩
+
+
+
+
+ 使用协议域压缩协商
+
+
+
+
+ 使用地址/控制压缩
+
+
+
+
+ 任意
+
+
+
+
+ 128位
+
+
+
+
+ 40位
+
+
+
+
+ 使用自定义网关端口
+
+
+
+
+ 使用压缩
+
+
+
+
+ 使用TCP连接
+
+
+
+
+ 设置虚拟设备类型
+
+
+
+
+ 设置虚拟设备名称
+
+
+
+
+ 限制TCP最大段尺寸(MSS)
+
+
+
+
+ 随机化远程主机
+
+
+
+
+ IPv6 tun连接
+
+
+
+
+ 指定Ping周期
+
+
+
+
+ 指定退出或重启的Ping
+
+
+
+
+ 指定路由上限
+
+
+
+
+ 出错时无限重试
+
+
+
+
+ 使用自定义密钥大小
+
+
+
+
+ 选择
+
+
+
+
+ 使用自定义重协商间隔
+
+
+
+
+ 使用自定义隧道最大单元传输(MTU)
+
+
+
+
+ 使用自定义UDP分片大小
+
+
+
+
+ 接受来自任何地址(Float)已通过身份验证的数据包
+
+
+
+
+ 主题匹配
+
+
+
+
+ 密钥文件
+
+
+
+
+ 密钥方向
+
+
+
+
+ 服务器地址
+
+
+
+
+ 端口
+
+
+
+
+ 代理用户名
+
+
+
+
+ 代理密码
+
+
+
+
+ 常规
+
+
+
+
+ TLS设置
+
+
+
+
+ 服务器证书检验
+
+
+
+
+ 使用前面验证端(服务器)证书
+
+
+
+
+ 验证对等点(服务器)证书nsCertType指定
+
+
+
+
+ 模式
+
+
+
+
+ 代理
+
+
+
+
+ 代理类型
+
+
+
+
+ 安全
+
+
+
+
+ HMAC认证
+
+
+
+
+ 输入内容
+
+
+
+
+ 否
+
+
+
+
+ 自适应
+
+
+
+
+ 自动
+
+
+
+
+ 退出
+
+
+
+
+ 重启
+
+
+
+
+ 不验证证书标识
+
+
+
+
+ 确切地验证整个主题
+
+
+
+
+ 精确验证名称
+
+
+
+
+ 按前缀验证名称
+
+
+
+
+
+ 服务器
+
+
+
+
+
+ 客户端
+
+
+
+
+
+
+ 无
+
+
+
+
+ TLS-认证
+
+
+
+
+ TLS-加密
+
+
+
+
+ 不需要
+
+
+
+
+ 默认
+
+
+
+
+ 选项:
+
+
+
+
+ 请求内部IP地址
+
+
+
+
+ 强制UDP封装
+
+
+
+
+ 使用IP压缩
+
+
+
+
+ 启用自定义密码建议
+
+
+
+ VpnConfigPage
+
+
+
+ 类型
+
+
+
+
+ 名称
+
+
+
+
+ 静态密钥
+
+
+
+
+ 本地IP地址
+
+
+
+
+ 远程IP地址
+
+
+
+
+ PIN码
+
+
+
+
+
+
+ 密码
+
+
+
+
+ NT域
+
+
+
+
+ 服务器地址
+
+
+
+
+ 认证方式
+
+
+
+
+ CA证书
+
+
+
+
+ 用户证书
+
+
+
+
+ 密钥方向
+
+
+
+
+ 私钥
+
+
+
+
+ 私有密钥密码
+
+
+
+
+
+ 密码选项
+
+
+
+
+ 用户名
+
+
+
+
+ 注意:
+如果使用了密钥方向,它必须和使用的VPN端相反。如果使用了“1”,连接必须要使用“0”。如果不确定使用哪个值,请联系您的系统管理员。
+
+
+
+
+
+
+
+ 选择
+
+
+
+
+ 无
+
+
+
+
+
+ 仅对当前用户保存密码
+
+
+
+
+
+ 为所有用户保存密码
+
+
+
+
+
+ 每次都询问
+
+
+
+
+
+ 不需要密码
+
+
+
+
+
+ 必填
+
+
+
+
+ 证书(TLS)
+
+
+
+
+ 静态密钥
+
+
+
+
+ 密码和证书(TLS)
+
+
+
+
+ 证书/私钥
+
+
+
+
+ 证书/ssh-agent
+
+
+
+
+ 智能卡
+
+
+
+
+ 选择私钥
+
+
+
+
+
+ 私钥文件(*.key *.pem *.der *.p12 *.pfx)
+
+
+
+
+ 选择CA证书
+
+
+
+
+
+ CA文件 (*.pem *.der *.p12 *.crt *.cer *.pfx)
+
+
+
+
+ 选择用户证书
+
+
+
+
+ 选择静态密钥
+
+
+
+ VpnIpv4Page
+
+
+
+ IPv4配置
+
+
+
+
+ 地址
+
+
+
+
+ 子网掩码
+
+
+
+
+ 默认网关
+
+
+
+
+ DNS服务器
+
+
+
+
+ 搜索域
+
+
+
+
+ DHCP客户端ID
+
+
+
+
+ 自动(DHCP)
+
+
+
+
+ 手动
+
+
+
+ VpnIpv6Page
+
+
+
+ IPv6配置
+
+
+
+
+ 地址
+
+
+
+
+ 子网掩码
+
+
+
+
+ 默认网关
+
+
+
+
+ DNS服务器
+
+
+
+
+ 搜索域
+
+
+
+
+ 自动(DHCP)
+
+
+
+
+ 手动
+
+
+
+ VpnListItem
+
+
+
+ 未连接
+
+
+
+
+
+ 断开
+
+
+
+
+
+ 连接
+
+
+
+ VpnPage
+
+
+
+
+
+
+
+
+ VPN设置
+
+
+
+ vpnAddPage
+
+
+
+ 创建VPN
+
+
+
+
+ VPN类型
+
+
+
+
+ VPN名称
+
+
+
+
+
+ 必填
+
+
+
+
+ 服务器地址
+
+
+
+
+
+
+
+
+
+ 自动连接
+
+
+
+
+ 确定
+
+
+
+
+ 取消
+
+
+
+ vpnConfigPage
+
+
+ VPN类型
+
+
+
+ VpnDetail
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 高级
+
+
+
+
+ 自动连接
+
+
+
+
+ 取消
+
+
+
+
+ 确定
+
+
+
+ vpnObject
+
+
+
+ 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/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/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/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