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