SmsMainMenu.c 48.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 * SmsMainMenu.c
 *
 * Project:
 * --------
 *   MAUI
 *
 * Description:
 * ------------
 *   This file is intends for message menu handling when UM is turned off.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *==============================================================================
 *******************************************************************************/

#include "MMI_features.h"
#ifndef __UM_SUPPORT__
#ifdef __MMI_TELEPHONY_SUPPORT__

#include "MMIDataType.h"
#include "kal_general_types.h"
#include "gui_typedef.h"
#include "GlobalResDef.h"
#include "mmi_frm_scenario_gprot.h"
#include "wgui_categories_util.h"
#include "ps_public_struct.h"
#include "mmi_rp_app_sms_def.h"
#include "mmi_msg_struct.h"
#include "mmi_frm_mem_gprot.h"
#include "kal_public_api.h"
#include "kal_release.h"
#include "DebugInitDef_Int.h"
#include "string.h"
#include "nvram_common_defs.h"
#include "SmsAppGprot.h"
#include "GpioSrvGprot.h"
#include "mmi_frm_events_gprot.h"
#include "gui_data_types.h"
#include "app_ltlcom.h"
#include "stack_config.h"
#include "stack_msgs.h"
#include "mmi_frm_queue_gprot.h"
#include "NotificationGprot.h"
#include "l4c2smsal_struct.h"
#include "SmsSrvGprot.h"
#include "SmsAppResDef.h"
#include "SmsAppType.h"
#include "PhbSrvGprot.h"
#include "wgui_categories_email.h"
#include "SmsAppProt.h"
#include "AlertScreen.h"
#include "wgui_categories_list.h"
#include "wgui_categories_popup.h"
#if defined(__TOPWELL_BASE_BUG__)  ///__TOPWELL_MMI_FACTORY_RESET__
#include "TimerEvents.h"
#endif
typedef struct
{
    srv_sms_box_enum msg_box_type;
} mmi_sms_del_folder_struct;

static void mmi_sms_enter_message_list(srv_sms_box_enum msg_box, MMI_ID parent_id);
static void mmi_sms_delete_folder_callback(srv_sms_callback_struct* callback_data);
static void mmi_sms_delete_folder_req(void);
static void mmi_sms_delete_all(void);
static void mmi_sms_alert_inbox_refresh(void);


mmi_sms_list_data_struct *g_sms_list_struct;
srv_sms_box_enum current_box;
SMS_HANDLE delete_handle;


#define MMI_SMS_UI_MAX_LEN_TIME_STR  (15 + 1 + 10 + 1) /* Date string + 1 space + Time string + NULL terminator*/

static MMI_BOOL mmi_sms_is_on_list_screen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	MMI_ID group_id,scrn_id;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	mmi_frm_get_active_scrn_id(&group_id, &scrn_id);
	if(scrn_id == SCR_ID_SMS_LIST)
		return MMI_TRUE;
	return MMI_FALSE;
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_group_proc
 * DESCRIPTION
 * group proc for the list sceen
 * PARAMETERS
 *  mmi_event_struct
 * RETURNS
 *  MMI_RET
 *****************************************************************************/
static MMI_RET mmi_sms_list_group_proc(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	switch(evt->evt_id)
	{
		case EVT_ID_GROUP_DEINIT:
			OslMfree(g_sms_list_struct);
			break;
			
	}
	return MMI_RET_OK;
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_list_highlight_handler
 * DESCRIPTION
 * highlight handler for the sms list screen
 * PARAMETERS
 *  srv_sms_box_enum
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_sms_list_highlight_handler(S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	char address[(SRV_SMS_MAX_ADDR_LEN+1)*ENCODING_LENGTH];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

	g_sms_list_struct->highlighted_item = index;
	g_sms_list_struct->curr_msg_id = srv_sms_get_msg_id(g_sms_list_struct->curr_box, g_sms_list_struct->highlighted_item);
	srv_sms_get_msg_address(g_sms_list_struct->curr_msg_id, address);
	mmi_sms_set_hilite_msg_addr(address);
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_get_list_async_item
 * DESCRIPTION
 * entry function for the message list
 * PARAMETERS
 *  srv_sms_box_enum
 * RETURNS
 *  void
 *****************************************************************************/
static S32 mmi_sms_get_list_async_item(S32 start_index, gui_iconlist_menu_item *menu_data, S32 num_of_item)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	U16 i, msg_id, copy_len;
	mmi_sms_msg_info_struct msg_detail_info;
	UI_character_type msg_time[MMI_SMS_UI_MAX_LEN_TIME_STR];
	UI_character_type str[MMI_SMS_UI_MAX_LEN_TIME_STR];    
    MYTIME time;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	for(i = 0; i < num_of_item; i++)
	{
		msg_id = srv_sms_get_msg_id(g_sms_list_struct->curr_box, (start_index + i));
		mmi_sms_get_msg_info_content(&msg_detail_info, msg_id, g_sms_list_struct->curr_box);

		#ifndef __MMI_BT_MAP_CLIENT__
            copy_len = MAX_SUBMENU_CHARACTERS;
            
            if (msg_detail_info.subject_length < MAX_SUBMENU_CHARACTERS)
            {
                copy_len = msg_detail_info.subject_length;
            }

            if (copy_len == 0)
            {
                mmi_ucs2ncpy(
                    (CHAR*) menu_data[i].item_list[0],
                    (CHAR*) GetString(STR_UM_EMPTY_SUBJECT_ID),
                    MMI_SMS_MAX_SUBJECT_LEN);
            }
            else
            {
                mmi_ucs2ncpy(
                    (CHAR*) menu_data[i].item_list[0],
                    (CHAR*) msg_detail_info.subject,
                    copy_len);
            }
        #else
			if (msg_detail_info.address_length == 0)
	        {
	            mmi_ucs2ncpy(
	                (S8*) menu_data[i].item_list[0],
	                (S8*) GetString(STR_GLOBAL_NO_NUMBER),
	                MMI_SMS_MAX_SUBJECT_LEN);
	        }
	        else
	        {
	            copy_len = MAX_SUBMENU_CHARACTERS - 1;
	            if (msg_detail_info.address_length < MAX_SUBMENU_CHARACTERS)
	            {
	                copy_len = msg_detail_info.address_length;
	            }

	            /* Lookup name first if it is phone number */
	            
	            
	                srv_phb_get_name_by_number((U16 *)msg_detail_info.address, 
	                                           (U16 *)menu_data[i].item_list[0], 
	                                           MAX_SUBMENU_CHARACTERS - 1);
	                if (0 == mmi_ucs2strlen((S8*)menu_data[i].item_list[0]))
	                {
	                    mmi_ucs2ncpy((S8*) menu_data[i].item_list[0], 
	                             (S8*) msg_detail_info.address, 
	                             copy_len);
	                }
	        }
		#endif

		/*Timestamp*/
        memset((CHAR*)str, 0, sizeof(str));
        memset((CHAR*)msg_time, 0, sizeof(msg_time));

        copy_len = MAX_SUBMENU_CHARACTERS;
        if (MMI_SMS_UI_MAX_LEN_TIME_STR < MAX_SUBMENU_CHARACTERS)
        {
            copy_len = MMI_SMS_UI_MAX_LEN_TIME_STR;
        }


        if (msg_detail_info.timestamp != 0)
        {
            U32 local_sec = 0;

            memset(&time, 0, sizeof(MYTIME));
            local_sec = applib_dt_sec_utc_to_local(msg_detail_info.timestamp);
            mmi_dt_utc_sec_2_mytime(local_sec, &time, MMI_FALSE);
            /* Normal time display as IDLE */
            date_string(&time, str, DT_IDLE_SCREEN);
            mmi_ucs2ncpy((S8*) msg_time, (S8*) str, (MMI_SMS_UI_MAX_LEN_TIME_STR - 1));
            mmi_ucs2ncat((S8*) msg_time, (S8*) " ", 1);

            time_string(&time, str, DT_IDLE_SCREEN);
            mmi_ucs2ncat((S8*) msg_time, (S8*) str, (MMI_SMS_UI_MAX_LEN_TIME_STR - 1));
		}
		mmi_ucs2ncpy(
            (S8*) menu_data[i].item_list[1],
            (S8*) msg_time,
            copy_len);

		// address
		if (msg_detail_info.address_length == 0)
		{
			mmi_ucs2ncpy(
				(S8*) menu_data[i].item_list[2],
				(S8*) GetString(STR_GLOBAL_NO_NUMBER),
				MMI_SMS_MAX_SUBJECT_LEN);
		}
		else
		{
			copy_len = MAX_SUBMENU_CHARACTERS - 1;
			if (msg_detail_info.address_length < MAX_SUBMENU_CHARACTERS)
			{
				copy_len = msg_detail_info.address_length;
			}

			/* Lookup name first if it is phone number */
				srv_phb_get_name_by_number((U16 *)msg_detail_info.address, 
										   (U16 *)menu_data[i].item_list[2], 
										   MAX_SUBMENU_CHARACTERS - 1);
				if (0 == mmi_ucs2strlen((S8*)menu_data[i].item_list[2]))
				{
					mmi_ucs2ncpy((S8*) menu_data[i].item_list[2], 
							 (S8*) msg_detail_info.address, 
							 copy_len);
				}
		}

		//image
		menu_data[i].image_list[0] = (PU8) GetImage(msg_detail_info.icon_id);


		#if (MMI_MAX_SIM_NUM >= 2)
        if (msg_detail_info.sim_id == SRV_SMS_SIM_1)
        {
            menu_data[i].image_list[1] = (PU8) GetImage(IMG_GLOBAL_SIM1);  
        }
        else if (msg_detail_info.sim_id == SRV_SMS_SIM_2)
        {
            menu_data[i].image_list[1] = (PU8) GetImage(IMG_GLOBAL_SIM2);  
        }
    #if (MMI_MAX_SIM_NUM >= 3) 
        else if (msg_detail_info.sim_id == SRV_SMS_SIM_3)
        {
            menu_data[i].image_list[1] = (PU8) GetImage(IMG_GLOBAL_SIM3);  
        }
    #endif
    #if (MMI_MAX_SIM_NUM >= 4)    
        else if (msg_detail_info.sim_id == SRV_SMS_SIM_4)
        {
            menu_data[i].image_list[1] = (PU8) GetImage(IMG_GLOBAL_SIM4);  
        }
    #endif
        else
        {
            menu_data[i].image_list[1] = NULL;
        }
    #endif
	
	}
	return i;
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_get_str_id_by_folder
 * DESCRIPTION
 * to return the string id for the title of message list
 * PARAMETERS
 *  srv_sms_box_enum
 * RETURNS
 *  U16
 *****************************************************************************/
 static U16 mmi_sms_get_str_id_by_folder(srv_sms_box_enum msg_box)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 str_id = 0;
	/*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	switch(msg_box)
	{
		case SRV_SMS_BOX_INBOX:
			str_id = STR_GLOBAL_INBOX;
			break;
		case SRV_SMS_BOX_OUTBOX:
			str_id = STR_UM_SENT_ID;
			break;
		case SRV_SMS_BOX_DRAFTS:
			str_id = STR_GLOBAL_DRAFTS;
			break;
		case SRV_SMS_BOX_UNSENT:
			str_id = STR_GLOBAL_OUTBOX;
			break;
	}
	return str_id;
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_enter_msg_viewer
 * DESCRIPTION
 * function to launch the message viewer
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
 static void mmi_sms_enter_msg_viewer(MMI_ID parent_id, U16 msg_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	g_sms_cntx.is_from_hs = MMI_FALSE;
    mmi_sms_um_set_sms_context(msg_id);

    mmi_sms_group_entry(parent_id);
    mmi_sms_view_curr_msg();
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_view_msg
 * DESCRIPTION
 * LSK/CSK handler for the message view screen
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
 static void mmi_sms_view_msg(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	
	mmi_sms_enter_msg_viewer(GRP_ID_SMS_LIST, g_sms_list_struct->curr_msg_id);
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_enter_message_list
 * DESCRIPTION
 * entry function for the message list
 * PARAMETERS
 *  srv_sms_box_enum
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_sms_enter_message_list_screen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	U16 lsk_str_id = 0;
	U16 title_id = 0;
	S32 error_flag;
	U16 box_size = srv_sms_get_list_size(g_sms_list_struct->curr_box);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

	mmi_frm_scrn_enter( GRP_ID_SMS_LIST, SCR_ID_SMS_LIST , NULL, mmi_sms_enter_message_list_screen, MMI_FRM_FULL_SCRN);
	title_id = mmi_sms_get_str_id_by_folder(g_sms_list_struct->curr_box);

	if(box_size > 0)
	{
		lsk_str_id = STR_GLOBAL_VIEW;
	}
	else
	{
		g_sms_list_struct->curr_msg_id = SRV_SMS_INVALID_MSG_ID; // set message id as invalid if there is no message in the list
	}


	wgui_cat_set_list_menu_empty_lable(get_string(STR_UM_EMPTY_MSG_ID));
	RegisterHighlightHandler(mmi_sms_list_highlight_handler);

#if !defined(__TOPWELL_MMI_SMS_SLIM_NO_INFOBAR__)
	ShowCategory263Screen(
		(U8*)get_string(title_id),
		0,
		lsk_str_id,
		IMG_GLOBAL_OPTIONS,
		STR_GLOBAL_BACK,
		IMG_GLOBAL_BACK,
		box_size,
		mmi_sms_get_list_async_item,
		NULL,
		g_sms_list_struct->highlighted_item,
		IMG_MESSAGE_READ,
		NULL,
		&error_flag);
#else	
#if !(defined (__MMI_MAINLCD_96X64__) || defined (__MMI_SMS_SLIM__)) || defined(__TOPWELL_MMI_SMS_LSK_OPTION__)	
	ShowCategory263Screen(
		(U8*)get_string(title_id),
		0,
		lsk_str_id,
		IMG_GLOBAL_OPTIONS,
		STR_GLOBAL_BACK,
		IMG_GLOBAL_BACK,
		box_size,
		mmi_sms_get_list_async_item,
		NULL,
		g_sms_list_struct->highlighted_item,
		IMG_MESSAGE_READ,
		NULL,
		&error_flag);
#else
	wgui_override_list_menu_slim_style(WGUI_LIST_MENU_SLIM_STYLE_DRAW_ICON);
	wgui_cat1032_show(
        (WCHAR*) get_string(title_id),
        0,
        (WCHAR*) GetString(lsk_str_id),
        (PU8) IMG_GLOBAL_OPTIONS,
        (WCHAR*) GetString(STR_GLOBAL_BACK),
        (PU8) IMG_GLOBAL_BACK,
        box_size,
        mmi_sms_get_list_async_item,
        NULL,
        g_sms_list_struct->highlighted_item,
		0,
        IMG_MESSAGE_READ,   /* for icon position used */
		0,
        NULL,
        &error_flag);
	wgui_restore_list_menu_slim_style();
#endif
#endif

	if(box_size > 0)
	{
	 #ifdef __TOPWELL_BASE_BUG__ //xn note´¥ÃþÆÁ×¢²áµÄÊÇKEY_EVENT_UPʼþ
		SetLeftSoftkeyFunction(mmi_sms_view_msg, KEY_EVENT_UP);
		SetCenterSoftkeyFunction(mmi_sms_view_msg, KEY_EVENT_UP);	 
	 #else
		SetLeftSoftkeyFunction(mmi_sms_view_msg, KEY_EVENT_DOWN);
		SetCenterSoftkeyFunction(mmi_sms_view_msg, KEY_EVENT_DOWN);
	 #endif	
	}
}
/*****************************************************************************
 * FUNCTION
 *  mmi_sms_enter_message_list
 * DESCRIPTION
 * entry function for the message list
 * PARAMETERS
 *  srv_sms_box_enum
 * RETURNS
 *  void
 *****************************************************************************/
#if defined(__TOPWELL_MMI_PRIVACY_PROTECTION__)
static MMI_ID g_privacy_sms_parent_id=0;
static void mmi_sms_enter_message_list_ext(void)
#else 
static void mmi_sms_enter_message_list(srv_sms_box_enum msg_box, MMI_ID parent_id)
#endif
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__TOPWELL_MMI_PRIVACY_PROTECTION__)   
     mmi_frm_group_create_ex(g_privacy_sms_parent_id, GRP_ID_SMS_LIST, mmi_sms_list_group_proc ,NULL, MMI_FRM_NODE_SMART_CLOSE_FLAG);

#else
	mmi_frm_group_create_ex(parent_id, GRP_ID_SMS_LIST, mmi_sms_list_group_proc ,NULL, MMI_FRM_NODE_SMART_CLOSE_FLAG);

	g_sms_list_struct = OslMalloc(sizeof(mmi_sms_list_data_struct));
	memset(g_sms_list_struct, 0x00, sizeof(mmi_sms_list_data_struct));

	g_sms_list_struct->curr_box = msg_box;
#endif    
	mmi_sms_enter_message_list_screen();
	
}

#if defined(__TOPWELL_MMI_PRIVACY_PROTECTION__)
#include "PhoneSetup.h"
 void mmi_sms_enter_message_list(srv_sms_box_enum msg_box, MMI_ID parent_id)
 {
 	g_sms_list_struct = OslMalloc(sizeof(mmi_sms_list_data_struct));
	memset(g_sms_list_struct, 0x00, sizeof(mmi_sms_list_data_struct));

	g_sms_list_struct->curr_box = msg_box;
    
        g_privacy_sms_parent_id = parent_id;

	 mmi_privacy_protection_launch(PRIVACY_MESSAGE, mmi_sms_enter_message_list_ext);    
 }
#endif

#ifdef __TOPWELL_MMI_SCHEDULE_SMS__
extern MMI_ID cui_sms_schedule_launch(MMI_ID parent_grp_id);

void EntrySmsShedule(void)
{
	cui_sms_schedule_launch(GRP_ID_ROOT);
}
void HightSmsSchedule(void)
{
    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    SetLeftSoftkeyFunction(EntrySmsShedule, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
    ChangeCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
    SetCenterSoftkeyFunction(EntrySmsShedule, KEY_EVENT_UP);

}
#endif

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_group_proc
 * DESCRIPTION
 * group proc for the SMS main menu
 * PARAMETERS
 *  mmi_event_struct
 * RETURNS
 *  MMI_RET
 *****************************************************************************/
static MMI_RET mmi_sms_group_proc(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	cui_menu_event_struct *menu_evt = (cui_menu_event_struct*) evt;
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	switch(evt->evt_id)
	{
		case EVT_ID_GROUP_DEINIT:
			if(delete_handle)
				srv_sms_abort(delete_handle, NULL, NULL);
			break;
		case EVT_ID_CUI_MENU_ITEM_SELECT:
			switch(menu_evt->highlighted_menu_id)
			{
				case MENU_ID_UM_WRITE_MSG:
					mmi_sms_enter_write_msg();
					break;
				case MENU_ID_SMS_INBOX:
					mmi_sms_enter_message_list(SRV_SMS_BOX_INBOX, GRP_ID_SMS_MAIN);
					break;
				case MENU_ID_SMS_DRAFTS:
					mmi_sms_enter_message_list(SRV_SMS_BOX_DRAFTS, GRP_ID_SMS_MAIN);
					break;
				case MENU_ID_SMS_OUTBOX:
					mmi_sms_enter_message_list(SRV_SMS_BOX_UNSENT, GRP_ID_SMS_MAIN);
					break;
				case MENU_ID_SMS_SENTBOX:
					mmi_sms_enter_message_list(SRV_SMS_BOX_OUTBOX, GRP_ID_SMS_MAIN);
					break;
			#ifdef __MMI_CBS_SUPPORT__
				case MENU_ID_SMS_CB_MAIN:
					 cui_sms_cbs_launch(GRP_ID_SMS_MAIN);			
					break;					
			#endif
				case MENU_ID_SMS_SETTING:
					cui_sms_setting_launch(mmi_frm_group_get_active_id());
					break;
				case MENU_ID_SMS_DELETE_MSG_FOLDER_INBOX:
					current_box = SRV_SMS_BOX_INBOX;
					mmi_sms_delete_all();
					break;
				case MENU_ID_SMS_DELETE_MSG_FOLDER_UNSENT:
					current_box = SRV_SMS_BOX_UNSENT;
					mmi_sms_delete_all();
					break;
				case MENU_ID_SMS_DELETE_MSG_FOLDER_SENT:
					current_box = SRV_SMS_BOX_OUTBOX;
					mmi_sms_delete_all();
					break;
				case MENU_ID_SMS_DELETE_MSG_FOLDER_DRAFTS:
					current_box = SRV_SMS_BOX_DRAFTS;
					mmi_sms_delete_all();
					break;
			    #if defined(__TOPWELL_MMI_MESSAGES_TEMPLATE_USERDEFINED__)||defined(__TOPWELL_MMI_MESSAGES_TEMPLATE_PREDEFINED__)
			    #ifndef __UM_FOLDER__
			        case MENU_ID_UM_TEMPLATE_SMS_ONLY:
			    #endif /* __UM_FOLDER__ */
			        {
			            cui_sms_templates_launch(GRP_ID_SMS_MAIN);
			            break;
			        }
			    #endif /* __MMI_MESSAGES_TEMPLATE__ */
                         #ifdef __TOPWELL_MMI_SCHEDULE_SMS__
			        case MENU_ID_UM_SCHEDULE_SMS:
			        {
			            cui_sms_schedule_launch(GRP_ID_SMS_MAIN);
			            break;
			        }
                         #endif
			}		
			break;
		case EVT_ID_CUI_MENU_CLOSE_REQUEST:
			cui_menu_close(menu_evt->sender_id);
			break;
			
	}
	return MMI_RET_OK;

	
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_enter_main_menu
 * DESCRIPTION
 *  function to run the SMS main menu
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_sms_enter_main_menu(mmi_id parent_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	MMI_ID menu_id;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	menu_id = cui_menu_create(
						parent_id,
						CUI_MENU_SRC_TYPE_RESOURCE,
						CUI_MENU_TYPE_APPMAIN,
						MAIN_MENU_MESSAGES_MENUID,
						MMI_FALSE,
						(void*) (U32)MAIN_MENU_MESSAGES_MENUID);
	cui_menu_run(menu_id);	
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_entry_main_message_menu
 * DESCRIPTION
 *  Entry function for the SMS main menu
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
#if defined(__TOPWELL_MMI_PRIVACY_PROTECTION__)
void mmi_sms_entry_main_message_menu_ex(void)
#else 
void mmi_sms_entry_main_message_menu(void)
#endif 
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__TOPWELL_MMI_SMS_CHECK_SIMCARD__)
    if (!srv_nw_usab_is_any_network_available())
    {
	 mmi_popup_display_simple(
            (WCHAR *)get_string(STR_GLOBAL_CURRENTLY_NOT_AVAILABLE), 
            MMI_EVENT_FAILURE, 
            GRP_ID_ROOT, 
            NULL);
        return;
    }
#endif

	if(!srv_sms_is_sms_ready())
	{
		mmi_popup_display_simple(
	            (WCHAR *)get_string(STR_GLOBAL_CURRENTLY_NOT_AVAILABLE), 
	            MMI_EVENT_FAILURE, 
	            GRP_ID_ROOT, 
	            NULL);
	}
	else
	{
		mmi_frm_group_create_ex(GRP_ID_ROOT , GRP_ID_SMS_MAIN , mmi_sms_group_proc ,NULL, MMI_FRM_NODE_SMART_CLOSE_FLAG);
		mmi_sms_enter_main_menu(GRP_ID_SMS_MAIN);		
	}
}

#if defined(__TOPWELL_MMI_PRIVACY_PROTECTION__)
#include "PhoneSetup.h"
 void mmi_sms_entry_main_message_menu(void)
 {
	 mmi_privacy_protection_launch(PRIVACY_MESSAGE, mmi_sms_entry_main_message_menu_ex);    
 }
#endif


/*****************************************************************************
 * FUNCTION
 *  mmi_sms_enter_write_msg
 * DESCRIPTION
 *  Entry function for the write message option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
 void mmi_sms_enter_write_msg(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__TOPWELL_MMI_SMS_CHECK_SIMCARD__)
    if (!srv_nw_usab_is_any_network_available())
    {
	 mmi_popup_display_simple(
            (WCHAR *)get_string(STR_GLOBAL_CURRENTLY_NOT_AVAILABLE), 
            MMI_EVENT_FAILURE, 
            GRP_ID_ROOT, 
            NULL);
        return;
    }
#endif

	#if 0
/* under construction !*/
	#else
	mmi_msg_pre_entry_write_new_msg();
	#endif
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_handle_srv_ind
 * DESCRIPTION
 *  handler for the events sent by SMS service
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
 MMI_RET mmi_sms_handle_srv_ind(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	srv_sms_event_struct* event_data = (srv_sms_event_struct*)evt;
	srv_sms_event_add_struct *event_info = (srv_sms_event_add_struct*)event_data->event_info;
	srv_sms_event_update_struct *update_info= (srv_sms_event_update_struct*)event_data->event_info;
	U16 msg_id;
	srv_sms_box_enum msg_box_type = SRV_SMS_BOX_NONE;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	mmi_sms_alert_inbox_refresh();	
	switch(evt->evt_id)
	{
		case EVT_ID_SRV_SMS_NEW_MSG:
			break;
			
		case EVT_ID_SRV_SMS_ADD_MSG:
			if(mmi_frm_scrn_is_present(GRP_ID_SMS_LIST, SCR_ID_SMS_LIST, MMI_FRM_NODE_ALL_FLAG))
			{
				msg_box_type = srv_sms_get_list_type(
									event_info->msg_info.status,
									event_info->msg_info.storage_type,
									event_info->msg_info.folder_id);
				/*
					Need to set the highlighted item only if the 3 conditions are met
					1. On the list screen
					2. Added message is in the current list only
					3. There is already some message present in the list
				*/
				if(msg_box_type == g_sms_list_struct->curr_box)
				{
					if(g_sms_list_struct->curr_msg_id != SRV_SMS_INVALID_MSG_ID)
						g_sms_list_struct->highlighted_item = srv_sms_get_msg_list_index(
																	&g_sms_list_struct->curr_box, 
																	g_sms_list_struct->curr_msg_id);
					if(mmi_sms_is_on_list_screen())
					{
						#if 0
/* under construction !*/
						#else
						mmi_frm_display_dummy_screen();
						mmi_frm_scrn_close(GRP_ID_SMS_LIST, SCR_ID_DUMMY);
						#endif
					}
				}
			}
			break;
			
		case EVT_ID_SRV_SMS_DEL_MSG:
			if(mmi_sms_is_on_list_screen())
			{
				msg_box_type = srv_sms_get_list_type(
									event_info->msg_info.status,
									event_info->msg_info.storage_type,
									event_info->msg_info.folder_id);
				
				if(msg_box_type == g_sms_list_struct->curr_box)
				{
					/*
					The check is added for the replacement message scenario when we dont 
					want to udpate the highlighted item in case the current highlighted message is being replaced
					The condition will only be met in the case of replacement message only
					*/
					if(g_sms_list_struct->curr_msg_id == event_info->msg_id)
						break;
					msg_id = srv_sms_get_msg_id(g_sms_list_struct->curr_box , g_sms_list_struct->highlighted_item + 1);
					if(msg_id == SRV_SMS_INVALID_MSG_ID)
					{
						/* 
						set the highlighter to the first item in the list in case the last message is deleted
						The delete message event is recieved after the list screen has been shown
						so we need to use a dummy screen to update the highlighted item
						*/
						g_sms_list_struct->highlighted_item = 0;
						mmi_frm_display_dummy_screen();
						mmi_frm_scrn_close(GRP_ID_SMS_LIST, SCR_ID_DUMMY);
					}
				}
			}
			break;
		case EVT_ID_SRV_SMS_UPDATE_MSG:
			if(mmi_sms_is_on_list_screen())
			{
				msg_box_type = srv_sms_get_list_type(
									update_info->new_msg_info.status,
									update_info->new_msg_info.storage_type,
									update_info->new_msg_info.folder_id);
				// show please wait pop-up only in case message content is updated
				if((msg_box_type == g_sms_list_struct->curr_box) && (update_info->change_para_flag & SRV_SMS_PARA_CONTENT_BUFF) )
					mmi_popup_display_ext( STR_GLOBAL_LOADING, MMI_EVENT_INFO,NULL);			
			}
			break;
	}

	
	return MMI_RET_OK;
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_delete_all
 * DESCRIPTION
 * function for the delete all query entry
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
 static void mmi_sms_delete_all(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

	mmi_sms_entry_confirm_generic(STR_GLOBAL_DELETE_ALL_ASK, mmi_sms_delete_folder_req, mmi_frm_scrn_close_active_id);
}

	
/*****************************************************************************
 * FUNCTION
 *  mmi_sms_entry_delete_processing_screen
 * DESCRIPTION
 * entry for the delete folder processing screen
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
 static void mmi_sms_entry_delete_processing_screen(void)
{
	/*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	U16 process_image_id;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	if(mmi_frm_scrn_enter(
			GRP_ID_SMS_MAIN,
			SCR_ID_SMS_PROCESSING,
			NULL,
			mmi_sms_entry_delete_processing_screen,
			MMI_FRM_FULL_SCRN))
	{
		process_image_id = mmi_get_event_based_image(MMI_EVENT_PROGRESS);
		ShowCategory8Screen(
            0,
            0,
            0,
            0,
            0,
            0,
            STR_GLOBAL_DELETING,
            process_image_id,
            NULL);
	}

}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_delete_folder_req
 * DESCRIPTION
 * API to handle the delete message folder req
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
 static void mmi_sms_delete_folder_req(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	mmi_sms_del_folder_struct *delete_context;
	srv_sms_sim_enum sim_id = SRV_SMS_SIM_1;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	#if (MMI_MAX_SIM_NUM >= 2)
	sim_id |=SRV_SMS_SIM_2;
	#endif
	delete_context = OslMalloc(sizeof(mmi_sms_del_folder_struct ));
	delete_context->msg_box_type = current_box;
	//mmi_sms_set_and_entry_processing_sg(GRP_ID_SMS_MAIN, STR_GLOBAL_DELETING, STR_GLOBAL_CANCEL);
	mmi_sms_entry_delete_processing_screen();
	delete_handle = srv_sms_delete_msg_list_ex
						(
						current_box,
						sim_id,
						mmi_sms_delete_folder_callback,
						delete_context);
	

}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_delete_folder_callback
 * DESCRIPTION
 * callback for the SMS delete all folder request
 * PARAMETERS
 *  srv_sms_callback_struct
 * RETURNS
 *  void
 *****************************************************************************/
 static void mmi_sms_delete_folder_callback(srv_sms_callback_struct* callback_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	mmi_sms_del_folder_struct *delete_context;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	delete_context = (mmi_sms_del_folder_struct*)callback_data->user_data;
	mmi_frm_scrn_close(GRP_ID_SMS_MAIN,SCR_ID_SMS_PROCESSING);	
	OslMfree(delete_context);

}

#ifdef __TOPWELL_MMI_FACTORY_RESET__
#if 1
extern U8 g_restore_is_processing_flag;
extern void topwell_mmi_phb_delete_all_for_reset(void);
/*****************************************************************************
 * FUNCTION
 *  topwell_mmi_um_ui_sh_general_folder_opt_del_all
 * DESCRIPTION
 *  topwell_mmi_um_ui_sh_general_folder_opt_del_all.
 *
 * PARAMETERS
 *  tb_info             [OUT]: Toolbar information
 *  box_type            [IN]:  Box type
 *  
 * RETURNS
 *  void
 *****************************************************************************/
U16 g_message_list_size;  
U16*g_message_id_list;	
U16 message_list_index = 0;
srv_sms_box_enum g_box_type = SRV_SMS_BOX_INBOX;

void topwell_mmi_sms_folder_del_all_factory_reset(void);
void topwell_mmi_sms_check_msg_storage(srv_sms_box_enum box_type);

static void topwell_msg_delete_msg_rsp(srv_sms_callback_struct* callback_data)
{
	if(callback_data->result)
	{
		StartTimer(TIMER_RESET_ALL_WAIT_ID, 50, topwell_mmi_sms_folder_del_all_factory_reset);  
	}
	else
	{
		topwell_mmi_sms_check_msg_storage(g_box_type);
	}
}

void topwell_mmi_sms_check_msg_storage(srv_sms_box_enum box_type)
{
	if(message_list_index < g_message_list_size)
	{
		if(srv_sms_get_msg_storage_type(g_message_id_list[message_list_index]) == SRV_SMS_STORAGE_ME)
		{
			srv_sms_delete_msg(g_message_id_list[message_list_index], topwell_msg_delete_msg_rsp, NULL);
		}
		else
		{
			message_list_index++;
			topwell_mmi_sms_check_msg_storage(g_box_type);
		}
	}
	else
	{
		if(g_box_type != SRV_SMS_BOX_UNSENT)
		{
			g_box_type = g_box_type << 1;
			topwell_mmi_sms_folder_del_all_factory_reset();
		}
		else
		{
			topwell_mmi_phb_delete_all_for_reset();
		}
	}
}

void topwell_mmi_phone_sms_folder_del_msg(srv_sms_box_enum box_type)
{
	srv_sms_get_list_and_size(&g_message_id_list, &g_message_list_size, box_type); 
	topwell_mmi_sms_check_msg_storage(box_type);
}

void topwell_mmi_sms_folder_del_all_factory_reset(void) 
{
	message_list_index = 0;
	g_message_id_list = 0;
	g_message_list_size = 0;
	StopTimer(TIMER_RESET_ALL_WAIT_ID);
	topwell_mmi_phone_sms_folder_del_msg(g_box_type);
}

#else

extern void topwell_mmi_phb_delete_all_for_reset(void);

 static void topwell_mmi_sms_delete_folder_reset_callback(srv_sms_callback_struct* callback_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	mmi_sms_del_folder_struct *delete_context;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	delete_context = (mmi_sms_del_folder_struct*)callback_data->user_data;
	OslMfree(delete_context);
	if(callback_data->result==MMI_TRUE)
	{
       topwell_mmi_phb_delete_all_for_reset();
	} 
}

void topwell_mmi_sms_folder_del_all_factory_reset(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	mmi_sms_del_folder_struct *delete_context;
	srv_sms_sim_enum sim_id = SRV_SMS_SIM_1;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	current_box= SRV_SMS_BOX_INBOX|SRV_SMS_BOX_OUTBOX|SRV_SMS_BOX_DRAFTS|SRV_SMS_BOX_UNSENT;
	#if (MMI_MAX_SIM_NUM >= 2)
	sim_id |=SRV_SMS_SIM_2;
	#endif
	delete_context = OslMalloc(sizeof(mmi_sms_del_folder_struct ));
	delete_context->msg_box_type = current_box;
	//mmi_sms_entry_delete_processing_screen();
	delete_handle = srv_sms_delete_msg_list_ex
						(
						current_box,
						sim_id,
						topwell_mmi_sms_delete_folder_reset_callback,
						delete_context);
	

}

#endif
#endif

/********************** Idle handling starts *************************/

#define MMI_UM_UI_MAX_IDLE_UNREAD_STRING_LEN (48)   /* the maximum length of unread message string */

static NMGR_HANDLE g_new_msg_handle;
static MMI_BOOL g_is_new_msg_icon_only;

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_nmgr_proc
 * DESCRIPTION
 * proc function for the NMGR alert
 * PARAMETERS
 *  mmi_event_struct
 * RETURNS
 *  void
 *****************************************************************************/
 static mmi_ret mmi_sms_nmgr_proc(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	switch(evt->evt_id)
	{
		case EVT_ID_NMGR_TEXT_PREVIEW_APP_LAUNCH:
		case EVT_ID_NMGR_POPUP_APP_LAUNCH:
			mmi_sms_enter_message_list(SRV_SMS_BOX_INBOX, GRP_ID_ROOT);
			
	    case EVT_ID_NMGR_ALERT_END:	
			g_is_new_msg_icon_only = MMI_TRUE;
			break;
	}
    return MMI_OK;
} 

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_prepare_alert_info
 * DESCRIPTION
 * function to create info for the NMGR alert
 * PARAMETERS
 *  mmi_frm_nmgr_alert_struct
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_sms_prepare_alert_info(mmi_frm_nmgr_alert_struct *alert_info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	U16 unread_num;
	static WCHAR main_text[MMI_UM_UI_MAX_IDLE_UNREAD_STRING_LEN * 2 + 1];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	mmi_wcscpy(main_text, (WCHAR *)GetString(STR_UM_UNREAD_MSG));
	unread_num = srv_sms_get_unread_sms_num();

	if (srv_sms_is_sms_ready())
	{
		if(unread_num)
		{
			MMI_ID unread_string = STR_UM_UNREAD_MSGS_WITH_NUMBER;
			WCHAR sub_text[MMI_UM_UI_MAX_IDLE_UNREAD_STRING_LEN + 1];

			if (unread_num == 1)
			{
				unread_string = STR_UM_UNREAD_MSG_WITH_NUMBER;
			}
			mmi_wsprintf(
				sub_text, 
				MMI_UM_UI_MAX_IDLE_UNREAD_STRING_LEN, 
				unread_string, 
				unread_num);

			mmi_ucs2cat((CHAR *)main_text, (const CHAR *)L"\n");
			mmi_ucs2cat((CHAR *)main_text, (const CHAR *)sub_text);
		}
	}
	alert_info->popup_para.popup_string = main_text;
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_inbox_alert
 * DESCRIPTION
 * alert for the new message
 * PARAMETERS
 *  mmi_frm_nmgr_alert_struct
 * RETURNS
 *  void
 *****************************************************************************/
 void mmi_sms_inbox_alert(mmi_frm_nmgr_alert_struct *alert)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	mmi_frm_nmgr_alert_struct *alert_info = (mmi_frm_nmgr_alert_struct *)alert;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/	
	mmi_sms_prepare_alert_info(alert_info);
	
		/*fill in app id for NSS query*/
	alert_info->app_id = APP_SMS; //your app id

	alert_info->ui_mask = MMI_FRM_NMGR_UI_STATUS_ICON_MASK|
						  MMI_FRM_NMGR_UI_STATUS_BAR_MASK|
						  MMI_FRM_NMGR_UI_POPUP_MASK;
	/*Once the NSS is not support , NMGR will take the behavior mask as its behavior guildline*/
	alert_info->behavior_mask = PREFER_STATUS_BAR; // or PREFER_STATUS_BAR. PREFER_ICON_ONLY

	/*fill in the status bar information*/
	alert_info->status_bar_para.status_bar_type = MMI_FRM_NMGR_ALERT_ST_PREVIEW_TYPE;
	/*the image icon is used for text preview, can be different from popup*/
	/*fill in the status bar icon information*/
	alert_info->status_bar_icon_para.icon_id = STATUS_ICON_INCOMING_SMS; 				
	 

	/*fill in the popup information*/	 
	alert_info->popup_para.popup_type = MMI_FRM_NMGR_ALERT_POPUP_TWO_BUTTON_TYPE;
	/*the image icon is used for popup, can be different from text preview*/
	#ifdef __TOPWELL_MMI_NEW_SMS_VIEW_STR_ALONE__
	alert_info->popup_para.popup_button_string = (WCHAR*)GetString(STR_GLOBAL_NEW_SMS_VIEW);
	alert_info->popup_para.popup_button_str_id=STR_GLOBAL_NEW_SMS_VIEW;
	#else
	alert_info->popup_para.popup_button_string = (WCHAR*)GetString(STR_GLOBAL_VIEW);
	alert_info->popup_para.popup_button_str_id=STR_GLOBAL_VIEW;
	#endif
	

	/*fill in the app launch callback*/
	alert_info->app_proc_para.scrn_group_proc = mmi_sms_nmgr_proc;
	alert_info->app_proc_para.user_data= NULL;
	g_new_msg_handle = mmi_frm_nmgr_alert(alert_info);
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_alert_inbox_update_icon_only
 * DESCRIPTION
 * to update only the icon for the new message
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
 static void mmi_sms_alert_inbox_update_icon_only(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	mmi_frm_nmgr_alert_struct alert_info;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	memset(&alert_info, 0, sizeof(alert_info));
	alert_info.event_type = MMI_EVENT_INFO;
	alert_info.scen_id = MMI_SCENARIO_ID_GENERAL;
	alert_info.app_id = APP_SMS; //your app id

	alert_info.alert_option = MMI_FRM_NMGR_DISABLE_PREVIEW |
								MMI_FRM_NMGR_DISABLE_TONE |
								MMI_FRM_NMGR_DISABLE_VIB |
								MMI_FRM_NMGR_DISABLE_POPUP; /* set status icon */
	
	alert_info.ui_mask = MMI_FRM_NMGR_UI_STATUS_ICON_MASK;
		/*fill in the status bar information*/
	alert_info.status_bar_para.status_bar_type = MMI_FRM_NMGR_ALERT_ST_PREVIEW_TYPE;
	/*the image icon is used for text preview, can be different from popup*/
	/*fill in the status bar icon information*/
	alert_info.status_bar_icon_para.icon_id = STATUS_ICON_INCOMING_SMS;	
	g_new_msg_handle = mmi_frm_nmgr_alert(&alert_info);
	g_is_new_msg_icon_only = MMI_TRUE;
}

/*****************************************************************************
 * FUNCTION
 *  mmi_sms_alert_inbox_refresh
 * DESCRIPTION
 * function to refresh NMGR whenever a new event is recieved
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
 static void mmi_sms_alert_inbox_refresh(void)
{
	if (g_new_msg_handle != NULL)
	{
		if( srv_sms_get_unread_sms_num() == 0)
		{
		    mmi_frm_nmgr_alert_cancel(g_new_msg_handle);
			g_new_msg_handle = NULL;
			return;
		}
	
		if ((MMI_FALSE == g_is_new_msg_icon_only))
		{		
			mmi_frm_nmgr_alert_struct alert_info;

			mmi_sms_prepare_alert_info(&alert_info);
			alert_info.app_id = APP_SMS; //your app id
			alert_info.alert_option = MMI_FRM_NMGR_DISABLE_PREVIEW |
											MMI_FRM_NMGR_DISABLE_TONE |
											MMI_FRM_NMGR_DISABLE_VIB;
	        alert_info.status_bar_icon_para.icon_id = STATUS_ICON_INCOMING_SMS;
			g_new_msg_handle = mmi_frm_nmgr_alert(&alert_info);
			
			g_is_new_msg_icon_only = MMI_FALSE;
		}
	}
	#ifndef __MMI_NCENTER_SUPPORT__
	/* if ncenter is enabled, the icon is only set by ecenter entry */
	else
	{
		if(srv_sms_get_unread_sms_num())
		{
			mmi_sms_alert_inbox_update_icon_only();
		}
	}
	#endif
   
}

/********************** Idle handling finish*************************/


#endif /* __MMI_TELEPHONY_SUPPORT__*/

#endif /* __UM_FOLDER__*/