Merge pull request #86 from CrankyPants123/master

Fixed some bugs
This commit is contained in:
chenlelin 2021-03-15 19:47:45 +08:00 committed by GitHub
commit cecfbd142e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 124 additions and 10 deletions

54
.gitignore vendored Executable file
View File

@ -0,0 +1,54 @@
# C++ objects and libs
*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.so.*
*.dll
*.dylib
# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*
*.prl
# Qt unit tests
target_wrapper.*
# QtCreator
*.autosave
# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*
# QtCreator CMake
CMakeLists.txt.user*
# QtCreator 4.8< compilation database
compile_commands.json
# QtCreator local machine specific files for imported projects
*creator.user*
# OS X extra file
.DS_Store

View File

@ -224,6 +224,21 @@ void ConfForm::on_btnCreate_clicked()
kylindbus.getWiredCardName();
QString mIfname;
QString mask = "";
if (ui->cbMask->currentIndex() == 0) {
mask = "24";
} else if(ui->cbMask->currentIndex() == 1) {
mask = "23";
} else if(ui->cbMask->currentIndex() == 2) {
mask = "22";
} else if(ui->cbMask->currentIndex() == 3) {
mask = "16";
} else if(ui->cbMask->currentIndex() == 4) {
mask = "8";
} else {
mask = "24";
}
if (kylindbus.multiWiredIfName.size() == 0) {
QString tip(tr("Can not create new wired network for without wired card"));
kylindbus.showDesktopNotify(tip);
@ -240,8 +255,22 @@ void ConfForm::on_btnCreate_clicked()
return;
}
}
QString cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
QString cmdStr;
if(ui->cbType->currentIndex() == 0){
cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
}else{
cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet ipv4.method manual ipv4.address "
+ ui->leAddr->text() + "/" + mask.toUtf8().data();
if(!ui->leGateway->text().isEmpty()){
cmdStr += " ipv4.gateway " + ui->leGateway->text();
}
if(!ui->leDns->text().isEmpty()){
cmdStr += " ipv4.dns " + ui->leDns->text();
if(!ui->leDns2->text().isEmpty()){
cmdStr += "," + ui->leDns2->text();
}
}
}
Utils::m_system(cmdStr.toUtf8().data());
if (ui->cbType->currentIndex() == 1) {
@ -396,8 +425,8 @@ void ConfForm::saveNetworkConfiguration()
}
//是选择的自动还是手动配置网络
if (!this->isCreateNewNet) {
if (ui->cbType->currentIndex() == 0) {
if (!this->isCreateNewNet) {
//kylin_network_set_automethod(ui->leName->text().toUtf8().data());
kylin_network_set_automethod(netUuid.toUtf8().data());
}
@ -571,6 +600,10 @@ void ConfForm::on_leDns2_textEdited(const QString &arg1)
//设置界面按钮是否可点击
void ConfForm::setEnableOfBtn()
{
// if(!isEditingAlready()){
// this->setBtnEnableFalse();
// return;
// }
if (ui->leName->text().size() == 0 ) {
this->setBtnEnableFalse();
return;
@ -619,6 +652,24 @@ void ConfForm::setEnableOfBtn()
}
bool ConfForm::isEditingAlready(){
if (ui->leName->text().size() == 0) return false;
if(ui->cbType->currentIndex() == 1){ //手动新建网络
//仅填写连接名和ipv4地址时可被按下
if(getTextEditState(ui->leAddr->text()) && ui->leAddr_ipv6->text().isEmpty()
&& ui->leGateway->text().isEmpty() && ui->leDns->text().isEmpty() && ui->leDns2->text().isEmpty()){
return true;
}
//全部填写完成时可被按下
if(getTextEditState(ui->leAddr->text()) && ui->leAddr_ipv6->text().isEmpty()
&& getTextEditState(ui->leGateway->text()) && getTextEditState(ui->leDns->text())){
if(getTextEditState(ui->leDns2->text()) || ui->leDns2->text().isEmpty()){
return true;
}
}
}
return false;
}
//文本的输入要符合ip的格式要求
bool ConfForm::getTextEditState(QString text)
{

View File

@ -88,6 +88,7 @@ private:
bool isActConf; //是否对已经连接的网络进行的更改
bool isCreateNewNet = false; //是否是创建的新网络
bool isShowSaveBtn = true; //是否显示保存按钮,即是否是编辑网络界面
bool isEditingAlready(); //连接按钮是否可被按下
QString lastConnName, lastIpv4, netUuid, newUuid;
bool isActWifi; //是否是wifi网络

View File

@ -1882,6 +1882,7 @@ void MainWindow::loadWifiListDone(QStringList slist)
activeWifiSignalLv = 0;
ccf->setConnedString(1, tr("Disconnected"), "");//"未连接"
ccf->isConnected = false;
ccf->lbFreq->hide();
ifWLanConnected = false;
lbLoadDown->hide();
lbLoadUp->hide();

View File

@ -50,6 +50,7 @@ OneConnForm::OneConnForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
ui->lbConned->setAlignment(Qt::AlignLeft);
ui->lePassword->setEchoMode(QLineEdit::Normal);
ui->lePassword->setContextMenuPolicy(Qt::NoContextMenu);
ui->btnConnPWD->setEnabled(false);
leQssLow = "QLineEdit{border:none;background:transparent;font-size:14px;}";
@ -134,7 +135,7 @@ OneConnForm::OneConnForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
ui->btnInfo->setAttribute(Qt::WA_Hover,true);
ui->btnInfo->installEventFilter(this);
connect(ui->lePassword, SIGNAL(returnPressed()), this, SLOT(on_btnConnPWD_clicked()));
// connect(ui->lePassword, SIGNAL(returnPressed()), this, SLOT(on_btnConnPWD_clicked()));
ui->btnConn->setShortcut(Qt::Key_Return);//将字母区回车键与连接按钮绑定在一起
ui->btnConnSub->setShortcut(Qt::Key_Return);//点击连接按钮触发回车键
@ -813,6 +814,7 @@ void OneConnForm::on_lePassword_textEdited(const QString &arg1)
"QPushButton:Hover{border:0px solid rgba(255,255,255,0.2);border-radius:4px;background-color:rgba(255,255,255,0.2);}"
"QPushButton:Pressed{border-radius:4px;background-color:rgba(255,255,255,0.08);}");
ui->btnConnPWD->setEnabled(false);
disconnect(ui->lePassword, SIGNAL(returnPressed()), this, SLOT(on_btnConnPWD_clicked()));
if (ui->lePassword->text().size() == 0) {
ui->lePassword->setStyleSheet("QLineEdit{border:1px solid rgba(61,107,229,1);border-radius:4px;background:rgba(0,0,0,0.2);}");
}
@ -820,6 +822,7 @@ void OneConnForm::on_lePassword_textEdited(const QString &arg1)
ui->btnConnPWD->setStyleSheet("QPushButton{border:0px;border-radius:4px;background-color:rgba(61,107,229,1);color:white;font-size:14px;}"
"QPushButton:Hover{border:0px solid rgba(255,255,255,0.2);border-radius:4px;background-color:rgba(107,142,235,1);}"
"QPushButton:Pressed{border-radius:4px;background-color:rgba(50,87,202,1);}");
connect(ui->lePassword, SIGNAL(returnPressed()), this, SLOT(on_btnConnPWD_clicked()));
ui->btnConnPWD->setEnabled(true);
}
}

View File

@ -87,6 +87,7 @@ public:
QString wifiUuid;
QString connType;
QString wifiSecu;
QLabel * lbFreq = nullptr;
bool isSelected;
bool isActive;
bool isConnected;
@ -139,7 +140,6 @@ private:
bool hasPwd;
QString leQssLow, leQssHigh;
QLabel * lbFreq = nullptr;
QLabel * lbNameText = nullptr;
QHBoxLayout * lbNameLyt = nullptr;
QString key_mgmt;

View File

@ -23,7 +23,7 @@
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusInterface>
@ -38,7 +38,7 @@ int Utils::m_system(char *cmd)
{
int status = 0;
pid_t pid;
clock_t start,finish;
if ((pid = vfork()) <0) {
qDebug()<<"failed to create a subprocess by using vfork";
syslog(LOG_ERR, "failed to create a subprocess by using vfork");
@ -60,6 +60,7 @@ int Utils::m_system(char *cmd)
new_argv[3] = NULL;
// execl("/bin/sh","sh","-c" ,cmd,(char *)0);
start = clock();
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);
@ -69,8 +70,11 @@ int Utils::m_system(char *cmd)
}
} else {
waitpid(pid,&status,0);
finish = clock();
}
double duration = (double)(finish-start)/CLOCKS_PER_SEC;
QString str = "It takes "+QString::number(duration)+" seconds to execute command:"+cmd;
syslog(LOG_DEBUG,"%s",str.toStdString().c_str());
return status;
}

View File

@ -305,7 +305,7 @@ void DlgHideWifiWpa::on_btnConnect_clicked()
QFuture < void > future1 = QtConcurrent::run([=](){
int x(1), n(0);
do {
sleep(1);
sleep(2);
n += 1;
if (n >= 20) {
x = 0;
@ -313,7 +313,7 @@ void DlgHideWifiWpa::on_btnConnect_clicked()
}
QString tmpPath = "/tmp/kylin-nm-btoutput-" + QDir::home().dirName();
QString cmd = "nmcli device wifi connect " + wifiName + " password " + wifiPassword + " hidden yes > " + tmpPath;
QString cmd = "nmcli device wifi connect " + wifiName + " password " + wifiPassword + " hidden yes > " + tmpPath + " 2>&1";
int status = system(cmd.toUtf8().data());
if (status != 0) {