cellular/telephonysettings/xqbindings/psetwrapper/src/psetnetworkwrapper_p.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     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 <rmmcustomapi.h>
       
    19 #include <psetcontainer.h>
       
    20 #include <psetnetwork.h>
       
    21 #include <gsmerror.h>
       
    22 #include <PsetCSP.h>
       
    23 
       
    24 #include "psetnetworkwrapper_p.h"
       
    25 #include "logging.h"
       
    26 #include "psetnetworkinfoconverter.h"
       
    27 
       
    28 /*!
       
    29     \class PSetNetworkWrapperPrivate
       
    30     \brief Private implementation for network wrapper.
       
    31 */
       
    32 
       
    33 /*!
       
    34   PSetNetworkWrapperPrivate::PSetNetworkWrapperPrivate
       
    35  */
       
    36 PSetNetworkWrapperPrivate::PSetNetworkWrapperPrivate(
       
    37     PSetNetworkWrapper &owner,
       
    38     CPsetContainer &psetContainer)
       
    39     :
       
    40     m_owner(owner),
       
    41     m_psetNetwork(NULL),
       
    42     m_psetNetworkMode(NULL)
       
    43 {
       
    44     DPRINT << ": IN ";
       
    45     
       
    46     QT_TRAP_THROWING(
       
    47         m_psetNetwork.reset(psetContainer.CreateNetworkObjectL(*this)));
       
    48     m_psetNetwork->SetNetworkModeObserver(*this);
       
    49     m_psetNetwork->SetNetSAObserver(*this);
       
    50     QT_TRAP_THROWING(
       
    51         m_psetNetworkMode.reset(psetContainer.CreateNetworkModeObjectL(*this)));
       
    52     QT_TRAP_THROWING(
       
    53         m_refreshHandler.reset(psetContainer.CreateRefreshHandlerL()));
       
    54     QT_TRAP_THROWING(m_refreshHandler->NotifyFileChangeL(
       
    55                 *this,
       
    56                 KCsp1Ef,
       
    57                 EFileChangeNotification));
       
    58     
       
    59     QT_TRAP_THROWING(m_csp.reset(CPsetCustomerServiceProfile::NewL()));
       
    60     QT_TRAP_THROWING(m_csp->OpenCSProfileL());
       
    61 
       
    62     DPRINT << ": OUT ";
       
    63 }
       
    64 
       
    65 /*!
       
    66   PSetNetworkWrapperPrivate::~PSetNetworkWrapperPrivate
       
    67  */
       
    68 PSetNetworkWrapperPrivate::~PSetNetworkWrapperPrivate()
       
    69 {
       
    70     DPRINT << ": IN ";
       
    71     
       
    72     while (!m_networkInfoList.isEmpty()) {
       
    73         DPRINT << " delete : " << m_networkInfoList.first()->m_longName;
       
    74         delete m_networkInfoList.takeFirst();
       
    75     }
       
    76     m_networkInfoList.clear();
       
    77     
       
    78     DPRINT << ": OUT ";
       
    79 }
       
    80 
       
    81 /*!
       
    82     PSetNetworkWrapperPrivate::getAvailableNetworks.
       
    83 */
       
    84 void PSetNetworkWrapperPrivate::getAvailableNetworks()
       
    85 {
       
    86     DPRINT << ": IN ";
       
    87     
       
    88     QT_TRAP_THROWING(m_psetNetwork->GetAvailableNetworksL());
       
    89     
       
    90     DPRINT << ": OUT ";
       
    91 }
       
    92 
       
    93 /*!
       
    94     PSetNetworkWrapperPrivate::getNetworkSelectionMode
       
    95 */
       
    96 PSetNetworkWrapper::ErrorCode 
       
    97     PSetNetworkWrapperPrivate::getNetworkSelectionMode(
       
    98     PSetNetworkWrapper::NetworkSelectionMode& mode) const
       
    99 {
       
   100     DPRINT;
       
   101     
       
   102     MPsetNetworkSelect::TSelectMode selectMode = 
       
   103         MPsetNetworkSelect::ENetSelectModeAutomatic;
       
   104     int result = m_psetNetwork->GetNetworkSelectMode(selectMode);
       
   105     mode = NetworkInfoConverter::ConvertToQtType(selectMode);
       
   106     
       
   107     return ConvertToQtErrorCode(result);
       
   108 }
       
   109 
       
   110 /*!
       
   111     PSetNetworkWrapperPrivate::selectNetwork.
       
   112  */
       
   113 void PSetNetworkWrapperPrivate::selectNetwork( 
       
   114     const PSetNetworkWrapper::NetworkInfo& info)
       
   115 {
       
   116     DPRINT << ": IN ";
       
   117     
       
   118     QT_TRAP_THROWING(m_psetNetwork->SelectNetworkL(
       
   119         NetworkInfoConverter::ConvertToSymbianType(info)));
       
   120          
       
   121     DPRINT << ": OUT ";
       
   122 }
       
   123 
       
   124 /*!
       
   125     PSetNetworkWrapperPrivate::cancelRequest
       
   126 */
       
   127 void PSetNetworkWrapperPrivate::cancelRequest()
       
   128 {
       
   129     DPRINT;
       
   130     
       
   131     m_psetNetwork->CancelProcess();
       
   132 }
       
   133 
       
   134 /*!
       
   135     PSetNetworkWrapperPrivate::getNetworkAccessMode
       
   136 */
       
   137 void PSetNetworkWrapperPrivate::getNetworkAccessMode() const
       
   138 {
       
   139     DPRINT << ": IN ";
       
   140     
       
   141     QT_TRAP_THROWING(
       
   142         m_psetNetwork->GetCurrentNetworkModeSelectionL());
       
   143         
       
   144     DPRINT << ": OUT ";
       
   145 }
       
   146 
       
   147 /*!
       
   148     PSetNetworkWrapperPrivate::setNetworkAccessMode
       
   149 */
       
   150 void PSetNetworkWrapperPrivate::setNetworkAccessMode(
       
   151     PSetNetworkWrapper::NetworkAccessMode mode)
       
   152 {
       
   153     DPRINT << ": IN ";
       
   154     
       
   155     RMmCustomAPI::TNetworkModeCaps modeCaps = 
       
   156         RMmCustomAPI::KCapsNetworkModeDual;
       
   157     switch (mode) {
       
   158         case PSetNetworkWrapper::AccessModeDual:
       
   159             modeCaps = RMmCustomAPI::KCapsNetworkModeDual;
       
   160             break;
       
   161         case PSetNetworkWrapper::AccessModeUmts:
       
   162             modeCaps = RMmCustomAPI::KCapsNetworkModeUmts;
       
   163             break;
       
   164         case PSetNetworkWrapper::AccessModeGsm:
       
   165             modeCaps = RMmCustomAPI::KCapsNetworkModeGsm;
       
   166             break;
       
   167         default:
       
   168             Q_ASSERT_X(false, "switch default", "unknown enumerator");
       
   169     }
       
   170     
       
   171     QT_TRAP_THROWING(m_psetNetwork->SetNetworkModeSelectionL(
       
   172         reinterpret_cast<TUint32&>(modeCaps)));
       
   173         
       
   174     DPRINT << ": OUT ";
       
   175 }
       
   176 
       
   177 /*!
       
   178      From MPsetNetworkInfoObserver.
       
   179      \see MPsetNetworkInfoObserver.
       
   180 */
       
   181 void PSetNetworkWrapperPrivate::HandleNetworkInfoReceivedL( 
       
   182     const CNetworkInfoArray* aInfoArray, 
       
   183     const TInt aResult)
       
   184 {
       
   185     DPRINT << ": IN ";
       
   186     
       
   187     Q_UNUSED(aResult);
       
   188     __ASSERT_DEBUG(NULL != aInfoArray, User::Leave(KErrArgument));
       
   189     
       
   190     // delete qlist
       
   191     while (!m_networkInfoList.isEmpty()) {
       
   192         DPRINT << " delete : " << m_networkInfoList.first()->m_longName;
       
   193         delete m_networkInfoList.takeFirst();
       
   194     }
       
   195     m_networkInfoList.clear();
       
   196     
       
   197     const int itemsCount = aInfoArray->Count();
       
   198 
       
   199     //then insert found networks
       
   200     for(int i = 0; i < itemsCount; i++)
       
   201         {
       
   202         PSetNetworkWrapper::NetworkInfo *info = 
       
   203             new (ELeave) PSetNetworkWrapper::NetworkInfo;
       
   204         
       
   205         info->m_id.m_countryCode = QString::fromUtf16(
       
   206             aInfoArray->At(i).iId.iCountryCode.Ptr(), 
       
   207             aInfoArray->At(i).iId.iCountryCode.Length());
       
   208         info->m_id.m_networkCode =  QString::fromUtf16(
       
   209             aInfoArray->At(i).iId.iNetworkCode.Ptr(), 
       
   210             aInfoArray->At(i).iId.iNetworkCode.Length());
       
   211         info->m_status = 
       
   212             static_cast<PSetNetworkWrapper::NetworkStatus>(
       
   213                 aInfoArray->At(i).iStatus);
       
   214         info->m_mode = 
       
   215             static_cast<PSetNetworkWrapper::NetworkSelectionMode>(
       
   216                 aInfoArray->At(i).iMode);
       
   217         info->m_access = 
       
   218             static_cast<PSetNetworkWrapper::NetworkAccessType>(
       
   219                 aInfoArray->At(i).iAccess);
       
   220         info->m_shortName = 
       
   221             QString::fromUtf16(
       
   222                 aInfoArray->At(i).iShortName.Ptr(), 
       
   223                 aInfoArray->At(i).iShortName.Length());
       
   224         info->m_longName = 
       
   225             QString::fromUtf16(
       
   226                 aInfoArray->At(i).iLongName.Ptr(), 
       
   227                 aInfoArray->At(i).iLongName.Length());
       
   228         
       
   229         m_networkInfoList.append(info);
       
   230         }
       
   231     
       
   232     QT_TRYCATCH_LEAVING(
       
   233         emit m_owner.availableNetworksGot(m_networkInfoList);
       
   234     )
       
   235     
       
   236     DPRINT << ": OUT ";
       
   237 }
       
   238 
       
   239 /*!
       
   240      From MPsetNetworkInfoObserver.
       
   241      \see MPsetNetworkInfoObserver.
       
   242 */
       
   243 void PSetNetworkWrapperPrivate::HandleCurrentNetworkInfoL( 
       
   244     const MPsetNetworkSelect::TCurrentNetworkInfo& aCurrentInfo, 
       
   245     const TInt aResult)
       
   246 {
       
   247     DPRINT;
       
   248     
       
   249     Q_UNUSED(aCurrentInfo);
       
   250     Q_UNUSED(aResult);
       
   251 }
       
   252 
       
   253 /*!
       
   254      From MPsetNetworkInfoObserver.
       
   255      \see MPsetNetworkInfoObserver.
       
   256 */
       
   257 void PSetNetworkWrapperPrivate::HandleNetworkChangedL( 
       
   258     const MPsetNetworkSelect::TNetworkInfo& aCurrentInfo,
       
   259     const MPsetNetworkSelect::TCurrentNetworkStatus aStatus, 
       
   260     const TInt aResult)
       
   261 {
       
   262     DPRINT;
       
   263     
       
   264     Q_UNUSED(aCurrentInfo);
       
   265     Q_UNUSED(aStatus);
       
   266     Q_UNUSED(aResult);
       
   267 }
       
   268 
       
   269 /*!
       
   270      From MPsetNetworkInfoObserver.
       
   271      \see MPsetNetworkInfoObserver.
       
   272 */
       
   273 void PSetNetworkWrapperPrivate::HandleNetworkChangedL( 
       
   274     const MPsetNetworkSelect::TNetworkInfo& aCurrentInfo,
       
   275     const RMobilePhone::TMobilePhoneRegistrationStatus& aStatus, 
       
   276     const TInt aResult)
       
   277 {
       
   278     DPRINT << ": IN ";
       
   279     
       
   280     Q_UNUSED(aResult);
       
   281     
       
   282     PSetNetworkWrapper::NetworkInfo info;      
       
   283     info.m_id.m_countryCode =  QString::fromUtf16(
       
   284         aCurrentInfo.iId.iCountryCode.Ptr(), 
       
   285         aCurrentInfo.iId.iCountryCode.Length());
       
   286     info.m_id.m_networkCode =  QString::fromUtf16(
       
   287         aCurrentInfo.iId.iNetworkCode.Ptr(), 
       
   288         aCurrentInfo.iId.iNetworkCode.Length());
       
   289     info.m_status = 
       
   290         static_cast<PSetNetworkWrapper::NetworkStatus>(
       
   291             aCurrentInfo.iStatus);
       
   292     info.m_mode = 
       
   293         static_cast<PSetNetworkWrapper::NetworkSelectionMode>(
       
   294             aCurrentInfo.iMode);
       
   295     info.m_access = 
       
   296         static_cast<PSetNetworkWrapper::NetworkAccessType>(
       
   297             aCurrentInfo.iAccess);
       
   298     info.m_shortName = 
       
   299         QString::fromUtf16(
       
   300             aCurrentInfo.iShortName.Ptr(), 
       
   301             aCurrentInfo.iShortName.Length());
       
   302     info.m_longName = 
       
   303         QString::fromUtf16(
       
   304             aCurrentInfo.iLongName.Ptr(), 
       
   305             aCurrentInfo.iLongName.Length());
       
   306     
       
   307     PSetNetworkWrapper::RegistrationStatus status;
       
   308     switch (aStatus){
       
   309         case RMobilePhone::ERegisteredOnHomeNetwork:
       
   310             status = PSetNetworkWrapper::RegisteredOnHomeNetwork;
       
   311             break;
       
   312         case RMobilePhone::ERegisteredRoaming:
       
   313             status = PSetNetworkWrapper::RegisteredRoaming;
       
   314             break;
       
   315         }
       
   316    
       
   317     QT_TRYCATCH_LEAVING(
       
   318         emit m_owner.networkChanged(info, status);
       
   319     )
       
   320     
       
   321     DPRINT << ": OUT ";
       
   322 }
       
   323 
       
   324 /*!
       
   325      From MPsetNetworkInfoObserver.
       
   326      \see MPsetNetworkInfoObserver.
       
   327 */
       
   328 void PSetNetworkWrapperPrivate::HandleSearchingNetworksL( 
       
   329     MPsetNetworkInfoObserver::TServiceRequest aRequest)
       
   330 {
       
   331     DPRINT << ": IN ";
       
   332     
       
   333     PSetNetworkWrapper::RequestType type =
       
   334         static_cast<PSetNetworkWrapper::RequestType>(aRequest);
       
   335     QT_TRYCATCH_LEAVING(
       
   336         emit m_owner.searchingNetworks(type);
       
   337     )
       
   338     
       
   339     DPRINT << ": OUT ";
       
   340 }
       
   341 
       
   342 /*!
       
   343      From MPsetNetworkInfoObserver.
       
   344      \see MPsetNetworkInfoObserver.
       
   345 */
       
   346 void PSetNetworkWrapperPrivate::HandleRequestingSelectedNetworkL( 
       
   347     TBool aOngoing)
       
   348 {
       
   349     DPRINT << ": IN ";
       
   350     
       
   351     QT_TRYCATCH_LEAVING(
       
   352         emit m_owner.requestingSelectedNetwork(
       
   353             static_cast<bool>(aOngoing));
       
   354     )
       
   355     
       
   356     DPRINT << ": OUT ";
       
   357 }
       
   358 
       
   359 /*!
       
   360      From MPsetNetworkInfoObserver.
       
   361      \see MPsetNetworkInfoObserver.
       
   362 */
       
   363 void PSetNetworkWrapperPrivate::HandleCallActivatedL()
       
   364 {
       
   365     DPRINT;
       
   366 }
       
   367 
       
   368 /*!
       
   369      From MPsetNetworkInfoObserver.
       
   370      \see MPsetNetworkInfoObserver.
       
   371 */
       
   372 void PSetNetworkWrapperPrivate::HandleNetworkErrorL( 
       
   373     const MPsetNetworkInfoObserver::TServiceRequest aRequest,
       
   374     const TInt aError)
       
   375 {
       
   376     DPRINT << ": IN ";
       
   377     
       
   378     PSetNetworkWrapper::ErrorCode error;
       
   379     switch(aError) {
       
   380         case KErrGsmNetCauseCallActive:
       
   381             error = PSetNetworkWrapper::ErrCauseCallActive;
       
   382             break;
       
   383         case KErrGsm0707NoNetworkService:
       
   384             error = PSetNetworkWrapper::ErrNoNetworkService;
       
   385             break;
       
   386         case KErrGsmOfflineOpNotAllowed:
       
   387             error = PSetNetworkWrapper::ErrOfflineOpNotAllowed;
       
   388             break;
       
   389         default:
       
   390             error = PSetNetworkWrapper::ErrNoNetworkAccess;
       
   391             break;
       
   392     }
       
   393 
       
   394     QT_TRYCATCH_LEAVING(
       
   395         emit m_owner.networkReqestFailed(
       
   396             error, static_cast<PSetNetworkWrapper::RequestType>(aRequest));
       
   397     )
       
   398 }
       
   399 
       
   400 /*!
       
   401      From MPsetNetworkInfoObserver.
       
   402      \see MPsetNetworkInfoObserver.
       
   403 */
       
   404 void PSetNetworkWrapperPrivate::HandleNetworkSystemModeEventsL( 
       
   405     const MPsetNetworkModeObserver::TServiceRequest aRequest,
       
   406     const TUint32 aNetworkModeCaps)
       
   407 {
       
   408     DPRINT;
       
   409     
       
   410     switch (aRequest) {
       
   411         case MPsetNetworkModeObserver::EServiceRequestNone:
       
   412             // TODO: what to do with this kind of event
       
   413             break;
       
   414         case MPsetNetworkModeObserver::EServiceRequestSetSelectedNetworkMode:
       
   415             // TODO: implement this
       
   416             break;
       
   417         case MPsetNetworkModeObserver::EServiceRequestGetCurrentNetworkMode: {
       
   418             PSetNetworkWrapper::NetworkAccessMode mode =
       
   419                 PSetNetworkWrapper::AccessModeDual;
       
   420             if (aNetworkModeCaps & RMmCustomAPI::KCapsNetworkModeDual) {
       
   421                 mode = PSetNetworkWrapper::AccessModeDual;
       
   422             } else if 
       
   423                 (aNetworkModeCaps & RMmCustomAPI::KCapsNetworkModeUmts) {
       
   424                     mode = PSetNetworkWrapper::AccessModeUmts;
       
   425             } else if 
       
   426                 (aNetworkModeCaps & RMmCustomAPI::KCapsNetworkModeGsm) {
       
   427                     mode = PSetNetworkWrapper::AccessModeGsm;
       
   428             } else {
       
   429                 Q_ASSERT(false);
       
   430             }
       
   431             QT_TRYCATCH_LEAVING(
       
   432                 emit m_owner.networkAccessModeGot(static_cast<int>(mode));
       
   433             )
       
   434 
       
   435         }
       
   436             break;
       
   437         default:
       
   438             Q_ASSERT_X(false, "switch default", "unknown enumerator");
       
   439     }
       
   440 }
       
   441 
       
   442 /*!
       
   443      From MPsetNetworkInfoObserver.
       
   444      \see MPsetNetworkInfoObserver.
       
   445 */
       
   446 void PSetNetworkWrapperPrivate::HandleNetworkErrorL(
       
   447     const MPsetNetworkModeObserver::TServiceRequest aRequest,
       
   448     const TInt aError)
       
   449 {
       
   450     DPRINT;
       
   451     
       
   452     Q_UNUSED(aRequest);
       
   453     Q_UNUSED(aError);
       
   454 }
       
   455 
       
   456 /*!
       
   457      PSetNetworkWrapperPrivate::ConvertToQtErrorCode
       
   458 */
       
   459 PSetNetworkWrapper::ErrorCode PSetNetworkWrapperPrivate::ConvertToQtErrorCode(
       
   460     TInt symbianErrorCode) const
       
   461 {
       
   462     // TODO: do proper conversion for error codes
       
   463     if (KErrNone == symbianErrorCode) {
       
   464         return PSetNetworkWrapper::ErrNoError;
       
   465     } else {
       
   466         return PSetNetworkWrapper::ErrGeneral;
       
   467     }    
       
   468 }
       
   469 
       
   470 /*!
       
   471      PSetNetworkWrapperPrivate::isManualNetworkSelectionSupported
       
   472 */
       
   473 bool PSetNetworkWrapperPrivate::isManualNetworkSelectionSupported() const
       
   474 {
       
   475     DPRINT << ": IN ";
       
   476     
       
   477     TBool settingSupported(EFalse);
       
   478     TInt retVal = m_csp->IsNetworkSelectionSupported(settingSupported);
       
   479  
       
   480     if ( retVal != KErrNone )
       
   481          {
       
   482         //if a CSP error occurs, by default service is available
       
   483         settingSupported = ETrue;
       
   484         }
       
   485 
       
   486     DPRINT << ": OUT ";
       
   487     return settingSupported;
       
   488 }
       
   489 
       
   490 /*!
       
   491      PSetNetworkWrapperPrivate::AllowRefresh
       
   492 */
       
   493 TBool PSetNetworkWrapperPrivate::AllowRefresh(
       
   494                 const TSatRefreshType aType,
       
   495                 const TSatElementaryFiles aFiles )
       
   496 {
       
   497     DPRINT << "aType: " << aType;
       
   498     DPRINT << "aFiles: " << aFiles;
       
   499     
       
   500     return ETrue;
       
   501 }
       
   502 
       
   503 /*!
       
   504      PSetNetworkWrapperPrivate::Refresh
       
   505 */
       
   506 void PSetNetworkWrapperPrivate::Refresh(
       
   507                 const TSatRefreshType aType,
       
   508                 const TSatElementaryFiles aFiles )
       
   509 {
       
   510     DPRINT << "aType: " << aType;
       
   511     DPRINT << "aFiles: " << aFiles;
       
   512     
       
   513     if ((aType != EFileChangeNotification) ||
       
   514         ((aType == EFileChangeNotification) &&
       
   515         (aFiles == KCsp1Ef))) {
       
   516         TBool networkSelectionSupported;
       
   517         if (KErrNone == m_csp->IsNetworkSelectionSupported(networkSelectionSupported)) {
       
   518             DPRINT << "networkSelectionSupported " << networkSelectionSupported;
       
   519             emit m_owner.chageVisbilityOfManualNetworkSelection(networkSelectionSupported);
       
   520         }
       
   521     }
       
   522     
       
   523     DPRINT << ": OUT";
       
   524 }
       
   525