Merge pull request #1 from ukui/master

Keep up to date with the main repository
This commit is contained in:
Andrew Pit 2021-03-05 16:16:45 +08:00 committed by GitHub
commit 95ef65f97e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 119 additions and 48 deletions

View File

@ -77,6 +77,7 @@ ConfForm::ConfForm(QWidget *parent) :
ui->leDns->setContextMenuPolicy(Qt::NoContextMenu);
ui->leDns2->setContextMenuPolicy(Qt::NoContextMenu);
ui->leGateway->setContextMenuPolicy(Qt::NoContextMenu);
ui->leAddr_ipv6->setContextMenuPolicy(Qt::NoContextMenu);
ui->lineUp->setStyleSheet(lineQss);
ui->lineDown->setStyleSheet(lineQss);
@ -171,6 +172,7 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
lastIpv4 = v4addr;
netUuid = uuidName;
isActWifi = false;
if (isWiFi) {
ui->leName->setEnabled(false);
isActWifi = isWiFi;
@ -253,11 +255,22 @@ 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 " + ui->leName->text() + " 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 " + ui->leName->text() + " ipv6.method auto";
QString cmdStr = "nmcli connection modify " + name + " ipv6.method auto";
Utils::m_system(cmdStr.toUtf8().data());
}
@ -351,15 +364,15 @@ void ConfForm::on_btnSave_clicked()
}
if (ui->cbType->currentIndex() == 1) {
//对于已保存连接修改ipv6地址使用UUID区分各网络配置排除名称含空格或特殊字符的干扰
if (!ui->leAddr_ipv6->text().isEmpty()) {
QString cmdStr = "nmcli connection modify " + ui->leName->text() + " 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 " + ui->leName->text() + " ipv6.method auto";
QString cmdStr = "nmcli connection modify " + netUuid + " ipv6.method auto";
Utils::m_system(cmdStr.toUtf8().data());
}
}
QString txt(tr("New network settings already finished"));
kylindbus.showDesktopNotify(txt);
}

View File

@ -369,6 +369,8 @@ void KylinDBus::getLanIpDNS(QString uuidName, bool isActNet)
dbusArg2nd.endArray();
dbusLanIpv6 = m_map.value("address").toString();
} else if (inner_key == "method") {
dbusLanIpv6Method = innerMap.value(inner_key).toString();
}
}
}
@ -1051,41 +1053,76 @@ QList<QString> KylinDBus::getAtiveWifiBSsidUuid(QStringList wifilist)
QDBusReply<QVariant> replyUuid = interfaceInfo.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Uuid");
//qDebug() << "wifi uuid : "<< replyUuid.value().toString();
strBSsidUuid.append(replyUuid.value().toString());
//再获取bssid
QDBusMessage resultConnection = interfaceInfo.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Connection");
QList<QVariant> outArgsConnection = resultConnection.arguments();
QVariant firstConnection = outArgsConnection.at(0);
QDBusVariant dbvFirstConnection = firstConnection.value<QDBusVariant>();
QVariant vFirstConnection = dbvFirstConnection.variant();
QDBusObjectPath dbusArgsConnection = vFirstConnection.value<QDBusObjectPath>();
QDBusInterface interfaceSet("org.freedesktop.NetworkManager",
dbusArgsConnection.path(),
"org.freedesktop.NetworkManager.Settings.Connection",
QDBusConnection::systemBus());
QDBusMessage resultSet = interfaceSet.call("GetSettings");
const QDBusArgument &dbusArg1stSet = resultSet.arguments().at( 0 ).value<QDBusArgument>();
QMap<QString,QMap<QString,QVariant>> mapSet;
dbusArg1stSet >> mapSet;
for (QString setKey : mapSet.keys() ) {
QMap<QString,QVariant> subSetMap = mapSet.value(setKey);
if (setKey == "802-11-wireless") {
for (QString searchKey : subSetMap.keys()) {
if (searchKey == "seen-bssids") {
//qDebug() << "wifi bssid : "<<subSetMap.value(searchKey).toStringList();
QStringList strBssidList = subSetMap.value(searchKey).toStringList();
foreach (QString strBssid, strBssidList) {
strBSsidUuid.append(strBssid);
}
}
}
}
}
}
}
dbusArgs.endArray();
//获取已经连接wifi的bssid
if (wifilist.size() != 0) {
// 填充可用网络列表
QString headLine = wifilist.at(0);
int indexSignal,indexSecu, indexFreq, indexBSsid, indexName;
headLine = headLine.trimmed();
// //获取已经连接wifi的bssid
// if (wifilist.size() != 0) {
// // 填充可用网络列表
// QString headLine = wifilist.at(0);
// int indexSignal,indexSecu, indexFreq, indexBSsid, indexName;
// headLine = headLine.trimmed();
bool isChineseExist = headLine.contains(QRegExp("[\\x4e00-\\x9fa5]+"));
if (isChineseExist) {
indexSignal = headLine.indexOf("SIGNAL");
indexSecu = headLine.indexOf("安全性");
indexFreq = headLine.indexOf("频率") + 4;
indexBSsid = headLine.indexOf("BSSID") + 6;
indexName = indexBSsid + 19;
} else {
indexSignal = headLine.indexOf("SIGNAL");
indexSecu = headLine.indexOf("SECURITY");
indexFreq = headLine.indexOf("FREQ");
indexBSsid = headLine.indexOf("BSSID");
indexName = indexBSsid + 19;
}
// bool isChineseExist = headLine.contains(QRegExp("[\\x4e00-\\x9fa5]+"));
// if (isChineseExist) {
// indexSignal = headLine.indexOf("SIGNAL");
// indexSecu = headLine.indexOf("安全性");
// indexFreq = headLine.indexOf("频率") + 4;
// indexBSsid = headLine.indexOf("BSSID") + 6;
// indexName = indexBSsid + 19;
// } else {
// indexSignal = headLine.indexOf("SIGNAL");
// indexSecu = headLine.indexOf("SECURITY");
// indexFreq = headLine.indexOf("FREQ");
// indexBSsid = headLine.indexOf("BSSID");
// indexName = indexBSsid + 19;
// }
for (int i = 1, j = 0; i < wifilist.size(); i ++) {
QString line = wifilist.at(i);
QString winuse = line.mid(0, indexSignal).trimmed();
QString wbssid = line.mid(indexBSsid, 17).trimmed();
if (winuse == "*") {
strBSsidUuid.append(wbssid);
}
}
}
// for (int i = 1, j = 0; i < wifilist.size(); i ++) {
// QString line = wifilist.at(i);
// QString winuse = line.mid(0, indexSignal).trimmed();
// QString wbssid = line.mid(indexBSsid, 17).trimmed();
// if (winuse == "*") {
// strBSsidUuid.append(wbssid);
// }
// }
// }
return strBSsidUuid;
}

View File

@ -88,6 +88,7 @@ public:
QString dbusLanIpv4 = "";
QString dbusLanIpv6 = "";
QString dbusLanIpv6Method = "";
QString dbusActiveLanIpv4 = "";
QString dbusActiveLanIpv6 = "";
QString dbusLanGateway = "";

View File

@ -1603,6 +1603,9 @@ void MainWindow::getLanListDone(QStringList slist)
} else if ((oldActLanName == actLanSsidName.at(kk)) && (oldDbusActLanDNS != objKyDBus->dbusActLanDNS)) {
//在第三方nm-connection-editor进行新的DNS配置后重新连接网络
objKyDBus->reConnectWiredNet(nuuid);
} else if (!objKyDBus->dbusActiveLanIpv6.isEmpty() && objKyDBus->dbusActiveLanIpv6 != objKyDBus->dbusLanIpv6 && objKyDBus->dbusLanIpv6Method == "manual") {
//在第三方nm-connection-editor或kylin-nm配置页进行新的IPV6配置后重新连接网络
objKyDBus->reConnectWiredNet(nuuid);
}
}
@ -1830,25 +1833,27 @@ void MainWindow::loadWifiListDone(QStringList slist)
scrollAreaw->setWidget(wifiListWidget);
scrollAreaw->move(W_LEFT_AREA, Y_SCROLL_AREA);
// 获取当前有线网的连接状态正在连接wifiActState==1连接wifiActState==2, 未连接wifiActState==3
// 获取当前有线网的连接状态正在连接wifiActState==1连接wifiActState==2, 未连接wifiActState==3
int wifiActState = objKyDBus->checkWifiConnectivity(); //检查wifi的连接状态
if (isWifiBeConnUp && wifiActState == 1) {
wifiActState = 2;
}
// if (isWifiBeConnUp && wifiActState == 1) {
// wifiActState = 2;
// }
QList<QString> currConnWifiBSsidUuid;
bool isLoop = true;
do {
currConnWifiBSsidUuid = objKyDBus->getAtiveWifiBSsidUuid(slist);
if (currConnWifiBSsidUuid.size() == 1 && currConnWifiBSsidUuid.at(0).length() != 17) {
sleep(1); //等于1说明只获取到uuid1秒后再获取一次
} else {
isLoop = false;
}
} while (isLoop);
currConnWifiBSsidUuid = objKyDBus->getAtiveWifiBSsidUuid(slist);
// bool isLoop = true;
// do {
// currConnWifiBSsidUuid = objKyDBus->getAtiveWifiBSsidUuid(slist);
// if (currConnWifiBSsidUuid.size() == 1 && currConnWifiBSsidUuid.at(0).length() != 17) {
// sleep(1); //等于1说明只获取到uuid1秒后再获取一次
// } else {
// isLoop = false;
// }
// } while (isLoop);
// 获取当前连接的wifi name
QString actWifiName = "--";
QString actWifiId = "--";
actWifiSsid = "--";
actWifiUuid = "--";
if (currConnWifiBSsidUuid.size() > 1) {
@ -1874,7 +1879,7 @@ void MainWindow::loadWifiListDone(QStringList slist)
// 根据当前连接的wifi 设置OneConnForm
OneConnForm *ccf = new OneConnForm(topWifiListWidget, this, confForm, ksnm);
if (actWifiName == "--" || wifiActState == 1) {
if (actWifiName == "--" || wifiActState == 1 || actWifiBssidList.at(0) == "--") {
ccf->setName(tr("Not connected"), "--", "--");//"当前未连接任何 Wifi"
ccf->setSignal("0", "--");
activeWifiSignalLv = 0;
@ -1941,6 +1946,11 @@ void MainWindow::loadWifiListDone(QStringList slist)
}
}
if (actWifiBssidList.size()==1 && actWifiBssidList.at(0)=="--") {
actWifiId = actWifiName;
actWifiName = "--";
}
for (int i = 1, j = 0; i < slist.size(); i ++) {
QString line = slist.at(i);
QString wsignal = line.mid(indexSignal, 3).trimmed();
@ -2021,6 +2031,8 @@ void MainWindow::loadWifiListDone(QStringList slist)
if (actWifiBssidList.contains(wbssid) && wifiActState == 1) {
ocf->startWaiting(true);
} else if (actWifiId == wname && wifiActState == 1) {
ocf->startWaiting(true);
}
j ++;

View File

@ -429,6 +429,8 @@ void WpaWifiDialog::slot_line_edit_changed() {
void WpaWifiDialog::slot_on_connectBtn_clicked() {
qDebug()<<"Clicked on connect Btn!";
//this->mw->is_stop_check_net_state = 1;
//this->mw->setTrayLoading(true);
//写/tmp/wpaconfig.ini配置文件
if (has_config) {
appendWifiUser(nameEditor->text(), userEditor->text());
@ -533,6 +535,8 @@ void WpaWifiDialog::activateConnection() {
timeout->deleteLater();
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);
syslog(LOG_DEBUG, "execute 'nmcli connection up' in function 'activateConnection' time out");
qDebug() << "qDebug: activate time out!";
qDebug() << "qDebug: 连接超时30秒超时时间";
@ -546,6 +550,8 @@ void WpaWifiDialog::activateConnection() {
//连接错误或连接超时
setEditorEnable(true);
emit conn_failed();
//this->mw->is_stop_check_net_state = 0;
//this->mw->setTrayLoading(false);
} else {
//连接成功
timeout->stop();
@ -554,6 +560,8 @@ void WpaWifiDialog::activateConnection() {
upThread->wait();
upThread->deleteLater();
emit conn_done();
//this->mw->is_stop_check_net_state = 0;
//this->mw->setTrayLoading(false);
syslog(LOG_DEBUG, "execute 'nmcli connection up' in function 'activateConnection' accepted");
//qDebug() << "qDebug: activated wpa wifi successfully";
this->close();