Feature: Write config file when wifi/lan switch status changed.
当有线/无线网开关状态改变时,存储配置,以便重启后校准网络设备开关状态 Link: http://172.17.66.192/biz/task-view-33373.html
This commit is contained in:
parent
55c16c5654
commit
2cec6f8dbc
|
@ -114,6 +114,25 @@ IFace* BackThread::execGetIface()
|
|||
return iface;
|
||||
}
|
||||
|
||||
void BackThread::saveSwitchButtonState(const QString &key, const QVariant &value)
|
||||
{
|
||||
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
|
||||
m_settings->setValue(key, value);
|
||||
m_settings->sync();
|
||||
delete m_settings;
|
||||
return;
|
||||
}
|
||||
|
||||
QVariant BackThread::getSwitchState(const QString &key)
|
||||
{
|
||||
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
|
||||
QVariant value = m_settings->value(key);
|
||||
delete m_settings;
|
||||
if (!value.isValid())
|
||||
return QVariant();
|
||||
return value;
|
||||
}
|
||||
|
||||
//turn on the switch of network
|
||||
void BackThread::execEnNet()
|
||||
{
|
||||
|
|
|
@ -29,6 +29,11 @@
|
|||
#include <QDBusInterface>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusArgument>
|
||||
#include <QSettings>
|
||||
|
||||
#define CONFIG_FILE_PATH QDir::homePath() + "/.config/ukui/kylin-nm.conf"
|
||||
#define WIFI_SWITCH_OPENED "wifi_switch_opened"
|
||||
#define LAN_SWITCH_OPENED "lan_switch_opened"
|
||||
|
||||
class IFace{
|
||||
public:
|
||||
|
@ -46,6 +51,8 @@ public:
|
|||
~BackThread();
|
||||
|
||||
static IFace* execGetIface();
|
||||
static void saveSwitchButtonState(const QString &key, const QVariant &value);
|
||||
static QVariant getSwitchState(const QString &key);
|
||||
QString getConnProp(QString connName);
|
||||
QString execChkLanWidth(QString ethName);
|
||||
QProcess *cmdProcessWifi = nullptr;
|
||||
|
|
|
@ -131,16 +131,34 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(btnWireless, &SwitchButton::clicked,this, &MainWindow::onBtnWifiClicked);
|
||||
connect(btnWired, &SwitchButton::clicked, this, &MainWindow::onBtnLanClicked);
|
||||
connect(this, &MainWindow::onWiredDeviceChanged, this, &MainWindow::setLanSwitchStatus);
|
||||
int lstate = BackThread::execGetIface()->lstate;
|
||||
if (objKyDBus->isWiredCableOn) {
|
||||
if (lstate == 2) {
|
||||
btnWired->setSwitchStatus(false);
|
||||
} else {
|
||||
btnWired->setSwitchStatus(true);
|
||||
}
|
||||
} else {
|
||||
|
||||
QVariant wifi_state = BackThread::getSwitchState(WIFI_SWITCH_OPENED);
|
||||
QVariant lan_state = BackThread::getSwitchState(LAN_SWITCH_OPENED);
|
||||
if (!wifi_state.isNull() && wifi_state.isValid()) {
|
||||
//设置WiFi开关状态
|
||||
if (wifi_state.toBool() && !btnWireless->getSwitchStatus())
|
||||
onBtnWifiClicked(1);
|
||||
else if (!wifi_state.toBool() && btnWireless->getSwitchStatus())
|
||||
onBtnWifiClicked(0);
|
||||
}
|
||||
if (!lan_state.isNull() && lan_state.isValid()) {
|
||||
//设置lan开关状态
|
||||
if (lan_state.toBool() && !btnWired->getSwitchStatus())
|
||||
onBtnLanClicked(1);
|
||||
else if (!lan_state.toBool() && btnWired->getSwitchStatus())
|
||||
onBtnLanClicked(0);
|
||||
}
|
||||
connect(btnWired, &SwitchButton::switchStatusChanged, this, [ = ]() {
|
||||
BackThread::saveSwitchButtonState(LAN_SWITCH_OPENED, btnWired->getSwitchStatus());
|
||||
});
|
||||
connect(btnWireless, &SwitchButton::switchStatusChanged, this, [ = ]() {
|
||||
BackThread::saveSwitchButtonState(WIFI_SWITCH_OPENED, btnWireless->getSwitchStatus());
|
||||
});
|
||||
if (!objKyDBus->isWiredCableOn) {
|
||||
btnWired->blockSignals(true);
|
||||
btnWired->setSwitchStatus(false);
|
||||
btnWired->setEnabled(false);
|
||||
btnWired->blockSignals(false);
|
||||
}
|
||||
|
||||
ui->btnNetList->setAttribute(Qt::WA_Hover,true);
|
||||
|
@ -378,7 +396,7 @@ void MainWindow::createLeftAreaUI()
|
|||
qDebug()<<"Creating Left Area Ui...";
|
||||
btnWireless = new SwitchButton(this);
|
||||
btnWireless->setStyleSheet("SwitchButton{border:none;background-color:rgba(255,255,255,0.12);}");
|
||||
btnWired= new SwitchButton(this);
|
||||
btnWired = new SwitchButton(this);
|
||||
btnWired->setStyleSheet("SwitchButton{border:none;background-color:rgba(255,255,255,0.12);}");
|
||||
ui->btnNetList->setFocusPolicy(Qt::NoFocus);
|
||||
QString txtEthernet(tr("Ethernet"));
|
||||
|
@ -1109,6 +1127,8 @@ void MainWindow::onNetworkDeviceAdded(QDBusObjectPath objPath)
|
|||
//仅处理无线网卡插入情况
|
||||
objKyDBus->isWirelessCardOn = false;
|
||||
objKyDBus->getObjectPath();
|
||||
if (objKyDBus->multiWirelessPaths.isEmpty())
|
||||
return;
|
||||
|
||||
if (objKyDBus->multiWirelessPaths.at(0).path() == objPath.path()) { //证明添加的是无线网卡
|
||||
is_wireless_adapter_ready = 0;
|
||||
|
@ -1124,6 +1144,8 @@ void MainWindow::onNetworkDeviceAdded(QDBusObjectPath objPath)
|
|||
|
||||
void MainWindow::onNetworkDeviceRemoved(QDBusObjectPath objPath)
|
||||
{
|
||||
if (objKyDBus->multiWirelessPaths.isEmpty())
|
||||
return;
|
||||
//仅处理无线网卡拔出情况
|
||||
if (objKyDBus->multiWirelessPaths.at(0).path() == objPath.path()) {
|
||||
objKyDBus->isWirelessCardOn = false;
|
||||
|
@ -1376,9 +1398,11 @@ void MainWindow::onBtnLanClicked(int flag)
|
|||
break;
|
||||
}
|
||||
case 5: {
|
||||
btnWired->blockSignals(true);
|
||||
btnWired->setSwitchStatus(false);
|
||||
qDebug()<<"Set btnwired enabled=false!";
|
||||
btnWired->setEnabled(false);
|
||||
btnWired->blockSignals(false);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -45,7 +45,7 @@ void SwitchButton::setSwitchStatus(bool check) {
|
|||
} else {
|
||||
m_bIsOn = 0;
|
||||
}
|
||||
|
||||
emit this->switchStatusChanged();
|
||||
m_cTimer->start(); //开始播放动画
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ private:
|
|||
|
||||
Q_SIGNALS:
|
||||
void clicked(int check);
|
||||
void switchStatusChanged();
|
||||
private Q_SLOTS:
|
||||
void startAnimation();
|
||||
|
||||
|
|
Loading…
Reference in New Issue