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
|
||||
|
||||
|
|
|
@ -1,21 +1,53 @@
|
|||
#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()
|
||||
{
|
||||
sleep(3);
|
||||
QDBusInterface interface( "org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop/NetworkManager",
|
||||
"org.freedesktop.NetworkManager",
|
||||
QDBusConnection::systemBus() );
|
||||
QDBusReply<uint> reply= interface.call("CheckConnectivity");
|
||||
if (reply.isValid()) {
|
||||
QDBusInterface interface( "org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop/NetworkManager",
|
||||
"org.freedesktop.NetworkManager",
|
||||
QDBusConnection::systemBus() );
|
||||
QDBusReply<uint> reply= interface.call("CheckConnectivity");
|
||||
if (reply.isValid()) {
|
||||
//qDebug()<<"---------------------wifi type:----------------------"<<reply.value();
|
||||
if (reply.value() == 2) {
|
||||
//system("xdg-open http://nmcheck.gnome.org");
|
||||
QProcess::startDetached(QString("xdg-open http://nmcheck.gnome.org"));
|
||||
while(1)
|
||||
{
|
||||
if(!_isConnect)
|
||||
QProcess::startDetached(QString("xdg-open http://nmcheck.gnome.org"));
|
||||
if(_isReply)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#ifndef WIFI_AUTH_THREAD_H
|
||||
#define WIFI_AUTH_THREAD_H
|
||||
#include <QThread>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QProcess>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
|
||||
|
@ -8,6 +12,14 @@ class WifiAuthThread:public QThread
|
|||
{
|
||||
protected:
|
||||
virtual void run();
|
||||
QNetworkRequest request;
|
||||
QNetworkAccessManager* naManager=nullptr;
|
||||
bool _isConnect=true;//是否已联网
|
||||
bool _isReply=false;//联网状态检查是否收到回复
|
||||
|
||||
public:
|
||||
WifiAuthThread();
|
||||
~WifiAuthThread();
|
||||
};
|
||||
|
||||
#endif //WIFI_AUTH_THREAD_H
|
||||
|
|
Loading…
Reference in New Issue