predictivesearch/adapters/contacts/src/cpcscontactfetch.cpp
branchRCL_3
changeset 35 4ae315f230bc
parent 0 e686773b3f54
child 64 c1e8ba0c2b16
equal deleted inserted replaced
32:2828b4d142c0 35:4ae315f230bc
    98     
    98     
    99 	// Initialize virtual phonebook with uris read from central repository.
    99 	// Initialize virtual phonebook with uris read from central repository.
   100 	CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewLC();
   100 	CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewLC();
   101 	for(TInt i = 0; i< iUriFromCenrep.Count();i++)
   101 	for(TInt i = 0; i< iUriFromCenrep.Count();i++)
   102 	{
   102 	{
   103 		uriArray->AppendL( TVPbkContactStoreUriPtr(iUriFromCenrep[i]->Des()));
   103 		uriArray->AppendL( TVPbkContactStoreUriPtr(*iUriFromCenrep[i]) );
   104 	}
   104 	}
   105 
   105 
   106 	// Create the instance of the contact manager
   106 	// Create the instance of the contact manager
   107 	iContactManager = CVPbkContactManager::NewL(*uriArray);
   107 	iContactManager = CVPbkContactManager::NewL(*uriArray);
   108 	CleanupStack::PopAndDestroy(uriArray); 
   108 	CleanupStack::PopAndDestroy(uriArray); 
   151 
   151 
   152 	PRINT ( _L("End CPcsContactFetch::~CPcsContactFetch") );
   152 	PRINT ( _L("End CPcsContactFetch::~CPcsContactFetch") );
   153 }
   153 }
   154 
   154 
   155 // ----------------------------------------------------------------------------
   155 // ----------------------------------------------------------------------------
   156 // CPsContactDataAdapter::SetObserver
   156 // CPcsContactFetch::SetObserver
   157 // 
   157 // 
   158 // ----------------------------------------------------------------------------
   158 // ----------------------------------------------------------------------------
   159 void CPcsContactFetch::SetObserver(MDataStoreObserver& aObserver)
   159 void CPcsContactFetch::SetObserver(MDataStoreObserver& aObserver)
   160 {
   160 {
   161 	iObserver = &aObserver;
   161 	iObserver = &aObserver;
   162 }
   162 }
   163 
   163 
   164 // ----------------------------------------------------------------------------
   164 // ----------------------------------------------------------------------------
   165 // CPsContactDataAdapter::GetSupportedDataStoresL
   165 // CPcsContactFetch::GetSupportedDataStoresL
   166 // 
   166 // 
   167 // ----------------------------------------------------------------------------
   167 // ----------------------------------------------------------------------------
   168 void CPcsContactFetch::GetSupportedDataStoresL( RPointerArray<TDesC> &aDataStoresURIs )
   168 void CPcsContactFetch::GetSupportedDataStoresL( RPointerArray<TDesC> &aDataStoresURIs )
   169 {
   169 {
   170 	PRINT ( _L("Enter CPcsContactFetch::GetSupportedDataStoresL") );
   170 	PRINT ( _L("Enter CPcsContactFetch::GetSupportedDataStoresL") );
   175 	PRINT ( _L("End CPcsContactFetch::GetSupportedDataStoresL") );
   175 	PRINT ( _L("End CPcsContactFetch::GetSupportedDataStoresL") );
   176 
   176 
   177 }
   177 }
   178 
   178 
   179 // ----------------------------------------------------------------------------
   179 // ----------------------------------------------------------------------------
   180 // CPsContactDataAdapter::RequestForDataL
   180 // CPcsContactFetch::RequestForDataL
   181 // 
   181 // 
   182 // ----------------------------------------------------------------------------
   182 // ----------------------------------------------------------------------------
   183 void  CPcsContactFetch::RequestForDataL(TDesC& aDataStoreURI)
   183 void  CPcsContactFetch::RequestForDataL(TDesC& aDataStoreURI)
   184 {
   184 {
   185 	PRINT ( _L("Enter CPcsContactFetch::RequestForDataL") );
   185 	PRINT ( _L("Enter CPcsContactFetch::RequestForDataL") );
   210 // ---------------------------------------------------------------------------
   210 // ---------------------------------------------------------------------------
   211 void CPcsContactFetch::StoreReady(MVPbkContactStore& /*aStore*/)
   211 void CPcsContactFetch::StoreReady(MVPbkContactStore& /*aStore*/)
   212 {
   212 {
   213 	PRINT ( _L("Enter CPcsContactFetch::StoreReady") );
   213 	PRINT ( _L("Enter CPcsContactFetch::StoreReady") );
   214 	iAtLeastOneStoreReady = ETrue;
   214 	iAtLeastOneStoreReady = ETrue;
   215 	if( iWait->IsStarted() ) 
   215 	if( iWait->IsStarted() )
   216 			iWait->AsyncStop();
   216 		iWait->AsyncStop();
   217 	
   217 	
   218 	PRINT ( _L("End CPcsContactFetch::StoreReady") );
   218 	PRINT ( _L("End CPcsContactFetch::StoreReady") );
   219 }
   219 }
   220 
   220 
   221 // ---------------------------------------------------------------------------
   221 // ---------------------------------------------------------------------------
   276 	
   276 	
   277 	if (!iAtLeastOneStoreReady) 
   277 	if (!iAtLeastOneStoreReady) 
   278 	{
   278 	{
   279 		if( iWait->IsStarted() ) 
   279 		if( iWait->IsStarted() ) 
   280 			iWait->AsyncStop();
   280 			iWait->AsyncStop();
   281     	 	
       
   282 	}
   281 	}
   283 }
   282 }
   284 
   283 
   285 // ---------------------------------------------------------------------------------
   284 // ---------------------------------------------------------------------------------
   286 // Called in case of any errros 
   285 // Called in case of any errros 
   295 // --------------------------------------------------------------------------- 
   294 // --------------------------------------------------------------------------- 
   296 
   295 
   297 void CPcsContactFetch::ReadUrisFromCenrepL()
   296 void CPcsContactFetch::ReadUrisFromCenrepL()
   298 {
   297 {
   299     
   298     
   300     CRepository *repository = CRepository::NewL( KCRUidPSContacts );
   299     CRepository* repository = CRepository::NewL( KCRUidPSContacts );
       
   300     CleanupStack::PushL( repository );
   301     
   301     
   302     // Read the cenrep for URIs	
   302     // Read the cenrep for URIs	
   303     TBuf<KCRMaxLen> UriStr;
   303     TBuf<KCRMaxLen> uriStr;
   304     for (TInt i(KUriCenRepStartKey); i < KUriCenRepStartKey + KCenrepUriSupportedCount; i++ )
   304     for (TInt i(KUriCenRepStartKey); i < KUriCenRepStartKey + KCenrepUriSupportedCount; i++ )
   305     {
   305     {
   306 	    TInt err = repository->Get(i, UriStr );
   306         TInt err = repository->Get( i, uriStr );
   307 	    if (KErrNone != err)
   307         if (KErrNone != err)
   308 	    {
   308         {
   309 		    break;
   309             break;
   310 	    }
   310         }
   311 	    
   311         
   312 	    if (UriStr != KNullDesC)
   312         if (uriStr != KNullDesC)
   313 	    {
   313         {
   314 		    iUriFromCenrep.Append(UriStr.AllocL());
   314             HBufC* uri = uriStr.AllocLC();
   315 	    }
   315             iUriFromCenrep.AppendL(uri);
   316 	    		
   316             CleanupStack::Pop(uri);
       
   317         }
       
   318     
   317     }
   319     }
   318     
   320     
   319     delete repository;
   321     CleanupStack::PopAndDestroy( repository );
   320 }
   322 }
   321 
   323 
   322 
   324 
   323 // ---------------------------------------------------------------------------
   325 // ---------------------------------------------------------------------------
   324 // Creates the contact view 
   326 // Creates the contact view 
   329 	
   331 	
   330 	if (!iAtLeastOneStoreReady) 
   332 	if (!iAtLeastOneStoreReady) 
   331 	{
   333 	{
   332 		if( ! (iWait->IsStarted()) ) 
   334 		if( ! (iWait->IsStarted()) ) 
   333 	    {
   335 	    {
   334 	    	iWait->Start();			        	
   336 	    	iWait->Start();
   335 	    }
   337 	    }
   336 	}
   338 	}
   337 	
   339 	
   338 	// Check if data store is already present
   340 	// Check if data store is already present
   339 	for ( int i = 0; i < iAllDataStores.Count(); i++ )
   341 	for ( TInt i = 0; i < iAllDataStores.Count(); i++ )
   340 	{
   342 	{
   341 	    CPcsContactStore* contactStore = iAllDataStores[i];
   343 	    CPcsContactStore* contactStore = iAllDataStores[i];
   342 		if ( contactStore->GetStoreUri().Compare(aDataStoreURI) == 0 )
   344 		if ( contactStore->GetStoreUri().Compare(aDataStoreURI) == 0 )
   343 		{
   345 		{
   344 		    // Remove the store
   346 		    // Remove the store
   345 		    delete contactStore;
   347 		    delete contactStore;
   346 			iAllDataStores.Remove(i);	
   348 			iAllDataStores.Remove(i);
   347 			break;		
   349 			break;
   348 		}
   350 		}
   349 	}
   351 	}
   350 	
   352 	
   351 	MVPbkContactStoreList& stores = iContactManager->ContactStoresL();
   353 	MVPbkContactStoreList& stores = iContactManager->ContactStoresL();
   352     for ( TInt i(0); i < stores.Count(); ++i )
   354     for ( TInt i(0); i < stores.Count(); ++i )
   354         if(stores.At(i).StoreProperties().Uri().UriDes().Compare(aDataStoreURI) == 0)
   356         if(stores.At(i).StoreProperties().Uri().UriDes().Compare(aDataStoreURI) == 0)
   355         {
   357         {
   356         	CPcsContactStore* contactStore = CPcsContactStore::NewL(*iContactManager,
   358         	CPcsContactStore* contactStore = CPcsContactStore::NewL(*iContactManager,
   357 		                                                        *iObserver,
   359 		                                                        *iObserver,
   358 		                                                        stores.At(i).StoreProperties().Uri().UriDes());
   360 		                                                        stores.At(i).StoreProperties().Uri().UriDes());
   359 			iAllDataStores.Append(contactStore);	
   361 			iAllDataStores.Append(contactStore);
   360 			break;
   362 			break;
   361         }
   363         }
   362 	}
   364 	}
   363 	PRINT ( _L("End CPcsContactFetch::CreateSubStoresL") );
   365 	PRINT ( _L("End CPcsContactFetch::CreateSubStoresL") );
   364 			  
   366 	
   365 }
   367 }
   366 
   368 
   367 // ----------------------------------------------------------------------------
   369 // ----------------------------------------------------------------------------
   368 // CPcsContactFetch::GetSupportedDataFieldsL
   370 // CPcsContactFetch::GetSupportedDataFieldsL
   369 // 
   371 // 
   385 	    }
   387 	    }
   386 	    if ( fieldToCache != 0 )
   388 	    if ( fieldToCache != 0 )
   387 	    {
   389 	    {
   388 		   aDataFields.Append(fieldToCache);
   390 		   aDataFields.Append(fieldToCache);
   389 	    }
   391 	    }
   390 	    		
   392 	
   391     }
   393     }
   392     
   394     
   393     delete repository; 
   395     delete repository; 
   394    	PRINT ( _L("End CPcsContactFetch::GetSupportedDataFieldsL") );
   396    	PRINT ( _L("End CPcsContactFetch::GetSupportedDataFieldsL") );
   395 }
   397 }
   399 // 
   401 // 
   400 // ----------------------------------------------------------------------------
   402 // ----------------------------------------------------------------------------
   401 TBool CPcsContactFetch::IsDataStoresSupportedL( TDesC& aDataStoreURI ) 
   403 TBool CPcsContactFetch::IsDataStoresSupportedL( TDesC& aDataStoreURI ) 
   402 {
   404 {
   403 	
   405 	
   404 	for(TInt i =0 ; i<iUriFromCenrep.Count();i++)
   406 	for ( TInt i = 0 ; i < iUriFromCenrep.Count() ; i++ )
   405 	{
   407 	{
   406 		if(iUriFromCenrep[i]->Des().Compare(aDataStoreURI) ==0)
   408 		if ( iUriFromCenrep[i]->Compare(aDataStoreURI) == 0 )
   407 		    return ETrue;
   409 		    return ETrue;
   408 	}
   410 	}
   409 	
   411 	
   410 	return EFalse;
   412 	return EFalse;
   411 }
   413 }