diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index a33d7cce..67f811e7 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -141,28 +141,28 @@ void LanPage::initLanDeviceState() void LanPage::initNetSwitch() { - bool wiredSwitch = true; + bool wiredGsetting = true; bool wiredEnable = m_wiredConnectOperation->getWiredEnabled(); if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); if (m_switchGsettings->keys().contains(WIRED_SWITCH)) { - wiredSwitch = m_switchGsettings->get(WIRED_SWITCH).toBool(); + wiredGsetting = m_switchGsettings->get(WIRED_SWITCH).toBool(); connect(m_switchGsettings, &QGSettings::changed, this, &LanPage::onSwithGsettingsChanged); + if (wiredEnable != wiredGsetting) { + wiredEnable = wiredGsetting; + m_wiredConnectOperation->setWiredEnabled(wiredGsetting); + } } } else { qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!"; } - if (nullptr != m_switchGsettings - && wiredSwitch != wiredEnable) { - m_switchGsettings->set(WIRED_SWITCH, wiredEnable); - } - //从3.0升级上来 先读取老的配置文件来保证和升级前状态一致 - bool oldVersionState; + bool oldVersionState = true; if (getOldVersionWiredSwitchState(oldVersionState)) { if (wiredEnable != oldVersionState) { + wiredEnable = oldVersionState; m_wiredConnectOperation->setWiredEnabled(oldVersionState); } } diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index 3e7ef919..91447f8c 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -440,7 +440,7 @@ void getDeviceEnableState(int type, QMap &map) kdr = nullptr; } -bool getOldVersionWiredSwitchState(bool state) +bool getOldVersionWiredSwitchState(bool &state) { QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); QVariant value = m_settings->value("lan_switch_opened"); diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index de09b3ce..df0d6a34 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -85,7 +85,7 @@ bool checkDeviceExist(KyDeviceType deviceType, QString deviceName); QString getDefaultDeviceName(KyDeviceType deviceType); void setDefaultDevice(KyDeviceType deviceType, QString deviceName); void getDeviceEnableState(int type, QMap &map); -bool getOldVersionWiredSwitchState(bool state); +bool getOldVersionWiredSwitchState(bool &state); class TabPage : public QWidget {