Merge branch 'dbus-interface-fork' into 'dbus-interface'

解决BUG 103974 【反馈回归】【无线网络】使用ip link set down dev wlan0关闭无线设备后,无线开关仍然是打开状态,无无线列表。顺带修改无线开关逻辑

See merge request kylin-desktop/kylin-nm!699
This commit is contained in:
赵世旭 2022-08-26 03:42:41 +00:00
commit ce5e20537d
14 changed files with 219 additions and 144 deletions

View File

@ -148,7 +148,6 @@ WlanConnect::~WlanConnect()
ui = nullptr; ui = nullptr;
} }
delete m_interface; delete m_interface;
delete m_switchGsettings;
} }
QString WlanConnect::plugini18nName() { QString WlanConnect::plugini18nName() {
@ -224,10 +223,10 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
if (w == m_wifiSwitch) { if (w == m_wifiSwitch) {
if (e->type() == QMouseEvent::MouseButtonRelease) { if (e->type() == QMouseEvent::MouseButtonRelease) {
if (!m_wifiSwitch->isCheckable()) { if (!getSwitchBtnEnable()) {
showDesktopNotify(tr("No wireless network card detected")); showDesktopNotify(tr("No wireless network card detected"));
} else { } else {
m_interface->call(QStringLiteral("setWirelessSwitchEnable"), !m_wifiSwitch->isChecked()); m_interface->call(QStringLiteral("setWirelessSwitchEnable"), !getSwitchBtnState());
return true; return true;
} }
} }
@ -246,33 +245,18 @@ void WlanConnect::initComponent() {
m_wifiSwitch->installEventFilter(this); m_wifiSwitch->installEventFilter(this);
//开关 //开关
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { initSwtichState();
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!";
}
//获取设备列表 //获取设备列表
getDeviceList(deviceList); getDeviceList(deviceList);
if (deviceList.isEmpty()) { if (deviceList.isEmpty()) {
qDebug() << "[WlanConnect]no device exist when init, set switch disable"; qDebug() << "[WlanConnect]no device exist when init, set switch disable";
m_wifiSwitch->setChecked(false); setSwitchBtnState(false);
m_wifiSwitch->setCheckable(false); setSwitchBtnEnable(false);
} }
initNet(); initNet();
if (!m_wifiSwitch->isChecked() || deviceList.isEmpty() || !m_interface->isValid()) { if (!getSwitchBtnState() || deviceList.isEmpty() || !m_interface->isValid()) {
hideLayout(ui->availableLayout); hideLayout(ui->availableLayout);
} }
@ -288,6 +272,7 @@ void WlanConnect::initComponent() {
// connect(m_interface, SIGNAL(signalStrengthChange(QString, QString, int)), this, SLOT(updateStrengthList(QString, QString, int))); // connect(m_interface, SIGNAL(signalStrengthChange(QString, QString, int)), this, SLOT(updateStrengthList(QString, QString, int)));
//网卡name处理 //网卡name处理
connect(m_interface, SIGNAL(deviceNameChanged(QString, QString, int)), this, SLOT(onDeviceNameChanged(QString, QString, int)), Qt::QueuedConnection); 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(m_interface, SIGNAL(timeToUpdate()), this, SLOT(updateList()), Qt::QueuedConnection);
//高级设置 //高级设置
@ -320,7 +305,7 @@ void WlanConnect::reScan()
//更新列表顺序 //更新列表顺序
void WlanConnect::updateList() void WlanConnect::updateList()
{ {
if (!m_wifiSwitch->isChecked()) { if (!getSwitchBtnState()) {
return; return;
} }
qDebug() << "update list"; qDebug() << "update list";
@ -525,11 +510,11 @@ void WlanConnect::onDeviceStatusChanged()
} }
deviceList = list; deviceList = list;
if (deviceList.isEmpty()) { if (deviceList.isEmpty()) {
m_wifiSwitch->setChecked(false); setSwitchBtnState(false);
m_wifiSwitch->setCheckable(false); setSwitchBtnEnable(false);
} else { } else {
m_wifiSwitch->setCheckable(true); setSwitchBtnEnable(true);
setSwitchStatus(); 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 //activeconnect status change
void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, int status) void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, int status)
{ {
if (!m_wifiSwitch->isChecked()) { if (!getSwitchBtnState()) {
return; return;
} }
if (uuid.isEmpty()) { if (uuid.isEmpty()) {
@ -623,7 +622,7 @@ void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QS
void WlanConnect::onNetworkAdd(QString deviceName, QStringList wlanInfo) void WlanConnect::onNetworkAdd(QString deviceName, QStringList wlanInfo)
{ {
qDebug()<<"[WlanConnect]onNetworkAdd "<< deviceName << " " << wlanInfo; qDebug()<<"[WlanConnect]onNetworkAdd "<< deviceName << " " << wlanInfo;
if(!m_wifiSwitch->isChecked() || deviceName.isEmpty()) { if(!getSwitchBtnState() || deviceName.isEmpty()) {
return; return;
} }
@ -693,25 +692,22 @@ void WlanConnect::getDeviceList(QStringList &list)
list = map.keys(); list = map.keys();
} }
//设置开关 void WlanConnect::initSwtichState()
void WlanConnect::setSwitchStatus()
{ {
// if (deviceList.size() == 0) { if (!m_interface->isValid()) {
// m_wifiSwitch->blockSignals(true); return;
// 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);
} }
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) void WlanConnect::initNetListFromDevice(QString deviceName)
{ {
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName; qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName;
if (!m_wifiSwitch->isChecked()) { if (!getSwitchBtnState()) {
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName << " switch off"; qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName << " switch off";
return; return;
} }

View File

@ -98,7 +98,6 @@ private:
//开关相关 //开关相关
void setSwitchStatus();
void hideLayout(QVBoxLayout * layout); void hideLayout(QVBoxLayout * layout);
void showLayout(QVBoxLayout * layout); void showLayout(QVBoxLayout * layout);
@ -124,6 +123,33 @@ private:
//单个wifi连接状态变化 //单个wifi连接状态变化
void itemActiveConnectionStatusChanged(WlanItem *item, int status); 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: protected:
bool eventFilter(QObject *w,QEvent *e); bool eventFilter(QObject *w,QEvent *e);
@ -136,8 +162,6 @@ private:
QDBusInterface *m_interface = nullptr; QDBusInterface *m_interface = nullptr;
QGSettings *m_switchGsettings = nullptr;
//设备列表 //设备列表
QStringList deviceList; QStringList deviceList;
//设备名 + 单设备frame //设备名 + 单设备frame
@ -162,6 +186,8 @@ private slots:
void onDeviceStatusChanged(); void onDeviceStatusChanged();
void onDeviceNameChanged(QString, QString, int); void onDeviceNameChanged(QString, QString, int);
void onSwitchBtnChanged(bool);
void reScan(); void reScan();

View File

@ -26,6 +26,8 @@
KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(parent) 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_networkResourceInstance = KyNetworkResourceManager::getInstance();
m_deviceMap.clear(); m_deviceMap.clear();
@ -39,6 +41,9 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(pare
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceUpdate, connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceUpdate,
this, &KyNetworkDeviceResourse::onDeviceUpdate, Qt::ConnectionType::DirectConnection); this, &KyNetworkDeviceResourse::onDeviceUpdate, Qt::ConnectionType::DirectConnection);
connect(m_networkResourceInstance, &KyNetworkResourceManager::stateChanged,
this, &KyNetworkDeviceResourse::stateChanged, Qt::ConnectionType::DirectConnection);
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceCarrierChanage, connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceCarrierChanage,
this, &KyNetworkDeviceResourse::carrierChanage); this, &KyNetworkDeviceResourse::carrierChanage);
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceBitRateChanage, connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceBitRateChanage,

View File

@ -44,6 +44,7 @@ signals:
void deviceBitRateChanage(QString deviceName, int bitRate); void deviceBitRateChanage(QString deviceName, int bitRate);
void deviceMacAddressChanage(QString deviceName, const QString &hwAddress); void deviceMacAddressChanage(QString deviceName, const QString &hwAddress);
void deviceActiveChanage(QString deviceName, bool deivceActive); void deviceActiveChanage(QString deviceName, bool deivceActive);
void stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason);
public slots: public slots:
void onDeviceAdd(QString deviceName, QString uni, NetworkManager::Device::Type deviceType); void onDeviceAdd(QString deviceName, QString uni, NetworkManager::Device::Type deviceType);

View File

@ -50,6 +50,8 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa
qRegisterMetaType<NetworkManager::Connectivity>("NetworkManager::Connectivity"); qRegisterMetaType<NetworkManager::Connectivity>("NetworkManager::Connectivity");
qRegisterMetaType<NetworkManager::ActiveConnection::Reason>("NetworkManager::ActiveConnection::Reason"); qRegisterMetaType<NetworkManager::ActiveConnection::Reason>("NetworkManager::ActiveConnection::Reason");
qRegisterMetaType<NetworkManager::Device::Type>("NetworkManager::Device::Type"); 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"), QDBusConnection::systemBus().connect(QString("org.freedesktop.DBus"),
QString("/org/freedesktop/DBus"), QString("/org/freedesktop/DBus"),
@ -264,6 +266,7 @@ void KyNetworkResourceManager::addDevice(NetworkManager::Device::Ptr device)
#endif #endif
connect(qobject_cast<NetworkManager::WirelessDevice *>(device.data()), &NetworkManager::WirelessDevice::networkAppeared, this, &KyNetworkResourceManager::onWifiNetworkAppeared); 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(qobject_cast<NetworkManager::WirelessDevice *>(device.data()), &NetworkManager::WirelessDevice::networkDisappeared, this, &KyNetworkResourceManager::onWifiNetworkDisappeared);
connect(device.data(), &NetworkManager::Device::stateChanged, this, &KyNetworkResourceManager::stateChanged);
break; break;
default: default:
//TODO: other device types! //TODO: other device types!

View File

@ -137,6 +137,8 @@ signals:
NetworkManager::VpnConnection::StateChangeReason reason); NetworkManager::VpnConnection::StateChangeReason reason);
void connectivityChanged(NetworkManager::Connectivity connectivity); void connectivityChanged(NetworkManager::Connectivity connectivity);
void stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason);
public slots: public slots:
void onInitNetwork(); void onInitNetwork();

View File

@ -50,6 +50,11 @@ QMap<QString, QVector<QStringList> > DbusAdaptor::getWirelessList()
return map; return map;
} }
bool DbusAdaptor::getWirelessSwitchBtnState()
{
return parent()->getWirelessSwitchBtnState();
}
//有线列表 //有线列表
QMap<QString, QVector<QStringList>> DbusAdaptor::getWiredList() QMap<QString, QVector<QStringList>> DbusAdaptor::getWiredList()
{ {

View File

@ -92,6 +92,9 @@ public Q_SLOTS: // METHODS
void keyRingClear(); void keyRingClear();
//just show //just show
void showKylinNM(int type); void showKylinNM(int type);
bool getWirelessSwitchBtnState();
Q_SIGNALS: // SIGNALS Q_SIGNALS: // SIGNALS
// void wirelessActivating(QString devName, QString ssid); // void wirelessActivating(QString devName, QString ssid);
// void wiredActivating(QString devName, QString ssid); // void wiredActivating(QString devName, QString ssid);
@ -108,6 +111,7 @@ Q_SIGNALS: // SIGNALS
//设备插拔 //设备插拔
void deviceStatusChanged(); void deviceStatusChanged();
void deviceNameChanged(QString oldName, QString newName, int type); void deviceNameChanged(QString oldName, QString newName, int type);
void wirelessSwitchBtnChanged(bool state);
//热点断开 //热点断开
void hotspotDeactivated(QString devName, QString ssid); void hotspotDeactivated(QString devName, QString ssid);
//热点连接 //热点连接

View File

@ -79,6 +79,11 @@ QString WlanListItem::getSsid()
return m_wirelessNetItem.m_NetSsid; return m_wirelessNetItem.m_NetSsid;
} }
QString WlanListItem::getUuid()
{
return m_wirelessNetItem.m_connectUuid;
}
void WlanListItem::setSignalStrength(const int &signal) void WlanListItem::setSignalStrength(const int &signal)
{ {
m_wirelessNetItem.m_signalStrength = signal; m_wirelessNetItem.m_signalStrength = signal;

View File

@ -59,6 +59,7 @@ public:
public: public:
QString getSsid(); QString getSsid();
QString getUuid();
void setSignalStrength(const int &signal); void setSignalStrength(const int &signal);
int getSignalStrength(); int getSignalStrength();

View File

@ -327,6 +327,7 @@ void MainWindow::initDbusConnnect()
connect(m_lanWidget, &LanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged); connect(m_lanWidget, &LanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged);
connect(m_wlanWidget, &WlanPage::deviceStatusChanged, this, &MainWindow::deviceStatusChanged); connect(m_wlanWidget, &WlanPage::deviceStatusChanged, this, &MainWindow::deviceStatusChanged);
connect(m_wlanWidget, &WlanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged); 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::activateFailed, this, &MainWindow::activateFailed);
connect(m_wlanWidget, &WlanPage::deactivateFailed, this, &MainWindow::deactivateFailed); 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调用 * @brief MainWindow::getWiredList lan列表dbus调用
* @param map * @param map

View File

@ -106,11 +106,14 @@ public:
void keyRingInit(); void keyRingInit();
void keyRingClear(); void keyRingClear();
bool getWirelessSwitchBtnState();
signals: signals:
//设备插拔 //设备插拔
void deviceStatusChanged(); void deviceStatusChanged();
//设备名称变化 //设备名称变化
void deviceNameChanged(QString oldName, QString newName, int type); void deviceNameChanged(QString oldName, QString newName, int type);
void wirelessSwitchBtnChanged(bool state);
//有线无线列表更新(有线增删、无线增加减少) //有线无线列表更新(有线增删、无线增加减少)
void lanAdd(QString devName, QStringList info); void lanAdd(QString devName, QStringList info);
void lanRemove(QString dbusPath); void lanRemove(QString dbusPath);

View File

@ -37,6 +37,8 @@ const QString IsApConnection = "1";
WlanPage::WlanPage(QWidget *parent) : TabPage(parent) 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_wirelessNetResource = new KyWirelessNetResource(this);
m_activatedConnectResource = new KyActiveConnectResourse(this); m_activatedConnectResource = new KyActiveConnectResourse(this);
m_netDeviceResource=new KyNetworkDeviceResourse(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::deviceRemove, this, &WlanPage::onDeviceRemove);
connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceNameUpdate, this, &WlanPage::onDeviceNameUpdate); 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::activateConnectionError, this, &WlanPage::activateFailed);
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::addAndActivateConnectionError, this, &WlanPage::activateFailed); connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::addAndActivateConnectionError, this, &WlanPage::activateFailed);
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::deactivateConnectionError, this, &WlanPage::deactivateFailed); connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::deactivateConnectionError, this, &WlanPage::deactivateFailed);
@ -86,13 +90,11 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e)
} }
} else if (w == m_netSwitch) { } else if (w == m_netSwitch) {
if (e->type() == QEvent::MouseButtonRelease) { if (e->type() == QEvent::MouseButtonRelease) {
if (m_devList.isEmpty()) { if (!getSwitchBtnEnable()) {
showDesktopNotify(tr("No wireless network card detected"), "networkwrong"); showDesktopNotify(tr("No wireless network card detected"), "networkwrong");
//检测不到无线网卡不再触发click信号 //检测不到无线网卡不再触发click信号
m_netSwitch->setChecked(false);
m_netSwitch->setCheckable(false);
} else { } else {
m_wirelessConnectOpreation->setWirelessEnabled(!m_netSwitch->isChecked()); setWirelessEnable(!getSwitchBtnState());
} }
return true; return true;
} }
@ -136,47 +138,37 @@ void WlanPage::initWlanUI()
m_netSwitch->installEventFilter(this); m_netSwitch->installEventFilter(this);
} }
bool WlanPage::getWirelessDevieceUseable()
void WlanPage::onWlanSwithGsettingsChanged(const QString &key)
{ {
if (key == WIRELESS_SWITCH) { for (auto devname : m_devList) {
m_wlanSwitchEnable = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); if (m_netDeviceResource->getDeviceState(devname) >= NetworkManager::Device::Disconnected) {
qDebug() << LOG_FLAG << "wlan switch state" << m_wlanSwitchEnable; return true;
}
if (m_wirelessConnectOpreation->getWirelessEnabled() != m_wlanSwitchEnable) { }
// 根据Gsetting更新开关状态 return false;
m_wirelessConnectOpreation->setWirelessEnabled(m_wlanSwitchEnable);
} }
m_netSwitch->setChecked(m_wlanSwitchEnable); void WlanPage::setWirelessEnable(bool state)
initDeviceCombox(); {
initWlanArea(); m_wirelessConnectOpreation->setWirelessEnabled(state);
return;
} }
bool WlanPage::getWirelessEnable()
{
return m_wirelessConnectOpreation->getWirelessEnabled();
} }
void WlanPage::initWlanSwitchState() 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()) { if (m_devList.isEmpty()) {
m_netSwitch->setChecked(false); setSwitchBtnState(false);
m_netSwitch->setCheckable(false); setSwitchBtnEnable(false);
} else { return ;
wirelessGsetting = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
if (m_wirelessConnectOpreation->getWirelessEnabled()
!= wirelessGsetting) {
//以gsetting为准
m_wirelessConnectOpreation->setWirelessEnabled(wirelessGsetting);
} }
m_netSwitch->setChecked(wirelessGsetting);
} setSwitchBtnEnable(true);
connect(m_switchGsettings, &QGSettings::changed, this, &WlanPage::onWlanSwithGsettingsChanged); setSwitchBtnState(getWirelessDevieceUseable());
}
}
m_netSwitch->setChecked(wirelessGsetting);
m_wlanSwitchEnable = wirelessGsetting;
return; return;
} }
@ -209,7 +201,7 @@ void WlanPage::initDeviceCombox()
this, &WlanPage::onDeviceComboxIndexChanged); this, &WlanPage::onDeviceComboxIndexChanged);
m_deviceComboBox->clear(); m_deviceComboBox->clear();
if (m_netSwitch->isChecked()) { if (getSwitchBtnState()) {
if (0 == m_devList.count()) { if (0 == m_devList.count()) {
m_deviceFrame->show(); m_deviceFrame->show();
m_tipsLabel->show(); m_tipsLabel->show();
@ -494,7 +486,7 @@ void WlanPage::constructWirelessNetArea()
void WlanPage::initWlanArea() void WlanPage::initWlanArea()
{ {
if (m_netSwitch->isChecked()) { if (getSwitchBtnState()) {
m_activatedNetFrame->show(); m_activatedNetFrame->show();
m_activatedNetDivider->show(); m_activatedNetDivider->show();
constructActivateConnectionArea(); constructActivateConnectionArea();
@ -656,7 +648,7 @@ void WlanPage::addDeviceToCombox(QString deviceName)
{ {
disconnect(m_deviceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), disconnect(m_deviceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &WlanPage::onDeviceComboxIndexChanged); this, &WlanPage::onDeviceComboxIndexChanged);
if (m_netSwitch->isChecked()) { if (getSwitchBtnState()) {
if (m_currentDevice.isEmpty()){ if (m_currentDevice.isEmpty()){
m_deviceFrame->hide(); m_deviceFrame->hide();
m_currentDevice = deviceName; m_currentDevice = deviceName;
@ -688,13 +680,10 @@ void WlanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type devi
return; return;
} }
if (m_devList.isEmpty()) {
bool wlanSwitch = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
m_netSwitch->setCheckable(true);
m_netSwitch->setChecked(wlanSwitch);
}
m_devList << deviceName; m_devList << deviceName;
setSwitchBtnEnable(true);
setSwitchBtnState(getWirelessDevieceUseable());
addDeviceToCombox(deviceName); addDeviceToCombox(deviceName);
if (m_currentDevice == deviceName) { if (m_currentDevice == deviceName) {
initWlanArea(); initWlanArea();
@ -710,7 +699,7 @@ void WlanPage::deleteDeviceFromCombox(QString deviceName)
disconnect(m_deviceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), disconnect(m_deviceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &WlanPage::onDeviceComboxIndexChanged); this, &WlanPage::onDeviceComboxIndexChanged);
if (m_netSwitch->isChecked()) { if (getSwitchBtnState()) {
if (0 == m_devList.count()) { if (0 == m_devList.count()) {
m_deviceFrame->hide(); m_deviceFrame->hide();
//m_tipsLabel->show(); //m_tipsLabel->show();
@ -751,8 +740,8 @@ void WlanPage::onDeviceRemove(QString deviceName)
deleteDeviceFromCombox(deviceName); deleteDeviceFromCombox(deviceName);
if (m_devList.isEmpty()) { if (m_devList.isEmpty()) {
m_netSwitch->setChecked(false); setSwitchBtnState(false);
m_netSwitch->setCheckable(false); setSwitchBtnEnable(false);
} }
if (originalDeviceName == deviceName) { if (originalDeviceName == deviceName) {
@ -799,6 +788,17 @@ void WlanPage::onDeviceNameUpdate(QString oldName, QString newName)
emit deviceNameChanged(oldName, newName, WIRELESS); 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, void WlanPage::sendApStateChangeSignal(QString uuid,
QString ssid, QString ssid,
QString deviceName, QString deviceName,
@ -879,10 +879,22 @@ void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName
} }
if (m_activateConnectionItemMap.contains(ssid)) { if (m_activateConnectionItemMap.contains(ssid)) {
QListWidgetItem *p_listWidgetItem = m_activateConnectionItemMap.value(ssid);
if (nullptr == p_listWidgetItem) {
qWarning()<< LOG_FLAG <<"wireless item is not exsit, it's ssid is " << ssid;
return;
}
WlanListItem *p_wlanItem = (WlanListItem *)m_activatedNetListWidget->itemWidget(p_listWidgetItem);
if (nullptr == p_wlanItem) {
qWarning() << LOG_FLAG << "p_wlanItem is null";
return;
}
if (p_wlanItem->getUuid() == uuid) {
deleteWirelessItemFormMap(m_activateConnectionItemMap, m_activatedNetListWidget, ssid); deleteWirelessItemFormMap(m_activateConnectionItemMap, m_activatedNetListWidget, ssid);
QListWidgetItem *p_activeListWidgetItem = addEmptyItem(m_activatedNetListWidget); QListWidgetItem *p_activeListWidgetItem = addEmptyItem(m_activatedNetListWidget);
m_activateConnectionItemMap.insert(EMPTY_SSID, p_activeListWidgetItem); m_activateConnectionItemMap.insert(EMPTY_SSID, p_activeListWidgetItem);
m_activatedNetListWidget->setFixedHeight(p_activeListWidgetItem->sizeHint().height()); m_activatedNetListWidget->setFixedHeight(p_activeListWidgetItem->sizeHint().height());
}
} else { } else {
qDebug() << LOG_FLAG << ssid << "is not in activeconnection map"; qDebug() << LOG_FLAG << ssid << "is not in activeconnection map";
} }
@ -918,7 +930,8 @@ void WlanPage::onConnectionStateChanged(QString uuid,
qDebug()<< LOG_FLAG << "emit wlanActiveConnectionStateChanged" << devName << ssid << state; qDebug()<< LOG_FLAG << "emit wlanActiveConnectionStateChanged" << devName << ssid << state;
emit wlanActiveConnectionStateChanged(devName, ssid, uuid, state); emit wlanActiveConnectionStateChanged(devName, ssid, uuid, state);
if (ssid.isEmpty() || devName.isEmpty()) { //解决通过高级设置添加的未指定网卡的无线连接无法断开的问题,去掉设备为空的判断
if (ssid.isEmpty()) {
qDebug()<< LOG_FLAG << "ssid or devicename is empty" qDebug()<< LOG_FLAG << "ssid or devicename is empty"
<< "devicename"<< devName <<"ssid"<<ssid; << "devicename"<< devName <<"ssid"<<ssid;
return; return;
@ -944,7 +957,7 @@ void WlanPage::onConnectionStateChanged(QString uuid,
} }
} }
if (devName != m_currentDevice) { if (!devName.isEmpty() && devName != m_currentDevice) {
return; return;
} }
@ -989,6 +1002,9 @@ void WlanPage::onConnectionStateChanged(QString uuid,
} }
} else if (state == NetworkManager::ActiveConnection::State::Deactivated) { } else if (state == NetworkManager::ActiveConnection::State::Deactivated) {
m_updateStrength = true; m_updateStrength = true;
if (devName.isEmpty()) {
devName = m_currentDevice;
}
updateWirelessNetArea(uuid, ssid, devName); updateWirelessNetArea(uuid, ssid, devName);
if (m_wirelessNetItemMap.contains(ssid)) { if (m_wirelessNetItemMap.contains(ssid)) {
QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid); QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid);
@ -1109,23 +1125,6 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn)
{ {
//监听外部命令导致wifi状态变化更新界面 //监听外部命令导致wifi状态变化更新界面
qDebug() << "[WlanPage] onWifiEnabledChanged wifi state" << isWifiOn; 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; return;
} }
@ -1297,6 +1296,12 @@ void WlanPage::getWirelessList(QMap<QString, QVector<QStringList> > &map)
return; return;
} }
//for dbus
bool WlanPage::getWirelessSwitchBtnState()
{
return getSwitchBtnState();
}
//开启热点 //开启热点
void WlanPage::activeWirelessAp(const QString apName, const QString apPassword, const QString wirelessBand, const QString apDevice) void WlanPage::activeWirelessAp(const QString apName, const QString apPassword, const QString wirelessBand, const QString apDevice)
{ {
@ -1489,22 +1494,7 @@ bool WlanPage::checkWlanStatus(NetworkManager::ActiveConnection::State state)
void WlanPage::setWirelessSwitchEnable(bool enable) void WlanPage::setWirelessSwitchEnable(bool enable)
{ {
qDebug() << "dbus setWirelessSwitchEnable = " << enable << __LINE__; qDebug() << "dbus setWirelessSwitchEnable = " << enable << __LINE__;
//应该先检测是否有无线网卡可用,才改变开关状态 setWirelessEnable(enable);
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();
}
}
} }
void WlanPage::getWirelessDeviceCap(QMap<QString, int> &map) void WlanPage::getWirelessDeviceCap(QMap<QString, int> &map)

View File

@ -76,6 +76,8 @@ public:
void getConnectivity(NetworkManager::Connectivity &connectivity); void getConnectivity(NetworkManager::Connectivity &connectivity);
bool getWirelessSwitchBtnState();
signals: signals:
void oneItemExpanded(const QString &ssid); void oneItemExpanded(const QString &ssid);
void wlanAdd(QString devName, QStringList info); void wlanAdd(QString devName, QStringList info);
@ -93,6 +95,8 @@ signals:
void connectivityChanged(NetworkManager::Connectivity connectivity); void connectivityChanged(NetworkManager::Connectivity connectivity);
void wirelessSwitchBtnChanged(bool state);
public slots: public slots:
void onMainWindowVisibleChanged(const bool &visible); void onMainWindowVisibleChanged(const bool &visible);
void onSecurityTypeChange(QString devName, QString ssid, QString secuType); void onSecurityTypeChange(QString devName, QString ssid, QString secuType);
@ -115,14 +119,14 @@ private slots:
NetworkManager::ActiveConnection::Reason reason); NetworkManager::ActiveConnection::Reason reason);
void onItemHeightChanged(const bool isExpanded, const QString &ssid); void onItemHeightChanged(const bool isExpanded, const QString &ssid);
void onWlanSwithGsettingsChanged(const QString &key);
void onDeviceComboxIndexChanged(int currentIndex); void onDeviceComboxIndexChanged(int currentIndex);
void onHiddenWlanClicked(); void onHiddenWlanClicked();
void showControlCenter(); void showControlCenter();
void onWifiEnabledChanged(bool isWifiOn); void onWifiEnabledChanged(bool isWifiOn);
void onRefreshIconTimer(); void onRefreshIconTimer();
void onWlanStateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason);
protected: protected:
bool eventFilter(QObject *watched, QEvent *event); bool eventFilter(QObject *watched, QEvent *event);
@ -174,6 +178,31 @@ private:
// void wlanShowNotify(QString ssid, NetworkManager::ActiveConnection::State state, // void wlanShowNotify(QString ssid, NetworkManager::ActiveConnection::State state,
// NetworkManager::ActiveConnection::Reason reason); // 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: private:
QMap<QString, QListWidgetItem*> m_wirelessNetItemMap; QMap<QString, QListWidgetItem*> m_wirelessNetItemMap;
QMap<QString, QListWidgetItem*> m_activateConnectionItemMap; QMap<QString, QListWidgetItem*> m_activateConnectionItemMap;
@ -195,9 +224,6 @@ private:
KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr; KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr;
KyConnectResourse * m_connectResource = nullptr; KyConnectResourse * m_connectResource = nullptr;
QGSettings *m_switchGsettings = nullptr;
bool m_wlanSwitchEnable = true;
bool m_updateStrength = true; bool m_updateStrength = true;
QTimer *m_scanTimer = nullptr; QTimer *m_scanTimer = nullptr;