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

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.  * ComposeRingTone.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements screen flow of Ring Tone Composer application.
  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.  *------------------------------------------------------------------------------
  120.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  121.  *============================================================================
  122.  ****************************************************************************/
  123.  /**
  124.  * Copyright Notice
  125.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  126.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  127.  *  (It is illegal to remove this copyright notice from this software or any
  128.  *  portion of it)
  129.  */
  130. /**************************************************************
  131.    FILENAME : ComposeRingTone.c
  132.    PURPOSE     : Main functions of the Fun and Games, Compose Ring Tone application
  133.    REMARKS     : nil
  134.    AUTHOR      : Yogesh
  135.    DATE     : July-28-2003
  136. **************************************************************/
  137. #ifndef _MMI_COMPOSERINGTONE_C
  138. #define _MMI_COMPOSERINGTONE_C
  139. /*  Include: MMI header file */
  140. #include "MMI_features.h"
  141. #if defined(__MMI_RING_COMPOSER__) && defined(__MMI_IMELODY_SUPPORT__)
  142. #include "GlobalDefs.h" /* resources */
  143. #include "CustDataRes.h"
  144. #include "CustMenuRes.h"
  145. #include "historyGprot.h"       /* display screen/ history */
  146. #include "MainMenuDef.h"
  147. #include "EventsGprot.h"
  148. #include "wgui_categories_inputs.h"
  149. #include "Wgui_categories_popup.h"
  150. #include "CommonScreens.h"
  151. #include "TimerEvents.h"        /* timer/message id definition */
  152. #include "ProtocolEvents.h"
  153. #include "DebugInitDef.h"       /* debug info */
  154. #include "StdC.h"       /* app headers */
  155. #include "UnicodExDcl.h"
  156. #include "FunAndGamesDefs.h"
  157. #include "FunAndGamesProts.h"
  158. #include "ComposeRingToneProts.h"
  159. #include "ComposeRingToneDefs.h"
  160. #include "ComposeRingToneEngineProts.h"
  161. #include "ProfileGprots.h"
  162. #include "PhoneBookGprot.h"
  163. #include "FileSystemDef.h"
  164. #include "FileSystemGProt.h"
  165. #include "gpioInc.h"
  166. #include "Wgui_categories.h"
  167. #include "FileManagerGProt.h"
  168. #include "EventsGprot.h"
  169. #ifdef __MOD_SMSAL__
  170. #include "MessagesExDcl.h"
  171. #endif 
  172. #include "fs_type.h"
  173. #include "FS_Func.h"
  174. #include "mdi_datatype.h"
  175. #include "mdi_audio.h"
  176. #include "AudioPlayerProt.h"
  177. /* it is assumed that the filemanager will always on */
  178. #include "FileManagerDef.h"
  179. #include "FileMgr.h"
  180. #include "FileManagerGProt.h"
  181. #include "datetimetype.h"
  182. #include "app_datetime.h"
  183. #define  RNGC_MAX_ENG_CHAR    26
  184. /* 
  185.  * Global Variable
  186.  */
  187. rngc_context_struct g_rngc_cntx;
  188. #ifdef MMI_ON_HARDWARE_P
  189. S16 RINGCOMPOSER_PATH[MAX_IMAGE_NAME_PATH_WIDTH];
  190. #else 
  191. S16 RINGCOMPOSER_PATH[MAX_IMAGE_NAME_PATH_WIDTH];
  192. #endif 
  193. extern const U8 CurrentInstrument[];    /* 110805 ringtonecomposer Calvin add */
  194. /* 
  195.  * Global Function
  196.  */
  197. /*****************************************************************************
  198.  * FUNCTION
  199.  *  RngcCreateDir
  200.  * DESCRIPTION
  201.  *  Create directory for ring tone composer if not exists.
  202.  * PARAMETERS
  203.  *  void
  204.  * RETURNS
  205.  *  enum value of result
  206.  *****************************************************************************/
  207. S32 RngcCreateDir(void)
  208. {
  209.     /*----------------------------------------------------------------*/
  210.     /* Local Variables                                                */
  211.     /*----------------------------------------------------------------*/
  212.     FS_HANDLE file_handle;
  213.     S8 fileBuf[MAX_IMAGE_NAME_PATH_WIDTH + RNGC_FILE_LEN];
  214.     /*----------------------------------------------------------------*/
  215.     /* Code Body                                                      */
  216.     /*----------------------------------------------------------------*/
  217.     memset(RINGCOMPOSER_PATH, 0, sizeof(RINGCOMPOSER_PATH));
  218.     sprintf(fileBuf, "%c:\", MMI_PUBLIC_DRV);
  219.     /* create file directory if not exists */
  220.     AnsiiToUnicodeString((S8*) RINGCOMPOSER_PATH, (S8*) fileBuf);
  221.     pfnUnicodeStrcat((S8*) RINGCOMPOSER_PATH, (S8*) FMGR_DEFAULT_FOLDER_AUDIO);
  222.     file_handle = FS_Open((U16*) RINGCOMPOSER_PATH, FS_OPEN_DIR | FS_READ_ONLY);
  223.     if (file_handle < 0)
  224.     {
  225.         return FS_CreateDir((U16*) RINGCOMPOSER_PATH);
  226.     }
  227.     else
  228.     {
  229.         FS_Close(file_handle);
  230.     #ifdef MMI_ON_HARDWARE_P
  231.         return FS_NO_ERROR;
  232.     #else 
  233.         return 0;
  234.     #endif 
  235.     }
  236. }
  237. /*****************************************************************************
  238.  * FUNCTION
  239.  *  RngcGetFileInfo
  240.  * DESCRIPTION
  241.  *  Get file info from file manager
  242.  * PARAMETERS
  243.  *  void
  244.  * RETURNS
  245.  *  enum value of result(?)
  246.  *****************************************************************************/
  247. void RngcGetFileInfo(void)
  248. {
  249.     /*----------------------------------------------------------------*/
  250.     /* Local Variables                                                */
  251.     /*----------------------------------------------------------------*/
  252.     FMGR_FILE_INFO_STRUCT file_info;
  253.     /*----------------------------------------------------------------*/
  254.     /* Code Body                                                      */
  255.     /*----------------------------------------------------------------*/
  256.     mmi_fmgr_kernel_get_file_info(mmi_fmgr_kernel_get_cur_idx(), &file_info);
  257.     pfnUnicodeStrcpy(g_rngc_cntx.FileName, (S8*) file_info.file_name);
  258.     /* mmi_rngc_filename_callback((void*)file_info.file_name); */
  259. }
  260. /*****************************************************************************
  261.  * FUNCTION
  262.  *  RngcExecPlay
  263.  * DESCRIPTION
  264.  *  Prepare temporary file and entry play screen.
  265.  * PARAMETERS
  266.  *  void
  267.  * RETURNS
  268.  *  void
  269.  *****************************************************************************/
  270. void RngcExecPlay(void)
  271. {
  272.     /*----------------------------------------------------------------*/
  273.     /* Local Variables                                                */
  274.     /*----------------------------------------------------------------*/
  275.     /*----------------------------------------------------------------*/
  276.     /* Code Body                                                      */
  277.     /*----------------------------------------------------------------*/
  278.     RngcGetFileInfo();
  279.     pfnUnicodeStrcpy((S8*) g_rngc_cntx.PrevFileName, (S8*) g_rngc_cntx.FileName);
  280.     EntryRngcPlayTone();
  281. }
  282. /*****************************************************************************
  283.  * FUNCTION
  284.  *  HighlightRngcPlay
  285.  * DESCRIPTION
  286.  *  Highlight handler of play option
  287.  * PARAMETERS
  288.  *  void
  289.  * RETURNS
  290.  *  void
  291.  *****************************************************************************/
  292. void HighlightRngcPlay(void)
  293. {
  294.     /*----------------------------------------------------------------*/
  295.     /* Local Variables                                                */
  296.     /*----------------------------------------------------------------*/
  297.     /*----------------------------------------------------------------*/
  298.     /* Code Body                                                      */
  299.     /*----------------------------------------------------------------*/
  300.     SetLeftSoftkeyFunction(RngcExecPlay, KEY_EVENT_UP);
  301.     SetKeyHandler(RngcExecPlay, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  302. }
  303. /*****************************************************************************
  304.  * FUNCTION
  305.  *  RngcExecEdit
  306.  * DESCRIPTION
  307.  *  Execute Edit command
  308.  * PARAMETERS
  309.  *  void
  310.  * RETURNS
  311.  *  void
  312.  *****************************************************************************/
  313. void RngcExecEdit(void)
  314. {
  315.     /*----------------------------------------------------------------*/
  316.     /* Local Variables                                                */
  317.     /*----------------------------------------------------------------*/
  318.     /*----------------------------------------------------------------*/
  319.     /* Code Body                                                      */
  320.     /*----------------------------------------------------------------*/
  321.     RngcGetFileInfo();
  322.     g_rngc_cntx.CurrEditState = ENUM_COMP_EDIT;
  323.     EditMelody((U8*) g_rngc_cntx.FileName);
  324. }
  325. /*****************************************************************************
  326.  * FUNCTION
  327.  *  HighlightRngcEdit
  328.  * DESCRIPTION
  329.  *  Highlight handler of Edit option
  330.  * PARAMETERS
  331.  *  void
  332.  * RETURNS
  333.  *  void
  334.  *****************************************************************************/
  335. void HighlightRngcEdit(void)
  336. {
  337.     /*----------------------------------------------------------------*/
  338.     /* Local Variables                                                */
  339.     /*----------------------------------------------------------------*/
  340.     /*----------------------------------------------------------------*/
  341.     /* Code Body                                                      */
  342.     /*----------------------------------------------------------------*/
  343.     SetLeftSoftkeyFunction(RngcExecEdit, KEY_EVENT_UP);
  344.     SetKeyHandler(RngcExecEdit, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  345. }
  346. /*****************************************************************************
  347.  * FUNCTION
  348.  *  RngcExecAdd
  349.  * DESCRIPTION
  350.  *  Execute Add command
  351.  * PARAMETERS
  352.  *  void
  353.  * RETURNS
  354.  *  void
  355.  *****************************************************************************/
  356. void RngcExecAdd(void)
  357. {
  358.     /*----------------------------------------------------------------*/
  359.     /* Local Variables                                                */
  360.     /*----------------------------------------------------------------*/
  361.     /*----------------------------------------------------------------*/
  362.     /* Code Body                                                      */
  363.     /*----------------------------------------------------------------*/
  364.     g_rngc_cntx.CurrEditState = ENUM_COMP_ADD;
  365.     FreeMemory();
  366.     EntryRngcComposerEngine();
  367. }
  368. /*****************************************************************************
  369.  * FUNCTION
  370.  *  HighlightRngcAdd
  371.  * DESCRIPTION
  372.  *  Highlight handler of Add option
  373.  * PARAMETERS
  374.  *  void
  375.  * RETURNS
  376.  *  void
  377.  *****************************************************************************/
  378. void HighlightRngcAdd(void)
  379. {
  380.     /*----------------------------------------------------------------*/
  381.     /* Local Variables                                                */
  382.     /*----------------------------------------------------------------*/
  383.     /*----------------------------------------------------------------*/
  384.     /* Code Body                                                      */
  385.     /*----------------------------------------------------------------*/
  386.     SetLeftSoftkeyFunction(RngcExecAdd, KEY_EVENT_UP);
  387.     SetKeyHandler(RngcExecAdd, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  388. }
  389. /*****************************************************************************
  390.  * FUNCTION
  391.  *  RngcExecRename
  392.  * DESCRIPTION
  393.  *  Execute rename command
  394.  * PARAMETERS
  395.  *  void
  396.  * RETURNS
  397.  *  void
  398.  *****************************************************************************/
  399. void RngcExecRename(void)
  400. {
  401.     /*----------------------------------------------------------------*/
  402.     /* Local Variables                                                */
  403.     /*----------------------------------------------------------------*/
  404.     /*----------------------------------------------------------------*/
  405.     /* Code Body                                                      */
  406.     /*----------------------------------------------------------------*/
  407.     RngcGetFileInfo();
  408.     g_rngc_cntx.CurrEditState = ENUM_COMP_RENAME;
  409.     SetRingToneFilenameBuf();
  410.     EntryRngcEditFileName();
  411. }
  412. /*****************************************************************************
  413.  * FUNCTION
  414.  *  HighlightRngcRename
  415.  * DESCRIPTION
  416.  *  Highlight handler of Rename option
  417.  * PARAMETERS
  418.  *  void
  419.  * RETURNS
  420.  *  void
  421.  *****************************************************************************/
  422. void HighlightRngcRename(void)
  423. {
  424.     /*----------------------------------------------------------------*/
  425.     /* Local Variables                                                */
  426.     /*----------------------------------------------------------------*/
  427.     /*----------------------------------------------------------------*/
  428.     /* Code Body                                                      */
  429.     /*----------------------------------------------------------------*/
  430.     SetLeftSoftkeyFunction(RngcExecRename, KEY_EVENT_UP);
  431.     SetKeyHandler(RngcExecRename, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  432. }
  433. /*****************************************************************************
  434.  * FUNCTION
  435.  *  HighlightRngcDelete
  436.  * DESCRIPTION
  437.  *  Highlight handler of Delete option
  438.  * PARAMETERS
  439.  *  void
  440.  * RETURNS
  441.  *  void
  442.  *****************************************************************************/
  443. void HighlightRngcDelete(void)
  444. {
  445.     /*----------------------------------------------------------------*/
  446.     /* Local Variables                                                */
  447.     /*----------------------------------------------------------------*/
  448.     /*----------------------------------------------------------------*/
  449.     /* Code Body                                                      */
  450.     /*----------------------------------------------------------------*/
  451.     SetLeftSoftkeyFunction(EntryRngcDeleteToneConfirm, KEY_EVENT_UP);
  452.     SetKeyHandler(NULL, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  453. }
  454. /*****************************************************************************
  455.  * FUNCTION
  456.  *  InitRingToneComposer
  457.  * DESCRIPTION
  458.  *  1. initialize handler
  459.  *  2. reset global variables
  460.  *  3. read data from NVRAM
  461.  *  4. Sync files and file indices
  462.  * PARAMETERS
  463.  *  void
  464.  * RETURNS
  465.  *  enum value of result(?)
  466.  *****************************************************************************/
  467. void InitRingToneComposer(void)
  468. {
  469.     /*----------------------------------------------------------------*/
  470.     /* Local Variables                                                */
  471.     /*----------------------------------------------------------------*/
  472.     /*----------------------------------------------------------------*/
  473.     /* Code Body                                                      */
  474.     /*----------------------------------------------------------------*/
  475.     /* highlight handler */
  476.     SetHiliteHandler(MENU3103_RINGTONE_COMPOSER, HighlightRngcMenu);
  477.     SetHiliteHandler(MENU_COMP_RINGTONE_COMP_SELPLAY, HighlightRngcPlay);
  478.     SetHiliteHandler(MENU_COMP_RINGTONE_COMP_SELEDIT, HighlightRngcEdit);
  479.     SetHiliteHandler(MENU_COMP_RINGTONE_COMP_SELADD, HighlightRngcAdd);
  480.     SetHiliteHandler(MENU_COMP_RINGTONE_COMP_SELRENAME, HighlightRngcRename);
  481.     SetHiliteHandler(MENU_COMP_RINGTONE_COMP_SELDELETE, HighlightRngcDelete);
  482.     /* reset global context */
  483.     memset(&g_rngc_cntx, 0, sizeof(g_rngc_cntx));
  484.     g_rngc_cntx.CurrInstr = INSTR_PIANO;
  485.     g_rngc_cntx.CurrSpeed = NORMAL_SPEED;
  486.     /*
  487.      * sync file system,
  488.      * create dir if not exists.
  489.      */
  490.     RngcCreateDir();
  491. }
  492. /*****************************************************************************
  493.  * FUNCTION
  494.  *  HighlightRngcMenu
  495.  * DESCRIPTION
  496.  *  Highlight handler for Ring Tone Composer menu in FunAndGame
  497.  * PARAMETERS
  498.  *  void
  499.  * RETURNS
  500.  *  enum value of result(?)
  501.  *****************************************************************************/
  502. void HighlightRngcMenu(void)
  503. {
  504.     /*----------------------------------------------------------------*/
  505.     /* Local Variables                                                */
  506.     /*----------------------------------------------------------------*/
  507.     /*----------------------------------------------------------------*/
  508.     /* Code Body                                                      */
  509.     /*----------------------------------------------------------------*/
  510.     SetLeftSoftkeyFunction(EntryRngcApp, KEY_EVENT_UP);
  511.     SetKeyHandler(EntryRngcApp, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  512. }
  513. /*****************************************************************************
  514.  * FUNCTION
  515.  *  mmi_rngc_dummy_callback
  516.  * DESCRIPTION
  517.  *  
  518.  * PARAMETERS
  519.  *  fullname        [?]         
  520.  *  is_short        [IN]        
  521.  * RETURNS
  522.  *  void
  523.  *****************************************************************************/
  524. void mmi_rngc_dummy_callback(void *fullname, int is_short)
  525. {
  526.     /*----------------------------------------------------------------*/
  527.     /* Local Variables                                                */
  528.     /*----------------------------------------------------------------*/
  529.     /*----------------------------------------------------------------*/
  530.     /* Code Body                                                      */
  531.     /*----------------------------------------------------------------*/
  532.     GoBackHistory();
  533. }
  534. /*****************************************************************************
  535.  * FUNCTION
  536.  *  EntryRngcApp
  537.  * DESCRIPTION
  538.  *  Entry first screen of composer
  539.  * PARAMETERS
  540.  *  void
  541.  * RETURNS
  542.  *  void
  543.  *****************************************************************************/
  544. void EntryRngcApp(void)
  545. {
  546.     /*----------------------------------------------------------------*/
  547.     /* Local Variables                                                */
  548.     /*----------------------------------------------------------------*/
  549.     FMGR_FILTER filter;
  550.     /*----------------------------------------------------------------*/
  551.     /* Code Body                                                      */
  552.     /*----------------------------------------------------------------*/
  553.     FMGR_FILTER_INIT(&filter);
  554.     FMGR_FILTER_SET(&filter, FMGR_TYPE_IMY);
  555.     RngcCreateDir();
  556.     mmi_fmgr_select_path_and_enter(
  557.         APP_RINGTONECOMPOSER,
  558.         FMGR_SELECT_BROWSE,
  559.         filter,
  560.         (S8*) RINGCOMPOSER_PATH,
  561.         mmi_rngc_dummy_callback);
  562. }
  563. /*****************************************************************************
  564.  * FUNCTION
  565.  *  HighlightRngcCompTone
  566.  * DESCRIPTION
  567.  *  Highlight handler when selecting a composed tone
  568.  * PARAMETERS
  569.  *  nIndex      [IN]        
  570.  * RETURNS
  571.  *  void
  572.  *****************************************************************************/
  573. void HighlightRngcCompTone(S32 nIndex)
  574. {
  575.     /*----------------------------------------------------------------*/
  576.     /* Local Variables                                                */
  577.     /*----------------------------------------------------------------*/
  578.     /*----------------------------------------------------------------*/
  579.     /* Code Body                                                      */
  580.     /*----------------------------------------------------------------*/
  581.     g_rngc_cntx.CurrTone = (U8) nIndex;
  582. }
  583. /*****************************************************************************
  584.  * FUNCTION
  585.  *  EntryRngcMainMenuOptList
  586.  * DESCRIPTION
  587.  *  Display available options for a composed tone
  588.  * PARAMETERS
  589.  *  void
  590.  * RETURNS
  591.  *  void
  592.  *****************************************************************************/
  593. void EntryRngcMainMenuOptList(void)
  594. {
  595.     /*----------------------------------------------------------------*/
  596.     /* Local Variables                                                */
  597.     /*----------------------------------------------------------------*/
  598.     U8 *guiBuffer;
  599.     U16 RingToneOptionList[ENUM_COMP_OPT_TOTAL];
  600.     U16 noOfChildren;
  601.     /*----------------------------------------------------------------*/
  602.     /* Code Body                                                      */
  603.     /*----------------------------------------------------------------*/
  604.     guiBuffer = GetCurrGuiBuffer(SCR_COMPOSE_RINGTONE_OPTION);
  605.     EntryNewScreen(SCR_COMPOSE_RINGTONE_OPTION, NULL, EntryRngcMainMenuOptList, NULL);
  606.     GetSequenceStringIds(MENU_COMP_RINGTONE_COMP_SELMENU_1, RingToneOptionList);
  607.     SetParentHandler(MENU_COMP_RINGTONE_COMP_SELMENU_1);
  608.     noOfChildren = GetNumOfChild(MENU_COMP_RINGTONE_COMP_SELMENU_1);
  609.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  610.     ShowCategory15Screen(
  611.         STR_GLOBAL_OPTIONS,
  612.         GetRootTitleIcon(MENU3103_RINGTONE_COMPOSER),
  613.         STR_GLOBAL_OK,
  614.         IMG_GLOBAL_OK,
  615.         STR_GLOBAL_BACK,
  616.         IMG_GLOBAL_BACK,
  617.         noOfChildren,
  618.         RingToneOptionList,
  619.         (PU16) gIndexIconsImageList,
  620.         1,
  621.         0,
  622.         guiBuffer);
  623.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  624.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  625. }
  626. /*****************************************************************************
  627.  * FUNCTION
  628.  *  SetRingToneFilenameBuf
  629.  * DESCRIPTION
  630.  *  Fill filename buffer
  631.  * PARAMETERS
  632.  *  void
  633.  * RETURNS
  634.  *  void
  635.  *****************************************************************************/
  636. void SetRingToneFilenameBuf(void)
  637. {
  638.     /*----------------------------------------------------------------*/
  639.     /* Local Variables                                                */
  640.     /*----------------------------------------------------------------*/
  641.     /*----------------------------------------------------------------*/
  642.     /* Code Body                                                      */
  643.     /*----------------------------------------------------------------*/
  644.     switch (g_rngc_cntx.CurrEditState)
  645.     {
  646.         case ENUM_COMP_ADD: /* insert default filename */
  647.         {
  648.             MYTIME TodayDateTime;
  649.             S8 dummyString[RNGC_FILE_LEN];  /* RMMDDHHMM */
  650.             S8 fullName[RNGC_FILE_LEN];
  651.             S8 extName[RNGC_FILE_LEN];
  652.             S32 i;
  653.             AnsiiToUnicodeString(extName, MELODY_FILE_EXTENSION);
  654.             GetDateTime(&TodayDateTime);
  655.             sprintf(
  656.                 dummyString,
  657.                 "R%02d%02d%02d%02da",
  658.                 TodayDateTime.nMonth,
  659.                 TodayDateTime.nDay,
  660.                 TodayDateTime.nHour,
  661.                 TodayDateTime.nMin);
  662.             for (i = 0; i < RNGC_MAX_ENG_CHAR; i++)
  663.             {
  664.                 AnsiiToUnicodeString(fullName, dummyString);
  665.                 pfnUnicodeStrcat(fullName, extName);
  666.                 if (!IsCompToneExisted(fullName))
  667.                 {
  668.                     break;
  669.                 }
  670.                 dummyString[9] = 'a' + i + 1;
  671.             }
  672.             AnsiiToUnicodeString(g_rngc_cntx.FileName, dummyString);
  673.             break;
  674.         }
  675.         default:
  676.             break;
  677.     }
  678.     pfnUnicodeStrcpy((S8*) g_rngc_cntx.PrevFileName, (S8*) g_rngc_cntx.FileName);
  679. }
  680. /*****************************************************************************
  681.  * FUNCTION
  682.  *  EntryRngcDeleteToneConfirm
  683.  * DESCRIPTION
  684.  *  Entry delete confirmation screen
  685.  * PARAMETERS
  686.  *  void
  687.  * RETURNS
  688.  *  void
  689.  *****************************************************************************/
  690. void EntryRngcDeleteToneConfirm(void)
  691. {
  692.     /*----------------------------------------------------------------*/
  693.     /* Local Variables                                                */
  694.     /*----------------------------------------------------------------*/
  695.     /*----------------------------------------------------------------*/
  696.     /* Code Body                                                      */
  697.     /*----------------------------------------------------------------*/
  698.     DisplayConfirm(
  699.         STR_GLOBAL_YES,
  700.         IMG_GLOBAL_YES,
  701.         STR_GLOBAL_NO,
  702.         IMG_GLOBAL_NO,
  703.         get_string(STR_CAP_COMP_RINGTONE_DELETE),
  704.         IMG_GLOBAL_QUESTION,
  705.         WARNING_TONE);
  706.     SetLeftSoftkeyFunction(DeleteCompRingTone, KEY_EVENT_UP);
  707.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  708.     /* set exit handler to NULL because does have have to add to history */
  709. }
  710. /*****************************************************************************
  711.  * FUNCTION
  712.  *  DeleteCompRingTone
  713.  * DESCRIPTION
  714.  *  1. Delete file index
  715.  *  2. Delete real file
  716.  *  3. Display popup screen accoding to result
  717.  * PARAMETERS
  718.  *  void
  719.  * RETURNS
  720.  *  void
  721.  *****************************************************************************/
  722. void DeleteCompRingTone(void)
  723. {
  724.     /*----------------------------------------------------------------*/
  725.     /* Local Variables                                                */
  726.     /*----------------------------------------------------------------*/
  727.     U8 result = 0;
  728.     S8 fileBuf[MAX_IMAGE_NAME_PATH_WIDTH + RNGC_FILE_LEN];
  729.     /*----------------------------------------------------------------*/
  730.     /* Code Body                                                      */
  731.     /*----------------------------------------------------------------*/
  732.     RngcGetFileInfo();
  733.     pfnUnicodeStrcpy((S8*) fileBuf, (S8*) RINGCOMPOSER_PATH);
  734.     pfnUnicodeStrcat((S8*) fileBuf, (S8*) g_rngc_cntx.FileName);
  735.     if (FS_Delete((U16*) fileBuf) != 0)
  736.     {
  737.         result = FALSE;
  738.     }
  739.     else
  740.     {
  741.         result = TRUE;
  742.     }
  743.     if (result) /* successfully, display "Done" screen */
  744.     {
  745.         DisplayPopup(
  746.             (U8*) GetString(STR_GLOBAL_DONE),
  747.             IMG_GLOBAL_ACTIVATED,
  748.             0,
  749.             UI_POPUP_NOTIFYDURATION_TIME,
  750.             SUCCESS_TONE);
  751.     }
  752.     else    /* unsucessfully, display "Unfinished" */
  753.     {
  754.         DisplayPopup(
  755.             (U8*) GetString(STR_GLOBAL_UNFINISHED),
  756.             IMG_GLOBAL_UNFINISHED,
  757.             0,
  758.             UI_POPUP_NOTIFYDURATION_TIME,
  759.             ERROR_TONE);
  760.     }
  761.     DeleteUptoScrID(SCR_FMGR_EXPLORER);
  762. }
  763. /*****************************************************************************
  764.  * FUNCTION
  765.  *  CompRingTonePlayFinishInd
  766.  * DESCRIPTION
  767.  *  Message handler of PRT_EQ_PLAY_AUDIO_FINISH_IND, go back to previous screen
  768.  * PARAMETERS
  769.  *  result      [IN]        
  770.  *  info(?)     [IN]        Local paramater of PRT_EQ_PLAY_AUDIO_FINISH_IND message
  771.  * RETURNS
  772.  *  void
  773.  *****************************************************************************/
  774. void CompRingTonePlayFinishInd(mdi_result result)
  775. {
  776. #ifdef __MTK_TARGET__
  777.     /*----------------------------------------------------------------*/
  778.     /* Local Variables                                                */
  779.     /*----------------------------------------------------------------*/
  780.     /*----------------------------------------------------------------*/
  781.     /* Code Body                                                      */
  782.     /*----------------------------------------------------------------*/
  783.     if (g_rngc_cntx.IsSelfStop == FALSE && result == MDI_AUDIO_TERMINATED)
  784.     {
  785.         g_rngc_cntx.IsTonePlaying = FALSE;
  786.         GoBackHistory();
  787.     }
  788.     else if (result != MDI_AUDIO_SUCCESS && result != MDI_AUDIO_TERMINATED)
  789.     {
  790.         GoBackHistory();
  791.     }
  792. #endif /* __MTK_TARGET__ */ 
  793. }
  794. /*****************************************************************************
  795.  * FUNCTION
  796.  *  RngcStopToneAndGoBackHistory
  797.  * DESCRIPTION
  798.  *  Stop iMelody and go back to previous screen
  799.  * PARAMETERS
  800.  *  void
  801.  * RETURNS
  802.  *  void
  803.  *****************************************************************************/
  804. void RngcStopToneAndGoBackHistory(void)
  805. {
  806.     /*----------------------------------------------------------------*/
  807.     /* Local Variables                                                */
  808.     /*----------------------------------------------------------------*/
  809.     /*----------------------------------------------------------------*/
  810.     /* Code Body                                                      */
  811.     /*----------------------------------------------------------------*/
  812.     g_rngc_cntx.IsSelfStop = TRUE;
  813.     GoBackHistory();
  814. }
  815. /*****************************************************************************
  816.  * FUNCTION
  817.  *  RngcStopToneAndGoToIdle
  818.  * DESCRIPTION
  819.  *  Stop iMelody and go to IDLE screen
  820.  * PARAMETERS
  821.  *  void
  822.  * RETURNS
  823.  *  void
  824.  *****************************************************************************/
  825. void RngcStopToneAndGoToIdle(void)
  826. {
  827.     /*----------------------------------------------------------------*/
  828.     /* Local Variables                                                */
  829.     /*----------------------------------------------------------------*/
  830.     /*----------------------------------------------------------------*/
  831.     /* Code Body                                                      */
  832.     /*----------------------------------------------------------------*/
  833.     g_rngc_cntx.IsSelfStop = TRUE;
  834.     DisplayIdleScreen();
  835. }
  836. /*****************************************************************************
  837.  * FUNCTION
  838.  *  RngcPlayToneCallBack
  839.  * DESCRIPTION
  840.  *  1. Call back function when play finished.
  841.  *  2. delete temporary file
  842.  * PARAMETERS
  843.  *  void
  844.  * RETURNS
  845.  *  void
  846.  *****************************************************************************/
  847. void RngcPlayToneCallBack(void)
  848. {
  849.     /*----------------------------------------------------------------*/
  850.     /* Local Variables                                                */
  851.     /*----------------------------------------------------------------*/
  852.     S8 fileBuf[RNGC_FILE_LEN + 80]; /* for path name */
  853.     S8 fileName[RNGC_FILE_LEN];
  854.     /*----------------------------------------------------------------*/
  855.     /* Code Body                                                      */
  856.     /*----------------------------------------------------------------*/
  857.     /* AnsiiToUnicodeString(fileName, (S8*)RNGC_TEMP_FILE_NAME); */
  858.     pfnUnicodeStrcpy((S8*) fileName, (S8*) FMGR_TEMP_FILE_MELODY);
  859.     GenerateCompleteComposeFileName((S8*) fileName, (S8*) fileBuf);
  860.     FS_Delete((U16*) fileBuf);
  861. }
  862. /*****************************************************************************
  863.  * FUNCTION
  864.  *  EntryRngcPlayTone
  865.  * DESCRIPTION
  866.  *  1. Display playing screen.
  867.  *  2. Stop LED pattern.
  868.  *  3. Play iMedloy file by name and file id.
  869.  *  4. Set playing flag.
  870.  * PARAMETERS
  871.  *  void
  872.  * RETURNS
  873.  *  void
  874.  *****************************************************************************/
  875. void EntryRngcPlayTone(void)
  876. {
  877.     /*----------------------------------------------------------------*/
  878.     /* Local Variables                                                */
  879.     /*----------------------------------------------------------------*/
  880.     S8 *fileBuf = (S8*)OslMalloc(RNGC_FILE_LEN + 80); /* for path name */
  881.     /*----------------------------------------------------------------*/
  882.     /* Code Body                                                      */
  883.     /*----------------------------------------------------------------*/
  884.     pfnUnicodeStrcpy((S8*) fileBuf, (S8*) RINGCOMPOSER_PATH);
  885.     pfnUnicodeStrcat((S8*) fileBuf, (S8*) g_rngc_cntx.PrevFileName);
  886.     mmi_audply_play_in_melody_composer((UI_string_type) fileBuf, RngcPlayToneCallBack);
  887.     OslMfree(fileBuf);
  888. }
  889. /*****************************************************************************
  890.  * FUNCTION
  891.  *  ExitRngcPlayTone
  892.  * DESCRIPTION
  893.  *  Exit handler of EntryRngcPlayTone
  894.  *  1. Stop playing file.
  895.  *  2. Reset IsTonePlaying flag.
  896.  *  3. Restore LED pattern.
  897.  * PARAMETERS
  898.  *  void
  899.  * RETURNS
  900.  *  void
  901.  *****************************************************************************/
  902. void ExitRngcPlayTone(void)
  903. {
  904.     /*----------------------------------------------------------------*/
  905.     /* Local Variables                                                */
  906.     /*----------------------------------------------------------------*/
  907.     S8 fileBuf[RNGC_FILE_LEN];  /* for path name */
  908.     S8 fileName[RNGC_FILE_LEN];
  909.     /*----------------------------------------------------------------*/
  910.     /* Code Body                                                      */
  911.     /*----------------------------------------------------------------*/
  912.     ClearProtocolEventHandler(PRT_EQ_PLAY_AUDIO_FINISH_IND);
  913.     /* stop playing file */
  914.     if (g_rngc_cntx.IsTonePlaying == TRUE)
  915.     {
  916.         mdi_audio_stop_file();
  917.     }
  918.     /* reset flag */
  919.     g_rngc_cntx.IsTonePlaying = FALSE;
  920.     /* AnsiiToUnicodeString(fileName, (S8*)RNGC_TEMP_FILE_NAME); */
  921.     pfnUnicodeStrcpy((S8*) fileName, (S8*) FMGR_TEMP_FILE_MELODY);
  922.     GenerateCompleteComposeFileName((S8*) fileName, (S8*) fileBuf);
  923.     FS_Delete((U16*) fileBuf);
  924.     /* restore LED pattern */
  925.     StartLEDPatternBackGround();
  926. }
  927. /*****************************************************************************
  928.  * FUNCTION
  929.  *  EntryRngcCompToneOptList
  930.  * DESCRIPTION
  931.  *  Display available options when composing a rnig tone
  932.  * PARAMETERS
  933.  *  void
  934.  * RETURNS
  935.  *  void
  936.  *****************************************************************************/
  937. void EntryRngcCompToneOptList(void)
  938. {
  939.     /*----------------------------------------------------------------*/
  940.     /* Local Variables                                                */
  941.     /*----------------------------------------------------------------*/
  942.     U8 *guiBuffer;
  943.     U16 ItemList[ENUM_ADD_TONE_OPT_TOTAL];
  944.     U16 nItems;
  945.     /*----------------------------------------------------------------*/
  946.     /* Code Body                                                      */
  947.     /*----------------------------------------------------------------*/
  948.     /* stop multitap timer of tone editor screen */
  949.     StopTimer(NOTE_MULTITAP_TIMER);
  950.     EntryNewScreen(SCR_COMP_RINGTONE_ADD_OPT, NULL, EntryRngcCompToneOptList, NULL);
  951.     guiBuffer = GetCurrGuiBuffer(SCR_COMP_RINGTONE_ADD_OPT);
  952.     SetParentHandler(MENU_COMP_RINGTONE_COMP_ADDOPT);
  953.     nItems = GetNumOfChild(MENU_COMP_RINGTONE_COMP_ADDOPT);
  954.     GetSequenceStringIds(MENU_COMP_RINGTONE_COMP_ADDOPT, ItemList);
  955.     RegisterHighlightHandler(HighlightRngcCompToneOpt);
  956.     ShowCategory52Screen(
  957.         STR_GLOBAL_OPTIONS,
  958.         GetRootTitleIcon(MENU3103_RINGTONE_COMPOSER),
  959.         STR_GLOBAL_OK,
  960.         IMG_GLOBAL_OK,
  961.         STR_GLOBAL_BACK,
  962.         IMG_GLOBAL_BACK,
  963.         nItems,
  964.         ItemList,
  965.         (PU16) gIndexIconsImageList,
  966.         0,
  967.         0,
  968.         0,
  969.         guiBuffer);
  970.     /* Register function for left soft key */
  971.     SetLeftSoftkeyFunction(RngcGotoSelectedCompToneOpt, KEY_EVENT_UP);
  972.     /* SetKeyHandler(GoBackHistory,KEY_LEFT_ARROW,KEY_EVENT_DOWN); */
  973.     /* Register function for right soft key */
  974.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  975. }
  976. /*****************************************************************************
  977.  * FUNCTION
  978.  *  HighlightRngcCompToneOpt
  979.  * DESCRIPTION
  980.  *  Highlight handler of EntryRngcCompToneOptList
  981.  * PARAMETERS
  982.  *  nIndex      [IN]        
  983.  * RETURNS
  984.  *  void
  985.  *****************************************************************************/
  986. void HighlightRngcCompToneOpt(S32 nIndex)
  987. {
  988.     /*----------------------------------------------------------------*/
  989.     /* Local Variables                                                */
  990.     /*----------------------------------------------------------------*/
  991.     /*----------------------------------------------------------------*/
  992.     /* Code Body                                                      */
  993.     /*----------------------------------------------------------------*/
  994.     g_rngc_cntx.CurrHiliteItem = (U8) nIndex;
  995.     ClearKeyHandler(KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  996.     /* register right key handler if current highlight is on "Play speed" or "Instrument" */
  997.     if (nIndex != ENUM_ADD_TONE_OPT_SAVE)   /* play speed and select instrument */
  998.     {
  999.         SetKeyHandler(RngcGotoSelectedCompToneOpt, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1000.     }
  1001. }
  1002. /*****************************************************************************
  1003.  * FUNCTION
  1004.  *  RngcGotoSelectedCompToneOpt
  1005.  * DESCRIPTION
  1006.  *  Entry selected option when adding a tone
  1007.  * PARAMETERS
  1008.  *  void
  1009.  * RETURNS
  1010.  *  void
  1011.  *****************************************************************************/
  1012. void RngcGotoSelectedCompToneOpt(void)
  1013. {
  1014.     /*----------------------------------------------------------------*/
  1015.     /* Local Variables                                                */
  1016.     /*----------------------------------------------------------------*/
  1017.     /*----------------------------------------------------------------*/
  1018.     /* Code Body                                                      */
  1019.     /*----------------------------------------------------------------*/
  1020.     switch (g_rngc_cntx.CurrHiliteItem)
  1021.     {
  1022.         case ENUM_ADD_TONE_OPT_PLAY:    /* Play */
  1023.             if (g_rngc_eng_cntx->TotalNotes > 0)
  1024.             {
  1025.                 S32 err;
  1026.                 //                              if(g_rngc_cntx.CurrEditState == ENUM_COMP_ADD)
  1027.                 //                              AnsiiToUnicodeString((S8*)g_rngc_cntx.PrevFileName,(S8*)RNGC_TEMP_FILE_NAME);
  1028.                 pfnUnicodeStrcpy((S8*) g_rngc_cntx.PrevFileName, (S8*) FMGR_TEMP_FILE_MELODY);
  1029.                 err = GenerateMelodyFile((S8*) g_rngc_cntx.PrevFileName);
  1030.                 if (err == 0)
  1031.                 {
  1032.                     EntryRngcPlayTone();
  1033.                 }
  1034.                 else
  1035.                 {
  1036.                     DisplayPopup(
  1037.                         (PU8) GetString(GetFileSystemErrorString(err)),
  1038.                         IMG_GLOBAL_ERROR,
  1039.                         1,
  1040.                         UI_POPUP_NOTIFYDURATION_TIME,
  1041.                         ERROR_TONE);
  1042.                 }
  1043.             }
  1044.             else
  1045.             {
  1046.                 DisplayPopup(
  1047.                     (U8*) GetString(STR_COMP_RINGTONE_EMPTYRINGTONE),
  1048.                     IMG_GLOBAL_WARNING,
  1049.                     0,
  1050.                     UI_POPUP_NOTIFYDURATION_TIME,
  1051.                     WARNING_TONE);
  1052.             }
  1053.             break;
  1054.         case ENUM_ADD_TONE_OPT_SPEED:   /* Play Speed */
  1055.             EntryRngcPlaySpeed();
  1056.             break;
  1057.         case ENUM_ADD_TONE_OPT_INSTR:   /* Select Instrument */
  1058.             EntryRngcInstrument();
  1059.             break;
  1060.         case ENUM_ADD_TONE_OPT_SAVE:    /* Save File */
  1061.             if (g_rngc_eng_cntx->TotalNotes > 0)
  1062.             {
  1063.                 SetRingToneFilenameBuf();
  1064.                 EntryRngcEditFileName();
  1065.             }
  1066.             else
  1067.             {
  1068.                 DisplayPopup(
  1069.                     (U8*) GetString(STR_COMP_RINGTONE_EMPTYRINGTONE),
  1070.                     IMG_GLOBAL_WARNING,
  1071.                     0,
  1072.                     UI_POPUP_NOTIFYDURATION_TIME,
  1073.                     WARNING_TONE);
  1074.             }
  1075.             break;
  1076.         default:
  1077.             break;
  1078.     }
  1079. }
  1080. /*****************************************************************************
  1081.  * FUNCTION
  1082.  *  EntryRngcPlaySpeed
  1083.  * DESCRIPTION
  1084.  *  Entry function of "Play Speed" item
  1085.  * PARAMETERS
  1086.  *  void
  1087.  * RETURNS
  1088.  *  void
  1089.  *****************************************************************************/
  1090. void EntryRngcPlaySpeed(void)
  1091. {
  1092.     /*----------------------------------------------------------------*/
  1093.     /* Local Variables                                                */
  1094.     /*----------------------------------------------------------------*/
  1095.     U16 ItemList[ENUM_SPEED_TOTAL]; /* Stores the strings id of submenus returned */
  1096.     U16 nItems;                     /* Stores no of children in the submenu */
  1097.     U8 *guiBuffer;                  /* Buffer holding history data */
  1098.     /*----------------------------------------------------------------*/
  1099.     /* Code Body                                                      */
  1100.     /*----------------------------------------------------------------*/
  1101.     EntryNewScreen(SCR_COMP_RINGTONE_SPEED, NULL, EntryRngcPlaySpeed, NULL);
  1102.     guiBuffer = GetCurrGuiBuffer(SCR_COMP_RINGTONE_SPEED);
  1103.     SetParentHandler(MENU_COMP_RINGTONE_COMP_PLAY_SPEED);
  1104.     nItems = GetNumOfChild(MENU_COMP_RINGTONE_COMP_PLAY_SPEED);
  1105.     GetSequenceStringIds(MENU_COMP_RINGTONE_COMP_PLAY_SPEED, ItemList);
  1106.     RegisterHighlightHandler(HighlightRngcGenericOptHdlr);
  1107.     ShowCategory11Screen(
  1108.         STR_COMP_RINGTONE_PLAY_SPEED,
  1109.         GetRootTitleIcon(MENU3103_RINGTONE_COMPOSER),
  1110.         STR_GLOBAL_OK,
  1111.         IMG_GLOBAL_OK,
  1112.         STR_GLOBAL_BACK,
  1113.         IMG_GLOBAL_BACK,
  1114.         nItems,
  1115.         ItemList,
  1116.         (U16) GetIndexCurrCompRingToneSpeed(),
  1117.         guiBuffer);
  1118.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1119.     SetLeftSoftkeyFunction(SetCurrCompRingToneSpeed, KEY_EVENT_UP);
  1120.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1121. }
  1122. /*****************************************************************************
  1123.  * FUNCTION
  1124.  *  HighlightRngcGenericOptHdlr
  1125.  * DESCRIPTION
  1126.  *  Generic highlight handler of each screen
  1127.  * PARAMETERS
  1128.  *  nIndex      [IN]        
  1129.  * RETURNS
  1130.  *  void
  1131.  *****************************************************************************/
  1132. void HighlightRngcGenericOptHdlr(S32 nIndex)
  1133. {
  1134.     /*----------------------------------------------------------------*/
  1135.     /* Local Variables                                                */
  1136.     /*----------------------------------------------------------------*/
  1137.     /*----------------------------------------------------------------*/
  1138.     /* Code Body                                                      */
  1139.     /*----------------------------------------------------------------*/
  1140.     g_rngc_cntx.CurrHiliteItem = (U8) nIndex;
  1141. }
  1142. /*****************************************************************************
  1143.  * FUNCTION
  1144.  *  SetCurrCompRingToneSpeed
  1145.  * DESCRIPTION
  1146.  *  Set ring tone speed to selected one.
  1147.  * PARAMETERS
  1148.  *  void
  1149.  * RETURNS
  1150.  *  void
  1151.  *****************************************************************************/
  1152. void SetCurrCompRingToneSpeed(void)
  1153. {
  1154.     /*----------------------------------------------------------------*/
  1155.     /* Local Variables                                                */
  1156.     /*----------------------------------------------------------------*/
  1157.     /*----------------------------------------------------------------*/
  1158.     /* Code Body                                                      */
  1159.     /*----------------------------------------------------------------*/
  1160.     switch (g_rngc_cntx.CurrHiliteItem)
  1161.     {
  1162.         case 0: /* fast */
  1163.             g_rngc_cntx.CurrSpeed = FAST_SPEED;
  1164.             break;
  1165.         case 1: /* normal */
  1166.             g_rngc_cntx.CurrSpeed = NORMAL_SPEED;
  1167.             break;
  1168.         case 2: /* slow */
  1169.             g_rngc_cntx.CurrSpeed = SLOW_SPEED;
  1170.             break;
  1171.         default:
  1172.             break;
  1173.     }
  1174.     GoBackHistory();
  1175. }
  1176. /*****************************************************************************
  1177.  * FUNCTION
  1178.  *  GetIndexCurrCompRingToneSpeed
  1179.  * DESCRIPTION
  1180.  *  Retrieve the item index of selected speed.
  1181.  * PARAMETERS
  1182.  *  void
  1183.  * RETURNS
  1184.  *  U8 : index of selected speed
  1185.  *****************************************************************************/
  1186. U8 GetIndexCurrCompRingToneSpeed(void)
  1187. {
  1188.     /*----------------------------------------------------------------*/
  1189.     /* Local Variables                                                */
  1190.     /*----------------------------------------------------------------*/
  1191.     /*----------------------------------------------------------------*/
  1192.     /* Code Body                                                      */
  1193.     /*----------------------------------------------------------------*/
  1194.     switch (g_rngc_cntx.CurrSpeed)
  1195.     {
  1196.         case FAST_SPEED:
  1197.             return ENUM_SPEED_FAST;     /* GetIndexOfStringId(MENU_COMP_RINGTONE_COMP_PLAY_SPEED,MENU_COMP_RINGTONE_FAST); */
  1198.         case NORMAL_SPEED:
  1199.             return ENUM_SPEED_NORMAL;   /* /GetIndexOfStringId(MENU_COMP_RINGTONE_COMP_PLAY_SPEED,MENU_COMP_RINGTONE_NORMAL); */
  1200.         case SLOW_SPEED:
  1201.             return ENUM_SPEED_SLOW;     /* GetIndexOfStringId(MENU_COMP_RINGTONE_COMP_PLAY_SPEED,MENU_COMP_RINGTONE_SLOW); */
  1202.         default:
  1203.             return (U8) 0;
  1204.     }
  1205. }
  1206. /*****************************************************************************
  1207.  * FUNCTION
  1208.  *  EntryRngcInstrument
  1209.  * DESCRIPTION
  1210.  *  Entry function of "Select Instrument" item
  1211.  * PARAMETERS
  1212.  *  void
  1213.  * RETURNS
  1214.  *  void
  1215.  *****************************************************************************/
  1216. void EntryRngcInstrument(void)
  1217. {
  1218.     /*----------------------------------------------------------------*/
  1219.     /* Local Variables                                                */
  1220.     /*----------------------------------------------------------------*/
  1221.     U8 *guiBuffer;
  1222.     U16 ItemList[10];
  1223.     U16 nItems;
  1224.     /*----------------------------------------------------------------*/
  1225.     /* Code Body                                                      */
  1226.     /*----------------------------------------------------------------*/
  1227.     EntryNewScreen(SCR_COMP_RINGTONE_INSTRUMENT, NULL, EntryRngcInstrument, NULL);
  1228.     guiBuffer = GetCurrGuiBuffer(SCR_COMP_RINGTONE_INSTRUMENT);
  1229.     SetParentHandler(MENU_COMP_RINGTONE_COMP_SEL_INST);
  1230.     nItems = GetNumOfChild(MENU_COMP_RINGTONE_COMP_SEL_INST);
  1231.     GetSequenceStringIds(MENU_COMP_RINGTONE_COMP_SEL_INST, ItemList);
  1232.     RegisterHighlightHandler(HighlightRngcGenericOptHdlr);
  1233.     ShowCategory52Screen(
  1234.         STR_COMP_RINGTONE_SEL_INST,
  1235.         GetRootTitleIcon(MENU3103_RINGTONE_COMPOSER),
  1236.         STR_GLOBAL_OK,
  1237.         IMG_GLOBAL_OK,
  1238.         STR_GLOBAL_BACK,
  1239.         IMG_GLOBAL_BACK,
  1240.         nItems,
  1241.         ItemList,
  1242.         (PU16) gIndexIconsImageList,
  1243.         0,
  1244.         0,
  1245.         (U32) GetCurrIndexCompRingToneInst(),
  1246.         guiBuffer);
  1247.     /* Register function for left soft key */
  1248.     SetLeftSoftkeyFunction(SetCurrCompRingToneInstrument, KEY_EVENT_UP);
  1249.     /* Register function for right soft key */
  1250.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1251.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1252. }
  1253. /*****************************************************************************
  1254.  * FUNCTION
  1255.  *  GetCurrIndexCompRingToneInst
  1256.  * DESCRIPTION
  1257.  *  Retrieve the index of instrument for highlight
  1258.  * PARAMETERS
  1259.  *  void
  1260.  * RETURNS
  1261.  *  U8 : the item index of selected instrument
  1262.  *****************************************************************************/
  1263. U8 GetCurrIndexCompRingToneInst(void)
  1264. {
  1265.     /*----------------------------------------------------------------*/
  1266.     /* Local Variables                                                */
  1267.     /*----------------------------------------------------------------*/
  1268.     /* 110805 ringtonecomposer Calvin Start */
  1269. #if 0
  1270. /* under construction !*/
  1271. /* under construction !*/
  1272. /* under construction !*/
  1273. /* under construction !*/
  1274. /* under construction !*/
  1275. /* under construction !*/
  1276. /* under construction !*/
  1277. /* under construction !*/
  1278. /* under construction !*/
  1279. /* under construction !*/
  1280. /* under construction !*/
  1281. /* under construction !*/
  1282. /* under construction !*/
  1283. /* under construction !*/
  1284. /* under construction !*/
  1285. /* under construction !*/
  1286. /* under construction !*/
  1287. /* under construction !*/
  1288. /* under construction !*/
  1289. /* under construction !*/
  1290. /* under construction !*/
  1291. /* under construction !*/
  1292. /* under construction !*/
  1293. /* under construction !*/
  1294. /* under construction !*/
  1295. /* under construction !*/
  1296. #else /* 0 */ 
  1297.     S32 i;
  1298.     /*----------------------------------------------------------------*/
  1299.     /* Code Body                                                      */
  1300.     /*----------------------------------------------------------------*/
  1301.     for (i = 0; i < ENUM_TOTAL_INSTR; i++)
  1302.     {
  1303.         if ((U8) g_rngc_cntx.CurrInstr == CurrentInstrument[i])
  1304.         {
  1305.             return i;
  1306.         }
  1307.     }
  1308.     return (U8) 0;
  1309. #endif /* 0 */ 
  1310.     /* 110805 ringtonecomposer Calvin End */
  1311. }
  1312. /*****************************************************************************
  1313.  * FUNCTION
  1314.  *  SetCurrCompRingToneInstrument
  1315.  * DESCRIPTION
  1316.  *  Save the instrument according to selection
  1317.  * PARAMETERS
  1318.  *  void
  1319.  * RETURNS
  1320.  *  U8 : the item index of selected instrument(?)
  1321.  *****************************************************************************/
  1322. void SetCurrCompRingToneInstrument(void)
  1323. {
  1324.     /*----------------------------------------------------------------*/
  1325.     /* Local Variables                                                */
  1326.     /*----------------------------------------------------------------*/
  1327.     /* 110805 ringtonecomposer Calvin Start */
  1328. #if 0
  1329. /* under construction !*/
  1330. /* under construction !*/
  1331. /* under construction !*/
  1332. /* under construction !*/
  1333. /* under construction !*/
  1334. /* under construction !*/
  1335. /* under construction !*/
  1336. /* under construction !*/
  1337. /* under construction !*/
  1338. /* under construction !*/
  1339. /* under construction !*/
  1340. /* under construction !*/
  1341. /* under construction !*/
  1342. /* under construction !*/
  1343. /* under construction !*/
  1344. /* under construction !*/
  1345. /* under construction !*/
  1346. /* under construction !*/
  1347. /* under construction !*/
  1348. /* under construction !*/
  1349. /* under construction !*/
  1350. /* under construction !*/
  1351. /* under construction !*/
  1352. /* under construction !*/
  1353. /* under construction !*/
  1354. /* under construction !*/
  1355. /* under construction !*/
  1356. /* under construction !*/
  1357. /* under construction !*/
  1358. /* under construction !*/
  1359. /* under construction !*/
  1360. /* under construction !*/
  1361. /* under construction !*/
  1362. /* under construction !*/
  1363. /* under construction !*/
  1364. #else /* 0 */ 
  1365.     /*----------------------------------------------------------------*/
  1366.     /* Code Body                                                      */
  1367.     /*----------------------------------------------------------------*/
  1368.     g_rngc_cntx.CurrInstr = CurrentInstrument[g_rngc_cntx.CurrHiliteItem];
  1369. #endif /* 0 */ 
  1370.     /* 110805 ringtonecomposer Calvin End */
  1371.     GoBackHistory();
  1372. }
  1373. /*****************************************************************************
  1374.  * FUNCTION
  1375.  *  RngcGoBackFromEditor
  1376.  * DESCRIPTION
  1377.  *  
  1378.  * PARAMETERS
  1379.  *  void
  1380.  * RETURNS
  1381.  *  void
  1382.  *****************************************************************************/
  1383. void RngcGoBackFromEditor(void)
  1384. {
  1385.     /*----------------------------------------------------------------*/
  1386.     /* Local Variables                                                */
  1387.     /*----------------------------------------------------------------*/
  1388.     /*----------------------------------------------------------------*/
  1389.     /* Code Body                                                      */
  1390.     /*----------------------------------------------------------------*/
  1391. #if defined(__MMI_FILE_MANAGER__)
  1392.     pfnUnicodeStrcpy((S8*) g_rngc_cntx.FileName, (S8*) g_rngc_cntx.PrevFileName);
  1393. #endif 
  1394.     GoBackHistory();
  1395. }
  1396. /*****************************************************************************
  1397.  * FUNCTION
  1398.  *  EntryRngcEditFileName
  1399.  * DESCRIPTION
  1400.  *  Display full screen editor for editing filename
  1401.  * PARAMETERS
  1402.  *  void
  1403.  * RETURNS
  1404.  *  void
  1405.  *****************************************************************************/
  1406. void EntryRngcEditFileName(void)
  1407. {
  1408.     /*----------------------------------------------------------------*/
  1409.     /* Local Variables                                                */
  1410.     /*----------------------------------------------------------------*/
  1411.     U8 *guiBuffer;
  1412.     S8 filenameExt[16];
  1413.     U8 FileLen = 0;
  1414.     U8 ExtLen = 0;
  1415.     /*----------------------------------------------------------------*/
  1416.     /* Code Body                                                      */
  1417.     /*----------------------------------------------------------------*/
  1418.     EntryNewScreen(SCR_COMP_RINGTONE_SAVEFILE, NULL, EntryRngcEditFileName, NULL);
  1419.     /* remove file extension */
  1420.     FileLen = (U8) pfnUnicodeStrlen((S8*) g_rngc_cntx.FileName);
  1421.     ExtLen = strlen((S8*) MELODY_FILE_EXTENSION);
  1422.     UnicodeToAnsii((S8*) filenameExt, (S8*) & g_rngc_cntx.FileName[(FileLen - ExtLen) * ENCODING_LENGTH]);
  1423.     if (!StrnCmp((S8*) filenameExt, (S8*) MELODY_FILE_EXTENSION, ExtLen))
  1424.     {
  1425.         g_rngc_cntx.FileName[(FileLen - ExtLen) * ENCODING_LENGTH] = '';
  1426.     }
  1427.     /* Get current screen to gui buffer  for history purposes */
  1428.     guiBuffer = GetCurrGuiBuffer(SCR_COMP_RINGTONE_SAVEFILE);
  1429.     /* Set current parent id */
  1430.     /* SetParentHandler(0); */
  1431.     ShowCategory5Screen(
  1432.         STR_COMP_RINGTONE_FILENAME,
  1433.         GetRootTitleIcon(MENU3103_RINGTONE_COMPOSER),
  1434.         STR_GLOBAL_OPTIONS,
  1435.         IMG_GLOBAL_OPTIONS,
  1436.         STR_GLOBAL_BACK,
  1437.         IMG_GLOBAL_BACK,
  1438.         INPUT_TYPE_ALPHANUMERIC_SENTENCECASE,
  1439.         (U8*) g_rngc_cntx.FileName,
  1440.         RNGC_INPUT_FILE_LEN,
  1441.         guiBuffer);
  1442.     SetLeftSoftkeyFunction(EntryRngcEditFilenameOptList, KEY_EVENT_UP);
  1443.     SetCategory5RightSoftkeyFunction(RngcGoBackFromEditor /* GoBackHistory */ , KEY_EVENT_UP);
  1444.     GetCurrEndKeyDownHandler();
  1445.     SetKeyHandler(ExecCurrEndKeyDownHandler, KEY_END, KEY_EVENT_DOWN);
  1446. }
  1447. /*****************************************************************************
  1448.  * FUNCTION
  1449.  *  EntryRngcEditFilenameOptList
  1450.  * DESCRIPTION
  1451.  *  Display list of options when editing filename
  1452.  * PARAMETERS
  1453.  *  void
  1454.  * RETURNS
  1455.  *  void
  1456.  *****************************************************************************/
  1457. void EntryRngcEditFilenameOptList(void)
  1458. {
  1459.     /*----------------------------------------------------------------*/
  1460.     /* Local Variables                                                */
  1461.     /*----------------------------------------------------------------*/
  1462.     U8 *guiBuffer;
  1463.     U16 ItemList[2];
  1464.     U16 nItems;
  1465.     /*----------------------------------------------------------------*/
  1466.     /* Code Body                                                      */
  1467.     /*----------------------------------------------------------------*/
  1468.     EntryNewScreen(SCR_COMP_RINGTONE_SAVE_OPT, NULL, EntryRngcEditFilenameOptList, NULL);
  1469.     guiBuffer = GetCurrGuiBuffer(SCR_COMP_RINGTONE_SAVE_OPT);
  1470.     SetParentHandler(MENU_COMP_RINGTONE_SAVE_TONE);
  1471.     nItems = GetNumOfChild(MENU_COMP_RINGTONE_SAVE_TONE);
  1472.     GetSequenceStringIds(MENU_COMP_RINGTONE_SAVE_TONE, ItemList);
  1473.     RegisterHighlightHandler(GetCompRingToneSaveOpt);
  1474.     ShowCategory52Screen(
  1475.         STR_GLOBAL_OPTIONS,
  1476.         GetRootTitleIcon(MENU3103_RINGTONE_COMPOSER),
  1477.         STR_GLOBAL_OK,
  1478.         IMG_GLOBAL_OK,
  1479.         STR_GLOBAL_BACK,
  1480.         IMG_GLOBAL_BACK,
  1481.         nItems,
  1482.         ItemList,
  1483.         (PU16) gIndexIconsImageList,
  1484.         0,
  1485.         0,
  1486.         0,
  1487.         guiBuffer);
  1488.     /* Register function for left soft key */
  1489.     SetLeftSoftkeyFunction(RngcGotoEditFinenameOpt, KEY_EVENT_UP);
  1490.     /* Register function for right soft key */
  1491.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1492.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1493. }
  1494. /*****************************************************************************
  1495.  * FUNCTION
  1496.  *  GetCompRingToneSaveOpt
  1497.  * DESCRIPTION
  1498.  *  Retrive the option index when editing filename
  1499.  * PARAMETERS
  1500.  *  nIndex      [IN]        Index of selected item
  1501.  * RETURNS
  1502.  *  void
  1503.  *****************************************************************************/
  1504. void GetCompRingToneSaveOpt(S32 nIndex)
  1505. {
  1506.     /*----------------------------------------------------------------*/
  1507.     /* Local Variables                                                */
  1508.     /*----------------------------------------------------------------*/
  1509.     /*----------------------------------------------------------------*/
  1510.     /* Code Body                                                      */
  1511.     /*----------------------------------------------------------------*/
  1512.     g_rngc_cntx.CurrHiliteItem = (U8) nIndex;
  1513.     switch (g_rngc_cntx.CurrHiliteItem)
  1514.     {
  1515.         case 0: /* Done */
  1516.             ClearKeyHandler(KEY_RIGHT_ARROW, KEY_EVENT_UP);
  1517.             break;
  1518.         case 1: /* Input Methods */
  1519.             SetKeyHandler(RngcGotoEditFinenameOpt, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1520.             break;
  1521.         default:
  1522.             break;
  1523.     }
  1524. }
  1525. /*****************************************************************************
  1526.  * FUNCTION
  1527.  *  RngcGotoEditFinenameOpt
  1528.  * DESCRIPTION
  1529.  *  Entry selected option when editing filename
  1530.  * PARAMETERS
  1531.  *  void
  1532.  * RETURNS
  1533.  *  void
  1534.  *****************************************************************************/
  1535. void RngcGotoEditFinenameOpt(void)
  1536. {
  1537.     /*----------------------------------------------------------------*/
  1538.     /* Local Variables                                                */
  1539.     /*----------------------------------------------------------------*/
  1540.     /*----------------------------------------------------------------*/
  1541.     /* Code Body                                                      */
  1542.     /*----------------------------------------------------------------*/
  1543.     switch (g_rngc_cntx.CurrHiliteItem)
  1544.     {
  1545.         case 0: /* Done */
  1546.             RngcDisplayPopupAfterSave();
  1547.             break;
  1548.         case 1: /* Input Methods */
  1549.             EntryInputMethodScreen();
  1550.             RegisterInputMethodScreenCloseFunction(GoBacknHistoryFromInputMethod);
  1551.             break;
  1552.         default:
  1553.             break;
  1554.     }
  1555. }
  1556. /*****************************************************************************
  1557.  * FUNCTION
  1558.  *  GoBacknHistoryFromInputMethod
  1559.  * DESCRIPTION
  1560.  *  Go back 1 history.
  1561.  * PARAMETERS
  1562.  *  void
  1563.  * RETURNS
  1564.  *  void
  1565.  *****************************************************************************/
  1566. void GoBacknHistoryFromInputMethod(void)
  1567. {
  1568.     /*----------------------------------------------------------------*/
  1569.     /* Local Variables                                                */
  1570.     /*----------------------------------------------------------------*/
  1571.     /*----------------------------------------------------------------*/
  1572.     /* Code Body                                                      */
  1573.     /*----------------------------------------------------------------*/
  1574.     GoBacknHistory(1);
  1575. }
  1576. /*****************************************************************************
  1577.  * FUNCTION
  1578.  *  RngcDisplayPopupAfterSave
  1579.  * DESCRIPTION
  1580.  *  Save composed tone and display corresponding popup screen
  1581.  * PARAMETERS
  1582.  *  void
  1583.  * RETURNS
  1584.  *  void
  1585.  *****************************************************************************/
  1586. void RngcDisplayPopupAfterSave(void)
  1587. {
  1588.     /*----------------------------------------------------------------*/
  1589.     /* Local Variables                                                */
  1590.     /*----------------------------------------------------------------*/
  1591.     S32 err;
  1592.     /*----------------------------------------------------------------*/
  1593.     /* Code Body                                                      */
  1594.     /*----------------------------------------------------------------*/
  1595.     err = SetSaveCompRingTone();
  1596.     if (err == 0)
  1597.     {
  1598.         DisplayPopup(
  1599.             (U8*) GetString(STR_GLOBAL_DONE),
  1600.             IMG_GLOBAL_ACTIVATED,
  1601.             0,
  1602.             UI_POPUP_NOTIFYDURATION_TIME,
  1603.             SAVE_TONE);
  1604.         DeleteUptoScrID(SCR_FMGR_EXPLORER);
  1605.     }
  1606.     else if (err == RC_DUP_FILENAME)
  1607.     {
  1608.         DisplayPopup(
  1609.             (U8*) GetString(STR_COMP_RINGTONE_DUPLICATE),
  1610.             IMG_GLOBAL_ERROR,
  1611.             0,
  1612.             UI_POPUP_NOTIFYDURATION_TIME,
  1613.             ERROR_TONE);
  1614.         DeleteUptoScrID(SCR_COMP_RINGTONE_SAVEFILE);
  1615.     }
  1616.     else if (err == RC_EMPTY_FILENAME)
  1617.     {
  1618.         DisplayPopup(
  1619.             (U8*) GetString(STR_COMP_RINGTONE_EMPTYFILENAME),
  1620.             IMG_GLOBAL_ERROR,
  1621.             0,
  1622.             UI_POPUP_NOTIFYDURATION_TIME,
  1623.             ERROR_TONE);
  1624.         DeleteUptoScrID(SCR_COMP_RINGTONE_SAVEFILE);
  1625.     }
  1626.     else
  1627.     {
  1628.         DisplayPopup(
  1629.             (PU8) GetString(GetFileSystemErrorString(err)),
  1630.             IMG_GLOBAL_ERROR,
  1631.             1,
  1632.             UI_POPUP_NOTIFYDURATION_TIME,
  1633.             ERROR_TONE);
  1634.         DeleteUptoScrID(SCR_COMP_RINGTONE_SAVEFILE);
  1635.     }
  1636. }
  1637. /*****************************************************************************
  1638.  * FUNCTION
  1639.  *  SetSaveCompRingTone
  1640.  * DESCRIPTION
  1641.  *  Save composed tone
  1642.  *  1. Generate file and save to file system.
  1643.  *  2. Insert entry into info table and save to NVRAM.
  1644.  * PARAMETERS
  1645.  *  void
  1646.  * RETURNS
  1647.  *  Error codes
  1648.  *****************************************************************************/
  1649. S32 SetSaveCompRingTone(void)
  1650. {
  1651.     /*----------------------------------------------------------------*/
  1652.     /* Local Variables                                                */
  1653.     /*----------------------------------------------------------------*/
  1654.     S8 filenameExt[16];
  1655.     S8 sFileBuf[RNGC_FILE_LEN + MAX_IMAGE_NAME_PATH_WIDTH];
  1656.     S8 sFileNewBuf[RNGC_FILE_LEN + MAX_IMAGE_NAME_PATH_WIDTH];
  1657.     S32 err = 0;
  1658.     /*----------------------------------------------------------------*/
  1659.     /* Code Body                                                      */
  1660.     /*----------------------------------------------------------------*/
  1661.     /* if user's input is empty */
  1662.     if (!pfnUnicodeStrlen((S8*) g_rngc_cntx.FileName))
  1663.     {
  1664.         return RC_EMPTY_FILENAME;
  1665.     }
  1666.     /* add file extension */
  1667.     if (pfnUnicodeStrcmp
  1668.         ((S8*) & g_rngc_cntx.
  1669.          FileName[pfnUnicodeStrlen(((S8*) g_rngc_cntx.FileName) - strlen((S8*) MELODY_FILE_EXTENSION)) *
  1670.                   ENCODING_LENGTH], (S8*) filenameExt))
  1671.     {
  1672.         AnsiiToUnicodeString((S8*) filenameExt, (S8*) MELODY_FILE_EXTENSION);
  1673.         pfnUnicodeStrcat((S8*) g_rngc_cntx.FileName, (S8*) filenameExt);
  1674.     }
  1675.     /* to check if there is some duplicated file name exits */
  1676.     if (g_rngc_cntx.CurrEditState)  /* rename or edit */
  1677.     {
  1678.         /* if the new filename is different from previous file name */
  1679.         if (pfnUnicodeStrcmp((S8*) g_rngc_cntx.FileName, (S8*) g_rngc_cntx.PrevFileName))
  1680.             if (IsCompToneExisted((S8*) g_rngc_cntx.FileName))
  1681.             {
  1682.                 return RC_DUP_FILENAME;
  1683.             }
  1684.     }
  1685.     else    /* add new file */
  1686.     {
  1687.         if (IsCompToneExisted((S8*) g_rngc_cntx.FileName))
  1688.         {
  1689.             return RC_DUP_FILENAME;
  1690.         }
  1691.     }
  1692.     switch (g_rngc_cntx.CurrEditState)
  1693.     {
  1694.         case ENUM_COMP_ADD:
  1695.         {
  1696.             err = GenerateMelodyFile((S8*) g_rngc_cntx.FileName);
  1697.             if (err != RC_SUCCESS)
  1698.             {
  1699.                 return err;
  1700.             }
  1701.             else
  1702.             {
  1703.                 FreeMemory();
  1704.             }
  1705.             break;
  1706.         }
  1707.         case ENUM_COMP_EDIT:
  1708.         {
  1709.             err = GenerateMelodyFile((S8*) g_rngc_cntx.FileName);
  1710.             if (err != RC_SUCCESS)
  1711.             {
  1712.                 return err;
  1713.             }
  1714.             else
  1715.             {
  1716.                 FreeMemory();
  1717.                 /* filename changed, delete previous file */
  1718.                 if (pfnUnicodeStrcmp((S8*) g_rngc_cntx.FileName, (S8*) g_rngc_cntx.PrevFileName))
  1719.                 {
  1720.                     GenerateCompleteComposeFileName((S8*) g_rngc_cntx.PrevFileName, (S8*) sFileBuf);
  1721.                     FS_Delete((U16*) sFileBuf); /* do not have to handle error case because there exits file sync mechanism */
  1722.                 }
  1723.             }
  1724.             break;
  1725.         }
  1726.         case ENUM_COMP_RENAME:
  1727.             pfnUnicodeStrcpy((S8*) sFileNewBuf, (S8*) RINGCOMPOSER_PATH);
  1728.             pfnUnicodeStrcpy((S8*) sFileBuf, (S8*) sFileNewBuf);
  1729.             pfnUnicodeStrcat((S8*) sFileBuf, (S8*) g_rngc_cntx.PrevFileName);
  1730.             pfnUnicodeStrcat((S8*) sFileNewBuf, (S8*) g_rngc_cntx.FileName);
  1731.             if (pfnUnicodeStrcmp(sFileBuf, sFileNewBuf))
  1732.             {
  1733.                 if ((err = pfrename(sFileBuf, sFileNewBuf)) < 0)
  1734.                 {
  1735.                     return err;
  1736.                 }
  1737.             }
  1738.             break;
  1739.         default:
  1740.             break;
  1741.     }
  1742.     err = RC_SUCCESS;
  1743.     return err;
  1744. }
  1745. /*****************************************************************************
  1746.  * FUNCTION
  1747.  *  GetComposedIMelodyInfo
  1748.  * DESCRIPTION
  1749.  *  Retrieve file info and total number of composed tones
  1750.  * PARAMETERS
  1751.  *  downloadAudioInfo       [IN/OUT]        Pointer to get file info
  1752.  * RETURNS
  1753.  *  total number of composed tones
  1754.  *****************************************************************************/
  1755. U8 GetComposedIMelodyInfo(DYNAUDIOINFO **downloadAudioInfo)
  1756. {
  1757. #if !defined(__MMI_FILE_MANAGER__)
  1758.     /*----------------------------------------------------------------*/
  1759.     /* Local Variables                                                */
  1760.     /*----------------------------------------------------------------*/
  1761.     /*----------------------------------------------------------------*/
  1762.     /* Code Body                                                      */
  1763.     /*----------------------------------------------------------------*/
  1764.     *downloadAudioInfo = g_rngc_cntx.RingToneInfo;
  1765.     return g_rngc_cntx.TotalTone;
  1766. #else /* !defined(__MMI_FILE_MANAGER__) */ 
  1767.     return 0;
  1768. #endif /* !defined(__MMI_FILE_MANAGER__) */ 
  1769. }
  1770. /*****************************************************************************
  1771.  * FUNCTION
  1772.  *  GetComposedIMelodyNameInFileSystem
  1773.  * DESCRIPTION
  1774.  *  Retrieve filename from id
  1775.  * PARAMETERS
  1776.  *  AudioId     [IN]        File index
  1777.  * RETURNS
  1778.  *  pointer of filename
  1779.  *****************************************************************************/
  1780. S8 *GetComposedIMelodyNameInFileSystem(U16 AudioId)
  1781. {
  1782. #if !defined(__MMI_FILE_MANAGER__)
  1783.     /*----------------------------------------------------------------*/
  1784.     /* Local Variables                                                */
  1785.     /*----------------------------------------------------------------*/
  1786.     U16 i;
  1787.     /*----------------------------------------------------------------*/
  1788.     /* Code Body                                                      */
  1789.     /*----------------------------------------------------------------*/
  1790.     if (AudioId >= COMPOSED_RINGTONE_BASE && AudioId <= COMPOSED_RINGTONE_BASE_END)
  1791.     {
  1792.         for (i = 0; i < g_rngc_cntx.TotalTone; i++)
  1793.         {
  1794.             if (g_rngc_cntx.RingToneInfo[i].AudioId == AudioId)
  1795.             {
  1796.                 return (S8*) g_rngc_cntx.RingToneInfo[i].AudioName;
  1797.             }
  1798.         }
  1799.     }
  1800. #endif /* !defined(__MMI_FILE_MANAGER__) */ 
  1801.     return NULL;
  1802. }
  1803. /*****************************************************************************
  1804.  * FUNCTION
  1805.  *  IsCompToneExisted
  1806.  * DESCRIPTION
  1807.  *  To check if file already exists
  1808.  * PARAMETERS
  1809.  *  filename        [IN]        Filename without path
  1810.  * RETURNS
  1811.  *  1 == true, 0 == false
  1812.  *****************************************************************************/
  1813. U8 IsCompToneExisted(S8 *filename)
  1814. {
  1815.     /*----------------------------------------------------------------*/
  1816.     /* Local Variables                                                */
  1817.     /*----------------------------------------------------------------*/
  1818.     S8 sFileBuf[RNGC_FILE_LEN + MAX_IMAGE_NAME_PATH_WIDTH];
  1819.     FILE_HANDLE h;
  1820.     /*----------------------------------------------------------------*/
  1821.     /* Code Body                                                      */
  1822.     /*----------------------------------------------------------------*/
  1823.     GenerateCompleteComposeFileName((S8*) filename, (S8*) sFileBuf);
  1824.     h = FS_Open((U16*) sFileBuf, FS_READ_ONLY);
  1825.     if (h > 0)
  1826.     {
  1827.         FS_Close(h);
  1828.         return 1;
  1829.     }
  1830.     return 0;
  1831. }
  1832. #endif /* defined(__MMI_RING_COMPOSER__) && defined(__MMI_IMELODY_SUPPORT__) */ // #if defined(__MMI_RING_COMPOSER__)
  1833. #endif /* _MMI_COMPOSERINGTONE_C */ // #ifndef _MMI_COMPOSERINGTONE_C