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

MTK

开发平台:

C/C++

  1.     }
  2.     flag = mmi_phb_op_increase_lookup_table(store_index, (S8*) localPtr->list[0].tel.number, NULL, NULL, NULL);
  3.     if (flag)
  4.     {
  5.         mmi_phb_lookup_table_sort();
  6.     }
  7.     PhoneBook[store_index].alpha_id.name_length = localPtr->list[0].alpha_id.name_length;
  8.     PhoneBook[store_index].alpha_id.name_dcs = localPtr->list[0].alpha_id.name_dcs;
  9.     InputboxConvertGSMToDeviceEncoding(
  10.         localPtr->list[0].alpha_id.name,
  11.         PhoneBook[store_index].alpha_id.name,
  12.         localPtr->list[0].alpha_id.name_length,
  13.         (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH,
  14.         localPtr->list[0].alpha_id.name_dcs,
  15.         0,
  16.         1);
  17.     PhoneBook[store_index].tel.type = localPtr->list[0].tel.type;
  18.     PhoneBook[store_index].tel.length = localPtr->list[0].tel.length;
  19.     mmi_phb_convert_to_bcd(
  20.         PhoneBook[store_index].tel.number,
  21.         localPtr->list[0].tel.number,
  22.         (MAX_PB_NUMBER_LENGTH + 1) / 2);
  23.     /* Update is column exists flag. */
  24.     PhoneBook[store_index].field = 0;
  25.     if (strlen((S8*) localPtr->list[0].tel.number))
  26.     {
  27.         PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_NUMBER;
  28.     }
  29.     /* Update Pinyin Cache for sort */
  30. #if defined(__MMI_PHB_PINYIN_SORT__)
  31.     mmi_phb_util_make_pinyin_cache(store_index);
  32. #endif 
  33.     /* Insert name to name mapping table. */
  34.     mmi_phb_sort_insert_name_index(store_index);
  35.     /* Insert email to email mapping table */
  36. #if defined(__MMI_PHB_EMAIL_SORT__)
  37. #ifdef __MMI_PHB_USIM_FIELD__
  38.     if (g_phb_email_sorted == 1)
  39. #else 
  40.     if ((localPtr->list[0].storage == MMI_NVRAM) && (g_phb_email_sorted == 1))
  41. #endif 
  42.         mmi_phb_sort_email_insert_index(store_index);
  43. #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  44.     g_phb_cntx.refresh_list = MMI_PHB_ENTRY_REFRESH;
  45. }
  46. /*****************************************************************************
  47.  * FUNCTION
  48.  *  mmi_phb_at_cmd_delete
  49.  * DESCRIPTION
  50.  *  Handles the phonebook update indication after an entry is deleted through AT command.
  51.  * PARAMETERS
  52.  *  info        [?]     
  53.  * RETURNS
  54.  *  void
  55.  *****************************************************************************/
  56. void mmi_phb_at_cmd_delete(void *info)
  57. {
  58.     /*----------------------------------------------------------------*/
  59.     /* Local Variables                                                */
  60.     /*----------------------------------------------------------------*/
  61.     MSG_PHB_UPDATE_IND_STRUCT *localPtr;
  62.     U16 deletedCnt = 0;
  63.     U16 store_index;
  64.     PHB_OPTIONAL_IDS_STRUCT *opt_ids;
  65.     /*----------------------------------------------------------------*/
  66.     /* Code Body                                                      */
  67.     /*----------------------------------------------------------------*/
  68.     localPtr = (MSG_PHB_UPDATE_IND_STRUCT*) info;
  69.     if (localPtr->list[0].storage == MMI_SIM)
  70.     {
  71.         store_index = localPtr->list[0].record_index + MAX_PB_PHONE_ENTRIES - 1;        /* Storage Location in array. */
  72.     }
  73.     else    /* MMI_NVRAM */
  74.     {
  75.         store_index = localPtr->list[0].record_index - 1;
  76.     #if defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__)
  77.         /* Delete image file in file folder */
  78.         mmi_phb_read_optional_ids(store_index);
  79.         opt_ids = (PHB_OPTIONAL_IDS_STRUCT*) g_phb_cntx.optional_ids;
  80.         if (opt_ids->pictureTagID == 1)
  81.         {
  82.             mmi_phb_image_delete_by_index((U16) (store_index + 1));
  83.         }
  84.     #endif /* defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__) */ 
  85.     #if defined(__MMI_INCOMING_CALL_VIDEO__)
  86.         mmi_phb_video_delete_by_index(store_index); /* Clear video field. */
  87.     #endif 
  88.         /* Clear birthday field */
  89.     #if defined(__MMI_PHB_BIRTHDAY_FIELD__) && defined(__MMI_BIRTHDAY_REMINDER__)
  90.         mmi_phb_bday_delete_field(store_index);
  91.     #endif 
  92.         /* Remove email entry from email sort mapping table */
  93.     #if defined(__MMI_PHB_EMAIL_SORT__)
  94.         if (g_phb_email_sorted == 1)
  95.         {
  96.             mmi_phb_sort_email_delete_index(store_index);
  97.         }
  98.     #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  99.     }
  100.     if (mmi_phb_util_check_entry_exist(store_index))
  101.     {
  102.         if (localPtr->list[0].storage == MMI_SIM)
  103.         {
  104.             g_phb_cntx.sim_used--;
  105.         }
  106.         else    /* MMI_NVRAM */
  107.         {
  108.             g_phb_cntx.phone_used--;
  109.         #ifdef __SYNCML_SUPPORT__
  110.             mmi_syncml_phb_data_changed_notification(SYNCML_RECORD_DELETE, store_index);
  111.         #endif
  112.         }
  113.     }
  114.     /* Remove lookup table entry */
  115.     deletedCnt = mmi_phb_op_clear_lookup_table_by_index(store_index);
  116.     if (deletedCnt)
  117.     {
  118.         mmi_phb_lookup_table_sort();
  119.         g_phb_cntx.lookup_table_count -= deletedCnt;
  120.     }
  121.     /* clear phonebook entry and remove from index */
  122.     mmi_phb_op_delete_update_index(store_index);
  123.     g_phb_cntx.refresh_list = MMI_PHB_ENTRY_REFRESH;
  124.     mmi_phb_refresh_phb_list();
  125. }
  126. /*****************************************************************************
  127.  * FUNCTION
  128.  *  mmi_phb_at_cmd_delete_all
  129.  * DESCRIPTION
  130.  *  Handles the phonebook update indication after an all the entries of one storage
  131.  *  location is deleted through AT command
  132.  * PARAMETERS
  133.  *  info        [?]     
  134.  * RETURNS
  135.  *  void
  136.  *****************************************************************************/
  137. void mmi_phb_at_cmd_delete_all(void *info)
  138. {
  139.     /*----------------------------------------------------------------*/
  140.     /* Local Variables                                                */
  141.     /*----------------------------------------------------------------*/
  142.     U8 storage;
  143.     MSG_PHB_UPDATE_IND_STRUCT *localPtr;
  144.     /*----------------------------------------------------------------*/
  145.     /* Code Body                                                      */
  146.     /*----------------------------------------------------------------*/
  147.     localPtr = (MSG_PHB_UPDATE_IND_STRUCT*) info;
  148.     if (localPtr->nvram_used == 0 && g_phb_cntx.phone_used != 0)
  149.     {
  150.         storage = MMI_NVRAM;
  151.         mmi_phb_op_delete_all_update_optioal_id();
  152.     }
  153.     else
  154.     {
  155.         storage = MMI_SIM;
  156.     }
  157.     /* Clear all storage and clear up name index. */
  158.     mmi_phb_op_delete_all_update_index(storage);
  159.     mmi_phb_op_delete_all_update_lookup_table(storage);
  160.     /* Remove email entry from email sort mapping table */
  161. #if defined(__MMI_PHB_EMAIL_SORT__)
  162.     if ((storage == MMI_NVRAM) && (g_phb_email_sorted == 1))
  163.     {
  164.         mmi_phb_sort_email_delete_all_index();
  165.     }
  166. #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  167.     mmi_phb_refresh_phb_list();
  168. }
  169. #ifdef __MMI_VCARD__
  170. /*****************************************************************************
  171.  * FUNCTION
  172.  *  mmi_phb_vcard_req_writer_v21_to_file
  173.  * DESCRIPTION
  174.  *  write select phonebook entry into vcard format into destination file.
  175.  * PARAMETERS
  176.  *  path            [IN]        Destination path
  177.  *  store_index     [IN]        
  178.  * RETURNS
  179.  *  void
  180.  *****************************************************************************/
  181. S32 mmi_phb_vcard_req_writer_v21_to_file(S8 *path, U16 store_index)
  182. {
  183.     /*----------------------------------------------------------------*/
  184.     /* Local Variables                                                */
  185.     /*----------------------------------------------------------------*/
  186.     S16 pError;
  187.     S8 number_buff[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];
  188.     PHB_OPTIONAL_FIELDS_STRUCT phb_opt_fields;
  189.     /*----------------------------------------------------------------*/
  190.     /* Code Body                                                      */
  191.     /*----------------------------------------------------------------*/
  192.     /* Mobile Number */
  193.     if (PhoneBook[store_index].tel.type == MMI_CSMCC_INTERNATIONAL_ADDR)
  194.     {
  195.         number_buff[0] = '+';
  196.         mmi_phb_convert_to_digit((U8*) number_buff + 1, PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  197.     }
  198.     else
  199.     {
  200.         mmi_phb_convert_to_digit((U8*) number_buff, PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  201.     }
  202.     if (store_index < MAX_PB_PHONE_ENTRIES) /* In NVRAM */
  203.     {
  204.     #if defined(__MMI_PHB_BIRTHDAY_FIELD__)
  205.         S8 b_day[9];    /* Format: yyyymmdd */
  206.         mmi_vcard_get_bday_to_buff(store_index, (S8*) b_day);
  207.     #endif /* defined(__MMI_PHB_BIRTHDAY_FIELD__) */ 
  208.     #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  209.         ReadRecord(
  210.             NVRAM_EF_PHB_FIELDS_LID,
  211.             (U16) (store_index + 1),
  212.             (void*)&phb_opt_fields,
  213.             OPTIONAL_FIELDS_RECORD_SIZE,
  214.             &pError);
  215.     #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  216.         return mmi_vcard_writer_v21_to_file(path, (S8*) PhoneBook[store_index].alpha_id.name, (S8*) number_buff,
  217.     #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  218.                                             (S8*) phb_opt_fields.homeNumber,
  219.                                             (S8*) phb_opt_fields.officeNumber,
  220.                                             (S8*) phb_opt_fields.faxNumber,
  221.                                             (S8*) phb_opt_fields.emailAddress, (S8*) phb_opt_fields.companyName,
  222.     #else /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  223.                                             NULL, NULL, NULL, NULL, NULL,
  224.     #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  225.     #if defined(__MMI_PHB_BIRTHDAY_FIELD__)
  226.                                             b_day,
  227.     #else 
  228.                                             NULL,
  229.     #endif 
  230.                                             NULL, NULL, NULL);
  231.     }
  232.     return mmi_vcard_writer_v21_to_file(
  233.             path,
  234.             (S8*) PhoneBook[store_index].alpha_id.name,
  235.             (S8*) number_buff,
  236.             NULL,
  237.             NULL,
  238.             NULL,
  239.             NULL,
  240.             NULL,
  241.             NULL,
  242.             NULL,
  243.             NULL,
  244.             NULL);
  245. }
  246. #endif /* __MMI_VCARD__ */ 
  247. /*****************************************************************************
  248.  * FUNCTION
  249.  *  mmi_phb_vcard_req_confirm
  250.  * DESCRIPTION
  251.  *  After MMI update done, send back confirm message.
  252.  * PARAMETERS
  253.  *  mode            [IN]        
  254.  *  req_result      [IN]        
  255.  *  store_index     [IN]        
  256.  * RETURNS
  257.  *  void
  258.  *****************************************************************************/
  259. void mmi_phb_vcard_req_confirm(U8 mode, BOOL req_result, U16 store_index)
  260. {
  261.     /*----------------------------------------------------------------*/
  262.     /* Local Variables                                                */
  263.     /*----------------------------------------------------------------*/
  264.     mmi_eq_vcard_res_req_struct *myMsgPtr;
  265.     MYQUEUE Message;
  266.     S32 result;
  267.     /*----------------------------------------------------------------*/
  268.     /* Code Body                                                      */
  269.     /*----------------------------------------------------------------*/
  270.     myMsgPtr = (mmi_eq_vcard_res_req_struct*) OslConstructDataPtr(sizeof(mmi_eq_vcard_res_req_struct));
  271. #ifdef __MMI_VCARD__
  272.     if (mode == 1)  /* req_result value is FALSE at first */
  273.     {
  274.         if (mmi_phb_util_check_entry_exist(store_index))
  275.         {
  276.             S32 check_result = mmi_vobj_fs_check_folder();
  277.             /* Create file path and folder. */
  278.             if (check_result == FS_NO_ERROR)
  279.             {
  280.                 mmi_phb_vcard_req_set_default_file((S8*) myMsgPtr->file_path);
  281.                 result = mmi_phb_vcard_req_writer_v21_to_file((S8*) myMsgPtr->file_path, store_index);
  282.                 if (result != VOBJ_ERR_NO_ERROR)
  283.                 {
  284.                     FS_Delete((U16*) myMsgPtr->file_path);
  285.                 }
  286.                 else
  287.                 {
  288.                     req_result = TRUE;  /* only this case is true */
  289.                 }
  290.             }
  291.         }
  292.     }
  293. #endif /* __MMI_VCARD__ */ 
  294.     myMsgPtr->result = req_result;
  295.     myMsgPtr->mode = mode;
  296.     Message.oslSrcId = MOD_MMI;
  297.     Message.oslDestId = MOD_L4C;
  298.     Message.oslMsgId = MSG_ID_MMI_EQ_VCARD_RES_REQ;
  299.     Message.oslDataPtr = (oslParaType*) myMsgPtr;
  300.     Message.oslPeerBuffPtr = NULL;
  301.     OslMsgSendExtQueue(&Message);
  302. }
  303. #ifdef __MMI_VCARD__
  304. /*****************************************************************************
  305.  * FUNCTION
  306.  *  mmi_phb_vcard_clear_data_buffer
  307.  * DESCRIPTION
  308.  *  Clears buffers used for adding/editing entry
  309.  * PARAMETERS
  310.  *  void
  311.  * RETURNS
  312.  *  void
  313.  *****************************************************************************/
  314. void mmi_phb_vcard_clear_data_buffer(void)
  315. {
  316.     /*----------------------------------------------------------------*/
  317.     /* Local Variables                                                */
  318.     /*----------------------------------------------------------------*/
  319.     /*----------------------------------------------------------------*/
  320.     /* Code Body                                                      */
  321.     /*----------------------------------------------------------------*/
  322.     memset(pbvCardHomeNumber, 0, ENCODING_LENGTH);
  323.     memset(pbvCardCompanyName, 0, ENCODING_LENGTH);
  324.     memset(pbvCardEmailAddress, 0, ENCODING_LENGTH);
  325.     memset(pbvCardOfficeNumber, 0, ENCODING_LENGTH);
  326.     memset(pbvCardFaxNumber, 0, ENCODING_LENGTH);
  327. #if defined(__MMI_PHB_BIRTHDAY_FIELD__)
  328.     pfnUnicodeStrcpy(pbvCardYear, (S8*) MMI_PHB_BDAY_YEAR_STR);
  329.     pfnUnicodeStrcpy(pbvCardMon, (S8*) MMI_PHB_BDAY_MON_STR);
  330.     pfnUnicodeStrcpy(pbvCardDay, (S8*) MMI_PHB_BDAY_DAY_STR);
  331. #endif /* defined(__MMI_PHB_BIRTHDAY_FIELD__) */ 
  332. }
  333. /*****************************************************************************
  334.  * FUNCTION
  335.  *  mmi_phb_vcard_req_set_default_file
  336.  * DESCRIPTION
  337.  *  
  338.  * PARAMETERS
  339.  *  path        [?]     
  340.  * RETURNS
  341.  *  void
  342.  *****************************************************************************/
  343. static void mmi_phb_vcard_req_set_default_file(S8 *path)
  344. {
  345.     /*----------------------------------------------------------------*/
  346.     /* Local Variables                                                */
  347.     /*----------------------------------------------------------------*/
  348.     S8 *ascii_path;
  349.     /*----------------------------------------------------------------*/
  350.     /* Code Body                                                      */
  351.     /*----------------------------------------------------------------*/
  352.     ascii_path = OslMalloc(25);
  353.     /* VOBJ_FILE_PATH */
  354.     sprintf(ascii_path, "%c:\Received\~vcard_r.vcf", MMI_PUBLIC_DRV);
  355.     AnsiiToUnicodeString(path, ascii_path);
  356.     OslMfree(ascii_path);
  357. }
  358. /*****************************************************************************
  359.  * FUNCTION
  360.  *  mmi_phb_vcard_reader_parse_line
  361.  * DESCRIPTION
  362.  *  Read one line to parse for each filed.
  363.  * PARAMETERS
  364.  *  fh      [IN]        file handle ready to read and parse.
  365.  * RETURNS
  366.  *  parse  error cause
  367.  *****************************************************************************/
  368. U8 mmi_phb_vcard_reader_parse_line(FS_HANDLE fh)
  369. {
  370.     /*----------------------------------------------------------------*/
  371.     /* Local Variables                                                */
  372.     /*----------------------------------------------------------------*/
  373.     S8 inBuff[512]; /* same as VOBJ_READ_BUFF_LEN */
  374.     U8 token;
  375.     /*----------------------------------------------------------------*/
  376.     /* Code Body                                                      */
  377.     /*----------------------------------------------------------------*/
  378.     /* BEGIN:VCARD */
  379.     if (mmi_vcard_uti_get_single_line(inBuff, fh) != 0)
  380.     {
  381.         if (mmi_vcard_reader_get_field(inBuff) != VCARD_FIELD_BEGIN)
  382.         {
  383.             return VCARD_BEGIN_ERROR;
  384.         }
  385.         else if (!mmi_vcard_reader_check_header(inBuff))
  386.         {
  387.             return VCARD_BEGIN_ERROR;
  388.         }
  389.     }
  390.     else
  391.     {
  392.         return VCARD_PARSE_UNKNOW_ERROR;
  393.     }
  394.     /* PARSE EACH FIELD */
  395.     while (mmi_vcard_uti_get_line(inBuff, fh) != 0)
  396.     {
  397.         token = mmi_vcard_reader_get_field(inBuff);
  398.         switch (token)
  399.         {
  400.             case VCARD_FIELD_END:
  401.                 if (!mmi_vcard_reader_check_header(inBuff))
  402.                 {
  403.                     return VCARD_PARSE_UNKNOW_ERROR;
  404.                 }
  405.                 else
  406.                 {
  407.                     return VCARD_PARSE_NO_ERROR;
  408.                 }
  409.                 break;                
  410.             case VCARD_FIELD_PHOTO:
  411.                 return VCARD_PARSE_NO_ERROR;
  412.             /* VERSION */
  413.             case VCARD_FIELD_VERSION:
  414.                 if (!mmi_vcard_reader_check_version(inBuff))
  415.                 {
  416.                     return VCARD_VERSION_ERROR;
  417.                 }
  418.                 break;
  419.             case VCARD_FIELD_N:
  420.                 /* mmi_vcard_reader_retrive_name(inBuff); */
  421.                 break;
  422.             case VCARD_FIELD_TEL:
  423.                 mmi_vcard_reader_retrive_number(inBuff, NULL, pbvCardHomeNumber, pbvCardOfficeNumber, pbvCardFaxNumber);
  424.                 break;
  425.             case VCARD_FIELD_EMAIL:
  426.                 mmi_vcard_reader_retrive_email(inBuff, pbvCardEmailAddress);
  427.                 break;
  428.             case VCARD_FIELD_ORG:
  429.                 mmi_vcard_reader_retrive_org(inBuff, pbvCardCompanyName);
  430.                 break;
  431.         #ifdef __MMI_PHB_BIRTHDAY_FIELD__
  432.             case VCARD_FIELD_BDAY:
  433.                 mmi_vcard_reader_retrive_bday(inBuff, pbvCardYear, pbvCardMon, pbvCardDay, FALSE);
  434.                 break;
  435.         #endif /* __MMI_PHB_BIRTHDAY_FIELD__ */ 
  436.         #ifdef __MMI_PHB_INFO_FIELD__
  437.             case VCARD_FIELD_TITLE:
  438.                 break;
  439.         #endif /* __MMI_PHB_INFO_FIELD__ */ 
  440.             default:
  441.                 break;
  442.         }
  443.     }
  444.     return VCARD_PARSE_UNKNOW_ERROR;
  445. }
  446. /*****************************************************************************
  447.  * FUNCTION
  448.  *  mmi_phb_vcard_req_save_obj_to_phb
  449.  * DESCRIPTION
  450.  *  save parsed vcard to phonebook after parsing.
  451.  * PARAMETERS
  452.  *  store_index     [IN]        
  453.  * RETURNS
  454.  *  void
  455.  *****************************************************************************/
  456. BOOL mmi_phb_vcard_req_save_obj_to_phb(U16 store_index)
  457. {
  458.     /*----------------------------------------------------------------*/
  459.     /* Local Variables                                                */
  460.     /*----------------------------------------------------------------*/
  461.     PHB_OPTIONAL_FIELDS_STRUCT phb_opt_fields;
  462.     S16 pError;
  463.     U8 temp_number[MAX_PB_NUMBER_LENGTH + 1 + 1];
  464.     U16 deletedCnt = 0;
  465.     U8 flag = 0;
  466.     /*----------------------------------------------------------------*/
  467.     /* Code Body                                                      */
  468.     /*----------------------------------------------------------------*/
  469.     if (!g_phb_cntx.phb_ready || g_phb_cntx.processing) /* Phonebook not ready */
  470.     {
  471.         return FALSE;
  472.     }
  473. #ifdef __SYNCML_SUPPORT__
  474.     else if (mmi_syncml_is_phb_sync_now())
  475.     {
  476.         return FALSE;
  477.     }
  478. #endif /* __SYNCML_SUPPORT__ */
  479.     else if (store_index >= MAX_PB_PHONE_ENTRIES)   /* only nvram data. */
  480.     {
  481.         return FALSE;
  482.     }
  483.     else if ((!mmi_phb_op_check_valid_number(pbvCardHomeNumber) ||      /* Number format not correct */
  484.               !mmi_phb_op_check_valid_number(pbvCardOfficeNumber) || !mmi_phb_op_check_valid_number(pbvCardFaxNumber)))
  485.     {
  486.         return FALSE;
  487.     }
  488.     mmi_phb_convert_to_digit(temp_number, PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  489.     /* Clear lookup table first, add later if exists. */
  490.     deletedCnt = mmi_phb_op_clear_lookup_table_by_index(store_index);
  491.     UnicodeToAnsii((PS8) phb_opt_fields.homeNumber, pbvCardHomeNumber);
  492.     pfnUnicodeStrcpy((PS8) phb_opt_fields.companyName, pbvCardCompanyName);
  493.     UnicodeToAnsii((PS8) phb_opt_fields.emailAddress, pbvCardEmailAddress);
  494.     UnicodeToAnsii((PS8) phb_opt_fields.officeNumber, pbvCardOfficeNumber);
  495.     UnicodeToAnsii((PS8) phb_opt_fields.faxNumber, pbvCardFaxNumber);
  496.     WriteRecord(
  497.         NVRAM_EF_PHB_FIELDS_LID,
  498.         (U16) (store_index + 1),
  499.         (void*)&phb_opt_fields,
  500.         OPTIONAL_FIELDS_RECORD_SIZE,
  501.         &pError);
  502. #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  503.     flag = mmi_phb_op_increase_lookup_table(
  504.             store_index,
  505.             NULL,
  506.             (S8*) phb_opt_fields.faxNumber,
  507.             (S8*) phb_opt_fields.homeNumber,
  508.             (S8*) phb_opt_fields.officeNumber);
  509. #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  510.     flag += mmi_phb_op_increase_lookup_table(store_index, (S8*) temp_number, NULL, NULL, NULL);
  511.     if (deletedCnt || flag)
  512.     {
  513.         mmi_phb_lookup_table_sort();
  514.         g_phb_cntx.lookup_table_count -= deletedCnt;
  515.     }
  516.     /* Update is column exists flag. */
  517. #if defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  518.     mmi_phb_op_update_field_flag(store_index, (S8*) temp_number, NULL, NULL, NULL, NULL, FALSE);
  519. #else /* defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  520.     mmi_phb_op_update_field_flag(
  521.         store_index,
  522.         (S8*) temp_number,
  523.         (S8*) phb_opt_fields.homeNumber,
  524.         (S8*) phb_opt_fields.officeNumber,
  525.         (S8*) phb_opt_fields.faxNumber,
  526.         (S8*) phb_opt_fields.emailAddress,
  527.         FALSE);
  528. #endif /* defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  529.     /* Save birthday field */
  530. #if defined(__MMI_PHB_BIRTHDAY_FIELD__)
  531.     mmi_phb_bday_update_field(store_index, (S8*) pbvCardYear, (S8*) pbvCardMon, (S8*) pbvCardDay);
  532. #endif 
  533.     /* Update email sorting mapping table */
  534. #if defined(__MMI_PHB_EMAIL_SORT__)
  535. #ifdef __MMI_PHB_USIM_FIELD__
  536.     if (g_phb_email_sorted == 1)
  537. #else 
  538.     if ((store_index < MAX_PB_PHONE_ENTRIES) && (g_phb_email_sorted == 1))
  539. #endif 
  540.     {
  541.         mmi_phb_sort_email_delete_index(store_index);
  542.         mmi_phb_sort_email_insert_index(store_index);
  543.     }
  544. #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  545.     return TRUE;
  546. }
  547. /*****************************************************************************
  548.  * FUNCTION
  549.  *  mmi_phb_save_vcard_req
  550.  * DESCRIPTION
  551.  *  
  552.  * PARAMETERS
  553.  *  path        [?]         
  554.  *  index       [IN]        
  555.  * RETURNS
  556.  *  
  557.  *****************************************************************************/
  558. BOOL mmi_phb_save_vcard_req(S8 *path, U16 index)
  559. {
  560.     /*----------------------------------------------------------------*/
  561.     /* Local Variables                                                */
  562.     /*----------------------------------------------------------------*/
  563.     FS_HANDLE fh;
  564.     U8 error_code = VCARD_PARSE_UNKNOW_ERROR;
  565.     /*----------------------------------------------------------------*/
  566.     /* Code Body                                                      */
  567.     /*----------------------------------------------------------------*/
  568.     fh = FS_Open((U16*) path, FS_READ_ONLY);
  569.     if (fh > 0)
  570.     {
  571.         mmi_phb_vcard_clear_data_buffer();  /* Clear all phonebook vcard temp buffer before parsing */
  572.         error_code = mmi_phb_vcard_reader_parse_line(fh);
  573.         FS_Close(fh);
  574.     }
  575.     else
  576.     {
  577.         error_code = MMI_PHB_VCARD_OPEN_FILE_ERROR;
  578.     }
  579.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_save_vcard_req. error_code: %d>n",
  580.                          __FILE__, __LINE__, error_code));
  581.     if (error_code == VCARD_PARSE_NO_ERROR)
  582.     {
  583.         return mmi_phb_vcard_req_save_obj_to_phb(index);
  584.     }
  585.     else
  586.     {
  587.         return FALSE;
  588.     }
  589. }
  590. #endif /* __MMI_VCARD__ */ 
  591. /*****************************************************************************
  592.  * FUNCTION
  593.  *  mmi_phb_vcard_req
  594.  * DESCRIPTION
  595.  *  This function handles the read indication through AT commands
  596.  * PARAMETERS
  597.  *  info        [?]     
  598.  * RETURNS
  599.  *  void
  600.  *****************************************************************************/
  601. static void mmi_phb_vcard_req(void *info)
  602. {
  603.     /*----------------------------------------------------------------*/
  604.     /* Local Variables                                                */
  605.     /*----------------------------------------------------------------*/
  606.     mmi_eq_vcard_req_ind_struct *localPtr;
  607.     U16 index;
  608.     /*----------------------------------------------------------------*/
  609.     /* Code Body                                                      */
  610.     /*----------------------------------------------------------------*/
  611.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_vcard_req.>n", __FILE__, __LINE__));
  612.     localPtr = (mmi_eq_vcard_req_ind_struct*) info;
  613.     index = localPtr->index;
  614.     ASSERT(index >= 1) index--; /* 1-based */
  615. #ifdef __MMI_VCARD__
  616.     if (localPtr->mode == 0 && mmi_phb_save_vcard_req((S8*) localPtr->file_path, index))
  617.     {
  618.         mmi_phb_vcard_req_confirm(localPtr->mode, TRUE, index);
  619.     }
  620.     else
  621.     {
  622.         mmi_phb_vcard_req_confirm(localPtr->mode, FALSE, index);
  623.     }
  624. #else /* __MMI_VCARD__ */ 
  625.     mmi_phb_vcard_req_confirm(localPtr->mode, FALSE, index);
  626. #endif /* __MMI_VCARD__ */ 
  627. }
  628. #define MMI_PHB_OPERATE_UTIL
  629. /*****************************************************************************
  630.  * FUNCTION
  631.  *  mmi_phb_mass_processing_abort
  632.  * DESCRIPTION
  633.  *  abort function of processing screen. It will set up the abort flag.
  634.  * PARAMETERS
  635.  *  void
  636.  * RETURNS
  637.  *  void
  638.  *****************************************************************************/
  639. void mmi_phb_mass_processing_abort(void)
  640. {
  641.     /*----------------------------------------------------------------*/
  642.     /* Local Variables                                                */
  643.     /*----------------------------------------------------------------*/
  644.     /*----------------------------------------------------------------*/
  645.     /* Code Body                                                      */
  646.     /*----------------------------------------------------------------*/
  647.     g_phb_mass_op_abort = TRUE;
  648.     mmi_phb_show_in_progress(STR_COPY_ALL_ABORTING, IMG_COPY_ALL_ABORTING);
  649.     DeleteScreenIfPresent(SCR_COPY_ALL_PROGRESS);
  650. }
  651. /*****************************************************************************
  652.  * FUNCTION
  653.  *  mmi_phb_op_delete_all_update_index
  654.  * DESCRIPTION
  655.  *  update name index after delete all.
  656.  * PARAMETERS
  657.  *  storage     [IN]        Storage location
  658.  * RETURNS
  659.  *  void
  660.  *****************************************************************************/
  661. void mmi_phb_op_delete_all_update_index(U8 storage)
  662. {
  663.     /*----------------------------------------------------------------*/
  664.     /* Local Variables                                                */
  665.     /*----------------------------------------------------------------*/
  666.     U16 pos, i;
  667.     /*----------------------------------------------------------------*/
  668.     /* Code Body                                                      */
  669.     /*----------------------------------------------------------------*/
  670.     for (i = 0; i < PhoneBookEntryCount; i++)
  671.     {
  672.         if ((storage == MMI_SIM && g_phb_name_index[i] >= MAX_PB_PHONE_ENTRIES) ||
  673.             (storage == MMI_NVRAM && g_phb_name_index[i] < MAX_PB_PHONE_ENTRIES))
  674.         {
  675.             g_phb_name_index[i] = 0xffff;
  676.         }
  677.     }
  678.     pos = 0;
  679.     while (pos < PhoneBookEntryCount)
  680.     {
  681.         if (g_phb_name_index[pos] == 0xffff)
  682.         {
  683.             for (i = pos; i < PhoneBookEntryCount; i++)
  684.             {
  685.                 g_phb_name_index[i] = g_phb_name_index[i + 1];
  686.             }
  687.             PhoneBookEntryCount--;
  688.         }
  689.         pos++;
  690.     }
  691. }
  692. /*****************************************************************************
  693.  * FUNCTION
  694.  *  mmi_phb_op_delete_all_update_lookup_table
  695.  * DESCRIPTION
  696.  *  clear lookup table
  697.  * PARAMETERS
  698.  *  storage     [IN]        
  699.  * RETURNS
  700.  *  void
  701.  *****************************************************************************/
  702. void mmi_phb_op_delete_all_update_lookup_table(U8 storage)
  703. {
  704.     /*----------------------------------------------------------------*/
  705.     /* Local Variables                                                */
  706.     /*----------------------------------------------------------------*/
  707.     U16 k;
  708.     U16 deletedCnt = 0;
  709.     /*----------------------------------------------------------------*/
  710.     /* Code Body                                                      */
  711.     /*----------------------------------------------------------------*/
  712.     /* Remove lookup table entry */
  713.     for (k = 0; k < g_phb_cntx.lookup_table_count; ++k)
  714.     {
  715.         if ((storage == MMI_SIM && LookUpTable[k].store_index >= MAX_PB_PHONE_ENTRIES) ||
  716.             (storage == MMI_NVRAM && LookUpTable[k].store_index < MAX_PB_PHONE_ENTRIES))
  717.         {
  718.             LookUpTable[k].number = INVALID_NUMBER;
  719.             ++deletedCnt;
  720.         }
  721.     }
  722.     if (deletedCnt)
  723.     {
  724.         mmi_phb_lookup_table_sort();
  725.         g_phb_cntx.lookup_table_count -= deletedCnt;
  726.     }
  727. }
  728. /*****************************************************************************
  729.  * FUNCTION
  730.  *  mmi_phb_op_delete_all_update_optioal_id
  731.  * DESCRIPTION
  732.  *  Update optional id on NVRAM after delete all.
  733.  * PARAMETERS
  734.  *  void
  735.  * RETURNS
  736.  *  void
  737.  *****************************************************************************/
  738. void mmi_phb_op_delete_all_update_optioal_id(void)
  739. {
  740.     /*----------------------------------------------------------------*/
  741.     /* Local Variables                                                */
  742.     /*----------------------------------------------------------------*/
  743.     U16 i, j;
  744.     S16 pError;
  745.     U8 optid_record, optid_index, current_record = 0;
  746.     PHB_OPTIONAL_IDS_STRUCT PhbOptIDs[OPTIONAL_IDS_RECORD_TOTAL];
  747.     /*----------------------------------------------------------------*/
  748.     /* Code Body                                                      */
  749.     /*----------------------------------------------------------------*/
  750.     for (i = 0; i < MAX_PB_PHONE_ENTRIES; i++)
  751.     {
  752.         /* If entry still exist, do not clear. */
  753.         for (j = 0; j < PhoneBookEntryCount; j++)
  754.         {
  755.             if (i == g_phb_name_index[j])
  756.             {
  757.                 continue;
  758.             }
  759.         }
  760.         /* Get optional IDs record. */
  761.         optid_record = (i / OPTIONAL_IDS_RECORD_TOTAL) + 1;
  762.         optid_index = i - (optid_record - 1) * OPTIONAL_IDS_RECORD_TOTAL;
  763.         if (optid_record != current_record)
  764.         {
  765.             ReadRecord(NVRAM_EF_PHB_IDS_LID, optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  766.             current_record = optid_record;
  767.         }
  768.         /* Clear image in file system */
  769.     #if defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__)
  770.         if (PhbOptIDs[optid_index].pictureTagID == 1)
  771.         {
  772.             mmi_phb_image_delete_by_index((U16) (i + 1));
  773.         }
  774.     #endif /* defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__) */ 
  775.     }
  776. }
  777. /*****************************************************************************
  778.  * FUNCTION
  779.  *  mmi_phb_op_update_optional_field
  780.  * DESCRIPTION
  781.  *  Saves optional fields of a Phone entry on NVRAM
  782.  * PARAMETERS
  783.  *  store_index     [IN]        
  784.  *  storage         [IN]        
  785.  *  type            [IN]  if type 0 is for Java PIM, don't need copy opt IDs.
  786.  * RETURNS
  787.  *  void
  788.  *****************************************************************************/
  789. void mmi_phb_op_update_optional_field(U16 store_index, U8 storage, U8 type)
  790. {
  791.     /*----------------------------------------------------------------*/
  792.     /* Local Variables                                                */
  793.     /*----------------------------------------------------------------*/
  794.     S16 pError;
  795.     U8 optid_record;
  796.     U8 optid_index;
  797.     /* U8 grpIndex; */
  798.     PHB_OPTIONAL_IDS_STRUCT tempIDs;
  799.     PHB_OPTIONAL_IDS_STRUCT PhbOptIDs[OPTIONAL_IDS_RECORD_TOTAL];
  800.     /*----------------------------------------------------------------*/
  801.     /* Code Body                                                      */
  802.     /*----------------------------------------------------------------*/
  803.     /*
  804.      *  Update optional fields.
  805.      */
  806. #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  807.     if (storage == MMI_NVRAM)
  808.     {
  809.         UnicodeToAnsii((PS8) PhoneBookOptionalFields.homeNumber, pbHomeNumber);
  810.         pfnUnicodeStrcpy((PS8) PhoneBookOptionalFields.companyName, pbCompanyName);
  811.         UnicodeToAnsii((PS8) PhoneBookOptionalFields.emailAddress, pbEmailAddress);
  812.         UnicodeToAnsii((PS8) PhoneBookOptionalFields.officeNumber, pbOfficeNumber);
  813.         UnicodeToAnsii((PS8) PhoneBookOptionalFields.faxNumber, pbFaxNumber);
  814.         WriteRecord(
  815.             NVRAM_EF_PHB_FIELDS_LID,
  816.             (U16) (store_index + 1),
  817.             (void*)&PhoneBookOptionalFields,
  818.             OPTIONAL_FIELDS_RECORD_SIZE,
  819.             &pError);
  820.     }
  821. #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  822. #if defined(SUPPORT_JSR_75_PIM) || defined(SUPPORT_CMCC)
  823.     if (type == 0)
  824.     {
  825.         return;
  826.     }
  827. #endif /* defined(SUPPORT_JSR_75_PIM) || defined(SUPPORT_CMCC) */ 
  828.     /*
  829.      *  Update optional selection field (id), and caller group counter
  830.      */
  831.     /* Read out related optional id record */
  832.     optid_record = (store_index / OPTIONAL_IDS_RECORD_TOTAL) + 1;
  833.     optid_index = store_index - (optid_record - 1) * OPTIONAL_IDS_RECORD_TOTAL;
  834.     ReadRecord(NVRAM_EF_PHB_IDS_LID, optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  835.     /* assign user selected optional id */
  836. #if defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__)
  837.     if (g_phb_cntx.selected_pic_index == g_phb_cntx.total_image_id - 1)
  838.     {
  839.         tempIDs.pictureTagID = 1;
  840.     }
  841.     else
  842. #endif /* defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__) */ 
  843.         tempIDs.pictureTagID = g_phb_cntx.image_id_list[g_phb_cntx.selected_pic_index];
  844.     tempIDs.callerGroupID = (U8) g_phb_cntx.selected_grp_index;
  845.     tempIDs.ringToneID = g_phb_cntx.ring_tone_list[g_phb_cntx.selected_ring_index];
  846. #if defined(__MMI_PHB_CALLERGROUP_IN_SIM__)     /* Associate caller group in SIM card entry */
  847.     if (storage == MMI_SIM)
  848.     {
  849.         tempIDs.pictureTagID = 0;
  850.         tempIDs.ringToneID = 0;
  851.     }
  852. #endif /* defined(__MMI_PHB_CALLERGROUP_IN_SIM__) */ 
  853.     /* Update associate id and write it back */
  854.     memcpy(&PhbOptIDs[optid_index], &tempIDs, sizeof(PHB_OPTIONAL_IDS_STRUCT));
  855.     WriteRecord(NVRAM_EF_PHB_IDS_LID, optid_record, PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  856. }
  857. /*****************************************************************************
  858.  * FUNCTION
  859.  *  mmi_phb_read_optional_ids
  860.  * DESCRIPTION
  861.  *  read one optional id for one entry
  862.  * PARAMETERS
  863.  *  store_index     [IN]        
  864.  * RETURNS
  865.  *  void
  866.  *****************************************************************************/
  867. void mmi_phb_read_optional_ids(U16 store_index)
  868. {
  869.     /*----------------------------------------------------------------*/
  870.     /* Local Variables                                                */
  871.     /*----------------------------------------------------------------*/
  872.     U8 optid_record;
  873.     U8 optid_index;
  874.     S16 pError;
  875.     PHB_OPTIONAL_IDS_STRUCT PhbOptIDs[OPTIONAL_IDS_RECORD_TOTAL];
  876.     /*----------------------------------------------------------------*/
  877.     /* Code Body                                                      */
  878.     /*----------------------------------------------------------------*/
  879.     optid_record = (store_index / OPTIONAL_IDS_RECORD_TOTAL) + 1;
  880.     optid_index = store_index - (optid_record - 1) * OPTIONAL_IDS_RECORD_TOTAL;
  881.     ReadRecord(NVRAM_EF_PHB_IDS_LID, optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  882.     memcpy(g_phb_cntx.optional_ids, &PhbOptIDs[optid_index], sizeof(PHB_OPTIONAL_IDS_STRUCT));
  883. }
  884. /*****************************************************************************
  885.  * FUNCTION
  886.  *  mmi_phb_clear_optional_ids
  887.  * DESCRIPTION
  888.  *  clear optional id field
  889.  * PARAMETERS
  890.  *  store_index     [IN]        
  891.  * RETURNS
  892.  *  void
  893.  *****************************************************************************/
  894. void mmi_phb_clear_optional_ids(U16 store_index)
  895. {
  896.     /*----------------------------------------------------------------*/
  897.     /* Local Variables                                                */
  898.     /*----------------------------------------------------------------*/
  899.     U8 optid_record;
  900.     U8 optid_index;
  901.     S16 pError;
  902.     PHB_OPTIONAL_IDS_STRUCT PhbOptIDs[OPTIONAL_IDS_RECORD_TOTAL];
  903.     /*----------------------------------------------------------------*/
  904.     /* Code Body                                                      */
  905.     /*----------------------------------------------------------------*/
  906.     optid_record = (store_index / OPTIONAL_IDS_RECORD_TOTAL) + 1;
  907.     optid_index = store_index - (optid_record - 1) * OPTIONAL_IDS_RECORD_TOTAL;
  908.     ReadRecord(NVRAM_EF_PHB_IDS_LID, optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  909.     memset(&PhbOptIDs[optid_index], 0, sizeof(PHB_OPTIONAL_IDS_STRUCT));
  910.     WriteRecord(NVRAM_EF_PHB_IDS_LID, optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  911. }
  912. /*****************************************************************************
  913.  * FUNCTION
  914.  *  mmi_phb_clear_optional_ids_for_sim
  915.  * DESCRIPTION
  916.  *  clear optional id field
  917.  * PARAMETERS
  918.  *  store_index     [IN]        
  919.  * RETURNS
  920.  *  void
  921.  *****************************************************************************/
  922. #if defined(__MMI_PHB_CALLERGROUP_IN_SIM__)     /* Associate caller group in SIM card entry */
  923. void mmi_phb_clear_optional_ids_for_sim(U16 store_index)
  924. {
  925.     /*----------------------------------------------------------------*/
  926.     /* Local Variables                                                */
  927.     /*----------------------------------------------------------------*/
  928.     U8 optid_record;
  929.     U8 optid_index;
  930.     S16 pError;
  931.     PHB_OPTIONAL_IDS_STRUCT PhbOptIDs[OPTIONAL_IDS_RECORD_TOTAL];
  932.     /*----------------------------------------------------------------*/
  933.     /* Code Body                                                      */
  934.     /*----------------------------------------------------------------*/
  935.     optid_record = (store_index / OPTIONAL_IDS_RECORD_TOTAL) + 1;
  936.     optid_index = store_index - (optid_record - 1) * OPTIONAL_IDS_RECORD_TOTAL;
  937.     ReadRecord(NVRAM_EF_PHB_IDS_LID, optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  938.     /* Clear Picture ID and Ring Tone ID for SIM because SIM does not have these fields. */
  939.     PhbOptIDs[optid_index].pictureTagID = 0;
  940.     PhbOptIDs[optid_index].ringToneID = 0;
  941.     WriteRecord(NVRAM_EF_PHB_IDS_LID, optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  942. }
  943. #endif /* defined(__MMI_PHB_CALLERGROUP_IN_SIM__) */ 
  944. /*****************************************************************************
  945.  * FUNCTION
  946.  *  mmi_phb_copy_optional_ids
  947.  * DESCRIPTION
  948.  *  copy optional id field and caller picture
  949.  * PARAMETERS
  950.  *  dst_store_index     [IN]        
  951.  *  src_store_index     [IN]        
  952.  * RETURNS
  953.  *  
  954.  *****************************************************************************/
  955. BOOL mmi_phb_copy_optional_ids(U16 dst_store_index, U16 src_store_index)
  956. {
  957.     /*----------------------------------------------------------------*/
  958.     /* Local Variables                                                */
  959.     /*----------------------------------------------------------------*/
  960.     U8 src_optid_record, dst_optid_record;
  961.     U8 optid_index;
  962.     S16 pError;
  963.     PHB_OPTIONAL_IDS_STRUCT PhbOptIDs[OPTIONAL_IDS_RECORD_TOTAL];
  964.     PHB_OPTIONAL_IDS_STRUCT tempIDs;
  965.     BOOL copy_image = TRUE;
  966.     /*----------------------------------------------------------------*/
  967.     /* Code Body                                                      */
  968.     /*----------------------------------------------------------------*/
  969.     /* Read Source ID first */
  970.     src_optid_record = (src_store_index / OPTIONAL_IDS_RECORD_TOTAL) + 1;
  971.     optid_index = src_store_index - (src_optid_record - 1) * OPTIONAL_IDS_RECORD_TOTAL;
  972.     ReadRecord(NVRAM_EF_PHB_IDS_LID, src_optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  973.     /* Copy to temp buffer. */
  974.     memcpy(&tempIDs, &PhbOptIDs[optid_index], sizeof(PHB_OPTIONAL_IDS_STRUCT));
  975.     /* Read Destination ID */
  976.     dst_optid_record = (dst_store_index / OPTIONAL_IDS_RECORD_TOTAL) + 1;
  977.     optid_index = dst_store_index - (dst_optid_record - 1) * OPTIONAL_IDS_RECORD_TOTAL;
  978.     if (dst_optid_record != src_optid_record)
  979.     {
  980.         ReadRecord(NVRAM_EF_PHB_IDS_LID, dst_optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  981.     }
  982.     /* Copy from temp buffer. */
  983.     memcpy(&PhbOptIDs[optid_index], &tempIDs, sizeof(PHB_OPTIONAL_IDS_STRUCT));
  984. #if defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__)
  985.     if (dst_store_index  < MAX_PB_PHONE_ENTRIES && src_store_index < MAX_PB_PHONE_ENTRIES) /* duplicate phone entry*/
  986.     {
  987.         /* Duplicate image in file system. */
  988.         if (PhbOptIDs[optid_index].pictureTagID == 1)
  989.         {
  990.             copy_image = mmi_phb_image_duplicate_by_index((U16) (dst_store_index + 1), (U16) (src_store_index + 1));
  991.             if (!copy_image)
  992.             {
  993.                 PhbOptIDs[optid_index].pictureTagID = 0;
  994.             }
  995.         }
  996.     }
  997. #endif /* defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__) */ 
  998.     /* Write Back To buffer */
  999.     WriteRecord(NVRAM_EF_PHB_IDS_LID, dst_optid_record, PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  1000.     return copy_image;
  1001. }
  1002. /*****************************************************************************
  1003.  * FUNCTION
  1004.  *  mmi_phb_copy_number_without_parentheses
  1005.  * DESCRIPTION
  1006.  *  prepare name and number by user input  before send to L4
  1007.  * PARAMETERS
  1008.  *  in_number     [IN]     
  1009.  *  out_number    [IN/OUT]     
  1010.  * RETURNS
  1011.  *  void
  1012.  *****************************************************************************/
  1013. void mmi_phb_copy_number_without_parentheses(S8 *in_number, S8 *out_number)
  1014. {
  1015.     while (!((*in_number == 0) && (*(in_number + 1) == 0)))
  1016.     {
  1017.         if (*in_number != '(' && *in_number != ')' && *in_number != '-')
  1018.         {
  1019.             *out_number = *(in_number);
  1020.             *(out_number + 1) =  *(in_number + 1);
  1021.             out_number += 2;
  1022.         }
  1023.         in_number += 2;
  1024.     }
  1025.     *out_number = 0;
  1026.     *(out_number + 1) = 0;
  1027. }
  1028. /*****************************************************************************
  1029.  * FUNCTION
  1030.  *  mmi_phb_op_set_entry_prepare_name_number
  1031.  * DESCRIPTION
  1032.  *  prepare name and number by user input  before send to L4
  1033.  * PARAMETERS
  1034.  *  dst_msg     [?]     
  1035.  *  in_name     [?]     
  1036.  *  in_num      [?]     
  1037.  * RETURNS
  1038.  *  void
  1039.  *****************************************************************************/
  1040. void mmi_phb_op_set_entry_prepare_name_number(void *dst_msg, S8 *in_name, S8 *in_num)
  1041. {
  1042.     /*----------------------------------------------------------------*/
  1043.     /* Local Variables                                                */
  1044.     /*----------------------------------------------------------------*/
  1045.     l4c_phb_entry_struct *phb_entry = (l4c_phb_entry_struct*) dst_msg;
  1046. #if defined(__PHB_0x81_SUPPORT__)
  1047.     U8 length;
  1048. #endif 
  1049.     /*----------------------------------------------------------------*/
  1050.     /* Code Body                                                      */
  1051.     /*----------------------------------------------------------------*/
  1052.     if (dst_msg == NULL)
  1053.     {
  1054.         return;
  1055.     }
  1056.     if (in_num != NULL)
  1057.     {
  1058.         S8* valid_num = OslMalloc((MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH);
  1059.         mmi_phb_copy_number_without_parentheses(in_num, valid_num);
  1060.         /* Prepate Number Data */
  1061.         if (in_num[0] == '+')
  1062.         {
  1063.             phb_entry->tel.type = MMI_CSMCC_INTERNATIONAL_ADDR; /* INTERNATIONAL */
  1064.             phb_entry->tel.length = (U8) pfnUnicodeStrlen(valid_num + ENCODING_LENGTH);    /* Exclude "+" */
  1065.             UnicodeToAnsii((PS8) phb_entry->tel.number, valid_num + ENCODING_LENGTH);
  1066.         }
  1067.         else
  1068.         {
  1069.             phb_entry->tel.type = MMI_CSMCC_DEFAULT_ADDR_TYPE;  /* DEFAULT */
  1070.             phb_entry->tel.length = (U8) pfnUnicodeStrlen(valid_num);
  1071.             UnicodeToAnsii((PS8) phb_entry->tel.number, valid_num);
  1072.         }
  1073.         OslMfree(valid_num);
  1074.     }
  1075.     if (in_name != NULL)
  1076.     {
  1077.         /* Prepare Name Data */
  1078.         if (GetUCS2Flag(in_name))
  1079.         {
  1080.         #if defined(__PHB_0x81_SUPPORT__)       /* Support maximum length of 0x81 UCS2 */
  1081.             if ((length = mmi_phb_convert_to_0x81((S8*) in_name, TRUE)) > 0)
  1082.             {
  1083.                 phb_entry->alpha_id.name_dcs = 0x09;
  1084.                 phb_entry->alpha_id.name_length = length;
  1085.                 memcpy(phb_entry->alpha_id.name, in_name, length);
  1086.                 memset(phb_entry->alpha_id.name + length, 0x00, 1);
  1087.             }
  1088.             else
  1089.         #endif /* defined(__PHB_0x81_SUPPORT__) */ 
  1090.             {
  1091.                 phb_entry->alpha_id.name_dcs = MMI_PHB_UCS2;
  1092.                 phb_entry->alpha_id.name_length = ((U8) pfnUnicodeStrlen(in_name)) * ENCODING_LENGTH;
  1093.                 InputboxConvertDeviceEncodingToGSM(
  1094.                     (PU8) in_name,
  1095.                     phb_entry->alpha_id.name,
  1096.                     MAX_PS_NAME_LENGTH,
  1097.                     MMI_PHB_UCS2,
  1098.                     0,
  1099.                     1);
  1100.             }
  1101.         }
  1102.         else
  1103.         {
  1104.             phb_entry->alpha_id.name_dcs = MMI_PHB_ASCII;
  1105.             phb_entry->alpha_id.name_length = InputboxConvertDeviceEncodingToGSM(
  1106.                                                 (PU8) in_name,
  1107.                                                 phb_entry->alpha_id.name,
  1108.                                                 MAX_PS_NAME_LENGTH,
  1109.                                                 MMI_PHB_ASCII,
  1110.                                                 0,
  1111.                                                 1) - 1;
  1112.         }
  1113.     }
  1114. }
  1115. /*****************************************************************************
  1116.  * FUNCTION
  1117.  *  mmi_phb_op_set_entry_prepare_name_number_by_index
  1118.  * DESCRIPTION
  1119.  *  prepare name and number by store index before send to L4
  1120.  * PARAMETERS
  1121.  *  dst_msg         [?]         
  1122.  *  store_index     [IN]        
  1123.  * RETURNS
  1124.  *  void
  1125.  *****************************************************************************/
  1126. void mmi_phb_op_set_entry_prepare_name_number_by_index(void *dst_msg, U16 store_index)
  1127. {
  1128.     /*----------------------------------------------------------------*/
  1129.     /* Local Variables                                                */
  1130.     /*----------------------------------------------------------------*/
  1131.     l4c_phb_entry_struct *phb_entry = (l4c_phb_entry_struct*) dst_msg;
  1132. #if defined(__PHB_0x81_SUPPORT__)
  1133.     U8 length;
  1134.     S8 *in_name = OslMalloc((MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH);
  1135.     /*----------------------------------------------------------------*/
  1136.     /* Code Body                                                      */
  1137.     /*----------------------------------------------------------------*/
  1138.     memcpy(in_name, PhoneBook[store_index].alpha_id.name, (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH);
  1139. #endif /* defined(__PHB_0x81_SUPPORT__) */ 
  1140.     phb_entry->alpha_id.name_length = PhoneBook[store_index].alpha_id.name_length;
  1141.     phb_entry->alpha_id.name_dcs = PhoneBook[store_index].alpha_id.name_dcs;
  1142. #if defined(__PHB_0x81_SUPPORT__)       /* Support maximum length of 0x81 UCS2 */
  1143.     if ((PhoneBook[store_index].alpha_id.name_dcs == MMI_PHB_UCS2)
  1144.         && ((length = mmi_phb_convert_to_0x81(in_name, TRUE)) > 0))
  1145.     {
  1146.         phb_entry->alpha_id.name_dcs = 0x09;
  1147.         phb_entry->alpha_id.name_length = length;
  1148.         memcpy(phb_entry->alpha_id.name, in_name, length);
  1149.         memset(phb_entry->alpha_id.name + length, 0x00, 1);
  1150.     }
  1151.     else
  1152. #endif /* defined(__PHB_0x81_SUPPORT__) */ 
  1153.     {
  1154.         InputboxConvertDeviceEncodingToGSM(
  1155.             PhoneBook[store_index].alpha_id.name,
  1156.             phb_entry->alpha_id.name,
  1157.             MAX_PS_NAME_LENGTH,
  1158.             PhoneBook[store_index].alpha_id.name_dcs,
  1159.             0,
  1160.             1);
  1161.     }
  1162.     phb_entry->tel.type = PhoneBook[store_index].tel.type;
  1163.     /* myMsgPtr->list.tel.length = PhoneBook[store_index].tel.length; */
  1164.     mmi_phb_convert_to_digit(phb_entry->tel.number, PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  1165.     phb_entry->tel.length = strlen((S8*) phb_entry->tel.number);
  1166. #if defined(__PHB_0x81_SUPPORT__)
  1167.     OslMfree(in_name);
  1168. #endif 
  1169. }
  1170. /*****************************************************************************
  1171.  * FUNCTION
  1172.  *  mmi_phb_op_set_entry_rsp_name_number
  1173.  * DESCRIPTION
  1174.  *  set name and number in the set entry response message.
  1175.  * PARAMETERS
  1176.  *  rsp_msg         [?]         
  1177.  *  store_index     [IN]        
  1178.  * RETURNS
  1179.  *  void
  1180.  *****************************************************************************/
  1181. void mmi_phb_op_set_entry_rsp_name_number(void *rsp_msg, U16 store_index)
  1182. {
  1183.     /*----------------------------------------------------------------*/
  1184.     /* Local Variables                                                */
  1185.     /*----------------------------------------------------------------*/
  1186.     l4c_phb_entry_struct *localPtr;
  1187.     /*----------------------------------------------------------------*/
  1188.     /* Code Body                                                      */
  1189.     /*----------------------------------------------------------------*/
  1190.     localPtr = (l4c_phb_entry_struct*) rsp_msg;
  1191.     PhoneBook[store_index].alpha_id.name_length = localPtr->alpha_id.name_length;
  1192.     PhoneBook[store_index].alpha_id.name_dcs = localPtr->alpha_id.name_dcs;
  1193.     InputboxConvertGSMToDeviceEncoding(
  1194.         localPtr->alpha_id.name,
  1195.         PhoneBook[store_index].alpha_id.name,
  1196.         localPtr->alpha_id.name_length,
  1197.         (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH,
  1198.         localPtr->alpha_id.name_dcs,
  1199.         0,
  1200.         1);
  1201. #if defined(__PHB_0x81_SUPPORT__)       /* Support maximum length of 0x81 UCS2 */
  1202.     if (PhoneBook[store_index].alpha_id.name_dcs == MMI_PHB_UCS2_81 ||
  1203.         PhoneBook[store_index].alpha_id.name_dcs == MMI_PHB_UCS2_82)
  1204.     {
  1205.         PhoneBook[store_index].alpha_id.name_dcs = MMI_PHB_UCS2;
  1206.     }
  1207. #endif /* defined(__PHB_0x81_SUPPORT__) */ 
  1208.     PhoneBook[store_index].tel.type = localPtr->tel.type;
  1209.     PhoneBook[store_index].tel.length = localPtr->tel.length;
  1210.     mmi_phb_convert_to_bcd(PhoneBook[store_index].tel.number, localPtr->tel.number, (MAX_PB_NUMBER_LENGTH + 1) / 2);
  1211. }
  1212. /*****************************************************************************
  1213.  * FUNCTION
  1214.  *  mmi_phb_op_get_store_index_and_increase_counter
  1215.  * DESCRIPTION
  1216.  *  Use storage and record_index to get phonebook store_index(store position in the array)
  1217.  * PARAMETERS
  1218.  *  storage             [IN]        
  1219.  *  record_index        [IN]        
  1220.  * RETURNS
  1221.  *  void
  1222.  *****************************************************************************/
  1223. U16 mmi_phb_op_get_store_index_and_increase_counter(U8 storage, U16 record_index)
  1224. {
  1225.     /*----------------------------------------------------------------*/
  1226.     /* Local Variables                                                */
  1227.     /*----------------------------------------------------------------*/
  1228.     U16 store_index;
  1229.     /*----------------------------------------------------------------*/
  1230.     /* Code Body                                                      */
  1231.     /*----------------------------------------------------------------*/
  1232.     if (storage == MMI_SIM)
  1233.     {
  1234.         g_phb_cntx.sim_used++;
  1235.         store_index = record_index + MAX_PB_PHONE_ENTRIES - 1;  /* Storage Location in array. */
  1236.         MMI_ASSERT((g_phb_cntx.sim_used <= g_phb_cntx.sim_total) && (store_index < MAX_PB_ENTRIES));
  1237.     }
  1238.     else
  1239.     {
  1240.         g_phb_cntx.phone_used++;
  1241.         store_index = record_index - 1; /* Storage Location in array. */
  1242.         MMI_ASSERT((g_phb_cntx.phone_used <= g_phb_cntx.phone_total) && (store_index < MAX_PB_PHONE_ENTRIES));
  1243.     }
  1244.     return store_index;
  1245. }
  1246. /*****************************************************************************
  1247.  * FUNCTION
  1248.  *  mmi_phb_op_clear_lookup_table_by_index
  1249.  * DESCRIPTION
  1250.  *  clear one entry in number lookup table
  1251.  * PARAMETERS
  1252.  *  store_index     [IN]        
  1253.  * RETURNS
  1254.  *  void
  1255.  *****************************************************************************/
  1256. U16 mmi_phb_op_clear_lookup_table_by_index(U16 store_index)
  1257. {
  1258.     /*----------------------------------------------------------------*/
  1259.     /* Local Variables                                                */
  1260.     /*----------------------------------------------------------------*/
  1261.     U16 deletedCnt = 0;
  1262.     U16 k;
  1263.     /*----------------------------------------------------------------*/
  1264.     /* Code Body                                                      */
  1265.     /*----------------------------------------------------------------*/
  1266.     for (k = 0; k < g_phb_cntx.lookup_table_count; ++k)
  1267.     {
  1268.         if (LookUpTable[k].store_index == store_index)
  1269.         {
  1270.             LookUpTable[k].number = INVALID_NUMBER;
  1271.             deletedCnt++;
  1272.         }
  1273.     }
  1274.     return deletedCnt;
  1275. }
  1276. /*****************************************************************************
  1277.  * FUNCTION
  1278.  *  mmi_phb_op_increase_lookup_table
  1279.  * DESCRIPTION
  1280.  *  add one entry into lookup table
  1281.  * PARAMETERS
  1282.  *  store_index     [IN]        
  1283.  *  number          [?]         
  1284.  *  fax             [?]         
  1285.  *  home            [?]         
  1286.  *  office          [?]         
  1287.  * RETURNS
  1288.  *  void
  1289.  *****************************************************************************/
  1290. U8 mmi_phb_op_increase_lookup_table(U16 store_index, S8 *number, S8 *fax, S8 *home, S8 *office)
  1291. {
  1292.     /*----------------------------------------------------------------*/
  1293.     /* Local Variables                                                */
  1294.     /*----------------------------------------------------------------*/
  1295.     U32 temp;
  1296.     U8 flag = 0;
  1297.     /*----------------------------------------------------------------*/
  1298.     /* Code Body                                                      */
  1299.     /*----------------------------------------------------------------*/
  1300.     if (number != NULL)
  1301.     {
  1302.         temp = mmi_phb_util_convert_number_to_int((U8*) number);
  1303.         if (temp < INVALID_NUMBER && g_phb_cntx.lookup_table_count < MAX_LOOKUP_TABLE_COUNT)
  1304.         {
  1305.             flag = 1;
  1306.             LookUpTable[g_phb_cntx.lookup_table_count].store_index = store_index;
  1307.             LookUpTable[g_phb_cntx.lookup_table_count++].number = temp;
  1308.         }
  1309.     }
  1310.     if (fax != NULL)
  1311.     {
  1312.         temp = mmi_phb_util_convert_number_to_int((U8*) fax);
  1313.         if (temp < INVALID_NUMBER && g_phb_cntx.lookup_table_count < MAX_LOOKUP_TABLE_COUNT)
  1314.         {
  1315.             flag = 1;
  1316.             LookUpTable[g_phb_cntx.lookup_table_count].store_index = store_index;
  1317.             LookUpTable[g_phb_cntx.lookup_table_count++].number = temp;
  1318.         }
  1319.     }
  1320.     if (home != NULL)
  1321.     {
  1322.         temp = mmi_phb_util_convert_number_to_int((U8*) home);
  1323.         if (temp < INVALID_NUMBER && g_phb_cntx.lookup_table_count < MAX_LOOKUP_TABLE_COUNT)
  1324.         {
  1325.             flag = 1;
  1326.             LookUpTable[g_phb_cntx.lookup_table_count].store_index = store_index;
  1327.             LookUpTable[g_phb_cntx.lookup_table_count++].number = temp;
  1328.         }
  1329.     }
  1330.     if (office != NULL)
  1331.     {
  1332.         temp = mmi_phb_util_convert_number_to_int((U8*) office);
  1333.         if (temp < INVALID_NUMBER && g_phb_cntx.lookup_table_count < MAX_LOOKUP_TABLE_COUNT)
  1334.         {
  1335.             flag = 1;
  1336.             LookUpTable[g_phb_cntx.lookup_table_count].store_index = store_index;
  1337.             LookUpTable[g_phb_cntx.lookup_table_count++].number = temp;
  1338.         }
  1339.     }
  1340.     return flag;
  1341. }
  1342. /*****************************************************************************
  1343.  * FUNCTION
  1344.  *  mmi_phb_op_update_field_flag
  1345.  * DESCRIPTION
  1346.  *  update fileter flag of each entry.
  1347.  * PARAMETERS
  1348.  *  store_index     [IN]        
  1349.  *  number          [?]         
  1350.  *  home            [?]         
  1351.  *  office          [?]         
  1352.  *  fax             [?]         
  1353.  *  email           [?]         
  1354.  *  is_new          [IN]        
  1355.  * RETURNS
  1356.  *  void
  1357.  *****************************************************************************/
  1358. void mmi_phb_op_update_field_flag(
  1359.         U16 store_index,
  1360.         S8 *number,
  1361.         S8 *home,
  1362.         S8 *office,
  1363.         S8 *fax,
  1364.         S8 *email,
  1365.         BOOL is_new)
  1366. {
  1367.     /*----------------------------------------------------------------*/
  1368.     /* Local Variables                                                */
  1369.     /*----------------------------------------------------------------*/
  1370.     /*----------------------------------------------------------------*/
  1371.     /* Code Body                                                      */
  1372.     /*----------------------------------------------------------------*/
  1373.     /* New record, clear first. */
  1374.     if (is_new)
  1375.     {
  1376.         PhoneBook[store_index].field = 0;
  1377.     }
  1378.     if (number != NULL)
  1379.     {
  1380.         if (strlen(number))
  1381.         {
  1382.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_NUMBER;
  1383.         }
  1384.         else if (!is_new)   /* Clear flag when the field is empty and the record is not a new record */
  1385.         {
  1386.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_NUMBER;
  1387.         }
  1388.     }
  1389. #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  1390.     if (home != NULL)
  1391.     {
  1392.         if (strlen(home) > 0)
  1393.         {
  1394.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_HOME;
  1395.         }
  1396.         else if (!is_new)
  1397.         {
  1398.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_HOME;
  1399.         }
  1400.     }
  1401.     if (office != NULL)
  1402.     {
  1403.         if (strlen(office) > 0)
  1404.         {
  1405.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_OFFICE;
  1406.         }
  1407.         else if (!is_new)
  1408.         {
  1409.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_OFFICE;
  1410.         }
  1411.     }
  1412.     if (fax != NULL)
  1413.     {
  1414.         if (strlen(fax) > 0)
  1415.         {
  1416.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_FAX;
  1417.         }
  1418.         else if (!is_new)
  1419.         {
  1420.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_FAX;
  1421.         }
  1422.     }
  1423.     if (email != NULL)
  1424.     {
  1425.         if (strlen(email) > 0)
  1426.         {
  1427.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_EMAIL;
  1428.         }
  1429.         else if (!is_new)
  1430.         {
  1431.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_EMAIL;
  1432.         }
  1433.     }
  1434. #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  1435. }
  1436. #ifdef __MMI_PHB_USIM_FIELD__
  1437. /*****************************************************************************
  1438.  * FUNCTION
  1439.  *  mmi_phb_op_copy_all_to_usim_one_after_one_rsp
  1440.  * DESCRIPTION
  1441.  *  copy all one entry set response.
  1442.  * PARAMETERS
  1443.  *  info        [?]     
  1444.  * RETURNS
  1445.  *  void
  1446.  *****************************************************************************/
  1447. static void mmi_phb_op_copy_all_to_usim_one_after_one_rsp(void *info)
  1448. {
  1449.     /*----------------------------------------------------------------*/
  1450.     /* Local Variables                                                */
  1451.     /*----------------------------------------------------------------*/
  1452.     MSG_PHB_SET_USIM_ENRTY_RSP_STRUCT *localPtr;
  1453.     U8 copy_from, copy_to = 0;
  1454.     U16 store_index;
  1455.     U32 temp;
  1456.     /*----------------------------------------------------------------*/
  1457.     /* Code Body                                                      */
  1458.     /*----------------------------------------------------------------*/
  1459.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_op_copy_all_to_usim_one_after_one_rsp.>n",
  1460.                          __FILE__, __LINE__));
  1461.     localPtr = (MSG_PHB_SET_USIM_ENRTY_RSP_STRUCT*) info;
  1462.     if (localPtr->result.flag == 0 /* OK */ )
  1463.     {
  1464.         g_phb_cntx.sim_used++;
  1465.         store_index = localPtr->list.record_index + MAX_PB_PHONE_ENTRIES - 1;   /* Storage Location in array. */
  1466.         copy_to = MMI_SIM;
  1467.         copy_from = MMI_NVRAM;
  1468.         /* Populate Number Field */
  1469.         temp = mmi_phb_util_convert_number_to_int(localPtr->list.tel.number);
  1470.         if (temp < INVALID_NUMBER)
  1471.         {
  1472.             LookUpTable[g_phb_cntx.lookup_table_count].store_index = store_index;
  1473.             LookUpTable[g_phb_cntx.lookup_table_count++].number = temp;
  1474.         }
  1475.         /* Add result to Phonebook Storage */
  1476.         mmi_phb_op_set_entry_rsp_name_number(&localPtr->list, store_index);
  1477.         /* Update field flag */
  1478.         mmi_phb_op_set_entry_usim_fields(&PhoneBookOptionalFields, store_index);
  1479.         mmi_phb_op_update_usim_field_flag(
  1480.             store_index,
  1481.             (S8*) localPtr->list.tel.number,
  1482.             (S8*) PhoneBookOptionalFields.homeNumber,
  1483.             (S8*) PhoneBookOptionalFields.officeNumber,
  1484.             (S8*) PhoneBookOptionalFields.faxNumber,
  1485.             (S8*) PhoneBookOptionalFields.emailAddress,
  1486.             TRUE);
  1487.         mmi_phb_op_increase_lookup_table(
  1488.             store_index,
  1489.             NULL,
  1490.             (S8*) PhoneBookOptionalFields.faxNumber,
  1491.             (S8*) PhoneBookOptionalFields.homeNumber,
  1492.             (S8*) PhoneBookOptionalFields.officeNumber);
  1493.     #if defined(__MMI_PHB_PINYIN_SORT__)    /* Make Pinyin cache for later sorting. */
  1494.         mmi_phb_util_make_pinyin_cache(store_index);
  1495.     #endif 
  1496.         /* Append new entry in the end of sorted list. Sorting when copy all done. */
  1497.         g_phb_name_index[PhoneBookEntryCount] = store_index;
  1498.         PhoneBookEntryCount++;
  1499.         g_phb_mass_op_count++;
  1500.         /* Insert email to email mapping table, not like name field, it should sort here. */
  1501.     #if defined(__MMI_PHB_EMAIL_SORT__)
  1502.         if (g_phb_email_sorted == 1)
  1503.         {
  1504.             mmi_phb_sort_email_insert_index(store_index);
  1505.         }
  1506.     #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  1507.         if (g_phb_mass_op_abort)
  1508.         {
  1509.             g_phb_mass_op_success = FALSE;
  1510.             mmi_phb_op_copy_all_done();
  1511.         }
  1512.         else
  1513.         {
  1514.             if ((copy_to == MMI_SIM && g_phb_mass_op_count < g_phb_cntx.phone_used))
  1515.             {
  1516.                 ++g_phb_mass_op_index;
  1517.                 mmi_phb_op_copy_all_to_usim_one_after_one_req();
  1518.             }
  1519.             else
  1520.             {
  1521.                 mmi_phb_op_copy_all_done();
  1522.             }
  1523.         }
  1524.     }
  1525.     else
  1526.     {
  1527.         g_phb_mass_op_success = FALSE;
  1528.         copy_from = MMI_NVRAM;
  1529.         /* Not copy fail due to capacity full. */
  1530.         if ((localPtr->result.cause != MMI_PHB_CAUSE_CAPACITY_EXCEEDED) &&
  1531.             ((copy_from == MMI_NVRAM && g_phb_mass_op_count < g_phb_cntx.phone_used)))
  1532.         {
  1533.             g_phb_mass_op_index++;
  1534.             mmi_phb_op_copy_all_to_usim_one_after_one_req();
  1535.         }
  1536.         else
  1537.         {
  1538.             mmi_phb_op_copy_all_done();
  1539.         }
  1540.     }
  1541. }
  1542. /*****************************************************************************
  1543.  * FUNCTION
  1544.  *  mmi_phb_op_copy_all_to_usim_one_after_one_req
  1545.  * DESCRIPTION
  1546.  *  Copy all one entry after one.
  1547.  * PARAMETERS
  1548.  *  void
  1549.  * RETURNS
  1550.  *  void
  1551.  *****************************************************************************/
  1552. static void mmi_phb_op_copy_all_to_usim_one_after_one_req(void)
  1553. {
  1554.     /*----------------------------------------------------------------*/
  1555.     /* Local Variables                                                */
  1556.     /*----------------------------------------------------------------*/
  1557.     MSG_PHB_SET_USIM_ENRTY_REQ_STRUCT *myMsgPtr;
  1558.     MYQUEUE Message;
  1559.     U16 store_index;
  1560.     /*----------------------------------------------------------------*/
  1561.     /* Code Body                                                      */
  1562.     /*----------------------------------------------------------------*/
  1563.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_op_copy_all_to_usim_one_after_one_req.>n",
  1564.                          __FILE__, __LINE__));
  1565.     while ((g_phb_name_index[g_phb_mass_op_index] >= MAX_PB_PHONE_ENTRIES) && (g_phb_mass_op_index < PhoneBookEntryCount))      /* Not in NVRAM */
  1566.     {
  1567.         g_phb_mass_op_index++;
  1568.     }
  1569.     if (g_phb_mass_op_index >= PhoneBookEntryCount)
  1570.     {
  1571.         mmi_phb_op_copy_all_done();
  1572.         return;
  1573.     }
  1574.     store_index = g_phb_name_index[g_phb_mass_op_index];
  1575. #if defined(__MMI_PHB_PINYIN_SORT__)    /* Make Pinyin cache for later sorting. */
  1576.     mmi_phb_util_make_pinyin_cache(store_index);
  1577. #endif 
  1578.     myMsgPtr = (MSG_PHB_SET_USIM_ENRTY_REQ_STRUCT*) OslConstructDataPtr(sizeof(MSG_PHB_SET_USIM_ENRTY_REQ_STRUCT));
  1579.     myMsgPtr->type = MMI_PHB_PHONEBOOK;
  1580.     myMsgPtr->no_data = 1;
  1581.     myMsgPtr->list.index = 0xFFFF;
  1582.     myMsgPtr->list.record_index = 0xFFFF;
  1583.     myMsgPtr->list.storage = MMI_SIM;
  1584.     myMsgPtr->anra.record_index = 0xFFFF;
  1585.     myMsgPtr->anrb.record_index = 0xFFFF;
  1586.     myMsgPtr->anrc.record_index = 0xFFFF;
  1587.     myMsgPtr->email.adn_record_index = 0xFFFF;
  1588.     mmi_phb_op_set_entry_prepare_name_number_by_index(&myMsgPtr->list, store_index);
  1589.     mmi_phb_op_set_entry_prepare_usim_data_by_index(store_index);
  1590.     mmi_phb_op_set_entry_prepare_usim_data(
  1591.         myMsgPtr,
  1592.         pbNickName,
  1593.         pbHomeNumber,
  1594.         pbOfficeNumber,
  1595.         pbFaxNumber,
  1596.         pbEmailAddress);
  1597.     myMsgPtr->group_type = 0;
  1598.     // TODO: hidden info
  1599.     //myMsgPtr->hidden_info = ;
  1600.     Message.oslSrcId = MOD_MMI;
  1601.     Message.oslDestId = MOD_L4C;
  1602.     Message.oslMsgId = PRT_PHB_WRITE_USIM_REQ;
  1603.     Message.oslDataPtr = (oslParaType*) myMsgPtr;
  1604.     Message.oslPeerBuffPtr = NULL;
  1605.     SetProtocolEventHandler(mmi_phb_op_copy_all_to_usim_one_after_one_rsp, PRT_PHB_WRITE_USIM_RSP);
  1606.     OslMsgSendExtQueue(&Message);
  1607. }
  1608. /*****************************************************************************
  1609.  * FUNCTION
  1610.  *  mmi_phb_op_set_entry_usim_fields
  1611.  * DESCRIPTION
  1612.  *  set name and number in the set entry response message.
  1613.  * PARAMETERS
  1614.  *  field_msg       [?]         
  1615.  *  store_index     [IN]        
  1616.  * RETURNS
  1617.  *  void
  1618.  *****************************************************************************/
  1619. void mmi_phb_op_set_entry_usim_fields(void *field_msg, U16 store_index)
  1620. {
  1621.     /*----------------------------------------------------------------*/
  1622.     /* Local Variables                                                */
  1623.     /*----------------------------------------------------------------*/
  1624.     PHB_OPTIONAL_FIELDS_STRUCT *localPtr = (PHB_OPTIONAL_FIELDS_STRUCT*) field_msg;
  1625.     /*----------------------------------------------------------------*/
  1626.     /* Code Body                                                      */
  1627.     /*----------------------------------------------------------------*/
  1628.     ASSERT(store_index >= MAX_PB_PHONE_ENTRIES);
  1629.     store_index -= MAX_PB_PHONE_ENTRIES;
  1630.     if (localPtr->homeNumber[0] == '+')
  1631.     {
  1632.         phb_anr[store_index][0].type = MMI_CSMCC_INTERNATIONAL_ADDR;    /* INTERNATIONAL */
  1633.         phb_anr[store_index][0].length = 
  1634.             mmi_phb_convert_to_bcd(phb_anr[store_index][0].number, localPtr->homeNumber + 1, (MAX_PB_NUMBER_LENGTH + 1) / 2);
  1635.     }
  1636.     else
  1637.     {
  1638.         phb_anr[store_index][0].type = MMI_CSMCC_DEFAULT_ADDR_TYPE;     /* DEFAULT */
  1639.         phb_anr[store_index][0].length = 
  1640.             mmi_phb_convert_to_bcd(phb_anr[store_index][0].number, localPtr->homeNumber, (MAX_PB_NUMBER_LENGTH + 1) / 2);
  1641.     }
  1642.     if (localPtr->officeNumber[0] == '+')
  1643.     {
  1644.         phb_anr[store_index][1].type = MMI_CSMCC_INTERNATIONAL_ADDR;    /* INTERNATIONAL */
  1645.         phb_anr[store_index][1].length = 
  1646.             mmi_phb_convert_to_bcd(phb_anr[store_index][1].number, localPtr->officeNumber + 1, (MAX_PB_NUMBER_LENGTH + 1) / 2);
  1647.     }
  1648.     else
  1649.     {
  1650.         phb_anr[store_index][1].type = MMI_CSMCC_DEFAULT_ADDR_TYPE;     /* DEFAULT */
  1651.         phb_anr[store_index][1].length = 
  1652.             mmi_phb_convert_to_bcd(phb_anr[store_index][1].number, localPtr->officeNumber, (MAX_PB_NUMBER_LENGTH + 1) / 2);
  1653.     }
  1654.     if (localPtr->faxNumber[0] == '+')
  1655.     {
  1656.         phb_anr[store_index][2].type = MMI_CSMCC_INTERNATIONAL_ADDR;    /* INTERNATIONAL */
  1657.         phb_anr[store_index][2].length = 
  1658.             mmi_phb_convert_to_bcd(phb_anr[store_index][2].number, localPtr->faxNumber + 1, (MAX_PB_NUMBER_LENGTH + 1) / 2);
  1659.     }
  1660.     else
  1661.     {
  1662.         phb_anr[store_index][2].type = MMI_CSMCC_DEFAULT_ADDR_TYPE;     /* DEFAULT */
  1663.         phb_anr[store_index][2].length = 
  1664.             mmi_phb_convert_to_bcd(phb_anr[store_index][2].number, localPtr->faxNumber, (MAX_PB_NUMBER_LENGTH + 1) / 2);
  1665.     }
  1666.     UnicodeToAnsii((S8*) phb_email[store_index].email_address, (S8*) pbEmailAddress);
  1667. }
  1668. /*****************************************************************************
  1669.  * FUNCTION
  1670.  *  mmi_phb_op_update_usim_field_flag
  1671.  * DESCRIPTION
  1672.  *  update fileter flag of each entry.
  1673.  * PARAMETERS
  1674.  *  store_index     [IN]        
  1675.  *  number          [?]         
  1676.  *  anra            [?]         
  1677.  *  anrb            [?]         
  1678.  *  anrc            [?]         
  1679.  *  email           [?]         
  1680.  *  is_new          [IN]        
  1681.  * RETURNS
  1682.  *  void
  1683.  *****************************************************************************/
  1684. void mmi_phb_op_update_usim_field_flag(
  1685.         U16 store_index,
  1686.         S8 *number,
  1687.         S8 *anra,
  1688.         S8 *anrb,
  1689.         S8 *anrc,
  1690.         S8 *email,
  1691.         BOOL is_new)
  1692. {
  1693.     /*----------------------------------------------------------------*/
  1694.     /* Local Variables                                                */
  1695.     /*----------------------------------------------------------------*/
  1696.     /*----------------------------------------------------------------*/
  1697.     /* Code Body                                                      */
  1698.     /*----------------------------------------------------------------*/
  1699.     /* New record, clear first. */
  1700.     if (is_new)
  1701.     {
  1702.         PhoneBook[store_index].field = 0;
  1703.     }
  1704.     if (number != NULL)
  1705.     {
  1706.         if (strlen(number))
  1707.         {
  1708.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_NUMBER;
  1709.         }
  1710.         else if (!is_new)   /* Clear flag when the field is empty and the record is not a new record */
  1711.         {
  1712.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_NUMBER;
  1713.         }
  1714.     }
  1715.     if (anra != NULL)
  1716.     {
  1717.         if (strlen(anra) > 0)
  1718.         {
  1719.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_ANRA;
  1720.         }
  1721.         else if (!is_new)
  1722.         {
  1723.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_ANRA;
  1724.         }
  1725.     }
  1726.     if (anrb != NULL)
  1727.     {
  1728.         if (strlen(anrb) > 0)
  1729.         {
  1730.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_ANRB;
  1731.         }
  1732.         else if (!is_new)
  1733.         {
  1734.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_ANRB;
  1735.         }
  1736.     }
  1737.     if (anrc != NULL)
  1738.     {
  1739.         if (strlen(anrc) > 0)
  1740.         {
  1741.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_ANRC;
  1742.         }
  1743.         else if (!is_new)
  1744.         {
  1745.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_ANRC;
  1746.         }
  1747.     }
  1748.     if (email != NULL)
  1749.     {
  1750.         if (strlen(email) > 0)
  1751.         {
  1752.             PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_EMAIL;
  1753.         }
  1754.         else if (!is_new)
  1755.         {
  1756.             PhoneBook[store_index].field &= ~MMI_PHB_ENTRY_FIELD_EMAIL;
  1757.         }
  1758.     }
  1759. }
  1760. /*****************************************************************************
  1761.  * FUNCTION
  1762.  *  mmi_phb_op_set_entry_prepare_usim_data_by_index
  1763.  * DESCRIPTION
  1764.  *  
  1765.  * PARAMETERS
  1766.  *  index       [IN]        
  1767.  * RETURNS
  1768.  *  void
  1769.  *****************************************************************************/
  1770. void mmi_phb_op_set_entry_prepare_usim_data_by_index(U16 index)
  1771. {
  1772.     /*----------------------------------------------------------------*/
  1773.     /* Local Variables                                                */
  1774.     /*----------------------------------------------------------------*/
  1775.     /*----------------------------------------------------------------*/
  1776.     /* Code Body                                                      */
  1777.     /*----------------------------------------------------------------*/
  1778.     /* memset(pbNumber, 0, ENCODING_LENGTH); */
  1779.     memset(pbHomeNumber, 0, ENCODING_LENGTH);
  1780.     memset(pbEmailAddress, 0, ENCODING_LENGTH);
  1781.     memset(pbOfficeNumber, 0, ENCODING_LENGTH);
  1782.     memset(pbFaxNumber, 0, ENCODING_LENGTH);
  1783.     memset(pbEmailAddress, 0, ENCODING_LENGTH);
  1784.     /* mmi_phb_convert_get_ucs2_number((S8*)pbNumber, index); */
  1785.     if (index < MAX_PB_PHONE_ENTRIES)   /* from nvram */
  1786.     {
  1787.     #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  1788.         S16 pError;
  1789.         ReadRecord(
  1790.             NVRAM_EF_PHB_FIELDS_LID,
  1791.             (U16) (index + 1),
  1792.             (void*)&PhoneBookOptionalFields,
  1793.             OPTIONAL_FIELDS_RECORD_SIZE,
  1794.             &pError);
  1795.         AnsiiToUnicodeString(pbHomeNumber, (PS8) PhoneBookOptionalFields.homeNumber);
  1796.         AnsiiToUnicodeString(pbEmailAddress, (PS8) PhoneBookOptionalFields.emailAddress);
  1797.         AnsiiToUnicodeString(pbOfficeNumber, (PS8) PhoneBookOptionalFields.officeNumber);
  1798.         AnsiiToUnicodeString(pbFaxNumber, (PS8) PhoneBookOptionalFields.faxNumber);
  1799.     #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  1800.     }
  1801.     else
  1802.     {
  1803.         mmi_phb_convert_get_ucs2_anr((S8*) pbHomeNumber, (S8*) pbOfficeNumber, (S8*) pbFaxNumber, index);
  1804.         if (index >= MAX_PB_PHONE_ENTRIES)
  1805.         {
  1806.             AnsiiToUnicodeString((S8*) pbEmailAddress, (S8*) phb_email[index - MAX_PB_PHONE_ENTRIES].email_address);
  1807.         }
  1808.     }
  1809. }
  1810. /*****************************************************************************
  1811.  * FUNCTION
  1812.  *  mmi_phb_op_set_entry_prepare_usim_data
  1813.  * DESCRIPTION
  1814.  *  prepare usim fields (except name and number) by user input  before send to L4
  1815.  * PARAMETERS
  1816.  *  dst_msg         [?]     
  1817.  *  in_name         [?]     
  1818.  *  in_num          [?]     
  1819.  *  in_numb         [?]     
  1820.  *  in_numc         [?]     
  1821.  *  in_email        [?]     
  1822.  * RETURNS
  1823.  *  void
  1824.  *****************************************************************************/
  1825. void mmi_phb_op_set_entry_prepare_usim_data(
  1826.         void *dst_msg,
  1827.         S8 *in_name,
  1828.         S8 *in_num,
  1829.         S8 *in_numb,
  1830.         S8 *in_numc,
  1831.         S8 *in_email)
  1832. {
  1833.     /*----------------------------------------------------------------*/
  1834.     /* Local Variables                                                */
  1835.     /*----------------------------------------------------------------*/
  1836.     MSG_PHB_SET_USIM_ENRTY_REQ_STRUCT *myMsgPtr;
  1837. #if defined(__PHB_0x81_SUPPORT__)
  1838.     U8 length;
  1839. #endif 
  1840.     /*----------------------------------------------------------------*/
  1841.     /* Code Body                                                      */
  1842.     /*----------------------------------------------------------------*/
  1843.     myMsgPtr = (MSG_PHB_SET_USIM_ENRTY_REQ_STRUCT*) dst_msg;
  1844.     if (dst_msg == NULL)
  1845.     {
  1846.         return;
  1847.     }
  1848.     if (in_name != NULL)
  1849.     {
  1850.         /* Prepare Second Name Data */
  1851.         if (GetUCS2Flag(in_name))
  1852.         {
  1853.         #if defined(__PHB_0x81_SUPPORT__)       /* Support maximum length of 0x81 UCS2 */
  1854.             if ((length = mmi_phb_convert_to_0x81((S8*) in_name, TRUE)) > 0)
  1855.             {
  1856.                 myMsgPtr->sne.name_dcs = 0x09;
  1857.                 myMsgPtr->sne.name_length = length;
  1858.                 memcpy(myMsgPtr->sne.name, in_name, length);
  1859.                 memset(myMsgPtr->sne.name + length, 0x00, 1);
  1860.             }
  1861.             else
  1862.         #endif /* defined(__PHB_0x81_SUPPORT__) */ 
  1863.             {
  1864.                 myMsgPtr->sne.name_dcs = MMI_PHB_UCS2;
  1865.                 myMsgPtr->sne.name_length = ((U8) pfnUnicodeStrlen(in_name)) * ENCODING_LENGTH;
  1866.                 InputboxConvertDeviceEncodingToGSM(
  1867.                     (PU8) in_name,
  1868.                     myMsgPtr->sne.name,
  1869.                     MAX_PS_NAME_LENGTH,
  1870.                     MMI_PHB_UCS2,
  1871.                     0,
  1872.                     1);
  1873.             }
  1874.         }
  1875.         else
  1876.         {
  1877.             myMsgPtr->sne.name_dcs = MMI_PHB_ASCII;
  1878.             myMsgPtr->sne.name_length = InputboxConvertDeviceEncodingToGSM(
  1879.                                             (PU8) in_name,
  1880.                                             myMsgPtr->sne.name,
  1881.                                             MAX_PS_NAME_LENGTH,
  1882.                                             MMI_PHB_ASCII,
  1883.                                             0,
  1884.                                             1) - 1;
  1885.         }
  1886.     }
  1887.     if (in_num != NULL)
  1888.     {
  1889.         /* Prepare Addtional Number A Data */
  1890.         if (in_num[0] == '+')
  1891.         {
  1892.             myMsgPtr->anra.tel_number.type = MMI_CSMCC_INTERNATIONAL_ADDR;      /* INTERNATIONAL */
  1893.             myMsgPtr->anra.tel_number.length = (U8) pfnUnicodeStrlen(in_num + ENCODING_LENGTH); /* Exclude "+" */
  1894.             UnicodeToAnsii((PS8) myMsgPtr->anra.tel_number.number, in_num + ENCODING_LENGTH);
  1895.         }
  1896.         else
  1897.         {
  1898.             myMsgPtr->anra.tel_number.type = MMI_CSMCC_DEFAULT_ADDR_TYPE;       /* DEFAULT */
  1899.             myMsgPtr->anra.tel_number.length = (U8) pfnUnicodeStrlen(in_num);
  1900.             UnicodeToAnsii((PS8) myMsgPtr->anra.tel_number.number, in_num);
  1901.         }
  1902.     }
  1903.     if (in_numb != NULL)
  1904.     {
  1905.         /* Prepare Addtional Number B Data */
  1906.         if (in_num[0] == '+')
  1907.         {
  1908.             myMsgPtr->anrb.tel_number.type = MMI_CSMCC_INTERNATIONAL_ADDR;      /* INTERNATIONAL */
  1909.             myMsgPtr->anrb.tel_number.length = (U8) pfnUnicodeStrlen(in_numb + ENCODING_LENGTH);        /* Exclude "+" */
  1910.             UnicodeToAnsii((PS8) myMsgPtr->anrb.tel_number.number, in_numb + ENCODING_LENGTH);
  1911.         }
  1912.         else
  1913.         {
  1914.             myMsgPtr->anrb.tel_number.type = MMI_CSMCC_DEFAULT_ADDR_TYPE;       /* DEFAULT */
  1915.             myMsgPtr->anrb.tel_number.length = (U8) pfnUnicodeStrlen(in_numb);
  1916.             UnicodeToAnsii((PS8) myMsgPtr->anrb.tel_number.number, in_numb);
  1917.         }
  1918.     }
  1919.     if (in_numc != NULL)
  1920.     {
  1921.         /* Prepare Addtional Number C Data */
  1922.         if (in_num[0] == '+')
  1923.         {
  1924.             myMsgPtr->anrc.tel_number.type = MMI_CSMCC_INTERNATIONAL_ADDR;      /* INTERNATIONAL */
  1925.             myMsgPtr->anrc.tel_number.length = (U8) pfnUnicodeStrlen(in_numc + ENCODING_LENGTH);        /* Exclude "+" */
  1926.             UnicodeToAnsii((PS8) myMsgPtr->anrc.tel_number.number, in_numc + ENCODING_LENGTH);
  1927.         }
  1928.         else
  1929.         {
  1930.             myMsgPtr->anrc.tel_number.type = MMI_CSMCC_DEFAULT_ADDR_TYPE;       /* DEFAULT */
  1931.             myMsgPtr->anrc.tel_number.length = (U8) pfnUnicodeStrlen(in_numc);
  1932.             UnicodeToAnsii((PS8) myMsgPtr->anrc.tel_number.number, in_numc);
  1933.         }
  1934.     }
  1935.     if (in_email != NULL)
  1936.     {
  1937.         /* Prepare email Data */
  1938.         myMsgPtr->email.email_length = InputboxConvertDeviceEncodingToGSM(
  1939.                                         (PU8) in_email,
  1940.                                         myMsgPtr->email.email_address,
  1941.                                         MAX_PB_EMAIL_LENGTH + 1,
  1942.                                         MMI_PHB_ASCII,
  1943.                                         0,
  1944.                                         1) - 1;
  1945.         myMsgPtr->email.adn_record_index = myMsgPtr->list.record_index;
  1946.     }
  1947. }
  1948. /*****************************************************************************
  1949.  * FUNCTION
  1950.  *  mmi_phb_op_set_option_data_by_usim_index
  1951.  * DESCRIPTION
  1952.  *  
  1953.  * PARAMETERS
  1954.  *  index           [IN]        
  1955.  *  opt_fields      [?]         
  1956.  * RETURNS
  1957.  *  void
  1958.  *****************************************************************************/
  1959. void mmi_phb_op_set_option_data_by_usim_index(U16 index, PHB_OPTIONAL_FIELDS_STRUCT *opt_fields)
  1960. {
  1961.     /*----------------------------------------------------------------*/
  1962.     /* Local Variables                                                */
  1963.     /*----------------------------------------------------------------*/
  1964.     /*----------------------------------------------------------------*/
  1965.     /* Code Body                                                      */
  1966.     /*----------------------------------------------------------------*/
  1967.     if (index >= MAX_PB_PHONE_ENTRIES)
  1968.     {
  1969.         mmi_phb_convert_get_ansii_anr(
  1970.             (S8*) opt_fields->homeNumber,
  1971.             (S8*) opt_fields->officeNumber,
  1972.             (S8*) opt_fields->faxNumber,
  1973.             index);
  1974.         memcpy(opt_fields->emailAddress, phb_email[index - MAX_PB_PHONE_ENTRIES].email_address, MAX_PB_EMAIL_LENGTH);
  1975.     }
  1976. }
  1977. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  1978. #endif /* _PHONEBOOKOPERATEMASS_C */