using dbus method to get signal when add or remove wireless device
This commit is contained in:
parent
fa743d8959
commit
0c4d6d420c
|
@ -124,9 +124,7 @@ void BackThread::execConnLan(QString connName){
|
|||
QString strType;
|
||||
int i = 0;
|
||||
while(1){
|
||||
if (txt[i] == ":"){
|
||||
break;
|
||||
}
|
||||
if (txt[i] == ":"){ break; }
|
||||
strType += txt[i];
|
||||
i += 1;
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
./man/kylin-nm.1
|
|
@ -1 +0,0 @@
|
|||
467a421b0078726ed4c41474a9c500d735617d88
|
|
@ -1,13 +0,0 @@
|
|||
Package: kylin-nm-dbgsym
|
||||
Package-Type: ddeb
|
||||
Source: kylin-nm
|
||||
Version: 1.0.4-1
|
||||
Auto-Built-Package: debug-symbols
|
||||
Architecture: amd64
|
||||
Maintainer: Kylin Team <team+kylin@tracker.debian.org>
|
||||
Installed-Size: 1848
|
||||
Depends: kylin-nm (= 1.0.4-1)
|
||||
Section: debug
|
||||
Priority: optional
|
||||
Description: debug symbols for kylin-nm
|
||||
Build-Ids: 467a421b0078726ed4c41474a9c500d735617d88
|
|
@ -1 +0,0 @@
|
|||
1eebe9081d52b0020fd01ef256d1962f usr/lib/debug/.build-id/46/7a421b0078726ed4c41474a9c500d735617d88.debug
|
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
kylin-nm
|
|
@ -1 +0,0 @@
|
|||
kylin-nm
|
|
@ -1,3 +0,0 @@
|
|||
kylin-nm-dbgsym_1.0.4-1_amd64.ddeb debug optional automatic=yes
|
||||
kylin-nm_1.0.4-1_amd64.buildinfo utils optional
|
||||
kylin-nm_1.0.4-1_amd64.deb utils optional
|
|
@ -1,3 +0,0 @@
|
|||
shlibs:Depends=libc6 (>= 2.14), libgcc1 (>= 1:3.0), libqt5core5a (>= 5.12.2), libqt5gui5 (>= 5.7.0) | libqt5gui5-gles (>= 5.7.0), libqt5widgets5 (>= 5.2.0), libstdc++6 (>= 5)
|
||||
misc:Depends=
|
||||
misc:Pre-Depends=
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui x11extras
|
||||
QT += core gui x11extras dbus
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
|
|
2
main.cpp
2
main.cpp
|
@ -30,7 +30,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
QIcon::setThemeName("ukui-icon-theme");
|
||||
QIcon::setThemeName("ukui-icon-theme-default");
|
||||
|
||||
// 国际化
|
||||
QString locale = QLocale::system().name();
|
||||
|
|
|
@ -132,6 +132,14 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::iconActivated);
|
||||
connect(ksnm, SIGNAL(getLanListFinished(QStringList)), this, SLOT(getLanListDone(QStringList)));
|
||||
connect(ksnm, SIGNAL(getWifiListFinished(QStringList)), this, SLOT(getWifiListDone(QStringList)));
|
||||
QDBusConnection::systemBus().connect(QString("org.freedesktop.NetworkManager"),
|
||||
QString("/org/freedesktop/NetworkManager"),
|
||||
QString("org.freedesktop.NetworkManager"),
|
||||
QString("DeviceAdded"), this, SLOT(checkWirelessDeviceState(/*QDBusObjectPath*/)) );
|
||||
QDBusConnection::systemBus().connect(QString("org.freedesktop.NetworkManager"),
|
||||
QString("/org/freedesktop/NetworkManager"),
|
||||
QString("org.freedesktop.NetworkManager"),
|
||||
QString("DeviceRemoved"), this, SLOT(checkWirelessDeviceState(/*QDBusObjectPath*/)) );
|
||||
|
||||
initTimer(); //初始化定时器
|
||||
changeTimerState();//初始化定时器
|
||||
|
@ -335,6 +343,28 @@ void MainWindow::changeTimerState()
|
|||
}
|
||||
}
|
||||
|
||||
//检测无线网卡与网线是否准备好,以及相应的处理
|
||||
void MainWindow::checkWirelessDeviceState(/*QDBusObjectPath path*/)
|
||||
{
|
||||
QString wlan_card = "iwconfig>/tmp/kylin-nm-iwconfig";
|
||||
system(wlan_card.toUtf8().data());
|
||||
|
||||
QFile file("/tmp/kylin-nm-iwconfig");
|
||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qDebug()<<"Can't open the file kylin-nm-iwconfig!"<<endl;
|
||||
}
|
||||
QString txt = file.readAll();
|
||||
file.close();
|
||||
|
||||
if(txt.indexOf("IEEE 802.11") != -1){
|
||||
is_wireless_adapter_ready = 1;
|
||||
}else{
|
||||
is_wireless_adapter_ready = 0;
|
||||
}
|
||||
|
||||
on_btnWifi_clicked();
|
||||
}
|
||||
|
||||
// 初始化网络
|
||||
void MainWindow::getIface()
|
||||
{
|
||||
|
@ -847,19 +877,9 @@ void MainWindow::on_btnNet_clicked()
|
|||
|
||||
void MainWindow::on_btnWifi_clicked()
|
||||
{
|
||||
QString wlan_card = "iwconfig>/tmp/kylin-nm-iwconfig";
|
||||
system(wlan_card.toUtf8().data());
|
||||
|
||||
QFile file("/tmp/kylin-nm-iwconfig");
|
||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qDebug()<<"Can't open the file kylin-nm-iwconfig!"<<endl;
|
||||
}
|
||||
QString txt = file.readAll();
|
||||
file.close();
|
||||
|
||||
//当连接上无线网卡时才能打开wifi开关
|
||||
if(txt.indexOf("IEEE 802.11") != -1){
|
||||
// 网络开关关闭时,点击Wifi开关无效
|
||||
if(is_wireless_adapter_ready == 1){
|
||||
// 网络开关关闭时,点击Wifi开关时,程序先打开有线开关
|
||||
if(checkLanOn()){
|
||||
if(checkWlOn()){
|
||||
QThread *t = new QThread();
|
||||
|
@ -1023,6 +1043,7 @@ void MainWindow::connLanDone(int connFlag){
|
|||
}
|
||||
|
||||
if(connFlag == 3){
|
||||
qDebug()<<"启动软件,Lan已经开启,即将循环检测是否断开";
|
||||
this->is_wired_line_ready = 1;
|
||||
changeTimerState();
|
||||
check_isLanConnect->start(4000);
|
||||
|
@ -1061,21 +1082,6 @@ void MainWindow::on_isLanConnect()
|
|||
count_loop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (iface->wstate == 2 && this->is_on_btnConn_clicked == 0) {
|
||||
//点击wifi连接按钮时,可能iface->wstate == 2,设置is_on_btnConn_clicked参数
|
||||
//用来阻止keepDisWifiState()执行,另外两处同理
|
||||
keepDisWifiState();
|
||||
is_keep_wifi_turn_on_state = 1;
|
||||
} else {
|
||||
//出无线网卡再插入需要执行一次
|
||||
if (is_keep_wifi_turn_on_state == 1) {
|
||||
ui->lbWifiImg->setStyleSheet("QLabel{background-image:url(:/res/x/wifi-line.png);}");
|
||||
ui->lbBtnWifiBG->setStyleSheet(btnOnQss);
|
||||
ui->lbBtnWifiT1->setText(tr("Enabled"));
|
||||
is_keep_wifi_turn_on_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_isNetOn()
|
||||
|
@ -1097,8 +1103,9 @@ void MainWindow::on_isNetOn()
|
|||
changeTimerState();
|
||||
check_isLanConnect->start(4000);
|
||||
} else if (iface->lstate == 0 && this->is_by_click_connect == 1){
|
||||
qDebug()<<"注意:有线网络已经重新连接";
|
||||
qDebug()<<"注意:有线网络已经点击连接";
|
||||
check_isNetOn->stop();
|
||||
qDebug()<<"即将重新检测 Lan 是否断开";
|
||||
} else if (iface->wstate == 0 && this->is_by_click_connect == 0){
|
||||
qDebug()<<"注意:Wifi网络已经重新连接";
|
||||
if(this->is_btnNetList_clicked == 1) {
|
||||
|
@ -1113,8 +1120,9 @@ void MainWindow::on_isNetOn()
|
|||
changeTimerState();
|
||||
check_isWifiConnect->start(4000);
|
||||
} else if (iface->wstate == 0 && this->is_by_click_connect == 1){
|
||||
qDebug()<<"注意:Wifi网络已经重新连接";
|
||||
qDebug()<<"注意:Wifi网络已经点击连接";
|
||||
check_isNetOn->stop();
|
||||
qDebug()<<"即将重新检测 Wifi 是否断开";
|
||||
} else if (iface->wstate != 2) {
|
||||
count_loop += 1;
|
||||
if (count_loop >= 2 && this->is_btnWifiList_clicked == 1){
|
||||
|
@ -1124,26 +1132,12 @@ void MainWindow::on_isNetOn()
|
|||
count_loop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (iface->wstate == 2 && this->is_on_btnConn_clicked == 0) {
|
||||
keepDisWifiState();
|
||||
is_keep_wifi_turn_on_state = 1;
|
||||
} else {
|
||||
//拔出无线网卡再插入需要执行一次
|
||||
if (is_keep_wifi_turn_on_state == 1) {
|
||||
ui->lbWifiImg->setStyleSheet("QLabel{background-image:url(:/res/x/wifi-line.png);}");
|
||||
ui->lbBtnWifiBG->setStyleSheet(btnOnQss);
|
||||
ui->lbBtnWifiT1->setText(tr("Enabled"));
|
||||
is_keep_wifi_turn_on_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wifi连接结果,0点击连接成功 1失败 2没有配置文件 3开机启动网络工具时已经连接
|
||||
void MainWindow::connDone(int connFlag)
|
||||
{
|
||||
if(connFlag == 0){
|
||||
this->is_on_btnConn_clicked = 0;
|
||||
this->is_by_click_connect = 1;
|
||||
this->ksnm->execGetWifiList();
|
||||
QString txt(tr("Conn Wifi Success"));
|
||||
|
@ -1153,6 +1147,7 @@ void MainWindow::connDone(int connFlag)
|
|||
changeTimerState();
|
||||
check_isWifiConnect->start(4000);
|
||||
} else if (connFlag == 3) {
|
||||
qDebug()<<"启动软件,Wifi已经开启,即将循环检测是否断开";
|
||||
changeTimerState();
|
||||
check_isWifiConnect->start(4000);
|
||||
}
|
||||
|
@ -1188,19 +1183,6 @@ void MainWindow::on_isWifiConnect()
|
|||
count_loop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (iface->wstate == 2 && this->is_on_btnConn_clicked ==0) {
|
||||
keepDisWifiState();
|
||||
is_keep_wifi_turn_on_state = 1;
|
||||
} else {
|
||||
//拔出无线网卡再插入需要执行一次
|
||||
if (is_keep_wifi_turn_on_state == 1) {
|
||||
ui->lbWifiImg->setStyleSheet("QLabel{background-image:url(:/res/x/wifi-line.png);}");
|
||||
ui->lbBtnWifiBG->setStyleSheet(btnOnQss);
|
||||
ui->lbBtnWifiT1->setText(tr("Enabled"));
|
||||
is_keep_wifi_turn_on_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_btnAdvConf_clicked()
|
||||
|
|
11
mainwindow.h
11
mainwindow.h
|
@ -33,11 +33,17 @@
|
|||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QtDBus/QDBusMessage>
|
||||
#include <QtDBus/QDBusInterface>
|
||||
#include <QtDBus/QDBusObjectPath>
|
||||
#include <QDBusObjectPath>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <QVariant>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "ksimplenm.h"
|
||||
|
@ -78,8 +84,11 @@ public:
|
|||
int is_btnNetList_clicked = 1; //是否处于有线网界面
|
||||
int is_btnWifiList_clicked = 0; //是否处于无线网界面
|
||||
int is_wired_line_ready = 1; //主机是否连接网线
|
||||
int is_wireless_adapter_ready = 1; //主机是否插入无线网卡
|
||||
int is_keep_wifi_turn_on_state = 1; //是否要执行wifi开关变为打开样式
|
||||
int is_on_btnConn_clicked = 0;//是否已经点击连接wifi按钮
|
||||
|
||||
public slots:
|
||||
void checkWirelessDeviceState(/*QDBusObjectPath path*/);
|
||||
|
||||
private:
|
||||
void checkSingle();
|
||||
|
|
|
@ -367,7 +367,6 @@ void OneConnForm::on_btnDisConn_clicked()
|
|||
//无需密码的wifi连接
|
||||
void OneConnForm::on_btnConn_clicked()
|
||||
{
|
||||
mw->is_on_btnConn_clicked = 1;
|
||||
QThread *t = new QThread();
|
||||
BackThread *bt = new BackThread();
|
||||
bt->moveToThread(t);
|
||||
|
|
Loading…
Reference in New Issue