[welcome] Use QNetworkAccessManager in checkHasInternet.

Use QNetworkAccessManager instead of raw QtDBus queries to
NetworkManager in RequirementsChecker::checkHasInternet(). This is much
simpler (i.e., less error-prone) and should be more portable (to, e.g.,
ConnMan).
This commit is contained in:
Kevin Kofler 2016-11-05 22:11:57 +01:00
parent 6eb512ab49
commit f08739cd15
2 changed files with 5 additions and 27 deletions

View file

@ -36,6 +36,7 @@
#include <QFile>
#include <QFileInfo>
#include <QLabel>
#include <QNetworkAccessManager>
#include <QProcess>
#include <QTimer>
@ -336,32 +337,8 @@ RequirementsChecker::checkHasPower()
bool
RequirementsChecker::checkHasInternet()
{
const QString NM_SVC_NAME( "org.freedesktop.NetworkManager" );
const QString NM_INTF_NAME( "org.freedesktop.NetworkManager" );
const QString NM_PATH( "/org/freedesktop/NetworkManager" );
const int NM_STATE_CONNECTED_GLOBAL = 70;
QDBusInterface nmIntf( NM_SVC_NAME,
NM_PATH,
NM_INTF_NAME,
QDBusConnection::systemBus(), 0 );
bool ok = false;
int nmState = nmIntf.property( "State" ).toInt( &ok );
if ( !ok || !nmIntf.isValid() )
{
// We can't talk to NM, so no idea. Wild guess: we're connected
// using ssh with X forwarding, and are therefore connected. This
// allows us to proceed with a minimum of complaint.
Calamares::JobQueue::instance()->globalStorage()->insert( "hasInternet", true );
return true;
}
bool hasInternet = nmState == NM_STATE_CONNECTED_GLOBAL;
Calamares::JobQueue::instance()->globalStorage()->insert( "hasInternet", hasInternet );
return hasInternet;
// default to true in the QNetworkAccessManager::UnknownAccessibility case
return QNetworkAccessManager(this).networkAccessible() != QNetworkAccessManager::NotAccessible;
}