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

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.  * ChatApp.C
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for Chat App.
  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.  *------------------------------------------------------------------------------
  84.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  85.  *============================================================================
  86.  ****************************************************************************/
  87. /**
  88.  * Copyright Notice
  89.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  90.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  91.  *  (It is illegal to remove this copyright notice from this software or any
  92.  *  portion of it)
  93.  */
  94. /**************************************************************
  95.    FILENAME : Chat.c
  96.    PURPOSE     : Chat application 
  97.    REMARKS     : nil
  98.    AUTHOR      : Alok Sharma     
  99.    DATE     : Feb 18,04
  100. **************************************************************/
  101. #include "MMI_features.h"
  102. #ifdef __MMI_MESSAGES_CHAT__
  103. #include "stdC.h"
  104. #include "L4Dr1.h"
  105. #include "PixtelDataTypes.h"
  106. #ifndef _CHAT_APP_
  107. #define _CHAT_APP_
  108. #include "ChatAppDef.h"
  109. #include "ChatAppGprot.h"
  110. #include "wgui_categories.h"
  111. #include "CustDataRes.h"
  112. #include "GlobalDefs.h"
  113. #include "QuickAccessMenuItemProt.h"
  114. #include "HistoryGprot.h"
  115. #include "MiscFunctions.h"
  116. // #include "OrganizerDcl.h"
  117. #include "CustMenuRes.h"
  118. #include "AlarmGProt.h"
  119. #include "SettingGprots.h"
  120. #include "SettingProt.h"
  121. #include "MessagesExDcl.h"
  122. #include "CalendarDef.h"
  123. // #include "CalendarGProt.h"
  124. #include "MainMenuDef.h"
  125. #include "ChatGtype.h"
  126. #include "NVRAMEnum.h"
  127. #include "NVRAMProt.h"
  128. #include "wgui_status_icons.h"
  129. #include "ChatAppprot.h"
  130. /****************Static Variable Start*********/
  131. typedef struct _CHAT_MEMEORY_DATA_STRUCT
  132. {
  133.     PU8 allocp;
  134.     PU8 maxMemUsed;
  135.     U8 isMemoryRounded;
  136. } chatMemoryDataStruct;
  137. static S16 gMessageChatRoomNo;
  138. static S16 gCurrentChatRoomNo;
  139. static U8 gChatBuffer[MAX_NO_OF_CHAT_ROOM][MAX_BUFFER_SIZE];
  140. /****************Static Variable End*********/
  141. /****************Static Function Start*********/
  142. /****************Static Function End*********/
  143. /****************Global Variable Start*********/
  144. chat_context_struct g_chat_cntx;
  145. chat_room_info_struct gChatRoomInfo[MAX_NO_OF_CHAT_ROOM];
  146. chatMemoryDataStruct gChatMemoryData[MAX_NO_OF_CHAT_ROOM];
  147. pBOOL gBlinkChatFlag[MAX_NO_OF_CHAT_ROOM];
  148. const U16 gChatSmsIcon[MAX_NO_OF_CHAT_ROOM] = 
  149. {
  150.     STATUS_ICON_CHAT_INDICATION_ROOM1,
  151.     STATUS_ICON_CHAT_INDICATION_ROOM2
  152. };
  153. extern chat_context_struct g_chat_cntx;
  154. extern chat_room_info_struct gChatRoomInfo[MAX_NO_OF_CHAT_ROOM];
  155. extern U32 mmi_phb_util_convert_number_to_int(PU8 number);
  156. /****************Global Variable End*********/
  157. /****************Function Start*********/
  158. PU8 GetMemoryPointer(S16 index, S16 roomNoIndex);
  159. S16 GetNumOfMessage(S16);
  160. void IncrementCounter(S16);
  161. void InitializeMemoryPointers(PS8 pointer[], S16 maxitems);
  162. void SetMessagechatRoomNo(S16 index);
  163. S16 GetMessagechatRoomNo(void);
  164. void ResetMessagechatRoomNo(void);
  165. void SetCurrentChatRoomNo(S16 index);
  166. S16 GetCurrentChatRoomNo(void);
  167. void ResetCurrentChatRoomNo(void);
  168. void ActivateChatRoom(S16 index);
  169. void DecrementCounter(S16 index);
  170. S8 GetChatRoomStatus(S16 index);
  171. void ShowChatStatusIcon(S16 index);
  172. void HideChatStatusIcon(S16 index);
  173. void BlinkChatIcon(S16 index);
  174. /****************Function End*********/
  175. /*****************************************************************************
  176.  * FUNCTION
  177.  *  InitializeChatApp
  178.  * DESCRIPTION
  179.  *  To Initialize Chat Variables at Boot time
  180.  * PARAMETERS
  181.  *  void
  182.  * RETURNS
  183.  *  void
  184.  *****************************************************************************/
  185. void InitializeChatApp(void)
  186. {
  187.     /*----------------------------------------------------------------*/
  188.     /* Local Variables                                                */
  189.     /*----------------------------------------------------------------*/
  190.     S16 iRoomCount;
  191.     S16 error;
  192.     static chat_info_nvram_struct infoStruct[MAX_NO_OF_CHAT_ROOM];
  193.     /*----------------------------------------------------------------*/
  194.     /* Code Body                                                      */
  195.     /*----------------------------------------------------------------*/
  196.     SetChatHiliteHandlers();
  197.     memset(&infoStruct, 0, MAX_NO_OF_CHAT_ROOM * sizeof(infoStruct));
  198.     for (iRoomCount = 0; iRoomCount < MAX_NO_OF_CHAT_ROOM; iRoomCount++)
  199.     {
  200.         U16 index = (U16) iRoomCount + 1;
  201.         if (ReadRecord
  202.             (NVRAM_EF_CHAT_ROOM_INFO_LID, index, &infoStruct[iRoomCount], NVRAM_CHAT_ROOM_INFO_RECORD_SIZE, &error) < 0)
  203.         {
  204.             memset(&infoStruct[iRoomCount], 0, sizeof(infoStruct));
  205.             WriteRecord(
  206.                 NVRAM_EF_CHAT_ROOM_INFO_LID,
  207.                 index,
  208.                 (void*)&infoStruct[iRoomCount],
  209.                 NVRAM_CHAT_ROOM_INFO_RECORD_SIZE,
  210.                 &error);
  211.         }
  212.         g_chat_cntx.chatRoomInfo[iRoomCount].status = MMI_MSG_CHAT_DISABLE;
  213.         g_chat_cntx.chatRoomInfo[iRoomCount].chatRoomCounter = 0;
  214.         pfnUnicodeStrcpy(
  215.             (S8*) (g_chat_cntx.chatRoomInfo[iRoomCount].chatInfo.nickName),
  216.             (S8*) infoStruct[iRoomCount].nickName);
  217.         AnsiiToUnicodeString(
  218.             (S8*) (g_chat_cntx.chatRoomInfo[iRoomCount].chatInfo.destinationNo),
  219.             (S8*) infoStruct[iRoomCount].destinationNo);
  220.         HideChatStatusIcon(iRoomCount);
  221.         g_chat_cntx.blinkChatFlag[iRoomCount] = FALSE;
  222.     }
  223.     InitChatHeader();
  224.     ResetCurrentChatRoomNo();
  225.     InitailizeMemoryManager();
  226.     memset(g_chat_cntx.writeChatBuffer, 0, ((MAX_MSG_SIZE + 1) * ENCODING_LENGTH));
  227. }
  228. /*****************************************************************************
  229.  * FUNCTION
  230.  *  InitailizeMemoryManager
  231.  * DESCRIPTION
  232.  *  It initializes memory buffer
  233.  * PARAMETERS
  234.  *  void
  235.  * RETURNS
  236.  *  void
  237.  *****************************************************************************/
  238. void InitailizeMemoryManager(void)
  239. {
  240.     /*----------------------------------------------------------------*/
  241.     /* Local Variables                                                */
  242.     /*----------------------------------------------------------------*/
  243.     S16 index;
  244.     /*----------------------------------------------------------------*/
  245.     /* Code Body                                                      */
  246.     /*----------------------------------------------------------------*/
  247.     for (index = 0; index < MAX_NO_OF_CHAT_ROOM; index++)
  248.     {
  249.         ResetMemoryBuffer(index);
  250.     }
  251. }
  252. /*****************************************************************************
  253.  * FUNCTION
  254.  *  EntryChatApp
  255.  * DESCRIPTION
  256.  *  This is Entry function of Chat Option Screen
  257.  * PARAMETERS
  258.  *  void
  259.  * RETURNS
  260.  *  void
  261.  *****************************************************************************/
  262. extern const U16 gIndexIconsImageList[];
  263. void EntryChatApp(void)
  264. {
  265.     /*----------------------------------------------------------------*/
  266.     /* Local Variables                                                */
  267.     /*----------------------------------------------------------------*/
  268.     U8 *guiBuffer;
  269.     S32 numOfItems = 0;
  270.     U8 iRoomCount = 0;
  271.     U16 itemList[MAX_SUB_MENUS];
  272.     U8 *itemStr[MAX_SUB_MENUS];
  273.     U16 ChatRoomIconstates[MAX_NO_OF_CHAT_ROOM];
  274.     /*----------------------------------------------------------------*/
  275.     /* Code Body                                                      */
  276.     /*----------------------------------------------------------------*/
  277.     guiBuffer = GetCurrGuiBuffer(CHAT_SCREEN_ID);
  278.     EntryNewScreen(CHAT_SCREEN_ID, NULL, EntryChatApp, NULL);
  279.     SetParentHandler(MENU_CHATAPP_ID);
  280.     numOfItems = GetNumOfChild(MENU_CHATAPP_ID);
  281.     GetSequenceStringIds(MENU_CHATAPP_ID, itemList);
  282.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  283.     for (iRoomCount = 0; iRoomCount < MAX_NO_OF_CHAT_ROOM; iRoomCount++)
  284.     {
  285.         itemStr[iRoomCount] = (U8*) GetString(itemList[iRoomCount]);
  286.         if (g_chat_cntx.chatRoomInfo[iRoomCount].status == MMI_MSG_CHAT_DISABLE)
  287.         {
  288.             ChatRoomIconstates[iRoomCount] = 0;
  289.         }
  290.         else
  291.         {
  292.             ChatRoomIconstates[iRoomCount] = IMG_VICON;
  293.         }
  294.     }
  295.     /*
  296.      * ShowCategory52Screen(CHAT_ROOM_MENU_TEXT,CHAT_IMAGE_APP_ID,
  297.      * STR_GLOBAL_OPTIONS,IMG_GLOBAL_OK,
  298.      * STR_GLOBAL_BACK,IMG_GLOBAL_BACK,
  299.      * numOfItems,itemList,ChatRoomIconstates,NULL,0,0,guiBuffer);
  300.      */
  301.     ShowCategory73Screen(
  302.         CHAT_ROOM_MENU_TEXT,
  303.         CHAT_IMAGE_APP_ID,
  304.         STR_GLOBAL_OPTIONS,
  305.         IMG_GLOBAL_OK,
  306.         STR_GLOBAL_BACK,
  307.         IMG_GLOBAL_BACK,
  308.         numOfItems,
  309.         itemStr,
  310.         ChatRoomIconstates,
  311.         (U16*) gIndexIconsImageList,
  312.         0,
  313.         guiBuffer,
  314.         ICON_ICON_TEXT);
  315.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  316. }
  317. /*****************************************************************************
  318.  * FUNCTION
  319.  *  GetNumOfMessage
  320.  * DESCRIPTION
  321.  *  Returns Total Number of message in Chat Room
  322.  * PARAMETERS
  323.  *  index       [IN]        
  324.  *  Chat Room No[0/1](?)
  325.  * RETURNS
  326.  *  Total Number of Message in Chat Room
  327.  *****************************************************************************/
  328. S16 GetNumOfMessage(S16 index)
  329. {
  330.     /*----------------------------------------------------------------*/
  331.     /* Local Variables                                                */
  332.     /*----------------------------------------------------------------*/
  333.     /*----------------------------------------------------------------*/
  334.     /* Code Body                                                      */
  335.     /*----------------------------------------------------------------*/
  336.     return g_chat_cntx.chatRoomInfo[index].chatRoomCounter;
  337. }
  338. /*****************************************************************************
  339.  * FUNCTION
  340.  *  IncrementCounter
  341.  * DESCRIPTION
  342.  *  Increses Counter of Chat Room
  343.  * PARAMETERS
  344.  *  index       [IN]        
  345.  *  Chat Room No[0/1](?)
  346.  * RETURNS
  347.  *  void
  348.  *****************************************************************************/
  349. void IncrementCounter(S16 index)
  350. {
  351.     /*----------------------------------------------------------------*/
  352.     /* Local Variables                                                */
  353.     /*----------------------------------------------------------------*/
  354.     /*----------------------------------------------------------------*/
  355.     /* Code Body                                                      */
  356.     /*----------------------------------------------------------------*/
  357.     g_chat_cntx.chatRoomInfo[index].chatRoomCounter++;
  358. }
  359. /*****************************************************************************
  360.  * FUNCTION
  361.  *  ResetCounter
  362.  * DESCRIPTION
  363.  *  Set Chat Room Counter to Zero
  364.  * PARAMETERS
  365.  *  index       [IN]        
  366.  *  Chat Room No[0/1](?)
  367.  * RETURNS
  368.  *  void
  369.  *****************************************************************************/
  370. void ResetCounter(S16 index)
  371. {
  372.     /*----------------------------------------------------------------*/
  373.     /* Local Variables                                                */
  374.     /*----------------------------------------------------------------*/
  375.     /*----------------------------------------------------------------*/
  376.     /* Code Body                                                      */
  377.     /*----------------------------------------------------------------*/
  378.     g_chat_cntx.chatRoomInfo[index].chatRoomCounter = 0;
  379. }
  380. /*****************************************************************************
  381.  * FUNCTION
  382.  *  DecrementCounter
  383.  * DESCRIPTION
  384.  *  Decreases Chat Room Counter By one
  385.  * PARAMETERS
  386.  *  index       [IN]        
  387.  *  Chat Room No[0/1](?)
  388.  * RETURNS
  389.  *  void
  390.  *****************************************************************************/
  391. void DecrementCounter(S16 index)
  392. {
  393.     /*----------------------------------------------------------------*/
  394.     /* Local Variables                                                */
  395.     /*----------------------------------------------------------------*/
  396.     /*----------------------------------------------------------------*/
  397.     /* Code Body                                                      */
  398.     /*----------------------------------------------------------------*/
  399.     g_chat_cntx.chatRoomInfo[index].chatRoomCounter--;
  400. }
  401. /*****************************************************************************
  402.  * FUNCTION
  403.  *  SetMessagechatRoomNo
  404.  * DESCRIPTION
  405.  *  It sets for which Chat Room New message has Arrived
  406.  * PARAMETERS
  407.  *  index       [IN]        
  408.  *  Chat Room No[0/1](?)
  409.  * RETURNS
  410.  *  void
  411.  *****************************************************************************/
  412. void SetMessagechatRoomNo(S16 index)
  413. {
  414.     /*----------------------------------------------------------------*/
  415.     /* Local Variables                                                */
  416.     /*----------------------------------------------------------------*/
  417.     /*----------------------------------------------------------------*/
  418.     /* Code Body                                                      */
  419.     /*----------------------------------------------------------------*/
  420.     gMessageChatRoomNo = index;
  421. }
  422. /*****************************************************************************
  423.  * FUNCTION
  424.  *  GetMessagechatRoomNo
  425.  * DESCRIPTION
  426.  *  It message Chat Room No
  427.  * PARAMETERS
  428.  *  void
  429.  * RETURNS
  430.  *  Message Chat Room no[0/1]
  431.  *****************************************************************************/
  432. S16 GetMessagechatRoomNo(void)
  433. {
  434.     /*----------------------------------------------------------------*/
  435.     /* Local Variables                                                */
  436.     /*----------------------------------------------------------------*/
  437.     /*----------------------------------------------------------------*/
  438.     /* Code Body                                                      */
  439.     /*----------------------------------------------------------------*/
  440.     return gMessageChatRoomNo;
  441. }
  442. /*****************************************************************************
  443.  * FUNCTION
  444.  *  ResetMessageChatRoomNo
  445.  * DESCRIPTION
  446.  *  Reset message Chat Room No
  447.  * PARAMETERS
  448.  *  void
  449.  * RETURNS
  450.  *  void
  451.  *****************************************************************************/
  452. void ResetMessageChatRoomNo(void)
  453. {
  454.     /*----------------------------------------------------------------*/
  455.     /* Local Variables                                                */
  456.     /*----------------------------------------------------------------*/
  457.     /*----------------------------------------------------------------*/
  458.     /* Code Body                                                      */
  459.     /*----------------------------------------------------------------*/
  460.     gMessageChatRoomNo = -1;
  461. }
  462. /*****************************************************************************
  463.  * FUNCTION
  464.  *  SetCurrentChatRoomNo
  465.  * DESCRIPTION
  466.  *  This sets Current Chat Room No
  467.  * PARAMETERS
  468.  *  index       [IN]        
  469.  *  Chat Room No[0/1](?)
  470.  * RETURNS
  471.  *  void
  472.  *****************************************************************************/
  473. void SetCurrentChatRoomNo(S16 index)
  474. {
  475.     /*----------------------------------------------------------------*/
  476.     /* Local Variables                                                */
  477.     /*----------------------------------------------------------------*/
  478.     /*----------------------------------------------------------------*/
  479.     /* Code Body                                                      */
  480.     /*----------------------------------------------------------------*/
  481.     gCurrentChatRoomNo = index;
  482. }
  483. /*****************************************************************************
  484.  * FUNCTION
  485.  *  GetCurrentChatRoomNo
  486.  * DESCRIPTION
  487.  *  This returns Current Chat Room No
  488.  * PARAMETERS
  489.  *  void
  490.  * RETURNS
  491.  *  Message None
  492.  *****************************************************************************/
  493. S16 GetCurrentChatRoomNo(void)
  494. {
  495.     /*----------------------------------------------------------------*/
  496.     /* Local Variables                                                */
  497.     /*----------------------------------------------------------------*/
  498.     /*----------------------------------------------------------------*/
  499.     /* Code Body                                                      */
  500.     /*----------------------------------------------------------------*/
  501.     return gCurrentChatRoomNo;
  502. }
  503. /*****************************************************************************
  504.  * FUNCTION
  505.  *  ResetCurrentChatRoomNo
  506.  * DESCRIPTION
  507.  *  This sets Current Chat Room No to -1
  508.  * PARAMETERS
  509.  *  void
  510.  * RETURNS
  511.  *  void
  512.  *****************************************************************************/
  513. void ResetCurrentChatRoomNo(void)
  514. {
  515.     /*----------------------------------------------------------------*/
  516.     /* Local Variables                                                */
  517.     /*----------------------------------------------------------------*/
  518.     /*----------------------------------------------------------------*/
  519.     /* Code Body                                                      */
  520.     /*----------------------------------------------------------------*/
  521.     gCurrentChatRoomNo = -1;
  522. }
  523. /*****************************************************************************
  524.  * FUNCTION
  525.  *  ActivateChatRoom
  526.  * DESCRIPTION
  527.  *  This Activates Chat Room
  528.  * PARAMETERS
  529.  *  index       [IN]        
  530.  *  Chat Room No[0/1](?)
  531.  * RETURNS
  532.  *  void
  533.  *****************************************************************************/
  534. void ActivateChatRoom(S16 index)
  535. {
  536.     /*----------------------------------------------------------------*/
  537.     /* Local Variables                                                */
  538.     /*----------------------------------------------------------------*/
  539.     /*----------------------------------------------------------------*/
  540.     /* Code Body                                                      */
  541.     /*----------------------------------------------------------------*/
  542.     ClearChat(index);
  543.     g_chat_cntx.chatRoomInfo[index].status = MMI_MSG_CHAT_ENABLE;
  544.     ShowChatStatusIcon(index);
  545. }
  546. /*****************************************************************************
  547.  * FUNCTION
  548.  *  GetMemoryPointer
  549.  * DESCRIPTION
  550.  *  This Returns Chat Room Message Pointer
  551.  * PARAMETERS
  552.  *  index           [IN]        Chat Room No[0/1]
  553.  *  roomNoIndex     [IN]        
  554.  * RETURNS
  555.  *  Pointer to a String
  556.  *****************************************************************************/
  557. PU8 GetMemoryPointer(S16 index, S16 roomNoIndex)
  558. {
  559.     /*----------------------------------------------------------------*/
  560.     /* Local Variables                                                */
  561.     /*----------------------------------------------------------------*/
  562.     /*----------------------------------------------------------------*/
  563.     /* Code Body                                                      */
  564.     /*----------------------------------------------------------------*/
  565.     return g_chat_cntx.chatRoomInfo[roomNoIndex].chatStrings[index].chat_message_string;
  566. }
  567. /*****************************************************************************
  568.  * FUNCTION
  569.  *  GetChatRoomStatus
  570.  * DESCRIPTION
  571.  *  This Returns Chat Room Status
  572.  * PARAMETERS
  573.  *  index       [IN]        
  574.  *  Chat Room No[0/1](?)
  575.  * RETURNS
  576.  *  Chat Room Status flag
  577.  *****************************************************************************/
  578. S8 GetChatRoomStatus(S16 index)
  579. {
  580.     /*----------------------------------------------------------------*/
  581.     /* Local Variables                                                */
  582.     /*----------------------------------------------------------------*/
  583.     /*----------------------------------------------------------------*/
  584.     /* Code Body                                                      */
  585.     /*----------------------------------------------------------------*/
  586.     return g_chat_cntx.chatRoomInfo[index].status;
  587. }
  588. /*****************************************************************************
  589.  * FUNCTION
  590.  *  ShowChatStatusIcon
  591.  * DESCRIPTION
  592.  *  This function sets Status icons
  593.  * PARAMETERS
  594.  *  index       [IN]        
  595.  *  Chat Room No[0/1](?)
  596.  * RETURNS
  597.  *  void
  598.  *****************************************************************************/
  599. void ShowChatStatusIcon(S16 index)
  600. {
  601.     /*----------------------------------------------------------------*/
  602.     /* Local Variables                                                */
  603.     /*----------------------------------------------------------------*/
  604.     /*----------------------------------------------------------------*/
  605.     /* Code Body                                                      */
  606.     /*----------------------------------------------------------------*/
  607.     IdleSetStatusIcon(gChatSmsIcon[index]);
  608. }
  609. /*****************************************************************************
  610.  * FUNCTION
  611.  *  HideChatStatusIcon
  612.  * DESCRIPTION
  613.  *  This function Hides Status icons
  614.  * PARAMETERS
  615.  *  index       [IN]        
  616.  *  Chat Room No[0/1](?)
  617.  * RETURNS
  618.  *  void
  619.  *****************************************************************************/
  620. void HideChatStatusIcon(S16 index)
  621. {
  622.     /*----------------------------------------------------------------*/
  623.     /* Local Variables                                                */
  624.     /*----------------------------------------------------------------*/
  625.     /*----------------------------------------------------------------*/
  626.     /* Code Body                                                      */
  627.     /*----------------------------------------------------------------*/
  628.     IdleResetStatusIcon(gChatSmsIcon[index]);
  629. }
  630. /*****************************************************************************
  631.  * FUNCTION
  632.  *  BlinkChatIcon
  633.  * DESCRIPTION
  634.  *  This function Blinks Status icons
  635.  * PARAMETERS
  636.  *  index       [IN]        
  637.  *  Chat Room No[0/1](?)
  638.  * RETURNS
  639.  *  void
  640.  *****************************************************************************/
  641. void BlinkChatIcon(S16 index)
  642. {
  643.     /*----------------------------------------------------------------*/
  644.     /* Local Variables                                                */
  645.     /*----------------------------------------------------------------*/
  646.     /*----------------------------------------------------------------*/
  647.     /* Code Body                                                      */
  648.     /*----------------------------------------------------------------*/
  649.     BlinkStatusIcon(gChatSmsIcon[index]);
  650.     UpdateStatusIcons();
  651.     g_chat_cntx.blinkChatFlag[index] = TRUE;
  652. }
  653. /*****************************************************************************
  654.  * FUNCTION
  655.  *  AllocMemory
  656.  * DESCRIPTION
  657.  *  It allocates memory from Memory pool
  658.  * PARAMETERS
  659.  *  len         [IN]        
  660.  *  roomNum     [IN]        
  661.  *  Total number of bytes & Chat room number(?)
  662.  * RETURNS
  663.  *  Pointer to Allocated memory
  664.  *****************************************************************************/
  665. PU8 AllocMemory(S32 len, S16 roomNum)
  666. {
  667.     /*----------------------------------------------------------------*/
  668.     /* Local Variables                                                */
  669.     /*----------------------------------------------------------------*/
  670.     U8 currMessIndex = g_chat_cntx.chatRoomInfo[roomNum].chatRoomCounter - 1;
  671.     /*----------------------------------------------------------------*/
  672.     /* Code Body                                                      */
  673.     /*----------------------------------------------------------------*/
  674.     /* if the intend-to-add chat message is larger than the max buffer size, it is not allowed */
  675.     if (len > MAX_BUFFER_SIZE)
  676.     {
  677.         return NULL;
  678.     }
  679.     /* the remaining space for the chatroom is not enough for the intend-to-add chat message */
  680.     if (((gChatBuffer[roomNum] + MAX_BUFFER_SIZE) - gChatMemoryData[roomNum].allocp) < len)
  681.     {
  682.         /* maxMemUsed points to the end of the last chat message in the chatroom before adding the intend-to-add chat message */
  683.         gChatMemoryData[roomNum].maxMemUsed = gChatMemoryData[roomNum].allocp;
  684.         gChatMemoryData[roomNum].isMemoryRounded = 1;
  685.     }
  686.     if (gChatMemoryData[roomNum].isMemoryRounded)
  687.     {
  688.         U8 index, indexCount = 0;
  689.         PU8 tempAllocBuf;
  690.         /* the remaining space for the chatroom is not enough for the intend-to-add chat message */
  691.         if ((gChatBuffer[roomNum] + MAX_BUFFER_SIZE) < (gChatMemoryData[roomNum].allocp + len))
  692.         {
  693.             /* allocp points to the start of the chatroom and it would be the start point of the intend-to-add chat message */
  694.             gChatMemoryData[roomNum].allocp = gChatBuffer[roomNum];
  695.             /* search for the chat message index that points to the start of the chatroom */
  696.             for (index = 0; index < currMessIndex; index++)
  697.             {
  698.                 if (g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index].chat_message_string == gChatBuffer[roomNum])
  699.                 {
  700.                     break;
  701.                 }
  702.                 /* indexCount is the chat message index that points to the start of the chatroom */
  703.                 indexCount++;
  704.             }
  705.         }
  706.         /* tempAllocBuf is the end point of the intend-to-add chat message */
  707.         tempAllocBuf = gChatMemoryData[roomNum].allocp + len;
  708.         for (index = indexCount; index < currMessIndex; index++)
  709.         {
  710.             /* the original chat message is out of the range of the intend-to-add chat message */
  711.             if ((g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index].chat_message_string <
  712.                  gChatMemoryData[roomNum].allocp) ||
  713.                 (g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index].chat_message_string > tempAllocBuf))
  714.             {
  715.                 if (index > 0)
  716.                 {
  717.                     /* the intend-to-add chat message is larger than all of the original chat messages, so all of the original chat messages would be removed */
  718.                     if (gChatMemoryData[roomNum].maxMemUsed <= tempAllocBuf)
  719.                     {
  720.                         break;
  721.                     }
  722.                     /* index-1 is the last chat message in the range of the intend-to-add chat message so align it to the end point of the intend-to-add chat message */
  723.                     g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index - 1].chat_message_string = tempAllocBuf;
  724.                     /* set the truncate flag, the truncated content would be represented as (..) */
  725.                     if (g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index - 1].flag == RECEIVING_CHAT)
  726.                     {
  727.                         g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index - 1].flag = RECEIVING_CHAT_TRUNCATE;
  728.                     }
  729.                     else if (g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index - 1].flag == SENDING_CHAT)
  730.                     {
  731.                         g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index - 1].flag = SENDING_CHAT_TRUNCATE;
  732.                     }
  733.                     /* indexCount decrement is because partial chat content of index-1 would appear in chatroom */
  734.                     indexCount--;
  735.                 }
  736.                 break;
  737.             }
  738.             /* if the original chat message is not out of the range of the intend-to-add chat message and it aligns well so no truncate is needed */
  739.             if ((g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index].chat_message_string == tempAllocBuf))
  740.             {
  741.                 break;
  742.             }
  743.             /* indexCount is the start index of the chat message that would remain in the chatroom */
  744.             indexCount++;
  745.         }
  746.         /* all of the original chat messages should be removed */
  747.         if (indexCount == currMessIndex)
  748.         {
  749.             /* in case the content of the last chat message before adding the intend-to-add chat message is out of range */
  750.             if (gChatMemoryData[roomNum].maxMemUsed > tempAllocBuf)
  751.             {
  752.                 indexCount--;
  753.                 /* align the start point of the last chat message before adding the intend-to-add chat message to the end point of the intend-to-add chat message */
  754.                 g_chat_cntx.chatRoomInfo[roomNum].chatStrings[indexCount].chat_message_string = tempAllocBuf;
  755.                 /* set the truncate flag, the truncated content would be represented as (..) */
  756.                 if (g_chat_cntx.chatRoomInfo[roomNum].chatStrings[indexCount].flag == RECEIVING_CHAT)
  757.                 {
  758.                     g_chat_cntx.chatRoomInfo[roomNum].chatStrings[indexCount].flag = RECEIVING_CHAT_TRUNCATE;
  759.                 }
  760.                 else if (g_chat_cntx.chatRoomInfo[roomNum].chatStrings[indexCount].flag == SENDING_CHAT)
  761.                 {
  762.                     g_chat_cntx.chatRoomInfo[roomNum].chatStrings[indexCount].flag = SENDING_CHAT_TRUNCATE;
  763.                 }
  764.             }
  765.         }
  766.         for (index = 0; indexCount && index < (currMessIndex - indexCount); index++)
  767.         {
  768.             g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index].chat_message_string =
  769.                 g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index + indexCount].chat_message_string;
  770.             g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index].flag =
  771.                 g_chat_cntx.chatRoomInfo[roomNum].chatStrings[index + indexCount].flag;
  772.         }
  773.         for (index = indexCount; index > 0; index--)
  774.         {
  775.             g_chat_cntx.chatRoomInfo[roomNum].chatStrings[currMessIndex - index].chat_message_string = NULL;
  776.             g_chat_cntx.chatRoomInfo[roomNum].chatStrings[currMessIndex - index].flag = 0;
  777.         }
  778.         g_chat_cntx.chatRoomInfo[roomNum].chatRoomCounter =
  779.             g_chat_cntx.chatRoomInfo[roomNum].chatRoomCounter - indexCount;
  780.     }
  781.     gChatMemoryData[roomNum].allocp += len;
  782.     return (gChatMemoryData[roomNum].allocp - len);
  783. }
  784. /*****************************************************************************
  785.  * FUNCTION
  786.  *  ResetMemoryBuffer
  787.  * DESCRIPTION
  788.  *  It resets memory buffer and other flags
  789.  * PARAMETERS
  790.  *  roomNum     [IN]        
  791.  *  Chat room number(?)
  792.  * RETURNS
  793.  *  void
  794.  *****************************************************************************/
  795. void ResetMemoryBuffer(S16 roomNum)
  796. {
  797.     /*----------------------------------------------------------------*/
  798.     /* Local Variables                                                */
  799.     /*----------------------------------------------------------------*/
  800.     /*----------------------------------------------------------------*/
  801.     /* Code Body                                                      */
  802.     /*----------------------------------------------------------------*/
  803.     gChatMemoryData[roomNum].allocp = gChatBuffer[roomNum];
  804.     gChatMemoryData[roomNum].maxMemUsed = gChatBuffer[roomNum];
  805.     gChatMemoryData[roomNum].isMemoryRounded = 0;
  806. }
  807. /*****************************************************************************
  808.  * FUNCTION
  809.  *  ResetRoundedFlag
  810.  * DESCRIPTION
  811.  *  It resets rounded flag
  812.  * PARAMETERS
  813.  *  roomNum     [IN]        
  814.  *  Chat room number(?)
  815.  * RETURNS
  816.  *  void
  817.  *****************************************************************************/
  818. void ResetRoundedFlag(S16 roomNum)
  819. {
  820.     /*----------------------------------------------------------------*/
  821.     /* Local Variables                                                */
  822.     /*----------------------------------------------------------------*/
  823.     /*----------------------------------------------------------------*/
  824.     /* Code Body                                                      */
  825.     /*----------------------------------------------------------------*/
  826.     gChatMemoryData[roomNum].isMemoryRounded = 0;
  827. }
  828. #endif /* _CHAT_APP_ */ 
  829. #endif /* __MMI_MESSAGES_CHAT__ */