add process to return value of system function,replace some system function.
This commit is contained in:
parent
588a7c998f
commit
a91a75e5fe
161
backthread.cpp
161
backthread.cpp
|
@ -17,30 +17,37 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "backthread.h"
|
#include "backthread.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
|
||||||
BackThread::BackThread(QObject *parent) : QObject(parent){
|
BackThread::BackThread(QObject *parent) : QObject(parent){
|
||||||
cmd = new QProcess(this);
|
cmdConnWifi = new QProcess(this);
|
||||||
connect(cmd , SIGNAL(readyReadStandardOutput()) , this , SLOT(on_readoutput()));
|
connect(cmdConnWifi , SIGNAL(readyReadStandardOutput()) , this , SLOT(on_readoutput()));
|
||||||
connect(cmd , SIGNAL(readyReadStandardError()) , this , SLOT(on_readerror()));
|
connect(cmdConnWifi , SIGNAL(readyReadStandardError()) , this , SLOT(on_readerror()));
|
||||||
cmd->start("bash");
|
cmdConnWifi->start("bash");
|
||||||
cmd->waitForStarted();
|
cmdConnWifi->waitForStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
BackThread::~BackThread()
|
BackThread::~BackThread()
|
||||||
{
|
{
|
||||||
cmd->close();
|
cmdConnWifi->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
IFace* BackThread::execGetIface(){
|
IFace* BackThread::execGetIface(){
|
||||||
IFace *iface = new IFace();
|
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";
|
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");
|
QFile file("/tmp/kylin-nm-iface");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
@ -98,7 +105,11 @@ IFace* BackThread::execGetIface(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackThread::execEnNet(){
|
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){
|
while(1){
|
||||||
if (execGetIface()->lstate != 2){
|
if (execGetIface()->lstate != 2){
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
@ -112,7 +123,11 @@ void BackThread::execEnNet(){
|
||||||
|
|
||||||
void BackThread::execDisNet(){
|
void BackThread::execDisNet(){
|
||||||
if (execGetIface()->wstate != 2){
|
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){
|
while(1){
|
||||||
if (execGetIface()->wstate == 2){
|
if (execGetIface()->wstate == 2){
|
||||||
emit disWifiDone();
|
emit disWifiDone();
|
||||||
|
@ -122,7 +137,11 @@ void BackThread::execDisNet(){
|
||||||
sleep(1);
|
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){
|
while(1){
|
||||||
if (execGetIface()->lstate == 2){
|
if (execGetIface()->lstate == 2){
|
||||||
emit disNetDone();
|
emit disNetDone();
|
||||||
|
@ -135,7 +154,10 @@ void BackThread::execDisNet(){
|
||||||
|
|
||||||
void BackThread::execEnWifi(){
|
void BackThread::execEnWifi(){
|
||||||
if (execGetIface()->lstate == 2){
|
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){
|
while(1){
|
||||||
if (execGetIface()->lstate != 2){
|
if (execGetIface()->lstate != 2){
|
||||||
emit launchLanDone();
|
emit launchLanDone();
|
||||||
|
@ -144,7 +166,11 @@ void BackThread::execEnWifi(){
|
||||||
sleep(1);
|
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){
|
while(1){
|
||||||
if (execGetIface()->wstate != 2){
|
if (execGetIface()->wstate != 2){
|
||||||
KylinDBus objKyDbus;
|
KylinDBus objKyDbus;
|
||||||
|
@ -163,7 +189,10 @@ void BackThread::execEnWifi(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackThread::execDisWifi(){
|
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){
|
while(1){
|
||||||
if (execGetIface()->wstate == 2){
|
if (execGetIface()->wstate == 2){
|
||||||
emit disWifiDone();
|
emit disWifiDone();
|
||||||
|
@ -175,12 +204,14 @@ void BackThread::execDisWifi(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackThread::execConnLan(QString connName){
|
void BackThread::execConnLan(QString connName){
|
||||||
lanDelete(); //连接前先断开已经连接的有线网
|
disConnLanOrWifi("ethernet");
|
||||||
|
|
||||||
KylinDBus objKyDbus;
|
KylinDBus objKyDbus;
|
||||||
if(objKyDbus.isWiredCableOn){
|
if(objKyDbus.isWiredCableOn){
|
||||||
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "'";
|
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);
|
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);
|
syslog(LOG_DEBUG, "In function execConnLan, wired net state is: %d", execGetIface()->lstate);
|
||||||
emit connDone(0);
|
emit connDone(0);
|
||||||
|
@ -192,10 +223,12 @@ void BackThread::execConnLan(QString connName){
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackThread::execConnWifiPWD(QString connName, QString password){
|
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";
|
QString cmdStr = "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());
|
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("/tmp/kylin-nm-btoutput");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
|
@ -212,7 +245,10 @@ void BackThread::execConnWifiPWD(QString connName, QString password){
|
||||||
}else{
|
}else{
|
||||||
QString txt(tr("Confirm your Wi-Fi password"));
|
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";
|
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);
|
emit connDone(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,16 +256,16 @@ void BackThread::execConnWifiPWD(QString connName, QString password){
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackThread::execConnWifi(QString connName){
|
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";
|
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()
|
void BackThread::on_readoutput()
|
||||||
{
|
{
|
||||||
QString str = cmd->readAllStandardOutput();
|
QString str = cmdConnWifi->readAllStandardOutput();
|
||||||
cmd->close();
|
cmdConnWifi->close();
|
||||||
qDebug()<<"on_readoutput: "<< str;
|
qDebug()<<"on_readoutput: "<< str;
|
||||||
if(str.indexOf("successfully") != -1){
|
if(str.indexOf("successfully") != -1){
|
||||||
emit connDone(0);
|
emit connDone(0);
|
||||||
|
@ -245,8 +281,8 @@ void BackThread::on_readoutput()
|
||||||
}
|
}
|
||||||
void BackThread::on_readerror()
|
void BackThread::on_readerror()
|
||||||
{
|
{
|
||||||
QString str = cmd->readAllStandardError();
|
QString str = cmdConnWifi->readAllStandardError();
|
||||||
cmd->close();
|
cmdConnWifi->close();
|
||||||
qDebug()<<"on_readerror: "<< str;
|
qDebug()<<"on_readerror: "<< str;
|
||||||
if(str.indexOf("successfully") != -1){
|
if(str.indexOf("successfully") != -1){
|
||||||
emit connDone(0);
|
emit connDone(0);
|
||||||
|
@ -261,11 +297,12 @@ void BackThread::on_readerror()
|
||||||
|
|
||||||
QString BackThread::getConnProp(QString connName){
|
QString BackThread::getConnProp(QString connName){
|
||||||
QString cmd = "nmcli connection show '" + connName + "' > /tmp/kylin-nm-connprop";
|
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");
|
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!");
|
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connprop!");
|
||||||
qDebug()<<"Can't open the file /tmp/kylin-nm-connprop!"<<endl;
|
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){
|
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";
|
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");
|
QFile file("/tmp/kylin-nm-chkwifiexist");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
@ -334,7 +373,9 @@ bool BackThread::execChkWifiExist(QString connName){
|
||||||
|
|
||||||
QString BackThread::execChkLanWidth(QString ethName){
|
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";
|
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");
|
QFile file("/tmp/kylin-nm-bandwidth");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
@ -354,30 +395,37 @@ QString BackThread::execChkLanWidth(QString ethName){
|
||||||
return rtn.trimmed();
|
return rtn.trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackThread::redundantNetDeleted()
|
void BackThread::disConnSparedNetSlot(QString type)
|
||||||
{
|
{
|
||||||
sleep(1);
|
sleep(1);
|
||||||
wifiDelete();
|
if (type == "wifi"){
|
||||||
|
disConnLanOrWifi("wifi");
|
||||||
|
} else if(type == "ethernet") {
|
||||||
|
disConnLanOrWifi("ethernet");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
emit disFinish();
|
emit disFinish();
|
||||||
emit ttFinish();
|
emit ttFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackThread::wifiDelete()
|
void BackThread::disConnLanOrWifi(QString type)
|
||||||
{
|
{
|
||||||
QString strSlist;
|
QString strSlist;
|
||||||
system("nmcli connection show -active>/tmp/kylin-nm-connshow");
|
const int BUF_SIZE = 1024;
|
||||||
QFile file("/tmp/kylin-nm-connshow");
|
char buf[BUF_SIZE];
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
|
||||||
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connshow!");
|
FILE * p_file = NULL;
|
||||||
qDebug()<<"Can't open the file /tmp/kylin-nm-connshow!";
|
|
||||||
|
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();
|
while (fgets(buf, BUF_SIZE, p_file) != NULL) {
|
||||||
QStringList txtLine = txt.split("\n");
|
QString line(buf);
|
||||||
file.close();
|
if(line.indexOf(type) != -1){
|
||||||
foreach (QString line, txtLine) {
|
|
||||||
if(line.indexOf("wifi") != -1){
|
|
||||||
QStringList subLine = line.split(" ");
|
QStringList subLine = line.split(" ");
|
||||||
if (subLine[1].size() == 1){
|
if (subLine[1].size() == 1){
|
||||||
strSlist = subLine[0]+ " " + subLine[1];
|
strSlist = subLine[0]+ " " + subLine[1];
|
||||||
|
@ -386,31 +434,6 @@ void BackThread::wifiDelete()
|
||||||
}
|
}
|
||||||
kylin_network_set_con_down(strSlist.toUtf8().data());
|
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!";
|
|
||||||
}
|
}
|
||||||
|
pclose(p_file);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
32
backthread.h
32
backthread.h
|
@ -22,7 +22,6 @@
|
||||||
#include "kylin-dbus-interface.h"
|
#include "kylin-dbus-interface.h"
|
||||||
#include "kylin-network-interface.h"
|
#include "kylin-network-interface.h"
|
||||||
|
|
||||||
#include <sys/syslog.h>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
@ -50,7 +49,22 @@ public:
|
||||||
QString getConnProp(QString connName);
|
QString getConnProp(QString connName);
|
||||||
bool execChkWifiExist(QString connName);
|
bool execChkWifiExist(QString connName);
|
||||||
QString execChkLanWidth(QString ethName);
|
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:
|
signals:
|
||||||
void enNetDone();
|
void enNetDone();
|
||||||
|
@ -64,20 +78,6 @@ signals:
|
||||||
void btFinish();
|
void btFinish();
|
||||||
void disFinish();
|
void disFinish();
|
||||||
void ttFinish();
|
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
|
#endif // BACKTHREAD_H
|
||||||
|
|
17
confform.cpp
17
confform.cpp
|
@ -20,7 +20,9 @@
|
||||||
#include "ui_confform.h"
|
#include "ui_confform.h"
|
||||||
#include "kylin-network-interface.h"
|
#include "kylin-network-interface.h"
|
||||||
#include "backthread.h"
|
#include "backthread.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
@ -70,7 +72,7 @@ ConfForm::ConfForm(QWidget *parent) :
|
||||||
ui->btnOk->setText(tr("Save"));//"保存"
|
ui->btnOk->setText(tr("Save"));//"保存"
|
||||||
ui->btnCreate->setText(tr("Ok"));//"确定"
|
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->wdHead->setStyleSheet("#wdHead{border:none}");
|
||||||
ui->wgManual->setStyleSheet("#wgManual{border:none}");
|
ui->wgManual->setStyleSheet("#wgManual{border:none}");
|
||||||
ui->wdBottom->setStyleSheet("#wdBottom{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()
|
void ConfForm::on_btnCreate_clicked()
|
||||||
{
|
{
|
||||||
QString cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' type ethernet";
|
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){
|
if(ui->cbType->currentIndex() == 1){
|
||||||
|
//config the ipv4 and netmask and gateway if select Manual
|
||||||
this->on_btnOk_clicked();
|
this->on_btnOk_clicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,11 +239,15 @@ void ConfForm::on_btnOk_clicked()
|
||||||
if(this->isActConf == true){
|
if(this->isActConf == true){
|
||||||
//QString cmd = "/usr/share/kylin-nm/shell/connup.sh '" + ui->leName->text() + "'";
|
//QString cmd = "/usr/share/kylin-nm/shell/connup.sh '" + ui->leName->text() + "'";
|
||||||
QString cmd = "nmcli connection up '" + 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"));
|
QString txt(tr("New settings already effective"));
|
||||||
cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "' -t 3800";
|
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");}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "dlghotspotcreate.h"
|
#include "dlghotspotcreate.h"
|
||||||
#include "ui_dlghotspotcreate.h"
|
#include "ui_dlghotspotcreate.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
DlgHotspotCreate::DlgHotspotCreate(QString wiFiCardName, QWidget *parent) :
|
DlgHotspotCreate::DlgHotspotCreate(QString wiFiCardName, QWidget *parent) :
|
||||||
wirelessCardName(wiFiCardName),
|
wirelessCardName(wiFiCardName),
|
||||||
|
@ -97,7 +98,10 @@ void DlgHotspotCreate::on_btnOk_clicked()
|
||||||
}else{
|
}else{
|
||||||
str = "nmcli device wifi hotspot ifname " + wirelessCardName + " con-name " + ui->leNetName->text() + " ssid " + ui->leNetName->text() + " password " + ui->lePassword->text();
|
str = "nmcli device wifi hotspot ifname " + wirelessCardName + " con-name " + ui->leNetName->text() + " ssid " + ui->leNetName->text() + " password " + ui->lePassword->text();
|
||||||
}
|
}
|
||||||
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();
|
this->close();
|
||||||
emit updateHotspotList();
|
emit updateHotspotList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef DLGHOTSPOTCREATE_H
|
#ifndef DLGHOTSPOTCREATE_H
|
||||||
#define DLGHOTSPOTCREATE_H
|
#define DLGHOTSPOTCREATE_H
|
||||||
|
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ksimplenm.h"
|
#include "ksimplenm.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
#define MAX_LEN 2048
|
#define MAX_LEN 2048
|
||||||
#define MAX_PATH 1024
|
#define MAX_PATH 1024
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#define KSIMPLENM_H
|
#define KSIMPLENM_H
|
||||||
|
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
|
@ -18,8 +18,10 @@
|
||||||
|
|
||||||
#include "kylin-dbus-interface.h"
|
#include "kylin-dbus-interface.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include <QTextCodec>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <QTextCodec>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
|
||||||
|
|
||||||
|
@ -466,20 +468,20 @@ bool KylinDBus::getSwitchStatus(QString key){
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KylinDBus::wifiSwitchSlot(bool signal){
|
void KylinDBus::setWifiSwitchState(bool signal){
|
||||||
if(!m_gsettings) {
|
if(!m_gsettings) {
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList list = m_gsettings->keys();
|
const QStringList list = m_gsettings->keys();
|
||||||
|
|
||||||
if (!list.contains("switch")) {
|
if (!list.contains("switchor")) {
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
m_gsettings->set("switch",signal);
|
m_gsettings->set("switchor",signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KylinDBus::wifiCardSlot(bool signal)
|
void KylinDBus::setWifiCardState(bool signal)
|
||||||
{
|
{
|
||||||
if(!m_gsettings) {
|
if(!m_gsettings) {
|
||||||
return ;
|
return ;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define KYLINDBUSINTERFACE_H
|
#define KYLINDBUSINTERFACE_H
|
||||||
|
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QtDBus/QDBusConnection>
|
#include <QtDBus/QDBusConnection>
|
||||||
|
@ -31,8 +32,8 @@ public:
|
||||||
|
|
||||||
void getWifiSwitchState();
|
void getWifiSwitchState();
|
||||||
bool getSwitchStatus(QString key);
|
bool getSwitchStatus(QString key);
|
||||||
void wifiSwitchSlot(bool signal);
|
void setWifiSwitchState(bool signal);
|
||||||
void wifiCardSlot(bool signal);
|
void setWifiCardState(bool signal);
|
||||||
|
|
||||||
QDBusObjectPath wiredPath;
|
QDBusObjectPath wiredPath;
|
||||||
QDBusObjectPath wirelessPath;
|
QDBusObjectPath wirelessPath;
|
||||||
|
|
|
@ -16,19 +16,19 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "kylin-network-interface.h"
|
||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <linux/route.h>
|
#include <linux/route.h>
|
||||||
#include <netinet/ether.h>
|
#include <netinet/ether.h>
|
||||||
#include <net/ethernet.h>
|
#include <net/ethernet.h>
|
||||||
#include<sys/types.h>
|
#include <sys/stat.h>
|
||||||
#include<sys/stat.h>
|
#include <fcntl.h>
|
||||||
#include<fcntl.h>
|
#include <sys/syslog.h>
|
||||||
#include "kylin-network-interface.h"
|
|
||||||
|
|
||||||
//获取网络接口名
|
//获取网络接口名
|
||||||
ifname *kylin_network_get_ifacename()
|
ifname *kylin_network_get_ifacename()
|
||||||
|
@ -58,19 +58,19 @@ ifname *kylin_network_get_ifacename()
|
||||||
//结构体指针ifreq指向buf,即ifconf.ifc_buf
|
//结构体指针ifreq指向buf,即ifconf.ifc_buf
|
||||||
ifreq = (struct ifreq*)buf;
|
ifreq = (struct ifreq*)buf;
|
||||||
int number=ifconf.ifc_len/sizeof(struct ifreq);
|
int number=ifconf.ifc_len/sizeof(struct ifreq);
|
||||||
// printf("%d\n",number);
|
// printf("%d\n",number);
|
||||||
|
|
||||||
ifname *ifn=(ifname *)malloc(sizeof(ifname)*(number+1));
|
ifname *ifn=(ifname *)malloc(sizeof(ifname)*(number+1));
|
||||||
|
|
||||||
for(i = number; i>0; i--)
|
for(i = number; i>0; i--)
|
||||||
{
|
{
|
||||||
// printf("name = [%s] \n",ifreq->ifr_name);
|
// printf("name = [%s] \n",ifreq->ifr_name);
|
||||||
|
|
||||||
int j=number-i;
|
int j=number-i;
|
||||||
ifn[j].if_name=(char *)malloc(sizeof(char)*10);
|
ifn[j].if_name=(char *)malloc(sizeof(char)*10);
|
||||||
strcpy(ifn[j].if_name,ifreq->ifr_name);
|
strcpy(ifn[j].if_name,ifreq->ifr_name);
|
||||||
// ifn[j].if_name=ifreq->ifr_name;
|
// ifn[j].if_name=ifreq->ifr_name;
|
||||||
// printf("if_name[%d]:%s\n",j,if_name[j]);
|
// printf("if_name[%d]:%s\n",j,if_name[j]);
|
||||||
|
|
||||||
ifreq++;
|
ifreq++;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,8 @@ ifname *kylin_network_get_ifacename()
|
||||||
//获取所有网络连接
|
//获取所有网络连接
|
||||||
conlist *kylin_network_get_conlist_info()
|
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";
|
char *filename="/tmp/conlist.txt";
|
||||||
|
|
||||||
FILE *confp;
|
FILE *confp;
|
||||||
|
@ -100,7 +101,7 @@ conlist *kylin_network_get_conlist_info()
|
||||||
fgets(ConStrLine,1024,confp);
|
fgets(ConStrLine,1024,confp);
|
||||||
connum++;
|
connum++;
|
||||||
}
|
}
|
||||||
// printf("%d\n",connum);
|
// printf("%d\n",connum);
|
||||||
fclose(confp);
|
fclose(confp);
|
||||||
conlist *clist=(conlist *)malloc(sizeof(conlist)*connum);
|
conlist *clist=(conlist *)malloc(sizeof(conlist)*connum);
|
||||||
|
|
||||||
|
@ -134,12 +135,12 @@ conlist *kylin_network_get_conlist_info()
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("连接名称长度:%d\n",num);
|
// printf("连接名称长度:%d\n",num);
|
||||||
clist[count].con_name=(char *)malloc(sizeof(char)*(num+1));
|
clist[count].con_name=(char *)malloc(sizeof(char)*(num+1));
|
||||||
strncpy(conname,StrLine,num+1);
|
strncpy(conname,StrLine,num+1);
|
||||||
conname[num]='\0';
|
conname[num]='\0';
|
||||||
strncpy(clist[count].con_name,conname,num+1);
|
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];
|
char type[100];
|
||||||
|
@ -173,7 +174,7 @@ conlist *kylin_network_get_conlist_info()
|
||||||
strncpy(type,index1+2,num1+1);
|
strncpy(type,index1+2,num1+1);
|
||||||
type[num1]='\0';
|
type[num1]='\0';
|
||||||
strncpy(clist[count].type,type,num1+1);
|
strncpy(clist[count].type,type,num1+1);
|
||||||
// printf("%s\n",clist[count].type);
|
// printf("%s\n",clist[count].type);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -187,7 +188,8 @@ conlist *kylin_network_get_conlist_info()
|
||||||
//获取当前活动网络连接
|
//获取当前活动网络连接
|
||||||
activecon *kylin_network_get_activecon_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";
|
char *filename="/tmp/activecon.txt";
|
||||||
|
|
||||||
FILE *activefp;
|
FILE *activefp;
|
||||||
|
@ -204,7 +206,7 @@ activecon *kylin_network_get_activecon_info()
|
||||||
fgets(activeStrLine,1024,activefp);
|
fgets(activeStrLine,1024,activefp);
|
||||||
activenum++;
|
activenum++;
|
||||||
}
|
}
|
||||||
// printf("%d\n",activenum);
|
// printf("%d\n",activenum);
|
||||||
fclose(activefp);
|
fclose(activefp);
|
||||||
activecon *activelist=(activecon *)malloc(sizeof(activecon)*activenum);
|
activecon *activelist=(activecon *)malloc(sizeof(activecon)*activenum);
|
||||||
|
|
||||||
|
@ -238,12 +240,12 @@ activecon *kylin_network_get_activecon_info()
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("连接名称长度:%d\n",num);
|
// printf("连接名称长度:%d\n",num);
|
||||||
activelist[count].con_name=(char *)malloc(sizeof(char)*(num+1));
|
activelist[count].con_name=(char *)malloc(sizeof(char)*(num+1));
|
||||||
strncpy(conname,StrLine,num+1);
|
strncpy(conname,StrLine,num+1);
|
||||||
conname[num]='\0';
|
conname[num]='\0';
|
||||||
strncpy(activelist[count].con_name,conname,num+1);
|
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];
|
char type[100];
|
||||||
|
@ -277,7 +279,7 @@ activecon *kylin_network_get_activecon_info()
|
||||||
strncpy(type,index1+2,num1+1);
|
strncpy(type,index1+2,num1+1);
|
||||||
type[num1]='\0';
|
type[num1]='\0';
|
||||||
strncpy(activelist[count].type,type,num1+1);
|
strncpy(activelist[count].type,type,num1+1);
|
||||||
// printf("%s\n",activelist[count].type);
|
// printf("%s\n",activelist[count].type);
|
||||||
|
|
||||||
//截取连接所属设备
|
//截取连接所属设备
|
||||||
char *index3=index2;
|
char *index3=index2;
|
||||||
|
@ -301,7 +303,7 @@ activecon *kylin_network_get_activecon_info()
|
||||||
strncpy(dev,index3+1,num2+1);
|
strncpy(dev,index3+1,num2+1);
|
||||||
dev[num2]='\0';
|
dev[num2]='\0';
|
||||||
strncpy(activelist[count].dev,dev,num2+1);
|
strncpy(activelist[count].dev,dev,num2+1);
|
||||||
// printf("%s\n",activelist[count].dev);
|
// printf("%s\n",activelist[count].dev);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -319,7 +321,8 @@ void kylin_network_create_new_ethernet(char *con_name,char *if_name)
|
||||||
char str[100];
|
char str[100];
|
||||||
char *net_type="ethernet";
|
char *net_type="ethernet";
|
||||||
sprintf(str,"nmcli connection add con-name %s ifname %s type %s",con_name,if_name,net_type);
|
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连接配置
|
// 创建新的wifi连接配置
|
||||||
|
@ -328,7 +331,8 @@ void kylin_network_create_new_wifi(char *con_name, char *if_name)
|
||||||
char str[200];
|
char str[200];
|
||||||
sprintf(str, "nmcli connection add con-name '%s' ifname '%s' type wifi ssid '%s'",
|
sprintf(str, "nmcli connection add con-name '%s' ifname '%s' type wifi ssid '%s'",
|
||||||
con_name, if_name, con_name);
|
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];
|
char str[100];
|
||||||
sprintf(str,"nmcli connection delete %s",con_name);
|
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
|
//设置动态分配ip
|
||||||
|
@ -345,7 +350,8 @@ void kylin_network_set_automethod(char *con_name)
|
||||||
char str[100];
|
char str[100];
|
||||||
char *automethod="auto";
|
char *automethod="auto";
|
||||||
sprintf(str,"nmcli connection modify '%s' ipv4.method %s",con_name,automethod);
|
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
|
//设置手动分配ip
|
||||||
|
@ -354,7 +360,8 @@ void kylin_network_set_manualmethod(char *con_name,char *ip)
|
||||||
char str[100];
|
char str[100];
|
||||||
char *method="manual";
|
char *method="manual";
|
||||||
sprintf(str,"nmcli connection modify '%s' ipv4.method %s ipv4.address %s",con_name,method,ip);
|
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
|
// 设置手动分配all
|
||||||
|
@ -362,7 +369,8 @@ void kylin_network_set_manualall(char *con_name, char *addr, char *mask, char *g
|
||||||
char str[200];
|
char str[200];
|
||||||
sprintf(str, "nmcli connection modify '%s' ipv4.method manual ipv4.address %s/%s ipv4.gateway %s ipv4.dns %s",
|
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);
|
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";
|
char *ac="yes";
|
||||||
sprintf(str,"nmcli connection modify %s connection.autoconnect %s",con_name,ac);
|
sprintf(str,"nmcli connection modify %s connection.autoconnect %s",con_name,ac);
|
||||||
}
|
}
|
||||||
system(str);
|
int status = system(str);
|
||||||
|
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_autoconnect' failed");}
|
||||||
}
|
}
|
||||||
|
|
||||||
//修改ip
|
//修改ip
|
||||||
|
@ -386,7 +395,8 @@ void kylin_network_mod_ip(char *con_name,char *ip)
|
||||||
{
|
{
|
||||||
char str[100];
|
char str[100];
|
||||||
sprintf(str,"nmcli connection modify %s ipv4.address %s",con_name,ip);
|
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];
|
char str[100];
|
||||||
sprintf(str,"nmcli connection modify %s ipv4.gateway %s",con_name,gw);
|
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
|
//修改dns
|
||||||
|
@ -402,7 +413,8 @@ void kylin_network_mod_dns(char *con_name,char *dns)
|
||||||
{
|
{
|
||||||
char str[100];
|
char str[100];
|
||||||
sprintf(str,"nmcli connection modify %s ipv4.dns %s",con_name,dns);
|
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];
|
char str[100];
|
||||||
sprintf(str,"nmcli connection up '%s'",con_name);
|
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];
|
char str[100];
|
||||||
sprintf(str,"nmcli connection down '%s'",con_name);
|
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
|
//连接wifi
|
||||||
|
@ -426,8 +440,8 @@ void kylin_network_set_wifi_up(char *con_name,char *passwd)
|
||||||
{
|
{
|
||||||
char str[100];
|
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);
|
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连接
|
//断开wifi连接
|
||||||
|
@ -435,14 +449,15 @@ void kylin_network_set_wifi_down(char *if_name)
|
||||||
{
|
{
|
||||||
char str[100];
|
char str[100];
|
||||||
sprintf(str,"nmcli device disconnect '%s'",if_name);
|
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列表信息
|
//获取wifi列表信息
|
||||||
wifilist *kylin_network_get_wifilist_info()
|
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";
|
char *filename="/tmp/wflist.txt";
|
||||||
|
|
||||||
FILE *wffp;
|
FILE *wffp;
|
||||||
|
@ -459,7 +474,7 @@ wifilist *kylin_network_get_wifilist_info()
|
||||||
fgets(WfStrLine,1024,wffp);
|
fgets(WfStrLine,1024,wffp);
|
||||||
wfnum++;
|
wfnum++;
|
||||||
}
|
}
|
||||||
// printf("wifi数量:%d\n",wfnum);
|
// printf("wifi数量:%d\n",wfnum);
|
||||||
fclose(wffp);
|
fclose(wffp);
|
||||||
//wifi实际数量是wfnum-1
|
//wifi实际数量是wfnum-1
|
||||||
wifilist *wflist=(wifilist *)malloc(sizeof(wifilist)*wfnum);
|
wifilist *wflist=(wifilist *)malloc(sizeof(wifilist)*wfnum);
|
||||||
|
@ -479,7 +494,7 @@ wifilist *kylin_network_get_wifilist_info()
|
||||||
|
|
||||||
fgets(StrLine,1024,fp);
|
fgets(StrLine,1024,fp);
|
||||||
|
|
||||||
// printf("%s\n",StrLine+3);
|
// printf("%s\n",StrLine+3);
|
||||||
char *index=StrLine+3;
|
char *index=StrLine+3;
|
||||||
|
|
||||||
//截取ssid
|
//截取ssid
|
||||||
|
@ -490,7 +505,7 @@ wifilist *kylin_network_get_wifilist_info()
|
||||||
int result=strncmp(index,str1,5);
|
int result=strncmp(index,str1,5);
|
||||||
if(result==0)
|
if(result==0)
|
||||||
{
|
{
|
||||||
// printf("%s\n",index);
|
// printf("%s\n",index);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -501,15 +516,15 @@ wifilist *kylin_network_get_wifilist_info()
|
||||||
char *ssidindex=index-1;
|
char *ssidindex=index-1;
|
||||||
int ssidnum=0;
|
int ssidnum=0;
|
||||||
for(ssidindex;*ssidindex==' ';ssidindex--)ssidnum++;
|
for(ssidindex;*ssidindex==' ';ssidindex--)ssidnum++;
|
||||||
// printf("空格数量:%d\n",ssidnum);
|
// printf("空格数量:%d\n",ssidnum);
|
||||||
// if(ssidnum==1)
|
// if(ssidnum==1)
|
||||||
strncpy(ssid,StrLine+3,num-1);
|
strncpy(ssid,StrLine+3,num-1);
|
||||||
ssid[num-ssidnum]='\0';
|
ssid[num-ssidnum]='\0';
|
||||||
// printf("-6666--%s---\n",ssid);
|
// printf("-6666--%s---\n",ssid);
|
||||||
|
|
||||||
wflist[count].ssid=(char *)malloc(sizeof(char)*(num-ssidnum));
|
wflist[count].ssid=(char *)malloc(sizeof(char)*(num-ssidnum));
|
||||||
strncpy(wflist[count].ssid,ssid,num-ssidnum+1);
|
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);
|
int result=strncmp(index,str2,6);
|
||||||
if(result==0)
|
if(result==0)
|
||||||
{
|
{
|
||||||
// printf("%s\n",index);
|
// printf("%s\n",index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -530,10 +545,10 @@ wifilist *kylin_network_get_wifilist_info()
|
||||||
for(signalindex;*signalindex!=' ';signalindex++)signalnum++;
|
for(signalindex;*signalindex!=' ';signalindex++)signalnum++;
|
||||||
strncpy(signal,index+8,signalnum);
|
strncpy(signal,index+8,signalnum);
|
||||||
signal[signalnum]='\0';
|
signal[signalnum]='\0';
|
||||||
// printf("-7777--%s---\n",signal);
|
// printf("-7777--%s---\n",signal);
|
||||||
|
|
||||||
wflist[count].signal=atoi(signal);
|
wflist[count].signal=atoi(signal);
|
||||||
// printf("%d ",wflist[count].signal);
|
// printf("%d ",wflist[count].signal);
|
||||||
|
|
||||||
//截取安全性
|
//截取安全性
|
||||||
char *str3="WPA";
|
char *str3="WPA";
|
||||||
|
@ -542,7 +557,7 @@ wifilist *kylin_network_get_wifilist_info()
|
||||||
int result=strncmp(index,str3,3);
|
int result=strncmp(index,str3,3);
|
||||||
if(result==0)
|
if(result==0)
|
||||||
{
|
{
|
||||||
// printf("%s\n",index);
|
// printf("%s\n",index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -558,11 +573,11 @@ wifilist *kylin_network_get_wifilist_info()
|
||||||
}
|
}
|
||||||
strncpy(safety,index,safetynum+1);
|
strncpy(safety,index,safetynum+1);
|
||||||
safety[safetynum+1]='\0';
|
safety[safetynum+1]='\0';
|
||||||
// printf("-8888--%s---\n",safety);
|
// printf("-8888--%s---\n",safety);
|
||||||
|
|
||||||
wflist[count].safety=(char *)malloc(sizeof(char)*(safetynum+1));
|
wflist[count].safety=(char *)malloc(sizeof(char)*(safetynum+1));
|
||||||
strncpy(wflist[count].safety,safety,safetynum+2);
|
strncpy(wflist[count].safety,safety,safetynum+2);
|
||||||
// printf("%s\n",wflist[count].safety);
|
// printf("%s\n",wflist[count].safety);
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
|
@ -580,29 +595,29 @@ wifilist *kylin_network_get_wifilist_info()
|
||||||
//启用联网
|
//启用联网
|
||||||
void kylin_network_enable_networking()
|
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()
|
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
|
//启用wifi
|
||||||
void kylin_network_enable_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
|
//禁用wifi
|
||||||
void kylin_network_disable_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地址
|
//获取ip地址
|
||||||
|
@ -706,7 +721,7 @@ int kylin_network_get_mac(char *if_name,char *macaddr)
|
||||||
memcpy(ðaddr,&ifr_mac.ifr_hwaddr.sa_data,sizeof(ethaddr));
|
memcpy(ðaddr,&ifr_mac.ifr_hwaddr.sa_data,sizeof(ethaddr));
|
||||||
strcpy(macaddr,ether_ntoa(ðaddr));//#include <netinet/ether.h>
|
strcpy(macaddr,ether_ntoa(ðaddr));//#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);
|
close(sock_mac);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -734,8 +749,8 @@ int kylin_network_get_mtu(char *if_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
int mtu=ifr_MTU.ifr_mtu;
|
int mtu=ifr_MTU.ifr_mtu;
|
||||||
// printf("%d\n",ifr_MTU.ifr_mtu);
|
// printf("%d\n",ifr_MTU.ifr_mtu);
|
||||||
// printf("%d\n",mtu);
|
// printf("%d\n",mtu);
|
||||||
|
|
||||||
close(sock_mtu);
|
close(sock_mtu);
|
||||||
return mtu;
|
return mtu;
|
||||||
|
@ -964,4 +979,3 @@ long *kylin_network_get_fifo(char *if_name)
|
||||||
}
|
}
|
||||||
return rtfifo;
|
return rtfifo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,12 @@
|
||||||
#ifndef __KYLINNETWORKINTERFACE_H__
|
#ifndef __KYLINNETWORKINTERFACE_H__
|
||||||
#define __KYLINNETWORKINTERFACE_H__
|
#define __KYLINNETWORKINTERFACE_H__
|
||||||
|
|
||||||
#include<stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"{
|
extern "C"{
|
||||||
|
|
|
@ -15,14 +15,9 @@ LANGUAGE = C++
|
||||||
CONFIG += c++14
|
CONFIG += c++14
|
||||||
CONFIG += qt warn_on
|
CONFIG += qt warn_on
|
||||||
CONFIG += release
|
CONFIG += release
|
||||||
#CONFIG += link_pkgconfig
|
|
||||||
#PKGCONFIG += libnm glib-2.0 gio-2.0 dbus-glib-1
|
|
||||||
#PKGCONFIG += Qt5Svg
|
|
||||||
|
|
||||||
|
|
||||||
CONFIG += link_pkgconfig
|
CONFIG += link_pkgconfig
|
||||||
PKGCONFIG += gsettings-qt
|
PKGCONFIG += gsettings-qt
|
||||||
#LIBS += -L/usr/lib/ -lgsettings-qt
|
|
||||||
|
|
||||||
target.path = /usr/bin
|
target.path = /usr/bin
|
||||||
target.source += $$TARGET
|
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.
|
# 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
|
#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_CPPFLAGS *= $(shell dpkg-buildflags --get CPPFLAGS)
|
||||||
QMAKE_CFLAGS *= $(shell dpkg-buildflags --get CFLAGS)
|
QMAKE_CFLAGS *= $(shell dpkg-buildflags --get CFLAGS)
|
||||||
QMAKE_CXXFLAGS *= $(shell dpkg-buildflags --get CXXFLAGS)
|
QMAKE_CXXFLAGS *= $(shell dpkg-buildflags --get CXXFLAGS)
|
||||||
|
|
227
mainwindow.cpp
227
mainwindow.cpp
|
@ -144,7 +144,6 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// 初始化控件、网络、定时器
|
// 初始化控件、网络、定时器
|
||||||
|
|
||||||
|
@ -219,10 +218,10 @@ void MainWindow::createOtherUI()
|
||||||
lbLoadDownImg->resize(16, 16);
|
lbLoadDownImg->resize(16, 16);
|
||||||
|
|
||||||
lbLoadUp = new QLabel(ui->centralWidget);
|
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);
|
lbLoadUp->resize(65, 20);
|
||||||
lbLoadUpImg = new QLabel(ui->centralWidget);
|
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);
|
lbLoadUpImg->resize(16, 16);
|
||||||
|
|
||||||
lbLoadDownImg->setStyleSheet("QLabel{background-image:url(:/res/x/load-down.png);}");
|
lbLoadDownImg->setStyleSheet("QLabel{background-image:url(:/res/x/load-down.png);}");
|
||||||
|
@ -335,25 +334,29 @@ void MainWindow::getInitLanSlist()
|
||||||
{
|
{
|
||||||
oldLanSlist.append("TYPE DEVICE NAME ");
|
oldLanSlist.append("TYPE DEVICE NAME ");
|
||||||
QString strSlist;
|
QString strSlist;
|
||||||
|
const int BUF_SIZE = 1024;
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
|
||||||
system("nmcli connection show>/tmp/kylin-nm-connshow");
|
FILE * p_file = NULL;
|
||||||
QFile file("/tmp/kylin-nm-connshow");
|
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
p_file = popen("nmcli connection show", "r");
|
||||||
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connshow!");
|
if (!p_file) {
|
||||||
qDebug()<<"Can't open the file /tmp/kylin-nm-connshow!";
|
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");
|
while (fgets(buf, BUF_SIZE, p_file) != NULL) {
|
||||||
file.close();
|
QString line(buf);
|
||||||
foreach (QString line, txtLine) {
|
|
||||||
if(line.indexOf("ethernet") != -1){
|
if(line.indexOf("ethernet") != -1){
|
||||||
QStringList subLine = line.split(" ");
|
QStringList subLine = line.split(" ");
|
||||||
if (subLine[1].size() == 1){
|
if (subLine[1].size() == 1){
|
||||||
strSlist = "ethernet -- " + subLine[0]+ " " + subLine[1] + " ";
|
strSlist = "ethernet -- " + subLine[0]+ " " + subLine[1] + " ";
|
||||||
}else{strSlist = "ethernet -- " + subLine[0] + " "; }
|
}else{strSlist = "ethernet -- " + subLine[0] + " "; }
|
||||||
|
// qDebug()<<strSlist;
|
||||||
oldLanSlist.append(strSlist);
|
oldLanSlist.append(strSlist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pclose(p_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化网络
|
// 初始化网络
|
||||||
|
@ -420,15 +423,18 @@ void MainWindow::initNetwork()
|
||||||
IFace *m_iface = m_bt->execGetIface();
|
IFace *m_iface = m_bt->execGetIface();
|
||||||
qDebug()<<"m_lstate ="<<m_iface->lstate<<" m_wstate ="<<m_iface->wstate ;
|
qDebug()<<"m_lstate ="<<m_iface->lstate<<" m_wstate ="<<m_iface->wstate ;
|
||||||
|
|
||||||
m_bt->lanDelete();
|
m_bt->disConnLanOrWifi("ethernet");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
m_bt->lanDelete();
|
m_bt->disConnLanOrWifi("ethernet");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
m_bt->lanDelete();
|
m_bt->disConnLanOrWifi("ethernet");
|
||||||
delete m_iface;
|
delete m_iface;
|
||||||
m_bt->deleteLater();
|
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();
|
onBtnNetListClicked();
|
||||||
|
|
||||||
|
@ -613,38 +619,36 @@ void MainWindow::handleIconClicked()
|
||||||
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
|
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
|
||||||
QRect screenGeometry = qApp->primaryScreen()->geometry();
|
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()<<" ";
|
||||||
// qDebug()<<"trayIcon:"<<trayIcon->geometry();
|
// qDebug()<<"trayIcon:"<<trayIcon->geometry();
|
||||||
// qDebug()<<"screenGeometry: "<<screenGeometry;
|
// qDebug()<<"screenGeometry: "<<screenGeometry;
|
||||||
// qDebug()<<"availableGeometry: "<<availableGeometry;
|
// qDebug()<<"availableGeometry: "<<availableGeometry;
|
||||||
|
|
||||||
|
// qDebug()<<"deskMainRect: "<<deskMainRect;
|
||||||
|
// qDebug()<<"screenMainRect: "<<screenMainRect;
|
||||||
|
// qDebug()<<"deskDupRect: "<<deskDupRect;
|
||||||
|
// qDebug()<<"screenDupRect: "<<screenDupRect;
|
||||||
|
|
||||||
if (screenGeometry.width() == availableGeometry.width() && screenGeometry.height() == availableGeometry.height()){
|
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 n = objKyDBus->getTaskbarPos("position");
|
||||||
int m = objKyDBus->getTaskbarHeight("height");
|
int m = objKyDBus->getTaskbarHeight("height");
|
||||||
|
|
||||||
if(n == 0){
|
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){
|
}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){
|
} else if (n == 2){
|
||||||
//任务栏在左侧
|
//任务栏在左侧
|
||||||
if (screenGeometry.x() == 0){
|
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{
|
}else{
|
||||||
this->move(screenGeometry.width() - availableGeometry.width() + m,screenDupRect.y() + screenDupRect.height() - this->height());//主屏在右侧
|
this->move(screenGeometry.width() - availableGeometry.width() + m,screenDupRect.y() + screenDupRect.height() - this->height());//主屏在右侧
|
||||||
}
|
}
|
||||||
|
@ -653,24 +657,24 @@ void MainWindow::handleIconClicked()
|
||||||
if (screenGeometry.x() == 0){//主屏在左侧
|
if (screenGeometry.x() == 0){//主屏在左侧
|
||||||
this->move(screenMainRect.width() + screenDupRect.width() - this->width() - m, screenDupRect.y() + screenDupRect.height() - this->height());
|
this->move(screenMainRect.width() + screenDupRect.width() - this->width() - m, screenDupRect.y() + screenDupRect.height() - this->height());
|
||||||
}else{//主屏在右侧
|
}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() ){
|
} else if(screenGeometry.width() == availableGeometry.width() ){
|
||||||
if (trayIcon->geometry().y() > availableGeometry.height()/2){
|
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{
|
}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()){
|
} else if (screenGeometry.height() == availableGeometry.height()){
|
||||||
if (trayIcon->geometry().x() > availableGeometry.width()/2){
|
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 {
|
} 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();
|
wiredCableUpTimer->stop();
|
||||||
BackThread *up_bt = new BackThread();
|
BackThread *up_bt = new BackThread();
|
||||||
up_bt->lanDelete();
|
up_bt->disConnLanOrWifi("ethernet");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
up_bt->lanDelete();
|
up_bt->disConnLanOrWifi("ethernet");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
up_bt->lanDelete();
|
up_bt->disConnLanOrWifi("ethernet");
|
||||||
up_bt->deleteLater();
|
up_bt->deleteLater();
|
||||||
|
|
||||||
this->stopLoading();
|
this->stopLoading();
|
||||||
|
@ -870,11 +874,11 @@ void MainWindow::onDeleteLan()
|
||||||
{
|
{
|
||||||
deleteLanTimer->stop();
|
deleteLanTimer->stop();
|
||||||
BackThread *btn_bt = new BackThread();
|
BackThread *btn_bt = new BackThread();
|
||||||
btn_bt->lanDelete();
|
btn_bt->disConnLanOrWifi("ethernet");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
btn_bt->lanDelete();
|
btn_bt->disConnLanOrWifi("ethernet");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
btn_bt->lanDelete();
|
btn_bt->disConnLanOrWifi("ethernet");
|
||||||
btn_bt->deleteLater();
|
btn_bt->deleteLater();
|
||||||
|
|
||||||
this->stopLoading();
|
this->stopLoading();
|
||||||
|
@ -998,7 +1002,7 @@ void MainWindow::onBtnWifiClicked(int flag)
|
||||||
// 网络开关关闭时,点击Wifi开关时,程序先打开有线开关
|
// 网络开关关闭时,点击Wifi开关时,程序先打开有线开关
|
||||||
if (flag == 0) {
|
if (flag == 0) {
|
||||||
if(checkWlOn()){
|
if(checkWlOn()){
|
||||||
//objKyDBus->wifiSwitchSlot(false);
|
objKyDBus->setWifiSwitchState(false);
|
||||||
lbTopWifiList->hide();
|
lbTopWifiList->hide();
|
||||||
btnAddNet->hide();
|
btnAddNet->hide();
|
||||||
|
|
||||||
|
@ -1015,8 +1019,8 @@ void MainWindow::onBtnWifiClicked(int flag)
|
||||||
if (is_fly_mode_on == 0){
|
if (is_fly_mode_on == 0){
|
||||||
on_btnWifiList_clicked();
|
on_btnWifiList_clicked();
|
||||||
is_stop_check_net_state = 1;
|
is_stop_check_net_state = 1;
|
||||||
//objKyDBus->wifiCardSlot(true);
|
objKyDBus->setWifiCardState(true);
|
||||||
//objKyDBus->wifiSwitchSlot(true);
|
objKyDBus->setWifiSwitchState(true);
|
||||||
lbTopWifiList->show();
|
lbTopWifiList->show();
|
||||||
btnAddNet->show();
|
btnAddNet->show();
|
||||||
|
|
||||||
|
@ -1073,13 +1077,15 @@ void MainWindow::onBtnWifiClicked(int flag)
|
||||||
btnAddNet->hide();
|
btnAddNet->hide();
|
||||||
|
|
||||||
if (flag == 0) {
|
if (flag == 0) {
|
||||||
//objKyDBus->wifiSwitchSlot(false);
|
objKyDBus->setWifiSwitchState(false);
|
||||||
//objKyDBus->wifiCardSlot(false);
|
objKyDBus->setWifiCardState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString txt(tr("please insert the wireless network adapter"));
|
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";
|
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();
|
disWifiStateKeep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1087,15 +1093,6 @@ void MainWindow::onBtnWifiClicked(int flag)
|
||||||
|
|
||||||
void MainWindow::onBtnNetListClicked(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_btnNetList_clicked = 1;
|
||||||
this->is_btnWifiList_clicked = 0;
|
this->is_btnWifiList_clicked = 0;
|
||||||
|
|
||||||
|
@ -1130,24 +1127,34 @@ void MainWindow::onBtnNetListClicked(int flag)
|
||||||
this->startLoading();
|
this->startLoading();
|
||||||
this->ksnm->execGetLanList();
|
this->ksnm->execGetLanList();
|
||||||
} else {
|
} else {
|
||||||
system("nmcli connection show -active>/tmp/kylin-nm-connshow");
|
const int BUF_SIZE = 1024;
|
||||||
QFile file("/tmp/kylin-nm-connshow");
|
char buf[BUF_SIZE];
|
||||||
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());
|
|
||||||
|
|
||||||
is_stop_check_net_state = 1;
|
FILE * p_file = NULL;
|
||||||
this->startLoading();
|
|
||||||
deleteLanTimer->start(1000);
|
p_file = popen("nmcli connection show -active", "r");
|
||||||
return;
|
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列表
|
delete topLanListWidget; // 清空top列表
|
||||||
createTopLanUI(); //创建顶部有线网item
|
createTopLanUI(); //创建顶部有线网item
|
||||||
lbTopLanList->hide();
|
lbTopLanList->hide();
|
||||||
|
@ -1652,7 +1659,10 @@ void MainWindow::updateWifiListDone(QStringList slist)
|
||||||
|
|
||||||
void MainWindow::on_btnAdvConf_clicked()
|
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()
|
void MainWindow::on_btnAdvConf_pressed()
|
||||||
|
@ -1697,28 +1707,8 @@ void MainWindow::on_btnHotspot_clicked()
|
||||||
} else {
|
} else {
|
||||||
on_btnHotspotState();
|
on_btnHotspotState();
|
||||||
|
|
||||||
QString strSlist;
|
BackThread objBT;
|
||||||
system("nmcli connection show -active>/tmp/kylin-nm-connshow");
|
objBT.disConnLanOrWifi("wifi");
|
||||||
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
|
|
||||||
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
on_btnWifiList_clicked();
|
on_btnWifiList_clicked();
|
||||||
|
@ -2018,7 +2008,7 @@ void MainWindow::activeWifiDisconn()
|
||||||
btt->moveToThread(tt);
|
btt->moveToThread(tt);
|
||||||
connect(tt, SIGNAL(finished()), tt, SLOT(deleteLater()));
|
connect(tt, SIGNAL(finished()), tt, SLOT(deleteLater()));
|
||||||
connect(tt, SIGNAL(started()), this, SLOT(activeStartLoading()));
|
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(disFinish()), this, SLOT(activeGetWifiList()));
|
||||||
connect(btt, SIGNAL(ttFinish()), tt, SLOT(quit()));
|
connect(btt, SIGNAL(ttFinish()), tt, SLOT(quit()));
|
||||||
tt->start();
|
tt->start();
|
||||||
|
@ -2028,7 +2018,7 @@ void MainWindow::activeStartLoading()
|
||||||
syslog(LOG_DEBUG, "Wi-Fi is disconnected");
|
syslog(LOG_DEBUG, "Wi-Fi is disconnected");
|
||||||
currSelNetName = "";
|
currSelNetName = "";
|
||||||
//this->startLoading();
|
//this->startLoading();
|
||||||
emit this->deleteRedundantNet();
|
emit this->disConnSparedNet("wifi");
|
||||||
}
|
}
|
||||||
void MainWindow::activeGetWifiList()
|
void MainWindow::activeGetWifiList()
|
||||||
{
|
{
|
||||||
|
@ -2231,8 +2221,35 @@ void MainWindow::on_setNetSpeed()
|
||||||
if (delta_rcv>=10000 || delta_rcv<0){delta_rcv = 0;}
|
if (delta_rcv>=10000 || delta_rcv<0){delta_rcv = 0;}
|
||||||
if (delta_tx>=10000 || delta_tx<0){delta_tx = 0;}
|
if (delta_tx>=10000 || delta_tx<0){delta_tx = 0;}
|
||||||
|
|
||||||
QString str_rcv = QString::number(delta_rcv/3) + "kb/s";
|
int rcv_num = delta_rcv/3;
|
||||||
QString str_tx = QString::number(delta_tx/3) + "kb/s";
|
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);
|
lbLoadDown->setText(str_rcv);
|
||||||
lbLoadUp->setText(str_tx);
|
lbLoadUp->setText(str_tx);
|
||||||
|
@ -2256,7 +2273,8 @@ void MainWindow::connLanDone(int connFlag)
|
||||||
this->ksnm->execGetLanList();
|
this->ksnm->execGetLanList();
|
||||||
QString txt(tr("Conn Ethernet Success"));
|
QString txt(tr("Conn Ethernet Success"));
|
||||||
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "' -t 3800";
|
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();
|
//changeTimerState();
|
||||||
//checkIfLanConnect->start(8000);
|
//checkIfLanConnect->start(8000);
|
||||||
|
@ -2267,7 +2285,9 @@ void MainWindow::connLanDone(int connFlag)
|
||||||
this->is_wired_line_ready = 0; //without net line connect to computer
|
this->is_wired_line_ready = 0; //without net line connect to computer
|
||||||
QString txt(tr("Conn Ethernet Fail"));
|
QString txt(tr("Conn Ethernet Fail"));
|
||||||
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "' -t 3800";
|
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){
|
if(connFlag == 3){
|
||||||
|
@ -2387,7 +2407,8 @@ void MainWindow::connWifiDone(int connFlag)
|
||||||
this->ksnm->execGetWifiList();
|
this->ksnm->execGetWifiList();
|
||||||
QString txt(tr("Conn Wifi Success"));
|
QString txt(tr("Conn Wifi Success"));
|
||||||
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';notify-send '" + txt + "' -t 3800";
|
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();
|
//changeTimerState();
|
||||||
//checkIfWifiConnect->start(8000);
|
//checkIfWifiConnect->start(8000);
|
||||||
|
|
37
mainwindow.h
37
mainwindow.h
|
@ -19,6 +19,21 @@
|
||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define 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 <QMainWindow>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
@ -46,27 +61,13 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QToolTip>
|
#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_LEFT_AREA 41
|
||||||
#define W_VERTICAL_LINE 1 //左边竖线宽度
|
#define W_VERTICAL_LINE 1 //左边竖线宽度
|
||||||
#define W_RIGHT_AREA 438 //41 + 1 + 438 = 480
|
#define W_RIGHT_AREA 438 //41 + 1 + 438 = 480
|
||||||
#define L_VERTICAL_LINE_TO_ITEM 4 //竖线到item左侧的距离
|
#define L_VERTICAL_LINE_TO_ITEM 4 //竖线到item左侧的距离
|
||||||
|
|
||||||
#define X_LEFT_WIFI_BALL 412 //白色小球在左边
|
#define X_LEFT_WIFI_BALL 422 //白色小球在左边
|
||||||
#define X_RIGHT_WIFI_BALL 438 //白色小球在右边
|
#define X_RIGHT_WIFI_BALL 448 //白色小球在右边
|
||||||
#define Y_WIFI_BALL 22 //白色小球y坐标
|
#define Y_WIFI_BALL 22 //白色小球y坐标
|
||||||
#define X_ITEM 46 //item到窗口左侧的距离 41 + 1 + 4 = 46
|
#define X_ITEM 46 //item到窗口左侧的距离 41 + 1 + 4 = 46
|
||||||
#define W_ITEM 424
|
#define W_ITEM 424
|
||||||
|
@ -91,7 +92,7 @@
|
||||||
|
|
||||||
#define W_BTN_FUN 57
|
#define W_BTN_FUN 57
|
||||||
#define H_BTN_FUN 14
|
#define H_BTN_FUN 14
|
||||||
#define X_BTN_FUN 365
|
#define X_BTN_FUN 371
|
||||||
#define Y_BTN_FUN 87 //新建网络,加入网络按钮的宽高、x坐标、y坐标
|
#define Y_BTN_FUN 87 //新建网络,加入网络按钮的宽高、x坐标、y坐标
|
||||||
|
|
||||||
#define W_NO_ITEM_TIP 220
|
#define W_NO_ITEM_TIP 220
|
||||||
|
@ -292,7 +293,7 @@ private slots:
|
||||||
void onBtnAddNetClicked();
|
void onBtnAddNetClicked();
|
||||||
void onBtnCreateNetClicked();
|
void onBtnCreateNetClicked();
|
||||||
signals:
|
signals:
|
||||||
void deleteRedundantNet();
|
void disConnSparedNet(QString type);
|
||||||
|
|
||||||
void waitWifiStop();
|
void waitWifiStop();
|
||||||
void waitLanStop();
|
void waitLanStop();
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<widget class="QLabel" name="lbBtnWifiBG">
|
<widget class="QLabel" name="lbBtnWifiBG">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>410</x>
|
<x>420</x>
|
||||||
<y>20</y>
|
<y>20</y>
|
||||||
<width>50</width>
|
<width>50</width>
|
||||||
<height>24</height>
|
<height>24</height>
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
<widget class="QPushButton" name="btnWifi">
|
<widget class="QPushButton" name="btnWifi">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>410</x>
|
<x>420</x>
|
||||||
<y>20</y>
|
<y>20</y>
|
||||||
<width>50</width>
|
<width>50</width>
|
||||||
<height>24</height>
|
<height>24</height>
|
||||||
|
@ -147,7 +147,7 @@
|
||||||
<widget class="QLabel" name="lbBtnWifiBall">
|
<widget class="QLabel" name="lbBtnWifiBall">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>438</x>
|
<x>448</x>
|
||||||
<y>22</y>
|
<y>22</y>
|
||||||
<width>20</width>
|
<width>20</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
|
@ -199,7 +199,7 @@
|
||||||
<widget class="QLabel" name="lbWifiListBG">
|
<widget class="QLabel" name="lbWifiListBG">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>1</x>
|
<x>2</x>
|
||||||
<y>57</y>
|
<y>57</y>
|
||||||
<width>37</width>
|
<width>37</width>
|
||||||
<height>37</height>
|
<height>37</height>
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "ui_oneconnform.h"
|
#include "ui_oneconnform.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "wireless-security/dlgconnhidwifi.h"
|
#include "wireless-security/dlgconnhidwifi.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
extern int currentActWifiSignalLv;
|
extern int currentActWifiSignalLv;
|
||||||
|
|
||||||
|
@ -603,7 +604,9 @@ void OneConnForm::slotConnWifiResult(int connFlag){
|
||||||
QString txt(tr("Conn Wifi Failed"));//"连接 Wifi 失败"
|
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());
|
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";
|
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的信号强度
|
// 设置全局变量,当前连接Wifi的信号强度
|
||||||
|
|
58
utils.cpp
58
utils.cpp
|
@ -17,7 +17,60 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "utils.h"
|
#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){}
|
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)
|
CustomStyle::CustomStyle(const QString &proxyStyleName, QObject *parent) : QProxyStyle (proxyStyleName)
|
||||||
{
|
{
|
||||||
|
|
55
utils.h
55
utils.h
|
@ -1,6 +1,11 @@
|
||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
@ -15,18 +20,23 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#include <string.h>
|
// The Utils class, used to do some assist function
|
||||||
#include <unistd.h>
|
|
||||||
|
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
|
class UseQssFile
|
||||||
{
|
{
|
||||||
public:
|
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
|
class NetworkSpeed : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -61,22 +67,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
* \brief The CustomStyle class
|
// The CustomStyle class, inherit from class QProxyStyle, to change control style customize
|
||||||
* \details
|
|
||||||
* 自定义QStyle
|
|
||||||
* 基于QProxyStyle,默认使用QProxyStyle的实例绘制控件,你需要针对某一个控件重新实现若干对应的接口。
|
|
||||||
* QProxyStyle可以从现有的qt style实例化,我们只需要知道这个style的名字即可。
|
|
||||||
* 这种做法带来了不错的扩展性和自由度,因为我们不需要将某个style的代码直接引入我们的项目中,
|
|
||||||
* 也能够“继承”这个style类进行二次开发。
|
|
||||||
*
|
|
||||||
* 下面的方法展现了QStyle的所有的接口,使用QStyle进行控件的绘制使得qt应用能够进行风格的切换,
|
|
||||||
* 从而达到不修改项目源码却对应用外观产生巨大影响的效果。
|
|
||||||
*
|
|
||||||
* \note
|
|
||||||
* 需要注意QStyle与QSS并不兼容,因为QSS本身其实上也是QStyle的一种实现,对一个控件而言,本身理论上只能
|
|
||||||
* 在同一时间调用唯一一个QStyle进行绘制。
|
|
||||||
*/
|
|
||||||
class CustomStyle : public QProxyStyle
|
class CustomStyle : public QProxyStyle
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -74,7 +74,8 @@ DlgConnHidWifi::DlgConnHidWifi(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…")); //新建...
|
||||||
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
@ -193,7 +194,8 @@ void DlgConnHidWifi::changeWindow(){
|
||||||
ui->btnConnect->setEnabled(false);
|
ui->btnConnect->setEnabled(false);
|
||||||
}else if (ui->cbxConn->currentIndex() >= 1){
|
}else if (ui->cbxConn->currentIndex() >= 1){
|
||||||
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >/tmp/kylin-nm-connshow";
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
@ -240,7 +242,8 @@ void DlgConnHidWifi::on_btnConnect_clicked()
|
||||||
do{
|
do{
|
||||||
sleep(1);
|
sleep(1);
|
||||||
QString cmd = "nmcli device wifi connect " + wifiName + " password '' hidden yes >/tmp/kylin-nm-btoutput";
|
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");
|
QFile file("/tmp/kylin-nm-btoutput");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
@ -279,7 +282,8 @@ void DlgConnHidWifi::slotStartLoading()
|
||||||
void DlgConnHidWifi::on_execSecConn()
|
void DlgConnHidWifi::on_execSecConn()
|
||||||
{
|
{
|
||||||
QString str = "nmcli device wifi connect " + strWifiname + " password ''";
|
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() ));
|
connect(this, SIGNAL(sendMessage()), this,SLOT(emitSignal() ));
|
||||||
QTimer::singleShot(3*1000, this, SLOT(emitSignal() ));
|
QTimer::singleShot(3*1000, this, SLOT(emitSignal() ));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include "ui_dlgconnhidwifileap.h"
|
#include "ui_dlgconnhidwifileap.h"
|
||||||
#include "kylinheadfile.h"
|
#include "kylinheadfile.h"
|
||||||
|
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
DlgConnHidWifiLeap::DlgConnHidWifiLeap(QWidget *parent) :
|
DlgConnHidWifiLeap::DlgConnHidWifiLeap(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::DlgConnHidWifiLeap)
|
ui(new Ui::DlgConnHidWifiLeap)
|
||||||
|
@ -73,7 +75,8 @@ DlgConnHidWifiLeap::DlgConnHidWifiLeap(QWidget *parent) :
|
||||||
ui->btnConnect->setText(tr("Connect")); //连接
|
ui->btnConnect->setText(tr("Connect")); //连接
|
||||||
|
|
||||||
ui->cbxConn->addItem(tr("C_reate…")); //新建...
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "ui_dlgconnhidwifisecfast.h"
|
#include "ui_dlgconnhidwifisecfast.h"
|
||||||
#include "kylinheadfile.h"
|
#include "kylinheadfile.h"
|
||||||
|
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
DlgConnHidWifiSecFast::DlgConnHidWifiSecFast(int type, QWidget *parent) :
|
DlgConnHidWifiSecFast::DlgConnHidWifiSecFast(int type, QWidget *parent) :
|
||||||
WepOrWpa(type),
|
WepOrWpa(type),
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
|
@ -93,7 +95,8 @@ DlgConnHidWifiSecFast::DlgConnHidWifiSecFast(int type, QWidget *parent) :
|
||||||
ui->btnConnect->setText(tr("Connect")); //连接
|
ui->btnConnect->setText(tr("Connect")); //连接
|
||||||
|
|
||||||
ui->cbxConn->addItem(tr("C_reate…")); //新建...
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "ui_dlgconnhidwifisecleap.h"
|
#include "ui_dlgconnhidwifisecleap.h"
|
||||||
#include "kylinheadfile.h"
|
#include "kylinheadfile.h"
|
||||||
|
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
DlgConnHidWifiSecLeap::DlgConnHidWifiSecLeap(int type, QWidget *parent) :
|
DlgConnHidWifiSecLeap::DlgConnHidWifiSecLeap(int type, QWidget *parent) :
|
||||||
WepOrWpa(type),
|
WepOrWpa(type),
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
|
@ -79,7 +81,8 @@ DlgConnHidWifiSecLeap::DlgConnHidWifiSecLeap(int type, QWidget *parent) :
|
||||||
ui->btnConnect->setText(tr("Connect")); //连接
|
ui->btnConnect->setText(tr("Connect")); //连接
|
||||||
|
|
||||||
ui->cbxConn->addItem(tr("C_reate…")); //新建...
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "ui_dlgconnhidwifisecpeap.h"
|
#include "ui_dlgconnhidwifisecpeap.h"
|
||||||
#include "kylinheadfile.h"
|
#include "kylinheadfile.h"
|
||||||
|
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
DlgConnHidWifiSecPeap::DlgConnHidWifiSecPeap(int type, QWidget *parent) :
|
DlgConnHidWifiSecPeap::DlgConnHidWifiSecPeap(int type, QWidget *parent) :
|
||||||
WepOrWpa(type),
|
WepOrWpa(type),
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
|
@ -104,7 +106,8 @@ DlgConnHidWifiSecPeap::DlgConnHidWifiSecPeap(int type, QWidget *parent) :
|
||||||
ui->btnConnect->setText(tr("Connect")); //连接
|
ui->btnConnect->setText(tr("Connect")); //连接
|
||||||
|
|
||||||
ui->cbxConn->addItem("新建...");
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "ui_dlgconnhidwifisecpwd.h"
|
#include "ui_dlgconnhidwifisecpwd.h"
|
||||||
#include "kylinheadfile.h"
|
#include "kylinheadfile.h"
|
||||||
|
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
DlgConnHidWifiSecPwd::DlgConnHidWifiSecPwd(int type, QWidget *parent) :
|
DlgConnHidWifiSecPwd::DlgConnHidWifiSecPwd(int type, QWidget *parent) :
|
||||||
WepOrWpa(type),
|
WepOrWpa(type),
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
|
@ -80,7 +82,8 @@ DlgConnHidWifiSecPwd::DlgConnHidWifiSecPwd(int type, QWidget *parent) :
|
||||||
ui->btnConnect->setText(tr("Connect")); //连接
|
ui->btnConnect->setText(tr("Connect")); //连接
|
||||||
|
|
||||||
ui->cbxConn->addItem(tr("C_reate…")); //新建...
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include "ui_dlgconnhidwifisectls.h"
|
#include "ui_dlgconnhidwifisectls.h"
|
||||||
#include "kylinheadfile.h"
|
#include "kylinheadfile.h"
|
||||||
|
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
DlgConnHidWifiSecTls::DlgConnHidWifiSecTls(int type, QWidget *parent) :
|
DlgConnHidWifiSecTls::DlgConnHidWifiSecTls(int type, QWidget *parent) :
|
||||||
WepOrWpa(type),
|
WepOrWpa(type),
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
|
@ -103,7 +105,8 @@ DlgConnHidWifiSecTls::DlgConnHidWifiSecTls(int type, QWidget *parent) :
|
||||||
ui->btnConnect->setText(tr("Connect")); //连接
|
ui->btnConnect->setText(tr("Connect")); //连接
|
||||||
|
|
||||||
ui->cbxConn->addItem(tr("C_reate…")); //新建...
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "ui_dlgconnhidwifisectunneltls.h"
|
#include "ui_dlgconnhidwifisectunneltls.h"
|
||||||
#include "kylinheadfile.h"
|
#include "kylinheadfile.h"
|
||||||
|
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
DlgConnHidWifiSecTunnelTLS::DlgConnHidWifiSecTunnelTLS(int type, QWidget *parent) :
|
DlgConnHidWifiSecTunnelTLS::DlgConnHidWifiSecTunnelTLS(int type, QWidget *parent) :
|
||||||
WepOrWpa(type),
|
WepOrWpa(type),
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
|
@ -101,7 +103,8 @@ DlgConnHidWifiSecTunnelTLS::DlgConnHidWifiSecTunnelTLS(int type, QWidget *parent
|
||||||
ui->btnConnect->setText(tr("Connect")); //连接
|
ui->btnConnect->setText(tr("Connect")); //连接
|
||||||
|
|
||||||
ui->cbxConn->addItem(tr("C_reate…")); //新建...
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include "ui_dlgconnhidwifiwep.h"
|
#include "ui_dlgconnhidwifiwep.h"
|
||||||
#include "kylinheadfile.h"
|
#include "kylinheadfile.h"
|
||||||
|
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
DlgConnHidWifiWep::DlgConnHidWifiWep(int type, QWidget *parent) :
|
DlgConnHidWifiWep::DlgConnHidWifiWep(int type, QWidget *parent) :
|
||||||
WepPwdOrCode(type),
|
WepPwdOrCode(type),
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
|
@ -79,7 +81,8 @@ DlgConnHidWifiWep::DlgConnHidWifiWep(int type, QWidget *parent) :
|
||||||
ui->btnConnect->setText(tr("Connect")); //连接
|
ui->btnConnect->setText(tr("Connect")); //连接
|
||||||
|
|
||||||
ui->cbxConn->addItem(tr("C_reate…")); //新建...
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
|
|
@ -80,7 +80,8 @@ DlgConnHidWifiWpa::DlgConnHidWifiWpa(int type, MainWindow *mainWindow, QWidget *
|
||||||
ui->btnConnect->setText(tr("Connect")); //连接
|
ui->btnConnect->setText(tr("Connect")); //连接
|
||||||
|
|
||||||
ui->cbxConn->addItem(tr("C_reate…")); //新建...
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
@ -200,7 +201,8 @@ void DlgConnHidWifiWpa::changeWindow(){
|
||||||
connect(connHidWifi, SIGNAL(reSetWifiList() ), mw, SLOT(on_btnWifiList_clicked()) );
|
connect(connHidWifi, SIGNAL(reSetWifiList() ), mw, SLOT(on_btnWifiList_clicked()) );
|
||||||
}else if (ui->cbxConn->currentIndex() >= 1){
|
}else if (ui->cbxConn->currentIndex() >= 1){
|
||||||
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >/tmp/kylin-nm-connshow";
|
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");
|
QFile file("/tmp/kylin-nm-connshow");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
qDebug()<<"Can't open the file!";
|
qDebug()<<"Can't open the file!";
|
||||||
|
@ -251,7 +253,8 @@ void DlgConnHidWifiWpa::on_btnConnect_clicked()
|
||||||
do{
|
do{
|
||||||
sleep(1);
|
sleep(1);
|
||||||
QString cmd = "nmcli device wifi connect " + wifiName + " password " + wifiPassword + " hidden yes >/tmp/kylin-nm-btoutput";
|
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");
|
QFile file("/tmp/kylin-nm-btoutput");
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
@ -308,7 +311,8 @@ void DlgConnHidWifiWpa::slotStartLoading()
|
||||||
void DlgConnHidWifiWpa::on_execSecConn()
|
void DlgConnHidWifiWpa::on_execSecConn()
|
||||||
{
|
{
|
||||||
QString str = "nmcli device wifi connect " + strWifiname + " password " + strWifiPassword;
|
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() ));
|
connect(this, SIGNAL(sendMessage()), this,SLOT(emitSignal() ));
|
||||||
QTimer::singleShot(3*1000, this, SLOT(emitSignal() ));
|
QTimer::singleShot(3*1000, this, SLOT(emitSignal() ));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue