无线开关状态

This commit is contained in:
zhangyuanyuan1 2022-06-28 13:58:04 +08:00
parent b02c53439f
commit 09d56a4d46
5 changed files with 49 additions and 17 deletions

View File

@ -207,8 +207,8 @@ void NetConnect::initComponent() {
getDeviceStatusMap(deviceStatusMap);
if (deviceStatusMap.isEmpty()) {
qDebug() << "[Netconnect] no device exist when init, set switch disable";
wiredSwitch->setCheckable(false);
wiredSwitch->setChecked(false);
wiredSwitch->setCheckable(false);
}
initNet();
@ -593,8 +593,8 @@ void NetConnect::onDeviceStatusChanged()
}
deviceStatusMap = map;
if (deviceStatusMap.isEmpty()) {
wiredSwitch->setCheckable(false);
wiredSwitch->setChecked(false);
wiredSwitch->setCheckable(false);
} else {
wiredSwitch->setCheckable(true);
setSwitchStatus();

View File

@ -267,8 +267,10 @@ void WlanConnect::initComponent() {
getDeviceList(deviceList);
if (deviceList.isEmpty()) {
qDebug() << "[WlanConnect]no device exist when init, set switch disable";
m_wifiSwitch->setCheckable(false);
m_wifiSwitch->setChecked(false);
m_wifiSwitch->setCheckable(false);
qDebug() << "KSwitchButton-----WlanConnect::initComponent" <<m_wifiSwitch->isCheckable()
<< "checked"<<m_wifiSwitch->isChecked();
}
initNet();
@ -525,8 +527,10 @@ void WlanConnect::onDeviceStatusChanged()
}
deviceList = list;
if (deviceList.isEmpty()) {
m_wifiSwitch->setCheckable(false);
m_wifiSwitch->setChecked(false);
m_wifiSwitch->setCheckable(false);
qDebug() << "KSwitchButton-----WlanConnect::onDeviceStatusChanged" <<m_wifiSwitch->isCheckable()
<< "checked"<<m_wifiSwitch->isChecked();
} else {
m_wifiSwitch->setCheckable(true);
setSwitchStatus();

View File

@ -629,8 +629,8 @@ void LanPage::onDeviceRemove(QString deviceName)
m_devList.removeOne(deviceName);
if (m_devList.count() == 0) {
m_netSwitch->setCheckable(false);
m_netSwitch->setChecked(false);
m_netSwitch->setCheckable(false);
qDebug() << "[wiredSwitch]set not enable after device remove";
}
@ -1183,8 +1183,8 @@ bool LanPage::eventFilter(QObject *watched, QEvent *event)
if (m_devList.count() == 0) {
this->showDesktopNotify(tr("No ethernet device avaliable"), "networkwrong");
m_netSwitch->setCheckable(false);
m_netSwitch->setChecked(false);
m_netSwitch->setCheckable(false);
} else {
m_netSwitch->setCheckable(true);
if (m_netSwitch->isChecked()) {

View File

@ -54,6 +54,19 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::wifiEnabledChanged, this, &WlanPage::onWifiEnabledChanged);
connect(m_connectResource, &KyConnectResourse::connectivityChanged, this, &WlanPage::connectivityChanged);
// QTimer::singleShot(10000, this, [=](){
// qDebug() << "KSwitchButton-----WlanPage::onDeviceRemove-before" <<m_netSwitch->isCheckable()
// << "checked"<<m_netSwitch->isChecked();
// onDeviceRemove("wlp3s0");
// qDebug() << "KSwitchButton-----WlanPage::onDeviceRemove-after" <<m_netSwitch->isCheckable()
// << "checked"<<m_netSwitch->isChecked();
// });
}
bool WlanPage::eventFilter(QObject *w, QEvent *e)
@ -69,8 +82,10 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e)
if (m_devList.isEmpty()) {
showDesktopNotify(tr("No wireless network card detected"), "networkwrong");
//检测不到无线网卡不再触发click信号
m_netSwitch->setCheckable(false);
m_netSwitch->setChecked(false);
m_netSwitch->setCheckable(false);
qDebug() << "KSwitchButton-----WlanPage::eventFilter" <<m_netSwitch->isCheckable()
<< "checked"<<m_netSwitch->isChecked();
} else {
m_wirelessConnectOpreation->setWirelessEnabled(!m_netSwitch->isChecked());
}
@ -123,13 +138,15 @@ void WlanPage::onWlanSwithGsettingsChanged(const QString &key)
m_wlanSwitchEnable = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
qDebug() << LOG_FLAG << "wlan switch state" << m_wlanSwitchEnable;
m_netSwitch->setChecked(m_wlanSwitchEnable);
if (m_wirelessConnectOpreation->getWirelessEnabled() != m_wlanSwitchEnable) {
m_wirelessConnectOpreation->setWirelessEnabled(m_wlanSwitchEnable);
qDebug() <<"wlan switch state!=";
}
m_netSwitch->setChecked(m_wlanSwitchEnable);
initDeviceCombox();
initWlanArea();
}
return;
}
void WlanPage::initWlanSwitchState()
@ -139,8 +156,10 @@ void WlanPage::initWlanSwitchState()
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
if (m_switchGsettings->keys().contains(WIRELESS_SWITCH)) {
if (m_devList.isEmpty()) {
m_netSwitch->setCheckable(false);
m_netSwitch->setChecked(false);
m_netSwitch->setCheckable(false);
qDebug() << "KSwitchButton-----WlanPage::initWlanSwitchState" <<m_netSwitch->isCheckable()
<< "checked"<<m_netSwitch->isChecked();
} else {
wirelessGsetting = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
if (m_wirelessConnectOpreation->getWirelessEnabled()
@ -716,8 +735,10 @@ void WlanPage::onDeviceRemove(QString deviceName)
deleteDeviceFromCombox(deviceName);
if (m_devList.isEmpty()) {
m_netSwitch->setCheckable(false);
m_netSwitch->setChecked(false);
m_netSwitch->setCheckable(false);
qDebug() << "KSwitchButton-----WlanPage::onDeviceRemove-after" <<m_netSwitch->isCheckable()
<< "checked"<<m_netSwitch->isChecked();
}
if (originalDeviceName == deviceName) {
@ -1019,6 +1040,7 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn)
{
//监听外部命令导致wifi状态变化更新界面
qDebug() << "[WlanPage] onWifiEnabledChanged wifi state" << isWifiOn;
isWifiOn = m_wirelessConnectOpreation->getWirelessEnabled();
//应该先检测是否有无线网卡可用,才改变开关状态
if (m_devList.isEmpty()) {
@ -1029,9 +1051,9 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn)
if (m_wlanSwitchEnable == isWifiOn) {
return;
} else {
if (!m_netSwitch->isChecked()) {
m_netSwitch->setChecked(true);
}
// if (!m_netSwitch->isChecked()) {
// m_netSwitch->setChecked(true);
// }
m_switchGsettings->set(WIRELESS_SWITCH, isWifiOn);
}
@ -1391,12 +1413,18 @@ void WlanPage::setWirelessSwitchEnable(bool enable)
qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__;
//检测不到无线网卡不再触发click信号
// m_netSwitch->setSwitchStatus(false);
m_netSwitch->setEnabled(false);
m_netSwitch->setChecked(false);
m_netSwitch->setCheckable(false);
qDebug() << "KSwitchButton-----WlanPage::setWirelessSwitchEnable checkable" <<m_netSwitch->isCheckable()
<< "checked"<<m_netSwitch->isChecked();
}else{
m_wirelessConnectOpreation->setWirelessEnabled(enable);
if (!enable) {
// m_netSwitch->setEnabled(false);
m_netSwitch->setChecked(false);
m_netSwitch->setCheckable(false);
qDebug() << "KSwitchButton-----WlanPage::setWirelessSwitchEnable2" <<m_netSwitch->isCheckable()
<< "checked"<<m_netSwitch->isChecked();;
m_activatedNetFrame->hide();
m_activatedNetDivider->hide();
m_inactivatedNetFrame->hide();

View File

@ -159,7 +159,7 @@ int main(int argc, char *argv[])
// window_hints.decorations = MWM_DECOR_BORDER;
// XAtomHelper::getInstance()->setWindowMotifHint(w.winId(), window_hints);
w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint /*| Qt::X11BypassWindowManagerHint*/);
// w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint /*| Qt::X11BypassWindowManagerHint*/);
DbusAdaptor adaptor(&w);