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

📄 plxbrowhistory.c

📁 mtk wap和mms代码。。适应mtk 25。26平台
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************
*
*                      Pollex Mobile Platform
*
*  Copyright (c) 2004 by Pollex Mobile Software Co., Ltd.
*                       All Rights Reserved
*
*  Module  :    Pollex WapBrowser History Module
*
*  Purpose :
*  
\**************************************************************************/
#include "PlxConfig.h"
#if defined(PROJECT_BRANCH_06A)
#define __NEWSIMULATOR
#include "FileSystemDef.h"
#undef __NEWSIMULATOR

#else

#ifdef MMI_ON_WIN32
#include <windows.h>
#endif

#ifndef MMI_ON_WIN32
#include "kal_release.h"
#endif
#endif // defined(PROJECT_BRANCH_06A)

#include "fs_type.h"
#include "fs_func.h"
#include "fs_errcode.h"
#include "GlobalScrEnum.h"
#include "StdC.h"
#include "CommonScreens.h"
#include "MMI_features.h"
#include "SettingProt.h"
#include "SettingProfile.h"
#include "stdlib.h"
#include "gui.h"
#include "wgui_categories_inputs.h"
#include "wgui_categories_popup.h"

#include "PWBE.h"
#include "../main/plxDefs.h"
#include "plxBrowDefs.h"
#include "plxbrow.h"
#include "../Public/PlxPublic.h"
#include "../Public/PlxPubDefs.h"
#include "plxBrowPublic.h"
#include "plxBrowHistory.h"




typedef struct tag_plxBrow_HistoryItem
{
       char  *szURLName;         //the url name string
} BrowHistoryItem, *PBrowHistoryItem;



static BrowHistoryItem  g_plxBrowHistories[PLXBROW_HISTORY_MAX_ITEM];
static char*  g_plxBrowHistoryItems[PLXBROW_HISTORY_MAX_ITEM];
static U16    g_plxBrowHistoryIcons[PLXBROW_HISTORY_MAX_ITEM];
static BOOL g_bPBHistoriesIsLoad ;

static int  curNumOfHistoryItems = 0;
static int	curSelHistoryItemID = 0;

static HDMENU hPlxBrowHistoryMenu = NULL;

//history handle
static int	plxBrowLoadHistories( void);
static BOOL	plxBrowSaveHistories(void);
static void plxBrowEmptyHistories(void);
static int plxBrowAddOneHistoryItem(const char *szUrl);

//history list screen
static void	EntryPlxBrowHistoryScreen(void);
static void plxBrowGetCurHiliteHisItemID(S32 item_index);
static void plxBrowJumpToSelHistoryUrlScreen(void);
static void ExitPlxBrowHistoryScreen(void);
//static pBOOL plxBrowGetNextHistoryItem( S32 item_index, UI_string_type str_buff, UI_image_type* img_buff_p, U8 str_img_mask );

//history menu screen
static void EntryPlxBrowHistoryMenu(void);
static int  plxBrowCreateHistroyMenu(void);
static void plxBrowModifyHistoryMenu(void);
static int  plxBrowHistoryMenuNty(HDMENU hMenu, unsigned long id, unsigned long event);

//history menu item handle
static void EntryPBHisDelMsgSelScreen (void);
static void DelHistoryConfirmCB(PLIBEVENT event);
static void HistoryDelMsgSelLskFunc(void);
static void EntryPBHisDelAllMsgSelScreen (void);
static void DelAllHistoryConfirmCB(PLIBEVENT event);
static void HistoryDelAllMsgSelLskFunc(void);
static void HistoryDelAllMsgSelRskFunc(void);
//key end hanlder 
static void PlxBrowHistoyKeyEndHandler(void);
static void HistoryKeyEndExitLskFunc(void);
//static void HistoryKeyEndExitConfirmCB(PLIBEVENT event);


/****************************************************************************
* Function	void  InitPlxBrowHistory(void)
* Purpose	init pollex browser history 
* Params	
* Return	
* Remarks	
\****************************************************************************/
void  InitPlxBrowHistory(void)
{
	plxBrowLoadHistories();
}


/****************************************************************************
* Function	void DeInitPlxBrowHistory(void)
* Purpose	Deinit pollex browser history 
* Params	
* Return	
* Remarks	
\****************************************************************************/
void DeInitPlxBrowHistory(void)
{
	plxBrowSaveHistories();
	curSelHistoryItemID = 0;
	if(NULL != hPlxBrowHistoryMenu)
	{
		PlxDestroyDMenu(hPlxBrowHistoryMenu);
		hPlxBrowHistoryMenu = NULL;
	}
}


/****************************************************************************
* Function	static void PlxBrowHistoyKeyEndHandler(void)
* Purpose	key end handler  
* Params	
* Return	
* Remarks	
\****************************************************************************/
void ExecGeneralKeyEndHandler (FuncPtr handler);
static void PlxBrowHistoyKeyEndHandler(void)
{	
/*	int   nToneId = WARNING_TONE;

	if(TRUE == IsScreenPresent(SCR_ID_PLX_BROW_VIEW))
		PLIB_ConfirmBox(NULL, (const WCHAR *) get_string(STR_ID_PLX_BROW_EXIT_CONFIRM), NULL,NULL, 
				NULL,0, (void*)&nToneId, 0, HistoryKeyEndExitConfirmCB);
	else
*/		
	ExecGeneralKeyEndHandler (HistoryKeyEndExitLskFunc);
}


/****************************************************************************
* Function	HistoryKeyEndExitConfirmCB
* Purpose	
* Params	
* Return	
* Remarks	
\****************************************************************************/
/*
static void HistoryKeyEndExitConfirmCB(PLIBEVENT event)
{
	if( PEVENT_POSITIVE== event)
		HistoryKeyEndExitLskFunc();
	else if(PEVENT_NEGTIVE  == event)
		GoBackHistory();

}
*/


/****************************************************************************
* Function	HistoryKeyEndExitLskFunc
* Purpose	
* Params	
* Return	
* Remarks	
\****************************************************************************/
static void HistoryKeyEndExitLskFunc(void)
{
//	DeInitPlxBrowHistory();
//	DeInitPlxBrowser();
//	DisplayIdleScreen();
	PlxBrowExitBrowserAndGoIdle();
}

/****************************************************************************
* Function	void EntryOfPlxBrowHistory(void)
* Purpose	enter of pollex browser history  
* Params	
* Return	
* Remarks	
\****************************************************************************/
void EntryOfPlxBrowHistory(void)
{	
	InitPlxBrowHistory();
	if(0 >= curNumOfHistoryItems)
	{	
		if(TRUE == IsScreenPresent(SCR_ID_PLX_BROW_VIEW))
			GoBackToHistory(SCR_ID_PLX_BROW_VIEW);
		else
			DeInitPlxBrowHistory();
		PLIB_MessageBox(PMBTYPE_EMPTY, NULL, (const WCHAR *)get_string(STR_GLOBAL_EMPTY), 	UI_POPUP_NOTIFYDURATION_TIME);
		return;
	}
	EntryPlxBrowHistoryScreen();
}


/****************************************************************************
* Function	int		plxBrowLoadHistories(void);
* Purpose	load histories from flash
* Params	
* Return	
* Remarks	
\****************************************************************************/
static int		plxBrowLoadHistories( void)
{

	FS_HANDLE 	fd;
	UINT		nRetFileSize=0;    
	int			flag = 0;
	int			hiscount = 0;
	int			i=0;
	WCHAR		szCurPath[PLXBROW_MAX_PATH];
	int			nUrlLen=0;
	int	       	nRetLen=0;
//	int			nRetUrl=0;
	int         nRetReadUrlLen;
	
	if(TRUE == g_bPBHistoriesIsLoad)
		return 0;
	AnsiiToUnicodeString((S8 *)szCurPath, (S8 *)GetPBUIHistoryFilePath());
	fd = FS_Open((const WCHAR*)szCurPath,FS_READ_ONLY);
	if (0 > fd)
		flag =  -1;
	else
	{
		
		if (FS_NO_ERROR != (nRetFileSize = FS_GetFileSize( fd,&nRetFileSize)))
		{
			flag =  -1;
		}
		else
		{
			FS_Seek( fd, 0,  FS_FILE_BEGIN);
			
			for (i =0; i< PLXBROW_HISTORY_MAX_ITEM; i++)
			{
				g_plxBrowHistories[i].szURLName =NULL;
				nRetReadUrlLen= FS_Read(fd,(void*)&nUrlLen,(UINT)sizeof(int),(UINT*)&nRetLen);
				if (nRetReadUrlLen != FS_NO_ERROR||
					nRetLen != sizeof(int) ||
					nUrlLen < 0 || nUrlLen >PLXBROW_URL_NAME_LEN)
				{
					flag =-1;
					break;
				}
				
				if ( nUrlLen > 0  )
				{
					g_plxBrowHistories[i].szURLName = PlxAppMalloc(nUrlLen); //the length of '\0' is calcuted nUrlLen ,see plxBrowSaveHisoties()
					if (!g_plxBrowHistories[i].szURLName)
					{
						flag =-1;
						break;
					}
					nRetReadUrlLen = FS_Read(fd,(void*)g_plxBrowHistories[i].szURLName,(UINT)nUrlLen,(UINT*)&nRetFileSize);
					if (nRetReadUrlLen != FS_NO_ERROR || nUrlLen != (int)nRetFileSize)
					{
						PlxAppFree(g_plxBrowHistories[i].szURLName);
						g_plxBrowHistories[i].szURLName =NULL;
						flag =  -1;
						break;
					}
				}//end if
			}//end for
			hiscount = i;			
		}//end else
		
		FS_Close(fd);
	}
	
	if (flag == -1)
	{
		for (i =hiscount;i< PLXBROW_HISTORY_MAX_ITEM;i++)
		{
			g_plxBrowHistories[i].szURLName=NULL;
		}
	}
	curNumOfHistoryItems = 0;
	for(i=0; i<PLXBROW_HISTORY_MAX_ITEM;i++)
	{
		if(	g_plxBrowHistories[i].szURLName != NULL &&
			pfnUnicodeStrlen(g_plxBrowHistories[i].szURLName) != 0)
				curNumOfHistoryItems++;
	}
	g_bPBHistoriesIsLoad = TRUE;
	return hiscount;
}


/****************************************************************************
* Function	BOOL	plxBrowSavehistories(void);
* Purpose	save histories to flash
* Params	
* Return	
* Remarks	
\****************************************************************************/
static BOOL	plxBrowSaveHistories(void)
{
	
	int			 nRetFileSize;
	int          i=0;
	int          nFileLen=0;
	int          nUrlLen;
	FS_HANDLE	 fd;
	WCHAR		 szCurPath[PLXBROW_MAX_PATH];
	char		 *szWbuf;
	char         *szWtmp;
	int			 nRetWrite;
	
	if(FALSE == g_bPBHistoriesIsLoad)
		return TRUE;

	AnsiiToUnicodeString((S8 *) szCurPath, (S8 *)GetPBUIHistoryFilePath());
	if(0 > (fd = FS_Open((const WCHAR*)szCurPath,FS_CREATE | FS_READ_WRITE | FS_ATTR_HIDDEN |FS_ATTR_SYSTEM)))	
	{
		plxBrowEmptyHistories();
		g_bPBHistoriesIsLoad = FALSE;
		return FALSE;
	}
	
	for(i=0;i< PLXBROW_HISTORY_MAX_ITEM; i++)
	{
		nFileLen +=  sizeof(int);				
		if (g_plxBrowHistories[i].szURLName)
			nFileLen += ((pfnUnicodeStrlen(g_plxBrowHistories[i].szURLName) +1)*2 );				
	}
/*	if(FALSE == PlxBrowIsFlashAvailabe((unsigned long)nFileLen, (const char *)GetPBUISettingFilePath()))
	{
		PLIB_MessageBox(PMBTYPE_ERROR, NULL, (const WCHAR *)get_string(STR_ID_PLX_BROW_SAVEPAGE_ERR_NOFLASHSPACE), UI_POPUP_NOTIFYDURATION_TIME);
		plxBrowEmptyHistories();
		g_bPBHistoriesIsLoad = FALSE;
		FS_Close(fd);
		return  FALSE;
	}
*/
	szWbuf= PlxAppMalloc(nFileLen);
	if (!szWbuf)
	{
		PLIB_MessageBox(PMBTYPE_ERROR, NULL, (const WCHAR *)get_string(STR_ID_PLX_BROW_ERR_MEMORYMALLOC), UI_POPUP_NOTIFYDURATION_TIME);
		nRetFileSize =-1;
	}
	else
	{
		szWtmp = szWbuf;
		for(i=0;i< PLXBROW_HISTORY_MAX_ITEM; i++)
		{
			nUrlLen =0;
			if (g_plxBrowHistories[i].szURLName)
				nUrlLen = (pfnUnicodeStrlen(g_plxBrowHistories[i].szURLName) +1)*2;
			PlxAppMemcpy(szWtmp,&nUrlLen,sizeof(int));
			szWtmp += sizeof(int);
			
			if (nUrlLen !=0)
			{
				PlxAppMemcpy(szWtmp,g_plxBrowHistories[i].szURLName,nUrlLen);				
				szWtmp += nUrlLen;
			}		
		}
		
		nRetWrite = FS_Write(fd,szWbuf,nFileLen,(UINT*)&nRetFileSize);
		PlxAppFree(szWbuf);
		if (nRetFileSize < nFileLen)		
			nRetFileSize = -1;
	}
	
	plxBrowEmptyHistories();
	g_bPBHistoriesIsLoad = FALSE;	
	if (nRetFileSize == -1)
	{
		FS_Close(fd);
		return FALSE;
	}
	//SetFileSize(fd,nFileLen);
	FS_Close(fd);
	return TRUE;
	
}

/****************************************************************************
* Function	int plxBrowAddOneHistory(const char *szUrl)
* Purpose		add one history item 
* Params	
* Return	
* Remarks	
\****************************************************************************/
int plxBrowAddOneHistory(const char *szUrl)
{
	return	plxBrowAddOneHistoryItem(szUrl);
}

/****************************************************************************
* Function	static int plxBrowAddOneHistoryItem(const int nUrltype,const char *szUrl)
* Purpose		add one history item 
* Params	
* Return	
* Remarks	
\****************************************************************************/
static int plxBrowAddOneHistoryItem(const char *szUtf8Url)
{
	int			i;
	int			nStart=0;
	int			nEnd=0;
	char			*pszWideUrl=NULL;
	int			nUtf8UrlLen;
	char               *szTempWideUrl;
	int                nWideUrlLen;
	char               *szTempUtf8Url;
	char			*p;

	if (NULL == szUtf8Url)
		return -1;
	if(0 == (nUtf8UrlLen = strlen(szUtf8Url)))
		return -1;
	if(NULL == (szTempUtf8Url = PlxAppMalloc(PLXBROW_URL_NAME_LEN)))
		return -1;
	if(NULL == (szTempWideUrl = PlxAppMalloc(PLXBROW_URL_NAME_LEN*2)))
	{
		PlxAppFree(szTempUtf8Url);
		return -1;
	}
	if(nUtf8UrlLen >=PLXBROW_URL_NAME_LEN)
	{
		nUtf8UrlLen = PLXBROW_URL_NAME_LEN -1;
		strncpy(szTempUtf8Url,szUtf8Url,nUtf8UrlLen);
		szTempUtf8Url[PLXBROW_URL_NAME_LEN -1] = '\0';
		p = strrchr(szTempUtf8Url,'/');
		*p = '\0';
		nUtf8UrlLen = p -szTempUtf8Url;
	}
	else
		strcpy(szTempUtf8Url,szUtf8Url);
	
//	memset(szTempWideUrl,0x0,PLXBROW_URL_NAME_LEN*2);
	PlxUTF82UCS2(szTempWideUrl, szTempUtf8Url, nUtf8UrlLen, PLXBROW_URL_NAME_LEN *2);
	PlxAppFree(szTempUtf8Url);
	for (i= 0;i<PLXBROW_HISTORY_MAX_ITEM ;i++)
	{	
		if(NULL == g_plxBrowHistories[i].szURLName)
		{
			nStart = 0;
			nEnd = i;
			break;
		}
		else	if ( pfnUnicodeStrcmp(g_plxBrowHistories[i].szURLName,szTempWideUrl) == 0)
		{
			nStart = 0;
			nEnd= i-1;
			pszWideUrl = g_plxBrowHistories[i].szURLName;
			break;
		}						
			nEnd = i;
	}
	if (nEnd == -1) 
	{
		PlxAppFree(szTempWideUrl);
		return 0;
	}
	if (nEnd >= PLXBROW_HISTORY_MAX_ITEM -1 )
	{
		nEnd = PLXBROW_HISTORY_MAX_ITEM -1;		
		
		if(pszWideUrl == NULL && g_plxBrowHistories[nEnd].szURLName) 
			PlxAppFree(g_plxBrowHistories[nEnd].szURLName);
	}
	for (i= (pszWideUrl == NULL ? nEnd -1 : nEnd); i>=nStart; i--)
	{
		g_plxBrowHistories[i+1].szURLName = g_plxBrowHistories[i].szURLName;
	}	
	if(nEnd + 1  > curNumOfHistoryItems)
		curNumOfHistoryItems = nEnd + 1; 

	if (pszWideUrl) //find the same url visited before
		g_plxBrowHistories[0].szURLName = pszWideUrl;
	else	//a new url 
	{
		nWideUrlLen = pfnUnicodeStrlen(szTempWideUrl);
		if(nWideUrlLen < PLXBROW_URL_NAME_LEN -1)
			g_plxBrowHistories[0].szURLName = PlxAppMalloc((nWideUrlLen +1)*2);

⌨️ 快捷键说明

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