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

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.  * ChatAppSendMsg.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.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  *------------------------------------------------------------------------------
  92.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  93.  *============================================================================
  94.  ****************************************************************************/
  95. /**
  96.  * Copyright Notice
  97.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  98.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  99.  *  (It is illegal to remove this copyright notice from this software or any
  100.  *  portion of it)
  101.  */
  102. /**************************************************************
  103.    FILENAME : ChatAppSendMsg.c
  104.    PURPOSE     : Chat application 
  105.    REMARKS     : nil
  106.    AUTHOR      : Alok Sharma     
  107.    DATE     : Feb 18,04
  108. **************************************************************/
  109. #include "MMI_features.h"
  110. #ifdef __MMI_MESSAGES_CHAT__
  111. #ifndef _CHAT_APPSENDMSG_
  112. #define _CHAT_APPSENDMSG_
  113. #include "stdC.h"
  114. #include "L4Dr1.h"
  115. #include "PixtelDataTypes.h"
  116. #include "EventsGprot.h"
  117. #include "HistoryGprot.h"
  118. #include "GlobalMenuItems.h"
  119. #include "GlobalConstants.h"
  120. #include "Globaldefs.h"
  121. #include "wgui_categories.h"
  122. #include "CustMenuRes.h"
  123. #include "CommonScreens.h"
  124. #include "Unicodexdcl.h"
  125. #include "TimerEvents.h"
  126. #include "DebugInitDef.h"
  127. #include "ProtocolEvents.h"
  128. #include "ChatAppDef.h"
  129. #include "ChatGtype.h"
  130. #include "ChatAppprot.h"
  131. #include "ChatAppGexdcl.h"
  132. #include "ChatAppGprot.h"
  133. #include "EmsMiscell.h"
  134. #include "MessagesExDcl.h"
  135. #include "MessagesMiscell.h"
  136. #include "SmsGuiInterfaceProt.h"
  137. #include "ProtocolEvents.h"
  138. #include "Gui_ems.h"
  139. #include "wgui_status_icons.h"
  140. #include "MessagesResourceData.h"
  141. #include "IdleAppProt.h"
  142. #include "SettingProfile.h"
  143. #include "gpioInc.h"
  144. #include "Asciiprot.h"
  145. #include "KeyBrd.h"     /* for ClearKeyEvents */
  146. #include "AlarmFrameworkProt.h"
  147. #include "l4dr.h"
  148. #include "customer_ps_inc.h"
  149. #include "mmi_msg_context.h"
  150. #include "SMSApi.h"
  151. #include "SMSStruct.h"
  152. #include "SMSFunc.h"
  153. /****************Static Variable Start*********/
  154. static U16 gCurrScrnNewChatSmsInd = 0;
  155. static S8 gHeader[3 * ENCODING_LENGTH];     /* ={": "}; */
  156. static S8 gInvitation[4 * ENCODING_LENGTH]; /* ={":-)"}; */
  157. static U16 gNewChatMsgScreenToDeleteFromHistory;
  158. static pBOOL gChatMsgIndPresentForKeypadLock;
  159. static U32 gChatInboxIndex;
  160. /****************Static Variable End*********/
  161. /****************Global Variable Start*********/
  162. pBOOL gChatInvitation;
  163. U8 gIsItChatSmsArrivalInd;
  164. U8 gIsThereAnyNewChatSMSToInd;
  165. pBOOL gChatRoomScreenPresent;
  166. /****************Global Variable End*********/
  167. /****************Function Start*********/
  168. /****************Function End*********/
  169. /***********Extern Variable Start*************/
  170. extern chat_context_struct g_chat_cntx;
  171. extern U16 gChatMsgFlag;
  172. extern pBOOL gBlinkChatFlag[MAX_NO_OF_CHAT_ROOM];
  173. extern pBOOL gInputBoxUcs2Flag;
  174. /***********Extern Variable End*************/
  175. extern PS8 lookUpNumber(PS8 number);
  176. extern BOOL GetUCS2Flag(S8 *);
  177. extern EMSData *GetEMSDataForView(EMSData **p, U8 force);
  178. extern EMSData *GetEMSDataForEdit(EMSData **p, U8 force);
  179. extern U8 DeInitMessagesEMSBuffer(msg_ems_data_struct *pE);
  180. extern void GetNewChatMsgIndDisplayString(U8 *number, U8 length, U8 type);
  181. /******************/
  182. /* Handle Chat Header */
  183. /******************/
  184. /*****************************************************************************
  185.  * FUNCTION
  186.  *  InitChatHeader
  187.  * DESCRIPTION
  188.  *  Init chat header string
  189.  * PARAMETERS
  190.  *  void
  191.  * RETURNS
  192.  *  void
  193.  *****************************************************************************/
  194. void InitChatHeader(void)
  195. {
  196.     /*----------------------------------------------------------------*/
  197.     /* Local Variables                                                */
  198.     /*----------------------------------------------------------------*/
  199.     /*----------------------------------------------------------------*/
  200.     /* Code Body                                                      */
  201.     /*----------------------------------------------------------------*/
  202.     AnsiiToUnicodeString((PS8) gHeader, ":");
  203.     AnsiiToUnicodeString((PS8) gInvitation, ":-)");
  204. }
  205. /*****************************************************************************
  206.  * FUNCTION
  207.  *  GetHeader
  208.  * DESCRIPTION
  209.  *  It Gets Header string
  210.  * PARAMETERS
  211.  *  dest        [IN]        
  212.  *  index       [IN]        
  213.  *  Header String and Chat Room Number(?)
  214.  * RETURNS
  215.  *  void
  216.  *****************************************************************************/
  217. void GetHeader(PU8 dest, S16 index)
  218. {
  219.     /*----------------------------------------------------------------*/
  220.     /* Local Variables                                                */
  221.     /*----------------------------------------------------------------*/
  222.     pBOOL flag = FALSE;
  223.     /*----------------------------------------------------------------*/
  224.     /* Code Body                                                      */
  225.     /*----------------------------------------------------------------*/
  226.     if (g_chat_cntx.chatRoomInfo[index].chatRoomCounter == 0)
  227.     {
  228.         pfnUnicodeStrcpy((PS8) dest, gInvitation);
  229.         flag = TRUE;
  230.     }
  231.     if ((pfnUnicodeStrlen((PS8) g_chat_cntx.chatRoomInfo[GetCurrentChatRoomNo()].chatInfo.nickName)) > 0)
  232.     {
  233.         if (flag == TRUE)
  234.         {
  235.             pfnUnicodeStrcat((PS8) dest, g_chat_cntx.chatRoomInfo[index].chatInfo.nickName);
  236.         }
  237.         else
  238.         {
  239.             pfnUnicodeStrcpy((PS8) dest, g_chat_cntx.chatRoomInfo[index].chatInfo.nickName);
  240.         }
  241.         pfnUnicodeStrcat((PS8) dest, gHeader);
  242.     }
  243.     else if (flag == TRUE)
  244.     {
  245.         pfnUnicodeStrcat((PS8) dest, gHeader);
  246.     }
  247.     else
  248.     {
  249.         pfnUnicodeStrcpy((PS8) dest, gHeader);
  250.     }
  251. }
  252. /*****************************************************************************
  253.  * FUNCTION
  254.  *  RemoveHeaderInfo
  255.  * DESCRIPTION
  256.  *  It Removes header info from message
  257.  * PARAMETERS
  258.  *  void
  259.  * RETURNS
  260.  *  void
  261.  *****************************************************************************/
  262. void RemoveHeaderInfo(void)
  263. {
  264.     /*----------------------------------------------------------------*/
  265.     /* Local Variables                                                */
  266.     /*----------------------------------------------------------------*/
  267.     U8 aHeader[(MAX_SMS_CHAT_HEADER_SIZE + 1) * ENCODING_LENGTH];
  268.     S16 nStrLen;
  269.     /*----------------------------------------------------------------*/
  270.     /* Code Body                                                      */
  271.     /*----------------------------------------------------------------*/
  272.     GetHeader(aHeader, GetCurrentChatRoomNo());
  273.     nStrLen = (S16) pfnUnicodeStrlen((PS8) aHeader);
  274.     DeletenCharFromEMSBuffer(nStrLen);
  275. }
  276. /*****************************************************************************
  277.  * FUNCTION
  278.  *  AddHeadertoMessage
  279.  * DESCRIPTION
  280.  *  It adds Message header to Chat Message
  281.  * PARAMETERS
  282.  *  void
  283.  * RETURNS
  284.  *  void
  285.  *****************************************************************************/
  286. void AddHeadertoMessage(void)
  287. {
  288.     /*----------------------------------------------------------------*/
  289.     /* Local Variables                                                */
  290.     /*----------------------------------------------------------------*/
  291.     EMSData *pEms;
  292.     U8 aHeader[(MAX_SMS_CHAT_HEADER_SIZE + 1) * ENCODING_LENGTH];
  293.     S32 nStrLen;
  294.     /*----------------------------------------------------------------*/
  295.     /* Code Body                                                      */
  296.     /*----------------------------------------------------------------*/
  297.     GetEMSDataForEdit(&pEms, 0);
  298.     ResetCurrentPosition(pEms);
  299.     GetHeader(aHeader, GetCurrentChatRoomNo());
  300.     nStrLen = pfnUnicodeStrlen((PS8) aHeader);
  301.     AddString(pEms, aHeader, (U16) (nStrLen * 2), NULL);    /* check length */
  302. }
  303. /*****************************************************************************
  304.  * FUNCTION
  305.  *  CopyToBuffer
  306.  * DESCRIPTION
  307.  *  It Copies Chat Room Data to Chat Buffer
  308.  * PARAMETERS
  309.  *  packet      [?]         
  310.  *  length      [IN]        Chat room Number
  311.  *  index       [IN]        
  312.  *  flag        [IN]        
  313.  * RETURNS
  314.  *  Buffer pointer
  315.  *****************************************************************************/
  316. PU8 CopyToBuffer(U8 packet[], S32 length, S16 index, U8 flag)
  317. {
  318.     /*----------------------------------------------------------------*/
  319.     /* Local Variables                                                */
  320.     /*----------------------------------------------------------------*/
  321.     S8 temp[MAX_DIGITS * ENCODING_LENGTH];
  322.     S8 *name;
  323.     PU8 pointer;
  324.     U32 nLimiter = 0;
  325.     S32 prelength = 0;
  326.     S32 len;
  327.     BOOL noNickname = FALSE;
  328.     /*----------------------------------------------------------------*/
  329.     /* Code Body                                                      */
  330.     /*----------------------------------------------------------------*/
  331.     len = pfnUnicodeStrlen((S8*) gHeader);
  332.     if (length >= len)
  333.     {
  334.         if (pfnUnicodeStrncmp((PS8) packet, gHeader, len) == 0)
  335.         {
  336.             noNickname = TRUE;
  337.         }
  338.     }
  339.     if (noNickname)
  340.     {
  341.         if (flag == SENDING_CHAT)
  342.         {
  343.             pfnUnicodeStrcpy(temp, GetString(CHATROOM_LOCAL_DEFAULT));
  344.         }
  345.         else
  346.         {
  347.             name = lookUpNumber((S8*) g_chat_cntx.chatRoomInfo[index].chatInfo.destinationNo);
  348.             if (pfnUnicodeStrlen(name))
  349.             {
  350.                 pfnUnicodeStrcpy((S8*) temp, name);
  351.             }
  352.             else
  353.             {
  354.                 pfnUnicodeStrcpy((S8*) temp, (S8*) g_chat_cntx.chatRoomInfo[index].chatInfo.destinationNo);
  355.             }
  356.         }
  357.         prelength = (pfnUnicodeStrlen(temp)) * ENCODING_LENGTH;
  358.     }
  359.     pointer = AllocMemory(prelength + length + 2, index);
  360.     if (pointer != NULL)
  361.     {   /* return NULL */
  362.         if (prelength)
  363.         {
  364.             memcpy(pointer, temp, prelength);
  365.         }
  366.         memcpy((pointer + prelength), packet, length);
  367.         memcpy((pointer + prelength + length), &nLimiter, ENCODING_LENGTH);
  368.     }
  369.     return pointer;
  370. }
  371. /*****************************************************************************
  372.  * FUNCTION
  373.  *  DeletenCharFromEMSBuffer
  374.  * DESCRIPTION
  375.  *  It delets chars from EMS buffer
  376.  * PARAMETERS
  377.  *  count       [IN]        
  378.  *  Total number of chars to be deleted(?)
  379.  * RETURNS
  380.  *  void
  381.  *****************************************************************************/
  382. void DeletenCharFromEMSBuffer(S16 count)
  383. {
  384.     /*----------------------------------------------------------------*/
  385.     /* Local Variables                                                */
  386.     /*----------------------------------------------------------------*/
  387.     EMSData *pEms;
  388.     /*----------------------------------------------------------------*/
  389.     /* Code Body                                                      */
  390.     /*----------------------------------------------------------------*/
  391.     GetEMSDataForEdit(&pEms, 0);
  392.     CancelCurrentPosition(pEms, (kal_uint16) (count + 1));
  393.     GoToEndPosition(pEms);
  394. }
  395. /*****************************************************************************
  396.  * FUNCTION
  397.  *  RemoveInvitationChar
  398.  * DESCRIPTION
  399.  *  It removes invitation chars from message
  400.  * PARAMETERS
  401.  *  void
  402.  * RETURNS
  403.  *  void
  404.  *****************************************************************************/
  405. void RemoveInvitationChar(void)
  406. {
  407.     /*----------------------------------------------------------------*/
  408.     /* Local Variables                                                */
  409.     /*----------------------------------------------------------------*/
  410.     EMSData *pEms;
  411.     S16 len = (S16) pfnUnicodeStrlen(gInvitation);
  412.     /*----------------------------------------------------------------*/
  413.     /* Code Body                                                      */
  414.     /*----------------------------------------------------------------*/
  415.     GetEMSDataForView(&pEms, 0);
  416.     ResetCurrentPosition(pEms);
  417.     ForwardCurrentPosition(pEms, len);
  418.     CancelCurrentPosition(pEms, (kal_uint16) (len + 1));
  419. }
  420. /*****************************************************************************
  421.  * FUNCTION
  422.  *  SetChatInboxIndex
  423.  * DESCRIPTION
  424.  *  Sets invition message index from inbox index
  425.  * PARAMETERS
  426.  *  index       [IN]        
  427.  * RETURNS
  428.  *  void
  429.  *****************************************************************************/
  430. void SetChatInboxIndex(U32 index)
  431. {
  432.     /*----------------------------------------------------------------*/
  433.     /* Local Variables                                                */
  434.     /*----------------------------------------------------------------*/
  435.     /*----------------------------------------------------------------*/
  436.     /* Code Body                                                      */
  437.     /*----------------------------------------------------------------*/
  438.     gChatInboxIndex = index;
  439. }
  440. /*****************************************************************************
  441.  * FUNCTION
  442.  *  GetChatInboxIndex
  443.  * DESCRIPTION
  444.  *  It returns index of message
  445.  * PARAMETERS
  446.  *  void
  447.  * RETURNS
  448.  *  chat invitation index
  449.  *****************************************************************************/
  450. U32 GetChatInboxIndex(void)
  451. {
  452.     /*----------------------------------------------------------------*/
  453.     /* Local Variables                                                */
  454.     /*----------------------------------------------------------------*/
  455.     /*----------------------------------------------------------------*/
  456.     /* Code Body                                                      */
  457.     /*----------------------------------------------------------------*/
  458.     return gChatInboxIndex;
  459. }
  460. /*****************/
  461. /* Receive Chat Msg */
  462. /*****************/
  463. /*****************************************************************************
  464.  * FUNCTION
  465.  *  CheckForChatNumber
  466.  * DESCRIPTION
  467.  *  It Checks whether a new message is Chat room message or not
  468.  * PARAMETERS
  469.  *  number      [IN]        number length,type
  470.  *  len         [IN]        
  471.  *  type        [IN]        
  472.  * RETURNS
  473.  *  Status flag[0/1]
  474.  *****************************************************************************/
  475. U16 CheckForChatNumber(PU8 number, U8 len, U8 type)
  476. {
  477.     /*----------------------------------------------------------------*/
  478.     /* Local Variables                                                */
  479.     /*----------------------------------------------------------------*/
  480.     S16 i;
  481.     U8 num1[44];
  482.     /*----------------------------------------------------------------*/
  483.     /* Code Body                                                      */
  484.     /*----------------------------------------------------------------*/
  485.     for (i = 0; i < MAX_NO_OF_CHAT_ROOM; i++)
  486.     {
  487.         UnicodeToAnsii((PS8) num1, (PS8) g_chat_cntx.chatRoomInfo[i].chatInfo.destinationNo);
  488.         num1[42] = '';
  489.         num1[43] = '';
  490.         if ((ComparePhoneNum((PU8) num1, (PU8) number)) && (g_chat_cntx.chatRoomInfo[i].status == MMI_MSG_CHAT_ENABLE))
  491.         {
  492.             SetMessagechatRoomNo(i);
  493.             return 1;
  494.         }
  495.     }
  496.     return 0;
  497. }
  498. /*****************************************************************************
  499.  * FUNCTION
  500.  *  CheckForChatMessage
  501.  * DESCRIPTION
  502.  *  It Checks whether a new message is Chat room message or not
  503.  * PARAMETERS
  504.  *  data            [?]         
  505.  *  withobject      [IN]        
  506.  *  content         [?]         
  507.  *  Destination number,number length,type(?)
  508.  * RETURNS
  509.  *  Status flag[0/1]
  510.  *****************************************************************************/
  511. U8 CheckForChatMessage(void *data, int withobject, void *content)
  512. {
  513.     /*----------------------------------------------------------------*/
  514.     /* Local Variables                                                */
  515.     /*----------------------------------------------------------------*/
  516.     mmi_frm_sms_deliver_msg_struct *msginfo = (mmi_frm_sms_deliver_msg_struct*) data;
  517.     U8 number[MSG_NUM_LEN];
  518.     U8 addrlen = 0;
  519.     U8 type = 0;
  520.     /*----------------------------------------------------------------*/
  521.     /* Code Body                                                      */
  522.     /*----------------------------------------------------------------*/
  523.     /* the message with ems object or smart message should not be treated as a chat message */
  524.     if ((withobject) || (msginfo->dcs == SMSAL_8BIT_DCS))
  525.     {
  526.         return FALSE;
  527.     }
  528.     /* incomplete message is not allowed to be dispatched to chat room */
  529.     if (!mmi_frm_sms_check_awaited_complete_msg(msginfo->msg_data[0]))
  530.     {
  531.         return FALSE;
  532.     }
  533.     memset((S8*) number, 0, MSG_NUM_LEN);
  534.     addrlen = (msginfo->addr_number.length > MSG_NUM_LEN) ? MSG_NUM_LEN : msginfo->addr_number.length;
  535.     if (msginfo->addr_number.type == CSMCC_INTERNATIONAL_ADDR)
  536.     {
  537.         number[0] = '+';
  538.         type = 1;
  539.     }
  540.     memcpy(number + type, msginfo->addr_number.number, addrlen);
  541.     /* chat message will dispatch to chatroom only if the current screen is chatroom or the chatroom screen is in the history */
  542.     if (GetMessagesCurrScrnID() == CHAT_ROOM_SCREEN_ID || IsScreenPresent(CHAT_ROOM_SCREEN_ID))
  543.     {
  544.         /* if (CheckForChatNumber(number, addrlen, type) && CheckForInvitationMsg((U8*)unicodecontent, length, FALSE)) */
  545.         if (CheckForChatNumber(number, addrlen, type))
  546.         {
  547.             if (type == 1)
  548.             {
  549.                 GetNewChatMsgIndDisplayString(number, (U8) (addrlen + 1), type);
  550.             }
  551.             else
  552.             {
  553.                 GetNewChatMsgIndDisplayString(number, addrlen, type);
  554.             }
  555.             return TRUE;
  556.         }
  557.         else
  558.         {
  559.             return FALSE;
  560.         }
  561.     }
  562.     else
  563.     {
  564.         return FALSE;
  565.     }
  566. }
  567. /*****************************************************************************
  568.  * FUNCTION
  569.  *  CheckForInvitationMsg
  570.  * DESCRIPTION
  571.  *  It checks for invitation function
  572.  * PARAMETERS
  573.  *  data        [IN]        length and invitation flag
  574.  *  length      [IN]        
  575.  *  flag        [IN]        
  576.  * RETURNS
  577.  *  Status
  578.  *****************************************************************************/
  579. pBOOL CheckForInvitationMsg(PU8 data, S32 length, pBOOL flag)
  580. {
  581.     /*----------------------------------------------------------------*/
  582.     /* Local Variables                                                */
  583.     /*----------------------------------------------------------------*/
  584.     S32 len;
  585.     /*----------------------------------------------------------------*/
  586.     /* Code Body                                                      */
  587.     /*----------------------------------------------------------------*/
  588.     len = pfnUnicodeStrlen((S8*) gInvitation);
  589.     if (length > 0)
  590.     {
  591.         if (pfnUnicodeStrncmp((PS8) data, gInvitation, len) == 0)
  592.         {
  593.             gChatInvitation = flag;
  594.             return TRUE;
  595.         }
  596.         else
  597.         {
  598.             return FALSE;
  599.         }
  600.     }
  601.     else
  602.     {
  603.         return FALSE;
  604.     }
  605. }
  606. /*****************************************************************************
  607.  * FUNCTION
  608.  *  DeleteInvitationMessage
  609.  * DESCRIPTION
  610.  *  Deletes invitation chars from Chat Invitation message
  611.  * PARAMETERS
  612.  *  void
  613.  * RETURNS
  614.  *  void
  615.  *****************************************************************************/
  616. void DeleteInvitationMessage(void)
  617. {
  618.     /*----------------------------------------------------------------*/
  619.     /* Local Variables                                                */
  620.     /*----------------------------------------------------------------*/
  621.     S16 index = GetCurrentChatRoomNo();
  622.     /*----------------------------------------------------------------*/
  623.     /* Code Body                                                      */
  624.     /*----------------------------------------------------------------*/
  625.     gChatMsgFlag = 1;
  626.     DeleteChatMsg((S32) GetChatInboxIndex());
  627.     gChatInvitation = FALSE;
  628.     g_chat_cntx.chatRoomInfo[index].status = MMI_MSG_CHAT_ENABLE;
  629.     ShowChatStatusIcon(index);
  630. }
  631. /*****************************************************************************
  632.  * FUNCTION
  633.  *  DisplayChatPopUpWindow
  634.  * DESCRIPTION
  635.  *  It Displays Chat Pop Up on idle screen and adds message to Chat room
  636.  * PARAMETERS
  637.  *  void
  638.  * RETURNS
  639.  *  void
  640.  *****************************************************************************/
  641. void DisplayChatPopUpWindow(void)
  642. {
  643.     /*----------------------------------------------------------------*/
  644.     /* Local Variables                                                */
  645.     /*----------------------------------------------------------------*/
  646.     /*----------------------------------------------------------------*/
  647.     /* Code Body                                                      */
  648.     /*----------------------------------------------------------------*/
  649.     gChatMsgIndPresentForKeypadLock = FALSE;
  650.     gIsItChatSmsArrivalInd = TRUE;
  651.     gIsThereAnyNewChatSMSToInd = TRUE;
  652.     PlayMessageArrivalTone();
  653.     TurnOnBacklight(1);
  654.     if (GetMessagesCurrScrnID() == CHAT_ROOM_SCREEN_ID)
  655.     {
  656.         if (GetMessagechatRoomNo() != GetCurrentChatRoomNo())
  657.         {
  658.             BlinkChatIcon(GetMessagechatRoomNo());
  659.         }
  660.     }
  661.     else
  662.     {
  663.         BlinkChatIcon(GetMessagechatRoomNo());
  664.     }
  665.     if (IsMMIInIdleState() || IsNewChatSmsIndScrn())
  666.     {
  667.         ClearKeyEvents();
  668.         MMI_ASSERT(g_idle_context.IsOnIdleScreen != 1 && g_idle_context.ScreenSaverRunFlag != 1);
  669.         MMI_ASSERT(gCurrScrnNewChatSmsInd != SCR_NEWCHATMSGARRIVALNOTIFICATION);
  670.         if ((IsScreenPresent(SCR_NEWCHATMSGARRIVALNOTIFICATION) == TRUE) || IsNewChatSmsIndScrn())
  671.         {
  672.             gNewChatMsgScreenToDeleteFromHistory = 1;
  673.         }
  674.         if (IsKeyPadLockState())
  675.         {
  676.             gChatMsgIndPresentForKeypadLock = TRUE;
  677.             EntryIdleScreen();
  678.         }
  679.         else
  680.         {
  681.             EntryNotifyNewChatMessageArrival();
  682.         }
  683.     }
  684.     else
  685.     {
  686.     #ifdef __MMI_LCD_PARTIAL_ON__
  687.         LeavePartialOnScreenSaverIfOk();
  688.     #endif 
  689.         if (GetMessagesCurrScrnID() == CHAT_ROOM_SCREEN_ID)
  690.         {
  691.             if (GetMessagechatRoomNo() == GetCurrentChatRoomNo())
  692.             {
  693.                 gIsItChatSmsArrivalInd = FALSE;
  694.                 gIsThereAnyNewChatSMSToInd = FALSE;
  695.                 EntryChatRoom();
  696.             }
  697.         }
  698.     }
  699. }
  700. /*****************************************************************************
  701.  * FUNCTION
  702.  *  HandleChatMessage
  703.  * DESCRIPTION
  704.  *  It Displays Chat Pop Up on idle screen and adds message to Chat room
  705.  * PARAMETERS
  706.  *  data        [?]     
  707.  *  content     [?]     
  708.  * RETURNS
  709.  *  void
  710.  *****************************************************************************/
  711. U8 HandleChatMessage(void *data, void *content)
  712. {
  713.     /*----------------------------------------------------------------*/
  714.     /* Local Variables                                                */
  715.     /*----------------------------------------------------------------*/
  716.     /*----------------------------------------------------------------*/
  717.     /* Code Body                                                      */
  718.     /*----------------------------------------------------------------*/
  719.     ModifyChatRoom(GetMessagechatRoomNo(), RECEIVING_CHAT, (void*)data, (S8*) content);
  720.     DisplayChatPopUpWindow();
  721.     return FALSE;
  722. }
  723. /*****************************************************************************
  724.  * FUNCTION
  725.  *  IsNewChatSmsIndScrn
  726.  * DESCRIPTION
  727.  *  Checks wheather new pop Chat message screen is on idle screen or not
  728.  *  Currently no use, but keep for future implementation when idle receiving chat message
  729.  * PARAMETERS
  730.  *  void
  731.  * RETURNS
  732.  *  status[0/1]
  733.  *****************************************************************************/
  734. U16 IsNewChatSmsIndScrn(void)
  735. {
  736.     /*----------------------------------------------------------------*/
  737.     /* Local Variables                                                */
  738.     /*----------------------------------------------------------------*/
  739.     /*----------------------------------------------------------------*/
  740.     /* Code Body                                                      */
  741.     /*----------------------------------------------------------------*/
  742.     return (gCurrScrnNewChatSmsInd == SCR_NEWCHATMSGARRIVALNOTIFICATION) ? 1 : 0;
  743. }
  744. /*****************************************************************************
  745.  * FUNCTION
  746.  *  EntryNotifyNewChatMessageArrival
  747.  * DESCRIPTION
  748.  *  It displays pop up for new Chat message received
  749.  * PARAMETERS
  750.  *  void
  751.  * RETURNS
  752.  *  void
  753.  *****************************************************************************/
  754. void EntryNotifyNewChatMessageArrival(void)
  755. {
  756.     /*----------------------------------------------------------------*/
  757.     /* Local Variables                                                */
  758.     /*----------------------------------------------------------------*/
  759.     /*----------------------------------------------------------------*/
  760.     /* Code Body                                                      */
  761.     /*----------------------------------------------------------------*/
  762.     EntryNewScreen(SCR_NEWCHATMSGARRIVALNOTIFICATION, ExitNotifyNewChatMessageArrival, NULL, NULL);
  763.     if (gNewChatMsgScreenToDeleteFromHistory)
  764.     {
  765.         DeleteNScrId(SCR_NEWCHATMSGARRIVALNOTIFICATION);
  766.     }
  767.     gCurrScrnNewChatSmsInd = SCR_NEWCHATMSGARRIVALNOTIFICATION;
  768.     ShowCategory154Screen(
  769.         CHATROOM_NEW_MSG_RCVD,
  770.         CHAT_IMAGE_APP_ID,
  771.         STR_GLOBAL_CHAT,
  772.         IMG_GLOBAL_OK,
  773.         STR_GLOBAL_BACK,
  774.         IMG_GLOBAL_OK,
  775.         (PU8) GetString(STR_CHAT_FROM),
  776.         (PU8) GetNewChatSmsIndDisplayStr(),
  777.         IMG_NEW_MESSAGE_NOTIFICATION_MSG,
  778.         NULL);
  779.     SetRightSoftkeyFunction(GoBackHistoryFromNewChatMessageScreen, KEY_EVENT_UP);
  780.     SetLeftSoftkeyFunction(NotifymessageLeftSoftKeyFunction, KEY_EVENT_UP);
  781.     SetKeyHandler(GoBackHistoryFromNewChatMessageScreenForEndKey, KEY_END, KEY_EVENT_DOWN);
  782. }
  783. /*****************************************************************************
  784.  * FUNCTION
  785.  *  ExitNotifyNewChatMessageArrival
  786.  * DESCRIPTION
  787.  *  Exit screen of new message arrival
  788.  * PARAMETERS
  789.  *  void
  790.  * RETURNS
  791.  *  void
  792.  *****************************************************************************/
  793. void ExitNotifyNewChatMessageArrival(void)
  794. {
  795.     /*----------------------------------------------------------------*/
  796.     /* Local Variables                                                */
  797.     /*----------------------------------------------------------------*/
  798.     /*----------------------------------------------------------------*/
  799.     /* Code Body                                                      */
  800.     /*----------------------------------------------------------------*/
  801.     gCurrScrnNewChatSmsInd = 0;
  802. }
  803. /*****************************************************************************
  804.  * FUNCTION
  805.  *  GoBackHistoryFromNewChatMessageScreen
  806.  * DESCRIPTION
  807.  *  Wrapper function for Calling GoBackHistory function
  808.  * PARAMETERS
  809.  *  void
  810.  * RETURNS
  811.  *  void
  812.  *****************************************************************************/
  813. void GoBackHistoryFromNewChatMessageScreen(void)
  814. {
  815.     /*----------------------------------------------------------------*/
  816.     /* Local Variables                                                */
  817.     /*----------------------------------------------------------------*/
  818.     /*----------------------------------------------------------------*/
  819.     /* Code Body                                                      */
  820.     /*----------------------------------------------------------------*/
  821.     gCurrScrnNewChatSmsInd = 0;
  822.     gIsItChatSmsArrivalInd = FALSE;
  823.     gIsThereAnyNewChatSMSToInd = FALSE;
  824.     GoBackHistory();
  825. }
  826. /*****************************************************************************
  827.  * FUNCTION
  828.  *  NotifymessageLeftSoftKeyFunction
  829.  * DESCRIPTION
  830.  *  Goes to Chat room from Idle screen when Chat is selected
  831.  * PARAMETERS
  832.  *  void
  833.  * RETURNS
  834.  *  void
  835.  *****************************************************************************/
  836. void NotifymessageLeftSoftKeyFunction(void)
  837. {
  838.     /*----------------------------------------------------------------*/
  839.     /* Local Variables                                                */
  840.     /*----------------------------------------------------------------*/
  841.     /*----------------------------------------------------------------*/
  842.     /* Code Body                                                      */
  843.     /*----------------------------------------------------------------*/
  844.     gIsThereAnyNewChatSMSToInd = FALSE;
  845.     SetCurrentChatRoomNo(GetMessagechatRoomNo());
  846.     EntryChatRoom();
  847. }
  848. /*****************************************************************************
  849.  * FUNCTION
  850.  *  GoBackHistoryFromNewChatMessageScreenForEndKey
  851.  * DESCRIPTION
  852.  *  Wrapper function for calling EndKey functionality
  853.  * PARAMETERS
  854.  *  void
  855.  * RETURNS
  856.  *  void
  857.  *****************************************************************************/
  858. void GoBackHistoryFromNewChatMessageScreenForEndKey(void)
  859. {
  860.     /*----------------------------------------------------------------*/
  861.     /* Local Variables                                                */
  862.     /*----------------------------------------------------------------*/
  863.     /*----------------------------------------------------------------*/
  864.     /* Code Body                                                      */
  865.     /*----------------------------------------------------------------*/
  866.     gNewChatMsgScreenToDeleteFromHistory = 0;
  867.     gIsThereAnyNewChatSMSToInd = FALSE;
  868.     DisplayIdleScreen();
  869. }
  870. /*****************************************************************************
  871.  * FUNCTION
  872.  *  IsThereAnyNewChatMessage
  873.  * DESCRIPTION
  874.  *  Returns whether there is new Chat message or not
  875.  * PARAMETERS
  876.  *  void
  877.  * RETURNS
  878.  *  status
  879.  *****************************************************************************/
  880. U8 IsThereAnyNewChatMessage(void)
  881. {
  882.     /*----------------------------------------------------------------*/
  883.     /* Local Variables                                                */
  884.     /*----------------------------------------------------------------*/
  885.     /*----------------------------------------------------------------*/
  886.     /* Code Body                                                      */
  887.     /*----------------------------------------------------------------*/
  888.     return gIsThereAnyNewChatSMSToInd;
  889. }
  890. /*****************************************************************************
  891.  * FUNCTION
  892.  *  NewChatMsgIndPresentForKeypadLock
  893.  * DESCRIPTION
  894.  *  It returns Keypad state when new Chat Messsage arrives
  895.  * PARAMETERS
  896.  *  void
  897.  * RETURNS
  898.  *  status
  899.  *****************************************************************************/
  900. pBOOL NewChatMsgIndPresentForKeypadLock(void)
  901. {
  902.     /*----------------------------------------------------------------*/
  903.     /* Local Variables                                                */
  904.     /*----------------------------------------------------------------*/
  905.     /*----------------------------------------------------------------*/
  906.     /* Code Body                                                      */
  907.     /*----------------------------------------------------------------*/
  908.     return gChatMsgIndPresentForKeypadLock;
  909. }
  910. /*****************************************************************************
  911.  * FUNCTION
  912.  *  DisplayNewChatMsgINDAfterKeypadUnlocked
  913.  * DESCRIPTION
  914.  *  It Sets flag for new chat message when keypad is unlocked
  915.  * PARAMETERS
  916.  *  void
  917.  * RETURNS
  918.  *  void
  919.  *****************************************************************************/
  920. void DisplayNewChatMsgINDAfterKeypadUnlocked(void)
  921. {
  922.     /*----------------------------------------------------------------*/
  923.     /* Local Variables                                                */
  924.     /*----------------------------------------------------------------*/
  925.     /*----------------------------------------------------------------*/
  926.     /* Code Body                                                      */
  927.     /*----------------------------------------------------------------*/
  928.     gChatMsgIndPresentForKeypadLock = FALSE;
  929.     EntryNotifyNewChatMessageArrival();
  930. }
  931. /*****************************************************************************
  932.  * FUNCTION
  933.  *  ModifyChatRoom
  934.  * DESCRIPTION
  935.  *  It modifies Chat room upon arrival of new message and deletes from Inbox
  936.  * PARAMETERS
  937.  *  index       [IN]        
  938.  *  flag        [IN]        
  939.  *  data        [?]         
  940.  *  content     [?]         
  941.  * RETURNS
  942.  *  status
  943.  *****************************************************************************/
  944. pBOOL ModifyChatRoom(U16 index, U8 flag, void *data, S8 *content)
  945. {
  946.     /*----------------------------------------------------------------*/
  947.     /* Local Variables                                                */
  948.     /*----------------------------------------------------------------*/
  949.     mmi_frm_sms_deliver_msg_struct *msgentry = (mmi_frm_sms_deliver_msg_struct*) data;
  950.     //U16 length = msgentry->no_msg_data; /* it is not the actual length of the data, ex. the length of 706B is 2, not 1 */
  951.     S16 len = 0;
  952.     S8 *unicodecontent = NULL;
  953.     PU8 point = NULL;
  954.     /*----------------------------------------------------------------*/
  955.     /* Code Body                                                      */
  956.     /*----------------------------------------------------------------*/
  957.     /* content might be unicode or ascii, convert it to unicode and store it to unicodecontent */
  958.     if (msgentry->dcs == SMSAL_UCS2_DCS)
  959.     {
  960.         len = (S16) pfnUnicodeStrlen(content);
  961.         unicodecontent = OslMalloc((len + 1) * 2);
  962.         memcpy(unicodecontent, content, len * 2);
  963.         memset(unicodecontent + len * 2, 0, 2);
  964.     }
  965.     else
  966.     {
  967.         len = strlen(content);
  968.         unicodecontent = OslMalloc((len + 1) * 2);
  969.         AnsiiNToUnicodeString(unicodecontent, content, len);
  970.         memset(unicodecontent + len * 2, 0, 2);
  971.     }
  972.     if (CheckForInvitationMsg((U8*) unicodecontent, len, FALSE))
  973.     {
  974.         S32 invitation_len = (S32)pfnUnicodeStrlen(gInvitation);
  975.         memcpy((S8*) unicodecontent, (S8*) unicodecontent + invitation_len * 2, (len - invitation_len) * 2);
  976.         memset((S8*) unicodecontent + (len - invitation_len) * 2, 0, invitation_len * 2);
  977.     }
  978.     IncrementCounter(index);
  979.     point = CopyToBuffer((U8*) unicodecontent, (S32) pfnUnicodeStrlen(unicodecontent) * 2, index, flag);
  980.     if (point == NULL)
  981.     {
  982.         DisplayPopup((PU8) GetString(CHATROOM_STORAGE_FULL_ERROR), IMG_GLOBAL_ERROR, FALSE, 2000, ERROR_TONE);
  983.         gChatMsgFlag = 0;
  984.     }
  985.     else
  986.     {
  987.         g_chat_cntx.chatRoomInfo[index].chatStrings[GetNumOfMessage(index) - 1].chat_message_string = point;
  988.         g_chat_cntx.chatRoomInfo[index].chatStrings[GetNumOfMessage(index) - 1].flag = flag;
  989.         mmi_frm_sms_delete_sms(NULL, MOD_MMI, MMI_FRM_SMS_APP_AWAITS, msgentry->index);
  990.     }
  991.     /* free unicodecontent buffer */
  992.     if (unicodecontent != NULL)
  993.     {
  994.         OslMfree(unicodecontent);
  995.         unicodecontent = NULL;
  996.     }
  997.     return TRUE;
  998. }
  999. /*****************************************************************************
  1000.  * FUNCTION
  1001.  *  UpdateChatRoom
  1002.  * DESCRIPTION
  1003.  *  It updates Chat room upon arrival of new message
  1004.  * PARAMETERS
  1005.  *  index       [IN]        
  1006.  *  flag        [IN]        
  1007.  * RETURNS
  1008.  *  status
  1009.  *****************************************************************************/
  1010. pBOOL UpdateChatRoom(U16 index, U8 flag)
  1011. {
  1012.     /*----------------------------------------------------------------*/
  1013.     /* Local Variables                                                */
  1014.     /*----------------------------------------------------------------*/
  1015.     EMSData *pEms;
  1016.     PU8 point = NULL;
  1017.     /*----------------------------------------------------------------*/
  1018.     /* Code Body                                                      */
  1019.     /*----------------------------------------------------------------*/
  1020.     if (flag == SENDING_CHAT)
  1021.     {
  1022.         GetEMSDataForEdit(&pEms, 0);
  1023.         if ((CheckForInvitationMsg(pEms->textBuffer, pEms->textLength, FALSE)))
  1024.         {
  1025.             S16 len = (S16) pfnUnicodeStrlen(gInvitation);
  1026.             ResetCurrentPosition(pEms);
  1027.             ForwardCurrentPosition(pEms, len);
  1028.             DeletenCharFromEMSBuffer(len);
  1029.         }
  1030.     }
  1031.     else
  1032.     {
  1033.         GetEMSDataForView(&pEms, 0);
  1034.     }
  1035.     if (pEms->listHead == NULL)
  1036.     {
  1037.         IncrementCounter(index);
  1038.         point = CopyToBuffer(pEms->textBuffer, (S32) pEms->textLength, index, flag);
  1039.         if (point == NULL)
  1040.         {
  1041.             DisplayPopup((PU8) GetString(CHATROOM_STORAGE_FULL_ERROR), IMG_GLOBAL_ERROR, FALSE, 2000, ERROR_TONE);
  1042.             return FALSE;
  1043.         }
  1044.         g_chat_cntx.chatRoomInfo[index].chatStrings[GetNumOfMessage(index) - 1].chat_message_string = point;
  1045.         g_chat_cntx.chatRoomInfo[index].chatStrings[GetNumOfMessage(index) - 1].flag = flag;
  1046.         return TRUE;
  1047.     }
  1048.     return TRUE;
  1049. }
  1050. /**************/
  1051. /* Send Chat Msg */
  1052. /**************/
  1053. S8 *chatbuff;
  1054. /*****************************************************************************
  1055.  * FUNCTION
  1056.  *  CallbackChatMsg
  1057.  * DESCRIPTION
  1058.  *  
  1059.  * PARAMETERS
  1060.  *  dummy       [?]         
  1061.  *  mod         [IN]        
  1062.  *  result      [IN]        
  1063.  * RETURNS
  1064.  *  void
  1065.  *****************************************************************************/
  1066. void CallbackChatMsg(void *dummy, module_type mod, U16 result)
  1067. {
  1068.     /*----------------------------------------------------------------*/
  1069.     /* Local Variables                                                */
  1070.     /*----------------------------------------------------------------*/
  1071.     /*----------------------------------------------------------------*/
  1072.     /* Code Body                                                      */
  1073.     /*----------------------------------------------------------------*/
  1074.     switch (result)
  1075.     {
  1076.         case MMI_FRM_SMS_OK:
  1077.             DisplayPopup(
  1078.                 (PU8) GetString(STR_SMS_SEND_SUCCESS),
  1079.                 IMG_SEND_SUCCESS_PIC_MSG,
  1080.                 1,
  1081.                 MESSAGES_POPUP_TIME_OUT,
  1082.                 (U8) SUCCESS_TONE);
  1083.             mmi_frm_sms_delete_screen_history();
  1084.             OnSMSChatSendSuccess();
  1085.             break;
  1086.         case MMI_FRM_SMS_ABORT:
  1087.             /* do not keep chat content when sending fail */
  1088.             ReleaseEMSEditBuffer();
  1089.             DisplayPopup(
  1090.                 (PU8) GetString(STR_ABORT_SENDING_SMS),
  1091.                 IMG_GLOBAL_ACTIVATED,
  1092.                 1,
  1093.                 MESSAGES_POPUP_TIME_OUT,
  1094.                 (U8) SUCCESS_TONE);
  1095.             mmi_frm_sms_delete_screen_history();
  1096.             OnSMSChatSendAbort();
  1097.             break;
  1098.         case MMI_FRM_SMS_NOTREADY:
  1099.             DisplayPopup(
  1100.                 (PU8) GetString(STR_SMS_MSG_NOT_READY_YET),
  1101.                 IMG_SEND_FAIL_PIC_MSG,
  1102.                 1,
  1103.                 MESSAGES_POPUP_TIME_OUT,
  1104.                 (U8) ERROR_TONE);
  1105.             break;
  1106.         default:
  1107.             /* do not keep chat content when sending fail */
  1108.             ReleaseEMSEditBuffer();
  1109.             DisplayPopup(
  1110.                 (PU8) GetString(STR_SMS_SEND_FAILED),
  1111.                 IMG_SEND_FAIL_PIC_MSG,
  1112.                 1,
  1113.                 MESSAGES_POPUP_TIME_OUT,
  1114.                 (U8) ERROR_TONE);
  1115.             mmi_frm_sms_delete_screen_history();
  1116.             OnSMSChatSendFailure();
  1117.             break;
  1118.     }
  1119.     if (chatbuff != NULL)
  1120.     {
  1121.         OslMfree(chatbuff);
  1122.         chatbuff = NULL;
  1123.     }
  1124. }
  1125. /*****************************************************************************
  1126.  * FUNCTION
  1127.  *  SendChatMsg
  1128.  * DESCRIPTION
  1129.  *  It sends chat message
  1130.  * PARAMETERS
  1131.  *  void
  1132.  * RETURNS
  1133.  *  void
  1134.  *****************************************************************************/
  1135. void SendChatMsg(void)
  1136. {
  1137. #if (defined(__MMI_SMART_MESSAGE_MO__) && !defined(__MMI_MESSAGES_EMS__))
  1138.     /*----------------------------------------------------------------*/
  1139.     /* Local Variables                                                */
  1140.     /*----------------------------------------------------------------*/
  1141.     mmi_frm_sms_send_struct *sendData = OslMalloc(sizeof(mmi_frm_sms_send_struct));
  1142.     U8 aHeader[(MAX_SMS_CHAT_HEADER_SIZE + 1) * ENCODING_LENGTH];
  1143.     U16 buffLen;
  1144.     U16 writeChatBufferCharNum;
  1145.     BOOL isUcs2Char = 0;
  1146.     /*----------------------------------------------------------------*/
  1147.     /* Code Body                                                      */
  1148.     /*----------------------------------------------------------------*/
  1149.     writeChatBufferCharNum = pfnUnicodeStrlen((PS8) g_chat_cntx.writeChatBuffer);
  1150.     isUcs2Char = mmi_frm_sms_check_UCS2((U16*) g_chat_cntx.writeChatBuffer, writeChatBufferCharNum);
  1151.     memset((S8*) sendData, 0, sizeof(mmi_frm_sms_send_struct));
  1152.     if (GetUCS2Flag(g_chat_cntx.chatRoomInfo[GetCurrentChatRoomNo()].chatInfo.nickName) || gInputBoxUcs2Flag ||
  1153.         isUcs2Char)
  1154.     {
  1155.         sendData->dcs = SMSAL_UCS2_DCS;
  1156.     }
  1157.     else
  1158.     {
  1159.         sendData->dcs = SMSAL_DEFAULT_DCS;
  1160.     }
  1161.     UnicodeToAnsii(
  1162.         (S8*) sendData->number,
  1163.         (S8*) g_chat_cntx.chatRoomInfo[GetCurrentChatRoomNo()].chatInfo.destinationNo);
  1164.     GetHeader(aHeader, GetCurrentChatRoomNo());
  1165.     sendData->stringlength = pfnUnicodeStrlen((PS8) aHeader) + pfnUnicodeStrlen((PS8) g_chat_cntx.writeChatBuffer);
  1166.     /* MMI could only allocate 2K control buffer, so limit the max allocate buffer to 1600 here */
  1167.     buffLen =
  1168.         (((sendData->stringlength + 1) * 2) <
  1169.          (MMI_FRM_SMS_MSG_LEN * 10)) ? ((sendData->stringlength + 1) * 2) : (MMI_FRM_SMS_MSG_LEN * 10);
  1170.     chatbuff = OslMalloc(buffLen);
  1171.     memset(chatbuff, 0, buffLen);
  1172.     pfnUnicodeStrcpy(chatbuff, (S8*) aHeader);
  1173.     pfnUnicodeStrcat(chatbuff, (S8*) g_chat_cntx.writeChatBuffer);
  1174.     sendData->string = OslMalloc(buffLen);
  1175.     memset(sendData->string, 0, buffLen);
  1176.     memcpy(sendData->string, chatbuff, buffLen);
  1177.     DeleteScreenIfPresent(CHAT_OPTION_SCREEN_ID_2);
  1178.     mmi_frm_sms_send_sms(CallbackChatMsg, MOD_MMI, sendData);
  1179.     OslMfree(sendData);
  1180. #else /* (defined(__MMI_SMART_MESSAGE_MO__) && !defined(__MMI_MESSAGES_EMS__)) */ 
  1181.     mmi_frm_sms_send_struct *sendData = OslMalloc(sizeof(mmi_frm_sms_send_struct));
  1182.     U8 aHeader[(MAX_SMS_CHAT_HEADER_SIZE + 1) * ENCODING_LENGTH];
  1183.     U16 buffLen;
  1184.     U8 *handledBuffer = NULL;
  1185.     U8 *handledHeaderBuffer = NULL;
  1186.     U16 writeChatBufferCharNum;
  1187.     U16 headerCharNum;
  1188.     BOOL isUcs2Char = 0;
  1189.     memset((S8*) sendData, 0, sizeof(mmi_frm_sms_send_struct));
  1190.     writeChatBufferCharNum = pfnUnicodeStrlen((PS8) g_chat_cntx.writeChatBuffer);
  1191.     isUcs2Char = mmi_frm_sms_check_UCS2((U16*) g_chat_cntx.writeChatBuffer, writeChatBufferCharNum);
  1192.     if (GetUCS2Flag(g_chat_cntx.chatRoomInfo[GetCurrentChatRoomNo()].chatInfo.nickName) || gInputBoxUcs2Flag ||
  1193.         isUcs2Char)
  1194.     {
  1195.         sendData->dcs = SMSAL_UCS2_DCS;
  1196.     }
  1197.     else
  1198.     {
  1199.         sendData->dcs = SMSAL_DEFAULT_DCS;
  1200.     }
  1201.     UnicodeToAnsii(
  1202.         (S8*) sendData->number,
  1203.         (S8*) g_chat_cntx.chatRoomInfo[GetCurrentChatRoomNo()].chatInfo.destinationNo);
  1204.     GetHeader(aHeader, GetCurrentChatRoomNo());
  1205.     headerCharNum = pfnUnicodeStrlen((PS8) aHeader);
  1206.     if (sendData->dcs == SMSAL_DEFAULT_DCS)
  1207.     {
  1208.         handledHeaderBuffer = OslMalloc((headerCharNum * 2 + 1) * ENCODING_LENGTH);
  1209.         memset((S8*) handledHeaderBuffer, 0, ((headerCharNum * 2 + 1) * ENCODING_LENGTH));
  1210.         mmi_frm_sms_handle_extension_char((U16*) handledHeaderBuffer, (U16*) aHeader, headerCharNum);
  1211.         handledBuffer = OslMalloc((writeChatBufferCharNum * 2 + 1) * ENCODING_LENGTH);
  1212.         memset((S8*) handledBuffer, 0, ((writeChatBufferCharNum * 2 + 1) * ENCODING_LENGTH));
  1213.         mmi_frm_sms_handle_extension_char(
  1214.             (U16*) handledBuffer,
  1215.             (U16*) g_chat_cntx.writeChatBuffer,
  1216.             writeChatBufferCharNum);
  1217.     }
  1218.     else
  1219.     {
  1220.         handledHeaderBuffer = OslMalloc((headerCharNum + 1) * ENCODING_LENGTH);
  1221.         memset((S8*) handledHeaderBuffer, 0, ((headerCharNum + 1) * ENCODING_LENGTH));
  1222.         memcpy((S8*) handledHeaderBuffer, (S8*) aHeader, headerCharNum * ENCODING_LENGTH);
  1223.         handledBuffer = OslMalloc((writeChatBufferCharNum + 1) * ENCODING_LENGTH);
  1224.         memset((S8*) handledBuffer, 0, ((writeChatBufferCharNum + 1) * ENCODING_LENGTH));
  1225.         memcpy((S8*) handledBuffer, (S8*) g_chat_cntx.writeChatBuffer, writeChatBufferCharNum * ENCODING_LENGTH);
  1226.     }
  1227.     sendData->stringlength = pfnUnicodeStrlen((PS8) handledHeaderBuffer) + pfnUnicodeStrlen((PS8) handledBuffer);
  1228.     /* MMI could only allocate 2K control buffer, so limit the max allocate buffer to 1600 here */
  1229.     buffLen =
  1230.         (((sendData->stringlength + 1) * 2) <
  1231.          (MMI_FRM_SMS_MSG_LEN * 10)) ? ((sendData->stringlength + 1) * 2) : (MMI_FRM_SMS_MSG_LEN * 10);
  1232.     chatbuff = OslMalloc(buffLen);
  1233.     memset(chatbuff, 0, buffLen);
  1234.     pfnUnicodeStrcpy(chatbuff, (S8*) handledHeaderBuffer);
  1235.     pfnUnicodeStrcat(chatbuff, (S8*) handledBuffer);
  1236.     sendData->string = OslMalloc(buffLen);
  1237.     memset(sendData->string, 0, buffLen);
  1238.     memcpy(sendData->string, chatbuff, buffLen);
  1239.     if (chatbuff != NULL)
  1240.     {
  1241.         OslMfree(chatbuff);
  1242.         chatbuff = NULL;
  1243.     }
  1244.     buffLen = ((pfnUnicodeStrlen((PS8) aHeader) + writeChatBufferCharNum) + 1) * 2;
  1245.     buffLen = ((buffLen) < (MMI_FRM_SMS_MSG_LEN * 10)) ? (buffLen) : (MMI_FRM_SMS_MSG_LEN * 10);
  1246.     chatbuff = OslMalloc(buffLen);
  1247.     memset(chatbuff, 0, buffLen);
  1248.     pfnUnicodeStrcpy(chatbuff, (S8*) aHeader);
  1249.     pfnUnicodeStrcat(chatbuff, (S8*) g_chat_cntx.writeChatBuffer);
  1250.     DeleteScreenIfPresent(CHAT_OPTION_SCREEN_ID_2);
  1251.     mmi_frm_sms_send_sms(CallbackChatMsg, MOD_MMI, sendData);
  1252.     OslMfree(sendData);
  1253.     OslMfree(handledBuffer);
  1254.     OslMfree(handledHeaderBuffer);
  1255. #endif /* (defined(__MMI_SMART_MESSAGE_MO__) && !defined(__MMI_MESSAGES_EMS__)) */ 
  1256. }
  1257. /*****************************************************************************
  1258.  * FUNCTION
  1259.  *  PreSendChatMsg
  1260.  * DESCRIPTION
  1261.  *  Before send chat message, check DCS and SC number
  1262.  * PARAMETERS
  1263.  *  void
  1264.  * RETURNS
  1265.  *  void
  1266.  *****************************************************************************/
  1267. void PreSendChatMsg(void)
  1268. {
  1269.     /*----------------------------------------------------------------*/
  1270.     /* Local Variables                                                */
  1271.     /*----------------------------------------------------------------*/
  1272.     /*----------------------------------------------------------------*/
  1273.     /* Code Body                                                      */
  1274.     /*----------------------------------------------------------------*/
  1275.     /* disallow re-entering SMS application when there is a pending SMS job running in the background */
  1276.     if (mmi_frm_sms_check_action_pending())
  1277.     {
  1278.         DisplayPopup(
  1279.             (PU8) GetString(STR_SMS_MSG_NOT_READY_YET),
  1280.             IMG_GLOBAL_UNFINISHED,
  1281.             1,
  1282.             MESSAGES_POPUP_TIME_OUT,
  1283.             (U8) ERROR_TONE);
  1284.         return;
  1285.     }
  1286.     if (!IsScreenPresent(CHAT_SCREEN_START_NEW_ID))
  1287.     {
  1288.         ExitChatWrite();
  1289.     }
  1290.     SendChatMsg();
  1291. }
  1292. /*****************************************************************************
  1293.  * FUNCTION
  1294.  *  OnSMSChatSendAbort
  1295.  * DESCRIPTION
  1296.  *  It delets Screen from history upon abort of Message send
  1297.  * PARAMETERS
  1298.  *  void
  1299.  * RETURNS
  1300.  *  void
  1301.  *****************************************************************************/
  1302. void OnSMSChatSendAbort(void)
  1303. {
  1304.     /*----------------------------------------------------------------*/
  1305.     /* Local Variables                                                */
  1306.     /*----------------------------------------------------------------*/
  1307.     /*----------------------------------------------------------------*/
  1308.     /* Code Body                                                      */
  1309.     /*----------------------------------------------------------------*/
  1310.     RemoveHeaderInfo();
  1311.     DeleteScreenIfPresent(CHAT_OPTION_SCREEN_ID);
  1312. }
  1313. /*****************************************************************************
  1314.  * FUNCTION
  1315.  *  OnSMSChatSendFailure
  1316.  * DESCRIPTION
  1317.  *  It delets Screen from history upon failure of Message send
  1318.  * PARAMETERS
  1319.  *  void
  1320.  * RETURNS
  1321.  *  void
  1322.  *****************************************************************************/
  1323. void OnSMSChatSendFailure(void)
  1324. {
  1325.     /*----------------------------------------------------------------*/
  1326.     /* Local Variables                                                */
  1327.     /*----------------------------------------------------------------*/
  1328.     /*----------------------------------------------------------------*/
  1329.     /* Code Body                                                      */
  1330.     /*----------------------------------------------------------------*/
  1331.     DeleteScreenIfPresent(CHAT_SCREEN_START_NEW_ID);
  1332.     DeleteScreenIfPresent(CHAT_OPTION_SCREEN_ID);
  1333.     gInputBoxUcs2Flag = 0;
  1334.     memset(g_chat_cntx.writeChatBuffer, 0, ((MAX_MSG_SIZE + 1) * ENCODING_LENGTH));
  1335. }
  1336. /*****************************************************************************
  1337.  * FUNCTION
  1338.  *  OnSMSChatSendSuccess
  1339.  * DESCRIPTION
  1340.  *  It delets Screen from history upon success of Message send
  1341.  * PARAMETERS
  1342.  *  void
  1343.  * RETURNS
  1344.  *  void
  1345.  *****************************************************************************/
  1346. void OnSMSChatSendSuccess(void)
  1347. {
  1348.     /*----------------------------------------------------------------*/
  1349.     /* Local Variables                                                */
  1350.     /*----------------------------------------------------------------*/
  1351.     S16 index = GetCurrentChatRoomNo();
  1352.     PU8 point = NULL;
  1353.     /*----------------------------------------------------------------*/
  1354.     /* Code Body                                                      */
  1355.     /*----------------------------------------------------------------*/
  1356.     if (IsScreenPresent(CHAT_ROOM_SCREEN_ID))
  1357.     {
  1358.         HistoryReplace(CHAT_ROOM_SCREEN_ID, CHAT_ROOM_SCREEN_ID, EntryChatRoom);
  1359.     }
  1360.     else if (IsScreenPresent(CHAT_SCREEN_START_NEW_ID))
  1361.     {
  1362.         HistoryReplace(CHAT_SCREEN_START_NEW_ID, CHAT_ROOM_SCREEN_ID, EntryChatRoom);
  1363.     }
  1364.     DeleteScreenIfPresent(CHAT_SCREEN_START_NEW_ID);
  1365.     DeleteScreenIfPresent(CHAT_OPTION_SCREEN_ID);
  1366.     if ((g_chat_cntx.chatRoomInfo[index].status == MMI_MSG_CHAT_DISABLE))
  1367.     {
  1368.         ActivateChatRoom(GetCurrentChatRoomNo());
  1369.     }
  1370.     gInputBoxUcs2Flag = 0;
  1371.     memset(g_chat_cntx.writeChatBuffer, 0, ((MAX_MSG_SIZE + 1) * ENCODING_LENGTH));
  1372.     IncrementCounter(index);
  1373.     if (CheckForInvitationMsg((U8*) chatbuff, pfnUnicodeStrlen(chatbuff) * 2, FALSE))
  1374.     {
  1375.         S16 len = (S16) pfnUnicodeStrlen(gInvitation);
  1376.         memcpy((S8*) chatbuff, (S8*) chatbuff + len * 2, pfnUnicodeStrlen(chatbuff) * 2 - len * 2);
  1377.         memset((S8*) chatbuff + pfnUnicodeStrlen(chatbuff) * 2 - len * 2, 0, len * 2);
  1378.     }
  1379.     point = CopyToBuffer((U8*) chatbuff, pfnUnicodeStrlen(chatbuff) * 2, index, SENDING_CHAT);
  1380.     if (point == NULL)
  1381.     {
  1382.         DisplayPopup((PU8) GetString(CHATROOM_STORAGE_FULL_ERROR), IMG_GLOBAL_ERROR, FALSE, 2000, ERROR_TONE);
  1383.         return;
  1384.     }
  1385.     g_chat_cntx.chatRoomInfo[index].chatStrings[GetNumOfMessage(index) - 1].chat_message_string = point;
  1386.     g_chat_cntx.chatRoomInfo[index].chatStrings[GetNumOfMessage(index) - 1].flag = SENDING_CHAT;
  1387. }
  1388. /*****************************************************************************
  1389.  * FUNCTION
  1390.  *  CallbackSaveChatMsg
  1391.  * DESCRIPTION
  1392.  *  
  1393.  * PARAMETERS
  1394.  *  status      [?]         
  1395.  *  mod         [IN]        
  1396.  *  result      [IN]        
  1397.  * RETURNS
  1398.  *  void
  1399.  *****************************************************************************/
  1400. void CallbackSaveChatMsg(void *status, module_type mod, U16 result)
  1401. {
  1402.     /*----------------------------------------------------------------*/
  1403.     /* Local Variables                                                */
  1404.     /*----------------------------------------------------------------*/
  1405.     U8 sendresult = *(U8*) status;
  1406.     /*----------------------------------------------------------------*/
  1407.     /* Code Body                                                      */
  1408.     /*----------------------------------------------------------------*/
  1409.     switch (result)
  1410.     {
  1411.         case MMI_FRM_SMS_OK:
  1412.             if (sendresult == SMSAL_STO_UNSENT)
  1413.             {
  1414.                 DisplayPopup(
  1415.                     (PU8) GetString(STR_SMS_SEND_FAILED_SAVE_SUCCESS),
  1416.                     IMG_GLOBAL_ACTIVATED,
  1417.                     1,
  1418.                     MESSAGES_POPUP_TIME_OUT,
  1419.                     (U8) SUCCESS_TONE);
  1420.             }
  1421.             else
  1422.             {
  1423.                 DisplayPopup(
  1424.                     (PU8) GetString(STR_SMS_SEND_SAVE_SUCESS),
  1425.                     IMG_GLOBAL_ACTIVATED,
  1426.                     1,
  1427.                     MESSAGES_POPUP_TIME_OUT,
  1428.                     (U8) SUCCESS_TONE);
  1429.             }
  1430.             break;
  1431.         case MMI_FRM_SMS_MEMFULL:
  1432.             if (sendresult == SMSAL_STO_UNSENT)
  1433.             {
  1434.                 DisplayPopup(
  1435.                     (PU8) GetString(STR_SMS_SEND_SAVE_FAILED),
  1436.                     IMG_GLOBAL_UNFINISHED,
  1437.                     1,
  1438.                     MESSAGES_POPUP_TIME_OUT,
  1439.                     (U8) SUCCESS_TONE);
  1440.             }
  1441.             else
  1442.             {
  1443.                 DisplayPopup(
  1444.                     (PU8) GetString(STR_SMS_SEND_SUCESS_SAVE_FILED),
  1445.                     IMG_GLOBAL_ACTIVATED,
  1446.                     1,
  1447.                     MESSAGES_POPUP_TIME_OUT,
  1448.                     (U8) SUCCESS_TONE);
  1449.             }
  1450.             break;
  1451.         default:
  1452.             DisplayPopup(
  1453.                 (PU8) GetString(STR_SMS_SEND_SAVE_FAILED),
  1454.                 IMG_GLOBAL_UNFINISHED,
  1455.                 1,
  1456.                 MESSAGES_POPUP_TIME_OUT,
  1457.                 (U8) ERROR_TONE);
  1458.             break;
  1459.     }
  1460.     if (IsScreenPresent(SCR_ID_MSG_WRITE))
  1461.     {
  1462.         SetMessagesScrnIdToDelHistoryNodes(SCR_ID_MSG_WRITE);
  1463.     }
  1464.     else
  1465.     {
  1466.         SetMessagesScrnIdToDelHistoryNodes(SCR_ID_MSG_PROCESSING);
  1467.     }
  1468.     DeleteMessagesHistoryNodes();
  1469.     AlmEnableSPOF();
  1470. }
  1471. /*****************************************************************************
  1472.  * FUNCTION
  1473.  *  SaveChatMsg
  1474.  * DESCRIPTION
  1475.  *  
  1476.  * PARAMETERS
  1477.  *  void
  1478.  * RETURNS
  1479.  *  void
  1480.  *****************************************************************************/
  1481. void SaveChatMsg(void)
  1482. {
  1483.     /*----------------------------------------------------------------*/
  1484.     /* Local Variables                                                */
  1485.     /*----------------------------------------------------------------*/
  1486.     mmi_frm_sms_send_struct *sendData = OslMalloc(sizeof(mmi_frm_sms_send_struct));
  1487.     /*----------------------------------------------------------------*/
  1488.     /* Code Body                                                      */
  1489.     /*----------------------------------------------------------------*/
  1490.     memset((S8*) sendData, 0, sizeof(mmi_frm_sms_send_struct));
  1491.     sendData->status = SMSAL_STO_UNSENT;
  1492.     memset((S8*) sendData->number, 0, MAX_DIGITS_SMS);
  1493.     mmi_frm_sms_save_sms(CallbackSaveChatMsg, MOD_MMI, sendData);
  1494.     OslMfree(sendData);
  1495. }
  1496. /*****************************************************************************
  1497.  * FUNCTION
  1498.  *  mmi_msg_chat_get_invitation_pattern
  1499.  * DESCRIPTION
  1500.  *  
  1501.  * PARAMETERS
  1502.  *  void
  1503.  * RETURNS
  1504.  *  
  1505.  *****************************************************************************/
  1506. S8 *mmi_msg_chat_get_invitation_pattern(void)
  1507. {
  1508.     /*----------------------------------------------------------------*/
  1509.     /* Local Variables                                                */
  1510.     /*----------------------------------------------------------------*/
  1511.     /*----------------------------------------------------------------*/
  1512.     /* Code Body                                                      */
  1513.     /*----------------------------------------------------------------*/
  1514.     return (S8*) gInvitation;
  1515. }
  1516. #endif /* _CHAT_APPSENDMSG_ */ 
  1517. #endif /* __MMI_MESSAGES_CHAT__ */