2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
18 #include "MsgContact.h"
19 #include "MsgStorageTypes.h"
20 #include "MsgUtilStorage.h"
21 #include "MsgGconfWrapper.h"
22 #include "MsgNotificationWrapper.h"
26 #include <notification.h>
29 /*==================================================================================================
30 FUNCTION IMPLEMENTATION
31 ==================================================================================================*/
32 void MsgSmsClass0Noti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
35 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
38 memset(tempId, 0x00, sizeof(tempId));
40 noti_err = notification_set_application(noti, "org.tizen.msg-ui-class0");
41 if (noti_err != NOTIFICATION_ERROR_NONE) {
42 MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
45 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
46 if (noti_err != NOTIFICATION_ERROR_NONE) {
47 MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
50 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
51 if (noti_err != NOTIFICATION_ERROR_NONE) {
52 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
55 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "CLASS 0 Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
57 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New CLASS 0 Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
59 if (pMsg->addressList[0].displayName[0] == '\0')
60 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
62 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
64 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
67 notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
69 bundle_add(args, "type", "msg_id");
71 snprintf(tempId, 5, "%d", pMsg->msgId);
72 bundle_add(args, "msgId", tempId);
77 void MsgSmsCBNoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
81 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
84 memset(tempId, 0x00, sizeof(tempId));
86 noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
87 if (noti_err != NOTIFICATION_ERROR_NONE) {
88 MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
91 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
92 if (noti_err != NOTIFICATION_ERROR_NONE) {
93 MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
96 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, CB_MSG_ICON_PATH);
97 if (noti_err != NOTIFICATION_ERROR_NONE) {
98 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
101 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "CB Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
103 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New CB Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
105 if (pMsg->addressList[0].displayName[0] == '\0')
106 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
108 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
110 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
113 notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
115 memset(&tempId, 0x00, sizeof(tempId));
117 bundle_add(args, "type", "msg_id");
119 snprintf(tempId, 5, "%d", pMsg->msgId);
120 bundle_add(args, "msgId", tempId);
125 void MsgSmsVoiceNoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
129 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
131 noti_err = notification_set_application(noti, "org.tizen.call");
132 if (noti_err != NOTIFICATION_ERROR_NONE) {
133 MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
136 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
137 if (noti_err != NOTIFICATION_ERROR_NONE) {
138 MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
141 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Voice Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
143 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Voice Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
145 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, VOICE_MSG_ICON_PATH);
146 if (noti_err != NOTIFICATION_ERROR_NONE) {
147 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
150 if (pMsg->addressList[0].displayName[0] == '\0')
151 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
153 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
155 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
158 notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
160 //FIXME :: Temp code for voice number, 2012.08.16 sangkoo.kim
161 bundle_add(args, "launch-type", "MO");
162 bundle_add(args, "number", pMsg->addressList[0].addressVal);
168 void MsgSmsReportNoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
172 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
175 memset(tempId, 0x00, sizeof(tempId));
177 noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
178 if (noti_err != NOTIFICATION_ERROR_NONE) {
179 MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
181 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
182 if (noti_err != NOTIFICATION_ERROR_NONE) {
183 MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
186 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
188 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Delivery Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
190 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NOTI_MSG_ICON_PATH);
191 if (noti_err != NOTIFICATION_ERROR_NONE) {
192 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
195 if (pMsg->addressList[0].displayName[0] == '\0')
196 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
198 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
200 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
203 notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
206 MsgDbHandler dbhandler;
207 char sqlQuery[MAX_QUERY_LEN+1];
208 memset(sqlQuery, 0x00, sizeof(sqlQuery));
209 snprintf(sqlQuery, sizeof(sqlQuery),
212 "WHERE CONV_ID IN (SELECT CONV_ID FROM %s WHERE ADDRESS_VAL LIKE '%%%s') AND FOLDER_ID=%d "
213 "ORDER BY DISPLAY_TIME DESC;"
214 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pMsg->addressList[0].addressVal, MSG_SENTBOX_ID);
216 MSG_DEBUG("sqlQuery - %s", sqlQuery);
218 if (dbhandler.prepareQuery(sqlQuery) == MSG_SUCCESS) {
220 if (dbhandler.stepQuery() == MSG_ERR_DB_ROW) {
221 memset(&tempId, 0x00, sizeof(tempId));
223 bundle_add(args, "type", "report");
225 snprintf(tempId, 5, "%d", dbhandler.columnInt(0));
226 bundle_add(args, "msgId", tempId);
228 MSG_DEBUG("msgId [%s] add.", tempId);
231 dbhandler.finalizeQuery();
238 msg_error_t MsgInsertNoti(MSG_MESSAGE_INFO_S* pMsg)
240 MSG_DEBUG("Start to Insert Notification.");
241 notification_h noti = NULL;
242 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
245 noti = notification_create(NOTIFICATION_TYPE_NOTI);
247 MSG_DEBUG("notification_create is failed.");
248 return MSG_ERR_UNKNOWN;
251 if (pMsg->msgType.mainType == MSG_SMS_TYPE) {
252 switch(pMsg->msgType.subType)
255 args = bundle_create();
256 MsgSmsCBNoti(pMsg, noti, args);
258 case MSG_MWI_VOICE_SMS :
259 case MSG_MWI_FAX_SMS :
260 case MSG_MWI_EMAIL_SMS :
261 case MSG_MWI_OTHER_SMS :
262 args = bundle_create();
263 MsgSmsVoiceNoti(pMsg, noti, args);
265 case MSG_STATUS_REPORT_SMS :
266 args = bundle_create();
267 MsgSmsReportNoti(pMsg, noti, args);
270 MsgRefreshNoti(true);
271 noti_err = notification_free(noti);
272 if (noti_err != NOTIFICATION_ERROR_NONE) {
273 MSG_DEBUG("Fail to notification_free");
278 } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
279 switch(pMsg->msgType.subType)
282 MsgRefreshNoti(true);
283 noti_err = notification_free(noti);
284 if (noti_err != NOTIFICATION_ERROR_NONE) {
285 MSG_DEBUG("Fail to notification_free");
291 MSG_DEBUG("Message type does not match.");
293 noti_err = notification_free(noti);
294 if (noti_err != NOTIFICATION_ERROR_NONE) {
295 MSG_DEBUG("Fail to notification_free");
298 return MSG_ERR_INVALID_PARAMETER;
302 noti_err = notification_set_args(noti, args, NULL);
303 if (noti_err != NOTIFICATION_ERROR_NONE) {
304 MSG_DEBUG("Fail to notification_set_args : %d", noti_err);
308 noti_err = notification_insert(noti, NULL);
309 if (noti_err != NOTIFICATION_ERROR_NONE) {
310 MSG_DEBUG("Fail to notification_insert");
313 noti_err = notification_free(noti);
314 if (noti_err != NOTIFICATION_ERROR_NONE) {
315 MSG_DEBUG("Fail to notification_free");
328 msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S* pMsg)
331 notification_h noti = NULL;
332 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
334 char addressVal[MAX_ADDRESS_VAL_LEN+1];
335 char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
336 char displayName[MAX_DISPLAY_NAME_LEN+1];
337 char contents[MAX_DISPLAY_NAME_LEN+1];
338 char sqlQuery[MAX_QUERY_LEN+1];
340 memset(addressVal, 0x00, sizeof(addressVal));
341 memset(firstName, 0x00, sizeof(firstName));
342 memset(lastName, 0x00, sizeof(lastName));
343 memset(displayName, 0x00, sizeof(displayName));
344 memset(contents, 0x00, sizeof(contents));
345 memset(sqlQuery, 0x00, sizeof(sqlQuery));
347 int report_status_type;
348 int report_status_value;
350 if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) {
351 report_status_type = MSG_REPORT_TYPE_DELIVERY;
352 MSG_DEBUG("mms subtype is Delivery Report type");
353 } else if (pMsg->msgType.subType == MSG_READORGIND_MMS) {
354 report_status_type = MSG_REPORT_TYPE_READ;
355 MSG_DEBUG("mms subtype is Read Report type");
357 MSG_DEBUG("No matching subtype. subtype [%d]", pMsg->msgType.subType);
361 MSG_ADDRESS_INFO_S *address_info_s = &pMsg->addressList[0];
362 MSG_DEBUG("address info : %s, type : %d", address_info_s->addressVal, address_info_s->addressType);
364 if (address_info_s->addressType == MSG_ADDRESS_TYPE_PLMN) {
366 if (strlen(address_info_s->addressVal) > MAX_PRECONFIG_NUM) {
367 char newPhoneNum[MAX_PRECONFIG_NUM+1];
369 memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
371 MsgConvertNumber(address_info_s->addressVal, newPhoneNum);
373 snprintf(sqlQuery, sizeof(sqlQuery),
374 "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
376 "WHERE B.MSG_ID=%d AND B.STATUS_TYPE=%d AND A.ADDRESS_VAL LIKE '%%%s' AND B.ADDRESS_VAL LIKE \'%%%s\';"
377 , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type, newPhoneNum, newPhoneNum);
380 snprintf(sqlQuery, sizeof(sqlQuery),
381 "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
383 "WHERE B.MSG_ID=%d AND B.STATUS_TYPE=%d AND A.ADDRESS_VAL LIKE '%s' AND B.ADDRESS_VAL LIKE '%s';"
384 , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type, address_info_s->addressVal, address_info_s->addressVal);
387 } else if (address_info_s->addressType == MSG_ADDRESS_TYPE_EMAIL) {//check full
388 snprintf(sqlQuery, sizeof(sqlQuery),
389 "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
391 "WHERE B.MSG_ID=%d AND B.STATUS_TYPE=%d AND A.ADDRESS_VAL=\'%s\' AND B.ADDRESS_VAL LIKE \'%s\';"
392 , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type, address_info_s->addressVal, address_info_s->addressVal);
394 snprintf(sqlQuery, sizeof(sqlQuery),
395 "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
397 "WHERE B.MSG_ID=%d B.STATUS_TYPE=%d;"
398 , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type);
401 MSG_DEBUG("sqlQuery = [%s]", sqlQuery);
403 if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
404 return MSG_ERR_DB_PREPARE;
406 if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
407 if (pDbHandle->columnText(0) != NULL) {
408 strncpy(addressVal, (char*)pDbHandle->columnText(0), MAX_ADDRESS_VAL_LEN);
409 MSG_DEBUG("addressVal is [%s]",addressVal);
411 MSG_DEBUG("address Val is Null");
414 char *pTempDisplayName = (char *)pDbHandle->columnText(1);
415 if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
416 strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
418 if (pDbHandle->columnText(2) != NULL)
419 strncpy(firstName, (char*)pDbHandle->columnText(2), MAX_DISPLAY_NAME_LEN);
421 if (pDbHandle->columnText(3) != NULL)
422 strncpy(lastName, (char*)pDbHandle->columnText(3), MAX_DISPLAY_NAME_LEN);
424 int order = MsgGetContactNameOrder();
427 if (firstName[0] != '\0') {
428 strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
431 if (lastName[0] != '\0') {
432 strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
433 strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
435 } else if (order == 1) {
436 if (lastName[0] != '\0') {
437 strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
438 strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
441 if (firstName[0] != '\0') {
442 strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
447 report_status_value = pDbHandle->columnInt(4);
448 MSG_DEBUG("report status [type = %d, value = %d]", report_status_type, report_status_value);
450 MSG_DEBUG("DB Query Result Fail");
451 pDbHandle->finalizeQuery();
452 return MSG_ERR_DB_STEP;
455 pDbHandle->finalizeQuery();
457 noti = notification_create(NOTIFICATION_TYPE_NOTI);
459 MSG_DEBUG("notification_create is failed.");
460 return MSG_ERR_UNKNOWN;
463 noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
464 if (noti_err != NOTIFICATION_ERROR_NONE) {
465 MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
467 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
468 if (noti_err != NOTIFICATION_ERROR_NONE) {
469 MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
472 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NOTI_MSG_ICON_PATH);
473 if (noti_err != NOTIFICATION_ERROR_NONE) {
474 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
477 if (displayName[0] == '\0')
478 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
480 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
483 // notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
486 if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) {
488 switch(report_status_value) {
489 case MSG_DELIVERY_REPORT_NONE:
490 noti_err = notification_free(noti);
491 if (noti_err != NOTIFICATION_ERROR_NONE) {
492 MSG_DEBUG("Fail to notification_free");
495 return MSG_ERR_UNKNOWN;
497 case MSG_DELIVERY_REPORT_EXPIRED:
498 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Expired.");
501 case MSG_DELIVERY_REPORT_REJECTED:
502 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Rejected.");
505 case MSG_DELIVERY_REPORT_DEFERRED:
506 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deferred.");
509 case MSG_DELIVERY_REPORT_UNRECOGNISED:
510 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Unrecognised.");
513 case MSG_DELIVERY_REPORT_INDETERMINATE:
514 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Indeterminate.");
517 case MSG_DELIVERY_REPORT_FORWARDED:
518 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Forwarded.");
521 case MSG_DELIVERY_REPORT_UNREACHABLE:
522 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Unreachable.");
525 case MSG_DELIVERY_REPORT_ERROR:
526 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Error.");
530 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Delivered.");
534 MSG_DEBUG("content text : %s", contents);
536 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
537 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
539 noti_err = notification_insert(noti, NULL);
540 if (noti_err != NOTIFICATION_ERROR_NONE)
541 MSG_DEBUG("Fail to notification_insert");
543 } else if (pMsg->msgType.subType == MSG_READORGIND_MMS) {
545 switch(report_status_value) {
546 case MSG_READ_REPORT_NONE:
547 noti_err = notification_free(noti);
548 if (noti_err != NOTIFICATION_ERROR_NONE)
549 MSG_DEBUG("Fail to notification_free");
551 return MSG_ERR_UNKNOWN;
553 case MSG_READ_REPORT_IS_DELETED:
554 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deleted.");
558 snprintf(contents, MAX_DISPLAY_NAME_LEN, "Read.");
562 MSG_DEBUG("content text : %s", contents);
564 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
566 noti_err = notification_insert(noti, NULL);
567 if (noti_err != NOTIFICATION_ERROR_NONE) {
568 MSG_DEBUG("Fail to notification_insert");
571 MSG_DEBUG("No matching subtype. subtype [%d]", pMsg->msgType.subType);
573 noti_err = notification_free(noti);
574 if (noti_err != NOTIFICATION_ERROR_NONE) {
575 MSG_DEBUG("Fail to notification_free");
580 noti_err = notification_free(noti);
581 if (noti_err != NOTIFICATION_ERROR_NONE) {
582 MSG_DEBUG("Fail to notification_free");
589 msg_error_t MsgRefreshNoti(bool bWithTicker)
592 MsgDbHandler dbhandler;
593 MSG_MESSAGE_INFO_S msg = {0,};
595 int notiPrivId = MsgSettingGetInt(NOTIFICATION_PRIV_ID);
597 notification_h noti = NULL;
598 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
602 msg_thread_id_t threadId = 0;
605 char addressVal[MAX_ADDRESS_VAL_LEN+1];
606 char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
607 char displayName[MAX_DISPLAY_NAME_LEN+1];
608 char thumbPath[MAX_IMAGE_PATH_LEN+1];
609 char sqlQuery[MAX_QUERY_LEN+1];
611 memset(tempId, 0x00, sizeof(tempId));
612 memset(addressVal, 0x00, sizeof(addressVal));
613 memset(firstName, 0x00, sizeof(firstName));
614 memset(lastName, 0x00, sizeof(lastName));
615 memset(displayName, 0x00, sizeof(displayName));
616 memset(thumbPath, 0x00, sizeof(thumbPath));
617 memset(sqlQuery, 0x00, sizeof(sqlQuery));
619 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, \
620 B.DISPLAY_TIME, A.CONTACT_ID, A.IMAGE_PATH, B.MSG_ID, B.MSG_TEXT, B.SUBJECT, B.MAIN_TYPE \
621 FROM %s A, %s B WHERE A.CONV_ID=B.CONV_ID AND B.READ_STATUS=0 AND B.FOLDER_ID=%d ORDER BY B.DISPLAY_TIME DESC;",
622 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID);
624 if (dbhandler.prepareQuery(sqlQuery) != MSG_SUCCESS)
625 return MSG_ERR_DB_PREPARE;
627 if (dbhandler.stepQuery() == MSG_ERR_DB_ROW) {
628 threadId = dbhandler.columnInt(0);
630 if (dbhandler.columnText(1) != NULL)
631 strncpy(addressVal, (char*)dbhandler.columnText(1), MAX_ADDRESS_VAL_LEN);
634 char *pTempDisplayName = (char *)dbhandler.columnText(2);
635 if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
636 strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
638 if (dbhandler.columnText(3) != NULL)
639 strncpy(firstName, (char*)dbhandler.columnText(3), MAX_DISPLAY_NAME_LEN);
641 if (dbhandler.columnText(4) != NULL)
642 strncpy(lastName, (char*)dbhandler.columnText(4), MAX_DISPLAY_NAME_LEN);
644 int order = MsgGetContactNameOrder();
647 if (firstName[0] != '\0') {
648 strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
651 if (lastName[0] != '\0') {
652 strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
653 strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
655 } else if (order == 1) {
656 if (lastName[0] != '\0') {
657 strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
658 strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
661 if (firstName[0] != '\0') {
662 strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
667 msgTime = (time_t)dbhandler.columnInt(5);
669 contactId = dbhandler.columnInt(6);
671 strncpy(thumbPath, (char*)dbhandler.columnText(7), MAX_IMAGE_PATH_LEN);
673 msg.msgId = dbhandler.columnInt(8);
675 strncpy(msg.msgText, (char*)dbhandler.columnText(9), MAX_MSG_TEXT_LEN);
677 strncpy(msg.subject, (char*)dbhandler.columnText(10), MAX_SUBJECT_LEN);
679 msg.msgType.mainType = dbhandler.columnInt(11);
681 MSG_DEBUG("unread message [%d].", msg.msgId);
684 MSG_DEBUG("No unread message.");
685 MSG_DEBUG("notiPrivId [%d]", notiPrivId);
687 dbhandler.finalizeQuery();
689 // No unread message.
690 if (notiPrivId > 0) {
691 noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, notiPrivId);
692 if (noti_err != NOTIFICATION_ERROR_NONE) {
693 MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
699 if(MsgSettingSetInt(NOTIFICATION_PRIV_ID, notiPrivId) != MSG_SUCCESS)
700 MSG_DEBUG("MsgSettingSetInt fail : NOTIFICATION_PRIV_ID");
702 return MSG_ERR_DB_STEP;
705 dbhandler.finalizeQuery();
708 args = bundle_create();
710 int unreadMsgCnt = MsgStoGetUnreadCnt(&dbhandler, MSG_SMS_TYPE);
711 unreadMsgCnt += MsgStoGetUnreadCnt(&dbhandler, MSG_MMS_TYPE);
713 MSG_DEBUG("notiPrivId [%d], unreadMsgCnt [%d]", notiPrivId, unreadMsgCnt);
715 if (notiPrivId > 0) {
716 noti = notification_load(NULL, notiPrivId);
718 MSG_DEBUG("notification_load is failed.");
722 noti = notification_create(NOTIFICATION_TYPE_NOTI);
724 MSG_DEBUG("notification_new is failed.");
726 return MSG_ERR_UNKNOWN;
731 noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
732 if (noti_err != NOTIFICATION_ERROR_NONE) {
733 MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
735 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
736 if (noti_err != NOTIFICATION_ERROR_NONE) {
737 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
741 if (unreadMsgCnt > 1) {
743 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
744 if (noti_err != NOTIFICATION_ERROR_NONE) {
745 MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
748 noti_err = notification_set_text_domain(noti, MSG_SYS_PACKAGE_NAME, MSG_SYS_LOCALEDIR);
749 if (noti_err != NOTIFICATION_ERROR_NONE) {
750 MSG_DEBUG("Fail to notification_set_text_domain.");
753 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Message", MESSAGE, NOTIFICATION_VARIABLE_TYPE_NONE);
755 char unreadMsgCntStr[5] = {0,};
756 snprintf(unreadMsgCntStr, 5, "%d", unreadMsgCnt);
757 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
759 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Messages", NEW_MESSAGES, NOTIFICATION_VARIABLE_TYPE_NONE);
761 if (displayName[0] == '\0')
762 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
764 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
766 if (msg.msgType.mainType == MSG_SMS_TYPE)
767 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2,msg.msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
769 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, msg.subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
772 notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
776 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
777 if (noti_err != NOTIFICATION_ERROR_NONE) {
778 MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
781 noti_err = notification_set_text_domain(noti, MSG_SYS_PACKAGE_NAME, MSG_SYS_LOCALEDIR);
782 if (noti_err != NOTIFICATION_ERROR_NONE) {
783 MSG_DEBUG("Fail to notification_set_text_domain.");
786 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Message", MESSAGE, NOTIFICATION_VARIABLE_TYPE_NONE);
788 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Message", NEW_MESSAGE, NOTIFICATION_VARIABLE_TYPE_NONE);
790 if (displayName[0] == '\0')
791 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
793 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
795 if (msg.msgType.mainType == MSG_SMS_TYPE)
796 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2,msg.msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
798 notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, msg.subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
801 notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
806 noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL);
808 noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER);
810 if (noti_err != NOTIFICATION_ERROR_NONE) {
811 MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
815 memset(&tempId, 0x00, sizeof(tempId));
817 bundle_add(args, "type", "msg_id");
819 snprintf(tempId, 5, "%d", msg.msgId);
820 bundle_add(args, "msgId", tempId);
823 noti_err = notification_set_args(noti, args, NULL);
824 if (noti_err != NOTIFICATION_ERROR_NONE) {
825 MSG_DEBUG("Fail to notification_set_args : %d", noti_err);
829 if (notiPrivId > 0) {
830 noti_err = notification_update(noti);
831 if (noti_err != NOTIFICATION_ERROR_NONE) {
832 MSG_DEBUG("Fail to notification_update");
835 noti_err = notification_insert(noti, ¬iPrivId);
836 if (noti_err != NOTIFICATION_ERROR_NONE) {
837 MSG_DEBUG("Fail to notification_insert");
840 if (MsgSettingSetInt(NOTIFICATION_PRIV_ID, notiPrivId) != MSG_SUCCESS)
841 MSG_DEBUG("MsgSettingSetInt fail: NOTIFICATION_PRIV_ID");
842 MSG_DEBUG("Insert notiPrivId [%d]", notiPrivId);
845 noti_err = notification_free(noti);
846 if (noti_err != NOTIFICATION_ERROR_NONE) {
847 MSG_DEBUG("Fail to notification_free");
855 msg_error_t MsgCleanAndResetNoti()
857 msg_error_t err = MSG_SUCCESS;
858 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
860 noti_err = notification_delete_all_by_type("/usr/bin/msg-server", NOTIFICATION_TYPE_NOTI);
861 if (noti_err != NOTIFICATION_ERROR_NONE) {
862 MSG_DEBUG("Fail to notification_delete_all_by_type noti_err [%d]", noti_err);
863 return MSG_ERR_UNKNOWN;
866 err = MsgRefreshNoti(false);
867 if (err != MSG_SUCCESS) {
868 MSG_DEBUG("Fail to MsgRefreshNoti");
875 msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg)
878 MSG_DEBUG("pTickerMsg [%s]", pTickerMsg);
879 MSG_DEBUG("pLocaleTickerMsg [%s]", pLocaleTickerMsg);
881 notification_h noti = NULL;
882 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
884 noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
886 MSG_DEBUG("notification_new is failed.");
887 return MSG_ERR_UNKNOWN;
890 noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
891 if (noti_err != NOTIFICATION_ERROR_NONE) {
892 MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
895 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
896 if (noti_err != NOTIFICATION_ERROR_NONE) {
897 MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
900 noti_err = notification_set_text_domain(noti, MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR);
901 if (noti_err != NOTIFICATION_ERROR_NONE) {
902 MSG_DEBUG("Fail to notification_set_text_domain.");
905 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, pTickerMsg, pLocaleTickerMsg, NOTIFICATION_VARIABLE_TYPE_NONE);
906 if (noti_err != NOTIFICATION_ERROR_NONE) {
907 MSG_DEBUG("Fail to notification_set_text : %d", noti_err);
910 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, pTickerMsg, pLocaleTickerMsg, NOTIFICATION_VARIABLE_TYPE_NONE);
911 if (noti_err != NOTIFICATION_ERROR_NONE) {
912 MSG_DEBUG("Fail to notification_set_text : %d", noti_err);
915 noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER);
916 if (noti_err != NOTIFICATION_ERROR_NONE) {
917 MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
920 noti_err = notification_insert(noti, NULL);
921 if (noti_err != NOTIFICATION_ERROR_NONE) {
922 MSG_DEBUG("Fail to notification_set_text_domain");
925 noti_err = notification_free(noti);
926 if (noti_err != NOTIFICATION_ERROR_NONE) {
927 MSG_DEBUG("Fail to notification_set_text_domain");
932 msg_error_t MsgInsertBadge(unsigned int unreadMsgCnt)