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

MTK

开发平台:

C/C++

  1.         IMG_GLOBAL_YES,
  2.         STR_GLOBAL_NO,
  3.         IMG_GLOBAL_NO,
  4.         (UI_string_type) GetString(msg),
  5.         IMG_GLOBAL_QUESTION,
  6.         WARNING_TONE);
  7.     SetLeftSoftkeyFunction(lskFuncPtr, KEY_EVENT_UP);
  8.     SetRightSoftkeyFunction(rskFuncPtr, KEY_EVENT_UP);
  9. }
  10. /*****************************************************************************
  11.  * FUNCTION
  12.  *  mmi_imps_hilite_comm_input_meth
  13.  * DESCRIPTION
  14.  *  Common highlight handler of Input Method option
  15.  * PARAMETERS
  16.  *  void
  17.  * RETURNS
  18.  *  void
  19.  *****************************************************************************/
  20. void mmi_imps_hilite_comm_input_meth(void)
  21. {
  22.     /*----------------------------------------------------------------*/
  23.     /* Local Variables                                                */
  24.     /*----------------------------------------------------------------*/
  25.     /*----------------------------------------------------------------*/
  26.     /* Code Body                                                      */
  27.     /*----------------------------------------------------------------*/
  28.     SetLeftSoftkeyFunction(EntryInputMethodScreen, KEY_EVENT_UP);
  29.     SetKeyHandler(EntryInputMethodScreen, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  30.     RegisterInputMethodScreenCloseFunction(mmi_imps_util_go_back_2_hist);
  31. }
  32. #define WATCH_LIST_IMPS
  33. /*****************************************************************************
  34.  * FUNCTION
  35.  *  mmi_imps_hilite_get_watch_list
  36.  * DESCRIPTION
  37.  *  Highlight handler of Get Watcher List option
  38.  * PARAMETERS
  39.  *  void
  40.  * RETURNS
  41.  *  void
  42.  *****************************************************************************/
  43. void mmi_imps_hilite_get_watch_list(void)
  44. {
  45.     /*----------------------------------------------------------------*/
  46.     /* Local Variables                                                */
  47.     /*----------------------------------------------------------------*/
  48.     /*----------------------------------------------------------------*/
  49.     /* Code Body                                                      */
  50.     /*----------------------------------------------------------------*/
  51.     SetLeftSoftkeyFunction(mmi_imps_get_watch_list, KEY_EVENT_UP);
  52. }
  53. /*****************************************************************************
  54.  * FUNCTION
  55.  *  mmi_imps_get_watch_list
  56.  * DESCRIPTION
  57.  *  Handler of Get Watcher List option
  58.  * PARAMETERS
  59.  *  void
  60.  * RETURNS
  61.  *  void
  62.  *****************************************************************************/
  63. void mmi_imps_get_watch_list(void)
  64. {
  65.     /*----------------------------------------------------------------*/
  66.     /* Local Variables                                                */
  67.     /*----------------------------------------------------------------*/
  68.     /*----------------------------------------------------------------*/
  69.     /* Code Body                                                      */
  70.     /*----------------------------------------------------------------*/
  71.     /* shall not function before auto-update finished */
  72.     if (!imps_p->gen_info.auto_update_done)
  73.     {
  74.         mmi_imps_util_disp_warning_popup(STR_ID_IMPS_ERR_CONT_NOT_READY);
  75.         return;
  76.     }
  77.     /* display progressing screen */
  78.     mmi_imps_pre_entry_progressing(
  79.         STR_ID_IMPS,
  80.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  81.         0,
  82.         0,
  83.         STR_GLOBAL_ABORT,
  84.         0,
  85.         (U8*) GetString(STR_ID_IMPS_PROGRESSING),
  86.         NULL,
  87.         IMG_GLOBAL_PROGRESS,
  88.         NULL,
  89.         mmi_imps_get_watch_list_abort,
  90.         mmi_imps_get_watch_list_abort);
  91.     /* reset context of search */
  92.     imps_p->search_result.count = 0;
  93. #ifdef IMPS_TEST_CODE
  94.     SetKeyHandler(mmi_imps_test_get_watch_list_complete, KEY_SEND, KEY_EVENT_DOWN);
  95. #else /* IMPS_TEST_CODE */ 
  96.     imps_p->search_result.search_cause = IMPS_SEARCH_WATCHER;
  97.     mmi_imps_ps_get_watch_list_req();
  98. #endif /* IMPS_TEST_CODE */ 
  99. }
  100. /*****************************************************************************
  101.  * FUNCTION
  102.  *  mmi_imps_get_watch_list_abort
  103.  * DESCRIPTION
  104.  *  Abort getting watch list
  105.  * PARAMETERS
  106.  *  void
  107.  * RETURNS
  108.  *  void
  109.  *****************************************************************************/
  110. void mmi_imps_get_watch_list_abort(void)
  111. {
  112.     /*----------------------------------------------------------------*/
  113.     /* Local Variables                                                */
  114.     /*----------------------------------------------------------------*/
  115.     /*----------------------------------------------------------------*/
  116.     /* Code Body                                                      */
  117.     /*----------------------------------------------------------------*/
  118.     mmi_imps_entry_abort();
  119. #ifdef IMPS_TEST_CODE
  120.     SetKeyHandler(mmi_imps_get_watch_list_abort_finish, KEY_SEND, KEY_EVENT_DOWN);
  121. #else 
  122.     mmi_imps_ps_abort_get_watch_list_req();
  123. #endif 
  124. }
  125. /*****************************************************************************
  126.  * FUNCTION
  127.  *  mmi_imps_get_watch_list_abort_finish
  128.  * DESCRIPTION
  129.  *  Aborting getting watch list finished
  130.  * PARAMETERS
  131.  *  void
  132.  * RETURNS
  133.  *  void
  134.  *****************************************************************************/
  135. void mmi_imps_get_watch_list_abort_finish(void)
  136. {
  137.     /*----------------------------------------------------------------*/
  138.     /* Local Variables                                                */
  139.     /*----------------------------------------------------------------*/
  140.     /*----------------------------------------------------------------*/
  141.     /* Code Body                                                      */
  142.     /*----------------------------------------------------------------*/
  143.     if (imps_p->search_result.count)    /* some result already came back */
  144.     {
  145.         mmi_imps_entry_search_result();
  146.         DeleteUptoScrID(SCR_ID_IMPS_CONT_OPT);
  147.     }
  148.     else
  149.     {
  150.         if (GetActiveScreenId() == SCR_ID_IMPS_PROGRESS)
  151.         {
  152.             GoBackToHistory(SCR_ID_IMPS_CONT_OPT);
  153.         }
  154.         else
  155.         {
  156.             DeleteUptoScrID(SCR_ID_IMPS_CONT_OPT);
  157.         }
  158.     }
  159. }
  160. /*****************************************************************************
  161.  * FUNCTION
  162.  *  mmi_imps_pre_entry_watch_list
  163.  * DESCRIPTION
  164.  *  Pre-Entry function of watch list. Retrieve data from file.
  165.  * PARAMETERS
  166.  *  filename            [?]         
  167.  *  file_path(?)        [IN]        File_path of search result
  168.  * RETURNS
  169.  *  result of open file
  170.  *****************************************************************************/
  171. S32 mmi_imps_pre_entry_watch_list(S16 *filename)
  172. {
  173.     /*----------------------------------------------------------------*/
  174.     /* Local Variables                                                */
  175.     /*----------------------------------------------------------------*/
  176.     S32 i, count;
  177.     FS_HANDLE fileHandle = 0;
  178.     imps_watcher_entity_struct *buff = (imps_watcher_entity_struct*) OslMalloc(sizeof(imps_watcher_entity_struct));
  179.     /*----------------------------------------------------------------*/
  180.     /* Code Body                                                      */
  181.     /*----------------------------------------------------------------*/
  182.     count = (S32) imps_p->search_result.count;
  183.     if (count)
  184.     {
  185.         U32 len;
  186.         S32 result;
  187.         fileHandle = FS_Open((U16*) filename, FS_READ_ONLY);
  188.         if (fileHandle > 0)
  189.         {
  190.             for (i = 0; i < count; i++)
  191.             {
  192.                 result = FS_Read(fileHandle, (void*)buff, sizeof(imps_watcher_entity_struct), &len);
  193.                 if (result == FS_NO_ERROR)
  194.                 {
  195.                     strcpy((S8*) imps_p->search_result.entity[i].id, (S8*) buff->watcher_user_id);
  196.                     memset(&imps_p->search_result.entity[i].sname[0], 0, sizeof(imps_p->search_result.entity[i].sname));
  197.                 }
  198.             }
  199.             FS_Close(fileHandle);
  200.         }
  201.     }
  202.     OslMfree(buff);
  203.     return (S32) fileHandle;
  204. }
  205. /*****************************************************************************
  206.  * FUNCTION
  207.  *  mmi_imps_entry_watch_list
  208.  * DESCRIPTION
  209.  *  Display watcher list
  210.  * PARAMETERS
  211.  *  void
  212.  * RETURNS
  213.  *  void
  214.  *****************************************************************************/
  215. void mmi_imps_entry_watch_list(void)
  216. {
  217.     /*----------------------------------------------------------------*/
  218.     /* Local Variables                                                */
  219.     /*----------------------------------------------------------------*/
  220.     U8 *guiBuffer;
  221.     S32 i;
  222.     S32 num_of_items;
  223.     /*----------------------------------------------------------------*/
  224.     /* Code Body                                                      */
  225.     /*----------------------------------------------------------------*/
  226.     num_of_items = (S32) imps_p->search_result.count;
  227.     if (num_of_items == 0)
  228.     {
  229.         mmi_imps_util_disp_empty_popup();
  230.         return;
  231.     }
  232.     EntryNewScreen(SCR_ID_IMPS_WATCHER_LIST, NULL, mmi_imps_entry_watch_list, NULL);
  233.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_WATCHER_LIST);
  234.     SetParentHandler(0);
  235.     RegisterHighlightHandler(mmi_imps_hilite_watch_list);
  236.     num_of_items = (S32) imps_p->search_result.count;
  237.     for (i = 0; i < num_of_items; i++)
  238.     {
  239.         mmi_imps_util_ansi_2_ucs2_menu(
  240.             (S8*) imps_p->search_result.entity[i].id,
  241.             (S8*) subMenuData[i],
  242.             MAX_SUBMENU_CHARACTERS);
  243.         mmi_imps_util_generate_name_hint((S8*) imps_p->search_result.entity[i].sname, i, MAX_SUBMENU_CHARACTERS);
  244.         subMenuDataPtrs[i] = subMenuData[i];
  245.     }
  246.     ShowCategory53Screen(
  247.         STR_ID_IMPS_WATCHER_LIST,
  248.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  249.         STR_GLOBAL_ADD,
  250.         IMG_GLOBAL_OK,
  251.         STR_GLOBAL_BACK,
  252.         IMG_GLOBAL_BACK,
  253.         num_of_items,
  254.         (U8 **) subMenuDataPtrs,
  255.         (U16*) gIndexIconsImageList,
  256.         (U8 **) hintDataPtrs,
  257.         0,
  258.         0,
  259.         guiBuffer);
  260.     if (imps_p->cont_info.no_cont == IMPS_MAX_NO_CONT || imps_p->group_info.no_group == 0)
  261.     {
  262.         ChangeLeftSoftkey(0, 0);
  263.     }
  264.     else
  265.     {
  266.         SetLeftSoftkeyFunction(mmi_imps_pre_entry_sel_group, KEY_EVENT_UP);
  267.     }
  268.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  269.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  270. }
  271. /*****************************************************************************
  272.  * FUNCTION
  273.  *  mmi_imps_hilite_watch_list
  274.  * DESCRIPTION
  275.  *  Highlight handler of watch list item
  276.  * PARAMETERS
  277.  *  index       [IN]        Index of highlighting item
  278.  * RETURNS
  279.  *  void
  280.  *****************************************************************************/
  281. void mmi_imps_hilite_watch_list(S32 index)
  282. {
  283.     /*----------------------------------------------------------------*/
  284.     /* Local Variables                                                */
  285.     /*----------------------------------------------------------------*/
  286.     /*----------------------------------------------------------------*/
  287.     /* Code Body                                                      */
  288.     /*----------------------------------------------------------------*/
  289.     imps_p->search_result.curr_item = (U8) index;
  290. }
  291. #define CHAT_IMPS
  292. /*****************************************************************************
  293.  * FUNCTION
  294.  *  mmi_imps_hilite_cont_send_msg
  295.  * DESCRIPTION
  296.  *  Highlight handler of Send/Read Message option
  297.  * PARAMETERS
  298.  *  void
  299.  * RETURNS
  300.  *  void
  301.  *****************************************************************************/
  302. void mmi_imps_hilite_cont_send_msg(void)
  303. {
  304.     /*----------------------------------------------------------------*/
  305.     /* Local Variables                                                */
  306.     /*----------------------------------------------------------------*/
  307.     /*----------------------------------------------------------------*/
  308.     /* Code Body                                                      */
  309.     /*----------------------------------------------------------------*/
  310.     SetLeftSoftkeyFunction(mmi_imps_pre_entry_chat, KEY_EVENT_UP);
  311.     SetKeyHandler(mmi_imps_pre_entry_chat, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  312. }
  313. /*****************************************************************************
  314.  * FUNCTION
  315.  *  mmi_imps_pre_entry_chat
  316.  * DESCRIPTION
  317.  *  Pre-Entry function of chat room
  318.  * PARAMETERS
  319.  *  void
  320.  * RETURNS
  321.  *  void
  322.  *****************************************************************************/
  323. void mmi_imps_pre_entry_chat(void)
  324. {
  325.     /*----------------------------------------------------------------*/
  326.     /* Local Variables                                                */
  327.     /*----------------------------------------------------------------*/
  328.     S32 i;
  329.     U8 *id;
  330.     UI_character_type *nick_name;
  331.     U8 new_room = TRUE;
  332.     /*----------------------------------------------------------------*/
  333.     /* Code Body                                                      */
  334.     /*----------------------------------------------------------------*/
  335.     id = &imps_p->cont_info.cont_list[imps_p->cont_info.curr_cont].id[0];
  336.     nick_name = &imps_p->cont_info.cont_list[imps_p->cont_info.curr_cont].nick_name[0];
  337.     /* check if chat room for the friend already exists */
  338.     for (i = 0; i < IMPS_MAX_NO_ROOM; i++)
  339.     {
  340.         if (imps_p->room_info.room_list[i].is_used)
  341.         {
  342.             if (mmi_imps_util_is_id_same((S8*) id, (S8*) imps_p->room_info.room_list[i].member[0].id))
  343.             {
  344.                 new_room = FALSE;
  345.                 break;
  346.             }
  347.         }
  348.     }
  349.     if (i == IMPS_MAX_NO_ROOM)  /* all chat rooms are occupied */
  350.     {
  351.         i = mmi_imps_util_get_empty_room_slot();
  352.         if (i == IMPS_MAX_NO_ROOM)
  353.         {
  354.             mmi_imps_util_disp_err_popup(STR_ID_IMPS_ERR_CHAT_ROOM_FULL);
  355.             return;
  356.         }
  357.     }
  358.     if (new_room)
  359.     {
  360.         /* reset all data */
  361.         mmi_imps_room_struct *room = &imps_p->room_info.room_list[i];
  362.         memset(room, 0, sizeof(mmi_imps_room_struct));
  363.         room->is_used = TRUE;
  364.         room->type = IMPS_ROOM_TYPE_SINGLE;
  365.         room->no_member = 1;
  366.         room->tab_index = imps_p->gen_info.curr_tab = imps_p->gen_info.no_tab;
  367.         imps_p->gen_info.no_tab++;
  368.         strcpy((S8*) room->member[0].id, (S8*) id);
  369.         strcpy((S8*) room->room_id, (S8*) id);
  370.         /* display be screen name if the user's alias is not empty */
  371.         if (pfnUnicodeStrlen((S8*) nick_name))
  372.         {
  373.             pfnUnicodeStrcpy((S8*) room->room_name, (S8*) nick_name);
  374.             pfnUnicodeStrcpy((S8*) room->member[0].sname, (S8*) nick_name);
  375.         }
  376.         else
  377.         {
  378.             AnsiiToUnicodeString((S8*) room->room_name, (S8*) id);
  379.             room->member[0].sname[0] = 0;
  380.         }
  381.         imps_p->room_info.no_rooms++;
  382.         /* update display buffer */
  383.         mmi_imps_new_room_string((S8*) room->chat_buff, (S8*) room->room_name);
  384.     }
  385.     else
  386.     {
  387.         imps_p->gen_info.curr_tab = (U8) imps_p->room_info.room_list[i].tab_index;
  388.     }
  389.     imps_p->chat_info.curr_room = (U8) i;
  390.     mmi_imps_entry_chat();
  391.     DeleteScreenIfPresent(SCR_ID_IMPS_CONT_OPT);
  392.     DeleteScreenIfPresent(SCR_ID_IMPS_CONT);
  393. }
  394. /*****************************************************************************
  395.  * FUNCTION
  396.  *  mmi_imps_chat_show_input_screen
  397.  * DESCRIPTION
  398.  *  Show input editor in chatting screen
  399.  * PARAMETERS
  400.  *  void
  401.  * RETURNS
  402.  *  void
  403.  *****************************************************************************/
  404. void mmi_imps_chat_show_input_screen(void)
  405. {
  406.     /*----------------------------------------------------------------*/
  407.     /* Local Variables                                                */
  408.     /*----------------------------------------------------------------*/
  409.     /*----------------------------------------------------------------*/
  410.     /* Code Body                                                      */
  411.     /*----------------------------------------------------------------*/
  412.     Category435ShowPopup(TRUE);
  413.     imps_p->room_info.room_list[imps_p->chat_info.curr_room].edit_mode = TRUE;
  414.     SetKeyHandler(mmi_imps_chat_send_key_hdlr, KEY_SEND, KEY_EVENT_DOWN);
  415. }
  416. /*****************************************************************************
  417.  * FUNCTION
  418.  *  mmi_imps_chat_hide_input_screen
  419.  * DESCRIPTION
  420.  *  Hide input editor in chatting screen
  421.  * PARAMETERS
  422.  *  redraw      [IN]        
  423.  * RETURNS
  424.  *  void
  425.  *****************************************************************************/
  426. void mmi_imps_chat_hide_input_screen(BOOL redraw)
  427. {
  428.     /*----------------------------------------------------------------*/
  429.     /* Local Variables                                                */
  430.     /*----------------------------------------------------------------*/
  431.     /*----------------------------------------------------------------*/
  432.     /* Code Body                                                      */
  433.     /*----------------------------------------------------------------*/
  434.     Category435HidePopup(redraw);
  435.     imps_p->room_info.room_list[imps_p->chat_info.curr_room].edit_mode = FALSE;
  436.     mmi_imps_chat_register_key_hdlr();
  437. }
  438. /*****************************************************************************
  439.  * FUNCTION
  440.  *  mmi_imps_chat_register_key_hdlr
  441.  * DESCRIPTION
  442.  *  Register key handlers for chatting screen
  443.  * PARAMETERS
  444.  *  void
  445.  * RETURNS
  446.  *  void
  447.  *****************************************************************************/
  448. void mmi_imps_chat_register_key_hdlr(void)
  449. {
  450.     /*----------------------------------------------------------------*/
  451.     /* Local Variables                                                */
  452.     /*----------------------------------------------------------------*/
  453.     U16 keyCodes[] = {KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_STAR, KEY_POUND};
  454.     U8 nKeyCodes = (U8) 12;
  455.     /*----------------------------------------------------------------*/
  456.     /* Code Body                                                      */
  457.     /*----------------------------------------------------------------*/
  458.     SetCategory435RSKFunction(GoBackHistory);
  459.     if (imps_p->room_info.room_list[imps_p->chat_info.curr_room].edit_mode == FALSE)
  460.     {
  461.         SetKeyHandler(mmi_imps_tab_prev, KEY_LEFT_ARROW, KEY_EVENT_DOWN);       /* move to previous tab */
  462.         SetKeyHandler(mmi_imps_tab_next, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);      /* move to next tab */
  463.         SetGroupKeyHandler(mmi_imps_chat_show_input_screen, keyCodes, nKeyCodes, KEY_EVENT_UP);
  464.     }
  465.     else
  466.     {
  467.         SetKeyHandler(mmi_imps_chat_send_key_hdlr, KEY_SEND, KEY_EVENT_DOWN);
  468.     }
  469. }
  470. /*****************************************************************************
  471.  * FUNCTION
  472.  *  mmi_imps_chat_input_rsk_hdlr
  473.  * DESCRIPTION
  474.  *  RSK handler of input screen. Hide input popup screen.
  475.  * PARAMETERS
  476.  *  void
  477.  * RETURNS
  478.  *  void
  479.  *****************************************************************************/
  480. void mmi_imps_chat_input_rsk_hdlr(void)
  481. {
  482.     /*----------------------------------------------------------------*/
  483.     /* Local Variables                                                */
  484.     /*----------------------------------------------------------------*/
  485.     /*----------------------------------------------------------------*/
  486.     /* Code Body                                                      */
  487.     /*----------------------------------------------------------------*/
  488.     mmi_imps_chat_hide_input_screen(TRUE);
  489. }
  490. /*****************************************************************************
  491.  * FUNCTION
  492.  *  mmi_imps_entry_chat
  493.  * DESCRIPTION
  494.  *  Entry chat room of IMPS application
  495.  * PARAMETERS
  496.  *  void
  497.  * RETURNS
  498.  *  void
  499.  *****************************************************************************/
  500. void mmi_imps_entry_chat(void)
  501. {
  502.     /*----------------------------------------------------------------*/
  503.     /* Local Variables                                                */
  504.     /*----------------------------------------------------------------*/
  505.     U8 *guiBuffer;
  506.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[imps_p->chat_info.curr_room];
  507.     /*----------------------------------------------------------------*/
  508.     /* Code Body                                                      */
  509.     /*----------------------------------------------------------------*/
  510.     EntryNewScreen(SCR_ID_IMPS_CHAT, mmi_imps_exit_chat, NULL, NULL);
  511.     /* if GUI buffer is not NULL, shall histroy shall be reset, and room is not in edit_mode */
  512.     if ((room->clear_gui_buff) && (room->edit_mode == FALSE))
  513.     {
  514.         guiBuffer = NULL;
  515.         room->clear_gui_buff = FALSE;
  516.     }
  517.     else
  518.     {
  519.         guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_CHAT);
  520.     }
  521.     if (room->edit_mode == FALSE)   /* clear buffer */
  522.     {
  523.         room->input_buff[0] = 0;
  524.     }
  525.     SetParentHandler(0);
  526.     /* initialize tab */
  527.     mmi_imps_tab_init();
  528.     /* configure icons */
  529.     wgui_config_general_multiline_icon_handler(MMI_FALSE, IMPS_NUM_MOOD, g_imps_mood_icon_list);
  530.     ShowCategory435Screen(
  531.         (UI_string_type) room->room_name,
  532.         STR_GLOBAL_OPTIONS,
  533.         IMG_GLOBAL_OK,
  534.         STR_GLOBAL_BACK,
  535.         IMG_GLOBAL_BACK,
  536.         STR_GLOBAL_OPTIONS,
  537.         IMG_GLOBAL_OK,
  538.         STR_GLOBAL_BACK,
  539.         IMG_GLOBAL_BACK,
  540.         (S8) imps_p->gen_info.no_tab,
  541.         (S8) imps_p->gen_info.curr_tab,
  542.         MMI_tab_bar_items,
  543.         room->edit_mode,
  544.         NULL,
  545.         INPUT_TYPE_ALPHANUMERIC_SENTENCECASE,
  546.         (U8*) room->input_buff,
  547.         IMPS_MAX_CHAT_INPUT_LEN,
  548.         (U8*) room->chat_buff,
  549.         pfnUnicodeStrlen((S8*) room->chat_buff),
  550.         wgui_general_multiline_icon_handler,
  551.         (PU8) GetImage(IMG_ID_IMPS_HAPPY),
  552.         guiBuffer);
  553.     SetCategory435TabSelectCallback(mmi_imps_tab_jump);
  554.     /* mark the unread message flag as FALSE */
  555.     room->unread_msg = FALSE;
  556.     mmi_imps_util_blink_tab();
  557.     /* update status icon because it might be changed when new message read */
  558.     mmi_imps_util_update_status_icon();
  559.     /* reset message icon in contact list */
  560.     mmi_imps_cont_reset_msg_icon();
  561.     /* RSK/LSK handlers for editable mode */
  562.     SetCategory435EditorRSKFunction(mmi_imps_chat_input_rsk_hdlr);
  563.     SetCategory435EditorLSKFunction(mmi_imps_chat_input_opt);
  564.     /* RSK/LSK handlers for read-only mode */
  565.     SetCategory435RSKFunction(GoBackHistory);
  566.     SetCategory435LSKFunction(mmi_imps_entry_chat_opt);
  567.     mmi_imps_chat_register_key_hdlr();
  568. }
  569. /*****************************************************************************
  570.  * FUNCTION
  571.  *  mmi_imps_exit_chat
  572.  * DESCRIPTION
  573.  *  Exit chat room of IMPS application (128*128/128*160)
  574.  * PARAMETERS
  575.  *  void
  576.  * RETURNS
  577.  *  void
  578.  *****************************************************************************/
  579. void mmi_imps_exit_chat(void)
  580. {
  581.     /*----------------------------------------------------------------*/
  582.     /* Local Variables                                                */
  583.     /*----------------------------------------------------------------*/
  584.     /*----------------------------------------------------------------*/
  585.     /* Code Body                                                      */
  586.     /*----------------------------------------------------------------*/
  587.     wgui_reset_general_multiline_icon_handler();
  588.     GenericExitScreen(SCR_ID_IMPS_CHAT, mmi_imps_entry_chat);
  589. }
  590. /*****************************************************************************
  591.  * FUNCTION
  592.  *  mmi_imps_entry_chat_opt
  593.  * DESCRIPTION
  594.  *  Entry option screen of chat room
  595.  * PARAMETERS
  596.  *  void
  597.  * RETURNS
  598.  *  void
  599.  *****************************************************************************/
  600. void mmi_imps_entry_chat_opt(void)
  601. {
  602.     /*----------------------------------------------------------------*/
  603.     /* Local Variables                                                */
  604.     /*----------------------------------------------------------------*/
  605.     U16 numItems;
  606.     U16 nStrItemList[5];
  607.     U8 *guiBuffer;
  608.     U16 menu_id;
  609.     /*----------------------------------------------------------------*/
  610.     /* Code Body                                                      */
  611.     /*----------------------------------------------------------------*/
  612.     if (imps_p->room_info.room_list[imps_p->chat_info.curr_room].type == IMPS_ROOM_TYPE_SINGLE)
  613.     {
  614.         menu_id = MENU_ID_IMPS_CHAT_OPT2;
  615.     }
  616.     else
  617.     {
  618.         menu_id = MENU_ID_IMPS_CHAT_OPT;
  619.     }
  620.     EntryNewScreen(SCR_ID_IMPS_CHAT_OPT, NULL, mmi_imps_entry_chat_opt, NULL);
  621.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_CHAT_OPT);
  622.     SetParentHandler(menu_id);
  623.     numItems = GetNumOfChild(menu_id);
  624.     GetSequenceStringIds(menu_id, nStrItemList);
  625.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  626.     ShowCategory52Screen(
  627.         STR_GLOBAL_OPTIONS,
  628.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  629.         STR_GLOBAL_OK,
  630.         IMG_GLOBAL_OK,
  631.         STR_GLOBAL_BACK,
  632.         IMG_GLOBAL_BACK,
  633.         numItems,
  634.         nStrItemList,
  635.         (U16*) gIndexIconsImageList,
  636.         NULL,
  637.         0,
  638.         0,
  639.         guiBuffer);
  640.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  641.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  642. }
  643. /*****************************************************************************
  644.  * FUNCTION
  645.  *  mmi_imps_hilite_chat_write
  646.  * DESCRIPTION
  647.  *  Highlight handler of Chat -> Option -> Write menu.
  648.  * PARAMETERS
  649.  *  void
  650.  * RETURNS
  651.  *  void
  652.  *****************************************************************************/
  653. void mmi_imps_hilite_chat_write(void)
  654. {
  655.     /*----------------------------------------------------------------*/
  656.     /* Local Variables                                                */
  657.     /*----------------------------------------------------------------*/
  658.     /*----------------------------------------------------------------*/
  659.     /* Code Body                                                      */
  660.     /*----------------------------------------------------------------*/
  661.     SetLeftSoftkeyFunction(mmi_imps_entry_chat_write, KEY_EVENT_UP);
  662. }
  663. /*****************************************************************************
  664.  * FUNCTION
  665.  *  mmi_imps_entry_chat_write
  666.  * DESCRIPTION
  667.  *  Display popup write message screen
  668.  * PARAMETERS
  669.  *  void
  670.  * RETURNS
  671.  *  void
  672.  *****************************************************************************/
  673. void mmi_imps_entry_chat_write(void)
  674. {
  675.     /*----------------------------------------------------------------*/
  676.     /* Local Variables                                                */
  677.     /*----------------------------------------------------------------*/
  678.     /*----------------------------------------------------------------*/
  679.     /* Code Body                                                      */
  680.     /*----------------------------------------------------------------*/
  681.     GoBackHistory();
  682.     mmi_imps_chat_show_input_screen();
  683. }
  684. /*****************************************************************************
  685.  * FUNCTION
  686.  *  mmi_imps_hilite_chat_send
  687.  * DESCRIPTION
  688.  *  Highlight handler of Send menu.
  689.  * PARAMETERS
  690.  *  void
  691.  * RETURNS
  692.  *  void
  693.  *****************************************************************************/
  694. void mmi_imps_hilite_chat_send(void)
  695. {
  696.     /*----------------------------------------------------------------*/
  697.     /* Local Variables                                                */
  698.     /*----------------------------------------------------------------*/
  699.     /*----------------------------------------------------------------*/
  700.     /* Code Body                                                      */
  701.     /*----------------------------------------------------------------*/
  702.     SetLeftSoftkeyFunction(mmi_imps_chat_send_done, KEY_EVENT_UP);
  703.     SetKeyHandler(mmi_imps_chat_send_done, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  704. }
  705. /*****************************************************************************
  706.  * FUNCTION
  707.  *  mmi_imps_hilite_chat_send_done
  708.  * DESCRIPTION
  709.  *  Highlight handler of Send -> Option -> Done
  710.  * PARAMETERS
  711.  *  void
  712.  * RETURNS
  713.  *  void
  714.  *****************************************************************************/
  715. void mmi_imps_hilite_chat_send_done(void)
  716. {
  717.     /*----------------------------------------------------------------*/
  718.     /* Local Variables                                                */
  719.     /*----------------------------------------------------------------*/
  720.     /*----------------------------------------------------------------*/
  721.     /* Code Body                                                      */
  722.     /*----------------------------------------------------------------*/
  723.     SetLeftSoftkeyFunction(mmi_imps_chat_send_done, KEY_EVENT_UP);
  724.     SetKeyHandler(mmi_imps_chat_send_done, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  725. }
  726. #ifdef IMPS_FOR_OMA_ONLY
  727. /*****************************************************************************
  728.  * FUNCTION
  729.  *  mmi_imps_chat_private_msg
  730.  * DESCRIPTION
  731.  *  Check if it's a private message within a chat room
  732.  * PARAMETERS
  733.  *  session_id      [IN]        Id of the chat session
  734.  *  buff            [IN]        Buffer of input message
  735.  *  curr_room       [IN]        Index of current chat room
  736.  * RETURNS
  737.  *  TRUE if it's a private message; otherwise FALSE
  738.  *****************************************************************************/
  739. BOOL mmi_imps_chat_private_msg(S32 session_id, S16 *buff, U8 curr_room)
  740. {
  741.     /*----------------------------------------------------------------*/
  742.     /* Local Variables                                                */
  743.     /*----------------------------------------------------------------*/
  744.     S32 i;
  745.     S16 *msg = buff;
  746.     U32 length;
  747.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[curr_room];
  748.     S32 count = (S32) room->no_member;
  749.     /*----------------------------------------------------------------*/
  750.     /* Code Body                                                      */
  751.     /*----------------------------------------------------------------*/
  752.     if (room->type == IMPS_ROOM_TYPE_SINGLE)
  753.     {
  754.         return FALSE;
  755.     }
  756.     for (i = 0; i < count; i++)
  757.     {
  758.         length = pfnUnicodeStrlen((S8*) room->member[i].sname);
  759.         if (pfnUnicodeStrncmp((S8*) room->member[i].sname, (S8*) msg, length) == 0)
  760.         {
  761.             break;
  762.         }
  763.     }
  764.     if (i == count)
  765.     {
  766.         return FALSE;
  767.     }
  768.     msg += length;
  769.     if (pfnUnicodeStrlen((S8*) msg))
  770.     {
  771.         mmi_imps_ps_send_msg_req(
  772.             session_id,
  773.             (S16*) msg,
  774.             room->room_id,
  775.             IMPS_ENTITY_TYPE_SCREEN_NAME,
  776.             (S8*) room->member[i].sname);
  777.         return TRUE;
  778.     }
  779.     return FALSE;
  780. }
  781. #endif /* IMPS_FOR_OMA_ONLY */ 
  782. /*****************************************************************************
  783.  * FUNCTION
  784.  *  mmi_imps_chat_send_key_hdlr
  785.  * DESCRIPTION
  786.  *  Send key handler of chat screen
  787.  * PARAMETERS
  788.  *  void
  789.  * RETURNS
  790.  *  void
  791.  *****************************************************************************/
  792. void mmi_imps_chat_send_key_hdlr(void)
  793. {
  794.     /*----------------------------------------------------------------*/
  795.     /* Local Variables                                                */
  796.     /*----------------------------------------------------------------*/
  797.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[imps_p->chat_info.curr_room];
  798.     /*----------------------------------------------------------------*/
  799.     /* Code Body                                                      */
  800.     /*----------------------------------------------------------------*/
  801.     if (pfnUnicodeStrlen((S8*) room->input_buff))
  802.     {
  803.         S32 session_id = mmi_imps_chat_insert_session();
  804.         /* check if there is any empty session can be used */
  805.         if (session_id == 0)
  806.         {
  807.             mmi_imps_chat_display_send_failed(imps_p->chat_info.curr_room, room->input_buff);
  808.             mmi_imps_util_play_tone(IMPS_ERR_TONE);
  809.         }
  810.         else
  811.         {
  812.             U8 entity_type;
  813.             mmi_imps_chat_disp_input_msg();
  814.         #ifndef IMPS_TEST_CODE
  815.         #ifdef IMPS_FOR_OMA_ONLY
  816.             if (mmi_imps_chat_private_msg(session_id, (S16*) room->input_buff, imps_p->chat_info.curr_room) == FALSE)
  817.         #endif 
  818.             {
  819.                 if (room->type == IMPS_ROOM_TYPE_SINGLE)
  820.                 {
  821.                     entity_type = IMPS_ENTITY_TYPE_USER;
  822.                 }
  823.                 else
  824.                 {
  825.                     entity_type = IMPS_ENTITY_TYPE_GROUP;
  826.                 }
  827.                 mmi_imps_ps_send_msg_req(session_id, (S16*) room->input_buff, room->room_id, (U8) entity_type, NULL);
  828.             }
  829.         #endif /* IMPS_TEST_CODE */ 
  830.         }
  831.         mmi_imps_chat_hide_input_screen(FALSE);
  832.         UpdateCategory435LogText((U8*) room->chat_buff, (S32) pfnUnicodeStrlen((S8*) room->chat_buff));
  833.         room->input_buff[0] = 0;
  834.     }
  835.     else
  836.     {
  837.         mmi_imps_chat_hide_input_screen(TRUE);
  838.     }
  839. }
  840. /*****************************************************************************
  841.  * FUNCTION
  842.  *  mmi_imps_chat_send_done
  843.  * DESCRIPTION
  844.  *  Highlight handler of Send -> Option -> Done
  845.  * PARAMETERS
  846.  *  void
  847.  * RETURNS
  848.  *  void
  849.  *****************************************************************************/
  850. void mmi_imps_chat_send_done(void)
  851. {
  852.     /*----------------------------------------------------------------*/
  853.     /* Local Variables                                                */
  854.     /*----------------------------------------------------------------*/
  855.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[imps_p->chat_info.curr_room];
  856.     /*----------------------------------------------------------------*/
  857.     /* Code Body                                                      */
  858.     /*----------------------------------------------------------------*/
  859.     if (pfnUnicodeStrlen((S8*) room->input_buff))
  860.     {
  861.         S32 session_id = mmi_imps_chat_insert_session();
  862.         /* check if there is any empty session can be used */
  863.         if (session_id == 0)
  864.         {
  865.             mmi_imps_chat_display_send_failed(imps_p->chat_info.curr_room, room->input_buff);
  866.             mmi_imps_util_play_tone(IMPS_ERR_TONE);
  867.         }
  868.         else
  869.         {
  870.             U8 entity_type;
  871.             mmi_imps_chat_disp_input_msg();
  872.         #ifndef IMPS_TEST_CODE
  873.         #ifdef IMPS_FOR_OMA_ONLY
  874.             if (mmi_imps_chat_private_msg(session_id, (S16*) room->input_buff, imps_p->chat_info.curr_room) == FALSE)
  875.         #endif 
  876.             {
  877.                 if (room->type == IMPS_ROOM_TYPE_SINGLE)
  878.                 {
  879.                     entity_type = IMPS_ENTITY_TYPE_USER;
  880.                 }
  881.                 else
  882.                 {
  883.                     entity_type = IMPS_ENTITY_TYPE_GROUP;
  884.                 }
  885.                 mmi_imps_ps_send_msg_req(session_id, (S16*) room->input_buff, room->room_id, (U8) entity_type, NULL);
  886.             }
  887.             room->input_buff[0] = 0;
  888.         #endif /* IMPS_TEST_CODE */ 
  889.         }
  890.     }
  891.     gui_lock_double_buffer();
  892.     GoBackToHistory(SCR_ID_IMPS_CHAT);
  893.     gui_unlock_double_buffer();
  894.     mmi_imps_chat_hide_input_screen(FALSE);
  895.     UpdateCategory435LogText((U8*) room->chat_buff, (S32) pfnUnicodeStrlen((S8*) room->chat_buff));
  896. }
  897. /*****************************************************************************
  898.  * FUNCTION
  899.  *  mmi_imps_chat_input_opt
  900.  * DESCRIPTION
  901.  *  Entry option screen of chat input box
  902.  * PARAMETERS
  903.  *  void
  904.  * RETURNS
  905.  *  void
  906.  *****************************************************************************/
  907. void mmi_imps_chat_input_opt(void)
  908. {
  909.     /*----------------------------------------------------------------*/
  910.     /* Local Variables                                                */
  911.     /*----------------------------------------------------------------*/
  912.     U16 numItems;
  913.     U16 nStrItemList[3];
  914.     U8 *guiBuffer;
  915.     /*----------------------------------------------------------------*/
  916.     /* Code Body                                                      */
  917.     /*----------------------------------------------------------------*/
  918.     EntryNewScreen(SCR_ID_IMPS_CHAT_OPT, NULL, mmi_imps_chat_input_opt, NULL);
  919.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_CHAT_OPT);
  920.     SetParentHandler(MENU_ID_IMPS_CHAT_INPUT_OPT);
  921.     numItems = GetNumOfChild(MENU_ID_IMPS_CHAT_INPUT_OPT);
  922.     GetSequenceStringIds(MENU_ID_IMPS_CHAT_INPUT_OPT, nStrItemList);
  923.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  924.     ShowCategory52Screen(
  925.         STR_GLOBAL_OPTIONS,
  926.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  927.         STR_GLOBAL_OK,
  928.         IMG_GLOBAL_OK,
  929.         STR_GLOBAL_BACK,
  930.         IMG_GLOBAL_BACK,
  931.         numItems,
  932.         nStrItemList,
  933.         (U16*) gIndexIconsImageList,
  934.         NULL,
  935.         0,
  936.         0,
  937.         guiBuffer);
  938.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  939.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  940. }
  941. /*****************************************************************************
  942.  * FUNCTION
  943.  *  mmi_imps_chat_disp_input_msg
  944.  * DESCRIPTION
  945.  *  Insert new input message in chat room.
  946.  * PARAMETERS
  947.  *  void
  948.  * RETURNS
  949.  *  void
  950.  *****************************************************************************/
  951. void mmi_imps_chat_disp_input_msg(void)
  952. {
  953.     /*----------------------------------------------------------------*/
  954.     /* Local Variables                                                */
  955.     /*----------------------------------------------------------------*/
  956.     U16 *tmp_input_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  957.     wgui_color_buffer_writer_struct writer;
  958.     BOOL result;
  959.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[imps_p->chat_info.curr_room];
  960.     /*----------------------------------------------------------------*/
  961.     /* Code Body                                                      */
  962.     /*----------------------------------------------------------------*/
  963.     tmp_input_buff[0] = 0;
  964.     wgui_color_buffer_create_writer(&writer, (U8*) tmp_input_buff, IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  965.     wgui_color_buffer_write_char(&writer, GUI_INPUT_COLOR_04 /* colorrr++ */ );
  966.     /* group talk */
  967.     if ((room->type != IMPS_ROOM_TYPE_SINGLE) && pfnUnicodeStrlen((S8*) room->sname))
  968.     {
  969.         wgui_color_buffer_write_char(&writer, '<');
  970.         wgui_color_buffer_write_string(&writer, (U8*) room->sname, MMI_FALSE, &result);
  971.         wgui_color_buffer_write_char(&writer, '>');
  972.     }
  973.     else
  974.     {
  975.         U16 *tmp_chat_buff1 = OslMalloc(IMPS_MAX_CHAT_BUFF);
  976.         U16 *tmp_chat_buff2 = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  977.         sprintf((S8*) tmp_chat_buff1, "<%s>", (S8*) imps_p->act_prof.username);
  978.         AnsiiToUnicodeString((S8*) tmp_chat_buff2, (S8*) tmp_chat_buff1);
  979.         wgui_color_buffer_write_string(&writer, (U8*) tmp_chat_buff2, MMI_FALSE, &result);
  980.         OslMfree(tmp_chat_buff1);
  981.         OslMfree(tmp_chat_buff2);
  982.     }
  983.     wgui_color_buffer_write_char(&writer, GUI_INPUT_MARKER_RESET_ALL);
  984.     wgui_color_buffer_write_string(&writer, (U8*) L"n", MMI_FALSE, &result);
  985.     wgui_color_buffer_write_string(&writer, (U8*) room->input_buff, MMI_FALSE, &result);
  986.     wgui_color_buffer_write_string(&writer, (U8*) L"nn", MMI_FALSE, &result);
  987.     mmi_imps_chat_flush_msg(tmp_input_buff, (S32) imps_p->chat_info.curr_room);
  988.     OslMfree(tmp_input_buff);
  989. }
  990. /*****************************************************************************
  991.  * FUNCTION
  992.  *  mmi_imps_chat_recv_msg
  993.  * DESCRIPTION
  994.  *  Handler when receiving a incoming message for current chat room
  995.  * PARAMETERS
  996.  *  msg         [?]         
  997.  *  room_id     [IN]        
  998.  *  sender      [?]         
  999.  * RETURNS
  1000.  *  void
  1001.  *****************************************************************************/
  1002. void mmi_imps_chat_recv_msg(U16 *msg, U8 room_id, imps_entity_struct *sender)
  1003. {
  1004.     /*----------------------------------------------------------------*/
  1005.     /* Local Variables                                                */
  1006.     /*----------------------------------------------------------------*/
  1007.     U16 *tmp_sname_buff;
  1008.     U16 *tmp_input_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  1009.     wgui_color_buffer_writer_struct writer;
  1010.     BOOL result;
  1011.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[room_id];
  1012.     /*----------------------------------------------------------------*/
  1013.     /* Code Body                                                      */
  1014.     /*----------------------------------------------------------------*/
  1015.     tmp_input_buff[0] = 0;
  1016.     wgui_color_buffer_create_writer(&writer, (U8*) tmp_input_buff, IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  1017.     wgui_color_buffer_write_char(&writer, GUI_INPUT_COLOR_00);
  1018.     /* insert input into buffer */
  1019.     wgui_color_buffer_write_char(&writer, '<');
  1020.     if (pfnUnicodeStrlen((S8*) sender->sname) > 0)
  1021.     {
  1022.         wgui_color_buffer_write_string(&writer, (U8*) sender->sname, MMI_FALSE, &result);
  1023.     }
  1024.     else
  1025.     {
  1026.         tmp_sname_buff = OslMalloc(IMPS_MAX_ID_LEN * ENCODING_LENGTH);
  1027.         AnsiiToUnicodeString((S8*) tmp_sname_buff, (S8*) sender->id);
  1028.         wgui_color_buffer_write_string(&writer, (U8*) tmp_sname_buff, MMI_FALSE, &result);
  1029.         OslMfree(tmp_sname_buff);
  1030.     }
  1031.     wgui_color_buffer_write_string(&writer, (U8*) L">n", MMI_FALSE, &result);
  1032.     wgui_color_buffer_write_char(&writer, GUI_INPUT_MARKER_RESET_ALL);
  1033.     wgui_color_buffer_write_string(&writer, (U8*) msg, MMI_FALSE, &result);
  1034.     wgui_color_buffer_write_string(&writer, (U8*) L"nn", MMI_FALSE, &result);
  1035.     mmi_imps_chat_flush_msg(tmp_input_buff, (S32) room_id);
  1036.     room->clear_gui_buff = TRUE;
  1037.     OslMfree(tmp_input_buff);
  1038. }
  1039. /*****************************************************************************
  1040.  * FUNCTION
  1041.  *  mmi_imps_chat_display_send_failed
  1042.  * DESCRIPTION
  1043.  *  Display error message if a message can not be sent
  1044.  * PARAMETERS
  1045.  *  room_id     [IN]        Index of room in room list
  1046.  *  msg         [IN]        Text message to be display
  1047.  * RETURNS
  1048.  *  void
  1049.  *****************************************************************************/
  1050. void mmi_imps_chat_display_send_failed(U8 room_id, U16 *msg)
  1051. {
  1052.     /*----------------------------------------------------------------*/
  1053.     /* Local Variables                                                */
  1054.     /*----------------------------------------------------------------*/
  1055.     U16 *tmp_input_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  1056.     wgui_color_buffer_writer_struct writer;
  1057.     BOOL result;
  1058.     /*----------------------------------------------------------------*/
  1059.     /* Code Body                                                      */
  1060.     /*----------------------------------------------------------------*/
  1061.     tmp_input_buff[0] = 0;
  1062.     wgui_color_buffer_create_writer(&writer, (U8*) tmp_input_buff, IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  1063.     wgui_color_buffer_write_char(&writer, GUI_INPUT_COLOR_00);
  1064.     wgui_color_buffer_write_string(&writer, (U8*) GetString(STR_ID_IMPS_MSG_CANNOT_SEND), MMI_FALSE, &result);
  1065.     wgui_color_buffer_write_char(&writer, GUI_INPUT_MARKER_RESET_ALL);
  1066.     wgui_color_buffer_write_char(&writer, 'n');
  1067.     wgui_color_buffer_write_string(&writer, (U8*) msg, MMI_FALSE, &result);
  1068.     wgui_color_buffer_write_string(&writer, (U8*) L"nn", MMI_FALSE, &result);
  1069.     mmi_imps_chat_flush_msg(tmp_input_buff, (S32) room_id);
  1070.     OslMfree(tmp_input_buff);
  1071. }
  1072. /*****************************************************************************
  1073.  * FUNCTION
  1074.  *  mmi_imps_chat_disp_user_change_msg
  1075.  * DESCRIPTION
  1076.  *  Display member joined/left message in the chat room
  1077.  * PARAMETERS
  1078.  *  room_id     [IN]        Index of room
  1079.  *  member      [IN]        Left memeber
  1080.  *  type        [IN]        Type of change
  1081.  * RETURNS
  1082.  *  void
  1083.  *****************************************************************************/
  1084. void mmi_imps_chat_disp_user_change_msg(S32 room_id, mmi_imps_entity_struct *member, S32 type)
  1085. {
  1086.     /*----------------------------------------------------------------*/
  1087.     /* Local Variables                                                */
  1088.     /*----------------------------------------------------------------*/
  1089.     U16 *tmp_sname_buff;
  1090.     U16 *tmp_input_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  1091.     /*----------------------------------------------------------------*/
  1092.     /* Code Body                                                      */
  1093.     /*----------------------------------------------------------------*/
  1094.     /* insert input into buffer */
  1095.     if (pfnUnicodeStrlen((S8*) member->sname))
  1096.     {
  1097.         pfnUnicodeStrcpy((S8*) tmp_input_buff, (S8*) member->sname);
  1098.     }
  1099.     else
  1100.     {
  1101.         tmp_sname_buff = OslMalloc(IMPS_MAX_ID_LEN * ENCODING_LENGTH);
  1102.         AnsiiToUnicodeString((S8*) tmp_sname_buff, (S8*) member->id);
  1103.         pfnUnicodeStrcpy((S8*) tmp_input_buff, (S8*) tmp_sname_buff);
  1104.         OslMfree(tmp_sname_buff);
  1105.     }
  1106.     pfnUnicodeStrcat((S8*) tmp_input_buff, (S8*) L" ");
  1107.     if (type == IMPS_ROOM_MEMBER_JOINED)
  1108.     {
  1109.         pfnUnicodeStrcat((S8*) tmp_input_buff, (S8*) GetString(STR_ID_IMPS_JOINED_ROOM));
  1110.     }
  1111.     else
  1112.     {
  1113.         pfnUnicodeStrcat((S8*) tmp_input_buff, (S8*) GetString(STR_ID_IMPS_LEFT_CHAT_ROOM));
  1114.     }
  1115.     pfnUnicodeStrcat((S8*) tmp_input_buff, (S8*) L"nn");
  1116.     mmi_imps_chat_flush_msg(tmp_input_buff, room_id);
  1117.     OslMfree(tmp_input_buff);
  1118. }
  1119. /*****************************************************************************
  1120.  * FUNCTION
  1121.  *  mmi_imps_chat_flush_msg
  1122.  * DESCRIPTION
  1123.  *  Flush message into display buffer
  1124.  * PARAMETERS
  1125.  *  data        [IN]        Data to be flush to display buffer
  1126.  *  room_id     [IN]        Index of chat room
  1127.  * RETURNS
  1128.  *  void
  1129.  *****************************************************************************/
  1130. void mmi_imps_chat_flush_msg(U16 *data, S32 room_id)
  1131. {
  1132.     /*----------------------------------------------------------------*/
  1133.     /* Local Variables                                                */
  1134.     /*----------------------------------------------------------------*/
  1135.     S32 input_len;
  1136.     S32 disp_len;
  1137.     S32 total_len;
  1138.     U16 *tmp_chat_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  1139.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[room_id];
  1140.     /*----------------------------------------------------------------*/
  1141.     /* Code Body                                                      */
  1142.     /*----------------------------------------------------------------*/
  1143.     input_len = pfnUnicodeStrlen((S8*) data);
  1144.     disp_len = pfnUnicodeStrlen((S8*) room->chat_buff);
  1145.     total_len = input_len + disp_len;
  1146.     if (total_len < IMPS_MAX_CHAT_BUFF)
  1147.     {
  1148.         pfnUnicodeStrcat((S8*) room->chat_buff, (S8*) data);
  1149.     }
  1150.     else
  1151.     {
  1152.         /* truncated previous string */
  1153.         U8 *cursor = (U8*) & room->chat_buff[0];
  1154.         U8 *end = (U8*) & room->chat_buff[(IMPS_MAX_CHAT_BUFF - 1)];
  1155.         cursor += ((total_len - IMPS_MAX_CHAT_BUFF + 1) * ENCODING_LENGTH);
  1156.         while ((cursor[0] != 0 || cursor[1] != 0) && (cursor < end))
  1157.         {
  1158.             if (cursor[0] == 'n' && cursor[1] == '')
  1159.             {
  1160.                 cursor += 2;    /* move cursor to new line */
  1161.                 break;
  1162.             }
  1163.             cursor += 2;
  1164.         }
  1165.         memset(tmp_chat_buff, 0, IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  1166.         if (cursor < end)
  1167.         {
  1168.             pfnUnicodeStrncpy((S8*) tmp_chat_buff, (S8*) cursor, (end - cursor));
  1169.         }
  1170.         room->chat_buff[0] = 0;
  1171.         pfnUnicodeStrcpy((S8*) room->chat_buff, (S8*) tmp_chat_buff);
  1172.         pfnUnicodeStrcat((S8*) room->chat_buff, (S8*) data);
  1173.     }
  1174.     OslMfree(tmp_chat_buff);
  1175. }
  1176. /*****************************************************************************
  1177.  * FUNCTION
  1178.  *  mmi_imps_chat_insert_session
  1179.  * DESCRIPTION
  1180.  *  Insert a chat session into queue
  1181.  * PARAMETERS
  1182.  *  void
  1183.  * RETURNS
  1184.  *  index of session
  1185.  *****************************************************************************/
  1186. S32 mmi_imps_chat_insert_session(void)
  1187. {
  1188.     /*----------------------------------------------------------------*/
  1189.     /* Local Variables                                                */
  1190.     /*----------------------------------------------------------------*/
  1191.     S32 i;
  1192.     /*----------------------------------------------------------------*/
  1193.     /* Code Body                                                      */
  1194.     /*----------------------------------------------------------------*/
  1195.     for (i = 0; i < IMPS_MAX_CHAT_MSG_COUNT; i++)
  1196.         if (imps_p->chat_info.chat_session[i].session_id == 0)
  1197.         {
  1198.             break;
  1199.         }
  1200.     if (i == IMPS_MAX_CHAT_MSG_COUNT)
  1201.     {
  1202.         return 0;
  1203.     }
  1204.     else
  1205.     {
  1206.         mmi_imps_chat_session_struct *session = &imps_p->chat_info.chat_session[i];
  1207.         pfnUnicodeStrcpy(
  1208.             (S8*) session->input_buff,
  1209.             (S8*) imps_p->room_info.room_list[imps_p->chat_info.curr_room].input_buff);
  1210.         session->session_id = mmi_imps_util_get_seq_no();
  1211.         strcpy((S8*) session->room_id, (S8*) imps_p->room_info.room_list[imps_p->chat_info.curr_room].room_id);
  1212.         return session->session_id;
  1213.     }
  1214. }
  1215. /*****************************************************************************
  1216.  * FUNCTION
  1217.  *  mmi_imps_hilite_chat_insert_symbol
  1218.  * DESCRIPTION
  1219.  *  Highlight handler of Insert Symbol menu.
  1220.  * PARAMETERS
  1221.  *  void
  1222.  * RETURNS
  1223.  *  void
  1224.  *****************************************************************************/
  1225. void mmi_imps_hilite_chat_insert_symbol(void)
  1226. {
  1227.     /*----------------------------------------------------------------*/
  1228.     /* Local Variables                                                */
  1229.     /*----------------------------------------------------------------*/
  1230.     /*----------------------------------------------------------------*/
  1231.     /* Code Body                                                      */
  1232.     /*----------------------------------------------------------------*/
  1233.     SetLeftSoftkeyFunction(mmi_imps_entry_chat_insert_symbol, KEY_EVENT_UP);
  1234.     SetKeyHandler(mmi_imps_entry_chat_insert_symbol, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1235. }
  1236. /*****************************************************************************
  1237.  * FUNCTION
  1238.  *  mmi_imps_entry_chat_insert_symbol
  1239.  * DESCRIPTION
  1240.  *  Display list of symbols to be inserted to chatting screen.
  1241.  * PARAMETERS
  1242.  *  void
  1243.  * RETURNS
  1244.  *  void
  1245.  *****************************************************************************/
  1246. void mmi_imps_entry_chat_insert_symbol(void)
  1247. {
  1248.     /*----------------------------------------------------------------*/
  1249.     /* Local Variables                                                */
  1250.     /*----------------------------------------------------------------*/
  1251.     U16 i;
  1252.     U8 *guiBuffer;
  1253.     U16 icons[IMPS_NUM_MOOD] = 
  1254.     {
  1255.         IMG_ID_IMPS_HAPPY,
  1256.         IMG_ID_IMPS_SAD,
  1257.         IMG_ID_IMPS_ANGRY,
  1258.         IMG_ID_IMPS_JEALOUS,
  1259.         IMG_ID_IMPS_ASHAMED,
  1260.         IMG_ID_IMPS_INVINCIBLE,
  1261.         IMG_ID_IMPS_IN_LOVE,
  1262.         IMG_ID_IMPS_SLEEPY,
  1263.         IMG_ID_IMPS_BORED,
  1264.         IMG_ID_IMPS_EXCITED,
  1265.         IMG_ID_IMPS_ANXIOUS
  1266.     };
  1267.     /*----------------------------------------------------------------*/
  1268.     /* Code Body                                                      */
  1269.     /*----------------------------------------------------------------*/
  1270.     EntryNewScreen(SCR_ID_IMPS_INSERT_SYMBOL, NULL, mmi_imps_entry_chat_insert_symbol, NULL);
  1271.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_INSERT_SYMBOL);
  1272.     SetParentHandler(0);
  1273.     RegisterHighlightHandler(mmi_imps_hilite_symbol);
  1274.     for (i = 0; i < IMPS_NUM_MOOD; i++)
  1275.     {
  1276.         memset(subMenuData[i], 0, MAX_SUB_MENU_SIZE);
  1277.         pfnUnicodeStrcpy((S8*) subMenuData[i], (S8*) GetString((U16) (STR_ID_IMPS_HAPPY + i)));
  1278.         subMenuDataPtrs[i] = subMenuData[i];
  1279.     }
  1280.     ShowCategory53Screen(
  1281.         STR_ID_IMPS_INSERT_SYMBOL,
  1282.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  1283.         STR_GLOBAL_OK,
  1284.         IMG_GLOBAL_OK,
  1285.         STR_GLOBAL_BACK,
  1286.         IMG_GLOBAL_BACK,
  1287.         IMPS_NUM_MOOD,
  1288.         (U8 **) subMenuDataPtrs,
  1289.         (U16*) icons,
  1290.         (U8 **) g_imps_mood_str,
  1291.         0,
  1292.         0,
  1293.         guiBuffer);
  1294.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1295.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1296.     SetLeftSoftkeyFunction(mmi_imps_sym_sel_done, KEY_EVENT_UP);
  1297. }
  1298. /*****************************************************************************
  1299.  * FUNCTION
  1300.  *  mmi_imps_hilite_symbol
  1301.  * DESCRIPTION
  1302.  *  Highlight handler in symbol list screen
  1303.  * PARAMETERS
  1304.  *  index       [IN]        
  1305.  * RETURNS
  1306.  *  void
  1307.  *****************************************************************************/
  1308. void mmi_imps_hilite_symbol(S32 index)
  1309. {
  1310.     /*----------------------------------------------------------------*/
  1311.     /* Local Variables                                                */
  1312.     /*----------------------------------------------------------------*/
  1313.     /*----------------------------------------------------------------*/
  1314.     /* Code Body                                                      */
  1315.     /*----------------------------------------------------------------*/
  1316.     imps_p->chat_info.sel_sym = (U8) index;
  1317. }
  1318. /*****************************************************************************
  1319.  * FUNCTION
  1320.  *  mmi_imps_sym_sel_done
  1321.  * DESCRIPTION
  1322.  *  Handler when finish selecting a symbol
  1323.  * PARAMETERS
  1324.  *  void
  1325.  * RETURNS
  1326.  *  void
  1327.  *****************************************************************************/
  1328. void mmi_imps_sym_sel_done(void)
  1329. {
  1330.     /*----------------------------------------------------------------*/
  1331.     /* Local Variables                                                */
  1332.     /*----------------------------------------------------------------*/
  1333.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[imps_p->chat_info.curr_room];
  1334.     S32 input_len = pfnUnicodeStrlen((S8*) room->input_buff);
  1335.     S32 sym_len = pfnUnicodeStrlen((S8*) g_imps_mood_str[imps_p->chat_info.sel_sym]);
  1336.     /*----------------------------------------------------------------*/
  1337.     /* Code Body                                                      */
  1338.     /*----------------------------------------------------------------*/
  1339.     if ((input_len + sym_len) > (IMPS_MAX_NOTE_LEN - 1))
  1340.     {
  1341.         mmi_imps_util_disp_err_popup(STR_ID_IMPS_ERR_NO_SPACE);
  1342.     }
  1343.     else
  1344.     {
  1345.         /* lock buffer to prevent redraw */
  1346.         gui_lock_double_buffer();
  1347.         GoBackToHistory(SCR_ID_IMPS_CHAT);
  1348.         gui_unlock_double_buffer();
  1349.         Category435DirectInsertString((UI_string_type) g_imps_mood_str[imps_p->chat_info.sel_sym], TRUE);
  1350.     }
  1351. }
  1352. /*****************************************************************************
  1353.  * FUNCTION
  1354.  *  mmi_imps_hilite_chat_member
  1355.  * DESCRIPTION
  1356.  *  Highlight handler of List Member menu.
  1357.  * PARAMETERS
  1358.  *  void
  1359.  * RETURNS
  1360.  *  void
  1361.  *****************************************************************************/
  1362. void mmi_imps_hilite_chat_member(void)
  1363. {
  1364.     /*----------------------------------------------------------------*/
  1365.     /* Local Variables                                                */
  1366.     /*----------------------------------------------------------------*/
  1367.     /*----------------------------------------------------------------*/
  1368.     /* Code Body                                                      */
  1369.     /*----------------------------------------------------------------*/
  1370.     SetLeftSoftkeyFunction(mmi_imps_entry_chat_member, KEY_EVENT_UP);
  1371.     SetKeyHandler(mmi_imps_entry_chat_member, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1372. }
  1373. /*****************************************************************************
  1374.  * FUNCTION
  1375.  *  mmi_imps_entry_chat_member
  1376.  * DESCRIPTION
  1377.  *  Display list of members who is currently on that chat room
  1378.  * PARAMETERS
  1379.  *  void
  1380.  * RETURNS
  1381.  *  void
  1382.  *****************************************************************************/
  1383. void mmi_imps_entry_chat_member(void)
  1384. {
  1385.     /*----------------------------------------------------------------*/
  1386.     /* Local Variables                                                */
  1387.     /*----------------------------------------------------------------*/
  1388.     U8 *guiBuffer;
  1389.     S32 i;
  1390.     S32 count;
  1391.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[imps_p->chat_info.curr_room];
  1392.     /*----------------------------------------------------------------*/
  1393.     /* Code Body                                                      */
  1394.     /*----------------------------------------------------------------*/
  1395.     if (room->no_member == 0)
  1396.     {
  1397.         mmi_imps_util_disp_empty_popup();
  1398.         return;
  1399.     }
  1400.     EntryNewScreen(SCR_ID_IMPS_CHAT_MEMBER, NULL, mmi_imps_entry_chat_member, NULL);
  1401.     /* fill member */
  1402.     for (i = 0, count = 0; i < IMPS_MAX_ENTITY_NUMBER; i++)
  1403.     {
  1404.         if (strlen((S8*) room->member[i].id) || pfnUnicodeStrlen((S8*) room->member[i].sname))
  1405.         {
  1406.             mmi_imps_util_ansi_2_ucs2_menu((S8*) room->member[i].id, (S8*) hintData[count], MAX_SUBMENU_CHARACTERS);
  1407.             if (pfnUnicodeStrlen((S8*) room->member[i].sname))
  1408.             {
  1409.                 pfnUnicodeStrcpy((S8*) subMenuData[count], (S8*) room->member[i].sname);
  1410.             }
  1411.             else
  1412.             {
  1413.                 pfnUnicodeStrcpy((S8*) subMenuData[count], (S8*) GetString(STR_ID_IMPS_ANONYMOUS));
  1414.             }
  1415.             subMenuDataPtrs[count] = subMenuData[count];
  1416.             if (pfnUnicodeStrlen((S8*) hintData[count]))
  1417.             {
  1418.                 hintDataPtrs[count] = hintData[count];
  1419.             }
  1420.             else
  1421.             {
  1422.                 hintDataPtrs[count] = NULL;
  1423.             }
  1424.             count++;
  1425.         }
  1426.     }
  1427.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_CHAT_MEMBER);
  1428.     SetParentHandler(0);
  1429.     ShowCategory53Screen(
  1430.         STR_ID_IMPS_LIST_MEMBER,
  1431.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  1432.         0,
  1433.         0,
  1434.         STR_GLOBAL_BACK,
  1435.         IMG_GLOBAL_BACK,
  1436.         (S32) count,
  1437.         (U8 **) subMenuDataPtrs,
  1438.         (U16*) gIndexIconsImageList,
  1439.         (U8 **) hintDataPtrs,
  1440.         0,
  1441.         0,
  1442.         guiBuffer);
  1443.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1444.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1445. }
  1446. /*****************************************************************************
  1447.  * FUNCTION
  1448.  *  mmi_imps_hilite_chat_save
  1449.  * DESCRIPTION
  1450.  *  Highlight handler of Save menu.
  1451.  * PARAMETERS
  1452.  *  void
  1453.  * RETURNS
  1454.  *  void
  1455.  *****************************************************************************/
  1456. void mmi_imps_hilite_chat_save(void)
  1457. {
  1458.     /*----------------------------------------------------------------*/
  1459.     /* Local Variables                                                */
  1460.     /*----------------------------------------------------------------*/
  1461.     /*----------------------------------------------------------------*/
  1462.     /* Code Body                                                      */
  1463.     /*----------------------------------------------------------------*/
  1464.     SetLeftSoftkeyFunction(mmi_imps_entry_chat_save, KEY_EVENT_UP);
  1465.     SetKeyHandler(mmi_imps_entry_chat_save, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1466. }
  1467. /*****************************************************************************
  1468.  * FUNCTION
  1469.  *  mmi_imps_entry_chat_save
  1470.  * DESCRIPTION
  1471.  *  Entry function of Save menu.
  1472.  * PARAMETERS
  1473.  *  void
  1474.  * RETURNS
  1475.  *  void
  1476.  *****************************************************************************/
  1477. void mmi_imps_entry_chat_save(void)
  1478. {
  1479.     /*----------------------------------------------------------------*/
  1480.     /* Local Variables                                                */
  1481.     /*----------------------------------------------------------------*/
  1482.     /*----------------------------------------------------------------*/
  1483.     /* Code Body                                                      */
  1484.     /*----------------------------------------------------------------*/
  1485.     if (pfnUnicodeStrlen((S8*) imps_p->room_info.room_list[imps_p->chat_info.curr_room].chat_buff) == 0)
  1486.     {
  1487.         mmi_imps_util_disp_err_popup(STR_ID_IMPS_EMPTY_INPUT);
  1488.     }
  1489.     else
  1490.     {
  1491.         FMGR_FILTER filter;
  1492.         FMGR_FILTER_INIT(&filter);
  1493.         FMGR_FILTER_SET(&filter, FMGR_TYPE_FOLDER);
  1494.         mmi_fmgr_select_path_and_enter(
  1495.             APP_IMPS,
  1496.             FMGR_SELECT_FOLDER,
  1497.             filter,
  1498.             (S8*) L"root",
  1499.             mmi_imps_chat_save_select_path_done);
  1500.     }
  1501. }
  1502. /*****************************************************************************
  1503.  * FUNCTION
  1504.  *  mmi_imps_chat_save_select_path_done
  1505.  * DESCRIPTION
  1506.  *  callback function when select path to save text finished.
  1507.  * PARAMETERS
  1508.  *  path            [?]         
  1509.  *  is_short        [IN]        
  1510.  * RETURNS
  1511.  *  void
  1512.  *****************************************************************************/
  1513. void mmi_imps_chat_save_select_path_done(void *path, int is_short)
  1514. {
  1515.     /*----------------------------------------------------------------*/
  1516.     /* Local Variables                                                */
  1517.     /*----------------------------------------------------------------*/
  1518.     /*----------------------------------------------------------------*/
  1519.     /* Code Body                                                      */
  1520.     /*----------------------------------------------------------------*/
  1521.     if (path)
  1522.     {
  1523.         imps_p->file_buff[0] = 0;
  1524.         pfnUnicodeStrcpy((S8*) imps_p->path_buff, (S8*) path);
  1525.         mmi_imps_entry_chat_save_filename();
  1526.     }
  1527.     else
  1528.     {
  1529.         GoBackToHistory(SCR_ID_IMPS_CHAT_OPT);
  1530.     }
  1531. }
  1532. /*****************************************************************************
  1533.  * FUNCTION
  1534.  *  mmi_imps_entry_chat_save_filename
  1535.  * DESCRIPTION
  1536.  *  Display screen for the user to enter file name for saving chat message
  1537.  * PARAMETERS
  1538.  *  void
  1539.  * RETURNS
  1540.  *  void
  1541.  *****************************************************************************/
  1542. void mmi_imps_entry_chat_save_filename(void)
  1543. {
  1544.     /*----------------------------------------------------------------*/
  1545.     /* Local Variables                                                */
  1546.     /*----------------------------------------------------------------*/
  1547.     U8 *guiBuffer;
  1548.     /*----------------------------------------------------------------*/
  1549.     /* Code Body                                                      */
  1550.     /*----------------------------------------------------------------*/
  1551.     EntryNewScreen(SCR_ID_IMPS_CHAT_FILENAME, NULL, mmi_imps_entry_chat_save_filename, NULL);
  1552.     SetParentHandler(0);
  1553.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_CHAT_FILENAME);
  1554.     ShowCategory5Screen(
  1555.         STR_GLOBAL_FILENAME,
  1556.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  1557.         STR_GLOBAL_OPTIONS,
  1558.         IMG_GLOBAL_OPTIONS,
  1559.         STR_GLOBAL_BACK,
  1560.         IMG_GLOBAL_BACK,
  1561.         INPUT_TYPE_ALPHANUMERIC_SENTENCECASE,
  1562.         (U8*) imps_p->file_buff,
  1563.         FMGR_MAX_INPUT_FILE_LEN,
  1564.         guiBuffer);
  1565.     SetLeftSoftkeyFunction(mmi_imps_entry_chat_save_opt, KEY_EVENT_UP);
  1566.     SetCategory5RightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1567. }
  1568. /*****************************************************************************
  1569.  * FUNCTION
  1570.  *  mmi_imps_entry_chat_save_opt
  1571.  * DESCRIPTION
  1572.  *  Display option screen for saving chat message.
  1573.  * PARAMETERS
  1574.  *  void
  1575.  * RETURNS
  1576.  *  void
  1577.  *****************************************************************************/
  1578. void mmi_imps_entry_chat_save_opt(void)
  1579. {
  1580.     /*----------------------------------------------------------------*/
  1581.     /* Local Variables                                                */
  1582.     /*----------------------------------------------------------------*/
  1583.     U16 numItems;
  1584.     U16 nStrItemList[2];
  1585.     U8 *guiBuffer;
  1586.     /*----------------------------------------------------------------*/
  1587.     /* Code Body                                                      */
  1588.     /*----------------------------------------------------------------*/
  1589.     EntryNewScreen(SCR_ID_IMPS_CHAT_SAVE_OPT, NULL, mmi_imps_entry_chat_save_opt, NULL);
  1590.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_CHAT_SAVE_OPT);
  1591.     SetParentHandler(MENU_ID_IMPS_CHAT_SAVE_OPT);
  1592.     numItems = GetNumOfChild(MENU_ID_IMPS_CHAT_SAVE_OPT);
  1593.     GetSequenceStringIds(MENU_ID_IMPS_CHAT_SAVE_OPT, nStrItemList);
  1594.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  1595.     ShowCategory52Screen(
  1596.         STR_GLOBAL_OPTIONS,
  1597.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  1598.         STR_GLOBAL_OK,
  1599.         IMG_GLOBAL_OK,
  1600.         STR_GLOBAL_BACK,
  1601.         IMG_GLOBAL_BACK,
  1602.         numItems,
  1603.         nStrItemList,
  1604.         (U16*) gIndexIconsImageList,
  1605.         NULL,
  1606.         0,
  1607.         0,
  1608.         guiBuffer);
  1609.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1610.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1611. }
  1612. /*****************************************************************************
  1613.  * FUNCTION
  1614.  *  mmi_imps_hilite_chat_save_opt_done
  1615.  * DESCRIPTION
  1616.  *  Highlight handler of Chat Save -> File Name -> Option -> Done
  1617.  * PARAMETERS
  1618.  *  void
  1619.  * RETURNS
  1620.  *  void
  1621.  *****************************************************************************/
  1622. void mmi_imps_hilite_chat_save_opt_done(void)
  1623. {
  1624.     /*----------------------------------------------------------------*/
  1625.     /* Local Variables                                                */
  1626.     /*----------------------------------------------------------------*/
  1627.     /*----------------------------------------------------------------*/
  1628.     /* Code Body                                                      */
  1629.     /*----------------------------------------------------------------*/
  1630.     SetLeftSoftkeyFunction(mmi_imps_chat_save_done, KEY_EVENT_UP);
  1631. }
  1632. /*****************************************************************************
  1633.  * FUNCTION
  1634.  *  mmi_imps_chat_save_done
  1635.  * DESCRIPTION
  1636.  *  LSK handler when confirm to save chat message
  1637.  * PARAMETERS
  1638.  *  void
  1639.  * RETURNS
  1640.  *  void
  1641.  *****************************************************************************/
  1642. void mmi_imps_chat_save_done(void)
  1643. {
  1644.     /*----------------------------------------------------------------*/
  1645.     /* Local Variables                                                */
  1646.     /*----------------------------------------------------------------*/
  1647.     S32 path_len = pfnUnicodeStrlen((S8*) imps_p->path_buff);
  1648.     S32 file_len = pfnUnicodeStrlen((S8*) imps_p->file_buff) + strlen(".txt");
  1649.     S8 *file_buff;
  1650.     /*----------------------------------------------------------------*/
  1651.     /* Code Body                                                      */
  1652.     /*----------------------------------------------------------------*/
  1653.     if (file_len == 0)
  1654.     {
  1655.         mmi_imps_util_disp_err_popup(STR_ID_IMPS_EMPTY_FILENAME);
  1656.         return;
  1657.     }
  1658.     if ((path_len + file_len) > FMGR_MAX_PATH_LEN)
  1659.     {
  1660.         mmi_imps_util_disp_err_popup(STR_ID_IMPS_FILENAME_TOO_LONG);
  1661.         return;
  1662.     }
  1663.     file_buff = OslMalloc((FMGR_MAX_PATH_LEN + 1)*ENCODING_LENGTH);
  1664.     pfnUnicodeStrcpy((S8*) file_buff, (S8*) imps_p->path_buff);
  1665.     pfnUnicodeStrcat((S8*) file_buff, (S8*) imps_p->file_buff);
  1666.     pfnUnicodeStrcat((S8*) file_buff, (S8*) L".txt");
  1667.     if (mmi_imps_util_check_file_exist(file_buff))
  1668.     {
  1669.         mmi_imps_util_disp_err_popup(STR_ID_IMPS_DUPLICATE_FILENAME);
  1670.     }
  1671.     else
  1672.     {
  1673.         FS_HANDLE fileHandle;
  1674.         fileHandle = FS_Open((U16*) file_buff, FS_CREATE_ALWAYS);
  1675.         if (fileHandle > 0)
  1676.         {
  1677.             S32 result;
  1678.             U32 len;
  1679.             wgui_color_buffer_reader_struct reader;
  1680.             S8 *out_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  1681.             /* create reader and strip color related markers */
  1682.             wgui_color_buffer_create_reader(
  1683.                 &reader,
  1684.                 (U8*) imps_p->room_info.room_list[imps_p->chat_info.curr_room].chat_buff);
  1685.             wgui_color_buffer_read_stripped_text(
  1686.                 &reader,
  1687.                 (U8*) out_buff,
  1688.                 IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH,
  1689.                 (S32*) & len);
  1690.             /* UCS2 string prefix */
  1691.             result = FS_Write(fileHandle, (void*)g_imps_ucs2_file_prefix, 2, &len);
  1692.             result = FS_Write(
  1693.                         fileHandle,
  1694.                         (void*)out_buff,
  1695.                         (pfnUnicodeStrlen((S8*) imps_p->room_info.room_list[imps_p->chat_info.curr_room].chat_buff) * ENCODING_LENGTH),
  1696.                         &len);
  1697.             FS_Close(fileHandle);
  1698.             if (result < 0)
  1699.             {
  1700.                 mmi_imps_util_disp_err_popup(GetFileSystemErrorString(result));
  1701.             }
  1702.             else
  1703.             {
  1704.                 mmi_imps_util_disp_popup_done();
  1705.                 DeleteUptoScrID(SCR_ID_IMPS_CHAT);
  1706.             }
  1707.             OslMfree(out_buff);
  1708.         }
  1709.         else
  1710.         {
  1711.             mmi_imps_util_disp_err_popup(GetFileSystemErrorString(fileHandle));
  1712.         }
  1713.     }
  1714.     OslMfree(file_buff);
  1715. }
  1716. /*****************************************************************************
  1717.  * FUNCTION
  1718.  *  mmi_imps_hilite_chat_close
  1719.  * DESCRIPTION
  1720.  *  Highlight handler of Close Chat Room menu.
  1721.  * PARAMETERS
  1722.  *  void
  1723.  * RETURNS
  1724.  *  void
  1725.  *****************************************************************************/
  1726. void mmi_imps_hilite_chat_close(void)
  1727. {
  1728.     /*----------------------------------------------------------------*/
  1729.     /* Local Variables                                                */
  1730.     /*----------------------------------------------------------------*/
  1731.     /*----------------------------------------------------------------*/
  1732.     /* Code Body                                                      */
  1733.     /*----------------------------------------------------------------*/
  1734.     SetLeftSoftkeyFunction(mmi_imps_entry_chat_close, KEY_EVENT_UP);
  1735.     SetKeyHandler(mmi_imps_entry_chat_close, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1736. }
  1737. /*****************************************************************************
  1738.  * FUNCTION
  1739.  *  mmi_imps_entry_chat_close
  1740.  * DESCRIPTION
  1741.  *  Entry function of Close Chat Room menu.
  1742.  * PARAMETERS
  1743.  *  void
  1744.  * RETURNS
  1745.  *  void
  1746.  *****************************************************************************/
  1747. void mmi_imps_entry_chat_close(void)
  1748. {
  1749.     /*----------------------------------------------------------------*/
  1750.     /* Local Variables                                                */
  1751.     /*----------------------------------------------------------------*/
  1752.     /*----------------------------------------------------------------*/
  1753.     /* Code Body                                                      */
  1754.     /*----------------------------------------------------------------*/
  1755.     mmi_imps_entry_confirm(STR_GLOBAL_CLOSE, mmi_imps_chat_close, GoBackHistory);
  1756. }
  1757. /*****************************************************************************
  1758.  * FUNCTION
  1759.  *  mmi_imps_chat_close
  1760.  * DESCRIPTION
  1761.  *  Confirm to close a chat room
  1762.  * PARAMETERS
  1763.  *  void
  1764.  * RETURNS
  1765.  *  void
  1766.  *****************************************************************************/
  1767. void mmi_imps_chat_close(void)
  1768. {
  1769.     /*----------------------------------------------------------------*/
  1770.     /* Local Variables                                                */
  1771.     /*----------------------------------------------------------------*/
  1772.     /* if it's a group, shall send request to protocol */
  1773.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[imps_p->chat_info.curr_room];
  1774.     /*----------------------------------------------------------------*/
  1775.     /* Code Body                                                      */
  1776.     /*----------------------------------------------------------------*/
  1777. #ifndef IMPS_TEST_CODE
  1778.     if (room->type == IMPS_ROOM_TYPE_GROUP_CREATE)
  1779.     {
  1780.         /* send delete group request */
  1781.         mmi_imps_display_progressing();
  1782.         mmi_imps_ps_del_group_req(room->room_id);
  1783.     }
  1784.     else if (room->type == IMPS_ROOM_TYPE_GROUP_JOIN)
  1785.     {
  1786.         /* send leave group request */
  1787.         mmi_imps_display_progressing();
  1788.         mmi_imps_ps_leave_group_req(room->room_id);
  1789.     }
  1790.     else
  1791.     {
  1792.         /* single talk */
  1793.         mmi_imps_room_close_finished(room);
  1794.         mmi_imps_pre_entry_cont();
  1795.         DeleteScreenIfPresent(SCR_ID_IMPS_CHAT);
  1796.         DeleteScreenIfPresent(SCR_ID_IMPS_CHAT_OPT);
  1797.     }
  1798. #else /* IMPS_TEST_CODE */ 
  1799.     mmi_imps_pre_entry_cont();
  1800.     DeleteScreenIfPresent(SCR_ID_IMPS_CHAT);
  1801.     DeleteScreenIfPresent(SCR_ID_IMPS_CHAT_OPT);
  1802.     mmi_imps_room_close_finished(room);
  1803. #endif /* IMPS_TEST_CODE */ 
  1804. }
  1805. /*****************************************************************************
  1806.  * FUNCTION
  1807.  *  mmi_imps_room_close_finished
  1808.  * DESCRIPTION
  1809.  *  Reset context of chat room when finish closing chat room
  1810.  * PARAMETERS
  1811.  *  room        [?]     
  1812.  * RETURNS
  1813.  *  void
  1814.  *****************************************************************************/
  1815. void mmi_imps_room_close_finished(mmi_imps_room_struct *room)
  1816. {
  1817.     /*----------------------------------------------------------------*/
  1818.     /* Local Variables                                                */
  1819.     /*----------------------------------------------------------------*/
  1820.     S32 i;
  1821.     /*----------------------------------------------------------------*/
  1822.     /* Code Body                                                      */
  1823.     /*----------------------------------------------------------------*/
  1824.     /* reset status icon of contact list */
  1825.     if (room->type == IMPS_ROOM_TYPE_SINGLE)
  1826.     {
  1827.         /* reset status icon of contact */
  1828.         for (i = 1; i < imps_p->cont_info.no_cont; i++)
  1829.         {
  1830.             if (mmi_imps_util_is_id_same((S8*) room->member[0].id, (S8*) imps_p->cont_info.cont_list[i].id))
  1831.             {
  1832.                 /* contact list found, unset new message state */
  1833.                 imps_p->cont_info.cont_list[i].comm_state &= ~IMPS_CONT_NEW_MSG;
  1834.                 break;
  1835.             }
  1836.         }
  1837.     }
  1838.     imps_p->chat_info.curr_room = 0;
  1839.     imps_p->room_info.curr_item = 0;
  1840.     imps_p->room_info.no_rooms--;
  1841.     mmi_imps_tab_del(room->tab_index, 0);
  1842.     mmi_imps_room_reset_cntx(room);
  1843.     mmi_imps_util_update_status_icon();
  1844. }
  1845. /*****************************************************************************
  1846.  * FUNCTION
  1847.  *  mmi_imps_close_chat_room_done
  1848.  * DESCRIPTION
  1849.  *  Callback handler when close chat room finished
  1850.  * PARAMETERS
  1851.  *  result      [IN]        Error cause of result
  1852.  * RETURNS
  1853.  *  void
  1854.  *****************************************************************************/
  1855. void mmi_imps_close_chat_room_done(S32 result)
  1856. {
  1857.     /*----------------------------------------------------------------*/
  1858.     /* Local Variables                                                */
  1859.     /*----------------------------------------------------------------*/
  1860.     /* finished close chat room */
  1861.     mmi_imps_room_struct *room = &imps_p->room_info.room_list[imps_p->chat_info.curr_room];
  1862.     BOOL chat_present = IsScreenPresent(SCR_ID_IMPS_CHAT);
  1863.     /*----------------------------------------------------------------*/
  1864.     /* Code Body                                                      */
  1865.     /*----------------------------------------------------------------*/
  1866.     if (result != IMPS_OK)
  1867.     {
  1868.         if (imps_p->gen_info.is_reentry)
  1869.         {
  1870.             mmi_imps_re_entry_app();
  1871.             mmi_imps_util_disp_err_popup(mmi_imps_util_get_err_str(result));
  1872.         }
  1873.         else
  1874.         {
  1875.             mmi_imps_util_disp_err_popup(mmi_imps_util_get_err_str(result));
  1876.             if (chat_present)   /* entry from chat screen */
  1877.             {
  1878.                 mmi_imps_util_del_scr_after_progress(SCR_ID_IMPS_CHAT);
  1879.             }
  1880.             else    /* entry from room list */
  1881.             {
  1882.                 mmi_imps_util_del_scr_after_progress(SCR_ID_IMPS_CHAT_ROOM_OPT);
  1883.             }
  1884.         }
  1885.     }
  1886.     else    /* close finished */
  1887.     {
  1888.         /* update tab info, delete one tab */
  1889.         mmi_imps_room_close_finished(room);
  1890.         if (imps_p->gen_info.is_reentry)
  1891.         {
  1892.             mmi_imps_re_entry_app();
  1893.         }
  1894.         else
  1895.         {
  1896.             if (IsScreenPresent(SCR_ID_IMPS_CHAT))  /* entry from chat screen */
  1897.             {
  1898.                 /* single talk */
  1899.                 if (GetActiveScreenId() == SCR_ID_IMPS_PROGRESS)
  1900.                 {
  1901.                     mmi_imps_pre_entry_cont();
  1902.                     DeleteScreenIfPresent(SCR_ID_IMPS_CHAT_OPT);
  1903.                     DeleteScreenIfPresent(SCR_ID_IMPS_PROGRESS);
  1904.                 }
  1905.                 else
  1906.                 {
  1907.                     mmi_imps_util_del_scr_after_progress(SCR_ID_IMPS_CHAT);
  1908.                     HistoryReplace(SCR_ID_IMPS_CHAT, SCR_ID_IMPS_CONT, mmi_imps_pre_entry_cont);
  1909.                 }
  1910.             }
  1911.             else
  1912.             {
  1913.                 /* alyways regarded as success */
  1914.                 mmi_imps_util_disp_popup_done();
  1915.                 mmi_imps_util_del_scr_after_progress(SCR_ID_IMPS_CHAT_ROOM);
  1916.             }
  1917.         }
  1918.     }
  1919. }
  1920. #define INVITE_IMPS
  1921. /*****************************************************************************
  1922.  * FUNCTION
  1923.  *  mmi_imps_hilite_chat_invite
  1924.  * DESCRIPTION
  1925.  *  Highlight handler of Invite Friend menu.
  1926.  * PARAMETERS
  1927.  *  void
  1928.  * RETURNS
  1929.  *  void
  1930.  *****************************************************************************/
  1931. void mmi_imps_hilite_chat_invite(void)
  1932. {
  1933.     /*----------------------------------------------------------------*/
  1934.     /* Local Variables                                                */
  1935.     /*----------------------------------------------------------------*/
  1936.     /*----------------------------------------------------------------*/
  1937.     /* Code Body                                                      */
  1938.     /*----------------------------------------------------------------*/
  1939.     SetLeftSoftkeyFunction(mmi_imps_pre_entry_chat_invite, KEY_EVENT_UP);
  1940.     SetKeyHandler(mmi_imps_pre_entry_chat_invite, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1941. }
  1942. /*****************************************************************************
  1943.  * FUNCTION
  1944.  *  mmi_imps_pre_entry_chat_invite
  1945.  * DESCRIPTION
  1946.  *  Pre-Entry function of Invite menu.
  1947.  * PARAMETERS
  1948.  *  void
  1949.  * RETURNS
  1950.  *  void
  1951.  *****************************************************************************/
  1952. void mmi_imps_pre_entry_chat_invite(void)
  1953. {
  1954.     /*----------------------------------------------------------------*/
  1955.     /* Local Variables                                                */
  1956.     /*----------------------------------------------------------------*/
  1957.     S32 i, j, k, no_cont, no_member;
  1958.     mmi_imps_room_struct *room;
  1959.     mmi_imps_cont_struct *cont;
  1960.     /*----------------------------------------------------------------*/
  1961.     /* Code Body                                                      */
  1962.     /*----------------------------------------------------------------*/
  1963.     no_cont = (S32) imps_p->cont_info.no_cont;
  1964.     room = &imps_p->room_info.room_list[imps_p->chat_info.curr_room];
  1965.     no_member = (S32) room->no_member;
  1966.     k = 0;
  1967.     for (i = 1; i < no_cont; i++)   /* neglect MySelf */
  1968.     {
  1969.         cont = &imps_p->cont_info.cont_list[i];
  1970.         if (cont->availability == IMPS_PA_USER_NOT_AVAILABLE || cont->availability == IMPS_PA_USER_UNKNOWN)
  1971.         {
  1972.             continue;
  1973.         }
  1974.         for (j = 0; j < IMPS_MAX_ENTITY_NUMBER; j++)
  1975.             if (mmi_imps_util_is_id_same((S8*) room->member[j].id, (S8*) cont->id))
  1976.             {
  1977.                 break;
  1978.             }
  1979.         if (j == IMPS_MAX_ENTITY_NUMBER)    /* user not in chat room */
  1980.         {
  1981.             mmi_imps_util_ansi_2_ucs2_menu((S8*) cont->id, (S8*) subMenuData[k], MAX_SUBMENU_CHARACTERS);
  1982.             mmi_imps_util_generate_name_hint((S8*) cont->nick_name, k, MAX_SUBMENU_CHARACTERS);
  1983.             imps_p->invite_info.invite_cand_list[k] = (U8) i;
  1984.             subMenuDataPtrs[k] = subMenuData[k];
  1985.             k++;
  1986.         }
  1987.     }
  1988.     imps_p->invite_info.invite_count = (U8) k;
  1989.     mmi_imps_entry_chat_invite();
  1990. }
  1991. /*****************************************************************************
  1992.  * FUNCTION
  1993.  *  mmi_imps_entry_chat_invite
  1994.  * DESCRIPTION
  1995.  *  Entry function of Invite menu.
  1996.  * PARAMETERS
  1997.  *  void
  1998.  * RETURNS
  1999.  *  void
  2000.  *****************************************************************************/
  2001. void mmi_imps_entry_chat_invite(void)
  2002. {
  2003.     /*----------------------------------------------------------------*/
  2004.     /* Local Variables                                                */
  2005.     /*----------------------------------------------------------------*/
  2006.     U8 *guiBuffer;
  2007.     U16 icon_list[IMPS_MAX_NO_CONT];
  2008.     S32 i;
  2009.     S32 count = (S32) imps_p->invite_info.invite_count;
  2010.     /*----------------------------------------------------------------*/
  2011.     /* Code Body                                                      */
  2012.     /*----------------------------------------------------------------*/
  2013.     if (count == 0)
  2014.     {
  2015.         mmi_imps_util_disp_empty_popup();
  2016.         return;
  2017.     }
  2018.     EntryNewScreen(SCR_ID_IMPS_INVITE, NULL, mmi_imps_entry_chat_invite, NULL);
  2019.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_INVITE);
  2020.     SetParentHandler(0);
  2021.     RegisterHighlightHandler(mmi_imps_hilite_invite_item);
  2022.     for (i = 0; i < count; i++)
  2023.     {
  2024.         icon_list[i] = IMG_ID_IMPS_ABOUT_ONLINE;
  2025.     }
  2026.     ShowCategory53Screen(
  2027.         STR_ID_IMPS_INVITE,
  2028.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  2029.         STR_GLOBAL_OK,
  2030.         IMG_GLOBAL_OK,
  2031.         STR_GLOBAL_BACK,
  2032.         IMG_GLOBAL_BACK,
  2033.         count,
  2034.         (U8 **) subMenuDataPtrs,
  2035.         (U16*) icon_list,
  2036.         (U8 **) hintDataPtrs,
  2037.         0,
  2038.         0,
  2039.         guiBuffer);
  2040.     SetLeftSoftkeyFunction(mmi_imps_entry_invite_note, KEY_EVENT_UP);
  2041.     SetKeyHandler(mmi_imps_entry_invite_note, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  2042.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  2043.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  2044. }
  2045. /*****************************************************************************
  2046.  * FUNCTION
  2047.  *  mmi_imps_hilite_invite_item
  2048.  * DESCRIPTION
  2049.  *  Highlight handler of invite candidate list
  2050.  * PARAMETERS
  2051.  *  index       [IN]        Index of highlighting item
  2052.  * RETURNS
  2053.  *  void
  2054.  *****************************************************************************/
  2055. void mmi_imps_hilite_invite_item(S32 index)
  2056. {
  2057.     /*----------------------------------------------------------------*/
  2058.     /* Local Variables                                                */
  2059.     /*----------------------------------------------------------------*/
  2060.     /*----------------------------------------------------------------*/
  2061.     /* Code Body                                                      */
  2062.     /*----------------------------------------------------------------*/
  2063.     imps_p->invite_info.curr_sel_cont = (U8) index;
  2064. }
  2065. /*****************************************************************************
  2066.  * FUNCTION
  2067.  *  mmi_imps_entry_invite_note
  2068.  * DESCRIPTION
  2069.  *  Entry function to input inviting note
  2070.  * PARAMETERS
  2071.  *  void
  2072.  * RETURNS
  2073.  *  void
  2074.  *****************************************************************************/
  2075. void mmi_imps_entry_invite_note(void)
  2076. {
  2077.     /*----------------------------------------------------------------*/
  2078.     /* Local Variables                                                */
  2079.     /*----------------------------------------------------------------*/
  2080.     U8 *guiBuffer;
  2081.     /*----------------------------------------------------------------*/
  2082.     /* Code Body                                                      */
  2083.     /*----------------------------------------------------------------*/
  2084.     EntryNewScreen(SCR_ID_IMPS_INVITE_NOTE, NULL, mmi_imps_entry_invite_note, NULL);
  2085.     SetParentHandler(0);
  2086.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_INVITE_NOTE);
  2087.     if (guiBuffer == NULL)  /* first time entry, reset input buffer */
  2088.     {
  2089.         imps_p->path_buff[0] = 0;
  2090.     }
  2091.     ShowCategory5Screen(
  2092.         STR_ID_IMPS_INVITE_NOTE,
  2093.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  2094.         STR_GLOBAL_OPTIONS,
  2095.         IMG_GLOBAL_OPTIONS,
  2096.         STR_GLOBAL_BACK,
  2097.         IMG_GLOBAL_BACK,
  2098.         INPUT_TYPE_ALPHANUMERIC_SENTENCECASE,
  2099.         (U8*) imps_p->path_buff,    /* reuse path buffer */
  2100.         IMPS_MAX_NOTE_LEN,
  2101.         guiBuffer);
  2102.     SetLeftSoftkeyFunction(mmi_imps_entry_invite_note_opt, KEY_EVENT_UP);
  2103.     SetCategory5RightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  2104. }
  2105. /*****************************************************************************
  2106.  * FUNCTION
  2107.  *  mmi_imps_entry_invite_note_opt
  2108.  * DESCRIPTION
  2109.  *  Display options for inviting note
  2110.  * PARAMETERS
  2111.  *  void
  2112.  * RETURNS
  2113.  *  void
  2114.  *****************************************************************************/
  2115. void mmi_imps_entry_invite_note_opt(void)
  2116. {
  2117.     /*----------------------------------------------------------------*/
  2118.     /* Local Variables                                                */
  2119.     /*----------------------------------------------------------------*/
  2120.     U16 numItems;
  2121.     U16 nStrItemList[2];
  2122.     U8 *guiBuffer;
  2123.     /*----------------------------------------------------------------*/
  2124.     /* Code Body                                                      */
  2125.     /*----------------------------------------------------------------*/
  2126.     EntryNewScreen(SCR_ID_IMPS_CHAT_NOTE_OPT, NULL, mmi_imps_entry_invite_note_opt, NULL);
  2127.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_CHAT_NOTE_OPT);
  2128.     SetParentHandler(MENU_ID_IMPS_ROOM_INVITE_OPT);
  2129.     numItems = GetNumOfChild(MENU_ID_IMPS_ROOM_INVITE_OPT);
  2130.     GetSequenceStringIds(MENU_ID_IMPS_ROOM_INVITE_OPT, nStrItemList);
  2131.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  2132.     ShowCategory52Screen(
  2133.         STR_GLOBAL_OPTIONS,
  2134.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  2135.         STR_GLOBAL_OK,
  2136.         IMG_GLOBAL_OK,
  2137.         STR_GLOBAL_BACK,
  2138.         IMG_GLOBAL_BACK,
  2139.         numItems,
  2140.         nStrItemList,
  2141.         (U16*) gIndexIconsImageList,
  2142.         NULL,
  2143.         0,
  2144.         0,
  2145.         guiBuffer);
  2146.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  2147.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  2148. }
  2149. /*****************************************************************************
  2150.  * FUNCTION
  2151.  *  mmi_imps_hilite_invite_note_opt_done
  2152.  * DESCRIPTION
  2153.  *  Highlight handler of List Member menu.
  2154.  * PARAMETERS
  2155.  *  void
  2156.  * RETURNS
  2157.  *  void
  2158.  *****************************************************************************/
  2159. void mmi_imps_hilite_invite_note_opt_done(void)
  2160. {
  2161.     /*----------------------------------------------------------------*/
  2162.     /* Local Variables                                                */
  2163.     /*----------------------------------------------------------------*/
  2164.     /*----------------------------------------------------------------*/
  2165.     /* Code Body                                                      */
  2166.     /*----------------------------------------------------------------*/
  2167.     SetLeftSoftkeyFunction(mmi_imps_invite_done, KEY_EVENT_UP);
  2168. }
  2169. /*****************************************************************************
  2170.  * FUNCTION
  2171.  *  mmi_imps_invite_done
  2172.  * DESCRIPTION
  2173.  *  Finish invitation input and start inviting
  2174.  * PARAMETERS
  2175.  *  void
  2176.  * RETURNS
  2177.  *  void
  2178.  *****************************************************************************/
  2179. void mmi_imps_invite_done(void)
  2180. {
  2181.     /*----------------------------------------------------------------*/
  2182.     /* Local Variables                                                */
  2183.     /*----------------------------------------------------------------*/
  2184.     /* check if all sessions are occupied */
  2185.     S32 session_id = mmi_imps_invite_insert_session();
  2186.     /*----------------------------------------------------------------*/
  2187.     /* Code Body                                                      */
  2188.     /*----------------------------------------------------------------*/
  2189.     if (session_id == 0)
  2190.     {
  2191.         mmi_imps_invite_disp_failed_msg();
  2192.         mmi_imps_util_play_tone(IMPS_ERR_TONE);
  2193.     }
  2194.     else
  2195.     {
  2196.         mmi_imps_invite_disp_msg();
  2197.         imps_p->room_info.room_list[imps_p->chat_info.curr_room].clear_gui_buff = TRUE;
  2198.     #ifndef IMPS_TEST_CODE
  2199.         mmi_imps_ps_invite_req(session_id);
  2200.     #else /* IMPS_TEST_CODE */ 
  2201.         SetKeyHandler(mmi_imps_test_invite_success, KEY_STAR, KEY_EVENT_DOWN);
  2202.         SetKeyHandler(mmi_imps_test_invite_failed, KEY_POUND, KEY_EVENT_DOWN);
  2203.     #endif /* IMPS_TEST_CODE */ 
  2204.     }
  2205.     GoBackToHistory(SCR_ID_IMPS_CHAT);
  2206. }
  2207. /*****************************************************************************
  2208.  * FUNCTION
  2209.  *  mmi_imps_invite_insert_session
  2210.  * DESCRIPTION
  2211.  *  insert Invitation to session list
  2212.  * PARAMETERS
  2213.  *  void
  2214.  * RETURNS
  2215.  *  session index
  2216.  *****************************************************************************/
  2217. S32 mmi_imps_invite_insert_session(void)
  2218. {
  2219.     /*----------------------------------------------------------------*/
  2220.     /* Local Variables                                                */
  2221.     /*----------------------------------------------------------------*/
  2222.     S32 i;
  2223.     /*----------------------------------------------------------------*/
  2224.     /* Code Body                                                      */
  2225.     /*----------------------------------------------------------------*/
  2226.     for (i = 0; i < IMPS_MAX_INVITEE_SESSION; i++)
  2227.         if (imps_p->invite_info.invite_session[i].session_id == 0)
  2228.         {
  2229.             break;
  2230.         }
  2231.     if (i == IMPS_MAX_INVITEE_SESSION)
  2232.     {
  2233.         return 0;
  2234.     }
  2235.     else
  2236.     {
  2237.         mmi_imps_invite_session_struct *session = &imps_p->invite_info.invite_session[i];
  2238.         session->session_id = mmi_imps_util_get_seq_no();
  2239.         strcpy(
  2240.             (S8*) session->cont_id,
  2241.             (S8*) imps_p->cont_info.cont_list[imps_p->invite_info. invite_cand_list[imps_p->invite_info.curr_sel_cont]].id);
  2242.         strcpy((S8*) session->room_id, (S8*) imps_p->room_info.room_list[imps_p->chat_info.curr_room].room_id);
  2243.         return session->session_id;
  2244.     }
  2245. }
  2246. /*****************************************************************************
  2247.  * FUNCTION
  2248.  *  mmi_imps_invite_disp_msg
  2249.  * DESCRIPTION
  2250.  *  Display invitation message in chat buffer.
  2251.  * PARAMETERS
  2252.  *  void
  2253.  * RETURNS
  2254.  *  void
  2255.  *****************************************************************************/
  2256. void mmi_imps_invite_disp_msg(void)
  2257. {
  2258.     /*----------------------------------------------------------------*/
  2259.     /* Local Variables                                                */
  2260.     /*----------------------------------------------------------------*/
  2261.     U16 *tmp_cont_buff;
  2262.     U16 *tmp_disp_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  2263.     mmi_imps_cont_struct *cont =
  2264.         &imps_p->cont_info.cont_list[imps_p->invite_info.invite_cand_list[imps_p->invite_info.curr_sel_cont]];
  2265.     /*----------------------------------------------------------------*/
  2266.     /* Code Body                                                      */
  2267.     /*----------------------------------------------------------------*/
  2268.     /* insert input into buffer */
  2269.     pfnUnicodeStrcpy((S8*) tmp_disp_buff, (S8*) GetString(STR_ID_IMPS_INVITING));
  2270.     pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) L" ");
  2271.     if (pfnUnicodeStrlen((S8*) cont->nick_name))
  2272.     {
  2273.         pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) cont->nick_name);
  2274.     }
  2275.     else
  2276.     {
  2277.         tmp_cont_buff = OslMalloc(IMPS_MAX_ID_LEN * ENCODING_LENGTH);
  2278.         AnsiiToUnicodeString((S8*) tmp_cont_buff, (S8*) cont->id);
  2279.         pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) tmp_cont_buff);
  2280.         OslMfree(tmp_cont_buff);
  2281.     }
  2282.     pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) L"nn");
  2283.     mmi_imps_chat_flush_msg(tmp_disp_buff, imps_p->chat_info.curr_room);
  2284.     OslMfree(tmp_disp_buff);
  2285. }
  2286. /*****************************************************************************
  2287.  * FUNCTION
  2288.  *  mmi_imps_invite_disp_failed_msg
  2289.  * DESCRIPTION
  2290.  *  Display invitation failed message.
  2291.  * PARAMETERS
  2292.  *  void
  2293.  * RETURNS
  2294.  *  void
  2295.  *****************************************************************************/
  2296. void mmi_imps_invite_disp_failed_msg(void)
  2297. {
  2298.     /*----------------------------------------------------------------*/
  2299.     /* Local Variables                                                */
  2300.     /*----------------------------------------------------------------*/
  2301.     U16 *tmp_disp_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  2302.     mmi_imps_cont_struct *cont =
  2303.         &imps_p->cont_info.cont_list[imps_p->invite_info.invite_cand_list[imps_p->invite_info.curr_sel_cont]];
  2304.     wgui_color_buffer_writer_struct writer;
  2305.     BOOL result;
  2306.     /*----------------------------------------------------------------*/
  2307.     /* Code Body                                                      */
  2308.     /*----------------------------------------------------------------*/
  2309.     tmp_disp_buff[0] = 0;
  2310.     wgui_color_buffer_create_writer(&writer, (U8*) tmp_disp_buff, IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  2311.     wgui_color_buffer_write_char(&writer, GUI_INPUT_COLOR_00);
  2312.     wgui_color_buffer_write_string(&writer, (U8*) GetString(STR_ID_IMPS_INVITE_FAIL), MMI_FALSE, &result);
  2313.     /* insert input into buffer */
  2314.     wgui_color_buffer_write_char(&writer, ' ');
  2315.     if (pfnUnicodeStrlen((S8*) cont->nick_name))
  2316.     {
  2317.         wgui_color_buffer_write_string(&writer, (U8*) cont->nick_name, MMI_FALSE, &result);
  2318.     }
  2319.     else
  2320.     {
  2321.         U16 *tmp_id_buff;
  2322.         tmp_id_buff = OslMalloc(IMPS_MAX_ID_LEN * ENCODING_LENGTH);
  2323.         AnsiiToUnicodeString((S8*) tmp_id_buff, (S8*) cont->id);
  2324.         wgui_color_buffer_write_string(&writer, (U8*) tmp_id_buff, MMI_FALSE, &result);
  2325.         OslMfree(tmp_id_buff);
  2326.     }
  2327.     wgui_color_buffer_write_char(&writer, GUI_INPUT_MARKER_RESET_ALL);
  2328.     wgui_color_buffer_write_string(&writer, (U8*) L"nn", MMI_FALSE, &result);
  2329.     mmi_imps_chat_flush_msg(tmp_disp_buff, imps_p->chat_info.curr_room);
  2330.     OslMfree(tmp_disp_buff);
  2331. }
  2332. /*****************************************************************************
  2333.  * FUNCTION
  2334.  *  mmi_imps_invite_rsp_success_msg
  2335.  * DESCRIPTION
  2336.  *  Display invitation failed message.
  2337.  * PARAMETERS
  2338.  *  session     [IN]        Invitation session
  2339.  *  sname       [IN]        Screen name of the invitee
  2340.  * RETURNS
  2341.  *  void
  2342.  *****************************************************************************/
  2343. void mmi_imps_invite_rsp_success_msg(mmi_imps_invite_session_struct *session, S8 *sname)
  2344. {
  2345.     /*----------------------------------------------------------------*/
  2346.     /* Local Variables                                                */
  2347.     /*----------------------------------------------------------------*/
  2348.     U16 *tmp_disp_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  2349.     S32 i;
  2350.     /*----------------------------------------------------------------*/
  2351.     /* Code Body                                                      */
  2352.     /*----------------------------------------------------------------*/
  2353.     /* insert input into buffer */
  2354.     if (pfnUnicodeStrlen(sname))
  2355.     {
  2356.         pfnUnicodeStrcpy((S8*) tmp_disp_buff, (S8*) sname);
  2357.     }
  2358.     else    /* no screen name */
  2359.     {
  2360.         AnsiiToUnicodeString((S8*) tmp_disp_buff, (S8*) session->cont_id);
  2361.     }
  2362.     pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) L" ");
  2363.     pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) GetString(STR_ID_IMPS_JOINED_ROOM));
  2364.     pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) L"n");
  2365.     /* find out the room index */
  2366.     for (i = 0; i < IMPS_MAX_NO_ROOM; i++)
  2367.     {
  2368.         if (mmi_imps_util_is_id_same((S8*) session->room_id, (S8*) imps_p->room_info.room_list[i].room_id))
  2369.         {
  2370.             break;
  2371.         }
  2372.     }
  2373.     MMI_ASSERT(i < IMPS_MAX_NO_ROOM);
  2374.     mmi_imps_chat_flush_msg(tmp_disp_buff, i);
  2375.     OslMfree(tmp_disp_buff);
  2376. }
  2377. /*****************************************************************************
  2378.  * FUNCTION
  2379.  *  mmi_imps_invite_rsp_failed_msg
  2380.  * DESCRIPTION
  2381.  *  Display invitation failed message.
  2382.  * PARAMETERS
  2383.  *  session     [?]     
  2384.  * RETURNS
  2385.  *  void
  2386.  *****************************************************************************/
  2387. void mmi_imps_invite_rsp_failed_msg(mmi_imps_invite_session_struct *session)
  2388. {
  2389.     /*----------------------------------------------------------------*/
  2390.     /* Local Variables                                                */
  2391.     /*----------------------------------------------------------------*/
  2392.     S32 i;
  2393.     U16 *tmp_disp_buff = OslMalloc(IMPS_MAX_CHAT_BUFF * ENCODING_LENGTH);
  2394.     U16 *tmp_id_buff = OslMalloc(IMPS_MAX_ID_LEN * ENCODING_LENGTH);
  2395.     S32 cont_index;
  2396.     mmi_imps_cont_struct *cont;
  2397.     /*----------------------------------------------------------------*/
  2398.     /* Code Body                                                      */
  2399.     /*----------------------------------------------------------------*/
  2400.     cont_index = mmi_imps_util_find_cont((S8*) session->cont_id);
  2401.     if (cont_index == imps_p->cont_info.no_cont)    /* nobody found */
  2402.     {
  2403.         AnsiiToUnicodeString((S8*) tmp_id_buff, (S8*) session->cont_id);
  2404.     }
  2405.     else
  2406.     {
  2407.         cont = &imps_p->cont_info.cont_list[cont_index];
  2408.         if (pfnUnicodeStrlen((S8*) cont->nick_name))
  2409.         {
  2410.             pfnUnicodeStrcpy((S8*) tmp_id_buff, (S8*) cont->nick_name);
  2411.         }
  2412.         else
  2413.         {
  2414.             AnsiiToUnicodeString((S8*) tmp_id_buff, (S8*) session->cont_id);
  2415.         }
  2416.     }
  2417.     /* insert input into buffer */
  2418.     pfnUnicodeStrcpy((S8*) tmp_disp_buff, (S8*) GetString(STR_ID_IMPS_INVITE_FAIL));
  2419.     pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) L" ");
  2420.     pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) tmp_id_buff);
  2421.     pfnUnicodeStrcat((S8*) tmp_disp_buff, (S8*) L"nn");
  2422.     OslMfree(tmp_id_buff);
  2423.     /* find out the room index */
  2424.     for (i = 0; i < IMPS_MAX_NO_ROOM; i++)
  2425.     {
  2426.         if (mmi_imps_util_is_id_same((S8*) session->room_id, (S8*) imps_p->room_info.room_list[i].room_id))
  2427.         {
  2428.             break;
  2429.         }
  2430.     }
  2431.     MMI_ASSERT(i < IMPS_MAX_NO_ROOM);
  2432.     mmi_imps_chat_flush_msg(tmp_disp_buff, i);
  2433.     OslMfree(tmp_disp_buff);
  2434. }
  2435. /*****************************************************************************
  2436.  * FUNCTION
  2437.  *  mmi_imps_invite_start
  2438.  * DESCRIPTION
  2439.  *  Start invitation process in PS
  2440.  * PARAMETERS
  2441.  *  result      [IN]        Result of invitation
  2442.  *  id          [IN]        Session index
  2443.  * RETURNS
  2444.  *  void
  2445.  *****************************************************************************/
  2446. void mmi_imps_invite_start(S32 result, S32 id)
  2447. {
  2448.     /*----------------------------------------------------------------*/
  2449.     /* Local Variables                                                */
  2450.     /*----------------------------------------------------------------*/
  2451.     S32 i;
  2452.     mmi_imps_invite_session_struct *session = NULL;
  2453.     /*----------------------------------------------------------------*/
  2454.     /* Code Body                                                      */
  2455.     /*----------------------------------------------------------------*/
  2456.     for (i = 0; i < IMPS_MAX_INVITEE_SESSION; i++)
  2457.     {
  2458.         if (imps_p->invite_info.invite_session[i].session_id == id)
  2459.         {
  2460.             session = &imps_p->invite_info.invite_session[i];
  2461.             break;
  2462.         }
  2463.     }
  2464.     if (session == NULL)
  2465.     {
  2466.         return;
  2467.     }
  2468.     /* update display buffer and context */
  2469.     if (result != IMPS_OK)
  2470.     {
  2471.         mmi_imps_room_struct *room = &imps_p->room_info.room_list[mmi_imps_util_find_room((S8*) session->room_id)];
  2472.         mmi_imps_invite_rsp_failed_msg(session);
  2473.         mmi_imps_tab_update_event(room, NULL);
  2474.         mmi_imps_util_play_tone(IMPS_ERR_TONE);
  2475.         /* clear session */
  2476.         session->session_id = 0;
  2477.         session->cont_id[0] = 0;
  2478.         session->room_id[0] = 0;
  2479.     }
  2480. }
  2481. /*****************************************************************************
  2482.  * FUNCTION
  2483.  *  mmi_imps_invite_finish
  2484.  * DESCRIPTION
  2485.  *  Finish invitation in PS. This function is the response handler from PS
  2486.  * PARAMETERS
  2487.  *  accept          [IN]        If the user accept invitation or not
  2488.  *  session_id      [IN]        Id of the invitation session
  2489.  *  sender          [IN]        User who accepted the invitation
  2490.  *  note            [IN]        Response note of the invitee
  2491.  * RETURNS
  2492.  *  void
  2493.  *****************************************************************************/
  2494. void mmi_imps_invite_finish(BOOL accept, S32 session_id, imps_entity_struct *sender, U16 *note)
  2495. {
  2496.     /*----------------------------------------------------------------*/
  2497.     /* Local Variables                                                */
  2498.     /*----------------------------------------------------------------*/
  2499.     S32 i;
  2500.     mmi_imps_invite_session_struct *session = NULL;
  2501.     mmi_imps_room_struct *room = NULL;
  2502.     /*----------------------------------------------------------------*/
  2503.     /* Code Body                                                      */
  2504.     /*----------------------------------------------------------------*/
  2505.     /* find out if a session corresponding to it */
  2506.     for (i = 0; i < IMPS_MAX_INVITEE_SESSION; i++)
  2507.     {
  2508.         if (imps_p->invite_info.invite_session[i].session_id == session_id)
  2509.         {
  2510.             session = &imps_p->invite_info.invite_session[i];
  2511.             break;
  2512.         }
  2513.     }
  2514.     if (session == NULL)
  2515.     {
  2516.         return;
  2517.     }
  2518.     /* find out the chat room it belongs to */
  2519.     for (i = 0; i < IMPS_MAX_NO_ROOM; i++)
  2520.     {
  2521.         if (mmi_imps_util_is_id_same((S8*) session->room_id, (S8*) imps_p->room_info.room_list[i].room_id))
  2522.         {
  2523.             room = &imps_p->room_info.room_list[i];
  2524.             break;
  2525.         }
  2526.     }
  2527.     /* session exists without chat room -- clear the session */
  2528.     if (room == NULL)
  2529.     {
  2530.         session->session_id = 0;
  2531.         session->cont_id[0] = 0;
  2532.         session->room_id[0] = 0;
  2533.         return;
  2534.     }
  2535.     if (accept == FALSE)
  2536.     {
  2537.         mmi_imps_invite_rsp_failed_msg(session);
  2538.         mmi_imps_util_play_tone(IMPS_ERR_TONE);
  2539.     }
  2540.     else
  2541.     {
  2542.         S8 *tmp_disp_buff = OslMalloc(IMPS_MAX_ID_LEN * ENCODING_LENGTH);
  2543.         S32 cont_index = mmi_imps_util_find_cont((S8*) session->cont_id);
  2544.         S32 sname_len = pfnUnicodeStrlen((S8*) sender->sname);
  2545.         mmi_imps_entity_struct *member = NULL;
  2546.         /* find an empty slot of member list to fill */
  2547.         for (i = 0; i < IMPS_MAX_ENTITY_NUMBER; i++)
  2548.         {
  2549.             if (strlen((S8*) room->member[i].id) == 0)
  2550.             {
  2551.                 member = &room->member[i];
  2552.                 break;
  2553.             }
  2554.         }
  2555.         if (i < IMPS_MAX_ENTITY_NUMBER)
  2556.         {
  2557.             room->no_member++;
  2558.             strcpy((S8*) member->id, (S8*) session->cont_id);
  2559.             if (sname_len)  /* regard as IMPS_ENTITY_TYPE_SCREEN_NAME */
  2560.             {
  2561.                 pfnUnicodeStrcpy((S8*) member->sname, (S8*) sender->sname);
  2562.                 mmi_imps_invite_rsp_success_msg(session, (S8*) member->sname);
  2563.             }
  2564.             else    /* IMPS_ENTITY_TYPE_USER */
  2565.             {
  2566.                 if ((S8) cont_index < imps_p->cont_info.no_cont)
  2567.                 {
  2568.                     if (pfnUnicodeStrlen((S8*) imps_p->cont_info.cont_list[cont_index].nick_name))
  2569.                     {
  2570.                         pfnUnicodeStrcat(
  2571.                             (S8*) member->sname,
  2572.                             (S8*) imps_p->cont_info.cont_list[cont_index].nick_name);
  2573.                     }
  2574.                     else
  2575.                     {
  2576.                         pfnUnicodeStrcat((S8*) member->sname, (S8*) GetString(STR_ID_IMPS_ANONYMOUS));
  2577.                     }
  2578.                     mmi_imps_invite_rsp_success_msg(session, (S8*) member->sname);
  2579.                 }
  2580.                 else
  2581.                 {
  2582.                     mmi_imps_invite_rsp_success_msg(session, (S8*) GetString(STR_ID_IMPS_ANONYMOUS));
  2583.                 }
  2584.             }
  2585.         }
  2586.         else
  2587.         {
  2588.             if (sname_len)
  2589.             {
  2590.                 mmi_imps_invite_rsp_success_msg(session, (S8*) sender->sname);
  2591.             }
  2592.             else
  2593.             {
  2594.                 AnsiiToUnicodeString(tmp_disp_buff, (S8*) sender->id);
  2595.                 mmi_imps_invite_rsp_success_msg(session, (S8*) tmp_disp_buff);
  2596.             }
  2597.         }
  2598.         mmi_imps_util_play_tone(IMPS_MSG_TONE);
  2599.         OslMfree(tmp_disp_buff);
  2600.     }
  2601.     /* update UI display */
  2602.     mmi_imps_tab_update_event(room, NULL);
  2603.     /* reset session */
  2604.     session->session_id = 0;
  2605.     session->cont_id[0] = 0;
  2606.     session->room_id[0] = 0;
  2607. }
  2608. #define INVITE_IND_IMPS
  2609. /*****************************************************************************
  2610.  * FUNCTION
  2611.  *  mmi_imps_check_pending_invite
  2612.  * DESCRIPTION
  2613.  *  Check if there is any pending invitation
  2614.  * PARAMETERS
  2615.  *  void
  2616.  *  msg(?)      [IN]        Message of invitation.
  2617.  * RETURNS
  2618.  *  void
  2619.  *****************************************************************************/
  2620. void mmi_imps_check_pending_invite(void)
  2621. {
  2622.     /*----------------------------------------------------------------*/
  2623.     /* Local Variables                                                */
  2624.     /*----------------------------------------------------------------*/
  2625.     /*----------------------------------------------------------------*/
  2626.     /* Code Body                                                      */
  2627.     /*----------------------------------------------------------------*/
  2628.     /* pending invitation exists */
  2629.     if (imps_p->invite_info.invite_pending_list[imps_p->invite_info.curr_pend_invite].node != NULL)
  2630.     {
  2631.         /* entry invitation screen */
  2632.         mmi_imps_entry_invite_ind();
  2633.     }
  2634. }
  2635. /*****************************************************************************
  2636.  * FUNCTION
  2637.  *  mmi_imps_entry_invite_ind
  2638.  * DESCRIPTION
  2639.  *  Entry invite indication screen
  2640.  * PARAMETERS
  2641.  *  void
  2642.  *  msg(?)      [IN]        Message of invitation.
  2643.  * RETURNS
  2644.  *  void
  2645.  *****************************************************************************/
  2646. void mmi_imps_entry_invite_ind(void)
  2647. {
  2648.     /*----------------------------------------------------------------*/
  2649.     /* Local Variables                                                */
  2650.     /*----------------------------------------------------------------*/
  2651.     U8 *guiBuffer;
  2652.     /*----------------------------------------------------------------*/
  2653.     /* Code Body                                                      */
  2654.     /*----------------------------------------------------------------*/
  2655.     EntryNewScreen(SCR_ID_IMPS_INVITATION_IND, NULL, mmi_imps_entry_invite_ind, NULL);
  2656.     mmi_imps_util_play_tone(IMPS_MSG_TONE);
  2657.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_INVITATION_IND);
  2658.     SetParentHandler(0);
  2659.     mmi_imps_invite_ind_gen_note();
  2660.     /* configure icons */
  2661.     wgui_config_general_multiline_icon_handler(MMI_FALSE, IMPS_NUM_INVITE, g_imps_invite_icon_list);
  2662.     ShowCategory78Screen(
  2663.         STR_ID_IMPS_INVITATION,
  2664.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  2665.         STR_ID_IMPS_JOIN,
  2666.         IMG_GLOBAL_OK,
  2667.         STR_GLOBAL_QUIT,
  2668.         IMG_GLOBAL_BACK,
  2669.         wgui_general_multiline_icon_handler,
  2670.         (U8*) imps_p->invite_info.invite_note,
  2671.         pfnUnicodeStrlen(imps_p->invite_info.invite_note),
  2672.         guiBuffer);
  2673.     /* re-use join screen */
  2674.     SetLeftSoftkeyFunction(mmi_imps_pre_entry_join, KEY_EVENT_UP);
  2675.     SetRightSoftkeyFunction(mmi_imps_ps_invite_reject, KEY_EVENT_UP);
  2676.     SetDelScrnIDCallbackHandler(SCR_ID_IMPS_INVITATION_IND, (HistoryDelCBPtr) mmi_imps_invite_ind_scr_del_callback);
  2677. }
  2678. /*****************************************************************************
  2679.  * FUNCTION
  2680.  *  mmi_imps_ps_invite_reject
  2681.  * DESCRIPTION
  2682.  *  
  2683.  * PARAMETERS
  2684.  *  void
  2685.  * RETURNS
  2686.  *  void
  2687.  *****************************************************************************/
  2688. void mmi_imps_ps_invite_reject(void)
  2689. {
  2690.     /*----------------------------------------------------------------*/
  2691.     /* Local Variables                                                */
  2692.     /*----------------------------------------------------------------*/
  2693.     /*----------------------------------------------------------------*/
  2694.     /* Code Body                                                      */
  2695.     /*----------------------------------------------------------------*/
  2696.     mmi_imps_display_progressing();
  2697.     mmi_imps_ps_invite_reply_req(FALSE);
  2698. }
  2699. /*****************************************************************************
  2700.  * FUNCTION
  2701.  *  mmi_imps_invite_ind_scr_del_callback
  2702.  * DESCRIPTION
  2703.  *  Function to free memory when invitation screen deleted.
  2704.  * PARAMETERS
  2705.  *  param       [?]     
  2706.  * RETURNS
  2707.  *  void
  2708.  *****************************************************************************/
  2709. U8 mmi_imps_invite_ind_scr_del_callback(void *param)
  2710. {
  2711.     /*----------------------------------------------------------------*/
  2712.     /* Local Variables                                                */
  2713.     /*----------------------------------------------------------------*/
  2714.     /*----------------------------------------------------------------*/
  2715.     /* Code Body                                                      */
  2716.     /*----------------------------------------------------------------*/
  2717.     mmi_imps_invite_ind_free_mem();
  2718.     mmi_imps_invite_ind_release_node();
  2719.     return FALSE;
  2720. }
  2721. /*****************************************************************************
  2722.  * FUNCTION
  2723.  *  mmi_imps_invite_reminder_del_callback
  2724.  * DESCRIPTION
  2725.  *  Function to free memory when invitation reminder screen deleted.
  2726.  * PARAMETERS
  2727.  *  param       [?]     
  2728.  * RETURNS
  2729.  *  void
  2730.  *****************************************************************************/
  2731. U8 mmi_imps_invite_reminder_del_callback(void *param)
  2732. {
  2733.     /*----------------------------------------------------------------*/
  2734.     /* Local Variables                                                */
  2735.     /*----------------------------------------------------------------*/
  2736.     /*----------------------------------------------------------------*/
  2737.     /* Code Body                                                      */
  2738.     /*----------------------------------------------------------------*/
  2739.     mmi_imps_invite_ind_free_mem();
  2740.     imps_p->invite_info.reminder_flag = FALSE;
  2741.     return FALSE;
  2742. }
  2743. /*****************************************************************************
  2744.  * FUNCTION
  2745.  *  mmi_imps_invite_ind_free_mem
  2746.  * DESCRIPTION
  2747.  *  Free memory of invitation screen
  2748.  * PARAMETERS
  2749.  *  void
  2750.  * RETURNS
  2751.  *  void
  2752.  *****************************************************************************/
  2753. void mmi_imps_invite_ind_free_mem(void)
  2754. {
  2755.     /*----------------------------------------------------------------*/
  2756.     /* Local Variables                                                */
  2757.     /*----------------------------------------------------------------*/
  2758.     /*----------------------------------------------------------------*/
  2759.     /* Code Body                                                      */
  2760.     /*----------------------------------------------------------------*/
  2761.     if (imps_p->invite_info.invite_note)
  2762.     {
  2763.         OslMfree(imps_p->invite_info.invite_note);
  2764.         imps_p->invite_info.invite_note = NULL;
  2765.     }
  2766. }
  2767. /*****************************************************************************
  2768.  * FUNCTION
  2769.  *  mmi_imps_invite_ind_free_n_back
  2770.  * DESCRIPTION
  2771.  *  Free memory of invitation screen and go back to previous screen
  2772.  * PARAMETERS
  2773.  *  void
  2774.  * RETURNS
  2775.  *  void
  2776.  *****************************************************************************/
  2777. void mmi_imps_invite_ind_free_n_back(void)
  2778. {
  2779.     /*----------------------------------------------------------------*/
  2780.     /* Local Variables                                                */
  2781.     /*----------------------------------------------------------------*/
  2782.     /*----------------------------------------------------------------*/
  2783.     /* Code Body                                                      */
  2784.     /*----------------------------------------------------------------*/
  2785.     /* release note buffer */
  2786.     mmi_imps_invite_ind_free_mem();
  2787.     /* release the holding local parameter */
  2788.     mmi_imps_invite_ind_release_node();
  2789.     GoBackHistory();
  2790. }
  2791. /*****************************************************************************
  2792.  * FUNCTION
  2793.  *  mmi_imps_invite_ind_release_node
  2794.  * DESCRIPTION
  2795.  *  Release the holding local parameter
  2796.  * PARAMETERS
  2797.  *  void
  2798.  * RETURNS
  2799.  *  void
  2800.  *****************************************************************************/
  2801. void mmi_imps_invite_ind_release_node(void)
  2802. {
  2803.     /*----------------------------------------------------------------*/
  2804.     /* Local Variables                                                */
  2805.     /*----------------------------------------------------------------*/
  2806.     S32 i = (S32) imps_p->invite_info.curr_pend_invite;
  2807.     /*----------------------------------------------------------------*/
  2808.     /* Code Body                                                      */
  2809.     /*----------------------------------------------------------------*/
  2810.     if (imps_p->invite_info.invite_pending_list[i].node)
  2811.     {
  2812.         free_local_para((local_para_struct*) imps_p->invite_info.invite_pending_list[i].node);
  2813.         imps_p->invite_info.invite_pending_list[i].node = NULL;
  2814.     }
  2815.     /* move index to the next node */
  2816.     i++;
  2817.     if (i == IMPS_MAX_PEND_INVITATION)
  2818.     {
  2819.         imps_p->invite_info.curr_pend_invite = 0;
  2820.     }
  2821.     else
  2822.     {
  2823.         imps_p->invite_info.curr_pend_invite = (U8) i;
  2824.     }
  2825. }
  2826. /*****************************************************************************
  2827.  * FUNCTION
  2828.  *  mmi_imps_invite_ind_gen_note
  2829.  * DESCRIPTION
  2830.  *  Generate invitation note of indication screen
  2831.  * PARAMETERS
  2832.  *  void
  2833.  * RETURNS
  2834.  *  void
  2835.  *****************************************************************************/
  2836. void mmi_imps_invite_ind_gen_note(void)
  2837. {
  2838.     /*----------------------------------------------------------------*/
  2839.     /* Local Variables                                                */
  2840.     /*----------------------------------------------------------------*/
  2841.     S8 *note;
  2842.     S8 *tmp_buff = OslMalloc(IMPS_MAX_NOTE_LEN * ENCODING_LENGTH);      /* temporary buffer for icon */
  2843.     mmi_imps_invite_ind_struct *invite_ind =
  2844.         imps_p->invite_info.invite_pending_list[imps_p->invite_info.curr_pend_invite].node;
  2845.     /*----------------------------------------------------------------*/
  2846.     /* Code Body                                                      */
  2847.     /*----------------------------------------------------------------*/
  2848.     if (imps_p->invite_info.invite_note == NULL)
  2849.     {
  2850.         imps_p->invite_info.invite_note = OslMalloc(IMPS_MAX_INVITATION_NOTE);
  2851.     }
  2852.     note = imps_p->invite_info.invite_note;
  2853.     /* Owner */
  2854.     AnsiiToUnicodeString((S8*) tmp_buff, g_imps_invite_icon_list[0].string);
  2855.     pfnUnicodeStrcpy(note, (S8*) tmp_buff);
  2856.     pfnUnicodeStrcat(note, (S8*) GetString(STR_ID_IMPS_OWNER));
  2857.     pfnUnicodeStrcat(note, (S8*) L":n");
  2858.     if (invite_ind->sender.entity_type == IMPS_ENTITY_TYPE_SCREEN_NAME)
  2859.     {
  2860.         pfnUnicodeStrcat(note, (S8*) invite_ind->sender.sname);
  2861.     }
  2862.     else
  2863.     {
  2864.         AnsiiToUnicodeString((S8*) tmp_buff, (S8*) invite_ind->sender.id);
  2865.         pfnUnicodeStrcat(note, (S8*) tmp_buff);
  2866.     }
  2867.     pfnUnicodeStrcat(note, (S8*) L"nn");
  2868.     /* Group ID */
  2869.     AnsiiToUnicodeString((S8*) tmp_buff, g_imps_invite_icon_list[1].string);
  2870.     pfnUnicodeStrcat(note, (S8*) tmp_buff);
  2871.     pfnUnicodeStrcat(note, (S8*) GetString(STR_ID_IMPS_CHAT_ROOMS));
  2872.     pfnUnicodeStrcat(note, (S8*) L":n");
  2873.     AnsiiToUnicodeString(tmp_buff, (S8*) invite_ind->group_id);
  2874.     pfnUnicodeStrcat(note, tmp_buff);
  2875.     pfnUnicodeStrcat(note, (S8*) L"nn");
  2876.     /* Note */
  2877.     pfnUnicodeStrcat(note, (S8*) GetString(STR_ID_IMPS_WELCOME_TEXT));
  2878.     pfnUnicodeStrcat(note, (S8*) L":n");
  2879.     pfnUnicodeStrcat(note, (S8*) invite_ind->invite_note);
  2880.     OslMfree(tmp_buff);
  2881. }
  2882. /*****************************************************************************
  2883.  * FUNCTION
  2884.  *  mmi_imps_invite_accept
  2885.  * DESCRIPTION
  2886.  *  Accept invitation, ask user to input screen name first
  2887.  * PARAMETERS
  2888.  *  void
  2889.  * RETURNS
  2890.  *  void
  2891.  *****************************************************************************/
  2892. void mmi_imps_invite_accept(void)
  2893. {
  2894.     /*----------------------------------------------------------------*/
  2895.     /* Local Variables                                                */
  2896.     /*----------------------------------------------------------------*/
  2897.     /*----------------------------------------------------------------*/
  2898.     /* Code Body                                                      */
  2899.     /*----------------------------------------------------------------*/
  2900.     /* send request to PS */
  2901.     mmi_imps_ps_invite_reply_req(TRUE);
  2902. }
  2903. /*****************************************************************************
  2904.  * FUNCTION
  2905.  *  mmi_imps_entry_invite_reminder
  2906.  * DESCRIPTION
  2907.  *  Entry reminder invitation screen
  2908.  * PARAMETERS
  2909.  *  void
  2910.  * RETURNS
  2911.  *  void
  2912.  *****************************************************************************/
  2913. void mmi_imps_entry_invite_reminder(void)
  2914. {
  2915.     /*----------------------------------------------------------------*/
  2916.     /* Local Variables                                                */
  2917.     /*----------------------------------------------------------------*/
  2918.     U8 *guiBuffer;
  2919.     /*----------------------------------------------------------------*/
  2920.     /* Code Body                                                      */
  2921.     /*----------------------------------------------------------------*/
  2922.     EntryNewScreen(SCR_ID_IMPS_INVITATION_IND, NULL, mmi_imps_entry_invite_reminder, NULL);
  2923.     guiBuffer = GetCurrGuiBuffer(SCR_ID_IMPS_INVITATION_IND);
  2924.     SetParentHandler(0);
  2925.     /* generate note */
  2926.     if (imps_p->invite_info.invite_note == NULL)
  2927.     {
  2928.         imps_p->invite_info.invite_note = OslMalloc(IMPS_MAX_INVITATION_NOTE);
  2929.     }
  2930.     pfnUnicodeStrcpy((S8*) imps_p->invite_info.invite_note, (S8*) GetString(STR_ID_IMPS_NEW_INVITE_REMINDER));
  2931.     /* configure icons */
  2932.     wgui_config_general_multiline_icon_handler(MMI_FALSE, IMPS_NUM_INVITE, g_imps_invite_icon_list);
  2933.     ShowCategory78Screen(
  2934.         STR_ID_IMPS_NEW_INVITATION,
  2935.         GetRootTitleIcon(MENU_ID_IMPS_MAIN),
  2936.         0,
  2937.         0,
  2938.         STR_GLOBAL_BACK,
  2939.         IMG_GLOBAL_BACK,
  2940.         wgui_general_multiline_icon_handler,
  2941.         (U8*) imps_p->invite_info.invite_note,
  2942.         pfnUnicodeStrlen(imps_p->invite_info.invite_note),
  2943.         guiBuffer);
  2944.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  2945.     SetDelScrnIDCallbackHandler(SCR_ID_IMPS_INVITATION_IND, (HistoryDelCBPtr) mmi_imps_invite_reminder_del_callback);
  2946. }
  2947. /*****************************************************************************
  2948.  * FUNCTION
  2949.  *  mmi_imps_entry_invite_key_lokced
  2950.  * DESCRIPTION
  2951.  *  Entry reminder invitation screen when keypad locked
  2952.  * PARAMETERS
  2953.  *  lsk_img_id      [IN]        
  2954.  *  lsk_str_id      [IN]        
  2955.  *  rsk_img_id      [IN]        
  2956.  *  rsk_str_id      [IN]        
  2957.  * RETURNS
  2958.  *  void
  2959.  *****************************************************************************/
  2960. void mmi_imps_entry_invite_key_lokced(U16 lsk_img_id, U16 lsk_str_id, U16 rsk_img_id, U16 rsk_str_id)
  2961. {
  2962.     /*----------------------------------------------------------------*/
  2963.     /* Local Variables                                                */
  2964.     /*----------------------------------------------------------------*/
  2965.     /*----------------------------------------------------------------*/
  2966.     /* Code Body                                                      */
  2967.     /*----------------------------------------------------------------*/
  2968.     /* generate note */
  2969.     if (imps_p->invite_info.invite_note == NULL)
  2970.     {
  2971.         imps_p->invite_info.invite_note = OslMalloc(IMPS_MAX_INVITATION_NOTE);
  2972.     }
  2973.     pfnUnicodeStrcpy((S8*) imps_p->invite_info.invite_note, (S8*) GetString(STR_ID_IMPS_NEW_INVITE_REMINDER));
  2974.     ShowCategory154Screen(
  2975.         0,
  2976.         0,
  2977.         lsk_str_id,
  2978.         lsk_img_id,
  2979.         rsk_str_id,
  2980.         rsk_img_id,
  2981.         (U8*) imps_p->invite_info.invite_note,
  2982.         NULL,
  2983.         IMG_GLOBAL_INFO,
  2984.         NULL);
  2985.     OslMfree(imps_p->invite_info.invite_note);
  2986.     imps_p->invite_info.invite_note = NULL;
  2987. }
  2988. /*****************************************************************************
  2989.  * FUNCTION
  2990.  *  mmi_imps_free_invite_list
  2991.  * DESCRIPTION
  2992.  *  Free all invite pending list when logout
  2993.  * PARAMETERS
  2994.  *  void
  2995.  * RETURNS
  2996.  *  void
  2997.  *****************************************************************************/
  2998. void mmi_imps_free_invite_list(void)
  2999. {
  3000.     /*----------------------------------------------------------------*/
  3001.     /* Local Variables                                                */
  3002.     /*----------------------------------------------------------------*/
  3003.     S32 i;
  3004.     mmi_imps_invite_list_struct *invite;
  3005.     /*----------------------------------------------------------------*/
  3006.     /* Code Body                                                      */
  3007.     /*----------------------------------------------------------------*/
  3008.     for (i = 0; i < IMPS_MAX_PEND_INVITATION; i++)
  3009.     {
  3010.         invite = &imps_p->invite_info.invite_pending_list[i];
  3011.         if (invite->node)
  3012.         {
  3013.             free_local_para((local_para_struct*) invite->node);
  3014.             invite->node = NULL;
  3015.         }
  3016.     }
  3017. }
  3018. #define GROUP_IMPS