summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2010-07-29 06:39:05 (GMT)
committerAaron McCarthy <aaron.mccarthy@nokia.com>2010-08-02 00:09:06 (GMT)
commitd12f39e50e4144f3272424bb0bff18c857105654 (patch)
treeffde9a7863c78af2adabcb9c7e85c79d9f79cfc6 /src/network
parent613bc8eb31d8a80b43aa045ab2040b7cb7e0eadf (diff)
downloadQt-d12f39e50e4144f3272424bb0bff18c857105654.zip
Qt-d12f39e50e4144f3272424bb0bff18c857105654.tar.gz
Qt-d12f39e50e4144f3272424bb0bff18c857105654.tar.bz2
Use an enum to return the bearer type of a network configuration.
Task-number: QTBUG-12378 Reviewed-by: Alex
Diffstat (limited to 'src/network')
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.cpp24
-rw-r--r--src/network/bearer/qnetworkconfiguration.cpp97
-rw-r--r--src/network/bearer/qnetworkconfiguration.h13
-rw-r--r--src/network/bearer/qnetworkconfiguration_p.h9
4 files changed, 114 insertions, 29 deletions
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp
index 5d4274f..c4f7c00 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.cpp
+++ b/src/network/bearer/qnetworkconfigmanager_p.cpp
@@ -150,25 +150,29 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration(
end = engine->accessPointConfigurations.end(); it != end; ++it) {
QNetworkConfigurationPrivatePointer ptr = it.value();
- const QString bearerName = ptr->bearerName();
QMutexLocker configLocker(&ptr->mutex);
+ QNetworkConfiguration::BearerType bearerType = ptr->bearerType;
if ((ptr->state & QNetworkConfiguration::Discovered) ==
QNetworkConfiguration::Discovered) {
if (!defaultConfiguration) {
defaultConfiguration = ptr;
} else {
+ QMutexLocker defaultConfigLocker(&defaultConfiguration->mutex);
+
if (defaultConfiguration->state == ptr->state) {
- if (defaultConfiguration->bearerName() == QLatin1String("Ethernet")) {
+ switch (defaultConfiguration->bearerType) {
+ case QNetworkConfiguration::BearerEthernet:
// do nothing
- } else if (defaultConfiguration->bearerName() == QLatin1String("WLAN")) {
- // ethernet beats wlan
- if (bearerName == QLatin1String("Ethernet"))
- defaultConfiguration = ptr;
- } else {
- // ethernet and wlan beats other
- if (bearerName == QLatin1String("Ethernet") ||
- bearerName == QLatin1String("WLAN")) {
+ break;
+ case QNetworkConfiguration::BearerWLAN:
+ // Ethernet beats WLAN
+ defaultConfiguration = ptr;
+ break;
+ default:
+ // Ethernet and WLAN beats other
+ if (bearerType == QNetworkConfiguration::BearerEthernet ||
+ bearerType == QNetworkConfiguration::BearerWLAN) {
defaultConfiguration = ptr;
}
}
diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp
index b939342..b645916 100644
--- a/src/network/bearer/qnetworkconfiguration.cpp
+++ b/src/network/bearer/qnetworkconfiguration.cpp
@@ -183,6 +183,23 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \enum QNetworkConfiguration::BearerType
+
+ Specifies the type of bearer used by a configuration.
+
+ \value BearerUnknown The type of bearer is unknown or unspecified. The bearerTypeName()
+ function may return additional information.
+ \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 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.
+ \value BearerBluetooth The configuration is for a Bluetooth interface.
+ \value BearerWiMAX The configuration is for a WiMAX interface.
+*/
+
+/*!
Constructs an invalid configuration object.
\sa isValid()
@@ -386,58 +403,110 @@ QList<QNetworkConfiguration> QNetworkConfiguration::children() const
\fn QString QNetworkConfiguration::bearerName() const
\deprecated
- This function is deprecated. It is equivalent to calling bearerTypeName().
+ This function is deprecated. It is equivalent to calling bearerTypeName(), however
+ bearerType() should be used in preference.
*/
/*!
+ Returns the type of bearer used by this network configuration.
+
+ If the bearer type is \l {QNetworkConfiguration::BearerUnknown}{unknown} the bearerTypeName()
+ function can be used to retrieve a textural type name for the bearer.
+
+ An invalid network configuration always returns the BearerUnknown value.
+*/
+QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const
+{
+ if (!isValid())
+ return BearerUnknown;
+
+ QMutexLocker locker(&d->mutex);
+
+ return d->bearerType;
+}
+
+/*!
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
- presents the currently known bearer types:
+ shows the fixed mappings between BearerType and the bearer type name for known types. If the
+ BearerType is unknown this function may return additional information if it is available;
+ otherwise an empty string will be returned.
\table
\header
+ \o BearerType
\o Value
- \o Description
\row
- \o Unknown
- \o The session is based on an unknown or unspecified bearer type.
+ \o BearerUnknown
+ \o
+ \o The session is based on an unknown or unspecified bearer type. The value of the
+ string returned describes the bearer type.
\row
+ \o BearerEthernet
\o Ethernet
- \o The session is based on Ethernet.
\row
+ \o BearerWLAN
\o WLAN
- \o The session is based on Wireless LAN.
\row
+ \o Bearer2G
\o 2G
- \o The session uses CSD, GPRS, HSCSD, EDGE or cdmaOne.
\row
+ \o BearerCDMA2000
\o CDMA2000
- \o The session uses CDMA.
\row
+ \o BearerWCDMA
\o WCDMA
- \o The session uses W-CDMA/UMTS.
\row
+ \o BearerHSPA
\o HSPA
- \o The session uses High Speed Packet Access.
\row
+ \o BearerBluetooth
\o Bluetooth
- \o The session uses Bluetooth.
\row
+ \o BearerWiMAX
\o WiMAX
- \o The session uses WiMAX.
\endtable
This function returns an empty string if this is an invalid configuration, a network
configuration of type \l QNetworkConfiguration::ServiceNetwork or
\l QNetworkConfiguration::UserChoice.
+
+ \sa bearerType()
*/
QString QNetworkConfiguration::bearerTypeName() const
{
if (!isValid())
return QString();
- return d->bearerName();
+ QMutexLocker locker(&d->mutex);
+
+ if (d->type == QNetworkConfiguration::ServiceNetwork ||
+ d->type == QNetworkConfiguration::UserChoice)
+ return QString();
+
+ switch (d->bearerType) {
+ case BearerUnknown:
+ return d->bearerTypeName();
+ case BearerEthernet:
+ return QLatin1String("Ethernet");
+ case BearerWLAN:
+ return QLatin1String("WLAN");
+ case Bearer2G:
+ return QLatin1String("2G");
+ case BearerCDMA2000:
+ return QLatin1String("CDMA2000");
+ case BearerWCDMA:
+ return QLatin1String("WCDMA");
+ case BearerHSPA:
+ return QLatin1String("HSPA");
+ case BearerBluetooth:
+ return QLatin1String("Bluetooth");
+ case BearerWiMAX:
+ return QLatin1String("WiMAX");
+ }
+
+ return QString();
}
QT_END_NAMESPACE
diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h
index 42e8b6a..d9d36fd 100644
--- a/src/network/bearer/qnetworkconfiguration.h
+++ b/src/network/bearer/qnetworkconfiguration.h
@@ -103,12 +103,25 @@ public:
Q_DECLARE_FLAGS(StateFlags, StateFlag)
+ enum BearerType {
+ BearerUnknown,
+ BearerEthernet,
+ BearerWLAN,
+ Bearer2G,
+ BearerCDMA2000,
+ BearerWCDMA,
+ BearerHSPA,
+ BearerBluetooth,
+ BearerWiMAX
+ };
+
StateFlags state() const;
Type type() const;
Purpose purpose() const;
// Required to maintain source compatibility with Qt Mobility.
QT_DEPRECATED inline QString bearerName() const { return bearerTypeName(); }
+ BearerType bearerType() const;
QString bearerTypeName() const;
QString identifier() const;
diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h
index 966dfb2..0fc6ee9 100644
--- a/src/network/bearer/qnetworkconfiguration_p.h
+++ b/src/network/bearer/qnetworkconfiguration_p.h
@@ -68,6 +68,7 @@ public:
QNetworkConfigurationPrivate ()
: mutex(QMutex::Recursive), type(QNetworkConfiguration::Invalid),
purpose(QNetworkConfiguration::UnknownPurpose),
+ bearerType(QNetworkConfiguration::BearerUnknown),
isValid(false), roamingSupported(false)
{
}
@@ -78,24 +79,22 @@ public:
serviceNetworkMembers.clear();
}
- virtual QString bearerName() const
+ virtual QString bearerTypeName() const
{
- QMutexLocker locker(&mutex);
-
- return bearer;
+ return QString();
}
QMap<unsigned int, QNetworkConfigurationPrivatePointer> serviceNetworkMembers;
mutable QMutex mutex;
- QString bearer;
QString name;
QString id;
QNetworkConfiguration::StateFlags state;
QNetworkConfiguration::Type type;
QNetworkConfiguration::Purpose purpose;
+ QNetworkConfiguration::BearerType bearerType;
bool isValid;
bool roamingSupported;