Fix bug program exit when select and click hotpot wifi in add hidden wifi window

This commit is contained in:
chenlelin 2021-02-06 09:15:20 +08:00
parent 041616e259
commit f0fc60682a
4 changed files with 42 additions and 34 deletions

View File

@ -640,6 +640,39 @@ int KylinDBus::getWiredNetworkNumber()
return wiredNetworkNumber; return wiredNetworkNumber;
} }
QStringList KylinDBus::getWifiSsidList()
{
QStringList wifiSsidList;
QDBusInterface m_interface("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager/Settings",
"org.freedesktop.NetworkManager.Settings",
QDBusConnection::systemBus() );
QDBusReply<QList<QDBusObjectPath>> m_reply = m_interface.call("ListConnections");
QDBusObjectPath specific_connection;
specific_connection.setPath("/");
QList<QDBusObjectPath> m_objSettingPaths = m_reply.value();
foreach (QDBusObjectPath objSettingPath, m_objSettingPaths) {
QDBusInterface m_interface("org.freedesktop.NetworkManager",
objSettingPath.path(),
"org.freedesktop.NetworkManager.Settings.Connection",
QDBusConnection::systemBus());
QDBusMessage result = m_interface.call("GetSettings");
const QDBusArgument &dbusArg1st = result.arguments().at( 0 ).value<QDBusArgument>();
QMap<QString,QMap<QString,QVariant>> map;
dbusArg1st >> map;
if (map.value("802-11-wireless").value("mode").toString() == "infrastructure") {
wifiSsidList.append(map.value("connection").value("id").toString());
}
}
return wifiSsidList;
}
void KylinDBus::toCreateNewLan() void KylinDBus::toCreateNewLan()
{ {
int i = 1; int i = 1;

View File

@ -48,6 +48,7 @@ public:
void getObjectPath(); void getObjectPath();
int getAccessPointsNumber(); int getAccessPointsNumber();
int getWiredNetworkNumber(); int getWiredNetworkNumber();
QStringList getWifiSsidList();
void showDesktopNotify(QString message); void showDesktopNotify(QString message);
void initConnectionInfo(); void initConnectionInfo();
QList<QString> getAtiveLanSsidUuid(); QList<QString> getAtiveLanSsidUuid();

View File

@ -66,22 +66,10 @@ DlgHideWifi::DlgHideWifi(int type, MainWindow *mainWindow, QWidget *parent) :
ui->btnConnect->setText(tr("Connect")); //连接 ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建... ui->cbxConn->addItem(tr("C_reate…")); //新建...
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName(); KylinDBus mkylindbus;
QString cmd = "nmcli connection show>" + tmpPath; QStringList wifiList = mkylindbus.getWifiSsidList();
int status = system(cmd.toUtf8().data()); foreach (QString strWifiSsid, wifiList) {
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgHideWifi' failed");} ui->cbxConn->addItem(strWifiSsid);
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
QString txt = file.readAll();
QStringList txtLine = txt.split("\n");
file.close();
foreach (QString line, txtLine) {
if (line.indexOf("wifi") != -1 || line.indexOf("802-11-wireless") != -1) {
QStringList subLine = line.split(" ");
ui->cbxConn->addItem(subLine[0]);
}
} }
ui->cbxConn->setCurrentIndex(0); ui->cbxConn->setCurrentIndex(0);
connect(ui->cbxConn,SIGNAL(currentIndexChanged(QString)),this,SLOT(changeWindow())); connect(ui->cbxConn,SIGNAL(currentIndexChanged(QString)),this,SLOT(changeWindow()));

View File

@ -72,24 +72,10 @@ DlgHideWifiWpa::DlgHideWifiWpa(int type, MainWindow *mainWindow, QWidget *parent
ui->btnConnect->setText(tr("Connect")); //连接 ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建... ui->cbxConn->addItem(tr("C_reate…")); //新建...
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName(); KylinDBus mkylindbus;
QString cmd = "nmcli connection show > " + tmpPath; QStringList wifiList = mkylindbus.getWifiSsidList();
int status = system(cmd.toUtf8().data()); foreach (QString strWifiSsid, wifiList) {
if (status != 0) { ui->cbxConn->addItem(strWifiSsid);
syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgHideWifiWpa' failed");
}
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
QString txt = file.readAll();
QStringList txtLine = txt.split("\n");
file.close();
foreach (QString line, txtLine) {
if (line.indexOf("wifi") != -1 || line.indexOf("802-11-wireless") != -1) {
QStringList subLine = line.split(" ");
ui->cbxConn->addItem(subLine[0]);
}
} }
ui->cbxConn->setCurrentIndex(0); ui->cbxConn->setCurrentIndex(0);
connect(ui->cbxConn,SIGNAL(currentIndexChanged(QString)),this,SLOT(changeWindow())); connect(ui->cbxConn,SIGNAL(currentIndexChanged(QString)),this,SLOT(changeWindow()));