contentctrl_plat/adapter_customization_api/tsrc/DummyAdapter/src/nsmldummymodsfetcher.cpp
branchRCL_3
changeset 52 4f0867e42d62
parent 14 b922b9936679
equal deleted inserted replaced
51:8e7494275d3a 52:4f0867e42d62
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  DS Dummy Adapter ModsFetcher
       
    15 *
       
    16 */
       
    17 
       
    18 //  CLASS HEADER
       
    19 #include "nsmldummymodsfetcher.h"
       
    20 
       
    21 
       
    22 //  EXTERNAL INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <s32strm.h>
       
    25 #include <e32cmn.h>
       
    26 #include <e32des16.h>
       
    27 #include <CVPbkContactViewDefinition.h>
       
    28 #include <CVPbkContactIdConverter.h>
       
    29 #include <CVPbkContactFieldIterator.h>
       
    30 #include <MVPbkContactStoreProperties.h>
       
    31 #include <MVPbkStoreContactProperties.h>
       
    32 #include <MVPbkViewContact.h>
       
    33 #include <MVPbkFieldType.h>
       
    34 #include <MVPbkContactFieldTextData.h>
       
    35 #include <MVPbkStoreContact.h>
       
    36 #include <MVPbkStoreContact2.h>
       
    37 #include <MVPbkContactLink.h>
       
    38 #include <vpbkeng.rsg>
       
    39 
       
    40 // INTERNAL INCLUDES
       
    41 #include "nsmldebug.h"
       
    42 #include "nsmlsnapshotitem.h"
       
    43 #include "nsmlchangefinder.h"
       
    44 #include "nsmldummyutility.h"
       
    45 
       
    46 
       
    47 // ------------------------------------------------------------------------------------------------
       
    48 // CNSmlDummyModsFetcher::CNSmlDummyModsFetcher
       
    49 // ------------------------------------------------------------------------------------------------
       
    50 //
       
    51 CNSmlDummyModsFetcher::CNSmlDummyModsFetcher(
       
    52     TBool& aSnapshotRegistered,CVPbkContactManager& aContactManager,
       
    53     MVPbkContactStore& aStore,TKeyArrayFix& aKey,
       
    54     CNSmlChangeFinder& aChangeFinder ) :
       
    55 	CActive( EPriorityLow ),
       
    56 	iSnapshotRegistered( aSnapshotRegistered ),
       
    57 	iKey( aKey ),
       
    58 	iChangeFinder( aChangeFinder ),
       
    59 	iContactManager( aContactManager ),
       
    60 	iStore( aStore ),
       
    61 	iContactViewBase( NULL )
       
    62 	{
       
    63 	_DBG_FILE("CNSmlDummyModsFetcher::CNSmlDummyModsFetcher(): begin");
       
    64 	CActiveScheduler::Add( this );
       
    65 	_DBG_FILE("CNSmlDummyModsFetcher::CNSmlDummyModsFetcher(): end");
       
    66 	}
       
    67 
       
    68 // ------------------------------------------------------------------------------------------------
       
    69 // CNSmlDummyModsFetcher::~CNSmlDummyModsFetcher
       
    70 // ------------------------------------------------------------------------------------------------
       
    71 //
       
    72 CNSmlDummyModsFetcher::~CNSmlDummyModsFetcher()
       
    73 	{
       
    74 	_DBG_FILE("CNSmlDummyModsFetcher::~CNSmlDummyModsFetcher(): begin");
       
    75 
       
    76 	Cancel();
       
    77 	delete iSnapshot;
       
    78 	delete iContactViewBase;
       
    79 
       
    80 	_DBG_FILE("CNSmlDummyModsFetcher::~CNSmlDummyModsFetcher(): end");
       
    81 	}
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CNSmlDummyModsFetcher::CancelRequest
       
    85 // ----------------------------------------------------------------------------
       
    86 void CNSmlDummyModsFetcher::CancelRequest()
       
    87      {
       
    88      _DBG_FILE("CNSmlDummyModsFetcher::CancelRequest(): begin");
       
    89 
       
    90      Cancel();
       
    91 
       
    92      _DBG_FILE("CNSmlDummyModsFetcher::CancelRequest(): end");
       
    93      }
       
    94 
       
    95 // ------------------------------------------------------------------------------------------------
       
    96 // CNSmlDummyModsFetcher::FetchModificationsL
       
    97 // ------------------------------------------------------------------------------------------------
       
    98 //
       
    99 void CNSmlDummyModsFetcher::FetchModificationsL( TRequestStatus& aStatus )
       
   100 	{
       
   101 	_DBG_FILE("CNSmlDummyModsFetcher::FetchModificationsL(): begin");
       
   102 
       
   103 	iCallerStatus = &aStatus;
       
   104 	*iCallerStatus = KRequestPending;
       
   105 	iContactCount = 0;
       
   106 	if( !iSnapshot )
       
   107 		{
       
   108 		iSnapshot = new (ELeave) CArrayFixSeg< TNSmlSnapshotItem >( KNSmlSnapshotSize );
       
   109 		}
       
   110 
       
   111 	if( iContactViewBase )
       
   112 	   {
       
   113 	   delete iContactViewBase;
       
   114 	   iContactViewBase = NULL;
       
   115 	   }
       
   116 
       
   117 	CreateViewL();
       
   118 
       
   119 	_DBG_FILE("CNSmlDummyModsFetcher::FetchModificationsL(): end");
       
   120 	}
       
   121 
       
   122 // ------------------------------------------------------------------------------------------------
       
   123 // CNSmlDummyModsFetcher::ConstructL
       
   124 // ------------------------------------------------------------------------------------------------
       
   125 //
       
   126 void CNSmlDummyModsFetcher::ConstructL()
       
   127 	{
       
   128 	_DBG_FILE("CNSmlDummyModsFetcher::ConstructL(): begin");
       
   129 
       
   130 	iSnapshot = new ( ELeave ) CArrayFixSeg< TNSmlSnapshotItem >( KNSmlSnapshotSmallSize );
       
   131 
       
   132 	_DBG_FILE("CNSmlDummyModsFetcher::ConstructL(): end");
       
   133 	}
       
   134 
       
   135 // ------------------------------------------------------------------------------------------------
       
   136 // CNSmlDummyModsFetcher::RunL
       
   137 // ------------------------------------------------------------------------------------------------
       
   138 //
       
   139 void CNSmlDummyModsFetcher::RunL()
       
   140 	{
       
   141 	_DBG_FILE("CNSmlDummyModsFetcher::RunL(): begin");
       
   142 
       
   143 	if ( !iSnapshotRegistered )
       
   144 		{
       
   145 		FetchNextContactL();
       
   146 		}
       
   147 #ifdef __NSML_MODULETEST__
       
   148 	else
       
   149 		{
       
   150 		CActiveScheduler::Stop();
       
   151 		}
       
   152 #endif
       
   153 
       
   154 	_DBG_FILE("CNSmlDummyModsFetcher::RunL(): end");
       
   155 	}
       
   156 
       
   157 // ------------------------------------------------------------------------------------------------
       
   158 // CNSmlDummyModsFetcher::FetchNextContactL
       
   159 // ------------------------------------------------------------------------------------------------
       
   160 //
       
   161 void CNSmlDummyModsFetcher::FetchNextContactL()
       
   162 	{
       
   163 	_DBG_FILE("CNSmlDummyModsFetcher::FetchNextContactL(): begin");
       
   164 	if( iContactViewBase->ContactCountL() == 0 )
       
   165 		{
       
   166 		User::RequestComplete( iCallerStatus, KErrNone );
       
   167 		return;
       
   168 		}
       
   169 	if ( !iSnapshotRegistered )
       
   170 		{
       
   171 		const MVPbkViewContact& contact = iContactViewBase->ContactAtL( iContactCount );
       
   172 
       
   173 		MVPbkContactLink* contactLink = contact.CreateLinkLC();
       
   174 		iContactManager.RetrieveContactL( *contactLink, *this );
       
   175 		CleanupStack::PopAndDestroy();
       
   176 		}
       
   177 
       
   178 	_DBG_FILE("CNSmlDummyModsFetcher::FetchNextContactL(): end");
       
   179 	}
       
   180 
       
   181 // ------------------------------------------------------------------------------------------------
       
   182 // CNSmlDummyModsFetcher::DoCancel
       
   183 // ------------------------------------------------------------------------------------------------
       
   184 //
       
   185 void CNSmlDummyModsFetcher::DoCancel()
       
   186 	{
       
   187 	_DBG_FILE("CNSmlDummyModsFetcher::DoCancel(): begin");
       
   188 
       
   189 	User::RequestComplete( iCallerStatus, KErrCancel );
       
   190 
       
   191 	_DBG_FILE("CNSmlDummyModsFetcher::DoCancel(): end");
       
   192 	}
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // CNSmlDummyModsFetcher::IsConfidentialL
       
   196 // ----------------------------------------------------------------------------
       
   197 //
       
   198 TBool CNSmlDummyModsFetcher::IsConfidentialL( MVPbkStoreContact& aItem )
       
   199     {
       
   200     _DBG_FILE("CNSmlDummyModsFetcher::IsConfidentialL(): begin");
       
   201     TBool ret( EFalse );
       
   202 
       
   203     //find X-CLASS field type
       
   204 	const MVPbkFieldType* syncclass =
       
   205         iContactManager.FieldTypes().Find( R_VPBK_FIELD_TYPE_SYNCCLASS );
       
   206 	CVPbkBaseContactFieldTypeIterator* itr =
       
   207         CVPbkBaseContactFieldTypeIterator::NewLC( *syncclass,
       
   208             aItem.Fields() );
       
   209 	while ( itr->HasNext() )
       
   210         {
       
   211         const MVPbkBaseContactField* field = itr->Next();
       
   212         const MVPbkContactFieldTextData& data =
       
   213         	MVPbkContactFieldTextData::Cast( field->FieldData() );
       
   214         TPtrC ptr = data.Text();
       
   215         //compare the sync type
       
   216         if ( ptr.Compare( KNSmlContactSyncNoSync ) == 0 )
       
   217             {
       
   218             _DBG_FILE("CNSmlDummyModsFetcher::IsConfidentialL(): \
       
   219                        find confidential");
       
   220             ret = ETrue;
       
   221             }
       
   222 
       
   223         }
       
   224 	CleanupStack::PopAndDestroy( itr );
       
   225 
       
   226     _DBG_FILE("CNSmlDummyModsFetcher::IsConfidentialL(): end");
       
   227     return ret;
       
   228     }
       
   229 
       
   230 
       
   231 // ----------------------------------------------------------------------------
       
   232 // CNSmlDummyModsFetcher::RunError
       
   233 // ----------------------------------------------------------------------------
       
   234  TInt CNSmlDummyModsFetcher::RunError( TInt aError )
       
   235 	{
       
   236 	DBG_FILE_CODE(aError, _S8("CNSmlDummyModsFetcher::RunError() : error code received "));
       
   237 	User::RequestComplete( iCallerStatus, aError );
       
   238 	return KErrNone;
       
   239 	}
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CNSmlDummyModsFetcher::CreateViewL()
       
   243 // Create a contact view of the store which is opened
       
   244 // -----------------------------------------------------------------------------
       
   245 
       
   246 void CNSmlDummyModsFetcher::CreateViewL()
       
   247 	{
       
   248 	_DBG_FILE("CNSmlDummyModsFetcher::CreateViewL(): begin");
       
   249 
       
   250 	CVPbkContactViewDefinition* viewDef = CVPbkContactViewDefinition::NewL();
       
   251 	CleanupStack::PushL( viewDef );
       
   252 	viewDef->SetType( EVPbkContactsView );
       
   253 
       
   254 	viewDef->SetUriL( iStore.StoreProperties().Uri().UriDes() );
       
   255 
       
   256 	 iContactViewBase = iContactManager.CreateContactViewLC(
       
   257 				                         *this,
       
   258 				                         *viewDef,
       
   259 				                         iContactManager.FieldTypes()  );
       
   260 	CleanupStack::Pop();
       
   261 	CleanupStack::PopAndDestroy( viewDef );
       
   262 
       
   263 	_DBG_FILE("CNSmlDummyModsFetcher::CreateViewL(): end");
       
   264 	}
       
   265 // ---------------------------------------------------------------------------
       
   266 //  CNSmlDummyModsFetcher::UpdateSnapshotL
       
   267 //  Add the fetched contacts id and timestamp
       
   268 //  to the snapshot.
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 
       
   272  void CNSmlDummyModsFetcher::UpdateSnapshotL( MVPbkStoreContact* aContact )
       
   273 {
       
   274     _DBG_FILE("CNSmlDummyModsFetcher::UpdateSnapshotL(): begin");
       
   275 
       
   276 	if( !IsConfidentialL( *aContact) )
       
   277 		{
       
   278 		CVPbkContactIdConverter* idConverter = CVPbkContactIdConverter::NewL( iStore );
       
   279 		CleanupStack::PushL( idConverter );
       
   280 
       
   281 		TInt32 id = idConverter->LinkToIdentifier(
       
   282 			*iContactViewBase->ContactAtL( iContactCount).CreateLinkLC() );
       
   283 		TNSmlSnapshotItem snap( id );
       
   284 
       
   285 		MVPbkStoreContact2* tempContact =
       
   286 		reinterpret_cast<MVPbkStoreContact2*> ( aContact->StoreContactExtension ( KMVPbkStoreContactExtension2Uid ) );
       
   287 
       
   288 		MVPbkStoreContactProperties *contactProterties
       
   289 									= tempContact ->PropertiesL();
       
   290 		CleanupDeletePushL( contactProterties );
       
   291 		snap.SetLastChangedDate( contactProterties->LastModifiedL() );
       
   292 		CleanupStack::PopAndDestroy();
       
   293 
       
   294 		iSnapshot->InsertIsqL( snap, iKey );
       
   295 		iCurrentSnapshotCounter++;
       
   296 		if ( iCurrentSnapshotCounter > KNSmlSnapshotCompressSize )
       
   297 			{
       
   298 			iSnapshot->Compress();
       
   299 			iCurrentSnapshotCounter = 0;
       
   300 			}
       
   301 		CleanupStack::PopAndDestroy();
       
   302 		CleanupStack::PopAndDestroy( idConverter );
       
   303 		}
       
   304 
       
   305 	iContactCount++;
       
   306 
       
   307 	if ( iContactCount == iContactViewBase->ContactCountL() )
       
   308 		{
       
   309 		iChangeFinder.SetNewSnapshot( iSnapshot ); // changefinder takes ownership
       
   310 		iSnapshot = NULL;
       
   311 		iSnapshotRegistered = ETrue;
       
   312 		User::RequestComplete( iCallerStatus, KErrNone );
       
   313 		}
       
   314 
       
   315 	_DBG_FILE("CNSmlDummyModsFetcher::UpdateSnapshotL(): end");
       
   316 }
       
   317 // ---------------------------------------------------------------------------
       
   318 // CNSmlDummyModsFetcher::ContactViewReady
       
   319 // Implements the view ready function of MVPbkContactViewObserver
       
   320 // ---------------------------------------------------------------------------
       
   321 void CNSmlDummyModsFetcher::ContactViewReady(
       
   322                 MVPbkContactViewBase& /*aView*/ )
       
   323 	{
       
   324     _DBG_FILE("CNSmlDummyModsFetcher::ContactViewReady(): begin");
       
   325 
       
   326 	SetActive();
       
   327 	TRequestStatus* status = &iStatus;
       
   328 	User::RequestComplete( status, KErrNone );
       
   329 
       
   330 	_DBG_FILE("CNSmlDummyModsFetcher::ContactViewReady(): end");
       
   331 	}
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CNSmlDummyModsFetcher::ContactViewUnavailable
       
   335 // Implements the view unavailable function of MVPbkContactViewObserver
       
   336 // ---------------------------------------------------------------------------
       
   337 void CNSmlDummyModsFetcher::ContactViewUnavailable(
       
   338                 MVPbkContactViewBase& /*aView*/ )
       
   339 {
       
   340 }
       
   341 
       
   342 // ---------------------------------------------------------------------------
       
   343 // CNSmlDummyModsFetcher::ContactAddedToView
       
   344 // Implements the add contact function of MVPbkContactViewObserver
       
   345 // ---------------------------------------------------------------------------
       
   346 void CNSmlDummyModsFetcher::ContactAddedToView(
       
   347             MVPbkContactViewBase& /*aView*/,
       
   348             TInt /*aIndex*/,
       
   349             const MVPbkContactLink& /*aContactLink*/ )
       
   350 {
       
   351 }
       
   352 
       
   353 // ---------------------------------------------------------------------------
       
   354 // Implements the remove contact function of MVPbkContactViewObserver
       
   355 // ---------------------------------------------------------------------------
       
   356 void CNSmlDummyModsFetcher::ContactRemovedFromView(
       
   357                 MVPbkContactViewBase& /*aView*/,
       
   358                 TInt /*aIndex*/,
       
   359                 const MVPbkContactLink& /*aContactLink*/ )
       
   360 {
       
   361 }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // CNSmlDummyModsFetcher::ContactViewError
       
   365 // Implements the view error function of MVPbkContactViewObserver
       
   366 // ---------------------------------------------------------------------------
       
   367 void CNSmlDummyModsFetcher::ContactViewError(
       
   368             MVPbkContactViewBase& /*aView*/,
       
   369             TInt aError,
       
   370             TBool /*aErrorNotified*/ )
       
   371 {
       
   372     _DBG_FILE("CNSmlDummyModsFetcher::ContactViewError(): begin");
       
   373 
       
   374     User::RequestComplete( iCallerStatus, aError );
       
   375 
       
   376     _DBG_FILE("CNSmlDummyModsFetcher::ContactViewError(): end");
       
   377 }
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 //  CNSmlDummyModsFetcher::VPbkSingleContactOperationComplete
       
   381 //  Called when the contact operation is completed.
       
   382 // ---------------------------------------------------------------------------
       
   383 //
       
   384  void CNSmlDummyModsFetcher::VPbkSingleContactOperationComplete(
       
   385 		MVPbkContactOperationBase& aOperation,
       
   386 		MVPbkStoreContact* aContact )
       
   387 {
       
   388     _DBG_FILE("CNSmlDummyModsFetcher::VPbkSingleContactOperationComplete(): begin");
       
   389 
       
   390 	MVPbkContactOperationBase* operation = &aOperation;
       
   391 	if ( operation )
       
   392 	{
       
   393 		delete operation;
       
   394 		operation = NULL;
       
   395 	}
       
   396 
       
   397 	TRAPD( error,UpdateSnapshotL( aContact ) );
       
   398 	delete aContact;
       
   399 	if( error!= KErrNone )
       
   400 	   {
       
   401 	   User::RequestComplete( iCallerStatus, error );
       
   402 	   }
       
   403 	else
       
   404 	   {
       
   405 	   SetActive();
       
   406 	   TRequestStatus* status = &iStatus;
       
   407 	   User::RequestComplete( status, KErrNone );
       
   408 	   }
       
   409 
       
   410 	_DBG_FILE("CNSmlDummyModsFetcher::VPbkSingleContactOperationComplete(): end");
       
   411 }
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 //  CNSmlDummyModsFetcher::VPbkSingleContactOperationFailed
       
   415 //  Called when the contact operation fails
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 void CNSmlDummyModsFetcher::VPbkSingleContactOperationFailed(
       
   419 		MVPbkContactOperationBase& aOperation,
       
   420 		 TInt /*aError*/ )
       
   421  {
       
   422     _DBG_FILE("CNSmlDummyModsFetcher::VPbkSingleContactOperationFailed(): begin");
       
   423 
       
   424  	MVPbkContactOperationBase* operation = &aOperation;
       
   425 	if ( operation )
       
   426 	{
       
   427 		delete operation;
       
   428 		operation = NULL;
       
   429 	}
       
   430 
       
   431 	_DBG_FILE("CNSmlDummyModsFetcher::VPbkSingleContactOperationFailed(): end");
       
   432  }
       
   433 // End of File