phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/src/CSimPhoneNumberIndex.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:  An index for sim phone numbers
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CSimPhoneNumberIndex.h"
       
    22 
       
    23 #include <VPbkPhoneNumberIndex.h>
       
    24 #include "MVPbkSimContact.h"
       
    25 #include "CVPbkSimCntField.h"
       
    26 #include "CStoreBase.h"
       
    27 
       
    28 namespace VPbkSimStoreImpl {
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CSimPhoneNumberIndex::CSimPhoneNumberIndex
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CSimPhoneNumberIndex::CSimPhoneNumberIndex( CStoreBase& aParentStore )
       
    39 :   iParentStore( aParentStore )
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CSimPhoneNumberIndex::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CSimPhoneNumberIndex::ConstructL()
       
    49     {
       
    50     iNumberIndex = 
       
    51         VPbkEngUtils::CPhoneNumberIndex<MVPbkSimContact>::NewL();
       
    52     ResetAndBuildIndexL();
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CSimPhoneNumberIndex::NewL
       
    57 // Two-phased constructor.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CSimPhoneNumberIndex* CSimPhoneNumberIndex::NewL( CStoreBase& aParentStore )
       
    61     {
       
    62     CSimPhoneNumberIndex* self = 
       
    63         new( ELeave ) CSimPhoneNumberIndex( aParentStore );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70     
       
    71 // Destructor
       
    72 CSimPhoneNumberIndex::~CSimPhoneNumberIndex()
       
    73     {
       
    74     delete iNumberIndex;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CSimPhoneNumberIndex::ContactAdded
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CSimPhoneNumberIndex::ContactAdded( MVPbkSimContact& aSimContact )
       
    82     {
       
    83     /// There is no one to notify in error case. The worst case here is that
       
    84     /// index will not be updated if there is no memory and clients possibly
       
    85     /// miss a match
       
    86     TRAP_IGNORE( AppendNumbersL( aSimContact ) );
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CSimPhoneNumberIndex::ContactRemoved
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CSimPhoneNumberIndex::ContactRemoved( MVPbkSimContact& aSimContact )
       
    94     {
       
    95     iNumberIndex->RemoveAll( aSimContact );
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CSimPhoneNumberIndex::ContactChanged
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CSimPhoneNumberIndex::ContactChanged( MVPbkSimContact& aOldContact,
       
   103     MVPbkSimContact& aNewContact )
       
   104     {
       
   105     ContactRemoved( aOldContact );
       
   106     ContactAdded( aNewContact );
       
   107     }
       
   108     
       
   109 // -----------------------------------------------------------------------------
       
   110 // CSimPhoneNumberIndex::ReBuildL
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CSimPhoneNumberIndex::ReBuildL()
       
   114     {
       
   115     ResetAndBuildIndexL();
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CSimPhoneNumberIndex::ResetAndBuildIndexL
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CSimPhoneNumberIndex::ResetAndBuildIndexL()
       
   123     {
       
   124     iNumberIndex->Reset();
       
   125     CContactArray& contacts = iParentStore.Contacts();
       
   126     const TInt count = contacts.Size();
       
   127     for ( TInt i = 1; i <= count; ++i )
       
   128         {
       
   129         MVPbkSimContact* cnt = contacts.At( i );
       
   130         if ( cnt )
       
   131             {
       
   132             AppendNumbersL( *cnt );
       
   133             }
       
   134         }
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CSimPhoneNumberIndex::AppendNumbersL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CSimPhoneNumberIndex::AppendNumbersL( MVPbkSimContact& aContact )
       
   142     {
       
   143     MVPbkSimContact::TFieldLookup lookup = 
       
   144         aContact.FindField( EVPbkSimGsmNumber );
       
   145     if ( !lookup.EndOfLookup() )
       
   146         {
       
   147         iNumberIndex->AddL( aContact.ConstFieldAt( lookup.Index() ).Data(), 
       
   148             aContact );
       
   149         }
       
   150     lookup = aContact.FindField( EVPbkSimAdditionalNumber );
       
   151     while ( !lookup.EndOfLookup() )
       
   152         {
       
   153         iNumberIndex->AddL( aContact.ConstFieldAt( lookup.Index() ).Data(), 
       
   154             aContact );
       
   155         aContact.FindNextField( lookup );
       
   156         }
       
   157     }
       
   158 } // namespace VPbkSimStore
       
   159 //  End of File