解决BUG 103974 【反馈回归】【无线网络】使用ip link set down dev wlan0关闭无线设备后,无线开关仍然是打开状态,无无线列表。顺带修改无线开关逻辑
This commit is contained in:
parent
3e6e8ef25e
commit
b148c6e23d
|
@ -148,7 +148,6 @@ WlanConnect::~WlanConnect()
|
|||
ui = nullptr;
|
||||
}
|
||||
delete m_interface;
|
||||
delete m_switchGsettings;
|
||||
}
|
||||
|
||||
QString WlanConnect::plugini18nName() {
|
||||
|
@ -224,10 +223,10 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
|
|||
|
||||
if (w == m_wifiSwitch) {
|
||||
if (e->type() == QMouseEvent::MouseButtonRelease) {
|
||||
if (!m_wifiSwitch->isCheckable()) {
|
||||
if (!getSwitchBtnEnable()) {
|
||||
showDesktopNotify(tr("No wireless network card detected"));
|
||||
} else {
|
||||
m_interface->call(QStringLiteral("setWirelessSwitchEnable"), !m_wifiSwitch->isChecked());
|
||||
m_interface->call(QStringLiteral("setWirelessSwitchEnable"), !getSwitchBtnState());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -246,33 +245,18 @@ void WlanConnect::initComponent() {
|
|||
m_wifiSwitch->installEventFilter(this);
|
||||
|
||||
//开关
|
||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
||||
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
|
||||
|
||||
setSwitchStatus();
|
||||
|
||||
connect(m_switchGsettings, &QGSettings::changed, this, [=] (const QString &key) {
|
||||
if (key == WIRELESS_SWITCH) {
|
||||
setSwitchStatus();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
m_wifiSwitch->blockSignals(true);
|
||||
m_wifiSwitch->setChecked(true);
|
||||
m_wifiSwitch->blockSignals(false);
|
||||
qDebug()<<"[netconnect] org.ukui.kylin-nm.switch is not installed!";
|
||||
}
|
||||
initSwtichState();
|
||||
|
||||
//获取设备列表
|
||||
getDeviceList(deviceList);
|
||||
if (deviceList.isEmpty()) {
|
||||
qDebug() << "[WlanConnect]no device exist when init, set switch disable";
|
||||
m_wifiSwitch->setChecked(false);
|
||||
m_wifiSwitch->setCheckable(false);
|
||||
setSwitchBtnState(false);
|
||||
setSwitchBtnEnable(false);
|
||||
}
|
||||
initNet();
|
||||
|
||||
if (!m_wifiSwitch->isChecked() || deviceList.isEmpty() || !m_interface->isValid()) {
|
||||
if (!getSwitchBtnState() || deviceList.isEmpty() || !m_interface->isValid()) {
|
||||
hideLayout(ui->availableLayout);
|
||||
}
|
||||
|
||||
|
@ -288,7 +272,8 @@ void WlanConnect::initComponent() {
|
|||
// connect(m_interface, SIGNAL(signalStrengthChange(QString, QString, int)), this, SLOT(updateStrengthList(QString, QString, int)));
|
||||
//网卡name处理
|
||||
connect(m_interface, SIGNAL(deviceNameChanged(QString, QString, int)), this, SLOT(onDeviceNameChanged(QString, QString, int)), Qt::QueuedConnection);
|
||||
|
||||
connect(m_interface, SIGNAL(wirelessSwitchBtnChanged(bool)), this, SLOT(onSwitchBtnChanged(bool)), Qt::QueuedConnection);
|
||||
|
||||
connect(m_interface, SIGNAL(timeToUpdate()), this, SLOT(updateList()), Qt::QueuedConnection);
|
||||
//高级设置
|
||||
connect(ui->detailBtn, &QPushButton::clicked, this, [=](bool checked) {
|
||||
|
@ -320,7 +305,7 @@ void WlanConnect::reScan()
|
|||
//更新列表顺序
|
||||
void WlanConnect::updateList()
|
||||
{
|
||||
if (!m_wifiSwitch->isChecked()) {
|
||||
if (!getSwitchBtnState()) {
|
||||
return;
|
||||
}
|
||||
qDebug() << "update list";
|
||||
|
@ -525,11 +510,11 @@ void WlanConnect::onDeviceStatusChanged()
|
|||
}
|
||||
deviceList = list;
|
||||
if (deviceList.isEmpty()) {
|
||||
m_wifiSwitch->setChecked(false);
|
||||
m_wifiSwitch->setCheckable(false);
|
||||
setSwitchBtnState(false);
|
||||
setSwitchBtnEnable(false);
|
||||
} else {
|
||||
m_wifiSwitch->setCheckable(true);
|
||||
setSwitchStatus();
|
||||
setSwitchBtnEnable(true);
|
||||
initSwtichState();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -558,10 +543,24 @@ void WlanConnect::onDeviceNameChanged(QString oldName, QString newName, int type
|
|||
}
|
||||
}
|
||||
|
||||
void WlanConnect::onSwitchBtnChanged(bool state)
|
||||
{
|
||||
if (getSwitchBtnState() == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSwitchBtnState(state);
|
||||
if (!getSwitchBtnState()) {
|
||||
hideLayout(ui->availableLayout);
|
||||
} else {
|
||||
showLayout(ui->availableLayout);
|
||||
}
|
||||
}
|
||||
|
||||
//activeconnect status change
|
||||
void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, int status)
|
||||
{
|
||||
if (!m_wifiSwitch->isChecked()) {
|
||||
if (!getSwitchBtnState()) {
|
||||
return;
|
||||
}
|
||||
if (uuid.isEmpty()) {
|
||||
|
@ -623,7 +622,7 @@ void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QS
|
|||
void WlanConnect::onNetworkAdd(QString deviceName, QStringList wlanInfo)
|
||||
{
|
||||
qDebug()<<"[WlanConnect]onNetworkAdd "<< deviceName << " " << wlanInfo;
|
||||
if(!m_wifiSwitch->isChecked() || deviceName.isEmpty()) {
|
||||
if(!getSwitchBtnState() || deviceName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -693,25 +692,22 @@ void WlanConnect::getDeviceList(QStringList &list)
|
|||
list = map.keys();
|
||||
}
|
||||
|
||||
//设置开关
|
||||
void WlanConnect::setSwitchStatus()
|
||||
void WlanConnect::initSwtichState()
|
||||
{
|
||||
// if (deviceList.size() == 0) {
|
||||
// m_wifiSwitch->blockSignals(true);
|
||||
// m_wifiSwitch->setChecked(false);
|
||||
// m_wifiSwitch->blockSignals(false);
|
||||
// return;
|
||||
// }
|
||||
bool status = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
|
||||
qDebug() << "[WlanConnect]setSwitchStatus" << status;
|
||||
m_wifiSwitch->blockSignals(true);
|
||||
m_wifiSwitch->setChecked(status);
|
||||
m_wifiSwitch->blockSignals(false);
|
||||
if (!m_wifiSwitch->isChecked()) {
|
||||
hideLayout(ui->availableLayout);
|
||||
} else {
|
||||
showLayout(ui->availableLayout);
|
||||
if (!m_interface->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusMessage result = m_interface->call("getWirelessSwitchBtnState");
|
||||
qDebug() << "[WlanConnect]call getWirelessSwitchBtnState respond" << __LINE__;
|
||||
if(result.type() == QDBusMessage::ErrorMessage)
|
||||
{
|
||||
qWarning() << "[WlanConnect]getWirelessSwitchBtnState error:" << result.errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
bool state = result.arguments().at(0).toBool();
|
||||
setSwitchBtnState(state);
|
||||
}
|
||||
|
||||
//初始化整体列表和单设备列表
|
||||
|
@ -731,7 +727,7 @@ void WlanConnect::initNet() {
|
|||
void WlanConnect::initNetListFromDevice(QString deviceName)
|
||||
{
|
||||
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName;
|
||||
if (!m_wifiSwitch->isChecked()) {
|
||||
if (!getSwitchBtnState()) {
|
||||
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName << " switch off";
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,6 @@ private:
|
|||
|
||||
|
||||
//开关相关
|
||||
void setSwitchStatus();
|
||||
void hideLayout(QVBoxLayout * layout);
|
||||
void showLayout(QVBoxLayout * layout);
|
||||
|
||||
|
@ -124,6 +123,33 @@ private:
|
|||
|
||||
//单个wifi连接状态变化
|
||||
void itemActiveConnectionStatusChanged(WlanItem *item, int status);
|
||||
|
||||
void initSwtichState();
|
||||
inline void setSwitchBtnEnable(bool state) {
|
||||
if (m_wifiSwitch != nullptr) {
|
||||
m_wifiSwitch->setCheckable(state);
|
||||
}
|
||||
}
|
||||
inline bool getSwitchBtnEnable() {
|
||||
if (m_wifiSwitch != nullptr) {
|
||||
return m_wifiSwitch->isCheckable();
|
||||
}
|
||||
}
|
||||
|
||||
inline void setSwitchBtnState(bool state) {
|
||||
if (m_wifiSwitch != nullptr) {
|
||||
m_wifiSwitch->blockSignals(true);
|
||||
m_wifiSwitch->setChecked(state);
|
||||
m_wifiSwitch->blockSignals(false);
|
||||
}
|
||||
}
|
||||
inline bool getSwitchBtnState() {
|
||||
if (m_wifiSwitch != nullptr) {
|
||||
return m_wifiSwitch->isChecked();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *w,QEvent *e);
|
||||
|
||||
|
@ -136,8 +162,6 @@ private:
|
|||
|
||||
QDBusInterface *m_interface = nullptr;
|
||||
|
||||
QGSettings *m_switchGsettings = nullptr;
|
||||
|
||||
//设备列表
|
||||
QStringList deviceList;
|
||||
//设备名 + 单设备frame
|
||||
|
@ -162,6 +186,8 @@ private slots:
|
|||
void onDeviceStatusChanged();
|
||||
void onDeviceNameChanged(QString, QString, int);
|
||||
|
||||
void onSwitchBtnChanged(bool);
|
||||
|
||||
void reScan();
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(parent)
|
||||
{
|
||||
qRegisterMetaType<NetworkManager::Device::State>("NetworkManager::Device::State");
|
||||
qRegisterMetaType<NetworkManager::Device::StateChangeReason>("NetworkManager::Device::StateChangeReason");
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
|
||||
m_deviceMap.clear();
|
||||
|
@ -39,6 +41,9 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(pare
|
|||
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceUpdate,
|
||||
this, &KyNetworkDeviceResourse::onDeviceUpdate, Qt::ConnectionType::DirectConnection);
|
||||
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::stateChanged,
|
||||
this, &KyNetworkDeviceResourse::stateChanged, Qt::ConnectionType::DirectConnection);
|
||||
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceCarrierChanage,
|
||||
this, &KyNetworkDeviceResourse::carrierChanage);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceBitRateChanage,
|
||||
|
|
|
@ -44,6 +44,7 @@ signals:
|
|||
void deviceBitRateChanage(QString deviceName, int bitRate);
|
||||
void deviceMacAddressChanage(QString deviceName, const QString &hwAddress);
|
||||
void deviceActiveChanage(QString deviceName, bool deivceActive);
|
||||
void stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason);
|
||||
|
||||
public slots:
|
||||
void onDeviceAdd(QString deviceName, QString uni, NetworkManager::Device::Type deviceType);
|
||||
|
|
|
@ -50,6 +50,8 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa
|
|||
qRegisterMetaType<NetworkManager::Connectivity>("NetworkManager::Connectivity");
|
||||
qRegisterMetaType<NetworkManager::ActiveConnection::Reason>("NetworkManager::ActiveConnection::Reason");
|
||||
qRegisterMetaType<NetworkManager::Device::Type>("NetworkManager::Device::Type");
|
||||
qRegisterMetaType<NetworkManager::Device::State>("NetworkManager::Device::State");
|
||||
qRegisterMetaType<NetworkManager::Device::StateChangeReason>("NetworkManager::Device::StateChangeReason");
|
||||
|
||||
QDBusConnection::systemBus().connect(QString("org.freedesktop.DBus"),
|
||||
QString("/org/freedesktop/DBus"),
|
||||
|
@ -264,6 +266,7 @@ void KyNetworkResourceManager::addDevice(NetworkManager::Device::Ptr device)
|
|||
#endif
|
||||
connect(qobject_cast<NetworkManager::WirelessDevice *>(device.data()), &NetworkManager::WirelessDevice::networkAppeared, this, &KyNetworkResourceManager::onWifiNetworkAppeared);
|
||||
connect(qobject_cast<NetworkManager::WirelessDevice *>(device.data()), &NetworkManager::WirelessDevice::networkDisappeared, this, &KyNetworkResourceManager::onWifiNetworkDisappeared);
|
||||
connect(device.data(), &NetworkManager::Device::stateChanged, this, &KyNetworkResourceManager::stateChanged);
|
||||
break;
|
||||
default:
|
||||
//TODO: other device types!
|
||||
|
|
|
@ -137,6 +137,8 @@ signals:
|
|||
NetworkManager::VpnConnection::StateChangeReason reason);
|
||||
|
||||
void connectivityChanged(NetworkManager::Connectivity connectivity);
|
||||
void stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason);
|
||||
|
||||
|
||||
public slots:
|
||||
void onInitNetwork();
|
||||
|
|
|
@ -50,6 +50,11 @@ QMap<QString, QVector<QStringList> > DbusAdaptor::getWirelessList()
|
|||
return map;
|
||||
}
|
||||
|
||||
bool DbusAdaptor::getWirelessSwitchBtnState()
|
||||
{
|
||||
return parent()->getWirelessSwitchBtnState();
|
||||
}
|
||||
|
||||
//有线列表
|
||||
QMap<QString, QVector<QStringList>> DbusAdaptor::getWiredList()
|
||||
{
|
||||
|
|
|
@ -92,6 +92,9 @@ public Q_SLOTS: // METHODS
|
|||
void keyRingClear();
|
||||
//just show
|
||||
void showKylinNM(int type);
|
||||
|
||||
bool getWirelessSwitchBtnState();
|
||||
|
||||
Q_SIGNALS: // SIGNALS
|
||||
// void wirelessActivating(QString devName, QString ssid);
|
||||
// void wiredActivating(QString devName, QString ssid);
|
||||
|
@ -108,6 +111,7 @@ Q_SIGNALS: // SIGNALS
|
|||
//设备插拔
|
||||
void deviceStatusChanged();
|
||||
void deviceNameChanged(QString oldName, QString newName, int type);
|
||||
void wirelessSwitchBtnChanged(bool state);
|
||||
//热点断开
|
||||
void hotspotDeactivated(QString devName, QString ssid);
|
||||
//热点连接
|
||||
|
|
|
@ -327,6 +327,7 @@ void MainWindow::initDbusConnnect()
|
|||
connect(m_lanWidget, &LanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged);
|
||||
connect(m_wlanWidget, &WlanPage::deviceStatusChanged, this, &MainWindow::deviceStatusChanged);
|
||||
connect(m_wlanWidget, &WlanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged);
|
||||
connect(m_wlanWidget, &WlanPage::wirelessSwitchBtnChanged, this, &MainWindow::wirelessSwitchBtnChanged);
|
||||
|
||||
connect(m_wlanWidget, &WlanPage::activateFailed, this, &MainWindow::activateFailed);
|
||||
connect(m_wlanWidget, &WlanPage::deactivateFailed, this, &MainWindow::deactivateFailed);
|
||||
|
@ -704,6 +705,13 @@ void MainWindow::getWirelessList(QMap<QString, QVector<QStringList> > &map)
|
|||
}
|
||||
}
|
||||
|
||||
bool MainWindow::getWirelessSwitchBtnState()
|
||||
{
|
||||
if (nullptr != m_wlanWidget) {
|
||||
return m_wlanWidget->getWirelessSwitchBtnState();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MainWindow::getWiredList 获取lan列表,供dbus调用
|
||||
* @param map
|
||||
|
|
|
@ -106,11 +106,14 @@ public:
|
|||
void keyRingInit();
|
||||
void keyRingClear();
|
||||
|
||||
bool getWirelessSwitchBtnState();
|
||||
|
||||
signals:
|
||||
//设备插拔
|
||||
void deviceStatusChanged();
|
||||
//设备名称变化
|
||||
void deviceNameChanged(QString oldName, QString newName, int type);
|
||||
void wirelessSwitchBtnChanged(bool state);
|
||||
//有线无线列表更新(有线增删、无线增加减少)
|
||||
void lanAdd(QString devName, QStringList info);
|
||||
void lanRemove(QString dbusPath);
|
||||
|
|
|
@ -37,6 +37,8 @@ const QString IsApConnection = "1";
|
|||
|
||||
WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
|
||||
{
|
||||
qRegisterMetaType<NetworkManager::Device::State>("NetworkManager::Device::State");
|
||||
qRegisterMetaType<NetworkManager::Device::StateChangeReason>("NetworkManager::Device::StateChangeReason");
|
||||
m_wirelessNetResource = new KyWirelessNetResource(this);
|
||||
m_activatedConnectResource = new KyActiveConnectResourse(this);
|
||||
m_netDeviceResource=new KyNetworkDeviceResourse(this);
|
||||
|
@ -67,6 +69,8 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
|
|||
connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceRemove, this, &WlanPage::onDeviceRemove);
|
||||
connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceNameUpdate, this, &WlanPage::onDeviceNameUpdate);
|
||||
|
||||
connect(m_netDeviceResource, &KyNetworkDeviceResourse::stateChanged, this, &WlanPage::onWlanStateChanged);
|
||||
|
||||
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::activateConnectionError, this, &WlanPage::activateFailed);
|
||||
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::addAndActivateConnectionError, this, &WlanPage::activateFailed);
|
||||
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::deactivateConnectionError, this, &WlanPage::deactivateFailed);
|
||||
|
@ -86,13 +90,11 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e)
|
|||
}
|
||||
} else if (w == m_netSwitch) {
|
||||
if (e->type() == QEvent::MouseButtonRelease) {
|
||||
if (m_devList.isEmpty()) {
|
||||
if (!getSwitchBtnEnable()) {
|
||||
showDesktopNotify(tr("No wireless network card detected"), "networkwrong");
|
||||
//检测不到无线网卡不再触发click信号
|
||||
m_netSwitch->setChecked(false);
|
||||
m_netSwitch->setCheckable(false);
|
||||
} else {
|
||||
m_wirelessConnectOpreation->setWirelessEnabled(!m_netSwitch->isChecked());
|
||||
setWirelessEnable(!getSwitchBtnState());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -136,47 +138,37 @@ void WlanPage::initWlanUI()
|
|||
m_netSwitch->installEventFilter(this);
|
||||
}
|
||||
|
||||
|
||||
void WlanPage::onWlanSwithGsettingsChanged(const QString &key)
|
||||
bool WlanPage::getWirelessDevieceUseable()
|
||||
{
|
||||
if (key == WIRELESS_SWITCH) {
|
||||
m_wlanSwitchEnable = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
|
||||
qDebug() << LOG_FLAG << "wlan switch state" << m_wlanSwitchEnable;
|
||||
|
||||
if (m_wirelessConnectOpreation->getWirelessEnabled() != m_wlanSwitchEnable) {
|
||||
// 根据Gsetting更新开关状态
|
||||
m_wirelessConnectOpreation->setWirelessEnabled(m_wlanSwitchEnable);
|
||||
for (auto devname : m_devList) {
|
||||
if (m_netDeviceResource->getDeviceState(devname) >= NetworkManager::Device::Disconnected) {
|
||||
return true;
|
||||
}
|
||||
|
||||
m_netSwitch->setChecked(m_wlanSwitchEnable);
|
||||
initDeviceCombox();
|
||||
initWlanArea();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WlanPage::setWirelessEnable(bool state)
|
||||
{
|
||||
m_wirelessConnectOpreation->setWirelessEnabled(state);
|
||||
return;
|
||||
}
|
||||
|
||||
bool WlanPage::getWirelessEnable()
|
||||
{
|
||||
return m_wirelessConnectOpreation->getWirelessEnabled();
|
||||
}
|
||||
|
||||
void WlanPage::initWlanSwitchState()
|
||||
{
|
||||
bool wirelessGsetting = true;
|
||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
||||
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
|
||||
if (m_switchGsettings->keys().contains(WIRELESS_SWITCH)) {
|
||||
if (m_devList.isEmpty()) {
|
||||
m_netSwitch->setChecked(false);
|
||||
m_netSwitch->setCheckable(false);
|
||||
} else {
|
||||
wirelessGsetting = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
|
||||
if (m_wirelessConnectOpreation->getWirelessEnabled()
|
||||
!= wirelessGsetting) {
|
||||
//以gsetting为准
|
||||
m_wirelessConnectOpreation->setWirelessEnabled(wirelessGsetting);
|
||||
}
|
||||
m_netSwitch->setChecked(wirelessGsetting);
|
||||
}
|
||||
connect(m_switchGsettings, &QGSettings::changed, this, &WlanPage::onWlanSwithGsettingsChanged);
|
||||
}
|
||||
if (m_devList.isEmpty()) {
|
||||
setSwitchBtnState(false);
|
||||
setSwitchBtnEnable(false);
|
||||
return ;
|
||||
}
|
||||
m_netSwitch->setChecked(wirelessGsetting);
|
||||
m_wlanSwitchEnable = wirelessGsetting;
|
||||
|
||||
setSwitchBtnEnable(true);
|
||||
setSwitchBtnState(getWirelessDevieceUseable());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -209,7 +201,7 @@ void WlanPage::initDeviceCombox()
|
|||
this, &WlanPage::onDeviceComboxIndexChanged);
|
||||
m_deviceComboBox->clear();
|
||||
|
||||
if (m_netSwitch->isChecked()) {
|
||||
if (getSwitchBtnState()) {
|
||||
if (0 == m_devList.count()) {
|
||||
m_deviceFrame->show();
|
||||
m_tipsLabel->show();
|
||||
|
@ -494,7 +486,7 @@ void WlanPage::constructWirelessNetArea()
|
|||
|
||||
void WlanPage::initWlanArea()
|
||||
{
|
||||
if (m_netSwitch->isChecked()) {
|
||||
if (getSwitchBtnState()) {
|
||||
m_activatedNetFrame->show();
|
||||
m_activatedNetDivider->show();
|
||||
constructActivateConnectionArea();
|
||||
|
@ -656,7 +648,7 @@ void WlanPage::addDeviceToCombox(QString deviceName)
|
|||
{
|
||||
disconnect(m_deviceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &WlanPage::onDeviceComboxIndexChanged);
|
||||
if (m_netSwitch->isChecked()) {
|
||||
if (getSwitchBtnState()) {
|
||||
if (m_currentDevice.isEmpty()){
|
||||
m_deviceFrame->hide();
|
||||
m_currentDevice = deviceName;
|
||||
|
@ -688,13 +680,10 @@ void WlanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type devi
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_devList.isEmpty()) {
|
||||
bool wlanSwitch = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
|
||||
m_netSwitch->setCheckable(true);
|
||||
m_netSwitch->setChecked(wlanSwitch);
|
||||
}
|
||||
|
||||
m_devList << deviceName;
|
||||
setSwitchBtnEnable(true);
|
||||
setSwitchBtnState(getWirelessDevieceUseable());
|
||||
|
||||
addDeviceToCombox(deviceName);
|
||||
if (m_currentDevice == deviceName) {
|
||||
initWlanArea();
|
||||
|
@ -710,7 +699,7 @@ void WlanPage::deleteDeviceFromCombox(QString deviceName)
|
|||
disconnect(m_deviceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &WlanPage::onDeviceComboxIndexChanged);
|
||||
|
||||
if (m_netSwitch->isChecked()) {
|
||||
if (getSwitchBtnState()) {
|
||||
if (0 == m_devList.count()) {
|
||||
m_deviceFrame->hide();
|
||||
//m_tipsLabel->show();
|
||||
|
@ -751,8 +740,8 @@ void WlanPage::onDeviceRemove(QString deviceName)
|
|||
deleteDeviceFromCombox(deviceName);
|
||||
|
||||
if (m_devList.isEmpty()) {
|
||||
m_netSwitch->setChecked(false);
|
||||
m_netSwitch->setCheckable(false);
|
||||
setSwitchBtnState(false);
|
||||
setSwitchBtnEnable(false);
|
||||
}
|
||||
|
||||
if (originalDeviceName == deviceName) {
|
||||
|
@ -799,6 +788,17 @@ void WlanPage::onDeviceNameUpdate(QString oldName, QString newName)
|
|||
emit deviceNameChanged(oldName, newName, WIRELESS);
|
||||
}
|
||||
|
||||
void WlanPage::onWlanStateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason)
|
||||
{
|
||||
if (getSwitchBtnState() == getWirelessDevieceUseable()) {
|
||||
return ;
|
||||
}
|
||||
setSwitchBtnState(getWirelessDevieceUseable());
|
||||
initDeviceCombox();
|
||||
initWlanArea();
|
||||
emit wirelessSwitchBtnChanged(getSwitchBtnState());
|
||||
}
|
||||
|
||||
void WlanPage::sendApStateChangeSignal(QString uuid,
|
||||
QString ssid,
|
||||
QString deviceName,
|
||||
|
@ -1109,23 +1109,6 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn)
|
|||
{
|
||||
//监听外部命令导致wifi状态变化,更新界面
|
||||
qDebug() << "[WlanPage] onWifiEnabledChanged wifi state" << isWifiOn;
|
||||
isWifiOn = m_wirelessConnectOpreation->getWirelessEnabled();
|
||||
|
||||
//应该先检测是否有无线网卡可用,才改变开关状态
|
||||
if (m_devList.isEmpty()) {
|
||||
qDebug() << "[WLanPage] have no device to use " << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_wlanSwitchEnable == isWifiOn) {
|
||||
return;
|
||||
} else {
|
||||
// if (!m_netSwitch->isChecked()) {
|
||||
// m_netSwitch->setChecked(true);
|
||||
// }
|
||||
m_switchGsettings->set(WIRELESS_SWITCH, isWifiOn);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1297,6 +1280,12 @@ void WlanPage::getWirelessList(QMap<QString, QVector<QStringList> > &map)
|
|||
return;
|
||||
}
|
||||
|
||||
//for dbus
|
||||
bool WlanPage::getWirelessSwitchBtnState()
|
||||
{
|
||||
return getSwitchBtnState();
|
||||
}
|
||||
|
||||
//开启热点
|
||||
void WlanPage::activeWirelessAp(const QString apName, const QString apPassword, const QString wirelessBand, const QString apDevice)
|
||||
{
|
||||
|
@ -1489,22 +1478,7 @@ bool WlanPage::checkWlanStatus(NetworkManager::ActiveConnection::State state)
|
|||
void WlanPage::setWirelessSwitchEnable(bool enable)
|
||||
{
|
||||
qDebug() << "dbus setWirelessSwitchEnable = " << enable << __LINE__;
|
||||
//应该先检测是否有无线网卡可用,才改变开关状态
|
||||
if (m_devList.isEmpty()) {
|
||||
qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__;
|
||||
//检测不到无线网卡不再触发click信号
|
||||
m_netSwitch->setChecked(false);
|
||||
m_netSwitch->setCheckable(false);
|
||||
}else{
|
||||
m_wirelessConnectOpreation->setWirelessEnabled(enable);
|
||||
if (!enable) {
|
||||
m_netSwitch->setChecked(false);
|
||||
m_activatedNetFrame->hide();
|
||||
m_activatedNetDivider->hide();
|
||||
m_inactivatedNetFrame->hide();
|
||||
m_deviceFrame->hide();
|
||||
}
|
||||
}
|
||||
setWirelessEnable(enable);
|
||||
}
|
||||
|
||||
void WlanPage::getWirelessDeviceCap(QMap<QString, int> &map)
|
||||
|
|
|
@ -76,6 +76,8 @@ public:
|
|||
|
||||
void getConnectivity(NetworkManager::Connectivity &connectivity);
|
||||
|
||||
bool getWirelessSwitchBtnState();
|
||||
|
||||
signals:
|
||||
void oneItemExpanded(const QString &ssid);
|
||||
void wlanAdd(QString devName, QStringList info);
|
||||
|
@ -93,6 +95,8 @@ signals:
|
|||
|
||||
void connectivityChanged(NetworkManager::Connectivity connectivity);
|
||||
|
||||
void wirelessSwitchBtnChanged(bool state);
|
||||
|
||||
public slots:
|
||||
void onMainWindowVisibleChanged(const bool &visible);
|
||||
void onSecurityTypeChange(QString devName, QString ssid, QString secuType);
|
||||
|
@ -115,14 +119,14 @@ private slots:
|
|||
NetworkManager::ActiveConnection::Reason reason);
|
||||
void onItemHeightChanged(const bool isExpanded, const QString &ssid);
|
||||
|
||||
void onWlanSwithGsettingsChanged(const QString &key);
|
||||
|
||||
void onDeviceComboxIndexChanged(int currentIndex);
|
||||
void onHiddenWlanClicked();
|
||||
void showControlCenter();
|
||||
void onWifiEnabledChanged(bool isWifiOn);
|
||||
void onRefreshIconTimer();
|
||||
|
||||
void onWlanStateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
|
@ -174,6 +178,31 @@ private:
|
|||
// void wlanShowNotify(QString ssid, NetworkManager::ActiveConnection::State state,
|
||||
// NetworkManager::ActiveConnection::Reason reason);
|
||||
|
||||
//是否存在可用的无线网卡
|
||||
bool getWirelessDevieceUseable();
|
||||
void setWirelessEnable(bool state);
|
||||
bool getWirelessEnable();
|
||||
inline void setSwitchBtnState(bool state) {
|
||||
if (m_netSwitch != nullptr) {
|
||||
m_netSwitch->setChecked(state);
|
||||
}
|
||||
}
|
||||
inline bool getSwitchBtnState() {
|
||||
if (m_netSwitch != nullptr) {
|
||||
return m_netSwitch->isChecked();
|
||||
}
|
||||
}
|
||||
inline void setSwitchBtnEnable(bool state) {
|
||||
if (m_netSwitch != nullptr) {
|
||||
m_netSwitch->setCheckable(state);
|
||||
}
|
||||
}
|
||||
inline bool getSwitchBtnEnable() {
|
||||
if (m_netSwitch != nullptr) {
|
||||
return m_netSwitch->isCheckable();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QMap<QString, QListWidgetItem*> m_wirelessNetItemMap;
|
||||
QMap<QString, QListWidgetItem*> m_activateConnectionItemMap;
|
||||
|
@ -195,9 +224,6 @@ private:
|
|||
KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr;
|
||||
KyConnectResourse * m_connectResource = nullptr;
|
||||
|
||||
QGSettings *m_switchGsettings = nullptr;
|
||||
bool m_wlanSwitchEnable = true;
|
||||
|
||||
bool m_updateStrength = true;
|
||||
|
||||
QTimer *m_scanTimer = nullptr;
|
||||
|
|
Loading…
Reference in New Issue