Delete code do not need anymore, add more comments

This commit is contained in:
chenlelin 2020-05-28 14:44:04 +08:00
parent d594ca4d85
commit 18f6c73c5c
18 changed files with 591 additions and 1073 deletions

View File

@ -55,7 +55,6 @@ SOURCES += \
src/loadingdiv.cpp \
src/main.cpp \
src/mainwindow.cpp \
src/notifysend.cpp \
src/oneconnform.cpp \
src/onelancform.cpp \
src/utils.cpp \
@ -81,7 +80,6 @@ HEADERS += \
src/kylin-network-interface.h \
src/loadingdiv.h \
src/mainwindow.h \
src/notifysend.h \
src/oneconnform.h \
src/onelancform.h \
src/utils.h \
@ -101,7 +99,6 @@ HEADERS += \
FORMS += \
src/confform.ui \
src/mainwindow.ui \
src/notifysend.ui \
src/oneconnform.ui \
src/onelancform.ui \
wireless-security/dlgconnhidwifi.ui \

View File

@ -29,7 +29,8 @@
#include <QRegExp>
#include <QStandardPaths>
BackThread::BackThread(QObject *parent) : QObject(parent){
BackThread::BackThread(QObject *parent) : QObject(parent)
{
cmdConnWifi = new QProcess(this);
connect(cmdConnWifi , SIGNAL(readyReadStandardOutput()) , this , SLOT(on_readoutput()));
connect(cmdConnWifi , SIGNAL(readyReadStandardError()) , this , SLOT(on_readerror()));
@ -41,8 +42,10 @@ BackThread::~BackThread()
{
cmdConnWifi->close();
}
IFace* BackThread::execGetIface(){
\
//get the connection state of wired and wireles network
IFace* BackThread::execGetIface()
{
IFace *iface = new IFace();
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
@ -51,13 +54,14 @@ IFace* BackThread::execGetIface(){
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f TYPE,DEVICE,STATE device > " + localPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device' in function 'execGetIface' failed");}
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device' in function 'execGetIface' failed");}
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-iface!");
qDebug()<<"Can't open the file /tmp/kylin-nm-iface!"<<endl;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// print information if can not open file ~/.config/kylin-nm-iface
syslog(LOG_ERR, "Can't open the file ~/.config/kylin-nm-iface!");
qDebug()<<"Can't open the file ~/.config/kylin-nm-iface!";
}
QString txt = file.readAll();
QStringList txtList = txt.split("\n");
@ -66,9 +70,9 @@ IFace* BackThread::execGetIface(){
iface->lstate = 2;
iface->wstate = 2;
for(int i = 1; i < txtList.size(); i ++){
for (int i = 1; i < txtList.size(); i ++) {
QString line = txtList.at(i);
if(line != ""){
if (line != "") {
int index1 = line.indexOf(" ");
QString type = line.left(index1);
QString lastStr = line.mid(index1).trimmed();
@ -76,30 +80,32 @@ IFace* BackThread::execGetIface(){
QString iname = lastStr.left(index2);
QString istateStr = lastStr.mid(index2).trimmed();
if(type == "ethernet"){
if (type == "ethernet") {
// if type is wired network
iface->lname = iname;
if(istateStr == "unmanaged"){
iface->lstate = 2;
if (istateStr == "unmanaged") {
iface->lstate = 2; //switch of wired device is off
}
if(istateStr == "disconnected" || istateStr == "unavailable"){
iface->lstate = 1;
if (istateStr == "disconnected" || istateStr == "unavailable") {
iface->lstate = 1; //wired network is disconnected
}
if(istateStr == "connected"){
iface->lstate = 0;
if (istateStr == "connected") {
iface->lstate = 0; //wired network is connected
}
}
if(type == "wifi"){
if (type == "wifi") {
// if type is wireless network
iface->wname = iname;
if(istateStr == "unmanaged" || istateStr == "unavailable"){
iface->wstate = 2;
if (istateStr == "unmanaged" || istateStr == "unavailable") {
iface->wstate = 2; //switch of wireless device is off
}
if(istateStr == "disconnected"){
iface->wstate = 1;
if (istateStr == "disconnected") {
iface->wstate = 1; //wireless network is disconnected
}
if(istateStr == "connected"){
iface->wstate = 0;
if (istateStr == "connected") {
iface->wstate = 0; //wireless network is connected
}
}
}
@ -108,14 +114,16 @@ IFace* BackThread::execGetIface(){
return iface;
}
void BackThread::execEnNet(){
//turn on the switch of network
void BackThread::execEnNet()
{
char *chr = "nmcli networking on";
Utils::m_system(chr);
// int status = system("nmcli networking on");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli networking on' in function 'execEnNet' failed");}
while(1){
if (execGetIface()->lstate != 2){
// int status = system("nmcli networking on");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli networking on' in function 'execEnNet' failed");}
while (1) {
if (execGetIface()->lstate != 2) {
sleep(3);
emit enNetDone();
emit btFinish();
@ -125,15 +133,17 @@ void BackThread::execEnNet(){
}
}
void BackThread::execDisNet(){
if (execGetIface()->wstate != 2){
//turn off the switch of wireless network first, then turn off the switch of network
void BackThread::execDisNet()
{
if (execGetIface()->wstate != 2) {
char *chr = "nmcli radio wifi off";
Utils::m_system(chr);
// int status = system("nmcli radio wifi off");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi off' in function 'execDisNet' failed");}
while(1){
if (execGetIface()->wstate == 2){
// int status = system("nmcli radio wifi off");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi off' in function 'execDisNet' failed");}
while (1) {
if (execGetIface()->wstate == 2) {
emit disWifiDone();
emit btFinish();
break;
@ -144,10 +154,10 @@ void BackThread::execDisNet(){
char *chr1 = "nmcli networking off";
Utils::m_system(chr1);
// int status1 = system("nmcli networking off");
// if (status1 != 0){ syslog(LOG_ERR, "execute 'nmcli networking off' in function 'execDisNet' failed");}
while(1){
if (execGetIface()->lstate == 2){
// int status1 = system("nmcli networking off");
// if (status1 != 0){ syslog(LOG_ERR, "execute 'nmcli networking off' in function 'execDisNet' failed");}
while (1) {
if (execGetIface()->lstate == 2) {
emit disNetDone();
emit btFinish();
break;
@ -156,30 +166,33 @@ void BackThread::execDisNet(){
}
}
void BackThread::execEnWifi(){
// if (execGetIface()->lstate == 2){
// char *chr = "nmcli networking on";
// Utils::m_system(chr);
// //int status = system("nmcli networking on");
// //if (status != 0){ syslog(LOG_ERR, "execute 'nmcli networking on' in function 'execEnWifi' failed");}
// while(1){
// if (execGetIface()->lstate != 2){
// emit launchLanDone();
// break;
// }
// sleep(1);
// }
// }
//turn on the switch of wireless network
void BackThread::execEnWifi()
{
//if (execGetIface()->lstate == 2){
// char *chr = "nmcli networking on";
// Utils::m_system(chr);
// //int status = system("nmcli networking on");
// //if (status != 0){ syslog(LOG_ERR, "execute 'nmcli networking on' in function 'execEnWifi' failed");}
// while(1){
// if (execGetIface()->lstate != 2){
// emit launchLanDone();
// break;
// }
// sleep(1);
// }
//}
char *chr1 = "nmcli radio wifi on";
Utils::m_system(chr1);
//int status1 = system("nmcli radio wifi on");
//if (status1 != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi on' in function 'execEnWifi' failed");}
while(1){
if (execGetIface()->wstate != 2){
while (1) {
if (execGetIface()->wstate != 2) {
KylinDBus objKyDbus;
while(1){
if (objKyDbus.getAccessPointsNumber() > 0){
while (1) {
if (objKyDbus.getAccessPointsNumber() > 0) {
// objKyDbus.getAccessPointsNumber()>0 standard can get wireless accesspoints now
emit enWifiDone();
emit btFinish();
break;
@ -192,13 +205,15 @@ void BackThread::execEnWifi(){
}
}
void BackThread::execDisWifi(){
//turn off the switch of wireless network
void BackThread::execDisWifi()
{
char *chr = "nmcli radio wifi off";
Utils::m_system(chr);
// int status = system("nmcli radio wifi off");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi off' in function 'execDisWifi' failed");}
while(1){
if (execGetIface()->wstate == 2){
// int status = system("nmcli radio wifi off");
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli radio wifi off' in function 'execDisWifi' failed");}
while (1) {
if (execGetIface()->wstate == 2) {
emit disWifiDone();
emit btFinish();
break;
@ -207,15 +222,18 @@ void BackThread::execDisWifi(){
}
}
void BackThread::execConnLan(QString connName){
//to connect wired network
void BackThread::execConnLan(QString connName)
{
disConnLanOrWifi("ethernet");
KylinDBus objKyDbus;
if(objKyDbus.isWiredCableOn){
if (objKyDbus.isWiredCableOn) {
// only if wired cable is plug in, can connect wired network
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "'";
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");}
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection up' in function 'execConnLan' failed");}
qDebug()<<"debug: in function execConnLan, wired net state is: "<<QString::number(execGetIface()->lstate);
syslog(LOG_DEBUG, "In function execConnLan, wired net state is: %d", execGetIface()->lstate);
emit connDone(0);
@ -226,7 +244,9 @@ void BackThread::execConnLan(QString connName){
emit btFinish();
}
void BackThread::execConnWifiPWD(QString connName, QString password){
//to connected wireless network need a password
void BackThread::execConnWifiPWD(QString connName, QString password)
{
//disConnLanOrWifi("wifi");
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
@ -234,29 +254,31 @@ void BackThread::execConnWifiPWD(QString connName, QString password){
QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '" + connName + "' password '" + password + "' > " + localPath;
Utils::m_system(cmdStr.toUtf8().data());
// int status = system(cmdStr.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'execConnWifiPWD' failed");}
// int status = system(cmdStr.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'execConnWifiPWD' failed");}
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
syslog(LOG_DEBUG, "Can't open the file /tmp/kylin-nm-btoutput !");
qDebug()<<"Can't open the file /tmp/kylin-nm-btoutput !"<<endl;
}
QString line = file.readLine();
file.close();
if(line.indexOf("successfully") != -1){
if (line.indexOf("successfully") != -1) {
emit connDone(0);
qDebug()<<"debug: in function execConnWifiPWD, wireless net state is: "<<QString::number(execGetIface()->wstate);
syslog(LOG_DEBUG, "In function execConnWifiPWD, wireless net state is: %d", execGetIface()->wstate);
}else{
} else {
emit connDone(1);
}
emit btFinish();
}
void BackThread::execConnWifi(QString connName){
//to connected wireless network driectly do not need a password
void BackThread::execConnWifi(QString connName)
{
//disConnLanOrWifi("wifi");
QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "'\n";
@ -268,13 +290,13 @@ void BackThread::on_readoutput()
QString str = cmdConnWifi->readAllStandardOutput();
cmdConnWifi->close();
qDebug()<<"on_readoutput: "<< str;
if(str.indexOf("successfully") != -1){
emit connDone(0);
if (str.indexOf("successfully") != -1) {
emit connDone(0); //send this signal if connect net successfully
qDebug()<<"debug: in function on_readoutput, wireless net state is: "<<QString::number(execGetIface()->wstate);
syslog(LOG_DEBUG, "In function on_readoutput, wireless net state is: %d", execGetIface()->wstate);
}else if(str.indexOf("unknown") != -1){
} else if(str.indexOf("unknown") != -1) {
emit connDone(2);
}else{
} else {
emit connDone(1);
}
@ -285,28 +307,30 @@ void BackThread::on_readerror()
QString str = cmdConnWifi->readAllStandardError();
cmdConnWifi->close();
qDebug()<<"on_readerror: "<< str;
if(str.indexOf("successfully") != -1){
if (str.indexOf("successfully") != -1) {
emit connDone(0);
}else if(str.indexOf("unknown") != -1 || str.indexOf("not exist") != -1){
emit connDone(2);
}else{
emit connDone(1);
} else if(str.indexOf("unknown") != -1 || str.indexOf("not exist") != -1) {
emit connDone(2); //send this signal if the network we want to connect has not a configuration file
} else {
emit connDone(1); //send this signal if connect net failed
}
emit btFinish();
}
QString BackThread::getConnProp(QString connName){
//get property of connected network
QString BackThread::getConnProp(QString connName)
{
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connprop";
QString cmd = "nmcli connection show '" + connName + "' > " + localPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'getConnProp' failed");}
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'getConnProp' failed");}
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connprop!");
qDebug()<<"Can't open the file /tmp/kylin-nm-connprop!"<<endl;
}
@ -317,34 +341,34 @@ QString BackThread::getConnProp(QString connName){
QString rtn = "";
foreach (QString line, txtLine) {
if(line.startsWith("ipv4.method:")){
if (line.startsWith("ipv4.method:")) {
QString v4method = line.mid(12).trimmed();
rtn += "method:" + v4method + "|";
}
if(line.startsWith("ipv4.addresses:")){
if (line.startsWith("ipv4.addresses:")) {
QString value = line.mid(15).trimmed();
if(value == "--"){
if (value == "--") {
rtn += "addr:|mask:|";
}else{
} else {
QString addr = value.split("/").at(0);
QString mask = value.trimmed().split("/").at(1);
rtn += "addr:" + addr + "|";
rtn += "mask:" + mask + "|";
}
}
if(line.startsWith("ipv4.gateway:")){
if (line.startsWith("ipv4.gateway:")) {
QString value = line.mid(13).trimmed();
if(value == "--"){
if (value == "--") {
rtn += "gateway:|";
}else{
} else {
rtn += "gateway:" + value + "|";
}
}
if(line.startsWith("ipv4.dns:")){
if (line.startsWith("ipv4.dns:")) {
QString value = line.mid(9).trimmed();
if(value == "--"){
if (value == "--") {
rtn += "dns:|";
}else{
} else {
rtn += "dns:" + value + "|";
}
}
@ -353,43 +377,19 @@ QString BackThread::getConnProp(QString connName){
return rtn.left(rtn.length() - 1);
}
bool BackThread::execChkWifiExist(QString connName){
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-chkwifiexist";
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection show '" + connName + "' > " + localPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'execChkWifiExist' failed");}
QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-chkwifiexist!");
qDebug()<<"Can't open the file /tmp/kylin-nm-chkwifiexist!"<<endl;
}
QString line = file.readLine();
file.close();
if(line.length() < 2 || line.indexOf("Error:") != -1){
return false;
}else{
return true;
}
}
QString BackThread::execChkLanWidth(QString ethName){
//get band width of wired network
QString BackThread::execChkLanWidth(QString ethName)
{
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-bandwidth";
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';ethtool '" + ethName + "' | grep Speed > " + localPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'ethtool' in function 'execChkLanWidth' failed");}
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'ethtool' in function 'execChkLanWidth' failed");}
QFile file(localPath);
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-bandwidth!");
qDebug()<<"Can't open the file /tmp/kylin-nm-bandwidth!"<<endl;
}
@ -397,7 +397,7 @@ QString BackThread::execChkLanWidth(QString ethName){
file.close();
QStringList params = line.split(":");
if(params.size() < 2){
if (params.size() < 2) {
return "";
}
@ -405,20 +405,21 @@ QString BackThread::execChkLanWidth(QString ethName){
return rtn.trimmed();
}
//disconnected spare ethernet or wifi
void BackThread::disConnSparedNetSlot(QString type)
{
sleep(1);
if (type == "wifi"){
if (type == "wifi") {
disConnLanOrWifi("wifi");
} else if(type == "ethernet") {
disConnLanOrWifi("ethernet");
}
emit disFinish();
emit ttFinish();
}
//disconnected ethernet or wifi according to network type
void BackThread::disConnLanOrWifi(QString type)
{
QString strSlist;

View File

@ -47,7 +47,6 @@ public:
IFace* execGetIface();
QString getConnProp(QString connName);
bool execChkWifiExist(QString connName);
QString execChkLanWidth(QString ethName);
QProcess *cmdConnWifi = nullptr;

View File

@ -141,32 +141,37 @@ ConfForm::~ConfForm()
delete ui;
}
void ConfForm::mousePressEvent(QMouseEvent *event){
if(event->button() == Qt::LeftButton){
void ConfForm::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
this->isPress = true;
this->winPos = this->pos();
this->dragPos = event->globalPos();
event->accept();
}
}
void ConfForm::mouseReleaseEvent(QMouseEvent *event){
void ConfForm::mouseReleaseEvent(QMouseEvent *event)
{
this->isPress = false;
}
void ConfForm::mouseMoveEvent(QMouseEvent *event){
if(this->isPress){
void ConfForm::mouseMoveEvent(QMouseEvent *event)
{
if (this->isPress) {
this->move(this->winPos - (this->dragPos - event->globalPos()));
event->accept();
}
}
void ConfForm::setProp(QString connName, QString v4method, QString addr, QString mask, QString gateway, QString dns, bool isActConf){
//网络配置参数设置界面的显示内容
void ConfForm::setProp(QString connName, QString v4method, QString addr, QString mask, QString gateway, QString dns, bool isActConf)
{
this->isActConf = isActConf;
ui->leName->setText(connName);
if(v4method == "auto" || v4method == ""){
if (v4method == "auto" || v4method == "") {
ui->cbType->setCurrentIndex(0);
cbTypeChanged(0);
}else{
} else {
ui->cbType->setCurrentIndex(1);
cbTypeChanged(1);
}
@ -175,30 +180,31 @@ void ConfForm::setProp(QString connName, QString v4method, QString addr, QString
ui->leGateway->setText(gateway);
// 配置中有多个DNS只处理前两个
if(dns.indexOf(",") != -1){
if (dns.indexOf(",") != -1) {
QStringList dnss = dns.split(",");
ui->leDns->setText(dnss.at(0));
ui->leDns2->setText(dnss.at(1));
}else{
} else {
ui->leDns->setText(dns);
ui->leDns2->setText("");
}
if(mask == "24"){
if (mask == "24") {
ui->cbMask->setCurrentIndex(0);
}else if(mask == "23"){
} else if(mask == "23") {
ui->cbMask->setCurrentIndex(1);
}else if(mask == "22"){
} else if(mask == "22") {
ui->cbMask->setCurrentIndex(2);
}else if(mask == "16"){
} else if(mask == "16") {
ui->cbMask->setCurrentIndex(3);
}else if(mask == "8"){
} else if(mask == "8") {
ui->cbMask->setCurrentIndex(4);
}else{
} else {
ui->cbMask->setCurrentIndex(0);
}
}
//点击了创建新的网络的按钮
void ConfForm::on_btnCreate_clicked()
{
QString cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' type ethernet";
@ -206,7 +212,7 @@ void ConfForm::on_btnCreate_clicked()
//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->isCreateNewNet = true;
this->on_btnOk_clicked();
@ -219,28 +225,29 @@ void ConfForm::on_btnCreate_clicked()
this->hide();
}
//点击了保存更改网络设置的按钮
void ConfForm::on_btnOk_clicked()
{
QString mask = "";
if(ui->cbMask->currentIndex() == 0){
if (ui->cbMask->currentIndex() == 0) {
mask = "24";
}else if(ui->cbMask->currentIndex() == 1){
} else if(ui->cbMask->currentIndex() == 1) {
mask = "23";
}else if(ui->cbMask->currentIndex() == 2){
} else if(ui->cbMask->currentIndex() == 2) {
mask = "22";
}else if(ui->cbMask->currentIndex() == 3){
} else if(ui->cbMask->currentIndex() == 3) {
mask = "16";
}else if(ui->cbMask->currentIndex() == 4){
} else if(ui->cbMask->currentIndex() == 4) {
mask = "8";
}else{
} else {
mask = "24";
}
if(ui->cbType->currentIndex() == 0){
if (ui->cbType->currentIndex() == 0) {
kylin_network_set_automethod(ui->leName->text().toUtf8().data());
}else{
} else {
QString dnss = ui->leDns->text();
if(ui->leDns2->text() != ""){
if (ui->leDns2->text() != "") {
dnss.append(",");
dnss.append(ui->leDns2->text());
}
@ -255,7 +262,7 @@ void ConfForm::on_btnOk_clicked()
kylindbus.showDesktopNotify(txt);
if (!this->isCreateNewNet) {
if(this->isActConf == true){
if (this->isActConf == true) {
// 如果是修改当前连接的网络,则修改设置后简略重连网络
//QString cmd = "/usr/share/kylin-nm/shell/connup.sh '" + ui->leName->text() + "'";
kylindbus.connectWiredNet(ui->leName->text()); //reconnect this wired network
@ -271,20 +278,23 @@ void ConfForm::on_btnOk_clicked()
this->isCreateNewNet = false;
}
//点击取消按钮
void ConfForm::on_btnCancel_clicked()
{
this->hide();
}
void ConfForm::cbTypeChanged(int index){
if (isShowSaveBtn){
//根据需要设置的种类(自动或手动等)显示界面内容
void ConfForm::cbTypeChanged(int index)
{
if (isShowSaveBtn) {
ui->leName->setEnabled(false);
ui->btnOk->show();
ui->btnCreate->hide();
ui->lbLeftupTitle->setText(tr("Edit Network"));
}
if(index == 0){
if (index == 0) {
ui->lineUp->hide();
ui->lineDown->hide();
ui->wgManual->hide();
@ -295,7 +305,7 @@ void ConfForm::cbTypeChanged(int index){
this->resize(432, 230);
}
if(index == 1){
if (index == 1) {
ui->lineUp->show();
ui->lineDown->show();
ui->wgManual->show();
@ -306,7 +316,7 @@ void ConfForm::cbTypeChanged(int index){
this->resize(432, 510);
}
if(index == 3){
if (index == 3) {
ui->btnOk->setStyleSheet(btnOffQss);
ui->btnOk->setEnabled(false);
@ -328,50 +338,56 @@ void ConfForm::cbTypeChanged(int index){
}
}
//编辑网络名称
void ConfForm::on_leName_textEdited(const QString &arg1)
{
this->setEnableOfBtn();
}
//编辑网络ip
void ConfForm::on_leAddr_textEdited(const QString &arg1)
{
this->setEnableOfBtn();
}
//编辑网络网关
void ConfForm::on_leGateway_textEdited(const QString &arg1)
{
this->setEnableOfBtn();
}
//编辑网络DNS
void ConfForm::on_leDns_textEdited(const QString &arg1)
{
this->setEnableOfBtn();
}
//编辑网络备用DNS
void ConfForm::on_leDns2_textEdited(const QString &arg1)
{
// this->setEnableOfBtn();
}
//设置界面按钮是否可点击
void ConfForm::setEnableOfBtn()
{
if (ui->leName->text().size() == 0 ){
if (ui->leName->text().size() == 0 ) {
this->setBtnEnableFalse();
return;
}
if (ui->cbType->currentIndex() == 1){
if (!this->getTextEditState(ui->leAddr->text()) ){
if (ui->cbType->currentIndex() == 1) {
if (!this->getTextEditState(ui->leAddr->text()) ) {
this->setBtnEnableFalse();
return;
}
if (!this->getTextEditState(ui->leGateway->text()) ){
if (!this->getTextEditState(ui->leGateway->text()) ) {
this->setBtnEnableFalse();
return;
}
if (!this->getTextEditState(ui->leDns->text()) ){
if (!this->getTextEditState(ui->leDns->text()) ) {
this->setBtnEnableFalse();
return;
}
@ -384,6 +400,7 @@ void ConfForm::setEnableOfBtn()
ui->btnCreate->setEnabled(true);
}
//文本的输入要符合ip的格式要求
bool ConfForm::getTextEditState(QString text)
{
QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
@ -395,6 +412,7 @@ bool ConfForm::getTextEditState(QString text)
return match;
}
//设置创建或保存按钮不可点击
void ConfForm::setBtnEnableFalse()
{
ui->btnOk->setStyleSheet(btnOffQss);

View File

@ -19,8 +19,6 @@
#ifndef CONFFORM_H
#define CONFFORM_H
#include "notifysend.h"
#include <QWidget>
#include <QMouseEvent>
#include <QDebug>

View File

@ -33,8 +33,10 @@ KSimpleNM::KSimpleNM(QObject *parent) : QObject(parent)
connect(runShellProcess, SIGNAL(finished(int)), this, SLOT(finishedProcess(int)));
}
void KSimpleNM::execGetLanList(){
if (isExecutingGetWifiList){
//获取有线网络列表数据
void KSimpleNM::execGetLanList()
{
if (isExecutingGetWifiList) {
syslog(LOG_DEBUG, "It is running getting wifi list when getting lan list");
qDebug()<<"debug: it is running getting wifi list when getting lan list";
isUseOldLanSlist = true;
@ -45,24 +47,30 @@ void KSimpleNM::execGetLanList(){
runShellProcess->start("nmcli -f type,device,name connection show");
}
void KSimpleNM::execGetWifiList(){
//获取无线网络列表数据
void KSimpleNM::execGetWifiList()
{
isExecutingGetWifiList = true;
shellOutput = "";
type = 1;
runShellProcess->start("nmcli -f signal,security,ssid device wifi");
}
void KSimpleNM::readProcess(){
//读取获取到的结果
void KSimpleNM::readProcess()
{
QString output = runShellProcess->readAll();
shellOutput += output;
}
void KSimpleNM::finishedProcess(int msg){
//读取完所有列表数据后发信号将数据发往mainwindow用于显示网络列表
void KSimpleNM::finishedProcess(int msg)
{
QStringList slist = shellOutput.split("\n");
if(type == 0){
if (type == 0) {
emit getLanListFinished(slist);
isExecutingGetLanList = false;
}else{
} else {
emit getWifiListFinished(slist);
isExecutingGetWifiList = false;
}

View File

@ -70,7 +70,7 @@ KylinDBus::KylinDBus(MainWindow *mainWindow, QObject *parent) :QObject(parent)
qDebug()<<"Can not find wired device object path when using dbus.";
}
if (wirelessPath.path() != ""){
if (wirelessPath.path() != "") {
QDBusConnection::systemBus().connect(QString("org.freedesktop.NetworkManager"),
QString(wirelessPath.path()),
QString("org.freedesktop.NetworkManager.Device.Wireless"),
@ -110,7 +110,7 @@ void KylinDBus::getObjectPath()
QList<QDBusObjectPath> obj_paths = obj_reply.value();
foreach (QDBusObjectPath obj_path, obj_paths){
foreach (QDBusObjectPath obj_path, obj_paths) {
QDBusInterface interface( "org.freedesktop.NetworkManager",
obj_path.path(),
"org.freedesktop.DBus.Introspectable",
@ -121,9 +121,9 @@ void KylinDBus::getObjectPath()
qDebug()<<"execute dbus method 'Introspect' is invalid in func getObjectPath()";
}
if(reply.value().indexOf("org.freedesktop.NetworkManager.Device.Wired") != -1){
if(reply.value().indexOf("org.freedesktop.NetworkManager.Device.Wired") != -1) {
wiredPath = obj_path;
} else if (reply.value().indexOf("org.freedesktop.NetworkManager.Device.Wireless") != -1){
} else if (reply.value().indexOf("org.freedesktop.NetworkManager.Device.Wireless") != -1) {
wirelessPath = obj_path;
isWirelessCardOn = true;
}
@ -139,17 +139,17 @@ void KylinDBus::getPhysicalCarrierState(int n)
QDBusReply<QVariant> reply = interface.call("Get", "org.freedesktop.NetworkManager.Device.Wired", "Carrier");
try{
if (reply.value().toString() == "true"){
try {
if (reply.value().toString() == "true") {
isWiredCableOn = true;
if (n == 1){ this->mw->onPhysicalCarrierChanged(isWiredCableOn);}
} else if (reply.value().toString() == "false"){
} else if (reply.value().toString() == "false") {
isWiredCableOn = false;
if (n == 1){ this->mw->onPhysicalCarrierChanged(isWiredCableOn);}
} else {
throw -1;
}
}catch(...){
} catch(...) {
syslog(LOG_ERR, "Error occurred when get the property 'Carrier' of Wired");
qDebug()<<"Error occurred when get the property 'Carrier' of Wired";
}
@ -209,7 +209,7 @@ void KylinDBus::getLanIp(QString netName)
QDBusReply<QList<QDBusObjectPath>> m_reply = m_interface.call("ListConnections");
QList<QDBusObjectPath> m_objNets = m_reply.value();
foreach (QDBusObjectPath objNet, m_objNets){
foreach (QDBusObjectPath objNet, m_objNets) {
QDBusInterface m_interface("org.freedesktop.NetworkManager",
objNet.path(),
"org.freedesktop.NetworkManager.Settings.Connection",
@ -221,26 +221,26 @@ void KylinDBus::getLanIp(QString netName)
QMap<QString,QMap<QString,QVariant>> map;
dbusArg1st >> map;
for(QString outside_key : map.keys() ){
for (QString outside_key : map.keys() ) {
QMap<QString,QVariant> outsideMap = map.value(outside_key);
if (outside_key == "connection") {
for (QString search_key : outsideMap.keys()){
if (search_key == "id"){
for (QString search_key : outsideMap.keys()) {
if (search_key == "id") {
//const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>();
if (netName == outsideMap.value(search_key).toString()){
if (netName == outsideMap.value(search_key).toString()) {
// qDebug()<<"aaaaaa"<<outsideMap.value(search_key).toString();
for(QString key : map.keys() ){
for (QString key : map.keys() ) {
QMap<QString,QVariant> innerMap = map.value(key);
//qDebug() << "Key: " << key;
if (key == "ipv4") {
for (QString inner_key : innerMap.keys()){
if (inner_key == "address-data"){
for (QString inner_key : innerMap.keys()) {
if (inner_key == "address-data") {
const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>();
QMap<QString,QVariant> m_map;
dbusArg2nd.beginArray();
while (!dbusArg2nd.atEnd()){
while (!dbusArg2nd.atEnd()) {
dbusArg2nd >> m_map;// append map to a vector here if you want to keep it
}
dbusArg2nd.endArray();
@ -252,13 +252,13 @@ void KylinDBus::getLanIp(QString netName)
}
if (key == "ipv6") {
for (QString inner_key : innerMap.keys()){
for (QString inner_key : innerMap.keys()) {
if (inner_key == "address-data"){
const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>();
QMap<QString,QVariant> m_map;
dbusArg2nd.beginArray();
while (!dbusArg2nd.atEnd()){
while (!dbusArg2nd.atEnd()) {
dbusArg2nd >> m_map;// append map to a vector here if you want to keep it
}
dbusArg2nd.endArray();
@ -283,39 +283,6 @@ void KylinDBus::getWifiMac(QString netName)
{
dbusWifiMac = "";
// //将wifi名转为utf-8 十进制形式
// std::vector<int> vec;
// int len_encoded;
// int len_netName = netName.size();
// for (int i=0;i<len_netName;i++){
// QTextCodec *utf8 = QTextCodec::codecForName("utf-8");
// QByteArray encoded = utf8->fromUnicode(netName.at(i)).toHex();
// len_encoded = encoded.size();
// qDebug()<<"debug: 11"<<QString::number(len_encoded);
// if (len_encoded == 2){
// QString str;
// str.append(encoded.at(0));
// str.append(encoded.at(1));
// bool ok;
// QString hex = str;
// int dec = hex.toInt(&ok, 16);
// vec.push_back(dec);
// } else if (len_encoded == 6){
// for (int j=0;j<3;j++){
// QString str = "";
// str.append(encoded.at(j*2));
// str.append(encoded.at(j*2 + 1));
// bool ok;
// QString hex = str;
// int dec = hex.toInt(&ok, 16);
// vec.push_back(dec);
// }
// }
// len_encoded = 0;
// }
QDBusInterface interface( "org.freedesktop.NetworkManager",
wirelessPath.path(),
"org.freedesktop.NetworkManager.Device.Wireless",
@ -324,7 +291,7 @@ void KylinDBus::getWifiMac(QString netName)
QDBusReply<QList<QDBusObjectPath>> reply = interface.call("GetAllAccessPoints");
QList<QDBusObjectPath> objPaths = reply.value();
foreach (QDBusObjectPath objPath, objPaths){
foreach (QDBusObjectPath objPath, objPaths) {
QDBusInterface ssid_interface( "org.freedesktop.NetworkManager",
objPath.path(),
"org.freedesktop.DBus.Properties",
@ -333,7 +300,7 @@ void KylinDBus::getWifiMac(QString netName)
QDBusReply<QVariant> ssid_replys = ssid_interface.call("Get", "org.freedesktop.NetworkManager.AccessPoint", "Ssid");
QString str_name = ssid_replys.value().toString();
if (str_name == netName){
if (str_name == netName) {
QDBusInterface path_interface( "org.freedesktop.NetworkManager",
objPath.path(),
"org.freedesktop.DBus.Properties",
@ -382,7 +349,7 @@ void KylinDBus::onNewConnection(QDBusObjectPath objPath)
QMap<QString,QMap<QString,QVariant>> map;
dbusArg1st >> map;
for(QString key : map.keys() ){
for(QString key : map.keys() ) {
if (key == "802-3-ethernet") {
emit this->updateWiredList(0);
syslog(LOG_DEBUG, "A new wired network was created.");
@ -396,7 +363,7 @@ void KylinDBus::onConnectionRemoved(QDBusObjectPath objPath)
syslog(LOG_DEBUG, "An old network was removed from configure directory.");
qDebug()<<"An old network was removed from configure directory.";
if (mw->is_btnNetList_clicked == 1){
if (mw->is_btnNetList_clicked == 1) {
emit this->updateWiredList(0);
}
}
@ -709,7 +676,7 @@ bool KylinDBus::getSwitchStatus(QString key) {
void KylinDBus::setWifiSwitchState(bool signal)
{
if(!m_gsettings) {
if (!m_gsettings) {
return ;
}
@ -723,7 +690,7 @@ void KylinDBus::setWifiSwitchState(bool signal)
void KylinDBus::setWifiCardState(bool signal)
{
if(!m_gsettings) {
if (!m_gsettings) {
return ;
}

View File

@ -38,7 +38,8 @@ LoadingDiv::LoadingDiv(QWidget *parent) : QWidget(parent)
this->hide();
}
void LoadingDiv::switchAnimStep(){
void LoadingDiv::switchAnimStep()
{
QString qpmQss = "QLabel{background-image:url(':/res/s/conning-b/";
qpmQss.append(QString::number(this->currentPage));
qpmQss.append(".png');}");
@ -46,24 +47,26 @@ void LoadingDiv::switchAnimStep(){
this->currentPage --;
if(this->currentPage < 1){
if (this->currentPage < 1) {
this->currentPage = 12;
}
this->countCurrentTime += FRAMESPEED;
if (this->countCurrentTime >= ALLTIME){
if (this->countCurrentTime >= ALLTIME) {
emit this->toStopLoading();
}
}
void LoadingDiv::startLoading(){
void LoadingDiv::startLoading()
{
this->currentPage = 12;
this->countCurrentTime = 0;
this->switchTimer->start(FRAMESPEED);
this->show();
}
void LoadingDiv::stopLoading(){
void LoadingDiv::stopLoading()
{
this->switchTimer->stop();
this->hide();
}

View File

@ -42,7 +42,7 @@ int main(int argc, char *argv[])
// 国际化
QString locale = QLocale::system().name();
QTranslator trans_global;
if(locale == "zh_CN"){
if (locale == "zh_CN") {
trans_global.load(":/translations/kylin-nm_zh_CN.qm");
//trans_global.load(":/translations/kylin-nm_bo.qm");
a.installTranslator(&trans_global);

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,6 @@
#include "kylin-dbus-interface.h"
#include "kylin-network-interface.h"
#include "utils.h"
#include "notifysend.h"
#include <fcntl.h>
#include <sys/types.h>
@ -130,11 +129,8 @@ public:
void getActiveInfo();
void initTimer();
void changeTimerState();
void checkIsWirelessDeviceOn();
void init_widget_action(QWidget *wid, QString iconstr, QString textstr);
QIcon iconLanOnline, iconLanOffline;
QIcon iconWifiFull, iconWifiHigh, iconWifiMedium, iconWifiLow;
QIcon iconConnecting;
@ -142,7 +138,6 @@ public:
QString mwBandWidth;
KylinDBus *objKyDBus = nullptr;
NetworkSpeed *objNetSpeed = nullptr;
NotifySend *m_notify = nullptr;
//状态设置,0为假1为真
int is_update_wifi_list = 0; //是否是update wifi列表而不是load wifi列表
@ -292,9 +287,6 @@ private slots:
void on_checkWifiListChanged();
void on_setNetSpeed();
void on_checkOverTime();
void on_isLanConnect();
void on_isWifiConnect();
void on_isNetOn();
// 后台回调
void enNetDone();

View File

@ -1,54 +0,0 @@
#include "notifysend.h"
#include "ui_notifysend.h"
NotifySend::NotifySend(QWidget *parent) :
QWidget(parent),
ui(new Ui::NotifySend)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
this->setAttribute(Qt::WA_TranslucentBackground);
QPainterPath path;
auto rect = this->rect();
rect.adjust(1, 1, -1, -1);
path.addRoundedRect(rect, 4, 4);
setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon()));
this->setStyleSheet("QWidget{border:none;border-radius:4px;}");
ui->backwidget->setStyleSheet("QWidget{border:1px solid rgba(255, 255, 255, 0.05);border-radius:4px;background:rgba(19,19,20,0.7);}");
ui->lbColor->setStyleSheet("QLabel{border:none;background:rgba(61,107,229,1);}");
ui->leText->setStyleSheet("QLineEdit{border:none;background:transparent;font-size:14px;color:white;font-size:14px;}");
ui->btnClose->setStyleSheet("QPushButton{background-image:url(:/res/g/close_white.png);background-color:transparent;border:none;}");
ui->btnClose->setFocusPolicy(Qt::NoFocus);
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
int d = 10; //窗口上边沿到屏幕边沿距离
int s = 10; //窗口右边沿到屏幕边沿距离
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - s, availableGeometry.y() + d);
}
NotifySend::~NotifySend()
{
delete ui;
}
void NotifySend::execNotifySend(QString text)
{
ui->leText->setText(text);
this->show();
QTimer::singleShot(4000, this, SLOT(closeNotifyDialog() ));
}
void NotifySend::closeNotifyDialog(){
ui->leText->setText("");
this->hide();
}
void NotifySend::on_btnClose_clicked()
{
this->hide();
}

View File

@ -1,34 +0,0 @@
#ifndef NOTIFYSEND_H
#define NOTIFYSEND_H
#include <QWidget>
#include <QTimer>
#include <QScreen>
namespace Ui {
class NotifySend;
}
class NotifySend : public QWidget
{
Q_OBJECT
public:
explicit NotifySend(QWidget *parent = nullptr);
~NotifySend();
void execNotifySend(QString text);
private:
Ui::NotifySend *ui;
private slots:
void closeNotifyDialog();
void on_btnClose_clicked();
signals:
void timeout();
};
#endif // NOTIFYSEND_H

View File

@ -1,69 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NotifySend</class>
<widget class="QWidget" name="NotifySend">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>70</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="lbColor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>60</width>
<height>70</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QPushButton" name="btnClose">
<property name="geometry">
<rect>
<x>360</x>
<y>20</y>
<width>30</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLineEdit" name="leText">
<property name="geometry">
<rect>
<x>80</x>
<y>20</y>
<width>260</width>
<height>27</height>
</rect>
</property>
</widget>
<widget class="QWidget" name="backwidget" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>70</height>
</rect>
</property>
</widget>
<zorder>backwidget</zorder>
<zorder>lbColor</zorder>
<zorder>btnClose</zorder>
<zorder>leText</zorder>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -144,11 +144,11 @@ OneConnForm::OneConnForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
OneConnForm::~OneConnForm()
{
m_notify->deleteLater();
delete ui;
}
void OneConnForm::mousePressEvent(QMouseEvent *){
void OneConnForm::mousePressEvent(QMouseEvent *)
{
emit selectedOneWifiForm(wifiName, H_WIFI_ITEM_BIG_EXTEND);
}
@ -197,11 +197,12 @@ bool OneConnForm::eventFilter(QObject *obj, QEvent *event)
}
// 是否当前连接的网络,字体设置不同
void OneConnForm::setAct(bool isAct){
if(isAct){
void OneConnForm::setAct(bool isAct)
{
if (isAct) {
ui->lbName->setStyleSheet("QLabel{font-size:14px;color:#ffffff;}");
ui->lbConned->show();
}else{
} else {
ui->lbName->setStyleSheet("QLabel{font-size:14px;color:#ffffff;}");
ui->lbConned->hide();
}
@ -210,7 +211,7 @@ void OneConnForm::setAct(bool isAct){
void OneConnForm::setLePassword()
{
if(ui->lePassword->text() == "Input Password..." || ui->lePassword->text() == "输入密码..."){
if (ui->lePassword->text() == "Input Password..." || ui->lePassword->text() == "输入密码...") {
ui->lePassword->setText(tr(""));
ui->lePassword->setEchoMode(QLineEdit::Password);
ui->checkBoxPwd->setChecked(false);
@ -218,8 +219,9 @@ void OneConnForm::setLePassword()
}
//点击窗口最上面的item时
void OneConnForm::setTopItem(bool isSelected){
if(isSelected){
void OneConnForm::setTopItem(bool isSelected)
{
if (isSelected) {
resize(W_ITEM, H_ITEM_BIG);
ui->wbg_3->show();
ui->leInfo_1->show();
@ -227,7 +229,7 @@ void OneConnForm::setTopItem(bool isSelected){
ui->leInfo_3->show();
this->isSelected = true;
}else{
} else {
resize(W_ITEM, H_ITEM);
ui->lePassword->setText("");
ui->wbg_3->hide();
@ -250,21 +252,22 @@ void OneConnForm::setTopItem(bool isSelected){
ui->btnHideConn->hide();
ui->btnInfo->show();
if (isConnected){
if (this->isWaiting){
if (isConnected) {
if (this->isWaiting) {
ui->btnDisConn->hide();
}else{
} else {
ui->btnDisConn->show();
}
}else{
} else {
ui->btnDisConn->hide();
}
this->isTopItem = true;
}
// 点击窗口下面的item时
void OneConnForm::setSelected(bool isSelected, bool isCurrName){
if(isSelected){
void OneConnForm::setSelected(bool isSelected, bool isCurrName)
{
if (isSelected) {
resize(W_ITEM, H_ITEM_BIG);
ui->line->move(X_LINE_BIG_EXTEND, Y_LINE_BIG_EXTEND);
ui->wbg->hide();
@ -277,7 +280,7 @@ void OneConnForm::setSelected(bool isSelected, bool isCurrName){
ui->btnConnSub->show();
this->isSelected = true;
}else{
} else {
resize(W_ITEM, H_ITEM);
ui->lePassword->setText(tr("Input Password..."));//"输入密码..."
ui->lePassword->setStyleSheet("QLineEdit{border:1px solid rgba(61,107,229,1);border-radius:4px;"
@ -293,9 +296,9 @@ void OneConnForm::setSelected(bool isSelected, bool isCurrName){
ui->leInfo_2->hide();
ui->leInfo_3->hide();
if (isCurrName){
if (isCurrName) {
ui->btnConn->show();
}else{
} else {
ui->btnConn->hide();
}
ui->btnConnSub->hide();
@ -314,8 +317,9 @@ void OneConnForm::setSelected(bool isSelected, bool isCurrName){
this->isTopItem = false;
}
// 点击连接隐藏wifi的item时
void OneConnForm::setHideItem(bool isHideItem, bool isShowHideBtn){
if (isHideItem){
void OneConnForm::setHideItem(bool isHideItem, bool isShowHideBtn)
{
if (isHideItem) {
ui->lbName->move(14, 20);
ui->wbg->hide();
ui->btnConn->hide();
@ -325,24 +329,26 @@ void OneConnForm::setHideItem(bool isHideItem, bool isShowHideBtn){
ui->btnConn->show();
}
if (isShowHideBtn){
if (isShowHideBtn) {
ui->btnHideConn->show();
} else{
ui->btnHideConn->hide();
}
}
void OneConnForm::setConnedString(bool showLable, QString str, QString str1){
if (!showLable){
void OneConnForm::setConnedString(bool showLable, QString str, QString str1)
{
if (!showLable) {
ui->lbConned->setText(str1);
ui->lbConned->hide();
ui->lbName->move(63, 18);
}else{
} else {
ui->lbConned->setText(str);
}
}
void OneConnForm::setName(QString name){
void OneConnForm::setName(QString name)
{
ui->lbName->setText(name);
wifiName = name;
}
@ -357,7 +363,8 @@ QString OneConnForm::getName()
return ui->lbName->text();
}
void OneConnForm::setRate(QString rate){
void OneConnForm::setRate(QString rate)
{
QString txt(tr("Rate"));//"速率"
this->setToolTip("<span style=\"font-size:14px;border:none;background-color:#3593b5;color:white;\">&nbsp; " + txt + ": " + rate + " &nbsp;</span>");
this->setToolTip(txt + ":" + rate);
@ -365,57 +372,58 @@ void OneConnForm::setRate(QString rate){
void OneConnForm::setLine(bool isShow)
{
if(isShow){
if (isShow) {
ui->line->show();
}else{
} else {
ui->line->hide();
}
}
void OneConnForm::setSignal(QString lv, QString secu){
void OneConnForm::setSignal(QString lv, QString secu)
{
int signal = lv.toInt();
if (secu == "--" || secu == ""){
if (secu == "--" || secu == "") {
hasPwd = false;
}else{
} else {
hasPwd = true;
}
if(signal > 75){
if(hasPwd){
if (signal > 75) {
if (hasPwd) {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-full-pwd.png);}");
}else{
} else {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-full.png);}");
}
signalLv = 1;
}
if(signal > 55 && signal <= 75){
if(hasPwd){
if (signal > 55 && signal <= 75) {
if (hasPwd) {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-high-pwd.png);}");
}else{
} else {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-high.png);}");
}
signalLv = 2;
}
if(signal > 35 && signal <= 55){
if(hasPwd){
if (signal > 35 && signal <= 55) {
if (hasPwd) {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-medium-pwd.png);}");
}else{
} else {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-medium.png);}");
}
signalLv = 3;
}
if(signal > 15 && signal <= 35){
if(hasPwd){
if (signal > 15 && signal <= 35) {
if (hasPwd) {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-low-pwd.png);}");
}else{
} else {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-low.png);}");
}
signalLv = 4;
}
if(signal <= 15){
if(hasPwd){
if (signal <= 15) {
if (hasPwd) {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-none-pwd.png);}");
}else{
} else {
ui->lbSignal->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/w/wifi-none.png);}");
}
signalLv = 4;
@ -437,12 +445,13 @@ void OneConnForm::setWifiInfo(QString str1, QString str2, QString str3)
void OneConnForm::slotConnWifi()
{
// mw->startLoading();
//mw->startLoading();
this->startWaiting(true);
emit sigConnWifi(ui->lbName->text());
}
void OneConnForm::slotConnWifiPWD(){
// mw->startLoading();
void OneConnForm::slotConnWifiPWD()
{
//mw->startLoading();
this->startWaiting(true);
emit sigConnWifiPWD(ui->lbName->text(), ui->lePassword->text());
}
@ -640,19 +649,19 @@ void OneConnForm::on_btnInfo_clicked()
QStringList propList = connProp.split("|");
QString v4method, addr, mask, gateway, dns;
foreach (QString line, propList) {
if(line.startsWith("method:")){
if (line.startsWith("method:")) {
v4method = line.split(":").at(1);
}
if(line.startsWith("addr:")){
if (line.startsWith("addr:")) {
addr = line.split(":").at(1);
}
if(line.startsWith("mask:")){
if (line.startsWith("mask:")) {
mask = line.split(":").at(1);
}
if(line.startsWith("gateway:")){
if (line.startsWith("gateway:")) {
gateway= line.split(":").at(1);
}
if(line.startsWith("dns:")){
if (line.startsWith("dns:")) {
dns = line.split(":").at(1);
}
}
@ -666,10 +675,11 @@ void OneConnForm::on_btnInfo_clicked()
}
// Wifi连接结果0成功 1失败 2没有配置文件
void OneConnForm::slotConnWifiResult(int connFlag){
void OneConnForm::slotConnWifiResult(int connFlag)
{
qDebug()<<"Function slotConnWifiResult receives a number: "<<connFlag;
if(connFlag == 2){
if (connFlag == 2) {
mw->currSelNetName = "";
emit selectedOneWifiForm(ui->lbName->text(), H_WIFI_ITEM_SMALL_EXTEND);
@ -693,12 +703,11 @@ void OneConnForm::slotConnWifiResult(int connFlag){
this->isSelected = true;
}
if(connFlag == 1){
if (connFlag == 1) {
// 使用配置文件连接失败,需要删除该配置文件
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());
//m_notify->execNotifySend(txt);
KylinDBus kylindbus;
kylindbus.showDesktopNotify(txt);
//QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection delete '" + ui->lbName->text() + "';notify-send '" + txt + "...' -t 3800";
@ -713,12 +722,13 @@ void OneConnForm::slotConnWifiResult(int connFlag){
currentActWifiSignalLv = signalLv;
this->stopWaiting();
// if (connFlag != 0){
// mw->stopLoading();
// }
//if (connFlag != 0){
// mw->stopLoading();
//}
}
void OneConnForm::waitAnimStep(){
void OneConnForm::waitAnimStep()
{
QString qpmQss = "QLabel{background-image:url(':/res/s/conning-a/";
qpmQss.append(QString::number(this->waitPage));
qpmQss.append(".png');}");
@ -726,20 +736,21 @@ void OneConnForm::waitAnimStep(){
this->waitPage --;
if(this->waitPage < 1){
if (this->waitPage < 1) {
this->waitPage = TOTAL_PAGE;
}
this->countCurrentTime += FRAME_SPEED;
if (this->countCurrentTime >= LIMIT_TIME){
if (this->countCurrentTime >= LIMIT_TIME) {
this->stopWaiting();
}
}
void OneConnForm::startWaiting(bool isConn){
void OneConnForm::startWaiting(bool isConn)
{
this->isWaiting = true;
if (isConn){
if (isConn) {
ui->lbWaiting->setStyleSheet("QLabel{border:0px;border-radius:4px;background-color:rgba(61,107,229,1);}");
}else{
} else {
ui->btnDisConn->hide();
ui->lbWaiting->setStyleSheet("QLabel{border:0px;border-radius:4px;background-color:rgba(255,255,255,0.12);}");
}
@ -752,7 +763,8 @@ void OneConnForm::startWaiting(bool isConn){
mw->setTrayLoading(true);
}
void OneConnForm::stopWaiting(){
void OneConnForm::stopWaiting()
{
this->isWaiting = false;
this->waitTimer->stop();
ui->lbWaiting->hide();

View File

@ -30,7 +30,6 @@
#include "confform.h"
#include "backthread.h"
#include "ksimplenm.h"
#include "notifysend.h"
#define FRAME_SPEED 150
#define LIMIT_TIME 20*1000
@ -82,7 +81,6 @@ public:
bool isWifiConfExist(QString netName);
NotifySend *m_notify = nullptr;
QString wifiName;
bool isSelected;
bool isActive;

View File

@ -99,7 +99,8 @@ OneLancForm::~OneLancForm()
delete ui;
}
void OneLancForm::mousePressEvent(QMouseEvent *){
void OneLancForm::mousePressEvent(QMouseEvent *)
{
//emit selectedOneLanForm(lanName);
emit selectedOneLanForm(lanName, uniqueName);//避免重名情况
}
@ -107,31 +108,31 @@ void OneLancForm::mousePressEvent(QMouseEvent *){
//事件过滤器
bool OneLancForm::eventFilter(QObject *obj, QEvent *event)
{
if (obj == ui->btnInfo){
if (obj == ui->btnInfo) {
if(event->type() == QEvent::HoverEnter) {
ui->leInfo_1->setStyleSheet(leQssHigh);
ui->leInfo_2->setStyleSheet(leQssHigh);
ui->leInfo_3->setStyleSheet(leQssHigh);
ui->leInfo_4->setStyleSheet(leQssHigh);
return true;
} else if(event->type() == QEvent::HoverLeave){
} else if(event->type() == QEvent::HoverLeave) {
ui->leInfo_1->setStyleSheet(leQssLow);
ui->leInfo_2->setStyleSheet(leQssLow);
ui->leInfo_3->setStyleSheet(leQssLow);
ui->leInfo_4->setStyleSheet(leQssLow);
return true;
}
}else if (obj == this){
if(event->type() == QEvent::HoverEnter) {
if (!this->isTopItem){
if (!this->isSelected){
} else if (obj == this) {
if (event->type() == QEvent::HoverEnter) {
if (!this->isTopItem) {
if (!this->isSelected) {
ui->btnConn->show();
ui->wbg_2->setStyleSheet("#wbg_2{border-radius:4px;background-color:rgba(255,255,255,0.1);}");
ui->wbg_2->show();
}
}
return true;
} else if(event->type() == QEvent::HoverLeave){
} else if(event->type() == QEvent::HoverLeave) {
ui->btnConn->hide();
ui->wbg_2->setStyleSheet("#wbg_2{border-radius:4px;background-color:rgba(255,255,255,0);}");
ui->wbg_2->hide();
@ -143,12 +144,13 @@ bool OneLancForm::eventFilter(QObject *obj, QEvent *event)
}
// 是否当前连接的网络,字体设置不同
void OneLancForm::setAct(bool isAct){
if(isAct){
void OneLancForm::setAct(bool isAct)
{
if (isAct) {
ui->lbName->setStyleSheet("QLabel{font-size:14px;color:#ffffff;}");
ui->lbConned->show();
ui->btnConnSub->hide();
}else{
} else {
ui->lbName->setStyleSheet("QLabel{font-size:14px;color:#ffffff;}");
ui->lbConned->hide();
ui->btnConnSub->hide();
@ -159,7 +161,7 @@ void OneLancForm::setAct(bool isAct){
// 是否选中
void OneLancForm::setSelected(bool isSelected, bool isCurrName)
{
if(isSelected){
if (isSelected) {
resize(W_ITEM, H_ITEM_EXTEND);
ui->wbg->show();
ui->wbg_2->hide();
@ -168,7 +170,7 @@ void OneLancForm::setSelected(bool isSelected, bool isCurrName)
ui->btnConnSub->show();
this->isSelected = true;
}else{
} else {
resize(W_ITEM, H_ITEM);
ui->wbg->hide();
ui->wbg_2->show();
@ -190,18 +192,18 @@ void OneLancForm::setSelected(bool isSelected, bool isCurrName)
void OneLancForm::setTopItem(bool isSelected)
{
if(isSelected){
if (isSelected) {
resize(W_ITEM, H_ITEM_EXTEND);
ui->wbg->show();
ui->btnConnSub->hide();
this->isSelected = true;
}else{
} else {
resize(W_ITEM, H_ITEM);
ui->wbg->hide();
ui->btnConnSub->hide();
this->isSelected = false;
}
if (isConnected){
if (isConnected) {
ui->btnDisConn->show();
} else {
ui->btnDisConn->hide();
@ -214,28 +216,30 @@ void OneLancForm::setTopItem(bool isSelected)
this->isTopItem = true;
}
void OneLancForm::setName(QString name, QString uniName){
void OneLancForm::setName(QString name, QString uniName)
{
ui->lbName->setText(name);
lanName = name;
uniqueName = uniName;
}
void OneLancForm::setConnedString(bool showLable, QString str){
if (!showLable){
void OneLancForm::setConnedString(bool showLable, QString str)
{
if (!showLable) {
ui->lbConned->hide();
ui->lbName->move(63, 18);
}else{
} else {
ui->lbConned->setText(str);
}
}
void OneLancForm::setLanInfo(QString str1, QString str2, QString str3, QString str4)
{
if (str1 == "" || str1 == "auto"){
if (str1 == "" || str1 == "auto") {
str1 = tr("No Configuration");
}
if (str2 == "" || str2 == "auto"){
if (str2 == "" || str2 == "auto") {
str2 = tr("No Configuration");
}
@ -250,24 +254,26 @@ void OneLancForm::setLanInfo(QString str1, QString str2, QString str3, QString s
ui->leInfo_4->setText(strMAC + str4);
}
void OneLancForm::setIcon(bool isOn){
if(isOn){
void OneLancForm::setIcon(bool isOn)
{
if (isOn) {
ui->lbIcon->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/l/network-online.png);}");
}else{
} else {
ui->lbIcon->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/l/network-offline.png);}");
}
}
void OneLancForm::setLine(bool isShow)
{
if(isShow){
if (isShow) {
ui->line->show();
}else{
} else {
ui->line->hide();
}
}
void OneLancForm::slotConnLan(){
void OneLancForm::slotConnLan()
{
//mw->startLoading();
this->startWaiting(true);
emit sigConnLan(ui->lbName->text());
@ -341,19 +347,19 @@ void OneLancForm::on_btnInfo_clicked()
QStringList propList = connProp.split("|");
QString v4method, addr, mask, gateway, dns;
foreach (QString line, propList) {
if(line.startsWith("method:")){
if (line.startsWith("method:")) {
v4method = line.split(":").at(1);
}
if(line.startsWith("addr:")){
if (line.startsWith("addr:")) {
addr = line.split(":").at(1);
}
if(line.startsWith("mask:")){
if (line.startsWith("mask:")) {
mask = line.split(":").at(1);
}
if(line.startsWith("gateway:")){
if (line.startsWith("gateway:")) {
gateway= line.split(":").at(1);
}
if(line.startsWith("dns:")){
if (line.startsWith("dns:")) {
dns = line.split(":").at(1);
}
}
@ -367,7 +373,8 @@ void OneLancForm::on_btnInfo_clicked()
cf->raise();
}
void OneLancForm::waitAnimStep(){
void OneLancForm::waitAnimStep()
{
QString qpmQss = "QLabel{background-image:url(':/res/s/conning-a/";
qpmQss.append(QString::number(this->waitPage));
qpmQss.append(".png');}");
@ -375,20 +382,21 @@ void OneLancForm::waitAnimStep(){
this->waitPage --;
if(this->waitPage < 1){
if (this->waitPage < 1) {
this->waitPage = TOTAL_PAGE;
}
this->countCurrentTime += FRAME_SPEED;
if (this->countCurrentTime >= LIMIT_TIME){
if (this->countCurrentTime >= LIMIT_TIME) {
this->stopWaiting();
}
}
void OneLancForm::startWaiting(bool isConn){
if (isConn){
void OneLancForm::startWaiting(bool isConn)
{
if (isConn) {
ui->lbWaiting->setStyleSheet("QLabel{border:0px;border-radius:4px;background-color:rgba(61,107,229,1);}");
}else{
} else {
ui->btnDisConn->hide();
ui->lbWaiting->setStyleSheet("QLabel{border:0px;border-radius:4px;background-color:rgba(255,255,255,0.12);}");
}
@ -401,7 +409,8 @@ void OneLancForm::startWaiting(bool isConn){
mw->setTrayLoading(true);
}
void OneLancForm::stopWaiting(){
void OneLancForm::stopWaiting()
{
this->waitTimer->stop();
ui->lbWaiting->hide();
ui->lbWaitingIcon->hide();

View File

@ -33,7 +33,7 @@ int Utils::m_system(char *cmd)
int status = 0;
pid_t pid;
if ((pid = vfork()) <0){
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;
@ -84,36 +84,36 @@ int NetworkSpeed::getCurrentDownloadRates(char *netname, long *save_rate, long *
//int i = 0;
char tmp_value[128];
if((NULL == netname)||(NULL == save_rate)||(NULL == tx_rate)){
if((NULL == netname)||(NULL == save_rate)||(NULL == tx_rate)) {
qDebug()<<"parameter pass to function getCurrentDownloadRates() error";
syslog(LOG_ERR, "parameter pass to function getCurrentDownloadRates() error");
return -1;
}
if ( (net_dev_file=fopen("/proc/net/dev", "r")) == NULL ){ //打开文件/pro/net/dev/,从中读取流量数据
if ( (net_dev_file=fopen("/proc/net/dev", "r")) == NULL ) { //打开文件/pro/net/dev/,从中读取流量数据
qDebug()<<"error occurred when try to open file /proc/net/dev/";
syslog(LOG_ERR, "error occurred when try to open file /proc/net/dev/");
return -1;
}
memset(buffer,0,sizeof(buffer));
while(fgets(buffer,sizeof(buffer),net_dev_file) != NULL){
while (fgets(buffer,sizeof(buffer),net_dev_file) != NULL) {
match = strstr(buffer,netname);
if(NULL == match){
if (NULL == match) {
// qDebug()<<"No eth0 keyword to find!";
continue;
}else{
} else {
match = match + strlen(netname) + strlen(":"); //地址偏移到冒号
sscanf(match,"%ld ",save_rate);
memset(tmp_value,0,sizeof(tmp_value));
sscanf(match,"%s ",tmp_value);
match = match + strlen(tmp_value);
for(size_t i=0;i<strlen(buffer);i++){
if(0x20 == *match){
for (size_t i=0;i<strlen(buffer);i++) {
if (0x20 == *match) {
match ++;
} else{
if(8 == counter){
} else {
if (8 == counter) {
sscanf(match,"%ld ",tx_rate);
}
memset(tmp_value,0,sizeof(tmp_value));
@ -189,19 +189,6 @@ int CustomStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *opt
void CustomStyle::polish(QWidget *widget)
{
// if (widget) {
// if (widget->inherits("QTipLabel")){
// widget->setAttribute(Qt::WA_TranslucentBackground);
// QPainterPath path;
// auto rect = widget->rect();
// rect.adjust(0, 0, -0, -0);
// path.addRoundedRect(rect, 3, 3);
// widget->setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon()));
// }
// }
return QProxyStyle::polish(widget);
}