新增VPN相关改动

This commit is contained in:
chenxuechao 2022-11-18 11:31:50 +08:00
parent f07986d71d
commit 77c05dd5f9
4 changed files with 333 additions and 0 deletions

View File

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

View File

@ -0,0 +1,71 @@
/*
* This file was generated by qdbusxml2cpp version 0.8
* Command line was: qdbusxml2cpp com.kylin.weather.xml -a dbusadaptor -c DbusAdaptor -l MainWindow
*
* qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
* before re-generating it.
*/
#ifndef VPNDBUSADAPTOR_H
#define VPNDBUSADAPTOR_H
#include <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 "vpnobject.h"
class VpnDbusAdaptor: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "com.kylin.vpnTool")
public:
VpnDbusAdaptor(vpnObject *parent);
virtual ~VpnDbusAdaptor();
inline vpnObject *parent() const
{ return static_cast<vpnObject *>(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

122
src/frontend/vpnobject.cpp Normal file
View File

@ -0,0 +1,122 @@
#include "vpnobject.h"
#include <QApplication>
#include "ukuistylehelper/ukuistylehelper.h"
vpnObject::vpnObject(QObject *parent) : QObject(parent)
{
initUI();
initTrayIcon();
initDbusConnnect();
}
vpnObject::~vpnObject()
{
if (m_vpnGsettings != nullptr) {
delete m_vpnGsettings;
m_vpnGsettings = nullptr;
}
}
void vpnObject::initUI()
{
m_vpnPage = new VpnPage(nullptr);
m_vpnPage->update();
}
void vpnObject::initTrayIcon()
{
m_vpnTrayIcon = new QSystemTrayIcon(this);
m_vpnTrayIcon->setToolTip(QString(tr("vpn tool")));
m_vpnTrayIcon->setIcon(QIcon::fromTheme("ukui-vpn-symbolic"));
m_vpnTrayIcon->setVisible(true);
initVpnIconVisible();
connect(m_vpnTrayIcon, &QSystemTrayIcon::activated, this, &vpnObject::onTrayIconActivated);
}
void vpnObject::initVpnIconVisible()
{
if (QGSettings::isSchemaInstalled(QByteArray(GSETTINGS_VPNICON_VISIBLE))) {
m_vpnGsettings = new QGSettings(QByteArray(GSETTINGS_VPNICON_VISIBLE));
if (m_vpnGsettings->keys().contains(QString(VISIBLE))) {
m_vpnTrayIcon->setVisible(m_vpnGsettings->get(VISIBLE).toBool());
connect(m_vpnGsettings, &QGSettings::changed, this, [=]() {
m_vpnTrayIcon->setVisible(m_vpnGsettings->get(VISIBLE).toBool());
});
}
}
}
/**
* @brief vpnObject::onTrayIconActivated
*/
void vpnObject::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch(reason) {
case QSystemTrayIcon::Trigger:
if(m_vpnPage->isActiveWindow()) {
m_vpnPage->hide();
} else {
onShowMainWindow();
}
break;
default:
break;
}
}
void vpnObject::getVirtualList(QVector<QStringList> &vector)
{
vector.clear();
if (nullptr != m_vpnPage) {
m_vpnPage->getVirtualList(vector);
}
}
//Vpn连接删除
void vpnObject::deleteVpn(const QString &connUuid)
{
m_vpnPage->deleteVpn(connUuid);
}
//Vpn连接断开
void vpnObject::activateVpn(const QString& connUuid)
{
m_vpnPage->activateVpn(connUuid);
}
void vpnObject::deactivateVpn(const QString& connUuid)
{
m_vpnPage->deactivateVpn(connUuid);
}
void vpnObject::onShowMainWindow()
{
kdk::UkuiStyleHelper::self()->removeHeader(m_vpnPage);
m_vpnPage->showUI();;
}
void vpnObject::initDbusConnnect()
{
connect(m_vpnPage, &VpnPage::activateFailed, this, &vpnObject::activateFailed);
connect(m_vpnPage, &VpnPage::deactivateFailed, this, &vpnObject::deactivateFailed);
connect(m_vpnPage, &VpnPage::vpnAdd, this, &vpnObject::vpnAdd);
connect(m_vpnPage, &VpnPage::vpnRemove, this, &vpnObject::vpnRemove);
connect(m_vpnPage, &VpnPage::vpnUpdate, this, &vpnObject::vpnUpdate);
connect(m_vpnPage, &VpnPage::vpnActiveConnectionStateChanged, this, &vpnObject::vpnActiveConnectionStateChanged);
//模式切换
QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interface"),
QString("/"),
QString("com.kylin.statusmanager.interface"),
QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool)));
}
void vpnObject::onTabletModeChanged(bool mode)
{
qDebug() << "TabletMode change" << mode;
Q_UNUSED(mode)
//模式切换时,隐藏主界面
m_vpnPage->hide();
}

68
src/frontend/vpnobject.h Normal file
View File

@ -0,0 +1,68 @@
#ifndef VPNOBJECT_H
#define VPNOBJECT_H
#include <QObject>
#include <QWidget>
#include <QScreen>
#include <QSystemTrayIcon>
#include <QMainWindow>
#include "vpnpage.h"
class VpnPage;
#define VISIBLE "visible"
#define GSETTINGS_VPNICON_VISIBLE "org.ukui.kylin-nm.vpnicon"
//const QByteArray GSETTINGS_VPNICON_VISIBLE = "org.ukui.kylin-nm.vpnicon";
class vpnObject : public QObject
{
Q_OBJECT
public:
explicit vpnObject(QObject *parent = nullptr);
~vpnObject();
void getVirtualList(QVector<QStringList> &vector);
//Vpn连接删除
void deleteVpn(const QString &connUuid);
//有线连接断开
void activateVpn(const QString& connUuid);
void deactivateVpn(const QString& connUuid);
private:
void initUI();
void initTrayIcon();
void initVpnIconVisible();
void initDbusConnnect();
private:
VpnPage *m_vpnPage = nullptr;
QSystemTrayIcon * m_vpnTrayIcon = nullptr;
QGSettings * m_vpnGsettings; //VPN配置文件
double tran =1;
QGSettings *StyleSettings = nullptr;
QWidget * vpnWidget = nullptr;
QDBusInterface * m_positionInterface = nullptr;
bool m_isShowInCenter = false;
public Q_SLOTS:
void onShowMainWindow();
private Q_SLOTS:
void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
void onTabletModeChanged(bool mode);
Q_SIGNALS:
void vpnAdd(QStringList info);
void vpnRemove(QString dbusPath);
void vpnUpdate(QStringList info);
void vpnActiveConnectionStateChanged(QString uuid, int status);
void activateFailed(QString errorMessage);
void deactivateFailed(QString errorMessage);
void mainWindowVisibleChanged(const bool &visible);
};
#endif // VPNOBJECT_H