add process to return value of system function,replace some system function.

This commit is contained in:
chenlelin 2020-03-19 10:55:40 +08:00
parent 588a7c998f
commit a91a75e5fe
28 changed files with 501 additions and 342 deletions

View File

@ -17,30 +17,37 @@
*/
#include "backthread.h"
#include "utils.h"
#include <unistd.h>
#include <stdlib.h>
#include <sys/syslog.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <QFile>
#include <QRegExp>
BackThread::BackThread(QObject *parent) : QObject(parent){
cmd = new QProcess(this);
connect(cmd , SIGNAL(readyReadStandardOutput()) , this , SLOT(on_readoutput()));
connect(cmd , SIGNAL(readyReadStandardError()) , this , SLOT(on_readerror()));
cmd->start("bash");
cmd->waitForStarted();
cmdConnWifi = new QProcess(this);
connect(cmdConnWifi , SIGNAL(readyReadStandardOutput()) , this , SLOT(on_readoutput()));
connect(cmdConnWifi , SIGNAL(readyReadStandardError()) , this , SLOT(on_readerror()));
cmdConnWifi->start("bash");
cmdConnWifi->waitForStarted();
}
BackThread::~BackThread()
{
cmd->close();
cmdConnWifi->close();
}
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";
system(cmd.toUtf8().data());
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");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
@ -98,7 +105,11 @@ IFace* BackThread::execGetIface(){
}
void BackThread::execEnNet(){
system("nmcli networking on");
char *chr = "nmcli networking on";
Utils::m_system(chr);
// int status = system("nmcli networking on");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli networking on' in function 'execEnNet' failed");}
while(1){
if (execGetIface()->lstate != 2){
sleep(3);
@ -112,7 +123,11 @@ void BackThread::execEnNet(){
void BackThread::execDisNet(){
if (execGetIface()->wstate != 2){
system("nmcli radio wifi off");
char *chr = "nmcli radio wifi off";
Utils::m_system(chr);
// int status = system("nmcli radio wifi off");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi off' in function 'execDisNet' failed");}
while(1){
if (execGetIface()->wstate == 2){
emit disWifiDone();
@ -122,7 +137,11 @@ void BackThread::execDisNet(){
sleep(1);
}
}
system("nmcli networking off");
char *chr1 = "nmcli networking off";
Utils::m_system(chr1);
// int status1 = system("nmcli networking off");
// if (status1 != 0){ syslog(LOG_ERR, "execute 'nmcli networking off' in function 'execDisNet' failed");}
while(1){
if (execGetIface()->lstate == 2){
emit disNetDone();
@ -135,7 +154,10 @@ void BackThread::execDisNet(){
void BackThread::execEnWifi(){
if (execGetIface()->lstate == 2){
system("nmcli networking on");
char *chr = "nmcli networking on";
Utils::m_system(chr);
// int status = system("nmcli networking on");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli networking on' in function 'execEnWifi' failed");}
while(1){
if (execGetIface()->lstate != 2){
emit launchLanDone();
@ -144,7 +166,11 @@ void BackThread::execEnWifi(){
sleep(1);
}
}
system("nmcli radio wifi on");
char *chr1 = "nmcli radio wifi on";
Utils::m_system(chr1);
// int status1 = system("nmcli radio wifi on");
// if (status1 != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi on' in function 'execEnWifi' failed");}
while(1){
if (execGetIface()->wstate != 2){
KylinDBus objKyDbus;
@ -163,7 +189,10 @@ void BackThread::execEnWifi(){
}
void BackThread::execDisWifi(){
system("nmcli radio wifi off");
char *chr = "nmcli radio wifi off";
Utils::m_system(chr);
// int status = system("nmcli radio wifi off");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi off' in function 'execDisWifi' failed");}
while(1){
if (execGetIface()->wstate == 2){
emit disWifiDone();
@ -175,12 +204,14 @@ void BackThread::execDisWifi(){
}
void BackThread::execConnLan(QString connName){
lanDelete(); //连接前先断开已经连接的有线网
disConnLanOrWifi("ethernet");
KylinDBus objKyDbus;
if(objKyDbus.isWiredCableOn){
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "'";
system(cmd.toUtf8().data());
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection up' in function 'execConnLan' failed");}
qDebug()<<"debug: in function execConnLan, wired net state is: "<<QString::number(execGetIface()->lstate);
syslog(LOG_DEBUG, "In function execConnLan, wired net state is: %d", execGetIface()->lstate);
emit connDone(0);
@ -192,10 +223,12 @@ void BackThread::execConnLan(QString connName){
}
void BackThread::execConnWifiPWD(QString connName, QString password){
wifiDelete(); //连接前先断开已经连接的wifi
disConnLanOrWifi("wifi");
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '" + connName + "' password '" + password + "' > /tmp/kylin-nm-btoutput";
system(cmd.toUtf8().data());
QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '" + connName + "' password '" + password + "' > /tmp/kylin-nm-btoutput";
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");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
@ -212,7 +245,10 @@ void BackThread::execConnWifiPWD(QString connName, QString password){
}else{
QString txt(tr("Confirm your Wi-Fi password"));
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "...' -t 3800";
system(cmd.toUtf8().data());
Utils::m_system(cmd.toUtf8().data());
// int status1 = system(cmd.toUtf8().data());
// if (status1 != 0){ syslog(LOG_ERR, "execute 'notify-send' in function 'execConnWifiPWD' failed");}
emit connDone(1);
}
@ -220,16 +256,16 @@ void BackThread::execConnWifiPWD(QString connName, QString password){
}
void BackThread::execConnWifi(QString connName){
wifiDelete(); //连接前先断开已经连接的wifi
disConnLanOrWifi("wifi");
QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "'\n";
cmd->write(cmdStr.toUtf8().data());
cmdConnWifi->write(cmdStr.toUtf8().data());
}
void BackThread::on_readoutput()
{
QString str = cmd->readAllStandardOutput();
cmd->close();
QString str = cmdConnWifi->readAllStandardOutput();
cmdConnWifi->close();
qDebug()<<"on_readoutput: "<< str;
if(str.indexOf("successfully") != -1){
emit connDone(0);
@ -245,8 +281,8 @@ void BackThread::on_readoutput()
}
void BackThread::on_readerror()
{
QString str = cmd->readAllStandardError();
cmd->close();
QString str = cmdConnWifi->readAllStandardError();
cmdConnWifi->close();
qDebug()<<"on_readerror: "<< str;
if(str.indexOf("successfully") != -1){
emit connDone(0);
@ -261,11 +297,12 @@ void BackThread::on_readerror()
QString BackThread::getConnProp(QString connName){
QString cmd = "nmcli connection show '" + connName + "' > /tmp/kylin-nm-connprop";
system(cmd.toUtf8().data());
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");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
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;
}
@ -314,7 +351,9 @@ 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";
system(cmd.toUtf8().data());
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");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
@ -334,7 +373,9 @@ 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";
system(cmd.toUtf8().data());
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");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
@ -354,30 +395,37 @@ QString BackThread::execChkLanWidth(QString ethName){
return rtn.trimmed();
}
void BackThread::redundantNetDeleted()
void BackThread::disConnSparedNetSlot(QString type)
{
sleep(1);
wifiDelete();
if (type == "wifi"){
disConnLanOrWifi("wifi");
} else if(type == "ethernet") {
disConnLanOrWifi("ethernet");
}
emit disFinish();
emit ttFinish();
}
void BackThread::wifiDelete()
void BackThread::disConnLanOrWifi(QString type)
{
QString strSlist;
system("nmcli connection show -active>/tmp/kylin-nm-connshow");
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connshow!");
qDebug()<<"Can't open the file /tmp/kylin-nm-connshow!";
const int BUF_SIZE = 1024;
char buf[BUF_SIZE];
FILE * p_file = NULL;
p_file = popen("nmcli connection show -active", "r");
if (!p_file) {
syslog(LOG_ERR, "Error occured when popen cmd 'nmcli connection show'");
qDebug()<<"Error occured when popen cmd 'nmcli connection show";
}
QString txt = file.readAll();
QStringList txtLine = txt.split("\n");
file.close();
foreach (QString line, txtLine) {
if(line.indexOf("wifi") != -1){
while (fgets(buf, BUF_SIZE, p_file) != NULL) {
QString line(buf);
if(line.indexOf(type) != -1){
QStringList subLine = line.split(" ");
if (subLine[1].size() == 1){
strSlist = subLine[0]+ " " + subLine[1];
@ -386,31 +434,6 @@ void BackThread::wifiDelete()
}
kylin_network_set_con_down(strSlist.toUtf8().data());
}
} //end foreach
}
void BackThread::lanDelete()
{
QString strSlist;
system("nmcli connection show -active>/tmp/kylin-nm-connshow");
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
syslog(LOG_DEBUG, "Can't open the file /tmp/kylin-nm-connshow!");
qDebug()<<"Can't open the file /tmp/kylin-nm-connshow!";
}
QString txt = file.readAll();
QStringList txtLine = txt.split("\n");
file.close();
foreach (QString line, txtLine) {
if(line.indexOf("ethernet") != -1){
QStringList subLine = line.split(" ");
if (subLine[1].size() == 1){
strSlist = subLine[0]+ " " + subLine[1];
}else {
strSlist = subLine[0];
}
kylin_network_set_con_down(strSlist.toUtf8().data());
}
} //end foreach
pclose(p_file);
}

View File

@ -22,7 +22,6 @@
#include "kylin-dbus-interface.h"
#include "kylin-network-interface.h"
#include <sys/syslog.h>
#include <QObject>
#include <QDebug>
#include <QTimer>
@ -50,7 +49,22 @@ public:
QString getConnProp(QString connName);
bool execChkWifiExist(QString connName);
QString execChkLanWidth(QString ethName);
QProcess *cmd;
QProcess *cmdConnWifi;
public slots:
void execEnNet();
void execDisNet();
void execEnWifi();
void execDisWifi();
void execConnLan(QString connName);
void execConnWifi(QString connName);
void execConnWifiPWD(QString connName, QString password);
void disConnSparedNetSlot(QString type);
void disConnLanOrWifi(QString type);
void on_readoutput();
void on_readerror();
signals:
void enNetDone();
@ -64,20 +78,6 @@ signals:
void btFinish();
void disFinish();
void ttFinish();
public slots:
void execEnNet();
void execDisNet();
void execEnWifi();
void execDisWifi();
void execConnLan(QString connName);
void execConnWifi(QString connName);
void execConnWifiPWD(QString connName, QString password);
void redundantNetDeleted();
void lanDelete();
void wifiDelete();
void on_readoutput();
void on_readerror();
};
#endif // BACKTHREAD_H

View File

@ -20,7 +20,9 @@
#include "ui_confform.h"
#include "kylin-network-interface.h"
#include "backthread.h"
#include "utils.h"
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
@ -70,7 +72,7 @@ ConfForm::ConfForm(QWidget *parent) :
ui->btnOk->setText(tr("Save"));//"保存"
ui->btnCreate->setText(tr("Ok"));//"确定"
// ui->centralWidget->setStyleSheet("#centralWidget{border:1px solid #297a97;background-color:#ffffff;}");
// ui->centralWidget->setStyleSheet("#centralWidget{border:1px solid #297a97;background-color:#ffffff;}");
ui->wdHead->setStyleSheet("#wdHead{border:none}");
ui->wgManual->setStyleSheet("#wgManual{border:none}");
ui->wdBottom->setStyleSheet("#wdBottom{border:none}");
@ -191,9 +193,12 @@ void ConfForm::setProp(QString connName, QString v4method, QString addr, QString
void ConfForm::on_btnCreate_clicked()
{
QString cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' type ethernet";
system(cmdStr.toUtf8().data());
Utils::m_system(cmdStr.toUtf8().data());
// int status = system(cmdStr.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection add con-name' in function 'on_btnCreate_clicked' failed");}
if(ui->cbType->currentIndex() == 1){
//config the ipv4 and netmask and gateway if select Manual
this->on_btnOk_clicked();
}
@ -234,11 +239,15 @@ void ConfForm::on_btnOk_clicked()
if(this->isActConf == true){
//QString cmd = "/usr/share/kylin-nm/shell/connup.sh '" + ui->leName->text() + "'";
QString cmd = "nmcli connection up '" + ui->leName->text() + "'";
system(cmd.toUtf8().data());
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection up' in function 'on_btnOk_clicked' failed");}
QString txt(tr("New settings already effective"));
cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "' -t 3800";
system(cmd.toUtf8().data());
Utils::m_system(cmd.toUtf8().data());
// int status1 = system(cmd.toUtf8().data());
// if (status1 != 0){ syslog(LOG_ERR, "execute 'notify-send' in function 'on_btnOk_clicked' failed");}
}
}

View File

@ -18,6 +18,7 @@
#include "dlghotspotcreate.h"
#include "ui_dlghotspotcreate.h"
#include "utils.h"
DlgHotspotCreate::DlgHotspotCreate(QString wiFiCardName, QWidget *parent) :
wirelessCardName(wiFiCardName),
@ -97,7 +98,10 @@ void DlgHotspotCreate::on_btnOk_clicked()
}else{
str = "nmcli device wifi hotspot ifname " + wirelessCardName + " con-name " + ui->leNetName->text() + " ssid " + ui->leNetName->text() + " password " + ui->lePassword->text();
}
system(str.toUtf8().data());
Utils::m_system(str.toUtf8().data());
// int status = system(str.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi hotspot' in function 'on_btnOk_clicked' failed");}
this->close();
emit updateHotspotList();
}

View File

@ -1,6 +1,8 @@
#ifndef DLGHOTSPOTCREATE_H
#define DLGHOTSPOTCREATE_H
#include <sys/syslog.h>
#include <QDialog>
#include <QMouseEvent>
#include <QDebug>

View File

@ -17,9 +17,11 @@
*/
#include "ksimplenm.h"
#include <stdio.h>
#include <unistd.h>
#include <QThread>
#define MAX_LEN 2048
#define MAX_PATH 1024

View File

@ -20,6 +20,7 @@
#define KSIMPLENM_H
#include <sys/syslog.h>
#include <QObject>
#include <QProcess>
#include <QDebug>

View File

@ -18,8 +18,10 @@
#include "kylin-dbus-interface.h"
#include "mainwindow.h"
#include <QTextCodec>
#include <vector>
#include <QTextCodec>
#include <QByteArray>
@ -466,20 +468,20 @@ bool KylinDBus::getSwitchStatus(QString key){
return res;
}
void KylinDBus::wifiSwitchSlot(bool signal){
void KylinDBus::setWifiSwitchState(bool signal){
if(!m_gsettings) {
return ;
}
const QStringList list = m_gsettings->keys();
if (!list.contains("switch")) {
if (!list.contains("switchor")) {
return ;
}
m_gsettings->set("switch",signal);
m_gsettings->set("switchor",signal);
}
void KylinDBus::wifiCardSlot(bool signal)
void KylinDBus::setWifiCardState(bool signal)
{
if(!m_gsettings) {
return ;

View File

@ -2,6 +2,7 @@
#define KYLINDBUSINTERFACE_H
#include <sys/syslog.h>
#include <QObject>
#include <QDebug>
#include <QtDBus/QDBusConnection>
@ -31,8 +32,8 @@ public:
void getWifiSwitchState();
bool getSwitchStatus(QString key);
void wifiSwitchSlot(bool signal);
void wifiCardSlot(bool signal);
void setWifiSwitchState(bool signal);
void setWifiCardState(bool signal);
QDBusObjectPath wiredPath;
QDBusObjectPath wirelessPath;

View File

@ -16,19 +16,19 @@
*
*/
#include "kylin-network-interface.h"
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <linux/route.h>
#include <netinet/ether.h>
#include <net/ethernet.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include "kylin-network-interface.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/syslog.h>
//获取网络接口名
ifname *kylin_network_get_ifacename()
@ -58,19 +58,19 @@ ifname *kylin_network_get_ifacename()
//结构体指针ifreq指向buf即ifconf.ifc_buf
ifreq = (struct ifreq*)buf;
int number=ifconf.ifc_len/sizeof(struct ifreq);
// printf("%d\n",number);
// printf("%d\n",number);
ifname *ifn=(ifname *)malloc(sizeof(ifname)*(number+1));
for(i = number; i>0; i--)
{
// printf("name = [%s] \n",ifreq->ifr_name);
// printf("name = [%s] \n",ifreq->ifr_name);
int j=number-i;
ifn[j].if_name=(char *)malloc(sizeof(char)*10);
strcpy(ifn[j].if_name,ifreq->ifr_name);
// ifn[j].if_name=ifreq->ifr_name;
// printf("if_name[%d]:%s\n",j,if_name[j]);
// ifn[j].if_name=ifreq->ifr_name;
// printf("if_name[%d]:%s\n",j,if_name[j]);
ifreq++;
}
@ -83,7 +83,8 @@ ifname *kylin_network_get_ifacename()
//获取所有网络连接
conlist *kylin_network_get_conlist_info()
{
system("nmcli connection show > /tmp/conlist.txt");
int status = system("nmcli connection show > /tmp/conlist.txt");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'kylin_network_get_conlist_info' failed");}
char *filename="/tmp/conlist.txt";
FILE *confp;
@ -100,7 +101,7 @@ conlist *kylin_network_get_conlist_info()
fgets(ConStrLine,1024,confp);
connum++;
}
// printf("%d\n",connum);
// printf("%d\n",connum);
fclose(confp);
conlist *clist=(conlist *)malloc(sizeof(conlist)*connum);
@ -134,12 +135,12 @@ conlist *kylin_network_get_conlist_info()
num++;
}
// printf("连接名称长度:%d\n",num);
// printf("连接名称长度:%d\n",num);
clist[count].con_name=(char *)malloc(sizeof(char)*(num+1));
strncpy(conname,StrLine,num+1);
conname[num]='\0';
strncpy(clist[count].con_name,conname,num+1);
// printf("%s\n",clist[count].con_name);
// printf("%s\n",clist[count].con_name);
//截取连接类型
char type[100];
@ -173,7 +174,7 @@ conlist *kylin_network_get_conlist_info()
strncpy(type,index1+2,num1+1);
type[num1]='\0';
strncpy(clist[count].type,type,num1+1);
// printf("%s\n",clist[count].type);
// printf("%s\n",clist[count].type);
count++;
}
fclose(fp);
@ -187,7 +188,8 @@ conlist *kylin_network_get_conlist_info()
//获取当前活动网络连接
activecon *kylin_network_get_activecon_info()
{
system("nmcli connection show -active > /tmp/activecon.txt");
int status = system("nmcli connection show -active > /tmp/activecon.txt");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show -active' in function 'kylin_network_get_activecon_info' failed");}
char *filename="/tmp/activecon.txt";
FILE *activefp;
@ -204,7 +206,7 @@ activecon *kylin_network_get_activecon_info()
fgets(activeStrLine,1024,activefp);
activenum++;
}
// printf("%d\n",activenum);
// printf("%d\n",activenum);
fclose(activefp);
activecon *activelist=(activecon *)malloc(sizeof(activecon)*activenum);
@ -238,12 +240,12 @@ activecon *kylin_network_get_activecon_info()
num++;
}
// printf("连接名称长度:%d\n",num);
// printf("连接名称长度:%d\n",num);
activelist[count].con_name=(char *)malloc(sizeof(char)*(num+1));
strncpy(conname,StrLine,num+1);
conname[num]='\0';
strncpy(activelist[count].con_name,conname,num+1);
// printf("%s\n",activelist[count].con_name);
// printf("%s\n",activelist[count].con_name);
//截取连接类型
char type[100];
@ -277,7 +279,7 @@ activecon *kylin_network_get_activecon_info()
strncpy(type,index1+2,num1+1);
type[num1]='\0';
strncpy(activelist[count].type,type,num1+1);
// printf("%s\n",activelist[count].type);
// printf("%s\n",activelist[count].type);
//截取连接所属设备
char *index3=index2;
@ -301,7 +303,7 @@ activecon *kylin_network_get_activecon_info()
strncpy(dev,index3+1,num2+1);
dev[num2]='\0';
strncpy(activelist[count].dev,dev,num2+1);
// printf("%s\n",activelist[count].dev);
// printf("%s\n",activelist[count].dev);
count++;
}
fclose(fp);
@ -319,7 +321,8 @@ void kylin_network_create_new_ethernet(char *con_name,char *if_name)
char str[100];
char *net_type="ethernet";
sprintf(str,"nmcli connection add con-name %s ifname %s type %s",con_name,if_name,net_type);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection add con-name' in function 'kylin_network_create_new_ethernet' failed");}
}
// 创建新的wifi连接配置
@ -328,7 +331,8 @@ void kylin_network_create_new_wifi(char *con_name, char *if_name)
char str[200];
sprintf(str, "nmcli connection add con-name '%s' ifname '%s' type wifi ssid '%s'",
con_name, if_name, con_name);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection add con-name' in function 'kylin_network_create_new_wifi' failed");}
}
//删除以太网连接
@ -336,7 +340,8 @@ void kylin_network_del_ethernet_con(char *con_name)
{
char str[100];
sprintf(str,"nmcli connection delete %s",con_name);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'kylin_network_del_ethernet_con' failed");}
}
//设置动态分配ip
@ -345,7 +350,8 @@ void kylin_network_set_automethod(char *con_name)
char str[100];
char *automethod="auto";
sprintf(str,"nmcli connection modify '%s' ipv4.method %s",con_name,automethod);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_automethod' failed");}
}
//设置手动分配ip
@ -354,7 +360,8 @@ void kylin_network_set_manualmethod(char *con_name,char *ip)
char str[100];
char *method="manual";
sprintf(str,"nmcli connection modify '%s' ipv4.method %s ipv4.address %s",con_name,method,ip);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_manualmethod' failed");}
}
// 设置手动分配all
@ -362,7 +369,8 @@ void kylin_network_set_manualall(char *con_name, char *addr, char *mask, char *g
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);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_manualall' failed");}
}
//设置是否自动连接
@ -378,7 +386,8 @@ void kylin_network_set_autoconnect(char *con_name,bool autocon)
char *ac="yes";
sprintf(str,"nmcli connection modify %s connection.autoconnect %s",con_name,ac);
}
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_autoconnect' failed");}
}
//修改ip
@ -386,7 +395,8 @@ void kylin_network_mod_ip(char *con_name,char *ip)
{
char str[100];
sprintf(str,"nmcli connection modify %s ipv4.address %s",con_name,ip);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_mod_ip' failed");}
}
//修改网关
@ -394,7 +404,8 @@ void kylin_network_mod_gateway(char *con_name,char *gw)
{
char str[100];
sprintf(str,"nmcli connection modify %s ipv4.gateway %s",con_name,gw);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_mod_gateway' failed");}
}
//修改dns
@ -402,7 +413,8 @@ void kylin_network_mod_dns(char *con_name,char *dns)
{
char str[100];
sprintf(str,"nmcli connection modify %s ipv4.dns %s",con_name,dns);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_mod_dns' failed");}
}
//连接以太网
@ -410,7 +422,8 @@ void kylin_network_set_con_up(char *con_name)
{
char str[100];
sprintf(str,"nmcli connection up '%s'",con_name);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection up' in function 'kylin_network_set_con_up' failed");}
}
//断开以太网
@ -418,7 +431,8 @@ void kylin_network_set_con_down(char *con_name)
{
char str[100];
sprintf(str,"nmcli connection down '%s'",con_name);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection down' in function 'kylin_network_set_con_down' failed");}
}
//连接wifi
@ -426,8 +440,8 @@ void kylin_network_set_wifi_up(char *con_name,char *passwd)
{
char str[100];
sprintf(str,"export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '%s' password '%s'", con_name,passwd);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'kylin_network_set_wifi_up' failed");}
}
//断开wifi连接
@ -435,14 +449,15 @@ void kylin_network_set_wifi_down(char *if_name)
{
char str[100];
sprintf(str,"nmcli device disconnect '%s'",if_name);
system(str);
int status = system(str);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device disconnect' in function 'kylin_network_set_wifi_down' failed");}
}
//获取wifi列表信息
wifilist *kylin_network_get_wifilist_info()
{
system("nmcli device wifi > /tmp/wflist.txt");
int status = system("nmcli device wifi > /tmp/wflist.txt");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi' in function 'kylin_network_get_wifilist_info' failed");}
char *filename="/tmp/wflist.txt";
FILE *wffp;
@ -459,7 +474,7 @@ wifilist *kylin_network_get_wifilist_info()
fgets(WfStrLine,1024,wffp);
wfnum++;
}
// printf("wifi数量%d\n",wfnum);
// printf("wifi数量%d\n",wfnum);
fclose(wffp);
//wifi实际数量是wfnum-1
wifilist *wflist=(wifilist *)malloc(sizeof(wifilist)*wfnum);
@ -479,7 +494,7 @@ wifilist *kylin_network_get_wifilist_info()
fgets(StrLine,1024,fp);
// printf("%s\n",StrLine+3);
// printf("%s\n",StrLine+3);
char *index=StrLine+3;
//截取ssid
@ -490,7 +505,7 @@ wifilist *kylin_network_get_wifilist_info()
int result=strncmp(index,str1,5);
if(result==0)
{
// printf("%s\n",index);
// printf("%s\n",index);
break;
}
@ -501,15 +516,15 @@ wifilist *kylin_network_get_wifilist_info()
char *ssidindex=index-1;
int ssidnum=0;
for(ssidindex;*ssidindex==' ';ssidindex--)ssidnum++;
// printf("空格数量:%d\n",ssidnum);
// if(ssidnum==1)
// printf("空格数量:%d\n",ssidnum);
// if(ssidnum==1)
strncpy(ssid,StrLine+3,num-1);
ssid[num-ssidnum]='\0';
// printf("-6666--%s---\n",ssid);
// printf("-6666--%s---\n",ssid);
wflist[count].ssid=(char *)malloc(sizeof(char)*(num-ssidnum));
strncpy(wflist[count].ssid,ssid,num-ssidnum+1);
// printf("第%d个%s ",count,wflist[count].ssid);
// printf("第%d个%s ",count,wflist[count].ssid);
//截取信号强度
@ -519,7 +534,7 @@ wifilist *kylin_network_get_wifilist_info()
int result=strncmp(index,str2,6);
if(result==0)
{
// printf("%s\n",index);
// printf("%s\n",index);
break;
}
}
@ -530,10 +545,10 @@ wifilist *kylin_network_get_wifilist_info()
for(signalindex;*signalindex!=' ';signalindex++)signalnum++;
strncpy(signal,index+8,signalnum);
signal[signalnum]='\0';
// printf("-7777--%s---\n",signal);
// printf("-7777--%s---\n",signal);
wflist[count].signal=atoi(signal);
// printf("%d ",wflist[count].signal);
// printf("%d ",wflist[count].signal);
//截取安全性
char *str3="WPA";
@ -542,7 +557,7 @@ wifilist *kylin_network_get_wifilist_info()
int result=strncmp(index,str3,3);
if(result==0)
{
// printf("%s\n",index);
// printf("%s\n",index);
break;
}
}
@ -558,11 +573,11 @@ wifilist *kylin_network_get_wifilist_info()
}
strncpy(safety,index,safetynum+1);
safety[safetynum+1]='\0';
// printf("-8888--%s---\n",safety);
// printf("-8888--%s---\n",safety);
wflist[count].safety=(char *)malloc(sizeof(char)*(safetynum+1));
strncpy(wflist[count].safety,safety,safetynum+2);
// printf("%s\n",wflist[count].safety);
// printf("%s\n",wflist[count].safety);
count++;
@ -580,29 +595,29 @@ wifilist *kylin_network_get_wifilist_info()
//启用联网
void kylin_network_enable_networking()
{
system("nmcli networking on");
int status = system("nmcli networking on");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli networking on' in function 'kylin_network_enable_networking' failed");}
}
//禁用联网
void kylin_network_disable_networking()
{
system("nmcli networking off");
int status = system("nmcli networking off");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli networking off' in function 'kylin_network_disable_networking' failed");}
}
//启用wifi
void kylin_network_enable_wifi()
{
system("nmcli radio wifi on;sleep 3");
int status = system("nmcli radio wifi on;sleep 3");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi on' in function 'kylin_network_enable_wifi' failed");}
}
//禁用wifi
void kylin_network_disable_wifi()
{
system("nmcli radio wifi off;sleep 2");
int status = system("nmcli radio wifi off;sleep 2");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi off' in function 'kylin_network_disable_wifi' failed");}
}
//获取ip地址
@ -706,7 +721,7 @@ int kylin_network_get_mac(char *if_name,char *macaddr)
memcpy(&ethaddr,&ifr_mac.ifr_hwaddr.sa_data,sizeof(ethaddr));
strcpy(macaddr,ether_ntoa(&ethaddr));//#include <netinet/ether.h>
// strcpy(macaddr,ether_ntoa((struct ether_addr*)ifr_mac.ifr_hwaddr.sa_data));
// strcpy(macaddr,ether_ntoa((struct ether_addr*)ifr_mac.ifr_hwaddr.sa_data));
close(sock_mac);
return 0;
@ -734,8 +749,8 @@ int kylin_network_get_mtu(char *if_name)
}
int mtu=ifr_MTU.ifr_mtu;
// printf("%d\n",ifr_MTU.ifr_mtu);
// printf("%d\n",mtu);
// printf("%d\n",ifr_MTU.ifr_mtu);
// printf("%d\n",mtu);
close(sock_mtu);
return mtu;
@ -964,4 +979,3 @@ long *kylin_network_get_fifo(char *if_name)
}
return rtfifo;
}

View File

@ -19,11 +19,12 @@
#ifndef __KYLINNETWORKINTERFACE_H__
#define __KYLINNETWORKINTERFACE_H__
#include<stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C"{

View File

@ -15,14 +15,9 @@ LANGUAGE = C++
CONFIG += c++14
CONFIG += qt warn_on
CONFIG += release
#CONFIG += link_pkgconfig
#PKGCONFIG += libnm glib-2.0 gio-2.0 dbus-glib-1
#PKGCONFIG += Qt5Svg
CONFIG += link_pkgconfig
PKGCONFIG += gsettings-qt
#LIBS += -L/usr/lib/ -lgsettings-qt
target.path = /usr/bin
target.source += $$TARGET
@ -43,6 +38,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
QMAKE_CXXFLAGS += -Wno-unused-parameter
QMAKE_CPPFLAGS *= $(shell dpkg-buildflags --get CPPFLAGS)
QMAKE_CFLAGS *= $(shell dpkg-buildflags --get CFLAGS)
QMAKE_CXXFLAGS *= $(shell dpkg-buildflags --get CXXFLAGS)

View File

@ -144,7 +144,6 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
return false;
}
///////////////////////////////////////////////////////////////////////////////
// 初始化控件、网络、定时器
@ -219,10 +218,10 @@ void MainWindow::createOtherUI()
lbLoadDownImg->resize(16, 16);
lbLoadUp = new QLabel(ui->centralWidget);
lbLoadUp->move(X_ITEM + 217, Y_TOP_ITEM + 32);
lbLoadUp->move(X_ITEM + 207, Y_TOP_ITEM + 32);
lbLoadUp->resize(65, 20);
lbLoadUpImg = new QLabel(ui->centralWidget);
lbLoadUpImg->move(X_ITEM + 200, Y_TOP_ITEM + 35);
lbLoadUpImg->move(X_ITEM + 190, Y_TOP_ITEM + 35);
lbLoadUpImg->resize(16, 16);
lbLoadDownImg->setStyleSheet("QLabel{background-image:url(:/res/x/load-down.png);}");
@ -335,25 +334,29 @@ void MainWindow::getInitLanSlist()
{
oldLanSlist.append("TYPE DEVICE NAME ");
QString strSlist;
const int BUF_SIZE = 1024;
char buf[BUF_SIZE];
system("nmcli connection show>/tmp/kylin-nm-connshow");
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connshow!");
qDebug()<<"Can't open the file /tmp/kylin-nm-connshow!";
FILE * p_file = NULL;
p_file = popen("nmcli connection show", "r");
if (!p_file) {
syslog(LOG_ERR, "Error occured when popen cmd 'nmcli connection show'");
qDebug()<<"Error occured when popen cmd 'nmcli connection show";
}
QString txt = file.readAll();
QStringList txtLine = txt.split("\n");
file.close();
foreach (QString line, txtLine) {
while (fgets(buf, BUF_SIZE, p_file) != NULL) {
QString line(buf);
if(line.indexOf("ethernet") != -1){
QStringList subLine = line.split(" ");
if (subLine[1].size() == 1){
strSlist = "ethernet -- " + subLine[0]+ " " + subLine[1] + " ";
}else{strSlist = "ethernet -- " + subLine[0] + " "; }
// qDebug()<<strSlist;
oldLanSlist.append(strSlist);
}
}
pclose(p_file);
}
// 初始化网络
@ -420,15 +423,18 @@ void MainWindow::initNetwork()
IFace *m_iface = m_bt->execGetIface();
qDebug()<<"m_lstate ="<<m_iface->lstate<<" m_wstate ="<<m_iface->wstate ;
m_bt->lanDelete();
m_bt->disConnLanOrWifi("ethernet");
sleep(1);
m_bt->lanDelete();
m_bt->disConnLanOrWifi("ethernet");
sleep(1);
m_bt->lanDelete();
m_bt->disConnLanOrWifi("ethernet");
delete m_iface;
m_bt->deleteLater();
system("nmcli networking on");
char *chr = "nmcli networking on";
Utils::m_system(chr);
// int status = system("nmcli networking on");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli networking on' in function 'initNetwork' failed");}
onBtnNetListClicked();
@ -613,38 +619,36 @@ void MainWindow::handleIconClicked()
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
QRect screenGeometry = qApp->primaryScreen()->geometry();
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect deskMainRect = desktopWidget->availableGeometry(0);//获取可用桌面大小
QRect screenMainRect = desktopWidget->screenGeometry(0);//获取设备屏幕大小
QRect deskDupRect = desktopWidget->availableGeometry(1);//获取可用桌面大小
QRect screenDupRect = desktopWidget->screenGeometry(1);//获取设备屏幕大小
// qDebug()<<" ";
// qDebug()<<"trayIcon:"<<trayIcon->geometry();
// qDebug()<<"screenGeometry: "<<screenGeometry;
// qDebug()<<"availableGeometry: "<<availableGeometry;
// qDebug()<<"deskMainRect: "<<deskMainRect;
// qDebug()<<"screenMainRect: "<<screenMainRect;
// qDebug()<<"deskDupRect: "<<deskDupRect;
// qDebug()<<"screenDupRect: "<<screenDupRect;
if (screenGeometry.width() == availableGeometry.width() && screenGeometry.height() == availableGeometry.height()){
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect deskMainRect = desktopWidget->availableGeometry(0);//获取可用桌面大小
QRect screenMainRect = desktopWidget->screenGeometry(0);//获取设备屏幕大小
QRect deskDupRect = desktopWidget->availableGeometry(1);//获取可用桌面大小
QRect screenDupRect = desktopWidget->screenGeometry(1);//获取设备屏幕大小
// qDebug()<<" ";
// qDebug()<<"deskMainRect: "<<deskMainRect;
// qDebug()<<"screenMainRect: "<<screenMainRect;
// qDebug()<<"deskDupRect: "<<deskDupRect;
// qDebug()<<"screenDupRect: "<<screenDupRect;
int n = objKyDBus->getTaskbarPos("position");
int m = objKyDBus->getTaskbarHeight("height");
if(n == 0){
//任务栏在下侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), availableGeometry.height() - this->height() - m);
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + availableGeometry.height() - this->height() - m);
}else if(n == 1){
//任务栏在上侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenGeometry.height() - availableGeometry.height() + m);
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + m);
} else if (n == 2){
//任务栏在左侧
if (screenGeometry.x() == 0){
this->move(screenGeometry.width() - availableGeometry.width() + m, screenMainRect.height() - this->height());//主屏在左侧
this->move(screenGeometry.width() - availableGeometry.width() + m, screenMainRect.y() + screenMainRect.height() - this->height());//主屏在左侧
}else{
this->move(screenGeometry.width() - availableGeometry.width() + m,screenDupRect.y() + screenDupRect.height() - this->height());//主屏在右侧
}
@ -653,24 +657,24 @@ void MainWindow::handleIconClicked()
if (screenGeometry.x() == 0){//主屏在左侧
this->move(screenMainRect.width() + screenDupRect.width() - this->width() - m, screenDupRect.y() + screenDupRect.height() - this->height());
}else{//主屏在右侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - m, screenMainRect.height() - this->height());
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - m, screenMainRect.y() + screenMainRect.height() - this->height());
}
}
} else if(screenGeometry.width() == availableGeometry.width() ){
if (trayIcon->geometry().y() > availableGeometry.height()/2){
//任务栏在下侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), availableGeometry.height() - this->height());
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + availableGeometry.height() - this->height());
}else{
//任务栏在上侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenGeometry.height() - availableGeometry.height());
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + screenGeometry.height() - availableGeometry.height());
}
} else if (screenGeometry.height() == availableGeometry.height()){
if (trayIcon->geometry().x() > availableGeometry.width()/2){
//任务栏在右侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenGeometry.height() - this->height());
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + screenGeometry.height() - this->height());
} else {
//任务栏在左侧
this->move(screenGeometry.width() - availableGeometry.width(), screenGeometry.height() - this->height());
this->move(screenGeometry.width() - availableGeometry.width(), screenMainRect.y() + screenGeometry.height() - this->height());
}
}
}
@ -846,11 +850,11 @@ void MainWindow::onCarrierUpHandle()
{
wiredCableUpTimer->stop();
BackThread *up_bt = new BackThread();
up_bt->lanDelete();
up_bt->disConnLanOrWifi("ethernet");
sleep(1);
up_bt->lanDelete();
up_bt->disConnLanOrWifi("ethernet");
sleep(1);
up_bt->lanDelete();
up_bt->disConnLanOrWifi("ethernet");
up_bt->deleteLater();
this->stopLoading();
@ -870,11 +874,11 @@ void MainWindow::onDeleteLan()
{
deleteLanTimer->stop();
BackThread *btn_bt = new BackThread();
btn_bt->lanDelete();
btn_bt->disConnLanOrWifi("ethernet");
sleep(1);
btn_bt->lanDelete();
btn_bt->disConnLanOrWifi("ethernet");
sleep(1);
btn_bt->lanDelete();
btn_bt->disConnLanOrWifi("ethernet");
btn_bt->deleteLater();
this->stopLoading();
@ -998,7 +1002,7 @@ void MainWindow::onBtnWifiClicked(int flag)
// 网络开关关闭时点击Wifi开关时程序先打开有线开关
if (flag == 0) {
if(checkWlOn()){
//objKyDBus->wifiSwitchSlot(false);
objKyDBus->setWifiSwitchState(false);
lbTopWifiList->hide();
btnAddNet->hide();
@ -1015,8 +1019,8 @@ void MainWindow::onBtnWifiClicked(int flag)
if (is_fly_mode_on == 0){
on_btnWifiList_clicked();
is_stop_check_net_state = 1;
//objKyDBus->wifiCardSlot(true);
//objKyDBus->wifiSwitchSlot(true);
objKyDBus->setWifiCardState(true);
objKyDBus->setWifiSwitchState(true);
lbTopWifiList->show();
btnAddNet->show();
@ -1073,13 +1077,15 @@ void MainWindow::onBtnWifiClicked(int flag)
btnAddNet->hide();
if (flag == 0) {
//objKyDBus->wifiSwitchSlot(false);
//objKyDBus->wifiCardSlot(false);
objKyDBus->setWifiSwitchState(false);
objKyDBus->setWifiCardState(false);
}
QString txt(tr("please insert the wireless network adapter"));
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "' -t 3800";
system(cmd.toUtf8().data());
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'notify-send' in function 'onBtnWifiClicked' failed");}
disWifiStateKeep();
}
@ -1087,15 +1093,6 @@ void MainWindow::onBtnWifiClicked(int flag)
void MainWindow::onBtnNetListClicked(int flag)
{
// if (this->ksnm->isExecutingGetWifiList ){
// qDebug()<<"executing update Wifi list now, try again";
// on_btnWifiList_pressed(); //当正在更新wifi列表时点击无效
// QString text(tr("update Wi-Fi list now, click again")); //"正在更新 Wi-Fi列表 请再次点击"
// QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + text + "...' -t 3800";
// system(cmd.toUtf8().data());
// return;
// }
this->is_btnNetList_clicked = 1;
this->is_btnWifiList_clicked = 0;
@ -1130,24 +1127,34 @@ void MainWindow::onBtnNetListClicked(int flag)
this->startLoading();
this->ksnm->execGetLanList();
} else {
system("nmcli connection show -active>/tmp/kylin-nm-connshow");
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
syslog(LOG_DEBUG, "Can't open the file /tmp/kylin-nm-connshow!");
qDebug()<<"Can't open the file /tmp/kylin-nm-connshow!";
}
QString txt = file.readAll();
if (txt.indexOf("ethernet") != -1){
QString txt(tr("Abnormal connection exist, program will delete it"));//仍然有连接异常的有线网络,断开异常连接的网络
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "...' -t 3800";
system(cmd.toUtf8().data());
const int BUF_SIZE = 1024;
char buf[BUF_SIZE];
is_stop_check_net_state = 1;
this->startLoading();
deleteLanTimer->start(1000);
return;
FILE * p_file = NULL;
p_file = popen("nmcli connection show -active", "r");
if (!p_file) {
syslog(LOG_ERR, "Error occured when popen cmd 'nmcli connection show'");
qDebug()<<"Error occured when popen cmd 'nmcli connection show";
}
while (fgets(buf, BUF_SIZE, p_file) != NULL) {
QString line(buf);
if(line.indexOf("ethernet") != -1){
QString txt(tr("Abnormal connection exist, program will delete it"));//仍然有连接异常的有线网络,断开异常连接的网络
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "...' -t 3800";
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'notify-send' in function 'onBtnNetListClicked' failed");}
is_stop_check_net_state = 1;
this->startLoading();
deleteLanTimer->start(1000);
pclose(p_file);
return;
}
}
pclose(p_file);
delete topLanListWidget; // 清空top列表
createTopLanUI(); //创建顶部有线网item
lbTopLanList->hide();
@ -1652,7 +1659,10 @@ void MainWindow::updateWifiListDone(QStringList slist)
void MainWindow::on_btnAdvConf_clicked()
{
system("nm-connection-editor &");
QProcess *qprocess = new QProcess(this);
qprocess->start("nm-connection-editor &");
// int status = system("nm-connection-editor &");
// if (status != 0){ syslog(LOG_ERR, "execute 'nm-connection-editor &' in function 'on_btnAdvConf_clicked' failed");}
}
void MainWindow::on_btnAdvConf_pressed()
@ -1697,28 +1707,8 @@ void MainWindow::on_btnHotspot_clicked()
} else {
on_btnHotspotState();
QString strSlist;
system("nmcli connection show -active>/tmp/kylin-nm-connshow");
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connshow!");
qDebug()<<"Can't open the file /tmp/kylin-nm-connshow!";
}
QString txt = file.readAll();
QStringList txtLine = txt.split("\n");
file.close();
foreach (QString line, txtLine) {
if(line.indexOf("wifi") != -1){
QStringList subLine = line.split(" ");
if (subLine[1].size() == 1){
strSlist = subLine[0]+ " " + subLine[1];
}else {
strSlist = subLine[0];
}
kylin_network_set_con_down(strSlist.toUtf8().data());
}
} //end foreach
BackThread objBT;
objBT.disConnLanOrWifi("wifi");
sleep(2);
on_btnWifiList_clicked();
@ -2018,7 +2008,7 @@ void MainWindow::activeWifiDisconn()
btt->moveToThread(tt);
connect(tt, SIGNAL(finished()), tt, SLOT(deleteLater()));
connect(tt, SIGNAL(started()), this, SLOT(activeStartLoading()));
connect(this, SIGNAL(deleteRedundantNet()), btt, SLOT(redundantNetDeleted()));
connect(this, SIGNAL(disConnSparedNet(QString)), btt, SLOT(disConnSparedNetSlot(QString)));
connect(btt, SIGNAL(disFinish()), this, SLOT(activeGetWifiList()));
connect(btt, SIGNAL(ttFinish()), tt, SLOT(quit()));
tt->start();
@ -2028,7 +2018,7 @@ void MainWindow::activeStartLoading()
syslog(LOG_DEBUG, "Wi-Fi is disconnected");
currSelNetName = "";
//this->startLoading();
emit this->deleteRedundantNet();
emit this->disConnSparedNet("wifi");
}
void MainWindow::activeGetWifiList()
{
@ -2231,8 +2221,35 @@ void MainWindow::on_setNetSpeed()
if (delta_rcv>=10000 || delta_rcv<0){delta_rcv = 0;}
if (delta_tx>=10000 || delta_tx<0){delta_tx = 0;}
QString str_rcv = QString::number(delta_rcv/3) + "kb/s";
QString str_tx = QString::number(delta_tx/3) + "kb/s";
int rcv_num = delta_rcv/3;
int tx_num = delta_tx/3;
QString str_rcv;
QString str_tx;
if (rcv_num < 1000){
str_rcv = QString::number(rcv_num) + "KB/s";
} else {
int remainder;
if (rcv_num%1000 < 100) {
remainder = 0;
}else{
remainder = (rcv_num%1000)/100;
}
str_rcv = QString::number(rcv_num/1000) + "." + QString::number(remainder) + "MB/s";
}
if (tx_num < 1000){
str_tx = QString::number(tx_num) + "KB/s";
} else {
int remainder;
if (tx_num%1000 < 100) {
remainder = 0;
}else{
remainder = (tx_num%1000)/100;
}
str_tx = QString::number(tx_num/1000) + "." + QString::number(remainder) + "MB/s";
}
lbLoadDown->setText(str_rcv);
lbLoadUp->setText(str_tx);
@ -2256,7 +2273,8 @@ void MainWindow::connLanDone(int connFlag)
this->ksnm->execGetLanList();
QString txt(tr("Conn Ethernet Success"));
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "' -t 3800";
system(cmd.toUtf8().data());
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'notify-send' in function 'connLanDone' failed");}
//changeTimerState();
//checkIfLanConnect->start(8000);
@ -2267,7 +2285,9 @@ void MainWindow::connLanDone(int connFlag)
this->is_wired_line_ready = 0; //without net line connect to computer
QString txt(tr("Conn Ethernet Fail"));
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "' -t 3800";
system(cmd.toUtf8().data());
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'notify-send' in function 'connLanDone' failed");}
}
if(connFlag == 3){
@ -2387,7 +2407,8 @@ void MainWindow::connWifiDone(int connFlag)
this->ksnm->execGetWifiList();
QString txt(tr("Conn Wifi Success"));
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "' -t 3800";
system(cmd.toUtf8().data());
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'notify-send' in function 'connWifiDone' failed");}
//changeTimerState();
//checkIfWifiConnect->start(8000);

View File

@ -19,6 +19,21 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ksimplenm.h"
#include "loadingdiv.h"
#include "confform.h"
#include "kylin-dbus-interface.h"
#include "kylin-network-interface.h"
#include "utils.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/syslog.h>
#include <unistd.h>
#include <xcb/xcb.h>
#include <QMainWindow>
#include <QWidget>
#include <QLabel>
@ -46,27 +61,13 @@
#include <QStringList>
#include <QToolTip>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/syslog.h>
#include <unistd.h>
#include <xcb/xcb.h>
#include "ksimplenm.h"
#include "loadingdiv.h"
#include "utils.h"
#include "confform.h"
#include "kylin-dbus-interface.h"
#include "kylin-network-interface.h"
#define W_LEFT_AREA 41
#define W_VERTICAL_LINE 1 //左边竖线宽度
#define W_RIGHT_AREA 438 //41 + 1 + 438 = 480
#define L_VERTICAL_LINE_TO_ITEM 4 //竖线到item左侧的距离
#define X_LEFT_WIFI_BALL 412 //白色小球在左边
#define X_RIGHT_WIFI_BALL 438 //白色小球在右边
#define X_LEFT_WIFI_BALL 422 //白色小球在左边
#define X_RIGHT_WIFI_BALL 448 //白色小球在右边
#define Y_WIFI_BALL 22 //白色小球y坐标
#define X_ITEM 46 //item到窗口左侧的距离 41 + 1 + 4 = 46
#define W_ITEM 424
@ -91,7 +92,7 @@
#define W_BTN_FUN 57
#define H_BTN_FUN 14
#define X_BTN_FUN 365
#define X_BTN_FUN 371
#define Y_BTN_FUN 87 //新建网络加入网络按钮的宽高、x坐标、y坐标
#define W_NO_ITEM_TIP 220
@ -292,7 +293,7 @@ private slots:
void onBtnAddNetClicked();
void onBtnCreateNetClicked();
signals:
void deleteRedundantNet();
void disConnSparedNet(QString type);
void waitWifiStop();
void waitLanStop();

View File

@ -43,7 +43,7 @@
<widget class="QLabel" name="lbBtnWifiBG">
<property name="geometry">
<rect>
<x>410</x>
<x>420</x>
<y>20</y>
<width>50</width>
<height>24</height>
@ -56,7 +56,7 @@
<widget class="QPushButton" name="btnWifi">
<property name="geometry">
<rect>
<x>410</x>
<x>420</x>
<y>20</y>
<width>50</width>
<height>24</height>
@ -147,7 +147,7 @@
<widget class="QLabel" name="lbBtnWifiBall">
<property name="geometry">
<rect>
<x>438</x>
<x>448</x>
<y>22</y>
<width>20</width>
<height>20</height>
@ -199,7 +199,7 @@
<widget class="QLabel" name="lbWifiListBG">
<property name="geometry">
<rect>
<x>1</x>
<x>2</x>
<y>57</y>
<width>37</width>
<height>37</height>

View File

@ -20,6 +20,7 @@
#include "ui_oneconnform.h"
#include "mainwindow.h"
#include "wireless-security/dlgconnhidwifi.h"
#include "utils.h"
extern int currentActWifiSignalLv;
@ -603,7 +604,9 @@ void OneConnForm::slotConnWifiResult(int connFlag){
QString txt(tr("Conn Wifi Failed"));//"连接 Wifi 失败"
syslog(LOG_DEBUG, "Try to connect wifi named %s, but failed, will delete it's configuration file", ui->lbName->text().toUtf8().data());
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection delete '" + ui->lbName->text() + "';notify-send '" + txt + "...' -t 3800";
system(cmd.toUtf8().data());
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'slotConnWifiResult' failed");}
}
// 设置全局变量当前连接Wifi的信号强度

View File

@ -17,7 +17,60 @@
*/
#include "utils.h"
#include <stdio.h>
#include <sys/syslog.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
///////////////////////////////////////////////////////////////////////////////
// The Utils class
Utils::Utils(){}
int Utils::m_system(char *cmd)
{
int status = 0;
pid_t pid;
if ((pid = vfork()) <0){
qDebug()<<"failed to create a subprocess by using vfork";
syslog(LOG_ERR, "failed to create a subprocess by using vfork");
status = -1;
} else if (pid==0) {
const char *new_argv[4];
struct sigaction sa_cld;
sa_cld.sa_handler = SIG_DFL;
sa_cld.sa_flags = 0;
// 在子进程中放开SIGINT信号
sigemptyset(&sa_cld.sa_mask);
sigaction (SIGINT, &sa_cld, NULL);
sigaction (SIGQUIT, &sa_cld, NULL);
new_argv[0] = "sh";
new_argv[1] = "-c";
new_argv[2] = cmd;
new_argv[3] = NULL;
// execl("/bin/sh","sh","-c" ,cmd,(char *)0);
if (execve("/bin/sh",(char *const *) new_argv, NULL) <0) {
qDebug()<<"failed to execve a shell command in function m_system";
syslog(LOG_ERR, "failed to execve %s! errno: %d\n",cmd, errno);
exit(1);
} else {
exit(0);
}
} else {
waitpid(pid,&status,0);
}
return status;
}
///////////////////////////////////////////////////////////////////////////////
// The NetworkSpeed class, used to get network speed
NetworkSpeed::NetworkSpeed(QObject *parent) :QObject(parent){}
@ -76,7 +129,8 @@ int NetworkSpeed::getCurrentDownloadRates(char *netname, long *save_rate, long *
}
///////////////////////////////////////////////////////////////////////////////
// The CustomStyle class, inherit from QProxyStyle, used to change style of control
CustomStyle::CustomStyle(const QString &proxyStyleName, QObject *parent) : QProxyStyle (proxyStyleName)
{

55
utils.h
View File

@ -1,6 +1,11 @@
#ifndef UTILS_H
#define UTILS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <QObject>
#include <QDebug>
#include <QString>
@ -15,18 +20,23 @@
#include <QFile>
#include <QApplication>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
///////////////////////////////////////////////////////////////////////////////
// The Utils class, used to do some assist function
class Utils
{
public:
Utils();
static int m_system(char *cmd);
};
///////////////////////////////////////////////////////////////////////////////
// The UseQssFile class, set control style by using .qss file
/*!
* \brief The UseQssFile class
* \details
* QSS文件设置样式
*/
class UseQssFile
{
public:
@ -42,13 +52,9 @@ public:
};
///////////////////////////////////////////////////////////////////////////////
// The NetworkSpeed class, get the network upload and download speed
/*!
* \brief The NetworkSpeed class
* \details
*
*/
class NetworkSpeed : public QObject
{
Q_OBJECT
@ -61,22 +67,9 @@ public:
/*!
* \brief The CustomStyle class
* \details
* QStyle
* QProxyStyle使QProxyStyle的实例绘制控件
* QProxyStyle可以从现有的qt style实例化style的名字即可
* style的代码直接引入我们的项目中
* style类进行二次开发
*
* QStyle的所有的接口使QStyle进行控件的绘制使得qt应用能够进行风格的切换
*
*
* \note
* QStyle与QSS并不兼容QSS本身其实上也是QStyle的一种实现
* QStyle进行绘制
*/
///////////////////////////////////////////////////////////////////////////////
// The CustomStyle class, inherit from class QProxyStyle, to change control style customize
class CustomStyle : public QProxyStyle
{
Q_OBJECT

View File

@ -74,7 +74,8 @@ DlgConnHidWifi::DlgConnHidWifi(int type, MainWindow *mainWindow, QWidget *parent
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建...
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifi' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
@ -193,7 +194,8 @@ void DlgConnHidWifi::changeWindow(){
ui->btnConnect->setEnabled(false);
}else if (ui->cbxConn->currentIndex() >= 1){
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >/tmp/kylin-nm-connshow";
system(currStr.toUtf8().data());
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");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
@ -240,7 +242,8 @@ void DlgConnHidWifi::on_btnConnect_clicked()
do{
sleep(1);
QString cmd = "nmcli device wifi connect " + wifiName + " password '' hidden yes >/tmp/kylin-nm-btoutput";
system(cmd.toUtf8().data());
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");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
@ -279,7 +282,8 @@ void DlgConnHidWifi::slotStartLoading()
void DlgConnHidWifi::on_execSecConn()
{
QString str = "nmcli device wifi connect " + strWifiname + " password ''";
system(str.toUtf8().data());
int status = system(str.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_execSecConn' failed");}
connect(this, SIGNAL(sendMessage()), this,SLOT(emitSignal() ));
QTimer::singleShot(3*1000, this, SLOT(emitSignal() ));
}

View File

@ -20,6 +20,8 @@
#include "ui_dlgconnhidwifileap.h"
#include "kylinheadfile.h"
#include <sys/syslog.h>
DlgConnHidWifiLeap::DlgConnHidWifiLeap(QWidget *parent) :
QDialog(parent),
ui(new Ui::DlgConnHidWifiLeap)
@ -73,7 +75,8 @@ DlgConnHidWifiLeap::DlgConnHidWifiLeap(QWidget *parent) :
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建...
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiLeap' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";

View File

@ -21,6 +21,8 @@
#include "ui_dlgconnhidwifisecfast.h"
#include "kylinheadfile.h"
#include <sys/syslog.h>
DlgConnHidWifiSecFast::DlgConnHidWifiSecFast(int type, QWidget *parent) :
WepOrWpa(type),
QDialog(parent),
@ -93,7 +95,8 @@ DlgConnHidWifiSecFast::DlgConnHidWifiSecFast(int type, QWidget *parent) :
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建...
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiSecFast' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";

View File

@ -21,6 +21,8 @@
#include "ui_dlgconnhidwifisecleap.h"
#include "kylinheadfile.h"
#include <sys/syslog.h>
DlgConnHidWifiSecLeap::DlgConnHidWifiSecLeap(int type, QWidget *parent) :
WepOrWpa(type),
QDialog(parent),
@ -79,7 +81,8 @@ DlgConnHidWifiSecLeap::DlgConnHidWifiSecLeap(int type, QWidget *parent) :
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建...
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiSecLeap' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";

View File

@ -21,6 +21,8 @@
#include "ui_dlgconnhidwifisecpeap.h"
#include "kylinheadfile.h"
#include <sys/syslog.h>
DlgConnHidWifiSecPeap::DlgConnHidWifiSecPeap(int type, QWidget *parent) :
WepOrWpa(type),
QDialog(parent),
@ -104,7 +106,8 @@ DlgConnHidWifiSecPeap::DlgConnHidWifiSecPeap(int type, QWidget *parent) :
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem("新建...");
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiSecPeap' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";

View File

@ -21,6 +21,8 @@
#include "ui_dlgconnhidwifisecpwd.h"
#include "kylinheadfile.h"
#include <sys/syslog.h>
DlgConnHidWifiSecPwd::DlgConnHidWifiSecPwd(int type, QWidget *parent) :
WepOrWpa(type),
QDialog(parent),
@ -80,7 +82,8 @@ DlgConnHidWifiSecPwd::DlgConnHidWifiSecPwd(int type, QWidget *parent) :
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建...
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiSecPwd' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";

View File

@ -20,6 +20,8 @@
#include "ui_dlgconnhidwifisectls.h"
#include "kylinheadfile.h"
#include <sys/syslog.h>
DlgConnHidWifiSecTls::DlgConnHidWifiSecTls(int type, QWidget *parent) :
WepOrWpa(type),
QDialog(parent),
@ -103,7 +105,8 @@ DlgConnHidWifiSecTls::DlgConnHidWifiSecTls(int type, QWidget *parent) :
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建...
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiSecTls' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";

View File

@ -21,6 +21,8 @@
#include "ui_dlgconnhidwifisectunneltls.h"
#include "kylinheadfile.h"
#include <sys/syslog.h>
DlgConnHidWifiSecTunnelTLS::DlgConnHidWifiSecTunnelTLS(int type, QWidget *parent) :
WepOrWpa(type),
QDialog(parent),
@ -101,7 +103,8 @@ DlgConnHidWifiSecTunnelTLS::DlgConnHidWifiSecTunnelTLS(int type, QWidget *parent
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建...
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiSecTunnelTLS' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";

View File

@ -20,6 +20,8 @@
#include "ui_dlgconnhidwifiwep.h"
#include "kylinheadfile.h"
#include <sys/syslog.h>
DlgConnHidWifiWep::DlgConnHidWifiWep(int type, QWidget *parent) :
WepPwdOrCode(type),
QDialog(parent),
@ -79,7 +81,8 @@ DlgConnHidWifiWep::DlgConnHidWifiWep(int type, QWidget *parent) :
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建...
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiWep' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";

View File

@ -80,7 +80,8 @@ DlgConnHidWifiWpa::DlgConnHidWifiWpa(int type, MainWindow *mainWindow, QWidget *
ui->btnConnect->setText(tr("Connect")); //连接
ui->cbxConn->addItem(tr("C_reate…")); //新建...
system("nmcli connection show>/tmp/kylin-nm-connshow");
int status = system("nmcli connection show>/tmp/kylin-nm-connshow");
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiWpa' failed");}
QFile file("/tmp/kylin-nm-connshow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
@ -200,7 +201,8 @@ void DlgConnHidWifiWpa::changeWindow(){
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";
system(currStr.toUtf8().data());
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");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
@ -251,7 +253,8 @@ void DlgConnHidWifiWpa::on_btnConnect_clicked()
do{
sleep(1);
QString cmd = "nmcli device wifi connect " + wifiName + " password " + wifiPassword + " hidden yes >/tmp/kylin-nm-btoutput";
system(cmd.toUtf8().data());
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");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
@ -308,7 +311,8 @@ void DlgConnHidWifiWpa::slotStartLoading()
void DlgConnHidWifiWpa::on_execSecConn()
{
QString str = "nmcli device wifi connect " + strWifiname + " password " + strWifiPassword;
system(str.toUtf8().data());
int status = system(str.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_execSecConn' failed");}
connect(this, SIGNAL(sendMessage()), this,SLOT(emitSignal() ));
QTimer::singleShot(3*1000, this, SLOT(emitSignal() ));
}