cellular/telephonysettings/src/PSetCallDivertingBase.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2008-2008 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: Implementation of CPSetCallDivertingBase class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "psetcalldivertingbasicimpl.h" 
       
    21 
       
    22 #include <badesca.h>
       
    23 #include <etelmm.h>           
       
    24 #include <e32math.h>
       
    25 #include <e32svr.h>
       
    26 #include <featmgr.h>
       
    27 #include <centralrepository.h>
       
    28 #include <settingsinternalcrkeys.h> 
       
    29 
       
    30 #include "psetcalldiverting.h" 
       
    31 #include "psetcontainer.h" 
       
    32 #include "mpsetdivertobs.h" 
       
    33 #include "psettelephony.h" 
       
    34 #include "psetpanic.h" 
       
    35 #include "mpsetrequestobs.h" 
       
    36 #include "psetutility.h" 
       
    37 #include "phonesettingslogger.h" 
       
    38 #include "psetsaobserver.h" 
       
    39 #include "psetcalldivertingbase.h" 
       
    40 
       
    41 //  LOCAL CONSTANTS AND MACROS
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CPSetCallDivertingBase::NewL
       
    47 // Two-phased constructor.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CPSetCallDivertingBase* CPSetCallDivertingBase::NewL( 
       
    51         MPsetDivertObserver& aObserver, 
       
    52         RMobilePhone& aPhone,
       
    53         CPsetCallDiverting* aDivert )
       
    54     {
       
    55     CPSetCallDivertingBase* self = new ( ELeave ) CPSetCallDivertingBase( aPhone, aDivert );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL( aObserver );
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CPSetCallDivertingBase::~CPSetCallDivertingBase
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CPSetCallDivertingBase::~CPSetCallDivertingBase()
       
    67     {
       
    68     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::~CPSetCallDivertingBase");
       
    69     Cancel();
       
    70 
       
    71     if ( iLine )
       
    72         {
       
    73         iLine->Close();
       
    74         }
       
    75     delete iLine;   
       
    76 
       
    77     if ( iSsSettings )
       
    78         {
       
    79         iSsSettings->Cancel( ESSSettingsAls, *this ); 
       
    80         iSsSettings->Close();
       
    81         }
       
    82     delete iSsSettings;
       
    83     delete iCfInterrogator;
       
    84 
       
    85     iReqObserver = NULL;
       
    86 
       
    87     delete iRepository;
       
    88     
       
    89     if ( iFeatureManagerInitialized )
       
    90         {
       
    91         FeatureManager::UnInitializeLib();
       
    92         }
       
    93 
       
    94     __PHSLOGSTRING("[PHS]<-- CPSetCallDivertingBase::~CPSetCallDivertingBase");
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CPSetCallDivertingBase::CPSetCallDivertingBase
       
    99 // C++ constructor can NOT contain any code, that
       
   100 // might leave.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CPSetCallDivertingBase::CPSetCallDivertingBase( RMobilePhone& aPhone,  CPsetCallDiverting* aDivert  ) : 
       
   104                     CActive ( EPriorityStandard ),
       
   105                     iPhone ( aPhone ),
       
   106                     iDivert( aDivert )
       
   107     {
       
   108     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::CPSetCallDivertingBase");
       
   109     iFeatureManagerInitialized = EFalse;
       
   110     __PHSLOGSTRING("[PHS]<-- CPSetCallDivertingBase::CPSetCallDivertingBase");
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CPSetCallDivertingBase::ConstructL
       
   115 // Symbian 2nd phase constructor can leave.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CPSetCallDivertingBase::ConstructL( MPsetDivertObserver& aObserver )
       
   119     {
       
   120     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::ConstructL" );
       
   121     iLine = new ( ELeave ) RMobileLine;
       
   122 
       
   123     //Copy received information to member variable.
       
   124     iObserver = &aObserver;
       
   125     
       
   126     CActiveScheduler::Add( this );
       
   127 
       
   128     //Check which line is used, or if ALS is not active.
       
   129     TInt usedLine = ESSSettingsAlsNotSupported;
       
   130 
       
   131     iSsSettings = new (ELeave) RSSSettings;
       
   132     User::LeaveIfError( iSsSettings->Open() );
       
   133     TRAPD( err, iSsSettings->Register( ESSSettingsAls, *this ) );
       
   134     if ( err == KErrNone )
       
   135         {
       
   136         iSsSettings->Get( ESSSettingsAls, usedLine );
       
   137         }
       
   138 
       
   139     iAls = static_cast <TSSSettingsAlsValue> ( usedLine );
       
   140     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::ConstructL: usedLine: %d", usedLine );
       
   141 
       
   142     iRepository = CRepository::NewL( KCRUidCallForwarding );
       
   143 
       
   144     // Sets up TLS, must be done before FeatureManager is used.
       
   145     FeatureManager::InitializeLibL();
       
   146     iFeatureManagerInitialized = ETrue;
       
   147     
       
   148     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::ConstructL" );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // RunL
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CPSetCallDivertingBase::RunL()
       
   156     {
       
   157     // Empty implementation.
       
   158     }
       
   159        
       
   160 // ---------------------------------------------------------------------------
       
   161 // DoCancel
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CPSetCallDivertingBase::DoCancel()
       
   165     {
       
   166     // Empty implementation.
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // SetRequestObserver
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void CPSetCallDivertingBase::SetRequestObserver( MPsetRequestObserver* aObs )
       
   174     {
       
   175     iReqObserver = aObs;
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // SetDivertingL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CPSetCallDivertingBase::SetDivertingL( const TCallDivertSetting& /*aDivert*/,  
       
   183                             TBasicServiceGroups /*aBsc*/ )
       
   184     {
       
   185     //Empty implementation.
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CancelCurrentRequest
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 TInt CPSetCallDivertingBase::CancelCurrentRequest()
       
   193     {
       
   194     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::CancelCurrentRequest" );
       
   195     // Set PSUI so that correct observer is used and hide requesting note.
       
   196     // When interrupting a note, does not leave.
       
   197     // This needs to be done first, since notes must be cleared from screen
       
   198     // even though request is not active.
       
   199     iObserver->SetEngineContact( iDivert );
       
   200     // Does not leave
       
   201     TRAPD( err, iObserver->HandleCFRequestingL( EFalse, ETrue ) );
       
   202 
       
   203     if ( !IsActive() || err != KErrNone )
       
   204         {
       
   205         __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::CancelCurrentRequest: KErrGeneral" );
       
   206         return KErrGeneral;
       
   207         }
       
   208     
       
   209     if ( iCFStatusCheck )
       
   210         {
       
   211         iCFStatusCheck = EFalse;
       
   212         Cancel();
       
   213         }
       
   214 
       
   215     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::CancelCurrentRequest: KErrNone" );
       
   216     return KErrNone;
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // Sets new default number the the default numbers list, erases the oldest one.
       
   221 // ---------------------------------------------------------------------------
       
   222 //
       
   223 TInt CPSetCallDivertingBase::SetNewDefaultNumberL( TDes& aNumber )
       
   224     {
       
   225     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::SetNewDefaultNumberL" );    
       
   226     TTelNumber oldFirst;
       
   227     TTelNumber oldSecond; 
       
   228 
       
   229     CDesC16ArrayFlat* defNumberArray = 
       
   230         new ( ELeave ) CDesC16ArrayFlat( KPSetDefaultNumberMax );
       
   231     CleanupStack::PushL( defNumberArray );
       
   232 
       
   233     TInt defNumbers = GetNumbersFromSharedDataL( iAls, *defNumberArray );
       
   234     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::SetNewDefaultNumberL: defNumbers: %d", defNumbers);
       
   235 
       
   236     if ( defNumbers > 0 ) //at least one number was fetched
       
   237         {
       
   238         //save latest divert no.
       
   239        oldFirst = defNumberArray->MdcaPoint( 0 );
       
   240         }
       
   241     if ( defNumbers > 1 ) //at least two numbers were fetched
       
   242         {
       
   243         //save second latest divert no.
       
   244         oldSecond = defNumberArray->MdcaPoint( 1 );
       
   245         }
       
   246     CleanupStack::PopAndDestroy( defNumberArray );
       
   247 
       
   248     if ( iAls != ESSSettingsAlsAlternate )
       
   249         {
       
   250         __PHSLOGSTRING("[PHS]    CPSetCallDivertingBase::SetNewDefaultNumberL: !ESSSettingsAlsAlternate" );
       
   251         switch ( defNumbers ) // cases flow through
       
   252             {
       
   253             case 3:
       
   254             case 2://two default numbers
       
   255                 User::LeaveIfError( 
       
   256                     SaveKey( KSettingsCFDefaultNumber3, oldSecond ) );
       
   257             case 1://one default number
       
   258                 User::LeaveIfError( 
       
   259                     SaveKey( KSettingsCFDefaultNumber2, oldFirst ) );
       
   260             case 0://no default numbers
       
   261                 User::LeaveIfError( 
       
   262                     SaveKey( KSettingsCFDefaultNumber1, aNumber ) );
       
   263                 break;
       
   264             }
       
   265         }
       
   266     else//aux line
       
   267         {
       
   268         __PHSLOGSTRING("[PHS]    CPSetCallDivertingBase::SetNewDefaultNumberL: Aux line" );
       
   269         switch ( defNumbers ) // cases flow through
       
   270             {
       
   271             case 3:
       
   272             case 2://two default numbers
       
   273                 User::LeaveIfError( 
       
   274                     SaveKey( KSettingsCFDefaultNumberAls3, oldSecond ) );
       
   275             case 1://one default number
       
   276                 User::LeaveIfError( 
       
   277                     SaveKey( KSettingsCFDefaultNumberAls2, oldFirst ) );
       
   278             case 0://no default numbers
       
   279                 User::LeaveIfError( 
       
   280                     SaveKey( KSettingsCFDefaultNumberAls1, aNumber ) );
       
   281                 break;
       
   282             default:
       
   283                 User::Leave( KErrArgument );
       
   284                 break;
       
   285             }
       
   286         } 
       
   287 
       
   288     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::SetNewDefaultNumberL" );
       
   289     return KErrNone; //return value is not used
       
   290     }
       
   291 
       
   292 // --------------------------------------------------------------------------- 
       
   293 // Saves a single value to central repository. Make sure that repository
       
   294 // is open before calling this function.
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 TInt CPSetCallDivertingBase::SaveKey(
       
   298     TUint32 aKeyId,
       
   299     const TDesC& aKeyValue )
       
   300     {
       
   301     TInt error = KErrUnknown;
       
   302 
       
   303     error = iRepository->Set( aKeyId, aKeyValue );
       
   304 
       
   305     return error;
       
   306     }
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // Reads used divert numbers (0-3) from shared data and fills array with them.
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 TInt CPSetCallDivertingBase::GetNumbersFromSharedDataL( TInt aType, 
       
   313                 CDesC16ArrayFlat& aArray )
       
   314     {
       
   315     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::GetNumbersFromSharedDataL" );
       
   316 
       
   317     TInt amount = 0;
       
   318     TTelNumber readValue;
       
   319     aType = iAls;
       
   320     
       
   321     RArray<TUint32> keyArray( KPSetDefaultNumberMax ); 
       
   322     CleanupClosePushL( keyArray );
       
   323     //to simplify reading, append needed values to an array    
       
   324     if ( aType != ESSSettingsAlsAlternate )
       
   325         {
       
   326         keyArray.AppendL( KSettingsCFDefaultNumber1 );
       
   327         keyArray.AppendL( KSettingsCFDefaultNumber2 );
       
   328         keyArray.AppendL( KSettingsCFDefaultNumber3 );
       
   329         }
       
   330     else //auxiliary line
       
   331         {
       
   332         keyArray.AppendL( KSettingsCFDefaultNumberAls1 );
       
   333         keyArray.AppendL( KSettingsCFDefaultNumberAls2 );
       
   334         keyArray.AppendL( KSettingsCFDefaultNumberAls3 );
       
   335         }    
       
   336 
       
   337     TInt i = KErrNone;
       
   338     TInt loc = KErrNone;
       
   339     while ( i == KErrNone && loc < KPSetDefaultNumberMax )
       
   340         {
       
   341         i = iRepository->Get( keyArray.operator[]( loc ), readValue );
       
   342         if ( i == KErrNone )
       
   343             {
       
   344             HBufC16* string = static_cast <HBufC16*> ( readValue.AllocLC() );
       
   345             if ( string->Length() > 0 )
       
   346                 {
       
   347                 aArray.AppendL( *string );
       
   348                 amount++;
       
   349                 }
       
   350             CleanupStack::PopAndDestroy( string );
       
   351             }
       
   352         loc++;
       
   353         }
       
   354     CleanupStack::PopAndDestroy(); // keyArray.
       
   355 
       
   356     __PHSLOGSTRING1("[PHS] <--CPSetCallDivertingBase::GetNumbersFromSharedDataL: amount: %d", amount );
       
   357     return amount;
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // Gets the timer value index related to "cfnry" from shared data
       
   362 // In error cases, return default value (30).
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 TInt CPSetCallDivertingBase::GetTimerValueL()
       
   366     {
       
   367     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::GetTimerValueL" );
       
   368     
       
   369     TInt timerValue = 0;
       
   370     TInt error = KErrNone;
       
   371 
       
   372     if ( iAls == ESSSettingsAlsAlternate )
       
   373         {
       
   374         error = iRepository->Get( KSettingsCFTimerValueAls, timerValue );
       
   375         __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::GetTimerValueL: KSettingsCFTimerValueAls: %d", timerValue );
       
   376         __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::GetTimerValueL: error: %d", error );
       
   377         }
       
   378     else
       
   379         {
       
   380         error = iRepository->Get( KSettingsCFTimerValue, timerValue );
       
   381 
       
   382         __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::GetTimerValueL: KPsetCFTimerValue: %d", timerValue );
       
   383         __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::GetTimerValueL: error: %d", error );
       
   384         }
       
   385     
       
   386     if ( error != KErrNone || !VerifyDelayTime( timerValue ) )
       
   387         {
       
   388         __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::GetTimerValueL: KPsetDefaultTimerValue" );
       
   389         return KPsetDefaultTimerValue;
       
   390         }
       
   391     else
       
   392         {
       
   393         __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::GetTimerValueL: timerValue" );
       
   394         return timerValue;
       
   395         }
       
   396     }
       
   397 
       
   398 // ---------------------------------------------------------------------------
       
   399 // Sets the default time for "divert when not answered" to .ini file 
       
   400 // ---------------------------------------------------------------------------
       
   401 TInt CPSetCallDivertingBase::SetTimerValueL( const TInt& aValue )
       
   402     {
       
   403     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::SetTimerValueL" );
       
   404 
       
   405     TInt retValue = KErrNone;
       
   406 
       
   407     // If delay time is not divisable by five, return.
       
   408     if ( !VerifyDelayTime( aValue ) )
       
   409         {
       
   410         return KErrArgument;
       
   411         }
       
   412 
       
   413     if ( iAls != ESSSettingsAlsAlternate )
       
   414         {
       
   415         retValue = iRepository->Set( KSettingsCFTimerValue, aValue );
       
   416         __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::SetTimerValueL: KPsetCFTimerValue: %d", aValue );
       
   417         }
       
   418     else
       
   419         {
       
   420         retValue = iRepository->Set( KSettingsCFTimerValueAls, aValue );
       
   421         __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::SetTimerValueL: KPsetCFTimerValueAls: %d", aValue );
       
   422         }
       
   423 
       
   424     __PHSLOGSTRING1("[PHS] <--CPSetCallDivertingBase::SetTimerValueL: retValue: %d", retValue );
       
   425     return retValue;
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------------------------
       
   429 // Verifies that delay time is divisible by five.
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 TBool CPSetCallDivertingBase::VerifyDelayTime( const TInt& aDelayTime )
       
   433     {
       
   434     TReal res = 0;
       
   435     Math::Mod( res, aDelayTime, KPsetDelayTimeDivider ); 
       
   436     return res == 0;
       
   437     }
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // Swaps the most recently used number to first in the shared data file.
       
   441 // ---------------------------------------------------------------------------
       
   442 //
       
   443 void CPSetCallDivertingBase::SwapDefaultNumberL( const TInt& aLocation )
       
   444     {
       
   445     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::SwapDefaultNumberL" );
       
   446 
       
   447     if ( aLocation == KPSetFirstDefNumber )
       
   448         {
       
   449         return; //no need to reorganize, number is already first
       
   450         }
       
   451     else if ( 
       
   452         !( aLocation == KPSetSecondDefNumber || 
       
   453            aLocation == KPSetThirdDefNumber ) )
       
   454         {
       
   455         User::Leave( KErrArgument );
       
   456         }
       
   457 
       
   458     CDesC16ArrayFlat* defNumbers = 
       
   459         new ( ELeave ) CDesC16ArrayFlat( KPSetDefaultNumberMax );
       
   460     CleanupStack::PushL( defNumbers );
       
   461 
       
   462     GetNumbersFromSharedDataL( iAls, *defNumbers );
       
   463 
       
   464     if ( iAls != ESSSettingsAlsAlternate ) 
       
   465     //EGetAlsLinePrimary or Not supported or Unknown
       
   466         {
       
   467         __PHSLOGSTRING("[PHS]    CPSetCallDivertingBase::SwapDefaultNumberL: !ESSSettingsAlsAlternate" );
       
   468         switch( aLocation )
       
   469             {
       
   470             case KPSetSecondDefNumber:
       
   471                 User::LeaveIfError( 
       
   472                     SaveKey( 
       
   473                         KSettingsCFDefaultNumber2, 
       
   474                         defNumbers->MdcaPoint(0) ) );
       
   475                 User::LeaveIfError( 
       
   476                     SaveKey( 
       
   477                         KSettingsCFDefaultNumber1, 
       
   478                         defNumbers->MdcaPoint(1) ) );
       
   479                 break;
       
   480             case KPSetThirdDefNumber:
       
   481                 User::LeaveIfError( 
       
   482                     SaveKey( 
       
   483                         KSettingsCFDefaultNumber2, 
       
   484                         defNumbers->MdcaPoint(0) ) );
       
   485                 User::LeaveIfError( 
       
   486                     SaveKey( 
       
   487                         KSettingsCFDefaultNumber3, 
       
   488                         defNumbers->MdcaPoint(1) ) );
       
   489                 User::LeaveIfError( 
       
   490                     SaveKey( 
       
   491                         KSettingsCFDefaultNumber1, 
       
   492                         defNumbers->MdcaPoint(2) ) );
       
   493                 break;
       
   494             default:
       
   495                 break;
       
   496             }
       
   497         }            
       
   498     else //alternate line
       
   499         {
       
   500         __PHSLOGSTRING("[PHS]    CPSetCallDivertingBase::SwapDefaultNumberL: ESSSettingsAlsAlternate" );
       
   501         switch( aLocation )
       
   502             {
       
   503             case KPSetSecondDefNumber:
       
   504                 User::LeaveIfError( 
       
   505                     SaveKey( 
       
   506                         KSettingsCFDefaultNumberAls1, 
       
   507                         defNumbers->MdcaPoint(0) ) );
       
   508                 User::LeaveIfError( 
       
   509                     SaveKey( 
       
   510                         KSettingsCFDefaultNumberAls2, 
       
   511                         defNumbers->MdcaPoint(1) ) );
       
   512                 break;
       
   513             case KPSetThirdDefNumber:
       
   514                 User::LeaveIfError( 
       
   515                     SaveKey( 
       
   516                         KSettingsCFDefaultNumberAls2, 
       
   517                         defNumbers->MdcaPoint(0) ) );
       
   518                 User::LeaveIfError( 
       
   519                     SaveKey( 
       
   520                         KSettingsCFDefaultNumberAls3, 
       
   521                         defNumbers->MdcaPoint(1) ) );
       
   522                 User::LeaveIfError( 
       
   523                     SaveKey( 
       
   524                         KSettingsCFDefaultNumberAls1, 
       
   525                         defNumbers->MdcaPoint(2) ) );
       
   526                 break;
       
   527             default:
       
   528                 break;
       
   529             }
       
   530         }
       
   531     CleanupStack::PopAndDestroy( defNumbers );
       
   532     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::SwapDefaultNumberL" );
       
   533     }
       
   534 
       
   535 // ---------------------------------------------------------------------------
       
   536 // Request diverting status from network asynhronously.
       
   537 // ---------------------------------------------------------------------------
       
   538 void CPSetCallDivertingBase::GetDivertingStatusL( 
       
   539     const TServiceGroup aServiceGroup,
       
   540     const TCallDivertingCondition aCondition, 
       
   541     TBasicServiceGroups aBsc ) 
       
   542     {
       
   543     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::GetDivertingStatusL" );
       
   544 
       
   545     if ( IsActive() )
       
   546         {
       
   547         User::Leave( KErrInUse );
       
   548         }
       
   549     
       
   550     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::GetDivertingStatusL: aServiceGroup: %d", aServiceGroup );
       
   551     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::GetDivertingStatusL: aCondition: %d", aCondition );
       
   552     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::GetDivertingStatusL: aBsc: %d", aBsc );
       
   553 
       
   554     iCFStatusCheck = ETrue;
       
   555 
       
   556     CPsetTelephony::CheckLineModeL( aServiceGroup, &iPhone, iLine );    
       
   557     if ( !iLine->SubSessionHandle() )
       
   558         {
       
   559         User::Leave( KErrBadHandle );
       
   560         }
       
   561 
       
   562     // in these cases basic service group will not be set
       
   563     if ( !( aCondition == EDivertConditionAllCalls || 
       
   564             aCondition == EDivertConditionAllConditionalCases ) )
       
   565         {
       
   566         __PHSLOGSTRING("[PHS]    CPSetCallDivertingBase::GetDivertingStatusL: CancelAll should not come here" );
       
   567         ValidateBsc( aBsc );
       
   568         }
       
   569 
       
   570     iReason = PSetUtility::GetDivertReason( aCondition );    
       
   571 
       
   572     // Start to request for status.
       
   573     if (iCfInterrogator)
       
   574         {
       
   575         delete iCfInterrogator;
       
   576         iCfInterrogator = NULL;
       
   577         }
       
   578     iCfInterrogator = CRetrieveMobilePhoneCFList::NewL( iPhone );
       
   579     iCfInterrogator->Start( 
       
   580         iStatus, 
       
   581         iReason, 
       
   582         PSetUtility::ChangeToEtelInternal( aBsc ) );
       
   583 
       
   584     StartRequestingL( EPSetGetDivertStatus );
       
   585 
       
   586     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::GetDivertingStatusL" );
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------------------------
       
   590 // Creates param list for NotifyDivertChange method.
       
   591 // ---------------------------------------------------------------------------
       
   592 //
       
   593 TCallDivertNotifySetting CPSetCallDivertingBase::CreateDivertNotifySetting( 
       
   594     TUnconditionalCFStatus aCurrentDivert, TBool aDivertChanged, 
       
   595     TBool aVoiceMbxDivert, TInt aBasic )
       
   596     {
       
   597     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase iVideoDivert    = %d", iVideoDivert );
       
   598     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase iVoiceDivert    = %d", iVoiceDivert );
       
   599     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase aVoiceMbxDivert = %d", aVoiceMbxDivert );
       
   600     
       
   601     TCallDivertNotifySetting divertNotify;
       
   602     divertNotify.Initialize();
       
   603 
       
   604     divertNotify.iPreviousCfStatus = aCurrentDivert;
       
   605     divertNotify.iCfActivated = aDivertChanged;
       
   606     
       
   607     divertNotify.iBasicServiceCode = aBasic;
       
   608 
       
   609     if ( aVoiceMbxDivert )
       
   610         {
       
   611         divertNotify.iVmbxDivert = ETrue;
       
   612         }
       
   613                
       
   614     return divertNotify;
       
   615     }
       
   616 
       
   617 // ---------------------------------------------------------------------------
       
   618 // Gets Als information
       
   619 // ---------------------------------------------------------------------------
       
   620 //
       
   621 TSelectedLine CPSetCallDivertingBase::GetSAAls()
       
   622     {
       
   623     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::GetSAAls" );
       
   624     __PHSLOGSTRING2("[PHS] iAls: %d iBsc: %d", iAls, iBsc  );
       
   625     TSelectedLine alsValue = ENotSupportedLine;
       
   626     switch ( iAls )
       
   627         {
       
   628         case ESSSettingsAlsNotSupported:
       
   629             alsValue = ENotSupportedLine;
       
   630             break;
       
   631         case ESSSettingsAlsPrimary:
       
   632             iChangeInfo.iServiceGroup == RMobilePhone::EAuxVoiceService 
       
   633                 ? ( alsValue = EAuxiliaryLine )  
       
   634                 : ( alsValue = EPrimaryLine );
       
   635             break;
       
   636         case ESSSettingsAlsAlternate:
       
   637             alsValue = EAuxiliaryLine;
       
   638             break;
       
   639         default:
       
   640             alsValue = ENotSupportedLine;
       
   641             break;
       
   642         }
       
   643     
       
   644     // If user checks/activates divert to line which is not selected currently than we have
       
   645     // to change returned alsvalue accordinly, if this is not done divert icon status is updated to wrong status.
       
   646     // Example case: Line 2 active user activates divert to line 1: **21*phonenumber*11#.
       
   647     if ( iBsc == EAltTele && iAls == ESSSettingsAlsPrimary )
       
   648         {
       
   649         __PHSLOGSTRING("[PHS]    CPSetCallDivertingBase::GetSAAls - Line 2 divert activation/check from Line 1" );
       
   650         alsValue = EAuxiliaryLine;
       
   651         }
       
   652     else if ( iBsc == ETelephony && iAls == ESSSettingsAlsAlternate )
       
   653         {
       
   654         __PHSLOGSTRING("[PHS]    CPSetCallDivertingBase::GetSAAls - Line 1 divert activation/check from Line 2" );
       
   655         alsValue = EPrimaryLine;
       
   656         }
       
   657     
       
   658     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::GetSAAls: alsValue: %d", alsValue );
       
   659     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::GetSAAls" );
       
   660     return alsValue;
       
   661     }
       
   662 
       
   663 // ---------------------------------------------------------------------------
       
   664 // Validates used bsc, if EUnknown, updates to real value
       
   665 // ---------------------------------------------------------------------------
       
   666 //
       
   667 void CPSetCallDivertingBase::ValidateBsc( TBasicServiceGroups& aBsc )
       
   668     {
       
   669     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::ValidateBsc" );
       
   670     if ( aBsc == EUnknown )
       
   671     // if bsc is unknown, update it
       
   672         {
       
   673         if ( iAls == ESSSettingsAlsAlternate )
       
   674             {
       
   675             aBsc = EAltTele;
       
   676             }
       
   677         else
       
   678             {
       
   679             aBsc = ETelephony;
       
   680             }
       
   681         }    
       
   682     else
       
   683     // If no specific line is indicated
       
   684         {
       
   685         if ( aBsc == EAllTeleAndBearer ||
       
   686              aBsc == EAllTele )
       
   687             {
       
   688             // if ALS is used, use 89 bsc
       
   689             if ( iAls == ESSSettingsAlsAlternate )
       
   690                 {
       
   691                 aBsc = EAltTele;
       
   692                 }
       
   693             }
       
   694         }
       
   695     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::ValidateBsc" );
       
   696     }
       
   697 
       
   698 // ---------------------------------------------------------------------------
       
   699 // Starts requesting
       
   700 // ---------------------------------------------------------------------------
       
   701 //
       
   702 void CPSetCallDivertingBase::StartRequestingL( const TInt& aRequest )
       
   703     {
       
   704     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::StartRequestingL" );
       
   705     if ( aRequest != KPsetRequestAlreadySet )
       
   706         {
       
   707         SetRequestStatus( static_cast <TPSetDivertRequest> ( aRequest ) );
       
   708         }
       
   709     
       
   710     SetActive();
       
   711 
       
   712     iObserver->SetEngineContact( iDivert );
       
   713 
       
   714     CleanupLeavePushL();    
       
   715     iObserver->HandleCFRequestingL( ETrue, EFalse );
       
   716     CleanupStack::Pop(); // CleanupCancelPushL
       
   717     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::StartRequestingL" );
       
   718     }
       
   719 
       
   720 // ---------------------------------------------------------------------------
       
   721 // Inform request observer that request status has changed.
       
   722 // ---------------------------------------------------------------------------
       
   723 //
       
   724 void CPSetCallDivertingBase::SetRequestStatus( TPSetDivertRequest aStatus )
       
   725     {
       
   726     iCurrentReq = aStatus;
       
   727     if ( iReqObserver )
       
   728         {
       
   729         iReqObserver->RequestStatusChanged( aStatus );
       
   730         }
       
   731     }
       
   732 
       
   733 // ---------------------------------------------------------------------------
       
   734 // If divert activation/cancellation/etc. affects more than one bsc, 
       
   735 //  inform PSUI about it.
       
   736 // ---------------------------------------------------------------------------
       
   737 TBool CPSetCallDivertingBase::IsMultiAffectingDivert( 
       
   738     const TCallDivertSetting& aDivert, TBasicServiceGroups aBsc )
       
   739     {
       
   740     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::IsMultiAffectingDivert" );
       
   741     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::IsMultiAffectingDivert: aBsc = %d", aBsc );
       
   742     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::IsMultiAffectingDivert: aDivert.iCondition = %d", aDivert.iCondition );
       
   743     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::IsMultiAffectingDivert: aDivert.iStatus = %d", aDivert.iStatus );
       
   744     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBase::IsMultiAffectingDivert: aDivert.iServiceGroup = %d", aDivert.iServiceGroup );
       
   745 
       
   746     if ( iReason == RMobilePhone::ECallForwardingAllCases ||
       
   747          iReason == RMobilePhone::ECallForwardingAllConditionalCases ||
       
   748          iReason == RMobilePhone::ECallForwardingNotReachable )
       
   749         {
       
   750         __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::IsMultiAffectingDivert1" );
       
   751          return ETrue;
       
   752         }
       
   753     if ( iReason == RMobilePhone::ECallForwardingUnconditional )
       
   754         {
       
   755         //it is a MMI string
       
   756         if ( ( aBsc != EUnknown && aBsc != ETelephony ) && aDivert.iServiceGroup == EServiceGroupVoice ) 
       
   757             {
       
   758             __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::IsMultiAffectingDivert2" );
       
   759             return ETrue;
       
   760             }
       
   761         }
       
   762     
       
   763     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::IsMultiAffectingDivert3" );
       
   764     return EFalse;
       
   765     }
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // Push object into cleanupstack to catch leaving.
       
   769 // ---------------------------------------------------------------------------
       
   770 //
       
   771 void CPSetCallDivertingBase::CleanupLeavePushL()
       
   772       {
       
   773       CleanupStack::PushL( TCleanupItem( DoHandleLeave, this ) );
       
   774       }
       
   775 
       
   776 // ---------------------------------------------------------------------------
       
   777 // Object has caused a leave.
       
   778 // ---------------------------------------------------------------------------
       
   779 //
       
   780 void CPSetCallDivertingBase::DoHandleLeave( TAny* aAny )
       
   781       {
       
   782       REINTERPRET_CAST( CPSetCallDivertingBasicImpl*, aAny )->HandleLeave();
       
   783       }
       
   784 
       
   785 // ---------------------------------------------------------------------------
       
   786 // Things to do when leave occurs.
       
   787 // ---------------------------------------------------------------------------
       
   788 //
       
   789 void CPSetCallDivertingBase::HandleLeave()
       
   790     {
       
   791     CancelCurrentRequest();
       
   792     }
       
   793 
       
   794 // ---------------------------------------------------------------------------
       
   795 // Inform the request observer that request has been completed.
       
   796 // ---------------------------------------------------------------------------
       
   797 //
       
   798 void CPSetCallDivertingBase::RequestCompleted( const TInt& aError )
       
   799     {
       
   800     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::RequestCompleted" );
       
   801     if ( aError != KErrNone )
       
   802         {
       
   803         SetRequestStatus( static_cast <TPSetDivertRequest> (aError) );
       
   804         }
       
   805     SetRequestStatus( EPSetNone );    
       
   806     iVoiceDivert = EFalse;
       
   807 
       
   808     if ( iReqObserver )
       
   809         {
       
   810         iReqObserver->RequestComplete(); 
       
   811         }
       
   812     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::RequestCompleted" );
       
   813     }
       
   814 
       
   815 // ---------------------------------------------------------------------------
       
   816 // Verifies whether the divert-to number is to voice mail box.
       
   817 // ---------------------------------------------------------------------------
       
   818 //
       
   819 TBool CPSetCallDivertingBase::IsVMBXDivertL( TDesC& /*aTelNumber*/ )
       
   820     {
       
   821 
       
   822     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBase::IsVMBXDivertL" );
       
   823     
       
   824     TBool result = EFalse;
       
   825     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBase::IsVMBXDivertL" );
       
   826     return result;
       
   827     }
       
   828 
       
   829 // ---------------------------------------------------------------------------
       
   830 // If SsSettings notifies of settings change, copy new value to member variable. 
       
   831 // ---------------------------------------------------------------------------
       
   832 void CPSetCallDivertingBase::PhoneSettingChanged( 
       
   833     TSSSettingsSetting aSetting, TInt aNewValue )
       
   834     {
       
   835     __PHSLOGSTRING2("[PHS]--> CPSetCallDivertingBase::PhoneSettingChanged ESSSettingsAls: %d, aNewValue: %d", aSetting, aNewValue );
       
   836     if ( aSetting == ESSSettingsAls )
       
   837         {
       
   838         iAls = static_cast <TSSSettingsAlsValue> (aNewValue);
       
   839         }
       
   840     __PHSLOGSTRING("[PHS]<-- CPSetCallDivertingBase::PhoneSettingChanged" );
       
   841     }
       
   842 
       
   843 // End of File