phoneapp/phoneuivoipextension/src/cphonecallforwardqueryhandler.cpp
changeset 0 5f000ab63145
child 21 92ab7f8d0eab
child 61 41a7f70b3818
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     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: Implementation of CPhoneCallForwardQueryHandler class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <featmgr.h>
       
    19 #include <StringLoader.h>
       
    20 #include <mpeengineinfo.h>
       
    21 
       
    22 #include "cphonecallforwardqueryhandler.h"
       
    23 #include "cphonelogger.h"
       
    24 #include "mphonestatemachine.h"
       
    25 #include "phonerssvoip.h"
       
    26 #include "phoneappvoipcommands.hrh"
       
    27 #include "cphonestate.h"
       
    28 #include "cphonestateincall.h"
       
    29 #include "tphonecmdparamcustomdialer.h"
       
    30 #include "tphonecmdparaminteger.h"
       
    31 #include "tphonecmdparamstring.h"
       
    32 #include "tphonecmdparamquery.h"
       
    33 #include "tphonecmdparamglobalnote.h"
       
    34 #include "cphonemainresourceresolver.h"
       
    35 #include "cphonestatemachinevoip.h"
       
    36 #include "tphonecmdparamstring.h"
       
    37 
       
    38 
       
    39 
       
    40 // ======== MEMBER FUNCTIONS ========
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CPhoneCallForwardQueryHandler::CPhoneCallForwardQueryHandler
       
    44 // C++ constructor.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CPhoneCallForwardQueryHandler::CPhoneCallForwardQueryHandler( 
       
    48         MPhoneStateMachine& aStateMachine,
       
    49         MPhoneViewCommandHandle& aViewCommandHandle )
       
    50     : iStateMachine( aStateMachine ), 
       
    51       iViewCommandHandle( aViewCommandHandle ),
       
    52       iMultipleChoicesArray( NULL )
       
    53     {
       
    54 
       
    55     }
       
    56 
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CPhoneCallForwardQueryHandler::ConstructL
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CPhoneCallForwardQueryHandler::ConstructL()
       
    63     {
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CPhoneCallForwardQueryHandler::NewL
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CPhoneCallForwardQueryHandler* CPhoneCallForwardQueryHandler::NewL(
       
    72         MPhoneStateMachine& aStateMachine,
       
    73         MPhoneViewCommandHandle& aViewCommandHandle )
       
    74     {
       
    75     CPhoneCallForwardQueryHandler* self = 
       
    76         CPhoneCallForwardQueryHandler::NewLC( 
       
    77             aStateMachine, aViewCommandHandle );
       
    78     CleanupStack::Pop( self );
       
    79     return self;
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CPhoneCallForwardQueryHandler::NewLC
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CPhoneCallForwardQueryHandler* CPhoneCallForwardQueryHandler::NewLC(
       
    88         MPhoneStateMachine& aStateMachine,
       
    89         MPhoneViewCommandHandle& aViewCommandHandle )
       
    90     {
       
    91     CPhoneCallForwardQueryHandler* self = 
       
    92         new( ELeave ) CPhoneCallForwardQueryHandler( 
       
    93             aStateMachine, aViewCommandHandle );
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL();
       
    96     return self;
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CPhoneCallForwardQueryHandler::~CPhoneCallForwardQueryHandler
       
   102 // Destructor.
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CPhoneCallForwardQueryHandler::~CPhoneCallForwardQueryHandler()
       
   106     {
       
   107     delete iMultipleChoicesArray;
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CPhoneCallForwardQueryHandler::ShowMovedPermanentlyQueryL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CPhoneCallForwardQueryHandler::ShowMovedPermanentlyQueryL(
       
   115         TInt aCallId )
       
   116     {
       
   117     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   118         "CPhoneCallForwardQueryHandler::ShowMovedPermanentlyQueryL" )
       
   119         
       
   120     iCallId = aCallId;
       
   121     iAddressArray = iStateMachine.PhoneEngineInfo()->
       
   122         ForwardAddressChoices( aCallId );
       
   123     
       
   124     if ( NULL == iAddressArray )
       
   125         {
       
   126         User::Leave( KErrNotSupported );
       
   127         }
       
   128     
       
   129     iQueryType = EPhoneMovedPermanently;
       
   130     TPhoneCmdParamQuery queryParam;
       
   131     queryParam.SetQueryCommandObserver( *this );
       
   132     queryParam.SetTone( EAvkonSIDInformationTone );
       
   133     queryParam.SetQueryType( EPhoneGlobalQueryDialog );
       
   134   
       
   135     HBufC* queryPrompt = StringLoader::LoadLC( 
       
   136             CPhoneMainResourceResolver::Instance()->ResolveResourceID( 
       
   137                     EPhoneVoIPMovedPermanentlyQueryHeader ));
       
   138    
       
   139     queryParam.SetQueryPrompt( *queryPrompt );
       
   140 
       
   141     queryParam.SetDefaultCba(             
       
   142         CPhoneMainResourceResolver::Instance()->
       
   143             ResolveResourceID( EPhoneVoIPMovedPermanentlySoftkeys ) );
       
   144   
       
   145     iCommandProcessed = EFalse;
       
   146     
       
   147     iViewCommandHandle.ExecuteCommandL( EPhoneViewShowQuery, &queryParam );
       
   148     
       
   149     CleanupStack::PopAndDestroy( queryPrompt );
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CPhoneCallForwardQueryHandler::ShowMultipleChoicesQueryL
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CPhoneCallForwardQueryHandler::ShowMultipleChoicesQueryL(
       
   157         TInt aCallId )
       
   158     {
       
   159     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   160         "CPhoneCallForwardQueryHandler::ShowMultipleChoicesQueryL" )
       
   161         
       
   162     iCallId = aCallId;
       
   163     iAddressArray = iStateMachine.PhoneEngineInfo()->
       
   164         ForwardAddressChoices( aCallId );
       
   165     
       
   166     if ( NULL == iAddressArray )
       
   167         {
       
   168         User::Leave( KErrNotSupported );
       
   169         }
       
   170     
       
   171     ResetMultipleChoicesArrayL( *iAddressArray );
       
   172     
       
   173     iQueryType = EPhoneMultipleChoices;
       
   174     TPhoneCmdParamQuery queryParam;
       
   175     queryParam.SetQueryCommandObserver( *this );
       
   176     queryParam.SetTone( EAvkonSIDInformationTone );
       
   177     queryParam.SetQueryType( EPhoneCustomListQueryDialog );
       
   178     queryParam.SetItemTextArrayForListQuery( 
       
   179             static_cast<MDesCArray&> ( *iMultipleChoicesArray ) );
       
   180 
       
   181     queryParam.SetQueryResourceId( 
       
   182             CPhoneMainResourceResolver::Instance()->ResolveResourceID( 
       
   183                     EPhoneVoIPMultipleChoicesListQuery ) );
       
   184 
       
   185     iCommandProcessed = EFalse;
       
   186     
       
   187     iViewCommandHandle.ExecuteCommandL( EPhoneViewShowQuery, &queryParam );
       
   188     
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // CPhoneCallForwardQueryHandler::AddToContacsL
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CPhoneCallForwardQueryHandler::AddToContacsL(
       
   196         TBool aCreateNew )
       
   197     {
       
   198     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   199         "CPhoneCallForwardQueryHandler::AddToContacsL" )
       
   200     
       
   201     if ( !iAddressArray ||
       
   202           0 == iAddressArray->Count() )
       
   203         {
       
   204         User::Leave( KErrNotFound );
       
   205         }
       
   206         
       
   207     HBufC* buf = HBufC::NewLC( iAddressArray->MdcaPoint(0).Length() );
       
   208     buf->Des().Copy( iAddressArray->MdcaPoint(0) );
       
   209     TPtr ptr( buf->Des() );
       
   210 
       
   211     iCommandProcessed = EFalse;
       
   212     
       
   213     TPhoneCmdParamString stringParam;
       
   214     stringParam.SetString( &ptr );
       
   215     iViewCommandHandle.ExecuteCommandL(
       
   216         aCreateNew ? EPhoneViewAddContactByString :
       
   217                      EPhoneViewUpdateContactByString,
       
   218         &stringParam );   
       
   219     
       
   220     CleanupStack::PopAndDestroy( buf );
       
   221     
       
   222     // Forward call to array index 0
       
   223     ForwardCallToAddressL( 0 );
       
   224     }
       
   225 
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CPhoneCallForwardQueryHandler::SaveAddressToContactsL
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 void CPhoneCallForwardQueryHandler::SaveAddressToContactsL()
       
   232     {
       
   233     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   234        "CPhoneCallForwardQueryHandler::SaveAddressToContactsL" )
       
   235     
       
   236     TPhoneCmdParamQuery queryDialogParam;
       
   237     iQueryType = EPhoneQueryAddToContacts;
       
   238     queryDialogParam.SetQueryCommandObserver( *this );
       
   239     queryDialogParam.SetQueryType( EPhoneContactsListQuery );
       
   240     queryDialogParam.SetQueryResourceId(
       
   241            CPhoneMainResourceResolver::Instance()->
       
   242                ResolveResourceID( EPhoneAddtoContactsListQuery )  );
       
   243     
       
   244     iCommandProcessed = EFalse;
       
   245     
       
   246     // Display dialog        
       
   247     iViewCommandHandle.ExecuteCommandL( EPhoneViewShowQuery,
       
   248        &queryDialogParam );
       
   249        
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // CPhoneCallForwardQueryHandler::ProcessCommandL
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 void CPhoneCallForwardQueryHandler::ProcessCommandL(
       
   257         TInt aCommandId )
       
   258     {
       
   259     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   260        "CPhoneCallForwardQueryHandler::ProcessCommandL" )
       
   261     
       
   262     if ( iCommandProcessed )
       
   263         {
       
   264         return;
       
   265         }
       
   266     
       
   267     iCommandProcessed = ETrue;
       
   268     
       
   269     if ( iQueryType == EPhoneQueryAddToContacts )
       
   270         {
       
   271         switch ( aCommandId )
       
   272             {          
       
   273             case EPhoneNumberAcqCmdSave:
       
   274                 AddToContacsL( ETrue );     
       
   275                 break;
       
   276                 
       
   277             case EPhoneNumberAcqCmdAddToName:
       
   278                 AddToContacsL( EFalse );     
       
   279                 break;
       
   280             case EAknSoftkeyCancel:
       
   281                 iStateMachine.SendPhoneEngineMessage( 
       
   282                         MPEPhoneModel::EPEMessageRelease );     
       
   283                 break;
       
   284             }
       
   285         }
       
   286     else if ( iQueryType == EPhoneMovedPermanently )
       
   287         {
       
   288         switch ( aCommandId )
       
   289             {          
       
   290             case EAknSoftkeyOk:
       
   291                 SaveAddressToContactsL();     
       
   292                 break;
       
   293                 
       
   294             default:
       
   295                 iStateMachine.SendPhoneEngineMessage( 
       
   296                         MPEPhoneModel::EPEMessageRelease );  
       
   297                 break;
       
   298             }
       
   299         }
       
   300     else if ( iQueryType == EPhoneMultipleChoices )
       
   301         {
       
   302         if ( iAddressArray && aCommandId >= 0 && 
       
   303              aCommandId < iAddressArray->MdcaCount() )
       
   304             {
       
   305             ForwardCallToAddressL( aCommandId );
       
   306             }
       
   307         else
       
   308             {
       
   309             iStateMachine.SendPhoneEngineMessage( 
       
   310                     MPEPhoneModel::EPEMessageRelease );
       
   311             }
       
   312         }
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CPhoneCallForwardQueryHandler::ShowCallForwardedNoteL
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 void CPhoneCallForwardQueryHandler::ShowCallForwardedNoteL()
       
   320     {
       
   321     __LOGMETHODSTARTEND(PhoneUIVoIPExtension, 
       
   322             "CPhoneCallForwardQueryHandler::ShowCallForwardedNoteL( ) ");
       
   323    
       
   324     CPhoneState* phoneState = 
       
   325         static_cast< CPhoneState* >( iStateMachine.State() );       
       
   326             
       
   327     phoneState->SendGlobalInfoNoteL( EPhoneRemoteForwarding );
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // CPhoneCallForwardQueryHandler::ResetMultipleChoicesArrayL
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CPhoneCallForwardQueryHandler::ResetMultipleChoicesArrayL(
       
   335         const MDesC8Array& aAddressArray )
       
   336     {
       
   337     __LOGMETHODSTARTEND(PhoneUIVoIPExtension, 
       
   338             "CPhoneCallForwardQueryHandler::ResetMultipleChoicesArrayL( ) ");
       
   339    
       
   340     delete iMultipleChoicesArray;
       
   341     iMultipleChoicesArray = NULL;
       
   342     
       
   343     iMultipleChoicesArray = 
       
   344         new(ELeave) CDesC16ArrayFlat( aAddressArray.MdcaCount() );
       
   345     
       
   346     for ( TInt i=0; i< aAddressArray.MdcaCount() ; i++ )
       
   347         {
       
   348         HBufC* buf = HBufC::NewLC( aAddressArray.MdcaPoint(i).Length() );
       
   349         buf->Des().Copy( aAddressArray.MdcaPoint(i) );
       
   350         iMultipleChoicesArray->AppendL( *buf );
       
   351         CleanupStack::PopAndDestroy( buf );
       
   352         }
       
   353     }
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // CPhoneCallForwardQueryHandler::ForwardCallToAddressL
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 void CPhoneCallForwardQueryHandler::ForwardCallToAddressL(
       
   360         TInt aIndex )
       
   361     {
       
   362     __LOGMETHODSTARTEND(PhoneUIVoIPExtension, 
       
   363             "CPhoneCallForwardQueryHandler::ForwardCallToAddressL( ) ");
       
   364    
       
   365     ShowCallForwardedNoteL();
       
   366     iStateMachine.PhoneEngineInfo()->SetForwardAddressIndex( aIndex );
       
   367     iStateMachine.SendPhoneEngineMessage( 
       
   368             MPEPhoneModel::EPEMessageForwardCallToAddress );
       
   369     }
       
   370 
       
   371 // End of File