uiservicetab/vimpststorage/src/cvimpststoragevpbklocalstore.cpp
branchRCL_3
changeset 14 9fdee5e1da30
parent 0 5e5d6b214f4f
equal deleted inserted replaced
13:796276a1bdcc 14:9fdee5e1da30
    22 #include "cvimpststoragevpbkstorehandler.h"
    22 #include "cvimpststoragevpbkstorehandler.h"
    23 
    23 
    24 #include <MVPbkContactView.h>
    24 #include <MVPbkContactView.h>
    25 #include <CVPbkContactIdConverter.h>
    25 #include <CVPbkContactIdConverter.h>
    26 #include "mvimpststorageserviceview.h"
    26 #include "mvimpststorageserviceview.h"
    27 #include "vimpstdebugtrace.h" 
    27 #include "uiservicetabtracer.h"
    28 #include "tvimpstconsts.h"
    28 #include "tvimpstconsts.h"
    29 #include <CVPbkContactLinkArray.h>
    29 #include <CVPbkContactLinkArray.h>
    30 #include <MVPbkContactLink.h>
    30 #include <MVPbkContactLink.h>
    31 #include "cvimpststoragecontact.h"
    31 #include "cvimpststoragecontact.h"
    32 #include "vimpststorageutils.h"
    32 #include "vimpststorageutils.h"
    45 CVIMPSTStorageVPbkLocalStore:: CVIMPSTStorageVPbkLocalStore( MVIMPSTStorageServiceCacheWriter& aServiceCacheWriter ):
    45 CVIMPSTStorageVPbkLocalStore:: CVIMPSTStorageVPbkLocalStore( MVIMPSTStorageServiceCacheWriter& aServiceCacheWriter ):
    46 	CActive( CActive::EPriorityIdle ),
    46 	CActive( CActive::EPriorityIdle ),
    47     iServiceCacheWriter( aServiceCacheWriter ),
    47     iServiceCacheWriter( aServiceCacheWriter ),
    48     iFetchStep( EFetchingUnknown )
    48     iFetchStep( EFetchingUnknown )
    49     { 
    49     { 
    50     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CVIMPSTStorageVPbkLocalStore()") ); 
    50 	TRACER_AUTO;
    51     CActiveScheduler::Add( this );
    51     CActiveScheduler::Add( this );
    52     }
    52     }
    53 
    53 
    54 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    55 // CVIMPSTStorageVPbkLocalStore::NewL
    55 // CVIMPSTStorageVPbkLocalStore::NewL
    57 //
    57 //
    58 CVIMPSTStorageVPbkLocalStore* CVIMPSTStorageVPbkLocalStore::NewL( const TDesC& aContactDb,
    58 CVIMPSTStorageVPbkLocalStore* CVIMPSTStorageVPbkLocalStore::NewL( const TDesC& aContactDb,
    59     															 const TDesC& aServiceName,
    59     															 const TDesC& aServiceName,
    60     															 MVIMPSTStorageServiceCacheWriter& aServiceCacheWriter )
    60     															 MVIMPSTStorageServiceCacheWriter& aServiceCacheWriter )
    61     {
    61     {
    62     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::NewL() begin") ); 
    62 	TRACER_AUTO;
    63     CVIMPSTStorageVPbkLocalStore* self = NewLC( aContactDb,  
    63     CVIMPSTStorageVPbkLocalStore* self = NewLC( aContactDb,  
    64     										   aServiceName,
    64     										   aServiceName,
    65 											  aServiceCacheWriter);
    65 											  aServiceCacheWriter);
    66     CleanupStack::Pop( self );
    66     CleanupStack::Pop( self );
    67     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::NewL() end") ); 
       
    68     return self;
    67     return self;
    69     }
    68     }
    70 
    69 
    71 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    72 // CVIMPSTStorageVPbkLocalStore::NewLC
    71 // CVIMPSTStorageVPbkLocalStore::NewLC
    75 CVIMPSTStorageVPbkLocalStore* 
    74 CVIMPSTStorageVPbkLocalStore* 
    76     CVIMPSTStorageVPbkLocalStore::NewLC( const TDesC& aContactDb, 
    75     CVIMPSTStorageVPbkLocalStore::NewLC( const TDesC& aContactDb, 
    77     									const TDesC& aServiceName,
    76     									const TDesC& aServiceName,
    78     									MVIMPSTStorageServiceCacheWriter& aServiceCacheWriter  )
    77     									MVIMPSTStorageServiceCacheWriter& aServiceCacheWriter  )
    79     {
    78     {
    80     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::NewLC() begin") );
    79 	TRACER_AUTO;
       
    80     
    81     CVIMPSTStorageVPbkLocalStore* self =
    81     CVIMPSTStorageVPbkLocalStore* self =
    82         new (ELeave) CVIMPSTStorageVPbkLocalStore(aServiceCacheWriter);
    82         new (ELeave) CVIMPSTStorageVPbkLocalStore(aServiceCacheWriter);
    83     CleanupStack::PushL( self );
    83     CleanupStack::PushL( self );
    84     self->ConstructL( aContactDb, aServiceName );
    84     self->ConstructL( aContactDb, aServiceName );
    85     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::NewLC() end") );
    85    
    86     return self;
    86     return self;
    87     }
    87     }
    88 // ---------------------------------------------------------------------------
    88 // ---------------------------------------------------------------------------
    89 // CVIMPSTStorageVPbkLocalStore::ConstructL
    89 // CVIMPSTStorageVPbkLocalStore::ConstructL
    90 // ---------------------------------------------------------------------------
    90 // ---------------------------------------------------------------------------
    91 //
    91 //
    92 void CVIMPSTStorageVPbkLocalStore::ConstructL( const TDesC& aContactDb, const TDesC& aServiceName )
    92 void CVIMPSTStorageVPbkLocalStore::ConstructL( const TDesC& aContactDb, const TDesC& aServiceName )
    93     {
    93     {
    94     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() begin") );
    94 	TRACER_AUTO;
       
    95    
    95     iVPbkStoreHandler = CVIMPSTStorageVPbkStoreHandler::NewL( aContactDb ,aServiceName, *this,ETrue );
    96     iVPbkStoreHandler = CVIMPSTStorageVPbkStoreHandler::NewL( aContactDb ,aServiceName, *this,ETrue );
    96     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() iVPbkStoreHandler created") );
    97     TRACE( "iVPbkStoreHandler created" );
    97      //construct the persistent store name
    98      //construct the persistent store name
    98     iLocalDBName = HBufC::NewL( aServiceName.Length()+ KStorageExtn().Length());
    99     iLocalDBName = HBufC::NewL( aServiceName.Length()+ KStorageExtn().Length());
    99     TPtr iLocalDBNamePtr = iLocalDBName->Des();
   100     TPtr iLocalDBNamePtr = iLocalDBName->Des();
   100     iLocalDBNamePtr.Append(aServiceName);
   101     iLocalDBNamePtr.Append(aServiceName);
   101     _LIT(KSpecialChar ,"/\\:*?<>\"");
   102     _LIT(KSpecialChar ,"/\\:*?<>\"");
   102     AknTextUtils :: StripCharacters(iLocalDBNamePtr,KSpecialChar); 
   103     AknTextUtils :: StripCharacters(iLocalDBNamePtr,KSpecialChar); 
   103     iLocalDBNamePtr.Append(KStorageExtn());    
   104     iLocalDBNamePtr.Append(KStorageExtn());    
   104     TRACE( T_LIT("iLocalDBNamePtr: %S"), &iLocalDBNamePtr );
   105     TRACE( "iLocalDBNamePtr: %S", &iLocalDBNamePtr );
   105     MVPbkContactStore* defaultStore = iVPbkStoreHandler->GetDefaultStoreL( aContactDb );
   106     MVPbkContactStore* defaultStore = iVPbkStoreHandler->GetDefaultStoreL( aContactDb );
   106     User::LeaveIfNull(defaultStore);  
   107     User::LeaveIfNull(defaultStore);  
   107     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() defaultStore retrived") );
   108     TRACE("defaultStore retrived" );
   108     iIdConverter = CVPbkContactIdConverter::NewL(*defaultStore);
   109     iIdConverter = CVPbkContactIdConverter::NewL(*defaultStore);
   109     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() iIdConverter created") ); 
   110     TRACE( "iIdConverter created" ); 
   110     User::LeaveIfError( iFs.Connect() );
   111     User::LeaveIfError( iFs.Connect() );
   111     // Open existing or create new database.
   112     // Open existing or create new database.
   112     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() connected to file server") ); 
   113     TRACE( "connected to file server" ); 
   113 	if ( DbExists() )
   114 	if ( DbExists() )
   114 		{
   115 		{
   115 		TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() local db exist") ); 
   116 		TRACE( "local db exist" ); 
   116         OpenDbL();
   117         OpenDbL();
   117         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() open success") );
   118         TRACE( "open success" );
   118 		}
   119 		}
   119 	else
   120 	else
   120 		{
   121 		{
   121 		TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() local db not exist") );
   122 		TRACE("local db not exist" );
   122         DoFreespaceLevelCheckL( KEmptyDbSize );
   123         DoFreespaceLevelCheckL( KEmptyDbSize );
   123         CreateDbL();
   124         CreateDbL();
   124         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() local db created") );
   125         TRACE("local db created");
   125 		}
   126 		}
   126     OpenTableL();
   127     OpenTableL();
   127     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() OpenTableL success ") );
   128     TRACE("OpenTableL success " );
   128     iColset = iDb.ColSetL( KContactTable );    
   129     iColset = iDb.ColSetL( KContactTable );    
   129    	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() iColset is set") );
   130    	TRACE( " iColset is set" );
   130     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ConstructL() end") );	
   131   
   131     }
   132     }
   132 
   133 
   133 // ---------------------------------------------------------------------------
   134 // ---------------------------------------------------------------------------
   134 // CVIMPSTStorageVPbkLocalStore::
   135 // CVIMPSTStorageVPbkLocalStore::
   135 //      ~CVIMPSTStorageVPbkLocalStore
   136 //      ~CVIMPSTStorageVPbkLocalStore
   136 // ---------------------------------------------------------------------------
   137 // ---------------------------------------------------------------------------
   137 //
   138 //
   138 CVIMPSTStorageVPbkLocalStore::~CVIMPSTStorageVPbkLocalStore()
   139 CVIMPSTStorageVPbkLocalStore::~CVIMPSTStorageVPbkLocalStore()
   139     {
   140     {
   140     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::~CVIMPSTStorageVPbkLocalStore() begin") );
   141 	TRACER_AUTO;
       
   142     
   141     iRetrivedContactArray.ResetAndDestroy();
   143     iRetrivedContactArray.ResetAndDestroy();
   142     TRAP_IGNORE( ResetAndDestroyLocalArrayL() );
   144     TRAP_IGNORE( ResetAndDestroyLocalArrayL() );
   143         
   145         
   144     CloseTable();
   146     CloseTable();
   145     delete iColset;
   147     delete iColset;
   148     
   150     
   149     delete iLocalDBName;
   151     delete iLocalDBName;
   150     delete iIdConverter;	        
   152     delete iIdConverter;	        
   151     delete iInviteId;
   153     delete iInviteId;
   152     delete iVPbkStoreHandler;
   154     delete iVPbkStoreHandler;
   153     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::~CVIMPSTStorageVPbkLocalStore() end") );
   155    
   154     }
   156     }
   155  
   157  
   156  // ---------------------------------------------------------------------------
   158  // ---------------------------------------------------------------------------
   157 // CVIMPSTStorageVPbkLocalStore::
   159 // CVIMPSTStorageVPbkLocalStore::
   158 //      ResetAndDestroyLocalArrayL
   160 //      ResetAndDestroyLocalArrayL
   159 // ---------------------------------------------------------------------------
   161 // ---------------------------------------------------------------------------
   160 //
   162 //
   161 void CVIMPSTStorageVPbkLocalStore::ResetAndDestroyLocalArrayL()
   163 void CVIMPSTStorageVPbkLocalStore::ResetAndDestroyLocalArrayL()
   162     {
   164     {
   163     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ResetAndDestroyLocalArrayL() begin") );
   165 	TRACER_AUTO;
   164     TInt count = iFetchContactsToBeAdded.Count();
   166     TInt count = iFetchContactsToBeAdded.Count();
   165    	while( count )
   167    	while( count )
   166 	   	{
   168 	   	{
   167 	   	TVIMPSTContactInfo contactInf = iFetchContactsToBeAdded[ count-1 ];
   169 	   	TVIMPSTContactInfo contactInf = iFetchContactsToBeAdded[ count-1 ];
   168 	   	iFetchContactsToBeAdded.Remove( count-1 );
   170 	   	iFetchContactsToBeAdded.Remove( count-1 );
   173          // not exist need to add 
   175          // not exist need to add 
   174         iFetchContactsToBeAdded.Compress();	
   176         iFetchContactsToBeAdded.Compress();	
   175         count = iFetchContactsToBeAdded.Count();
   177         count = iFetchContactsToBeAdded.Count();
   176 	   	}
   178 	   	}
   177 	iFetchContactsToBeAdded.Reset();
   179 	iFetchContactsToBeAdded.Reset();
   178     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ResetAndDestroyLocalArrayL() end") );
   180     
   179     }
   181     }
   180  
   182  
   181 // ----------------------------------------------------------
   183 // ----------------------------------------------------------
   182 // CVIMPSTStorageVPbkLocalStore::LocalStore
   184 // CVIMPSTStorageVPbkLocalStore::LocalStore
   183 // ----------------------------------------------------------
   185 // ----------------------------------------------------------
   184 //
   186 //
   185 TBool CVIMPSTStorageVPbkLocalStore::LocalStore() const 
   187 TBool CVIMPSTStorageVPbkLocalStore::LocalStore() const 
   186 	{
   188 	{
   187 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::LocalStore() local store") );
   189 	TRACER_AUTO;
   188 	return ETrue;
   190 	return ETrue;
   189 	}
   191 	}
   190 // ---------------------------------------------------------------------------
   192 // ---------------------------------------------------------------------------
   191 // CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL
   193 // CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL
   192 // ---------------------------------------------------------------------------
   194 // ---------------------------------------------------------------------------
   193 //
   195 //
   194 void CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL(TVIMPSTVPbkStoreEvent aVPbkStoreEvent) 
   196 void CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL(TVIMPSTVPbkStoreEvent aVPbkStoreEvent) 
   195 	{
   197 	{
   196 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() begin") );
   198 	TRACER_AUTO;
   197 	switch( aVPbkStoreEvent.iEventType )
   199 	switch( aVPbkStoreEvent.iEventType )
   198 	    {
   200 	    {
   199 	    case EVPbkContactReadCompleted:
   201 	    case EVPbkContactReadCompleted:
   200 	    	{
   202 	    	{
   201 	    	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactReadCompleted started") );
   203 	    	TRACE( " EVPbkContactReadCompleted started" );
   202 	    	iServiceCacheWriter.NotifyServiceViewL(TVIMPSTEnums::EStorageContactReadComplete);
   204 	    	iServiceCacheWriter.NotifyServiceViewL(TVIMPSTEnums::EStorageContactReadComplete);
   203 	    	if( iFetchStep == EFetchingCalled )
   205 	    	if( iFetchStep == EFetchingCalled )
   204 		    	{
   206 		    	{
   205 		    	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactReadCompleted EFetchingCalled ") );
   207 		    	TRACE( " EVPbkContactReadCompleted EFetchingCalled " );
   206 		    	IssueRequest();		
   208 		    	IssueRequest();		
   207 		    	}
   209 		    	}
   208 	    	iFetchStep = EContactReadComplete;
   210 	    	iFetchStep = EContactReadComplete;
   209 	    	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EContactReadComplete completed ") );
   211 	    	TRACE( "EContactReadComplete completed " );
   210 		  	break;
   212 		  	break;
   211 	    	}
   213 	    	}
   212 	    case EVPbkContactReading:
   214 	    case EVPbkContactReading:
   213 		    {
   215 		    {
   214 		    // a contact entry has been created in virtual database store
   216 		    // a contact entry has been created in virtual database store
   215 			// create the cache contact
   217 			// create the cache contact
   216 			TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   218 			TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   217 			TDbColNo colNo = iColset->ColNo( KContactId );
   219 			TDbColNo colNo = iColset->ColNo( KContactId );
   218 		    if ( SeekRowL( colNo, linkId ) )
   220 		    if ( SeekRowL( colNo, linkId ) )
   219 				{
   221 				{
   220 				TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactReading contact") );
   222 				TRACE( "EVPbkContactReading contact" );
   221 				/*
   223 				/*
   222 					*	This is local store, that is phone book and service tab shares only one cdb file.
   224 					*	This is local store, that is phone book and service tab shares only one cdb file.
   223 					* 	in that case, if somebody edits the cdb file from contacts tab, then also we get the 
   225 					* 	in that case, if somebody edits the cdb file from contacts tab, then also we get the 
   224 					* 	callback, then checking for entry in db table makes sens.. 
   226 					* 	callback, then checking for entry in db table makes sens.. 
   225 				*/
   227 				*/
   250 			// create the cache contact
   252 			// create the cache contact
   251 			TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   253 			TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   252 			TDbColNo colNo = iColset->ColNo( KContactId );
   254 			TDbColNo colNo = iColset->ColNo( KContactId );
   253 			if( iFetchStep  == EFetchingOn )
   255 			if( iFetchStep  == EFetchingOn )
   254 		         {
   256 		         {
   255 		         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactFetching contact") );
   257 		         TRACE( "EVPbkContactFetching contact" );
   256 		         WriteToStoreDbL( linkId );
   258 		         WriteToStoreDbL( linkId );
   257 		         iServiceCacheWriter.AddContactToCacheL (*aVPbkStoreEvent.iContactLink , 
   259 		         iServiceCacheWriter.AddContactToCacheL (*aVPbkStoreEvent.iContactLink , 
   258 		                 aVPbkStoreEvent.iUserId ,
   260 		                 aVPbkStoreEvent.iUserId ,
   259 		                 aVPbkStoreEvent.iDisplayName ,
   261 		                 aVPbkStoreEvent.iDisplayName ,
   260 		                 aVPbkStoreEvent.iAvatarContent,
   262 		                 aVPbkStoreEvent.iAvatarContent,
   261 		                 TVIMPSTEnums::EStorageContactFetching );
   263 		                 TVIMPSTEnums::EStorageContactFetching );
   262 		      	IssueRequest();		
   264 		      	IssueRequest();		
   263 				}
   265 				}
   264 			else if ( SeekRowL( colNo, linkId ) )
   266 			else if ( SeekRowL( colNo, linkId ) )
   265 				{
   267 				{
   266 				TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactAdded start") );
   268 				TRACE( " EVPbkContactAdded start" );
   267 				/*
   269 				/*
   268 					*	This is local store, that is phone book and service tab shares only one cdb file.
   270 					*	This is local store, that is phone book and service tab shares only one cdb file.
   269 					* 	in that case, if somebody edits the cdb file from contacts tab, then also we get the 
   271 					* 	in that case, if somebody edits the cdb file from contacts tab, then also we get the 
   270 					* 	callback, then checking for entry in db table makes sens.. 
   272 					* 	callback, then checking for entry in db table makes sens.. 
   271 				*/
   273 				*/
   283 				iServiceCacheWriter.AddContactToCacheL (*aVPbkStoreEvent.iContactLink , 
   285 				iServiceCacheWriter.AddContactToCacheL (*aVPbkStoreEvent.iContactLink , 
   284 										 aVPbkStoreEvent.iUserId ,
   286 										 aVPbkStoreEvent.iUserId ,
   285 										 aVPbkStoreEvent.iDisplayName,
   287 										 aVPbkStoreEvent.iDisplayName,
   286 										 aVPbkStoreEvent.iAvatarContent,
   288 										 aVPbkStoreEvent.iAvatarContent,
   287 										 TVIMPSTEnums::EStorageEventContactAddition  );
   289 										 TVIMPSTEnums::EStorageEventContactAddition  );
   288 				TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactAdded completed") );
   290 				TRACE( "EVPbkContactAdded completed" );
   289 				}
   291 				}
   290 			else if(  iInviteId )
   292 			else if(  iInviteId )
   291 			    {
   293 			    {
   292 			    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() iInviteId accepted") );
   294 			    TRACE( "iInviteId accepted" );
   293 			    if( IsSameContactIdL( *iInviteId, aVPbkStoreEvent.iUserId ) )
   295 			    if( IsSameContactIdL( *iInviteId, aVPbkStoreEvent.iUserId ) )
   294 			        {
   296 			        {
   295 			        WriteToStoreDbL( linkId );
   297 			        WriteToStoreDbL( linkId );
   296 			        iServiceCacheWriter.AddContactToCacheL (*aVPbkStoreEvent.iContactLink , 
   298 			        iServiceCacheWriter.AddContactToCacheL (*aVPbkStoreEvent.iContactLink , 
   297 			                aVPbkStoreEvent.iUserId ,
   299 			                aVPbkStoreEvent.iUserId ,
   299 			                aVPbkStoreEvent.iAvatarContent,
   301 			                aVPbkStoreEvent.iAvatarContent,
   300 			                TVIMPSTEnums::EStorageEventContactAddition );
   302 			                TVIMPSTEnums::EStorageEventContactAddition );
   301 			        delete iInviteId;
   303 			        delete iInviteId;
   302 			        iInviteId = NULL;
   304 			        iInviteId = NULL;
   303 			        }
   305 			        }
   304                  TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() iInviteId accepted sucess") );
   306                  TRACE( "iInviteId accepted sucess" );
   305 			    }
   307 			    }
   306 			break;	
   308 			break;	
   307 			}
   309 			}
   308 	   	case EVPbkContactSynchronizing:
   310 	   	case EVPbkContactSynchronizing:
   309 	   	    {
   311 	   	    {
   310 	   	    TRACE( T_LIT("CVIMPSTStorageVPbkServerStore::HandleVPbkStoreEventL EVPbkContactSynchronizing " ) );
   312 	   	    TRACE( "EVPbkContactSynchronizing "  );
   311 	   	    // a contact entry has been created in virtual database store
   313 	   	    // a contact entry has been created in virtual database store
   312 	   	    // create the cache contact
   314 	   	    // create the cache contact
   313 	   	    TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   315 	   	    TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   314 	   	    TDbColNo colNo = iColset->ColNo( KContactId );
   316 	   	    TDbColNo colNo = iColset->ColNo( KContactId );
   315 	   	    if ( SeekRowL( colNo, linkId ) )
   317 	   	    if ( SeekRowL( colNo, linkId ) )
   336 	   	                aVPbkStoreEvent.iAvatarContent,
   338 	   	                aVPbkStoreEvent.iAvatarContent,
   337 	   	                TVIMPSTEnums::EStorageContactFetching  );
   339 	   	                TVIMPSTEnums::EStorageContactFetching  );
   338 	   	        }
   340 	   	        }
   339 	   	   if(iFetchStep == EFetchingOn)          
   341 	   	   if(iFetchStep == EFetchingOn)          
   340                {
   342                {
   341                TRACE( T_LIT("CVIMPSTStorageVPbkServerStore::HandleVPbkStoreEventL  EVPbkContactSynchronizing fetchin on" ) );
   343                TRACE( "EVPbkContactSynchronizing fetchin on" );
   342                IssueRequest();
   344                IssueRequest();
   343                }
   345                }
   344 	   	    TRACE( T_LIT("CVIMPSTStorageVPbkServerStore::HandleVPbkStoreEventL EVPbkContactSynchronizing completed" ) );
   346 	   	    TRACE(" EVPbkContactSynchronizing completed"  );
   345 	   	    break;
   347 	   	    break;
   346 	   	    }
   348 	   	    }
   347 		case EVPbkContactDeleted:
   349 		case EVPbkContactDeleted:
   348 		    {
   350 		    {
   349 		    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactDeleted") );
   351 		    TRACE( "EVPbkContactDeleted" );
   350 		    TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   352 		    TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   351 		    // a contact entry has been deleted from virtual database store
   353 		    // a contact entry has been deleted from virtual database store
   352 		    TDbColNo colNo = iColset->ColNo( KContactId );
   354 		    TDbColNo colNo = iColset->ColNo( KContactId );
   353 		    if ( SeekRowL( colNo, linkId ) )
   355 		    if ( SeekRowL( colNo, linkId ) )
   354 		        { 
   356 		        { 
   355 		        TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactDeleted found in db") );
   357 		        TRACE( "EVPbkContactDeleted found in db" );
   356 		        // contatc found in local database ,delete from local database 
   358 		        // contatc found in local database ,delete from local database 
   357 		        DeleteContactFromInternalStoreL( linkId );
   359 		        DeleteContactFromInternalStoreL( linkId );
   358 		        TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactDeleted deleted from db") );
   360 		        TRACE( "EVPbkContactDeleted deleted from db" );
   359 		         // delete from cache contact
   361 		         // delete from cache contact
   360 		    	iServiceCacheWriter.RemoveContactFromCacheL(*aVPbkStoreEvent.iContactLink, 
   362 		    	iServiceCacheWriter.RemoveContactFromCacheL(*aVPbkStoreEvent.iContactLink, 
   361 		    												TVIMPSTEnums::EStorageEventDeleteFromPbk );
   363 		    												TVIMPSTEnums::EStorageEventDeleteFromPbk );
   362 		    	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactDeleted deleted from cache") );
   364 		    	TRACE( "EVPbkContactDeleted deleted from cache" );
   363 		        }
   365 		        }
   364 		    break;	 
   366 		    break;	 
   365 		    }
   367 		    }
   366 		case EVPbkContactChanged:
   368 		case EVPbkContactChanged:
   367 		    {
   369 		    {
   368 		    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactChanged ") );
   370 		    TRACE( "EVPbkContactChanged ");
   369 		    TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   371 		    TInt32 linkId = iIdConverter->LinkToIdentifier(*aVPbkStoreEvent.iContactLink );
   370 		    TDbColNo colNo = iColset->ColNo( KContactId );
   372 		    TDbColNo colNo = iColset->ColNo( KContactId );
   371 		    if ( SeekRowL( colNo, linkId ) )
   373 		    if ( SeekRowL( colNo, linkId ) )
   372 		       {
   374 		       {
   373 		       TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactChanged found in local db") );
   375 		       TRACE( "EVPbkContactChanged found in local db" );
   374 		       // found in the list update it
   376 		       // found in the list update it
   375 		       iServiceCacheWriter.UpdateCacheContactL(*aVPbkStoreEvent.iContactLink , 
   377 		       iServiceCacheWriter.UpdateCacheContactL(*aVPbkStoreEvent.iContactLink , 
   376 					    						 	 aVPbkStoreEvent.iUserId ,
   378 					    						 	 aVPbkStoreEvent.iUserId ,
   377 					    							 aVPbkStoreEvent.iDisplayName,
   379 					    							 aVPbkStoreEvent.iDisplayName,
   378 					    							 aVPbkStoreEvent.iAvatarContent );
   380 					    							 aVPbkStoreEvent.iAvatarContent );
   379 			   TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactChanged changed in cache") );
   381 			   TRACE( "EVPbkContactChanged changed in cache");
   380 		       }
   382 		       }
   381 		    break;	
   383 		    break;	
   382 		    }
   384 		    }
   383 	    case EVPbkContactRetriving:
   385 	    case EVPbkContactRetriving:
   384 		    {
   386 		    {
   385 		    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactRetriving") );
   387 		    TRACE( "EVPbkContactRetriving");
   386 		    // in case of local we allow all 
   388 		    // in case of local we allow all 
   387 		    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactRetriving valid Id") );
   389 		    TRACE( "EVPbkContactRetriving valid Id");
   388 			CVIMPSTStorageContact* retrivedContact = CVIMPSTStorageContact::NewL( aVPbkStoreEvent.iUserId ,
   390 			CVIMPSTStorageContact* retrivedContact = CVIMPSTStorageContact::NewL( aVPbkStoreEvent.iUserId ,
   389 											    								  aVPbkStoreEvent.iDisplayName,
   391 											    								  aVPbkStoreEvent.iDisplayName,
   390 											    								  *aVPbkStoreEvent.iContactLink,
   392 											    								  *aVPbkStoreEvent.iContactLink,
   391 											    								  aVPbkStoreEvent.iAvatarContent);
   393 											    								  aVPbkStoreEvent.iAvatarContent);
   392 			iRetrivedContactArray.Append( retrivedContact ); // takes the ownership of retrivedContact
   394 			iRetrivedContactArray.Append( retrivedContact ); // takes the ownership of retrivedContact
   393 			TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkContactRetriving valid Id added") );
   395 			TRACE( "EVPbkContactRetriving valid Id added" );
   394 			// keep the backup of retrieved contacts
   396 			// keep the backup of retrieved contacts
   395 			// user can add later once it sent to server
   397 			// user can add later once it sent to server
   396 			break;	
   398 			break;	
   397 		    }
   399 		    }
   398 		case EVPbkUnknownChanges:
   400 		case EVPbkUnknownChanges:
   399 		    {
   401 		    {
   400 		    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkUnknownChanges start") );
   402 		    TRACE("EVPbkUnknownChanges start" );
   401 		    DeleteAllContactFromInternalStoreL();
   403 		    DeleteAllContactFromInternalStoreL();
   402 		    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkUnknownChanges all delete from db") );
   404 		    TRACE( " EVPbkUnknownChanges all delete from db" );
   403 		     // unknow mean all contact deleted from store
   405 		     // unknow mean all contact deleted from store
   404 		    iServiceCacheWriter.RemoveAllCacheContactsL();
   406 		    iServiceCacheWriter.RemoveAllCacheContactsL();
   405 		    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() EVPbkUnknownChanges all delete from cache") );
   407 		    TRACE( " EVPbkUnknownChanges all delete from cache" );
   406 		    break;	
   408 		    break;	
   407 		    }
   409 		    }
   408 	    default:
   410 	    default:
   409 		 	break;
   411 		 	break;
   410 	    }
   412 	    }
   411 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::HandleVPbkStoreEventL() end") );
   413 	
   412 	}
   414 	}
   413 
   415 
   414 
   416 
   415 // --------------------------------------------------------------------------
   417 // --------------------------------------------------------------------------
   416 // CVIMPSTStorageVPbkLocalStore::IssueRequest
   418 // CVIMPSTStorageVPbkLocalStore::IssueRequest
   417 // --------------------------------------------------------------------------
   419 // --------------------------------------------------------------------------
   418 //
   420 //
   419 void CVIMPSTStorageVPbkLocalStore::IssueRequest()
   421 void CVIMPSTStorageVPbkLocalStore::IssueRequest()
   420     {
   422     {
   421     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::IssueRequest() begin") );
   423 	TRACER_AUTO;
   422     if( !IsActive() )
   424     if( !IsActive() )
   423 	    {
   425 	    {
   424 	    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::IssueRequest() SetActive") );
   426 	    TRACE( "SetActive" );
   425 	    TRequestStatus* status = &iStatus;
   427 	    TRequestStatus* status = &iStatus;
   426 	    User::RequestComplete( status, KErrNone );
   428 	    User::RequestComplete( status, KErrNone );
   427 	    SetActive();
   429 	    SetActive();
   428 	    }
   430 	    }
   429 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::IssueRequest() begin") );
   431 	
   430     }
   432     }
   431     
   433     
   432 // --------------------------------------------------------------------------
   434 // --------------------------------------------------------------------------
   433 // CVIMPSTStorageVPbkLocalStore::RunL
   435 // CVIMPSTStorageVPbkLocalStore::RunL
   434 // --------------------------------------------------------------------------
   436 // --------------------------------------------------------------------------
   435 //
   437 //
   436 void CVIMPSTStorageVPbkLocalStore::RunL()
   438 void CVIMPSTStorageVPbkLocalStore::RunL()
   437     {
   439     {
   438     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunL() begin") );
   440 	TRACER_AUTO;
   439     TInt count = iFetchContactsToBeAdded.Count();
   441     TInt count = iFetchContactsToBeAdded.Count();
   440     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunL() count to be added = %d "),count );
   442     TRACE( "count to be added = %d ",count );
   441     if( !count )
   443     if( !count )
   442         {
   444         {
   443         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunL() fetch completed " ) );
   445         TRACE(" fetch completed "  );
   444         iFetchStep = EContactReadComplete;
   446         iFetchStep = EContactReadComplete;
   445         iServiceCacheWriter.NotifyServiceViewL( TVIMPSTEnums::EStorageContactFetchComplete );
   447         iServiceCacheWriter.NotifyServiceViewL( TVIMPSTEnums::EStorageContactFetchComplete );
   446 		TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunL() fetch completed notification sent" ) );     
   448 		TRACE( "fetch completed notification sent"  );     
   447 	    }
   449 	    }
   448     else
   450     else
   449         {
   451         {
   450         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunL() fetch in progress" ) );     
   452         TRACE( "fetch in progress"  );     
   451         iFetchStep  = EFetchingOn;
   453         iFetchStep  = EFetchingOn;
   452         TVIMPSTContactInfo contactInfoToAdd = iFetchContactsToBeAdded[0];
   454         TVIMPSTContactInfo contactInfoToAdd = iFetchContactsToBeAdded[0];
   453         MVIMPSTStorageContact* exist = iServiceCacheWriter.FindCacheContactByUserId( *contactInfoToAdd.iUserId );
   455         MVIMPSTStorageContact* exist = iServiceCacheWriter.FindCacheContactByUserId( *contactInfoToAdd.iUserId );
   454         if( exist )
   456         if( exist )
   455 	        {
   457 	        {
   456 	        // contact is already exist ,send the notification about this
   458 	        // contact is already exist ,send the notification about this
   457 	        iServiceCacheWriter.NotifyServiceViewL(TVIMPSTEnums::EStorageContactFetchExistInStore, exist );
   459 	        iServiceCacheWriter.NotifyServiceViewL(TVIMPSTEnums::EStorageContactFetchExistInStore, exist );
   458 	        TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunL() fetch in progress id exist" ) ); 
   460 	        TRACE( " fetch in progress id exist" ); 
   459 	        // process next
   461 	        // process next
   460 	        IssueRequest();
   462 	        IssueRequest();
   461 	        }
   463 	        }
   462 	    else
   464 	    else
   463 		    {
   465 		    {
   464 		    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunL() fetch in progress create id in store called" ) ); 
   466 		    TRACE( "fetch in progress create id in store called"  ); 
   465 		     // pass the display NAme in place of NULL
   467 		     // pass the display NAme in place of NULL
   466         	iVPbkStoreHandler->CreateVPbkContactL( *contactInfoToAdd.iUserId, *contactInfoToAdd.iDisplayName ); // process always 0th item
   468         	iVPbkStoreHandler->CreateVPbkContactL( *contactInfoToAdd.iUserId, *contactInfoToAdd.iDisplayName ); // process always 0th item
   467             }
   469             }
   468         iFetchContactsToBeAdded.Remove( 0 );
   470         iFetchContactsToBeAdded.Remove( 0 );
   469         delete contactInfoToAdd.iUserId;
   471         delete contactInfoToAdd.iUserId;
   470         contactInfoToAdd.iUserId = NULL;
   472         contactInfoToAdd.iUserId = NULL;
   471         delete contactInfoToAdd.iDisplayName;
   473         delete contactInfoToAdd.iDisplayName;
   472         contactInfoToAdd.iDisplayName = NULL ;
   474         contactInfoToAdd.iDisplayName = NULL ;
   473         iFetchContactsToBeAdded.Compress();
   475         iFetchContactsToBeAdded.Compress();
   474         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunL() fetch in progress iFetchContactsToBeAdded ,one entry removed" ) ); 
   476         TRACE( "fetch in progress iFetchContactsToBeAdded ,one entry removed"  ); 
   475         }
   477         }
   476     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunL() end") );
   478     
   477     }
   479     }
   478 
   480 
   479 // --------------------------------------------------------------------------
   481 // --------------------------------------------------------------------------
   480 // CVIMPSTStorageVPbkLocalStore::DoCancel
   482 // CVIMPSTStorageVPbkLocalStore::DoCancel
   481 // --------------------------------------------------------------------------
   483 // --------------------------------------------------------------------------
   482 //
   484 //
   483 void CVIMPSTStorageVPbkLocalStore::DoCancel()
   485 void CVIMPSTStorageVPbkLocalStore::DoCancel()
   484     {
   486     {
   485     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DoCancel()") );
   487 	TRACER_AUTO;
   486     }
   488     }
   487 
   489 
   488 // --------------------------------------------------------------------------
   490 // --------------------------------------------------------------------------
   489 // CVIMPSTStorageVPbkLocalStore::RunError
   491 // CVIMPSTStorageVPbkLocalStore::RunError
   490 // --------------------------------------------------------------------------
   492 // --------------------------------------------------------------------------
   491 //
   493 //
   492 TInt CVIMPSTStorageVPbkLocalStore::RunError( TInt aError )
   494 TInt CVIMPSTStorageVPbkLocalStore::RunError( TInt aError )
   493     { 
   495     { 
   494     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RunError()") );   
   496 	TRACER_AUTO;  
   495     return aError;
   497     return aError;
   496     }
   498     }
   497 
   499 
   498 //////////////////////////////////////////////////////////
   500 //////////////////////////////////////////////////////////
   499 // ---------------------------------------------------------------------------
   501 // ---------------------------------------------------------------------------
   502 // 
   504 // 
   503 TInt CVIMPSTStorageVPbkLocalStore::CreateVPbkContactL(const TDesC& aUserId, 
   505 TInt CVIMPSTStorageVPbkLocalStore::CreateVPbkContactL(const TDesC& aUserId, 
   504         										   	  const TDesC& aDisplayName ,
   506         										   	  const TDesC& aDisplayName ,
   505         										   	  TBool aInvitationAutoAccept /* = EFalse */ )   
   507         										   	  TBool aInvitationAutoAccept /* = EFalse */ )   
   506 	{
   508 	{
   507 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateVPbkContactL() begin") ); 
   509 	TRACER_AUTO;
   508 	TInt error = KErrGeneral;
   510 	TInt error = KErrGeneral;
   509 	if( aInvitationAutoAccept)
   511 	if( aInvitationAutoAccept)
   510 	    {
   512 	    {
   511 	    TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateVPbkContactL() autoaccept add contact") ); 
   513 	    TRACE("autoaccept add contact" ); 
   512 	    delete iInviteId;
   514 	    delete iInviteId;
   513 	    iInviteId = NULL;
   515 	    iInviteId = NULL;
   514 	    iInviteId = aUserId.AllocL();
   516 	    iInviteId = aUserId.AllocL();
   515 	    error = iVPbkStoreHandler->CreateVPbkContactL( *iInviteId,aDisplayName ); 
   517 	    error = iVPbkStoreHandler->CreateVPbkContactL( *iInviteId,aDisplayName ); 
   516 	    }
   518 	    }
   517 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateVPbkContactL() error = %d"),error ); 
   519 	TRACE( "error = %d",error ); 
   518 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateVPbkContactL() begin") ); 
   520 	
   519 	return error;
   521 	return error;
   520 	}
   522 	}
   521 
   523 
   522 // ---------------------------------------------------------------------------
   524 // ---------------------------------------------------------------------------
   523 // CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL
   525 // CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL
   524 // ---------------------------------------------------------------------------
   526 // ---------------------------------------------------------------------------
   525 //  
   527 //  
   526 TInt CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL(const MVPbkContactLink& aContactLink) 
   528 TInt CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL(const MVPbkContactLink& aContactLink) 
   527 	{
   529 	{
   528 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL() begin") ); 
   530 	TRACER_AUTO;; 
   529 	TInt error = KErrNotFound;
   531 	TInt error = KErrNotFound;
   530 	// text now holds the name (or first field of the contact) 
   532 	// text now holds the name (or first field of the contact) 
   531 	TInt32 linkId = iIdConverter->LinkToIdentifier(aContactLink);
   533 	TInt32 linkId = iIdConverter->LinkToIdentifier(aContactLink);
   532 	// a contact entry has been deleted from virtual database store
   534 	// a contact entry has been deleted from virtual database store
   533 	TDbColNo colNo = iColset->ColNo( KContactId );
   535 	TDbColNo colNo = iColset->ColNo( KContactId );
   534 	if ( SeekRowL( colNo, linkId ) )
   536 	if ( SeekRowL( colNo, linkId ) )
   535 		{
   537 		{
   536 		TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL() link exist in db") ); 
   538 		TRACE( "link exist in db" ); 
   537 		// contatc found in local database ,delete from local database 
   539 		// contatc found in local database ,delete from local database 
   538 		DeleteContactFromInternalStoreL( linkId );
   540 		DeleteContactFromInternalStoreL( linkId );
   539 		TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL() link deleted from db") ); 
   541 		TRACE( "link deleted from db" ); 
   540 		// delete from cache contact
   542 		// delete from cache contact
   541 		error = iServiceCacheWriter.RemoveContactFromCacheL(aContactLink, 
   543 		error = iServiceCacheWriter.RemoveContactFromCacheL(aContactLink, 
   542 															TVIMPSTEnums::EStorageEventContactDelete );
   544 															TVIMPSTEnums::EStorageEventContactDelete );
   543 		TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL() link deleted from cache") ); 
   545 		TRACE( "link deleted from cache" ); 
   544 		}
   546 		}
   545 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL() error %d"),error );
   547 	TRACE("error %d",error );
   546 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveVPbkContactL() end") ); 
   548 	
   547     return error;
   549     return error;
   548   	}
   550   	}
   549  
   551  
   550 // ---------------------------------------------------------------------------
   552 // ---------------------------------------------------------------------------
   551 // CVIMPSTStorageVPbkLocalStore::RemoveAllVPbkContactsL
   553 // CVIMPSTStorageVPbkLocalStore::RemoveAllVPbkContactsL
   552 // ---------------------------------------------------------------------------
   554 // ---------------------------------------------------------------------------
   553 // 
   555 // 
   554 TInt CVIMPSTStorageVPbkLocalStore::RemoveAllVPbkContactsL() 
   556 TInt CVIMPSTStorageVPbkLocalStore::RemoveAllVPbkContactsL() 
   555 	{
   557 	{
   556 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveAllVPbkContactsL() begin" ) );
   558 	TRACER_AUTO;
   557 	iRetrivedContactArray.ResetAndDestroy(); 
   559 	iRetrivedContactArray.ResetAndDestroy(); 
   558 	DeleteAllContactFromInternalStoreL();
   560 	DeleteAllContactFromInternalStoreL();
   559 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveAllVPbkContactsL() all contacts deleted from db") );
   561 	TRACE( "all contacts deleted from db" );
   560 	iServiceCacheWriter.RemoveAllCacheContactsL();
   562 	iServiceCacheWriter.RemoveAllCacheContactsL();
   561 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveAllVPbkContactsL() all contacts deleted from cache") );
   563 	TRACE( "all contacts deleted from cache" );
   562 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveAllVPbkContactsL() end" ) );
   564 	
   563 	return KErrNone;// local store : delete from local store ,own user has changed
   565 	return KErrNone;// local store : delete from local store ,own user has changed
   564 	}
   566 	}
   565 // ---------------------------------------------------------------------------
   567 // ---------------------------------------------------------------------------
   566 // CVIMPSTStorageVPbkLocalStore::RetrieveVPbkXSPIdL
   568 // CVIMPSTStorageVPbkLocalStore::RetrieveVPbkXSPIdL
   567 // ---------------------------------------------------------------------------
   569 // ---------------------------------------------------------------------------
   568 //  
   570 //  
   569 TInt CVIMPSTStorageVPbkLocalStore::RetrieveVPbkXSPIdL(const TDesC8& aPackedLinks ) 
   571 TInt CVIMPSTStorageVPbkLocalStore::RetrieveVPbkXSPIdL(const TDesC8& aPackedLinks ) 
   570 	{
   572 	{
   571 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RetrieveVPbkXSPIdL() begin" ) );
   573 	TRACER_AUTO;
   572 	iRetrivedContactArray.ResetAndDestroy();
   574 	iRetrivedContactArray.ResetAndDestroy();
   573 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RetrieveVPbkXSPIdL() iRetrivedContactArray Reset" ) );
   575 	TRACE( " iRetrivedContactArray Reset"  );
   574     iVPbkStoreHandler->RetrieveVPbkContactL( aPackedLinks );
   576     iVPbkStoreHandler->RetrieveVPbkContactL( aPackedLinks );
   575     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RetrieveVPbkXSPIdL() iRetrivedContactArray count= %d " ),iRetrivedContactArray.Count() );
   577     TRACE( "iRetrivedContactArray count= %d " ,iRetrivedContactArray.Count() );
   576     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RetrieveVPbkXSPIdL() end " ) );
   578     
   577     return iRetrivedContactArray.Count();
   579     return iRetrivedContactArray.Count();
   578     }
   580     }
   579 
   581 
   580  // ---------------------------------------------------------------------------
   582  // ---------------------------------------------------------------------------
   581 // CVIMPSTStorageVPbkLocalStore::GetRetrieveVPbkXSPIdL
   583 // CVIMPSTStorageVPbkLocalStore::GetRetrieveVPbkXSPIdL
   582 // ---------------------------------------------------------------------------
   584 // ---------------------------------------------------------------------------
   583 //  
   585 //  
   584 const TDesC& CVIMPSTStorageVPbkLocalStore::GetRetrieveVPbkXSPIdL(TInt aIndex ) 
   586 const TDesC& CVIMPSTStorageVPbkLocalStore::GetRetrieveVPbkXSPIdL(TInt aIndex ) 
   585 	{
   587 	{
   586 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::GetRetrieveVPbkXSPIdL() begin" ) );
   588 	TRACER_AUTO;
   587 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::GetRetrieveVPbkXSPIdL() aIndex = %d" ),aIndex );
   589 	TRACE( "aIndex = %d" ,aIndex );
   588 	MVIMPSTStorageContact* contact = NULL;
   590 	MVIMPSTStorageContact* contact = NULL;
   589 	if( aIndex >= 0 && aIndex < iRetrivedContactArray.Count() )
   591 	if( aIndex >= 0 && aIndex < iRetrivedContactArray.Count() )
   590         {
   592         {
   591         contact = iRetrivedContactArray[ aIndex ];
   593         contact = iRetrivedContactArray[ aIndex ];
   592         }
   594         }
   593     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::GetRetrieveVPbkXSPIdL() end" ) );   
   595        
   594     return contact ? contact->UserId() : KNullDesC ; 	
   596     return contact ? contact->UserId() : KNullDesC ; 	
   595 	}
   597 	}
   596 // ---------------------------------------------------------------------------
   598 // ---------------------------------------------------------------------------
   597 // CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL
   599 // CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL
   598 // ---------------------------------------------------------------------------
   600 // ---------------------------------------------------------------------------
   599 // 
   601 // 
   600 TInt CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL( TInt aIndexToUse  )   
   602 TInt CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL( TInt aIndexToUse  )   
   601     {
   603     {
   602     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL() begin" ) );
   604 	TRACER_AUTO;
   603     if( aIndexToUse < 0 && aIndexToUse >= iRetrivedContactArray.Count() )
   605     if( aIndexToUse < 0 && aIndexToUse >= iRetrivedContactArray.Count() )
   604         {
   606         {
   605         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL() argument error" ) );
   607         TRACE( " argument error"  );
   606         return KErrArgument;
   608         return KErrArgument;
   607         }
   609         }
   608     TInt error = KErrAlreadyExists;
   610     TInt error = KErrAlreadyExists;
   609     MVIMPSTStorageContact* retrivedContact = iRetrivedContactArray[ aIndexToUse ];
   611     MVIMPSTStorageContact* retrivedContact = iRetrivedContactArray[ aIndexToUse ];
   610     
   612     
   614 	    {
   616 	    {
   615 	    exist = iServiceCacheWriter.FindCacheContactByLink( *contactLink  );		
   617 	    exist = iServiceCacheWriter.FindCacheContactByLink( *contactLink  );		
   616 	    }
   618 	    }
   617     if( !exist )
   619     if( !exist )
   618         {
   620         {
   619         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL() adding to  cache" ) );
   621         TRACE( "adding to  cache" );
   620         MVPbkContactLink* link = retrivedContact->ContactLink();
   622         MVPbkContactLink* link = retrivedContact->ContactLink();
   621         if( link )
   623         if( link )
   622 			{
   624 			{
   623 			CVIMPSTStorageContact* contactToAdd = CVIMPSTStorageContact::NewL( retrivedContact->UserId() ,
   625 			CVIMPSTStorageContact* contactToAdd = CVIMPSTStorageContact::NewL( retrivedContact->UserId() ,
   624 												    					 	  retrivedContact->Name(),
   626 												    					 	  retrivedContact->Name(),
   626 																	    	 retrivedContact->AvatarContent()
   628 																	    	 retrivedContact->AvatarContent()
   627 																	    	 );
   629 																	    	 );
   628 			CleanupStack::PushL( contactToAdd );
   630 			CleanupStack::PushL( contactToAdd );
   629 			TInt32 linkId = iIdConverter->LinkToIdentifier( *link );
   631 			TInt32 linkId = iIdConverter->LinkToIdentifier( *link );
   630 			error = iServiceCacheWriter.AddStorageContactToCacheL( contactToAdd ); // contactToAdd ownership is transfered
   632 			error = iServiceCacheWriter.AddStorageContactToCacheL( contactToAdd ); // contactToAdd ownership is transfered
   631 			TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL() adding to  cache done" ) );
   633 			TRACE( " adding to  cache done"  );
   632 			if( error == KErrNone )
   634 			if( error == KErrNone )
   633 				{
   635 				{
   634 				CleanupStack::Pop(); // contactToAdd , Ownership is transfered to AddStorageContactToCacheL
   636 				CleanupStack::Pop(); // contactToAdd , Ownership is transfered to AddStorageContactToCacheL
   635 				WriteToStoreDbL( linkId );	
   637 				WriteToStoreDbL( linkId );	
   636 				}
   638 				}
   637 			else
   639 			else
   638 				{
   640 				{
   639 				CleanupStack::PopAndDestroy(); // contactToAdd	
   641 				CleanupStack::PopAndDestroy(); // contactToAdd	
   640 				}
   642 				}
   641 			TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL() adding to  db done" ) );
   643 			TRACE( " adding to  db done"  );
   642 			}
   644 			}
   643         }
   645         }
   644     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL() error =%d" ),error );
   646     TRACE( "error =%d" ,error );
   645     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateRetriveVPbkContactL() end" ) );
   647     
   646     return error;
   648     return error;
   647     }
   649     }
   648 
   650 
   649 // ---------------------------------------------------------------------------
   651 // ---------------------------------------------------------------------------
   650 // CVIMPSTStorageVPbkLocalStore::deleteRetriveVPbkContactL
   652 // CVIMPSTStorageVPbkLocalStore::deleteRetriveVPbkContactL
   651 // ---------------------------------------------------------------------------
   653 // ---------------------------------------------------------------------------
   652 // 
   654 // 
   653 TInt CVIMPSTStorageVPbkLocalStore::deleteRetriveVPbkContactL( TInt aIndexToUse  )   
   655 TInt CVIMPSTStorageVPbkLocalStore::deleteRetriveVPbkContactL( TInt aIndexToUse  )   
   654     {
   656     {
   655     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::deleteRetriveVPbkContactL() begin" ) );
   657 	TRACER_AUTO;
   656     if( aIndexToUse < 0 && aIndexToUse >= iRetrivedContactArray.Count() )
   658     if( aIndexToUse < 0 && aIndexToUse >= iRetrivedContactArray.Count() )
   657         {
   659         {
   658         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::deleteRetriveVPbkContactL() argument error" ) );
   660         TRACE( "argument error" );
   659         return KErrArgument;
   661         return KErrArgument;
   660         }
   662         }
   661     MVIMPSTStorageContact* retrivedContact = iRetrivedContactArray[ aIndexToUse ];
   663     MVIMPSTStorageContact* retrivedContact = iRetrivedContactArray[ aIndexToUse ];
   662     MVPbkContactLink* contactLink = retrivedContact->ContactLink();
   664     MVPbkContactLink* contactLink = retrivedContact->ContactLink();
   663     // delete from cache contact
   665     // delete from cache contact
   665     MVPbkContactLink* link = contactLink->CloneLC();    
   667     MVPbkContactLink* link = contactLink->CloneLC();    
   666     contactsToDelete->AppendL( link ); // takes ownership
   668     contactsToDelete->AppendL( link ); // takes ownership
   667     CleanupStack::Pop(); // link
   669     CleanupStack::Pop(); // link
   668     TInt error = iVPbkStoreHandler->RemoveVPbkContactL( *contactsToDelete );
   670     TInt error = iVPbkStoreHandler->RemoveVPbkContactL( *contactsToDelete );
   669     CleanupStack::PopAndDestroy(); // contactsToDelete
   671     CleanupStack::PopAndDestroy(); // contactsToDelete
   670     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::deleteRetriveVPbkContactL() begin" ) );
   672     
   671     return error;
   673     return error;
   672     }
   674     }
   673 // CVIMPSTStorageVPbkLocalStore::UpdateAvatarFieldDataL()
   675 // CVIMPSTStorageVPbkLocalStore::UpdateAvatarFieldDataL()
   674 // ---------------------------------------------------------------------------
   676 // ---------------------------------------------------------------------------
   675 //
   677 //
   676 TInt CVIMPSTStorageVPbkLocalStore::UpdateAvatarFieldDataL(const MVPbkContactLink& aContactLink,
   678 TInt CVIMPSTStorageVPbkLocalStore::UpdateAvatarFieldDataL(const MVPbkContactLink& aContactLink,
   677 														  const TDesC8& aAvatartData )
   679 														  const TDesC8& aAvatartData )
   678     {
   680     {
   679     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::UpdateAvatarFieldDataL()" ) );
   681 	TRACER_AUTO;
   680     return iVPbkStoreHandler->UpdateAvatarFieldDataL( aContactLink, aAvatartData );
   682     return iVPbkStoreHandler->UpdateAvatarFieldDataL( aContactLink, aAvatartData );
   681     }
   683     }
   682 
   684 
   683 // ---------------------------------------------------------------------------
   685 // ---------------------------------------------------------------------------
   684 // CVIMPSTStorageVPbkLocalStore::RemoveAvatarFieldL()
   686 // CVIMPSTStorageVPbkLocalStore::RemoveAvatarFieldL()
   685 // ---------------------------------------------------------------------------
   687 // ---------------------------------------------------------------------------
   686 //
   688 //
   687 TInt CVIMPSTStorageVPbkLocalStore::RemoveAvatarFieldL(MVPbkStoreContact& aStoreContact)
   689 TInt CVIMPSTStorageVPbkLocalStore::RemoveAvatarFieldL(MVPbkStoreContact& aStoreContact)
   688 	{
   690 	{
   689 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::RemoveAvatarFieldL()" ) );
   691 	TRACER_AUTO;
   690 	return iVPbkStoreHandler->RemoveAvatarFieldL( aStoreContact );	
   692 	return iVPbkStoreHandler->RemoveAvatarFieldL( aStoreContact );	
   691 	}
   693 	}
   692 
   694 
   693 // ---------------------------------------------------------------------------
   695 // ---------------------------------------------------------------------------
   694 // CVIMPSTStorageVPbkLocalStore::AddVPbkFetchContactsL()
   696 // CVIMPSTStorageVPbkLocalStore::AddVPbkFetchContactsL()
   695 // ---------------------------------------------------------------------------
   697 // ---------------------------------------------------------------------------
   696 //
   698 //
   697 void CVIMPSTStorageVPbkLocalStore::AddVPbkFetchContactsL( RArray <TPtrC>& aFirstNameList, 
   699 void CVIMPSTStorageVPbkLocalStore::AddVPbkFetchContactsL( RArray <TPtrC>& aFirstNameList, 
   698                                                            RArray <TPtrC> &aServiceField ) 
   700                                                            RArray <TPtrC> &aServiceField ) 
   699      {
   701      {
   700      TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::AddVPbkFetchContactsL() begin" ) );
   702 	TRACER_AUTO;
   701      // in case of server contacts delete all contacts
   703      // in case of server contacts delete all contacts
   702      ResetAndDestroyLocalArrayL();
   704      ResetAndDestroyLocalArrayL();
   703      TInt count = aServiceField.Count();
   705      TInt count = aServiceField.Count();
   704      TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::AddVPbkFetchContactsL() count=%d" ),count );
   706      TRACE( " count=%d" ,count );
   705      for( TInt i = 0; i<count; i++ )
   707      for( TInt i = 0; i<count; i++ )
   706          {
   708          {
   707          TVIMPSTContactInfo contactInf =
   709          TVIMPSTContactInfo contactInf =
   708 							         {
   710 							         {
   709 							         aServiceField[i].AllocL() ,
   711 							         aServiceField[i].AllocL() ,
   712          // not exist need to add 
   714          // not exist need to add 
   713          iFetchContactsToBeAdded.Append( contactInf );
   715          iFetchContactsToBeAdded.Append( contactInf );
   714          }
   716          }
   715      if( iFetchStep == EContactReadComplete )
   717      if( iFetchStep == EContactReadComplete )
   716 	     {
   718 	     {
   717 	     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::AddVPbkFetchContactsL() start fetcing" ) );
   719 	     TRACE( "start fetcing"  );
   718 	     IssueRequest();	
   720 	     IssueRequest();	
   719 	     }
   721 	     }
   720 	 else
   722 	 else
   721 		 {
   723 		 {
   722 		 TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::AddVPbkFetchContactsL() EFetchingCalled" ) );
   724 		 TRACE( " EFetchingCalled"  );
   723 		 iFetchStep = EFetchingCalled;	
   725 		 iFetchStep = EFetchingCalled;	
   724 		 }
   726 		 }
   725 	 TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::AddVPbkFetchContactsL() end" ) );
   727 	
   726      }
   728      }
   727 
   729 
   728 //******************* Database Operations *********************************//
   730 //******************* Database Operations *********************************//
   729 // -----------------------------------------------------------
   731 // -----------------------------------------------------------
   730 // CVIMPSTStorageVPbkLocalStore::DbExists
   732 // CVIMPSTStorageVPbkLocalStore::DbExists
   731 // -----------------------------------------------------------
   733 // -----------------------------------------------------------
   732 //
   734 //
   733 TBool CVIMPSTStorageVPbkLocalStore::DbExists()
   735 TBool CVIMPSTStorageVPbkLocalStore::DbExists()
   734 	{
   736 	{
   735 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DbExists() begin" ) );
   737 	TRACER_AUTO;
   736 	RFile temp;
   738 	RFile temp;
   737 
   739 
   738 	TBuf< KMaxPath > storagePath;
   740 	TBuf< KMaxPath > storagePath;
   739 
   741 
   740 	storagePath.Append( KDbPath );    
   742 	storagePath.Append( KDbPath );    
   749 	temp.Close();
   751 	temp.Close();
   750 	if ( (size == 0) || ( err != KErrNone ) )
   752 	if ( (size == 0) || ( err != KErrNone ) )
   751 		{
   753 		{
   752 		ret = EFalse;
   754 		ret = EFalse;
   753 		}
   755 		}
   754 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DbExists() end" ) );
   756 	
   755 	return ret;
   757 	return ret;
   756 	}
   758 	}
   757 
   759 
   758 
   760 
   759 // -----------------------------------------------------------
   761 // -----------------------------------------------------------
   760 // CVIMPSTStorageVPbkLocalStore::CreateDbL
   762 // CVIMPSTStorageVPbkLocalStore::CreateDbL
   761 // -----------------------------------------------------------
   763 // -----------------------------------------------------------
   762 //
   764 //
   763 void CVIMPSTStorageVPbkLocalStore::CreateDbL()
   765 void CVIMPSTStorageVPbkLocalStore::CreateDbL()
   764 	{
   766 	{
   765 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateDbL() begin" ) );
   767 	TRACER_AUTO;
   766 	TBuf< KMaxPath > storagePath;
   768 	TBuf< KMaxPath > storagePath;
   767 	storagePath.Append( KDbPath );
   769 	storagePath.Append( KDbPath );
   768 	iFs.MkDirAll( storagePath );    // make sure the directory exists	
   770 	iFs.MkDirAll( storagePath );    // make sure the directory exists	
   769     storagePath.Append( *iLocalDBName );
   771     storagePath.Append( *iLocalDBName );
   770     iFs.SetAtt( *iLocalDBName ,KEntryAttHidden|KEntryAttSystem , KEntryAttNormal);
   772     iFs.SetAtt( *iLocalDBName ,KEntryAttHidden|KEntryAttSystem , KEntryAttNormal);
   775     TStreamId streamId( 0 );
   777     TStreamId streamId( 0 );
   776 	TRAPD( err, streamId = iDb.CreateL( iFileStore ) );
   778 	TRAPD( err, streamId = iDb.CreateL( iFileStore ) );
   777 
   779 
   778     if( err ) 
   780     if( err ) 
   779         {
   781         {
   780         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateDbL() err = %d" ),err );
   782         TRACE( " err = %d" ,err );
   781         delete iFileStore;
   783         delete iFileStore;
   782         iFileStore = NULL;
   784         iFileStore = NULL;
   783 
   785 
   784         // remember to keep this updated
   786         // remember to keep this updated
   785         iFs.Delete( storagePath );
   787         iFs.Delete( storagePath );
   797         iFileStore = NULL;
   799         iFileStore = NULL;
   798         iDb.Close();
   800         iDb.Close();
   799         iFs.Delete( storagePath );
   801         iFs.Delete( storagePath );
   800         User::Leave( err3 );
   802         User::Leave( err3 );
   801         }
   803         }
   802     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateDbL() end" ) );
   804     
   803     }    
   805     }    
   804 
   806 
   805 // -----------------------------------------------------------
   807 // -----------------------------------------------------------
   806 // CVIMPSTStorageVPbkLocalStore::OpenDbL
   808 // CVIMPSTStorageVPbkLocalStore::OpenDbL
   807 // -----------------------------------------------------------
   809 // -----------------------------------------------------------
   808 //
   810 //
   809 void CVIMPSTStorageVPbkLocalStore::OpenDbL()
   811 void CVIMPSTStorageVPbkLocalStore::OpenDbL()
   810     {
   812     {
   811     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::OpenDbL() begin" ) );
   813 	TRACER_AUTO;
   812     TBuf< KMaxPath > storagePath;
   814     TBuf< KMaxPath > storagePath;
   813     storagePath.Append( KDbPath );
   815     storagePath.Append( KDbPath );
   814     storagePath.Append( *iLocalDBName );
   816     storagePath.Append( *iLocalDBName );
   815     iFileStore = CPermanentFileStore::OpenL( iFs, storagePath, EFileShareReadersOrWriters|EFileWrite );   
   817     iFileStore = CPermanentFileStore::OpenL( iFs, storagePath, EFileShareReadersOrWriters|EFileWrite );   
   816     iFileStore->SetTypeL( iFileStore->Layout() );
   818     iFileStore->SetTypeL( iFileStore->Layout() );
   817     iDb.OpenL( iFileStore, iFileStore->Root() );
   819     iDb.OpenL( iFileStore, iFileStore->Root() );
   818     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::OpenDbL() begin" ) );
   820     
   819     }
   821     }
   820 
   822 
   821 // -----------------------------------------------------------
   823 // -----------------------------------------------------------
   822 // CVIMPSTStorageVPbkLocalStore::CloseDb
   824 // CVIMPSTStorageVPbkLocalStore::CloseDb
   823 // -----------------------------------------------------------
   825 // -----------------------------------------------------------
   824 //
   826 //
   825 void CVIMPSTStorageVPbkLocalStore::CloseDb()
   827 void CVIMPSTStorageVPbkLocalStore::CloseDb()
   826 	{ 
   828 	{ 
   827 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CloseDb() begin" ) );
   829 	TRACER_AUTO;
   828     delete iFileStore;
   830     delete iFileStore;
   829     iFileStore = NULL;
   831     iFileStore = NULL;
   830     iDb.Close();
   832     iDb.Close();
   831     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CloseDb() end" ) );
   833     
   832     }
   834     }
   833 
   835 
   834 // -----------------------------------------------------------
   836 // -----------------------------------------------------------
   835 // CVIMPSTStorageVPbkLocalStore::CreateTablesL
   837 // CVIMPSTStorageVPbkLocalStore::CreateTablesL
   836 // -----------------------------------------------------------
   838 // -----------------------------------------------------------
   837 //
   839 //
   838 void CVIMPSTStorageVPbkLocalStore::CreateTablesL()
   840 void CVIMPSTStorageVPbkLocalStore::CreateTablesL()
   839 	{
   841 	{
   840 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateTablesL() begin" ) );
   842 	TRACER_AUTO;
   841 	CDbColSet* contactId = CDbColSet::NewLC();
   843 	CDbColSet* contactId = CDbColSet::NewLC();
   842 
   844 
   843 	AddColumnL( KContactId, EDbColInt32, contactId );
   845 	AddColumnL( KContactId, EDbColInt32, contactId );
   844 
   846 
   845 	TInt err = iDb.CreateTable( KContactTable, *contactId );
   847 	TInt err = iDb.CreateTable( KContactTable, *contactId );
   846 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateTablesL() err = %d" ),err );
   848 	TRACE( "err = %d" ,err );
   847 	User::LeaveIfError( err );
   849 	User::LeaveIfError( err );
   848 
   850 
   849 	CleanupStack::PopAndDestroy( contactId );
   851 	CleanupStack::PopAndDestroy( contactId );
   850 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CreateTablesL() end" ) );	
   852 	
   851 	}
   853 	}
   852 
   854 
   853 // -----------------------------------------------------------
   855 // -----------------------------------------------------------
   854 // CVIMPSTStorageVPbkLocalStore::AddColumnL
   856 // CVIMPSTStorageVPbkLocalStore::AddColumnL
   855 // -----------------------------------------------------------
   857 // -----------------------------------------------------------
   856 //
   858 //
   857 void CVIMPSTStorageVPbkLocalStore::AddColumnL( const TDesC& aName, TDbColType aType, CDbColSet* aColset  )
   859 void CVIMPSTStorageVPbkLocalStore::AddColumnL( const TDesC& aName, TDbColType aType, CDbColSet* aColset  )
   858 	{
   860 	{
   859 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::AddColumnL() begin" ) );
   861 	TRACER_AUTO;
   860 	TDbCol column( aName, aType );
   862 	TDbCol column( aName, aType );
   861 	aColset->AddL( column );
   863 	aColset->AddL( column );
   862 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::AddColumnL() end" ) );
   864 	
   863 	}
   865 	}
   864 
   866 
   865 // -----------------------------------------------------------
   867 // -----------------------------------------------------------
   866 // CVIMPSTStorageVPbkLocalStore::DoFreespaceLevelCheckL
   868 // CVIMPSTStorageVPbkLocalStore::DoFreespaceLevelCheckL
   867 // -----------------------------------------------------------
   869 // -----------------------------------------------------------
   868 //
   870 //
   869 void CVIMPSTStorageVPbkLocalStore::DoFreespaceLevelCheckL( TInt aSize )
   871 void CVIMPSTStorageVPbkLocalStore::DoFreespaceLevelCheckL( TInt aSize )
   870 	{
   872 	{
   871 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DoFreespaceLevelCheckL() begin" ) );
   873 	TRACER_AUTO;
   872     if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, aSize ) )
   874     if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, aSize ) )
   873         {
   875         {
   874 		User::Leave( KErrDiskFull );
   876 		User::Leave( KErrDiskFull );
   875         }
   877         }
   876     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DoFreespaceLevelCheckL() end" ) );
   878     
   877 	}
   879 	}
   878 
   880 
   879 // -----------------------------------------------------------------------------
   881 // -----------------------------------------------------------------------------
   880 // CVIMPSTStorageVPbkLocalStore::DeleteAllContactFromInternalStoreL
   882 // CVIMPSTStorageVPbkLocalStore::DeleteAllContactFromInternalStoreL
   881 // -----------------------------------------------------------------------------
   883 // -----------------------------------------------------------------------------
   882 //
   884 //
   883 void CVIMPSTStorageVPbkLocalStore::DeleteAllContactFromInternalStoreL()
   885 void CVIMPSTStorageVPbkLocalStore::DeleteAllContactFromInternalStoreL()
   884 	{
   886 	{
   885 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DeleteAllContactFromInternalStoreL() begin" ) );
   887 	TRACER_AUTO;
   886 	iColset->ColNo( KContactId );
   888 	iColset->ColNo( KContactId );
   887 	iTable.LastL();	
   889 	iTable.LastL();	
   888 	while( !iTable.IsEmptyL() )
   890 	while( !iTable.IsEmptyL() )
   889 		{
   891 		{
   890 		iTable.GetL();
   892 		iTable.GetL();
   891 		iTable.DeleteL();
   893 		iTable.DeleteL();
   892 		iDb.Compact();
   894 		iDb.Compact();
   893 		// delete alwasy first item untill table is empty
   895 		// delete alwasy first item untill table is empty
   894 		iTable.LastL();
   896 		iTable.LastL();
   895 		}
   897 		}
   896 	TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DeleteAllContactFromInternalStoreL() end" ) );
   898 	
   897 	}
   899 	}
   898 // ----------------------------------------------------------
   900 // ----------------------------------------------------------
   899 // CVIMPSTStorageVPbkLocalStore::DeleteContactFromInternalStoreL
   901 // CVIMPSTStorageVPbkLocalStore::DeleteContactFromInternalStoreL
   900 // ----------------------------------------------------------
   902 // ----------------------------------------------------------
   901 //
   903 //
   902 void CVIMPSTStorageVPbkLocalStore::DeleteContactFromInternalStoreL( TInt32& aIdentifier )
   904 void CVIMPSTStorageVPbkLocalStore::DeleteContactFromInternalStoreL( TInt32& aIdentifier )
   903     {
   905     {
   904     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DeleteContactFromInternalStoreL() begin" ) );
   906 	TRACER_AUTO;
   905     TDbColNo colNo = iColset->ColNo( KContactId );
   907     TDbColNo colNo = iColset->ColNo( KContactId );
   906     if ( SeekRowL( colNo, aIdentifier ) )
   908     if ( SeekRowL( colNo, aIdentifier ) )
   907         {
   909         {
   908         iTable.DeleteL();
   910         iTable.DeleteL();
   909         iDb.Compact();
   911         iDb.Compact();
   910         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DeleteContactFromInternalStoreL() found deleted" ) );
   912         TRACE( "found deleted"  );
   911         }
   913         }
   912     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DeleteContactFromInternalStoreL() end" ) );
   914    
   913     }
   915     }
   914  
   916  
   915 // ----------------------------------------------------------
   917 // ----------------------------------------------------------
   916 // CVIMPSTStorageVPbkLocalStore::WriteToStoreDbL
   918 // CVIMPSTStorageVPbkLocalStore::WriteToStoreDbL
   917 // ----------------------------------------------------------
   919 // ----------------------------------------------------------
   918 //
   920 //
   919 void CVIMPSTStorageVPbkLocalStore::WriteToStoreDbL( TInt32& aIdentifier )
   921 void CVIMPSTStorageVPbkLocalStore::WriteToStoreDbL( TInt32& aIdentifier )
   920     {
   922     {
   921     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::WriteToStoreDbL() begin" ) );
   923 	TRACER_AUTO;
   922     TDbColNo colNo = iColset->ColNo( KContactId );
   924     TDbColNo colNo = iColset->ColNo( KContactId );
   923     if (!SeekRowL( colNo, aIdentifier ) )        
   925     if (!SeekRowL( colNo, aIdentifier ) )        
   924         {
   926         {
   925         iTable.InsertL();
   927         iTable.InsertL();
   926      
   928      
   934             // recover
   936             // recover
   935             iTable.Cancel();
   937             iTable.Cancel();
   936             iTable.Reset();
   938             iTable.Reset();
   937             } 
   939             } 
   938         }
   940         }
   939     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::WriteToStoreDbL() end" ) );    
   941    
   940     }
   942     }
   941 // ----------------------------------------------------------
   943 // ----------------------------------------------------------
   942 // CVIMPSTStorageVPbkLocalStore::OpenTableL
   944 // CVIMPSTStorageVPbkLocalStore::OpenTableL
   943 // ----------------------------------------------------------
   945 // ----------------------------------------------------------
   944 //
   946 //
   945 void CVIMPSTStorageVPbkLocalStore::OpenTableL()
   947 void CVIMPSTStorageVPbkLocalStore::OpenTableL()
   946     {
   948     {
   947     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::OpenTableL() begin" ) );
   949 	TRACER_AUTO;
   948     TInt err( iTable.Open( iDb, KContactTable ) );
   950     TInt err( iTable.Open( iDb, KContactTable ) );
   949     if ( err != KErrNone )
   951     if ( err != KErrNone )
   950         {
   952         {
   951         TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::OpenTableL() err =%d" ),err );
   953         TRACE( " err =%d" ,err );
   952         iTable.Close();
   954         iTable.Close();
   953         User::Leave( err );
   955         User::Leave( err );
   954         }
   956         }
   955     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::OpenTableL() end" ) );
   957     
   956     }
   958     }
   957 
   959 
   958 // ----------------------------------------------------------
   960 // ----------------------------------------------------------
   959 // CVIMPSTStorageVPbkLocalStore::CloseTable
   961 // CVIMPSTStorageVPbkLocalStore::CloseTable
   960 // ----------------------------------------------------------
   962 // ----------------------------------------------------------
   961 //
   963 //
   962 void CVIMPSTStorageVPbkLocalStore::CloseTable()
   964 void CVIMPSTStorageVPbkLocalStore::CloseTable()
   963     {
   965     {
   964     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CloseTable() begin" ) );
   966 	TRACER_AUTO;
   965     iTable.Close();
   967     iTable.Close();
   966     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::CloseTable() end" ) );
   968    
   967     }
   969     }
   968 
   970 
   969 // ----------------------------------------------------------
   971 // ----------------------------------------------------------
   970 // CVIMPSTStorageVPbkLocalStore::ReadFirstL
   972 // CVIMPSTStorageVPbkLocalStore::ReadFirstL
   971 // ----------------------------------------------------------
   973 // ----------------------------------------------------------
   972 //
   974 //
   973 TInt CVIMPSTStorageVPbkLocalStore::ReadFirstL(  TInt32& aIdentifier )
   975 TInt CVIMPSTStorageVPbkLocalStore::ReadFirstL(  TInt32& aIdentifier )
   974     { 
   976     { 
   975     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ReadFirstL() begin" ) );   
   977 	TRACER_AUTO;
   976     iTable.BeginningL();
   978     iTable.BeginningL();
   977     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ReadFirstL() end" ) );
   979     
   978     return ReadNextL( aIdentifier );
   980     return ReadNextL( aIdentifier );
   979     }
   981     }
   980 
   982 
   981 // ----------------------------------------------------------
   983 // ----------------------------------------------------------
   982 // CVIMPSTStorageVPbkLocalStore::ReadNextL
   984 // CVIMPSTStorageVPbkLocalStore::ReadNextL
   983 // ----------------------------------------------------------
   985 // ----------------------------------------------------------
   984 //
   986 //
   985 TInt CVIMPSTStorageVPbkLocalStore::ReadNextL( TInt32& aIdentifier )
   987 TInt CVIMPSTStorageVPbkLocalStore::ReadNextL( TInt32& aIdentifier )
   986     { 
   988     { 
   987     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ReadNextL() begin" ) );
   989 	TRACER_AUTO;
   988     TInt err = KErrNotFound;   
   990     TInt err = KErrNotFound;   
   989     if ( iTable.NextL() )
   991     if ( iTable.NextL() )
   990         {
   992         {
   991         TRAP( err, ReadCurrentL( aIdentifier ) );
   993         TRAP( err, ReadCurrentL( aIdentifier ) );
   992 		// For some reason ReadCurrentL leaves with KErrEof,
   994 		// For some reason ReadCurrentL leaves with KErrEof,
   993         // even if the contact was read succesfully.
   995         // even if the contact was read succesfully.
   994         }
   996         }
   995     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ReadNextL() err = %d" ),err );
   997     TRACE( " err = %d" ,err );
   996     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ReadNextL() end" ) );
   998    
   997     return err;
   999     return err;
   998     }
  1000     }
   999 
  1001 
  1000 
  1002 
  1001 // ----------------------------------------------------------
  1003 // ----------------------------------------------------------
  1002 // CVIMPSTStorageVPbkLocalStore::ReadCurrentL
  1004 // CVIMPSTStorageVPbkLocalStore::ReadCurrentL
  1003 // ----------------------------------------------------------
  1005 // ----------------------------------------------------------
  1004 //
  1006 //
  1005 void CVIMPSTStorageVPbkLocalStore::ReadCurrentL( TInt32& aIdentifier )
  1007 void CVIMPSTStorageVPbkLocalStore::ReadCurrentL( TInt32& aIdentifier )
  1006     {
  1008     {
  1007     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ReadCurrentL() begin" ) );
  1009 	TRACER_AUTO;
  1008     iTable.GetL();
  1010     iTable.GetL();
  1009 	 // Get Column number for contact data size
  1011 	 // Get Column number for contact data size
  1010     TDbColNo colNo = iColset->ColNo( KContactId );
  1012     TDbColNo colNo = iColset->ColNo( KContactId );
  1011     aIdentifier = iTable.ColInt32(colNo);
  1013     aIdentifier = iTable.ColInt32(colNo);
  1012     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::ReadCurrentL() end" ) );
  1014    
  1013     }
  1015     }
  1014     
  1016     
  1015 // ----------------------------------------------------------
  1017 // ----------------------------------------------------------
  1016 // CVIMPSTStorageVPbkLocalStore::SeekRowL
  1018 // CVIMPSTStorageVPbkLocalStore::SeekRowL
  1017 // ----------------------------------------------------------
  1019 // ----------------------------------------------------------
  1018 //
  1020 //
  1019 TBool CVIMPSTStorageVPbkLocalStore::SeekRowL( TDbColNo aColNo, TInt32& aIdentifier )
  1021 TBool CVIMPSTStorageVPbkLocalStore::SeekRowL( TDbColNo aColNo, TInt32& aIdentifier )
  1020     {
  1022     {
  1021     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::SeekRowL() begin" ) );
  1023 	TRACER_AUTO;
  1022     TBool ret = EFalse;
  1024     TBool ret = EFalse;
  1023     iTable.BeginningL();
  1025     iTable.BeginningL();
  1024     while ( iTable.NextL() )
  1026     while ( iTable.NextL() )
  1025         {
  1027         {
  1026         iTable.GetL();
  1028         iTable.GetL();
  1028             {
  1030             {
  1029             ret = ETrue;
  1031             ret = ETrue;
  1030             break; 
  1032             break; 
  1031             }
  1033             }
  1032         }
  1034         }
  1033     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::SeekRowL() end" ) );
  1035    
  1034     return ret;
  1036     return ret;
  1035     }
  1037     }
  1036 // ----------------------------------------------------------
  1038 // ----------------------------------------------------------
  1037 // CVIMPSTStorageVPbkLocalStore::DeleteDatabaseL
  1039 // CVIMPSTStorageVPbkLocalStore::DeleteDatabaseL
  1038 // ----------------------------------------------------------
  1040 // ----------------------------------------------------------
  1039 void CVIMPSTStorageVPbkLocalStore::DeleteDatabaseL()
  1041 void CVIMPSTStorageVPbkLocalStore::DeleteDatabaseL()
  1040     {
  1042     {
  1041     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DeleteDatabaseL() begin" ) );
  1043 	TRACER_AUTO;
  1042     TBuf< KMaxPath > storagePath;
  1044     TBuf< KMaxPath > storagePath;
  1043     storagePath.Append( KDbPath ); 
  1045     storagePath.Append( KDbPath ); 
  1044     iFs.MkDirAll( storagePath );   
  1046     iFs.MkDirAll( storagePath );   
  1045     storagePath.Append( *iLocalDBName );
  1047     storagePath.Append( *iLocalDBName );
  1046     //close db before deleting it.
  1048     //close db before deleting it.
  1047     CloseDb();
  1049     CloseDb();
  1048     iFs.Delete( storagePath );
  1050     iFs.Delete( storagePath );
  1049     TRACE( T_LIT("CVIMPSTStorageVPbkLocalStore::DeleteDatabaseL() end" ) );
  1051    
  1050     }
  1052     }
  1051 // ----------------------------------------------------------
  1053 // ----------------------------------------------------------
  1052 // CVIMPSTStorageVPbkLocalStore::IsSameContactIdL
  1054 // CVIMPSTStorageVPbkLocalStore::IsSameContactIdL
  1053 // ----------------------------------------------------------
  1055 // ----------------------------------------------------------
  1054 TBool CVIMPSTStorageVPbkLocalStore::IsSameContactIdL(const TDesC& aFirstId, const TDesC& aSecondId )
  1056 TBool CVIMPSTStorageVPbkLocalStore::IsSameContactIdL(const TDesC& aFirstId, const TDesC& aSecondId )
  1055     {
  1057     {
       
  1058 	TRACER_AUTO;
  1056     TInt colIndex = aFirstId.Find(_L(":"));
  1059     TInt colIndex = aFirstId.Find(_L(":"));
  1057     TPtrC firstId = aFirstId.Right( aFirstId.Length() - colIndex -1);
  1060     TPtrC firstId = aFirstId.Right( aFirstId.Length() - colIndex -1);
  1058     colIndex = aSecondId.Find(_L(":"));
  1061     colIndex = aSecondId.Find(_L(":"));
  1059     TPtrC secondId = aSecondId.Right( aSecondId.Length() - colIndex -1);
  1062     TPtrC secondId = aSecondId.Right( aSecondId.Length() - colIndex -1);
  1060     //if( Compare( firstId,secondId  ) == 0 )
  1063     //if( Compare( firstId,secondId  ) == 0 )