!30 合并其他产线改动

Merge pull request !30 from zhaoshixu/upstream-dev
This commit is contained in:
zhaoshixu 2023-04-10 09:58:18 +00:00 committed by Gitee
commit f5b6d2ba7a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
179 changed files with 15138 additions and 3566 deletions

View File

@ -1,14 +1,25 @@
TEMPLATE = subdirs
CONFIG += ordered \
CONFIG += \
ordered \
qt
SUBDIRS = \
plugins/plugin.pro \
src \
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 \

View File

@ -17,9 +17,6 @@
<file>res/h/right-pwd.png</file>
<file>res/h/show-pwd.png</file>
<file>res/h/no-pwd-wifi.png</file>
<file>translations/kylin-nm_bo.qm</file>
<file>translations/kylin-nm_tr.qm</file>
<file>translations/kylin-nm_zh_CN.qm</file>
<file>res/x/fly-mode-off.svg</file>
<file>res/x/fly-mode-on.svg</file>
<file>res/x/hot-spot-off.svg</file>
@ -128,6 +125,5 @@
<file>res/s/conning-b/10.png</file>
<file>res/s/conning-b/11.png</file>
<file>res/s/conning-b/12.png</file>
<file>translations/kylin-nm_bo_CN.qm</file>
</qresource>
</RCC>

View File

@ -20,6 +20,7 @@
#include "addnetbtn.h"
#include <QEvent>
#include <QHBoxLayout>
#include <QLabel>
#include <QVariant>
#include <QPainter>
#include <QPainterPath>
@ -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;

View File

@ -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();

View File

@ -22,6 +22,7 @@
#include <QPainter>
#include <QApplication>
#include <QDebug>
#include <QPainterPath>
#define BUTTON_SIZE 36,36
#define ICON_SIZE 16,16

View File

@ -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<QString, QString> &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();

View File

@ -49,15 +49,8 @@ public:
}
private:
QFrame* myLine();
TitleLabel *m_titleLabel = nullptr;
QVBoxLayout *m_blacklistLayout = nullptr;
QMap<QString, QString> m_blacklistMap;
QDBusInterface *m_settingPathInterface = nullptr;
void getBlacklistDevice(QMap<QString, QString> &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<QString, QString> m_blacklistMap;
QDBusInterface *m_settingPathInterface = nullptr;
private slots:
void onsetStaIntoBlacklist(QString staMac, QString staName);
void onRemoveFromBlacklistBtnClicked(QString staMac, QString staName);

View File

@ -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<QString, QString> &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();

View File

@ -50,12 +50,6 @@ public:
private:
QFrame* myLine();
TitleLabel *m_titleLabel = nullptr;
QVBoxLayout *m_staListLayout = nullptr;
QMap<QString, QString> m_staMap;
QDBusInterface *m_activePathInterface = nullptr;
void getConnectStaDevice(QMap<QString, QString> &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<QString, QString> m_staMap;
QDBusInterface *m_activePathInterface = nullptr;
signals:
void setStaIntoBlacklist(QString staMac, QString staName);

View File

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

View File

@ -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,19 +314,16 @@ 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);
if (!state) {
m_switchBtn->setChecked(state);
m_uuid.clear();
m_switchBtn->setCheckable(false);
} else {
m_switchBtn->setCheckable(true);
}
}
}
void MobileHotspotWidget::initInterfaceInfo()
{
@ -720,7 +714,9 @@ void MobileHotspotWidget::setWidgetHidden(bool isHidden)
m_uuid = "";
} else {
m_switchBtn->setCheckable(true);
onGsettingChanged(WIRELESS_SWITCH);
QDBusReply<bool> reply = m_interface->call("getWirelessSwitchBtnState");
bool state = reply.value();
onWirelessBtnChanged(state);
}
resetFrameSize();

View File

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

View File

@ -4,7 +4,7 @@
<context>
<name>BlacklistItem</name>
<message>
<location filename="../blacklistitem.cpp" line="49"/>
<location filename="../blacklistitem.cpp" line="50"/>
<source>Remove</source>
<translation type="unfinished"></translation>
</message>
@ -12,7 +12,7 @@
<context>
<name>BlacklistPage</name>
<message>
<location filename="../blacklistpage.cpp" line="45"/>
<location filename="../blacklistpage.cpp" line="47"/>
<source>Blacklist</source>
<translation type="unfinished"></translation>
</message>
@ -20,7 +20,7 @@
<context>
<name>ConnectDevListItem</name>
<message>
<location filename="../connectdevlistitem.cpp" line="49"/>
<location filename="../connectdevlistitem.cpp" line="50"/>
<source>drag into blacklist</source>
<translation type="unfinished"></translation>
</message>
@ -28,7 +28,7 @@
<context>
<name>ConnectdevPage</name>
<message>
<location filename="../connectdevpage.cpp" line="46"/>
<location filename="../connectdevpage.cpp" line="48"/>
<source>Connect device</source>
<translation type="unfinished"></translation>
</message>
@ -56,79 +56,69 @@
<context>
<name>MobileHotspotWidget</name>
<message>
<location filename="../mobilehotspotwidget.cpp" line="59"/>
<location filename="../mobilehotspotwidget.cpp" line="61"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="62"/>
<location filename="../mobilehotspotwidget.cpp" line="64"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="138"/>
<location filename="../mobilehotspotwidget.cpp" line="149"/>
<source>wirless switch is close or no wireless device</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="142"/>
<source>start to close hotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="151"/>
<location filename="../mobilehotspotwidget.cpp" line="169"/>
<source>hotpots name or device is invalid</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="158"/>
<source>start to open hotspot </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="489"/>
<location filename="../mobilehotspotwidget.cpp" line="490"/>
<source>Contains at least 8 characters</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="205"/>
<location filename="../mobilehotspotwidget.cpp" line="223"/>
<source>Hotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="295"/>
<location filename="../mobilehotspotwidget.cpp" line="610"/>
<location filename="../mobilehotspotwidget.cpp" line="310"/>
<location filename="../mobilehotspotwidget.cpp" line="605"/>
<source>hotspot already close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="435"/>
<location filename="../mobilehotspotwidget.cpp" line="436"/>
<source>Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="456"/>
<location filename="../mobilehotspotwidget.cpp" line="457"/>
<source>Wi-Fi Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="477"/>
<location filename="../mobilehotspotwidget.cpp" line="478"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="518"/>
<location filename="../mobilehotspotwidget.cpp" line="519"/>
<source>Frequency band</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="544"/>
<location filename="../mobilehotspotwidget.cpp" line="545"/>
<source>Net card</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="639"/>
<location filename="../mobilehotspotwidget.cpp" line="647"/>
<location filename="../mobilehotspotwidget.cpp" line="635"/>
<location filename="../mobilehotspotwidget.cpp" line="643"/>
<source>hotspot already open</source>
<translation type="unfinished"></translation>
</message>

View File

@ -4,7 +4,7 @@
<context>
<name>BlacklistItem</name>
<message>
<location filename="../blacklistitem.cpp" line="49"/>
<location filename="../blacklistitem.cpp" line="50"/>
<source>Remove</source>
<translation></translation>
</message>
@ -12,7 +12,7 @@
<context>
<name>BlacklistPage</name>
<message>
<location filename="../blacklistpage.cpp" line="45"/>
<location filename="../blacklistpage.cpp" line="47"/>
<source>Blacklist</source>
<translation></translation>
</message>
@ -20,7 +20,7 @@
<context>
<name>ConnectDevListItem</name>
<message>
<location filename="../connectdevlistitem.cpp" line="49"/>
<location filename="../connectdevlistitem.cpp" line="50"/>
<source>drag into blacklist</source>
<translation></translation>
</message>
@ -28,7 +28,7 @@
<context>
<name>ConnectdevPage</name>
<message>
<location filename="../connectdevpage.cpp" line="46"/>
<location filename="../connectdevpage.cpp" line="48"/>
<source>Connect device</source>
<translation></translation>
</message>
@ -56,27 +56,26 @@
<context>
<name>MobileHotspotWidget</name>
<message>
<location filename="../mobilehotspotwidget.cpp" line="59"/>
<location filename="../mobilehotspotwidget.cpp" line="61"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="62"/>
<location filename="../mobilehotspotwidget.cpp" line="64"/>
<source>ukui control center desktop message</source>
<translation>ukui </translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="138"/>
<location filename="../mobilehotspotwidget.cpp" line="149"/>
<source>wirless switch is close or no wireless device</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="142"/>
<source>start to close hotspot</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="151"/>
<location filename="../mobilehotspotwidget.cpp" line="169"/>
<source>hotpots name or device is invalid</source>
<translation></translation>
</message>
@ -85,54 +84,53 @@
<translation type="vanished">!</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="158"/>
<source>start to open hotspot </source>
<translation> </translation>
<translation type="vanished"> </translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="489"/>
<location filename="../mobilehotspotwidget.cpp" line="490"/>
<source>Contains at least 8 characters</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="205"/>
<location filename="../mobilehotspotwidget.cpp" line="223"/>
<source>Hotspot</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="295"/>
<location filename="../mobilehotspotwidget.cpp" line="610"/>
<location filename="../mobilehotspotwidget.cpp" line="310"/>
<location filename="../mobilehotspotwidget.cpp" line="605"/>
<source>hotspot already close</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="435"/>
<location filename="../mobilehotspotwidget.cpp" line="436"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="456"/>
<location filename="../mobilehotspotwidget.cpp" line="457"/>
<source>Wi-Fi Name</source>
<translation>Wi-Fiཡི</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="477"/>
<location filename="../mobilehotspotwidget.cpp" line="478"/>
<source>Password</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="518"/>
<location filename="../mobilehotspotwidget.cpp" line="519"/>
<source>Frequency band</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="544"/>
<location filename="../mobilehotspotwidget.cpp" line="545"/>
<source>Net card</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="639"/>
<location filename="../mobilehotspotwidget.cpp" line="647"/>
<location filename="../mobilehotspotwidget.cpp" line="635"/>
<location filename="../mobilehotspotwidget.cpp" line="643"/>
<source>hotspot already open</source>
<translation></translation>
</message>

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en">
<context>
<name>BlacklistItem</name>
<message>
<location filename="../blacklistitem.cpp" line="50"/>
<source>Remove</source>
<translation>Remove</translation>
</message>
</context>
<context>
<name>BlacklistPage</name>
<message>
<location filename="../blacklistpage.cpp" line="47"/>
<source>Blacklist</source>
<translation>Blacklist</translation>
</message>
</context>
<context>
<name>ConnectDevListItem</name>
<message>
<location filename="../connectdevlistitem.cpp" line="50"/>
<source>drag into blacklist</source>
<translation>drag into blacklist</translation>
</message>
</context>
<context>
<name>ConnectdevPage</name>
<message>
<location filename="../connectdevpage.cpp" line="48"/>
<source>Connect device</source>
<translation>Connect device</translation>
</message>
</context>
<context>
<name>MobileHotspot</name>
<message>
<location filename="../mobilehotspot.cpp" line="35"/>
<source>MobileHotspot</source>
<translation>MobileHotspot</translation>
</message>
<message>
<location filename="../mobilehotspot.cpp" line="101"/>
<source>mobilehotspot</source>
<translation>mobilehotspot</translation>
<extra-contents_path>/mobilehotspot/mobilehotspot</extra-contents_path>
</message>
<message>
<location filename="../mobilehotspot.cpp" line="103"/>
<source>mobilehotspot open</source>
<translation>mobilehotspot open</translation>
<extra-contents_path>/mobilehotspot/mobilehotspot open</extra-contents_path>
</message>
</context>
<context>
<name>MobileHotspotWidget</name>
<message>
<location filename="../mobilehotspotwidget.cpp" line="61"/>
<source>ukui control center</source>
<translation>ukui control center</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="64"/>
<source>ukui control center desktop message</source>
<translation>ukui control center desktop message</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="149"/>
<source>wirless switch is close or no wireless device</source>
<translation>wirless switch is close or no wireless device</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="169"/>
<source>hotpots name or device is invalid</source>
<translation>hotpots name or device is invalid</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="223"/>
<source>Hotspot</source>
<translation>Hotspot</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="310"/>
<location filename="../mobilehotspotwidget.cpp" line="605"/>
<source>hotspot already close</source>
<translation>hotspot already close</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="436"/>
<source>Open</source>
<translation>Open</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="457"/>
<source>Wi-Fi Name</source>
<translation>Wi-Fi Name</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="478"/>
<source>Password</source>
<translation>Password</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="490"/>
<source>Contains at least 8 characters</source>
<translation>Contains at least 8 characters</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="519"/>
<source>Frequency band</source>
<translation>Frequency band</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="545"/>
<source>Net card</source>
<translation>Net card</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="635"/>
<location filename="../mobilehotspotwidget.cpp" line="643"/>
<source>hotspot already open</source>
<translation>hotspot already open</translation>
</message>
</context>
</TS>

View File

@ -4,7 +4,7 @@
<context>
<name>BlacklistItem</name>
<message>
<location filename="../blacklistitem.cpp" line="49"/>
<location filename="../blacklistitem.cpp" line="50"/>
<source>Remove</source>
<translation type="unfinished"></translation>
</message>
@ -12,7 +12,7 @@
<context>
<name>BlacklistPage</name>
<message>
<location filename="../blacklistpage.cpp" line="45"/>
<location filename="../blacklistpage.cpp" line="47"/>
<source>Blacklist</source>
<translation type="unfinished"></translation>
</message>
@ -20,7 +20,7 @@
<context>
<name>ConnectDevListItem</name>
<message>
<location filename="../connectdevlistitem.cpp" line="49"/>
<location filename="../connectdevlistitem.cpp" line="50"/>
<source>drag into blacklist</source>
<translation type="unfinished"></translation>
</message>
@ -28,7 +28,7 @@
<context>
<name>ConnectdevPage</name>
<message>
<location filename="../connectdevpage.cpp" line="46"/>
<location filename="../connectdevpage.cpp" line="48"/>
<source>Connect device</source>
<translation type="unfinished"></translation>
</message>
@ -56,79 +56,69 @@
<context>
<name>MobileHotspotWidget</name>
<message>
<location filename="../mobilehotspotwidget.cpp" line="59"/>
<location filename="../mobilehotspotwidget.cpp" line="61"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="62"/>
<location filename="../mobilehotspotwidget.cpp" line="64"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="138"/>
<location filename="../mobilehotspotwidget.cpp" line="149"/>
<source>wirless switch is close or no wireless device</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="142"/>
<source>start to close hotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="151"/>
<location filename="../mobilehotspotwidget.cpp" line="169"/>
<source>hotpots name or device is invalid</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="158"/>
<source>start to open hotspot </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="489"/>
<location filename="../mobilehotspotwidget.cpp" line="490"/>
<source>Contains at least 8 characters</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="205"/>
<location filename="../mobilehotspotwidget.cpp" line="223"/>
<source>Hotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="295"/>
<location filename="../mobilehotspotwidget.cpp" line="610"/>
<location filename="../mobilehotspotwidget.cpp" line="310"/>
<location filename="../mobilehotspotwidget.cpp" line="605"/>
<source>hotspot already close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="435"/>
<location filename="../mobilehotspotwidget.cpp" line="436"/>
<source>Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="456"/>
<location filename="../mobilehotspotwidget.cpp" line="457"/>
<source>Wi-Fi Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="477"/>
<location filename="../mobilehotspotwidget.cpp" line="478"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="518"/>
<location filename="../mobilehotspotwidget.cpp" line="519"/>
<source>Frequency band</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="544"/>
<location filename="../mobilehotspotwidget.cpp" line="545"/>
<source>Net card</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="639"/>
<location filename="../mobilehotspotwidget.cpp" line="647"/>
<location filename="../mobilehotspotwidget.cpp" line="635"/>
<location filename="../mobilehotspotwidget.cpp" line="643"/>
<source>hotspot already open</source>
<translation type="unfinished"></translation>
</message>

View File

@ -4,7 +4,7 @@
<context>
<name>BlacklistItem</name>
<message>
<location filename="../blacklistitem.cpp" line="49"/>
<location filename="../blacklistitem.cpp" line="50"/>
<source>Remove</source>
<translation></translation>
</message>
@ -12,7 +12,7 @@
<context>
<name>BlacklistPage</name>
<message>
<location filename="../blacklistpage.cpp" line="45"/>
<location filename="../blacklistpage.cpp" line="47"/>
<source>Blacklist</source>
<translation></translation>
</message>
@ -20,7 +20,7 @@
<context>
<name>ConnectDevListItem</name>
<message>
<location filename="../connectdevlistitem.cpp" line="49"/>
<location filename="../connectdevlistitem.cpp" line="50"/>
<source>drag into blacklist</source>
<translation></translation>
</message>
@ -28,7 +28,7 @@
<context>
<name>ConnectdevPage</name>
<message>
<location filename="../connectdevpage.cpp" line="46"/>
<location filename="../connectdevpage.cpp" line="48"/>
<source>Connect device</source>
<translation></translation>
</message>
@ -56,27 +56,26 @@
<context>
<name>MobileHotspotWidget</name>
<message>
<location filename="../mobilehotspotwidget.cpp" line="59"/>
<location filename="../mobilehotspotwidget.cpp" line="61"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="62"/>
<location filename="../mobilehotspotwidget.cpp" line="64"/>
<source>ukui control center desktop message</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="138"/>
<location filename="../mobilehotspotwidget.cpp" line="149"/>
<source>wirless switch is close or no wireless device</source>
<translation>线线</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="142"/>
<source>start to close hotspot</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="151"/>
<location filename="../mobilehotspotwidget.cpp" line="169"/>
<source>hotpots name or device is invalid</source>
<translation></translation>
</message>
@ -85,54 +84,53 @@
<translation type="vanished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="158"/>
<source>start to open hotspot </source>
<translation></translation>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="489"/>
<location filename="../mobilehotspotwidget.cpp" line="490"/>
<source>Contains at least 8 characters</source>
<translation>8</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="205"/>
<location filename="../mobilehotspotwidget.cpp" line="223"/>
<source>Hotspot</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="295"/>
<location filename="../mobilehotspotwidget.cpp" line="610"/>
<location filename="../mobilehotspotwidget.cpp" line="310"/>
<location filename="../mobilehotspotwidget.cpp" line="605"/>
<source>hotspot already close</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="435"/>
<location filename="../mobilehotspotwidget.cpp" line="436"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="456"/>
<location filename="../mobilehotspotwidget.cpp" line="457"/>
<source>Wi-Fi Name</source>
<translation>Wi-Fi名称</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="477"/>
<location filename="../mobilehotspotwidget.cpp" line="478"/>
<source>Password</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="518"/>
<location filename="../mobilehotspotwidget.cpp" line="519"/>
<source>Frequency band</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="544"/>
<location filename="../mobilehotspotwidget.cpp" line="545"/>
<source>Net card</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="639"/>
<location filename="../mobilehotspotwidget.cpp" line="647"/>
<location filename="../mobilehotspotwidget.cpp" line="635"/>
<location filename="../mobilehotspotwidget.cpp" line="643"/>
<source>hotspot already open</source>
<translation></translation>
</message>

View File

@ -18,6 +18,7 @@
*
*/
#include "deviceframe.h"
#include <QPainterPath>
#define LAYOUT_MARGINS 16,0,16,0
#define FRAME_HEIGHT 58

View File

@ -18,6 +18,8 @@
*
*/
#include "lanitem.h"
#include <QApplication>
#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();

View File

@ -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 {
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<QString, bool> &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__;
@ -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__;
@ -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__;

View File

@ -153,7 +153,6 @@ private slots:
void onDeviceStatusChanged();
void onDeviceNameChanged(QString, QString, int);
};
Q_DECLARE_METATYPE(QList<QDBusObjectPath>);

View File

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

View File

@ -4,61 +4,93 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../addnetbtn.cpp" line="22"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="57"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="120"/>
<location filename="../lanitem.cpp" line="133"/>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="122"/>
<location filename="../lanitem.cpp" line="131"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<location filename="../netconnect.cpp" line="152"/>
<source>Wired Network</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="154"/>
<location filename="../netconnect.cpp" line="158"/>
<source>open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="151"/>
<location filename="../netconnect.cpp" line="155"/>
<source>Advanced settings</source>
<translation type="unfinished"></translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="63"/>
<location filename="../netconnect.cpp" line="67"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="66"/>
<location filename="../netconnect.cpp" line="70"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="80"/>
<source>WiredConnect</source>
<location filename="../netconnect.cpp" line="84"/>
<location filename="../netconnect.cpp" line="156"/>
<source>LAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="177"/>
<location filename="../netconnect.cpp" line="172"/>
<source>No ethernet device avaliable</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="426"/>
<location filename="../netconnect.cpp" line="833"/>
<location filename="../netconnect.cpp" line="450"/>
<location filename="../netconnect.cpp" line="896"/>
<source>connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="490"/>
<location filename="../netconnect.cpp" line="452"/>
<location filename="../netconnect.cpp" line="749"/>
<location filename="../netconnect.cpp" line="906"/>
<source>not connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="528"/>
<source>card</source>
<translation type="unfinished"></translation>
</message>

View File

@ -4,12 +4,12 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation></translation>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="52"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation></translation>
</message>
@ -17,81 +17,86 @@
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="59"/>
<location filename="../lanitem.cpp" line="57"/>
<source>Delete</source>
<translation></translation>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="121"/>
<location filename="../lanitem.cpp" line="134"/>
<location filename="../lanitem.cpp" line="120"/>
<location filename="../lanitem.cpp" line="133"/>
<source>Disconnect</source>
<translation></translation>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="123"/>
<location filename="../lanitem.cpp" line="132"/>
<location filename="../lanitem.cpp" line="122"/>
<location filename="../lanitem.cpp" line="131"/>
<source>Connect</source>
<translation></translation>
<translation></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<location filename="../netconnect.cpp" line="153"/>
<source>Wired Network</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="155"/>
<location filename="../netconnect.cpp" line="158"/>
<source>open</source>
<translation></translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="152"/>
<location filename="../netconnect.cpp" line="155"/>
<source>Advanced settings</source>
<translation></translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="64"/>
<location filename="../netconnect.cpp" line="67"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="67"/>
<location filename="../netconnect.cpp" line="70"/>
<source>ukui control center desktop message</source>
<translation>ukui </translation>
</message>
<message>
<location filename="../netconnect.cpp" line="81"/>
<source>WiredConnect</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="169"/>
<location filename="../netconnect.cpp" line="84"/>
<location filename="../netconnect.cpp" line="156"/>
<source>LAN</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="172"/>
<source>No ethernet device avaliable</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="437"/>
<location filename="../netconnect.cpp" line="866"/>
<location filename="../netconnect.cpp" line="450"/>
<location filename="../netconnect.cpp" line="896"/>
<source>connected</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="512"/>
<location filename="../netconnect.cpp" line="452"/>
<location filename="../netconnect.cpp" line="749"/>
<location filename="../netconnect.cpp" line="906"/>
<source>not connected</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="528"/>
<source>card</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="439"/>
<location filename="../netconnect.cpp" line="876"/>
<source>not connected</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en">
<context>
<name>AddNetBtn</name>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation>Add Others</translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation>Add WiredNetork</translation>
</message>
</context>
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="57"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="120"/>
<location filename="../lanitem.cpp" line="133"/>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="122"/>
<location filename="../lanitem.cpp" line="131"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<source>Wired Network</source>
<translation>Wired Network</translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="158"/>
<source>open</source>
<translation>open</translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="155"/>
<source>Advanced settings</source>
<translation>Advanced settings</translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="67"/>
<source>ukui control center</source>
<translation>ukui control center</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="70"/>
<source>ukui control center desktop message</source>
<translation>ukui control center desktop message</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="84"/>
<location filename="../netconnect.cpp" line="156"/>
<source>LAN</source>
<translation>LAN</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="172"/>
<source>No ethernet device avaliable</source>
<translation>No ethernet device avaliable</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="450"/>
<location filename="../netconnect.cpp" line="896"/>
<source>connected</source>
<translation>connected</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="452"/>
<location filename="../netconnect.cpp" line="749"/>
<location filename="../netconnect.cpp" line="906"/>
<source>not connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="528"/>
<source>card</source>
<translation>card</translation>
</message>
</context>
</TS>

View File

@ -4,61 +4,93 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../addnetbtn.cpp" line="22"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="57"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="120"/>
<location filename="../lanitem.cpp" line="133"/>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="122"/>
<location filename="../lanitem.cpp" line="131"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<location filename="../netconnect.cpp" line="152"/>
<source>Wired Network</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="154"/>
<location filename="../netconnect.cpp" line="158"/>
<source>open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="151"/>
<location filename="../netconnect.cpp" line="155"/>
<source>Advanced settings</source>
<translation type="unfinished"></translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="63"/>
<location filename="../netconnect.cpp" line="67"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="66"/>
<location filename="../netconnect.cpp" line="70"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="80"/>
<source>WiredConnect</source>
<location filename="../netconnect.cpp" line="84"/>
<location filename="../netconnect.cpp" line="156"/>
<source>LAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="177"/>
<location filename="../netconnect.cpp" line="172"/>
<source>No ethernet device avaliable</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="426"/>
<location filename="../netconnect.cpp" line="833"/>
<location filename="../netconnect.cpp" line="450"/>
<location filename="../netconnect.cpp" line="896"/>
<source>connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="490"/>
<location filename="../netconnect.cpp" line="452"/>
<location filename="../netconnect.cpp" line="749"/>
<location filename="../netconnect.cpp" line="906"/>
<source>not connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="528"/>
<source>card</source>
<translation type="unfinished"></translation>
</message>

View File

@ -4,12 +4,12 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation></translation>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="52"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation>线</translation>
</message>
@ -17,19 +17,19 @@
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="59"/>
<location filename="../lanitem.cpp" line="57"/>
<source>Delete</source>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="121"/>
<location filename="../lanitem.cpp" line="134"/>
<location filename="../lanitem.cpp" line="120"/>
<location filename="../lanitem.cpp" line="133"/>
<source>Disconnect</source>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="123"/>
<location filename="../lanitem.cpp" line="132"/>
<location filename="../lanitem.cpp" line="122"/>
<location filename="../lanitem.cpp" line="131"/>
<source>Connect</source>
<translation></translation>
</message>
@ -38,60 +38,65 @@
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<location filename="../netconnect.cpp" line="153"/>
<source>Wired Network</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="155"/>
<location filename="../netconnect.cpp" line="158"/>
<source>open</source>
<translation></translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="152"/>
<location filename="../netconnect.cpp" line="155"/>
<source>Advanced settings</source>
<translation></translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="64"/>
<location filename="../netconnect.cpp" line="67"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="67"/>
<location filename="../netconnect.cpp" line="70"/>
<source>ukui control center desktop message</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="81"/>
<source>WiredConnect</source>
<translation type="vanished">线</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="84"/>
<location filename="../netconnect.cpp" line="156"/>
<source>LAN</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="169"/>
<location filename="../netconnect.cpp" line="172"/>
<source>No ethernet device avaliable</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="437"/>
<location filename="../netconnect.cpp" line="866"/>
<location filename="../netconnect.cpp" line="450"/>
<location filename="../netconnect.cpp" line="896"/>
<source>connected</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="512"/>
<source>card</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="439"/>
<location filename="../netconnect.cpp" line="876"/>
<location filename="../netconnect.cpp" line="452"/>
<location filename="../netconnect.cpp" line="749"/>
<location filename="../netconnect.cpp" line="906"/>
<source>not connected</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="528"/>
<source>card</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -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());
}
}

View File

@ -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);
}

View File

@ -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)
{
@ -68,6 +68,7 @@ Proxy::~Proxy()
{
if (!mFirstLoad) {
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,9 +761,12 @@ void Proxy::setAptProxy(QString host, QString port, bool status)
"/",
"com.control.center.interface",
QDBusConnection::systemBus());
if (mAptproxyDbus->isValid())
if (mAptproxyDbus->isValid()) {
QDBusReply<bool> reply = mAptproxyDbus->call("setaptproxy", host, port , status);
}
delete mAptproxyDbus;
mAptproxyDbus = nullptr;
}
QHash<QString, QVariant> Proxy::getAptProxy()
{
@ -781,6 +798,8 @@ QHash<QString, QVariant> 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());
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);

View File

@ -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();

View File

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

View File

@ -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<QString, VpnItem *> itemMap;
QMap<QString, VpnItem *> m_itemMap;
// //已激活uuid
// QString uuid = "";
//新建无线连接
AddNetBtn * addWlanWidget = nullptr;
AddNetBtn * m_addVpnWidget = nullptr;
void filletStyleChange();
};

View File

@ -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<QVector<QStringList>>();
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<bool> 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<QString, VpnItem *>::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)

View File

@ -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();

View File

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

View File

@ -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<QIcon> loadIcons;
int currentIconIndex=0;
QTimer *m_waitTimer = nullptr;
bool m_useHalfFillet = false;
QList<QIcon> m_loadIcons;
int m_currentIconIndex=0;
private slots:
void updateIcon();

View File

@ -19,6 +19,7 @@
*/
#include "deviceframe.h"
#include <QPainter>
#include <QPainterPath>
#define LAYOUT_MARGINS 18,0,8,0
#define FRAME_HEIGHT 58

View File

@ -4,12 +4,12 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="24"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="27"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation type="unfinished"></translation>
</message>
@ -18,54 +18,54 @@
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.ui" line="14"/>
<location filename="../wlanconnect.cpp" line="140"/>
<source>WlanConnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="35"/>
<location filename="../wlanconnect.cpp" line="211"/>
<location filename="../wlanconnect.cpp" line="144"/>
<location filename="../wlanconnect.cpp" line="215"/>
<source>WLAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="94"/>
<location filename="../wlanconnect.cpp" line="213"/>
<location filename="../wlanconnect.cpp" line="217"/>
<source>open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/wlanconnect/open</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.ui" line="147"/>
<location filename="../wlanconnect.cpp" line="210"/>
<location filename="../wlanconnect.cpp" line="214"/>
<source>Advanced settings</source>
<translation type="unfinished"></translation>
<extra-contents_path>/wlanconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.cpp" line="123"/>
<location filename="../wlanconnect.cpp" line="127"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="126"/>
<location filename="../wlanconnect.cpp" line="130"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="228"/>
<location filename="../wlanconnect.cpp" line="232"/>
<source>No wireless network card detected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="374"/>
<location filename="../wlanconnect.cpp" line="1022"/>
<location filename="../wlanconnect.cpp" line="1084"/>
<location filename="../wlanconnect.cpp" line="368"/>
<location filename="../wlanconnect.cpp" line="1039"/>
<location filename="../wlanconnect.cpp" line="1101"/>
<source>connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="959"/>
<location filename="../wlanconnect.cpp" line="976"/>
<source>card</source>
<translation type="unfinished"></translation>
</message>

View File

@ -4,12 +4,12 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="43"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="47"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation type="unfinished"></translation>
</message>
@ -18,54 +18,54 @@
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.ui" line="14"/>
<location filename="../wlanconnect.cpp" line="140"/>
<source>WlanConnect</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="35"/>
<location filename="../wlanconnect.cpp" line="211"/>
<location filename="../wlanconnect.cpp" line="144"/>
<location filename="../wlanconnect.cpp" line="215"/>
<source>WLAN</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="94"/>
<location filename="../wlanconnect.cpp" line="213"/>
<location filename="../wlanconnect.cpp" line="217"/>
<source>open</source>
<translation></translation>
<extra-contents_path>/wlanconnect/open</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.ui" line="147"/>
<location filename="../wlanconnect.cpp" line="210"/>
<location filename="../wlanconnect.cpp" line="214"/>
<source>Advanced settings</source>
<translation></translation>
<extra-contents_path>/wlanconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.cpp" line="123"/>
<location filename="../wlanconnect.cpp" line="127"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="126"/>
<location filename="../wlanconnect.cpp" line="130"/>
<source>ukui control center desktop message</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="228"/>
<location filename="../wlanconnect.cpp" line="232"/>
<source>No wireless network card detected</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="374"/>
<location filename="../wlanconnect.cpp" line="1022"/>
<location filename="../wlanconnect.cpp" line="1084"/>
<location filename="../wlanconnect.cpp" line="368"/>
<location filename="../wlanconnect.cpp" line="1039"/>
<location filename="../wlanconnect.cpp" line="1101"/>
<source>connected</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="959"/>
<location filename="../wlanconnect.cpp" line="976"/>
<source>card</source>
<translation></translation>
</message>

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>AddNetBtn</name>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation>Add Others</translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation>Add WiredNetork</translation>
</message>
</context>
<context>
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.ui" line="14"/>
<source>WlanConnect</source>
<translation>WlanConnect</translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="35"/>
<location filename="../wlanconnect.cpp" line="144"/>
<location filename="../wlanconnect.cpp" line="215"/>
<source>WLAN</source>
<translation>WLAN</translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="94"/>
<location filename="../wlanconnect.cpp" line="217"/>
<source>open</source>
<translation>open</translation>
<extra-contents_path>/wlanconnect/open</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.ui" line="147"/>
<location filename="../wlanconnect.cpp" line="214"/>
<source>Advanced settings</source>
<translation>Advanced settings</translation>
<extra-contents_path>/wlanconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.cpp" line="127"/>
<source>ukui control center</source>
<translation>ukui control center</translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="130"/>
<source>ukui control center desktop message</source>
<translation>ukui control center desktop message</translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="232"/>
<source>No wireless network card detected</source>
<translation>No wireless network card detected</translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="368"/>
<location filename="../wlanconnect.cpp" line="1039"/>
<location filename="../wlanconnect.cpp" line="1101"/>
<source>connected</source>
<translation>connected</translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="976"/>
<source>card</source>
<translation>card</translation>
</message>
</context>
</TS>

View File

@ -4,12 +4,12 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="24"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="27"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation type="unfinished"></translation>
</message>
@ -18,54 +18,54 @@
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.ui" line="14"/>
<location filename="../wlanconnect.cpp" line="140"/>
<source>WlanConnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="35"/>
<location filename="../wlanconnect.cpp" line="211"/>
<location filename="../wlanconnect.cpp" line="144"/>
<location filename="../wlanconnect.cpp" line="215"/>
<source>WLAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="94"/>
<location filename="../wlanconnect.cpp" line="213"/>
<location filename="../wlanconnect.cpp" line="217"/>
<source>open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/wlanconnect/open</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.ui" line="147"/>
<location filename="../wlanconnect.cpp" line="210"/>
<location filename="../wlanconnect.cpp" line="214"/>
<source>Advanced settings</source>
<translation type="unfinished"></translation>
<extra-contents_path>/wlanconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.cpp" line="123"/>
<location filename="../wlanconnect.cpp" line="127"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="126"/>
<location filename="../wlanconnect.cpp" line="130"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="228"/>
<location filename="../wlanconnect.cpp" line="232"/>
<source>No wireless network card detected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="374"/>
<location filename="../wlanconnect.cpp" line="1022"/>
<location filename="../wlanconnect.cpp" line="1084"/>
<location filename="../wlanconnect.cpp" line="368"/>
<location filename="../wlanconnect.cpp" line="1039"/>
<location filename="../wlanconnect.cpp" line="1101"/>
<source>connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="959"/>
<location filename="../wlanconnect.cpp" line="976"/>
<source>card</source>
<translation type="unfinished"></translation>
</message>

View File

@ -4,12 +4,12 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="24"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="44"/>
<source>Add Others</source>
<translation></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="27"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add WiredNetork</source>
<translation type="unfinished"></translation>
</message>
@ -18,54 +18,54 @@
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.ui" line="14"/>
<location filename="../wlanconnect.cpp" line="140"/>
<source>WlanConnect</source>
<translation>线</translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="35"/>
<location filename="../wlanconnect.cpp" line="211"/>
<location filename="../wlanconnect.cpp" line="144"/>
<location filename="../wlanconnect.cpp" line="215"/>
<source>WLAN</source>
<translation>线</translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="94"/>
<location filename="../wlanconnect.cpp" line="213"/>
<location filename="../wlanconnect.cpp" line="217"/>
<source>open</source>
<translation></translation>
<extra-contents_path>/wlanconnect/open</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.ui" line="147"/>
<location filename="../wlanconnect.cpp" line="210"/>
<location filename="../wlanconnect.cpp" line="214"/>
<source>Advanced settings</source>
<translation></translation>
<extra-contents_path>/wlanconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.cpp" line="123"/>
<location filename="../wlanconnect.cpp" line="127"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="126"/>
<location filename="../wlanconnect.cpp" line="130"/>
<source>ukui control center desktop message</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="228"/>
<location filename="../wlanconnect.cpp" line="232"/>
<source>No wireless network card detected</source>
<translation>线</translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="374"/>
<location filename="../wlanconnect.cpp" line="1022"/>
<location filename="../wlanconnect.cpp" line="1084"/>
<location filename="../wlanconnect.cpp" line="368"/>
<location filename="../wlanconnect.cpp" line="1039"/>
<location filename="../wlanconnect.cpp" line="1101"/>
<source>connected</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="959"/>
<location filename="../wlanconnect.cpp" line="976"/>
<source>card</source>
<translation></translation>
</message>

View File

@ -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 {
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<bool> 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<bool> reply =m_appManagerDbusInterface.call("LaunchApp",desktopFile);
return reply;
}
}

View File

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

View File

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

View File

@ -184,7 +184,7 @@
<customwidget>
<class>TitleLabel</class>
<extends>QLabel</extends>
<header location="global">titlelabel.h</header>
<header>titlelabel.h</header>
</customwidget>
</customwidgets>
<resources/>

View File

@ -19,6 +19,8 @@
*/
#include "wlanitem.h"
#include <QPainter>
#include <QPainterPath>
#include <QApplication>
#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();

View File

@ -0,0 +1,10 @@
INCLUDEPATH += $$PWD
include(../../src/backend/dbus-interface/dbus-interface.pri)
HEADERS += \
$$PWD/vpndbusadaptor.h
SOURCES += \
$$PWD/vpndbusadaptor.cpp
DISTFILES +=

View File

@ -21,22 +21,15 @@
* Implementation of adaptor class VpnDbusAdaptor
*/
VpnDbusAdaptor::VpnDbusAdaptor(vpnMainWindow *parent)
VpnDbusAdaptor::VpnDbusAdaptor(vpnObject *parent)
: QDBusAbstractAdaptor(parent)
{
// constructor
qDBusRegisterMetaType<QMap<QString, bool> >();
qDBusRegisterMetaType<QMap<QString, int> >();
qDBusRegisterMetaType<QVector<QStringList> >();
//setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号因此不必再额外写一个转发
setAutoRelaySignals(true);
}
VpnDbusAdaptor::~VpnDbusAdaptor()
{
// destructor
}
//虚拟连接列表
QVector<QStringList> 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);
}

View File

@ -17,10 +17,11 @@
#include <QtDBus/QDBusMetaType>
#include "singlepage.h"
#include "../dbus-interface/kylinnetworkdeviceresource.h"
#include "kylinnetworkdeviceresource.h"
#include "kyvpnconnectoperation.h"
QT_BEGIN_NAMESPACE
class QByteArray;
//template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
@ -28,37 +29,29 @@ class QVariant;
template<class T> 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<vpnMainWindow *>(QObject::parent()); }
inline vpnObject *parent() const
{ return static_cast<vpnObject *>(QObject::parent()); }
public: // PROPERTIES
public Q_SLOTS: // METHODS
//虚拟连接列表
public Q_SLOTS:
QVector<QStringList> 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);

View File

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

View File

@ -0,0 +1,10 @@
INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/listitem.h \
$$PWD/vpnlistitem.h
SOURCES += \
$$PWD/listitem.cpp \
$$PWD/vpnlistitem.cpp

View File

@ -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 <QDebug>
#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);
}

View File

@ -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 <QFrame>
#include <QEvent>
#include <QHBoxLayout>
#include <QDebug>
#include <QMouseEvent>
#include <QMenu>
#include <QApplication>
#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

View File

@ -18,20 +18,20 @@
*
*/
#include "vpnlistitem.h"
#include "backend/dbus-interface/kylinconnectitem.h"
#include "kylinconnectitem.h"
#include <QDebug>
#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,12 +181,36 @@ 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");
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)
{
m_vpnConnectItem.m_connectState = (NetworkManager::ActiveConnection::State)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()

View File

@ -25,6 +25,13 @@
#include <QDBusInterface>
#include <QEvent>
#include <QAction>
#include <QProcess>
#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

View File

@ -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 <qsettings.h>
#include <QDBusInterface>
#include <QLabel>
#include <QApplication>
#include <QDBusReply>
#include <KWindowEffects>
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<QString, QVariant> hints;
if (!soundName.isEmpty()) {
hints.insert("sound-name",soundName); //添加声音
}
QList<QVariant> args;
args<<(tr("Kylin VPN"))
<<((unsigned int) 0)
<<QString("gnome-dev-ethernet")
<<tr("kylin vpn applet desktop message") //显示的是什么类型的信息
<<message //显示的具体信息
<<actions
<<hints
<<(int)-1;
iface.callWithArgumentList(QDBus::AutoDetect,"Notify",args);
}
void SinglePage::paintEvent(QPaintEvent *event) {
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::transparent);
QColor col = qApp->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);
}

View File

@ -34,25 +34,18 @@
#include <QProcess>
#include <QDebug>
#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

View File

@ -18,29 +18,20 @@
*
*/
#include "vpnpage.h"
#include "networkmodeconfig.h"
#include <QDebug>
#include <QScrollBar>
#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<QString, QListWidgetItem *> &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<QString, QListWidgetItem *> &connectM
}
void VpnPage::clearConnectionMap(QMap<QString, QListWidgetItem *> &connectMap,
QListWidget *lanListWidget)
QListWidget *vpnListWidget)
{
QMap<QString, QListWidgetItem *>::iterator iter;
@ -89,11 +86,11 @@ void VpnPage::clearConnectionMap(QMap<QString, QListWidgetItem *> &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<QString, QListWidgetItem *> &connectMap,
return;
}
void VpnPage::constructActiveConnectionArea()
void VpnPage::constructItemArea()
{
QList<KyConnectItem *> activedList;
QList<KyConnectItem *> 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()<<LOG_FLAG << "has contain uuid" << p_netConnectionItem->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()<<LOG_FLAG << "has contain uuid" << p_netConnectionItem->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);
}
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 {
if (vpnGsettings != nullptr
&& vpnGsettings->keys().contains(QString(VISIBLE))) {
vpnGsettings->set(VISIBLE, false);
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<QString, QListWidgetItem *> &connectMap,
QListWidget *lanListWidget, QString path)
QListWidget *vpnListWidget, QString path)
{
QMap<QString, QListWidgetItem *>::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:"<<p_newItem->m_connectName;
QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_vpnListWidget);
if (m_netConnectionMap.contains(p_newItem->m_connectUuid)) {
qDebug()<<LOG_FLAG << "the connection is exsit" << p_newItem->m_connectUuid;
QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget);
if (m_vpnItemMap.contains(p_newItem->m_connectUuid)) {
qDebug()<<LOG_FLAG << "the connection is exist" << p_newItem->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"<<p_newItem->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"<<p_newItem->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<QString, QListWidgetItem *> &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()<<LOG_FLAG << "has contained connection" << newUuid;
}
m_netConnectionMap.insert(newUuid, p_sortListWidgetItem);
} else if (p_connectItem->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()<<LOG_FLAG << "has contained connection uuid" << newUuid;
}
m_netConnectionMap.insert(newUuid, p_listWidgetItem);
m_vpnItemMap.insert(newUuid, p_listWidgetItem);
}
} else {
qWarning() << LOG_FLAG << newUuid <<" is in activemap, so not process.";
@ -529,15 +516,15 @@ void VpnPage::updateActiveConnectionProperty(KyConnectItem *p_connectItem)
{
QString newUuid = p_connectItem->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;
QListWidgetItem * vpnlistItem = m_vpnItemMap.value(uuid);
VpnListItem *vpnItem = (VpnListItem *)m_listWidget->itemWidget(vpnlistItem);
vpnItem->onInfoButtonClicked();
}
if (nullptr == p_item) {
qWarning()<<"[VpnPage] GetConnectionItemByUuid is empty when showDetailPage."
<<"device name"<<devName
<<"connect uuid"<<uuid;
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;
}
NetDetail *netDetail = new NetDetail(devName, p_item->m_connectName, uuid, isActive, false, false);
netDetail->show();
void VpnPage::resetWindowPosition()
{
delete p_item;
p_item = nullptr;
#endif
#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<QVariantList> 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);
}
}

View File

@ -29,11 +29,19 @@
#include <QMap>
#include <QGSettings>
#include <KWindowSystem>
#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<QString, QListWidgetItem *> &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<QString, QListWidgetItem *> &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<QString, QListWidgetItem *> &connectMap,
QListWidget *lanListWidget);
QListWidget *vpnListWidget);
void deleteConnectionMapItem(QMap<QString, QListWidgetItem *> &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<QString, QListWidgetItem *> m_netConnectionMap;
QMap<QString, QListWidgetItem *> m_activeConnectionMap;
QMap<QString, QListWidgetItem *> m_vpnItemMap;
QMap<QString, QListWidgetItem *> m_activeItemMap;
QDBusInterface * m_positionInterface = nullptr;
public Q_SLOTS:
inline void onDeviceComboxIndexChanged(int currentIndex) { return; }
void showUI();
};
#endif // LANPAGE_H

View File

@ -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();
}

View File

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

View File

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

View File

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

View File

@ -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模式
}
}

View File

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

View File

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

View File

@ -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);
}
}

View File

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

View File

@ -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);
}
}

View File

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

View File

@ -0,0 +1,138 @@
#include "vpnobject.h"
#include <QApplication>
#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<QStringList> &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();
}

View File

@ -0,0 +1,75 @@
#ifndef VPNOBJECT_H
#define VPNOBJECT_H
#include <QObject>
#include <QWidget>
#include <QScreen>
#include <QSystemTrayIcon>
#include <QMainWindow>
#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<QStringList> &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

18
src-vpn/kylin-vpn.desktop Normal file
View File

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

137
src-vpn/main.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/&gt;.
*
*/
//#include "mainwindow.h"
//#include "dbusadaptor.h"
#include "vpndbusadaptor.h"
#include <QTranslator>
#include <QLocale>
#include "qt-single-application.h"
#include <QDebug>
#include <QDesktopWidget>
#include <QFile>
#include <ukui-log4qt.h>
#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();
}

View File

@ -0,0 +1,9 @@
<schemalist gettext-domain="kylin-vpn">
<schema id="org.ukui.kylin-nm.vpnicon" path="/org/ukui/kylin-nm/vpnicon/">
<key type="b" name="visible">
<default>false</default>
<summary>vpnicon visible</summary>
<description>vpnicon visible.true is visible,false is invisible.</description>
</key>
</schema>
</schemalist>

View File

@ -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 <QCoreApplication>
#include <QDataStream>
#include <QTime>
#if defined(Q_OS_UNIX)
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#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); //获取新进程的启动信息并作为信号发送给前端
}

View File

@ -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 <QLocalServer>
#include <QLocalSocket>
#include <QDir>
#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

View File

@ -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 <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#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();
}

View File

@ -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.
*/

View File

@ -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 <QFile>
#ifdef Q_OS_WIN
#include <QVector>
#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<Qt::HANDLE> rmutexes;
QString mutexname;
Qt::HANDLE getMutexHandle(int idx, bool doCreate);
bool waitMutex(Qt::HANDLE mutex, bool doBlock);
#endif
LockMode m_lock_mode;
};
}
#endif

View File

@ -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 <QWidget>
#include <QDesktopWidget>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusReply>
#include <QMainWindow>
#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
*/

View File

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

View File

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

73
src-vpn/src-vpn.pro Normal file
View File

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

View File

@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="bo_CN">
<context>
<name>SinglePage</name>
<message>
<location filename="../frontend/single-pages/singlepage.cpp" line="73"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/single-pages/singlepage.cpp" line="121"/>
<source>Kylin VPN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/single-pages/singlepage.cpp" line="124"/>
<source>kylin vpn applet desktop message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>VpnListItem</name>
<message>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="61"/>
<source>Not connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="160"/>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="176"/>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="162"/>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="174"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>VpnPage</name>
<message>
<location filename="../frontend/single-pages/vpnpage.cpp" line="259"/>
<source>VPN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/single-pages/vpnpage.cpp" line="270"/>
<source>VPN Settings</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>vpnAddPage</name>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="15"/>
<source>create VPN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="47"/>
<source>VPN Type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="75"/>
<source>VPN Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="81"/>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="103"/>
<source>Required</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="98"/>
<source>VPN Server</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetailpage.cpp" line="12"/>
<source>VPN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetailpage.cpp" line="41"/>
<source>Auto Connection</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetailpage.cpp" line="53"/>
<source>Confirm</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetailpage.cpp" line="56"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>vpnConfigPage</name>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="35"/>
<source>VPN Type</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>VpnDetail</name>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="15"/>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="27"/>
<source>VPN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="28"/>
<source>IPv4</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="30"/>
<source>IPv6</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="32"/>
<source>Advanced</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>vpnObject</name>
<message>
<location filename="../frontend/vpnobject.cpp" line="31"/>
<source>vpn tool</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

Binary file not shown.

View File

@ -0,0 +1,835 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>SinglePage</name>
<message>
<location filename="../frontend/single-pages/singlepage.cpp" line="73"/>
<source>Settings</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/single-pages/singlepage.cpp" line="121"/>
<source>Kylin VPN</source>
<translation>VPN工具</translation>
</message>
<message>
<location filename="../frontend/single-pages/singlepage.cpp" line="124"/>
<source>kylin vpn applet desktop message</source>
<translation>vpn配置桌面提示</translation>
</message>
</context>
<context>
<name>VpnAdvancedPage</name>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="791"/>
<source>MPPE encryption algorithm:</source>
<translation>MPPE加密算法</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="792"/>
<source>Use Stateful encryption</source>
<translation>使</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="793"/>
<source>Send PPP echo packets</source>
<translation>PPP回显包</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="794"/>
<source>Authentication Mode:</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="795"/>
<source>PAP authentication</source>
<translation>PAP认证</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="796"/>
<source>CHAP authentication</source>
<translation>CHAP认证</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="797"/>
<source>MSCHAP authentication</source>
<translation>MSCHAP认证</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="798"/>
<source>MSCHAP2 authentication</source>
<translation>MSCHAP2认证</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="799"/>
<source>EAP authentication</source>
<translation>EAP认证</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="800"/>
<source>Compression Mode:</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="801"/>
<source>Allow BSD data compression</source>
<translation>BSD压缩</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="802"/>
<source>Allow Default data compression</source>
<translation>Default压缩</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="803"/>
<source>Allow TCP header compression</source>
<translation>TCP头压缩</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="804"/>
<source>Use protocol field compression negotiation</source>
<translation>使</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="805"/>
<source>Use Address/Control compression</source>
<translation>使/</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="811"/>
<source>All Available</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="812"/>
<source>128-bit</source>
<translation>128</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="813"/>
<source>40-bit</source>
<translation>40</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1010"/>
<source>Use custom gateway port</source>
<translation>使</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1011"/>
<source>Use compression</source>
<translation>使</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1012"/>
<source>Use a TCP connection</source>
<translation>使TCP连接</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1013"/>
<source>Set virtual device type</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1014"/>
<source>Set virtual device name</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1015"/>
<source>Limit TCP Maximum Segment Size(MSS)</source>
<translation>TCP最大段尺寸MSS</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1016"/>
<source>Randomize remote hosts</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1017"/>
<source>IPv6 tun link</source>
<translation>IPv6 tun连接</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1018"/>
<source>Specify ping interval</source>
<translation>Ping周期</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1019"/>
<source>Specify exit or restart ping</source>
<translation>退Ping</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1020"/>
<source>Specify max routes</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1021"/>
<source>Infinite retry on error</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1022"/>
<source>Use custom key size</source>
<translation>使</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1023"/>
<source>Choose</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1026"/>
<source>Use custom renegotiation interval</source>
<translation>使</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1028"/>
<source>Use custom tunnel Maximum Transmission Umit(MTU)</source>
<translation>使MTU</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1030"/>
<source>Use custom UDP fragment size</source>
<translation>使UDP分片大小</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1032"/>
<source>Accept authenticated packets from any address (Float)</source>
<translation>Float</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1034"/>
<source>Subject Match</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1035"/>
<source>Key File</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1036"/>
<source>Key Direction</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1038"/>
<source>Server Address</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1039"/>
<source>Port</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1040"/>
<source>Proxy USername</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1041"/>
<source>Proxy Password</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1043"/>
<source>General</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1044"/>
<source>TLS settings</source>
<translation>TLS设置</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1045"/>
<source>Server Certificate Check</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1047"/>
<source>Use the previous authentication end (server) certificate</source>
<translation>使</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1049"/>
<source>Verify peer (server) certificate nsCertType specification</source>
<translation>nsCertType指定</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1050"/>
<source>Mode</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1051"/>
<source>Proxies</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1052"/>
<source>Proxy Type</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1053"/>
<source>Security</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1054"/>
<source>HMAC Authentication</source>
<translation>HMAC认证</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1064"/>
<source>Input content</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1066"/>
<source>No</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1070"/>
<source>Self-adaption</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1071"/>
<source>Automatic</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1076"/>
<source>Exit</source>
<translation>退</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1077"/>
<source>Restart</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1079"/>
<source>Don&apos;t verify certificate identification</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1080"/>
<source>Verify the entire subject exactly</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1081"/>
<source>Verify name exactly</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1082"/>
<source>Verify name by prefix</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1084"/>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1087"/>
<source>Server</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1085"/>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1088"/>
<source>Client</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1090"/>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1094"/>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1103"/>
<source>None</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1091"/>
<source>TLS-Certification</source>
<translation>TLS-</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1092"/>
<source>TLS-Encryption</source>
<translation>TLS-</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1098"/>
<source>Not Required</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1102"/>
<source>Default</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1176"/>
<source>Options:</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1179"/>
<source>Request an inner IP address</source>
<translation>IP地址</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1180"/>
<source>Enforce UDP encapsulation</source>
<translation>UDP封装</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1181"/>
<source>Use IP compression</source>
<translation>使IP压缩</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnadvancedpage.cpp" line="1182"/>
<source>Enable custom password suggestions</source>
<translation></translation>
</message>
</context>
<context>
<name>VpnConfigPage</name>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="312"/>
<source>Type</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="313"/>
<source>Name</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="314"/>
<source>Static Key</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="315"/>
<source>Local IP</source>
<translation>IP地址</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="316"/>
<source>Remote IP</source>
<translation>IP地址</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="317"/>
<source>PIN Code</source>
<translation>PIN码</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="318"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="790"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="797"/>
<source>Password</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="319"/>
<source>NT Domain</source>
<translation>NT域</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="321"/>
<source>Server Address</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="322"/>
<source>Authentication Mode</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="323"/>
<source>CA Certificate</source>
<translation>CA证书</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="324"/>
<source>User Certificate</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="325"/>
<source>Key Direction</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="326"/>
<source>Private Key</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="327"/>
<source>Private Key Password</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="328"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="330"/>
<source>Password Options</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="329"/>
<source>Username</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="333"/>
<source>Notice:
If key direction is used, it must be opposite to the VPN side used. If &apos;1&apos; is used, the connection must use &apos;0&apos;. If you are not sure which value to use, please contact your system administrator.</source>
<translation>
使使VPN端相反使1使0使</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="340"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="341"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="342"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="343"/>
<source>Choose</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="350"/>
<source>None</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="354"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="360"/>
<source>Save password only for this user</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="355"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="361"/>
<source>Save password for all users</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="356"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="362"/>
<source>Ask password every time</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="357"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="363"/>
<source>Don&apos;t require a password</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="366"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="367"/>
<source>Required</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="795"/>
<source>Certificate(TLS)</source>
<translation>TLS</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="796"/>
<source>Static key</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="798"/>
<source>Password and certificate(TLS)</source>
<translation>TLS</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="807"/>
<source>Certificate/Private key</source>
<translation>/</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="808"/>
<source>Certificate/ssh-agent</source>
<translation>/ssh-agent</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="809"/>
<source>Smart card</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="864"/>
<source>Choose a private key</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="866"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="905"/>
<source>Key Files (*.key *.pem *.der *.p12 *.pfx)</source>
<translation>(*.key *.pem *.der *.p12 *.pfx)</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="877"/>
<source>Choose a CA certificate</source>
<translation>CA证书</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="879"/>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="892"/>
<source>CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)</source>
<translation>CA文件 (*.pem *.der *.p12 *.crt *.cer *.pfx)</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="890"/>
<source>Choose a User certificate</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnconfigpage.cpp" line="903"/>
<source>Choose a Static key</source>
<translation></translation>
</message>
</context>
<context>
<name>VpnIpv4Page</name>
<message>
<location filename="../frontend/vpndetails/vpnipv4page.cpp" line="152"/>
<source>IPv4 Config</source>
<translation>IPv4配置</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv4page.cpp" line="153"/>
<source>Address</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv4page.cpp" line="154"/>
<source>Netmask</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv4page.cpp" line="155"/>
<source>Default Gateway</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv4page.cpp" line="156"/>
<source>DNS Server</source>
<translation>DNS服务器</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv4page.cpp" line="157"/>
<source>Search Domain</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv4page.cpp" line="158"/>
<source>DHCP Client ID</source>
<translation>DHCP客户端ID</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv4page.cpp" line="160"/>
<source>Auto(DHCP)</source>
<translation>(DHCP)</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv4page.cpp" line="161"/>
<source>Manual</source>
<translation></translation>
</message>
</context>
<context>
<name>VpnIpv6Page</name>
<message>
<location filename="../frontend/vpndetails/vpnipv6page.cpp" line="141"/>
<source>IPv6 Config</source>
<translation>IPv6配置</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv6page.cpp" line="142"/>
<source>Address</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv6page.cpp" line="143"/>
<source>Netmask</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv6page.cpp" line="144"/>
<source>Default Gateway</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv6page.cpp" line="145"/>
<source>DNS Server</source>
<translation>DNS服务器</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv6page.cpp" line="146"/>
<source>Search Domain</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv6page.cpp" line="148"/>
<source>Auto(DHCP)</source>
<translation>(DHCP)</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnipv6page.cpp" line="149"/>
<source>Manual</source>
<translation></translation>
</message>
</context>
<context>
<name>VpnListItem</name>
<message>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="61"/>
<source>Not connected</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="160"/>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="176"/>
<source>Disconnect</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="162"/>
<location filename="../frontend/list-items/vpnlistitem.cpp" line="174"/>
<source>Connect</source>
<translation></translation>
</message>
</context>
<context>
<name>VpnPage</name>
<message>
<location filename="../frontend/single-pages/vpnpage.cpp" line="259"/>
<source>VPN</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/single-pages/vpnpage.cpp" line="270"/>
<source>VPN Settings</source>
<translation>VPN设置</translation>
</message>
</context>
<context>
<name>vpnAddPage</name>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="15"/>
<source>create VPN</source>
<translation>VPN</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="47"/>
<source>VPN Type</source>
<translation>VPN类型</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="75"/>
<source>VPN Name</source>
<translation>VPN名称</translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="81"/>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="103"/>
<source>Required</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpnaddpage.cpp" line="98"/>
<source>VPN Server</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetailpage.cpp" line="12"/>
<source>VPN</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetailpage.cpp" line="41"/>
<source>Auto Connection</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetailpage.cpp" line="53"/>
<source>Confirm</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetailpage.cpp" line="56"/>
<source>Cancel</source>
<translation></translation>
</message>
</context>
<context>
<name>vpnConfigPage</name>
<message>
<source>VPN Type</source>
<translation type="vanished">VPN类型</translation>
</message>
</context>
<context>
<name>VpnDetail</name>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="61"/>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="145"/>
<source>VPN</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="146"/>
<source>IPv4</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="148"/>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="225"/>
<source>IPv6</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="153"/>
<source>Advanced</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="158"/>
<source>Auto Connection</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="159"/>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<location filename="../frontend/vpndetails/vpndetail.cpp" line="160"/>
<source>Confirm</source>
<translation></translation>
</message>
</context>
<context>
<name>vpnObject</name>
<message>
<location filename="../frontend/vpnobject.cpp" line="31"/>
<source>vpn tool</source>
<translation>VPN工具</translation>
</message>
</context>
</TS>

6
src-vpn/vpnqrc.qrc Normal file
View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/">
<file>translations/kylin-vpn_zh_CN.qm</file>
<file>translations/kylin-vpn_bo_CN.qm</file>
</qresource>
</RCC>

View File

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

View File

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

View File

@ -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<NetworkManager::Security8021xSetting>();
QList<NetworkManager::Security8021xSetting::EapMethod> 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<NetworkManager::WirelessSecuritySetting>();
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<NetworkManager::Security8021xSetting>();
QList<NetworkManager::Security8021xSetting::EapMethod> 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<NetworkManager::WirelessSecuritySetting>();
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<NetworkManager::Security8021xSetting>();
QList<NetworkManager::Security8021xSetting::EapMethod> list;
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodFast);
wifi_8021x_sett->setInitialized(true);
wifi_8021x_sett->setEapMethods(list);
wifi_8021x_sett->setAnonymousIdentity(fastInfo.m_anonIdentity);
if (fastInfo.m_allowAutoPacFlag) {
wifi_8021x_sett->setPhase1FastProvisioning((NetworkManager::Security8021xSetting::FastProvisioning)fastInfo.m_pacProvisioning);
} else {
wifi_8021x_sett->setPhase1FastProvisioning(NetworkManager::Security8021xSetting::FastProvisioning::FastProvisioningDisabled);
}
QByteArray pacEndWithNull("file://" + fastInfo.m_pacFilePath.toUtf8() + '\0');
wifi_8021x_sett->setPacFile(pacEndWithNull);
wifi_8021x_sett->setPhase2AuthMethod((NetworkManager::Security8021xSetting::AuthMethod)fastInfo.m_authMethod);
wifi_8021x_sett->setIdentity(fastInfo.m_userName);
wifi_8021x_sett->setPassword(fastInfo.m_userPwd);
wifi_8021x_sett->setPasswordFlags(fastInfo.m_passwdFlag);
NetworkManager::WirelessSecuritySetting::Ptr security_sett
= connSettingPtr->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
security_sett->setInitialized(true);
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap);
return;
}
void modifyEapMethodLeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodLeapInfo &leapInfo)
{
NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett
= connSettingPtr->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
wifi_8021x_sett->setInitialized(true);
QList<NetworkManager::Security8021xSetting::EapMethod> list;
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodLeap);
wifi_8021x_sett->setEapMethods(list);
wifi_8021x_sett->setIdentity(leapInfo.m_userName);
if(leapInfo.bChanged)
{
wifi_8021x_sett->setPassword(leapInfo.m_userPwd);
}
wifi_8021x_sett->setPasswordFlags(leapInfo.m_passwdFlag);
QByteArray caCerEndWithNull("");
wifi_8021x_sett->setCaCertificate(caCerEndWithNull);
return;
}
void modifyEapMethodPwdSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPwdInfo &pwdInfo)
{
NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett
= connSettingPtr->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
wifi_8021x_sett->setInitialized(true);
QList<NetworkManager::Security8021xSetting::EapMethod> list;
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodPwd);
wifi_8021x_sett->setEapMethods(list);
wifi_8021x_sett->setIdentity(pwdInfo.m_userName);
if(pwdInfo.bChanged)
{
wifi_8021x_sett->setPassword(pwdInfo.m_userPwd);
}
wifi_8021x_sett->setPasswordFlags(pwdInfo.m_passwdFlag);
QByteArray caCerEndWithNull("");
wifi_8021x_sett->setCaCertificate(caCerEndWithNull);
return;
}
void modifyEapMethodFastSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodFastInfo &fastInfo)
{
NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett
= connSettingPtr->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
wifi_8021x_sett->setInitialized(true);
QList<NetworkManager::Security8021xSetting::EapMethod> list;
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodFast);
wifi_8021x_sett->setEapMethods(list);
wifi_8021x_sett->setAnonymousIdentity(fastInfo.m_anonIdentity);
if (fastInfo.m_allowAutoPacFlag) {
wifi_8021x_sett->setPhase1FastProvisioning((NetworkManager::Security8021xSetting::FastProvisioning)fastInfo.m_pacProvisioning);
} else {
wifi_8021x_sett->setPhase1FastProvisioning(NetworkManager::Security8021xSetting::FastProvisioning::FastProvisioningDisabled);
}
QByteArray pacEndWithNull("file://" + fastInfo.m_pacFilePath.toUtf8() + '\0');
wifi_8021x_sett->setPacFile(pacEndWithNull);
wifi_8021x_sett->setPhase2AuthMethod((NetworkManager::Security8021xSetting::AuthMethod)fastInfo.m_authMethod);
wifi_8021x_sett->setIdentity(fastInfo.m_userName);
if(fastInfo.bChanged)
{
wifi_8021x_sett->setPassword(fastInfo.m_userPwd);
}
wifi_8021x_sett->setPasswordFlags(fastInfo.m_passwdFlag);
return;
}

View File

@ -30,6 +30,9 @@ enum KyEapMethodType {
TLS = 0,
PEAP,
TTLS,
LEAP,
PWD,
FAST,
};
class KyEapMethodTlsInfo
@ -154,12 +157,99 @@ public:
}
};
typedef enum {
KyFastProvisioningUnknown = -1,
KyFastProvisioningDisabled,
KyFastProvisioningAllowUnauthenticated,
KyFastProvisioningAllowAuthenticated,
KyFastProvisioningAllowBoth
}KyFastProvisioning;
class KyEapMethodLeapInfo
{
public:
QString m_userName;
QString m_userPwd;
NetworkManager::Setting::SecretFlags m_passwdFlag;
// only valid when update
bool bChanged;
inline bool operator == (const KyEapMethodLeapInfo& info) const
{
if (this->m_userName == info.m_userName
&& this->m_userPwd == info.m_userPwd
&& this->m_passwdFlag == info.m_passwdFlag) {
return true;
} else {
return false;
}
}
};
class KyEapMethodPwdInfo
{
public:
QString m_userName;
QString m_userPwd;
NetworkManager::Setting::SecretFlags m_passwdFlag;
// only valid when update
bool bChanged;
inline bool operator == (const KyEapMethodPwdInfo& info) const
{
if (this->m_userName == info.m_userName
&& this->m_userPwd == info.m_userPwd
&& this->m_passwdFlag == info.m_passwdFlag) {
return true;
} else {
return false;
}
}
};
class KyEapMethodFastInfo
{
public:
QString m_anonIdentity;
KyFastProvisioning m_pacProvisioning;
bool m_allowAutoPacFlag;
QString m_pacFilePath;
KyNoEapMethodAuth m_authMethod;
QString m_userName;
QString m_userPwd;
NetworkManager::Setting::SecretFlags m_passwdFlag;
// only valid when update
bool bChanged;
inline bool operator == (const KyEapMethodFastInfo& info) const
{
if (this->m_anonIdentity == info.m_anonIdentity
&& this->m_pacProvisioning == info.m_pacProvisioning
&& this->m_allowAutoPacFlag == info.m_allowAutoPacFlag
&& this->m_pacFilePath == info.m_pacFilePath
&& this->m_authMethod == info.m_authMethod
&& this->m_userName == info.m_userName
&& this->m_userPwd == info.m_userPwd
&& this->m_passwdFlag == info.m_passwdFlag) {
return true;
} else {
return false;
}
}
};
void assembleEapMethodTlsSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodTlsInfo &tlsInfo);
void assembleEapMethodPeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPeapInfo &peapInfo);
void assembleEapMethodTtlsSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodTtlsInfo &ttlsInfo);
void assembleEapMethodLeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodLeapInfo &leapInfo);
void assembleEapMethodPwdSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPwdInfo &pwdInfo);
void assembleEapMethodFastSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodFastInfo &fastInfo);
void modifyEapMethodTlsSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodTlsInfo &tlsInfo);
void modifyEapMethodPeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPeapInfo &peapInfo);
void modifyEapMethodTtlsSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodTtlsInfo &ttlsInfo);
void modifyEapMethodLeapSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodLeapInfo &leapInfo);
void modifyEapMethodPwdSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodPwdInfo &pwdInfo);
void modifyEapMethodFastSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodFastInfo &fastInfo);
#endif // KYENTERPRICESETTINGINFO_H

Some files were not shown because too many files have changed in this diff Show More