diff --git a/.gitignore b/.gitignore
new file mode 100755
index 00000000..b9616cd3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,54 @@
+# C++ objects and libs
+*.slo
+*.lo
+*.o
+*.a
+*.la
+*.lai
+*.so
+*.so.*
+*.dll
+*.dylib
+
+# Qt-es
+object_script.*.Release
+object_script.*.Debug
+*_plugin_import.cpp
+/.qmake.cache
+/.qmake.stash
+*.pro.user
+*.pro.user.*
+*.qbs.user
+*.qbs.user.*
+*.moc
+moc_*.cpp
+moc_*.h
+qrc_*.cpp
+ui_*.h
+*.qmlc
+*.jsc
+Makefile*
+*build-*
+*.prl
+
+# Qt unit tests
+target_wrapper.*
+
+# QtCreator
+*.autosave
+
+# QtCreator Qml
+*.qmlproject.user
+*.qmlproject.user.*
+
+# QtCreator CMake
+CMakeLists.txt.user*
+
+# QtCreator 4.8< compilation database
+compile_commands.json
+
+# QtCreator local machine specific files for imported projects
+*creator.user*
+
+# OS X extra file
+.DS_Store
diff --git a/kylin-nm.pro b/kylin-nm.pro
index 4999ff17..d995544b 100644
--- a/kylin-nm.pro
+++ b/kylin-nm.pro
@@ -1,13 +1,26 @@
TEMPLATE = subdirs
-CONFIG += ordered \
- qt
+
+CONFIG += \
+ ordered \
+ qt
SUBDIRS = \
- plugins/plugin.pro \
- src \
+ plugins/plugin.pro \
+ src-vpn/src-vpn.pro \
+ src
TRANSLATIONS += \
translations/kylin-nm_zh_CN.ts \
translations/kylin-nm_tr.ts \
- translations/kylin-nm_bo.ts
+ translations/kylin-nm_bo.ts \
+ translations/kylin-nm_bo_CN.ts
+
+CONFIG(release, debug|release) {
+ !system($$PWD/translate_generation.sh): error("Failed to generate translation")
+}
+
+qm_files.path = $${PREFIX}/share/kylin-nm/kylin-nm/
+qm_files.files = translations/*.qm
+
+INSTALLS += qm_files \
diff --git a/nmqrc.qrc b/nmqrc.qrc
index db90969b..aea1ec48 100644
--- a/nmqrc.qrc
+++ b/nmqrc.qrc
@@ -17,9 +17,6 @@
res/h/right-pwd.png
res/h/show-pwd.png
res/h/no-pwd-wifi.png
- translations/kylin-nm_bo.qm
- translations/kylin-nm_tr.qm
- translations/kylin-nm_zh_CN.qm
res/x/fly-mode-off.svg
res/x/fly-mode-on.svg
res/x/hot-spot-off.svg
diff --git a/plugins/component/AddBtn/addnetbtn.cpp b/plugins/component/AddBtn/addnetbtn.cpp
index eb1bc6fb..f60ba82d 100644
--- a/plugins/component/AddBtn/addnetbtn.cpp
+++ b/plugins/component/AddBtn/addnetbtn.cpp
@@ -20,6 +20,7 @@
#include "addnetbtn.h"
#include
#include
+#include
#include
#include
#include
@@ -33,35 +34,30 @@ AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent)
this->setMaximumSize(QSize(16777215, 60));
this->setProperty("useButtonPalette", true);
this->setFlat(true);
- QPalette pal = this->palette();
- QColor color = pal.color(QPalette::Button);
- color.setAlphaF(0.5);
- pal.setColor(QPalette::Button, color);
- this->setPalette(pal);
- QHBoxLayout *addLyt = new QHBoxLayout(this);
+
+ QHBoxLayout *addLyt = new QHBoxLayout;
QLabel *iconLabel = new QLabel(this);
- textLabel = new QLabel(this);
+ m_textLabel = new QLabel(this);
if (isWlan) {
- textLabel->setText(tr("Add Others"));
+ m_textLabel->setText(tr("Add Others"));
addLyt->addSpacing(8);
- addLyt->addWidget(textLabel);
+ addLyt->addWidget(m_textLabel);
} else {
- textLabel->setText(tr("Add WiredNetork"));
+ m_textLabel->setText(tr("Add WiredNetork"));
QIcon mAddIcon = QIcon::fromTheme("list-add-symbolic");
- iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(24, 24))));
- iconLabel->setProperty("useIconHighlightEffect", true);
- iconLabel->setProperty("iconHighlightEffectMode", 1);
+ iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(16, 16))));
+ iconLabel->setProperty("useIconHighlightEffect", 0x2);
+// iconLabel->setProperty("iconHighlightEffectMode", 1);
addLyt->addStretch();
addLyt->addWidget(iconLabel);
- addLyt->addWidget(textLabel);
+ addLyt->addWidget(m_textLabel);
}
addLyt->addStretch();
this->setLayout(addLyt);
-
}
AddNetBtn::~AddNetBtn()
@@ -83,12 +79,18 @@ void AddNetBtn::leaveEvent(QEvent *event){
void AddNetBtn::paintEvent(QPaintEvent *event)
{
- QPalette pal = this->palette();
+ QPalette pal = qApp->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
- painter.setBrush(pal.color(QPalette::Base));
+
+ painter.setBrush(this->palette().base().color());
+
+ QColor color = pal.color(QPalette::Button);
+ color.setAlphaF(0.5);
+ pal.setColor(QPalette::Button, color);
+ this->setPalette(pal);
QRect rect = this->rect();
QPainterPath path;
diff --git a/plugins/component/AddBtn/addnetbtn.h b/plugins/component/AddBtn/addnetbtn.h
index 60ba8028..85876755 100644
--- a/plugins/component/AddBtn/addnetbtn.h
+++ b/plugins/component/AddBtn/addnetbtn.h
@@ -34,8 +34,8 @@ public:
AddNetBtn(bool isWlan, QWidget *parent = nullptr);
~AddNetBtn();
- void setTextLabel(QString str) {
- textLabel->setText(str);
+ void setTextLabel(const QString str) {
+ m_textLabel->setText(str);
}
protected:
@@ -44,7 +44,7 @@ protected:
void paintEvent(QPaintEvent *event);
private:
- QLabel* textLabel;
+ QLabel *m_textLabel;
Q_SIGNALS:
void enterWidget();
diff --git a/plugins/component/AddBtn/grayinfobutton.cpp b/plugins/component/AddBtn/grayinfobutton.cpp
new file mode 100644
index 00000000..daa4fa1d
--- /dev/null
+++ b/plugins/component/AddBtn/grayinfobutton.cpp
@@ -0,0 +1,33 @@
+/* -*- 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 "grayinfobutton.h"
+
+#include
+
+#define BUTTON_SIZE 36,36
+#define ICON_SIZE 16,16
+
+GrayInfoButton::GrayInfoButton(QWidget *parent): QPushButton(parent)
+{
+ this->setFixedSize(BUTTON_SIZE);
+ this->setIcon(QIcon::fromTheme("preferences-system-details-symbolic"));
+ this->setProperty("useButtonPalette", true);
+ this->setFlat(true);
+}
diff --git a/plugins/component/AddBtn/grayinfobutton.h b/plugins/component/AddBtn/grayinfobutton.h
new file mode 100644
index 00000000..0024f8b7
--- /dev/null
+++ b/plugins/component/AddBtn/grayinfobutton.h
@@ -0,0 +1,34 @@
+/* -*- 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 GRAYINFOBUTTON_H
+#define GRAYINFOBUTTON_H
+
+#include
+#include
+
+class GrayInfoButton : public QPushButton
+{
+ Q_OBJECT
+public:
+ explicit GrayInfoButton(QWidget * parent = nullptr);
+ ~GrayInfoButton() = default;
+};
+
+#endif // GRAYINFOBUTTON_H
diff --git a/plugins/component/DrownLabel/drownlabel.cpp b/plugins/component/DrownLabel/drownlabel.cpp
index 4e46523a..356c7d23 100644
--- a/plugins/component/DrownLabel/drownlabel.cpp
+++ b/plugins/component/DrownLabel/drownlabel.cpp
@@ -1,3 +1,22 @@
+/* -*- 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 "drownlabel.h"
#include "deviceframe.h"
diff --git a/plugins/component/DrownLabel/drownlabel.h b/plugins/component/DrownLabel/drownlabel.h
index 806dc132..b4daf2a2 100644
--- a/plugins/component/DrownLabel/drownlabel.h
+++ b/plugins/component/DrownLabel/drownlabel.h
@@ -1,3 +1,23 @@
+
+/* -*- 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 DROWNLABEL_H
#define DROWNLABEL_H
diff --git a/plugins/component/InfoButton/infobutton.cpp b/plugins/component/InfoButton/infobutton.cpp
index 26ac05a2..edb8b2db 100644
--- a/plugins/component/InfoButton/infobutton.cpp
+++ b/plugins/component/InfoButton/infobutton.cpp
@@ -1,9 +1,28 @@
+/* -*- 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 "infobutton.h"
#include
#include
-#include
#include
#include
+#include
#define BUTTON_SIZE 36,36
#define ICON_SIZE 16,16
diff --git a/plugins/component/InfoButton/infobutton.h b/plugins/component/InfoButton/infobutton.h
index 6376b028..f4607ade 100644
--- a/plugins/component/InfoButton/infobutton.h
+++ b/plugins/component/InfoButton/infobutton.h
@@ -1,3 +1,22 @@
+/* -*- 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 INFOBUTTON_H
#define INFOBUTTON_H
#include
diff --git a/plugins/component/addbtn.pri b/plugins/component/addbtn.pri
index c22c6e7c..f3961167 100644
--- a/plugins/component/addbtn.pri
+++ b/plugins/component/addbtn.pri
@@ -2,8 +2,10 @@
SOURCES += \
$$PWD/AddBtn/addnetbtn.cpp \
+ $$PWD/AddBtn/grayinfobutton.cpp
HEADERS += \
$$PWD/AddBtn/addnetbtn.h \
+ $$PWD/AddBtn/grayinfobutton.h
diff --git a/plugins/mobilehotspot/blacklistitem.cpp b/plugins/mobilehotspot/blacklistitem.cpp
new file mode 100644
index 00000000..bc59735d
--- /dev/null
+++ b/plugins/mobilehotspot/blacklistitem.cpp
@@ -0,0 +1,70 @@
+/* -*- 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 "blacklistitem.h"
+#include
+
+#define MAIN_LAYOUT_MARGINS 0,0,0,0
+#define MAIN_LAYOUT_SPACING 0
+#define ITEM_FRAME_MARGINS 0,0,0,0
+#define ITEM_FRAME_SPACING 10
+#define FRAME_WIDTH 395
+#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)
+
+#define FRAME_MIN_SIZE 550, 60
+#define CONTECT_FRAME_MAX_SIZE 16777215, 60
+#define LABLE_MIN_WIDTH 188
+#define ITEM_MARGINS 16, 0, 16, 0
+
+BlacklistItem::BlacklistItem(QString staMac, QString staName, QWidget *parent) :
+ QFrame(parent),
+ m_mac(staMac),
+ m_hostName(staName)
+{
+ this->setMinimumHeight(60);
+ this->setFixedHeight(60);
+
+ QHBoxLayout *hItemLayout = new QHBoxLayout(this);
+ hItemLayout->setContentsMargins(ITEM_MARGINS);
+ QLabel *nameLabel = new QLabel(staName, this);
+ m_removeFromBlacklistBtn = new KBorderlessButton(this);
+ m_removeFromBlacklistBtn->setText(tr("Remove"));
+ hItemLayout->setSpacing(0);
+ hItemLayout->addWidget(nameLabel, Qt::AlignLeft);
+ hItemLayout->addStretch();
+ hItemLayout->addWidget(m_removeFromBlacklistBtn, Qt::AlignRight);
+
+ m_removeFromBlacklistBtn->installEventFilter(this);
+ this->setLayout(hItemLayout);
+}
+
+bool BlacklistItem::eventFilter(QObject *w, QEvent *e)
+{
+ if (e->type() == QEvent::MouseButtonRelease) {
+ if (w == m_removeFromBlacklistBtn) {
+ emit onBtnClicked(m_mac, m_hostName);
+ return true;
+ }
+ }
+ return QWidget::eventFilter(w,e);
+}
+
diff --git a/plugins/mobilehotspot/blacklistitem.h b/plugins/mobilehotspot/blacklistitem.h
new file mode 100644
index 00000000..dab02aae
--- /dev/null
+++ b/plugins/mobilehotspot/blacklistitem.h
@@ -0,0 +1,52 @@
+/* -*- 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 BLACKLISTITEM_H
+#define BLACKLISTITEM_H
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "kborderlessbutton.h"
+
+using namespace kdk;
+
+class BlacklistItem : public QFrame
+{
+ Q_OBJECT
+public:
+ BlacklistItem(QString staMac, QString staName, QWidget *parent = nullptr);
+
+protected:
+ KBorderlessButton *m_removeFromBlacklistBtn = nullptr;
+
+ QString m_mac;
+ QString m_hostName;
+ bool eventFilter(QObject *w, QEvent *e);
+
+signals:
+ void onBtnClicked(QString staMac, QString staName);
+
+
+};
+
+#endif // LISTITEM_H
diff --git a/plugins/mobilehotspot/blacklistpage.cpp b/plugins/mobilehotspot/blacklistpage.cpp
new file mode 100644
index 00000000..d923749c
--- /dev/null
+++ b/plugins/mobilehotspot/blacklistpage.cpp
@@ -0,0 +1,200 @@
+/* -*- 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 "blacklistpage.h"
+#include
+
+#define CONTENTS_MARGINS 0, 0, 0, 0
+#define FRAME_MIN_SIZE 550, 60
+#define FRAME_MAX_SIZE 16777215, 16777215
+#define LINE_MAX_SIZE 16777215, 1
+#define LINE_MIN_SIZE 0, 1
+
+#define LOG_HEAD "[BlacklistPage]"
+
+BlacklistPage::BlacklistPage(QWidget *parent) : QWidget(parent)
+{
+ QVBoxLayout *Vlayout = new QVBoxLayout(this);
+ Vlayout->setContentsMargins(CONTENTS_MARGINS);
+ Vlayout->setSpacing(0);
+
+ 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(m_blacklistFrame);
+ m_blacklistLayout->setContentsMargins(0, 0, 0, 0);
+ m_blacklistLayout->setSpacing(0);
+
+ m_titleLabel = new TitleLabel(this);
+ m_titleLabel->setText(tr("Blacklist"));
+
+ Vlayout->addWidget(m_titleLabel);
+ Vlayout->addSpacing(8);
+ Vlayout->addWidget(m_blacklistFrame);
+}
+
+QFrame* BlacklistPage::myLine()
+{
+ QFrame *line = new QFrame(this);
+ line->setMinimumSize(QSize(LINE_MIN_SIZE));
+ line->setMaximumSize(QSize(LINE_MAX_SIZE));
+ line->setLineWidth(0);
+ line->setFrameShape(QFrame::HLine);
+ line->setFrameShadow(QFrame::Sunken);
+
+ return line;
+}
+
+void BlacklistPage::getBlacklistDevice(QMap &blacklistMap)
+{
+ if (m_settingPathInterface == nullptr || !m_settingPathInterface->isValid()) {
+ qDebug() << LOG_HEAD << "dbus interface m_settingPathInterface is invaild";
+ return;
+ }
+
+ QDBusMessage reply = m_settingPathInterface->call("Getblacklist");
+ if(reply.type() == QDBusMessage::ErrorMessage)
+ {
+ qWarning() << LOG_HEAD << "Getblacklist error:" << reply.errorMessage();
+ return;
+ }
+ if (reply.arguments().isEmpty()
+ || reply.arguments().at(0).toString() == ""
+ || reply.arguments().at(1).toString() == "") {
+ qDebug() << LOG_HEAD << "Dbus interface call Getblacklist return is empty!";
+ return;
+ }
+ 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 ++) {
+ QString macTemp = macList.at(index);
+ macTemp = macTemp.trimmed();
+ if (!blacklistMap.contains(macTemp) && hostNameList.at(index) != nullptr) {
+ blacklistMap[macTemp] = hostNameList.at(index);
+ }
+ }
+}
+
+void BlacklistPage::initBlacklistDev()
+{
+ QMap::const_iterator item = m_blacklistMap.cbegin();
+ while (item != m_blacklistMap.cend()) {
+ addBlacklistDevFrame(item.key(), item.value());
+ item ++;
+ if (item != m_blacklistMap.cend()) {
+ m_blacklistLayout->addWidget(myLine());
+ }
+ }
+}
+
+void BlacklistPage::onsetStaIntoBlacklist(QString staMac, QString staName)
+{
+ if (m_settingPathInterface == nullptr || !m_settingPathInterface->isValid()) {
+ qDebug() << LOG_HEAD << LOG_HEAD << "dbus interface m_settingPathInterface is invaild";
+ return;
+ }
+
+ QDBusMessage reply = m_settingPathInterface->call("Addblacklist", staMac, staName);
+ if(reply.type() == QDBusMessage::ErrorMessage)
+ {
+ qWarning() << LOG_HEAD << "Addblacklist error:" << reply.errorMessage();
+ return;
+ }
+
+ refreshBlacklist();
+}
+
+void BlacklistPage::addBlacklistDevFrame(QString staMac, QString staName)
+{
+ BlacklistItem *itemFrame = new BlacklistItem(staMac, staName, m_blacklistLayout->widget());
+ m_blacklistLayout->addWidget(itemFrame);
+ connect(itemFrame, &BlacklistItem::onBtnClicked, this, &BlacklistPage::onRemoveFromBlacklistBtnClicked);
+}
+
+void BlacklistPage::clearBlacklistLayout()
+{
+ if (m_blacklistLayout->layout() != NULL) {
+ QLayoutItem* layoutItem;
+ while ((layoutItem = m_blacklistLayout->layout()->takeAt(0)) != NULL) {
+ delete layoutItem->widget();
+ delete layoutItem;
+ }
+ }
+}
+
+bool BlacklistPage::removeStaFromBlacklist(QString staMac, QString staName)
+{
+ if (m_settingPathInterface == nullptr || !m_settingPathInterface->isValid()) {
+ qDebug() << LOG_HEAD << "dbus interface m_settingPathInterface is invaild";
+ return false;
+ }
+
+ QDBusMessage reply = m_settingPathInterface->call("Delblacklist", staMac, staName);
+ if(reply.type() == QDBusMessage::ErrorMessage)
+ {
+ qWarning() << LOG_HEAD << "Delblacklist error:" << reply.errorMessage();
+ return false;
+ }
+
+ return true;
+}
+
+void BlacklistPage::resetLayoutHight()
+{
+ int height = 0;
+ for (int i = 0; i < m_blacklistLayout->count(); i ++) {
+ QWidget *w = m_blacklistLayout->itemAt(i)->widget();
+ if (w != nullptr) {
+ height += w->height();
+ }
+ }
+ m_blacklistFrame->setFixedHeight(height);
+
+ if (m_blacklistMap.isEmpty()) {
+ this->hide();
+ } else {
+ this->show();
+ }
+ this->update();
+}
+
+void BlacklistPage::refreshBlacklist()
+{
+ m_blacklistMap.clear();
+ getBlacklistDevice(m_blacklistMap);
+ clearBlacklistLayout();
+ initBlacklistDev();
+ resetLayoutHight();
+}
+
+void BlacklistPage::onRemoveFromBlacklistBtnClicked(QString staMac, QString staName)
+{
+ if (staMac.isNull()
+ || staMac.isEmpty()
+ || staName.isNull()
+ || staName.isEmpty()) {
+ qDebug() << LOG_HEAD <<"On remove from blacklist button clicked error! sta mac or name is empty!";
+ return;
+ }
+ removeStaFromBlacklist(staMac, staName);
+ refreshBlacklist();
+}
+
diff --git a/plugins/mobilehotspot/blacklistpage.h b/plugins/mobilehotspot/blacklistpage.h
new file mode 100644
index 00000000..8a511c1d
--- /dev/null
+++ b/plugins/mobilehotspot/blacklistpage.h
@@ -0,0 +1,74 @@
+/* -*- 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 BLACKLISTPAGE_H
+#define BLACKLISTPAGE_H
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#include "titlelabel.h"
+#include "blacklistitem.h"
+
+using namespace kdk;
+
+class BlacklistPage : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit BlacklistPage(QWidget *parent = nullptr);
+
+ void refreshBlacklist();
+ bool setStaIntoBlacklist(QString staMac);
+
+ inline void setInterface(QDBusInterface *settingInterface) {
+ m_settingPathInterface = settingInterface;
+ }
+
+private:
+ QFrame* myLine();
+
+ void getBlacklistDevice(QMap &blacklistMap);
+ bool removeStaFromBlacklist(QString staMac, QString staName);
+ void initBlacklistDev();
+ void addBlacklistDevFrame(QString staMac, QString staName);
+ void clearBlacklistLayout();
+ void resetLayoutHight();
+
+private:
+ QFrame *m_blacklistFrame = nullptr;
+ TitleLabel *m_titleLabel = nullptr;
+ QVBoxLayout *m_blacklistLayout = nullptr;
+ QMap m_blacklistMap;
+
+ QDBusInterface *m_settingPathInterface = nullptr;
+
+private slots:
+ void onsetStaIntoBlacklist(QString staMac, QString staName);
+ void onRemoveFromBlacklistBtnClicked(QString staMac, QString staName);
+};
+
+#endif // MOBILEHOTSPOTWIDGET_H
diff --git a/plugins/mobilehotspot/connectdevlistitem.cpp b/plugins/mobilehotspot/connectdevlistitem.cpp
new file mode 100644
index 00000000..a8107905
--- /dev/null
+++ b/plugins/mobilehotspot/connectdevlistitem.cpp
@@ -0,0 +1,70 @@
+/* -*- 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 "connectdevlistitem.h"
+#include
+
+#define MAIN_LAYOUT_MARGINS 0,0,0,0
+#define MAIN_LAYOUT_SPACING 0
+#define ITEM_FRAME_MARGINS 0,0,0,0
+#define ITEM_FRAME_SPACING 10
+#define FRAME_WIDTH 395
+#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)
+
+#define FRAME_MIN_SIZE 550, 60
+#define CONTECT_FRAME_MAX_SIZE 16777215, 60
+#define LABLE_MIN_WIDTH 188
+#define ITEM_MARGINS 16, 0, 16, 0
+
+ConnectDevListItem::ConnectDevListItem(QString staMac, QString staName, QWidget *parent) :
+ QFrame(parent),
+ m_mac(staMac),
+ m_hostName(staName)
+{
+ this->setMinimumSize(FRAME_MIN_SIZE);
+ this->setFixedHeight(60);
+
+ QHBoxLayout *hItemLayout = new QHBoxLayout(this);
+ hItemLayout->setContentsMargins(ITEM_MARGINS);
+ QLabel *nameLabel = new QLabel(staName, this);
+ m_dragIntoBlackListBtn = new KBorderlessButton(this);
+ m_dragIntoBlackListBtn->setText(tr("drag into blacklist"));
+ hItemLayout->setSpacing(0);
+ hItemLayout->addWidget(nameLabel, Qt::AlignLeft);
+ hItemLayout->addStretch();
+ hItemLayout->addWidget(m_dragIntoBlackListBtn, Qt::AlignRight);
+
+ m_dragIntoBlackListBtn->installEventFilter(this);
+ this->setLayout(hItemLayout);
+}
+
+bool ConnectDevListItem::eventFilter(QObject *w, QEvent *e)
+{
+ if (e->type() == QEvent::MouseButtonRelease) {
+ if (w == m_dragIntoBlackListBtn) {
+ emit onBtnClicked(m_mac, m_hostName);
+ return true;
+ }
+ }
+ return QWidget::eventFilter(w,e);
+}
+
diff --git a/plugins/mobilehotspot/connectdevlistitem.h b/plugins/mobilehotspot/connectdevlistitem.h
new file mode 100644
index 00000000..182d581e
--- /dev/null
+++ b/plugins/mobilehotspot/connectdevlistitem.h
@@ -0,0 +1,52 @@
+/* -*- 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 CONNECTDEVLISTITEM_H
+#define CONNECTDEVLISTITEM_H
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "kborderlessbutton.h"
+
+using namespace kdk;
+
+class ConnectDevListItem : public QFrame
+{
+ Q_OBJECT
+public:
+ ConnectDevListItem(QString staMac, QString staName, QWidget *parent = nullptr);
+
+protected:
+ KBorderlessButton *m_dragIntoBlackListBtn = nullptr;
+
+ QString m_mac;
+ QString m_hostName;
+ bool eventFilter(QObject *w, QEvent *e);
+
+signals:
+ void onBtnClicked(QString staMac, QString staName);
+
+
+};
+
+#endif // LISTITEM_H
diff --git a/plugins/mobilehotspot/connectdevpage.cpp b/plugins/mobilehotspot/connectdevpage.cpp
new file mode 100644
index 00000000..473a4c69
--- /dev/null
+++ b/plugins/mobilehotspot/connectdevpage.cpp
@@ -0,0 +1,191 @@
+/* -*- 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 "connectdevpage.h"
+#include
+
+#define CONTENTS_MARGINS 0, 0, 0, 0
+#define FRAME_MIN_SIZE 550, 60
+#define FRAME_MAX_SIZE 16777215, 16777215
+#define LINE_MAX_SIZE 16777215, 1
+#define LINE_MIN_SIZE 0, 1
+
+#define LOG_HEAD "[ConnectdevPage]"
+
+ConnectdevPage::ConnectdevPage(QWidget *parent) :
+ QWidget(parent)
+{
+ QVBoxLayout *Vlayout = new QVBoxLayout(this);
+ Vlayout->setContentsMargins(CONTENTS_MARGINS);
+ Vlayout->setSpacing(0);
+
+ 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(m_staistFrame);
+ m_staListLayout->setContentsMargins(0, 0, 0, 0);
+ m_staListLayout->setSpacing(0);
+
+ m_titleLabel = new TitleLabel(this);
+ m_titleLabel->setText(tr("Connect device"));
+
+ Vlayout->addWidget(m_titleLabel);
+ Vlayout->addSpacing(8);
+ Vlayout->addWidget(m_staistFrame);
+}
+
+QFrame* ConnectdevPage::myLine()
+{
+ QFrame *line = new QFrame(this);
+ line->setMinimumSize(QSize(LINE_MIN_SIZE));
+ line->setMaximumSize(QSize(LINE_MAX_SIZE));
+ line->setLineWidth(0);
+ line->setFrameShape(QFrame::HLine);
+ line->setFrameShadow(QFrame::Sunken);
+
+ return line;
+}
+
+void ConnectdevPage::getConnectStaDevice(QMap &staMap)
+{
+ staMap.clear();
+ if (m_activePathInterface == nullptr || !m_activePathInterface->isValid()) {
+ qDebug() << LOG_HEAD << "dbus interface m_activePathInterface is invaild";
+ return;
+ }
+
+ QDBusMessage reply = m_activePathInterface->call("Getstainfo");
+ if(reply.type() == QDBusMessage::ErrorMessage)
+ {
+ qWarning() << LOG_HEAD << "Getstainfo error:" << reply.errorMessage();
+ return;
+ }
+
+ if (reply.arguments().isEmpty()
+ || reply.arguments().at(0).toString() == ""
+ || reply.arguments().at(0).toString() == "[Invalid UTF-8]"
+ || reply.arguments().at(1).toString() == "") {
+ qDebug() << LOG_HEAD << "Dbus interface call Getstainfo return is empty!";
+ return;
+ }
+
+ 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)) && hostNameList.at(index) != nullptr) {
+ staMap[macList.at(index)] = hostNameList.at(index);
+ }
+ }
+
+}
+
+void ConnectdevPage::initStaDev()
+{
+ QMap::const_iterator item = m_staMap.cbegin();
+ while (item != m_staMap.cend()) {
+ addStaDevFrame(item.key(), item.value());
+ item ++;
+ if (item != m_staMap.cend()) {
+ m_staListLayout->addWidget(myLine());
+ }
+ }
+}
+
+void ConnectdevPage::addStaDevFrame(QString staMac, QString staName)
+{
+ ConnectDevListItem *itemFrame = new ConnectDevListItem(staMac, staName, m_staListLayout->widget());
+ m_staListLayout->addWidget(itemFrame);
+ connect(itemFrame, &ConnectDevListItem::onBtnClicked, this, &ConnectdevPage::onDropIntoBlacklistBtnClicked);
+}
+
+void ConnectdevPage::clearStaListLayout()
+{
+
+ if (m_staListLayout->layout() != NULL) {
+ QLayoutItem* layoutItem;
+ while ((layoutItem = m_staListLayout->layout()->takeAt(0)) != NULL) {
+ delete layoutItem->widget();
+ delete layoutItem;
+ }
+ }
+}
+
+void ConnectdevPage::onStaDevAdded(bool istrue, QString staMac, QString staName)
+{
+ if (!m_staMap.contains(staMac)) {
+ m_staMap.insert(staMac, staName);
+ clearStaListLayout();
+ initStaDev();
+ resetLayoutHight();
+ }
+}
+
+void ConnectdevPage::onStaDevRemoved(bool istrue, QString staMac, QString staName)
+{
+ if (m_staMap.contains(staMac)) {
+ if (m_staMap.remove(staMac)) {
+ clearStaListLayout();
+ initStaDev();
+ resetLayoutHight();
+ }
+ }
+}
+
+void ConnectdevPage::resetLayoutHight()
+{
+ int height = 0;
+ for (int i = 0; i < m_staListLayout->count(); i ++) {
+ QWidget *w = m_staListLayout->itemAt(i)->widget();
+ if (w != nullptr) {
+ height += w->height();
+ }
+ }
+ m_staistFrame->setFixedHeight(height);
+
+ if (m_staMap.isEmpty()) {
+ this->hide();
+ } else {
+ this->show();
+ }
+ this->update();
+}
+
+void ConnectdevPage::refreshStalist()
+{
+ m_staMap.clear();
+ getConnectStaDevice(m_staMap);
+ clearStaListLayout();
+ initStaDev();
+ resetLayoutHight();
+}
+
+void ConnectdevPage::onDropIntoBlacklistBtnClicked(QString staMac, QString staName)
+{
+ if (staMac.isNull()
+ || staMac.isEmpty()
+ || staName.isNull()
+ || staName.isEmpty()) {
+ qDebug() << LOG_HEAD <<"On drop into blacklist button clicked error! sta mac or name is empty!";
+ return;
+ }
+
+ emit setStaIntoBlacklist(staMac, staName);
+}
diff --git a/plugins/mobilehotspot/connectdevpage.h b/plugins/mobilehotspot/connectdevpage.h
new file mode 100644
index 00000000..ce9abb09
--- /dev/null
+++ b/plugins/mobilehotspot/connectdevpage.h
@@ -0,0 +1,84 @@
+/* -*- 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 CONNECTDEVPAGE_H
+#define CONNECTDEVPAGE_H
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#include "titlelabel.h"
+#include "connectdevlistitem.h"
+
+using namespace kdk;
+
+class ConnectdevPage : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit ConnectdevPage(QWidget *parent = nullptr);
+
+ void refreshStalist();
+
+ inline void setInterface(QDBusInterface *activeInterface) {
+ m_activePathInterface = activeInterface;
+ }
+
+private:
+ QFrame* myLine();
+
+ void getConnectStaDevice(QMap &blacklistMap);
+ bool removeStaFromBlacklist(QString staMac);
+ void initStaDev();
+ void addStaDevFrame(QString staMac, QString staName);
+ void clearStaListLayout();
+ QString getActivePathByUuid(QDBusInterface *interface);
+ void initNmDbus(QDBusInterface *interface);
+
+ void onStaDevChanged(bool istrue, QString staMac, QString staName);
+ void resetLayoutHight();
+
+private:
+ QFrame *m_staistFrame = nullptr;
+
+ TitleLabel *m_titleLabel = nullptr;
+ QVBoxLayout *m_staListLayout = nullptr;
+ QMap m_staMap;
+
+ QDBusInterface *m_activePathInterface = nullptr;
+
+signals:
+ void setStaIntoBlacklist(QString staMac, QString staName);
+
+public slots:
+ void onStaDevAdded(bool istrue, QString staMac, QString staName);
+ void onStaDevRemoved(bool istrue, QString staMac, QString staName);
+
+private slots:
+ void onDropIntoBlacklistBtnClicked(QString staMac, QString staName);
+};
+
+#endif // MOBILEHOTSPOTWIDGET_H
diff --git a/plugins/mobilehotspot/mobilehotspot.pro b/plugins/mobilehotspot/mobilehotspot.pro
index c4916f46..90c84dab 100644
--- a/plugins/mobilehotspot/mobilehotspot.pro
+++ b/plugins/mobilehotspot/mobilehotspot.pro
@@ -25,10 +25,18 @@ PKGCONFIG += gsettings-qt \
#DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
+ blacklistpage.cpp \
+ blacklistitem.cpp \
+ connectdevpage.cpp \
+ connectdevlistitem.cpp \
mobilehotspot.cpp \
mobilehotspotwidget.cpp
HEADERS += \
+ blacklistpage.h \
+ blacklistitem.h \
+ connectdevpage.h \
+ connectdevlistitem.h \
mobilehotspot.h \
mobilehotspotwidget.h \
libukcc_global.h
@@ -40,4 +48,6 @@ INSTALLS += target \
TRANSLATIONS += \
translations/zh_CN.ts \
translations/tr.ts \
- translations/bo.ts
+ translations/bo.ts\
+ translations/bo_CN.ts \
+ translations/en_US.ts
diff --git a/plugins/mobilehotspot/mobilehotspotwidget.cpp b/plugins/mobilehotspot/mobilehotspotwidget.cpp
index 0b3fc081..a9fcb57d 100644
--- a/plugins/mobilehotspot/mobilehotspotwidget.cpp
+++ b/plugins/mobilehotspot/mobilehotspotwidget.cpp
@@ -1,5 +1,25 @@
+/* -*- 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 "mobilehotspotwidget.h"
#include
+#include
#define LABEL_RECT 17, 0, 105, 23
#define CONTENTS_MARGINS 0, 0, 0, 0
@@ -7,16 +27,30 @@
#define FRAME_MIN_SIZE 550, 60
#define FRAME_MAX_SIZE 16777215, 16777215
#define CONTECT_FRAME_MAX_SIZE 16777215, 60
+
+#define HINT_TEXT_MARGINS 8, 0, 0, 0
+#define FRAME_MIN_SIZE 550, 60
+
#define LABLE_MIN_WIDTH 188
#define COMBOBOX_MIN_WIDTH 200
#define LINE_MAX_SIZE 16777215, 1
#define LINE_MIN_SIZE 0, 1
#define ICON_SIZE 24,24
+#define PASSWORD_FRAME_MIN_HIGHT 60
+#define PASSWORD_FRAME_FIX_HIGHT 80
+#define PASSWORD_FRAME_MIN_SIZE 550, 60
+#define PASSWORD_FRAME_MAX_SIZE 16777215, 86
+#define PASSWORD_ITEM_MARGINS 16, 12, 16, 14
+
#define WIRELESS 1
#define AP_NAME_MAX_LENGTH 32
+#define REFRESH_MSEC 20*1000
+
+#define LOG_HEAD "[MobileHotspotWidget]"
+
const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch";
const QString WIRELESS_SWITCH = "wirelessswitch";
@@ -29,7 +63,7 @@ void MobileHotspotWidget::showDesktopNotify(const QString &message)
QList args;
args<<(tr("ukui control center"))
<<((unsigned int) 0)
- <setContentsMargins(CONTENTS_MARGINS);
+ m_Vlayout = new QVBoxLayout(this);
+ m_Vlayout->setContentsMargins(CONTENTS_MARGINS);
+ m_Vlayout->setSpacing(0);
qDBusRegisterMetaType >();
qDBusRegisterMetaType >();
@@ -49,12 +86,18 @@ MobileHotspotWidget::MobileHotspotWidget(QWidget *parent) : QWidget(parent)
qDBusRegisterMetaType >>();
initUI();
+
+#ifdef HOTSPOT_CONTROL
+ initConnectDevPage();
+ initBlackListPage();
+#endif
+
m_switchBtn->installEventFilter(this);
m_interface = new QDBusInterface("com.kylin.network", "/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if(!m_interface->isValid()) {
- qDebug() << "dbus interface com.kylin.network is invaild";
+ qDebug() << LOG_HEAD << "dbus interface com.kylin.network is invaild";
m_switchBtn->setChecked(false);
setUiEnabled(false);
}
@@ -66,15 +109,30 @@ MobileHotspotWidget::MobileHotspotWidget(QWidget *parent) : QWidget(parent)
initInterfaceInfo();
getApInfo();
+#ifdef HOTSPOT_CONTROL
+ initNmDbus();
+#endif
+
+ this->setLayout(m_Vlayout);
+ m_Vlayout->addStretch();
+
connect(m_switchBtn, &KSwitchButton::stateChanged, this, &MobileHotspotWidget::setUiEnabled);
connect(m_interfaceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, [=]() {
m_interfaceName = m_interfaceComboBox->currentText();
updateBandCombox();
});
+
+#ifdef HOTSPOT_CONTROL
+ m_connectDevPage->refreshStalist();
+ m_blacklistPage->refreshBlacklist();
+#endif
+ this->update();
}
MobileHotspotWidget::~MobileHotspotWidget()
{
+ deleteActivePathInterface();
+ deleteSettingPathInterface();
delete m_interface;
}
@@ -84,8 +142,9 @@ bool MobileHotspotWidget::eventFilter(QObject *watched, QEvent *event)
return true;
}
- if (event->type() == QEvent::MouseButtonRelease) {
- if (watched == m_switchBtn) {
+
+ if (watched == m_switchBtn) {
+ if (event->type() == QEvent::MouseButtonRelease) {
if (!m_interface->isValid()) {
return true;
}
@@ -94,12 +153,19 @@ bool MobileHotspotWidget::eventFilter(QObject *watched, QEvent *event)
return true;
}
if (m_switchBtn->isChecked()) {
- showDesktopNotify(tr("start to close hotspot"));
+// showDesktopNotify(tr("start to close hotspot"));
QDBusReply reply = m_interface->call("deactiveWirelessAp", m_apNameLine->text(), m_uuid);
if (!reply.isValid()) {
- qDebug() << "[MobileHotspotWidget] call deactiveWirelessAp failed ";
+ qDebug() << LOG_HEAD << "call deactiveWirelessAp failed ";
return true;
}
+#ifdef HOTSPOT_CONTROL
+ deleteActivePathInterface();
+ m_connectDevPage->setInterface(nullptr);
+ m_connectDevPage->refreshStalist();
+ m_blacklistPage->refreshBlacklist();
+#endif
+ this->update();
} else {
if (m_apNameLine->text().isEmpty() || m_interfaceName.isEmpty())
{
@@ -107,17 +173,17 @@ bool MobileHotspotWidget::eventFilter(QObject *watched, QEvent *event)
return true;
}
if (m_pwdNameLine->text().length() < 8) {
- showDesktopNotify(tr("can not create hotspot with password length less than eight!"));
+// showDesktopNotify(tr("can not create hotspot with password length less than eight!"));
return true;
}
- showDesktopNotify(tr("start to open hotspot ") + m_apNameLine->text());
+// showDesktopNotify(tr("start to open hotspot ") + m_apNameLine->text());
QDBusReply reply = m_interface->call("activeWirelessAp",
- m_apNameLine->text(),
- m_pwdNameLine->text(),
- m_freqBandComboBox->currentText(),
- m_interfaceComboBox->currentText());
+ m_apNameLine->text(),
+ m_pwdNameLine->text(),
+ m_freqBandComboBox->currentText(),
+ m_interfaceComboBox->currentText());
if (!reply.isValid()) {
- qDebug() << "[MobileHotspotWidget] call deactiveWirelessAp failed ";
+ qDebug() << LOG_HEAD << "call activeWirelessAp failed ";
return true;
}
}
@@ -132,15 +198,28 @@ void MobileHotspotWidget::paintEvent(QPaintEvent *event)
QWidget::paintEvent(event);
}
+void MobileHotspotWidget::resetFrameSize()
+{
+ int height = 0;
+ for (int i = 0; i < m_hotspotFrame->layout()->count(); i ++) {
+ QWidget *w = m_hotspotFrame->layout()->itemAt(i)->widget();
+ if (w != nullptr && !w->isHidden()) {
+ height += w->height();
+ }
+ }
+ m_hotspotFrame->setFixedHeight(height);
+}
+
void MobileHotspotWidget::initUI()
{
- QFrame *hotspotFrame = new QFrame(this);
- hotspotFrame->setMinimumSize(FRAME_MIN_SIZE);
- hotspotFrame->setMaximumSize(FRAME_MAX_SIZE);
- hotspotFrame->setFrameShape(QFrame::Box);
+ m_hotspotFrame = new QFrame(this);
+ m_hotspotFrame->setMinimumSize(FRAME_MIN_SIZE);
+ m_hotspotFrame->setMaximumSize(FRAME_MAX_SIZE);
+ m_hotspotFrame->setFrameShape(QFrame::Box);
- QVBoxLayout *hotspotLyt = new QVBoxLayout(hotspotFrame);
+ QVBoxLayout *hotspotLyt = new QVBoxLayout(this);
hotspotLyt->setContentsMargins(0, 0, 0, 0);
+ m_hotspotFrame->setLayout(hotspotLyt);
m_hotspotTitleLabel = new TitleLabel(this);
m_hotspotTitleLabel->setText(tr("Hotspot"));
@@ -156,7 +235,6 @@ void MobileHotspotWidget::initUI()
pwdAndfreqBandLine = myLine();
freqBandAndInterfaceLine = myLine();
- /* add widget */
hotspotLyt->addWidget(m_switchFrame);
hotspotLyt->addWidget(switchAndApNameLine);
hotspotLyt->addWidget(m_ApNameFrame);
@@ -168,10 +246,12 @@ void MobileHotspotWidget::initUI()
hotspotLyt->addWidget(m_interfaceFrame);
hotspotLyt->setSpacing(0);
- mVlayout->addWidget(m_hotspotTitleLabel);
- mVlayout->setSpacing(8);
- mVlayout->addWidget(hotspotFrame);
- mVlayout->addStretch();
+ resetFrameSize();
+
+ m_Vlayout->addWidget(m_hotspotTitleLabel);
+ m_Vlayout->addSpacing(8);
+ m_Vlayout->addWidget(m_hotspotFrame);
+
}
void MobileHotspotWidget::initDbusConnect()
@@ -182,18 +262,20 @@ void MobileHotspotWidget::initDbusConnect()
connect(m_interface,SIGNAL(deviceStatusChanged()), this, SLOT(onDeviceStatusChanged()), Qt::QueuedConnection);
connect(m_interface,SIGNAL(deviceNameChanged(QString, QString, int)), this, SLOT(onDeviceNameChanged(QString, QString, int)), Qt::QueuedConnection);
connect(m_interface,SIGNAL(hotspotDeactivated(QString, QString)), this, SLOT(onHotspotDeactivated(QString, QString)), Qt::QueuedConnection);
- connect(m_interface,SIGNAL(hotspotActivated(QString, QString, QString)), this, SLOT(onHotspotActivated(QString, QString, QString)), Qt::QueuedConnection);
+
+ 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
+ connect(m_connectDevPage, SIGNAL(setStaIntoBlacklist(QString, QString)), m_blacklistPage, SLOT(onsetStaIntoBlacklist(QString, QString)));
+#endif
+ connect(m_pwdNameLine, SIGNAL(textChanged(QString)), this, SLOT(onPwdTextChanged()));
}
void MobileHotspotWidget::onApLineEditTextEdit(QString text)
@@ -211,6 +293,18 @@ void MobileHotspotWidget::onApLineEditTextEdit(QString text)
m_apNameLine->setText(text.left(i));
}
+void MobileHotspotWidget::onPwdTextChanged()
+{
+ if (m_pwdNameLine->text().length() < 8) {
+ m_passwordFrame->setFixedHeight(PASSWORD_FRAME_FIX_HIGHT);
+ m_pwdHintLabel->show();
+ } else {
+ m_passwordFrame->setFixedHeight(PASSWORD_FRAME_MIN_HIGHT);
+ m_pwdHintLabel->hide();
+ }
+ resetFrameSize();
+ this->update();
+}
void MobileHotspotWidget::onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, int status)
{
@@ -222,29 +316,14 @@ void MobileHotspotWidget::onActiveConnectionChanged(QString deviceName, QString
}
}
-void MobileHotspotWidget::onGsettingChanged(const QString &key)
+void MobileHotspotWidget::onWirelessBtnChanged(bool state)
{
- if (key == WIRELESS_SWITCH) {
- bool status = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
- if (!status) {
-// if (m_switchBtn->isChecked()) {
-// if(m_interface->isValid()) {
-// QDBusReply reply = m_interface->call("deactiveWirelessAp",
-// m_apNameLine->text(),
-// m_pwdNameLine->text(),
-// m_interfaceComboBox->currentText());
-// if (!reply.isValid()) {
-// qDebug() << "[MobileHotspotWidget] call deactiveWirelessAp failed ";
-// return true;
-// }
-// }
-// }
- m_switchBtn->setChecked(status);
- m_uuid.clear();
- m_switchBtn->setCheckable(false);
- } else {
- m_switchBtn->setCheckable(true);
- }
+ if (!state) {
+ m_switchBtn->setChecked(state);
+ m_uuid.clear();
+ m_switchBtn->setCheckable(false);
+ } else {
+ m_switchBtn->setCheckable(true);
}
}
@@ -257,7 +336,7 @@ void MobileHotspotWidget::initInterfaceInfo()
QDBusReply > reply = m_interface->call("getDeviceListAndEnabled",WIRELESS);
if (!reply.isValid()) {
- qDebug()<<"execute dbus method 'getDeviceListAndEnabled' is invalid in func initInterfaceInfo()";
+ qDebug() << LOG_HEAD <<"execute dbus method 'getDeviceListAndEnabled' is invalid in func initInterfaceInfo()";
setWidgetHidden(true);
return;
}
@@ -265,7 +344,7 @@ void MobileHotspotWidget::initInterfaceInfo()
QDBusReply > capReply = m_interface->call("getWirelessDeviceCap");
if (!capReply.isValid()) {
- qDebug()<<"execute dbus method 'getWirelessDeviceCap' is invalid in func initInterfaceInfo()" <setCheckable(false);
} else {
@@ -292,7 +371,7 @@ void MobileHotspotWidget::initInterfaceInfo()
updateBandCombox();
}
} else {
- qDebug() << "no useable wireless device";
+ qDebug() << LOG_HEAD << "no useable wireless device";
setWidgetHidden(true);
}
}
@@ -305,22 +384,22 @@ void MobileHotspotWidget::getApInfo()
}
if (m_interfaceComboBox->count() <= 0) {
- m_switchBtn->setChecked(false);
- setWidgetHidden(true);
- qWarning() << "getApInfo but interface is empty";
- return;
- }
+ m_switchBtn->setChecked(false);
+ setWidgetHidden(true);
+ qWarning() << LOG_HEAD << "getApInfo but interface is empty";
+ return;
+ }
QDBusReply reply = m_interface->call("getStoredApInfo");
if (!reply.isValid()) {
- qDebug()<<"execute dbus method 'getStoredApInfo' is invalid in func getObjectPath()";
+ qDebug() << LOG_HEAD <<"execute dbus method 'getStoredApInfo' is invalid in func getObjectPath()";
}
QStringList apInfo = reply.value();
if (apInfo.isEmpty()) {
- qDebug() << "no stored hotspot info";
+ qDebug() << LOG_HEAD << "no stored hotspot info";
m_apNameLine->setText(m_hostName);
m_pwdNameLine->setText("12345678");
return;
@@ -338,9 +417,10 @@ void MobileHotspotWidget::getApInfo()
} else {
m_switchBtn->setChecked(false);
setUiEnabled(false);
+ m_uuid = apInfo.at(4);
}
} else {
- qDebug() << "no such interface " << apInfo.at(2);
+ qDebug() << LOG_HEAD << "no such interface " << apInfo.at(2);
}
}
}
@@ -353,7 +433,7 @@ void MobileHotspotWidget::setSwitchFrame()
m_switchFrame->setMinimumSize(FRAME_MIN_SIZE);
m_switchFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
- QHBoxLayout *switchLayout = new QHBoxLayout();
+ QHBoxLayout *switchLayout = new QHBoxLayout(m_switchFrame);
m_switchLabel = new QLabel(tr("Open"), this);
m_switchLabel->setMinimumWidth(LABLE_MIN_WIDTH);
@@ -374,7 +454,7 @@ void MobileHotspotWidget::setApNameFrame()
m_ApNameFrame->setMinimumSize(FRAME_MIN_SIZE);
m_ApNameFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
- QHBoxLayout *apNameHLayout = new QHBoxLayout();
+ QHBoxLayout *apNameHLayout = new QHBoxLayout(m_ApNameFrame);
m_apNameLabel = new QLabel(tr("Wi-Fi Name"), this);
m_apNameLabel->setMinimumWidth(LABLE_MIN_WIDTH);
@@ -394,22 +474,38 @@ void MobileHotspotWidget::setPasswordFrame()
/* Password */
m_passwordFrame = new QFrame(this);
m_passwordFrame->setFrameShape(QFrame::Shape::NoFrame);
- m_passwordFrame->setMinimumSize(FRAME_MIN_SIZE);
- m_passwordFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
-
- QHBoxLayout *passwordHLayout = new QHBoxLayout();
+ m_passwordFrame->setMinimumSize(PASSWORD_FRAME_MIN_SIZE);
+ m_passwordFrame->setMaximumSize(PASSWORD_FRAME_MAX_SIZE);
m_pwdLabel = new QLabel(tr("Password"), this);
m_pwdLabel->setMinimumWidth(LABLE_MIN_WIDTH);
m_pwdNameLine = new KPasswordEdit(this);
m_pwdNameLine->setClearButtonEnabled(false);//禁用ClearBtn按钮X
m_pwdNameLine->setMinimumWidth(COMBOBOX_MIN_WIDTH);
- passwordHLayout->setContentsMargins(ITEM_MARGINS);
- passwordHLayout->setSpacing(0);
- passwordHLayout->addWidget(m_pwdLabel);
- passwordHLayout->addWidget(m_pwdNameLine);
+ m_pwdHintLabel= new QLabel(this);
+ m_pwdHintLabel->setFixedHeight(20);
+ m_pwdHintLabel->setContentsMargins(HINT_TEXT_MARGINS);
- m_passwordFrame->setLayout(passwordHLayout);
+ QPalette hintTextColor;
+ hintTextColor.setColor(QPalette::WindowText, Qt::red);
+ m_pwdHintLabel->setPalette(hintTextColor);
+ m_pwdHintLabel->setText(tr("Contains at least 8 characters")); //至少包含8个字符
+
+ QWidget *pwdInputWidget = new QWidget(m_passwordFrame);
+ QVBoxLayout *pwdInputVLayout = new QVBoxLayout(pwdInputWidget);
+ pwdInputVLayout->setContentsMargins(CONTENTS_MARGINS);
+ pwdInputVLayout->setSpacing(0);
+ pwdInputVLayout->addWidget(m_pwdNameLine);
+ pwdInputVLayout->addWidget(m_pwdHintLabel);
+
+ QFormLayout *pwdLayout = new QFormLayout(m_passwordFrame);
+ pwdLayout->setContentsMargins(PASSWORD_ITEM_MARGINS);
+ pwdLayout->setSpacing(0);
+ pwdLayout->addRow(m_pwdLabel, pwdInputWidget);
+
+ m_passwordFrame->setLayout(pwdLayout);
+
+ m_pwdNameLine->installEventFilter(this);
}
void MobileHotspotWidget::setFreqBandFrame()
@@ -420,7 +516,7 @@ void MobileHotspotWidget::setFreqBandFrame()
m_freqBandFrame->setMinimumSize(FRAME_MIN_SIZE);
m_freqBandFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
- QHBoxLayout *freqBandHLayout = new QHBoxLayout();
+ QHBoxLayout *freqBandHLayout = new QHBoxLayout(m_freqBandFrame);
m_freqBandLabel = new QLabel(tr("Frequency band"), this);
m_freqBandLabel->setMinimumWidth(LABLE_MIN_WIDTH);
@@ -428,8 +524,8 @@ void MobileHotspotWidget::setFreqBandFrame()
m_freqBandComboBox->setInsertPolicy(QComboBox::NoInsert);
m_freqBandComboBox->setMinimumWidth(COMBOBOX_MIN_WIDTH);
m_freqBandComboBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
- m_freqBandComboBox->addItem("2.4Ghz");
- m_freqBandComboBox->addItem("5Ghz");
+ m_freqBandComboBox->addItem("2.4GHz");
+ m_freqBandComboBox->addItem("5GHz");
freqBandHLayout->setContentsMargins(ITEM_MARGINS);
freqBandHLayout->setSpacing(0);
freqBandHLayout->addWidget(m_freqBandLabel);
@@ -446,7 +542,7 @@ void MobileHotspotWidget::setInterFaceFrame()
m_interfaceFrame->setMinimumSize(FRAME_MIN_SIZE);
m_interfaceFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
- QHBoxLayout *interfaceHLayout = new QHBoxLayout;
+ QHBoxLayout *interfaceHLayout = new QHBoxLayout(m_interfaceFrame);
m_interfaceLabel = new QLabel(tr("Net card"), this);
m_interfaceLabel->setMinimumWidth(LABLE_MIN_WIDTH);
@@ -513,12 +609,26 @@ void MobileHotspotWidget::onHotspotDeactivated(QString devName, QString ssid)
}
//热点连接
-void MobileHotspotWidget::onHotspotActivated(QString devName, QString ssid, QString uuid)
+void MobileHotspotWidget::onHotspotActivated(QString devName, QString ssid, QString uuid, QString activePath, QString settingPath)
{
- qDebug() << "onHotspotActivated" <isChecked()) {
return;
}
+#ifdef HOTSPOT_CONTROL
+ if (activePath != nullptr) {
+ deleteActivePathInterface();
+ initActivePathInterface(activePath);
+ }
+ if (settingPath != nullptr) {
+ deleteSettingPathInterface();
+ initSettingPathInterface(settingPath);
+ }
+
+ m_connectDevPage->refreshStalist();
+ m_blacklistPage->refreshBlacklist();
+#endif
+ this->update();
if (devName == m_interfaceComboBox->currentText() && ssid == m_apNameLine->text()) {
m_switchBtn->setChecked(true);
@@ -604,9 +714,11 @@ void MobileHotspotWidget::setWidgetHidden(bool isHidden)
m_uuid = "";
} else {
m_switchBtn->setCheckable(true);
- onGsettingChanged(WIRELESS_SWITCH);
+ QDBusReply reply = m_interface->call("getWirelessSwitchBtnState");
+ bool state = reply.value();
+ onWirelessBtnChanged(state);
}
-
+ resetFrameSize();
}
void MobileHotspotWidget::updateBandCombox()
@@ -620,10 +732,10 @@ void MobileHotspotWidget::updateBandCombox()
}
QMap devCapMap = capReply.value();
if (devCapMap[m_interfaceName] & 0x02) {
- m_freqBandComboBox->addItem("2.4Ghz");
+ m_freqBandComboBox->addItem("2.4GHz");
}
if (devCapMap[m_interfaceName] & 0x04) {
- m_freqBandComboBox->addItem("5Ghz");
+ m_freqBandComboBox->addItem("5GHz");
}
}
@@ -655,3 +767,120 @@ QString MobileHotspotWidget::getHostName()
}
return "default";
}
+
+QString MobileHotspotWidget::getSettingPathByUuid()
+{
+ if (!m_interface->isValid()) {
+ return nullptr;
+ }
+
+ QDBusReply reply = m_interface->call("getApConnectionPath", m_uuid);
+ if (!reply.isValid()) {
+ return nullptr;
+ }
+
+ return reply.value();
+}
+
+QString MobileHotspotWidget::getActivePathByUuid()
+{
+ if (!m_interface->isValid()) {
+ return nullptr;
+ }
+
+ QDBusReply reply = m_interface->call("getActiveConnectionPath", m_uuid);
+ if (!reply.isValid()) {
+ return nullptr;
+ }
+ return reply.value();
+}
+
+void MobileHotspotWidget::initNmDbus()
+{
+ QString activePath = getActivePathByUuid();
+ QString settingPath = getSettingPathByUuid();
+
+ if (activePath != nullptr) {
+ m_activePathInterface = new QDBusInterface("org.freedesktop.NetworkManager",
+ activePath,
+ "org.freedesktop.NetworkManager.Connection.Active",
+ QDBusConnection::systemBus());
+ if (m_activePathInterface->isValid()) {
+ m_connectDevPage->setInterface(m_activePathInterface);
+
+ connect(m_activePathInterface, SIGNAL(NewStaConnected(bool, QString, QString)), m_connectDevPage, SLOT(onStaDevAdded(bool, QString, QString)), Qt::QueuedConnection);
+ connect(m_activePathInterface, SIGNAL(StaRemoved(bool, QString, QString)), m_connectDevPage, SLOT(onStaDevRemoved(bool, QString, QString)), Qt::QueuedConnection);
+ }
+ }
+
+ if (settingPath != nullptr) {
+ m_settingPathInterface = new QDBusInterface("org.freedesktop.NetworkManager",
+ settingPath,
+ "org.freedesktop.NetworkManager.Settings.Connection",
+ QDBusConnection::systemBus());
+ if (m_settingPathInterface->isValid()) {
+ m_blacklistPage->setInterface(m_settingPathInterface);
+ }
+ }
+}
+
+void MobileHotspotWidget::initActivePathInterface(QString path)
+{
+ if (path != nullptr){
+ m_activePathInterface = new QDBusInterface("org.freedesktop.NetworkManager",
+ path,
+ "org.freedesktop.NetworkManager.Connection.Active",
+ QDBusConnection::systemBus());
+ if (m_activePathInterface->isValid()) {
+ m_connectDevPage->setInterface(m_activePathInterface);
+
+ connect(m_activePathInterface, SIGNAL(NewStaConnected(bool, QString, QString)), m_connectDevPage, SLOT(onStaDevAdded(bool, QString, QString)), Qt::QueuedConnection);
+ connect(m_activePathInterface, SIGNAL(StaRemoved(bool, QString, QString)), m_connectDevPage, SLOT(onStaDevRemoved(bool, QString, QString)), Qt::QueuedConnection);
+ }
+ }
+}
+
+void MobileHotspotWidget::deleteActivePathInterface()
+{
+ if (m_activePathInterface != nullptr){
+ disconnect(m_activePathInterface);
+ delete m_activePathInterface;
+ m_activePathInterface = nullptr;
+ }
+}
+
+void MobileHotspotWidget::initSettingPathInterface(QString path)
+{
+ if (path != nullptr){
+ m_settingPathInterface = new QDBusInterface("org.freedesktop.NetworkManager",
+ path,
+ "org.freedesktop.NetworkManager.Settings.Connection",
+ QDBusConnection::systemBus());
+ if (m_settingPathInterface->isValid()) {
+ m_blacklistPage->setInterface(m_settingPathInterface);
+ }
+ }
+}
+
+void MobileHotspotWidget::deleteSettingPathInterface()
+{
+ if (m_settingPathInterface != nullptr){
+ disconnect(m_settingPathInterface);
+ delete m_settingPathInterface;
+ m_settingPathInterface = nullptr;
+ }
+}
+
+void MobileHotspotWidget::initConnectDevPage()
+{
+ m_connectDevPage = new ConnectdevPage(this);
+ m_Vlayout->addSpacing(32);
+ m_Vlayout->addWidget(m_connectDevPage);
+}
+
+void MobileHotspotWidget::initBlackListPage()
+{
+ m_blacklistPage = new BlacklistPage(this);
+ m_Vlayout->addSpacing(32);
+ m_Vlayout->addWidget(m_blacklistPage);
+}
diff --git a/plugins/mobilehotspot/mobilehotspotwidget.h b/plugins/mobilehotspot/mobilehotspotwidget.h
index 8116811d..99e67bfe 100644
--- a/plugins/mobilehotspot/mobilehotspotwidget.h
+++ b/plugins/mobilehotspot/mobilehotspotwidget.h
@@ -1,3 +1,22 @@
+/* -*- 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 MOBILEHOTSPOTWIDGET_H
#define MOBILEHOTSPOTWIDGET_H
@@ -11,18 +30,22 @@
#include
#include
-
+#include
#include
#include
#include
#include
#include
+#include
#include "titlelabel.h"
#include "kwidget.h"
#include "kswitchbutton.h"
#include "kpasswordedit.h"
+#include "connectdevlistitem.h"
+#include "blacklistpage.h"
+#include "connectdevpage.h"
using namespace kdk;
@@ -34,6 +57,7 @@ public:
~MobileHotspotWidget();
private:
+ QFrame *m_hotspotFrame = nullptr;
QFrame *m_switchFrame = nullptr; //开关
QFrame *m_ApNameFrame = nullptr; //wifi名称
QFrame *m_passwordFrame = nullptr; //密码
@@ -46,6 +70,7 @@ private:
QLabel *m_switchLabel;
QLabel *m_apNameLabel;
QLabel *m_pwdLabel;
+ QLabel *m_pwdHintLabel;
QLabel *m_freqBandLabel;
QLabel *m_interfaceLabel;
@@ -54,7 +79,7 @@ private:
QFrame *pwdAndfreqBandLine;
QFrame *freqBandAndInterfaceLine;
- QVBoxLayout *mVlayout;
+ QVBoxLayout *m_Vlayout;
QLineEdit *m_apNameLine;
KPasswordEdit *m_pwdNameLine;
@@ -71,6 +96,7 @@ private:
QString m_uuid = "";
QString m_hostName = "";
+ void resetFrameSize();
void initUI();
void initDbusConnect();
void initInterfaceInfo();
@@ -96,6 +122,21 @@ private:
QFrame* myLine();
+ QDBusInterface *m_activePathInterface = nullptr;
+ QDBusInterface *m_settingPathInterface = nullptr;
+
+ ConnectdevPage * m_connectDevPage = nullptr;
+ BlacklistPage *m_blacklistPage = nullptr;
+
+ QString getActivePathByUuid();
+ QString getSettingPathByUuid();
+ void initNmDbus();
+ void initActivePathInterface(QString path);
+ void deleteActivePathInterface();
+ void initSettingPathInterface(QString path);
+ void deleteSettingPathInterface();
+ void initConnectDevPage();
+ void initBlackListPage();
signals:
private slots:
@@ -107,14 +148,15 @@ private slots:
//热点断开
void onHotspotDeactivated(QString devName, QString ssid);
//热点连接
- void onHotspotActivated(QString devName, QString ssid, QString uuid);
+ 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);
void onApLineEditTextEdit(QString text);
+ void onPwdTextChanged();
};
#endif // MOBILEHOTSPOTWIDGET_H
diff --git a/plugins/mobilehotspot/translations/bo.ts b/plugins/mobilehotspot/translations/bo.ts
index fad9d3e2..2c1f8b3d 100644
--- a/plugins/mobilehotspot/translations/bo.ts
+++ b/plugins/mobilehotspot/translations/bo.ts
@@ -1,6 +1,38 @@
+
+ BlacklistItem
+
+
+
+
+
+
+
+ BlacklistPage
+
+
+
+
+
+
+
+ ConnectDevListItem
+
+
+
+
+
+
+
+ ConnectdevPage
+
+
+
+
+
+
MobileHotspot
@@ -24,79 +56,69 @@
MobileHotspotWidget
-
+
-
+
-
+
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
diff --git a/plugins/mobilehotspot/translations/bo_CN.qm b/plugins/mobilehotspot/translations/bo_CN.qm
new file mode 100644
index 00000000..b9da303b
Binary files /dev/null and b/plugins/mobilehotspot/translations/bo_CN.qm differ
diff --git a/plugins/mobilehotspot/translations/bo_CN.ts b/plugins/mobilehotspot/translations/bo_CN.ts
new file mode 100644
index 00000000..f2f82810
--- /dev/null
+++ b/plugins/mobilehotspot/translations/bo_CN.ts
@@ -0,0 +1,138 @@
+
+
+
+
+ BlacklistItem
+
+
+
+ སྤོ་སྐྱོད་བྱས་པ།
+
+
+
+ BlacklistPage
+
+
+
+ སྒྲིག་ཆས་ཀྱི་མིང་ཐོ་ནག་པོ།
+
+
+
+ ConnectDevListItem
+
+
+
+ མིང་ཐོ་ནག་པོའི་ཁ་སྣོན་རྒྱག་པ།
+
+
+
+ ConnectdevPage
+
+
+
+ འབྲེལ་མཐུད་སྒྲིག་ཆས།
+
+
+
+ MobileHotspot
+
+
+
+ སྒུལ་བདེའི་ཧའོ་ཚི་ཀུང་སི།
+
+
+
+
+ སྒུལ་བདེའི་འཕྲུལ་ཆས།
+ /mobilehotspot/mobilehotspot
+
+
+
+
+ སྒུལ་བདེའི་འཕྲུལ་ཆས་ཀྱི་སྒོ་ཕྱེ་བ།
+ /mobilehotspot/mobilehotspot open
+
+
+
+ MobileHotspotWidget
+
+
+
+ ཝུའུ་ཁི་ལན་གྱི་ཚོད་འཛིན་ལྟེ་གནས།
+
+
+
+
+ ukui ཚོད་འཛིན་ལྟེ་གནས་ཀྱི་ཅོག་ངོས་ཆ་འཕྲིན།
+
+
+
+
+ སྐུད་མེད་གློག་སྒོ་རྒྱག་པའམ་ཡང་ན་སྐུད་མེད་སྒྲིག་ཆས་མེད་པ།
+
+
+
+ སྒོ་རྒྱག་འགོ་བརྩམས།
+
+
+
+
+ ཚ་བ་ཆེ་བའི་མིང་ངམ་སྒྲིག་ཆས་ལ་ནུས་པ་མེད།
+
+
+
+ གསང་གྲངས་ཀྱི་རིང་ཚད་ནི་གླེང་མང་བའི་གནད་དོན་བརྒྱད་ལས་ཆུང་བ་བྱེད་མི་རུང་།!
+
+
+
+ ཀུན་གྱིས་དོ་སྣང་བྱེད་ཡུལ་གསར་སྐྲུན་བྱེད་འགོ་
+
+
+
+
+ མ་མཐར་ཡང་ཡིག་རྟགས་བརྒྱད་འདུས་ཡོད།
+
+
+
+
+ ཚ་བ་ཆེ་བ།
+
+
+
+
+
+ ཚ་བ་ཆེ་བའི་གནད་དོན་ཐག་ཉེ་རུ་སོང་ཡོད།
+
+
+
+
+ སྒོ་ཕྱེ་བ།
+
+
+
+
+ Wi-Fiཡི་མིང་།
+
+
+
+
+ གསང་གྲངས།
+
+
+
+
+ ཐེངས་གྲངས་ཀྱི་རོལ་ཆའི་རུ་ཁག
+
+
+
+
+ དྲ་རྒྱའི་བྱང་བུ།
+
+
+
+
+
+ ཚ་བ་ཆེ་བའི་གནད་དོན་དེ་སྒོ་ཕྱེ་ཟིན།
+
+
+
diff --git a/plugins/mobilehotspot/translations/en_US.ts b/plugins/mobilehotspot/translations/en_US.ts
new file mode 100644
index 00000000..bb4f55f3
--- /dev/null
+++ b/plugins/mobilehotspot/translations/en_US.ts
@@ -0,0 +1,126 @@
+
+
+
+
+ BlacklistItem
+
+
+
+ Remove
+
+
+
+ BlacklistPage
+
+
+
+ Blacklist
+
+
+
+ ConnectDevListItem
+
+
+
+ drag into blacklist
+
+
+
+ ConnectdevPage
+
+
+
+ Connect device
+
+
+
+ MobileHotspot
+
+
+
+ MobileHotspot
+
+
+
+
+ mobilehotspot
+ /mobilehotspot/mobilehotspot
+
+
+
+
+ mobilehotspot open
+ /mobilehotspot/mobilehotspot open
+
+
+
+ MobileHotspotWidget
+
+
+
+ ukui control center
+
+
+
+
+ ukui control center desktop message
+
+
+
+
+ wirless switch is close or no wireless device
+
+
+
+
+ hotpots name or device is invalid
+
+
+
+
+ Hotspot
+
+
+
+
+
+ hotspot already close
+
+
+
+
+ Open
+
+
+
+
+ Wi-Fi Name
+
+
+
+
+ Password
+
+
+
+
+ Contains at least 8 characters
+
+
+
+
+ Frequency band
+
+
+
+
+ Net card
+
+
+
+
+
+ hotspot already open
+
+
+
diff --git a/plugins/mobilehotspot/translations/tr.ts b/plugins/mobilehotspot/translations/tr.ts
index fad9d3e2..2c1f8b3d 100644
--- a/plugins/mobilehotspot/translations/tr.ts
+++ b/plugins/mobilehotspot/translations/tr.ts
@@ -1,6 +1,38 @@
+
+ BlacklistItem
+
+
+
+
+
+
+
+ BlacklistPage
+
+
+
+
+
+
+
+ ConnectDevListItem
+
+
+
+
+
+
+
+ ConnectdevPage
+
+
+
+
+
+
MobileHotspot
@@ -24,79 +56,69 @@
MobileHotspotWidget
-
+
-
+
-
+
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
diff --git a/plugins/mobilehotspot/translations/zh_CN.qm b/plugins/mobilehotspot/translations/zh_CN.qm
index 52e6c4f8..1b67cfd1 100644
Binary files a/plugins/mobilehotspot/translations/zh_CN.qm and b/plugins/mobilehotspot/translations/zh_CN.qm differ
diff --git a/plugins/mobilehotspot/translations/zh_CN.ts b/plugins/mobilehotspot/translations/zh_CN.ts
index 0867a0ec..a9fb2288 100644
--- a/plugins/mobilehotspot/translations/zh_CN.ts
+++ b/plugins/mobilehotspot/translations/zh_CN.ts
@@ -1,6 +1,38 @@
+
+ BlacklistItem
+
+
+
+ 移出
+
+
+
+ BlacklistPage
+
+
+
+ 设备黑名单
+
+
+
+ ConnectDevListItem
+
+
+
+ 添加进黑名单
+
+
+
+ ConnectdevPage
+
+
+
+ 连接设备
+
+
MobileHotspot
@@ -24,79 +56,81 @@
MobileHotspotWidget
-
+
控制面板
-
+
控制面板桌面通知
-
+
无线开关已关闭或不存在有热点功能的无线网卡
-
- 开始关闭热点
+ 开始关闭热点
-
+
热点名称或设备错误
-
- 不能创建密码长度小于八位的热点!
+ 不能创建密码长度小于八位的热点!
-
- 开始创建热点
+ 开始创建热点
-
+
+
+ 至少包含8个字符
+
+
+
移动热点
-
-
+
+
热点已关闭
-
+
开启
-
+
Wi-Fi名称
-
+
网络密码
-
+
网络频带
-
+
共享网卡端口
-
-
+
+
热点已开启
diff --git a/plugins/netconnect/deviceframe.cpp b/plugins/netconnect/deviceframe.cpp
index 88f8fc0e..a90e9f67 100644
--- a/plugins/netconnect/deviceframe.cpp
+++ b/plugins/netconnect/deviceframe.cpp
@@ -1,8 +1,26 @@
+/* -*- 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 "deviceframe.h"
#include
-#include
-#define LAYOUT_MARGINS 18,0,24,0
+#define LAYOUT_MARGINS 16,0,16,0
#define FRAME_HEIGHT 58
#define RADIUS 6.0
@@ -17,6 +35,7 @@ DeviceFrame::DeviceFrame(QString devName, QWidget *parent) : QFrame(parent)
deviceLabel = new QLabel(this);
dropDownLabel = new DrownLabel(devName, this);
deviceSwitch = new KSwitchButton(this);
+ deviceSwitch->installEventFilter(this);
deviceLayout->addWidget(deviceLabel);
deviceLayout->addStretch();
@@ -24,9 +43,15 @@ DeviceFrame::DeviceFrame(QString devName, QWidget *parent) : QFrame(parent)
deviceLayout->addWidget(deviceSwitch);
}
-DeviceFrame::~DeviceFrame()
+bool DeviceFrame::eventFilter(QObject *w,QEvent *e)
{
-
+ if (w == deviceSwitch) {
+ if (e->type() == QEvent::MouseButtonPress) {
+ emit deviceSwitchClicked(!deviceSwitch->isChecked());
+ return true;
+ }
+ }
+ return QFrame::eventFilter(w, e);
}
void DeviceFrame::paintEvent(QPaintEvent *event)
diff --git a/plugins/netconnect/deviceframe.h b/plugins/netconnect/deviceframe.h
index 2807f067..9a5d0746 100644
--- a/plugins/netconnect/deviceframe.h
+++ b/plugins/netconnect/deviceframe.h
@@ -1,3 +1,22 @@
+/* -*- 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 DEVICEFRAME_H
#define DEVICEFRAME_H
#include
@@ -16,9 +35,9 @@ using namespace kdk;
class DeviceFrame : public QFrame
{
+ Q_OBJECT
public:
DeviceFrame(QString devName, QWidget *parent = nullptr);
- ~DeviceFrame();
public:
QLabel * deviceLabel = nullptr;
KSwitchButton * deviceSwitch = nullptr;
@@ -26,11 +45,14 @@ public:
protected:
void paintEvent(QPaintEvent *event);
+ bool eventFilter(QObject *w,QEvent *e);
private:
bool isDropDown = false;
int frameSize;
+signals:
+ void deviceSwitchClicked(bool);
};
#endif // DEVICEFRAME_H
diff --git a/plugins/netconnect/itemframe.cpp b/plugins/netconnect/itemframe.cpp
index 9fbea20f..17b83de7 100644
--- a/plugins/netconnect/itemframe.cpp
+++ b/plugins/netconnect/itemframe.cpp
@@ -1,3 +1,22 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
#include "itemframe.h"
#include
@@ -30,11 +49,6 @@ ItemFrame::ItemFrame(QString devName, QWidget *parent) : QFrame(parent)
connect(deviceFrame->dropDownLabel, &DrownLabel::labelClicked, this, &ItemFrame::onDrownLabelClicked);
}
-ItemFrame::~ItemFrame()
-{
-
-}
-
void ItemFrame::onDrownLabelClicked()
{
if (!deviceFrame->dropDownLabel->isChecked) {
diff --git a/plugins/netconnect/itemframe.h b/plugins/netconnect/itemframe.h
index 360b9e61..07aa0ee7 100644
--- a/plugins/netconnect/itemframe.h
+++ b/plugins/netconnect/itemframe.h
@@ -1,3 +1,22 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
#ifndef ITEMFRAME_H
#define ITEMFRAME_H
#include
@@ -12,7 +31,7 @@ class ItemFrame : public QFrame
Q_OBJECT
public:
ItemFrame(QString devName, QWidget *parent = nullptr);
- ~ItemFrame();
+
//单设备整体layout
QVBoxLayout * deviceLanLayout = nullptr;
//单设备名称+下拉按钮Frame+d单设备开关
diff --git a/plugins/netconnect/lanitem.cpp b/plugins/netconnect/lanitem.cpp
index f3536094..9e51efb1 100644
--- a/plugins/netconnect/lanitem.cpp
+++ b/plugins/netconnect/lanitem.cpp
@@ -1,4 +1,25 @@
+/* -*- 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 "lanitem.h"
+#include
+
#define FRAME_SPEED 150
#define LIMIT_TIME 60*1000
#define TOTAL_PAGE 8
@@ -20,9 +41,11 @@ 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 InfoButton(this);
+ infoLabel = new GrayInfoButton(this);
+
//【更多】菜单
m_moreButton = new QToolButton(this);
m_moreButton->setProperty("useButtonPalette", true);
@@ -54,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);
@@ -121,12 +143,17 @@ void LanItem::onDeletetTriggered()
void LanItem::paintEvent(QPaintEvent *event)
{
- QPalette pal = this->palette();
+ QPalette pal = qApp->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
- painter.setBrush(pal.color(QPalette::Base));
+ painter.setBrush(this->palette().base().color());
+
+ QColor color = pal.color(QPalette::Button);
+ color.setAlphaF(0.5);
+ pal.setColor(QPalette::Button, color);
+ this->setPalette(pal);
QRect rect = this->rect();
diff --git a/plugins/netconnect/lanitem.h b/plugins/netconnect/lanitem.h
index e749ab5f..b27a9df2 100644
--- a/plugins/netconnect/lanitem.h
+++ b/plugins/netconnect/lanitem.h
@@ -1,3 +1,22 @@
+/* -*- 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 LANITEM_H
#define LANITEM_H
#include
@@ -14,7 +33,8 @@
#include
#include
#include "fixlabel.h"
-#include "infobutton.h"
+//#include "infobutton.h"
+#include "../component/AddBtn/grayinfobutton.h"
class LanItem : public QPushButton
{
@@ -24,7 +44,7 @@ public:
~LanItem();
public:
QLabel * iconLabel = nullptr;
- InfoButton * infoLabel = nullptr;
+ GrayInfoButton * infoLabel = nullptr;
FixLabel * titileLabel = nullptr;
QLabel * statusLabel = nullptr;
QToolButton* m_moreButton = nullptr;
diff --git a/plugins/netconnect/netconnect.cpp b/plugins/netconnect/netconnect.cpp
index da55d78d..32384507 100644
--- a/plugins/netconnect/netconnect.cpp
+++ b/plugins/netconnect/netconnect.cpp
@@ -32,7 +32,9 @@
#define ITEMHEIGH 50
#define LAN_TYPE 0
#define CONTROL_CENTER_WIFI "org.ukui.control-center.wifi.switch"
-
+#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager"
+#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager"
+#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager"
const QString KLanSymbolic = "network-wired-connected-symbolic";
const QString NoNetSymbolic = "network-wired-disconnected-symbolic";
@@ -78,7 +80,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;
}
@@ -150,7 +152,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"));
}
@@ -168,7 +170,9 @@ bool NetConnect::eventFilter(QObject *w, QEvent *e) {
if (!wiredSwitch->isCheckable()) {
showDesktopNotify(tr("No ethernet device avaliable"));
} else {
- m_interface->call(QStringLiteral("setWiredSwitchEnable"), !wiredSwitch->isChecked());
+ if (m_interface != nullptr && m_interface->isValid()) {
+ m_interface->call(QStringLiteral("setWiredSwitchEnable"), !wiredSwitch->isChecked());
+ }
return true;
}
}
@@ -180,8 +184,10 @@ bool NetConnect::eventFilter(QObject *w, QEvent *e) {
void NetConnect::initComponent() {
wiredSwitch = new KSwitchButton(pluginWidget);
ui->openWIifLayout->addWidget(wiredSwitch);
+ ui->openWIifLayout->setContentsMargins(0,0,8,0);
ui->detailLayOut->setContentsMargins(MAIN_LAYOUT_MARGINS);
ui->verticalLayout_3->setContentsMargins(NO_MARGINS);
+ ui->verticalLayout_3->setSpacing(8);
ui->availableLayout->setSpacing(SPACING);
ui->horizontalLayout->setContentsMargins(TOP_MARGINS);
@@ -207,8 +213,8 @@ void NetConnect::initComponent() {
getDeviceStatusMap(deviceStatusMap);
if (deviceStatusMap.isEmpty()) {
qDebug() << "[Netconnect] no device exist when init, set switch disable";
- wiredSwitch->setCheckable(false);
wiredSwitch->setChecked(false);
+ wiredSwitch->setCheckable(false);
}
initNet();
@@ -240,7 +246,7 @@ void NetConnect::initComponent() {
//获取网卡列表
void NetConnect::getDeviceStatusMap(QMap &map)
{
- if (!m_interface->isValid()) {
+ if (m_interface == nullptr || !m_interface->isValid()) {
return;
}
qDebug() << "[NetConnect]call getDeviceListAndEnabled" << __LINE__;
@@ -347,12 +353,6 @@ void NetConnect::initNet()
}
}
-void NetConnect::runExternalApp() {
- QString cmd = "nm-connection-editor";
- QProcess process(this);
- process.startDetached(cmd);
-}
-
//刪除
void NetConnect::deleteOneLan(QString ssid, int type)
{
@@ -361,8 +361,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__;
@@ -370,6 +381,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__;
@@ -383,7 +397,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__;
@@ -446,9 +460,9 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL
lanItem->uuid = infoList.at(1);
lanItem->dbusPath = infoList.at(2);
- connect(lanItem->infoLabel, &InfoButton::clicked, this, [=]{
+ 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__;
@@ -486,6 +500,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__;
@@ -520,26 +537,32 @@ void NetConnect::addDeviceFrame(QString devName)
deviceFrameMap.insert(devName, itemFrame);
qDebug() << "[NetConnect]deviceFrameMap insert" << devName;
- connect(itemFrame->deviceFrame->deviceSwitch, &KSwitchButton::stateChanged, this, [=] (bool checked) {
+ connect(itemFrame->deviceFrame, &DeviceFrame::deviceSwitchClicked ,this, [=] (bool checked) {
qDebug() << "[NetConnect]call setDeviceEnable" << devName << checked << __LINE__;
m_interface->call(QStringLiteral("setDeviceEnable"), devName, checked);
qDebug() << "[NetConnect]call setDeviceEnable Respond" << __LINE__;
+ });
+
+ connect(itemFrame->deviceFrame->deviceSwitch, &KSwitchButton::stateChanged, this, [=] (bool checked) {
+
if (checked) {
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__;
@@ -612,13 +635,21 @@ void NetConnect::onDeviceStatusChanged()
}
deviceStatusMap = map;
if (deviceStatusMap.isEmpty()) {
- wiredSwitch->setCheckable(false);
wiredSwitch->setChecked(false);
+ wiredSwitch->setCheckable(false);
} else {
wiredSwitch->setCheckable(true);
setSwitchStatus();
}
+ QMap::iterator iter;
+ for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
+ if (deviceStatusMap.contains(iter.key())) {
+ if (iter.value()->deviceFrame->deviceSwitch->isChecked() != deviceStatusMap[iter.key()]) {
+ iter.value()->deviceFrame->deviceSwitch->setChecked(deviceStatusMap[iter.key()]);
+ }
+ }
+ }
}
void NetConnect::onDeviceNameChanged(QString oldName, QString newName, int type)
@@ -726,9 +757,9 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis
lanItem->uuid = connUuid;
lanItem->dbusPath = connDbusPath;
- connect(lanItem->infoLabel, &InfoButton::clicked, this, [=]{
+ 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__;
@@ -883,7 +914,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__;
@@ -914,3 +945,19 @@ int NetConnect::getInsertPos(QString connName, QString deviceName)
}
return index;
}
+
+bool NetConnect::LaunchApp(QString desktopFile)
+{
+ QDBusInterface m_appManagerDbusInterface(KYLIN_APP_MANAGER_NAME,
+ KYLIN_APP_MANAGER_PATH,
+ KYLIN_APP_MANAGER_INTERFACE,
+ QDBusConnection::sessionBus());//局部变量
+
+ if (!m_appManagerDbusInterface.isValid()) {
+ qWarning()<<"m_appManagerDbusInterface init error";
+ return false;
+ } else {
+ QDBusReply reply =m_appManagerDbusInterface.call("LaunchApp",desktopFile);
+ return reply;
+ }
+}
diff --git a/plugins/netconnect/netconnect.h b/plugins/netconnect/netconnect.h
index ad89998e..e8858614 100644
--- a/plugins/netconnect/netconnect.h
+++ b/plugins/netconnect/netconnect.h
@@ -123,6 +123,7 @@ private:
//单个lan连接状态变化
void itemActiveConnectionStatusChanged(LanItem *item, int status);
+ bool LaunchApp(QString desktopFile);
protected:
bool eventFilter(QObject *w,QEvent *e);
diff --git a/plugins/netconnect/netconnect.pro b/plugins/netconnect/netconnect.pro
index 539f2f97..500a3b7e 100644
--- a/plugins/netconnect/netconnect.pro
+++ b/plugins/netconnect/netconnect.pro
@@ -50,4 +50,6 @@ INSTALLS += target \
TRANSLATIONS += \
translations/zh_CN.ts \
translations/tr.ts \
- translations/bo.ts
+ translations/bo.ts \
+ translations/bo_CN.ts \
+ translations/en_US.ts
diff --git a/plugins/netconnect/translations/bo.ts b/plugins/netconnect/translations/bo.ts
index 80bbd9f4..9841010e 100644
--- a/plugins/netconnect/translations/bo.ts
+++ b/plugins/netconnect/translations/bo.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
-
+
@@ -17,19 +17,19 @@
LanItem
-
+
-
-
+
+
-
-
+
+
@@ -38,59 +38,59 @@
NetConnect
-
-
+
/netconnect/open
-
+
/netconnect/Advanced settings"
-
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
-
-
+
+
+
-
+
diff --git a/plugins/netconnect/translations/bo_CN.qm b/plugins/netconnect/translations/bo_CN.qm
new file mode 100644
index 00000000..f41e3534
Binary files /dev/null and b/plugins/netconnect/translations/bo_CN.qm differ
diff --git a/plugins/netconnect/translations/bo_CN.ts b/plugins/netconnect/translations/bo_CN.ts
new file mode 100644
index 00000000..895a44e9
--- /dev/null
+++ b/plugins/netconnect/translations/bo_CN.ts
@@ -0,0 +1,102 @@
+
+
+
+
+ AddNetBtn
+
+
+
+
+
+
+
+
+ སྐུད་ཡོད་བརྙན་འཕྲིན་ཁ་སྣོན་བྱས་ཡོད།
+
+
+
+ LanItem
+
+
+
+ སུབ་དགོས།
+
+
+
+
+
+ བར་མཚམས་ཆད་པ་རེད།
+
+
+
+
+
+ འབྲེལ་མཐུད་བཅས་བྱ་དགོས།
+
+
+
+ NetConnect
+
+
+
+ སྐུད་ཡོད་བརྙན་འཕྲིན་དྲ་བ།
+
+
+
+
+
+ སྒོ་ཕྱེ་བ།
+ /netconnect/open
+
+
+
+
+
+ སྔོན་ཐོན་གྱི་སྒྲིག་བཀོད།
+ /netconnect/Advanced settings"
+
+
+
+
+ ཝུའུ་ཁི་ལན་གྱི་ཚོད་འཛིན་ལྟེ་གནས།
+
+
+
+
+ ukui ཚོད་འཛིན་ལྟེ་གནས་ཀྱི་ཅོག་ངོས་ཆ་འཕྲིན།
+
+
+
+ སྐུད་ཡོད་སྦྲེལ་མཐུད།
+
+
+
+
+
+ སྐུད་ཡོད་དྲ་བ།
+
+
+
+
+ ཨེ་ཙི་དྲ་རྒྱའི་སྒྲིག་ཆས་ལ་བཙན་འཛུལ་བྱས་མི་ཆོག།
+
+
+
+
+
+ འབྲེལ་མཐུད་བྱེད་པ།
+
+
+
+
+
+
+ འབྲེལ་མཐུད་མ་བྱས་པ།
+
+
+
+
+ བྱང་བུ།
+
+
+
diff --git a/plugins/netconnect/translations/en_US.ts b/plugins/netconnect/translations/en_US.ts
new file mode 100644
index 00000000..67be9443
--- /dev/null
+++ b/plugins/netconnect/translations/en_US.ts
@@ -0,0 +1,98 @@
+
+
+
+
+ AddNetBtn
+
+
+
+ Add Others
+
+
+
+
+ Add WiredNetork
+
+
+
+ LanItem
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NetConnect
+
+
+
+ Wired Network
+
+
+
+
+
+ open
+ /netconnect/open
+
+
+
+
+
+ Advanced settings
+ /netconnect/Advanced settings"
+
+
+
+
+ ukui control center
+
+
+
+
+ ukui control center desktop message
+
+
+
+
+
+ LAN
+
+
+
+
+ No ethernet device avaliable
+
+
+
+
+
+ connected
+
+
+
+
+
+
+
+
+
+
+
+ card
+
+
+
diff --git a/plugins/netconnect/translations/tr.ts b/plugins/netconnect/translations/tr.ts
index 80bbd9f4..9841010e 100644
--- a/plugins/netconnect/translations/tr.ts
+++ b/plugins/netconnect/translations/tr.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
-
+
@@ -17,19 +17,19 @@
LanItem
-
+
-
-
+
+
-
-
+
+
@@ -38,59 +38,59 @@
NetConnect
-
-
+
/netconnect/open
-
+
/netconnect/Advanced settings"
-
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
-
-
+
+
+
-
+
diff --git a/plugins/netconnect/translations/zh_CN.qm b/plugins/netconnect/translations/zh_CN.qm
index 549add6b..6ac7d043 100644
Binary files a/plugins/netconnect/translations/zh_CN.qm and b/plugins/netconnect/translations/zh_CN.qm differ
diff --git a/plugins/netconnect/translations/zh_CN.ts b/plugins/netconnect/translations/zh_CN.ts
index 112fe9ce..da195eef 100644
--- a/plugins/netconnect/translations/zh_CN.ts
+++ b/plugins/netconnect/translations/zh_CN.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
- 加入其他网络
+
-
+
添加有线网络
@@ -17,19 +17,19 @@
LanItem
-
+
删除
-
-
+
+
断开
-
-
+
+
连接
@@ -38,59 +38,63 @@
NetConnect
-
有线网络
-
+
开启
/netconnect/open
-
+
高级设置
/netconnect/Advanced settings"
-
+
控制面板
-
+
控制面板桌面通知
-
+ 有线网络
+
+
+
+
+
有线网络
-
+
未检测到有线设备
-
-
+
+
已连接
-
-
-
+
+
+
未连接
-
+
网卡
diff --git a/plugins/plugin.pro b/plugins/plugin.pro
index e2b6db16..1ef03f43 100644
--- a/plugins/plugin.pro
+++ b/plugins/plugin.pro
@@ -4,4 +4,4 @@ SUBDIRS = \
wlanconnect \
mobilehotspot \
proxy \
- vpn \
+ vpn
diff --git a/plugins/proxy/applistwidget.cpp b/plugins/proxy/applistwidget.cpp
index c3c87109..dc2e5cd3 100644
--- a/plugins/proxy/applistwidget.cpp
+++ b/plugins/proxy/applistwidget.cpp
@@ -29,7 +29,7 @@ AppListWidget::AppListWidget(QString path, QWidget *parent)
AppListWidget::~AppListWidget()
{
-
+ delete m_dbusInterface;
}
/**
@@ -79,8 +79,9 @@ void AppListWidget::onAppCheckStateChanged()
*/
void AppListWidget::AddAppProxyConfig()
{
- if(!m_dbusInterface->isValid()) {
+ if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) {
qWarning ()<< "init AppProxy dbus error";
+ return;
}
qDebug() << "call QDBusInterface addAppIntoProxy";
@@ -93,8 +94,9 @@ void AppListWidget::AddAppProxyConfig()
*/
void AppListWidget::RemoveAppProxyConfig()
{
- if(!m_dbusInterface->isValid()) {
+ if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) {
qWarning ()<< "init AppProxy dbus error";
+ return;
}
qDebug() << "call QDBusInterface delAppIntoProxy";
@@ -116,7 +118,6 @@ void AppListWidget::initUI()
mainLayout->setContentsMargins(17, 0, 17, 0);
mainLayout->setSpacing(8);
m_checkBox = new QCheckBox(this);
- m_checkBox->setFixedSize(16, 16);
m_checkBox->setAttribute(Qt::WA_TransparentForMouseEvents, true); //m_checkBox不响应鼠标事件,将其传递给父窗口
m_iconLabel = new QLabel(this);
m_iconLabel->setFixedSize(24, 24);
@@ -135,4 +136,7 @@ void AppListWidget::initDbus()
"/org/ukui/SettingsDaemon/AppProxy",
"org.ukui.SettingsDaemon.AppProxy",
QDBusConnection::sessionBus());
+ if(!m_dbusInterface->isValid()) {
+ qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
+ }
}
diff --git a/plugins/proxy/proxy.cpp b/plugins/proxy/proxy.cpp
index 0e89d9e5..268eaa6b 100644
--- a/plugins/proxy/proxy.cpp
+++ b/plugins/proxy/proxy.cpp
@@ -45,7 +45,7 @@
#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
@@ -67,7 +67,8 @@ Proxy::Proxy() : mFirstLoad(true)
Proxy::~Proxy()
{
if (!mFirstLoad) {
- plugin_leave();
+ plugin_leave();
+ delete m_appProxyDbus;
}
}
@@ -162,6 +163,11 @@ QIcon Proxy::icon() const
return QIcon::fromTheme("ukui-network-agent-symbolic");
}
+QString Proxy::translationPath() const
+{
+ return "/usr/share/kylin-nm/proxy/%1.ts";
+}
+
bool Proxy::isEnable() const
{
return true;
@@ -702,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()
@@ -752,8 +761,11 @@ void Proxy::setAptProxy(QString host, QString port, bool status)
"/",
"com.control.center.interface",
QDBusConnection::systemBus());
- if (mAptproxyDbus->isValid())
+ if (mAptproxyDbus->isValid()) {
QDBusReply reply = mAptproxyDbus->call("setaptproxy", host, port , status);
+ }
+ delete mAptproxyDbus;
+ mAptproxyDbus = nullptr;
}
QHash Proxy::getAptProxy()
@@ -786,6 +798,8 @@ QHash Proxy::getAptProxy()
mAptInfo.insert(it.arg, it.out.variant());
}
}
+ delete mAptproxyDbus;
+ mAptproxyDbus = nullptr;
return mAptInfo;
}
@@ -814,8 +828,9 @@ void Proxy::reboot()
"/org/gnome/SessionManager",
"org.gnome.SessionManager",
QDBusConnection::sessionBus());
-
- rebootDbus->call("reboot");
+ if (rebootDbus->isValid()) {
+ rebootDbus->call("reboot");
+ }
delete rebootDbus;
rebootDbus = nullptr;
}
@@ -841,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;
}
//获取应用代理开启状态
@@ -859,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;
}
@@ -881,6 +897,7 @@ QStringList Proxy::getAppProxyConf()
if(!dbusInterface.isValid()) {
qWarning ()<< "init AppProxy dbus error";
+ return info;
}
//获取应用代理配置信息
@@ -903,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;
}
@@ -1160,18 +1178,23 @@ 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()
@@ -1240,7 +1263,6 @@ void Proxy::onAppProxyConfChanged()
{
if (!getipEditState(m_ipAddressLineEdit->text()) || m_portLineEdit->text().isEmpty()) {
return;
- qDebug() << "onAppProxyConfChanged return";
}
if (m_ipAddressLineEdit->text().isEmpty()) {
@@ -1257,8 +1279,6 @@ void Proxy::onAppProxyConfChanged()
m_appProxyInfo.append("");
m_appProxyInfo.append("");
}
-
- qDebug() << m_appProxyInfo << Q_FUNC_INFO << __LINE__;
}
}
@@ -1269,6 +1289,16 @@ void Proxy::onAppProxyConfEditFinished()
}
}
+void Proxy::onPaletteChanged()
+{
+ QPalette mpal(m_appListWidget->palette());
+ mpal.setColor(QPalette::Base, qApp->palette().base().color());
+ mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color());
+ m_appListWidget->setBackgroundRole(QPalette::Base);
+ m_appListWidget->setAlternatingRowColors(true);
+ m_appListWidget->setPalette(mpal);
+}
+
void Proxy::onappProxyEnableChanged(bool enable)
{
m_proxyTypeFrame->setVisible(enable);
diff --git a/plugins/proxy/proxy.h b/plugins/proxy/proxy.h
index 48d9cc30..6d690847 100644
--- a/plugins/proxy/proxy.h
+++ b/plugins/proxy/proxy.h
@@ -103,6 +103,7 @@ public:
bool isShowOnHomePage() const Q_DECL_OVERRIDE;
QIcon icon() const Q_DECL_OVERRIDE;
bool isEnable() const Q_DECL_OVERRIDE;
+ QString translationPath() const Q_DECL_OVERRIDE;
public:
void initUi(QWidget *widget);
@@ -262,8 +263,8 @@ private:
QFileSystemWatcher *mfileWatch_1;
QFileSystemWatcher *mfileWatch_2;
- QDBusInterface *mAptproxyDbus;
- QDBusInterface *m_appProxyDbus;
+// QDBusInterface *mAptproxyDbus;
+ QDBusInterface *m_appProxyDbus = nullptr;
bool isExistSettings = false;
bool settingsCreate;
@@ -277,6 +278,7 @@ private slots:
void onipEditStateChanged(); //IP地址无效提示
void onAppProxyConfChanged(); //应用代理配置信息变化
void onAppProxyConfEditFinished();
+ void onPaletteChanged();
// void onCancelBtnClicked();
// void onSaveBtnClicked();
// void setBtnEnable();
diff --git a/plugins/vpn/itemframe.cpp b/plugins/vpn/itemframe.cpp
index 816828f7..29b6bf9c 100644
--- a/plugins/vpn/itemframe.cpp
+++ b/plugins/vpn/itemframe.cpp
@@ -25,36 +25,36 @@
ItemFrame::ItemFrame(QWidget *parent)
:QFrame(parent)
{
- deviceLanLayout = new QVBoxLayout(this);
- deviceLanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
- lanItemFrame = new QFrame(this);
- lanItemFrame->setFrameShape(QFrame::Shape::NoFrame);
- lanItemFrame->setContentsMargins(LAYOUT_MARGINS);
+ m_mainVLayout = new QVBoxLayout(this);
+ m_mainVLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
+ m_vpnFrame = new QFrame(this);
+ m_vpnFrame->setFrameShape(QFrame::Shape::NoFrame);
+ m_vpnFrame->setContentsMargins(LAYOUT_MARGINS);
- lanItemLayout = new QVBoxLayout(this);
- lanItemLayout->setContentsMargins(LAYOUT_MARGINS);
- lanItemLayout->setSpacing(1);
- addWlanWidget = new AddNetBtn(false, this);
- addWlanWidget->setTextLabel(tr("Add Vpn"));
+ m_vpnVLayout = new QVBoxLayout(this);
+ m_vpnVLayout->setContentsMargins(LAYOUT_MARGINS);
+ m_vpnVLayout->setSpacing(1);
+ m_addVpnWidget = new AddNetBtn(false, this);
+ m_addVpnWidget->setTextLabel(tr("Add Vpn"));
- deviceLanLayout->setSpacing(1);
- setLayout(deviceLanLayout);
- lanItemFrame->setLayout(lanItemLayout);
+ m_mainVLayout->setSpacing(1);
+ setLayout(m_mainVLayout);
+ m_vpnFrame->setLayout(m_vpnVLayout);
- deviceLanLayout->addWidget(lanItemFrame);
- deviceLanLayout->addWidget(addWlanWidget);
+ m_mainVLayout->addWidget(m_vpnFrame);
+ m_mainVLayout->addWidget(m_addVpnWidget);
}
void ItemFrame::filletStyleChange()
{
- if (lanItemLayout->isEmpty()) {
+ if (m_vpnVLayout->isEmpty()) {
return;
}
- for (int i = 0; i < lanItemLayout->count(); ++i) {
- QLayoutItem *it = lanItemLayout->itemAt(i);
+ for (int i = 0; i < m_vpnVLayout->count(); ++i) {
+ QLayoutItem *it = m_vpnVLayout->itemAt(i);
VpnItem *itemFrame = (VpnItem*)(it->widget());
- if (i != lanItemLayout->count()-1) {
+ if (i != m_vpnVLayout->count()-1) {
itemFrame->setHalfFillet(false);
} else {
itemFrame->setHalfFillet(true);
diff --git a/plugins/vpn/itemframe.h b/plugins/vpn/itemframe.h
index b41153fa..18595863 100644
--- a/plugins/vpn/itemframe.h
+++ b/plugins/vpn/itemframe.h
@@ -29,18 +29,18 @@ class ItemFrame : public QFrame
Q_OBJECT
public:
ItemFrame(QWidget *parent = nullptr);
- //单设备整体layout
- QVBoxLayout * deviceLanLayout = nullptr;
- //单设备列表Frame
- QFrame * lanItemFrame = nullptr;
+ //VPN整体layout
+ QVBoxLayout * m_mainVLayout = nullptr;
+ //vpn列表Frame
+ QFrame * m_vpnFrame = nullptr;
//单设备列表layout
- QVBoxLayout * lanItemLayout = nullptr;
+ QVBoxLayout * m_vpnVLayout = nullptr;
//item列表
- QMap itemMap;
+ QMap m_itemMap;
// //已激活uuid
// QString uuid = "";
//新建无线连接
- AddNetBtn * addWlanWidget = nullptr;
+ AddNetBtn * m_addVpnWidget = nullptr;
void filletStyleChange();
};
diff --git a/plugins/vpn/vpn.cpp b/plugins/vpn/vpn.cpp
index 143e06da..0ba36924 100644
--- a/plugins/vpn/vpn.cpp
+++ b/plugins/vpn/vpn.cpp
@@ -59,19 +59,19 @@
const QString VISIBLE = "visible";
const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.vpnicon";
-Vpn::Vpn() : mFirstLoad(true)
+Vpn::Vpn() : m_firstLoad(true)
{
QTranslator* translator = new QTranslator(this);
translator->load("/usr/share/kylin-nm/vpn/" + QLocale::system().name());
QApplication::installTranslator(translator);
- pluginName = tr("Vpn");
- pluginType = NETWORK;
+ m_pluginName = tr("Vpn");
+ m_pluginType = NETWORK;
}
Vpn::~Vpn()
{
- if (!mFirstLoad) {
+ if (!m_firstLoad) {
delete ui;
ui = nullptr;
delete m_interface;
@@ -80,25 +80,25 @@ Vpn::~Vpn()
}
QString Vpn::plugini18nName(){
- return pluginName;
+ return m_pluginName;
}
int Vpn::pluginTypes(){
- return pluginType;
+ return m_pluginType;
}
QWidget *Vpn::pluginUi(){
- if (mFirstLoad) {
- mFirstLoad = false;
+ if (m_firstLoad) {
+ m_firstLoad = false;
ui = new Ui::Vpn;
- pluginWidget = new QWidget;
- pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
- ui->setupUi(pluginWidget);
+ m_pluginWidget = new QWidget;
+ m_pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
+ ui->setupUi(m_pluginWidget);
qDBusRegisterMetaType>();
- m_interface = new QDBusInterface("com.kylin.network",
- "/com/kylin/vpnTool",
- "com.kylin.vpnTool",
+ m_interface = new QDBusInterface("com.kylin.kylinvpn",
+ "/com/kylin/kylinvpn",
+ "com.kylin.kylinvpn",
QDBusConnection::sessionBus());
if(!m_interface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
@@ -108,7 +108,7 @@ QWidget *Vpn::pluginUi(){
initConnect();
initNet();
}
- return pluginWidget;
+ return m_pluginWidget;
}
const QString Vpn::name() const {
@@ -134,12 +134,12 @@ bool Vpn::isEnable() const
void Vpn::initComponent(){
//在任务栏上显示图标
//显示已连接时间
- m_topFrame = new QFrame(pluginWidget);
+ m_topFrame = new QFrame(m_pluginWidget);
m_topFrame->setMinimumSize(FRAME_MIN_SIZE);
m_topFrame->setMaximumSize(FRAME_MAX_SIZE);
m_topFrame->setFrameShape(QFrame::Box);
- QVBoxLayout *hotspotLyt = new QVBoxLayout(pluginWidget);
+ QVBoxLayout *hotspotLyt = new QVBoxLayout(m_pluginWidget);
hotspotLyt->setContentsMargins(0, 0, 0, 0);
m_topFrame->setLayout(hotspotLyt);
@@ -181,12 +181,13 @@ 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 +268,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 +300,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 +314,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 +329,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, &InfoButton::clicked, this, [=]{
- QDBusInterface appManagerDbusInterface(KYLIN_APP_MANAGER_NAME,
- KYLIN_APP_MANAGER_PATH,
- KYLIN_APP_MANAGER_INTERFACE,
- QDBusConnection::sessionBus());
-
- if (!appManagerDbusInterface.isValid()) {
- qWarning()<<"appManagerDbusInterface init error";
- } else {
- QDBusReply reply = appManagerDbusInterface.call("LaunchApp", "nm-connection-editor.desktop");
- }
+ connect(item->m_infoLabel, &GrayInfoButton::clicked, this, [=]{
+ showDetailPage(item->m_uuid);
});
- item->isAcitve = (status == 2);
- item->setConnectActionText(item->isAcitve);
+ item->m_isAcitve = (status == 2);
+ item->setConnectActionText(item->m_isAcitve);
- if (item->isAcitve) {
- item->statusLabel->setText(tr("connected"));
+ if (item->m_isAcitve) {
+ item->m_statusLabel->setText(tr("connected"));
} else {
- item->statusLabel->setText(tr("not connected"));
+ item->m_statusLabel->setText(tr("not connected"));
}
connect(item, &QPushButton::clicked, this, [=] {
- if (item->isAcitve || item->loading) {
- deActiveConnect(item->uuid);
+ if (item->m_isAcitve || item->m_loading) {
+ deActiveConnect(item->m_uuid);
} else {
- activeConnect(item->uuid);
+ activeConnect(item->m_uuid);
}
});
connect(item, &VpnItem::connectActionTriggered, this, [=] {
- activeConnect(item->uuid);
+ activeConnect(item->m_uuid);
});
connect(item, &VpnItem::disconnectActionTriggered, this, [=] {
- deActiveConnect(item->uuid);
+ deActiveConnect(item->m_uuid);
});
connect(item, &VpnItem::deleteActionTriggered, this, [=] {
- deleteVpn(item->uuid);
+ deleteVpn(item->m_uuid);
});
- //记录到deviceFrame的itemMap中
- m_listFrame->itemMap.insert(connUuid, item);
+ //记录到deviceFrame的m_itemMap中
+ m_listFrame->m_itemMap.insert(connUuid, item);
int index = getInsertPos(connName);
qDebug()<<"[Vpn]addOneVirtualItem " << connName << " at pos:" << index;
- m_listFrame->lanItemLayout->insertWidget(index, item);
+ m_listFrame->m_vpnVLayout->insertWidget(index, item);
}
void Vpn::removeOneVirtualItem(QString dbusPath)
@@ -379,13 +385,13 @@ void Vpn::removeOneVirtualItem(QString dbusPath)
qDebug()<<"[Vpn]vpn remove dbus path:" << dbusPath;
QMap::iterator itemIter;
- for (itemIter = m_listFrame->itemMap.begin(); itemIter != m_listFrame->itemMap.end(); itemIter++) {
- if (itemIter.value()->dbusPath == dbusPath) {
- qDebug()<<"[Vpn]vpn remove " << dbusPath << " find in " << itemIter.value()->titileLabel->text();
+ for (itemIter = m_listFrame->m_itemMap.begin(); itemIter != m_listFrame->m_itemMap.end(); itemIter++) {
+ if (itemIter.value()->m_dbusPath == dbusPath) {
+ qDebug()<<"[Vpn]vpn remove " << dbusPath << " find in " << itemIter.value()->m_titileLabel->text();
QString key = itemIter.key();
- m_listFrame->lanItemLayout->removeWidget(itemIter.value());
+ m_listFrame->m_vpnVLayout->removeWidget(itemIter.value());
delete itemIter.value();
- m_listFrame->itemMap.remove(key);
+ m_listFrame->m_itemMap.remove(key);
break;
}
}
@@ -398,18 +404,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 +429,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 +454,22 @@ void Vpn::itemActiveConnectionStatusChanged(VpnItem *item, int status)
} else if (status == ACTIVATED) {
item->stopLoading();
// iconPath = KLanSymbolic;
- item->statusLabel->clear();
- item->statusLabel->setMinimumSize(36,36);
- item->statusLabel->setMaximumSize(16777215,16777215);
- item->statusLabel->setText(tr("connected"));
- item->isAcitve = true;
+ item->m_statusLabel->clear();
+ item->m_statusLabel->setMinimumSize(36,36);
+ item->m_statusLabel->setMaximumSize(16777215,16777215);
+ item->m_statusLabel->setText(tr("connected"));
+ item->m_isAcitve = true;
} else if (status == DEACTIVATING) {
item->startLoading();
} else {
item->stopLoading();
- item->statusLabel->setMinimumSize(36,36);
- item->statusLabel->setMaximumSize(16777215,16777215);
- item->statusLabel->clear();
- item->isAcitve = false;
- item->statusLabel->setText(tr("not connected"));
+ item->m_statusLabel->setMinimumSize(36,36);
+ item->m_statusLabel->setMaximumSize(16777215,16777215);
+ item->m_statusLabel->clear();
+ item->m_isAcitve = false;
+ item->m_statusLabel->setText(tr("not connected"));
}
- item->setConnectActionText(item->isAcitve);
+ item->setConnectActionText(item->m_isAcitve);
}
int Vpn::getInsertPos(QString connName)
diff --git a/plugins/vpn/vpn.h b/plugins/vpn/vpn.h
index 941f8f4f..82d89ea2 100644
--- a/plugins/vpn/vpn.h
+++ b/plugins/vpn/vpn.h
@@ -69,9 +69,9 @@ protected:
private:
Ui::Vpn *ui;
- QString pluginName;
- int pluginType;
- QWidget * pluginWidget;
+ QString m_pluginName;
+ int m_pluginType;
+ QWidget * m_pluginWidget;
QDBusInterface *m_interface = nullptr;
@@ -85,7 +85,7 @@ private:
KSwitchButton *m_timeBtn;
ItemFrame *m_listFrame;
- bool mFirstLoad;
+ bool m_firstLoad;
QGSettings *m_switchGsettings;
QFrame* myLine();
@@ -95,6 +95,7 @@ private:
void deleteVpn(QString uuid);
void activeConnect(QString uuid);
void deActiveConnect(QString uuid);
+ void showDetailPage(QString uuid);
//获取设备列表
void initNet();
diff --git a/plugins/vpn/vpnitem.cpp b/plugins/vpn/vpnitem.cpp
index 57c2cff4..19b0e877 100644
--- a/plugins/vpn/vpnitem.cpp
+++ b/plugins/vpn/vpnitem.cpp
@@ -28,7 +28,7 @@
#define MODE_QT_KEY "style-name"
VpnItem::VpnItem(bool bAcitve, QWidget *parent)
- : isAcitve(bAcitve), QPushButton(parent)
+ : m_isAcitve(bAcitve), QPushButton(parent)
{
this->setMinimumSize(550, 58);
this->setProperty("useButtonPalette", true);
@@ -41,12 +41,12 @@ VpnItem::VpnItem(bool bAcitve, QWidget *parent)
QHBoxLayout *mLanLyt = new QHBoxLayout(this);
mLanLyt->setContentsMargins(16,0,16,0);
mLanLyt->setSpacing(16);
- iconLabel = new QLabel(this);
- iconLabel->setProperty("useIconHighlightEffect", 0x2);
- titileLabel = new FixLabel(this);
- statusLabel = new QLabel(this);
- statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
- infoLabel = new InfoButton(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,28 @@ 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 +86,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 +145,7 @@ void VpnItem::paintEvent(QPaintEvent *event)
QRect rect = this->rect();
#if 0
- if (!useHalfFillet) {
+ if (!m_useHalfFillet) {
painter.drawRect(rect);
} else {
QPainterPath path;
diff --git a/plugins/vpn/vpnitem.h b/plugins/vpn/vpnitem.h
index 2df6a25a..bbe8a3ec 100644
--- a/plugins/vpn/vpnitem.h
+++ b/plugins/vpn/vpnitem.h
@@ -33,7 +33,7 @@
#include
#include
#include "fixlabel.h"
-#include "infobutton.h"
+#include "../component/AddBtn/grayinfobutton.h"
class VpnItem : public QPushButton
{
@@ -41,37 +41,36 @@ class VpnItem : public QPushButton
public:
VpnItem(bool bAcitve, QWidget *parent = nullptr);
public:
- QLabel * iconLabel = nullptr;
- InfoButton * infoLabel = nullptr;
- FixLabel * titileLabel = nullptr;
- QLabel * statusLabel = nullptr;
+ QLabel * m_iconLabel = nullptr;
+ GrayInfoButton * m_infoLabel = nullptr;
+ FixLabel * m_titileLabel = nullptr;
+ QLabel * m_statusLabel = nullptr;
QToolButton* m_moreButton = nullptr;
QMenu* m_moreMenu = nullptr;
QAction* m_connectAction = nullptr;
QAction* m_deleteAction = nullptr;
- QString uuid = "";
- QString dbusPath = "";
+ QString m_uuid = "";
+ QString m_dbusPath = "";
- void setHalfFillet(bool flag) {useHalfFillet = flag; repaint();}
+ void setHalfFillet(bool flag) {m_useHalfFillet = flag; repaint();}
public:
void startLoading();
void stopLoading();
void setConnectActionText(bool isAcitve);
- bool isAcitve = false;
- bool loading = false;
+ bool m_isAcitve = false;
+ bool m_loading = false;
protected:
void paintEvent(QPaintEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
private:
- QTimer *waitTimer = nullptr;
- QGSettings *themeGsettings = nullptr;
- bool useHalfFillet = false;
- QList loadIcons;
- int currentIconIndex=0;
+ QTimer *m_waitTimer = nullptr;
+ bool m_useHalfFillet = false;
+ QList m_loadIcons;
+ int m_currentIconIndex=0;
private slots:
void updateIcon();
diff --git a/plugins/wlanconnect/deviceframe.cpp b/plugins/wlanconnect/deviceframe.cpp
index 9765faef..a7822712 100644
--- a/plugins/wlanconnect/deviceframe.cpp
+++ b/plugins/wlanconnect/deviceframe.cpp
@@ -1,3 +1,22 @@
+/* -*- 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 "deviceframe.h"
#include
#include
diff --git a/plugins/wlanconnect/deviceframe.h b/plugins/wlanconnect/deviceframe.h
index f70eda47..d6300e36 100644
--- a/plugins/wlanconnect/deviceframe.h
+++ b/plugins/wlanconnect/deviceframe.h
@@ -1,3 +1,22 @@
+/* -*- 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 DEVICEFRAME_H
#define DEVICEFRAME_H
#include
diff --git a/plugins/wlanconnect/itemframe.cpp b/plugins/wlanconnect/itemframe.cpp
index 05112f29..503e3b2b 100644
--- a/plugins/wlanconnect/itemframe.cpp
+++ b/plugins/wlanconnect/itemframe.cpp
@@ -1,3 +1,22 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
#include "itemframe.h"
#include
diff --git a/plugins/wlanconnect/itemframe.h b/plugins/wlanconnect/itemframe.h
index 4a980920..ee947279 100644
--- a/plugins/wlanconnect/itemframe.h
+++ b/plugins/wlanconnect/itemframe.h
@@ -1,3 +1,22 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
#ifndef ITEMFRAME_H
#define ITEMFRAME_H
#include
diff --git a/plugins/wlanconnect/translations/bo.ts b/plugins/wlanconnect/translations/bo.ts
index f8fab3a1..824aac8c 100644
--- a/plugins/wlanconnect/translations/bo.ts
+++ b/plugins/wlanconnect/translations/bo.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
-
+
@@ -18,54 +18,54 @@
WlanConnect
-
-
+
+
-
+
/wlanconnect/open
-
+
/wlanconnect/Advanced settings"
-
+
-
+
-
+
-
-
-
+
+
+
-
+
diff --git a/plugins/wlanconnect/translations/bo_CN.qm b/plugins/wlanconnect/translations/bo_CN.qm
new file mode 100644
index 00000000..8f72b8c9
Binary files /dev/null and b/plugins/wlanconnect/translations/bo_CN.qm differ
diff --git a/plugins/wlanconnect/translations/bo_CN.ts b/plugins/wlanconnect/translations/bo_CN.ts
new file mode 100644
index 00000000..7be28fd3
--- /dev/null
+++ b/plugins/wlanconnect/translations/bo_CN.ts
@@ -0,0 +1,73 @@
+
+
+
+
+ AddNetBtn
+
+
+
+ དྲ་རྒྱ་གཞན་དག་ནང་ཞུགས་དགོས།
+
+
+
+
+
+
+
+
+ WlanConnect
+
+
+
+ ཝུའུ་ལན་འབྲེལ་མཐུད།
+
+
+
+
+
+
+ སྐུད་མེད་ཅུས་ཁོངས་ཀྱི་དྲ་བ།
+
+
+
+
+
+ སྒོ་ཕྱེ་བ།
+ /wlanconnect/open
+
+
+
+
+
+ སྔོན་ཐོན་གྱི་སྒྲིག་བཀོད།
+ /wlanconnect/Advanced settings"
+
+
+
+
+ ཝུའུ་ཁི་ལན་གྱི་ཚོད་འཛིན་ལྟེ་གནས།
+
+
+
+
+ ངོས་ལེབ་ངོས་ཀྱི་བརྡ་ཐོ་ཚོད་འཛིན་བྱ་དགོས།
+
+
+
+
+ སྐུད་མེད་དྲ་རྒྱའི་བྱང་བུ་མ་རྙེད་པ།
+
+
+
+
+
+
+ འབྲེལ་མཐུད་བྱེད་པ།
+
+
+
+
+ བྱང་བུ།
+
+
+
diff --git a/plugins/wlanconnect/translations/en_US.ts b/plugins/wlanconnect/translations/en_US.ts
new file mode 100644
index 00000000..01b3915e
--- /dev/null
+++ b/plugins/wlanconnect/translations/en_US.ts
@@ -0,0 +1,73 @@
+
+
+
+
+ AddNetBtn
+
+
+
+ Add Others
+
+
+
+
+ Add WiredNetork
+
+
+
+ WlanConnect
+
+
+
+ WlanConnect
+
+
+
+
+
+
+ WLAN
+
+
+
+
+
+ open
+ /wlanconnect/open
+
+
+
+
+
+ Advanced settings
+ /wlanconnect/Advanced settings"
+
+
+
+
+ ukui control center
+
+
+
+
+ ukui control center desktop message
+
+
+
+
+ No wireless network card detected
+
+
+
+
+
+
+ connected
+
+
+
+
+ card
+
+
+
diff --git a/plugins/wlanconnect/translations/tr.ts b/plugins/wlanconnect/translations/tr.ts
index f8fab3a1..824aac8c 100644
--- a/plugins/wlanconnect/translations/tr.ts
+++ b/plugins/wlanconnect/translations/tr.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
-
+
@@ -18,54 +18,54 @@
WlanConnect
-
-
+
+
-
+
/wlanconnect/open
-
+
/wlanconnect/Advanced settings"
-
+
-
+
-
+
-
-
-
+
+
+
-
+
diff --git a/plugins/wlanconnect/translations/zh_CN.ts b/plugins/wlanconnect/translations/zh_CN.ts
index a62ddac2..52d7a5cc 100644
--- a/plugins/wlanconnect/translations/zh_CN.ts
+++ b/plugins/wlanconnect/translations/zh_CN.ts
@@ -4,12 +4,12 @@
AddNetBtn
-
+
加入其它网络
-
+
@@ -18,54 +18,54 @@
WlanConnect
-
无线局域网
-
+
+
无线局域网
-
+
开启
/wlanconnect/open
-
+
高级设置
/wlanconnect/Advanced settings"
-
+
控制面板
-
+
控制面板桌面通知
-
+
未检测到无线网卡
-
-
-
+
+
+
已连接
-
+
网卡
diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp
index 4f174a56..2dcb4f9c 100644
--- a/plugins/wlanconnect/wlanconnect.cpp
+++ b/plugins/wlanconnect/wlanconnect.cpp
@@ -48,6 +48,10 @@
#define SIGNAL_NONE 5
#define ICON_SIZE 16,16
+#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager"
+#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager"
+#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager"
+
const QString WIRELESS_SWITCH = "wirelessswitch";
const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch";
@@ -137,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;
}
@@ -148,7 +152,6 @@ WlanConnect::~WlanConnect()
ui = nullptr;
}
delete m_interface;
- delete m_switchGsettings;
}
QString WlanConnect::plugini18nName() {
@@ -174,6 +177,7 @@ QWidget *WlanConnect::pluginUi() {
if(!m_interface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
}
+ initSearchText();
initComponent();
}
return pluginWidget;
@@ -224,10 +228,12 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
if (w == m_wifiSwitch) {
if (e->type() == QMouseEvent::MouseButtonRelease) {
- if (!m_wifiSwitch->isCheckable()) {
+ if (!getSwitchBtnEnable()) {
showDesktopNotify(tr("No wireless network card detected"));
} else {
- m_interface->call(QStringLiteral("setWirelessSwitchEnable"), !m_wifiSwitch->isChecked());
+ if (m_interface != nullptr && m_interface->isValid()) {
+ m_interface->call(QStringLiteral("setWirelessSwitchEnable"), !getSwitchBtnState());
+ }
return true;
}
}
@@ -239,40 +245,27 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
void WlanConnect::initComponent() {
m_wifiSwitch = new KSwitchButton(pluginWidget);
ui->openWIifLayout->addWidget(m_wifiSwitch);
+ ui->openWIifLayout->setContentsMargins(0,0,8,0);
ui->detailLayOut_3->setContentsMargins(MAIN_LAYOUT_MARGINS);
ui->verticalLayout_3->setContentsMargins(NO_MARGINS);
+ ui->verticalLayout_3->setSpacing(8);
ui->availableLayout->setSpacing(SPACING);
m_wifiSwitch->installEventFilter(this);
//开关
- if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
- m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
-
- setSwitchStatus();
-
- connect(m_switchGsettings, &QGSettings::changed, this, [=] (const QString &key) {
- if (key == WIRELESS_SWITCH) {
- setSwitchStatus();
- }
- });
- } else {
- m_wifiSwitch->blockSignals(true);
- m_wifiSwitch->setChecked(true);
- m_wifiSwitch->blockSignals(false);
- qDebug()<<"[netconnect] org.ukui.kylin-nm.switch is not installed!";
- }
+ initSwtichState();
//获取设备列表
getDeviceList(deviceList);
if (deviceList.isEmpty()) {
qDebug() << "[WlanConnect]no device exist when init, set switch disable";
- m_wifiSwitch->setCheckable(false);
- m_wifiSwitch->setChecked(false);
+ setSwitchBtnState(false);
+ setSwitchBtnEnable(false);
}
initNet();
- if (!m_wifiSwitch->isChecked() || deviceList.isEmpty() || !m_interface->isValid()) {
+ if (!getSwitchBtnState() || deviceList.isEmpty() || !m_interface->isValid()) {
hideLayout(ui->availableLayout);
}
@@ -288,7 +281,7 @@ void WlanConnect::initComponent() {
// connect(m_interface, SIGNAL(signalStrengthChange(QString, QString, int)), this, SLOT(updateStrengthList(QString, QString, int)));
//网卡name处理
connect(m_interface, SIGNAL(deviceNameChanged(QString, QString, int)), this, SLOT(onDeviceNameChanged(QString, QString, int)), Qt::QueuedConnection);
-
+ connect(m_interface, SIGNAL(wirelessSwitchBtnChanged(bool)), this, SLOT(onSwitchBtnChanged(bool)), Qt::QueuedConnection);
connect(m_interface, SIGNAL(timeToUpdate()), this, SLOT(updateList()), Qt::QueuedConnection);
//高级设置
connect(ui->detailBtn, &QPushButton::clicked, this, [=](bool checked) {
@@ -310,7 +303,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__;
@@ -320,11 +313,11 @@ void WlanConnect::reScan()
//更新列表顺序
void WlanConnect::updateList()
{
- if (!m_wifiSwitch->isChecked()) {
+ if (!getSwitchBtnState()) {
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__;
@@ -438,9 +431,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";
}
@@ -525,11 +518,17 @@ void WlanConnect::onDeviceStatusChanged()
}
deviceList = list;
if (deviceList.isEmpty()) {
- m_wifiSwitch->setCheckable(false);
- m_wifiSwitch->setChecked(false);
+ setSwitchBtnState(false);
+ setSwitchBtnEnable(false);
} else {
- m_wifiSwitch->setCheckable(true);
- setSwitchStatus();
+ setSwitchBtnEnable(true);
+ initSwtichState();
+ }
+
+ if (!getSwitchBtnState()) {
+ hideLayout(ui->availableLayout);
+ } else {
+ showLayout(ui->availableLayout);
}
}
@@ -558,10 +557,24 @@ void WlanConnect::onDeviceNameChanged(QString oldName, QString newName, int type
}
}
+void WlanConnect::onSwitchBtnChanged(bool state)
+{
+ if (getSwitchBtnState() == state) {
+ return;
+ }
+ setSwitchBtnEnable(true);
+ setSwitchBtnState(state);
+ if (!getSwitchBtnState()) {
+ hideLayout(ui->availableLayout);
+ } else {
+ showLayout(ui->availableLayout);
+ }
+}
+
//activeconnect status change
void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, int status)
{
- if (!m_wifiSwitch->isChecked()) {
+ if (!getSwitchBtnState()) {
return;
}
if (uuid.isEmpty()) {
@@ -623,7 +636,7 @@ void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QS
void WlanConnect::onNetworkAdd(QString deviceName, QStringList wlanInfo)
{
qDebug()<<"[WlanConnect]onNetworkAdd "<< deviceName << " " << wlanInfo;
- if(!m_wifiSwitch->isChecked() || deviceName.isEmpty()) {
+ if(!getSwitchBtnState() || deviceName.isEmpty()) {
return;
}
@@ -676,7 +689,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__;
@@ -693,25 +706,23 @@ void WlanConnect::getDeviceList(QStringList &list)
list = map.keys();
}
-//设置开关
-void WlanConnect::setSwitchStatus()
+void WlanConnect::initSwtichState()
{
-// if (deviceList.size() == 0) {
-// m_wifiSwitch->blockSignals(true);
-// m_wifiSwitch->setChecked(false);
-// m_wifiSwitch->blockSignals(false);
-// return;
-// }
- bool status = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
- qDebug() << "[WlanConnect]setSwitchStatus" << status;
- m_wifiSwitch->blockSignals(true);
- m_wifiSwitch->setChecked(status);
- m_wifiSwitch->blockSignals(false);
- if (!m_wifiSwitch->isChecked()) {
- hideLayout(ui->availableLayout);
- } else {
- showLayout(ui->availableLayout);
+ if (m_interface == nullptr || !m_interface->isValid()) {
+ return;
}
+
+ QDBusMessage result = m_interface->call("getWirelessSwitchBtnState");
+ qDebug() << "[WlanConnect]call getWirelessSwitchBtnState respond" << __LINE__;
+ if(result.type() == QDBusMessage::ErrorMessage)
+ {
+ qWarning() << "[WlanConnect]getWirelessSwitchBtnState error:" << result.errorMessage();
+ return;
+ }
+
+ bool state = result.arguments().at(0).toBool();
+ setSwitchBtnEnable(true);
+ setSwitchBtnState(state);
}
//初始化整体列表和单设备列表
@@ -731,7 +742,7 @@ void WlanConnect::initNet() {
void WlanConnect::initNetListFromDevice(QString deviceName)
{
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName;
- if (!m_wifiSwitch->isChecked()) {
+ if (!getSwitchBtnState()) {
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName << " switch off";
return;
}
@@ -739,7 +750,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__;
@@ -777,9 +788,11 @@ void WlanConnect::initNetListFromDevice(QString deviceName)
//高级设置
void WlanConnect::runExternalApp() {
- QString cmd = "nm-connection-editor";
- QProcess process(this);
- process.startDetached(cmd);
+ if (!LaunchApp("nm-connection-editor.desktop")){
+ QString cmd = "nm-connection-editor";
+ QProcess process(this);
+ process.startDetached(cmd);
+ }
}
//根据信号强度分级+安全性分图标
@@ -872,6 +885,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__;
@@ -898,7 +914,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__;
@@ -907,7 +923,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__;
@@ -960,7 +976,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__;
@@ -1012,9 +1028,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);
@@ -1026,9 +1042,9 @@ void WlanConnect::addOneWlanFrame(ItemFrame *frame, QString deviceName, QString
wlanItem->statusLabel->setText("");
}
- connect(wlanItem->infoLabel, &InfoButton::clicked, this, [=]{
+ 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__;
@@ -1094,3 +1110,18 @@ void WlanConnect::itemActiveConnectionStatusChanged(WlanItem *item, int status)
}
}
+bool WlanConnect::LaunchApp(QString desktopFile)
+{
+ QDBusInterface m_appManagerDbusInterface(KYLIN_APP_MANAGER_NAME,
+ KYLIN_APP_MANAGER_PATH,
+ KYLIN_APP_MANAGER_INTERFACE,
+ QDBusConnection::sessionBus());//局部变量
+
+ if (!m_appManagerDbusInterface.isValid()) {
+ qWarning()<<"m_appManagerDbusInterface init error";
+ return false;
+ } else {
+ QDBusReply reply =m_appManagerDbusInterface.call("LaunchApp",desktopFile);
+ return reply;
+ }
+}
diff --git a/plugins/wlanconnect/wlanconnect.h b/plugins/wlanconnect/wlanconnect.h
index 0a7800d5..abb2c8c0 100644
--- a/plugins/wlanconnect/wlanconnect.h
+++ b/plugins/wlanconnect/wlanconnect.h
@@ -98,7 +98,6 @@ private:
//开关相关
- void setSwitchStatus();
void hideLayout(QVBoxLayout * layout);
void showLayout(QVBoxLayout * layout);
@@ -124,6 +123,33 @@ private:
//单个wifi连接状态变化
void itemActiveConnectionStatusChanged(WlanItem *item, int status);
+
+ void initSwtichState();
+ inline void setSwitchBtnEnable(bool state) {
+ if (m_wifiSwitch != nullptr) {
+ m_wifiSwitch->setEnabled(state);
+ }
+ }
+ inline bool getSwitchBtnEnable() {
+ if (m_wifiSwitch != nullptr) {
+ return m_wifiSwitch->isEnabled();
+ }
+ }
+
+ inline void setSwitchBtnState(bool state) {
+ if (m_wifiSwitch != nullptr) {
+ m_wifiSwitch->blockSignals(true);
+ m_wifiSwitch->setChecked(state);
+ m_wifiSwitch->blockSignals(false);
+ }
+ }
+ inline bool getSwitchBtnState() {
+ if (m_wifiSwitch != nullptr) {
+ return m_wifiSwitch->isChecked();
+ }
+ }
+
+ bool LaunchApp(QString desktopFile);
protected:
bool eventFilter(QObject *w,QEvent *e);
@@ -136,8 +162,6 @@ private:
QDBusInterface *m_interface = nullptr;
- QGSettings *m_switchGsettings = nullptr;
-
//设备列表
QStringList deviceList;
//设备名 + 单设备frame
@@ -162,6 +186,8 @@ private slots:
void onDeviceStatusChanged();
void onDeviceNameChanged(QString, QString, int);
+ void onSwitchBtnChanged(bool);
+
void reScan();
diff --git a/plugins/wlanconnect/wlanconnect.pro b/plugins/wlanconnect/wlanconnect.pro
index f6da053d..d558656a 100644
--- a/plugins/wlanconnect/wlanconnect.pro
+++ b/plugins/wlanconnect/wlanconnect.pro
@@ -50,4 +50,6 @@ INSTALLS += target \
TRANSLATIONS += \
translations/zh_CN.ts \
translations/tr.ts \
- translations/bo.ts
+ translations/bo.ts \
+ translations/bo_CN.ts \
+ translations/en_US.ts
diff --git a/plugins/wlanconnect/wlanitem.cpp b/plugins/wlanconnect/wlanitem.cpp
index 5e076437..f4576426 100644
--- a/plugins/wlanconnect/wlanitem.cpp
+++ b/plugins/wlanconnect/wlanitem.cpp
@@ -1,6 +1,26 @@
+/* -*- 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 "wlanitem.h"
#include
#include
+#include
#define FRAME_SPEED 150
#define LIMIT_TIME 60*1000
#define TOTAL_PAGE 8
@@ -15,15 +35,18 @@ WlanItem::WlanItem(bool bAcitve, bool isLock, QWidget *parent)
this->setMinimumSize(550, 58);
this->setProperty("useButtonPalette", true);
this->setFlat(true);
+
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 InfoButton(this);
+ infoLabel = new GrayInfoButton(this);
mLanLyt->addWidget(iconLabel);
mLanLyt->addWidget(titileLabel,Qt::AlignLeft);
mLanLyt->addStretch();
@@ -40,7 +63,6 @@ WlanItem::WlanItem(bool bAcitve, bool isLock, QWidget *parent)
waitTimer = new QTimer(this);
connect(waitTimer, &QTimer::timeout, this, &WlanItem::updateIcon);
-
}
WlanItem::~WlanItem()
@@ -70,12 +92,17 @@ void WlanItem::stopLoading(){
void WlanItem::paintEvent(QPaintEvent *event)
{
- QPalette pal = this->palette();
+ QPalette pal = qApp->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
- painter.setBrush(pal.color(QPalette::Base));
+ painter.setBrush(this->palette().base().color());
+
+ QColor color = pal.color(QPalette::Button);
+ color.setAlphaF(0.5);
+ pal.setColor(QPalette::Button, color);
+ this->setPalette(pal);
QRect rect = this->rect();
diff --git a/plugins/wlanconnect/wlanitem.h b/plugins/wlanconnect/wlanitem.h
index 9d24757d..035daccf 100644
--- a/plugins/wlanconnect/wlanitem.h
+++ b/plugins/wlanconnect/wlanitem.h
@@ -1,3 +1,22 @@
+/* -*- 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 WLANITEM_H
#define WLANITEM_H
#include
@@ -10,7 +29,8 @@
#include
#include
#include "fixlabel.h"
-#include "infobutton.h"
+//#include "infobutton.h"
+#include "../component/AddBtn/grayinfobutton.h"
class WlanItem : public QPushButton
{
@@ -19,7 +39,7 @@ public:
~WlanItem();
public:
QLabel * iconLabel = nullptr;
- InfoButton * infoLabel = nullptr;
+ GrayInfoButton * infoLabel = nullptr;
FixLabel * titileLabel = nullptr;
QLabel * statusLabel = nullptr;
QString uuid = "";
diff --git a/src-vpn/backend/backend.pri b/src-vpn/backend/backend.pri
new file mode 100644
index 00000000..3419c1f0
--- /dev/null
+++ b/src-vpn/backend/backend.pri
@@ -0,0 +1,10 @@
+INCLUDEPATH += $$PWD
+include(../../src/backend/dbus-interface/dbus-interface.pri)
+
+HEADERS += \
+ $$PWD/vpndbusadaptor.h
+
+SOURCES += \
+ $$PWD/vpndbusadaptor.cpp
+
+DISTFILES +=
diff --git a/src-vpn/backend/vpndbusadaptor.cpp b/src-vpn/backend/vpndbusadaptor.cpp
new file mode 100644
index 00000000..e94ab43b
--- /dev/null
+++ b/src-vpn/backend/vpndbusadaptor.cpp
@@ -0,0 +1,78 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp com.kylin.weather.xml -a VpnDbusAdaptor -c VpnDbusAdaptor -l MainWindow
+ *
+ * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
+ *
+ * This is an auto-generated file.
+ * Do not edit! All changes made to it will be lost.
+ */
+
+#include "vpndbusadaptor.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/*
+ * Implementation of adaptor class VpnDbusAdaptor
+ */
+
+VpnDbusAdaptor::VpnDbusAdaptor(vpnObject *parent)
+ : QDBusAbstractAdaptor(parent)
+{
+ qDBusRegisterMetaType >();
+ qDBusRegisterMetaType >();
+ qDBusRegisterMetaType >();
+ setAutoRelaySignals(true);
+}
+
+//虚拟连接列表
+QVector VpnDbusAdaptor::getVirtualList()
+{
+ QVector vector;
+ parent()->getVirtualList(vector);
+ return vector;
+}
+
+//删除
+void VpnDbusAdaptor::deleteVpn(QString uuid)
+{
+ qDebug() << "delete vpn" << uuid;
+ parent()->deleteVpn(uuid);
+}
+
+//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
+void VpnDbusAdaptor::activateVpn(const QString& connUuid)
+{
+ qDebug() << "activate vpn" << connUuid;
+ parent()->activateVpn(connUuid);
+}
+
+//断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
+void VpnDbusAdaptor::deactivateVpn(const QString& connUuid)
+{
+ qDebug() << "deactivate vpn" << connUuid;
+ parent()->deactivateVpn(connUuid);
+}
+
+void VpnDbusAdaptor::showKylinVpn()
+{
+ parent()->onShowMainWindow();
+}
+
+void VpnDbusAdaptor::showVpnAddWidget()
+{
+ qDebug() << "showVpnAddWidget";
+ parent()->showVpnAddWidget();
+}
+
+void VpnDbusAdaptor::showDetailPage(const QString& connUuid)
+{
+ qDebug() << "showDetailPage vpn" << connUuid;
+ parent()->showDetailPage(connUuid);
+}
+
diff --git a/src-vpn/backend/vpndbusadaptor.h b/src-vpn/backend/vpndbusadaptor.h
new file mode 100644
index 00000000..919f092e
--- /dev/null
+++ b/src-vpn/backend/vpndbusadaptor.h
@@ -0,0 +1,64 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp com.kylin.weather.xml -a dbusadaptor -c DbusAdaptor -l MainWindow
+ *
+ * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
+ *
+ * This is an auto-generated file.
+ * This file may have been hand-edited. Look for HAND-EDIT comments
+ * before re-generating it.
+ */
+
+#ifndef VPNDBUSADAPTOR_H
+#define VPNDBUSADAPTOR_H
+
+#include
+#include
+#include
+
+#include "singlepage.h"
+#include "kylinnetworkdeviceresource.h"
+#include "kyvpnconnectoperation.h"
+
+QT_BEGIN_NAMESPACE
+class QByteArray;
+template class QMap;
+class QString;
+class QStringList;
+class QVariant;
+template class QVector;
+QT_END_NAMESPACE
+
+#include "vpnobject.h"
+
+class VpnDbusAdaptor: public QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "com.kylin.kylinvpn")
+public:
+ VpnDbusAdaptor(vpnObject *parent);
+
+ inline vpnObject *parent() const
+ { return static_cast(QObject::parent()); }
+
+public Q_SLOTS:
+ QVector getVirtualList();
+ Q_NOREPLY void deleteVpn(QString uuid);
+ Q_NOREPLY void activateVpn(const QString& connUuid);
+ Q_NOREPLY void deactivateVpn(const QString& connUuid);
+ Q_NOREPLY void showVpnAddWidget();
+ Q_NOREPLY void showDetailPage(const QString& connUuid);
+
+ void showKylinVpn();
+
+Q_SIGNALS:
+ void vpnAdd(QStringList info);
+ void vpnRemove(QString dbusPath);
+ void vpnUpdate(QStringList info);
+ void vpnActiveConnectionStateChanged(QString uuid, int status);
+
+ void activateFailed(QString errorMessage);
+ void deactivateFailed(QString errorMessage);
+};
+
+#endif
diff --git a/src-vpn/frontend/frontend.pri b/src-vpn/frontend/frontend.pri
new file mode 100644
index 00000000..0d131ba1
--- /dev/null
+++ b/src-vpn/frontend/frontend.pri
@@ -0,0 +1,11 @@
+INCLUDEPATH += $$PWD
+include(../../src/frontend/tools/tools.pri)
+include(list-items/list-items.pri)
+include(vpndetails/vpndetails.pri)
+include(single-pages/single-pages.pri)
+
+HEADERS += \
+ $$PWD/vpnobject.h
+
+SOURCES += \
+ $$PWD/vpnobject.cpp
diff --git a/src-vpn/frontend/list-items/list-items.pri b/src-vpn/frontend/list-items/list-items.pri
new file mode 100644
index 00000000..fefdcbe8
--- /dev/null
+++ b/src-vpn/frontend/list-items/list-items.pri
@@ -0,0 +1,10 @@
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/listitem.h \
+ $$PWD/vpnlistitem.h
+
+SOURCES += \
+ $$PWD/listitem.cpp \
+ $$PWD/vpnlistitem.cpp
+
diff --git a/src-vpn/frontend/list-items/listitem.cpp b/src-vpn/frontend/list-items/listitem.cpp
new file mode 100644
index 00000000..6ed14804
--- /dev/null
+++ b/src-vpn/frontend/list-items/listitem.cpp
@@ -0,0 +1,151 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "listitem.h"
+#include
+
+#define MAIN_LAYOUT_MARGINS 0,0,0,0
+#define MAIN_LAYOUT_SPACING 0
+#define ITEM_FRAME_MARGINS 12,6,16,6
+
+#define ITEM_FRAME_SPACING 8
+#define FRAME_WIDTH 404
+#define INFO_ICON_WIDTH 16
+#define INFO_ICON_HEIGHT 16
+#define LIGHT_HOVER_COLOR QColor(240,240,240,255)
+#define DARK_HOVER_COLOR QColor(15,15,15,255)
+
+ListItem::ListItem(QWidget *parent) : QFrame(parent)
+{
+ m_connectState = UnknownState;
+
+ initUI();
+ initConnection();
+ connect(qApp, &QApplication::paletteChanged, this, &ListItem::onPaletteChanged);
+// m_itemFrame->installEventFilter(this);
+}
+
+ListItem::~ListItem()
+{
+ if (nullptr != m_netButton) {
+ delete m_netButton;
+ m_netButton = nullptr;
+ }
+
+ if (nullptr != m_infoButton) {
+ delete m_infoButton;
+ m_infoButton = nullptr;
+ }
+
+}
+
+void ListItem::setName(const QString &name)
+{
+ m_nameLabel->setText(name);
+}
+
+//仅无线调用,有线自己获取
+void ListItem::setActive(const bool &isActive)
+{
+ m_netButton->setActive(isActive);
+ m_isActive = isActive;
+}
+
+void ListItem::setConnectState(ConnectState state)
+{
+ m_connectState = state;
+}
+
+void ListItem::mousePressEvent(QMouseEvent *event)
+{
+ qDebug()<<"[ListItem]"<<"mousePressEvent";
+ if (event->button() == Qt::LeftButton) {
+ onNetButtonClicked();
+ } else if (event->button() == Qt::RightButton) {
+ onRightButtonClicked();
+ }
+ return QFrame::mousePressEvent(event);
+}
+
+void ListItem::enterEvent(QEvent *event)
+{
+}
+
+void ListItem::leaveEvent(QEvent *event)
+{
+}
+
+void ListItem::paintEvent(QPaintEvent *event)
+{
+}
+
+void ListItem::initUI()
+{
+ m_menu = new QMenu(this);//右键菜单
+// m_menu->setStyleSheet("QMenu::item{border:3px; border-radius:3px}");
+// m_menu->setStyleSheet("QMenu{border-radius:6px; margin:6px 6px 6px 6px}");
+ connect(m_menu, &QMenu::triggered, this, &ListItem::onMenuTriggered);
+
+ m_mainLayout = new QVBoxLayout(this);
+ m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
+ m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
+ this->setLayout(m_mainLayout);
+
+ m_itemFrame = new QFrame(this);
+ m_itemFrame->setFixedWidth(FRAME_WIDTH);
+
+ m_hItemLayout = new QHBoxLayout(m_itemFrame);
+ m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS);
+ m_hItemLayout->setSpacing(ITEM_FRAME_SPACING);
+ m_hItemLayout->setAlignment(Qt::AlignHCenter);
+
+ m_netButton = new RadioItemButton(m_itemFrame);
+ m_nameLabel = new QLabel(m_itemFrame);
+ m_nameLabel->setMinimumWidth(262);
+ m_infoButton = new InfoButton(m_itemFrame);
+ m_infoButton->setIconSize(QSize(INFO_ICON_WIDTH,INFO_ICON_HEIGHT));
+
+ m_hItemLayout->addWidget(m_netButton);
+ m_hItemLayout->addWidget(m_nameLabel);
+ m_hItemLayout->addStretch();
+ m_hItemLayout->addWidget(m_infoButton);
+
+ m_mainLayout->addWidget(m_itemFrame);
+
+// this->setAutoFillBackground(true);
+// this->setBackgroundRole(QPalette::Base);
+// QPalette pal = qApp->palette();
+// pal.setColor(QPalette::Window, qApp->palette().base().color());
+// this->setPalette(pal);
+}
+
+
+void ListItem::initConnection()
+{
+ connect(this->m_netButton, &RadioItemButton::clicked, this, &ListItem::onNetButtonClicked);
+ // connect(this->m_infoButton, &InfoButton::clicked, this, &ListItem::onInfoButtonClicked);
+}
+
+void ListItem::onPaletteChanged()
+{
+// QPalette pal = qApp->palette();
+// pal.setColor(QPalette::Window, qApp->palette().base().color());
+// this->setPalette(pal);
+}
+
diff --git a/src-vpn/frontend/list-items/listitem.h b/src-vpn/frontend/list-items/listitem.h
new file mode 100644
index 00000000..8b6c843a
--- /dev/null
+++ b/src-vpn/frontend/list-items/listitem.h
@@ -0,0 +1,87 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef LISTITEM_H
+#define LISTITEM_H
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "radioitembutton.h"
+#include "infobutton.h"
+
+
+typedef enum{
+ UnknownState = 0, /**< The active connection is in an unknown state */
+ Activating, /**< The connection is activating */
+ Activated, /**< The connection is activated */
+ Deactivating, /**< The connection is being torn down and cleaned up */
+ Deactivated /**< The connection is no longer active */
+}ConnectState;
+
+class ListItem : public QFrame
+{
+ Q_OBJECT
+public:
+ ListItem(QWidget *parent = nullptr);
+ ~ListItem();
+ void setName(const QString &name);
+ void setActive(const bool &isActive);
+ void setConnectState(ConnectState state);
+ static void showDesktopNotify(const QString &message, QString soundName);
+
+protected:
+ void mousePressEvent(QMouseEvent *event);
+ void enterEvent(QEvent *event);
+ void leaveEvent(QEvent *event);
+ void paintEvent(QPaintEvent *event);
+ virtual void onRightButtonClicked() = 0;
+
+protected:
+ QFrame * m_itemFrame = nullptr;
+
+ QLabel * m_nameLabel = nullptr;
+ RadioItemButton * m_netButton = nullptr;
+ InfoButton * m_infoButton = nullptr;
+
+ bool m_isActive = false;
+ ConnectState m_connectState;
+
+ QMenu *m_menu = nullptr;
+public:
+ QVBoxLayout * m_mainLayout = nullptr;
+ QHBoxLayout * m_hItemLayout = nullptr;
+
+private:
+ void initUI();
+ void initConnection();
+
+public Q_SLOTS:
+ virtual void onNetButtonClicked() = 0;
+ void onPaletteChanged();
+ virtual void onMenuTriggered(QAction *action)=0;
+
+Q_SIGNALS:
+ void detailShow(bool isShow);
+};
+
+#endif // LISTITEM_H
diff --git a/src-vpn/frontend/list-items/vpnlistitem.cpp b/src-vpn/frontend/list-items/vpnlistitem.cpp
new file mode 100644
index 00000000..64679857
--- /dev/null
+++ b/src-vpn/frontend/list-items/vpnlistitem.cpp
@@ -0,0 +1,249 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "vpnlistitem.h"
+#include "kylinconnectitem.h"
+
+#include
+
+#define LOG_FLAG "[VpnListItem]"
+
+VpnListItem::VpnListItem(const KyConnectItem *vpnConnectItem, QWidget *parent):ListItem(parent)
+{
+ m_connectOperation = new KyVpnConnectOperation(this);
+ m_deviceResource = new KyNetworkDeviceResourse(this);
+
+ connectItemCopy(vpnConnectItem);
+
+ m_nameLabel->setText(m_vpnConnectItem.m_connectName);
+ m_netButton->setButtonIcon(QIcon::fromTheme("ukui-vpn-symbolic"));
+
+ qDebug() << "VpnListItem init:" << m_vpnConnectItem.m_connectName << m_vpnConnectItem.m_connectState << m_vpnConnectItem.m_ifaceName;
+
+ if (Deactivated == m_vpnConnectItem.m_connectState || Activated == m_vpnConnectItem.m_connectState) {
+ m_netButton->stopLoading();
+ if (m_vpnConnectItem.m_connectState == Activated) {
+ setIcon(true);
+ } else {
+ setIcon(false);
+ }
+ } else {
+ m_netButton->startLoading();
+ }
+
+ m_itemFrame->installEventFilter(this);
+ connect(this->m_infoButton, &InfoButton::clicked, this, &VpnListItem::onInfoButtonClicked);
+ connect(m_menu, &QMenu::triggered, this, &VpnListItem::onMenuTriggered);
+}
+
+
+VpnListItem::VpnListItem(QWidget *parent) : ListItem(parent)
+{
+ m_isActive = false;
+ m_netButton->setButtonIcon(QIcon::fromTheme("ukui-vpn-symbolic"));
+ setIcon(false);
+ const QString str=tr("Not connected");
+ m_nameLabel->setText(str);
+ this->m_infoButton->hide();
+}
+
+VpnListItem::~VpnListItem()
+{
+ qDebug()<<"[LanPage] lan list item is deleted." << m_vpnConnectItem.m_connectName;
+}
+
+void VpnListItem::setIcon(bool isOn)
+{
+ if (isOn) {
+ m_netButton->setActive(true); //设置图标显示不同颜色
+ } else {
+ m_netButton->setActive(false);
+ }
+}
+
+void VpnListItem::connectItemCopy(const KyConnectItem *vpnConnectItem)
+{
+ if (vpnConnectItem) {
+ m_vpnConnectItem.m_connectName = vpnConnectItem->m_connectName;
+ m_vpnConnectItem.m_connectPath = vpnConnectItem->m_connectPath;
+ m_vpnConnectItem.m_connectState = vpnConnectItem->m_connectState;
+ m_vpnConnectItem.m_connectUuid = vpnConnectItem->m_connectUuid;
+ m_vpnConnectItem.m_ifaceName = vpnConnectItem->m_ifaceName;
+ m_vpnConnectItem.m_itemType = vpnConnectItem->m_itemType;
+ } else {
+ qDebug() << LOG_FLAG <<"the connect item is nullptr";
+ m_vpnConnectItem.m_connectName = "";
+ m_vpnConnectItem.m_connectPath = "";
+ m_vpnConnectItem.m_connectState = NetworkManager::ActiveConnection::State::Unknown;
+ m_vpnConnectItem.m_connectUuid = "";
+ m_vpnConnectItem.m_ifaceName = "";
+ m_vpnConnectItem.m_itemType = NetworkManager::ConnectionSettings::ConnectionType::Unknown;
+ }
+}
+
+void VpnListItem::activeConnection()
+{
+ if (m_vpnConnectItem.m_connectUuid.isEmpty()) {
+ qDebug() << LOG_FLAG << "connect is empty, so can not connect or disconnect.";
+ return;
+ }
+
+ if (Deactivated == m_vpnConnectItem.m_connectState) {
+ //断开的连接,点击激活连接
+ m_connectOperation->activateVpnConnection(m_vpnConnectItem.m_connectUuid);
+ qDebug() << LOG_FLAG << "it will activate connection" << m_vpnConnectItem.m_connectName;
+ m_netButton->startLoading();
+ } else {
+ qDebug() << LOG_FLAG <<"the connection" << m_vpnConnectItem.m_connectName
+ << "is not deactived, so it can not be operation.";
+ }
+}
+
+void VpnListItem::onNetButtonClicked()
+{
+ if (m_vpnConnectItem.m_connectUuid.isEmpty()) {
+ qDebug() << LOG_FLAG << "connect is empty, so can not connect or disconnect.";
+ return;
+ }
+
+ if (Deactivated == m_vpnConnectItem.m_connectState) {
+ //断开的连接,点击激活连接
+ m_connectOperation->activateVpnConnection(m_vpnConnectItem.m_connectUuid);
+ qDebug() << LOG_FLAG << "it will activate connection" << m_vpnConnectItem.m_connectName;
+ m_netButton->startLoading();
+ } else {
+ qDebug() << LOG_FLAG <<"the connection" << m_vpnConnectItem.m_connectName
+ << "is not deactived, so it can not be operation.";
+ }
+}
+
+void VpnListItem::onRightButtonClicked()
+{
+ //右键点击事件
+ qDebug()<< LOG_FLAG <<"onRightButtonClicked";
+ if (!m_menu) {
+ return;
+ }
+
+ m_menu->clear();
+ if (Activated == m_vpnConnectItem.m_connectState || Activating == m_vpnConnectItem.m_connectState) {
+ m_menu->addAction(new QAction(tr("Disconnect"), this));
+ } else if (Deactivated == m_vpnConnectItem.m_connectState) {
+ m_menu->addAction(new QAction(tr("Connect"), this));
+ } else {
+ return;
+ }
+
+ m_menu->move(cursor().pos());
+ m_menu->show();
+}
+
+void VpnListItem::onMenuTriggered(QAction *action)
+{
+ if (action->text() == tr("Connect")) {
+ this->onNetButtonClicked();
+ } else if (action->text() == tr("Disconnect")) {
+ m_connectOperation->deactivateVpnConnection(m_vpnConnectItem.m_connectName, m_vpnConnectItem.m_connectUuid);
+ qDebug() << LOG_FLAG << "it will disconnect connection" << m_vpnConnectItem.m_connectName;
+ m_netButton->startLoading();
+ }
+}
+
+bool VpnListItem::launchApp(QString desktopFile)
+{
+ QDBusInterface appManagerDbusInterface(KYLIN_APP_MANAGER_NAME,
+ KYLIN_APP_MANAGER_PATH,
+ KYLIN_APP_MANAGER_INTERFACE,
+ QDBusConnection::sessionBus());
+
+ if (!appManagerDbusInterface.isValid()) {
+ qWarning()<<"appManagerDbusInterface init error";
+ return false;
+ } else {
+ QDBusReply reply = appManagerDbusInterface.call("LaunchApp", desktopFile);
+ return reply;
+ }
+}
+
+void VpnListItem::runExternalApp() {
+ if (!launchApp("nm-connection-editor.desktop")){
+ QString cmd = "nm-connection-editor";
+ QProcess process(this);
+ process.startDetached(cmd);
+ }
+}
+
+void VpnListItem::onInfoButtonClicked()
+{
+ if (m_vpnConnectItem.m_itemType != NetworkManager::ConnectionSettings::ConnectionType::Vpn) {
+ runExternalApp();
+ return;
+ }
+
+ if(m_vpnDetail != nullptr){
+ m_vpnDetail->activateWindow();
+ return;
+ }
+ m_vpnDetail = new VpnDetail(m_vpnConnectItem.m_connectUuid, getConnectionName());
+ connect(m_vpnDetail, &VpnDetail::destroyed, [&](){
+ if (m_vpnDetail != nullptr) {
+ m_vpnDetail = nullptr;
+ }
+ });
+
+ m_vpnDetail->show();
+ m_vpnDetail->centerToScreen();
+}
+
+void VpnListItem::updateConnectionState(ConnectState state)
+{
+ m_vpnConnectItem.m_connectState = (NetworkManager::ActiveConnection::State)state;
+
+ if (Deactivated == state || Activated == state) {
+ m_netButton->stopLoading();
+ if (state == Activated) {
+ setIcon(true);
+ } else {
+ setIcon(false);
+ }
+ } else {
+ m_netButton->startLoading();
+ }
+}
+
+QString VpnListItem::getConnectionName()
+{
+ return m_vpnConnectItem.m_connectName;
+}
+
+void VpnListItem::updateConnectionName(QString connectionName)
+{
+ m_vpnConnectItem.m_connectName = connectionName;
+ m_nameLabel->setText(m_vpnConnectItem.m_connectName);
+}
+
+QString VpnListItem::getConnectionPath()
+{
+ return m_vpnConnectItem.m_connectPath;
+}
+
+void VpnListItem::updateConnectionPath(QString connectionPath)
+{
+ m_vpnConnectItem.m_connectPath = connectionPath;
+}
diff --git a/src-vpn/frontend/list-items/vpnlistitem.h b/src-vpn/frontend/list-items/vpnlistitem.h
new file mode 100644
index 00000000..b2be2edc
--- /dev/null
+++ b/src-vpn/frontend/list-items/vpnlistitem.h
@@ -0,0 +1,88 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef VPNLISTITEM_H
+#define VPNLISTITEM_H
+#include "listitem.h"
+#include "kylinactiveconnectresource.h"
+
+#include
+#include
+#include
+#include
+
+#include "vpndetails/vpndetail.h"
+#include "kylinconnectresource.h"
+//#include "kylinwiredconnectoperation.h"
+#include "kyvpnconnectoperation.h"
+
+
+#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager"
+#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager"
+#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager"
+
+class VpnListItem : public ListItem
+{
+ Q_OBJECT
+
+public:
+ VpnListItem(const KyConnectItem *vpnConnectItem, QWidget *parent = nullptr);
+ VpnListItem(QWidget *parent = nullptr);
+
+ ~VpnListItem();
+
+public:
+ void updateConnectionState(ConnectState state);
+
+ QString getConnectionName();
+ void updateConnectionName(QString connectionName);
+
+ QString getConnectionPath();
+ void updateConnectionPath(QString connectionPath);
+
+ void activeConnection();
+
+protected:
+ void setIcon(bool isOn);
+ void onRightButtonClicked();
+ bool launchApp(QString desktopFile);
+ void runExternalApp();
+
+private:
+ void connectItemCopy(const KyConnectItem *vpnConnectItem);
+
+public Q_SLOTS:
+ void onInfoButtonClicked();
+
+private Q_SLOTS:
+ void onNetButtonClicked();
+ void onMenuTriggered(QAction *action);
+
+private:
+ KyConnectItem m_vpnConnectItem;
+
+ KyVpnConnectOperation *m_connectOperation = nullptr;
+ KyNetworkDeviceResourse *m_deviceResource = nullptr;
+
+ QString m_deviceName = "";
+
+ VpnDetail *m_vpnDetail = nullptr;
+};
+
+#endif // VPNLISTITEM_H
diff --git a/src-vpn/frontend/single-pages/single-pages.pri b/src-vpn/frontend/single-pages/single-pages.pri
new file mode 100644
index 00000000..96c70dc5
--- /dev/null
+++ b/src-vpn/frontend/single-pages/single-pages.pri
@@ -0,0 +1,10 @@
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/vpnpage.h \
+ $$PWD/singlepage.h
+
+SOURCES += \
+ $$PWD/vpnpage.cpp \
+ $$PWD/singlepage.cpp
+
diff --git a/src-vpn/frontend/single-pages/singlepage.cpp b/src-vpn/frontend/single-pages/singlepage.cpp
new file mode 100644
index 00000000..695e75e2
--- /dev/null
+++ b/src-vpn/frontend/single-pages/singlepage.cpp
@@ -0,0 +1,185 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "singlepage.h"
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+SinglePage::SinglePage(QWidget *parent) : QWidget(parent)
+{
+ initUI();
+ initWindowProperties();
+ initTransparency();
+}
+
+SinglePage::~SinglePage()
+{
+}
+
+void SinglePage::initUI()
+{
+ m_mainLayout = new QVBoxLayout(this);
+ m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
+ m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
+ this->setLayout(m_mainLayout);
+
+ m_titleFrame = new QFrame(this);
+ m_titleFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
+ m_titleLayout = new QHBoxLayout(m_titleFrame);
+ m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
+ m_titleFrame->setLayout(m_titleLayout);
+ m_titleLabel = new QLabel(m_titleFrame);
+ m_titleLayout->addWidget(m_titleLabel);
+ m_titleLayout->addStretch();
+
+ m_netDivider = new Divider(this);
+
+ m_listFrame = new QFrame(this);
+ m_listLayout = new QVBoxLayout(m_listFrame);
+ m_listLayout->setContentsMargins(NET_LAYOUT_MARGINS);
+ m_listFrame->setLayout(m_listLayout);
+ m_listWidget = new QListWidget(m_listFrame);
+ m_listLayout->addWidget(m_listWidget);
+
+ m_setDivider = new Divider(this);
+
+ m_settingsFrame = new QFrame(this);
+ m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
+ m_settingsLayout = new QHBoxLayout(m_settingsFrame);
+ m_settingsLayout->setContentsMargins(SETTINGS_LAYOUT_MARGINS);
+ m_settingsLabel = new KyLable(m_settingsFrame);
+ m_settingsLabel->setCursor(Qt::PointingHandCursor);
+ m_settingsLabel->setText(tr("Settings"));
+ m_settingsLabel->setScaledContents(true);
+ m_settingsLayout->addWidget(m_settingsLabel);
+ m_settingsLayout->addStretch();
+ m_settingsFrame->setLayout(m_settingsLayout);
+
+ m_mainLayout->addWidget(m_titleFrame);
+ m_mainLayout->addWidget(m_netDivider);
+ m_mainLayout->addWidget(m_listFrame);
+ m_mainLayout->addWidget(m_setDivider);
+ m_mainLayout->addWidget(m_settingsFrame);
+}
+
+void SinglePage::initWindowProperties()
+{
+ QPalette pal = m_listFrame->palette();
+ pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明
+ m_listFrame->setPalette(pal);
+
+ this->setFixedWidth(MAX_WIDTH);
+ this->setAttribute(Qt::WA_TranslucentBackground);
+ this->setProperty("useStyleWindowManager", false); //禁用拖动
+ //绘制毛玻璃特效
+ QString platform = QGuiApplication::platformName();
+ if(!platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive))
+ {
+ QPainterPath path;
+ auto rect = this->rect();
+ path.addRoundedRect(rect, 12, 12);
+ path.addRect(rect);
+ KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); //背景模糊
+ }
+}
+
+void SinglePage::showDesktopNotify(const QString &message, QString soundName)
+{
+ QDBusInterface iface("org.freedesktop.Notifications",
+ "/org/freedesktop/Notifications",
+ "org.freedesktop.Notifications",
+ QDBusConnection::sessionBus());
+ QStringList actions; //跳转动作
+ actions.append("kylin-vpn");
+ actions.append("default"); //默认动作:点击消息体时打开麒麟录音
+ QMap hints;
+ if (!soundName.isEmpty()) {
+ hints.insert("sound-name",soundName); //添加声音
+ }
+ QList args;
+ args<<(tr("Kylin VPN"))
+ <<((unsigned int) 0)
+ <palette().window().color();
+
+ QPainterPath rectPath;
+
+ col.setAlphaF(m_transparency);
+ rectPath.addRoundedRect(this->rect(),12,12);
+
+ painter.setBrush(col);
+ painter.drawPath(rectPath);
+ KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(rectPath.toFillPolygon().toPolygon())); //背景模糊
+}
+
+void SinglePage::initTransparency()
+{
+ if(QGSettings::isSchemaInstalled(QByteArray(TRANSPARENCY_GSETTINGS))) {
+ m_transGsettings = new QGSettings(QByteArray(TRANSPARENCY_GSETTINGS));
+ if(m_transGsettings->keys().contains(TRANSPARENCY)) {
+ m_transparency = m_transGsettings->get(TRANSPARENCY).toDouble() + 0.15;
+ m_transparency = (m_transparency > 1) ? 1 : m_transparency;
+ connect(m_transGsettings, &QGSettings::changed, this, &SinglePage::onTransChanged);
+ }
+ }
+}
+
+void SinglePage::onTransChanged()
+{
+ m_transparency = m_transGsettings->get("transparency").toDouble() + 0.15;
+ m_transparency = (m_transparency > 1) ? 1 : m_transparency;
+ paintWithTrans();
+}
+
+void SinglePage::paintWithTrans()
+{
+ QPalette pal = this->palette();
+ QColor color = qApp->palette().base().color();
+ color.setAlphaF(m_transparency);
+ pal.setColor(QPalette::Window, color);
+ this->setPalette(pal);
+}
+
+void SinglePage::keyPressEvent(QKeyEvent *event)
+{
+ if (event->key() == Qt::Key_Escape) {
+ this->hide();
+ }
+ return QWidget::keyPressEvent(event);
+}
+
+
diff --git a/src-vpn/frontend/single-pages/singlepage.h b/src-vpn/frontend/single-pages/singlepage.h
new file mode 100644
index 00000000..2855b96b
--- /dev/null
+++ b/src-vpn/frontend/single-pages/singlepage.h
@@ -0,0 +1,112 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef SINGLEPAGE_H
+#define SINGLEPAGE_H
+
+#include "divider.h"
+#include "kylable.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "kylinnetworkdeviceresource.h"
+#include "kwidget.h"
+#include "kswitchbutton.h"
+
+using namespace kdk;
+
+#define MAIN_LAYOUT_MARGINS 0,0,0,0
+#define MAIN_LAYOUT_SPACING 0
+#define TITLE_FRAME_HEIGHT 60 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度
+#define TITLE_LAYOUT_MARGINS 24,0,24,0
+#define NET_LAYOUT_MARGINS 8,8,0,8
+#define TEXT_HEIGHT 20
+#define SETTINGS_LAYOUT_MARGINS 23,0,24,0
+
+#define MAX_ITEMS 4
+#define MAX_WIDTH 412
+#define MIN_WIDTH 404
+
+#define SCROLL_STEP 4
+
+#define TRANSPARENCY "transparency"
+#define TRANSPARENCY_GSETTINGS "org.ukui.control-center.personalise"
+
+class SinglePage : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit SinglePage(QWidget *parent = nullptr);
+ ~SinglePage();
+
+ static void showDesktopNotify(const QString &message, QString soundName);
+
+Q_SIGNALS:
+ void activateFailed(QString errorMessage);
+ void deactivateFailed(QString errorMessage);
+
+private Q_SLOTS:
+ void onTransChanged();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void keyPressEvent(QKeyEvent *event);
+
+protected:
+ void initUI();
+ void initTransparency();
+ void paintWithTrans();
+
+
+private:
+ void initWindowProperties();
+
+protected:
+ QVBoxLayout * m_mainLayout = nullptr;
+
+ QLabel * m_titleLabel = nullptr;
+ QFrame * m_titleFrame = nullptr;
+ QHBoxLayout * m_titleLayout = nullptr;
+
+ QFrame * m_listFrame = nullptr;
+ QListWidget * m_listWidget = nullptr;
+ QVBoxLayout * m_listLayout = nullptr;
+
+ QFrame * m_settingsFrame = nullptr;
+ QHBoxLayout * m_settingsLayout = nullptr;
+ KyLable * m_settingsLabel = nullptr;
+
+ Divider * m_netDivider = nullptr;
+ Divider * m_setDivider = nullptr;
+
+
+ QGSettings * m_transGsettings = nullptr;
+ double m_transparency = 1.0; //透明度
+
+};
+
+#endif // TABPAGE_H
diff --git a/src-vpn/frontend/single-pages/vpnpage.cpp b/src-vpn/frontend/single-pages/vpnpage.cpp
new file mode 100644
index 00000000..e2cb274b
--- /dev/null
+++ b/src-vpn/frontend/single-pages/vpnpage.cpp
@@ -0,0 +1,690 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "vpnpage.h"
+#include
+#include
+#include "windowmanager/windowmanager.h"
+
+
+VpnPage::VpnPage(QWidget *parent) : SinglePage(parent)
+{
+ m_activeResourse = new KyActiveConnectResourse(this);
+ m_connectResourse = new KyConnectResourse(this);
+ m_vpnConnectOperation = new KyVpnConnectOperation(this);
+
+ initUI();
+ initVpnArea();
+ installEventFilter(this);
+
+ connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &VpnPage::onConnectionStateChange);
+ connect(m_activeResourse, &KyActiveConnectResourse::activeConnectRemove, this, [=] (QString activeConnectUuid) {
+ sendVpnStateChangeSignal(activeConnectUuid,Deactivated);
+ } );
+
+ connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &VpnPage::onAddConnection);
+ connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &VpnPage::onRemoveConnection);
+ connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &VpnPage::onUpdateConnection);
+
+ connect(m_vpnConnectOperation, &KyVpnConnectOperation::activateConnectionError, this, &VpnPage::activateFailed);
+ connect(m_vpnConnectOperation, &KyVpnConnectOperation::deactivateConnectionError, this, &VpnPage::deactivateFailed);
+
+ connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, [&](WId activeWindowId){
+ if (activeWindowId != this->winId() && activeWindowId != 0) {
+ hide();
+ }
+ });
+}
+
+VpnPage::~VpnPage()
+{
+
+}
+
+void VpnPage::deleteConnectionMapItem(QMap &connectMap,
+ QListWidget *vpnListWidget, QString uuid)
+{
+ QListWidgetItem *p_listWidgetItem = connectMap.value(uuid);
+ if (p_listWidgetItem) {
+ connectMap.remove(uuid);
+ VpnListItem *p_vpnItem = (VpnListItem *)vpnListWidget->itemWidget(p_listWidgetItem);
+ vpnListWidget->removeItemWidget(p_listWidgetItem);
+
+ delete p_vpnItem;
+ p_vpnItem = nullptr;
+
+ delete p_listWidgetItem;
+ p_listWidgetItem = nullptr;
+ }
+
+ return;
+}
+
+void VpnPage::clearConnectionMap(QMap &connectMap,
+ QListWidget *vpnListWidget)
+{
+ QMap::iterator iter;
+
+ iter = connectMap.begin();
+ while (iter != connectMap.end()) {
+ qDebug()<<"[VpnPage] clear connection map item"<< iter.key();
+
+ QListWidgetItem *p_widgetItem = iter.value();
+ VpnListItem *p_vpnItem = (VpnListItem *)vpnListWidget->itemWidget(p_widgetItem);
+ vpnListWidget->removeItemWidget(p_widgetItem);
+
+ delete p_vpnItem;
+ p_vpnItem = nullptr;
+
+ delete p_widgetItem;
+ p_widgetItem = nullptr;
+
+ iter = connectMap.erase(iter);
+ }
+
+ return;
+}
+
+void VpnPage::constructItemArea()
+{
+ QList activedList;
+ QList netList;
+
+ activedList.clear();
+ netList.clear();
+ clearConnectionMap(m_activeItemMap, m_listWidget);
+ clearConnectionMap(m_vpnItemMap, m_listWidget);
+
+ m_connectResourse->getVpnAndVirtualConnections(netList);
+ KyConnectItem *p_newItem = nullptr;
+ if (!netList.isEmpty()) {
+ for (int index = 0; index < netList.size(); index++) {
+ KyConnectItem *p_netConnectionItem = netList.at(index);
+ p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid);
+ if (p_newItem == nullptr) {
+ if (m_vpnItemMap.contains(p_netConnectionItem->m_connectUuid)) {
+ qDebug()<m_connectUuid;
+ }
+ QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_listWidget);
+ m_vpnItemMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem);
+ } else {
+ if (m_activeItemMap.contains(p_netConnectionItem->m_connectUuid)) {
+ qDebug()<m_connectUuid;
+ }
+ QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_listWidget);
+ m_activeItemMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem);
+ }
+
+ delete p_netConnectionItem;
+ p_netConnectionItem = nullptr;
+ }
+ }
+
+ if (QGSettings::isSchemaInstalled(GSETTINGS_VPNICON_VISIBLE)) {
+ QGSettings vpnGsettings(GSETTINGS_VPNICON_VISIBLE);
+ if (vpnGsettings.keys().contains(QString(VISIBLE))) {
+ if (!netList.isEmpty()) {
+ vpnGsettings.set(VISIBLE, true);
+ } else {
+ vpnGsettings.set(VISIBLE, false);
+ }
+ }
+ }
+
+ resetListWidgetWidth();
+}
+
+void VpnPage::initVpnArea()
+{
+ constructItemArea();
+}
+
+void VpnPage::resetPageHeight()
+{
+ int height = 0;
+ int count = m_listWidget->count();
+ m_listFrame->setFixedHeight((count >= 4) ? (MAX_ITEMS * ITEM_HEIGHT + ITEM_SPACE) : (count * ITEM_HEIGHT + ITEM_SPACE));
+
+ if (count == 0) {
+ m_listWidget->setHidden(true);
+ m_listFrame->setHidden(true);
+ m_netDivider->setHidden(true);
+ } else {
+ m_listWidget->show();
+ m_listFrame->show();
+ m_netDivider->show();
+ }
+}
+
+bool VpnPage::removeConnectionItem(QMap &connectMap,
+ QListWidget *vpnListWidget, QString path)
+{
+ QMap::iterator iter;
+ for (iter = connectMap.begin(); iter != connectMap.end(); ++iter) {
+ QListWidgetItem *p_listWidgetItem = iter.value();
+ VpnListItem *p_vpnItem = (VpnListItem*)vpnListWidget->itemWidget(p_listWidgetItem);
+ if (p_vpnItem->getConnectionPath() == path) {
+ qDebug()<<"[VpnPage] Remove a connection from list";
+
+ vpnListWidget->removeItemWidget(p_listWidgetItem);
+
+ delete p_vpnItem;
+ p_vpnItem = nullptr;
+
+ delete p_listWidgetItem;
+ p_listWidgetItem = nullptr;
+
+ iter = connectMap.erase(iter);
+ resetListWidgetWidth();
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void VpnPage::onRemoveConnection(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除
+{
+ //for dbus
+ qDebug() << "[VpnPage] emit lanRemove because onRemoveConnection " << path;
+ Q_EMIT vpnRemove(path);
+
+ removeConnectionItem(m_vpnItemMap, m_listWidget, path);
+ removeConnectionItem(m_activeItemMap, m_listWidget, path);
+ resetPageHeight();
+ resetWindowPosition();
+ this->update();
+}
+
+void VpnPage::onAddConnection(QString uuid) //新增一个有线连接,将其加入到激活列表
+{
+ if (!m_connectResourse->isVirtualConncection(uuid)) {
+ return;
+ }
+
+ KyConnectItem *p_newItem = nullptr;
+ p_newItem = m_connectResourse->getConnectionItemByUuid(uuid);
+ if (nullptr == p_newItem) {
+ return;
+ }
+
+ sendVpnAddSignal(p_newItem);
+
+ qDebug()<<"[VpnPage] Add a new connection, name:"<m_connectName;
+ QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget);
+ if (m_vpnItemMap.contains(p_newItem->m_connectUuid)) {
+ qDebug()<m_connectUuid;
+ }
+ m_vpnItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
+
+ delete p_newItem;
+ p_newItem = nullptr;
+ resetListWidgetWidth();
+ resetPageHeight();
+ resetWindowPosition();
+ this->update();
+ return;
+}
+
+void VpnPage::onShowControlCenter()
+{
+ QProcess process;
+ process.startDetached("ukui-control-center -m vpn");
+}
+
+void VpnPage::initUI()
+{
+ m_titleLabel->setText(tr("VPN"));
+
+// m_listFrame->setMaximumHeight(MAX_ITEMS * ITEM_HEIGHT + ITEM_SPACE);
+
+ m_listWidget->setFrameShape(QFrame::Shape::NoFrame);
+ m_listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ m_listWidget->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel);
+ m_listWidget->verticalScrollBar()->setProperty("drawScrollBarGroove",false); //去除滚动条的外侧黑框
+ m_listWidget->verticalScrollBar()->setSingleStep(SCROLL_STEP);
+ m_listWidget->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu);
+
+ m_settingsLabel->setText(tr("VPN Settings"));
+ m_settingsLabel->installEventFilter(this);
+}
+
+QListWidgetItem *VpnPage::insertNewItem(KyConnectItem *itemData, QListWidget *listWidget)
+{
+ int index = 0;
+
+ for(index = 0; index < m_listWidget->count(); index++) {
+ QListWidgetItem *p_listWidgetItem = m_listWidget->item(index);
+ VpnListItem *p_vpnItem = (VpnListItem *)m_listWidget->itemWidget(p_listWidgetItem);
+ QString name1 = p_vpnItem->getConnectionName();
+ QString name2 = itemData->m_connectName;
+ if (QString::compare(name1, name2, Qt::CaseInsensitive) > 0) {
+ break;
+ }
+ }
+
+ QListWidgetItem *p_sortListWidgetItem = new QListWidgetItem();
+ p_sortListWidgetItem->setFlags(p_sortListWidgetItem->flags() & (~Qt::ItemIsSelectable)); //设置不可被选中
+ p_sortListWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT));
+
+ listWidget->insertItem(index, p_sortListWidgetItem);
+
+ VpnListItem *p_sortLanItem = nullptr;
+ p_sortLanItem = new VpnListItem(itemData);
+ listWidget->setItemWidget(p_sortListWidgetItem, p_sortLanItem);
+
+ return p_sortListWidgetItem;
+}
+
+QListWidgetItem *VpnPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget)
+{
+ QListWidgetItem *p_listWidgetItem = new QListWidgetItem();
+ p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable));
+ p_listWidgetItem->setSizeHint(QSize(listWidget->width() - 16, ITEM_HEIGHT));
+ listWidget->addItem(p_listWidgetItem);
+ VpnListItem *p_vpnItem = nullptr;
+ if (itemData != nullptr) {
+ p_vpnItem = new VpnListItem(itemData);
+ qDebug() << "[VpnPage] addNewItem, connection: " << itemData->m_connectName;
+ } else {
+ p_vpnItem = new VpnListItem();
+ qDebug() << "[VpnPage] Add nullItem!";
+ }
+
+ listWidget->setItemWidget(p_listWidgetItem, p_vpnItem);
+ return p_listWidgetItem;
+}
+
+void VpnPage::updateActivatedConnectionArea(KyConnectItem *p_newItem)
+{
+ if (m_activeItemMap.contains(p_newItem->m_connectUuid)) {
+ return;
+ }
+
+ deleteConnectionMapItem(m_vpnItemMap, m_listWidget, p_newItem->m_connectUuid);
+ qDebug()<<"[VpnPage]update active connection item"<m_connectName;
+ deleteConnectionMapItem(m_activeItemMap, m_listWidget, p_newItem->m_connectUuid);
+ QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_listWidget);
+ m_activeItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
+
+ resetListWidgetWidth();
+
+ return;
+}
+
+void VpnPage::updateConnectionArea(KyConnectItem *p_newItem)
+{
+ if (m_vpnItemMap.contains(p_newItem->m_connectUuid)) {
+ return;
+ }
+
+ deleteConnectionMapItem(m_activeItemMap, m_listWidget, p_newItem->m_connectUuid);
+ qDebug()<<"[VpnPage] update connection item"<m_connectName;
+ QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget);
+ m_vpnItemMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
+
+ resetListWidgetWidth();
+}
+
+void VpnPage::updateConnectionState(QMap &connectMap,
+ QListWidget *vpnListWidget, QString uuid, ConnectState state)
+{
+ qDebug() << LOG_FLAG << "update connection state";
+
+ QListWidgetItem *p_listWidgetItem = connectMap.value(uuid);
+ if (p_listWidgetItem) {
+ VpnListItem *p_vpnItem = (VpnListItem *)vpnListWidget->itemWidget(p_listWidgetItem);
+ p_vpnItem->updateConnectionState(state);
+ }
+
+}
+
+void VpnPage::onConnectionStateChange(QString uuid,
+ NetworkManager::ActiveConnection::State state,
+ NetworkManager::ActiveConnection::Reason reason)
+{
+ //VpnPage函数内持续监听连接状态的变化并记录供其他函数调用获取状态
+ if (!m_connectResourse->isVirtualConncection(uuid)) {
+ qDebug() << "[VpnPage] connection state change signal but not vpn";
+ return;
+ }
+
+ sendVpnStateChangeSignal(uuid, (ConnectState)state);
+
+ if (m_activeItemMap.keys().contains(uuid) && state == NetworkManager::ActiveConnection::State::Activated) {
+ return;
+ }
+
+ qDebug()<<"[VpnPage] connection uuid"<< uuid
+ << "state change slot:"<< state;
+
+ KyConnectItem *p_newItem = nullptr;
+ QString deviceName = "";
+ QString ssid = "";
+
+ if (state == NetworkManager::ActiveConnection::State::Activated) {
+ p_newItem = m_activeResourse->getActiveConnectionByUuid(uuid);
+ if (nullptr == p_newItem) {
+ qWarning()<<"[VpnPage] get active connection failed, connection uuid" << uuid;
+ return;
+ }
+
+ ssid = p_newItem->m_connectName;
+ updateActivatedConnectionArea(p_newItem);
+ updateConnectionState(m_activeItemMap, m_listWidget, uuid, (ConnectState)state);
+ } else if (state == NetworkManager::ActiveConnection::State::Deactivated) {
+ p_newItem = m_connectResourse->getConnectionItemByUuid(uuid);
+ qDebug() << "[VpnPage] deactivated reason" << reason;
+ if (nullptr == p_newItem) {
+ qWarning()<<"[VpnPage] get active connection failed, connection uuid" << uuid;
+ return;
+ }
+
+ ssid = p_newItem->m_connectName;
+ updateConnectionArea(p_newItem);
+ updateConnectionState(m_vpnItemMap, m_listWidget, uuid, (ConnectState)state);
+ } else if (state == NetworkManager::ActiveConnection::State::Activating) {
+ updateConnectionState(m_vpnItemMap, m_listWidget, uuid, (ConnectState)state);
+ } else if (state == NetworkManager::ActiveConnection::State::Deactivating) {
+ updateConnectionState(m_activeItemMap, m_listWidget, uuid, (ConnectState)state);
+ }
+
+ Q_EMIT vpnActiveConnectionStateChanged(uuid, state);
+
+ if (p_newItem) {
+ delete p_newItem;
+ p_newItem = nullptr;
+ }
+
+ return;
+}
+
+void VpnPage::getVirtualList(QVector &vector)
+{
+ QList netConnectList;
+ vector.clear();
+ m_connectResourse->getVpnAndVirtualConnections(netConnectList); //未激活列表的显示
+ if (!netConnectList.isEmpty()) {
+ for (int i = 0; i < netConnectList.size(); i++) {
+ KyConnectItem *p_newItem = nullptr;
+ KyConnectItem *p_netConnectionItem = netConnectList.at(i);
+ p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid);
+ NetworkManager::ActiveConnection::State state = p_netConnectionItem->m_connectState;
+ if (p_newItem != nullptr) {
+ state = NetworkManager::ActiveConnection::Activated;
+ }
+ vector.append(QStringList() << netConnectList.at(i)->m_connectName
+ << netConnectList.at(i)->m_connectUuid
+ << netConnectList.at(i)->m_connectPath
+ << QString::number(state));
+ }
+ }
+ return;
+}
+
+void VpnPage::sendVpnUpdateSignal(KyConnectItem *p_connectItem)
+{
+ QStringList info;
+ info << p_connectItem->m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath;
+ Q_EMIT vpnUpdate(info);
+
+ return;
+}
+
+void VpnPage::sendVpnAddSignal(KyConnectItem *p_connectItem)
+{
+ QStringList info;
+ KyConnectItem *p_newItem = nullptr;
+ p_newItem = m_activeResourse->getActiveConnectionByUuid(p_connectItem->m_connectUuid);
+ NetworkManager::ActiveConnection::State state = p_connectItem->m_connectState;
+ if (p_newItem != nullptr) {
+ state = NetworkManager::ActiveConnection::Activated;
+ }
+ info << p_connectItem->m_connectName
+ << p_connectItem->m_connectUuid
+ << p_connectItem->m_connectPath
+ << QString::number(state);
+ qDebug() << "[VpnPage] emit vpnAdd because addConnection ";
+ Q_EMIT vpnAdd(info);
+
+ return;
+}
+
+void VpnPage::sendVpnStateChangeSignal(QString uuid, ConnectState state)
+{
+ if (state == Activating || state == Deactivating) {
+ if (m_activeResourse->connectionIsVirtual(uuid)) {
+ return;
+ }
+ }
+
+ Q_EMIT this->vpnConnectChanged(state);
+
+ return;
+}
+
+void VpnPage::updateConnectionProperty(KyConnectItem *p_connectItem)
+{
+ QString newUuid = p_connectItem->m_connectUuid;
+
+ if (m_vpnItemMap.contains(newUuid)) {
+ QListWidgetItem *p_listWidgetItem = m_vpnItemMap.value(newUuid);
+ VpnListItem *p_vpnItem = (VpnListItem*)m_listWidget->itemWidget(p_listWidgetItem);
+ if (p_connectItem->m_connectName != p_vpnItem->getConnectionName()){
+ //只要名字改变就要删除,重新插入,主要是为了排序
+ deleteConnectionMapItem(m_vpnItemMap, m_listWidget, newUuid);
+ QListWidgetItem *p_sortListWidgetItem = insertNewItem(p_connectItem, m_listWidget);
+ if (m_vpnItemMap.contains(newUuid)) {
+ qDebug()<m_connectPath != p_vpnItem->getConnectionPath()) {
+ p_vpnItem->updateConnectionPath(p_connectItem->m_connectPath);
+ }
+ } else if (!m_activeItemMap.contains(newUuid)){
+ if (p_connectItem->m_ifaceName.isEmpty()) {
+ QListWidgetItem *p_listWidgetItem = insertNewItem(p_connectItem, m_listWidget);
+ if (m_vpnItemMap.contains(newUuid)) {
+ qDebug()<m_connectUuid;
+
+ if (m_activeItemMap.contains(newUuid)) {
+ QListWidgetItem *p_listWidgetItem = m_activeItemMap.value(newUuid);
+ VpnListItem *p_vpnItem = (VpnListItem *)m_listWidget->itemWidget(p_listWidgetItem);
+ if (p_vpnItem->getConnectionName() != p_connectItem->m_connectName) {
+ p_vpnItem->updateConnectionName(p_connectItem->m_connectName);
+ }
+
+ if (p_vpnItem->getConnectionName() != p_connectItem->m_connectPath) {
+ p_vpnItem->updateConnectionPath(p_connectItem->m_connectPath);
+ }
+ }
+ return;
+}
+
+void VpnPage::onUpdateConnection(QString uuid)
+{
+ if (!m_connectResourse->isVirtualConncection(uuid)) {
+ return;
+ }
+
+ qDebug() << "[VpnPage]:Connection property Changed." << Q_FUNC_INFO << __LINE__;
+
+ KyConnectItem *p_newItem = nullptr;
+ if (m_connectResourse->isActivatedConnection(uuid)) {
+ p_newItem = m_activeResourse->getActiveConnectionByUuid(uuid);
+ if (nullptr == p_newItem) {
+ qWarning()<<"[VpnPage] get item failed, when update activate connection."
+ <<"connection uuid" << uuid;
+ return;
+ }
+
+ updateActiveConnectionProperty(p_newItem);
+ } else {
+ p_newItem = m_connectResourse->getConnectionItemByUuid(uuid);
+ if (nullptr == p_newItem) {
+ qWarning()<<"[VpnPage] get item failed, when update connection."
+ <<"connection uuid"<type() == QEvent::MouseButtonRelease) {
+ onShowControlCenter();
+ }
+ }
+
+ return QWidget::eventFilter(watched, event);
+}
+
+void VpnPage::deleteVpn(const QString &connUuid)
+{
+ qDebug() << "[VpnPage] deleteVpn" << connUuid;
+ if (connUuid == nullptr) {
+ return;
+ }
+ m_vpnConnectOperation->deleteVpnConnect(connUuid);
+}
+
+void VpnPage::activateVpn(const QString& connUuid)
+{
+ if (m_vpnItemMap.contains(connUuid)) {
+ qDebug() << "[VpnPage] activateVpn" << connUuid;
+ m_vpnConnectOperation->activateVpnConnection(connUuid);
+ }
+}
+
+void VpnPage::deactivateVpn(const QString& connUuid)
+{
+ qDebug() << "[VpnPage] deactivateVpn" << connUuid;
+ QString name("");
+ m_vpnConnectOperation->deactivateVpnConnection(name, connUuid);
+}
+
+void VpnPage::showDetailPage(QString uuid)
+{
+ QListWidgetItem * vpnlistItem = m_vpnItemMap.value(uuid);
+ VpnListItem *vpnItem = (VpnListItem *)m_listWidget->itemWidget(vpnlistItem);
+ vpnItem->onInfoButtonClicked();
+}
+
+void VpnPage::showUI()
+{
+ //2209中窗管在hide界面时会刷新属性,需要重新设置无图标属性
+ const KWindowInfo info(this->winId(), NET::WMState);
+ if (!info.hasState(NET::SkipTaskbar) || !info.hasState(NET::SkipPager)) {
+ KWindowSystem::setState(this->winId(), NET::SkipTaskbar | NET::SkipPager);
+ }
+
+ resetPageHeight();
+
+ showNormal();
+ raise();
+ activateWindow();
+ resetWindowPosition();
+ return;
+}
+
+void VpnPage::resetWindowPosition()
+{
+
+#define MARGIN 4
+#define PANEL_TOP 1
+#define PANEL_LEFT 2
+#define PANEL_RIGHT 3
+//#define PANEL_BOTTOM 4
+ if (!m_positionInterface) {
+ m_positionInterface = new QDBusInterface("org.ukui.panel",
+ "/panel/position",
+ "org.ukui.panel",
+ QDBusConnection::sessionBus());
+ }
+ QRect rect;
+ QDBusReply reply = m_positionInterface->call("GetPrimaryScreenGeometry");
+ //reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置
+ if (!m_positionInterface->isValid() || !reply.isValid() || reply.value().size() < 5) {
+ qCritical() << QDBusConnection::sessionBus().lastError().message();
+ kdk::WindowManager::setGeometry(this->windowHandle(), QRect(0, 0, this->width(), this->height()));
+ return;
+ }
+ QVariantList position_list = reply.value();
+ int position = position_list.at(4).toInt();
+ switch(position){
+ case PANEL_TOP:
+ //任务栏位于上方
+ rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
+ position_list.at(1).toInt() + MARGIN,
+ this->width(), this->height());
+ break;
+ //任务栏位于左边
+ case PANEL_LEFT:
+ rect = QRect(position_list.at(0).toInt() + MARGIN,
+ position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
+ this->width(), this->height());
+ break;
+ //任务栏位于右边
+ case PANEL_RIGHT:
+ rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
+ position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
+ this->width(), this->height());
+ break;
+ //任务栏位于下方
+ default:
+ rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
+ position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
+ this->width(), this->height());
+ break;
+ }
+ kdk::WindowManager::setGeometry(this->windowHandle(), rect);
+ qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__;
+}
+
+void VpnPage::resetListWidgetWidth()
+{
+ if (m_listWidget->count() <= MAX_ITEMS) {
+ m_listFrame->setFixedWidth(MIN_WIDTH);
+ } else {
+ m_listFrame->setFixedWidth(MAX_WIDTH);
+ }
+}
diff --git a/src-vpn/frontend/single-pages/vpnpage.h b/src-vpn/frontend/single-pages/vpnpage.h
new file mode 100644
index 00000000..e5748723
--- /dev/null
+++ b/src-vpn/frontend/single-pages/vpnpage.h
@@ -0,0 +1,137 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef VPNPAGE_H
+#define VPNPAGE_H
+
+#include "divider.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+#include "list-items/listitem.h"
+#include "list-items/vpnlistitem.h"
+#include "single-pages/singlepage.h"
+
+#define VPNPAGE_LAYOUT_MARGINS 0,0,0,0
+#define VPN_LIST_SPACING 0
+#define ITEM_HEIGHT 50
+#define ITEM_SPACE 16
+#define PAGE_SPACE 22
+
+#define LOG_FLAG "[VpnPage]"
+
+#define VISIBLE "visible"
+const QByteArray GSETTINGS_VPNICON_VISIBLE = "org.ukui.kylin-nm.vpnicon";
+
+class VpnListItem;
+
+class VpnPage : public SinglePage
+{
+ Q_OBJECT
+public:
+ explicit VpnPage(QWidget *parent = nullptr);
+ ~VpnPage();
+
+ //for dbus
+ void getVirtualList(QVector &vector);
+ void deleteVpn(const QString &connUuid);
+ void activateVpn(const QString& connUuid);
+ void deactivateVpn(const QString& connUuid);
+ void showDetailPage(QString uuid);
+
+protected:
+ bool eventFilter(QObject *watched, QEvent *event);
+
+private:
+ void initUI();
+ void initVpnArea();
+ void resetPageHeight();
+
+ inline void initDeviceCombox() { return; }
+
+ QListWidgetItem *insertNewItem(KyConnectItem *itemData, QListWidget *listWidget);
+ QListWidgetItem *addNewItem(KyConnectItem *itemData, QListWidget *listWidget);
+ bool removeConnectionItem(QMap &connectMap,
+ QListWidget *vpnListWidget, QString path);
+
+ void constructItemArea();
+
+ void updateConnectionArea(KyConnectItem *p_newItem);
+ void updateActivatedConnectionArea(KyConnectItem *p_newItem);
+ void updateConnectionState(QMap &connectMap,
+ QListWidget *vpnListWidget, QString uuid, ConnectState state);
+
+ void updateActiveConnectionProperty(KyConnectItem *p_connectItem);
+ void updateConnectionProperty(KyConnectItem *p_connectItem);
+
+ void sendVpnUpdateSignal(KyConnectItem *p_connectItem);
+ void sendVpnAddSignal(KyConnectItem *p_connectItem);
+ void sendVpnStateChangeSignal(QString uuid, ConnectState state);
+
+ void clearConnectionMap(QMap &connectMap,
+ QListWidget *vpnListWidget);
+ void deleteConnectionMapItem(QMap &connectMap,
+ QListWidget *vpnListWidget, QString uuid);
+
+ void resetWindowPosition();
+ void resetListWidgetWidth();
+
+Q_SIGNALS:
+ void vpnAdd(QStringList info);
+ void vpnRemove(QString dbusPath);
+ void vpnUpdate(QStringList info);
+
+ void vpnActiveConnectionStateChanged(QString uuid, int status);
+ void vpnConnectChanged(int state);
+
+private Q_SLOTS:
+ void onConnectionStateChange(QString uuid,
+ NetworkManager::ActiveConnection::State state,
+ NetworkManager::ActiveConnection::Reason reason);
+
+ void onAddConnection(QString uuid);
+ void onRemoveConnection(QString path);
+ void onUpdateConnection(QString uuid);
+
+ void onShowControlCenter();
+
+private:
+ KyVpnConnectOperation *m_vpnConnectOperation = nullptr;
+ KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接
+ KyConnectResourse *m_connectResourse = nullptr; //未激活的连接
+
+ QMap m_vpnItemMap;
+ QMap m_activeItemMap;
+
+ QDBusInterface * m_positionInterface = nullptr;
+
+
+
+public Q_SLOTS:
+ void showUI();
+};
+
+#endif // LANPAGE_H
diff --git a/src-vpn/frontend/vpndetails/vpnaddpage.cpp b/src-vpn/frontend/vpndetails/vpnaddpage.cpp
new file mode 100644
index 00000000..087470d1
--- /dev/null
+++ b/src-vpn/frontend/vpndetails/vpnaddpage.cpp
@@ -0,0 +1,234 @@
+#include "vpnaddpage.h"
+#include
+#include "vpnconfigpage.h"
+
+vpnAddPage::vpnAddPage(QWidget *parent) : QWidget(parent)
+{
+ m_vpnConnOperation = new KyVpnConnectOperation(this);
+ initWindow();
+ initUI();
+ initConnection();
+ centerToScreen();
+}
+
+void vpnAddPage::centerToScreen()
+{
+ QDesktopWidget* m = QApplication::desktop();
+ QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos()));
+ int desk_x = desk_rect.width();
+ int desk_y = desk_rect.height();
+ int x = this->width();
+ int y = this->height();
+ this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
+}
+
+void vpnAddPage::initWindow()
+{
+ this->setFixedSize(VPNADDPAGE_SIZE);
+ this->setWindowTitle(tr("create VPN"));
+ this->setWindowFlag(Qt::WindowMinMaxButtonsHint,false);
+ this->setAttribute(Qt::WA_DeleteOnClose);
+}
+
+void vpnAddPage::initUI()
+{
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ mainLayout->setContentsMargins(VPNADDPAGE_MAINLAYOUT_MARGINS);
+ mainLayout->setSpacing(VPNADDPAGE_NULLSPACE);
+
+ initVpnTypeFrame();
+ initVpnNameFrame();
+ initVpnServerFrame();
+ initButtonFrame();
+ onSetConfimBtnEnable();
+
+ mainLayout->addWidget(m_vpnTypeFrame);
+ mainLayout->addWidget(m_vpnNameFrame);
+ mainLayout->addWidget(m_vpnServerFrame);
+ mainLayout->addStretch();
+ mainLayout->addWidget(m_buttonFrame);
+ this->setLayout(mainLayout);
+}
+
+void vpnAddPage::initVpnTypeFrame()
+{
+ m_vpnTypeFrame = new QFrame(this);
+ m_vpnTypeFrame->setFrameShape(QFrame::Shape::NoFrame);
+ m_vpnTypeFrame->setFixedSize(VPNADDPAGE_FRAME_FIXEDSIZE);
+
+ QHBoxLayout *typeLayout = new QHBoxLayout(m_vpnTypeFrame);
+ typeLayout->setContentsMargins(VPNADDPAGE_ITEM_MARGINS);
+ typeLayout->setSpacing(VPNADDPAGE_NULLSPACE);
+
+ QLabel *vpnTypeLabel = new QLabel(tr("VPN Type"), this);
+ vpnTypeLabel->setFixedWidth(VPNADDPAGE_LABLE_FIXEDWIDTH);
+
+ m_vpnTypeComboBox = new QComboBox(this);
+ m_vpnTypeComboBox->setInsertPolicy(QComboBox::NoInsert);
+ m_vpnTypeComboBox->setFixedWidth(VPNADDPAGE_COMBOBOX_FIXEDWIDTH);
+ m_vpnTypeComboBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
+
+ m_vpnTypeComboBox->addItem("L2TP", L2TP);
+ m_vpnTypeComboBox->addItem("open VPN", OPEN_VPN);
+ m_vpnTypeComboBox->addItem("PPTP", PPTP);
+ m_vpnTypeComboBox->addItem("strong-swan", STRONG_SWAN);
+
+
+ typeLayout->addWidget(vpnTypeLabel);
+ typeLayout->addWidget(m_vpnTypeComboBox);
+ m_vpnTypeFrame->setLayout(typeLayout);
+}
+
+void vpnAddPage::initVpnNameFrame()
+{
+ m_vpnNameFrame = new QFrame(this);
+ m_vpnNameFrame->setFrameShape(QFrame::Shape::NoFrame);
+ m_vpnNameFrame->setFixedSize(VPNADDPAGE_FRAME_FIXEDSIZE);
+
+ QHBoxLayout *nameLayout = new QHBoxLayout(m_vpnNameFrame);
+ nameLayout->setContentsMargins(VPNADDPAGE_ITEM_MARGINS);
+ nameLayout->setSpacing(VPNADDPAGE_NULLSPACE);
+
+ QLabel *vpnNameLabel = new QLabel(tr("VPN Name"), this);
+ vpnNameLabel->setFixedWidth(VPNADDPAGE_LABLE_FIXEDWIDTH);
+
+ m_vpnNameLineEdit = new QLineEdit(this);
+ m_vpnNameLineEdit->setFixedWidth(VPNADDPAGE_INPUTBOX_FIXEDWIDTH);
+ m_vpnNameLineEdit->setMaxLength(VPNADDPAGE_NAME_MAX_LENGTH);
+ m_vpnNameLineEdit->setPlaceholderText(tr("Required")); //必填
+
+ nameLayout->addWidget(vpnNameLabel);
+ nameLayout->addWidget(m_vpnNameLineEdit);
+ m_vpnNameFrame->setLayout(nameLayout);
+}
+
+void vpnAddPage::initVpnServerFrame()
+{
+ m_vpnServerFrame = new QFrame(this);
+ m_vpnServerFrame->setFrameShape(QFrame::Shape::NoFrame);
+ m_vpnServerFrame->setFixedSize(VPNADDPAGE_FRAME_FIXEDSIZE);
+
+ QHBoxLayout *serverLayout = new QHBoxLayout(m_vpnServerFrame);
+ serverLayout->setContentsMargins(VPNADDPAGE_ITEM_MARGINS);
+ serverLayout->setSpacing(VPNADDPAGE_NULLSPACE);
+
+ QLabel *vpnServerLabel = new QLabel(tr("VPN Server"), this);
+ vpnServerLabel->setFixedWidth(VPNADDPAGE_LABLE_FIXEDWIDTH);
+
+ m_vpnServerLineEdit = new QLineEdit(this);
+ m_vpnServerLineEdit->setFixedWidth(VPNADDPAGE_INPUTBOX_FIXEDWIDTH);
+ m_vpnServerLineEdit->setPlaceholderText(tr("Required")); //必填
+
+ serverLayout->addWidget(vpnServerLabel);
+ serverLayout->addWidget(m_vpnServerLineEdit);
+ m_vpnServerFrame->setLayout(serverLayout);
+
+ // IP的正则格式限制
+ QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
+ QRegExpValidator *ipExpVal = new QRegExpValidator(rxIp, this);
+ m_vpnServerLineEdit->setValidator(ipExpVal);
+}
+
+void vpnAddPage::initButtonFrame()
+{
+ m_buttonFrame = new QFrame(this);
+ m_buttonFrame->setFixedSize(VPNDETAILPAGE_FRAME_FIXEDSIZE);
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout(m_buttonFrame);
+ buttonLayout->setContentsMargins(VPNDETAILPAGE_ITEM_MARGINS);
+ buttonLayout->setSpacing(VPNDETAILPAGE_NULLSPACE);
+
+ QLabel *autoConnectLabel = new QLabel(this);
+ m_autoConnectBox = new QCheckBox(this);
+ autoConnectLabel->setText(tr("Auto Connection"));
+ QWidget *autoConWidget = new QWidget(this);
+ QHBoxLayout *autoLayout = new QHBoxLayout(autoConWidget);
+
+ autoLayout->setContentsMargins(VPNDETAILPAGE_NULLMAGINS);
+ autoLayout->setSpacing(VPNDETAILPAGE_NULLSPACE);
+ autoLayout->addWidget(m_autoConnectBox);
+ autoLayout->addWidget(autoConnectLabel);
+ autoConWidget->setLayout(autoLayout);
+
+ m_confimBtn = new QPushButton(this);
+ m_confimBtn->setFixedSize(VPNDETAILPAGE_BUTTON_FIXEDSIZE);
+ m_confimBtn->setText(tr("Confirm"));
+ m_cancelBtn = new QPushButton(this);
+ m_cancelBtn->setFixedSize(VPNDETAILPAGE_BUTTON_FIXEDSIZE);
+ m_cancelBtn->setText(tr("Cancel"));
+
+ buttonLayout->addWidget(autoConWidget);
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(m_cancelBtn);
+ buttonLayout->addSpacing(VPNDETAILPAGE_BUTTON_SPACE);
+ buttonLayout->addWidget(m_confimBtn);
+ m_buttonFrame->setLayout(buttonLayout);
+}
+
+void vpnAddPage::initConnection()
+{
+ if (m_vpnNameLineEdit != nullptr) {
+ connect(m_vpnNameLineEdit, &QLineEdit::textChanged, this, &vpnAddPage::onSetConfimBtnEnable);
+ }
+
+ if (m_vpnServerLineEdit != nullptr) {
+ connect(m_vpnServerLineEdit, &QLineEdit::textChanged, this, &vpnAddPage::onSetConfimBtnEnable);
+ }
+
+ if (m_cancelBtn != nullptr) {
+ connect(m_cancelBtn, &QPushButton::clicked, [&] () {this->close();});
+ }
+
+ if (m_confimBtn != nullptr) {
+ connect(m_confimBtn, &QPushButton::clicked, this, &vpnAddPage::onConfimBtnClicked);
+ }
+}
+
+bool vpnAddPage::checkConfimBtnIsEnabled()
+{
+ if (m_vpnNameLineEdit->text().isEmpty()) {
+ qDebug() << "ipv4address empty or invalid";
+ return false;
+ }
+
+ if (m_vpnServerLineEdit->text().isEmpty()) {
+ qDebug() << "ipv4 netMask empty or invalid";
+ return false;
+ }
+ return true;
+}
+
+void vpnAddPage::onSetConfimBtnEnable()
+{
+ m_confimBtn->setEnabled(checkConfimBtnIsEnabled());
+}
+
+void vpnAddPage::onConfimBtnClicked()
+{
+ //新建有线连接
+ qDebug() << "Confirm create vpn connect";
+ if (!createVpnConnect()) {
+// setNetdetailSomeEnable(true);
+// return;
+ }
+ close();
+}
+
+bool vpnAddPage::createVpnConnect()
+{
+ KyVpnConfig vpnSetting;
+ QString connectName = m_vpnNameLineEdit->text();
+ vpnSetting.m_gateway = m_vpnServerLineEdit->text();
+ vpnSetting.setConnectName(connectName);
+ vpnSetting.m_vpnName = connectName;
+ vpnSetting.m_isAutoConnect = m_autoConnectBox->isChecked();
+ vpnSetting.m_vpnType = (KyVpnType)m_vpnTypeComboBox->currentData().toInt();
+
+ m_vpnConnOperation->createVpnConnect(vpnSetting);
+ return true;
+}
+
+vpnAddPage::~vpnAddPage()
+{
+ Q_EMIT this->closed();
+}
diff --git a/src-vpn/frontend/vpndetails/vpnaddpage.h b/src-vpn/frontend/vpndetails/vpnaddpage.h
new file mode 100644
index 00000000..19fe9c64
--- /dev/null
+++ b/src-vpn/frontend/vpndetails/vpnaddpage.h
@@ -0,0 +1,90 @@
+#ifndef VPNADDPAGE_H
+#define VPNADDPAGE_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "kyvpnconnectoperation.h"
+
+#define VPNADDPAGE_MAINLAYOUT_MARGINS 0, 12, 0, 12
+#define VPNADDPAGE_ITEM_MARGINS 24, 0, 24, 0
+#define VPNADDPAGE_NULLMAGINS 0, 0, 0, 0
+
+#define VPNADDPAGE_SIZE 520,312
+#define VPNADDPAGE_FRAME_FIXEDSIZE 520, 60
+#define VPNADDPAGE_BUTTON_FIXEDSIZE 96, 36
+
+#define VPNADDPAGE_NULLSPACE 0
+#define VPNADDPAGE_BUTTON_SPACE 16
+#define VPNADDPAGE_NAME_MAX_LENGTH 32
+#define VPNADDPAGE_LABLE_FIXEDWIDTH 112
+#define VPNADDPAGE_COMBOBOX_FIXEDWIDTH 360
+#define VPNADDPAGE_INPUTBOX_FIXEDWIDTH 360
+
+#define VPNDETAILPAGE_ITEM_MARGINS 24, 0, 24, 0
+#define VPNDETAILPAGE_NULLMAGINS 0, 0, 0, 0
+
+#define VPNDETAILPAGE_FRAME_FIXEDSIZE 520, 60
+#define VPNDETAILPAGE_BUTTON_FIXEDSIZE 96, 36
+
+#define VPNDETAILPAGE_NULLSPACE 0
+#define VPNDETAILPAGE_BUTTON_SPACE 16
+
+
+
+class vpnAddPage : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit vpnAddPage(QWidget *parent = nullptr);
+ void centerToScreen();
+ ~vpnAddPage();
+
+private:
+ void initWindow();
+ void initUI();
+ void initVpnTypeFrame();
+ void initVpnNameFrame();
+ void initVpnServerFrame();
+ void initButtonFrame();
+
+ void initConnection();
+
+ bool checkConfimBtnIsEnabled();
+ bool createVpnConnect();
+
+private:
+ QFrame *m_vpnTypeFrame = nullptr;
+ QFrame *m_vpnNameFrame = nullptr;
+ QFrame *m_vpnServerFrame = nullptr;
+ QFrame *m_buttonFrame = nullptr;
+
+ QComboBox *m_vpnTypeComboBox = nullptr;
+ QLineEdit *m_vpnNameLineEdit = nullptr;
+ QLineEdit *m_vpnServerLineEdit = nullptr;
+
+ QPushButton *m_confimBtn = nullptr;
+ QPushButton *m_cancelBtn = nullptr;
+ QCheckBox *m_autoConnectBox = nullptr;
+
+ KyVpnConnectOperation *m_vpnConnOperation = nullptr;
+
+private Q_SLOTS:
+ void onConfimBtnClicked();
+ void onSetConfimBtnEnable();
+
+Q_SIGNALS:
+ void closed();
+};
+
+#endif // VPNADDPAGE_H
diff --git a/src-vpn/frontend/vpndetails/vpnadvancedpage.cpp b/src-vpn/frontend/vpndetails/vpnadvancedpage.cpp
new file mode 100644
index 00000000..c8a3b08d
--- /dev/null
+++ b/src-vpn/frontend/vpndetails/vpnadvancedpage.cpp
@@ -0,0 +1,1508 @@
+#include "vpnadvancedpage.h"
+
+#include
+#include
+#include
+#define NO_LAYOUT_MARGINS 0, 0, 0, 0
+#define NO_SPACE 0
+#define LAYOUT_SPACING_SMALL 8
+#define HOR_LAYOUT_SPACING 24
+#define LAYOUT_ADD_SPACING 16
+#define VLAYOUT_ADD_SPACING 24
+#define LISTWIDGET_HEIGHT 184
+#define LISTWIDGET_HEIGHT_SMALL 112
+#define MIN_EDIT_WIDTH 150
+#define FIX_EDIT_WIDTH 200
+#define MIN_LABEL_WIDTH 140
+#define MAX_LABEL_WIDTH 240
+#define ONE_LABEL_WIDTH 440
+#define MAX_MRU_LENGTH 4
+#define ITEM_HEIGHT 36
+#define COMP_MODE_PROTOCOL 3
+#define COMP_MODE_ADDRESS 4
+#define LOG_FLAG "[VPN AdvancedPage]"
+
+VpnAdvancedPage::VpnAdvancedPage(QWidget *parent) : QFrame(parent)
+{
+ initUi();
+ initConnect();
+ initDefalutCheckState();
+}
+
+void VpnAdvancedPage::setL2tpOrPptpAdiaInfo(const KyVpnConfig &vpnInfo)
+{
+ //L2TP PPTP共有
+ m_mppeECheckbox->setChecked(vpnInfo.m_mppeEnable);
+ if (m_mppeECheckbox->isChecked()) {
+ m_mppeECombox->setCurrentIndex((int)vpnInfo.m_mppeEncryptMethod);
+ } else {
+ m_mppeECombox->setEnabled(false);
+ }
+ m_useStatefulECheckbox->setChecked(vpnInfo.m_isAllowStatefulEncryption);
+ m_useStatefulECheckbox->setEnabled(vpnInfo.m_mppeEnable);
+ m_papAuthCheckbox->setEnabled(!vpnInfo.m_mppeEnable);
+ m_chapAuthCheckbox->setEnabled(!vpnInfo.m_mppeEnable);
+ m_eapAuthCheckbox->setEnabled(!vpnInfo.m_mppeEnable);
+
+ m_sendPppEchoPkgCheckbox->setChecked(vpnInfo.m_sendPppPackage);
+
+ //Auth Methods
+ m_papAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_PAP));
+ m_chapAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_CHAP));
+ m_mschapAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAP));
+ m_mschap2AuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAPV2));
+ m_eapAuthCheckbox->setChecked(vpnInfo.m_authMethods.testFlag(KYAUTH2_EAP));
+
+ //Compress Methods
+ m_bsdCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_BSD));
+ m_defaultCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_DEFLATE));
+ m_tcpCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_TCP));
+
+
+ //L2TP
+ if (vpnInfo.m_vpnType == KYVPNTYPE_L2TP) {
+ m_protocolCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_PROTO));
+ m_addressCompModeCheckbox->setChecked(vpnInfo.m_compressMethods.testFlag(KYCOMP_ADDR));
+
+ m_mruEdit->setText(vpnInfo.m_mru);
+ m_mtuEdit->setText(vpnInfo.m_mtu);
+ }
+}
+
+void VpnAdvancedPage::setOpenVpnAdiaInfo(const KyVpnConfig &vpnInfo)
+{
+ //General
+ m_customGatewayPortCheckbox->setChecked(vpnInfo.m_useAssignPort);
+ m_gatewayPortEdit->setText(vpnInfo.m_assignPort);
+
+ m_customRenegotiaInrCheckbox->setChecked(vpnInfo.m_useRenegSeconds);
+ m_renogotiaInrEdit->setText(vpnInfo.m_renegSeconds);
+
+ m_compressionCheckbox->setChecked(vpnInfo.m_useCompress);
+ m_compressionCombox->setCurrentIndex((int)vpnInfo.m_openvpnCompress);
+
+ m_tcpConnCheckbox->setChecked(vpnInfo.m_useTcpLink);
+
+ m_setVDevTypeCheckbox->setChecked(vpnInfo.m_setDevType);
+ m_setVDevTypeCombox->setCurrentIndex((int)vpnInfo.m_devType);
+
+ m_setVDevNameCheckbox->setChecked(vpnInfo.m_setDevName);
+ m_setVDevNameEdit->setText(vpnInfo.m_devName);
+
+ m_customMtuCheckbox->setChecked(vpnInfo.m_useTunnelMtu);
+ m_customMtuEdit->setText(vpnInfo.m_tunnelMtu);
+
+ m_customUdpFragSizeCheckbox->setChecked(vpnInfo.m_useFragmentSize);
+ m_customUdpFragSizeEdit->setText(vpnInfo.m_fragmentSize);
+
+ m_tcpMssCheckbox->setChecked(vpnInfo.m_mssfix);
+
+ m_randomRemoteHostCheckbox->setChecked(vpnInfo.m_remoteRandom);
+
+ m_ipv6TunLinkCheckbox->setChecked(vpnInfo.m_ipv6TunLink);
+
+ m_specPingInrCheckbox->setChecked(vpnInfo.m_setPingCycle);
+ m_specPingInrEdit->setText(vpnInfo.m_pingCycle);
+
+ m_specExitPingCheckbox->setChecked(vpnInfo.m_usePingMethod);
+ m_specExitRestarCombox->setCurrentIndex((int)vpnInfo.m_pingMethod);
+ m_specExRePingEdit->setText(vpnInfo.m_pingMethodTime);
+
+ m_acceptAuthedPaksCheckbox->setChecked(vpnInfo.m_float);
+
+ m_specMaxRouteCheckbox->setChecked(vpnInfo.m_setMaxRoute);
+ m_specMaxRouteEdit->setText(vpnInfo.m_maxRoute);
+
+
+ //TLS settings
+ m_serverCertCheckCombox->setCurrentIndex((int)vpnInfo.m_checkServerCa);
+
+ m_subjectMatchEdit->setText(vpnInfo.m_verifyName);
+
+ m_usePreviousCertCheckbox->setChecked(vpnInfo.m_useRemoteCertTls);
+ m_usePreviousCertCombox->setCurrentIndex((int)vpnInfo.m_remoteCertType);
+
+ m_verifyPeerCertCheckbox->setChecked(vpnInfo.m_useNsCertTls);
+ m_verifyPeerCertCombox->setCurrentIndex((int)vpnInfo.m_nsCertType);
+
+ m_tlsModeCombox->setCurrentIndex(vpnInfo.m_vpnTlsMode);
+ m_keyPathEdit->setText(vpnInfo.m_vpnKeyFile);
+ if (vpnInfo.m_vpnTlsMode == KYVPNTLS_AUTHENTICATION) {
+ if (vpnInfo.m_vpnTlsTaDir == KEY_DIRECTION_ZERO) {
+ m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ZERO_INDEX);
+ } else if (vpnInfo.m_vpnTlsTaDir == KEY_DIRECTION_ONE) {
+ m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_ONE_INDEX);
+ } else {
+ m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_NONE_INDEX);
+ }
+ } else {
+ m_keyDirectionCombox->setCurrentIndex(KEY_DIRECTION_NONE_INDEX);
+ }
+
+ //Proxies
+ m_proxyTypeCombox->setCurrentIndex((int)vpnInfo.m_vpnProxyType);
+ m_proxyServerAddEdit->setText(vpnInfo.m_vpnProxyServer);
+ m_proxyPortEdit->setText(vpnInfo.m_vpnProxyPort);
+ m_infiniteRetryCheckbox->setChecked(vpnInfo.m_vpnProxyRetry);
+ m_proxyUsernameEdit->setText(vpnInfo.m_vpnProxyName);
+ m_proxyPwdEdit->setText(vpnInfo.m_vpnProxyPasswd);
+
+ //Security
+ m_customKeySizeCheckbox->setChecked(vpnInfo.m_useKeysize);
+ m_customKeySizeEdit->setText(vpnInfo.m_keySize);
+ m_hmacAuthCombox->setCurrentIndex((int)vpnInfo.m_hmacAuthMethod);
+}
+
+void VpnAdvancedPage::setStrongSwanAdiaInfo(const KyVpnConfig &vpnInfo)
+{
+ m_requestInIPCheckbox->setChecked(vpnInfo.m_virtual);
+ m_udpEncapCheckbox->setChecked(vpnInfo.m_encap);
+ m_ipCompCheckbox->setChecked(vpnInfo.m_ipcomp);
+ m_enablCustomCheckbox->setChecked(vpnInfo.m_proposal);
+
+ if (vpnInfo.m_proposal) {
+ m_ikeEdit->setText(vpnInfo.m_ike);
+ m_espEdit->setText(vpnInfo.m_esp);
+ }
+}
+
+bool VpnAdvancedPage::checkIsChanged(const KyVpnConfig &vpnInfo, VpnType &vpnType)
+{
+ bool isChanged = false;
+ switch (vpnType) {
+ case L2TP:
+ if (checkL2tpIsChanged(vpnInfo)) {
+ isChanged = true;
+ }
+ break;
+ case PPTP:
+ if (checkPptpIsChanged(vpnInfo)) {
+ isChanged = true;
+ }
+ break;
+ case OPEN_VPN:
+ if (checkOpenVpnIsChanged(vpnInfo)) {
+ isChanged = true;
+ }
+ break;
+ case STRONG_SWAN:
+ if (checkStrongSwanIsChanged(vpnInfo)) {
+ isChanged = true;
+ }
+ break;
+ default:
+ qDebug() << LOG_FLAG << "Unknow VPN Type" << vpnType;
+ break;
+ }
+ return isChanged;
+}
+
+bool VpnAdvancedPage::checkL2tpIsChanged(const KyVpnConfig &vpnInfo)
+{
+ bool isChanged = false;
+ if (vpnInfo.m_mppeEnable != m_mppeECheckbox->isChecked()
+ || m_mppeECombox->currentData().toInt() != vpnInfo.m_mppeEncryptMethod
+ || vpnInfo.m_isAllowStatefulEncryption != m_useStatefulECheckbox->isChecked()
+ || vpnInfo.m_sendPppPackage != m_sendPppEchoPkgCheckbox->isChecked()) {
+
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_authMethods.testFlag(KYAUTH2_PAP) != m_papAuthCheckbox->isChecked()
+ || vpnInfo.m_authMethods.testFlag(KYAUTH2_CHAP) != m_chapAuthCheckbox->isChecked()
+ || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAP) != m_mschapAuthCheckbox->isChecked()
+ || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAPV2) != m_mschap2AuthCheckbox->isChecked()
+ || vpnInfo.m_authMethods.testFlag(KYAUTH2_EAP) != m_eapAuthCheckbox->isChecked()) {
+
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_compressMethods.testFlag(KYCOMP_BSD) != m_bsdCompModeCheckbox->isChecked()
+ || vpnInfo.m_compressMethods.testFlag(KYCOMP_DEFLATE) != m_defaultCompModeCheckbox->isChecked()
+ || vpnInfo.m_compressMethods.testFlag(KYCOMP_TCP) != m_tcpCompModeCheckbox->isChecked()
+ || vpnInfo.m_compressMethods.testFlag(KYCOMP_PROTO) != m_protocolCompModeCheckbox->isChecked()
+ || vpnInfo.m_compressMethods.testFlag(KYCOMP_ADDR) != m_addressCompModeCheckbox->isChecked()) {
+
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_mru != m_mruEdit->text() || vpnInfo.m_mtu != m_mtuEdit->text()) {
+ isChanged = true;
+ }
+
+ return isChanged;
+}
+
+bool VpnAdvancedPage::checkPptpIsChanged(const KyVpnConfig &vpnInfo)
+{
+ bool isChanged = false;
+ if (vpnInfo.m_mppeEnable != m_mppeECheckbox->isChecked()
+ || m_mppeECombox->currentData().toInt() != vpnInfo.m_mppeEncryptMethod
+ || vpnInfo.m_isAllowStatefulEncryption != m_useStatefulECheckbox->isChecked()
+ || vpnInfo.m_sendPppPackage != m_sendPppEchoPkgCheckbox->isChecked()) {
+
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_authMethods.testFlag(KYAUTH2_PAP) != m_papAuthCheckbox->isChecked()
+ || vpnInfo.m_authMethods.testFlag(KYAUTH2_CHAP) != m_chapAuthCheckbox->isChecked()
+ || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAP) != m_mschapAuthCheckbox->isChecked()
+ || vpnInfo.m_authMethods.testFlag(KYAUTH2_MSCHAPV2) != m_mschap2AuthCheckbox->isChecked()
+ || vpnInfo.m_authMethods.testFlag(KYAUTH2_EAP) != m_eapAuthCheckbox->isChecked()) {
+
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_compressMethods.testFlag(KYCOMP_BSD) != m_bsdCompModeCheckbox->isChecked()
+ || vpnInfo.m_compressMethods.testFlag(KYCOMP_DEFLATE) != m_defaultCompModeCheckbox->isChecked()
+ || vpnInfo.m_compressMethods.testFlag(KYCOMP_TCP) != m_tcpCompModeCheckbox->isChecked()) {
+
+ isChanged = true;
+ }
+
+ return isChanged;
+}
+
+bool VpnAdvancedPage::checkOpenVpnIsChanged(const KyVpnConfig &vpnInfo)
+{
+ bool isChanged = false;
+ //General
+ if (vpnInfo.m_useAssignPort != m_customGatewayPortCheckbox->isChecked()
+ || vpnInfo.m_assignPort != m_gatewayPortEdit->text()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_useRenegSeconds != m_customRenegotiaInrCheckbox->isChecked()
+ || vpnInfo.m_renegSeconds != m_renogotiaInrEdit->text()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_useCompress != m_compressionCheckbox->isChecked()
+ || vpnInfo.m_openvpnCompress != m_compressionCombox->currentData().toInt()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_useTcpLink != m_tcpConnCheckbox->isChecked()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_setDevType != m_setVDevTypeCheckbox->isChecked()
+ || vpnInfo.m_devType != m_setVDevTypeCombox->currentData().toInt()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_setDevName != m_setVDevNameCheckbox->isChecked()
+ || vpnInfo.m_devName != m_setVDevNameEdit->text()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_useTunnelMtu != m_customMtuCheckbox->isChecked()
+ || vpnInfo.m_tunnelMtu != m_customMtuEdit->text()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_useFragmentSize != m_customUdpFragSizeCheckbox->isChecked()
+ || vpnInfo.m_fragmentSize != m_customUdpFragSizeEdit->text()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_mssfix != m_tcpMssCheckbox->isChecked()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_remoteRandom != m_randomRemoteHostCheckbox->isChecked()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_ipv6TunLink != m_ipv6TunLinkCheckbox->isChecked()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_setPingCycle != m_specPingInrCheckbox->isChecked()
+ || vpnInfo.m_pingCycle != m_specPingInrEdit->text()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_usePingMethod != m_specExitPingCheckbox->isChecked()
+ || vpnInfo.m_pingMethod != m_specExitRestarCombox->currentData().toInt()
+ || vpnInfo.m_pingMethodTime != m_specExRePingEdit->text()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_float != m_acceptAuthedPaksCheckbox->isChecked()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_setMaxRoute != m_specMaxRouteCheckbox->isChecked()
+ || vpnInfo.m_maxRoute != m_specMaxRouteEdit->text()) {
+ isChanged = true;
+ }
+
+
+ //TLS settings
+ if (vpnInfo.m_checkServerCa != m_serverCertCheckCombox->currentData().toInt()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_verifyName != m_subjectMatchEdit->text()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_useRemoteCertTls != m_usePreviousCertCheckbox->isChecked()
+ || vpnInfo.m_remoteCertType != m_usePreviousCertCombox->currentData().toInt()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_useNsCertTls != m_verifyPeerCertCheckbox->isChecked()
+ || vpnInfo.m_nsCertType != m_verifyPeerCertCombox->currentData().toInt()) {
+ isChanged = true;
+ }
+
+ if (vpnInfo.m_vpnTlsMode != m_tlsModeCombox->currentData().toInt()
+ || vpnInfo.m_vpnKeyFile != m_keyPathEdit->text()
+ || vpnInfo.m_vpnTlsTaDir != m_keyDirectionCombox->currentData().toString()) {
+ isChanged = true;
+ }
+
+
+ //Proxies
+ int currentProxyType = m_proxyTypeCombox->currentData().toInt();
+ if (vpnInfo.m_vpnProxyType != currentProxyType) {
+ isChanged = true;
+ }
+
+ if (currentProxyType == HTTP || currentProxyType == SOCKS) {
+ if (vpnInfo.m_vpnProxyServer != m_proxyServerAddEdit->text()
+ || vpnInfo.m_vpnProxyPort != m_proxyPortEdit->text()
+ || vpnInfo.m_vpnProxyRetry != m_infiniteRetryCheckbox->isChecked()) {
+ isChanged = true;
+ }
+
+ if (currentProxyType == HTTP) {
+ if (vpnInfo.m_vpnProxyName != m_proxyUsernameEdit->text()
+ || vpnInfo.m_vpnProxyPasswd != m_proxyPwdEdit->text()) {
+ isChanged = true;
+ }
+ }
+ }
+
+
+ //Security
+ if (vpnInfo.m_useKeysize != m_customKeySizeCheckbox->isChecked()
+ || vpnInfo.m_keySize != m_customKeySizeEdit->text()
+ || vpnInfo.m_hmacAuthMethod != m_hmacAuthCombox->currentData().toInt()) {
+ isChanged = true;
+ }
+
+
+ return isChanged;
+}
+
+bool VpnAdvancedPage::checkStrongSwanIsChanged(const KyVpnConfig &vpnInfo)
+{
+ bool isChanged = false;
+ if (vpnInfo.m_virtual != m_requestInIPCheckbox->isChecked()
+ || vpnInfo.m_encap != m_udpEncapCheckbox->isChecked()
+ || vpnInfo.m_ipcomp != m_ipCompCheckbox->isChecked()
+ || vpnInfo.m_proposal != m_enablCustomCheckbox->isChecked()) {
+
+ isChanged = true;
+ }
+
+ if (m_enablCustomCheckbox->isChecked()) {
+ if (vpnInfo.m_ike != m_ikeEdit->text() || vpnInfo.m_esp != m_espEdit->text()) {
+ isChanged = true;
+ }
+ }
+
+ return isChanged;
+}
+
+void VpnAdvancedPage::updateL2tpOrPptpAdiaInfo(KyVpnConfig &vpnInfo)
+{
+ vpnInfo.m_mppeEnable = m_mppeECheckbox->isChecked();
+ vpnInfo.m_mppeEncryptMethod = (KyMPPEMethod)m_mppeECombox->currentData().toInt();
+ vpnInfo.m_isAllowStatefulEncryption = m_useStatefulECheckbox->isChecked();
+ vpnInfo.m_sendPppPackage = m_sendPppEchoPkgCheckbox->isChecked();
+
+ vpnInfo.m_authMethods.setFlag(KYAUTH2_PAP, m_papAuthCheckbox->isChecked());
+ vpnInfo.m_authMethods.setFlag(KYAUTH2_CHAP, m_chapAuthCheckbox->isChecked());
+ vpnInfo.m_authMethods.setFlag(KYAUTH2_MSCHAP, m_mschapAuthCheckbox->isChecked());
+ vpnInfo.m_authMethods.setFlag(KYAUTH2_MSCHAPV2, m_mschap2AuthCheckbox->isChecked());
+ vpnInfo.m_authMethods.setFlag(KYAUTH2_EAP, m_eapAuthCheckbox->isChecked());
+
+ vpnInfo.m_compressMethods.setFlag(KYCOMP_BSD, m_bsdCompModeCheckbox->isChecked());
+ vpnInfo.m_compressMethods.setFlag(KYCOMP_DEFLATE, m_defaultCompModeCheckbox->isChecked());
+ vpnInfo.m_compressMethods.setFlag(KYCOMP_TCP, m_tcpCompModeCheckbox->isChecked());
+
+ if (!m_compModeListWidget->item(COMP_MODE_PROTOCOL)->isHidden()
+ && !m_compModeListWidget->item(COMP_MODE_ADDRESS)->isHidden()) {
+ vpnInfo.m_compressMethods.setFlag(KYCOMP_PROTO, m_protocolCompModeCheckbox->isChecked());
+ vpnInfo.m_compressMethods.setFlag(KYCOMP_ADDR, m_addressCompModeCheckbox->isChecked());
+ vpnInfo.m_mru = m_mruEdit->text();
+ vpnInfo.m_mtu = m_mtuEdit->text();
+ qDebug() << LOG_FLAG << "Update L2TP advanced info finished";
+
+ } else {
+ qDebug() << LOG_FLAG << "Update PPTP advanced info finished";
+ }
+}
+
+void VpnAdvancedPage::updateOpenVpnAdiaInfo(KyVpnConfig &vpnInfo)
+{
+ //General
+ vpnInfo.m_useAssignPort = m_customGatewayPortCheckbox->isChecked();
+ vpnInfo.m_assignPort = m_gatewayPortEdit->text();
+
+ vpnInfo.m_useRenegSeconds = m_customRenegotiaInrCheckbox->isChecked();
+ vpnInfo.m_renegSeconds = m_renogotiaInrEdit->text();
+
+ vpnInfo.m_useCompress = m_compressionCheckbox->isChecked();
+ vpnInfo.m_openvpnCompress = (KyCompressMethod2)m_compressionCombox->currentData().toInt();
+
+ vpnInfo.m_useTcpLink = m_tcpConnCheckbox->isChecked();
+
+ vpnInfo.m_setDevType = m_setVDevTypeCheckbox->isChecked();
+ vpnInfo.m_devType = (KyVirtualDeviceType)m_setVDevTypeCombox->currentData().toInt();
+
+ vpnInfo.m_setDevName = m_setVDevNameCheckbox->isChecked();
+ vpnInfo.m_devName = m_setVDevNameEdit->text();
+
+ vpnInfo.m_useTunnelMtu = m_customMtuCheckbox->isChecked();
+ vpnInfo.m_tunnelMtu = m_customMtuEdit->text();
+
+ vpnInfo.m_useFragmentSize = m_customUdpFragSizeCheckbox->isChecked();
+ vpnInfo.m_fragmentSize = m_customUdpFragSizeEdit->text();
+
+ vpnInfo.m_mssfix = m_tcpMssCheckbox->isChecked();
+ vpnInfo.m_remoteRandom = m_randomRemoteHostCheckbox->isChecked();
+ vpnInfo.m_ipv6TunLink = m_ipv6TunLinkCheckbox->isChecked();
+
+ vpnInfo.m_setPingCycle = m_specPingInrCheckbox->isChecked();
+ vpnInfo.m_pingCycle = m_specPingInrEdit->text();
+
+ vpnInfo.m_usePingMethod = m_specExitPingCheckbox->isChecked();
+ vpnInfo.m_pingMethod = (KyVpnPingMethod)m_specExitRestarCombox->currentData().toInt();
+ vpnInfo.m_pingMethodTime = m_specExRePingEdit->text();
+
+ vpnInfo.m_float = m_acceptAuthedPaksCheckbox->isChecked();
+
+ vpnInfo.m_setMaxRoute = m_specMaxRouteCheckbox->isChecked();
+ vpnInfo.m_maxRoute = m_specMaxRouteEdit->text();
+
+
+ //TLS settings
+ vpnInfo.m_checkServerCa = (KyVpnCheckServerMethod)m_serverCertCheckCombox->currentData().toInt();
+ vpnInfo.m_verifyName = m_subjectMatchEdit->text();
+
+ vpnInfo.m_useRemoteCertTls = m_usePreviousCertCheckbox->isChecked();
+ vpnInfo.m_remoteCertType = (KyVpnCertType)m_usePreviousCertCombox->currentData().toInt();
+
+ vpnInfo.m_useNsCertTls = m_verifyPeerCertCheckbox->isChecked();
+ vpnInfo.m_nsCertType = (KyVpnCertType)m_verifyPeerCertCombox->currentData().toInt();
+
+ vpnInfo.m_vpnTlsMode = (KyVpnTlsMode)m_tlsModeCombox->currentData().toInt();
+ vpnInfo.m_vpnKeyFile = m_keyPathEdit->text();
+ vpnInfo.m_vpnTlsTaDir = m_keyDirectionCombox->currentData().toString();
+
+
+ //Proxies
+ vpnInfo.m_vpnProxyType = (KyVpnProxyType)m_proxyTypeCombox->currentData().toInt();
+ vpnInfo.m_vpnProxyServer = m_proxyServerAddEdit->text();
+ vpnInfo.m_vpnProxyPort = m_proxyPortEdit->text();
+ vpnInfo.m_vpnProxyRetry = m_infiniteRetryCheckbox->isChecked();
+ vpnInfo.m_vpnProxyName = m_proxyUsernameEdit->text();
+ vpnInfo.m_vpnProxyPasswd = m_proxyPwdEdit->text();
+
+
+ //Security
+ vpnInfo.m_useKeysize = m_customKeySizeCheckbox->isChecked();
+ vpnInfo.m_keySize = m_customKeySizeEdit->text();
+ vpnInfo.m_hmacAuthMethod = (KyHMACAuthMethod)m_hmacAuthCombox->currentData().toInt();
+
+ qDebug() << LOG_FLAG << "Update open VPN advanced info finished";
+}
+
+void VpnAdvancedPage::updateStrongSwanAdiaInfo(KyVpnConfig &vpnInfo)
+{
+ vpnInfo.m_virtual = m_requestInIPCheckbox->isChecked();
+ vpnInfo.m_encap = m_udpEncapCheckbox->isChecked();
+ vpnInfo.m_ipcomp = m_ipCompCheckbox->isChecked();
+ vpnInfo.m_proposal = m_enablCustomCheckbox->isChecked();
+
+ vpnInfo.m_ike = m_ikeEdit->text();
+ vpnInfo.m_esp = m_espEdit->text();
+
+ qDebug() << LOG_FLAG << "update strong-swan advanced info finished";
+}
+
+void VpnAdvancedPage::setVpnAdvancedPage(const VpnType &type)
+{
+ switch (type) {
+ case L2TP:
+ showL2tpAdiaPage();
+ break;
+ case OPEN_VPN:
+ showOpenVpnAdiaPage();
+ break;
+ case PPTP:
+ showPptpAdiaPage();
+ break;
+ case STRONG_SWAN:
+ showSSwanAdiaPage();
+ break;
+ default:
+ break;
+ }
+}
+
+void VpnAdvancedPage::paintEvent(QPaintEvent *event)
+{
+ if (m_authModeListWidget) {
+ QPalette mpal(m_authModeListWidget->palette());
+ mpal.setColor(QPalette::Base, qApp->palette().base().color());
+ mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color());
+ m_authModeListWidget->setBackgroundRole(QPalette::Base);
+ m_authModeListWidget->setAlternatingRowColors(true);
+ m_authModeListWidget->setPalette(mpal);
+ }
+ if (m_compModeListWidget) {
+ QPalette mpal(m_compModeListWidget->palette());
+ mpal.setColor(QPalette::Base, qApp->palette().base().color());
+ mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color());
+ m_compModeListWidget->setBackgroundRole(QPalette::Base);
+ m_compModeListWidget->setAlternatingRowColors(true);
+ m_compModeListWidget->setPalette(mpal);
+ }
+ if (m_optionsListWidget) {
+ QPalette mpal(m_optionsListWidget->palette());
+ mpal.setColor(QPalette::Base, qApp->palette().base().color());
+ mpal.setColor(QPalette::AlternateBase, qApp->palette().alternateBase().color());
+ m_optionsListWidget->setBackgroundRole(QPalette::Base);
+ m_optionsListWidget->setAlternatingRowColors(true);
+ m_optionsListWidget->setPalette(mpal);
+ }
+}
+
+void VpnAdvancedPage::initUi()
+{
+ m_defaultAdiaFrame = new QFrame(this);
+ m_openVpnAdiaFrame = new QFrame(this);
+ m_sSwanAdiaFrame = new QFrame(this);
+
+ initDefaultAdiaFrame();
+ initOpenVpnAdiaFrame();
+ initSSwanAdiaFrame();
+
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ mainLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ mainLayout->setSpacing(NO_SPACE);
+ mainLayout->addWidget(m_defaultAdiaFrame);
+ mainLayout->addWidget(m_openVpnAdiaFrame);
+ mainLayout->addWidget(m_sSwanAdiaFrame);
+ mainLayout->addSpacing(3);
+ mainLayout->addStretch();
+}
+
+void VpnAdvancedPage::initConnect()
+{
+ connect(m_mppeECheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_mppeECombox->setEnabled(state);
+ m_useStatefulECheckbox->setEnabled(state);
+
+ m_papAuthCheckbox->setEnabled(!state);
+ m_chapAuthCheckbox->setEnabled(!state);
+ m_eapAuthCheckbox->setEnabled(!state);
+ });
+
+ //strong-Swan
+ connect(m_enablCustomCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_ikeEspFrame->setEnabled(state);
+ });
+
+ //open VPN General
+ connect(m_customGatewayPortCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_gatewayPortEdit->setEnabled(state);
+ });
+ connect(m_customRenegotiaInrCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_renogotiaInrEdit->setEnabled(state);
+ });
+ connect(m_compressionCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_compressionCombox->setEnabled(state);
+ });
+ connect(m_compressionCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ if (state == Qt::CheckState::Unchecked) {
+ m_compressionCombox->setCurrentIndex(KYCOMP2_LZODISABLE);
+ }
+ });
+ connect(m_setVDevTypeCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_setVDevTypeCombox->setEnabled(state);
+ });
+ connect(m_setVDevNameCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_setVDevNameEdit->setEnabled(state);
+ });
+ connect(m_customMtuCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_customMtuEdit->setEnabled(state);
+ });
+ connect(m_customUdpFragSizeCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_customUdpFragSizeEdit->setEnabled(state);
+ });
+ connect(m_specPingInrCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_specPingInrEdit->setEnabled(state);
+ });
+ connect(m_specExitPingCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_specExitRestarCombox->setEnabled(state);
+ });
+ connect(m_specExitPingCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_specExRePingEdit->setEnabled(state);
+ });
+ connect(m_specMaxRouteCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_specMaxRouteEdit->setEnabled(state);
+ });
+
+ //open VPN TLS settings
+ connect(m_serverCertCheckCombox, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) {
+ if (index == (int)KYCHECKSERVER_NONE) {
+ m_subjectMatchEdit->setEnabled(false);
+ } else {
+ m_subjectMatchEdit->setEnabled(true);
+ }
+ });
+ connect(m_tlsModeCombox, QOverload::of(&QComboBox::currentIndexChanged),
+ this, &VpnAdvancedPage::onTlsModeComboxIndexChanged);
+ connect(m_usePreviousCertCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_usePreviousCertCombox->setEnabled(state);
+ });
+ connect(m_verifyPeerCertCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_verifyPeerCertCombox->setEnabled(state);
+ });
+ //open VPN proxies
+ connect(m_proxyTypeCombox, QOverload::of(&QComboBox::currentIndexChanged),
+ this, &VpnAdvancedPage::onProxyTypeComboxIndexChanged);
+ //open VPN security
+ connect(m_customKeySizeCheckbox, &QCheckBox::stateChanged, this, [=](int state) {
+ m_customKeySizeEdit->setEnabled(state);
+ });
+
+ connect(m_mruEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_mtuEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_gatewayPortEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_renogotiaInrEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_setVDevNameEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_customMtuEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_customUdpFragSizeEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_specPingInrEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_specExRePingEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_subjectMatchEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_specMaxRouteEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_keyPathEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_proxyServerAddEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_proxyPortEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_proxyUsernameEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_proxyPwdEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_customKeySizeEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_ikeEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_espEdit, &QLineEdit::textChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+
+ connect(m_customGatewayPortCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_customRenegotiaInrCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_setVDevNameCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_customMtuCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_customUdpFragSizeCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_specPingInrCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_specExitPingCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_specMaxRouteCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_customKeySizeCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+ connect(m_enablCustomCheckbox, &QCheckBox::stateChanged, this, &VpnAdvancedPage::setEnableOfConfirmBtn);
+
+ connect(m_serverCertCheckCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn()));
+ connect(m_tlsModeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn()));
+ connect(m_proxyTypeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfConfirmBtn()));
+ connect(m_keyPathChooseBtn, &QPushButton::clicked, this, &VpnAdvancedPage::onKeyPathButtonClicked);
+}
+
+void VpnAdvancedPage::initDefaultAdiaFrame()
+{
+ /**********控件**********/
+ m_mppeECheckbox = new QCheckBox(this);
+ m_useStatefulECheckbox = new QCheckBox(this);
+ m_sendPppEchoPkgCheckbox = new QCheckBox(this);
+ m_authModeLabel = new QLabel(this);
+ m_compModeLabel = new QLabel(this);
+ m_mruLabel = new QLabel(this);
+ m_mtuLabel = new QLabel(this);
+
+ m_mppeECombox = new QComboBox(this);
+ m_authModeListWidget = new QListWidget(this);
+ m_papAuthCheckbox = new QCheckBox(this);
+ m_chapAuthCheckbox = new QCheckBox(this);
+ m_mschapAuthCheckbox = new QCheckBox(this);
+ m_mschap2AuthCheckbox = new QCheckBox(this);
+ m_eapAuthCheckbox = new QCheckBox(this);
+
+ m_compModeListWidget = new QListWidget(this);
+ m_bsdCompModeCheckbox = new QCheckBox(this);
+ m_defaultCompModeCheckbox = new QCheckBox(this);
+ m_tcpCompModeCheckbox = new QCheckBox(this);
+ m_protocolCompModeCheckbox = new QCheckBox(this);
+ m_addressCompModeCheckbox = new QCheckBox(this);
+
+ m_mruFrame = new QFrame(this);
+ m_mruEdit = new QLineEdit(this);
+ m_mtuEdit = new QLineEdit(this);
+
+ m_authModeListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus);
+ m_authModeListWidget->setFrameShape(QFrame::Shape::StyledPanel);
+ addListItem(m_authModeListWidget, m_papAuthCheckbox);
+ addListItem(m_authModeListWidget, m_chapAuthCheckbox);
+ addListItem(m_authModeListWidget, m_mschapAuthCheckbox);
+ addListItem(m_authModeListWidget, m_mschap2AuthCheckbox);
+ addListItem(m_authModeListWidget, m_eapAuthCheckbox);
+
+ m_compModeListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus);
+ m_compModeListWidget->setFrameShape(QFrame::Shape::StyledPanel);
+ addListItem(m_compModeListWidget, m_bsdCompModeCheckbox);
+ addListItem(m_compModeListWidget, m_defaultCompModeCheckbox);
+ addListItem(m_compModeListWidget, m_tcpCompModeCheckbox);
+ addListItem(m_compModeListWidget, m_protocolCompModeCheckbox);
+ addListItem(m_compModeListWidget, m_addressCompModeCheckbox);
+
+ /**********布局**********/
+ QVBoxLayout *defaultAdiaVLayout = new QVBoxLayout(m_defaultAdiaFrame);
+ defaultAdiaVLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ defaultAdiaVLayout->setSpacing(LAYOUT_SPACING_SMALL);
+
+ QFrame *secuFrame= new QFrame(m_defaultAdiaFrame);
+ QFormLayout *secuLayout = new QFormLayout(secuFrame);
+ secuLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ secuLayout->setVerticalSpacing(LAYOUT_SPACING_SMALL);
+ secuLayout->setHorizontalSpacing(HOR_LAYOUT_SPACING);
+ secuLayout->addRow(m_mppeECheckbox, m_mppeECombox);
+ secuLayout->addRow(m_useStatefulECheckbox);
+ secuLayout->addRow(m_sendPppEchoPkgCheckbox);
+ m_mppeECheckbox->setMinimumWidth(MIN_LABEL_WIDTH);
+
+ QHBoxLayout *mruHLayout = new QHBoxLayout(m_mruFrame);
+ mruHLayout->setContentsMargins(0, 16, 0, 0);
+ mruHLayout->setSpacing(HOR_LAYOUT_SPACING);
+ mruHLayout->addWidget(m_mruLabel);
+ mruHLayout->addWidget(m_mruEdit);
+ mruHLayout->addStretch();
+ mruHLayout->addWidget(m_mtuLabel);
+ mruHLayout->addWidget(m_mtuEdit);
+ m_mruEdit->setFixedWidth(MIN_EDIT_WIDTH);
+ m_mtuEdit->setFixedWidth(MIN_EDIT_WIDTH);
+
+ defaultAdiaVLayout->addWidget(secuFrame);
+ defaultAdiaVLayout->addSpacing(4);
+ defaultAdiaVLayout->addWidget(m_authModeLabel);
+ defaultAdiaVLayout->addWidget(m_authModeListWidget);
+ defaultAdiaVLayout->addSpacing(LAYOUT_ADD_SPACING);
+ defaultAdiaVLayout->addWidget(m_compModeLabel);
+ defaultAdiaVLayout->addWidget(m_compModeListWidget);
+ defaultAdiaVLayout->addWidget(m_mruFrame);
+ m_authModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT);
+ m_compModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT);
+
+ /**********控件显示**********/
+ m_mppeECheckbox->setText(tr("MPPE encryption algorithm:")); //MPPE加密算法:
+ m_useStatefulECheckbox->setText(tr("Use Stateful encryption")); //使用有状态加密
+ m_sendPppEchoPkgCheckbox->setText(tr("Send PPP echo packets")); //发送PPP回显包
+ m_authModeLabel->setText(tr("Authentication Mode:")); //认证方式:
+ m_papAuthCheckbox->setText(tr("PAP authentication")); //PAP认证
+ m_chapAuthCheckbox->setText(tr("CHAP authentication")); //CHAP认证
+ m_mschapAuthCheckbox->setText(tr("MSCHAP authentication")); //MSCHAP认证
+ m_mschap2AuthCheckbox->setText(tr("MSCHAP2 authentication")); //MSCHAP2认证
+ m_eapAuthCheckbox->setText(tr("EAP authentication")); //EAP认证
+ m_compModeLabel->setText(tr("Compression Mode:")); //压缩方式:
+ m_bsdCompModeCheckbox->setText(tr("Allow BSD data compression")); //允许BSD压缩
+ m_defaultCompModeCheckbox->setText(tr("Allow Default data compression")); //允许Default压缩
+ m_tcpCompModeCheckbox->setText(tr("Allow TCP header compression")); //允许TCP头压缩
+ m_protocolCompModeCheckbox->setText(tr("Use protocol field compression negotiation")); //使用协议域压缩协商
+ m_addressCompModeCheckbox->setText(tr("Use Address/Control compression")); //使用地址/控制压缩
+ m_mruLabel->setText("MRU");
+ m_mtuLabel->setText("MTU");
+ m_mruEdit->setText("0");
+ m_mtuEdit->setText("0");
+
+ m_mppeECombox->addItem(tr("All Available"), KYMPPE_DEFAULT); //任意
+ m_mppeECombox->addItem(tr("128-bit"), KYMPPE_REQUIRE128); //128位
+ m_mppeECombox->addItem(tr("40-bit"), KYMPPE_REQUIRE40); //40位
+
+ //控件输入格式限制
+ QRegExp rxNumber("^[0-9]+$");
+ m_mruEdit->setValidator(new QRegExpValidator(rxNumber, this));
+ m_mtuEdit->setValidator(new QRegExpValidator(rxNumber, this));
+ m_mruEdit->setMaxLength(MAX_MRU_LENGTH);
+ m_mtuEdit->setMaxLength(MAX_MRU_LENGTH);
+}
+
+void VpnAdvancedPage::initOpenVpnAdiaFrame()
+{
+ /**********控件**********/
+ //General
+ QLabel *generalLabel = new QLabel(m_openVpnAdiaFrame);
+ m_customGatewayPortCheckbox = new QCheckBox(this);
+ m_customRenegotiaInrCheckbox = new QCheckBox(this);
+ m_compressionCheckbox = new QCheckBox(this);
+ m_tcpConnCheckbox = new QCheckBox(this);
+ m_setVDevTypeCheckbox = new QCheckBox(this);
+ m_setVDevNameCheckbox = new QCheckBox(this);
+ m_customMtuCheckbox = new QCheckBox(this);
+ m_customUdpFragSizeCheckbox = new QCheckBox(this);
+ m_tcpMssCheckbox = new QCheckBox(this);
+ m_randomRemoteHostCheckbox = new QCheckBox(this);
+ m_ipv6TunLinkCheckbox = new QCheckBox(this);
+ m_specPingInrCheckbox = new QCheckBox(this);
+ m_specExitPingCheckbox = new QCheckBox(this);
+ m_acceptAuthedPaksCheckbox = new QCheckBox(this);
+ m_specMaxRouteCheckbox = new QCheckBox(this);
+
+ m_gatewayPortEdit = new QLineEdit(this);
+ m_renogotiaInrEdit = new QLineEdit(this);
+ m_setVDevNameEdit = new QLineEdit(this);
+ m_customMtuEdit = new QLineEdit(this);
+ m_customUdpFragSizeEdit = new QLineEdit(this);
+ m_specPingInrEdit = new QLineEdit(this);
+ m_specExRePingEdit = new QLineEdit(this);
+ m_specMaxRouteEdit = new QLineEdit(this);
+ m_compressionCombox = new QComboBox(this);
+ m_setVDevTypeCombox = new QComboBox(this);
+ m_specExitRestarCombox = new QComboBox(this);
+ m_customRenoInrLabel = new FixLabel(this);
+ m_customMtuLabel = new FixLabel(this);
+ m_acceptAuthedPaksLabel = new FixLabel(this);
+ m_customUdpLabel = new FixLabel(this);
+
+ //TLS settings
+ QLabel *tlsSettingLabel = new QLabel(m_openVpnAdiaFrame);
+ QLabel *serverCertCheckLabel = new QLabel(m_openVpnAdiaFrame);
+ QLabel *tlsModeLabel = new QLabel(m_openVpnAdiaFrame);
+
+ FixLabel *usePreviousCertLabel = new FixLabel(m_openVpnAdiaFrame);
+ FixLabel *verifyPeerCertLabel = new FixLabel(m_openVpnAdiaFrame);
+
+ m_subjectMatchLabel = new QLabel(this);
+ m_keyPathLabel = new QLabel(this);
+ m_keyDirectionLabel = new QLabel(this);
+ m_subjectMatchEdit = new QLineEdit(this);
+ m_keyPathEdit = new QLineEdit(this);
+ m_keyPathChooseBtn = new QPushButton(this);
+ m_usePreviousCertCheckbox = new QCheckBox(this);
+ m_verifyPeerCertCheckbox = new QCheckBox(this);
+ m_serverCertCheckCombox = new QComboBox(this);
+ m_usePreviousCertCombox = new QComboBox(this);
+ m_verifyPeerCertCombox = new QComboBox(this);
+ m_tlsModeCombox = new QComboBox(this);
+ m_keyDirectionCombox = new QComboBox(this);
+
+ //Proxies
+ QLabel *proxiesLabel = new QLabel(m_openVpnAdiaFrame);
+ QLabel *proxyTypeLabel = new QLabel(m_openVpnAdiaFrame);
+ m_proxyServerAddLabel = new QLabel(this);
+ m_proxyPortLabel = new QLabel(this);
+ m_proxyUsernameLabel = new QLabel(this);
+ m_proxyPwdLabel = new QLabel(this);
+ m_proxyTypeCombox = new QComboBox(this);
+ m_infiniteRetryCheckbox = new QCheckBox(this);
+ m_proxyServerAddEdit = new QLineEdit(this);
+ m_proxyPortEdit = new QLineEdit(this);
+ m_proxyUsernameEdit = new QLineEdit(this);
+ m_proxyPwdEdit = new KPasswordEdit(this);
+ m_proxyPwdEdit->setClearButtonEnabled(false);
+
+ //Security
+ QLabel *securityLabel = new QLabel(m_openVpnAdiaFrame);
+ QLabel *hmacLabel = new QLabel(m_openVpnAdiaFrame);
+ m_customKeySizeCheckbox = new QCheckBox(this);
+ m_customKeySizeEdit = new QLineEdit(this);
+ m_hmacAuthCombox = new QComboBox(this);
+
+
+ /**********布局**********/
+ QVBoxLayout *openVpnAdiaVLayout = new QVBoxLayout(m_openVpnAdiaFrame);
+ openVpnAdiaVLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+
+ //General
+ QFrame *generalFrame = new QFrame(m_openVpnAdiaFrame);
+ QFormLayout *generalLayout = new QFormLayout(generalFrame);
+
+ QWidget *customRenoInrWidget = new QWidget(this);
+ initCheckWidget(m_customRenegotiaInrCheckbox, m_customRenoInrLabel, customRenoInrWidget);
+
+ QWidget *customMtuWidget = new QWidget(this);
+ initCheckWidget(m_customMtuCheckbox, m_customMtuLabel, customMtuWidget);
+
+ QWidget *customUdpWidget = new QWidget(this);
+ initCheckWidget(m_customUdpFragSizeCheckbox, m_customUdpLabel, customUdpWidget);
+
+ QWidget *acceptAuthWidget = new QWidget(this);
+ initCheckWidget(m_acceptAuthedPaksCheckbox, m_acceptAuthedPaksLabel, acceptAuthWidget);
+
+ QWidget *exitRestarWidget = new QWidget(this);
+ QHBoxLayout *exitRestarLayout = new QHBoxLayout(exitRestarWidget);
+ exitRestarLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ exitRestarLayout->addWidget(m_specExitRestarCombox);
+ exitRestarLayout->addWidget(m_specExRePingEdit);
+
+ generalLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ generalLayout->addRow(m_customGatewayPortCheckbox, m_gatewayPortEdit);
+ generalLayout->addRow(customRenoInrWidget, m_renogotiaInrEdit);
+ generalLayout->addRow(m_compressionCheckbox, m_compressionCombox);
+ generalLayout->addRow(m_tcpConnCheckbox);
+ generalLayout->addRow(m_setVDevTypeCheckbox, m_setVDevTypeCombox);
+ generalLayout->addRow(m_setVDevNameCheckbox, m_setVDevNameEdit);
+ generalLayout->addRow(customMtuWidget, m_customMtuEdit);
+ generalLayout->addRow(customUdpWidget, m_customUdpFragSizeEdit);
+ generalLayout->addRow(m_tcpMssCheckbox);
+ generalLayout->addRow(m_randomRemoteHostCheckbox);
+ generalLayout->addRow(m_ipv6TunLinkCheckbox);
+ generalLayout->addRow(m_specPingInrCheckbox, m_specPingInrEdit);
+ generalLayout->addRow(m_specExitPingCheckbox, exitRestarWidget);
+ generalLayout->addRow(acceptAuthWidget);
+ generalLayout->addRow(m_specMaxRouteCheckbox, m_specMaxRouteEdit);
+
+ //TLS settings
+ QFrame *tlsSettingsFrame = new QFrame(m_openVpnAdiaFrame);
+ QFormLayout *tlsLayout = new QFormLayout(tlsSettingsFrame);
+
+ QWidget *usePreviousCertWidget = new QWidget(this);
+ initCheckWidget(m_usePreviousCertCheckbox, usePreviousCertLabel, usePreviousCertWidget);
+
+ QWidget *verifyPeerCertWidget = new QWidget(this);
+ initCheckWidget(m_verifyPeerCertCheckbox, verifyPeerCertLabel, verifyPeerCertWidget);
+
+ QWidget *keyfileWidget = new QWidget(this);
+ QGridLayout *keyfileLayout = new QGridLayout(keyfileWidget);
+ keyfileLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ keyfileLayout->addWidget(m_keyPathLabel, 0, 0);
+ keyfileLayout->addWidget(m_keyPathEdit, 0, 1);
+ keyfileLayout->addWidget(m_keyPathChooseBtn, 0, 2);
+ keyfileLayout->addWidget(m_keyDirectionLabel, 1, 0);
+ keyfileLayout->addWidget(m_keyDirectionCombox, 1, 1, 1, 2);
+ m_keyDirectionLabel->setMinimumWidth(MIN_LABEL_WIDTH);
+
+ tlsLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ tlsLayout->addRow(serverCertCheckLabel, m_serverCertCheckCombox);
+ tlsLayout->addRow(m_subjectMatchLabel, m_subjectMatchEdit);
+ tlsLayout->addRow(usePreviousCertWidget, m_usePreviousCertCombox);
+ tlsLayout->addRow(verifyPeerCertWidget, m_verifyPeerCertCombox);
+ tlsLayout->addRow(tlsModeLabel, m_tlsModeCombox);
+ tlsLayout->addRow(keyfileWidget);
+
+ //Proxies
+ QFrame *proxiesFrame = new QFrame(m_openVpnAdiaFrame);
+ QFormLayout *proxiesLayout = new QFormLayout(proxiesFrame);
+ proxiesLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ proxiesLayout->addRow(proxyTypeLabel, m_proxyTypeCombox);
+ proxiesLayout->addRow(m_proxyServerAddLabel, m_proxyServerAddEdit);
+ proxiesLayout->addRow(m_proxyPortLabel, m_proxyPortEdit);
+ proxiesLayout->addRow(nullptr, m_infiniteRetryCheckbox);
+ proxiesLayout->addRow(m_proxyUsernameLabel, m_proxyUsernameEdit);
+ proxiesLayout->addRow(m_proxyPwdLabel, m_proxyPwdEdit);
+ m_proxyUsernameLabel->setMinimumWidth(MIN_LABEL_WIDTH);
+
+ //Security
+ QFrame *securityFrame = new QFrame(m_openVpnAdiaFrame);
+ QFormLayout *securityLayout = new QFormLayout(securityFrame);
+ securityLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ securityLayout->addRow(m_customKeySizeCheckbox, m_customKeySizeEdit);
+ securityLayout->addRow(hmacLabel, m_hmacAuthCombox);
+
+ //all
+ openVpnAdiaVLayout->setSpacing(LAYOUT_SPACING_SMALL);
+ openVpnAdiaVLayout->addWidget(generalLabel);
+ openVpnAdiaVLayout->addWidget(generalFrame);
+ openVpnAdiaVLayout->addSpacing(VLAYOUT_ADD_SPACING);
+ openVpnAdiaVLayout->addWidget(tlsSettingLabel);
+ openVpnAdiaVLayout->addWidget(tlsSettingsFrame);
+ openVpnAdiaVLayout->addSpacing(VLAYOUT_ADD_SPACING);
+ openVpnAdiaVLayout->addWidget(proxiesLabel);
+ openVpnAdiaVLayout->addWidget(proxiesFrame);
+ openVpnAdiaVLayout->addSpacing(VLAYOUT_ADD_SPACING);
+ openVpnAdiaVLayout->addWidget(securityLabel);
+ openVpnAdiaVLayout->addWidget(securityFrame);
+
+ /**********控件显示**********/
+ m_customGatewayPortCheckbox->setText(tr("Use custom gateway port")); //使用自定义网关端口
+ m_compressionCheckbox->setText(tr("Use compression")); //使用压缩
+ m_tcpConnCheckbox->setText(tr("Use a TCP connection")); //使用TCP连接
+ m_setVDevTypeCheckbox->setText(tr("Set virtual device type")); //设置虚拟设备类型
+ m_setVDevNameCheckbox->setText(tr("Set virtual device name")); //设置虚拟设备名称
+ m_tcpMssCheckbox->setText(tr("Limit TCP Maximum Segment Size(MSS)")); //限制TCP最大段尺寸(MSS)
+ m_randomRemoteHostCheckbox->setText(tr("Randomize remote hosts")); //随机化远程主机
+ m_ipv6TunLinkCheckbox->setText(tr("IPv6 tun link")); //IPv6 tun连接
+ m_specPingInrCheckbox->setText(tr("Specify ping interval")); //指定ping周期
+ m_specExitPingCheckbox->setText(tr("Specify exit or restart ping")); //指定退出或重启的Ping
+ m_specMaxRouteCheckbox->setText(tr("Specify max routes")); //指定路由上限
+ m_infiniteRetryCheckbox->setText(tr("Infinite retry on error")); //出错时无限重试
+ m_customKeySizeCheckbox->setText(tr("Use custom key size")); //使用自定义密钥大小
+ m_keyPathChooseBtn->setText(tr("Choose")); //选择
+
+ m_customRenoInrLabel->setFixedWidth(MAX_LABEL_WIDTH);
+ m_customRenoInrLabel->setLabelText(tr("Use custom renegotiation interval")); //使用自定义重协商间隔
+ m_customMtuLabel->setFixedWidth(MAX_LABEL_WIDTH);
+ m_customMtuLabel->setLabelText(tr("Use custom tunnel Maximum Transmission Umit(MTU)")); //使用自定义隧道最大单元传输(MTU)
+ m_customUdpLabel->setFixedWidth(MAX_LABEL_WIDTH);
+ m_customUdpLabel->setLabelText(tr("Use custom UDP fragment size")); //使用自定义UDP分片大小
+ m_acceptAuthedPaksLabel->setFixedWidth(440);//文本显示宽度
+ m_acceptAuthedPaksLabel->setLabelText(tr("Accept authenticated packets from any address (Float)")); //接受来自任何地址(Float)已通过身份验证的数据包
+
+ m_subjectMatchLabel->setText(tr("Subject Match")); //主题匹配
+ m_keyPathLabel->setText(tr("Key File")); //密钥文件
+ m_keyDirectionLabel->setText(tr("Key Direction")); //密钥方向
+
+ m_proxyServerAddLabel->setText(tr("Server Address")); //服务器地址
+ m_proxyPortLabel->setText(tr("Port")); //端口
+ m_proxyUsernameLabel->setText(tr("Proxy USername")); //代理用户名
+ m_proxyPwdLabel->setText(tr("Proxy Password")); //代理密码
+
+ generalLabel->setText(tr("General")); //常规
+ tlsSettingLabel->setText(tr("TLS settings"));
+ serverCertCheckLabel->setText(tr("Server Certificate Check")); //服务器证书检验
+ usePreviousCertLabel->setFixedWidth(MAX_LABEL_WIDTH);
+ usePreviousCertLabel->setLabelText(tr("Use the previous authentication end (server) certificate")); //使用前面验证端(服务器)证书
+ verifyPeerCertLabel->setFixedWidth(MAX_LABEL_WIDTH);
+ verifyPeerCertLabel->setLabelText(tr("Verify peer (server) certificate nsCertType specification")); //验证对等点(服务器)证书nsCertType指定
+ tlsModeLabel->setText(tr("Mode"));
+ proxiesLabel->setText(tr("Proxies"));
+ proxyTypeLabel->setText(tr("Proxy Type"));
+ securityLabel->setText(tr("Security"));
+ hmacLabel->setText(tr("HMAC Authentication")); //HMAC认证
+ hmacLabel->setFixedWidth(268); //调整控件对齐=MAX_LABEL_WIDTH+28
+
+ QFont font = generalLabel->font();
+ font.setWeight(QFont::Weight::Medium);
+ generalLabel->setFont(font);
+ tlsSettingLabel->setFont(font);
+ proxiesLabel->setFont(font);
+ securityLabel->setFont(font);
+
+ m_setVDevNameEdit->setPlaceholderText(tr("Input content")); //输入内容
+
+ m_compressionCombox->addItem(tr("No"), KYCOMP2_LZODISABLE); //否
+ m_compressionCombox->addItem("LZO", KYCOMP2_LZO);
+ m_compressionCombox->addItem("LZ4", KYCOMP2_LZ4);
+ m_compressionCombox->addItem("LZ4 v2", KYCOMP2_LZ4V2);
+ m_compressionCombox->addItem(tr("Self-adaption"), KYCOMP2_LZOADAPTIVE); //自适应
+ m_compressionCombox->addItem(tr("Automatic"), KYCOMP2_AUTO); //自动
+
+ m_setVDevTypeCombox->addItem("TUN", KYVIRDEVTYPE_TUN);
+ m_setVDevTypeCombox->addItem("TAP", KYVIRDEVTYPE_TAP);
+
+ m_specExitRestarCombox->addItem(tr("Exit"), KYVPNPING_EXIT); //退出
+ m_specExitRestarCombox->addItem(tr("Restart"), KYVPNPING_RESTART); //重启
+
+ m_serverCertCheckCombox->addItem(tr("Don't verify certificate identification"), KYCHECKSERVER_NONE); //不验证证书标识
+ m_serverCertCheckCombox->addItem(tr("Verify the entire subject exactly"), KYCHECKSERVER_ENTIRETHEME); //确切地验证整个主题
+ m_serverCertCheckCombox->addItem(tr("Verify name exactly"), KYCHECKSERVER_ENTIRENAME); //精确验证名称
+ m_serverCertCheckCombox->addItem(tr("Verify name by prefix"), KYCHECKSERVER_PRENAME); //按前缀验证名称
+
+ m_usePreviousCertCombox->addItem(tr("Server"), KYVPNCERT_SERVER);
+ m_usePreviousCertCombox->addItem(tr("Client"), KYVPNCERT_CLIENT);
+
+ m_verifyPeerCertCombox->addItem(tr("Server"), KYVPNCERT_SERVER);
+ m_verifyPeerCertCombox->addItem(tr("Client"), KYVPNCERT_CLIENT);
+
+ m_tlsModeCombox->addItem(tr("None"), NONE); //无
+ m_tlsModeCombox->addItem(tr("TLS-Certification"), TLS_CERT); //TLS-认证
+ m_tlsModeCombox->addItem(tr("TLS-Encryption"), TLS_ENCRYPTION); //TLS-加密
+
+ m_keyDirectionCombox->addItem(tr("None"), KEY_DIRECTION_NONE); //无
+ m_keyDirectionCombox->addItem("0", KEY_DIRECTION_ZERO);
+ m_keyDirectionCombox->addItem("1", KEY_DIRECTION_ONE);
+
+ m_proxyTypeCombox->addItem(tr("Not Required"), NO); //不需要
+ m_proxyTypeCombox->addItem("HTTP", HTTP);
+ m_proxyTypeCombox->addItem("SOCKS", SOCKS);
+
+ m_hmacAuthCombox->addItem(tr("Default"), KYHMACAUTH_DEFAULT); //默认
+ m_hmacAuthCombox->addItem(tr("None"), KYHMACAUTH_NONE); //无
+ m_hmacAuthCombox->addItem("MD-4", KYHMACAUTH_MD4);
+ m_hmacAuthCombox->addItem("MD-5", KYHMACAUTH_MD5);
+ m_hmacAuthCombox->addItem("SHA-1", KYHMACAUTH_SHA1);
+ m_hmacAuthCombox->addItem("SHA-224", KYHMACAUTH_SHA224);
+ m_hmacAuthCombox->addItem("SHA-256", KYHMACAUTH_SHA256);
+ m_hmacAuthCombox->addItem("SHA-384", KYHMACAUTH_SHA384);
+ m_hmacAuthCombox->addItem("SHA-512", KYHMACAUTH_SHA512);
+ m_hmacAuthCombox->addItem("RIPEMD-160", KYHMACAUTH_RIPEMD160);
+
+ //控件输入格式限制
+ QRegExp rxNumber("^[0-9]+$");
+ m_gatewayPortEdit->setValidator(new QRegExpValidator(rxNumber, this));
+ m_renogotiaInrEdit->setValidator(new QRegExpValidator(rxNumber, this));
+ m_customMtuEdit->setValidator(new QRegExpValidator(rxNumber, this));
+ m_customUdpFragSizeEdit->setValidator(new QRegExpValidator(rxNumber, this));
+ m_specPingInrEdit->setValidator(new QRegExpValidator(rxNumber, this));
+ m_specExRePingEdit->setValidator(new QRegExpValidator(rxNumber, this));
+ m_specMaxRouteEdit->setValidator(new QRegExpValidator(rxNumber, this));
+
+ // IP的正则格式限制
+ QRegExp rxIp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
+ m_proxyServerAddEdit->setValidator(new QRegExpValidator(rxIp, this));
+
+ //default
+ m_gatewayPortEdit->setText("1194");
+ m_renogotiaInrEdit->setText("0");
+ m_customMtuEdit->setText("1500");
+ m_customUdpFragSizeEdit->setText("1500");
+ m_specPingInrEdit->setText("30");
+ m_specExRePingEdit->setText("30");
+ m_specMaxRouteEdit->setText("30");
+ if (m_serverCertCheckCombox->currentData().toInt() == (int)KYCHECKSERVER_NONE) {
+ m_subjectMatchEdit->setEnabled(false);
+ } else {
+ m_subjectMatchEdit->setEnabled(true);
+ }
+ onTlsModeComboxIndexChanged();
+ onProxyTypeComboxIndexChanged();
+}
+
+void VpnAdvancedPage::initSSwanAdiaFrame()
+{
+ /**********控件**********/
+ QLabel *optionsLabel = new QLabel(this);
+ QLabel *ikeLabel = new QLabel(this);
+ QLabel *espLabel = new QLabel(this);
+ m_optionsListWidget = new QListWidget(this);
+ m_requestInIPCheckbox = new QCheckBox(this);
+ m_udpEncapCheckbox = new QCheckBox(this);
+ m_ipCompCheckbox = new QCheckBox(this);
+ m_enablCustomCheckbox = new QCheckBox(this);
+ m_ikeEdit = new QLineEdit(this);
+ m_espEdit = new QLineEdit(this);
+ m_ikeEspFrame = new QFrame(m_sSwanAdiaFrame);
+
+ /**********布局**********/
+ QVBoxLayout *sSwanAdiaVLayout = new QVBoxLayout(m_sSwanAdiaFrame);
+ sSwanAdiaVLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ sSwanAdiaVLayout->setSpacing(LAYOUT_SPACING_SMALL);
+
+ QFormLayout *ikeEspFrameLayout = new QFormLayout(m_ikeEspFrame);
+ ikeEspFrameLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ ikeEspFrameLayout->setHorizontalSpacing(HOR_LAYOUT_SPACING);
+ ikeEspFrameLayout->setVerticalSpacing(LAYOUT_ADD_SPACING);
+ ikeEspFrameLayout->addRow(ikeLabel, m_ikeEdit);
+ ikeEspFrameLayout->addRow(espLabel, m_espEdit);
+
+ sSwanAdiaVLayout->addWidget(optionsLabel);
+ sSwanAdiaVLayout->addWidget(m_optionsListWidget);
+ sSwanAdiaVLayout->addSpacing(LAYOUT_ADD_SPACING);
+ sSwanAdiaVLayout->addWidget(m_enablCustomCheckbox);
+ sSwanAdiaVLayout->addWidget(m_ikeEspFrame);
+ sSwanAdiaVLayout->addStretch();
+ m_optionsListWidget->setFixedHeight(LISTWIDGET_HEIGHT_SMALL);
+
+ /**********控件显示**********/
+ optionsLabel->setText(tr("Options:")); //选项:
+ ikeLabel->setText("IKE");
+ espLabel->setText("ESP");
+ m_requestInIPCheckbox->setText(tr("Request an inner IP address")); //请求内部IP地址
+ m_udpEncapCheckbox->setText(tr("Enforce UDP encapsulation")); //强制UDP封装
+ m_ipCompCheckbox->setText(tr("Use IP compression")); //使用IP压缩
+ m_enablCustomCheckbox->setText(tr("Enable custom password suggestions")); //启用自定义密码建议
+
+ m_optionsListWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus);
+ m_optionsListWidget->setFrameShape(QFrame::Shape::StyledPanel);
+ addListItem(m_optionsListWidget, m_requestInIPCheckbox);
+ addListItem(m_optionsListWidget, m_udpEncapCheckbox);
+ addListItem(m_optionsListWidget, m_ipCompCheckbox);
+
+ //strong-Swan default
+ m_enablCustomCheckbox->setChecked(false);
+ m_ikeEspFrame->setEnabled(false);
+}
+
+void VpnAdvancedPage::initDefalutCheckState()
+{
+ m_mppeECheckbox->setChecked(false);
+ m_mppeECombox->setEnabled(m_mppeECheckbox->isChecked());
+
+ //openVPN
+ m_customGatewayPortCheckbox->setChecked(true);
+ m_customRenegotiaInrCheckbox->setChecked(true);
+ m_compressionCheckbox->setChecked(true);
+ m_tcpConnCheckbox->setChecked(true);
+ m_setVDevTypeCheckbox->setChecked(true);
+ m_setVDevNameCheckbox->setChecked(true);
+ m_customMtuCheckbox->setChecked(true);
+ m_customUdpFragSizeCheckbox->setChecked(true);
+ m_tcpMssCheckbox->setChecked(true);
+ m_randomRemoteHostCheckbox->setChecked(true);
+ m_ipv6TunLinkCheckbox->setChecked(true);
+ m_specPingInrCheckbox->setChecked(true);
+ m_specExitPingCheckbox->setChecked(true);
+ m_acceptAuthedPaksCheckbox->setChecked(true);
+ m_specMaxRouteCheckbox->setChecked(true);
+
+ m_gatewayPortEdit->setEnabled(m_customGatewayPortCheckbox->isChecked());
+ m_renogotiaInrEdit->setEnabled(m_customRenegotiaInrCheckbox->isChecked());
+ m_setVDevNameEdit->setEnabled(m_setVDevNameCheckbox->isChecked());
+ m_customMtuEdit->setEnabled(m_customMtuCheckbox->isChecked());
+ m_customUdpFragSizeEdit->setEnabled(m_customUdpFragSizeCheckbox->isChecked());
+ m_specPingInrEdit->setEnabled(m_specPingInrCheckbox->isChecked());
+ m_specExRePingEdit->setEnabled(m_specExitPingCheckbox->isChecked());
+ m_specMaxRouteEdit->setEnabled(m_specMaxRouteCheckbox->isChecked());
+ m_compressionCombox->setEnabled(m_compressionCheckbox->isChecked());
+ m_setVDevTypeCombox->setEnabled(m_setVDevTypeCheckbox->isChecked());
+ m_specExitRestarCombox->setEnabled(m_specExitPingCheckbox->isChecked());
+
+ m_usePreviousCertCombox->setEnabled(m_usePreviousCertCheckbox->isChecked());
+ m_verifyPeerCertCombox->setEnabled(m_verifyPeerCertCheckbox->isChecked());
+
+ m_customKeySizeEdit->setEnabled(m_customKeySizeCheckbox->isChecked());
+}
+
+void VpnAdvancedPage::addListItem(QListWidget *listWidget, QWidget *widget)
+{
+ QListWidgetItem *listWidgetItem = new QListWidgetItem(listWidget);
+ QWidget *itemWidget = new QWidget(listWidget);
+ QHBoxLayout *hLayout = new QHBoxLayout(itemWidget);
+ hLayout->setContentsMargins(16, 0, 0, 0);
+ hLayout->addWidget(widget);
+ listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT));
+ listWidgetItem->setFlags(Qt::NoItemFlags);
+ listWidget->addItem(listWidgetItem);
+ listWidget->setItemWidget(listWidgetItem, itemWidget);
+}
+
+void VpnAdvancedPage::initCheckWidget(QCheckBox *checkBox, FixLabel *label, QWidget *widget)
+{
+ QHBoxLayout *hLayout = new QHBoxLayout(widget);
+ hLayout->setContentsMargins(NO_LAYOUT_MARGINS);
+ hLayout->setSpacing(4);
+ hLayout->addWidget(checkBox);
+ hLayout->addWidget(label);
+ hLayout->addStretch();
+}
+
+void VpnAdvancedPage::onProxyTypeComboxIndexChanged()
+{
+ switch (m_proxyTypeCombox->currentData().toInt()) {
+ case NO:
+ m_proxyServerAddEdit->clear();
+ m_proxyPortEdit->clear();
+ m_proxyUsernameEdit->clear();
+ m_proxyPwdEdit->clear();
+ m_infiniteRetryCheckbox->setChecked(false);
+
+ m_proxyServerAddLabel->setEnabled(false);
+ m_proxyPortLabel->setEnabled(false);
+ m_proxyUsernameLabel->setEnabled(false);
+ m_proxyPwdLabel->setEnabled(false);
+ m_infiniteRetryCheckbox->setEnabled(false);
+ m_proxyServerAddEdit->setEnabled(false);
+ m_proxyPortEdit->setEnabled(false);
+ m_proxyUsernameEdit->setEnabled(false);
+ m_proxyPwdEdit->setEnabled(false);
+ break;
+ case HTTP:
+ m_proxyServerAddLabel->setEnabled(true);
+ m_proxyPortLabel->setEnabled(true);
+ m_proxyUsernameLabel->setEnabled(true);
+ m_proxyPwdLabel->setEnabled(true);
+ m_infiniteRetryCheckbox->setEnabled(true);
+ m_proxyServerAddEdit->setEnabled(true);
+ m_proxyPortEdit->setEnabled(true);
+ m_proxyUsernameEdit->setEnabled(true);
+ m_proxyPwdEdit->setEnabled(true);
+ break;
+ case SOCKS:
+ m_proxyServerAddLabel->setEnabled(true);
+ m_proxyPortLabel->setEnabled(true);
+ m_infiniteRetryCheckbox->setEnabled(true);
+ m_proxyServerAddEdit->setEnabled(true);
+ m_proxyPortEdit->setEnabled(true);
+ m_proxyUsernameLabel->setEnabled(false);
+ m_proxyPwdLabel->setEnabled(false);
+ m_proxyUsernameEdit->setEnabled(false);
+ m_proxyPwdEdit->setEnabled(false);
+ break;
+ default:
+ break;
+ }
+}
+
+void VpnAdvancedPage::onTlsModeComboxIndexChanged()
+{
+ switch (m_tlsModeCombox->currentData().toInt()) {
+ case NONE:
+ m_keyPathLabel->setEnabled(false);
+ m_keyPathEdit->setEnabled(false);
+ m_keyPathChooseBtn->setEnabled(false);
+ m_keyDirectionLabel->setEnabled(false);
+ m_keyDirectionCombox->setEnabled(false);
+ break;
+ case TLS_CERT:
+ m_keyPathLabel->setEnabled(true);
+ m_keyPathEdit->setEnabled(true);
+ m_keyPathChooseBtn->setEnabled(true);
+ m_keyDirectionLabel->setEnabled(true);
+ m_keyDirectionCombox->setEnabled(true);
+ break;
+ case TLS_ENCRYPTION:
+ m_keyPathLabel->setEnabled(true);
+ m_keyPathEdit->setEnabled(true);
+ m_keyPathChooseBtn->setEnabled(true);
+ m_keyDirectionLabel->setEnabled(false);
+ m_keyDirectionCombox->setEnabled(false);
+ break;
+ default:
+ break;
+ }
+}
+
+void VpnAdvancedPage::setEnableOfConfirmBtn()
+{
+ Q_EMIT setAdvancedPageState(checkConfirmBtnIsEnabled());
+}
+
+void VpnAdvancedPage::onKeyPathButtonClicked()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Choose a private key"),
+ "recent:///",
+ tr("Key Files (*.key *.pem *.der *.p12 *.pfx)"));
+ if (!fileName.isNull()) {
+ m_keyPathEdit->blockSignals(true);
+ m_keyPathEdit->setText(fileName);
+ m_keyPathEdit->blockSignals(false);
+ }
+}
+
+void VpnAdvancedPage::showL2tpAdiaPage()
+{
+ m_defaultAdiaFrame->setHidden(false);
+ m_mruFrame->setHidden(false);
+ m_compModeListWidget->item(COMP_MODE_PROTOCOL)->setHidden(false);
+ m_compModeListWidget->item(COMP_MODE_ADDRESS)->setHidden(false);
+ m_compModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT);
+
+ m_openVpnAdiaFrame->setHidden(true);
+ m_sSwanAdiaFrame->setHidden(true);
+}
+
+void VpnAdvancedPage::showPptpAdiaPage()
+{
+ m_defaultAdiaFrame->setHidden(false);
+ m_compModeListWidget->item(COMP_MODE_PROTOCOL)->setHidden(true);
+ m_compModeListWidget->item(COMP_MODE_ADDRESS)->setHidden(true);
+ m_compModeListWidget->setFixedHeight(LISTWIDGET_HEIGHT_SMALL);
+
+ m_mruFrame->setHidden(true);
+ m_openVpnAdiaFrame->setHidden(true);
+ m_sSwanAdiaFrame->setHidden(true);
+}
+
+void VpnAdvancedPage::showOpenVpnAdiaPage()
+{
+ m_openVpnAdiaFrame->setHidden(false);
+
+ m_defaultAdiaFrame->setHidden(true);
+ m_mruFrame->setHidden(true);
+ m_sSwanAdiaFrame->setHidden(true);
+}
+
+void VpnAdvancedPage::showSSwanAdiaPage()
+{
+ m_sSwanAdiaFrame->setHidden(false);
+
+ m_defaultAdiaFrame->setHidden(true);
+ m_mruFrame->setHidden(true);
+ m_openVpnAdiaFrame->setHidden(true);
+}
+
+bool VpnAdvancedPage::checkConfirmBtnIsEnabled()
+{
+ //L2TP
+ if (!m_mruFrame->isHidden()) {
+ if (m_mruEdit->text().isEmpty() || m_mtuEdit->text().isEmpty()) {
+ qDebug() << LOG_FLAG << "MRU or MTU is empty";
+ return false;
+ }
+ }
+
+ //PPTP 无必填项
+
+ //OPEN VPN
+ if (!m_openVpnAdiaFrame->isHidden()) {
+ if (m_customGatewayPortCheckbox->isChecked() && m_gatewayPortEdit->text().isEmpty()) {
+ return false;
+ }
+
+ if (m_customRenegotiaInrCheckbox->isChecked() && m_renogotiaInrEdit->text().isEmpty()) {
+ return false;
+ }
+
+ if (m_setVDevNameCheckbox->isChecked() && m_setVDevNameEdit->text().isEmpty()) {
+ return false;
+ }
+
+ if (m_customMtuCheckbox->isChecked() && m_customMtuEdit->text().isEmpty()) {
+ return false;
+ }
+
+ if (m_customUdpFragSizeCheckbox->isChecked() && m_customUdpFragSizeEdit->text().isEmpty()) {
+ return false;
+ }
+
+ if (m_specPingInrCheckbox->isChecked() && m_specPingInrEdit->text().isEmpty()) {
+ return false;
+ }
+
+ if (m_specExitPingCheckbox->isChecked() && m_specExRePingEdit->text().isEmpty()) {
+ return false;
+ }
+
+ if (m_specMaxRouteCheckbox->isChecked() && m_specMaxRouteEdit->text().isEmpty()) {
+ return false;
+ }
+
+ if (m_serverCertCheckCombox->currentData().toInt() != (int)KYCHECKSERVER_NONE
+ && m_subjectMatchEdit->text().isEmpty()) {
+ return false;
+ }
+
+ if (m_tlsModeCombox->currentData().toInt() == TLS_CERT || m_tlsModeCombox->currentData().toInt() == TLS_ENCRYPTION) {
+ if (m_keyPathEdit->text().isEmpty()) {
+ return false;
+ }
+ }
+
+ if (m_proxyTypeCombox->currentData().toInt() == HTTP || m_proxyTypeCombox->currentData().toInt() == SOCKS) {
+ if (m_proxyServerAddEdit->text().isEmpty() || !getTextEditState(m_proxyServerAddEdit->text())) {
+ return false;
+ }
+ if (m_proxyPortEdit->text().isEmpty()) {
+ return false;
+ }
+ }
+
+ if(m_customKeySizeCheckbox->isChecked() && m_customKeySizeEdit->text().isEmpty()) {
+ return false;
+ }
+ }
+
+ //strong-swan
+ if (!m_sSwanAdiaFrame->isHidden()) {
+ if (m_enablCustomCheckbox->isChecked()) {
+ if (m_ikeEdit->text().isEmpty() || m_espEdit->text().isEmpty()) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool VpnAdvancedPage::getTextEditState(QString text)
+{
+ if (text.isEmpty()) {
+ return true;
+ }
+ QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
+
+ bool match = false;
+ match = rx.exactMatch(text);
+
+ return match;
+}
diff --git a/src-vpn/frontend/vpndetails/vpnadvancedpage.h b/src-vpn/frontend/vpndetails/vpnadvancedpage.h
new file mode 100644
index 00000000..4c6be900
--- /dev/null
+++ b/src-vpn/frontend/vpndetails/vpnadvancedpage.h
@@ -0,0 +1,197 @@
+#ifndef VPNADVANCEDPAGE_H
+#define VPNADVANCEDPAGE_H
+
+#include
+#include