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

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * PhoneBookHandlerJava.C
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for providing phonebook interface for java package
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  * removed!
  148.  * removed!
  149.  * removed!
  150.  *
  151.  * removed!
  152.  * removed!
  153.  * removed!
  154.  *
  155.  *------------------------------------------------------------------------------
  156.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  157.  *============================================================================
  158.  ****************************************************************************/
  159. #ifndef _MMI_PHONEBOOKJAVAHANDLER_C
  160. #define _MMI_PHONEBOOKJAVAHANDLER_C
  161. #ifdef __J2ME__
  162. #include "j2me_custom_option.h"
  163. #endif
  164. #if defined(SUPPORT_JSR_75_PIM) || defined(SUPPORT_CMCC)
  165. /*  Include: MMI header file */
  166. #include "MMI_features.h"
  167. #include "stdC.h"
  168. #include "L4Dr1.h"
  169. #include "PixtelDataTypes.h"
  170. #include "GlobalDefs.h"
  171. #include "CommonScreens.h"
  172. #include "PhoneBookTypes.h"
  173. #include "PhoneBookDef.h"
  174. #include "PhoneBookProt.h"
  175. #include "PhoneBookGProt.h"
  176. #include "PhoneBookJavaHandler.h"
  177. #include "SettingDefs.h"        /* For FDN on check */
  178. #include "SettingsGdcl.h"
  179. #include "Nvram_user_defs.h"
  180. #include "NVRAMProt.h"
  181. #include "NVRAMType.h"
  182. #include "SimDetectionDef.h"
  183. #include "SimDetectionGprot.h"
  184. #include "DateTimeType.h"
  185. #ifdef __SYNCML_SUPPORT__
  186. #include "SyncMLGprot.h"
  187. #endif
  188. #ifdef __MMI_PHB_BIRTHDAY_FIELD__
  189. #include "app_datetime.h"
  190. #endif
  191. /* 
  192.  * Typedef 
  193.  */
  194. /* 
  195.  * Define
  196.  */
  197. /* 
  198.  * Local Variable
  199.  */
  200. static U8 g_phb_java_storage;
  201. static U8 g_phb_java_sort;
  202. #if defined(__MMI_PHB_EMAIL_SORT__)
  203. extern U8 g_phb_email_sorted;
  204. #endif 
  205. /* 
  206.  * Local Function
  207.  */
  208. /* 
  209.  * Global Variable
  210.  */
  211. extern U8 gInsertSimAppFlag;
  212. extern U16 PhoneBookEntryCount;
  213. extern U8 g_phb_enter_from;
  214. extern U16 g_phb_name_index[];
  215. extern S8 pbName[];
  216. extern S8 pbNumber[];
  217. extern S8 pbHomeNumber[];
  218. extern S8 pbOfficeNumber[];
  219. extern S8 pbFaxNumber[];
  220. extern S8 pbEmailAddress[];
  221. extern S8 pbCompanyName[];
  222. #if defined(__MMI_PHB_BIRTHDAY_FIELD__)
  223. extern const kal_uint8 g_dt_day_per_mon[];
  224. extern S8 pbDay[];
  225. extern S8 pbMon[];
  226. extern S8 pbYear[];
  227. #endif /* defined(__MMI_PHB_BIRTHDAY_FIELD__) */
  228. extern MMI_PHB_ENTRY_BCD_STRUCT PhoneBook[];
  229. #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  230. extern PHB_OPTIONAL_FIELDS_STRUCT PhoneBookOptionalFields;
  231. #endif 
  232. /* 
  233.  * Global Function
  234.  */
  235. extern void mmi_phb_callergroup_copy_group_info(U8 group_index, U8* group_name);
  236. #define MMI_PHB_JAVA_HANDLER
  237. /*****************************************************************************
  238.  * FUNCTION
  239.  *  mmi_phb_java_handler_init
  240.  * DESCRIPTION
  241.  *  This function initializes phonebook handler app.
  242.  * PARAMETERS
  243.  *  void
  244.  * RETURNS
  245.  *  void
  246.  *****************************************************************************/
  247. void mmi_phb_java_handler_init(void)
  248. {
  249.     /*----------------------------------------------------------------*/
  250.     /* Local Variables                                                */
  251.     /*----------------------------------------------------------------*/
  252.     /*----------------------------------------------------------------*/
  253.     /* Code Body                                                      */
  254.     /*----------------------------------------------------------------*/
  255.     SetProtocolEventHandler(mmi_phb_java_write_req, MSG_ID_MMI_PHB_JAVA_SET_ENTRY_REQ);
  256.     SetProtocolEventHandler(mmi_phb_java_read_req, MSG_ID_MMI_PHB_JAVA_GET_ENTRY_REQ);
  257.     SetProtocolEventHandler(mmi_phb_java_search_req, MSG_ID_MMI_PHB_JAVA_SEARCH_ENTRY_REQ);
  258.     SetProtocolEventHandler(mmi_phb_java_get_group_info_req, MSG_ID_MMI_PHB_JAVA_GET_GROUP_INFO_REQ);
  259.     SetProtocolEventHandler(mmi_phb_java_set_group_info_req, MSG_ID_MMI_PHB_JAVA_SET_GROUP_INFO_REQ);
  260. }
  261. /*****************************************************************************
  262.  * FUNCTION
  263.  *  mmi_phb_java_write_req
  264.  * DESCRIPTION
  265.  *  This function write a phonebook entry from JAVA request
  266.  * PARAMETERS
  267.  *  info        [?]     
  268.  * RETURNS
  269.  *  void
  270.  *****************************************************************************/
  271. void mmi_phb_java_write_req(void *info)
  272. {
  273.     /*----------------------------------------------------------------*/
  274.     /* Local Variables                                                */
  275.     /*----------------------------------------------------------------*/
  276.     mmi_phb_handler_set_entry_req_struct *LocalPtr;
  277.     U8 name_extend_char_num = 0;
  278.     /*----------------------------------------------------------------*/
  279.     /* Code Body                                                      */
  280.     /*----------------------------------------------------------------*/
  281.     LocalPtr = (mmi_phb_handler_set_entry_req_struct*) info;
  282.     if (!g_phb_cntx.phb_ready || g_phb_cntx.processing)
  283.     {
  284.         mmi_phb_java_write_rsp(MMI_PHB_JAVA_NOT_READY, 0xffff);
  285.         return;
  286.     }
  287. #ifdef __MMI_PHB_USIM_FIELD__
  288.     if (g_phb_cntx.is_usim && g_phb_cntx.usim_ready_stage != MMI_PHB_USIM_READY)
  289.     {
  290.         mmi_phb_java_write_rsp(MMI_PHB_JAVA_NOT_READY, 0);
  291.         return;
  292.     }
  293. #endif /* __MMI_PHB_USIM_FIELD__ */
  294. #ifdef __SYNCML_SUPPORT__
  295.     if (mmi_syncml_is_phb_sync_now())
  296.     {
  297.         mmi_phb_java_write_rsp(MMI_PHB_JAVA_NOT_READY, 0);
  298.         return;
  299.     }
  300. #endif /* __SYNCML_SUPPORT__ */
  301.     g_phb_java_storage = LocalPtr->storage;
  302.     //g_phb_java_sort = LocalPtr->sort_type;
  303.     /* [Add or Update] operation. (Not Delete) */
  304.     if (LocalPtr->entry_ptr)
  305.     {
  306.         /*  Check if name and number are both empty and all numbers are valid. */
  307.         if ((!pfnUnicodeStrlen(LocalPtr->entry_ptr->name) && !pfnUnicodeStrlen(LocalPtr->entry_ptr->number)) ||
  308.             !mmi_phb_op_check_valid_number(LocalPtr->entry_ptr->number) ||
  309.             !mmi_phb_op_check_valid_number(LocalPtr->entry_ptr->homeNumber) ||
  310.             !mmi_phb_op_check_valid_number(LocalPtr->entry_ptr->officeNumber) ||
  311.             !mmi_phb_op_check_valid_number(LocalPtr->entry_ptr->faxNumber))
  312.         {
  313.             mmi_phb_java_write_rsp(MMI_PHB_JAVA_ERROR, 0xffff);
  314.             return;
  315.         }
  316.     }
  317.     /* [Add] operation. */
  318.     if (LocalPtr->index == 0xffff)
  319.     {
  320.         /* Support Email sorting */
  321. //        if (g_phb_java_sort == MMI_PHB_BY_EMAIL)
  322. //        {
  323. //        #if defined(__MMI_PHB_EMAIL_SORT__)
  324. //            #ifndef __MMI_PHB_USIM_FIELD__
  325. //            if (g_phb_java_storage != MMI_NVRAM)
  326. //            {
  327. //                mmi_phb_java_write_rsp(MMI_PHB_JAVA_NOT_SUPPORT, 0xffff);
  328. //                return;
  329. //            }
  330. //            #endif /* ~__MMI_PHB_USIM_FIELD__ */
  331.             /* Email sorting not populated after bootup. */
  332. //            if (g_phb_email_sorted == 0)
  333. //           {
  334. //                mmi_phb_java_util_rebuild_email_sorting();
  335. //                g_phb_email_sorted = 1;
  336. //            }
  337. //        #else /* defined(__MMI_PHB_EMAIL_SORT__) */
  338. //            mmi_phb_java_write_rsp(MMI_PHB_JAVA_NOT_SUPPORT, 0xffff);
  339. //            return;
  340. //        #endif /* defined(__MMI_PHB_EMAIL_SORT__) */
  341. //        }
  342.         /* Check free space and assign storage location */
  343. //        if (gInsertSimAppFlag == 1)
  344.         if (mmi_bootup_is_sim_valid() == MMI_FALSE)
  345.         {
  346.             if (LocalPtr->storage == MMI_SIM)
  347.             {
  348.                 mmi_phb_java_write_rsp(MMI_PHB_JAVA_NO_SIM_CARD, 0xffff);
  349.                 return;
  350.             }
  351.             else if (g_phb_cntx.phone_used < g_phb_cntx.phone_total)
  352.             {
  353.                 g_phb_cntx.selected_storage = MMI_NVRAM;
  354.             }
  355.             else
  356.             {
  357.                 mmi_phb_java_write_rsp(MMI_PHB_JAVA_STORAGE_FULL, 0xffff);
  358.                 return;
  359.             }
  360.         }
  361.         else
  362.         {
  363.             if ((LocalPtr->storage == MMI_STORAGE_BOTH) && (PhoneBookEntryCount < (g_phb_cntx.sim_total + g_phb_cntx.phone_total)))
  364.             {
  365.                 if (g_phb_cntx.prefer_storage == MMI_NVRAM)
  366.                 {
  367.                     if (g_phb_cntx.phone_used < g_phb_cntx.phone_total)
  368.                     {
  369.                         g_phb_cntx.selected_storage = MMI_NVRAM;
  370.                     }
  371.                     else if(g_phb_cntx.sim_used < g_phb_cntx.sim_total)
  372.                     {
  373.                         g_phb_cntx.selected_storage = MMI_SIM;
  374.                     }
  375.                     else
  376.                     {
  377.                         ASSERT(0);
  378.                     }
  379.                 }
  380.                 else if (g_phb_cntx.prefer_storage == MMI_SIM)
  381.                 {
  382.                     if (g_phb_cntx.sim_used < g_phb_cntx.sim_total)
  383.                     {
  384.                         g_phb_cntx.selected_storage = MMI_SIM;
  385.                     }
  386.                     else if (g_phb_cntx.phone_used < g_phb_cntx.phone_total)
  387.                     {
  388.                         g_phb_cntx.selected_storage = MMI_NVRAM;
  389.                     }
  390.                     else
  391.                     {
  392.                         ASSERT(0);
  393.                     }
  394.                 }
  395.                 else
  396.                 {
  397.                     ASSERT(0);
  398.                 }
  399.             }
  400.             else if (((LocalPtr->storage == MMI_SIM) && (g_phb_cntx.sim_used < g_phb_cntx.sim_total)) ||
  401.                      ((LocalPtr->storage == MMI_NVRAM) && (g_phb_cntx.phone_used < g_phb_cntx.phone_total)))
  402.             {
  403.                 g_phb_cntx.selected_storage = LocalPtr->storage;
  404.             }
  405.             else
  406.             {
  407.                 mmi_phb_java_write_rsp(MMI_PHB_JAVA_STORAGE_FULL, 0xffff);
  408.                 return;
  409.             }
  410.         }
  411.         /*
  412.          * Prepare data for name and number field
  413.          */
  414.         mmi_phb_util_clear_buffer(TRUE);
  415.         if (LocalPtr->entry_ptr->name)
  416.         {
  417.             if (GetUCS2Flag(LocalPtr->entry_ptr->name) == 1) /* there is chinese character, length = 14 */
  418.             {
  419.                 pfnUnicodeStrncpy(pbName, LocalPtr->entry_ptr->name, (MAX_PB_NAME_LENGTH - 1) / 2);
  420.             }
  421.             else
  422.             {
  423.                 name_extend_char_num = GetUCS2ExtendedNum((PS8)LocalPtr->entry_ptr->name, MAX_PB_NAME_LENGTH);
  424.                 if ((pfnUnicodeStrlen(LocalPtr->entry_ptr->name) + name_extend_char_num) > MAX_PB_NAME_LENGTH)
  425.                 {           
  426.                     pfnUnicodeStrncpy(pbName, LocalPtr->entry_ptr->name, MAX_PB_NAME_LENGTH - name_extend_char_num);
  427.                 }
  428.                 else
  429.                 {
  430.                     pfnUnicodeStrncpy(pbName, LocalPtr->entry_ptr->name, MAX_PB_NAME_LENGTH);
  431.                 }
  432.             }
  433.         }
  434.         memcpy(pbNumber, LocalPtr->entry_ptr->number, (MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH);
  435.         /*
  436.          * Prepare data for optional fields
  437.          */
  438.         memcpy(pbHomeNumber, LocalPtr->entry_ptr->homeNumber, (MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH);
  439.         memcpy(pbOfficeNumber, LocalPtr->entry_ptr->officeNumber, (MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH);
  440.         memcpy(pbFaxNumber, LocalPtr->entry_ptr->faxNumber, (MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH);
  441.         memcpy(pbEmailAddress, LocalPtr->entry_ptr->emailAddress, (MAX_PB_EMAIL_LENGTH + 1) * ENCODING_LENGTH);
  442.         memcpy(pbCompanyName, LocalPtr->entry_ptr->companyName, (MAX_PB_COMPANY_LENGTH + 1) * ENCODING_LENGTH);
  443.         /*
  444.          * Prepare data for birthday
  445.          */
  446. #ifdef __MMI_PHB_BIRTHDAY_FIELD__
  447.         if (mmi_phb_java_check_bday_is_valid(&(LocalPtr->entry_ptr->bDay)) == 0)
  448.         {
  449.             mmi_phb_java_write_rsp(MMI_PHB_JAVA_BIRTHDAY_ERROR, 0xffff);
  450.             return;
  451.         }
  452. mmi_phb_bday_set_changed();
  453.         mmi_phb_java_set_bday(&(LocalPtr->entry_ptr->bDay), pbYear, pbMon, pbDay);
  454. #endif /* def __MMI_PHB_BIRTHDAY_FIELD__ */
  455.         /*
  456.          * prepare data for optional id
  457.          */
  458.         g_phb_cntx.selected_pic_index = 0;
  459.         g_phb_cntx.selected_ring_index = 0;
  460.         if (g_phb_cntx.selected_storage == MMI_NVRAM && LocalPtr->entry_ptr->group_id <= MAX_PB_CALLER_GROUPS)
  461.         {
  462.             g_phb_cntx.selected_grp_index = LocalPtr->entry_ptr->group_id;
  463.         }
  464. #ifdef __MMI_PHB_USIM_FIELD__
  465.         else if (g_phb_cntx.selected_storage == MMI_SIM && g_phb_cntx.is_usim &&
  466.             LocalPtr->entry_ptr->group_id > MAX_PB_CALLER_GROUPS &&
  467.             LocalPtr->entry_ptr->group_id <= (MAX_PB_CALLER_GROUPS + g_phb_cntx.gas_total))
  468.         {
  469.             g_phb_cntx.selected_grp_index = LocalPtr->entry_ptr->group_id - MAX_PB_CALLER_GROUPS;
  470.         }
  471. #endif /* __MMI_PHB_USIM_FIELD__ */
  472.         else
  473.         {
  474.             g_phb_cntx.selected_grp_index = 0;
  475.         }
  476.         g_phb_cntx.image_location = MMI_PHB_IMAGE_NO_SELECT;
  477.         g_phb_enter_from = MMI_PHB_ENTER_FROM_JAVA;
  478.     #ifdef __MMI_PHB_USIM_FIELD__
  479.         if (g_phb_cntx.is_usim && g_phb_cntx.selected_storage == MMI_SIM)
  480.         {
  481.             mmi_phb_op_add_usim_entry_req();
  482.         }
  483.         /* Email sorting not populated after bootup. */
  484.         else
  485.     #endif /* __MMI_PHB_USIM_FIELD__ */ 
  486.         {
  487.             mmi_phb_op_add_entry_req();
  488.         }
  489.     }
  490.     else
  491.     {
  492.         U16 pos;
  493.         g_phb_cntx.java_store_index = 0xffff;
  494.         for (pos = 0; pos < PhoneBookEntryCount; pos++)
  495.         {
  496.             if (g_phb_name_index[pos] == LocalPtr->index)
  497.             {
  498.                 g_phb_cntx.java_store_index = LocalPtr->index;
  499.                 break;
  500.             }
  501.         }
  502.         if (g_phb_cntx.java_store_index == 0xffff)
  503.         {
  504.             mmi_phb_java_write_rsp(MMI_PHB_JAVA_OUT_OF_INDEX, 0xffff);
  505.             return;
  506.         }
  507.         g_phb_enter_from = MMI_PHB_ENTER_FROM_JAVA;
  508.         
  509.         /* [Delete] operation. */
  510.         if (LocalPtr->entry_ptr == NULL)
  511.         {
  512.             mmi_phb_op_delete_entry_req();
  513.         }
  514.         /* [Update] operation. */
  515.         else
  516.         {
  517.             /* Prepare data for name and number field */
  518.             mmi_phb_util_clear_buffer(TRUE);
  519.             memcpy(pbName, LocalPtr->entry_ptr->name, (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH);
  520.             memcpy(pbNumber, LocalPtr->entry_ptr->number, (MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH);
  521.             /* Prepare data for optional fields */
  522.             memcpy(pbHomeNumber, LocalPtr->entry_ptr->homeNumber, (MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH);
  523.             memcpy(pbOfficeNumber, LocalPtr->entry_ptr->officeNumber, (MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH);
  524.             memcpy(pbFaxNumber, LocalPtr->entry_ptr->faxNumber, (MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH);
  525.             memcpy(pbEmailAddress, LocalPtr->entry_ptr->emailAddress, (MAX_PB_EMAIL_LENGTH + 1) * ENCODING_LENGTH);
  526.             memcpy(pbCompanyName, LocalPtr->entry_ptr->companyName, (MAX_PB_COMPANY_LENGTH + 1) * ENCODING_LENGTH);
  527.         #ifdef __MMI_PHB_BIRTHDAY_FIELD__
  528.             if (mmi_phb_java_check_bday_is_valid(&(LocalPtr->entry_ptr->bDay)) == 0)
  529.             {
  530.                 mmi_phb_java_write_rsp(MMI_PHB_JAVA_BIRTHDAY_ERROR, 0xffff);
  531.                 return;
  532.             }
  533. mmi_phb_bday_set_changed();
  534.             mmi_phb_java_set_bday(&(LocalPtr->entry_ptr->bDay), pbYear, pbMon, pbDay);
  535.         #endif /* def __MMI_PHB_BIRTHDAY_FIELD__ */
  536.             if (LocalPtr->index < MAX_PB_PHONE_ENTRIES && LocalPtr->entry_ptr->group_id <= MAX_PB_CALLER_GROUPS)
  537.             {
  538.                 g_phb_cntx.selected_grp_index = LocalPtr->entry_ptr->group_id;
  539.             }
  540.         #ifdef __MMI_PHB_USIM_FIELD__
  541.             else if (LocalPtr->index >= MAX_PB_PHONE_ENTRIES && g_phb_cntx.is_usim &&
  542.                 LocalPtr->entry_ptr->group_id > MAX_PB_CALLER_GROUPS &&
  543.                 LocalPtr->entry_ptr->group_id <= (MAX_PB_CALLER_GROUPS + g_phb_cntx.gas_total))
  544.             {
  545.                 g_phb_cntx.selected_grp_index = LocalPtr->entry_ptr->group_id - MAX_PB_CALLER_GROUPS;
  546.             }
  547.         #endif /* __MMI_PHB_USIM_FIELD__ */
  548.             else
  549.             {
  550.                 g_phb_cntx.selected_grp_index = 0;
  551.             }
  552.         #ifdef __MMI_PHB_USIM_FIELD__
  553.             if (g_phb_cntx.is_usim && LocalPtr->index >= MAX_PB_PHONE_ENTRIES)
  554.             {
  555.                 mmi_phb_op_edit_usim_entry_req();
  556.             }
  557.             /* Email sorting not populated after bootup. */
  558.             else
  559.         #endif /* __MMI_PHB_USIM_FIELD__ */
  560.             {
  561.                 /* prepare data for optional id */
  562.                 g_phb_cntx.selected_pic_index = 0;
  563.                 g_phb_cntx.selected_ring_index = 0;
  564.                 g_phb_cntx.image_location = MMI_PHB_IMAGE_NO_SELECT;
  565.                 mmi_phb_op_edit_entry_req();
  566.             }
  567.         }
  568.     }
  569. }
  570. /*****************************************************************************
  571.  * FUNCTION
  572.  *  mmi_phb_java_write_rsp
  573.  * DESCRIPTION
  574.  *  This function return write result to JAVA
  575.  * PARAMETERS
  576.  *  result          [IN]        
  577.  *  store_index     [IN]        
  578.  * RETURNS
  579.  *  void
  580.  *****************************************************************************/
  581. void mmi_phb_java_write_rsp(U16 result, U16 store_index)
  582. {
  583.     /*----------------------------------------------------------------*/
  584.     /* Local Variables                                                */
  585.     /*----------------------------------------------------------------*/
  586.     mmi_phb_handler_set_entry_rsp_struct *MsgPtr;
  587.     MYQUEUE Message;
  588.     /*----------------------------------------------------------------*/
  589.     /* Code Body                                                      */
  590.     /*----------------------------------------------------------------*/
  591.     MsgPtr = (mmi_phb_handler_set_entry_rsp_struct*) OslConstructDataPtr(sizeof(mmi_phb_handler_set_entry_rsp_struct));
  592. //    MsgPtr->index = 0xffff;
  593.     /* Decide error cause */
  594.     if ((MsgPtr->result = result) == MMI_PHB_JAVA_SUCCESS)
  595.     {
  596. //        MsgPtr->index = mmi_phb_java_util_get_index_by_store_index(g_phb_java_sort, g_phb_java_storage, store_index);
  597.         MsgPtr->store_index = store_index; /* >= MAX_PB_PHONE_ENTRIES is SIM entry */
  598.     }
  599.     else if ((MsgPtr->result = result) == MMI_PHB_JAVA_NOT_SUPPORT)
  600.     {
  601.         /* Do nothing */ ;
  602.     }
  603.     else if ((MsgPtr->result = result) == MMI_PHB_JAVA_STORAGE_FULL)
  604.     {
  605.         /* Do nothing */ ;
  606.     }
  607.     else if ((MsgPtr->result = result) == MMI_PHB_JAVA_NOT_READY)
  608.     {
  609.         /* Do nothing */ ;
  610.     }
  611.     else if (result == MMI_SIM_EF_RECORD_FULL)
  612.     {
  613.         MsgPtr->result = MMI_PHB_JAVA_NUMBER_TOO_LONG;
  614.     }
  615.     else if (gSecuritySetupContext.FdlStatus)
  616.     {
  617.         MsgPtr->result = MMI_PHB_JAVA_FDN_ON;
  618.     }
  619. #ifdef __MMI_PHB_USIM_FIELD__
  620.     else if (result == MMI_PHB_USIM_EMAIL_FULL)
  621.     {
  622.         MsgPtr->result = MMI_PHB_JAVA_EMAIL_FULL;
  623.     }
  624.     else if (result == MMI_PHB_USIM_ANR_FULL)
  625.     {
  626.         MsgPtr->result = MMI_PHB_JAVA_ANR_FULL;
  627.     }
  628. #endif /* __MMI_PHB_USIM_FIELD__ */
  629.     else
  630.     {
  631.         MsgPtr->result = MMI_PHB_JAVA_ERROR;
  632.     }
  633.     g_phb_enter_from = MMI_PHB_ENTER_NONE;
  634.     Message.oslSrcId = MOD_MMI;
  635.     Message.oslDestId = MOD_JASYN;
  636.     Message.oslMsgId = MSG_ID_MMI_PHB_JAVA_SET_ENTRY_RSP;
  637.     Message.oslDataPtr = (oslParaType*) MsgPtr;
  638.     Message.oslPeerBuffPtr = NULL;
  639.     OslMsgSendExtQueue(&Message);
  640. }
  641. /*****************************************************************************
  642.  * FUNCTION
  643.  *  mmi_phb_java_read_req
  644.  * DESCRIPTION
  645.  *  This function initializes phonebook handler app.
  646.  * PARAMETERS
  647.  *  info        [?]     
  648.  * RETURNS
  649.  *  void
  650.  *****************************************************************************/
  651. void mmi_phb_java_read_req(void *info)
  652. {
  653.     /*----------------------------------------------------------------*/
  654.     /* Local Variables                                                */
  655.     /*----------------------------------------------------------------*/
  656.     U16 pos;
  657.     U16 count = 0;
  658.     U16 store_index = 0;
  659.     mmi_phb_handler_get_entry_req_struct *LocalPtr;
  660.     /*----------------------------------------------------------------*/
  661.     /* Code Body                                                      */
  662.     /*----------------------------------------------------------------*/
  663.     LocalPtr = (mmi_phb_handler_get_entry_req_struct*) info;
  664.     if (!g_phb_cntx.phb_ready || g_phb_cntx.processing)
  665.     {
  666.         mmi_phb_java_read_rsp(MMI_PHB_JAVA_NOT_READY, 0);
  667.         return;
  668.     }
  669. #ifdef __SYNCML_SUPPORT__
  670.     if (mmi_syncml_is_phb_sync_now())
  671.     {
  672.         mmi_phb_java_read_rsp(MMI_PHB_JAVA_NOT_READY, 0);
  673.         return;
  674.     }
  675. #endif /* __SYNCML_SUPPORT__ */
  676.     /*
  677.      * Get entry data
  678.      */
  679.     if ((LocalPtr->count > 0) && (LocalPtr->entry_ptr != NULL))
  680.     {
  681.         /*
  682.          *  Check valid index first.
  683.          */
  684.         if (((LocalPtr->storage == MMI_STORAGE_BOTH) && (LocalPtr->index > PhoneBookEntryCount)) ||
  685.             ((LocalPtr->storage == MMI_NVRAM) && (LocalPtr->index > g_phb_cntx.phone_used)) ||
  686.             ((LocalPtr->storage == MMI_SIM) && (LocalPtr->index > g_phb_cntx.sim_used)))
  687.         {
  688.             mmi_phb_java_read_rsp(MMI_PHB_JAVA_OUT_OF_INDEX, 0);
  689.             return;
  690.         }
  691.         /* Sort By NAME */
  692.         if (LocalPtr->sort_type == MMI_PHB_BY_NAME)
  693.         {
  694.             /* Find index position */
  695.             for (pos = 0; pos < PhoneBookEntryCount; pos++)
  696.             {
  697.                 store_index = g_phb_name_index[pos];
  698.                 if ((LocalPtr->storage == MMI_STORAGE_BOTH) ||
  699.                     (LocalPtr->storage == MMI_NVRAM && store_index < MAX_PB_PHONE_ENTRIES) ||
  700.                     (LocalPtr->storage == MMI_SIM && store_index >= MAX_PB_PHONE_ENTRIES))
  701.                 {
  702.                     count++;
  703.                 }
  704.                 if (count == LocalPtr->index)
  705.                 {
  706.                     break;
  707.                 }
  708.             }
  709.             /* Copy entry by assigned count number */
  710.             count = 0;
  711.             LocalPtr->entry_ptr[count].sort_index = LocalPtr->index;
  712.             mmi_phb_java_util_copy_entry_from_phb(store_index, &LocalPtr->entry_ptr[count++]);
  713.             while ((++pos < PhoneBookEntryCount) && (count < LocalPtr->count))
  714.             {
  715.                 store_index = g_phb_name_index[pos];
  716.                 if ((LocalPtr->storage == MMI_STORAGE_BOTH) ||
  717.                     (LocalPtr->storage == MMI_NVRAM && store_index < MAX_PB_PHONE_ENTRIES) ||
  718.                     (LocalPtr->storage == MMI_SIM && store_index >= MAX_PB_PHONE_ENTRIES))
  719.                 {
  720.                     LocalPtr->entry_ptr[count].sort_index = LocalPtr->index+count;
  721.                     mmi_phb_java_util_copy_entry_from_phb(store_index, &LocalPtr->entry_ptr[count++]);
  722.                 }
  723.             }
  724.             mmi_phb_java_read_rsp(MMI_PHB_JAVA_SUCCESS, count);
  725.             return;
  726.         }
  727.         /* Support Email sorting */
  728.     #if defined(__MMI_PHB_EMAIL_SORT__)
  729.     #ifdef __MMI_PHB_USIM_FIELD__
  730.         if (LocalPtr->sort_type == MMI_PHB_BY_EMAIL)
  731.     #else 
  732.         if ((LocalPtr->sort_type == MMI_PHB_BY_EMAIL) && (LocalPtr->storage == MMI_NVRAM))
  733.     #endif 
  734.         {
  735.             S16 pError;
  736.         #ifdef __MMI_PHB_USIM_FIELD__
  737.             U16 g_phb_email_index[MAX_PB_ENTRIES];
  738.         #else 
  739.             U16 g_phb_email_index[MAX_PB_PHONE_ENTRIES];
  740.         #endif 
  741.             /* Email sorting not populated after bootup. */
  742.             if (g_phb_email_sorted == 0)
  743.             {
  744.                 mmi_phb_java_util_rebuild_email_sorting();
  745.                 g_phb_email_sorted = 1;
  746.             }
  747.         #ifdef __MMI_PHB_USIM_FIELD__
  748.             ReadRecord(
  749.                 NVRAM_EF_PHB_EMAIL_SORT_LID,
  750.                 1,
  751.                 (void*)g_phb_email_index,
  752.                 MAX_PB_ENTRIES * sizeof(U16),
  753.                 &pError);
  754.         #else /* __MMI_PHB_USIM_FIELD__ */ 
  755.             ReadRecord(
  756.                 NVRAM_EF_PHB_EMAIL_SORT_LID,
  757.                 1,
  758.                 (void*)g_phb_email_index,
  759.                 MAX_PB_PHONE_ENTRIES * sizeof(U16),
  760.                 &pError);
  761.         #endif /* __MMI_PHB_USIM_FIELD__ */ 
  762.             /* Find first index position */
  763.             pos = LocalPtr->index - 1;
  764.             /* Copy entry by assigned count number */
  765.             store_index = g_phb_email_index[pos];
  766.             LocalPtr->entry_ptr[count].sort_index = LocalPtr->index;
  767.             mmi_phb_java_util_copy_entry_from_phb(store_index, &LocalPtr->entry_ptr[count++]);
  768.         #ifdef __MMI_PHB_USIM_FIELD__
  769.             while ((++pos < PhoneBookEntryCount) && (count < LocalPtr->count))
  770.         #else 
  771.             while ((++pos < g_phb_cntx.phone_used) && (count < LocalPtr->count))
  772.         #endif 
  773.             {
  774.                 store_index = g_phb_email_index[pos];
  775.             #ifndef __MMI_PHB_USIM_FIELD__
  776.                 if (store_index < MAX_PB_PHONE_ENTRIES) /* In NVRAM */
  777.             #endif 
  778.                 {
  779.                     LocalPtr->entry_ptr[count].sort_index = LocalPtr->index+count;
  780.                     mmi_phb_java_util_copy_entry_from_phb(store_index, &LocalPtr->entry_ptr[count++]);
  781.                 }
  782.             }
  783.             mmi_phb_java_read_rsp(MMI_PHB_JAVA_SUCCESS, count);
  784.             return;
  785.         }
  786.     #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  787.     }
  788.     /*
  789.      * Get total count by storage, no need to return data.
  790.      */
  791.     else if (LocalPtr->count == 0)
  792.     {
  793.         if (LocalPtr->storage == MMI_STORAGE_BOTH)
  794.         {
  795.             mmi_phb_java_read_rsp(MMI_PHB_JAVA_SUCCESS, PhoneBookEntryCount);
  796.             return;
  797.         }
  798.         else if (LocalPtr->storage == MMI_NVRAM)
  799.         {
  800.             mmi_phb_java_read_rsp(MMI_PHB_JAVA_SUCCESS, g_phb_cntx.phone_used);
  801.             return;
  802.         }
  803.         else if (LocalPtr->storage == MMI_SIM)
  804.         {
  805.             mmi_phb_java_read_rsp(MMI_PHB_JAVA_SUCCESS, g_phb_cntx.sim_used);
  806.             return;
  807.         }
  808.     }
  809.     /* Error */
  810.     mmi_phb_java_read_rsp(MMI_PHB_JAVA_NOT_SUPPORT, 0);
  811. }
  812. /*****************************************************************************
  813.  * FUNCTION
  814.  *  mmi_phb_java_read_rsp
  815.  * DESCRIPTION
  816.  *  This function initializes phonebook handler app.
  817.  * PARAMETERS
  818.  *  result      [IN]        
  819.  *  count       [IN]        
  820.  * RETURNS
  821.  *  void
  822.  *****************************************************************************/
  823. void mmi_phb_java_read_rsp(U16 result, U16 count)
  824. {
  825.     /*----------------------------------------------------------------*/
  826.     /* Local Variables                                                */
  827.     /*----------------------------------------------------------------*/
  828.     mmi_phb_handler_get_entry_rsp_struct *MsgPtr;
  829.     MYQUEUE Message;
  830.     /*----------------------------------------------------------------*/
  831.     /* Code Body                                                      */
  832.     /*----------------------------------------------------------------*/
  833.     MsgPtr = (mmi_phb_handler_get_entry_rsp_struct*) OslConstructDataPtr(sizeof(mmi_phb_handler_get_entry_rsp_struct));
  834.     MsgPtr->result = result;
  835.     MsgPtr->count = count;
  836.     Message.oslSrcId = MOD_MMI;
  837.     Message.oslDestId = MOD_JASYN;
  838.     Message.oslMsgId = MSG_ID_MMI_PHB_JAVA_GET_ENTRY_RSP;
  839.     Message.oslDataPtr = (oslParaType*) MsgPtr;
  840.     Message.oslPeerBuffPtr = NULL;
  841.     OslMsgSendExtQueue(&Message);
  842. }
  843. /*****************************************************************************
  844.  * FUNCTION
  845.  *  mmi_phb_java_search_req
  846.  * DESCRIPTION
  847.  *  This function initializes phonebook handler app.
  848.  * PARAMETERS
  849.  *  info        [IN/OUT]     
  850.  * RETURNS
  851.  *  void
  852.  *****************************************************************************/
  853. void mmi_phb_java_search_req(void *info)
  854. {
  855.     /*----------------------------------------------------------------*/
  856.     /* Local Variables                                                */
  857.     /*----------------------------------------------------------------*/
  858.     U16 store_index;
  859.     U16 index;
  860.     S32 distance;
  861.     U8 same_count;
  862.     mmi_phb_handler_search_entry_req_struct *LocalPtr;
  863.     /*----------------------------------------------------------------*/
  864.     /* Code Body                                                      */
  865.     /*----------------------------------------------------------------*/
  866.     LocalPtr = (mmi_phb_handler_search_entry_req_struct*) info;
  867.     if (!g_phb_cntx.phb_ready || g_phb_cntx.processing)
  868.     {
  869.         mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_READY, 0xffff);
  870.         return;
  871.     }
  872. #ifdef __SYNCML_SUPPORT__
  873.     if (mmi_syncml_is_phb_sync_now())
  874.     {
  875.         mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_READY, 0xffff);
  876.         return;
  877.     }
  878. #endif /* __SYNCML_SUPPORT__ */
  879.     g_phb_java_sort = LocalPtr->sort_type;
  880.     g_phb_java_storage = LocalPtr->storage;
  881.     /* Check if search pattern empty */
  882.     if (pfnUnicodeStrlen((S8*) LocalPtr->pattern) == 0)
  883.     {
  884.         mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_FOUND, 0xffff);
  885.         return;
  886.     }
  887.     /* Search by name */
  888.     if (LocalPtr->search_type == MMI_PHB_BY_NAME)
  889.     {
  890.         /* Find the closest entry */
  891.         index = mmi_phb_search_name_binary_search(0, (PhoneBookEntryCount - 1), LocalPtr->pattern);
  892.         if ((index + LocalPtr->start_index) >=  PhoneBookEntryCount)
  893.         {
  894.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_FOUND, 0xffff);
  895.             return;
  896.         }
  897.         store_index = g_phb_name_index[index + LocalPtr->start_index];
  898.         /* Check if the closest entry prefix match the pattern */
  899.         mmi_phb_compare_ucs2_strings(
  900.             LocalPtr->pattern,
  901.             (S8*) PhoneBook[store_index].alpha_id.name,
  902.             &same_count,
  903.             &distance);
  904.         if (pfnUnicodeStrlen(LocalPtr->pattern) == same_count)
  905.         {
  906.             LocalPtr->entry_ptr->sort_index = index;
  907.             /* store_index will be set in mmi_phb_java_util_copy_entry_from_phb */
  908.             mmi_phb_java_util_copy_entry_from_phb(store_index, LocalPtr->entry_ptr);
  909.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_SUCCESS, store_index);
  910.         }
  911.         else
  912.         {
  913.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_FOUND, 0xffff);
  914.         }
  915.     }
  916.     /* Search by email */
  917. #if defined(__MMI_PHB_EMAIL_SORT__)
  918.     else if (LocalPtr->search_type == MMI_PHB_BY_EMAIL)
  919.     {
  920.     #ifdef __MMI_PHB_USIM_FIELD__
  921.         U16 g_phb_email_index[MAX_PB_ENTRIES];
  922.     #else 
  923.         U16 g_phb_email_index[MAX_PB_PHONE_ENTRIES];
  924.     #endif 
  925.         S16 pError;
  926.         /* Email sorting not populated after bootup. */
  927.         if (g_phb_email_sorted == 0)
  928.         {
  929.             mmi_phb_java_util_rebuild_email_sorting();
  930.             g_phb_email_sorted = 1;
  931.         }
  932.     #ifdef __MMI_PHB_USIM_FIELD__
  933.         ReadRecord(
  934.             NVRAM_EF_PHB_EMAIL_SORT_LID,
  935.             1,
  936.             (void*)g_phb_email_index,
  937.             MAX_PB_ENTRIES * sizeof(U16),
  938.             &pError);
  939.         /* Find the closest entry */
  940.         store_index = mmi_phb_search_email_binary_search(0, (PhoneBookEntryCount - 1), LocalPtr->pattern);
  941.         if ((store_index + LocalPtr->start_index) >=  PhoneBookEntryCount)
  942.         {
  943.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_FOUND, 0xffff);
  944.             return;
  945.         }
  946.         store_index = g_phb_name_index[store_index + LocalPtr->start_index];
  947.         /* Check if the closest entry prefix match the pattern */
  948.         if (store_index >= MAX_PB_PHONE_ENTRIES)
  949.         {
  950.             AnsiiToUnicodeString((S8*) pbEmailAddress, (S8*) phb_email[first - MAX_PB_PHONE_ENTRIES].email_address);
  951.         }
  952.         else
  953.     #else /* __MMI_PHB_USIM_FIELD__ */ 
  954.         ReadRecord(
  955.             NVRAM_EF_PHB_EMAIL_SORT_LID,
  956.             1,
  957.             (void*)g_phb_email_index,
  958.             MAX_PB_PHONE_ENTRIES * sizeof(U16),
  959.             &pError);
  960.         /* Find the closest entry */
  961.         store_index = mmi_phb_search_email_binary_search(0, (g_phb_cntx.phone_used - 1), LocalPtr->pattern);
  962.         if ((store_index + LocalPtr->start_index) >=  g_phb_cntx.phone_used)
  963.         {
  964.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_FOUND, 0xffff);
  965.             return;
  966.         }
  967.         store_index = g_phb_name_index[store_index + LocalPtr->start_index];
  968.     #endif /* __MMI_PHB_USIM_FIELD__ */ 
  969.         {
  970.             ReadRecord(
  971.                 NVRAM_EF_PHB_FIELDS_LID,
  972.                 (U16) (store_index + 1),
  973.                 (void*)&PhoneBookOptionalFields,
  974.                 OPTIONAL_FIELDS_RECORD_SIZE,
  975.                 &pError);
  976.             AnsiiToUnicodeString(pbEmailAddress, (PS8) PhoneBookOptionalFields.emailAddress);
  977.         }
  978.         /* Check if the closest entry prefix match the pattern */
  979.         mmi_phb_compare_ucs2_strings(LocalPtr->pattern, pbEmailAddress, &same_count, &distance);
  980.         if (pfnUnicodeStrlen(LocalPtr->pattern) == same_count || distance == 0)
  981.         {
  982.             mmi_phb_java_util_copy_entry_from_phb(store_index, LocalPtr->entry_ptr);
  983.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_SUCCESS, store_index);
  984.         }
  985.         else
  986.         {
  987.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_FOUND, 0xffff);
  988.         }
  989.     }
  990. #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  991.     /* Search by number */
  992.     else if (LocalPtr->search_type == MMI_PHB_BY_NUMBER)
  993.     {
  994.         U32 num;
  995.         U8 number_ASCII[MAX_PB_NUMBER_LENGTH + 1 + 1];
  996.         /* Number not sorted yet */
  997.         if (g_phb_cntx.populate_count != 0xffff)
  998.         {
  999.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_READY, 0xffff);
  1000.             return;
  1001.         }
  1002.         if (LocalPtr->sort_type != MMI_PHB_BY_NAME
  1003.         #ifdef __MMI_PHB_EMAIL_SORT__
  1004.             && LocalPtr->sort_type != MMI_PHB_BY_EMAIL
  1005.         #endif
  1006.             )
  1007.         {
  1008.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_SUPPORT, 0);
  1009.             return;
  1010.         }
  1011.         memset(number_ASCII, 0, ENCODING_LENGTH);
  1012.         UnicodeToAnsii((S8*) number_ASCII, LocalPtr->pattern);
  1013.         num = mmi_phb_util_convert_number_to_int(number_ASCII);
  1014.         if (num < INVALID_NUMBER)
  1015.         {
  1016.             store_index = mmi_phb_lookup_table_search(num, 0, (U16)(g_phb_cntx.lookup_table_count - 1), 
  1017.                 (S8*) number_ASCII, g_phb_java_storage);
  1018.             if (store_index < 0xffff)   /* storage location in array, begin from 0. */
  1019.             {
  1020.                 mmi_phb_java_util_copy_entry_from_phb(store_index, LocalPtr->entry_ptr);
  1021.                 //sort_index will be set in search rsp
  1022.                 mmi_phb_java_search_rsp(MMI_PHB_JAVA_SUCCESS, store_index);
  1023.             }
  1024.             else
  1025.             {
  1026.                 mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_FOUND, 0xffff);
  1027.             }
  1028.         }
  1029.         else
  1030.         {
  1031.             mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_FOUND, 0xffff);
  1032.         }
  1033.     }
  1034.     else
  1035.     {
  1036.         mmi_phb_java_search_rsp(MMI_PHB_JAVA_NOT_SUPPORT, 0xffff);
  1037.     }
  1038. }
  1039. /*****************************************************************************
  1040.  * FUNCTION
  1041.  *  mmi_phb_java_search_rsp
  1042.  * DESCRIPTION
  1043.  *  This function initializes phonebook handler app.
  1044.  * PARAMETERS
  1045.  *  result          [IN]        
  1046.  *  store_index     [IN]        
  1047.  * RETURNS
  1048.  *  void
  1049.  *****************************************************************************/
  1050. void mmi_phb_java_search_rsp(U16 result, U16 store_index)
  1051. {
  1052.     /*----------------------------------------------------------------*/
  1053.     /* Local Variables                                                */
  1054.     /*----------------------------------------------------------------*/
  1055.     mmi_phb_handler_search_entry_rsp_struct *MsgPtr;
  1056.     MYQUEUE Message;
  1057.     /*----------------------------------------------------------------*/
  1058.     /* Code Body                                                      */
  1059.     /*----------------------------------------------------------------*/
  1060.     MsgPtr =
  1061.         (mmi_phb_handler_search_entry_rsp_struct*)
  1062.         OslConstructDataPtr(sizeof(mmi_phb_handler_search_entry_rsp_struct));
  1063.     /* Decide error cause */
  1064.     MsgPtr->result = result;
  1065.     MsgPtr->index = store_index;
  1066.     if (result == MMI_PHB_JAVA_SUCCESS)
  1067.     {
  1068.         MsgPtr->index = mmi_phb_java_util_get_index_by_store_index(g_phb_java_sort, g_phb_java_storage, store_index);
  1069.     }
  1070.     Message.oslSrcId = MOD_MMI;
  1071.     Message.oslDestId = MOD_JASYN;
  1072.     Message.oslMsgId = MSG_ID_MMI_PHB_JAVA_SEARCH_ENTRY_RSP;
  1073.     Message.oslDataPtr = (oslParaType*) MsgPtr;
  1074.     Message.oslPeerBuffPtr = NULL;
  1075.     OslMsgSendExtQueue(&Message);
  1076. }
  1077. /*****************************************************************************
  1078.  * FUNCTION
  1079.  *  mmi_phb_java_get_group_info_req
  1080.  * DESCRIPTION
  1081.  *  This function gets group information.
  1082.  * PARAMETERS
  1083.  *  info        [?]     
  1084.  * RETURNS
  1085.  *  void
  1086.  *****************************************************************************/
  1087. void mmi_phb_java_get_group_info_req(void *info)
  1088. {
  1089.     /*----------------------------------------------------------------*/
  1090.     /* Local Variables                                                */
  1091.     /*----------------------------------------------------------------*/
  1092.     U8 count;
  1093.     mmi_phb_handler_get_group_info_req_struct *LocalPtr;
  1094.     /*----------------------------------------------------------------*/
  1095.     /* Code Body                                                      */
  1096.     /*----------------------------------------------------------------*/
  1097.     LocalPtr = (mmi_phb_handler_get_group_info_req_struct*) info;
  1098.     if (!g_phb_cntx.phb_ready || g_phb_cntx.processing)
  1099.     {
  1100.         mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_NOT_READY, 0);
  1101.         return;
  1102.     }
  1103. #ifdef __MMI_PHB_USIM_FIELD__
  1104.     if (g_phb_cntx.is_usim && g_phb_cntx.usim_ready_stage != MMI_PHB_USIM_READY)
  1105.     {
  1106.         mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_NOT_READY, 0);
  1107.         return;
  1108.     }
  1109. #endif /* __MMI_PHB_USIM_FIELD__ */
  1110.     /* Get entry data */
  1111.     if(LocalPtr->storage == MMI_STORAGE_BOTH)
  1112.     {
  1113.         if (LocalPtr->group_ptr == NULL)
  1114.         {
  1115.         #ifdef __MMI_PHB_USIM_FIELD__
  1116.             mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_SUCCESS, (U8)(MAX_PB_CALLER_GROUPS + g_phb_cntx.gas_total));
  1117.         #else
  1118.             mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_SUCCESS, MAX_PB_CALLER_GROUPS);
  1119.         #endif
  1120.             return;
  1121.         }
  1122.         if ((LocalPtr->max_group > 0) && (LocalPtr->group_ptr != NULL))
  1123.         {
  1124.             /* Copy group information by assigned count number */
  1125.             for (count = 0; count < LocalPtr->max_group;count++)
  1126.             {
  1127.                 if (count < (MAX_PB_CALLER_GROUPS )) /* max group no in phone */
  1128.                 {
  1129.                     mmi_phb_callergroup_copy_group_info(count, LocalPtr->group_ptr[count].group_name);
  1130.                     LocalPtr->group_ptr[count].group_id = count;
  1131.                 }
  1132.             #ifdef __MMI_PHB_USIM_FIELD__
  1133.                 else if (g_phb_cntx.is_usim && count < (MAX_PB_CALLER_GROUPS + g_phb_cntx.gas_total))
  1134.                 {
  1135.                     mmi_phb_op_edit_usim_entry_req();
  1136.                 }
  1137.                 /* Email sorting not populated after bootup. */
  1138.             #endif /* __MMI_PHB_USIM_FIELD__ */
  1139.                 else
  1140.                 {
  1141.                     mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_SUCCESS, count);
  1142.                     return;
  1143.                 }
  1144.             }
  1145.             mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_SUCCESS, count);
  1146.             return;
  1147.         }
  1148.         /* Error */
  1149.         mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_ERROR, 0);
  1150.     }
  1151.     else if (LocalPtr->storage == MMI_NVRAM)
  1152.     {
  1153.         if (LocalPtr->group_ptr == NULL)
  1154.         {
  1155.             mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_SUCCESS, MAX_PB_CALLER_GROUPS);
  1156.             return;
  1157.         }
  1158.         if ((LocalPtr->max_group > 0) && (LocalPtr->group_ptr != NULL))
  1159.         {
  1160.             /* Copy group information by assigned count number */
  1161.             for (count = 0; count < LocalPtr->max_group;count++)
  1162.             {
  1163.                 if (count < (MAX_PB_CALLER_GROUPS )) /* max group no in phone */
  1164.                 {
  1165.                     mmi_phb_callergroup_copy_group_info(count, LocalPtr->group_ptr[count].group_name);
  1166.                     LocalPtr->group_ptr[count].group_id = count;
  1167.                 }
  1168.                 else
  1169.                 {
  1170.                     mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_SUCCESS, count);
  1171.                     return;
  1172.                 }
  1173.             }
  1174.             mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_SUCCESS, count);
  1175.             return;
  1176.         }
  1177.         /* Error */
  1178.         mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_ERROR, 0);
  1179.     }
  1180.     else if (LocalPtr->storage == MMI_SIM)
  1181.     {
  1182.     #ifdef __MMI_PHB_USIM_FIELD__
  1183.         if (LocalPtr->group_ptr == NULL)
  1184.         {
  1185.             mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_SUCCESS, g_phb_cntx.gas_total);
  1186.             return;
  1187.         }
  1188.     #else /* __MMI_PHB_USIM_FIELD__ */
  1189.         if (LocalPtr->group_ptr == NULL)
  1190.         {
  1191.             mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_SUCCESS, 0);
  1192.             return;
  1193.         }
  1194.         else
  1195.         {
  1196.             mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_ERROR, 0);
  1197.             return;
  1198.         }
  1199.     #endif /* __MMI_PHB_USIM_FIELD__ */
  1200.     }
  1201.     else
  1202.     {
  1203.         mmi_phb_java_get_group_info_rsp(MMI_PHB_JAVA_ERROR, 0);
  1204.         return;
  1205.     }
  1206. }
  1207. /*****************************************************************************
  1208. * FUNCTION
  1209.  *  mmi_phb_java_get_group_info_rsp
  1210. * DESCRIPTION
  1211. *   This function initializes phonebook handler app.
  1212. * PARAMETERS
  1213.  *  result      [IN]        
  1214.  *  count       [IN]        
  1215.  * RETURNS
  1216. *  void
  1217.  *****************************************************************************/
  1218. void mmi_phb_java_get_group_info_rsp(U16 result, U16 count)
  1219. {
  1220.     /*----------------------------------------------------------------*/
  1221.     /* Local Variables                                                */
  1222.     /*----------------------------------------------------------------*/
  1223.     mmi_phb_handler_get_group_info_rsp_struct *MsgPtr;
  1224.     MYQUEUE Message;
  1225.     /*----------------------------------------------------------------*/
  1226.     /* Code Body                                                      */
  1227.     /*----------------------------------------------------------------*/
  1228.     MsgPtr = (mmi_phb_handler_get_group_info_rsp_struct*) OslConstructDataPtr(sizeof(mmi_phb_handler_get_group_info_rsp_struct));
  1229.     MsgPtr->result = result;
  1230.     MsgPtr->count = count;
  1231.     Message.oslSrcId = MOD_MMI;
  1232.     Message.oslDestId = MOD_JASYN;
  1233.     Message.oslMsgId = MSG_ID_MMI_PHB_JAVA_GET_GROUP_INFO_RSP;
  1234.     Message.oslDataPtr = (oslParaType*) MsgPtr;
  1235.     Message.oslPeerBuffPtr = NULL;
  1236.     OslMsgSendExtQueue(&Message);
  1237. }
  1238. /*****************************************************************************
  1239.  * FUNCTION
  1240.  *  mmi_phb_java_set_group_info_req
  1241.  * DESCRIPTION
  1242.  *  This function write a group name from JAVA request
  1243.  * PARAMETERS
  1244.  *  info        [IN]     
  1245. * RETURNS
  1246. *  void
  1247. *****************************************************************************/
  1248. void mmi_phb_java_set_group_info_req(void *info)
  1249. {
  1250.    /*----------------------------------------------------------------*/
  1251.    /* Local Variables                                                */
  1252.    /*----------------------------------------------------------------*/
  1253.     mmi_phb_handler_set_group_info_req_struct *LocalPtr;
  1254.    /*----------------------------------------------------------------*/
  1255.    /* Code Body                                                      */
  1256.    /*----------------------------------------------------------------*/
  1257.     LocalPtr = (mmi_phb_handler_set_group_info_req_struct*) info;
  1258.     if (!g_phb_cntx.phb_ready || g_phb_cntx.processing)
  1259.     {
  1260.         mmi_phb_java_set_group_info_rsp(MMI_PHB_JAVA_NOT_READY);
  1261.         return;
  1262.     }
  1263. #ifdef __SYNCML_SUPPORT__
  1264.     if (mmi_syncml_is_phb_sync_now())
  1265.     {
  1266.         mmi_phb_java_set_group_info_rsp(MMI_PHB_JAVA_NOT_READY);
  1267.         return;
  1268.     }
  1269. #endif /* __SYNCML_SUPPORT__ */
  1270. #ifdef __MMI_PHB_USIM_FIELD__
  1271.     if (g_phb_cntx.is_usim && g_phb_cntx.usim_ready_stage != MMI_PHB_USIM_READY && 
  1272.         LocalPtr->group_id > MAX_PB_CALLER_GROUPS)
  1273.    {
  1274.         mmi_phb_java_set_group_info_rsp(MMI_PHB_JAVA_NOT_READY);
  1275.         return;
  1276.     }
  1277.     if (LocalPtr->group_id > (MAX_PB_CALLER_GROUPS + g_phb_cntx.gas_total))
  1278. #else
  1279.     if (LocalPtr->group_id > MAX_PB_CALLER_GROUPS )
  1280. #endif /* __MMI_PHB_USIM_FIELD__ */
  1281.     {
  1282.         mmi_phb_java_set_group_info_rsp(MMI_PHB_JAVA_OUT_OF_INDEX);
  1283.         return;
  1284.     }
  1285.     /* Update group name operation. */
  1286.     if (LocalPtr->group_ptr != NULL)
  1287.     {
  1288.     #ifdef __MMI_PHB_USIM_FIELD__
  1289.         if (g_phb_cntx.is_usim && LocalPtr->group_id > MAX_PB_CALLER_GROUPS)
  1290.         {
  1291.             if (!mmi_phb_gas_is_duplicated(LocalPtr->group_id - MAX_PB_CALLER_GROUPS - 1, LocalPtr->group_ptr->group_name))
  1292.             {
  1293.                 g_phb_cntx.java_store_index = LocalPtr->group_id - MAX_PB_CALLER_GROUPS - 1;
  1294.                 g_phb_enter_from = MMI_PHB_ENTER_FROM_JAVA;
  1295.                 /* Prepare data for group name field */
  1296.                 memcpy(pbName, LocalPtr->group_ptr->group_name, (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH);
  1297.                 memset(pbNumber, 0, ENCODING_LENGTH);
  1298.                 mmi_phb_gas_save_req();
  1299.             }
  1300.         }
  1301.         else
  1302.     #endif /* __MMI_PHB_USIM_FIELD__ */
  1303.         {
  1304.             if (!mmi_phb_callergroup_name_is_duplicated((U16)(LocalPtr->group_id - 1), (S8*)(LocalPtr->group_ptr->group_name)))
  1305.             {
  1306.                 S16 pError;
  1307.                 PHB_CALLER_GROUP_STRUCT* callerGroups = (PHB_CALLER_GROUP_STRUCT*) g_phb_cntx.caller_group;
  1308.                 callerGroups[LocalPtr->group_id - 1].is_modified = 1;
  1309.                 pfnUnicodeStrncpy(
  1310.                     (PS8)callerGroups[LocalPtr->group_id - 1].groupName,
  1311.                     (PS8)LocalPtr->group_ptr->group_name,
  1312.                     MAX_GRP_NAME_LENGTH);
  1313.                 WriteRecord(NVRAM_EF_PHB_CALLER_GROUPS_LID, 1, callerGroups, CALLER_GROUPS_RECORD_SIZE, &pError);
  1314.                 mmi_phb_java_set_group_info_rsp(MMI_PHB_JAVA_SUCCESS);
  1315.                 return;
  1316.             }
  1317.         }
  1318.     }
  1319.     mmi_phb_java_set_group_info_rsp(MMI_PHB_JAVA_ERROR);
  1320. }
  1321. /*****************************************************************************
  1322.  * FUNCTION
  1323.  *  mmi_phb_java_set_group_info_rsp
  1324.  * DESCRIPTION
  1325.  *  This function return set group info result to JAVA
  1326.  * PARAMETERS
  1327.  *  result          [IN]        
  1328.  * RETURNS
  1329.  *  void
  1330.  *****************************************************************************/
  1331. void mmi_phb_java_set_group_info_rsp(U16 result)
  1332. {
  1333.     /*----------------------------------------------------------------*/
  1334.     /* Local Variables                                                */
  1335.     /*----------------------------------------------------------------*/
  1336.     mmi_phb_handler_set_group_info_rsp_struct *MsgPtr;
  1337.     MYQUEUE Message;
  1338.     /*----------------------------------------------------------------*/
  1339.     /* Code Body                                                      */
  1340.     /*----------------------------------------------------------------*/
  1341.     MsgPtr = (mmi_phb_handler_set_group_info_rsp_struct*) OslConstructDataPtr(sizeof(mmi_phb_handler_set_group_info_rsp_struct));
  1342.     MsgPtr->result = result;
  1343.     g_phb_enter_from = MMI_PHB_ENTER_NONE;
  1344.     Message.oslSrcId = MOD_MMI;
  1345.     Message.oslDestId = MOD_JASYN;
  1346.     Message.oslMsgId = MSG_ID_MMI_PHB_JAVA_SET_GROUP_INFO_RSP;
  1347.     Message.oslDataPtr = (oslParaType*) MsgPtr;
  1348.     Message.oslPeerBuffPtr = NULL;
  1349.     OslMsgSendExtQueue(&Message);
  1350. }
  1351. #define MMI_PHB_JAVA_HANDLER_UTILITIES
  1352. /*****************************************************************************
  1353.  * FUNCTION
  1354.  *  mmi_phb_java_util_get_index_by_store_index
  1355.  * DESCRIPTION
  1356.  *  This function reture sort index by store index.
  1357.  * PARAMETERS
  1358.  *  sort_type           [IN]        
  1359.  *  storage             [IN]        
  1360.  *  in_store_index      [IN]        
  1361.  * RETURNS
  1362.  *  U16
  1363.  *****************************************************************************/
  1364. U16 mmi_phb_java_util_get_index_by_store_index(U8 sort_type, U8 storage, U16 in_store_index)
  1365. {
  1366.     /*----------------------------------------------------------------*/
  1367.     /* Local Variables                                                */
  1368.     /*----------------------------------------------------------------*/
  1369.     U16 i;
  1370.     U16 count = 0;
  1371.     U16 store_index;
  1372.     /*----------------------------------------------------------------*/
  1373.     /* Code Body                                                      */
  1374.     /*----------------------------------------------------------------*/
  1375.     /*
  1376.      * Sort By Name
  1377.      */
  1378.     if (sort_type == MMI_PHB_BY_NAME)
  1379.     {
  1380.         for (i = 0; i < PhoneBookEntryCount; i++)
  1381.         {
  1382.             store_index = g_phb_name_index[i];
  1383.             if ((storage == MMI_STORAGE_BOTH) ||
  1384.                 ((storage == MMI_NVRAM) && (store_index < MAX_PB_PHONE_ENTRIES)) ||
  1385.                 ((storage == MMI_SIM) && (store_index >= MAX_PB_PHONE_ENTRIES)))
  1386.             {
  1387.                 count++;
  1388.             }
  1389.             if (store_index == in_store_index)
  1390.             {
  1391.                 return count;
  1392.             }
  1393.         }
  1394.     }
  1395.     /*
  1396.      * Sort By Email, Only for storage in NVRAM only.
  1397.      */
  1398. #if defined(__MMI_PHB_EMAIL_SORT__)
  1399.     else if (sort_type == MMI_PHB_BY_EMAIL)
  1400.     {
  1401.         S16 pError;
  1402.     #ifdef __MMI_PHB_USIM_FIELD__
  1403.         U16 g_phb_email_index[MAX_PB_ENTRIES];
  1404.         ReadRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_ENTRIES * sizeof(U16), &pError);
  1405.         for (i = 0; i < PhoneBookEntryCount; i++)
  1406.     #else /* __MMI_PHB_USIM_FIELD__ */ 
  1407.         U16 g_phb_email_index[MAX_PB_PHONE_ENTRIES];
  1408.         if (storage != MMI_NVRAM)
  1409.         {
  1410.             return 0xffff;
  1411.         }
  1412.         ReadRecord(
  1413.             NVRAM_EF_PHB_EMAIL_SORT_LID,
  1414.             1,
  1415.             (void*)g_phb_email_index,
  1416.             MAX_PB_PHONE_ENTRIES * sizeof(U16),
  1417.             &pError);
  1418.         for (i = 0; i < g_phb_cntx.phone_used; i++)
  1419.     #endif /* __MMI_PHB_USIM_FIELD__ */ 
  1420.         {
  1421.             store_index = g_phb_email_index[i];
  1422.             count++;
  1423.             if (store_index == in_store_index)
  1424.             {
  1425.                 return count;
  1426.             }
  1427.         }
  1428.     }
  1429. #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  1430.     return 0xffff;
  1431. }
  1432. /*****************************************************************************
  1433.  * FUNCTION
  1434.  *  mmi_phb_java_util_get_store_index_by_sort_index
  1435.  * DESCRIPTION
  1436.  *  This function reture store index by sort index.
  1437.  * PARAMETERS
  1438.  *  sort_type           [IN]        
  1439.  *  storage             [IN]        
  1440.  *  in_sort_index       [IN]        
  1441.  * RETURNS
  1442.  *  U16
  1443.  *****************************************************************************/
  1444. U16 mmi_phb_java_util_get_store_index_by_sort_index(U8 sort_type, U8 storage, U16 in_sort_index)
  1445. {
  1446.     /*----------------------------------------------------------------*/
  1447.     /* Local Variables                                                */
  1448.     /*----------------------------------------------------------------*/
  1449.     U16 count = 0;
  1450.     U16 store_index;
  1451.     U16 pos;
  1452.     /*----------------------------------------------------------------*/
  1453.     /* Code Body                                                      */
  1454.     /*----------------------------------------------------------------*/
  1455.     /* Sort By NAME */
  1456.     if (sort_type == MMI_PHB_BY_NAME)
  1457.     {
  1458.         /* Find index position */
  1459.         for (pos = 0; pos < PhoneBookEntryCount; pos++)
  1460.         {
  1461.             store_index = g_phb_name_index[pos];
  1462.             if ((storage == MMI_STORAGE_BOTH) ||
  1463.                 (storage == MMI_NVRAM && store_index < MAX_PB_PHONE_ENTRIES) ||
  1464.                 (storage == MMI_SIM && store_index >= MAX_PB_PHONE_ENTRIES))
  1465.             {
  1466.                 count++;
  1467.             }
  1468.             if (count == in_sort_index)
  1469.             {
  1470.                 return store_index;
  1471.             }
  1472.         }
  1473.     }
  1474.     /* Support Email sorting */
  1475. #if defined(__MMI_PHB_EMAIL_SORT__)
  1476. #ifdef __MMI_PHB_USIM_FIELD__
  1477.     else if (LocalPtr->sort_type == MMI_PHB_BY_EMAIL)
  1478. #else 
  1479.     else if ((LocalPtr->sort_type == MMI_PHB_BY_EMAIL) && (LocalPtr->storage == MMI_NVRAM))
  1480. #endif 
  1481.     {
  1482.         S16 pError;
  1483.     #ifdef __MMI_PHB_USIM_FIELD__
  1484.         U16 g_phb_email_index[MAX_PB_ENTRIES];
  1485.     #else 
  1486.         U16 g_phb_email_index[MAX_PB_PHONE_ENTRIES];
  1487.     #endif 
  1488.         /* Email sorting not populated after bootup. */
  1489.         if (g_phb_email_sorted == 0)
  1490.         {
  1491.             mmi_phb_java_util_rebuild_email_sorting();
  1492.             g_phb_email_sorted = 1;
  1493.         }
  1494.     #ifdef __MMI_PHB_USIM_FIELD__
  1495.         ReadRecord(
  1496.             NVRAM_EF_PHB_EMAIL_SORT_LID,
  1497.             1,
  1498.             (void*)g_phb_email_index,
  1499.             MAX_PB_ENTRIES * sizeof(U16),
  1500.             &pError);
  1501.     #else /* __MMI_PHB_USIM_FIELD__ */ 
  1502.         ReadRecord(
  1503.             NVRAM_EF_PHB_EMAIL_SORT_LID,
  1504.             1,
  1505.             (void*)g_phb_email_index,
  1506.             MAX_PB_PHONE_ENTRIES * sizeof(U16),
  1507.             &pError);
  1508.     #endif /* __MMI_PHB_USIM_FIELD__ */ 
  1509.         /* Find first index position */
  1510.         pos = in_sort_index - 1;
  1511.         return g_phb_email_index[pos];
  1512.     }
  1513. #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  1514.     return 0xffff;
  1515. }
  1516. /*****************************************************************************
  1517.  * FUNCTION
  1518.  *  mmi_phb_java_util_copy_entry_from_phb
  1519.  * DESCRIPTION
  1520.  *  This function
  1521.  * PARAMETERS
  1522.  *  store_index     [IN]        
  1523.  *  entry           [OUT]         
  1524.  * RETURNS
  1525.  *  void
  1526.  *****************************************************************************/
  1527. void mmi_phb_java_util_copy_entry_from_phb(U16 store_index, mmi_phb_handler_entry_struct *entry)
  1528. {
  1529.     /*----------------------------------------------------------------*/
  1530.     /* Local Variables                                                */
  1531.     /*----------------------------------------------------------------*/
  1532.     S16 pError;
  1533.     /*----------------------------------------------------------------*/
  1534.     /* Code Body                                                      */
  1535.     /*----------------------------------------------------------------*/
  1536.     entry->store_index = store_index;
  1537.     memcpy(entry->name, PhoneBook[store_index].alpha_id.name, (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH);
  1538.     mmi_phb_convert_get_ucs2_number(entry->number, store_index);
  1539.     if (store_index < MAX_PB_PHONE_ENTRIES) /* In NVRAM */
  1540.     {
  1541.     #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  1542.         ReadRecord(
  1543.             NVRAM_EF_PHB_FIELDS_LID,
  1544.             (U16) (store_index + 1),
  1545.             (void*)&PhoneBookOptionalFields,
  1546.             OPTIONAL_FIELDS_RECORD_SIZE,
  1547.             &pError);
  1548.         AnsiiToUnicodeString(entry->homeNumber, (PS8) PhoneBookOptionalFields.homeNumber);
  1549.         pfnUnicodeStrcpy(entry->companyName, (PS8) PhoneBookOptionalFields.companyName);
  1550.         AnsiiToUnicodeString(entry->emailAddress, (PS8) PhoneBookOptionalFields.emailAddress);
  1551.         AnsiiToUnicodeString(entry->officeNumber, (PS8) PhoneBookOptionalFields.officeNumber);
  1552.         AnsiiToUnicodeString(entry->faxNumber, (PS8) PhoneBookOptionalFields.faxNumber);
  1553.     #else /* clear buffer */
  1554.         memset(entry->homeNumber, 0, 2);
  1555.         memset(entry->companyName, 0, 2);
  1556.         memset(entry->emailAddress, 0, 2);
  1557.         memset(entry->officeNumber, 0, 2);
  1558.         memset(entry->faxNumber, 0, 2);
  1559.     #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */
  1560.     #ifdef __MMI_PHB_BIRTHDAY_FIELD__
  1561.         mmi_phb_java_get_bday(store_index, &entry->bDay);
  1562.     #else
  1563.         mmi_phb_java_util_clear_bday(&entry->bDay);
  1564.     #endif
  1565.         mmi_phb_read_optional_ids(store_index);
  1566.         entry->group_id = ((PHB_OPTIONAL_IDS_STRUCT *)g_phb_cntx.optional_ids)->callerGroupID;
  1567.     }
  1568.     else
  1569.     {
  1570.     #ifdef __MMI_PHB_USIM_FIELD__
  1571.         mmi_phb_op_set_option_data_by_usim_index(store_index, &PhoneBookOptionalFields);
  1572.         AnsiiToUnicodeString(entry->homeNumber, (PS8) PhoneBookOptionalFields.homeNumber);
  1573.         AnsiiToUnicodeString(entry->officeNumber, (PS8) PhoneBookOptionalFields.officeNumber);
  1574.         AnsiiToUnicodeString(entry->faxNumber, (PS8) PhoneBookOptionalFields.faxNumber);
  1575.         AnsiiToUnicodeString(entry->emailAddress, (PS8) PhoneBookOptionalFields.emailAddress);
  1576.         entry->group_id = g_phb_cntx.group_type[store_index - MAX_PB_PHONE_ENTRIES];
  1577.     #else /* __MMI_PHB_USIM_FIELD__ */ 
  1578.         memset(entry->homeNumber, 0, 2);
  1579.         memset(entry->officeNumber, 0, 2);
  1580.         memset(entry->faxNumber, 0, 2);
  1581.         memset(entry->emailAddress, 0, 2);
  1582.         entry->group_id = 0;
  1583.     #endif /* __MMI_PHB_USIM_FIELD__ */ 
  1584.     }
  1585. }
  1586. #if defined(__MMI_PHB_EMAIL_SORT__)
  1587. /*****************************************************************************
  1588.  * FUNCTION
  1589.  *  mmi_phb_java_util_rebuild_email_sorting
  1590.  * DESCRIPTION
  1591.  *  This function
  1592.  * PARAMETERS
  1593.  *  void
  1594.  * RETURNS
  1595.  *  void
  1596.  *****************************************************************************/
  1597. void mmi_phb_java_util_rebuild_email_sorting(void)
  1598. {
  1599.     /*----------------------------------------------------------------*/
  1600.     /* Local Variables                                                */
  1601.     /*----------------------------------------------------------------*/
  1602.     U16 i, j;
  1603.     U16 store_index;
  1604.     S16 pError;
  1605.     U16 *g_phb_email_index;
  1606.     U16 pop_count = 0;
  1607.     U16 pos;
  1608.     /*----------------------------------------------------------------*/
  1609.     /* Code Body                                                      */
  1610.     /*----------------------------------------------------------------*/
  1611.     g_phb_cntx.processing = TRUE;
  1612.     mmi_phb_java_entry_processing_email();
  1613. #ifdef __MMI_PHB_USIM_FIELD__
  1614.     g_phb_email_index = OslMalloc(MAX_PB_ENTRIES * sizeof(U16));
  1615.     memset(g_phb_email_index, 0xff, MAX_PB_ENTRIES * sizeof(U16));
  1616. #else /* __MMI_PHB_USIM_FIELD__ */ 
  1617.     g_phb_email_index = OslMalloc(MAX_PB_PHONE_ENTRIES * sizeof(U16));
  1618.     memset(g_phb_email_index, 0xff, MAX_PB_PHONE_ENTRIES * sizeof(U16));
  1619. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  1620.     for (i = 0; i < PhoneBookEntryCount; i++)
  1621.     {
  1622.         store_index = g_phb_name_index[i];
  1623.     #ifndef __MMI_PHB_USIM_FIELD__
  1624.         if (store_index < MAX_PB_PHONE_ENTRIES) /* Entry in phone */
  1625.     #endif 
  1626.         {
  1627.             ++pop_count;
  1628.             if (pop_count == 1)
  1629.             {
  1630.                 g_phb_email_index[(pop_count - 1)] = store_index;
  1631.             }
  1632.             else
  1633.             {
  1634.                 pos = mmi_phb_sort_email_find_insert_pos(0, (pop_count - 2), store_index, g_phb_email_index);
  1635.                 for (j = (pop_count - 1); j > pos; j--)
  1636.                 {
  1637.                     g_phb_email_index[j] = g_phb_email_index[j - 1];
  1638.                 }
  1639.                 g_phb_email_index[pos] = store_index;
  1640.             }
  1641.         }
  1642.     }
  1643. #ifdef __MMI_PHB_USIM_FIELD__
  1644.     WriteRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_ENTRIES * sizeof(U16), &pError);
  1645. #else 
  1646.     WriteRecord(NVRAM_EF_PHB_EMAIL_SORT_LID, 1, (void*)g_phb_email_index, MAX_PB_PHONE_ENTRIES * sizeof(U16), &pError);
  1647. #endif 
  1648.     OslMfree(g_phb_email_index);
  1649.     g_phb_cntx.processing = FALSE;
  1650.     /* DisplayPopup((PU8)GetString(STR_GLOBAL_DONE), IMG_GLOBAL_ACTIVATED, TRUE, PHB_NOTIFY_TIMEOUT, SUCCESS_TONE); */
  1651.     GoBackHistory();
  1652. }
  1653. /*****************************************************************************
  1654.  * FUNCTION
  1655.  *  mmi_phb_java_entry_processing_email
  1656.  * DESCRIPTION
  1657.  *  This function
  1658.  * PARAMETERS
  1659.  *  void
  1660.  * RETURNS
  1661.  *  void
  1662.  *****************************************************************************/
  1663. void mmi_phb_java_entry_processing_email(void)
  1664. {
  1665.     /*----------------------------------------------------------------*/
  1666.     /* Local Variables                                                */
  1667.     /*----------------------------------------------------------------*/
  1668.     /*----------------------------------------------------------------*/
  1669.     /* Code Body                                                      */
  1670.     /*----------------------------------------------------------------*/
  1671.     EntryNewScreen(SCR_ID_PHB_SORTING_EMAIL, mmi_phb_java_exit_processing_email, NULL, NULL);
  1672.     ShowCategory8Screen(
  1673.         STR_SCR_PBOOK_CAPTION,
  1674.         IMG_SCR_PBOOK_CAPTION,
  1675.         0,
  1676.         0,
  1677.         0,
  1678.         0,
  1679.         STR_ID_PHB_SORTING_EMAIL,
  1680.         IMG_PROCESSING_PHONEBOOK,
  1681.         NULL);
  1682.     ClearInputEventHandler(MMI_DEVICE_ALL);
  1683.     ClearKeyHandler(KEY_END, KEY_EVENT_UP);
  1684.     ClearKeyHandler(KEY_END, KEY_EVENT_DOWN);
  1685.     ClearKeyHandler(KEY_END, KEY_LONG_PRESS);
  1686.     ClearKeyHandler(KEY_END, KEY_REPEAT);
  1687. }
  1688. /*****************************************************************************
  1689.  * FUNCTION
  1690.  *  mmi_phb_java_exit_processing_email
  1691.  * DESCRIPTION
  1692.  *  This function
  1693.  * PARAMETERS
  1694.  *  void
  1695.  * RETURNS
  1696.  *  void
  1697.  *****************************************************************************/
  1698. void mmi_phb_java_exit_processing_email(void)
  1699. {
  1700.     /*----------------------------------------------------------------*/
  1701.     /* Local Variables                                                */
  1702.     /*----------------------------------------------------------------*/
  1703.     history h;
  1704.     S16 nHistory = 0;
  1705.     /*----------------------------------------------------------------*/
  1706.     /* Code Body                                                      */
  1707.     /*----------------------------------------------------------------*/
  1708.     if (g_phb_cntx.processing)
  1709.     {
  1710.         g_phb_cntx.end_scr_id = SCR_ID_PHB_SORTING_EMAIL;
  1711.         h.scrnID = SCR_ID_PHB_SORTING_EMAIL;
  1712.         h.entryFuncPtr = mmi_phb_java_entry_processing_email;
  1713.         pfnUnicodeStrcpy((PS8) h.inputBuffer, (PS8) & nHistory);
  1714.         GetCategoryHistory(h.guiBuffer);
  1715.         AddHistory(h);
  1716.     }
  1717. }
  1718. #endif /* defined(__MMI_PHB_EMAIL_SORT__) */
  1719. #ifdef __MMI_PHB_BIRTHDAY_FIELD__
  1720. /*****************************************************************************
  1721.  * FUNCTION
  1722.  *  mmi_phb_java_check_bday_is_valid
  1723.  * DESCRIPTION
  1724.  *  This function
  1725.  * PARAMETERS
  1726.  *  store_index     [IN]
  1727.  *  entry           [OUT]
  1728.  * RETURNS
  1729.  *  void
  1730.  *****************************************************************************/
  1731. MMI_BOOL mmi_phb_java_check_bday_is_valid(applib_time_struct *t)
  1732. {
  1733.     /*----------------------------------------------------------------*/
  1734.     /* Local Variables                                                */
  1735.     /*----------------------------------------------------------------*/
  1736.     
  1737.     /*----------------------------------------------------------------*/
  1738.     /* Code Body                                                      */
  1739.     /*----------------------------------------------------------------*/
  1740.     /* error handling */
  1741. if ((t->nYear == 0) && (t->nMonth == 0) && (t->nDay == 0) && (t->nHour == 0) &&
  1742.         (t->nMin == 0) && (t->nSec == 0) && (t->DayIndex == 0))
  1743. {
  1744. return MMI_TRUE;
  1745. }
  1746. else
  1747. {
  1748.         if (t->nYear > MMI_PHB_BDAY_MAX_YEAR_INT || t->nYear < MMI_PHB_BDAY_MIN_YEAR_INT)
  1749.         {
  1750.             return MMI_FALSE;
  1751.         }
  1752.         if (t->nMonth > 12)
  1753.         {
  1754.             return MMI_FALSE;
  1755.         }
  1756.         if (t->nMonth == 2)
  1757.         {
  1758.             if (t->nDay > (g_dt_day_per_mon[t->nMonth - 1] + applib_dt_is_leap_year(t->nYear)))
  1759.             {
  1760.                 return MMI_FALSE;
  1761.             }
  1762.         }
  1763.         else
  1764.         {
  1765.             if (t->nDay > g_dt_day_per_mon[t->nMonth - 1])
  1766.             {
  1767.                 return MMI_FALSE;
  1768.             }
  1769.         }
  1770.         if (t->nHour > 23)
  1771.         {
  1772.             return MMI_FALSE;
  1773.         }
  1774.         if (t->nMin > 59)
  1775.         {
  1776.             return MMI_FALSE;
  1777.         }
  1778.         if (t->nSec > 59)
  1779.         {
  1780.             return MMI_FALSE;
  1781.         }
  1782.         return MMI_TRUE;
  1783. }
  1784. }
  1785. /*****************************************************************************
  1786.  * FUNCTION
  1787.  *  mmi_phb_java_set_bday
  1788.  * DESCRIPTION
  1789.  *  This function
  1790.  * PARAMETERS
  1791.  *  store_index     [IN]
  1792.  *  entry           [OUT]
  1793.  * RETURNS
  1794.  *  void
  1795.  *****************************************************************************/
  1796. void mmi_phb_java_set_bday(applib_time_struct* b_day, S8* pb_Year, S8* pb_Mon, S8* pb_Day)
  1797. {
  1798.     /*----------------------------------------------------------------*/
  1799.     /* Local Variables                                                */
  1800.     /*----------------------------------------------------------------*/
  1801.     S8 ascii_buff[6];
  1802.     /*----------------------------------------------------------------*/
  1803.     /* Code Body                                                      */
  1804.     /*----------------------------------------------------------------*/
  1805.     sprintf(ascii_buff, "%04d", b_day->nYear);
  1806.     AnsiiToUnicodeString(pb_Year, ascii_buff);
  1807.     sprintf(ascii_buff, "%02d", b_day->nMonth);
  1808.     AnsiiToUnicodeString(pb_Mon, ascii_buff);
  1809.     sprintf(ascii_buff, "%02d", b_day->nDay);
  1810.     AnsiiToUnicodeString(pb_Day, ascii_buff);
  1811. }
  1812. /*****************************************************************************
  1813.  * FUNCTION
  1814.  *  mmi_phb_java_get_bday
  1815.  * DESCRIPTION
  1816.  *  This function
  1817.  * PARAMETERS
  1818.  *  store_index     [IN]
  1819.  *  entry           [OUT]
  1820.  * RETURNS
  1821.  *  void
  1822.  *****************************************************************************/
  1823. void mmi_phb_java_get_bday(U16 store_index, applib_time_struct *b_day)
  1824. {
  1825.     /*----------------------------------------------------------------*/
  1826.     /* Local Variables                                                */
  1827.     /*----------------------------------------------------------------*/
  1828.     U16 bday_record, bday_index;
  1829.     S16 pError;
  1830.     MMI_PHB_BDAY_STRUCT bday_data[NVRAM_EF_PHB_BIRTHDAY_COUNT];
  1831.     /*----------------------------------------------------------------*/
  1832.     /* Code Body                                                      */
  1833.     /*----------------------------------------------------------------*/
  1834.     bday_record = (store_index / NVRAM_EF_PHB_BIRTHDAY_COUNT) + 1;
  1835.     bday_index = store_index - (bday_record - 1) * NVRAM_EF_PHB_BIRTHDAY_COUNT;
  1836.     ReadRecord(NVRAM_EF_PHB_BIRTHDAY_LID, bday_record, (void*)bday_data, NVRAM_EF_PHB_BIRTHDAY_SIZE, &pError);
  1837.     /* Year */
  1838.     if (bday_data[bday_index].bYear <= MMI_PHB_BDAY_MAX_YEAR_INT && bday_data[bday_index].bYear >= MMI_PHB_BDAY_MIN_YEAR_INT)
  1839.     {
  1840.         b_day->nYear = bday_data[bday_index].bYear;
  1841.     }
  1842.     else
  1843.     {
  1844.         b_day->nYear = 0;
  1845.     }
  1846.     /* Month */
  1847.     if (bday_data[bday_index].bMonth <= 12)
  1848.     {
  1849.         b_day->nMonth = bday_data[bday_index].bMonth;
  1850.     }
  1851.     else
  1852.     {
  1853.         b_day->nMonth = 0;
  1854.     }
  1855.     /* Day */
  1856.     if (bday_data[bday_index].bDay <= 31)
  1857.     {
  1858.         b_day->nDay = bday_data[bday_index].bDay;
  1859.     }
  1860.     else
  1861.     {
  1862.         b_day->nDay = 0;
  1863.     }
  1864.     b_day->nHour = b_day->nMin = b_day->nSec = b_day->DayIndex = 0;
  1865. }
  1866. #else /* defined (__MMI_PHB_BIRTHDAY_FIELD__)*/
  1867. /*****************************************************************************
  1868.  * FUNCTION
  1869.  *  mmi_phb_java_util_clear_bday
  1870.  * DESCRIPTION
  1871.  *  This function
  1872.  * PARAMETERS
  1873.  *  store_index     [IN]
  1874.  *  entry           [OUT]
  1875.  * RETURNS
  1876.  *  void
  1877.  *****************************************************************************/
  1878. void mmi_phb_java_util_clear_bday(applib_time_struct* b_day)
  1879. {
  1880.     /*----------------------------------------------------------------*/
  1881.     /* Local Variables                                                */
  1882.     /*----------------------------------------------------------------*/
  1883.     /*----------------------------------------------------------------*/
  1884.     /* Code Body                                                      */
  1885.     /*----------------------------------------------------------------*/
  1886. b_day->nYear = b_day->nMonth = b_day->nDay = b_day->nHour = b_day->nMin = b_day->nSec = b_day->DayIndex = 0;
  1887. }
  1888. #endif /* defined (__MMI_PHB_BIRTHDAY_FIELD__)*/
  1889. #endif /* defined(SUPPORT_JSR_75_PIM) || defined(SUPPORT_CMCC) */ 
  1890. #endif /* _MMI_PHONEBOOKJAVAHANDLER_C */