Exemplo n.º 1
0
/*===========================================================================

FUNCTION: ABR_DeleteContactRec

DESCRIPTION:
  This function delete record whose id is wID

PARAMETERS:
  pMe [in] - Pointer to the CAddrBookRuim structure. This structure contains 
    information specific to this applet. 
  wID[in] - record id which is want to be deleted

DEPENDENCIES:
   None

RETURN VALUE:
  AEE_SUCCESS -  IADDRREC_RemoveRec operate successfully
  other - fail


SIDE EFFECTS:
   None
===========================================================================*/
int32 ABR_DeleteContactRec( CAddrBookRuim *pMe, AEECLSID ContactCLS, uint16 wID)
{
    int nRet = 0;
    IAddrBook *pb;
    IAddrRec *pR;
    
    if ( pMe==NULL || pMe->pIShell==NULL )
    {
        return (-1);
    }

    if(!ISHELL_CreateInstance(pMe->pIShell, ContactCLS, (void **)&pb))
    {
        pR = IADDRBOOK_GetRecByID(pb, wID);
        if(pR)
        {
            nRet = IADDRREC_RemoveRec(pR);
        }
        else
        {
            nRet = 2;  // IADDRBOOK_GetRecByID fail
        }
        IADDRBOOK_Release(pb);
    }
    else
    {
        nRet = 1;
    }

    return nRet;
}
Exemplo n.º 2
0
/*===========================================================================

FUNCTION: ABR_GetContactFieldByItemID

DESCRIPTION:
  This function get all fields of record whose id is wID

PARAMETERS:
  pMe [in] - Pointer to the CAddrBookRuim structure. This structure contains 
    information specific to this applet. 
  wID[in] - record id to be query
  pTextName[out] - name field 
  pTextNum[out] - number field

DEPENDENCIES:
   None

RETURN VALUE:
  AEE_SUCCESS -  IADDRREC_UpdateAllFields operate successfully
  other - fail

SIDE EFFECTS:
   None
===========================================================================*/
int32  ABR_GetContactFieldByItemID(CAddrBookRuim *pMe, AEECLSID ContactCLS, uint16 wID, AECHAR *pTextName, AECHAR *pTextNum)
{
    int nRet = 0;
    IAddrBook *pb;
    IAddrRec *pR;
    boolean bFlgNameGet;
    boolean bFlgNumGet;
    
    if(pMe==NULL || pMe->pIShell==NULL || pTextName==NULL || pTextNum==NULL)
    {
        return (-1);
    }

    if(!ISHELL_CreateInstance(pMe->pIShell, ContactCLS, (void **)&pb))
    {
        pR =IADDRBOOK_GetRecByID(pb, wID);
        if(pR)
        {
            AEEAddrField *ptr = NULL;
            int i;
            int nFields;

            bFlgNameGet = FALSE;
            bFlgNumGet = FALSE;
            nFields= IADDRREC_GetFieldCount(pR);
            for(i = 0; i < nFields; i++)
            {
               ptr = IADDRREC_GetField(pR,i);
               // find name field and save it;
               if (   ptr->fID == AEE_ADDRFIELD_NAME  
                   ||ptr->fID == AEE_ADDRFIELD_FIRSTNAME
                   ||ptr->fID == AEE_ADDRFIELD_LASTNAME
                   ||ptr->fID == AEE_ADDRFIELD_NICKNAME)
               { 
                  if(bFlgNameGet==FALSE)
                   {
                      bFlgNameGet = TRUE;
                      WSTRCPY(pTextName, ptr->pBuffer);
                   }
               }

               // find number field and save it;
               if (    ptr->fID >= AEE_ADDRFIELD_PHONE_WORK  
                  && ptr->fID <= AEE_ADDRFIELD_PHONE_OTHER)
               { 
                  if(bFlgNumGet==FALSE)
                   {
                      bFlgNumGet = TRUE;
                      WSTRCPY(pTextNum, ptr->pBuffer);
                   }
               }

            }

            if(bFlgNameGet && bFlgNumGet) 
            {
                nRet=0;
            }
            else
            {
                nRet=3;
            }
        }
        else
        {
            nRet=2;  // IADDRBOOK_GetRecByID fail
        }

        IADDRBOOK_Release(pb);
    }
    else
    {
        nRet = 1; // fail ISHELL_CreateInstance
    }

    return nRet;
}
Exemplo n.º 3
0
/*===========================================================================

FUNCTION: ABR_UpdateContactRec

DESCRIPTION:
  This function update record whose id is wID

PARAMETERS:
  pMe [in] - Pointer to the CAddrBookRuim structure. This structure contains 
    information specific to this applet. 
  wID[in] - record id which is want to be update
  pTextName[in] - name field which record will change to
  pTextNum[in] - number field which record will change to

DEPENDENCIES:
   None

RETURN VALUE:
  AEE_SUCCESS -  IADDRREC_UpdateAllFields operate successfully
  other - fail


SIDE EFFECTS:
   None
===========================================================================*/
int32 ABR_UpdateContactRec( CAddrBookRuim *pMe, AEECLSID ContactCLS, uint16 wID, AECHAR *pTextName, AECHAR *pTextNum)
{
    int nRet = 0;
    IAddrBook *pb;
    IAddrRec *pR;
    AEEAddrField field;
    boolean bFlgNameGet;
    boolean bFlgNumGet;
    
    if(pMe==NULL || pMe->pIShell==NULL || pTextName==NULL || pTextNum==NULL)
    {
        return (-1);
    }

    if(!ISHELL_CreateInstance(pMe->pIShell, ContactCLS, (void **)&pb))
    {
        pR =IADDRBOOK_GetRecByID(pb, wID);
        if(pR)
        {
                int nFields;
                int i;
                AEEAddrField *ptr = NULL;
                bFlgNameGet = FALSE;
                bFlgNumGet = FALSE;
                nFields= IADDRREC_GetFieldCount(pR);
                for(i = 0; i < nFields; i++)
                {
                    ptr = IADDRREC_GetField(pR,i);
                    DBGPRINTF("lintao fID   =%d", ptr->fID);
                    DBGPRINTF("lintao fType=%d", ptr->fType);

                    // find name field and save it;
                    if (   ptr->fID == AEE_ADDRFIELD_NAME  
                       ||ptr->fID == AEE_ADDRFIELD_FIRSTNAME
                       ||ptr->fID == AEE_ADDRFIELD_LASTNAME
                       ||ptr->fID == AEE_ADDRFIELD_NICKNAME)
                    { 
                        if(bFlgNameGet==FALSE)
                        {
                            bFlgNameGet = TRUE;
                            field.fID = ptr->fID;
                            field.fType = ptr->fType;
                            field.pBuffer = pTextName;
                            field.wDataLen = (WSTRLEN(pTextName)+1)*sizeof(AECHAR);
                            IADDRREC_UpdateField(pR, i, &field);
                        }
                    }

                    // find number field and save it;
                    if (    ptr->fID >= AEE_ADDRFIELD_PHONE_WORK  
                        && ptr->fID <= AEE_ADDRFIELD_PHONE_OTHER)
                    { 
                        if(bFlgNumGet==FALSE)
                        {
                            bFlgNumGet = TRUE;
                            field.fID = ptr->fID;
                            field.fType = ptr->fType;
                            field.pBuffer = pTextNum;
                            field.wDataLen = (WSTRLEN(pTextNum)+1)*sizeof(AECHAR);
                            IADDRREC_UpdateField(pR, i, &field);
                        }
                    }
                }

                // ÐÕÃûºÍºÅÂë¾ùÓÐ
                if(bFlgNameGet && bFlgNumGet) 
                {
                    nRet=0;
                }
                else
                {
                    nRet=4;
                }
        }
        else
        {
            nRet=2;  // IADDRBOOK_GetRecByID fail
        }

        IADDRBOOK_Release(pb);
    }
    else
    {
        nRet = 3;
    }
    DBGPRINTF("nRet=%d", nRet);
    return nRet;
}
// ================================================================================
// FUNCTION		: UpdateAddrBook
// DESCRIPTION	: Update phone addressbook.
// ================================================================================
bool CDbHandler::UpdateAddrBook(CContactInfo *pContactAr, int nSize)
{

	int nState=0;
	IAddrBook *pAddrBook=NULL;
	IAddrRec *pRec=NULL;
	AEEAddrField *field=NULL;
	int nCount=0;
	int nRet=0;
	uint16 wId=0;
	AECHAR* pwsGlobalId=NULL;


	if(SUCCESS!=ISHELL_CreateInstance(m_pIShell, AEECLSID_ADDRBOOK, (void **)&pAddrBook))
		return false;

	for (int i=0; i<nSize; i++)
	{
		nState = pContactAr[i].GetState();

		if ( pContactAr[i].FillAddrFields(&field, nCount))
		{
		
			switch (nState)
			{
			case SM_RECORD_ADD:

										
				pRec = IADDRBOOK_CreateRec(pAddrBook,AEE_ADDR_CAT_NONE, (AEEAddrField*)field, nCount);

				if (NULL==pRec)
				{
					IADDRBOOK_Release(pAddrBook);
					delete [] field;
					return false;
				}
				
				//set contact id of record.
				pContactAr[i].SetContactId( IADDRREC_GetRecID(pRec));

				IADDRREC_Release(pRec);
				pRec=NULL;
							
				break;

			case SM_RECORD_UPDATE:
	
				wId = pContactAr[i].GetContactId();

				pRec = IADDRBOOK_GetRecByID(pAddrBook, wId);

				if ( NULL!=pRec )
				{
					if ( AEE_SUCCESS != IADDRREC_UpdateAllFields(pRec,field,nCount))
					{
						
						IADDRREC_Release(pRec);
						IADDRBOOK_Release(pAddrBook);
						delete [] field;
						return false;
					}

					//set contact id of record.
					//pContactAr[i].SetContactId( IADDRREC_GetRecID(pRec));

					IADDRREC_Release(pRec);
					pRec=NULL;
				}
				
				break;

			case SM_RECORD_DELETE:

				wId = pContactAr[i].GetContactId();
				DBGPRINTF("Deleted rec id= %u", wId);
				pRec = IADDRBOOK_GetRecByID(pAddrBook, wId);
				if ( NULL!=pRec )
				{
					//set contact id of record.
					pContactAr[i].SetContactId( IADDRREC_GetRecID(pRec));

					if(AEE_SUCCESS !=IADDRREC_RemoveRec(pRec))
					{
						IADDRBOOK_Release(pAddrBook);
						delete [] field;
						return false;
					}

					DBGPRINTF("deleted record");
					//no need to relase the address record after deleting it.
				}

				break;

			default:
				break;
			}

			if ( NULL!=field )
			{
				delete [] field;
				field=NULL;
			}
		}
	}

	IADDRBOOK_Release(pAddrBook);

	return true;
}