browsercore/core/network/WebNetworkConnectionManager.cpp
changeset 0 1450b09d0cfd
child 3 0954f5dd2cd0
child 5 0f2326c2a325
equal deleted inserted replaced
-1:000000000000 0:1450b09d0cfd
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "WebNetworkConnectionManager.h"
       
    20 
       
    21 namespace WRT {
       
    22 
       
    23 WebNetworkConnectionManager::WebNetworkConnectionManager(QObject *parent)
       
    24     : QObject(parent), m_WebNetworkSession(0)
       
    25 { 
       
    26     connect(&m_NetworkConfigurationManager, SIGNAL(updateCompleted()), 
       
    27             this, SLOT(configurationUpdateCompleted()));
       
    28     connect(&m_NetworkConfigurationManager, SIGNAL(configurationAdded(const QNetworkConfiguration&)),
       
    29             this, SLOT(configurationAdded(const QNetworkConfiguration&)));
       
    30     connect(&m_NetworkConfigurationManager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)),
       
    31             this, SLOT(configurationRemoved(const QNetworkConfiguration&)));
       
    32     connect(&m_NetworkConfigurationManager, SIGNAL(onlineStateChanged(bool)), 
       
    33             this, SLOT(onlineStateChanged(bool)));
       
    34     connect(&m_NetworkConfigurationManager, SIGNAL(configurationChanged(const QNetworkConfiguration&)),
       
    35             this, SLOT(configurationChanged(const QNetworkConfiguration&)));
       
    36     	      
       
    37     updateConfigurations();
       
    38 }
       
    39 
       
    40 WebNetworkConnectionManager::~WebNetworkConnectionManager()
       
    41 {
       
    42     if (m_WebNetworkSession)
       
    43         deleteSession();
       
    44 }
       
    45 
       
    46 void WebNetworkConnectionManager::updateConfigurations()
       
    47 {
       
    48     m_NetworkConfigurationManager.updateConfigurations();
       
    49 }
       
    50 
       
    51 QNetworkConfiguration WebNetworkConnectionManager::defaultConfiguration() const
       
    52 {
       
    53     const bool canStartIAP = (m_NetworkConfigurationManager.capabilities() 
       
    54                               & QNetworkConfigurationManager::CanStartAndStopInterfaces);
       
    55     QNetworkConfiguration config = m_NetworkConfigurationManager.defaultConfiguration();
       
    56     if (!config.isValid() || !canStartIAP)
       
    57         return config;
       
    58         
       
    59     switch(config.type()) {
       
    60         case QNetworkConfiguration::InternetAccessPoint:
       
    61             // no user interaction -> system starts IAP immediately
       
    62             qDebug() << "IAP";
       
    63             break;
       
    64         case QNetworkConfiguration::ServiceNetwork:
       
    65             // no user interaction -> system determines best IAP in group and starts it
       
    66             qDebug() << "SNAP";
       
    67             break;
       
    68         case QNetworkConfiguration::UserChoice:
       
    69             // IAP resolved by asking user as part of QNetworkSession::open()
       
    70             qDebug() << "User Choice";
       
    71             break;
       
    72     }
       
    73     
       
    74     return config;
       
    75 }
       
    76 
       
    77 void WebNetworkConnectionManager::createSession(QNetworkConfiguration config)
       
    78 {   
       
    79     m_WebNetworkSession = new WebNetworkSession(config);
       
    80 }
       
    81 
       
    82 void WebNetworkConnectionManager::deleteSession(void)
       
    83 {   
       
    84     delete m_WebNetworkSession;
       
    85 }
       
    86 
       
    87 void WebNetworkConnectionManager::configurationUpdateCompleted()
       
    88 {
       
    89 	  qDebug() << "configurationUpdateCompleted: create new network connection session";
       
    90 	  if (m_WebNetworkSession)
       
    91 	  {
       
    92 	  	  qDebug() << "Delete old network connection session";
       
    93 	  	  deleteSession();
       
    94 	  }
       
    95 	  
       
    96     createSession(defaultConfiguration());
       
    97 }
       
    98 
       
    99 void WebNetworkConnectionManager::configurationAdded(const QNetworkConfiguration& config)
       
   100 {
       
   101     qDebug() << "Configuration" << config.name() << "Added";    
       
   102 }
       
   103 
       
   104 void WebNetworkConnectionManager::configurationRemoved(const QNetworkConfiguration& config)
       
   105 {
       
   106     qDebug() << "Configuration" << config.name() << "Removed";
       
   107 }
       
   108 
       
   109 void WebNetworkConnectionManager::onlineStateChanged(bool isOnline)
       
   110 {
       
   111     if (!isOnline)
       
   112     {
       
   113         qDebug() << "offline";
       
   114     }
       
   115     else
       
   116     {
       
   117         qDebug() << "online";
       
   118     }
       
   119     // flash icon to indicate the online state change with "online" and "offline".
       
   120 }
       
   121 
       
   122 void WebNetworkConnectionManager::configurationChanged(const QNetworkConfiguration &config)
       
   123 {
       
   124     qDebug() << "Configuration" << config.name() << "Changed";  
       
   125 }
       
   126 }