phonebookengines/VirtualPhonebook/VPbkSimStore/src/CMatchPhoneNumberOperation.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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:  An operation for number matching
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CMatchPhoneNumberOperation.h"
       
    22 
       
    23 #include <MVPbkContactFindObserver.h>
       
    24 #include <MVPbkSimStoreOperation.h>
       
    25 #include <CVPbkContactLinkArray.h>
       
    26 #include "CContactStore.h"
       
    27 #include "CRemoteStore.h"
       
    28 #include "CContactLink.h"
       
    29 
       
    30 namespace VPbkSimStore {
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CMatchPhoneNumberOperation::CMatchPhoneNumberOperation
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CMatchPhoneNumberOperation::CMatchPhoneNumberOperation( 
       
    41     TInt aMaxMatchDigits, MVPbkContactFindObserver& aObserver, 
       
    42     CContactStore& aStore )
       
    43     :   iMaxMatchDigits( aMaxMatchDigits ),
       
    44         iObserver( aObserver ),
       
    45         iStore( aStore )
       
    46     {
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CMatchPhoneNumberOperation::ConstructL
       
    51 // Symbian 2nd phase constructor can leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CMatchPhoneNumberOperation::ConstructL( const TDesC& aPhoneNumber )
       
    55     {
       
    56     iPhoneNumber = aPhoneNumber.AllocL();
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CMatchPhoneNumberOperation::NewL
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CMatchPhoneNumberOperation* CMatchPhoneNumberOperation::NewL( 
       
    65         const TDesC& aPhoneNumber, 
       
    66         TInt aMaxMatchDigits,
       
    67         MVPbkContactFindObserver& aObserver,
       
    68         CContactStore& aStore )
       
    69     {
       
    70     CMatchPhoneNumberOperation* self = 
       
    71         new( ELeave ) CMatchPhoneNumberOperation( aMaxMatchDigits, 
       
    72             aObserver, aStore );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL( aPhoneNumber );
       
    75     CleanupStack::Pop( self );
       
    76     return self;
       
    77     }
       
    78 
       
    79 // Destructor
       
    80 CMatchPhoneNumberOperation::~CMatchPhoneNumberOperation()
       
    81     {       
       
    82     delete iSimOperation;
       
    83     delete iPhoneNumber;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMatchPhoneNumberOperation::StartL
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CMatchPhoneNumberOperation::StartL()
       
    91     {
       
    92     iSimOperation = iStore.NativeStore().CreateMatchPhoneNumberOperationL( 
       
    93         *iPhoneNumber, iMaxMatchDigits, *this );
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CMatchPhoneNumberOperation::Cancel
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CMatchPhoneNumberOperation::Cancel()
       
   101     {
       
   102     delete iSimOperation;
       
   103     iSimOperation = NULL;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CMatchPhoneNumberOperation::FindCompleted
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CMatchPhoneNumberOperation::FindCompleted( MVPbkSimCntStore& /*aStore*/,
       
   111     const RVPbkStreamedIntArray& aSimIndexArray )
       
   112     {
       
   113     TRAPD( res, HandleFindCompletedL( aSimIndexArray ) );
       
   114     if ( res != KErrNone )
       
   115         {
       
   116         iObserver.FindFailed( res );
       
   117         }
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CMatchPhoneNumberOperation::FindError
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CMatchPhoneNumberOperation::FindError( MVPbkSimCntStore& /*aStore*/, 
       
   125     TInt aError )
       
   126     {
       
   127     iObserver.FindFailed( aError );
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CMatchPhoneNumberOperation::HandleFindCompletedL
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CMatchPhoneNumberOperation::HandleFindCompletedL( 
       
   135     const RVPbkStreamedIntArray& aSimIndexArray )
       
   136     {
       
   137     CVPbkContactLinkArray* linkArray = NULL;
       
   138     const TInt count = aSimIndexArray.Count();
       
   139     if ( count > 0 )
       
   140         {
       
   141         linkArray = CVPbkContactLinkArray::NewLC();
       
   142         for ( TInt i = 0; i < count; ++i )
       
   143             {
       
   144             CContactLink* link = 
       
   145                 CContactLink::NewLC( iStore, aSimIndexArray[i] );
       
   146             linkArray->AppendL( link );
       
   147             CleanupStack::Pop( link );
       
   148             }
       
   149         }
       
   150     
       
   151     // Pop before transferring ownership to the client.
       
   152     if ( linkArray )
       
   153         {
       
   154         CleanupStack::Pop( linkArray );
       
   155         }
       
   156         
       
   157     iObserver.FindCompleteL( linkArray );
       
   158     }
       
   159 } // namespace VPbkSimStore
       
   160 //  End of File