predictivesearch/adapters/contacts/src/cpcscontactstore.cpp
branchRCL_3
changeset 21 b3431bff8c19
parent 15 e8e3147d53eb
child 32 2828b4d142c0
equal deleted inserted replaced
15:e8e3147d53eb 21:b3431bff8c19
    47 #include <CVPbkFieldTypeSelector.h>
    47 #include <CVPbkFieldTypeSelector.h>
    48 #include <CVPbkContactLinkArray.h>
    48 #include <CVPbkContactLinkArray.h>
    49 #include <CVPbkSortOrder.h>
    49 #include <CVPbkSortOrder.h>
    50 #include <data_caging_path_literals.hrh>
    50 #include <data_caging_path_literals.hrh>
    51 #include <bautils.h>
    51 #include <bautils.h>
       
    52 #include <featmgr.h>
       
    53 #include <CPbk2SortOrderManager.h>
    52 
    54 
    53 // USER INCLUDES
    55 // USER INCLUDES
    54 #include "cpcscontactstore.h"
    56 #include "cpcscontactstore.h"
    55 #include "CPsData.h"
    57 #include "CPsData.h"
    56 #include "CPcsDebug.h" 
    58 #include "CPcsDebug.h" 
    88 
    90 
    89 // ---------------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------------
    90 // Constructor
    92 // Constructor
    91 // ---------------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------------
    92 CPcsContactStore::CPcsContactStore():
    94 CPcsContactStore::CPcsContactStore():
    93 	CActive( CActive::EPriorityLow),
    95     CActive( CActive::EPriorityLow ),
    94     iAllContactLinksCount(0),
    96     iAllContactLinksCount(0),
    95     iFetchedContactCount(0),
    97     iFetchedContactCount(0),
    96     iContactViewReady(EFalse)
    98     iContactViewReady(EFalse)
    97 {
    99 {
    98     PRINT ( _L("Enter CPcsContactStore::CPcsContactStore") );
   100     PRINT ( _L("Enter CPcsContactStore::CPcsContactStore") );
    99     CActiveScheduler::Add( this );
   101     CActiveScheduler::Add( this );
   100 	PRINT ( _L("End CPcsContactStore::CPcsContactStore") );
   102     PRINT ( _L("End CPcsContactStore::CPcsContactStore") );
   101 }
   103 }
   102 
   104 
   103 
   105 
   104 // ---------------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------------
   105 // CPcsContactStore::ConstructL() 
   107 // CPcsContactStore::ConstructL() 
   115 	iObserver = &aObserver;
   117 	iObserver = &aObserver;
   116 	
   118 	
   117 	iUri = HBufC::NewL(aUri.Length());
   119 	iUri = HBufC::NewL(aUri.Length());
   118 	iUri->Des().Copy(aUri);
   120 	iUri->Des().Copy(aUri);
   119 	
   121 	
   120 	// create containers for holding the sim data      
   122 	// create containers for holding the sim data
   121     iSimContactItems = CVPbkContactLinkArray::NewL();
   123     iSimContactItems = CVPbkContactLinkArray::NewL();
   122    
   124    
   123 	
   125 	
   124 	// for creating sort order
   126 	// for creating sort order
   125 	iSortOrder = CVPbkFieldTypeRefsList::NewL();
   127 	iSortOrder = CVPbkFieldTypeRefsList::NewL();
   132     
   134     
   133     // Initial state
   135     // Initial state
   134 	iNextState = ECreateView;
   136 	iNextState = ECreateView;
   135 	IssueRequest();
   137 	IssueRequest();
   136 	
   138 	
       
   139     FeatureManager::InitializeLibL();
       
   140     if( FeatureManager::FeatureSupported( KFeatureIdffContactsMycard ) )
       
   141         {
       
   142         iMyCardSupported = ETrue;
       
   143         }
       
   144     FeatureManager::UnInitializeLib();    
       
   145 
   137 	PRINT ( _L("End CPcsContactStore::ConstructL") );
   146 	PRINT ( _L("End CPcsContactStore::ConstructL") );
   138 }
   147 }
   139 
   148 
   140 // ---------------------------------------------------------------------------------
   149 // ---------------------------------------------------------------------------------
   141 // Destructor
   150 // Destructor
   156 	delete iWait;
   165 	delete iWait;
   157 	iWait = NULL;
   166 	iWait = NULL;
   158 	
   167 	
   159 	delete iUri;
   168 	delete iUri;
   160 	iUri = NULL;
   169 	iUri = NULL;
   161 		
   170 	
   162 	iTimer.Cancel();
   171 	iTimer.Cancel();
   163     iTimer.Close();
   172     iTimer.Close();
   164 	iFieldsToCache.Close();	
   173 	iFieldsToCache.Close();	
   165 	
   174 	
   166 	iFs.Close();
   175 	iFs.Close();
   167 	
   176 	
   168 	if(IsActive())
   177 	if(IsActive())
   169 	{
   178 	{
   170 		Deque();
   179 		Deque();
   171 	}
   180 	}
       
   181 	
       
   182 	delete iSortOrderMan;
   172 	
   183 	
   173 	PRINT ( _L("End CPcsContactStore::~CPcsContactStore") );
   184 	PRINT ( _L("End CPcsContactStore::~CPcsContactStore") );
   174 }
   185 }
   175 
   186 
   176 
   187 
   203 		case TVPbkContactStoreEvent::EContactDeleted:
   214 		case TVPbkContactStoreEvent::EContactDeleted:
   204 		case TVPbkContactStoreEvent::EContactChanged:
   215 		case TVPbkContactStoreEvent::EContactChanged:
   205 		case TVPbkContactStoreEvent::EGroupDeleted:
   216 		case TVPbkContactStoreEvent::EGroupDeleted:
   206 		case TVPbkContactStoreEvent::EGroupChanged:
   217 		case TVPbkContactStoreEvent::EGroupChanged:
   207 		{
   218 		{
   208 		    if ( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged ) 
   219 		    if ( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged ||
       
   220 		         aStoreEvent.iEventType == TVPbkContactStoreEvent::EGroupChanged ) 
   209 		    {
   221 		    {
   210 		    	PRINT ( _L("Change contact/group event received") );
   222 		    	PRINT ( _L("Change contact/group event received") );
   211 		    }
   223 		    }
   212 		    else 
   224 		    else 
   213 		    {
   225 		    {
   222 	        
   234 	        
   223 	        if ( err == KErrNotSupported )
   235 	        if ( err == KErrNotSupported )
   224 	        {
   236 	        {
   225 	            // sim domain  
   237 	            // sim domain  
   226 	            // Pass the sim observer string in the next line
   238 	            // Pass the sim observer string in the next line
   227 	            TInt contactLocation =  iSimContactItems->Find(*aStoreEvent.iContactLink);	
   239 	            TInt contactLocation = iSimContactItems->Find(*aStoreEvent.iContactLink);
   228 				if( KErrNotFound != contactLocation)
   240 				if( KErrNotFound != contactLocation)
   229 				{
   241 				{
   230 				    // We are not removing from the array cache. If you try to fetch, 
   242 				    // We are not removing from the array cache. If you try to fetch, 
   231 				    // then it will give an error			       
   243 				    // then it will give an error
   232 				    TInt index = CreateCacheIDfromSimArrayIndex (contactLocation);
   244 				    TInt index = CreateCacheIDfromSimArrayIndex (contactLocation);
   233 				    
   245 				    
   234 	                iObserver->RemoveData(*iUri,index );
   246 	                iObserver->RemoveData(*iUri,index );
   235 		       	} 	               	           
   247 		       	}
   236 		               	           
   248 		    
   237 	        }
   249 	        }
   238 	        else
   250 	        else
   239 	        {
   251 	        {
   240 	           // cntdb domain
   252 	           // cntdb domain
   241 	           // Get contact id by mapping the link
   253 	           // Get contact id by mapping the link
   250 		    
   262 		    
   251 	        if (( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged ) ||
   263 	        if (( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged ) ||
   252 	            ( aStoreEvent.iEventType == TVPbkContactStoreEvent::EGroupChanged ) )
   264 	            ( aStoreEvent.iEventType == TVPbkContactStoreEvent::EGroupChanged ) )
   253 	        {
   265 	        {
   254 	  		    // Add the contact
   266 	  		    // Add the contact
   255 	  		   iContactManager->RetrieveContactL( *(aStoreEvent.iContactLink),
   267 	  		   iContactManager->RetrieveContactL( *(aStoreEvent.iContactLink), *this );
   256 	  		                                                           *this );
       
   257 	        }
   268 	        }
   258 	        	  		  
   269 	        
   259 			break;
   270 			break;
   260 		}
   271 		}
   261 	}
   272 	}
   262 
   273 
   263 	PRINT ( _L("End CPcsContactStore::HandleStoreEventL") );
   274 	PRINT ( _L("End CPcsContactStore::HandleStoreEventL") );
   266 // ---------------------------------------------------------------------------
   277 // ---------------------------------------------------------------------------
   267 //  Returns ths database URI
   278 //  Returns ths database URI
   268 // ---------------------------------------------------------------------------
   279 // ---------------------------------------------------------------------------
   269 TDesC& CPcsContactStore::GetStoreUri()
   280 TDesC& CPcsContactStore::GetStoreUri()
   270 {
   281 {
   271   return *iUri;
   282     return *iUri;
   272 }
   283 }
   273 
   284 
   274 // ---------------------------------------------------------------------------
   285 // ---------------------------------------------------------------------------
   275 //  Callback Method. Called when one Retrieve operation is complete
   286 //  Callback Method. Called when one Retrieve operation is complete
   276 // --------------------------------------------------------------------------- 
   287 // --------------------------------------------------------------------------- 
   342 // ---------------------------------------------------------------------------
   353 // ---------------------------------------------------------------------------
   343 // Handles the operations for a single contact after it is fetched
   354 // Handles the operations for a single contact after it is fetched
   344 // ---------------------------------------------------------------------------
   355 // ---------------------------------------------------------------------------
   345 void CPcsContactStore::HandleRetrievedContactL(MVPbkStoreContact* aContact)
   356 void CPcsContactStore::HandleRetrievedContactL(MVPbkStoreContact* aContact)
   346 {    
   357 {    
       
   358     if ( iMyCardSupported && IsMyCard( *aContact ) )
       
   359         {
       
   360         return;
       
   361         }
       
   362     
       
   363     // Take the ownership
       
   364     aContact->PushL();
       
   365 
   347     // Fill the contact link
   366     // Fill the contact link
   348 	MVPbkContactLink* tmpLink = aContact->CreateLinkLC();
   367 	MVPbkContactLink* tmpLink = aContact->CreateLinkLC();
   349 		
   368 	
   350     // If the link is null, then it is not put on the cleanup stack,
   369     // If the link is null, then it is not put on the cleanup stack,
   351     // so we need not pop in such a case
   370     // so we need not pop in such a case
   352     if( NULL == tmpLink )
   371     if( NULL == tmpLink )
   353     {
   372     {
   354         delete aContact;
   373         CleanupStack::PopAndDestroy( aContact );
   355         aContact = NULL;
   374         return;
   356     	return;
       
   357     }
   375     }
   358    
   376    
   359     // Recover the URI
   377 	CPsData* phoneContact = CPsData::NewL();
   360     HBufC* storeUri = HBufC::NewL(aContact->ParentStore().StoreProperties().Uri().UriDes().Length());
       
   361     storeUri->Des().Copy(aContact->ParentStore().StoreProperties().Uri().UriDes());
       
   362         			
       
   363 	CPsData *phoneContact = CPsData::NewL();
       
   364 
   378 
   365 	
   379 	
   366 	// Fill the contact id
   380 	// Fill the contact id
   367 	CVPbkContactIdConverter* converter = NULL;
   381 	CVPbkContactIdConverter* converter = NULL;
   368 	TRAPD ( err, converter = CVPbkContactIdConverter::NewL( aContact->ParentStore() ) );
   382 	TRAPD ( err, converter = CVPbkContactIdConverter::NewL( aContact->ParentStore() ) );
   369 	
   383 	
   370 	if ( err == KErrNotSupported )
   384 	if ( err == KErrNotSupported )
   371 	{
   385 	{
   372 		// simdb domain	
   386 		// simdb domain
   373 		PRINT ( _L("SIM domain data received") );
   387 		PRINT ( _L("SIM domain data received") );
   374 			
   388 		
   375 		TInt tempIndex =  iSimContactItems->Find(*tmpLink);	
   389         // Set the contact link 
       
   390         HBufC8* extnInfo = tmpLink->PackLC();
       
   391         phoneContact->SetDataExtension(extnInfo);
       
   392         CleanupStack::Pop( extnInfo );
       
   393 
       
   394         // Get the index of the SIM contact
       
   395         TInt tempIndex =  iSimContactItems->Find(*tmpLink);	
   376 		
   396 		
   377 		if( KErrNotFound == tempIndex)
   397 		if( KErrNotFound == tempIndex)
   378 
       
   379 		    {
   398 		    {
   380 		    	tempIndex = iSimContactItems->Count();
   399 		    tempIndex = iSimContactItems->Count();
   381 	        iSimContactItems->AppendL(tmpLink);
   400 	        iSimContactItems->AppendL(tmpLink);
   382 	      }
   401 	        CleanupStack::Pop(); // tmpLink
       
   402 	        }
       
   403 		else
       
   404 		    {
       
   405             CleanupStack::PopAndDestroy(); // tmpLink
       
   406 		    }
       
   407 		
   383 	    //Create a dummy sim index and set it
   408 	    //Create a dummy sim index and set it
   384 	    TInt simIndex = CreateCacheIDfromSimArrayIndex(tempIndex);
   409 	    TInt simIndex = CreateCacheIDfromSimArrayIndex(tempIndex);
   385 	    phoneContact->SetId(simIndex);
   410 	    phoneContact->SetId(simIndex);
   386 	    
       
   387 	    // Set the contact link 
       
   388 	    HBufC8* extnInfo = tmpLink->PackLC();
       
   389 	    phoneContact->SetDataExtension(extnInfo);
       
   390 	    CleanupStack::Pop();//extnInfo		      
       
   391 	    CleanupStack::Pop(); // tmpLink
       
   392 	}
   411 	}
   393 	else 
   412 	else 
   394 	{
   413 	{
   395 	    // cntdb domain
   414 	    // cntdb domain
   396 		TInt32 contactId = converter->LinkToIdentifier(*tmpLink);
   415 		TInt32 contactId = converter->LinkToIdentifier(*tmpLink);
   397 		phoneContact->SetId(contactId);		
   416 		phoneContact->SetId(contactId);
   398 		CleanupStack::PopAndDestroy(); // tmpLink
   417 		CleanupStack::PopAndDestroy(); // tmpLink
   399 	}
   418 	}
   400    	 
   419    	 
   401 	// Take the ownership
       
   402 	aContact->PushL();
       
   403 
       
   404 	MVPbkContactGroup* myContactGroup= aContact->Group();
   420 	MVPbkContactGroup* myContactGroup= aContact->Group();
   405 	
   421 	
   406 	// The retrieved contact can be a contact item or a contact group, Handle accordingly
   422 	// The retrieved contact can be a contact item or a contact group, Handle accordingly
   407 	if ( NULL == myContactGroup )
   423 	if ( NULL == myContactGroup )
   408 	{
   424 	{
   409 		// The fetched contact item (and not a contact group.)
   425 		// The fetched contact item (and not a contact group.)
   410 		GetDataForSingleContactL( *aContact, phoneContact );
   426 		GetDataForSingleContactL( *aContact, phoneContact );
       
   427 	    // Recover the URI
       
   428 	    HBufC* storeUri = aContact->ParentStore().StoreProperties().Uri().UriDes().AllocL();
   411 		//Add the data to the relevent cache through the observer
   429 		//Add the data to the relevent cache through the observer
   412 		iObserver->AddData(*storeUri, phoneContact);
   430 		iObserver->AddData(*storeUri, phoneContact);
       
   431 		delete storeUri;
   413 	}
   432 	}
   414 	else
   433 	else
   415 	{  
   434 	{  
   416 	    // Fetch the group name 
   435 	    // Fetch the group name 
   417 	    HBufC* groupName = HBufC::NewL(myContactGroup->GroupLabel().Length());
   436 	    HBufC* groupName = myContactGroup->GroupLabel().AllocLC();
   418 	    groupName->Des().Copy(myContactGroup->GroupLabel());
       
   419 	    TInt grpArrayIndex = -1; 
   437 	    TInt grpArrayIndex = -1; 
   420 	    for(TInt i =0; i  <iFieldsToCache.Count(); i++)
   438 	    for(TInt i =0; i  <iFieldsToCache.Count(); i++)
   421 	    {
   439 	    {
   422 	    	if(iFieldsToCache[i] == R_VPBK_FIELD_TYPE_LASTNAME)
   440 	    	if(iFieldsToCache[i] == R_VPBK_FIELD_TYPE_LASTNAME)
   423          
   441 			{
   424 			 {
   442 			    grpArrayIndex = i;
   425 			 grpArrayIndex = i;
   443 			}
   426 			 	
   444 			phoneContact->SetDataL(i, KNullDesC);
   427 			 }
       
   428 			 phoneContact->SetDataL(i,KNullDesC);
       
   429 	    }
   445 	    }
   430 	    if(grpArrayIndex != -1)
   446 	    if(grpArrayIndex != -1)
   431 	    {
   447 	    {
   432 	    	phoneContact->SetDataL(grpArrayIndex,groupName->Des());
   448 	    	phoneContact->SetDataL(grpArrayIndex, *groupName);
   433 	    	storeUri->Des().Copy(KVPbkDefaultGrpDbURI);	    
       
   434 	    
   449 	    
   435 	
   450             // Check for the contact in the group.
   436 	    
   451             MVPbkContactLinkArray* contactsContainedInGroup = myContactGroup->ItemsContainedLC();
   437 	    
   452             for(TInt i = 0; i < contactsContainedInGroup->Count(); i++)
   438         // Check for the contact in the group.
   453             {
   439 	    MVPbkContactLinkArray* contactsContainedInGroup = myContactGroup->ItemsContainedLC();
   454                 TInt grpContactId = converter->LinkToIdentifier(contactsContainedInGroup->At(i));
   440         for(TInt i = 0; i < contactsContainedInGroup->Count(); i++)
   455                 phoneContact->AddIntDataExtL(grpContactId);
   441 		{
   456             }
   442 			TInt grpContactId = converter->LinkToIdentifier(contactsContainedInGroup->At(i));
   457             CleanupStack::PopAndDestroy(); // contactsContainedInGroup
   443 			phoneContact->AddIntDataExtL(grpContactId);
   458             
   444 		}
   459             // Recover the URI
   445 		CleanupStack::PopAndDestroy(); // contactsContainedInGroup
   460             HBufC* storeUri = KVPbkDefaultGrpDbURI().AllocL();
   446  
   461             
   447  		
   462             //Add the data to the relevent cache through the observer
   448  		//Add the data to the relevent cache through the observer
   463             iObserver->AddData(*storeUri, phoneContact);
   449 	    iObserver->AddData(*storeUri, phoneContact);
   464             
       
   465             delete storeUri;
   450 	 	}
   466 	 	}
   451 	    else
   467 	    else
   452 	    {
   468 	    {
   453 	    	//We do not add anything here since Lastname does not exists in cenrep
   469 	    	//We do not add anything here since Lastname does not exists in cenrep
   454 	    	delete 	phoneContact;
   470 	    	delete phoneContact;
   455 	    	phoneContact = NULL;
   471 	    	phoneContact = NULL;
   456 	    }
   472 	    }
   457 	    delete groupName;
   473 	    CleanupStack::PopAndDestroy( groupName );
   458 	    groupName = NULL;
       
   459 	}
   474 	}
   460 	
   475 	
   461 	delete converter;
   476 	delete converter;
   462 	converter = NULL;
   477 	converter = NULL;
   463 
   478 
   464 	delete storeUri;
   479 	CleanupStack::PopAndDestroy(aContact);
   465     storeUri = NULL;
       
   466     
       
   467 	CleanupStack::PopAndDestroy(aContact); // aContact
       
   468 }
   480 }
   469  
   481  
   470     
   482     
   471 // ---------------------------------------------------------------------------
   483 // ---------------------------------------------------------------------------
   472 // Fetches the data from a particular contact 
   484 // Fetches the data from a particular contact 
   531                     }
   543                     }
   532                     else
   544                     else
   533                     {
   545                     {
   534                         aPhoneData->SetDataL(i,data.Text());
   546                         aPhoneData->SetDataL(i,data.Text());
   535                     }
   547                     }
   536 				}			
   548 				}
   537 			}					
   549 			}
   538 		}
   550 		}
   539 	}
   551 	}
   540 	
   552 	
   541 	CleanupStack::PopAndDestroy( itr ); 
   553 	CleanupStack::PopAndDestroy( itr ); 
   542 }
   554 }
   547 void CPcsContactStore::FetchlinksL()
   559 void CPcsContactStore::FetchlinksL()
   548 {		
   560 {		
   549 
   561 
   550 	PRINT1 ( _L("CPcsContactStore::Total contacts downloaded = %d"),
   562 	PRINT1 ( _L("CPcsContactStore::Total contacts downloaded = %d"),
   551 	          iFetchedContactCount );
   563 	          iFetchedContactCount );
   552 	          						
   564 	
   553     TInt blockCount = iFetchedContactCount + KLinksToFetchInOneGo;
   565     TInt blockCount = iFetchedContactCount + KLinksToFetchInOneGo;
   554     
   566     
   555     if( blockCount >= iAllContactLinksCount)
   567     if( blockCount >= iAllContactLinksCount)
   556     	blockCount = iAllContactLinksCount;
   568     	blockCount = iAllContactLinksCount;
   557     
   569     
   558 	for(int cnt = iFetchedContactCount; cnt < blockCount; cnt++)
   570 	for(TInt cnt = iFetchedContactCount; cnt < blockCount; cnt++)
   559 	{	
   571 	{	
   560 		// Retrieve the contact 
   572 		// Retrieve the contact 
   561 		MVPbkContactLink* tempLink =iContactViewBase->CreateLinkLC(cnt);
   573 		MVPbkContactLink* tempLink =iContactViewBase->CreateLinkLC(cnt);
   562 		iContactManager->RetrieveContactL( *tempLink, *this );
   574 		iContactManager->RetrieveContactL( *tempLink, *this );
   563 		CleanupStack::PopAndDestroy();
   575 		CleanupStack::PopAndDestroy(); // tempLink
   564 	}				
   576 	}
   565 
   577 
   566 }
   578 }
   567 
   579 
   568 // ---------------------------------------------------------------------------
   580 // ---------------------------------------------------------------------------
   569 // Implements the view ready function of MVPbkContactViewObserver
   581 // Implements the view ready function of MVPbkContactViewObserver
   668 	viewName->Des().Append(KPcsViewPrefix);
   680 	viewName->Des().Append(KPcsViewPrefix);
   669 	viewName->Des().Append(iUri->Des());
   681 	viewName->Des().Append(iUri->Des());
   670 	CleanupStack::PushL(viewName);
   682 	CleanupStack::PushL(viewName);
   671 
   683 
   672 	// Set the Uri
   684 	// Set the Uri
   673 	if ( iUri->Des().CompareC(KVPbkDefaultGrpDbURI) == 0)
   685 	if ( iUri->CompareC(KVPbkDefaultGrpDbURI) == 0)
   674 	{	    
   686 	{	    
   675 		// Special Handling required for Groups Data Store
   687 		// Special Handling required for Groups Data Store
   676 		// Read the resource file and create the sort order
   688 		// Read the resource file and create the sort order
   677 		// The sort order created is used in view creation.
   689 		// The sort order created is used in view creation.
   678 		
   690 		
   725     
   737     
   726     	// Close the resouce File
   738     	// Close the resouce File
   727         iResourceFile.Close();                        
   739         iResourceFile.Close();                        
   728 	
   740 	
   729 	}
   741 	}
       
   742 	else if ( iUri->CompareC(KVPbkDefaultCntDbURI) == 0)
       
   743     {       
       
   744         // For phone contacts DB we use the shared "AllContacts" -view so that 
       
   745         // we don't need to generate a new view. This way we save some RAM
       
   746         // from contacts server and some CPU time because the view is already
       
   747         // generated and sorted. Difference is noticiable with larger amount 
       
   748         // of contacts e.g. 7000. 
       
   749 	
       
   750         viewDef->SetUriL( iUri->Des() );
       
   751         viewDef->SetType( EVPbkContactsView );
       
   752 
       
   753         if( !iSortOrderMan )
       
   754             {
       
   755             iSortOrderMan = CPbk2SortOrderManager::NewL( 
       
   756                 iContactManager->FieldTypes(), &iContactManager->FsSession() );
       
   757             }
       
   758 
       
   759         iContactViewBase = iContactManager->CreateContactViewLC( 
       
   760             *this, *viewDef, iSortOrderMan->SortOrder() );
       
   761         CleanupStack::Pop(); // iContactViewBase       
       
   762     }
   730 	else
   763 	else
   731 	{
   764 	{        
   732 	
       
   733 		// Create sort order with the fields from cenrep
   765 		// Create sort order with the fields from cenrep
   734 		CreateSortOrderL(iContactManager->FieldTypes());
   766 		CreateSortOrderL(iContactManager->FieldTypes());
   735 		
   767 		
   736 		CVPbkSortOrder* sortOrderPhone = CVPbkSortOrder::NewL(*iSortOrder);
   768 		CVPbkSortOrder* sortOrderPhone = CVPbkSortOrder::NewL(*iSortOrder);
   737 	    CleanupStack::PushL(sortOrderPhone);
   769 	    CleanupStack::PushL(sortOrderPhone);
   777     switch( iNextState)
   809     switch( iNextState)
   778     {
   810     {
   779 	   	case ECreateView :
   811 	   	case ECreateView :
   780 			CreateContactFetchViewL();
   812 			CreateContactFetchViewL();
   781 		    break;
   813 		    break;
   782    					      	
   814    		
   783 	   	case EFetchContactBlock:
   815 	   	case EFetchContactBlock:
   784 	   		PRINT ( _L("Issuing the fetch request for next block") );
   816 	   		PRINT ( _L("Issuing the fetch request for next block") );
   785 			FetchlinksL();
   817 			FetchlinksL();
   786 			
   818 			
   787 			// Delay the next fetch since contact fetch is CPU intensive,
   819 			// Delay the next fetch since contact fetch is CPU intensive,
   788 			// this will give other threads a chance to use CPU
   820 			// this will give other threads a chance to use CPU
   789 			iTimer.After( timerStatus, 100000); // 100 milliseconds
   821 			iTimer.After( timerStatus, 100000); // 100 milliseconds
   790 			User::WaitForRequest( timerStatus );
   822 			User::WaitForRequest( timerStatus );
   791 			break;
   823 			break;
   792 	   						
   824 	   	
   793 	   	case EComplete:
   825 	   	case EComplete:
   794 		    PRINT ( _L("Contacts Caching FINISHED") );
   826 		    PRINT ( _L("Contacts Caching FINISHED") );
   795 		    PRINT_BOOT_PERFORMANCE ( _L("Contacts Caching FINISHED") );
   827 		    PRINT_BOOT_PERFORMANCE ( _L("Contacts Caching FINISHED") );
   796 		    break;
   828 		    break;
   797     }
   829     }
   800 // ---------------------------------------------------------------------------------
   832 // ---------------------------------------------------------------------------------
   801 // Called in case of any errros 
   833 // Called in case of any errros 
   802 // ---------------------------------------------------------------------------------
   834 // ---------------------------------------------------------------------------------
   803 TInt CPcsContactStore::RunError(TInt /*aError*/) 
   835 TInt CPcsContactStore::RunError(TInt /*aError*/) 
   804 {
   836 {
   805 	 PRINT ( _L(" Enter CPcsContactStore:: CPcsContactStore::RunError()") );
   837 	PRINT ( _L(" Enter CPcsContactStore:: CPcsContactStore::RunError()") );
   806 
   838 
   807 	 PRINT1 ( _L(" CPcsContactStore:: RunError().  Completing caching in contacts store %S with status ECachingCompleteWithErrors "), &(iUri->Des()));
   839 	PRINT1 ( _L(" CPcsContactStore:: RunError().  Completing caching in contacts store %S with status ECachingCompleteWithErrors "), &(iUri->Des()));
   808    iObserver->UpdateCachingStatus(*iUri, ECachingCompleteWithErrors);
   840     iObserver->UpdateCachingStatus(*iUri, ECachingCompleteWithErrors);
   809  	 PRINT ( _L(" End CPcsContactStore:: CPcsContactStore::RunError()") );
   841  	PRINT ( _L(" End CPcsContactStore:: CPcsContactStore::RunError()") );
   810 	return KErrNone;
   842 	return KErrNone;
   811 }
   843 }
   812 
   844 
   813 // ---------------------------------------------------------------------------------
   845 // ---------------------------------------------------------------------------------
   814 // Read the fields to cache from the central repository
   846 // Read the fields to cache from the central repository
   885 			break;
   917 			break;
   886 		}
   918 		}
   887 	}
   919 	}
   888 	
   920 	
   889 }
   921 }
   890 
   922 // ---------------------------------------------------------------------------------
       
   923 // Checks MyCard extension of contact
       
   924 // ---------------------------------------------------------------------------------
       
   925 TBool CPcsContactStore::IsMyCard( const MVPbkBaseContact& aContact )
       
   926     {
       
   927     TBool isMyCard( EFalse);
       
   928     // this is temporary solution to hide own contact from phonebook contacts list,
       
   929     // TODO remove this code when we can hide own contact with contact model
       
   930 
       
   931     MVPbkBaseContact& contact = const_cast<MVPbkBaseContact&>( aContact );
       
   932     TAny* extension = contact.BaseContactExtension( KVPbkBaseContactExtension2Uid );
       
   933 
       
   934     if( extension )
       
   935         {
       
   936         MVPbkBaseContact2* baseContactExtension = static_cast<MVPbkBaseContact2*>( extension );
       
   937         TInt error( KErrNone );
       
   938         isMyCard = baseContactExtension->IsOwnContact( error );
       
   939         }
       
   940     
       
   941     return isMyCard;
       
   942     }
   891 // End of file
   943 // End of file