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

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.  * PhoneBookMain.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for phonebook main function.
  48.  *   Including initialize procedure, main menu, common utilities, etc.
  49.  *
  50.  * Author:
  51.  * -------
  52.  * -------
  53.  *
  54.  *============================================================================
  55.  *             HISTORY
  56.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  57.  *------------------------------------------------------------------------------
  58.  * removed!
  59.  *
  60.  * removed!
  61.  * removed!
  62.  * removed!
  63.  *
  64.  * removed!
  65.  * removed!
  66.  * removed!
  67.  *
  68.  * removed!
  69.  * removed!
  70.  * removed!
  71.  *
  72.  * removed!
  73.  * removed!
  74.  * removed!
  75.  *
  76.  * removed!
  77.  * removed!
  78.  * removed!
  79.  *
  80.  * removed!
  81.  * removed!
  82.  * removed!
  83.  *
  84.  * removed!
  85.  * removed!
  86.  * removed!
  87.  *
  88.  * removed!
  89.  * removed!
  90.  * removed!
  91.  *
  92.  * removed!
  93.  * removed!
  94.  * removed!
  95.  *
  96.  * removed!
  97.  * removed!
  98.  * removed!
  99.  *
  100.  * removed!
  101.  * removed!
  102.  * removed!
  103.  *
  104.  * removed!
  105.  * removed!
  106.  * removed!
  107.  *
  108.  * removed!
  109.  * removed!
  110.  * removed!
  111.  *
  112.  * removed!
  113.  * removed!
  114.  * removed!
  115.  *
  116.  * removed!
  117.  * removed!
  118.  * removed!
  119.  *
  120.  * removed!
  121.  * removed!
  122.  * removed!
  123.  *
  124.  * removed!
  125.  * removed!
  126.  * removed!
  127.  *
  128.  * removed!
  129.  * removed!
  130.  * removed!
  131.  *
  132.  * removed!
  133.  * removed!
  134.  * removed!
  135.  *
  136.  * removed!
  137.  * removed!
  138.  * removed!
  139.  *
  140.  * removed!
  141.  * removed!
  142.  * removed!
  143.  *
  144.  * removed!
  145.  * removed!
  146.  * removed!
  147.  *
  148.  * removed!
  149.  * removed!
  150.  * removed!
  151.  *
  152.  * removed!
  153.  * removed!
  154.  * removed!
  155.  *
  156.  * removed!
  157.  * removed!
  158.  * removed!
  159.  *
  160.  * removed!
  161.  * removed!
  162.  * removed!
  163.  *
  164.  * removed!
  165.  * removed!
  166.  * removed!
  167.  *
  168.  * removed!
  169.  * removed!
  170.  * removed!
  171.  *
  172.  * removed!
  173.  * removed!
  174.  * removed!
  175.  *
  176.  * removed!
  177.  * removed!
  178.  * removed!
  179.  *
  180.  * removed!
  181.  * removed!
  182.  * removed!
  183.  *
  184.  * removed!
  185.  * removed!
  186.  * removed!
  187.  *
  188.  * removed!
  189.  * removed!
  190.  * removed!
  191.  *
  192.  * removed!
  193.  * removed!
  194.  * removed!
  195.  *
  196.  * removed!
  197.  * removed!
  198.  * removed!
  199.  *
  200.  * removed!
  201.  * removed!
  202.  * removed!
  203.  *
  204.  * removed!
  205.  * removed!
  206.  * removed!
  207.  *
  208.  * removed!
  209.  * removed!
  210.  * removed!
  211.  *
  212.  * removed!
  213.  * removed!
  214.  * removed!
  215.  *
  216.  * removed!
  217.  * removed!
  218.  * removed!
  219.  *
  220.  * removed!
  221.  * removed!
  222.  * removed!
  223.  *
  224.  * removed!
  225.  * removed!
  226.  * removed!
  227.  *
  228.  * removed!
  229.  * removed!
  230.  * removed!
  231.  *
  232.  * removed!
  233.  * removed!
  234.  * removed!
  235.  *
  236.  * removed!
  237.  * removed!
  238.  * removed!
  239.  *
  240.  * removed!
  241.  * removed!
  242.  * removed!
  243.  *
  244.  * removed!
  245.  * removed!
  246.  * removed!
  247.  *
  248.  * removed!
  249.  * removed!
  250.  * removed!
  251.  *
  252.  * removed!
  253.  * removed!
  254.  * removed!
  255.  *
  256.  * removed!
  257.  * removed!
  258.  * removed!
  259.  *
  260.  * removed!
  261.  * removed!
  262.  * removed!
  263.  *
  264.  * removed!
  265.  * removed!
  266.  * removed!
  267.  *
  268.  * removed!
  269.  * removed!
  270.  * removed!
  271.  *
  272.  * removed!
  273.  * removed!
  274.  * removed!
  275.  *
  276.  * removed!
  277.  * removed!
  278.  * removed!
  279.  *
  280.  * removed!
  281.  * removed!
  282.  * removed!
  283.  *
  284.  * removed!
  285.  * removed!
  286.  * removed!
  287.  *
  288.  * removed!
  289.  * removed!
  290.  * removed!
  291.  *
  292.  * removed!
  293.  * removed!
  294.  * removed!
  295.  *
  296.  * removed!
  297.  * removed!
  298.  * removed!
  299.  *
  300.  * removed!
  301.  * removed!
  302.  * removed!
  303.  *
  304.  * removed!
  305.  * removed!
  306.  * removed!
  307.  *
  308.  * removed!
  309.  * removed!
  310.  * removed!
  311.  *
  312.  * removed!
  313.  * removed!
  314.  * removed!
  315.  *
  316.  * removed!
  317.  * removed!
  318.  * removed!
  319.  *
  320.  * removed!
  321.  * removed!
  322.  * removed!
  323.  *
  324.  * removed!
  325.  * removed!
  326.  * removed!
  327.  *
  328.  * removed!
  329.  * removed!
  330.  * removed!
  331.  *
  332.  * removed!
  333.  * removed!
  334.  * removed!
  335.  *
  336.  * removed!
  337.  * removed!
  338.  * removed!
  339.  *
  340.  * removed!
  341.  * removed!
  342.  * removed!
  343.  *
  344.  * removed!
  345.  * removed!
  346.  * removed!
  347.  *
  348.  * removed!
  349.  * removed!
  350.  * removed!
  351.  *
  352.  * removed!
  353.  * removed!
  354.  * removed!
  355.  *
  356.  * removed!
  357.  * removed!
  358.  * removed!
  359.  *
  360.  * removed!
  361.  * removed!
  362.  * removed!
  363.  *
  364.  * removed!
  365.  * removed!
  366.  * removed!
  367.  *
  368.  * removed!
  369.  * removed!
  370.  * removed!
  371.  *
  372.  * removed!
  373.  * removed!
  374.  * removed!
  375.  *
  376.  * removed!
  377.  * removed!
  378.  * removed!
  379.  *
  380.  * removed!
  381.  * removed!
  382.  * removed!
  383.  *
  384.  * removed!
  385.  * removed!
  386.  *
  387.  *
  388.  * removed!
  389.  * removed!
  390.  *
  391.  *
  392.  * removed!
  393.  * removed!
  394.  * removed!
  395.  *
  396.  * removed!
  397.  * removed!
  398.  *
  399.  *
  400.  * removed!
  401.  * removed!
  402.  *
  403.  *
  404.  * removed!
  405.  * removed!
  406.  *
  407.  *
  408.  * removed!
  409.  * removed!
  410.  *
  411.  *
  412.  * removed!
  413.  * removed!
  414.  *
  415.  *
  416.  *------------------------------------------------------------------------------
  417.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  418.  *============================================================================
  419.  ****************************************************************************/
  420. #ifndef _PHONEBOOKMAIN_C
  421. #define _PHONEBOOKMAIN_C
  422. #include "MMI_features.h"
  423. #include "stdC.h"
  424. #include "L4Dr1.h"
  425. #include "PixtelDataTypes.h"
  426. #include "GlobalConstants.h"
  427. #include "kal_trace.h"  /* Debug Info */
  428. #include "DebugInitDef.h"       /* Debug Info */
  429. #include "mmi_trc.h"    /* Debug Info */
  430. #include "ProtocolEvents.h"
  431. #include "HistoryGprot.h"
  432. #include "wgui_categories.h"
  433. #include "wgui_categories_inputs.h"
  434. #include "wgui_status_icons.h"
  435. #include "AllAppGprot.h"
  436. #include "PhonebookDef.h"
  437. #include "PhoneBookTypes.h"
  438. #include "PhonebookProt.h"
  439. #include "PhonebookGprot.h"
  440. #include "QueueGProt.h"
  441. #include "mainmenudef.h"
  442. #include "Unicodexdcl.h"
  443. #include "GlobalDefs.h"
  444. #include "TimerEvents.h"
  445. #include "IdleAppDef.h"
  446. #include "SpeedDial.h"
  447. #include "NVRAMProt.h"
  448. #include "NVRAMType.h"
  449. #include "NVRAMEnum.h"
  450. #include "IdleAppDef.h"
  451. #include "IdleAppProt.h"
  452. #include "CommonScreens.h"
  453. #include "SettingGprots.h"
  454. #include "gpioInc.h"
  455. #include "CommonScreens.h"
  456. #include "SettingDefs.h"        /* For FDN on Message */
  457. #include "SettingsGdcl.h"
  458. #ifdef MMI_ON_HARDWARE_P
  459. #include "nvram_data_items.h"
  460. #endif 
  461. #include "GSM7BitDefaultAlphabet.h"
  462. #include "statusiconres.h"
  463. #if defined(__MMI_PHB_UPDATE_CALL_LOG_AFTER_SAVE__)     /* Update Call Log after save number */
  464. #include "CallHistoryGProts.h"
  465. #endif 
  466. #if defined(__MMI_FILE_MANAGER__) && defined(MMI_ON_HARDWARE_P)
  467. #include "wgui_categories_fmgr.h"       /* For image list */
  468. #endif
  469. #ifdef __J2ME__
  470. #include "j2me_custom_option.h"
  471. #endif
  472. #if defined(SUPPORT_JSR_75_PIM) || defined(SUPPORT_CMCC)
  473. #include "PhoneBookJavaHandler.h"
  474. #endif 
  475. #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
  476. #include "ProfileGprots.h"
  477. #endif 
  478. #include "CallManagementGprot.h"
  479. #if defined(__MMI_VRSI__)
  480. #include "Mdi_datatype.h"
  481. #include "VRSIEnum.h"
  482. #include "VRSIType.h"
  483. #include "VRSIProt.h"
  484. #endif /* defined(__MMI_VRSI__) */ 
  485. #if !defined(__MMI_KEYPADLOCK_WITH_KEYTONE__)
  486. #include "KeyBrd.h"
  487. #endif 
  488. #include "PictureEditorDefs.h"
  489. #include "SimDetectionGprot.h"
  490. #ifdef __MMI_VOIP__
  491. #include "VoIPGProt.h"
  492. #endif
  493. #ifdef __SYNCML_SUPPORT__
  494. #include "SyncMLDef.h"
  495. #include "SyncMLGprot.h"
  496. #endif /* __SYNCML_SUPPORT__ */
  497. #ifdef __USB_IN_NORMAL_MODE__ 
  498. #include "USBDeviceGprot.h"
  499. #endif /* __USB_IN_NORMAL_MODE__ */
  500. /*
  501.  * Local Variable
  502.  */
  503. static PHB_OPTIONAL_IDS_STRUCT g_phb_optional_ids;
  504. static PHB_CALLER_GROUP_STRUCT g_phb_caller_group[MAX_PB_CALLER_GROUPS];
  505. #ifdef __MMI_PHB_USIM_FIELD__
  506. static MMI_PHB_NAME_STRUCT g_phb_usim_group[MAX_PB_USIM_GROUPS];
  507. #endif 
  508. static U16 g_phb_message;
  509. static U16 g_phb_message_icon;
  510. static U16 g_phb_alpha_index_list[ALPHA_LIST_LENGTH];
  511. static U16 g_phb_highlight_alpha;
  512. #if defined(__MMI_VOIP__)
  513. static U8 phb_voip_number_index = 0xff;
  514. #endif 
  515. #if defined(__MMI_PHB_NAME_LIST_FILTER__)
  516. static U32 g_phb_list_index_total;
  517. #endif /* defined(__MMI_PHB_NAME_LIST_FILTER__) */
  518. mmi_phb_context_struct g_phb_cntx;
  519. U16 PhoneBookEntryCount;
  520. #if (MAX_PB_ENTRIES)
  521. U16 g_phb_name_index[MAX_PB_ENTRIES];   /* Sorting Order by Name Field. */
  522. MMI_PHB_ENTRY_BCD_STRUCT PhoneBook[MAX_PB_ENTRIES];
  523. #if (MAX_PB_ENTRIES >= 1000)
  524. U16 g_phb_list_filter[MAX_PB_ENTRIES];
  525. #endif /* MAX_PB_ENTRIES >= 1000 */
  526. #else /* (MAX_PB_ENTRIES) */ 
  527. U16 g_phb_name_index[1];    /* Sorting Order by Name Field. */
  528. MMI_PHB_ENTRY_BCD_STRUCT PhoneBook[1];
  529. #endif /* (MAX_PB_ENTRIES) */ 
  530. #ifdef __MMI_PHB_USIM_FIELD__
  531. MMI_PHB_EMAIL_STRUCT phb_email[MAX_PB_SIM_ENTRIES];
  532. MMI_PHB_NUMBER_BCD_STRUCT phb_anr[MAX_PB_SIM_ENTRIES][3];
  533. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  534. #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) || defined(__MMI_PHB_USIM_FIELD__)
  535. PHB_OPTIONAL_FIELDS_STRUCT PhoneBookOptionalFields;
  536. #endif 
  537. MMI_PHB_LOOKUP_NODE_STRUCT LookUpTable[MAX_LOOKUP_TABLE_COUNT];
  538. #ifdef __MTK_TARGET__
  539. __align(2)
  540. #endif
  541. S8 pbName[(MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH];
  542. #ifdef __MTK_TARGET__
  543. __align(2)
  544. #endif
  545. S8 pbNumber[(MAX_PB_NUMBER_LENGTH+1+1)*ENCODING_LENGTH];
  546. S8 pbHomeNumber[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];      /* ANRA */
  547. S8 pbCompanyName[(MAX_PB_COMPANY_LENGTH + 1) * ENCODING_LENGTH];        /* ANRB */
  548. S8 pbEmailAddress[(MAX_PB_EMAIL_LENGTH + 1) * ENCODING_LENGTH];
  549. S8 pbOfficeNumber[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];
  550. S8 pbFaxNumber[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];       /* ANRC */
  551. #if defined(__MMI_PHB_BIRTHDAY_FIELD__)
  552. S8 pbBday[12 * ENCODING_LENGTH];    /* Use for display total sstring, Format: xxxx/xx/xx */
  553. S8 pbDay[3 * ENCODING_LENGTH];
  554. S8 pbMon[3 * ENCODING_LENGTH];
  555. S8 pbYear[6 * ENCODING_LENGTH];
  556. #endif /* defined(__MMI_PHB_BIRTHDAY_FIELD__) */ 
  557. #if defined(__MMI_PHB_INFO_FIELD__)
  558. PHB_INFO_FIELDS_STRUCT PhoneBookInfoFields;
  559. S8 pbTitle[(MAX_PB_TITLE_LENGTH + 1) * ENCODING_LENGTH];
  560. S8 pbUrl[(MAX_PB_URL_LENGTH + 1) * ENCODING_LENGTH];
  561. S8 pbAddress[(MAX_PB_ADDRESS_LENGTH + 1) * ENCODING_LENGTH];
  562. S8 pbNote[(MAX_PB_NOTE_LENGTH + 1) * ENCODING_LENGTH];
  563. #endif /* defined(__MMI_PHB_INFO_FIELD__) */ 
  564. #if defined(__MMI_VOIP__)
  565. S8 PhoneBookVoipField[VOIP_URI_LEN];
  566. S8 pbVoip[(VOIP_URI_LEN) * ENCODING_LENGTH];
  567. #endif /* defined(__MMI_VOIP__) */ 
  568. #ifdef __MMI_PHB_USIM_FIELD__
  569. S8 pbNickName[(MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH];
  570. #endif 
  571. U8 gPictureItemIndex = 10;
  572. U16 TitleStrings[MAX_PB_FIELDS];
  573. #ifdef __MMI_INTELLIGENT_CALL_ALERT__
  574. U8 g_phb_is_speaking_name = 0;
  575. #endif 
  576. /*
  577.  * Global Variable
  578.  */
  579. extern MMI_PHB_LIST_VIEW phbListView;
  580. extern wgui_inline_item wgui_inline_items[];
  581. extern BOOL r2lMMIFlag; /* For right to left language */
  582. extern U8 gInsertSimAppFlag;
  583. extern U16 g_phb_read_index;
  584. extern BOOL g_phb_mass_op_success;  /* for sim refresh */
  585. extern U16 g_phb_mass_op_count;
  586. extern U8 g_phb_enter_from;
  587. /*
  588.  * Global Function
  589.  */
  590. extern void MakeCall(PS8);
  591. extern void set_wgui_inline_list_menu_changed(void);
  592. #if defined(__IP_NUMBER__)
  593. extern void SetTempUseIPNumber(pBOOL flag);
  594. #endif 
  595. #if defined(__MMI_PHB_CALLERGROUP_IN_SIM__)
  596. static U8 g_phb_sim_check;
  597. extern kal_bool is_sim_replaced(void);
  598. #endif /* defined(__MMI_PHB_CALLERGROUP_IN_SIM__) */ 
  599. #if defined(__MMI_FILE_MANAGER__) && defined(MMI_ON_HARDWARE_P)
  600. extern void Cat212ShortCutHdlr(S32 item_index); /* For Image List Fast Jump */
  601. #endif 
  602. /*
  603.  * Static Function
  604.  */
  605. #ifdef __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__
  606. static void mmi_phb_two_line_send_key_handler(void);
  607. #endif 
  608. #ifdef __MMI_PHB_USIM_FIELD__
  609. static void mmi_phb_ind_startup_phase1_finish(void *info);
  610. static void mmi_phb_startup_anr_read_rsp(void *info);
  611. static void mmi_phb_startup_email_read_rsp(void *info);
  612. static void mmi_phb_startup_gas_read_rsp(void *info);
  613. static void mmi_phb_read_usim_field(U8 access_id);
  614. static void mmi_phb_read_usim_anr_field(void *info);
  615. static void mmi_phb_read_usim_email_field(void *info);
  616. static void mmi_phb_read_usim_gas_field(void *info);
  617. static void mmi_phb_read_usim_grp_field(void *info);
  618. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  619. #define MMI_PHB_INIT
  620. /*****************************************************************************
  621.  * FUNCTION
  622.  *  mmi_phb_init_protocol
  623.  * DESCRIPTION
  624.  *  Initialize phonebook protocol handler. This should be call before L4 begin to read
  625.  * PARAMETERS
  626.  *  void
  627.  * RETURNS
  628.  *  void
  629.  *****************************************************************************/
  630. void mmi_phb_init_protocol(void)
  631. {
  632.     /*----------------------------------------------------------------*/
  633.     /* Local Variables                                                */
  634.     /*----------------------------------------------------------------*/
  635.     /*----------------------------------------------------------------*/
  636.     /* Code Body                                                      */
  637.     /*----------------------------------------------------------------*/
  638.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_init_protocol.>n", __FILE__, __LINE__));
  639. #ifdef __MMI_PHB_USIM_FIELD__
  640.     SetProtocolEventHandler(mmi_phb_ind_startup_phase1_finish, PRT_PHB_STARTUP_PHASE1_FINISH_IND);
  641.     SetProtocolEventHandler(mmi_phb_read_usim_anr_field, PRT_PHB_STARTUP_READ_ANR_IND);
  642.     SetProtocolEventHandler(mmi_phb_read_usim_email_field, PRT_PHB_STARTUP_READ_EMAIL_IND);
  643.     SetProtocolEventHandler(mmi_phb_read_usim_gas_field, PRT_PHB_STARTUP_READ_GAS_IND);
  644.     SetProtocolEventHandler(mmi_phb_read_usim_grp_field, PRT_PHB_STARTUP_READ_GRP_IND);
  645. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  646.     SetProtocolEventHandler(mmi_phb_ind_startup_finish, PRT_PHB_STARTUP_FINISH_IND);
  647. #if defined(MMI_ON_HARDWARE_P)
  648.     SetProtocolEventHandler(mmi_phb_ind_startup_begin, PRT_PHB_STARTUP_BEGIN_IND);
  649.     SetProtocolEventHandler(mmi_phb_ind_startup_read, PRT_PHB_STARTUP_READ_IND);
  650. #endif /* defined(MMI_ON_HARDWARE_P) */ 
  651. #if defined(SUPPORT_JSR_75_PIM) || defined(SUPPORT_CMCC)
  652.     mmi_phb_java_handler_init();
  653. #endif 
  654.     /* Initial Global Context. */
  655.     g_phb_cntx.phb_ready = FALSE;
  656.     g_phb_cntx.processing = FALSE;
  657.     g_phb_cntx.nvram_data_init = FALSE;
  658.     g_phb_cntx.optional_ids = &g_phb_optional_ids;
  659.     g_phb_cntx.caller_group = &g_phb_caller_group[0];
  660. #ifdef __MMI_PHB_USIM_FIELD__
  661.     g_phb_cntx.usim_group = &g_phb_usim_group[0];
  662.     g_phb_cntx.usim_ready_stage = MMI_PHB_USIM_NOT_READY;
  663.     memset(g_phb_cntx.support_field, 0, MMI_PHB_USIM_FIELD_TOTAL);
  664. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  665.     g_phb_cntx.list_filter = NULL;
  666.     g_phb_cntx.start_scr_id = 0;
  667.     g_phb_cntx.end_scr_id = 0;
  668.     g_phb_cntx.refresh_list = MMI_PHB_ENTRY_REFRESH;
  669.     g_phb_cntx.highlight_entry = 0;
  670.     g_phb_cntx.new_highlight_entry = 0xffff;
  671.     g_phb_cntx.populate_count = 0;
  672.     g_phb_cntx.lookup_table_count = 0;
  673.     g_phb_cntx.current_op = MMI_PHB_OP_NONE;
  674.     g_phb_cntx.selected_pic_index = 0;
  675.     g_phb_cntx.selected_ring_index = 0;
  676.     g_phb_cntx.selected_grp_index = 0;
  677.     g_phb_cntx.selected_pattern_index = 0;
  678.     g_phb_cntx.selected_alert_index = 0;
  679.     g_phb_cntx.selected_pic_in_view = 0;
  680.     g_phb_cntx.image_location = MMI_PHB_IMAGE_NO_SELECT;
  681.     g_phb_cntx.set_done_flag = 0;
  682.     g_phb_cntx.dial_from_list = MMI_PHB_NONE;
  683. #if defined(__MMI_PHB_PINYIN_SORT__)
  684.     g_phb_cntx.sort_type = MMI_PHB_SORT_PINYIN;
  685. #else 
  686.     g_phb_cntx.sort_type = MMI_PHB_SORT_ENCODING;
  687. #endif 
  688. }
  689. /*****************************************************************************
  690.  * FUNCTION
  691.  *  mmi_phb_init
  692.  * DESCRIPTION
  693.  *  Initialize phonebook applications.
  694.  *  (This is used to initialize hilite/hint handlers and PS reponse callback functions)
  695.  * PARAMETERS
  696.  *  void
  697.  * RETURNS
  698.  *  void
  699.  *****************************************************************************/
  700. void mmi_phb_init(void)
  701. {
  702.     /*----------------------------------------------------------------*/
  703.     /* Local Variables                                                */
  704.     /*----------------------------------------------------------------*/
  705.     /*----------------------------------------------------------------*/
  706.     /* Code Body                                                      */
  707.     /*----------------------------------------------------------------*/
  708.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_init.>n", __FILE__, __LINE__));
  709.     mmi_phb_search_init();
  710.     mmi_phb_operate_single_init();
  711.     mmi_phb_operate_mass_init();
  712.     mmi_phb_caller_group_init();
  713.     mmi_phb_extra_number_init();
  714.     mmi_phb_setting_init();
  715.     PhbInitSpeedDial();
  716.     mmi_phb_stubs_to_others_init();
  717. }
  718. /*****************************************************************************
  719.  * FUNCTION
  720.  *  mmi_phb_set_main_menu_highlight_handler
  721.  * DESCRIPTION
  722.  *  Set phonebook main menu highlight handler
  723.  * PARAMETERS
  724.  *  void
  725.  * RETURNS
  726.  *  void
  727.  *****************************************************************************/
  728. static void mmi_phb_set_main_menu_highlight_handler(void)
  729. {
  730.     /*----------------------------------------------------------------*/
  731.     /* Local Variables                                                */
  732.     /*----------------------------------------------------------------*/
  733.     /*----------------------------------------------------------------*/
  734.     /* Code Body                                                      */
  735.     /*----------------------------------------------------------------*/
  736.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_set_main_menu_highlight_handler.>n",
  737.                          __FILE__, __LINE__));
  738.     SetHiliteHandler(MITEM101_PBOOK_SEARCH_ENTRY, mmi_phb_highlight_search_name);
  739. #if defined(__MMI_PHB_QUICK_SEARCH__) || defined(MMI_ON_WIN32)
  740.     SetHiliteHandler(MENU_ID_PHB_QUICK_SEARCH, mmi_phb_highlight_quick_search_list);
  741. #endif 
  742.     /* Add Entry */
  743.     SetHiliteHandler(MITEM102_PBOOK_NEW_ENTRY, mmi_phb_highlight_op_add_entry);
  744.     /* Copy All */
  745.     SetHiliteHandler(MITEM104_PBOOK_COPY_ALL, mmi_phb_highlight_copy_all);
  746.     /* Delete All */
  747.     SetHiliteHandler(MITEM103_PBOOK_DELETE_ALL, mmi_phb_highlight_delete_all);
  748.     SetHiliteHandler(MITEM109_PBOOK_CALLER_GROUPS, mmi_phb_highlight_callergroup);
  749.     mmi_phb_extra_number_init();
  750.     /* Settings */
  751.     SetHiliteHandler(MITEM110_PBOOK_SETTINGS, mmi_phb_highlight_setting);
  752.     SetHiliteHandler(MITEM1101_PBOOK_MEMORY_STATUS, mmi_phb_highlight_memory_status);
  753.     SetHiliteHandler(MITEM1102_PBOOK_STORAGE_LOCATION, mmi_phb_highlight_storage_location);
  754.     SetHiliteHandler(MITEM1103_PBOOK_VIEW_FIELDS, mmi_phb_highlight_view_field);
  755.     SetHintHandler(MITEM1102_PBOOK_STORAGE_LOCATION, mmi_phb_hint_storage_location);
  756.     SetHintHandler(MITEM_STORAGE_LOCATION_SIM, mmi_phb_hint_storage_location_in_sim);
  757.     SetHintHandler(MITEM_STORAGE_LOCATION_PHONE, mmi_phb_hint_storage_location_in_phone);
  758. #if defined(__MMI_PHB_NAME_LIST_FILTER__)
  759.     SetHiliteHandler(MENU_ID_PHB_NAME_LIST_FILTER, mmi_phb_highlight_name_list_filter);
  760.     SetHintHandler(MENU_ID_PHB_NAME_LIST_FILTER, mmi_phb_hint_name_list_filter);
  761. #endif /* defined(__MMI_PHB_NAME_LIST_FILTER__) */
  762.     
  763.     /* My vCard */
  764.     SetHiliteHandler(MENU_ID_PHB_VCARD_MYCARD, mmi_phb_highlight_vcard_mycard);
  765.     SetHiliteHandler(MENU_ID_PHB_VCARD_EDIT_MYCARD, mmi_phb_highlight_vcard_edit_mycard);
  766.     SetHiliteHandler(MENU_ID_PHB_VCARD_SEND_MYCARD, mmi_phb_highlight_vcard_send_mycard);
  767. #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
  768.     SetHiliteHandler(MENU_ID_PHB_SPEAK_NAME, mmi_phb_highlight_speak_name);
  769.     SetHintHandler(MENU_ID_PHB_SPEAK_NAME, mmi_phb_hint_speak_name);
  770. #endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */ 
  771.     /* Forward resource to phonebook entry */
  772. #if defined(__MMI_PHB_CALLER_RES_SETTING__)
  773.     /* For submenu in phonebook */
  774.     SetHiliteHandler(MENU_ID_PHB_CALLER_PIC, mmi_phb_highlight_caller_pic);
  775.     SetHiliteHandler(MENU_ID_PHB_CALLER_RING, mmi_phb_highlight_caller_ring);
  776. #if defined(__MMI_INCOMING_CALL_VIDEO__)
  777.     SetHiliteHandler(MENU_ID_PHB_CALLER_VIDEO, mmi_phb_highlight_caller_video);
  778. #endif 
  779. #endif /* defined(__MMI_PHB_CALLER_RES_SETTING__) */ 
  780. #if defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__)
  781.     /* Save Image From File Manager */
  782.     SetHiliteHandler(MENU_ID_PHB_FMGR_SAVE_NEW, mmi_phb_highlight_fmgr_add_entry);
  783.     SetHiliteHandler(MENU_ID_PHB_FMGR_SAVE_LIST, mmi_phb_highlight_fmgr_edit_entry);
  784.     SetHiliteHandler(MENU_ID_PHB_FMGR_SAVE_CALLGRP, mmi_phb_highlight_edit_callergroup);
  785. #endif /* defined(__MMI_FILE_MANAGER__) && !defined(__MMI_FILE_MANAGER_HIDE_MENU__) */ 
  786.     /* Done and Input Method */
  787.     mmi_frm_set_highlight_handler();
  788. }
  789. /*****************************************************************************
  790.  * FUNCTION
  791.  *  mmi_phb_ind_startup_begin
  792.  * DESCRIPTION
  793.  *  Initialize variables before L4 Phb start to read
  794.  * PARAMETERS
  795.  *  info        [?]     
  796.  * RETURNS
  797.  *  void
  798.  *****************************************************************************/
  799. void mmi_phb_ind_startup_begin(void *info)
  800. {
  801.     /*----------------------------------------------------------------*/
  802.     /* Local Variables                                                */
  803.     /*----------------------------------------------------------------*/
  804.     /*----------------------------------------------------------------*/
  805.     /* Code Body                                                      */
  806.     /*----------------------------------------------------------------*/
  807.     g_phb_cntx.phb_ready = FALSE;
  808. #ifdef __MMI_PHB_USIM_FIELD__
  809.     g_phb_cntx.usim_ready_stage = MMI_PHB_USIM_NOT_READY;
  810. #endif 
  811.     g_phb_cntx.sim_used = 0;
  812.     g_phb_cntx.phone_used = 0;
  813.     PhoneBookEntryCount = 0;
  814.     g_phb_cntx.lookup_table_count = 0;
  815.     g_phb_cntx.populate_count = 0;
  816.     g_phb_cntx.current_op = MMI_PHB_OP_NONE;
  817. #if defined(__MMI_VRSI__)
  818.     /* Phonebook reload so need reset VR. After sorting done, add phonebook entry again. */
  819.     mmi_vrsi_init_central_reset();
  820. #endif /* defined(__MMI_VRSI__) */ 
  821. }
  822. /*****************************************************************************
  823.  * FUNCTION
  824.  *  mmi_phb_sat_handler
  825.  * DESCRIPTION
  826.  *  Handler sim refresh cmd
  827.  * PARAMETERS
  828.  *  reset_adn        [IN]
  829.  * RETURNS
  830.  *  void
  831.  *****************************************************************************/
  832. void mmi_phb_sat_handler(BOOL reset_adn)
  833. {
  834.     g_phb_cntx.phb_ready = FALSE;
  835. #ifdef __MMI_PHB_USIM_FIELD__
  836.     g_phb_cntx.usim_ready_stage = MMI_PHB_USIM_NOT_READY;
  837. #endif
  838.     if (reset_adn)
  839.     {
  840.         g_phb_cntx.sim_used = 0;
  841.         g_phb_cntx.phone_used = 0;
  842.         PhoneBookEntryCount = 0;
  843.     }
  844.     g_phb_cntx.lookup_table_count = 0;
  845.     g_phb_cntx.populate_count = 0;
  846. #if defined(__MMI_VRSI__)
  847.     /* Phonebook reload so need reset VR. After sorting done, add phonebook entry again. */
  848.     mmi_vrsi_init_central_reset();
  849. #endif /* defined(__MMI_VRSI__) */ 
  850.     if (g_phb_cntx.processing)
  851.     {
  852.         S8 outBuf[100], count[10];
  853.         g_phb_cntx.processing = FALSE;
  854.         TurnOnBacklight(1); /* Turn On Back Light When done */
  855.         DeleteScreenIfPresent(SCR_IN_PROGRESS_PHB);
  856.         if (g_phb_cntx.copy_all)
  857.         {
  858.             g_phb_cntx.copy_all = FALSE;
  859.             /* Display result for !g_phb_mass_op_success */
  860.             g_phb_mass_op_success = TRUE;
  861.             sprintf(count, "%d ", g_phb_mass_op_count);
  862.             AnsiiToUnicodeString(outBuf, count);
  863.             pfnUnicodeStrcat(outBuf, GetString(STR_ENTRIES_COPIED));
  864.             DisplayPopup((PU8) outBuf, IMG_GLOBAL_UNFINISHED, TRUE, PHB_NOTIFY_TIMEOUT, ERROR_TONE);
  865.             /* Solve Copying Screen Hang Problem */
  866.             DeleteScreenIfPresent(SCR_COPY_ALL_PROGRESS);
  867.         }
  868.         else
  869.         {
  870.             /* Display result for !g_phb_mass_op_success */
  871.             g_phb_mass_op_success = TRUE;
  872.             sprintf(count, "%d ", g_phb_mass_op_count);
  873.             AnsiiToUnicodeString(outBuf, count);
  874.             pfnUnicodeStrcat(outBuf, GetString(STR_ID_PHB_ENTRIES_DELETED));
  875.             DisplayPopup((U8*) outBuf, IMG_GLOBAL_UNFINISHED, TRUE, PHB_NOTIFY_TIMEOUT, ERROR_TONE);
  876.             /* Solve Copying Screen Hang Problem */
  877.             DeleteScreenIfPresent(SCR_COPY_ALL_PROGRESS);
  878.             /* Re-add all central command for vrsi. */
  879.         #if defined(__MMI_VRSI__)
  880.             mmi_vrsi_init_central_abort();
  881.             /* Also remove SD tag if entry is deleted. */
  882.         #if defined(__MMI_VRSI_TRAIN_TAG__)
  883.             mmi_vrsi_ndial_central_update_sd_mapping();
  884.         #endif 
  885.         #endif /* defined(__MMI_VRSI__) */ 
  886.         }
  887.     }
  888.     else if (g_phb_cntx.current_op == MMI_PHB_OP_ADD)
  889.     {
  890.         DisplayPopup(
  891.             (PU8) GetString(STR_GLOBAL_UNFINISHED),
  892.             IMG_GLOBAL_UNFINISHED,
  893.             TRUE,
  894.             PHB_NOTIFY_TIMEOUT,
  895.             ERROR_TONE);
  896.         mmi_phb_clear_old_add_history();
  897.     }
  898.     else if (g_phb_cntx.current_op == MMI_PHB_OP_EDIT)
  899.     {
  900.         DisplayPopup(
  901.             (PU8) GetString(STR_GLOBAL_UNFINISHED),
  902.             IMG_GLOBAL_UNFINISHED,
  903.             TRUE,
  904.             PHB_NOTIFY_TIMEOUT,
  905.             ERROR_TONE);
  906.         mmi_phb_clear_old_edit_history();
  907.     }
  908.     g_phb_enter_from = MMI_PHB_ENTER_NONE;
  909.     /* copyEntry = duplicateEntry = moveEntry = FALSE;*/
  910.     g_phb_cntx.current_op = MMI_PHB_NONE;
  911. }
  912. #ifdef __MMI_INTELLIGENT_CALL_ALERT__
  913. /*****************************************************************************
  914.  * FUNCTION
  915.  *  mmi_phb_speak_name_handler
  916.  * DESCRIPTION
  917.  *  
  918.  * PARAMETERS
  919.  *  result      [IN]        
  920.  * RETURNS
  921.  *  void
  922.  *****************************************************************************/
  923. void mmi_phb_speak_name_handler(mdi_result result)
  924. {
  925.     /*----------------------------------------------------------------*/
  926.     /* Local Variables                                                */
  927.     /*----------------------------------------------------------------*/
  928.     /*----------------------------------------------------------------*/
  929.     /* Code Body                                                      */
  930.     /*----------------------------------------------------------------*/
  931.     g_phb_is_speaking_name = 0;
  932. }
  933. #endif /* __MMI_INTELLIGENT_CALL_ALERT__ */ 
  934. #if defined(MMI_ON_HARDWARE_P)
  935. /*****************************************************************************
  936.  * FUNCTION
  937.  *  mmi_phb_startup_read_entry
  938.  * DESCRIPTION
  939.  *  This function set the read indication data from L4 Phb at bootup time.
  940.  *  Stores each indication to the global phonebook list.
  941.  * PARAMETERS
  942.  *  phb_entry       [IN]        
  943.  *  store_index     [IN]        
  944.  * RETURNS
  945.  *  void
  946.  *****************************************************************************/
  947. static void mmi_phb_startup_read_entry(l4c_phb_bcd_entry_struct phb_entry, U16 store_index)
  948. {
  949.     /*----------------------------------------------------------------*/
  950.     /* Local Variables                                                */
  951.     /*----------------------------------------------------------------*/
  952.     U8 num_ascii[MAX_PB_NUMBER_LENGTH + 1 + 1];
  953.     U8 bcd_length = 0;
  954.     /*----------------------------------------------------------------*/
  955.     /* Code Body                                                      */
  956.     /*----------------------------------------------------------------*/
  957.     /* Name Field */
  958.     PhoneBook[store_index].alpha_id.name_length = phb_entry.alpha_id.name_length;
  959.     PhoneBook[store_index].alpha_id.name_dcs = phb_entry.alpha_id.name_dcs;
  960.     if (PhoneBook[store_index].alpha_id.name_length == 0 
  961.         || (phb_entry.alpha_id.name[0] == 0xff && phb_entry.alpha_id.name[1] == 0xff))
  962.     {
  963.         memset(PhoneBook[store_index].alpha_id.name, 0, 2);
  964.     }
  965.     else
  966.     {
  967.         InputboxConvertGSMToDeviceEncoding(
  968.             phb_entry.alpha_id.name,
  969.             PhoneBook[store_index].alpha_id.name,
  970.             phb_entry.alpha_id.name_length,
  971.             (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH,
  972.             phb_entry.alpha_id.name_dcs,
  973.             0,
  974.             1);
  975.     }
  976. #if defined(__PHB_0x81_SUPPORT__)       /* Support maximum length of 0x81 UCS2 */
  977.     if (PhoneBook[store_index].alpha_id.name_dcs == MMI_PHB_UCS2_81 ||
  978.         PhoneBook[store_index].alpha_id.name_dcs == MMI_PHB_UCS2_82)
  979.     {
  980.         PhoneBook[store_index].alpha_id.name_dcs = MMI_PHB_UCS2;
  981.     }
  982. #endif /* defined(__PHB_0x81_SUPPORT__) */ 
  983. #if defined(__MMI_PHB_PINYIN_SORT__)
  984.     mmi_phb_util_make_pinyin_cache(store_index);
  985. #endif 
  986.     /* Number Field
  987.        For L4 phb struct, the first byte of addr_bcd is TON, and the rest are BCD numbers.
  988.        And the length is the total byte of TON + BCD numbers. */
  989.     PhoneBook[store_index].tel.type = phb_entry.tel.addr_bcd[0];
  990.     if (phb_entry.tel.addr_length > 0)
  991.     {
  992.         bcd_length =
  993.             ((phb_entry.tel.addr_length - 1) <
  994.              ((MAX_PB_NUMBER_LENGTH + 1) / 2)) ? (phb_entry.tel.addr_length - 1) : ((MAX_PB_NUMBER_LENGTH + 1) / 2);
  995.     }
  996.     if (bcd_length > 0)
  997.     {
  998.         /* strncpy((S8*)PhoneBook[store_index].tel.number, (S8*)(LocalPtr->phb_entry.tel.addr_bcd+1), (MAX_PB_NUMBER_LENGTH + 1) / 2); */
  999.         memset(PhoneBook[store_index].tel.number, 0xff, ((MAX_PB_NUMBER_LENGTH + 1) / 2));
  1000.         memcpy(PhoneBook[store_index].tel.number, (phb_entry.tel.addr_bcd + 1), bcd_length);
  1001.     }
  1002.     else
  1003.     {
  1004.         PhoneBook[store_index].tel.number[0] = 0xff;
  1005.     }
  1006.     mmi_phb_convert_to_digit(num_ascii, PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  1007.     PhoneBook[store_index].tel.length = strlen((S8*) num_ascii);
  1008.     /* Update flag for number exists entry, Clear it first. */
  1009.     PhoneBook[store_index].field = 0;
  1010.     if ((PhoneBook[store_index].tel.number[0] & 0x0f) != 0x0f)
  1011.     {
  1012.         PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_NUMBER;
  1013.     }
  1014. #ifdef __MMI_PHB_USIM_FIELD__
  1015.     if (store_index >= MAX_PB_PHONE_ENTRIES) /* No matter sim or usim */
  1016.     {
  1017.         phb_anr[store_index - MAX_PB_PHONE_ENTRIES][0].number[0] = 0xff;
  1018.         phb_anr[store_index - MAX_PB_PHONE_ENTRIES][1].number[0] = 0xff;
  1019.         phb_anr[store_index - MAX_PB_PHONE_ENTRIES][2].number[0] = 0xff;
  1020.         memset(phb_email[store_index - MAX_PB_PHONE_ENTRIES].email_address, 0, 2);
  1021.     }
  1022. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  1023.     g_phb_name_index[PhoneBookEntryCount] = store_index;
  1024.     PhoneBookEntryCount++;
  1025. }
  1026. /*****************************************************************************
  1027.  * FUNCTION
  1028.  *  mmi_phb_ind_startup_read
  1029.  * DESCRIPTION
  1030.  *  This function receives the read indication from L4 Phb at bootup time.
  1031.  *  Stores each indication to the global phonebook list.
  1032.  * PARAMETERS
  1033.  *  info        [IN]        Indication from L4 PHB
  1034.  * RETURNS
  1035.  *  void
  1036.  *****************************************************************************/
  1037. void mmi_phb_ind_startup_read(void *info)
  1038. {
  1039.     /*----------------------------------------------------------------*/
  1040.     /* Local Variables                                                */
  1041.     /*----------------------------------------------------------------*/
  1042.     MSG_PHB_STARTUP_READ_IND_STRUCT *LocalPtr;
  1043.     U16 store_index;
  1044.     /*----------------------------------------------------------------*/
  1045.     /* Code Body                                                      */
  1046.     /*----------------------------------------------------------------*/
  1047.     LocalPtr = (MSG_PHB_STARTUP_READ_IND_STRUCT*) info;
  1048.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "record_index: [%d]  storage: [%d] n",
  1049.                          LocalPtr->phb_entries[0].phb_entry[0].record_index,
  1050.                          LocalPtr->phb_entries[0].phb_entry[0].storage));
  1051.     /* Send read confirm messaeg back to L4 */
  1052.     mmi_phb_ind_startup_read_next_req(LocalPtr->access_id);
  1053.     /* Parse and save data from indication */
  1054.     if (LocalPtr->phb_entries[0].phb_entry[0].storage == MMI_SIM)
  1055.     {
  1056.         g_phb_cntx.sim_used++;
  1057.         store_index = LocalPtr->phb_entries[0].phb_entry[0].record_index + MAX_PB_PHONE_ENTRIES - 1;    /* Storage Location in array. */
  1058.         MMI_ASSERT((g_phb_cntx.sim_used <= MAX_PB_SIM_ENTRIES) && (store_index < MAX_PB_ENTRIES));
  1059.         mmi_phb_startup_read_entry(LocalPtr->phb_entries[0].phb_entry[0], store_index);
  1060.     }
  1061.     else /* NVRAM has multiple-read */
  1062.     {
  1063.         int i;
  1064.         for (i = 0; i < LocalPtr->phb_entries[0].num_of_entry; i++)
  1065.         {
  1066.             g_phb_cntx.phone_used++;
  1067.             store_index = LocalPtr->phb_entries[0].phb_entry[i].record_index - 1;       /* Storage Location in array. */
  1068.             MMI_ASSERT((g_phb_cntx.phone_used <= MAX_PB_PHONE_ENTRIES) && (store_index < MAX_PB_PHONE_ENTRIES));
  1069.             mmi_phb_startup_read_entry(LocalPtr->phb_entries[0].phb_entry[i], store_index);
  1070.         }
  1071.     }
  1072. }
  1073. /*****************************************************************************
  1074.  * FUNCTION
  1075.  *  mmi_phb_ind_startup_read_next_req
  1076.  * DESCRIPTION
  1077.  *  This function receives the read indication from L4 Phb at bootup time.
  1078.  *  and send confirm to L4 to read next entry.
  1079.  * PARAMETERS
  1080.  *  access_id       [IN]        
  1081.  *  info(?)         [IN]        Indication from L4 PHB
  1082.  * RETURNS
  1083.  *  void
  1084.  *****************************************************************************/
  1085. void mmi_phb_ind_startup_read_next_req(U8 access_id)
  1086. {
  1087.     /*----------------------------------------------------------------*/
  1088.     /* Local Variables                                                */
  1089.     /*----------------------------------------------------------------*/
  1090.     MSG_PHB_STARTUP_READ_NEXT_REQ_STRUCT *myMsgPtr;
  1091.     MYQUEUE Message;
  1092.     /*----------------------------------------------------------------*/
  1093.     /* Code Body                                                      */
  1094.     /*----------------------------------------------------------------*/
  1095.     myMsgPtr =
  1096.         (MSG_PHB_STARTUP_READ_NEXT_REQ_STRUCT*) OslConstructDataPtr(sizeof(MSG_PHB_STARTUP_READ_NEXT_REQ_STRUCT));
  1097.     myMsgPtr->access_id = access_id;
  1098.     Message.oslSrcId = MOD_MMI;
  1099.     Message.oslDestId = MOD_L4C;
  1100.     Message.oslMsgId = PRT_PHB_STARTUP_READ_NEXT_REQ;
  1101.     Message.oslDataPtr = (oslParaType*) myMsgPtr;
  1102.     Message.oslPeerBuffPtr = NULL;
  1103.     OslMsgSendExtQueue(&Message);
  1104. }
  1105. #endif /* defined(MMI_ON_HARDWARE_P) */ 
  1106. /*****************************************************************************
  1107.  * FUNCTION
  1108.  *  mmi_phb_ind_startup_finish
  1109.  * DESCRIPTION
  1110.  *  Reads the Phonebook ready indication from PS and prepare to sort.
  1111.  * PARAMETERS
  1112.  *  info        [IN]        Finish indication
  1113.  * RETURNS
  1114.  *  void
  1115.  *****************************************************************************/
  1116. void mmi_phb_ind_startup_finish(void *info)
  1117. {
  1118.     /*----------------------------------------------------------------*/
  1119.     /* Local Variables                                                */
  1120.     /*----------------------------------------------------------------*/
  1121.     MSG_PHB_STARTUP_FINISH_IND_STRUCT *localPtr;
  1122.     /*----------------------------------------------------------------*/
  1123.     /* Code Body                                                      */
  1124.     /*----------------------------------------------------------------*/
  1125.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_ind_startup_finish.>n", __FILE__,
  1126.                          __LINE__));
  1127.     localPtr = (MSG_PHB_STARTUP_FINISH_IND_STRUCT*) info;
  1128. #ifdef __MMI_PHB_USIM_FIELD__
  1129.     g_phb_cntx.usim_ready_stage = MMI_PHB_USIM_READY;
  1130.     if (!g_phb_cntx.is_usim)
  1131. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  1132.     {
  1133.         g_phb_cntx.sim_name_len = localPtr->phb_len;
  1134.         g_phb_cntx.fdn_name_len = localPtr->fdn_len;
  1135.         g_phb_cntx.bdn_name_len = localPtr->bdn_len;
  1136.         g_phb_cntx.owner_name_len = localPtr->owner_len;
  1137.         g_phb_cntx.sim_total = localPtr->sim_max_num;
  1138.         g_phb_cntx.phone_total = localPtr->phb_max_num;
  1139.         if (g_phb_cntx.sim_total > MAX_PB_SIM_ENTRIES)
  1140.         {
  1141.             g_phb_cntx.sim_total = MAX_PB_SIM_ENTRIES;
  1142.         }
  1143.         if (g_phb_cntx.phone_total > MAX_PB_PHONE_ENTRIES)
  1144.         {
  1145.             g_phb_cntx.phone_total = MAX_PB_PHONE_ENTRIES;  /* This two values should be the same */
  1146.         }
  1147.         if (!g_phb_cntx.nvram_data_init)
  1148.         {
  1149.             mmi_phb_init_get_data_from_nvram();
  1150.             g_phb_cntx.nvram_data_init = TRUE;
  1151.         }
  1152.     #if defined(MMI_ON_HARDWARE_P)
  1153.         /* Sort name list */
  1154.         mmi_phb_sort_build_name_index();
  1155.         /*
  1156.          *   Use SIM storage buffer to store FDN list when FDN is enable.
  1157.          *   Because when FDN is enable, the ADN entry cannot be retrieved from SIM card.
  1158.          *   This list is for incoming call lookup name usage.
  1159.          *
  1160.          *   Note: Be sure to retrieve speed dial number after retrieve FDN list.
  1161.          */
  1162.         if (gSecuritySetupContext.FdlStatus)
  1163.         {
  1164.             mmi_phb_fdn_get_list_to_ram();
  1165.         }
  1166.         /*
  1167.          * Get Speed Dial Info. If FDN on, get speed dial info after FDN list retrieved.
  1168.          * Because they all use same message.
  1169.          */
  1170.         else
  1171.         {
  1172.             if (gInsertSimAppFlag == 1)
  1173.             {
  1174.                 g_phb_cntx.phb_ready = TRUE;
  1175.                 mmi_phb_init_build_lookup_table();
  1176.             }
  1177.             else
  1178.             {
  1179.                 PhbGetSpeedDialInfo();
  1180.             }
  1181.         }
  1182.     #else /* defined(MMI_ON_HARDWARE_P) */ 
  1183.         mmi_phb_init_refresh_phonebook();
  1184.     #endif /* defined(MMI_ON_HARDWARE_P) */ 
  1185.     }
  1186. }
  1187. /*****************************************************************************
  1188.  * FUNCTION
  1189.  *  mmi_phb_init_get_data_from_nvram
  1190.  * DESCRIPTION
  1191.  *  Retrieves the phonebook data like, Caller Group details, view fields,
  1192.  *  preferred storage, etc from NVRAM
  1193.  * PARAMETERS
  1194.  *  void
  1195.  * RETURNS
  1196.  *  void
  1197.  *****************************************************************************/
  1198. void mmi_phb_init_get_data_from_nvram(void)
  1199. {
  1200.     /*----------------------------------------------------------------*/
  1201.     /* Local Variables                                                */
  1202.     /*----------------------------------------------------------------*/
  1203.     U8 i;
  1204.     S16 pError;
  1205.     U16 tempStorageLocation;    /* Temp Solution For Read/Write 2 bytes NVRAM_PHB_STORAGE_LOCATION */
  1206.     U16 tempNameListFilter;
  1207.     PHB_CALLER_GROUP_STRUCT *callerGroups;
  1208.     U8 viewField[NVRAM_PHB_SETTINGS_SIZE];
  1209.     /*----------------------------------------------------------------*/
  1210.     /* Code Body                                                      */
  1211.     /*----------------------------------------------------------------*/
  1212.     callerGroups = (PHB_CALLER_GROUP_STRUCT*) g_phb_cntx.caller_group;
  1213.     ReadRecord(NVRAM_EF_PHB_SETTINGS_LID, 1, viewField, NVRAM_PHB_SETTINGS_SIZE, &pError);
  1214.     memcpy(g_phb_cntx.view_field, viewField, MAX_PB_VIEW_FIELDS);
  1215.     ReadValue(NVRAM_PHB_STORAGE_LOCATION, &tempStorageLocation, DS_SHORT, &pError);     /* 2 bytes for DS_SHORT */
  1216.     g_phb_cntx.prefer_storage = (U8) tempStorageLocation;
  1217.     
  1218.     ReadValue(NVRAM_PHB_NAME_LIST_FILTER, &tempNameListFilter, DS_SHORT, &pError);     /* 2 bytes for DS_SHORT */
  1219.     g_phb_cntx.name_list_filter = (U8) tempNameListFilter;
  1220.     
  1221.     ReadRecord(NVRAM_EF_PHB_CALLER_GROUPS_LID, 1, callerGroups, CALLER_GROUPS_RECORD_SIZE, &pError);
  1222.     if (g_phb_cntx.prefer_storage != MMI_SIM && g_phb_cntx.prefer_storage != MMI_NVRAM)
  1223.     {
  1224.         g_phb_cntx.prefer_storage = MMI_SIM;
  1225.         tempStorageLocation = g_phb_cntx.prefer_storage;
  1226.         WriteValue(NVRAM_PHB_STORAGE_LOCATION, &tempStorageLocation, DS_SHORT, &pError);        /* 2 bytes for DS_SHORT */
  1227.     }
  1228.     if ((g_phb_cntx.name_list_filter != MMI_SIM) && (g_phb_cntx.name_list_filter != MMI_NVRAM) && (g_phb_cntx.name_list_filter != MMI_STORAGE_BOTH))
  1229.     {
  1230.         g_phb_cntx.name_list_filter = MMI_STORAGE_BOTH;
  1231.         tempNameListFilter = g_phb_cntx.name_list_filter;
  1232.         WriteValue(NVRAM_PHB_NAME_LIST_FILTER, &tempNameListFilter, DS_SHORT, &pError);        /* 2 bytes for DS_SHORT */
  1233.     }
  1234.     /* No alert or LED seting in caller group. */
  1235.     for (i = 0; i < MAX_PB_CALLER_GROUPS; ++i)
  1236.     {
  1237.     #if defined(__MMI_CALLERGROUP_NO_ALERT__)
  1238.         callerGroups[i].alertType = MMI_ALERT_NONE;
  1239.     #endif 
  1240.     #if !defined(__MMI_STATUS_LED__)
  1241.         callerGroups[i].LEDPatternId = 0;
  1242.     #endif 
  1243.     }
  1244.     /* Should never go into this section in normal situation */
  1245. #if !defined(MMI_ON_HARDWARE_P)
  1246.     if (callerGroups[0].ringToneID == 0xFFFF)
  1247.     {
  1248.         mmi_phb_callergroup_restore_default();
  1249.     }
  1250. #endif /* !defined(MMI_ON_HARDWARE_P) */ 
  1251. }
  1252. /*****************************************************************************
  1253.  * FUNCTION
  1254.  *  mmi_phb_init_build_lookup_table
  1255.  * DESCRIPTION
  1256.  *  This function builds the lookup table for cross-referencing during MO/MT calls.
  1257.  *  This table contains the home/mobile/fax/office number(s) of a phonebook entry.
  1258.  * PARAMETERS
  1259.  *  void
  1260.  * RETURNS
  1261.  *  void
  1262.  *****************************************************************************/
  1263. void mmi_phb_init_build_lookup_table(void)
  1264. {
  1265.     /*----------------------------------------------------------------*/
  1266.     /* Local Variables                                                */
  1267.     /*----------------------------------------------------------------*/
  1268.     U16 count, store_index;
  1269.     U8 num_ascii[MAX_PB_NUMBER_LENGTH + 1 + 1];
  1270.     /*----------------------------------------------------------------*/
  1271.     /* Code Body                                                      */
  1272.     /*----------------------------------------------------------------*/
  1273.     count = 0;
  1274.     /* Read compare length from NVRAM */
  1275.     mmi_phb_util_read_compare_length();
  1276.     while (count < PhoneBookEntryCount)
  1277.     {
  1278.         store_index = g_phb_name_index[count];
  1279.         /* Populate Mobile Number Field. Either in SIM or in NVRAM */
  1280.         mmi_phb_convert_to_digit(num_ascii, PhoneBook[store_index].tel.number, MAX_PB_NUMBER_LENGTH + 1);
  1281.         mmi_phb_op_increase_lookup_table(store_index, (S8*) num_ascii, NULL, NULL, NULL);
  1282.         count++;
  1283.     }
  1284. #if defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  1285.     mmi_phb_lookup_table_sort();
  1286. #else /* defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  1287.     /* Start a timer to avoid extensive NVRAM access which may cause MMI hang shortly */
  1288.     /* mmi_phb_init_populate_lookup_table(); */
  1289.     StartTimer(PHB_READ_OPT_FILED_TIMER, 500, mmi_phb_init_populate_lookup_table);
  1290. #endif /* defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  1291. }
  1292. #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
  1293. /*****************************************************************************
  1294.  * FUNCTION
  1295.  *  mmi_phb_get_the_nearest_index
  1296.  * DESCRIPTION
  1297.  *  
  1298.  * PARAMETERS
  1299.  *  index       [IN]        
  1300.  * RETURNS
  1301.  *  
  1302.  *****************************************************************************/
  1303. static U16 mmi_phb_get_the_nearest_index(U16 index)
  1304. {
  1305.     /*----------------------------------------------------------------*/
  1306.     /* Local Variables                                                */
  1307.     /*----------------------------------------------------------------*/
  1308.     U16 nearest_index = MAX_PB_PHONE_ENTRIES;
  1309.     U16 count = 0;
  1310.     /*----------------------------------------------------------------*/
  1311.     /* Code Body                                                      */
  1312.     /*----------------------------------------------------------------*/
  1313.     while (count < PhoneBookEntryCount)
  1314.     {
  1315.         if ((g_phb_name_index[count] < nearest_index) && (g_phb_name_index[count] >= index))
  1316.         {
  1317.             nearest_index = g_phb_name_index[count];
  1318.         }
  1319.         count++;
  1320.     }
  1321.     return nearest_index;
  1322. }
  1323. /*****************************************************************************
  1324.  * FUNCTION
  1325.  *  mmi_phb_field_need_populate
  1326.  * DESCRIPTION
  1327.  *  
  1328.  * PARAMETERS
  1329.  *  index       [IN]        
  1330.  * RETURNS
  1331.  *  
  1332.  *****************************************************************************/
  1333. static BOOL mmi_phb_field_need_populate(U16 index)
  1334. {
  1335.     /*----------------------------------------------------------------*/
  1336.     /* Local Variables                                                */
  1337.     /*----------------------------------------------------------------*/
  1338.     /* U16 nearest_index = MAX_PB_PHONE_ENTRIES; */
  1339.     U16 count = 0;
  1340.     /*----------------------------------------------------------------*/
  1341.     /* Code Body                                                      */
  1342.     /*----------------------------------------------------------------*/
  1343.     while (count < PhoneBookEntryCount)
  1344.     {
  1345.         if (g_phb_name_index[count] == index)
  1346.         {
  1347.             return TRUE;
  1348.         }
  1349.         count++;
  1350.     }
  1351.     return FALSE;
  1352. }
  1353. /*****************************************************************************
  1354.  * FUNCTION
  1355.  *  mmi_phb_init_populate_lookup_table
  1356.  * DESCRIPTION
  1357.  *  This function populates the lookup table with home/fax/mobile/office numbers after
  1358.  *  converting the last 7(or 9) characters of the phone number into digits.
  1359.  * PARAMETERS
  1360.  *  void
  1361.  * RETURNS
  1362.  *  void
  1363.  *****************************************************************************/
  1364. void mmi_phb_init_populate_lookup_table(void)
  1365. {
  1366.     /*----------------------------------------------------------------*/
  1367.     /* Local Variables                                                */
  1368.     /*----------------------------------------------------------------*/
  1369.     U16 count = 0;
  1370.     S16 pError;
  1371.     U16 max_rec_amount = 2000 / OPTIONAL_FIELDS_RECORD_SIZE;    /* 8 */
  1372.     void *p_data = OslMalloc((U16) (OPTIONAL_FIELDS_RECORD_SIZE * max_rec_amount));
  1373.     U16 processed_index = g_phb_cntx.populate_count;
  1374.     U16 read_rec_amount = 0;
  1375.     /*----------------------------------------------------------------*/
  1376.     /* Code Body                                                      */
  1377.     /*----------------------------------------------------------------*/
  1378.     MMI_TRACE((MMI_TRACE_G4_PHB, MMI_PHB_FUNC_PopulateLookUpTable_BEGIN, g_phb_cntx.populate_count));
  1379.     if (!p_data)
  1380.     {
  1381.         max_rec_amount = max_rec_amount / 2;
  1382.         p_data = OslMalloc((U16) (OPTIONAL_FIELDS_RECORD_SIZE * max_rec_amount));
  1383.     }
  1384.     /* Populate Optional Number Field. Only Populate record in NVRAM */
  1385.     while ((processed_index = mmi_phb_get_the_nearest_index(processed_index)) < MAX_PB_PHONE_ENTRIES)
  1386.     {
  1387.         U8 multi_record_index;
  1388.     #ifdef MMI_ON_HARDWARE_P
  1389.         if ((MAX_PB_PHONE_ENTRIES - processed_index) < max_rec_amount)
  1390.         {
  1391.             read_rec_amount = (MAX_PB_PHONE_ENTRIES - processed_index);
  1392.         }
  1393.         else
  1394.         {
  1395.             read_rec_amount = max_rec_amount;
  1396.         }
  1397.         ReadMultiRecord(
  1398.             NVRAM_EF_PHB_FIELDS_LID,
  1399.             (U16) (processed_index + 1),
  1400.             p_data,
  1401.             (U16) (OPTIONAL_FIELDS_RECORD_SIZE * read_rec_amount),
  1402.             read_rec_amount,
  1403.             &pError);
  1404.     #else /* MMI_ON_HARDWARE_P */ 
  1405.         read_rec_amount = 1;
  1406.         ReadRecord(
  1407.             NVRAM_EF_PHB_FIELDS_LID,
  1408.             (U16) (processed_index + 1),
  1409.             p_data,
  1410.             (U16) (OPTIONAL_FIELDS_RECORD_SIZE * max_rec_amount),
  1411.             &pError);
  1412.     #endif /* MMI_ON_HARDWARE_P */ 
  1413.         count++;
  1414.         for (multi_record_index = 0; multi_record_index < read_rec_amount; multi_record_index++)
  1415.         {
  1416.             if (multi_record_index == 0 || mmi_phb_field_need_populate(processed_index))
  1417.             {
  1418.                 memcpy(
  1419.                     &PhoneBookOptionalFields,
  1420.                     ((U8*) p_data) + (multi_record_index * OPTIONAL_FIELDS_RECORD_SIZE),
  1421.                     OPTIONAL_FIELDS_RECORD_SIZE);
  1422.                 mmi_phb_op_increase_lookup_table(
  1423.                     processed_index,
  1424.                     NULL,
  1425.                     (S8*) PhoneBookOptionalFields.faxNumber,
  1426.                     (S8*) PhoneBookOptionalFields.homeNumber,
  1427.                     (S8*) PhoneBookOptionalFields.officeNumber);
  1428.                 /* Update if phonebook column exists flag. */
  1429.                 mmi_phb_op_update_field_flag(
  1430.                     processed_index,
  1431.                     NULL,
  1432.                     (S8*) PhoneBookOptionalFields.homeNumber,
  1433.                     (S8*) PhoneBookOptionalFields.officeNumber,
  1434.                     (S8*) PhoneBookOptionalFields.faxNumber,
  1435.                     (S8*) PhoneBookOptionalFields.emailAddress,
  1436.                     FALSE);
  1437.             }
  1438.             processed_index++;
  1439.         }
  1440.         if ((count % 10) == 0)  /* Populate at least 10 entries each time */
  1441.         {
  1442.             break;
  1443.         }
  1444.     }
  1445.     OslMfree(p_data);
  1446.     g_phb_cntx.populate_count = processed_index;
  1447.     MMI_TRACE((MMI_TRACE_G4_PHB, MMI_PHB_FUNC_PopulateLookUpTable_END, g_phb_cntx.populate_count));
  1448.     if (processed_index < MAX_PB_PHONE_ENTRIES) /* More entries to populate */
  1449.     {
  1450.         StopTimer(PHB_READ_OPT_FILED_TIMER);
  1451.         StartTimer(PHB_READ_OPT_FILED_TIMER, 250, mmi_phb_init_populate_lookup_table);
  1452.     }
  1453.     else    /* All entries populated, begin to sort it. */
  1454.     {
  1455.         mmi_phb_lookup_table_sort();
  1456.     }
  1457. }
  1458. #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
  1459. #ifdef __MMI_PHB_USIM_FIELD__
  1460. /*****************************************************************************
  1461.  * FUNCTION
  1462.  *  mmi_phb_ind_startup_phase1_finish
  1463.  * DESCRIPTION
  1464.  *  Reads the Phonebook ready indication from PS and prepare to sort.
  1465.  * PARAMETERS
  1466.  *  info        [IN]        Finish indication
  1467.  * RETURNS
  1468.  *  void
  1469.  *****************************************************************************/
  1470. static void mmi_phb_ind_startup_phase1_finish(void *info)
  1471. {
  1472.     /*----------------------------------------------------------------*/
  1473.     /* Local Variables                                                */
  1474.     /*----------------------------------------------------------------*/
  1475.     MSG_PHB_STARTUP_FINISH_PHASE1_IND_STRUCT *localPtr;
  1476.     /*----------------------------------------------------------------*/
  1477.     /* Code Body                                                      */
  1478.     /*----------------------------------------------------------------*/
  1479.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_ind_startup_phase1_finish.>n", __FILE__,
  1480.                          __LINE__));
  1481.     localPtr = (MSG_PHB_STARTUP_FINISH_PHASE1_IND_STRUCT*) info;
  1482.     g_phb_cntx.is_usim = TRUE;   /* since only usim have this indicator */
  1483.     g_phb_cntx.sim_name_len = localPtr->phb_len;
  1484.     g_phb_cntx.fdn_name_len = localPtr->fdn_len;
  1485.     g_phb_cntx.bdn_name_len = localPtr->bdn_len;
  1486.     g_phb_cntx.owner_name_len = localPtr->owner_len;
  1487.     g_phb_cntx.sim_total = localPtr->sim_max_num;
  1488.     g_phb_cntx.phone_total = localPtr->phb_max_num;
  1489.     if (g_phb_cntx.sim_total > MAX_PB_SIM_ENTRIES)
  1490.     {
  1491.         g_phb_cntx.sim_total = MAX_PB_SIM_ENTRIES;
  1492.     }
  1493.     if (g_phb_cntx.phone_total > MAX_PB_PHONE_ENTRIES)
  1494.     {
  1495.         g_phb_cntx.phone_total = MAX_PB_PHONE_ENTRIES;  /* This two values should be the same */
  1496.     }
  1497.     if (localPtr->is_group_support)
  1498.     {
  1499.         g_phb_cntx.support_field[MMI_PHB_USIM_FIELD_GROUP] = 1;
  1500.         if (localPtr->group_max_num > MAX_PB_USIM_GROUPS)
  1501.         {
  1502.             g_phb_cntx.gas_total = MAX_PB_USIM_GROUPS;
  1503.         }
  1504.         else
  1505.         {
  1506.             g_phb_cntx.gas_total = localPtr->group_max_num;
  1507.         }
  1508.         if (localPtr->group_len > MAX_GRP_NAME_LENGTH)
  1509.         {
  1510.             g_phb_cntx.group_name_len = MAX_GRP_NAME_LENGTH;
  1511.         }
  1512.         else
  1513.         {
  1514.             g_phb_cntx.group_name_len = localPtr->group_len;
  1515.         }
  1516.     }
  1517.     if (localPtr->anra_support_type > 0)
  1518.     {
  1519.         g_phb_cntx.support_field[MMI_PHB_USIM_FIELD_ANRA] = 1;
  1520.     }
  1521.     if (localPtr->anrb_support_type > 0)
  1522.     {
  1523.     }
  1524.     if (localPtr->anrc_support_type > 0)
  1525.     {
  1526.     }
  1527.     if (localPtr->email_support_type > 0)
  1528.     {
  1529.         g_phb_cntx.support_field[MMI_PHB_USIM_FIELD_EMAIL] = 1;
  1530.         g_phb_cntx.email_total = localPtr->email_max_num;
  1531.         g_phb_cntx.email_length = localPtr->email_len;
  1532.     }
  1533.     if (!g_phb_cntx.nvram_data_init)
  1534.     {
  1535.         mmi_phb_init_get_data_from_nvram();
  1536.         g_phb_cntx.nvram_data_init = TRUE;
  1537.     }
  1538. #if defined(MMI_ON_HARDWARE_P)
  1539.     /* Sort name list */
  1540.     mmi_phb_sort_build_name_index();
  1541.     /*
  1542.      *   Use SIM storage buffer to store FDN list when FDN is enable.
  1543.      *   Because when FDN is enable, the ADN entry cannot be retrieved from SIM card.
  1544.      *   This list is for incoming call lookup name usage.
  1545.      *
  1546.      *   Note: Be sure to retrieve speed dial number after retrieve FDN list.
  1547.      */
  1548.     if (gSecuritySetupContext.FdlStatus)
  1549.     {
  1550.         mmi_phb_fdn_get_list_to_ram();
  1551.     }
  1552.     /*
  1553.      * Get Speed Dial Info. If FDN on, get speed dial info after FDN list retrieved.
  1554.      * Because they all use same message.
  1555.      */
  1556.     else
  1557.     {
  1558.         if (gInsertSimAppFlag == 1 || mmi_bootup_get_active_flight_mode() == 1)
  1559.         {
  1560.             g_phb_cntx.phb_ready = TRUE;
  1561.             mmi_phb_init_build_lookup_table();
  1562.         }
  1563.         else
  1564.         {
  1565.             PhbGetSpeedDialInfo();
  1566.         }
  1567.         /* After sorting done, init vrsi engine to add phonebook data. */
  1568.     #if defined(__MMI_VRSI__)
  1569.         mmi_vrsi_init_central_reset();
  1570.         /* mmi_vrsi_init_central_add_all(); */
  1571.     #endif /* defined(__MMI_VRSI__) */ 
  1572.     }
  1573. #else /* defined(MMI_ON_HARDWARE_P) */ 
  1574.     mmi_phb_init_refresh_phonebook();
  1575. #endif /* defined(MMI_ON_HARDWARE_P) */ 
  1576. }
  1577. /*****************************************************************************
  1578.  * FUNCTION
  1579.  *  mmi_phb_read_usim_anr_field
  1580.  * DESCRIPTION
  1581.  *  This function reads the anr field in usim card.
  1582.  * PARAMETERS
  1583.  *  info        [?]     
  1584.  * RETURNS
  1585.  *  void
  1586.  *****************************************************************************/
  1587. static void mmi_phb_read_usim_anr_field(void *info)
  1588. {
  1589.     /*----------------------------------------------------------------*/
  1590.     /* Local Variables                                                */
  1591.     /*----------------------------------------------------------------*/
  1592.     /*----------------------------------------------------------------*/
  1593.     /* Code Body                                                      */
  1594.     /*----------------------------------------------------------------*/
  1595.     if (!g_phb_cntx.is_usim)
  1596.     {
  1597.         ASSERT(0);
  1598.         return;
  1599.     }
  1600.     if (g_phb_cntx.usim_ready_stage < MMI_PHB_USIM_READY_ANR)
  1601.     {
  1602.         g_phb_cntx.usim_ready_stage = MMI_PHB_USIM_READY_ANR;
  1603.     }
  1604.     SetProtocolEventHandler(mmi_phb_startup_anr_read_rsp, PRT_PHB_STARTUP_READ_ANR_IND);
  1605.     mmi_phb_startup_anr_read_rsp(info);
  1606. }
  1607. /*****************************************************************************
  1608.  * FUNCTION
  1609.  *  mmi_phb_read_usim_email_field
  1610.  * DESCRIPTION
  1611.  *  This function reads the email field in usim card.
  1612.  * PARAMETERS
  1613.  *  info        [?]     
  1614.  * RETURNS
  1615.  *  void
  1616.  *****************************************************************************/
  1617. static void mmi_phb_read_usim_email_field(void *info)
  1618. {
  1619.     /*----------------------------------------------------------------*/
  1620.     /* Local Variables                                                */
  1621.     /*----------------------------------------------------------------*/
  1622.     /*----------------------------------------------------------------*/
  1623.     /* Code Body                                                      */
  1624.     /*----------------------------------------------------------------*/
  1625.     if (!g_phb_cntx.is_usim)
  1626.     {
  1627.         ASSERT(0);
  1628.         return;
  1629.     }
  1630.     if (g_phb_cntx.usim_ready_stage < MMI_PHB_USIM_READY_EMAIL)
  1631.     {
  1632.         g_phb_cntx.usim_ready_stage = MMI_PHB_USIM_READY_EMAIL;
  1633.     }
  1634.     SetProtocolEventHandler(mmi_phb_startup_email_read_rsp, PRT_PHB_STARTUP_READ_EMAIL_IND);
  1635.     mmi_phb_startup_email_read_rsp(info);
  1636. }
  1637. /*****************************************************************************
  1638.  * FUNCTION
  1639.  *  mmi_phb_read_usim_gas_field
  1640.  * DESCRIPTION
  1641.  *  This function reads the gas field in usim card.
  1642.  * PARAMETERS
  1643.  *  info        [?]     
  1644.  * RETURNS
  1645.  *  void
  1646.  *****************************************************************************/
  1647. static void mmi_phb_read_usim_gas_field(void *info)
  1648. {
  1649.     /*----------------------------------------------------------------*/
  1650.     /* Local Variables                                                */
  1651.     /*----------------------------------------------------------------*/
  1652.     /*----------------------------------------------------------------*/
  1653.     /* Code Body                                                      */
  1654.     /*----------------------------------------------------------------*/
  1655.     if (!g_phb_cntx.is_usim)
  1656.     {
  1657.         ASSERT(0);
  1658.         return;
  1659.     }
  1660.     if (g_phb_cntx.usim_ready_stage < MMI_PHB_USIM_READY_GAS)
  1661.     {
  1662.         g_phb_cntx.usim_ready_stage = MMI_PHB_USIM_READY_GAS;
  1663.     }
  1664.     SetProtocolEventHandler(mmi_phb_startup_gas_read_rsp, PRT_PHB_STARTUP_READ_GAS_IND);
  1665.     mmi_phb_startup_gas_read_rsp(info);
  1666. }
  1667. /*****************************************************************************
  1668.  * FUNCTION
  1669.  *  mmi_phb_read_usim_grp_field
  1670.  * DESCRIPTION
  1671.  *  This function reads the gas field in usim card.
  1672.  * PARAMETERS
  1673.  *  info        [?]     
  1674.  * RETURNS
  1675.  *  void
  1676.  *****************************************************************************/
  1677. static void mmi_phb_read_usim_grp_field(void *info)
  1678. {
  1679.     /*----------------------------------------------------------------*/
  1680.     /* Local Variables                                                */
  1681.     /*----------------------------------------------------------------*/
  1682.     MSG_PHB_STARTUP_READ_GRP_IND_STRUCT *localPtr;
  1683.     U8 i;
  1684.     /*----------------------------------------------------------------*/
  1685.     /* Code Body                                                      */
  1686.     /*----------------------------------------------------------------*/
  1687.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_read_usim_grp_field.>n", __FILE__,
  1688.                          __LINE__));
  1689.     if (!g_phb_cntx.is_usim)
  1690.     {
  1691.         ASSERT(0);
  1692.         return;
  1693.     }
  1694.     if (g_phb_cntx.usim_ready_stage < MMI_PHB_USIM_READY_GRP)
  1695.     {
  1696.         g_phb_cntx.usim_ready_stage = MMI_PHB_USIM_READY_GRP;
  1697.     }
  1698.     localPtr = (MSG_PHB_STARTUP_READ_GRP_IND_STRUCT*) info;
  1699.     for (i = 0; i < g_phb_cntx.sim_total; i++)
  1700.     {
  1701.         if (localPtr->grp[i] > MAX_PB_USIM_GROUPS)
  1702.         {
  1703.             g_phb_cntx.group_type[i] = 0;
  1704.         }
  1705.         else
  1706.         {
  1707.             g_phb_cntx.group_type[i] = localPtr->grp[i];
  1708.         }
  1709.     }
  1710.     //memcpy(g_phb_cntx.group_type, (localPtr->grp), MAX_PB_SIM_ENTRIES);
  1711.     //read next usim field or finish;
  1712.     mmi_phb_read_usim_field(localPtr->access_id);
  1713. }
  1714. /*****************************************************************************
  1715.  * FUNCTION
  1716.  *  mmi_phb_read_usim_field
  1717.  * DESCRIPTION
  1718.  *  Sends the L4 request to read usim email field
  1719.  * PARAMETERS
  1720.  *  access_id       [IN]        
  1721.  * RETURNS
  1722.  *  void
  1723.  *****************************************************************************/
  1724. static void mmi_phb_read_usim_field(U8 access_id)
  1725. {
  1726.     /*----------------------------------------------------------------*/
  1727.     /* Local Variables                                                */
  1728.     /*----------------------------------------------------------------*/
  1729.     MSG_PHB_STARTUP_READ_NEXT_USIM_FIELD_REQ_STRUCT *myMsgPtr;
  1730.     MYQUEUE Message;
  1731.     /*----------------------------------------------------------------*/
  1732.     /* Code Body                                                      */
  1733.     /*----------------------------------------------------------------*/
  1734.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_read_email_req.>n", __FILE__, __LINE__));
  1735.     myMsgPtr = (MSG_PHB_STARTUP_READ_NEXT_USIM_FIELD_REQ_STRUCT*)
  1736.         OslConstructDataPtr(sizeof(MSG_PHB_STARTUP_READ_NEXT_USIM_FIELD_REQ_STRUCT));
  1737.     myMsgPtr->access_id = access_id;
  1738.     Message.oslSrcId = MOD_MMI;
  1739.     Message.oslDestId = MOD_L4C;
  1740.     Message.oslMsgId = PRT_PHB_STARTUP_READ_NEXT_USIM_FIELD_REQ;
  1741.     Message.oslDataPtr = (oslParaType*) myMsgPtr;
  1742.     Message.oslPeerBuffPtr = NULL;
  1743.     OslMsgSendExtQueue(&Message);
  1744. }
  1745. /*****************************************************************************
  1746.  * FUNCTION
  1747.  *  mmi_phb_startup_gas_read_rsp
  1748.  * DESCRIPTION
  1749.  *  Handle the L4 response for reading the usim gas field
  1750.  * PARAMETERS
  1751.  *  info        [?]     
  1752.  * RETURNS
  1753.  *  void
  1754.  *****************************************************************************/
  1755. static void mmi_phb_startup_gas_read_rsp(void *info)
  1756. {
  1757.     /*----------------------------------------------------------------*/
  1758.     /* Local Variables                                                */
  1759.     /*----------------------------------------------------------------*/
  1760.     MSG_PHB_STARTUP_READ_GAS_IND_STRUCT *localPtr;
  1761.     U8 i;
  1762.     MMI_PHB_NAME_STRUCT *usim_group = (MMI_PHB_NAME_STRUCT*) g_phb_cntx.usim_group;
  1763.     /*----------------------------------------------------------------*/
  1764.     /* Code Body                                                      */
  1765.     /*----------------------------------------------------------------*/
  1766.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_startup_read_gas_rsp.>n", __FILE__,
  1767.                          __LINE__));
  1768.     localPtr = (MSG_PHB_STARTUP_READ_GAS_IND_STRUCT*) info;
  1769.     for (i = 0; i < localPtr->num_of_entry; ++i)
  1770.     {
  1771.         if (g_phb_read_index <= MAX_PB_USIM_GROUPS)
  1772.         {
  1773.             g_phb_read_index = localPtr->gas_entry[i].record_index;
  1774.             usim_group[g_phb_read_index - 1].name_length = localPtr->gas_entry[i].alpha_id.name_length;
  1775.             usim_group[g_phb_read_index - 1].name_dcs = localPtr->gas_entry[i].alpha_id.name_dcs;
  1776.             InputboxConvertGSMToDeviceEncoding(
  1777.                 localPtr->gas_entry[i].alpha_id.name,
  1778.                 usim_group[g_phb_read_index - 1].name,
  1779.                 localPtr->gas_entry[i].alpha_id.name_length,
  1780.                 (MAX_GRP_NAME_LENGTH + 1) * ENCODING_LENGTH,
  1781.                 localPtr->gas_entry[i].alpha_id.name_dcs,
  1782.                 0,
  1783.                 1);
  1784.         }
  1785.     }
  1786.     /* read next usim field or finish */
  1787.     mmi_phb_read_usim_field(localPtr->access_id);
  1788. }
  1789. /*****************************************************************************
  1790.  * FUNCTION
  1791.  *  mmi_phb_startup_email_read_rsp
  1792.  * DESCRIPTION
  1793.  *  Handle the L4 response for reading the usim email field
  1794.  * PARAMETERS
  1795.  *  info        [?]     
  1796.  * RETURNS
  1797.  *  void
  1798.  *****************************************************************************/
  1799. static void mmi_phb_startup_email_read_rsp(void *info)
  1800. {
  1801.     /*----------------------------------------------------------------*/
  1802.     /* Local Variables                                                */
  1803.     /*----------------------------------------------------------------*/
  1804.     MSG_PHB_STARTUP_READ_EMAIL_IND_STRUCT *localPtr;
  1805.     U16 i;
  1806.     U16 store_index;
  1807.     U16 index;
  1808.     /*----------------------------------------------------------------*/
  1809.     /* Code Body                                                      */
  1810.     /*----------------------------------------------------------------*/
  1811.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_startup_email_read_rsp.>n", __FILE__,
  1812.                          __LINE__));
  1813.     localPtr = (MSG_PHB_STARTUP_READ_EMAIL_IND_STRUCT*) info;
  1814.     for (i = 0; i < localPtr->num_of_entry; ++i)
  1815.     {
  1816.         //if (g_phb_cntx.email_used < g_phb_cntx.email_total)
  1817.         //{
  1818.         store_index = localPtr->email_entry[i].adn_record_index + MAX_PB_PHONE_ENTRIES - 1;
  1819.         index = localPtr->email_entry[i].adn_record_index - 1;
  1820.         /* PhoneBook[store_index].usim_field |= MMI_PHB_ENTRY_FIELD_EMAIL; */
  1821.         PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_EMAIL;
  1822.         g_phb_cntx.email_used++;
  1823.         /* Email Field */
  1824.         phb_email[index].email_length = localPtr->email_entry[i].email_length;
  1825.         if (phb_email[index].email_length == 0)
  1826.         {
  1827.             memset(phb_email[index].email_address, 0, 2);
  1828.         }
  1829.         else
  1830.         {
  1831.             ConvertGSM7BitDefaultEncodingToAscii(
  1832.                 phb_email[index].email_address,
  1833.                 localPtr->email_entry[i].email_address,
  1834.                 localPtr->email_entry[i].email_length,
  1835.                 (U16*) & (localPtr->email_entry[i].email_length));
  1836.         }
  1837.         //}       
  1838.         //else
  1839.         //{
  1840.         //        break;
  1841.         //}
  1842.     }
  1843.     /* read next usim field or finish */
  1844.     mmi_phb_read_usim_field(localPtr->access_id);
  1845. }
  1846. /*****************************************************************************
  1847.  * FUNCTION
  1848.  *  mmi_phb_startup_anr_read_rsp
  1849.  * DESCRIPTION
  1850.  *  Handle the L4 response for reading the usim anr field
  1851.  * PARAMETERS
  1852.  *  info        [?]     
  1853.  * RETURNS
  1854.  *  void
  1855.  *****************************************************************************/
  1856. static void mmi_phb_startup_anr_read_rsp(void *info)
  1857. {
  1858.     /*----------------------------------------------------------------*/
  1859.     /* Local Variables                                                */
  1860.     /*----------------------------------------------------------------*/
  1861.     MSG_PHB_STARTUP_READ_ANR_IND_STRUCT *local_ptr;
  1862.     U16 i = 0;
  1863.     U16 store_index;
  1864.     U8 num_ascii[MAX_PB_NUMBER_LENGTH + 1 + 1];
  1865.     U8 bcd_length = 0;
  1866.     U8 type_of_anr;
  1867.     /*----------------------------------------------------------------*/
  1868.     /* Code Body                                                      */
  1869.     /*----------------------------------------------------------------*/
  1870.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_startup_email_read_rsp.>n", __FILE__,
  1871.                          __LINE__));
  1872.     local_ptr = (MSG_PHB_STARTUP_READ_ANR_IND_STRUCT*) info;
  1873.     type_of_anr = local_ptr->anr_entry[i].anr_type;
  1874.     for (i = 0; i < local_ptr->num_of_entry; ++i)
  1875.     {
  1876.         /* if (g_phb_cntx.anra_used < g_phb_cntx.anra_total && type_of_anr == 0) // ANRA */
  1877.         if (type_of_anr == 0)   /* ANRA */
  1878.         {
  1879.             store_index = local_ptr->anr_entry[i].adn_record_index;
  1880.             /* PhoneBook[store_index + MAX_PB_PHONE_ENTRIES - 1].usim_field |= MMI_PHB_ENTRY_FIELD_ANRA; */
  1881.             PhoneBook[store_index + MAX_PB_PHONE_ENTRIES - 1].field |= MMI_PHB_ENTRY_FIELD_ANRA;
  1882.             g_phb_cntx.anra_used++;
  1883.             /* Number Field
  1884.                For L4 anr struct, the first byte of addr_bcd is TON, and the rest are BCD numbers.
  1885.                And the length is the total byte of TON + BCD numbers. */
  1886.             phb_anr[store_index - 1][type_of_anr].type = local_ptr->anr_entry[i].tel_number.addr_bcd[0];
  1887.             if (local_ptr->anr_entry[i].tel_number.addr_length > 0)
  1888.             {
  1889.                 bcd_length = ((local_ptr->anr_entry[i].tel_number.addr_length - 1) < ((MAX_PB_NUMBER_LENGTH + 1) / 2))
  1890.                     ? (local_ptr->anr_entry[i].tel_number.addr_length - 1) : ((MAX_PB_NUMBER_LENGTH + 1) / 2);
  1891.             }
  1892.             if (bcd_length > 0)
  1893.             {
  1894.                 // TODO:
  1895.                 //strncpy((S8*)PhoneBook[store_index].tel.number, (S8*)(LocalPtr->phb_entry.tel.addr_bcd+1), (MAX_PB_NUMBER_LENGTH + 1) / 2);
  1896.                 memset(phb_anr[store_index - 1][type_of_anr].number, 0xff, ((MAX_PB_NUMBER_LENGTH + 1) / 2));
  1897.                 memcpy(
  1898.                     phb_anr[store_index - 1][type_of_anr].number,
  1899.                     (local_ptr->anr_entry[i].tel_number.addr_bcd + 1),
  1900.                     bcd_length);
  1901.             }
  1902.             else
  1903.             {
  1904.                 phb_anr[store_index - 1][type_of_anr].number[0] = 0xff;
  1905.             }
  1906.             mmi_phb_convert_to_digit(num_ascii, phb_anr[store_index - 1][type_of_anr].number, MAX_PB_NUMBER_LENGTH + 1);
  1907.             phb_anr[store_index - 1][type_of_anr].length = strlen((S8*) num_ascii);
  1908.             mmi_phb_op_increase_lookup_table(
  1909.                 (U16) (store_index + MAX_PB_PHONE_ENTRIES - 1),
  1910.                 (S8*) num_ascii,
  1911.                 NULL,
  1912.                 NULL,
  1913.                 NULL);
  1914.             /* Update flag for number exists entry, Clear it first. */
  1915.             // TODO: what is the field flag for anr?
  1916.             //PhoneBook[store_index].field = 0;
  1917.             if (phb_anr[store_index - 1][type_of_anr].number[0] != 0xff)
  1918.             {
  1919.                 PhoneBook[store_index - 1].field |= MMI_PHB_ENTRY_FIELD_ANRA;
  1920.             }
  1921.         }
  1922.         else
  1923.         {
  1924.             break;
  1925.         }
  1926.     }
  1927.     //if ((localPtr->num_of_entry == MAX_EMAIL_ENTRIES_IN_LIST) && (g_phb_cntx.email_used < g_phb_cntx.email_total) &&
  1928.     //   g_phb_read_index < g_phb_cntx.email_total)
  1929.     {
  1930.         /* mmi_phb_email_read_req(g_phb_name_index[++g_phb_cntx.usim_field_read_count]); */
  1931.     }
  1932.     /* else */
  1933.     {
  1934.         /* read next usim field or finish; */
  1935.         mmi_phb_read_usim_field(local_ptr->access_id);
  1936.     }
  1937. }
  1938. #endif /* __MMI_PHB_USIM_FIELD__ */ 
  1939. #if !defined(MMI_ON_HARDWARE_P) /* For PC Simulater Load Entry */
  1940. /*****************************************************************************
  1941.  * FUNCTION
  1942.  *  mmi_phb_init_refresh_phonebook
  1943.  * DESCRIPTION
  1944.  *  Syncs the MMI phonebook with the protocol stack phonebook
  1945.  * PARAMETERS
  1946.  *  void
  1947.  * RETURNS
  1948.  *  void
  1949.  *****************************************************************************/
  1950. void mmi_phb_init_refresh_phonebook(void)
  1951. {
  1952.     /*----------------------------------------------------------------*/
  1953.     /* Local Variables                                                */
  1954.     /*----------------------------------------------------------------*/
  1955.     /*----------------------------------------------------------------*/
  1956.     /* Code Body                                                      */
  1957.     /*----------------------------------------------------------------*/
  1958.     g_phb_cntx.phone_used = 0;
  1959.     g_phb_cntx.sim_used = 0;
  1960.     PhoneBookEntryCount = 0;
  1961.     g_phb_cntx.refresh_list = MMI_PHB_ENTRY_REFRESH;
  1962.     mmi_phb_get_entry_by_index_req();
  1963. }
  1964. /*****************************************************************************
  1965.  * FUNCTION
  1966.  *  mmi_phb_get_entry_by_index_req
  1967.  * DESCRIPTION
  1968.  *  Requests the stack to return the phonebook entries
  1969.  * PARAMETERS
  1970.  *  void
  1971.  * RETURNS
  1972.  *  void
  1973.  *****************************************************************************/
  1974. void mmi_phb_get_entry_by_index_req(void)
  1975. {
  1976.     /*----------------------------------------------------------------*/
  1977.     /* Local Variables                                                */
  1978.     /*----------------------------------------------------------------*/
  1979.     MSG_PHB_GET_ENTRY_BY_INDEX_REQ_STRUCT *myMsgPtr;
  1980.     MYQUEUE Message;
  1981.     /*----------------------------------------------------------------*/
  1982.     /* Code Body                                                      */
  1983.     /*----------------------------------------------------------------*/
  1984.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_get_entry_by_index_req.>n", __FILE__,
  1985.                          __LINE__));
  1986.     if (!PhoneBookEntryCount)
  1987.     {
  1988.         g_phb_read_index = 1;
  1989.     }
  1990.     else
  1991.     {
  1992.         g_phb_read_index += MAX_ENTRIES_IN_LIST;
  1993.     }
  1994.     myMsgPtr =
  1995.         (MSG_PHB_GET_ENTRY_BY_INDEX_REQ_STRUCT*) OslConstructDataPtr(sizeof(MSG_PHB_GET_ENTRY_BY_INDEX_REQ_STRUCT));
  1996.     myMsgPtr->index = g_phb_read_index;
  1997.     myMsgPtr->record_index = 0xFFFF;
  1998.     myMsgPtr->storage = MMI_STORAGE_NONE;
  1999.     myMsgPtr->type = MMI_PHB_PHONEBOOK;
  2000.     myMsgPtr->no_data = MAX_ENTRIES_IN_LIST;
  2001.     Message.oslSrcId = MOD_MMI;
  2002.     Message.oslDestId = MOD_L4C;
  2003.     Message.oslMsgId = PRT_PHB_GET_ENTRY_BY_INDEX_REQ;
  2004.     Message.oslDataPtr = (oslParaType*) myMsgPtr;
  2005.     Message.oslPeerBuffPtr = NULL;
  2006.     SetProtocolEventHandler(mmi_phb_get_entry_by_index_rsp, PRT_PHB_GET_ENTRY_BY_INDEX_RSP);
  2007.     OslMsgSendExtQueue(&Message);
  2008. }
  2009. /*****************************************************************************
  2010.  * FUNCTION
  2011.  *  mmi_phb_get_entry_by_index_rsp
  2012.  * DESCRIPTION
  2013.  *  Handles response from stack, which returns phonebook entries
  2014.  * PARAMETERS
  2015.  *  info        [?]     
  2016.  * RETURNS
  2017.  *  void
  2018.  *****************************************************************************/
  2019. void mmi_phb_get_entry_by_index_rsp(void *info)
  2020. {
  2021.     /*----------------------------------------------------------------*/
  2022.     /* Local Variables                                                */
  2023.     /*----------------------------------------------------------------*/
  2024.     MSG_PHB_GET_ENTRY_BY_INDEX_RSP_STRUCT *localPtr;
  2025.     U8 i;
  2026.     U16 store_index;
  2027.     /*----------------------------------------------------------------*/
  2028.     /* Code Body                                                      */
  2029.     /*----------------------------------------------------------------*/
  2030.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_get_entry_by_index_rsp.>n", __FILE__,
  2031.                          __LINE__));
  2032.     localPtr = (MSG_PHB_GET_ENTRY_BY_INDEX_RSP_STRUCT*) info;
  2033.     if (localPtr->result.flag == 0 /* OK */ )
  2034.     {
  2035.         for (i = 0; i < localPtr->no_list; ++i)
  2036.         {
  2037.             if (localPtr->list[i].storage == MMI_SIM)
  2038.             {
  2039.                 if (g_phb_cntx.sim_used < g_phb_cntx.sim_total)
  2040.                 {
  2041.                     ++g_phb_cntx.sim_used;
  2042.                     store_index = localPtr->list[i].record_index + MAX_PB_PHONE_ENTRIES - 1;    /* Storage Location in array. */
  2043.                 }
  2044.                 else
  2045.                 {
  2046.                     continue;
  2047.                 }
  2048.             }
  2049.             else
  2050.             {
  2051.                 if (g_phb_cntx.phone_used < g_phb_cntx.phone_total)
  2052.                 {
  2053.                     ++g_phb_cntx.phone_used;
  2054.                     store_index = localPtr->list[i].record_index - 1;   /* Storage Location in array. */
  2055.                 }
  2056.                 else
  2057.                 {
  2058.                     continue;
  2059.                 }
  2060.             }
  2061.             PhoneBook[store_index].alpha_id.name_length = localPtr->list[i].alpha_id.name_length;       /* *ENCODING_LENGTH; */
  2062.             PhoneBook[store_index].alpha_id.name_dcs = localPtr->list[i].alpha_id.name_dcs;
  2063.             InputboxConvertGSMToDeviceEncoding(
  2064.                 localPtr->list[i].alpha_id.name,
  2065.                 PhoneBook[store_index].alpha_id.name,
  2066.                 localPtr->list[i].alpha_id.name_length,
  2067.                 (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH,
  2068.                 localPtr->list[i].alpha_id.name_dcs,
  2069.                 0,
  2070.                 1);
  2071.         #if defined(__PHB_0x81_SUPPORT__)       /* Support maximum length of 0x81 UCS2 */
  2072.             if (PhoneBook[store_index].alpha_id.name_dcs == MMI_PHB_UCS2_81 ||
  2073.                 PhoneBook[store_index].alpha_id.name_dcs == MMI_PHB_UCS2_82)
  2074.             {
  2075.                 PhoneBook[store_index].alpha_id.name_dcs = MMI_PHB_UCS2;
  2076.             }
  2077.         #endif /* defined(__PHB_0x81_SUPPORT__) */ 
  2078.             PhoneBook[store_index].tel.type = localPtr->list[i].tel.type;
  2079.             PhoneBook[store_index].tel.length = localPtr->list[i].tel.length;
  2080.             mmi_phb_convert_to_bcd(
  2081.                 PhoneBook[store_index].tel.number,
  2082.                 localPtr->list[i].tel.number,
  2083.                 (MAX_PB_NUMBER_LENGTH + 1) / 2);
  2084.             /* Update flag for number exists entry, Clear it first. */
  2085.             PhoneBook[store_index].field = 0;
  2086.             if (PhoneBook[store_index].tel.number[0] != 0xff)
  2087.             {
  2088.                 PhoneBook[store_index].field |= MMI_PHB_ENTRY_FIELD_NUMBER;
  2089.             }
  2090.             g_phb_name_index[PhoneBookEntryCount] = store_index;
  2091.             ++PhoneBookEntryCount;
  2092.         }
  2093.         if ((localPtr->no_list == MAX_ENTRIES_IN_LIST) &&
  2094.             (PhoneBookEntryCount < (g_phb_cntx.sim_total + g_phb_cntx.phone_total)))
  2095.         {
  2096.             mmi_phb_get_entry_by_index_req();
  2097.         }
  2098.         else
  2099.         {
  2100.             mmi_phb_sort_build_name_index();
  2101.             PhbGetSpeedDialInfo();
  2102.         }
  2103.     }
  2104.     else
  2105.     {
  2106.         mmi_phb_sort_build_name_index();
  2107.         PhbGetSpeedDialInfo();
  2108.     }
  2109. }
  2110. #endif /* !defined(MMI_ON_HARDWARE_P) */ 
  2111. #if defined(__MMI_PHB_CALLERGROUP_IN_SIM__)     /* Associate caller group in SIM card entry */
  2112. /*****************************************************************************
  2113.  * FUNCTION
  2114.  *  mmi_phb_init_check_sim_change
  2115.  * DESCRIPTION
  2116.  *  This function checks if sim changes for phonebook.
  2117.  * PARAMETERS
  2118.  *  void
  2119.  * RETURNS
  2120.  *  TRUE if updated. FALSE if not.
  2121.  *****************************************************************************/
  2122. BOOL mmi_phb_init_check_sim_change(void)
  2123. {
  2124. #if defined(MMI_ON_HARDWARE_P)  /* Check SIM change only on hardware */
  2125.     /*----------------------------------------------------------------*/
  2126.     /* Local Variables                                                */
  2127.     /*----------------------------------------------------------------*/
  2128.     U16 count = 0;
  2129.     U16 i;
  2130.     S16 pError;
  2131.     U8 optid_record, optid_index, current_record = 0;
  2132.     PHB_OPTIONAL_IDS_STRUCT PhbOptIDs[OPTIONAL_IDS_RECORD_TOTAL];
  2133.     /*----------------------------------------------------------------*/
  2134.     /* Code Body                                                      */
  2135.     /*----------------------------------------------------------------*/
  2136.     if (g_phb_sim_check == 0)
  2137.     {
  2138.         g_phb_sim_check = 1;
  2139.         if (is_sim_replaced())
  2140.         {
  2141.             /* Count entry number first */
  2142.             for (i = MAX_PB_PHONE_ENTRIES; i < MAX_PB_ENTRIES; ++i)
  2143.             {
  2144.                 /* Get optional IDs record. */
  2145.                 optid_record = (i / OPTIONAL_IDS_RECORD_TOTAL) + 1;
  2146.                 optid_index = i - (optid_record - 1) * OPTIONAL_IDS_RECORD_TOTAL;
  2147.                 if (optid_record != current_record)
  2148.                 {
  2149.                     ReadRecord(
  2150.                         NVRAM_EF_PHB_IDS_LID,
  2151.                         optid_record,
  2152.                         (void*)PhbOptIDs,
  2153.                         OPTIONAL_IDS_RECORD_SIZE,
  2154.                         &pError);
  2155.                     current_record = optid_record;
  2156.                 }
  2157.                 if (PhbOptIDs[optid_index].callerGroupID != 0)
  2158.                 {
  2159.                     count++;
  2160.                 }
  2161.             }
  2162.             /* If id exists, prompt user to delete. */
  2163.             if (count)
  2164.             {
  2165.                 mmi_phb_init_entry_sim_refresh_confirm();
  2166.                 return TRUE;
  2167.             }
  2168.         }
  2169.     }
  2170. #endif /* defined(MMI_ON_HARDWARE_P) */ 
  2171.     return FALSE;
  2172. }
  2173. /*****************************************************************************
  2174.  * FUNCTION
  2175.  *  mmi_phb_init_entry_sim_refresh_confirm
  2176.  * DESCRIPTION
  2177.  *  This function is the confirmation screen for SIM changed.
  2178.  * PARAMETERS
  2179.  *  void
  2180.  * RETURNS
  2181.  *  void
  2182.  *****************************************************************************/
  2183. void mmi_phb_init_entry_sim_refresh_confirm(void)
  2184. {
  2185.     /*----------------------------------------------------------------*/
  2186.     /* Local Variables                                                */
  2187.     /*----------------------------------------------------------------*/
  2188.     /*----------------------------------------------------------------*/
  2189.     /* Code Body                                                      */
  2190.     /*----------------------------------------------------------------*/
  2191.     /* U8* guiBuffer; */
  2192.     DisplayConfirm(
  2193.         STR_GLOBAL_YES,
  2194.         IMG_GLOBAL_YES,
  2195.         STR_GLOBAL_NO,
  2196.         IMG_GLOBAL_NO,
  2197.         get_string(STR_ID_PHB_REFRESH_SIM),
  2198.         IMG_GLOBAL_QUESTION,
  2199.         WARNING_TONE);
  2200.     //EntryNewScreen(SCR_ID_PHB_REFRESH_SIM_CONFIRM, NULL, mmi_phb_init_entry_sim_refresh_confirm, NULL);
  2201.     //guiBuffer = GetCurrGuiBuffer(SCR_ID_PHB_REFRESH_SIM_CONFIRM);
  2202.     //ShowCategory164Screen(STR_GLOBAL_YES, IMG_GLOBAL_YES, STR_GLOBAL_NO,IMG_GLOBAL_NO,
  2203.     //   STR_ID_PHB_REFRESH_SIM, IMG_GLOBAL_QUESTION, guiBuffer);
  2204.     SetLeftSoftkeyFunction(mmi_phb_init_delete_caller_group_in_sim, KEY_EVENT_UP);
  2205.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  2206.     /* playRequestedTone(WARNING_TONE); */
  2207. }
  2208. /*****************************************************************************
  2209.  * FUNCTION
  2210.  *  mmi_phb_init_delete_caller_group_in_sim
  2211.  * DESCRIPTION
  2212.  *  This function clears all caller group associate to SIM card.
  2213.  * PARAMETERS
  2214.  *  void
  2215.  * RETURNS
  2216.  *  void
  2217.  *****************************************************************************/
  2218. void mmi_phb_init_delete_caller_group_in_sim(void)
  2219. {
  2220.     /*----------------------------------------------------------------*/
  2221.     /* Local Variables                                                */
  2222.     /*----------------------------------------------------------------*/
  2223.     U16 i;
  2224.     S16 pError;
  2225.     U8 optid_record, optid_index, current_record = 0;
  2226.     PHB_OPTIONAL_IDS_STRUCT PhbOptIDs[OPTIONAL_IDS_RECORD_TOTAL];
  2227.     /*----------------------------------------------------------------*/
  2228.     /* Code Body                                                      */
  2229.     /*----------------------------------------------------------------*/
  2230.     for (i = MAX_PB_PHONE_ENTRIES; i < MAX_PB_ENTRIES; ++i)
  2231.     {
  2232.         /* Get optional IDs record. */
  2233.         optid_record = (i / OPTIONAL_IDS_RECORD_TOTAL) + 1;
  2234.         optid_index = i - (optid_record - 1) * OPTIONAL_IDS_RECORD_TOTAL;
  2235.         if (optid_record != current_record)
  2236.         {
  2237.             if (current_record != 0)    /* Write result back for previous optional ID record. */
  2238.             {
  2239.                 WriteRecord(NVRAM_EF_PHB_IDS_LID, current_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  2240.             }
  2241.             /* Read out next record. */
  2242.             ReadRecord(NVRAM_EF_PHB_IDS_LID, optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  2243.             current_record = optid_record;
  2244.         }
  2245.         memset(&PhbOptIDs[optid_index], 0, sizeof(PHB_OPTIONAL_IDS_STRUCT));
  2246.     }
  2247.     /* Write back for last record. */
  2248.     WriteRecord(NVRAM_EF_PHB_IDS_LID, optid_record, (void*)PhbOptIDs, OPTIONAL_IDS_RECORD_SIZE, &pError);
  2249.     DisplayPopup(
  2250.         (U8*) GetString(STR_GLOBAL_DONE),
  2251.         IMG_GLOBAL_ACTIVATED,
  2252.         TRUE,
  2253.         UI_POPUP_NOTIFYDURATION_TIME,
  2254.         SUCCESS_TONE);
  2255.     DeleteNScrId(SCR_ID_PHB_REFRESH_SIM_CONFIRM);
  2256. }
  2257. #endif /* defined(__MMI_PHB_CALLERGROUP_IN_SIM__) */ 
  2258. #define MMI_PHB_MAIN_MENU
  2259. /*****************************************************************************
  2260.  * FUNCTION
  2261.  *  mmi_phb_entry_main_menu
  2262.  * DESCRIPTION
  2263.  *  Shows the Phonebook main menu
  2264.  * PARAMETERS
  2265.  *  void
  2266.  * RETURNS
  2267.  *  void
  2268.  *****************************************************************************/
  2269. void mmi_phb_entry_main_menu(void)
  2270. {
  2271.     /*----------------------------------------------------------------*/
  2272.     /* Local Variables                                                */
  2273.     /*----------------------------------------------------------------*/
  2274.     U8 *guiBuffer;
  2275.     U16 nStrItemList[MAX_SUB_MENUS];
  2276.     U16 nImgIltemList[MAX_SUB_MENUS];
  2277.     U16 nNumofItem;
  2278.     U8 *hintList[MAX_SUB_MENUS];    /* Array for hint */
  2279.     /*----------------------------------------------------------------*/
  2280.     /* Code Body                                                      */
  2281.     /*----------------------------------------------------------------*/
  2282.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_entry_main_menu.>n", __FILE__, __LINE__));
  2283.     /* g_phb_cntx.selected_pic_in_view = 0; */
  2284.     /* if sync now, user cannot enter phonebook */
  2285. #ifdef __SYNCML_SUPPORT__
  2286.     if (mmi_syncml_is_phb_sync_now())
  2287.     {
  2288.         mmi_phb_entry_not_ready(STR_ID_SYNC_PLEASE_WAIT);
  2289.         return;
  2290.     }
  2291. #endif /* __SYNCML_SUPPORT__ */
  2292.     g_phb_enter_from = MMI_PHB_ENTER_NONE;
  2293.     EntryNewScreen(SCR_PBOOK_MAIN_MENU, mmi_phb_exit_main_menu, mmi_phb_entry_main_menu, NULL);
  2294.     guiBuffer = GetCurrGuiBuffer(SCR_PBOOK_MAIN_MENU);  /* Getting the Index from history */
  2295.     if (gInsertSimAppFlag != 1)
  2296.     {
  2297.         nNumofItem = GetNumOfChild(MAIN_MENU_PHONEBOOK_MENUID);
  2298.         GetSequenceStringIds(MAIN_MENU_PHONEBOOK_MENUID, nStrItemList);
  2299.         GetSequenceImageIds(MAIN_MENU_PHONEBOOK_MENUID, nImgIltemList);
  2300.         SetParentHandler(MAIN_MENU_PHONEBOOK_MENUID);
  2301.         /* Construct List To Show Hint */
  2302.         ConstructHintsList(MAIN_MENU_PHONEBOOK_MENUID, hintList);
  2303.     }
  2304.     else
  2305.     {
  2306.         nNumofItem = GetNumOfChild(MAIN_MENU_PHONEBOOK_NO_SIM_MENUID);
  2307.         GetSequenceStringIds(MAIN_MENU_PHONEBOOK_NO_SIM_MENUID, nStrItemList);
  2308.         GetSequenceImageIds(MAIN_MENU_PHONEBOOK_NO_SIM_MENUID, nImgIltemList);
  2309.         SetParentHandler(MAIN_MENU_PHONEBOOK_NO_SIM_MENUID);
  2310.         /* Construct List To Show Hint */
  2311.         ConstructHintsList(MAIN_MENU_PHONEBOOK_NO_SIM_MENUID, hintList);
  2312.     }
  2313.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  2314.     /* Call option menu may invoke before mmi_phb_init is executed */
  2315.     mmi_phb_set_main_menu_highlight_handler();
  2316.     /* MTK Leo add, mini_tab_bar */
  2317. #ifdef __MMI_WGUI_MINI_TAB_BAR__
  2318.     if (gInsertSimAppFlag != 1)
  2319.     {
  2320.         wgui_enable_mini_tab_bar(MAIN_MENU_PHONEBOOK_MENUID);
  2321.     }
  2322.     else
  2323.     {
  2324.         wgui_enable_mini_tab_bar(MAIN_MENU_PHONEBOOK_NO_SIM_MENUID);
  2325.     }
  2326. #endif /* __MMI_WGUI_MINI_TAB_BAR__ */ 
  2327.     /* MTK Leo end */
  2328.     /* Screen with hint, if no hint needed, can change to Screen 15 */
  2329.     ShowCategory52Screen(
  2330.         STR_SCR_PBOOK_CAPTION,
  2331.         IMG_SCR_PBOOK_CAPTION,
  2332.         STR_GLOBAL_OK,
  2333.         IMG_GLOBAL_OK,
  2334.         STR_GLOBAL_BACK,
  2335.         IMG_GLOBAL_BACK,
  2336.         nNumofItem,
  2337.         nStrItemList,
  2338.         nImgIltemList,
  2339.         hintList,
  2340.         0,
  2341.         0,
  2342.         guiBuffer);
  2343. }
  2344. /*****************************************************************************
  2345.  * FUNCTION
  2346.  *  mmi_phb_exit_main_menu
  2347.  * DESCRIPTION
  2348.  *  Exit function for mmi_phb_entry_main_menu()
  2349.  * PARAMETERS
  2350.  *  void
  2351.  * RETURNS
  2352.  *  void
  2353.  *****************************************************************************/
  2354. void mmi_phb_exit_main_menu(void)
  2355. {
  2356.     /*----------------------------------------------------------------*/
  2357.     /* Local Variables                                                */
  2358.     /*----------------------------------------------------------------*/
  2359.     /*----------------------------------------------------------------*/
  2360.     /* Code Body                                                      */
  2361.     /*----------------------------------------------------------------*/
  2362.     g_phb_cntx.start_scr_id = SCR_PBOOK_MAIN_MENU;
  2363.     g_phb_cntx.end_scr_id = SCR_PBOOK_MAIN_MENU;
  2364.     /* MTK Leo add, mini_tab_bar */
  2365. #ifdef __MMI_WGUI_MINI_TAB_BAR__
  2366.     wgui_disable_mini_tab_bar();
  2367. #endif 
  2368.     /* MTK Leo end */
  2369. }
  2370. /*****************************************************************************
  2371.  * FUNCTION
  2372.  *  mmi_phb_entry_not_ready
  2373.  * DESCRIPTION
  2374.  *  Displays Phobebook not ready screen
  2375.  * PARAMETERS
  2376.  *  str_id        [IN]   String id for display     
  2377.  * RETURNS
  2378.  *  void
  2379.  *****************************************************************************/
  2380. void mmi_phb_entry_not_ready(U16 str_id)
  2381. {
  2382.     /*----------------------------------------------------------------*/
  2383.     /* Local Variables                                                */
  2384.     /*----------------------------------------------------------------*/
  2385.     /*----------------------------------------------------------------*/
  2386.     /* Code Body                                                      */
  2387.     /*----------------------------------------------------------------*/
  2388.     EntryNewScreen(SCR_PHB_DUMMY, mmi_phb_exit_not_ready, NULL, NULL);
  2389.     StartTimer(PHB_NOTIFYDURATION_TIMER, PHB_NOTIFY_TIMEOUT, mmi_phb_wait_and_go_back);
  2390.     ShowCategory66Screen(
  2391.         STR_SCR_PBOOK_CAPTION,
  2392.         IMG_SCR_PBOOK_CAPTION,
  2393.         0,
  2394.         0,
  2395.         STR_GLOBAL_BACK,
  2396.         IMG_GLOBAL_BACK,
  2397.         (PU8) GetString(str_id),
  2398.         IMG_PROCESSING_PHONEBOOK,
  2399.         NULL);
  2400.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  2401. }
  2402. /*****************************************************************************
  2403.  * FUNCTION
  2404.  *  mmi_phb_exit_not_ready
  2405.  * DESCRIPTION
  2406.  *  Exit function for mmi_phb_entry_not_ready.
  2407.  * PARAMETERS
  2408.  *  void
  2409.  * RETURNS
  2410.  *  void
  2411.  *****************************************************************************/
  2412. void mmi_phb_exit_not_ready(void)
  2413. {
  2414.     /*----------------------------------------------------------------*/
  2415.     /* Local Variables                                                */
  2416.     /*----------------------------------------------------------------*/
  2417.     /*----------------------------------------------------------------*/
  2418.     /* Code Body                                                      */
  2419.     /*----------------------------------------------------------------*/
  2420.     StopTimer(PHB_NOTIFYDURATION_TIMER);
  2421.     g_idle_context.ToNameScrFromIdleApp = 0;
  2422.     g_idle_context.RskPressedFromIdleApp = 0;
  2423. }
  2424. /*****************************************************************************
  2425.  * FUNCTION
  2426.  *  mmi_phb_wait_and_go_back
  2427.  * DESCRIPTION
  2428.  *  Goes back to history after timer expires
  2429.  * PARAMETERS
  2430.  *  void
  2431.  * RETURNS
  2432.  *  void
  2433.  *****************************************************************************/
  2434. void mmi_phb_wait_and_go_back(void)
  2435. {
  2436.     /*----------------------------------------------------------------*/
  2437.     /* Local Variables                                                */
  2438.     /*----------------------------------------------------------------*/
  2439.     /*----------------------------------------------------------------*/
  2440.     /* Code Body                                                      */
  2441.     /*----------------------------------------------------------------*/
  2442.     StopTimer(PHB_NOTIFYDURATION_TIMER);
  2443.     GoBackHistory();
  2444.     g_idle_context.ToNameScrFromIdleApp = 0;
  2445.     g_idle_context.RskPressedFromIdleApp = 0;
  2446. }
  2447. /*****************************************************************************
  2448.  * FUNCTION
  2449.  *  mmi_phb_show_in_progress
  2450.  * DESCRIPTION
  2451.  *  To display work-in-progress status
  2452.  * PARAMETERS
  2453.  *  msg         [IN]        
  2454.  *  msgIcon     [IN]        
  2455.  * RETURNS
  2456.  *  void
  2457.  *****************************************************************************/
  2458. void mmi_phb_show_in_progress(U16 msg, U16 msgIcon)
  2459. {
  2460.     /*----------------------------------------------------------------*/
  2461.     /* Local Variables                                                */
  2462.     /*----------------------------------------------------------------*/
  2463.     /*----------------------------------------------------------------*/
  2464.     /* Code Body                                                      */
  2465.     /*----------------------------------------------------------------*/
  2466.     g_phb_message = msg;
  2467.     g_phb_message_icon = msgIcon;
  2468.     mmi_phb_entry_in_progress();
  2469. }
  2470. /*****************************************************************************
  2471.  * FUNCTION
  2472.  *  mmi_phb_entry_in_progress
  2473.  * DESCRIPTION
  2474.  *  Draws the in-progress screen
  2475.  * PARAMETERS
  2476.  *  void
  2477.  * RETURNS
  2478.  *  void
  2479.  *****************************************************************************/
  2480. void mmi_phb_entry_in_progress(void)
  2481. {
  2482.     /*----------------------------------------------------------------*/
  2483.     /* Local Variables                                                */
  2484.     /*----------------------------------------------------------------*/
  2485.     /*----------------------------------------------------------------*/
  2486.     /* Code Body                                                      */
  2487.     /*----------------------------------------------------------------*/
  2488.     /* EntryNewScreen(SCR_IN_PROGRESS_PHB, mmi_phb_exit_in_progress, NULL,NULL); */
  2489.     EntryNewScreen(SCR_IN_PROGRESS_PHB, NULL, NULL, NULL);
  2490.     /* PMT HIMANSHU START 20050920 */
  2491. #ifdef __MMI_MAINLCD_240X320__
  2492.     /* passing 0xffff for Title string and Title icon for the disbling the status bar and title display. */
  2493.     ShowCategory8Screen(0xffff, 0xffff, 0, 0, 0, 0, g_phb_message, g_phb_message_icon, NULL);
  2494. #else /* __MMI_MAINLCD_240X320__ */ 
  2495.     ShowCategory8Screen(
  2496.         STR_SCR_PBOOK_CAPTION,
  2497.         IMG_SCR_PBOOK_CAPTION,
  2498.         0,
  2499.         0,
  2500.         0,
  2501.         0,
  2502.         g_phb_message,
  2503.         g_phb_message_icon,
  2504.         NULL);
  2505. #endif /* __MMI_MAINLCD_240X320__ */ 
  2506.     ClearInputEventHandler(MMI_DEVICE_ALL);
  2507.     ClearKeyHandler(KEY_END, KEY_EVENT_UP);
  2508.     ClearKeyHandler(KEY_END, KEY_EVENT_DOWN);
  2509.     ClearKeyHandler(KEY_END, KEY_LONG_PRESS);
  2510.     ClearKeyHandler(KEY_END, KEY_REPEAT);
  2511. }
  2512. /*****************************************************************************
  2513.  * FUNCTION
  2514.  *  mmi_phb_show_mass_processing
  2515.  * DESCRIPTION
  2516.  *  To display work-in-progress status for mass operation. (Copy All, Delete All)
  2517.  * PARAMETERS
  2518.  *  msg         [IN]        
  2519.  *  msgIcon     [IN]        
  2520.  * RETURNS
  2521.  *  void
  2522.  *****************************************************************************/
  2523. void mmi_phb_show_mass_processing(U16 msg, U16 msgIcon)
  2524. {
  2525.     /*----------------------------------------------------------------*/
  2526.     /* Local Variables                                                */
  2527.     /*----------------------------------------------------------------*/
  2528.     /*----------------------------------------------------------------*/
  2529.     /* Code Body                                                      */
  2530.     /*----------------------------------------------------------------*/
  2531.     g_phb_message = msg;
  2532.     g_phb_message_icon = msgIcon;
  2533.     mmi_phb_entry_mass_processing();
  2534. }
  2535. /*****************************************************************************
  2536.  * FUNCTION
  2537.  *  mmi_phb_mass_processing_scr_del_callback
  2538.  * DESCRIPTION
  2539.  *  Call back function when the screen is deleted
  2540.  * PARAMETERS
  2541.  *  p       [?]     
  2542.  * RETURNS
  2543.  *  void
  2544.  *****************************************************************************/
  2545. U8 mmi_phb_mass_processing_scr_del_callback(void *p)
  2546. {
  2547.     /*----------------------------------------------------------------*/
  2548.     /* Local Variables                                                */
  2549.     /*----------------------------------------------------------------*/
  2550.     /*----------------------------------------------------------------*/
  2551.     /* Code Body                                                      */
  2552.     /*----------------------------------------------------------------*/
  2553.     if (g_phb_cntx.processing)  /* if phonebook still copying or deleting, do not deleted this screen */
  2554.     {
  2555.         return MMI_TRUE;
  2556.     }
  2557.     else
  2558.     {
  2559.         return MMI_FALSE;
  2560.     }
  2561. }
  2562. /*****************************************************************************
  2563.  * FUNCTION
  2564.  *  mmi_phb_entry_mass_processing
  2565.  * DESCRIPTION
  2566.  *  Draws the in-progress screen for mass operation. (This screen has abort function.)
  2567.  * PARAMETERS
  2568.  *  void
  2569.  * RETURNS
  2570.  *  void
  2571.  *****************************************************************************/
  2572. void mmi_phb_entry_mass_processing(void)
  2573. {
  2574.     /*----------------------------------------------------------------*/
  2575.     /* Local Variables                                                */
  2576.     /*----------------------------------------------------------------*/
  2577.     /*----------------------------------------------------------------*/
  2578.     /* Code Body                                                      */
  2579.     /*----------------------------------------------------------------*/
  2580.     EntryNewScreen(SCR_COPY_ALL_PROGRESS, mmi_phb_exit_mass_processing, NULL, NULL);
  2581. #ifdef __MMI_MAINLCD_240X320__
  2582.     /* passing 0xffff for Title string and Title icon for the disbling the status bar and title display. */
  2583.     ShowCategory8Screen(
  2584.         0xffff,
  2585.         0xffff,
  2586.         0,
  2587.         0,
  2588.         STR_GLOBAL_ABORT,
  2589.         IMG_COPY_ALL_ABORT,
  2590.         g_phb_message,
  2591.         g_phb_message_icon,
  2592.         NULL);
  2593. #else /* __MMI_MAINLCD_240X320__ */ 
  2594.     ShowCategory8Screen(
  2595.         STR_SCR_PBOOK_CAPTION,
  2596.         IMG_SCR_PBOOK_CAPTION,
  2597.         0,
  2598.         0,
  2599.         STR_GLOBAL_ABORT,
  2600.         IMG_COPY_ALL_ABORT,
  2601.         g_phb_message,
  2602.         g_phb_message_icon,
  2603.         NULL);
  2604. #endif /* __MMI_MAINLCD_240X320__ */ 
  2605.     /* If this screen is deleted, call back function. */
  2606.     SetDelScrnIDCallbackHandler(SCR_COPY_ALL_PROGRESS, (HistoryDelCBPtr) mmi_phb_mass_processing_scr_del_callback);
  2607.     ClearInputEventHandler(MMI_DEVICE_KEY);
  2608.     ClearKeyHandler(KEY_END, KEY_EVENT_UP);
  2609.     ClearKeyHandler(KEY_END, KEY_EVENT_DOWN);
  2610.     ClearKeyHandler(KEY_END, KEY_LONG_PRESS);
  2611.     ClearKeyHandler(KEY_END, KEY_REPEAT);
  2612.     SetRightSoftkeyFunction(mmi_phb_mass_processing_abort, KEY_EVENT_UP);
  2613. }
  2614. /*****************************************************************************
  2615.  * FUNCTION
  2616.  *  mmi_phb_exit_mass_processing
  2617.  * DESCRIPTION
  2618.  *  Exit function to mmi_phb_entry_mass_processing()
  2619.  * PARAMETERS
  2620.  *  void
  2621.  * RETURNS
  2622.  *  void
  2623.  *****************************************************************************/
  2624. void mmi_phb_exit_mass_processing(void)
  2625. {
  2626.     /*----------------------------------------------------------------*/
  2627.     /* Local Variables                                                */
  2628.     /*----------------------------------------------------------------*/
  2629.     history h;
  2630.     S16 nHistory = 0;
  2631.     /*----------------------------------------------------------------*/
  2632.     /* Code Body                                                      */
  2633.     /*----------------------------------------------------------------*/
  2634.     if (g_phb_cntx.processing)
  2635.     {
  2636.         g_phb_cntx.end_scr_id = SCR_COPY_ALL_PROGRESS;
  2637.         h.scrnID = SCR_COPY_ALL_PROGRESS;
  2638.         h.entryFuncPtr = mmi_phb_entry_mass_processing;
  2639.         pfnUnicodeStrcpy((PS8) h.inputBuffer, (PS8) & nHistory);
  2640.         GetCategoryHistory(h.guiBuffer);
  2641.         AddHistory(h);
  2642.     }
  2643. }
  2644. #define MMI_PHB_LIST
  2645. /*****************************************************************************
  2646.  * FUNCTION
  2647.  *  mmi_phb_list_allocate_filter
  2648.  * DESCRIPTION
  2649.  *  allocate memory phonebook list filter buffer. The filter is used for display phonebook list
  2650.  *  with certain conditions.
  2651.  * PARAMETERS
  2652.  *  void
  2653.  * RETURNS
  2654.  *  void
  2655.  *****************************************************************************/
  2656. void mmi_phb_list_allocate_filter(void)
  2657. {
  2658. #if (MAX_PB_ENTRIES >= 1000)
  2659.     /*----------------------------------------------------------------*/
  2660.     /* Local Variables                                                */
  2661.     /*----------------------------------------------------------------*/
  2662.     /*----------------------------------------------------------------*/
  2663.     /* Code Body                                                      */
  2664.     /*----------------------------------------------------------------*/
  2665.     g_phb_cntx.list_filter = (U16*) g_phb_list_filter;
  2666. #else /* (MAX_PB_ENTRIES >= 1000) */ 
  2667.     if (g_phb_cntx.list_filter == NULL)
  2668.     {
  2669.         g_phb_cntx.list_filter = OslMalloc(MAX_PB_ENTRIES * 2);
  2670.     }
  2671. #endif /* (MAX_PB_ENTRIES >= 1000) */ /* MAX_PB_ENTRIES >= 1000 */
  2672. }
  2673. /*****************************************************************************
  2674.  * FUNCTION
  2675.  *  mmi_phb_list_free_filter
  2676.  * DESCRIPTION
  2677.  *  free memory phonebook list filter buffer.
  2678.  * PARAMETERS
  2679.  *  void
  2680.  * RETURNS
  2681.  *  void
  2682.  *****************************************************************************/
  2683. void mmi_phb_list_free_filter(void)
  2684. {
  2685. #if (MAX_PB_ENTRIES < 1000)
  2686.     /*----------------------------------------------------------------*/
  2687.     /* Local Variables                                                */
  2688.     /*----------------------------------------------------------------*/
  2689.     /*----------------------------------------------------------------*/
  2690.     /* Code Body                                                      */
  2691.     /*----------------------------------------------------------------*/
  2692.     if (g_phb_cntx.list_filter)
  2693.     {
  2694.         OslMfree(g_phb_cntx.list_filter);
  2695.         g_phb_cntx.list_filter = NULL;
  2696.     }
  2697. #endif /* (MAX_PB_ENTRIES < 1000) */ /* MAX_PB_ENTRIES < 1000 */
  2698. }
  2699. /*****************************************************************************
  2700.  * FUNCTION
  2701.  *  mmi_phb_list_pre_entry
  2702.  * DESCRIPTION
  2703.  *  This function provide call back function before enter phonebook list
  2704.  * PARAMETERS
  2705.  *  void
  2706.  * RETURNS
  2707.  *  void
  2708.  *****************************************************************************/
  2709. void mmi_phb_list_pre_entry(void)
  2710. {
  2711.     /*----------------------------------------------------------------*/
  2712.     /* Local Variables                                                */
  2713.     /*----------------------------------------------------------------*/
  2714.     /*----------------------------------------------------------------*/
  2715.     /* Code Body                                                      */
  2716.     /*----------------------------------------------------------------*/
  2717.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_list_pre_entry.>n", __FILE__, __LINE__));
  2718.     g_phb_highlight_alpha = 0;
  2719. #if defined(__MMI_FILE_MANAGER__) && defined(MMI_ON_HARDWARE_P) && (!defined __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__)
  2720.     if (UI_device_height == 220 && UI_device_width == 176)
  2721.     {
  2722.         mmi_phb_entry_image_list1();
  2723.     }
  2724.     else
  2725. #endif /* defined(__MMI_FILE_MANAGER__) && defined(MMI_ON_HARDWARE_P) && (!defined __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__) */ 
  2726.     {
  2727.         FunctionPtr send_key_ptr;
  2728. #ifdef __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__
  2729.         if (phbListView == MMI_PHB_LIST_FOR_PHB)
  2730.         {
  2731.             send_key_ptr = mmi_phb_two_line_send_key_handler;
  2732.         }
  2733.         else 
  2734. #endif /* __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__ */
  2735.         {
  2736.             send_key_ptr = mmi_phb_choose_number_normal;
  2737.         }
  2738.         mmi_phb_entry_list(PhoneBookEntryCount,             /* Total Entry */
  2739.                            STR_SCR_PBOOK_VIEW_CAPTION,      /* Title String */
  2740.                            IMG_SCR_PBOOK_CAPTION,           /* Title Image */
  2741.                            STR_GLOBAL_OPTIONS,              /* LSK */
  2742.                            IMG_GLOBAL_OPTIONS,              /* LSK */
  2743. #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
  2744.                            mmi_phb_get_index_speak_name,
  2745. #else 
  2746.                            mmi_phb_get_index,               /* Highlight Callback */
  2747. #endif 
  2748.                            mmi_phb_entry_op_option,         /* LSK Callback */
  2749.                            send_key_ptr,                    /* SEND Key Callback */
  2750.                            mmi_phb_list_get_item,           /* List Callback */
  2751.                            mmi_phb_list_get_hint,           /* Hint Callback */
  2752.                            mmi_phb_list_pre_entry,          /* Re-Entry Callback */
  2753.                            TRUE,                            /* Alpha Index */
  2754.                            TRUE);                           /* Right Arrow Key */
  2755.     }
  2756. }
  2757. #if defined(__MMI_PHB_NAME_LIST_FILTER__)
  2758. /*****************************************************************************
  2759.  * FUNCTION
  2760.  *  mmi_phb_nlf_list_pre_entry
  2761.  * DESCRIPTION
  2762.  *  This function provide call back function before enter phonebook list with 
  2763.  *  name list filter feature
  2764.  * PARAMETERS
  2765.  *  void
  2766.  * RETURNS
  2767.  *  void
  2768.  *****************************************************************************/
  2769. void mmi_phb_nlf_list_pre_entry(void)
  2770. {
  2771.     /*----------------------------------------------------------------*/
  2772.     /* Local Variables                                                */
  2773.     /*----------------------------------------------------------------*/
  2774.     /*----------------------------------------------------------------*/
  2775.     /* Code Body                                                      */
  2776.     /*----------------------------------------------------------------*/
  2777.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_nlf_list_pre_entry.>n", __FILE__, __LINE__));
  2778.     g_phb_highlight_alpha = 0;
  2779. #if defined(__MMI_FILE_MANAGER__) && defined(MMI_ON_HARDWARE_P) && (!defined __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__)
  2780.     if (UI_device_height == 220 && UI_device_width == 176)
  2781.     {
  2782.         mmi_phb_nlf_entry_image_list1();
  2783.     }
  2784.     else
  2785. #endif /* defined(__MMI_FILE_MANAGER__) && defined(MMI_ON_HARDWARE_P) && (!defined __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__) */ 
  2786.     {
  2787.         FunctionPtr send_key_ptr;
  2788. #ifdef __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__
  2789.         if (phbListView == MMI_PHB_LIST_FOR_PHB)
  2790.         {
  2791.             send_key_ptr = mmi_phb_two_line_send_key_handler;
  2792.         }
  2793.         else 
  2794. #endif /* __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__ */
  2795.         {
  2796.             send_key_ptr = mmi_phb_choose_number_normal;
  2797.         }
  2798.         if(g_phb_cntx.name_list_filter == MMI_SIM)
  2799.         {
  2800.             g_phb_list_index_total = g_phb_cntx.sim_used;
  2801.         }
  2802.         else if(g_phb_cntx.name_list_filter == MMI_NVRAM)
  2803.         {
  2804.             g_phb_list_index_total = g_phb_cntx.phone_used;
  2805.         }
  2806.         else
  2807.         {
  2808.             g_phb_list_index_total = PhoneBookEntryCount;
  2809.         }
  2810.         mmi_phb_nlf_entry_list(g_phb_list_index_total,          /* Total Entry */
  2811.                            STR_SCR_PBOOK_VIEW_CAPTION,      /* Title String */
  2812.                            IMG_SCR_PBOOK_CAPTION,           /* Title Image */
  2813.                            STR_GLOBAL_OPTIONS,              /* LSK */
  2814.                            IMG_GLOBAL_OPTIONS,              /* LSK */
  2815. #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
  2816.                            mmi_phb_get_index_speak_name_nlf,
  2817. #else 
  2818.                            mmi_phb_get_index_nlf,               /* Highlight Callback */
  2819. #endif 
  2820.                            mmi_phb_entry_op_option,     /* LSK Callback */
  2821.                            send_key_ptr,                    /* SEND Key Callback */
  2822.                            mmi_phb_nlf_list_get_item,       /* List Callback */
  2823.                            mmi_phb_nlf_list_get_hint,       /* Hint Callback */
  2824.                            mmi_phb_nlf_list_pre_entry,      /* Re-Entry Callback */
  2825.                            TRUE,                            /* Alpha Index */
  2826.                            TRUE);                           /* Right Arrow Key */
  2827.     }
  2828. }