Ejemplo 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;
}
Ejemplo n.º 2
0
/*===========================================================================

FUNCTION: ABR_AddContactRec

DESCRIPTION:
  This function add a record to address book

PARAMETERS:
  pMe [in] - Pointer to the CAddrBookRuim structure. This structure contains 
    information specific to this applet. 
  pTextName[in]- name field of record
  pTextNum[in]- telephone number field of record

DEPENDENCIES:
   None

RETURN VALUE:
  AEE_SUCCESS -  IADDRBOOK_CreateRec () invocation was  successful
  other - fail


SIDE EFFECTS:
   None
===========================================================================*/
int32 ABR_AddContactRec( CAddrBookRuim *pMe, AEECLSID ContactCLS, AECHAR *pTextName, AECHAR *pTextNum)
{
    AEEAddrField field[2];   //  fields of a record
    int32 nRet = 0;  // return code
    IAddrBook *pAddrBook;

    // check point
    if(pMe==NULL || pMe->pIShell==NULL || pTextName==NULL || pTextNum==NULL)
    {
      return -1;
    }

    // create instance of ADDRESS BOOK for RUIM
    if(!ISHELL_CreateInstance(pMe->pIShell, ContactCLS, (void **)&pAddrBook))
    {
        IAddrRec *pRec;

        //Num
        field[0].fID = (ContactCLS==AEECLSID_ADDRBOOK_RUIM)?
                            AEE_ADDRFIELD_PHONE_GENERIC:AEE_ADDRFIELD_PHONE_WORK;
        field[0].fType = AEEDB_FT_PHONE;
        field[0].pBuffer= pTextNum;
        field[0].wDataLen = (WSTRLEN(pTextNum)+1)*sizeof(AECHAR);

        //Name
        field[1].fID = AEE_ADDRFIELD_NAME;
        field[1].fType = AEEDB_FT_STRING;
        field[1].pBuffer= pTextName;
        field[1].wDataLen = (WSTRLEN(pTextName)+1)*sizeof(AECHAR);

        // create a record with 2 fields
        pRec = IADDRBOOK_CreateRec(pAddrBook, AEE_ADDR_CAT_NONE, (AEEAddrField*)field, 2);

        if(pRec)
        {
            IADDRREC_Release(pRec);
            nRet=0; // success
        }
        else
        {
            nRet=2; // IADDRBOOK_CreateRec fail;
        }

        IADDRBOOK_Release(pAddrBook);
    }
    else
    {
        nRet=1; // error : ISHELL_CreateInstance fail
    }
    DBGPRINTF("Add contact nRet = %d", nRet);
    return nRet;
}
Ejemplo n.º 3
0
// ================================================================================
// FUNCTION		: CopyAddrBookToBackupDb
// DESCRIPTION	: Copy all contacts in addrressbook to backup database.
// ================================================================================
bool CDbHandler::CopyAddrBookToBackupDb()
{
	IDatabase *pBkpDatabase;
	IAddrBook * pIAddrBook=NULL;
	IAddrRec* rec=NULL;
	CContactInfo *pContact;

	//delete previous backup database.
	//this should change to: create a tempory backup database. after successfully creating this.
	//rename current bakup to old backup and temp backup to backup and delete old backup
	if ( !DeleteDatabase( SM_BACKUPDB )) return false;

	pContact = new CContactInfo();
	if ( NULL==pContact ) return false;

	if ( !OpenBackupDb(&pBkpDatabase))
	{
		delete pContact;
		return false;
	}

	//enumerate addressbook
	if ( SUCCESS != ISHELL_CreateInstance(m_pIShell, AEECLSID_ADDRBOOK, (void **)&pIAddrBook))
	{
		delete pContact;
		IDATABASE_Release(pBkpDatabase);
		return false;
	}

	if( AEE_SUCCESS == IADDRBOOK_EnumRecInit(pIAddrBook,AEE_ADDR_CAT_NONE, AEE_ADDRFIELD_NONE,NULL,0) )
	{
		while( NULL != (rec=IADDRBOOK_EnumNextRec(pIAddrBook)) )
		{

			pContact->SetContactInfo(rec);
			//Add contact to backup database
			AddToBackupDb( pBkpDatabase, pContact);

			IADDRREC_Release(rec);
		
		}
	}

	delete pContact;
	//release address book
	IADDRBOOK_Release(pIAddrBook);
	IDATABASE_Release(pBkpDatabase);

	return true;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
/*===========================================================================

FUNCTION: ABR_GetContactRec

DESCRIPTION:
  This function get all record from address book and show every record as a manu item

PARAMETERS:
  pMe [in] - Pointer to the CAddrBookRuim structure. This structure contains 
    information specific to this applet. 
  pMenu[out] - menu show all address book menu  
  pnTotal[out] - all records count of address book

DEPENDENCIES:
   None

RETURN VALUE:
  AEE_SUCCESS -  successfully enumate all record in address book
  other - fail


SIDE EFFECTS:
   None
===========================================================================*/
int32 ABR_GetContactRec( CAddrBookRuim * pMe, AEECLSID ContactCLS, IMenuCtl* pMenu, uint32* pnTotal)
{
    IAddrBook *pb;
    IAddrRec *pR;
    int nRet = 0;
    uint32 nTempTotal;
    boolean bFlgNameGet;
    boolean bFlgNumGet;

    AECHAR *aszNum, *aszName;


    if(pMe==NULL || pMe->pIShell==NULL || pMenu==NULL || pnTotal==NULL)
    {
        return (-1);
    }

    aszNum = (AECHAR *)MALLOC(MAX_CONTACT_NUM_SIZE*sizeof(AECHAR));
    aszName = (AECHAR *)MALLOC(MAX_CONTACT_NAME_SIZE*sizeof(AECHAR));

    
    if(aszNum==NULL ||  aszName==NULL)
    {
        return (-2);
    }

    // Clear any items from the IMenuCtl
    IMENUCTL_Reset( pMenu );
    IMENUCTL_SetRect( pMenu, &pMe->m_rScreenRect );
    IMENUCTL_SetTitle( pMenu, ADDRBOOKRUIM_RES_FILE, IDS_VIEW_MENU, NULL);

    nTempTotal = 0;

    if(!ISHELL_CreateInstance(pMe->pIShell, ContactCLS, (void **)&pb))
    {
        nRet = IADDRBOOK_EnumRecInit(pb,  AEE_ADDR_CAT_NONE, AEE_ADDRFIELD_NONE, NULL, 0);
        if(nRet == AEE_SUCCESS)
        {
            while((pR = IADDRBOOK_EnumNextRec(pb)) != NULL)
            {
                AEEAddrField *ptr = NULL;
                int i;
                int nFields;

                bFlgNameGet = FALSE;
                bFlgNumGet = FALSE;
                MEMSET( aszName, 0, MAX_CONTACT_NAME_SIZE*sizeof(AECHAR));
                MEMSET( aszNum,  0, MAX_CONTACT_NUM_SIZE*sizeof(AECHAR));
                nFields= IADDRREC_GetFieldCount(pR);
                for(i = 0; i < nFields; i++)
                {
                    ptr = IADDRREC_GetField(pR,i);
                    DBGPRINTF("lintao fID   =%d", ptr->fID);
                    // 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(aszName, 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(aszNum, ptr->pBuffer);
                        }
                    }

                }

                if(bFlgNameGet && bFlgNumGet) 
                {
                    nTempTotal++;
                    IMENUCTL_AddItem(pMenu, 
                                     NULL, 
                                     0,  
                                     ABR_REC_LIST_ID + IADDRREC_GetRecID(pR), 
                                     aszName, 
                                     NULL);
                }
            }                  
        }

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

    *pnTotal = nTempTotal;
    IMENUCTL_SetActive( pMenu, TRUE );

    FREEIF(aszNum);
    FREEIF(aszName);
    return nRet;
}
Ejemplo n.º 8
0
// ================================================================================
// 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;
	
}
Ejemplo n.º 9
0
// ================================================================================
// FUNCTION		: CreateChangeDb
// DESCRIPTION	: Create Changes database. This is the database synchronize with server.
// ================================================================================
int CDbHandler::CreateChangeDb()
{	
	IDatabase * pChangeDb = NULL;
	IDatabase * pBackupDb = NULL;

	//if ChangeDb is alreday there. we return SUCCESS.
	//means that last backup is not success and we continue with it.
	if ( OpenChangeDb(&pChangeDb) ) return SM_SUCCESS;

	//Open Backup database
	if ( !OpenBackupDb(&pBackupDb)) return SM_ERROR;
	
	//enumerate Address book to create ChaneDb
	//create address book
	IAddrBook * pIAddrBook=NULL;
	if ( SUCCESS != ISHELL_CreateInstance(m_pIShell, AEECLSID_ADDRBOOK, (void **)&pIAddrBook))
	{
		//release changeDb
		IDATABASE_Release(pChangeDb);
		//release Backup Database
		IDATABASE_Release(pBackupDb);
		return SM_ERROR;
	}

	//Process-1
	//Enumerate through addressbook, copmare it with last time backedup database
	//create ChangeDb. In this process we only do additions and updates to ChangeDb.
	if( AEE_SUCCESS == IADDRBOOK_EnumRecInit(pIAddrBook,AEE_ADDR_CAT_NONE, AEE_ADDRFIELD_NONE,NULL,0) )
	{
		IAddrRec* rec=NULL;
		//enumerate records
		CContactInfo * pAddrBookContact = new CContactInfo();
		CContactInfo * pBackedupContact = new CContactInfo();

		if ( NULL==pAddrBookContact || NULL==pBackedupContact )
		{
			//if only one memory alloc failed.
			if ( NULL!=pAddrBookContact ) delete pAddrBookContact;
			if ( NULL!=pBackedupContact ) delete pBackedupContact;

			//release changeDb
			IDATABASE_Release(pChangeDb);
			//release Backup Database
			IDATABASE_Release(pBackupDb);
			//release address book
			IADDRBOOK_Release(pIAddrBook);
			return SM_NOMEMORY;
		}

		uint16 nRecId = 0;
		DbSearchResult searchStatus;
		while( NULL != (rec=IADDRBOOK_EnumNextRec(pIAddrBook)) )
		{
			//Fetch single contact info from Address book
			//Get current contact from address book
			nRecId = IADDRREC_GetRecID(rec);
			if ( SM_SUCCESS != pAddrBookContact->SetContactInfo(rec) )
			{
				//cleanup and exit
				IADDRREC_Release(rec);
				delete pAddrBookContact;
				delete pBackedupContact;
				//release changeDb
				IDATABASE_Release(pChangeDb);
				//release Backup Database
				IDATABASE_Release(pBackupDb);
				//release address book
				IADDRBOOK_Release(pIAddrBook);

				return SM_ERROR;
			}
	
			//search the corresponding record in backup database.
			searchStatus = SearchContactInBackupDb(pBackupDb, nRecId, pAddrBookContact, pBackedupContact);

			//depending on search status add, update and delete the record to ChangedDb
			if ( !AddToChangesDb(pChangeDb, searchStatus, pAddrBookContact))
			{
				//cleanup and exit
				IADDRREC_Release(rec);
				delete pAddrBookContact;
				delete pBackedupContact;
				//release changeDb
				IDATABASE_Release(pChangeDb);
				//release Backup Database
				IDATABASE_Release(pBackupDb);
				//release address book
				IADDRBOOK_Release(pIAddrBook);

				return SM_ERROR;
			}

			IADDRREC_Release(rec);

		}

		delete pAddrBookContact;
		delete pBackedupContact;
	}
	//End of Process-1

	//Process-2
	//Add deleted records(from last backup) to ChangeDb
	//After this process ChangeDb is completed.
	if ( !SetDeletedRecordsInAddrBook(pBackupDb, pChangeDb))
	{
		//cleanup and exit

	}
	//end process-2

	//release Backup Database
	IDATABASE_Release(pBackupDb);
	//release changeDb
	IDATABASE_Release(pChangeDb);

	//release address book
	IADDRBOOK_Release(pIAddrBook);

	return SM_SUCCESS;
}
Ejemplo n.º 10
0
// ================================================================================
// 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;
}
Ejemplo n.º 11
0
// ================================================================================
// FUNCTION		: SetDeletedRecordsInAddrBook
// DESCRIPTION	: Set deleted records in changes databse according to addressbook.
// ================================================================================
bool CDbHandler::SetDeletedRecordsInAddrBook(IDatabase *pBackupDb, IDatabase *pCghangeDb)
{
	IDBRecord* pRecord=NULL;
	uint16 nFieldLen;
	AEEDBFieldName rFieldName;
	AEEDBFieldType rFieldType;
	uint16 nId;
	uint16 nAddrRecId;
	IAddrBook * pIAddrBook=NULL;
	IAddrRec* rec=NULL;
	bool bStatus = false;


	//create address book
	if ( SUCCESS != ISHELL_CreateInstance(m_pIShell, AEECLSID_ADDRBOOK, (void **)&pIAddrBook))
	{
		return false;
	}

	//enumerate last backed up database and check any deleted records
	IDATABASE_Reset( pBackupDb );
	int n = (int) IDATABASE_GetRecordCount(pBackupDb);


	while (  NULL != (pRecord=IDATABASE_GetNextRecord( pBackupDb )) )
	{
		// Get the first field. DB_BACKUP_RECORD_ID.
		rFieldType = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen );
		if ( (nFieldLen>0) && (SMDB_FT_WORD==rFieldType) )
		{
			IDBRECORD_GetFieldWord(pRecord, &nId);
			
			//check weather the record is present in the addressbook
			if( AEE_SUCCESS == IADDRBOOK_EnumRecInit(pIAddrBook,AEE_ADDR_CAT_NONE, AEE_ADDRFIELD_NONE,NULL,0) )
			{
				while( NULL != (rec=IADDRBOOK_EnumNextRec(pIAddrBook)) )
				{

					nAddrRecId = IADDRREC_GetRecID (rec);
					if ( nId==nAddrRecId ) 
					//if we found the record in addrbook we stop searching
					{
						bStatus = true;
						IADDRREC_Release(rec);
						break;
					}
					IADDRREC_Release(rec);
				}
			}
			else
			{
				// Release the db record
				IDBRECORD_Release( pRecord );
				return false;
			}

		}

		
		// Release the record
		IDBRECORD_Release( pRecord );

		//if record didnt find in address book, add it to ChangeDb as a deleted record.
		if ( !bStatus )
		{
			CContactInfo * pContact = new CContactInfo();
			if ( NULL==pContact ) return false;
			pContact->SetDeletedContact(nId);
			if ( !AddToChangesDb(pCghangeDb, SM_RECORD_DELETE, pContact))
			{
				delete pContact;
				//release address book
				IADDRBOOK_Release(pIAddrBook);
				return false;
			}
			delete pContact;
		}

	}

	//release address book
	IADDRBOOK_Release(pIAddrBook);

	return true;
}