browsercore/core/network/WebNetworkConnectionManager.cpp
changeset 6 1c3b8676e58c
parent 5 0f2326c2a325
child 10 232fbd5a2dcb
equal deleted inserted replaced
5:0f2326c2a325 6:1c3b8676e58c
    25 
    25 
    26 /*!
    26 /*!
    27     Constructs a WebNetworkConfigurationManager with the given \a parent.
    27     Constructs a WebNetworkConfigurationManager with the given \a parent.
    28 */
    28 */
    29 WebNetworkConnectionManager::WebNetworkConnectionManager(QObject *parent)
    29 WebNetworkConnectionManager::WebNetworkConnectionManager(QObject *parent)
    30     : QObject(parent), m_WebNetworkSession(0)
    30     : QObject(parent), m_WebNetworkSession(0), m_offlined(false)
    31 { 
    31 { 
    32     // set up handlers for Network Configuration Manager signals
    32     // set up handlers for Network Configuration Manager signals
    33     connect(&m_NetworkConfigurationManager, SIGNAL(updateCompleted()), 
    33     connect(&m_NetworkConfigurationManager, SIGNAL(updateCompleted()), 
    34             this, SLOT(handleConfigurationUpdateCompleted()));
    34             this, SLOT(handleConfigurationUpdateCompleted()));
    35     connect(&m_NetworkConfigurationManager, SIGNAL(configurationAdded(const QNetworkConfiguration&)),
    35     connect(&m_NetworkConfigurationManager, SIGNAL(configurationAdded(const QNetworkConfiguration&)),
   115     m_WebNetworkSession = new WebNetworkSession(config);
   115     m_WebNetworkSession = new WebNetworkSession(config);
   116 
   116 
   117     // set up handlers for the WebNetworkSession signals
   117     // set up handlers for the WebNetworkSession signals
   118     connect(m_WebNetworkSession, SIGNAL(sessionConfigurationChanged(const QNetworkConfiguration &)),
   118     connect(m_WebNetworkSession, SIGNAL(sessionConfigurationChanged(const QNetworkConfiguration &)),
   119             this, SLOT(handleSessionConfigurationChanged(const QNetworkConfiguration &)));
   119             this, SLOT(handleSessionConfigurationChanged(const QNetworkConfiguration &)));
   120     connect(m_WebNetworkSession, SIGNAL(sessionStateChanged(const QNetworkConfiguration &, QNetworkSession::State)),
       
   121             this, SLOT(handleSessionStateChanged(const QNetworkConfiguration &, QNetworkSession::State))); 
       
   122 }
   120 }
   123 
   121 
   124 /*! 
   122 /*! 
   125     Delete a Web Network Session.
   123     Delete a Web Network Session.
   126     
   124     
   127 */
   125 */
   128 void WebNetworkConnectionManager::deleteSession(void)
   126 void WebNetworkConnectionManager::deleteSession(void)
   129 {   
   127 {   
   130     delete m_WebNetworkSession;
   128     delete m_WebNetworkSession;
       
   129     m_WebNetworkSession = 0;
   131 }
   130 }
   132 
   131 
   133 /*!
   132 /*!
   134     Handle the updateCompleted signal from Network Configuration Manager.
   133     Handle the updateCompleted signal from Network Configuration Manager.
   135     
   134     
   162 {
   161 {
   163     qDebug() << "Configuration" << config.name() << "Removed";
   162     qDebug() << "Configuration" << config.name() << "Removed";
   164 }
   163 }
   165 
   164 
   166 /*! 
   165 /*! 
   167     Handle the conlineStateChanged signal from Network Configuration Manager.
   166     Handle the onlineStateChanged signal from Network Configuration Manager.
   168 */
   167 */
   169 void WebNetworkConnectionManager::handleOnlineStateChanged(bool isOnline)
   168 void WebNetworkConnectionManager::handleOnlineStateChanged(bool isOnline)
   170 {
   169 {
       
   170     emit networkOnlineStateChanged(isOnline);
       
   171     
   171     if (!isOnline)
   172     if (!isOnline)
   172     {
   173     {
   173         qDebug() << "offline";
   174         qDebug() << "offline";
       
   175         m_offlined = true;
   174     }
   176     }
   175     else
   177     else
   176     {
   178     {
   177         qDebug() << "online";
   179         qDebug() << "online";
       
   180         m_offlined = false;
   178     }
   181     }
   179     // flash icon to indicate the online state change with "online" and "offline".
   182     // flash icon to indicate the online state change with "online" and "offline".
   180 }
   183 }
   181 
   184 
   182 /*! 
   185 /*! 
   183     Handle the configurationChanged signal from Network Configuration Manager.
   186     Handle the configurationChanged signal from Network Configuration Manager.
   184 */
   187 */
   185 void WebNetworkConnectionManager::handleConfigurationChanged(const QNetworkConfiguration &config)
   188 void WebNetworkConnectionManager::handleConfigurationChanged(const QNetworkConfiguration &config)
   186 {
   189 {
   187     qDebug() << "Configuration" << config.name() << "Changed";  
   190     qDebug() << "Configuration" << config.name() << "Changed";
   188 }
   191     qDebug() << "bearername:" << config.bearerName() << "type:" << config.type() << "state:" << config.state() << "purpose:" << config.purpose();
       
   192     
       
   193     /* The QNetworkSession is closed becuase of previous offline condition. Re-open the session if 
       
   194        the configuration matches the configurations hold by the QNetworkSession */
       
   195 #ifdef NO_OFFLINED_BUG
       
   196     if (isOfflined())
       
   197     {
       
   198 #endif // NO_OFFLINED_BUG
       
   199         if (m_WebNetworkSession && !m_WebNetworkSession->isOpen())
       
   200         {
       
   201             QNetworkConfiguration sessionConfig = m_WebNetworkSession->configuration();
       
   202             QList<QNetworkConfiguration> children = sessionConfig.children();
       
   203         	  switch(sessionConfig.type())
       
   204             {
       
   205                 case QNetworkConfiguration::ServiceNetwork:        
       
   206                     /* Traverse all configuration to find the matching configuration */
       
   207                     foreach(QNetworkConfiguration tmpConfig, children)
       
   208                     {
       
   209         	              if (config == tmpConfig)
       
   210         	              {
       
   211         	              	  if ((config.state() == QNetworkConfiguration::Discovered) ||
       
   212         	              	  	   (config.state() == QNetworkConfiguration::Active))
       
   213         	                      m_WebNetworkSession->open();
       
   214             	              break;
       
   215             	          }
       
   216             	      }
       
   217                     break;  
       
   218                case QNetworkConfiguration::InternetAccessPoint:
       
   219         	          qDebug() << "InternetAccessPoint";
       
   220                     break;
       
   221                case QNetworkConfiguration::UserChoice:
       
   222         	          qDebug() << "UserChoice";
       
   223         	          break;
       
   224                default:
       
   225         	         break;
       
   226             } 	  
       
   227         }
       
   228 #ifdef NO_OFFLINED_BUG
       
   229     }
       
   230 #endif // NO_OFFLINED_BUG
       
   231 } 
   189 
   232 
   190 /*! 
   233 /*! 
   191     Handle the networkNameChanged signal from Network Configuration Manager and translate 
   234     Handle the networkNameChanged signal from Network Configuration Manager and translate 
   192     sessionConfiguration signal to networknameChanged.
   235     sessionConfiguration signal to networknameChanged.
   193     
   236     
   194     It a\ emits networkNameChanged signal for no cellular network connetion.
   237     It a\ emits networkNameChanged signal for no cellular network connetion.
   195 */
   238 */
   196 void WebNetworkConnectionManager::handleSessionConfigurationChanged(const QNetworkConfiguration &config)
   239 void WebNetworkConnectionManager::handleSessionConfigurationChanged(const QNetworkConfiguration &config)
   197 {  
   240 {  
   198     qDebug() << "handleSessionConfigurationChanged" << "bearname:" << config.bearerName();
   241     qDebug() << "handleSessionConfigurationChanged" << "bearername:" << config.bearerName();
   199 
   242 
   200 #ifdef QT_MOBILITY_SYSINFO  
   243 #ifdef QT_MOBILITY_SYSINFO  
   201     QSystemNetworkInfo::NetworkMode mode;
   244     QSystemNetworkInfo::NetworkMode mode;
   202     mode = m_mapStringNetworkMode[config.bearerName()];
   245     mode = m_mapStringNetworkMode[config.bearerName()];
   203     switch(mode)
   246 
   204     {
   247     emit networkSessionNameChanged(mode, config.name());
   205     	  case QSystemNetworkInfo::EthernetMode:
       
   206     	  case QSystemNetworkInfo::WlanMode:
       
   207     	  case QSystemNetworkInfo::BluetoothMode:
       
   208     	  case QSystemNetworkInfo::WimaxMode:
       
   209             emit networkNameChanged(mode, config.name());
       
   210             break;
       
   211         case QSystemNetworkInfo::GsmMode:
       
   212         case QSystemNetworkInfo::CdmaMode:
       
   213         case QSystemNetworkInfo::WcdmaMode:
       
   214         	  break;
       
   215         case QSystemNetworkInfo::UnknownMode:
       
   216         default:
       
   217         	  emit networkNameChanged(mode, config.name());
       
   218         	  break;
       
   219     }
       
   220 #endif // QT_MOBILITY_SYSINFO
       
   221 }
       
   222 
       
   223 /*! 
       
   224     Handle the networkSignalStrengthChanged from Network Configuration Manager and
       
   225     translate sessionStateChanged to networkSignalStrengthChanged.
       
   226     
       
   227     It a\ emits networkSignalStrengthChanged for non cellular network connection.
       
   228 */
       
   229 void WebNetworkConnectionManager::handleSessionStateChanged(const QNetworkConfiguration &config, 
       
   230 	       QNetworkSession::State state)
       
   231 {
       
   232 	  int strength = 0;
       
   233 	  
       
   234 	  qDebug() << "handleSessionStateChanged" << "bearname:" << config.bearerName();
       
   235 	  
       
   236 	  switch(state)
       
   237 	  {
       
   238 	      case QNetworkSession::Connecting:
       
   239 	      case QNetworkSession::Connected:
       
   240 	      case QNetworkSession::Roaming:
       
   241 	      	  strength = 100;
       
   242 	      	  break;
       
   243 	      default:
       
   244 	       	  break;
       
   245 	  }
       
   246 
       
   247 #ifdef QT_MOBILITY_SYSINFO
       
   248     QSystemNetworkInfo::NetworkMode mode;
       
   249 	  mode = m_mapStringNetworkMode[config.bearerName()];
       
   250     switch(mode)
       
   251     {
       
   252     	  case QSystemNetworkInfo::EthernetMode:
       
   253     	  case QSystemNetworkInfo::WlanMode:
       
   254         case QSystemNetworkInfo::BluetoothMode:
       
   255     	  case QSystemNetworkInfo::WimaxMode:
       
   256     	  	  emit networkSignalStrengthChanged(mode, strength);
       
   257             break;
       
   258         case QSystemNetworkInfo::GsmMode:
       
   259         case QSystemNetworkInfo::CdmaMode:
       
   260         case QSystemNetworkInfo::WcdmaMode:
       
   261         	  break;
       
   262         case QSystemNetworkInfo::UnknownMode:
       
   263         default:
       
   264         	  emit networkSignalStrengthChanged(mode, strength);
       
   265         	  break;
       
   266     }
       
   267 #endif // QT_MOBILITY_SYSINFO
   248 #endif // QT_MOBILITY_SYSINFO
   268 }
   249 }
   269 
   250 
   270 #ifdef QT_MOBILITY_SYSINFO
   251 #ifdef QT_MOBILITY_SYSINFO
   271 void WebNetworkConnectionManager::initializeMapString(void)
   252 void WebNetworkConnectionManager::initializeMapString(void)
   281 	  m_mapStringNetworkMode[""] = QSystemNetworkInfo::UnknownMode;
   262 	  m_mapStringNetworkMode[""] = QSystemNetworkInfo::UnknownMode;
   282 }
   263 }
   283 #endif // QT_MOBILITY_SYSINFO
   264 #endif // QT_MOBILITY_SYSINFO
   284 
   265 
   285 } // WRT
   266 } // WRT
       
   267