新增VPN详情页
This commit is contained in:
parent
82d8bfc6e2
commit
c87184a139
|
@ -37,23 +37,23 @@ AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent)
|
||||||
|
|
||||||
QHBoxLayout *addLyt = new QHBoxLayout;
|
QHBoxLayout *addLyt = new QHBoxLayout;
|
||||||
|
|
||||||
QLabel *iconLabel = new QLabel();
|
QLabel *iconLabel = new QLabel(this);
|
||||||
QLabel *textLabel = new QLabel();
|
m_textLabel = new QLabel(this);
|
||||||
|
|
||||||
if (isWlan) {
|
if (isWlan) {
|
||||||
textLabel->setText(tr("Add Others"));
|
m_textLabel->setText(tr("Add Others"));
|
||||||
addLyt->addSpacing(8);
|
addLyt->addSpacing(8);
|
||||||
addLyt->addWidget(textLabel);
|
addLyt->addWidget(m_textLabel);
|
||||||
} else {
|
} else {
|
||||||
textLabel->setText(tr("Add WiredNetork"));
|
m_textLabel->setText(tr("Add WiredNetork"));
|
||||||
QIcon mAddIcon = QIcon::fromTheme("list-add-symbolic");
|
QIcon mAddIcon = QIcon::fromTheme("list-add-symbolic");
|
||||||
iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(24, 24))));
|
iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(16, 16))));
|
||||||
iconLabel->setProperty("useIconHighlightEffect", 0x2);
|
iconLabel->setProperty("useIconHighlightEffect", 0x2);
|
||||||
// iconLabel->setProperty("iconHighlightEffectMode", 1);
|
// iconLabel->setProperty("iconHighlightEffectMode", 1);
|
||||||
|
|
||||||
addLyt->addStretch();
|
addLyt->addStretch();
|
||||||
addLyt->addWidget(iconLabel);
|
addLyt->addWidget(iconLabel);
|
||||||
addLyt->addWidget(textLabel);
|
addLyt->addWidget(m_textLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
addLyt->addStretch();
|
addLyt->addStretch();
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
class AddNetBtn : public QPushButton
|
class AddNetBtn : public QPushButton
|
||||||
{
|
{
|
||||||
|
@ -33,11 +34,18 @@ public:
|
||||||
AddNetBtn(bool isWlan, QWidget *parent = nullptr);
|
AddNetBtn(bool isWlan, QWidget *parent = nullptr);
|
||||||
~AddNetBtn();
|
~AddNetBtn();
|
||||||
|
|
||||||
|
void setTextLabel(const QString str) {
|
||||||
|
m_textLabel->setText(str);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void leaveEvent(QEvent * event);
|
virtual void leaveEvent(QEvent * event);
|
||||||
virtual void enterEvent(QEvent * event);
|
virtual void enterEvent(QEvent * event);
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLabel *m_textLabel;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void enterWidget();
|
void enterWidget();
|
||||||
void leaveWidget();
|
void leaveWidget();
|
||||||
|
|
|
@ -200,14 +200,15 @@ void VpnListItem::onInfoButtonClicked()
|
||||||
m_vpnDetail->activateWindow();
|
m_vpnDetail->activateWindow();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_vpnDetail = new vpnDetail(m_vpnConnectItem.m_connectUuid, getConnectionName());
|
m_vpnDetail = new VpnDetail(m_vpnConnectItem.m_connectUuid, getConnectionName());
|
||||||
connect(m_vpnDetail, &vpnDetail::destroyed, [&](){
|
connect(m_vpnDetail, &VpnDetail::destroyed, [&](){
|
||||||
if (m_vpnDetail != nullptr) {
|
if (m_vpnDetail != nullptr) {
|
||||||
m_vpnDetail = nullptr;
|
m_vpnDetail = nullptr;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
m_vpnDetail->show();
|
m_vpnDetail->show();
|
||||||
|
m_vpnDetail->centerToScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VpnListItem::updateConnectionState(ConnectState state)
|
void VpnListItem::updateConnectionState(ConnectState state)
|
||||||
|
|
|
@ -82,7 +82,7 @@ private:
|
||||||
|
|
||||||
QString m_deviceName = "";
|
QString m_deviceName = "";
|
||||||
|
|
||||||
vpnDetail *m_vpnDetail = nullptr;
|
VpnDetail *m_vpnDetail = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VPNLISTITEM_H
|
#endif // VPNLISTITEM_H
|
||||||
|
|
|
@ -0,0 +1,234 @@
|
||||||
|
#include "vpnaddpage.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#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();
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
#ifndef VPNADDPAGE_H
|
||||||
|
#define VPNADDPAGE_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
#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
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,197 @@
|
||||||
|
#ifndef VPNADVANCEDPAGE_H
|
||||||
|
#define VPNADVANCEDPAGE_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QListWidget>
|
||||||
|
#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
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,198 @@
|
||||||
|
#ifndef VPNCONFIGPAGE_H
|
||||||
|
#define VPNCONFIGPAGE_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QGridLayout>
|
||||||
|
|
||||||
|
#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
|
|
@ -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<bool> 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模式
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,111 @@
|
||||||
|
#ifndef VPNDETAIL_H
|
||||||
|
#define VPNDETAIL_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QStackedWidget>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
#include <QDBusMessage>
|
||||||
|
#include <QDBusObjectPath>
|
||||||
|
#include <QDBusInterface>
|
||||||
|
#include <QDBusReply>
|
||||||
|
|
||||||
|
#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
|
|
@ -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
|
|
@ -0,0 +1,284 @@
|
||||||
|
#include "vpnipv4page.h"
|
||||||
|
#include "math.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#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<QHostAddress> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
#ifndef VPNIPV4PAGE_H
|
||||||
|
#define VPNIPV4PAGE_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QFormLayout>
|
||||||
|
|
||||||
|
#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
|
|
@ -0,0 +1,240 @@
|
||||||
|
#include "vpnipv6page.h"
|
||||||
|
#include "math.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#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<QHostAddress> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
#ifndef VPNIPV6PAGE_H
|
||||||
|
#define VPNIPV6PAGE_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QFormLayout>
|
||||||
|
|
||||||
|
#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
|
Loading…
Reference in New Issue