phoneplugins/infowidgetplugin/infowidget/src/infowidgetnetworkhandler.cpp
branchRCL_3
changeset 61 41a7f70b3818
equal deleted inserted replaced
58:40a3f856b14d 61:41a7f70b3818
       
     1 /*
       
     2  * Copyright (c) 2009 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 #include <networkhandlingproxy.h>
       
    19 #include <cnwsession.h>
       
    20 #include <xqsettingsmanager.h>
       
    21 #include <xqsettingskey.h>
       
    22 #include <settingsinternalcrkeys.h>
       
    23 #include "infowidgetnetworkhandler.h"
       
    24 #include "infowidgetlogging.h"
       
    25 
       
    26 /*!
       
    27   \class InfoWidgetNetworkHandler
       
    28   \brief Handles network specific functionality of 
       
    29          Operator info widget
       
    30 */
       
    31 
       
    32 // Local constants 
       
    33 const int KMcnValueOff = 0;  
       
    34 const int KMcnValueOn = 1; 
       
    35 
       
    36 /*!
       
    37     InfoWidgetNetworkHandler::InfoWidgetNetworkHandler()
       
    38 */
       
    39 InfoWidgetNetworkHandler::InfoWidgetNetworkHandler(QObject *parent) 
       
    40     :QObject(parent), 
       
    41     m_nwSession(NULL) 
       
    42 {
       
    43     DPRINT;
       
    44     if (!createSession()) {
       
    45         DCRITICAL << ": session creation failed!"; 
       
    46     } 
       
    47 }
       
    48 
       
    49 /*!
       
    50     InfoWidgetNetworkHandler::~InfoWidgetNetworkHandler()
       
    51 */
       
    52 InfoWidgetNetworkHandler::~InfoWidgetNetworkHandler()
       
    53 {
       
    54     DPRINT;
       
    55     try {
       
    56         // Disable MCN setting, 
       
    57         // display client is being deleted
       
    58         disableMcn(); 
       
    59     } catch (const std::exception& ex) {
       
    60         DCRITICAL << ": exception detected: " << ex.what();  
       
    61     }      
       
    62      
       
    63 }    
       
    64 
       
    65 /*!
       
    66     InfoWidgetNetworkHandler::createSession()
       
    67 */
       
    68 bool InfoWidgetNetworkHandler::createSession()
       
    69 {
       
    70     DPRINT;
       
    71     bool success(false);
       
    72     if (!m_nwSession) {
       
    73         QT_TRAP_THROWING(m_nwSession.reset(
       
    74                 CreateL(*this, m_nwInfo)));
       
    75         if (m_nwSession) {
       
    76             DPRINT << ": session created"; 
       
    77             success = true;
       
    78         }
       
    79     } else {
       
    80         DWARNING << ": session already created!"; 
       
    81     }
       
    82     
       
    83     return success; 
       
    84 }
       
    85 
       
    86 /*!
       
    87     InfoWidgetNetworkHandler::suspend()
       
    88 */
       
    89 void InfoWidgetNetworkHandler::suspend()
       
    90 {
       
    91     DPRINT;
       
    92 }
       
    93 
       
    94 /*!
       
    95     InfoWidgetNetworkHandler::resume()
       
    96 */
       
    97 void InfoWidgetNetworkHandler::resume()
       
    98 {
       
    99     DPRINT;
       
   100 }
       
   101 
       
   102 /*!
       
   103     InfoWidgetNetworkHandler::serviceProviderName()
       
   104 */
       
   105 QString InfoWidgetNetworkHandler::serviceProviderName() const 
       
   106 {
       
   107     QString qBuf;
       
   108     qBuf = QString((QChar*)m_nwInfo.iSPName.Ptr(), 
       
   109         m_nwInfo.iSPName.Length());
       
   110     DPRINT << ": serviceProviderName: " << qBuf;
       
   111     
       
   112     return qBuf; 
       
   113 }
       
   114 
       
   115 /*!
       
   116     InfoWidgetNetworkHandler::serviceProviderNameDisplayRequired()
       
   117 */
       
   118 bool InfoWidgetNetworkHandler::serviceProviderNameDisplayRequired() const 
       
   119 {
       
   120     bool displayRequired(true); 
       
   121     if (m_nwInfo.iServiceProviderNameDisplayReq == 
       
   122             RMobilePhone::KDisplaySPNNotRequired) {
       
   123         displayRequired = false; 
       
   124     } 
       
   125     return displayRequired; 
       
   126 }
       
   127 
       
   128 /*!
       
   129     InfoWidgetNetworkHandler::homeZoneTextTag()
       
   130 */
       
   131 QString InfoWidgetNetworkHandler::homeZoneTextTag() const 
       
   132 {
       
   133     QString qBuf;
       
   134     qBuf = QString((QChar*)m_nwInfo.iViagTextTag.Ptr(), 
       
   135         m_nwInfo.iViagTextTag.Length());
       
   136     return qBuf; 
       
   137 }
       
   138 
       
   139 /*!
       
   140     InfoWidgetNetworkHandler::homeZoneIndicatorType()
       
   141 */
       
   142 int InfoWidgetNetworkHandler::homeZoneIndicatorType() const 
       
   143 {
       
   144     int indicatorType = m_nwInfo.iViagIndicatorType;
       
   145     return indicatorType; 
       
   146 }
       
   147 
       
   148 /*!
       
   149     InfoWidgetNetworkHandler::enableMcn()
       
   150 */
       
   151 void InfoWidgetNetworkHandler::enableMcn() 
       
   152 {
       
   153     DPRINT;
       
   154     if (!readMcnDisplayState()) {
       
   155         DPRINT << ": enabling mcn display cenrep";
       
   156         writeMcnDisplayState(true); 
       
   157     }
       
   158 }
       
   159 
       
   160 /*!
       
   161     InfoWidgetNetworkHandler::disableMcn()
       
   162 */
       
   163 void InfoWidgetNetworkHandler::disableMcn()
       
   164 {
       
   165     DPRINT;
       
   166     if (readMcnDisplayState()) {
       
   167         DPRINT << ": disabling mcn display cenrep";
       
   168         writeMcnDisplayState(false); 
       
   169     }
       
   170 }
       
   171 
       
   172 /*!
       
   173     InfoWidgetNetworkHandler::mcnName()
       
   174 */
       
   175 QString InfoWidgetNetworkHandler::mcnName() const 
       
   176 {
       
   177     QString qBuf;
       
   178     qBuf = QString((QChar*)m_nwInfo.iMCNName.Ptr(),
       
   179         m_nwInfo.iMCNName.Length());
       
   180     DPRINT << ": mcnName: " << qBuf;
       
   181     return qBuf; 
       
   182 }
       
   183 
       
   184 /*!
       
   185     InfoWidgetNetworkHandler::mcnIndicatorType()
       
   186 */
       
   187 int InfoWidgetNetworkHandler::mcnIndicatorType() const 
       
   188 {
       
   189     DPRINT << ": mcnIndicatorType: " << m_nwInfo.iMCNIndicatorType;
       
   190     return m_nwInfo.iMCNIndicatorType;  
       
   191 }
       
   192 
       
   193 /*!
       
   194     InfoWidgetNetworkHandler::networkRegistrationStatus()
       
   195 */
       
   196 int InfoWidgetNetworkHandler::networkRegistrationStatus() const 
       
   197 {
       
   198     DPRINT << ": networkRegistrationStatus: " 
       
   199             << static_cast<int>(m_nwInfo.iRegistrationStatus);
       
   200     return static_cast<int>(m_nwInfo.iRegistrationStatus); 
       
   201 }
       
   202 
       
   203 /*!
       
   204     InfoWidgetNetworkHandler::isOnline()
       
   205     
       
   206     Check if network registration status is registered and 
       
   207     return status accordingly 
       
   208 */
       
   209 bool InfoWidgetNetworkHandler::isOnline() const
       
   210 {
       
   211     bool online(false); 
       
   212 
       
   213     if (!m_nwSession.isNull()) {
       
   214         switch (networkRegistrationStatus()) {
       
   215             case ENWRegisteredBusy: // Fall through
       
   216             case ENWRegisteredOnHomeNetwork: // Fall through
       
   217             case ENWRegisteredRoaming: 
       
   218                 online = true;
       
   219                 break; 
       
   220             default: 
       
   221                 break; 
       
   222         }
       
   223     }
       
   224     DPRINT << ": online: " << online;
       
   225     return online; 
       
   226 }
       
   227 
       
   228 /*!
       
   229     InfoWidgetNetworkHandler::HandleNetworkMessage()
       
   230     
       
   231     Implementation for MNWMessageObserver callback
       
   232     function 
       
   233 */
       
   234 void InfoWidgetNetworkHandler::HandleNetworkMessage( 
       
   235     const TNWMessages aMessage )
       
   236 {   
       
   237     DPRINT << ": message: " << aMessage;
       
   238     
       
   239     bool acceptedMessage = false;
       
   240     switch (aMessage) {
       
   241         case ENWMessageCurrentCellInfoMessage: // Fall through 
       
   242         case ENWMessageServiceProviderNameChange: // Fall through
       
   243         case ENWMessageNetworkRegistrationStatusChange: // Fall through
       
   244             acceptedMessage = true;
       
   245             break;
       
   246         default:
       
   247             // not interesting message, filter out
       
   248             DPRINT << ": message filtered out";
       
   249             acceptedMessage = false;
       
   250     }
       
   251     
       
   252     if (acceptedMessage) {
       
   253         int result = 0;
       
   254         QT_TRYCATCH_ERROR(result, emit networkDataChanged());
       
   255         if (0 != result) {
       
   256             DPRINT << ": Exception occured while emitting signal:" << result;
       
   257         }
       
   258     }
       
   259 }
       
   260 
       
   261 /*!
       
   262     InfoWidgetNetworkHandler::HandleNetworkError()
       
   263     
       
   264     Implementation for MNWMessageObserver callback
       
   265     function 
       
   266 */
       
   267 void InfoWidgetNetworkHandler::HandleNetworkError( 
       
   268     const TNWOperation aOperation, 
       
   269     TInt aErrorCode )
       
   270 {
       
   271     DPRINT << ": operation: " << aOperation <<  
       
   272         " error code: " << aErrorCode;
       
   273     
       
   274     // Reset invalid data  
       
   275     switch (aOperation) {
       
   276         case MNWMessageObserver::ENWGetServiceProviderName:
       
   277             m_nwInfo.iServiceProviderNameDisplayReq = 
       
   278                     RMobilePhone::KDisplaySPNNotRequired;
       
   279             m_nwInfo.iSPName.Zero();
       
   280         break;
       
   281         default: 
       
   282             break; 
       
   283     }
       
   284     
       
   285     // Emit error signal 
       
   286     int result = 0;
       
   287     QT_TRYCATCH_ERROR(result, emit networkError( 
       
   288         static_cast<int>(aOperation), static_cast<int>(aErrorCode)));
       
   289     if (0 != result) {
       
   290         DPRINT << ": Exception occured while emitting signal:" << result;
       
   291     }
       
   292 }
       
   293 
       
   294 /*!
       
   295     Write Mcn cenrep key.   
       
   296 */
       
   297 void InfoWidgetNetworkHandler::writeMcnDisplayState(bool enabled)
       
   298 {
       
   299     QScopedPointer<XQSettingsManager> settingsManager(new XQSettingsManager); 
       
   300     XQSettingsKey settingsKey(XQSettingsKey::TargetCentralRepository, 
       
   301         KCRUidNetworkSettings.iUid, KSettingsMcnDisplay);
       
   302     int value; 
       
   303     if (enabled) {
       
   304         value = KMcnValueOn; 
       
   305     } else {
       
   306         value = KMcnValueOff; 
       
   307     }
       
   308 
       
   309     bool result = settingsManager->writeItemValue(settingsKey, value);
       
   310     DPRINT << ": write success: " << result << " mcn enabled: " << enabled;
       
   311      
       
   312 }
       
   313 
       
   314 /*!
       
   315     Read Mcn cenrep key.
       
   316 */
       
   317 bool InfoWidgetNetworkHandler::readMcnDisplayState()
       
   318 {
       
   319     QScopedPointer<XQSettingsManager> settingsManager(new XQSettingsManager); 
       
   320     XQSettingsKey settingsKey(XQSettingsKey::TargetCentralRepository, 
       
   321         KCRUidNetworkSettings.iUid, KSettingsMcnDisplay); 
       
   322     bool success(false); 
       
   323     int value = settingsManager->readItemValue(
       
   324             settingsKey,
       
   325             XQSettingsManager::TypeInt).toInt(&success);
       
   326 
       
   327     bool mcnEnabled(false); 
       
   328     if (success && value == KMcnValueOn) {
       
   329         mcnEnabled = true; 
       
   330     }
       
   331         
       
   332     DPRINT << ": read success: " << success << " mcn enabled: " << mcnEnabled;
       
   333     return mcnEnabled; 
       
   334 }
       
   335 
       
   336 
       
   337 // End of File.