Merge branch 'master' into systemd
[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         notification_h noti = NULL;
33         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
34         bundle* args;
35
36         int contactId = 0;
37         msg_thread_id_t threadId = 0;
38         time_t msgTime = 0;
39         char tempId[6];
40         char addressVal[MAX_ADDRESS_VAL_LEN+1];
41         char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
42         char displayName[MAX_DISPLAY_NAME_LEN+1];
43         char thumbPath[MAX_IMAGE_PATH_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(thumbPath, 0x00, sizeof(thumbPath));
52         memset(sqlQuery, 0x00, sizeof(sqlQuery));
53
54         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.DISPLAY_TIME, A.CONTACT_ID, A.IMAGE_PATH \
55                         FROM %s A, %s B WHERE B.MSG_ID=%d AND A.CONV_ID=B.CONV_ID;",
56                         MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
57
58         if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
59                 return MSG_ERR_DB_PREPARE;
60
61         if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
62                 threadId = pDbHandle->columnInt(0);
63
64                 if (pDbHandle->columnText(1) != NULL)
65                         strncpy(addressVal, (char*)pDbHandle->columnText(1), MAX_ADDRESS_VAL_LEN);
66
67
68                 char *pTempDisplayName = (char *)pDbHandle->columnText(2);
69                 if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
70                         strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
71                 } else {
72                         if (pDbHandle->columnText(3) != NULL)
73                                 strncpy(firstName, (char*)pDbHandle->columnText(3), MAX_DISPLAY_NAME_LEN);
74
75                         if (pDbHandle->columnText(4) != NULL)
76                                 strncpy(lastName, (char*)pDbHandle->columnText(4), MAX_DISPLAY_NAME_LEN);
77
78                         int order = MsgGetContactNameOrder();
79
80                         if (order == 0) {
81                                 if (firstName[0] != '\0') {
82                                         strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
83                                 }
84
85                                 if (lastName[0] != '\0') {
86                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
87                                         strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
88                                 }
89                         } else if (order == 1) {
90                                 if (lastName[0] != '\0') {
91                                         strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
92                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
93                                 }
94
95                                 if (firstName[0] != '\0') {
96                                         strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
97                                 }
98                         }
99                 }
100
101                 msgTime = (time_t)pDbHandle->columnInt(5);
102
103                 contactId = pDbHandle->columnInt(6);
104
105                 strncpy(thumbPath, (char*)pDbHandle->columnText(7), MAX_IMAGE_PATH_LEN);
106         } else {
107                 pDbHandle->finalizeQuery();
108                 return MSG_ERR_DB_STEP;
109         }
110
111         pDbHandle->finalizeQuery();
112
113
114         args = bundle_create();
115
116         if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->msgType.subType == MSG_CB_SMS) {
117
118                 noti = notification_new(NOTIFICATION_TYPE_NOTI, 1, pMsg->msgId);
119                 if (noti == NULL) {
120                         MSG_DEBUG("notification_new is failed.");
121                         bundle_free(args);
122                         return MSG_ERR_UNKNOWN;
123                 }
124
125                 noti_err = notification_set_application(noti, "org.tizen.message");
126                 if (noti_err != NOTIFICATION_ERROR_NONE) {
127                         MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
128                 }
129
130                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, CB_MSG_ICON_PATH);
131                 if (noti_err != NOTIFICATION_ERROR_NONE) {
132                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
133                 }
134
135                 memset(&tempId, 0x00, sizeof(tempId));
136
137                 bundle_add(args, "type", "msg_id");
138
139                 snprintf(tempId, 5, "%d", pMsg->msgId);
140                 bundle_add(args, "msgId", tempId);
141         } else if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->msgType.classType == MSG_CLASS_0) {
142
143                 noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
144                 if (noti == NULL) {
145                         MSG_DEBUG("notification_new is failed.");
146                         bundle_free(args);
147                         return MSG_ERR_UNKNOWN;
148                 }
149
150                 noti_err = notification_set_application(noti, "org.tizen.msg-ui-class0");
151                 if (noti_err != NOTIFICATION_ERROR_NONE) {
152                         MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
153                 }
154
155                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
156                 if (noti_err != NOTIFICATION_ERROR_NONE) {
157                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
158                 }
159
160                 bundle_add(args, "type", "msg_id");
161
162                 snprintf(tempId, 5, "%d", pMsg->msgId);
163                 bundle_add(args, "msgId", tempId);
164         } else if (pMsg->msgType.mainType == MSG_SMS_TYPE &&
165                         (pMsg->msgType.subType >= MSG_MWI_VOICE_SMS && pMsg->msgType.subType <= MSG_MWI_OTHER_SMS)) {
166
167                 noti = notification_new(NOTIFICATION_TYPE_NOTI, 1, NOTIFICATION_PRIV_ID_NONE);
168                 if (noti == NULL) {
169                         MSG_DEBUG("notification_new is failed.");
170                         bundle_free(args);
171                         return MSG_ERR_UNKNOWN;
172                 }
173
174                 noti_err = notification_set_application(noti, "org.tizen.message");
175                 if (noti_err != NOTIFICATION_ERROR_NONE) {
176                         MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
177                 }
178
179                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, VOICE_MSG_ICON_PATH);
180                 if (noti_err != NOTIFICATION_ERROR_NONE) {
181                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
182                 }
183
184                 memset(&tempId, 0x00, sizeof(tempId));
185
186                 bundle_add(args, "launch-type", "MO");
187                 bundle_add(args, "number", addressVal);
188
189         } else {
190                 MSG_DEBUG("notification_new pMsg->msgId [%d]", pMsg->msgId);
191                 noti = notification_new(NOTIFICATION_TYPE_NOTI, 1, pMsg->msgId);
192                 if (noti == NULL) {
193                         MSG_DEBUG("notification_new is failed.");
194                         bundle_free(args);
195                         return MSG_ERR_UNKNOWN;
196                 }
197
198                 noti_err = notification_set_application(noti, "org.tizen.message");
199                 if (noti_err != NOTIFICATION_ERROR_NONE) {
200                         MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
201                 }
202
203                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
204                 if (noti_err != NOTIFICATION_ERROR_NONE) {
205                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
206                 }
207
208                 memset(&tempId, 0x00, sizeof(tempId));
209
210                 bundle_add(args, "type", "msg_id");
211
212                 snprintf(tempId, 5, "%d", pMsg->msgId);
213                 bundle_add(args, "msgId", tempId);
214         }
215
216         if (displayName[0] == '\0')
217                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
218         else
219                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
220
221         if (pMsg->msgType.mainType == MSG_SMS_TYPE)
222                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
223         else
224                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg->subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
225
226
227         if (args != NULL) {
228                 noti_err = notification_set_args(noti, args, NULL);
229                 if (noti_err != NOTIFICATION_ERROR_NONE) {
230                         MSG_DEBUG("Fail to notification_set_args : %d", noti_err);
231                 }
232         }
233
234         noti_err = notification_set_time(noti, msgTime);
235         if (noti_err != NOTIFICATION_ERROR_NONE) {
236                 MSG_DEBUG("Fail to notification_set_time : %d", noti_err);
237         }
238
239         if (thumbPath[0] != '\0') {
240                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, thumbPath);
241                 if (noti_err != NOTIFICATION_ERROR_NONE) {
242                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
243                 }
244
245                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_THUMBNAIL_FOR_LOCK, thumbPath);
246                 if (noti_err != NOTIFICATION_ERROR_NONE) {
247                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
248                 }
249         }
250
251         noti_err = notification_insert(noti, NULL);
252         if (noti_err != NOTIFICATION_ERROR_NONE) {
253                 MSG_DEBUG("Fail to notification_insert");
254         }
255
256         noti_err = notification_free(noti);
257         if (noti_err != NOTIFICATION_ERROR_NONE) {
258                 MSG_DEBUG("Fail to notification_free");
259         }
260
261         bundle_free(args);
262
263         return MSG_SUCCESS;
264 }
265
266 msg_error_t MsgInsertNoti(MSG_MESSAGE_INFO_S* pMsg)
267 {
268         notification_h noti = NULL;
269         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
270         bundle* args;
271
272         char addressVal[MAX_ADDRESS_VAL_LEN+1];
273         char displayName[MAX_DISPLAY_NAME_LEN+1];
274
275         memset(addressVal, 0x00, sizeof(addressVal));
276         memset(displayName, 0x00, sizeof(displayName));
277
278         snprintf(addressVal, sizeof(addressVal), "%s", pMsg->addressList[0].addressVal);
279         snprintf(displayName, sizeof(displayName), "%s", pMsg->addressList[0].displayName);
280
281         if (pMsg->msgType.mainType == MSG_SMS_TYPE &&
282                         (pMsg->msgType.subType >= MSG_MWI_VOICE_SMS && pMsg->msgType.subType <= MSG_MWI_OTHER_SMS)) {
283
284                 args = bundle_create();
285
286                 noti = notification_new(NOTIFICATION_TYPE_NOTI, 1, NOTIFICATION_PRIV_ID_NONE);
287                 if (noti == NULL) {
288                         MSG_DEBUG("notification_new is failed.");
289                         bundle_free(args);
290                         return MSG_ERR_UNKNOWN;
291                 }
292
293                 noti_err = notification_set_application(noti, "com.samsung.call");
294                 if (noti_err != NOTIFICATION_ERROR_NONE) {
295                         MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
296                 }
297
298                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, VOICE_MSG_ICON_PATH);
299                 if (noti_err != NOTIFICATION_ERROR_NONE) {
300                         MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
301                 }
302
303                 //FIXME :: Temp code for voice number, 2012.08.16 sangkoo.kim
304                 bundle_add(args, "launch-type", "MO");
305                 bundle_add(args, "number", pMsg->addressList[0].addressVal);
306
307         } else {
308                 return MSG_ERR_INVALID_PARAMETER;
309         }
310
311         if (displayName[0] == '\0')
312                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
313         else
314                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
315
316         notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
317
318         if (args != NULL) {
319                 noti_err = notification_set_args(noti, args, NULL);
320                 if (noti_err != NOTIFICATION_ERROR_NONE) {
321                         MSG_DEBUG("Fail to notification_set_args : %d", noti_err);
322                 }
323         }
324
325         noti_err = notification_set_time(noti, pMsg->displayTime);
326         if (noti_err != NOTIFICATION_ERROR_NONE) {
327                 MSG_DEBUG("Fail to notification_set_time : %d", noti_err);
328         }
329
330         noti_err = notification_insert(noti, NULL);
331         if (noti_err != NOTIFICATION_ERROR_NONE) {
332                 MSG_DEBUG("Fail to notification_insert");
333         }
334
335         noti_err = notification_free(noti);
336         if (noti_err != NOTIFICATION_ERROR_NONE) {
337                 MSG_DEBUG("Fail to notification_free");
338         }
339
340         bundle_free(args);
341
342         return MSG_SUCCESS;
343 }
344
345 msg_error_t MsgInsertSmsReportToNoti(MsgDbHandler *pDbHandle, msg_message_id_t msgId, msg_delivery_report_status_t status)
346 {
347         notification_h noti = NULL;
348         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
349
350         char addressVal[MAX_ADDRESS_VAL_LEN+1];
351         char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
352         char displayName[MAX_DISPLAY_NAME_LEN+1];
353         char contents[MAX_DISPLAY_NAME_LEN+1];
354         char sqlQuery[MAX_QUERY_LEN+1];
355
356         memset(addressVal, 0x00, sizeof(addressVal));
357         memset(firstName, 0x00, sizeof(firstName));
358         memset(lastName, 0x00, sizeof(lastName));
359         memset(displayName, 0x00, sizeof(displayName));
360         memset(contents, 0x00, sizeof(contents));
361         memset(sqlQuery, 0x00, sizeof(sqlQuery));
362
363         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME \
364                         FROM %s A, %s B WHERE B.MSG_ID = %d AND A.CONV_ID = B.CONV_ID;",
365                         MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, msgId);
366
367         if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
368                 return MSG_ERR_DB_PREPARE;
369
370         if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
371                 if (pDbHandle->columnText(0) != NULL)
372                         strncpy(addressVal, (char*)pDbHandle->columnText(0), MAX_ADDRESS_VAL_LEN);
373
374                 if (pDbHandle->columnText(1) != NULL) {
375                         strncpy(displayName, (char*)pDbHandle->columnText(1), MAX_DISPLAY_NAME_LEN);
376                 } else {
377                         if (pDbHandle->columnText(2) != NULL)
378                                 strncpy(firstName, (char*)pDbHandle->columnText(2), MAX_DISPLAY_NAME_LEN);
379
380                         if (pDbHandle->columnText(3) != NULL)
381                                 strncpy(lastName, (char*)pDbHandle->columnText(3), MAX_DISPLAY_NAME_LEN);
382
383                         int order = MsgGetContactNameOrder();
384
385                         if (order == 0) {
386                                 if (firstName[0] != '\0') {
387                                         strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
388                                 }
389
390                                 if (lastName[0] != '\0') {
391                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
392                                         strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
393                                 }
394                         } else if (order == 1) {
395                                 if (lastName[0] != '\0') {
396                                         strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
397                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
398                                 }
399
400                                 if (firstName[0] != '\0') {
401                                         strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
402                                 }
403                         }
404                 }
405         } else {
406                 MSG_DEBUG("query : %s", sqlQuery);
407
408                 pDbHandle->finalizeQuery();
409
410                 return MSG_ERR_DB_STEP;
411         }
412
413         pDbHandle->finalizeQuery();
414
415
416         noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
417         if (noti == NULL) {
418                 MSG_DEBUG("notification_new is failed.");
419                 return MSG_ERR_UNKNOWN;
420         }
421
422         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NOTI_MSG_ICON_PATH);
423         if (noti_err != NOTIFICATION_ERROR_NONE) {
424                 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
425         }
426
427         if (displayName[0] == '\0')
428                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
429         else
430                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
431
432
433         if (status == MSG_DELIVERY_REPORT_SUCCESS)
434                 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Delivered.");
435         else
436                 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deliver Failed.");
437
438         notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
439
440         noti_err = notification_insert(noti, NULL);
441         if (noti_err != NOTIFICATION_ERROR_NONE) {
442                 MSG_DEBUG("Fail to notification_insert");
443         }
444
445         noti_err = notification_free(noti);
446         if (noti_err != NOTIFICATION_ERROR_NONE) {
447                 MSG_DEBUG("Fail to notification_free");
448         }
449
450         return MSG_SUCCESS;
451 }
452
453
454 msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S* pMsg)
455 {
456         notification_h noti = NULL;
457         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
458
459         char addressVal[MAX_ADDRESS_VAL_LEN+1];
460         char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
461         char displayName[MAX_DISPLAY_NAME_LEN+1];
462         char contents[MAX_DISPLAY_NAME_LEN+1];
463         char sqlQuery[MAX_QUERY_LEN+1];
464
465         memset(addressVal, 0x00, sizeof(addressVal));
466         memset(firstName, 0x00, sizeof(firstName));
467         memset(lastName, 0x00, sizeof(lastName));
468         memset(displayName, 0x00, sizeof(displayName));
469         memset(contents, 0x00, sizeof(contents));
470         memset(sqlQuery, 0x00, sizeof(sqlQuery));
471
472         int report_status_type;
473         int report_status_value;
474
475         if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) {
476                 report_status_type = MSG_REPORT_TYPE_DELIVERY;
477                 MSG_DEBUG("mms subtype is Delivery Report type");
478         } else if (pMsg->msgType.subType == MSG_READORGIND_MMS) {
479                 report_status_type = MSG_REPORT_TYPE_READ;
480                 MSG_DEBUG("mms subtype is Read Report type");
481         } else {
482                 MSG_DEBUG("No matching subtype. subtype [%d]", pMsg->msgType.subType);
483                 return MSG_SUCCESS;
484         }
485
486         MSG_ADDRESS_INFO_S *address_info_s = &pMsg->addressList[0];
487         MSG_DEBUG("address info : %s, type : %d", address_info_s->addressVal, address_info_s->addressType);
488
489         if (address_info_s->addressType == MSG_ADDRESS_TYPE_PLMN) {//FIXME: compare 10 char of address
490                 snprintf(sqlQuery, sizeof(sqlQuery),
491                         "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
492                         "FROM %s A, %s B "
493                         "WHERE B.MSG_ID=%d AND B.STATUS_TYPE=%d AND A.ADDRESS_VAL LIKE \'%s\';"
494                         , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type, address_info_s->addressVal);
495         } else if (address_info_s->addressType == MSG_ADDRESS_TYPE_EMAIL) {//check full
496                 snprintf(sqlQuery, sizeof(sqlQuery),
497                         "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
498                         "FROM %s A, %s B "
499                         "WHERE B.MSG_ID=%d AND B.STATUS_TYPE=%d AND A.ADDRESS_VAL=\'%s\';"
500                         , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type, address_info_s->addressVal);
501         } else {
502                 snprintf(sqlQuery, sizeof(sqlQuery),
503                         "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
504                         "FROM %s A, %s B "
505                         "WHERE B.MSG_ID=%d B.STATUS_TYPE=%d;"
506                         , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type);
507         }
508
509         MSG_DEBUG("sqlQuery = [%s]", sqlQuery);
510
511         if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
512                 return MSG_ERR_DB_PREPARE;
513
514         if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
515                 if (pDbHandle->columnText(0) != NULL) {
516                         strncpy(addressVal, (char*)pDbHandle->columnText(0), MAX_ADDRESS_VAL_LEN);
517                         MSG_DEBUG("addressVal is [%s]",addressVal);
518                 } else {
519                         MSG_DEBUG("address Val is Null");
520                 }
521
522                 char *pTempDisplayName = (char *)pDbHandle->columnText(1);
523                 if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
524                         strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
525                 } else {
526                         if (pDbHandle->columnText(2) != NULL)
527                                 strncpy(firstName, (char*)pDbHandle->columnText(2), MAX_DISPLAY_NAME_LEN);
528
529                         if (pDbHandle->columnText(3) != NULL)
530                                 strncpy(lastName, (char*)pDbHandle->columnText(3), MAX_DISPLAY_NAME_LEN);
531
532                         int order = MsgGetContactNameOrder();
533
534                         if (order == 0) {
535                                 if (firstName[0] != '\0') {
536                                         strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
537                                 }
538
539                                 if (lastName[0] != '\0') {
540                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
541                                         strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
542                                 }
543                         } else if (order == 1) {
544                                 if (lastName[0] != '\0') {
545                                         strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
546                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
547                                 }
548
549                                 if (firstName[0] != '\0') {
550                                         strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
551                                 }
552                         }
553                 }
554
555                 report_status_value = pDbHandle->columnInt(4);
556
557         } else {
558                 MSG_DEBUG("DB Query Result Fail");
559                 pDbHandle->finalizeQuery();
560                 return MSG_ERR_DB_STEP;
561         }
562
563         pDbHandle->finalizeQuery();
564
565         noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
566         if (noti == NULL) {
567                 MSG_DEBUG("notification_new is failed.");
568                 return MSG_ERR_UNKNOWN;
569         }
570
571         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NOTI_MSG_ICON_PATH);
572         if (noti_err != NOTIFICATION_ERROR_NONE) {
573                 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
574         }
575
576         if (displayName[0] == '\0')
577                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
578         else
579                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
580
581         if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) {
582
583                 switch(report_status_value) {
584                 case MSG_DELIVERY_REPORT_NONE:
585                         noti_err = notification_free(noti);
586                         if (noti_err != NOTIFICATION_ERROR_NONE) {
587                                 MSG_DEBUG("Fail to notification_free");
588                         }
589
590                         return MSG_ERR_UNKNOWN;
591
592                 case MSG_DELIVERY_REPORT_EXPIRED:
593                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Expired.");
594                         break;
595
596                 case MSG_DELIVERY_REPORT_REJECTED:
597                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Rejected.");
598                         break;
599
600                 case MSG_DELIVERY_REPORT_DEFERRED:
601                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deferred.");
602                         break;
603
604                 case MSG_DELIVERY_REPORT_UNRECOGNISED:
605                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Unrecognised.");
606                         break;
607
608                 case MSG_DELIVERY_REPORT_INDETERMINATE:
609                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Indeterminate.");
610                         break;
611
612                 case MSG_DELIVERY_REPORT_FORWARDED:
613                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Forwarded.");
614                         break;
615
616                 case MSG_DELIVERY_REPORT_UNREACHABLE:
617                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Unreachable.");
618                         break;
619
620                 case MSG_DELIVERY_REPORT_ERROR:
621                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Error.");
622                         break;
623
624                 default :
625                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Delivered.");
626                 }
627
628                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
629                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
630
631                 noti_err = notification_insert(noti, NULL);
632                 if (noti_err != NOTIFICATION_ERROR_NONE)
633                         MSG_DEBUG("Fail to notification_insert");
634
635         } else if (pMsg->msgType.subType == MSG_READORGIND_MMS) {
636
637                 switch(report_status_value) {
638                 case MSG_READ_REPORT_NONE:
639                         noti_err = notification_free(noti);
640                         if (noti_err != NOTIFICATION_ERROR_NONE)
641                                 MSG_DEBUG("Fail to notification_free");
642
643                         return MSG_ERR_UNKNOWN;
644
645                 case MSG_READ_REPORT_IS_DELETED:
646                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deleted.");
647                         break;
648
649                 default :
650                         snprintf(contents, MAX_DISPLAY_NAME_LEN, "Read.");
651                 }
652
653                 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
654
655                 noti_err = notification_insert(noti, NULL);
656                 if (noti_err != NOTIFICATION_ERROR_NONE) {
657                         MSG_DEBUG("Fail to notification_insert");
658                 }
659         } else {
660                 MSG_DEBUG("No matching subtype. subtype [%d]", pMsg->msgType.subType);
661
662                 noti_err = notification_free(noti);
663                 if (noti_err != NOTIFICATION_ERROR_NONE) {
664                         MSG_DEBUG("Fail to notification_free");
665                 }
666                 return MSG_SUCCESS;
667         }
668
669         noti_err = notification_free(noti);
670         if (noti_err != NOTIFICATION_ERROR_NONE) {
671                 MSG_DEBUG("Fail to notification_free");
672         }
673
674         return MSG_SUCCESS;
675 }
676
677
678 msg_error_t MsgDeleteNotiByMsgId(msg_message_id_t msgId)
679 {
680
681         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
682
683         MSG_DEBUG("notification_delete_by_priv_id msgId [%d]", msgId);
684
685         noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, msgId);
686
687         if (noti_err != NOTIFICATION_ERROR_NONE) {
688                 MSG_DEBUG("Fail to notification_delete_by_priv_id noti_err [%d]", noti_err);
689         }
690
691         return MSG_SUCCESS;
692 }
693
694
695 msg_error_t MsgDeleteNotiByThreadId(msg_thread_id_t ThreadId)
696 {
697         notification_delete_group_by_group_id(NULL, NOTIFICATION_TYPE_NOTI, ThreadId);
698
699         return MSG_SUCCESS;
700 }
701
702
703 msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg)
704 {
705
706         MSG_DEBUG("pTickerMsg [%s]", pTickerMsg);
707         MSG_DEBUG("pLocaleTickerMsg [%s]", pLocaleTickerMsg);
708
709         notification_h noti = NULL;
710         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
711
712         noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
713         if (noti == NULL) {
714                 MSG_DEBUG("notification_new is failed.");
715                 return MSG_ERR_UNKNOWN;
716         }
717
718         noti_err = notification_set_application(noti, "org.tizen.message");
719         if (noti_err != NOTIFICATION_ERROR_NONE) {
720                 MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
721         }
722
723         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
724         if (noti_err != NOTIFICATION_ERROR_NONE) {
725                 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
726         }
727
728         noti_err = notification_set_text_domain(noti, MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR);
729         if (noti_err != NOTIFICATION_ERROR_NONE) {
730                 MSG_DEBUG("Fail to notification_set_text_domain.");
731         }
732
733         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, pTickerMsg, pLocaleTickerMsg, NOTIFICATION_VARIABLE_TYPE_NONE);
734         if (noti_err != NOTIFICATION_ERROR_NONE) {
735                 MSG_DEBUG("Fail to notification_set_text : %d", noti_err);
736         }
737
738         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, pTickerMsg, pLocaleTickerMsg, NOTIFICATION_VARIABLE_TYPE_NONE);
739         if (noti_err != NOTIFICATION_ERROR_NONE) {
740                 MSG_DEBUG("Fail to notification_set_text : %d", noti_err);
741         }
742
743         noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER);
744         if (noti_err != NOTIFICATION_ERROR_NONE) {
745                 MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
746         }
747
748         noti_err = notification_insert(noti, NULL);
749         if (noti_err != NOTIFICATION_ERROR_NONE) {
750                 MSG_DEBUG("Fail to notification_set_text_domain");
751         }
752
753         noti_err = notification_free(noti);
754         if (noti_err != NOTIFICATION_ERROR_NONE) {
755                 MSG_DEBUG("Fail to notification_set_text_domain");
756         }
757
758         return MSG_SUCCESS;
759 }