From dfd834fafb0e1c038838f53baef4b372016757db Mon Sep 17 00:00:00 2001 From: chenxuechao Date: Thu, 27 Oct 2022 09:15:37 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=A2=9EVPN=20dbus=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/backend.pri | 2 + src/backend/vpndbusadaptor.cpp | 73 +++++ src/backend/vpndbusadaptor.h | 71 +++++ src/frontend/list-items/vpnlistitem.cpp | 21 +- src/frontend/list-items/vpnlistitem.h | 2 + src/frontend/single-pages/vpnpage.cpp | 81 ++--- src/frontend/single-pages/vpnpage.h | 11 +- src/frontend/vpnmainwindow.cpp | 360 +++++------------------ src/frontend/vpnmainwindow.h | 73 ++--- src/main.cpp | 10 +- src/org.ukui.kylin-nm.switch.gschema.xml | 7 + 11 files changed, 292 insertions(+), 419 deletions(-) create mode 100644 src/backend/vpndbusadaptor.cpp create mode 100644 src/backend/vpndbusadaptor.h diff --git a/src/backend/backend.pri b/src/backend/backend.pri index feb4853f..10314e58 100644 --- a/src/backend/backend.pri +++ b/src/backend/backend.pri @@ -4,6 +4,7 @@ include(dbus-interface/dbus-interface.pri) HEADERS += \ $$PWD/dbusadaptor.h \ + $$PWD/vpndbusadaptor.h \ $$PWD/kylinarping.h \ $$PWD/kylinipv4arping.h \ $$PWD/kylinipv6arping.h \ @@ -13,6 +14,7 @@ HEADERS += \ SOURCES += \ $$PWD/dbusadaptor.cpp \ + $$PWD/vpndbusadaptor.cpp \ $$PWD/kylinipv4arping.cpp \ $$PWD/kylinipv6arping.cpp \ $$PWD/sysdbusregister.cpp \ diff --git a/src/backend/vpndbusadaptor.cpp b/src/backend/vpndbusadaptor.cpp new file mode 100644 index 00000000..a811a535 --- /dev/null +++ b/src/backend/vpndbusadaptor.cpp @@ -0,0 +1,73 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp com.kylin.weather.xml -a VpnDbusAdaptor -c VpnDbusAdaptor -l MainWindow + * + * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#include "vpndbusadaptor.h" +#include +#include +#include +#include +#include +#include +#include + +/* + * Implementation of adaptor class VpnDbusAdaptor + */ + +VpnDbusAdaptor::VpnDbusAdaptor(vpnMainWindow *parent) + : QDBusAbstractAdaptor(parent) +{ + // constructor + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >>(); + //setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发 + setAutoRelaySignals(true); +} + +VpnDbusAdaptor::~VpnDbusAdaptor() +{ + // destructor +} + +//虚拟连接列表 +QMap> VpnDbusAdaptor::getVirtualList() +{ + QMap> map; + parent()->getVirtualList(map); + return map; +} + +//删除 +void VpnDbusAdaptor::deleteVpn(QString uuid) +{ + qDebug() << "delete vpn" << uuid; + parent()->deleteVpn(uuid); +} + +//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid +void VpnDbusAdaptor::activateVpn(const QString& connUuid) +{ + qDebug() << "activate vpn" << connUuid; + parent()->activateVpn(connUuid); +} + +//断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid +void VpnDbusAdaptor::deactivateVpn(const QString& connUuid) +{ + qDebug() << "deactivate vpn" << connUuid; + parent()->deactivateVpn(connUuid); +} + +void VpnDbusAdaptor::showKylinVpn() +{ + parent()->onShowMainWindow(); +} diff --git a/src/backend/vpndbusadaptor.h b/src/backend/vpndbusadaptor.h new file mode 100644 index 00000000..c54ea2a9 --- /dev/null +++ b/src/backend/vpndbusadaptor.h @@ -0,0 +1,71 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp com.kylin.weather.xml -a dbusadaptor -c DbusAdaptor -l MainWindow + * + * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#ifndef VPNDBUSADAPTOR_H +#define VPNDBUSADAPTOR_H + +#include +#include +#include + +#include "singlepage.h" +#include "../dbus-interface/kylinnetworkdeviceresource.h" +QT_BEGIN_NAMESPACE +class QByteArray; +//template class QList; +template class QMap; +class QString; +class QStringList; +class QVariant; +template class QVector; +QT_END_NAMESPACE + +/* + * Adaptor class for interface com.kylin.weather + */ + +#include "vpnmainwindow.h" + +class VpnDbusAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "com.kylin.vpnTool") +public: + VpnDbusAdaptor(vpnMainWindow *parent); + virtual ~VpnDbusAdaptor(); + + inline vpnMainWindow *parent() const + { return static_cast(QObject::parent()); } + +public: // PROPERTIES +public Q_SLOTS: // METHODS + //虚拟连接列表 + QMap > getVirtualList(); + //刪除 根据网络名称 参数1 0:lan 1:wlan 参数2 为ssid/uuid + Q_NOREPLY void deleteVpn(QString uuid); + //连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid + Q_NOREPLY void activateVpn(const QString& connUuid); + //断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid + Q_NOREPLY void deactivateVpn(const QString& connUuid); + //just show + void showKylinVpn(); + +Q_SIGNALS: // SIGNALS + void vpnAdd(QStringList info); + void vpnRemove(QString dbusPath); + void vpnUpdate(QStringList info); + void vpnActiveConnectionStateChanged(QString uuid, int status); + + void activateFailed(QString errorMessage); + void deactivateFailed(QString errorMessage); +}; + +#endif diff --git a/src/frontend/list-items/vpnlistitem.cpp b/src/frontend/list-items/vpnlistitem.cpp index 6b3c0bee..493507eb 100644 --- a/src/frontend/list-items/vpnlistitem.cpp +++ b/src/frontend/list-items/vpnlistitem.cpp @@ -107,10 +107,29 @@ void VpnListItem::connectItemCopy(const KyConnectItem *lanConnectItem) //} +void VpnListItem::activeConnection() +{ + if (m_vpnConnectItem.m_connectUuid.isEmpty()) { + qDebug() << LOG_FLAG << "connect is empty, so can not connect or disconnect."; + return; + } + + if (Deactivated == m_vpnConnectItem.m_connectState) { + //断开的连接,点击激活连接 + m_connectOperation->activateVpnConnection(m_vpnConnectItem.m_connectUuid); + qDebug() << LOG_FLAG << "it will activate connection" << m_vpnConnectItem.m_connectName; + m_netButton->startLoading(); + } else { + qDebug() << LOG_FLAG <<"the connection" << m_vpnConnectItem.m_connectName + << "is not deactived, so it can not be operation."; + } + + return; +} + void VpnListItem::onNetButtonClicked() { if (m_vpnConnectItem.m_connectUuid.isEmpty()) { - qDebug()<<"--cxc--"<getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid); if (p_newItem == nullptr) { - qDebug()<<"---cxc---"<m_connectUuid<m_connectName<m_connectState; if (m_netConnectionMap.contains(p_netConnectionItem->m_connectUuid)) { qDebug()<m_connectUuid; } QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_vpnListWidget); m_netConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); } else { - qDebug()<<"---cxc---"<m_connectUuid<m_connectName<m_connectState; if (m_activeConnectionMap.contains(p_netConnectionItem->m_connectUuid)) { qDebug()<m_connectUuid; } @@ -155,43 +153,10 @@ void VpnPage::constructActiveConnectionArea() return; } -void VpnPage::constructConnectionArea() -{ - QList netList; - - netList.clear(); - clearConnectionMap(m_netConnectionMap, m_vpnListWidget); - - m_connectResourse->getVpnAndVirtualConnections(netList); - qDebug() << "[VpnPage]construct connection area get connection list size:" << netList.size(); - if (!netList.isEmpty()) { - for (int index = 0; index < netList.size(); index++) { - KyConnectItem *p_netConnectionItem = netList.at(index); - qDebug()<<"[VpnPage] construct connection area add deactive item"<m_connectName; - QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_vpnListWidget); - if (m_netConnectionMap.contains(p_netConnectionItem->m_connectUuid)) { - qDebug()<m_connectUuid; - } - m_netConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); - - delete p_netConnectionItem; - p_netConnectionItem = nullptr; - - } - } - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); - } else { - m_vpnListWidget->setFixedWidth(MAX_WIDTH); - } - return; -} - void VpnPage::initVpnArea() { m_netFrame->show(); constructActiveConnectionArea(); -// constructConnectionArea(); return; } @@ -394,7 +359,6 @@ void VpnPage::onConnectionStateChange(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) { - qDebug()<<"--cxc--"<isVirtualConncection(uuid)) { qDebug() << "[VpnPage] connection state change signal but not wired"; @@ -404,7 +368,6 @@ void VpnPage::onConnectionStateChange(QString uuid, sendVpnStateChangeSignal(uuid, (ConnectState)state); if (m_activeConnectionMap.keys().contains(uuid) && state == NetworkManager::ActiveConnection::State::Activated) { - qDebug()<<"--cxc--"<m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath; - Q_EMIT vpnUpdate(p_connectItem->m_ifaceName, info); + Q_EMIT vpnUpdate(info); return; } @@ -483,7 +446,7 @@ void VpnPage::sendVpnAddSignal(KyConnectItem *p_connectItem) QStringList info; info << p_connectItem->m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath; qDebug() << "[VpnPage] emit vpnAdd because addConnection "; - Q_EMIT vpnAdd(p_connectItem->m_ifaceName, info); + Q_EMIT vpnAdd(info); return; } @@ -600,22 +563,28 @@ bool VpnPage::eventFilter(QObject *watched, QEvent *event) return QWidget::eventFilter(watched, event); } +void VpnPage::deleteVpn(const QString &connUuid) +{ + qDebug() << "[VpnPage] deleteVpn" << connUuid; + if (connUuid == nullptr) { + return; + } + m_wiredConnectOperation->deleteWiredConnect(connUuid); +} + void VpnPage::activateVpn(const QString& connUuid) { -// qDebug() << "[VpnPage] activateVpn" << connUuid; -// if (!m_deviceResource->wiredDeviceIsCarriered(devName)) { -// qDebug() << LOG_FLAG << devName << "is not carried, so can not activate connection"; -// this->showDesktopNotify(tr("Wired Device not carried"), "networkwrong"); -// } else { -// m_wiredConnectOperation->activateConnection(connUuid, devName); -// } + if (m_netConnectionMap.contains(connUuid)) { + qDebug() << "[VpnPage] activateVpn" << connUuid; + m_wiredConnectOperation->activateVpnConnection(connUuid); + } } void VpnPage::deactivateVpn(const QString& connUuid) { qDebug() << "[VpnPage] deactivateVpn" << connUuid; QString name(""); -// m_wiredConnectOperation->deactivateWiredConnection(name, connUuid); + m_wiredConnectOperation->deactivateWiredConnection(name, connUuid); } void VpnPage::showDetailPage(QString devName, QString uuid) @@ -646,13 +615,3 @@ void VpnPage::showDetailPage(QString devName, QString uuid) p_item = nullptr; #endif } - -bool VpnPage::vpnIsConnected() -{ - if (m_activeResourse->wiredConnectIsActived()) { - return true; - } else { - return false; - } -} - diff --git a/src/frontend/single-pages/vpnpage.h b/src/frontend/single-pages/vpnpage.h index ddb212ff..c15a101d 100644 --- a/src/frontend/single-pages/vpnpage.h +++ b/src/frontend/single-pages/vpnpage.h @@ -46,12 +46,11 @@ public: //for dbus void getVirtualList(QMap > &map); + void deleteVpn(const QString &connUuid); void activateVpn(const QString& connUuid); void deactivateVpn(const QString& connUuid); void showDetailPage(QString devName, QString uuid); - bool vpnIsConnected(); - protected: bool eventFilter(QObject *watched, QEvent *event); @@ -87,11 +86,11 @@ private: QListWidget *lanListWidget, QString uuid); Q_SIGNALS: - void vpnAdd(QString devName, QStringList info); + void vpnAdd(QStringList info); void vpnRemove(QString dbusPath); - void vpnUpdate(QString devName, QStringList info); + void vpnUpdate(QStringList info); - void vpnActiveConnectionStateChanged(QString interface, QString uuid, int status); + void vpnActiveConnectionStateChanged(QString uuid, int status); void vpnConnectChanged(int state); private Q_SLOTS: @@ -110,7 +109,7 @@ private: QListWidget * m_vpnListWidget = nullptr; // KyNetworkDeviceResourse *m_deviceResource = nullptr; -// KyWiredConnectOperation *m_wiredConnectOperation = nullptr; + KyWiredConnectOperation *m_wiredConnectOperation = nullptr; KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接 KyConnectResourse *m_connectResourse = nullptr; //未激活的连接 diff --git a/src/frontend/vpnmainwindow.cpp b/src/frontend/vpnmainwindow.cpp index 3a22b754..a5461c24 100644 --- a/src/frontend/vpnmainwindow.cpp +++ b/src/frontend/vpnmainwindow.cpp @@ -93,7 +93,7 @@ void vpnMainWindow::showMainwindow() } /** - * @brief MainWindow::hideMainwindow 隐藏主页面时要进行的操作,后续可以添加到此函数 + * @brief vpnMainWindow::hideMainwindow 隐藏主页面时要进行的操作,后续可以添加到此函数 */ void vpnMainWindow::hideMainwindow() { @@ -102,9 +102,9 @@ void vpnMainWindow::hideMainwindow() } ///** -// * @brief MainWindow::setWiredDefaultDevice 设置有线设备默认网卡 +// * @brief vpnMainWindow::setWiredDefaultDevice 设置有线设备默认网卡 // */ -//void MainWindow::setWiredDefaultDevice(QString deviceName) +//void vpnMainWindow::setWiredDefaultDevice(QString deviceName) //{ //// m_vpnPage->updateDefaultDevice(deviceName); //} @@ -170,6 +170,7 @@ void vpnMainWindow::initWindowProperties() // this->setFixedSize(MAINWINDOW_WIDTH, MAINWINDOW_HEIGHT); // //绘制毛玻璃特效 // this->setAttribute(Qt::WA_TranslucentBackground, true); //透明 + this->setProperty("needTranslucent", true); this->setFocusPolicy(Qt::NoFocus); QString platform = QGuiApplication::platformName(); @@ -188,8 +189,6 @@ void vpnMainWindow::paintEvent(QPaintEvent *event) QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; painter.setPen(Qt::transparent); -// auto rect = this->rect(); -// painter.drawRoundedRect(rect, 12, 12); //窗口圆角 } void vpnMainWindow::initTransparency() @@ -244,44 +243,27 @@ void vpnMainWindow::initUI() void vpnMainWindow::initTrayIcon() { m_vpnTrayIcon = new QSystemTrayIcon(this); - m_vpnTrayIconMenu = new QMenu(); -// m_showMainwindowAction = new QAction(tr("Show MainWindow"),this); -// m_showSettingsAction = new QAction(tr("Settings"),this); - m_vpnTrayIcon->setToolTip(QString(tr("vpn tool"))); m_vpnTrayIcon->setIcon(QIcon::fromTheme("ukui-vpn-symbolic")); -// m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) ); -//// m_vpnTrayIconMenu->addAction(m_showMainwindowAction); -// m_vpnTrayIconMenu->addAction(m_showSettingsAction); -// m_vpnTrayIcon->setContextMenu(m_vpnTrayIconMenu); -// m_vpnTrayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); -// m_iconStatus = IconActiveType::LAN_CONNECTED; -// onRefreshTrayIcon(); - + initVpnIconVisible(); connect(m_vpnTrayIcon, &QSystemTrayIcon::activated, this, &vpnMainWindow::onTrayIconActivated); -//// connect(m_showMainwindowAction, &QAction::triggered, this, &MainWindow::onShowMainwindowActionTriggled); -// connect(m_showSettingsAction, &QAction::triggered, this, &MainWindow::onShowSettingsActionTriggled); - m_vpnTrayIcon->show(); } void vpnMainWindow::initDbusConnnect() { -// connect(m_vpnPage, &LanPage::deviceStatusChanged, this, &MainWindow::deviceStatusChanged); -// connect(m_vpnPage, &LanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged); -// connect(m_vpnPage, &LanPage::activateFailed, this, &MainWindow::activateFailed); -// connect(m_vpnPage, &LanPage::deactivateFailed, this, &MainWindow::deactivateFailed); + connect(m_vpnPage, &VpnPage::activateFailed, this, &vpnMainWindow::activateFailed); + connect(m_vpnPage, &VpnPage::deactivateFailed, this, &vpnMainWindow::deactivateFailed); connect(m_vpnPage, &VpnPage::vpnAdd, this, &vpnMainWindow::vpnAdd); connect(m_vpnPage, &VpnPage::vpnRemove, this, &vpnMainWindow::vpnRemove); connect(m_vpnPage, &VpnPage::vpnUpdate, this, &vpnMainWindow::vpnUpdate); connect(m_vpnPage, &VpnPage::vpnActiveConnectionStateChanged, this, &vpnMainWindow::vpnActiveConnectionStateChanged); -// connect(m_vpnPage, &LanPage::lanConnectChanged, this, &MainWindow::onLanConnectStatusToChangeTrayIcon); -// //模式切换 -// QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), -// QString("/"), -// QString("com.kylin.statusmanager.interface"), -// QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool))); + //模式切换 + QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), + QString("/"), + QString("com.kylin.statusmanager.interface"), + QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool))); } /** @@ -350,31 +332,6 @@ void vpnMainWindow::resetWindowPosition() qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__; } -///** -// * @brief MainWindow::resetTrayIconTool 重新获取网络连接状态并重新设置图标和tooltip -// */ -//void MainWindow::resetTrayIconTool() -//{ -// //ZJP_TODO 检测当前连接的是有线还是无线,是否可用,设置图标和tooltip,图标最好提前define -//// int connectivity = objKyDBus->getNetworkConectivity(); -//// qDebug() << "Value of current network Connectivity property : "<< connectivity; -//// switch (connectivity) { -//// case UnknownConnectivity: -//// case Portal: -//// case Limited: -//// setTrayIcon(iconLanOnlineNoInternet); -//// trayIcon->setToolTip(QString(tr("Network Connected But Can Not Access Internet"))); -//// break; -//// case NoConnectivity: -//// case Full: -//// setTrayIcon(iconLanOnline); -//// trayIcon->setToolTip(QString(tr("kylin-nm"))); -//// break; -//// } -// qDebug() << "Has set tray icon to be XXX." << Q_FUNC_INFO << __LINE__; -//} - - /** * @brief vpnMainWindow::initWindowTheme 初始化窗口主题并创建信号槽 */ @@ -390,29 +347,9 @@ void vpnMainWindow::initWindowTheme() } ///** -// * @brief MainWindow::resetWindowTheme 读取和设置窗口主题 +// * @brief vpnMainWindow::showControlCenter 打开控制面板网络界面 // */ -//void MainWindow::resetWindowTheme() -//{ -// if (!m_styleGsettings) { return; } -// QString currentTheme = m_styleGsettings->get(COLOR_THEME).toString(); -// auto app = static_cast(QCoreApplication::instance()); -// if(currentTheme == "ukui-dark" || currentTheme == "ukui-black"){ -// app->setStyle(new CustomStyle("ukui-dark")); -// qDebug() << "Has set color theme to ukui-dark." << Q_FUNC_INFO << __LINE__; -// Q_EMIT qApp->paletteChanged(qApp->palette()); -// return; -// } -// app->setStyle(new CustomStyle("ukui-light")); -// qDebug() << "Has set color theme to " << currentTheme << Q_FUNC_INFO << __LINE__; -// Q_EMIT qApp->paletteChanged(qApp->palette()); -// return; -//} - -///** -// * @brief MainWindow::showControlCenter 打开控制面板网络界面 -// */ -//void MainWindow::showControlCenter() +//void vpnMainWindow::showControlCenter() //{ // QProcess process; // if (!m_vpnPage->lanIsConnected() && m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activated)){ @@ -433,21 +370,6 @@ void vpnMainWindow::showByWaylandHelper() } -void vpnMainWindow::setCentralWidgetType(IconActiveType iconStatus) -{ - if (iconStatus == WLAN_CONNECTED || iconStatus == WLAN_CONNECTED_LIMITED) { -// m_vpnWidget->setCurrentIndex(WLAN_PAGE_INDEX); - } else if (iconStatus == ACTIVATING) { -// if (m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activating)) { -// m_vpnWidget->setCurrentIndex(WLAN_PAGE_INDEX); -// } else { -// m_vpnWidget->setCurrentIndex(LAN_PAGE_INDEX); -// } - } else { -// m_vpnWidget->setCurrentIndex(LAN_PAGE_INDEX); - } -} - void vpnMainWindow::getTabletMode() { QDBusInterface interface(QString("com.kylin.statusmanager.interface"), @@ -471,11 +393,10 @@ void vpnMainWindow::getTabletMode() */ void vpnMainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason) { - setCentralWidgetType(m_iconStatus); switch(reason) { - case QSystemTrayIcon::Context: - m_vpnTrayIconMenu->popup(QCursor::pos()); - break; +// case QSystemTrayIcon::Context: +// m_vpnTrayIconMenu->popup(QCursor::pos()); +// break; case QSystemTrayIcon::Trigger: if (this->isVisible()) { qDebug() << "Received signal of tray icon activated, will hide mainwindow." << Q_FUNC_INFO << __LINE__; @@ -489,29 +410,8 @@ void vpnMainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason default: break; } -// if (reason == QSystemTrayIcon::ActivationReason::Context) { -// m_vpnTrayIconMenu->popup(QCursor::pos()); -// } else { -// if (this->isVisible()) { -// qDebug() << "Received signal of tray icon activated, will hide mainwindow." << Q_FUNC_INFO << __LINE__; -// hideMainwindow(); -// return; -// } -// qDebug() << "Received signal of tray icon activated, will show mainwindow." << Q_FUNC_INFO << __LINE__; -// this->showMainwindow(); -// } } -//void MainWindow::onShowMainwindowActionTriggled() -//{ -// showMainwindow(); -//} - -//void MainWindow::onShowSettingsActionTriggled() -//{ -// showControlCenter(); -//} - void vpnMainWindow::onThemeChanged(const QString &key) { if (key == COLOR_THEME) { @@ -523,99 +423,39 @@ void vpnMainWindow::onThemeChanged(const QString &key) } } -void vpnMainWindow::onRefreshTrayIcon() +void vpnMainWindow::onTabletModeChanged(bool mode) { - //更新托盘图标显示 -// m_iconTimer->stop(); -// if (m_vpnPage->lanIsConnected()) { -// m_vpnTrayIcon->setIcon(QIcon::fromTheme("network-wired-connected-symbolic")); -// m_iconStatus = IconActiveType::LAN_CONNECTED; -// } else { -// m_vpnTrayIcon->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic")); -// m_iconStatus = IconActiveType::NOT_CONNECTED; -// } + qDebug() << "TabletMode change" << mode; + Q_UNUSED(mode) + //模式切换时,隐藏主界面 + hideMainwindow(); +} - NetworkManager::Connectivity connecttivity; - if (connecttivity != NetworkManager::Connectivity::Full) { - if (m_iconStatus == IconActiveType::LAN_CONNECTED) { - m_vpnTrayIcon->setIcon(QIcon::fromTheme("network-error-symbolic")); - m_iconStatus = IconActiveType::LAN_CONNECTED_LIMITED; - } +void vpnMainWindow::onShowMainWindow() +{ + if(QApplication::activeWindow() != this) { + this->showMainwindow(); } } -//void vpnMainWindow::onSetTrayIconLoading() -//{ -// if (m_currentIconIndex > 11) { -// m_currentIconIndex = 0; -// } -// m_vpnTrayIcon->setIcon(m_loadIcons.at(m_currentIconIndex)); -// m_iconStatus = IconActiveType::ACTIVATING; -// m_currentIconIndex ++; -//} +/** + * @brief vpnMainWindow::keyPressEvent 按esc键关闭主界面 + * @param event + */ +void vpnMainWindow::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape) { + hideMainwindow(); + } + return QWidget::keyPressEvent(event); +} -//void MainWindow::onLanConnectStatusToChangeTrayIcon(int state) -//{ -// qDebug() << "lan state:" << state << Q_FUNC_INFO << __LINE__; -// if (state==1 || state==3){ -// m_lanIsLoading = true; -// m_iconTimer->start(LOADING_TRAYICON_TIMER_MS); -// } else { -// m_lanIsLoading = false; -// if (m_wlanIsLoading == false) { -// onRefreshTrayIcon(); -// } -// } -//} - -//void MainWindow::onTabletModeChanged(bool mode) -//{ -// qDebug() << "TabletMode change" << mode; -// Q_UNUSED(mode) -// //模式切换时,隐藏主界面 -// hideMainwindow(); -//} - -//void MainWindow::onShowMainWindow(int type) -//{ -// m_vpnWidget->setCurrentIndex(type); - -// if(QApplication::activeWindow() != this) { -// this->showMainwindow(); -// } -//} - -//void MainWindow::onConnectivityChanged(NetworkManager::Connectivity connectivity) -//{ -// if (!m_vpnTrayIcon) { -// return; -// } - -// if (m_iconStatus == ACTIVATING) { -// return; -// } - -// onRefreshTrayIcon(); -//} - -///** -// * @brief MainWindow::keyPressEvent 按esc键关闭主界面 -// * @param event -// */ -//void MainWindow::keyPressEvent(QKeyEvent *event) -//{ -// if (event->key() == Qt::Key_Escape) { -// hideMainwindow(); -// } -// return QWidget::keyPressEvent(event); -//} - -///** -// * @brief MainWindow::eventFilter 事件过滤器 -// * @param watched -// * @param event -// * @return -// */ +/** + * @brief vpnMainWindow::eventFilter 事件过滤器 + * @param watched + * @param event + * @return + */ bool vpnMainWindow::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::ActivationChange) { @@ -634,96 +474,13 @@ void vpnMainWindow::getVirtualList(QMap> &map) } } -//void MainWindow::setWiredDeviceEnable(const QString& devName, bool enable) -//{ -// m_vpnPage->setWiredDeviceEnable(devName, enable); -//} -//void MainWindow::showPropertyWidget(QString devName, QString ssid) -//{ -// KyNetworkDeviceResourse *devResourse = new KyNetworkDeviceResourse(); -// QStringList wiredDeviceList; -// wiredDeviceList.clear(); -// devResourse->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDeviceList); -// if (wiredDeviceList.contains(devName)) { -// qDebug() << "showPropertyWidget device type wired device name " << devName << " uuid " << ssid; -// m_vpnPage->showDetailPage(devName, ssid); -// delete devResourse; -// devResourse = nullptr; -// return; -// } +//Vpn连接删除 +void vpnMainWindow::deleteVpn(const QString &connUuid) +{ + m_vpnPage->deleteVpn(connUuid); +} -// QStringList wirelessDeviceList; -// wirelessDeviceList.clear(); -// devResourse->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDeviceList); -// if (wirelessDeviceList.contains(devName)) { -// qDebug() << "showPropertyWidget device type wireless device name " << devName << " ssid " << ssid; -// m_wlanWidget->showDetailPage(devName, ssid); -// delete devResourse; -// devResourse = nullptr; -// return; -// } - -// qWarning() << "showPropertyWidget no such device " << devName; -// delete devResourse; -// devResourse = nullptr; -//} - -//void MainWindow::showCreateWiredConnectWidget(const QString devName) -//{ -// qDebug() << "showCreateWiredConnectWidget! devName = " << devName; -// if (m_createPagePtrMap.contains(devName)) { -// if (m_createPagePtrMap[devName] != nullptr) { -// qDebug() << "showCreateWiredConnectWidget" << devName << "already create,just raise"; - -// KWindowSystem::raiseWindow(m_createPagePtrMap[devName]->winId()); -// return; -// } -// } -// NetDetail *netDetail = new NetDetail(devName, "", "", false, false, true, this); -// connect(netDetail, &NetDetail::createPageClose, [&](QString interfaceName){ -// if (m_createPagePtrMap.contains(interfaceName)) { -// m_createPagePtrMap[interfaceName] = nullptr; -// } -// }); -// m_createPagePtrMap.insert(devName, netDetail); -// netDetail->show(); -//} - -//void MainWindow::showAddOtherWlanWidget(QString devName) -//{ -// qDebug() << "showAddOtherWlanWidget! devName = " << devName; -// if (m_addOtherPagePtrMap.contains(devName)) { -// if (m_addOtherPagePtrMap[devName] != nullptr) { -// qDebug() << "showAddOtherWlanWidget" << devName << "already create,just raise"; - -// KWindowSystem::raiseWindow(m_addOtherPagePtrMap[devName]->winId()); -// return; -// } -// } - -//#if 0 -// NetDetail *netDetail = new NetDetail(devName, "", "", false, true, true, this); -// connect(netDetail, &NetDetail::createPageClose, [&](QString interfaceName){ -// if (m_addOtherPagePtrMap.contains(interfaceName)) { -// m_addOtherPagePtrMap[interfaceName] = nullptr; -// } -// }); -// m_addOtherPagePtrMap.insert(devName, netDetail); -// netDetail->show(); -//#endif - -// JoinHiddenWiFiPage *hiddenWiFi =new JoinHiddenWiFiPage(devName); -// connect(hiddenWiFi, &JoinHiddenWiFiPage::hiddenWiFiPageClose, [&](QString interfaceName){ -// if (m_addOtherPagePtrMap.contains(interfaceName)) { -// m_addOtherPagePtrMap[interfaceName] = nullptr; -// } -// }); -// m_addOtherPagePtrMap.insert(devName, hiddenWiFi); -// connect(hiddenWiFi, &JoinHiddenWiFiPage::showWlanList, this, &MainWindow::onShowMainWindow); -// hiddenWiFi->show(); -//} - -//有线连接断开 +//Vpn连接断开 void vpnMainWindow::activateVpn(const QString& connUuid) { m_vpnPage->activateVpn(connUuid); @@ -733,3 +490,20 @@ void vpnMainWindow::deactivateVpn(const QString& connUuid) m_vpnPage->deactivateVpn(connUuid); } +void vpnMainWindow::onVpnIconVisibleChanged() +{ + m_vpnTrayIcon->setVisible(m_vpnGsettings->get("visible").toBool()); +} + +void vpnMainWindow::initVpnIconVisible() +{ + if(QGSettings::isSchemaInstalled(GSETTINGS_VPNICON_VISIBLE)) { + m_vpnGsettings = new QGSettings(GSETTINGS_VPNICON_VISIBLE); + if(m_vpnGsettings->keys().contains(QString("visible"))) { + connect(m_vpnGsettings, &QGSettings::changed, this, &vpnMainWindow::onVpnIconVisibleChanged); + m_vpnTrayIcon->setVisible(m_vpnGsettings->get("visible").toBool()); + } + } +} + + diff --git a/src/frontend/vpnmainwindow.h b/src/frontend/vpnmainwindow.h index 3dc6fc2c..72584067 100644 --- a/src/frontend/vpnmainwindow.h +++ b/src/frontend/vpnmainwindow.h @@ -33,21 +33,7 @@ #include "vpnpage.h" #include "mainwindow.h" -#ifdef WITHKYSEC -#include -#include -#endif - -//enum IconActiveType { -// NOT_CONNECTED = 0, -// LAN_CONNECTED, -// WLAN_CONNECTED, -// LAN_CONNECTED_LIMITED, -// WLAN_CONNECTED_LIMITED, -// ACTIVATING, -//}; - -//const QByteArray TRANSPARENCY_GSETTINGS = "org.ukui.control-center.personalise"; +const QByteArray GSETTINGS_VPNICON_VISIBLE = "org.ukui.kylin-nm.vpnicon"; class VpnPage; @@ -61,35 +47,29 @@ public: void getVirtualList(QMap> &map); -// void setWiredDefaultDevice(QString deviceName); + //Vpn连接删除 + void deleteVpn(const QString &connUuid); // //有线连接断开 void activateVpn(const QString& connUuid); void deactivateVpn(const QString& connUuid); -// //唤起属性页 根据网卡类型 参数2 为ssid/uuid -// void showPropertyWidget(QString devName, QString ssid); -// //唤起新建有线连接界面 + void initVpnIconVisible(); + + //唤起新建有线连接界面 // void showCreateWiredConnectWidget(const QString devName); Q_SIGNALS: -// //设备插拔 -// void deviceStatusChanged(); -// //设备名称变化 -// void deviceNameChanged(QString oldName, QString newName, int type); - void vpnAdd(QString devName, QStringList info); + void vpnAdd(QStringList info); void vpnRemove(QString dbusPath); - void vpnUpdate(QString devName, QStringList info); - void vpnActiveConnectionStateChanged(QString devName, QString uuid, int status); -// void activateFailed(QString errorMessage); -// void deactivateFailed(QString errorMessage); + void vpnUpdate(QStringList info); + void vpnActiveConnectionStateChanged(QString uuid, int status); + void activateFailed(QString errorMessage); + void deactivateFailed(QString errorMessage); void mainWindowVisibleChanged(const bool &visible); -// //列表排序 -// void timeToUpdate(); -public Q_SLOTS: protected: -// void keyPressEvent(QKeyEvent *event); + void keyPressEvent(QKeyEvent *event); bool eventFilter(QObject *watched, QEvent *event) override; void paintEvent(QPaintEvent *event); @@ -105,23 +85,16 @@ private: void initUI(); void initDbusConnnect(); void initTrayIcon(); -// void resetTrayIconTool(); void initWindowTheme(); -// void resetWindowTheme(); -// void showControlCenter(); void showByWaylandHelper(); - void setCentralWidgetType(IconActiveType iconStatus); void getTabletMode(); + double m_transparency=1.0; //透明度 QGSettings * m_transGsettings; //透明度配置文件 - int m_currentIconIndex = 0; - QList m_loadIcons; - QTimer *m_iconTimer = nullptr; + QGSettings * m_vpnGsettings; //VPN配置文件 // //主窗口的主要构成控件 QWidget * m_vpnWidget = nullptr; -// QHBoxLayout * m_tabBarLayout = nullptr; - QLabel * m_lanLabel = nullptr; VpnPage * m_vpnPage = nullptr; QVBoxLayout * m_vpnLayout = nullptr; @@ -135,34 +108,22 @@ private: // //托盘图标,托盘图标右键菜单 QSystemTrayIcon * m_vpnTrayIcon = nullptr; QMenu * m_vpnTrayIconMenu = nullptr; -// QAction * m_showMainwindowAction = nullptr; -// QAction * m_showSettingsAction = nullptr; - -// bool m_lanIsLoading = false; bool m_isShowInCenter = false; IconActiveType m_iconStatus = IconActiveType::NOT_CONNECTED; QMap m_createPagePtrMap; -//// QMap m_addOtherPagePtrMap; -// QMap m_addOtherPagePtrMap; public Q_SLOTS: -// void onShowMainWindow(int type); + void onShowMainWindow(); private Q_SLOTS: void onTransChanged(); void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason); -// void onShowMainwindowActionTriggled(); -// void onShowSettingsActionTriggled(); void onThemeChanged(const QString &key); - void onRefreshTrayIcon(); -// void onSetTrayIconLoading(); -// void onLanConnectStatusToChangeTrayIcon(int state); -// void onWlanConnectStatusToChangeTrayIcon(int state); -// void onConnectivityChanged(NetworkManager::Connectivity connectivity); -// void onTabletModeChanged(bool mode); + void onTabletModeChanged(bool mode); + void onVpnIconVisibleChanged(); }; #endif // MAINWINDOW_H diff --git a/src/main.cpp b/src/main.cpp index 1784eef0..0b6bd839 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ #include "mainwindow.h" #include "vpnmainwindow.h" #include "dbusadaptor.h" +#include "vpndbusadaptor.h" #include #include #include "qt-single-application.h" @@ -80,7 +81,7 @@ void messageOutput(QtMsgType type, const QMessageLogContext &context, const QStr int main(int argc, char *argv[]) { - initUkuiLog4qt("kylin-nm"); +// initUkuiLog4qt("kylin-nm"); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); @@ -169,8 +170,13 @@ int main(int argc, char *argv[]) DbusAdaptor adaptor(&w); Q_UNUSED(adaptor); + VpnDbusAdaptor vpnAdaptor(&vpnwindow); + Q_UNUSED(vpnAdaptor); + auto connection = QDBusConnection::sessionBus(); - if (!connection.registerService("com.kylin.network") || !connection.registerObject("/com/kylin/network", &w)) { + if (!connection.registerService("com.kylin.network") + || !connection.registerObject("/com/kylin/network", &w) + || !connection.registerObject("/com/kylin/vpnTool", &vpnwindow)) { qCritical() << "QDbus register service failed reason:" << connection.lastError(); } diff --git a/src/org.ukui.kylin-nm.switch.gschema.xml b/src/org.ukui.kylin-nm.switch.gschema.xml index 544f2cd0..f7fa75de 100644 --- a/src/org.ukui.kylin-nm.switch.gschema.xml +++ b/src/org.ukui.kylin-nm.switch.gschema.xml @@ -11,4 +11,11 @@ Wired switch.true is open,false is close. + + + false + vpnicon visible + vpnicon visible.true is visible,false is invisible. + + From 122b1d934b1d071195982db79d5ed19645e487f6 Mon Sep 17 00:00:00 2001 From: chenxuechao Date: Tue, 1 Nov 2022 11:15:15 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E8=A7=A3=E5=86=B3VPN=E5=B4=A9=E6=BA=83?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=88=A0=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=AE=9E=E7=8E=B0dbus?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbus-interface/kylinagentinterface.c | 16 +++++----- .../dbus-interface/kylinconnectresource.cpp | 29 +++++++++++++++++++ .../kylinnetworkresourcemanager.cpp | 2 ++ src/backend/vpndbusadaptor.cpp | 9 +++--- src/backend/vpndbusadaptor.h | 2 +- src/frontend/single-pages/vpnpage.cpp | 24 ++++++++------- src/frontend/single-pages/vpnpage.h | 7 +++-- src/frontend/tab-pages/wlanpage.cpp | 10 +++---- src/frontend/vpnmainwindow.cpp | 6 ++-- src/frontend/vpnmainwindow.h | 2 +- 10 files changed, 71 insertions(+), 36 deletions(-) diff --git a/src/backend/dbus-interface/kylinagentinterface.c b/src/backend/dbus-interface/kylinagentinterface.c index 35a7d41a..d8c21c0b 100644 --- a/src/backend/dbus-interface/kylinagentinterface.c +++ b/src/backend/dbus-interface/kylinagentinterface.c @@ -212,14 +212,6 @@ wifi_get_secrets (SecretsRequest *req, GError **error) g_return_val_if_fail (!info->dialog, FALSE); -#if GTK_CHECK_VERSION(3,90,0) - gtk_init (); -#else - int argc = 0; - char ***argv = NULL; - gtk_init (&argc, &argv); -#endif - NMClient *nm_client = nm_client_new (NULL, NULL); if (!nm_client) { g_set_error (error, @@ -409,6 +401,14 @@ void agent_init() GError *error = NULL; kylinAgent = applet_agent_new (&error); +#if GTK_CHECK_VERSION(3,90,0) + gtk_init (); +#else + int argc = 0; + char ***argv = NULL; + gtk_init (&argc, &argv); +#endif + g_signal_connect (kylinAgent, APPLET_AGENT_GET_SECRETS, G_CALLBACK (applet_agent_get_secrets_cb), NULL); g_signal_connect (kylinAgent, APPLET_AGENT_CANCEL_SECRETS, diff --git a/src/backend/dbus-interface/kylinconnectresource.cpp b/src/backend/dbus-interface/kylinconnectresource.cpp index c95fa223..dfdfb1cb 100644 --- a/src/backend/dbus-interface/kylinconnectresource.cpp +++ b/src/backend/dbus-interface/kylinconnectresource.cpp @@ -42,11 +42,36 @@ static bool subLanListSort(const KyConnectItem* info1, const KyConnectItem* info return result; } +static bool subVpnListSort(const KyConnectItem* info1, const KyConnectItem* info2) +{ + if (info1->m_connectState != info2->m_connectState) { + if (info1->m_connectState == 2) { + return true; + } + + if (info2->m_connectState == 2) { + return false; + } + } + QString name1 = info1->m_connectName; + QString name2 = info2->m_connectName; + bool result = true; + if (QString::compare(name1, name2, Qt::CaseInsensitive) > 0) { + result = false; + } + return result; +} + static void lanListSort(QList &list) { qSort(list.begin(), list.end(), subLanListSort); } +static void vpnListSort(QList &list) +{ + qSort(list.begin(), list.end(), subVpnListSort); +} + KyConnectResourse::KyConnectResourse(QObject *parent) : QObject(parent) { m_networkResourceInstance = KyNetworkResourceManager::getInstance(); @@ -249,6 +274,10 @@ void KyConnectResourse::getVpnAndVirtualConnections(QList &conn connectPtr = nullptr; } + + if (connectItemList.size() > 1) { + vpnListSort(connectItemList); + } } void KyConnectResourse::getConnectionList(QString deviceName, diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp index 0737a0bd..084f600e 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp @@ -52,6 +52,8 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa qRegisterMetaType("NetworkManager::Device::Type"); qRegisterMetaType("NetworkManager::Device::State"); qRegisterMetaType("NetworkManager::Device::StateChangeReason"); + qRegisterMetaType("NetworkManager::VpnConnection::State"); + qRegisterMetaType("NetworkManager::VpnConnection::StateChangeReason"); QDBusConnection::systemBus().connect(QString("org.freedesktop.DBus"), QString("/org/freedesktop/DBus"), diff --git a/src/backend/vpndbusadaptor.cpp b/src/backend/vpndbusadaptor.cpp index a811a535..1b43deb0 100644 --- a/src/backend/vpndbusadaptor.cpp +++ b/src/backend/vpndbusadaptor.cpp @@ -28,7 +28,6 @@ VpnDbusAdaptor::VpnDbusAdaptor(vpnMainWindow *parent) qDBusRegisterMetaType >(); qDBusRegisterMetaType >(); qDBusRegisterMetaType >(); - qDBusRegisterMetaType >>(); //setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发 setAutoRelaySignals(true); } @@ -39,11 +38,11 @@ VpnDbusAdaptor::~VpnDbusAdaptor() } //虚拟连接列表 -QMap> VpnDbusAdaptor::getVirtualList() +QVector VpnDbusAdaptor::getVirtualList() { - QMap> map; - parent()->getVirtualList(map); - return map; + QVector vector; + parent()->getVirtualList(vector); + return vector; } //删除 diff --git a/src/backend/vpndbusadaptor.h b/src/backend/vpndbusadaptor.h index c54ea2a9..2fba0c84 100644 --- a/src/backend/vpndbusadaptor.h +++ b/src/backend/vpndbusadaptor.h @@ -48,7 +48,7 @@ public: public: // PROPERTIES public Q_SLOTS: // METHODS //虚拟连接列表 - QMap > getVirtualList(); + QVector getVirtualList(); //刪除 根据网络名称 参数1 0:lan 1:wlan 参数2 为ssid/uuid Q_NOREPLY void deleteVpn(QString uuid); //连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid diff --git a/src/frontend/single-pages/vpnpage.cpp b/src/frontend/single-pages/vpnpage.cpp index 5e2c553b..3ed01a2f 100644 --- a/src/frontend/single-pages/vpnpage.cpp +++ b/src/frontend/single-pages/vpnpage.cpp @@ -49,7 +49,7 @@ VpnPage::VpnPage(QWidget *parent) : SinglePage(parent) initUI(); initVpnArea(); - connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &VpnPage::onConnectionStateChange); + connect(m_activeResourse, &KyActiveConnectResourse::vpnConnectChangeReason, this, &VpnPage::onConnectionStateChange); connect(m_activeResourse, &KyActiveConnectResourse::activeConnectRemove, this, [=] (QString activeConnectUuid) { sendVpnStateChangeSignal(activeConnectUuid,Deactivated); } ); @@ -356,12 +356,12 @@ void VpnPage::updateConnectionState(QMap &connectMap } void VpnPage::onConnectionStateChange(QString uuid, - NetworkManager::ActiveConnection::State state, - NetworkManager::ActiveConnection::Reason reason) + NetworkManager::VpnConnection::State state, + NetworkManager::VpnConnection::StateChangeReason reason) { //VpnPage函数内持续监听连接状态的变化并记录供其他函数调用获取状态 if (!m_connectResourse->isVirtualConncection(uuid)) { - qDebug() << "[VpnPage] connection state change signal but not wired"; + qDebug() << "[VpnPage] connection state change signal but not vpn"; return; } @@ -417,16 +417,17 @@ void VpnPage::onConnectionStateChange(QString uuid, } -void VpnPage::getVirtualList(QMap > &map) +void VpnPage::getVirtualList(QVector &vector) { QList netConnectList; - QVector vector; + vector.clear(); m_connectResourse->getVpnAndVirtualConnections(netConnectList); //未激活列表的显示 if (!netConnectList.isEmpty()) { for (int i = 0; i < netConnectList.size(); i++) { - vector.clear(); - vector.append(QStringList()<m_connectName<m_connectUuid << netConnectList.at(i)->m_connectPath); - map.insert(netConnectList.at(i)->m_connectUuid, vector); + vector.append(QStringList() << netConnectList.at(i)->m_connectName + << netConnectList.at(i)->m_connectUuid + << netConnectList.at(i)->m_connectPath + << QString::number(netConnectList.at(i)->m_connectState)); } } return; @@ -444,7 +445,10 @@ void VpnPage::sendVpnUpdateSignal(KyConnectItem *p_connectItem) void VpnPage::sendVpnAddSignal(KyConnectItem *p_connectItem) { QStringList info; - info << p_connectItem->m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath; + info << p_connectItem->m_connectName + << p_connectItem->m_connectUuid + << p_connectItem->m_connectPath + << QString::number(p_connectItem->m_connectState); qDebug() << "[VpnPage] emit vpnAdd because addConnection "; Q_EMIT vpnAdd(info); diff --git a/src/frontend/single-pages/vpnpage.h b/src/frontend/single-pages/vpnpage.h index c15a101d..c064bd75 100644 --- a/src/frontend/single-pages/vpnpage.h +++ b/src/frontend/single-pages/vpnpage.h @@ -45,7 +45,7 @@ public: ~VpnPage(); //for dbus - void getVirtualList(QMap > &map); + void getVirtualList(QVector &vector); void deleteVpn(const QString &connUuid); void activateVpn(const QString& connUuid); void deactivateVpn(const QString& connUuid); @@ -94,8 +94,9 @@ Q_SIGNALS: void vpnConnectChanged(int state); private Q_SLOTS: - void onConnectionStateChange(QString uuid, NetworkManager::ActiveConnection::State state, - NetworkManager::ActiveConnection::Reason reason); + void onConnectionStateChange(QString uuid, + NetworkManager::VpnConnection::State state, + NetworkManager::VpnConnection::StateChangeReason reason); void onAddConnection(QString uuid); void onRemoveConnection(QString path); diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index efe6ea31..70e2ac60 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -928,6 +928,11 @@ void WlanPage::onConnectionStateChanged(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) { + if (!m_connectResource->isWirelessConnection(uuid)) { + qDebug()<< LOG_FLAG << "it is not wireless connection" << uuid; + return; + } + QString devName, ssid; m_wirelessNetResource->getSsidByUuid(uuid, ssid); m_wirelessNetResource->getDeviceByUuid(uuid, devName); @@ -942,11 +947,6 @@ void WlanPage::onConnectionStateChanged(QString uuid, return; } - if (!m_connectResource->isWirelessConnection(uuid)) { - qDebug()<< LOG_FLAG << "it is not wireless connection" << uuid; - return; - } - Q_EMIT this->wlanConnectChanged(state); bool isApConnection = m_connectResource->isApConnection(uuid); diff --git a/src/frontend/vpnmainwindow.cpp b/src/frontend/vpnmainwindow.cpp index a5461c24..4238cd33 100644 --- a/src/frontend/vpnmainwindow.cpp +++ b/src/frontend/vpnmainwindow.cpp @@ -466,11 +466,11 @@ bool vpnMainWindow::eventFilter(QObject *watched, QEvent *event) return QMainWindow::eventFilter(watched,event); } -void vpnMainWindow::getVirtualList(QMap> &map) +void vpnMainWindow::getVirtualList(QVector &vector) { - map.clear(); + vector.clear(); if (nullptr != m_vpnPage) { - m_vpnPage->getVirtualList(map); + m_vpnPage->getVirtualList(vector); } } diff --git a/src/frontend/vpnmainwindow.h b/src/frontend/vpnmainwindow.h index 72584067..341efe85 100644 --- a/src/frontend/vpnmainwindow.h +++ b/src/frontend/vpnmainwindow.h @@ -45,7 +45,7 @@ public: void showMainwindow(); void hideMainwindow(); - void getVirtualList(QMap> &map); + void getVirtualList(QVector &vector); //Vpn连接删除 From 1bf02f0d0d28bb053b66cdcfbc5c0af1269d56db Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Mon, 31 Oct 2022 09:16:27 +0800 Subject: [PATCH 3/6] fix merge --- plugins/plugin.pro | 3 +- plugins/vpn/itemframe.cpp | 62 ++++++++ plugins/vpn/itemframe.h | 47 ++++++ plugins/vpn/vpn.cpp | 248 +++++++++++++++++++++++++++++ plugins/vpn/vpn.h | 108 +++++++++++++ plugins/vpn/vpn.pro | 44 +++++ plugins/vpn/vpn.ui | 112 +++++++++++++ plugins/vpn/vpnitem.cpp | 124 +++++++++++++++ plugins/vpn/vpnitem.h | 71 +++++++++ plugins/wlanconnect/wlanconnect.ui | 2 +- 10 files changed, 819 insertions(+), 2 deletions(-) create mode 100644 plugins/vpn/itemframe.cpp create mode 100644 plugins/vpn/itemframe.h create mode 100644 plugins/vpn/vpn.cpp create mode 100644 plugins/vpn/vpn.h create mode 100644 plugins/vpn/vpn.pro create mode 100644 plugins/vpn/vpn.ui create mode 100644 plugins/vpn/vpnitem.cpp create mode 100644 plugins/vpn/vpnitem.h diff --git a/plugins/plugin.pro b/plugins/plugin.pro index cee11d57..1ef03f43 100644 --- a/plugins/plugin.pro +++ b/plugins/plugin.pro @@ -3,4 +3,5 @@ SUBDIRS = \ netconnect \ wlanconnect \ mobilehotspot \ - proxy + proxy \ + vpn diff --git a/plugins/vpn/itemframe.cpp b/plugins/vpn/itemframe.cpp new file mode 100644 index 00000000..61fc23d1 --- /dev/null +++ b/plugins/vpn/itemframe.cpp @@ -0,0 +1,62 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include "itemframe.h" +#include + +#define LAYOUT_MARGINS 0,0,0,0 +#define MAIN_LAYOUT_MARGINS 0,0,0,0 +ItemFrame::ItemFrame(QWidget *parent) + :QFrame(parent) +{ + deviceLanLayout = new QVBoxLayout(this); + deviceLanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); + lanItemFrame = new QFrame(this); + lanItemFrame->setFrameShape(QFrame::Shape::NoFrame); + lanItemFrame->setContentsMargins(LAYOUT_MARGINS); + + lanItemLayout = new QVBoxLayout(this); + lanItemLayout->setContentsMargins(LAYOUT_MARGINS); + lanItemLayout->setSpacing(1); + addWlanWidget = new AddNetBtn(true, this); + + deviceLanLayout->setSpacing(1); + setLayout(deviceLanLayout); + lanItemFrame->setLayout(lanItemLayout); + + deviceLanLayout->addWidget(lanItemFrame); + deviceLanLayout->addWidget(addWlanWidget); +} + +void ItemFrame::filletStyleChange() +{ + if (lanItemLayout->isEmpty()) { + return; + } + + for (int i = 0; i < lanItemLayout->count(); ++i) { + QLayoutItem *it = lanItemLayout->itemAt(i); + VpnItem *itemFrame = (VpnItem*)(it->widget()); + if (i != lanItemLayout->count()-1) { + itemFrame->setHalfFillet(false); + } else { + itemFrame->setHalfFillet(true); + } + } +} diff --git a/plugins/vpn/itemframe.h b/plugins/vpn/itemframe.h new file mode 100644 index 00000000..b41153fa --- /dev/null +++ b/plugins/vpn/itemframe.h @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#ifndef ITEMFRAME_H +#define ITEMFRAME_H +#include +#include +#include "../component/AddBtn/addnetbtn.h" +#include "vpnitem.h" + +class ItemFrame : public QFrame +{ + Q_OBJECT +public: + ItemFrame(QWidget *parent = nullptr); + //单设备整体layout + QVBoxLayout * deviceLanLayout = nullptr; + //单设备列表Frame + QFrame * lanItemFrame = nullptr; + //单设备列表layout + QVBoxLayout * lanItemLayout = nullptr; + //item列表 + QMap itemMap; +// //已激活uuid +// QString uuid = ""; + //新建无线连接 + AddNetBtn * addWlanWidget = nullptr; + void filletStyleChange(); +}; + +#endif // ITEMFRAME_H diff --git a/plugins/vpn/vpn.cpp b/plugins/vpn/vpn.cpp new file mode 100644 index 00000000..27702e51 --- /dev/null +++ b/plugins/vpn/vpn.cpp @@ -0,0 +1,248 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include "vpn.h" +#include "ui_vpn.h" + +#include +#include +#include + +#define LABEL_RECT 17, 0, 105, 23 +#define CONTENTS_MARGINS 0, 0, 0, 0 +#define ITEM_MARGINS 16, 0, 16, 0 +#define FRAME_MIN_SIZE 550, 60 +#define FRAME_MAX_SIZE 16777215, 16777215 +#define CONTECT_FRAME_MAX_SIZE 16777215, 60 +#define HINT_TEXT_MARGINS 8, 0, 0, 0 +#define FRAME_MIN_SIZE 550, 60 +#define LABLE_MIN_WIDTH 188 +#define COMBOBOX_MIN_WIDTH 200 +#define LINE_MAX_SIZE 16777215, 1 +#define LINE_MIN_SIZE 0, 1 +#define ICON_SIZE 24,24 +#define PASSWORD_FRAME_MIN_HIGHT 60 +#define PASSWORD_FRAME_FIX_HIGHT 80 +#define PASSWORD_FRAME_MIN_SIZE 550, 60 +#define PASSWORD_FRAME_MAX_SIZE 16777215, 86 +#define PASSWORD_ITEM_MARGINS 16, 12, 16, 14 + +#define KVpnSymbolic "ukui-vpn-symbolic" + +Vpn::Vpn() : mFirstLoad(true) +{ + pluginName = tr("Vpn"); + pluginType = NETWORK; +} + +Vpn::~Vpn() +{ + if (!mFirstLoad) { + delete ui; + ui = nullptr; + } +} + +QString Vpn::plugini18nName(){ + return pluginName; +} + +int Vpn::pluginTypes(){ + return pluginType; +} + +QWidget *Vpn::pluginUi(){ + if (mFirstLoad) { + mFirstLoad = false; + ui = new Ui::Vpn; + pluginWidget = new QWidget; + pluginWidget->setAttribute(Qt::WA_DeleteOnClose); + ui->setupUi(pluginWidget); + + initComponent(); + } + return pluginWidget; +} + +const QString Vpn::name() const { + + return QStringLiteral("Vpn"); +} + +bool Vpn::isShowOnHomePage() const +{ + return true; +} + +QIcon Vpn::icon() const +{ + return QIcon::fromTheme("ukui-vpn-symbolic"); +} + +bool Vpn::isEnable() const +{ + return true; +} + +void Vpn::initComponent(){ + //在任务栏上显示图标 + //显示已连接时间 + m_topFrame = new QFrame(pluginWidget); + m_topFrame->setMinimumSize(FRAME_MIN_SIZE); + m_topFrame->setMaximumSize(FRAME_MAX_SIZE); + m_topFrame->setFrameShape(QFrame::Box); + + QVBoxLayout *hotspotLyt = new QVBoxLayout(pluginWidget); + hotspotLyt->setContentsMargins(0, 0, 0, 0); + m_topFrame->setLayout(hotspotLyt); + + m_showFrame = new QFrame(m_topFrame); + m_showFrame->setFrameShape(QFrame::Shape::NoFrame); + m_showFrame->setMinimumSize(FRAME_MIN_SIZE); + m_showFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE); + QHBoxLayout *showLayout = new QHBoxLayout(m_showFrame); + m_showLabel = new QLabel(tr("Open"), m_showFrame); + m_showLabel->setMinimumWidth(LABLE_MIN_WIDTH); + m_showBtn = new KSwitchButton(m_showFrame); + showLayout->setContentsMargins(ITEM_MARGINS); + showLayout->addWidget(m_showLabel); + showLayout->addStretch(); + showLayout->addWidget(m_showBtn); + + m_showFrame->setLayout(showLayout); + + m_Line = myLine(); + + m_timeFrame = new QFrame(m_topFrame); + m_timeFrame->setFrameShape(QFrame::Shape::NoFrame); + m_timeFrame->setMinimumSize(FRAME_MIN_SIZE); + m_timeFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE); + QHBoxLayout *timeLayout = new QHBoxLayout(m_timeFrame); + m_timeLabel = new QLabel(tr("Open"), m_timeFrame); + m_timeLabel->setMinimumWidth(LABLE_MIN_WIDTH); + m_timeBtn = new KSwitchButton(m_timeFrame); + timeLayout->setContentsMargins(ITEM_MARGINS); + timeLayout->addWidget(m_timeLabel); + timeLayout->addStretch(); + timeLayout->addWidget(m_timeBtn); + + m_timeFrame->setLayout(timeLayout); + + hotspotLyt->addWidget(m_showFrame); + hotspotLyt->addWidget(m_Line); + hotspotLyt->addWidget(m_timeFrame); + hotspotLyt->setSpacing(0); + + //列表 + m_listFrame = new ItemFrame(pluginWidget); + + ui->verticalLayout_4->addWidget(m_topFrame); + ui->verticalLayout_3->addWidget(m_listFrame); + + connect(m_listFrame->addWlanWidget, &AddNetBtn::clicked, this, [=]() { + runExternalApp(); + }); +} + +void Vpn::runExternalApp(){ + QString cmd = "nm-connection-editor"; + QProcess process(this); + process.startDetached(cmd); +} + +QFrame* Vpn::myLine() +{ + QFrame *line = new QFrame(pluginWidget); + line->setMinimumSize(QSize(LINE_MIN_SIZE)); + line->setMaximumSize(QSize(LINE_MAX_SIZE)); + line->setLineWidth(0); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + + return line; +} + + + + +//增加一项 +void Vpn::addOneVirtualItem(QStringList infoList) +{ + if (m_listFrame->itemMap.contains(infoList.at(1))) { + qDebug() << "[Vpn]Already exist a virtual " << infoList.at(1); + return; + } + + qDebug() << "[Vpn]addOneVitualItem" << infoList.at(0); + QString connName = infoList.at(0); + QString connUuid = infoList.at(1); + QString connDbusPath = infoList.at(2); + VpnItem * lanItem = new VpnItem(pluginWidget); + + QString iconPath; + iconPath = KVpnSymbolic; + lanItem->statusLabel->setText(""); + + QIcon searchIcon = QIcon::fromTheme(iconPath); + lanItem->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE)))); + lanItem->titileLabel->setText(connName); + + lanItem->uuid = connUuid; + lanItem->dbusPath = connDbusPath; + +// connect(lanItem->infoLabel, &GrayInfoButton::clicked, this, [=]{ +// // open landetail page +// if (!m_interface->isValid()) { +// return; +// } +// qDebug() << "[NetConnect]call showPropertyWidget" << deviceName << connUuid << __LINE__; +// m_interface->call(QStringLiteral("showPropertyWidget"), deviceName, connUuid); +// qDebug() << "[NetConnect]call showPropertyWidget respond" << __LINE__; +// }); + + lanItem->isAcitve = false; + + connect(lanItem, &QPushButton::clicked, this, [=] { + if (lanItem->isAcitve || lanItem->loading) { + deActiveConnect(lanItem->uuid, deviceName, WIRED_TYPE); + } else { + activeConnect(lanItem->uuid, deviceName, WIRED_TYPE); + } + }); + + //记录到deviceFrame的itemMap中 + m_listFrame->itemMap.insert(connUuid, lanItem); + int index = getInsertPos(connName); + qDebug()<<"[NetConnect]addOneVirtualItem " << connName << " to " << deviceName << " list at pos:" << index; + m_listFrame->lanItemLayout->insertWidget(index, lanItem); +} + +void Vpn::removeOneVirtualItem(QString uuid) +{ + if (!m_listFrame->itemMap.contains(uuid)) { + qDebug() << "[Vpn]not exist a virtual " << uuid; + return; + } + + qDebug()<<"[Vpn]removeOneVirtualItem " << uuid; + + m_listFrame->lanItemLayout->removeWidget(m_listFrame->itemMap[uuid]); + delete m_listFrame->itemMap[uuid]; + m_listFrame->itemMap.remove(uuid); +} diff --git a/plugins/vpn/vpn.h b/plugins/vpn/vpn.h new file mode 100644 index 00000000..14793f43 --- /dev/null +++ b/plugins/vpn/vpn.h @@ -0,0 +1,108 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#ifndef VPN_H +#define VPN_H + +#include +#include +#include +#include +#include + +#include "interface.h" +#include "addbtn.h" +#include "imageutil.h" +#include "kwidget.h" +#include "kswitchbutton.h" +#include "itemframe.h" + +using namespace kdk; + +namespace Ui { +class Vpn; +} + +class Vpn : public QObject, CommonInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface") + Q_INTERFACES(CommonInterface) + +public: + Vpn(); + ~Vpn(); + + QString plugini18nName() Q_DECL_OVERRIDE; + int pluginTypes() Q_DECL_OVERRIDE; + QWidget * pluginUi() Q_DECL_OVERRIDE; + const QString name() const Q_DECL_OVERRIDE; + bool isShowOnHomePage() const Q_DECL_OVERRIDE; + QIcon icon() const Q_DECL_OVERRIDE; + bool isEnable() const Q_DECL_OVERRIDE; + +public: + void initComponent(); + + void runExternalApp(); + +protected: +// bool eventFilter(QObject *watched, QEvent *event); + +private: + Ui::Vpn *ui; + + QString pluginName; + int pluginType; + QWidget * pluginWidget; + + QFrame *m_topFrame; + QFrame *m_showFrame; + QLabel *m_showLabel; + KSwitchButton *m_showBtn; + QFrame *m_Line; + QFrame *m_timeFrame; + QLabel *m_timeLabel; + KSwitchButton *m_timeBtn; + ItemFrame *m_listFrame; + + bool mFirstLoad; + + QFrame* myLine(); + + int getInsertPos(QString connName); + + void deleteOneLan(QString uuid); + void activeConnect(QString uuid); + void deActiveConnect(QString uuid); + + //获取设备列表 + void initNet(); + //处理列表增加 + void addLanItem(QStringList infoList, bool isActived); + //增加一项 + void addOneVirtualItem(QStringList infoList); + //减少一项 + void removeOneVirtualItem(QString uuid); + //单个lan连接状态变化 + void itemActiveConnectionStatusChanged(VpnItem *item, int status); + +}; + +#endif // VPN_H diff --git a/plugins/vpn/vpn.pro b/plugins/vpn/vpn.pro new file mode 100644 index 00000000..4884bc97 --- /dev/null +++ b/plugins/vpn/vpn.pro @@ -0,0 +1,44 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2019-06-29T13:53:10 +# +#------------------------------------------------- + +QT += widgets dbus + +TEMPLATE = lib +CONFIG += plugin \ + c++11 \ + link_pkgconfig + +include(../component/addbtn.pri) + +PKGCONFIG += gsettings-qt \ + kysdk-qtwidgets \ + +TARGET = $$qtLibraryTarget(vpn) +DESTDIR = ../.. +target.path = $$[QT_INSTALL_LIBS]/ukui-control-center + +INCLUDEPATH += \ + $$PROJECT_COMPONENTSOURCE \ + $$PROJECT_ROOTDIR \ + /usr/include/ukcc/interface \ + /usr/include/ukcc/widgets + +LIBS += -L$$[QT_INSTALL_LIBS] -lukcc + +SOURCES += \ + vpn.cpp \ + itemframe.cpp \ + vpnitem.cpp + +HEADERS += \ + vpn.h \ + itemframe.h \ + vpnitem.h + +FORMS += \ + vpn.ui + +INSTALLS += target diff --git a/plugins/vpn/vpn.ui b/plugins/vpn/vpn.ui new file mode 100644 index 00000000..bd1de4af --- /dev/null +++ b/plugins/vpn/vpn.ui @@ -0,0 +1,112 @@ + + + Vpn + + + + 0 + 0 + 800 + 710 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Vpn + + + + 8 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + VPN + + + + + + + + + + + + + + + import + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + TitleLabel + QLabel +
titlelabel.h
+
+
+ + +
diff --git a/plugins/vpn/vpnitem.cpp b/plugins/vpn/vpnitem.cpp new file mode 100644 index 00000000..cdaa397f --- /dev/null +++ b/plugins/vpn/vpnitem.cpp @@ -0,0 +1,124 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include "vpnitem.h" +#include +#define FRAME_SPEED 150 +#define LIMIT_TIME 60*1000 +#define TOTAL_PAGE 8 +#define RADIUS 6.0 + +#define THEME_QT_SCHEMA "org.ukui.style" +#define MODE_QT_KEY "style-name" + +VpnItem::VpnItem(bool bAcitve, bool isLock, QWidget *parent) + : isAcitve(bAcitve), isLock(isLock), QPushButton(parent) +{ + this->setMinimumSize(550, 58); + this->setProperty("useButtonPalette", true); + this->setFlat(true); + QPalette pal = this->palette(); + QColor color = pal.color(QPalette::Button); + color.setAlphaF(0.5); + pal.setColor(QPalette::Button, color); + this->setPalette(pal); + QHBoxLayout *mLanLyt = new QHBoxLayout(this); + mLanLyt->setContentsMargins(16,0,16,0); + mLanLyt->setSpacing(16); + iconLabel = new QLabel(this); + titileLabel = new FixLabel(this); + statusLabel = new QLabel(this); + statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); +// statusLabel->setMinimumSize(36,36); +// infoLabel = new GrayInfoButton(this); + mLanLyt->addWidget(iconLabel); + mLanLyt->addWidget(titileLabel,Qt::AlignLeft); + mLanLyt->addStretch(); + mLanLyt->addWidget(statusLabel); +// mLanLyt->addWidget(infoLabel); + + loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-3-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-4-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-5-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-6-symbolic")); + loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic")); + + waitTimer = new QTimer(this); + connect(waitTimer, &QTimer::timeout, this, &VpnItem::updateIcon); + +} + +void VpnItem::updateIcon() +{ + if (currentIconIndex > 6) { + currentIconIndex = 0; + } + statusLabel->setPixmap(loadIcons.at(currentIconIndex).pixmap(16,16)); + currentIconIndex ++; +} + +void VpnItem::startLoading() +{ + waitTimer->start(FRAME_SPEED); + loading = true; +} + +void VpnItem::stopLoading(){ + waitTimer->stop(); + loading = false; +} + +void VpnItem::paintEvent(QPaintEvent *event) +{ + QPalette pal = this->palette(); + + QPainter painter(this); + painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿 + painter.setPen(Qt::NoPen); + painter.setBrush(pal.color(QPalette::Base)); + + QRect rect = this->rect(); + +#if 0 + if (!useHalfFillet) { + painter.drawRect(rect); + } else { + QPainterPath path; +// path.addRoundedRect (rect, RADIUS, RADIUS); +// QRect temp_rect(rect.left(), rect.top(), rect.width(), rect.height()/2); +// path.addRect(temp_rect); + //设置起点 + path.moveTo(rect.topLeft().x(), rect.topLeft().y()); + path.lineTo(rect.bottomLeft().x(), rect.bottomLeft().y() - RADIUS); + //绘制圆角 圆弧以外切圆的270度位置为起点,逆时针画圆弧运行90度结束 + path.arcTo(QRect(QPoint(rect.bottomLeft().x(), rect.bottomLeft().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 180, 90); + path.lineTo(rect.bottomRight().x() - RADIUS, rect.bottomRight().y()); + //画圆弧 + path.arcTo(QRect(QPoint(rect.bottomRight().x() - (RADIUS * 2), rect.bottomRight().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 270, 90); + path.lineTo(rect.topRight()); + path.lineTo(rect.topLeft()); + painter.drawPath(path); + } +#endif + + painter.drawRect(rect); + QPushButton::paintEvent(event); +} diff --git a/plugins/vpn/vpnitem.h b/plugins/vpn/vpnitem.h new file mode 100644 index 00000000..4e79cd3e --- /dev/null +++ b/plugins/vpn/vpnitem.h @@ -0,0 +1,71 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#ifndef VPNITEM_H +#define VPNITEM_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "fixlabel.h" +//#include "infobutton.h" +#include "../component/AddBtn/grayinfobutton.h" + +class VpnItem : public QPushButton +{ +public: + VpnItem(bool bAcitve, bool isLock, QWidget *parent = nullptr); +public: + QLabel * iconLabel = nullptr; +// GrayInfoButton * infoLabel = nullptr; + FixLabel * titileLabel = nullptr; + QLabel * statusLabel = nullptr; + QString uuid = ""; + + void setHalfFillet(bool flag) {useHalfFillet = flag; repaint();} +public: + void startLoading(); + void stopLoading(); + bool isAcitve = false; + bool loading = false; + bool isLock = false; + + + +protected: + void paintEvent(QPaintEvent *event); + +private: + QTimer *waitTimer = nullptr; + QGSettings *themeGsettings = nullptr; + bool useHalfFillet = false; + QList loadIcons; + int currentIconIndex=0; + +private slots: + void updateIcon(); + +}; + +#endif // VPNITEM_H diff --git a/plugins/wlanconnect/wlanconnect.ui b/plugins/wlanconnect/wlanconnect.ui index fa8cfe41..99b9e7c2 100644 --- a/plugins/wlanconnect/wlanconnect.ui +++ b/plugins/wlanconnect/wlanconnect.ui @@ -184,7 +184,7 @@ TitleLabel QLabel -
titlelabel.h
+
titlelabel.h
From f490fe0ff0c25170bd6cc2144acab892531255ea Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Mon, 31 Oct 2022 17:51:35 +0800 Subject: [PATCH 4/6] vpn --- plugins/component/AddBtn/addnetbtn.cpp | 7 +- plugins/component/AddBtn/addnetbtn.h | 8 + plugins/vpn/itemframe.cpp | 3 +- plugins/vpn/vpn.cpp | 324 +++++++++++++++++++++---- plugins/vpn/vpn.h | 17 +- plugins/vpn/vpnitem.cpp | 69 +++++- plugins/vpn/vpnitem.h | 27 ++- 7 files changed, 394 insertions(+), 61 deletions(-) diff --git a/plugins/component/AddBtn/addnetbtn.cpp b/plugins/component/AddBtn/addnetbtn.cpp index f186a922..eb1bc6fb 100644 --- a/plugins/component/AddBtn/addnetbtn.cpp +++ b/plugins/component/AddBtn/addnetbtn.cpp @@ -20,7 +20,6 @@ #include "addnetbtn.h" #include #include -#include #include #include #include @@ -39,10 +38,10 @@ AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent) color.setAlphaF(0.5); pal.setColor(QPalette::Button, color); this->setPalette(pal); - QHBoxLayout *addLyt = new QHBoxLayout; + QHBoxLayout *addLyt = new QHBoxLayout(this); - QLabel *iconLabel = new QLabel(); - QLabel *textLabel = new QLabel(); + QLabel *iconLabel = new QLabel(this); + textLabel = new QLabel(this); if (isWlan) { textLabel->setText(tr("Add Others")); diff --git a/plugins/component/AddBtn/addnetbtn.h b/plugins/component/AddBtn/addnetbtn.h index 959d2d09..60ba8028 100644 --- a/plugins/component/AddBtn/addnetbtn.h +++ b/plugins/component/AddBtn/addnetbtn.h @@ -25,6 +25,7 @@ #include #include #include +#include class AddNetBtn : public QPushButton { @@ -33,11 +34,18 @@ public: AddNetBtn(bool isWlan, QWidget *parent = nullptr); ~AddNetBtn(); + void setTextLabel(QString str) { + textLabel->setText(str); + } + protected: virtual void leaveEvent(QEvent * event); virtual void enterEvent(QEvent * event); void paintEvent(QPaintEvent *event); +private: + QLabel* textLabel; + Q_SIGNALS: void enterWidget(); void leaveWidget(); diff --git a/plugins/vpn/itemframe.cpp b/plugins/vpn/itemframe.cpp index 61fc23d1..816828f7 100644 --- a/plugins/vpn/itemframe.cpp +++ b/plugins/vpn/itemframe.cpp @@ -34,7 +34,8 @@ ItemFrame::ItemFrame(QWidget *parent) lanItemLayout = new QVBoxLayout(this); lanItemLayout->setContentsMargins(LAYOUT_MARGINS); lanItemLayout->setSpacing(1); - addWlanWidget = new AddNetBtn(true, this); + addWlanWidget = new AddNetBtn(false, this); + addWlanWidget->setTextLabel(tr("Add Vpn")); deviceLanLayout->setSpacing(1); setLayout(deviceLanLayout); diff --git a/plugins/vpn/vpn.cpp b/plugins/vpn/vpn.cpp index 27702e51..b6b05dae 100644 --- a/plugins/vpn/vpn.cpp +++ b/plugins/vpn/vpn.cpp @@ -23,6 +23,13 @@ #include #include #include +#include +#include + +#define ACTIVATING 1 +#define ACTIVATED 2 +#define DEACTIVATING 3 +#define DEACTIVATED 4 #define LABEL_RECT 17, 0, 105, 23 #define CONTENTS_MARGINS 0, 0, 0, 0 @@ -45,6 +52,9 @@ #define KVpnSymbolic "ukui-vpn-symbolic" +const QString VISIBLE = "visible"; +const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.vpnicon"; + Vpn::Vpn() : mFirstLoad(true) { pluginName = tr("Vpn"); @@ -56,6 +66,8 @@ Vpn::~Vpn() if (!mFirstLoad) { delete ui; ui = nullptr; + delete m_interface; + delete m_switchGsettings; } } @@ -75,7 +87,18 @@ QWidget *Vpn::pluginUi(){ pluginWidget->setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(pluginWidget); + qDBusRegisterMetaType>(); + m_interface = new QDBusInterface("com.kylin.network", + "/com/kylin/vpnTool", + "com.kylin.vpnTool", + QDBusConnection::sessionBus()); + if(!m_interface->isValid()) { + qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); + } + initComponent(); + initConnect(); + initNet(); } return pluginWidget; } @@ -117,7 +140,7 @@ void Vpn::initComponent(){ m_showFrame->setMinimumSize(FRAME_MIN_SIZE); m_showFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE); QHBoxLayout *showLayout = new QHBoxLayout(m_showFrame); - m_showLabel = new QLabel(tr("Open"), m_showFrame); + m_showLabel = new QLabel(tr("Show on Taskbar"), m_showFrame); m_showLabel->setMinimumWidth(LABLE_MIN_WIDTH); m_showBtn = new KSwitchButton(m_showFrame); showLayout->setContentsMargins(ITEM_MARGINS); @@ -127,26 +150,26 @@ void Vpn::initComponent(){ m_showFrame->setLayout(showLayout); - m_Line = myLine(); +// m_Line = myLine(); - m_timeFrame = new QFrame(m_topFrame); - m_timeFrame->setFrameShape(QFrame::Shape::NoFrame); - m_timeFrame->setMinimumSize(FRAME_MIN_SIZE); - m_timeFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE); - QHBoxLayout *timeLayout = new QHBoxLayout(m_timeFrame); - m_timeLabel = new QLabel(tr("Open"), m_timeFrame); - m_timeLabel->setMinimumWidth(LABLE_MIN_WIDTH); - m_timeBtn = new KSwitchButton(m_timeFrame); - timeLayout->setContentsMargins(ITEM_MARGINS); - timeLayout->addWidget(m_timeLabel); - timeLayout->addStretch(); - timeLayout->addWidget(m_timeBtn); +// m_timeFrame = new QFrame(m_topFrame); +// m_timeFrame->setFrameShape(QFrame::Shape::NoFrame); +// m_timeFrame->setMinimumSize(FRAME_MIN_SIZE); +// m_timeFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE); +// QHBoxLayout *timeLayout = new QHBoxLayout(m_timeFrame); +// m_timeLabel = new QLabel(tr("Open"), m_timeFrame); +// m_timeLabel->setMinimumWidth(LABLE_MIN_WIDTH); +// m_timeBtn = new KSwitchButton(m_timeFrame); +// timeLayout->setContentsMargins(ITEM_MARGINS); +// timeLayout->addWidget(m_timeLabel); +// timeLayout->addStretch(); +// timeLayout->addWidget(m_timeBtn); - m_timeFrame->setLayout(timeLayout); +// m_timeFrame->setLayout(timeLayout); hotspotLyt->addWidget(m_showFrame); - hotspotLyt->addWidget(m_Line); - hotspotLyt->addWidget(m_timeFrame); +// hotspotLyt->addWidget(m_Line); +// hotspotLyt->addWidget(m_timeFrame); hotspotLyt->setSpacing(0); //列表 @@ -158,6 +181,81 @@ void Vpn::initComponent(){ connect(m_listFrame->addWlanWidget, &AddNetBtn::clicked, this, [=]() { runExternalApp(); }); + + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { + m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); + setShowSwitchStatus(); + + connect(m_switchGsettings, &QGSettings::changed, this, [=] (const QString &key) { + if (key == VISIBLE) { + setShowSwitchStatus(); + } + }); + } else { + m_showBtn->setChecked(false); + m_showBtn->setCheckable(false); + qDebug()<<"[Vpn] org.ukui.kylin-nm.visible is not installed!"; + } + + connect(m_showBtn, &KSwitchButton::stateChanged, this, [=](bool state){ + if (m_switchGsettings != nullptr) { + m_switchGsettings->set(VISIBLE, state); + } + }); + +// connect(m_timeBtn, &KSwitchButton::stateChanged, this, [=](bool state){ +// if (m_switchGsettings != nullptr) { +// m_switchGsettings->set(VISIBLE, state); +// } +// }); + ui->pushButton->hide(); +} + +void Vpn::initConnect() +{ + connect(m_interface, SIGNAL(vpnAdd(QStringList)), this, SLOT(onVpnAdd(QStringList))); + connect(m_interface, SIGNAL(vpnRemove(QString)), this, SLOT(onVpnRemove(QString))); + connect(m_interface, SIGNAL(vpnUpdate(QStringList)), this, SLOT(onVpnUpdate(QStringList))); + connect(m_interface, SIGNAL(vpnActiveConnectionStateChanged(QString, int)), + this, SLOT(onVpnActiveConnectionStateChanged(QString, int))); +} + +//初始化列表 +void Vpn::initNet() +{ + qDebug() << "[Vpn]initNet"; + if (!m_interface->isValid()) { + return; + } + QDBusMessage result = m_interface->call(QStringLiteral("getVirtualList")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getVirtualList error:" << result.errorMessage(); + return; + } + auto dbusArg = result.arguments().at(0).value(); + QVector variantList; + dbusArg >> variantList; + if (variantList.size() == 0) { + qDebug() << "[Vpn]initNet list empty"; + return; + } + + for (int i = 0; i < variantList.size(); ++i) { + QStringList vpnInfo = variantList.at(i); + addOneVirtualItem(vpnInfo); + } + return; +} + +void Vpn::setShowSwitchStatus() +{ + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { + bool status = m_switchGsettings->get(VISIBLE).toBool(); + m_showBtn->setChecked(status); + } else { + qDebug()<<"[Vpn] org.ukui.kylin-nm.switch is not installed!"; + } } void Vpn::runExternalApp(){ @@ -178,7 +276,21 @@ QFrame* Vpn::myLine() return line; } +//刪除 +void Vpn::deleteVpn(QString uuid) +{ + m_interface->call(QStringLiteral("deleteVpn"), uuid); +} +//激活 +void Vpn::activeConnect(QString uuid) { + m_interface->call(QStringLiteral("activateVpn"), uuid); +} + +//断开 +void Vpn::deActiveConnect(QString uuid) { + m_interface->call(QStringLiteral("deactivateVpn"), uuid); +} //增加一项 @@ -189,22 +301,25 @@ void Vpn::addOneVirtualItem(QStringList infoList) return; } - qDebug() << "[Vpn]addOneVitualItem" << infoList.at(0); + qDebug() << "[Vpn]addOneVitualItem" << infoList.at(0) << infoList.at(3) ; QString connName = infoList.at(0); QString connUuid = infoList.at(1); QString connDbusPath = infoList.at(2); - VpnItem * lanItem = new VpnItem(pluginWidget); + int status = infoList.at(3).toInt(); //1-连接中 2-已连接 3-断开中 4-已断开 + VpnItem * item = new VpnItem(pluginWidget); - QString iconPath; - iconPath = KVpnSymbolic; - lanItem->statusLabel->setText(""); + item->statusLabel->setText(tr("not connected")); - QIcon searchIcon = QIcon::fromTheme(iconPath); - lanItem->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE)))); - lanItem->titileLabel->setText(connName); + QIcon searchIcon = QIcon::fromTheme(KVpnSymbolic); + item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE)))); + item->titileLabel->setText(connName); - lanItem->uuid = connUuid; - lanItem->dbusPath = connDbusPath; + item->uuid = connUuid; + item->dbusPath = connDbusPath; + + if (status == 1 || status == 3) { + item->startLoading(); + } // connect(lanItem->infoLabel, &GrayInfoButton::clicked, this, [=]{ // // open landetail page @@ -216,33 +331,152 @@ void Vpn::addOneVirtualItem(QStringList infoList) // qDebug() << "[NetConnect]call showPropertyWidget respond" << __LINE__; // }); - lanItem->isAcitve = false; + item->isAcitve = (status == 2); + item->setConnectActionText(item->isAcitve); - connect(lanItem, &QPushButton::clicked, this, [=] { - if (lanItem->isAcitve || lanItem->loading) { - deActiveConnect(lanItem->uuid, deviceName, WIRED_TYPE); + connect(item, &QPushButton::clicked, this, [=] { + if (item->isAcitve || item->loading) { + deActiveConnect(item->uuid); } else { - activeConnect(lanItem->uuid, deviceName, WIRED_TYPE); + activeConnect(item->uuid); } }); + connect(item, &VpnItem::connectActionTriggered, this, [=] { + activeConnect(item->uuid); + }); + connect(item, &VpnItem::disconnectActionTriggered, this, [=] { + deActiveConnect(item->uuid); + }); + connect(item, &VpnItem::deleteActionTriggered, this, [=] { + deleteVpn(item->uuid); + }); + //记录到deviceFrame的itemMap中 - m_listFrame->itemMap.insert(connUuid, lanItem); + m_listFrame->itemMap.insert(connUuid, item); int index = getInsertPos(connName); - qDebug()<<"[NetConnect]addOneVirtualItem " << connName << " to " << deviceName << " list at pos:" << index; - m_listFrame->lanItemLayout->insertWidget(index, lanItem); + qDebug()<<"[Vpn]addOneVirtualItem " << connName << " at pos:" << index; + m_listFrame->lanItemLayout->insertWidget(index, item); } -void Vpn::removeOneVirtualItem(QString uuid) +void Vpn::removeOneVirtualItem(QString dbusPath) { - if (!m_listFrame->itemMap.contains(uuid)) { - qDebug() << "[Vpn]not exist a virtual " << uuid; - return; - } + qDebug()<<"[Vpn]vpn remove dbus path:" << dbusPath; - qDebug()<<"[Vpn]removeOneVirtualItem " << uuid; - - m_listFrame->lanItemLayout->removeWidget(m_listFrame->itemMap[uuid]); - delete m_listFrame->itemMap[uuid]; - m_listFrame->itemMap.remove(uuid); + QMap::iterator itemIter; + for (itemIter = m_listFrame->itemMap.begin(); itemIter != m_listFrame->itemMap.end(); itemIter++) { + if (itemIter.value()->dbusPath == dbusPath) { + qDebug()<<"[Vpn]vpn remove " << dbusPath << " find in " << itemIter.value()->titileLabel->text(); + QString key = itemIter.key(); + m_listFrame->lanItemLayout->removeWidget(itemIter.value()); + delete itemIter.value(); + m_listFrame->itemMap.remove(key); + break; + } + } +} + +//增加 +void Vpn::onVpnAdd(QStringList infoList) +{ + addOneVirtualItem(infoList); +} + +//移出 +void Vpn::onVpnRemove(QString uuid) +{ + removeOneVirtualItem(uuid); +} + +//名称变化 +void Vpn::onVpnUpdate(QStringList info) +{ + if (m_listFrame->itemMap.contains(info.at(1))) { + qDebug() << "[Vpn]" << m_listFrame->itemMap[info.at(1)]->titileLabel->text() << "change to" << info.at(0); + if (m_listFrame->itemMap[info.at(1)]->titileLabel->text() != info.at(0)) { + m_listFrame->itemMap[info.at(1)]->titileLabel->setText(info.at(0)); + } + } +} + +void Vpn::onVpnActiveConnectionStateChanged(QString uuid, int status) +{ + if (uuid.isEmpty()) { + qDebug() << "[Vpn]onActiveConnectionChanged but uuid is empty"; + return; + } + qDebug() << "[Vpn]onActiveConnectionChanged " << uuid << status; + VpnItem * item= nullptr; + + if (m_listFrame->itemMap.contains(uuid)) { + item = m_listFrame->itemMap[uuid]; + if (status == ACTIVATED) { + //为已连接则放到第一个 + m_listFrame->lanItemLayout->removeWidget(item); + m_listFrame->lanItemLayout->insertWidget(0,item); + } else if (status == DEACTIVATED) { + //为断开则重新插入 + int index = getInsertPos(item->titileLabel->text()); + qDebug() << "[Vpn]reinsert" << item->titileLabel->text() << "pos" << index << "because status changes to deactive"; + m_listFrame->lanItemLayout->removeWidget(item); + m_listFrame->lanItemLayout->insertWidget(index,item); + } + itemActiveConnectionStatusChanged(item, status); + } +} + +void Vpn::itemActiveConnectionStatusChanged(VpnItem *item, int status) +{ +// QString iconPath = NoNetSymbolic; + if (status == ACTIVATING) { + item->startLoading(); + } else if (status == ACTIVATED) { + item->stopLoading(); +// iconPath = KLanSymbolic; + item->statusLabel->clear(); + item->statusLabel->setMinimumSize(36,36); + item->statusLabel->setMaximumSize(16777215,16777215); + item->statusLabel->setText(tr("connected")); + item->isAcitve = true; + } else if (status == DEACTIVATING) { + item->startLoading(); + } else { + item->stopLoading(); + item->statusLabel->setMinimumSize(36,36); + item->statusLabel->setMaximumSize(16777215,16777215); + item->statusLabel->clear(); + item->isAcitve = false; + item->statusLabel->setText(tr("not connected")); + } + item->setConnectActionText(item->isAcitve); +} + +int Vpn::getInsertPos(QString connName) +{ + qDebug() << "[Vpn]getInsertPos" << connName; + int index = 0; + if(!m_interface->isValid()) { + index = 0; + } else { + QDBusMessage result = m_interface->call(QStringLiteral("getVirtualList")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getVirtualList error:" << result.errorMessage(); + return 0; + } + auto dbusArg = result.arguments().at(0).value(); + QVector variantList; + dbusArg >> variantList; + for (int i = 0; i < variantList.size(); ++i ) { + if (variantList.at(i).at(0) == connName) { + qDebug() << "pos in kylin-nm is " << i; + index = i; + break; + } + } + if (variantList.at(0).size() == 1) { + index--; + } + } + return index; } diff --git a/plugins/vpn/vpn.h b/plugins/vpn/vpn.h index 14793f43..941f8f4f 100644 --- a/plugins/vpn/vpn.h +++ b/plugins/vpn/vpn.h @@ -59,6 +59,7 @@ public: public: void initComponent(); + void initConnect(); void runExternalApp(); @@ -72,6 +73,8 @@ private: int pluginType; QWidget * pluginWidget; + QDBusInterface *m_interface = nullptr; + QFrame *m_topFrame; QFrame *m_showFrame; QLabel *m_showLabel; @@ -83,19 +86,18 @@ private: ItemFrame *m_listFrame; bool mFirstLoad; + QGSettings *m_switchGsettings; QFrame* myLine(); int getInsertPos(QString connName); - void deleteOneLan(QString uuid); + void deleteVpn(QString uuid); void activeConnect(QString uuid); void deActiveConnect(QString uuid); //获取设备列表 void initNet(); - //处理列表增加 - void addLanItem(QStringList infoList, bool isActived); //增加一项 void addOneVirtualItem(QStringList infoList); //减少一项 @@ -103,6 +105,15 @@ private: //单个lan连接状态变化 void itemActiveConnectionStatusChanged(VpnItem *item, int status); + + void setShowSwitchStatus(); + +private slots: + void onVpnAdd(QStringList); + void onVpnRemove(QString); + void onVpnUpdate(QStringList); + void onVpnActiveConnectionStateChanged(QString, int); + }; #endif // VPN_H diff --git a/plugins/vpn/vpnitem.cpp b/plugins/vpn/vpnitem.cpp index cdaa397f..52897159 100644 --- a/plugins/vpn/vpnitem.cpp +++ b/plugins/vpn/vpnitem.cpp @@ -27,8 +27,8 @@ #define THEME_QT_SCHEMA "org.ukui.style" #define MODE_QT_KEY "style-name" -VpnItem::VpnItem(bool bAcitve, bool isLock, QWidget *parent) - : isAcitve(bAcitve), isLock(isLock), QPushButton(parent) +VpnItem::VpnItem(bool bAcitve, QWidget *parent) + : isAcitve(bAcitve), QPushButton(parent) { this->setMinimumSize(550, 58); this->setProperty("useButtonPalette", true); @@ -42,16 +42,32 @@ VpnItem::VpnItem(bool bAcitve, bool isLock, QWidget *parent) 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); -// statusLabel->setMinimumSize(36,36); // infoLabel = new GrayInfoButton(this); + + m_moreButton = new QToolButton(this); + m_moreButton->setProperty("useButtonPalette", true); + m_moreButton->setPopupMode(QToolButton::InstantPopup); + m_moreButton->setAutoRaise(true); + m_moreButton->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic")); + m_moreMenu = new QMenu(m_moreButton); + m_connectAction = new QAction(m_moreMenu); + m_deleteAction = new QAction(tr("Delete"), m_moreMenu); + setConnectActionText(isAcitve); + + m_moreMenu->addAction(m_connectAction); + m_moreMenu->addAction(m_deleteAction); + m_moreButton->setMenu(m_moreMenu); + mLanLyt->addWidget(iconLabel); mLanLyt->addWidget(titileLabel,Qt::AlignLeft); mLanLyt->addStretch(); mLanLyt->addWidget(statusLabel); // mLanLyt->addWidget(infoLabel); + mLanLyt->addWidget(m_moreButton); loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic")); loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic")); @@ -64,6 +80,9 @@ VpnItem::VpnItem(bool bAcitve, bool isLock, QWidget *parent) waitTimer = new QTimer(this); connect(waitTimer, &QTimer::timeout, this, &VpnItem::updateIcon); + connect(m_connectAction, &QAction::triggered, this, &VpnItem::onConnectTriggered); + connect(m_deleteAction, &QAction::triggered, this, &VpnItem::onDeletetTriggered); + m_moreMenu->installEventFilter(this); } void VpnItem::updateIcon() @@ -86,6 +105,35 @@ void VpnItem::stopLoading(){ loading = false; } +void VpnItem::setConnectActionText(bool isAcitve) +{ + if (isAcitve) { + m_connectAction->setText(tr("Disconnect")); + } else { + m_connectAction->setText(tr("Connect")); + } +} + +void VpnItem::onConnectTriggered() +{ + if (!m_connectAction) { + return; + } + if (m_connectAction->text() == tr("Connect")) { + Q_EMIT connectActionTriggered(); + } else if (m_connectAction->text() == tr("Disconnect")) { + Q_EMIT disconnectActionTriggered(); + } +} + +void VpnItem::onDeletetTriggered() +{ + if (!m_deleteAction) { + return; + } + Q_EMIT deleteActionTriggered(); +} + void VpnItem::paintEvent(QPaintEvent *event) { QPalette pal = this->palette(); @@ -122,3 +170,18 @@ void VpnItem::paintEvent(QPaintEvent *event) painter.drawRect(rect); QPushButton::paintEvent(event); } + +bool VpnItem::eventFilter(QObject *watched, QEvent *event) +{ + //菜单右边界与按钮右边界对齐 + if (event->type() == QEvent::Show && watched == m_moreMenu) { + int menuXPos = m_moreMenu->pos().x(); + int menuWidth = m_moreMenu->size().width(); + int btnWidth = m_moreButton->size().width(); + + QPoint pos = QPoint (menuXPos - menuWidth + btnWidth, m_moreMenu->pos().y()); + m_moreMenu->move(pos); + return true; + } + return false; +} diff --git a/plugins/vpn/vpnitem.h b/plugins/vpn/vpnitem.h index 4e79cd3e..eef1b415 100644 --- a/plugins/vpn/vpnitem.h +++ b/plugins/vpn/vpnitem.h @@ -28,33 +28,43 @@ #include #include #include +#include +#include +#include +#include #include "fixlabel.h" -//#include "infobutton.h" #include "../component/AddBtn/grayinfobutton.h" class VpnItem : public QPushButton { + Q_OBJECT public: - VpnItem(bool bAcitve, bool isLock, QWidget *parent = nullptr); + VpnItem(bool bAcitve, QWidget *parent = nullptr); public: QLabel * iconLabel = nullptr; // GrayInfoButton * infoLabel = nullptr; FixLabel * titileLabel = nullptr; QLabel * statusLabel = nullptr; + QToolButton* m_moreButton = nullptr; + QMenu* m_moreMenu = nullptr; + QAction* m_connectAction = nullptr; + QAction* m_deleteAction = nullptr; + QString uuid = ""; + QString dbusPath = ""; void setHalfFillet(bool flag) {useHalfFillet = flag; repaint();} public: void startLoading(); void stopLoading(); + void setConnectActionText(bool isAcitve); + bool isAcitve = false; bool loading = false; - bool isLock = false; - - protected: void paintEvent(QPaintEvent *event); + bool eventFilter(QObject *watched, QEvent *event); private: QTimer *waitTimer = nullptr; @@ -65,6 +75,13 @@ private: private slots: void updateIcon(); + void onConnectTriggered(); + void onDeletetTriggered(); + +Q_SIGNALS: + void connectActionTriggered(); + void disconnectActionTriggered(); + void deleteActionTriggered(); }; From c00f5054792fab2ad97a2615498cae3758c14c28 Mon Sep 17 00:00:00 2001 From: chenxuechao Date: Wed, 2 Nov 2022 17:42:31 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=A7=A3=E5=86=B3VPN=E5=B4=A9=E6=BA=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=92=8C=E9=83=A8=E5=88=86BUG=EF=BC=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=83=A8=E5=88=86=E5=A4=9A=E4=B8=8E=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/kylin-nm.preinst | 3 + plugins/vpn/translations/zh_CN.qm | Bin 0 -> 594 bytes plugins/vpn/translations/zh_CN.ts | 80 +++++++++++++++++++++++ plugins/vpn/vpn.cpp | 37 +++++++---- plugins/vpn/vpn.pro | 8 ++- plugins/vpn/vpnitem.cpp | 4 +- plugins/vpn/vpnitem.h | 2 +- src/frontend/list-items/vpnlistitem.cpp | 48 +++++--------- src/frontend/list-items/vpnlistitem.h | 6 ++ src/frontend/single-pages/singlepage.cpp | 3 +- src/frontend/single-pages/singlepage.h | 5 -- src/frontend/single-pages/vpnpage.cpp | 65 +++++++++++------- src/frontend/single-pages/vpnpage.h | 8 ++- src/frontend/vpnmainwindow.cpp | 20 +----- src/frontend/vpnmainwindow.h | 2 - 15 files changed, 191 insertions(+), 100 deletions(-) create mode 100644 plugins/vpn/translations/zh_CN.qm create mode 100644 plugins/vpn/translations/zh_CN.ts diff --git a/debian/kylin-nm.preinst b/debian/kylin-nm.preinst index 8b913081..1390f944 100755 --- a/debian/kylin-nm.preinst +++ b/debian/kylin-nm.preinst @@ -7,3 +7,6 @@ dpkg-divert --package kylin-nm --rename --divert "$path"".old" --add $path path2="/usr/lib/`/usr/bin/dpkg-architecture -qDEB_TARGET_MULTIARCH`/ukui-control-center/libproxy.so" dpkg-divert --package kylin-nm --rename --divert "$path2"".old" --add $path2 + +path3="/usr/lib/`/usr/bin/dpkg-architecture -qDEB_TARGET_MULTIARCH`/ukui-control-center/libvpn.so" +dpkg-divert --package kylin-nm --rename --divert "$path3"".old" --add $path3 diff --git a/plugins/vpn/translations/zh_CN.qm b/plugins/vpn/translations/zh_CN.qm new file mode 100644 index 0000000000000000000000000000000000000000..56074df7001ff23cc82b4642556a596316b3c298 GIT binary patch literal 594 zcmcE7ks@*G{hX<16=n7(EZlq7iGhJ3fq@~~4@mE3V2I5F($|=D5412aFq*Nf(OC+l zJ6OFBTmg!IWX+rQ8Avm*vy@E%ic7FBi`4^iL%9-vn*jOixKh2J0O>>?c}69mcniPK z&)Gm)BNHfigZV!YZ~(asY(UKAn3AI4Uy_kpRLlP5i+b`Q-}vc?uzk#o0-TMIg=0Kts@+#2gmjhf@k-B}5lcJ6r6h{(H$w z;Z|@a=jY|6CYPk9;4pzLGq)hWs01MkG9+CK#Sq@S{1OE$1_70_peST_hS&x&jUDI_ oP(XmgfF(#_S_<4zY%ZxesU@kHs#4d+Gr(1GxnveYEk#iY0QPo`1^@s6 literal 0 HcmV?d00001 diff --git a/plugins/vpn/translations/zh_CN.ts b/plugins/vpn/translations/zh_CN.ts new file mode 100644 index 00000000..ed7ce029 --- /dev/null +++ b/plugins/vpn/translations/zh_CN.ts @@ -0,0 +1,80 @@ + + + + + AddNetBtn + + + Add Others + + + + + Add WiredNetork + + + + + ItemFrame + + + Add Vpn + 添加VPN + + + + Vpn + + + VPN + + + + + import + + + + + Vpn + + + + + Show on Taskbar + 在任务栏显示图标 + + + + + connected + 已连接 + + + + + not connected + 未连接 + + + + VpnItem + + + Delete + 删除 + + + + + Disconnect + 断开 + + + + + Connect + 连接 + + + diff --git a/plugins/vpn/vpn.cpp b/plugins/vpn/vpn.cpp index b6b05dae..f4c13273 100644 --- a/plugins/vpn/vpn.cpp +++ b/plugins/vpn/vpn.cpp @@ -52,11 +52,19 @@ #define KVpnSymbolic "ukui-vpn-symbolic" +#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" +#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" +#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" + const QString VISIBLE = "visible"; const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.vpnicon"; Vpn::Vpn() : mFirstLoad(true) { + QTranslator* translator = new QTranslator(this); + translator->load("/usr/share/kylin-nm/vpn/" + QLocale::system().name()); + QApplication::installTranslator(translator); + pluginName = tr("Vpn"); pluginType = NETWORK; } @@ -308,8 +316,6 @@ void Vpn::addOneVirtualItem(QStringList infoList) int status = infoList.at(3).toInt(); //1-连接中 2-已连接 3-断开中 4-已断开 VpnItem * item = new VpnItem(pluginWidget); - item->statusLabel->setText(tr("not connected")); - QIcon searchIcon = QIcon::fromTheme(KVpnSymbolic); item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(ICON_SIZE)))); item->titileLabel->setText(connName); @@ -321,19 +327,28 @@ void Vpn::addOneVirtualItem(QStringList infoList) item->startLoading(); } -// connect(lanItem->infoLabel, &GrayInfoButton::clicked, this, [=]{ -// // open landetail page -// if (!m_interface->isValid()) { -// return; -// } -// qDebug() << "[NetConnect]call showPropertyWidget" << deviceName << connUuid << __LINE__; -// m_interface->call(QStringLiteral("showPropertyWidget"), deviceName, connUuid); -// qDebug() << "[NetConnect]call showPropertyWidget respond" << __LINE__; -// }); + connect(item->infoLabel, &GrayInfoButton::clicked, this, [=]{ + QDBusInterface appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, + KYLIN_APP_MANAGER_PATH, + KYLIN_APP_MANAGER_INTERFACE, + QDBusConnection::sessionBus()); + + if (!appManagerDbusInterface.isValid()) { + qWarning()<<"appManagerDbusInterface init error"; + } else { + QDBusReply reply = appManagerDbusInterface.call("LaunchApp", "nm-connection-editor.desktop"); + } + }); item->isAcitve = (status == 2); item->setConnectActionText(item->isAcitve); + if (item->isAcitve) { + item->statusLabel->setText(tr("connected")); + } else { + item->statusLabel->setText(tr("not connected")); + } + connect(item, &QPushButton::clicked, this, [=] { if (item->isAcitve || item->loading) { deActiveConnect(item->uuid); diff --git a/plugins/vpn/vpn.pro b/plugins/vpn/vpn.pro index 4884bc97..957517c6 100644 --- a/plugins/vpn/vpn.pro +++ b/plugins/vpn/vpn.pro @@ -19,6 +19,8 @@ PKGCONFIG += gsettings-qt \ TARGET = $$qtLibraryTarget(vpn) DESTDIR = ../.. target.path = $$[QT_INSTALL_LIBS]/ukui-control-center +trans.files = translations/* +trans.path = /usr/share/kylin-nm/vpn/ INCLUDEPATH += \ $$PROJECT_COMPONENTSOURCE \ @@ -41,4 +43,8 @@ HEADERS += \ FORMS += \ vpn.ui -INSTALLS += target +INSTALLS += target \ + trans + +TRANSLATIONS += \ + translations/zh_CN.ts diff --git a/plugins/vpn/vpnitem.cpp b/plugins/vpn/vpnitem.cpp index 52897159..28ff57eb 100644 --- a/plugins/vpn/vpnitem.cpp +++ b/plugins/vpn/vpnitem.cpp @@ -46,7 +46,7 @@ VpnItem::VpnItem(bool bAcitve, QWidget *parent) titileLabel = new FixLabel(this); statusLabel = new QLabel(this); statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); -// infoLabel = new GrayInfoButton(this); + infoLabel = new GrayInfoButton(this); m_moreButton = new QToolButton(this); m_moreButton->setProperty("useButtonPalette", true); @@ -66,7 +66,7 @@ VpnItem::VpnItem(bool bAcitve, QWidget *parent) mLanLyt->addWidget(titileLabel,Qt::AlignLeft); mLanLyt->addStretch(); mLanLyt->addWidget(statusLabel); -// mLanLyt->addWidget(infoLabel); + mLanLyt->addWidget(infoLabel); mLanLyt->addWidget(m_moreButton); loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic")); diff --git a/plugins/vpn/vpnitem.h b/plugins/vpn/vpnitem.h index eef1b415..6947d60f 100644 --- a/plugins/vpn/vpnitem.h +++ b/plugins/vpn/vpnitem.h @@ -42,7 +42,7 @@ public: VpnItem(bool bAcitve, QWidget *parent = nullptr); public: QLabel * iconLabel = nullptr; -// GrayInfoButton * infoLabel = nullptr; + GrayInfoButton * infoLabel = nullptr; FixLabel * titileLabel = nullptr; QLabel * statusLabel = nullptr; QToolButton* m_moreButton = nullptr; diff --git a/src/frontend/list-items/vpnlistitem.cpp b/src/frontend/list-items/vpnlistitem.cpp index 493507eb..0a1541d1 100644 --- a/src/frontend/list-items/vpnlistitem.cpp +++ b/src/frontend/list-items/vpnlistitem.cpp @@ -26,7 +26,6 @@ VpnListItem::VpnListItem(const KyConnectItem *lanConnectItem, QWidget *parent):ListItem(parent) { - m_infoButton->setVisible(false); m_connectOperation = new KyWiredConnectOperation(this); m_deviceResource = new KyNetworkDeviceResourse(this); @@ -182,40 +181,25 @@ void VpnListItem::onMenuTriggered(QAction *action) return; } +bool VpnListItem::launchApp(QString desktopFile) +{ + QDBusInterface appManagerDbusInterface(KYLIN_APP_MANAGER_NAME, + KYLIN_APP_MANAGER_PATH, + KYLIN_APP_MANAGER_INTERFACE, + QDBusConnection::sessionBus()); + + if (!appManagerDbusInterface.isValid()) { + qWarning()<<"appManagerDbusInterface init error"; + return false; + } else { + QDBusReply reply = appManagerDbusInterface.call("LaunchApp", desktopFile); + return reply; + } +} void VpnListItem::onInfoButtonClicked() { -// if (m_vpnConnectItem.m_connectUuid.isEmpty()) { -// qDebug() << LOG_FLAG << "connect is empty, so can not show detail info."; -// return; -// } - -// if(netDetail != nullptr){ -// netDetail->activateWindow(); -// return; -// } - -// qDebug()<< LOG_FLAG << "the info button of lan is clicked! uuid = " -// << m_vpnConnectItem.m_connectUuid << "; name = " << m_vpnConnectItem.m_connectName -// << "." <show(); -// Q_EMIT this->detailShow(true); - + launchApp("nm-connection-editor.desktop"); return; } diff --git a/src/frontend/list-items/vpnlistitem.h b/src/frontend/list-items/vpnlistitem.h index 2e361fe6..b65d22dc 100644 --- a/src/frontend/list-items/vpnlistitem.h +++ b/src/frontend/list-items/vpnlistitem.h @@ -26,6 +26,10 @@ #include #include +#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager" +#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager" +#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager" + class VpnListItem : public ListItem { Q_OBJECT @@ -50,6 +54,7 @@ public: protected: void setIcon(bool isOn); void onRightButtonClicked(); + bool launchApp(QString desktopFile); private: void connectItemCopy(const KyConnectItem *lanConnectItem); @@ -61,6 +66,7 @@ private Q_SLOTS: private: KyConnectItem m_vpnConnectItem; +// QDBusInterface m_appManagerDbusInterface; KyWiredConnectOperation *m_connectOperation = nullptr; KyNetworkDeviceResourse *m_deviceResource = nullptr; diff --git a/src/frontend/single-pages/singlepage.cpp b/src/frontend/single-pages/singlepage.cpp index 2e059cac..f3293a5e 100644 --- a/src/frontend/single-pages/singlepage.cpp +++ b/src/frontend/single-pages/singlepage.cpp @@ -42,7 +42,7 @@ void SinglePage::initUI() this->setLayout(m_mainLayout); m_netFrame = new QFrame(this); - m_netFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT); + m_netFrame->setMinimumHeight(TEXT_HEIGHT + 17); m_netLayout = new QVBoxLayout(m_netFrame); m_netLayout->setContentsMargins(NET_LAYOUT_MARGINS); m_netFrame->setLayout(m_netLayout); @@ -79,7 +79,6 @@ void SinglePage::initUI() m_mainLayout->addStretch(); m_mainLayout->addWidget(m_netDivider); m_mainLayout->addWidget(m_settingsFrame); - } void SinglePage::showDesktopNotify(const QString &message, QString soundName) diff --git a/src/frontend/single-pages/singlepage.h b/src/frontend/single-pages/singlepage.h index a9248433..356cbacd 100644 --- a/src/frontend/single-pages/singlepage.h +++ b/src/frontend/single-pages/singlepage.h @@ -44,10 +44,6 @@ using namespace kdk; #define MAIN_LAYOUT_MARGINS 0,0,0,0 #define MAIN_LAYOUT_SPACING 0 #define TITLE_FRAME_HEIGHT 50 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度 -#define TITLE_LAYOUT_MARGINS 24,0,24,0 -#define DEVICE_LAYOUT_MARGINS 24,0,24,8 -#define DEVICE_COMBOBOX_WIDTH 180 -#define ACTIVE_NET_LAYOUT_MARGINS 8,8,8,8 #define NET_LAYOUT_MARGINS 8,8,0,1 #define NET_LAYOUT_SPACING 8 #define NET_LIST_SPACING 0 @@ -57,7 +53,6 @@ using namespace kdk; #define SETTINGS_LAYOUT_MARGINS 23,0,24,0 #define TRANSPARENT_COLOR QColor(0,0,0,0) #define INACTIVE_AREA_MIN_HEIGHT 170 -#define ACTIVE_AREA_MAX_HEIGHT 92 #define MAX_ITEMS 4 #define MAX_WIDTH 412 diff --git a/src/frontend/single-pages/vpnpage.cpp b/src/frontend/single-pages/vpnpage.cpp index 3ed01a2f..d594a35c 100644 --- a/src/frontend/single-pages/vpnpage.cpp +++ b/src/frontend/single-pages/vpnpage.cpp @@ -22,14 +22,7 @@ #include #include -#define MAIN_LAYOUT_MARGINS 0,0,0,0 -#define MAIN_LAYOUT_SPACING 0 -#define TITLE_FRAME_HEIGHT 52 -#define TITLE_LAYOUT_MARGINS 24,0,24,0 -#define LAN_LIST_SPACING 0 -#define TEXT_MARGINS 16,0,0,0 -#define SETTINGS_LAYOUT_MARGINS 24,16,24,16 -#define TRANSPARENT_COLOR QColor(0,0,0,0) +#define VPN_LIST_SPACING 0 #define ITEM_HEIGHT 48 @@ -49,7 +42,7 @@ VpnPage::VpnPage(QWidget *parent) : SinglePage(parent) initUI(); initVpnArea(); - connect(m_activeResourse, &KyActiveConnectResourse::vpnConnectChangeReason, this, &VpnPage::onConnectionStateChange); + connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &VpnPage::onConnectionStateChange); connect(m_activeResourse, &KyActiveConnectResourse::activeConnectRemove, this, [=] (QString activeConnectUuid) { sendVpnStateChangeSignal(activeConnectUuid,Deactivated); } ); @@ -115,6 +108,7 @@ void VpnPage::constructActiveConnectionArea() { QList activedList; QList netList; + QGSettings vpnGsettings(GSETTINGS_VPNICON_VISIBLE); activedList.clear(); netList.clear(); @@ -136,7 +130,6 @@ void VpnPage::constructActiveConnectionArea() if (m_activeConnectionMap.contains(p_netConnectionItem->m_connectUuid)) { qDebug()<m_connectUuid; } -// p_netConnectionItem->m_connectState = NetworkManager::ActiveConnection::Activated; QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_vpnListWidget); m_activeConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); } @@ -144,21 +137,29 @@ void VpnPage::constructActiveConnectionArea() delete p_netConnectionItem; p_netConnectionItem = nullptr; } + if (vpnGsettings.keys().contains(QString(VISIBLE))) { + vpnGsettings.set(VISIBLE, true); + } + } else { + if (vpnGsettings.keys().contains(QString(VISIBLE))) { + vpnGsettings.set(VISIBLE, false); + } } + if (m_vpnListWidget->count() <= MAX_ITEMS) { m_vpnListWidget->setFixedWidth(MIN_WIDTH); + m_netListArea->setFixedHeight(m_vpnListWidget->count() * ITEM_HEIGHT); } else { m_vpnListWidget->setFixedWidth(MAX_WIDTH); + m_netListArea->setFixedHeight(MAX_ITEMS * ITEM_HEIGHT); } - return; + m_netFrame->setFixedHeight(37 + m_netListArea->height()); } void VpnPage::initVpnArea() { m_netFrame->show(); constructActiveConnectionArea(); - - return; } bool VpnPage::removeConnectionItem(QMap &connectMap, @@ -182,6 +183,7 @@ bool VpnPage::removeConnectionItem(QMap &connectMap, iter = connectMap.erase(iter); if (m_vpnListWidget->count() <= MAX_ITEMS) { m_vpnListWidget->setFixedWidth(MIN_WIDTH); + m_netListArea->setFixedHeight(m_vpnListWidget->count() * ITEM_HEIGHT); } return true; } @@ -197,6 +199,7 @@ void VpnPage::onRemoveConnection(QString path) //删除时后端会 Q_EMIT vpnRemove(path); if (removeConnectionItem(m_netConnectionMap, m_vpnListWidget, path)) { + m_netFrame->setFixedHeight(37 + m_netListArea->height()); return; } } @@ -224,9 +227,13 @@ void VpnPage::onAddConnection(QString uuid) //新增一个有线 delete p_newItem; p_newItem = nullptr; - if (m_vpnListWidget->count() > MAX_ITEMS) { + if (m_vpnListWidget->count() >= MAX_ITEMS) { m_vpnListWidget->setFixedWidth(MAX_WIDTH); + m_netListArea->setFixedHeight(MAX_ITEMS * ITEM_HEIGHT); + } else { + m_netListArea->setFixedHeight(m_vpnListWidget->count() * ITEM_HEIGHT); } + m_netFrame->setFixedHeight(37 + m_netListArea->height()); return; } @@ -241,13 +248,14 @@ void VpnPage::initUI() m_netLabel->setText(tr("VPN Connection")); m_vpnListWidget = new QListWidget(m_netListArea); m_vpnListWidget->setFrameShape(QFrame::Shape::NoFrame); - m_vpnListWidget->setSpacing(LAN_LIST_SPACING); + m_vpnListWidget->setSpacing(VPN_LIST_SPACING); m_vpnListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_vpnListWidget->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel); m_vpnListWidget->verticalScrollBar()->setProperty("drawScrollBarGroove",false); //去除滚动条的外侧黑框 m_vpnListWidget->verticalScrollBar()->setSingleStep(SCROLL_STEP); m_vpnListWidget->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu); m_netAreaLayout->addWidget(m_vpnListWidget); + m_netListArea->setFixedHeight(0); QPalette pal = m_vpnListWidget->palette(); pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明 @@ -337,8 +345,6 @@ void VpnPage::updateConnectionArea(KyConnectItem *p_newItem) } else { m_vpnListWidget->setFixedWidth(MAX_WIDTH); } - - return; } void VpnPage::updateConnectionState(QMap &connectMap, @@ -352,12 +358,11 @@ void VpnPage::updateConnectionState(QMap &connectMap p_lanItem->updateConnectionState(state); } - return; } void VpnPage::onConnectionStateChange(QString uuid, - NetworkManager::VpnConnection::State state, - NetworkManager::VpnConnection::StateChangeReason reason) + NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason) { //VpnPage函数内持续监听连接状态的变化并记录供其他函数调用获取状态 if (!m_connectResourse->isVirtualConncection(uuid)) { @@ -416,7 +421,6 @@ void VpnPage::onConnectionStateChange(QString uuid, return; } - void VpnPage::getVirtualList(QVector &vector) { QList netConnectList; @@ -424,10 +428,17 @@ void VpnPage::getVirtualList(QVector &vector) 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(netConnectList.at(i)->m_connectState)); + << QString::number(state)); } } return; @@ -445,10 +456,16 @@ void VpnPage::sendVpnUpdateSignal(KyConnectItem *p_connectItem) 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(p_connectItem->m_connectState); + << QString::number(state); qDebug() << "[VpnPage] emit vpnAdd because addConnection "; Q_EMIT vpnAdd(info); @@ -521,7 +538,7 @@ void VpnPage::updateActiveConnectionProperty(KyConnectItem *p_connectItem) void VpnPage::onUpdateConnection(QString uuid) { - if (!m_connectResourse->isWiredConnection(uuid)) { + if (!m_connectResourse->isVirtualConncection(uuid)) { return; } diff --git a/src/frontend/single-pages/vpnpage.h b/src/frontend/single-pages/vpnpage.h index c064bd75..0b3c5fd8 100644 --- a/src/frontend/single-pages/vpnpage.h +++ b/src/frontend/single-pages/vpnpage.h @@ -35,6 +35,9 @@ #define VPNPAGE_LAYOUT_MARGINS 0,0,0,0 +#define VISIBLE "visible" +const QByteArray GSETTINGS_VPNICON_VISIBLE = "org.ukui.kylin-nm.vpnicon"; + class VpnListItem; class VpnPage : public SinglePage @@ -65,7 +68,6 @@ private: bool removeConnectionItem(QMap &connectMap, QListWidget *lanListWidget, QString path); - void constructConnectionArea(); void constructActiveConnectionArea(); void updateConnectionArea(KyConnectItem *p_newItem); @@ -95,8 +97,8 @@ Q_SIGNALS: private Q_SLOTS: void onConnectionStateChange(QString uuid, - NetworkManager::VpnConnection::State state, - NetworkManager::VpnConnection::StateChangeReason reason); + NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason); void onAddConnection(QString uuid); void onRemoveConnection(QString path); diff --git a/src/frontend/vpnmainwindow.cpp b/src/frontend/vpnmainwindow.cpp index 4238cd33..e5c1a4f0 100644 --- a/src/frontend/vpnmainwindow.cpp +++ b/src/frontend/vpnmainwindow.cpp @@ -73,23 +73,10 @@ void vpnMainWindow::showMainwindow() KWindowSystem::setState(this->winId(), NET::SkipTaskbar | NET::SkipPager); } } - this->showByWaylandHelper(); this->raise(); this->activateWindow(); - Q_EMIT this->mainWindowVisibleChanged(true); -#ifdef WITHKYSEC -// if (!kysec_is_disabled() && kysec_get_3adm_status() && (getuid() || geteuid())){ -// if (nullptr != m_vpnPage) { -// m_vpnPage->hideSetting(); -// } -// } else { -// if (nullptr != m_vpnPage) { -// m_vpnPage->showSetting(); -// } -// } -#endif - +// Q_EMIT this->mainWindowVisibleChanged(true); } /** @@ -98,7 +85,7 @@ void vpnMainWindow::showMainwindow() void vpnMainWindow::hideMainwindow() { this->hide(); - Q_EMIT this->mainWindowVisibleChanged(false); +// Q_EMIT this->mainWindowVisibleChanged(false); } ///** @@ -258,7 +245,6 @@ void vpnMainWindow::initDbusConnnect() connect(m_vpnPage, &VpnPage::vpnRemove, this, &vpnMainWindow::vpnRemove); connect(m_vpnPage, &VpnPage::vpnUpdate, this, &vpnMainWindow::vpnUpdate); connect(m_vpnPage, &VpnPage::vpnActiveConnectionStateChanged, this, &vpnMainWindow::vpnActiveConnectionStateChanged); - //模式切换 QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"), QString("/"), @@ -499,7 +485,7 @@ void vpnMainWindow::initVpnIconVisible() { if(QGSettings::isSchemaInstalled(GSETTINGS_VPNICON_VISIBLE)) { m_vpnGsettings = new QGSettings(GSETTINGS_VPNICON_VISIBLE); - if(m_vpnGsettings->keys().contains(QString("visible"))) { + if(m_vpnGsettings->keys().contains(QString(VISIBLE))) { connect(m_vpnGsettings, &QGSettings::changed, this, &vpnMainWindow::onVpnIconVisibleChanged); m_vpnTrayIcon->setVisible(m_vpnGsettings->get("visible").toBool()); } diff --git a/src/frontend/vpnmainwindow.h b/src/frontend/vpnmainwindow.h index 341efe85..8630d8dc 100644 --- a/src/frontend/vpnmainwindow.h +++ b/src/frontend/vpnmainwindow.h @@ -33,8 +33,6 @@ #include "vpnpage.h" #include "mainwindow.h" -const QByteArray GSETTINGS_VPNICON_VISIBLE = "org.ukui.kylin-nm.vpnicon"; - class VpnPage; class vpnMainWindow : public QMainWindow From 9ff2a19dc91001262ef0dad5fbf6c3fb1f180139 Mon Sep 17 00:00:00 2001 From: chenxuechao Date: Wed, 2 Nov 2022 18:02:59 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=B8=8A=E4=BC=A0changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/changelog | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/debian/changelog b/debian/changelog index 16e0a091..e4c67553 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,18 @@ +kylin-nm (3.20.1.6-ok9) v101; urgency=medium + + * BUG号: + - #145719 【VPN】在任务栏虚拟连接界面点击连接VPN,任务栏网络图标消失后重新显示,概率性不恢复显示 + - #145710 【VPN】没有添加虚拟连接,任务栏仍显示虚拟连接图标 + - #145491 【设计】【网络】网络属性界面显示不全 + - #145699 【平板】【网络连接】编辑网络连接时,添加DNS后点击“+”,会清空当前输入,而不是在下方增加DNS + - #144990 【控制面板】【无线网络】打开设置网络子窗口并关闭后控制面板主窗口被最小化 + - #145707 【平板】【网络连接】打开网络高级设置界面,新建一个有线连接并保存,无法再次打开高级设置界面 + - #146541 【平板】【网络连接】平板模式下点击侧边栏网络图标,网络连接界面显示在屏幕中央 + - #145681 【平板】【VPN】未实现控制面板VPN界面功能 + - #145687 【VPN】任务栏虚拟连接界面不显示详情按钮 + + -- chenxuechao Wed, 02 Nov 2022 17:57:45 +0800 + kylin-nm (3.20.1.6-ok8) v101; urgency=medium * BUG号: