diff options
author | vladimirb <vladimir.bezkorovainyi@nokia.com> | 2012-05-07 18:18:41 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-16 04:06:15 +0200 |
commit | 9c68d7c658bc1901efa7b2e43a4a8be61a313c40 (patch) | |
tree | be5b93df166ad469ddf4bb50b50aa644aef76eac /src/plugins/geoservices/nokia/qgeouriprovider.cpp | |
parent | 89e01acaae12f1e3dedcd51478f49d0fc4b340e8 (diff) | |
download | qtlocation-9c68d7c658bc1901efa7b2e43a4a8be61a313c40.tar.gz |
China shifting support for dual sim
Change-Id: I278bad0a8b167a3a40c8e737622a83683e966e64
Reviewed-by: Alex Wilson <alex.wilson@nokia.com>
Diffstat (limited to 'src/plugins/geoservices/nokia/qgeouriprovider.cpp')
-rw-r--r-- | src/plugins/geoservices/nokia/qgeouriprovider.cpp | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/src/plugins/geoservices/nokia/qgeouriprovider.cpp b/src/plugins/geoservices/nokia/qgeouriprovider.cpp new file mode 100644 index 00000000..6aa43f36 --- /dev/null +++ b/src/plugins/geoservices/nokia/qgeouriprovider.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +** This file is part of the Ovi services plugin for the Maps and +** Navigation API. The use of these services, whether by use of the +** plugin or by other means, is governed by the terms and conditions +** described by the file OVI_SERVICES_TERMS_AND_CONDITIONS.txt in +** this package, located in the directory containing the Ovi services +** plugin source code. +** +****************************************************************************/ +#include "qgeouriprovider.h" + +#ifdef USE_CHINA_NETWORK_REGISTRATION +#include <QNetworkInfo> +#endif + +#include <QMap> +#include <QVariant> +#include <QSet> +#include <QString> + +QT_BEGIN_NAMESPACE + +namespace +{ + const QString CHINA_MCC = QStringLiteral("460"); // China mobile country code + const QString CHINA2_MCC = QStringLiteral("461"); // China mobile country code + const QString HONG_KONG_MCC = QStringLiteral("454"); // Hong Kong mobile country code + const QString MACAU_MCC = QStringLiteral("455"); // Macau mobile country code +} + +QGeoUriProvider::QGeoUriProvider( + QObject *parent, + const QMap<QString, QVariant> & parameters, + const QString &hostParameterName, + const QString &internationalHost, + const QString &localizedHost) + : QObject(parent) +#ifdef USE_CHINA_NETWORK_REGISTRATION + , m_networkInfo(new QNetworkInfo(this)) +#endif + , m_internationalHost(parameters.value(hostParameterName, internationalHost).toString()) + , m_localizedHost(localizedHost) + , m_firstSubdomain(QChar::Null) + , m_maxSubdomains(0) +{ +#ifdef USE_CHINA_NETWORK_REGISTRATION + QObject::connect(m_networkInfo, SIGNAL(currentMobileCountryCodeChanged(int, const QString&)), this, SLOT(mobileCountryCodeChanged(int, const QString &))); +#endif + setCurrentHost(isInternationalNetwork() || m_localizedHost.isEmpty() ? m_internationalHost : m_localizedHost); +} + +QString QGeoUriProvider::getCurrentHost() const +{ + if (m_maxSubdomains) { + QString result(m_firstSubdomain.toAscii() + qrand() % m_maxSubdomains); + result += "." + m_currentHost; + return result; + } + return m_currentHost; +} + +void QGeoUriProvider::setCurrentHost(const QString &host) +{ + if (host.length() > 4 && host.at(1) == QChar('-') && host.at(3) == QChar('.')) { + QString realHost = host.right(host.length() - 4); + m_firstSubdomain = host.at(0); + m_maxSubdomains = host.at(2).toAscii() - host.at(0).toAscii() + 1; + m_currentHost = realHost; + } else { + m_currentHost = host; + m_firstSubdomain = QChar::Null; + m_maxSubdomains = 0; + } +} + +void QGeoUriProvider::mobileCountryCodeChanged(int interface, const QString& mcc) +{ + Q_UNUSED(interface) + Q_UNUSED(mcc) + + setCurrentHost(isInternationalNetwork() || m_localizedHost.isEmpty() ? m_internationalHost : m_localizedHost); +} + +bool QGeoUriProvider::isInternationalNetwork() const +{ +#ifndef USE_CHINA_NETWORK_REGISTRATION + return true; +#else + static QSet<QString> codes; + if (codes.empty()) { + codes.insert(CHINA_MCC); + codes.insert(CHINA2_MCC); + } + + QNetworkInfo::NetworkMode mode = m_networkInfo->currentNetworkMode(); + + int interfaces = m_networkInfo->networkInterfaceCount(mode); + for (int i = 0; i < interfaces; ++i) { + QString mcc = m_networkInfo->currentMobileCountryCode(interfaces); + if (codes.contains(mcc)) + return false; + } + + return true; +#endif // USE_CHINA_NETWORK_REGISTRATION +} + +QT_END_NAMESPACE |