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

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) 2002
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11.  *
  12.  * Filename:
  13.  * ---------
  14.  *  jmms_store_handling.C
  15.  *
  16.  * Project:
  17.  * --------
  18.  *  MAUI
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *  This file conains the store APIs for interacting with Jatayu Store module
  23.  *
  24.  * Author:
  25.  * -------
  26.  * -------
  27.  *
  28.  *============================================================================
  29.  *             HISTORY
  30.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31.  *------------------------------------------------------------------------------
  32.  * removed!
  33.  *
  34.  * removed!
  35.  * removed!
  36.  * removed!
  37.  *
  38.  * removed!
  39.  * removed!
  40.  * removed!
  41.  *
  42.  * removed!
  43.  * removed!
  44.  * removed!
  45.  *
  46.  * removed!
  47.  * removed!
  48.  * removed!
  49.  *
  50.  * removed!
  51.  * removed!
  52.  * removed!
  53.  *
  54.  * removed!
  55.  * removed!
  56.  * removed!
  57.  *
  58.  * removed!
  59.  * removed!
  60.  * removed!
  61.  *
  62.  * removed!
  63.  * removed!
  64.  * removed!
  65.  *
  66.  * removed!
  67.  * removed!
  68.  * removed!
  69.  *
  70.  * removed!
  71.  * removed!
  72.  * removed!
  73.  *
  74.  * removed!
  75.  * removed!
  76.  * removed!
  77.  *
  78.  * removed!
  79.  * removed!
  80.  * removed!
  81.  *
  82.  *------------------------------------------------------------------------------
  83.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  84.  *============================================================================
  85.  ****************************************************************************/
  86. #ifndef _MMI_JMMSSTOREHANDLING_C
  87. #define _MMI_JMMSSTOREHANDLING_C
  88. /***************************************************************************** 
  89. * Include
  90. *****************************************************************************/
  91. #include "MMI_features.h"
  92. #if (defined (JATAAYU_SUPPORT) && defined(MMS_SUPPORT))
  93. #include "PixtelDataTypes.h"
  94. #include "Unicodexdcl.h"
  95. #include "HistoryGprot.h"
  96. #include "GlobalDefs.h"
  97. #include "SettingProfile.h"
  98. #include "DebugInitDef.h"
  99. #include "CommonScreens.h"
  100. #include "EventsGprot.h"
  101. #include "wgui_inputs.h"
  102. #include "wgui_categories.h"
  103. #include "wgui_categories_inputs.h"
  104. #include "MainMenuDef.h"
  105. #include <ddl.h>
  106. #include <jcal.h>
  107. #include <ddlbase.h>
  108. #include <MessagingDataTypes.h>
  109. #include <MessagingAPI.h>
  110. #include "JMMSConfig.h"
  111. #include "JMMSMessageSettings.h"
  112. #include "JMMSCoreAPI.h"
  113. #include "JMMSDrafts.h"
  114. #include "JMMSExdcl.h"
  115. #include "JMMSCompose.h"
  116. #include "JMMSGprot.h"
  117. #include "JMMSInbox.h"
  118. #include "JMMSJSRHandler.h"
  119. #include "JMMSMainMMS.h"
  120. #include "JMMSMessageSettingsUtils.h"
  121. #include "JMMSOutbox.h"
  122. #include "JMMSProtocols.h"
  123. #include "JMMSPushHandling.h"
  124. #include "JMMSResEnum.h"
  125. #include "JMMSSent.h"
  126. #include "JMMSStoreHandling.h"
  127. #include "JMMSStructs.h"
  128. #include "JMMSTemplates.h"
  129. #include "JMMSUseDetails.h"
  130. #include "JMMSView.h"
  131. #include "JMMSWriteMMS.h"
  132. #include "NVRAMType.h"
  133. #include "NVRAMProt.h"
  134. #include "NVRAMEnum.h"
  135. #include "PrvStoreDataTypes.h"
  136. #include "PrvStoreHandleInterfaces.h"
  137. #include "JSRProts.h"
  138. //PMT VIKAS START 20060325
  139. //For size calculation.
  140. #include "FileMgr.h"
  141. /* PMT VIKAS END 20060325 */
  142. /***************************************************************************** 
  143. * Define
  144. *****************************************************************************/
  145. /***************************************************************************** 
  146. * Typedef 
  147. *****************************************************************************/
  148. /***************************************************************************** 
  149. * Local Variable
  150. *****************************************************************************/
  151. /***************************************************************************** 
  152. * Local Function
  153. *****************************************************************************/
  154. /***************************************************************************** 
  155. * Global Variable
  156. *****************************************************************************/
  157. U64 g_jmms_normal_msgid = MMI_JMMS_MAX_JAVA_MSG_ID;
  158. U64 g_jmms_java_msgid = 0;
  159. /***************************************************************************** 
  160. * Global Function
  161. *****************************************************************************/
  162. extern void mmi_jmms_create_template_messages(void);
  163. /*****************************************************************************
  164.  * FUNCTION
  165.  *  mmi_jmms_get_normal_msgid_value_from_nvram
  166.  * DESCRIPTION
  167.  *  
  168.  * PARAMETERS
  169.  *  void
  170.  * RETURNS
  171.  *  void
  172.  *****************************************************************************/
  173. void mmi_jmms_get_normal_msgid_value_from_nvram(void)
  174. {
  175.     /*----------------------------------------------------------------*/
  176.     /* Local Variables                                                */
  177.     /*----------------------------------------------------------------*/
  178.     S16 error;
  179.     /*----------------------------------------------------------------*/
  180.     /* Code Body                                                      */
  181.     /*----------------------------------------------------------------*/
  182.     ReadValue(NVRAM_JMMS_NORMAL_MESSAGE_ID, &g_jmms_normal_msgid, DS_DOUBLE, &error);
  183.     if (g_jmms_normal_msgid > (0xFFFFFFFF))    // COMPILER WARNING REMOVAL
  184.     {
  185.         g_jmms_normal_msgid = MMI_JMMS_MAX_JAVA_MSG_ID;
  186.         WriteValue(NVRAM_JMMS_NORMAL_MESSAGE_ID, &g_jmms_normal_msgid, DS_DOUBLE, &error);
  187.     }
  188. }
  189. /*****************************************************************************
  190.  * FUNCTION
  191.  *  mmi_jmms_get_java_msgid_value_from_nvram
  192.  * DESCRIPTION
  193.  *  
  194.  * PARAMETERS
  195.  *  void
  196.  * RETURNS
  197.  *  void
  198.  *****************************************************************************/
  199. void mmi_jmms_get_java_msgid_value_from_nvram(void)
  200. {
  201.     /*----------------------------------------------------------------*/
  202.     /* Local Variables                                                */
  203.     /*----------------------------------------------------------------*/
  204.     S16 error;
  205.     /*----------------------------------------------------------------*/
  206.     /* Code Body                                                      */
  207.     /*----------------------------------------------------------------*/
  208.     ReadValue(NVRAM_JMMS_JAVA_MESSAGE_ID, &g_jmms_java_msgid, DS_DOUBLE, &error);
  209.     if (g_jmms_java_msgid > (0xFFFFFFFF))    // COMPILER WARNING REMOVAL
  210.     {
  211.         g_jmms_java_msgid = 0;
  212.         WriteValue(NVRAM_JMMS_JAVA_MESSAGE_ID, &g_jmms_java_msgid, DS_DOUBLE, &error);
  213.     }
  214. }
  215. /*****************************************************************************
  216.  * FUNCTION
  217.  *  mmi_jmms_set_normal_msgid_value_to_nvram
  218.  * DESCRIPTION
  219.  *  
  220.  * PARAMETERS
  221.  *  void
  222.  * RETURNS
  223.  *  void
  224.  *****************************************************************************/
  225. void mmi_jmms_set_normal_msgid_value_to_nvram(void)
  226. {
  227.     /*----------------------------------------------------------------*/
  228.     /* Local Variables                                                */
  229.     /*----------------------------------------------------------------*/
  230.     S16 error;
  231.     /*----------------------------------------------------------------*/
  232.     /* Code Body                                                      */
  233.     /*----------------------------------------------------------------*/
  234.     WriteValue(NVRAM_JMMS_NORMAL_MESSAGE_ID, &g_jmms_normal_msgid, DS_DOUBLE, &error);
  235. }
  236. /*****************************************************************************
  237.  * FUNCTION
  238.  *  mmi_jmms_set_java_msgid_value_to_nvram
  239.  * DESCRIPTION
  240.  *  
  241.  * PARAMETERS
  242.  *  void
  243.  * RETURNS
  244.  *  void
  245.  *****************************************************************************/
  246. void mmi_jmms_set_java_msgid_value_to_nvram(void)
  247. {
  248.     /*----------------------------------------------------------------*/
  249.     /* Local Variables                                                */
  250.     /*----------------------------------------------------------------*/
  251.     S16 error;
  252.     /*----------------------------------------------------------------*/
  253.     /* Code Body                                                      */
  254.     /*----------------------------------------------------------------*/
  255.     WriteValue(NVRAM_JMMS_JAVA_MESSAGE_ID, &g_jmms_java_msgid, DS_DOUBLE, &error);
  256. }
  257. /*****************************************************************************
  258.  * FUNCTION
  259.  *  mmi_jmms_get_folder_list
  260.  * DESCRIPTION
  261.  *  This function is to get the folder list from store
  262.  * PARAMETERS
  263.  *  folder_list     [IN]        - list of folders
  264.  * RETURNS
  265.  *  void
  266.  *****************************************************************************/
  267. JC_RETCODE mmi_jmms_get_folder_list(FOLDER_INFO **folder_list)
  268. {
  269.     /*----------------------------------------------------------------*/
  270.     /* Local Variables                                                */
  271.     /*----------------------------------------------------------------*/
  272.     FOLDER_INFO *pFolderList = NULL;
  273.     JC_RETCODE eRet = JC_OK;
  274.     /*----------------------------------------------------------------*/
  275.     /* Code Body                                                      */
  276.     /*----------------------------------------------------------------*/
  277.     eRet = mmi_jmms_jdi_get_folders(g_jmms_context->hStoreHandle, &pFolderList);
  278.     if (JC_OK == eRet)
  279.     {
  280.         *folder_list = pFolderList;
  281.     }
  282.     else
  283.     {
  284.         folder_list = NULL;
  285.     }
  286.     return eRet;
  287. }
  288. /*****************************************************************************
  289.  * FUNCTION
  290.  *  mmi_jmms_get_messages_list
  291.  * DESCRIPTION
  292.  *  This function is to get the msg list from a folder
  293.  * PARAMETERS
  294.  *  pFolderName             [?]         [?]
  295.  *  msg_list                [IN]        - list of mesages
  296.  *  retrieve_filters        [?]         [?]
  297.  *  folder_name   - name of folder from which messages are to fetch out(?)(?)
  298.  * RETURNS
  299.  *  void
  300.  *****************************************************************************/
  301. JC_RETCODE mmi_jmms_get_messages_list(S8 *pFolderName, MESSAGE_LIST **msg_list, RETRIEVE_FILTERS *retrieve_filters)
  302. {
  303.     /*----------------------------------------------------------------*/
  304.     /* Local Variables                                                */
  305.     /*----------------------------------------------------------------*/
  306.     JC_RETCODE eRet = JC_OK;
  307.     /*----------------------------------------------------------------*/
  308.     /* Code Body                                                      */
  309.     /*----------------------------------------------------------------*/
  310.     eRet = mmi_jmms_set_active_folder(pFolderName);
  311.     if (JC_OK != eRet)
  312.     {
  313.         return eRet;
  314.     }
  315.     eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, msg_list, retrieve_filters);
  316.     if (JC_OK != eRet)
  317.     {
  318.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  319.         {
  320.             eRet = mmi_jmms_restore_folder_info();
  321.             if (eRet == JC_OK)
  322.             {
  323.                 eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, msg_list, retrieve_filters);
  324.             }
  325.         }
  326.     }
  327.     return eRet;
  328. }
  329. /*****************************************************************************
  330.  * FUNCTION
  331.  *  mmi_mms_get_number_of_messages
  332.  * DESCRIPTION
  333.  *  This function is to get the total number of messages present in a folder
  334.  * PARAMETERS
  335.  *  pFolderName             [?]     [?]
  336.  *  total_num_messages      [?]     [?]     - list of mesages
  337.  *  folder_name   - name of folder from which messages are to fetch out(?)(?)
  338.  * RETURNS
  339.  *  void
  340.  *****************************************************************************/
  341. JC_RETCODE mmi_mms_get_number_of_messages(S8 *pFolderName, U8 *total_num_messages)
  342. {
  343.     /*----------------------------------------------------------------*/
  344.     /* Local Variables                                                */
  345.     /*----------------------------------------------------------------*/
  346.     U32 len = 0;
  347.     S8 *folder_name = NULL;
  348.     JC_RETCODE eRet = JC_OK;
  349.     FOLDER_INFO *folder_info = NULL;
  350.     FOLDER_LIST *pFolderList = NULL;
  351.     /*----------------------------------------------------------------*/
  352.     /* Code Body                                                      */
  353.     /*----------------------------------------------------------------*/
  354.     *total_num_messages = 0;
  355.     len = (strlen((PS8) pFolderName) + 1) * ENCODING_LENGTH;
  356.     folder_name = (PS8) jdd_MemAlloc(sizeof(S8), len);
  357.     if (NULL == folder_name)
  358.     {
  359.         return JC_ERR_MEMORY_ALLOCATION;
  360.     }
  361.     AnsiiToUnicodeString((PS8) folder_name, (PS8) pFolderName);
  362.     /* manish changing */
  363.     eRet = mmi_jmms_jdi_get_folders(g_jmms_context->hStoreHandle, &folder_info);
  364.     if (JC_OK != eRet)
  365.     {
  366.         goto END;
  367.     }
  368.     pFolderList = folder_info->pFolderList;
  369.     while (pFolderList != NULL)
  370.     {
  371.         if (pfnUnicodeStrcmp((S8*) pFolderList->pFolderName, (S8*) folder_name) == NULL)
  372.         {
  373.             *total_num_messages = pFolderList->uiTotalMessages;
  374.             break;
  375.         }
  376.         pFolderList = pFolderList->pNext;
  377.     }
  378.   END:
  379.     if (folder_name != NULL)
  380.     {
  381.         jdd_MemFree(folder_name);
  382.         folder_name = NULL;
  383.     }
  384.     return eRet;
  385. }
  386. /*****************************************************************************
  387.  * FUNCTION
  388.  *  mmi_jmms_get_total_number_of_messages
  389.  * DESCRIPTION
  390.  *  
  391.  * PARAMETERS
  392.  *  total_num_messages      [?]     [?]
  393.  * RETURNS
  394.  *  
  395.  *****************************************************************************/
  396. JC_RETCODE mmi_jmms_get_total_number_of_messages(U8 *total_num_messages)
  397. {
  398.     /*----------------------------------------------------------------*/
  399.     /* Local Variables                                                */
  400.     /*----------------------------------------------------------------*/
  401.     U32 i = 0;
  402.     U8 msgs = 0;
  403.     S8 *folder_list[MMI_JMMS_NO_OF_SYSTEM_FOLDERS] = {MMI_JMMS_INBOX,
  404.         MMI_JMMS_OUTBOX,
  405.         MMI_JMMS_SENT,
  406.         MMI_JMMS_DRAFTS,
  407.         MMI_JMMS_TEMPLATES
  408.     };
  409.     JC_RETCODE eRet = JC_OK;
  410.     /*----------------------------------------------------------------*/
  411.     /* Code Body                                                      */
  412.     /*----------------------------------------------------------------*/
  413.     *total_num_messages = 0;
  414.     for (i = 0; i < MMI_JMMS_NO_OF_SYSTEM_FOLDERS; i++)
  415.     {
  416.         msgs = 0;
  417.         eRet = mmi_mms_get_number_of_messages(folder_list[i], &msgs);
  418.         if (eRet != JC_OK)
  419.         {
  420.             return eRet;
  421.         }
  422.         *total_num_messages += msgs;
  423.     }
  424.     return eRet;
  425. }
  426. /* PMT VIKAS START 20060325 */
  427. /*****************************************************************************
  428.  * FUNCTION
  429.  *  mmi_jmms_get_free_size_for_mms
  430.  * DESCRIPTION
  431.  *  This function is to get the total free space for mms
  432.  * PARAMETERS
  433.  *  disk_free_space     [?]     [?]
  434.  * RETURNS
  435.  *  void
  436.  *****************************************************************************/
  437. void mmi_jmms_get_free_size_for_mms(U64 *disk_free_space)
  438. {
  439.     /*----------------------------------------------------------------*/
  440.     /* Local Variables                                                */
  441.     /*----------------------------------------------------------------*/
  442.     S8 buf[6];
  443.     FS_HANDLE file_handle;
  444.     FS_DiskInfo disk_info;
  445.     S32 fs_RetDrv = FS_GetDrive(FS_DRIVE_I_SYSTEM, 1, FS_NO_ALT_DRIVE);
  446.     /*----------------------------------------------------------------*/
  447.     /* Code Body                                                      */
  448.     /*----------------------------------------------------------------*/
  449.     *disk_free_space = 0;
  450. #ifdef MMS_IN_LARGE_STORAGE
  451.     /* Order: 1. Invisible NAND 2. Visible NAND 3. visible NOR 4. Invisible NOR */
  452.     fs_RetDrv = FS_GetDrive(FS_DRIVE_V_NORMAL, 2, FS_DRIVE_V_NORMAL | FS_DRIVE_I_SYSTEM);
  453. #endif /* MMS_IN_LARGE_STORAGE */ 
  454.     sprintf(buf, "%c:\", (U8) fs_RetDrv);
  455.     memset(subMenuData, 0, (FMGR_MAX_PATH_LEN + FMGR_MAX_FILE_LEN) * ENCODING_LENGTH);
  456.     AnsiiToUnicodeString((S8*) subMenuData, (S8*) buf);
  457.     file_handle = FS_Open((kal_uint16*) subMenuData, FS_OPEN_DIR | FS_READ_ONLY);
  458.     if(file_handle)
  459.     {
  460.         FS_GetDiskInfo((PU16) subMenuData, &disk_info, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);
  461.         *disk_free_space = disk_info.FreeClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
  462.         FS_Close(file_handle);
  463.     }
  464. }
  465. /* PMT VIKAS END 20060325 */
  466. /*****************************************************************************
  467.  * FUNCTION
  468.  *  mmi_jmms_sys_folders_exist
  469.  * DESCRIPTION
  470.  *  This function is check whether MMS Sys folders have been created or not
  471.  * PARAMETERS
  472.  *  void
  473.  * RETURNS
  474.  *  void
  475.  *****************************************************************************/
  476. S32 mmi_jmms_sys_folders_exist(void)
  477. {
  478. JDD_FSHANDLE fs_handle = NULL;
  479.     JC_INT32 drive_letter = FS_GetDrive(FS_DRIVE_I_SYSTEM, 1, FS_NO_ALT_DRIVE);
  480.     JC_INT8 mms_folder_path_ascii[FMGR_MAX_PATH_LEN + 1];
  481.     JC_CHAR mms_folder_path_ucs2[(FMGR_MAX_PATH_LEN + 1) * ENCODING_LENGTH];
  482.     JC_CHAR *mms_sys_filepath_ucs2 = NULL;
  483.     JC_RETCODE eRet = JC_OK;
  484.     #ifdef MMS_IN_LARGE_STORAGE
  485.     /* Order: 1. Invisible NAND 2. Visible NAND 3. visible NOR 4. Invisible NOR */
  486.     drive_letter = FS_GetDrive(FS_DRIVE_I_SYSTEM, 2, FS_DRIVE_V_NORMAL | FS_DRIVE_I_SYSTEM);
  487.     #endif /* MMS_IN_LARGE_STORAGE */ 
  488.     if (fs_handle == NULL)
  489.     {
  490.         if (jdd_FSInitialize(&fs_handle) != JC_OK)
  491.         {
  492.             return -1;
  493.         }
  494.     }
  495.     jdi_UtilsCharToTchar(&mms_sys_filepath_ucs2, JDD_FS_MMS_SYS_FOLDER);
  496.     if (jdd_FSIsDirExist(fs_handle, mms_sys_filepath_ucs2) == E_FALSE)
  497.     {
  498.         eRet=-1;
  499.         goto error;
  500.     }
  501.     sprintf(mms_folder_path_ascii, "%c:\@mms", drive_letter);
  502.     app_ansii_to_unicodestring((kal_int8*) mms_folder_path_ucs2, (kal_int8*) mms_folder_path_ascii);
  503.     if (jdd_FSIsDirExist(fs_handle, mms_folder_path_ucs2) == E_FALSE)
  504.     {
  505.         eRet=-1;
  506.         goto error;
  507.     }
  508. error:
  509.     jdd_MemFree(mms_sys_filepath_ucs2);
  510.     if (fs_handle != NULL)
  511.     {
  512.         jdd_FSDeinitialize(fs_handle);
  513.         fs_handle = NULL;
  514.     }
  515.     return eRet;
  516. }
  517. /*****************************************************************************
  518.  * FUNCTION
  519.  *  mmi_jmms_init_store
  520.  * DESCRIPTION
  521.  *  This function is to initialize the store.
  522.  * PARAMETERS
  523.  *  void
  524.  * RETURNS
  525.  *  void
  526.  *****************************************************************************/
  527. void mmi_jmms_init_store(void)
  528. {
  529.     /*----------------------------------------------------------------*/
  530.     /* Local Variables                                                */
  531.     /*----------------------------------------------------------------*/
  532.     JC_RETCODE eRet = JC_OK;
  533.     /* FOLDER_INFO          *folder_info=NULL; */
  534.     JC_CHAR *folder_name = NULL;
  535.     U32 len = 0;
  536.     U32 i = 0;
  537.     S8 *folder_list[MMI_JMMS_NO_OF_SYSTEM_FOLDERS] = {MMI_JMMS_INBOX,
  538.         MMI_JMMS_OUTBOX,
  539.         MMI_JMMS_SENT,
  540.         MMI_JMMS_DRAFTS,
  541.         MMI_JMMS_TEMPLATES
  542.     };
  543.     /*----------------------------------------------------------------*/
  544.     /* Code Body                                                      */
  545.     /*----------------------------------------------------------------*/
  546.     eRet = mmi_jmms_jdi_store_init(&g_jmms_context->hStoreHandle);
  547.     if(mmi_jmms_sys_folders_exist()!=JC_OK)
  548.     {
  549.         g_jmms_context->init_done = JMMS_NOT_INITIALIZED;
  550.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "mmi_jmms_init_store: %d",g_jmms_context->init_done ));
  551. return;
  552.     }
  553.     if (JC_OK != eRet)
  554.     {
  555.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  556.         {
  557.             eRet = mmi_jmms_restore_folder_info();
  558.             if (eRet != JC_OK)
  559.             {
  560.                 ASSERT(0);
  561.             }
  562.         }
  563.         else
  564.         {
  565.             ASSERT(0);
  566.         }
  567.     }
  568.     for (i = 0; i < MMI_JMMS_NO_OF_SYSTEM_FOLDERS; i++)
  569.     {
  570.         len = (strlen((S8*) folder_list[i]) + 1) * ENCODING_LENGTH;
  571.         folder_name = (JC_CHAR*) jdd_MemAlloc(sizeof(S8), len);
  572.         if (NULL == folder_name)
  573.         {
  574.             ASSERT(0);
  575.         }
  576.         AnsiiToUnicodeString((PS8) folder_name, (PS8) folder_list[i]);
  577.         eRet = mmi_jmms_jdi_create_folder(g_jmms_context->hStoreHandle, (JC_CHAR*) folder_name, NULL);
  578.         /* don't free memory on success. It will be used in Store. */
  579.         if (eRet != JC_OK)
  580.         {
  581.             jdd_MemFree(folder_name);
  582. if(eRet!=JC_ERR_STORE_FOLDER_ALREADY_EXIST)
  583. {
  584. g_jmms_context->init_done = JMMS_NOT_INITIALIZED;
  585.                 PRINT_INFORMATION_2((MMI_TRACE_INFO, "mmi_jmms_init_store at bottom: %d",g_jmms_context->init_done ));
  586. return;
  587. }
  588.         }
  589.     }
  590. }
  591. /*****************************************************************************
  592.  * FUNCTION
  593.  *  mmi_jmms_create_templates_in_store
  594.  * DESCRIPTION
  595.  *  This function is to initialize the templates. Should always be called after Initializing ans syncing store
  596.  * PARAMETERS
  597.  *  void
  598.  * RETURNS
  599.  *  void
  600.  *****************************************************************************/
  601. void mmi_jmms_create_templates_in_store(void)
  602. {
  603.     /*----------------------------------------------------------------*/
  604.     /* Local Variables                                                */
  605.     /*----------------------------------------------------------------*/
  606.     JC_RETCODE eRet = JC_OK;
  607.     U8 num_mms = 0;
  608.     eRet = mmi_mms_get_number_of_messages("Templates", &num_mms);
  609.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "mmi_mms_get_number_of_messages returns eRet = %d, No MMS =%d", eRet,num_mms ));
  610.     if (eRet != JC_OK)
  611.     {
  612.         mmi_jmms_update_status_icon_indicator();
  613.         g_jmms_context->init_done = JMMS_TEMPLATES_INITIALIZED;/*we won't be creating templates so let's READY JMMS anyway*/
  614.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "mmi_jmms_create_templates_in_store: %d",g_jmms_context->init_done ));
  615.         return;
  616.     }
  617.     if (num_mms < __MMI_MMS_TEMPLATES_NUM__)
  618.     {
  619.         eRet = mmi_jmms_delete_all_message("Templates");
  620.         ASSERT(!(eRet != JC_OK && num_mms > 0));
  621.         mmi_jmms_create_template_messages();
  622.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "mmi_jmms_create_templates_in_store returns from second: %d ",num_mms));
  623.     }
  624.     else
  625.     {
  626.         g_jmms_context->init_done = JMMS_TEMPLATES_INITIALIZED;
  627.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "mmi_jmms_create_templates_in_store at bottom: %d",g_jmms_context->init_done ));
  628.     }
  629.     mmi_jmms_update_status_icon_indicator();
  630.     return;
  631. }
  632. /*****************************************************************************
  633.  * FUNCTION
  634.  *  mmi_jmms_de_init_store
  635.  * DESCRIPTION
  636.  *  This function is to deinitialize the store.
  637.  * PARAMETERS
  638.  *  void
  639.  * RETURNS
  640.  *  void
  641.  *****************************************************************************/
  642. void mmi_jmms_de_init_store(void)
  643. {
  644.     /*----------------------------------------------------------------*/
  645.     /* Local Variables                                                */
  646.     /*----------------------------------------------------------------*/
  647.     JC_RETCODE eRet = JC_OK;
  648.     /*----------------------------------------------------------------*/
  649.     /* Code Body                                                      */
  650.     /*----------------------------------------------------------------*/
  651.     if (g_jmms_context != NULL)
  652.     {
  653.         eRet = mmi_jmms_jdi_store_dinit(g_jmms_context->hStoreHandle);
  654.         if (eRet == JC_OK)
  655.         {
  656.             g_jmms_context->hStoreHandle = NULL;
  657.         }
  658.     }
  659. }
  660. /*****************************************************************************
  661.  * FUNCTION
  662.  *  mmi_jmms_restore_folder_info
  663.  * DESCRIPTION
  664.  *  
  665.  * PARAMETERS
  666.  *  void
  667.  * RETURNS
  668.  *  
  669.  *****************************************************************************/
  670. JC_RETCODE mmi_jmms_restore_folder_info(void)
  671. {
  672.     /*----------------------------------------------------------------*/
  673.     /* Local Variables                                                */
  674.     /*----------------------------------------------------------------*/
  675.     JC_RETCODE eRet = JC_OK;
  676.     JC_CHAR *folder_name = NULL;
  677.     U32 len = 0;
  678.     U32 i = 0;
  679.     S8 *folder_list[MMI_JMMS_NO_OF_SYSTEM_FOLDERS] = {MMI_JMMS_INBOX,
  680.         MMI_JMMS_OUTBOX,
  681.         MMI_JMMS_SENT,
  682.         MMI_JMMS_DRAFTS,
  683.         MMI_JMMS_TEMPLATES
  684.     };
  685.     /*----------------------------------------------------------------*/
  686.     /* Code Body                                                      */
  687.     /*----------------------------------------------------------------*/
  688.     eRet = mmi_jmms_jdi_store_restore(g_jmms_context->hStoreHandle);
  689.     if (eRet != JC_OK)
  690.     {
  691.         ASSERT(0);
  692.     }
  693.     eRet = mmi_jmms_jdi_store_dinit(g_jmms_context->hStoreHandle);
  694.     if (eRet != JC_OK)
  695.     {
  696.         ASSERT(0);
  697.     }
  698.     g_jmms_context->hStoreHandle = NULL;
  699.     eRet = mmi_jmms_jdi_store_init(&g_jmms_context->hStoreHandle);
  700.     if (eRet != JC_OK)
  701.     {
  702.         ASSERT(0);
  703.     }
  704.     for (i = 0; i < MMI_JMMS_NO_OF_SYSTEM_FOLDERS; i++)
  705.     {
  706.         JC_RETCODE eRet_temp = JC_OK;
  707.         len = (strlen((S8*) folder_list[i]) + 1) * ENCODING_LENGTH;
  708.         folder_name = (JC_CHAR*) jdd_MemAlloc(sizeof(S8), len);
  709.         if (NULL == folder_name)
  710.         {
  711.             ASSERT(0);
  712.         }
  713.         AnsiiToUnicodeString((PS8) folder_name, (PS8) folder_list[i]);
  714.         eRet_temp = mmi_jmms_jdi_create_folder(g_jmms_context->hStoreHandle, (JC_CHAR*) folder_name, NULL);
  715.         /* don't free memory on success. It will be used in Store. */
  716.         if (eRet_temp != JC_OK)
  717.         {
  718.             jdd_MemFree(folder_name);
  719.         }
  720.     }
  721.     return eRet;
  722. }
  723. /*****************************************************************************
  724.  * FUNCTION
  725.  *  mmi_jmms_delete_message_as_per_id
  726.  * DESCRIPTION
  727.  *  This function is to delete the message from the store.
  728.  * PARAMETERS
  729.  *  msgId [IN]         Message Id
  730.  * RETURNS
  731.  *  JC_RETCODE
  732.  *****************************************************************************/
  733. void mmi_jmms_delete_message_as_per_id(U32 msgId)
  734. {
  735.     /*----------------------------------------------------------------*/
  736.     /* Local Variables                                                */
  737.     /*----------------------------------------------------------------*/
  738.     MESSAGE_LIST *pMessageList = NULL;
  739.     MESSAGE_LIST *pTempMessageList = NULL;
  740.     S8 fname[100];
  741.     U32 msgIndex = 0;
  742.     JC_RETCODE eRet = JC_OK;
  743.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  744.     /*----------------------------------------------------------------*/
  745.     /* Code Body                                                      */
  746.     /*----------------------------------------------------------------*/
  747.     memset(fname, 0, 100);
  748.     mmi_jmms_get_folder_name_from_folderId(JSR_INBOX, fname);
  749.     /* /manish chnging here 0n 2 Feb */
  750.     StoreRetFilter.uiStartIndex = 1;
  751.     StoreRetFilter.uiNumMessage = 0;
  752.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  753.     mmi_jmms_get_messages_list((S8*) fname, &pMessageList, &StoreRetFilter);
  754.     pTempMessageList = pMessageList;
  755.     while (pTempMessageList)
  756.     {
  757.         msgIndex++;
  758.     #ifdef __MMI_UNIFIED_MESSAGE__
  759.         if ((pTempMessageList->uiExtraBytes & 0x00FFFFFF) == msgId)     /* msgId is stored in the extra bytes of message list. */
  760.     #else 
  761.         if (pTempMessageList->uiExtraBytes == msgId)    /* msgId is stored in the extra bytes of message list. */
  762.     #endif 
  763.         {
  764.             eRet = mmi_jmms_delete_message(fname, msgIndex);
  765. if(eRet == JC_OK)
  766. mmi_jmms_delete_msg_status(msgIndex);
  767.             break;
  768.         }
  769.         pTempMessageList = pTempMessageList->pNext;
  770.     }
  771. }
  772. /*****************************************************************************
  773.  * FUNCTION
  774.  *  mmi_jmms_delete_message
  775.  * DESCRIPTION
  776.  *  This function is to delete the message from the store.
  777.  * PARAMETERS
  778.  *  pFolderName     [?]         [?]
  779.  *  uiMsgIndex      [IN]        - index of the message
  780.  *  folder_name   - name of folder from where the message to be deleted(?)(?)
  781.  * RETURNS
  782.  *  JC_RETCODE
  783.  *****************************************************************************/
  784. JC_RETCODE mmi_jmms_delete_message(S8 *pFolderName, JC_UINT32 uiMsgIndex)
  785. {
  786.     /*----------------------------------------------------------------*/
  787.     /* Local Variables                                                */
  788.     /*----------------------------------------------------------------*/
  789.     MESSAGE_LIST *pMessageList = NULL;
  790.     JC_RETCODE eRet = JC_OK;
  791.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  792.     U8 number_mms = 0;
  793.     /*----------------------------------------------------------------*/
  794.     /* Code Body                                                      */
  795.     /*----------------------------------------------------------------*/
  796.     eRet = mmi_jmms_set_active_folder(pFolderName);
  797.     if (JC_OK != eRet)
  798.     {
  799.         return eRet;
  800.     }
  801.     StoreRetFilter.uiStartIndex = uiMsgIndex;
  802.     StoreRetFilter.uiNumMessage = 1;
  803.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  804.     eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  805.     if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  806.     {
  807.         eRet = mmi_jmms_restore_folder_info();
  808.         if (eRet == JC_OK)
  809.         {
  810.             eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  811.         }
  812.     }
  813.     if (eRet != JC_OK)
  814.     {
  815.         return eRet;
  816.     }
  817.     eRet = mmi_jmms_jdi_delete_msg(g_jmms_context->hStoreHandle, uiMsgIndex);
  818.     if (JC_OK != eRet)
  819.     {
  820.         return eRet;
  821.     }
  822. #ifdef __MMI_UNIFIED_MESSAGE__
  823.     if (g_jmms_context->msg_handle != NULL)
  824.     {
  825.         eRet = mmi_jmms_jdi_msg_deinit(g_jmms_context->msg_handle);
  826.         if (JC_OK != eRet)
  827.         {
  828.             return eRet;
  829.         }
  830.         g_jmms_context->msg_handle = NULL;
  831.     }
  832. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  833.     eRet = mmi_jmms_jdi_update_msg_list(g_jmms_context->hStoreHandle, E_FALSE);
  834.     if (JC_OK != eRet)
  835.     {
  836.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  837.         {
  838.             eRet = mmi_jmms_restore_folder_info();
  839.         }
  840.     }
  841.     if (eRet == JC_OK)
  842.     {
  843.         eRet = mmi_jmms_get_total_number_of_messages(&number_mms);
  844.         if (eRet != JC_OK)
  845.         {
  846.             return eRet;
  847.         }
  848.         if (number_mms < MAX_POSSIBLE_MESSAGES)
  849.         {
  850.             mmi_jmms_remove_memory_full_node_if_present();
  851.         }
  852.     }
  853.     /* PMT VIKAS START 20060405 */
  854.     mmi_jmms_update_status_icon_indicator();
  855.     /* PMT VIKAS END 20060405 */
  856.     g_jmms_context->is_unread_msg_deleted = 0;
  857.     if (strcmp(pFolderName, MMI_JMMS_INBOX) == 0)
  858.     {
  859.         if (g_jmms_context->is_unread_msg_deleted == 1)
  860.         {
  861.             mmi_jmms_handle_read_report(g_jmms_context->MsgHeader_type_p);
  862.         }
  863.     }
  864.     return eRet;
  865. }
  866. /*****************************************************************************
  867.  * FUNCTION
  868.  *  mmi_jmms_save_message_buffer_in_Store
  869.  * DESCRIPTION
  870.  *  
  871.  * PARAMETERS
  872.  *  pFolderName     [?]         [?]
  873.  *  uiMsgIndex      [?]         [?]
  874.  *  MsgHeaders      [?]         [?]
  875.  *  Content         [?]         [?]
  876.  *  extraBytes      [IN]        
  877.  * RETURNS
  878.  *  
  879.  *****************************************************************************/
  880. JC_RETCODE mmi_jmms_save_message_buffer_in_Store(
  881.             S8 *pFolderName,
  882.             JC_UINT32 *uiMsgIndex,
  883.             MESSAGE_HEADERS *MsgHeaders,
  884.             CONTENT_DATA *Content,
  885.             JC_UINT32 *extraBytes)
  886. {
  887.     /*----------------------------------------------------------------*/
  888.     /* Local Variables                                                */
  889.     /*----------------------------------------------------------------*/
  890.     U32 len = 0;
  891.     S8 *folder_name = NULL;
  892.     JC_RETCODE eRet = JC_OK;
  893.     U32 msgId = 0;
  894.     U8 number_mms = 0;
  895.     //      MMI_BOOL isJavaMsg = MMI_FALSE;
  896.     //   JC_INT8 *content_type = NULL;
  897.     /*----------------------------------------------------------------*/
  898.     /* Code Body                                                      */
  899.     /*----------------------------------------------------------------*/
  900.     /* /check whether Total msgs count have been reached to max limit */
  901.     eRet = mmi_jmms_get_total_number_of_messages(&number_mms);
  902.     if (eRet != JC_OK)
  903.     {
  904.         return eRet;
  905.     }
  906.     if (number_mms >= MAX_POSSIBLE_MESSAGES)
  907.     {
  908.         mmi_jmms_add_memory_full_node_if_not_already();
  909.         return E_MEMORY_FULL_ERROR;
  910.     }
  911.     len = (strlen((PS8) pFolderName) + 1) * ENCODING_LENGTH;
  912.     folder_name = (PS8) jdd_MemAlloc(sizeof(S8), len);
  913.     if (NULL == folder_name)
  914.     {
  915.         return JC_ERR_MEMORY_ALLOCATION;
  916.     }
  917.     AnsiiToUnicodeString((PS8) folder_name, (PS8) pFolderName);
  918.     eRet = mmi_jmms_set_active_folder(pFolderName);
  919.     if (JC_OK != eRet)
  920.     {
  921.         jdd_MemFree(folder_name);
  922.         return eRet;
  923.     }
  924.     mmi_jmms_get_normal_msgid_value_from_nvram();
  925.     msgId = (U32) (g_jmms_normal_msgid) + 1;
  926.     if (msgId >= MMI_JMMS_MAX_NORMAL_MSG_ID)
  927.     {
  928.         msgId = MMI_JMMS_MAX_JAVA_MSG_ID + 1;
  929.     }
  930. #ifdef __MMI_UNIFIED_MESSAGE__
  931.     if (extraBytes != NULL)
  932.     {
  933.         *extraBytes = msgId | *extraBytes;
  934.         eRet = mmi_jmms_jdi_save_msg(
  935.                 g_jmms_context->hStoreHandle,
  936.                 (JC_CHAR*) folder_name,
  937.                 0,
  938.                 MsgHeaders,
  939.                 Content,
  940.                 uiMsgIndex,
  941.                 *extraBytes);
  942.     }
  943.     else
  944. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  945.         eRet = mmi_jmms_jdi_save_msg(
  946.                 g_jmms_context->hStoreHandle,
  947.                 (JC_CHAR*) folder_name,
  948.                 0,
  949.                 MsgHeaders,
  950.                 Content,
  951.                 uiMsgIndex,
  952.                 msgId);
  953.     if (JC_OK != eRet)
  954.     {
  955.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  956.         {
  957.             eRet = mmi_jmms_restore_folder_info();
  958.         }
  959.     }
  960.     else
  961.     {
  962.         g_jmms_normal_msgid = msgId;
  963.         mmi_jmms_set_normal_msgid_value_to_nvram();
  964.     }
  965.     jdd_MemFree(folder_name);
  966.     /* sandeep there is no need to update for saving notification
  967.     if (eRet == JC_OK)
  968.     {
  969.         mmi_jmms_update_status_icon_indicator();
  970.     }
  971.     */
  972.     return eRet;
  973. }
  974. /*****************************************************************************
  975.  * FUNCTION
  976.  *  mmi_jmms_get_message
  977.  * DESCRIPTION
  978.  *  
  979.  * PARAMETERS
  980.  *  pFolderName     [?]         [?]
  981.  *  Content         [?]         [?]
  982.  *  index           [IN]        
  983.  * RETURNS
  984.  *  
  985.  *****************************************************************************/
  986. JC_RETCODE mmi_jmms_get_message(S8 *pFolderName, CONTENT_DATA *Content, JC_INT32 index)
  987. {
  988.     /*----------------------------------------------------------------*/
  989.     /* Local Variables                                                */
  990.     /*----------------------------------------------------------------*/
  991.     JC_RETCODE eRet = JC_OK;
  992.     MESSAGE_LIST *pMessageList = NULL;
  993.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  994.     /*----------------------------------------------------------------*/
  995.     /* Code Body                                                      */
  996.     /*----------------------------------------------------------------*/
  997.     eRet = mmi_jmms_set_active_folder(pFolderName);
  998.     if (JC_OK != eRet)
  999.     {
  1000.         return eRet;
  1001.     }
  1002.     ///TODO:: need to check this step whether require and check if require get only for
  1003.     //index
  1004.     ///manish chnging here 0n 2 Feb
  1005.     StoreRetFilter.uiStartIndex = index;
  1006.     StoreRetFilter.uiNumMessage = 1;
  1007.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  1008.     eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1009.     if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  1010.     {
  1011.         eRet = mmi_jmms_restore_folder_info();
  1012.         if (eRet == JC_OK)
  1013.         {
  1014.             eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1015.         }
  1016.     }
  1017.     if (eRet == JC_OK)
  1018.     {
  1019.         eRet = mmi_jmms_jdi_get_msg(g_jmms_context->hStoreHandle, index, Content);
  1020.     }
  1021.     return eRet;
  1022. }
  1023. /*****************************************************************************
  1024.  * FUNCTION
  1025.  *  mmi_jmms_store_move_message
  1026.  * DESCRIPTION
  1027.  *  
  1028.  * PARAMETERS
  1029.  *  pSrcFolderName      [?]     [?]
  1030.  *  pDestFolderName     [?]     [?]
  1031.  *  uiMsgIndex          [?]     [?]
  1032.  * RETURNS
  1033.  *  
  1034.  *****************************************************************************/
  1035. JC_RETCODE mmi_jmms_store_move_message(S8 *pSrcFolderName, S8 *pDestFolderName, JC_UINT32 *uiMsgIndex)
  1036. {
  1037.     /*----------------------------------------------------------------*/
  1038.     /* Local Variables                                                */
  1039.     /*----------------------------------------------------------------*/
  1040.     U32 len = 0;
  1041.     S8 *folder_name = NULL;
  1042.     JC_RETCODE eRet = JC_OK;
  1043.     MESSAGE_LIST *pMessageList = NULL;
  1044.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  1045.     /*----------------------------------------------------------------*/
  1046.     /* Code Body                                                      */
  1047.     /*----------------------------------------------------------------*/
  1048.     eRet = mmi_jmms_set_active_folder(pSrcFolderName);
  1049.     if (JC_OK != eRet)
  1050.     {
  1051.         return eRet;
  1052.     }
  1053.     StoreRetFilter.uiStartIndex = *uiMsgIndex;
  1054.     StoreRetFilter.uiNumMessage = 1;
  1055.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  1056.     eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1057.     if (JC_OK != eRet)
  1058.     {
  1059.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  1060.         {
  1061.             eRet = mmi_jmms_restore_folder_info();
  1062.             if (eRet == JC_OK)
  1063.             {
  1064.                 eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1065.                 if (eRet != JC_OK)
  1066.                 {
  1067.                     goto END;
  1068.                 }
  1069.             }
  1070.             else
  1071.             {
  1072.                 goto END;
  1073.             }
  1074.         }
  1075.         else
  1076.         {
  1077.             goto END;
  1078.         }
  1079.     }
  1080.     len = (strlen((S8*) pDestFolderName) + 1) * ENCODING_LENGTH;
  1081.     folder_name = (S8*) jdd_MemAlloc(sizeof(S8), len);
  1082.     if (NULL == folder_name)
  1083.     {
  1084.         return JC_ERR_MEMORY_ALLOCATION;
  1085.     }
  1086.     AnsiiToUnicodeString((S8*) folder_name, (PS8) pDestFolderName);
  1087.     eRet = mmi_jmms_jdi_move_msg(g_jmms_context->hStoreHandle, (JC_UINT32) (*uiMsgIndex), (JC_CHAR*) folder_name);
  1088.     if (JC_OK != eRet)
  1089.     {
  1090.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  1091.         {
  1092.             eRet = mmi_jmms_restore_folder_info();
  1093.             if (eRet != JC_OK)
  1094.             {
  1095.                 goto END;
  1096.             }
  1097.         }
  1098.         else
  1099.         {
  1100.             goto END;
  1101.         }
  1102.     }
  1103.     eRet = mmi_jmms_jdi_update_msg_list(g_jmms_context->hStoreHandle, E_FALSE);
  1104.     if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  1105.     {
  1106.         eRet = mmi_jmms_restore_folder_info();
  1107.     }
  1108.   END:
  1109.     jdd_MemFree(folder_name);
  1110.     return eRet;
  1111. }
  1112. /*****************************************************************************
  1113.  * FUNCTION
  1114.  *  mmi_jmms_store_update_message
  1115.  * DESCRIPTION
  1116.  *  
  1117.  * PARAMETERS
  1118.  *  pFolderName     [?]         [?]
  1119.  *  uiMsgIndex      [?]         [?]
  1120.  *  MsgHeaders      [?]         [?]
  1121.  *  Content         [?]         [?]
  1122.  *  extraBytes      [IN]        
  1123.  * RETURNS
  1124.  *  
  1125.  *****************************************************************************/
  1126. JC_RETCODE mmi_jmms_store_update_message(
  1127.             S8 *pFolderName,
  1128.             JC_UINT32 *uiMsgIndex,
  1129.             MESSAGE_HEADERS *MsgHeaders,
  1130.             CONTENT_DATA *Content,
  1131.             JC_UINT32 extraBytes)
  1132. {
  1133.     /*----------------------------------------------------------------*/
  1134.     /* Local Variables                                                */
  1135.     /*----------------------------------------------------------------*/
  1136.     JC_RETCODE eRet = JC_OK;
  1137.     MESSAGE_LIST *pMessageList = NULL;
  1138.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  1139.     U32 msgId = 0;
  1140.     MMI_BOOL isJavaMsg = MMI_FALSE;
  1141.     JC_INT8 *content_type = NULL;
  1142.     JC_UINT32 new_extraBytes = 0;
  1143.     /*----------------------------------------------------------------*/
  1144.     /* Code Body                                                      */
  1145.     /*----------------------------------------------------------------*/
  1146.     eRet = mmi_jmms_set_active_folder(pFolderName);
  1147.     if (JC_OK != eRet)
  1148.     {
  1149.         return eRet;
  1150.     }
  1151.     StoreRetFilter.uiStartIndex = *uiMsgIndex;
  1152.     StoreRetFilter.uiNumMessage = 1;
  1153.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  1154.     eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1155.     if (JC_OK != eRet)
  1156.     {
  1157.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  1158.         {
  1159.             eRet = mmi_jmms_restore_folder_info();
  1160.             if (eRet == JC_OK)
  1161.             {
  1162.                 eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1163.             }
  1164.         }
  1165.         if (eRet != JC_OK)
  1166.         {
  1167.             return eRet;
  1168.         }
  1169.     }
  1170. if( pMessageList == NULL)
  1171. {
  1172. return -1;
  1173. }
  1174.     mmi_jmms_get_content_type(Content, &content_type);
  1175.     if (content_type != NULL)
  1176.     {
  1177.         isJavaMsg = mmi_jsr_check_recv_mms_for_java(content_type);
  1178.     }
  1179.     if (isJavaMsg == MMI_TRUE)
  1180.     {
  1181.         mmi_jmms_get_java_msgid_value_from_nvram();
  1182.         msgId = (U32) (g_jmms_java_msgid) + 1;
  1183.         if (msgId >= MMI_JMMS_MAX_JAVA_MSG_ID)
  1184.         {
  1185.             msgId = 0;
  1186.         }
  1187.     }
  1188.     else
  1189.     {
  1190.         msgId = (U32) (pMessageList->uiExtraBytes & 0x00FFFFFF);
  1191.     }
  1192.     if (extraBytes != 0)
  1193.     {
  1194.         new_extraBytes = (extraBytes & 0xFF000000);
  1195.     }
  1196.     else
  1197.     {
  1198.         new_extraBytes = (pMessageList->uiExtraBytes & 0xFF000000);
  1199.     }
  1200.     new_extraBytes |= msgId;
  1201.     eRet = mmi_jmms_jdi_update_msg(g_jmms_context->hStoreHandle, *uiMsgIndex, MsgHeaders, Content, new_extraBytes);
  1202.     if (eRet == JC_OK)
  1203.     {
  1204.         if (isJavaMsg == E_TRUE)
  1205.         {
  1206.             g_jmms_java_msgid = msgId;
  1207.             mmi_jmms_set_java_msgid_value_to_nvram();
  1208.             mmi_jsr_add_recv_java_mms_content(msgId, content_type);
  1209.         }
  1210.     }
  1211.     if (content_type != NULL)
  1212.     {
  1213.         jdd_MemFree(content_type);
  1214.         content_type = NULL;
  1215.     }
  1216.     return eRet;
  1217. }
  1218. /*****************************************************************************
  1219.  * FUNCTION
  1220.  *  mmi_jmms_store_update_message_extrabyte
  1221.  * DESCRIPTION
  1222.  *  
  1223.  * PARAMETERS
  1224.  *  pFolderName         [?]         [?]
  1225.  *  uiMsgIndex          [IN]        [?]
  1226.  *  uiExtraBytes        [IN]        
  1227.  *  extraBytes(?)       [IN]        
  1228.  * RETURNS
  1229.  *  
  1230.  *****************************************************************************/
  1231. JC_RETCODE mmi_jmms_store_update_message_extrabyte(S8 *pFolderName, JC_UINT32 uiMsgIndex, JC_UINT32 uiExtraBytes)
  1232. {
  1233.     /*----------------------------------------------------------------*/
  1234.     /* Local Variables                                                */
  1235.     /*----------------------------------------------------------------*/
  1236.     MESSAGE_LIST *pMessageList = NULL;
  1237.     JC_RETCODE eRet = JC_OK;
  1238.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  1239.     /*----------------------------------------------------------------*/
  1240.     /* Code Body                                                      */
  1241.     /*----------------------------------------------------------------*/
  1242.     eRet = mmi_jmms_set_active_folder(pFolderName);
  1243.     if (JC_OK != eRet)
  1244.     {
  1245.         return eRet;
  1246.     }
  1247.     StoreRetFilter.uiStartIndex = uiMsgIndex;
  1248.     StoreRetFilter.uiNumMessage = 1;
  1249.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  1250.     eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1251.     if (JC_OK != eRet)
  1252.     {
  1253.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  1254.         {
  1255.             eRet = mmi_jmms_restore_folder_info();
  1256.             if (eRet == JC_OK)
  1257.             {
  1258.                 eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1259.             }
  1260.             else
  1261.             {
  1262.                 return eRet;
  1263.             }
  1264.         }
  1265.         else
  1266.         {
  1267.             return eRet;
  1268.         }
  1269.     }
  1270.     if (eRet != JC_OK)
  1271.     {
  1272.         return eRet;
  1273.     }
  1274.     eRet = mmi_jmms_jdi_update_extrabytes(g_jmms_context->hStoreHandle, uiMsgIndex, uiExtraBytes);
  1275.     return eRet;
  1276. }
  1277. /*****************************************************************************
  1278.  * FUNCTION
  1279.  *  mmi_jmms_delete_all_message
  1280.  * DESCRIPTION
  1281.  *  
  1282.  * PARAMETERS
  1283.  *  pFolderName     [?]     [?]
  1284.  * RETURNS
  1285.  *  
  1286.  *****************************************************************************/
  1287. JC_RETCODE mmi_jmms_delete_all_message(S8 *pFolderName)
  1288. {
  1289.     /*----------------------------------------------------------------*/
  1290.     /* Local Variables                                                */
  1291.     /*----------------------------------------------------------------*/
  1292.     JC_RETCODE eRet = JC_OK;
  1293.     U8 number_mms = 0;
  1294.     // TODO::manish changing here.Ned to test
  1295.     MESSAGE_LIST *pMessageList = NULL;
  1296.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  1297.     /*----------------------------------------------------------------*/
  1298.     /* Code Body                                                      */
  1299.     /*----------------------------------------------------------------*/
  1300.     eRet = mmi_jmms_set_active_folder(pFolderName);
  1301.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "mmi_jmms_delete_all_message: %s", pFolderName));
  1302.     if (JC_OK != eRet)
  1303.     {
  1304.         return eRet;
  1305.     }
  1306.     StoreRetFilter.uiStartIndex = 1;
  1307.     StoreRetFilter.uiNumMessage = 0;
  1308.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  1309.     eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1310.     if (JC_OK != eRet)
  1311.     {
  1312.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  1313.         {
  1314.             eRet = mmi_jmms_restore_folder_info();
  1315.             if (eRet == JC_OK)
  1316.             {
  1317.                 eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1318.             }
  1319.         }
  1320.         if (eRet != JC_OK)
  1321.         {
  1322.             return eRet;
  1323.         }
  1324.     }
  1325.     eRet = mmi_jmms_store_jdi_delete_all_msg(g_jmms_context->hStoreHandle);
  1326.     if (JC_OK != eRet)
  1327.     {
  1328.         return eRet;
  1329.     }
  1330.     eRet = mmi_jmms_jdi_update_msg_list(g_jmms_context->hStoreHandle, E_FALSE);
  1331.     if (JC_OK != eRet)
  1332.     {
  1333.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  1334.         {
  1335.             eRet = mmi_jmms_restore_folder_info();
  1336.             if (eRet != JC_OK)
  1337.             {
  1338.                 return eRet;
  1339.             }
  1340.         }
  1341.     }
  1342.     if (eRet == JC_OK)
  1343.     {
  1344.         eRet = mmi_jmms_get_total_number_of_messages(&number_mms);
  1345.         if (eRet != JC_OK)
  1346.         {
  1347.             return eRet;
  1348.         }
  1349.         if (number_mms < MAX_POSSIBLE_MESSAGES)
  1350.         {
  1351.             mmi_jmms_remove_memory_full_node_if_present();
  1352.         }
  1353.         /* PMT VIKAS START 20060405 */
  1354.         mmi_jmms_update_status_icon_indicator();
  1355.         /* PMT VIKAS END 20060405 */
  1356.     }
  1357.     return eRet;
  1358. }
  1359. /*****************************************************************************
  1360.  * FUNCTION
  1361.  *  mmi_jmms_get_message_id
  1362.  * DESCRIPTION
  1363.  *  
  1364.  * PARAMETERS
  1365.  *  pFolderName     [?]         [?]
  1366.  *  uiMsgIndex      [IN]        
  1367.  * RETURNS
  1368.  *  
  1369.  *****************************************************************************/
  1370. JC_UINT32 mmi_jmms_get_message_id(S8 *pFolderName, JC_UINT32 uiMsgIndex)
  1371. {
  1372.     /*----------------------------------------------------------------*/
  1373.     /* Local Variables                                                */
  1374.     /*----------------------------------------------------------------*/
  1375.     JC_RETCODE eRet = JC_OK;
  1376.     JC_UINT32 msgId = 0;
  1377.     MESSAGE_LIST *pMessageList = NULL;
  1378.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  1379.     /*----------------------------------------------------------------*/
  1380.     /* Code Body                                                      */
  1381.     /*----------------------------------------------------------------*/
  1382.     eRet = mmi_jmms_set_active_folder(pFolderName);
  1383.     if (JC_OK != eRet)
  1384.     {
  1385.         return 0;
  1386.     }
  1387.     StoreRetFilter.uiStartIndex = uiMsgIndex;
  1388.     StoreRetFilter.uiNumMessage = 1;
  1389.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  1390.     eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1391.     if (JC_OK != eRet)
  1392.     {
  1393.         if (JC_ERR_STORE_FILE_CORRUPTED == eRet)
  1394.         {
  1395.             eRet = mmi_jmms_restore_folder_info();
  1396.             if (eRet == JC_OK)
  1397.             {
  1398.                 eRet = mmi_jmms_jdi_get_msg_list(g_jmms_context->hStoreHandle, &pMessageList, &StoreRetFilter);
  1399.             }
  1400.         }
  1401.         if (eRet != JC_OK)
  1402.         {
  1403.             return 0;
  1404.         }
  1405.     }
  1406. #ifdef __MMI_UNIFIED_MESSAGE__
  1407.     msgId = pMessageList->uiExtraBytes & 0x00FFFFFF;
  1408. #else 
  1409.     msgId = pMessageList->uiExtraBytes;
  1410. #endif 
  1411.     return msgId;
  1412. }
  1413. /*****************************************************************************
  1414.  * FUNCTION
  1415.  *  mmi_jmms_free_messages_list
  1416.  * DESCRIPTION
  1417.  *  
  1418.  * PARAMETERS
  1419.  *  void
  1420.  * RETURNS
  1421.  *  void
  1422.  *****************************************************************************/
  1423. void mmi_jmms_free_messages_list(void)
  1424. {
  1425.     /*----------------------------------------------------------------*/
  1426.     /* Local Variables                                                */
  1427.     /*----------------------------------------------------------------*/
  1428.     STORAGE_CTX *pStorageHandle = NULL;
  1429.     /*----------------------------------------------------------------*/
  1430.     /* Code Body                                                      */
  1431.     /*----------------------------------------------------------------*/
  1432.     pStorageHandle = (STORAGE_CTX*) (g_jmms_context->hStoreHandle);
  1433.     if (pStorageHandle->pMessageList != NULL)
  1434.     {
  1435.         StoreFreeMessageList(pStorageHandle->pMessageList);
  1436.         pStorageHandle->pMessageList = NULL;
  1437.     }
  1438. }
  1439. /* PMT VIKAS START 20060401 */
  1440. /*****************************************************************************
  1441.  * FUNCTION
  1442.  *  mmi_jmms_get_number_of_unread_messages_in_inbox
  1443.  * DESCRIPTION
  1444.  *  
  1445.  * PARAMETERS
  1446.  *  total_num_unread_messages       [?]     [?]
  1447.  * RETURNS
  1448.  *  
  1449.  *****************************************************************************/
  1450. JC_RETCODE mmi_jmms_get_number_of_unread_messages_in_inbox(U8 *total_num_unread_messages)
  1451. {
  1452.     /*----------------------------------------------------------------*/
  1453.     /* Local Variables                                                */
  1454.     /*----------------------------------------------------------------*/
  1455.     JC_RETCODE eRet = JC_OK;
  1456.     U8 msgs = 0;
  1457.     U8 i = 0;
  1458.     /*----------------------------------------------------------------*/
  1459.     /* Code Body                                                      */
  1460.     /*----------------------------------------------------------------*/
  1461.     *total_num_unread_messages = 0;
  1462.     eRet = mmi_mms_get_number_of_messages(MMI_JMMS_INBOX, &msgs);
  1463.     if (eRet != JC_OK)
  1464.     {
  1465.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s%d", "mmi_jmms_get_number_of_unread_messages_in_inbox returns = ",eRet));
  1466.         return eRet;
  1467.     }
  1468.     for (i = 0; i < msgs; i++)
  1469.     {
  1470.         U8 msg_index = 0;
  1471.         msg_index = msgs - i;
  1472.         msg_index = msg_index - 1;
  1473.         if (mmi_jmms_is_msg_read(msg_index) == MMI_FALSE)
  1474.         {
  1475.             *total_num_unread_messages = *total_num_unread_messages + 1;
  1476.         }
  1477.     }
  1478.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s%d", "unread_messages_in_inbox = ",*total_num_unread_messages));
  1479.     return eRet;
  1480. }
  1481. /*****************************************************************************
  1482.  * FUNCTION
  1483.  *  mmi_jmms_set_active_folder
  1484.  * DESCRIPTION
  1485.  *  
  1486.  * PARAMETERS
  1487.  *  pFolderName     [?]     [?]
  1488.  * RETURNS
  1489.  *  
  1490.  *****************************************************************************/
  1491. JC_RETCODE mmi_jmms_set_active_folder(S8 *pFolderName)
  1492. {
  1493.     /*----------------------------------------------------------------*/
  1494.     /* Local Variables                                                */
  1495.     /*----------------------------------------------------------------*/
  1496.     U32 len = 0;
  1497.     JC_CHAR *folder_name = NULL;
  1498.     JC_RETCODE eRet = JC_OK;
  1499.     /*----------------------------------------------------------------*/
  1500.     /* Code Body                                                      */
  1501.     /*----------------------------------------------------------------*/
  1502.     len = strlen((PS8) pFolderName);
  1503.     folder_name = (JC_CHAR*) jdd_MemAlloc(sizeof(JC_CHAR), len + 1);
  1504.     if (NULL == folder_name)
  1505.     {
  1506.         return JC_ERR_MEMORY_ALLOCATION;
  1507.     }
  1508.     AnsiiToUnicodeString((PS8) folder_name, (PS8) pFolderName);
  1509.     eRet = mmi_jmms_jdi_set_active_folder(g_jmms_context->hStoreHandle, (JC_CHAR*) folder_name);
  1510.     jdd_MemFree(folder_name);
  1511.     return eRet;
  1512. }
  1513. /*****************************************************************************
  1514.  * FUNCTION
  1515.  *  mmi_jmms_delete_progresing_screen
  1516.  * DESCRIPTION
  1517.  *  
  1518.  * PARAMETERS
  1519.  *  pFolderName     [?]     [?]
  1520.  * RETURNS
  1521.  *  
  1522.  *****************************************************************************/
  1523. void mmi_jmms_delete_progresing_screen(U16 title_str_id, U16 image_id)
  1524. {
  1525.     /*----------------------------------------------------------------*/
  1526.     /* Local Variables                                                */
  1527.     /*----------------------------------------------------------------*/
  1528.     /*----------------------------------------------------------------*/
  1529.     /* Code Body                                                      */
  1530.     /*----------------------------------------------------------------*/
  1531.     EntryNewScreen(SCR_ID_JMMS_DELETING_PROGRESS, NULL, NULL, NULL);
  1532.     ShowCategory8Screen(
  1533.         title_str_id,
  1534.         GetRootTitleIcon(MAIN_MENU_MESSAGES_MENUID),
  1535.         0,
  1536.         0,
  1537.         0,
  1538.         0,
  1539.         STR_ID_JMMS_DELETING_MMS,
  1540.         image_id,
  1541.         NULL);
  1542. }
  1543. /*****************************************************************************
  1544.  * FUNCTION
  1545.  *  mmi_jmms_recreate_sys_folders
  1546.  * DESCRIPTION
  1547.  *  
  1548.  * PARAMETERS
  1549.  *  void     [?]     [?]
  1550.  * RETURNS
  1551.  *  JC_RETCODE
  1552.  *****************************************************************************/
  1553. JC_RETCODE mmi_jmms_recreate_sys_folders(void)
  1554. {
  1555. JDD_FSHANDLE fs_handle = NULL;
  1556.     JC_INT32 drive_letter = FS_GetDrive(FS_DRIVE_I_SYSTEM, 1, FS_NO_ALT_DRIVE);
  1557.     JC_INT8 mms_folder_path_ascii[30];
  1558.     JC_CHAR mms_folder_path_ucs2[30 * ENCODING_LENGTH];
  1559.     JC_CHAR *mms_sys_filepath_ucs2 = NULL;
  1560.     JC_RETCODE eRet = JC_OK;
  1561.     #ifdef MMS_IN_LARGE_STORAGE
  1562.     /* Order: 1. Invisible NAND 2. Visible NAND 3. visible NOR 4. Invisible NOR */
  1563.     drive_letter = FS_GetDrive(FS_DRIVE_I_SYSTEM, 2, FS_DRIVE_V_NORMAL | FS_DRIVE_I_SYSTEM);
  1564.     #endif /* MMS_IN_LARGE_STORAGE */ 
  1565.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "Enters mmi_jmms_recreate_sys_folders"));
  1566.     if (fs_handle == NULL)
  1567.     {
  1568.         if (jdd_FSInitialize(&fs_handle) != JC_OK)
  1569.         {
  1570.             return -1;
  1571.         }
  1572.     }
  1573.     jdi_UtilsCharToTchar(&mms_sys_filepath_ucs2, JDD_FS_MMS_SYS_FOLDER);
  1574.     if (jdd_FSIsDirExist(fs_handle, mms_sys_filepath_ucs2) == E_TRUE)
  1575.     {
  1576.         eRet=jdd_FSDelDir(fs_handle,  mms_sys_filepath_ucs2);
  1577.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "mmi_jmms_delete_sys_folders: %d",eRet));
  1578.         eRet=jdd_FSMakeDir(fs_handle, mms_sys_filepath_ucs2);
  1579.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "mmi_jmms_create_sys_folders: %d",eRet));
  1580.     }
  1581. error:
  1582.     jdd_MemFree(mms_sys_filepath_ucs2);
  1583.     if (fs_handle != NULL)
  1584.     {
  1585.         jdd_FSDeinitialize(fs_handle);
  1586.         fs_handle = NULL;
  1587.     }
  1588.     return eRet;
  1589. }
  1590. /* PMT VIKAS END 20060401 */
  1591. #endif /* (defined (JATAAYU_SUPPORT) && defined(MMS_SUPPORT)) */ 
  1592. #endif /* _MMI_JMMSSTOREHANDLING_C */ /* _MMI_STOREHANDLING_C */