解决VPN崩溃的问题,删除多余代码,实现dbus接口
This commit is contained in:
parent
dfd834fafb
commit
122b1d934b
|
@ -212,14 +212,6 @@ wifi_get_secrets (SecretsRequest *req, GError **error)
|
||||||
|
|
||||||
g_return_val_if_fail (!info->dialog, FALSE);
|
g_return_val_if_fail (!info->dialog, FALSE);
|
||||||
|
|
||||||
#if GTK_CHECK_VERSION(3,90,0)
|
|
||||||
gtk_init ();
|
|
||||||
#else
|
|
||||||
int argc = 0;
|
|
||||||
char ***argv = NULL;
|
|
||||||
gtk_init (&argc, &argv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NMClient *nm_client = nm_client_new (NULL, NULL);
|
NMClient *nm_client = nm_client_new (NULL, NULL);
|
||||||
if (!nm_client) {
|
if (!nm_client) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
|
@ -409,6 +401,14 @@ void agent_init()
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
kylinAgent = applet_agent_new (&error);
|
kylinAgent = applet_agent_new (&error);
|
||||||
|
|
||||||
|
#if GTK_CHECK_VERSION(3,90,0)
|
||||||
|
gtk_init ();
|
||||||
|
#else
|
||||||
|
int argc = 0;
|
||||||
|
char ***argv = NULL;
|
||||||
|
gtk_init (&argc, &argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
g_signal_connect (kylinAgent, APPLET_AGENT_GET_SECRETS,
|
g_signal_connect (kylinAgent, APPLET_AGENT_GET_SECRETS,
|
||||||
G_CALLBACK (applet_agent_get_secrets_cb), NULL);
|
G_CALLBACK (applet_agent_get_secrets_cb), NULL);
|
||||||
g_signal_connect (kylinAgent, APPLET_AGENT_CANCEL_SECRETS,
|
g_signal_connect (kylinAgent, APPLET_AGENT_CANCEL_SECRETS,
|
||||||
|
|
|
@ -42,11 +42,36 @@ static bool subLanListSort(const KyConnectItem* info1, const KyConnectItem* info
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool subVpnListSort(const KyConnectItem* info1, const KyConnectItem* info2)
|
||||||
|
{
|
||||||
|
if (info1->m_connectState != info2->m_connectState) {
|
||||||
|
if (info1->m_connectState == 2) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info2->m_connectState == 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QString name1 = info1->m_connectName;
|
||||||
|
QString name2 = info2->m_connectName;
|
||||||
|
bool result = true;
|
||||||
|
if (QString::compare(name1, name2, Qt::CaseInsensitive) > 0) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static void lanListSort(QList<KyConnectItem *> &list)
|
static void lanListSort(QList<KyConnectItem *> &list)
|
||||||
{
|
{
|
||||||
qSort(list.begin(), list.end(), subLanListSort);
|
qSort(list.begin(), list.end(), subLanListSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void vpnListSort(QList<KyConnectItem *> &list)
|
||||||
|
{
|
||||||
|
qSort(list.begin(), list.end(), subVpnListSort);
|
||||||
|
}
|
||||||
|
|
||||||
KyConnectResourse::KyConnectResourse(QObject *parent) : QObject(parent)
|
KyConnectResourse::KyConnectResourse(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||||
|
@ -249,6 +274,10 @@ void KyConnectResourse::getVpnAndVirtualConnections(QList<KyConnectItem *> &conn
|
||||||
|
|
||||||
connectPtr = nullptr;
|
connectPtr = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (connectItemList.size() > 1) {
|
||||||
|
vpnListSort(connectItemList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KyConnectResourse::getConnectionList(QString deviceName,
|
void KyConnectResourse::getConnectionList(QString deviceName,
|
||||||
|
|
|
@ -52,6 +52,8 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa
|
||||||
qRegisterMetaType<NetworkManager::Device::Type>("NetworkManager::Device::Type");
|
qRegisterMetaType<NetworkManager::Device::Type>("NetworkManager::Device::Type");
|
||||||
qRegisterMetaType<NetworkManager::Device::State>("NetworkManager::Device::State");
|
qRegisterMetaType<NetworkManager::Device::State>("NetworkManager::Device::State");
|
||||||
qRegisterMetaType<NetworkManager::Device::StateChangeReason>("NetworkManager::Device::StateChangeReason");
|
qRegisterMetaType<NetworkManager::Device::StateChangeReason>("NetworkManager::Device::StateChangeReason");
|
||||||
|
qRegisterMetaType<NetworkManager::VpnConnection::State>("NetworkManager::VpnConnection::State");
|
||||||
|
qRegisterMetaType<NetworkManager::VpnConnection::StateChangeReason>("NetworkManager::VpnConnection::StateChangeReason");
|
||||||
|
|
||||||
QDBusConnection::systemBus().connect(QString("org.freedesktop.DBus"),
|
QDBusConnection::systemBus().connect(QString("org.freedesktop.DBus"),
|
||||||
QString("/org/freedesktop/DBus"),
|
QString("/org/freedesktop/DBus"),
|
||||||
|
|
|
@ -28,7 +28,6 @@ VpnDbusAdaptor::VpnDbusAdaptor(vpnMainWindow *parent)
|
||||||
qDBusRegisterMetaType<QMap<QString, bool> >();
|
qDBusRegisterMetaType<QMap<QString, bool> >();
|
||||||
qDBusRegisterMetaType<QMap<QString, int> >();
|
qDBusRegisterMetaType<QMap<QString, int> >();
|
||||||
qDBusRegisterMetaType<QVector<QStringList> >();
|
qDBusRegisterMetaType<QVector<QStringList> >();
|
||||||
qDBusRegisterMetaType<QMap<QString, QVector<QStringList> >>();
|
|
||||||
//setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发
|
//setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发
|
||||||
setAutoRelaySignals(true);
|
setAutoRelaySignals(true);
|
||||||
}
|
}
|
||||||
|
@ -39,11 +38,11 @@ VpnDbusAdaptor::~VpnDbusAdaptor()
|
||||||
}
|
}
|
||||||
|
|
||||||
//虚拟连接列表
|
//虚拟连接列表
|
||||||
QMap<QString, QVector<QStringList>> VpnDbusAdaptor::getVirtualList()
|
QVector<QStringList> VpnDbusAdaptor::getVirtualList()
|
||||||
{
|
{
|
||||||
QMap<QString, QVector<QStringList>> map;
|
QVector<QStringList> vector;
|
||||||
parent()->getVirtualList(map);
|
parent()->getVirtualList(vector);
|
||||||
return map;
|
return vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除
|
//删除
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
public: // PROPERTIES
|
public: // PROPERTIES
|
||||||
public Q_SLOTS: // METHODS
|
public Q_SLOTS: // METHODS
|
||||||
//虚拟连接列表
|
//虚拟连接列表
|
||||||
QMap<QString, QVector<QStringList> > getVirtualList();
|
QVector<QStringList> getVirtualList();
|
||||||
//刪除 根据网络名称 参数1 0:lan 1:wlan 参数2 为ssid/uuid
|
//刪除 根据网络名称 参数1 0:lan 1:wlan 参数2 为ssid/uuid
|
||||||
Q_NOREPLY void deleteVpn(QString uuid);
|
Q_NOREPLY void deleteVpn(QString uuid);
|
||||||
//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
|
//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
|
||||||
|
|
|
@ -49,7 +49,7 @@ VpnPage::VpnPage(QWidget *parent) : SinglePage(parent)
|
||||||
initUI();
|
initUI();
|
||||||
initVpnArea();
|
initVpnArea();
|
||||||
|
|
||||||
connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &VpnPage::onConnectionStateChange);
|
connect(m_activeResourse, &KyActiveConnectResourse::vpnConnectChangeReason, this, &VpnPage::onConnectionStateChange);
|
||||||
connect(m_activeResourse, &KyActiveConnectResourse::activeConnectRemove, this, [=] (QString activeConnectUuid) {
|
connect(m_activeResourse, &KyActiveConnectResourse::activeConnectRemove, this, [=] (QString activeConnectUuid) {
|
||||||
sendVpnStateChangeSignal(activeConnectUuid,Deactivated);
|
sendVpnStateChangeSignal(activeConnectUuid,Deactivated);
|
||||||
} );
|
} );
|
||||||
|
@ -356,12 +356,12 @@ void VpnPage::updateConnectionState(QMap<QString, QListWidgetItem *> &connectMap
|
||||||
}
|
}
|
||||||
|
|
||||||
void VpnPage::onConnectionStateChange(QString uuid,
|
void VpnPage::onConnectionStateChange(QString uuid,
|
||||||
NetworkManager::ActiveConnection::State state,
|
NetworkManager::VpnConnection::State state,
|
||||||
NetworkManager::ActiveConnection::Reason reason)
|
NetworkManager::VpnConnection::StateChangeReason reason)
|
||||||
{
|
{
|
||||||
//VpnPage函数内持续监听连接状态的变化并记录供其他函数调用获取状态
|
//VpnPage函数内持续监听连接状态的变化并记录供其他函数调用获取状态
|
||||||
if (!m_connectResourse->isVirtualConncection(uuid)) {
|
if (!m_connectResourse->isVirtualConncection(uuid)) {
|
||||||
qDebug() << "[VpnPage] connection state change signal but not wired";
|
qDebug() << "[VpnPage] connection state change signal but not vpn";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,16 +417,17 @@ void VpnPage::onConnectionStateChange(QString uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VpnPage::getVirtualList(QMap<QString, QVector<QStringList> > &map)
|
void VpnPage::getVirtualList(QVector<QStringList> &vector)
|
||||||
{
|
{
|
||||||
QList<KyConnectItem *> netConnectList;
|
QList<KyConnectItem *> netConnectList;
|
||||||
QVector<QStringList> vector;
|
vector.clear();
|
||||||
m_connectResourse->getVpnAndVirtualConnections(netConnectList); //未激活列表的显示
|
m_connectResourse->getVpnAndVirtualConnections(netConnectList); //未激活列表的显示
|
||||||
if (!netConnectList.isEmpty()) {
|
if (!netConnectList.isEmpty()) {
|
||||||
for (int i = 0; i < netConnectList.size(); i++) {
|
for (int i = 0; i < netConnectList.size(); i++) {
|
||||||
vector.clear();
|
vector.append(QStringList() << netConnectList.at(i)->m_connectName
|
||||||
vector.append(QStringList()<<netConnectList.at(i)->m_connectName<<netConnectList.at(i)->m_connectUuid << netConnectList.at(i)->m_connectPath);
|
<< netConnectList.at(i)->m_connectUuid
|
||||||
map.insert(netConnectList.at(i)->m_connectUuid, vector);
|
<< netConnectList.at(i)->m_connectPath
|
||||||
|
<< QString::number(netConnectList.at(i)->m_connectState));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -444,7 +445,10 @@ void VpnPage::sendVpnUpdateSignal(KyConnectItem *p_connectItem)
|
||||||
void VpnPage::sendVpnAddSignal(KyConnectItem *p_connectItem)
|
void VpnPage::sendVpnAddSignal(KyConnectItem *p_connectItem)
|
||||||
{
|
{
|
||||||
QStringList info;
|
QStringList info;
|
||||||
info << p_connectItem->m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath;
|
info << p_connectItem->m_connectName
|
||||||
|
<< p_connectItem->m_connectUuid
|
||||||
|
<< p_connectItem->m_connectPath
|
||||||
|
<< QString::number(p_connectItem->m_connectState);
|
||||||
qDebug() << "[VpnPage] emit vpnAdd because addConnection ";
|
qDebug() << "[VpnPage] emit vpnAdd because addConnection ";
|
||||||
Q_EMIT vpnAdd(info);
|
Q_EMIT vpnAdd(info);
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
~VpnPage();
|
~VpnPage();
|
||||||
|
|
||||||
//for dbus
|
//for dbus
|
||||||
void getVirtualList(QMap<QString, QVector<QStringList> > &map);
|
void getVirtualList(QVector<QStringList> &vector);
|
||||||
void deleteVpn(const QString &connUuid);
|
void deleteVpn(const QString &connUuid);
|
||||||
void activateVpn(const QString& connUuid);
|
void activateVpn(const QString& connUuid);
|
||||||
void deactivateVpn(const QString& connUuid);
|
void deactivateVpn(const QString& connUuid);
|
||||||
|
@ -94,8 +94,9 @@ Q_SIGNALS:
|
||||||
void vpnConnectChanged(int state);
|
void vpnConnectChanged(int state);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onConnectionStateChange(QString uuid, NetworkManager::ActiveConnection::State state,
|
void onConnectionStateChange(QString uuid,
|
||||||
NetworkManager::ActiveConnection::Reason reason);
|
NetworkManager::VpnConnection::State state,
|
||||||
|
NetworkManager::VpnConnection::StateChangeReason reason);
|
||||||
|
|
||||||
void onAddConnection(QString uuid);
|
void onAddConnection(QString uuid);
|
||||||
void onRemoveConnection(QString path);
|
void onRemoveConnection(QString path);
|
||||||
|
|
|
@ -928,6 +928,11 @@ void WlanPage::onConnectionStateChanged(QString uuid,
|
||||||
NetworkManager::ActiveConnection::State state,
|
NetworkManager::ActiveConnection::State state,
|
||||||
NetworkManager::ActiveConnection::Reason reason)
|
NetworkManager::ActiveConnection::Reason reason)
|
||||||
{
|
{
|
||||||
|
if (!m_connectResource->isWirelessConnection(uuid)) {
|
||||||
|
qDebug()<< LOG_FLAG << "it is not wireless connection" << uuid;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString devName, ssid;
|
QString devName, ssid;
|
||||||
m_wirelessNetResource->getSsidByUuid(uuid, ssid);
|
m_wirelessNetResource->getSsidByUuid(uuid, ssid);
|
||||||
m_wirelessNetResource->getDeviceByUuid(uuid, devName);
|
m_wirelessNetResource->getDeviceByUuid(uuid, devName);
|
||||||
|
@ -942,11 +947,6 @@ void WlanPage::onConnectionStateChanged(QString uuid,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_connectResource->isWirelessConnection(uuid)) {
|
|
||||||
qDebug()<< LOG_FLAG << "it is not wireless connection" << uuid;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT this->wlanConnectChanged(state);
|
Q_EMIT this->wlanConnectChanged(state);
|
||||||
|
|
||||||
bool isApConnection = m_connectResource->isApConnection(uuid);
|
bool isApConnection = m_connectResource->isApConnection(uuid);
|
||||||
|
|
|
@ -466,11 +466,11 @@ bool vpnMainWindow::eventFilter(QObject *watched, QEvent *event)
|
||||||
return QMainWindow::eventFilter(watched,event);
|
return QMainWindow::eventFilter(watched,event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vpnMainWindow::getVirtualList(QMap<QString, QVector<QStringList>> &map)
|
void vpnMainWindow::getVirtualList(QVector<QStringList> &vector)
|
||||||
{
|
{
|
||||||
map.clear();
|
vector.clear();
|
||||||
if (nullptr != m_vpnPage) {
|
if (nullptr != m_vpnPage) {
|
||||||
m_vpnPage->getVirtualList(map);
|
m_vpnPage->getVirtualList(vector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
void showMainwindow();
|
void showMainwindow();
|
||||||
void hideMainwindow();
|
void hideMainwindow();
|
||||||
|
|
||||||
void getVirtualList(QMap<QString, QVector<QStringList>> &map);
|
void getVirtualList(QVector<QStringList> &vector);
|
||||||
|
|
||||||
|
|
||||||
//Vpn连接删除
|
//Vpn连接删除
|
||||||
|
|
Loading…
Reference in New Issue