update tizen source
[framework/messaging/msg-service.git] / utils / MsgNotificationWrapper.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 #include "MsgDebug.h"
32 #include "MsgContact.h"
33 #include "MsgStorageTypes.h"
34 #include "MsgNotificationWrapper.h"
35
36 extern "C"
37 {
38         #include <notification.h>
39 }
40
41 /*==================================================================================================
42                                      FUNCTION IMPLEMENTATION
43 ==================================================================================================*/
44 MSG_ERROR_T MsgInsertNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S* pMsg)
45 {
46
47         notification_h noti = NULL;
48         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
49         bundle* args;
50
51         int contactId = 0;
52         int threadId = 0;
53         time_t msgTime = 0;
54         char tempId[6];
55         char addressVal[MAX_ADDRESS_VAL_LEN+1];
56         char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
57         char displayName[MAX_DISPLAY_NAME_LEN+1];
58         char sqlQuery[MAX_QUERY_LEN+1];
59
60         memset(tempId, 0x00, sizeof(tempId));
61         memset(addressVal, 0x00, sizeof(addressVal));
62         memset(firstName, 0x00, sizeof(firstName));
63         memset(lastName, 0x00, sizeof(lastName));
64         memset(displayName, 0x00, sizeof(displayName));
65         memset(sqlQuery, 0x00, sizeof(sqlQuery));
66
67         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, \
68                                                 B.DISPLAY_TIME, A.CONTACT_ID \
69                                                 FROM %s A, %s B \
70                                              WHERE B.MSG_ID=%d AND A.ADDRESS_ID=B.ADDRESS_ID;",
71                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
72
73         if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
74                 return MSG_ERR_DB_PREPARE;
75
76         if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
77                 threadId = pDbHandle->columnInt(0);
78
79                 if (pDbHandle->columnText(1) != NULL)
80                         strncpy(addressVal, (char*)pDbHandle->columnText(1), MAX_ADDRESS_VAL_LEN);
81
82
83                 char *pTempDisplayName = (char *)pDbHandle->columnText(2);
84                 if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
85                         strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
86                 } else {
87                         if (pDbHandle->columnText(3) != NULL)
88                                 strncpy(firstName, (char*)pDbHandle->columnText(3), MAX_DISPLAY_NAME_LEN);
89
90                         if (pDbHandle->columnText(4) != NULL)
91                                 strncpy(lastName, (char*)pDbHandle->columnText(4), MAX_DISPLAY_NAME_LEN);
92
93                         int order = MsgGetContactNameOrder();
94
95                         if (order == 0) {
96                                 if (firstName[0] != '\0') {
97                                         strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
98                                 }
99
100                                 if (lastName[0] != '\0') {
101                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
102                                         strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
103                                 }
104                         } else if (order == 1) {
105                                 if (lastName[0] != '\0') {
106                                         strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
107                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
108                                 }
109
110                                 if (firstName[0] != '\0') {
111                                         strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
112                                 }
113                         }
114                 }
115
116                 msgTime = (time_t)pDbHandle->columnInt(5);
117
118                 contactId = pDbHandle->columnInt(6);
119         } else {
120                 pDbHandle->finalizeQuery();
121                 return MSG_ERR_DB_STEP;
122         }
123
124         pDbHandle->finalizeQuery();
125
126
127         args = bundle_create();
128
129         if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->msgType.subType == MSG_CB_SMS) {
130
131                 noti = notification_new(NOTIFICATION_TYPE_NOTI, 1, pMsg->msgId);
132                 if (noti == NULL) {
133                         MSG_DEBUG("notification_new is failed.");
134                         bundle_free(args);
135                         return MSG_ERR_UNKNOWN;
136                 }
137
138                 noti_err = notification_set_application(noti, "org.tizen.message");
139                 if (noti_err != NOTIFICATION_ERROR_NONE) {
140                         MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
141                 }
142
143                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, CB_MSG_ICON_PATH);
144                 if (noti_err != NOTIFICATION_ERROR_NONE) {
145                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
146                 }
147
148                 memset(&tempId, 0x00, sizeof(tempId));
149
150                 snprintf(tempId, 5, "%d", threadId);
151                 bundle_add(args, "threadId", tempId);
152         } else if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->msgType.classType == MSG_CLASS_0) {
153
154                 noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
155                 if (noti == NULL) {
156                         MSG_DEBUG("notification_new is failed.");
157                         bundle_free(args);
158                         return MSG_ERR_UNKNOWN;
159                 }
160
161                 noti_err = notification_set_application(noti, "org.tizen.msg-ui-class0");
162                 if (noti_err != NOTIFICATION_ERROR_NONE) {
163                         MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
164                 }
165
166                 snprintf(tempId, 5, "%d", pMsg->msgId);
167                 bundle_add(args, "msg_id", tempId);
168         } else if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->msgType.subType == MSG_MWI_VOICE_SMS) {
169
170                 noti = notification_new(NOTIFICATION_TYPE_NOTI, 1, pMsg->msgId);
171                 if (noti == NULL) {
172                         MSG_DEBUG("notification_new is failed.");
173                         bundle_free(args);
174                         return MSG_ERR_UNKNOWN;
175                 }
176
177                 noti_err = notification_set_application(noti, "org.tizen.message");
178                 if (noti_err != NOTIFICATION_ERROR_NONE) {
179                         MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
180                 }
181
182                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, VOICE_MSG_ICON_PATH);
183                 if (noti_err != NOTIFICATION_ERROR_NONE) {
184                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
185                 }
186
187                 memset(&tempId, 0x00, sizeof(tempId));
188
189                 snprintf(tempId, 5, "%d", threadId);
190                 bundle_add(args, "threadId", tempId);
191         } else {
192                 MSG_DEBUG("notification_new pMsg->msgId [%d]", pMsg->msgId);
193                 noti = notification_new(NOTIFICATION_TYPE_NOTI, 1, pMsg->msgId);
194                 if (noti == NULL) {
195                         MSG_DEBUG("notification_new is failed.");
196                         bundle_free(args);
197                         return MSG_ERR_UNKNOWN;
198                 }
199
200                 noti_err = notification_set_application(noti, "org.tizen.message");
201                 if (noti_err != NOTIFICATION_ERROR_NONE) {
202                         MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
203                 }
204
205                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
206                 if (noti_err != NOTIFICATION_ERROR_NONE) {
207                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
208                 }
209
210                 memset(&tempId, 0x00, sizeof(tempId));
211
212                 snprintf(tempId, 5, "%d", threadId);
213                 bundle_add(args, "threadId", tempId);
214         }
215
216         bundle_add(args, "type", "msg_id");
217
218         snprintf(tempId, 5, "%d", pMsg->msgId);
219         bundle_add(args, "msgId", tempId);
220
221         if (displayName[0] == '\0')
222                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
223         else
224                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
225
226         if (pMsg->msgType.mainType == MSG_SMS_TYPE)
227                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
228         else
229                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg->subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
230
231
232         if (args != NULL) {
233                 noti_err = notification_set_args(noti, args, NULL);
234                 if (noti_err != NOTIFICATION_ERROR_NONE) {
235                         MSG_DEBUG("Fail to notification_set_args : %d", noti_err);
236                 }
237         }
238
239         noti_err = notification_set_time(noti, msgTime);
240         if (noti_err != NOTIFICATION_ERROR_NONE) {
241                 MSG_DEBUG("Fail to notification_set_time : %d", noti_err);
242         }
243
244         noti_err = notification_insert(noti, NULL);
245         if (noti_err != NOTIFICATION_ERROR_NONE) {
246                 MSG_DEBUG("Fail to notification_insert");
247         }
248
249         noti_err = notification_free(noti);
250         if (noti_err != NOTIFICATION_ERROR_NONE) {
251                 MSG_DEBUG("Fail to notification_free");
252         }
253
254         bundle_free(args);
255
256         return MSG_SUCCESS;
257 }
258
259
260 MSG_ERROR_T MsgInsertSmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_ID_T MsgId, MSG_DELIVERY_REPORT_STATUS_T Status)
261 {
262         notification_h noti = NULL;
263         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
264
265         char addressVal[MAX_ADDRESS_VAL_LEN+1];
266         char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
267         char displayName[MAX_DISPLAY_NAME_LEN+1];
268         char contents[MAX_DISPLAY_NAME_LEN+1];
269         char sqlQuery[MAX_QUERY_LEN+1];
270
271         memset(addressVal, 0x00, sizeof(addressVal));
272         memset(firstName, 0x00, sizeof(firstName));
273         memset(lastName, 0x00, sizeof(lastName));
274         memset(displayName, 0x00, sizeof(displayName));
275         memset(contents, 0x00, sizeof(contents));
276         memset(sqlQuery, 0x00, sizeof(sqlQuery));
277
278         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME \
279                                                                        FROM %s A, %s B \
280                                                                     WHERE B.MSG_ID = %d \
281                                                                          AND A.ADDRESS_ID = B.ADDRESS_ID;",
282                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, MsgId);
283
284         if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
285                 return MSG_ERR_DB_PREPARE;
286
287         if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
288                 if (pDbHandle->columnText(0) != NULL)
289                         strncpy(addressVal, (char*)pDbHandle->columnText(0), MAX_ADDRESS_VAL_LEN);
290
291                 if (pDbHandle->columnText(1) != NULL) {
292                         strncpy(displayName, (char*)pDbHandle->columnText(1), MAX_DISPLAY_NAME_LEN);
293                 } else {
294                         if (pDbHandle->columnText(2) != NULL)
295                                 strncpy(firstName, (char*)pDbHandle->columnText(2), MAX_DISPLAY_NAME_LEN);
296
297                         if (pDbHandle->columnText(3) != NULL)
298                                 strncpy(lastName, (char*)pDbHandle->columnText(3), MAX_DISPLAY_NAME_LEN);
299
300                         int order = MsgGetContactNameOrder();
301
302                         if (order == 0) {
303                                 if (firstName[0] != '\0') {
304                                         strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
305                                 }
306
307                                 if (lastName[0] != '\0') {
308                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
309                                         strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
310                                 }
311                         } else if (order == 1) {
312                                 if (lastName[0] != '\0') {
313                                         strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
314                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
315                                 }
316
317                                 if (firstName[0] != '\0') {
318                                         strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
319                                 }
320                         }
321                 }
322         } else {
323                 MSG_DEBUG("query : %s", sqlQuery);
324
325                 pDbHandle->finalizeQuery();
326
327                 return MSG_ERR_DB_STEP;
328         }
329
330         pDbHandle->finalizeQuery();
331
332
333         noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
334         if (noti == NULL) {
335                 MSG_DEBUG("notification_new is failed.");
336                 return MSG_ERR_UNKNOWN;
337         }
338
339         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NOTI_MSG_ICON_PATH);
340         if (noti_err != NOTIFICATION_ERROR_NONE) {
341                 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
342         }
343
344         if (displayName[0] == '\0')
345                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
346         else
347                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
348
349
350         if (Status == MSG_DELIVERY_REPORT_SUCCESS)
351                 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Delivered.");
352         else
353                 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deliver Failed.");
354
355         notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
356
357         noti_err = notification_insert(noti, NULL);
358         if (noti_err != NOTIFICATION_ERROR_NONE) {
359                 MSG_DEBUG("Fail to notification_insert");
360         }
361
362         noti_err = notification_free(noti);
363         if (noti_err != NOTIFICATION_ERROR_NONE) {
364                 MSG_DEBUG("Fail to notification_free");
365         }
366
367         return MSG_SUCCESS;
368 }
369
370
371 MSG_ERROR_T MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S* pMsg)
372 {
373
374         notification_h noti = NULL;
375         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
376
377         MSG_DELIVERY_REPORT_STATUS_T    deliveryStatus;
378         MSG_READ_REPORT_STATUS_T                readStatus;
379
380         char addressVal[MAX_ADDRESS_VAL_LEN+1];
381         char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
382         char displayName[MAX_DISPLAY_NAME_LEN+1];
383         char contents[MAX_DISPLAY_NAME_LEN+1];
384         char sqlQuery[MAX_QUERY_LEN+1];
385
386         memset(addressVal, 0x00, sizeof(addressVal));
387         memset(firstName, 0x00, sizeof(firstName));
388         memset(lastName, 0x00, sizeof(lastName));
389         memset(displayName, 0x00, sizeof(displayName));
390         memset(contents, 0x00, sizeof(contents));
391         memset(sqlQuery, 0x00, sizeof(sqlQuery));
392
393         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.DELIVERY_REPORT_STATUS, B.READ_REPORT_STATUS \
394                                                                        FROM %s A, %s B \
395                                                                         WHERE B.MSG_ID=%d AND A.ADDRESS_ID=B.ADDRESS_ID;",
396                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
397
398         if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
399                 return MSG_ERR_DB_PREPARE;
400
401         if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
402                 if (pDbHandle->columnText(0) != NULL)
403                         strncpy(addressVal, (char*)pDbHandle->columnText(0), MAX_ADDRESS_VAL_LEN);
404
405
406                 char *pTempDisplayName = (char *)pDbHandle->columnText(1);
407                 if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
408                         strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
409                 } else {
410                         if (pDbHandle->columnText(2) != NULL)
411                                 strncpy(firstName, (char*)pDbHandle->columnText(2), MAX_DISPLAY_NAME_LEN);
412
413                         if (pDbHandle->columnText(3) != NULL)
414                                 strncpy(lastName, (char*)pDbHandle->columnText(3), MAX_DISPLAY_NAME_LEN);
415
416                         int order = MsgGetContactNameOrder();
417
418                         if (order == 0) {
419                                 if (firstName[0] != '\0') {
420                                         strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
421                                 }
422
423                                 if (lastName[0] != '\0') {
424                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
425                                         strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
426                                 }
427                         } else if (order == 1) {
428                                 if (lastName[0] != '\0') {
429                                         strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
430                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
431                                 }
432
433                                 if (firstName[0] != '\0') {
434                                         strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
435                                 }
436                         }
437                 }
438
439                 deliveryStatus = (MSG_DELIVERY_REPORT_STATUS_T)pDbHandle->columnInt(4);
440                 readStatus = (MSG_READ_REPORT_STATUS_T)pDbHandle->columnInt(5);
441
442         } else {
443                 pDbHandle->finalizeQuery();
444                 return MSG_ERR_DB_STEP;
445         }
446
447         pDbHandle->finalizeQuery();
448
449         noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
450         if (noti == NULL) {
451                 MSG_DEBUG("notification_new is failed.");
452                 return MSG_ERR_UNKNOWN;
453         }
454
455         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NOTI_MSG_ICON_PATH);
456         if (noti_err != NOTIFICATION_ERROR_NONE) {
457                 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
458         }
459
460         if (displayName[0] == '\0')
461                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
462         else
463                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
464
465         if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) {
466
467                 switch(deliveryStatus) {
468                 case MSG_DELIVERY_REPORT_NONE:
469                         noti_err = notification_free(noti);
470                         if (noti_err != NOTIFICATION_ERROR_NONE) {
471                                 MSG_DEBUG("Fail to notification_free");
472                         }
473
474                         return MSG_ERR_UNKNOWN;
475
476                 case MSG_DELIVERY_REPORT_EXPIRED:
477                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Expired.");
478                         break;
479
480                 case MSG_DELIVERY_REPORT_REJECTED:
481                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Rejected.");
482                         break;
483
484                 case MSG_DELIVERY_REPORT_DEFERRED:
485                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deferred.");
486                         break;
487
488                 case MSG_DELIVERY_REPORT_UNRECOGNISED:
489                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Unrecognised.");
490                         break;
491
492                 case MSG_DELIVERY_REPORT_INDETERMINATE:
493                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Indeterminate.");
494                         break;
495
496                 case MSG_DELIVERY_REPORT_FORWARDED:
497                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Forwarded.");
498                         break;
499
500                 case MSG_DELIVERY_REPORT_UNREACHABLE:
501                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Unreachable.");
502                         break;
503
504                 case MSG_DELIVERY_REPORT_ERROR:
505                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Error.");
506                         break;
507
508                 default :
509                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Delivered.");
510                 }
511
512                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
513                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
514
515                 noti_err = notification_insert(noti, NULL);
516                 if (noti_err != NOTIFICATION_ERROR_NONE)
517                         MSG_DEBUG("Fail to notification_insert");
518
519         } else if (pMsg->msgType.subType == MSG_READORGIND_MMS) {
520
521                 switch(readStatus) {
522                 case MSG_READ_REPORT_NONE:
523                         noti_err = notification_free(noti);
524                         if (noti_err != NOTIFICATION_ERROR_NONE)
525                                 MSG_DEBUG("Fail to notification_free");
526
527                         return MSG_ERR_UNKNOWN;
528
529                 case MSG_READ_REPORT_IS_DELETED:
530                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deleted.");
531                         break;
532
533                 default :
534                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Read.");
535                 }
536
537                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
538
539                 noti_err = notification_insert(noti, NULL);
540                 if (noti_err != NOTIFICATION_ERROR_NONE) {
541                         MSG_DEBUG("Fail to notification_insert");
542                 }
543         } else {
544                 MSG_DEBUG("No matching subtype. subtype [%d]", pMsg->msgType.subType);
545
546                 noti_err = notification_free(noti);
547                 if (noti_err != NOTIFICATION_ERROR_NONE) {
548                         MSG_DEBUG("Fail to notification_free");
549                 }
550                 return MSG_SUCCESS;
551         }
552
553         noti_err = notification_free(noti);
554         if (noti_err != NOTIFICATION_ERROR_NONE) {
555                 MSG_DEBUG("Fail to notification_free");
556         }
557
558         return MSG_SUCCESS;
559 }
560
561
562 MSG_ERROR_T MsgDeleteNotiByMsgId(MSG_MESSAGE_ID_T msgId)
563 {
564
565         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
566
567         MSG_DEBUG("notification_delete_by_priv_id msgId [%d]", msgId);
568
569         noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, msgId);
570
571         if (noti_err != NOTIFICATION_ERROR_NONE) {
572                 MSG_DEBUG("Fail to notification_delete_by_priv_id noti_err [%d]", noti_err);
573         }
574
575         return MSG_SUCCESS;
576 }
577
578
579 MSG_ERROR_T MsgDeleteNotiByThreadId(MSG_THREAD_ID_T ThreadId)
580 {
581         notification_delete_group_by_group_id(NULL, NOTIFICATION_TYPE_NOTI, ThreadId);
582
583         return MSG_SUCCESS;
584 }
585
586
587 MSG_ERROR_T MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg)
588 {
589
590         MSG_DEBUG("pTickerMsg [%s]", pTickerMsg);
591         MSG_DEBUG("pLocaleTickerMsg [%s]", pLocaleTickerMsg);
592
593         notification_h noti = NULL;
594         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
595
596         noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
597         if (noti == NULL) {
598                 MSG_DEBUG("notification_new is failed.");
599                 return MSG_ERR_UNKNOWN;
600         }
601
602         noti_err = notification_set_application(noti, "org.tizen.message");
603         if (noti_err != NOTIFICATION_ERROR_NONE) {
604                 MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
605         }
606
607         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, CB_MSG_ICON_PATH);
608         if (noti_err != NOTIFICATION_ERROR_NONE) {
609                 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
610         }
611
612         noti_err = notification_set_text_domain(noti, MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR);
613         if (noti_err != NOTIFICATION_ERROR_NONE) {
614                 MSG_DEBUG("Fail to notification_set_text_domain.");
615         }
616
617         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, pTickerMsg, pLocaleTickerMsg, NOTIFICATION_VARIABLE_TYPE_NONE);
618         if (noti_err != NOTIFICATION_ERROR_NONE) {
619                 MSG_DEBUG("Fail to notification_set_text : %d", noti_err);
620         }
621
622         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, pTickerMsg, pLocaleTickerMsg, NOTIFICATION_VARIABLE_TYPE_NONE);
623         if (noti_err != NOTIFICATION_ERROR_NONE) {
624                 MSG_DEBUG("Fail to notification_set_text : %d", noti_err);
625         }
626
627         noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER);
628         if (noti_err != NOTIFICATION_ERROR_NONE) {
629                 MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
630         }
631
632         noti_err = notification_insert(noti, NULL);
633         if (noti_err != NOTIFICATION_ERROR_NONE) {
634                 MSG_DEBUG("Fail to notification_set_text_domain");
635         }
636
637         noti_err = notification_free(noti);
638         if (noti_err != NOTIFICATION_ERROR_NONE) {
639                 MSG_DEBUG("Fail to notification_set_text_domain");
640         }
641
642         return MSG_SUCCESS;
643 }