📄 plxmms_box.c
字号:
* Remarks
\**************************************************************************/
BOOL CreateMmsBox(void* mmse, char* folder)
{
if(!mmse)
return FALSE;
MMS_Memset((void*)&g_box_data, 0, sizeof(MmsBoxData));
g_box_data.mmse = mmse;
g_box_data.folder = folder;
//g_box_data.id_to_report = -1;
g_id_to_report = -1;
//put message info into list
GetMmsInfoList();
if(g_box_data.info_count == 0) //no message, just go back
{
MMS_Memset((void*)&g_box_data, 0, sizeof(MmsBoxData));
return FALSE;
}
//create box menu
if(!CreateBoxMenu())
{
//clear list and go back
ClearList();
MMS_Memset((void*)&g_box_data, 0, sizeof(MmsBoxData));
return FALSE;
}
//show list
EnterMmsBox();
return TRUE;
}
/***************************************************************************
* Function CreateMmsInbox
* Purpose Open message list from other app
* Params
* Return
* Remarks In this call, will open a mmse and should close it when go back
\**************************************************************************/
BOOL CreateMmsInbox(void)
{
void* mmse;
MMS_Memset((void*)&g_box_data, 0, sizeof(MmsBoxData));
mmse = MMSE_Open(MMSE_ACCESS_READ);
if(!mmse)
return FALSE;
g_box_data.mmse = mmse;
g_box_data.folder = MMSE_FOLDER_INBOX;
g_box_data.bPubCall = TRUE;
g_box_data.back_screen = GetActiveScreenId();
//create inbox message list
GetMmsInfoList();
if(g_box_data.info_count == 0) //no message, just go back
{
MMSE_Close(mmse);
MMS_Memset((void*)&g_box_data, 0, sizeof(MmsBoxData));
return FALSE;
}
//create box menu
if(!CreateBoxMenu())
{
//clear list and go back
ClearList();
MMSE_Close(mmse);
MMS_Memset((void*)&g_box_data, 0, sizeof(MmsBoxData));
return FALSE;
}
//show list
EnterMmsBox();
return TRUE;
}
/***************************************************************************
* Function MmsBoxGoBackToIdle
* Purpose When processing KEY_END, mms main call this function to clear
* box data
* Params
* Return
* Remarks
\**************************************************************************/
void MmsBoxGoBackToIdle(void)
{
//clear message list
ClearList();
//close mmse if box is opened from other app
if(g_box_data.bPubCall &&
g_box_data.mmse)
MMSE_Close(g_box_data.mmse);
//destroy menu
if(g_box_data.hMenu)
PlxDestroyDMenu(g_box_data.hMenu);
if(g_box_data.hReportMenu)
PlxDestroyDMenu(g_box_data.hReportMenu);
//reset global data
MMS_Memset((void*)&g_box_data, 0, sizeof(MmsBoxData));
g_id_to_report = -1;
}
void SetNewMsgViewIntoInbox(void)
{
g_box_data.back_screen = MMS_NEW_MSG_VIEW_BACK_SCREEN;
}
/***************************************************************************
* private functions impelementation
\**************************************************************************/
/***************************************************************************
* Function EnterMmsBox
* Purpose Enter Mms box screen
* Params
* Return
* Remarks
\**************************************************************************/
void EnterMmsBox(void)
{
U8* guiBuffer = NULL;
U16 title;
//enter new screen
if(GetActiveScreenId() != SCR_ID_PLX_MMS_BOXLIST)
{
if(!g_box_data.info_count)
{
// ExitMmsBoxList();
//go back
if(g_box_data.bPubCall)
{
if(g_box_data.back_screen == MMS_NEW_MSG_VIEW_BACK_SCREEN)
GoBackToHistory(IDLE_SCREEN_ID);
else
GoBackToHistory(g_box_data.back_screen);
}
else
GoBackToHistory(SCR_ID_PLX_MMS_MAIN);
PLIB_MessageBox(PMBTYPE_EMPTY, NULL,
(WCHAR*)GetString(STR_GLOBAL_EMPTY), 0);
MmsBoxGoBackToIdle();
return;
}
EntryNewScreen(SCR_ID_PLX_MMS_BOXLIST, NULL, EnterMmsBox, NULL);
SetParentHandler(MENU_ID_PLX_MMS);
}
else
{
EntryNewScreen(SCR_ID_PLX_MMS_BOXLIST, NULL, EnterMmsBox, NULL);
SetDelScrnIDCallbackHandler(SCR_ID_PLX_MMS_BOXLIST, NULL);
DeleteScreenIfPresent(SCR_ID_PLX_MMS_BOXLIST);
}
//high light handler to get current message data
RegisterHighlightHandler(MmsBoxListHiliteHandler);
//title
switch((int)g_box_data.folder)
{
case 1: //inbox
title = STR_ID_PLX_MMS_INBOX;
break;
case 2: //outbox
title = STR_ID_PLX_MMS_OUTBOX;
break;
case 3: //draft
title = STR_ID_PLX_MMS_DRAFT;
break;
case 4: //sent
title = STR_ID_PLX_MMS_SENT;
break;
default:
title = 0;
}
ShowCategory184Screen(title, IMG_ID_PLX_MMS,
STR_GLOBAL_OPTIONS, IMG_GLOBAL_OK,
STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
g_box_data.info_count, MmsBoxListGetItemText,
MmsBoxListGetItemHint, g_box_data.cur_info_index, guiBuffer);
SetLeftSoftkeyFunction(EnterMmsBoxListMenu, KEY_EVENT_UP);
// SetKeyHandler(EnterMmsBoxListMenu, KEY_ENTER, KEY_EVENT_DOWN);
SetKeyHandler(PlxMmsGoBackToIdle, KEY_END, KEY_EVENT_DOWN);
SetRightSoftkeyFunction(ExitMmsBoxList, KEY_EVENT_UP);
SetKeyHandler(ExitMmsBoxList, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
SetKeyHandler(EnterMmsBoxListMenu, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
if(!IsScreenPresent(SCR_ID_PLX_MMS_MAIN))
SetDelScrnIDCallbackHandler(SCR_ID_PLX_MMS_BOXLIST, PlxMmsDelHistoryHdlr);
}
/***************************************************************************
* Function ExitMmsBoxList
* Purpose Exit Mms box
* Params
* Return
* Remarks
\**************************************************************************/
void ExitMmsBoxList(void)
{
//clear message list
ClearList();
//close mmse if called from other app
if(g_box_data.bPubCall &&
g_box_data.mmse)
MMSE_Close(g_box_data.mmse);
//destroy menu
if(g_box_data.hMenu)
PlxDestroyDMenu(g_box_data.hMenu);
if(g_box_data.hReportMenu)
PlxDestroyDMenu(g_box_data.hReportMenu);
//go back
if(g_box_data.bPubCall)
{
if(g_box_data.back_screen == MMS_NEW_MSG_VIEW_BACK_SCREEN)
GoBackToHistory(IDLE_SCREEN_ID);
else
GoBackToHistory(g_box_data.back_screen);
}
else
GoBackHistory();
//reset box data
MMS_Memset((void*)&g_box_data, 0, sizeof(MmsBoxData));
g_id_to_report = -1;
}
/***************************************************************************
* Function GetMmsInfoList
* Purpose Create message list
* Params
* Return
* Remarks When into box, call this function to create message list.
* Add message into list, call AddListItem. The list will released
* while exiting box
\**************************************************************************/
BOOL GetMmsInfoList(void)
{
PMMSEMSGINFO pInfo = NULL;
MmsBoxItem* p = NULL;
char* sub_charset = NULL;
char temp = 0;
int index = 1;
int count = 0;
int result = -1;
WCHAR* wSub = NULL;
int wSubLen = 0;
#ifdef MMS_DEBUG
PlxTrace("GetMmsInfoList\r\n");
#endif
//clear list
if(g_box_data.info_count > 0)
ClearList();
//select folder
MMSE_SelectFolder(g_box_data.mmse, g_box_data.folder);
//buffer for message info
pInfo = (PMMSEMSGINFO)g_msg_info_buf; //pBuf;
MMS_Memset((void*)pInfo, 0, MSG_INFO_BUF_LEN);
//get message count
count = MMSE_ListMessage(g_box_data.mmse, 1, NULL, 0);
#ifdef MMS_DEBUG
PlxTrace("msg count=%d\r\n", count);
#endif
if(count <= 0) //no message
return FALSE;
//list message and add into listbox
while ((result = MMSE_ListMessage(g_box_data.mmse, index, pInfo, MSG_INFO_BUF_LEN)) > 0)
{
int i;
#ifdef MMS_DEBUG
PlxTrace("MMSE_ListMessage return %d\r\n", result);
#endif
// in most case , 300 byte is enough for more than one message info
for (i = 0; i < result; i++)
{
#ifdef MMS_DEBUG
PlxTrace("a message, index = %d\r\n", index);
#endif
//new node
p = (MmsBoxItem*)MMS_Malloc(sizeof(MmsBoxItem));
if(!p)
{
#ifdef MMS_DEBUG
PlxTrace("malloc a new node failed\r\n");
#endif
goto get_list_err;
}
MMS_Memset((void*)p, 0, sizeof(MmsBoxItem));
//get number
#ifdef MMS_DEBUG
if(pInfo[i].pSender)
PlxTrace("number = %s\r\n", pInfo[i].pSender);
#endif
if(pInfo[i].pSender &&
pInfo[i].pSender[0] != 0)
{
#ifdef MMS_DEBUG
PlxTrace("has number\r\n");
#endif
//find the first number
sub_charset = MMS_Strstr(pInfo[i].pSender, ";");
if(sub_charset)
{
temp = *sub_charset;
*sub_charset = 0;
}
//if a email
if(MMS_Strstr(pInfo[i].pSender, "@") ||
MMS_Strlen(pInfo[i].pSender) >= MAX_NUM_LEN)
p->bEMail = TRUE;
//save number. name will get as hint
AnsiiToUnicodeString((S8*)p->num, (S8*)pInfo[i].pSender);
if(sub_charset && temp)
{
*sub_charset = temp;
temp = 0;
}
}
else //no number
{
#ifdef MMS_DEBUG
PlxTrace("no number\r\n");
#endif
if(g_box_data.folder == MMSE_FOLDER_INBOX &&
(pInfo[i].status == MMT_DELIVERYREPORT || //is a delivery report in inbox
pInfo[i].status == MMT_UNREADDELIVERYREPORT)
)
{
pfnUnicodeStrcpy((S8*)p->num,
(S8*)GetString(STR_ID_PLX_MMS_BOX_DELIVERYREPORTSUB));
}
//else, leave num as L"" and show "No Number" when get hint
}
#ifdef MMS_DEBUG
PlxTrace("will get sub\r\n");
#endif
//get sub
if(pInfo[i].status == MMT_DELIVERYREPORT ||
pInfo[i].status == MMT_UNREADDELIVERYREPORT) //delivery report
{
#ifdef MMS_DEBUG
PlxTrace("a delivery report\r\n");
#endif
pfnUnicodeStrcpy((S8*)p->sub,
(S8*)GetString(STR_ID_PLX_MMS_BOX_DELIVERYREPORTSUB));
}
else //normal message
{
#ifdef MMS_DEBUG
PlxTrace("a normal message\r\n");
#endif
if(pInfo[i].pSubject)
{
//remove charset
sub_charset = MMS_Strstr(pInfo[i].pSubject, ";Charset");
if(sub_charset)
{
temp = *sub_charset;
*sub_charset = 0;
}
//uniLen = PlxMmsUTF8ToWideChar((const char*)pInfo[i].pSubject, MMS_Strlen(pInfo[i].pSubject),
// (char*)p->sub, MAX_SUB_LEN);
wSub = MMS_UTF8ToUnicode((unsigned char*)pInfo[i].pSubject,
MMS_Strlen(pInfo[i].pSubject), &wSubLen);
if(!wSub || wSub[0] == 0x0000)
{
pfnUnicodeStrcpy((S8*)p->sub,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -