diff --git a/qtbase/src/plugins/bearer/connman/connman.pro b/qtbase/src/plugins/bearer/connman/connman.pro index 43a5a720c6..57f19eb9d5 100644 --- a/qtbase/src/plugins/bearer/connman/connman.pro +++ b/qtbase/src/plugins/bearer/connman/connman.pro @@ -9,14 +9,14 @@ QT = core core-private network-private dbus core-private HEADERS += qconnmanservice_linux_p.h \ qofonoservice_linux_p.h \ qconnmanengine.h \ - ../qnetworksession_impl.h \ + qnetworksession_impl.h \ ../qbearerengine_impl.h SOURCES += main.cpp \ qconnmanservice_linux.cpp \ qofonoservice_linux.cpp \ qconnmanengine.cpp \ - ../qnetworksession_impl.cpp + qnetworksession_impl.cpp OTHER_FILES += connman.json diff --git a/qtbase/src/plugins/bearer/connman/qconnmanengine.cpp b/qtbase/src/plugins/bearer/connman/qconnmanengine.cpp index 834d5d72b2..5ff0fa4f00 100644 --- a/qtbase/src/plugins/bearer/connman/qconnmanengine.cpp +++ b/qtbase/src/plugins/bearer/connman/qconnmanengine.cpp @@ -41,7 +41,7 @@ #include "qconnmanengine.h" #include "qconnmanservice_linux_p.h" -#include "../qnetworksession_impl.h" +#include "qnetworksession_impl.h" #include @@ -67,7 +67,9 @@ QConnmanEngine::QConnmanEngine(QObject *parent) connmanManager(new QConnmanManagerInterface(this)), ofonoManager(new QOfonoManagerInterface(this)), ofonoNetwork(0), - ofonoContextManager(0) + ofonoContextManager(0), + connSelectorInterface(0), + connectionDialogOpened(false) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); @@ -77,6 +79,7 @@ QConnmanEngine::QConnmanEngine(QObject *parent) QConnmanEngine::~QConnmanEngine() { qt_safe_close(inotifyFileDescriptor); + delete connSelectorInterface; } bool QConnmanEngine::connmanAvailable() const @@ -100,6 +103,24 @@ void QConnmanEngine::initialize() connect(connmanManager,SIGNAL(servicesReady(QStringList)),this,SLOT(servicesReady(QStringList))); connect(connmanManager,SIGNAL(scanFinished()),this,SLOT(finishedScan())); + /* We create a default configuration which is a pseudo config */ + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate(); + cpPriv->name = "UserChoice"; + cpPriv->state = QNetworkConfiguration::Discovered; + cpPriv->isValid = true; + cpPriv->id = QStringLiteral("Any"); + cpPriv->type = QNetworkConfiguration::UserChoice; + cpPriv->purpose = QNetworkConfiguration::ServiceSpecificPurpose; + cpPriv->roamingSupported = false; + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + userChoiceConfigurations.insert(cpPriv->id, ptr); + foundConfigurations.append(cpPriv); + + locker.unlock(); + Q_EMIT configurationAdded(ptr); + locker.relock(); + foreach (const QString &servPath, connmanManager->getServices()) { addServiceConfiguration(servPath); } @@ -171,13 +192,19 @@ QString QConnmanEngine::getInterfaceFromId(const QString &id) bool QConnmanEngine::hasIdentifier(const QString &id) { QMutexLocker locker(&mutex); - return accessPointConfigurations.contains(id); + return accessPointConfigurations.contains(id) || + userChoiceConfigurations.contains(id); } void QConnmanEngine::connectToId(const QString &id) { QMutexLocker locker(&mutex); + if (id == QStringLiteral("Any")) { + openConnectionDialog(QString()); + return; + } + QConnmanServiceInterface *serv = connmanServiceInterfaces.value(id); if (!serv->isValid()) { @@ -190,7 +217,7 @@ void QConnmanEngine::connectToId(const QString &id) return; } if (isAlwaysAskRoaming()) { - emit connectionError(id, QBearerEngineImpl::OperationNotSupported); + Q_EMIT openDialog(QStringLiteral("cellular")); return; } } @@ -250,6 +277,18 @@ QNetworkSession::State QConnmanEngine::sessionStateForId(const QString &id) { QMutexLocker locker(&mutex); + if (id == QStringLiteral("Any")) { + QNetworkConfigurationPrivatePointer userPtr = userChoiceConfigurations.value(QStringLiteral("Any")); + + if ((userPtr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } + + if ((userPtr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } + } + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr || !ptr->isValid) @@ -335,19 +374,13 @@ QNetworkConfigurationManager::Capabilities QConnmanEngine::capabilities() const QNetworkSessionPrivate *QConnmanEngine::createSessionBackend() { - return new QNetworkSessionPrivateImpl; + return new QNetworkSessionPrivateImpl; } QNetworkConfigurationPrivatePointer QConnmanEngine::defaultConfiguration() { const QMutexLocker locker(&mutex); - Q_FOREACH (const QString &servPath, connmanManager->getServices()) { - if (connmanServiceInterfaces.contains(servPath)) { - if (accessPointConfigurations.contains(servPath)) - return accessPointConfigurations.value(servPath); - } - } - return QNetworkConfigurationPrivatePointer(); + return userChoiceConfigurations.value(QStringLiteral("Any")); } void QConnmanEngine::serviceStateChanged(const QString &state) @@ -388,6 +421,47 @@ void QConnmanEngine::configurationChange(QConnmanServiceInterface *serv) ptr->mutex.unlock(); + QNetworkConfigurationPrivatePointer userPtr = userChoiceConfigurations.value(QStringLiteral("Any")); + + bool userChanged = false; + + userPtr->mutex.lock(); + + if (userPtr->name == networkName && userPtr->state != ptr->state) { + userPtr->name = "UserChoice"; + userPtr->state = QNetworkConfiguration::Discovered; + userPtr->type = QNetworkConfiguration::UserChoice; + userPtr->roamingSupported = false; + userChanged = true; + + } else if (userPtr->name != networkName && serv->state() == QStringLiteral("online")) { + + if (!userPtr->isValid) { + userPtr->isValid = true; + } + + if (userPtr->name != networkName) { + userPtr->name = networkName; + userChanged = true; + } + + if (userPtr->state != curState) { + userPtr->state = curState; + userChanged = true; + } + + userPtr->roamingSupported = ptr->roamingSupported; + userPtr->type = ptr->type; + } + userPtr->mutex.unlock(); + + if (userChanged) { + locker.unlock(); + Q_EMIT configurationChanged(userPtr); + locker.relock(); + } + + if (changed) { locker.unlock(); emit configurationChanged(ptr); @@ -410,8 +484,7 @@ QNetworkConfiguration::StateFlags QConnmanEngine::getStateForService(const QStri if (serv->type() == QLatin1String("cellular")) { if (!serv->autoConnect() - || (serv->roaming() - && (isAlwaysAskRoaming() || !isRoamingAllowed(serv->path())))) { + || (serv->roaming() && !isRoamingAllowed(serv->path()))) { flag = (flag | QNetworkConfiguration::Defined); } else { flag = (flag | QNetworkConfiguration::Discovered); @@ -556,6 +629,24 @@ void QConnmanEngine::addServiceConfiguration(const QString &servicePath) locker.unlock(); Q_EMIT configurationAdded(ptr); locker.relock(); + + QNetworkConfigurationPrivatePointer userPtr = userChoiceConfigurations.value(QStringLiteral("Any")); + // update the user configuration if this one is online + + if ((cpPriv->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active + && (userPtr->state & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) { + + userPtr->mutex.lock(); + userPtr->name = networkName; + userPtr->id = cpPriv->id; + userPtr->state = cpPriv->state; + userPtr->roamingSupported = cpPriv->roamingSupported; + userPtr->mutex.unlock(); + + locker.unlock(); + Q_EMIT configurationChanged(userPtr); + locker.relock(); + } } } @@ -592,6 +683,47 @@ void QConnmanEngine::inotifyActivated() } } + +void QConnmanEngine::openConnectionDialog(const QString &type) +{ + if (connectionDialogOpened) + return; + // open Connection Selector + if (!connSelectorInterface) { + connSelectorInterface = new QDBusInterface(QStringLiteral("com.jolla.lipstick.ConnectionSelector"), + QStringLiteral("/"), + QStringLiteral("com.jolla.lipstick.ConnectionSelectorIf"), + QDBusConnection::sessionBus(), + 0); + } + connSelectorInterface->connection().connect(QStringLiteral("com.jolla.lipstick.ConnectionSelector"), + QStringLiteral("/"), + QStringLiteral("com.jolla.lipstick.ConnectionSelectorIf"), + QStringLiteral("connectionSelectorClosed"), + this, + SLOT(connectionDialogClosed(bool))); + QList args; + args.append(type); + connSelectorInterface->callWithArgumentList(QDBus::NoBlock, + QStringLiteral("openConnection"), args); + connectionDialogOpened = true; +} + +void QConnmanEngine::connectionDialogClosed(bool b) +{ + connSelectorInterface->connection().disconnect(QStringLiteral("com.jolla.lipstick.ConnectionSelector"), + QStringLiteral("/"), + QStringLiteral("com.jolla.lipstick.ConnectionSelectorIf"), + QStringLiteral("connectionSelectorClosed"), + this, + SLOT(connectionDialogClosed(bool))); + + if (!b && connectionDialogOpened) { + Q_EMIT dialogClosed(b); + } + connectionDialogOpened = false; +} + QT_END_NAMESPACE #endif // QT_NO_DBUS diff --git a/qtbase/src/plugins/bearer/connman/qconnmanengine.h b/qtbase/src/plugins/bearer/connman/qconnmanengine.h index 4a4e91659b..317872ac6b 100644 --- a/qtbase/src/plugins/bearer/connman/qconnmanengine.h +++ b/qtbase/src/plugins/bearer/connman/qconnmanengine.h @@ -97,6 +97,12 @@ class QConnmanEngine : public QBearerEngineImpl QList getConfigurations(); + void openConnectionDialog(const QString &type); + +Q_SIGNALS: + void openDialog(const QString &type); + void dialogClosed(bool); + private Q_SLOTS: void doRequestUpdate(); @@ -109,6 +115,9 @@ private Q_SLOTS: void configurationChange(QConnmanServiceInterface * service); void reEvaluateCellular(); void inotifyActivated(); + + void connectionDialogClosed(bool b); + private: QConnmanManagerInterface *connmanManager; @@ -139,9 +148,12 @@ private Q_SLOTS: int inotifyWatcher; int inotifyFileDescriptor; + QDBusInterface *connSelectorInterface; + bool connectionDialogOpened; protected: bool requiresPolling() const; + }; diff --git a/qtbase/src/plugins/bearer/connman/qnetworksession_impl.cpp b/qtbase/src/plugins/bearer/connman/qnetworksession_impl.cpp new file mode 100644 index 0000000000..3209c46b4e --- /dev/null +++ b/qtbase/src/plugins/bearer/connman/qnetworksession_impl.cpp @@ -0,0 +1,478 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** Copyright (C) 2014 Jolla Oy +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworksession_impl.h" +#include "../qbearerengine_impl.h" + +#include +#include + +#include +#include +#include +#include +#include + +#ifndef QT_NO_BEARERMANAGEMENT + +QT_BEGIN_NAMESPACE + +static QBearerEngineImpl *getEngineFromId(const QString &id) +{ + QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); + + foreach (QBearerEngine *engine, priv->engines()) { + QBearerEngineImpl *engineImpl = qobject_cast(engine); + if (engineImpl && engineImpl->hasIdentifier(id)) + return engineImpl; + } + + return 0; +} + +class QNetworkSessionManagerPrivate : public QObject +{ + Q_OBJECT + +public: + QNetworkSessionManagerPrivate(QObject *parent = 0) : QObject(parent) {} + ~QNetworkSessionManagerPrivate() {} + + inline void forceSessionClose(const QNetworkConfiguration &config) + { emit forcedSessionClose(config); } + +Q_SIGNALS: + void forcedSessionClose(const QNetworkConfiguration &config); +}; + +#include "qnetworksession_impl.moc" + +Q_GLOBAL_STATIC(QNetworkSessionManagerPrivate, sessionManager); + +void QNetworkSessionPrivateImpl::syncStateWithInterface() +{ + connect(sessionManager(), SIGNAL(forcedSessionClose(QNetworkConfiguration)), + this, SLOT(forcedSessionClose(QNetworkConfiguration))); + + opened = false; + isOpen = false; + state = QNetworkSession::Invalid; + lastError = QNetworkSession::UnknownSessionError; + + qRegisterMetaType(); + + switch (publicConfig.type()) { + case QNetworkConfiguration::InternetAccessPoint: + case QNetworkConfiguration::UserChoice: + activeConfig = publicConfig; + engine = getEngineFromId(activeConfig.identifier()); + if (engine) { + qRegisterMetaType(); + connect(engine, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer)), + Qt::QueuedConnection); + connect(engine, SIGNAL(connectionError(QString,QBearerEngineImpl::ConnectionError)), + this, SLOT(connectionError(QString,QBearerEngineImpl::ConnectionError)), + Qt::QueuedConnection); + connect(engine,SIGNAL(dialogClosed(bool)),this,SLOT(connectionSelectorClosed(bool)), + Qt::UniqueConnection); + } + break; + case QNetworkConfiguration::ServiceNetwork: + serviceConfig = publicConfig; + default: + engine = 0; + } + + networkConfigurationsChanged(); +} + +void QNetworkSessionPrivateImpl::open() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit QNetworkSessionPrivate::error(lastError); + } else if (!isOpen) { + + if (activeConfig.type() == QNetworkConfiguration::UserChoice) { + + if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) { + if (connectInBackground) { + // client wanted automatic background connection, but none are enabled/found + // so don't bother user + lastError = QNetworkSession::SessionAbortedError; + emit QNetworkSessionPrivate::error(lastError); + return; + } else { + opened = true; + state = QNetworkSession::Connecting; + emit stateChanged(state); + engine->connectToId(QStringLiteral("Any")); + return; + } + } + } + if ((activeConfig.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { + lastError = QNetworkSession::InvalidConfigurationError; + state = QNetworkSession::NotAvailable; + emit stateChanged(state); + emit QNetworkSessionPrivate::error(lastError); + return; + } + opened = true; + + if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) { + state = QNetworkSession::Connecting; + emit stateChanged(state); + + engine->connectToId(activeConfig.identifier()); + } + + isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + if (isOpen) + emit quitPendingWaitsForOpened(); + } +} + +void QNetworkSessionPrivateImpl::close() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit QNetworkSessionPrivate::error(lastError); + } else if (isOpen) { + opened = false; + isOpen = false; + emit closed(); + } +} + +void QNetworkSessionPrivateImpl::stop() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit QNetworkSessionPrivate::error(lastError); + } else { + if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Closing; + emit stateChanged(state); + + engine->disconnectFromId(activeConfig.identifier()); + + sessionManager()->forceSessionClose(activeConfig); + } + + opened = false; + isOpen = false; + emit closed(); + } +} + +void QNetworkSessionPrivateImpl::migrate() +{ +} + +void QNetworkSessionPrivateImpl::accept() +{ +} + +void QNetworkSessionPrivateImpl::ignore() +{ +} + +void QNetworkSessionPrivateImpl::reject() +{ +} + +#ifndef QT_NO_NETWORKINTERFACE +QNetworkInterface QNetworkSessionPrivateImpl::currentInterface() const +{ + if (!engine || state != QNetworkSession::Connected || !publicConfig.isValid()) + return QNetworkInterface(); + + QString interface = engine->getInterfaceFromId(activeConfig.identifier()); + if (interface.isEmpty()) + return QNetworkInterface(); + return QNetworkInterface::interfaceFromName(interface); +} +#endif + +QVariant QNetworkSessionPrivateImpl::sessionProperty(const QString &key) const +{ + if (key == QLatin1String("ConnectInBackground")) { + return connectInBackground; + } + return QVariant(); +} + +void QNetworkSessionPrivateImpl::setSessionProperty(const QString &key, const QVariant &value) +{ + if (key == QLatin1String("ConnectInBackground")) { + connectInBackground = value.toBool(); + } +} + +QString QNetworkSessionPrivateImpl::errorString() const +{ + switch (lastError) { + case QNetworkSession::UnknownSessionError: + return tr("Unknown session error."); + case QNetworkSession::SessionAbortedError: + return tr("The session was aborted by the user or system."); + case QNetworkSession::OperationNotSupportedError: + return tr("The requested operation is not supported by the system."); + case QNetworkSession::InvalidConfigurationError: + return tr("The specified configuration cannot be used."); + case QNetworkSession::RoamingError: + return tr("Roaming was aborted or is not possible."); + default: + break; + } + + return QString(); +} + +QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const +{ + return lastError; +} + +quint64 QNetworkSessionPrivateImpl::bytesWritten() const +{ + if (engine && state == QNetworkSession::Connected) + return engine->bytesWritten(activeConfig.identifier()); + return Q_UINT64_C(0); +} + +quint64 QNetworkSessionPrivateImpl::bytesReceived() const +{ + if (engine && state == QNetworkSession::Connected) + return engine->bytesReceived(activeConfig.identifier()); + return Q_UINT64_C(0); +} + +quint64 QNetworkSessionPrivateImpl::activeTime() const +{ + if (state == QNetworkSession::Connected && startTime != Q_UINT64_C(0)) + return QDateTime::currentDateTime().toTime_t() - startTime; + return Q_UINT64_C(0); +} + +QNetworkSession::UsagePolicies QNetworkSessionPrivateImpl::usagePolicies() const +{ + return currentPolicies; +} + +void QNetworkSessionPrivateImpl::setUsagePolicies(QNetworkSession::UsagePolicies newPolicies) +{ + if (newPolicies != currentPolicies) { + currentPolicies = newPolicies; + emit usagePoliciesChanged(currentPolicies); + } +} + +void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() +{ + QNetworkSession::State oldState = state; + + foreach (const QNetworkConfiguration &config, serviceConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) + continue; + + if (activeConfig != config) { + if (engine) { + disconnect(engine, SIGNAL(connectionError(QString,QBearerEngineImpl::ConnectionError)), + this, SLOT(connectionError(QString,QBearerEngineImpl::ConnectionError))); + } + + activeConfig = config; + engine = getEngineFromId(activeConfig.identifier()); + + if (engine) { + connect(engine, SIGNAL(connectionError(QString,QBearerEngineImpl::ConnectionError)), + this, SLOT(connectionError(QString,QBearerEngineImpl::ConnectionError)), + Qt::QueuedConnection); + } + emit newConfigurationActivated(); + } + + state = QNetworkSession::Connected; + if (state != oldState) + emit stateChanged(state); + + return; + } + + if (serviceConfig.children().isEmpty()) + state = QNetworkSession::NotAvailable; + else + state = QNetworkSession::Disconnected; + + if (state != oldState) + emit stateChanged(state); +} + +void QNetworkSessionPrivateImpl::updateStateFromActiveConfig() +{ + if (!engine) + return; + + QNetworkSession::State oldState = state; + state = engine->sessionStateForId(activeConfig.identifier()); + bool oldActive = isOpen; + + isOpen = (state == QNetworkSession::Connected) ? opened : false; + + if (!oldActive && isOpen) + emit quitPendingWaitsForOpened(); + if (oldActive && !isOpen) + emit closed(); + + if (oldState != state) + emit stateChanged(state); +} + +void QNetworkSessionPrivateImpl::networkConfigurationsChanged() +{ + if (serviceConfig.isValid()) + updateStateFromServiceNetwork(); + else + updateStateFromActiveConfig(); + + if (!engine) + return; + startTime = engine->startTime(activeConfig.identifier()); +} + +void QNetworkSessionPrivateImpl::configurationChanged(QNetworkConfigurationPrivatePointer config) +{ + if (serviceConfig.isValid() && + (config->id == serviceConfig.identifier() || config->id == activeConfig.identifier())) { + updateStateFromServiceNetwork(); + } else if (config->id == activeConfig.identifier()) { + updateStateFromActiveConfig(); + } +} + +void QNetworkSessionPrivateImpl::forcedSessionClose(const QNetworkConfiguration &config) +{ + if (activeConfig == config) { + opened = false; + isOpen = false; + + emit closed(); + + lastError = QNetworkSession::SessionAbortedError; + emit QNetworkSessionPrivate::error(lastError); + } +} + +void QNetworkSessionPrivateImpl::connectionError(const QString &id, QBearerEngineImpl::ConnectionError error) +{ + if (activeConfig.identifier() == id) { + networkConfigurationsChanged(); + switch (error) { + case QBearerEngineImpl::OperationNotSupported: + lastError = QNetworkSession::OperationNotSupportedError; + opened = false; + break; + case QBearerEngineImpl::InterfaceLookupError: + case QBearerEngineImpl::ConnectError: + case QBearerEngineImpl::DisconnectionError: + default: + lastError = QNetworkSession::UnknownSessionError; + } + + emit QNetworkSessionPrivate::error(lastError); + } +} + +void QNetworkSessionPrivateImpl::decrementTimeout() +{ + if (--sessionTimeout <= 0) { + disconnect(engine, SIGNAL(updateCompleted()), this, SLOT(decrementTimeout())); + sessionTimeout = -1; + close(); + } +} + +void QNetworkSessionPrivateImpl::connectionSelectorClosed(bool b) +{ + if (!b) { + //canceled + opened = false; + lastError = QNetworkSession::SessionAbortedError; + state = QNetworkSession::NotAvailable; + emit stateChanged(state); + emit QNetworkSessionPrivate::error(lastError); + } +} + +QNetworkConfiguration& QNetworkSessionPrivateImpl::copyConfig(QNetworkConfiguration &, + QNetworkConfiguration &toConfig, + bool ) +{ + QNetworkConfigurationPrivate *cpPriv; + cpPriv = new QNetworkConfigurationPrivate; + setPrivateConfiguration(toConfig, QNetworkConfigurationPrivatePointer(cpPriv)); + + QNetworkConfigurationPrivate *fromPriv= new QNetworkConfigurationPrivate; + setPrivateConfiguration(toConfig, QNetworkConfigurationPrivatePointer(fromPriv)); + + QMutexLocker toLocker(&cpPriv->mutex); + QMutexLocker fromLocker(&fromPriv->mutex); + + cpPriv->name = fromPriv->name; + cpPriv->isValid = fromPriv->isValid; + // Note that we do not copy id field here + cpPriv->state = fromPriv->state; + cpPriv->type = fromPriv->type; + cpPriv->roamingSupported = fromPriv->roamingSupported; + cpPriv->purpose = fromPriv->purpose; + cpPriv->bearerType = fromPriv->bearerType; + + return toConfig; +} + + +QT_END_NAMESPACE + +#endif // QT_NO_BEARERMANAGEMENT diff --git a/qtbase/src/plugins/bearer/connman/qnetworksession_impl.h b/qtbase/src/plugins/bearer/connman/qnetworksession_impl.h new file mode 100644 index 0000000000..b6fd0bbe27 --- /dev/null +++ b/qtbase/src/plugins/bearer/connman/qnetworksession_impl.h @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKSESSION_IMPL_H +#define QNETWORKSESSION_IMPL_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "../qbearerengine_impl.h" + +#include +#include + +#ifndef QT_NO_BEARERMANAGEMENT + +QT_BEGIN_NAMESPACE + +class QBearerEngineImpl; +class QDBusInterface; + +class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate +{ + Q_OBJECT + +public: + QNetworkSessionPrivateImpl() + : engine(0), startTime(0), lastError(QNetworkSession::UnknownSessionError), sessionTimeout(-1), + currentPolicies(QNetworkSession::NoPolicy), opened(false), + connectInBackground(false) + {} + ~QNetworkSessionPrivateImpl() + {} + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + +#ifndef QT_NO_NETWORKINTERFACE + QNetworkInterface currentInterface() const; +#endif + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + + void open(); + void close(); + void stop(); + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + + QNetworkSession::UsagePolicies usagePolicies() const; + void setUsagePolicies(QNetworkSession::UsagePolicies); + +private Q_SLOTS: + void networkConfigurationsChanged(); + void configurationChanged(QNetworkConfigurationPrivatePointer config); + void forcedSessionClose(const QNetworkConfiguration &config); + void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error); + void decrementTimeout(); + void connectionSelectorClosed(bool b); + +private: + void updateStateFromServiceNetwork(); + void updateStateFromActiveConfig(); + QNetworkConfiguration& copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy = true); + +private: + QBearerEngineImpl *engine; + + quint64 startTime; + + QNetworkSession::SessionError lastError; + + int sessionTimeout; + QNetworkSession::UsagePolicies currentPolicies; + bool opened; + + bool connectInBackground; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_BEARERMANAGEMENT + +#endif // QNETWORKSESSION_IMPL_H