diff --git a/sources/dataengine/netctl.cpp b/sources/dataengine/netctl.cpp index 4d3e5bd..163c93a 100644 --- a/sources/dataengine/netctl.cpp +++ b/sources/dataengine/netctl.cpp @@ -185,6 +185,8 @@ QString Netctl::getExtIp(const QString cmd) if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd; + // test network connection + if (!isNetworkActive()) return QString("N\\A"); TaskResult process = runTask(cmd); if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) @@ -317,6 +319,22 @@ QString Netctl::getStatus(const QString cmdNetctl, const QString cmdNetctlAuto) } +bool Netctl::isNetworkActive() +{ + if (debug) qDebug() << PDEBUG; + + QString cmd = QString("ping -c 1 google.com"); + if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd; + TaskResult process = runTask(cmd); + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; + + if (process.exitCode == 0) + return true; + else + return false; +} + + bool Netctl::updateSourceEvent(const QString &source) { if (debug) qDebug() << PDEBUG; diff --git a/sources/dataengine/netctl.h b/sources/dataengine/netctl.h index 85db121..694e363 100644 --- a/sources/dataengine/netctl.h +++ b/sources/dataengine/netctl.h @@ -37,6 +37,7 @@ public: QStringList getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto); QStringList getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto); QString getStatus(const QString cmdNetctl, const QString cmdNetctlAuto); + bool isNetworkActive(); protected: bool sourceRequestEvent(const QString &name);