phonebookui/Phonebook2/USIMExtension/src/CPsu2FixedDialingCall.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Phonebook 2 USIM UI Extension FDN call implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPsu2FixedDialingCall.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPsu2NumberQueryDlg.h"
       
    24 #include <CPbk2FieldPropertyArray.h>
       
    25 #include <MPbk2FieldProperty.h>
       
    26 #include <Pbk2UIControls.rsg>
       
    27 #include <MPbk2CommandHandler.h>
       
    28 #include <CPbk2AppViewBase.h>
       
    29 #include <CPbk2ContactUiControlSubstitute.h>
       
    30 
       
    31 // Virtual Phonebook
       
    32 #include <CVPbkContactManager.h>
       
    33 #include <MVPbkContactStore.h>
       
    34 #include <MVPbkStoreContact.h>
       
    35 #include <MVPbkContactFieldData.h>
       
    36 #include <MVPbkContactFieldTextData.h>
       
    37 #include <CVPbkFieldTypeSelector.h>
       
    38 #include <MVPbkContactOperationBase.h>
       
    39 #include <MVPbkContactLink.h>
       
    40 #include <MVPbkFieldType.h>
       
    41 #include <MVPbkContactStoreProperties.h>
       
    42 
       
    43 // System includes
       
    44 #include <StringLoader.h>
       
    45 #include <eikmenup.h>
       
    46 #include <barsread.h>
       
    47 
       
    48 /// Unnamed namespace for local definitions
       
    49 namespace {
       
    50 
       
    51 const TInt KMaxNumberLength = 52;
       
    52 
       
    53 /**
       
    54  * Checks is the given field type included in
       
    55  * the given selection.
       
    56  *
       
    57  * @param aResourceId   Selector's resource id.
       
    58  * @param aFieldType    The field type to check.
       
    59  * @param aManager      Virtual Phonebook contact manager.
       
    60  * @return  ETrue if field type is included.
       
    61  */
       
    62 TBool IsFieldTypeIncludedL(
       
    63         const MVPbkFieldType& aFieldType,
       
    64         const CVPbkContactManager& aManager,
       
    65         const TInt aResourceId )
       
    66     {
       
    67     // Get the field type
       
    68     TResourceReader resReader;
       
    69     CCoeEnv::Static()->CreateResourceReaderLC
       
    70         (resReader, aResourceId);
       
    71 
       
    72     CVPbkFieldTypeSelector* selector =
       
    73         CVPbkFieldTypeSelector::NewL(resReader, aManager.FieldTypes());
       
    74     CleanupStack::PopAndDestroy(); // resReader
       
    75 
       
    76     TBool ret = selector->IsFieldTypeIncluded(aFieldType);
       
    77     delete selector;
       
    78     return ret;
       
    79     }
       
    80 
       
    81 } /// namespace
       
    82 
       
    83 // --------------------------------------------------------------------------
       
    84 // CPsu2FixedDialingCall::CPsu2FixedDialingCall
       
    85 // --------------------------------------------------------------------------
       
    86 //
       
    87 CPsu2FixedDialingCall::CPsu2FixedDialingCall
       
    88         ( CVPbkContactManager& aContactManager,
       
    89           MPbk2CommandHandler& aCommandHandler,
       
    90           CPbk2AppViewBase& aAppViewBase ) :
       
    91             CActive(EPriorityStandard),
       
    92             iContactManager( aContactManager ),
       
    93             iCommandHandler( aCommandHandler ),
       
    94             iAppViewBase( aAppViewBase )
       
    95     {
       
    96     }
       
    97 
       
    98 // --------------------------------------------------------------------------
       
    99 // CPsu2FixedDialingCall::~CPsu2FixedDialingCall
       
   100 // --------------------------------------------------------------------------
       
   101 //
       
   102 CPsu2FixedDialingCall::~CPsu2FixedDialingCall()
       
   103     {
       
   104     Cancel();
       
   105     delete iUiControlSubstitute;
       
   106     delete iRetrieveOperation;
       
   107     delete iTempContact;
       
   108     delete iStoreContact;
       
   109     delete iContactLink;
       
   110     }
       
   111 
       
   112 // --------------------------------------------------------------------------
       
   113 // CPsu2FixedDialingCall::NewL
       
   114 // --------------------------------------------------------------------------
       
   115 //
       
   116 CPsu2FixedDialingCall* CPsu2FixedDialingCall::NewL(
       
   117         CVPbkContactManager& aContactManager,
       
   118         MPbk2CommandHandler& aCommandHandler,
       
   119         CPbk2AppViewBase& aAppViewBase )
       
   120     {
       
   121     CPsu2FixedDialingCall* self = new ( ELeave ) CPsu2FixedDialingCall
       
   122         ( aContactManager, aCommandHandler, aAppViewBase );
       
   123     CleanupStack::PushL( self );
       
   124     self->ConstructL();
       
   125     CleanupStack::Pop( self );
       
   126     return self;
       
   127     }
       
   128 
       
   129 // --------------------------------------------------------------------------
       
   130 // CPsu2FixedDialingCall::ConstructL
       
   131 // --------------------------------------------------------------------------
       
   132 //
       
   133 void CPsu2FixedDialingCall::ConstructL()
       
   134     {
       
   135     CActiveScheduler::Add(this);
       
   136 
       
   137     iUiControlSubstitute = CPbk2ContactUiControlSubstitute::NewL();
       
   138     }
       
   139 
       
   140 // --------------------------------------------------------------------------
       
   141 // CPsu2FixedDialingCall::CreateCallL
       
   142 // --------------------------------------------------------------------------
       
   143 //
       
   144 void CPsu2FixedDialingCall::CreateCallL
       
   145         ( MVPbkContactLink* aContactLink, TInt aCommand  )
       
   146     {
       
   147     iCommand = aCommand;
       
   148     iContactLink = aContactLink;
       
   149 
       
   150     // Load contact
       
   151     delete iRetrieveOperation;
       
   152     iRetrieveOperation = NULL;
       
   153     iRetrieveOperation = iContactManager.RetrieveContactL
       
   154         ( *iContactLink, *this );
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // CPsu2FixedDialingCall::RunL
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 void CPsu2FixedDialingCall::RunL()
       
   162     {
       
   163     NumberQueryL();
       
   164     }
       
   165 
       
   166 // --------------------------------------------------------------------------
       
   167 // CPsu2FixedDialingCall::DoCancel
       
   168 // --------------------------------------------------------------------------
       
   169 //
       
   170 void CPsu2FixedDialingCall::DoCancel()
       
   171     {
       
   172     // Nothing to do here
       
   173     }
       
   174 
       
   175 // --------------------------------------------------------------------------
       
   176 // CPsu2FixedDialingCall::RunError
       
   177 // --------------------------------------------------------------------------
       
   178 //
       
   179 TInt CPsu2FixedDialingCall::RunError(TInt aError)
       
   180     {
       
   181     CCoeEnv::Static()->HandleError(aError);
       
   182     return KErrNone;
       
   183     }
       
   184 
       
   185 // --------------------------------------------------------------------------
       
   186 // CPsu2FixedDialingCall::VPbkSingleContactOperationComplete
       
   187 // --------------------------------------------------------------------------
       
   188 //
       
   189 void CPsu2FixedDialingCall::VPbkSingleContactOperationComplete(
       
   190         MVPbkContactOperationBase& /*aOperation*/,
       
   191         MVPbkStoreContact* aContact)
       
   192     {
       
   193     delete iRetrieveOperation;
       
   194     iRetrieveOperation = NULL;
       
   195 
       
   196     delete iStoreContact;
       
   197     iStoreContact = aContact;
       
   198 
       
   199     IssueRequest();
       
   200     }
       
   201 
       
   202 // --------------------------------------------------------------------------
       
   203 // CPsu2FixedDialingCall::VPbkSingleContactOperationFailed
       
   204 // --------------------------------------------------------------------------
       
   205 //
       
   206 void CPsu2FixedDialingCall::VPbkSingleContactOperationFailed
       
   207         ( MVPbkContactOperationBase& /*aOperation*/, TInt /*aError*/ )
       
   208     {
       
   209     delete iRetrieveOperation;
       
   210     iRetrieveOperation = NULL;
       
   211     }
       
   212 
       
   213 // --------------------------------------------------------------------------
       
   214 // CPsu2FixedDialingCall::ContactTextDataL
       
   215 // --------------------------------------------------------------------------
       
   216 //
       
   217 const TPtrC CPsu2FixedDialingCall::ContactTextDataL
       
   218         ( MVPbkStoreContact& aContact, TInt aSelectorResourceId )
       
   219     {
       
   220     MVPbkStoreContactFieldCollection& fields = aContact.Fields();
       
   221     TInt count( fields.FieldCount() );
       
   222     for (TInt index(0); index < count; ++index )
       
   223         {
       
   224         MVPbkStoreContactField& field = fields.FieldAt( index );
       
   225         if ( IsFieldTypeIncludedL( *field.BestMatchingFieldType(),
       
   226                    iContactManager, aSelectorResourceId ) )
       
   227             {
       
   228             return MVPbkContactFieldTextData::Cast
       
   229                 ( field.FieldData() ).Text();
       
   230             }
       
   231         }
       
   232     return KNullDesC();
       
   233     }
       
   234 
       
   235 // --------------------------------------------------------------------------
       
   236 // CPsu2FixedDialingCall::ContactDataTypeL
       
   237 // --------------------------------------------------------------------------
       
   238 //
       
   239 const MVPbkFieldType* CPsu2FixedDialingCall::ContactDataTypeL
       
   240     (  const MVPbkFieldTypeList& aFieldTypeList, TInt aSelectorResourceId )
       
   241     {
       
   242     TInt count( aFieldTypeList.FieldTypeCount() );
       
   243     for (TInt index(0); index < count; ++index )
       
   244         {
       
   245         const MVPbkFieldType& fieldType =
       
   246             aFieldTypeList.FieldTypeAt( index );
       
   247         if ( IsFieldTypeIncludedL
       
   248                 ( fieldType, iContactManager, aSelectorResourceId ) )
       
   249             {
       
   250             return &fieldType;
       
   251             }
       
   252         }
       
   253     return NULL;
       
   254     }
       
   255 
       
   256 // --------------------------------------------------------------------------
       
   257 // CPsu2FixedDialingCall::IssueRequest
       
   258 // --------------------------------------------------------------------------
       
   259 //
       
   260 void CPsu2FixedDialingCall::IssueRequest()
       
   261     {
       
   262     if ( !IsActive() )
       
   263         {
       
   264         TRequestStatus* status = &iStatus;
       
   265         User::RequestComplete( status, KErrNone );
       
   266         SetActive();        
       
   267         }
       
   268     }
       
   269 
       
   270 // --------------------------------------------------------------------------
       
   271 // CPsu2FixedDialingCall::NumberQueryL
       
   272 // --------------------------------------------------------------------------
       
   273 //
       
   274 void CPsu2FixedDialingCall::NumberQueryL()
       
   275     {
       
   276     HBufC* buf = HBufC::NewLC( KMaxNumberLength );
       
   277     TPtr numberPtr( buf->Des() );
       
   278     CPsu2NumberQueryDlg* dlg = CPsu2NumberQueryDlg::NewL(
       
   279         ContactTextDataL( *iStoreContact,
       
   280             R_PHONEBOOK2_PHONENUMBER_SELECTOR ),
       
   281                 numberPtr );
       
   282 
       
   283     if ( dlg->ExecuteLD() )
       
   284         {
       
   285         // Create temporary contact for phone call
       
   286         MVPbkContactStore& store = iStoreContact->ParentStore();
       
   287         delete iTempContact;
       
   288         iTempContact = NULL;
       
   289         iTempContact = store.CreateNewContactLC();
       
   290         CleanupStack::Pop(); // iTempContact
       
   291 
       
   292         const MVPbkFieldTypeList& fieldTypeList =
       
   293             store.StoreProperties().SupportedFields();
       
   294 
       
   295         // Copy contact name
       
   296         const MVPbkFieldType* fieldType = ContactDataTypeL( fieldTypeList,
       
   297                 R_PHONEBOOK2_LAST_NAME_SELECTOR );
       
   298         if ( fieldType )
       
   299             {
       
   300             MVPbkStoreContactField* tempNameField = iTempContact->CreateFieldLC(
       
   301                 *fieldType );
       
   302             TPtrC namePtr( ContactTextDataL
       
   303                 ( *iStoreContact, R_PHONEBOOK2_LAST_NAME_SELECTOR ) );
       
   304             MVPbkContactFieldTextData::Cast
       
   305                 ( tempNameField->FieldData() ).SetTextL(namePtr );
       
   306             iTempContact->AddFieldL( tempNameField ); // takes ownership
       
   307             CleanupStack::Pop(); // tempNameField            
       
   308             }
       
   309 
       
   310         // Copy phone number
       
   311         fieldType =  NULL;
       
   312         fieldType = ContactDataTypeL
       
   313                 ( fieldTypeList, R_PHONEBOOK2_PHONENUMBER_SELECTOR );
       
   314         MVPbkStoreContactField* tempNumberField = NULL;
       
   315         TInt tempNumberFieldIndex = KErrNotFound;
       
   316         if ( fieldType )
       
   317             {
       
   318             tempNumberField =
       
   319                 iTempContact->CreateFieldLC( *fieldType );
       
   320             MVPbkContactFieldTextData::Cast
       
   321                 ( tempNumberField->FieldData() ).SetTextL( numberPtr );
       
   322             tempNumberFieldIndex =
       
   323                 iTempContact->AddFieldL(tempNumberField); // takes ownership
       
   324             CleanupStack::Pop(); // tempNumberField
       
   325             tempNumberField = NULL;            
       
   326             tempNumberField = &iTempContact->Fields().FieldAt
       
   327                 ( tempNumberFieldIndex );
       
   328             }
       
   329             
       
   330         iUiControlSubstitute->SetFocusedStoreContact( *iTempContact );
       
   331         iUiControlSubstitute->SetFocusedField( *tempNumberField );
       
   332         iUiControlSubstitute->SetFocusedFieldIndex( tempNumberFieldIndex );
       
   333 
       
   334         iCommandHandler.HandleCommandL
       
   335             ( iCommand, *iUiControlSubstitute, &iAppViewBase );
       
   336         }
       
   337 
       
   338     CleanupStack::PopAndDestroy( buf );
       
   339     }
       
   340 
       
   341 //  End of File