diff options
-rw-r--r-- | src/network/bearer/qnetworkconfiguration.cpp | 70 | ||||
-rw-r--r-- | src/network/bearer/qnetworkconfiguration.h | 5 | ||||
-rw-r--r-- | tests/manual/qnetworkconfiguration/main.cpp | 23 |
3 files changed, 95 insertions, 3 deletions
diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index 52fbb2441f..fae4aad76e 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -41,10 +41,10 @@ #include "qnetworkconfiguration.h" #include "qnetworkconfiguration_p.h" +#include <QDebug> #ifdef Q_OS_BLACKBERRY #include "private/qcore_unix_p.h" // qt_safe_open -#include <QDebug> #include <sys/pps.h> #endif // Q_OS_BLACKBERRY @@ -199,6 +199,8 @@ QT_BEGIN_NAMESPACE \value BearerEthernet The configuration is for an Ethernet interfaces. \value BearerWLAN The configuration is for a Wireless LAN interface. \value Bearer2G The configuration is for a CSD, GPRS, HSCSD, EDGE or cdmaOne interface. + \value Bearer3G The configuration is for a 3G interface. + \value Bearer4G The configuration is for a 4G interface. \value BearerCDMA2000 The configuration is for CDMA interface. \value BearerWCDMA The configuration is for W-CDMA/UMTS interface. \value BearerHSPA The configuration is for High Speed Packet Access (HSPA) interface. @@ -491,6 +493,8 @@ QList<QNetworkConfiguration> QNetworkConfiguration::children() const function can be used to retrieve a textural type name for the bearer. An invalid network configuration always returns the BearerUnknown value. + + \sa bearerTypeName(), bearerTypeFamily() */ QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const { @@ -515,6 +519,58 @@ QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const } /*! + \since 5.2 + + Returns the bearer type family used by this network configuration. + The following table lists how bearerType() values map to + bearerTypeFamily() values: + + \table + \header + \li bearer type + \li bearer type family + \row + \li BearerUnknown, Bearer2G, BearerEthernet, BearerWLAN, + BearerBluetooth + \li (same type) + \row + \li BearerCDMA2000, BearerEVDO, BearerWCDMA, BearerHSPA, Bearer3G + \li Bearer3G + \row + \li BearerWiMAX, BearerLTE, Bearer4G + \li Bearer4G + \endtable + + An invalid network configuration always returns the BearerUnknown value. + + \sa bearerType(), bearerTypeName() +*/ +QNetworkConfiguration::BearerType QNetworkConfiguration::bearerTypeFamily() const +{ + QNetworkConfiguration::BearerType type = bearerType(); + switch (type) { + case QNetworkConfiguration::BearerUnknown: // fallthrough + case QNetworkConfiguration::Bearer2G: // fallthrough + case QNetworkConfiguration::BearerEthernet: // fallthrough + case QNetworkConfiguration::BearerWLAN: // fallthrough + case QNetworkConfiguration::BearerBluetooth: + return type; + case QNetworkConfiguration::BearerCDMA2000: // fallthrough + case QNetworkConfiguration::BearerEVDO: // fallthrough + case QNetworkConfiguration::BearerWCDMA: // fallthrough + case QNetworkConfiguration::BearerHSPA: // fallthrough + case QNetworkConfiguration::Bearer3G: + return QNetworkConfiguration::Bearer3G; + case QNetworkConfiguration::BearerWiMAX: // fallthrough + case QNetworkConfiguration::BearerLTE: // fallthrough + case QNetworkConfiguration::Bearer4G: + return QNetworkConfiguration::Bearer4G; + default: + qWarning() << "unknown bearer type" << type; + return QNetworkConfiguration::BearerUnknown; + } +} +/*! Returns the type of bearer used by this network configuration as a string. The string is not translated and therefore can not be shown to the user. The subsequent table @@ -541,6 +597,12 @@ QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const \li Bearer2G \li 2G \row + \li Bearer3G + \li 3G + \row + \li Bearer4G + \li 4G + \row \li BearerCDMA2000 \li CDMA2000 \row @@ -567,7 +629,7 @@ QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const configuration of type \l QNetworkConfiguration::ServiceNetwork or \l QNetworkConfiguration::UserChoice. - \sa bearerType() + \sa bearerType(), bearerTypeFamily() */ QString QNetworkConfiguration::bearerTypeName() const { @@ -601,6 +663,10 @@ QString QNetworkConfiguration::bearerTypeName() const } #endif // Q_OS_BLACKBERRY return QStringLiteral("2G"); + case Bearer3G: + return QStringLiteral("3G"); + case Bearer4G: + return QStringLiteral("4G"); case BearerCDMA2000: return QStringLiteral("CDMA2000"); case BearerWCDMA: diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h index 8809e5526a..8887525a2f 100644 --- a/src/network/bearer/qnetworkconfiguration.h +++ b/src/network/bearer/qnetworkconfiguration.h @@ -99,7 +99,9 @@ public: BearerBluetooth, BearerWiMAX, BearerEVDO, - BearerLTE + BearerLTE, + Bearer3G, + Bearer4G }; StateFlags state() const; @@ -107,6 +109,7 @@ public: Purpose purpose() const; BearerType bearerType() const; + BearerType bearerTypeFamily() const; QString bearerTypeName() const; QString identifier() const; diff --git a/tests/manual/qnetworkconfiguration/main.cpp b/tests/manual/qnetworkconfiguration/main.cpp index 8bf5983796..c611cfc9e2 100644 --- a/tests/manual/qnetworkconfiguration/main.cpp +++ b/tests/manual/qnetworkconfiguration/main.cpp @@ -51,6 +51,7 @@ class tst_qnetworkconfiguration : public QObject private slots: void bearerType(); + void bearerTypeFamily(); }; void tst_qnetworkconfiguration::bearerType() @@ -111,6 +112,28 @@ void tst_qnetworkconfiguration::bearerType() } } +void tst_qnetworkconfiguration::bearerTypeFamily() +{ + QNetworkConfigurationManager m; + foreach (const QNetworkConfiguration &config, + m.allConfigurations(QNetworkConfiguration::Active)) { + QString family; + switch (config.bearerTypeFamily()) { + case QNetworkConfiguration::Bearer3G: + family = QLatin1String("Bearer3G"); + break; + case QNetworkConfiguration::Bearer4G: + family = QLatin1String("Bearer4G"); + break; + default: + family = config.bearerTypeName(); + } + qDebug() << config.name() << "has bearer type" + << config.bearerTypeName() << "of bearer type family" + << family; + } +} + QTEST_MAIN(tst_qnetworkconfiguration) #include "main.moc" |