harvesterplugins/contacts/src/ccontactsplugin.cpp
changeset 27 7a8855317cbd
parent 26 367228f82b66
equal deleted inserted replaced
26:367228f82b66 27:7a8855317cbd
    20 #include <common.h>
    20 #include <common.h>
    21 #include <csearchdocument.h>
    21 #include <csearchdocument.h>
    22 
    22 
    23 #include <ccpixindexer.h>
    23 #include <ccpixindexer.h>
    24 #include <e32base.h>
    24 #include <e32base.h>
       
    25 #include <s32file.h>
       
    26 #include <BAUTILS.H>
    25 #include "OstTraceDefinitions.h"
    27 #include "OstTraceDefinitions.h"
    26 #ifdef OST_TRACE_COMPILER_IN_USE
    28 #ifdef OST_TRACE_COMPILER_IN_USE
    27 #include "ccontactspluginTraces.h"
    29 #include "ccontactspluginTraces.h"
    28 #endif
    30 #endif
    29  
    31  
    38 /** Number of contacts to process in one active scheduler cycle */
    40 /** Number of contacts to process in one active scheduler cycle */
    39 const TInt KContactsPerRunL = 1;
    41 const TInt KContactsPerRunL = 1;
    40 
    42 
    41 _LIT(KExcerptDelimiter, " ");
    43 _LIT(KExcerptDelimiter, " ");
    42 _LIT(KTimeFormat, "%D%N%Y%1 %2 %3"); //Date, Month name and Year format
    44 _LIT(KTimeFormat, "%D%N%Y%1 %2 %3"); //Date, Month name and Year format
    43  
    45 _LIT(KManagerFileName, "ContactStore.temp");
    44 // -----------------------------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    45 // CContactsPlugin::NewL()
    47 // CContactsPlugin::NewL()
    46 // -----------------------------------------------------------------------------
    48 // -----------------------------------------------------------------------------
    47 //
    49 //
    48 CContactsPlugin* CContactsPlugin::NewL()
    50 CContactsPlugin* CContactsPlugin::NewL()
    93             if(iHLDisplayExcerpt)
    95             if(iHLDisplayExcerpt)
    94                 {
    96                 {
    95                 delete iHLDisplayExcerpt;
    97                 delete iHLDisplayExcerpt;
    96                 iHLDisplayExcerpt = NULL;
    98                 iHLDisplayExcerpt = NULL;
    97                 }
    99                 }
    98 //#endif            
   100 //#endif
       
   101     iFs.Close();    
    99 	}
   102 	}
   100 	
   103 	
   101 // -----------------------------------------------------------------------------
   104 // -----------------------------------------------------------------------------
   102 // CContactsPlugin::ConstructL()
   105 // CContactsPlugin::ConstructL()
   103 // -----------------------------------------------------------------------------
   106 // -----------------------------------------------------------------------------
   104 //
   107 //
   105 void CContactsPlugin::ConstructL()
   108 void CContactsPlugin::ConstructL()
   106 	{
   109 	{    
       
   110     
   107 	iDatabase = CContactDatabase::OpenL();
   111 	iDatabase = CContactDatabase::OpenL();
   108     iIndexState = ETrue;
   112     iIndexState = ETrue;
   109 	// This pointer is valid until a change is made to the database or until 
   113 	// This pointer is valid until a change is made to the database or until 
   110 	// the database's active object is allowed to run. If the array is 
   114 	// the database's active object is allowed to run. If the array is 
   111 	// required after one of the above two events has occurred, a copy of the 
   115 	// required after one of the above two events has occurred, a copy of the 
   112 	// array must first be made.
   116 	// array must first be made.
   113 	iContacts = iDatabase->SortedItemsL();
   117 	iContacts = iDatabase->SortedItemsL();
   114 
   118 
   115     iAsynchronizer = CDelayedCallback::NewL( CActive::EPriorityIdle );
   119     iAsynchronizer = CDelayedCallback::NewL( CActive::EPriorityIdle );// connect to file system
       
   120     
       
   121     User::LeaveIfError(iFs.Connect());    
       
   122     // Load the configuration
       
   123     TFileName pathWithoutDrive;
       
   124     iFs.CreatePrivatePath(EDriveC);
       
   125     iFilePath = _L("C:");        
       
   126     iFs.PrivatePath( pathWithoutDrive );
       
   127     iFilePath.Append(pathWithoutDrive);
       
   128     iFilePath.Append(KManagerFileName);
       
   129     
   116 	}
   130 	}
   117 
   131 
   118 // -----------------------------------------------------------------------------
   132 // -----------------------------------------------------------------------------
   119 // CContactsPlugin::StartPluginL()
   133 // CContactsPlugin::StartPluginL()
   120 // -----------------------------------------------------------------------------
   134 // -----------------------------------------------------------------------------
   131 	// Start harvester for this plugin
   145 	// Start harvester for this plugin
   132 	iObserver->AddHarvestingQueue(this, iIndexer->GetBaseAppClass());
   146 	iObserver->AddHarvestingQueue(this, iIndexer->GetBaseAppClass());
   133 
   147 
   134 	// Start monitoring when plugin is started
   148 	// Start monitoring when plugin is started
   135 	iChangeNotifier = CContactChangeNotifier::NewL(*iDatabase, this);	
   149 	iChangeNotifier = CContactChangeNotifier::NewL(*iDatabase, this);	
       
   150     
       
   151     if( BaflUtils::FileExists(iFs,iFilePath) )
       
   152         LoadL();
   136 	}
   153 	}
   137 
   154 
   138 // -----------------------------------------------------------------------------
   155 // -----------------------------------------------------------------------------
   139 // CContactsPlugin::StartHarvestingL()
   156 // CContactsPlugin::StartHarvestingL()
   140 // -----------------------------------------------------------------------------
   157 // -----------------------------------------------------------------------------
   638     for (TInt i=0; i<iJobQueue.Count(); i++)
   655     for (TInt i=0; i<iJobQueue.Count(); i++)
   639         {
   656         {
   640             if (iJobQueue[i].iContactId == aEntry.iContactId)
   657             if (iJobQueue[i].iContactId == aEntry.iContactId)
   641             {
   658             {
   642                 // Older version found
   659                 // Older version found
   643                 iJobQueue[i] = aEntry;
   660                 iJobQueue[i].iContactId = aEntry.iContactId;
       
   661                 iJobQueue[i].iActionType = aEntry.iActionType;
   644                 OstTraceFunctionExit0( CCONTACTSPLUGIN_OVERWRITEORADDTOQUEUEL_EXIT );
   662                 OstTraceFunctionExit0( CCONTACTSPLUGIN_OVERWRITEORADDTOQUEUEL_EXIT );
   645                 return;
   663                 return;
   646             }
   664             }
   647         }        
   665         }        
   648     // older not found, append
   666     // older not found, append
   651     }
   669     }
   652 
   670 
   653 void CContactsPlugin::IndexQueuedItems()
   671 void CContactsPlugin::IndexQueuedItems()
   654     {
   672     {
   655     OstTraceFunctionEntry0( CCONTACTSPLUGIN_INDEXQUEUEDITEMS_ENTRY );
   673     OstTraceFunctionEntry0( CCONTACTSPLUGIN_INDEXQUEUEDITEMS_ENTRY );
   656     while (iJobQueue.Count()>0)
   674     while (iJobQueue.Count()>0 && iIndexState )
   657         {
   675         {
   658         TRecord entry = iJobQueue[0];        
   676         TRecord entry = iJobQueue[0];        
   659         //Let the indexer handle this object TRAP it as it can leave
   677         //Let the indexer handle this object TRAP it as it can leave
   660         TRAPD(err,CreateContactIndexItemL( entry.iContactId, entry.iActionType ));        
   678         TRAPD(err,CreateContactIndexItemL( entry.iContactId, entry.iActionType ));        
   661         if(KErrNone == err)
   679         if(KErrNone == err)
   662             {
   680             {
   663             iJobQueue.Remove(0);
   681             iJobQueue.Remove(0);
   664             }
   682             }
   665         }
   683         }
       
   684     
       
   685     if( iJobQueue.Count() == 0 )
       
   686         {
       
   687         //Check for temp file, it exists delete
       
   688         if( BaflUtils::FileExists( iFs, iFilePath ))
       
   689                 BaflUtils::DeleteFile( iFs, iFilePath );
       
   690         }
   666     OstTraceFunctionExit0( CCONTACTSPLUGIN_INDEXQUEUEDITEMS_EXIT );
   691     OstTraceFunctionExit0( CCONTACTSPLUGIN_INDEXQUEUEDITEMS_EXIT );
       
   692     }
       
   693 
       
   694 void CContactsPlugin::LoadL()
       
   695     {
       
   696     // Open the stream
       
   697     RFile file;
       
   698     User::LeaveIfError(file.Open(iFs, iFilePath, EFileRead));
       
   699     CleanupClosePushL(file);
       
   700     RFileReadStream rd(file);
       
   701     rd.PushL();
       
   702     
       
   703     // Read harvester count
       
   704     TInt count = rd.ReadInt32L();
       
   705     // Read the harvesters
       
   706     for (TInt i=0; i<count; i++)
       
   707         {
       
   708         TRecord record;
       
   709         record.iContactId = rd.ReadInt32L();
       
   710         record.iActionType = static_cast<TCPixActionType> ( rd.ReadInt16L());        
       
   711         OverWriteOrAddToQueueL(record);
       
   712         }
       
   713     
       
   714     if( count > 0)
       
   715         IndexQueuedItems();
       
   716     // Cleanup
       
   717     CleanupStack::PopAndDestroy(2, &file);
       
   718     }
       
   719 
       
   720 void CContactsPlugin::SaveL()
       
   721     { 
       
   722     if (iJobQueue.Count() <= 0)
       
   723         return;
       
   724     
       
   725     // Open the stream
       
   726     RFile file;
       
   727     User::LeaveIfError(file.Replace(iFs, iFilePath, EFileWrite));
       
   728     CleanupClosePushL(file);
       
   729     
       
   730     RFileWriteStream wr(file);
       
   731     wr.PushL();
       
   732     
       
   733     // Write harvester count
       
   734     wr.WriteInt32L(iJobQueue.Count());
       
   735     
       
   736     for (TInt i=0; i<iJobQueue.Count(); i++)    
       
   737         {
       
   738         wr.WriteInt32L(iJobQueue[i].iContactId);
       
   739         wr.WriteInt16L(iJobQueue[i].iActionType);        
       
   740         }    
       
   741     // Commit and cleanup
       
   742     wr.CommitL();
       
   743     CleanupStack::PopAndDestroy(2, &file);
   667     }
   744     }
   668 // ---------------------------------------------------------------------------
   745 // ---------------------------------------------------------------------------
   669 // CContactsPlugin::UpdatePerformaceDataL
   746 // CContactsPlugin::UpdatePerformaceDataL
   670 // ---------------------------------------------------------------------------
   747 // ---------------------------------------------------------------------------
   671 //	
   748 //