harvesterplugins/notes/src/notesplugin.cpp
changeset 26 367228f82b66
parent 18 1edf350003c5
child 27 7a8855317cbd
equal deleted inserted replaced
24:1abfa342db42 26:367228f82b66
    53 _LIT(KNpdUpdateTime , "Date");
    53 _LIT(KNpdUpdateTime , "Date");
    54 
    54 
    55 //Reference from CPix calender harvester plugin.
    55 //Reference from CPix calender harvester plugin.
    56 _LIT(KNotesTimeFormat,"%04d %02d %02d %02d %02d");
    56 _LIT(KNotesTimeFormat,"%04d %02d %02d %02d %02d");
    57 
    57 
    58 _LIT(KExcerptDelimiter, " ");
    58 //_LIT(KExcerptDelimiter, " ");
    59 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    60 // CNotesPlugin::NewL
    60 // CNotesPlugin::NewL
    61 // ---------------------------------------------------------------------------
    61 // ---------------------------------------------------------------------------
    62 //  
    62 //  
    63 CNotesPlugin* CNotesPlugin::NewL()
    63 CNotesPlugin* CNotesPlugin::NewL()
    97         iAsynchronizer->CancelCallback();
    97         iAsynchronizer->CancelCallback();
    98 	delete iAsynchronizer;
    98 	delete iAsynchronizer;
    99 	delete iIndexer;
    99 	delete iIndexer;
   100     delete iNotesInstanceView;
   100     delete iNotesInstanceView;
   101 	delete iEntryView;
   101 	delete iEntryView;
       
   102 	iJobQueue.Reset();
       
   103 	iJobQueue.Close();
   102 	iNotesInstanceArray.ResetAndDestroy();
   104 	iNotesInstanceArray.ResetAndDestroy();
   103 	if( iSession )
   105 	if( iSession )
   104 		{
   106 		{
   105 		iSession->StopChangeNotification();
   107 		iSession->StopChangeNotification();
   106 		}
   108 		}
   111 // CNotesPlugin::ConstructL
   113 // CNotesPlugin::ConstructL
   112 // ---------------------------------------------------------------------------
   114 // ---------------------------------------------------------------------------
   113 //  
   115 //  
   114 void CNotesPlugin::ConstructL()
   116 void CNotesPlugin::ConstructL()
   115 	{
   117 	{
       
   118     iIndexState = ETrue;
   116 	iAsynchronizer = CDelayedCallback::NewL( CActive::EPriorityIdle );
   119 	iAsynchronizer = CDelayedCallback::NewL( CActive::EPriorityIdle );
   117 	iSession = CCalSession::NewL();
   120 	iSession = CCalSession::NewL();
   118 	TRAPD ( err , iSession->OpenL( iSession->DefaultFileNameL() ) );
   121 	TRAPD ( err , iSession->OpenL( iSession->DefaultFileNameL() ) );
   119     if ( err == KErrNotFound)
   122     if ( err == KErrNotFound)
   120         {
   123         {
   169 void CNotesPlugin::StartHarvestingL(const TDesC& /*aQualifiedBaseAppClass*/)
   172 void CNotesPlugin::StartHarvestingL(const TDesC& /*aQualifiedBaseAppClass*/)
   170     {
   173     {
   171     OstTraceFunctionEntry0( CNOTESPLUGIN_STARTHARVESTINGL_ENTRY );
   174     OstTraceFunctionEntry0( CNOTESPLUGIN_STARTHARVESTINGL_ENTRY );
   172     CPIXLOGSTRING("CNotesPlugin::StartHarvestingL: Enter");
   175     CPIXLOGSTRING("CNotesPlugin::StartHarvestingL: Enter");
   173     iIndexer->ResetL();
   176     iIndexer->ResetL();
       
   177     iHarvestState = EHarvesterStartHarvest;
   174     //Have taken start time and end time reference from calender plugin
   178     //Have taken start time and end time reference from calender plugin
   175     TTime startTime , endTime;
   179     TTime startTime , endTime;
   176     InitTimeValuesL( startTime , endTime );
   180     InitTimeValuesL( startTime , endTime );
   177     TCalTime startTimeCal , endTimeCal ;
   181     TCalTime startTimeCal , endTimeCal ;
   178     startTimeCal.SetTimeUtcL( startTime );
   182     startTimeCal.SetTimeUtcL( startTime );
   197 void CNotesPlugin::DelayedCallbackL( TInt /*aCode*/ )
   201 void CNotesPlugin::DelayedCallbackL( TInt /*aCode*/ )
   198     {
   202     {
   199     OstTraceFunctionEntry0( CNOTESPLUGIN_DELAYEDCALLBACKL_ENTRY );
   203     OstTraceFunctionEntry0( CNOTESPLUGIN_DELAYEDCALLBACKL_ENTRY );
   200     // Harvest items on each call
   204     // Harvest items on each call
   201     CPIXLOGSTRING("CNotesPlugin::DelayedCallbackL: Enter");
   205     CPIXLOGSTRING("CNotesPlugin::DelayedCallbackL: Enter");
       
   206     //If paused state
       
   207     if(!iIndexState)
       
   208        return;
       
   209     
   202     if( iNoteCount )
   210     if( iNoteCount )
   203         {
   211         {
   204         OstTrace1( TRACE_NORMAL, CNOTESPLUGIN_DELAYEDCALLBACKL, "CNotesPlugin::DelayedCallbackL;Remaining Notes Count=%d", iNoteCount );
   212         OstTrace1( TRACE_NORMAL, CNOTESPLUGIN_DELAYEDCALLBACKL, "CNotesPlugin::DelayedCallbackL;Remaining Notes Count=%d", iNoteCount );
   205         CPIXLOGSTRING2("CNotesPlugin::DelayedCallbackL(): remaining Note count=%d.", iNoteCount);
   213         CPIXLOGSTRING2("CNotesPlugin::DelayedCallbackL(): remaining Note count=%d.", iNoteCount);
   206         // Retrieve the calendar entry for the calinstance and update the CPix database.
   214         // Retrieve the calendar entry for the calinstance and update the CPix database.
   217 		// Harvesting was successfully completed		
   225 		// Harvesting was successfully completed		
   218 		Flush(*iIndexer);
   226 		Flush(*iIndexer);
   219 #ifdef __PERFORMANCE_DATA
   227 #ifdef __PERFORMANCE_DATA
   220     UpdatePerformaceDataL();
   228     UpdatePerformaceDataL();
   221 #endif
   229 #endif
   222 		iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), KErrNone);		
   230         iHarvestState = EHarvesterIdleState;
       
   231         iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), KErrNone);		
   223 		}
   232 		}
   224 	OstTraceFunctionExit0( CNOTESPLUGIN_DELAYEDCALLBACKL_EXIT );
   233 	OstTraceFunctionExit0( CNOTESPLUGIN_DELAYEDCALLBACKL_EXIT );
   225 	}
   234 	}
   226 
   235 
   227 // ---------------------------------------------------------------------------
   236 // ---------------------------------------------------------------------------
   230 //  
   239 //  
   231 void CNotesPlugin::DelayedError(TInt aError)
   240 void CNotesPlugin::DelayedError(TInt aError)
   232 	{
   241 	{
   233 	// Harvesting was completed
   242 	// Harvesting was completed
   234 	Flush(*iIndexer);
   243 	Flush(*iIndexer);
       
   244 	iHarvestState = EHarvesterIdleState;
   235 	iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), aError);
   245 	iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), aError);
   236 	}
   246 	}
   237 
   247 
   238 // ---------------------------------------------------------------------------
   248 // ---------------------------------------------------------------------------
   239 // CNotesPlugin::CalChangeNotification
   249 // CNotesPlugin::CalChangeNotification
   264 		{		
   274 		{		
   265 		case EChangeAdd:
   275 		case EChangeAdd:
   266 			{
   276 			{
   267 			OstTrace1( TRACE_NORMAL, CNOTESPLUGIN_HANDLENOTECHANGEDENTRYL, "CNotesPlugin::HandleNoteChangedEntryL;Monitored add id=%d", changedEntry.iEntryId );
   277 			OstTrace1( TRACE_NORMAL, CNOTESPLUGIN_HANDLENOTECHANGEDENTRYL, "CNotesPlugin::HandleNoteChangedEntryL;Monitored add id=%d", changedEntry.iEntryId );
   268 			CPIXLOGSTRING2("CNotesPlugin::HandleNoteChangedEntryL(): Monitored add id=%d.", changedEntry.iEntryId);
   278 			CPIXLOGSTRING2("CNotesPlugin::HandleNoteChangedEntryL(): Monitored add id=%d.", changedEntry.iEntryId);
   269 			CreateNoteEntryL( changedEntry.iEntryId, ECPixAddAction );
   279 			if( iIndexState )
       
   280 			    CreateNoteEntryL( changedEntry.iEntryId, ECPixAddAction );
       
   281 			else
       
   282 			    OverWriteOrAddToQueueL(changedEntry.iEntryId, ECPixAddAction);
   270 			break;
   283 			break;
   271 			}
   284 			}
   272 
   285 
   273 		case EChangeDelete:
   286 		case EChangeDelete:
   274 			{	
   287 			{	
   275 			OstTrace1( TRACE_NORMAL, DUP1_CNOTESPLUGIN_HANDLENOTECHANGEDENTRYL, "CNotesPlugin::HandleNoteChangedEntryL;Monitored delete id=%d", changedEntry.iEntryId );
   288 			OstTrace1( TRACE_NORMAL, DUP1_CNOTESPLUGIN_HANDLENOTECHANGEDENTRYL, "CNotesPlugin::HandleNoteChangedEntryL;Monitored delete id=%d", changedEntry.iEntryId );
   276 			CPIXLOGSTRING2("CNotesPlugin::HandleNoteChangedEntryL(): Monitored delete id=%d.", changedEntry.iEntryId);
   289 			CPIXLOGSTRING2("CNotesPlugin::HandleNoteChangedEntryL(): Monitored delete id=%d.", changedEntry.iEntryId);
   277 			CreateNoteEntryL( changedEntry.iEntryId, ECPixRemoveAction );
   290 			if( iIndexState )
       
   291 			    CreateNoteEntryL( changedEntry.iEntryId, ECPixRemoveAction );
       
   292 			else
       
   293 			    OverWriteOrAddToQueueL(changedEntry.iEntryId, ECPixRemoveAction);
   278 			break;
   294 			break;
   279 			}
   295 			}
   280 
   296 
   281 		case EChangeModify:
   297 		case EChangeModify:
   282 			{
   298 			{
   283 			OstTrace1( TRACE_NORMAL, DUP2_CNOTESPLUGIN_HANDLENOTECHANGEDENTRYL, "CNotesPlugin::HandleNoteChangedEntryL;Monitored update id=%d", changedEntry.iEntryId );
   299 			OstTrace1( TRACE_NORMAL, DUP2_CNOTESPLUGIN_HANDLENOTECHANGEDENTRYL, "CNotesPlugin::HandleNoteChangedEntryL;Monitored update id=%d", changedEntry.iEntryId );
   284 			CPIXLOGSTRING2("CNotesPlugin::HandleNoteChangedEntryL(): Monitored update id=%d.", changedEntry.iEntryId);
   300 			CPIXLOGSTRING2("CNotesPlugin::HandleNoteChangedEntryL(): Monitored update id=%d.", changedEntry.iEntryId);
   285 			CreateNoteEntryL( changedEntry.iEntryId, ECPixUpdateAction );
   301 			if( iIndexState )
       
   302 			    CreateNoteEntryL( changedEntry.iEntryId, ECPixUpdateAction );
       
   303 			else
       
   304 			    OverWriteOrAddToQueueL(changedEntry.iEntryId, ECPixUpdateAction);
   286 			break;
   305 			break;
   287 			}
   306 			}
   288 
   307 
   289 		case EChangeUndefined:
   308 		case EChangeUndefined:
   290 			{
   309 			{
   295 			// Remove it from the harvesting queue to cause it to enter 
   314 			// Remove it from the harvesting queue to cause it to enter 
   296 			// EHarvesterStatusHibernate state.
   315 			// EHarvesterStatusHibernate state.
   297 			// Now add it to the harvesting queue and force a reharvest.
   316 			// Now add it to the harvesting queue and force a reharvest.
   298 
   317 
   299 			Flush(*iIndexer);
   318 			Flush(*iIndexer);
       
   319 			iJobQueue.Reset();
   300 			iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), KErrCancel);
   320 			iObserver->HarvestingCompleted(this, iIndexer->GetBaseAppClass(), KErrCancel);
   301 			iObserver->RemoveHarvestingQueue(this, iIndexer->GetBaseAppClass());
   321 			iObserver->RemoveHarvestingQueue(this, iIndexer->GetBaseAppClass());
   302 			iObserver->AddHarvestingQueue(this, iIndexer->GetBaseAppClass(), ETrue);
   322 			iObserver->AddHarvestingQueue(this, iIndexer->GetBaseAppClass(), ETrue);
   303 			break;
   323 			break;
   304 			}
   324 			}
   338             OstTrace0( TRACE_NORMAL, DUP1_CNOTESPLUGIN_CREATENOTEENTRYL, "CNotesPlugin::CreateNoteEntryL(): return as not a Note entry." );
   358             OstTrace0( TRACE_NORMAL, DUP1_CNOTESPLUGIN_CREATENOTEENTRYL, "CNotesPlugin::CreateNoteEntryL(): return as not a Note entry." );
   339             CPIXLOGSTRING("CNotesPlugin::CreateNoteEntryL(): return as not a Note entry.");
   359             CPIXLOGSTRING("CNotesPlugin::CreateNoteEntryL(): return as not a Note entry.");
   340 	        CleanupStack::PopAndDestroy(entry);
   360 	        CleanupStack::PopAndDestroy(entry);
   341 	        return;
   361 	        return;
   342 	        }
   362 	        }
       
   363 	    OstTrace0( TRACE_NORMAL, DUP4_CNOTESPLUGIN_CREATENOTEENTRYL, "CNotesPlugin::Indexing Notes" );
       
   364 	    
   343 	    OstTrace0( TRACE_NORMAL, DUP2_CNOTESPLUGIN_CREATENOTEENTRYL, "CNotesPlugin::CreateNoteEntryL(): Creating document." );
   365 	    OstTrace0( TRACE_NORMAL, DUP2_CNOTESPLUGIN_CREATENOTEENTRYL, "CNotesPlugin::CreateNoteEntryL(): Creating document." );
   344 	    CPIXLOGSTRING("CNotesPlugin::CreateNoteEntryL(): Creating document.");
   366 	    CPIXLOGSTRING("CNotesPlugin::CreateNoteEntryL(): Creating document.");
   345 		CSearchDocument* index_item = CSearchDocument::NewLC(docid_str, _L(NOTESAPPCLASS));
   367 		CSearchDocument* index_item = CSearchDocument::NewLC(docid_str, _L(NOTESAPPCLASS));
   346 		// Add Description fields		
   368 		// Add Description fields		
   347 		index_item->AddFieldL(KNpdMemo, entry->DescriptionL());
   369 		index_item->AddFieldL(KNpdMemo, entry->DescriptionL());
   358 
   380 
   359 		index_item->AddFieldL(KMimeTypeField, KMimeTypeNotes, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized);
   381 		index_item->AddFieldL(KMimeTypeField, KMimeTypeNotes, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized);
   360 
   382 
   361 		//For notes, no content is expected in excerpt for now.
   383 		//For notes, no content is expected in excerpt for now.
   362 		//See appclass-hierarchy.txt for details.
   384 		//See appclass-hierarchy.txt for details.
   363 #ifdef USE_HIGHLIGHTER
   385 //#ifdef USE_HIGHLIGHTER
   364 		_LIT(KExcerptTimeFormat,"%04d/%02d/%02d %02d:%02d");
   386 		_LIT(KExcerptTimeFormat,"%04d/%02d/%02d %02d:%02d");
   365 		index_item->AddHLDisplayFieldL(entry->DescriptionL());
   387 		index_item->AddHLDisplayFieldL(entry->DescriptionL());
   366 		
   388 		
   367 		dateString.Format( KExcerptTimeFormat, datetime.Year(),
   389 		dateString.Format( KExcerptTimeFormat, datetime.Year(),
   368 		                                     TInt(datetime.Month()+ 1),
   390 		                                     TInt(datetime.Month()+ 1),
   369 		                                     datetime.Day() + 1,
   391 		                                     datetime.Day() + 1,
   370 		                                     datetime.Hour(),
   392 		                                     datetime.Hour(),
   371 		                                     datetime.Minute());
   393 		                                     datetime.Minute());
   372         index_item->AddExcerptL(dateString);
   394         index_item->AddExcerptL(dateString);
   373     
   395     
   374 #endif      
   396 //#endif      
   375 		
   397 		
   376 		// Send for indexing
   398 		// Send for indexing
   377 		if (aActionType == ECPixAddAction)
   399 		if (aActionType == ECPixAddAction)
   378 			{
   400 			{
   379 #ifndef _DEBUG
   401 #ifndef _DEBUG
   441     TDateTime enddate(year,(TMonth)(month-1),day , 0 , 0 , 0 , 0);
   463     TDateTime enddate(year,(TMonth)(month-1),day , 0 , 0 , 0 , 0);
   442     aEndTime = enddate;
   464     aEndTime = enddate;
   443     CPIXLOGSTRING2("CNotesPlugin::InitTimeValuesL: Exit with Error = %d", error);     
   465     CPIXLOGSTRING2("CNotesPlugin::InitTimeValuesL: Exit with Error = %d", error);     
   444     OstTraceFunctionExit0( CNOTESPLUGIN_INITTIMEVALUESL_EXIT );
   466     OstTraceFunctionExit0( CNOTESPLUGIN_INITTIMEVALUESL_EXIT );
   445     }
   467     }
       
   468 // ---------------------------------------------------------------------------
       
   469 // CNotesPlugin::PausePluginL
       
   470 // ---------------------------------------------------------------------------
       
   471 //
       
   472 void CNotesPlugin::PausePluginL()
       
   473     {
       
   474     OstTraceFunctionEntry0( CNOTESPLUGIN_PAUSEPLUGINL_ENTRY );
       
   475     iIndexState = EFalse;
       
   476     OstTraceFunctionExit0( CNOTESPLUGIN_PAUSEPLUGINL_EXIT );
       
   477     }
       
   478 // ---------------------------------------------------------------------------
       
   479 // CNotesPlugin::ResumePluginL
       
   480 // ---------------------------------------------------------------------------
       
   481 //
       
   482 void CNotesPlugin::ResumePluginL()
       
   483     {
       
   484     OstTraceFunctionEntry0( CNOTESPLUGIN_RESUMEPLUGINL_ENTRY );
       
   485     iIndexState = ETrue;
       
   486             
       
   487     if(iHarvestState == EHarvesterStartHarvest)
       
   488         {
       
   489         if(iAsynchronizer->CallbackPending())
       
   490             iAsynchronizer->CancelCallback();
       
   491         iAsynchronizer->Start( 0, this, KHarvestingDelay );
       
   492         }
       
   493     else
       
   494         {
       
   495         IndexQueuedItems();
       
   496         }
       
   497     OstTraceFunctionExit0( CNOTESPLUGIN_RESUMEPLUGINL_EXIT );
       
   498     }
       
   499 // ---------------------------------------------------------------------------
       
   500 // CNotesPlugin::OverWriteOrAddToQueueL
       
   501 // ---------------------------------------------------------------------------
       
   502 //
       
   503 void CNotesPlugin::OverWriteOrAddToQueueL(const TCalLocalUid& aLocalUid, TCPixActionType aActionType)
       
   504     {
       
   505     OstTraceFunctionEntry0( CNOTESPLUGIN_OVERWRITEORADDTOQUEUEL_ENTRY );
       
   506     TRecord entry;    
       
   507     for (TInt i=0; i<iJobQueue.Count(); i++)
       
   508         {
       
   509             if (iJobQueue[i].iLocalUid == aLocalUid)
       
   510             {
       
   511                 // Older version found
       
   512                 iJobQueue[i].iLocalUid = aLocalUid;
       
   513                 iJobQueue[i].iActionType = aActionType;
       
   514                 OstTraceFunctionExit0( CNOTESPLUGIN_OVERWRITEORADDTOQUEUEL_EXIT );
       
   515                 return;
       
   516             }
       
   517         }        
       
   518     // older not found, append
       
   519     entry.iActionType = aActionType;
       
   520     entry.iLocalUid = aLocalUid;
       
   521     iJobQueue.AppendL(entry);
       
   522     OstTraceFunctionExit0( DUP1_CNOTESPLUGIN_OVERWRITEORADDTOQUEUEL_EXIT );
       
   523     }
       
   524 // ---------------------------------------------------------------------------
       
   525 // CNotesPlugin::IndexQueuedItems
       
   526 // ---------------------------------------------------------------------------
       
   527 //
       
   528 void CNotesPlugin::IndexQueuedItems()
       
   529     {
       
   530     OstTraceFunctionEntry0( CNOTESPLUGIN_INDEXQUEUEDITEMS_ENTRY );
       
   531     while (iJobQueue.Count()>0)
       
   532         {
       
   533         TRecord entry = iJobQueue[0];        
       
   534         //Let the indexer handle this object TRAP it as it can leave
       
   535         TRAPD(err,CreateNoteEntryL( entry.iLocalUid, entry.iActionType ));        
       
   536         if(KErrNone == err)
       
   537             {
       
   538             iJobQueue.Remove(0);
       
   539             }
       
   540         }
       
   541     OstTraceFunctionExit0( CNOTESPLUGIN_INDEXQUEUEDITEMS_EXIT );
       
   542     }
   446 
   543 
   447 #ifdef __PERFORMANCE_DATA
   544 #ifdef __PERFORMANCE_DATA
   448 void CNotesPlugin::UpdatePerformaceDataL()
   545 void CNotesPlugin::UpdatePerformaceDataL()
   449     {
   546     {
   450     TTime now;
   547     TTime now;