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