update tizen source
[framework/messaging/msg-service.git] / test_app / MsgTestThreadView.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31
32 /*==================================================================================================
33                                          INCLUDE FILES
34 ==================================================================================================*/
35 #include <time.h>
36 #include <iostream>
37 #include <string>
38 #include <stdlib.h>
39 using namespace std;
40
41 #include "MsgMmsTypes.h"
42 #include "MsgTypes.h"
43 #include "MapiStorage.h"
44 #include "MapiSetting.h"
45 #include "MapiMessage.h"
46 #include "MsgTestStorage.h"
47 #include "MsgTestTransport.h"
48 #include "MsgTestThreadView.h"
49 #include "main.h"
50
51
52 #define MSG_PROFILE_BEGIN(pfid) \
53         unsigned int __prf_l1_##pfid = __LINE__;    \
54         struct timeval __prf_1_##pfid;              \
55         struct timeval __prf_2_##pfid;              \
56         do {                                        \
57                 gettimeofday(&__prf_1_##pfid, 0);       \
58         } while (0)
59
60 #define MSG_PROFILE_END(pfid) \
61         unsigned int __prf_l2_##pfid = __LINE__;\
62         do { \
63                 gettimeofday(&__prf_2_##pfid, 0);\
64                 long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
65                 long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
66                 if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
67                 printf("**PROFILE** [MSGFW: %s: %s() %u ~ %u] " #pfid " -> Elapsed Time: %u.%06u seconds\n",                    \
68                 rindex(__FILE__, '/')+1,                \
69                 __FUNCTION__, \
70                 __prf_l1_##pfid,                                         \
71                 __prf_l2_##pfid,                                         \
72                 (unsigned int)(__ds),                                    \
73                 (unsigned int)(__dm));                                   \
74         } while (0)
75
76
77 /*==================================================================================================
78                                      FUNCTION IMPLEMENTATION
79 ==================================================================================================*/
80 void MsgThreadViewMain(MSG_HANDLE_T hMsgHandle)
81 {
82         if (hMsgHandle == NULL)
83         {
84                 MSG_DEBUG("Handle is NULL");
85                 return;
86         }
87
88         char menu[5];
89
90         MSG_ERROR_T err = MSG_SUCCESS;
91
92         MSG_SORT_RULE_S sortRule = {0};
93
94         // Set Sort Rule
95         sortRule.sortType = MSG_SORT_BY_THREAD_DATE;
96         sortRule.bAscending = false;
97
98         MSG_THREAD_VIEW_LIST_S threadViewList;
99
100         char displayTime[32];
101
102         do
103         {
104                 err = msg_get_thread_view_list(hMsgHandle, NULL, &threadViewList);
105
106                 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD)
107                 {
108                         print("Get Message List is failed!");
109                         return;
110                 }
111
112                 system ("clear" );
113
114                 print("======================================");
115                 print("============ Thread View =============");
116                 print("======================================");
117
118                 if (threadViewList.nCount <= 0)
119                 {
120                         print("Empty...");
121                 }
122                 else
123                 {
124                         MSG_PROFILE_BEGIN(1);
125
126                         for (int i = 0; i < threadViewList.nCount; i++)
127                         {
128                                 memset(displayTime, 0x00, sizeof(displayTime));
129
130                                 MsgConvertTime(msg_thread_view_get_time(threadViewList.msgThreadInfo[i]), displayTime);
131
132                                 printf("[%04d]\tUnread Msg [%d]\t[%s] [%s] [%s]\n[%s]\tType [%s]\tMessage Text [%s]\n",
133                                                 msg_thread_view_get_thread_id(threadViewList.msgThreadInfo[i]),
134                                                 msg_thread_view_get_unread_cnt(threadViewList.msgThreadInfo[i]),
135                                                 msg_thread_view_get_address(threadViewList.msgThreadInfo[i]),
136                                                 msg_thread_view_get_name(threadViewList.msgThreadInfo[i]),
137                                                 displayTime,
138                                                 MsgConvertDirection(msg_thread_view_get_direction(threadViewList.msgThreadInfo[i])),
139                                                 MsgConvertType(msg_thread_view_get_message_type(threadViewList.msgThreadInfo[i])),
140                                                 msg_thread_view_get_data(threadViewList.msgThreadInfo[i]));
141
142                                 printf("--------------------------------------------------------\n");
143                         }
144                         MSG_PROFILE_END(1);
145                 }
146
147                 print("======================================");
148                 print("================ Menu ================");
149                 print("======================================");
150                 print("[C] Create Message");
151                 print("[D] Delete Thread");
152                 print("[B] Back");
153                 print("======================================");
154
155                 print("Input : ");
156
157                 memset(menu, 0x00, sizeof(menu));
158                 cin.getline(menu, 5);
159
160                 if (!strcmp(menu, "C") || !strcmp(menu, "c")) // Add Message
161                 {
162                         MsgTestAddMessage(hMsgHandle);
163                 }
164                 else if (!strcmp(menu, "D") || !strcmp(menu, "d"))
165                 {
166                         print("Choose Thread ID : ");
167
168                         char id[5];
169
170                         memset(id, 0x00, sizeof(id));
171                         cin.getline(id, 5);
172
173                         print("Do you really wanna delete messages in thread [Y or N] ?");
174
175                         char select[2];
176
177                         memset(select, 0x00, sizeof(select));
178                         cin.getline(select, 2);
179
180 MSG_PROFILE_BEGIN(3);
181                         if (!strcmp(select, "Y") || !strcmp(select, "y"))
182                                 msg_delete_thread_message_list(hMsgHandle, (MSG_THREAD_ID_T)atoi(id));
183 MSG_PROFILE_END(3);
184                 }
185                 else if (!strcmp(menu, "B") || !strcmp(menu, "b"))
186                 {
187                         msg_release_thread_view_list(&threadViewList);
188                         MSG_DEBUG("release thread view list [%d]", threadViewList.nCount);
189                         break;
190                 }
191                 else
192                 {
193                         MSG_THREAD_ID_T threadId = atoi(menu);
194
195                         for (int i = 0; i < threadViewList.nCount; i++)
196                         {
197                                 if ((MSG_THREAD_ID_T)msg_thread_view_get_thread_id(threadViewList.msgThreadInfo[i]) == threadId)
198                                 {
199                                         MsgRunConversationView(hMsgHandle, threadId, msg_thread_view_get_address(threadViewList.msgThreadInfo[i]), msg_thread_view_get_name(threadViewList.msgThreadInfo[i]));
200
201                                         break;
202                                 }
203                         }
204                 }
205
206                 msg_release_thread_view_list(&threadViewList);
207                 MSG_DEBUG("release thread view list [%d]", threadViewList.nCount);
208         }
209         while (strcmp(menu, "B"));
210 }
211
212
213 void MsgSearchViewMain(MSG_HANDLE_T hMsgHandle)
214 {
215         if (hMsgHandle == NULL)
216         {
217                 MSG_DEBUG("Handle is NULL");
218                 return;
219         }
220
221         char menu[5], displayTime[32], searchString[1024];
222
223         MSG_ERROR_T err = MSG_SUCCESS;
224
225         do
226         {
227                 print("Search Mode 0:Message 1:Thread :");
228
229                 memset(menu, 0x00, sizeof(menu));
230                 cin.getline(menu, 4);
231
232                 int searchType = atoi(menu);
233
234
235                 print("Input String to Search :");
236
237                 memset(searchString, 0x00, sizeof(searchString));
238
239                 cin.getline(searchString, 1024);
240
241
242                 if(searchType == 0)
243                 {
244
245                         MSG_LIST_S msgList;
246
247                         print("Target folder (0:ALLBOX 1:INBOX 2:OUTBOX 3:SENTBOX) :");
248
249                         memset(menu, 0x00, sizeof(menu));
250                         cin.getline(menu, 4);
251
252                         int folderId = atoi(menu);
253
254
255                         print("Target message type (0:ALLTYPE 1:SMS 9:MMS) :");
256
257                         memset(menu, 0x00, sizeof(menu));
258                         cin.getline(menu, 4);
259
260                         int msgType = atoi(menu);
261
262
263                         print("Search Result offset (0~) :");
264
265                         memset(menu, 0x00, sizeof(menu));
266                         cin.getline(menu, 4);
267
268                         int offset = atoi(menu);
269
270
271                         print("Search Result limit (0~) :");
272
273                         memset(menu, 0x00, sizeof(menu));
274                         cin.getline(menu, 4);
275
276                         int limit = atoi(menu);
277
278                         MSG_SEARCH_CONDITION_S searchCon;
279                         memset(&searchCon, 0x00, sizeof(MSG_SEARCH_CONDITION_S));
280
281                         searchCon.msgType = msgType;
282                         searchCon.folderId = folderId;
283                         searchCon.pSearchVal = searchString;
284                         searchCon.pAddressVal = searchString;
285
286                         MSG_PROFILE_BEGIN(_msg_search_message_);
287                         err = msg_search_message(hMsgHandle, &searchCon, offset, limit, &msgList);
288                         MSG_PROFILE_END(_msg_search_message_);
289
290                         if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD)
291                         {
292                                 print("Get Message List is failed!");
293                                 return;
294                         }
295
296
297                         system ("clear" );
298
299                         print("======================================");
300                         print("============ Search View =============");
301                         print("======================================");
302
303                         if (msgList.nCount <= 0)
304                         {
305                                 print("Empty...");
306                         }
307                         else
308                         {
309
310                                 for (int i = 0; i < msgList.nCount; i++)
311                                 {
312                                         memset(displayTime, 0x00, sizeof(displayTime));
313
314                                         MsgConvertTime(msg_get_time(msgList.msgInfo[i]), displayTime);
315
316                                         const char* msgText = NULL;
317
318                                         int msgType = msg_get_message_type(msgList.msgInfo[i]);
319
320                                         if(msgType==MSG_TYPE_MMS_NOTI || msgType==MSG_TYPE_MMS_JAVA || msgType==MSG_TYPE_MMS)
321                                                 msgText = msg_mms_get_text_contents(msgList.msgInfo[i]);
322                                         else
323                                                 msgText = msg_sms_get_message_body(msgList.msgInfo[i]);
324
325                                         printf("[%02d]\t[%s %s %s %s] [%s]\t[%s]\nDate [%s]\nMessage Text [%s] \tMessage data size [%d]\n",
326                                                         msg_get_message_id(msgList.msgInfo[i]),
327                                                         MsgConvertMsgType(msg_get_message_type(msgList.msgInfo[i])),
328                                                         MsgConvertStorageId(msg_get_storage_id(msgList.msgInfo[i])),
329                                                         MsgConvertReadStatus(msg_is_read(msgList.msgInfo[i])),
330                                                         MsgConvertProtectedStatus(msg_is_protected(msgList.msgInfo[i])),
331                                                         MsgConvertNetworkStatus(msg_get_network_status(msgList.msgInfo[i])),
332                                                         msg_get_ith_address(msgList.msgInfo[i], 0),
333                                                         displayTime,
334                                                         msgText,
335                                                         msg_get_message_body_size(msgList.msgInfo[i]));
336                                         printf("--------------------------------------------------------\n");
337                                 }
338                         }
339
340                         print("======================================");
341                         print("================ Menu ================");
342                         print("======================================");
343                         print("[S] Search Again");
344                         print("[B] Back");
345                         print("======================================");
346
347                         print("Input : ");
348
349                         memset(menu, 0x00, sizeof(menu));
350                         cin.getline(menu, 5);
351
352                         if (!strcmp(menu, "S") || !strcmp(menu, "s"))
353                         {
354                                 continue;
355                         }
356                         else if (!strcmp(menu, "B") || !strcmp(menu, "b"))
357                         {
358                                 msg_release_message_list(&msgList);
359                                 MSG_DEBUG("release msg list [%d]", msgList.nCount);
360                                 break;
361                         }
362                         else
363                         {
364                                 int msgId = atoi(menu);
365
366                                 MsgTestGetMessage(hMsgHandle, msgId);
367                                 break;
368                         }
369
370                         msg_release_message_list(&msgList);
371                         MSG_DEBUG("release msg list [%d]", msgList.nCount);
372                 }
373                 else if(searchType == 1)
374                 {
375
376                         MSG_THREAD_VIEW_LIST_S threadViewList;
377
378                 MSG_PROFILE_BEGIN(1);
379
380                         err = msg_search_message_for_thread_view(hMsgHandle, searchString, &threadViewList);
381
382                 MSG_PROFILE_END(1);
383
384                 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD)
385                 {
386                         print("Get Message List is failed!");
387                         return;
388                 }
389
390                 system ("clear" );
391
392                 print("======================================");
393                 print("============ Search View =============");
394                 print("======================================");
395
396                 if (threadViewList.nCount <= 0)
397                 {
398                         print("Empty...");
399                 }
400                 else
401                 {
402
403                         for (int i = 0; i < threadViewList.nCount; i++)
404                         {
405                                 memset(displayTime, 0x00, sizeof(displayTime));
406
407                                 MsgConvertTime(msg_thread_view_get_time(threadViewList.msgThreadInfo[i]), displayTime);
408
409                                 printf("[%04d]\tUnread Msg [%d]\t[%s] [%s] [%s] [%s]\n[%s]\tMessage Text [%s]\n",
410                                                 msg_thread_view_get_thread_id(threadViewList.msgThreadInfo[i]),
411                                                 msg_thread_view_get_unread_cnt(threadViewList.msgThreadInfo[i]),
412                                                 msg_thread_view_get_address(threadViewList.msgThreadInfo[i]),
413                                                 msg_thread_view_get_name(threadViewList.msgThreadInfo[i]),
414                                                 msg_thread_view_get_image_path(threadViewList.msgThreadInfo[i]),
415                                                 displayTime,
416                                                 MsgConvertDirection(msg_thread_view_get_direction(threadViewList.msgThreadInfo[i])),
417                                                 msg_thread_view_get_data(threadViewList.msgThreadInfo[i]));
418
419                                 printf("--------------------------------------------------------\n");
420                         }
421                 }
422
423                 print("======================================");
424                 print("================ Menu ================");
425                 print("======================================");
426                 print("[C] Create Message");
427                 print("[D] Delete Thread");
428                 print("[S] Search Again");
429                 print("[B] Back");
430                 print("======================================");
431
432                 print("Input : ");
433
434                 memset(menu, 0x00, sizeof(menu));
435                 cin.getline(menu, 5);
436
437                 if (!strcmp(menu, "C") || !strcmp(menu, "c")) // Add Message
438                 {
439                         MsgTestAddMessage(hMsgHandle);
440                 }
441                 else if (!strcmp(menu, "D") || !strcmp(menu, "d"))
442                 {
443                         print("Choose Thread ID : ");
444
445                         char id[5];
446
447                         memset(id, 0x00, sizeof(id));
448                         cin.getline(id, 5);
449
450                         print("Do you really wanna delete messages in thread [Y or N] ?");
451
452                         char select[2];
453
454                         memset(select, 0x00, sizeof(select));
455                         cin.getline(select, 2);
456
457                         if (!strcmp(select, "Y") || !strcmp(select, "y"))
458                                 msg_delete_thread_message_list(hMsgHandle, (MSG_THREAD_ID_T)atoi(id));
459                 }
460                 else if (!strcmp(menu, "S") || !strcmp(menu, "s"))
461                 {
462                         continue;
463                 }
464                 else if (!strcmp(menu, "B") || !strcmp(menu, "b"))
465                 {
466                         msg_release_thread_view_list(&threadViewList);
467                         MSG_DEBUG("release thread view list [%d]", threadViewList.nCount);
468                         break;
469                 }
470                 else
471                 {
472                         MSG_THREAD_ID_T threadId = atoi(menu);
473
474                         for (int i = 0; i < threadViewList.nCount; i++)
475                         {
476                                 if ((MSG_THREAD_ID_T)msg_thread_view_get_thread_id(threadViewList.msgThreadInfo[i]) == threadId)
477                                 {
478                                         MsgRunConversationView(hMsgHandle, threadId, msg_thread_view_get_address(threadViewList.msgThreadInfo[i]), msg_thread_view_get_name(threadViewList.msgThreadInfo[i]));
479
480                                         break;
481                                 }
482                         }
483                 }
484
485                 msg_release_thread_view_list(&threadViewList);
486                 MSG_DEBUG("release thread view list [%d]", threadViewList.nCount);
487         }
488         }
489         while (strcmp(menu, "B"));
490 }
491
492
493 void MsgRunConversationView(MSG_HANDLE_T hMsgHandle, MSG_THREAD_ID_T ThreadId, const char *pAddress, const char *pName)
494 {
495         char menu[5];
496
497         char displayTime[32];
498
499         MSG_ERROR_T err = MSG_SUCCESS;
500
501         MSG_LIST_S convViewList;
502
503         do
504         {
505                 err = msg_get_conversation_view_list(hMsgHandle, ThreadId, &convViewList);
506
507                 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD)
508                 {
509                         print("Get Message List is failed!");
510                         return;
511                 }
512
513                 system ("clear" );
514
515                 printf("======================================\n");
516                 printf("============ %s ============\n", pAddress);
517                 printf("============ %s ============\n", pName);
518                 printf("======================================\n");
519
520                 if (convViewList.nCount <= 0)
521                 {
522                         print("Empty...");
523                 }
524                 else
525                 {
526                         for (int i = 0; i < convViewList.nCount; i++)
527                         {
528                                 memset(displayTime, 0x00, sizeof(displayTime));
529
530                                 MsgConvertTime(msg_get_time(convViewList.msgInfo[i]), displayTime);
531
532                                 const char* msgText = NULL;
533
534                                 int msgType = msg_get_message_type(convViewList.msgInfo[i]);
535
536                                 if(msgType==MSG_TYPE_MMS_NOTI || msgType==MSG_TYPE_MMS_JAVA || msgType==MSG_TYPE_MMS)
537                                         msgText = msg_mms_get_text_contents(convViewList.msgInfo[i]);
538                                 else
539                                         msgText = msg_sms_get_message_body(convViewList.msgInfo[i]);
540
541                                 printf("[%04d]\t[%s] [%s]\tText [%s] Attachment count [%d] Date [%s]\n",
542                                                 msg_get_message_id(convViewList.msgInfo[i]),
543                                                 MsgConvertDirection(msg_get_direction_info(convViewList.msgInfo[i])),
544                                                 MsgConvertMsgType(msg_get_message_type(convViewList.msgInfo[i])),
545                                                 msgText,
546                                                 msg_get_attachment_count(convViewList.msgInfo[i]),
547                                                 displayTime);
548
549                                 printf("--------------------------------------------------------\n");
550                         }
551                 }
552
553                 print("======================================");
554                 print("================ Menu ================");
555                 print("======================================");
556                 print("[R] Reply");
557                 print("[D] Delete Message");
558                 print("[B] Back");
559                 print("======================================");
560
561                 print("Input : ");
562
563                 memset(menu, 0x00, sizeof(menu));
564                 cin.getline(menu, 5);
565
566                 if (!strcmp(menu, "R") || !strcmp(menu, "r"))
567                 {
568
569                 }
570                 else if (!strcmp(menu, "D") || !strcmp(menu, "d"))
571                 {
572
573                 }
574
575                 msg_release_message_list(&convViewList);
576                 MSG_DEBUG("release conversation view list [%d]", convViewList.nCount);
577         }
578         while (strcmp(menu, "B") && strcmp(menu, "b"));
579 }
580
581
582 const char* MsgConvertDirection(MSG_DIRECTION_TYPE_T Direction)
583 {
584         if (Direction == MSG_DIRECTION_TYPE_MO)
585                 return "SENT";
586         else if (Direction == MSG_DIRECTION_TYPE_MT)
587                 return "RECEIVED";
588
589         return "RECEIVED";
590 }
591
592
593 const char* MsgConvertType(MSG_MESSAGE_TYPE_T MsgType)
594 {
595         if (MsgType == MSG_TYPE_SMS)
596                 return "SMS";
597         else if (MsgType == MSG_TYPE_SMS_CB ||MsgType == MSG_TYPE_SMS_JAVACB)
598                 return "CB";
599         else if (MsgType == MSG_TYPE_SMS_WAPPUSH)
600                 return "WAP Push";
601         else if (MsgType == MSG_TYPE_SMS_MWI)
602                 return "MWI";
603         else if (MsgType == MSG_TYPE_SMS_SYNCML)
604                 return "SyncML";
605         else if (MsgType == MSG_TYPE_SMS_REJECT)
606                 return "Reject SMS";
607         else if (MsgType == MSG_TYPE_MMS)
608                 return "MMS";
609         else if (MsgType == MSG_TYPE_MMS_NOTI)
610                 return "MMS Noti";
611         else if (MsgType == MSG_TYPE_MMS_JAVA)
612                 return "Java MMS";
613
614         return "SMS";
615 }
616