改为事件过滤器调Dbus方法setSwitchEnable

This commit is contained in:
zhangyuanyuan1 2022-05-27 16:01:48 +08:00
parent bda1492373
commit c60276ef91
2 changed files with 32 additions and 28 deletions

View File

@ -162,11 +162,22 @@ bool NetConnect::eventFilter(QObject *w, QEvent *e) {
if (w->findChild<QWidget*>())
w->findChild<QWidget*>()->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();

View File

@ -220,11 +220,23 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
if (w->findChild<QWidget*>())
w->findChild<QWidget*>()->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();