改为事件过滤器调Dbus方法setSwitchEnable
This commit is contained in:
parent
bda1492373
commit
c60276ef91
|
@ -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 (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();
|
||||
|
|
|
@ -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 (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();
|
||||
|
|
Loading…
Reference in New Issue