move notification, media-player feature to msg-manager from msg-service
[platform/core/messaging/msg-service.git] / manager / src / msg-manager-notification.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 /*==================================================================================================
18                                          INCLUDE FILES
19 ==================================================================================================*/
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <glib.h>
24
25 #include <libintl.h>
26 #include <locale.h>
27 #include <stdarg.h>
28
29 #include <app_control_internal.h>
30 #include <badge_internal.h>
31 #include <bundle.h>
32 #include <notification_list.h>
33 #include <notification_text_domain.h>
34 #include <notification_internal.h>
35 #include <notification_status.h>
36 #include <package_manager.h>
37 #include <phone_number.h>
38 #include <vconf.h>
39
40 #include <msg.h>
41 #include <msg_storage.h>
42
43 #include <msg-manager-alarm.h>
44 #include <msg-manager-contact.h>
45 #include <msg-manager-debug.h>
46 #include <msg-manager-notification.h>
47 #include <msg-manager-sound.h>
48
49
50 #define EMAIL_AT '@'
51
52 /*==================================================================================================
53                                      VARIABLES
54 ==================================================================================================*/
55
56 static GList *msg_report_notification_list = NULL;
57 static bool is_init = false;
58 extern msg_handle_t msg_handle;
59 int g_alarmId = 0;
60
61
62 /*==================================================================================================
63                                          STRUCTURES
64 ==================================================================================================*/
65 typedef struct _report_notification_s
66 {
67         int priv_id;
68         char addressVal[MAX_ADDRESS_VAL_LEN+1];
69 } report_notification_s;
70
71
72 typedef struct _msg_mgr_noti_info_s
73 {
74         msg_mgr_notification_type_t             type;
75         int                     id;
76         int                     layout;
77         int                     count;
78         int                     senderCount;
79         time_t          time;
80         char            sender[MSG_NOTI_TEXT_LEN_S+1];
81         char            text[MSG_NOTI_TEXT_LEN+1];
82         char            number[MSG_NOTI_TEXT_LEN_S+1];
83         char            imagePath[MAX_IMAGE_PATH_LEN+1];                /**< Indicates the image path of contact. */
84         int                     applist;
85         app_control_h           svc_h;
86         app_control_h           active_noti_svc_h[MSG_ACTIVE_NOTI_BUTTON_NUM];
87         msg_message_id_t                msg_id;
88         unsigned char           extra_data;
89         int             sim_idx;
90         int                     active_noti_button_num;
91         int             active_media_cnt;
92         int             active_media_size;
93         unsigned char   active_subtype;         /**< to distinguish cb, push message */
94         char            active_sender[MSG_NOTI_TEXT_LEN_S+1];
95         char            active_subject[MSG_NOTI_TEXT_LEN_S+1];
96         char            active_text[MSG_NOTI_TEXT_LEN+1];
97 } MSG_MGR_NOTI_INFO_S;
98
99
100 /*==================================================================================================
101                                                                                 FUNCTION DEFINE
102 ===================================================================================================*/
103
104 void MsgMgrInitReportNotiList();
105 void MsgRefreshNotiCb(void *data);
106
107 notification_h getHandle(int *noti_id);
108
109 int getPrivId(msg_mgr_notification_type_t noti_type, int sim_idx);
110 void updatePrivId(msg_mgr_notification_type_t noti_type, int noti_id, int sim_idx);
111
112 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info); /* For addNoti() */
113 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, msg_mgr_active_notification_type_t active_noti);
114 void createActiveInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info);
115 void clearInfoData(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
116
117 int getAppIcon(const char *app_id, char **icon_path);
118 int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage);
119
120 void setProperty(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
121 void setTextDomain(notification_h noti_h, msg_mgr_notification_type_t noti_type);
122 void setText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
123 void setIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
124 void setSoundAndVibration(notification_h noti_h, char *addressVal, bool bVoiceMail);
125 void setActiveNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
126 void setActiveProperty(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
127 void setActiveText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
128 void setActiveIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
129
130 void setNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info, bool bFeedback);
131
132 bool isExistAddressInReportTable(const char *addr);
133
134 /* Wrapper */
135 void createServiceHandle(app_control_h *svc_h);
136 void setServiceAppId(app_control_h svc_h, const char* app_id);
137 void setServiceUri(app_control_h svc_h, const char* uri);
138 void setServiceOperation(app_control_h svc_h, const char* operation);
139 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, const char* bundle_val);
140 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, int bundle_val);
141 void setServicePackageName(app_control_h svc_h, const char* pkg_name);
142 void sendServicelaunchRequest(app_control_h svc_h, app_control_reply_cb callback, void *user_data);
143
144 void setNotiTextDomain(notification_h noti_h, const char *pkg_name, const char *loc_dir);
145 void setNotiText(notification_h noti_h, notification_text_type_e type, const char *text, const char *key);
146 void setNotiTimeToText(notification_h noti_h, notification_text_type_e type, time_t time);
147 void setNotiTime(notification_h noti_h, time_t time);
148 void setNotiImage(notification_h noti_h, notification_image_type_e type, const char *image_path);
149 void setNotiSound(notification_h noti_h, notification_sound_type_e type, const char *path);
150 void setNotiVibration(notification_h noti_h, notification_vibration_type_e type, const char *path);
151 void setNotiEventHandler(notification_h noti_h, notification_event_type_e type, app_control_h event_handler);
152
153 /* Alarm */
154 void MsgMgrNotiSoundRepeatAlarmCB(int alarmId);
155 void MsgMgrSoundCreateRepeatAlarm(int RepeatTime);
156 void MsgMgrSoundSetRepeatAlarm();
157
158 char *get_translate_text(const char *pkg_name, const char *locale_dir, const char *text);
159
160 /*==================================================================================================
161                                                                         FUNCTION IMPLEMENTATION
162 ==================================================================================================*/
163 bool _is_valid_email(char *pAddress)
164 {
165         if (!pAddress || pAddress[0] == 0)
166                 return false;
167         if (!strchr (pAddress, EMAIL_AT))
168                 return false;
169         return true;
170 }
171
172
173 bool isExistAddressInReportTable(const char *addr)
174 {
175         char sqlQuery[MAX_QUERY_LEN+1];
176         char *normal_addr = NULL;
177         int rowCnt = 0, colCnt = 0;
178         char **db_res = NULL;
179         int msg_err = 0;
180
181         int ret = phone_number_get_normalized_number(addr, &normal_addr);
182         if (ret != PHONE_NUMBER_ERROR_NONE) {
183                 MSG_MGR_ERR("phone_number_get_normalized_number() failed [%d]", ret);
184                 return false;
185         }
186
187         memset(sqlQuery, 0x00, sizeof(sqlQuery));
188         snprintf(sqlQuery, sizeof(sqlQuery), "* FROM %s WHERE ADDRESS_VAL LIKE '%%%%%s'", MSGFW_SMS_REPORT_TABLE_NAME, normal_addr);
189
190         msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &rowCnt, &colCnt);
191         if (msg_err != MSG_SUCCESS) {
192                 MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
193                 g_free(normal_addr);
194                 return false;
195         }
196
197         msg_err = msg_db_free(msg_handle, db_res);
198         if (msg_err != MSG_SUCCESS) {
199                 MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
200                 g_free(normal_addr);
201                 return false;
202         }
203
204         if (rowCnt > 0) {
205                 g_free(normal_addr);
206                 return true;
207         }
208
209         memset(sqlQuery, 0x00, sizeof(sqlQuery));
210         snprintf(sqlQuery, sizeof(sqlQuery), "* FROM %s WHERE ADDRESS_VAL LIKE '%%%%%s'", MSGFW_REPORT_TABLE_NAME, normal_addr);
211
212         g_free(normal_addr);
213
214         msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &rowCnt, &colCnt);
215         if (msg_err != MSG_SUCCESS) {
216                 MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
217                 return false;
218         }
219
220         msg_err = msg_db_free(msg_handle, db_res);
221         if (msg_err != MSG_SUCCESS) {
222                 MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
223                 return false;
224         }
225
226         if (rowCnt > 0)
227                 return true;
228
229         return false;
230 }
231
232
233 void MsgMgrInitReportNotiList()
234 {
235         MSG_MGR_BEGIN();
236
237         if (msg_report_notification_list) {
238                 MSG_MGR_DEBUG("Report Noti List is already inited");
239                 return;
240         }
241
242         msg_report_notification_list = NULL;
243
244         notification_h noti = NULL;
245         notification_list_h noti_list = NULL;
246         notification_list_h head_noti_list = NULL;
247         int noti_err = NOTIFICATION_ERROR_NONE;
248         bundle *b = NULL;
249
250         noti_err = notification_get_list(NOTIFICATION_TYPE_NONE, -1, &noti_list);
251         if (noti_err != NOTIFICATION_ERROR_NONE) {
252                 MSG_MGR_DEBUG("notification_get_list() is failed!!");
253                 return;
254         }
255
256         head_noti_list = noti_list;
257
258         while (noti_list != NULL) {
259                 noti = notification_list_get_data(noti_list);
260
261                 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
262                 memset(tempAddr, 0x00, sizeof(tempAddr));
263
264                 noti_err = notification_get_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &b);
265                 if (noti_err != NOTIFICATION_ERROR_NONE) {
266                         MSG_MGR_DEBUG("notification_get_excute_option() failed!!");
267                         break;
268                 }
269
270                 char *bundle_addr = NULL;
271
272                 int ret = bundle_get_str(b, "address", &bundle_addr);
273                 if (ret == BUNDLE_ERROR_NONE && bundle_addr != NULL) {
274                         if (isExistAddressInReportTable(bundle_addr)) {
275                                 report_notification_s *info = new report_notification_s;
276                                 memset(info, 0x00, sizeof(report_notification_s));
277
278                                 notification_get_id(noti, NULL, &(info->priv_id));
279                                 snprintf(info->addressVal, sizeof(info->addressVal), "%s", bundle_addr);
280
281                                 msg_report_notification_list = g_list_append(msg_report_notification_list, (void *)info);
282                                 MSG_MGR_SEC_DEBUG("appended list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
283                         }
284                 }
285
286                 noti_list = notification_list_get_next(noti_list);
287         }
288
289         if (head_noti_list)
290                 notification_free_list(head_noti_list);
291
292         MSG_MGR_END();
293 }
294
295
296 void MsgMgrInitNoti()
297 {
298         if (is_init)
299                 return;
300
301         bool bNotiSvcReady = false;
302
303         bNotiSvcReady = notification_is_service_ready();
304
305         if (bNotiSvcReady == true) {
306                 MSG_MGR_DEBUG("Notification server is available");
307 #ifndef MSG_NOTI_INTEGRATION
308                 MsgDeleteNotification(MSG_MGR_NOTI_TYPE_SIM, -1);
309 #endif
310                 MsgMgrRefreshAllNotification(false, true, MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT);            /* On Booting */
311                 MsgMgrInitReportNotiList();
312         } else {
313                 MSG_MGR_DEBUG("Notification server is not available. Init is defered");
314 #ifndef MSG_NOTI_INTEGRATION
315                 MSG_MGR_NOTI_INFO_S *delNotiInfo = (MSG_MGR_NOTI_INFO_S *)calloc(1, sizeof(MSG_MGR_NOTI_INFO_S));
316                 if (delNotiInfo) {
317                         delNotiInfo->type = MSG_MGR_NOTI_TYPE_SIM;
318                         delNotiInfo->sim_idx = -1;
319                 }
320                 notification_add_deferred_task(MsgDeleteNotiCb, (void *)delNotiInfo);
321 #endif
322                 notification_add_deferred_task(MsgRefreshNotiCb, (void *)NULL);
323         }
324
325         is_init = true;
326 }
327
328
329 void MsgRefreshNotiCb(void *data)
330 {
331         MsgMgrRefreshAllNotification(false, true, MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT);
332         MsgMgrInitReportNotiList();
333
334         if (data) {
335                 free(data);
336                 data = NULL;
337         }
338
339         return;
340 }
341
342
343 int MsgMgrInsertOnlyActiveNotification(msg_mgr_notification_type_t noti_type, MSG_MGR_MESSAGE_INFO_S *msg_info)
344 {
345         MSG_MGR_BEGIN();
346
347         notification_h noti_h = NULL;
348
349         MSG_MGR_NOTI_INFO_S noti_info = {0, };
350
351         noti_info.type = noti_type;
352         noti_info.active_noti_button_num = 1;
353
354         createActiveInfoData(&noti_info, msg_info);
355
356         noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
357
358         setActiveNotification(noti_h, &noti_info);
359
360         clearInfoData(noti_h, &noti_info);
361
362         MSG_MGR_END();
363         return 0;
364 }
365
366
367 int MsgMgrRefreshNotification(msg_mgr_notification_type_t noti_type, bool bFeedback, msg_mgr_active_notification_type_t active_type)
368 {
369         int err = 0;
370         notification_h noti_h = NULL;
371         int bNotification = 1;
372 /*      bool bReplyPopup = false; */
373
374         MSG_MGR_NOTI_INFO_S noti_info = {0,};
375         noti_info.type = noti_type;
376         noti_info.id = getPrivId(noti_info.type, -1);
377
378         err = getLatestMsgInfo(&noti_info, false);
379
380         if (err != 0) {
381                 MSG_MGR_DEBUG("getLatestMsgInfo() err = [%d]", err);
382                 goto __END_OF_REFRESH_NOTI;
383         }
384
385         if (active_type == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT) {
386                 err = MsgMgrInsertInstantMessage(noti_type);
387
388                 if (err != 0) {
389                         MSG_MGR_DEBUG(" MsgMgrInsertInstantMessage() err = [%d]", err);
390                         goto __END_OF_REFRESH_NOTI;
391                 }
392         }
393
394         if (vconf_get_bool(MSG_SETTING_NOTIFICATION, &bNotification) != 0) {
395                 MSG_MGR_DEBUG("vconf_get_bool is failed.");
396         }
397
398         if (bNotification == 0) {
399                 MSG_MGR_DEBUG("Msg Alert notification is off.");
400                 goto __END_OF_REFRESH_NOTI;
401         }
402
403         createInfoData(&noti_info, active_type);
404
405         noti_h = getHandle(&noti_info.id);
406
407         if (noti_h == NULL) {
408                 MSG_MGR_DEBUG("Notification handle is NULL");
409                 err = MSG_ERR_NULL_POINTER;
410                 goto __END_OF_REFRESH_NOTI;
411         }
412
413         setNotification(noti_h, &noti_info, bFeedback);
414
415 __END_OF_REFRESH_NOTI :
416         clearInfoData(noti_h, &noti_info);
417
418         return err;
419 }
420
421
422 int MsgMgrAddReportNotification(msg_mgr_notification_type_t noti_type, MSG_MGR_MESSAGE_INFO_S *msg_info)
423 {
424         int ret = 0;
425
426         notification_h noti_h = NULL;
427
428         report_notification_s *info = new report_notification_s;
429         memset(info, 0x00, sizeof(report_notification_s));
430
431         MSG_MGR_NOTI_INFO_S noti_info = {0,};
432         noti_info.type = noti_type;
433
434         createInfoData(&noti_info, msg_info);
435
436         noti_h = getHandle(&noti_info.id);
437
438         if (noti_h == NULL) {
439                 MSG_MGR_DEBUG("Notification handle is NULL");
440                 ret = -1;
441                 goto __END_OF_ADD_REPORT_NOTI;
442         }
443
444         setNotification(noti_h, &noti_info, true);
445
446         info->priv_id = noti_info.id;
447         snprintf(info->addressVal, sizeof(info->addressVal), "%s", msg_info->addressVal);
448         msg_report_notification_list = g_list_append(msg_report_notification_list, (void *)info);
449         MSG_MGR_SEC_DEBUG("appended list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
450
451 __END_OF_ADD_REPORT_NOTI :
452         clearInfoData(noti_h, &noti_info);
453
454         return ret;
455 }
456
457
458 int MsgMgrDeleteReportNotification(const char *addr)
459 {
460         MSG_MGR_BEGIN();
461
462         notification_h noti_h = NULL;
463         int bNotification = 1;
464
465         if (vconf_get_bool(MSG_SETTING_NOTIFICATION, &bNotification) != 0) {
466                 MSG_MGR_DEBUG("vconf_get_bool is failed.");
467         }
468
469         if (bNotification == 0) {
470                 MSG_MGR_DEBUG("Msg Alert notification is off.");
471                 return 0;
472         }
473
474         char* normalAddr = NULL;
475         unsigned int list_length = g_list_length(msg_report_notification_list);
476         bool isDelete = false;
477
478         MSG_MGR_DEBUG("list length [%d]", list_length);
479
480         if (list_length > 0) {
481                 GList *iter = g_list_first(msg_report_notification_list);
482
483                 while (iter != NULL) {
484                         isDelete = false;
485                         report_notification_s *info = (report_notification_s*)(iter->data);
486                         if (info == NULL) {
487                                 MSG_MGR_DEBUG("info is NULL!");
488                                 return -1;
489                         }
490
491                         MSG_MGR_SEC_DEBUG("list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
492
493                         noti_h = notification_load(NULL, info->priv_id);
494                         if (noti_h == NULL) {
495                                 MSG_MGR_DEBUG("notification with priv_id [%d] is NULL", info->priv_id);
496                                 isDelete = true;
497                         } else {
498                                 phone_number_get_normalized_number(info->addressVal, &normalAddr);
499
500                                 if (normalAddr) {
501                                         MSG_MGR_SEC_DEBUG("normalized number = %s", normalAddr);
502
503                                         if (g_str_has_suffix(addr, normalAddr)) {
504                                                 if (notification_delete(noti_h) == NOTIFICATION_ERROR_NONE) {
505                                                         MSG_MGR_SEC_DEBUG("delete report notification address [%s]", info->addressVal);
506                                                         isDelete = true;
507                                                 } else {
508                                                         MSG_MGR_DEBUG("delete notification failed");
509                                                 }
510                                         }
511
512                                         g_free(normalAddr);
513                                         normalAddr = NULL;
514                                 }
515
516                                 notification_free(noti_h);
517                                 noti_h = NULL;
518                         }
519
520                         iter = g_list_next(iter);
521
522                         if (isDelete) {
523                                 msg_report_notification_list = g_list_remove(msg_report_notification_list, (void *)info);
524                                 if (info) {
525                                         delete info;
526                                         info = NULL;
527                                 }
528                         }
529                 }
530         }
531
532         MSG_MGR_END();
533
534         return 0;
535 }
536
537 int MsgMgrAddNotification(msg_mgr_notification_type_t noti_type, MSG_MGR_MESSAGE_INFO_S *msg_info)
538 {
539         int ret = 0;
540
541         notification_h noti_h = NULL;
542
543         MSG_MGR_NOTI_INFO_S noti_info = {0, };
544
545         noti_info.type = noti_type;
546
547         createInfoData(&noti_info, msg_info);
548
549         /* check mwi or voicemail count is 0 then skip add notification */
550         if (noti_info.count == 0) {
551                 MSG_MGR_DEBUG("Notification count is 0");
552                 ret = -1;
553                 goto __END_OF_ADD_NOTI;
554         }
555
556         noti_h = getHandle(&noti_info.id);
557
558         if (noti_h == NULL) {
559                 MSG_MGR_DEBUG("Notification handle is NULL");
560                 ret = -1;
561                 goto __END_OF_ADD_NOTI;
562         }
563
564         setNotification(noti_h, &noti_info, true);
565
566 __END_OF_ADD_NOTI :
567         clearInfoData(noti_h, &noti_info);
568
569         return ret;
570 }
571
572
573 void MsgMgrRefreshAllNotification(bool bWithSimNoti, bool bFeedback, msg_mgr_active_notification_type_t active_type)
574 {
575         MSG_MGR_BEGIN();
576
577         int err = 0;
578
579 #ifndef MSG_NOTI_INTEGRATION
580         MsgDeleteNotification(MSG_MGR_NOTI_TYPE_SIM);
581 #endif
582
583 #ifdef MSG_NOTI_INTEGRATION
584         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_NORMAL, bFeedback, active_type);
585         if (err != 0)
586                 MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_NORMAL, err);
587 #else
588         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_NORMAL, bFeedback, active_type);
589         if (err != 0)
590                 MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_NORMAL, err);
591
592         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_CB, bFeedback, active_type);
593         if (err != 0)
594                 MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_CB, err);
595
596         if (bWithSimNoti) {
597                 err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_SIM, bFeedback, active_type);
598                 if (err != 0)
599                         MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_SIM, err);
600         }
601 #endif
602
603         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_FAILED, bFeedback, active_type);
604         if (err != 0)
605                 MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_FAILED, err);
606
607         MSG_MGR_END();
608 }
609
610
611 void setProperty(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
612 {
613         MSG_MGR_BEGIN();
614
615         int noti_err = NOTIFICATION_ERROR_NONE;
616
617         /* set layout */
618         noti_err = notification_set_layout(noti_h, (notification_ly_type_e)noti_info->layout);
619         if (noti_err != NOTIFICATION_ERROR_NONE) {
620                 MSG_MGR_DEBUG("Fail to notification_set_layout : %d", noti_err);
621         }
622
623         /* set led */
624         noti_err = notification_set_led(noti_h, NOTIFICATION_LED_OP_ON, 0x00);
625         if (noti_err != NOTIFICATION_ERROR_NONE) {
626                 MSG_MGR_DEBUG("Fail to notification_set_led.");
627         }
628
629         /* set execute option */
630         bundle *bundle_data = NULL;
631         bundle *reply_msg = NULL;
632
633         app_control_to_bundle(noti_info->svc_h, &bundle_data);
634
635         if (bundle_data == NULL) {
636                 MSG_MGR_DEBUG("bundle is NULL");
637         }
638
639         /* set execute option and property */
640         switch (noti_info->type) {
641         case MSG_MGR_NOTI_TYPE_NORMAL: {
642                 if (noti_info->count > 1) {
643                         notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, bundle_data);
644                         notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_RESPONDING, NULL, NULL, NULL);
645                 } else {
646                         if (noti_info->svc_h) { /* overwrite bundle key "type" */
647                                 /* addServiceExtraData(noti_info->svc_h, "type", "reply"); */
648                                 addServiceExtraData(noti_info->svc_h, "show_list", "list_show");
649
650                                 app_control_to_bundle(noti_info->svc_h, &reply_msg);
651                         }
652                         notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
653                         notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_RESPONDING, NULL, NULL, reply_msg);
654                 }
655
656                 notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
657                 break;
658         }
659         case MSG_MGR_NOTI_TYPE_CB:
660         case MSG_MGR_NOTI_TYPE_SIM: {
661                 if (noti_info->count > 1) {
662                         notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, bundle_data);
663                 } else {
664                         notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
665                 }
666
667                 notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE|NOTIFICATION_PROP_VOLATILE_DISPLAY);
668                 break;
669         }
670         case MSG_MGR_NOTI_TYPE_FAILED: {
671                 notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
672                 notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
673                 break;
674         }
675         case MSG_MGR_NOTI_TYPE_SIM_FULL: {
676                 notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
677                 break;
678         }
679         case MSG_MGR_NOTI_TYPE_VOICE_1:
680         case MSG_MGR_NOTI_TYPE_VOICE_2:
681         case MSG_MGR_NOTI_TYPE_MWI:
682         case MSG_MGR_NOTI_TYPE_CLASS0:
683         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT:
684         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
685         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
686                 notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
687                 break;
688         }
689         default:
690                 MSG_MGR_DEBUG("No matching type for notification_set_execute_option() [%d]", noti_info->type);
691                 break;
692         }
693
694         /* set applist */
695         noti_err = notification_set_display_applist(noti_h, noti_info->applist);
696         if (noti_err != NOTIFICATION_ERROR_NONE) {
697                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
698         }
699
700
701         MSG_MGR_END();
702 }
703
704
705 void setTextDomain(notification_h noti_h, msg_mgr_notification_type_t noti_type)
706 {
707         MSG_MGR_BEGIN();
708
709         setNotiTextDomain(noti_h, MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR);
710         MSG_MGR_END();
711 }
712
713
714 void setText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
715 {
716         MSG_MGR_BEGIN();
717
718         char unreadMsgCntStr[10] = {0};
719         int bPreview = 1;
720
721         if (vconf_get_bool(MSG_SETTING_PREVIEW, &bPreview) != 0) {
722                 MSG_MGR_DEBUG("vconf_get_bool is failed.");
723         }
724
725         /* set title and content */
726         switch (noti_info->type) {
727 #ifdef MSG_NOTI_INTEGRATION
728         case MSG_MGR_NOTI_TYPE_NORMAL:
729         case MSG_MGR_NOTI_TYPE_CB:
730         case MSG_MGR_NOTI_TYPE_SIM: {
731                 if (noti_info->count > 1) {
732                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Messages", NEW_MESSAGES);
733                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
734                         setNotiTime(noti_h, noti_info->time);
735
736                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
737                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
738
739                 } else {
740                         if (bPreview) {
741                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
742                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
743                         } else {
744                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Message", NEW_MESSAGE);
745                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
746                         }
747                         setNotiTime(noti_h, noti_info->time);
748                 }
749                 break;
750         }
751 #else
752         case MSG_MGR_NOTI_TYPE_NORMAL: {
753                 if (noti_info->count > 1) {
754                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Messages", NEW_MESSAGES);
755                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
756                         setNotiTime(noti_h, noti_info->time);
757
758                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
759                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
760                 } else {
761                         if (bPreview) {
762                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
763                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
764                         } else {
765                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Message", NEW_MESSAGE);
766                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
767                         }
768                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
769                         setNotiTime(noti_h, noti_info->time);
770                 }
771                 break;
772         }
773         case MSG_MGR_NOTI_TYPE_CB: {
774                 if (noti_info->count > 1) {
775                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", CB_MESSAGE);
776                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
777                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
778                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
779                         setNotiTime(noti_h, noti_info->time);
780
781                 } else {
782                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
783                         setNotiTime(noti_h, noti_info->time);
784
785                         if (bPreview) {
786                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
787                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
788                         } else {
789                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", CB_MESSAGE);
790                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
791                         }
792                 }
793                 break;
794         }
795         case MSG_MGR_NOTI_TYPE_SIM: {
796                 if (noti_info->count > 1) {
797                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card Message", SIM_CARD_MESSAGE);
798                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
799                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
800
801                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
802                         setNotiTime(noti_h, noti_info->time);
803                 } else {
804                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
805                         setNotiTime(noti_h, noti_info->time);
806
807                         if (bPreview) {
808                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
809                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
810                         } else {
811                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card Message", SIM_CARD_MESSAGE);
812                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
813                         }
814                 }
815                 break;
816         }
817 #endif
818         case MSG_MGR_NOTI_TYPE_FAILED: {
819                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Message", MSG_MESSAGE);
820                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Failed to send message.", FAILED_TO_SEND_MESSAGE);
821                 if (noti_info->count > 1) {
822                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
823                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
824                 }
825                 setNotiTime(noti_h, noti_info->time);
826                 break;
827         }
828         case MSG_MGR_NOTI_TYPE_VOICE_1:
829         case MSG_MGR_NOTI_TYPE_VOICE_2: {
830                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Voicemail", VOICE_MAIL);
831                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
832                 setNotiTime(noti_h, noti_info->time);
833
834                 if (noti_info->count == 1) {
835                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
836                 } else if (noti_info->count > 1) {
837                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
838                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
839                 } else {
840                         MSG_MGR_DEBUG("Invalid notification count, [cnt = %d]", noti_info->count);
841                 }
842                 break;
843         }
844         case MSG_MGR_NOTI_TYPE_MWI: {
845                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "MWI Message", NULL);
846                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
847                 setNotiTime(noti_h, noti_info->time);
848                 break;
849         }
850         case MSG_MGR_NOTI_TYPE_CLASS0: {
851                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "CLASS 0 Message", NULL);
852                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
853                 setNotiTime(noti_h, noti_info->time);
854                 break;
855         }
856         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT: {
857                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery report", DELIVERY_MESSAGE);
858                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
859
860                 if (noti_info->extra_data == MSG_NETWORK_DELIVER_SUCCESS) {
861                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delivered", DELIVERED_MESSAGE);
862                 } else if (noti_info->extra_data == MSG_NETWORK_DELIVER_EXPIRED) {
863                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message expired", EXPIRED_MESSAGE);
864                 } else {
865                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message deferred", DEFERRED_MESSAGE);
866                 }
867
868                 setNotiTime(noti_h, noti_info->time);
869                 break;
870         }
871         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT: {
872                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Read Report", READ_REPORT_MESSAGE);
873                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
874
875                 if (noti_info->extra_data == MSG_READ_REPORT_IS_DELETED) {
876                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message deleted", READ_REPORT_DELETE);
877                 /* CID 45672: noti_info->extra_data in unsigned char but MSG_READ_REPORT_NONE is -1. So the expression is always false */
878 #if 0
879                 } else if (noti_info->extra_data == MSG_READ_REPORT_NONE) {
880                         /* notification free */
881 #endif
882                 } else {
883                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message read", READ_REPORT_READ);
884                 }
885
886                 setNotiTime(noti_h, noti_info->time);
887                 break;
888         }
889         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
890                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery Report", DELIVERY_MESSAGE);
891                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
892
893                 if (noti_info->extra_data == MSG_DELIVERY_REPORT_EXPIRED)
894                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message expired", EXPIRED_MESSAGE);
895                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_REJECTED)
896                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message rejected", REJECTED_MESSAGE);
897                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_DEFERRED)
898                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message deferred", DEFERRED_MESSAGE);
899                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_UNRECOGNISED)
900                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message unrecognised", UNRECOGNISED_MESSAGE);
901                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_INDETERMINATE)
902                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message indeterminate", INDETEMINATE_MESSAGE);
903                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_FORWARDED)
904                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message forwarded", NULL);
905                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_UNREACHABLE)
906                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message unreachable", UNREACHABLE_MESSAGE);
907                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_ERROR)
908                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message error", NULL);
909                 /* CID 45672: noti_info->extra_data in unsigned char but MSG_READ_REPORT_NONE is -1. So the expression is always false */
910 #if 0
911                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_NONE) {
912                         /* notification free */
913                 }
914 #endif
915                 else
916                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delivered", DELIVERED_MESSAGE);
917
918                 setNotiTime(noti_h, noti_info->time);
919                 break;
920         }
921         case MSG_MGR_NOTI_TYPE_SIM_FULL: {
922                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card full", SMS_SIM_CARD_FULL);
923                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Not enough memory. Delete some items.", SMS_MESSAGE_MEMORY_FULL);
924                 break;
925         }
926         default:
927                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
928                 break;
929         }
930
931         MSG_MGR_END();
932 }
933
934 void setIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
935 {
936         MSG_MGR_BEGIN();
937
938         switch (noti_info->type) {
939 #ifdef MSG_NOTI_INTEGRATION
940         case MSG_MGR_NOTI_TYPE_NORMAL:
941         case MSG_MGR_NOTI_TYPE_CB:
942         case MSG_MGR_NOTI_TYPE_SIM: {
943                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
944                 if (noti_info->count > 1 && noti_info->senderCount > 1) {
945                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NORMAL_ICON_PATH);
946                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
947                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_SUB, "");
948                 } else {
949                         if (noti_info->active_subtype == MSG_CB_SMS) {
950                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_CB_ICON_PATH);
951                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
952                         } else if (noti_info->active_subtype == MSG_WAP_SI_SMS || noti_info->active_subtype == MSG_WAP_SL_SMS) {
953                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_ACTIVE_PUSH_ICON_PATH);
954                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_ACTIVE_PUSH_ICON_PATH);
955                         } else if (noti_info->active_subtype == MSG_SYNCML_CP) {
956                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_OTA_ICON_PATH);
957                         } else {
958                                 if (noti_info->imagePath[0] != '\0') {
959                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, noti_info->imagePath);
960                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, noti_info->imagePath);
961                                 } else {
962                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NO_CONTACT_PROFILE_ICON_PATH);
963                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NO_CONTACT_PROFILE_ICON_PATH);
964                                 }
965
966                                 char *msg_icon_path = NULL;
967                                 if (getAppIcon(MSG_DEFAULT_APP_ID, &msg_icon_path) == 0) {
968                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_SUB, msg_icon_path);
969                                         g_free(msg_icon_path);
970                                 } else {
971                                         MSG_MGR_ERR("fail to get message-app icon");
972                                 }
973                         }
974                 }
975                 break;
976         }
977 #else
978         case MSG_MGR_NOTI_TYPE_NORMAL: {
979                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
980                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NORMAL_ICON_PATH);
981
982                 if (noti_info->count > 1) {
983                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
984                 } else {
985                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_REPLY_ICON_PATH);
986                 }
987                 break;
988         }
989         case MSG_MGR_NOTI_TYPE_CB: {
990                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
991                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_CB_ICON_PATH);
992                 break;
993         }
994         case MSG_MGR_NOTI_TYPE_SIM: {
995                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SIM_ICON_PATH);
996                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_SIM_ICON_PATH);
997                 break;
998         }
999 #endif
1000         case MSG_MGR_NOTI_TYPE_FAILED: {
1001                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SMS_SENDING_FAILED_ICON_PATH);
1002                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_SMS_SENDING_FAILED_ICON_PATH);
1003                 break;
1004         }
1005         case MSG_MGR_NOTI_TYPE_VOICE_1:
1006         case MSG_MGR_NOTI_TYPE_VOICE_2:
1007         case MSG_MGR_NOTI_TYPE_MWI: {
1008                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_VOICE_MSG_STATUS_ICON);
1009                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_VOICE_ICON_PATH);
1010                 break;
1011         }
1012         case MSG_MGR_NOTI_TYPE_CLASS0:
1013                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1014                 break;
1015         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT:
1016                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1017                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1018                 break;
1019         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
1020                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1021                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1022                 break;
1023         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT:
1024                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1025                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1026                 break;
1027         case MSG_MGR_NOTI_TYPE_SIM_FULL:
1028                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1029                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1030                 break;
1031         default:
1032                 MSG_MGR_DEBUG("No matching type for MsgNotiSetImage [%d]", noti_info->type);
1033                 break;
1034         }
1035
1036         MSG_MGR_END();
1037 }
1038
1039 void setActiveProperty(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1040 {
1041         MSG_MGR_BEGIN();
1042
1043         int noti_err = NOTIFICATION_ERROR_NONE;
1044
1045         /* set layout */
1046         noti_err = notification_set_layout(noti_h, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
1047         if (noti_err != NOTIFICATION_ERROR_NONE) {
1048                 MSG_MGR_DEBUG("Fail to notification_set_layout : %d", noti_err);
1049         }
1050
1051         /* set led */
1052         noti_err = notification_set_led(noti_h, NOTIFICATION_LED_OP_ON, 0x00);
1053         if (noti_err != NOTIFICATION_ERROR_NONE) {
1054                 MSG_MGR_DEBUG("Fail to notification_set_led.");
1055         }
1056
1057         /* set applist */
1058         noti_err = notification_set_display_applist(noti_h, NOTIFICATION_DISPLAY_APP_ACTIVE);
1059         if (noti_err != NOTIFICATION_ERROR_NONE) {
1060                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
1061         }
1062
1063         MSG_MGR_END();
1064 }
1065
1066
1067 void setActiveText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1068 {
1069         MSG_MGR_BEGIN();
1070
1071         switch (noti_info->type) {
1072         case MSG_MGR_NOTI_TYPE_NORMAL:
1073         case MSG_MGR_NOTI_TYPE_SIM:
1074         case MSG_MGR_NOTI_TYPE_CB: {
1075                 if (noti_info->active_subject[0] == '\0') {
1076                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->active_sender, NULL);
1077                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->active_text, NULL);
1078                 } else {
1079                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->active_sender, NULL);
1080                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, noti_info->active_subject, NULL);
1081                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->active_text, NULL);
1082                 }
1083                 break;
1084         }
1085         case MSG_MGR_NOTI_TYPE_CLASS0: {
1086                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "CLASS 0 Message", NULL);
1087                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->active_sender, NULL);
1088                 break;
1089         }
1090         default:
1091                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
1092                 break;
1093         }
1094
1095         MSG_MGR_END();
1096 }
1097
1098
1099 void setActiveIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1100 {
1101         MSG_MGR_BEGIN();
1102
1103         switch (noti_info->type) {
1104         case MSG_MGR_NOTI_TYPE_NORMAL:
1105         case MSG_MGR_NOTI_TYPE_SIM: {
1106                 switch (noti_info->active_subtype) {
1107                 case MSG_CB_SMS:
1108                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
1109                         break;
1110                 case MSG_WAP_SI_SMS:
1111                 case MSG_WAP_SL_SMS:
1112                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_ACTIVE_PUSH_ICON_PATH);
1113                         break;
1114                 case MSG_SYNCML_CP:
1115                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_OTA_ICON_PATH);
1116                         break;
1117                 default:
1118                         if (noti_info->imagePath[0] != '\0')
1119                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, noti_info->imagePath);
1120                         else
1121                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NO_CONTACT_PROFILE_ICON_PATH);
1122
1123                         char *msg_icon_path = NULL;
1124                         if (getAppIcon(MSG_DEFAULT_APP_ID, &msg_icon_path) == 0) {
1125                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_SUB, msg_icon_path);
1126                                 g_free(msg_icon_path);
1127                         } else {
1128                                 MSG_MGR_ERR("fail to get message-app icon");
1129                         }
1130
1131                         break;
1132                 }
1133
1134                 break;
1135         }
1136         case MSG_MGR_NOTI_TYPE_CB: {
1137                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
1138                 break;
1139         }
1140         case MSG_MGR_NOTI_TYPE_CLASS0:
1141                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1142                 break;
1143         default:
1144                 MSG_MGR_DEBUG("No matching type for MsgNotiSetImage [%d]", noti_info->type);
1145                 break;
1146         }
1147
1148         MSG_MGR_END();
1149 }
1150
1151
1152 void setSoundAndVibration(notification_h noti_h, char *addressVal, bool bVoiceMail)
1153 {
1154         MSG_MGR_BEGIN();
1155
1156         MSG_MGR_ADDRESS_INFO_S addrInfo = {0,};
1157         MSG_MGR_CONTACT_INFO_S contactInfo = {0,};
1158
1159         if (addressVal != NULL) {
1160                 snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", addressVal);
1161                 /* Get Contact Info */
1162                 if (MsgMgrGetContactInfo(&addrInfo, &contactInfo) != 0) {
1163                         MSG_MGR_DEBUG("MsgMgrGetContactInfo() fail.");
1164                 }
1165         } else {
1166                 MSG_MGR_DEBUG("addressVal is NULL.");
1167         }
1168
1169         char *msg_tone_file_path = NULL;
1170
1171         MsgMgrGetRingtonePath(contactInfo.alerttonePath, &msg_tone_file_path);
1172
1173         MSG_MGR_SEC_DEBUG("Sound File [%s]", msg_tone_file_path);
1174
1175         bool bPlaySound = false;
1176         bool bPlayVibration = false;
1177         bool bOnCall = false;
1178
1179         MsgMgrGetPlayStatus(bVoiceMail, &bPlaySound, &bPlayVibration, &bOnCall);
1180
1181         if (bPlaySound) {
1182                 if (msg_tone_file_path)
1183                         setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_USER_DATA, msg_tone_file_path);
1184                 else {
1185                         int tmpVal = 0;
1186                         if (vconf_get_int(MSG_SETTING_RINGTONE_TYPE, &tmpVal) != 0) {
1187                                 MSG_MGR_INFO("MsgSettingGetInt() is failed");
1188                         }
1189                         int ringtoneType = tmpVal;
1190                         if (ringtoneType == MSG_RINGTONE_TYPE_SILENT)
1191                                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1192                         else
1193                                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL);
1194                 }
1195         } else {
1196                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1197         }
1198
1199         if (bPlayVibration) {
1200                 if (contactInfo.vibrationPath[0] == '\0')
1201                         setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
1202                 else
1203                         setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_USER_DATA, contactInfo.vibrationPath);
1204         } else {
1205                 setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
1206         }
1207
1208         if (msg_tone_file_path)
1209                 delete [] msg_tone_file_path;
1210
1211         MSG_MGR_END();
1212 }
1213
1214
1215 void setActiveNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1216 {
1217         MSG_MGR_BEGIN();
1218
1219         int noti_err = NOTIFICATION_ERROR_NONE;
1220
1221         setActiveProperty(noti_h, noti_info);
1222
1223         setTextDomain(noti_h, noti_info->type);
1224
1225         setActiveText(noti_h, noti_info);
1226
1227         setActiveIcon(noti_h, noti_info);
1228
1229         if (noti_info->active_noti_button_num > 1) {
1230                 createServiceHandle(&noti_info->active_noti_svc_h[0]);
1231                 if (noti_info->active_noti_svc_h[0]) {
1232                         setServicePackageName(noti_info->active_noti_svc_h[0], MSG_CALL_APP_ID);
1233                         setServiceOperation(noti_info->active_noti_svc_h[0], APP_CONTROL_OPERATION_CALL);
1234
1235                         MSG_MGR_DEBUG("Active Notification button 1 - Msg Id = [%d]", noti_info->msg_id);
1236
1237                         char tel_num[MSG_NOTI_TEXT_LEN_S] = {0, };
1238                         snprintf(tel_num, sizeof(tel_num), "tel:%s", noti_info->number);
1239                         MSG_MGR_SEC_DEBUG("Active sender number [%s]", noti_info->number);
1240                         setServiceUri(noti_info->active_noti_svc_h[0], tel_num);
1241                 }
1242
1243                 createServiceHandle(&noti_info->active_noti_svc_h[1]);
1244                 if (noti_info->active_noti_svc_h[1]) {
1245                         setServicePackageName(noti_info->active_noti_svc_h[1], MSG_DEFAULT_APP_ID);
1246
1247                         MSG_MGR_DEBUG("Active Notification button 2 - Msg Id = [%d]", noti_info->msg_id);
1248                         addServiceExtraData(noti_info->active_noti_svc_h[1], "type", "reply");
1249                         addServiceExtraData(noti_info->active_noti_svc_h[1], "msgId", noti_info->msg_id);
1250
1251                         char slot_id[5] = {0, };
1252                         snprintf(slot_id, sizeof(slot_id), "%d", noti_info->sim_idx - 1);
1253                         addServiceExtraData(noti_info->active_noti_svc_h[1], "slot_id", slot_id);
1254                 }
1255         }
1256
1257         createServiceHandle(&noti_info->active_noti_svc_h[2]);
1258         if (noti_info->active_noti_svc_h[2]) {
1259                 setServicePackageName(noti_info->active_noti_svc_h[2], MSG_DEFAULT_APP_ID);
1260
1261                 MSG_MGR_DEBUG("Active Notification button 3 - msgId = [%d]", noti_info->msg_id);
1262                 addServiceExtraData(noti_info->active_noti_svc_h[2], "type", "new_msg");
1263                 addServiceExtraData(noti_info->active_noti_svc_h[2], "msgId", noti_info->msg_id);
1264                 addServiceExtraData(noti_info->active_noti_svc_h[2], "CALLER", "active_noti");
1265
1266                 char slot_id[5] = {0, };
1267                 snprintf(slot_id, sizeof(slot_id), "%d", noti_info->sim_idx - 1);
1268                 addServiceExtraData(noti_info->active_noti_svc_h[2], "slot_id", slot_id);
1269         }
1270
1271         if (noti_info->active_noti_button_num > 1) {
1272                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, noti_info->active_noti_svc_h[0]);
1273                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2, noti_info->active_noti_svc_h[1]);
1274                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3, noti_info->active_noti_svc_h[2]);
1275
1276                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_1, "Call", NULL);
1277                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_2, "Reply", NULL);
1278                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_3, "View", NULL);
1279         } else {
1280                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, noti_info->active_noti_svc_h[2]);
1281
1282                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_1, "View", NULL);
1283         }
1284
1285         noti_err = notification_post(noti_h);
1286         if (noti_err != NOTIFICATION_ERROR_NONE) {
1287                 MSG_MGR_DEBUG("Fail to notification_post");
1288         }
1289
1290         MSG_MGR_END();
1291 }
1292
1293
1294 void setNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info, bool bFeedback)
1295 {
1296         MSG_MGR_BEGIN();
1297
1298         int noti_err = NOTIFICATION_ERROR_NONE;
1299
1300         MSG_MGR_DEBUG("active num [%d]", noti_info->active_noti_button_num);
1301
1302         if (bFeedback && noti_info->active_noti_button_num > 0 &&
1303                 ((noti_info->type >= MSG_MGR_NOTI_TYPE_NORMAL && noti_info->type <= MSG_MGR_NOTI_TYPE_SIM) || noti_info->type == MSG_MGR_NOTI_TYPE_CLASS0)) {
1304                 notification_h active_noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
1305
1306                 setActiveNotification(active_noti_h, noti_info);
1307
1308                 notification_free(active_noti_h);
1309                 active_noti_h = NULL;
1310         }
1311
1312         setProperty(noti_h, noti_info);
1313
1314         setTextDomain(noti_h, noti_info->type);
1315
1316         setText(noti_h, noti_info);
1317
1318         setIcon(noti_h, noti_info);
1319
1320         if (bFeedback) {
1321                 if (noti_info->type == MSG_MGR_NOTI_TYPE_VOICE_1 || noti_info->type == MSG_MGR_NOTI_TYPE_VOICE_2)
1322                         setSoundAndVibration(noti_h, noti_info->number, true);
1323                 else
1324                         setSoundAndVibration(noti_h, noti_info->number, false);
1325
1326         } else {
1327                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1328                 setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
1329         }
1330
1331         if (noti_info->id > 0) {
1332                 MSG_MGR_DEBUG("Notification update");
1333                 noti_err = notification_update(noti_h);
1334                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1335                         MSG_MGR_DEBUG("Fail to notification_update");
1336                 }
1337         } else {
1338                 MSG_MGR_DEBUG("Notification insert");
1339                 noti_err = notification_insert(noti_h, &noti_info->id);
1340                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1341                         MSG_MGR_DEBUG("Fail to notification_insert");
1342                 }
1343
1344                 updatePrivId(noti_info->type, noti_info->id, noti_info->sim_idx);
1345         }
1346
1347         MSG_MGR_END();
1348 }
1349
1350
1351 void createActiveInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info)
1352 {
1353         MSG_MGR_BEGIN();
1354
1355         if (!msg_info) {
1356                 MSG_MGR_DEBUG("msg_info is NULL");
1357                 return;
1358         }
1359
1360         noti_info->msg_id = msg_info->msgId;
1361         noti_info->sim_idx = msg_info->sim_idx;
1362
1363         switch (noti_info->type) {
1364         case MSG_MGR_NOTI_TYPE_NORMAL: {
1365                 char *senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, PUSH_MESSAGE);
1366                 snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", senderStr);
1367                 if (senderStr) {
1368                         free(senderStr);
1369                         senderStr = NULL;
1370                 }
1371                 break;
1372         }
1373         case MSG_MGR_NOTI_TYPE_CLASS0: {
1374                 if (msg_info->displayName[0] == '\0')
1375                         snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", msg_info->addressVal);
1376                 else
1377                         snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", msg_info->displayName);
1378
1379                 snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", msg_info->msgText);
1380                 break;
1381         }
1382         default:
1383                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
1384                 break;
1385         }
1386
1387         MSG_MGR_END();
1388 }
1389
1390
1391 void clearInfoData(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1392 {
1393         MSG_MGR_BEGIN();
1394
1395         if (noti_h) {
1396                 notification_free(noti_h);
1397                 noti_h = NULL;
1398         }
1399
1400         if (noti_info->svc_h) {
1401                 app_control_destroy(noti_info->svc_h);
1402                 noti_info->svc_h = NULL;
1403         }
1404
1405         for (int i = 0; i < MSG_ACTIVE_NOTI_BUTTON_NUM; i++) {
1406                 if (noti_info->active_noti_svc_h[i]) {
1407                         app_control_destroy(noti_info->active_noti_svc_h[i]);
1408                         noti_info->active_noti_svc_h[i] = NULL;
1409                 }
1410         }
1411
1412         MSG_MGR_END();
1413 }
1414
1415
1416 int getAppIcon(const char *app_id, char **icon_path)
1417 {
1418         MSG_MGR_BEGIN();
1419
1420         package_info_h pkg_info_h = NULL;
1421         int pkg_err = PACKAGE_MANAGER_ERROR_NONE;
1422         int ret = 0;
1423
1424         if (app_id == NULL) {
1425                 MSG_MGR_ERR("app id is NULL");
1426                 ret = -1;
1427                 goto END_OF_GET_APP_ICON;
1428         }
1429
1430         pkg_err = package_info_create(app_id, &pkg_info_h);
1431         if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1432                 MSG_MGR_ERR("package_info_create failed (%d)", pkg_err);
1433                 ret = -1;
1434                 goto END_OF_GET_APP_ICON;
1435         }
1436
1437         pkg_err = package_info_get_icon(pkg_info_h, icon_path);
1438         if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1439                 MSG_MGR_ERR("package_info_get_icon failed (%d)", pkg_err);
1440                 ret = -1;
1441         } else {
1442                 if (icon_path == NULL) {
1443                         MSG_MGR_WARN("icon path is NULL");
1444                         ret = -1;
1445                 }
1446         }
1447
1448 END_OF_GET_APP_ICON:
1449         if (pkg_info_h) {
1450                 pkg_err = package_info_destroy(pkg_info_h);
1451                 if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1452                         MSG_MGR_ERR("package_info_destroy failed (%d)", pkg_err);
1453                 }
1454
1455                 pkg_info_h = NULL;
1456         }
1457
1458         MSG_MGR_END();
1459
1460         return ret;
1461 }
1462
1463
1464 int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage)
1465 {
1466         MSG_MGR_BEGIN();
1467
1468         int noti_err = 0;
1469         msg_error_t msg_err = MSG_SUCCESS;
1470         char **db_res = NULL;
1471         int row_cnt = 0, col_cnt = 0;
1472
1473         switch (noti_info->type) {
1474         case MSG_MGR_NOTI_TYPE_NORMAL:
1475 #ifdef MSG_NOTI_INTEGRATION
1476         case MSG_MGR_NOTI_TYPE_CB:
1477         case MSG_MGR_NOTI_TYPE_SIM:
1478 #endif
1479     {
1480         int smsUnreadCnt = 0;
1481                 int mmsUnreadCnt = 0;
1482
1483                 char sqlQuery[MAX_QUERY_LEN     +1];
1484                 unsigned char mainType;
1485                 unsigned char subType;
1486                 int msgSize;
1487
1488                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1489 #ifdef MSG_NOTI_INTEGRATION
1490                 snprintf(sqlQuery, sizeof(sqlQuery), "DISTINCT "
1491                                 "A.ADDRESS_VAL, "
1492                                 "B.SUB_TYPE "
1493                                 "FROM %s A, %s B "
1494                                 "WHERE A.CONV_ID=B.CONV_ID "
1495                                 "AND B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
1496                                 "AND B.STORAGE_ID = %d "
1497                                 "GROUP BY A.ADDRESS_VAL "
1498                                 "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
1499                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1500                                 MSG_INBOX_ID, MSG_CBMSGBOX_ID,
1501                                 MSG_STORAGE_PHONE);
1502 #else
1503                 snprintf(sqlQuery, sizeof(sqlQuery), "DISTINCT "
1504                                 "A.ADDRESS_VAL, "
1505                                 "B.SUB_TYPE "
1506                                 "FROM %s A, %s B "
1507                                 "WHERE A.CONV_ID=B.CONV_ID "
1508                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1509                                 "AND B.STORAGE_ID = %d "
1510                                 "GROUP BY A.ADDRESS_VAL "
1511                                 "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
1512                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1513                                 MSG_INBOX_ID,
1514                                 MSG_STORAGE_PHONE);
1515 #endif
1516                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1517
1518                 row_cnt = 0, col_cnt = 0;
1519                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1520                 if (msg_err != MSG_SUCCESS) {
1521                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1522                         return -1;
1523                 }
1524
1525 /* contacts-service is not used for gear */
1526 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
1527                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo;
1528                 int normalAddCnt = 0;
1529                 int index = col_cnt;
1530
1531                 for (int i = 1; i <= row_cnt; i++) {
1532                         memset(&tmpAddressInfo, 0x00, sizeof(MSG_MGR_ADDRESS_INFO_S));
1533
1534                         char *address = db_res[index++];
1535                         normalAddCnt++;
1536                         if (address) {
1537                                 snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", address);
1538                                 if (_is_valid_email(address)) {
1539                                         tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
1540                                 } else {
1541                                         tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
1542                                 }
1543                         }
1544                         subType = atoi(db_res[index++]);
1545
1546                         MSG_MGR_CONTACT_INFO_S tmpContact;
1547                         memset(&tmpContact, 0x00, sizeof(MSG_MGR_CONTACT_INFO_S));
1548
1549                         MsgMgrGetContactInfo(&tmpAddressInfo, &tmpContact);
1550
1551                         if (row_cnt == 1) {
1552                                 snprintf(noti_info->imagePath, sizeof(noti_info->imagePath), "%s", tmpContact.imagePath);
1553                         }
1554
1555                         if (normalAddCnt > 1) {
1556                                 g_strlcat(noti_info->sender, ", ", sizeof(noti_info->sender)-strlen(noti_info->sender));
1557                         }
1558
1559                         if (tmpContact.firstName[0] != '\0') {
1560                                 g_strlcat(noti_info->sender, tmpContact.firstName, sizeof(noti_info->sender)-strlen(noti_info->sender));
1561                         } else if (tmpAddressInfo.addressVal[0] == '\0') {
1562                                 char *senderStr = NULL;
1563                                 senderStr = get_translate_text("message", MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
1564                                 g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1565                                 if (senderStr) {
1566                                         free(senderStr);
1567                                         senderStr = NULL;
1568                                 }
1569
1570                                 if (i == 1) {
1571                                         noti_info->active_noti_button_num = 1;
1572                                 }
1573                         } else {
1574                                 char *senderStr = NULL;
1575                                 if (subType == MSG_CB_SMS) {
1576                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, CB_MESSAGE);
1577                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1578                                         noti_info->active_noti_button_num = 1;
1579                                 } else if (subType == MSG_SYNCML_CP) {
1580                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, CP_MESSAGE);
1581                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1582                                         noti_info->active_noti_button_num = 1;
1583                                 } else if (subType == MSG_WAP_SI_SMS || subType == MSG_WAP_SL_SMS) {
1584                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, PUSH_MESSAGE);
1585                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1586                                         noti_info->active_noti_button_num = 1;
1587                                 } else {
1588                                         g_strlcat(noti_info->sender, tmpAddressInfo.addressVal, sizeof(noti_info->sender)-strlen(noti_info->sender));
1589                                 }
1590
1591                                 if (senderStr) {
1592                                         free(senderStr);
1593                                         senderStr = NULL;
1594                                 }
1595                         }
1596
1597                         if (i == 1) {
1598                                 noti_info->active_subtype = subType;
1599                                 snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->sender);
1600                                 snprintf(noti_info->imagePath, sizeof(noti_info->imagePath), "%s", tmpContact.imagePath);
1601                         }
1602                 }
1603
1604                 noti_info->senderCount = normalAddCnt;
1605 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
1606                 msg_db_free(msg_handle, db_res);
1607
1608                 MSG_MGR_SEC_DEBUG("sender info = [%s]", noti_info->sender);
1609
1610                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1611
1612 #ifdef MSG_NOTI_INTEGRATION
1613                 snprintf(sqlQuery, sizeof(sqlQuery),
1614                                 "A.ADDRESS_VAL, "
1615                                 "B.DISPLAY_TIME, "
1616                                 "B.MSG_ID, "
1617                                 "B.SUBJECT, "
1618                                 "B.MSG_TEXT, "
1619                                 "B.MAIN_TYPE, "
1620                                 "(COUNT(DISTINCT(CASE WHEN B.MAIN_TYPE = %d THEN B.MSG_ID END))) AS SMS_UNREAD_CNT, "
1621                                 "(COUNT(DISTINCT(CASE WHEN B.MAIN_TYPE = %d THEN B.MSG_ID END))) AS MMS_UNREAD_CNT, "
1622                                 "(CASE WHEN B.MAIN_TYPE = %d AND B.NETWORK_STATUS = %d THEN (SELECT C.MSG_SIZE FROM %s C WHERE B.MSG_ID = C.MSG_ID) ELSE -1 END) "
1623                                 "FROM %s A, %s B "
1624                                 "WHERE A.CONV_ID=B.CONV_ID "
1625                                 "AND B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
1626                                 "AND B.STORAGE_ID = %d "
1627                                 "ORDER BY B.DISPLAY_TIME DESC;",
1628                                 MSG_SMS_TYPE,
1629                                 MSG_MMS_TYPE,
1630                                 MSG_MMS_TYPE, MSG_NETWORK_RECEIVED, MMS_PLUGIN_MESSAGE_TABLE_NAME,
1631                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1632                                 MSG_INBOX_ID, MSG_CBMSGBOX_ID,
1633                                 MSG_STORAGE_PHONE);
1634 #else
1635                 snprintf(sqlQuery, sizeof(sqlQuery),
1636                                 "A.ADDRESS_VAL, "
1637                                 "B.DISPLAY_TIME, "
1638                                 "B.MSG_ID, "
1639                                 "B.SUBJECT, "
1640                                 "B.MSG_TEXT, "
1641                                 "B.MAIN_TYPE, "
1642                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT, "
1643                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS MMS_UNREAD_CNT "
1644                                 "FROM %s A, %s B "
1645                                 "WHERE A.CONV_ID=B.CONV_ID "
1646                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1647                                 "AND B.STORAGE_ID = %d "
1648                                 "ORDER BY B.DISPLAY_TIME DESC;",
1649                                 MSG_SMS_TYPE,
1650                                 MSG_MMS_TYPE,
1651                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1652                                 MSG_INBOX_ID,
1653                                 MSG_STORAGE_PHONE);
1654 #endif
1655                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1656
1657                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1658                 if (msg_err != MSG_SUCCESS) {
1659                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1660                         return -1;
1661                 }
1662
1663                 if (row_cnt > 0) {
1664                         smsUnreadCnt = atoi(db_res[col_cnt+6]);
1665                         mmsUnreadCnt = atoi(db_res[col_cnt+7]);
1666                         msgSize = atoi(db_res[col_cnt+8]);
1667
1668                         noti_info->count = smsUnreadCnt + mmsUnreadCnt;
1669
1670                         if (noti_info->count > 0) {
1671                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", db_res[col_cnt]);
1672
1673                                 noti_info->time = (time_t)atoi(db_res[col_cnt+1]);
1674
1675                                 noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]);
1676
1677                                 mainType = (unsigned char)atoi(db_res[col_cnt+5]);
1678
1679                                 if (mainType == MSG_MMS_TYPE) {
1680                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]);
1681                                         if (noti_info->text[0] == '\0') {
1682                                                 char *noti_text = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_NO_SUBJECT);
1683                                                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", noti_text);
1684                                                 g_free(noti_text);
1685                                         }
1686
1687                                         char *prefix_subject = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_SUBJECT_COLON);
1688                                         if (prefix_subject) {
1689                                                 snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s%s", prefix_subject, noti_info->text);
1690                                                 g_free(prefix_subject);
1691                                         } else {
1692                                                 snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->text);
1693                                         }
1694
1695                                         if (msgSize > -1) {
1696                                                 int kb_msg_size = msgSize / 1024;
1697                                                 if (kb_msg_size == 0 && msgSize > 0)
1698                                                         kb_msg_size = 1;
1699                                                 else if (msgSize % 1024 >= 512)
1700                                                         kb_msg_size++;
1701
1702                                                 char *msg_size_string = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_STRING);
1703                                                 char *msg_size_unit_kb = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_UNIT_KB);
1704
1705                                                 snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s : %d%s", msg_size_string, kb_msg_size, msg_size_unit_kb);
1706
1707                                                 g_free(msg_size_string);
1708                                                 g_free(msg_size_unit_kb);
1709                                         }
1710
1711                                 } else {
1712                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]);
1713                                 }
1714
1715                                 if (noti_info->active_text[0] == '\0')
1716                                         snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", db_res[col_cnt+4]);
1717
1718                                 MSG_MGR_DEBUG("unread message ID [%d].", noti_info->msg_id);
1719
1720                                 MSG_MGR_DEBUG("active sender [%s]", noti_info->active_sender);
1721                                 MSG_MGR_DEBUG("active subject [%s]", noti_info->active_subject);
1722                                 MSG_MGR_DEBUG("active text [%s]", noti_info->active_text);
1723
1724                                 if (!isForInstantMessage) {
1725                                         if (noti_info->id > 0 && noti_info->count == 1) {
1726                                                 noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, noti_info->id);
1727                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1728                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
1729                                                 }
1730
1731                                                 noti_info->id = 0;
1732                                                 if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0)
1733                                                         MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID");
1734                                         }
1735
1736                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, smsUnreadCnt);
1737                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, mmsUnreadCnt);
1738                                         MsgMgrInsertBadge(noti_info->count);
1739                                         MsgMgrSoundSetRepeatAlarm();
1740                                 }
1741                         } else {
1742                                 MSG_MGR_DEBUG("No unread message.");
1743                                 MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id);
1744
1745                                 msg_db_free(msg_handle, db_res);
1746
1747                                 if (!isForInstantMessage) {
1748                                         /* No unread message. */
1749                                         if (noti_info->id > 0) {
1750                                                 noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, noti_info->id);
1751                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1752                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
1753                                                 }
1754                                         }
1755
1756                                         noti_info->id = 0;
1757
1758                                         if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0)
1759                                                 MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID");
1760
1761                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, 0);
1762                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, 0);
1763                                         MsgMgrInsertBadge(0);
1764                                         MsgMgrSoundSetRepeatAlarm();
1765                                 }
1766
1767                                 return -1;
1768                         }
1769                 } else {
1770                         MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1771                         msg_db_free(msg_handle, db_res);
1772                         return -1;
1773                 }
1774
1775                 msg_db_free(msg_handle, db_res);
1776                 break;
1777         }
1778
1779 #ifndef MSG_NOTI_INTEGRATION
1780         case MSG_MGR_NOTI_TYPE_CB: {
1781                 char sqlQuery[MAX_QUERY_LEN+1];
1782                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1783
1784                 snprintf(sqlQuery, sizeof(sqlQuery),
1785                                 "A.ADDRESS_VAL, "
1786                                 "B.DISPLAY_TIME, "
1787                                 "B.MSG_ID, "
1788                                 "B.MSG_TEXT "
1789                                 "FROM %s A, %s B "
1790                                 "WHERE A.CONV_ID=B.CONV_ID "
1791                                 "AND B.READ_STATUS=0 "
1792                                 "AND B.FOLDER_ID=%d "
1793                                 "AND B.STORAGE_ID = %d "
1794                                 "ORDER BY B.DISPLAY_TIME DESC;",
1795                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1796                                 MSG_CBMSGBOX_ID,
1797                                 MSG_STORAGE_PHONE);
1798
1799                 if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
1800                         return MSG_ERR_DB_PREPARE;
1801
1802                 if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
1803                         MSG_ADDRESS_INFO_S addrInfo;
1804                         memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1805
1806                         if (dbhandler->columnText(0) != NULL)
1807                                 snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
1808
1809                         MSG_CONTACT_INFO_S tmpContact;
1810                         memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
1811
1812                         MsgGetContactInfo(&addrInfo, &tmpContact);
1813
1814                         if (tmpContact.firstName[0] != '\0') {
1815                                 snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
1816                         } else if (addrInfo.addressVal[0] == '\0') {
1817                                 char *senderStr = NULL;
1818                                 senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
1819                                 g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1820                                 if (senderStr) {
1821                                         free(senderStr);
1822                                         senderStr = NULL;
1823                                 }
1824                         } else {
1825                                 snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
1826                         }
1827
1828                         snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
1829
1830                         noti_info->time = (time_t)dbhandler->columnInt(1);
1831
1832                         noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
1833
1834                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
1835
1836                         MSG_MGR_DEBUG("unread CB message [%d].", noti_info->msg_id);
1837                 } else {
1838                         MSG_MGR_DEBUG("No unread CB message.");
1839                         MSG_MGR_DEBUG("notiCbId [%d]", noti_info->id);
1840
1841                         dbhandler->finalizeQuery();
1842
1843                         if (!isForInstantMessage) {
1844                                 /* No unread message. */
1845                                 if (noti_info->id > 0) {
1846                                         noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, noti_info->id);
1847                                         if (noti_err != NOTIFICATION_ERROR_NONE) {
1848                                                 MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
1849                                         }
1850                                 }
1851
1852                                 noti_info->id = 0;
1853
1854                                 if (MsgSettingSetInt(CB_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
1855                                         MSG_MGR_DEBUG("MsgSettingSetInt fail : CB_NOTI_PRIV_ID");
1856                         }
1857                         return MSG_ERR_DB_STEP;
1858                 }
1859
1860                 dbhandler->finalizeQuery();
1861
1862                 if (dbhandler->getTable(sqlQuery, &noti_info->count, NULL) != MSG_SUCCESS) {
1863                         MSG_MGR_DEBUG("getTable is failed");
1864                         dbhandler->freeTable();
1865                         return MSG_ERR_DB_GETTABLE;
1866                 }
1867
1868                 dbhandler->freeTable();
1869                 MSG_MGR_DEBUG("notiCbId [%d], unreadCbMsgCnt [%d]", noti_info->id, noti_info->count);
1870                 break;
1871         }
1872         case MSG_MGR_NOTI_TYPE_SIM: {
1873                 char sqlQuery[MAX_QUERY_LEN+1];
1874                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1875
1876                 snprintf(sqlQuery, sizeof(sqlQuery),
1877                                 "A.ADDRESS_VAL, "
1878                                 "B.DISPLAY_TIME, "
1879                                 "B.MSG_ID, "
1880                                 "B.MSG_TEXT, "
1881                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT "
1882                                 "FROM %s A, %s B "
1883                                 "WHERE A.CONV_ID=B.CONV_ID "
1884                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1885                                 "AND B.STORAGE_ID = %d "
1886                                 "ORDER BY B.DISPLAY_TIME DESC;",
1887                                 MSG_SMS_TYPE,
1888                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1889                                 MSG_INBOX_ID,
1890                                 MSG_STORAGE_SIM);
1891
1892                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1893
1894                 if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
1895                         return MSG_ERR_DB_PREPARE;
1896
1897                 if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
1898                         noti_info->count = dbhandler->columnInt(4);
1899
1900                         if (noti_info->count > 0) {
1901                                 MSG_ADDRESS_INFO_S addrInfo;
1902                                 memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1903
1904                                 if (dbhandler->columnText(0) != NULL)
1905                                         snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
1906
1907                                 MSG_CONTACT_INFO_S tmpContact;
1908                                 memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
1909
1910                                 MsgGetContactInfo(&addrInfo, &tmpContact);
1911
1912                                 if (tmpContact.firstName[0] != '\0') {
1913                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
1914                                 } else if (addrInfo.addressVal[0] == '\0') {
1915                                         char *senderStr = NULL;
1916                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
1917                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1918                                         if (senderStr) {
1919                                                 free(senderStr);
1920                                                 senderStr = NULL;
1921                                         }
1922                                 } else {
1923                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
1924                                 }
1925
1926                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
1927
1928                                 noti_info->time = (time_t)dbhandler->columnInt(1);
1929
1930                                 noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
1931
1932                                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
1933
1934                                 MSG_MGR_DEBUG("unread SIM message [%d].", noti_info->msg_id);
1935                         } else {
1936                                 MSG_MGR_DEBUG("No unread SIM message.");
1937                                 MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id);
1938
1939                                 dbhandler->finalizeQuery();
1940
1941                                 if (!isForInstantMessage) {
1942                                         /* No unread message. */
1943                                         if (noti_info->id > 0) {
1944                                                 noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, noti_info->id);
1945                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1946                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
1947                                                 }
1948                                         }
1949
1950                                         noti_info->id = 0;
1951
1952                                         if (MsgSettingSetInt(SIM_MSG_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
1953                                                 MSG_MGR_DEBUG("MsgSettingSetInt fail : SIM_MSG_NOTI_PRIV_ID");
1954                                 }
1955
1956                                 return MSG_ERR_DB_STEP;
1957                         }
1958                 } else {
1959                         MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1960                         dbhandler->finalizeQuery();
1961                         return MSG_ERR_DB_STEP;
1962                 }
1963
1964                 dbhandler->finalizeQuery();
1965                 break;
1966         }
1967 #endif
1968         case MSG_MGR_NOTI_TYPE_FAILED: {
1969                 char sqlQuery[MAX_QUERY_LEN+1];
1970                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1971
1972                 snprintf(sqlQuery, sizeof(sqlQuery),
1973                                 "A.ADDRESS_VAL, "
1974                                 "B.DISPLAY_TIME, "
1975                                 "B.MSG_ID, "
1976                                 "B.MSG_TEXT, "
1977                                 "B.SUBJECT, "
1978                                 "B.MAIN_TYPE, "
1979                                 "(COUNT(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END)) AS SENT_FAILED_CNT "
1980                                 "FROM %s A, %s B "
1981                                 "WHERE A.CONV_ID=B.CONV_ID "
1982                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1983                                 "AND B.STORAGE_ID = %d "
1984                                 "ORDER BY B.DISPLAY_TIME DESC;",
1985                                 MSG_NETWORK_SEND_FAIL,
1986                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1987                                 MSG_OUTBOX_ID,
1988                                 MSG_STORAGE_PHONE);
1989
1990                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1991
1992                 row_cnt = 0, col_cnt = 0;
1993                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1994                 if (msg_err != MSG_SUCCESS) {
1995                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1996                         return -1;
1997                 }
1998
1999                 if (row_cnt > 0) {
2000                         noti_info->count = atoi(db_res[col_cnt+6]);
2001
2002                         if (noti_info->count > 0) {
2003                                 MSG_MGR_ADDRESS_INFO_S addrInfo = {0,};
2004
2005                                 snprintf(addrInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", db_res[col_cnt]);
2006
2007                                 MSG_MGR_CONTACT_INFO_S tmpContact = {0,};
2008
2009                                 MsgMgrGetContactInfo(&addrInfo, &tmpContact);
2010
2011                                 if (tmpContact.firstName[0] != '\0') {
2012                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
2013                                 } else if (addrInfo.addressVal[0] == '\0') {
2014                                         char *senderStr = NULL;
2015                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
2016                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
2017                                         if (senderStr) {
2018                                                 free(senderStr);
2019                                                 senderStr = NULL;
2020                                         }
2021                                 } else {
2022                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
2023                                 }
2024
2025                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
2026
2027                                 noti_info->time = (time_t)atoi(db_res[col_cnt+1]);
2028
2029                                 noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]);
2030
2031                                 unsigned char mainType = (unsigned char)atoi(db_res[col_cnt+5]);
2032
2033                                 if (mainType == MSG_TYPE_MMS)
2034                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]);
2035                                 else
2036                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]);
2037
2038                                 MSG_MGR_DEBUG("Sent failed message ID [%d].", noti_info->msg_id);
2039
2040                                 if (!isForInstantMessage) {
2041                                         if (noti_info->id > 0 && noti_info->count == 1) {
2042                                                 noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, noti_info->id);
2043                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2044                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2045                                                 }
2046                                                 noti_info->id = 0;
2047                                                 if (vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_info->id) != 0)
2048                                                         MSG_MGR_DEBUG("vconf_set_int fail : MSG_SENTFAIL_NOTI_ID");
2049                                         }
2050                                 }
2051                         } else {
2052                                 MSG_MGR_DEBUG("No sent failed message.");
2053                                 MSG_MGR_DEBUG("failedNotiId [%d]", noti_info->id);
2054
2055                                 msg_db_free(msg_handle, db_res);
2056
2057                                 if (!isForInstantMessage) {
2058                                         /* No unread message. */
2059                                         if (noti_info->id > 0) {
2060                                                 noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, noti_info->id);
2061                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2062                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2063                                                 }
2064                                         }
2065
2066                                         noti_info->id = 0;
2067
2068                                         if (vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_info->id) != 0)
2069                                                 MSG_MGR_DEBUG("vconf_set_int fail : MSG_SENTFAIL_NOTI_ID");
2070                                 }
2071
2072                                 return -1;
2073                         }
2074                 } else {
2075                         msg_db_free(msg_handle, db_res);
2076                         return -1;
2077                 }
2078
2079                 msg_db_free(msg_handle, db_res);
2080                 break;
2081         }
2082         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2083                 break;
2084         default:
2085                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
2086                 return -1;
2087         }
2088
2089         MSG_MGR_END();
2090
2091         return 0;
2092 }
2093
2094
2095 notification_h getHandle(int *noti_id)
2096 {
2097         notification_h noti_h = NULL;
2098
2099         if (*noti_id > 0) {
2100                 MSG_MGR_DEBUG("Notification load");
2101                 noti_h = notification_load(NULL, *noti_id);
2102                 if (noti_h == NULL)
2103                         MSG_MGR_DEBUG("notification_load is failed.");
2104         }
2105
2106         if (noti_h == NULL) {
2107                 MSG_MGR_DEBUG("Notification create");
2108                 noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
2109                 if (noti_h == NULL) {
2110                         MSG_MGR_DEBUG("notification_create is failed.");
2111                         return NULL;
2112                 }
2113
2114                 *noti_id = 0;
2115         }
2116
2117         return noti_h;
2118 }
2119
2120
2121 int getPrivId(msg_mgr_notification_type_t noti_type, int sim_idx)
2122 {
2123         MSG_MGR_BEGIN();
2124
2125         int noti_id = 0;
2126
2127         switch (noti_type) {
2128 #ifdef MSG_NOTI_INTEGRATION
2129         case MSG_MGR_NOTI_TYPE_NORMAL:
2130         case MSG_MGR_NOTI_TYPE_SIM:
2131         case MSG_MGR_NOTI_TYPE_CB:
2132                 vconf_get_int(NOTIFICATION_PRIV_ID, &noti_id);
2133                 break;
2134 #else
2135         case MSG_MGR_NOTI_TYPE_NORMAL:
2136                 vconf_get_int(NOTIFICATION_PRIV_ID, &noti_id);
2137                 break;
2138         case MSG_MGR_NOTI_TYPE_SIM:
2139                 vconf_get_int(SIM_MSG_NOTI_PRIV_ID, &noti_id);
2140                 break;
2141         case MSG_MGR_NOTI_TYPE_CB:
2142                 vconf_get_int(CB_NOTI_PRIV_ID, &noti_id);
2143                 break;
2144 #endif
2145         case MSG_MGR_NOTI_TYPE_FAILED:
2146                 vconf_get_int(MSG_SENTFAIL_NOTI_ID, &noti_id);
2147                 break;
2148         case MSG_MGR_NOTI_TYPE_VOICE_1: {
2149                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2150                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
2151                 vconf_get_int(keyName, &noti_id);
2152                 break;
2153         }
2154         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2155                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2156                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
2157                 vconf_get_int(keyName, &noti_id);
2158                 break;
2159         }
2160         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2161                 vconf_get_int(SIM_FULL_NOTI_PRIV_ID, &noti_id);
2162                 break;
2163         default:
2164                 MSG_MGR_DEBUG("No matching noti type [%d]", noti_type);
2165                 break;
2166         }
2167
2168         MSG_MGR_DEBUG("Get noti type = %d, id = %d, sim_idx:%d", noti_type, noti_id, sim_idx);
2169
2170         MSG_MGR_END();
2171
2172         return noti_id;
2173 }
2174
2175
2176 void updatePrivId(msg_mgr_notification_type_t noti_type, int noti_id, int sim_idx)
2177 {
2178         MSG_MGR_BEGIN();
2179
2180         int err = 0;
2181
2182         MSG_MGR_DEBUG("Update noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
2183
2184         switch (noti_type) {
2185 #ifdef MSG_NOTI_INTEGRATION
2186         case MSG_MGR_NOTI_TYPE_NORMAL:
2187         case MSG_MGR_NOTI_TYPE_SIM:
2188         case MSG_MGR_NOTI_TYPE_CB:
2189                 err = vconf_set_int(NOTIFICATION_PRIV_ID, noti_id);
2190                 break;
2191 #else
2192         case MSG_MGR_NOTI_TYPE_NORMAL:
2193                 err = vconf_set_int(NOTIFICATION_PRIV_ID, noti_id);
2194                 break;
2195         case MSG_MGR_NOTI_TYPE_SIM:
2196                 err = vconf_set_int(SIM_MSG_NOTI_PRIV_ID, noti_id);
2197                 break;
2198         case MSG_MGR_NOTI_TYPE_CB:
2199                 err = vconf_set_int(CB_NOTI_PRIV_ID, noti_id);
2200                 break;
2201 #endif
2202         case MSG_MGR_NOTI_TYPE_FAILED:
2203                 err = vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_id);
2204                 break;
2205         case MSG_MGR_NOTI_TYPE_VOICE_1: {
2206                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2207                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
2208                 err = vconf_set_int(keyName, noti_id);
2209                 break;
2210         }
2211         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2212                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2213                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
2214                 err = vconf_set_int(keyName, noti_id);
2215                 break;
2216         }
2217         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2218                 err = vconf_set_int(SIM_FULL_NOTI_PRIV_ID, noti_id);
2219                 break;
2220         default:
2221                 MSG_MGR_DEBUG("No matching type [%d]", noti_type);
2222                 break;
2223         }
2224
2225         if (err != 0)
2226                 MSG_MGR_INFO("vconf_set_int fail : noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
2227
2228         MSG_MGR_END();
2229 }
2230
2231
2232 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info)
2233 {
2234         MSG_MGR_BEGIN();
2235
2236         if (msg_info) {
2237                 noti_info->id = getPrivId(noti_info->type, msg_info->sim_idx);
2238                 noti_info->msg_id = msg_info->msgId;
2239         } else {
2240                 MSG_MGR_DEBUG("msg_info is NULL");
2241                 return;
2242         }
2243
2244         noti_info->sim_idx = msg_info->sim_idx;
2245
2246         createServiceHandle(&noti_info->svc_h);
2247         char keyName[MAX_VCONFKEY_NAME_LEN];
2248
2249         switch (noti_info->type) {
2250         case MSG_MGR_NOTI_TYPE_VOICE_1:
2251         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2252                 memset(keyName, 0x00, sizeof(keyName));
2253                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, msg_info->sim_idx);
2254                 vconf_get_int(keyName, &noti_info->count);
2255                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2256                 noti_info->time = msg_info->displayTime;
2257
2258                 memset(keyName, 0x00, sizeof(keyName));
2259                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msg_info->sim_idx);
2260                 char *voiceNumber = vconf_get_str(keyName);
2261                 memset(keyName, 0x00, sizeof(keyName));
2262                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msg_info->sim_idx);
2263                 char *voiceAlphaId = vconf_get_str(keyName);
2264                 char *dialNumber = NULL;
2265
2266                 MSG_MGR_SEC_DEBUG("Voice mail server - alpha id = [%s], default num = [%s]", voiceAlphaId, voiceNumber);
2267
2268                 if (voiceNumber && strlen(voiceNumber))
2269                         dialNumber = voiceNumber;
2270
2271                 if (voiceAlphaId && strlen(voiceAlphaId) > 0) {
2272                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", voiceAlphaId);
2273                 } else if (dialNumber && strlen(dialNumber) > 0) {
2274                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", dialNumber);
2275                 }
2276
2277                 if (dialNumber && strlen(dialNumber) > 0)
2278                         snprintf(noti_info->number, sizeof(noti_info->number), "%s", dialNumber);
2279
2280                 if (noti_info->svc_h) {
2281                         setServiceOperation(noti_info->svc_h, APP_CONTROL_OPERATION_CALL);
2282                         setServiceUri(noti_info->svc_h, MSG_TEL_URI_VOICEMAIL);
2283
2284                         char slot_id[5] = {0, };
2285                         snprintf(slot_id, sizeof(slot_id), "%d", msg_info->sim_idx - 1);
2286                         addServiceExtraData(noti_info->svc_h, "slot_id", slot_id);
2287                 }
2288
2289                 if (voiceNumber)        g_free(voiceNumber);
2290                 if (voiceAlphaId) g_free(voiceAlphaId);
2291                 break;
2292         }
2293         case MSG_MGR_NOTI_TYPE_MWI:
2294         case MSG_MGR_NOTI_TYPE_CLASS0: {
2295                 noti_info->count = 1;
2296                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2297                 noti_info->time = msg_info->displayTime;
2298
2299                 if (msg_info->displayName[0] == '\0')
2300                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2301                 else
2302                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->displayName);
2303
2304                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2305
2306                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", msg_info->msgText);
2307
2308                 if (noti_info->type == MSG_MGR_NOTI_TYPE_MWI) {
2309                         if (noti_info->svc_h) {
2310                                 setServiceOperation(noti_info->svc_h, APP_CONTROL_OPERATION_CALL);
2311                                 setServiceUri(noti_info->svc_h, MSG_TEL_URI_VOICEMAIL);
2312
2313                                 char slot_id[5] = {0, };
2314                                 snprintf(slot_id, sizeof(slot_id), "%d", msg_info->sim_idx - 1);
2315                                 addServiceExtraData(noti_info->svc_h, "slot_id", slot_id);
2316                         }
2317
2318                 } else {
2319                         setServiceAppId(noti_info->svc_h, "org.tizen.msg-ui-class0");
2320                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2321                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2322                 }
2323                 break;
2324         }
2325         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT: {
2326                 noti_info->count = 1;
2327                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2328                 noti_info->time = msg_info->displayTime;
2329                 noti_info->extra_data = msg_info->networkStatus;
2330
2331 /* contacts-service is not used for gear */
2332 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
2333                 MSG_MGR_CONTACT_INFO_S contactInfo = {0,};
2334                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo = {0,};
2335                 if (msg_info->addressVal) {
2336                         snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", msg_info->addressVal);
2337                         if (_is_valid_email(msg_info->addressVal)) {
2338                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
2339                         } else {
2340                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
2341                         }
2342                 }
2343
2344                 if (MsgMgrGetContactInfo(&tmpAddressInfo, &contactInfo) != 0) {
2345                         MSG_MGR_WARN("MsgMgrGetContactInfo() fail.");
2346                 }
2347 #endif /*MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
2348
2349                 if (contactInfo.firstName[0] == '\0')
2350                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2351                 else
2352                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", contactInfo.firstName);
2353
2354                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2355
2356                 if (noti_info->msg_id > 0) {
2357                         setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2358                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2359                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2360                         addServiceExtraData(noti_info->svc_h, "address", msg_info->addressVal);
2361                 }
2362                 break;
2363         }
2364         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
2365         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
2366                 noti_info->count = 1;
2367                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2368                 noti_info->time = msg_info->displayTime;
2369
2370 /* contacts-service is not used for gear */
2371 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
2372                 MSG_MGR_CONTACT_INFO_S contactInfo = {0,};
2373                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo = {0,};
2374                 if (msg_info->addressVal) {
2375                         snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", msg_info->addressVal);
2376                         if (_is_valid_email(msg_info->addressVal)) {
2377                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
2378                         } else {
2379                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
2380                         }
2381                 }
2382
2383                 if (MsgMgrGetContactInfo(&tmpAddressInfo, &contactInfo) != 0) {
2384                         MSG_MGR_WARN("MsgMgrGetContactInfo() fail.");
2385                 }
2386 #endif /*MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
2387                 if (contactInfo.firstName[0] == '\0')
2388                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2389                 else
2390                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", contactInfo.firstName);
2391
2392                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2393
2394                 char sqlQuery[MAX_QUERY_LEN+1];
2395                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2396
2397                 int report_status_type;
2398                 int report_status_value;
2399
2400                 if (noti_info->type == MSG_MGR_NOTI_TYPE_MMS_READ_REPORT) {
2401                         report_status_type = MSG_REPORT_TYPE_READ;
2402                 } else {
2403                         report_status_type = MSG_REPORT_TYPE_DELIVERY;
2404                 }
2405
2406                 char *normalNum = NULL;
2407                 if (msg_info->addressVal[0] != '\0')
2408                         phone_number_get_normalized_number(msg_info->addressVal, &normalNum);
2409
2410                 snprintf(sqlQuery, sizeof(sqlQuery),
2411                                 "STATUS "
2412                                 "FROM %s "
2413                                 "WHERE MSG_ID=%d AND STATUS_TYPE=%d AND ADDRESS_VAL LIKE '%%%s';",
2414                                 MSGFW_REPORT_TABLE_NAME, msg_info->msgId, report_status_type, normalNum);
2415
2416                 MSG_MGR_DEBUG("sqlQuery = [%s]", sqlQuery);
2417
2418                 if (normalNum)
2419                         g_free(normalNum);
2420
2421                 char **db_res = NULL;
2422                 int row_cnt = 0, col_cnt = 0;
2423
2424                 int msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
2425                 if (msg_err != MSG_SUCCESS || row_cnt <= 0) {
2426                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
2427                         return;
2428                 }
2429
2430                 report_status_value = atoi(db_res[col_cnt]);
2431
2432                 MSG_MGR_DEBUG("report status [type = %d, value = %d]", report_status_type, report_status_value);
2433
2434                 msg_err = msg_db_free(msg_handle, db_res);
2435                 if (msg_err != MSG_SUCCESS) {
2436                         MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
2437                         return;
2438                 }
2439
2440                 if (noti_info->msg_id > 0) {
2441                         setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2442                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2443                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2444                         addServiceExtraData(noti_info->svc_h, "address", msg_info->addressVal);
2445                 }
2446
2447                 noti_info->extra_data = (unsigned char)report_status_value;
2448                 break;
2449         }
2450         default:
2451                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
2452                 break;
2453         }
2454
2455         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2456         MSG_MGR_END();
2457 }
2458
2459
2460 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, msg_mgr_active_notification_type_t active_noti)
2461 {
2462         MSG_MGR_BEGIN();
2463
2464         createServiceHandle(&noti_info->svc_h);
2465
2466         switch (noti_info->type) {
2467         case MSG_MGR_NOTI_TYPE_NORMAL: {
2468                 if (noti_info->count > 1) {
2469                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2470                 } else {
2471                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2472                 }
2473
2474                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2475                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2476                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2477                 addServiceExtraData(noti_info->svc_h, "http://tizen.org/appcontrol/data/notification", "new_message");
2478
2479                 noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER;
2480
2481                 if (noti_info->active_noti_button_num == 0)
2482                         noti_info->active_noti_button_num = 3;
2483                 break;
2484         }
2485         case MSG_MGR_NOTI_TYPE_CB: {
2486                 if (noti_info->count > 1) {
2487                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2488                 } else {
2489                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2490                 }
2491
2492                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2493                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2494                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2495
2496                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT)
2497                         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2498                 else
2499                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2500
2501                 noti_info->active_noti_button_num = 1;
2502                 break;
2503         }
2504         case MSG_MGR_NOTI_TYPE_SIM: {
2505                 if (noti_info->count > 1) {
2506                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2507                 } else {
2508                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2509                 }
2510
2511                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2512                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2513                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2514
2515                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT)
2516                         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2517                 else
2518                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2519
2520                 if (noti_info->active_noti_button_num == 0)
2521                         noti_info->active_noti_button_num = 3;
2522                 break;
2523         }
2524         case MSG_MGR_NOTI_TYPE_FAILED: {
2525                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2526
2527                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2528                 addServiceExtraData(noti_info->svc_h, "type", "send_failed_msg");
2529                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2530
2531                 noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER^NOTIFICATION_DISPLAY_APP_LOCK;
2532                 break;
2533         }
2534         case MSG_MGR_NOTI_TYPE_SIM_FULL: {
2535                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2536
2537                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2538                 addServiceExtraData(noti_info->svc_h, "sim_list_show", "sim_setting");
2539
2540                 noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2541                 break;
2542         }
2543         default:
2544                 break;
2545         }
2546
2547         if (active_noti != MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE)
2548                 noti_info->active_noti_button_num = 0;
2549
2550         MSG_MGR_END();
2551 }
2552
2553
2554 void createServiceHandle(app_control_h *svc_h)
2555 {
2556         int svc_err = APP_CONTROL_ERROR_NONE;
2557
2558         svc_err = app_control_create(svc_h);
2559
2560         if (svc_err != APP_CONTROL_ERROR_NONE)
2561                 MSG_MGR_DEBUG("app_control_create() is failed, [%d]", svc_err);
2562 }
2563
2564
2565 void setServiceAppId(app_control_h svc_h, const char* app_id)
2566 {
2567         int svc_err = APP_CONTROL_ERROR_NONE;
2568
2569         svc_err = app_control_set_app_id(svc_h, app_id);
2570
2571         if (svc_err != APP_CONTROL_ERROR_NONE)
2572                 MSG_MGR_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
2573 }
2574
2575
2576 void setServiceUri(app_control_h svc_h, const char* uri)
2577 {
2578         int svc_err = APP_CONTROL_ERROR_NONE;
2579
2580         svc_err = app_control_set_uri(svc_h, uri);
2581
2582         if (svc_err != APP_CONTROL_ERROR_NONE)
2583                 MSG_MGR_DEBUG("app_control_set_uri() was failed, [%d]", svc_err);
2584 }
2585
2586
2587 void setServiceOperation(app_control_h svc_h, const char* operation)
2588 {
2589         int svc_err = APP_CONTROL_ERROR_NONE;
2590
2591         svc_err = app_control_set_operation(svc_h, operation);
2592
2593         if (svc_err != APP_CONTROL_ERROR_NONE)
2594                 MSG_MGR_DEBUG("app_control_set_operation() was failed, [%d]", svc_err);
2595 }
2596
2597
2598 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, const char* bundle_val)
2599 {
2600         int svc_err = APP_CONTROL_ERROR_NONE;
2601
2602         svc_err = app_control_add_extra_data(svc_h, bundle_key, bundle_val);
2603
2604         if (svc_err != APP_CONTROL_ERROR_NONE)
2605                 MSG_MGR_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
2606 }
2607
2608
2609 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, int bundle_val)
2610 {
2611         int svc_err = APP_CONTROL_ERROR_NONE;
2612
2613         char tempId[10];
2614         memset(&tempId, 0x00, sizeof(tempId));
2615         snprintf(tempId, sizeof(tempId), "%d", bundle_val);
2616
2617         svc_err = app_control_add_extra_data(svc_h, bundle_key, (const char *)tempId);
2618
2619         if (svc_err != APP_CONTROL_ERROR_NONE)
2620                 MSG_MGR_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
2621 }
2622
2623
2624 void setServicePackageName(app_control_h svc_h, const char* pkg_name)
2625 {
2626         int svc_err = APP_CONTROL_ERROR_NONE;
2627
2628         svc_err = app_control_set_app_id(svc_h, pkg_name);
2629
2630         if (svc_err != APP_CONTROL_ERROR_NONE)
2631                 MSG_MGR_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
2632 }
2633
2634
2635 void sendServicelaunchRequest(app_control_h svc_h, app_control_reply_cb callback, void *user_data)
2636 {
2637         int svc_err = APP_CONTROL_ERROR_NONE;
2638
2639         svc_err = app_control_send_launch_request(svc_h, callback, user_data);
2640
2641         if (svc_err != APP_CONTROL_ERROR_NONE)
2642                 MSG_MGR_DEBUG("app_control_send_launch_request() is failed : %d", svc_err);
2643 }
2644
2645
2646 void setNotiTextDomain(notification_h noti_h, const char *pkg_name, const char *loc_dir)
2647 {
2648         int noti_err = NOTIFICATION_ERROR_NONE;
2649
2650         noti_err = notification_set_text_domain(noti_h, pkg_name, loc_dir);
2651         if (noti_err != NOTIFICATION_ERROR_NONE)
2652                 MSG_MGR_DEBUG("notification_set_text_domain() was failed. [%d]", noti_err);
2653 }
2654
2655
2656 void setNotiText(notification_h noti_h, notification_text_type_e type, const char *text, const char *key)
2657 {
2658         int noti_err = NOTIFICATION_ERROR_NONE;
2659
2660         noti_err = notification_set_text(noti_h, type, text, key, NOTIFICATION_VARIABLE_TYPE_NONE);
2661
2662         if (noti_err != NOTIFICATION_ERROR_NONE)
2663                 MSG_MGR_DEBUG("notification_set_text() was failed. [%d]", noti_err);
2664 }
2665
2666
2667 void setNotiTimeToText(notification_h noti_h, notification_text_type_e type, time_t time)
2668 {
2669         int noti_err = NOTIFICATION_ERROR_NONE;
2670
2671         noti_err = notification_set_time_to_text(noti_h, type, time);
2672
2673         if (noti_err != NOTIFICATION_ERROR_NONE)
2674                 MSG_MGR_DEBUG("notification_set_time_to_text() was failed. [%d]", noti_err);
2675 }
2676
2677
2678 void setNotiTime(notification_h noti_h, time_t time)
2679 {
2680         int noti_err = NOTIFICATION_ERROR_NONE;
2681
2682         noti_err = notification_set_time(noti_h, time);
2683
2684         if (noti_err != NOTIFICATION_ERROR_NONE)
2685                 MSG_MGR_DEBUG("notification_set_time() was failed. [%d]", noti_err);
2686 }
2687
2688
2689
2690 void setNotiImage(notification_h noti_h, notification_image_type_e type, const char *image_path)
2691 {
2692         int noti_err = NOTIFICATION_ERROR_NONE;
2693
2694         noti_err = notification_set_image(noti_h, type, image_path);
2695
2696         if (noti_err != NOTIFICATION_ERROR_NONE)
2697                 MSG_MGR_DEBUG("notification_set_image() was failed. [%d]", noti_err);
2698 }
2699
2700
2701 void setNotiSound(notification_h noti_h, notification_sound_type_e type, const char *path)
2702 {
2703         int noti_err = NOTIFICATION_ERROR_NONE;
2704
2705         noti_err = notification_set_sound(noti_h, type, path);
2706
2707         if (noti_err != NOTIFICATION_ERROR_NONE)
2708                 MSG_MGR_DEBUG("notification_set_sound() was failed. [%d]", noti_err);
2709 }
2710
2711
2712 void setNotiVibration(notification_h noti_h, notification_vibration_type_e type, const char *path)
2713 {
2714         int noti_err = NOTIFICATION_ERROR_NONE;
2715
2716         noti_err = notification_set_vibration(noti_h, type, path);
2717
2718         if (noti_err != NOTIFICATION_ERROR_NONE)
2719                 MSG_MGR_DEBUG("notification_set_vibration() was failed. [%d]", noti_err);
2720 }
2721
2722
2723 void setNotiEventHandler(notification_h noti_h, notification_event_type_e type, app_control_h event_handler)
2724 {
2725         int noti_err = NOTIFICATION_ERROR_NONE;
2726
2727         noti_err = notification_set_event_handler(noti_h, type, event_handler);
2728
2729         if (noti_err != NOTIFICATION_ERROR_NONE)
2730                 MSG_MGR_DEBUG("notification_set_event_handler() was failed. [%d]", noti_err);
2731 }
2732
2733
2734 int MsgMgrInsertInstantMessage(msg_mgr_notification_type_t noti_type)
2735 {
2736         MSG_MGR_BEGIN();
2737
2738         char *notiMsg = NULL;
2739
2740         notification_h noti = notification_create(NOTIFICATION_TYPE_NOTI);
2741
2742         switch (noti_type) {
2743         case MSG_MGR_NOTI_TYPE_NORMAL:
2744         case MSG_MGR_NOTI_TYPE_SIM:
2745         case MSG_MGR_NOTI_TYPE_CB: {
2746                 MSG_MGR_NOTI_INFO_S noti_info;
2747                 memset(&noti_info, 0x00, sizeof(MSG_MGR_NOTI_INFO_S));
2748
2749                 noti_info.type = noti_type;
2750                 int err = getLatestMsgInfo(&noti_info, true);
2751
2752                 if (err == 0) {
2753                         MSG_MGR_DEBUG("Unread count [%d]", noti_info.count);
2754                         if (noti_info.count == 1) {
2755                                 MSG_MGR_SEC_DEBUG("noti_info.sender [%s]", noti_info.sender);
2756                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, noti_info.sender, NULL);
2757                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.text, NULL);
2758                         } else if (noti_info.count > 1) {
2759                                 gchar *cnt_string = g_strdup_printf("%i", noti_info.count);
2760
2761                                 notiMsg = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, NEW_MESSAGE);
2762                                 gchar *outString = g_strconcat(cnt_string, " ", notiMsg, NULL);
2763                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, outString, NULL);
2764                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.sender, NULL);
2765                                 g_free(outString);
2766                                 g_free(cnt_string);
2767                         }
2768
2769                         setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
2770                 }
2771                 break;
2772         }
2773         case MSG_MGR_NOTI_TYPE_FAILED: {
2774                 notiMsg = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, FAILED_TO_SEND_MESSAGE);
2775                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, notiMsg, NULL);
2776                 setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SMS_SENDING_FAILED_ICON_PATH);
2777                 break;
2778         }
2779         default:
2780                 MSG_MGR_DEBUG("No matching type for MsgNotiType%d]", noti_type);
2781                 goto _END_OF_INSTANT_NOTI;
2782                 break;
2783         }
2784
2785         if (notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER) != NOTIFICATION_ERROR_NONE)
2786                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
2787
2788         if (notification_post(noti) != NOTIFICATION_ERROR_NONE)
2789                 MSG_MGR_DEBUG("Fail to notification_post");
2790
2791 _END_OF_INSTANT_NOTI:
2792
2793         if (notification_delete(noti) != NOTIFICATION_ERROR_NONE)
2794                 MSG_MGR_DEBUG("Fail to notification_delete");
2795         if (notiMsg) {
2796                 free(notiMsg);
2797                 notiMsg = NULL;
2798         }
2799
2800         if (noti) {
2801                 if (notification_free(noti) != NOTIFICATION_ERROR_NONE)
2802                         MSG_MGR_DEBUG("Fail to notification_free");
2803                 noti = NULL;
2804         }
2805
2806         MSG_MGR_END();
2807         return 0;
2808 }
2809
2810
2811 int MsgMgrInsertBadge(unsigned int unreadMsgCnt)
2812 {
2813         MSG_MGR_DEBUG("Start to set badge to [%d].", unreadMsgCnt);
2814
2815         int err = BADGE_ERROR_NONE;
2816         bool exist = false;
2817
2818         err = badge_is_existing(MSG_DEFAULT_APP_ID, &exist);
2819
2820         if (err != BADGE_ERROR_NONE) {
2821                 MSG_MGR_ERR("Fail to badge_is_existing : %d", err);
2822                 return -1;
2823         }
2824
2825         if (!exist) {
2826                 /* create badge */
2827                 err = badge_add(MSG_DEFAULT_APP_ID);
2828                 if (err != BADGE_ERROR_NONE) {
2829                         MSG_MGR_ERR("Fail to badge_add : %d", err);
2830                         return -1;
2831                 }
2832         }
2833
2834         err = badge_set_count(MSG_DEFAULT_APP_ID, unreadMsgCnt);
2835
2836         if (err != BADGE_ERROR_NONE) {
2837                 MSG_MGR_ERR("Fail to badge_set_count : %d", err);
2838                 return -1;
2839         }
2840
2841         return 0;
2842 }
2843
2844
2845 void MsgMgrNotiSoundRepeatAlarmCB(int alarmId)
2846 {
2847         MSG_MGR_BEGIN();
2848
2849         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_NORMAL, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
2850
2851 #ifndef MSG_NOTI_INTEGRATION
2852         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_SIM, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
2853         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_CB, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
2854 #endif
2855
2856         MSG_MGR_END();
2857         return;
2858 }
2859
2860
2861 void MsgMgrSoundCreateRepeatAlarm(int RepeatTime)
2862 {
2863         MSG_MGR_BEGIN();
2864
2865         int tmpAlarmId = 0;
2866         time_t tmp_time;
2867         struct tm repeat_tm;
2868
2869         time(&tmp_time);
2870
2871         tmp_time += (RepeatTime*60);
2872         tzset();
2873         localtime_r(&tmp_time, &repeat_tm);
2874
2875         if (MsgMgrAlarmRegistration(&repeat_tm, MsgMgrNotiSoundRepeatAlarmCB, &tmpAlarmId) != 0) {
2876                 MSG_MGR_DEBUG("MsgAlarmRegistration fail.");
2877                 return;
2878         }
2879
2880         g_alarmId = tmpAlarmId;
2881         MSG_MGR_DEBUG("Set alarmId to [%d]", g_alarmId);
2882
2883         MSG_MGR_END();
2884
2885         return;
2886 }
2887
2888
2889 void MsgMgrSoundSetRepeatAlarm()
2890 {
2891         int nRepeatValue = 0;
2892         long nRepeatTime = 0;
2893
2894         if (vconf_get_int(MSG_ALERT_REP_TYPE, &nRepeatValue) != 0) {
2895                 MSG_MGR_INFO("vconf_get_int() is failed");
2896         }
2897
2898         switch (nRepeatValue) {
2899         case MSG_ALERT_TONE_ONCE:
2900                 nRepeatTime = 0;
2901                 break;
2902         case MSG_ALERT_TONE_2MINS:
2903                 nRepeatTime = 2;
2904                 break;
2905         case MSG_ALERT_TONE_5MINS:
2906                 nRepeatTime = 5;
2907                 break;
2908         case MSG_ALERT_TONE_10MINS:
2909                 nRepeatTime = 10;
2910                 break;
2911         default:
2912                 MSG_MGR_DEBUG("Invalid Repetition time");
2913                 break;
2914         }
2915
2916         MSG_MGR_DEBUG("nRepeatTime = %d", nRepeatTime);
2917
2918         if (nRepeatTime > 0) {
2919                 if (g_alarmId > 0) {
2920                         if (MsgMgrAlarmRemove(g_alarmId) != 0) {
2921                                 MSG_MGR_FATAL("MsgAlarmRemove fail.");
2922                         }
2923                         g_alarmId = 0;
2924                 }
2925                 MsgMgrSoundCreateRepeatAlarm(nRepeatTime);
2926         }
2927
2928         return;
2929 }
2930
2931
2932 char *get_translate_text(const char *pkg_name, const char *locale_dir, const char *text)
2933 {
2934         char *notiMsg = NULL;
2935         char *lang = NULL;
2936
2937         lang = vconf_get_str(VCONFKEY_LANGSET);
2938
2939         setlocale(LC_MESSAGES, lang);
2940
2941         bindtextdomain(pkg_name, locale_dir);
2942
2943         notiMsg = dgettext(pkg_name, text);
2944
2945         if (lang) {
2946                 free(lang);
2947                 lang = NULL;
2948         }
2949
2950         return g_strdup(notiMsg);
2951 }
2952