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

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.  * ThemeManager.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This is the source file for Theme Manager.
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *==============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  * removed!
  148.  * removed!
  149.  * removed!
  150.  *
  151.  * removed!
  152.  * removed!
  153.  * removed!
  154.  *
  155.  * removed!
  156.  * removed!
  157.  * removed!
  158.  *
  159.  * removed!
  160.  * removed!
  161.  * removed!
  162.  *
  163.  * removed!
  164.  * removed!
  165.  * removed!
  166.  *
  167.  * removed!
  168.  * removed!
  169.  * removed!
  170.  * removed!
  171.  *
  172.  * removed!
  173.  * removed!
  174.  * removed!
  175.  * removed!
  176.  *
  177.  *------------------------------------------------------------------------------
  178.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  179.  *==============================================================================
  180.  *******************************************************************************/
  181. /*  Include: MMI header file */
  182. #include "MMI_features.h"
  183. #include "stdC.h"
  184. #include "L4Dr1.h"
  185. #include "PixtelDataTypes.h"
  186. #include "ThemeManager.h"
  187. #include "ThemeConverter.h"
  188. #include "gui.h"
  189. #include "Unicodexdcl.h"
  190. #include "FileSystemDef.h"
  191. #include "NVRAMProt.h"
  192. #include "NVRAMEnum.h"
  193. #include "NVRAMType.h"
  194. #include "DebugInitDef.h"
  195. #include "MMIThemes.h"
  196. #include "FileSystemGProt.h"
  197. #include "EventsGProt.h"
  198. #include "FunAndGamesDefs.h"
  199. #include "gui_themes.h"
  200. #include "drm_gprot.h"
  201. #include "QueueGprot.h"
  202. #include "SimDetectionGexdcl.h"
  203. #include "PhoneBookDef.h"
  204. #include "GlobalDefs.h"
  205. #include "ProtocolEvents.h"
  206. #include  "xml_def.h"
  207. #include "FileMgr.h"
  208. #include "FileSystemDef.h"
  209. #include "FileManagerDef.h"
  210. #include "MyPicture.h"
  211. #include "commonscreens.h"
  212. #include "poweronoffdisplaydefs.h"
  213. #include "mmi_phnset_dispchar.h"
  214. #include "Conversions.h"
  215. #include "PhoneSetupGprots.h"
  216. #include "SettingProfile.h"
  217. #include "GlobalScrEnum.h"
  218. #include "JavaAgencyDef.h"
  219. #include "ExtDeviceDefs.h"
  220. #include "app_crc.h"
  221. /***************************************************************************** 
  222. * Define
  223. *****************************************************************************/
  224. #if (defined(MMI_ON_WIN32) && !defined(NVRAM_EF_THEME_MANAGER_RECORD_SIZE))
  225. #define NVRAM_EF_THEME_MANAGER_RECORD_SIZE (sizeof(tm_theme_list_struct))*MAX_DOWNLOADED_THEMES
  226. #endif 
  227. #define NVRAM_EF_THEME_MANAGER_RECORD_TOTAL 1
  228. /* cache size */
  229. #if defined(__MMI_DLT_CACHE_SUPPORT__)
  230.     #define DLT_LOAD_ALWAYS_CACHE_SIZE      ((__DLT_ALWAYS_LOAD_BUFFER_SIZE__) * 1024)
  231.     #define DLT_LOAD_ON_DEMAND_CACHE_SIZE   ((__DLT_LOAD_ON_DEMAND_BUFFER_SIZE__) * 1024)
  232. #endif /* __MMI_DLT_CACHE_SUPPORT__ */ 
  233. /***************************************************************************** 
  234. * Typedef 
  235. *****************************************************************************/
  236. /***************************************************************************** 
  237. * Local Variable
  238. *****************************************************************************/
  239. #ifdef __MMI_DOWNLOADABLE_THEMES_SUPPORT__
  240. static MMI_BOOL g_tm_was_theme_alarm_cb = MMI_FALSE;    /* Was there a theme alarm expiry when usb was plugged in */
  241. #endif
  242. /***************************************************************************** 
  243. * Local Function
  244. *****************************************************************************/
  245. /***************************************************************************** 
  246. * Global Variable
  247. *****************************************************************************/
  248. theme_details_struct g_tm_activated_theme;
  249. #ifdef __MMI_DOWNLOADABLE_THEMES_SUPPORT__
  250. static tm_context_struct g_tm_cntx;
  251. __align(4)
  252. static tm_theme_list_struct g_tm_theme_list[TOTAL_THEMES_COUNT];
  253. static U8 g_tm_theme_image_dirty_bits[(MAX_MMI_IMAGEID_IMAGES / 8) + 1];
  254. __align(4)
  255. static tm_theme_list_struct g_tm_NvramThmArr[MAX_DOWNLOADED_THEMES];
  256. static BOOL g_tm_USB_mode = FALSE;
  257. #endif   /* __MMI_DOWNLOADABLE_THEMES_SUPPORT__ */
  258. #if (defined(__MMI_DOWNLOADABLE_THEMES_SUPPORT__))
  259. #if (defined(__MMI_DLT_CACHE_SUPPORT__))
  260. static U8 g_tm_load_always_cache[DLT_LOAD_ALWAYS_CACHE_SIZE];
  261. static U8 g_tm_load_ondemand_cache[DLT_LOAD_ON_DEMAND_CACHE_SIZE];
  262. static U32 g_tm_load_always_offset = 0;
  263. static U32 g_tm_load_ondemand_offset = 0;
  264. #endif /* (defined(__MMI_DLT_CACHE_SUPPORT__)) */ 
  265. /***************************************************************
  266. Start Supported Theme version Table
  267. ***************************************************************/
  268. FLOAT g_tm_supported_thm_version_table[MAX_SUPPORTED_VERSION_NUM] = 
  269. {
  270.     2.0
  271. };
  272. /***************************************************************
  273. End of Supported Theme version Table
  274. ***************************************************************/
  275. U16 g_tm_checkThemeVersion; /* Variable check for theme versioning */
  276. extern U16 mmi_ta_check_theme_file_version_compatibility(FLOAT theme_version);
  277. extern U16 mmi_ta_check_theme_file_lcd_dim_compatibiltiy(U32 lcd_width, U32 lcd_height);
  278. extern BOOL PhnsetIsWPCurrentTheme(void);
  279. extern BOOL PhnsetIsScrSvrCurrentTheme(void);
  280. extern void ThemeManagerSetWallpaper(U16);
  281. extern void ThemeManagerSetScreensaver(U16);
  282. extern XML_PARSER_STRUCT g_tc_parser;
  283. extern tc_deviceinfo_struct g_tc_deviceInfo;
  284. extern tc_theme_download_info_struct g_tc_themeInfo;
  285. extern DYNAUDIOINFO gDwnlThmToneInfo[MAXIMUM_THEMES_TONES];
  286. static U16 gVirAudFileNameList[MAXIMUM_THEMES_TONES][FS_GenVFN_SIZE + 8];
  287. #endif /* (defined(__MMI_DOWNLOADABLE_THEMES_SUPPORT__)) */ 
  288. extern oslMsgqid mmi_ext_qid;
  289. extern MMI_BOOL g_keypad_flag;
  290. extern drv_get_key_func keypad_ptr;
  291. extern theme_details_struct *MMI_themes;
  292. extern void SetThemes(U8 index);
  293. extern void initialize_status_icons(void);
  294. /* PMT DLT_FIXES - TK 20060321 START */
  295. extern S32 GetThemesNames(U8 **dest[]);
  296. /* PMT DLT_FIXES - TK 20060321 END */
  297. extern U8 g_tc_audiothmfileformat;
  298. void mmi_dispchar_get_img_id(U8 nDataItemId, U16 *pBuffer);
  299. /***************************************************************************** 
  300. * Global Function
  301. *****************************************************************************/
  302. #ifdef __MMI_DOWNLOADABLE_THEMES_SUPPORT__
  303. /*****************************************************************************
  304.  * FUNCTION
  305.  *  mmi_tm_create_image_header_pool
  306.  * DESCRIPTION
  307.  *  This function is for initializing image header buffer
  308.  * PARAMETERS
  309.  *  ds_p                [?]             
  310.  *  mempool_p           [?]             
  311.  *  unit_size           [IN]            
  312.  *  total_pool_size     [IN]            
  313.  *  a(?)                [IN/OUT]        First variable, used as returns
  314.  *  b(?)                [IN]            Second variable
  315.  * RETURNS
  316.  *  the description of return value, if any.(?)
  317.  *****************************************************************************/
  318. void mmi_tm_create_image_header_pool(
  319.         tm_theme_image_header_struct *ds_p,
  320.         void *mempool_p,
  321.         U16 unit_size,
  322.         U32 total_pool_size)
  323. {
  324.     /*----------------------------------------------------------------*/
  325.     /* Local Variables                                                */
  326.     /*----------------------------------------------------------------*/
  327.     /*----------------------------------------------------------------*/
  328.     /* Code Body                                                      */
  329.     /*----------------------------------------------------------------*/
  330.     ds_p->mempool_p = mempool_p;
  331.     ds_p->current_offset = 0;
  332.     ds_p->unit_size = unit_size;
  333.     ds_p->total_pool_size = total_pool_size;
  334. }
  335. /*****************************************************************************
  336.  * FUNCTION
  337.  *  mmi_tm_reset_imageid_image_header_pool
  338.  * DESCRIPTION
  339.  *  this function resets the image header pool buffer for images with IDs
  340.  * PARAMETERS
  341.  *  void
  342.  * RETURNS
  343.  *  void
  344.  *****************************************************************************/
  345. void mmi_tm_reset_imageid_image_header_pool(void)
  346. {
  347.     /*----------------------------------------------------------------*/
  348.     /* Local Variables                                                */
  349.     /*----------------------------------------------------------------*/
  350.     /*----------------------------------------------------------------*/
  351.     /* Code Body                                                      */
  352.     /*----------------------------------------------------------------*/
  353.     mmi_tm_reset_image_header_pool(&(g_tm_cntx.imageid_images_headers));
  354.     memset(&g_tm_cntx.image_cache, 0xFF, sizeof(g_tm_cntx.image_cache));
  355. }
  356. /*****************************************************************************
  357.  * FUNCTION
  358.  *  mmi_tm_reset_non_imageid_image_header_pool
  359.  * DESCRIPTION
  360.  *  this function resets the image header pool buffer for images without IDs
  361.  * PARAMETERS
  362.  *  void
  363.  * RETURNS
  364.  *  void
  365.  *****************************************************************************/
  366. void mmi_tm_reset_non_imageid_image_header_pool(void)
  367. {
  368.     /*----------------------------------------------------------------*/
  369.     /* Local Variables                                                */
  370.     /*----------------------------------------------------------------*/
  371.     /*----------------------------------------------------------------*/
  372.     /* Code Body                                                      */
  373.     /*----------------------------------------------------------------*/
  374.     mmi_tm_reset_image_header_pool(&(g_tm_cntx.non_imageid_images_headers));
  375. }
  376. /*****************************************************************************
  377.  * FUNCTION
  378.  *  mmi_tm_reset_image_header_pool
  379.  * DESCRIPTION
  380.  *  this function resets the image header pool buffer
  381.  * PARAMETERS
  382.  *  ds_p        [?]     
  383.  * RETURNS
  384.  *  void
  385.  *****************************************************************************/
  386. void mmi_tm_reset_image_header_pool(tm_theme_image_header_struct *ds_p)
  387. {
  388.     /*----------------------------------------------------------------*/
  389.     /* Local Variables                                                */
  390.     /*----------------------------------------------------------------*/
  391.     /*----------------------------------------------------------------*/
  392.     /* Code Body                                                      */
  393.     /*----------------------------------------------------------------*/
  394.     ds_p->current_offset = 0;
  395. }
  396. /*****************************************************************************
  397.  * FUNCTION
  398.  *  mmi_tm_add_image_header_to_pool
  399.  * DESCRIPTION
  400.  *  this function adds image header to pool buffer
  401.  * PARAMETERS
  402.  *  ds_p        [?]     
  403.  *  buff        [?]     
  404.  * RETURNS
  405.  *  void
  406.  *****************************************************************************/
  407. void *mmi_tm_add_image_header_to_pool(tm_theme_image_header_struct *ds_p, void *buff)
  408. {
  409.     /*----------------------------------------------------------------*/
  410.     /* Local Variables                                                */
  411.     /*----------------------------------------------------------------*/
  412.     void *temp_ptr;
  413.     /*----------------------------------------------------------------*/
  414.     /* Code Body                                                      */
  415.     /*----------------------------------------------------------------*/
  416.     if ((ds_p->current_offset + ds_p->unit_size) > ds_p->total_pool_size)
  417.     {
  418.         return NULL;
  419.     }
  420.     else
  421.     {
  422.         memcpy((ds_p->mempool_p + ds_p->current_offset), buff, ds_p->unit_size);
  423.         temp_ptr = ds_p->mempool_p + ds_p->current_offset;
  424.         ds_p->current_offset += ds_p->unit_size;
  425.         return temp_ptr;
  426.     }
  427. }
  428. /*****************************************************************************
  429.  * FUNCTION
  430.  *  mmi_tm_get_downloaded_theme_image
  431.  * DESCRIPTION
  432.  *  It returns downloadable theme image pointer
  433.  * PARAMETERS
  434.  *  image_offset        [IN]        
  435.  *  nArrIndex           [IN]        
  436.  * RETURNS
  437.  *  void
  438.  *****************************************************************************/
  439. void *mmi_tm_get_downloaded_theme_image(U32 image_offset, S32 nArrIndex)
  440. {
  441.     /*----------------------------------------------------------------*/
  442.     /* Local Variables                                                */
  443.     /*----------------------------------------------------------------*/
  444.     S32 size;
  445.     void *image_p;
  446.     U8 buff[MAX_THEME_IMAGE_HEADER_LENGTH] = {0};
  447.     /*----------------------------------------------------------------*/
  448.     /* Code Body                                                      */
  449.     /*----------------------------------------------------------------*/
  450.     if (FS_ParseFH(g_tm_cntx.theme_file_handle) >= 0)
  451.     {
  452.         if (g_tm_cntx.image_cache[nArrIndex].nOffset != -1)
  453.         {
  454.             return (void*)((S8*) g_tm_cntx.imageid_images_headers.mempool_p +
  455.                             g_tm_cntx.image_cache[nArrIndex].nOffset);
  456.         }
  457.         if (DRM_seek_file(g_tm_cntx.theme_file_handle, image_offset, FS_FILE_BEGIN) >= 0 )
  458.         {
  459.             if (DRM_read_file(g_tm_cntx.theme_file_handle, buff, THEME_IMAGE_INFO_HEADER, (U32*) & size) !=
  460.                 FS_NO_ERROR)
  461.             {
  462.            mmi_tm_handle_file_access_failed();
  463.           return NULL;
  464.             }
  465.         }
  466.         else
  467.         {
  468.         mmi_tm_handle_file_access_failed();
  469.          return NULL;
  470.         }
  471.         /* offset in next 4 bytes */
  472.         buff[8] = (U8) (image_offset & 0x000000ff);
  473.         buff[9] = (U8) ((image_offset >> 8) & 0x000000ff);
  474.         buff[10] = (U8) ((image_offset >> 16) & 0x000000ff);
  475.         buff[11] = (U8) ((image_offset >> 24) & 0x000000ff);
  476.         /* file handle in next 4 bytes */
  477.         buff[12] = (U8) (g_tm_cntx.theme_file_handle & 0x000000ff);
  478.         buff[13] = (U8) ((g_tm_cntx.theme_file_handle >> 8) & 0x000000ff);
  479.         buff[14] = (U8) ((g_tm_cntx.theme_file_handle >> 16) & 0x000000ff);
  480.         buff[15] = (U8) ((g_tm_cntx.theme_file_handle >> 24) & 0x000000ff);
  481.         image_p = mmi_tm_add_image_header_to_pool(&(g_tm_cntx.imageid_images_headers), buff);
  482.         if (image_p)
  483.         {
  484.             g_tm_cntx.image_cache[nArrIndex].nOffset =
  485.                 (U16) ((S8*) image_p - (S8*) g_tm_cntx.imageid_images_headers.mempool_p);
  486.             return image_p;
  487.         }
  488.     }
  489.     return GetDefaultImage();
  490. }
  491. /*****************************************************************************
  492.  * FUNCTION
  493.  *  mmi_tm_check_theme_file_phone_model_compatibility
  494.  * DESCRIPTION
  495.  *  validates Theme Phone Model.
  496.  * PARAMETERS
  497.  *  theme_phone_model       [IN]        
  498.  * RETURNS
  499.  *  true if compatible otherwise false
  500.  *****************************************************************************/
  501. U16 mmi_tm_check_theme_file_phone_model_compatibility(PS8 theme_phone_model)
  502. {
  503.     /*----------------------------------------------------------------*/
  504.     /* Local Variables                                                */
  505.     /*----------------------------------------------------------------*/
  506.     /*----------------------------------------------------------------*/
  507.     /* Code Body                                                      */
  508.     /*----------------------------------------------------------------*/
  509.     if (strncmp(theme_phone_model, mmi_get_phone_model(), MAX_MODEL_ID_LEN))
  510.     {
  511.         return FALSE;
  512.     }
  513.     else
  514.     {
  515.         return TRUE;
  516.     }
  517. }
  518. /*****************************************************************************
  519.  * FUNCTION
  520.  *  mmi_tm_theme_version_and_deviceinfo_check
  521.  * DESCRIPTION
  522.  *  It checks theme version and deviceinfo in DLT file(.med)
  523.  * PARAMETERS
  524.  *  theme_struct_p      [?]     
  525.  * RETURNS
  526.  *  true  : if successfully checks,
  527.  *  false : if unable to check
  528.  *****************************************************************************/
  529. BOOL mmi_tm_theme_version_and_deviceinfo_check(tm_theme_list_struct *theme_struct_p)
  530. {
  531.     /*----------------------------------------------------------------*/
  532.     /* Local Variables                                                */
  533.     /*----------------------------------------------------------------*/
  534.     U8 theme_file_name[(MAX_DWNL_THM_PATH_LEN + MAX_THEME_NAME_LENGTH) * ENCODING_LENGTH] = {0};
  535.     U8 tmp_path[50] = {0};
  536.     FS_HANDLE tmp_theme_file_handle;
  537.     /*----------------------------------------------------------------*/
  538.     /* Code Body                                                      */
  539.     /*----------------------------------------------------------------*/
  540.     g_tm_checkThemeVersion = TRUE;
  541.     if (theme_struct_p->theme_type == THEME_TYPE_DOWNLOADED_PHONE)
  542.     {
  543.         sprintf((PS8) tmp_path, "%c%s", MMI_PUBLIC_DRV, DOWNLOADED_THEMES_PATH);
  544.         AnsiiToUnicodeString((PS8) theme_file_name, (PS8) tmp_path);
  545.     }
  546.     else
  547.     {
  548.         sprintf((PS8) tmp_path, "%c%s", MMI_CARD_DRV, DOWNLOADED_THEMES_PATH);
  549.         AnsiiToUnicodeString((PS8) theme_file_name, (PS8) tmp_path);
  550.     }
  551.     pfnUnicodeStrcat((PS8) theme_file_name, (PS8) theme_struct_p->theme_name);
  552.     //      last_theme_file_handle = g_tm_cntx.theme_file_handle;
  553.     //tmp_theme_file_handle = DRM_open_file((U16*)theme_file_name, FS_READ_ONLY, 0/*DRM_PERMISSION_NONE*/); 
  554.     tmp_theme_file_handle = DRM_open_file((U16*) theme_file_name, FS_READ_ONLY | FS_OPEN_SHARED, 0);
  555.     if (tmp_theme_file_handle < FS_NO_ERROR)
  556.     {
  557.         return FALSE;
  558.     }
  559.     if (xml_new_parser(&g_tc_parser) == -1)
  560.     {
  561.         return FALSE;
  562.     }
  563.     xml_register_element_handler(&g_tc_parser, mmi_tc_my_xml_elem_start_hdlr, mmi_tc_my_xml_elem_end_hdlr);
  564.     /* PMT DLT_FIXES - TK 20060321 START */
  565.     g_tc_parser.pos = THEME_FILE_SIZE_HEADER + THEME_CHECKSUM_HEADER_SIZE;
  566.     /* PMT DLT_FIXES - TK 20060321 END */
  567.     xml_parse_file_from_offset(&g_tc_parser, tmp_theme_file_handle);
  568.     DRM_close_file(tmp_theme_file_handle);
  569.     g_tm_checkThemeVersion = FALSE;
  570.     if (mmi_ta_check_theme_file_version_compatibility((FLOAT) g_tc_themeInfo.version))
  571.     {
  572.         return TRUE;
  573.     }
  574.     return FALSE;
  575. }
  576. #ifdef __MMI_DLT_CACHE_SUPPORT__
  577. /*****************************************************************************
  578.  * FUNCTION
  579.  *  mmi_tm_clear_ondemand_cache
  580.  * DESCRIPTION
  581.  *  clears the ondemand cache by clearing pointer and making offset as zero
  582.  * PARAMETERS
  583.  *  void
  584.  * RETURNS
  585.  *  void
  586.  *****************************************************************************/
  587. void mmi_tm_clear_ondemand_cache(void)
  588. {
  589.     /*----------------------------------------------------------------*/
  590.     /* Local Variables                                                */
  591.     /*----------------------------------------------------------------*/
  592.     U32 count = 0;
  593.     /*----------------------------------------------------------------*/
  594.     /* Code Body                                                      */
  595.     /*----------------------------------------------------------------*/
  596.     while (g_tm_load_ondemand_offset && count < g_tm_cntx.theme_imageid_image_count)
  597.     {
  598.         if (g_tm_cntx.theme_image_list[count].image_type == THEME_IMG_LOAD_ONDEMAND)
  599.         {
  600.             g_tm_cntx.theme_image_list[count].image_cache_ptr = NULL;
  601.         }
  602.         ++count;
  603.     }
  604.     g_tm_load_ondemand_offset = 0;
  605. }
  606. /*****************************************************************************
  607.  * FUNCTION
  608.  *  mmi_tm_get_image_load_type
  609.  * DESCRIPTION
  610.  *  To determine the load type of an image
  611.  * PARAMETERS
  612.  *  img_list_index      [IN]        
  613.  * RETURNS
  614.  *  
  615.  *****************************************************************************/
  616. tm_image_load_type_enum mmi_tm_get_image_load_type(U32 img_list_index)
  617. {
  618.     /*----------------------------------------------------------------*/
  619.     /* Local Variables                                                */
  620.     /*----------------------------------------------------------------*/
  621.     /*----------------------------------------------------------------*/
  622.     /* Code Body                                                      */
  623.     /*----------------------------------------------------------------*/
  624.     return g_tm_cntx.theme_image_list[img_list_index].image_type;
  625. }
  626. /*****************************************************************************
  627.  * FUNCTION
  628.  *  mmi_tm_find_img_in_cache
  629.  * DESCRIPTION
  630.  *  returns image pointer
  631.  * PARAMETERS
  632.  *  img_list_index      [IN]        
  633.  *  type                [IN]        
  634.  * RETURNS
  635.  *  
  636.  *****************************************************************************/
  637. PU8 mmi_tm_find_img_in_cache(U32 img_list_index, tm_image_load_type_enum type)
  638. {
  639.     /*----------------------------------------------------------------*/
  640.     /* Local Variables                                                */
  641.     /*----------------------------------------------------------------*/
  642.     /*----------------------------------------------------------------*/
  643.     /* Code Body                                                      */
  644.     /*----------------------------------------------------------------*/
  645.     return g_tm_cntx.theme_image_list[img_list_index].image_cache_ptr;
  646. }
  647. /*****************************************************************************
  648.  * FUNCTION
  649.  *  mmi_tm_add_to_DLT_img_cache
  650.  * DESCRIPTION
  651.  *  add an image to image cache
  652.  * PARAMETERS
  653.  *  image_offset        [IN]        
  654.  *  img_load_type       [IN]        
  655.  * RETURNS
  656.  *  
  657.  *****************************************************************************/
  658. PU8 mmi_tm_add_to_DLT_img_cache(U32 image_offset, tm_image_load_type_enum img_load_type)
  659. {
  660.     /*----------------------------------------------------------------*/
  661.     /* Local Variables                                                */
  662.     /*----------------------------------------------------------------*/
  663.     S32 size;
  664.     U32 fp;
  665.     U8 buff[MAX_THEME_IMAGE_HEADER_LENGTH] = {0};
  666.     S32 image_file_size;
  667.     S32 dlt_img_cache_size;
  668.     PU8 image_buff;
  669.     PU32 cache_offset;
  670.     PU8 cache_ptr;
  671. PU8 p_img_ret=NULL;
  672.     /*----------------------------------------------------------------*/
  673.     /* Code Body                                                      */
  674.     /*----------------------------------------------------------------*/
  675.     if ( FS_GetFilePosition(g_tm_cntx.theme_file_handle, &fp) != FS_NO_ERROR )
  676.     {
  677.         mmi_tm_handle_file_access_failed();
  678.         return NULL;
  679.     }
  680.     if( DRM_seek_file(g_tm_cntx.theme_file_handle, image_offset, FS_FILE_BEGIN) >= 0)
  681.     {
  682.         if ( DRM_read_file(g_tm_cntx.theme_file_handle, buff, THEME_IMAGE_INFO_HEADER, (U32*) & size) != FS_NO_ERROR )
  683.         {
  684.             mmi_tm_handle_file_access_failed();
  685.             return NULL;
  686.         }
  687.     }
  688.     else
  689.     {
  690.         mmi_tm_handle_file_access_failed();
  691.         return NULL;
  692.     }
  693.     image_file_size = (U8) buff[2];
  694.     image_file_size = (image_file_size << 8) | (U8) buff[3];
  695.     image_file_size = (image_file_size << 8) | (U8) buff[4];
  696.     switch (img_load_type)
  697.     {
  698.         case THEME_IMG_LOAD_ALWAYS:
  699.             cache_ptr = g_tm_load_always_cache;
  700.             cache_offset = &g_tm_load_always_offset;
  701.             dlt_img_cache_size = DLT_LOAD_ALWAYS_CACHE_SIZE;
  702.             break;
  703.         case THEME_IMG_LOAD_ONDEMAND:
  704.         default:
  705.             cache_ptr = g_tm_load_ondemand_cache;
  706.             cache_offset = &g_tm_load_ondemand_offset;
  707.             dlt_img_cache_size = DLT_LOAD_ON_DEMAND_CACHE_SIZE;
  708.     }
  709.     /* 4-byte algin */
  710.     if (((U32) cache_ptr + *cache_offset) % 4)
  711.     {
  712.         *cache_offset += 4 - (((U32) cache_ptr + *cache_offset) % 4);
  713.     }
  714.     /* Refer gdi_image_parse_resource_internal() in Gdi_image.c for header format information */
  715.     if (buff[0] == GDI_IMAGE_TYPE_BMP_FILE_OFFSET || buff[0] == GDI_IMAGE_TYPE_GIF_FILE_OFFSET || buff[0] == GDI_IMAGE_TYPE_JPG_FILE_OFFSET)
  716.     {
  717.         if ((*cache_offset + image_file_size + 8) > dlt_img_cache_size) /* 8 extra bytes for Gif Header */
  718.         {
  719.             if ( DRM_seek_file(g_tm_cntx.theme_file_handle, fp, FS_FILE_BEGIN) < 0)
  720.             {
  721.                 mmi_tm_handle_file_access_failed();
  722.             }
  723.             return NULL;
  724.         }
  725.         image_buff = cache_ptr + *cache_offset;
  726.         image_buff[1] = buff[1];
  727.         image_buff[2] = (U8) (image_file_size & 0x000000ff);
  728.         image_buff[3] = (U8) ((image_file_size >> 8) & 0x000000ff);
  729.         image_buff[4] = (U8) ((image_file_size >> 16) & 0x000000ff);
  730.         image_buff[5] = (U8) ((image_file_size >> 24) & 0x000000ff);
  731.         switch (buff[0])
  732.         {
  733.             case GDI_IMAGE_TYPE_GIF_FILE_OFFSET:
  734.                 image_buff[0] = GDI_IMAGE_TYPE_GIF;
  735.                 image_buff[6] = 0;
  736.                 image_buff[7] = 0;
  737.                 if ( DRM_read_file(g_tm_cntx.theme_file_handle, image_buff + 8, image_file_size, (U32*) & size) != FS_NO_ERROR )
  738.                 {
  739.                     mmi_tm_handle_file_access_failed();
  740.                     return NULL;
  741.                 }
  742.                 *cache_offset += (image_file_size + 8); /* 8 extra bytes for Gif Header */
  743.                 p_img_ret = image_buff;
  744.                 break;
  745.             case GDI_IMAGE_TYPE_BMP_FILE_OFFSET:
  746.                 image_buff[0] = GDI_IMAGE_TYPE_BMP;
  747.                 if ( DRM_read_file(g_tm_cntx.theme_file_handle, image_buff + 6, image_file_size, (U32*) & size) != FS_NO_ERROR)
  748.                 {
  749.                     mmi_tm_handle_file_access_failed();
  750.                     return NULL;
  751.                 }
  752.                 *cache_offset += (image_file_size + 6); /* 6 extra bytes for BMP Header */
  753.                 p_img_ret = image_buff;
  754.                 break;
  755.             case GDI_IMAGE_TYPE_JPG_FILE_OFFSET:
  756.                 image_buff[0] = GDI_IMAGE_TYPE_JPG;
  757.                 if ( DRM_read_file(g_tm_cntx.theme_file_handle, image_buff + 6, image_file_size, (U32*) & size) != FS_NO_ERROR )
  758.                 {
  759.                     mmi_tm_handle_file_access_failed();
  760.                     return NULL;
  761.                 }
  762.                 *cache_offset += (image_file_size + 6); /* 6 extra bytes for jpg Header */
  763.                 p_img_ret = image_buff;
  764.                 break;
  765.             default:
  766.             p_img_ret = NULL;
  767. break;
  768.         }
  769.     }
  770.     else
  771.     {
  772.         p_img_ret = NULL;
  773.     }
  774.     if ( DRM_seek_file(g_tm_cntx.theme_file_handle, fp, FS_FILE_BEGIN) < 0)
  775.     {
  776.         mmi_tm_handle_file_access_failed();
  777.         return NULL;
  778.     }
  779. return p_img_ret;
  780. }
  781. /*****************************************************************************
  782.  * FUNCTION
  783.  *  mmi_tm_add_img_id_to_cache
  784.  * DESCRIPTION
  785.  *  
  786.  * PARAMETERS
  787.  *  img_list_index      [IN]        
  788.  *  image_offset        [IN]        
  789.  *  type                [IN]        
  790.  * RETURNS
  791.  *  
  792.  *****************************************************************************/
  793. PU8 mmi_tm_add_img_id_to_cache(U32 img_list_index, U32 image_offset, tm_image_load_type_enum type)
  794. {
  795.     /*----------------------------------------------------------------*/
  796.     /* Local Variables                                                */
  797.     /*----------------------------------------------------------------*/
  798.     PU8 pImage;
  799.     /*----------------------------------------------------------------*/
  800.     /* Code Body                                                      */
  801.     /*----------------------------------------------------------------*/
  802.     pImage = mmi_tm_add_to_DLT_img_cache(image_offset, type);
  803.     g_tm_cntx.theme_image_list[img_list_index].image_cache_ptr = pImage;
  804.     PRINT_INFORMATION(("mmi_tm_add_img_id_to_cache: img_list_index =%d, image_offset = %d type = %dn", img_list_index,
  805.                        image_offset, type));
  806.     return pImage;
  807. }
  808. #endif /* __MMI_DLT_CACHE_SUPPORT__ */ 
  809. /*****************************************************************************
  810.  * FUNCTION
  811.  *  mmi_tm_create_non_imageid_image
  812.  * DESCRIPTION
  813.  *  this function creates non id image buffer and add it to pool
  814.  * PARAMETERS
  815.  *  image_offset        [IN]        
  816.  *  type                [IN]        
  817.  * RETURNS
  818.  *  current image pointer in image pool buffer
  819.  *****************************************************************************/
  820. PU8 mmi_tm_create_non_imageid_image(U32 image_offset, tm_image_load_type_enum type)
  821. {
  822.     /*----------------------------------------------------------------*/
  823.     /* Local Variables                                                */
  824.     /*----------------------------------------------------------------*/
  825.     S32 size;
  826.     U32 fp;
  827.     PU8 pImage;
  828.     U8 buff[MAX_THEME_IMAGE_HEADER_LENGTH] = {0};
  829.     /*----------------------------------------------------------------*/
  830.     /* Code Body                                                      */
  831.     /*----------------------------------------------------------------*/
  832. #ifdef __MMI_DLT_CACHE_SUPPORT__
  833.     if (type != THEME_IMG_LOAD_NEVER)
  834.     {
  835.         pImage = mmi_tm_add_to_DLT_img_cache(image_offset, type);
  836.         if (pImage)
  837.         {
  838.             PRINT_INFORMATION(("mmi_tm_create_non_imageid_image: image_offset =%d, type = %dn", image_offset, type));
  839.             return pImage;
  840.         }
  841.     }
  842. #endif /* __MMI_DLT_CACHE_SUPPORT__ */ 
  843.     if ( FS_GetFilePosition(g_tm_cntx.theme_file_handle, &fp) != FS_NO_ERROR )
  844.     {
  845.         mmi_tm_handle_file_access_failed();
  846.         return NULL;
  847.     }
  848.     if ( DRM_seek_file(g_tm_cntx.theme_file_handle, image_offset, FS_FILE_BEGIN) >=0 )
  849.     {
  850.         if ( DRM_read_file(g_tm_cntx.theme_file_handle, buff, THEME_IMAGE_INFO_HEADER, (U32*) & size) != FS_NO_ERROR )
  851.         {
  852.             mmi_tm_handle_file_access_failed();
  853.             return NULL;
  854.         }
  855.     }
  856.     else
  857.     {
  858.         mmi_tm_handle_file_access_failed();
  859.         return NULL;
  860.     }
  861.     /* offset in next 4 bytes */
  862.     buff[8] = (U8) (image_offset & 0x000000ff);
  863.     buff[9] = (U8) ((image_offset >> 8) & 0x000000ff);
  864.     buff[10] = (U8) ((image_offset >> 16) & 0x000000ff);
  865.     buff[11] = (U8) ((image_offset >> 24) & 0x000000ff);
  866.     /* file handle in next 4 bytes */
  867.     buff[12] = (U8) (g_tm_cntx.theme_file_handle & 0x000000ff);
  868.     buff[13] = (U8) ((g_tm_cntx.theme_file_handle >> 8) & 0x000000ff);
  869.     buff[14] = (U8) ((g_tm_cntx.theme_file_handle >> 16) & 0x000000ff);
  870.     buff[15] = (U8) ((g_tm_cntx.theme_file_handle >> 24) & 0x000000ff);
  871.     if ( DRM_seek_file(g_tm_cntx.theme_file_handle, fp, FS_FILE_BEGIN) < 0)
  872.     {
  873.         mmi_tm_handle_file_access_failed();
  874.         return NULL;
  875.     }
  876.     return (PU8) mmi_tm_add_image_header_to_pool(&(g_tm_cntx.non_imageid_images_headers), buff);
  877. }
  878. /*****************************************************************************
  879.  * FUNCTION
  880.  *  mmi_tm_handle_audio
  881.  * DESCRIPTION
  882.  *  this function handles downloadable theme audio files
  883.  * PARAMETERS
  884.  *  audio_offset        [IN]        
  885.  *  audio_size          [IN]        
  886.  * RETURNS
  887.  *  void
  888.  *****************************************************************************/
  889. void mmi_tm_handle_audio(U32 audio_offset, U32 audio_size)
  890. {
  891.     /*----------------------------------------------------------------*/
  892.     /* Local Variables                                                */
  893.     /*----------------------------------------------------------------*/
  894.     U16 virtual_audio_fname[FS_GenVFN_SIZE + 8];
  895.     S32 fs_result;
  896.     /* PMT DLT_FIXES - TK 20060325 START */
  897.     S8 TempName[MAX_IMAGE_NAME_PATH_WIDTH + MAX_AUDIO_NAME_WIDTH];
  898.     /*----------------------------------------------------------------*/
  899.     /* Code Body                                                      */
  900.     /*----------------------------------------------------------------*/
  901.     /* PMT DLT_FIXES - TK 20060325 END */
  902.     if (g_tc_audiothmfileformat == THEME_AUDIO)
  903.     {
  904.         AnsiiToUnicodeString((S8*) gDwnlThmToneInfo[0].AudioName, THEME_AUDIO_FILE);   /* currently only one audio is suported. Will be changed */
  905.     }
  906.     else if (g_tc_audiothmfileformat == THEME_MIDI)
  907.     {
  908.         AnsiiToUnicodeString((S8*) gDwnlThmToneInfo[0].AudioName, THEME_AUDIO_MID_FILE);
  909.     }
  910.     else if (g_tc_audiothmfileformat == THEME_MP3)
  911.     {
  912.         AnsiiToUnicodeString((S8*) gDwnlThmToneInfo[0].AudioName, THEME_AUDIO_MP3_FILE);
  913.     }
  914.     /* PMT DLT_FIXES - TK 20060325 START */
  915.     memset(TempName, 0, (MAX_IMAGE_NAME_PATH_WIDTH + MAX_AUDIO_NAME_WIDTH));
  916.     AnsiiToUnicodeString((S8*) TempName, THEME_AUDIO_FOLDER_PATH);
  917.     FS_CreateDir((PU16) TempName);
  918.     //      CreateDir((U8*)TempName);
  919.     //PMT DLT_FIXES - TK 20060325 END
  920.     //      AnsiiToUnicodeString((S8*)gDwnlThmToneInfo[0].AudioName, THEME_AUDIO_FILE);//currently only one audio is suported. Will be changed
  921.     memset(virtual_audio_fname, 0, sizeof(virtual_audio_fname));
  922.     fs_result = FS_GenVirtualFileName(
  923.                     g_tm_cntx.theme_file_handle,
  924.                     (U16*) virtual_audio_fname,
  925.                     (unsigned int)FS_GenVFN_SIZE,
  926.                     audio_offset,
  927.                     audio_size);
  928.     pfnUnicodeStrcat((PS8) virtual_audio_fname, (PS8) ".");
  929.     pfnUnicodeStrcat((PS8) virtual_audio_fname, mmi_fmgr_extract_ext_file_name((PS8) gDwnlThmToneInfo[0].AudioName));
  930.     pfnUnicodeStrcpy((S8*) gVirAudFileNameList[0], (S8*) virtual_audio_fname);
  931.     if (fs_result >= 0)
  932.     {
  933.         g_tm_cntx.theme_has_ringtone = TRUE;
  934.         gDwnlThmToneInfo[0].AudioId = CURRENT_THEME_INCOMING_CALL_TONE;
  935.     }
  936.     else
  937.     {
  938.         DisplayPopup(
  939.             (PU8) GetString(STR_ID_FMGR_SPACE_NOT_AVAILABLE),
  940.             IMG_GLOBAL_EMPTY,
  941.             0,
  942.             UI_POPUP_NOTIFYDURATION_TIME,
  943.             WARNING_TONE);
  944.     }
  945.     /* PMT DLT_FIXES - TK 20060328 END */
  946. }
  947. /*****************************************************************************
  948.  * FUNCTION
  949.  *  mmi_tm_activate_downloaded_theme
  950.  * DESCRIPTION
  951.  *  This function activates downloadable theme
  952.  * PARAMETERS
  953.  *  theme_struct_p      [?]     
  954.  * RETURNS
  955.  *  theme error code
  956.  *****************************************************************************/
  957. tm_theme_error_enum mmi_tm_activate_downloaded_theme(tm_theme_list_struct *theme_struct_p)
  958. {
  959.     /*----------------------------------------------------------------*/
  960.     /* Local Variables                                                */
  961.     /*----------------------------------------------------------------*/
  962.     tm_theme_error_enum result;
  963.     S16 err;
  964.     U8 theme_file_name[(MAX_DWNL_THM_PATH_LEN + MAX_THEME_NAME_LENGTH) * ENCODING_LENGTH] = {0};
  965.     U8 tmp_path[50] = {0};
  966.     U16 nmodels = 0;
  967.     BOOL phonemodelcheck = FALSE;
  968.     FS_HANDLE last_theme_file_handle;
  969.     /*----------------------------------------------------------------*/
  970.     /* Code Body                                                      */
  971.     /*----------------------------------------------------------------*/
  972.     if (theme_struct_p->theme_type == THEME_TYPE_DOWNLOADED_PHONE)
  973.     {
  974.         sprintf((PS8) tmp_path, "%c%s", MMI_PUBLIC_DRV, DOWNLOADED_THEMES_PATH);
  975.         AnsiiToUnicodeString((PS8) theme_file_name, (PS8) tmp_path);
  976.     }
  977.     else
  978.     {
  979.         sprintf((PS8) tmp_path, "%c%s", MMI_CARD_DRV, DOWNLOADED_THEMES_PATH);
  980.         AnsiiToUnicodeString((PS8) theme_file_name, (PS8) tmp_path);
  981.     }
  982.     {
  983.         pfnUnicodeStrcat((PS8) theme_file_name, (PS8) theme_struct_p->theme_name);
  984.     }
  985.     last_theme_file_handle = g_tm_cntx.theme_file_handle;
  986.     // g_tm_cntx.theme_file_handle = DRM_open_file((U16*)theme_file_name, FS_READ_ONLY, 0/*DRM_PERMISSION_NONE*/);
  987.     g_tm_cntx.theme_file_handle = DRM_open_file((U16*) theme_file_name, FS_READ_ONLY | FS_OPEN_SHARED, 0);
  988.     if (g_tm_cntx.theme_file_handle < FS_NO_ERROR)
  989.     {
  990.         g_tm_cntx.theme_file_handle = last_theme_file_handle;
  991.         return THEME_ERROR_THEME_NOT_AVAILABLE;
  992.     }
  993.     if ( theme_struct_p->theme_checksum_verified == CHECKSUM_VERIFIED_BAD )
  994.     {
  995.         DRM_close_file(g_tm_cntx.theme_file_handle);
  996.         g_tm_cntx.theme_file_handle = last_theme_file_handle;
  997.         return THEME_ERROR_FILE_FORMAT_BAD;
  998.     }
  999.     else
  1000.     {
  1001.         result = mmi_tm_verify_theme_checksum(theme_file_name);
  1002.         if (result == THEME_ERROR_SUCCESS)
  1003.         {
  1004.             theme_struct_p->theme_checksum_verified = CHECKSUM_VERIFIED_OK;
  1005.             WriteRecord(
  1006.                 NVRAM_EF_THEME_MANAGER_LID,
  1007.                 1,
  1008.                 (void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt),
  1009.                 NVRAM_EF_THEME_MANAGER_RECORD_SIZE,
  1010.                 &err);
  1011.         }
  1012.         else
  1013.         {
  1014.             theme_struct_p->theme_checksum_verified = CHECKSUM_VERIFIED_BAD;
  1015.             WriteRecord(
  1016.                 NVRAM_EF_THEME_MANAGER_LID,
  1017.                 1,
  1018.                 (void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt),
  1019.                 NVRAM_EF_THEME_MANAGER_RECORD_SIZE,
  1020.                 &err);
  1021.             DRM_close_file(g_tm_cntx.theme_file_handle);
  1022.             g_tm_cntx.theme_file_handle = last_theme_file_handle;
  1023.             return THEME_ERROR_FILE_FORMAT_BAD;
  1024.         }
  1025.     }
  1026.     memset(&g_tc_deviceInfo, 0, sizeof(tc_deviceinfo_struct));
  1027.     memset(&g_tc_themeInfo, 0, sizeof(tc_theme_download_info_struct));
  1028.     if (mmi_tm_theme_version_and_deviceinfo_check(theme_struct_p) != TRUE)
  1029.     {
  1030.         DRM_close_file(g_tm_cntx.theme_file_handle);
  1031.         g_tm_cntx.theme_file_handle = last_theme_file_handle;
  1032.         return THEME_ERROR_VERSION_FAILURE;
  1033.     }
  1034.     if (!mmi_ta_check_theme_file_lcd_dim_compatibiltiy(g_tc_deviceInfo.lcdwidth, g_tc_deviceInfo.lcdht))
  1035.     {
  1036.         DRM_close_file(g_tm_cntx.theme_file_handle);
  1037.         g_tm_cntx.theme_file_handle = last_theme_file_handle;
  1038.         return THEME_ERROR_LCD_SIZE_MISMATCH;
  1039.     }
  1040.     while (*g_tc_deviceInfo.model_ID[nmodels] && nmodels < MAX_PHONE_MODELS)
  1041.     {
  1042.         if (mmi_tm_check_theme_file_phone_model_compatibility((PS8) g_tc_deviceInfo.model_ID[nmodels]) == TRUE)
  1043.         {
  1044.             phonemodelcheck = TRUE;
  1045.             break;
  1046.         }
  1047.         ++nmodels;
  1048.     }
  1049.     if (!phonemodelcheck)
  1050.     {
  1051.         DRM_close_file(g_tm_cntx.theme_file_handle);
  1052.         g_tm_cntx.theme_file_handle = last_theme_file_handle;
  1053.         return THEME_ERROR_PHONE_MODEL_MISMATCH;
  1054.     }
  1055.     DRM_close_file(last_theme_file_handle);
  1056.     g_tm_cntx.theme_has_alternate_image = FALSE;
  1057.     g_tm_activated_theme.system_image_list = NULL;
  1058.     g_tm_activated_theme.theme_image_details_list = g_tm_cntx.theme_image_list;
  1059.     mmi_tm_reset_imageid_image_header_pool();
  1060.     mmi_tm_reset_non_imageid_image_header_pool();
  1061. #ifdef __MMI_DLT_CACHE_SUPPORT__
  1062.     g_tm_load_always_offset = 0;
  1063.     mmi_tm_clear_ondemand_cache();
  1064. #endif /* __MMI_DLT_CACHE_SUPPORT__ */ 
  1065.     g_tm_cntx.theme_imageid_image_count = 0;
  1066.     memset(g_tm_theme_image_dirty_bits, 0, sizeof(g_tm_theme_image_dirty_bits));
  1067.     g_tm_cntx.theme_has_wallpaper = FALSE;
  1068.     g_tm_cntx.theme_has_screensaver = FALSE;
  1069.     g_tm_cntx.theme_has_ringtone = FALSE;
  1070.     if (!mmi_tc_convert_theme_file_to_mmi_theme(&(g_tm_activated_theme.theme), g_tm_cntx.theme_file_handle))
  1071.     {
  1072.         return THEME_ERROR_FAILURE;
  1073.     }
  1074.     mmi_tm_sort_theme_image_table();
  1075.     set_MMI_theme(g_tm_activated_theme.theme);
  1076.     MMI_apply_current_theme();
  1077.     g_tm_cntx.curr_activated_theme_id = theme_struct_p->theme_id;
  1078.     g_tm_cntx.curr_activated_theme_type = theme_struct_p->theme_type;
  1079.     WriteValue(THEME_MANAGER_CURR_THEME_ID, (void*)&g_tm_cntx.curr_activated_theme_id, DS_DOUBLE, &err);
  1080.     return THEME_ERROR_SUCCESS;
  1081. }
  1082. /*****************************************************************************
  1083.  * FUNCTION
  1084.  *  mmi_tm_activate_theme_from_fmgr
  1085.  * DESCRIPTION
  1086.  *  This function activates theme from file manager
  1087.  * PARAMETERS
  1088.  *  theme_type          [IN]        
  1089.  *  theme_name_p        [?]         
  1090.  * RETURNS
  1091.  *  theme error code
  1092.  *****************************************************************************/
  1093. U8 mmi_tm_get_themes_for_fmgr(tm_theme_list_struct **theme_list_p, PS8 filename, tm_theme_type_enum storage_type);
  1094. tm_theme_error_enum mmi_tm_activate_theme_from_fmgr(tm_theme_type_enum theme_type, U8 *theme_name_p)
  1095. {
  1096.     /*----------------------------------------------------------------*/
  1097.     /* Local Variables                                                */
  1098.     /*----------------------------------------------------------------*/
  1099.     U8 i;
  1100.     U8 found = 0;
  1101.     tm_theme_error_enum result;
  1102.     U32 len;
  1103.     U16 filename[(MAX_THEME_NAME_LENGTH + 1)];
  1104.     tm_theme_list_struct *theme_list_p;
  1105.     /*----------------------------------------------------------------*/
  1106.     /* Code Body                                                      */
  1107.     /*----------------------------------------------------------------*/
  1108.     if ( mmi_tm_get_usb_mode() )
  1109.     {
  1110.         return THEME_ERROR_USB_MODE_ON;
  1111.     }
  1112.     pfnUnicodeStrcpy((PS8) filename, (PS8) theme_name_p);
  1113.     len = pfnUnicodeStrlen((S8*) filename);
  1114.     for (i = 0; i < len; ++i)
  1115.     {
  1116.         if (filename[i] == 0x7E)    /* tilde */
  1117.         {
  1118.             return THEME_ERROR_FILENAME_INCORRECT;
  1119.         }
  1120.     }
  1121.     /* Check if theme already on the list */
  1122.     for (i = g_tm_cntx.sys_thm_cnt; i < g_tm_cntx.total_thm_cnt; ++i)
  1123.     {
  1124.         if ((pfnUnicodeStrcmp((PS8) g_tm_theme_list[i].theme_name, (PS8) filename) == 0) &&
  1125.             (g_tm_theme_list[i].theme_type == theme_type))
  1126.         {
  1127.             found = 1;
  1128.             break;
  1129.         }
  1130.     }
  1131.     if (found == 0)
  1132.     {
  1133.         /* Try to add theme to theme list */
  1134.         mmi_tm_get_themes_for_fmgr(&theme_list_p, (PS8) filename, theme_type);
  1135.         /* Theme still might not have been added: Check */
  1136.         for (i = g_tm_cntx.sys_thm_cnt; i < g_tm_cntx.total_thm_cnt; ++i)
  1137.         {
  1138.             if ((pfnUnicodeStrcmp((PS8) g_tm_theme_list[i].theme_name, (PS8) filename) == 0) &&
  1139.                 (g_tm_theme_list[i].theme_type == theme_type))
  1140.             {
  1141.                 found = 1;
  1142.                 break;
  1143.             }
  1144.         }
  1145.     }
  1146.     if (found == 0)
  1147.     {
  1148.         return THEME_ERROR_MAX_COUNT_REACHED;
  1149.     }
  1150.     else
  1151.     {
  1152.         if (g_tm_cntx.curr_activated_theme_id == g_tm_theme_list[i].theme_id)
  1153.         {
  1154.             return THEME_ERROR_ALREADY_ACTIVATED;
  1155.         }
  1156.         else
  1157.         {
  1158.             result = mmi_tm_activate_downloaded_theme(&g_tm_theme_list[i]);
  1159.         }
  1160.     }
  1161.     if (result == THEME_ERROR_SUCCESS)
  1162.     {
  1163.         if (g_tm_cntx.theme_has_wallpaper)
  1164.         {
  1165.             ThemeManagerSetWallpaper(IMG_ID_DISPCHAR_THEME_WALLPAPER);
  1166.         }
  1167.         else
  1168.         {
  1169.             if (PhnsetIsWPCurrentTheme())
  1170.             {
  1171.                 ThemeManagerSetWallpaper(IMG_ID_PHNSET_WP_START);
  1172.             }
  1173.         }
  1174.         if (g_tm_cntx.theme_has_screensaver)
  1175.         {
  1176.             ThemeManagerSetScreensaver(IMG_ID_DISPCHAR_THEME_SCREENSAVER);
  1177.         }
  1178.         else
  1179.         {
  1180.             if (PhnsetIsScrSvrCurrentTheme())
  1181.             {
  1182.                 ThemeManagerSetScreensaver(IMG_ID_PHNSET_SS_START);
  1183.             }
  1184.         }
  1185.         if (g_tm_cntx.theme_has_ringtone)
  1186.         {
  1187.             ThemeManagerSetRingTone(CURRENT_THEME_INCOMING_CALL_TONE);
  1188.             ThemeManagerSetAlarmTone(CURRENT_THEME_ALARM_EXPIRY_TONE);
  1189.         }
  1190.         else
  1191.         {
  1192.             ThemeManagerResetRingTone();
  1193.             ThemeManagerResetAlarmTone();
  1194.         }
  1195.         if (mmi_tm_does_theme_have_alt_image())
  1196.         {
  1197.             initialize_status_icons();
  1198.         }
  1199.     }
  1200.     return result;
  1201. }
  1202. /*****************************************************************************
  1203.  * FUNCTION
  1204.  *  mmi_tm_delete_theme
  1205.  * DESCRIPTION
  1206.  *  This function deletes the theme with the corresponding theme id
  1207.  * PARAMETERS
  1208.  *  theme_id        [IN]        
  1209.  *  error_type      [IN]        
  1210.  * RETURNS
  1211.  *  theme error code
  1212.  *****************************************************************************/
  1213. tm_theme_error_enum mmi_tm_delete_theme(THEME_ID theme_id, PS32 error_type)
  1214. {
  1215.     /*----------------------------------------------------------------*/
  1216.     /* Local Variables                                                */
  1217.     /*----------------------------------------------------------------*/
  1218.     U8 i, found = 0;
  1219.     S16 err;
  1220.     /*----------------------------------------------------------------*/
  1221.     /* Code Body                                                      */
  1222.     /*----------------------------------------------------------------*/
  1223.     for (i = g_tm_cntx.sys_thm_cnt; i < g_tm_cntx.total_thm_cnt; ++i)
  1224.     {
  1225.         if (g_tm_theme_list[i].theme_id == theme_id)
  1226.         {
  1227.             found = 1;
  1228.             break;
  1229.         }
  1230.     }
  1231.     if (!found)
  1232.     {
  1233.         return THEME_ERROR_THEME_NOT_AVAILABLE;
  1234.     }
  1235.     else
  1236.     {
  1237.         U8 tmp_file_name[50];
  1238.         U8 file_name[100];
  1239.         if (g_tm_theme_list[i].theme_type == THEME_TYPE_DOWNLOADED_PHONE)
  1240.         {
  1241.             sprintf((PS8) tmp_file_name, "%c%s", MMI_PUBLIC_DRV, DOWNLOADED_THEMES_PATH);
  1242.             AnsiiToUnicodeString((PS8) file_name, (PS8) tmp_file_name);
  1243.         }
  1244.         else
  1245.         {
  1246.             sprintf((PS8) tmp_file_name, "%c%s", MMI_CARD_DRV, DOWNLOADED_THEMES_PATH);
  1247.             AnsiiToUnicodeString((PS8) file_name, (PS8) tmp_file_name);
  1248.         }
  1249.         pfnUnicodeStrcat((PS8) file_name, (PS8) g_tm_theme_list[i].theme_name);
  1250.         if ((*error_type = FS_Delete((U16*) file_name)) == FS_NO_ERROR)
  1251.         {
  1252.             for (; i < g_tm_cntx.total_thm_cnt - 1; ++i)
  1253.             {
  1254.                 memcpy((void*)&g_tm_theme_list[i], (void*)&g_tm_theme_list[i + 1], sizeof(tm_theme_list_struct));
  1255.             }
  1256.             memset((void*)&g_tm_theme_list[g_tm_cntx.total_thm_cnt - 1], 0, sizeof(tm_theme_list_struct));
  1257.             WriteRecord(
  1258.                 NVRAM_EF_THEME_MANAGER_LID,
  1259.                 1,
  1260.                 (void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt),
  1261.                 NVRAM_EF_THEME_MANAGER_RECORD_SIZE,
  1262.                 &err);
  1263.             --g_tm_cntx.total_thm_cnt;
  1264.             return THEME_ERROR_SUCCESS;
  1265.         }
  1266.         else
  1267.         {
  1268.             return THEME_ERROR_FAILURE;
  1269.         }
  1270.     }
  1271. }
  1272. /*****************************************************************************
  1273.  * FUNCTION
  1274.  *  mmi_tm_delete_theme_from_fmgr
  1275.  * DESCRIPTION
  1276.  *  This function deletes theme with the corresponding theme name from file manager
  1277.  * PARAMETERS
  1278.  *  theme_type          [IN]        
  1279.  *  theme_name_p        [?]         
  1280.  *  error_type          [IN]        
  1281.  * RETURNS
  1282.  *  theme error code
  1283.  *****************************************************************************/
  1284. tm_theme_error_enum mmi_tm_delete_theme_from_fmgr(tm_theme_type_enum theme_type, U8 *theme_name_p, PS32 error_type)
  1285. {
  1286.     /*----------------------------------------------------------------*/
  1287.     /* Local Variables                                                */
  1288.     /*----------------------------------------------------------------*/
  1289.     U8 i, found = 0;
  1290.     U8 tmp_file_name[50];
  1291.     U8 file_name[100];
  1292.     S16 err;
  1293.     /*----------------------------------------------------------------*/
  1294.     /* Code Body                                                      */
  1295.     /*----------------------------------------------------------------*/
  1296.     for (i = g_tm_cntx.sys_thm_cnt; i < g_tm_cntx.total_thm_cnt; ++i)
  1297.     {
  1298.         if (!pfnUnicodeStrcmp((PS8) g_tm_theme_list[i].theme_name, (PS8) theme_name_p) &&
  1299.             (g_tm_theme_list[i].theme_type == theme_type))
  1300.         {
  1301.             found = 1;
  1302.             break;
  1303.         }
  1304.     }
  1305.     if (theme_type == THEME_TYPE_DOWNLOADED_PHONE)
  1306.     {
  1307.         sprintf((PS8) tmp_file_name, "%c%s", MMI_PUBLIC_DRV, DOWNLOADED_THEMES_PATH);
  1308.         AnsiiToUnicodeString((PS8) file_name, (PS8) tmp_file_name);
  1309.     }
  1310.     else
  1311.     {
  1312.         sprintf((PS8) tmp_file_name, "%c%s", MMI_CARD_DRV, DOWNLOADED_THEMES_PATH);
  1313.         AnsiiToUnicodeString((PS8) file_name, (PS8) tmp_file_name);
  1314.     }
  1315.     pfnUnicodeStrcat((PS8) file_name, (PS8) theme_name_p);
  1316.     if (found)
  1317.     {
  1318.         if (g_tm_theme_list[i].theme_id == g_tm_cntx.curr_activated_theme_id)
  1319.         {
  1320.             return THEME_ERROR_ALREADY_ACTIVATED;
  1321.         }
  1322.         if ((*error_type = FS_Delete((U16*) file_name)) == FS_NO_ERROR)
  1323.         {
  1324.             for (; i < g_tm_cntx.total_thm_cnt - 1; ++i)
  1325.             {
  1326.                 memcpy((void*)&g_tm_theme_list[i], (void*)&g_tm_theme_list[i + 1], sizeof(tm_theme_list_struct));
  1327.             }
  1328.             memset((void*)&g_tm_theme_list[g_tm_cntx.total_thm_cnt - 1], 0, sizeof(tm_theme_list_struct));
  1329.             WriteRecord(
  1330.                 NVRAM_EF_THEME_MANAGER_LID,
  1331.                 1,
  1332.                 (void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt),
  1333.                 NVRAM_EF_THEME_MANAGER_RECORD_SIZE,
  1334.                 &err);
  1335.             --g_tm_cntx.total_thm_cnt;
  1336.             return THEME_ERROR_SUCCESS;
  1337.         }
  1338.         else
  1339.         {
  1340.             return THEME_ERROR_DELETE_FAILURE;
  1341.         }
  1342.     }
  1343.     else if ((*error_type = FS_Delete((U16*) file_name)) == FS_NO_ERROR)
  1344.     {
  1345.         return THEME_ERROR_SUCCESS;
  1346.     }
  1347.     else
  1348.     {
  1349.         return THEME_ERROR_FAILURE;
  1350.     }
  1351. }
  1352. /*****************************************************************************
  1353.  * FUNCTION
  1354.  *  mmi_tm_get_current_theme_ringtone
  1355.  * DESCRIPTION
  1356.  *  This function gets the current theme ringtone
  1357.  * PARAMETERS
  1358.  *  void
  1359.  * RETURNS
  1360.  *  void
  1361.  *****************************************************************************/
  1362. pBOOL mmi_tm_get_current_theme_ringtone(void)
  1363. {
  1364.     /*----------------------------------------------------------------*/
  1365.     /* Local Variables                                                */
  1366.     /*----------------------------------------------------------------*/
  1367.     /*----------------------------------------------------------------*/
  1368.     /* Code Body                                                      */
  1369.     /*----------------------------------------------------------------*/
  1370.     return g_tm_cntx.theme_has_ringtone;
  1371. }
  1372. /*****************************************************************************
  1373.  * FUNCTION
  1374.  *  mmi_tm_get_theme_version_table
  1375.  * DESCRIPTION
  1376.  *  This function gets the theme version table
  1377.  * PARAMETERS
  1378.  *  void
  1379.  * RETURNS
  1380.  *  void
  1381.  *****************************************************************************/
  1382. const FLOAT *mmi_tm_get_theme_version_table(void)
  1383. {
  1384.     /*----------------------------------------------------------------*/
  1385.     /* Local Variables                                                */
  1386.     /*----------------------------------------------------------------*/
  1387.     /*----------------------------------------------------------------*/
  1388.     /* Code Body                                                      */
  1389.     /*----------------------------------------------------------------*/
  1390.     return g_tm_supported_thm_version_table;
  1391. }
  1392. U32 g_tc_checksumkey = 0xFFFFFFFF;
  1393. extern U8 gFileBuffer[MAX_BUFF_SIZE];
  1394. extern S32 gnFileBytesRead;
  1395. /* update the CRC on the data block one byte at a time */
  1396. /*****************************************************************************
  1397.  * FUNCTION
  1398.  *  mmi_tm_crc32
  1399.  * DESCRIPTION
  1400.  *  This function calls update crc function
  1401.  * PARAMETERS
  1402.  *  Data_p      [?]         
  1403.  *  Length      [IN]        
  1404.  * RETURNS
  1405.  *  void
  1406.  *****************************************************************************/
  1407. U32 mmi_tm_crc32(U8 *Data_p, U16 Length)
  1408. {
  1409.     /*----------------------------------------------------------------*/
  1410.     /* Local Variables                                                */
  1411.     /*----------------------------------------------------------------*/
  1412.     /*----------------------------------------------------------------*/
  1413.     /* Code Body                                                      */
  1414.     /*----------------------------------------------------------------*/
  1415.     return applib_crc_update(g_tc_checksumkey, Data_p, Length);
  1416. }
  1417. /*****************************************************************************
  1418.  * FUNCTION
  1419.  *  mmi_tm_verify_theme_checksum
  1420.  * DESCRIPTION
  1421.  *  This function checks the theme file checksum
  1422.  * PARAMETERS
  1423.  *  file_name_p     [?]     
  1424.  * RETURNS
  1425.  *  theme error code
  1426.  *****************************************************************************/
  1427. tm_theme_error_enum mmi_tm_verify_theme_checksum(U8 *file_name_p)
  1428. {
  1429.     /*----------------------------------------------------------------*/
  1430.     /* Local Variables                                                */
  1431.     /*----------------------------------------------------------------*/
  1432.     S32 no_of_char;
  1433.     U32 checksum[2];
  1434.     FILE_HANDLE file;
  1435.     U32 theme_file_size;
  1436.     U32 bytes_read = 0;
  1437.     /*----------------------------------------------------------------*/
  1438.     /* Code Body                                                      */
  1439.     /*----------------------------------------------------------------*/
  1440. #ifndef MMI_ON_WIN32
  1441.     file = OpenCache((U8*) file_name_p, PFS_READ_BINARY);
  1442. #else 
  1443.     file = OpenCache((U8*) file_name_p, (U8*) "r");
  1444. #endif 
  1445.     if (!file)
  1446.     {
  1447.         return THEME_ERROR_FILE_FORMAT_BAD;
  1448.     }
  1449.     else
  1450.     {
  1451.         /* Read checksum & File Size here, after Opening file get it's size */
  1452.         if (FS_GetFileSize(file, &theme_file_size) != FS_NO_ERROR)
  1453.         {
  1454.             pfclose(file);
  1455.             return THEME_ERROR_FILE_FORMAT_BAD;
  1456.         }
  1457.         if (gnFileBytesRead > (THEME_CHECKSUM_HEADER_SIZE + THEME_FILE_SIZE_HEADER))
  1458.         {
  1459.             pCacheFileRead(file, THEME_CHECKSUM_HEADER_SIZE + THEME_FILE_SIZE_HEADER, &no_of_char, (U8*) & checksum);
  1460.             FS_Seek(file, (THEME_CHECKSUM_HEADER_SIZE + THEME_FILE_SIZE_HEADER), FS_FILE_BEGIN);
  1461.             /* 4 bytes of File Size are used to calculate CRC therefore we need to include in CRC checking */
  1462.         }
  1463.         else
  1464.         {
  1465.             pfclose(file);
  1466.             return THEME_ERROR_FILE_FORMAT_BAD;
  1467.         }
  1468.         if (theme_file_size != checksum[1])
  1469.         {
  1470.             pfclose(file);
  1471.             return THEME_ERROR_FILE_FORMAT_BAD;
  1472.         }
  1473.         /* Tricky THEME_NO_OF_BYTE_TO_CHECK_FOR_CRC is assumed to be multiple of MAX_BUFF_SIZE */
  1474.         while (bytes_read < (THEME_NO_OF_BYTE_TO_CHECK_FOR_CRC))        /*  0x80000 Bytes => 512 * 1024 = 524288 Bytes */
  1475.         {
  1476.             StartFileRead(file, 0);
  1477.             if (gnFileBytesRead == MAX_BUFF_SIZE)
  1478.             {
  1479.                 bytes_read += gnFileBytesRead;
  1480.                 g_tc_checksumkey = mmi_tm_crc32(gFileBuffer, (U16) gnFileBytesRead);
  1481.             }
  1482.             else if (gnFileBytesRead != 0 && gnFileBytesRead < MAX_BUFF_SIZE)
  1483.             {
  1484.                 bytes_read += gnFileBytesRead;
  1485.                 g_tc_checksumkey = mmi_tm_crc32(gFileBuffer, (U16) gnFileBytesRead);
  1486.                 break;
  1487.             }
  1488.             /* PMT DLT_FIXES - TK 20060321 START */
  1489.             else
  1490.             {
  1491.                 break;  /* boundary value analysis is not consider here so this loop is */
  1492.             }
  1493.             /* PMT DLT_FIXES - TK 20060321 END */
  1494.         }
  1495.     }
  1496.     pfclose(file);
  1497.     if (g_tc_checksumkey == checksum[0])
  1498.     {
  1499.         g_tc_checksumkey = 0xFFFFFFFF;
  1500.         return THEME_ERROR_SUCCESS;
  1501.     }
  1502.     else
  1503.     {
  1504.         g_tc_checksumkey = 0xFFFFFFFF;
  1505.         return THEME_ERROR_FILE_FORMAT_BAD;
  1506.     }
  1507. }
  1508. #ifdef __DLT_ENABLE_PROCESS_QUEUE__
  1509. /*****************************************************************************
  1510.  * FUNCTION
  1511.  *  mmi_tm_theme_process_queue
  1512.  * DESCRIPTION
  1513.  *  This function polls for message queue
  1514.  * PARAMETERS
  1515.  *  void
  1516.  *  a(?)        [IN/OUT]        None/Error status
  1517.  *  b(?)        [IN]            None
  1518.  * RETURNS
  1519.  *  theme error code
  1520.  *****************************************************************************/
  1521. tm_theme_error_enum mmi_tm_theme_process_queue(void)
  1522. {
  1523. #ifndef MMI_ON_WIN32
  1524.     /*----------------------------------------------------------------*/
  1525.     /* Local Variables                                                */
  1526.     /*----------------------------------------------------------------*/
  1527.     MYQUEUE queueNode;
  1528.     /* MMIEQNVRAMREADRSP *readMessage; */
  1529.     unsigned int my_index;
  1530.     /*----------------------------------------------------------------*/
  1531.     /* Code Body                                                      */
  1532.     /*----------------------------------------------------------------*/
  1533.     /* MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_REC_INT_HDLR, nFileId, nRecordId)); */
  1534.     /* SendNVRAMReadReq(nFileId,nRecordId); */
  1535.     OslReceiveMsgExtQ(mmi_ext_qid, &queueNode);
  1536.     OslGetMyTaskIndex(&my_index);
  1537.     OslStackSetActiveModuleID(my_index, MOD_MMI);
  1538.     switch (queueNode.msg_id)
  1539.     {
  1540.             /* case PRT_INCOMINGCALL_EVENT:
  1541.                ProtocolEventHandler((U16)queueNode.oslMsgId,(void*)queueNode.oslDataPtr,(int)queueNode.oslSrcId, (void*) queueNode.oslPeerBuffPtr );
  1542.                return THEME_ERROR_INCOMING_CALL;
  1543.                break; */
  1544.         case MSG_ID_MMI_EQ_PLAY_AUDIO_RSP:
  1545.         case MSG_ID_MMI_EQ_STOP_AUDIO_RSP:
  1546.         case MSG_ID_MMI_EQ_EXE_GPIO_LEVEL_RSP:
  1547.         case MSG_ID_MMI_EQ_SET_VOLUME_RSP:
  1548.             OslFreeInterTaskMsg(&queueNode);
  1549.             break;
  1550.         case MSG_ID_MMI_EQ_KEYPAD_DETECT_IND:
  1551.         {
  1552.             if (mmi_bootup_is_searching_or_idle_reached() == MMI_FALSE)
  1553.             {
  1554.                 KeyHandleBeforePWRON((void*)queueNode.oslDataPtr);
  1555.             }
  1556.             else
  1557.             {
  1558.                 mmi_eq_keypad_detect_ind_struct *p;
  1559.                 p = (mmi_eq_keypad_detect_ind_struct*) queueNode.local_para_ptr;
  1560.                 g_keypad_flag = MMI_TRUE;
  1561.                 keypad_ptr = p->func;
  1562.             }
  1563.             OslFreeInterTaskMsg(&queueNode);
  1564.             break;
  1565.         }
  1566.         case MSG_ID_MMI_EQ_GET_RTC_TIME_RSP:
  1567.         {
  1568.             if (mmi_bootup_is_searching_or_idle_reached() == MMI_FALSE)
  1569.             {
  1570.                 ProtocolEventHandler(
  1571.                     (U16) queueNode.oslMsgId,
  1572.                     (void*)queueNode.oslDataPtr,
  1573.                     (int)queueNode.oslSrcId,
  1574.                     (void*)queueNode.oslPeerBuffPtr);
  1575.                 OslFreeInterTaskMsg(&queueNode);
  1576.                 break;
  1577.             }
  1578.         }
  1579.         case MSG_ID_TIMER_EXPIRY:
  1580.         {
  1581.             /* if(!g_pwr_context.idleScreenFirst) */
  1582.             {
  1583.                 kal_uint16 msg_len;
  1584.                 EvshedMMITimerHandler(get_local_para_ptr(queueNode.oslDataPtr, &msg_len));
  1585.                 break;
  1586.             }
  1587.             /* else
  1588.                {
  1589.                stack_timer_struct* stack_timer_ptr;
  1590.                stack_timer_ptr = (stack_timer_struct*)queueNode.oslDataPtr;
  1591.                if (!stack_is_time_out_valid(stack_timer_ptr))
  1592.                {
  1593.                PRINT_INFORMATION(("==========Time out is not valid=========="));
  1594.                OslFreeInterTaskMsg(&queueNode);       
  1595.                break;   
  1596.                }
  1597.                } */
  1598.         }
  1599.         default:
  1600.         {
  1601.             ilm_struct ilm_ptr;
  1602.             U8 flag = 0;
  1603.             ilm_ptr.src_mod_id = queueNode.src_mod_id;
  1604.             ilm_ptr.dest_mod_id = queueNode.dest_mod_id;
  1605.             ilm_ptr.msg_id = queueNode.msg_id;
  1606.             ilm_ptr.sap_id = queueNode.sap_id;
  1607.             ilm_ptr.local_para_ptr = queueNode.local_para_ptr;
  1608.             ilm_ptr.peer_buff_ptr = queueNode.peer_buff_ptr;
  1609.             flag = OslWriteCircularQ(&ilm_ptr);
  1610.             /* TIMER use special data in the local_para_ptr field. Can NOT treat as general ILM */
  1611.             if ((queueNode.src_mod_id != MOD_TIMER) && (flag == 1))
  1612.             {
  1613.                 hold_local_para(ilm_ptr.local_para_ptr);
  1614.                 hold_peer_buff(ilm_ptr.peer_buff_ptr);
  1615.             }
  1616.             OslFreeInterTaskMsg(&queueNode);
  1617.             break;
  1618.         }
  1619.     }
  1620.     OslFreeInterTaskMsg(&queueNode);
  1621.     return THEME_ERROR_PROCESS_QUEUE_SUCESS;
  1622. #endif /* MMI_ON_WIN32 */ 
  1623.     return THEME_ERROR_PROCESS_QUEUE_SUCESS;
  1624. }
  1625. #endif /* __DLT_ENABLE_PROCESS_QUEUE__ */ 
  1626. /*****************************************************************************
  1627.  * FUNCTION
  1628.  *  mmi_tm_handle_theme_activation_error_status
  1629.  * DESCRIPTION
  1630.  *  This function handles error status at the time of theme activation
  1631.  * PARAMETERS
  1632.  *  status      [IN]        
  1633.  * RETURNS
  1634.  *  void
  1635.  *****************************************************************************/
  1636. void mmi_tm_handle_theme_activation_error_status(U16 status)
  1637. {
  1638.     /*----------------------------------------------------------------*/
  1639.     /* Local Variables                                                */
  1640.     /*----------------------------------------------------------------*/
  1641.     /*----------------------------------------------------------------*/
  1642.     /* Code Body                                                      */
  1643.     /*----------------------------------------------------------------*/
  1644.     switch (status)
  1645.     {
  1646.         case THEME_ERROR_SUCCESS:
  1647.             DisplayPopup(
  1648.                 (PU8) GetString(STR_THEME_ACTIVATE_SUCCESS),
  1649.                 IMG_GLOBAL_ACTIVATED,
  1650.                 0,
  1651.                 UI_POPUP_NOTIFYDURATION_TIME,
  1652.                 SUCCESS_TONE);
  1653.             break;
  1654.         case THEME_ERROR_SPACE_NOT_AVAILABLE:
  1655.             DisplayPopup(
  1656.                 (PU8) GetString(STR_ID_FMGR_SPACE_NOT_AVAILABLE),
  1657.                 IMG_GLOBAL_EMPTY,
  1658.                 0,
  1659.                 UI_POPUP_NOTIFYDURATION_TIME,
  1660.                 WARNING_TONE);
  1661.             break;
  1662.         case THEME_ERROR_THEME_NOT_AVAILABLE:
  1663.             DisplayPopup(
  1664.                 (PU8) GetString(STR_THEME_NOT_AVAILABLE),
  1665.                 IMG_GLOBAL_ERROR,
  1666.                 0,
  1667.                 UI_POPUP_NOTIFYDURATION_TIME,
  1668.                 WARNING_TONE);
  1669.             break;
  1670.         case THEME_ERROR_FILE_FORMAT_BAD:
  1671.             DisplayPopup(
  1672.                 (PU8) GetString(STR_THEME_FORMAT_NOT_SUPPORTED),
  1673.                 IMG_GLOBAL_ERROR,
  1674.                 0,
  1675.                 UI_POPUP_NOTIFYDURATION_TIME,
  1676.                 WARNING_TONE);
  1677.             break;
  1678.         case THEME_ERROR_FAILURE:
  1679.             DisplayPopup(
  1680.                 (PU8) GetString(STR_THEME_UNKNOWN_ERROR),
  1681.                 IMG_GLOBAL_ERROR,
  1682.                 0,
  1683.                 UI_POPUP_NOTIFYDURATION_TIME,
  1684.                 WARNING_TONE);
  1685.             break;
  1686.         case THEME_ERROR_ALREADY_ACTIVATED:
  1687.             DisplayPopup(
  1688.                 (PU8) GetString(STR_ID_FMGR_ALREADY_ACTIVE),
  1689.                 IMG_GLOBAL_ACTIVATED,
  1690.                 0,
  1691.                 UI_POPUP_NOTIFYDURATION_TIME,
  1692.                 WARNING_TONE);
  1693.             break;
  1694.         case THEME_ERROR_MAX_COUNT_REACHED:
  1695.             DisplayPopup((PU8) GetString(STR_ID_FMGR_MAX_COUNT_REACHED), IMG_GLOBAL_ERROR, 0, 1000, WARNING_TONE);
  1696.             break;
  1697.         case THEME_ERROR_VERSION_FAILURE:
  1698.             DisplayPopup(
  1699.                 (PU8) GetString(STR_DOWNLOAD_THEME_UNSUPPORTED),
  1700.                 IMG_GLOBAL_WARNING,
  1701.                 0,
  1702.                 UI_POPUP_NOTIFYDURATION_TIME,
  1703.                 WARNING_TONE);
  1704.             break;
  1705.         case THEME_ERROR_PROCESS_QUEUE_SUCESS:
  1706.             DisplayPopup(NULL, IMG_PROCESSING_PHONEBOOK, 1, UI_POPUP_NOTIFYDURATION_TIME, 0);
  1707.             break;
  1708.         case THEME_ERROR_LCD_SIZE_MISMATCH:
  1709.             DisplayPopup(
  1710.                 (PU8) GetString(STR_LCD_SIZE_MISMATCH),
  1711.                 IMG_GLOBAL_ERROR,
  1712.                 TRUE,
  1713.                 UI_POPUP_NOTIFYDURATION_TIME,
  1714.                 WARNING_TONE);
  1715.             break;
  1716.         case THEME_ERROR_FILENAME_INCORRECT:
  1717.             DisplayPopup(
  1718.                 (PU8) GetString(STR_THEME_ERROR_FILENAME_INCORRECT),
  1719.                 IMG_GLOBAL_WARNING,
  1720.                 0,
  1721.                 UI_POPUP_NOTIFYDURATION_TIME,
  1722.                 WARNING_TONE);
  1723.             break;
  1724.         case THEME_ERROR_PHONE_MODEL_MISMATCH:
  1725.             DisplayPopup(
  1726.                 (PU8) GetString(STR_THEME_ERROR_PHONE_MODEL_MISMATCH),
  1727.                 IMG_GLOBAL_WARNING,
  1728.                 0,
  1729.                 UI_POPUP_NOTIFYDURATION_TIME,
  1730.                 WARNING_TONE);
  1731.             break;
  1732.         case THEME_ERROR_USB_MODE_ON:
  1733.             DisplayPopup(
  1734.                 (PU8) GetString(STR_ID_USB_MODE_EXPORTED_WARNING),
  1735.                 IMG_GLOBAL_ERROR,
  1736.                 TRUE,
  1737.                 UI_POPUP_NOTIFYDURATION_TIME,
  1738.                 WARNING_TONE);
  1739.             break;
  1740.         default:
  1741.             DisplayPopup(
  1742.                 (PU8) GetString(STR_THEME_UNKNOWN_ERROR),
  1743.                 IMG_GLOBAL_ERROR,
  1744.                 0,
  1745.                 UI_POPUP_NOTIFYDURATION_TIME,
  1746.                 WARNING_TONE);
  1747.             break;
  1748.     }
  1749. }
  1750. /*****************************************************************************
  1751.  * FUNCTION
  1752.  *  mmi_tm_set_was_theme_alarm_cb
  1753.  * DESCRIPTION
  1754.  *  
  1755.  * PARAMETERS
  1756.  *  void
  1757.  * RETURNS
  1758.  *  void
  1759.  *****************************************************************************/
  1760. void mmi_tm_set_was_theme_alarm_cb(void)
  1761. {
  1762.     /*----------------------------------------------------------------*/
  1763.     /* Local Variables                                                */
  1764.     /*----------------------------------------------------------------*/
  1765.     /*----------------------------------------------------------------*/
  1766.     /* Code Body                                                      */
  1767.     /*----------------------------------------------------------------*/
  1768.     g_tm_was_theme_alarm_cb = MMI_TRUE;
  1769. }
  1770. /*****************************************************************************
  1771.  * FUNCTION
  1772.  *  mmi_tm_init_theme_usb_mode_plugin_callback
  1773.  * DESCRIPTION
  1774.  *  
  1775.  * PARAMETERS
  1776.  *  void
  1777.  * RETURNS
  1778.  *  void
  1779.  *****************************************************************************/
  1780. void mmi_tm_init_theme_usb_mode_plugin_callback(void)
  1781. {
  1782.     /*----------------------------------------------------------------*/
  1783.     /* Local Variables                                                */
  1784.     /*----------------------------------------------------------------*/
  1785. S16 err;
  1786.     /*----------------------------------------------------------------*/
  1787.     /* Code Body                                                      */
  1788.     /*----------------------------------------------------------------*/
  1789.     if (mmi_tm_get_curr_theme_type() != THEME_TYPE_SYSTEM)  /* fixed for usb */
  1790.     {
  1791. WriteValue(NVRAM_USB_PREVIOUS_THEME_INDEX, (void*)&g_tm_cntx.curr_activated_theme_id, DS_DOUBLE, &err);
  1792.         ActivateDefaultTheme();
  1793.         g_thm_cntx.CurrTheme = mmi_tm_get_current_theme_id();
  1794.     }
  1795.     g_tm_USB_mode = TRUE;
  1796. }
  1797. /*****************************************************************************
  1798.  * FUNCTION
  1799.  *  mmi_tm_init_theme_usb_mode_plugout_callback
  1800.  * DESCRIPTION
  1801.  *  
  1802.  * PARAMETERS
  1803.  *  void
  1804.  * RETURNS
  1805.  *  void
  1806.  *****************************************************************************/
  1807. void mmi_tm_init_theme_usb_mode_plugout_callback(void)
  1808. {
  1809.     /*----------------------------------------------------------------*/
  1810.     /* Local Variables                                                */
  1811.     /*----------------------------------------------------------------*/
  1812.     U16 period;
  1813. S16 err;
  1814.     U64 buff;     
  1815. U32 usb_id;
  1816.     /*----------------------------------------------------------------*/
  1817.     /* Code Body                                                      */
  1818.     /*----------------------------------------------------------------*/
  1819. ReadValue(NVRAM_USB_PREVIOUS_THEME_INDEX, (void*)&buff, DS_DOUBLE, &err);
  1820. usb_id = (U32) buff;
  1821. if (usb_id != -1)
  1822. {
  1823. WriteValue(THEME_MANAGER_CURR_THEME_ID, (void*)&usb_id, DS_DOUBLE, &err);
  1824.         mmi_tm_activate_theme(usb_id);
  1825. usb_id = -1;
  1826. WriteValue(NVRAM_USB_PREVIOUS_THEME_INDEX, (void*)&usb_id, DS_DOUBLE, &err);
  1827. }
  1828.     g_tm_USB_mode = FALSE;
  1829.     if (g_tm_was_theme_alarm_cb == MMI_TRUE)
  1830.     {
  1831.         ThemeAlarmCallBack(0, &period, 0);
  1832.         g_tm_was_theme_alarm_cb = MMI_FALSE;
  1833.     }
  1834. }
  1835. /*****************************************************************************
  1836.  * FUNCTION
  1837.  *  mmi_tm_get_usb_mode
  1838.  * DESCRIPTION
  1839.  *  
  1840.  * PARAMETERS
  1841.  *  void
  1842.  * RETURNS
  1843.  *  
  1844.  *****************************************************************************/
  1845. BOOL mmi_tm_get_usb_mode(void)
  1846. {
  1847.     /*----------------------------------------------------------------*/
  1848.     /* Local Variables                                                */
  1849.     /*----------------------------------------------------------------*/
  1850.     /*----------------------------------------------------------------*/
  1851.     /* Code Body                                                      */
  1852.     /*----------------------------------------------------------------*/
  1853.     if (g_tm_USB_mode || (g_pwr_context.PowerOnMode == POWER_ON_USB))
  1854.     {
  1855.         return TRUE;
  1856.     }
  1857.     return FALSE;
  1858. }
  1859. /*****************************************************************************
  1860.  * FUNCTION
  1861.  *  mmi_tm_get_audio_filename
  1862.  * DESCRIPTION
  1863.  *  It gives the theme tone virtual file name
  1864.  * PARAMETERS
  1865.  *  index       [IN]        
  1866.  * RETURNS
  1867.  *  string of theme tone virtual file name
  1868.  *****************************************************************************/
  1869. S8 *mmi_tm_get_audio_filename(U8 index)
  1870. {
  1871.     /*----------------------------------------------------------------*/
  1872.     /* Local Variables                                                */
  1873.     /*----------------------------------------------------------------*/
  1874.     /*----------------------------------------------------------------*/
  1875.     /* Code Body                                                      */
  1876.     /*----------------------------------------------------------------*/
  1877.     return (S8*) gVirAudFileNameList[index];
  1878. }
  1879. #endif /* __MMI_DOWNLOADABLE_THEMES_SUPPORT__ */
  1880. #if (defined(__MMI_THEMES_V2_SUPPORT__))
  1881. /*****************************************************************************
  1882.  * FUNCTION
  1883.  *  mmi_tm_activate_default_theme
  1884.  * DESCRIPTION
  1885.  *  This function is called when the file access has failed for some reason.
  1886.  *  As a safegaurd it activates the default theme to insure nothing else breaks
  1887.  * PARAMETERS
  1888.  *  void
  1889.  * RETURNS
  1890.  *  void
  1891.  *****************************************************************************/
  1892. void mmi_tm_activate_default_theme(void)
  1893. {
  1894.     /*----------------------------------------------------------------*/
  1895.     /* Local Variables                                                */
  1896.     /*----------------------------------------------------------------*/
  1897. #ifdef __J2ME__
  1898. U8 IsJavaPlaying = FALSE;
  1899. #endif
  1900.     /*----------------------------------------------------------------*/
  1901.     /* Code Body                                                      */
  1902.     /*----------------------------------------------------------------*/
  1903.     PRINT_INFORMATION(("mmi_tm_activate_default_theme"));
  1904.     if (mmi_tm_get_curr_theme_type() != THEME_TYPE_SYSTEM)
  1905.     {
  1906. #ifdef __J2ME__
  1907.         if (GetActiveScreenId() ==  SCR_JAVA_APP)
  1908.         {
  1909.             EntryNewScreen(GLOBAL_SCR_DUMMY, NULL, NULL, NULL);
  1910.             ShowCategory66Screen(
  1911.                 STR_SCR3001_THEMES_CAPTION,
  1912.                 0,
  1913.                 0,
  1914.                 0,
  1915.                 0,
  1916.                 0,
  1917.                 (PU8) GetString(STR_ID_DLT_THM_PROGRESS),
  1918.                 IMG_THEME_ACTIVATION,
  1919.                 NULL);
  1920.           IsJavaPlaying = TRUE;
  1921.         }
  1922. #endif /* __J2ME__ */ 
  1923.         mmi_tm_activate_theme(DefaultThmID);
  1924.         g_thm_cntx.CurrTheme = mmi_tm_get_current_theme_id();
  1925.         SetThemes(g_thm_cntx.CurrTheme);
  1926.         DisplayPopup( (U8*) GetString(STR_DEFAULT_THEME_ACTIVATION), 
  1927.                     IMG_GLOBAL_WARNING,
  1928.                     0,
  1929.                     UI_POPUP_NOTIFYDURATION_TIME,
  1930.                     WARNING_TONE);
  1931. #ifdef __J2ME__
  1932. if(IsJavaPlaying == TRUE)
  1933. {
  1934. DeleteUptoScrID(SCR_JAVA_APP);
  1935. }
  1936. #endif
  1937.     
  1938.     }
  1939. }
  1940. /*****************************************************************************
  1941.  * FUNCTION
  1942.  *  mmi_tm_handle_file_access_failed
  1943.  * DESCRIPTION
  1944.  *  This function is called when the file access has failed for some reason.
  1945.  *  As a safegaurd it activates the default theme to insure nothing else breaks
  1946.  * PARAMETERS
  1947.  *  void
  1948.  * RETURNS
  1949.  *  void
  1950.  *****************************************************************************/
  1951. void mmi_tm_handle_file_access_failed(void)
  1952. {
  1953.     /*----------------------------------------------------------------*/
  1954.     /* Local Variables                                                */
  1955.     /*----------------------------------------------------------------*/
  1956.     /*----------------------------------------------------------------*/
  1957.     /* Code Body                                                      */
  1958.     /*----------------------------------------------------------------*/
  1959.     gui_start_timer ( 200,  mmi_tm_activate_default_theme ); 
  1960. }
  1961. /*****************************************************************************
  1962.  * FUNCTION
  1963.  *  mmi_theme_manager_init
  1964.  * DESCRIPTION
  1965.  *  It initilizes the global theme structure 'g_tm_cntx'
  1966.  * PARAMETERS
  1967.  *  void
  1968.  * RETURNS
  1969.  *  void
  1970.  *****************************************************************************/
  1971. void mmi_theme_manager_init(void)
  1972. {
  1973.     /*----------------------------------------------------------------*/
  1974.     /* Local Variables                                                */
  1975.     /*----------------------------------------------------------------*/
  1976.     /*----------------------------------------------------------------*/
  1977.     /* Code Body                                                      */
  1978.     /*----------------------------------------------------------------*/
  1979.     memset((void*)&g_tm_cntx, 0, sizeof(tm_context_struct));
  1980. #ifdef __MMI_DOWNLOADABLE_THEMES_SUPPORT__      /* ritesh */
  1981.     mmi_tm_create_image_header_pool(
  1982.         &(g_tm_cntx.imageid_images_headers),
  1983.         g_tm_cntx.imageid_images_headers_pool,
  1984.         MAX_THEME_IMAGE_HEADER_LENGTH,
  1985.         (MAX_THEME_IMAGE_HEADER_LENGTH * MAX_THEME_IMAGEID_IMAGES));
  1986.     mmi_tm_create_image_header_pool(
  1987.         &(g_tm_cntx.non_imageid_images_headers),
  1988.         g_tm_cntx.non_imageid_images_headers_pool,
  1989.         MAX_THEME_IMAGE_HEADER_LENGTH,
  1990.         (MAX_THEME_IMAGE_HEADER_LENGTH * MAX_THEME_NON_IMAGEID_IMAGES));
  1991. #endif /* __MMI_DOWNLOADABLE_THEMES_SUPPORT__ */ /* ritesh */
  1992. }
  1993. /*****************************************************************************
  1994.  * FUNCTION
  1995.  *  mmi_tm_get_system_theme_image
  1996.  * DESCRIPTION
  1997.  *  It returns system theme image pointer
  1998.  * PARAMETERS
  1999.  *  image_index     [IN]        
  2000.  * RETURNS
  2001.  *  void
  2002.  *****************************************************************************/
  2003. void *mmi_tm_get_system_theme_image(U32 image_index)
  2004. {
  2005.     /*----------------------------------------------------------------*/
  2006.     /* Local Variables                                                */
  2007.     /*----------------------------------------------------------------*/
  2008.     /*----------------------------------------------------------------*/
  2009.     /* Code Body                                                      */
  2010.     /*----------------------------------------------------------------*/
  2011.     return g_tm_activated_theme.system_image_list[image_index];
  2012. }
  2013. /*****************************************************************************
  2014.  * FUNCTION
  2015.  *  mmi_tm_set_imageid
  2016.  * DESCRIPTION
  2017.  *  this function sets the image id and image offset of the image
  2018.  * PARAMETERS
  2019.  *  image_id            [IN]        
  2020.  *  image_offset        [IN]        
  2021.  *  type                [IN]        
  2022.  * RETURNS
  2023.  *  void
  2024.  *****************************************************************************/
  2025. void mmi_tm_set_imageid(U16 image_id, U32 image_offset, tm_image_load_type_enum type)
  2026. {
  2027.     /*----------------------------------------------------------------*/
  2028.     /* Local Variables                                                */
  2029.     /*----------------------------------------------------------------*/
  2030.     U16 image_index;
  2031.     U16 n_byte;
  2032.     U8 n_bit;
  2033.     /*----------------------------------------------------------------*/
  2034.     /* Code Body                                                      */
  2035.     /*----------------------------------------------------------------*/
  2036.     if (g_tm_cntx.theme_imageid_image_count >= MAX_THEME_IMAGEID_IMAGES)
  2037.     {
  2038.         return;
  2039.     }
  2040.     else
  2041.     {
  2042.         PRINT_INFORMATION(("mmi_tm_set_imageid: image_id =%d has type = %dn", image_id, type));
  2043. if(image_id == IMG_ID_DISPCHAR_THEME_WALLPAPER)
  2044. g_tm_cntx.theme_has_wallpaper = TRUE;
  2045. if(image_id == IMG_ID_DISPCHAR_THEME_SCREENSAVER)
  2046. g_tm_cntx.theme_has_screensaver = TRUE;
  2047.         g_tm_cntx.theme_image_list[g_tm_cntx.theme_imageid_image_count].image_id = image_id;
  2048.         g_tm_cntx.theme_image_list[g_tm_cntx.theme_imageid_image_count].image_offset = image_offset;
  2049.     #ifdef __MMI_DLT_CACHE_SUPPORT__
  2050.         g_tm_cntx.theme_image_list[g_tm_cntx.theme_imageid_image_count].image_type = type;
  2051.         g_tm_cntx.theme_image_list[g_tm_cntx.theme_imageid_image_count].image_cache_ptr = 0;
  2052.     #endif /* __MMI_DLT_CACHE_SUPPORT__ */ 
  2053.         ++g_tm_cntx.theme_imageid_image_count;
  2054.         g_tm_cntx.theme_has_alternate_image = TRUE;
  2055.         image_index = GetImageIndex(image_id);
  2056.         n_byte = (image_index >> 3);
  2057.         n_bit = (image_index % 8);
  2058.         g_tm_theme_image_dirty_bits[n_byte] |= (0x80 >> n_bit);
  2059.     }
  2060. }
  2061. /*****************************************************************************
  2062.  * FUNCTION
  2063.  *  mmi_tm_get_themes_for_fmgr
  2064.  * DESCRIPTION
  2065.  *  1. Purge the theme list of any non-existant themes
  2066.  *  2. Add theme to list if space available.
  2067.  * PARAMETERS
  2068.  *  theme_list_p        [IN]        
  2069.  *  filename            [IN]        
  2070.  *  storage_type        [IN]        
  2071.  * RETURNS
  2072.  *  total number of themes
  2073.  *****************************************************************************/
  2074. U8 mmi_tm_get_themes_for_fmgr(tm_theme_list_struct **theme_list_p, PS8 filename, tm_theme_type_enum storage_type)
  2075. {
  2076.     /*----------------------------------------------------------------*/
  2077.     /* Local Variables                                                */
  2078.     /*----------------------------------------------------------------*/
  2079.     S32 nvm_card_thm_cnt = 0;
  2080.     tm_theme_list_struct *tmp_theme_list_p;
  2081.     U8 j, k;
  2082.     S16 err;
  2083.     U32 max_theme_id;
  2084.     U64 buff;
  2085.     U8 *temp_name;
  2086.     U8 nSystemThemeCount;
  2087.     S16 error_code;
  2088.     S8 tmp_str[MAX_DWNL_THM_PATH_LEN + MAX_THEME_SEARCH_STR_LEN];
  2089.     U16 theme_path[MAX_DWNL_THM_PATH_LEN + MAX_THEME_SEARCH_STR_LEN + MAX_THEME_NAME_LENGTH + 1];
  2090.     U16 theme_path_phone[MAX_DWNL_THM_PATH_LEN];    /* Plus 2 for MMI_PUBLIC_DRV: check */
  2091.     U16 theme_path_card[MAX_DWNL_THM_PATH_LEN];     /* Plus 2 for MMI_CARD_DRV: check */
  2092.     U16 theme_search_path[MAX_DWNL_THM_PATH_LEN + MAX_THEME_SEARCH_STR_LEN];
  2093.     /*----------------------------------------------------------------*/
  2094.     /* Code Body                                                      */
  2095.     /*----------------------------------------------------------------*/
  2096.     nSystemThemeCount = (U8) GetThemesNames((U8 ***) & temp_name);
  2097.     if (nSystemThemeCount > MAX_SYSTEM_THEMES)
  2098.     {
  2099.         nSystemThemeCount = MAX_SYSTEM_THEMES;
  2100.     }
  2101.     memset((void*)g_tm_theme_list, 0, sizeof(tm_theme_list_struct) * TOTAL_THEMES_COUNT);
  2102.     g_tm_cntx.total_thm_cnt = 0;
  2103.     g_tm_cntx.sys_thm_cnt = 0;
  2104.     for (j = 0; j < nSystemThemeCount; ++j)
  2105.     {
  2106.         pfnUnicodeStrncpy(
  2107.             (PS8) g_tm_theme_list[j].theme_name,
  2108.             GetString((U16) (STR_THEME_DEFAULT + j)),
  2109.             MAX_THEME_NAME_LENGTH);
  2110.         g_tm_theme_list[j].theme_checksum_verified = CHECKSUM_VERIFIED_OK;
  2111.         g_tm_theme_list[j].theme_id = j + 1;
  2112.         g_tm_theme_list[j].theme_type = THEME_TYPE_SYSTEM;
  2113.     }
  2114.     g_tm_cntx.total_thm_cnt = g_tm_cntx.sys_thm_cnt = nSystemThemeCount;
  2115.     /* Read Themes from NVRAM */
  2116.     ReadRecord(
  2117.         NVRAM_EF_THEME_MANAGER_LID,
  2118.         1,
  2119.         (void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt),
  2120.         NVRAM_EF_THEME_MANAGER_RECORD_SIZE,
  2121.         &err);
  2122.     /* err = 1 => NVRAM_READ_SUCCESS */
  2123.     if (err != NVRAM_READ_SUCCESS)
  2124.     {
  2125.         *theme_list_p = g_tm_theme_list;
  2126.         return g_tm_cntx.total_thm_cnt;
  2127.     }
  2128.     /* Sukrit: A better way to do it will be through something like does file exists on phone folder */
  2129.     sprintf(tmp_str, "%c%s", MMI_PUBLIC_DRV, DOWNLOADED_THEMES_PATH);
  2130.     AnsiiToUnicodeString((PS8) theme_path_phone, tmp_str);
  2131.     sprintf(tmp_str, "%c%s", MMI_CARD_DRV, DOWNLOADED_THEMES_PATH);
  2132.     AnsiiToUnicodeString((PS8) theme_path_card, tmp_str);
  2133.     ReadValue(THEME_MANAGER_MAX_THEME_ID, (void*)&buff, DS_DOUBLE, &err);
  2134.     max_theme_id = (U32) buff;
  2135.     if (max_theme_id == 0xFFFFFFFF || err == -1)
  2136.     {
  2137.         max_theme_id = 10;
  2138.         WriteValue(THEME_MANAGER_MAX_THEME_ID, (void*)&max_theme_id, DS_DOUBLE, &err);
  2139.     }
  2140.     tmp_theme_list_p = (tm_theme_list_struct*) & g_tm_NvramThmArr;
  2141.     /* Get all themes from NVRAM list, which are actually present on Phone, in a new theme list */
  2142.     /* Also, Count number of themes on phone and card that are actually on NVRAM */
  2143.     for (j = g_tm_cntx.sys_thm_cnt, k = 0; j < TOTAL_THEMES_COUNT; ++j)
  2144.     {
  2145.         if ((g_tm_theme_list[j].theme_type == THEME_TYPE_DOWNLOADED_PHONE))
  2146.         {
  2147.             pfnUnicodeStrncpy((PS8) theme_path, (PS8) theme_path_phone, MAX_DWNL_THM_PATH_LEN);
  2148.             pfnUnicodeStrncat((PS8) theme_path, (PS8) g_tm_theme_list[j].theme_name, MAX_THEME_NAME_LENGTH);
  2149.             error_code = FS_GetAttributes(theme_path);
  2150.             if ((error_code > 0) || (error_code == FS_ACCESS_DENIED))
  2151.             {
  2152.                 memcpy((void*)(tmp_theme_list_p + k), (void*)&g_tm_theme_list[j], sizeof(tm_theme_list_struct));
  2153.                 ++k;
  2154.             }
  2155.         }
  2156.         else if (g_tm_theme_list[j].theme_type == THEME_TYPE_DOWNLOADED_CARD)
  2157.         {
  2158.             pfnUnicodeStrncpy((PS8) theme_path, (PS8) theme_path_card, MAX_DWNL_THM_PATH_LEN);
  2159.             pfnUnicodeStrncat((PS8) theme_path, (PS8) g_tm_theme_list[j].theme_name, MAX_THEME_NAME_LENGTH);
  2160.             error_code = FS_GetAttributes(theme_path);
  2161.             if ((error_code > 0) || (error_code == FS_ACCESS_DENIED))
  2162.             {
  2163.                 nvm_card_thm_cnt++;
  2164.             }
  2165.         }
  2166.     }
  2167.     /* Insert new Phone themes in NVRAM list */
  2168.     sprintf(tmp_str, "%c%s%s", MMI_PUBLIC_DRV, DOWNLOADED_THEMES_PATH, THEME_SEARCH_STR);
  2169.     AnsiiToUnicodeString((PS8) theme_search_path, tmp_str);
  2170.     if (storage_type == THEME_TYPE_DOWNLOADED_PHONE && k < (MAX_DOWNLOADED_THEMES - nvm_card_thm_cnt))
  2171.     {
  2172.         memset((void*)&tmp_theme_list_p[k], 0, sizeof(tm_theme_list_struct));
  2173.         pfnUnicodeStrncpy((PS8) tmp_theme_list_p[k].theme_name, (PS8) filename, MAX_THEME_NAME_LENGTH);
  2174.         tmp_theme_list_p[k].theme_checksum_verified = CHECKSUM_NOT_VERIFIED;
  2175.         tmp_theme_list_p[k].theme_id = ++max_theme_id;
  2176.         tmp_theme_list_p[k].theme_type = THEME_TYPE_DOWNLOADED_PHONE;
  2177.         ++k;
  2178.     }
  2179.     /* Get all themes from NVRAM list, which are actually present on card, in a new theme list */
  2180.     for (j = g_tm_cntx.sys_thm_cnt; j < TOTAL_THEMES_COUNT; ++j)
  2181.     {
  2182.         if ((g_tm_theme_list[j].theme_type == THEME_TYPE_DOWNLOADED_CARD))
  2183.         {
  2184.             pfnUnicodeStrncpy((PS8) theme_path, (PS8) theme_path_card, MAX_DWNL_THM_PATH_LEN);
  2185.             pfnUnicodeStrncat((PS8) theme_path, (PS8) g_tm_theme_list[j].theme_name, MAX_THEME_NAME_LENGTH);
  2186.             error_code = FS_GetAttributes(theme_path);
  2187.             if ((error_code > 0) || (error_code == FS_ACCESS_DENIED))
  2188.             {
  2189.                 memcpy((void*)(tmp_theme_list_p + k), (void*)&g_tm_theme_list[j], sizeof(tm_theme_list_struct));
  2190.                 ++k;
  2191.             }
  2192.         }
  2193.     }
  2194.     /* Insert new Card themes in NVRAM list */
  2195.     sprintf(tmp_str, "%c%s%s", MMI_CARD_DRV, DOWNLOADED_THEMES_PATH, THEME_SEARCH_STR);
  2196.     AnsiiToUnicodeString((PS8) theme_search_path, tmp_str);
  2197.     if (storage_type == THEME_TYPE_DOWNLOADED_CARD && k < MAX_DOWNLOADED_THEMES)
  2198.     {
  2199.         memset((void*)&tmp_theme_list_p[k], 0, sizeof(tm_theme_list_struct));
  2200.         pfnUnicodeStrncpy((PS8) tmp_theme_list_p[k].theme_name, (PS8) filename, MAX_THEME_NAME_LENGTH);
  2201.         tmp_theme_list_p[k].theme_checksum_verified = CHECKSUM_NOT_VERIFIED;
  2202.         tmp_theme_list_p[k].theme_id = ++max_theme_id;
  2203.         tmp_theme_list_p[k].theme_type = THEME_TYPE_DOWNLOADED_CARD;
  2204.         ++k;
  2205.     }
  2206.     g_tm_cntx.total_thm_cnt = g_tm_cntx.sys_thm_cnt + k;
  2207.     memset((void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt), 0, sizeof(tm_theme_list_struct) * MAX_DOWNLOADED_THEMES);
  2208.     memcpy((void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt), tmp_theme_list_p, sizeof(tm_theme_list_struct) * k);
  2209.     /* Write Themes back to NVRAM */
  2210.     WriteRecord(
  2211.         NVRAM_EF_THEME_MANAGER_LID,
  2212.         1,
  2213.         (void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt),
  2214.         NVRAM_EF_THEME_MANAGER_RECORD_SIZE,
  2215.         &err);
  2216.     /* err = 4 => NVRAM_WRITE_SUCCESS */
  2217.     WriteValue(THEME_MANAGER_MAX_THEME_ID, (void*)&max_theme_id, DS_DOUBLE, &err);
  2218.     *theme_list_p = g_tm_theme_list;
  2219.     return g_tm_cntx.total_thm_cnt;
  2220. }
  2221. /*****************************************************************************
  2222.  * FUNCTION
  2223.  *  mmi_tm_checkfile_exists
  2224.  * DESCRIPTION
  2225.  *  
  2226.  * PARAMETERS
  2227.  *  filename        [IN]        
  2228.  * RETURNS
  2229.  *  
  2230.  *****************************************************************************/
  2231. MMI_BOOL mmi_tm_checkfile_exists(PS16 filename)
  2232. {
  2233.     /*----------------------------------------------------------------*/
  2234.     /* Local Variables                                                */
  2235.     /*----------------------------------------------------------------*/
  2236.     FS_HANDLE fh;
  2237.     /*----------------------------------------------------------------*/
  2238.     /* Code Body                                                      */
  2239.     /*----------------------------------------------------------------*/
  2240.     fh = FS_Open((WCHAR*) filename, FS_READ_ONLY);
  2241.     if (fh > 0)
  2242.     {
  2243.         FS_Close(fh);
  2244.         return MMI_TRUE;
  2245.     }
  2246.     else
  2247.     {
  2248.         FS_Close(fh);
  2249.         return MMI_FALSE;
  2250.     }
  2251. }
  2252. /*****************************************************************************
  2253.  * FUNCTION
  2254.  *  mmi_tm_get_themes
  2255.  * DESCRIPTION
  2256.  *  1. Purge the theme list of any non-existant themes
  2257.  *  2. Add any new themes if available.
  2258.  * PARAMETERS
  2259.  *  theme_list_p        [IN]        
  2260.  * RETURNS
  2261.  *  total number of themes
  2262.  *****************************************************************************/
  2263. U8 mmi_tm_get_themes(tm_theme_list_struct **theme_list_p)
  2264. {
  2265.     /*----------------------------------------------------------------*/
  2266.     /* Local Variables                                                */
  2267.     /*----------------------------------------------------------------*/
  2268.     S32 dwnl_ph_thm_cnt = 0;
  2269.     S32 dwnl_card_thm_cnt = 0;
  2270.     S32 nvm_card_thm_cnt = 0;
  2271.     tm_theme_list_struct *tmp_theme_list_p;
  2272.     U8 j, k;
  2273.     S16 err;
  2274.     U32 max_theme_id;
  2275.     U64 buff;
  2276.     U8 *temp_name;
  2277.     U8 nSystemThemeCount;
  2278.     S16 error_code;
  2279.     S8 tmp_str[MAX_DWNL_THM_PATH_LEN + MAX_THEME_SEARCH_STR_LEN];
  2280.     U16 theme_path[MAX_DWNL_THM_PATH_LEN + MAX_THEME_SEARCH_STR_LEN + MAX_THEME_NAME_LENGTH + 1];
  2281.     U16 theme_path_phone[MAX_DWNL_THM_PATH_LEN];    /* Plus 2 for MMI_PUBLIC_DRV: check */
  2282.     U16 theme_path_card[MAX_DWNL_THM_PATH_LEN];     /* Plus 2 for MMI_CARD_DRV: check */
  2283.     U16 theme_search_path[MAX_DWNL_THM_PATH_LEN + MAX_THEME_SEARCH_STR_LEN];
  2284.     U8 theme_type_bitmap[MAX_DOWNLOADED_THEMES] = {0};
  2285.     FS_HANDLE fh_cur;
  2286.     FS_DOSDirEntry file_info;
  2287.     U16 filename[MAX_THEME_NAME_LENGTH + 1];
  2288.     U16 len = 0;
  2289.     MMI_BOOL invalid_name = MMI_FALSE;
  2290.     /*----------------------------------------------------------------*/
  2291.     /* Code Body                                                      */
  2292.     /*----------------------------------------------------------------*/
  2293.     nSystemThemeCount = (U8) GetThemesNames((U8 ***) & temp_name);
  2294.     if (nSystemThemeCount > MAX_SYSTEM_THEMES)
  2295.     {
  2296.         nSystemThemeCount = MAX_SYSTEM_THEMES;
  2297.     }
  2298.     memset((void*)g_tm_theme_list, 0, sizeof(tm_theme_list_struct) * TOTAL_THEMES_COUNT);
  2299.     g_tm_cntx.total_thm_cnt = 0;
  2300.     g_tm_cntx.sys_thm_cnt = 0;
  2301.     for (j = 0; j < nSystemThemeCount; ++j)
  2302.     {
  2303.         pfnUnicodeStrncpy(
  2304.             (PS8) g_tm_theme_list[j].theme_name,
  2305.             GetString((U16) (STR_THEME_DEFAULT + j)),
  2306.             MAX_THEME_NAME_LENGTH);
  2307.         g_tm_theme_list[j].theme_checksum_verified = CHECKSUM_VERIFIED_OK;
  2308.         g_tm_theme_list[j].theme_id = j + 1;
  2309.         g_tm_theme_list[j].theme_type = THEME_TYPE_SYSTEM;
  2310.     }
  2311.     g_tm_cntx.total_thm_cnt = g_tm_cntx.sys_thm_cnt = nSystemThemeCount;
  2312.     /* Read Themes from NVRAM */
  2313.     ReadRecord(
  2314.         NVRAM_EF_THEME_MANAGER_LID,
  2315.         1,
  2316.         (void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt),
  2317.         NVRAM_EF_THEME_MANAGER_RECORD_SIZE,
  2318.         &err);
  2319.     /* err = 1 => NVRAM_READ_SUCCESS */
  2320.     if (err != NVRAM_READ_SUCCESS)
  2321.     {
  2322.         *theme_list_p = g_tm_theme_list;
  2323.         return g_tm_cntx.total_thm_cnt;
  2324.     }
  2325.     /* Sukrit: A better way to do it will be through something like does file exists on phone folder */
  2326.     sprintf(tmp_str, "%c%s", MMI_PUBLIC_DRV, DOWNLOADED_THEMES_PATH);
  2327.     AnsiiToUnicodeString((PS8) theme_path_phone, tmp_str);
  2328.     dwnl_ph_thm_cnt = FS_Count(theme_path_phone, FS_FILE_TYPE, NULL, 0);
  2329.     sprintf(tmp_str, "%c%s", MMI_CARD_DRV, DOWNLOADED_THEMES_PATH);
  2330.     AnsiiToUnicodeString((PS8) theme_path_card, tmp_str);
  2331.     dwnl_card_thm_cnt = FS_Count(theme_path_card, FS_FILE_TYPE, NULL, 0);
  2332.     ReadValue(THEME_MANAGER_MAX_THEME_ID, (void*)&buff, DS_DOUBLE, &err);
  2333.     max_theme_id = (U32) buff;
  2334.     if (max_theme_id == 0xFFFFFFFF || err == -1)
  2335.     {
  2336.         max_theme_id = 10;
  2337.         WriteValue(THEME_MANAGER_MAX_THEME_ID, (void*)&max_theme_id, DS_DOUBLE, &err);
  2338.     }
  2339.     tmp_theme_list_p = (tm_theme_list_struct*) & g_tm_NvramThmArr;
  2340.     /* Get all themes from NVRAM list, which are actually present on Phone, in a new theme list */
  2341.     /* Also, Count number of themes on phone and card that are actually on NVRAM */
  2342.     for (j = g_tm_cntx.sys_thm_cnt, k = 0; j < TOTAL_THEMES_COUNT; ++j)
  2343.     {
  2344.         if ((g_tm_theme_list[j].theme_type == THEME_TYPE_DOWNLOADED_PHONE))
  2345.         {
  2346.             pfnUnicodeStrncpy((PS8) theme_path, (PS8) theme_path_phone, MAX_DWNL_THM_PATH_LEN);
  2347.             pfnUnicodeStrncat((PS8) theme_path, (PS8) g_tm_theme_list[j].theme_name, MAX_THEME_NAME_LENGTH);
  2348.             error_code = FS_GetAttributes(theme_path);
  2349.             if ((error_code > 0) || (error_code == FS_ACCESS_DENIED))
  2350.             {
  2351.                 memcpy((void*)(tmp_theme_list_p + k), (void*)&g_tm_theme_list[j], sizeof(tm_theme_list_struct));
  2352.                 theme_type_bitmap[k] = THEME_TYPE_DOWNLOADED_PHONE;
  2353.                 ++k;
  2354.                 dwnl_ph_thm_cnt--;
  2355.             }
  2356.         }
  2357.         else if (g_tm_theme_list[j].theme_type == THEME_TYPE_DOWNLOADED_CARD)
  2358.         {
  2359.             pfnUnicodeStrncpy((PS8) theme_path, (PS8) theme_path_card, MAX_DWNL_THM_PATH_LEN);
  2360.             pfnUnicodeStrncat((PS8) theme_path, (PS8) g_tm_theme_list[j].theme_name, MAX_THEME_NAME_LENGTH);
  2361.             error_code = FS_GetAttributes(theme_path);
  2362.             if ((error_code > 0) || (error_code == FS_ACCESS_DENIED))
  2363.             {
  2364.                 nvm_card_thm_cnt++;
  2365.                 dwnl_card_thm_cnt--;
  2366.             }
  2367.         }
  2368.     }
  2369.     /* Insert new Phone themes in NVRAM list */
  2370.     sprintf(tmp_str, "%c%s%s", MMI_PUBLIC_DRV, DOWNLOADED_THEMES_PATH, THEME_SEARCH_STR);
  2371.     AnsiiToUnicodeString((PS8) theme_search_path, tmp_str);
  2372.     if (dwnl_ph_thm_cnt > 0 && k < (MAX_DOWNLOADED_THEMES - nvm_card_thm_cnt))
  2373.     {
  2374.         if ((fh_cur = FS_FindFirst(
  2375.                         (U16*) theme_search_path,
  2376.                         0,
  2377.                         0,
  2378.                         &file_info,
  2379.                         (U16*) filename,
  2380.                         MAX_THEME_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  2381.         {
  2382.             do
  2383.             {
  2384.                 MMI_BOOL theme_already_on_nvram_list = MMI_FALSE;
  2385.                 /* Check if theme already in the list */
  2386.                 for (j = g_tm_cntx.sys_thm_cnt; j < TOTAL_THEMES_COUNT; ++j)
  2387.                 {
  2388.                     if (theme_type_bitmap[j - g_tm_cntx.sys_thm_cnt] == THEME_TYPE_DOWNLOADED_PHONE &&
  2389.                         pfnUnicodeStrcmp(
  2390.                             (PS8) tmp_theme_list_p[j - g_tm_cntx.sys_thm_cnt].theme_name,
  2391.                             (PS8) filename) == 0)
  2392.                     {
  2393.                         theme_already_on_nvram_list = MMI_TRUE;
  2394.                         theme_type_bitmap[j - g_tm_cntx.sys_thm_cnt] = 0xFF;
  2395.                         break;
  2396.                     }
  2397.                 }
  2398.                 if (theme_already_on_nvram_list == MMI_FALSE)
  2399.                 {
  2400.                     len = 0;
  2401.                     invalid_name = MMI_FALSE;
  2402.                     /*
  2403.                      * If we have memory for display we can use this function.
  2404.                      * if (file_info.NTReserved == FS_LFN_MATCH)// File system returned a short file name
  2405.                      * {
  2406.                      * mmi_chset_mixed_text_to_ucs2_str(
  2407.                      * (U8*) g_tm_theme_display_names[k],
  2408.                      * MAX_THEME_NAME_LENGTH * ENCODING_LENGTH,
  2409.                      * (U8*) filename,
  2410.                      * PhnsetGetDefEncodingType());
  2411.                      * pfnUnicodeStrncpy((PS8)tmp_theme_list_p[k].theme_name, (PS8) filename,MAX_THEME_NAME_LENGTH);
  2412.                      * tmp_theme_list_p[k].theme_name_encoding = 1;
  2413.                      * continue;//long file names are not visible to application
  2414.                      * 
  2415.                      * }
  2416.                      * else
  2417.                      * {
  2418.                      * tmp_theme_list_p[k].theme_name_encoding = 0;
  2419.                      * pfnUnicodeStrncpy((PS8)tmp_theme_list_p[k].theme_name, (PS8) filename,MAX_THEME_NAME_LENGTH);
  2420.                      * }
  2421.                      */
  2422.                     len = pfnUnicodeStrlen((S8*) filename);
  2423.                     for (j = 0; j < len; ++j)
  2424.                     {
  2425.                         if (filename[j] == 0x7E)    /* tilde */
  2426.                         {
  2427.                             invalid_name = MMI_TRUE;
  2428.                             dwnl_ph_thm_cnt--;
  2429.                             break;
  2430.                         }
  2431.                     }
  2432.                     if (invalid_name == MMI_FALSE)
  2433.                     {
  2434.                         memset((void*)&tmp_theme_list_p[k], 0, sizeof(tm_theme_list_struct));
  2435.                         pfnUnicodeStrncpy((PS8) tmp_theme_list_p[k].theme_name, (PS8) filename, MAX_THEME_NAME_LENGTH);
  2436.                         tmp_theme_list_p[k].theme_checksum_verified = CHECKSUM_NOT_VERIFIED;
  2437.                         tmp_theme_list_p[k].theme_id = ++max_theme_id;
  2438.                         tmp_theme_list_p[k].theme_type = THEME_TYPE_DOWNLOADED_PHONE;
  2439.                         ++k;
  2440.                         dwnl_ph_thm_cnt--;
  2441.                     }
  2442.                 }
  2443.             } while (k < (MAX_DOWNLOADED_THEMES - nvm_card_thm_cnt) &&
  2444.                      (FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_THEME_NAME_LENGTH * ENCODING_LENGTH) ==
  2445.                       FS_NO_ERROR));
  2446.             FS_FindClose(fh_cur);
  2447.         }
  2448.     }
  2449.     /* Get all themes from NVRAM list, which are actually present on card, in a new theme list */
  2450.     for (j = g_tm_cntx.sys_thm_cnt; j < TOTAL_THEMES_COUNT; ++j)
  2451.     {
  2452.         if ((g_tm_theme_list[j].theme_type == THEME_TYPE_DOWNLOADED_CARD))
  2453.         {
  2454.             pfnUnicodeStrncpy((PS8) theme_path, (PS8) theme_path_card, MAX_DWNL_THM_PATH_LEN);
  2455.             pfnUnicodeStrncat((PS8) theme_path, (PS8) g_tm_theme_list[j].theme_name, MAX_THEME_NAME_LENGTH);
  2456.             error_code = FS_GetAttributes(theme_path);
  2457.             if ((error_code > 0) || (error_code == FS_ACCESS_DENIED))
  2458.             {
  2459.                 memcpy((void*)(tmp_theme_list_p + k), (void*)&g_tm_theme_list[j], sizeof(tm_theme_list_struct));
  2460.                 theme_type_bitmap[k] = THEME_TYPE_DOWNLOADED_CARD;
  2461.                 ++k;
  2462.             }
  2463.         }
  2464.     }
  2465.     /* Insert new Card themes in NVRAM list */
  2466.     sprintf(tmp_str, "%c%s%s", MMI_CARD_DRV, DOWNLOADED_THEMES_PATH, THEME_SEARCH_STR);
  2467.     AnsiiToUnicodeString((PS8) theme_search_path, tmp_str);
  2468.     if (dwnl_card_thm_cnt > 0 && k < MAX_DOWNLOADED_THEMES)
  2469.     {
  2470.         if ((fh_cur = FS_FindFirst(
  2471.                         (U16*) theme_search_path,
  2472.                         0,
  2473.                         0,
  2474.                         &file_info,
  2475.                         (U16*) filename,
  2476.                         MAX_THEME_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  2477.         {
  2478.             do
  2479.             {
  2480.                 MMI_BOOL theme_already_on_nvram_list = MMI_FALSE;
  2481.                 /* Check if theme already in the list */
  2482.                 for (j = g_tm_cntx.sys_thm_cnt; j < TOTAL_THEMES_COUNT; ++j)
  2483.                 {
  2484.                     if (theme_type_bitmap[j - g_tm_cntx.sys_thm_cnt] == THEME_TYPE_DOWNLOADED_CARD &&
  2485.                         pfnUnicodeStrcmp(
  2486.                             (PS8) tmp_theme_list_p[j - g_tm_cntx.sys_thm_cnt].theme_name,
  2487.                             (PS8) filename) == 0)
  2488.                     {
  2489.                         theme_already_on_nvram_list = MMI_TRUE;
  2490.                         theme_type_bitmap[j - g_tm_cntx.sys_thm_cnt] = 0xFF;
  2491.                         break;
  2492.                     }
  2493.                 }
  2494.                 if (theme_already_on_nvram_list == MMI_FALSE)
  2495.                 {
  2496.                     len = 0;
  2497.                     invalid_name = MMI_FALSE;
  2498.                     /*
  2499.                      * If we have memory for display we can use this function.
  2500.                      * if (file_info.NTReserved == FS_LFN_MATCH)// File system returned a short file name 
  2501.                      * {
  2502.                      * mmi_chset_mixed_text_to_ucs2_str(
  2503.                      * (U8*) tmp_theme_list_p[k].theme_name,
  2504.                      * MAX_THEME_NAME_LENGTH * ENCODING_LENGTH,
  2505.                      * (U8*) filename,
  2506.                      * PhnsetGetDefEncodingType());
  2507.                      * tmp_theme_list_p[k].theme_name_encoding = 1;
  2508.                      * continue;//long file names are not visible to application
  2509.                      * }
  2510.                      * else
  2511.                      * {
  2512.                      * tmp_theme_list_p[k].theme_name_encoding = 0;
  2513.                      * pfnUnicodeStrncpy((PS8)tmp_theme_list_p[k].theme_name, (PS8) filename,MAX_THEME_NAME_LENGTH);
  2514.                      * }
  2515.                      */
  2516.                     len = pfnUnicodeStrlen((S8*) filename);
  2517.                     for (j = 0; j < len; ++j)
  2518.                     {
  2519.                         if (filename[j] == 0x7E)    /* tilde */
  2520.                         {
  2521.                             invalid_name = MMI_TRUE;
  2522.                             dwnl_card_thm_cnt--;
  2523.                             break;
  2524.                         }
  2525.                     }
  2526.                     if (invalid_name == MMI_FALSE)
  2527.                     {
  2528.                         memset((void*)&tmp_theme_list_p[k], 0, sizeof(tm_theme_list_struct));
  2529.                         pfnUnicodeStrncpy((PS8) tmp_theme_list_p[k].theme_name, (PS8) filename, MAX_THEME_NAME_LENGTH);
  2530.                         tmp_theme_list_p[k].theme_checksum_verified = CHECKSUM_NOT_VERIFIED;
  2531.                         tmp_theme_list_p[k].theme_id = ++max_theme_id;
  2532.                         tmp_theme_list_p[k].theme_type = THEME_TYPE_DOWNLOADED_CARD;
  2533.                         dwnl_card_thm_cnt--;
  2534.                         ++k;
  2535.                     }
  2536.                 }
  2537.             } while (k < MAX_DOWNLOADED_THEMES &&
  2538.                      (FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_THEME_NAME_LENGTH * ENCODING_LENGTH) ==
  2539.                       FS_NO_ERROR));
  2540.             FS_FindClose(fh_cur);
  2541.         }
  2542.     }
  2543.     g_tm_cntx.total_thm_cnt = g_tm_cntx.sys_thm_cnt + k;
  2544.     memset((void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt), 0, sizeof(tm_theme_list_struct) * MAX_DOWNLOADED_THEMES);
  2545.     memcpy((void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt), tmp_theme_list_p, sizeof(tm_theme_list_struct) * k);
  2546.     /* Write Themes back to NVRAM */
  2547.     WriteRecord(
  2548.         NVRAM_EF_THEME_MANAGER_LID,
  2549.         1,
  2550.         (void*)(g_tm_theme_list + g_tm_cntx.sys_thm_cnt),
  2551.         NVRAM_EF_THEME_MANAGER_RECORD_SIZE,
  2552.         &err);
  2553.     /* err = 4 => NVRAM_WRITE_SUCCESS */
  2554.     WriteValue(THEME_MANAGER_MAX_THEME_ID, (void*)&max_theme_id, DS_DOUBLE, &err);
  2555.     *theme_list_p = g_tm_theme_list;
  2556.     return g_tm_cntx.total_thm_cnt;
  2557. }
  2558. /*****************************************************************************
  2559.  * FUNCTION
  2560.  *  mmi_tm_activate_theme_at_bootup
  2561.  * DESCRIPTION
  2562.  *  This function activates theme at bootup time
  2563.  * PARAMETERS
  2564.  *  void
  2565.  * RETURNS
  2566.  *  void
  2567.  *****************************************************************************/
  2568. void mmi_tm_activate_theme_at_bootup(void)
  2569. {
  2570.     /*----------------------------------------------------------------*/
  2571.     /* Local Variables                                                */
  2572.     /*----------------------------------------------------------------*/
  2573.     U8 i = 0, found = 0, result;
  2574.     U32 curr_theme_id;
  2575. U32 usb_id;  
  2576. S16 err;
  2577. U64 buff;   
  2578.     /*----------------------------------------------------------------*/
  2579.     /* Code Body                                                      */
  2580.     /*----------------------------------------------------------------*/
  2581.     ReadValue(NVRAM_USB_PREVIOUS_THEME_INDEX, (void*)&buff, DS_DOUBLE, &err);
  2582. usb_id = (U32) buff;
  2583. if (usb_id != -1)
  2584. {
  2585. WriteValue(THEME_MANAGER_CURR_THEME_ID, (void*)&usb_id, DS_DOUBLE, &err);
  2586. usb_id = -1;
  2587. WriteValue(NVRAM_USB_PREVIOUS_THEME_INDEX, (void*)&usb_id, DS_DOUBLE, &err);
  2588. }
  2589.     curr_theme_id = mmi_tm_get_current_theme_id();
  2590.     for (i = 0; i < g_tm_cntx.total_thm_cnt; ++i)
  2591.     {
  2592.         if (curr_theme_id == g_tm_theme_list[i].theme_id)
  2593.         {
  2594.             found = 1;
  2595.             break;
  2596.         }
  2597.     }
  2598.     if (found)
  2599.     {
  2600.         if (g_tm_theme_list[i].theme_type == THEME_TYPE_SYSTEM)
  2601.         {
  2602.             result = mmi_tm_activate_system_theme(&g_tm_theme_list[i]);
  2603.         }
  2604.     #ifdef __MMI_DOWNLOADABLE_THEMES_SUPPORT__      /* ritesh */
  2605.         else
  2606.         {
  2607.             result = mmi_tm_activate_downloaded_theme(&g_tm_theme_list[i]);
  2608.         }
  2609.     #endif /* __MMI_DOWNLOADABLE_THEMES_SUPPORT__ */ 
  2610.         if (result != THEME_ERROR_SUCCESS)
  2611.         {
  2612.             mmi_tm_activate_system_theme(&g_tm_theme_list[0]);
  2613.             if (PhnsetIsWPCurrentTheme())
  2614.             {
  2615.                 ThemeManagerSetWallpaper(IMG_ID_PHNSET_WP_0);
  2616.             }
  2617.             if (PhnsetIsScrSvrCurrentTheme())
  2618.             {
  2619.                 ThemeManagerSetScreensaver(IMG_ID_PHNSET_SS_0);
  2620.             }
  2621.         #ifdef __MMI_DOWNLOADABLE_THEMES_SUPPORT__      /* ritesh */
  2622.             ThemeManagerResetRingTone();
  2623.             ThemeManagerResetAlarmTone();
  2624.         #endif /* __MMI_DOWNLOADABLE_THEMES_SUPPORT__ */ /* ritesh */
  2625.         }
  2626.         else
  2627.         {
  2628.             if (g_tm_cntx.theme_has_wallpaper)
  2629.             {
  2630.                 if ( PhnsetIsWPCurrentTheme() ) 
  2631.                 {
  2632.                     ThemeManagerSetWallpaper(IMG_ID_DISPCHAR_THEME_WALLPAPER);
  2633.                 }
  2634.             }
  2635.             else
  2636.             {
  2637.                 if (PhnsetIsWPCurrentTheme())
  2638.                 {
  2639.                     ThemeManagerSetWallpaper(IMG_ID_PHNSET_WP_0);
  2640.                 }
  2641.             }
  2642.             if (g_tm_cntx.theme_has_screensaver)
  2643.             {
  2644.                 if (PhnsetIsScrSvrCurrentTheme())
  2645.                 {
  2646.                     ThemeManagerSetScreensaver(IMG_ID_DISPCHAR_THEME_SCREENSAVER);
  2647.                 }
  2648.             }
  2649.             else
  2650.             {
  2651.                 if (PhnsetIsScrSvrCurrentTheme())
  2652.                 {
  2653.                     ThemeManagerSetScreensaver(IMG_ID_PHNSET_SS_START);
  2654.                 }
  2655.             }
  2656.         }
  2657.     }
  2658.     else
  2659.     {
  2660.         mmi_tm_activate_system_theme(&g_tm_theme_list[0]);
  2661.         if (PhnsetIsWPCurrentTheme())
  2662.         {
  2663.             ThemeManagerSetWallpaper(IMG_ID_PHNSET_WP_0);
  2664.         }
  2665.         if (PhnsetIsScrSvrCurrentTheme())
  2666.         {
  2667.             ThemeManagerSetScreensaver(IMG_ID_PHNSET_SS_0);
  2668.         }
  2669.     #ifdef __MMI_DOWNLOADABLE_THEMES_SUPPORT__      /* ritesh */
  2670.         ThemeManagerResetRingTone();
  2671.         ThemeManagerResetAlarmTone();
  2672.     #endif /* __MMI_DOWNLOADABLE_THEMES_SUPPORT__ */ /* ritesh */
  2673.     }
  2674.     if (mmi_tm_does_theme_have_alt_image())
  2675.     {
  2676.         initialize_status_icons();
  2677.     }
  2678. }
  2679. /*****************************************************************************
  2680.  * FUNCTION
  2681.  *  mmi_tm_activate_theme
  2682.  * DESCRIPTION
  2683.  *  This function activates theme at the time of theme selection
  2684.  * PARAMETERS
  2685.  *  theme_id        [IN]        
  2686.  * RETURNS
  2687.  *  theme error code
  2688.  *****************************************************************************/
  2689. tm_theme_error_enum mmi_tm_activate_theme(THEME_ID theme_id)
  2690. {
  2691.     /*----------------------------------------------------------------*/
  2692.     /* Local Variables                                                */
  2693.     /*----------------------------------------------------------------*/
  2694.     U8 i;
  2695.     tm_theme_error_enum result;
  2696.     /*----------------------------------------------------------------*/
  2697.     /* Code Body                                                      */
  2698.     /*----------------------------------------------------------------*/
  2699.     /* ShowCategory66Screen(STR_SCR3001_THEMES_CAPTION,0, 0, 0, STR_GLOBAL_BACK, IMG_GLOBAL_BACK, (PU8)GetString(STR_ID_DLT_THM_PROGRESS), IMG_THEME_ACTIVATION, NULL); */
  2700.     if (g_tm_cntx.curr_activated_theme_id == theme_id)
  2701.     {
  2702.         return THEME_ERROR_ALREADY_ACTIVATED;
  2703.     }
  2704.     for (i = 0; i < g_tm_cntx.total_thm_cnt; ++i)
  2705.     {
  2706.         if (theme_id == g_tm_theme_list[i].theme_id)
  2707.         {
  2708.             break;
  2709.         }
  2710.     }
  2711.     if (g_tm_theme_list[i].theme_type == THEME_TYPE_SYSTEM)
  2712.     {
  2713.         result = mmi_tm_activate_system_theme(&g_tm_theme_list[i]);
  2714.     }
  2715. #ifdef __MMI_DOWNLOADABLE_THEMES_SUPPORT__      /* ritesh */
  2716.     else
  2717.     {
  2718.         result = mmi_tm_activate_downloaded_theme(&g_tm_theme_list[i]);
  2719.     }
  2720. #endif /* __MMI_DOWNLOADABLE_THEMES_SUPPORT__ */ /* ritesh */
  2721.     if (result == THEME_ERROR_SUCCESS)
  2722.     {
  2723.         if (g_tm_cntx.theme_has_wallpaper)
  2724.         {
  2725.             ThemeManagerSetWallpaper(IMG_ID_DISPCHAR_THEME_WALLPAPER);
  2726.         }
  2727.         else
  2728.         {
  2729.             if (PhnsetIsWPCurrentTheme())
  2730.             {
  2731.                 ThemeManagerSetWallpaper(IMG_ID_PHNSET_WP_START);
  2732.             }
  2733.         }
  2734.         if (g_tm_cntx.theme_has_screensaver)
  2735.         {
  2736.             ThemeManagerSetScreensaver(IMG_ID_DISPCHAR_THEME_SCREENSAVER);
  2737.         }
  2738.         else
  2739.         {
  2740.             if (PhnsetIsScrSvrCurrentTheme())
  2741.             {
  2742.                 ThemeManagerSetScreensaver(IMG_ID_PHNSET_SS_START);
  2743.             }
  2744.         }
  2745.     #ifdef __MMI_DOWNLOADABLE_THEMES_SUPPORT__      /* ritesh */
  2746.         if (g_tm_cntx.theme_has_ringtone)
  2747.         {
  2748.             ThemeManagerSetRingTone(CURRENT_THEME_INCOMING_CALL_TONE);
  2749.             ThemeManagerSetAlarmTone(CURRENT_THEME_ALARM_EXPIRY_TONE);
  2750.         }
  2751.         else
  2752.         {
  2753.             ThemeManagerResetRingTone();
  2754.             ThemeManagerResetAlarmTone();
  2755.         }
  2756.     #endif /* __MMI_DOWNLOADABLE_THEMES_SUPPORT__ */ /* ritesh */
  2757.         /* if(mmi_tm_does_theme_have_alt_image()) */
  2758.         initialize_status_icons();
  2759.     }
  2760.     return result;
  2761. }
  2762. /*****************************************************************************
  2763.  * FUNCTION
  2764.  *  mmi_tm_activate_system_theme
  2765.  * DESCRIPTION
  2766.  *  This function activates system theme
  2767.  * PARAMETERS
  2768.  *  theme_struct_p      [?]     [?]
  2769.  * RETURNS
  2770.  *  theme error code
  2771.  *****************************************************************************/
  2772. tm_theme_error_enum mmi_tm_activate_system_theme(tm_theme_list_struct *theme_struct_p)
  2773. {
  2774.     /*----------------------------------------------------------------*/
  2775.     /* Local Variables                                                */
  2776.     /*----------------------------------------------------------------*/
  2777.     S16 err;
  2778.     /*----------------------------------------------------------------*/
  2779.     /* Code Body                                                      */
  2780.     /*----------------------------------------------------------------*/
  2781.     /* todo: To copy from MCT */
  2782.     g_tm_cntx.curr_activated_theme_type = theme_struct_p->theme_type;
  2783.     g_tm_cntx.theme_has_alternate_image = FALSE;
  2784.     g_tm_activated_theme.system_image_list = NULL;
  2785.     g_tm_activated_theme.theme = NULL;
  2786.     g_tm_activated_theme.theme_image_details_list = NULL;
  2787.     g_tm_cntx.theme_has_wallpaper = FALSE;
  2788.     g_tm_cntx.theme_has_screensaver = FALSE;
  2789.     g_tm_cntx.theme_has_ringtone = FALSE;
  2790.     set_MMI_theme((MMI_theme*) MMI_themes[(theme_struct_p->theme_id - 1)].theme);
  2791.     MMI_apply_current_theme();
  2792.     DRM_close_file(g_tm_cntx.theme_file_handle);
  2793.     g_tm_cntx.theme_file_handle = 0;
  2794.     g_tm_cntx.curr_activated_theme_id = theme_struct_p->theme_id;
  2795.     g_tm_cntx.curr_activated_theme_type = theme_struct_p->theme_type;
  2796.     WriteValue(THEME_MANAGER_CURR_THEME_ID, (void*)&g_tm_cntx.curr_activated_theme_id, DS_DOUBLE, &err);
  2797.     return THEME_ERROR_SUCCESS;
  2798. }
  2799. /*****************************************************************************
  2800.  * FUNCTION
  2801.  *  mmi_tm_sort_theme_image_table
  2802.  * DESCRIPTION
  2803.  *  this function sort the table containg image id to offset mapping
  2804.  * PARAMETERS
  2805.  *  void
  2806.  * RETURNS
  2807.  *  void
  2808.  *****************************************************************************/
  2809. void mmi_tm_sort_theme_image_table(void)
  2810. {
  2811.     /*----------------------------------------------------------------*/
  2812.     /* Local Variables                                                */
  2813.     /*----------------------------------------------------------------*/
  2814.     /*----------------------------------------------------------------*/
  2815.     /* Code Body                                                      */
  2816.     /*----------------------------------------------------------------*/
  2817.     if (g_tm_cntx.theme_imageid_image_count)
  2818.     {
  2819.         mmi_tm_image_table_quick_sort(0, (U16) (g_tm_cntx.theme_imageid_image_count - 1));
  2820.         mmi_tm_image_table_insertion_sort(0, (U16) (g_tm_cntx.theme_imageid_image_count - 1));
  2821.     }
  2822. }
  2823. /*****************************************************************************
  2824.  * FUNCTION
  2825.  *  mmi_tm_image_table_quick_sort
  2826.  * DESCRIPTION
  2827.  *  It sorts the table using quick sort algorithm
  2828.  * PARAMETERS
  2829.  *  l       [IN]        
  2830.  *  r       [IN]        
  2831.  * RETURNS
  2832.  *  void
  2833.  *****************************************************************************/
  2834. void mmi_tm_image_table_quick_sort(U16 l, U16 r)
  2835. {
  2836.     /*----------------------------------------------------------------*/
  2837.     /* Local Variables                                                */
  2838.     /*----------------------------------------------------------------*/
  2839.     U16 i, j;
  2840.     U32 pivot;
  2841.     /*----------------------------------------------------------------*/
  2842.     /* Code Body                                                      */
  2843.     /*----------------------------------------------------------------*/
  2844.     if ((r - l) > 4)
  2845.     {
  2846.         i = (r + l) / 2;
  2847.         if (g_tm_activated_theme.theme_image_details_list[l].image_id >
  2848.             g_tm_activated_theme.theme_image_details_list[i].image_id)
  2849.         {
  2850.             mmi_tm_image_table_swap_node(l, i);
  2851.         }
  2852.         if (g_tm_activated_theme.theme_image_details_list[l].image_id >
  2853.             g_tm_activated_theme.theme_image_details_list[r].image_id)
  2854.         {
  2855.             mmi_tm_image_table_swap_node(l, r);
  2856.         }
  2857.         if (g_tm_activated_theme.theme_image_details_list[i].image_id >
  2858.             g_tm_activated_theme.theme_image_details_list[r].image_id)
  2859.         {
  2860.             mmi_tm_image_table_swap_node(i, r);
  2861.         }
  2862.         j = r - 1;
  2863.         mmi_tm_image_table_swap_node(i, j);
  2864.         i = l;
  2865.         pivot = g_tm_activated_theme.theme_image_details_list[j].image_id;
  2866.         for (;;)
  2867.         {
  2868.             do
  2869.             {
  2870.             } while (g_tm_activated_theme.theme_image_details_list[++i].image_id < pivot);
  2871.             do
  2872.             {
  2873.             } while (g_tm_activated_theme.theme_image_details_list[--j].image_id > pivot);
  2874.             if (j < i)
  2875.             {
  2876.                 break;
  2877.             }
  2878.             mmi_tm_image_table_swap_node(i, j);
  2879.         }
  2880.         mmi_tm_image_table_swap_node(i, (U16) (r - 1));
  2881.         mmi_tm_image_table_quick_sort(l, j);
  2882.         mmi_tm_image_table_quick_sort((U16) (i + 1), r);
  2883.     }
  2884. }
  2885. /*****************************************************************************
  2886.  * FUNCTION
  2887.  *  mmi_tm_image_table_insertion_sort
  2888.  * DESCRIPTION
  2889.  *  It sorts the table using insertion sort algorithm
  2890.  * PARAMETERS
  2891.  *  lo      [IN]        
  2892.  *  hi      [IN]        
  2893.  * RETURNS
  2894.  *  void
  2895.  *****************************************************************************/
  2896. void mmi_tm_image_table_insertion_sort(U16 lo, U16 hi)
  2897. {
  2898.     /*----------------------------------------------------------------*/
  2899.     /* Local Variables                                                */
  2900.     /*----------------------------------------------------------------*/
  2901.     U16 i, j;
  2902.     theme_image_detail_struct elem;
  2903.     /*----------------------------------------------------------------*/
  2904.     /* Code Body                                                      */
  2905.     /*----------------------------------------------------------------*/
  2906.     for (i = lo + 1; i <= hi; ++i)
  2907.     {
  2908.         memcpy(&elem, &g_tm_activated_theme.theme_image_details_list[i], sizeof(theme_image_detail_struct));
  2909.         j = i;
  2910.         while (j > lo)
  2911.         {
  2912.             if (g_tm_activated_theme.theme_image_details_list[j - 1].image_id <= elem.image_id)
  2913.             {
  2914.                 break;
  2915.             }
  2916.             memcpy(
  2917.                 &g_tm_activated_theme.theme_image_details_list[j],
  2918.                 &g_tm_activated_theme.theme_image_details_list[j - 1],
  2919.                 sizeof(theme_image_detail_struct));
  2920.             j--;
  2921.         }
  2922.         memcpy(&g_tm_activated_theme.theme_image_details_list[j], &elem, sizeof(theme_image_detail_struct));
  2923.     }
  2924. }
  2925. /*****************************************************************************
  2926.  * FUNCTION
  2927.  *  mmi_tm_image_table_swap_node
  2928.  * DESCRIPTION
  2929.  *  It swaps the theme images
  2930.  * PARAMETERS
  2931.  *  i       [IN]        
  2932.  *  j       [IN]        
  2933.  * RETURNS
  2934.  *  void
  2935.  *****************************************************************************/
  2936. void mmi_tm_image_table_swap_node(U16 i, U16 j)
  2937. {
  2938.     /*----------------------------------------------------------------*/
  2939.     /* Local Variables                                                */
  2940.     /*----------------------------------------------------------------*/
  2941.     theme_image_detail_struct temp;
  2942.     /*----------------------------------------------------------------*/
  2943.     /* Code Body                                                      */
  2944.     /*----------------------------------------------------------------*/
  2945.     memcpy(&temp, &g_tm_activated_theme.theme_image_details_list[i], sizeof(theme_image_detail_struct));
  2946.     memcpy(
  2947.         &g_tm_activated_theme.theme_image_details_list[i],
  2948.         &g_tm_activated_theme.theme_image_details_list[j],
  2949.         sizeof(theme_image_detail_struct));
  2950.     memcpy(&g_tm_activated_theme.theme_image_details_list[j], &temp, sizeof(theme_image_detail_struct));
  2951. }
  2952. /*****************************************************************************
  2953.  * FUNCTION
  2954.  *  mmi_tm_get_current_theme_id
  2955.  * DESCRIPTION
  2956.  *  This function gets the current theme ID
  2957.  * PARAMETERS
  2958.  *  void
  2959.  * RETURNS
  2960.  *  numeric theme id value
  2961.  *****************************************************************************/
  2962. U32 mmi_tm_get_current_theme_id(void)
  2963. {
  2964.     /*----------------------------------------------------------------*/
  2965.     /* Local Variables                                                */
  2966.     /*----------------------------------------------------------------*/
  2967.     S16 err;
  2968.     U64 buff;
  2969.     /*----------------------------------------------------------------*/
  2970.     /* Code Body                                                      */
  2971.     /*----------------------------------------------------------------*/
  2972.     ReadValue(THEME_MANAGER_CURR_THEME_ID, (void*)&buff, DS_DOUBLE, &err);
  2973.     g_tm_cntx.curr_activated_theme_id = (U32) buff;
  2974.     if (g_tm_cntx.curr_activated_theme_id == 0xFFFFFFFF || err == -1)
  2975.     {
  2976.         g_tm_cntx.curr_activated_theme_id = 1;
  2977.         WriteValue(THEME_MANAGER_CURR_THEME_ID, (void*)&g_tm_cntx.curr_activated_theme_id, DS_DOUBLE, &err);
  2978.     }
  2979.     return g_tm_cntx.curr_activated_theme_id;
  2980. }
  2981. /*****************************************************************************
  2982.  * FUNCTION
  2983.  *  mmi_tm_does_theme_have_alt_image
  2984.  * DESCRIPTION
  2985.  *  This function checks whether downloadable theme has alternative image or not
  2986.  * PARAMETERS
  2987.  *  void
  2988.  * RETURNS
  2989.  *  true if alternate image present otherwise false
  2990.  *****************************************************************************/
  2991. U8 mmi_tm_does_theme_have_alt_image(void)
  2992. {
  2993.     /*----------------------------------------------------------------*/
  2994.     /* Local Variables                                                */
  2995.     /*----------------------------------------------------------------*/
  2996.     /*----------------------------------------------------------------*/
  2997.     /* Code Body                                                      */
  2998.     /*----------------------------------------------------------------*/
  2999.     return g_tm_cntx.theme_has_alternate_image;
  3000. }
  3001. /*****************************************************************************
  3002.  * FUNCTION
  3003.  *  mmi_tm_is_theme_dirty_bit_set
  3004.  * DESCRIPTION
  3005.  *  This function checks whether dirty bit is set for the image or not
  3006.  * PARAMETERS
  3007.  *  image_index     [IN]        
  3008.  * RETURNS
  3009.  *  true if dirty bit set otherwise false
  3010.  *****************************************************************************/
  3011. U8 mmi_tm_is_theme_dirty_bit_set(U16 image_index)
  3012. {
  3013.     /*----------------------------------------------------------------*/
  3014.     /* Local Variables                                                */
  3015.     /*----------------------------------------------------------------*/
  3016.     U16 n_byte;
  3017.     U16 n_bit;
  3018.     /*----------------------------------------------------------------*/
  3019.     /* Code Body                                                      */
  3020.     /*----------------------------------------------------------------*/
  3021.     n_byte = (image_index >> 3);
  3022.     n_bit = (image_index % 8);
  3023.     return (U8) ((g_tm_theme_image_dirty_bits[n_byte]) & (0x80 >> n_bit));
  3024. }
  3025. /*****************************************************************************
  3026.  * FUNCTION
  3027.  *  mmi_tm_get_theme_image_offset_or_index
  3028.  * DESCRIPTION
  3029.  *  This function gets the offset/index for the image
  3030.  * PARAMETERS
  3031.  *  image_id            [IN]        
  3032.  *  nArrayIndex_p       [?]         [?]
  3033.  * RETURNS
  3034.  *  numeric value of image offset or index
  3035.  *****************************************************************************/
  3036. U32 mmi_tm_get_theme_image_offset_or_index(U16 image_id, S32 *nArrayIndex_p)
  3037. {
  3038.     /*----------------------------------------------------------------*/
  3039.     /* Local Variables                                                */
  3040.     /*----------------------------------------------------------------*/
  3041.     S32 nFirst = 0;
  3042.     S32 nLast = g_tm_cntx.theme_imageid_image_count;
  3043.     S32 nMid;
  3044.     /*----------------------------------------------------------------*/
  3045.     /* Code Body                                                      */
  3046.     /*----------------------------------------------------------------*/
  3047.     while (nLast >= nFirst)
  3048.     {
  3049.         nMid = (nFirst + nLast) / 2;;
  3050.         if (g_tm_activated_theme.theme_image_details_list[nMid].image_id == image_id)
  3051.         {
  3052.             *nArrayIndex_p = nMid;
  3053.             return g_tm_activated_theme.theme_image_details_list[nMid].image_offset;
  3054.         }
  3055.         if (image_id > g_tm_activated_theme.theme_image_details_list[nMid].image_id)
  3056.         {
  3057.             nFirst = nMid + 1;
  3058.         }
  3059.         else
  3060.         {
  3061.             nLast = nMid - 1;
  3062.         }
  3063.     }
  3064.     return 0;
  3065. }
  3066. /*****************************************************************************
  3067.  * FUNCTION
  3068.  *  mmi_tm_get_curr_theme_type
  3069.  * DESCRIPTION
  3070.  *  This function returns the current activated theme type
  3071.  * PARAMETERS
  3072.  *  void
  3073.  * RETURNS
  3074.  *  numeric value of the theme type
  3075.  *****************************************************************************/
  3076. U8 mmi_tm_get_curr_theme_type(void)
  3077. {
  3078.     /*----------------------------------------------------------------*/
  3079.     /* Local Variables                                                */
  3080.     /*----------------------------------------------------------------*/
  3081.     /*----------------------------------------------------------------*/
  3082.     /* Code Body                                                      */
  3083.     /*----------------------------------------------------------------*/
  3084.     return g_tm_cntx.curr_activated_theme_type;
  3085. }
  3086. /*****************************************************************************
  3087.  * FUNCTION
  3088.  *  mmi_tm_get_total_themes_count
  3089.  * DESCRIPTION
  3090.  *  It gets the total no. of the themes
  3091.  * PARAMETERS
  3092.  *  void
  3093.  * RETURNS
  3094.  *  total number of themes
  3095.  *****************************************************************************/
  3096. U8 mmi_tm_get_total_themes_count(void)
  3097. {
  3098.     /*----------------------------------------------------------------*/
  3099.     /* Local Variables                                                */
  3100.     /*----------------------------------------------------------------*/
  3101.     /*----------------------------------------------------------------*/
  3102.     /* Code Body                                                      */
  3103.     /*----------------------------------------------------------------*/
  3104.     return g_tm_cntx.total_thm_cnt;
  3105. }
  3106. /*****************************************************************************
  3107.  * FUNCTION
  3108.  *  mmi_tm_get_current_theme_wallapaper
  3109.  * DESCRIPTION
  3110.  *  This function gets the current theme wallpaper
  3111.  * PARAMETERS
  3112.  *  void
  3113.  * RETURNS
  3114.  *  void
  3115.  *****************************************************************************/
  3116. pBOOL mmi_tm_get_current_theme_wallapaper(void)
  3117. {
  3118.     /*----------------------------------------------------------------*/
  3119.     /* Local Variables                                                */
  3120.     /*----------------------------------------------------------------*/
  3121.     /*----------------------------------------------------------------*/
  3122.     /* Code Body                                                      */
  3123.     /*----------------------------------------------------------------*/
  3124.     return g_tm_cntx.theme_has_wallpaper;
  3125. }
  3126. /*****************************************************************************
  3127.  * FUNCTION
  3128.  *  mmi_tm_get_current_theme_screensaver
  3129.  * DESCRIPTION
  3130.  *  This function gets the current theme screensaver
  3131.  * PARAMETERS
  3132.  *  void
  3133.  * RETURNS
  3134.  *  void
  3135.  *****************************************************************************/
  3136. pBOOL mmi_tm_get_current_theme_screensaver(void)
  3137. {
  3138.     /*----------------------------------------------------------------*/
  3139.     /* Local Variables                                                */
  3140.     /*----------------------------------------------------------------*/
  3141.     /*----------------------------------------------------------------*/
  3142.     /* Code Body                                                      */
  3143.     /*----------------------------------------------------------------*/
  3144.     return g_tm_cntx.theme_has_screensaver;
  3145. }
  3146. #endif /* (defined(__MMI_THEMES_V2_SUPPORT__)) */