/*=========================================================================== FUNCTION: DisplayOutput DESCRIPTION This function displays an output string at a given line number on the screen. If the nline parameter is a negative value (-1) the string is displayed in the middle of the screen. If the "nline" value is larger than or equal to zero the "nline" value is multiplied by 15 and the resulting value in pixels is set to the y-coordinate of the start of the string display on the screen. If the string does not fit on one line the string wraps around to the next line (spaced rougly 10-15 pixels apart). By default 5 is used as the starting the x-coordinate of a displayed string. How many characters that fit on one line is calculated for each line that is wrapped around to the next line. Note: depending on the phone screen size and the fonts used for characters the output might differ on different handsets (devices). Where some handsets will have a smaller screen and large default fonts which will cause partial overlapping of lines. This function does not try to address these issues (this is meant as a simple display function). PROTOTYPE: int DisplayOutput(IShell *pIShell, IDisplay *pDisplay, int nline, char *pszStr, AECHAR *pszwStr, boolean isWideChar) PARAMETERS: pIShell: [in]: Contains a pointer to the IShell interface. pIDisplay: [in]: Contains a pointer to the IDisplay interface. nline: [in]: Contains the line number to start displaying the text. The line numbers are by default spaced 15 pixels apart along the y-axis. pszStr: [in]: The character string to be displayed on the screen. DEPENDENCIES None RETURN VALUE Number of lines written to the screen. SIDE EFFECTS None ===========================================================================*/ static int DisplayOutput(IShell *pIShell, IDisplay *pIDisplay, int nline, char *pszStr, AECHAR *pszwStr, boolean isWideChar) { AEEDeviceInfo di; // Device Info AECHAR * szBuf; // a buffer that supports 200 char string AECHAR * psz = NULL; int charHeight = 0; // Stores the char height in pixels for given font int pnAscent = 0; // Stores the ascent in number of pixels int pnDescent = 0; // Stores the descent in number of pixels int pixelWidth; AEEFont font = AEE_FONT_NORMAL; int pnFits = 0, dy; int totalCh = 0; int numLinesPrinted = 0; // Make sure the pointers we'll be using are valid if (pIShell == NULL || pIDisplay == NULL) { return 0; } if ((szBuf = (AECHAR *) MALLOC(TEXT_BUFFER_SIZE)) == NULL) { return 0; } // Get device information ISHELL_GetDeviceInfo(pIShell,&di); // Get the font metrics info charHeight = IDISPLAY_GetFontMetrics (pIDisplay, AEE_FONT_NORMAL, &pnAscent, &pnDescent); if(isWideChar) { WSTRCPY(szBuf,pszwStr); } else { // Convert to wide string (unicode) STR_TO_WSTR ((char *)pszStr, szBuf, TEXT_BUFFER_SIZE); } // If nlines is zero then print this string starting around the middle of // the screen. Or else multiply nlines by charheight to decide the y coordinate of // the start of the string. if (nline < 0) { dy = di.cyScreen*2/5; } else{ dy = nline * charHeight + 5; } // psz keeps track of the point from which to write from the string buffer // in case the string does not fit one line and needs to wrap around in the // next line. psz = szBuf; // Need to calculate the lotal string length to decide if any wrapping // around is needed. if(isWideChar) { totalCh = 2*WSTRLEN (pszwStr); } else { totalCh = STRLEN ((char *)pszStr); } // Keep displaying text string on multiple lines if the string can't be displayed // on one single line. Lines are spaced 15 pixels apart. while ((totalCh > 0) && (*psz != NULL)) { // Get information on how many characters will fit in a line. // Give the pointer to the buffer to be displayed, and the number of // pixels along the x axis you want to display the string in (max number) // pnFits will have the max number of chars that will fit in the maxWidth // number of pixels (given string can't fit in one line), or the number of // chars in the string (if it does fit in one line). pnWidth gives the // number of pixels that will be used to display pnFits number of chars. pixelWidth = IDISPLAY_MeasureTextEx(pIDisplay, font, (AECHAR *) psz, // Start of the buffer to display, -1, di.cxScreen - 5, // maxWidth &pnFits); // Number of chars that will fit a line // If pnFits is zero there is something wrong in the input to above function. // Normally this scenario should not occur. But, have the check anyway. if (pnFits == 0) { FREE(szBuf); return 0; } IDISPLAY_DrawText(pIDisplay, AEE_FONT_NORMAL, psz, pnFits, 5 /*start dx*/, dy, 0 /* use default rectangle coordinates */, 0); psz += pnFits; // move pointer to the next segment to be displayed totalCh -= pnFits; // reduce the total number of characters to still display dy += charHeight; // Place next line charHeight pixels below the // previous line. ++numLinesPrinted; IDISPLAY_Update(pIDisplay); //, TRUE); if (totalCh < pnFits) pnFits = totalCh; // if total number is less than pnFits, adjust pnFits } FREE(szBuf); return numLinesPrinted; } // End of DisplayOutput
/*=========================================================================== 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; }
/*=========================================================================== 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; }
CWERROR db_cont_get_by_id(CW_DB_CONNECTION *db, CW_CONTACT *cont, CW_BOOL *exists, const CW_UINT32 sid, const CW_UINT32 uid) { static const char query[] = "SELECT cid,sid,uid,name,mname,lname,addr,phone,mphone,fax,www,email,company,notes FROM contacts WHERE sid=? AND uid=?"; CW_DB_RESULT res; CW_DB_RESULT_ROW *row; CW_DB_VALUE binds[2] = {{DB_INT64, (CW_INT64)sid}, {DB_INT64, (CW_INT64)uid}}; CWERROR err = CW_ER_OK; *exists = FALSE; if ((err = db_query(db, &res, query, sizeof(query)-1, &binds[0], 2)) != CW_ER_OK) { DEBUG_ERROR(); db_result_free(&res); return err; } if (DB_RESULT_ROW_COUNT(res) == 0) { db_result_free(&res); return CW_ER_OK; } row = DB_RESULT_ROW_FIRST(res); cont->cid = DB_RESULT_AS_INT64(row, 0); cont->sid = (CW_UINT32)DB_RESULT_AS_INT64(row, 1); cont->uid = (CW_UINT32)DB_RESULT_AS_INT64(row, 2); #define WSTRCPY(to, n) \ if (wcscpy_s((to), DB_RESULT_AS_BLOB(row, (n)), sizeof((to))) == NULL) { \ DEBUG_ERROR(); \ db_result_free(&res); \ return CW_ER_INTERNAL; \ } WSTRCPY(cont->name, 3); WSTRCPY(cont->mname, 4); WSTRCPY(cont->lname, 5); WSTRCPY(cont->addr, 6); WSTRCPY(cont->phone, 7); WSTRCPY(cont->mphone, 8); WSTRCPY(cont->fax, 9); WSTRCPY(cont->www, 10); WSTRCPY(cont->email, 11); WSTRCPY(cont->comp, 12); WSTRCPY(cont->notes, 13); #undef WSTRCPY *exists = TRUE; db_result_free(&res); return CW_ER_OK; }
CWERROR db_cont_get_list(CW_DB_CONNECTION *db, CW_CONTACT **clist, CW_UINT32 *count) { static const char query[] = "SELECT cid,sid,uid,name,mname,lname,addr,phone,mphone,fax,www,email,company,notes FROM contacts"; CW_DB_RESULT res; CW_DB_RESULT_ROW *row; CW_CONTACT *list = NULL; CW_UINT32 n, i = 0; CWERROR err = CW_ER_OK; if ((err = db_query(db, &res, query, sizeof(query)-1, NULL, 0)) != CW_ER_OK) { DEBUG_ERROR(); db_result_free(&res); return err; } if ((n = *count = DB_RESULT_ROW_COUNT(res)) == 0) { db_result_free(&res); return CW_ER_OK; } if ((list = *clist = DLL_MALLOC(sizeof(CW_CONTACT) * n)) == NULL) { DEBUG_ERROR(); db_result_free(&res); return CW_ER_MEMORY; } row = DB_RESULT_ROW_FIRST(res); do { list[i].cid = DB_RESULT_AS_INT64(row, 0); list[i].sid = (CW_UINT32)DB_RESULT_AS_INT64(row, 1); list[i].uid = (CW_UINT32)DB_RESULT_AS_INT64(row, 2); #define WSTRCPY(to, n) \ if (wcscpy_s((to), DB_RESULT_AS_BLOB(row, (n)), sizeof((to))) == NULL) { \ DEBUG_ERROR(); \ DLL_FREE(list); \ db_result_free(&res); \ return CW_ER_INTERNAL; \ } WSTRCPY(list[i].name, 3); WSTRCPY(list[i].mname, 4); WSTRCPY(list[i].lname, 5); WSTRCPY(list[i].addr, 6); WSTRCPY(list[i].phone, 7); WSTRCPY(list[i].mphone, 8); WSTRCPY(list[i].fax, 9); WSTRCPY(list[i].www, 10); WSTRCPY(list[i].email, 11); WSTRCPY(list[i].comp, 12); WSTRCPY(list[i].notes, 13); #undef WSTRCPY ++i; } while (((row = DB_RESULT_ROW_NEXT(row)) != NULL) && (--n)); db_result_free(&res); return CW_ER_OK; }
// ================================================================================ // FUNCTION : GetSms // DESCRIPTION : retrive the sms in to array(pSmsAr). Make sure to free the pSmsAr after use. // even GetSms failed there may be resource allocted to pSmsAr and need to free it. // ================================================================================ int CDbHandler::GetSms(sms **pSmsAr, int nTotal, char **pFilterAr, int nNo) { IDatabase *pDatabase=NULL; IDBRecord* pRecord=NULL; uint16 nFieldLen; AEEDBFieldName rFieldName; AEEDBFieldType rFieldType; AECHAR* psStringPtr=NULL; AECHAR* psStringPtr2=NULL; uint16 wTemp=0; int nCount=0; if ( !OpenDatabase(&pDatabase, SM_SMSDB, FALSE)) return ENOMEMORY; IDATABASE_Reset(pDatabase); nTotal = (int) IDATABASE_GetRecordCount(pDatabase); //if sms array is NUll we return the no of records in database. if (NULL==pSmsAr) { IDATABASE_Release(pDatabase); return nTotal; } while ( NULL != (pRecord=IDATABASE_GetNextRecord(pDatabase)) ) { //allocate memory for single sms pSmsAr[nCount] = (sms*)MALLOC(sizeof(sms)); if (NULL==pSmsAr[nCount] ) { IDBRECORD_Release( pRecord ); IDATABASE_Release(pDatabase); return ENOMEMORY; } //set sms state pSmsAr[nCount]->bStatus = FALSE; //set sms record id pSmsAr[nCount]->nSmsId = IDBRECORD_GetID(pRecord); // Get the first field. sms sent/received rFieldType = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen ); if ( (nFieldLen>0) && (SMDB_FT_WORD==rFieldType) ) { IDBRECORD_GetFieldWord(pRecord, &pSmsAr[nCount]->nSent); } // Get the first field. sms contact id. rFieldType = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen ); if ( (nFieldLen>0) && (SMDB_FT_WORD==rFieldType) ) { IDBRECORD_GetFieldWord(pRecord, &pSmsAr[nCount]->nContactId); } // Get next field. sms from field rFieldType = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen ); if ( (nFieldLen>0) && (SMDB_FT_STRING==rFieldType) ) { psStringPtr = IDBRECORD_GetFieldString(pRecord); pSmsAr[nCount]->pszFrom = (AECHAR*)MALLOC(WSTRSIZE(psStringPtr)+2); if (NULL==pSmsAr[nCount]->pszFrom) { IDBRECORD_Release( pRecord ); IDATABASE_Release(pDatabase); return ENOMEMORY; } WSTRCPY(pSmsAr[nCount]->pszFrom, psStringPtr); } // Get next field. sms message field rFieldType = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen ); if ( (nFieldLen>0) && (SMDB_FT_STRING==rFieldType) ) { psStringPtr = IDBRECORD_GetFieldString(pRecord); pSmsAr[nCount]->pszMsg = (AECHAR*)MALLOC(WSTRSIZE(psStringPtr)+2); if (NULL==pSmsAr[nCount]->pszMsg) { IDBRECORD_Release( pRecord ); IDATABASE_Release(pDatabase); return ENOMEMORY; } WSTRCPY(pSmsAr[nCount]->pszMsg, psStringPtr); } // Get next field. sms message field rFieldType = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen ); if ( (nFieldLen>0) && (SMDB_FT_STRING==rFieldType) ) { psStringPtr = IDBRECORD_GetFieldString(pRecord); pSmsAr[nCount]->pszTime = (AECHAR*)MALLOC(WSTRSIZE(psStringPtr)+2); if (NULL==pSmsAr[nCount]->pszTime) { IDBRECORD_Release( pRecord ); IDATABASE_Release(pDatabase); return ENOMEMORY; } WSTRCPY(pSmsAr[nCount]->pszTime, psStringPtr); } // Release the record IDBRECORD_Release( pRecord ); //check the sms with filtered phone numbers //if ( IsSmsMatched(pSmsAr[nCount]->pszFrom, pFilterAr, nNo)) { nCount++; } //else // FREEIF(pSmsAr[nCount]); } nTotal = nCount; IDATABASE_Release(pDatabase); return SUCCESS; }