phonebookengines_old/contactsmodel/cntmatchlog/src/CntMatchLog.cpp
branchRCL_3
changeset 19 5b6f26637ad3
equal deleted inserted replaced
18:d4f567ce2e7c 19:5b6f26637ad3
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "CntMatchLog.h"
       
    17 #include <e32def.h>
       
    18 #include <ecom/implementationproxy.h>
       
    19 
       
    20 CCntMatchLog* CCntMatchLog::NewL()
       
    21 	/** Creates a CCntMatchLog object for accessing the contacts model. 
       
    22 	@capability None */
       
    23 	{
       
    24    	CCntMatchLog* self = new (ELeave) CCntMatchLog;
       
    25    	return self;
       
    26 	}
       
    27 
       
    28 void CCntMatchLog::OpenContactsL()
       
    29 	/** Opens the contacts DB and stores a pointer to the DB in iContactDb.	
       
    30 	@capability ReadUserData WriteUserData*/
       
    31 	{
       
    32 	if( iContactDb)
       
    33 		{
       
    34 		return;
       
    35 		}
       
    36 		
       
    37 	TRAPD(err, iContactDb = CContactDatabase::OpenL());
       
    38 	if(err == KErrNotFound)
       
    39 		{
       
    40 		iContactDb = CContactDatabase::CreateL();
       
    41 		}
       
    42 	else
       
    43 		{
       
    44 		User::LeaveIfError(err);
       
    45 		}
       
    46 	}
       
    47 	
       
    48 void CCntMatchLog::CloseContacts()
       
    49 	/** Closes the contacts DB and deletes the pointer to the DB. 
       
    50 	@capability None */
       
    51 	{
       
    52 	if( iContactDb)
       
    53 		{	
       
    54 		delete iContactDb;
       
    55 		iContactDb = NULL;
       
    56 		}
       
    57 	}
       
    58 	
       
    59 CCntMatchLog::~CCntMatchLog()
       
    60 	/** Closes the contacts DB */
       
    61 	{
       
    62 	this->CloseContacts();
       
    63 	}
       
    64 	
       
    65 TLogContactItemId CCntMatchLog::MatchPhoneNumberL(const TDesC& aNumber, TInt aMatchLengthFromRight)
       
    66 	/** Attempts to find a contact item ID for the contact items which contains
       
    67 	the specified telephone number in a telephone, fax or SMS type field.
       
    68 	If more than one contact item contains the telephone number this should be 
       
    69 	treated the same as no contact found.
       
    70 	
       
    71 	@capability ReadUserData
       
    72 	@param aNumber Phone number string
       
    73 	@param aMatchLengthFromRight Number of digits from the right of the phone number to use
       
    74 	@return The contact Id found that contains the phone number. KLogNullContactId if none or more than one is found. */
       
    75 	{
       
    76 	CContactIdArray* array = NULL;
       
    77 	TLogContactItemId contactId=KLogNullContactId;
       
    78 	
       
    79 	array = iContactDb->MatchPhoneNumberL(aNumber, aMatchLengthFromRight);
       
    80 				
       
    81 	// Only set contactId if we have exactly one match
       
    82 	if (array->Count() == 1)
       
    83 		{
       
    84 		// we have only one match so set the contact id
       
    85 		contactId = static_cast<TLogContactItemId>((*array)[0]);
       
    86 		}
       
    87 	delete array;
       
    88 	return contactId;
       
    89 	}
       
    90 	
       
    91 void CCntMatchLog::ReadContactNameL(TLogContactItemId aContactId, TDes &aName, TLogContactNameFormat aNameFormat)
       
    92 	/** Gets the text data for the family and given name fields of a given contact Id.
       
    93 	
       
    94 	@capability ReadUserData
       
    95 	@param aContactId Contact Id to find data for
       
    96 	@param aName On return contains the family and given name in the desired format if found, a 0 length string otherwise.
       
    97 	@param aNameFormat Desired format of returned string - Chinese or Western format */
       
    98 	{
       
    99 		
       
   100 	// Specify what fields to fetch and concatenate
       
   101 	CContactTextDef* textDef = CContactTextDef::NewLC();
       
   102 	_LIT(KRemotePartyNameSeparator, " ");	
       
   103 	
       
   104 	if(ELogChineseFormat == aNameFormat)
       
   105 		{
       
   106 		textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName, KRemotePartyNameSeparator));
       
   107 		textDef->AppendL(TContactTextDefItem(KUidContactFieldGivenName));
       
   108 		}
       
   109 	else //ELogWesternFormat == iContactNameFormat
       
   110 		{
       
   111 		textDef->AppendL(TContactTextDefItem(KUidContactFieldGivenName, KRemotePartyNameSeparator));
       
   112 		textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName));
       
   113 		}
       
   114 	textDef->SetExactMatchOnly(ETrue);
       
   115 	iContactDb->ReadContactTextDefL(aContactId, aName, textDef);
       
   116 	CleanupStack::PopAndDestroy(textDef);
       
   117 	}
       
   118 	
       
   119 
       
   120 CCntMatchLog::CCntMatchLog()
       
   121 	{
       
   122 	}
       
   123 		
       
   124 const TImplementationProxy ImplementationTable[] = 
       
   125 	{
       
   126 	IMPLEMENTATION_PROXY_ENTRY(0x2000862C, CCntMatchLog::NewL)
       
   127 	};
       
   128 
       
   129 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   130     {
       
   131     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   132     return ImplementationTable;
       
   133     }
       
   134