Example #1
0
/*===========================================================================

FUNCTION: ARB_GetTotalRecNum

DESCRIPTION:
  This function get all record count in address book

PARAMETERS:
  pMe [in] - Pointer to the CAddrBookRuim structure. This structure contains 
    information specific to this applet. 

DEPENDENCIES:
   None

RETURN VALUE:
  records count in address book

SIDE EFFECTS:
   None
===========================================================================*/
uint32 ARB_GetTotalRecNum( CAddrBookRuim * pMe, AEECLSID ContactCLS )
{
    IAddrBook *pb;
    int nCount=0;
    
    if(pMe==NULL||pMe->pIShell==NULL)
    {
        return 0;
    }
    DBGPRINTF("contact cls id=0x%x",ContactCLS);
    if(!ISHELL_CreateInstance(pMe->pIShell, ContactCLS, (void **)&pb))
    {
        nCount = IADDRBOOK_GetNumRecs(pb);    
        IADDRBOOK_Release(pb);
    }

    return nCount;
}
// ================================================================================
// FUNCTION		: GetContactList
// DESCRIPTION	: Get the addressbook contacts 
// ================================================================================
int CDbHandler::GetContactList(AECHAR **pszContactList)
{
	
	//create address book
	IAddrBook * pIAddrBook=NULL;
	if ( SUCCESS != ISHELL_CreateInstance(m_pIShell, AEECLSID_ADDRBOOK, (void **)&pIAddrBook))
	{
		return 0;
	}

	//get the number of records in addressbook and create a buffer to hold the names
	int nSize = IADDRBOOK_GetNumRecs(pIAddrBook);
	*pszContactList = (AECHAR*)MALLOC(nSize*100*sizeof(AECHAR));//assume approximate name length + mobile number is 100
	if ( NULL==*pszContactList ) goto error;

	if( AEE_SUCCESS == IADDRBOOK_EnumRecInit(pIAddrBook,AEE_ADDR_CAT_NONE, AEE_ADDRFIELD_NONE,NULL,0) )
	{
		IAddrRec* rec=NULL;

		while( NULL != (rec=IADDRBOOK_EnumNextRec(pIAddrBook)) )
		{
			AEEAddrField* pField;

			int noOfFilelds = IADDRREC_GetFieldCount(rec);

			for ( int i=0; i<noOfFilelds; i++)
			{
				pField = IADDRREC_GetField(rec, i);
				//append first name and last name to the buffer
				if ( SM_ADDRFIELD_FIRSTNAME==pField->fID )
				{
					WSTRCAT(*pszContactList, (AECHAR*)pField->pBuffer);
					WSTRCAT(*pszContactList, L" ");
				}

				//append the last name to the buffer
				if ( SM_ADDRFIELD_LASTNAME==pField->fID )
				{
					WSTRCAT(*pszContactList, (AECHAR*)pField->pBuffer);
					
				}

				//append the mobile number
				if ( SM_ADDRFIELD_MOBILE==pField->fID )
				{
					WSTRCAT(*pszContactList, L":");
					WSTRCAT(*pszContactList, (AECHAR*)pField->pBuffer);
					
				}
			}

			WSTRCAT(*pszContactList, L";");

			IADDRREC_Release(rec);
		
		}

	}

error:
	IADDRBOOK_Release(pIAddrBook);

	return nSize;
	
}