From 49eccd8ac2f6b813e240b9315696a9a74f4e729b Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Wed, 26 May 2021 13:34:31 +0800 Subject: [PATCH] feat(lan): Emit dbus signal when lan connected/disconnected/added/removed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 当有线网增删连断时,发出dbus信号通知控制面板更新 Log: 当有线网增删连断时,发出dbus信号通知控制面板更新 --- src/dbusadaptor.h | 6 ++++++ src/kylin-dbus-interface.cpp | 16 +++++++++++----- src/kylin-dbus-interface.h | 1 + src/mainwindow.cpp | 3 +++ src/mainwindow.h | 3 +++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/dbusadaptor.h b/src/dbusadaptor.h index d56ed49c..8f566d86 100644 --- a/src/dbusadaptor.h +++ b/src/dbusadaptor.h @@ -44,6 +44,9 @@ class DbusAdaptor: public QDBusAbstractAdaptor " \n" " \n" " \n" +" \n" +" \n" +" \n" " \n" "") public: @@ -61,6 +64,9 @@ public Q_SLOTS: // METHODS Q_SIGNALS: // SIGNALS void getWifiListFinished(); void configurationChanged(); + void wiredConnectionAdded(); + void wiredConnectionRemoved(); + void actWiredConnectionChanged(); }; #endif diff --git a/src/kylin-dbus-interface.cpp b/src/kylin-dbus-interface.cpp index ad1caa97..4068ed45 100644 --- a/src/kylin-dbus-interface.cpp +++ b/src/kylin-dbus-interface.cpp @@ -717,6 +717,7 @@ void KylinDBus::getConnectNetIp(QString netUuid) //监听有线网络ip变化 void KylinDBus::getLanIpChanged() { + m_lanPathList.clear(); QDBusInterface m_interface("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings", "org.freedesktop.NetworkManager.Settings", @@ -742,6 +743,7 @@ void KylinDBus::getLanIpChanged() objNet.path(), QString("org.freedesktop.NetworkManager.Settings.Connection"), QString("Updated"), this, SLOT(onLanIpPropertiesChanged() ) ); + m_lanPathList.append(objNet.path()); } else if (key == "802-11-wireless") { QDBusConnection::systemBus().connect(QString("org.freedesktop.NetworkManager"), objNet.path(), @@ -1036,6 +1038,8 @@ void KylinDBus::onNewConnection(QDBusObjectPath objPath) if (key == "802-3-ethernet") { emit this->updateWiredList(0); //send this signal to update wired network list emit this->newConnAdded(0); + m_lanPathList.append(objPath.path()); + emit mw->wiredConnectionAdded(); //syslog(LOG_DEBUG, "A new wired network was created."); qDebug()<<"A new wired network was created."; break; @@ -1101,10 +1105,13 @@ void KylinDBus::onNewConnection(QDBusObjectPath objPath) void KylinDBus::onConnectionRemoved(QDBusObjectPath objPath) { //syslog(LOG_DEBUG, "An old network was removed from configure directory."); - qDebug()<<"An old network was removed from configure directory."; - - if (mw->is_btnLanList_clicked == 1) { - emit this->updateWiredList(0); //send this signal to update wired network list + if (m_lanPathList.contains(objPath.path())) { + m_lanPathList.removeOne(objPath.path()); + qDebug()<<"An old network was removed from configure directory."; + if (mw->is_btnLanList_clicked == 1) { + emit this->updateWiredList(0); //send this signal to update wired network list + } + emit mw->wiredConnectionRemoved(); } onWiredSettingNumChanged(); @@ -1724,7 +1731,6 @@ void KylinDBus::onLanPropertyChanged(QVariantMap qvm) qDebug()<<"kylin-nm receive a signal 'Device.Wired PropertiesChanged' about interface."; isRunningFunction = true; //function onLanPropertyChanged is running time->start(3000); - QString str = qvm.value("Carrier").toString(); if (str == "false" || str == "true") { getPhysicalCarrierState(1); diff --git a/src/kylin-dbus-interface.h b/src/kylin-dbus-interface.h index 6a28564c..51c28a4b 100644 --- a/src/kylin-dbus-interface.h +++ b/src/kylin-dbus-interface.h @@ -147,6 +147,7 @@ private: QGSettings *m_tastbar_gsettings = nullptr; QGSettings *m_gsettings = nullptr; QGSettings *m_transparency_gsettings = nullptr; + QStringList m_lanPathList;//有线网dbuspath列表 signals: void updateWiredList(int n); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3cd61e9b..3dee53e8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3387,6 +3387,7 @@ void MainWindow::handleLanDisconn() qDebug()<<"Wired net is disconnected!"; QString txt(tr("Wired net is disconnected")); + emit this->actWiredConnectionChanged(); objKyDBus->showDesktopNotify(txt); currSelNetName = ""; oldActLanName = ""; @@ -3669,6 +3670,7 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp) void MainWindow::onExternalLanChange() { + emit this->actWiredConnectionChanged(); if (is_btnLanList_clicked) { onBtnNetListClicked(0); } else { @@ -3924,6 +3926,7 @@ void MainWindow::connLanDone(int connFlag) //this->ksnm->execGetLanList(); QString txt(tr("Conn Ethernet Success")); + emit this->actWiredConnectionChanged(); objKyDBus->showDesktopNotify(txt); } diff --git a/src/mainwindow.h b/src/mainwindow.h index a75e3e49..55245065 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -421,6 +421,9 @@ signals: void getWifiListFinished(); void startReconnectWifi(const QString& ssid); void stopReconnectWifi(const QString& ssid); + void wiredConnectionAdded(); + void wiredConnectionRemoved(); + void actWiredConnectionChanged(); }; #endif // MAINWINDOW_H