harvesterplugins/calendar/src/ccalendarplugin.cpp
changeset 0 ccd0fd43f247
child 2 208a4ba3894c
equal deleted inserted replaced
-1:000000000000 0:ccd0fd43f247
       
     1 /*
       
     2 * Copyright (c) 2010 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: 
       
    15  *
       
    16 */
       
    17 
       
    18 #include "ccalendarplugin.h"
       
    19 #include "harvesterserverlogger.h"
       
    20 #include <common.h>
       
    21 #include <csearchdocument.h>
       
    22 
       
    23 #include <ccpixindexer.h>
       
    24 #include <e32base.h> 
       
    25 #include <calsession.h>
       
    26 #include <calentry.h>
       
    27 #include <caliterator.h>
       
    28 #include <calentryview.h>
       
    29 #include <mmfcontrollerpluginresolver.h> // CleanupResetAndDestroyPushL
       
    30 
       
    31 _LIT(KMimeTypeField, CPIX_MIMETYPE_FIELD);
       
    32 _LIT(KMimeTypeCalendar, CALENDAR_MIMETYPE);
       
    33 
       
    34 _LIT(KExcerptDelimiter, " ");
       
    35 
       
    36 /** The delay between harvesting chunks. */
       
    37 const TInt KHarvestingDelay = 2000;
       
    38 
       
    39 _LIT(KCalendarTimeFormat,"%F%/0%Y%M%D%H%T"); // Locale independent YYYYMMDDHHSS
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CMessagePlugin::NewL
       
    43 // ---------------------------------------------------------------------------
       
    44 //  
       
    45 CCalendarPlugin* CCalendarPlugin::NewL()
       
    46 	{
       
    47 	CCalendarPlugin* instance = CCalendarPlugin::NewLC();
       
    48     CleanupStack::Pop(instance);
       
    49     return instance;
       
    50 	}
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CCalendarPlugin::NewLC
       
    54 // ---------------------------------------------------------------------------
       
    55 //  
       
    56 CCalendarPlugin* CCalendarPlugin::NewLC()
       
    57 	{
       
    58 	CCalendarPlugin* instance = new (ELeave) CCalendarPlugin();
       
    59     CleanupStack::PushL(instance);
       
    60     instance->ConstructL();
       
    61     return instance;
       
    62 	}
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CCalendarPlugin::CCalendarPlugin
       
    66 // ---------------------------------------------------------------------------
       
    67 //  
       
    68 CCalendarPlugin::CCalendarPlugin()
       
    69 	{
       
    70 	}
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CCalendarPlugin::~CCalendarPlugin
       
    74 // ---------------------------------------------------------------------------
       
    75 //  
       
    76 CCalendarPlugin::~CCalendarPlugin()
       
    77 	{
       
    78     if (iAsynchronizer)
       
    79         iAsynchronizer->CancelCallback();
       
    80 	delete iAsynchronizer;
       
    81 	delete iIndexer;
       
    82 
       
    83 	delete iEntryView;
       
    84 	delete iCalIterator;
       
    85 	if( iSession )
       
    86 		{
       
    87 		iSession->StopChangeNotification();
       
    88 		}
       
    89 	delete iSession;
       
    90 	}
       
    91 	
       
    92 // ---------------------------------------------------------------------------
       
    93 // CCalendarPlugin::ConstructL
       
    94 // ---------------------------------------------------------------------------
       
    95 //  
       
    96 void CCalendarPlugin::ConstructL()
       
    97 	{
       
    98 	iAsynchronizer = CDelayedCallback::NewL( CActive::EPriorityIdle );
       
    99 	iSession = CCalSession::NewL();	
       
   100 	TRAPD ( err , iSession->OpenL( iSession->DefaultFileNameL() ) );
       
   101 	if ( err == KErrNotFound)
       
   102 	    {
       
   103 	    iSession->CreateCalFileL( iSession->DefaultFileNameL() );
       
   104 	    iSession->OpenL( iSession->DefaultFileNameL() );
       
   105 	    }
       
   106 	iCalIterator = CCalIter::NewL( *iSession );
       
   107 	iEntryView = CCalEntryView::NewL( *iSession, *this );
       
   108 	}
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CCalendarPlugin::StartPluginL
       
   112 // ---------------------------------------------------------------------------
       
   113 //  
       
   114 void CCalendarPlugin::StartPluginL()
       
   115 	{
       
   116 	// Define this base application class, use default location
       
   117 	User::LeaveIfError(iSearchSession.DefineVolume( _L(CALENDAR_QBASEAPPCLASS), KNullDesC ));
       
   118 
       
   119 	// Open the database
       
   120 	iIndexer = CCPixIndexer::NewL(iSearchSession);
       
   121 	iIndexer->OpenDatabaseL( _L(CALENDAR_QBASEAPPCLASS) ); 
       
   122 
       
   123 	// Start harvester for this plugin
       
   124 	iObserver->AddHarvestingQueue(this, iIndexer->GetBaseAppClass());
       
   125 	
       
   126 	// Start monitoring calendar events
       
   127 	TTime startTime( TDateTime( 1980, EJanuary, 0, 0, 0, 0, 0 ) );
       
   128 	TTime endTime( startTime + TTimeIntervalYears( 40 ) );
       
   129 	TCalTime startTimeCal;
       
   130 	TCalTime endTimeCal;
       
   131 	startTimeCal.SetTimeUtcL( startTime );
       
   132 	endTimeCal.SetTimeUtcL( endTime );
       
   133 	CCalChangeNotificationFilter* filter = CCalChangeNotificationFilter::NewL( MCalChangeCallBack2::EChangeEntryAll, ETrue, CalCommon::TCalTimeRange( startTimeCal, endTimeCal ) );
       
   134 	iSession->StartChangeNotification( *this, *filter );
       
   135 	delete filter;
       
   136 	}	
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CCalendarPlugin::StartHarvestingL
       
   140 // ---------------------------------------------------------------------------
       
   141 //  
       
   142 void CCalendarPlugin::StartHarvestingL(const TDesC& /*aQualifiedBaseAppClass*/)
       
   143     {
       
   144     iIndexer->ResetL();
       
   145     iStartHarvesting = ETrue;
       
   146 #ifdef __PERFORMANCE_DATA
       
   147     iStartTime.UniversalTime();
       
   148 #endif  
       
   149     if (iFirstEntry)
       
   150         {
       
   151         iAsynchronizer->Start( 0, this, KHarvestingDelay );
       
   152         }
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CCalendarPlugin::Progress
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 void CCalendarPlugin::Progress( TInt /*aPercentageCompleted*/ )
       
   160 	{
       
   161 	// No implementation needed
       
   162 	}
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CCalendarPlugin::Completed
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CCalendarPlugin::Completed( TInt aError )
       
   169 	{
       
   170 	// No error code and harvesting is needed star harvesting.
       
   171 	iFirstEntry = ETrue;
       
   172 	if (aError == KErrNone && iStartHarvesting)
       
   173 		{
       
   174 		// Calendar entry view constructed successfully, start harvesting
       
   175 		iAsynchronizer->Start( 0, this, KHarvestingDelay );
       
   176 		}
       
   177 	}
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CCalendarPlugin::NotifyProgress
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 TBool CCalendarPlugin::NotifyProgress()
       
   184 	{
       
   185 	return EFalse;
       
   186 	}
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CContactsPlugin::DelayedCallbackL
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CCalendarPlugin::DelayedCallbackL( TInt /*aCode*/ )
       
   193     {
       
   194     // Harvest items on each call
       
   195 	TPtrC8 uid( KNullDesC8 );
       
   196 
       
   197 	if( iFirstEntry )
       
   198 		{
       
   199 		uid.Set( iCalIterator->FirstL() );
       
   200 		iFirstEntry = EFalse;
       
   201 		}
       
   202 	else
       
   203 		{
       
   204 		uid.Set( iCalIterator->NextL() );
       
   205 		}
       
   206 
       
   207 	if( uid != KNullDesC8 )
       
   208 		{
       
   209 		RPointerArray<CCalEntry> entryArray;
       
   210 		CleanupResetAndDestroyPushL(entryArray);
       
   211 		iEntryView->FetchL( uid, entryArray );
       
   212 		// Handle only the first (i.e. parent entry)
       
   213 		if( entryArray.Count() > 0 )
       
   214 			{
       
   215 			CCalEntry* entry = (CCalEntry*)entryArray[ 0 ];
       
   216 			CPIXLOGSTRING2("CCalendarPlugin::DelayedCallbackL(): Harvesting id=%d.", entry->LocalUidL());
       
   217 			CreateEntryL( entry->LocalUidL(), ECPixAddAction );
       
   218 			}
       
   219 		CleanupStack::PopAndDestroy(&entryArray);
       
   220 
       
   221 		// Request next entry.
       
   222 		iAsynchronizer->Start( 0, this, KHarvestingDelay );
       
   223 		}
       
   224 	else
       
   225 		{
       
   226 		// Harvesting was successfully completed
       
   227 		iFirstEntry = ETrue; // Make sure we can harvest next time as well...
       
   228 		Flush(*iIndexer);
       
   229 #ifdef __PERFORMANCE_DATA
       
   230     UpdatePerformaceDataL();
       
   231 #endif
       
   232 		iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), KErrNone);		
       
   233 		}
       
   234 	}
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CCalendarPlugin::DelayedError
       
   238 // ---------------------------------------------------------------------------
       
   239 //  
       
   240 void CCalendarPlugin::DelayedError(TInt aError)
       
   241 	{
       
   242 	// Harvesting was completed
       
   243 	iFirstEntry = ETrue; // Make sure we can harvest next time as well...
       
   244 	Flush(*iIndexer);
       
   245 	iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), aError);
       
   246 	}
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CCalendarPlugin::CalChangeNotification
       
   250 // ---------------------------------------------------------------------------
       
   251 //  
       
   252 void CCalendarPlugin::CalChangeNotification( RArray< TCalChangeEntry >& aChangeItems )
       
   253 	{
       
   254 	const TInt count(aChangeItems.Count());
       
   255 	CPIXLOGSTRING2("CCalendarPlugin::CalChangeNotification(): changed item count =%d.", count);
       
   256 	for( TInt i = 0; i < count; ++i )
       
   257 		{
       
   258 		TCalChangeEntry changedEntry = aChangeItems[ i ];
       
   259 		TRAP_IGNORE(HandleChangedEntryL(changedEntry));
       
   260 		}
       
   261 	}
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // CCalendarPlugin::HandleChangedEntryL
       
   265 // ---------------------------------------------------------------------------
       
   266 //  
       
   267 void CCalendarPlugin::HandleChangedEntryL(const TCalChangeEntry& changedEntry)
       
   268 	{
       
   269 	switch( changedEntry.iChangeType )
       
   270 		{		
       
   271 		case EChangeAdd:
       
   272 			{
       
   273 			CPIXLOGSTRING2("CCalendarPlugin::HandleChangedEntryL(): Monitored add id=%d.", changedEntry.iEntryId);
       
   274 #ifdef __PERFORMANCE_DATA
       
   275             iStartTime.UniversalTime();
       
   276 			CreateEntryL( changedEntry.iEntryId, ECPixAddAction );
       
   277 			UpdatePerformaceDataL(ECPixAddAction);
       
   278 #else
       
   279 			CreateEntryL( changedEntry.iEntryId, ECPixAddAction );
       
   280 #endif
       
   281 			break;
       
   282 			}
       
   283 
       
   284 		case EChangeDelete:
       
   285 			{	
       
   286 			CPIXLOGSTRING2("CCalendarPlugin::HandleChangedEntryL(): Monitored delete id=%d.", changedEntry.iEntryId);
       
   287 #ifdef __PERFORMANCE_DATA
       
   288             iStartTime.UniversalTime();
       
   289 			CreateEntryL( changedEntry.iEntryId, ECPixAddAction );
       
   290 			UpdatePerformaceDataL(ECPixAddAction);
       
   291 #else
       
   292 			CreateEntryL( changedEntry.iEntryId, ECPixRemoveAction );
       
   293 #endif
       
   294 			break;
       
   295 			}
       
   296 
       
   297 		case EChangeModify:
       
   298 			{
       
   299 			CPIXLOGSTRING2("CCalendarPlugin::HandleChangedEntryL(): Monitored update id=%d.", changedEntry.iEntryId);
       
   300 #ifdef __PERFORMANCE_DATA
       
   301             iStartTime.UniversalTime(); 
       
   302 			CreateEntryL( changedEntry.iEntryId, ECPixUpdateAction );
       
   303 			UpdatePerformaceDataL(ECPixUpdateAction);
       
   304 #else
       
   305 			CreateEntryL( changedEntry.iEntryId, ECPixUpdateAction );
       
   306 #endif
       
   307 			break;
       
   308 			}
       
   309 			
       
   310 		/* TCalChangeEntry documentation:
       
   311 			If iChangeType is EChangeUndefined or EChangeOverflowError, iEntryId and
       
   312 			iEntryType are undefined and should not be used by clients.
       
   313 		 */
       
   314 		case EChangeUndefined:
       
   315 			{
       
   316 			CPIXLOGSTRING("CCalendarPlugin::HandleChangedEntryL(): EChangeUndefined.");
       
   317 			// This event could be related to synchronization.
       
   318 			// Mark harvesting as cancelled.
       
   319 			// Remove it from the harvesting queue to cause it to enter 
       
   320 			// EHarvesterStatusHibernate state.
       
   321 			// Now add it to the harvesting queue and force a reharvest.
       
   322 
       
   323 			iFirstEntry = ETrue; // Make sure we can harvest next time as well...
       
   324 			Flush(*iIndexer);
       
   325 			iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), KErrCancel);
       
   326 			iObserver->RemoveHarvestingQueue(this, iIndexer->GetBaseAppClass());
       
   327 			iObserver->AddHarvestingQueue(this, iIndexer->GetBaseAppClass(), ETrue);
       
   328 			break;
       
   329 			}
       
   330 		default:
       
   331 			// Ignore other events
       
   332 			break;
       
   333 		}	
       
   334 	}
       
   335 	
       
   336 // ---------------------------------------------------------------------------
       
   337 // CCalendarPlugin::CreateEntryL
       
   338 // ---------------------------------------------------------------------------
       
   339 //  
       
   340 void CCalendarPlugin::CreateEntryL( const TCalLocalUid& aLocalUid, TCPixActionType aActionType )
       
   341 	{
       
   342 	if (!iIndexer)
       
   343     	return;
       
   344 
       
   345 	CPIXLOGSTRING2("CCalendarPlugin::CreateEntryL():  Uid = %d.", aLocalUid);
       
   346 	
       
   347 	// creating CSearchDocument object with unique ID for this application
       
   348 	TBuf<20> docid_str;
       
   349 	docid_str.AppendNum(aLocalUid);
       
   350 	
       
   351 	if (aActionType == ECPixAddAction || aActionType == ECPixUpdateAction)
       
   352 		{
       
   353 		CSearchDocument* index_item = CSearchDocument::NewLC(docid_str, _L(CALENDARAPPCLASS)); 
       
   354 		
       
   355 		// Return the entry that has been fetched, this will be NULL if there are 
       
   356 		// no entries with the cal unique id
       
   357 		CCalEntry* entry = iEntryView->FetchL(aLocalUid);
       
   358 		// TODO leave if entry is NULL
       
   359 		CleanupStack::PushL(entry);
       
   360 		// TODO Uncomment below portion of code when the latest Organiser code in MCL
       
   361 		if( CCalEntry::ENote == entry->EntryTypeL() )
       
   362 		    {
       
   363             CleanupStack::PopAndDestroy(entry);
       
   364             CleanupStack::PopAndDestroy(index_item);
       
   365             CPIXLOGSTRING("CCalendarPlugin::CreateEntryL(): Donot harvest Note item.");
       
   366             return;
       
   367 		    }
       
   368 
       
   369 		// Add fields
       
   370 		index_item->AddFieldL(KCalendarSummaryField, entry->SummaryL());
       
   371 		index_item->AddFieldL(KCalendarDescriptionField, entry->DescriptionL());
       
   372 		index_item->AddFieldL(KCalendarLocationField, entry->LocationL());
       
   373 
       
   374 		TBuf<30> dateString;
       
   375 
       
   376 		TTime startTime = entry->StartTimeL().TimeUtcL();
       
   377 		startTime.FormatL(dateString, KCalendarTimeFormat);
       
   378 		index_item->AddFieldL(KCalendarStartTimeField, dateString, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized);
       
   379 
       
   380 		TTime endTime = entry->EndTimeL().TimeUtcL();
       
   381 		endTime.FormatL(dateString, KCalendarTimeFormat);
       
   382 		index_item->AddFieldL(KCalendarEndTimeField, dateString, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized);
       
   383 
       
   384 		index_item->AddFieldL(KMimeTypeField, KMimeTypeCalendar, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized);
       
   385 
       
   386     	TInt excerptLength = 3 + entry->SummaryL().Length() + entry->DescriptionL().Length() + entry->LocationL().Length();
       
   387 		HBufC* excerpt = HBufC::NewLC(excerptLength);
       
   388 		TPtr excerptDes = excerpt->Des();
       
   389 		excerptDes.Copy(entry->SummaryL());
       
   390 		excerptDes.Append(KExcerptDelimiter);
       
   391 		excerptDes.Append(entry->DescriptionL());
       
   392 		excerptDes.Append(KExcerptDelimiter);
       
   393 		excerptDes.Append(entry->LocationL());
       
   394 
       
   395         index_item->AddExcerptL(*excerpt);
       
   396         CleanupStack::PopAndDestroy(excerpt);
       
   397         CleanupStack::PopAndDestroy(entry);
       
   398 
       
   399 		/*
       
   400 		RPointerArray<CCalAttendee>& attendees = iEntry.AttendeesL();
       
   401 		for( TInt i = 0; i < attendees.Count(); i++ )
       
   402 			{
       
   403 			CCalAttendee* attendee = (CCalAttendee*)attendees[ i ];
       
   404 			TInt err = KErrNone;
       
   405 		    TRAP( err, AddContent( CIndexContent::NewL( attendee->CommonName(), ECalendarAttendee ) ) );
       
   406 			}
       
   407 		attendees.ResetAndDestroy();
       
   408 		*/
       
   409 		
       
   410 		// Send for indexing
       
   411 		if (aActionType == ECPixAddAction)
       
   412 			{
       
   413 			TRAPD(err, iIndexer->AddL(*index_item));
       
   414 			if (err == KErrNone)
       
   415 				{
       
   416 				CPIXLOGSTRING("CCalendarPlugin::CreateEntryL(): Added.");
       
   417 				}
       
   418 			else
       
   419 				{
       
   420 				CPIXLOGSTRING2("CCalendarPlugin::CreateEntryL(): Error %d in adding.", err);
       
   421 				}			
       
   422 			}
       
   423 		else if (aActionType == ECPixUpdateAction)
       
   424 			{
       
   425 			TRAPD(err, iIndexer->UpdateL(*index_item));
       
   426 			if (err == KErrNone)
       
   427 				{
       
   428 				CPIXLOGSTRING("CCalendarPlugin::CreateEntryL(): Updated.");
       
   429 				}
       
   430 			else
       
   431 				{
       
   432 				CPIXLOGSTRING2("CCalendarPlugin::CreateEntryL(): Error %d in updating.", err);
       
   433 				}			
       
   434 			}
       
   435 		CleanupStack::PopAndDestroy(index_item);
       
   436 		}
       
   437 	else if (aActionType == ECPixRemoveAction)
       
   438 		{
       
   439 		TRAPD(err, iIndexer->DeleteL(docid_str));
       
   440 		if (err == KErrNone)
       
   441 			{
       
   442 			CPIXLOGSTRING("CCalendarPlugin::CreateEntryL(): Deleted.");
       
   443 			}
       
   444 		else
       
   445 			{
       
   446 			CPIXLOGSTRING2("CCalendarPlugin::CreateEntryL(): Error %d in deleting.", err);				
       
   447 			}
       
   448 		}
       
   449 
       
   450 	}
       
   451 
       
   452 // ---------------------------------------------------------------------------
       
   453 // CCalendarPlugin::UpdatePerformaceDataL
       
   454 // ---------------------------------------------------------------------------
       
   455 //
       
   456 #ifdef __PERFORMANCE_DATA
       
   457 void CCalendarPlugin::UpdatePerformaceDataL()
       
   458     {
       
   459     TTime now;
       
   460    
       
   461     
       
   462     iCompleteTime.UniversalTime();
       
   463     TTimeIntervalMicroSeconds timeDiff = iCompleteTime.MicroSecondsFrom(iStartTime);
       
   464     
       
   465     RFs fileSession;
       
   466     RFile perfFile;
       
   467     User::LeaveIfError( fileSession.Connect () );
       
   468     
       
   469     
       
   470     /* Open file if it exists, otherwise create it and write content in it */
       
   471     
       
   472         if(perfFile.Open(fileSession, _L("c:\\data\\CalenderPerf.txt"), EFileWrite))
       
   473                    User::LeaveIfError(perfFile.Create (fileSession, _L("c:\\data\\CalenderPerf.txt"), EFileWrite));
       
   474     
       
   475     HBufC8 *heap = HBufC8::NewL(100);
       
   476     TPtr8 ptr = heap->Des();
       
   477     now.HomeTime();
       
   478     TBuf<50> timeString;             
       
   479                 
       
   480     _LIT(KOwnTimeFormat,"%:0%H%:1%T%:2%S");
       
   481     now.FormatL(timeString,KOwnTimeFormat);
       
   482     ptr.AppendNum(now.DateTime().Day());
       
   483     ptr.Append(_L("/"));
       
   484     ptr.AppendNum(now.DateTime().Month());
       
   485     ptr.Append(_L("/"));
       
   486     ptr.AppendNum(now.DateTime().Year());
       
   487     ptr.Append(_L(":"));
       
   488     ptr.Append(timeString);
       
   489     ptr.Append( _L("Time taken for Harvesting Calendar is : "));
       
   490     ptr.AppendNum(timeDiff.Int64()/1000) ;
       
   491     ptr.Append(_L(" MilliSeonds \n"));
       
   492     TInt myInt = 0;
       
   493     perfFile.Seek(ESeekEnd,myInt);
       
   494     perfFile.Write (ptr);
       
   495     perfFile.Close ();
       
   496     fileSession.Close ();
       
   497     delete heap;
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // CCalendarPlugin::UpdatePerformaceDataL
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 void CCalendarPlugin::UpdatePerformaceDataL(TCPixActionType action)
       
   505     {
       
   506    
       
   507     iCompleteTime.UniversalTime();
       
   508     TTimeIntervalMicroSeconds timeDiff = iCompleteTime.MicroSecondsFrom(iStartTime);
       
   509     
       
   510     RFs fileSession;
       
   511     RFile perfFile;
       
   512     User::LeaveIfError( fileSession.Connect () );
       
   513     
       
   514     
       
   515     /* Open file if it exists, otherwise create it and write content in it */
       
   516     
       
   517         if(perfFile.Open(fileSession, _L("c:\\data\\CalenderPerf.txt"), EFileWrite))
       
   518                    User::LeaveIfError(perfFile.Create (fileSession, _L("c:\\data\\CalenderPerf.txt"), EFileWrite));
       
   519     
       
   520     HBufC8 *heap = HBufC8::NewL(100);
       
   521     TPtr8 ptr = heap->Des();
       
   522 
       
   523     switch (action) {
       
   524         case ECPixAddAction: ptr.Append( _L("add "));break;
       
   525         case ECPixUpdateAction: ptr.Append( _L("upd "));break;
       
   526         case ECPixRemoveAction: ptr.Append( _L("del "));break;
       
   527     } 
       
   528     ptr.AppendNum(timeDiff.Int64()/1000) ;
       
   529     ptr.Append(_L("\n"));
       
   530     TInt myInt = 0;
       
   531     perfFile.Seek(ESeekEnd,myInt);
       
   532     perfFile.Write (ptr);
       
   533     perfFile.Close ();
       
   534     fileSession.Close ();
       
   535     delete heap;
       
   536     }
       
   537 #endif
       
   538 // End of file