Change wired network connection style

This commit is contained in:
chenlelin 2021-01-09 10:50:45 +08:00
parent b5b1305c3e
commit 642587c56d
9 changed files with 132 additions and 90 deletions

View File

@ -32,15 +32,20 @@
BackThread::BackThread(QObject *parent) : QObject(parent)
{
cmdConnWifi = new QProcess(this);
connect(cmdConnWifi , SIGNAL(readyReadStandardOutput()) , this , SLOT(on_readoutput()));
connect(cmdConnWifi , SIGNAL(readyReadStandardError()) , this , SLOT(on_readerror()));
cmdConnWifi->start("bash");
connect(cmdConnWifi , SIGNAL(readyReadStandardOutput()) , this , SLOT(onReadOutputWifi()));
connect(cmdConnWifi , SIGNAL(readyReadStandardError()) , this , SLOT(onReadErrorWifi()));
cmdConnWifi->start("/bin/bash");
cmdConnWifi->waitForStarted();
process = new QProcess(this);
connect(process , SIGNAL(readyReadStandardOutput()) , this , SLOT(onReadOutputLan()));
connect(process , SIGNAL(readyReadStandardError()) , this , SLOT(onReadErrorLan()));
}
BackThread::~BackThread()
{
cmdConnWifi->close();
process->close();
}
//get the connection state of wired and wireles network
@ -199,6 +204,7 @@ void BackThread::execDisWifi()
//to connect wired network
void BackThread::execConnLan(QString connName, QString ifname)
{
currConnLanUuid = connName;
KylinDBus objKyDbus;
//先断开当前网卡对应的已连接有线网
@ -210,34 +216,12 @@ void BackThread::execConnLan(QString connName, QString ifname)
bool wiredCableState = objKyDbus.getWiredCableStateByIfname(ifname);
if (wiredCableState) {
// only if wired cable is plug in, can connect wired network
QString tmpPath = "/tmp/kylin-nm-connprop-" + QDir::home().dirName();
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "' ifname '" + ifname + "' > " + tmpPath;
Utils::m_system(cmd.toUtf8().data());
QFile file(tmpPath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-lanprop!");
qDebug()<<"Can't open the file /tmp/kylin-nm-lanprop!"<<endl;
}
QString txt = file.readAll();
file.close();
qDebug() << txt;
if (txt.indexOf("successfully") != -1) {
qDebug()<<"debug: in function execConnLan, wired net state is: "<<QString::number(execGetIface()->lstate);
syslog(LOG_DEBUG, "In function execConnLan, wired net state is: %d", execGetIface()->lstate);
emit connDone(0);
} else {
QString cmd = "nmcli connection down '" + connName + "'";
Utils::m_system(cmd.toUtf8().data());
if (txt.indexOf("IP configuration could not be reserved") != -1) {
emit connDone(5);
} else if(txt.indexOf("MACs") != -1 || txt.indexOf("Mac") != -1 || txt.indexOf("MAC") != -1) {
emit connDone(2);
} else {
emit connDone(4);
}
}
QString mycmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "' ifname '" + ifname + "'";
QStringList options;
options << "-c" << mycmd;
process->start("/bin/bash",options);
process->waitForStarted();
process->waitForFinished();
} else {
qDebug()<<"connect wired network failed for without wired cable plug in.";
syslog(LOG_DEBUG, "connect wired network failed for without wired cable plug in.");
@ -247,6 +231,42 @@ void BackThread::execConnLan(QString connName, QString ifname)
emit btFinish();
}
void BackThread::onReadOutputLan()
{
QByteArray cmdout = process->readAllStandardOutput();
QString strResult = QString::fromLocal8Bit(cmdout);
qDebug()<<"on_readoutput_lan: "<< strResult;
dellConnectLanResult(strResult);
}
void BackThread::onReadErrorLan()
{
QByteArray cmdout = process->readAllStandardError();
QString strResult = QString::fromLocal8Bit(cmdout);
qDebug()<<"on_readerror_lan: "<< strResult;
dellConnectLanResult(strResult);
}
void BackThread::dellConnectLanResult(QString info)
{
if (info.indexOf("successfully") != -1) {
qDebug()<<"debug: in function execConnLan, wired net state is: "<<QString::number(execGetIface()->lstate);
syslog(LOG_DEBUG, "In function execConnLan, wired net state is: %d", execGetIface()->lstate);
emit connDone(0);
} else {
QString cmd = "nmcli connection down '" + currConnLanUuid + "'";
Utils::m_system(cmd.toUtf8().data());
if (info.indexOf("IP configuration could not be reserved") != -1) {
emit connDone(4);
} else if(info.indexOf("MACs") != -1 || info.indexOf("Mac") != -1 || info.indexOf("MAC") != -1) {
emit connDone(5);
} else if(info.indexOf("Killed") != -1 || info.indexOf("killed") != -1) {
emit connDone(6);
} else {
emit connDone(7);
}
}
}
//to connected wireless network need a password
void BackThread::execConnWifiPWD(QString connName, QString password, QString connType)
{
@ -292,43 +312,40 @@ void BackThread::execConnWifi(QString connName)
cmdConnWifi->write(cmdStr.toUtf8().data());
}
void BackThread::on_readoutput()
void BackThread::onReadOutputWifi()
{
QString str = cmdConnWifi->readAllStandardOutput();
cmdConnWifi->close();
qDebug()<<"on_readoutput: "<< str;
if (str.indexOf("successfully") != -1) {
emit connDone(0); //send this signal if connect net successfully
qDebug()<<"debug: in function on_readoutput, wireless net state is: "<<QString::number(execGetIface()->wstate);
syslog(LOG_DEBUG, "In function on_readoutput, wireless net state is: %d", execGetIface()->wstate);
} else if(str.indexOf("unknown") != -1) {
emit connDone(2);
} else {
//emit connDone(1);
}
emit btFinish();
qDebug()<<"on_readoutput_wifi: "<< str;
syslog(LOG_DEBUG, "on_readoutput_wifi : %s", str.toUtf8().data());
dellConnectWifiResult(str);
}
void BackThread::on_readerror()
void BackThread::onReadErrorWifi()
{
QString str = cmdConnWifi->readAllStandardError();
cmdConnWifi->close();
qDebug()<<"on_readerror: "<< str;
syslog(LOG_DEBUG, "on_readerror : %s", str.toUtf8().data());
if (str.indexOf("successfully") != -1) {
//emit connDone(0);
} else if(str.indexOf("unknown") != -1 || str.indexOf("not exist") != -1) {
emit connDone(2); //send this signal if the network we want to connect has not a configuration file
} else if(str.indexOf("not given") != -1 || str.indexOf("Secrets were required") != -1){
qDebug()<<"on_readerror_wifi: "<< str;
syslog(LOG_DEBUG, "on_readerror_wifi : %s", str.toUtf8().data());
dellConnectWifiResult(str);
}
void BackThread::dellConnectWifiResult(QString info)
{
if (info.indexOf("successfully") != -1) {
emit connDone(0);
} else if(info.indexOf("unknown") != -1 || info.indexOf("not exist") != -1) {
//send this signal if the network we want to connect has not a configuration file
emit connDone(2);
} else if(info.indexOf("not given") != -1 || info.indexOf("Secrets were required") != -1){
//password for '802-11-wireless-security.psk' not given in 'passwd-file'
emit connDone(4);
} else {
emit connDone(1); //send this signal if connect net failed
//send this signal if connect net failed
emit connDone(1);
}
emit btFinish();
}
//get property of connected network
QString BackThread::getConnProp(QString connName)
{

View File

@ -49,6 +49,8 @@ public:
QString getConnProp(QString connName);
QString execChkLanWidth(QString ethName);
QProcess *cmdConnWifi = nullptr;
QProcess *process;
QString currConnLanUuid;
public slots:
void execEnNet();
@ -62,8 +64,13 @@ public slots:
void disConnSparedNetSlot(QString type);
void disConnLanOrWifi(QString type);
void on_readoutput();
void on_readerror();
void onReadOutputWifi();
void onReadErrorWifi();
void dellConnectWifiResult(QString info);
void onReadOutputLan();
void onReadErrorLan();
void dellConnectLanResult(QString info);
signals:

View File

@ -2692,46 +2692,27 @@ void MainWindow::connLanDone(int connFlag)
if (connFlag == 0) {
syslog(LOG_DEBUG, "Wired net already connected by clicking button");
this->is_wired_line_ready = 1;
this->is_by_click_connect = 1;
this->ksnm->execGetLanList();
//this->ksnm->execGetLanList();
QString txt(tr("Conn Ethernet Success"));
objKyDBus->showDesktopNotify(txt);
}
if (connFlag == 1) {
//qDebug()<<"without net line connect to computer";
syslog(LOG_DEBUG, "without net line connect to computer.");
this->is_wired_line_ready = 0; //without net line connect to computer
this->is_wired_line_ready = 0; //is_wired_line_ready=0 mean without wired cable
is_stop_check_net_state = 0;
QString txt(tr("Without Lan Cable"));
objKyDBus->showDesktopNotify(txt);
}
if (connFlag == 2) {
//qDebug()<<"The MACs of the device and the connection do not match.";
syslog(LOG_DEBUG, "The MACs of the device and the connection do not match.");
is_stop_check_net_state = 0;
QString txt(tr("MAC Address Mismatch"));
objKyDBus->showDesktopNotify(txt);
}
if (connFlag == 3) {
syslog(LOG_DEBUG, "Launch kylin-nm, Lan already connected");
this->is_wired_line_ready = 1;
}
if (connFlag == 4) {
syslog(LOG_DEBUG, "Connect Wired Network Failed");
this->is_wired_line_ready = 1;
QString txt(tr("Connect Wired Network Failed"));
objKyDBus->showDesktopNotify(txt);
}
if (connFlag == 5) {
syslog(LOG_DEBUG, "IP configuration could not be reserved");
this->is_wired_line_ready = 1;
@ -2739,6 +2720,30 @@ void MainWindow::connLanDone(int connFlag)
objKyDBus->showDesktopNotify(txt);
}
if (connFlag == 5) {
syslog(LOG_DEBUG, "The MACs of the device and the connection do not match.");
this->is_wired_line_ready = 1;
QString txt(tr("MAC Address Mismatch"));
objKyDBus->showDesktopNotify(txt);
}
if (connFlag == 6) {
syslog(LOG_DEBUG, "Connection timed out");
this->is_wired_line_ready = 1;
QString txt(tr("Connection timed out"));
objKyDBus->showDesktopNotify(txt);
}
if (connFlag == 7) {
syslog(LOG_DEBUG, "Connect Wired Network Failed");
this->is_wired_line_ready = 1;
QString txt(tr("Connect Wired Network Failed"));
objKyDBus->showDesktopNotify(txt);
}
this->stopLoading();
}
@ -2747,7 +2752,6 @@ void MainWindow::connWifiDone(int connFlag)
// Wifi连接结果0点击连接成功 1失败 2没有配置文件 3开机启动网络工具时已经连接
if (connFlag == 0) {
syslog(LOG_DEBUG, "Wi-Fi already connected by clicking button");
this->is_by_click_connect = 1;
this->ksnm->execGetWifiList();
QString txt(tr("Conn Wifi Success"));

View File

@ -148,7 +148,6 @@ public:
//状态设置,0为假1为真
int is_update_wifi_list = 0; //是否是update wifi列表而不是load wifi列表
int is_init_wifi_list = 0; //是否在启动软件时正在获取wifi的列表
int is_by_click_connect = 0; //是否是通过点击连接按钮进行的连接
int is_btnNetList_clicked = 1; //是否处于有线网界面
int is_btnWifiList_clicked = 0; //是否处于无线网界面
int is_wired_line_ready = 1; //主机是否连接网线

View File

@ -30,7 +30,7 @@
#include "ksimplenm.h"
#define FRAME_SPEED 150
#define LIMIT_TIME 30*1000
#define LIMIT_TIME 60*1000
#define TOTAL_PAGE 8
#define W_ITEM 424

View File

@ -1363,12 +1363,17 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2759"/>
<location filename="../src/mainwindow.cpp" line="2746"/>
<source>Connection timed out</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2767"/>
<source>Confirm your Wi-Fi password or usable of wireless card</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2764"/>
<location filename="../src/mainwindow.cpp" line="2772"/>
<source>Confirm your Wi-Fi password</source>
<translation type="unfinished"></translation>
</message>
@ -1394,7 +1399,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2753"/>
<location filename="../src/mainwindow.cpp" line="2761"/>
<source>Conn Wifi Success</source>
<translation type="unfinished"></translation>
</message>

View File

@ -1522,12 +1522,17 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2759"/>
<location filename="../src/mainwindow.cpp" line="2746"/>
<source>Connection timed out</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2767"/>
<source>Confirm your Wi-Fi password or usable of wireless card</source>
<translation type="unfinished">Kablosuz şifrenizi veya kablosuz kart kullanılabilirliğini onaylayın</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2764"/>
<location filename="../src/mainwindow.cpp" line="2772"/>
<source>Confirm your Wi-Fi password</source>
<translation type="unfinished">Wi-Fi parolasını doğrula</translation>
</message>
@ -1596,7 +1601,7 @@
<translation type="vanished">Ethernet Bağlantısı Hatası</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2753"/>
<location filename="../src/mainwindow.cpp" line="2761"/>
<source>Conn Wifi Success</source>
<translation>Wi-Fi Bağlantısı Başarılı</translation>
</message>

Binary file not shown.

View File

@ -1482,12 +1482,17 @@
<translation type="unfinished">IP </translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2759"/>
<location filename="../src/mainwindow.cpp" line="2746"/>
<source>Connection timed out</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2767"/>
<source>Confirm your Wi-Fi password or usable of wireless card</source>
<translation type="unfinished">Wi-Fi密码或无线设备</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2764"/>
<location filename="../src/mainwindow.cpp" line="2772"/>
<source>Confirm your Wi-Fi password</source>
<translation type="unfinished">Wi-Fi密码</translation>
</message>
@ -1556,7 +1561,7 @@
<translation type="vanished">线</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2753"/>
<location filename="../src/mainwindow.cpp" line="2761"/>
<source>Conn Wifi Success</source>
<translation>线</translation>
</message>