harvesterplugins/contacts/src/ccontactsplugin.cpp
changeset 7 51d10d255e92
parent 5 3bc31ad99ee7
child 9 4a2987baf8f7
child 11 773be20e0a25
equal deleted inserted replaced
5:3bc31ad99ee7 7:51d10d255e92
    37 
    37 
    38 /** Number of contacts to process in one active scheduler cycle */
    38 /** Number of contacts to process in one active scheduler cycle */
    39 const TInt KContactsPerRunL = 1;
    39 const TInt KContactsPerRunL = 1;
    40 
    40 
    41 _LIT(KExcerptDelimiter, " ");
    41 _LIT(KExcerptDelimiter, " ");
    42 
    42 _LIT(KTimeFormat, "%D%N%Y%1 %2 %3"); //Date, Month name and Year format
       
    43  
    43 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    44 // CContactsPlugin::NewL()
    45 // CContactsPlugin::NewL()
    45 // -----------------------------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    46 //
    47 //
    47 CContactsPlugin* CContactsPlugin::NewL()
    48 CContactsPlugin* CContactsPlugin::NewL()
   247 // Adds information field (if available)
   248 // Adds information field (if available)
   248 // If the contact has multiple values for the same Field (e.g. multiple 
   249 // If the contact has multiple values for the same Field (e.g. multiple 
   249 // PhoneNumber values), then the FieldNames of non-first values are appended a 
   250 // PhoneNumber values), then the FieldNames of non-first values are appended a 
   250 // number.
   251 // number.
   251 // ---------------------------------------------------------------------------
   252 // ---------------------------------------------------------------------------
   252 void CContactsPlugin::AddFieldL(CSearchDocument& aDocument, CContactItemFieldSet& aFieldSet, TUid aFieldId, const TDesC& aFieldName)
   253 void CContactsPlugin::AddFieldL(CSearchDocument& aDocument, CContactItemFieldSet& aFieldSet, TUid aFieldId, const TDesC& aFieldName, const TInt aConfig)
   253 	{
   254 	{
   254 	HBufC* fieldName = HBufC::NewLC(aFieldName.Length() + 3); // +3 so can append variable 'i'.
   255 	HBufC* fieldName = HBufC::NewLC(aFieldName.Length() + 3); // +3 so can append variable 'i'.
   255 	TPtr fieldNamePtr = fieldName->Des();
   256 	TPtr fieldNamePtr = fieldName->Des();
   256 
   257 
   257 	// Find field
   258 	// Find field
   262 		if (i>0)
   263 		if (i>0)
   263 			{
   264 			{
   264 			fieldNamePtr.AppendNum(i);
   265 			fieldNamePtr.AppendNum(i);
   265 			}
   266 			}
   266 		CContactItemField& additionalField = aFieldSet[findpos];
   267 		CContactItemField& additionalField = aFieldSet[findpos];
   267 		CContactTextField* fieldText = additionalField.TextStorage();
   268 		if( additionalField.StorageType() == KStorageTypeDateTime)
   268 		if (fieldText && fieldText->Text() != KNullDesC)
   269 		    {
   269 	        aDocument.AddFieldL(fieldNamePtr, fieldText->Text(), CDocumentField::EStoreYes | CDocumentField::EIndexTokenized);
   270             CContactDateField* fieldDate = additionalField.DateTimeStorage();
       
   271             if (fieldDate)
       
   272                 {
       
   273                 TBuf<30> dateString;
       
   274                 fieldDate->Time().FormatL(dateString, KTimeFormat);
       
   275                 aDocument.AddFieldL(fieldNamePtr, dateString, aConfig);
       
   276                 }
       
   277             else
       
   278                 aDocument.AddFieldL(fieldNamePtr, KNullDesC, aConfig);
       
   279 		    }
   270 		else
   280 		else
   271 	        aDocument.AddFieldL(fieldNamePtr, KNullDesC, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized);
   281 		    {
   272 		
   282             CContactTextField* fieldText = additionalField.TextStorage();
   273 		findpos = aFieldSet.FindNext(aFieldId, findpos+1);
   283             if (fieldText && fieldText->Text() != KNullDesC && aFieldId != KUidContactFieldAnniversary)
       
   284                 aDocument.AddFieldL(fieldNamePtr, fieldText->Text(), aConfig);
       
   285             else if (fieldText && aFieldId == KUidContactFieldAnniversary)
       
   286                 {
       
   287                 TBuf<30> dateString;
       
   288                 GetDateL(fieldText->Text(), dateString);
       
   289                 aDocument.AddFieldL(fieldNamePtr, dateString, aConfig);
       
   290                 }
       
   291             else
       
   292                 aDocument.AddFieldL(fieldNamePtr, KNullDesC, aConfig);
       
   293 		    }
       
   294             findpos = aFieldSet.FindNext(aFieldId, findpos+1);
       
   295 
   274 		}
   296 		}
   275 	CleanupStack::PopAndDestroy(fieldName);
   297 	CleanupStack::PopAndDestroy(fieldName);
   276 	}
   298 	}
   277 
   299 
   278 
   300 
   279 // ---------------------------------------------------------------------------
   301 // ---------------------------------------------------------------------------
   280 // CContactsPlugin::AddToExcerptL
   302 // CContactsPlugin::AddToExcerptL
   281 // Adds more text to excerpt
   303 // Adds more text to excerpt
   282 // ---------------------------------------------------------------------------
   304 // ---------------------------------------------------------------------------
   283 void CContactsPlugin::AddToExcerptL(CSearchDocument& /*aDocument*/, CContactItemFieldSet& aFieldSet, TUid aFieldId, const TDesC& /*aFieldName*/ )
   305 void CContactsPlugin::AddToExcerptL(CSearchDocument& /*aDocument*/, CContactItemFieldSet& aFieldSet, TUid aFieldId, const TDesC& /*aFieldName*/)
   284 	{
   306 	{
   285 	// Find field
   307 	// Find field
   286 	TInt findpos = aFieldSet.Find( aFieldId );
   308 	TInt findpos = aFieldSet.Find( aFieldId );
   287 	if (! (findpos < 0) || (findpos >= aFieldSet.Count() ) )
   309 	if (! (findpos < 0) || (findpos >= aFieldSet.Count() ) )
   288 		{
   310 		{
   304 // Helper: Adds the field to the document AND to the exceprt field.
   326 // Helper: Adds the field to the document AND to the exceprt field.
   305 // This function helps avoid calling two functions explicitly for most fields.
   327 // This function helps avoid calling two functions explicitly for most fields.
   306 // This function needs to be a member function as it has to call member functions.
   328 // This function needs to be a member function as it has to call member functions.
   307 // Improvement: AddFieldL need to be a member function - can be refactored.
   329 // Improvement: AddFieldL need to be a member function - can be refactored.
   308 // ---------------------------------------------------------------------------
   330 // ---------------------------------------------------------------------------
   309 void CContactsPlugin::AddFieldToDocumentAndExcerptL(CSearchDocument& aDocument, CContactItemFieldSet& aFieldSet, TUid aFieldId, const TDesC& aFieldName )
   331 void CContactsPlugin::AddFieldToDocumentAndExcerptL(CSearchDocument& aDocument, CContactItemFieldSet& aFieldSet, TUid aFieldId, const TDesC& aFieldName, const TInt aConfig )
   310     {
   332     {
   311     AddFieldL( aDocument, aFieldSet, aFieldId, aFieldName );
   333     AddFieldL( aDocument, aFieldSet, aFieldId, aFieldName, aConfig );
   312     AddToExcerptL( aDocument, aFieldSet, aFieldId, aFieldName );
   334     AddToExcerptL( aDocument, aFieldSet, aFieldId, aFieldName );
   313     }
   335     }
   314 
   336 
   315 // ---------------------------------------------------------------------------
   337 // ---------------------------------------------------------------------------
   316 // CContactsPlugin::CreateMessageIndexItemL
   338 // CContactsPlugin::CreateMessageIndexItemL
   356             //For contacts, all fields __except__ GivenName and FamilyName should be added to excerpt.
   378             //For contacts, all fields __except__ GivenName and FamilyName should be added to excerpt.
   357             //See appclass-hierarchy.txt for details.
   379             //See appclass-hierarchy.txt for details.
   358             /* The order of fields in excerpt is as below. The order in this case
   380             /* The order of fields in excerpt is as below. The order in this case
   359              * is the order of fields shown when you 'Edit' the contact.
   381              * is the order of fields shown when you 'Edit' the contact.
   360              */
   382              */
   361             AddFieldL( *index_item, fieldSet, KUidContactFieldGivenName, KContactsGivenNameField );
   383             AddFieldL( *index_item, fieldSet, KUidContactFieldGivenName, KContactsGivenNameField, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText );
   362             AddFieldL( *index_item, fieldSet, KUidContactFieldFamilyName, KContactsFamilyNameField );
   384             AddFieldL( *index_item, fieldSet, KUidContactFieldFamilyName, KContactsFamilyNameField, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField:: EIndexFreeText );
   363             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldPhoneNumber, KContactsPhoneNumberField );
   385             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldPhoneNumber, KContactsPhoneNumberField );
   364             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldEMail, KContactsEMailField );
   386             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldEMail, KContactsEMailField );
   365             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldSIPID, KContactsSIPIDField );
   387             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldSIPID, KContactsSIPIDField );
   366             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldCompanyName, KContactsCompanyNameField );
   388             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldCompanyName, KContactsCompanyNameField, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText );
   367             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldJobTitle, KContactsJobTitleField );
   389             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldJobTitle, KContactsJobTitleField, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText );
   368             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldNote, KContactsNoteField );
   390             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldNote, KContactsNoteField );
   369 
   391 
   370             /* The following fields are not displayed when 'Edit'-ing the contact.
   392             /* The following fields are not displayed when 'Edit'-ing the contact.
   371              * The order here is arbitrary.
   393              * The order here is arbitrary.
   372              */
   394              */
   373             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldAddress, KContactsAddressField );
   395             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldAddress, KContactsAddressField );
   374             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldSecondName, KContactsSecondNameField ); 
   396             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldSecondName, KContactsSecondNameField, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText );
   375             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldPrefixName, KContactsPrefixField );
   397             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldPrefixName, KContactsPrefixField );
   376             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldSuffixName, KContactsSuffixField );
   398             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldSuffixName, KContactsSuffixField );
   377             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldAdditionalName, KContactsAdditionalNameField );
   399             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldAdditionalName, KContactsAdditionalNameField, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText);
   378             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldUrl, KContactsUrlField );
   400             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldUrl, KContactsUrlField );
   379     
   401     
   380             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldPostOffice, KContactsPostOfficeField );
   402             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldPostOffice, KContactsPostOfficeField );
   381             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldExtendedAddress, KContactsExtendedAddressField );
   403             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldExtendedAddress, KContactsExtendedAddressField );
   382             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldLocality, KContactsLocalityField );
   404             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldLocality, KContactsLocalityField );
   383             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldRegion, KContactsRegionField );
   405             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldRegion, KContactsRegionField );
   384             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldPostcode, KContactsPostcodeField );
   406             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldPostcode, KContactsPostcodeField );
   385             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldCountry, KContactsCountryField );
   407             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldCountry, KContactsCountryField );
   386     
   408     
   387             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldSpouse, KContactsSpouseField );
   409             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldSpouse, KContactsSpouseField, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText);
   388             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldChildren, KContactsChildrenField );
   410             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldChildren, KContactsChildrenField, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText);
   389             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldClass, KContactsClassField );
   411             //AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldClass, KContactsClassField ); //sync field
   390             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldFax, KContactsFaxField );				
   412             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldFax, KContactsFaxField );
   391             
   413             
   392             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldGivenNamePronunciation, KContactsGivenNamePronunciationField );
   414             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldAssistant, KContactAssistant, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText);
   393             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldFamilyNamePronunciation, KContactsFamilyNamePronunciationField );
   415             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldDepartmentName, KContactsDepartmentName, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText);
   394             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldCompanyNamePronunciation, KContactsCompanyNamePronunciationField );
   416             
   395             //left: Birthday; Anniversary (date kind of type), Picture, Logo..
   417             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldIMAddress, KContactIMAddress);
   396 
   418             AddFieldToDocumentAndExcerptL( *index_item, fieldSet, KUidContactFieldServiceProvider, KContactServiceProvider);
       
   419             
       
   420             AddFieldL( *index_item, fieldSet, KUidContactFieldBirthday, KContactBirthday);
       
   421             AddFieldL( *index_item, fieldSet, KUidContactFieldAnniversary, KContactAnniversary);
   397             index_item->AddExcerptL(*iExcerpt);
   422             index_item->AddExcerptL(*iExcerpt);
   398             }
   423             }
   399         
   424         
   400     	index_item->AddFieldL(KMimeTypeField, KMimeTypeContact, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized);
   425     	index_item->AddFieldL(KMimeTypeField, KMimeTypeContact, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized);
   401         
   426         
   448 			}			
   473 			}			
   449 		}
   474 		}
   450     }
   475     }
   451 
   476 
   452 // ---------------------------------------------------------------------------
   477 // ---------------------------------------------------------------------------
       
   478 // CContactsPlugin::GetDateL
       
   479 // ---------------------------------------------------------------------------
       
   480 //
       
   481 void CContactsPlugin::GetDateL(const TDesC& aTime, TDes& aDateString)
       
   482     {
       
   483     TTime time;
       
   484     //sort the date string to the requried format dd/mm/yyyy from returned
       
   485     //format yyyy/mm/dd as parse API is currently not supporting japanese date format
       
   486     if( aTime.Length() >= KDateFieldLength)
       
   487         {
       
   488         aDateString.Copy(aTime.Mid( KDayPosition, KDayLength ));
       
   489         aDateString.Append(KDateSeparator);
       
   490         aDateString.Append(aTime.Mid( KMonthPosition, KDayLength ));
       
   491         aDateString.Append(KDateSeparator);
       
   492         aDateString.Append(aTime.Mid( KYearPosition, KYearLength ));
       
   493         TInt err = time.Parse(aDateString);
       
   494         if ( err >= KErrNone)
       
   495             {
       
   496             time.FormatL(aDateString, KTimeFormat);
       
   497             }
       
   498         }
       
   499     }
       
   500 // ---------------------------------------------------------------------------
   453 // CContactsPlugin::UpdatePerformaceDataL
   501 // CContactsPlugin::UpdatePerformaceDataL
   454 // ---------------------------------------------------------------------------
   502 // ---------------------------------------------------------------------------
   455 //	
   503 //	
   456 #ifdef __PERFORMANCE_DATA
   504 #ifdef __PERFORMANCE_DATA
   457 void CContactsPlugin::UpdatePerformaceDataL()
   505 void CContactsPlugin::UpdatePerformaceDataL()