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

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.  * Alarm.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements Alarm application related screens.
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  * removed!
  148.  * removed!
  149.  * removed!
  150.  *
  151.  * removed!
  152.  * removed!
  153.  * removed!
  154.  *
  155.  * removed!
  156.  * removed!
  157.  * removed!
  158.  *
  159.  * removed!
  160.  * removed!
  161.  * removed!
  162.  *
  163.  * removed!
  164.  * removed!
  165.  * removed!
  166.  *
  167.  * removed!
  168.  * removed!
  169.  * removed!
  170.  *
  171.  * removed!
  172.  * removed!
  173.  * removed!
  174.  *
  175.  * removed!
  176.  * removed!
  177.  * removed!
  178.  *
  179.  * removed!
  180.  * removed!
  181.  * removed!
  182.  *
  183.  * removed!
  184.  * removed!
  185.  * removed!
  186.  *
  187.  * removed!
  188.  * removed!
  189.  * removed!
  190.  *
  191.  * removed!
  192.  * removed!
  193.  * removed!
  194.  *
  195.  * removed!
  196.  * removed!
  197.  * removed!
  198.  *
  199.  * removed!
  200.  * removed!
  201.  * removed!
  202.  *
  203.  * removed!
  204.  * removed!
  205.  * removed!
  206.  *
  207.  * removed!
  208.  * removed!
  209.  * removed!
  210.  *
  211.  * removed!
  212.  * removed!
  213.  * removed!
  214.  *
  215.  * removed!
  216.  * removed!
  217.  * removed!
  218.  *
  219.  * removed!
  220.  * removed!
  221.  * removed!
  222.  *
  223.  * removed!
  224.  * removed!
  225.  * removed!
  226.  *
  227.  * removed!
  228.  * removed!
  229.  * removed!
  230.  *
  231.  * removed!
  232.  * removed!
  233.  * removed!
  234.  *
  235.  * removed!
  236.  * removed!
  237.  * removed!
  238.  *
  239.  * removed!
  240.  * removed!
  241.  * removed!
  242.  * removed!
  243.  *
  244.  * removed!
  245.  * removed!
  246.  * removed!
  247.  * removed!
  248.  *
  249.  * removed!
  250.  * removed!
  251.  * removed!
  252.  *
  253.  * removed!
  254.  * removed!
  255.  * removed!
  256.  *
  257.  * removed!
  258.  * removed!
  259.  * removed!
  260.  *
  261.  * removed!
  262.  * removed!
  263.  * removed!
  264.  *
  265.  * removed!
  266.  * removed!
  267.  * removed!
  268.  *
  269.  * removed!
  270.  * removed!
  271.  * removed!
  272.  *
  273.  * removed!
  274.  * removed!
  275.  * removed!
  276.  *
  277.  * removed!
  278.  * removed!
  279.  * removed!
  280.  *
  281.  * removed!
  282.  * removed!
  283.  * removed!
  284.  *
  285.  * removed!
  286.  * removed!
  287.  * removed!
  288.  *
  289.  * removed!
  290.  * removed!
  291.  * removed!
  292.  *
  293.  * removed!
  294.  * removed!
  295.  * removed!
  296.  *
  297.  * removed!
  298.  * removed!
  299.  * removed!
  300.  *
  301.  * removed!
  302.  * removed!
  303.  * removed!
  304.  *
  305.  * removed!
  306.  * removed!
  307.  * removed!
  308.  *
  309.  * removed!
  310.  * removed!
  311.  * removed!
  312.  *
  313.  * removed!
  314.  * removed!
  315.  * removed!
  316.  *
  317.  * removed!
  318.  * removed!
  319.  * removed!
  320.  *
  321.  * removed!
  322.  * removed!
  323.  * removed!
  324.  *
  325.  * removed!
  326.  * removed!
  327.  * removed!
  328.  *
  329.  * removed!
  330.  * removed!
  331.  * removed!
  332.  *
  333.  * removed!
  334.  * removed!
  335.  * removed!
  336.  *
  337.  * removed!
  338.  * removed!
  339.  * removed!
  340.  *
  341.  * removed!
  342.  * removed!
  343.  * removed!
  344.  *
  345.  * removed!
  346.  * removed!
  347.  * removed!
  348.  *
  349.  * removed!
  350.  * removed!
  351.  * removed!
  352.  *
  353.  * removed!
  354.  * removed!
  355.  * removed!
  356.  *
  357.  *------------------------------------------------------------------------------
  358.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  359.  *============================================================================
  360.  ****************************************************************************/
  361. /**
  362.  * Copyright Notice
  363.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  364.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  365.  *  (It is illegal to remove this copyright notice from this software or any
  366.  *  portion of it) 
  367.  */
  368. /**************************************************************
  369.    FILENAME : Alarm.c
  370.    PURPOSE     : Handling of Alarm Application
  371.    REMARKS     : nil
  372.    AUTHOR      : Neeraj Sharma, Gautam Saluja
  373.    DATE     : June 9,03
  374. **************************************************************/
  375. #ifndef _MMI_ALARM_C
  376. #define _MMI_ALARM_C
  377. #include "MMI_features.h"
  378. /*  Include: MMI header file */
  379. #include "PixtelDataTypes.h"
  380. #include "GlobalDefs.h"
  381. #include "ProtocolEvents.h"
  382. #include "TimerEvents.h"
  383. #include "HistoryGprot.h"
  384. #include "SubLCDHistoryGprot.h"
  385. #include "wgui_categories.h"
  386. #include "wgui_status_icons.h"
  387. #include "wgui_categories_inputs.h"
  388. #include "gpioInc.h"
  389. #include "DateTimeGprot.h"
  390. #include "AlarmProt.h"
  391. #include "AlarmDef.h"
  392. #include "AlarmGProt.h"
  393. #include "AlarmFrameworkProt.h"
  394. #include "FileMgr.h"
  395. #include "ProfileGprots.h"
  396. #include "ProfileMgrGProt.h"
  397. #include "Profiles_prot.h"
  398. #include "KeyBrd.h"     /* for ClearKeyEvents */
  399. #include "Unicodexdcl.h"
  400. #include "CustDataRes.h"
  401. #include "DebugInitDef.h"
  402. #include "SettingProfile.h"
  403. #include "NVRAMEnum.h"
  404. #include "NVRAMType.h"
  405. #include "NVRAMProt.h"
  406. #include "AudioInc.h"
  407. #include "TimerEvents.h"
  408. #include "OrganizerDef.h"
  409. #include "ProfilesDefs.h"
  410. #include "WrapperGprot.h"
  411. #include "SimDetectionGexdcl.h"
  412. #include "ExtDeviceDefs.h"
  413. #include "CommonScreens.h"
  414. #include "Wgui_categories_popup.h"
  415. #include "Wgui_status_icons.h"
  416. #if defined(__MMI_DOWNLOADABLE_THEMES_SUPPORT__)
  417. #include "DownloadDefs.h"
  418. #include "DownloadProtos.h"
  419. #include "ThemeManager.h"
  420. #endif /* defined(__MMI_DOWNLOADABLE_THEMES_SUPPORT__) */ 
  421. #ifdef __MMI_ALM_AUDIO_OPTIONS__
  422. #include "FMRadioDef.h"
  423. #include "FMRadioType.h"
  424. #include "FMRadioProt.h"
  425. #include "MainMenuDef.h"
  426. #include "Aud_Defs.h"
  427. #include "FS_Type.h"
  428. #include "FS_Func.h"
  429. #include "conversions.h"
  430. #include "ScrMemMgrGProt.h"
  431. extern mmi_fmrdo_struct g_fmrdo;    /* defined in FMRadioSrc.c */
  432. extern pBOOL mmi_fmrdo_channel_list_item(S32 item_index, UI_string_type str_buff, PU8 *img_buff_p, U8 str_img_mask);
  433. extern S32 mmi_fmrdo_channel_list_item_hint(S32 item_index, UI_string_type *hint_array);
  434. extern void kal_wsprintf(unsigned short *outstr, char *fmt, ...);
  435. BOOL g_alm_aud_opt_selected = FALSE;
  436. extern U8 isEarphonePlugged;
  437. S8 *g_alm_audio_options_string[NUM_AUDIO_OPTIONS];  /* array to store the audio option strings */
  438. U16 g_alm_audio_options_curselitem[MAX_NAME_INPUT_LEN];
  439. S8 g_alm_aud_opt_curselitem_inline_index;
  440. S32 g_alm_audio_option_previndex;                   /* the index of the selected audio option i.e. FM or tone. */
  441. U8 g_alm_aud_opt_fmrdo_channel_index;
  442. U16 g_alm_aud_opt_fmrdo_channel_opt_index;
  443. U16 g_alm_fmrdo_man_inp_opt_index;
  444. U16 g_alm_fmrdo_prev_freq;
  445. static UI_character_type channel_manual_input_buffer[MAX_MANUAL_INPUT_LEN];
  446. static BOOL g_alm_fmrdo_read_channel_name = FALSE;
  447. #ifdef __MMI_PROFILE_EXTMELODY_SUPPORT__
  448. static PRFSET_MELODY_CONF_TYPE g_alm_tone_conf_type = 0;
  449. static U8 g_ext_melody_idx = 0;
  450. static U8 extMldHlitItem = 0;
  451. static U8* g_alm_ext_melody_short_name_ptr = NULL;
  452. #endif /* __MMI_PROFILE_EXTMELODY_SUPPORT__ */ 
  453. static S32 g_alm_tone_index;
  454. extern U8 mmi_profiles_get_melody_list(U16 CurMelodyID, U16 *selecteditem);
  455. extern U16 gstartRingId;
  456. extern U16 gtotalRingId;
  457. extern U16 gstartMidiId;
  458. extern U16 gtotalMidiId;
  459. extern U16 gcurrentaudioId;
  460. extern PROFILE gcurrentprofile;
  461. #endif /* __MMI_ALM_AUDIO_OPTIONS__ */ 
  462. /* 
  463.  * Define
  464.  */
  465. /* 
  466.  * Typedef 
  467.  */
  468. /* 
  469.  * Local Variable
  470.  */
  471. const U8 g_alm_freq_set[ALARM_FREQ_NUM] = {ALM_FREQ_ONCE, ALM_FREQ_EVERYDAY, ALM_FREQ_DAYS};
  472. /* 
  473.  * Local Function
  474.  */
  475. /* 
  476.  * Global Variable
  477.  */
  478. alm_context_struct g_alm_cntx;
  479. S8 *gAlmFreqList[ALM_FREQ_TOTAL];   /* array to store frequency type of alarm */
  480. S8 *gAlmOnOffString[NUM_STATE_FOR_ALM];  /* array to store on/off state of an alarm */
  481. U8 gAlmDaysStates[NUM_DAYS];                    /* signifies the days alarm has been set for in case of freq weekdays */
  482. #ifdef __MMI_ALM_CUST_VOLUME__
  483. S8 *gAlmVolumeList[LEVEL7 + 1];
  484. const S8 gAlmVolumeString[LEVEL7 + 1][4] = 
  485. {
  486.     {'1', 0, 0, 0},
  487.     {'2', 0, 0, 0},
  488.     {'3', 0, 0, 0},
  489.     {'4', 0, 0, 0},
  490.     {'5', 0, 0, 0},
  491.     {'6', 0, 0, 0},
  492.     {'7', 0, 0, 0}
  493. };
  494. #endif /* __MMI_ALM_CUST_VOLUME__ */ 
  495. #ifdef __MMI_ALM_SNOOZE_SETTING__
  496. S8 *gAlmSettingSnooze[ALM_SNOOZE_INTERVAL_SETTING_NUM];
  497. #endif 
  498. #ifdef __MMI_ALM_ALERT_TYPE__
  499. S8 *gAlmSettingAlertType[ALM_ALERT_TYPE_SETTING_NUM];
  500. #endif 
  501. extern wgui_inline_item wgui_inline_items[];
  502. /* 
  503.  * Global Function
  504.  */
  505. extern void AlarmDisplayCharging(void);
  506. extern void AudioPlayToneWithCallBackVolPath(U16 soundId, U8 style, U8 tone_type, U8 volume, U8 path);
  507. /*****************************************************************************
  508.  * FUNCTION
  509.  *  HighlightAlmMenu
  510.  * DESCRIPTION
  511.  *  Highlight handler of alarm menu item.
  512.  *  Register key handlers.
  513.  * PARAMETERS
  514.  *  void
  515.  * RETURNS
  516.  *  void
  517.  *****************************************************************************/
  518. void HighlightAlmMenu(void)
  519. {
  520.     /*----------------------------------------------------------------*/
  521.     /* Local Variables                                                */
  522.     /*----------------------------------------------------------------*/
  523.     /*----------------------------------------------------------------*/
  524.     /* Code Body                                                      */
  525.     /*----------------------------------------------------------------*/
  526.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  527.     SetLeftSoftkeyFunction(EntryAlmMenu, KEY_EVENT_UP);
  528.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  529.     SetKeyHandler(EntryAlmMenu, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  530.     g_alm_cntx.CurrHiliteAlarm = 0;
  531. }
  532. /*****************************************************************************
  533.  * FUNCTION
  534.  *  AlmInit
  535.  * DESCRIPTION
  536.  *  Initailization function. Set the highlight handlers and get required strings
  537.  * PARAMETERS
  538.  *  void
  539.  * RETURNS
  540.  *  void
  541.  *****************************************************************************/
  542. void AlmInit(void)
  543. {
  544.     /*----------------------------------------------------------------*/
  545.     /* Local Variables                                                */
  546.     /*----------------------------------------------------------------*/
  547.     /*----------------------------------------------------------------*/
  548.     /* Code Body                                                      */
  549.     /*----------------------------------------------------------------*/
  550.     SetHiliteHandler(ORGANIZER_ALARM_MENU, HighlightAlmMenu);
  551. }
  552. /*****************************************************************************
  553.  * FUNCTION
  554.  *  AlmExpiryTimeCBH
  555.  * DESCRIPTION
  556.  *  Callback handler to get information of alarm expiry setting.
  557.  * PARAMETERS
  558.  *  index           [IN]            
  559.  *  alarmTime       [?]             
  560.  *  Freq            [?]             
  561.  *  WeekDays        [?]             
  562.  *  MYTIME(?)       [IN/OUT]        Expiry time set by user
  563.  *  U8(?)           [IN/OUT]        Expiry days of week
  564.  * RETURNS
  565.  *  void
  566.  *****************************************************************************/
  567. void AlmExpiryTimeCBH(U8 index, MYTIME *alarmTime, U8 *Freq, U8 *WeekDays, MYTIME *preReminder)
  568. {
  569.     /*----------------------------------------------------------------*/
  570.     /* Local Variables                                                */
  571.     /*----------------------------------------------------------------*/
  572.     MYTIME currTime, incTime;
  573.     /*----------------------------------------------------------------*/
  574.     /* Code Body                                                      */
  575.     /*----------------------------------------------------------------*/
  576.     DTGetRTCTime(&currTime);
  577. alarmTime->nYear = currTime.nYear;
  578.     alarmTime->nMonth = currTime.nMonth;
  579.     alarmTime->nDay = currTime.nDay;
  580. alarmTime->DayIndex = DOW(alarmTime->nYear, alarmTime->nMonth, alarmTime->nDay);
  581.     alarmTime->nHour = g_alm_cntx.AlmList[index].Hour;
  582.     alarmTime->nMin = g_alm_cntx.AlmList[index].Min;
  583.     *Freq = g_alm_freq_set[g_alm_cntx.AlmList[index].Freq];
  584.     *WeekDays = g_alm_cntx.AlmList[index].Days;
  585.     if (g_alm_cntx.AlmList[index].Snooze)
  586.     {
  587.         memset(&incTime, 0, sizeof(MYTIME));
  588.         incTime.nMin = AlmGetSnoozeInterval(index);  /* ALM_SNOOZE_INTERVAL; */
  589.         IncrementTime(currTime, incTime, alarmTime);
  590.     }
  591. }
  592. /*****************************************************************************
  593.  * FUNCTION
  594.  *  AlmReInitQueueCBH
  595.  * DESCRIPTION
  596.  *  Callback handler of reiniting alarm to alarm queue.
  597.  * PARAMETERS
  598.  *  void
  599.  * RETURNS
  600.  *  void
  601.  *****************************************************************************/
  602. void AlmReInitQueueCBH(void)
  603. {
  604.     /*----------------------------------------------------------------*/
  605.     /* Local Variables                                                */
  606.     /*----------------------------------------------------------------*/
  607.     U8 i;
  608.     /*----------------------------------------------------------------*/
  609.     /* Code Body                                                      */
  610.     /*----------------------------------------------------------------*/
  611.     for (i = 0; i < NUM_OF_ALM; i++)
  612.     {
  613.         g_alm_cntx.AlmList[i].Snooze = 0;
  614.         if (g_alm_cntx.AlmList[i].State == 1)
  615.         {
  616.             AlmInsertIntoQueue((U8) (i + ALM_ALM_START), FALSE);
  617.         }
  618.     }
  619. }
  620. /*****************************************************************************
  621.  * FUNCTION
  622.  *  AlmExpiryHandlerCB
  623.  * DESCRIPTION
  624.  *  CallBack handler to execute alarm expiry.
  625.  * PARAMETERS
  626.  *  index           [IN]        
  627.  *  period          [?]         
  628.  *  power_on        [IN]        
  629.  *  BOOL(?)         [IN]        Power status
  630.  *  U8(?)           [IN]        Index of alarm item
  631.  * RETURNS
  632.  *  void
  633.  *****************************************************************************/
  634. U8 AlmExpiryHandlerCB(U8 index, U16 *period, BOOL power_on)
  635. {
  636.     /*----------------------------------------------------------------*/
  637.     /* Local Variables                                                */
  638.     /*----------------------------------------------------------------*/
  639.     /*----------------------------------------------------------------*/
  640.     /* Code Body                                                      */
  641.     /*----------------------------------------------------------------*/
  642.     *period = ALM_DEFAULT_EXPIRY_PERIOD;
  643.     /* For the situation of taking off the battery during alarm working.*/
  644.     if (g_alm_freq_set[g_alm_cntx.AlmList[index].Freq] == ALM_FREQ_ONCE)        /* reset the alarm state */
  645.     {
  646.         g_alm_cntx.AlmList[index].State = UNSET_STATE;
  647.         AlmWriteToNvram();
  648.     }
  649.     if (power_on)
  650.     {
  651.         update_mainlcd_dt_display();
  652.         EntryAlmIndicationScreen();
  653.     }
  654.     else
  655.     {
  656.         AlmInitLCDModule();
  657.         EntryAlmIndicationScreen();
  658.         g_pwr_context.PowerOnMMIStatus = MMI_POWER_ON_IDLE; /* 0x80: Alarm idle screen */
  659.     }
  660.     return ALM_HAS_IND;
  661. }
  662. /*****************************************************************************
  663.  * FUNCTION
  664.  *  AlmFCBInit
  665.  * DESCRIPTION
  666.  *  Set callback function needed by alarm framework
  667.  * PARAMETERS
  668.  *  void
  669.  * RETURNS
  670.  *  void
  671.  *****************************************************************************/
  672. void AlmFCBInit(void)
  673. {
  674.     /*----------------------------------------------------------------*/
  675.     /* Local Variables                                                */
  676.     /*----------------------------------------------------------------*/
  677.     /*----------------------------------------------------------------*/
  678.     /* Code Body                                                      */
  679.     /*----------------------------------------------------------------*/
  680.     mmi_alm_set_start_index(ALM_TYPE_ALARM, ALM_ALM_START);
  681.     AlmSetExpiryTimeCB(ALM_TYPE_ALARM, AlmExpiryTimeCBH);
  682.     AlmSetExpiryHandlerCB(ALM_TYPE_ALARM, AlmExpiryHandlerCB);
  683.     AlmSetInitHandlerCB(ALM_TYPE_ALARM, AlmInitNvram, AlmReInitQueueCBH);
  684.     AlmSetStopAlarmCB(ALM_TYPE_ALARM, AlmSnoozeHandler);
  685. }
  686. /*****************************************************************************
  687.  * FUNCTION
  688.  *  AlarmDeInit
  689.  * DESCRIPTION
  690.  *  Deinitailization function of alarm application.
  691.  * PARAMETERS
  692.  *  void
  693.  * RETURNS
  694.  *  void
  695.  *****************************************************************************/
  696. void AlarmDeInit()
  697. {
  698.     /*----------------------------------------------------------------*/
  699.     /* Local Variables                                                */
  700.     /*----------------------------------------------------------------*/
  701.     /*----------------------------------------------------------------*/
  702.     /* Code Body                                                      */
  703.     /*----------------------------------------------------------------*/
  704. }
  705. /*****************************************************************************
  706.  * FUNCTION
  707.  *  AlmInitNvram
  708.  * DESCRIPTION
  709.  *  Gets the information from NVRAM
  710.  * PARAMETERS
  711.  *  void
  712.  * RETURNS
  713.  *  void
  714.  *****************************************************************************/
  715. void AlmInitNvram(void)
  716. {
  717.     /*----------------------------------------------------------------*/
  718.     /* Local Variables                                                */
  719.     /*----------------------------------------------------------------*/
  720.     S16 error;
  721.     U8 nvram_buf[NVRAM_ALM_ALARM_DATA_SIZE];
  722. #ifdef MMI_ON_WIN32
  723.     S32 i;
  724. #endif 
  725.     /*----------------------------------------------------------------*/
  726.     /* Code Body                                                      */
  727.     /*----------------------------------------------------------------*/
  728.     ReadRecord(NVRAM_EF_ALM_ALARM_DATA_LID, 1, (void*)nvram_buf, NVRAM_ALM_ALARM_DATA_SIZE, &error);
  729.     memcpy(g_alm_cntx.AlmList, nvram_buf, sizeof(g_alm_cntx.AlmList));
  730. #ifdef MMI_ON_WIN32
  731.     for (i = 0; i < NUM_OF_ALM; i++)
  732.     {
  733.         if (g_alm_cntx.AlmList[i].Hour > 23 || g_alm_cntx.AlmList[i].Min > 59)
  734.         {
  735.             memset(&g_alm_cntx.AlmList[i], 0x0, sizeof(alm_nvram_struct));
  736.         }
  737.     }
  738. #endif /* MMI_ON_WIN32 */ 
  739.     if (AlmIsAnyAlarmActivated())
  740.     {
  741.         AlmActivateIndicator();
  742.     }
  743.     else
  744.     {
  745.         AlmDeactivateIndicator();
  746.     }
  747. }
  748. /*****************************************************************************
  749.  * FUNCTION
  750.  *  HighlightAlmIndex
  751.  * DESCRIPTION
  752.  *  Highlight handler of alarm item in alarm screen.
  753.  *  Store current highlight index.
  754.  * PARAMETERS
  755.  *  nIndex      [IN]        
  756.  *  S32(?)      [IN]        Index of current highlighted item
  757.  * RETURNS
  758.  *  void
  759.  *****************************************************************************/
  760. void HighlightAlmIndex(S32 nIndex)
  761. {
  762.     /*----------------------------------------------------------------*/
  763.     /* Local Variables                                                */
  764.     /*----------------------------------------------------------------*/
  765.     /*----------------------------------------------------------------*/
  766.     /* Code Body                                                      */
  767.     /*----------------------------------------------------------------*/
  768.     g_alm_cntx.CurrHiliteAlarm = (U8) nIndex;
  769. }
  770. /*****************************************************************************
  771.  * FUNCTION
  772.  *  EntryAlmMenu
  773.  * DESCRIPTION
  774.  *  Entry function of Alarm application
  775.  * PARAMETERS
  776.  *  void
  777.  * RETURNS
  778.  *  void
  779.  *****************************************************************************/
  780. void EntryAlmMenu(void)
  781. {
  782.     /*----------------------------------------------------------------*/
  783.     /* Local Variables                                                */
  784.     /*----------------------------------------------------------------*/
  785.     U8 *guiBuffer;
  786.     S32 i;
  787.     U16 alarm_states_icon[NUM_OF_ALM];
  788.     MYTIME almTime;
  789.     /*----------------------------------------------------------------*/
  790.     /* Code Body                                                      */
  791.     /*----------------------------------------------------------------*/
  792.     /* Use FM radio list before FM radio initialize */
  793. #ifdef __MMI_ALM_AUDIO_OPTIONS__
  794.     mmi_alm_aud_fmrdo_init_channe_list();
  795. #endif 
  796.     EntryNewScreen(SCR_ID_ALM_LIST, NULL, EntryAlmMenu, NULL);
  797.     guiBuffer = GetCurrGuiBuffer(SCR_ID_ALM_LIST);
  798.     if (guiBuffer == NULL)
  799.     {
  800.         g_alm_cntx.CurrHiliteAlarm = 0;
  801.     }
  802.     g_alm_cntx.IsDOWSet = 0;
  803.     /* construct displayed string and icon */
  804.     for (i = 0; i < NUM_OF_ALM; i++)
  805.     {
  806.         almTime.nHour = g_alm_cntx.AlmList[i].Hour;
  807.         almTime.nMin = g_alm_cntx.AlmList[i].Min;
  808.         time_string(&almTime, (UI_string_type) subMenuDataPtrs[i], DT_IDLE_SCREEN);
  809.         if (g_alm_cntx.AlmList[i].State == SET_STATE)
  810.         {
  811.             alarm_states_icon[i] = CHECKBOX_ON_IMAGE_ID;
  812.         }
  813.         else
  814.         {
  815.             alarm_states_icon[i] = CHECKBOX_OFF_IMAGE_ID;
  816.         }
  817.     }
  818.     wgui_override_list_menu_slim_style(WGUI_LIST_MENU_SLIM_STYLE_DRAW_ICON);
  819.     ShowCategory53Screen(
  820.         ORGANIZER_MENU_ALARMS_STRINGID,
  821.         GetRootTitleIcon(ORGANIZER_ALARM_MENU),
  822.         ALARMS_EDIT_SOFTKEY_STRINGID,
  823.         ALARMS_EDIT_SOFTKEY_IMAGEID,
  824.         STR_GLOBAL_BACK,
  825.         IMG_GLOBAL_BACK,
  826.         NUM_OF_ALM,
  827.         subMenuDataPtrs,
  828.         alarm_states_icon,
  829.         0,
  830.         0,
  831.         (S32) g_alm_cntx.CurrHiliteAlarm,
  832.         guiBuffer);
  833.     wgui_restore_list_menu_slim_style();
  834.     SetLeftSoftkeyFunction(AlmPrepareInlineScreen, KEY_EVENT_UP);
  835.     SetKeyHandler(AlmPrepareInlineScreen, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  836.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  837.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  838.     RegisterHighlightHandler(HighlightAlmIndex);
  839. }
  840. /*****************************************************************************
  841.  * FUNCTION
  842.  *  AlmGoBackAlarmMenu
  843.  * DESCRIPTION
  844.  *  Go back to alarm menu list.
  845.  * PARAMETERS
  846.  *  void
  847.  * RETURNS
  848.  *  void
  849.  *****************************************************************************/
  850. void AlmGoBackAlarmMenu(void)
  851. {
  852.     /*----------------------------------------------------------------*/
  853.     /* Local Variables                                                */
  854.     /*----------------------------------------------------------------*/
  855.     /*----------------------------------------------------------------*/
  856.     /* Code Body                                                      */
  857.     /*----------------------------------------------------------------*/
  858.     GoBackToHistory(SCR_ID_ALM_LIST);
  859. }
  860. /*****************************************************************************
  861.  * FUNCTION
  862.  *  EntryAlmSaveConfirmation
  863.  * DESCRIPTION
  864.  *  Display confirmation screen for setting alarm.
  865.  * PARAMETERS
  866.  *  void
  867.  * RETURNS
  868.  *  void
  869.  *****************************************************************************/
  870. void EntryAlmSaveConfirmation(void)
  871. {
  872. #ifdef __MMI_ALM_AUDIO_OPTIONS__
  873.     /*----------------------------------------------------------------*/
  874.     /* Local Variables                                                */
  875.     /*----------------------------------------------------------------*/
  876.     /*----------------------------------------------------------------*/
  877.     /* Code Body                                                      */
  878.     /*----------------------------------------------------------------*/
  879.     if ((!
  880.          ((g_alm_cntx.CurrHiliteAudioOption && g_alm_audio_option_previndex) ||
  881.           (!g_alm_cntx.CurrHiliteAudioOption && !g_alm_audio_option_previndex))) ||
  882.         (g_alm_cntx.CurrHiliteAudioOptionValue == 0))
  883.     {
  884.         DisplayConfirm(
  885.             STR_GLOBAL_OK,
  886.             IMG_GLOBAL_OK,
  887.             0,
  888.             0,
  889.             get_string(STR_ID_ALM_FMRDO_AUD_OPT_INCOMPLETE_NOTIFY),
  890.             0,
  891.             WARNING_TONE);
  892.         SetLeftSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  893.         return;
  894.     }
  895.     /* check if the currently selected option is ALM_AUDIO_OPTIONS_FMRADIO_CHANNEL and some channel is selected for it */
  896.     if (g_alm_cntx.CurrHiliteAudioOption == ALM_AUDIO_OPTIONS_FMRADIO_CHANNEL)
  897.     {
  898.         U16 index;
  899.         BOOL valid_chan = TRUE;
  900.         if (g_alm_cntx.CurrHiliteAudioOptionValue == 0 || g_alm_cntx.CurrHiliteAudioOptionValue > FM_RADIO_CHANNEL_NUM)
  901.         {
  902.             valid_chan = FALSE;
  903.         }
  904.         else
  905.         {
  906.             index = g_alm_cntx.CurrHiliteAudioOptionValue - 1;
  907.             if (g_fmrdo.channel_list.freq[index] < MIN_FM_FREQUENCY ||
  908.                 g_fmrdo.channel_list.freq[index] > MAX_FM_FREQUENCY)
  909.             {
  910.                 valid_chan = FALSE;
  911.             }
  912.         }
  913.         if (!valid_chan)
  914.         {
  915.             DisplayConfirm(
  916.                 STR_GLOBAL_OK,
  917.                 IMG_GLOBAL_OK,
  918.                 0,
  919.                 0,
  920.                 get_string(STR_ID_ALM_FMRDO_INCOMPLETE_CHANNEL_INFO),
  921.                 0,
  922.                 WARNING_TONE);
  923.             SetLeftSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  924.             return;
  925.         }
  926.     }
  927. #endif /* __MMI_ALM_AUDIO_OPTIONS__ */ 
  928.     DisplayConfirm(
  929.         STR_GLOBAL_YES,
  930.         IMG_GLOBAL_YES,
  931.         STR_GLOBAL_NO,
  932.         IMG_GLOBAL_NO,
  933.         get_string(STR_GLOBAL_SAVE),
  934.         IMG_GLOBAL_QUESTION,
  935.         WARNING_TONE);
  936.     SetLeftSoftkeyFunction(AlmSaveInlineEdit, KEY_EVENT_UP);
  937.     SetRightSoftkeyFunction(AlmGoBackAlarmMenu, KEY_EVENT_UP);
  938. }
  939. /*****************************************************************************
  940.  * FUNCTION
  941.  *  AlmPrepareInlineScreen
  942.  * DESCRIPTION
  943.  *  This fuction builds the display information of the selected alarm, and then enter
  944.  *  alarm screen.
  945.  * PARAMETERS
  946.  *  void
  947.  * RETURNS
  948.  *  void
  949.  *****************************************************************************/
  950. void AlmPrepareInlineScreen(void)
  951. {
  952.     /*----------------------------------------------------------------*/
  953.     /* Local Variables                                                */
  954.     /*----------------------------------------------------------------*/
  955.     S32 i, j;
  956.     /*----------------------------------------------------------------*/
  957.     /* Code Body                                                      */
  958.     /*----------------------------------------------------------------*/
  959.     i = g_alm_cntx.CurrHiliteAlarm;
  960.     /* fill inline selection strings */
  961.     gAlmOnOffString[0] = GetString(STR_GLOBAL_OFF);
  962.     gAlmOnOffString[1] = GetString(STR_GLOBAL_ON);
  963. #ifdef __MMI_ALM_AUDIO_OPTIONS__
  964.     g_alm_audio_options_string[0] = GetString(STR_ID_ALM_AUDIO_OPTIONS_TONE);
  965.     g_alm_audio_options_string[1] = GetString(STR_ID_ALM_AUDIO_OPTIONS_FMRADIO);
  966. #endif /* __MMI_ALM_AUDIO_OPTIONS__ */ 
  967.     /* time string */
  968.     AlmGetStringValue(g_alm_cntx.HourBuf, g_alm_cntx.AlmList[i].Hour);
  969.     AlmGetStringValue(g_alm_cntx.MinBuf, g_alm_cntx.AlmList[i].Min);
  970.     g_alm_cntx.CurrHiliteState = g_alm_cntx.AlmList[i].State;
  971.     g_alm_cntx.CurrHiliteFreq = g_alm_cntx.AlmList[i].Freq;
  972. #ifdef __MMI_ALM_CUST_VOLUME__
  973.     g_alm_cntx.CurrHiliteVol = g_alm_cntx.AlmList[i].Volume;
  974. #endif 
  975.     if (g_alm_freq_set[g_alm_cntx.CurrHiliteFreq] == ALM_FREQ_DAYS)     /* not Days */
  976.     {
  977.         for (j = 0; j < NUM_DAYS; j++)
  978.         {
  979.             gAlmDaysStates[j] = ((((g_alm_cntx.AlmList[i].Days) & (0x1 << j)) == 0) ? 0 : 1);
  980.         }
  981.     }
  982.     else
  983.     {
  984.         memset(gAlmDaysStates, 0, 7);
  985.     }
  986.     /* Audio options in alarm */
  987. #ifdef __MMI_ALM_AUDIO_OPTIONS__
  988.     g_alm_cntx.CurrHiliteAudioOption = g_alm_cntx.AlmList[i].AudioOption;
  989.     if (g_alm_cntx.CurrHiliteAudioOption == ALM_AUDIO_OPTIONS_FMRADIO_CHANNEL)
  990.     {
  991.         U16 freq = 0;
  992.         U16 index = g_alm_cntx.CurrHiliteAudioOptionValue = g_alm_cntx.AlmList[i].AudioOptionValue;
  993.         if ((index > 0) && (index <= FM_RADIO_CHANNEL_NUM))
  994.         {
  995.             freq = g_fmrdo.channel_list.freq[index - 1];
  996.         }
  997.         /* In valid frequency, restore to default ring tone */
  998.         if ((freq < MIN_FM_FREQUENCY) || (freq > MAX_FM_FREQUENCY))
  999.         {
  1000.             g_alm_cntx.CurrHiliteAudioOption = ALM_AUDIO_OPTIONS_TONE;
  1001.             g_alm_cntx.CurrHiliteAudioOptionValue = (U16) (gstartMidiId + 1);
  1002.         }
  1003.     }
  1004.     else if (g_alm_cntx.CurrHiliteAudioOption == ALM_AUDIO_OPTIONS_FMRADIO_MANUAL)
  1005.     {
  1006.         g_alm_cntx.CurrHiliteAudioOptionValue = g_alm_cntx.AlmList[i].AudioOptionValue;
  1007.     }
  1008.     else    /* ALM_AUDIO_OPTIONS_TONE */
  1009.     {
  1010.     #ifdef __MMI_ALM_CUSTOMIZE_TONE__
  1011.         if (g_alm_cntx.AlmList[i].AudioOptionValue > 0)
  1012.         {
  1013.             g_alm_cntx.CurrHiliteAudioOptionValue = g_alm_cntx.AlmList[i].AudioOptionValue;
  1014.         }
  1015.         else
  1016.         {
  1017.             g_alm_cntx.CurrHiliteAudioOptionValue = (U16) (gstartMidiId + 1);
  1018.         }
  1019.     #else /* __MMI_ALM_CUSTOMIZE_TONE__ */ 
  1020.         g_alm_cntx.CurrHiliteAudioOptionValue = gcurrentprofile.toneSetup.alarmTone;
  1021.     #endif /* __MMI_ALM_CUSTOMIZE_TONE__ */ 
  1022.     }
  1023. #endif /* __MMI_ALM_AUDIO_OPTIONS__ */ 
  1024. #ifdef __MMI_ALM_SNOOZE_SETTING__
  1025.     g_alm_cntx.CurrHilightSnoozeInterval = g_alm_cntx.AlmList[i].SnoozeInterval;
  1026. #endif 
  1027. #ifdef __MMI_ALM_ALERT_TYPE__
  1028.     g_alm_cntx.CurrHilightAlertType = g_alm_cntx.AlmList[i].AlertType;
  1029. #endif 
  1030.     EntryAlmEditScreen();
  1031. }
  1032. #ifdef __MMI_ALM_CUST_VOLUME__
  1033. /*****************************************************************************
  1034.  * FUNCTION
  1035.  *  AlmPlayAlarmToneWithVol
  1036.  * DESCRIPTION
  1037.  *  Play alarm tone with setting volume level.
  1038.  * PARAMETERS
  1039.  *  volume      [IN]        
  1040.  *  U8(?)       [IN]        Volumn level
  1041.  * RETURNS
  1042.  *  void
  1043.  *****************************************************************************/
  1044. void AlmPlayAlarmToneWithVol(U8 volume)
  1045. {
  1046.     /*----------------------------------------------------------------*/
  1047.     /* Local Variables                                                */
  1048.     /*----------------------------------------------------------------*/
  1049.     /*----------------------------------------------------------------*/
  1050.     /* Code Body                                                      */
  1051.     /*----------------------------------------------------------------*/
  1052.     if (g_alm_frm_cntx.IsAlmTonePlaying == FALSE)
  1053.     {
  1054.     #ifdef __MMI_PROFILE_ALERT_TYPE_DOMINANT__
  1055.         U8 alert_type = GetMtCallAlertTypeEnum();
  1056.     #endif 
  1057.         VibratorOn();
  1058.     #ifdef __MMI_PROFILE_ALERT_TYPE_DOMINANT__
  1059.         if (alert_type != MMI_VIBRATION_ONLY && alert_type != MMI_SILENT)
  1060.     #endif 
  1061.         {
  1062.             /* Added support for Alarm Audio Options i.e. FM Radio as alarm tone. */
  1063.         #ifdef __MMI_ALM_AUDIO_OPTIONS__
  1064.             if (g_alm_frm_cntx.CurrAlmIndex >= ALM_ALM_START && g_alm_frm_cntx.CurrAlmIndex < ALM_SPOF_START)
  1065.             {
  1066.                 U8 alarm_index = g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START;
  1067.                 if (g_alm_cntx.AlmList[alarm_index].AudioOption == ALM_AUDIO_OPTIONS_TONE)
  1068.                 {
  1069.                 #ifdef __MMI_ALM_CUSTOMIZE_TONE__
  1070.                     AudioPlayToneWithCallBackVolPath(
  1071.                         g_alm_cntx.AlmList[g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START].AudioOptionValue,  /* current profile alarm tone id */
  1072.                         DEVICE_AUDIO_PLAY_INFINITE,
  1073.                         ALARM_TONE,
  1074.                         volume,             /* your volume level 0~6 */
  1075.                         MDI_DEVICE_SPEAKER_BOTH);
  1076.                 #else /* __MMI_ALM_CUSTOMIZE_TONE__ */ 
  1077.                     AudioPlayToneWithCallBackVolPath(
  1078.                         GetAlarmToneType(), /* current profile alarm tone id */
  1079.                         DEVICE_AUDIO_PLAY_INFINITE,
  1080.                         ALARM_TONE,
  1081.                         volume,             /* your volume level 0~6 */
  1082.                         MDI_DEVICE_SPEAKER_BOTH);
  1083.                 #endif /* __MMI_ALM_CUSTOMIZE_TONE__ */ 
  1084.                 }
  1085.                 else
  1086.                 {
  1087.                     mmi_alm_aud_fmrdo_play_alarm(alarm_index, volume);
  1088.                 }
  1089.             }
  1090.             else
  1091.         #endif /* __MMI_ALM_AUDIO_OPTIONS__ */ 
  1092.             {
  1093.                 AudioPlayToneWithCallBackVolPath(
  1094.                     GetAlarmToneType(), /* current profile alarm tone id */
  1095.                     DEVICE_AUDIO_PLAY_INFINITE,
  1096.                     ALARM_TONE,
  1097.                     volume,             /* your volume level 0~6 */
  1098.                     MDI_DEVICE_SPEAKER_BOTH);
  1099.             }
  1100.         }
  1101.         g_alm_frm_cntx.IsAlmTonePlaying = TRUE;
  1102.     }
  1103. }
  1104. #endif /* __MMI_ALM_CUST_VOLUME__ */ 
  1105. /*****************************************************************************
  1106.  * FUNCTION
  1107.  *  EntryAlmIndicationScreen
  1108.  * DESCRIPTION
  1109.  *  Display indication screen and play alarm tone when alarm expires.
  1110.  * PARAMETERS
  1111.  *  void
  1112.  * RETURNS
  1113.  *  void
  1114.  *****************************************************************************/
  1115.  #ifdef IS_VSMJ_BASE_GAME  //jerson add 20070619
  1116. extern BOOL mmi_gx_vsmj_getplaystate(void);     //KP Jerry add for avoid screen-display-error when vsmj is playing on 2007-3-24
  1117. #endif
  1118. void EntryAlmIndicationScreen(void)
  1119. {
  1120.     /*----------------------------------------------------------------*/
  1121.     /* Local Variables                                                */
  1122.     /*----------------------------------------------------------------*/
  1123.     U8 *guiBuffer;
  1124.     MYTIME currTime;
  1125.     U8 timeString[SIZE_OF_DATE_STRING];
  1126.     static U8 dateString[SIZE_OF_ALARM_STRING + SIZE_OF_DATE_STRING];
  1127.     U8 almindex = g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START;
  1128.     /*----------------------------------------------------------------*/
  1129.     /* Code Body                                                      */
  1130.     /*----------------------------------------------------------------*/
  1131. //KP Jerry add for avoid screen-display-error when vsmj is playing on 2007-3-24 start
  1132. #ifdef IS_VSMJ_BASE_GAME  //jerson add 20070619
  1133.     if(mmi_gx_vsmj_getplaystate())
  1134.     {
  1135.     GoBackHistory();
  1136.     }
  1137. #endif
  1138. //KP Jerry add for avoid screen-display-error when vsmj is playing on 2007-3-24 end
  1139.     StopTimer(ALARM_TIMER_WAIT_FOR_CALL);
  1140.     if (!IsMyTimerExist(ALARM_ALERT_NOTIFYDURATION_TIMER))
  1141.     {
  1142.         StartTimer(ALARM_ALERT_NOTIFYDURATION_TIMER, ALM_EXPIRE_DURATION, AlmHandleAlarmTimeout);
  1143.     }
  1144.     EntryNewScreen(SCR_ID_ALM_INDICATION, ExitAlmIndicationScreen, NULL, NULL);
  1145.     GetDateTime(&currTime);
  1146.     time_string(&currTime, (UI_string_type) timeString, DT_IDLE_SCREEN);
  1147.     /* prepare string to display */
  1148.     if (g_alm_frm_cntx.CurrAlmIndex == ALM_FACTORY)
  1149.     {
  1150.         memset(dateString, 0, ENCODING_LENGTH);
  1151.         pfnUnicodeStrcpy((S8*) dateString, (S8*) L"n");
  1152.         pfnUnicodeStrcat((S8*) dateString, (S8*) GetString(ALARMS_POWER_ON));
  1153.         pfnUnicodeStrcat((S8*) dateString, (S8*) L"?");
  1154.     }
  1155.     else
  1156.     {
  1157.         date_string(&currTime, (UI_string_type) dateString, DT_IDLE_SCREEN);
  1158.         pfnUnicodeStrcat((S8*) dateString, (S8*) L"n");
  1159.         pfnUnicodeStrcat((S8*) dateString, (S8*) timeString);
  1160.     }
  1161.     /* flush key because alarm if some key is not released, the alarm may be stopped */
  1162.     ClearKeyEvents();
  1163.     g_alm_cntx.IsSaveToHistory = 1;
  1164.     guiBuffer = GetCurrGuiBuffer(SCR_ID_ALM_INDICATION);
  1165. #ifdef __MMI_ALM_CUST_VOLUME__
  1166.     if (g_alm_frm_cntx.CurrAlmIndex != ALM_FACTORY)
  1167.     {
  1168.         AlmPlayAlarmToneWithVol(g_alm_cntx.AlmList[almindex].Volume);
  1169.     }
  1170.     else
  1171. #endif /* __MMI_ALM_CUST_VOLUME__ */ 
  1172.     {
  1173.         AlmPlayAlarmTone();
  1174.     }
  1175.     ShowCategory121Screen(
  1176.         ALARMS_STOP_STRINGID,
  1177.         ALARMS_STOP_IMAGEID,
  1178.         ALARMS_SNOOZE_STRINGID,
  1179.         ALARMS_SNOOZE_IMAGEID,
  1180.         dateString,
  1181.         ALARM_ANIMATION_INDICATION_IMAGEID,
  1182.         guiBuffer,
  1183.         1);
  1184.     TurnOnBacklight(1);
  1185.     if (g_alm_frm_cntx.CurrAlmIndex == ALM_FACTORY)
  1186.     {
  1187.         ChangeLeftSoftkey(STR_GLOBAL_YES, IMG_GLOBAL_YES);
  1188.         ChangeRightSoftkey(STR_GLOBAL_NO, IMG_GLOBAL_NO);
  1189.         SetLeftSoftkeyFunction(AlmSendPowerOn, KEY_EVENT_UP);
  1190.         SetRightSoftkeyFunction(AlmSendPowerOff, KEY_EVENT_UP);
  1191.     }
  1192.     else
  1193.     {
  1194.         if (g_alm_cntx.AlmList[almindex].Snooze >= MAX_SNOOZE_CHANCES)
  1195.         {
  1196.             ChangeRightSoftkey(0, 0);
  1197.         }
  1198.         else
  1199.         {
  1200.             SetRightSoftkeyFunction(AlmSnoozeHandler, KEY_EVENT_UP);
  1201.         #if defined(__MMI_ALARM_SIDE_KEY_CONTROL__)
  1202.             SetKeyHandler(AlmSnoozeHandler, KEY_VOL_DOWN, KEY_EVENT_DOWN);
  1203.         #endif 
  1204.         }
  1205.         SetLeftSoftkeyFunction(AlmStopHandler, KEY_EVENT_UP);
  1206.         SetKeyHandler(AlmStopHandler, KEY_END, KEY_EVENT_DOWN); /* SetKeyHandler(AlarmEndKeyPressed,KEY_END,KEY_EVENT_DOWN); */
  1207.     #if defined(__MMI_ALARM_SIDE_KEY_CONTROL__)
  1208.         SetKeyHandler(AlmStopHandler, KEY_VOL_UP, KEY_EVENT_DOWN);
  1209.     #endif 
  1210.     }
  1211.     ForceSubLCDScreen(EntryAlmSubLcdScreen);
  1212.     /* register END key for power on alarm */
  1213.     if (g_alm_frm_cntx.IsPwronAlarm)
  1214.     {
  1215.         ClearKeyHandler(KEY_END, KEY_EVENT_UP);
  1216.         ClearKeyHandler(KEY_END, KEY_EVENT_DOWN);
  1217.     #ifdef __MMI_POWER_ON_OFF_BY_POWER_KEY__     
  1218.      ClearKeyHandler(KEY_END, KEY_LONG_PRESS);
  1219.     
  1220.         ClearKeyHandler(KEY_POWER, KEY_EVENT_UP);
  1221.         ClearKeyHandler(KEY_POWER, KEY_EVENT_DOWN);
  1222.         SetKeyHandler(AlmHandleEndKey, KEY_POWER, KEY_LONG_PRESS);                
  1223.     #else
  1224.      SetKeyHandler(AlmHandleEndKey, KEY_END, KEY_LONG_PRESS);
  1225.     #endif
  1226.         if (g_charbat_context.isChargerConnected && (!g_charbat_context.ChargingComplete))
  1227.         {
  1228.             AnimateStatusIcon(STATUS_ICON_BATTERY_STRENGTH);
  1229.             AnimateStatusIcon(STATUS_ICON_SUBLCD_BATTERY_STRENGTH);
  1230.             UpdateStatusIcons();
  1231.         }
  1232.     }
  1233. #ifdef MMI_ON_WIN32
  1234.     SetRightSoftkeyFunction(PopupNoSupport, KEY_EVENT_UP);
  1235. #endif 
  1236. }
  1237. /*****************************************************************************
  1238.  * FUNCTION
  1239.  *  AlmHandleEndKey
  1240.  * DESCRIPTION
  1241.  *  End key handler of alarm indication screen.
  1242.  * PARAMETERS
  1243.  *  void
  1244.  * RETURNS
  1245.  *  void
  1246.  *****************************************************************************/
  1247. void AlmHandleEndKey(void)
  1248. {
  1249.     /*----------------------------------------------------------------*/
  1250.     /* Local Variables                                                */
  1251.     /*----------------------------------------------------------------*/
  1252.     S32 i;
  1253.     /*----------------------------------------------------------------*/
  1254.     /* Code Body                                                      */
  1255.     /*----------------------------------------------------------------*/
  1256.     i = g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START;
  1257.     AlmsStopAlarmTone();
  1258.     g_alm_cntx.AlmList[i].Snooze = 0;
  1259.     if (g_alm_freq_set[g_alm_cntx.AlmList[i].Freq] == ALM_FREQ_ONCE)    /* reset the alarm state */
  1260.     {
  1261.         g_alm_cntx.AlmList[i].State = UNSET_STATE;
  1262.     }
  1263.     AlmWriteToNvram();
  1264.     AlmSendPowerOn();
  1265. }
  1266. /*****************************************************************************
  1267.  * FUNCTION
  1268.  *  ExitAlmIndicationScreen
  1269.  * DESCRIPTION
  1270.  *  Exit function of alarm indication screen.
  1271.  *  If exits screen because of interrupts, add screen to history.
  1272.  * PARAMETERS
  1273.  *  void
  1274.  * RETURNS
  1275.  *  void
  1276.  *****************************************************************************/
  1277. void ExitAlmIndicationScreen(void)
  1278. {
  1279.     /*----------------------------------------------------------------*/
  1280.     /* Local Variables                                                */
  1281.     /*----------------------------------------------------------------*/
  1282.     /*----------------------------------------------------------------*/
  1283.     /* Code Body                                                      */
  1284.     /*----------------------------------------------------------------*/
  1285.     AlmsStopAlarmTone();
  1286.     if (g_alm_cntx.IsSaveToHistory) /* add screen to history */
  1287.     {
  1288.         GenericExitScreen(SCR_ID_ALM_INDICATION, EntryAlmIndicationScreen);
  1289.     }
  1290. }
  1291. /*****************************************************************************
  1292.  * FUNCTION
  1293.  *  EntryAlmSubLcdScreen
  1294.  * DESCRIPTION
  1295.  *  Display sub-lcd screen when alarm expires.
  1296.  * PARAMETERS
  1297.  *  void
  1298.  * RETURNS
  1299.  *  void
  1300.  *****************************************************************************/
  1301. void EntryAlmSubLcdScreen(void)
  1302. {
  1303.     /*----------------------------------------------------------------*/
  1304.     /* Local Variables                                                */
  1305.     /*----------------------------------------------------------------*/
  1306.     /*----------------------------------------------------------------*/
  1307.     /* Code Body                                                      */
  1308.     /*----------------------------------------------------------------*/
  1309.     ExecSubLCDCurrExitHandler();
  1310.     ShowCategory304Screen(ALARM_ANIMATION_INDICATION_SUBLCD_IMAGEID, 0);
  1311. }
  1312. /*****************************************************************************
  1313.  * FUNCTION
  1314.  *  ExitAlmSubLcdScreen
  1315.  * DESCRIPTION
  1316.  *  Exit function of EntryAlmSubLcdScreen
  1317.  * PARAMETERS
  1318.  *  void
  1319.  * RETURNS
  1320.  *  void
  1321.  *****************************************************************************/
  1322. void ExitAlmSubLcdScreen(void)
  1323. {
  1324.     /*----------------------------------------------------------------*/
  1325.     /* Local Variables                                                */
  1326.     /*----------------------------------------------------------------*/
  1327.     SubLCDHistoryNode SubLCDHistory;
  1328.     /*----------------------------------------------------------------*/
  1329.     /* Code Body                                                      */
  1330.     /*----------------------------------------------------------------*/
  1331.     SubLCDHistory.entryFuncPtr = EntryAlmSubLcdScreen;
  1332.     AddSubLCDHistoryWithScrID(&SubLCDHistory, SCR_ID_ALM_SUB_INDICATION);
  1333. }
  1334. /*****************************************************************************
  1335.  * FUNCTION
  1336.  *  AlmCommonExitProcedure
  1337.  * DESCRIPTION
  1338.  *  Stop alarm tone by user or timeout.
  1339.  * PARAMETERS
  1340.  *  void
  1341.  * RETURNS
  1342.  *  void
  1343.  *****************************************************************************/
  1344. void AlmCommonExitProcedure(void)
  1345. {
  1346.     /*----------------------------------------------------------------*/
  1347.     /* Local Variables                                                */
  1348.     /*----------------------------------------------------------------*/
  1349.     /*----------------------------------------------------------------*/
  1350.     /* Code Body                                                      */
  1351.     /*----------------------------------------------------------------*/
  1352.     g_alm_cntx.IsSaveToHistory = 0;
  1353.     TurnOffBacklight();
  1354.     AlmsStopAlarmTone();
  1355. }
  1356. /*****************************************************************************
  1357.  * FUNCTION
  1358.  *  AlmExitIndScreen
  1359.  * DESCRIPTION
  1360.  *  Exit alarm indication screen.
  1361.  * PARAMETERS
  1362.  *  void
  1363.  * RETURNS
  1364.  *  void
  1365.  *****************************************************************************/
  1366. void AlmExitIndScreen(void)
  1367. {
  1368.     /*----------------------------------------------------------------*/
  1369.     /* Local Variables                                                */
  1370.     /*----------------------------------------------------------------*/
  1371.     /*----------------------------------------------------------------*/
  1372.     /* Code Body                                                      */
  1373.     /*----------------------------------------------------------------*/
  1374.     if (GetActiveScreenId() == SCR_ID_ALM_INDICATION)
  1375.     {
  1376.      if (GetSubLCDScreenCountInHistory() == 0)
  1377.         {
  1378.             GoBackHistory();
  1379.         }
  1380.         else
  1381.         {
  1382.             GoBackBothLCDHistory();
  1383.         }
  1384.     }
  1385.     else
  1386.     {
  1387.         DeleteScreenIfPresent(SCR_ID_ALM_INDICATION);
  1388.     }
  1389. }
  1390. /*****************************************************************************
  1391.  * FUNCTION
  1392.  *  AlmStopHandler
  1393.  * DESCRIPTION
  1394.  *  Handler for stopping alarm.
  1395.  * PARAMETERS
  1396.  *  void
  1397.  * RETURNS
  1398.  *  void
  1399.  *****************************************************************************/
  1400. void AlmStopHandler(void)
  1401. {
  1402.     /*----------------------------------------------------------------*/
  1403.     /* Local Variables                                                */
  1404.     /*----------------------------------------------------------------*/
  1405.     S32 i;
  1406.     /*----------------------------------------------------------------*/
  1407.     /* Code Body                                                      */
  1408.     /*----------------------------------------------------------------*/
  1409.     StopTimer(ALARM_ALERT_NOTIFYDURATION_TIMER);
  1410.     AlmCommonExitProcedure();
  1411.     /* factory alarm does not have to re-schedule */
  1412.     if (g_alm_frm_cntx.CurrAlmIndex != ALM_FACTORY)
  1413.     {
  1414.         i = g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START;
  1415.         if (i >= NUM_OF_ALM)
  1416.         {
  1417.             return;
  1418.         }
  1419.             
  1420.         g_alm_cntx.AlmList[i].Snooze = 0;
  1421.         if (g_alm_freq_set[g_alm_cntx.AlmList[i].Freq] == ALM_FREQ_ONCE)        /* reset the alarm state */
  1422.         {
  1423.             g_alm_cntx.AlmList[i].State = UNSET_STATE;
  1424.             if (!(AlmIsAnyAlarmActivated()))
  1425.             {
  1426.                 AlmDeactivateIndicator();
  1427.             }
  1428.         }
  1429.         AlmWriteToNvram();
  1430.     }
  1431.     g_alm_frm_cntx.CurrAlmIndex = 0xff;
  1432.     if (g_alm_frm_cntx.IsPwronAlarm == FALSE)
  1433.     {
  1434.         AlmExitIndScreen();
  1435.         if (g_alm_frm_cntx.IsExitByTimer == FALSE)
  1436.         {
  1437.             AlmExecPwrOnAlarm();
  1438.         }
  1439.     }
  1440.     else
  1441.     {
  1442.         if (GetCurrScrnId() == (U16) SCR_ID_ALM_PWRON_CONFIRM
  1443.     #ifdef __NVRAM_IN_USB_MS__
  1444.             || (g_pwr_context.PowerOnMode == POWER_ON_USB)
  1445.     #endif 
  1446.             )
  1447.         {
  1448.             AlmExitIndScreen();
  1449.         }
  1450.         else
  1451.         {
  1452.             EntryAlmPowerOnConfirmation();
  1453.         }
  1454.     #ifdef __MTK_TARGET__
  1455.         if (g_alm_frm_cntx.IsExitByTimer == FALSE)
  1456.         {
  1457.             AlmExecPwrOffAlarm();
  1458.         }
  1459.     #endif /* __MTK_TARGET__ */ 
  1460.     }
  1461. }
  1462. /*****************************************************************************
  1463.  * FUNCTION
  1464.  *  AlmSnoozeHandler
  1465.  * DESCRIPTION
  1466.  *  Handler for snoozing alarm.
  1467.  * PARAMETERS
  1468.  *  void
  1469.  * RETURNS
  1470.  *  void
  1471.  *****************************************************************************/
  1472. void AlmSnoozeHandler(void)
  1473. {
  1474.     /*----------------------------------------------------------------*/
  1475.     /* Local Variables                                                */
  1476.     /*----------------------------------------------------------------*/
  1477.     S32 i;
  1478.     /*----------------------------------------------------------------*/
  1479.     /* Code Body                                                      */
  1480.     /*----------------------------------------------------------------*/
  1481. #ifdef MMI_ON_WIN32
  1482.     if (g_alm_frm_cntx.IsPwronAlarm)
  1483.     {
  1484.         AlmSendPowerOff();
  1485.     }
  1486. #endif /* MMI_ON_WIN32 */ 
  1487.     StopTimer(ALARM_ALERT_NOTIFYDURATION_TIMER);
  1488.     i = g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START;
  1489.     
  1490.     if (i >= NUM_OF_ALM)
  1491.     {
  1492.             return;
  1493.     }
  1494.     
  1495.     g_alm_cntx.AlmList[i].Snooze++;
  1496.     g_alm_cntx.AlmList[i].State = SET_STATE;
  1497.     AlmCommonExitProcedure();
  1498.     if (g_alm_cntx.AlmList[i].Snooze <= MAX_SNOOZE_CHANCES)
  1499.     {
  1500.         AlmWriteToNvram();
  1501.         AlmInsertIntoQueue(g_alm_frm_cntx.CurrAlmIndex, TRUE);
  1502.         g_alm_frm_cntx.CurrAlmIndex = 0xff;
  1503.         if (g_alm_frm_cntx.IsPwronAlarm == FALSE)
  1504.         {
  1505.             /* GoBackBothLCDHistory(); */
  1506.             AlmExitIndScreen();
  1507.         }
  1508.     #if 0
  1509. /* under construction !*/
  1510. /* under construction !*/
  1511. /* under construction !*/
  1512. /* under construction !*/
  1513. /* under construction !*/
  1514. /* under construction !*/
  1515. /* under construction !*/
  1516. /* under construction !*/
  1517. /* under construction !*/
  1518. /* under construction !*/
  1519. /* under construction !*/
  1520. /* under construction !*/
  1521. /* under construction !*/
  1522.     #endif /* 0 */ 
  1523.         else if (g_alm_frm_cntx.IsPwronAlarm && g_alm_frm_cntx.IsAppExecuting)
  1524.         {
  1525.             /* GoBackHistory(); */
  1526.             AlmExitIndScreen();
  1527.         }
  1528.         if (g_alm_frm_cntx.IsExitByTimer == FALSE)
  1529.         {
  1530.             if (g_alm_frm_cntx.IsPwronAlarm)
  1531.             {
  1532.                 AlmExecPwrOffAlarm();
  1533.             }
  1534.             else
  1535.             {
  1536.                 AlmExecPwrOnAlarm();
  1537.             }
  1538.         }
  1539.     }
  1540.     else
  1541.     {
  1542.         AlmStopHandler();
  1543.     }
  1544. }
  1545. /*****************************************************************************
  1546.  * FUNCTION
  1547.  *  AlmWriteToNvram
  1548.  * DESCRIPTION
  1549.  *  Write alarm data to nvram
  1550.  * PARAMETERS
  1551.  *  void
  1552.  * RETURNS
  1553.  *  void
  1554.  *****************************************************************************/
  1555. void AlmWriteToNvram(void)
  1556. {
  1557.     /*----------------------------------------------------------------*/
  1558.     /* Local Variables                                                */
  1559.     /*----------------------------------------------------------------*/
  1560.     S16 error;
  1561.     U8 nvram_buf[NVRAM_ALM_ALARM_DATA_SIZE];
  1562.     /*----------------------------------------------------------------*/
  1563.     /* Code Body                                                      */
  1564.     /*----------------------------------------------------------------*/
  1565.     memset(nvram_buf, 0, NVRAM_ALM_ALARM_DATA_SIZE);
  1566.     memcpy(nvram_buf, g_alm_cntx.AlmList, sizeof(g_alm_cntx.AlmList));
  1567.     WriteRecord(NVRAM_EF_ALM_ALARM_DATA_LID, 1, (void*)nvram_buf, NVRAM_ALM_ALARM_DATA_SIZE, &error);
  1568. }
  1569. /*****************************************************************************
  1570.  * FUNCTION
  1571.  *  AlmIsAnyAlarmActivated
  1572.  * DESCRIPTION
  1573.  *  To check if there is any activated alarm.
  1574.  * PARAMETERS
  1575.  *  void
  1576.  * RETURNS
  1577.  *  0 if no activated alarm; otherwise 0.
  1578.  *****************************************************************************/
  1579. U8 AlmIsAnyAlarmActivated(void)
  1580. {
  1581.     /*----------------------------------------------------------------*/
  1582.     /* Local Variables                                                */
  1583.     /*----------------------------------------------------------------*/
  1584.     S32 i;
  1585.     /*----------------------------------------------------------------*/
  1586.     /* Code Body                                                      */
  1587.     /*----------------------------------------------------------------*/
  1588.     for (i = 0; i < NUM_OF_ALM; i++)
  1589.         if (g_alm_cntx.AlmList[i].State == SET_STATE)
  1590.         {
  1591.             return 1;
  1592.         }
  1593.     return 0;
  1594. }
  1595. /*****************************************************************************
  1596.  * FUNCTION
  1597.  *  AlmActivateIndicator
  1598.  * DESCRIPTION
  1599.  *  Show alarm status icon in IDLE screen.
  1600.  * PARAMETERS
  1601.  *  void
  1602.  * RETURNS
  1603.  *  void
  1604.  *****************************************************************************/
  1605. void AlmActivateIndicator(void)
  1606. {
  1607.     /*----------------------------------------------------------------*/
  1608.     /* Local Variables                                                */
  1609.     /*----------------------------------------------------------------*/
  1610.     /*----------------------------------------------------------------*/
  1611.     /* Code Body                                                      */
  1612.     /*----------------------------------------------------------------*/
  1613.     ShowStatusIcon(STATUS_ICON_ALARM);
  1614. #ifndef __MMI_SUBLCD_SHORT_STATUSICON_LIST__
  1615.     ShowStatusIcon(STATUS_ICON_SUBLCD_ALARM);
  1616. #endif 
  1617.     UpdateStatusIcons();
  1618. }
  1619. /*****************************************************************************
  1620.  * FUNCTION
  1621.  *  AlmDeactivateIndicator
  1622.  * DESCRIPTION
  1623.  *  Hide alarm status icon in IDLE screen.
  1624.  * PARAMETERS
  1625.  *  void
  1626.  * RETURNS
  1627.  *  void
  1628.  *****************************************************************************/
  1629. void AlmDeactivateIndicator(void)
  1630. {
  1631.     /*----------------------------------------------------------------*/
  1632.     /* Local Variables                                                */
  1633.     /*----------------------------------------------------------------*/
  1634.     /*----------------------------------------------------------------*/
  1635.     /* Code Body                                                      */
  1636.     /*----------------------------------------------------------------*/
  1637.     HideStatusIcon(STATUS_ICON_ALARM);
  1638. #ifndef __MMI_SUBLCD_SHORT_STATUSICON_LIST__
  1639.     HideStatusIcon(STATUS_ICON_SUBLCD_ALARM);
  1640. #endif 
  1641.     UpdateStatusIcons();
  1642. }
  1643. /*****************************************************************************
  1644.  * FUNCTION
  1645.  *  mmi_alm_check_history_and_poweroff
  1646.  * DESCRIPTION
  1647.  *  Check history before sending power off request.
  1648.  * PARAMETERS
  1649.  *  void
  1650.  * RETURNS
  1651.  *  void
  1652.  *****************************************************************************/
  1653. void mmi_alm_check_history_and_poweroff(void)
  1654. {
  1655.     /*----------------------------------------------------------------*/
  1656.     /* Local Variables                                                */
  1657.     /*----------------------------------------------------------------*/
  1658.     /*----------------------------------------------------------------*/
  1659.     /* Code Body                                                      */
  1660.     /*----------------------------------------------------------------*/
  1661.     if (GetScreenCountInHistory() > 0)
  1662.     {
  1663.         if (GetSubLCDScreenCountInHistory() == 0)
  1664.         {
  1665.             GoBackHistory();
  1666.         }
  1667.         else
  1668.         {
  1669.             GoBackBothLCDHistory();
  1670.         }
  1671.     }
  1672.     else
  1673.     {
  1674.         AlmSendPowerOff();
  1675.     }
  1676. }
  1677. /*****************************************************************************
  1678.  * FUNCTION
  1679.  *  EntryAlmPowerOnConfirmation
  1680.  * DESCRIPTION
  1681.  *  Display confirmation screen to decide power on or not.
  1682.  *  This screen is used for power off alarm.
  1683.  * PARAMETERS
  1684.  *  void
  1685.  * RETURNS
  1686.  *  void
  1687.  *****************************************************************************/
  1688. void EntryAlmPowerOnConfirmation(void)
  1689. {
  1690.     /*----------------------------------------------------------------*/
  1691.     /* Local Variables                                                */
  1692.     /*----------------------------------------------------------------*/
  1693.     U8 *guiBuffer;
  1694.     /*----------------------------------------------------------------*/
  1695.     /* Code Body                                                      */
  1696.     /*----------------------------------------------------------------*/
  1697.     mmi_alm_disable_pwroff();
  1698.     EntryNewScreen(SCR_ID_ALM_PWRON_CONFIRM, NULL, EntryAlmPowerOnConfirmation, NULL);
  1699.     /* to prevent power on confirmation screen from displaying twice */
  1700.     DeleteScreenIfPresent(SCR_ID_ALM_PWRON_CONFIRM);
  1701.     guiBuffer = GetCurrGuiBuffer(SCR_ID_ALM_PWRON_CONFIRM);
  1702.     ShowCategory123Screen(
  1703.         ORGANIZER_MENU_ALARMS_STRINGID,
  1704.         ALARMS_MAIN_TITLE_IMAGEID,
  1705.         STR_GLOBAL_YES,
  1706.         IMG_GLOBAL_YES,
  1707.         STR_GLOBAL_NO,
  1708.         IMG_GLOBAL_NO,
  1709.         ALARMS_POWER_ON,
  1710.         IMG_GLOBAL_QUESTION,
  1711.         guiBuffer);
  1712.     SetLeftSoftkeyFunction(AlmSendPowerOn, KEY_EVENT_UP);
  1713.     SetRightSoftkeyFunction(mmi_alm_check_history_and_poweroff, KEY_EVENT_UP);
  1714.     ClearKeyHandler(KEY_END, KEY_EVENT_UP);
  1715.     ClearKeyHandler(KEY_END, KEY_EVENT_DOWN);
  1716.     SetKeyHandler(AlmSendPowerOn, KEY_END, KEY_LONG_PRESS);
  1717.     /* to prevent double displayed this screen */
  1718.     DeleteScreenIfPresent(SCR_ID_ALM_PWRON_CONFIRM);
  1719.     ForceSubLCDScreen(EntryAlmSubLcdScreen);
  1720. #ifdef MMI_ON_WIN32
  1721.     SetLeftSoftkeyFunction(PopupNoSupport, KEY_EVENT_UP);
  1722.     SetRightSoftkeyFunction(PopupNoSupport, KEY_EVENT_UP);
  1723.     SetKeyHandler(PopupNoSupport, KEY_END, KEY_LONG_PRESS);
  1724. #endif /* MMI_ON_WIN32 */ 
  1725. }
  1726. /*****************************************************************************
  1727.  * FUNCTION
  1728.  *  HighlightAlmInlineRepeat
  1729.  * DESCRIPTION
  1730.  *  Highlight handler of Repeat inline selection item in editor screen.
  1731.  *  Enable DOW component when selecting "Days"
  1732.  * PARAMETERS
  1733.  *  index       [IN]        Index of inline selection
  1734.  * RETURNS
  1735.  *  void
  1736.  *****************************************************************************/
  1737. void HighlightAlmInlineRepeat(S32 index)
  1738. {
  1739.     /*----------------------------------------------------------------*/
  1740.     /* Local Variables                                                */
  1741.     /*----------------------------------------------------------------*/
  1742.     U8 j = 0;
  1743.     /*----------------------------------------------------------------*/
  1744.     /* Code Body                                                      */
  1745.     /*----------------------------------------------------------------*/
  1746.     if (g_alm_freq_set[index] == ALM_FREQ_DAYS)
  1747.     {
  1748.         if (g_alm_cntx.IsDOWSet == 0)
  1749.         {
  1750.             /* if the user did not select DOW yet */
  1751.             if (g_alm_cntx.AlmList[g_alm_cntx.CurrHiliteAlarm].Days == 0)
  1752.             {
  1753.                 memset(gAlmDaysStates, 1, 7);
  1754.                 gAlmDaysStates[0] = 0;
  1755.                 gAlmDaysStates[6] = 0;
  1756.             }
  1757.             else    /* fill user-set value to DOW */
  1758.             {
  1759.                 for (j = 0; j < NUM_DAYS; j++)
  1760.                 {
  1761.                     gAlmDaysStates[j] =
  1762.                         ((((g_alm_cntx.AlmList[g_alm_cntx.CurrHiliteAlarm].Days) & (0x1 << j)) == 0) ? 0 : 1);
  1763.                 }
  1764.             }
  1765.             g_alm_cntx.IsDOWSet = 1;
  1766.             EnableInlineItem(&wgui_inline_items[4], 4); /* multi select days */
  1767.         }
  1768.     }
  1769.     else
  1770.     {
  1771.         g_alm_cntx.IsDOWSet = 0;
  1772.         memset(gAlmDaysStates, 0, 7);
  1773.         DisableInlineItem(&wgui_inline_items[4], 4);    /* multi select days */
  1774.     }
  1775.     RedrawCategory57Screen();
  1776. }
  1777. /* added the support for alarm audio options. */
  1778. /*****************************************************************************
  1779.  * FUNCTION
  1780.  *  AlmGetSnoozeInterval
  1781.  * DESCRIPTION
  1782.  *  Get Snooze Interval
  1783.  * PARAMETERS
  1784.  *  void
  1785.  * RETURNS
  1786.  *  Snooze interval
  1787.  *****************************************************************************/
  1788. U8 AlmGetSnoozeInterval(U8 almIndex)
  1789. {
  1790.     /*----------------------------------------------------------------*/
  1791.     /* Local Variables                                                */
  1792.     /*----------------------------------------------------------------*/
  1793.     U8 snooze;
  1794. #ifdef __MMI_ALM_SNOOZE_SETTING__
  1795.     /*----------------------------------------------------------------*/
  1796.     /* Code Body                                                      */
  1797.     /*----------------------------------------------------------------*/
  1798.     snooze = g_alm_cntx.AlmList[almIndex].SnoozeInterval;
  1799. #endif /* __MMI_ALM_SNOOZE_SETTING__ */ 
  1800.     if (snooze == 0)
  1801.     {
  1802.         snooze = ALM_SNOOZE_INTERVAL;
  1803.     }
  1804.     /* ReadValue(NVRAM_ALM_SNOOZE_TIME, &snooze, DS_BYTE, &error); */
  1805.     return snooze;
  1806. }
  1807. #ifdef __MMI_ALM_AUDIO_OPTIONS__
  1808. #ifdef __MMI_ALM_CUSTOMIZE_TONE__
  1809. /*****************************************************************************
  1810.  * FUNCTION
  1811.  *  mmi_alm_entry_aud_opt_tone
  1812.  * DESCRIPTION
  1813.  *  The entry function for the screen displaying options for tone audio option.
  1814.  * PARAMETERS
  1815.  *  void
  1816.  * RETURNS
  1817.  *  void
  1818.  *****************************************************************************/
  1819. void mmi_alm_entry_aud_opt_tone(void)
  1820. {
  1821.     /*----------------------------------------------------------------*/
  1822.     /* Local Variables                                                */
  1823.     /*----------------------------------------------------------------*/
  1824.     U8 *guiBuffer;
  1825.     U16 selecteditem = 0;
  1826.     U8 totalItems = 0;
  1827.     /*----------------------------------------------------------------*/
  1828.     /* Code Body                                                      */
  1829.     /*----------------------------------------------------------------*/
  1830.     EntryNewScreen(SCR_ID_ALM_TONE_SETUP, mmi_alm_exit_aud_opt_tone, mmi_alm_entry_aud_opt_tone, NULL);
  1831.     guiBuffer = GetCurrGuiBuffer(SCR_ID_ALM_TONE_SETUP);
  1832.     SetParentHandler(MENU_ID_ALM_TONE_SETUP);
  1833.     RegisterHighlightHandler(mmi_alm_tone_setup_hilite_hdlr);
  1834.     /* Get the highlight index from profile */
  1835.     if (g_alm_cntx.CurrHiliteAudioOption != ALM_AUDIO_OPTIONS_TONE ||
  1836.         (g_alm_cntx.CurrHiliteAudioOption == ALM_AUDIO_OPTIONS_TONE && g_alm_cntx.CurrHiliteAudioOptionValue == 0))
  1837.     {
  1838.         totalItems = mmi_profiles_get_melody_list((U16) (gstartMidiId + 1), &selecteditem);
  1839.     }
  1840.     else
  1841.     {
  1842.         totalItems = mmi_profiles_get_melody_list(g_alm_cntx.CurrHiliteAudioOptionValue, &selecteditem);
  1843.     }
  1844.     ShowCategory89Screen(
  1845.         STR_ALARM_TONE_CAPTION,
  1846.         IMG_PROFILES_TITLEE,
  1847.         STR_GLOBAL_OK,
  1848.         IMG_GLOBAL_OK,
  1849.         STR_GLOBAL_BACK,
  1850.         IMG_GLOBAL_BACK,
  1851.         totalItems,
  1852.         subMenuDataPtrs,
  1853.         hintDataPtrs,
  1854.         0,
  1855.         selecteditem,
  1856.         guiBuffer);
  1857.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1858.     SetLeftSoftkeyFunction(mmi_alm_entry_tone_setup_set_alarm_tone, KEY_EVENT_UP);
  1859.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1860. }
  1861. /*****************************************************************************
  1862.  * FUNCTION
  1863.  *  mmi_alm_exit_aud_opt_tone
  1864.  * DESCRIPTION
  1865.  *  The exit function for the screen displaying options for tone audio option.
  1866.  * PARAMETERS
  1867.  *  void
  1868.  * RETURNS
  1869.  *  void
  1870.  *****************************************************************************/
  1871. void mmi_alm_exit_aud_opt_tone(void)
  1872. {
  1873.     /*----------------------------------------------------------------*/
  1874.     /* Local Variables                                                */
  1875.     /*----------------------------------------------------------------*/
  1876.     /*----------------------------------------------------------------*/
  1877.     /* Code Body                                                      */
  1878.     /*----------------------------------------------------------------*/
  1879.     StopToneAudio();
  1880. }
  1881. /*****************************************************************************
  1882.  * FUNCTION
  1883.  *  mmi_alm_entry_tone_setup_set_alarm_tone
  1884.  * DESCRIPTION
  1885.  *  Setting Alarm tone ID.
  1886.  * PARAMETERS
  1887.  *  void
  1888.  * RETURNS
  1889.  *  void
  1890.  *****************************************************************************/
  1891. void mmi_alm_entry_tone_setup_set_alarm_tone(void)
  1892. {
  1893.     /*----------------------------------------------------------------*/
  1894.     /* Local Variables                                                */
  1895.     /*----------------------------------------------------------------*/
  1896.     TONE_SETUP tonesetup;
  1897.     U32 tempval1 = 0, tempval2 = gtotalRingId;
  1898.     U32 data = 0;
  1899.     U8 ExtMelodyFlag = MMI_FALSE;
  1900.     /*----------------------------------------------------------------*/
  1901.     /* Code Body                                                      */
  1902.     /*----------------------------------------------------------------*/
  1903.     if (((g_alm_tone_index) >= (U8) tempval1) && ((g_alm_tone_index) < (U8) (tempval2)))
  1904.     {
  1905.         tonesetup.ringTone = g_alm_tone_index + gstartRingId;
  1906.     }
  1907.     tempval1 = tempval2;
  1908.     tempval2 = gtotalMidiId + gtotalRingId;
  1909.     if (((g_alm_tone_index) >= (U8) tempval1) && ((g_alm_tone_index) < (U8) (tempval2)))
  1910.     {
  1911.         tonesetup.ringTone = g_alm_tone_index + gstartMidiId - gtotalRingId;
  1912.     }
  1913. #if defined(__MMI_PROFILE_EXTMELODY_SUPPORT__)
  1914.     tempval1 = tempval2;
  1915.     tempval2 = gtotalMidiId + gtotalRingId + MAXIMUM_EXT_MELODY_NUM;
  1916.     if (((g_alm_tone_index) >= (U8) tempval1) && ((g_alm_tone_index) < (U8) (tempval2)))
  1917.     {
  1918.         /* data is zero based */
  1919.         data = g_alm_tone_index - (gtotalMidiId + gtotalRingId);
  1920.         g_ext_melody_idx = (U8) data;
  1921.         ExtMelodyFlag = MMI_TRUE;
  1922.     }
  1923.     if (ExtMelodyFlag == MMI_TRUE)
  1924.     {
  1925.         g_alm_tone_conf_type = PRFSET_MELODY_TYPE_ALARM;
  1926.         mmi_alm_entry_tone_setup_ext_melody();
  1927.         return;
  1928.     }
  1929. #endif /* defined(__MMI_PROFILE_EXTMELODY_SUPPORT__) */ 
  1930. #if defined(__MMI_DOWNLOADABLE_THEMES_SUPPORT__)
  1931.     if (g_alm_tone_index == tempval2)
  1932.     {
  1933.         DYNAUDIOINFO *download_theme_tones;
  1934.         if (GetThemeV2TonesInfo(&download_theme_tones) != 0 && mmi_tm_get_current_theme_ringtone())
  1935.         {
  1936.             tonesetup.ringTone = (U16) download_theme_tones[0].AudioId;
  1937.         }
  1938.     }
  1939. #endif /* defined(__MMI_DOWNLOADABLE_THEMES_SUPPORT__) */ 
  1940.     DisplayPopup(
  1941.         (PU8) GetString(STR_GLOBAL_DONE),
  1942.         IMG_GLOBAL_ACTIVATED,
  1943.         1,
  1944.         UI_POPUP_NOTIFYDURATION_TIME,
  1945.         SUCCESS_TONE);
  1946.     g_alm_cntx.CurrHiliteAudioOptionValue = tonesetup.ringTone;
  1947.     g_alm_cntx.CurrHiliteAudioOption = ALM_AUDIO_OPTIONS_TONE;
  1948.     g_alm_aud_opt_selected = TRUE;
  1949.     StopToneAudio();
  1950.     DeleteScreenIfPresent(SCR_ID_ALM_TONE_SETUP);
  1951. }
  1952. #ifdef __MMI_PROFILE_EXTMELODY_SUPPORT__
  1953. /*****************************************************************************
  1954.  * FUNCTION
  1955.  *  mmi_alm_entry_tone_setup_ext_melody
  1956.  * DESCRIPTION
  1957.  *  Entry function for the external melodies screen.
  1958.  * PARAMETERS
  1959.  *  void
  1960.  * RETURNS
  1961.  *  void
  1962.  *****************************************************************************/
  1963. void mmi_alm_entry_tone_setup_ext_melody(void)
  1964. {
  1965.     /*----------------------------------------------------------------*/
  1966.     /* Local Variables                                                */
  1967.     /*----------------------------------------------------------------*/
  1968.     U8 *nStrItemList[PRF_MENU_EXTMLD_MAX];
  1969.     U8 nNumofItem = 0;
  1970.     U8 *guiBuffer;
  1971.     U16 StrIDToneSet = 0, StrIDToneDel = 0, StrIDToneAdd = 0;
  1972.     /*----------------------------------------------------------------*/
  1973.     /* Code Body                                                      */
  1974.     /*----------------------------------------------------------------*/
  1975.     StrIDToneSet = STR_TONE_SETUP_ALARM_TONE_EXT_SET;
  1976.     StrIDToneDel = STR_TONE_SETUP_ALARM_TONE_EXT_DEL;
  1977.     StrIDToneAdd = STR_TONE_SETUP_ALARM_TONE_EXT_ADD;
  1978.     if (PmgIsEmptySlot(g_ext_melody_idx) == MMI_FALSE)  /* Not Empty Slot */
  1979.     {
  1980.         nStrItemList[PRF_MENU_EXTMLD_DONE] = (U8*) GetString(StrIDToneSet);
  1981.         nStrItemList[PRF_MENU_EXTMLD_DEL] = (U8*) GetString(StrIDToneDel);
  1982.         nStrItemList[PRF_MENU_EXTMLD_ADD] = (U8*) GetString(StrIDToneAdd);
  1983.         nNumofItem = (U8) PRF_MENU_EXTMLD_MAX;
  1984.     }
  1985.     else    /* Empty slot, show replace only */
  1986.     {
  1987.         nStrItemList[0] = (U8*) GetString(StrIDToneAdd);
  1988.         nNumofItem = 1;
  1989.     }
  1990.     EntryNewScreen(SCR_ID_ALM_TONE_SETUP_EXT_MELODY, NULL, mmi_alm_entry_tone_setup_ext_melody, NULL);
  1991.     guiBuffer = GetCurrGuiBuffer(SCR_ID_ALM_TONE_SETUP_EXT_MELODY);
  1992.     RegisterHighlightHandler(mmi_alm_tone_setup_ext_melody_hilight_hdlr);
  1993.     ShowCategory56Screen(
  1994.         STR_ALARM_TONE_CAPTION,
  1995.         IMG_PROFILES_TITLEE,
  1996.         STR_GLOBAL_OK,
  1997.         IMG_GLOBAL_OK,
  1998.         STR_GLOBAL_BACK,
  1999.         IMG_GLOBAL_BACK,
  2000.         nNumofItem,
  2001.         nStrItemList,
  2002.         NULL,
  2003.         0,
  2004.         guiBuffer);
  2005.     SetLeftSoftkeyFunction(mmi_alm_tone_setup_ext_melody_option, KEY_EVENT_UP);
  2006.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  2007. }
  2008. /*****************************************************************************
  2009.  * FUNCTION
  2010.  *  mmi_alm_tone_setup_ext_melody_hilight_hdlr
  2011.  * DESCRIPTION
  2012.  *  Highlight handler for the external melodies options screen
  2013.  * PARAMETERS
  2014.  *  index       [IN]        
  2015.  * RETURNS
  2016.  *  void
  2017.  *****************************************************************************/
  2018. void mmi_alm_tone_setup_ext_melody_hilight_hdlr(S32 index)
  2019. {
  2020.     /*----------------------------------------------------------------*/
  2021.     /* Local Variables                                                */
  2022.     /*----------------------------------------------------------------*/
  2023.     /*----------------------------------------------------------------*/
  2024.     /* Code Body                                                      */
  2025.     /*----------------------------------------------------------------*/
  2026.     extMldHlitItem = (U8) index;
  2027. }
  2028. /*****************************************************************************
  2029.  * FUNCTION
  2030.  *  mmi_alm_tone_setup_ext_melody_option
  2031.  * DESCRIPTION
  2032.  *  LSK fucntion for the external melodies options screen
  2033.  * PARAMETERS
  2034.  *  void
  2035.  * RETURNS
  2036.  *  void
  2037.  *****************************************************************************/
  2038. void mmi_alm_tone_setup_ext_melody_option(void)
  2039. {
  2040.     /*----------------------------------------------------------------*/
  2041.     /* Local Variables                                                */
  2042.     /*----------------------------------------------------------------*/
  2043.     U8 idx = mmi_alm_tone_setup_convert_empty_slot_menu_list(extMldHlitItem);
  2044.     /*----------------------------------------------------------------*/
  2045.     /* Code Body                                                      */
  2046.     /*----------------------------------------------------------------*/
  2047.     if (idx == PRF_MENU_EXTMLD_DONE)
  2048.     {
  2049.         if (PmgIsEmptySlot(g_ext_melody_idx) == MMI_FALSE)
  2050.         {
  2051.             g_alm_cntx.CurrHiliteAudioOptionValue = PMG_EXT_MELODY_BEGIN + g_ext_melody_idx;
  2052.             g_alm_cntx.CurrHiliteAudioOption = ALM_AUDIO_OPTIONS_TONE;
  2053.             g_alm_aud_opt_selected = TRUE;
  2054.             if (g_alm_tone_conf_type != PRFSET_MELODY_TYPE_PHB_RING)
  2055.             {
  2056.                 DisplayPopup(
  2057.                     (PU8) GetString(STR_GLOBAL_DONE),
  2058.                     IMG_GLOBAL_ACTIVATED,
  2059.                     1,