phonebookengines/VirtualPhonebook/VPbkSimStore/src/CContactStore.cpp
changeset 0 e686773b3f54
child 18 d4f567ce2e7c
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:  The virtual phonebook store implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "CContactStore.h"
       
    21 
       
    22 #include "CContactView.h"
       
    23 #include "CContact.h"
       
    24 #include "CRemoteStore.h"
       
    25 #include "CFieldTypeMappings.h"
       
    26 #include "CContactStoreDomain.h"
       
    27 #include "CCommitContactsOperation.h"
       
    28 #include "CDeleteContactsOperation.h"
       
    29 #include "CMatchPhoneNumberOperation.h"
       
    30 #include "CFindOperation.h"
       
    31 #include "CFindWithParserOperation.h"
       
    32 #include "CContactRetriever.h"
       
    33 #include "CSupportedFieldTypes.h"
       
    34 #include "CContactLink.h"
       
    35 #include "CContactOperationCallback.h"
       
    36 #include "CContactStoreInfo.h"
       
    37 
       
    38 #include "VPbkSimStoreError.h"
       
    39 #include "VPbkStoreUriLiterals.h"
       
    40 
       
    41 #include <CVPbkContactStoreUri.h>
       
    42 #include <TVPbkContactStoreUriPtr.h>
       
    43 #include <MVPbkContactStoreObserver.h>
       
    44 #include <CVPbkSimContact.h>
       
    45 #include <TVPbkSimStoreProperty.h>
       
    46 #include <CVPbkContactStoreProperties.h>
       
    47 #include <VPbkError.h>
       
    48 #include <VPbkSimStoreTemplateFunctions.h>
       
    49 #include <CVPbkAsyncCallback.h>
       
    50 
       
    51 namespace VPbkSimStore {
       
    52 
       
    53 // LOCAL
       
    54 namespace {
       
    55 
       
    56 // CONSTANTS
       
    57 
       
    58 // ============================= LOCAL FUNCTIONS ===============================
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // GetStoreIdentifier
       
    62 // Converts Virtual phonebook store name to sim store identifier
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 TVPbkSimStoreIdentifier GetStoreIdentifier( const TDesC& aStoreName )
       
    66     {
       
    67     TVPbkSimStoreIdentifier identifier = EVPbkSimAdnGlobalStore;
       
    68     if ( aStoreName.Compare( KVPbkSimGlobalAdnURI ) == 0 )
       
    69         {
       
    70         identifier = EVPbkSimAdnGlobalStore;
       
    71         }
       
    72     else if ( aStoreName.Compare( KVPbkSimGlobalSdnURI ) == 0 )
       
    73         {
       
    74         identifier = EVPbkSimSdnGlobalStore;
       
    75         }
       
    76     else if ( aStoreName.Compare( KVPbkSimGlobalFdnURI ) == 0 )
       
    77         {
       
    78         identifier = EVPbkSimFdnGlobalStore;
       
    79         }
       
    80     else if ( aStoreName.Compare( KVPbkSimGlobalOwnNumberURI ) == 0 )
       
    81         {
       
    82         identifier = EVPbkSimONStore;
       
    83         }
       
    84     else
       
    85         {
       
    86         VPbkSimStore::Panic( VPbkSimStore::EStoreNameMappingFailed );
       
    87         }
       
    88     return identifier;
       
    89     }
       
    90 }  // unnamed namespace
       
    91 
       
    92 // ============================ MEMBER FUNCTIONS ===============================
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CContactStore::CContactStore
       
    96 // C++ default constructor can NOT contain any code, that
       
    97 // might leave.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 inline CContactStore::CContactStore( CContactStoreDomain& aStoreDomain )
       
   101 :   iStoreDomain( aStoreDomain ),
       
   102     iStoreState( EStoreNotOpen )
       
   103     {
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CContactStore::ConstructL
       
   108 // Symbian 2nd phase constructor can leave.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 inline void CContactStore::ConstructL( const TVPbkContactStoreUriPtr& aURI )
       
   112     {
       
   113     iProperties = CVPbkContactStoreProperties::NewL();
       
   114     iStoreURI = CVPbkContactStoreUri::NewL( aURI );
       
   115     iProperties->SetName( iStoreURI->Uri() );
       
   116     iAsyncOpenOp =
       
   117         CVPbkAsyncObjectOperation<MVPbkContactStoreObserver>::NewL();
       
   118 
       
   119     iStoreInfo = CContactStoreInfo::NewL( *this );
       
   120     iNativeStore = CRemoteStore::NewL( GetStoreIdentifier(
       
   121                     iStoreURI->Uri().UriDes() ) );
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CContactStore::NewL
       
   126 // Two-phased constructor.
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 CContactStore* CContactStore::NewL( const TVPbkContactStoreUriPtr& aURI,
       
   130     CContactStoreDomain& aStoreDomain )
       
   131     {
       
   132     CContactStore* self = new ( ELeave ) CContactStore( aStoreDomain );
       
   133     CleanupStack::PushL( self );
       
   134     self->ConstructL( aURI );
       
   135     CleanupStack::Pop( self );
       
   136     return self;
       
   137     }
       
   138 
       
   139 // Destructor
       
   140 CContactStore::~CContactStore()
       
   141     {
       
   142     iStoreObservers.Close();
       
   143     delete iStoreInfo;
       
   144     delete iSupportedFieldTypes;
       
   145     delete iAsyncOpenOp;
       
   146     delete iStoreURI;
       
   147     if ( iNativeStore )
       
   148         {
       
   149         iNativeStore->Close( *this );
       
   150         delete iNativeStore;
       
   151         }
       
   152     delete iProperties;
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CContactStore::FieldTypeMappings
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 CFieldTypeMappings& CContactStore::FieldTypeMappings()
       
   160     {
       
   161     return iStoreDomain.FieldTypeMappings();
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CContactStore::MasterFieldTypeList
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 const MVPbkFieldTypeList& CContactStore::MasterFieldTypeList() const
       
   169     {
       
   170     return iStoreDomain.MasterFieldTypeList();
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CContactStore::NativeStore
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 MVPbkSimCntStore& CContactStore::NativeStore()
       
   178     {
       
   179     return *iNativeStore;
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CContactStore::CreateLinkLC
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 MVPbkContactLink* CContactStore::CreateLinkLC( TInt aSimIndex ) const
       
   187     {
       
   188     MVPbkContactLink* ret = NULL;
       
   189     if ( aSimIndex != KVPbkSimStoreFirstFreeIndex )
       
   190         {
       
   191         // Contact store constness casted away, no reason to be const
       
   192         ret = CContactLink::NewLC( const_cast<CContactStore&>(*this), aSimIndex );
       
   193         }
       
   194     return ret;
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CContactStore::ReadContactL
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 CContact* CContactStore::ReadContactL( TInt aSimIndex )
       
   202     {
       
   203     __ASSERT_DEBUG( iStoreState != EStoreNotOpen,
       
   204         VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
       
   205 
       
   206     // Read sim contact synchronously
       
   207     const TDesC8* etelCnt = iNativeStore->AtL( aSimIndex );
       
   208     if( !etelCnt )
       
   209         {
       
   210         User::Leave( KErrNotFound );
       
   211         }
       
   212     CVPbkSimContact* simCnt =
       
   213         CVPbkSimContact::NewLC( *etelCnt, *iNativeStore );
       
   214     // Create vpbk contact
       
   215     CContact* cnt = CContact::NewL( *this, simCnt );
       
   216     CleanupStack::Pop( simCnt );
       
   217     return cnt;
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CContactStore::MatchContactStore
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 TBool CContactStore::MatchContactStore( const TDesC& aContactStoreUri ) const
       
   225     {
       
   226     if ( iStoreURI->Uri().Compare(
       
   227         TVPbkContactStoreUriPtr( aContactStoreUri ),
       
   228         TVPbkContactStoreUriPtr::EContactStoreUriAllComponents ) == 0 )
       
   229         {
       
   230         return ETrue;
       
   231         }
       
   232     return EFalse;
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CContactStore::MatchContactStoreDomain
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 TBool CContactStore::MatchContactStoreDomain(
       
   240         const TDesC& aContactStoreDomain ) const
       
   241     {
       
   242     if ( iStoreURI->Uri().Compare(
       
   243         aContactStoreDomain,
       
   244         TVPbkContactStoreUriPtr::EContactStoreUriStoreType ) == 0 )
       
   245         {
       
   246         return ETrue;
       
   247         }
       
   248     return EFalse;
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CContactStore::CreateBookmarkLC
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 MVPbkContactBookmark* CContactStore::CreateBookmarkLC( TInt aSimIndex ) const
       
   256     {
       
   257     __ASSERT_DEBUG( iStoreState != EStoreNotOpen,
       
   258         VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
       
   259     // Bookmark is implemented as a link in this store
       
   260     // Contact store constness casted away, no reason to be const
       
   261     return CContactLink::NewLC( const_cast<CContactStore&>(*this), aSimIndex );
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CContactStore::CreateCommitContactsOperationL
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 MVPbkContactOperation* CContactStore::CreateCommitContactsOperationL(
       
   269     const TArray<MVPbkStoreContact*>& aContacts,
       
   270     MVPbkBatchOperationObserver& aObserver )
       
   271     {
       
   272 
       
   273     RArray<MVPbkStoreContact*> simContacts;
       
   274     CleanupClosePushL( simContacts );
       
   275     const TInt count = aContacts.Count();
       
   276     for ( TInt i = 0; i < count; ++i )
       
   277         {
       
   278         if ( &aContacts[i]->ParentStore() == this )
       
   279             {
       
   280             simContacts.AppendL( aContacts[i] );
       
   281             }
       
   282         }
       
   283 
       
   284     CCommitContactsOperation* cntOp = NULL;
       
   285     if ( simContacts.Count() > 0 )
       
   286         {
       
   287         __ASSERT_DEBUG( iStoreState != EStoreNotOpen,
       
   288             VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
       
   289         if (iStoreState == EStoreOpen )
       
   290             {
       
   291             cntOp = CCommitContactsOperation::NewL( *this, aObserver,
       
   292                 simContacts.Array() );
       
   293             }
       
   294 
       
   295         }
       
   296     CleanupStack::PopAndDestroy(); // simContacts
       
   297     return cntOp;
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CContactStore::CreateContactRetrieverL
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 MVPbkContactOperation* CContactStore::CreateContactRetrieverL(
       
   305     const MVPbkContactLink& aLink,
       
   306     MVPbkSingleContactOperationObserver& aObserver )
       
   307     {
       
   308 
       
   309     if ( CContactLink::IsValid( *this, aLink ) )
       
   310         {
       
   311         __ASSERT_DEBUG( iStoreState != EStoreNotOpen,
       
   312             VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
       
   313         if ( iStoreState == EStoreOpen )
       
   314             {
       
   315             const CContactLink& link = static_cast<const CContactLink&>( aLink );
       
   316             return CContactRetriever::NewL( *this, link.SimIndex(), aObserver );
       
   317             }
       
   318         }
       
   319     return NULL;
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CContactStore::CreateDeleteContactsOperationL
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 MVPbkContactOperation* CContactStore::CreateDeleteContactsOperationL(
       
   327     const MVPbkContactLinkArray& aContactLinks,
       
   328     MVPbkBatchOperationObserver& aObserver )
       
   329     {
       
   330 
       
   331     MVPbkContactOperation* operation = NULL;
       
   332     if ( !iProperties->ReadOnly() )
       
   333         {
       
   334         const TInt count = aContactLinks.Count();
       
   335         const TInt granularity = 20;
       
   336         RArray<TInt> indexes( granularity );
       
   337         CleanupClosePushL( indexes );
       
   338         for ( TInt i = 0; i < count; ++i )
       
   339             {
       
   340             if ( &aContactLinks.At(i).ContactStore() == this )
       
   341                 {
       
   342                 const CContactLink& link =
       
   343                     static_cast<const CContactLink&>( aContactLinks.At(i) );
       
   344                 indexes.AppendL( link.SimIndex() );
       
   345                 }
       
   346 
       
   347             }
       
   348 
       
   349         if ( indexes.Count() > 0 )
       
   350             {
       
   351             __ASSERT_DEBUG( iStoreState != EStoreNotOpen,
       
   352                 VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
       
   353             if ( iStoreState == EStoreOpen )
       
   354                 {
       
   355                 operation = CDeleteContactsOperation::NewL( *this, aObserver,
       
   356                     indexes.Array() );
       
   357                 }
       
   358             }
       
   359         CleanupStack::PopAndDestroy(); // indexes
       
   360         }
       
   361     return operation;
       
   362     }
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CContactStore::CreateMatchPhoneNumberOperationL
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 MVPbkContactOperation* CContactStore::CreateMatchPhoneNumberOperationL(
       
   369     const TDesC& aPhoneNumber, TInt aMaxMatchDigits,
       
   370     MVPbkContactFindObserver& aObserver )
       
   371     {
       
   372 
       
   373     if ( iStoreState == EStoreOpen )
       
   374         {
       
   375         return CMatchPhoneNumberOperation::NewL( aPhoneNumber,
       
   376             aMaxMatchDigits, aObserver, *this );
       
   377         }
       
   378     return NULL;
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CContactStore::CreateFindOperationL
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 MVPbkContactOperation* CContactStore::CreateFindOperationL(
       
   386         const TDesC& aSearchString,
       
   387         const MVPbkFieldTypeList& aFieldTypes,
       
   388         MVPbkContactFindObserver& aObserver)
       
   389     {
       
   390 
       
   391     if ( iStoreState == EStoreOpen )
       
   392         {
       
   393         return CFindOperation::NewL( *this, aObserver, aSearchString,
       
   394             aFieldTypes );
       
   395         }
       
   396     return NULL;
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CContactStore::CreateFindOperationL
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 MVPbkContactOperation* CContactStore::CreateFindOperationL(
       
   404         const MDesC16Array& aSearchStrings,
       
   405         const MVPbkFieldTypeList& aFieldTypes,
       
   406         MVPbkContactFindFromStoresObserver& aObserver,
       
   407         const TCallBack& aWordParserCallBack )
       
   408     {
       
   409 
       
   410     if ( iStoreState == EStoreOpen )
       
   411         {
       
   412         return CFindWithParserOperation::NewL( *this, aSearchStrings,
       
   413             aFieldTypes, aObserver, aWordParserCallBack );
       
   414         }
       
   415     return NULL;
       
   416     }
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // CContactStore::CreateCompressStoresOperationL
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 MVPbkContactOperation* CContactStore::CreateCompressStoresOperationL(
       
   423 		MVPbkBatchOperationObserver& /*aObserver*/)
       
   424 	{
       
   425 	return NULL;
       
   426 	}
       
   427 
       
   428 // -----------------------------------------------------------------------------
       
   429 // CContactStore::StoreProperties
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 const MVPbkContactStoreProperties& CContactStore::StoreProperties() const
       
   433     {
       
   434     return *iProperties;
       
   435     }
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 // CContactStore::OpenL
       
   439 // -----------------------------------------------------------------------------
       
   440 //
       
   441 void CContactStore::OpenL( MVPbkContactStoreObserver& aObserver )
       
   442     {
       
   443     switch ( iStoreState )
       
   444         {
       
   445         case EStoreNotOpen:
       
   446             {
       
   447             // Close first to ensure that store doesn't register twice.
       
   448             iNativeStore->Close( *this );
       
   449             iNativeStore->OpenL( iStoreDomain.SecurityInformation(), *this );
       
   450             break;
       
   451             }
       
   452         case EStoreOpen:
       
   453         case EStoreNotAvailable:
       
   454         default:
       
   455             {
       
   456             CVPbkAsyncObjectCallback<MVPbkContactStoreObserver>* callback =
       
   457                 VPbkEngUtils::CreateAsyncObjectCallbackLC(
       
   458                     *this,
       
   459                     &CContactStore::DoOpenL,
       
   460                     &CContactStore::DoOpenError,
       
   461                     aObserver);
       
   462             iAsyncOpenOp->CallbackL( callback );
       
   463             CleanupStack::Pop( callback );
       
   464             break;
       
   465             }
       
   466         }
       
   467 
       
   468     // adds aObserver to list of observers if it isn't there already, thus
       
   469     // avoids clients registering multiple times
       
   470     if ( iStoreObservers.Find(&aObserver) == KErrNotFound )
       
   471         {
       
   472         iStoreObservers.AppendL( &aObserver );
       
   473         }
       
   474     }
       
   475 
       
   476 // -----------------------------------------------------------------------------
       
   477 // CContactStore::ReplaceL
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 void CContactStore::ReplaceL(MVPbkContactStoreObserver& aObserver)
       
   481     {
       
   482     OpenL( aObserver );
       
   483     }
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CContactStore::Close
       
   487 // -----------------------------------------------------------------------------
       
   488 //
       
   489 void CContactStore::Close(MVPbkContactStoreObserver& aObserver)
       
   490     {
       
   491     iAsyncOpenOp->CancelCallback( &aObserver );
       
   492 
       
   493     const TInt pos = iStoreObservers.Find( &aObserver );
       
   494     if ( pos != KErrNotFound )
       
   495         {
       
   496         iStoreObservers.Remove( pos );
       
   497         }
       
   498 
       
   499     if ( iStoreObservers.Count() == 0 )
       
   500         {
       
   501         iNativeStore->Close( *this );
       
   502         iAsyncOpenOp->Purge();
       
   503         iStoreState = EStoreNotOpen;
       
   504         }
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CContactStore::CreateNewContactLC
       
   509 // -----------------------------------------------------------------------------
       
   510 //
       
   511 MVPbkStoreContact* CContactStore::CreateNewContactLC()
       
   512     {
       
   513     __ASSERT_DEBUG( iStoreState != EStoreNotOpen,
       
   514         VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
       
   515 
       
   516     CVPbkSimContact* simCnt = CVPbkSimContact::NewLC( *iNativeStore );
       
   517     CContact* cnt = CContact::NewL( *this, simCnt, ETrue );
       
   518     CleanupStack::Pop( simCnt );
       
   519     CleanupStack::PushL( cnt );
       
   520     return cnt;
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // CContactStore::CreateNewContactGroupLC
       
   525 // -----------------------------------------------------------------------------
       
   526 //
       
   527 MVPbkContactGroup* CContactStore::CreateNewContactGroupLC()
       
   528     {
       
   529     User::Leave(KErrNotSupported);
       
   530     return NULL;
       
   531     }
       
   532 
       
   533 // -----------------------------------------------------------------------------
       
   534 // CContactStore::CreateViewLC
       
   535 // -----------------------------------------------------------------------------
       
   536 //
       
   537 MVPbkContactView* CContactStore::CreateViewLC(
       
   538         const CVPbkContactViewDefinition& aViewDefinition,
       
   539         MVPbkContactViewObserver& aObserver,
       
   540         const MVPbkFieldTypeList& aSortOrder )
       
   541     {
       
   542     return CContactView::NewLC( aObserver, *this, aSortOrder, aViewDefinition );
       
   543     }
       
   544 
       
   545 // -----------------------------------------------------------------------------
       
   546 // CContactStore::ContactGroupsLC
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 MVPbkContactLinkArray* CContactStore::ContactGroupsLC() const
       
   550     {
       
   551     return CVPbkContactLinkArray::NewLC();
       
   552     }
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // CContactStore::StoreInfo
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 const MVPbkContactStoreInfo& CContactStore::StoreInfo() const
       
   559     {
       
   560     return *iStoreInfo;
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CContactStore::CreateLinkFromInternalsLC
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 MVPbkContactLink* CContactStore::CreateLinkFromInternalsLC(
       
   568         RReadStream& aStream) const
       
   569     {
       
   570     // Contact store constness casted away, no reason to be const
       
   571     return CContactLink::NewLC( const_cast<CContactStore&>(*this), aStream );
       
   572     }
       
   573 
       
   574 
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CContactStore::StoreReady
       
   578 // -----------------------------------------------------------------------------
       
   579 //
       
   580 void CContactStore::StoreReady( MVPbkSimCntStore& /*aStore*/ )
       
   581     {
       
   582     TVPbkGsmStoreProperty gsmProperties;
       
   583     TInt res = iNativeStore->GetGsmStoreProperties( gsmProperties );
       
   584 
       
   585     if ( res == KErrNone )
       
   586         {
       
   587         delete iSupportedFieldTypes;
       
   588         iSupportedFieldTypes = NULL;
       
   589         TRAP( res, iSupportedFieldTypes = CSupportedFieldTypes::NewL(
       
   590             iStoreDomain.FieldTypeMappings(), gsmProperties ) );
       
   591         iSimStoreCapabilities = gsmProperties.iCaps;
       
   592         }
       
   593 
       
   594     if ( res != KErrNone )
       
   595         {
       
   596         iStoreState = EStoreNotAvailable;
       
   597         VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
       
   598             &MVPbkContactStoreObserver::StoreUnavailable, *this, res );
       
   599         }
       
   600     else
       
   601         {
       
   602         iProperties->SetSupportedFields( *iSupportedFieldTypes );
       
   603         // After sim store is opened get read-only information and set properties
       
   604         SetStaticProperties( gsmProperties );
       
   605         iStoreState = EStoreOpen;
       
   606         VPbkSimStoreImpl::SendObserverMessageR( iStoreObservers,
       
   607             &MVPbkContactStoreObserver::StoreReady, *this );
       
   608         }
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CContactStore::StoreReady
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 void CContactStore::StoreError( MVPbkSimCntStore& /*aStore*/, TInt aError )
       
   616     {
       
   617     iStoreState = EStoreNotAvailable;
       
   618     VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
       
   619         &MVPbkContactStoreObserver::StoreUnavailable, *this, aError );
       
   620     }
       
   621 
       
   622 // -----------------------------------------------------------------------------
       
   623 // CContactStore::StoreNotAvailable
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 void CContactStore::StoreNotAvailable( MVPbkSimCntStore& /*aStore*/ )
       
   627     {
       
   628     iStoreState = EStoreNotAvailable;
       
   629     VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
       
   630         &MVPbkContactStoreObserver::StoreUnavailable, *this,
       
   631         KErrNotSupported );
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // CContactStore::StoreContactEvent
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 void CContactStore::StoreContactEvent( TEvent aEvent, TInt aSimIndex )
       
   639     {
       
   640     CContactLink* link = NULL;
       
   641     TRAPD( result,
       
   642         {
       
   643         link = CContactLink::NewLC( *this, aSimIndex );
       
   644         CleanupStack::Pop( link );
       
   645         });
       
   646     if ( result != KErrNone )
       
   647         {
       
   648         // First param not used in StoreError()
       
   649         StoreError( *iNativeStore, result );
       
   650         return;
       
   651         }
       
   652 
       
   653     switch ( aEvent )
       
   654         {
       
   655         case EContactAdded:
       
   656             {
       
   657             TVPbkContactStoreEvent event(TVPbkContactStoreEvent::EContactAdded, link);
       
   658             VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
       
   659                 &MVPbkContactStoreObserver::HandleStoreEventL, *this, event);
       
   660             break;
       
   661             }
       
   662         case EContactDeleted:
       
   663             {
       
   664             TVPbkContactStoreEvent event(TVPbkContactStoreEvent::EContactDeleted, link);
       
   665             VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
       
   666                 &MVPbkContactStoreObserver::HandleStoreEventL, *this, event);
       
   667             break;
       
   668             }
       
   669         case EContactChanged:
       
   670             {
       
   671             TVPbkContactStoreEvent event(TVPbkContactStoreEvent::EContactChanged, link);
       
   672             VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
       
   673                 &MVPbkContactStoreObserver::HandleStoreEventL, *this, event);
       
   674             break;
       
   675             }
       
   676         default:
       
   677             {
       
   678             __ASSERT_DEBUG( EFalse,
       
   679                 VPbkSimStore::Panic( VPbkSimStore::EUnknownSimStoreEvent ) );
       
   680             VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
       
   681                 &MVPbkContactStoreObserver::StoreUnavailable, *this,
       
   682                 KErrUnknown );
       
   683             break;
       
   684             }
       
   685         }
       
   686 
       
   687     delete link;
       
   688     }
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CContactStore::DoOpenL
       
   692 // -----------------------------------------------------------------------------
       
   693 //
       
   694 void CContactStore::DoOpenL( MVPbkContactStoreObserver& aObserver )
       
   695     {
       
   696     if ( iStoreState == EStoreOpen )
       
   697         {
       
   698         aObserver.StoreReady( *this );
       
   699         }
       
   700     else
       
   701         {
       
   702         aObserver.StoreUnavailable( *this, KErrNotSupported );
       
   703         }
       
   704     }
       
   705 
       
   706 // -----------------------------------------------------------------------------
       
   707 // CContactStore::DoOpenError
       
   708 // -----------------------------------------------------------------------------
       
   709 //
       
   710 void CContactStore::DoOpenError( MVPbkContactStoreObserver& aObserver,
       
   711         TInt aError )
       
   712     {
       
   713     aObserver.StoreUnavailable( *this, aError );
       
   714     }
       
   715 
       
   716 // -----------------------------------------------------------------------------
       
   717 // CContactStore::SetStaticProperties
       
   718 // -----------------------------------------------------------------------------
       
   719 //
       
   720 void CContactStore::SetStaticProperties( TVPbkGsmStoreProperty& aProperties )
       
   721     {
       
   722     // SIM resides in device -> local store
       
   723     iProperties->SetBooleanProperty(
       
   724         CVPbkContactStoreProperties::EPropertyLocal, ETrue );
       
   725     // In some devices SIM can be also removed from the device run time
       
   726     // -> removable store
       
   727     iProperties->SetBooleanProperty(
       
   728         CVPbkContactStoreProperties::EPropertyRemovable, ETrue );
       
   729     // If client changes the SIM store the changes are saved persistently
       
   730     // -> persistent store.
       
   731     iProperties->SetBooleanProperty(
       
   732         CVPbkContactStoreProperties::EPropertyPersistent, ETrue );
       
   733 
       
   734     if ( !( aProperties.iCaps & VPbkSimStoreImpl::KWriteAccess ) )
       
   735         {
       
   736         iProperties->SetBooleanProperty(
       
   737             CVPbkContactStoreProperties::EPropertyReadOnly, ETrue );
       
   738         }
       
   739     }
       
   740 
       
   741 // --------------------------------------------------------------------------
       
   742 // CContactStore::ContactStoreDomainFsSession
       
   743 // --------------------------------------------------------------------------
       
   744 //
       
   745 RFs& CContactStore::ContactStoreDomainFsSession()
       
   746     {
       
   747     return iStoreDomain.FsSession();
       
   748     }
       
   749 
       
   750 } // namespace VPbkSimStore
       
   751