Merge pull request #67 from mammonsama666/0120-dev

fix(wifi): Added wifi will not be connected automatically.
This commit is contained in:
chenlelin 2021-01-21 15:10:35 +08:00 committed by GitHub
commit 5ed582bc87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 1 deletions

View File

@ -34,6 +34,10 @@ KSimpleNM::KSimpleNM(QObject *parent) : QObject(parent)
runProcessWifi = new QProcess(this);
connect(runProcessWifi, &QProcess::readyRead, this, &KSimpleNM::readProcessWifi);
connect(runProcessWifi, SIGNAL(finished(int)), this, SLOT(finishedProcessWifi(int)));
runProcessConn = new QProcess(this);
connect(runProcessConn, &QProcess::readyRead, this, &KSimpleNM::readProcessConn);
connect(runProcessConn, SIGNAL(finished(int)), this, SLOT(finishedProcessConn(int)));
}
KSimpleNM::~KSimpleNM()
@ -83,6 +87,13 @@ void KSimpleNM::execGetWifiList()
runProcessWifi->start("nmcli -f signal,security,freq,bssid,ssid device wifi");
}
//获取保存的网络列表数据
void KSimpleNM::execGetConnList()
{
shellOutputConn = "";
runProcessConn->start("nmcli -f name connection show");
}
//读取获取到的结果
void KSimpleNM::readProcessLan()
{
@ -94,6 +105,11 @@ void KSimpleNM::readProcessWifi()
QString output = runProcessWifi->readAll();
shellOutputWifi += output;
}
void KSimpleNM::readProcessConn()
{
QString output = runProcessConn->readAll();
shellOutputConn += output;
}
//读取完所有列表数据后发信号将数据发往mainwindow用于显示网络列表
void KSimpleNM::finishedProcessLan(int msg)
@ -108,3 +124,8 @@ void KSimpleNM::finishedProcessWifi(int msg)
emit getWifiListFinished(slist);
isExecutingGetWifiList = false;
}
void KSimpleNM::finishedProcessConn(int msg)
{
QStringList slist = shellOutputConn.split("\n");
emit getConnListFinished(slist);
}

View File

@ -34,8 +34,10 @@ public:
QProcess *runProcessLan;
QProcess *runProcessWifi;
QProcess *runProcessConn;
QString shellOutputLan;
QString shellOutputWifi;
QString shellOutputConn;
bool isExecutingGetLanList = false; //是否正在执行获取有线网列表
bool isExecutingGetWifiList = false; //是否正在执行获取无线网列表
@ -44,16 +46,20 @@ public:
void execGetLanList();
void execGetWifiList();
void execGetConnList();
signals:
void getLanListFinished(QStringList slist);
void getWifiListFinished(QStringList slist);
void getConnListFinished(QStringList slist);
public slots:
void readProcessLan();
void readProcessWifi();
void readProcessConn();
void finishedProcessLan(int msg);
void finishedProcessWifi(int msg);
void finishedProcessConn(int msg);
};
#endif // KSIMPLENM_H

View File

@ -105,6 +105,7 @@ KylinDBus::KylinDBus(MainWindow *mainWindow, QObject *parent) :QObject(parent)
if (mw) {
QObject::connect(this, SIGNAL(updateWiredList(int)), mw, SLOT(onBtnNetListClicked(int)));
QObject::connect(this, SIGNAL(newConnAdded(int)), mw, SLOT(onNewConnAdded(int)));
}
mUtils = new Utils();
@ -770,8 +771,15 @@ void KylinDBus::onNewConnection(QDBusObjectPath objPath)
for(QString key : map.keys() ) {
if (key == "802-3-ethernet") {
emit this->updateWiredList(0); //send this signal to update wired network list
emit this->newConnAdded(0);
syslog(LOG_DEBUG, "A new wired network was created.");
qDebug()<<"A new wired network was created.";
break;
} else if (key == "802-11-wireless") {
syslog(LOG_DEBUG, "A new wireless network(wifi) was created.");
qDebug()<<"A new wireless network was created.";
emit this->newConnAdded(1);
break;
}
}

View File

@ -130,6 +130,7 @@ private:
signals:
void updateWiredList(int n);
void requestSendDesktopNotify(QString message);
void newConnAdded(int type);
};
#endif // KYLINDBUSINTERFACE_H

View File

@ -90,6 +90,7 @@ MainWindow::MainWindow(QWidget *parent) :
this->ksnm = new KSimpleNM();
connect(ksnm, SIGNAL(getLanListFinished(QStringList)), this, SLOT(getLanListDone(QStringList)));
connect(ksnm, SIGNAL(getWifiListFinished(QStringList)), this, SLOT(getWifiListDone(QStringList)));
connect(ksnm, SIGNAL(getConnListFinished(QStringList)), this, SLOT(getConnListDone(QStringList)));
loading = new LoadingDiv(this);
loading->move(40,0);
@ -436,6 +437,8 @@ void MainWindow::getInitLanSlist()
// 初始化网络
void MainWindow::initNetwork()
{
ksnm->execGetConnList();
BackThread *bt = new BackThread();
IFace *iface = bt->execGetIface();
@ -1330,6 +1333,17 @@ void MainWindow::on_btnWifiList_clicked()
bt->deleteLater();
}
/**
* @brief MainWindow::onNewConnAdded
* @param type 0线1线
*/
void MainWindow::onNewConnAdded(int type) {
if (type == 1) {
isAddedWifi = true;
}
this->ksnm->execGetConnList();
}
///////////////////////////////////////////////////////////////////////////////
//网络列表加载与更新
@ -1596,6 +1610,42 @@ void MainWindow::getWifiListDone(QStringList slist)
oldWifiSlist = slist;
}
// 获取已保存的连接列表回调
void MainWindow::getConnListDone(QStringList slist)
{
if (isInitConnList) {
// oldConnSlist = slist;
for (int i = 1; i < slist.length() - 1; i++) {
oldConnSlist << slist.at(i).trimmed();
}
// qDebug()<<oldConnSlist;
isInitConnList = false;
return;
} else {
QStringList newConnSlist;
for (int i = 1; i < slist.length() - 1; i++) {
newConnSlist << slist.at(i).trimmed();
}
for (auto s : newConnSlist) {
if (!oldConnSlist.contains(s)) {
lastAddedConn = s;
break;
}
}
if (isAddedWifi) {
isAddedWifi = false;
//如果是新添加的wifi尝试激活这个wifi
this->is_stop_check_net_state = 1;
BackThread *bt = new BackThread();
bt->execConnWifi(lastAddedConn);
connect(bt, SIGNAL(connDone(int)), this, SLOT(connWifiDone(int)));
}
oldConnSlist.clear();
oldConnSlist = newConnSlist;
return;
}
}
// 加载wifi列表
void MainWindow::loadWifiListDone(QStringList slist)
{
@ -2852,7 +2902,7 @@ void MainWindow::connWifiDone(int connFlag)
QString txt(tr("Conn Wifi Success"));
objKyDBus->showDesktopNotify(txt);
} else if (connFlag == 1) {
is_stop_check_net_state = 0;
// is_stop_check_net_state = 0;
is_connect_net_failed = 1;
QString txt(tr("Confirm your Wi-Fi password or usable of wireless card"));
@ -2864,6 +2914,7 @@ void MainWindow::connWifiDone(int connFlag)
QString txt(tr("Confirm your Wi-Fi password"));
objKyDBus->showDesktopNotify(txt);
}
is_stop_check_net_state = 0;
}
//重新绘制背景色

View File

@ -258,6 +258,10 @@ private:
QStringList oldLanSlist; //上一次获取Lan列表
QStringList oldWifiSlist; //上一次获取wifi列表
QStringList oldConnSlist; //上一次获取的以保存网络列表
bool isInitConnList = true;
bool isAddedWifi = false;
QString lastAddedConn = "";
QString oldActLanName = ""; //上一次获取的已连接有线网名称
int oldDbusActLanDNS = 0; //上一次获取的已连接有线网的DNS代号
@ -293,9 +297,11 @@ private slots:
void onBtnNetClicked();
// void on_btnWifiList_clicked();
void onBtnNetListClicked(int flag=0);
void onNewConnAdded(int type);
void getLanListDone(QStringList slist);
void getWifiListDone(QStringList slist);
void getConnListDone(QStringList slist);
void loadWifiListDone(QStringList slist);
void updateWifiListDone(QStringList slist);
QString TranslateLanName(QString lanName);