⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thememanager.c

📁 MTK手机平台的MMI部分的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ( FS_GetFilePosition(g_tm_cntx.theme_file_handle, &fp) != FS_NO_ERROR )
    {
        mmi_tm_handle_file_access_failed();
        return NULL;
    }

    if( DRM_seek_file(g_tm_cntx.theme_file_handle, image_offset, FS_FILE_BEGIN) >= 0)
    {
        if ( DRM_read_file(g_tm_cntx.theme_file_handle, buff, THEME_IMAGE_INFO_HEADER, (U32*) & size) != FS_NO_ERROR )
        {
            mmi_tm_handle_file_access_failed();
            return NULL;
        }
    }
    else
    {
        mmi_tm_handle_file_access_failed();
        return NULL;
    }

    image_file_size = (U8) buff[2];
    image_file_size = (image_file_size << 8) | (U8) buff[3];
    image_file_size = (image_file_size << 8) | (U8) buff[4];

    switch (img_load_type)
    {
        case THEME_IMG_LOAD_ALWAYS:
            cache_ptr = g_tm_load_always_cache;
            cache_offset = &g_tm_load_always_offset;
            dlt_img_cache_size = DLT_LOAD_ALWAYS_CACHE_SIZE;
            break;
        case THEME_IMG_LOAD_ONDEMAND:
        default:
            cache_ptr = g_tm_load_ondemand_cache;
            cache_offset = &g_tm_load_ondemand_offset;
            dlt_img_cache_size = DLT_LOAD_ON_DEMAND_CACHE_SIZE;
    }

    /* 4-byte algin */
    if (((U32) cache_ptr + *cache_offset) % 4)
    {
        *cache_offset += 4 - (((U32) cache_ptr + *cache_offset) % 4);
    }

    /* Refer gdi_image_parse_resource_internal() in Gdi_image.c for header format information */
    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)
    {
        if ((*cache_offset + image_file_size + 8) > dlt_img_cache_size) /* 8 extra bytes for Gif Header */
        {
            if ( DRM_seek_file(g_tm_cntx.theme_file_handle, fp, FS_FILE_BEGIN) < 0)
            {
                mmi_tm_handle_file_access_failed();
            }
            return NULL;
        }
        image_buff = cache_ptr + *cache_offset;
        image_buff[1] = buff[1];
        image_buff[2] = (U8) (image_file_size & 0x000000ff);
        image_buff[3] = (U8) ((image_file_size >> 8) & 0x000000ff);
        image_buff[4] = (U8) ((image_file_size >> 16) & 0x000000ff);
        image_buff[5] = (U8) ((image_file_size >> 24) & 0x000000ff);

        switch (buff[0])
        {
            case GDI_IMAGE_TYPE_GIF_FILE_OFFSET:
                image_buff[0] = GDI_IMAGE_TYPE_GIF;
                image_buff[6] = 0;
                image_buff[7] = 0;
                if ( DRM_read_file(g_tm_cntx.theme_file_handle, image_buff + 8, image_file_size, (U32*) & size) != FS_NO_ERROR )
                {
                    mmi_tm_handle_file_access_failed();
                    return NULL;
                }
                *cache_offset += (image_file_size + 8); /* 8 extra bytes for Gif Header */
                p_img_ret = image_buff;
                break;
            case GDI_IMAGE_TYPE_BMP_FILE_OFFSET:
                image_buff[0] = GDI_IMAGE_TYPE_BMP;
                if ( DRM_read_file(g_tm_cntx.theme_file_handle, image_buff + 6, image_file_size, (U32*) & size) != FS_NO_ERROR)
                {
                    mmi_tm_handle_file_access_failed();
                    return NULL;
                }
                *cache_offset += (image_file_size + 6); /* 6 extra bytes for BMP Header */
                p_img_ret = image_buff;
                break;
            case GDI_IMAGE_TYPE_JPG_FILE_OFFSET:
                image_buff[0] = GDI_IMAGE_TYPE_JPG;
                if ( DRM_read_file(g_tm_cntx.theme_file_handle, image_buff + 6, image_file_size, (U32*) & size) != FS_NO_ERROR )
                {
                    mmi_tm_handle_file_access_failed();
                    return NULL;
                }
                *cache_offset += (image_file_size + 6); /* 6 extra bytes for jpg Header */
                p_img_ret = image_buff;
                break;
            default:
	            p_img_ret = NULL;
				break;
        }
    }
    else
    {
        p_img_ret = NULL;
    }

    if ( DRM_seek_file(g_tm_cntx.theme_file_handle, fp, FS_FILE_BEGIN) < 0)
    {
        mmi_tm_handle_file_access_failed();
        return NULL;
    }
	return p_img_ret;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_tm_add_img_id_to_cache
 * DESCRIPTION
 *  
 * PARAMETERS
 *  img_list_index      [IN]        
 *  image_offset        [IN]        
 *  type                [IN]        
 * RETURNS
 *  
 *****************************************************************************/
PU8 mmi_tm_add_img_id_to_cache(U32 img_list_index, U32 image_offset, tm_image_load_type_enum type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    PU8 pImage;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    pImage = mmi_tm_add_to_DLT_img_cache(image_offset, type);
    g_tm_cntx.theme_image_list[img_list_index].image_cache_ptr = pImage;

    PRINT_INFORMATION(("mmi_tm_add_img_id_to_cache: img_list_index =%d, image_offset = %d type = %d\n", img_list_index,
                       image_offset, type));

    return pImage;
}
#endif /* __MMI_DLT_CACHE_SUPPORT__ */ 


/*****************************************************************************
 * FUNCTION
 *  mmi_tm_create_non_imageid_image
 * DESCRIPTION
 *  this function creates non id image buffer and add it to pool
 * PARAMETERS
 *  image_offset        [IN]        
 *  type                [IN]        
 * RETURNS
 *  current image pointer in image pool buffer
 *****************************************************************************/
PU8 mmi_tm_create_non_imageid_image(U32 image_offset, tm_image_load_type_enum type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 size;
    U32 fp;
    PU8 pImage;
    U8 buff[MAX_THEME_IMAGE_HEADER_LENGTH] = {0};

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __MMI_DLT_CACHE_SUPPORT__
    if (type != THEME_IMG_LOAD_NEVER)
    {
        pImage = mmi_tm_add_to_DLT_img_cache(image_offset, type);

        if (pImage)
        {
            PRINT_INFORMATION(("mmi_tm_create_non_imageid_image: image_offset =%d, type = %d\n", image_offset, type));
            return pImage;
        }
    }
#endif /* __MMI_DLT_CACHE_SUPPORT__ */ 
    if ( FS_GetFilePosition(g_tm_cntx.theme_file_handle, &fp) != FS_NO_ERROR )
    {
        mmi_tm_handle_file_access_failed();
        return NULL;
    }

    if ( DRM_seek_file(g_tm_cntx.theme_file_handle, image_offset, FS_FILE_BEGIN) >=0 )
    {
        if ( DRM_read_file(g_tm_cntx.theme_file_handle, buff, THEME_IMAGE_INFO_HEADER, (U32*) & size) != FS_NO_ERROR )
        {
            mmi_tm_handle_file_access_failed();
            return NULL;
        }
    }
    else
    {
        mmi_tm_handle_file_access_failed();
        return NULL;
    }

    /* offset in next 4 bytes */
    buff[8] = (U8) (image_offset & 0x000000ff);
    buff[9] = (U8) ((image_offset >> 8) & 0x000000ff);
    buff[10] = (U8) ((image_offset >> 16) & 0x000000ff);
    buff[11] = (U8) ((image_offset >> 24) & 0x000000ff);

    /* file handle in next 4 bytes */
    buff[12] = (U8) (g_tm_cntx.theme_file_handle & 0x000000ff);
    buff[13] = (U8) ((g_tm_cntx.theme_file_handle >> 8) & 0x000000ff);
    buff[14] = (U8) ((g_tm_cntx.theme_file_handle >> 16) & 0x000000ff);
    buff[15] = (U8) ((g_tm_cntx.theme_file_handle >> 24) & 0x000000ff);

    if ( DRM_seek_file(g_tm_cntx.theme_file_handle, fp, FS_FILE_BEGIN) < 0)
    {
        mmi_tm_handle_file_access_failed();
        return NULL;
    }

    return (PU8) mmi_tm_add_image_header_to_pool(&(g_tm_cntx.non_imageid_images_headers), buff);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_tm_handle_audio
 * DESCRIPTION
 *  this function handles downloadable theme audio files
 * PARAMETERS
 *  audio_offset        [IN]        
 *  audio_size          [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_tm_handle_audio(U32 audio_offset, U32 audio_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 virtual_audio_fname[FS_GenVFN_SIZE + 8];
    S32 fs_result;

    /* PMT DLT_FIXES - TK 20060325 START */
    S8 TempName[MAX_IMAGE_NAME_PATH_WIDTH + MAX_AUDIO_NAME_WIDTH];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* PMT DLT_FIXES - TK 20060325 END */

    if (g_tc_audiothmfileformat == THEME_AUDIO)
    {
        AnsiiToUnicodeString((S8*) gDwnlThmToneInfo[0].AudioName, THEME_AUDIO_FILE);   /* currently only one audio is suported. Will be changed */
    }
    else if (g_tc_audiothmfileformat == THEME_MIDI)
    {
        AnsiiToUnicodeString((S8*) gDwnlThmToneInfo[0].AudioName, THEME_AUDIO_MID_FILE);
    }
    else if (g_tc_audiothmfileformat == THEME_MP3)
    {
        AnsiiToUnicodeString((S8*) gDwnlThmToneInfo[0].AudioName, THEME_AUDIO_MP3_FILE);
    }
    /* PMT DLT_FIXES - TK 20060325 START */
    memset(TempName, 0, (MAX_IMAGE_NAME_PATH_WIDTH + MAX_AUDIO_NAME_WIDTH));
    AnsiiToUnicodeString((S8*) TempName, THEME_AUDIO_FOLDER_PATH);
    FS_CreateDir((PU16) TempName);
    //      CreateDir((U8*)TempName);
    //PMT DLT_FIXES - TK 20060325 END
    //      AnsiiToUnicodeString((S8*)gDwnlThmToneInfo[0].AudioName, THEME_AUDIO_FILE);//currently only one audio is suported. Will be changed
    memset(virtual_audio_fname, 0, sizeof(virtual_audio_fname));
    fs_result = FS_GenVirtualFileName(
                    g_tm_cntx.theme_file_handle,
                    (U16*) virtual_audio_fname,
                    (unsigned int)FS_GenVFN_SIZE,
                    audio_offset,
                    audio_size);
    pfnUnicodeStrcat((PS8) virtual_audio_fname, (PS8) ".");
    pfnUnicodeStrcat((PS8) virtual_audio_fname, mmi_fmgr_extract_ext_file_name((PS8) gDwnlThmToneInfo[0].AudioName));
    pfnUnicodeStrcpy((S8*) gVirAudFileNameList[0], (S8*) virtual_audio_fname);
    if (fs_result >= 0)
    {
        g_tm_cntx.theme_has_ringtone = TRUE;
        gDwnlThmToneInfo[0].AudioId = CURRENT_THEME_INCOMING_CALL_TONE;
    }
    else
    {
        DisplayPopup(
            (PU8) GetString(STR_ID_FMGR_SPACE_NOT_AVAILABLE),
            IMG_GLOBAL_EMPTY,
            0,
            UI_POPUP_NOTIFYDURATION_TIME,
            WARNING_TONE);
    }

    /* PMT DLT_FIXES - TK 20060328 END */
}




/*****************************************************************************
 * FUNCTION
 *  mmi_tm_activate_downloaded_theme
 * DESCRIPTION
 *  This function activates downloadable theme
 * PARAMETERS
 *  theme_struct_p      [?]     
 * RETURNS
 *  theme error code
 *****************************************************************************/
tm_theme_error_enum mmi_tm_activate_downloaded_theme(tm_theme_list_struct *theme_struct_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    tm_theme_error_enum result;
    S16 err;
    U8 theme_file_name[(MAX_DWNL_THM_PATH_LEN + MAX_THEME_NAME_LENGTH) * ENCODING_LENGTH] = {0};
    U8 tmp_path[50] = {0};
    U16 nmodels = 0;
    BOOL phonemodelcheck = FALSE;
    FS_HANDLE last_theme_file_handle;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (theme_struct_p->theme_type == THEME_TYPE_DOWNLOADED_PHONE)
    {
        sprintf((PS8) tmp_path, "%c%s", MMI_PUBLIC_DRV, DOWNLOADED_THEMES_PATH);
        AnsiiToUnicodeString((PS8) theme_file_name, (PS8) tmp_path);
    }
    else
    {
        sprintf((PS8) tmp_path, "%c%s", MMI_CARD_DRV, DOWNLOADED_THEMES_PATH);
        AnsiiToUnicodeString((PS8) theme_file_name, (PS8) tmp_path);
    }
    {
        pfnUnicodeStrcat((PS8) theme_file_name, (PS8) theme_struct_p->theme_name);
    }


    last_theme_file_handle = g_tm_cntx.theme_file_handle;
    // g_tm_cntx.theme_file_handle = DRM_open_file((U16*)theme_file_name, FS_READ_ONLY, 0/*DRM_PERMISSION_NONE*/);
    g_tm_cntx.theme_file_handle = DRM_open_file((U16*) theme_file_name, FS_READ_ONLY | FS_OPEN_SHARED, 0);

    if (g_tm_cntx.theme_file_handle < FS_NO_ERROR)
    {
        g_tm_cntx.theme_file_handle = last_theme_file_handle;
        return THEME_ERROR_THEME_NOT_AVAILABLE;
    }

    if ( theme_struct_p->theme_checksum_verified == CHECKSUM_VERIFIED_BAD )
    {
        DRM_close_file(g_tm_cntx.theme_file_handle);
        g_tm_cntx.theme_file_handle = last_theme_file_handle;
        return THEME_ERROR_FILE_FORMAT_BAD;
    }
    else
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -