Optmize connect portal wifi function
This commit is contained in:
parent
505fe36fdc
commit
cbb9bb0717
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
#-------------------------------------------------
|
#-------------------------------------------------
|
||||||
|
|
||||||
QT += core gui x11extras dbus KWindowSystem svg concurrent
|
QT += core gui x11extras dbus KWindowSystem svg concurrent network
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,34 @@
|
||||||
#include "wifi-auth-thread.h"
|
#include "wifi-auth-thread.h"
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QDebug>
|
||||||
|
|
||||||
|
WifiAuthThread::WifiAuthThread()
|
||||||
|
{
|
||||||
|
//检查连接状态
|
||||||
|
naManager = new QNetworkAccessManager(this);
|
||||||
|
// QString url=QString("http://nmcheck.gnome.org/check_network_status.txt");
|
||||||
|
QString url=QString("http://connectivity-check.ubuntu.com/");
|
||||||
|
request.setUrl(QUrl(url));
|
||||||
|
naManager->get(request);
|
||||||
|
//qDebug()<<"-------------------Network state check!----------------------";
|
||||||
|
connect(naManager,&QNetworkAccessManager::finished,this,[=](QNetworkReply* reply){
|
||||||
|
_isReply=true;
|
||||||
|
QNetworkReply::NetworkError err = reply->error();
|
||||||
|
//qDebug()<<"----------------NetworkReply error:----------------------"<<err;
|
||||||
|
if(err==QNetworkReply::NoError)
|
||||||
|
{
|
||||||
|
if(!reply->readAll().isEmpty())
|
||||||
|
_isConnect=false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_isConnect=false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
WifiAuthThread::~WifiAuthThread()
|
||||||
|
{
|
||||||
|
delete naManager;
|
||||||
|
}
|
||||||
|
|
||||||
void WifiAuthThread::run()
|
void WifiAuthThread::run()
|
||||||
{
|
{
|
||||||
|
@ -11,11 +39,15 @@ void WifiAuthThread::run()
|
||||||
QDBusConnection::systemBus() );
|
QDBusConnection::systemBus() );
|
||||||
QDBusReply<uint> reply= interface.call("CheckConnectivity");
|
QDBusReply<uint> reply= interface.call("CheckConnectivity");
|
||||||
if (reply.isValid()) {
|
if (reply.isValid()) {
|
||||||
|
//qDebug()<<"---------------------wifi type:----------------------"<<reply.value();
|
||||||
if (reply.value() == 2) {
|
if (reply.value() == 2) {
|
||||||
//system("xdg-open http://nmcheck.gnome.org");
|
while(1)
|
||||||
|
{
|
||||||
|
if(!_isConnect)
|
||||||
QProcess::startDetached(QString("xdg-open http://nmcheck.gnome.org"));
|
QProcess::startDetached(QString("xdg-open http://nmcheck.gnome.org"));
|
||||||
|
if(_isReply)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
#ifndef WIFI_AUTH_THREAD_H
|
#ifndef WIFI_AUTH_THREAD_H
|
||||||
#define WIFI_AUTH_THREAD_H
|
#define WIFI_AUTH_THREAD_H
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QProcess>
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#include <QDBusReply>
|
#include <QDBusReply>
|
||||||
|
|
||||||
|
@ -8,6 +12,14 @@ class WifiAuthThread:public QThread
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
QNetworkRequest request;
|
||||||
|
QNetworkAccessManager* naManager=nullptr;
|
||||||
|
bool _isConnect=true;//是否已联网
|
||||||
|
bool _isReply=false;//联网状态检查是否收到回复
|
||||||
|
|
||||||
|
public:
|
||||||
|
WifiAuthThread();
|
||||||
|
~WifiAuthThread();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //WIFI_AUTH_THREAD_H
|
#endif //WIFI_AUTH_THREAD_H
|
||||||
|
|
Loading…
Reference in New Issue