diff --git a/plugins/netconnect/netconnect.cpp b/plugins/netconnect/netconnect.cpp index a4eadc8b..70e41830 100644 --- a/plugins/netconnect/netconnect.cpp +++ b/plugins/netconnect/netconnect.cpp @@ -162,11 +162,22 @@ bool NetConnect::eventFilter(QObject *w, QEvent *e) { if (w->findChild()) w->findChild()->setStyleSheet("QWidget{background: palette(base);border-radius:4px;}"); } - if (w == wiredSwitch && e->type() == QMouseEvent::MouseButtonPress) { - if (!wiredSwitch->isCheckable()) { - showDesktopNotify(tr("No ethernet device avaliable")); + if (w == wiredSwitch) { + if (e->type() == QMouseEvent::MouseButtonRelease) { + if (!wiredSwitch->isCheckable()) { + showDesktopNotify(tr("No ethernet device avaliable")); + } else { + if (deviceStatusMap.count() == 0) { + wiredSwitch->setCheckable(false); + wiredSwitch->setChecked(false); + } else { + m_interface->call(QStringLiteral("setWiredSwitchEnable"), !wiredSwitch->isChecked()); + } + return true; + } } } + return QObject::eventFilter(w,e); } @@ -182,18 +193,9 @@ void NetConnect::initComponent() { if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); - connect(wiredSwitch, &KSwitchButton::stateChanged, this, [=] (bool checked) { - if (!m_interface->isValid()) { - return; - } - if (!wiredSwitch->isCheckable()) { - return; - } - qDebug() << "[NetConnect]call setWiredSwitchEnable" << checked << __LINE__; - m_interface->call(QStringLiteral("setWiredSwitchEnable"),checked); - qDebug() << "[NetConnect]call setWiredSwitchEnable Respond" << __LINE__; - }); + setSwitchStatus(); + connect(m_switchGsettings, &QGSettings::changed, this, [=] (const QString &key) { if (key == WIRED_SWITCH) { setSwitchStatus(); diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp index 4eacc1b4..d69b599b 100644 --- a/plugins/wlanconnect/wlanconnect.cpp +++ b/plugins/wlanconnect/wlanconnect.cpp @@ -220,11 +220,23 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) { if (w->findChild()) w->findChild()->setStyleSheet("QWidget{background: palette(base);border-radius:4px;}"); } - if (w == m_wifiSwitch && e->type() == QMouseEvent::MouseButtonPress) { - if (!m_wifiSwitch->isCheckable()) { - showDesktopNotify(tr("No wireless network card detected")); + + if (w == m_wifiSwitch) { + if (e->type() == QMouseEvent::MouseButtonRelease) { + if (!m_wifiSwitch->isCheckable()) { + showDesktopNotify(tr("No wireless network card detected")); + } else { + if (deviceList.isEmpty()) { + m_wifiSwitch->setCheckable(false); + m_wifiSwitch->setChecked(false); + } else { + m_interface->call(QStringLiteral("setWirelessSwitchEnable"), !m_wifiSwitch->isChecked()); + } + return true; + } } } + return QObject::eventFilter(w,e); } @@ -241,18 +253,8 @@ void WlanConnect::initComponent() { if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); - connect(m_wifiSwitch, &KSwitchButton::stateChanged, this, [=] (bool checked) { - if (!m_interface->isValid()) { - return; - } - if (!m_wifiSwitch->isCheckable()) { - return; - } - qDebug() << "[WlanConnect]call setWirelessSwitchEnable " << checked << __LINE__; - m_interface->call(QStringLiteral("setWirelessSwitchEnable"),checked); - qDebug() << "[WlanConnect]call setWirelessSwitchEnable respond" << __LINE__; - }); setSwitchStatus(); + connect(m_switchGsettings, &QGSettings::changed, this, [=] (const QString &key) { if (key == WIRELESS_SWITCH) { setSwitchStatus();