PhoneBookStubsToOthers.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:281k
源码类别:

MTK

开发平台:

C/C++

  1.     /*----------------------------------------------------------------*/
  2.     /* Code Body                                                      */
  3.     /*----------------------------------------------------------------*/
  4.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<SendDataForMMS>n", __FILE__, __LINE__));
  5.     ClearInputEventHandler(MMI_DEVICE_ALL); /* Clear Key Handler to avoid resend message. */
  6. #if defined(OBIGO_SUPPORT) && !defined(MMI_ON_WIN32)
  7.     widget_MMI_fullscreen_editor_update_from_phonebook((kal_uint8*) number);
  8. #endif 
  9. #if defined (JATAAYU_SUPPORT)
  10.     if (phb_list_view_type == MMI_PHB_ENTRY_FIELD_ALL_NUMBER)
  11.     {
  12.         update_mms_number_from_phonebook(number);
  13.     }
  14.     else if (phb_list_view_type == MMI_PHB_ENTRY_FIELD_EMAIL)
  15.     {
  16.         update_mms_email_from_phonebook(number);
  17.     }
  18. #endif /* JATAAYU_SUPPORT */ 
  19. }
  20. #endif /* ((defined(OBIGO_SUPPORT) || defined (JATAAYU_SUPPORT)) && defined(MMS_SUPPORT)) */
  21. /*****************************************************************************
  22.  * FUNCTION
  23.  *  mmi_phb_exit_mms_choose_number
  24.  * DESCRIPTION
  25.  *  exit function
  26.  * PARAMETERS
  27.  *  void
  28.  * RETURNS
  29.  *  void
  30.  *****************************************************************************/
  31. void mmi_phb_exit_mms_choose_number(void)
  32. {
  33.     /*----------------------------------------------------------------*/
  34.     /* Local Variables                                                */
  35.     /*----------------------------------------------------------------*/
  36.     /*----------------------------------------------------------------*/
  37.     /* Code Body                                                      */
  38.     /*----------------------------------------------------------------*/
  39.     g_phb_cntx.end_scr_id = SCR_ID_PHB_MMS_CHOOSE_ENTRY;
  40. }
  41. /*****************************************************************************
  42.  * FUNCTION
  43.  *  mmi_phb_mms_email_list_get_item
  44.  * DESCRIPTION
  45.  *  dynamic list call back function
  46.  * PARAMETERS
  47.  *  item_index          [IN]        
  48.  *  str_buff            [IN]        
  49.  *  img_buff_p          [?]         
  50.  *  str_img_mask        [IN]        
  51.  * RETURNS
  52.  *  
  53.  *****************************************************************************/
  54. pBOOL mmi_phb_mms_email_list_get_item(S32 item_index, UI_string_type str_buff, PU8 *img_buff_p, U8 str_img_mask)
  55. {
  56.     /*----------------------------------------------------------------*/
  57.     /* Local Variables                                                */
  58.     /*----------------------------------------------------------------*/
  59.     U16 i;
  60.     /*----------------------------------------------------------------*/
  61.     /* Code Body                                                      */
  62.     /*----------------------------------------------------------------*/
  63.     i = g_phb_cntx.list_filter[item_index];
  64.     if (pfnUnicodeStrlen((S8*) PhoneBook[i].alpha_id.name))
  65.     {
  66.         pfnUnicodeStrcpy((S8*) str_buff, (S8*) PhoneBook[i].alpha_id.name);
  67.     }
  68.     else
  69.     {
  70.         mmi_phb_convert_get_ucs2_number((S8*) str_buff, i);
  71.     }
  72.     if (i >= MAX_PB_PHONE_ENTRIES)
  73.     {
  74.         *img_buff_p = get_image(IMG_STORAGE_SIM);
  75.     }
  76.     else
  77.     {
  78.         *img_buff_p = get_image(IMG_STORAGE_HANDSET);
  79.     }
  80.     return TRUE;
  81. }
  82. /*****************************************************************************
  83.  * FUNCTION
  84.  *  mmi_phb_mms_email_list_get_hint
  85.  * DESCRIPTION
  86.  *  
  87.  * PARAMETERS
  88.  *  item_index      [IN]        
  89.  *  hint_array      [?]         
  90.  * RETURNS
  91.  *  
  92.  *****************************************************************************/
  93. S32 mmi_phb_mms_email_list_get_hint(S32 item_index, UI_string_type *hint_array)
  94. {
  95.     /*----------------------------------------------------------------*/
  96.     /* Local Variables                                                */
  97.     /*----------------------------------------------------------------*/
  98.     U16 store_index;
  99.     S8 temp_number[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];
  100.     /*----------------------------------------------------------------*/
  101.     /* Code Body                                                      */
  102.     /*----------------------------------------------------------------*/
  103.     store_index = g_phb_cntx.list_filter[item_index];
  104.     mmi_phb_convert_get_ucs2_number((S8*) temp_number, store_index);
  105.     if (pfnUnicodeStrlen((S8*) PhoneBook[store_index].alpha_id.name) && pfnUnicodeStrlen((S8*) temp_number))
  106.     {
  107.         pfnUnicodeStrcpy((S8*) hint_array[0], (S8*) temp_number);
  108.     }
  109.     else
  110.     {
  111.         return 0;   /* No Hint Data */
  112.     }
  113.     return 1;   /* One hint data only, can be more hints. */
  114. }
  115. /*--------------------------------------------------END Interface for MMS  ------------------------------------------------------*/
  116. /*------------------------------------------------------  Interface for File Manager Image---------------------------------------------------*/
  117. #define MMI_PHB_INTERFACE_FOR_FMGR
  118. #if defined(__MMI_FILE_MANAGER__)
  119. /*****************************************************************************
  120.  * FUNCTION
  121.  *  mmi_phb_fmgr_select_image_done
  122.  * DESCRIPTION
  123.  *  
  124.  * PARAMETERS
  125.  *  void
  126.  * RETURNS
  127.  *  void
  128.  *****************************************************************************/
  129. static void mmi_phb_fmgr_select_image_done(void)
  130. {
  131.     /*----------------------------------------------------------------*/
  132.     /* Local Variables                                                */
  133.     /*----------------------------------------------------------------*/
  134.     /*----------------------------------------------------------------*/
  135.     /* Code Body                                                      */
  136.     /*----------------------------------------------------------------*/
  137.     /* Clear Previous PHB screen, and set phb new entry point here. */
  138.     mmi_phb_clear_old_history();
  139.     g_phb_cntx.start_scr_id = SCR_ID_PHB_FMGR_SAVE_OPTION;
  140.     mmi_phb_entry_fmgr_save_option();
  141.     DeleteScreenIfPresent(SCR_ID_PHB_IMAGE_VIEW_IMAGE);
  142. }
  143. /*****************************************************************************
  144.  * FUNCTION
  145.  *  mmi_phb_fmgr_image_preview
  146.  * DESCRIPTION
  147.  *  
  148.  * PARAMETERS
  149.  *  void
  150.  * RETURNS
  151.  *  void
  152.  *****************************************************************************/
  153. static void mmi_phb_fmgr_image_preview(void)
  154. {
  155.     /*----------------------------------------------------------------*/
  156.     /* Local Variables                                                */
  157.     /*----------------------------------------------------------------*/
  158.     /*----------------------------------------------------------------*/
  159.     /* Code Body                                                      */
  160.     /*----------------------------------------------------------------*/
  161.     EntryNewScreen(SCR_ID_PHB_IMAGE_VIEW_IMAGE, NULL, mmi_phb_fmgr_image_preview, NULL);
  162.     /* entry cat222 to decode and display a image from file */
  163.     ShowCategory222Screen(
  164.         STR_ASSOCIATE_PICTURE,
  165.         IMG_SCR_PBOOK_CAPTION,
  166.         STR_GLOBAL_OK,
  167.         IMG_GLOBAL_OK,
  168.         STR_GLOBAL_BACK,
  169.         IMG_GLOBAL_BACK,
  170.         GDI_COLOR_BLACK,
  171.         (PS8) NULL,
  172.         (PS8) g_phb_file_path,
  173.         FALSE,
  174.         mmi_phb_image_preview_callback);
  175.     SetLeftSoftkeyFunction(mmi_phb_fmgr_select_image_done, KEY_EVENT_UP);
  176.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  177. }
  178. /*****************************************************************************
  179.  * FUNCTION
  180.  *  mmi_phb_fmgr_select_video_done
  181.  * DESCRIPTION
  182.  *  
  183.  * PARAMETERS
  184.  *  void
  185.  * RETURNS
  186.  *  void
  187.  *****************************************************************************/
  188. static void mmi_phb_fmgr_select_video_done(void)
  189. {
  190.     /*----------------------------------------------------------------*/
  191.     /* Local Variables                                                */
  192.     /*----------------------------------------------------------------*/
  193.     /*----------------------------------------------------------------*/
  194.     /* Code Body                                                      */
  195.     /*----------------------------------------------------------------*/
  196.     /* Clear Previous PHB screen, and set phb new entry point here. */
  197.     mmi_phb_clear_old_history();
  198.     g_phb_cntx.start_scr_id = SCR_ID_PHB_FMGR_SAVE_OPTION;
  199.     mmi_phb_entry_fmgr_save_option();
  200.     DeleteScreenIfPresent(SCR_ID_PHB_VIDEO_PREVIEW);
  201. }
  202. #if defined(__MMI_INCOMING_CALL_VIDEO__)
  203. /*****************************************************************************
  204.  * FUNCTION
  205.  *  mmi_phb_fmgr_video_preview
  206.  * DESCRIPTION
  207.  *  
  208.  * PARAMETERS
  209.  *  void
  210.  * RETURNS
  211.  *  void
  212.  *****************************************************************************/
  213. static void mmi_phb_fmgr_video_preview(void)
  214. {
  215.     /*----------------------------------------------------------------*/
  216.     /* Local Variables                                                */
  217.     /*----------------------------------------------------------------*/
  218.     PU8 gui_buffer;
  219.     /*----------------------------------------------------------------*/
  220.     /* Code Body                                                      */
  221.     /*----------------------------------------------------------------*/
  222.     if (isInCall()) /* Can not preview video during call. */
  223.     {
  224. #ifdef __MMI_SWFLASH__
  225. if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_SWFLASH)
  226. {
  227. DisplayPopup((U8*)GetString(STR_ID_PHB_CANT_VIEW_SWFLASH_IN_CALL), IMG_GLOBAL_WARNING, FALSE, PHB_NOTIFY_TIMEOUT, WARNING_TONE);
  228. }
  229. else
  230. #endif /* __MMI_SWFLASH__ */
  231.         {
  232.         DisplayPopup(
  233.             (U8*) GetString(STR_ID_PHB_CANT_VIEW_VIDEO_IN_CALL),
  234.             IMG_GLOBAL_WARNING,
  235.             FALSE,
  236.             PHB_NOTIFY_TIMEOUT,
  237.             WARNING_TONE);
  238.         }
  239.         return;
  240.     }
  241.     EntryNewScreen(SCR_ID_PHB_VIDEO_PREVIEW, NULL, mmi_phb_fmgr_video_preview, NULL);
  242.     gui_buffer = GetCurrGuiBuffer(SCR_ID_PHB_VIDEO_PREVIEW);
  243.     ShowCategory225Screen(
  244.         STR_GLOBAL_VIEW,                    /* title_str */
  245.         IMG_SCR_PBOOK_CAPTION,              /* title_icon */
  246.         STR_GLOBAL_OK,                      /* lsk_str */
  247.         IMG_GLOBAL_OK,                      /* lsk_icon */
  248.         STR_GLOBAL_BACK,                    /* rsk_str */
  249.         IMG_GLOBAL_BACK,                    /* rsk_icon */
  250.         0,                                  /* video_id */
  251.         (S8*) g_phb_video_file_path,      /* video_filename */
  252.         1,                                  /* repeat_count */
  253.         TRUE,                               /* is_visual_update */
  254.         (BOOL) ! IsSilentModeActivated(),   /* is_play_audio */
  255.         TRUE,                               /* is_lcd_no_sleep */
  256.         GDI_COLOR_WHITE,                    /* bg_color */
  257.         mmi_phb_video_view_callback,
  258.         gui_buffer);
  259.     SetLeftSoftkeyFunction(mmi_phb_fmgr_select_video_done, KEY_EVENT_UP);
  260.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  261. }
  262. #endif /* __MMI_INCOMING_CALL_VIDEO__ */
  263. /*****************************************************************************
  264.  * FUNCTION
  265.  *  mmi_phb_fmgr_from_file_mgr
  266.  * DESCRIPTION
  267.  *  forward function for file manager application
  268.  * PARAMETERS
  269.  *  path        [IN]        
  270.  * RETURNS
  271.  *  void
  272.  *****************************************************************************/
  273. void mmi_phb_fmgr_from_file_mgr(S8 *path)
  274. {
  275.     /*----------------------------------------------------------------*/
  276.     /* Local Variables                                                */
  277.     /*----------------------------------------------------------------*/
  278. #if defined(__MMI_INCOMING_CALL_VIDEO__)
  279.     PS8 ext_ptr;
  280.     S8 ext_name[20];
  281.     S32 i;
  282. #endif /* defined(__MMI_INCOMING_CALL_VIDEO__) */ 
  283.     /*----------------------------------------------------------------*/
  284.     /* Code Body                                                      */
  285.     /*----------------------------------------------------------------*/
  286.     if (path == NULL)
  287.     {
  288.         DisplayPopup(
  289.             (U8*) GetString(STR_ID_PHB_FMGR_IMAGE_NO_SELECT),
  290.             IMG_GLOBAL_ERROR,
  291.             FALSE,
  292.             PHB_NOTIFY_TIMEOUT,
  293.             ERROR_TONE);
  294.         return;
  295.     }
  296. #if defined(__MMI_INCOMING_CALL_VIDEO__)
  297.     /* Check video content */
  298.     ext_ptr = mmi_fmgr_extract_ext_file_name(path);
  299.     memset(ext_name, 0, sizeof(ext_name));
  300.     UnicodeNToAnsii(ext_name, ext_ptr, 5 * ENCODING_LENGTH);
  301.     /* make upper */
  302.     for (i = 0; i < 12; i++)
  303.     {
  304.         if (ext_name[i] != 0)
  305.         {
  306.             if (ext_name[i] >= 'a')
  307.             {
  308.                 ext_name[i] -= 'a' - 'A';
  309.             }
  310.         }
  311.     }
  312.     if (strcmp(ext_name, "3GP") == 0 || strcmp(ext_name, "MP4") == 0 || strcmp(ext_name, "AVI") == 0)
  313.     {
  314.         if (mmi_phb_video_check_data_space(path))
  315.         {
  316.             pfnUnicodeStrcpy(g_phb_video_file_path, path);
  317.             g_phb_cntx.recv_res_from = MMI_PHB_RECV_RES_VIDEO;
  318.             mmi_phb_fmgr_video_preview();
  319.         }
  320.     }
  321. #if defined(__MMI_SWFLASH__) && defined(SWFLASH_CHAOTEX)
  322.     else if (strcmp(ext_name, "CMP") == 0)
  323.     {
  324.         if (mmi_phb_video_check_data_space(path))
  325.         {
  326.             pfnUnicodeStrcpy(g_phb_video_file_path, path);
  327.             g_phb_cntx.recv_res_from = MMI_PHB_RECV_RES_SWFLASH;
  328.             mmi_phb_fmgr_video_preview();
  329.         }
  330.     }
  331. #endif /* defined(__MMI_SWFLASH__) && defined(SWFLASH_CHAOTEX) */ 
  332.     /* Check image content */
  333.     else if (mmi_phb_image_check_valid_image(path))
  334. #else /* defined(__MMI_INCOMING_CALL_VIDEO__) */ 
  335.     /* Check image content */
  336.     if (mmi_phb_image_check_valid_image(path))
  337. #endif /* defined(__MMI_INCOMING_CALL_VIDEO__) */ 
  338.     {
  339.         pfnUnicodeStrcpy(g_phb_file_path, path);
  340.         /* Clear Previous PHB screen, and set phb new entry point here. */
  341.         mmi_phb_clear_old_history();
  342.         g_phb_cntx.start_scr_id = SCR_ID_PHB_FMGR_SAVE_OPTION;
  343.         g_phb_cntx.recv_res_from = MMI_PHB_RECV_RES_IMAGE;
  344.         mmi_phb_fmgr_image_preview();
  345.     }
  346. }
  347. /*****************************************************************************
  348.  * FUNCTION
  349.  *  mmi_phb_highlight_fmgr_add_entry
  350.  * DESCRIPTION
  351.  *  Highlight function to associate image from file manager to a new phonebook entry
  352.  * PARAMETERS
  353.  *  void
  354.  * RETURNS
  355.  *  void
  356.  *****************************************************************************/
  357. void mmi_phb_highlight_fmgr_add_entry(void)
  358. {
  359.     /*----------------------------------------------------------------*/
  360.     /* Local Variables                                                */
  361.     /*----------------------------------------------------------------*/
  362.     /*----------------------------------------------------------------*/
  363.     /* Code Body                                                      */
  364.     /*----------------------------------------------------------------*/
  365.     SetLeftSoftkeyFunction(mmi_phb_fmgr_pre_add_entry, KEY_EVENT_UP);
  366.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  367.     SetKeyHandler(mmi_phb_fmgr_pre_add_entry, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  368.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  369. }
  370. /*****************************************************************************
  371.  * FUNCTION
  372.  *  mmi_phb_highlight_fmgr_edit_entry
  373.  * DESCRIPTION
  374.  *  Highlight function for associate image to a existing phonebook entry
  375.  * PARAMETERS
  376.  *  void
  377.  * RETURNS
  378.  *  void
  379.  *****************************************************************************/
  380. void mmi_phb_highlight_fmgr_edit_entry(void)
  381. {
  382.     /*----------------------------------------------------------------*/
  383.     /* Local Variables                                                */
  384.     /*----------------------------------------------------------------*/
  385.     /*----------------------------------------------------------------*/
  386.     /* Code Body                                                      */
  387.     /*----------------------------------------------------------------*/
  388.     SetLeftSoftkeyFunction(mmi_phb_list_pre_entry_for_fmgr_in_nvram, KEY_EVENT_UP);
  389.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  390.     SetKeyHandler(mmi_phb_list_pre_entry_for_fmgr_in_nvram, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  391.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  392.     phbListView = MMI_PHB_LIST_FOR_SAVE_FROM_FILE_MGR;
  393. }
  394. /*****************************************************************************
  395.  * FUNCTION
  396.  *  mmi_phb_highlight_edit_callergroup
  397.  * DESCRIPTION
  398.  *  Highlight function for associate image to a existing phonebook caller group
  399.  * PARAMETERS
  400.  *  void
  401.  * RETURNS
  402.  *  void
  403.  *****************************************************************************/
  404. void mmi_phb_highlight_edit_callergroup(void)
  405. {
  406.     /*----------------------------------------------------------------*/
  407.     /* Local Variables                                                */
  408.     /*----------------------------------------------------------------*/
  409.     /*----------------------------------------------------------------*/
  410.     /* Code Body                                                      */
  411.     /*----------------------------------------------------------------*/
  412.     SetLeftSoftkeyFunction(mmi_phb_entry_callergroup, KEY_EVENT_UP);
  413.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  414.     SetKeyHandler(mmi_phb_entry_callergroup, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  415.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  416.     phbListView = MMI_PHB_LIST_FOR_SAVE_FROM_FILE_MGR;
  417. }
  418. /*****************************************************************************
  419.  * FUNCTION
  420.  *  mmi_phb_entry_fmgr_save_option
  421.  * DESCRIPTION
  422.  *  Entry function for save image from file manager option menu
  423.  * PARAMETERS
  424.  *  void
  425.  * RETURNS
  426.  *  void
  427.  *****************************************************************************/
  428. void mmi_phb_entry_fmgr_save_option(void)
  429. {
  430.     /*----------------------------------------------------------------*/
  431.     /* Local Variables                                                */
  432.     /*----------------------------------------------------------------*/
  433.     U8 *guiBuffer;
  434.     U16 nStrItemList[3];
  435.     U16 nNumofItem;
  436.     /*----------------------------------------------------------------*/
  437.     /* Code Body                                                      */
  438.     /*----------------------------------------------------------------*/
  439.     EntryNewScreen(SCR_ID_PHB_FMGR_SAVE_OPTION, mmi_phb_exit_fmgr_save_option, mmi_phb_entry_fmgr_save_option, NULL);
  440.     guiBuffer = GetCurrGuiBuffer(SCR_ID_PHB_FMGR_SAVE_OPTION);
  441.     nNumofItem = GetNumOfChild(MENU_ID_PHB_FMGR_SAVE_OPTION);
  442.     GetSequenceStringIds(MENU_ID_PHB_FMGR_SAVE_OPTION, nStrItemList);
  443.     SetParentHandler(MENU_ID_PHB_FMGR_SAVE_OPTION);
  444.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  445.     ShowCategory15Screen(
  446.         STR_SCR_VIEW_OPTIONS_CAPTION,
  447.         IMG_SCR_PBOOK_CAPTION,
  448.         STR_GLOBAL_OK,
  449.         IMG_GLOBAL_OK,
  450.         STR_GLOBAL_BACK,
  451.         IMG_GLOBAL_BACK,
  452.         nNumofItem,
  453.         nStrItemList,
  454.         (U16*) gIndexIconsImageList,
  455.         LIST_MENU,
  456.         0,
  457.         guiBuffer);
  458. }
  459. /*****************************************************************************
  460.  * FUNCTION
  461.  *  mmi_phb_exit_fmgr_save_option
  462.  * DESCRIPTION
  463.  *  Exit function
  464.  * PARAMETERS
  465.  *  void
  466.  * RETURNS
  467.  *  void
  468.  *****************************************************************************/
  469. void mmi_phb_exit_fmgr_save_option(void)
  470. {
  471.     /*----------------------------------------------------------------*/
  472.     /* Local Variables                                                */
  473.     /*----------------------------------------------------------------*/
  474.     /*----------------------------------------------------------------*/
  475.     /* Code Body                                                      */
  476.     /*----------------------------------------------------------------*/
  477.     g_phb_cntx.end_scr_id = SCR_ID_PHB_FMGR_SAVE_OPTION;
  478. }
  479. /*****************************************************************************
  480.  * FUNCTION
  481.  *  mmi_phb_fmgr_pre_add_entry
  482.  * DESCRIPTION
  483.  *  pre check for associate image from file manager to a new phonebook entry
  484.  * PARAMETERS
  485.  *  void
  486.  * RETURNS
  487.  *  void
  488.  *****************************************************************************/
  489. void mmi_phb_fmgr_pre_add_entry(void)
  490. {
  491.     /*----------------------------------------------------------------*/
  492.     /* Local Variables                                                */
  493.     /*----------------------------------------------------------------*/
  494.     /*----------------------------------------------------------------*/
  495.     /* Code Body                                                      */
  496.     /*----------------------------------------------------------------*/
  497. #ifdef __SYNCML_SUPPORT__
  498.     if (mmi_syncml_is_phb_sync_now())
  499.     {
  500.         mmi_phb_entry_not_ready(STR_ID_SYNC_PLEASE_WAIT);
  501.     }
  502.     else
  503. #endif /* __SYNCML_SUPPORT__ */
  504.     if (g_phb_cntx.phb_ready && !g_phb_cntx.processing)
  505.     {
  506.         if (g_phb_cntx.phone_used >= g_phb_cntx.phone_total)    /* No spcace in NVRAM */
  507.         {
  508.             DisplayPopup((PU8) GetString(STR_PBOOK_FULL_MSG), IMG_GLOBAL_ERROR, FALSE, PHB_NOTIFY_TIMEOUT, ERROR_TONE);
  509.         }
  510.         else
  511.         {
  512.             mmi_phb_util_clear_buffer(TRUE);
  513.             if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_IMAGE)
  514.             {
  515.                 mmi_phb_build_image_list();
  516.                 g_phb_cntx.selected_pic_index = g_phb_cntx.total_image_id - 1;
  517.                 g_phb_cntx.image_location = MMI_PHB_IMAGE_SELECT_PATH;
  518.             }
  519.             else if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_AUDIO)
  520.             {
  521.                 mmi_phb_build_ring_tone_list();
  522.                 g_phb_cntx.selected_ring_index = mmi_phb_get_ring_tone_index(g_phb_cntx.recv_res_id);
  523.             }
  524.         #if defined(__MMI_INCOMING_CALL_VIDEO__)
  525.             else if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_VIDEO)
  526.             {
  527.                 mmi_phb_build_video_list();
  528.                 g_phb_cntx.selected_video_index = g_phb_cntx.total_video_id - 1;
  529.                 g_phb_cntx.video_location = MMI_PHB_IMAGE_SELECT_PATH;
  530.             }
  531.         #ifdef __MMI_SWFLASH__
  532.             else if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_SWFLASH)
  533.             {
  534.                 mmi_phb_build_video_list();
  535.                 g_phb_cntx.selected_video_index = g_phb_cntx.total_video_id - 2;
  536.                 g_phb_cntx.video_location = MMI_PHB_SWFLASH_SELECT_PATH;
  537.             }
  538.         #endif /* __MMI_SWFLASH__ */ 
  539.         #endif /* defined(__MMI_INCOMING_CALL_VIDEO__) */ 
  540.             g_phb_cntx.set_done_flag = 2;
  541.             g_phb_cntx.selected_storage = MMI_NVRAM;
  542.             mmi_phb_entry_op_add_entry();
  543.         }
  544.     }
  545.     else
  546.     {
  547.         mmi_phb_entry_not_ready(STR_PROCESSING_PHONEBOOK);
  548.     }
  549. }
  550. /*****************************************************************************
  551.  * FUNCTION
  552.  *  mmi_phb_fmgr_pre_edit_entry
  553.  * DESCRIPTION
  554.  *  pre check for associate image to a existing phonebook entry
  555.  * PARAMETERS
  556.  *  void
  557.  * RETURNS
  558.  *  void
  559.  *****************************************************************************/
  560. void mmi_phb_fmgr_pre_edit_entry(void)
  561. {
  562.     /*----------------------------------------------------------------*/
  563.     /* Local Variables                                                */
  564.     /*----------------------------------------------------------------*/
  565.     S16 pError;
  566.     U16 i, store_index;
  567.     PHB_OPTIONAL_IDS_STRUCT *opt_ids;
  568.     /*----------------------------------------------------------------*/
  569.     /* Code Body                                                      */
  570.     /*----------------------------------------------------------------*/
  571.     store_index = g_phb_cntx.active_index;
  572.     if (store_index >= MAX_PB_PHONE_ENTRIES)    /* ERROR!, Record in NVRAM only */
  573.     {
  574.         /* Print Error Log Here. */
  575.         GoBackHistory();
  576.         return;
  577.     }
  578.     /* set active index for edit entry */
  579.     for (i = 0; i < PhoneBookEntryCount; i++)
  580.     {
  581.         if (g_phb_name_index[i] == store_index)
  582.         {
  583.             g_phb_cntx.active_index = i;
  584.             break;
  585.         }
  586.     }
  587.     /* Clear All Buffer First. */
  588.     mmi_phb_util_clear_buffer(TRUE);
  589.     /* Assign value for each field for update */
  590.     pfnUnicodeStrcpy(pbName, (S8*) PhoneBook[store_index].alpha_id.name);
  591.     mmi_phb_convert_get_ucs2_number(pbNumber, store_index);
  592. #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  593.     ReadRecord(
  594.         NVRAM_EF_PHB_FIELDS_LID,
  595.         (U16) (store_index + 1),
  596.         (void*)&PhoneBookOptionalFields,
  597.         OPTIONAL_FIELDS_RECORD_SIZE,
  598.         &pError);
  599.     AnsiiToUnicodeString(pbHomeNumber, (PS8) PhoneBookOptionalFields.homeNumber);
  600.     pfnUnicodeStrcpy(pbCompanyName, (PS8) PhoneBookOptionalFields.companyName);
  601.     AnsiiToUnicodeString(pbEmailAddress, (PS8) PhoneBookOptionalFields.emailAddress);
  602.     AnsiiToUnicodeString(pbOfficeNumber, (PS8) PhoneBookOptionalFields.officeNumber);
  603.     AnsiiToUnicodeString(pbFaxNumber, (PS8) PhoneBookOptionalFields.faxNumber);
  604. #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  605. #if defined(__MMI_PHB_BIRTHDAY_FIELD__)
  606.     mmi_phb_bday_read_data_to_buff(store_index);
  607. #endif 
  608.     mmi_phb_build_image_list();
  609.     mmi_phb_build_ring_tone_list();
  610.     mmi_phb_read_optional_ids(store_index);
  611.     opt_ids = (PHB_OPTIONAL_IDS_STRUCT*) g_phb_cntx.optional_ids;
  612.     /* Image setting */
  613.     if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_IMAGE)
  614.     {
  615.         g_phb_cntx.selected_pic_index = g_phb_cntx.total_image_id - 1;
  616.         g_phb_cntx.image_location = MMI_PHB_IMAGE_SELECT_PATH;
  617.     }
  618.     else    /* Keep original image */
  619.     {
  620.         g_phb_cntx.selected_pic_index = mmi_phb_get_image_index(opt_ids->pictureTagID);
  621.         if (opt_ids->pictureTagID == 1)
  622.         {
  623.             g_phb_cntx.image_location = MMI_PHB_IMAGE_FOR_ENTRY;
  624.         }
  625.         else
  626.         {
  627.             g_phb_cntx.image_location = MMI_PHB_IMAGE_NO_SELECT;
  628.         }
  629.     }
  630.     /* Audio Setting */
  631.     if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_AUDIO)
  632.     {
  633.         g_phb_cntx.selected_ring_index = mmi_phb_get_ring_tone_index(g_phb_cntx.recv_res_id);
  634.     }
  635.     else    /* Keep original audio */
  636.     {
  637.         g_phb_cntx.selected_ring_index = mmi_phb_get_ring_tone_index(opt_ids->ringToneID);
  638.     }
  639.     /* Video Setting */
  640. #if defined(__MMI_INCOMING_CALL_VIDEO__)
  641.     mmi_phb_build_video_list();
  642.     if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_VIDEO)
  643.     {
  644.         g_phb_cntx.selected_video_index = g_phb_cntx.total_video_id - 1;
  645.         g_phb_cntx.video_location = MMI_PHB_IMAGE_SELECT_PATH;
  646.         g_phb_cntx.video_audio = 1; /* Turn on video's audio by default */
  647.     }
  648. #ifdef __MMI_SWFLASH__
  649.     else if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_SWFLASH)
  650.     {
  651.         g_phb_cntx.selected_video_index = g_phb_cntx.total_video_id - 2;
  652.         g_phb_cntx.video_location = MMI_PHB_SWFLASH_SELECT_PATH;
  653.         g_phb_cntx.video_audio = 1; /* Turn on video's audio by default */
  654.     }
  655. #endif /* __MMI_SWFLASH__ */ 
  656.     else    /* Keep original video */
  657.     {
  658.         U16 video_id = mmi_phb_video_get_id_by_index(store_index);
  659.         g_phb_cntx.selected_video_index = mmi_phb_get_video_index(video_id);
  660.         g_phb_cntx.video_audio = ((video_id == 0) || (video_id & 0x4000)) ? 1 : 0;
  661.         if ((video_id & 0x8000) && mmi_phb_video_get_path_by_index(video_id))   /* Check if the video is a file */
  662.         {
  663.         #ifdef __MMI_SWFLASH__
  664.             if(video_id & 0x2000)
  665.             {
  666.                 g_phb_cntx.video_location = MMI_PHB_SWFLASH_SELECT_PATH;
  667.             }
  668.             else
  669.         #endif /* __MMI_SWFLASH__ */
  670.             {
  671.                 g_phb_cntx.video_location = MMI_PHB_IMAGE_SELECT_PATH;
  672.             }
  673.         }
  674.         else
  675.         {
  676.             g_phb_cntx.video_location = MMI_PHB_IMAGE_NO_SELECT;
  677.         }
  678.     }
  679. #endif /* defined(__MMI_INCOMING_CALL_VIDEO__) */ 
  680.     /* Caller Group Setting, keep original caller group */
  681.     g_phb_cntx.selected_grp_index = opt_ids->callerGroupID;
  682.     mmi_phb_entry_op_edit_save_confirm();
  683. }
  684. /*****************************************************************************
  685.  * FUNCTION
  686.  *  mmi_phb_fmgr_pre_edit_callergrp
  687.  * DESCRIPTION
  688.  *  pre check for associate image to a existing phonebook caller group
  689.  * PARAMETERS
  690.  *  void
  691.  * RETURNS
  692.  *  void
  693.  *****************************************************************************/
  694. void mmi_phb_fmgr_pre_edit_callergrp(void)
  695. {
  696.     /*----------------------------------------------------------------*/
  697.     /* Local Variables                                                */
  698.     /*----------------------------------------------------------------*/
  699.     PHB_CALLER_GROUP_STRUCT *callerGroups;
  700.     /*----------------------------------------------------------------*/
  701.     /* Code Body                                                      */
  702.     /*----------------------------------------------------------------*/
  703.     callerGroups = (PHB_CALLER_GROUP_STRUCT*) g_phb_cntx.caller_group;
  704.     pfnUnicodeStrcpy(pbName, (PS8) callerGroups[g_phb_cntx.active_index].groupName);
  705.     mmi_phb_build_led_and_alert_list();
  706.     mmi_phb_build_ring_tone_list();
  707.     mmi_phb_build_image_list();
  708.     /* Image Setting */
  709.     if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_IMAGE)
  710.     {
  711.         g_phb_cntx.selected_pic_index = g_phb_cntx.total_image_id - 1;
  712.         g_phb_cntx.image_location = MMI_PHB_IMAGE_SELECT_PATH;
  713.     }
  714.     else    /* Keep original image */
  715.     {
  716.         g_phb_cntx.selected_pic_index = mmi_phb_get_image_index(callerGroups[g_phb_cntx.active_index].pictureTagID);
  717.         if (callerGroups[g_phb_cntx.active_index].pictureTagID == 1)
  718.         {
  719.             g_phb_cntx.image_location = MMI_PHB_IMAGE_FOR_ENTRY;
  720.         }
  721.         else
  722.         {
  723.             g_phb_cntx.image_location = MMI_PHB_IMAGE_NO_SELECT;
  724.         }
  725.     }
  726.     /* Audio Setting */
  727.     if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_AUDIO)
  728.     {
  729.         g_phb_cntx.selected_ring_index = mmi_phb_get_ring_tone_index(g_phb_cntx.recv_res_id);
  730.     }
  731.     else    /* Keep original audio */
  732.     {
  733.         g_phb_cntx.selected_ring_index = mmi_phb_get_ring_tone_index(callerGroups[g_phb_cntx.active_index].ringToneID);
  734.     }
  735.     /* Video Setting */
  736. #if defined(__MMI_INCOMING_CALL_VIDEO__)
  737.     mmi_phb_build_video_list();
  738.     if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_VIDEO)
  739.     {
  740.         g_phb_cntx.selected_video_index = g_phb_cntx.total_video_id - 1;
  741.         g_phb_cntx.video_location = MMI_PHB_IMAGE_SELECT_PATH;
  742.         g_phb_cntx.video_audio = 1; /* Turn on video's audio by default */
  743.     }
  744. #ifdef __MMI_SWFLASH__
  745.     else if (g_phb_cntx.recv_res_from == MMI_PHB_RECV_RES_SWFLASH)
  746.     {
  747.         g_phb_cntx.selected_video_index = g_phb_cntx.total_video_id - 2;
  748.         g_phb_cntx.video_location = MMI_PHB_SWFLASH_SELECT_PATH;
  749.         g_phb_cntx.video_audio = 1; /* Turn on video's audio by default */
  750.     }
  751. #endif /* __MMI_SWFLASH__ */ 
  752.     else    /* Keep original video */
  753.     {
  754.         U16 video_id = callerGroups[g_phb_cntx.active_index].VideoID;
  755.         g_phb_cntx.selected_video_index = mmi_phb_get_video_index(video_id);
  756.         g_phb_cntx.video_audio = ((video_id == 0) || (video_id & 0x4000)) ? 1 : 0;
  757.         if ((video_id & 0x8000) &&
  758.             mmi_phb_video_get_path_by_index((U16) (g_phb_cntx.active_index + MAX_PB_PHONE_ENTRIES)))
  759.         {
  760.         #ifdef __MMI_SWFLASH__
  761.             if(video_id & 0x2000)
  762.             {
  763.                 g_phb_cntx.video_location = MMI_PHB_SWFLASH_SELECT_PATH;
  764.             }
  765.             else
  766.         #endif /* __MMI_SWFLASH__ */
  767.             {
  768.     g_phb_cntx.video_location = MMI_PHB_IMAGE_SELECT_PATH;
  769.             }
  770.         }
  771.         else
  772.         {
  773.             g_phb_cntx.video_location = MMI_PHB_IMAGE_NO_SELECT;
  774.         }
  775.     }
  776. #endif /* defined(__MMI_INCOMING_CALL_VIDEO__) */ 
  777.     /* Keep other settings */
  778.     g_phb_cntx.selected_alert_index = callerGroups[g_phb_cntx.active_index].alertType;
  779.     g_phb_cntx.selected_pattern_index = callerGroups[g_phb_cntx.active_index].LEDPatternId;
  780.     mmi_phb_callergroup_detail_pre_save();
  781. }
  782. /*------------------------------------------------------  END Interface for File Manager Image------------------------------------------------*/
  783. #endif /* defined(__MMI_FILE_MANAGER__) */ 
  784. #define MMI_PHB_INTERFACE_FOR_EMAIL
  785. #if defined(__MMI_EMAIL__)
  786. /*****************************************************************************
  787.  * FUNCTION
  788.  *  mmi_phb_email_enter_list
  789.  * DESCRIPTION
  790.  *  Phonebook list interface for email application.
  791.  * PARAMETERS
  792.  *  void
  793.  * RETURNS
  794.  *  void
  795.  *****************************************************************************/
  796. void mmi_phb_email_enter_list(void)
  797. {
  798.     /*----------------------------------------------------------------*/
  799.     /* Local Variables                                                */
  800.     /*----------------------------------------------------------------*/
  801.     /*----------------------------------------------------------------*/
  802.     /* Code Body                                                      */
  803.     /*----------------------------------------------------------------*/
  804.     phbListView = MMI_PHB_LIST_FOR_EMAIL_APP;
  805.     mmi_phb_list_pre_entry_second_level();
  806. }
  807. /*****************************************************************************
  808.  * FUNCTION
  809.  *  mmi_phb_email_choose_entry
  810.  * DESCRIPTION
  811.  *  choose entry result, send result back to email app.
  812.  * PARAMETERS
  813.  *  void
  814.  * RETURNS
  815.  *  void
  816.  *****************************************************************************/
  817. void mmi_phb_email_choose_entry(void)
  818. {
  819.     /*----------------------------------------------------------------*/
  820.     /* Local Variables                                                */
  821.     /*----------------------------------------------------------------*/
  822.     S16 pError;
  823.     U16 store_index;
  824.     /*----------------------------------------------------------------*/
  825.     /* Code Body                                                      */
  826.     /*----------------------------------------------------------------*/
  827.     store_index = g_phb_cntx.active_index_second;
  828.     /* Clear buffer */
  829.     memset(pbEmailAddress, 0, 2);
  830. #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  831.     if (store_index < MAX_PB_PHONE_ENTRIES) /* in NVRAM */
  832.     {
  833.         ReadRecord(
  834.             NVRAM_EF_PHB_FIELDS_LID,
  835.             (U16) (store_index + 1),
  836.             (void*)&PhoneBookOptionalFields,
  837.             OPTIONAL_FIELDS_RECORD_SIZE,
  838.             &pError);
  839.         AnsiiToUnicodeString(pbEmailAddress, (S8*) PhoneBookOptionalFields.emailAddress);
  840.     }
  841. #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  842. #ifdef __MMI_PHB_USIM_FIELD__
  843.     if (store_index >= MAX_PB_PHONE_ENTRIES)    /* in USIM */
  844.     {
  845.         AnsiiToUnicodeString((S8*) pbEmailAddress, (S8*) phb_email[store_index - MAX_PB_PHONE_ENTRIES].email_address);
  846.     }
  847. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  848.     /* Send back to email app. */
  849.     mmi_email_phb_get_addr_callback((S8*) PhoneBook[store_index].alpha_id.name, (S8*) pbEmailAddress);
  850. }
  851. /*****************************************************************************
  852.  * FUNCTION
  853.  *  mmi_phb_email_save_entry_to_phb
  854.  * DESCRIPTION
  855.  *  save name and email to phonebook as a new entry
  856.  * PARAMETERS
  857.  *  ucs2_name       [IN]         Input email string pointer
  858.  *  ucs2_email      [IN]         Input name string pointer
  859.  * RETURNS
  860.  *  void
  861.  *****************************************************************************/
  862. void mmi_phb_email_save_entry_to_phb(S8 *ucs2_name, S8 *ucs2_email)
  863. {
  864.     /*----------------------------------------------------------------*/
  865.     /* Local Variables                                                */
  866.     /*----------------------------------------------------------------*/
  867.     /*----------------------------------------------------------------*/
  868.     /* Code Body                                                      */
  869.     /*----------------------------------------------------------------*/
  870.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_email_save_entry_to_phb.>n", __FILE__,
  871.                          __LINE__));
  872. #ifdef __SYNCML_SUPPORT__
  873.     if (mmi_syncml_is_phb_sync_now())
  874.     {
  875.         mmi_phb_entry_not_ready(STR_ID_SYNC_PLEASE_WAIT);
  876.     }
  877.     else
  878. #endif /* __SYNCML_SUPPORT__ */
  879.     if (g_phb_cntx.phb_ready && !g_phb_cntx.processing)
  880.     {
  881.         if (PhoneBookEntryCount == g_phb_cntx.sim_total + g_phb_cntx.phone_total)
  882.         {
  883.             DisplayPopup((PU8) GetString(STR_PBOOK_FULL_MSG), IMG_GLOBAL_ERROR, FALSE, PHB_NOTIFY_TIMEOUT, ERROR_TONE);
  884.         }
  885.         else
  886.         {
  887.             /* Ensure the length will not exceed max length and phonebook buffer. */
  888.             memset((ucs2_email + MAX_PB_EMAIL_LENGTH * ENCODING_LENGTH), 0, 2);
  889.             /* Clear other field */
  890.             mmi_phb_util_clear_buffer(TRUE);
  891.             /* Bring in data and enter save entry screen. */
  892.             g_phb_cntx.set_done_flag = 1;
  893.             pfnUnicodeStrcpy(pbName, ucs2_name);
  894.             if (GetUCS2Flag(pbName))
  895.             {
  896.                 memset(pbName + (((MAX_PB_NAME_LENGTH - 1) / 2) * 2), 0, 2);
  897.             }
  898.             else
  899.             {
  900.                 memset((pbName + MAX_PB_NAME_LENGTH * ENCODING_LENGTH), 0, 2);
  901.             }
  902.             pfnUnicodeStrcpy(pbEmailAddress, ucs2_email);
  903.             mmi_phb_clear_old_history();
  904.             mmi_phb_entry_op_add_choose_storage();
  905.         }
  906.     }
  907.     else
  908.     {
  909.         mmi_phb_entry_not_ready(STR_PROCESSING_PHONEBOOK);
  910.     }
  911. }
  912. #endif /* defined(__MMI_EMAIL__) */ 
  913. #if defined(MMS_SUPPORT)
  914. /*****************************************************************************
  915.  * FUNCTION
  916.  *  mmi_phb_entry_dummy_screen
  917.  * DESCRIPTION
  918.  *  
  919.  * PARAMETERS
  920.  *  void
  921.  * RETURNS
  922.  *  void
  923.  *****************************************************************************/
  924. void mmi_phb_entry_dummy_screen(void)
  925. {
  926.     /*----------------------------------------------------------------*/
  927.     /* Local Variables                                                */
  928.     /*----------------------------------------------------------------*/
  929.     /*----------------------------------------------------------------*/
  930.     /* Code Body                                                      */
  931.     /*----------------------------------------------------------------*/
  932. }
  933. /*****************************************************************************
  934.  * FUNCTION
  935.  *  mmi_phb_email_save_entry_to_phb_from_jmms
  936.  * DESCRIPTION
  937.  *  save the email entry from JMMS
  938.  * PARAMETERS
  939.  *  ucs2_email      [IN]         Input email string pointer
  940.  * RETURNS
  941.  *  void
  942.  *****************************************************************************/
  943. void mmi_phb_email_save_entry_to_phb_from_jmms(S8 *ucs2_email)
  944. {
  945.     /*----------------------------------------------------------------*/
  946.     /* Local Variables                                                */
  947.     /*----------------------------------------------------------------*/
  948.     /*----------------------------------------------------------------*/
  949.     /* Code Body                                                      */
  950.     /*----------------------------------------------------------------*/
  951.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_email_save_entry_to_phb.>n", __FILE__,
  952.                          __LINE__));
  953.     if (!g_phb_cntx.phb_ready || g_phb_cntx.processing)
  954.     {
  955.         mmi_phb_entry_not_ready(STR_PROCESSING_PHONEBOOK);
  956.     }
  957. #ifdef __MMI_PHB_USIM_FIELD__
  958.     else if (g_phb_cntx.is_usim && g_phb_cntx.usim_ready_stage != MMI_PHB_USIM_READY)
  959.     {
  960.         mmi_phb_entry_not_ready(STR_ID_PHB_PROCESSING_USIM);
  961.     }
  962. #endif /* __MMI_PHB_USIM_FIELD__ */
  963. #ifdef __SYNCML_SUPPORT__
  964.     else if (mmi_syncml_is_phb_sync_now())
  965.     {
  966.         mmi_phb_entry_not_ready(STR_ID_SYNC_PLEASE_WAIT);
  967.     }
  968. #endif /* __SYNCML_SUPPORT__ */
  969.     else
  970.     {
  971.         if (PhoneBookEntryCount == g_phb_cntx.sim_total + g_phb_cntx.phone_total)
  972.         {
  973.             DisplayPopup((PU8) GetString(STR_PBOOK_FULL_MSG), IMG_GLOBAL_ERROR, FALSE, PHB_NOTIFY_TIMEOUT, ERROR_TONE);
  974.         }
  975.         else
  976.         {
  977.             /* Ensure the length will not exceed phonebook buffer. */
  978.             if(pfnUnicodeStrlen((S8*)ucs2_email) > MAX_PB_EMAIL_LENGTH)
  979.             {
  980.                 memset((ucs2_email + MAX_PB_EMAIL_LENGTH * ENCODING_LENGTH), 0, 2);
  981.             }
  982.             /* Clear other field */
  983.             mmi_phb_util_clear_buffer(TRUE);
  984.             /* Bring in data and enter save entry screen. */
  985.             g_phb_cntx.set_done_flag = 1;
  986.             pfnUnicodeStrcpy(pbEmailAddress, ucs2_email);
  987.             mmi_phb_clear_old_history();
  988.             /* adding here */
  989.             g_phb_cntx.selected_storage = MMI_NVRAM;
  990.             if (g_phb_cntx.phone_used >= g_phb_cntx.phone_total)
  991.             {
  992.                 DisplayPopup(
  993.                     (PU8) GetString(STR_PBOOK_FULL_MSG),
  994.                     IMG_GLOBAL_ERROR,
  995.                     FALSE,
  996.                     PHB_NOTIFY_TIMEOUT,
  997.                     ERROR_TONE);
  998.             }
  999.             else
  1000.             {
  1001.                 EntryNewScreen(SCR_STORAGE_LOCATION_MENU, NULL, mmi_phb_entry_dummy_screen, NULL);
  1002.                 mmi_phb_entry_op_add_entry();
  1003.             }
  1004.         }
  1005.     }
  1006. }
  1007. #endif /* defined(MMS_SUPPORT) */ 
  1008. #define MMI_PHB_INTERFACE_FOR_VRSD_DIAL
  1009. #if defined(__MMI_VRSD_DIAL__)
  1010. /*****************************************************************************
  1011.  * FUNCTION
  1012.  *  mmi_phb_vrsddial_enter_tag_list
  1013.  * DESCRIPTION
  1014.  *  Phonebook list interface for voice dial application.
  1015.  * PARAMETERS
  1016.  *  void
  1017.  * RETURNS
  1018.  *  void
  1019.  *****************************************************************************/
  1020. void mmi_phb_vrsddial_enter_tag_list(void)
  1021. {
  1022.     /*----------------------------------------------------------------*/
  1023.     /* Local Variables                                                */
  1024.     /*----------------------------------------------------------------*/
  1025.     U16 i, j;
  1026.     U16 EntryCount = 0;
  1027.     U16 store_index;
  1028.     vrsd_tag_struct tag_list[MMI_VRSD_MAX_TAG];
  1029.     S16 pError;
  1030.     /*----------------------------------------------------------------*/
  1031.     /* Code Body                                                      */
  1032.     /*----------------------------------------------------------------*/
  1033. #ifdef __SYNCML_SUPPORT__
  1034.     if (mmi_syncml_is_phb_sync_now())
  1035.     {
  1036.         mmi_phb_entry_not_ready(STR_ID_SYNC_PLEASE_WAIT);
  1037.     }
  1038.     else
  1039. #endif /* __SYNCML_SUPPORT__ */
  1040.     if (g_phb_cntx.phb_ready && !g_phb_cntx.processing)
  1041.     {
  1042.         /* Allocate buffer for phonebook memeber list filter */
  1043.         mmi_phb_list_allocate_filter();
  1044.         /* Read voice tag list from NVRAM */
  1045.         ReadRecord(
  1046.             NVRAM_EF_VRSD_TAG_LID,
  1047.             MMI_VRSD_GROUP_ALL,
  1048.             (void*)tag_list,
  1049.             MMI_VRSD_MAX_TAG * sizeof(vrsd_tag_struct),
  1050.             &pError);
  1051.         /* Find out entry with tag and put it into filter list */
  1052.         for (i = 0; i < PhoneBookEntryCount; i++)
  1053.         {
  1054.             store_index = g_phb_name_index[i];
  1055.             for (j = 0; j < MMI_VRSD_MAX_TAG; j++)
  1056.             {
  1057.                 if ((tag_list[j].appref_id < 0xffff) && (tag_list[j].app_id == MMI_VRSD_APP_DIAL) &&
  1058.                     (tag_list[j].appref_id == store_index))
  1059.                 {
  1060.                     g_phb_cntx.list_filter[EntryCount] = store_index;
  1061.                     EntryCount++;
  1062.                     break;
  1063.                 }
  1064.             }
  1065.         }
  1066.         /* If voice tag exists, enter phonebook list */
  1067.         if (EntryCount)
  1068.         {
  1069.             g_phb_cntx.highlight_entry = 0;
  1070.             phbListView = MMI_PHB_LIST_FOR_VR;
  1071.             mmi_phb_entry_list(
  1072.                 EntryCount,                             /* Total Entry */
  1073.                 STR_ID_VRSD_DIAL,                       /* Title String */
  1074.                 IMG_ID_VRSD_APP,                        /* Title Image */
  1075.                 STR_GLOBAL_OPTIONS,                     /* LSK */
  1076.                 IMG_GLOBAL_OPTIONS,                     /* LSK */
  1077.                 mmi_phb_vrsddial_get_tag_list_index,    /* Highlight Callback */
  1078.                 mmi_vrsddial_main_menu_all_option,      /* LSK Callback */
  1079.                 NULL,                                   /* SEND Key Callback */
  1080.                 mmi_phb_filter_list_get_item,           /* List Callback */
  1081.                 mmi_phb_filter_list_get_hint,           /* Hint Callback */
  1082.                 mmi_phb_vrsddial_enter_tag_list,        /* Re-Entry Callback */
  1083.                 FALSE,                                  /* Alpha Index */
  1084.                 TRUE);                                  /* Right Arrow Key */
  1085.         }
  1086.         else    /* No voice Tag exists, Go to menu directly. */
  1087.         {
  1088.             mmi_vrsddial_entry_empty_list();
  1089.             mmi_phb_list_free_filter();
  1090.         }
  1091.     }
  1092.     else
  1093.     {
  1094.         mmi_phb_entry_not_ready(STR_PROCESSING_PHONEBOOK);
  1095.     }
  1096. }
  1097. /*****************************************************************************
  1098.  * FUNCTION
  1099.  *  mmi_phb_vrsddial_get_tag_list_index
  1100.  * DESCRIPTION
  1101.  *  This function is just for template.
  1102.  * PARAMETERS
  1103.  *  nIndex      [IN]            
  1104.  * RETURNS
  1105.  *  void
  1106.  *****************************************************************************/
  1107. void mmi_phb_vrsddial_get_tag_list_index(S32 nIndex)
  1108. {
  1109.     /*----------------------------------------------------------------*/
  1110.     /* Local Variables                                                */
  1111.     /*----------------------------------------------------------------*/
  1112.     /*----------------------------------------------------------------*/
  1113.     /* Code Body                                                      */
  1114.     /*----------------------------------------------------------------*/
  1115.     g_phb_cntx.active_index = g_phb_cntx.list_filter[nIndex];   /* This is store_index in filter list */
  1116.     StopTimer(VRSD_DIAL_PLAYBACK_TIMER);
  1117.     StartTimer(VRSD_DIAL_PLAYBACK_TIMER, MMI_VRSD_PLAY_TAG_DELAY, mmi_phb_vrsddial_playback_by_store_index);
  1118. }
  1119. /*****************************************************************************
  1120.  * FUNCTION
  1121.  *  mmi_phb_vrsddial_playback_by_store_index
  1122.  * DESCRIPTION
  1123.  *  This function is just for template.
  1124.  * PARAMETERS
  1125.  *  void
  1126.  * RETURNS
  1127.  *  void
  1128.  *****************************************************************************/
  1129. void mmi_phb_vrsddial_playback_by_store_index(void)
  1130. {
  1131.     /*----------------------------------------------------------------*/
  1132.     /* Local Variables                                                */
  1133.     /*----------------------------------------------------------------*/
  1134.     U16 tag_id;
  1135.     /*----------------------------------------------------------------*/
  1136.     /* Code Body                                                      */
  1137.     /*----------------------------------------------------------------*/
  1138.     tag_id = mmi_vrsd_util_get_tag_id(MMI_VRSD_APP_DIAL, g_phb_cntx.active_index);
  1139.     mmi_vrsd_playback_req(tag_id, NULL);
  1140. }
  1141. /*****************************************************************************
  1142.  * FUNCTION
  1143.  *  mmi_phb_vrsddial_enter_no_tag_list
  1144.  * DESCRIPTION
  1145.  *  Phonebook list interface for voice dial application.
  1146.  * PARAMETERS
  1147.  *  void
  1148.  * RETURNS
  1149.  *  void
  1150.  *****************************************************************************/
  1151. void mmi_phb_vrsddial_enter_no_tag_list(void)
  1152. {
  1153.     /*----------------------------------------------------------------*/
  1154.     /* Local Variables                                                */
  1155.     /*----------------------------------------------------------------*/
  1156.     U16 i, j;
  1157.     U16 EntryCount = 0;
  1158.     U16 store_index;
  1159.     vrsd_tag_struct tag_list[MMI_VRSD_MAX_TAG];
  1160.     S16 pError;
  1161.     BOOL has_tag;
  1162.     /*----------------------------------------------------------------*/
  1163.     /* Code Body                                                      */
  1164.     /*----------------------------------------------------------------*/
  1165. #ifdef __SYNCML_SUPPORT__
  1166.     if (mmi_syncml_is_phb_sync_now())
  1167.     {
  1168.         mmi_phb_entry_not_ready(STR_ID_SYNC_PLEASE_WAIT);
  1169.     }
  1170.     else
  1171. #endif /* __SYNCML_SUPPORT__ */
  1172.     if (g_phb_cntx.phb_ready && !g_phb_cntx.processing)
  1173.     {
  1174.         /* Allocate buffer for phonebook memeber list filter */
  1175.         mmi_phb_list_allocate_filter();
  1176.         /* Read voice tag list from NVRAM */
  1177.         ReadRecord(
  1178.             NVRAM_EF_VRSD_TAG_LID,
  1179.             MMI_VRSD_GROUP_ALL,
  1180.             (void*)tag_list,
  1181.             MMI_VRSD_MAX_TAG * sizeof(vrsd_tag_struct),
  1182.             &pError);
  1183.         /* Find out entry without voice tag and put it into filter list */
  1184.         for (i = 0; i < PhoneBookEntryCount; i++)
  1185.         {
  1186.             store_index = g_phb_name_index[i];
  1187.             has_tag = FALSE;
  1188.             for (j = 0; j < MMI_VRSD_MAX_TAG; j++)
  1189.             {
  1190.                 if ((tag_list[j].app_id == MMI_VRSD_APP_DIAL) && (tag_list[j].appref_id == store_index))
  1191.                 {
  1192.                     has_tag = TRUE;
  1193.                     break;
  1194.                 }
  1195.             }
  1196.             /* Add to list if the entry has no tag. */
  1197.             if (!has_tag)
  1198.             {
  1199.                 g_phb_cntx.list_filter[EntryCount] = store_index;
  1200.                 EntryCount++;
  1201.             }
  1202.         }
  1203.         /* If voice tag exists, enter phonebook list */
  1204.         if (EntryCount)
  1205.         {
  1206.             g_phb_cntx.highlight_entry = 0;
  1207.             phbListView = MMI_PHB_LIST_FOR_VR;
  1208.             mmi_phb_entry_list(
  1209.                 EntryCount,                                 /* Total Entry */
  1210.                 STR_ID_VRSD_DIAL,                           /* Title String */
  1211.                 IMG_ID_VRSD_APP,                            /* Title Image */
  1212.                 STR_GLOBAL_OK,                              /* LSK */
  1213.                 IMG_GLOBAL_OK,                              /* LSK */
  1214.                 mmi_phb_get_index_by_store_location_second, /* Highlight Callback */
  1215.                 mmi_vrsddial_add_tag_from_list,             /* LSK Callback */
  1216.                 NULL,                                       /* SEND Key Callback */
  1217.                 mmi_phb_filter_list_get_item,               /* List Callback */
  1218.                 mmi_phb_filter_list_get_hint,               /* Hint Callback */
  1219.                 mmi_phb_vrsddial_enter_no_tag_list,         /* Re-Entry Callback */
  1220.                 FALSE,                                      /* Alpha Index */
  1221.                 TRUE);                                      /* Right Arrow Key */
  1222.         }
  1223.         else    /* All Entries has voice tag. */
  1224.         {
  1225.             DisplayPopup(
  1226.                 (PU8) GetString(STR_ID_PHB_NO_ENTRY_TO_SELECT),
  1227.                 IMG_GLOBAL_EMPTY,
  1228.                 TRUE,
  1229.                 PHB_NOTIFY_TIMEOUT,
  1230.                 EMPTY_LIST_TONE);
  1231.             mmi_phb_list_free_filter();
  1232.         }
  1233.     }
  1234.     else
  1235.     {
  1236.         mmi_phb_entry_not_ready(STR_PROCESSING_PHONEBOOK);
  1237.     }
  1238. }
  1239. /*****************************************************************************
  1240.  * FUNCTION
  1241.  *  mmi_phb_highlight_op_voice_dial
  1242.  * DESCRIPTION
  1243.  *  This function is just for template.
  1244.  * PARAMETERS
  1245.  *  void
  1246.  * RETURNS
  1247.  *  viod
  1248.  *****************************************************************************/
  1249. void mmi_phb_highlight_op_voice_dial(void)
  1250. {
  1251.     /*----------------------------------------------------------------*/
  1252.     /* Local Variables                                                */
  1253.     /*----------------------------------------------------------------*/
  1254.     /*----------------------------------------------------------------*/
  1255.     /* Code Body                                                      */
  1256.     /*----------------------------------------------------------------*/
  1257.     SetLeftSoftkeyFunction(mmi_vrsddial_phb_main_menu_pre_entry, KEY_EVENT_UP);
  1258.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1259.     SetKeyHandler(mmi_vrsddial_phb_main_menu_pre_entry, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1260.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1261. }
  1262. /*****************************************************************************
  1263.  * FUNCTION
  1264.  *  mmi_phb_vrsddial_auto_dial
  1265.  * DESCRIPTION
  1266.  *  This function is just for template.
  1267.  * PARAMETERS
  1268.  *  store_index     [IN]            
  1269.  * RETURNS
  1270.  *  void
  1271.  *****************************************************************************/
  1272. void mmi_phb_vrsddial_auto_dial(U16 store_index)
  1273. {
  1274.     /*----------------------------------------------------------------*/
  1275.     /* Local Variables                                                */
  1276.     /*----------------------------------------------------------------*/
  1277.     U16 i;
  1278.     /*----------------------------------------------------------------*/
  1279.     /* Code Body                                                      */
  1280.     /*----------------------------------------------------------------*/
  1281.     g_phb_cntx.active_index = 0;
  1282.     for (i = 0; i < PhoneBookEntryCount; i++)
  1283.     {
  1284.         if (g_phb_name_index[i] == store_index)
  1285.         {
  1286.             g_phb_cntx.active_index = i;
  1287.             break;
  1288.         }
  1289.     }
  1290.     mmi_phb_choose_number_normal();
  1291. }
  1292. #endif /* defined(__MMI_VRSD_DIAL__) */ 
  1293. #define MMI_PHB_INTERFACE_FOR_VRSI
  1294. #if defined(__MMI_VRSI__) && defined(__MMI_VRSI_TRAIN_TAG__)
  1295. /*****************************************************************************
  1296.  * FUNCTION
  1297.  *  mmi_phb_vrsi_list_get_item
  1298.  * DESCRIPTION
  1299.  *  This function is just for template.
  1300.  * PARAMETERS
  1301.  *  void
  1302.  * RETURNS
  1303.  *  void
  1304.  *****************************************************************************/
  1305. pBOOL mmi_phb_vrsi_list_get_item(S32 item_index, UI_string_type str_buff, PU8 *img_buff_p, U8 str_img_mask)
  1306. {
  1307.     /*----------------------------------------------------------------*/
  1308.     /* Local Variables                                                */
  1309.     /*----------------------------------------------------------------*/
  1310.     U16 store_index;
  1311.     /*----------------------------------------------------------------*/
  1312.     /* Code Body                                                      */
  1313.     /*----------------------------------------------------------------*/
  1314.     if ((item_index < 0) || (item_index >= PhoneBookEntryCount))
  1315.     {
  1316.         return FALSE;
  1317.     }
  1318.     store_index = g_phb_name_index[item_index];
  1319.     if (pfnUnicodeStrlen((S8*) PhoneBook[store_index].alpha_id.name))
  1320.     {
  1321.         pfnUnicodeStrcpy((S8*) str_buff, (S8*) PhoneBook[store_index].alpha_id.name);
  1322.     }
  1323.     else
  1324.     {
  1325.         mmi_phb_convert_get_ucs2_number((S8*) str_buff, store_index);
  1326.     }
  1327.     /* Check if phonebook item has VRSD tag */
  1328.     if (mmi_vrsi_train_util_get_loc_in_list(MMI_VRSI_APP_DIAL, store_index, g_phb_vrsi_tag_list) != 0xff)
  1329.     {
  1330.         *img_buff_p = get_image(IMG_ID_VRSI_APP);
  1331.     }
  1332.     else
  1333.     {
  1334.         if (store_index >= MAX_PB_PHONE_ENTRIES)
  1335.         {
  1336.             *img_buff_p = get_image(IMG_STORAGE_SIM);
  1337.         }
  1338.         else
  1339.         {
  1340.             *img_buff_p = get_image(IMG_STORAGE_HANDSET);
  1341.         }
  1342.     }
  1343.     return TRUE;
  1344. }
  1345. /*****************************************************************************
  1346.  * FUNCTION
  1347.  *  mmi_phb_vrsi_pre_entry_list
  1348.  * DESCRIPTION
  1349.  *  This function is just for template.
  1350.  * PARAMETERS
  1351.  *  void
  1352.  * RETURNS
  1353.  *  void
  1354.  *****************************************************************************/
  1355. void mmi_phb_vrsi_pre_entry_list(void)
  1356. {
  1357.     /*----------------------------------------------------------------*/
  1358.     /* Local Variables                                                */
  1359.     /*----------------------------------------------------------------*/
  1360.     S16 pError;
  1361.     /*----------------------------------------------------------------*/
  1362.     /* Code Body                                                      */
  1363.     /*----------------------------------------------------------------*/
  1364.     g_phb_cntx.highlight_entry = 0;
  1365.     phbListView = MMI_PHB_LIST_FOR_VR;
  1366.     /* Allocate memory for list to temporarily store vrsi tag list */
  1367.     g_phb_vrsi_tag_list = OslMalloc(MMI_VRSI_MAX_SD_TAG * sizeof(vrsi_sd_tag_struct));
  1368.     ReadRecord(NVRAM_EF_VRSI_TAG_LID, 1, (void*)g_phb_vrsi_tag_list, MMI_VRSI_MAX_SD_TAG * sizeof(vrsi_sd_tag_struct), &pError);
  1369.     mmi_phb_entry_list(
  1370.         PhoneBookEntryCount,                /* Total Entry */
  1371.         STR_ID_VRSI_APP,                    /* Title String */
  1372.         IMG_ID_VRSI_APP,                    /* Title Image */
  1373.         STR_GLOBAL_OK,                      /* LSK */
  1374.         IMG_GLOBAL_OK,                      /* LSK */
  1375.         mmi_phb_get_index_second_level,     /* Highlight Callback */
  1376.         mmi_phb_vrsi_entry_list_callback,   /* LSK Callback */
  1377.         NULL,                               /* SEND Key Callback */
  1378.         mmi_phb_vrsi_list_get_item,         /* List Callback */
  1379.         mmi_phb_list_get_hint,              /* Hint Callback */
  1380.         mmi_phb_vrsi_pre_entry_list,        /* Re-Entry Callback */
  1381.         TRUE,                               /* Alpha Index */
  1382.         TRUE);                              /* Right Arrow Key */
  1383. }
  1384. /*****************************************************************************
  1385.  * FUNCTION
  1386.  *  mmi_phb_vrsi_exit_entry_list
  1387.  * DESCRIPTION
  1388.  *  
  1389.  * PARAMETERS
  1390.  *  void
  1391.  * RETURNS
  1392.  *  void
  1393.  *****************************************************************************/
  1394. void mmi_phb_vrsi_exit_entry_list(void)
  1395. {
  1396.     /*----------------------------------------------------------------*/
  1397.     /* Local Variables                                                */
  1398.     /*----------------------------------------------------------------*/
  1399.     /*----------------------------------------------------------------*/
  1400.     /* Code Body                                                      */
  1401.     /*----------------------------------------------------------------*/
  1402.     if(g_phb_vrsi_tag_list)
  1403.     {
  1404.         OslMfree(g_phb_vrsi_tag_list);
  1405.         g_phb_vrsi_tag_list = NULL;
  1406.     }
  1407. }
  1408. /*****************************************************************************
  1409.  * FUNCTION
  1410.  *  mmi_phb_vrsi_entry_list_callback
  1411.  * DESCRIPTION
  1412.  *  This function is just for template.
  1413.  * PARAMETERS
  1414.  *  void
  1415.  * RETURNS
  1416.  *  void
  1417.  *****************************************************************************/
  1418. void mmi_phb_vrsi_entry_list_callback(void)
  1419. {
  1420.     /*----------------------------------------------------------------*/
  1421.     /* Local Variables                                                */
  1422.     /*----------------------------------------------------------------*/
  1423.     U16 store_index;
  1424.     /*----------------------------------------------------------------*/
  1425.     /* Code Body                                                      */
  1426.     /*----------------------------------------------------------------*/
  1427.     store_index = g_phb_name_index[g_phb_cntx.active_index_second];
  1428.     mmi_vrsi_ndial_train_list_callback(store_index);
  1429. }
  1430. #endif /* defined(__MMI_VRSI__) && defined(__MMI_VRSI_TRAIN_TAG__) */ 
  1431. #ifdef __SYNCML_SUPPORT__
  1432. /*****************************************************************************
  1433.  * FUNCTION
  1434.  *  mmi_phb_get_phone_index_arrary
  1435.  * DESCRIPTION
  1436.  *  
  1437.  * PARAMETERS
  1438.  *  index_array       [OUT]        
  1439.  * RETURNS
  1440.  *  U16
  1441.  *****************************************************************************/
  1442. U16 mmi_phb_get_phone_index_arrary(U16* index_array)
  1443. {
  1444.     /*----------------------------------------------------------------*/
  1445.     /* Local Variables                                                */
  1446.     /*----------------------------------------------------------------*/
  1447.     U16 i;
  1448.     U16 array_count = 0;
  1449.     U16 store_index;
  1450.     
  1451.     /*----------------------------------------------------------------*/
  1452.     /* Code Body                                                      */
  1453.     /*----------------------------------------------------------------*/
  1454.     if (!g_phb_cntx.phb_ready || g_phb_cntx.processing)
  1455.     {
  1456.         return 0xFFFF;
  1457.     }
  1458.     if (index_array != NULL)
  1459.     {
  1460.         for (i = 0; i < PhoneBookEntryCount; i++)
  1461.         {
  1462.             store_index = g_phb_name_index[i];
  1463.             if (store_index < MAX_PB_PHONE_ENTRIES)
  1464.             {
  1465.                 index_array[array_count] = store_index;
  1466.                 array_count++;
  1467.             }
  1468.         }
  1469.     }
  1470.     return g_phb_cntx.phone_used;
  1471. }
  1472. /*****************************************************************************
  1473.  * FUNCTION
  1474.  *  mmi_phb_sync_vcard
  1475.  * DESCRIPTION
  1476.  *  
  1477.  * PARAMETERS
  1478.  *  path        [IN]         
  1479.  *  index       [IN]        
  1480.  * RETURNS
  1481.  *  
  1482.  *****************************************************************************/
  1483. void mmi_phb_sync_vcard(U8 action, S8 *path, U16 index)
  1484. {
  1485.     /*----------------------------------------------------------------*/
  1486.     /* Local Variables                                                */
  1487.     /*----------------------------------------------------------------*/
  1488.     FS_HANDLE fh;
  1489.     U8 error_code = VCARD_PARSE_NO_ERROR;
  1490.     S16 pError;
  1491.     S8 number_buff[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];
  1492.     S8 b_day[9];    /* Format: yyyymmdd */
  1493.     S32 get_result;
  1494.     
  1495.     /*----------------------------------------------------------------*/
  1496.     /* Code Body                                                      */
  1497.     /*----------------------------------------------------------------*/
  1498.     if (action != MMI_PHB_VCARD_DELETE && path == NULL)
  1499.     {
  1500.         mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_ERROR, index);
  1501.         return;
  1502.     }    
  1503.     if ((action != MMI_PHB_VCARD_ADD) && index >= MAX_PB_PHONE_ENTRIES)
  1504.     {
  1505.         mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_OUT_OF_INDEX, index);        
  1506.         return;
  1507.     }
  1508.     if (!g_phb_cntx.phb_ready || g_phb_cntx.processing)
  1509.     {
  1510.         mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_NOT_READY, index);
  1511.         return;
  1512.     }
  1513. #ifdef __MMI_PHB_USIM_FIELD__
  1514.     if (g_phb_cntx.is_usim && g_phb_cntx.usim_ready_stage != MMI_PHB_USIM_READY)
  1515.     {
  1516.         mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_NOT_READY, index);
  1517.         return;
  1518.     }
  1519. #endif /* __MMI_PHB_USIM_FIELD__ */    
  1520.     if (action == MMI_PHB_VCARD_READ)
  1521.     {
  1522.         /* Mobile Number */
  1523.         if (PhoneBook[index].tel.type == MMI_CSMCC_INTERNATIONAL_ADDR)
  1524.         {
  1525.             number_buff[0] = '+';
  1526.             mmi_phb_convert_to_digit((U8*) number_buff + 1, PhoneBook[index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  1527.         }
  1528.         else
  1529.         {
  1530.             mmi_phb_convert_to_digit((U8*) number_buff, PhoneBook[index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  1531.         }
  1532.     #if defined(__MMI_PHB_BIRTHDAY_FIELD__)
  1533.         mmi_vcard_get_bday_to_buff(index, (S8*) b_day);
  1534.     #endif /* defined(__MMI_PHB_BIRTHDAY_FIELD__) */ 
  1535.     #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  1536.         ReadRecord(
  1537.             NVRAM_EF_PHB_FIELDS_LID,
  1538.             (U16) (index + 1),
  1539.             (void*)&PhoneBookOptionalFields,
  1540.             OPTIONAL_FIELDS_RECORD_SIZE,
  1541.             &pError);
  1542.     #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  1543.         get_result = mmi_vcard_writer_v21_to_file(path, (S8*) PhoneBook[index].alpha_id.name, (S8*) number_buff,
  1544.                                 #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  1545.                                             (S8*) PhoneBookOptionalFields.homeNumber,
  1546.                                             (S8*) PhoneBookOptionalFields.officeNumber,
  1547.                                             (S8*) PhoneBookOptionalFields.faxNumber,
  1548.                                             (S8*) PhoneBookOptionalFields.emailAddress,
  1549.                                             (S8*) PhoneBookOptionalFields.companyName,
  1550.                                 #else /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  1551.                                             NULL, NULL, NULL, NULL, NULL,
  1552.                                 #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  1553.                                 #if defined(__MMI_PHB_BIRTHDAY_FIELD__)
  1554.                                             b_day,
  1555.                                 #else 
  1556.                                             NULL,
  1557.                                 #endif 
  1558.                                             NULL, NULL, NULL);
  1559.         if (get_result != VOBJ_ERR_NO_ERROR)
  1560.         {
  1561.             mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_ERROR, index);
  1562.         }
  1563.         else
  1564.         {
  1565.             mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_SUCCESS, index);
  1566.         }
  1567.         return;
  1568.     }
  1569.     else if (action == MMI_PHB_VCARD_ADD || action == MMI_PHB_VCARD_UPDATE)
  1570.     {
  1571.         if (action == MMI_PHB_VCARD_ADD)
  1572.         {
  1573.             if (g_phb_cntx.phone_used >= g_phb_cntx.phone_total) /* NVRAM Only */
  1574.             {
  1575.                 mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_STORAGE_FULL, index);
  1576.                 return;
  1577.             }
  1578.             g_phb_cntx.selected_storage = MMI_NVRAM;
  1579.         }
  1580.         fh = FS_Open((U16*) path, FS_READ_ONLY);
  1581.         if (fh <= 0)
  1582.         {
  1583.             mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_OPEN_FILE_ERROR, index);
  1584.             return;
  1585.         }
  1586.         mmi_phb_util_clear_buffer(TRUE);  /* Clear all phonebook vcard temp buffer before parsing */
  1587.         error_code = mmi_vcard_reader_parse_line(fh);
  1588.         FS_Close(fh);
  1589.     }
  1590.     
  1591.     if (action == MMI_PHB_VCARD_DELETE)
  1592.     {
  1593.         if (mmi_phb_util_check_entry_exist(index))
  1594.         {
  1595.             g_phb_enter_from = MMI_PHB_ENTER_FROM_SYNCML;
  1596.             g_phb_cntx.active_index = index;
  1597.             mmi_phb_op_delete_entry_req();
  1598.         }
  1599.         else /* Entry already deleted by handset user (Client) */
  1600.         {
  1601.             mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_SUCCESS, index);
  1602.         }
  1603.         return;
  1604.     }
  1605.     
  1606.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_sync_vcard. error_code: %d>n",
  1607.                          __FILE__, __LINE__, error_code));
  1608.     /*  Check if parse and validation ok. */
  1609.     if (error_code != VCARD_PARSE_NO_ERROR || !mmi_phb_op_check_pre_save(FALSE))
  1610.     {
  1611.         mmi_syncml_phb_sync_rsp(MMI_PHB_SYNC_ERROR, index);
  1612.         return;
  1613.     }
  1614.     if (action == MMI_PHB_VCARD_ADD)
  1615.     {
  1616.         g_phb_enter_from = MMI_PHB_ENTER_FROM_SYNCML;
  1617.         mmi_phb_op_add_entry_req();
  1618.     }
  1619.     else if (action == MMI_PHB_VCARD_UPDATE)
  1620.     {
  1621.         g_phb_enter_from = MMI_PHB_ENTER_FROM_SYNCML;
  1622.         g_phb_cntx.active_index = index;
  1623.         mmi_phb_op_edit_entry_req();
  1624.     }
  1625. }
  1626. #endif /* __SYNCML_SUPPORT__ */
  1627. #ifdef __MMI_BIRTHDAY_REMINDER__
  1628. /*****************************************************************************
  1629.  * FUNCTION
  1630.  *  mmi_phb_get_name_number
  1631.  * DESCRIPTION
  1632.  *  check if an entry exists
  1633.  * PARAMETERS
  1634.  *  store_index     [IN]        The store location id of the entry
  1635.  *  out_name        [OUT]       The name of the phonebook entry (UCS2)
  1636.  *  out_number      [OUT]       The default mobile number of the entry (ASCII)
  1637.  * RETURNS
  1638.  *  TRUE if the location has the entry, else FALSE
  1639.  *****************************************************************************/
  1640. void mmi_phb_get_name_number(U16 store_index, U8* out_name, U8* out_number)
  1641. {
  1642.     /*----------------------------------------------------------------*/
  1643.     /* Local Variables                                                */
  1644.     /*----------------------------------------------------------------*/
  1645.     /*----------------------------------------------------------------*/
  1646.     /* Code Body                                                      */
  1647.     /*----------------------------------------------------------------*/
  1648.     pfnUnicodeStrcpy((S8*)out_name, (S8*) PhoneBook[store_index].alpha_id.name);
  1649.     if (PhoneBook[store_index].tel.type == MMI_CSMCC_INTERNATIONAL_ADDR)
  1650.     {
  1651.         out_number[0] = '+';
  1652.         mmi_phb_convert_to_digit((U8*) (out_number + 1), PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  1653.     }
  1654.     else
  1655.     {
  1656.         mmi_phb_convert_to_digit(out_number, PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  1657.     }
  1658. }
  1659. #endif /* __MMI_BIRTHDAY_REMINDER__ */
  1660. /* Convert function for phonebook numbers between BCD and ASCII format. */
  1661. #define MMI_PHB_GENERAL_UTIL
  1662. /*****************************************************************************
  1663.  * FUNCTION
  1664.  *  mmi_phb_util_check_entry_exist
  1665.  * DESCRIPTION
  1666.  *  check if an entry exists
  1667.  * PARAMETERS
  1668.  *  store_index     [IN]        The store location id of the entry
  1669.  * RETURNS
  1670.  *  TRUE if the location has the entry, else FALSE
  1671.  *****************************************************************************/
  1672. BOOL mmi_phb_util_check_entry_exist(U16 store_index)
  1673. {
  1674.     /*----------------------------------------------------------------*/
  1675.     /* Local Variables                                                */
  1676.     /*----------------------------------------------------------------*/
  1677.     U16 i;
  1678.     /*----------------------------------------------------------------*/
  1679.     /* Code Body                                                      */
  1680.     /*----------------------------------------------------------------*/
  1681.     for (i = 0; i < PhoneBookEntryCount; i++)
  1682.     {
  1683.         if (g_phb_name_index[i] == store_index)
  1684.         {
  1685.             return TRUE;
  1686.         }
  1687.     }
  1688.     return FALSE;
  1689. }
  1690. /*****************************************************************************
  1691.  * FUNCTION
  1692.  *  mmi_phb_util_check_additional_number_exist
  1693.  * DESCRIPTION
  1694.  *  check if any additional number exists
  1695.  * PARAMETERS
  1696.  *  store_index     [IN]        The store location id of the entry
  1697.  * RETURNS
  1698.  *  TRUE if the location has any additional number, else FALSE
  1699.  *****************************************************************************/
  1700. BOOL mmi_phb_util_check_additional_number_exist(U16 store_index)
  1701. {
  1702.     /*----------------------------------------------------------------*/
  1703.     /* Local Variables                                                */
  1704.     /*----------------------------------------------------------------*/
  1705.     /*----------------------------------------------------------------*/
  1706.     /* Code Body                                                      */
  1707.     /*----------------------------------------------------------------*/
  1708.     return ((PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_HOME) ||
  1709.             (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_OFFICE) ||
  1710.             (PhoneBook[store_index].field & MMI_PHB_ENTRY_FIELD_FAX));
  1711. }
  1712. /*****************************************************************************
  1713.  * FUNCTION
  1714.  *  mmi_phb_convert_to_bcd_get_byte
  1715.  * DESCRIPTION
  1716.  *  convert ASCII character to BCD
  1717.  * PARAMETERS
  1718.  *  digit       [IN]        Ascii character
  1719.  * RETURNS
  1720.  *  bcd character
  1721.  *****************************************************************************/
  1722. U8 mmi_phb_convert_to_bcd_get_byte(U8 digit)
  1723. {
  1724.     /*----------------------------------------------------------------*/
  1725.     /* Local Variables                                                */
  1726.     /*----------------------------------------------------------------*/
  1727.     U8 half_byte;
  1728.     /*----------------------------------------------------------------*/
  1729.     /* Code Body                                                      */
  1730.     /*----------------------------------------------------------------*/
  1731.     if (digit <= '9' && digit >= '0')
  1732.     {
  1733.         half_byte = digit - '0';
  1734.     }
  1735.     else
  1736.     {
  1737.         switch (digit)
  1738.         {
  1739.             case '*':
  1740.                 half_byte = 0x0a;
  1741.                 break;
  1742.             case '#':
  1743.                 half_byte = 0x0b;
  1744.                 break;
  1745.             case 'p':
  1746.             case 'P':
  1747.                 half_byte = 0x0c;
  1748.                 break;
  1749.             case 'w':
  1750.             case 'W':
  1751.                 half_byte = 0x0d;
  1752.                 break;
  1753.             case '+':
  1754.                 half_byte = 0x0e;
  1755.                 break;
  1756.             default:
  1757.                 half_byte = 0x0f;
  1758.                 break;
  1759.         }
  1760.     }
  1761.     return half_byte;
  1762. }
  1763. /*****************************************************************************
  1764.  * FUNCTION
  1765.  *  mmi_phb_convert_to_bcd
  1766.  * DESCRIPTION
  1767.  *  convert ASCII string to BCD. (If reaches max length, there will be no terminate '0x0f')
  1768.  * PARAMETERS
  1769.  *  dest                [IN/OUT]        An BCD encoding string.
  1770.  *  source              [IN]            An ASCII encoding string.
  1771.  *  max_dest_len        [IN]            The byte size of dest array.
  1772.  * RETURNS
  1773.  *  byte number after convert.
  1774.  *****************************************************************************/
  1775. U8 mmi_phb_convert_to_bcd(U8 *dest, U8 *source, U8 max_dest_len)
  1776. {
  1777.     /*----------------------------------------------------------------*/
  1778.     /* Local Variables                                                */
  1779.     /*----------------------------------------------------------------*/
  1780.     U8 i = 0;
  1781.     U8 lower_byte, upper_byte;
  1782.     /*----------------------------------------------------------------*/
  1783.     /* Code Body                                                      */
  1784.     /*----------------------------------------------------------------*/
  1785.     while (source[i] != '')
  1786.     {
  1787.         lower_byte = mmi_phb_convert_to_bcd_get_byte(source[i]);
  1788.         upper_byte = mmi_phb_convert_to_bcd_get_byte(source[i + 1]);
  1789.         if ((i >> 1) >= max_dest_len)
  1790.         {
  1791.             return (i >> 1);
  1792.         }
  1793.         *((U8*) dest + (i >> 1)) = (upper_byte << 4) + lower_byte;
  1794.         if (source[i + 1] == '')
  1795.         {
  1796.             if ((i >> 1) >= max_dest_len)
  1797.             {
  1798.                 return (i >> 1) + 1;
  1799.             }
  1800.             *((U8*) dest + (i >> 1)) |= 0xf0;
  1801.             return (i >> 1) + 1;
  1802.         }
  1803.         i += 2;
  1804.     }
  1805.     if ((i >> 1) >= max_dest_len)
  1806.     {
  1807.         return (i >> 1);
  1808.     }
  1809.     *((U8*) dest + (i >> 1)) = 0xff;
  1810.     return (i >> 1);
  1811. }
  1812. /*****************************************************************************
  1813.  * FUNCTION
  1814.  *  mmi_phb_convert_to_digit_get_byte
  1815.  * DESCRIPTION
  1816.  *  convert BCD character to ASCII
  1817.  * PARAMETERS
  1818.  *  bcd     [IN]        Bcd character
  1819.  * RETURNS
  1820.  *  ascii character
  1821.  *****************************************************************************/
  1822. U8 mmi_phb_convert_to_digit_get_byte(U8 bcd)
  1823. {
  1824.     /*----------------------------------------------------------------*/
  1825.     /* Local Variables                                                */
  1826.     /*----------------------------------------------------------------*/
  1827.     U8 digit;
  1828.     /*----------------------------------------------------------------*/
  1829.     /* Code Body                                                      */
  1830.     /*----------------------------------------------------------------*/
  1831.     if (bcd <= 9)
  1832.     {
  1833.         digit = bcd + '0';
  1834.     }
  1835.     else
  1836.     {
  1837.         switch (bcd)
  1838.         {
  1839.             case 0x0a:
  1840.                 digit = '*';
  1841.                 break;
  1842.             case 0x0b:
  1843.                 digit = '#';
  1844.                 break;
  1845.             case 0x0c:
  1846.                 digit = 'p';
  1847.                 break;
  1848.             case 0x0d:
  1849.                 digit = 'w';
  1850.                 break;
  1851.             case 0x0e:
  1852.                 digit = '+';
  1853.                 break;
  1854.             default:
  1855.                 digit = '';
  1856.                 break;
  1857.         }
  1858.     }
  1859.     return digit;
  1860. }
  1861. /*****************************************************************************
  1862.  * FUNCTION
  1863.  *  mmi_phb_convert_to_digit
  1864.  * DESCRIPTION
  1865.  *  convert BCD string to ASCII
  1866.  * PARAMETERS
  1867.  *  dest                [IN/OUT]        An ASCII encoding string.
  1868.  *  source              [IN]            An BCD encoding string.
  1869.  *  max_dest_len        [IN]            The byte size of dest array.(include null terminate '')
  1870.  * RETURNS
  1871.  *  byte number after convert.
  1872.  *****************************************************************************/
  1873. U8 mmi_phb_convert_to_digit(U8 *dest, U8 *source, U8 max_dest_len)
  1874. {
  1875.     /*----------------------------------------------------------------*/
  1876.     /* Local Variables                                                */
  1877.     /*----------------------------------------------------------------*/
  1878.     U8 ch1, ch2;
  1879.     U8 i = 0, j = 0;
  1880.     /*----------------------------------------------------------------*/
  1881.     /* Code Body                                                      */
  1882.     /*----------------------------------------------------------------*/
  1883.     while ((source[i] != 0xff) && (j < max_dest_len - 1))
  1884.     {
  1885.         ch1 = source[i] & 0x0f;
  1886.         ch2 = (source[i] & 0xf0) >> 4;
  1887.         *((U8*) dest + j) = mmi_phb_convert_to_digit_get_byte(ch1);
  1888.         if (ch2 == 0x0f)
  1889.         {
  1890.             *((U8*) dest + j + 1) = '';
  1891.             return j + 1;
  1892.         }
  1893.         else
  1894.         {
  1895.             *((U8*) dest + j + 1) = mmi_phb_convert_to_digit_get_byte(ch2);
  1896.         }
  1897.         i++;
  1898.         j += 2;
  1899.     }
  1900.     *((U8*) dest + j) = '';
  1901.     return j;
  1902. }
  1903. /*****************************************************************************
  1904.  * FUNCTION
  1905.  *  mmi_phb_convert_get_ucs2_number
  1906.  * DESCRIPTION
  1907.  *  This function returns the UCS2 number string by specifying store_index
  1908.  * PARAMETERS
  1909.  *  pString     [IN/OUT]        Buffter to store convert result
  1910.  *  index       [IN]            Store index of the phonebook entry to be converted.
  1911.  * RETURNS
  1912.  *  void
  1913.  *****************************************************************************/
  1914. void mmi_phb_convert_get_ucs2_number(S8 *pString, U16 index)
  1915. {
  1916.     /*----------------------------------------------------------------*/
  1917.     /* Local Variables                                                */
  1918.     /*----------------------------------------------------------------*/
  1919.     U8 tempNumber[MAX_PB_NUMBER_LENGTH + 1 + 1];
  1920.     /*----------------------------------------------------------------*/
  1921.     /* Code Body                                                      */
  1922.     /*----------------------------------------------------------------*/
  1923.     if (PhoneBook[index].tel.type == MMI_CSMCC_INTERNATIONAL_ADDR)
  1924.     {
  1925.         tempNumber[0] = '+';
  1926.         mmi_phb_convert_to_digit((U8*) (tempNumber + 1), PhoneBook[index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  1927.     }
  1928.     else
  1929.     {
  1930.         mmi_phb_convert_to_digit(tempNumber, PhoneBook[index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  1931.     }
  1932.     AnsiiToUnicodeString(pString, (S8*) tempNumber);
  1933. }
  1934. #ifdef __MMI_PHB_USIM_FIELD__
  1935. /*****************************************************************************
  1936.  * FUNCTION
  1937.  *  mmi_phb_convert_get_ucs2_anr
  1938.  * DESCRIPTION
  1939.  *  This function returns the UCS2 number string by specifying store_index
  1940.  * PARAMETERS
  1941.  *  anra            [?]             
  1942.  *  anrb            [?]             
  1943.  *  anrc            [?]             
  1944.  *  index           [IN]            Store index of the phonebook entry to be converted.
  1945.  * RETURNS
  1946.  *  void
  1947.  *****************************************************************************/
  1948. void mmi_phb_convert_get_ucs2_anr(S8 *anra, S8 *anrb, S8 *anrc, U16 index)
  1949. {
  1950.     /*----------------------------------------------------------------*/
  1951.     /* Local Variables                                                */
  1952.     /*----------------------------------------------------------------*/
  1953.     U8 tempNumber[MAX_PB_NUMBER_LENGTH + 1 + 1];
  1954.     /*----------------------------------------------------------------*/
  1955.     /* Code Body                                                      */
  1956.     /*----------------------------------------------------------------*/
  1957.     ASSERT(index >= MAX_PB_PHONE_ENTRIES);
  1958.     index -= MAX_PB_PHONE_ENTRIES;
  1959.     if (phb_anr[index][0].type == MMI_CSMCC_INTERNATIONAL_ADDR)
  1960.     {
  1961.         tempNumber[0] = '+';
  1962.         mmi_phb_convert_to_digit((U8*) (tempNumber + 1), phb_anr[index][0].number, MAX_PB_NUMBER_LENGTH + 1);
  1963.     }
  1964.     else
  1965.     {
  1966.         mmi_phb_convert_to_digit((U8*) tempNumber, phb_anr[index][0].number, MAX_PB_NUMBER_LENGTH + 1);
  1967.     }
  1968.     AnsiiToUnicodeString(anra, (S8*) tempNumber);
  1969.     if (phb_anr[index][1].type == MMI_CSMCC_INTERNATIONAL_ADDR)
  1970.     {
  1971.         tempNumber[0] = '+';
  1972.         mmi_phb_convert_to_digit((U8*) (tempNumber + 1), phb_anr[index][1].number, MAX_PB_NUMBER_LENGTH + 1);
  1973.     }
  1974.     else
  1975.     {
  1976.         mmi_phb_convert_to_digit((U8*) tempNumber, phb_anr[index][1].number, MAX_PB_NUMBER_LENGTH + 1);
  1977.     }
  1978.     AnsiiToUnicodeString(anrb, (S8*) tempNumber);
  1979.     if (phb_anr[index][2].type == MMI_CSMCC_INTERNATIONAL_ADDR)
  1980.     {
  1981.         tempNumber[0] = '+';
  1982.         mmi_phb_convert_to_digit((U8*) (tempNumber + 1), phb_anr[index][2].number, MAX_PB_NUMBER_LENGTH + 1);
  1983.     }
  1984.     else
  1985.     {
  1986.         mmi_phb_convert_to_digit((U8*) tempNumber, phb_anr[index][2].number, MAX_PB_NUMBER_LENGTH + 1);
  1987.     }
  1988.     AnsiiToUnicodeString(anrb, (S8*) tempNumber);
  1989. }
  1990. /*****************************************************************************
  1991.  * FUNCTION
  1992.  *  mmi_phb_convert_get_ansii_anr
  1993.  * DESCRIPTION
  1994.  *  This function returns the ansii number string by specifying store_index
  1995.  * PARAMETERS
  1996.  *  anra            [?]             
  1997.  *  anrb            [?]             
  1998.  *  anrc            [?]             
  1999.  *  index           [IN]            Store index of the phonebook entry to be converted.
  2000.  *  pString(?)      [IN/OUT]        Buffter to store convert result
  2001.  * RETURNS
  2002.  *  void
  2003.  *****************************************************************************/
  2004. void mmi_phb_convert_get_ansii_anr(S8 *anra, S8 *anrb, S8 *anrc, U16 index)
  2005. {
  2006.     /*----------------------------------------------------------------*/
  2007.     /* Local Variables                                                */
  2008.     /*----------------------------------------------------------------*/
  2009.     /*----------------------------------------------------------------*/
  2010.     /* Code Body                                                      */
  2011.     /*----------------------------------------------------------------*/
  2012.     ASSERT(index >= MAX_PB_PHONE_ENTRIES);
  2013.     index -= MAX_PB_PHONE_ENTRIES;
  2014.     if (phb_anr[index][0].type == MMI_CSMCC_INTERNATIONAL_ADDR)
  2015.     {
  2016.         anra[0] = '+';
  2017.         mmi_phb_convert_to_digit((U8*) (anra + 1), phb_anr[index][0].number, MAX_PB_NUMBER_LENGTH + 1);
  2018.     }
  2019.     else
  2020.     {
  2021.         mmi_phb_convert_to_digit((U8*) anra, phb_anr[index][0].number, MAX_PB_NUMBER_LENGTH + 1);
  2022.     }
  2023.     if (phb_anr[index][1].type == MMI_CSMCC_INTERNATIONAL_ADDR)
  2024.     {
  2025.         anrb[0] = '+';
  2026.         mmi_phb_convert_to_digit((U8*) (anrb + 1), phb_anr[index][1].number, MAX_PB_NUMBER_LENGTH + 1);
  2027.     }
  2028.     else
  2029.     {
  2030.         mmi_phb_convert_to_digit((U8*) anrb, phb_anr[index][1].number, MAX_PB_NUMBER_LENGTH + 1);
  2031.     }
  2032.     if (phb_anr[index][2].type == MMI_CSMCC_INTERNATIONAL_ADDR)
  2033.     {
  2034.         anrc[0] = '+';
  2035.         mmi_phb_convert_to_digit((U8*) (anrc + 1), phb_anr[index][2].number, MAX_PB_NUMBER_LENGTH + 1);
  2036.     }
  2037.     else
  2038.     {
  2039.         mmi_phb_convert_to_digit((U8*) anrc, phb_anr[index][2].number, MAX_PB_NUMBER_LENGTH + 1);
  2040.     }
  2041. }
  2042. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  2043. /*****************************************************************************
  2044.  * FUNCTION
  2045.  *  mmi_phb_convert_to_0x81_get_offset
  2046.  * DESCRIPTION
  2047.  *  This function get the offset according to the base for a two bytes UCS2 character.
  2048.  * PARAMETERS
  2049.  *  base        [IN]        Base of the character.
  2050.  *  code        [IN]        Character for getting offset
  2051.  * RETURNS
  2052.  *  offset
  2053.  *****************************************************************************/
  2054. U8 mmi_phb_convert_to_0x81_get_offset(U16 base, U16 code)
  2055. {
  2056.     /*----------------------------------------------------------------*/
  2057.     /* Local Variables                                                */
  2058.     /*----------------------------------------------------------------*/
  2059.     /*----------------------------------------------------------------*/
  2060.     /* Code Body                                                      */
  2061.     /*----------------------------------------------------------------*/
  2062.     if (code < 0x80)
  2063.     {
  2064.         return (U8) code;
  2065.     }
  2066.     else
  2067.     {
  2068.         return (U8) (code - base + 0x80);
  2069.     }
  2070. }
  2071. /*****************************************************************************
  2072.  * FUNCTION
  2073.  *  mmi_phb_convert_to_0x81_get_base
  2074.  * DESCRIPTION
  2075.  *  This function get the base for a two bytes UCS2 chatacters.(For Thai only now.)
  2076.  * PARAMETERS
  2077.  *  code        [IN]        Input character
  2078.  * RETURNS
  2079.  *  the offset base
  2080.  *****************************************************************************/
  2081. U16 mmi_phb_convert_to_0x81_get_base(U16 code)
  2082. {
  2083.     /*----------------------------------------------------------------*/
  2084.     /* Local Variables                                                */
  2085.     /*----------------------------------------------------------------*/
  2086.     /*----------------------------------------------------------------*/
  2087.     /* Code Body                                                      */
  2088.     /*----------------------------------------------------------------*/
  2089.     if ((code >= 0x0E00) && (code <= 0x0E5F))   /* Thai 0E00 ~ 0E5F */
  2090.     {
  2091.         return 0x0E00;
  2092.     }
  2093.     if ((code >= 0x0080) && (code <= 0x00FF))   /* C1 Controls and Latin-1 Supplement */
  2094.     {
  2095.         return 0x0080;
  2096.     }
  2097.     if ((code >= 0x0100) && (code <= 0x017F))   /* Latin Extended - A */
  2098.     {
  2099.         return 0x0100;
  2100.     }
  2101.     if ((code >= 0x0180) && (code <= 0x01FF))   /* Latin Extended - B (Partial) */
  2102.     {
  2103.         return 0x0180;
  2104.     }
  2105.     if ((code >= 0x0400) && (code <= 0x04FF))   /* Russian 0400 ~ 04FF */
  2106.     {
  2107.         return 0x0400;
  2108.     }
  2109.     if ((code >= 0x0600) && (code <= 0x06FF))   /* Arabic 0600 ~ 06FF */
  2110.     {
  2111.         return 0x0600;
  2112.     }
  2113.     return 0x0000;
  2114. }
  2115. /*****************************************************************************
  2116.  * FUNCTION
  2117.  *  mmi_phb_convert_to_0x81
  2118.  * DESCRIPTION
  2119.  *  This convert a 0x80 UCS2 string to 0x81 format. (Only for Thai Language right now.)
  2120.  * PARAMETERS
  2121.  *  input_name      [IN]        The input string.(Assume the input name is in high byte - low byte order)
  2122.  *  is_convert      [IN]        
  2123.  * RETURNS
  2124.  *  converted result length(in byte) for input string.
  2125.  *****************************************************************************/
  2126. U8 mmi_phb_convert_to_0x81(S8 *input_name, BOOL is_convert)
  2127. {
  2128.     /*----------------------------------------------------------------*/
  2129.     /* Local Variables                                                */
  2130.     /*----------------------------------------------------------------*/
  2131.     U16 code;
  2132.     U16 base = 0;
  2133.     BOOL flag = TRUE;
  2134.     S8 result_name[(MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH];
  2135.     S8 *temp_name;
  2136.     U8 i = 0;
  2137.     /*----------------------------------------------------------------*/
  2138.     /* Code Body                                                      */
  2139.     /*----------------------------------------------------------------*/
  2140.     temp_name = input_name;
  2141.     /* Find first UCS2 character as base */
  2142.     while (!((*temp_name == 0) && (*(temp_name + 1) == 0)))
  2143.     {
  2144.         memcpy(&code, temp_name, 2);
  2145.         /* Already GSM Encoding, need to exchange byte order */
  2146.         /*
  2147.          * if(is_convert)
  2148.          * {
  2149.          * code = (code << 8) | (code >> 8);
  2150.          * }
  2151.          */
  2152.         if (code >= 0x80 && !UI_TEST_8895_1_CHAR_IN_GSM_DEF_CHAR(code))
  2153.         {
  2154.             base = mmi_phb_convert_to_0x81_get_base(code);
  2155.             break;
  2156.         }
  2157.         temp_name += 2;
  2158.     }
  2159.     /* Check if whole string can be encoded as 0x81. */
  2160.     temp_name = input_name;
  2161.     if (base > 0)
  2162.     {
  2163.         memset(result_name, 0xFF, (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH);
  2164.         result_name[0] = (U8) 0x81;
  2165.         result_name[1] = (U8) pfnUnicodeStrlen(input_name);
  2166.         result_name[2] = (U8) (base >> 7);
  2167.         i = 3;
  2168.         while (!((*temp_name == 0) && (*(temp_name + 1) == 0)))
  2169.         {
  2170.             memcpy(&code, temp_name, 2);
  2171.             /* Already GSM Encoding, need to exchange byte order */
  2172.             /*
  2173.              * if(is_convert)
  2174.              * {
  2175.              * code = (code << 8) | (code >> 8);
  2176.              * }
  2177.              */
  2178.             if ((code >= 0x80) && (mmi_phb_convert_to_0x81_get_base(code) != base))
  2179.             {
  2180.                 flag = FALSE;
  2181.                 break;
  2182.             }
  2183.             result_name[i] = mmi_phb_convert_to_0x81_get_offset(base, code);
  2184.             temp_name += 2;
  2185.             i++;
  2186.         }
  2187.         if (flag)
  2188.         {
  2189.             /* Wrtie result to the same buffer */
  2190.             if (is_convert)
  2191.             {
  2192.                 memcpy(input_name, result_name, (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH);
  2193.             }
  2194.             return i;
  2195.         }
  2196.     }
  2197.     return 0;
  2198. }
  2199. /*****************************************************************************
  2200.  * FUNCTION
  2201.  *  PhbAsciiToGSM7Bit
  2202.  * DESCRIPTION
  2203.  *  Converts Ascii to GSM 7-Bit encoding
  2204.  * PARAMETERS
  2205.  *  buffer      [IN/OUT]        Result buffer
  2206.  * RETURNS
  2207.  *  void
  2208.  *****************************************************************************/
  2209. void PhbAsciiToGSM7Bit(PU8 buffer)
  2210. {
  2211.     /*----------------------------------------------------------------*/
  2212.     /* Local Variables                                                */
  2213.     /*----------------------------------------------------------------*/
  2214.     U16 i, length;
  2215.     /*----------------------------------------------------------------*/
  2216.     /* Code Body                                                      */
  2217.     /*----------------------------------------------------------------*/
  2218.     length = strlen((PS8) buffer);
  2219.     for (i = 0; i < length; ++i)
  2220.     {
  2221.         buffer[i] = AsciiToDefaultArray[buffer[i]];
  2222.     }
  2223. }
  2224. /*****************************************************************************
  2225.  * FUNCTION
  2226.  *  PhbGSM7BitToAscii
  2227.  * DESCRIPTION
  2228.  *  Converts GSM 7-Bit to Ascii encoding
  2229.  * PARAMETERS
  2230.  *  buffer      [IN/OUT]        Result buffer
  2231.  *  length      [IN]            Result buffer size
  2232.  * RETURNS
  2233.  *  void
  2234.  *****************************************************************************/
  2235. void PhbGSM7BitToAscii(PU8 buffer, U8 length)
  2236. {
  2237.     /*----------------------------------------------------------------*/
  2238.     /* Local Variables                                                */
  2239.     /*----------------------------------------------------------------*/
  2240.     U16 i;
  2241.     /*----------------------------------------------------------------*/
  2242.     /* Code Body                                                      */
  2243.     /*----------------------------------------------------------------*/
  2244.     for (i = 0; i < length; ++i)
  2245.     {
  2246.         if (buffer[i] == 27)    /* treat escape char as a space */
  2247.         {
  2248.             buffer[i] = 32;
  2249.         }
  2250.         else
  2251.         {
  2252.             buffer[i] = DefaultToAsciiArray[buffer[i]];
  2253.         }
  2254.     }
  2255. }
  2256. /*****************************************************************************
  2257.  * FUNCTION
  2258.  *  GetUCS2Flag
  2259.  * DESCRIPTION
  2260.  *  Checks if the buffer contains Chinese character
  2261.  * PARAMETERS
  2262.  *  buffer      [IN]        String to be checked
  2263.  * RETURNS
  2264.  *  TRUE is a UCS2 two bytes string
  2265.  *****************************************************************************/
  2266. pBOOL GetUCS2Flag(PS8 buffer)
  2267. {
  2268.     /*----------------------------------------------------------------*/
  2269.     /* Local Variables                                                */
  2270.     /*----------------------------------------------------------------*/
  2271.     pBOOL UCS2Flag = FALSE;
  2272.     U8 i, bufferLen;
  2273.     UI_character_type ch;
  2274.     /*----------------------------------------------------------------*/
  2275.     /* Code Body                                                      */
  2276.     /*----------------------------------------------------------------*/
  2277.     bufferLen = pfnUnicodeStrlen(buffer) * ENCODING_LENGTH;
  2278.     for (i = 1; i < bufferLen; i += 2)
  2279.     {
  2280.         if (buffer[i] || (buffer[i - 1] & 0x80))
  2281.         {
  2282.             ch = ((UI_character_type) buffer[i] << 8) | ((UI_character_type) buffer[i - 1]);
  2283.             if (!UI_TEST_8895_1_CHAR_IN_GSM_DEF_CHAR(ch))
  2284.             {
  2285.                 UCS2Flag = TRUE;
  2286.                 break;
  2287.             }
  2288.         }
  2289.     }
  2290.     return UCS2Flag;
  2291. }
  2292. /*****************************************************************************
  2293.  * FUNCTION
  2294.  *  GetUCS2ExtendedNum
  2295.  * DESCRIPTION
  2296.  *  Checks if the buffer contains Chinese character
  2297.  * PARAMETERS
  2298.  *  buffer      [IN]        String to be checked
  2299.  * RETURNS
  2300.  *  TRUE is a UCS2 two bytes string
  2301.  *****************************************************************************/
  2302. U8 GetUCS2ExtendedNum(PS8 buffer, U8 max_buffer_len)
  2303. {
  2304.     /*----------------------------------------------------------------*/
  2305.     /* Local Variables                                                */
  2306.     /*----------------------------------------------------------------*/
  2307.     U8 extend_num = 0;
  2308.     UI_character_type ch;
  2309.     U8 ex_count = 0;
  2310.     U8 ex_len = 1; /* need second bytes */
  2311.     U8 buffer_len = pfnUnicodeStrlen(buffer) * ENCODING_LENGTH;
  2312.     /*----------------------------------------------------------------*/
  2313.     /* Code Body                                                      */
  2314.     /*----------------------------------------------------------------*/
  2315.     while (ex_count < max_buffer_len && ex_len < buffer_len)
  2316.     {
  2317.         ch = ((UI_character_type) buffer[ex_len] << 8) | ((UI_character_type) buffer[ex_len - 1]);
  2318.         if (UI_TEST_GSM_EXTENDED(ch))
  2319.         {
  2320.             ex_count++;
  2321.             extend_num++;
  2322.         }
  2323.         ex_count++;
  2324.         ex_len += 2;
  2325.     }
  2326.     return extend_num;
  2327. }
  2328. /*****************************************************************************
  2329.  * FUNCTION
  2330.  *  BigEndianToLittleEndian
  2331.  * DESCRIPTION
  2332.  *  Changes big endian to be little endian and vice versa
  2333.  * PARAMETERS
  2334.  *  dstBuffer       [IN]        Destination buffer
  2335.  *  srcBuffer       [IN]        Source buffer
  2336.  * RETURNS
  2337.  *  result string
  2338.  *****************************************************************************/
  2339. PS8 BigEndianToLittleEndian(PS8 dstBuffer, PS8 srcBuffer)
  2340. {
  2341.     /*----------------------------------------------------------------*/
  2342.     /* Local Variables                                                */
  2343.     /*----------------------------------------------------------------*/
  2344.     U8 i = 0;
  2345.     U8 len;
  2346.     /*----------------------------------------------------------------*/
  2347.     /* Code Body                                                      */
  2348.     /*----------------------------------------------------------------*/
  2349.     len = pfnUnicodeStrlen(srcBuffer) * ENCODING_LENGTH;
  2350.     while (i != len)
  2351.     {
  2352.         dstBuffer[i] = srcBuffer[i + 1];
  2353.         dstBuffer[i + 1] = srcBuffer[i];
  2354.         i += 2;
  2355.     }
  2356.     dstBuffer[i] = '';
  2357.     dstBuffer[i + 1] = '';
  2358.     return dstBuffer;
  2359. }
  2360. /*****************************************************************************
  2361.  * FUNCTION
  2362.  *  mmi_phb_check_is_phonebook_full
  2363.  * DESCRIPTION
  2364.  *  
  2365.  * PARAMETERS
  2366.  *  void
  2367.  * RETURNS
  2368.  *  
  2369.  *****************************************************************************/
  2370. U8 mmi_phb_check_is_phonebook_full(void)
  2371. {
  2372.     /*----------------------------------------------------------------*/
  2373.     /* Local Variables                                                */
  2374.     /*----------------------------------------------------------------*/
  2375.     /*----------------------------------------------------------------*/
  2376.     /* Code Body                                                      */
  2377.     /*----------------------------------------------------------------*/
  2378.     if(PhoneBookEntryCount == (g_phb_cntx.sim_total + g_phb_cntx.phone_total))
  2379.     {
  2380.         return TRUE;
  2381.     }
  2382.     else
  2383.     {
  2384.         return FALSE;
  2385.     }
  2386. }
  2387. #endif /* _PHONEBOOKSTUBSTOOTHERS_C */