Tizen 2.1 base
[platform/core/api/notification.git] / src / notification.c
1 /*
2  *  libnotification
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>, Youngsub Ko <ys4610.ko@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <libintl.h>
28 #include <dbus/dbus.h>
29 #include <dbus/dbus-glib-lowlevel.h>
30
31 #include <aul.h>
32 #include <ail.h>
33 #include <appsvc.h>
34 #include <vconf-keys.h>
35 #include <vconf.h>
36
37 #include <notification.h>
38 #include <notification_list.h>
39 #include <notification_debug.h>
40 #include <notification_internal.h>
41 #include <notification_noti.h>
42 #include <notification_ongoing.h>
43 #include <notification_group.h>
44
45 typedef struct _notification_cb_list notification_cb_list_s;
46
47 typedef enum __notification_cb_type {
48         NOTIFICATION_CB_NORMAL = 1,
49         NOTIFICATION_CB_DETAILED,
50 } _notification_cb_type_e;
51
52 struct _notification_cb_list {
53         notification_cb_list_s *prev;
54         notification_cb_list_s *next;
55
56         _notification_cb_type_e cb_type;
57         void (*changed_cb) (void *data, notification_type_e type);
58         void (*detailed_changed_cb) (void *data, notification_type_e type, notification_op *op_list, int num_op);
59         void *data;
60 };
61
62 static notification_cb_list_s *g_notification_cb_list = NULL;
63 static DBusConnection *g_dbus_handle;
64
65 #define NOTI_TEXT_RESULT_LEN 2048
66 #define NOTI_PKGNAME_LEN        512
67 #define NOTI_CHANGED_NOTI       "notification_noti_changed"
68 #define NOTI_CHANGED_ONGOING    "notification_ontoing_changed"
69
70 #define NOTI_DBUS_BUS_NAME      "org.tizen.libnotification"
71 #define NOTI_DBUS_PATH          "/org/tizen/libnotification"
72 #define NOTI_DBUS_INTERFACE     "org.tizen.libnotification.signal"
73
74 static char *_notification_get_pkgname_by_pid(void)
75 {
76         char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
77         char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
78         int pid = 0, ret = AUL_R_OK;
79         int fd;
80
81         pid = getpid();
82
83         ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
84         if (ret != AUL_R_OK) {
85                 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
86
87                 fd = open(buf, O_RDONLY);
88                 if (fd < 0) {
89                         return NULL;
90                 }
91
92                 ret = read(fd, pkgname, sizeof(pkgname) - 1);
93                 if (ret <= 0) {
94                         close(fd);
95                         return NULL;
96                 }
97
98                 if (ret > NOTI_PKGNAME_LEN)
99                         pkgname[NOTI_PKGNAME_LEN] = '\0';
100                 else
101                         pkgname[ret] = '\0';
102
103                 close(fd);
104         }
105
106         if (strlen(pkgname) <= 0) {
107                 return NULL;
108         } else {
109                 return strdup(pkgname);
110         }
111 }
112
113 static void _notification_pack_operation_msg(DBusMessageIter *iter, notification_op *op_list, int op_num)
114 {
115         int i = 0;
116
117         if (op_list == NULL) {
118                 int tmp_op_num = 0;
119
120                 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &tmp_op_num);
121                 return ;
122         }
123
124         dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &op_num);
125         for (i = 0; i < op_num; i++) {
126                 NOTIFICATION_ERR("pack:%d/%d", i, op_num);
127                 notification_op *op = op_list + i;
128                 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(op->type));
129                 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(op->priv_id));
130                 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(op->extra_info_1));
131                 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(op->extra_info_2));
132         }
133 }
134
135 static void _notification_unpack_operation_msg(DBusMessageIter *iter, notification_op **op_list, int *op_num)
136 {
137         int i = 0;
138
139         if (iter == NULL || op_list == NULL || op_num == NULL) {
140                 return;
141         }
142
143         dbus_message_iter_get_basic(iter, op_num);
144
145         int tmp_op_num = *op_num;
146
147         if (tmp_op_num <= 0) {
148                 *op_list = NULL;
149                 *op_num = 0;
150                 return;
151         }
152
153         *op_list = (notification_op*)malloc(sizeof(notification_op) * (tmp_op_num));
154
155         dbus_message_iter_next(iter);
156
157         if (*op_list != NULL) {
158                 for (i = 0; i < tmp_op_num; i++) {
159                         notification_op *op = (*op_list) + i;
160                         dbus_message_iter_get_basic(iter, &(op->type));
161                         dbus_message_iter_next(iter);
162                         dbus_message_iter_get_basic(iter, &(op->priv_id));
163                         dbus_message_iter_next(iter);
164                         dbus_message_iter_get_basic(iter, &(op->extra_info_1));
165                         dbus_message_iter_next(iter);
166                         dbus_message_iter_get_basic(iter, &(op->extra_info_2));
167                         dbus_message_iter_next(iter);
168                 }
169         }
170 }
171
172 static char *_notification_get_icon(const char *package)
173 {
174         ail_appinfo_h handle;
175         ail_error_e ret;
176         char *str = NULL;
177         char *icon = NULL;
178
179         ret = ail_package_get_appinfo(package, &handle);
180         if (ret != AIL_ERROR_OK) {
181                 return NULL;
182         }
183
184         ret = ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &str);
185         if (ret != AIL_ERROR_OK) {
186                 ail_package_destroy_appinfo(handle);
187                 return NULL;
188         }
189
190         icon = strdup(str);
191
192         ret = ail_package_destroy_appinfo(handle);
193         if (ret != AIL_ERROR_OK) {
194                 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
195         }
196
197         return icon;
198 }
199
200 static char *_notification_get_name(const char *package)
201 {
202         ail_appinfo_h handle;
203         ail_error_e ret;
204         char *str = NULL;
205         char *name = NULL;
206
207         ret = ail_package_get_appinfo(package, &handle);
208         if (ret != AIL_ERROR_OK) {
209                 return NULL;
210         }
211
212         ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
213         if (ret != AIL_ERROR_OK) {
214                 ail_package_destroy_appinfo(handle);
215                 return NULL;
216         }
217
218         name = strdup(str);
219
220         ret = ail_package_destroy_appinfo(handle);
221         if (ret != AIL_ERROR_OK) {
222                 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
223         }
224
225         return name;
226 }
227
228 static void _notification_get_text_domain(notification_h noti)
229 {
230         if (noti->domain != NULL) {
231
232         }
233
234         if (noti->dir != NULL) {
235
236         }
237 }
238
239 static void _notification_chagned_noti_cb(DBusMessage *message, void *data)
240 {
241         notification_cb_list_s *noti_cb_list = NULL;
242         DBusMessageIter iter;
243
244         int op_num = 0;
245         notification_op *op_list = NULL;
246
247         if (g_notification_cb_list == NULL) {
248                 return;
249         }
250
251         noti_cb_list = g_notification_cb_list;
252
253         while (noti_cb_list->prev != NULL) {
254                 noti_cb_list = noti_cb_list->prev;
255         }
256
257         if (message != NULL) {
258                 if (dbus_message_iter_init(message, &iter)) {
259                         _notification_unpack_operation_msg(&iter, &op_list, &op_num);
260                         NOTIFICATION_ERR("operation num:%d", op_num);
261                 }
262         }
263
264         while (noti_cb_list != NULL) {
265                 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
266                         noti_cb_list->changed_cb(noti_cb_list->data,
267                                                  NOTIFICATION_TYPE_NOTI);
268                 }
269                 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
270                         noti_cb_list->detailed_changed_cb(noti_cb_list->data,
271                                                  NOTIFICATION_TYPE_NOTI, op_list, op_num);
272                 }
273
274                 noti_cb_list = noti_cb_list->next;
275         }
276
277         if (op_list != NULL) {
278                 free(op_list);
279         }
280 }
281
282 #if 0
283 static void _notification_chagned_ongoing_cb(void *data)
284 {
285         notification_cb_list_s *noti_cb_list = NULL;
286
287         if (g_notification_cb_list == NULL) {
288                 return;
289         }
290
291         noti_cb_list = g_notification_cb_list;
292
293         while (noti_cb_list->prev != NULL) {
294                 noti_cb_list = noti_cb_list->prev;
295         }
296
297         while (noti_cb_list != NULL) {
298                 if (noti_cb_list->changed_cb) {
299                         noti_cb_list->changed_cb(noti_cb_list->data,
300                                                  NOTIFICATION_TYPE_ONGOING);
301                 }
302
303                 noti_cb_list = noti_cb_list->next;
304         }
305 }
306 #endif
307
308 static void _notification_pack_and_send_dbus_message(const char *type, notification_op *op_list , int op_num)
309 {
310         DBusConnection *connection = NULL;
311         DBusMessage *message = NULL;
312         DBusMessageIter iter;
313         DBusError err;
314         dbus_bool_t ret;
315         int i = 0;
316
317         if (!type) {
318                 NOTIFICATION_ERR("type is NULL");
319                 return;
320         }
321
322         dbus_error_init(&err);
323         connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
324         if (!connection) {
325                 NOTIFICATION_ERR("Fail to dbus_bus_get : %s", err.message);
326                 return;
327         }
328
329         message = dbus_message_new_signal(NOTI_DBUS_PATH,
330                                 NOTI_DBUS_INTERFACE,
331                                 type);
332
333         if (!message) {
334                 NOTIFICATION_ERR("fail to create dbus message");
335                 goto release_n_return;
336         }
337
338         if (op_num > 0 && op_list != NULL) {
339                 dbus_message_iter_init_append(message, &iter);
340                 _notification_pack_operation_msg(&iter, op_list, op_num);
341         }
342
343         ret = dbus_connection_send(connection, message, NULL);
344         if (!ret) {
345                 NOTIFICATION_ERR("fail to send dbus message : %s", type);
346                 goto release_n_return;
347         }
348
349         dbus_connection_flush(connection);
350
351         NOTIFICATION_DBG("success to emit signal [%s]", type);
352
353 release_n_return:
354         dbus_error_free(&err);
355
356         if (message)
357                 dbus_message_unref(message);
358
359         if (connection)
360                 dbus_connection_unref(connection);
361 }
362
363 #define SET_DBUS_MESSAGE 30
364
365 static void _notification_changed(const char *type, notification_op *op_list , int op_num)
366 {
367         int set = 0;
368         int set_total = 0;
369         int set_modular = 0;
370
371         if (op_num <= SET_DBUS_MESSAGE) {
372                 _notification_pack_and_send_dbus_message(type, op_list, op_num);
373         } else {
374                 set_total = op_num / SET_DBUS_MESSAGE;
375                 set_modular = op_num - (set_total * SET_DBUS_MESSAGE);
376
377                 for (set = 0; set < set_total; set++) {
378                         _notification_pack_and_send_dbus_message(type, op_list + (set * SET_DBUS_MESSAGE), SET_DBUS_MESSAGE);
379                 }
380
381                 if (set_modular > 0) {
382                         _notification_pack_and_send_dbus_message(type,
383                                         op_list + (set_total * SET_DBUS_MESSAGE), set_modular);
384                 }
385         }
386 }
387
388 static DBusHandlerResult _dbus_signal_filter(DBusConnection *conn,
389                 DBusMessage *msg, void *user_data)
390 {
391         const char *interface = NULL;
392         
393         interface = dbus_message_get_interface(msg);
394         NOTIFICATION_DBG("path : %s", dbus_message_get_path(msg));
395         NOTIFICATION_DBG("interface : %s", interface);
396
397         if (strcmp(NOTI_DBUS_INTERFACE, interface))
398                 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
399
400
401         switch (dbus_message_get_type(msg)) {
402                 case DBUS_MESSAGE_TYPE_SIGNAL:
403                         _notification_chagned_noti_cb(msg, NULL);
404                         return DBUS_HANDLER_RESULT_HANDLED;
405                 default:
406                         break;
407         }
408         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
409 }
410
411 static DBusConnection *_noti_changed_monitor_init()
412 {
413         DBusError err;
414         DBusConnection *conn = NULL;
415         char rule[1024];
416
417         dbus_error_init(&err);
418         conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
419         if (!conn) {
420                 printf("fail to get bus\n");
421                 return NULL;
422         }
423         dbus_connection_setup_with_g_main(conn, NULL);
424         snprintf(rule, 1024, 
425                 "path='%s',type='signal',interface='%s',member='%s'",
426                 NOTI_DBUS_PATH, 
427                 NOTI_DBUS_INTERFACE,
428                 NOTI_CHANGED_NOTI);
429
430         dbus_bus_add_match(conn, rule, &err);
431         if (dbus_connection_add_filter(conn,_dbus_signal_filter, 
432                                         NULL, NULL) == FALSE) {
433                 NOTIFICATION_ERR("fail to dbus_connection_add_filter");
434                 dbus_connection_close(conn);
435                 return NULL;
436         }
437
438         dbus_connection_set_exit_on_disconnect(conn, FALSE);
439         return conn;
440 }
441
442 static void _noti_chanaged_monitor_fini()
443 {
444         DBusConnection *conn = g_dbus_handle;
445         char rule[1024];
446
447         if (!conn)
448                 return;
449         dbus_connection_remove_filter(conn, _dbus_signal_filter, NULL);
450
451         snprintf(rule, 1024, 
452                 "path='%s',type='signal',interface='%s',member='%s'",
453                 NOTI_DBUS_PATH, 
454                 NOTI_DBUS_INTERFACE,
455                 NOTI_CHANGED_NOTI);
456         dbus_bus_remove_match(conn, rule, NULL);
457
458         dbus_connection_close(conn);
459         g_dbus_handle = NULL;
460 }       
461
462 notification_op *_notification_make_basic_op(notification_op_type_e type, int num_op, int *list_priv_id, int num_priv_id)
463 {
464         int i = 0;
465         notification_op *op_list = NULL;
466
467         if (num_op <= 0) {
468                 return NULL;
469         }
470
471         op_list = (notification_op *)malloc(sizeof(notification_op) * num_op);
472         memset(op_list, 0x0, sizeof(notification_op) * num_op);
473
474         for (i = 0; i < num_priv_id; i++) {
475                 (op_list + i)->type = type;
476                 if (list_priv_id != NULL) {
477                         (op_list + i)->priv_id = *(list_priv_id + i);
478                 }
479         }
480
481         return op_list;
482 }
483
484 /* notification_set_icon will be removed */
485 EXPORT_API notification_error_e notification_set_icon(notification_h noti,
486                                                       const char *icon_path)
487 {
488         int ret_err = NOTIFICATION_ERROR_NONE;
489
490         ret_err =
491             notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
492                                    icon_path);
493
494         return ret_err;
495 }
496
497 /* notification_get_icon will be removed */
498 EXPORT_API notification_error_e notification_get_icon(notification_h noti,
499                                                       char **icon_path)
500 {
501         int ret_err = NOTIFICATION_ERROR_NONE;
502         char *ret_image_path = NULL;
503
504         ret_err =
505             notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
506                                    &ret_image_path);
507
508         if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
509                 *icon_path = ret_image_path;
510
511                 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
512         }
513
514         return ret_err;
515 }
516
517 EXPORT_API notification_error_e notification_set_image(notification_h noti,
518                                                        notification_image_type_e type,
519                                                        const char *image_path)
520 {
521         bundle *b = NULL;
522         char buf_key[32] = { 0, };
523         const char *ret_val = NULL;
524
525         /* Check noti and image_path are valid data */
526         if (noti == NULL || image_path == NULL) {
527                 return NOTIFICATION_ERROR_INVALID_DATA;
528         }
529
530         /* Check image type is valid type */
531         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
532             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
533                 return NOTIFICATION_ERROR_INVALID_DATA;
534         }
535
536         /* Check image path bundle is exist */
537         if (noti->b_image_path) {
538                 /* If image path bundle is exist, store local bundle value */
539                 b = noti->b_image_path;
540
541                 /* Set image type to key as char string type */
542                 snprintf(buf_key, sizeof(buf_key), "%d", type);
543
544                 /* Get value using key */
545                 ret_val = bundle_get_val(b, buf_key);
546                 if (ret_val != NULL) {
547                         /* If key is exist, remove this value to store new image path */
548                         bundle_del(b, buf_key);
549                 }
550
551                 /* Add new image path with type key */
552                 bundle_add(b, buf_key, image_path);
553         } else {
554                 /* If image path bundle is not exist, create new one */
555                 b = bundle_create();
556
557                 /* Set image type to key as char string type */
558                 snprintf(buf_key, sizeof(buf_key), "%d", type);
559
560                 /* Add new image path with type key */
561                 bundle_add(b, buf_key, image_path);
562
563                 /* Save to image path bundle */
564                 noti->b_image_path = b;
565         }
566
567         return NOTIFICATION_ERROR_NONE;
568 }
569
570 EXPORT_API notification_error_e notification_get_image(notification_h noti,
571                                                        notification_image_type_e type,
572                                                        char **image_path)
573 {
574         bundle *b = NULL;
575         char buf_key[32] = { 0, };
576         const char *ret_val = NULL;
577         const char *pkgname = NULL;
578
579         /* Check noti and image_path is valid data */
580         if (noti == NULL || image_path == NULL) {
581                 return NOTIFICATION_ERROR_INVALID_DATA;
582         }
583
584         /* Check image type is valid data */
585         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
586             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
587                 return NOTIFICATION_ERROR_INVALID_DATA;
588         }
589
590         /* Check image path bundle exist */
591         if (noti->b_image_path) {
592                 /* If image path bundle exist, store local bundle data */
593                 b = noti->b_image_path;
594
595                 /* Set image type to key as char string type */
596                 snprintf(buf_key, sizeof(buf_key), "%d", type);
597
598                 /* Get value of key */
599                 ret_val = bundle_get_val(b, buf_key);
600
601                 *image_path = (char *)ret_val;
602         } else {
603                 /* If image path bundle does not exist, image path is NULL */
604                 *image_path = NULL;
605         }
606
607         /* If image path is NULL and type is ICON, icon path set from AIL */
608         /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
609         if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
610                 /* Check App icon path is already set */
611                 if (noti->app_icon_path != NULL) {
612                         /* image path will be app icon path */
613                         *image_path = noti->app_icon_path;
614                 } else {
615                         /* Get image path using launch_pkgname */
616                         if (noti->launch_pkgname != NULL) {
617                                 noti->app_icon_path =
618                                     _notification_get_icon(noti->launch_pkgname);
619                         }
620
621                         /* If app icon path is NULL, get image path using caller_pkgname */
622                         if (noti->app_icon_path == NULL
623                             && noti->caller_pkgname != NULL) {
624                                 noti->app_icon_path =
625                                     _notification_get_icon(noti->caller_pkgname);
626                         }
627
628                         /* If app icon path is NULL, get image path using service data */
629                         if (noti->app_icon_path == NULL
630                             && noti->b_service_single_launch != NULL) {
631                                 pkgname =
632                                     appsvc_get_pkgname(noti->b_service_single_launch);
633                                 if (pkgname != NULL) {
634                                         noti->app_icon_path =
635                                             _notification_get_icon(pkgname);
636                                 }
637                         }
638
639                         *image_path = noti->app_icon_path;
640                 }
641         }
642
643         return NOTIFICATION_ERROR_NONE;
644 }
645
646 EXPORT_API notification_error_e notification_set_time(notification_h noti,
647                                                       time_t input_time)
648 {
649         /* Check noti is valid data */
650         if (noti == NULL) {
651                 return NOTIFICATION_ERROR_INVALID_DATA;
652         }
653
654         if (input_time == 0) {
655                 /* If input time is 0, set current time */
656                 noti->time = time(NULL);
657         } else {
658                 /* save input time */
659                 noti->time = input_time;
660         }
661
662         return NOTIFICATION_ERROR_NONE;
663 }
664
665 EXPORT_API notification_error_e notification_get_time(notification_h noti,
666                                                       time_t * ret_time)
667 {
668         /* Check noti and time is valid data */
669         if (noti == NULL || ret_time == NULL) {
670                 return NOTIFICATION_ERROR_INVALID_DATA;
671         }
672
673         /* Set time infomation */
674         *ret_time = noti->time;
675
676         return NOTIFICATION_ERROR_NONE;
677 }
678
679 EXPORT_API notification_error_e notification_get_insert_time(notification_h noti,
680                                                              time_t * ret_time)
681 {
682         /* Check noti and ret_time is valid data */
683         if (noti == NULL || ret_time == NULL) {
684                 return NOTIFICATION_ERROR_INVALID_DATA;
685         }
686
687         /* Set insert time information */
688         *ret_time = noti->insert_time;
689
690         return NOTIFICATION_ERROR_NONE;
691 }
692
693 EXPORT_API notification_error_e notification_set_title(notification_h noti,
694                                                        const char *title,
695                                                        const char *loc_title)
696 {
697         int noti_err = NOTIFICATION_ERROR_NONE;
698
699         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
700                                          title, loc_title,
701                                          NOTIFICATION_VARIABLE_TYPE_NONE);
702
703         return noti_err;
704 }
705
706 EXPORT_API notification_error_e notification_get_title(notification_h noti,
707                                                        char **title,
708                                                        char **loc_title)
709 {
710         int noti_err = NOTIFICATION_ERROR_NONE;
711         char *ret_text = NULL;
712
713         noti_err =
714             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
715                                   &ret_text);
716
717         if (title != NULL) {
718                 *title = ret_text;
719         }
720
721         if (loc_title != NULL) {
722                 *loc_title = NULL;
723         }
724
725         return noti_err;
726 }
727
728 EXPORT_API notification_error_e notification_set_content(notification_h noti,
729                                                          const char *content,
730                                                          const char *loc_content)
731 {
732         int noti_err = NOTIFICATION_ERROR_NONE;
733
734         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
735                                          content, loc_content,
736                                          NOTIFICATION_VARIABLE_TYPE_NONE);
737
738         return noti_err;
739 }
740
741 EXPORT_API notification_error_e notification_get_content(notification_h noti,
742                                                          char **content,
743                                                          char **loc_content)
744 {
745         int noti_err = NOTIFICATION_ERROR_NONE;
746         char *ret_text = NULL;
747
748         noti_err =
749             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
750                                   &ret_text);
751
752         if (content != NULL) {
753                 *content = ret_text;
754         }
755
756         if (loc_content != NULL) {
757                 *loc_content = NULL;
758         }
759
760         return noti_err;
761
762 #if 0
763         ret =
764             vconf_get_bool
765             (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
766
767         if (ret == -1 || boolval == 0) {
768                 if (content != NULL && noti->default_content != NULL) {
769                         *content = noti->default_content;
770                 }
771
772                 if (loc_content != NULL && noti->loc_default_content != NULL) {
773                         *loc_content = noti->loc_default_content;
774                 }
775         }
776 #endif
777 }
778
779 EXPORT_API notification_error_e notification_set_text(notification_h noti,
780                                                       notification_text_type_e type,
781                                                       const char *text,
782                                                       const char *key,
783                                                       int args_type, ...)
784 {
785         bundle *b = NULL;
786         char buf_key[32] = { 0, };
787         char buf_val[1024] = { 0, };
788         const char *ret_val = NULL;
789         va_list var_args;
790         notification_variable_type_e var_type;
791         int num_args = 0;
792         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
793         int var_value_int = 0;
794         double var_value_double = 0.0;
795         char *var_value_string = NULL;
796         notification_count_pos_type_e var_value_count =
797             NOTIFICATION_COUNT_POS_NONE;
798
799         /* Check noti is valid data */
800         if (noti == NULL) {
801                 return NOTIFICATION_ERROR_INVALID_DATA;
802         }
803
804         /* Check text type is valid type */
805         if (type <= NOTIFICATION_TEXT_TYPE_NONE
806             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
807                 return NOTIFICATION_ERROR_INVALID_DATA;
808         }
809
810         /* Check text bundle exist */
811         if (text != NULL) {
812                 if (noti->b_text != NULL) {
813                         /* If text bundle exist, store local bundle data */
814                         b = noti->b_text;
815
816                         /* Make type to key as char string */
817                         snprintf(buf_key, sizeof(buf_key), "%d", type);
818
819                         /* Get value using type key */
820                         ret_val = bundle_get_val(b, buf_key);
821                         if (ret_val != NULL) {
822                                 /* If value exist, remove this to add new value */
823                                 bundle_del(b, buf_key);
824                         }
825
826                         snprintf(buf_val, sizeof(buf_val), "%s", text);
827
828                         /* Add new text value */
829                         bundle_add(b, buf_key, buf_val);
830                 } else {
831                         /* If text bundle does not exist, create new one */
832                         b = bundle_create();
833
834                         /* Make type to key as char string */
835                         snprintf(buf_key, sizeof(buf_key), "%d", type);
836
837                         snprintf(buf_val, sizeof(buf_val), "%s", text);
838
839                         /* Add new text value */
840                         bundle_add(b, buf_key, buf_val);
841
842                         /* Save text bundle */
843                         noti->b_text = b;
844                 }
845         } else {
846                 /* Reset if text is NULL */
847                 if (noti->b_text != NULL) {
848                         /* If text bundle exist, store local bundle data */
849                         b = noti->b_text;
850
851                         /* Make type to key as char string */
852                         snprintf(buf_key, sizeof(buf_key), "%d", type);
853
854                         /* Get value using type key */
855                         ret_val = bundle_get_val(b, buf_key);
856                         if (ret_val != NULL) {
857                                 /* If value exist, remove this */
858                                 bundle_del(b, buf_key);
859                         }
860                 }
861         }
862
863         /* Save key if key is valid data */
864         if (key != NULL) {
865                 /* Check key bundle exist */
866                 if (noti->b_key != NULL) {
867                         /* If key bundle exist,  store local bundle data */
868                         b = noti->b_key;
869
870                         /* Make type to key as char string */
871                         snprintf(buf_key, sizeof(buf_key), "%d", type);
872
873                         /* Get value using type key */
874                         ret_val = bundle_get_val(b, buf_key);
875                         if (ret_val != NULL) {
876                                 /* If value exist, remove this to add new value */
877                                 bundle_del(b, buf_key);
878                         }
879
880                         snprintf(buf_val, sizeof(buf_val), "%s", key);
881
882                         /* Add new key value */
883                         bundle_add(b, buf_key, buf_val);
884                 } else {
885                         /* If key bundle does not exist, create new one */
886                         b = bundle_create();
887
888                         /* Make type to key as char string */
889                         snprintf(buf_key, sizeof(buf_key), "%d", type);
890
891                         snprintf(buf_val, sizeof(buf_val), "%s", key);
892
893                         /* Add new key value */
894                         bundle_add(b, buf_key, buf_val);
895
896                         /* Save key bundle */
897                         noti->b_key = b;
898                 }
899         } else {
900                 /* Reset if key is NULL */
901                 if (noti->b_key != NULL) {
902                         /* If key bundle exist,  store local bundle data */
903                         b = noti->b_key;
904
905                         /* Make type to key as char string */
906                         snprintf(buf_key, sizeof(buf_key), "%d", type);
907
908                         /* Get value using type key */
909                         ret_val = bundle_get_val(b, buf_key);
910                         if (ret_val != NULL) {
911                                 /* If value exist, remove this */
912                                 bundle_del(b, buf_key);
913                         }
914                 }
915         }
916
917         if (noti->b_format_args != NULL) {
918                 b = noti->b_format_args;
919         } else {
920                 b = bundle_create();
921         }
922
923         va_start(var_args, args_type);
924
925         var_type = args_type;
926         num_args = 0;
927
928         while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
929                 /* Type */
930                 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
931                 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
932
933                 ret_val = bundle_get_val(b, buf_key);
934                 if (ret_val != NULL) {
935                         bundle_del(b, buf_key);
936                 }
937
938                 bundle_add(b, buf_key, buf_val);
939
940                 switch (var_type) {
941                 case NOTIFICATION_VARIABLE_TYPE_INT:
942                         var_value_int = va_arg(var_args, int);
943
944                         /* Value */
945                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
946                                  num_args);
947                         snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
948
949                         ret_val = bundle_get_val(b, buf_key);
950                         if (ret_val != NULL) {
951                                 bundle_del(b, buf_key);
952                         }
953
954                         bundle_add(b, buf_key, buf_val);
955                         break;
956                 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
957                         var_value_double = va_arg(var_args, double);
958
959                         /* Value */
960                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
961                                  num_args);
962                         snprintf(buf_val, sizeof(buf_val), "%.2f",
963                                  var_value_double);
964
965                         ret_val = bundle_get_val(b, buf_key);
966                         if (ret_val != NULL) {
967                                 bundle_del(b, buf_key);
968                         }
969
970                         bundle_add(b, buf_key, buf_val);
971                         break;
972                 case NOTIFICATION_VARIABLE_TYPE_STRING:
973                         var_value_string = va_arg(var_args, char *);
974
975                         /* Value */
976                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
977                                  num_args);
978                         snprintf(buf_val, sizeof(buf_val), "%s",
979                                  var_value_string);
980
981                         ret_val = bundle_get_val(b, buf_key);
982                         if (ret_val != NULL) {
983                                 bundle_del(b, buf_key);
984                         }
985
986                         bundle_add(b, buf_key, buf_val);
987                         break;
988                 case NOTIFICATION_VARIABLE_TYPE_COUNT:
989                         var_value_count =
990                             va_arg(var_args, notification_count_pos_type_e);
991
992                         /* Value */
993                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
994                                  num_args);
995                         snprintf(buf_val, sizeof(buf_val), "%d",
996                                  var_value_count);
997
998                         ret_val = bundle_get_val(b, buf_key);
999                         if (ret_val != NULL) {
1000                                 bundle_del(b, buf_key);
1001                         }
1002
1003                         bundle_add(b, buf_key, buf_val);
1004                         break;
1005                 default:
1006                         NOTIFICATION_ERR("Error. invalid variable type. : %d",
1007                                          var_type);
1008                         noti_err = NOTIFICATION_ERROR_INVALID_DATA;
1009                         break;
1010                 }
1011
1012                 num_args++;
1013                 var_type = va_arg(var_args, notification_variable_type_e);
1014         }
1015         va_end(var_args);
1016
1017         if (noti_err == NOTIFICATION_ERROR_NONE) {
1018                 noti->num_format_args = num_args;
1019         } else {
1020                 noti->num_format_args = 0;
1021         }
1022
1023         snprintf(buf_key, sizeof(buf_key), "num%d", type);
1024         snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
1025
1026         ret_val = bundle_get_val(b, buf_key);
1027         if (ret_val != NULL) {
1028                 bundle_del(b, buf_key);
1029         }
1030
1031         bundle_add(b, buf_key, buf_val);
1032
1033         noti->b_format_args = b;
1034
1035         return noti_err;
1036 }
1037
1038 EXPORT_API notification_error_e notification_get_text(notification_h noti,
1039                                                       notification_text_type_e type,
1040                                                       char **text)
1041 {
1042         bundle *b = NULL;
1043         char buf_key[32] = { 0, };
1044         const char *ret_val = NULL;
1045         const char *pkgname = NULL;
1046         const char *get_str = NULL;
1047         const char *get_check_type_str = NULL;
1048         int ret = 0;
1049         int boolval = 0;
1050         notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
1051         int display_option_flag = 0;
1052
1053         char *temp_str = NULL;
1054         char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
1055         char buf_str[1024] = { 0, };
1056         int num_args = 0;
1057         notification_variable_type_e ret_var_type = 0;
1058         int ret_variable_int = 0;
1059         double ret_variable_double = 0.0;
1060
1061         /* Check noti is valid data */
1062         if (noti == NULL || text == NULL) {
1063                 return NOTIFICATION_ERROR_INVALID_DATA;
1064         }
1065
1066         /* Check text type is valid type */
1067         if (type <= NOTIFICATION_TEXT_TYPE_NONE
1068             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1069                 return NOTIFICATION_ERROR_INVALID_DATA;
1070         }
1071
1072         /* Check key */
1073         if (noti->b_key != NULL) {
1074                 b = noti->b_key;
1075
1076                 /* Get text domain and dir */
1077                 _notification_get_text_domain(noti);
1078
1079                 snprintf(buf_key, sizeof(buf_key), "%d", type);
1080
1081                 ret_val = bundle_get_val(b, buf_key);
1082                 if (ret_val != NULL && noti->domain != NULL
1083                     && noti->dir != NULL) {
1084                         /* Get application string */
1085                         bindtextdomain(noti->domain, noti->dir);
1086
1087                         get_str = dgettext(noti->domain, ret_val);
1088                 } else if (ret_val != NULL) {
1089                         /* Get system string */
1090                         get_str = dgettext("sys_string", ret_val);
1091                 } else {
1092                         get_str = NULL;
1093                 }
1094         }
1095
1096         if (get_str == NULL && noti->b_text != NULL) {
1097                 b = noti->b_text;
1098                 /* Get basic text */
1099                 snprintf(buf_key, sizeof(buf_key), "%d", type);
1100
1101                 get_str = bundle_get_val(b, buf_key);
1102         }
1103
1104         check_type = type;
1105
1106         /* Set display option is off type when option is off, type is noti */
1107         if (get_str != NULL && display_option_flag == 1
1108             && noti->type == NOTIFICATION_TYPE_NOTI) {
1109                 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
1110                     || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
1111                         /* Set check_type to option content string */
1112                         if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
1113                                 check_type =
1114                                     NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
1115                         } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
1116                                 check_type =
1117                                     NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
1118                         }
1119
1120                         /* Check key */
1121                         if (noti->b_key != NULL) {
1122                                 b = noti->b_key;
1123
1124                                 /* Get text domain and dir */
1125                                 _notification_get_text_domain(noti);
1126
1127                                 snprintf(buf_key, sizeof(buf_key), "%d",
1128                                          check_type);
1129
1130                                 ret_val = bundle_get_val(b, buf_key);
1131                                 if (ret_val != NULL && noti->domain != NULL
1132                                     && noti->dir != NULL) {
1133                                         /* Get application string */
1134                                         bindtextdomain(noti->domain, noti->dir);
1135
1136                                         get_check_type_str =
1137                                             dgettext(noti->domain, ret_val);
1138                                 } else if (ret_val != NULL) {
1139                                         /* Get system string */
1140                                         get_check_type_str =
1141                                             dgettext("sys_string", ret_val);
1142                                 } else {
1143                                         get_check_type_str = NULL;
1144                                 }
1145                         }
1146
1147                         if (get_check_type_str == NULL && noti->b_text != NULL) {
1148                                 b = noti->b_text;
1149                                 /* Get basic text */
1150                                 snprintf(buf_key, sizeof(buf_key), "%d",
1151                                          check_type);
1152
1153                                 get_check_type_str = bundle_get_val(b, buf_key);
1154                         }
1155                 }
1156
1157                 if (get_check_type_str != NULL) {
1158                         /* Replace option off type string */
1159                         get_str = get_check_type_str;
1160                 } else {
1161                         /* Set default string */
1162                         get_str =
1163                             dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
1164                 }
1165         }
1166
1167         if (get_str != NULL) {
1168                 /* Get number format args */
1169                 b = noti->b_format_args;
1170                 noti->num_format_args = 0;
1171
1172                 if (b != NULL) {
1173                         snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
1174                         ret_val = bundle_get_val(b, buf_key);
1175                         if (ret_val != NULL) {
1176                                 noti->num_format_args = atoi(ret_val);
1177                         }
1178                 }
1179
1180                 if (noti->num_format_args == 0) {
1181                         *text = (char *)get_str;
1182                 } else {
1183                         /* Check first variable is count, LEFT pos */
1184                         snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1185                                  check_type, num_args);
1186                         ret_val = bundle_get_val(b, buf_key);
1187                         ret_var_type = atoi(ret_val);
1188
1189                         if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
1190                                 /* Get var Value */
1191                                 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
1192                                          check_type, num_args);
1193                                 ret_val = bundle_get_val(b, buf_key);
1194                                 ret_variable_int = atoi(ret_val);
1195
1196                                 if (ret_variable_int ==
1197                                     NOTIFICATION_COUNT_POS_LEFT) {
1198                                         notification_noti_get_count(noti->type,
1199                                                                     noti->caller_pkgname,
1200                                                                     noti->group_id,
1201                                                                     noti->priv_id,
1202                                                                     &ret_variable_int);
1203                                         snprintf(buf_str, sizeof(buf_str),
1204                                                  "%d ", ret_variable_int);
1205
1206                                         int src_len = strlen(result_str);
1207                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
1208
1209                                         strncat(result_str, buf_str,
1210                                                         max_len);
1211
1212                                         num_args++;
1213                                 }
1214
1215                         }
1216
1217                         /* Check variable IN pos */
1218                         for (temp_str = (char *)get_str; *temp_str != '\0';
1219                              temp_str++) {
1220                                 if (*temp_str != '%') {
1221                                         strncat(result_str, temp_str, 1);
1222                                 } else {
1223                                         if (*(temp_str + 1) == '%') {
1224                                                 strncat(result_str, temp_str,
1225                                                         1);
1226                                         } else if (*(temp_str + 1) == 'd') {
1227                                                 /* Get var Type */
1228                                                 ret_variable_int = 0;
1229
1230                                                 snprintf(buf_key,
1231                                                          sizeof(buf_key),
1232                                                          "%dtype%d", check_type,
1233                                                          num_args);
1234                                                 ret_val =
1235                                                     bundle_get_val(b, buf_key);
1236                                                 ret_var_type = atoi(ret_val);
1237                                                 if (ret_var_type ==
1238                                                     NOTIFICATION_VARIABLE_TYPE_COUNT)
1239                                                 {
1240                                                         /* Get notification count */
1241                                                         notification_noti_get_count
1242                                                             (noti->type,
1243                                                              noti->caller_pkgname,
1244                                                              noti->group_id,
1245                                                              noti->priv_id,
1246                                                              &ret_variable_int);
1247                                                 } else {
1248                                                         /* Get var Value */
1249                                                         snprintf(buf_key,
1250                                                                  sizeof
1251                                                                  (buf_key),
1252                                                                  "%dvalue%d",
1253                                                                  check_type,
1254                                                                  num_args);
1255                                                         ret_val =
1256                                                             bundle_get_val(b,
1257                                                                            buf_key);
1258                                                         ret_variable_int =
1259                                                             atoi(ret_val);
1260                                                 }
1261
1262                                                 snprintf(buf_str,
1263                                                          sizeof(buf_str), "%d",
1264                                                          ret_variable_int);
1265
1266                                                 int src_len = strlen(result_str);
1267                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
1268
1269                                                 strncat(result_str, buf_str,
1270                                                                 max_len);
1271
1272                                                 temp_str++;
1273
1274                                                 num_args++;
1275                                         } else if (*(temp_str + 1) == 's') {
1276                                                 /* Get var Value */
1277                                                 snprintf(buf_key,
1278                                                          sizeof(buf_key),
1279                                                          "%dvalue%d",
1280                                                          check_type, num_args);
1281                                                 ret_val =
1282                                                     bundle_get_val(b, buf_key);
1283
1284                                                 snprintf(buf_str,
1285                                                          sizeof(buf_str), "%s",
1286                                                          ret_val);
1287
1288                                                 int src_len = strlen(result_str);
1289                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
1290
1291                                                 strncat(result_str, buf_str,
1292                                                                 max_len);
1293
1294                                                 temp_str++;
1295
1296                                                 num_args++;
1297                                         } else if (*(temp_str + 1) == 'f') {
1298                                                 /* Get var Value */
1299                                                 snprintf(buf_key,
1300                                                          sizeof(buf_key),
1301                                                          "%dvalue%d",
1302                                                          check_type, num_args);
1303                                                 ret_val =
1304                                                     bundle_get_val(b, buf_key);
1305                                                 ret_variable_double =
1306                                                     atof(ret_val);
1307
1308                                                 snprintf(buf_str,
1309                                                          sizeof(buf_str),
1310                                                          "%.2f",
1311                                                          ret_variable_double);
1312
1313                                                 int src_len = strlen(result_str);
1314                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
1315
1316                                                 strncat(result_str, buf_str,
1317                                                                 max_len);
1318
1319                                                 temp_str++;
1320
1321                                                 num_args++;
1322                                         }
1323                                 }
1324
1325                         }
1326
1327                         /* Check last variable is count, LEFT pos */
1328                         if (num_args < noti->num_format_args) {
1329                                 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1330                                          check_type, num_args);
1331                                 ret_val = bundle_get_val(b, buf_key);
1332                                 ret_var_type = atoi(ret_val);
1333                                 if (ret_var_type ==
1334                                     NOTIFICATION_VARIABLE_TYPE_COUNT) {
1335                                         /* Get var Value */
1336                                         snprintf(buf_key, sizeof(buf_key),
1337                                                  "%dvalue%d", check_type,
1338                                                  num_args);
1339                                         ret_val = bundle_get_val(b, buf_key);
1340                                         ret_variable_int = atoi(ret_val);
1341
1342                                         if (ret_variable_int ==
1343                                             NOTIFICATION_COUNT_POS_RIGHT) {
1344                                                 notification_noti_get_count
1345                                                     (noti->type,
1346                                                      noti->caller_pkgname,
1347                                                      noti->group_id,
1348                                                      noti->priv_id,
1349                                                      &ret_variable_int);
1350                                                 snprintf(buf_str,
1351                                                          sizeof(buf_str), " %d",
1352                                                          ret_variable_int);
1353
1354                                                 int src_len = strlen(result_str);
1355                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
1356
1357                                                 strncat(result_str, buf_str,
1358                                                                 max_len);
1359
1360                                                 num_args++;
1361                                         }
1362
1363                                 }
1364                         }
1365
1366                         switch (check_type) {
1367                         case NOTIFICATION_TEXT_TYPE_TITLE:
1368                         case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
1369                                 if (noti->temp_title != NULL)
1370                                         free(noti->temp_title);
1371
1372                                 noti->temp_title = strdup(result_str);
1373
1374                                 *text = noti->temp_title;
1375                                 break;
1376                         case NOTIFICATION_TEXT_TYPE_CONTENT:
1377                         case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1378                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
1379                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1380                                 if (noti->temp_content !=
1381                                     NULL)
1382                                         free(noti->temp_content);
1383
1384                                 noti->temp_content = strdup(result_str);
1385
1386                                 *text = noti->temp_content;
1387                                 break;
1388                         default:
1389                                 break;
1390                         }
1391
1392                 }
1393
1394         } else {
1395                 if (check_type == NOTIFICATION_TEXT_TYPE_TITLE
1396                     || check_type == NOTIFICATION_TEXT_TYPE_GROUP_TITLE) {
1397                         /* Remove app name if exist, because pkgname is changed according to language setting */
1398                         if (noti->app_name != NULL) {
1399                                 free(noti->app_name);
1400                                 noti->app_name = NULL;
1401                         }
1402
1403                         /* First, get app name from launch_pkgname */
1404                         if (noti->launch_pkgname != NULL) {
1405                                 noti->app_name =
1406                                     _notification_get_name(noti->
1407                                                            launch_pkgname);
1408                         }
1409
1410                         /* Second, get app name from caller_pkgname */
1411                         if (noti->app_name == NULL
1412                             && noti->caller_pkgname != NULL) {
1413                                 noti->app_name =
1414                                     _notification_get_name(noti->
1415                                                            caller_pkgname);
1416                         }
1417
1418                         /* Third, get app name from service data */
1419                         if (noti->app_name == NULL
1420                             && noti->b_service_single_launch != NULL) {
1421                                 pkgname =
1422                                     appsvc_get_pkgname(noti->
1423                                                        b_service_single_launch);
1424
1425                                 if (pkgname != NULL) {
1426                                         noti->app_name =
1427                                             _notification_get_name(pkgname);
1428                                 }
1429                         }
1430
1431                         *text = noti->app_name;
1432                 } else {
1433                         *text = NULL;
1434                 }
1435         }
1436
1437         return NOTIFICATION_ERROR_NONE;
1438 }
1439
1440 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
1441                                                              const char *domain,
1442                                                              const char *dir)
1443 {
1444         /* check noti and domain is valid data */
1445         if (noti == NULL || domain == NULL) {
1446                 return NOTIFICATION_ERROR_INVALID_DATA;
1447         }
1448
1449         /* Check domain */
1450         if (noti->domain) {
1451                 /* Remove previous domain */
1452                 free(noti->domain);
1453         }
1454         /* Copy domain */
1455         noti->domain = strdup(domain);
1456
1457         /* Check locale dir */
1458         if (noti->dir) {
1459                 /* Remove previous locale dir */
1460                 free(noti->dir);
1461         }
1462         /* Copy locale dir */
1463         noti->dir = strdup(dir);
1464
1465         return NOTIFICATION_ERROR_NONE;
1466 }
1467
1468 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
1469                                                              char **domain,
1470                                                              char **dir)
1471 {
1472         /* Check noti is valid data */
1473         if (noti == NULL) {
1474                 return NOTIFICATION_ERROR_INVALID_DATA;
1475         }
1476
1477         /* Get domain */
1478         if (domain != NULL && noti->domain != NULL) {
1479                 *domain = noti->domain;
1480         }
1481
1482         /* Get locale dir */
1483         if (dir != NULL && noti->dir != NULL) {
1484                 *dir = noti->dir;
1485         }
1486
1487         return NOTIFICATION_ERROR_NONE;
1488 }
1489
1490 EXPORT_API notification_error_e notification_set_time_to_text(notification_h noti, notification_text_type_e type,
1491                                                                 time_t time)
1492 {
1493         notification_error_e ret = NOTIFICATION_ERROR_NONE;
1494         char buf[256] = { 0, };
1495         char buf_tag[512] = { 0, };
1496
1497         if (noti == NULL) {
1498                 return NOTIFICATION_ERROR_INVALID_DATA;
1499         }
1500         if (time <= 0) {
1501                 return NOTIFICATION_ERROR_INVALID_DATA;
1502         }
1503
1504         snprintf(buf, sizeof(buf), "%lu", time);
1505         ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
1506
1507         if (ret != NOTIFICATION_ERROR_NONE) {
1508                 return ret;
1509         }
1510
1511         return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1512 }
1513
1514 EXPORT_API notification_error_e notification_get_time_from_text(notification_h noti, notification_text_type_e type,
1515                                                                 time_t *time)
1516 {
1517         notification_error_e ret = NOTIFICATION_ERROR_NONE;
1518         char buf[256] = { 0, };
1519         char buf_tag[512] = { 0, };
1520
1521         if (noti == NULL) {
1522                 return NOTIFICATION_ERROR_INVALID_DATA;
1523         }
1524         if (time == NULL) {
1525                 return NOTIFICATION_ERROR_INVALID_DATA;
1526         }
1527
1528         char *ret_text = NULL;
1529         ret = notification_get_text(noti, type, &ret_text);
1530
1531         if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
1532                 return NOTIFICATION_ERROR_INVALID_DATA;
1533         }
1534
1535         if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
1536                 return NOTIFICATION_ERROR_INVALID_DATA;
1537         }
1538
1539         char *tag_value = NULL;
1540         tag_value = notification_noti_strip_tag(ret_text);
1541         if (tag_value == NULL) {
1542                 return NOTIFICATION_ERROR_INVALID_DATA;
1543         }
1544
1545         *time = atol(tag_value);
1546         free(tag_value);
1547
1548         return NOTIFICATION_ERROR_NONE;
1549 }
1550
1551 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1552                                                        notification_sound_type_e type,
1553                                                        const char *path)
1554 {
1555         /* Check noti is valid data */
1556         if (noti == NULL) {
1557                 return NOTIFICATION_ERROR_INVALID_DATA;
1558         }
1559
1560         /* Check type is valid */
1561         if (type < NOTIFICATION_SOUND_TYPE_NONE
1562             || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1563                 return NOTIFICATION_ERROR_INVALID_DATA;
1564         }
1565
1566         /* Save sound type */
1567         noti->sound_type = type;
1568
1569         /* Save sound path if user data type */
1570         if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1571                 if (noti->sound_path != NULL) {
1572                         free(noti->sound_path);
1573                 }
1574
1575                 noti->sound_path = strdup(path);
1576         } else {
1577                 if (noti->sound_path != NULL) {
1578                         free(noti->sound_path);
1579                         noti->sound_path = NULL;
1580                 }
1581         }
1582
1583         return NOTIFICATION_ERROR_NONE;
1584 }
1585
1586 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1587                                                        notification_sound_type_e *type,
1588                                                        const char **path)
1589 {
1590         /* check noti and type is valid data */
1591         if (noti == NULL || type == NULL) {
1592                 return NOTIFICATION_ERROR_INVALID_DATA;
1593         }
1594
1595         /* Set sound type */
1596         *type = noti->sound_type;
1597
1598         /* Set sound path if user data type */
1599         if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1600             && path != NULL) {
1601                 *path = noti->sound_path;
1602         }
1603
1604         return NOTIFICATION_ERROR_NONE;
1605 }
1606
1607 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1608                                                            notification_vibration_type_e type,
1609                                                            const char *path)
1610 {
1611         /* Check noti is valid data */
1612         if (noti == NULL) {
1613                 return NOTIFICATION_ERROR_INVALID_DATA;
1614         }
1615
1616         /* Check type is valid */
1617         if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1618             || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1619                 return NOTIFICATION_ERROR_INVALID_DATA;
1620         }
1621
1622         /* Save vibration type */
1623         noti->vibration_type = type;
1624
1625         /* Save sound path if user data type */
1626         if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1627                 if (noti->vibration_path != NULL) {
1628                         free(noti->vibration_path);
1629                 }
1630
1631                 noti->vibration_path = strdup(path);
1632         } else {
1633                 if (noti->vibration_path != NULL) {
1634                         free(noti->vibration_path);
1635                         noti->vibration_path = NULL;
1636                 }
1637         }
1638
1639         return NOTIFICATION_ERROR_NONE;
1640
1641 }
1642
1643 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1644                                                            notification_vibration_type_e *type,
1645                                                            const char **path)
1646 {
1647         /* check noti and type is valid data */
1648         if (noti == NULL || type == NULL) {
1649                 return NOTIFICATION_ERROR_INVALID_DATA;
1650         }
1651
1652         /* Set vibration type */
1653         *type = noti->vibration_type;
1654
1655         /* Set sound path if user data type */
1656         if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1657             && path != NULL) {
1658                 *path = noti->vibration_path;
1659         }
1660
1661         return NOTIFICATION_ERROR_NONE;
1662 }
1663
1664 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1665                                                              const char *pkgname)
1666 {
1667         if (noti == NULL || pkgname == NULL) {
1668                 return NOTIFICATION_ERROR_INVALID_DATA;
1669         }
1670
1671         if (noti->launch_pkgname) {
1672                 free(noti->launch_pkgname);
1673         }
1674
1675         noti->launch_pkgname = strdup(pkgname);
1676
1677         return NOTIFICATION_ERROR_NONE;
1678 }
1679
1680 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1681                                                              char **pkgname)
1682 {
1683         if (noti == NULL || pkgname == NULL) {
1684                 return NOTIFICATION_ERROR_INVALID_DATA;
1685         }
1686
1687         if (noti->launch_pkgname) {
1688                 *pkgname = noti->launch_pkgname;
1689         } else {
1690                 *pkgname = noti->caller_pkgname;
1691         }
1692
1693         return NOTIFICATION_ERROR_NONE;
1694 }
1695
1696 EXPORT_API notification_error_e notification_set_args(notification_h noti,
1697                                                       bundle * args,
1698                                                       bundle * group_args)
1699 {
1700         if (noti == NULL || args == NULL) {
1701                 return NOTIFICATION_ERROR_INVALID_DATA;
1702         }
1703
1704         if (noti->args) {
1705                 bundle_free(noti->args);
1706         }
1707
1708         noti->args = bundle_dup(args);
1709
1710         if (noti->group_args) {
1711                 bundle_free(noti->group_args);
1712                 noti->group_args = NULL;
1713         }
1714
1715         if (group_args != NULL) {
1716                 noti->group_args = bundle_dup(group_args);
1717         }
1718
1719         return NOTIFICATION_ERROR_NONE;
1720 }
1721
1722 EXPORT_API notification_error_e notification_get_args(notification_h noti,
1723                                                       bundle ** args,
1724                                                       bundle ** group_args)
1725 {
1726         if (noti == NULL || args == NULL) {
1727                 return NOTIFICATION_ERROR_INVALID_DATA;
1728         }
1729
1730         if (noti->args) {
1731                 *args = noti->args;
1732         } else {
1733                 *args = NULL;
1734         }
1735
1736         if (group_args != NULL && noti->group_args) {
1737                 *group_args = noti->group_args;
1738         }
1739
1740         return NOTIFICATION_ERROR_NONE;
1741 }
1742
1743 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1744                                                                 notification_execute_type_e type,
1745                                                                 const char *text,
1746                                                                 const char *key,
1747                                                                 bundle *service_handle)
1748 {
1749         char buf_key[32] = { 0, };
1750         const char *ret_val = NULL;
1751         bundle *b = NULL;
1752
1753         if (noti == NULL) {
1754                 return NOTIFICATION_ERROR_INVALID_DATA;
1755         }
1756
1757         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1758             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1759                 return NOTIFICATION_ERROR_INVALID_DATA;
1760         }
1761
1762         /* Create execute option bundle if does not exist */
1763         if (noti->b_execute_option != NULL) {
1764                 noti->b_execute_option = bundle_create();
1765         }
1766
1767         b = noti->b_execute_option;
1768
1769         /* Save text */
1770         if (text != NULL) {
1771                 /* Make text key */
1772                 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1773
1774                 /* Check text key exist */
1775                 ret_val = bundle_get_val(b, buf_key);
1776                 if (ret_val != NULL) {
1777                         /* Remove previous data */
1778                         bundle_del(b, buf_key);
1779                 }
1780
1781                 /* Add text data */
1782                 bundle_add(b, buf_key, text);
1783         }
1784
1785         /* Save key */
1786         if (key != NULL) {
1787                 /* Make key key */
1788                 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1789
1790                 /* Check key key exist */
1791                 ret_val = bundle_get_val(b, buf_key);
1792                 if (ret_val != NULL) {
1793                         /* Remove previous data */
1794                         bundle_del(b, buf_key);
1795                 }
1796
1797                 /* Add text data */
1798                 bundle_add(b, buf_key, key);
1799         }
1800
1801         switch (type) {
1802         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1803                 /* Remove previous data if exist */
1804                 if (noti->b_service_responding != NULL) {
1805                         bundle_free(noti->b_service_responding);
1806                         noti->b_service_responding = NULL;
1807                 }
1808
1809                 /* Save service handle */
1810                 if (service_handle != NULL) {
1811                         noti->b_service_responding = bundle_dup(service_handle);
1812                 }
1813                 break;
1814         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1815                 /* Remove previous data if exist */
1816                 if (noti->b_service_single_launch != NULL) {
1817                         bundle_free(noti->b_service_single_launch);
1818                         noti->b_service_single_launch = NULL;
1819                 }
1820
1821                 /* Save service handle */
1822                 if (service_handle != NULL) {
1823                         noti->b_service_single_launch =
1824                             bundle_dup(service_handle);
1825                 }
1826                 break;
1827         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1828                 /* Remove previous data if exist */
1829                 if (noti->b_service_multi_launch != NULL) {
1830                         bundle_free(noti->b_service_multi_launch);
1831                         noti->b_service_multi_launch = NULL;
1832                 }
1833
1834                 /* Save service handle */
1835                 if (service_handle != NULL) {
1836                         noti->b_service_multi_launch =
1837                             bundle_dup(service_handle);
1838                 }
1839                 break;
1840         }
1841
1842         return NOTIFICATION_ERROR_NONE;
1843 }
1844
1845 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1846                                                                 notification_execute_type_e type,
1847                                                                 const char **text,
1848                                                                 bundle **service_handle)
1849 {
1850         char buf_key[32] = { 0, };
1851         const char *ret_val = NULL;
1852         char *get_str = NULL;
1853         bundle *b = NULL;
1854
1855         if (noti == NULL) {
1856                 return NOTIFICATION_ERROR_INVALID_DATA;
1857         }
1858
1859         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1860             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1861                 return NOTIFICATION_ERROR_INVALID_DATA;
1862         }
1863
1864         switch (type) {
1865         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1866                 b = noti->b_service_responding;
1867                 break;
1868         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1869                 b = noti->b_service_single_launch;
1870                 break;
1871         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1872                 b = noti->b_service_multi_launch;
1873                 break;
1874         default:
1875                 b = NULL;
1876                 break;
1877         }
1878
1879         if (b != NULL) {
1880                 // Return text
1881                 if (text != NULL) {
1882                         // Get text domain and dir
1883                         if (noti->domain == NULL || noti->dir == NULL) {
1884                                 _notification_get_text_domain(noti);
1885                         }
1886
1887                         /* Make key */
1888                         snprintf(buf_key, sizeof(buf_key), "key%d", type);
1889
1890                         /* Check key key exist */
1891                         ret_val = bundle_get_val(b, buf_key);
1892                         if (ret_val != NULL && noti->domain != NULL
1893                             && noti->dir != NULL) {
1894                                 /* Get application string */
1895                                 bindtextdomain(noti->domain, noti->dir);
1896
1897                                 get_str = dgettext(noti->domain, ret_val);
1898
1899                                 *text = get_str;
1900                         } else if (ret_val != NULL) {
1901                                 /* Get system string */
1902                                 get_str = dgettext("sys_string", ret_val);
1903
1904                                 *text = get_str;
1905                         } else {
1906                                 /* Get basic text */
1907                                 snprintf(buf_key, sizeof(buf_key), "text%d",
1908                                          type);
1909
1910                                 ret_val = bundle_get_val(b, buf_key);
1911
1912                                 *text = ret_val;
1913                         }
1914                 }
1915         }
1916
1917         switch (type) {
1918         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1919                 b = noti->b_service_responding;
1920                 break;
1921         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1922                 b = noti->b_service_single_launch;
1923                 break;
1924         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1925                 b = noti->b_service_multi_launch;
1926                 break;
1927         default:
1928                 b = NULL;
1929                 break;
1930         }
1931
1932         if (service_handle != NULL) {
1933                 *service_handle = b;
1934         }
1935
1936         return NOTIFICATION_ERROR_NONE;
1937 }
1938
1939 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1940                                                           int flags)
1941 {
1942         /* Check noti is valid data */
1943         if (noti == NULL) {
1944                 return NOTIFICATION_ERROR_INVALID_DATA;
1945         }
1946
1947         /* Set flags */
1948         noti->flags_for_property = flags;
1949
1950         return NOTIFICATION_ERROR_NONE;
1951 }
1952
1953 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1954                                                           int *flags)
1955 {
1956         /* Check noti and flags are valid data */
1957         if (noti == NULL || flags == NULL) {
1958                 return NOTIFICATION_ERROR_INVALID_DATA;
1959         }
1960
1961         /* Set flags */
1962         *flags = noti->flags_for_property;
1963
1964         return NOTIFICATION_ERROR_NONE;
1965 }
1966
1967 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1968                                                                  int applist)
1969 {
1970         /* Check noti is valid data */
1971         if (noti == NULL) {
1972                 return NOTIFICATION_ERROR_INVALID_DATA;
1973         }
1974
1975         /* Set app list */
1976         noti->display_applist = applist;
1977
1978         return NOTIFICATION_ERROR_NONE;
1979 }
1980
1981 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1982                                                                  int *applist)
1983 {
1984         /* Check noti and applist are valid data */
1985         if (noti == NULL || applist == NULL) {
1986                 return NOTIFICATION_ERROR_INVALID_DATA;
1987         }
1988
1989         /* Set app list */
1990         *applist = noti->display_applist;
1991
1992         return NOTIFICATION_ERROR_NONE;
1993 }
1994
1995 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1996                                                       double size)
1997 {
1998         /* Check noti is valid data */
1999         if (noti == NULL) {
2000                 return NOTIFICATION_ERROR_INVALID_DATA;
2001         }
2002
2003         /* Save progress size */
2004         noti->progress_size = size;
2005
2006         return NOTIFICATION_ERROR_NONE;
2007 }
2008
2009 EXPORT_API notification_error_e notification_get_size(notification_h noti,
2010                                                       double *size)
2011 {
2012         /* Check noti and size is valid data */
2013         if (noti == NULL || size == NULL) {
2014                 return NOTIFICATION_ERROR_INVALID_DATA;
2015         }
2016
2017         /* Set progress size */
2018         *size = noti->progress_size;
2019
2020         return NOTIFICATION_ERROR_NONE;
2021 }
2022
2023 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
2024                                                           double percentage)
2025 {
2026         /* Check noti is valid data */
2027         if (noti == NULL) {
2028                 return NOTIFICATION_ERROR_INVALID_DATA;
2029         }
2030
2031         /* Save progress percentage */
2032         noti->progress_percentage = percentage;
2033
2034         return NOTIFICATION_ERROR_NONE;
2035 }
2036
2037 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
2038                                                           double *percentage)
2039 {
2040         /* Check noti and percentage are valid data */
2041         if (noti == NULL || percentage == NULL) {
2042                 return NOTIFICATION_ERROR_INVALID_DATA;
2043         }
2044
2045         /* Set progress percentage */
2046         *percentage = noti->progress_percentage;
2047
2048         return NOTIFICATION_ERROR_NONE;
2049 }
2050
2051 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
2052                                                          const char *pkgname)
2053 {
2054         /* check noti and pkgname are valid data */
2055         if (noti == NULL || pkgname == NULL) {
2056                 return NOTIFICATION_ERROR_INVALID_DATA;
2057         }
2058
2059         /* Remove previous caller pkgname */
2060         if (noti->caller_pkgname) {
2061                 free(noti->caller_pkgname);
2062                 noti->caller_pkgname = NULL;
2063         }
2064
2065         noti->caller_pkgname = strdup(pkgname);
2066
2067         return NOTIFICATION_ERROR_NONE;
2068 }
2069
2070 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
2071                                                          char **pkgname)
2072 {
2073         /* Check noti and pkgname are valid data */
2074         if (noti == NULL || pkgname == NULL) {
2075                 return NOTIFICATION_ERROR_INVALID_DATA;
2076         }
2077
2078         /* Get caller pkgname */
2079         if (noti->caller_pkgname) {
2080                 *pkgname = noti->caller_pkgname;
2081         } else {
2082                 *pkgname = NULL;
2083         }
2084
2085         return NOTIFICATION_ERROR_NONE;
2086 }
2087
2088 EXPORT_API notification_error_e notification_set_layout(notification_h noti,
2089                 notification_ly_type_e layout)
2090 {
2091         /* check noti and pkgname are valid data */
2092         if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
2093                 return NOTIFICATION_ERROR_INVALID_DATA;
2094         }
2095
2096         noti->layout = layout;
2097
2098         return NOTIFICATION_ERROR_NONE;
2099 }
2100
2101 EXPORT_API notification_error_e notification_get_layout(notification_h noti,
2102                 notification_ly_type_e *layout)
2103 {
2104         /* Check noti and pkgname are valid data */
2105         if (noti == NULL || layout == NULL) {
2106                 return NOTIFICATION_ERROR_INVALID_DATA;
2107         }
2108
2109         *layout = noti->layout;
2110
2111         return NOTIFICATION_ERROR_NONE;
2112 }
2113
2114 EXPORT_API notification_error_e notification_set_badge(const char *pkgname,
2115                                                        int group_id, int count)
2116 {
2117         char *caller_pkgname = NULL;
2118         int ret = NOTIFICATION_ERROR_NONE;
2119
2120         /* Check count is valid count */
2121         if (count < 0) {
2122                 return NOTIFICATION_ERROR_INVALID_DATA;
2123         }
2124
2125         /* Check pkgname */
2126         if (pkgname == NULL) {
2127                 caller_pkgname = _notification_get_pkgname_by_pid();
2128
2129                 /* Set count into Group DB */
2130                 ret =
2131                     notification_group_set_badge(caller_pkgname, group_id,
2132                                                  count);
2133
2134                 if (caller_pkgname != NULL) {
2135                         free(caller_pkgname);
2136                 }
2137         } else {
2138                 /* Set count into Group DB */
2139                 ret = notification_group_set_badge(pkgname, group_id, count);
2140         }
2141
2142         return ret;
2143 }
2144
2145 EXPORT_API notification_error_e notification_get_badge(const char *pkgname,
2146                                                        int group_id, int *count)
2147 {
2148         char *caller_pkgname = NULL;
2149         int ret = NOTIFICATION_ERROR_NONE;
2150         int ret_unread_count = 0;
2151
2152         /* Check pkgname */
2153         if (pkgname == NULL) {
2154                 caller_pkgname = _notification_get_pkgname_by_pid();
2155
2156                 /* Get count from Group DB */
2157                 ret =
2158                     notification_group_get_badge(caller_pkgname, group_id,
2159                                                  &ret_unread_count);
2160
2161                 if (caller_pkgname != NULL) {
2162                         free(caller_pkgname);
2163                 }
2164         } else {
2165                 /* Get count from Group DB */
2166                 ret =
2167                     notification_group_get_badge(pkgname, group_id,
2168                                                  &ret_unread_count);
2169         }
2170
2171         if (ret != NOTIFICATION_ERROR_NONE) {
2172                 return ret;
2173         }
2174
2175         /* Set count */
2176         if (count != NULL) {
2177                 *count = ret_unread_count;
2178         }
2179
2180         return NOTIFICATION_ERROR_NONE;
2181 }
2182
2183 EXPORT_API notification_error_e notification_get_id(notification_h noti,
2184                                                     int *group_id, int *priv_id)
2185 {
2186         /* check noti is valid data */
2187         if (noti == NULL) {
2188                 return NOTIFICATION_ERROR_INVALID_DATA;
2189         }
2190
2191         /* Check group_id is valid data */
2192         if (group_id) {
2193                 /* Set group id */
2194                 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
2195                         *group_id = NOTIFICATION_GROUP_ID_NONE;
2196                 } else {
2197                         *group_id = noti->group_id;
2198                 }
2199         }
2200
2201         /* Check priv_id is valid data */
2202         if (priv_id) {
2203                 /* Set priv_id */
2204                 *priv_id = noti->priv_id;
2205         }
2206
2207         return NOTIFICATION_ERROR_NONE;
2208 }
2209
2210 EXPORT_API notification_error_e notification_get_type(notification_h noti,
2211                                                       notification_type_e *type)
2212 {
2213         /* Check noti and type is valid data */
2214         if (noti == NULL || type == NULL) {
2215                 return NOTIFICATION_ERROR_INVALID_DATA;
2216         }
2217
2218         /* Set noti type */
2219         *type = noti->type;
2220
2221         return NOTIFICATION_ERROR_NONE;
2222 }
2223
2224 EXPORT_API notification_error_e notification_insert(notification_h noti,
2225                                                     int *priv_id)
2226 {
2227         int ret = 0;
2228
2229         /* Check noti is vaild data */
2230         if (noti == NULL) {
2231                 return NOTIFICATION_ERROR_INVALID_DATA;
2232         }
2233
2234         /* Check noti type is valid type */
2235         if (noti->type <= NOTIFICATION_TYPE_NONE
2236             || noti->type >= NOTIFICATION_TYPE_MAX) {
2237                 return NOTIFICATION_ERROR_INVALID_DATA;
2238         }
2239
2240         /* Save insert time */
2241         noti->insert_time = time(NULL);
2242
2243         /* Insert into DB */
2244         ret = notification_noti_insert(noti);
2245         if (ret != NOTIFICATION_ERROR_NONE) {
2246                 return ret;
2247         }
2248
2249         /* Check disable update on insert property */
2250         if (noti->flags_for_property
2251                 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
2252                 /* Disable changed cb */
2253         } else {
2254                 /* Enable changed cb */
2255                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1);
2256                 if (noti_op != NULL) {
2257                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2258                         free(noti_op);
2259                 }
2260         }
2261
2262         /* If priv_id is valid data, set priv_id */
2263         if (priv_id != NULL) {
2264                 *priv_id = noti->priv_id;
2265         }
2266
2267         return NOTIFICATION_ERROR_NONE;
2268 }
2269
2270 EXPORT_API notification_error_e notification_update(notification_h noti)
2271 {
2272         int ret = 0;
2273
2274         /* Check noti is valid data */
2275         if (noti != NULL) {
2276                 /* Update insert time ? */
2277                 noti->insert_time = time(NULL);
2278
2279                 ret = notification_noti_update(noti);
2280                 if (ret != NOTIFICATION_ERROR_NONE) {
2281                         return ret;
2282                 }
2283
2284                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1);
2285                 if (noti_op != NULL) {
2286                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2287                         free(noti_op);
2288                 }
2289         } else {
2290                 /* Send changed notification */
2291                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0);
2292                 if (noti_op != NULL) {
2293                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2294                         free(noti_op);
2295                 }
2296         }
2297         return NOTIFICATION_ERROR_NONE;
2298 }
2299
2300 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
2301 {
2302         int ret = 0;
2303         int num_deleted = 0;
2304         int *list_deleted = NULL;
2305
2306         /* Delete all notification of type */
2307         ret = notification_noti_delete_all(type, NULL, &num_deleted, &list_deleted);
2308         if (ret != NOTIFICATION_ERROR_NONE) {
2309                 return ret;
2310         }
2311
2312         /* Send chagned notification */
2313
2314         if (num_deleted > 0 && list_deleted != NULL) {
2315                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, num_deleted, list_deleted, num_deleted);
2316                 if (noti_op != NULL) {
2317                         NOTIFICATION_ERR("noti_op %x", noti_op);
2318                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, num_deleted);
2319                         free(noti_op);
2320                 }
2321         }
2322
2323         if (list_deleted != NULL) {
2324                 free(list_deleted);
2325         }
2326
2327         return NOTIFICATION_ERROR_NONE;
2328 }
2329
2330 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
2331                                                                 notification_type_e type)
2332 {
2333         int ret = 0;
2334         int num_deleted = 0;
2335         int *list_deleted = NULL;
2336         char *caller_pkgname = NULL;
2337
2338         if (pkgname == NULL) {
2339                 caller_pkgname = _notification_get_pkgname_by_pid();
2340         } else {
2341                 caller_pkgname = strdup(pkgname);
2342         }
2343
2344         ret = notification_noti_delete_all(type, caller_pkgname, &num_deleted, &list_deleted);
2345         if (ret != NOTIFICATION_ERROR_NONE) {
2346                 free(caller_pkgname);
2347                 return ret;
2348         }
2349
2350         /* Send chagned notification */
2351         if (num_deleted > 0 && list_deleted != NULL) {
2352                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, num_deleted, list_deleted, num_deleted);
2353                 if (noti_op != NULL) {
2354                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, num_deleted);
2355                         free(noti_op);
2356                 }
2357         }
2358         if (caller_pkgname != NULL) {
2359                 free(caller_pkgname);
2360                 caller_pkgname = NULL;
2361         }
2362         if (list_deleted != NULL) {
2363                 free(list_deleted);
2364                 list_deleted = NULL;
2365         }
2366
2367         return ret;
2368 }
2369
2370 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
2371                                                                       notification_type_e type,
2372                                                                       int group_id)
2373 {
2374         int ret = 0;
2375         int num_deleted = 0;
2376         int *list_deleted = NULL;
2377         char *caller_pkgname = NULL;
2378
2379         if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2380                 return NOTIFICATION_ERROR_INVALID_DATA;
2381         }
2382
2383         if (pkgname == NULL) {
2384                 caller_pkgname = _notification_get_pkgname_by_pid();
2385         } else {
2386                 caller_pkgname = strdup(pkgname);
2387         }
2388
2389         ret =
2390             notification_noti_delete_group_by_group_id(caller_pkgname,
2391                                                        group_id, &num_deleted, &list_deleted);
2392         if (ret != NOTIFICATION_ERROR_NONE) {
2393                 free(caller_pkgname);
2394                 return ret;
2395         }
2396
2397         if (num_deleted > 0 && list_deleted != NULL) {
2398                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, num_deleted, list_deleted, num_deleted);
2399                 if (noti_op != NULL) {
2400                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, num_deleted);
2401                         free(noti_op);
2402                 }
2403         }
2404
2405         if (caller_pkgname != NULL) {
2406                 free(caller_pkgname);
2407                 caller_pkgname = NULL;
2408         }
2409         if (list_deleted != NULL) {
2410                 free(list_deleted);
2411                 list_deleted = NULL;
2412         }
2413
2414         return ret;
2415 }
2416
2417 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2418                                                                      notification_type_e type,
2419                                                                      int priv_id)
2420 {
2421         int ret = 0;
2422         char *caller_pkgname = NULL;
2423
2424         if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2425                 return NOTIFICATION_ERROR_INVALID_DATA;
2426         }
2427
2428         if (pkgname == NULL) {
2429                 caller_pkgname = _notification_get_pkgname_by_pid();
2430         } else {
2431                 caller_pkgname = strdup(pkgname);
2432         }
2433
2434         ret =
2435             notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id);
2436         if (ret != NOTIFICATION_ERROR_NONE) {
2437                 free(caller_pkgname);
2438                 return ret;
2439         }
2440
2441         notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, 1, NULL, 0);
2442         if (noti_op != NULL) {
2443                 _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2444                 free(noti_op);
2445         }
2446
2447         free(caller_pkgname);
2448
2449         return ret;
2450 }
2451
2452 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
2453                                                                notification_type_e type,
2454                                                                int priv_id)
2455 {
2456         int ret = 0;
2457         char *caller_pkgname = NULL;
2458
2459         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2460                 return NOTIFICATION_ERROR_INVALID_DATA;
2461         }
2462
2463         if (pkgname == NULL) {
2464                 caller_pkgname = _notification_get_pkgname_by_pid();
2465         } else {
2466                 caller_pkgname = strdup(pkgname);
2467         }
2468
2469         ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id);
2470         if (ret != NOTIFICATION_ERROR_NONE) {
2471                 free(caller_pkgname);
2472                 return ret;
2473         }
2474
2475         notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1);
2476         if (noti_op != NULL) {
2477                 _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2478                 free(noti_op);
2479         }
2480
2481         free(caller_pkgname);
2482
2483         return ret;
2484 }
2485
2486 EXPORT_API notification_error_e notification_delete(notification_h noti)
2487 {
2488         int ret = 0;
2489
2490         if (noti == NULL) {
2491                 return NOTIFICATION_ERROR_INVALID_DATA;
2492         }
2493
2494         ret =
2495             notification_noti_delete_by_priv_id(noti->caller_pkgname,
2496                                                 noti->priv_id);
2497         if (ret != NOTIFICATION_ERROR_NONE) {
2498                 return ret;
2499         }
2500
2501         if (noti->flags_for_property
2502                 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) {
2503                 NOTIFICATION_INFO("Disabled update while delete.");
2504         } else {
2505                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, 1, &(noti->priv_id), 1);
2506                 if (noti_op != NULL) {
2507                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2508                         free(noti_op);
2509                 }
2510         }
2511
2512         return NOTIFICATION_ERROR_NONE;
2513 }
2514
2515 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
2516                                                              int priv_id,
2517                                                              double progress)
2518 {
2519         char *caller_pkgname = NULL;
2520         int input_priv_id = 0;
2521         double input_progress = 0.0;
2522
2523         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2524                 if (noti == NULL) {
2525                         return NOTIFICATION_ERROR_INVALID_DATA;
2526                 } else {
2527                         input_priv_id = noti->priv_id;
2528                 }
2529         } else {
2530                 input_priv_id = priv_id;
2531         }
2532
2533         if (noti == NULL) {
2534                 caller_pkgname = _notification_get_pkgname_by_pid();
2535         } else {
2536                 caller_pkgname = strdup(noti->caller_pkgname);
2537         }
2538
2539         if (progress < 0.0) {
2540                 input_progress = 0.0;
2541         } else if (progress > 1.0) {
2542                 input_progress = 1.0;
2543         } else {
2544                 input_progress = progress;
2545         }
2546
2547         notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2548                                              input_progress);
2549
2550         if (caller_pkgname) {
2551                 free(caller_pkgname);
2552         }
2553
2554         return NOTIFICATION_ERROR_NONE;
2555 }
2556
2557 EXPORT_API notification_error_e notification_update_size(notification_h noti,
2558                                                          int priv_id,
2559                                                          double size)
2560 {
2561         char *caller_pkgname = NULL;
2562         int input_priv_id = 0;
2563         double input_size = 0.0;
2564
2565         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2566                 if (noti == NULL) {
2567                         return NOTIFICATION_ERROR_INVALID_DATA;
2568                 } else {
2569                         input_priv_id = noti->priv_id;
2570                 }
2571         } else {
2572                 input_priv_id = priv_id;
2573         }
2574
2575         if (noti == NULL) {
2576                 caller_pkgname = _notification_get_pkgname_by_pid();
2577         } else {
2578                 caller_pkgname = strdup(noti->caller_pkgname);
2579         }
2580
2581         if (size < 0.0) {
2582                 input_size = 0.0;
2583         } else {
2584                 input_size = size;
2585         }
2586
2587         notification_ongoing_update_size(caller_pkgname, input_priv_id,
2588                                          input_size);
2589
2590         if (caller_pkgname) {
2591                 free(caller_pkgname);
2592         }
2593
2594         return NOTIFICATION_ERROR_NONE;
2595 }
2596
2597 EXPORT_API notification_error_e notification_update_content(notification_h noti,
2598                                                          int priv_id,
2599                                                          const char *content)
2600 {
2601         char *caller_pkgname = NULL;
2602         int input_priv_id = 0;
2603
2604         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2605                 if (noti == NULL) {
2606                         return NOTIFICATION_ERROR_INVALID_DATA;
2607                 } else {
2608                         input_priv_id = noti->priv_id;
2609                 }
2610         } else {
2611                 input_priv_id = priv_id;
2612         }
2613
2614         if (noti == NULL) {
2615                 caller_pkgname = _notification_get_pkgname_by_pid();
2616         } else {
2617                 caller_pkgname = strdup(noti->caller_pkgname);
2618         }
2619
2620         notification_ongoing_update_content(caller_pkgname, input_priv_id,
2621                                          content);
2622
2623         if (caller_pkgname) {
2624                 free(caller_pkgname);
2625         }
2626
2627         return NOTIFICATION_ERROR_NONE;
2628 }
2629
2630 static notification_h _notification_create(notification_type_e type) {
2631         notification_h noti = NULL;
2632
2633         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2634                 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2635                 return NULL;
2636         }
2637
2638         noti = (notification_h) malloc(sizeof(struct _notification));
2639         if (noti == NULL) {
2640                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2641                 return NULL;
2642         }
2643         memset(noti, 0x00, sizeof(struct _notification));
2644
2645         noti->type = type;
2646
2647         if (type == NOTIFICATION_TYPE_NOTI)
2648                 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2649         else if (type == NOTIFICATION_TYPE_ONGOING)
2650                 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
2651
2652         noti->group_id = NOTIFICATION_GROUP_ID_NONE;
2653         noti->internal_group_id = 0;
2654         noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
2655
2656         noti->caller_pkgname = _notification_get_pkgname_by_pid();
2657         noti->launch_pkgname = NULL;
2658         noti->args = NULL;
2659         noti->group_args = NULL;
2660
2661         noti->b_execute_option = NULL;
2662         noti->b_service_responding = NULL;
2663         noti->b_service_single_launch = NULL;
2664         noti->b_service_multi_launch = NULL;
2665
2666         noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2667         noti->sound_path = NULL;
2668
2669         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2670         noti->vibration_path = NULL;
2671
2672         noti->domain = NULL;
2673         noti->dir = NULL;
2674
2675         noti->b_text = NULL;
2676         noti->b_key = NULL;
2677         noti->b_format_args = NULL;
2678         noti->num_format_args = 0;
2679
2680         noti->b_image_path = NULL;
2681
2682         noti->time = 0;
2683         noti->insert_time = 0;
2684
2685         noti->flags_for_property = 0;
2686         noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2687
2688         noti->progress_size = 0.0;
2689         noti->progress_percentage = 0.0;
2690
2691         noti->app_icon_path = NULL;
2692         noti->app_name = NULL;
2693         noti->temp_title = NULL;
2694         noti->temp_content = NULL;
2695
2696         return noti;
2697 }
2698
2699 EXPORT_API notification_h notification_new(notification_type_e type,
2700                                            int group_id, int priv_id)
2701 {
2702         return _notification_create(type);
2703 }
2704
2705 EXPORT_API notification_h notification_create(notification_type_e type)
2706 {
2707         return _notification_create(type);
2708 }
2709
2710 EXPORT_API notification_h notification_load(char *pkgname,
2711                                                       int priv_id)
2712 {
2713         int ret = 0;
2714         notification_h noti = NULL;
2715
2716         noti = (notification_h) malloc(sizeof(struct _notification));
2717         if (noti == NULL) {
2718                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2719                 return NULL;
2720         }
2721         memset(noti, 0x00, sizeof(struct _notification));
2722
2723         ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id);
2724         if (ret != NOTIFICATION_ERROR_NONE) {
2725                 notification_free(noti);
2726                 return NULL;
2727         }
2728
2729         return noti;
2730 }
2731
2732 EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone)
2733 {
2734         notification_h new_noti = NULL;
2735
2736         if (noti == NULL || clone == NULL) {
2737                 NOTIFICATION_ERR("INVALID PARAMETER.");
2738                 return NOTIFICATION_ERROR_INVALID_DATA;
2739         }
2740
2741         new_noti = (notification_h) malloc(sizeof(struct _notification));
2742         if (new_noti == NULL) {
2743                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2744                 return NOTIFICATION_ERROR_NO_MEMORY;
2745         }
2746         memset(new_noti, 0x00, sizeof(struct _notification));
2747
2748         new_noti->type = noti->type;
2749         new_noti->layout = noti->layout;
2750
2751         new_noti->group_id = noti->group_id;
2752         new_noti->internal_group_id = noti->internal_group_id;
2753         new_noti->priv_id = noti->priv_id;
2754
2755         if(noti->caller_pkgname != NULL) {
2756                 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2757         } else {
2758                 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2759         }
2760         if(noti->launch_pkgname != NULL) {
2761                 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2762         } else {
2763                 new_noti->launch_pkgname = NULL;
2764         }
2765
2766         if(noti->args != NULL) {
2767                 new_noti->args = bundle_dup(noti->args);
2768         } else {
2769                 new_noti->args = NULL;
2770         }
2771         if(noti->group_args != NULL) {
2772                 new_noti->group_args = bundle_dup(noti->group_args);
2773         } else {
2774                 new_noti->group_args = NULL;
2775         }
2776
2777         if(noti->b_execute_option != NULL) {
2778                 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2779         } else {
2780                 new_noti->b_execute_option = NULL;
2781         }
2782         if(noti->b_service_responding != NULL) {
2783                 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2784         } else {
2785                 new_noti->b_service_responding = NULL;
2786         }
2787         if(noti->b_service_single_launch != NULL) {
2788                 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2789         } else {
2790                 new_noti->b_service_single_launch = NULL;
2791         }
2792         if(noti->b_service_multi_launch != NULL) {
2793                 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2794         } else {
2795                 new_noti->b_service_multi_launch = NULL;
2796         }
2797
2798         new_noti->sound_type = noti->sound_type;
2799         if(noti->sound_path != NULL) {
2800                 new_noti->sound_path = strdup(noti->sound_path);
2801         } else {
2802                 new_noti->sound_path = NULL;
2803         }
2804         new_noti->vibration_type = noti->vibration_type;
2805         if(noti->vibration_path != NULL) {
2806                 new_noti->vibration_path = strdup(noti->vibration_path);
2807         } else {
2808                 new_noti->vibration_path = NULL;
2809         }
2810
2811         if(noti->domain != NULL) {
2812                 new_noti->domain = strdup(noti->domain);
2813         } else {
2814                 new_noti->domain = NULL;
2815         }
2816         if(noti->dir != NULL) {
2817                 new_noti->dir = strdup(noti->dir);
2818         } else {
2819                 new_noti->dir = NULL;
2820         }
2821
2822         if(noti->b_text != NULL) {
2823                 new_noti->b_text = bundle_dup(noti->b_text);
2824         } else {
2825                 new_noti->b_text = NULL;
2826         }
2827         if(noti->b_key != NULL) {
2828                 new_noti->b_key = bundle_dup(noti->b_key);
2829         } else {
2830                 new_noti->b_key = NULL;
2831         }
2832         if(noti->b_format_args != NULL) {
2833                 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2834         } else {
2835                 new_noti->b_format_args = NULL;
2836         }
2837         new_noti->num_format_args = noti->num_format_args;
2838
2839         if(noti->b_image_path != NULL) {
2840                 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2841         } else {
2842                 new_noti->b_image_path = NULL;
2843         }
2844
2845         new_noti->time = noti->time;
2846         new_noti->insert_time = noti->insert_time;
2847
2848         new_noti->flags_for_property = noti->flags_for_property;
2849         new_noti->display_applist = noti->display_applist;
2850
2851         new_noti->progress_size = noti->progress_size;
2852         new_noti->progress_percentage = noti->progress_percentage;
2853
2854         new_noti->app_icon_path = NULL;
2855         new_noti->app_name = NULL;
2856         new_noti->temp_title = NULL;
2857         new_noti->temp_content = NULL;
2858
2859         *clone = new_noti;
2860
2861         return NOTIFICATION_ERROR_NONE;
2862 }
2863
2864
2865 EXPORT_API notification_error_e notification_free(notification_h noti)
2866 {
2867         if (noti == NULL) {
2868                 return NOTIFICATION_ERROR_INVALID_DATA;
2869         }
2870
2871         if (noti->caller_pkgname) {
2872                 free(noti->caller_pkgname);
2873         }
2874         if (noti->launch_pkgname) {
2875                 free(noti->launch_pkgname);
2876         }
2877         if (noti->args) {
2878                 bundle_free(noti->args);
2879         }
2880         if (noti->group_args) {
2881                 bundle_free(noti->group_args);
2882         }
2883
2884         if (noti->b_execute_option) {
2885                 bundle_free(noti->b_execute_option);
2886         }
2887         if (noti->b_service_responding) {
2888                 bundle_free(noti->b_service_responding);
2889         }
2890         if (noti->b_service_single_launch) {
2891                 bundle_free(noti->b_service_single_launch);
2892         }
2893         if (noti->b_service_multi_launch) {
2894                 bundle_free(noti->b_service_multi_launch);
2895         }
2896
2897         if (noti->sound_path) {
2898                 free(noti->sound_path);
2899         }
2900         if (noti->vibration_path) {
2901                 free(noti->vibration_path);
2902         }
2903
2904         if (noti->domain) {
2905                 free(noti->domain);
2906         }
2907         if (noti->dir) {
2908                 free(noti->dir);
2909         }
2910
2911         if (noti->b_text) {
2912                 bundle_free(noti->b_text);
2913         }
2914         if (noti->b_key) {
2915                 bundle_free(noti->b_key);
2916         }
2917         if (noti->b_format_args) {
2918                 bundle_free(noti->b_format_args);
2919         }
2920
2921         if (noti->b_image_path) {
2922                 bundle_free(noti->b_image_path);
2923         }
2924
2925         if (noti->app_icon_path) {
2926                 free(noti->app_icon_path);
2927         }
2928         if (noti->app_name) {
2929                 free(noti->app_name);
2930         }
2931         if (noti->temp_title) {
2932                 free(noti->temp_title);
2933         }
2934         if (noti->temp_content) {
2935                 free(noti->temp_content);
2936         }
2937
2938         free(noti);
2939
2940         return NOTIFICATION_ERROR_NONE;
2941 }
2942
2943 EXPORT_API notification_error_e
2944 notification_resister_changed_cb(void (*changed_cb)
2945                                  (void *data, notification_type_e type),
2946                                  void *user_data)
2947 {
2948         notification_cb_list_s *noti_cb_list_new = NULL;
2949         notification_cb_list_s *noti_cb_list = NULL;
2950
2951         if (!g_dbus_handle) {
2952                 g_dbus_handle = _noti_changed_monitor_init();
2953                 if (!g_dbus_handle)
2954                         return NOTIFICATION_ERROR_FROM_DBUS;
2955         }
2956
2957         noti_cb_list_new =
2958             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2959
2960         noti_cb_list_new->next = NULL;
2961         noti_cb_list_new->prev = NULL;
2962
2963         noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
2964         noti_cb_list_new->changed_cb = changed_cb;
2965         noti_cb_list_new->detailed_changed_cb = NULL;
2966         noti_cb_list_new->data = user_data;
2967
2968         if (g_notification_cb_list == NULL) {
2969                 g_notification_cb_list = noti_cb_list_new;
2970         } else {
2971                 noti_cb_list = g_notification_cb_list;
2972
2973                 while (noti_cb_list->next != NULL) {
2974                         noti_cb_list = noti_cb_list->next;
2975                 }
2976
2977                 noti_cb_list->next = noti_cb_list_new;
2978                 noti_cb_list_new->prev = noti_cb_list;
2979         }
2980         return NOTIFICATION_ERROR_NONE;
2981 }
2982
2983 EXPORT_API notification_error_e
2984 notification_unresister_changed_cb(void (*changed_cb)
2985                                    (void *data, notification_type_e type))
2986 {
2987         notification_cb_list_s *noti_cb_list = NULL;
2988         notification_cb_list_s *noti_cb_list_prev = NULL;
2989         notification_cb_list_s *noti_cb_list_next = NULL;
2990
2991         noti_cb_list = g_notification_cb_list;
2992
2993         if (noti_cb_list == NULL) {
2994                 return NOTIFICATION_ERROR_INVALID_DATA;
2995         }
2996
2997         while (noti_cb_list->prev != NULL) {
2998                 noti_cb_list = noti_cb_list->prev;
2999         }
3000
3001         do {
3002                 if (noti_cb_list->changed_cb == changed_cb) {
3003                         noti_cb_list_prev = noti_cb_list->prev;
3004                         noti_cb_list_next = noti_cb_list->next;
3005
3006                         if (noti_cb_list_prev == NULL) {
3007                                 g_notification_cb_list = noti_cb_list_next;
3008                         } else {
3009                                 noti_cb_list_prev->next = noti_cb_list_next;
3010                         }
3011
3012                         if (noti_cb_list_next == NULL) {
3013                                 if (noti_cb_list_prev != NULL) {
3014                                         noti_cb_list_prev->next = NULL;
3015                                 }
3016                         } else {
3017                                 noti_cb_list_next->prev = noti_cb_list_prev;
3018                         }
3019
3020                         free(noti_cb_list);
3021
3022                         if (g_notification_cb_list == NULL)
3023                                 _noti_chanaged_monitor_fini();
3024
3025                         return NOTIFICATION_ERROR_NONE;
3026                 }
3027                 noti_cb_list = noti_cb_list->next;
3028         } while (noti_cb_list != NULL);
3029
3030         return NOTIFICATION_ERROR_INVALID_DATA;
3031 }
3032
3033 EXPORT_API notification_error_e
3034 notification_register_detailed_changed_cb(
3035                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
3036                 void *user_data)
3037 {
3038         notification_cb_list_s *noti_cb_list_new = NULL;
3039         notification_cb_list_s *noti_cb_list = NULL;
3040
3041         if (!g_dbus_handle) {
3042                 g_dbus_handle = _noti_changed_monitor_init();
3043                 if (!g_dbus_handle)
3044                         return NOTIFICATION_ERROR_FROM_DBUS;
3045         }
3046
3047         noti_cb_list_new =
3048             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
3049
3050         noti_cb_list_new->next = NULL;
3051         noti_cb_list_new->prev = NULL;
3052
3053         noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
3054         noti_cb_list_new->changed_cb = NULL;
3055         noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
3056         noti_cb_list_new->data = user_data;
3057
3058         if (g_notification_cb_list == NULL) {
3059                 g_notification_cb_list = noti_cb_list_new;
3060         } else {
3061                 noti_cb_list = g_notification_cb_list;
3062
3063                 while (noti_cb_list->next != NULL) {
3064                         noti_cb_list = noti_cb_list->next;
3065                 }
3066
3067                 noti_cb_list->next = noti_cb_list_new;
3068                 noti_cb_list_new->prev = noti_cb_list;
3069         }
3070         return NOTIFICATION_ERROR_NONE;
3071 }
3072
3073 EXPORT_API notification_error_e
3074 notification_unregister_detailed_changed_cb(
3075                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op_type_e op_type, int *list_priv_id, int num_priv_id),
3076                 void *user_data)
3077 {
3078         notification_cb_list_s *noti_cb_list = NULL;
3079         notification_cb_list_s *noti_cb_list_prev = NULL;
3080         notification_cb_list_s *noti_cb_list_next = NULL;
3081
3082         noti_cb_list = g_notification_cb_list;
3083
3084         if (noti_cb_list == NULL) {
3085                 return NOTIFICATION_ERROR_INVALID_DATA;
3086         }
3087
3088         while (noti_cb_list->prev != NULL) {
3089                 noti_cb_list = noti_cb_list->prev;
3090         }
3091
3092         do {
3093                 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
3094                         noti_cb_list_prev = noti_cb_list->prev;
3095                         noti_cb_list_next = noti_cb_list->next;
3096
3097                         if (noti_cb_list_prev == NULL) {
3098                                 g_notification_cb_list = noti_cb_list_next;
3099                         } else {
3100                                 noti_cb_list_prev->next = noti_cb_list_next;
3101                         }
3102
3103                         if (noti_cb_list_next == NULL) {
3104                                 if (noti_cb_list_prev != NULL) {
3105                                         noti_cb_list_prev->next = NULL;
3106                                 }
3107                         } else {
3108                                 noti_cb_list_next->prev = noti_cb_list_prev;
3109                         }
3110
3111                         free(noti_cb_list);
3112
3113                         if (g_notification_cb_list == NULL)
3114                                 _noti_chanaged_monitor_fini();
3115
3116                         return NOTIFICATION_ERROR_NONE;
3117                 }
3118                 noti_cb_list = noti_cb_list->next;
3119         } while (noti_cb_list != NULL);
3120
3121         return NOTIFICATION_ERROR_INVALID_DATA;
3122 }
3123
3124 EXPORT_API notification_error_e
3125 notification_resister_badge_changed_cb(void (*changed_cb)
3126                                        (void *data, const char *pkgname,
3127                                         int group_id), void *user_data)
3128 {
3129         // Add DBus signal handler
3130         return NOTIFICATION_ERROR_NONE;
3131 }
3132
3133 EXPORT_API notification_error_e
3134 notification_unresister_badge_changed_cb(void (*changed_cb)
3135                                          (void *data, const char *pkgname,
3136                                           int group_id))
3137 {
3138         // Del DBus signal handler
3139         return NOTIFICATION_ERROR_NONE;
3140 }
3141
3142 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
3143                                                        const char *pkgname,
3144                                                        int group_id,
3145                                                        int priv_id, int *count)
3146 {
3147         int ret = 0;
3148         int noti_count = 0;
3149
3150         ret =
3151             notification_noti_get_count(type, pkgname, group_id, priv_id,
3152                                         &noti_count);
3153         if (ret != NOTIFICATION_ERROR_NONE) {
3154                 return ret;
3155         }
3156
3157         if (count != NULL) {
3158                 *count = noti_count;
3159         }
3160
3161         return NOTIFICATION_ERROR_NONE;
3162 }
3163
3164 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
3165                                                       int count,
3166                                                       notification_list_h *list)
3167 {
3168         notification_list_h get_list = NULL;
3169         int ret = 0;
3170
3171         ret = notification_noti_get_grouping_list(type, count, &get_list);
3172         if (ret != NOTIFICATION_ERROR_NONE) {
3173                 return ret;
3174         }
3175
3176         *list = get_list;
3177
3178         return NOTIFICATION_ERROR_NONE;
3179 }
3180
3181 EXPORT_API notification_error_e
3182 notification_get_grouping_list(notification_type_e type, int count,
3183                                notification_list_h * list)
3184 {
3185         notification_list_h get_list = NULL;
3186         int ret = 0;
3187
3188         ret = notification_noti_get_grouping_list(type, count, &get_list);
3189         if (ret != NOTIFICATION_ERROR_NONE) {
3190                 return ret;
3191         }
3192
3193         *list = get_list;
3194
3195         return NOTIFICATION_ERROR_NONE;
3196 }
3197
3198 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
3199                                                              int group_id,
3200                                                              int priv_id,
3201                                                              int count,
3202                                                              notification_list_h *list)
3203 {
3204         notification_list_h get_list = NULL;
3205         int ret = 0;
3206
3207         ret =
3208             notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
3209                                               &get_list);
3210         if (ret != NOTIFICATION_ERROR_NONE) {
3211                 return ret;
3212         }
3213
3214         *list = get_list;
3215
3216         return NOTIFICATION_ERROR_NONE;
3217 }
3218
3219 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
3220 {
3221         notification_list_h cur_list = NULL;
3222         notification_h noti = NULL;
3223
3224         if (list == NULL) {
3225                 NOTIFICATION_ERR("INVALID DATA : list == NULL");
3226                 return NOTIFICATION_ERROR_INVALID_DATA;
3227         }
3228
3229         cur_list = notification_list_get_head(list);
3230
3231         while (cur_list != NULL) {
3232                 noti = notification_list_get_data(cur_list);
3233                 cur_list = notification_list_remove(cur_list, noti);
3234
3235                 notification_free(noti);
3236         }
3237
3238         return NOTIFICATION_ERROR_NONE;
3239 }
3240
3241 EXPORT_API notification_error_e notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
3242                                                        void *data)
3243 {
3244         if (noti_op == NULL) {
3245                 return NOTIFICATION_ERROR_INVALID_DATA;
3246         }
3247
3248         switch (type) {
3249                 case NOTIFICATION_OP_DATA_TYPE:
3250                         *((int*)data) = noti_op->type;
3251                         break;
3252                 case NOTIFICATION_OP_DATA_PRIV_ID:
3253                         *((int*)data) = noti_op->priv_id;
3254                         break;
3255                 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
3256                         *((int*)data) = noti_op->extra_info_1;
3257                         break;
3258                 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
3259                         *((int*)data) = noti_op->extra_info_2;
3260                         break;
3261                 default:
3262                         return NOTIFICATION_ERROR_INVALID_DATA;
3263                         break;
3264         }
3265
3266         return NOTIFICATION_ERROR_NONE;
3267 }