Example #1
0
//! [0]
Cloud::Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent)
:   QGraphicsItem(parent), configuration(config), deleteAfterAnimation(false)
{
    session = new QNetworkSession(configuration, this);
    connect(session, SIGNAL(newConfigurationActivated()),
            this, SLOT(newConfigurationActivated()));
    connect(session, SIGNAL(stateChanged(QNetworkSession::State)),
            this, SLOT(stateChanged(QNetworkSession::State)));

    setFlag(ItemIsMovable);
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
    setFlag(ItemSendsGeometryChanges);
#endif
    setZValue(1);

    icon = new QGraphicsSvgItem(this);
    text = new QGraphicsTextItem(this);

    currentScale = 0;
    finalScale = 1;
    setTransform(QTransform::fromScale(currentScale, currentScale), false);
    setOpacity(0);

    newConfigurationActivated();
}
Example #2
0
SessionTab::SessionTab(QNetworkConfiguration* apNetworkConfiguration,
                       QNetworkConfigurationManager* configManager,
                       QListWidget* eventListWidget,
                       int index,
                       BearerEx * parent)
    : QWidget(parent), m_dataTransferer(0), m_eventListWidget(eventListWidget),
     m_index(index), m_alrEnabled (false)
{
    setupUi(this);

    m_ConfigManager = configManager;
    m_NetworkSession = new QNetworkSession(*apNetworkConfiguration);

    // Update initial Session state to UI
    newState(m_NetworkSession->state());

    connect(m_NetworkSession, SIGNAL(newConfigurationActivated()), this, SLOT(newConfigurationActivated()));
    connect(m_NetworkSession, SIGNAL(stateChanged(QNetworkSession::State)),
            this, SLOT(stateChanged(QNetworkSession::State)));
    connect(m_NetworkSession, SIGNAL(opened()), this, SLOT(opened()));
    connect(m_NetworkSession, SIGNAL(closed()), this, SLOT(closed()));
    connect(m_NetworkSession, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(error(QNetworkSession::SessionError)));
    
    if (apNetworkConfiguration->type() == QNetworkConfiguration::InternetAccessPoint) {
        snapLabel->hide();
        snapLineEdit->hide();
        alrButton->hide();
        iapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")");
    } else if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) {
        snapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")");
    }
    bearerLineEdit->setText(apNetworkConfiguration->bearerName());
    sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+
                                 QString(" / ")+
                                 QString::number(m_NetworkSession->bytesReceived()));
    snapLineEdit->setFocusPolicy(Qt::NoFocus);
    iapLineEdit->setFocusPolicy(Qt::NoFocus);
    bearerLineEdit->setFocusPolicy(Qt::NoFocus);
    sentRecDataLineEdit->setFocusPolicy(Qt::NoFocus);
    stateLineEdit->setFocusPolicy(Qt::NoFocus);
}
Example #3
0
void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &config)
{
    Q_Q(QNetworkAccessManager);

    initializeSession = false;

    if (networkSession)
        delete networkSession;

    if (!config.isValid()) {
        networkSession = 0;
        online = false;

        if (networkAccessible == QNetworkAccessManager::NotAccessible)
            emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
        else
            emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility);

        return;
    }

    networkSession = new QNetworkSession(config, q);

    QObject::connect(networkSession, SIGNAL(opened()), q, SIGNAL(networkSessionConnected()));
    QObject::connect(networkSession, SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()));
    QObject::connect(networkSession, SIGNAL(stateChanged(QNetworkSession::State)),
                     q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)));
    QObject::connect(networkSession, SIGNAL(newConfigurationActivated()),
                     q, SLOT(_q_networkSessionNewConfigurationActivated()));
    QObject::connect(networkSession,
                     SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)),
                     q,
                     SLOT(_q_networkSessionPreferredConfigurationChanged(QNetworkConfiguration,bool)));

    _q_networkSessionStateChanged(networkSession->state());
}
/*!
  Opens a new network session.
*/
void ConnectionManager::openNewNetworkSession()
{
    qDebug() << "ConnectionManager::openNewNetworkSession() =>";

    if (mState == Connecting) {
        qDebug() << "ConnectionManager::openNewNetworkSession()"
                 << "<= Already connecting!!!";
        return;
    }

    // Disconnect previous connection and delete the network session instance.
    disconnect();
    clearConnectionInformation();
    delete mNetworkSession;
    mNetworkSession = 0;

    // Set state to 'Connecting'.
    setState(Connecting);

    // Get the configurations.
    QList<QNetworkConfiguration> configurations =
            mNetworkConfMgr->allConfigurations(QNetworkConfiguration::Discovered);

    if (configurations.isEmpty()) {
        configurations << mNetworkConfMgr->defaultConfiguration();
    }

    bool sessionOpened(false);

    foreach (QNetworkConfiguration configuration, configurations) {
        if (!validWlanConfiguration(configuration)) {
            // Invalid configuration, try the next one.
            continue;
        }

        // Valid configuration found!
        mNetworkSession = new QNetworkSession(configuration, this);

        // Open the network session.
        mNetworkSession->open();

        if (mNetworkSession->waitForOpened()) {
            qDebug() << "ConnectionManager::openNewNetworkSession():"
                     << "Selecting" << configuration.name();

            // Connect the signals.
            connect(mNetworkSession, SIGNAL(closed()),
                    this, SLOT(handleNetworkSessionClosed()),
                    Qt::UniqueConnection);
            connect(mNetworkSession, SIGNAL(error(QNetworkSession::SessionError)),
                    this, SLOT(handleError(QNetworkSession::SessionError)),
                    Qt::UniqueConnection);
            connect(mNetworkSession, SIGNAL(newConfigurationActivated()),
                    this, SLOT(handleNewConfigurationActivated()),
                    Qt::UniqueConnection);
            connect(mNetworkSession, SIGNAL(stateChanged(QNetworkSession::State)),
                    this, SLOT(handleStateChanged(QNetworkSession::State)),
                    Qt::UniqueConnection);

            handleNetworkSessionOpened();
            sessionOpened = true;

            break;
        }
        else {
            qDebug() << "ConnectionManager::openNewNetworkSession():"
                     << "Failed to open" << configuration.name()
                     << ":" << mNetworkSession->errorString();

            delete mNetworkSession;
            mNetworkSession = 0;
        }
    }

    if (!sessionOpened) {
        qDebug() << "ConnectionManager::openNewNetworkSession():"
                 << "No valid session opened!";
        setState(Failed);
    }

    qDebug() << "ConnectionManager::openNewNetworkSession() <=";
}
Example #5
0
QT_BEGIN_NAMESPACE

/*!
    \class QNetworkSession

    \brief The QNetworkSession class provides control over the system's access points
    and enables session management for cases when multiple clients access the same access point.

    \since 4.7

    \inmodule QtNetwork
    \ingroup network

    A QNetworkSession enables control over the system's network interfaces. The session's configuration
    parameter are determined via the QNetworkConfiguration object to which it is bound. Depending on the 
    type of the session (single access point or service network) a session may be linked to one or more
    network interfaces. By means of \l{open()}{opening} and \l{close()}{closing} of network sessions 
    a developer can start and stop the systems network interfaces. If the configuration represents 
    multiple access points (see \l QNetworkConfiguration::ServiceNetwork) more advanced features such as roaming may be supported.

    QNetworkSession supports session management within the same process and depending on the platform's 
    capabilities may support out-of-process sessions. If the same 
    network configuration is used by multiple open sessions the underlying network interface is only terminated once
    the last session has been closed.

    \section1 Roaming

    Applications may connect to the preferredConfigurationChanged() signal in order to 
    receive notifications when a more suitable access point becomes available. 
    In response to this signal the application must either initiate the roaming via migrate()
    or ignore() the new access point. Once the session has roamed the 
    newConfigurationActivated() signal is emitted. The application may now test the 
    carrier and must either accept() or reject() it. The session will return to the previous
    access point if the roaming was rejected. The subsequent state diagram depicts the required
    state transitions.
    
    \image roaming-states.png

    Some platforms may distinguish forced roaming and application level roaming (ALR). 
    ALR implies that the application controls (via migrate(), ignore(), accept() and reject()) 
    whether a network session can roam from one access point to the next. Such control is useful
    if the application maintains stateful socket connections and wants to control the transition from
    one interface to the next. Forced roaming implies that the system automatically roams to the next network without 
    consulting the application. This has the advantage that the application can make use of roaming features
    without actually being aware of it. It is expected that the application detects that the underlying 
    socket is broken and automatically reconnects via the new network link.

    If the platform supports both modes of roaming, an application indicates its preference
    by connecting to the preferredConfigurationChanged() signal. Connecting to this signal means that
    the application wants to take control over the roaming behavior and therefore implies application
    level roaming. If the client does not connect to the preferredConfigurationChanged(), forced roaming
    is used. If forced roaming is not supported the network session will not roam by default.

    Some applications may want to suppress any form of roaming altogether. Possible use cases may be 
    high priority downloads or remote services which cannot handle a roaming enabled client. Clients
    can suppress roaming by connecting to the preferredConfigurationChanged() signal and answer each
    signal emission with ignore().

    \sa QNetworkConfiguration, QNetworkConfigurationManager
*/

/*!
    \enum QNetworkSession::State

    This enum describes the connectivity state of the session. If the session is based on a
    single access point configuration the state of the session is the same as the state of the
    associated network interface.

    \value Invalid          The session is invalid due to an invalid configuration. This may 
                            happen due to a removed access point or a configuration that was 
                            invalid to begin with.
    \value NotAvailable     The session is based on a defined but not yet discovered QNetworkConfiguration
                            (see \l QNetworkConfiguration::StateFlag).
    \value Connecting       The network session is being established.
    \value Connected        The network session is connected. If the current process wishes to use this session
                            it has to register its interest by calling open(). A network session 
                            is considered to be ready for socket operations if it isOpen() and connected.
    \value Closing          The network session is in the process of being shut down.
    \value Disconnected     The network session is not connected. The associated QNetworkConfiguration
                            has the state QNetworkConfiguration::Discovered.
    \value Roaming          The network session is roaming from one access point to another 
                            access point.
*/

/*!
    \enum QNetworkSession::SessionError

    This enum describes the session errors that can occur.

    \value UnknownSessionError          An unidentified error occurred.
    \value SessionAbortedError          The session was aborted by the user or system.
    \value RoamingError                 The session cannot roam to a new configuration.
    \value OperationNotSupportedError   The operation is not supported for current configuration.
    \value InvalidConfigurationError    The operation cannot currently be performed for the
                                        current configuration.
*/

/*!
    \fn void QNetworkSession::stateChanged(QNetworkSession::State state)

    This signal is emitted whenever the state of the network session changes.
    The \a state parameter is the new state.

    \sa state()
*/

/*!
    \fn void QNetworkSession::error(QNetworkSession::SessionError error)

    This signal is emitted after an error occurred. The \a error parameter
    describes the error that occurred.

    \sa error(), errorString()
*/

/*!
    \fn void QNetworkSession::preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless)

    This signal is emitted when the preferred configuration/access point for the
    session changes. Only sessions which are based on service network configurations
    may emit this signal. \a config can be used to determine access point specific
    details such as proxy settings and \a isSeamless indicates whether roaming will
    break the sessions IP address.

    As a consequence to this signal the application must either start the roaming process
    by calling migrate() or choose to ignore() the new access point.

    If the roaming process is non-seamless the IP address will change which means that
    a socket becomes invalid. However seamless mobility can ensure that the local IP address
    does not change. This is achieved by using a virtual IP address which is bound to the actual
    link address. During the roaming process the virtual address is attached to the new link 
    address.

    Some platforms may support the concept of Forced Roaming and Application Level Roaming (ALR). 
    Forced roaming implies that the platform may simply roam to a new configuration without 
    consulting applications. It is up to the application to detect the link layer loss and reestablish
    its sockets. In contrast ALR provides the opportunity to prevent the system from roaming. 
    If this session is based on a configuration that supports roaming the application can choose
    whether it wants to be consulted (ALR use case) by connecting to this signal. For as long as this signal 
    connection remains the session remains registered as a roaming stakeholder; otherwise roaming will 
    be enforced by the platform.

    \sa migrate(), ignore(), QNetworkConfiguration::isRoamingAvailable()
*/

/*!
    \fn void QNetworkSession::newConfigurationActivated()

    This signal is emitted once the session has roamed to the new access point.
    The application may reopen its socket and test the suitability of the new network link.
    Subsequently it must either accept() or reject() the new access point. 

    \sa accept(), reject()
*/

/*!
    \fn void QNetworkSession::opened()

    This signal is emitted when the network session has been opened. 
    
    The underlying network interface will not be shut down as long as the session remains open.
    Note that this feature is dependent on \l{QNetworkConfigurationManager::SystemSessionSupport}{system wide session support}.
*/

/*!
    \fn void QNetworkSession::closed()

    This signal is emitted when the network session has been closed.
*/

/*!
    Constructs a session based on \a connectionConfig with the given \a parent.

    \sa QNetworkConfiguration
*/
QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent)
:   QObject(parent), d(0)
{
    foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->engines()) {
        if (engine->hasIdentifier(connectionConfig.identifier())) {
            d = engine->createSessionBackend();
            d->q = this;
            d->publicConfig = connectionConfig;
            d->syncStateWithInterface();
            connect(d, SIGNAL(quitPendingWaitsForOpened()), this, SIGNAL(opened()));
            connect(d, SIGNAL(error(QNetworkSession::SessionError)),
                    this, SIGNAL(error(QNetworkSession::SessionError)));
            connect(d, SIGNAL(stateChanged(QNetworkSession::State)),
                    this, SIGNAL(stateChanged(QNetworkSession::State)));
            connect(d, SIGNAL(closed()), this, SIGNAL(closed()));
            connect(d, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)),
                    this, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)));
            connect(d, SIGNAL(newConfigurationActivated()),
                    this, SIGNAL(newConfigurationActivated()));
            break;
        }
    }