cellular/telephonysettings/xqbindings/psetwrapper/src/psetcallbarringwrapper_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 <psetcontainer.h>
       
    19 #include <psetcallbarring.h>
       
    20 #include "psetcallbarringwrapper.h"
       
    21 #include "psetcallbarringwrapper_p.h"
       
    22 #include "logging.h"
       
    23 
       
    24 TServiceGroup convertServiceGroup(PsServiceGroup serviceGroup)
       
    25 {
       
    26     TServiceGroup convertedType = EServiceGroupVoice;
       
    27     switch (serviceGroup) {
       
    28         case ServiceGroupVoice:
       
    29             convertedType = EServiceGroupVoice;
       
    30             break;
       
    31         case ServiceGroupData:
       
    32             convertedType = EServiceGroupData;
       
    33             break;
       
    34         case ServiceGroupFax:
       
    35             convertedType = EServiceGroupFax;
       
    36             break;
       
    37         case ServiceGroupAllTeleservices:
       
    38             convertedType = EServiceGroupAllTeleservices;
       
    39             break;
       
    40         default:
       
    41             break;
       
    42     }
       
    43     
       
    44     return convertedType;
       
    45 }
       
    46 
       
    47 PSetCallBarringWrapper::BarringType convertBarringType(
       
    48     TBarringProgram barringType)
       
    49 {
       
    50     PSetCallBarringWrapper::BarringType convertedType = 
       
    51         PSetCallBarringWrapper::BarringTypeAllBarrings;
       
    52     switch (barringType) {
       
    53         case EBarringTypeAllBarrings:
       
    54             convertedType = PSetCallBarringWrapper::BarringTypeAllBarrings;
       
    55             break;
       
    56         case EBarringTypeAllOutgoing:
       
    57             convertedType = PSetCallBarringWrapper::BarringTypeAllOutgoing;
       
    58             break;
       
    59         case EBarringTypeOutgoingInternational:
       
    60             convertedType = PSetCallBarringWrapper::BarringTypeOutgoingInternational;
       
    61             break;
       
    62         case EBarringTypeOutgoingInternationalExceptToHomeCountry:
       
    63             convertedType = PSetCallBarringWrapper::
       
    64                 BarringTypeOutgoingInternationalExceptToHomeCountry;
       
    65             break;
       
    66         case EBarringTypeAllIncoming:
       
    67             convertedType = PSetCallBarringWrapper::BarringTypeAllIncoming;
       
    68             break;
       
    69         case EBarringTypeIncomingWhenRoaming:
       
    70             convertedType = PSetCallBarringWrapper::BarringTypeIncomingWhenRoaming;
       
    71             break;
       
    72         case EBarringTypeAllServices:
       
    73             convertedType = PSetCallBarringWrapper::BarringTypeAllServices;
       
    74             break;
       
    75         case EBarringTypeAllOutgoingServices:
       
    76             convertedType = PSetCallBarringWrapper::BarringTypeAllOutgoingServices;
       
    77             break;
       
    78         case EBarringTypeAllIncomingServices:
       
    79             convertedType = PSetCallBarringWrapper::BarringTypeAllIncomingServices;
       
    80             break;
       
    81         default:
       
    82             break;
       
    83     }
       
    84     
       
    85     return convertedType;
       
    86 }
       
    87 
       
    88 TBarringProgram convertBarringType(
       
    89     PSetCallBarringWrapper::BarringType barringType)
       
    90 {
       
    91     TBarringProgram convertedType = EBarringTypeAllBarrings;
       
    92     switch (barringType) {
       
    93         case PSetCallBarringWrapper::BarringTypeAllBarrings:
       
    94             convertedType = EBarringTypeAllBarrings;
       
    95             break;
       
    96         case PSetCallBarringWrapper::BarringTypeAllOutgoing:
       
    97             convertedType = EBarringTypeAllOutgoing;
       
    98             break;
       
    99         case PSetCallBarringWrapper::BarringTypeOutgoingInternational:
       
   100             convertedType = EBarringTypeOutgoingInternational;
       
   101             break;
       
   102         case PSetCallBarringWrapper::
       
   103                 BarringTypeOutgoingInternationalExceptToHomeCountry:
       
   104             convertedType 
       
   105                 = EBarringTypeOutgoingInternationalExceptToHomeCountry;
       
   106             break;
       
   107         case PSetCallBarringWrapper::BarringTypeAllIncoming:
       
   108             convertedType = EBarringTypeAllIncoming;
       
   109             break;
       
   110         case PSetCallBarringWrapper::BarringTypeIncomingWhenRoaming:
       
   111             convertedType = EBarringTypeIncomingWhenRoaming;
       
   112             break;
       
   113         case PSetCallBarringWrapper::BarringTypeAllServices:
       
   114             convertedType = EBarringTypeAllServices;
       
   115             break;
       
   116         case PSetCallBarringWrapper::BarringTypeAllOutgoingServices:
       
   117             convertedType = EBarringTypeAllOutgoingServices;
       
   118             break;
       
   119         case PSetCallBarringWrapper::BarringTypeAllIncomingServices:
       
   120             convertedType = EBarringTypeAllIncomingServices;
       
   121             break;
       
   122         default:
       
   123             break;
       
   124     }
       
   125     
       
   126     return convertedType;
       
   127 }
       
   128 
       
   129 
       
   130 PSetCallBarringWrapper::BarringStatus convertBarringStatus(
       
   131     TBarringStatus status)
       
   132 {
       
   133     PSetCallBarringWrapper::BarringStatus convertedType = 
       
   134         PSetCallBarringWrapper::BarringStatusUnknown;
       
   135     switch (status) {
       
   136         case EBarringStatusActive:
       
   137             convertedType = PSetCallBarringWrapper::BarringStatusActive;
       
   138             break;
       
   139         case EBarringStatusInactive:
       
   140             convertedType = PSetCallBarringWrapper::BarringStatusInactive;
       
   141             break;
       
   142         case EBarringStatusNotProvisioned:
       
   143             convertedType = 
       
   144                 PSetCallBarringWrapper::BarringStatusNotProvisioned;
       
   145             break;
       
   146         case EBarringStatusUnavailable:
       
   147             convertedType = PSetCallBarringWrapper::BarringStatusUnavailable;
       
   148             break;
       
   149         case EBarringStatusUnknown:
       
   150         default:
       
   151             convertedType = PSetCallBarringWrapper::BarringStatusUnknown;
       
   152             break;
       
   153     }
       
   154     
       
   155     return convertedType;
       
   156 }
       
   157 
       
   158 
       
   159 /*!
       
   160   PSetCallBarringWrapperPrivate::PSetCallBarringWrapperPrivate
       
   161  */
       
   162 PSetCallBarringWrapperPrivate::PSetCallBarringWrapperPrivate( 
       
   163         PSetCallBarringWrapper &owner, CPsetContainer &psetContainer) 
       
   164     : 
       
   165     m_owner(owner),
       
   166     m_callBarring(NULL),
       
   167     m_currentRequest(RequestNone),
       
   168     m_barringError(PSetCallBarringWrapper::BarringErrorNone),
       
   169     m_barringStatus(PSetCallBarringWrapper::BarringStatusUnknown),
       
   170     m_barringType(PSetCallBarringWrapper::BarringTypeAllBarrings),
       
   171     m_plural(false)
       
   172 {
       
   173     DPRINT;
       
   174     
       
   175     QT_TRAP_THROWING(
       
   176         m_callBarring = psetContainer.CreateCBObjectL(*this)
       
   177     )
       
   178     
       
   179     m_callBarring->SetRequestObserver(this);
       
   180 }
       
   181 
       
   182 
       
   183 /*!
       
   184   PSetCallBarringWrapperPrivate::~PSetCallBarringWrapperPrivate
       
   185  */
       
   186 PSetCallBarringWrapperPrivate::~PSetCallBarringWrapperPrivate()
       
   187 {
       
   188     DPRINT;
       
   189     
       
   190     delete m_callBarring;
       
   191 }
       
   192 
       
   193 
       
   194 /*!
       
   195   PSetCallBarringWrapperPrivate::barringStatus
       
   196  */
       
   197 void PSetCallBarringWrapperPrivate::barringStatus(
       
   198     PsServiceGroup serviceGroup,
       
   199     PSetCallBarringWrapper::BarringType barringType)
       
   200 {
       
   201     DPRINT;
       
   202     
       
   203     TServiceGroup convertedServiceGroup = convertServiceGroup(serviceGroup);
       
   204     TBarringProgram convertedBarringType = convertBarringType(barringType);
       
   205 
       
   206     m_currentRequest = RequestBarringStatus;
       
   207     QT_TRAP_THROWING(m_callBarring->GetBarringStatusL(
       
   208         convertedServiceGroup, convertedBarringType)
       
   209     )
       
   210 }
       
   211 
       
   212 
       
   213 /*!
       
   214   PSetCallBarringWrapperPrivate::enableBarring
       
   215  */
       
   216 void PSetCallBarringWrapperPrivate::enableBarring(
       
   217         PsServiceGroup serviceGroup,
       
   218         PSetCallBarringWrapper::BarringType barringType,
       
   219         QString barringPassword)
       
   220 {
       
   221     DPRINT;
       
   222     
       
   223     TCallBarringSetting setting;
       
   224     setting.iType = convertBarringType(barringType);
       
   225     setting.iSetting = EActivateBarring;
       
   226     setting.iServiceGroup = convertServiceGroup(serviceGroup);
       
   227     setting.iPassword.Copy(barringPassword.utf16());
       
   228     
       
   229     TBasicServiceGroups serviceGroups = EAllTeleAndBearer;
       
   230     
       
   231     m_currentRequest = RequestEnableBarring;
       
   232     QT_TRAP_THROWING(
       
   233         m_callBarring->SetBarringL(setting, serviceGroups);
       
   234     )
       
   235 }
       
   236 
       
   237 
       
   238 /*!
       
   239   PSetCallBarringWrapperPrivate::disableBarring
       
   240  */
       
   241 void PSetCallBarringWrapperPrivate::disableBarring(
       
   242     PsServiceGroup serviceGroup,
       
   243     PSetCallBarringWrapper::BarringType barringType,
       
   244     QString barringPassword)
       
   245 {
       
   246     DPRINT;
       
   247     
       
   248     TCallBarringSetting setting;
       
   249     setting.iType = convertBarringType(barringType);
       
   250     setting.iSetting = ECancelBarring;
       
   251     setting.iServiceGroup = convertServiceGroup(serviceGroup);
       
   252     setting.iPassword.Copy(barringPassword.utf16());
       
   253     
       
   254     TBasicServiceGroups serviceGroups = EAllTeleAndBearer;
       
   255 
       
   256     m_currentRequest = RequestDisableBarring;
       
   257     QT_TRAP_THROWING(
       
   258         m_callBarring->SetBarringL(setting, serviceGroups);
       
   259     )    
       
   260 }
       
   261 
       
   262 
       
   263 /*!
       
   264   PSetCallBarringWrapperPrivate::changeBarringPassword
       
   265  */
       
   266 void PSetCallBarringWrapperPrivate::changeBarringPassword(
       
   267     const QString &oldPassword,
       
   268     const QString &newPassword,
       
   269     const QString &verifiedPassword)
       
   270 {
       
   271     RMobilePhone::TMobilePhonePasswordChangeV2 passwordChange;
       
   272     passwordChange.iOldPassword.Copy(oldPassword.utf16());
       
   273     passwordChange.iNewPassword.Copy(newPassword.utf16());
       
   274     passwordChange.iVerifiedPassword.Copy(verifiedPassword.utf16());
       
   275     
       
   276     m_currentRequest = RequestChangePassword;
       
   277     QT_TRAP_THROWING(
       
   278         m_callBarring->ChangePasswordL(passwordChange);
       
   279     )
       
   280 }
       
   281 
       
   282 
       
   283 /*!
       
   284   From MPsetBarringObserver.
       
   285   PSetCallBarringWrapperPrivate::HandleBarringModeChangedL
       
   286  */
       
   287 void PSetCallBarringWrapperPrivate::HandleBarringModeChangedL( 
       
   288     TBarringProgram aType, 
       
   289     TBarringStatus aStatus, 
       
   290     TBool aPlural )
       
   291 {
       
   292     DPRINT;
       
   293     Q_ASSERT(RequestEnableBarring == m_currentRequest || 
       
   294              RequestDisableBarring == m_currentRequest);
       
   295     
       
   296     m_barringType = convertBarringType(aType);
       
   297     m_barringError = PSetCallBarringWrapper::BarringErrorNone;
       
   298     m_barringStatus = convertBarringStatus(aStatus);
       
   299     m_plural = static_cast<bool>(aPlural);
       
   300 }
       
   301 
       
   302 
       
   303 /*!
       
   304   From MPsetBarringObserver.
       
   305   PSetCallBarringWrapperPrivate::HandleBarringModeStatusL
       
   306  */
       
   307 void PSetCallBarringWrapperPrivate::HandleBarringModeStatusL( 
       
   308     TUint8 aBsc[KPSetNumberOfBsc], 
       
   309     TBarringStatus aStatus )
       
   310 {
       
   311     DPRINT;
       
   312     Q_ASSERT(RequestBarringStatus == m_currentRequest);
       
   313     
       
   314     m_barringError = PSetCallBarringWrapper::BarringErrorNone;
       
   315     QT_TRYCATCH_LEAVING(
       
   316         int index = 0;
       
   317         unsigned char groupIdCandidate = aBsc[index];
       
   318         while ((groupIdCandidate 
       
   319                 != static_cast<unsigned char>(KPSetUnusedValue))) {
       
   320             m_basicServiceGroupIds << groupIdCandidate;
       
   321             groupIdCandidate = aBsc[++index];
       
   322         }
       
   323     )
       
   324     m_barringStatus = convertBarringStatus(aStatus);
       
   325 }
       
   326 
       
   327 
       
   328 /*!
       
   329   From MPsetBarringObserver.
       
   330   PSetCallBarringWrapperPrivate::HandleBarringErrorL
       
   331  */
       
   332 void PSetCallBarringWrapperPrivate::HandleBarringErrorL( 
       
   333     TInt aReason )
       
   334 {
       
   335     DPRINT;
       
   336     Q_UNUSED(aReason)
       
   337     
       
   338     m_barringError = aReason;
       
   339     m_basicServiceGroupIds.clear();
       
   340     m_barringStatus = PSetCallBarringWrapper::BarringStatusUnknown;
       
   341     m_plural = false;
       
   342 }
       
   343 
       
   344 
       
   345 /*!
       
   346   From MPsetBarringObserver.
       
   347   PSetCallBarringWrapperPrivate::HandleCBRequestingL
       
   348  */
       
   349 void PSetCallBarringWrapperPrivate::HandleCBRequestingL( 
       
   350     TBool aTrue, 
       
   351     TBool aInterrupted )
       
   352 {
       
   353     DPRINT;
       
   354     
       
   355     Q_UNUSED(aTrue)
       
   356     Q_UNUSED(aInterrupted)
       
   357 }
       
   358 
       
   359 
       
   360 /*!
       
   361   From MPsetBarringObserver.
       
   362   PSetCallBarringWrapperPrivate::SetEngineContact
       
   363  */
       
   364 void PSetCallBarringWrapperPrivate::SetEngineContact( 
       
   365     MPsetCallBarring* aBarringEngine )
       
   366 {
       
   367     DPRINT;
       
   368     
       
   369     Q_UNUSED(aBarringEngine)
       
   370 }
       
   371 
       
   372 
       
   373 /*!
       
   374   From MPsetBarringObserver.
       
   375   PSetCallBarringWrapperPrivate::CbPasswordChangedL
       
   376  */
       
   377 void PSetCallBarringWrapperPrivate::CbPasswordChangedL( 
       
   378     TBool aSuccess )
       
   379 {
       
   380     DPRINT;
       
   381     
       
   382     if (aSuccess) {
       
   383         m_barringError = PSetCallBarringWrapper::BarringErrorNone;
       
   384     } else {
       
   385         m_barringError = KErrGsmSSNegativePasswordCheck;
       
   386     }
       
   387 }
       
   388 
       
   389 
       
   390 /*!
       
   391   From MPsetRequestObserver.
       
   392   PSetCallBarringWrapperPrivate::RequestComplete
       
   393  */
       
   394 void PSetCallBarringWrapperPrivate::RequestComplete()
       
   395 {
       
   396     DPRINT;
       
   397     Q_ASSERT(RequestNone != m_currentRequest);
       
   398     BarringRequest completedRequest = m_currentRequest;
       
   399     m_currentRequest = RequestNone;
       
   400     
       
   401     switch (completedRequest)
       
   402     {
       
   403         case RequestBarringStatus:
       
   404         {
       
   405             int errorCode = 0;
       
   406             QT_TRYCATCH_ERROR( errorCode,
       
   407                 emit m_owner.barringStatusRequestCompleted(
       
   408                     m_barringError,
       
   409                     m_basicServiceGroupIds, 
       
   410                     m_barringStatus);
       
   411             )
       
   412             DPRINT << "RequestBarringStatus ERROR:" << errorCode;
       
   413             break;
       
   414         }
       
   415         
       
   416         case RequestEnableBarring:
       
   417         {
       
   418             int errorCode = 0;
       
   419             QT_TRYCATCH_ERROR( errorCode,
       
   420                 emit m_owner.enableBarringRequestCompleted(
       
   421                     m_barringError,
       
   422                     m_barringType,
       
   423                     m_barringStatus, 
       
   424                     m_plural);
       
   425             )
       
   426             DPRINT << "RequestEnableBarring ERROR:" << errorCode;
       
   427             break;
       
   428         }
       
   429         
       
   430         case RequestDisableBarring:
       
   431         {
       
   432             int errorCode = 0;
       
   433             QT_TRYCATCH_ERROR( errorCode,
       
   434                 emit m_owner.disableBarringRequestCompleted(
       
   435                     m_barringError,
       
   436                     m_barringType,
       
   437                     m_barringStatus, 
       
   438                     m_plural);
       
   439             )
       
   440             DPRINT << "RequestDisableBarring ERROR:" << errorCode;
       
   441             break;
       
   442         }
       
   443         
       
   444         case RequestChangePassword:
       
   445         {
       
   446             int errorCode = 0;
       
   447             QT_TRYCATCH_ERROR( errorCode,
       
   448                 emit m_owner.barringPasswordChangeRequestCompleted(
       
   449                     m_barringError);
       
   450             )
       
   451             DPRINT << "RequestChangePassword ERROR:" << errorCode;
       
   452             break;
       
   453         }
       
   454         
       
   455         default:
       
   456             break;
       
   457     }
       
   458 }
       
   459 
       
   460 
       
   461 /*!
       
   462   From MPsetRequestObserver.
       
   463   PSetCallBarringWrapperPrivate::RequestStatusChanged
       
   464  */
       
   465 void PSetCallBarringWrapperPrivate::RequestStatusChanged( 
       
   466     TInt aNewStatus)
       
   467 {
       
   468     DPRINT;
       
   469     Q_UNUSED(aNewStatus)
       
   470     Q_ASSERT(RequestNone != m_currentRequest);
       
   471 }
       
   472 
       
   473 // End of File.