PhoneBookSearch.c
资源名称:mmi.rar [点击查看]
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:182k
源码类别:
MTK
开发平台:
C/C++
- mdi_audio_stop_string();
- }
- #endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */
- }
- else if (gInsertSimAppFlag != 1
- #ifdef __FLIGHT_MODE_SUPPORT__
- && mmi_bootup_get_active_flight_mode() != 1
- #endif
- )
- {
- SetKeyHandler(mmi_phb_list_pre_choose_number, KEY_SEND, KEY_EVENT_UP);
- }
- return result_count;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_quick_search_get_index
- * DESCRIPTION
- *
- * PARAMETERS
- * nIndex [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_quick_search_get_index(S32 nIndex)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 i, count;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- count = 0;
- for (i = 0; i < PhoneBookEntryCount; i++)
- {
- /* if(g_phb_qsearch[i] == 1) */
- if (g_phb_qsearch_bitmask[i >> BYTE_SIZE_SHIFT_ARITHMETIC] & (1 << (i % BYTE_SIZE)))
- {
- if (count == nIndex)
- {
- break;
- }
- count++;
- }
- }
- g_phb_cntx.active_index = i;
- #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
- StopTimer(PHB_LIST_SPEAK_NAME_TIMER);
- if (g_phb_is_speaking_name)
- {
- mdi_audio_stop_string();
- }
- if (g_phb_cntx.speak_name)
- {
- StartTimer(PHB_LIST_SPEAK_NAME_TIMER, UI_POPUP_NOTIFYDURATION_TIME, mmi_phb_list_speak_name);
- }
- #endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_quick_search_list_pre_entry
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_quick_search_list_pre_entry(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef __SYNCML_SUPPORT__
- if (mmi_syncml_is_phb_sync_now())
- {
- mmi_phb_entry_not_ready(STR_ID_SYNC_PLEASE_WAIT);
- }
- else
- #endif /* __SYNCML_SUPPORT__ */
- if (g_phb_cntx.phb_ready && !g_phb_cntx.processing)
- {
- if (PhoneBookEntryCount)
- {
- mmi_phb_entry_quick_search_list();
- }
- else
- {
- DisplayPopup(
- (PU8) GetString(STR_NO_ENTRIES_MESSAGE),
- IMG_GLOBAL_EMPTY,
- TRUE,
- PHB_NOTIFY_TIMEOUT,
- EMPTY_LIST_TONE);
- }
- }
- else
- {
- mmi_phb_entry_not_ready(STR_PROCESSING_PHONEBOOK);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_entry_quick_search_list
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_entry_quick_search_list(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 *guiBuffer;
- U16 entryCount;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- EntryNewScreen(
- SCR_ID_PHB_QUICK_SEARCH_LIST,
- mmi_phb_exit_quick_search_list,
- mmi_phb_quick_search_list_pre_entry,
- NULL);
- guiBuffer = GetCurrGuiBuffer(SCR_ID_PHB_QUICK_SEARCH_LIST);
- RegisterHighlightHandler(mmi_phb_quick_search_get_index);
- RegisterCat200SearchFunction(mmi_phb_quick_search_find_entry);
- /* First Time enter or any entry has been modified.. */
- if ((guiBuffer == NULL) || (g_phb_cntx.refresh_list == MMI_PHB_ENTRY_REFRESH))
- {
- g_phb_cntx.highlight_entry = 0;
- memset(g_phb_qsearch_input, 0, ENCODING_LENGTH);
- // memset(g_phb_qsearch,1,MAX_PB_ENTRIES); /*All records are in the subset at the beginning*/
- memset(g_phb_qsearch_bitmask, 0xff, (MAX_PB_ENTRIES + 7) / 8);
- entryCount = PhoneBookEntryCount;
- guiBuffer = NULL;
- g_phb_cntx.refresh_list = MMI_PHB_ENTRY_QSEARCH; /* '2' is used only for this screen. */
- }
- else
- {
- entryCount = (U16) mmi_phb_quick_search_find_entry(g_phb_qsearch_input);
- }
- #ifdef __MMI_UI_HINTS_IN_MENUITEM__
- set_force_icon_on_highlight_only_in_menuitem();
- #endif
- ShowCategory200Screen(
- STR_SCR_PBOOK_VIEW_CAPTION,
- IMG_SCR_PBOOK_CAPTION,
- STR_GLOBAL_OPTIONS,
- IMG_GLOBAL_OPTIONS,
- STR_GLOBAL_BACK,
- IMG_GLOBAL_BACK,
- entryCount,
- mmi_phb_quick_search_list_get_item,
- mmi_phb_quick_search_list_get_hint,
- g_phb_cntx.highlight_entry,
- IMG_ID_PHB_QUICK_SEARCH_FIND,
- (U8*) g_phb_qsearch_input,
- MMI_PHB_QUICK_SEARCH_INPUT_LENGTH,
- guiBuffer);
- SetCategory200RightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
- #if defined(__MMI_MULTITAP_FOR_STAR_AND_POUND__)
- SetCategory200LeftSoftkeyFunction(mmi_phb_entry_quick_search_option, KEY_EVENT_UP);
- SetLeftSoftkeyFunction(mmi_phb_entry_quick_search_option, KEY_EVENT_UP);
- #else /* defined(__MMI_MULTITAP_FOR_STAR_AND_POUND__) */
- SetCategory200LeftSoftkeyFunction(mmi_phb_entry_op_option, KEY_EVENT_UP);
- SetLeftSoftkeyFunction(mmi_phb_entry_op_option, KEY_EVENT_UP);
- #endif /* defined(__MMI_MULTITAP_FOR_STAR_AND_POUND__) */
- if (gInsertSimAppFlag != 1 && entryCount > 0
- #ifdef __FLIGHT_MODE_SUPPORT__
- && mmi_bootup_get_active_flight_mode() != 1
- #endif
- )
- {
- SetKeyHandler(mmi_phb_list_pre_choose_number, KEY_SEND, KEY_EVENT_UP);
- }
- //MTK Elvis 20040517--it is incorrect to regist RSK here
- //SetRightSoftkeyFunction(GoBackHistory,KEY_EVENT_UP);
- /* Make cache according to the current input method, after input method initialized in ShowCategoryScreen. */
- if (guiBuffer == NULL)
- {
- g_phb_qsearch_is_cache = 0;
- mmi_phb_quick_search_make_cache();
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_exit_quick_search_list
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_exit_quick_search_list(void)
- {
- #if defined(__MMI_PHB_RSK_QUICK_SEARCH__)
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_idle_context.ToNameScrFromIdleApp)
- {
- g_phb_cntx.start_scr_id = SCR_ID_PHB_QUICK_SEARCH_LIST;
- }
- g_phb_cntx.end_scr_id = SCR_ID_PHB_QUICK_SEARCH_LIST;
- g_idle_context.ToNameScrFromIdleApp = 0;
- g_idle_context.RskPressedFromIdleApp = 0;
- StopTimer(KEYPAD_LOCK_TIMER);
- #if defined(__MMI_VRSD_DIAL__)
- StopTimer(VRSD_DIAL_PLAYBACK_TIMER);
- #endif
- #endif /* defined(__MMI_PHB_RSK_QUICK_SEARCH__) */
- #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
- StopTimer(PHB_LIST_SPEAK_NAME_TIMER);
- if (g_phb_is_speaking_name)
- {
- mdi_audio_stop_string();
- }
- #endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_quick_search_list_get_item
- * DESCRIPTION
- *
- * PARAMETERS
- * item_index [IN]
- * str_buff [IN]
- * img_buff_p [?]
- * str_img_mask [IN]
- * RETURNS
- *
- *****************************************************************************/
- pBOOL mmi_phb_quick_search_list_get_item(S32 item_index, UI_string_type str_buff, PU8 *img_buff_p, U8 str_img_mask)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 i, count, store_index;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- count = 0;
- for (i = 0; i < PhoneBookEntryCount; i++)
- {
- /* if(g_phb_qsearch[i] == 1) */
- if (g_phb_qsearch_bitmask[i >> BYTE_SIZE_SHIFT_ARITHMETIC] & (1 << (i % BYTE_SIZE)))
- {
- if (count == item_index)
- {
- break;
- }
- count++;
- }
- }
- store_index = g_phb_name_index[i];
- if (pfnUnicodeStrlen((S8*) PhoneBook[store_index].alpha_id.name))
- {
- pfnUnicodeStrcpy((S8*) str_buff, (S8*) PhoneBook[store_index].alpha_id.name);
- }
- else
- {
- mmi_phb_convert_get_ucs2_number((S8*) str_buff, store_index);
- }
- if (store_index >= MAX_PB_PHONE_ENTRIES) /* In SIM */
- {
- *img_buff_p = get_image(IMG_STORAGE_SIM);
- }
- else
- {
- *img_buff_p = get_image(IMG_STORAGE_HANDSET);
- }
- return TRUE;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_quick_search_list_get_hint
- * DESCRIPTION
- *
- * PARAMETERS
- * item_index [IN]
- * hint_array [?]
- * RETURNS
- *
- *****************************************************************************/
- S32 mmi_phb_quick_search_list_get_hint(S32 item_index, UI_string_type *hint_array)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 i, count, store_index;
- S8 temp_number[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- count = 0;
- for (i = 0; i < PhoneBookEntryCount; i++)
- {
- /* if(g_phb_qsearch[i] == 1) */
- if (g_phb_qsearch_bitmask[i >> BYTE_SIZE_SHIFT_ARITHMETIC] & (1 << (i % BYTE_SIZE)))
- {
- if (count == item_index)
- {
- break;
- }
- count++;
- }
- }
- store_index = g_phb_name_index[i];
- mmi_phb_convert_get_ucs2_number((S8*) temp_number, store_index);
- if (pfnUnicodeStrlen((S8*) PhoneBook[store_index].alpha_id.name) && pfnUnicodeStrlen((S8*) temp_number))
- {
- pfnUnicodeStrcpy((S8*) hint_array[0], (S8*) temp_number);
- }
- else
- {
- return 0;
- }
- return 1; /* One hint data only, can be more hints. */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_quick_search_change_input_mode
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_quick_search_change_input_mode(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- // memset(g_phb_qsearch,1,MAX_PB_ENTRIES); /*All records are in the subset at the beginning*/
- memset(g_phb_qsearch_bitmask, 0xff, (MAX_PB_ENTRIES + 7) / 8);
- g_phb_qsearch_is_cache = 0;
- /*
- * Make cache according to the current input method.
- * Start a timer to avoid convert cache each time when user change input method quickly.
- */
- StopTimer(PHB_QUICK_SEARCH_TIMER);
- StartTimer(PHB_QUICK_SEARCH_TIMER, 500, mmi_phb_quick_search_make_cache);
- }
- #if defined(__MMI_MULTITAP_FOR_STAR_AND_POUND__)
- extern void EntryQuickSearchInputMethodScreen(void);
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_quick_search_go_back_editor
- * DESCRIPTION
- * Go back screen after change input method.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_quick_search_go_back_editor(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- GoBackToHistory(SCR_ID_PHB_QUICK_SEARCH_LIST);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_highlight_quick_search_input_method
- * DESCRIPTION
- * Highlight function to enter change input method
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_highlight_quick_search_input_method(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- SetLeftSoftkeyFunction(EntryQuickSearchInputMethodScreen, KEY_EVENT_UP);
- SetKeyHandler(EntryQuickSearchInputMethodScreen, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
- RegisterInputMethodScreenCloseFunction(mmi_phb_quick_search_go_back_editor);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_highlight_quick_search_op_option
- * DESCRIPTION
- * Highlight function to enter entry option.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_highlight_quick_search_op_option(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- SetLeftSoftkeyFunction(mmi_phb_entry_op_option, KEY_EVENT_UP);
- SetKeyHandler(mmi_phb_entry_op_option, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_entry_quick_search_option
- * DESCRIPTION
- * Entry function of phonebook quick search option.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_entry_quick_search_option(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 *guiBuffer;
- U16 nStrItemList[10]; /* Need Expand when has more options. */
- U16 nNumofItem;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- EntryNewScreen(
- SCR_ID_PHB_QUICK_SEARCH_OPTION,
- mmi_phb_exit_quick_search_option,
- mmi_phb_entry_quick_search_option,
- NULL);
- guiBuffer = GetCurrGuiBuffer(SCR_ID_PHB_QUICK_SEARCH_OPTION);
- nNumofItem = GetNumOfChild(MENU_ID_PHB_QUICK_SEARCH_OPTION);
- GetSequenceStringIds(MENU_ID_PHB_QUICK_SEARCH_OPTION, nStrItemList);
- SetParentHandler(MENU_ID_PHB_QUICK_SEARCH_OPTION);
- RegisterHighlightHandler(ExecuteCurrHiliteHandler);
- ShowCategory15Screen(
- STR_GLOBAL_OPTIONS,
- IMG_SCR_PBOOK_CAPTION,
- STR_GLOBAL_OK,
- IMG_GLOBAL_OK,
- STR_GLOBAL_BACK,
- IMG_GLOBAL_BACK,
- nNumofItem,
- nStrItemList,
- (U16*) gIndexIconsImageList,
- LIST_MENU,
- 0,
- guiBuffer);
- SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
- SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_exit_quick_search_option
- * DESCRIPTION
- * Exit function of phonebook quick search option
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_exit_quick_search_option(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_phb_cntx.end_scr_id = SCR_ID_PHB_QUICK_SEARCH_OPTION;
- }
- #endif /* defined(__MMI_MULTITAP_FOR_STAR_AND_POUND__) */
- #endif /* defined(__MMI_PHB_QUICK_SEARCH__) */
- #define MMI_PHB_UTIL_SEARCH
- /*---------------------------------------------------- General Compare String Functions -------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_compare_chars
- * PARAMETERS
- * char1 [IN]
- * char2 [IN]
- * RETURNS
- *
- *****************************************************************************/
- S32 mmi_phb_compare_chars(U16 char1, U16 char2)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* try UCS2 matching */
- if (char1 == char2)
- {
- return 0;
- }
- /* if not, try ASCII case-insensitive matching */
- else if ((char1 < 0x007E) && (char2 < 0x007E))
- {
- if ((char1 <= 0x007b) && (char1 >= 0x0061))
- {
- char1 -= 0x20;
- }
- if ((char2 <= 0x007b) && (char2 >= 0x0061))
- {
- char2 -= 0x20;
- }
- return char1 - char2;
- }
- /* no match */
- return char1 - char2;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_compare_ucs2_strings
- * PARAMETERS
- * string1 [?]
- * string2 [?]
- * same_count [?]
- * distance [?]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_compare_ucs2_strings(S8 *string1, S8 *string2, U8 *same_count, S32 *distance)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 len1, len2;
- U8 max_len, min_len;
- U8 i;
- U16 code1, code2;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- *same_count = 0;
- *distance = 0;
- len1 = (U8) pfnUnicodeStrlen(string1);
- len2 = (U8) pfnUnicodeStrlen(string2);
- if (len1 > len2)
- {
- max_len = len1;
- min_len = len2;
- }
- else
- {
- max_len = len2;
- min_len = len1;
- }
- for (i = 0; i < max_len && i < MAX_PB_EMAIL_LENGTH; i++) /* Use Max Phonebook Strlen as upper bound */
- /* for (i = 0; i < max_len; i++) */
- {
- /* If all characters are identical from 0 to min_len. */
- if (i >= min_len)
- {
- /* First is greater than second */
- if (len1 > len2)
- {
- *distance = (U16) string1[i * ENCODING_LENGTH];
- }
- /* First and second is congruence */
- else if (len1 == len2)
- {
- *distance = 0;
- }
- /* len1 < len2: First is less than second */
- else
- {
- *distance = -(U16) string2[i * ENCODING_LENGTH];
- }
- //if (min_len == 0)
- // *distance = - *distance;
- break;
- }
- /* First, compare from 0 to min_len */
- else
- {
- memcpy(&code1, (string1 + i * ENCODING_LENGTH), 2);
- memcpy(&code2, (string2 + i * ENCODING_LENGTH), 2);
- if ((*distance = mmi_phb_compare_chars(code1, code2)) == 0)
- {
- *same_count = *same_count + 1;
- }
- /* First and second is not equal, return distance */
- else
- {
- break;
- }
- }
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_compare_ascii_strings
- * PARAMETERS
- * string1 [?] > string2 ; <0 if sting1 < string2
- * string2 [?]
- * same_count [?]
- * distance [?]
- *****************************************************************************/
- void mmi_phb_compare_ascii_strings(S8 *string1, S8 *string2, U16 *same_count, S32 *distance)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 len1, len2;
- U16 max_len, min_len;
- U16 i;
- U16 code1, code2;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- *same_count = 0;
- *distance = 0;
- len1 = strlen(string1);
- len2 = strlen(string2);
- if (len1 > len2)
- {
- max_len = len1;
- min_len = len2;
- }
- else
- {
- max_len = len2;
- min_len = len1;
- }
- for (i = 0; i < max_len; i++)
- {
- if (i >= min_len) /* If all characters are identical from 0 to min_len. */
- {
- if (len1 > len2) /* First is greater than second */
- {
- *distance = (U16) string1[i];
- }
- else if (len1 == len2) /* First and second is congruence */
- {
- *distance = 0;
- }
- else /* len1 < len2: First is less than second */
- {
- *distance = -(U16) string2[i];
- }
- if (min_len == 0)
- {
- *distance = -*distance;
- }
- break;
- }
- else /* First, compare from 0 to min_len */
- {
- code1 = (U16) string1[i];
- code2 = (U16) string2[i];
- if ((*distance = mmi_phb_compare_chars(code1, code2)) == 0)
- {
- *same_count = *same_count + 1;
- }
- else /* First and second is not equal, return distance */
- {
- break;
- }
- }
- }
- }
- #if defined(__MMI_PHB_PINYIN_SORT__)
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_util_make_pinyin_cache
- * DESCRIPTION
- *
- * PARAMETERS
- * store_index [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_util_make_pinyin_cache(U16 store_index)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 count;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if ((PhoneBook[store_index].alpha_id.name_length != 0) &&
- (PhoneBook[store_index].alpha_id.name_dcs != MMI_PHB_ASCII))
- {
- count = mmi_phb_util_convert_to_pinyin(
- PhoneBook[store_index].alpha_id.name,
- &g_phb_name_pinyin_index[store_index][0],
- MMI_PHB_SORT_LENGTH * ENCODING_LENGTH);
- g_phb_name_pinyin_index[store_index][count++] = 0x00;
- g_phb_name_pinyin_index[store_index][count++] = 0x00;
- }
- else
- {
- memset(&g_phb_name_pinyin_index[store_index][0], 0, 2);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_util_get_pinyin_cache
- * DESCRIPTION
- *
- * PARAMETERS
- * store_index [IN]
- * pinyin_ptr [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_util_get_pinyin_cache(U16 store_index, U8 **pinyin_ptr)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- *pinyin_ptr = &g_phb_name_pinyin_index[store_index][0];
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_util_convert_to_pinyin
- * DESCRIPTION
- * This function convert the input string into Chinese Pinyin string according to the library
- * Between each pinyin string result, it will append the original encoding to seperate two
- * Chinese pinyin result.
- * PARAMETERS
- * inputString [?] The input string buffer in ucs2 format.
- * outputString [?] The output string buffer, it will be ucs2 format
- * out_length [IN] The output string buffer size, in bytes.
- * RETURNS
- * void
- *****************************************************************************/
- #if defined(__MMI_T9__)
- #if defined(__MMI_T9_V7__)
- U16 mmi_phb_util_convert_to_pinyin(U8 *inputString, U8 *outputString, U16 out_length)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- T9STATUS t9ReturnCodes;
- U8 i, out = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- T9ChangeLanguageToSMChinesePinYin();
- while (!((*inputString == 0) && (*(inputString + 1) == 0)) && ((out + 1) < out_length))
- {
- t9ReturnCodes = T9CCGetCharSpell(&FieldInfo.CCFieldInfo, (U16*) inputString, 0);
- if (t9ReturnCodes == 0) /* (code >= 0x4e00) && (code <= 0x9fa5) */
- {
- i = 0;
- while ((FieldInfo.CCFieldInfo.pbSpellBuf[i] != 0x00) && ((out + 1) < out_length))
- {
- outputString[out++] = FieldInfo.CCFieldInfo.pbSpellBuf[i++];
- outputString[out++] = 0x00;
- }
- }
- /* Add character encoding beetween pinyin strings */
- if ((out + 1) < out_length)
- {
- outputString[out++] = inputString[0];
- outputString[out++] = inputString[1];
- }
- inputString += 2;
- }
- return out;
- }
- #else /* defined(__MMI_T9_V7__) */
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_util_convert_to_pinyin
- * DESCRIPTION
- *
- * PARAMETERS
- * inputString [?]
- * outputString [?]
- * out_length [IN]
- * RETURNS
- *
- *****************************************************************************/
- U16 mmi_phb_util_convert_to_pinyin(U8 *inputString, U8 *outputString, U16 out_length)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- T9Event t9EventInput;
- T9STATUS t9ReturnCodes;
- U8 i, out = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- T9ChangeLanguageToSMChinesePinYin();
- while (!((*inputString == 0) && (*(inputString + 1) == 0)) && ((out + 1) < out_length))
- {
- t9EventInput.mType = T9EVTSPELLING;
- t9EventInput.data.sLDBData.psBuf = (U16*) inputString;
- t9EventInput.data.sLDBData.mCtrlID = 0;
- t9ReturnCodes = T9HandleEvent(&FieldInfo, &t9EventInput);
- if (t9ReturnCodes == 0) /* (code >= 0x4e00) && (code <= 0x9fa5) */
- {
- i = 0;
- while ((FieldInfo.uLangData.pAuxChinese->pbSpellBuf[i] != 0x00) && ((out + 1) < out_length))
- {
- outputString[out++] = FieldInfo.uLangData.pAuxChinese->pbSpellBuf[i++];
- outputString[out++] = 0x00;
- }
- }
- /* Add character encoding beetween pinyin strings */
- if ((out + 1) < out_length)
- {
- outputString[out++] = inputString[0];
- outputString[out++] = inputString[1];
- }
- inputString += 2;
- }
- return out;
- }
- #endif /* defined(__MMI_T9_V7__) */
- #elif defined(__MMI_ZI__)
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_util_convert_to_pinyin
- * DESCRIPTION
- *
- * PARAMETERS
- * inputString [?]
- * outputString [?]
- * out_length [IN]
- * RETURNS
- *
- *****************************************************************************/
- U16 mmi_phb_util_convert_to_pinyin(U8 *inputString, U8 *outputString, U16 out_length)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 i, out = 0;
- U16 code;
- U16 pCharInfoBuffer[MMI_PHB_CONVERT_BUFF_ZI];
- U16 PinYin_Base = ZI8_BASE_PINYIN - 0x0061;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while (!((*inputString == 0) && (*(inputString + 1) == 0)) && ((out + 1) < out_length))
- {
- memcpy(&code, inputString, 2);
- if ((code >= 0x4e00) && (code <= 0x9fa5) &&
- Zi8GetCharInfo(code, (U16*) pCharInfoBuffer, MMI_PHB_CONVERT_BUFF_ZI, ZI8_GETMODE_PINYIN))
- {
- i = 0;
- while ((pCharInfoBuffer[i] != 0x0000) && (out < out_length) && ((pCharInfoBuffer[i] < 0xf431) || (pCharInfoBuffer[i] > 0xf435))) /* No tone needed */
- {
- outputString[out++] = (U8) (pCharInfoBuffer[i++] - PinYin_Base);
- outputString[out++] = 0x00;
- }
- }
- /* Add character encoding beetween pinyin strings */
- if ((out + 1) < out_length)
- {
- outputString[out++] = inputString[0];
- outputString[out++] = inputString[1];
- }
- inputString += 2;
- }
- return out;
- }
- //KP Jerry add on 2007-3-8 start
- #elif defined(__MMI_CSTAR__)
- U16 mmi_phb_util_convert_to_pinyin(U8* inputString, U8* outputString, U16 out_length)
- {
- U16 out;
- int i;
- U16 code;
- U16 buf[16];
- out = 0;
- while ( !((inputString[0] == 0) && (inputString[1] == 0)) && (out + 1 < out_length) )
- {
- memcpy(&code, inputString, 2);
- if (CstarQueryCharInfo(code, buf, 16, INPUT_MODE_MMI_MULTITAP_PINYIN) > 0)
- {
- i = 0;
- while ( (buf[i] != 0) && (out < out_length) )
- {
- outputString[out++] = (U8)(buf[i++]);
- outputString[out++] = 0x00;
- }
- }
- if (out + 1 < out_length)
- {
- outputString[out++] = inputString[0];
- outputString[out++] = inputString[1];
- }
- inputString += 2;
- }
- return out;
- }
- //KP Jerry add on 2007-3-8 end
- #elif defined(__MMI_ITAP__)
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- #else
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_util_convert_to_pinyin
- * DESCRIPTION
- *
- * PARAMETERS
- * inputString [?]
- * outputString [?]
- * out_length [IN]
- * RETURNS
- *
- *****************************************************************************/
- U16 mmi_phb_util_convert_to_pinyin(U8 *inputString, U8 *outputString, U16 out_length)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- pfnUnicodeStrncpy((S8*) outputString, (S8*) inputString, out_length);
- return out_length;
- }
- #endif
- #endif /* defined(__MMI_PHB_PINYIN_SORT__) */
- #define MMI_PHB_LOOKUP_TABLE
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_lookup_table_sort
- * DESCRIPTION
- * Sorts the look-up table
- *
- * This is a fast Quick-Sort as suggested by
- * Pluto. It will perform insertion sort for
- * array chunks of size less than 4 and quick
- * sort for size greater than 4.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_lookup_table_sort(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_phb_cntx.lookup_table_count)
- {
- /* Set to zero beore sorting, check if this flag larger than phonebook entries to see if finish sorting. */
- g_phb_cntx.populate_count = 0;
- /* Begin to sort. */
- mmi_phb_lookup_table_quicksort(0, (U16) (g_phb_cntx.lookup_table_count - 1));
- mmi_phb_lookup_table_insertionsort(0, (U16) (g_phb_cntx.lookup_table_count - 1));
- /* After sorting, set it to total phonebook entries. */
- g_phb_cntx.populate_count = 0xffff;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_lookup_table_quicksort
- * DESCRIPTION
- * Sorts the lookup table using quick sort algorithm
- * PARAMETERS
- * l [IN]
- * r [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_lookup_table_quicksort(U16 l, U16 r)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 i, j;
- U32 pivot;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if ((r - l) > 4)
- {
- i = (r + l) / 2;
- if (LookUpTable[l].number > LookUpTable[i].number)
- {
- mmi_phb_lookup_table_swap_node(l, i);
- }
- if (LookUpTable[l].number > LookUpTable[r].number)
- {
- mmi_phb_lookup_table_swap_node(l, r);
- }
- if (LookUpTable[i].number > LookUpTable[r].number)
- {
- mmi_phb_lookup_table_swap_node(i, r);
- }
- j = r - 1;
- mmi_phb_lookup_table_swap_node(i, j);
- i = l;
- pivot = LookUpTable[j].number;
- for (;;)
- {
- do
- {
- } while (LookUpTable[++i].number < pivot);
- do
- {
- } while (LookUpTable[--j].number > pivot);
- if (j < i)
- {
- break;
- }
- mmi_phb_lookup_table_swap_node(i, j);
- }
- mmi_phb_lookup_table_swap_node(i, (U16) (r - 1));
- mmi_phb_lookup_table_quicksort(l, j);
- mmi_phb_lookup_table_quicksort((U16) (i + 1), r);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_lookup_table_insertionsort
- * DESCRIPTION
- * Sorts the lookup table using insertion sort algorithm
- * PARAMETERS
- * lo [IN]
- * hi [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_lookup_table_insertionsort(U16 lo, U16 hi)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 i, j;
- MMI_PHB_LOOKUP_NODE_STRUCT elem;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (i = lo + 1; i <= hi; ++i)
- {
- memcpy(&elem, &LookUpTable[i], sizeof(MMI_PHB_LOOKUP_NODE_STRUCT));
- j = i;
- while (j > lo)
- {
- if (LookUpTable[j - 1].number <= elem.number)
- {
- break;
- }
- memcpy(&LookUpTable[j], &LookUpTable[j - 1], sizeof(MMI_PHB_LOOKUP_NODE_STRUCT));
- j--;
- }
- memcpy(&LookUpTable[j], &elem, sizeof(MMI_PHB_LOOKUP_NODE_STRUCT));
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_lookup_table_swap_node
- * DESCRIPTION
- * Swaps the look-up table nodes
- * PARAMETERS
- * i [IN]
- * j [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_lookup_table_swap_node(U16 i, U16 j)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- MMI_PHB_LOOKUP_NODE_STRUCT temp;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- memcpy(&temp, &LookUpTable[i], sizeof(MMI_PHB_LOOKUP_NODE_STRUCT));
- memcpy(&LookUpTable[i], &LookUpTable[j], sizeof(MMI_PHB_LOOKUP_NODE_STRUCT));
- memcpy(&LookUpTable[j], &temp, sizeof(MMI_PHB_LOOKUP_NODE_STRUCT));
- }
- /* Advance Search Phone Numbe. For Mobile Field Only!!! */
- #if defined(__MMI_PHB_ADV_NUM_MATCH_MOBILE__)
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_number_has_extension
- * DESCRIPTION
- * Find out if a phone number has extension field.
- * PARAMETERS
- * number [?]
- * RETURNS
- * The position of the first extension character.
- * Ex. *31#+81234567890p123 => 16
- *****************************************************************************/
- U16 mmi_phb_number_has_extension(S8 *number)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 temp;
- U16 pos = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Ignore *31# and #31# */
- while (((number[0] == '*') && (number[1] == '3') && (number[2] == '1') && (number[3] == '#')) ||
- ((number[0] == '#') && (number[1] == '3') && (number[2] == '1') && (number[3] == '#')))
- {
- number += 4;
- pos += 4;
- }
- /* Ignore '+' */
- if (number[0] == '+')
- {
- number++;
- pos++;
- }
- /* Find position of first extension character */
- temp = strcspn((PS8) number, "+pw*#");
- if (temp)
- {
- number = number + temp;
- pos = pos + temp;
- }
- /* Check if extension character exists. */
- if (number[0] == '+' || number[0] == 'p' || number[0] == 'w' || number[0] == '*' || number[0] == '#')
- {
- return pos;
- }
- else
- {
- return 0;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_number_compare_extension
- * DESCRIPTION
- *
- * PARAMETERS
- * number1 [?]
- * number2 [?]
- * RETURNS
- *
- *****************************************************************************/
- BOOL mmi_phb_number_compare_extension(S8 *number1, S8 *number2)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 temp;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Ignore *31# and #31# when compare. */
- while (((number1[0] == '*') && (number1[1] == '3') && (number1[2] == '1') && (number1[3] == '#')) ||
- ((number1[0] == '#') && (number1[1] == '3') && (number1[2] == '1') && (number1[3] == '#')))
- {
- number1 += 4;
- }
- while (((number2[0] == '*') && (number2[1] == '3') && (number2[2] == '1') && (number2[3] == '#')) ||
- ((number2[0] == '#') && (number2[1] == '3') && (number2[2] == '1') && (number2[3] == '#')))
- {
- number2 += 4;
- }
- /* Ignore '+' when compare. */
- if (number1[0] == '+')
- {
- number1++;
- }
- if (number2[0] == '+')
- {
- number2++;
- }
- /* Only Compare Extension part. */
- temp = strcspn((PS8) number1, "+pw*#");
- if (temp)
- {
- number1 = number1 + temp;
- }
- temp = strcspn((PS8) number2, "+pw*#");
- if (temp)
- {
- number2 = number2 + temp;
- }
- /* Compare if the number is full match. */
- if (!strcmp((PS8) number1, (PS8) number2))
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_number_compare_before_extension
- * DESCRIPTION
- * Compare number before extension part
- * If two numbers are less than 9 digts, do not need to
- * do extra handling
- * PARAMETERS
- * number1 [?]
- * number2 [?]
- * RETURNS
- *
- *****************************************************************************/
- BOOL mmi_phb_number_compare_before_extension(S8 *number1, S8 *number2)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 i;
- U16 len1, len2;
- U16 ext_pos1, ext_pos2;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Ignore *31# and #31# */
- while (((number2[0] == '*') && (number2[1] == '3') && (number2[2] == '1') && (number2[3] == '#')) ||
- ((number2[0] == '#') && (number2[1] == '3') && (number2[2] == '1') && (number2[3] == '#')) )
- {
- number2 += 4;
- }
- /* compare length shorter than 9
- if(g_phb_compare_length <= 9)
- return TRUE;
- although already compared when enter this function, still need to confirm the number type
- and need to do more comparation */
- ext_pos1 = mmi_phb_number_has_extension(number1);
- ext_pos2 = mmi_phb_number_has_extension(number2);
- if ((ext_pos1 == 0 && ext_pos2 != 0 && (number2[ext_pos2] == '#' || number2[ext_pos2] == '*'))
- || (ext_pos2 == 0 && ext_pos1 != 0 && (number2[ext_pos1] == '#' || number2[ext_pos1] == '*')))
- { /* only one with extension '#' or '*'. Not match! */
- return FALSE;
- }
- len1 = (ext_pos1 == 0) ? strlen(number1) : ext_pos1;
- len2 = (ext_pos2 == 0) ? strlen(number2) : ext_pos2;
- if ((len1 < g_phb_compare_length) || (len2 < g_phb_compare_length))
- {
- U16 num_len1 = (number1[0] == '+') ? (len1 - 1) : len1;
- U16 num_len2 = (number2[0] == '+') ? (len2 - 1) : len2;
- if (num_len1 != num_len2)
- {
- return FALSE;
- }
- else /* the same length except "+" sign */
- {
- for (i = 1; i <= len1 && i <= len2; i++)
- {
- if (number1[len1 - i] != number2[len2 - i])
- {
- return FALSE;
- }
- }
- }
- return TRUE;
- }
- /* (len1 >= g_phb_compare_length) && (len2 >= g_phb_compare_length) */
- for (i = 1; i <= g_phb_compare_length; i++)
- {
- if (number1[len1 - i] != number2[len2 - i])
- {
- return FALSE;
- }
- }
- return TRUE;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_number_check_full_match_with_extension
- * DESCRIPTION
- *
- * PARAMETERS
- * lookup_index [IN]
- * number_in [?]
- * RETURNS
- *
- *****************************************************************************/
- BOOL mmi_phb_number_check_full_match_with_extension(U16 lookup_index, S8 *number_in)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 number_buff[MAX_PB_NUMBER_LENGTH + 1 + 1];
- U16 store_index = LookUpTable[lookup_index].store_index;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Check if mobile field is match */
- if (PhoneBook[store_index].tel.type == MMI_CSMCC_INTERNATIONAL_ADDR)
- {
- number_buff[0] = '+';
- mmi_phb_convert_to_digit((U8*) (number_buff + 1), PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
- }
- else
- {
- mmi_phb_convert_to_digit(number_buff, PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
- }
- if (!mmi_phb_number_has_extension((S8*) number_buff) &&
- mmi_phb_number_compare_before_extension(number_in, (S8*) number_buff))
- {
- return TRUE;
- }
- #ifdef __MMI_PHB_USIM_FIELD__
- /* Check number in the anr field */
- if (store_index >= MAX_PB_PHONE_ENTRIES)
- {
- if (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_ANRA)
- {
- if (phb_anr[store_index - MAX_PB_PHONE_ENTRIES][0].type == MMI_CSMCC_INTERNATIONAL_ADDR)
- {
- number_buff[0] = '+';
- mmi_phb_convert_to_digit(
- (U8*) (number_buff + 1),
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][0].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- else
- {
- mmi_phb_convert_to_digit(
- (U8*) number_buff,
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][0].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- if (!mmi_phb_number_has_extension((S8*) number_buff) &&
- mmi_phb_number_compare_before_extension(number_in, (S8*) number_buff))
- {
- return TRUE;
- }
- }
- if (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_ANRB)
- {
- if (phb_anr[store_index - MAX_PB_PHONE_ENTRIES][1].type == MMI_CSMCC_INTERNATIONAL_ADDR)
- {
- number_buff[0] = '+';
- mmi_phb_convert_to_digit(
- (U8*) (number_buff + 1),
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][1].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- else
- {
- mmi_phb_convert_to_digit(
- (U8*) number_buff,
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][1].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- if (!mmi_phb_number_has_extension((S8*) number_buff) &&
- mmi_phb_number_compare_before_extension(number_in, (S8*) number_buff))
- {
- return TRUE;
- }
- }
- if (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_ANRC)
- {
- if (phb_anr[store_index - MAX_PB_PHONE_ENTRIES][2].type == MMI_CSMCC_INTERNATIONAL_ADDR)
- {
- number_buff[0] = '+';
- mmi_phb_convert_to_digit(
- (U8*) (number_buff + 1),
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][2].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- else
- {
- mmi_phb_convert_to_digit(
- (U8*) number_buff,
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][2].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- if (!mmi_phb_number_has_extension((S8*) number_buff) &&
- mmi_phb_number_compare_before_extension(number_in, (S8*) number_buff))
- {
- return TRUE;
- }
- }
- }
- #endif /* __MMI_PHB_USIM_FIELD__ */
- #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
- /* Check number in the optional field */
- if ((store_index < MAX_PB_PHONE_ENTRIES) &&
- ((PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_HOME) ||
- (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_OFFICE) ||
- (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_FAX)))
- {
- S16 pError;
- ReadRecord(
- NVRAM_EF_PHB_FIELDS_LID,
- (U16) (store_index + 1),
- (void*)&PhoneBookOptionalFields,
- OPTIONAL_FIELDS_RECORD_SIZE,
- &pError);
- if (PhoneBook[store_index].field | MMI_PHB_ENTRY_FIELD_HOME)
- {
- if (!mmi_phb_number_has_extension((S8*) PhoneBookOptionalFields.homeNumber) &&
- mmi_phb_number_compare_before_extension(number_in, (S8*) PhoneBookOptionalFields.homeNumber))
- {
- g_phb_cntx.searched_number_type = MMI_PHB_ENTRY_FIELD_HOME;
- return TRUE;
- }
- }
- if (PhoneBook[store_index].field | MMI_PHB_ENTRY_FIELD_OFFICE)
- {
- if (!mmi_phb_number_has_extension((S8*) PhoneBookOptionalFields.officeNumber) &&
- mmi_phb_number_compare_before_extension(number_in, (S8*) PhoneBookOptionalFields.officeNumber))
- {
- g_phb_cntx.searched_number_type = MMI_PHB_ENTRY_FIELD_OFFICE;
- return TRUE;
- }
- }
- if (PhoneBook[store_index].field | MMI_PHB_ENTRY_FIELD_FAX)
- {
- if (!mmi_phb_number_has_extension((S8*) PhoneBookOptionalFields.faxNumber) &&
- mmi_phb_number_compare_before_extension(number_in, (S8*) PhoneBookOptionalFields.faxNumber))
- {
- g_phb_cntx.searched_number_type = MMI_PHB_ENTRY_FIELD_FAX;
- return TRUE;
- }
- }
- }
- #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */
- return FALSE;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_number_find_first_without_extension
- * DESCRIPTION
- *
- * PARAMETERS
- * mid [IN]
- * number [IN]
- * number_in [?]
- * RETURNS
- *
- *****************************************************************************/
- S16 mmi_phb_number_find_first_without_extension(S16 mid, U32 number, S8 *number_in)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 i, new_mid, min_index;
- S16 counter = 0;
- U16 j;
- BOOL is_match = FALSE;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- new_mid = mid;
- min_index = MAX_PB_ENTRIES;
- /* Compare number before mid */
- i = mid;
- while ((i >= 0) && (LookUpTable[i].number == number))
- {
- if (mmi_phb_number_check_full_match_with_extension(i, number_in))
- {
- for (j = 0; j < PhoneBookEntryCount; j++)
- if (g_phb_name_index[j] == LookUpTable[i].store_index)
- {
- is_match = TRUE;
- break;
- }
- if (j < min_index)
- {
- min_index = j;
- new_mid = i;
- }
- }
- i--;
- counter++;
- if (counter >= MAX_PHB_NUMBER_COMP)
- {
- break;
- }
- }
- /* Compare number after mid */
- i = mid + 1;
- while ((i < g_phb_cntx.lookup_table_count) && (LookUpTable[i].number == number))
- {
- if (mmi_phb_number_check_full_match_with_extension(i, number_in))
- {
- for (j = 0; j < PhoneBookEntryCount; j++)
- if (g_phb_name_index[j] == LookUpTable[i].store_index)
- {
- is_match = TRUE;
- break;
- }
- if (j < min_index)
- {
- min_index = j;
- new_mid = i;
- }
- }
- i++;
- counter++;
- if (counter >= MAX_PHB_NUMBER_COMP)
- {
- break;
- }
- }
- if (is_match)
- {
- return new_mid; /* Always return, even only number with extension exists. */
- }
- else
- {
- return -1;
- }
- /*
- * if(counter <= 1) //Only one entry match.
- * return new_mid;
- * else if(min_index < MAX_PB_ENTRIES)
- * return new_mid;
- * else
- * return -1;
- */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_number_check_full_match_without_extension
- * DESCRIPTION
- *
- * PARAMETERS
- * lookup_index [IN]
- * number_list [?]
- * number_in [?]
- * RETURNS
- *
- *****************************************************************************/
- BOOL mmi_phb_number_check_full_match_without_extension(U16 lookup_index, S8 *number_list, S8 *number_in)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 store_index = LookUpTable[lookup_index].store_index;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Check if mobile field is match */
- if (PhoneBook[store_index].tel.type == MMI_CSMCC_INTERNATIONAL_ADDR)
- {
- number_list[0] = '+';
- mmi_phb_convert_to_digit((U8*) (number_list + 1), PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
- }
- else
- {
- mmi_phb_convert_to_digit((U8*) number_list, PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
- }
- if (mmi_phb_number_compare_before_extension(number_in, (S8*) number_list) &&
- mmi_phb_number_compare_extension(number_in, (S8*) number_list))
- {
- return TRUE;
- }
- #ifdef __MMI_PHB_USIM_FIELD__
- /* Check number in the anr field */
- if (store_index >= MAX_PB_PHONE_ENTRIES)
- {
- if (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_ANRA)
- {
- if (phb_anr[store_index - MAX_PB_PHONE_ENTRIES][0].type == MMI_CSMCC_INTERNATIONAL_ADDR)
- {
- number_list[0] = '+';
- mmi_phb_convert_to_digit(
- (U8*) (number_list + 1),
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][0].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- else
- {
- mmi_phb_convert_to_digit(
- (U8*) number_list,
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][0].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- if (mmi_phb_number_compare_before_extension(number_in, (S8*) number_list) &&
- mmi_phb_number_compare_extension(number_in, (S8*) number_list))
- {
- return TRUE;
- }
- }
- if (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_ANRB)
- {
- if (phb_anr[store_index - MAX_PB_PHONE_ENTRIES][1].type == MMI_CSMCC_INTERNATIONAL_ADDR)
- {
- number_list[0] = '+';
- mmi_phb_convert_to_digit(
- (U8*) (number_list + 1),
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][1].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- else
- {
- mmi_phb_convert_to_digit(
- (U8*) number_list,
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][1].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- if (mmi_phb_number_compare_before_extension(number_in, (S8*) number_list) &&
- mmi_phb_number_compare_extension(number_in, (S8*) number_list))
- {
- return TRUE;
- }
- }
- if (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_ANRC)
- {
- if (phb_anr[store_index - MAX_PB_PHONE_ENTRIES][2].type == MMI_CSMCC_INTERNATIONAL_ADDR)
- {
- number_list[0] = '+';
- mmi_phb_convert_to_digit(
- (U8*) (number_list + 1),
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][2].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- else
- {
- mmi_phb_convert_to_digit(
- (U8*) number_list,
- phb_anr[store_index - MAX_PB_PHONE_ENTRIES][2].number,
- MAX_PB_NUMBER_LENGTH + 1);
- }
- if (mmi_phb_number_compare_before_extension(number_in, (S8*) number_list) &&
- mmi_phb_number_compare_extension(number_in, (S8*) number_list))
- {
- return TRUE;
- }
- }
- }
- #endif /* __MMI_PHB_USIM_FIELD__ */
- #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
- /* Check number in the optional field */
- if ((store_index < MAX_PB_PHONE_ENTRIES) &&
- ((PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_HOME) ||
- (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_OFFICE) ||
- (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_FAX)))
- {
- S16 pError;
- ReadRecord(
- NVRAM_EF_PHB_FIELDS_LID,
- (U16) (store_index + 1),
- (void*)&PhoneBookOptionalFields,
- OPTIONAL_FIELDS_RECORD_SIZE,
- &pError);
- if (PhoneBook[store_index].field | MMI_PHB_ENTRY_FIELD_HOME)
- {
- if (mmi_phb_number_compare_before_extension(number_in, (S8*) PhoneBookOptionalFields.homeNumber) &&
- mmi_phb_number_compare_extension(number_in, (S8*) PhoneBookOptionalFields.homeNumber))
- {
- g_phb_cntx.searched_number_type = MMI_PHB_ENTRY_FIELD_HOME;
- return TRUE;
- }
- }
- if (PhoneBook[store_index].field | MMI_PHB_ENTRY_FIELD_OFFICE)
- {
- if (mmi_phb_number_compare_before_extension(number_in, (S8*) PhoneBookOptionalFields.officeNumber) &&
- mmi_phb_number_compare_extension(number_in, (S8*) PhoneBookOptionalFields.officeNumber))
- {
- g_phb_cntx.searched_number_type = MMI_PHB_ENTRY_FIELD_OFFICE;
- return TRUE;
- }
- }
- if (PhoneBook[store_index].field | MMI_PHB_ENTRY_FIELD_FAX)
- {
- if (mmi_phb_number_compare_before_extension(number_in, (S8*) PhoneBookOptionalFields.faxNumber) &&
- mmi_phb_number_compare_extension(number_in, (S8*) PhoneBookOptionalFields.faxNumber))
- {
- g_phb_cntx.searched_number_type = MMI_PHB_ENTRY_FIELD_FAX;
- return TRUE;
- }
- }
- }
- #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */
- return FALSE;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_number_find_first_with_extension
- * DESCRIPTION
- *
- * PARAMETERS
- * mid [IN]
- * number [IN]
- * number_in [?]
- * RETURNS
- *
- *****************************************************************************/
- S16 mmi_phb_number_find_first_with_extension(S16 mid, U32 number, S8 *number_in)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 i, new_mid, min_index, counter;
- U8 number_list[MAX_PB_NUMBER_LENGTH + 1 + 1];
- U16 j;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- new_mid = mid;
- min_index = MAX_PB_ENTRIES;
- counter = 0;
- /* Compare number before mid */
- i = mid;
- while ((i >= 0) && (LookUpTable[i].number == number))
- {
- if (mmi_phb_number_check_full_match_without_extension(i, (S8*) number_list, number_in))
- {
- for (j = 0; j < PhoneBookEntryCount; j++)
- if (g_phb_name_index[j] == LookUpTable[i].store_index)
- {
- break;
- }
- if (j < min_index)
- {
- min_index = j;
- new_mid = i;
- }
- }
- i--;
- counter++;
- if (counter >= MAX_PHB_NUMBER_COMP)
- {
- break;
- }
- }
- /* Compare number after mid */
- i = mid + 1;
- while ((i < g_phb_cntx.lookup_table_count) && (LookUpTable[i].number == number))
- {
- if (mmi_phb_number_check_full_match_without_extension(i, (S8*) number_list, number_in))
- {
- for (j = 0; j < PhoneBookEntryCount; j++)
- if (g_phb_name_index[j] == LookUpTable[i].store_index)
- {
- break;
- }
- if (j < min_index)
- {
- min_index = j;
- new_mid = i;
- }
- }
- i++;
- counter++;
- if (counter >= MAX_PHB_NUMBER_COMP)
- {
- break;
- }
- }
- if (min_index == MAX_PB_ENTRIES)
- {
- U16 ext1 = 0;
- mmi_phb_convert_to_digit(
- number_list,
- PhoneBook[LookUpTable[new_mid].store_index].tel.number,
- MAX_PB_NUMBER_LENGTH + 1);
- if ((counter <= 1) && !mmi_phb_number_has_extension((S8*) number_list) &&
- ((ext1 = mmi_phb_number_has_extension(number_in)) > 0) &&
- (number_in[ext1] != '#') && (number_in[ext1] != '*'))
- {
- return mid;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return new_mid;
- }
- }
- #endif /* defined(__MMI_PHB_ADV_NUM_MATCH_MOBILE__) */
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_lookup_table_search
- * DESCRIPTION
- * Search for the number in the lookup table
- * and returns the index of the matched entry.
- *
- * Its a non-recursive binary search
- * PARAMETERS
- * number [IN]
- * low [IN]
- * high [IN]
- * number_ASCII [IN]
- * storage [IN]
- * RETURNS
- * void
- *****************************************************************************/
- U16 mmi_phb_lookup_table_search(U32 number, S16 low, S16 high, S8 *number_ASCII, U8 storage)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 mid;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while (low <= high)
- {
- mid = (low + high) / 2;
- if (number == LookUpTable[mid].number)
- {
- /*
- * Advanced Compare - Compare number longer than 9 digit,
- * with extension, find out the prior one if numbers are the same, and etc.
- */
- #if defined(__MMI_PHB_ADV_NUM_MATCH_MOBILE__)
- if (!mmi_phb_number_has_extension(number_ASCII))
- {
- mid = mmi_phb_number_find_first_without_extension(mid, number, number_ASCII);
- }
- else
- {
- mid = mmi_phb_number_find_first_with_extension(mid, number, number_ASCII);
- }
- if (mid < 0)
- {
- return 0xffff; /* an invalid number */
- }
- else
- #endif /* defined(__MMI_PHB_ADV_NUM_MATCH_MOBILE__) */
- {
- if (storage == MMI_STORAGE_BOTH ||
- (storage == MMI_SIM && LookUpTable[mid].store_index >= MAX_PB_PHONE_ENTRIES) ||
- (storage == MMI_NVRAM && LookUpTable[mid].store_index < MAX_PB_PHONE_ENTRIES))
- {
- return LookUpTable[mid].store_index; /* return storage location in array, begin from 0 */
- }
- mid++;
- while ((mid < (g_phb_cntx.lookup_table_count - 1)) && number == LookUpTable[mid].number)
- {
- if (storage == MMI_STORAGE_BOTH ||
- (storage == MMI_SIM && LookUpTable[mid].store_index >= MAX_PB_PHONE_ENTRIES) ||
- (storage == MMI_NVRAM && LookUpTable[mid].store_index < MAX_PB_PHONE_ENTRIES))
- {
- return LookUpTable[mid].store_index; /* return storage location in array, begin from 0 */
- }
- mid++;
- }
- }
- }
- else if (number < LookUpTable[mid].number)
- {
- high = mid - 1;
- }
- else
- {
- low = mid + 1;
- }
- }
- return 0xffff;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_util_read_compare_length
- * DESCRIPTION
- * Read the compare length from NVRAM
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_util_read_compare_length(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 pError;
- U8 comp_len;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Already read value */
- if (g_phb_compare_length != 0xff)
- {
- return;
- }
- ReadRecord(NVRAM_EF_PHB_COMPARE_DIGIT_LID, 1, (void*)&comp_len, 1, &pError);
- if (comp_len < 6)
- {
- g_phb_compare_length = 6;
- }
- else if (comp_len > 20)
- {
- g_phb_compare_length = 20;
- }
- else
- {
- g_phb_compare_length = comp_len;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_util_convert_number_to_int
- * DESCRIPTION
- * Converts the last n characters of a phone number to digits
- * PARAMETERS
- * ascii_number [IN] Input ascii number
- * RETURNS
- * interger of input number
- *****************************************************************************/
- U32 mmi_phb_util_convert_number_to_int(U8 *ascii_number)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 num_len;
- U16 ext_len;
- U16 buff_len = MAX_PB_NUMBER_LENGTH + 1;
- U8 *number;
- U8 temp_number[MAX_PB_NUMBER_LENGTH + 1 + 1];
- U8 compare_length = 9; /* Maximum convert number length is 9 digits. (4 bytes integer) */
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- PRINT_INFORMATION(("---[PhonebookSearch.c] mmi_phb_util_convert_number_to_int() => number: [%s] n", ascii_number));
- if (ascii_number != NULL)
- {
- strncpy((S8*) temp_number, (S8*) ascii_number, buff_len);
- memset((temp_number + buff_len), 0x00, 1); /* Makre sure there will be terminator */
- }
- else
- {
- return INVALID_NUMBER;
- }
- number = (U8*) temp_number;
- /* Ignore *31# and #31# case */
- while (((number[0] == '*') && (number[1] == '3') && (number[2] == '1') && (number[3] == '#')) ||
- ((number[0] == '#') && (number[1] == '3') && (number[2] == '1') && (number[3] == '#')))
- {
- number += 4;
- }
- /* Skip the first plus sign */
- if (number[0] == '+')
- {
- number++;
- }
- /* number empty */
- if (number[0] == ' ')
- {
- return INVALID_NUMBER;
- }
- /* Find the position of extension number and remove that part */
- ext_len = strcspn((PS8) number, "+pw*#");
- if (!ext_len)
- {
- return INVALID_NUMBER;
- }
- else
- {
- MMI_ASSERT(ext_len <= buff_len);
- number[ext_len] = ' ';
- /* Read compare length from NVRAM */
- mmi_phb_util_read_compare_length();
- num_len = strlen((PS8) number);
- /* May compare less number than 9 digits */
- if (g_phb_compare_length < 9)
- {
- compare_length = g_phb_compare_length;
- }
- /* Convert at most 9 digits integer */
- if (num_len > compare_length)
- {
- number += num_len - compare_length;
- }
- /* return a 32 bits integer by atol() */
- return atol((PS8) number);
- }
- }
- /*-----------------------------------------------END General Compare String Functions -------------------------------------------------*/
- #define MMI_PHB_SEARCH_EMAIL
- #if defined(__MMI_PHB_EMAIL_SORT__)
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_sort_email_insert_index
- * DESCRIPTION
- * This function inserts email to mapping table by its index.
- * PARAMETERS
- * store_index [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_sort_email_insert_index(U16 store_index)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 pos;
- U16 i;
- S16 pError;
- #ifdef __MMI_PHB_USIM_FIELD__
- U16 g_phb_email_index[MAX_PB_ENTRIES];
- #else
- U16 g_phb_email_index[MAX_PB_PHONE_ENTRIES];
- #endif
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef __MMI_PHB_USIM_FIELD__
- ReadRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_ENTRIES * sizeof(U16), &pError);
- if (PhoneBookEntryCount == 1)
- {
- g_phb_email_index[(PhoneBookEntryCount - 1)] = store_index;
- }
- else
- {
- pos = mmi_phb_sort_email_find_insert_pos(0, (PhoneBookEntryCount - 2), store_index, g_phb_email_index);
- for (i = (PhoneBookEntryCount - 1); i > pos; i--)
- {
- g_phb_email_index[i] = g_phb_email_index[i - 1];
- }
- g_phb_email_index[pos] = store_index;
- }
- WriteRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_ENTRIES * sizeof(U16), &pError);
- #else /* __MMI_PHB_USIM_FIELD__ */
- ReadRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_PHONE_ENTRIES * sizeof(U16), &pError);
- if (g_phb_cntx.phone_used == 1)
- {
- g_phb_email_index[(g_phb_cntx.phone_used - 1)] = store_index;
- }
- else
- {
- pos = mmi_phb_sort_email_find_insert_pos(0, (g_phb_cntx.phone_used - 2), store_index, g_phb_email_index);
- for (i = (g_phb_cntx.phone_used - 1); i > pos; i--)
- {
- g_phb_email_index[i] = g_phb_email_index[i - 1];
- }
- g_phb_email_index[pos] = store_index;
- }
- WriteRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_PHONE_ENTRIES * sizeof(U16), &pError);
- #endif /* __MMI_PHB_USIM_FIELD__ */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_sort_email_find_insert_pos
- * DESCRIPTION
- * This function find the insert position for a new adding email.
- * PARAMETERS
- * low [IN]
- * high [IN]
- * store_index [IN]
- * mapping_table [?]
- * RETURNS
- * void
- *****************************************************************************/
- U16 mmi_phb_sort_email_find_insert_pos(S32 low, S32 high, U16 store_index, U16 *mapping_table)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 mid;
- S16 flag;
- U8 same_count;
- S32 distance;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while (low <= high)
- {
- mid = (low + high) / 2;
- mmi_phb_sort_email_compare_by_encoding(store_index, mapping_table[mid], &same_count, &distance);
- if (distance > 0)
- {
- low = mid + 1;
- flag = -1;
- }
- else /* Either > 0 or < 0, not possible ==0 */
- {
- high = mid - 1;
- flag = 1;
- }
- }
- if (flag == -1)
- {
- return (U16) (mid + 1);
- }
- else
- {
- return (U16) mid;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_sort_email_compare_by_encoding
- * DESCRIPTION
- * This function compare email precedence by encoding.
- * If no email presents, use name instead.
- * PARAMETERS
- * first [IN]
- * second [IN]
- * same_count [?]
- * distance [?]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_sort_email_compare_by_encoding(U16 first, U16 second, U8 *same_count, S32 *distance)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S8 *string1, *string2;
- S8 email1[(MAX_PB_EMAIL_LENGTH + 1) * ENCODING_LENGTH];
- S8 email2[(MAX_PB_EMAIL_LENGTH + 1) * ENCODING_LENGTH];
- S16 pError;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /*
- * Prepare data for compare string 1
- */
- if (PhoneBook[first].field & MMI_PHB_ENTRY_FIELD_EMAIL)
- {
- #ifdef __MMI_PHB_USIM_FIELD__
- if (first >= MAX_PB_PHONE_ENTRIES)
- {
- AnsiiToUnicodeString((S8*) pbEmailAddress, (S8*) phb_email[first - MAX_PB_PHONE_ENTRIES].email_address);
- }
- else
- #endif /* __MMI_PHB_USIM_FIELD__ */
- {
- ReadRecord(
- NVRAM_EF_PHB_FIELDS_LID,
- (U16) (first + 1),
- (void*)&PhoneBookOptionalFields,
- OPTIONAL_FIELDS_RECORD_SIZE,
- &pError);
- AnsiiToUnicodeString(email1, (S8*) PhoneBookOptionalFields.emailAddress);
- }
- string1 = email1;
- }
- else
- {
- string1 = (S8*) PhoneBook[first].alpha_id.name;
- }
- /*
- * Prepare data for compare string 2
- */
- if (PhoneBook[second].field & MMI_PHB_ENTRY_FIELD_EMAIL)
- {
- #ifdef __MMI_PHB_USIM_FIELD__
- if (second >= MAX_PB_PHONE_ENTRIES)
- {
- AnsiiToUnicodeString((S8*) pbEmailAddress, (S8*) phb_email[second - MAX_PB_PHONE_ENTRIES].email_address);
- }
- else
- #endif /* __MMI_PHB_USIM_FIELD__ */
- {
- ReadRecord(
- NVRAM_EF_PHB_FIELDS_LID,
- (U16) (second + 1),
- (void*)&PhoneBookOptionalFields,
- OPTIONAL_FIELDS_RECORD_SIZE,
- &pError);
- AnsiiToUnicodeString(email2, (S8*) PhoneBookOptionalFields.emailAddress);
- }
- string2 = email2;
- }
- else
- {
- string2 = (S8*) PhoneBook[second].alpha_id.name;
- }
- /*
- * compare strings
- */
- mmi_phb_compare_ucs2_strings(string1, string2, same_count, distance);
- /*
- * If two strings are the same, put smaller store index in front.
- */
- if (*distance == 0)
- {
- if (first < second)
- {
- *distance = -1;
- }
- else if (first > second)
- {
- *distance = 1;
- }
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_sort_email_delete_index
- * DESCRIPTION
- * This function
- * PARAMETERS
- * store_index [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_sort_email_delete_index(U16 store_index)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 pos, i;
- S16 pError;
- #ifdef __MMI_PHB_USIM_FIELD__
- U16 g_phb_email_index[MAX_PB_ENTRIES];
- #else
- U16 g_phb_email_index[MAX_PB_PHONE_ENTRIES];
- #endif
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef __MMI_PHB_USIM_FIELD__
- ReadRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_ENTRIES * sizeof(U16), &pError);
- for (pos = 0; pos < (PhoneBookEntryCount + 1); pos++)
- if (g_phb_email_index[pos] == store_index)
- {
- break;
- }
- for (i = pos; i < (PhoneBookEntryCount + 1); i++)
- {
- g_phb_email_index[i] = g_phb_email_index[i + 1];
- }
- WriteRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_ENTRIES * sizeof(U16), &pError);
- #else /* __MMI_PHB_USIM_FIELD__ */
- ReadRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_PHONE_ENTRIES * sizeof(U16), &pError);
- for (pos = 0; pos < (g_phb_cntx.phone_used + 1); pos++)
- if (g_phb_email_index[pos] == store_index)
- {
- break;
- }
- for (i = pos; i < (g_phb_cntx.phone_used + 1); i++)
- {
- g_phb_email_index[i] = g_phb_email_index[i + 1];
- }
- WriteRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_PHONE_ENTRIES * sizeof(U16), &pError);
- #endif /* __MMI_PHB_USIM_FIELD__ */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_sort_email_delete_all_index
- * DESCRIPTION
- * This function
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_phb_sort_email_delete_all_index(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 pError;
- #ifdef __MMI_PHB_USIM_FIELD__
- U16 g_phb_email_index[MAX_PB_ENTRIES];
- #else
- U16 g_phb_email_index[MAX_PB_PHONE_ENTRIES];
- #endif
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef __MMI_PHB_USIM_FIELD__
- memset(g_phb_email_index, 0xff, MAX_PB_ENTRIES * sizeof(U16));
- WriteRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_ENTRIES * sizeof(U16), &pError);
- #else /* __MMI_PHB_USIM_FIELD__ */
- memset(g_phb_email_index, 0xff, MAX_PB_PHONE_ENTRIES * sizeof(U16));
- WriteRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_PHONE_ENTRIES * sizeof(U16), &pError);
- #endif /* __MMI_PHB_USIM_FIELD__ */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_phb_search_email_binary_search
- * DESCRIPTION
- * This function
- * PARAMETERS
- * low [IN]
- * high [IN]
- * ucs2_pattern [?]
- * RETURNS
- * void
- *****************************************************************************/
- U16 mmi_phb_search_email_binary_search(S32 low, S32 high, S8 *ucs2_pattern)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 pError;
- U16 g_phb_email_index[MAX_PB_PHONE_ENTRIES];
- S32 mid;
- S16 flag;
- U8 same_count;
- S32 distance;
- U16 index;
- S8 *string;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Get email mapping table from NVRAM */
- ReadRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_PHONE_ENTRIES * sizeof(U16), &pError);
- /* Use binary search to find nearest name. */
- while (low <= high)
- {
- mid = (low + high) / 2;
- index = g_phb_email_index[mid];
- /* Use email to compare pattern, if email empty, use name instead */
- ReadRecord(
- NVRAM_EF_PHB_FIELDS_LID,
- (U16) (index + 1),
- (void*)&PhoneBookOptionalFields,
- OPTIONAL_FIELDS_RECORD_SIZE,
- &pError);
- if (PhoneBookOptionalFields.emailAddress[0] != 0x00)
- {
- AnsiiToUnicodeString(pbEmailAddress, (PS8) PhoneBookOptionalFields.emailAddress);
- string = (S8*) pbEmailAddress;
- }
- else
- {
- string = (S8*) PhoneBook[index].alpha_id.name;
- }
- mmi_phb_compare_ucs2_strings(ucs2_pattern, string, &same_count, &distance);
- if (distance > 0)
- {
- low = mid + 1;
- flag = -1;
- }
- /*
- * Distance == 0 or < 0 here
- * If there are duplicate entry, this will help to move up until first entry.
- */
- else
- {
- high = mid - 1;
- flag = 1;
- }
- }
- if (flag == -1)
- {
- return (U16) (mid + 1);
- }
- else
- {
- return (U16) mid;
- }
- }
- #endif /* defined(__MMI_PHB_EMAIL_SORT__) */
- #endif /* _PHONEBOOKSEARCH_C */