有线网络名称保存时会自动去除前后的空格,无法输入仅为空格的有线网络名称。修复shell的引号问题。降低连接一个不存在的wifi连接时可能会崩溃的问题。

This commit is contained in:
lvhan 2021-03-23 14:57:21 +08:00
parent 0351e91d9e
commit b7b1be7ca2
11 changed files with 55 additions and 84 deletions

View File

@ -94,9 +94,9 @@ void DlgHotspotCreate::on_btnOk_clicked()
//example: nmcli device wifi hotspot ifname wlan0 con-name MyHostspot ssid MyHostspotSSID password 12345678
QString str;
if(ui->cbxSecurity->currentIndex() == 0 ){
str = "nmcli device wifi hotspot ifname " + wirelessCardName + " con-name " + ui->leNetName->text() + " ssid " + ui->leNetName->text() + "SSID";
str = "nmcli device wifi hotspot ifname '" + wirelessCardName + "' con-name '" + ui->leNetName->text() + "' ssid '" + ui->leNetName->text() + "' SSID";
}else{
str = "nmcli device wifi hotspot ifname " + wirelessCardName + " con-name " + ui->leNetName->text() + " ssid " + ui->leNetName->text() + " password " + ui->lePassword->text();
str = "nmcli device wifi hotspot ifname '" + wirelessCardName + "' con-name '" + ui->leNetName->text() + "' ssid '" + ui->leNetName->text() + "' password '" + ui->lePassword->text() + "'";
}
Utils::m_system(str.toUtf8().data());

View File

@ -80,7 +80,7 @@ ConfForm::ConfForm(QWidget *parent) :
ui->leAddr_ipv6->setContextMenuPolicy(Qt::NoContextMenu);
//设置网络名称的正则表达式
ui->leName->setValidator(new QRegExpValidator(QRegExp("[^ \s]*"), ui->leName));
// ui->leName->setValidator(new QRegExpValidator(QRegExp("[^ \s]*"), ui->leName));
ui->lineUp->setStyleSheet(lineQss);
ui->lineDown->setStyleSheet(lineQss);
@ -258,11 +258,12 @@ void ConfForm::on_btnCreate_clicked()
return;
}
}
QString name = ui->leName->text().trimmed();
QString cmdStr;
if(ui->cbType->currentIndex() == 0){
cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet";
}else{
cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet ipv4.method manual ipv4.address "
cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet ipv4.method manual ipv4.address "
+ ui->leAddr->text() + "/" + mask.toUtf8().data();
if(!ui->leGateway->text().isEmpty()){
cmdStr += " ipv4.gateway " + ui->leGateway->text();
@ -287,22 +288,11 @@ void ConfForm::on_btnCreate_clicked()
kylindbus.showDesktopNotify(txt);
}
QString name = ui->leName->text();
QStringList charToEscape;
charToEscape << "~" << "(" << ")" << "<" << ">" <<"\\" << "*" << "|" << "&" << "#"; //一些命令行特殊字符,需要转义
foreach (auto ch , charToEscape) {
if (name.contains(ch)) {
name.replace(ch, QString("%1%2").arg("\\").arg(ch));
}
}
if (name.contains(" ")) { //空格会影响命令行参数的判断,需要转义
name.replace(QRegExp("[\\s]"), "\\\ ");
}
if (!ui->leAddr_ipv6->text().isEmpty()) {
QString cmdStr = "nmcli connection modify " + name + " ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
Utils::m_system(cmdStr.toUtf8().data());
} else {
QString cmdStr = "nmcli connection modify " + name + " ipv6.method auto";
QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method auto";
Utils::m_system(cmdStr.toUtf8().data());
}
@ -342,22 +332,19 @@ void ConfForm::on_btnSave_clicked()
}
//如果网络的名称已经修改,则删掉当前网络,新建一个网络
if (ui->leName->text() != lastConnName) {
QString name = ui->leName->text().trimmed();
if (name != lastConnName) {
QString cmd = "nmcli connection delete '" + netUuid + "'";
int status = system(cmd.toUtf8().data());
if (status != 0) {
syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'on_btnSave_clicked' failed");
}
//this->hide();
//QString cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
//Utils::m_system(cmdStr.toUtf8().data());
this->isCreateNewNet = true;
newUuid = "--";
QProcess * processAdd = new QProcess;
QString cmdAdd = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
QString cmdAdd = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet";
QStringList options;
options << "-c" << cmdAdd;
processAdd->start("/bin/bash",options);
@ -398,10 +385,10 @@ void ConfForm::on_btnSave_clicked()
if (ui->cbType->currentIndex() == 1) {
//对于已保存连接修改ipv6地址使用UUID区分各网络配置排除名称含空格或特殊字符的干扰
if (!ui->leAddr_ipv6->text().isEmpty()) {
QString cmdStr = "nmcli connection modify " + netUuid + " ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
QString cmdStr = "nmcli connection modify '" + netUuid + "' ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
Utils::m_system(cmdStr.toUtf8().data());
} else {
QString cmdStr = "nmcli connection modify " + netUuid + " ipv6.method auto";
QString cmdStr = "nmcli connection modify '" + netUuid + "' ipv6.method auto";
Utils::m_system(cmdStr.toUtf8().data());
}
}
@ -427,10 +414,11 @@ void ConfForm::saveNetworkConfiguration()
mask = "24";
}
QString name = ui->leName->text().trimmed();
//是选择的自动还是手动配置网络
if (!this->isCreateNewNet) {
if (ui->cbType->currentIndex() == 0) {
//kylin_network_set_automethod(ui->leName->text().toUtf8().data());
//kylin_network_set_automethod(name.toUtf8().data());
kylin_network_set_automethod(netUuid.toUtf8().data());
}
} else {
@ -443,7 +431,7 @@ void ConfForm::saveNetworkConfiguration()
if (newUuid != "--") {
kylin_network_set_manualall(newUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
} else {
kylin_network_set_manualall(ui->leName->text().toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
kylin_network_set_manualall(name.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
}
} else {
kylin_network_set_manualall(netUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
@ -625,7 +613,7 @@ void ConfForm::setEnableOfBtn()
// this->setBtnEnableFalse();
// return;
// }
if (ui->leName->text().size() == 0 ) {
if (ui->leName->text().trimmed().size() == 0 ) {
this->setBtnEnableFalse();
return;
}

View File

@ -778,7 +778,7 @@ void KylinDBus::toCreateNewLan()
int i = 1;
if (multiWiredIfName.size() != 0) {
foreach (QString strIfName, multiWiredIfName) {
QString cmdStr = "nmcli connection add con-name '有线连接" + QString::number(i,10) + "' ifname '" + strIfName + "' type ethernet";
QString cmdStr = "nmcli connection add con-name '有线连接 " + QString::number(i,10) + "' ifname '" + strIfName + "' type ethernet";
Utils::m_system(cmdStr.toUtf8().data());
i += 1;
}

View File

@ -15,7 +15,6 @@
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#include "kylin-network-interface.h"
#include <netinet/in.h>
@ -30,7 +29,6 @@
#include <sys/syslog.h>
#include <pwd.h>
//获取网络接口名
ifname *kylin_network_get_ifacename()
{
@ -354,7 +352,7 @@ void kylin_network_create_new_wifi(char *con_name, char *if_name)
void kylin_network_del_ethernet_con(char *con_name)
{
char str[256];
sprintf(str,"nmcli connection delete %s",con_name);
sprintf(str,"nmcli connection delete '%s'",con_name);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'kylin_network_del_ethernet_con' failed");}
}
@ -380,7 +378,8 @@ void kylin_network_set_manualmethod(char *con_name,char *ip)
}
// 设置手动分配all
void kylin_network_set_manualall(char *con_name, char *addr, char *mask, char *gateway, char *dns){
void kylin_network_set_manualall(char *con_name, char *addr, char *mask, char *gateway, char *dns)
{
char str[200];
sprintf(str, "nmcli connection modify '%s' ipv4.method manual ipv4.address %s/%s ipv4.gateway %s ipv4.dns %s",
con_name, addr, mask, gateway, dns);
@ -395,11 +394,11 @@ void kylin_network_set_autoconnect(char *con_name,bool autocon)
if(autocon==false)
{
char *ac="no";
sprintf(str,"nmcli connection modify %s connection.autoconnect %s",con_name,ac);
sprintf(str,"nmcli connection modify '%s' connection.autoconnect %s",con_name,ac);
}
else{
char *ac="yes";
sprintf(str,"nmcli connection modify %s connection.autoconnect %s",con_name,ac);
sprintf(str,"nmcli connection modify '%s' connection.autoconnect %s",con_name,ac);
}
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_autoconnect' failed");}
@ -409,7 +408,7 @@ void kylin_network_set_autoconnect(char *con_name,bool autocon)
void kylin_network_mod_ip(char *con_name,char *ip)
{
char str[256];
sprintf(str,"nmcli connection modify %s ipv4.address %s",con_name,ip);
sprintf(str,"nmcli connection modify '%s' ipv4.address %s",con_name,ip);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_mod_ip' failed");}
}
@ -418,7 +417,7 @@ void kylin_network_mod_ip(char *con_name,char *ip)
void kylin_network_mod_gateway(char *con_name,char *gw)
{
char str[256];
sprintf(str,"nmcli connection modify %s ipv4.gateway %s",con_name,gw);
sprintf(str,"nmcli connection modify '%s' ipv4.gateway %s",con_name,gw);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_mod_gateway' failed");}
}
@ -427,7 +426,7 @@ void kylin_network_mod_gateway(char *con_name,char *gw)
void kylin_network_mod_dns(char *con_name,char *dns)
{
char str[256];
sprintf(str,"nmcli connection modify %s ipv4.dns %s",con_name,dns);
sprintf(str,"nmcli connection modify '%s' ipv4.dns %s",con_name,dns);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_mod_dns' failed");}
}

View File

@ -1892,10 +1892,7 @@ void MainWindow::loadWifiListDone(QStringList slist)
} else {
QProcess * process = new QProcess;
QString name = actWifiName;
if (name.contains(" ")) {
name.replace(QRegExp("[\\s]"), "\\\ "); //防止名字包含空格导致指令识别错误,需要转义
}
process->start(QString("nmcli -f 802-11-wireless.ssid connection show %1").arg(name));
process->start(QString("nmcli -f 802-11-wireless.ssid connection show '%1'").arg(name));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});

View File

@ -584,7 +584,7 @@ void OneConnForm::toConnectWirelessNetwork()
//有配置文件需要判断一下当前配置文件wifi安全性是不是wpa-eap若是需要把原配置文件删除重新配置
QProcess * process = new QProcess(this);
process->start(QString("nmcli -f 802-11-wireless-security.key-mgmt connection show %1").arg(wifiName));
process->start(QString("nmcli -f 802-11-wireless-security.key-mgmt connection show '%1'").arg(wifiName));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});
@ -595,7 +595,7 @@ void OneConnForm::toConnectWirelessNetwork()
process->waitForFinished();
if (QString::compare(key_mgmt, "wpa-eap") == 0) {
//原配置文件是企业wifi删掉请求输入新的密码
QString cmdStr = "nmcli connection delete " + wifiName;
QString cmdStr = "nmcli connection delete '" + wifiName + "'";
Utils::m_system(cmdStr.toUtf8().data());
psk_flag = 0;
slotConnWifiResult(2); //现在已无配置文件,申请输入密码
@ -605,11 +605,7 @@ void OneConnForm::toConnectWirelessNetwork()
if (isWifiConfExist(wifiName)) {
//有配置文件,获取密码存储策略
QProcess * process = new QProcess(this);
QString ssid = wifiName;
if (ssid.contains(" ")) {
ssid.replace(QRegExp("[\\s]"), "\\\ "); //防止名字包含空格导致指令识别错误,需要转义
}
process->start(QString("nmcli -f 802-11-wireless-security.psk-flags connection show %1").arg(wifiName));
process->start(QString("nmcli -f 802-11-wireless-security.psk-flags connection show '%1'").arg(wifiName));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});
@ -657,7 +653,7 @@ void OneConnForm::toConnectWirelessNetwork()
connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
connect(t, &QThread::started, this, [ = ]() {
this->startWaiting(true);
QString cmdStr = "nmcli connection up " + wifiName + " passwd-file " + homePath +"/.config/" + wifiName + ".psk";
QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk";
emit this->sigConnWifiPsk(cmdStr);
});
connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString)));
@ -715,7 +711,7 @@ void OneConnForm::on_btnConnPWD_clicked()
connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
connect(t, &QThread::started, this, [ = ]() {
this->startWaiting(true);
QString cmdStr = "nmcli connection up " + wifiName + " passwd-file " + homePath +"/.config/" + wifiName + ".psk";
QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk";
emit this->sigConnWifiPsk(cmdStr);
});
connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString)));
@ -1027,11 +1023,7 @@ void OneConnForm::on_btnCancel_clicked()
int OneConnForm::getPskFlag()
{
QProcess * process = new QProcess(this);
QString ssid = wifiName;
if (ssid.contains(" ")) {
ssid.replace(QRegExp("[\\s]"), "\\\ "); //防止名字包含空格导致指令识别错误,需要转义
}
process->start(QString("nmcli -f 802-11-wireless-security.psk-flags connection show %1").arg(wifiName));
process->start(QString("nmcli -f 802-11-wireless-security.psk-flags connection show '%1'").arg(wifiName));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});

View File

@ -48,9 +48,9 @@ void UpConnThread::run() {
if (passwdFile->open(QIODevice::ReadWrite)) {
passwdFile->write(QString("802-1x.identity:%1\n802-1x.password:%2").arg(m_user).arg(m_pwd).toUtf8());
passwdFile->close();
cmdStr = "nmcli connection up " + this->conn_name + " passwd-file /tmp/" + conn_name + ".txt";
cmdStr = "nmcli connection up '" + this->conn_name + "' passwd-file /tmp/" + conn_name + ".txt";
} else {
cmdStr = "nmcli connection up " + this->conn_name;
cmdStr = "nmcli connection up '" + this->conn_name + "'";
}
qDebug()<<"qDebug: 激活连接: \n"<<
"qDebug: " + cmdStr;
@ -361,10 +361,7 @@ void WpaWifiDialog::changeDialog()
void WpaWifiDialog::getPwdFlag() {
QProcess * process = new QProcess(this);
QString ssid = nameEditor->text();
if (ssid.contains(" ")) {
ssid.replace(QRegExp("[\\s]"), "\\\ "); //防止名字包含空格导致指令识别错误,需要转义
}
process->start(QString("nmcli -f 802-1x.password-flags connection show %1").arg(ssid));
process->start(QString("nmcli -f 802-1x.password-flags connection show '%1'").arg(ssid));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});
@ -383,10 +380,7 @@ void WpaWifiDialog::getPwdFlag() {
bool WpaWifiDialog::setPwdFlag(const int & flag) {
QProcess * process = new QProcess;
QString ssid = nameEditor->text();
if (ssid.contains(" ")) {
ssid.replace(QRegExp("[\\s]"), "\\\ "); //防止名字包含空格导致指令识别错误,需要转义
}
process->start(QString("nmcli connection modify %1 802-1x.password-flags %2").arg(ssid).arg(QString::number(flag)));
process->start(QString("nmcli connection modify '%1' 802-1x.password-flags %2").arg(ssid).arg(QString::number(flag)));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});
@ -439,7 +433,7 @@ void WpaWifiDialog::slot_on_connectBtn_clicked() {
has_config = true;
}
// QString cmdStr = "nmcli connection modify " + nameEditor->text() + " 802-1x.password " + pwdEditor->text();
QString cmdStr = "nmcli connection modify " + nameEditor->text() + " ipv4.method auto";
QString cmdStr = "nmcli connection modify '" + nameEditor->text() + "' ipv4.method auto";
int res = Utils::m_system(cmdStr.toUtf8().data());
if (res == 0) {
//有配置文件需要判断一下当前配置文件wifi安全性是不是wpa-eap若不是需要把原配置文件删除重新配置
@ -462,9 +456,9 @@ void WpaWifiDialog::slot_on_connectBtn_clicked() {
process->waitForFinished();
//有网络配置文件,接下来修改网络配置,然后激活连接
qDebug()<<"qDebug: 有配置文件,修改配置后激活:"<<"\n"<<
"qDebug: nmcli connection modify " + nameEditor->text() + " 802-1x.eap " + eapCombox->currentData().toString() + " 802-1x.phase2-auth "
"qDebug: nmcli connection modify '" + nameEditor->text() + "' 802-1x.eap " + eapCombox->currentData().toString() + " 802-1x.phase2-auth "
+ innerCombox->currentData().toString() + " 802-1x.identity " + userEditor->text() + " 802-1x.password " + pwdEditor->text();
QString cmdStr_1 = "nmcli connection modify " + nameEditor->text() + " 802-1x.eap " + eapCombox->currentData().toString()+ " 802-1x.phase2-auth "
QString cmdStr_1 = "nmcli connection modify '" + nameEditor->text() + "' 802-1x.eap " + eapCombox->currentData().toString()+ " 802-1x.phase2-auth "
+ innerCombox->currentData().toString() + " 802-1x.identity " + userEditor->text() + " 802-1x.password " + pwdEditor->text();
Utils::m_system(cmdStr_1.toUtf8().data());
if (askPwdBtn->isChecked()) setPwdFlag(2);
@ -485,7 +479,7 @@ void WpaWifiDialog::slot_on_connectBtn_clicked() {
"qDebug: 802-1x.identity: "<<userEditor->text()<<"\n"<<
"qDebug: 802-1x.password: "<<pwdEditor->text();
QString create_cmd;
create_cmd = "nmcli connection add con-name " + nameEditor->text() + " ifname "
create_cmd = "nmcli connection add con-name '" + nameEditor->text() + "' ifname "
+ wifi_card_name + " ipv4.method auto type wifi ssid " + nameEditor->text()
+ " 802-1x.eap " + eapCombox->currentData().toString() + " 802-1x.phase2-auth "
+ innerCombox->currentData().toString() + " 802-1x.identity "
@ -533,7 +527,7 @@ void WpaWifiDialog::activateConnection() {
//连接超时
timeout->stop();
timeout->deleteLater();
QString cmdStr_2 = "nmcli connection down " + nameEditor->text();
QString cmdStr_2 = "nmcli connection down '" + nameEditor->text() + "'";
Utils::m_system(cmdStr_2.toUtf8().data());
//this->mw->is_stop_check_net_state = 0;
//this->mw->setTrayLoading(false);

View File

@ -208,7 +208,7 @@ void DlgHideWifi::changeWindow(){
ui->btnConnect->setEnabled(false);
}else if (ui->cbxConn->currentIndex() >= 1){
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName();
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >" + tmpPath;
QString currStr = "nmcli connection show '" + ui->cbxConn->currentText() + "' >" + tmpPath;
int status = system(currStr.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'changeWindow' failed");}
@ -291,7 +291,7 @@ void DlgHideWifi::on_btnConnect_clicked()
do {
sleep(1);
QString tmpPath = "/tmp/kylin-nm-btoutput-" + QDir::home().dirName();
QString cmd = "nmcli device wifi connect " + wifiName + " password '' hidden yes > " + tmpPath;
QString cmd = "nmcli device wifi connect '" + wifiName + "' password '' hidden yes > " + tmpPath;
int status = system(cmd.toUtf8().data());
if (status != 0)
@ -340,7 +340,7 @@ void DlgHideWifi::slotStartLoading()
void DlgHideWifi::on_execSecConn()
{
QString str = "nmcli device wifi connect " + strWifiname + " password ''";
QString str = "nmcli device wifi connect '" + strWifiname + "' password ''";
int status = system(str.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_execSecConn' failed");}
QTimer::singleShot(3*1000, this, SLOT(emitSignal() ));

View File

@ -270,7 +270,7 @@ void DlgHideWifiEapPeap::changeWindow(){
connect(connHidWifi, SIGNAL(reSetWifiList() ), mw, SLOT(on_btnWifiList_clicked()) );
} else if (ui->cbxConn->currentIndex() >= 1) {
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName();
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " > " + tmpPath;
QString currStr = "nmcli connection show '" + ui->cbxConn->currentText() + "' > " + tmpPath;
int status = system(currStr.toUtf8().data());
if(status != 0){

View File

@ -259,7 +259,7 @@ void DlgHideWifiEapTls::changeWindow(){
connect(connHidWifi, SIGNAL(reSetWifiList() ), mw, SLOT(on_btnWifiList_clicked()) );
}else if (ui->cbxConn->currentIndex() >= 1){
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName();
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >" + tmpPath;
QString currStr = "nmcli connection show '" + ui->cbxConn->currentText() + "' >" + tmpPath;
int status = system(currStr.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'changeWindow' failed");}

View File

@ -215,7 +215,7 @@ void DlgHideWifiWpa::changeWindow()
connect(connHidWifi, SIGNAL(reSetWifiList() ), mw, SLOT(on_btnWifiList_clicked()) );
}else if (ui->cbxConn->currentIndex() >= 1){
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName();
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " > " + tmpPath;
QString currStr = "nmcli connection show '" + ui->cbxConn->currentText() + "' > " + tmpPath;
int status = system(currStr.toUtf8().data());
if(status != 0){
@ -313,8 +313,9 @@ void DlgHideWifiWpa::on_btnConnect_clicked()
}
QString tmpPath = "/tmp/kylin-nm-btoutput-" + QDir::home().dirName();
QString cmd = "nmcli device wifi connect " + wifiName + " password " + wifiPassword + " hidden yes > " + tmpPath + " 2>&1";
QString cmd = "nmcli device wifi connect '" + wifiName + "' password '" + wifiPassword + "' hidden yes > " + tmpPath + " 2>&1";
// qDebug() << Q_FUNC_INFO << cmd << tmpPath;
int status = system(cmd.toUtf8().data());
if (status != 0) {
syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_btnConnect_clicked' failed");
@ -327,12 +328,12 @@ void DlgHideWifiWpa::on_btnConnect_clicked()
QString text = file.readAll();
file.close();
if(text.indexOf("Scanning not allowed") != -1 || text.isEmpty()){x = 1;} else { x = 0;}
// qDebug() << Q_FUNC_INFO << x << text;
} while (x == 1);
emit this->stopSignal();
emit reSetWifiList();
//mw->stopLoading();
//QTimer::singleShot(8*1000, this, SLOT(on_execSecConn() ));
//屏蔽下面两行可以大大减小崩溃的概率
// emit reSetWifiList();
// emit stopSignal();
});
} else {
shellProcess = new QProcess(this);
@ -409,7 +410,7 @@ void DlgHideWifiWpa::slotStartLoading()
void DlgHideWifiWpa::on_execSecConn()
{
QString str = "nmcli device wifi connect " + strWifiname + " password " + strWifiPassword;
QString str = "nmcli device wifi connect '" + strWifiname + "' password '" + strWifiPassword + "'";
int status = system(str.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_execSecConn' failed");}
qDebug() << "debug: 准备等待7秒";