openkylin 改动
This commit is contained in:
parent
ad8c64db66
commit
bc2276f646
|
@ -1,72 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 <QtCore/QMetaObject>
|
|
||||||
#include <QtCore/QByteArray>
|
|
||||||
#include <QtCore/QList>
|
|
||||||
#include <QtCore/QMap>
|
|
||||||
#include <QtCore/QString>
|
|
||||||
#include <QtCore/QStringList>
|
|
||||||
#include <QtCore/QVariant>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Implementation of adaptor class VpnDbusAdaptor
|
|
||||||
*/
|
|
||||||
|
|
||||||
VpnDbusAdaptor::VpnDbusAdaptor(vpnMainWindow *parent)
|
|
||||||
: QDBusAbstractAdaptor(parent)
|
|
||||||
{
|
|
||||||
// constructor
|
|
||||||
qDBusRegisterMetaType<QMap<QString, bool> >();
|
|
||||||
qDBusRegisterMetaType<QMap<QString, int> >();
|
|
||||||
qDBusRegisterMetaType<QVector<QStringList> >();
|
|
||||||
//setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发
|
|
||||||
setAutoRelaySignals(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
VpnDbusAdaptor::~VpnDbusAdaptor()
|
|
||||||
{
|
|
||||||
// destructor
|
|
||||||
}
|
|
||||||
|
|
||||||
//虚拟连接列表
|
|
||||||
QVector<QStringList> VpnDbusAdaptor::getVirtualList()
|
|
||||||
{
|
|
||||||
QVector<QStringList> vector;
|
|
||||||
parent()->getVirtualList(vector);
|
|
||||||
return vector;
|
|
||||||
}
|
|
||||||
|
|
||||||
//删除
|
|
||||||
void VpnDbusAdaptor::deleteVpn(QString uuid)
|
|
||||||
{
|
|
||||||
qDebug() << "delete vpn" << uuid;
|
|
||||||
parent()->deleteVpn(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
|
|
||||||
void VpnDbusAdaptor::activateVpn(const QString& connUuid)
|
|
||||||
{
|
|
||||||
qDebug() << "activate vpn" << connUuid;
|
|
||||||
parent()->activateVpn(connUuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
//断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
|
|
||||||
void VpnDbusAdaptor::deactivateVpn(const QString& connUuid)
|
|
||||||
{
|
|
||||||
qDebug() << "deactivate vpn" << connUuid;
|
|
||||||
parent()->deactivateVpn(connUuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnDbusAdaptor::showKylinVpn()
|
|
||||||
{
|
|
||||||
parent()->onShowMainWindow();
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 <QtCore/QObject>
|
|
||||||
#include <QtDBus/QtDBus>
|
|
||||||
#include <QtDBus/QDBusMetaType>
|
|
||||||
|
|
||||||
#include "singlepage.h"
|
|
||||||
#include "../dbus-interface/kylinnetworkdeviceresource.h"
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QByteArray;
|
|
||||||
//template<class T> class QList;
|
|
||||||
template<class Key, class Value> class QMap;
|
|
||||||
class QString;
|
|
||||||
class QStringList;
|
|
||||||
class QVariant;
|
|
||||||
template<class T> 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<vpnMainWindow *>(QObject::parent()); }
|
|
||||||
|
|
||||||
public: // PROPERTIES
|
|
||||||
public Q_SLOTS: // METHODS
|
|
||||||
//虚拟连接列表
|
|
||||||
QVector<QStringList> getVirtualList();
|
|
||||||
//刪除 根据网络名称 参数1 0:lan 1:wlan 参数2 为ssid/uuid
|
|
||||||
Q_NOREPLY void deleteVpn(QString uuid);
|
|
||||||
//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
|
|
||||||
Q_NOREPLY void activateVpn(const QString& connUuid);
|
|
||||||
//断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
|
|
||||||
Q_NOREPLY void deactivateVpn(const QString& connUuid);
|
|
||||||
//just show
|
|
||||||
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
|
|
|
@ -1,244 +0,0 @@
|
||||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#include "vpnlistitem.h"
|
|
||||||
#include "backend/dbus-interface/kylinconnectitem.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#define LOG_FLAG "[VpnListItem]"
|
|
||||||
|
|
||||||
VpnListItem::VpnListItem(const KyConnectItem *lanConnectItem, QWidget *parent):ListItem(parent)
|
|
||||||
{
|
|
||||||
m_connectOperation = new KyWiredConnectOperation(this);
|
|
||||||
m_deviceResource = new KyNetworkDeviceResourse(this);
|
|
||||||
|
|
||||||
connectItemCopy(lanConnectItem);
|
|
||||||
|
|
||||||
m_nameLabel->setLabelText(m_vpnConnectItem.m_connectName);
|
|
||||||
m_netButton->setButtonIcon(QIcon::fromTheme("ukui-vpn-symbolic"));
|
|
||||||
|
|
||||||
qDebug() << "VpnListItem init:" << m_vpnConnectItem.m_connectName << m_vpnConnectItem.m_connectState << m_vpnConnectItem.m_ifaceName;
|
|
||||||
|
|
||||||
if (Deactivated == m_vpnConnectItem.m_connectState || Activated == m_vpnConnectItem.m_connectState) {
|
|
||||||
m_netButton->stopLoading();
|
|
||||||
if (m_vpnConnectItem.m_connectState == Activated) {
|
|
||||||
setIcon(true);
|
|
||||||
} else {
|
|
||||||
setIcon(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_netButton->startLoading();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_itemFrame->installEventFilter(this);
|
|
||||||
connect(this->m_infoButton, &InfoButton::clicked, this, &VpnListItem::onInfoButtonClicked);
|
|
||||||
connect(m_menu, &QMenu::triggered, this, &VpnListItem::onMenuTriggered);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
VpnListItem::VpnListItem(QWidget *parent) : ListItem(parent)
|
|
||||||
{
|
|
||||||
m_isActive = false;
|
|
||||||
m_netButton->setButtonIcon(QIcon::fromTheme("ukui-vpn-symbolic"));
|
|
||||||
setIcon(false);
|
|
||||||
const QString str=tr("Not connected");
|
|
||||||
m_nameLabel->setLabelText(str);
|
|
||||||
this->m_infoButton->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
VpnListItem::~VpnListItem()
|
|
||||||
{
|
|
||||||
qDebug()<<"[LanPage] lan list item is deleted." << m_vpnConnectItem.m_connectName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnListItem::setIcon(bool isOn)
|
|
||||||
{
|
|
||||||
if (isOn) {
|
|
||||||
m_netButton->setActive(true); //设置图标显示不同颜色
|
|
||||||
} else {
|
|
||||||
m_netButton->setActive(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnListItem::connectItemCopy(const KyConnectItem *lanConnectItem)
|
|
||||||
{
|
|
||||||
if (lanConnectItem) {
|
|
||||||
m_vpnConnectItem.m_connectName = lanConnectItem->m_connectName;
|
|
||||||
m_vpnConnectItem.m_connectPath = lanConnectItem->m_connectPath;
|
|
||||||
m_vpnConnectItem.m_connectState = lanConnectItem->m_connectState;
|
|
||||||
m_vpnConnectItem.m_connectUuid = lanConnectItem->m_connectUuid;
|
|
||||||
m_vpnConnectItem.m_ifaceName = lanConnectItem->m_ifaceName;
|
|
||||||
m_vpnConnectItem.m_itemType = lanConnectItem->m_itemType;
|
|
||||||
} else {
|
|
||||||
qDebug() << LOG_FLAG <<"the connect item is nullptr";
|
|
||||||
m_vpnConnectItem.m_connectName = "";
|
|
||||||
m_vpnConnectItem.m_connectPath = "";
|
|
||||||
m_vpnConnectItem.m_connectState = NetworkManager::ActiveConnection::State::Unknown;
|
|
||||||
m_vpnConnectItem.m_connectUuid = "";
|
|
||||||
m_vpnConnectItem.m_ifaceName = "";
|
|
||||||
m_vpnConnectItem.m_itemType = NetworkManager::ConnectionSettings::ConnectionType::Unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//void VpnListItem::changeState(QString uuid,
|
|
||||||
// NetworkManager::ActiveConnection::State state,
|
|
||||||
// NetworkManager::ActiveConnection::Reason reason)
|
|
||||||
//{
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
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() << 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::onRightButtonClicked()
|
|
||||||
{
|
|
||||||
//右键点击事件
|
|
||||||
qDebug()<< LOG_FLAG <<"onRightButtonClicked";
|
|
||||||
if (!m_menu) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_menu->clear();
|
|
||||||
if (Activated == m_vpnConnectItem.m_connectState || Activating == m_vpnConnectItem.m_connectState) {
|
|
||||||
m_menu->addAction(new QAction(tr("Disconnect"), this));
|
|
||||||
} else if (Deactivated == m_vpnConnectItem.m_connectState) {
|
|
||||||
m_menu->addAction(new QAction(tr("Connect"), this));
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_menu->move(cursor().pos());
|
|
||||||
m_menu->show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnListItem::onMenuTriggered(QAction *action)
|
|
||||||
{
|
|
||||||
if (action->text() == tr("Connect")) {
|
|
||||||
this->onNetButtonClicked();
|
|
||||||
} else if (action->text() == tr("Disconnect")) {
|
|
||||||
m_connectOperation->deactivateWiredConnection(m_vpnConnectItem.m_connectName, m_vpnConnectItem.m_connectUuid);
|
|
||||||
qDebug() << LOG_FLAG << "it will disconnect connection" << m_vpnConnectItem.m_connectName;
|
|
||||||
m_netButton->startLoading();
|
|
||||||
}
|
|
||||||
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<bool> reply = appManagerDbusInterface.call("LaunchApp", desktopFile);
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnListItem::onInfoButtonClicked()
|
|
||||||
{
|
|
||||||
launchApp("nm-connection-editor.desktop");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnListItem::updateConnectionState(ConnectState state)
|
|
||||||
{
|
|
||||||
m_vpnConnectItem.m_connectState = (NetworkManager::ActiveConnection::State)state;
|
|
||||||
|
|
||||||
if (Deactivated == state || Activated == state) {
|
|
||||||
m_netButton->stopLoading();
|
|
||||||
if (state == Activated) {
|
|
||||||
setIcon(true);
|
|
||||||
} else {
|
|
||||||
setIcon(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_netButton->startLoading();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString VpnListItem::getConnectionName()
|
|
||||||
{
|
|
||||||
return m_vpnConnectItem.m_connectName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnListItem::updateConnectionName(QString connectionName)
|
|
||||||
{
|
|
||||||
m_vpnConnectItem.m_connectName = connectionName;
|
|
||||||
m_nameLabel->setLabelText(m_vpnConnectItem.m_connectName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString VpnListItem::getConnectionPath()
|
|
||||||
{
|
|
||||||
return m_vpnConnectItem.m_connectPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnListItem::updateConnectionPath(QString connectionPath)
|
|
||||||
{
|
|
||||||
m_vpnConnectItem.m_connectPath = connectionPath;
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef VPNLISTITEM_H
|
|
||||||
#define VPNLISTITEM_H
|
|
||||||
#include "listitem.h"
|
|
||||||
#include "kylinactiveconnectresource.h"
|
|
||||||
|
|
||||||
#include <QDBusInterface>
|
|
||||||
#include <QEvent>
|
|
||||||
#include <QAction>
|
|
||||||
|
|
||||||
#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager"
|
|
||||||
#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager"
|
|
||||||
#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager"
|
|
||||||
|
|
||||||
class VpnListItem : public ListItem
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
VpnListItem(const KyConnectItem *lanConnectItem, QWidget *parent = nullptr);
|
|
||||||
VpnListItem(QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
~VpnListItem();
|
|
||||||
|
|
||||||
public:
|
|
||||||
void updateConnectionState(ConnectState state);
|
|
||||||
|
|
||||||
QString getConnectionName();
|
|
||||||
void updateConnectionName(QString connectionName);
|
|
||||||
|
|
||||||
QString getConnectionPath();
|
|
||||||
void updateConnectionPath(QString connectionPath);
|
|
||||||
|
|
||||||
void activeConnection();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void setIcon(bool isOn);
|
|
||||||
void onRightButtonClicked();
|
|
||||||
bool launchApp(QString desktopFile);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void connectItemCopy(const KyConnectItem *lanConnectItem);
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onInfoButtonClicked();
|
|
||||||
void onNetButtonClicked();
|
|
||||||
void onMenuTriggered(QAction *action);
|
|
||||||
|
|
||||||
private:
|
|
||||||
KyConnectItem m_vpnConnectItem;
|
|
||||||
// QDBusInterface m_appManagerDbusInterface;
|
|
||||||
|
|
||||||
KyWiredConnectOperation *m_connectOperation = nullptr;
|
|
||||||
KyNetworkDeviceResourse *m_deviceResource = nullptr;
|
|
||||||
|
|
||||||
QString m_deviceName = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // VPNLISTITEM_H
|
|
|
@ -153,6 +153,7 @@ void MainWindow::firstlyStart()
|
||||||
{
|
{
|
||||||
initWindowProperties();
|
initWindowProperties();
|
||||||
initTransparency();
|
initTransparency();
|
||||||
|
registerTrayIcon();
|
||||||
initUI();
|
initUI();
|
||||||
initDbusConnnect();
|
initDbusConnnect();
|
||||||
initWindowTheme();
|
initWindowTheme();
|
||||||
|
@ -228,6 +229,30 @@ void MainWindow::initWindowProperties()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MainWindow::registerTrayIcon 注册托盘图标
|
||||||
|
*/
|
||||||
|
void MainWindow::registerTrayIcon()
|
||||||
|
{
|
||||||
|
m_registerCount++;
|
||||||
|
if (QSystemTrayIcon::isSystemTrayAvailable() || m_registerCount > 10) {
|
||||||
|
m_trayIcon = new QSystemTrayIcon();
|
||||||
|
if (nullptr == m_trayIcon) {
|
||||||
|
qWarning()<< "分配空间trayIcon失败";
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
|
||||||
|
m_trayIcon->setToolTip(QString(tr("kylin-nm")));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (m_registerCount <= 10) {
|
||||||
|
QTimer::singleShot(m_intervalTime,[this] {
|
||||||
|
registerTrayIcon();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::paintEvent(QPaintEvent *event)
|
void MainWindow::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
@ -323,17 +348,14 @@ void MainWindow::initTrayIcon()
|
||||||
iconTimer = new QTimer(this);
|
iconTimer = new QTimer(this);
|
||||||
connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading);
|
connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading);
|
||||||
|
|
||||||
m_trayIcon = new QSystemTrayIcon();
|
|
||||||
m_trayIconMenu = new QMenu();
|
m_trayIconMenu = new QMenu();
|
||||||
m_showMainwindowAction = new QAction(tr("Show MainWindow"),this);
|
m_showMainwindowAction = new QAction(tr("Show MainWindow"),this);
|
||||||
m_showSettingsAction = new QAction(tr("Settings"),this);
|
m_showSettingsAction = new QAction(tr("Settings"),this);
|
||||||
|
|
||||||
m_trayIcon->setToolTip(QString(tr("Network tool")));
|
|
||||||
m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
|
m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
|
||||||
// m_trayIconMenu->addAction(m_showMainwindowAction);
|
// m_trayIconMenu->addAction(m_showMainwindowAction);
|
||||||
m_trayIconMenu->addAction(m_showSettingsAction);
|
m_trayIconMenu->addAction(m_showSettingsAction);
|
||||||
m_trayIcon->setContextMenu(m_trayIconMenu);
|
m_trayIcon->setContextMenu(m_trayIconMenu);
|
||||||
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
|
|
||||||
iconStatus = IconActiveType::LAN_CONNECTED;
|
iconStatus = IconActiveType::LAN_CONNECTED;
|
||||||
onRefreshTrayIcon();
|
onRefreshTrayIcon();
|
||||||
|
|
||||||
|
@ -875,6 +897,7 @@ void MainWindow::showCreateWiredConnectWidget(const QString devName)
|
||||||
});
|
});
|
||||||
m_createPagePtrMap.insert(devName, netDetail);
|
m_createPagePtrMap.insert(devName, netDetail);
|
||||||
netDetail->show();
|
netDetail->show();
|
||||||
|
netDetail->centerToScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showAddOtherWlanWidget(QString devName)
|
void MainWindow::showAddOtherWlanWidget(QString devName)
|
||||||
|
|
|
@ -153,6 +153,7 @@ private:
|
||||||
void paintWithTrans();
|
void paintWithTrans();
|
||||||
void initUI();
|
void initUI();
|
||||||
void initDbusConnnect();
|
void initDbusConnnect();
|
||||||
|
void registerTrayIcon();
|
||||||
void initTrayIcon();
|
void initTrayIcon();
|
||||||
|
|
||||||
void resetTrayIconTool();
|
void resetTrayIconTool();
|
||||||
|
@ -200,6 +201,9 @@ private:
|
||||||
|
|
||||||
NetworkMode *m_networkMode;
|
NetworkMode *m_networkMode;
|
||||||
|
|
||||||
|
uint m_intervalTime = 100;
|
||||||
|
uint m_registerCount = 0;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void onShowMainWindow(int type);
|
void onShowMainWindow(int type);
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,8 @@ public:
|
||||||
void stopLoading();
|
void stopLoading();
|
||||||
void showIpv4AddressConflict(bool isConflict);
|
void showIpv4AddressConflict(bool isConflict);
|
||||||
|
|
||||||
|
QString getNetMaskText(QString text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QComboBox *ipv4ConfigCombox;
|
QComboBox *ipv4ConfigCombox;
|
||||||
LineEdit *ipv4addressEdit;
|
LineEdit *ipv4addressEdit;
|
||||||
|
@ -90,7 +92,6 @@ private:
|
||||||
void configSave();
|
void configSave();
|
||||||
bool getTextEditState(QString text);
|
bool getTextEditState(QString text);
|
||||||
bool netMaskIsValide(QString text);
|
bool netMaskIsValide(QString text);
|
||||||
QString getNetMaskText(QString text);
|
|
||||||
bool checkConnectBtnIsEnabled();
|
bool checkConnectBtnIsEnabled();
|
||||||
void initConflictHintLable();
|
void initConflictHintLable();
|
||||||
void initLoadingIcon();
|
void initLoadingIcon();
|
||||||
|
|
|
@ -274,3 +274,17 @@ void JoinHiddenWiFiPage::onPaletteChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JoinHiddenWiFiPage::centerToScreen()
|
||||||
|
{
|
||||||
|
QDesktopWidget* m = QApplication::desktop();
|
||||||
|
QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos()));
|
||||||
|
int desk_x = desk_rect.width();
|
||||||
|
int desk_y = desk_rect.height();
|
||||||
|
int x = this->width();
|
||||||
|
int y = this->height();
|
||||||
|
// this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
|
||||||
|
kdk::WindowManager::setGeometry(this->windowHandle(), QRect(desk_x / 2 - x / 2 + desk_rect.left(),
|
||||||
|
desk_y / 2 - y / 2 + desk_rect.top(),
|
||||||
|
this->width(),
|
||||||
|
this->height()));
|
||||||
|
}
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
|
||||||
|
#include "windowmanager/windowmanager.h"
|
||||||
#include "coninfo.h"
|
#include "coninfo.h"
|
||||||
#include "kywirelessconnectoperation.h"
|
#include "kywirelessconnectoperation.h"
|
||||||
#include "securitypage.h"
|
#include "securitypage.h"
|
||||||
|
@ -43,6 +45,7 @@ public:
|
||||||
JoinHiddenWiFiPage(QString devName, KDialog *parent = nullptr);
|
JoinHiddenWiFiPage(QString devName, KDialog *parent = nullptr);
|
||||||
~JoinHiddenWiFiPage();
|
~JoinHiddenWiFiPage();
|
||||||
|
|
||||||
|
void centerToScreen();
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
||||||
|
|
|
@ -270,11 +270,11 @@ void NetDetail::centerToScreen()
|
||||||
int desk_y = desk_rect.height();
|
int desk_y = desk_rect.height();
|
||||||
int x = this->width();
|
int x = this->width();
|
||||||
int y = this->height();
|
int y = this->height();
|
||||||
this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
|
// this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
|
||||||
// kdk::WindowManager::setGeometry(this->windowHandle(), QRect(desk_x / 2 - x / 2 + desk_rect.left(),
|
kdk::WindowManager::setGeometry(this->windowHandle(), QRect(desk_x / 2 - x / 2 + desk_rect.left(),
|
||||||
// desk_y / 2 - y / 2 + desk_rect.top(),
|
desk_y / 2 - y / 2 + desk_rect.top(),
|
||||||
// this->width(),
|
this->width(),
|
||||||
// this->height()));
|
this->height()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDetail::initUI()
|
void NetDetail::initUI()
|
||||||
|
@ -651,22 +651,29 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived)
|
||||||
kyConnectResourse->getConnectionSetting(m_uuid,connetSetting);
|
kyConnectResourse->getConnectionSetting(m_uuid,connetSetting);
|
||||||
connetSetting.dumpInfo();
|
connetSetting.dumpInfo();
|
||||||
|
|
||||||
conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType;
|
// conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType;
|
||||||
conInfo.ipv6ConfigType = connetSetting.m_ipv6ConfigIpType;
|
conInfo.ipv6ConfigType = connetSetting.m_ipv6ConfigIpType;
|
||||||
conInfo.isAutoConnect = connetSetting.m_isAutoConnect;
|
conInfo.isAutoConnect = connetSetting.m_isAutoConnect;
|
||||||
|
|
||||||
if (connetSetting.m_ipv4ConfigIpType == CONFIG_IP_MANUAL) {
|
// if (connetSetting.m_ipv4ConfigIpType == CONFIG_IP_MANUAL) {
|
||||||
if (connetSetting.m_ipv4Address.size() > 0) {
|
// if (connetSetting.m_ipv4Address.size() > 0) {
|
||||||
conInfo.strIPV4Address = connetSetting.m_ipv4Address.at(0).ip().toString();
|
// conInfo.strIPV4Address = connetSetting.m_ipv4Address.at(0).ip().toString();
|
||||||
conInfo.strIPV4NetMask = connetSetting.m_ipv4Address.at(0).netmask().toString();
|
// conInfo.strIPV4NetMask = connetSetting.m_ipv4Address.at(0).netmask().toString();
|
||||||
conInfo.strIPV4GateWay = connetSetting.m_ipv4Address.at(0).gateway().toString();
|
// conInfo.strIPV4GateWay = connetSetting.m_ipv4Address.at(0).gateway().toString();
|
||||||
}
|
// }
|
||||||
if (connetSetting.m_ipv4Dns.size() == 1) {
|
// if (connetSetting.m_ipv4Dns.size() == 1) {
|
||||||
conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString();
|
// conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString();
|
||||||
} else if (connetSetting.m_ipv4Dns.size() > 1) {
|
// } else if (connetSetting.m_ipv4Dns.size() > 1) {
|
||||||
conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString();
|
// conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString();
|
||||||
conInfo.strIPV4SecDns = connetSetting.m_ipv4Dns.at(1).toString();
|
// conInfo.strIPV4SecDns = connetSetting.m_ipv4Dns.at(1).toString();
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
//openkylin从第三方库读取有问题 改为ipv4信息直接通过dbus获取
|
||||||
|
KyConnectItem* item = kyConnectResourse->getConnectionItemByUuidWithoutActivateChecking(m_uuid);
|
||||||
|
if (item == nullptr) {
|
||||||
|
conInfo.ipv4ConfigType = CONFIG_IP_DHCP;
|
||||||
|
} else {
|
||||||
|
getIpv4Info(item->m_connectPath, conInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connetSetting.m_ipv6ConfigIpType == CONFIG_IP_MANUAL) {
|
if (connetSetting.m_ipv6ConfigIpType == CONFIG_IP_MANUAL) {
|
||||||
|
@ -1224,3 +1231,94 @@ void ThreadObject::checkIpv6ConflictThread(const QString &ipv6Address)
|
||||||
ipv6rping = nullptr;
|
ipv6rping = nullptr;
|
||||||
Q_EMIT ipv6IsConflict(isConflict);
|
Q_EMIT ipv6IsConflict(isConflict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetDetail::getIpv4Info(QString objPath, ConInfo &conInfo)
|
||||||
|
{
|
||||||
|
QDBusInterface m_interface("org.freedesktop.NetworkManager",
|
||||||
|
objPath,
|
||||||
|
"org.freedesktop.NetworkManager.Settings.Connection",
|
||||||
|
QDBusConnection::systemBus());
|
||||||
|
QDBusMessage result = m_interface.call("GetSettings");
|
||||||
|
|
||||||
|
if (result.arguments().isEmpty()) { return; }
|
||||||
|
const QDBusArgument &dbusArg1st = result.arguments().at( 0 ).value<QDBusArgument>();
|
||||||
|
QMap<QString,QMap<QString,QVariant>> map;
|
||||||
|
dbusArg1st >> map;
|
||||||
|
|
||||||
|
for (QString key : map.keys() ) {
|
||||||
|
QMap<QString,QVariant> innerMap = map.value(key);
|
||||||
|
if (key == "ipv4") {
|
||||||
|
for (QString inner_key : innerMap.keys()) {
|
||||||
|
if (inner_key == "address-data") {
|
||||||
|
//ipv4地址 ipv4子网掩码
|
||||||
|
const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>();
|
||||||
|
QVector<QMap<QString,QVariant>> addressVector;
|
||||||
|
|
||||||
|
dbusArg2nd.beginArray();
|
||||||
|
|
||||||
|
while (!dbusArg2nd.atEnd()) {
|
||||||
|
QMap<QString,QVariant> tempMap;
|
||||||
|
dbusArg2nd >> tempMap;
|
||||||
|
addressVector.append(tempMap);
|
||||||
|
}
|
||||||
|
dbusArg2nd.endArray();
|
||||||
|
if (addressVector.size() >= 1) {
|
||||||
|
conInfo.strIPV4Address = addressVector.at(0).value("address").toString();
|
||||||
|
conInfo.strIPV4NetMask = ipv4Page->getNetMaskText(addressVector.at(0).value("prefix").toString());
|
||||||
|
}
|
||||||
|
} else if (inner_key == "method") {
|
||||||
|
//ipv4 method
|
||||||
|
if (innerMap.value(inner_key).toString() == "auto")
|
||||||
|
conInfo.ipv4ConfigType = CONFIG_IP_DHCP;
|
||||||
|
else {
|
||||||
|
conInfo.ipv4ConfigType = CONFIG_IP_MANUAL;
|
||||||
|
}
|
||||||
|
} else if (inner_key == "dns") {
|
||||||
|
//dns
|
||||||
|
const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>();
|
||||||
|
QList<uint> addressVector;
|
||||||
|
|
||||||
|
dbusArg2nd.beginArray();
|
||||||
|
while (!dbusArg2nd.atEnd()) {
|
||||||
|
uint tempMap;
|
||||||
|
dbusArg2nd >> tempMap;
|
||||||
|
addressVector.append(tempMap);
|
||||||
|
}
|
||||||
|
dbusArg2nd.endArray();
|
||||||
|
if (addressVector.size() == 1) {
|
||||||
|
QString dns(inet_ntoa(*(struct in_addr *)&addressVector.at(0)));
|
||||||
|
conInfo.strIPV4FirDns = dns;
|
||||||
|
} else if (addressVector.size() > 1) {
|
||||||
|
QString dns1(inet_ntoa(*(struct in_addr *)&addressVector.at(0)));
|
||||||
|
QString dns2(inet_ntoa(*(struct in_addr *)&addressVector.at(1)));
|
||||||
|
conInfo.strIPV4FirDns = dns1;
|
||||||
|
conInfo.strIPV4SecDns = dns2;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (inner_key == "gateway") {
|
||||||
|
//gateway
|
||||||
|
conInfo.strIPV4GateWay = innerMap.value(inner_key).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (key == "ipv6") {
|
||||||
|
// for (QString inner_key : innerMap.keys()) {
|
||||||
|
// if (inner_key == "address-data"){
|
||||||
|
// const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>();
|
||||||
|
// QMap<QString,QVariant> m_map;
|
||||||
|
|
||||||
|
// dbusArg2nd.beginArray();
|
||||||
|
// while (!dbusArg2nd.atEnd()) {
|
||||||
|
// dbusArg2nd >> m_map;// append map to a vector here if you want to keep it
|
||||||
|
// }
|
||||||
|
// dbusArg2nd.endArray();
|
||||||
|
|
||||||
|
// dbusWifiIpv6 = m_map.value("address").toString();
|
||||||
|
// } else if (inner_key == "method") {
|
||||||
|
// dbusWifiIpv6Method = innerMap.value(inner_key).toString();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include "kwidget.h"
|
#include "kwidget.h"
|
||||||
#include "ktabbar.h"
|
#include "ktabbar.h"
|
||||||
#include "networkmodeconfig.h"
|
#include "networkmodeconfig.h"
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
using namespace kdk;
|
using namespace kdk;
|
||||||
|
|
||||||
|
@ -95,13 +96,14 @@ public:
|
||||||
NetDetail(QString interface, QString name, QString uuid, bool isActive, bool isWlan, bool isCreateNet, QWidget *parent = nullptr);
|
NetDetail(QString interface, QString name, QString uuid, bool isActive, bool isWlan, bool isCreateNet, QWidget *parent = nullptr);
|
||||||
~NetDetail();
|
~NetDetail();
|
||||||
|
|
||||||
|
void centerToScreen();
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
bool eventFilter(QObject *w, QEvent *event);
|
bool eventFilter(QObject *w, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initUI();
|
void initUI();
|
||||||
void centerToScreen();
|
|
||||||
void initComponent();
|
void initComponent();
|
||||||
void getConInfo(ConInfo &conInfo);
|
void getConInfo(ConInfo &conInfo);
|
||||||
void loadPage();
|
void loadPage();
|
||||||
|
@ -140,6 +142,8 @@ private:
|
||||||
void startObjectThread();
|
void startObjectThread();
|
||||||
void setNetTabToolTip();
|
void setNetTabToolTip();
|
||||||
|
|
||||||
|
void getIpv4Info(QString objPath, ConInfo &conInfo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KyNetworkDeviceResourse *m_netDeviceResource = nullptr;
|
KyNetworkDeviceResourse *m_netDeviceResource = nullptr;
|
||||||
KyConnectOperation* m_connectOperation = nullptr;
|
KyConnectOperation* m_connectOperation = nullptr;
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
INCLUDEPATH += $$PWD
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
$$PWD/vpnpage.h \
|
|
||||||
$$PWD/singlepage.h
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
$$PWD/vpnpage.cpp \
|
|
||||||
$$PWD/singlepage.cpp
|
|
||||||
|
|
|
@ -1,108 +0,0 @@
|
||||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#include "singlepage.h"
|
|
||||||
#include <qsettings.h>
|
|
||||||
#include <QDBusInterface>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QDBusReply>
|
|
||||||
|
|
||||||
SinglePage::SinglePage(QWidget *parent) : QWidget(parent)
|
|
||||||
{
|
|
||||||
initUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
SinglePage::~SinglePage()
|
|
||||||
{
|
|
||||||
delete m_netDivider;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SinglePage::initUI()
|
|
||||||
{
|
|
||||||
m_mainLayout = new QVBoxLayout(this);
|
|
||||||
m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
|
||||||
m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
|
|
||||||
this->setLayout(m_mainLayout);
|
|
||||||
|
|
||||||
m_netFrame = new QFrame(this);
|
|
||||||
m_netFrame->setMinimumHeight(TEXT_HEIGHT + 17);
|
|
||||||
m_netLayout = new QVBoxLayout(m_netFrame);
|
|
||||||
m_netLayout->setContentsMargins(NET_LAYOUT_MARGINS);
|
|
||||||
m_netFrame->setLayout(m_netLayout);
|
|
||||||
|
|
||||||
m_netLabel = new QLabel(m_netFrame);
|
|
||||||
m_netLabel->setContentsMargins(TEXT_MARGINS);
|
|
||||||
m_netLabel->setFixedHeight(TEXT_HEIGHT);
|
|
||||||
|
|
||||||
m_netListArea = new QWidget(m_netFrame);
|
|
||||||
m_netAreaLayout = new QVBoxLayout(m_netListArea);
|
|
||||||
m_netAreaLayout->setSpacing(MAIN_LAYOUT_SPACING);
|
|
||||||
m_netAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
|
||||||
|
|
||||||
m_netLayout->addWidget(m_netLabel);
|
|
||||||
m_netLayout->addWidget(m_netListArea);
|
|
||||||
|
|
||||||
m_netDivider = new Divider(this);
|
|
||||||
m_settingsFrame = new QFrame(this);
|
|
||||||
m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
|
|
||||||
|
|
||||||
m_settingsLayout = new QHBoxLayout(m_settingsFrame);
|
|
||||||
m_settingsLayout->setContentsMargins(SETTINGS_LAYOUT_MARGINS);
|
|
||||||
|
|
||||||
m_settingsLabel = new KyLable(m_settingsFrame);
|
|
||||||
m_settingsLabel->setCursor(Qt::PointingHandCursor);
|
|
||||||
m_settingsLabel->setText(tr("Settings"));
|
|
||||||
m_settingsLabel->setScaledContents(true);
|
|
||||||
|
|
||||||
m_settingsLayout->addWidget(m_settingsLabel);
|
|
||||||
m_settingsLayout->addStretch();
|
|
||||||
m_settingsFrame->setLayout(m_settingsLayout);
|
|
||||||
|
|
||||||
m_mainLayout->addWidget(m_netFrame);
|
|
||||||
m_mainLayout->addStretch();
|
|
||||||
m_mainLayout->addWidget(m_netDivider);
|
|
||||||
m_mainLayout->addWidget(m_settingsFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SinglePage::showDesktopNotify(const QString &message, QString soundName)
|
|
||||||
{
|
|
||||||
QDBusInterface iface("org.freedesktop.Notifications",
|
|
||||||
"/org/freedesktop/Notifications",
|
|
||||||
"org.freedesktop.Notifications",
|
|
||||||
QDBusConnection::sessionBus());
|
|
||||||
QStringList actions; //跳转动作
|
|
||||||
actions.append("kylin-nm");
|
|
||||||
actions.append("default"); //默认动作:点击消息体时打开麒麟录音
|
|
||||||
QMap<QString, QVariant> hints;
|
|
||||||
if (!soundName.isEmpty()) {
|
|
||||||
hints.insert("sound-name",soundName); //添加声音
|
|
||||||
}
|
|
||||||
QList<QVariant> args;
|
|
||||||
args<<(tr("Kylin NM"))
|
|
||||||
<<((unsigned int) 0)
|
|
||||||
<<QString("gnome-dev-ethernet")
|
|
||||||
<<tr("kylin network applet desktop message") //显示的是什么类型的信息
|
|
||||||
<<message //显示的具体信息
|
|
||||||
<<actions
|
|
||||||
<<hints
|
|
||||||
<<(int)-1;
|
|
||||||
iface.callWithArgumentList(QDBus::AutoDetect,"Notify",args);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef SINGLEPAGE_H
|
|
||||||
#define SINGLEPAGE_H
|
|
||||||
|
|
||||||
#include "divider.h"
|
|
||||||
#include "kylable.h"
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QFormLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QScrollArea>
|
|
||||||
#include <QListWidget>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QComboBox>
|
|
||||||
#include <QEvent>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QDebug>
|
|
||||||
#include "kylinnetworkdeviceresource.h"
|
|
||||||
#include "firewalldialog.h"
|
|
||||||
#include "kwidget.h"
|
|
||||||
#include "kswitchbutton.h"
|
|
||||||
//#include "kborderlessbutton.h"
|
|
||||||
|
|
||||||
using namespace kdk;
|
|
||||||
|
|
||||||
#define MAIN_LAYOUT_MARGINS 0,0,0,0
|
|
||||||
#define MAIN_LAYOUT_SPACING 0
|
|
||||||
#define TITLE_FRAME_HEIGHT 50 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度
|
|
||||||
#define NET_LAYOUT_MARGINS 8,8,0,1
|
|
||||||
#define NET_LAYOUT_SPACING 8
|
|
||||||
#define NET_LIST_SPACING 0
|
|
||||||
#define TEXT_MARGINS 16,0,0,0
|
|
||||||
#define TEXT_HEIGHT 20
|
|
||||||
//#define SCROLL_AREA_HEIGHT 200
|
|
||||||
#define SETTINGS_LAYOUT_MARGINS 23,0,24,0
|
|
||||||
#define TRANSPARENT_COLOR QColor(0,0,0,0)
|
|
||||||
#define INACTIVE_AREA_MIN_HEIGHT 170
|
|
||||||
|
|
||||||
#define MAX_ITEMS 4
|
|
||||||
#define MAX_WIDTH 412
|
|
||||||
#define MIN_WIDTH 404
|
|
||||||
|
|
||||||
#define SCROLL_STEP 4
|
|
||||||
|
|
||||||
class SinglePage : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit SinglePage(QWidget *parent = nullptr);
|
|
||||||
~SinglePage();
|
|
||||||
|
|
||||||
static void showDesktopNotify(const QString &message, QString soundName);
|
|
||||||
|
|
||||||
void hideSetting() {
|
|
||||||
if (nullptr != m_settingsFrame) {
|
|
||||||
m_settingsFrame->hide();
|
|
||||||
m_netDivider->hide();
|
|
||||||
m_netFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT + 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void showSetting() {
|
|
||||||
if (nullptr != m_settingsFrame) {
|
|
||||||
m_netFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT);
|
|
||||||
m_settingsFrame->show();
|
|
||||||
m_netDivider->show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void activateFailed(QString errorMessage);
|
|
||||||
void deactivateFailed(QString errorMessage);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void initUI();
|
|
||||||
QVBoxLayout * m_mainLayout = nullptr;
|
|
||||||
|
|
||||||
QFrame * m_netFrame = nullptr;
|
|
||||||
QVBoxLayout * m_netLayout = nullptr;
|
|
||||||
QLabel * m_netLabel = nullptr;
|
|
||||||
QWidget * m_netListArea = nullptr;
|
|
||||||
QVBoxLayout * m_netAreaLayout = nullptr;
|
|
||||||
|
|
||||||
Divider * m_netDivider = nullptr;
|
|
||||||
|
|
||||||
QFrame * m_settingsFrame = nullptr;
|
|
||||||
QHBoxLayout * m_settingsLayout = nullptr;
|
|
||||||
KyLable * m_settingsLabel = nullptr;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TABPAGE_H
|
|
|
@ -1,645 +0,0 @@
|
||||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#include "vpnpage.h"
|
|
||||||
#include "networkmodeconfig.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QScrollBar>
|
|
||||||
|
|
||||||
#define VPN_LIST_SPACING 0
|
|
||||||
#define ITEM_HEIGHT 48
|
|
||||||
|
|
||||||
|
|
||||||
#define LOG_FLAG "[VpnPage]"
|
|
||||||
|
|
||||||
const QString EMPTY_CONNECT_UUID = "emptyconnect";
|
|
||||||
|
|
||||||
const QString WIRED_SWITCH = "wiredswitch";
|
|
||||||
|
|
||||||
VpnPage::VpnPage(QWidget *parent) : SinglePage(parent)
|
|
||||||
{
|
|
||||||
m_activeResourse = new KyActiveConnectResourse(this);
|
|
||||||
m_connectResourse = new KyConnectResourse(this);
|
|
||||||
// m_deviceResource = new KyNetworkDeviceResourse(this);
|
|
||||||
m_wiredConnectOperation = new KyWiredConnectOperation(this);
|
|
||||||
|
|
||||||
initUI();
|
|
||||||
initVpnArea();
|
|
||||||
|
|
||||||
connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &VpnPage::onConnectionStateChange);
|
|
||||||
connect(m_activeResourse, &KyActiveConnectResourse::activeConnectRemove, this, [=] (QString activeConnectUuid) {
|
|
||||||
sendVpnStateChangeSignal(activeConnectUuid,Deactivated);
|
|
||||||
} );
|
|
||||||
|
|
||||||
connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &VpnPage::onAddConnection);
|
|
||||||
connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &VpnPage::onRemoveConnection);
|
|
||||||
connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &VpnPage::onUpdateConnection);
|
|
||||||
|
|
||||||
connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &VpnPage::activateFailed);
|
|
||||||
connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &VpnPage::deactivateFailed);
|
|
||||||
}
|
|
||||||
|
|
||||||
VpnPage::~VpnPage()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::deleteConnectionMapItem(QMap<QString, QListWidgetItem *> &connectMap,
|
|
||||||
QListWidget *lanListWidget, QString uuid)
|
|
||||||
{
|
|
||||||
QListWidgetItem *p_listWidgetItem = connectMap.value(uuid);
|
|
||||||
if (p_listWidgetItem) {
|
|
||||||
connectMap.remove(uuid);
|
|
||||||
VpnListItem *p_lanItem = (VpnListItem *)lanListWidget->itemWidget(p_listWidgetItem);
|
|
||||||
lanListWidget->removeItemWidget(p_listWidgetItem);
|
|
||||||
|
|
||||||
delete p_lanItem;
|
|
||||||
p_lanItem = nullptr;
|
|
||||||
|
|
||||||
delete p_listWidgetItem;
|
|
||||||
p_listWidgetItem = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::clearConnectionMap(QMap<QString, QListWidgetItem *> &connectMap,
|
|
||||||
QListWidget *lanListWidget)
|
|
||||||
{
|
|
||||||
QMap<QString, QListWidgetItem *>::iterator iter;
|
|
||||||
|
|
||||||
iter = connectMap.begin();
|
|
||||||
while (iter != connectMap.end()) {
|
|
||||||
qDebug()<<"[VpnPage] clear connection map item"<< iter.key();
|
|
||||||
|
|
||||||
QListWidgetItem *p_widgetItem = iter.value();
|
|
||||||
VpnListItem *p_lanItem = (VpnListItem *)lanListWidget->itemWidget(p_widgetItem);
|
|
||||||
lanListWidget->removeItemWidget(p_widgetItem);
|
|
||||||
|
|
||||||
delete p_lanItem;
|
|
||||||
p_lanItem = nullptr;
|
|
||||||
|
|
||||||
delete p_widgetItem;
|
|
||||||
p_widgetItem = nullptr;
|
|
||||||
|
|
||||||
iter = connectMap.erase(iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::constructActiveConnectionArea()
|
|
||||||
{
|
|
||||||
QList<KyConnectItem *> activedList;
|
|
||||||
QList<KyConnectItem *> netList;
|
|
||||||
QGSettings* vpnGsettings = nullptr;
|
|
||||||
if (QGSettings::isSchemaInstalled(GSETTINGS_VPNICON_VISIBLE)) {
|
|
||||||
vpnGsettings = new QGSettings(GSETTINGS_VPNICON_VISIBLE);
|
|
||||||
}
|
|
||||||
activedList.clear();
|
|
||||||
netList.clear();
|
|
||||||
clearConnectionMap(m_activeConnectionMap, m_vpnListWidget);
|
|
||||||
|
|
||||||
m_connectResourse->getVpnAndVirtualConnections(netList);
|
|
||||||
KyConnectItem *p_newItem = nullptr;
|
|
||||||
if (!netList.isEmpty()) {
|
|
||||||
for (int index = 0; index < netList.size(); index++) {
|
|
||||||
KyConnectItem *p_netConnectionItem = netList.at(index);
|
|
||||||
p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid);
|
|
||||||
if (p_newItem == nullptr) {
|
|
||||||
if (m_netConnectionMap.contains(p_netConnectionItem->m_connectUuid)) {
|
|
||||||
qDebug()<<LOG_FLAG << "has contain uuid" << p_netConnectionItem->m_connectUuid;
|
|
||||||
}
|
|
||||||
QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_vpnListWidget);
|
|
||||||
m_netConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem);
|
|
||||||
} else {
|
|
||||||
if (m_activeConnectionMap.contains(p_netConnectionItem->m_connectUuid)) {
|
|
||||||
qDebug()<<LOG_FLAG << "has contain uuid" << p_netConnectionItem->m_connectUuid;
|
|
||||||
}
|
|
||||||
QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_vpnListWidget);
|
|
||||||
m_activeConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete p_netConnectionItem;
|
|
||||||
p_netConnectionItem = nullptr;
|
|
||||||
}
|
|
||||||
if (vpnGsettings != nullptr
|
|
||||||
&& vpnGsettings->keys().contains(QString(VISIBLE))) {
|
|
||||||
vpnGsettings->set(VISIBLE, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (vpnGsettings != nullptr
|
|
||||||
&& vpnGsettings->keys().contains(QString(VISIBLE))) {
|
|
||||||
vpnGsettings->set(VISIBLE, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_vpnListWidget->count() <= MAX_ITEMS) {
|
|
||||||
m_vpnListWidget->setFixedWidth(MIN_WIDTH);
|
|
||||||
m_netListArea->setFixedHeight(m_vpnListWidget->count() * ITEM_HEIGHT);
|
|
||||||
} else {
|
|
||||||
m_vpnListWidget->setFixedWidth(MAX_WIDTH);
|
|
||||||
m_netListArea->setFixedHeight(MAX_ITEMS * ITEM_HEIGHT);
|
|
||||||
}
|
|
||||||
m_netFrame->setFixedHeight(37 + m_netListArea->height());
|
|
||||||
|
|
||||||
delete vpnGsettings;
|
|
||||||
vpnGsettings = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::initVpnArea()
|
|
||||||
{
|
|
||||||
m_netFrame->show();
|
|
||||||
constructActiveConnectionArea();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VpnPage::removeConnectionItem(QMap<QString, QListWidgetItem *> &connectMap,
|
|
||||||
QListWidget *lanListWidget, QString path)
|
|
||||||
{
|
|
||||||
QMap<QString, QListWidgetItem *>::iterator iter;
|
|
||||||
for (iter = connectMap.begin(); iter != connectMap.end(); ++iter) {
|
|
||||||
QListWidgetItem *p_listWidgetItem = iter.value();
|
|
||||||
VpnListItem *p_lanItem = (VpnListItem*)lanListWidget->itemWidget(p_listWidgetItem);
|
|
||||||
if (p_lanItem->getConnectionPath() == path) {
|
|
||||||
qDebug()<<"[VpnPage] Remove a connection from list";
|
|
||||||
|
|
||||||
lanListWidget->removeItemWidget(p_listWidgetItem);
|
|
||||||
|
|
||||||
delete p_lanItem;
|
|
||||||
p_lanItem = nullptr;
|
|
||||||
|
|
||||||
delete p_listWidgetItem;
|
|
||||||
p_listWidgetItem = nullptr;
|
|
||||||
|
|
||||||
iter = connectMap.erase(iter);
|
|
||||||
if (m_vpnListWidget->count() <= MAX_ITEMS) {
|
|
||||||
m_vpnListWidget->setFixedWidth(MIN_WIDTH);
|
|
||||||
m_netListArea->setFixedHeight(m_vpnListWidget->count() * ITEM_HEIGHT);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::onRemoveConnection(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除
|
|
||||||
{
|
|
||||||
//for dbus
|
|
||||||
qDebug() << "[VpnPage] emit lanRemove because onRemoveConnection " << path;
|
|
||||||
Q_EMIT vpnRemove(path);
|
|
||||||
|
|
||||||
if (removeConnectionItem(m_netConnectionMap, m_vpnListWidget, path)) {
|
|
||||||
m_netFrame->setFixedHeight(37 + m_netListArea->height());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::onAddConnection(QString uuid) //新增一个有线连接,将其加入到激活列表
|
|
||||||
{
|
|
||||||
if (!m_connectResourse->isVirtualConncection(uuid)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
KyConnectItem *p_newItem = nullptr;
|
|
||||||
p_newItem = m_connectResourse->getConnectionItemByUuid(uuid);
|
|
||||||
if (nullptr == p_newItem) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendVpnAddSignal(p_newItem);
|
|
||||||
|
|
||||||
qDebug()<<"[VpnPage] Add a new connection, name:"<<p_newItem->m_connectName;
|
|
||||||
QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_vpnListWidget);
|
|
||||||
if (m_netConnectionMap.contains(p_newItem->m_connectUuid)) {
|
|
||||||
qDebug()<<LOG_FLAG << "the connection is exsit" << p_newItem->m_connectUuid;
|
|
||||||
}
|
|
||||||
m_netConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
|
|
||||||
|
|
||||||
delete p_newItem;
|
|
||||||
p_newItem = nullptr;
|
|
||||||
if (m_vpnListWidget->count() >= MAX_ITEMS) {
|
|
||||||
m_vpnListWidget->setFixedWidth(MAX_WIDTH);
|
|
||||||
m_netListArea->setFixedHeight(MAX_ITEMS * ITEM_HEIGHT);
|
|
||||||
} else {
|
|
||||||
m_netListArea->setFixedHeight(m_vpnListWidget->count() * ITEM_HEIGHT);
|
|
||||||
}
|
|
||||||
m_netFrame->setFixedHeight(37 + m_netListArea->height());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::onShowControlCenter()
|
|
||||||
{
|
|
||||||
QProcess process;
|
|
||||||
process.startDetached("ukui-control-center -m vpn");
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::initUI()
|
|
||||||
{
|
|
||||||
m_netLabel->setText(tr("VPN Connection"));
|
|
||||||
m_vpnListWidget = new QListWidget(m_netListArea);
|
|
||||||
m_vpnListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
|
||||||
m_vpnListWidget->setSpacing(VPN_LIST_SPACING);
|
|
||||||
m_vpnListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
||||||
m_vpnListWidget->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel);
|
|
||||||
m_vpnListWidget->verticalScrollBar()->setProperty("drawScrollBarGroove",false); //去除滚动条的外侧黑框
|
|
||||||
m_vpnListWidget->verticalScrollBar()->setSingleStep(SCROLL_STEP);
|
|
||||||
m_vpnListWidget->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu);
|
|
||||||
m_netAreaLayout->addWidget(m_vpnListWidget);
|
|
||||||
m_netListArea->setFixedHeight(0);
|
|
||||||
|
|
||||||
QPalette pal = m_vpnListWidget->palette();
|
|
||||||
pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明
|
|
||||||
m_vpnListWidget->setPalette(pal);
|
|
||||||
|
|
||||||
m_settingsLabel->setText(tr("VPN Settings"));
|
|
||||||
m_settingsLabel->installEventFilter(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QListWidgetItem *VpnPage::insertNewItem(KyConnectItem *itemData, QListWidget *listWidget)
|
|
||||||
{
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
for(index = 0; index < m_vpnListWidget->count(); index++) {
|
|
||||||
QListWidgetItem *p_listWidgetItem = m_vpnListWidget->item(index);
|
|
||||||
VpnListItem *p_lanItem = (VpnListItem *)m_vpnListWidget->itemWidget(p_listWidgetItem);
|
|
||||||
QString name1 = p_lanItem->getConnectionName();
|
|
||||||
QString name2 = itemData->m_connectName;
|
|
||||||
if (QString::compare(name1, name2, Qt::CaseInsensitive) > 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QListWidgetItem *p_sortListWidgetItem = new QListWidgetItem();
|
|
||||||
p_sortListWidgetItem->setFlags(p_sortListWidgetItem->flags() & (~Qt::ItemIsSelectable)); //设置不可被选中
|
|
||||||
p_sortListWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT));
|
|
||||||
|
|
||||||
listWidget->insertItem(index, p_sortListWidgetItem);
|
|
||||||
|
|
||||||
VpnListItem *p_sortLanItem = nullptr;
|
|
||||||
p_sortLanItem = new VpnListItem(itemData);
|
|
||||||
listWidget->setItemWidget(p_sortListWidgetItem, p_sortLanItem);
|
|
||||||
|
|
||||||
return p_sortListWidgetItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
QListWidgetItem *VpnPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget)
|
|
||||||
{
|
|
||||||
QListWidgetItem *p_listWidgetItem = new QListWidgetItem();
|
|
||||||
p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable));
|
|
||||||
p_listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT));
|
|
||||||
listWidget->addItem(p_listWidgetItem);
|
|
||||||
VpnListItem *p_lanItem = nullptr;
|
|
||||||
if (itemData != nullptr) {
|
|
||||||
p_lanItem = new VpnListItem(itemData);
|
|
||||||
qDebug() << "[VpnPage] addNewItem, connection: " << itemData->m_connectName;
|
|
||||||
} else {
|
|
||||||
p_lanItem = new VpnListItem();
|
|
||||||
qDebug() << "[VpnPage] Add nullItem!";
|
|
||||||
}
|
|
||||||
|
|
||||||
listWidget->setItemWidget(p_listWidgetItem, p_lanItem);
|
|
||||||
return p_listWidgetItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::updateActivatedConnectionArea(KyConnectItem *p_newItem)
|
|
||||||
{
|
|
||||||
if (m_activeConnectionMap.contains(p_newItem->m_connectUuid)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteConnectionMapItem(m_netConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid);
|
|
||||||
qDebug()<<"[VpnPage]update active connection item"<<p_newItem->m_connectName;
|
|
||||||
deleteConnectionMapItem(m_activeConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid);
|
|
||||||
QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_vpnListWidget);
|
|
||||||
m_activeConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
|
|
||||||
if (m_vpnListWidget->count() <= MAX_ITEMS) {
|
|
||||||
m_vpnListWidget->setFixedWidth(MIN_WIDTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::updateConnectionArea(KyConnectItem *p_newItem)
|
|
||||||
{
|
|
||||||
if (m_netConnectionMap.contains(p_newItem->m_connectUuid)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteConnectionMapItem(m_activeConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid);
|
|
||||||
qDebug()<<"[VpnPage] update connection item"<<p_newItem->m_connectName;
|
|
||||||
QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_vpnListWidget);
|
|
||||||
m_netConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
|
|
||||||
|
|
||||||
if (m_vpnListWidget->count() <= MAX_ITEMS) {
|
|
||||||
m_vpnListWidget->setFixedWidth(MIN_WIDTH);
|
|
||||||
} else {
|
|
||||||
m_vpnListWidget->setFixedWidth(MAX_WIDTH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::updateConnectionState(QMap<QString, QListWidgetItem *> &connectMap,
|
|
||||||
QListWidget *lanListWidget, QString uuid, ConnectState state)
|
|
||||||
{
|
|
||||||
qDebug() << LOG_FLAG << "update connection state";
|
|
||||||
|
|
||||||
QListWidgetItem *p_listWidgetItem = connectMap.value(uuid);
|
|
||||||
if (p_listWidgetItem) {
|
|
||||||
VpnListItem *p_lanItem = (VpnListItem *)lanListWidget->itemWidget(p_listWidgetItem);
|
|
||||||
p_lanItem->updateConnectionState(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::onConnectionStateChange(QString uuid,
|
|
||||||
NetworkManager::ActiveConnection::State state,
|
|
||||||
NetworkManager::ActiveConnection::Reason reason)
|
|
||||||
{
|
|
||||||
//VpnPage函数内持续监听连接状态的变化并记录供其他函数调用获取状态
|
|
||||||
if (!m_connectResourse->isVirtualConncection(uuid)) {
|
|
||||||
qDebug() << "[VpnPage] connection state change signal but not vpn";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendVpnStateChangeSignal(uuid, (ConnectState)state);
|
|
||||||
|
|
||||||
if (m_activeConnectionMap.keys().contains(uuid) && state == NetworkManager::ActiveConnection::State::Activated) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug()<<"[VpnPage] connection uuid"<< uuid
|
|
||||||
<< "state change slot:"<< state;
|
|
||||||
|
|
||||||
KyConnectItem *p_newItem = nullptr;
|
|
||||||
QString deviceName = "";
|
|
||||||
QString ssid = "";
|
|
||||||
|
|
||||||
if (state == NetworkManager::ActiveConnection::State::Activated) {
|
|
||||||
p_newItem = m_activeResourse->getActiveConnectionByUuid(uuid);
|
|
||||||
if (nullptr == p_newItem) {
|
|
||||||
qWarning()<<"[VpnPage] get active connection failed, connection uuid" << uuid;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssid = p_newItem->m_connectName;
|
|
||||||
updateActivatedConnectionArea(p_newItem);
|
|
||||||
updateConnectionState(m_activeConnectionMap, m_vpnListWidget, uuid, (ConnectState)state);
|
|
||||||
} else if (state == NetworkManager::ActiveConnection::State::Deactivated) {
|
|
||||||
p_newItem = m_connectResourse->getConnectionItemByUuid(uuid);
|
|
||||||
qDebug() << "[VpnPage] deactivated reason" << reason;
|
|
||||||
if (nullptr == p_newItem) {
|
|
||||||
qWarning()<<"[VpnPage] get active connection failed, connection uuid" << uuid;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssid = p_newItem->m_connectName;
|
|
||||||
updateConnectionArea(p_newItem);
|
|
||||||
updateConnectionState(m_netConnectionMap, m_vpnListWidget, uuid, (ConnectState)state);
|
|
||||||
NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, deviceName, ssid);
|
|
||||||
} else if (state == NetworkManager::ActiveConnection::State::Activating) {
|
|
||||||
updateConnectionState(m_netConnectionMap, m_vpnListWidget, uuid, (ConnectState)state);
|
|
||||||
} else if (state == NetworkManager::ActiveConnection::State::Deactivating) {
|
|
||||||
updateConnectionState(m_activeConnectionMap, m_vpnListWidget, uuid, (ConnectState)state);
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT vpnActiveConnectionStateChanged(uuid, state);
|
|
||||||
|
|
||||||
if (p_newItem) {
|
|
||||||
delete p_newItem;
|
|
||||||
p_newItem = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::getVirtualList(QVector<QStringList> &vector)
|
|
||||||
{
|
|
||||||
QList<KyConnectItem *> netConnectList;
|
|
||||||
vector.clear();
|
|
||||||
m_connectResourse->getVpnAndVirtualConnections(netConnectList); //未激活列表的显示
|
|
||||||
if (!netConnectList.isEmpty()) {
|
|
||||||
for (int i = 0; i < netConnectList.size(); i++) {
|
|
||||||
KyConnectItem *p_newItem = nullptr;
|
|
||||||
KyConnectItem *p_netConnectionItem = netConnectList.at(i);
|
|
||||||
p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid);
|
|
||||||
NetworkManager::ActiveConnection::State state = p_netConnectionItem->m_connectState;
|
|
||||||
if (p_newItem != nullptr) {
|
|
||||||
state = NetworkManager::ActiveConnection::Activated;
|
|
||||||
}
|
|
||||||
vector.append(QStringList() << netConnectList.at(i)->m_connectName
|
|
||||||
<< netConnectList.at(i)->m_connectUuid
|
|
||||||
<< netConnectList.at(i)->m_connectPath
|
|
||||||
<< QString::number(state));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::sendVpnUpdateSignal(KyConnectItem *p_connectItem)
|
|
||||||
{
|
|
||||||
QStringList info;
|
|
||||||
info << p_connectItem->m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath;
|
|
||||||
Q_EMIT vpnUpdate(info);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::sendVpnAddSignal(KyConnectItem *p_connectItem)
|
|
||||||
{
|
|
||||||
QStringList info;
|
|
||||||
KyConnectItem *p_newItem = nullptr;
|
|
||||||
p_newItem = m_activeResourse->getActiveConnectionByUuid(p_connectItem->m_connectUuid);
|
|
||||||
NetworkManager::ActiveConnection::State state = p_connectItem->m_connectState;
|
|
||||||
if (p_newItem != nullptr) {
|
|
||||||
state = NetworkManager::ActiveConnection::Activated;
|
|
||||||
}
|
|
||||||
info << p_connectItem->m_connectName
|
|
||||||
<< p_connectItem->m_connectUuid
|
|
||||||
<< p_connectItem->m_connectPath
|
|
||||||
<< QString::number(state);
|
|
||||||
qDebug() << "[VpnPage] emit vpnAdd because addConnection ";
|
|
||||||
Q_EMIT vpnAdd(info);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::sendVpnStateChangeSignal(QString uuid, ConnectState state)
|
|
||||||
{
|
|
||||||
if (state == Activating || state == Deactivating) {
|
|
||||||
if (m_activeResourse->connectionIsVirtual(uuid)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT this->vpnConnectChanged(state);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::updateConnectionProperty(KyConnectItem *p_connectItem)
|
|
||||||
{
|
|
||||||
QString newUuid = p_connectItem->m_connectUuid;
|
|
||||||
|
|
||||||
if (m_netConnectionMap.contains(newUuid)) {
|
|
||||||
QListWidgetItem *p_listWidgetItem = m_netConnectionMap.value(newUuid);
|
|
||||||
VpnListItem *p_lanItem = (VpnListItem*)m_vpnListWidget->itemWidget(p_listWidgetItem);
|
|
||||||
if (p_connectItem->m_connectName != p_lanItem->getConnectionName()){
|
|
||||||
//只要名字改变就要删除,重新插入,主要是为了排序
|
|
||||||
deleteConnectionMapItem(m_netConnectionMap, m_vpnListWidget, newUuid);
|
|
||||||
QListWidgetItem *p_sortListWidgetItem = insertNewItem(p_connectItem, m_vpnListWidget);
|
|
||||||
if (m_netConnectionMap.contains(newUuid)) {
|
|
||||||
qDebug()<<LOG_FLAG << "has contained connection" << newUuid;
|
|
||||||
}
|
|
||||||
m_netConnectionMap.insert(newUuid, p_sortListWidgetItem);
|
|
||||||
} else if (p_connectItem->m_connectPath != p_lanItem->getConnectionPath()) {
|
|
||||||
p_lanItem->updateConnectionPath(p_connectItem->m_connectPath);
|
|
||||||
}
|
|
||||||
} else if (!m_activeConnectionMap.contains(newUuid)){
|
|
||||||
if (p_connectItem->m_ifaceName.isEmpty()) {
|
|
||||||
QListWidgetItem *p_listWidgetItem = insertNewItem(p_connectItem, m_vpnListWidget);
|
|
||||||
if (m_netConnectionMap.contains(newUuid)) {
|
|
||||||
qDebug()<<LOG_FLAG << "has contained connection uuid" << newUuid;
|
|
||||||
}
|
|
||||||
m_netConnectionMap.insert(newUuid, p_listWidgetItem);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
qWarning() << LOG_FLAG << newUuid <<" is in activemap, so not process.";
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::updateActiveConnectionProperty(KyConnectItem *p_connectItem)
|
|
||||||
{
|
|
||||||
QString newUuid = p_connectItem->m_connectUuid;
|
|
||||||
|
|
||||||
if (m_activeConnectionMap.contains(newUuid)) {
|
|
||||||
QListWidgetItem *p_listWidgetItem = m_activeConnectionMap.value(newUuid);
|
|
||||||
VpnListItem *p_lanItem = (VpnListItem *)m_vpnListWidget->itemWidget(p_listWidgetItem);
|
|
||||||
if (p_lanItem->getConnectionName() != p_connectItem->m_connectName) {
|
|
||||||
p_lanItem->updateConnectionName(p_connectItem->m_connectName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_lanItem->getConnectionName() != p_connectItem->m_connectPath) {
|
|
||||||
p_lanItem->updateConnectionPath(p_connectItem->m_connectPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::onUpdateConnection(QString uuid)
|
|
||||||
{
|
|
||||||
if (!m_connectResourse->isVirtualConncection(uuid)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << "[VpnPage]:Connection property Changed." << Q_FUNC_INFO << __LINE__;
|
|
||||||
|
|
||||||
KyConnectItem *p_newItem = nullptr;
|
|
||||||
if (m_connectResourse->isActivatedConnection(uuid)) {
|
|
||||||
p_newItem = m_activeResourse->getActiveConnectionByUuid(uuid);
|
|
||||||
if (nullptr == p_newItem) {
|
|
||||||
qWarning()<<"[VpnPage] get item failed, when update activate connection."
|
|
||||||
<<"connection uuid" << uuid;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateActiveConnectionProperty(p_newItem);
|
|
||||||
} else {
|
|
||||||
p_newItem = m_connectResourse->getConnectionItemByUuid(uuid);
|
|
||||||
if (nullptr == p_newItem) {
|
|
||||||
qWarning()<<"[VpnPage] get item failed, when update connection."
|
|
||||||
<<"connection uuid"<<uuid;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateConnectionProperty(p_newItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
sendVpnUpdateSignal(p_newItem);
|
|
||||||
|
|
||||||
delete p_newItem;
|
|
||||||
p_newItem = nullptr;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VpnPage::eventFilter(QObject *watched, QEvent *event)
|
|
||||||
{
|
|
||||||
if (watched == m_settingsLabel) {
|
|
||||||
if (event->type() == QEvent::MouseButtonRelease) {
|
|
||||||
onShowControlCenter();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VpnPage::showDetailPage(QString devName, QString uuid)
|
|
||||||
{
|
|
||||||
#ifdef VPN_DETAIL
|
|
||||||
KyConnectItem *p_item = nullptr;
|
|
||||||
bool isActive = true;
|
|
||||||
|
|
||||||
if (m_connectResourse->isActivatedConnection(uuid)) {
|
|
||||||
p_item = m_activeResourse->getActiveConnectionByUuid(uuid);
|
|
||||||
isActive = true;
|
|
||||||
} else {
|
|
||||||
p_item = m_connectResourse->getConnectionItemByUuid(uuid);
|
|
||||||
isActive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nullptr == p_item) {
|
|
||||||
qWarning()<<"[VpnPage] GetConnectionItemByUuid is empty when showDetailPage."
|
|
||||||
<<"device name"<<devName
|
|
||||||
<<"connect uuid"<<uuid;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetDetail *netDetail = new NetDetail(devName, p_item->m_connectName, uuid, isActive, false, false);
|
|
||||||
netDetail->show();
|
|
||||||
|
|
||||||
delete p_item;
|
|
||||||
p_item = nullptr;
|
|
||||||
#endif
|
|
||||||
}
|
|
|
@ -1,126 +0,0 @@
|
||||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef VPNPAGE_H
|
|
||||||
#define VPNPAGE_H
|
|
||||||
|
|
||||||
#include "divider.h"
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QScrollArea>
|
|
||||||
#include <QListWidget>
|
|
||||||
#include <QMap>
|
|
||||||
#include <QGSettings>
|
|
||||||
|
|
||||||
#include "list-items/listitem.h"
|
|
||||||
#include "list-items/vpnlistitem.h"
|
|
||||||
#include "single-pages/singlepage.h"
|
|
||||||
|
|
||||||
#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
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit VpnPage(QWidget *parent = nullptr);
|
|
||||||
~VpnPage();
|
|
||||||
|
|
||||||
//for dbus
|
|
||||||
void getVirtualList(QVector<QStringList> &vector);
|
|
||||||
void deleteVpn(const QString &connUuid);
|
|
||||||
void activateVpn(const QString& connUuid);
|
|
||||||
void deactivateVpn(const QString& connUuid);
|
|
||||||
void showDetailPage(QString devName, QString uuid);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void initUI();
|
|
||||||
void initVpnArea();
|
|
||||||
|
|
||||||
inline void initDeviceCombox() { return; }
|
|
||||||
|
|
||||||
QListWidgetItem *insertNewItem(KyConnectItem *itemData, QListWidget *listWidget);
|
|
||||||
QListWidgetItem *addNewItem(KyConnectItem *itemData, QListWidget *listWidget);
|
|
||||||
bool removeConnectionItem(QMap<QString, QListWidgetItem *> &connectMap,
|
|
||||||
QListWidget *lanListWidget, QString path);
|
|
||||||
|
|
||||||
void constructActiveConnectionArea();
|
|
||||||
|
|
||||||
void updateConnectionArea(KyConnectItem *p_newItem);
|
|
||||||
void updateActivatedConnectionArea(KyConnectItem *p_newItem);
|
|
||||||
void updateConnectionState(QMap<QString, QListWidgetItem *> &connectMap,
|
|
||||||
QListWidget *lanListWidget, QString uuid, ConnectState state);
|
|
||||||
|
|
||||||
void updateActiveConnectionProperty(KyConnectItem *p_connectItem);
|
|
||||||
void updateConnectionProperty(KyConnectItem *p_connectItem);
|
|
||||||
|
|
||||||
void sendVpnUpdateSignal(KyConnectItem *p_connectItem);
|
|
||||||
void sendVpnAddSignal(KyConnectItem *p_connectItem);
|
|
||||||
void sendVpnStateChangeSignal(QString uuid, ConnectState state);
|
|
||||||
|
|
||||||
void clearConnectionMap(QMap<QString, QListWidgetItem *> &connectMap,
|
|
||||||
QListWidget *lanListWidget);
|
|
||||||
void deleteConnectionMapItem(QMap<QString, QListWidgetItem *> &connectMap,
|
|
||||||
QListWidget *lanListWidget, QString uuid);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void vpnAdd(QStringList info);
|
|
||||||
void vpnRemove(QString dbusPath);
|
|
||||||
void vpnUpdate(QStringList info);
|
|
||||||
|
|
||||||
void vpnActiveConnectionStateChanged(QString uuid, int status);
|
|
||||||
void vpnConnectChanged(int state);
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onConnectionStateChange(QString uuid,
|
|
||||||
NetworkManager::ActiveConnection::State state,
|
|
||||||
NetworkManager::ActiveConnection::Reason reason);
|
|
||||||
|
|
||||||
void onAddConnection(QString uuid);
|
|
||||||
void onRemoveConnection(QString path);
|
|
||||||
void onUpdateConnection(QString uuid);
|
|
||||||
|
|
||||||
void onShowControlCenter();
|
|
||||||
|
|
||||||
// void onStateChange();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QListWidget * m_vpnListWidget = nullptr;
|
|
||||||
|
|
||||||
// KyNetworkDeviceResourse *m_deviceResource = nullptr;
|
|
||||||
KyWiredConnectOperation *m_wiredConnectOperation = nullptr;
|
|
||||||
KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接
|
|
||||||
KyConnectResourse *m_connectResourse = nullptr; //未激活的连接
|
|
||||||
|
|
||||||
QMap<QString, QListWidgetItem *> m_netConnectionMap;
|
|
||||||
QMap<QString, QListWidgetItem *> m_activeConnectionMap;
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
inline void onDeviceComboxIndexChanged(int currentIndex) { return; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // LANPAGE_H
|
|
|
@ -1262,6 +1262,7 @@ void LanPage::showDetailPage(QString devName, QString uuid)
|
||||||
NetDetail *netDetail = new NetDetail(devName, p_item->m_connectName, uuid, isActive, false, false);
|
NetDetail *netDetail = new NetDetail(devName, p_item->m_connectName, uuid, isActive, false, false);
|
||||||
m_lanPagePtrMap.insert(p_item->m_connectPath, netDetail);
|
m_lanPagePtrMap.insert(p_item->m_connectPath, netDetail);
|
||||||
netDetail->show();
|
netDetail->show();
|
||||||
|
netDetail->centerToScreen();
|
||||||
|
|
||||||
connect(netDetail, &NetDetail::detailPageClose, [&](QString deviceName, QString lanName, QString lanUuid){
|
connect(netDetail, &NetDetail::detailPageClose, [&](QString deviceName, QString lanName, QString lanUuid){
|
||||||
if (lanUuid.isEmpty()) {
|
if (lanUuid.isEmpty()) {
|
||||||
|
|
|
@ -1492,6 +1492,7 @@ void WlanPage::showHiddenWlanPage(QString devName)
|
||||||
|
|
||||||
m_joinHiddenWiFiPagePtrMap.insert(devName, hiddenWiFi);
|
m_joinHiddenWiFiPagePtrMap.insert(devName, hiddenWiFi);
|
||||||
hiddenWiFi->show();
|
hiddenWiFi->show();
|
||||||
|
hiddenWiFi->centerToScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WlanPage::showDetailPage(QString devName, QString ssid)
|
void WlanPage::showDetailPage(QString devName, QString ssid)
|
||||||
|
@ -1521,6 +1522,7 @@ void WlanPage::showDetailPage(QString devName, QString ssid)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
netDetail->show();
|
netDetail->show();
|
||||||
|
netDetail->centerToScreen();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,495 +0,0 @@
|
||||||
/* -*- 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 "vpnmainwindow.h"
|
|
||||||
#include "customstyle.h"
|
|
||||||
#include <KWindowEffects>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QDBusReply>
|
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QProcess>
|
|
||||||
|
|
||||||
#include "kylinnetworkdeviceresource.h"
|
|
||||||
#include "../backend/dbus-interface/kylinagentinterface.h"
|
|
||||||
|
|
||||||
#include "ukuistylehelper/ukuistylehelper.h"
|
|
||||||
#include "windowmanager/windowmanager.h"
|
|
||||||
#include "kysdk/kysdk-system/libkysysinfo.h"
|
|
||||||
|
|
||||||
#define MAINWINDOW_WIDTH 420
|
|
||||||
#define MAINWINDOW_HEIGHT 300
|
|
||||||
#define VPN_LAYOUT_MARGINS 0,12,0,12
|
|
||||||
#define THEME_SCHAME "org.ukui.style"
|
|
||||||
#define COLOR_THEME "styleName"
|
|
||||||
|
|
||||||
const QString v10Sp1 = "V10SP1";
|
|
||||||
const QString intel = "V10SP1-edu";
|
|
||||||
|
|
||||||
#define KEY_PRODUCT_FEATURES "PRODUCT_FEATURES"
|
|
||||||
|
|
||||||
#include <kwindowsystem.h>
|
|
||||||
#include <kwindowsystem_export.h>
|
|
||||||
|
|
||||||
vpnMainWindow::vpnMainWindow(QWidget *parent): QMainWindow(parent)
|
|
||||||
{
|
|
||||||
firstlyStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::showMainwindow show主窗口,同时也作为dbus接口提供给外部组件调用
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::showMainwindow()
|
|
||||||
{
|
|
||||||
if (!m_loadFinished) {
|
|
||||||
m_secondaryStartTimer->stop();
|
|
||||||
secondaryStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置主界面跳过任务栏和分页器的属性,隐藏再次展示有可能辉冲刷掉该属性,需要展示时重新设置
|
|
||||||
*/
|
|
||||||
QString platform = QGuiApplication::platformName();
|
|
||||||
if(!platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive))
|
|
||||||
{
|
|
||||||
const KWindowInfo info(this->winId(), NET::WMState);
|
|
||||||
if (!info.hasState(NET::SkipTaskbar) || !info.hasState(NET::SkipPager)) {
|
|
||||||
KWindowSystem::setState(this->winId(), NET::SkipTaskbar | NET::SkipPager);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this->showByWaylandHelper();
|
|
||||||
this->raise();
|
|
||||||
this->activateWindow();
|
|
||||||
// Q_EMIT this->mainWindowVisibleChanged(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::hideMainwindow 隐藏主页面时要进行的操作,后续可以添加到此函数
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::hideMainwindow()
|
|
||||||
{
|
|
||||||
this->hide();
|
|
||||||
// Q_EMIT this->mainWindowVisibleChanged(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
///**
|
|
||||||
// * @brief vpnMainWindow::setWiredDefaultDevice 设置有线设备默认网卡
|
|
||||||
// */
|
|
||||||
//void vpnMainWindow::setWiredDefaultDevice(QString deviceName)
|
|
||||||
//{
|
|
||||||
//// m_vpnPage->updateDefaultDevice(deviceName);
|
|
||||||
//}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MainWindow::firstlyStart 一级启动,执行重要且不耗时的启动操作
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::firstlyStart()
|
|
||||||
{
|
|
||||||
initWindowProperties();
|
|
||||||
initTransparency();
|
|
||||||
initUI();
|
|
||||||
initDbusConnnect();
|
|
||||||
initWindowTheme();
|
|
||||||
initTrayIcon();
|
|
||||||
installEventFilter(this);
|
|
||||||
m_secondaryStartTimer = new QTimer(this);
|
|
||||||
connect(m_secondaryStartTimer, &QTimer::timeout, this, [ = ]() {
|
|
||||||
m_secondaryStartTimer->stop();
|
|
||||||
secondaryStart();//满足条件后执行比较耗时的二级启动
|
|
||||||
});
|
|
||||||
m_secondaryStartTimer->start(5 * 1000);
|
|
||||||
|
|
||||||
m_createPagePtrMap.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::secondaryStart 二级启动,可以将较耗时的初始化操作放到此处执行
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::secondaryStart()
|
|
||||||
{
|
|
||||||
if (m_loadFinished)
|
|
||||||
return;
|
|
||||||
m_loadFinished = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::initPlatform 初始化平台信息
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::initPlatform()
|
|
||||||
{
|
|
||||||
char* projectName = kdk_system_get_projectName();
|
|
||||||
QString strProjectName(projectName);
|
|
||||||
free(projectName);
|
|
||||||
projectName = NULL;
|
|
||||||
if(v10Sp1.compare(strProjectName,Qt::CaseInsensitive) == 0) {
|
|
||||||
unsigned int feature = kdk_system_get_productFeatures();
|
|
||||||
if (feature == 3) {
|
|
||||||
m_isShowInCenter = true;
|
|
||||||
}
|
|
||||||
} else if (intel.compare(strProjectName,Qt::CaseInsensitive) == 0) {
|
|
||||||
m_isShowInCenter = true;
|
|
||||||
}
|
|
||||||
qDebug() << "projectName" << projectName << m_isShowInCenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::initWindowProperties 初始化一些窗口属性
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::initWindowProperties()
|
|
||||||
{
|
|
||||||
this->setWindowTitle(tr("kylin-vpn"));
|
|
||||||
// this->setFixedSize(MAINWINDOW_WIDTH, MAINWINDOW_HEIGHT);
|
|
||||||
// //绘制毛玻璃特效
|
|
||||||
// this->setAttribute(Qt::WA_TranslucentBackground, true); //透明
|
|
||||||
this->setProperty("needTranslucent", true);
|
|
||||||
this->setFocusPolicy(Qt::NoFocus);
|
|
||||||
|
|
||||||
QString platform = QGuiApplication::platformName();
|
|
||||||
if(!platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive))
|
|
||||||
{
|
|
||||||
QPainterPath path;
|
|
||||||
auto rect = this->rect();
|
|
||||||
// path.addRoundedRect(rect, 12, 12);
|
|
||||||
path.addRect(rect);
|
|
||||||
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); //背景模糊
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
QPainter painter(this);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
|
||||||
painter.setPen(Qt::transparent);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::initTransparency()
|
|
||||||
{
|
|
||||||
if(QGSettings::isSchemaInstalled(TRANSPARENCY_GSETTINGS)) {
|
|
||||||
m_transGsettings = new QGSettings(TRANSPARENCY_GSETTINGS);
|
|
||||||
if(m_transGsettings->keys().contains(QString("transparency"))) {
|
|
||||||
m_transparency = m_transGsettings->get("transparency").toDouble() + 0.15;
|
|
||||||
m_transparency = (m_transparency > 1) ? 1 : m_transparency;
|
|
||||||
connect(m_transGsettings, &QGSettings::changed, this, &vpnMainWindow::onTransChanged);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::onTransChanged()
|
|
||||||
{
|
|
||||||
m_transparency = m_transGsettings->get("transparency").toDouble() + 0.15;
|
|
||||||
m_transparency = (m_transparency > 1) ? 1 : m_transparency;
|
|
||||||
paintWithTrans();
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::paintWithTrans()
|
|
||||||
{
|
|
||||||
QPalette pal = this->palette();
|
|
||||||
QColor color = qApp->palette().base().color();
|
|
||||||
color.setAlphaF(m_transparency);
|
|
||||||
pal.setColor(QPalette::Window, color);
|
|
||||||
this->setPalette(pal);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::initUI 初始化窗口内控件
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::initUI()
|
|
||||||
{
|
|
||||||
m_vpnWidget = new QWidget(this);
|
|
||||||
this->setCentralWidget(m_vpnWidget);
|
|
||||||
m_vpnLayout = new QVBoxLayout(m_vpnWidget);
|
|
||||||
m_vpnLayout->setContentsMargins(VPN_LAYOUT_MARGINS);
|
|
||||||
m_vpnWidget->setLayout(m_vpnLayout);
|
|
||||||
m_vpnWidget->setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明 解决切换黑屏问题
|
|
||||||
|
|
||||||
m_vpnPage = new VpnPage(m_vpnWidget);
|
|
||||||
m_vpnLayout->addWidget(m_vpnPage);
|
|
||||||
|
|
||||||
paintWithTrans();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::initTrayIcon 初始化托盘图标和托盘右键菜单
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::initTrayIcon()
|
|
||||||
{
|
|
||||||
m_vpnTrayIcon = new QSystemTrayIcon(this);
|
|
||||||
m_vpnTrayIcon->setToolTip(QString(tr("vpn tool")));
|
|
||||||
m_vpnTrayIcon->setIcon(QIcon::fromTheme("ukui-vpn-symbolic"));
|
|
||||||
initVpnIconVisible();
|
|
||||||
connect(m_vpnTrayIcon, &QSystemTrayIcon::activated, this, &vpnMainWindow::onTrayIconActivated);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::initDbusConnnect()
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
//模式切换
|
|
||||||
QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"),
|
|
||||||
QString("/"),
|
|
||||||
QString("com.kylin.statusmanager.interface"),
|
|
||||||
QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::resetWindowPosition 重新计算窗口位置
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::resetWindowPosition()
|
|
||||||
{
|
|
||||||
|
|
||||||
if (m_isShowInCenter) {
|
|
||||||
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
|
|
||||||
QRect rect((availableGeometry.width() - this->width())/2, (availableGeometry.height() - this->height())/2,
|
|
||||||
this->width(), this->height());
|
|
||||||
kdk::WindowManager::setGeometry(this->windowHandle(), rect);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define MARGIN 4
|
|
||||||
#define PANEL_TOP 1
|
|
||||||
#define PANEL_LEFT 2
|
|
||||||
#define PANEL_RIGHT 3
|
|
||||||
//#define PANEL_BOTTOM 4
|
|
||||||
if (!m_positionInterface) {
|
|
||||||
m_positionInterface = new QDBusInterface("org.ukui.panel",
|
|
||||||
"/panel/position",
|
|
||||||
"org.ukui.panel",
|
|
||||||
QDBusConnection::sessionBus());
|
|
||||||
}
|
|
||||||
QRect rect;
|
|
||||||
QDBusReply<QVariantList> reply = m_positionInterface->call("GetPrimaryScreenGeometry");
|
|
||||||
//reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置
|
|
||||||
if (!m_positionInterface->isValid() || !reply.isValid() || reply.value().size() < 5) {
|
|
||||||
qCritical() << QDBusConnection::sessionBus().lastError().message();
|
|
||||||
kdk::WindowManager::setGeometry(this->windowHandle(), QRect(0, 0, this->width(), this->height()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QVariantList position_list = reply.value();
|
|
||||||
int position = position_list.at(4).toInt();
|
|
||||||
switch(position){
|
|
||||||
case PANEL_TOP:
|
|
||||||
//任务栏位于上方
|
|
||||||
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
|
|
||||||
position_list.at(1).toInt() + MARGIN,
|
|
||||||
this->width(), this->height());
|
|
||||||
break;
|
|
||||||
//任务栏位于左边
|
|
||||||
case PANEL_LEFT:
|
|
||||||
rect = QRect(position_list.at(0).toInt() + MARGIN,
|
|
||||||
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
|
|
||||||
this->width(), this->height());
|
|
||||||
break;
|
|
||||||
//任务栏位于右边
|
|
||||||
case PANEL_RIGHT:
|
|
||||||
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
|
|
||||||
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
|
|
||||||
this->width(), this->height());
|
|
||||||
break;
|
|
||||||
//任务栏位于下方
|
|
||||||
default:
|
|
||||||
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
|
|
||||||
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
|
|
||||||
this->width(), this->height());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
kdk::WindowManager::setGeometry(this->windowHandle(), rect);
|
|
||||||
qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::initWindowTheme 初始化窗口主题并创建信号槽
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::initWindowTheme()
|
|
||||||
{
|
|
||||||
const QByteArray style_id(THEME_SCHAME);
|
|
||||||
if (QGSettings::isSchemaInstalled(style_id)) {
|
|
||||||
m_styleGsettings = new QGSettings(style_id);
|
|
||||||
connect(m_styleGsettings, &QGSettings::changed, this, &vpnMainWindow::onThemeChanged);
|
|
||||||
} else {
|
|
||||||
qWarning() << "Gsettings interface \"org.ukui.style\" is not exist!" << Q_FUNC_INFO << __LINE__;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///**
|
|
||||||
// * @brief vpnMainWindow::showControlCenter 打开控制面板网络界面
|
|
||||||
// */
|
|
||||||
//void vpnMainWindow::showControlCenter()
|
|
||||||
//{
|
|
||||||
// QProcess process;
|
|
||||||
// if (!m_vpnPage->lanIsConnected() && m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activated)){
|
|
||||||
// process.startDetached("ukui-control-center -m wlanconnect");
|
|
||||||
// } else {
|
|
||||||
// process.startDetached("ukui-control-center -m netconnect");
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
void vpnMainWindow::showByWaylandHelper()
|
|
||||||
{
|
|
||||||
//去除窗管标题栏,传入参数为QWidget*
|
|
||||||
kdk::UkuiStyleHelper::self()->removeHeader(this);
|
|
||||||
this->show();
|
|
||||||
getTabletMode();
|
|
||||||
resetWindowPosition();
|
|
||||||
//设置窗体位置,传入参数为QWindow*,QRect
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::getTabletMode()
|
|
||||||
{
|
|
||||||
// QDBusInterface interface(QString("com.kylin.statusmanager.interface"),
|
|
||||||
// QString("/"),
|
|
||||||
// QString("com.kylin.statusmanager.interface"),
|
|
||||||
// QDBusConnection::sessionBus());
|
|
||||||
// if(!interface.isValid()) {
|
|
||||||
// m_isShowInCenter = true;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// QDBusReply<bool> reply = interface.call("get_current_tabletmode");
|
|
||||||
// if (!reply.isValid()) {
|
|
||||||
// m_isShowInCenter = true;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// m_isShowInCenter = reply.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::onTrayIconActivated 点击托盘图标的槽函数
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
|
||||||
{
|
|
||||||
switch(reason) {
|
|
||||||
// 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__;
|
|
||||||
hideMainwindow();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
qDebug() << "Received signal of tray icon activated, will show mainwindow." << Q_FUNC_INFO << __LINE__;
|
|
||||||
this->showMainwindow();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::onThemeChanged(const QString &key)
|
|
||||||
{
|
|
||||||
if (key == COLOR_THEME) {
|
|
||||||
qDebug() << "Received signal of theme changed, will reset theme." << Q_FUNC_INFO << __LINE__;
|
|
||||||
paintWithTrans();
|
|
||||||
Q_EMIT qApp->paletteChanged(qApp->palette());
|
|
||||||
} else {
|
|
||||||
qDebug() << "Received signal of theme changed, key=" << key << " will do nothing." << Q_FUNC_INFO << __LINE__;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::onTabletModeChanged(bool mode)
|
|
||||||
{
|
|
||||||
qDebug() << "TabletMode change" << mode;
|
|
||||||
Q_UNUSED(mode)
|
|
||||||
//模式切换时,隐藏主界面
|
|
||||||
hideMainwindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::onShowMainWindow()
|
|
||||||
{
|
|
||||||
if(QApplication::activeWindow() != this) {
|
|
||||||
this->showMainwindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::keyPressEvent 按esc键关闭主界面
|
|
||||||
* @param event
|
|
||||||
*/
|
|
||||||
void vpnMainWindow::keyPressEvent(QKeyEvent *event)
|
|
||||||
{
|
|
||||||
if (event->key() == Qt::Key_Escape) {
|
|
||||||
hideMainwindow();
|
|
||||||
}
|
|
||||||
return QWidget::keyPressEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vpnMainWindow::eventFilter 事件过滤器
|
|
||||||
* @param watched
|
|
||||||
* @param event
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
bool vpnMainWindow::eventFilter(QObject *watched, QEvent *event)
|
|
||||||
{
|
|
||||||
if (event->type() == QEvent::ActivationChange) {
|
|
||||||
if(QApplication::activeWindow() != this) {
|
|
||||||
hideMainwindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QMainWindow::eventFilter(watched,event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vpnMainWindow::getVirtualList(QVector<QStringList> &vector)
|
|
||||||
{
|
|
||||||
vector.clear();
|
|
||||||
if (nullptr != m_vpnPage) {
|
|
||||||
m_vpnPage->getVirtualList(vector);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Vpn连接删除
|
|
||||||
void vpnMainWindow::deleteVpn(const QString &connUuid)
|
|
||||||
{
|
|
||||||
m_vpnPage->deleteVpn(connUuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Vpn连接断开
|
|
||||||
void vpnMainWindow::activateVpn(const QString& connUuid)
|
|
||||||
{
|
|
||||||
m_vpnPage->activateVpn(connUuid);
|
|
||||||
}
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,127 +0,0 @@
|
||||||
/* -*- 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 VPNMAINWINDOW_H
|
|
||||||
#define VPNMAINWINDOW_H
|
|
||||||
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include <QTableWidget>
|
|
||||||
#include <QGSettings/QGSettings>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QSystemTrayIcon>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QAction>
|
|
||||||
#include <QDBusInterface>
|
|
||||||
#include <QMap>
|
|
||||||
#include <QScreen>
|
|
||||||
#include "vpnpage.h"
|
|
||||||
#include "mainwindow.h"
|
|
||||||
|
|
||||||
class VpnPage;
|
|
||||||
|
|
||||||
class vpnMainWindow : public QMainWindow
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit vpnMainWindow(QWidget *parent = nullptr);
|
|
||||||
void showMainwindow();
|
|
||||||
void hideMainwindow();
|
|
||||||
|
|
||||||
void getVirtualList(QVector<QStringList> &vector);
|
|
||||||
|
|
||||||
|
|
||||||
//Vpn连接删除
|
|
||||||
void deleteVpn(const QString &connUuid);
|
|
||||||
// //有线连接断开
|
|
||||||
void activateVpn(const QString& connUuid);
|
|
||||||
void deactivateVpn(const QString& connUuid);
|
|
||||||
|
|
||||||
void initVpnIconVisible();
|
|
||||||
|
|
||||||
//唤起新建有线连接界面
|
|
||||||
// void showCreateWiredConnectWidget(const QString devName);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void vpnAdd(QStringList info);
|
|
||||||
void vpnRemove(QString dbusPath);
|
|
||||||
void vpnUpdate(QStringList info);
|
|
||||||
void vpnActiveConnectionStateChanged(QString uuid, int status);
|
|
||||||
void activateFailed(QString errorMessage);
|
|
||||||
void deactivateFailed(QString errorMessage);
|
|
||||||
void mainWindowVisibleChanged(const bool &visible);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void keyPressEvent(QKeyEvent *event);
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
|
||||||
void paintEvent(QPaintEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void firstlyStart(); //一级启动
|
|
||||||
void secondaryStart(); //二级启动
|
|
||||||
bool m_loadFinished = false; //是否二级启动已执行完
|
|
||||||
QTimer * m_secondaryStartTimer = nullptr; //执行二级启动的倒计时
|
|
||||||
void initPlatform();
|
|
||||||
void initWindowProperties();
|
|
||||||
void initTransparency();
|
|
||||||
void paintWithTrans();
|
|
||||||
void initUI();
|
|
||||||
void initDbusConnnect();
|
|
||||||
void initTrayIcon();
|
|
||||||
void initWindowTheme();
|
|
||||||
void showByWaylandHelper();
|
|
||||||
void getTabletMode();
|
|
||||||
|
|
||||||
double m_transparency=1.0; //透明度
|
|
||||||
QGSettings * m_transGsettings; //透明度配置文件
|
|
||||||
QGSettings * m_vpnGsettings; //VPN配置文件
|
|
||||||
|
|
||||||
// //主窗口的主要构成控件
|
|
||||||
QWidget * m_vpnWidget = nullptr;
|
|
||||||
VpnPage * m_vpnPage = nullptr;
|
|
||||||
QVBoxLayout * m_vpnLayout = nullptr;
|
|
||||||
|
|
||||||
//监听主题的Gsettings
|
|
||||||
QGSettings * m_styleGsettings = nullptr;
|
|
||||||
|
|
||||||
// //获取和重置窗口位置
|
|
||||||
void resetWindowPosition();
|
|
||||||
QDBusInterface * m_positionInterface = nullptr;
|
|
||||||
|
|
||||||
// //托盘图标,托盘图标右键菜单
|
|
||||||
QSystemTrayIcon * m_vpnTrayIcon = nullptr;
|
|
||||||
QMenu * m_vpnTrayIconMenu = nullptr;
|
|
||||||
|
|
||||||
bool m_isShowInCenter = false;
|
|
||||||
|
|
||||||
IconActiveType m_iconStatus = IconActiveType::NOT_CONNECTED;
|
|
||||||
|
|
||||||
QMap<QString, NetDetail*> m_createPagePtrMap;
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void onShowMainWindow();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onTransChanged();
|
|
||||||
void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
|
||||||
void onThemeChanged(const QString &key);
|
|
||||||
void onTabletModeChanged(bool mode);
|
|
||||||
void onVpnIconVisibleChanged();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
|
|
@ -169,7 +169,7 @@ int main(int argc, char *argv[])
|
||||||
// window_hints.decorations = MWM_DECOR_BORDER;
|
// window_hints.decorations = MWM_DECOR_BORDER;
|
||||||
// XAtomHelper::getInstance()->setWindowMotifHint(w.winId(), window_hints);
|
// XAtomHelper::getInstance()->setWindowMotifHint(w.winId(), window_hints);
|
||||||
|
|
||||||
// w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint /*| Qt::X11BypassWindowManagerHint*/);
|
w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint /*| Qt::X11BypassWindowManagerHint*/);
|
||||||
|
|
||||||
|
|
||||||
DbusAdaptor adaptor(&w);
|
DbusAdaptor adaptor(&w);
|
||||||
|
|
Loading…
Reference in New Issue