diff --git a/src/backthread.cpp b/src/backthread.cpp index a16a30d4..59d2a24f 100644 --- a/src/backthread.cpp +++ b/src/backthread.cpp @@ -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!"<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: "<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: "<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) { diff --git a/src/backthread.h b/src/backthread.h index a5d98365..00c6df20 100644 --- a/src/backthread.h +++ b/src/backthread.h @@ -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: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1854462d..b16fd1a9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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")); diff --git a/src/mainwindow.h b/src/mainwindow.h index 6d600bfd..52f6d43a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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; //主机是否连接网线 diff --git a/src/onelancform.h b/src/onelancform.h index d42b617c..651e9c55 100644 --- a/src/onelancform.h +++ b/src/onelancform.h @@ -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 diff --git a/translations/kylin-nm_bo.ts b/translations/kylin-nm_bo.ts index c8850c24..16f80048 100644 --- a/translations/kylin-nm_bo.ts +++ b/translations/kylin-nm_bo.ts @@ -1363,12 +1363,17 @@ - + + Connection timed out + + + + Confirm your Wi-Fi password or usable of wireless card - + Confirm your Wi-Fi password @@ -1394,7 +1399,7 @@ - + Conn Wifi Success diff --git a/translations/kylin-nm_tr.ts b/translations/kylin-nm_tr.ts index 070ab301..5ab11278 100644 --- a/translations/kylin-nm_tr.ts +++ b/translations/kylin-nm_tr.ts @@ -1522,12 +1522,17 @@ - + + Connection timed out + + + + Confirm your Wi-Fi password or usable of wireless card Kablosuz şifrenizi veya kablosuz kart kullanılabilirliğini onaylayın - + Confirm your Wi-Fi password Wi-Fi parolasını doğrula @@ -1596,7 +1601,7 @@ Ethernet Bağlantısı Hatası - + Conn Wifi Success Wi-Fi Bağlantısı Başarılı diff --git a/translations/kylin-nm_zh_CN.qm b/translations/kylin-nm_zh_CN.qm index d1e24682..b59b8452 100644 Binary files a/translations/kylin-nm_zh_CN.qm and b/translations/kylin-nm_zh_CN.qm differ diff --git a/translations/kylin-nm_zh_CN.ts b/translations/kylin-nm_zh_CN.ts index 94f027da..14e4da26 100644 --- a/translations/kylin-nm_zh_CN.ts +++ b/translations/kylin-nm_zh_CN.ts @@ -1482,12 +1482,17 @@ IP 未分配成功 - + + Connection timed out + 连接超时 + + + Confirm your Wi-Fi password or usable of wireless card 请确认Wi-Fi密码或无线设备 - + Confirm your Wi-Fi password 请再次确认Wi-Fi密码 @@ -1556,7 +1561,7 @@ 连接有线网络失败 - + Conn Wifi Success 连接无线网络成功