Skip to content

Commit

Permalink
Fix bug UI can not refresh after connect or disconnect network in mul…
Browse files Browse the repository at this point in the history
…tiple users system
  • Loading branch information
chenlelin committed Apr 15, 2020
1 parent 0e6b1da commit 4499bdf
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 29 deletions.
37 changes: 27 additions & 10 deletions src/backthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <QFile>
#include <QRegExp>
#include <QStandardPaths>

BackThread::BackThread(QObject *parent) : QObject(parent){
cmdConnWifi = new QProcess(this);
Expand All @@ -43,13 +44,17 @@ BackThread::~BackThread()

IFace* BackThread::execGetIface(){
IFace *iface = new IFace();
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f TYPE,DEVICE,STATE device > /tmp/kylin-nm-iface";

QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-iface";

QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f TYPE,DEVICE,STATE device > " + localPath;
Utils::m_system(cmd.toUtf8().data());

// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device' in function 'execGetIface' failed");}

QFile file("/tmp/kylin-nm-iface");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-iface!");
Expand Down Expand Up @@ -225,12 +230,15 @@ void BackThread::execConnLan(QString connName){
void BackThread::execConnWifiPWD(QString connName, QString password){
disConnLanOrWifi("wifi");

QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '" + connName + "' password '" + password + "' > /tmp/kylin-nm-btoutput";
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-btoutput";

QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '" + connName + "' password '" + password + "' > " + localPath;
Utils::m_system(cmdStr.toUtf8().data());
// int status = system(cmdStr.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'execConnWifiPWD' failed");}

QFile file("/tmp/kylin-nm-btoutput");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
syslog(LOG_DEBUG, "Can't open the file /tmp/kylin-nm-btoutput !");
qDebug()<<"Can't open the file /tmp/kylin-nm-btoutput !"<<endl;
Expand Down Expand Up @@ -290,12 +298,15 @@ void BackThread::on_readerror()
}

QString BackThread::getConnProp(QString connName){
QString cmd = "nmcli connection show '" + connName + "' > /tmp/kylin-nm-connprop";
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connprop";

QString cmd = "nmcli connection show '" + connName + "' > " + localPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'getConnProp' failed");}

QFile file("/tmp/kylin-nm-connprop");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connprop!");
qDebug()<<"Can't open the file /tmp/kylin-nm-connprop!"<<endl;
Expand Down Expand Up @@ -344,12 +355,15 @@ QString BackThread::getConnProp(QString connName){
}

bool BackThread::execChkWifiExist(QString connName){
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection show '" + connName + "' > /tmp/kylin-nm-chkwifiexist";
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-chkwifiexist";

QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection show '" + connName + "' > " + localPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'execChkWifiExist' failed");}

QFile file("/tmp/kylin-nm-chkwifiexist");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-chkwifiexist!");
Expand All @@ -366,12 +380,15 @@ bool BackThread::execChkWifiExist(QString connName){
}

QString BackThread::execChkLanWidth(QString ethName){
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';ethtool '" + ethName + "' | grep Speed > /tmp/kylin-nm-bandwidth";
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-bandwidth";

QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';ethtool '" + ethName + "' | grep Speed > " + localPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'ethtool' in function 'execChkLanWidth' failed");}

QFile file("/tmp/kylin-nm-bandwidth");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-bandwidth!");
Expand Down
10 changes: 7 additions & 3 deletions src/kylin-network-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,15 @@ conlist *kylin_network_get_conlist_info()
}

//获取当前活动网络连接
activecon *kylin_network_get_activecon_info()
activecon *kylin_network_get_activecon_info(char *path)
{
int status = system("nmcli connection show -active > /tmp/activecon.txt");
char *chr = "nmcli connection show -active > ";
char *cmd = (char *) malloc(strlen(chr) + strlen(path));
strcpy(cmd, chr);
strcat(cmd, path);
int status = system(cmd);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show -active' in function 'kylin_network_get_activecon_info' failed");}
char *filename="/tmp/activecon.txt";
char *filename = path;

FILE *activefp;
int activenum=0;
Expand Down
3 changes: 2 additions & 1 deletion src/kylin-network-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <malloc.h>
#include <string.h>
#include <unistd.h>
#include <string.h>

#ifdef __cplusplus
extern "C"{
Expand Down Expand Up @@ -72,7 +73,7 @@ conlist *kylin_network_get_conlist_info();
* Get the active network connection.
* return the struct pointer.
*/
activecon *kylin_network_get_activecon_info();
activecon *kylin_network_get_activecon_info(char *path);

/*
* Create a new Ethernet connection.
Expand Down
15 changes: 12 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,10 @@ void MainWindow::getActiveInfo()
QString actLanName = "--";
QString actWifiName = "--";

activecon *act = kylin_network_get_activecon_info();
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString lockPath = homePath.at(0) + "/.config/kylin-nm-activecon";

activecon *act = kylin_network_get_activecon_info(lockPath.toUtf8().data());
int index = 0;
while(act[index].con_name != NULL){
if(QString(act[index].type) == "ethernet"){
Expand Down Expand Up @@ -1391,7 +1394,10 @@ void MainWindow::getLanListDone(QStringList slist)

// 获取当前连接的lan name
QString actLanName = "--";
activecon *act = kylin_network_get_activecon_info();
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString lockPath = homePath.at(0) + "/.config/kylin-nm-activecon";

activecon *act = kylin_network_get_activecon_info(lockPath.toUtf8().data());
int index = 0;
while(act[index].con_name != NULL){
if(QString(act[index].type) == "ethernet"){
Expand Down Expand Up @@ -1523,7 +1529,10 @@ void MainWindow::loadWifiListDone(QStringList slist)

// 获取当前连接的wifi name
QString actWifiName = "--";
activecon *act = kylin_network_get_activecon_info();
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString lockPath = homePath.at(0) + "/.config/kylin-nm-activecon";

activecon *act = kylin_network_get_activecon_info(lockPath.toUtf8().data());
int index = 0;
while(act[index].con_name != NULL){
if(QString(act[index].type) == "wifi"){
Expand Down
22 changes: 16 additions & 6 deletions wireless-security/dlgconnhidwifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ DlgConnHidWifi::DlgConnHidWifi(int type, MainWindow *mainWindow, QWidget *parent
ui->btnConnect->setText(tr("Connect")); //连接

ui->cbxConn->addItem(tr("C_reate…")); //新建...
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow";
QString cmd = "nmcli connection show>" + localPath;
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifi' failed");}
QFile file("/tmp/kylin-nm-connshow");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
Expand Down Expand Up @@ -195,10 +198,13 @@ void DlgConnHidWifi::changeWindow(){
ui->cbxSecurity->setEnabled(true);
ui->btnConnect->setEnabled(false);
}else if (ui->cbxConn->currentIndex() >= 1){
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >/tmp/kylin-nm-connshow";
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow";

QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >" + localPath;
int status = system(currStr.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'changeWindow' failed");}
QFile file("/tmp/kylin-nm-connshow");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
Expand Down Expand Up @@ -243,11 +249,15 @@ void DlgConnHidWifi::on_btnConnect_clicked()
int x = 0;
do{
sleep(1);
QString cmd = "nmcli device wifi connect " + wifiName + " password '' hidden yes >/tmp/kylin-nm-btoutput";

QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-btoutput";

QString cmd = "nmcli device wifi connect " + wifiName + " password '' hidden yes > " + localPath;
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_btnConnect_clicked' failed");}

QFile file("/tmp/kylin-nm-btoutput");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug()<<"Can't open the file!"<<endl;
Expand Down
22 changes: 16 additions & 6 deletions wireless-security/dlgconnhidwifiwpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ DlgConnHidWifiWpa::DlgConnHidWifiWpa(int type, MainWindow *mainWindow, QWidget *
ui->btnConnect->setText(tr("Connect")); //连接

ui->cbxConn->addItem(tr("C_reate…")); //新建...
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow";
QString cmd = "nmcli connection show> " + localPath;
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiWpa' failed");}
QFile file("/tmp/kylin-nm-connshow");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
Expand Down Expand Up @@ -202,10 +205,13 @@ void DlgConnHidWifiWpa::changeWindow(){
connHidWifi->show();
connect(connHidWifi, SIGNAL(reSetWifiList() ), mw, SLOT(on_btnWifiList_clicked()) );
}else if (ui->cbxConn->currentIndex() >= 1){
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >/tmp/kylin-nm-connshow";
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow";

QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " > " + localPath;
int status = system(currStr.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'changeWindow' failed");}
QFile file("/tmp/kylin-nm-connshow");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
Expand Down Expand Up @@ -254,11 +260,15 @@ void DlgConnHidWifiWpa::on_btnConnect_clicked()
int x = 0;
do{
sleep(1);
QString cmd = "nmcli device wifi connect " + wifiName + " password " + wifiPassword + " hidden yes >/tmp/kylin-nm-btoutput";

QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-btoutput";

QString cmd = "nmcli device wifi connect " + wifiName + " password " + wifiPassword + " hidden yes > " + localPath;
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_btnConnect_clicked' failed");}

QFile file("/tmp/kylin-nm-btoutput");
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug()<<"Can't open the file!"<<endl;
Expand Down

0 comments on commit 4499bdf

Please sign in to comment.