phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/src/CNumberMatchOperation.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002-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:  A command that finds the contacts that matches to given number
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CNumberMatchOperation.h"
       
    22 
       
    23 #include <VPbkPhoneNumberIndex.h>
       
    24 #include "CVPbkSimContact.h"
       
    25 #include "CVPbkSimCntField.h"
       
    26 #include "CSimPhoneNumberIndex.h"
       
    27 #include "RVPbkStreamedIntArray.h"
       
    28 #include "MVPbkSimFindObserver.h"
       
    29 #include "MVPbkSimCommandObserver.h"
       
    30 
       
    31 namespace VPbkSimStoreImpl {
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CNumberMatchOperation::CNumberMatchOperation
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CNumberMatchOperation::CNumberMatchOperation( MVPbkSimFindObserver& aObserver,
       
    42     CSimPhoneNumberIndex& aSimPhoneNumberIndex, TInt aNumDigits, 
       
    43     MVPbkSimCntStore& aStore )
       
    44     :   CActive( EPriorityStandard ),
       
    45         iObserver( aObserver ),
       
    46         iNumberIndex( aSimPhoneNumberIndex ),
       
    47         iNumDigits( aNumDigits ),
       
    48         iStore( aStore )
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CNumberMatchOperation::ConstructL
       
    54 // Symbian 2nd phase constructor can leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CNumberMatchOperation::ConstructL( const TDesC& aPhoneNumber )
       
    58     {
       
    59     CActiveScheduler::Add( this );
       
    60     iPhoneNumber = aPhoneNumber.Right( iNumDigits ).AllocL();
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CNumberMatchOperation::NewL
       
    65 // Two-phased constructor.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CNumberMatchOperation* CNumberMatchOperation::NewL( MVPbkSimFindObserver& aObserver,
       
    69     CSimPhoneNumberIndex& aSimPhoneNumberIndex,
       
    70     const TDesC& aPhoneNumber, TInt aNumDigits, MVPbkSimCntStore& aStore )
       
    71     {
       
    72     CNumberMatchOperation* self = new( ELeave ) CNumberMatchOperation( aObserver, 
       
    73         aSimPhoneNumberIndex, aNumDigits, aStore );
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL( aPhoneNumber );
       
    76     CleanupStack::Pop( self );
       
    77     return self;
       
    78     }
       
    79 
       
    80 // Destructor
       
    81 CNumberMatchOperation::~CNumberMatchOperation()
       
    82     {
       
    83     delete iPhoneNumber;
       
    84     Cancel();
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CNumberMatchOperation::RunL
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CNumberMatchOperation::RunL()
       
    92     {
       
    93     VPbkEngUtils::RPhoneNumberLookup<MVPbkSimContact>lookup = 
       
    94         iNumberIndex.Index().StartLookupL( *iPhoneNumber, iNumDigits );
       
    95     CleanupClosePushL( lookup );
       
    96 
       
    97     RVPbkStreamedIntArray indexArray;
       
    98     CleanupClosePushL( indexArray );
       
    99     
       
   100     while ( !lookup.AtEnd() )
       
   101         {
       
   102         MVPbkSimContact& cnt = lookup.Current();
       
   103         TInt simIndex = cnt.SimIndex();
       
   104         if ( indexArray.Find( simIndex ) == KErrNotFound )
       
   105             {
       
   106             // Add sim index only if it hasn't been added
       
   107             indexArray.AppendIntL( simIndex );
       
   108             }
       
   109         iNumberIndex.Index().LookupNext( lookup );
       
   110         }
       
   111     iObserver.FindCompleted( iStore, indexArray );
       
   112     CleanupStack::PopAndDestroy(2); // indexArray, lookup
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CNumberMatchOperation::DoCancel
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CNumberMatchOperation::DoCancel()
       
   120     {
       
   121     // Nothing to cancel here
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CNumberMatchOperation::RunError
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 TInt CNumberMatchOperation::RunError( TInt aError )
       
   129     {
       
   130     iObserver.FindError( iStore, aError );
       
   131     return KErrNone;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CNumberMatchOperation::Execute
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CNumberMatchOperation::Execute()
       
   139     {
       
   140     TRequestStatus* status = &iStatus;
       
   141     User::RequestComplete( status, KErrNone );
       
   142     SetActive();
       
   143     }
       
   144 } // namespace VPbkSimStoreImpl
       
   145 //  End of File