sync with private git
[apps/home/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_led(notification_h noti,
1665                                                            notification_led_op_e operation,
1666                                                            int led_argb)
1667 {
1668         /* Check noti is valid data */
1669         if (noti == NULL) {
1670                 return NOTIFICATION_ERROR_INVALID_DATA;
1671         }
1672
1673         /* Check operation is valid */
1674         if (operation < NOTIFICATION_LED_OP_OFF
1675             || operation >= NOTIFICATION_LED_OP_MAX) {
1676                 return NOTIFICATION_ERROR_INVALID_DATA;
1677         }
1678
1679         /* Save led operation */
1680         noti->led_operation = operation;
1681
1682         /* Save led argb if operation is turning on LED with custom color */
1683         if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1684                 noti->led_argb = led_argb;
1685         }
1686
1687         return NOTIFICATION_ERROR_NONE;
1688 }
1689
1690 EXPORT_API notification_error_e notification_get_led(notification_h noti,
1691                                                            notification_led_op_e *operation,
1692                                                            int *led_argb)
1693 {
1694         /* check noti and operation is valid data */
1695         if (noti == NULL || operation == NULL) {
1696                 return NOTIFICATION_ERROR_INVALID_DATA;
1697         }
1698
1699         /* Set led operation */
1700         *operation = noti->led_operation;
1701
1702         /* Save led argb if operation is turning on LED with custom color */
1703         if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1704             && led_argb != NULL) {
1705                 *led_argb = noti->led_argb;
1706         }
1707
1708         return NOTIFICATION_ERROR_NONE;
1709 }
1710
1711 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1712                                                              const char *pkgname)
1713 {
1714         if (noti == NULL || pkgname == NULL) {
1715                 return NOTIFICATION_ERROR_INVALID_DATA;
1716         }
1717
1718         if (noti->launch_pkgname) {
1719                 free(noti->launch_pkgname);
1720         }
1721
1722         noti->launch_pkgname = strdup(pkgname);
1723
1724         return NOTIFICATION_ERROR_NONE;
1725 }
1726
1727 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1728                                                              char **pkgname)
1729 {
1730         if (noti == NULL || pkgname == NULL) {
1731                 return NOTIFICATION_ERROR_INVALID_DATA;
1732         }
1733
1734         if (noti->launch_pkgname) {
1735                 *pkgname = noti->launch_pkgname;
1736         } else {
1737                 *pkgname = noti->caller_pkgname;
1738         }
1739
1740         return NOTIFICATION_ERROR_NONE;
1741 }
1742
1743 EXPORT_API notification_error_e notification_set_args(notification_h noti,
1744                                                       bundle * args,
1745                                                       bundle * group_args)
1746 {
1747         if (noti == NULL || args == NULL) {
1748                 return NOTIFICATION_ERROR_INVALID_DATA;
1749         }
1750
1751         if (noti->args) {
1752                 bundle_free(noti->args);
1753         }
1754
1755         noti->args = bundle_dup(args);
1756
1757         if (noti->group_args) {
1758                 bundle_free(noti->group_args);
1759                 noti->group_args = NULL;
1760         }
1761
1762         if (group_args != NULL) {
1763                 noti->group_args = bundle_dup(group_args);
1764         }
1765
1766         return NOTIFICATION_ERROR_NONE;
1767 }
1768
1769 EXPORT_API notification_error_e notification_get_args(notification_h noti,
1770                                                       bundle ** args,
1771                                                       bundle ** group_args)
1772 {
1773         if (noti == NULL || args == NULL) {
1774                 return NOTIFICATION_ERROR_INVALID_DATA;
1775         }
1776
1777         if (noti->args) {
1778                 *args = noti->args;
1779         } else {
1780                 *args = NULL;
1781         }
1782
1783         if (group_args != NULL && noti->group_args) {
1784                 *group_args = noti->group_args;
1785         }
1786
1787         return NOTIFICATION_ERROR_NONE;
1788 }
1789
1790 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1791                                                                 notification_execute_type_e type,
1792                                                                 const char *text,
1793                                                                 const char *key,
1794                                                                 bundle *service_handle)
1795 {
1796         char buf_key[32] = { 0, };
1797         const char *ret_val = NULL;
1798         bundle *b = NULL;
1799
1800         if (noti == NULL) {
1801                 return NOTIFICATION_ERROR_INVALID_DATA;
1802         }
1803
1804         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1805             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1806                 return NOTIFICATION_ERROR_INVALID_DATA;
1807         }
1808
1809         /* Create execute option bundle if does not exist */
1810         if (noti->b_execute_option != NULL) {
1811                 noti->b_execute_option = bundle_create();
1812         }
1813
1814         b = noti->b_execute_option;
1815
1816         /* Save text */
1817         if (text != NULL) {
1818                 /* Make text key */
1819                 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1820
1821                 /* Check text key exist */
1822                 ret_val = bundle_get_val(b, buf_key);
1823                 if (ret_val != NULL) {
1824                         /* Remove previous data */
1825                         bundle_del(b, buf_key);
1826                 }
1827
1828                 /* Add text data */
1829                 bundle_add(b, buf_key, text);
1830         }
1831
1832         /* Save key */
1833         if (key != NULL) {
1834                 /* Make key key */
1835                 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1836
1837                 /* Check key key exist */
1838                 ret_val = bundle_get_val(b, buf_key);
1839                 if (ret_val != NULL) {
1840                         /* Remove previous data */
1841                         bundle_del(b, buf_key);
1842                 }
1843
1844                 /* Add text data */
1845                 bundle_add(b, buf_key, key);
1846         }
1847
1848         switch (type) {
1849         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1850                 /* Remove previous data if exist */
1851                 if (noti->b_service_responding != NULL) {
1852                         bundle_free(noti->b_service_responding);
1853                         noti->b_service_responding = NULL;
1854                 }
1855
1856                 /* Save service handle */
1857                 if (service_handle != NULL) {
1858                         noti->b_service_responding = bundle_dup(service_handle);
1859                 }
1860                 break;
1861         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1862                 /* Remove previous data if exist */
1863                 if (noti->b_service_single_launch != NULL) {
1864                         bundle_free(noti->b_service_single_launch);
1865                         noti->b_service_single_launch = NULL;
1866                 }
1867
1868                 /* Save service handle */
1869                 if (service_handle != NULL) {
1870                         noti->b_service_single_launch =
1871                             bundle_dup(service_handle);
1872                 }
1873                 break;
1874         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1875                 /* Remove previous data if exist */
1876                 if (noti->b_service_multi_launch != NULL) {
1877                         bundle_free(noti->b_service_multi_launch);
1878                         noti->b_service_multi_launch = NULL;
1879                 }
1880
1881                 /* Save service handle */
1882                 if (service_handle != NULL) {
1883                         noti->b_service_multi_launch =
1884                             bundle_dup(service_handle);
1885                 }
1886                 break;
1887         }
1888
1889         return NOTIFICATION_ERROR_NONE;
1890 }
1891
1892 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1893                                                                 notification_execute_type_e type,
1894                                                                 const char **text,
1895                                                                 bundle **service_handle)
1896 {
1897         char buf_key[32] = { 0, };
1898         const char *ret_val = NULL;
1899         char *get_str = NULL;
1900         bundle *b = NULL;
1901
1902         if (noti == NULL) {
1903                 return NOTIFICATION_ERROR_INVALID_DATA;
1904         }
1905
1906         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1907             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1908                 return NOTIFICATION_ERROR_INVALID_DATA;
1909         }
1910
1911         switch (type) {
1912         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1913                 b = noti->b_service_responding;
1914                 break;
1915         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1916                 b = noti->b_service_single_launch;
1917                 break;
1918         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1919                 b = noti->b_service_multi_launch;
1920                 break;
1921         default:
1922                 b = NULL;
1923                 break;
1924         }
1925
1926         if (b != NULL) {
1927                 // Return text
1928                 if (text != NULL) {
1929                         // Get text domain and dir
1930                         if (noti->domain == NULL || noti->dir == NULL) {
1931                                 _notification_get_text_domain(noti);
1932                         }
1933
1934                         /* Make key */
1935                         snprintf(buf_key, sizeof(buf_key), "key%d", type);
1936
1937                         /* Check key key exist */
1938                         ret_val = bundle_get_val(b, buf_key);
1939                         if (ret_val != NULL && noti->domain != NULL
1940                             && noti->dir != NULL) {
1941                                 /* Get application string */
1942                                 bindtextdomain(noti->domain, noti->dir);
1943
1944                                 get_str = dgettext(noti->domain, ret_val);
1945
1946                                 *text = get_str;
1947                         } else if (ret_val != NULL) {
1948                                 /* Get system string */
1949                                 get_str = dgettext("sys_string", ret_val);
1950
1951                                 *text = get_str;
1952                         } else {
1953                                 /* Get basic text */
1954                                 snprintf(buf_key, sizeof(buf_key), "text%d",
1955                                          type);
1956
1957                                 ret_val = bundle_get_val(b, buf_key);
1958
1959                                 *text = ret_val;
1960                         }
1961                 }
1962         }
1963
1964         switch (type) {
1965         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1966                 b = noti->b_service_responding;
1967                 break;
1968         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1969                 b = noti->b_service_single_launch;
1970                 break;
1971         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1972                 b = noti->b_service_multi_launch;
1973                 break;
1974         default:
1975                 b = NULL;
1976                 break;
1977         }
1978
1979         if (service_handle != NULL) {
1980                 *service_handle = b;
1981         }
1982
1983         return NOTIFICATION_ERROR_NONE;
1984 }
1985
1986 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1987                                                           int flags)
1988 {
1989         /* Check noti is valid data */
1990         if (noti == NULL) {
1991                 return NOTIFICATION_ERROR_INVALID_DATA;
1992         }
1993
1994         /* Set flags */
1995         noti->flags_for_property = flags;
1996
1997         return NOTIFICATION_ERROR_NONE;
1998 }
1999
2000 EXPORT_API notification_error_e notification_get_property(notification_h noti,
2001                                                           int *flags)
2002 {
2003         /* Check noti and flags are valid data */
2004         if (noti == NULL || flags == NULL) {
2005                 return NOTIFICATION_ERROR_INVALID_DATA;
2006         }
2007
2008         /* Set flags */
2009         *flags = noti->flags_for_property;
2010
2011         return NOTIFICATION_ERROR_NONE;
2012 }
2013
2014 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
2015                                                                  int applist)
2016 {
2017         /* Check noti is valid data */
2018         if (noti == NULL) {
2019                 return NOTIFICATION_ERROR_INVALID_DATA;
2020         }
2021
2022         /* Set app list */
2023         noti->display_applist = applist;
2024
2025         return NOTIFICATION_ERROR_NONE;
2026 }
2027
2028 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
2029                                                                  int *applist)
2030 {
2031         /* Check noti and applist are valid data */
2032         if (noti == NULL || applist == NULL) {
2033                 return NOTIFICATION_ERROR_INVALID_DATA;
2034         }
2035
2036         /* Set app list */
2037         *applist = noti->display_applist;
2038
2039         return NOTIFICATION_ERROR_NONE;
2040 }
2041
2042 EXPORT_API notification_error_e notification_set_size(notification_h noti,
2043                                                       double size)
2044 {
2045         /* Check noti is valid data */
2046         if (noti == NULL) {
2047                 return NOTIFICATION_ERROR_INVALID_DATA;
2048         }
2049
2050         /* Save progress size */
2051         noti->progress_size = size;
2052
2053         return NOTIFICATION_ERROR_NONE;
2054 }
2055
2056 EXPORT_API notification_error_e notification_get_size(notification_h noti,
2057                                                       double *size)
2058 {
2059         /* Check noti and size is valid data */
2060         if (noti == NULL || size == NULL) {
2061                 return NOTIFICATION_ERROR_INVALID_DATA;
2062         }
2063
2064         /* Set progress size */
2065         *size = noti->progress_size;
2066
2067         return NOTIFICATION_ERROR_NONE;
2068 }
2069
2070 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
2071                                                           double percentage)
2072 {
2073         /* Check noti is valid data */
2074         if (noti == NULL) {
2075                 return NOTIFICATION_ERROR_INVALID_DATA;
2076         }
2077
2078         /* Save progress percentage */
2079         noti->progress_percentage = percentage;
2080
2081         return NOTIFICATION_ERROR_NONE;
2082 }
2083
2084 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
2085                                                           double *percentage)
2086 {
2087         /* Check noti and percentage are valid data */
2088         if (noti == NULL || percentage == NULL) {
2089                 return NOTIFICATION_ERROR_INVALID_DATA;
2090         }
2091
2092         /* Set progress percentage */
2093         *percentage = noti->progress_percentage;
2094
2095         return NOTIFICATION_ERROR_NONE;
2096 }
2097
2098 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
2099                                                          const char *pkgname)
2100 {
2101         /* check noti and pkgname are valid data */
2102         if (noti == NULL || pkgname == NULL) {
2103                 return NOTIFICATION_ERROR_INVALID_DATA;
2104         }
2105
2106         /* Remove previous caller pkgname */
2107         if (noti->caller_pkgname) {
2108                 free(noti->caller_pkgname);
2109                 noti->caller_pkgname = NULL;
2110         }
2111
2112         noti->caller_pkgname = strdup(pkgname);
2113
2114         return NOTIFICATION_ERROR_NONE;
2115 }
2116
2117 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
2118                                                          char **pkgname)
2119 {
2120         /* Check noti and pkgname are valid data */
2121         if (noti == NULL || pkgname == NULL) {
2122                 return NOTIFICATION_ERROR_INVALID_DATA;
2123         }
2124
2125         /* Get caller pkgname */
2126         if (noti->caller_pkgname) {
2127                 *pkgname = noti->caller_pkgname;
2128         } else {
2129                 *pkgname = NULL;
2130         }
2131
2132         return NOTIFICATION_ERROR_NONE;
2133 }
2134
2135 EXPORT_API notification_error_e notification_set_layout(notification_h noti,
2136                 notification_ly_type_e layout)
2137 {
2138         /* check noti and pkgname are valid data */
2139         if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
2140                 return NOTIFICATION_ERROR_INVALID_DATA;
2141         }
2142
2143         noti->layout = layout;
2144
2145         return NOTIFICATION_ERROR_NONE;
2146 }
2147
2148 EXPORT_API notification_error_e notification_get_layout(notification_h noti,
2149                 notification_ly_type_e *layout)
2150 {
2151         /* Check noti and pkgname are valid data */
2152         if (noti == NULL || layout == NULL) {
2153                 return NOTIFICATION_ERROR_INVALID_DATA;
2154         }
2155
2156         *layout = noti->layout;
2157
2158         return NOTIFICATION_ERROR_NONE;
2159 }
2160
2161 EXPORT_API notification_error_e notification_set_badge(const char *pkgname,
2162                                                        int group_id, int count)
2163 {
2164         char *caller_pkgname = NULL;
2165         int ret = NOTIFICATION_ERROR_NONE;
2166
2167         /* Check count is valid count */
2168         if (count < 0) {
2169                 return NOTIFICATION_ERROR_INVALID_DATA;
2170         }
2171
2172         /* Check pkgname */
2173         if (pkgname == NULL) {
2174                 caller_pkgname = _notification_get_pkgname_by_pid();
2175
2176                 /* Set count into Group DB */
2177                 ret =
2178                     notification_group_set_badge(caller_pkgname, group_id,
2179                                                  count);
2180
2181                 if (caller_pkgname != NULL) {
2182                         free(caller_pkgname);
2183                 }
2184         } else {
2185                 /* Set count into Group DB */
2186                 ret = notification_group_set_badge(pkgname, group_id, count);
2187         }
2188
2189         return ret;
2190 }
2191
2192 EXPORT_API notification_error_e notification_get_badge(const char *pkgname,
2193                                                        int group_id, int *count)
2194 {
2195         char *caller_pkgname = NULL;
2196         int ret = NOTIFICATION_ERROR_NONE;
2197         int ret_unread_count = 0;
2198
2199         /* Check pkgname */
2200         if (pkgname == NULL) {
2201                 caller_pkgname = _notification_get_pkgname_by_pid();
2202
2203                 /* Get count from Group DB */
2204                 ret =
2205                     notification_group_get_badge(caller_pkgname, group_id,
2206                                                  &ret_unread_count);
2207
2208                 if (caller_pkgname != NULL) {
2209                         free(caller_pkgname);
2210                 }
2211         } else {
2212                 /* Get count from Group DB */
2213                 ret =
2214                     notification_group_get_badge(pkgname, group_id,
2215                                                  &ret_unread_count);
2216         }
2217
2218         if (ret != NOTIFICATION_ERROR_NONE) {
2219                 return ret;
2220         }
2221
2222         /* Set count */
2223         if (count != NULL) {
2224                 *count = ret_unread_count;
2225         }
2226
2227         return NOTIFICATION_ERROR_NONE;
2228 }
2229
2230 EXPORT_API notification_error_e notification_get_id(notification_h noti,
2231                                                     int *group_id, int *priv_id)
2232 {
2233         /* check noti is valid data */
2234         if (noti == NULL) {
2235                 return NOTIFICATION_ERROR_INVALID_DATA;
2236         }
2237
2238         /* Check group_id is valid data */
2239         if (group_id) {
2240                 /* Set group id */
2241                 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
2242                         *group_id = NOTIFICATION_GROUP_ID_NONE;
2243                 } else {
2244                         *group_id = noti->group_id;
2245                 }
2246         }
2247
2248         /* Check priv_id is valid data */
2249         if (priv_id) {
2250                 /* Set priv_id */
2251                 *priv_id = noti->priv_id;
2252         }
2253
2254         return NOTIFICATION_ERROR_NONE;
2255 }
2256
2257 EXPORT_API notification_error_e notification_get_type(notification_h noti,
2258                                                       notification_type_e *type)
2259 {
2260         /* Check noti and type is valid data */
2261         if (noti == NULL || type == NULL) {
2262                 return NOTIFICATION_ERROR_INVALID_DATA;
2263         }
2264
2265         /* Set noti type */
2266         *type = noti->type;
2267
2268         return NOTIFICATION_ERROR_NONE;
2269 }
2270
2271 EXPORT_API notification_error_e notification_insert(notification_h noti,
2272                                                     int *priv_id)
2273 {
2274         int ret = 0;
2275
2276         /* Check noti is vaild data */
2277         if (noti == NULL) {
2278                 return NOTIFICATION_ERROR_INVALID_DATA;
2279         }
2280
2281         /* Check noti type is valid type */
2282         if (noti->type <= NOTIFICATION_TYPE_NONE
2283             || noti->type >= NOTIFICATION_TYPE_MAX) {
2284                 return NOTIFICATION_ERROR_INVALID_DATA;
2285         }
2286
2287         /* Save insert time */
2288         noti->insert_time = time(NULL);
2289
2290         /* Insert into DB */
2291         ret = notification_noti_insert(noti);
2292         if (ret != NOTIFICATION_ERROR_NONE) {
2293                 return ret;
2294         }
2295
2296         /* Check disable update on insert property */
2297         if (noti->flags_for_property
2298                 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
2299                 /* Disable changed cb */
2300         } else {
2301                 /* Enable changed cb */
2302                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1);
2303                 if (noti_op != NULL) {
2304                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2305                         free(noti_op);
2306                 }
2307         }
2308
2309         /* If priv_id is valid data, set priv_id */
2310         if (priv_id != NULL) {
2311                 *priv_id = noti->priv_id;
2312         }
2313
2314         return NOTIFICATION_ERROR_NONE;
2315 }
2316
2317 EXPORT_API notification_error_e notification_update(notification_h noti)
2318 {
2319         int ret = 0;
2320
2321         /* Check noti is valid data */
2322         if (noti != NULL) {
2323                 /* Update insert time ? */
2324                 noti->insert_time = time(NULL);
2325
2326                 ret = notification_noti_update(noti);
2327                 if (ret != NOTIFICATION_ERROR_NONE) {
2328                         return ret;
2329                 }
2330
2331                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1);
2332                 if (noti_op != NULL) {
2333                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2334                         free(noti_op);
2335                 }
2336         } else {
2337                 /* Send changed notification */
2338                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0);
2339                 if (noti_op != NULL) {
2340                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2341                         free(noti_op);
2342                 }
2343         }
2344         return NOTIFICATION_ERROR_NONE;
2345 }
2346
2347 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
2348 {
2349         int ret = 0;
2350         int num_deleted = 0;
2351         int *list_deleted = NULL;
2352
2353         /* Delete all notification of type */
2354         ret = notification_noti_delete_all(type, NULL, &num_deleted, &list_deleted);
2355         if (ret != NOTIFICATION_ERROR_NONE) {
2356                 return ret;
2357         }
2358
2359         /* Send chagned notification */
2360
2361         if (num_deleted > 0 && list_deleted != NULL) {
2362                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, num_deleted, list_deleted, num_deleted);
2363                 if (noti_op != NULL) {
2364                         NOTIFICATION_ERR("noti_op %x", noti_op);
2365                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, num_deleted);
2366                         free(noti_op);
2367                 }
2368         }
2369
2370         if (list_deleted != NULL) {
2371                 free(list_deleted);
2372         }
2373
2374         return NOTIFICATION_ERROR_NONE;
2375 }
2376
2377 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
2378                                                                 notification_type_e type)
2379 {
2380         int ret = 0;
2381         int num_deleted = 0;
2382         int *list_deleted = NULL;
2383         char *caller_pkgname = NULL;
2384
2385         if (pkgname == NULL) {
2386                 caller_pkgname = _notification_get_pkgname_by_pid();
2387         } else {
2388                 caller_pkgname = strdup(pkgname);
2389         }
2390
2391         ret = notification_noti_delete_all(type, caller_pkgname, &num_deleted, &list_deleted);
2392         if (ret != NOTIFICATION_ERROR_NONE) {
2393                 free(caller_pkgname);
2394                 return ret;
2395         }
2396
2397         /* Send chagned notification */
2398         if (num_deleted > 0 && list_deleted != NULL) {
2399                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, num_deleted, list_deleted, num_deleted);
2400                 if (noti_op != NULL) {
2401                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, num_deleted);
2402                         free(noti_op);
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_group_id(const char *pkgname,
2418                                                                       notification_type_e type,
2419                                                                       int group_id)
2420 {
2421         int ret = 0;
2422         int num_deleted = 0;
2423         int *list_deleted = NULL;
2424         char *caller_pkgname = NULL;
2425
2426         if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2427                 return NOTIFICATION_ERROR_INVALID_DATA;
2428         }
2429
2430         if (pkgname == NULL) {
2431                 caller_pkgname = _notification_get_pkgname_by_pid();
2432         } else {
2433                 caller_pkgname = strdup(pkgname);
2434         }
2435
2436         ret =
2437             notification_noti_delete_group_by_group_id(caller_pkgname,
2438                                                        group_id, &num_deleted, &list_deleted);
2439         if (ret != NOTIFICATION_ERROR_NONE) {
2440                 free(caller_pkgname);
2441                 return ret;
2442         }
2443
2444         if (num_deleted > 0 && list_deleted != NULL) {
2445                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, num_deleted, list_deleted, num_deleted);
2446                 if (noti_op != NULL) {
2447                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, num_deleted);
2448                         free(noti_op);
2449                 }
2450         }
2451
2452         if (caller_pkgname != NULL) {
2453                 free(caller_pkgname);
2454                 caller_pkgname = NULL;
2455         }
2456         if (list_deleted != NULL) {
2457                 free(list_deleted);
2458                 list_deleted = NULL;
2459         }
2460
2461         return ret;
2462 }
2463
2464 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2465                                                                      notification_type_e type,
2466                                                                      int priv_id)
2467 {
2468         int ret = 0;
2469         char *caller_pkgname = NULL;
2470
2471         if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2472                 return NOTIFICATION_ERROR_INVALID_DATA;
2473         }
2474
2475         if (pkgname == NULL) {
2476                 caller_pkgname = _notification_get_pkgname_by_pid();
2477         } else {
2478                 caller_pkgname = strdup(pkgname);
2479         }
2480
2481         ret =
2482             notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id);
2483         if (ret != NOTIFICATION_ERROR_NONE) {
2484                 free(caller_pkgname);
2485                 return ret;
2486         }
2487
2488         notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, 1, NULL, 0);
2489         if (noti_op != NULL) {
2490                 _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2491                 free(noti_op);
2492         }
2493
2494         free(caller_pkgname);
2495
2496         return ret;
2497 }
2498
2499 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
2500                                                                notification_type_e type,
2501                                                                int priv_id)
2502 {
2503         int ret = 0;
2504         char *caller_pkgname = NULL;
2505
2506         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2507                 return NOTIFICATION_ERROR_INVALID_DATA;
2508         }
2509
2510         if (pkgname == NULL) {
2511                 caller_pkgname = _notification_get_pkgname_by_pid();
2512         } else {
2513                 caller_pkgname = strdup(pkgname);
2514         }
2515
2516         ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id);
2517         if (ret != NOTIFICATION_ERROR_NONE) {
2518                 free(caller_pkgname);
2519                 return ret;
2520         }
2521
2522         notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1);
2523         if (noti_op != NULL) {
2524                 _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2525                 free(noti_op);
2526         }
2527
2528         free(caller_pkgname);
2529
2530         return ret;
2531 }
2532
2533 EXPORT_API notification_error_e notification_delete(notification_h noti)
2534 {
2535         int ret = 0;
2536
2537         if (noti == NULL) {
2538                 return NOTIFICATION_ERROR_INVALID_DATA;
2539         }
2540
2541         ret =
2542             notification_noti_delete_by_priv_id(noti->caller_pkgname,
2543                                                 noti->priv_id);
2544         if (ret != NOTIFICATION_ERROR_NONE) {
2545                 return ret;
2546         }
2547
2548         if (noti->flags_for_property
2549                 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) {
2550                 NOTIFICATION_INFO("Disabled update while delete.");
2551         } else {
2552                 notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, 1, &(noti->priv_id), 1);
2553                 if (noti_op != NULL) {
2554                         _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1);
2555                         free(noti_op);
2556                 }
2557         }
2558
2559         return NOTIFICATION_ERROR_NONE;
2560 }
2561
2562 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
2563                                                              int priv_id,
2564                                                              double progress)
2565 {
2566         char *caller_pkgname = NULL;
2567         int input_priv_id = 0;
2568         double input_progress = 0.0;
2569
2570         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2571                 if (noti == NULL) {
2572                         return NOTIFICATION_ERROR_INVALID_DATA;
2573                 } else {
2574                         input_priv_id = noti->priv_id;
2575                 }
2576         } else {
2577                 input_priv_id = priv_id;
2578         }
2579
2580         if (noti == NULL) {
2581                 caller_pkgname = _notification_get_pkgname_by_pid();
2582         } else {
2583                 caller_pkgname = strdup(noti->caller_pkgname);
2584         }
2585
2586         if (progress < 0.0) {
2587                 input_progress = 0.0;
2588         } else if (progress > 1.0) {
2589                 input_progress = 1.0;
2590         } else {
2591                 input_progress = progress;
2592         }
2593
2594         notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2595                                              input_progress);
2596
2597         if (caller_pkgname) {
2598                 free(caller_pkgname);
2599         }
2600
2601         return NOTIFICATION_ERROR_NONE;
2602 }
2603
2604 EXPORT_API notification_error_e notification_update_size(notification_h noti,
2605                                                          int priv_id,
2606                                                          double size)
2607 {
2608         char *caller_pkgname = NULL;
2609         int input_priv_id = 0;
2610         double input_size = 0.0;
2611
2612         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2613                 if (noti == NULL) {
2614                         return NOTIFICATION_ERROR_INVALID_DATA;
2615                 } else {
2616                         input_priv_id = noti->priv_id;
2617                 }
2618         } else {
2619                 input_priv_id = priv_id;
2620         }
2621
2622         if (noti == NULL) {
2623                 caller_pkgname = _notification_get_pkgname_by_pid();
2624         } else {
2625                 caller_pkgname = strdup(noti->caller_pkgname);
2626         }
2627
2628         if (size < 0.0) {
2629                 input_size = 0.0;
2630         } else {
2631                 input_size = size;
2632         }
2633
2634         notification_ongoing_update_size(caller_pkgname, input_priv_id,
2635                                          input_size);
2636
2637         if (caller_pkgname) {
2638                 free(caller_pkgname);
2639         }
2640
2641         return NOTIFICATION_ERROR_NONE;
2642 }
2643
2644 EXPORT_API notification_error_e notification_update_content(notification_h noti,
2645                                                          int priv_id,
2646                                                          const char *content)
2647 {
2648         char *caller_pkgname = NULL;
2649         int input_priv_id = 0;
2650
2651         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2652                 if (noti == NULL) {
2653                         return NOTIFICATION_ERROR_INVALID_DATA;
2654                 } else {
2655                         input_priv_id = noti->priv_id;
2656                 }
2657         } else {
2658                 input_priv_id = priv_id;
2659         }
2660
2661         if (noti == NULL) {
2662                 caller_pkgname = _notification_get_pkgname_by_pid();
2663         } else {
2664                 caller_pkgname = strdup(noti->caller_pkgname);
2665         }
2666
2667         notification_ongoing_update_content(caller_pkgname, input_priv_id,
2668                                          content);
2669
2670         if (caller_pkgname) {
2671                 free(caller_pkgname);
2672         }
2673
2674         return NOTIFICATION_ERROR_NONE;
2675 }
2676
2677 static notification_h _notification_create(notification_type_e type) {
2678         notification_h noti = NULL;
2679
2680         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2681                 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2682                 return NULL;
2683         }
2684
2685         noti = (notification_h) malloc(sizeof(struct _notification));
2686         if (noti == NULL) {
2687                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2688                 return NULL;
2689         }
2690         memset(noti, 0x00, sizeof(struct _notification));
2691
2692         noti->type = type;
2693
2694         if (type == NOTIFICATION_TYPE_NOTI)
2695                 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2696         else if (type == NOTIFICATION_TYPE_ONGOING)
2697                 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
2698
2699         noti->group_id = NOTIFICATION_GROUP_ID_NONE;
2700         noti->internal_group_id = 0;
2701         noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
2702
2703         noti->caller_pkgname = _notification_get_pkgname_by_pid();
2704         noti->launch_pkgname = NULL;
2705         noti->args = NULL;
2706         noti->group_args = NULL;
2707
2708         noti->b_execute_option = NULL;
2709         noti->b_service_responding = NULL;
2710         noti->b_service_single_launch = NULL;
2711         noti->b_service_multi_launch = NULL;
2712
2713         noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2714         noti->sound_path = NULL;
2715
2716         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2717         noti->vibration_path = NULL;
2718
2719         noti->led_operation = NOTIFICATION_LED_OP_OFF;
2720         noti->led_argb = 0;
2721
2722         noti->domain = NULL;
2723         noti->dir = NULL;
2724
2725         noti->b_text = NULL;
2726         noti->b_key = NULL;
2727         noti->b_format_args = NULL;
2728         noti->num_format_args = 0;
2729
2730         noti->b_image_path = NULL;
2731
2732         noti->time = 0;
2733         noti->insert_time = 0;
2734
2735         noti->flags_for_property = 0;
2736         noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2737
2738         noti->progress_size = 0.0;
2739         noti->progress_percentage = 0.0;
2740
2741         noti->app_icon_path = NULL;
2742         noti->app_name = NULL;
2743         noti->temp_title = NULL;
2744         noti->temp_content = NULL;
2745
2746         return noti;
2747 }
2748
2749 EXPORT_API notification_h notification_new(notification_type_e type,
2750                                            int group_id, int priv_id)
2751 {
2752         return _notification_create(type);
2753 }
2754
2755 EXPORT_API notification_h notification_create(notification_type_e type)
2756 {
2757         return _notification_create(type);
2758 }
2759
2760 EXPORT_API notification_h notification_load(char *pkgname,
2761                                                       int priv_id)
2762 {
2763         int ret = 0;
2764         notification_h noti = NULL;
2765
2766         noti = (notification_h) malloc(sizeof(struct _notification));
2767         if (noti == NULL) {
2768                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2769                 return NULL;
2770         }
2771         memset(noti, 0x00, sizeof(struct _notification));
2772
2773         ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id);
2774         if (ret != NOTIFICATION_ERROR_NONE) {
2775                 notification_free(noti);
2776                 return NULL;
2777         }
2778
2779         return noti;
2780 }
2781
2782 EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone)
2783 {
2784         notification_h new_noti = NULL;
2785
2786         if (noti == NULL || clone == NULL) {
2787                 NOTIFICATION_ERR("INVALID PARAMETER.");
2788                 return NOTIFICATION_ERROR_INVALID_DATA;
2789         }
2790
2791         new_noti = (notification_h) malloc(sizeof(struct _notification));
2792         if (new_noti == NULL) {
2793                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2794                 return NOTIFICATION_ERROR_NO_MEMORY;
2795         }
2796         memset(new_noti, 0x00, sizeof(struct _notification));
2797
2798         new_noti->type = noti->type;
2799         new_noti->layout = noti->layout;
2800
2801         new_noti->group_id = noti->group_id;
2802         new_noti->internal_group_id = noti->internal_group_id;
2803         new_noti->priv_id = noti->priv_id;
2804
2805         if(noti->caller_pkgname != NULL) {
2806                 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2807         } else {
2808                 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2809         }
2810         if(noti->launch_pkgname != NULL) {
2811                 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2812         } else {
2813                 new_noti->launch_pkgname = NULL;
2814         }
2815
2816         if(noti->args != NULL) {
2817                 new_noti->args = bundle_dup(noti->args);
2818         } else {
2819                 new_noti->args = NULL;
2820         }
2821         if(noti->group_args != NULL) {
2822                 new_noti->group_args = bundle_dup(noti->group_args);
2823         } else {
2824                 new_noti->group_args = NULL;
2825         }
2826
2827         if(noti->b_execute_option != NULL) {
2828                 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2829         } else {
2830                 new_noti->b_execute_option = NULL;
2831         }
2832         if(noti->b_service_responding != NULL) {
2833                 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2834         } else {
2835                 new_noti->b_service_responding = NULL;
2836         }
2837         if(noti->b_service_single_launch != NULL) {
2838                 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2839         } else {
2840                 new_noti->b_service_single_launch = NULL;
2841         }
2842         if(noti->b_service_multi_launch != NULL) {
2843                 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2844         } else {
2845                 new_noti->b_service_multi_launch = NULL;
2846         }
2847
2848         new_noti->sound_type = noti->sound_type;
2849         if(noti->sound_path != NULL) {
2850                 new_noti->sound_path = strdup(noti->sound_path);
2851         } else {
2852                 new_noti->sound_path = NULL;
2853         }
2854         new_noti->vibration_type = noti->vibration_type;
2855         if(noti->vibration_path != NULL) {
2856                 new_noti->vibration_path = strdup(noti->vibration_path);
2857         } else {
2858                 new_noti->vibration_path = NULL;
2859         }
2860         new_noti->led_operation = noti->led_operation;
2861         new_noti->led_argb = noti->led_argb;
2862
2863         if(noti->domain != NULL) {
2864                 new_noti->domain = strdup(noti->domain);
2865         } else {
2866                 new_noti->domain = NULL;
2867         }
2868         if(noti->dir != NULL) {
2869                 new_noti->dir = strdup(noti->dir);
2870         } else {
2871                 new_noti->dir = NULL;
2872         }
2873
2874         if(noti->b_text != NULL) {
2875                 new_noti->b_text = bundle_dup(noti->b_text);
2876         } else {
2877                 new_noti->b_text = NULL;
2878         }
2879         if(noti->b_key != NULL) {
2880                 new_noti->b_key = bundle_dup(noti->b_key);
2881         } else {
2882                 new_noti->b_key = NULL;
2883         }
2884         if(noti->b_format_args != NULL) {
2885                 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2886         } else {
2887                 new_noti->b_format_args = NULL;
2888         }
2889         new_noti->num_format_args = noti->num_format_args;
2890
2891         if(noti->b_image_path != NULL) {
2892                 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2893         } else {
2894                 new_noti->b_image_path = NULL;
2895         }
2896
2897         new_noti->time = noti->time;
2898         new_noti->insert_time = noti->insert_time;
2899
2900         new_noti->flags_for_property = noti->flags_for_property;
2901         new_noti->display_applist = noti->display_applist;
2902
2903         new_noti->progress_size = noti->progress_size;
2904         new_noti->progress_percentage = noti->progress_percentage;
2905
2906         new_noti->app_icon_path = NULL;
2907         new_noti->app_name = NULL;
2908         new_noti->temp_title = NULL;
2909         new_noti->temp_content = NULL;
2910
2911         *clone = new_noti;
2912
2913         return NOTIFICATION_ERROR_NONE;
2914 }
2915
2916
2917 EXPORT_API notification_error_e notification_free(notification_h noti)
2918 {
2919         if (noti == NULL) {
2920                 return NOTIFICATION_ERROR_INVALID_DATA;
2921         }
2922
2923         if (noti->caller_pkgname) {
2924                 free(noti->caller_pkgname);
2925         }
2926         if (noti->launch_pkgname) {
2927                 free(noti->launch_pkgname);
2928         }
2929         if (noti->args) {
2930                 bundle_free(noti->args);
2931         }
2932         if (noti->group_args) {
2933                 bundle_free(noti->group_args);
2934         }
2935
2936         if (noti->b_execute_option) {
2937                 bundle_free(noti->b_execute_option);
2938         }
2939         if (noti->b_service_responding) {
2940                 bundle_free(noti->b_service_responding);
2941         }
2942         if (noti->b_service_single_launch) {
2943                 bundle_free(noti->b_service_single_launch);
2944         }
2945         if (noti->b_service_multi_launch) {
2946                 bundle_free(noti->b_service_multi_launch);
2947         }
2948
2949         if (noti->sound_path) {
2950                 free(noti->sound_path);
2951         }
2952         if (noti->vibration_path) {
2953                 free(noti->vibration_path);
2954         }
2955
2956         if (noti->domain) {
2957                 free(noti->domain);
2958         }
2959         if (noti->dir) {
2960                 free(noti->dir);
2961         }
2962
2963         if (noti->b_text) {
2964                 bundle_free(noti->b_text);
2965         }
2966         if (noti->b_key) {
2967                 bundle_free(noti->b_key);
2968         }
2969         if (noti->b_format_args) {
2970                 bundle_free(noti->b_format_args);
2971         }
2972
2973         if (noti->b_image_path) {
2974                 bundle_free(noti->b_image_path);
2975         }
2976
2977         if (noti->app_icon_path) {
2978                 free(noti->app_icon_path);
2979         }
2980         if (noti->app_name) {
2981                 free(noti->app_name);
2982         }
2983         if (noti->temp_title) {
2984                 free(noti->temp_title);
2985         }
2986         if (noti->temp_content) {
2987                 free(noti->temp_content);
2988         }
2989
2990         free(noti);
2991
2992         return NOTIFICATION_ERROR_NONE;
2993 }
2994
2995 EXPORT_API notification_error_e
2996 notification_resister_changed_cb(void (*changed_cb)
2997                                  (void *data, notification_type_e type),
2998                                  void *user_data)
2999 {
3000         notification_cb_list_s *noti_cb_list_new = NULL;
3001         notification_cb_list_s *noti_cb_list = NULL;
3002
3003         if (!g_dbus_handle) {
3004                 g_dbus_handle = _noti_changed_monitor_init();
3005                 if (!g_dbus_handle)
3006                         return NOTIFICATION_ERROR_FROM_DBUS;
3007         }
3008
3009         noti_cb_list_new =
3010             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
3011
3012         noti_cb_list_new->next = NULL;
3013         noti_cb_list_new->prev = NULL;
3014
3015         noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
3016         noti_cb_list_new->changed_cb = changed_cb;
3017         noti_cb_list_new->detailed_changed_cb = NULL;
3018         noti_cb_list_new->data = user_data;
3019
3020         if (g_notification_cb_list == NULL) {
3021                 g_notification_cb_list = noti_cb_list_new;
3022         } else {
3023                 noti_cb_list = g_notification_cb_list;
3024
3025                 while (noti_cb_list->next != NULL) {
3026                         noti_cb_list = noti_cb_list->next;
3027                 }
3028
3029                 noti_cb_list->next = noti_cb_list_new;
3030                 noti_cb_list_new->prev = noti_cb_list;
3031         }
3032         return NOTIFICATION_ERROR_NONE;
3033 }
3034
3035 EXPORT_API notification_error_e
3036 notification_unresister_changed_cb(void (*changed_cb)
3037                                    (void *data, notification_type_e type))
3038 {
3039         notification_cb_list_s *noti_cb_list = NULL;
3040         notification_cb_list_s *noti_cb_list_prev = NULL;
3041         notification_cb_list_s *noti_cb_list_next = NULL;
3042
3043         noti_cb_list = g_notification_cb_list;
3044
3045         if (noti_cb_list == NULL) {
3046                 return NOTIFICATION_ERROR_INVALID_DATA;
3047         }
3048
3049         while (noti_cb_list->prev != NULL) {
3050                 noti_cb_list = noti_cb_list->prev;
3051         }
3052
3053         do {
3054                 if (noti_cb_list->changed_cb == changed_cb) {
3055                         noti_cb_list_prev = noti_cb_list->prev;
3056                         noti_cb_list_next = noti_cb_list->next;
3057
3058                         if (noti_cb_list_prev == NULL) {
3059                                 g_notification_cb_list = noti_cb_list_next;
3060                         } else {
3061                                 noti_cb_list_prev->next = noti_cb_list_next;
3062                         }
3063
3064                         if (noti_cb_list_next == NULL) {
3065                                 if (noti_cb_list_prev != NULL) {
3066                                         noti_cb_list_prev->next = NULL;
3067                                 }
3068                         } else {
3069                                 noti_cb_list_next->prev = noti_cb_list_prev;
3070                         }
3071
3072                         free(noti_cb_list);
3073
3074                         if (g_notification_cb_list == NULL)
3075                                 _noti_chanaged_monitor_fini();
3076
3077                         return NOTIFICATION_ERROR_NONE;
3078                 }
3079                 noti_cb_list = noti_cb_list->next;
3080         } while (noti_cb_list != NULL);
3081
3082         return NOTIFICATION_ERROR_INVALID_DATA;
3083 }
3084
3085 EXPORT_API notification_error_e
3086 notification_register_detailed_changed_cb(
3087                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
3088                 void *user_data)
3089 {
3090         notification_cb_list_s *noti_cb_list_new = NULL;
3091         notification_cb_list_s *noti_cb_list = NULL;
3092
3093         if (!g_dbus_handle) {
3094                 g_dbus_handle = _noti_changed_monitor_init();
3095                 if (!g_dbus_handle)
3096                         return NOTIFICATION_ERROR_FROM_DBUS;
3097         }
3098
3099         noti_cb_list_new =
3100             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
3101
3102         noti_cb_list_new->next = NULL;
3103         noti_cb_list_new->prev = NULL;
3104
3105         noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
3106         noti_cb_list_new->changed_cb = NULL;
3107         noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
3108         noti_cb_list_new->data = user_data;
3109
3110         if (g_notification_cb_list == NULL) {
3111                 g_notification_cb_list = noti_cb_list_new;
3112         } else {
3113                 noti_cb_list = g_notification_cb_list;
3114
3115                 while (noti_cb_list->next != NULL) {
3116                         noti_cb_list = noti_cb_list->next;
3117                 }
3118
3119                 noti_cb_list->next = noti_cb_list_new;
3120                 noti_cb_list_new->prev = noti_cb_list;
3121         }
3122         return NOTIFICATION_ERROR_NONE;
3123 }
3124
3125 EXPORT_API notification_error_e
3126 notification_unregister_detailed_changed_cb(
3127                 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
3128                 void *user_data)
3129 {
3130         notification_cb_list_s *noti_cb_list = NULL;
3131         notification_cb_list_s *noti_cb_list_prev = NULL;
3132         notification_cb_list_s *noti_cb_list_next = NULL;
3133
3134         noti_cb_list = g_notification_cb_list;
3135
3136         if (noti_cb_list == NULL) {
3137                 return NOTIFICATION_ERROR_INVALID_DATA;
3138         }
3139
3140         while (noti_cb_list->prev != NULL) {
3141                 noti_cb_list = noti_cb_list->prev;
3142         }
3143
3144         do {
3145                 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
3146                         noti_cb_list_prev = noti_cb_list->prev;
3147                         noti_cb_list_next = noti_cb_list->next;
3148
3149                         if (noti_cb_list_prev == NULL) {
3150                                 g_notification_cb_list = noti_cb_list_next;
3151                         } else {
3152                                 noti_cb_list_prev->next = noti_cb_list_next;
3153                         }
3154
3155                         if (noti_cb_list_next == NULL) {
3156                                 if (noti_cb_list_prev != NULL) {
3157                                         noti_cb_list_prev->next = NULL;
3158                                 }
3159                         } else {
3160                                 noti_cb_list_next->prev = noti_cb_list_prev;
3161                         }
3162
3163                         free(noti_cb_list);
3164
3165                         if (g_notification_cb_list == NULL)
3166                                 _noti_chanaged_monitor_fini();
3167
3168                         return NOTIFICATION_ERROR_NONE;
3169                 }
3170                 noti_cb_list = noti_cb_list->next;
3171         } while (noti_cb_list != NULL);
3172
3173         return NOTIFICATION_ERROR_INVALID_DATA;
3174 }
3175
3176 EXPORT_API notification_error_e
3177 notification_resister_badge_changed_cb(void (*changed_cb)
3178                                        (void *data, const char *pkgname,
3179                                         int group_id), void *user_data)
3180 {
3181         // Add DBus signal handler
3182         return NOTIFICATION_ERROR_NONE;
3183 }
3184
3185 EXPORT_API notification_error_e
3186 notification_unresister_badge_changed_cb(void (*changed_cb)
3187                                          (void *data, const char *pkgname,
3188                                           int group_id))
3189 {
3190         // Del DBus signal handler
3191         return NOTIFICATION_ERROR_NONE;
3192 }
3193
3194 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
3195                                                        const char *pkgname,
3196                                                        int group_id,
3197                                                        int priv_id, int *count)
3198 {
3199         int ret = 0;
3200         int noti_count = 0;
3201
3202         ret =
3203             notification_noti_get_count(type, pkgname, group_id, priv_id,
3204                                         &noti_count);
3205         if (ret != NOTIFICATION_ERROR_NONE) {
3206                 return ret;
3207         }
3208
3209         if (count != NULL) {
3210                 *count = noti_count;
3211         }
3212
3213         return NOTIFICATION_ERROR_NONE;
3214 }
3215
3216 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
3217                                                       int count,
3218                                                       notification_list_h *list)
3219 {
3220         notification_list_h get_list = NULL;
3221         int ret = 0;
3222
3223         ret = notification_noti_get_grouping_list(type, count, &get_list);
3224         if (ret != NOTIFICATION_ERROR_NONE) {
3225                 return ret;
3226         }
3227
3228         *list = get_list;
3229
3230         return NOTIFICATION_ERROR_NONE;
3231 }
3232
3233 EXPORT_API notification_error_e
3234 notification_get_grouping_list(notification_type_e type, int count,
3235                                notification_list_h * list)
3236 {
3237         notification_list_h get_list = NULL;
3238         int ret = 0;
3239
3240         ret = notification_noti_get_grouping_list(type, count, &get_list);
3241         if (ret != NOTIFICATION_ERROR_NONE) {
3242                 return ret;
3243         }
3244
3245         *list = get_list;
3246
3247         return NOTIFICATION_ERROR_NONE;
3248 }
3249
3250 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
3251                                                              int group_id,
3252                                                              int priv_id,
3253                                                              int count,
3254                                                              notification_list_h *list)
3255 {
3256         notification_list_h get_list = NULL;
3257         int ret = 0;
3258
3259         ret =
3260             notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
3261                                               &get_list);
3262         if (ret != NOTIFICATION_ERROR_NONE) {
3263                 return ret;
3264         }
3265
3266         *list = get_list;
3267
3268         return NOTIFICATION_ERROR_NONE;
3269 }
3270
3271 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
3272 {
3273         notification_list_h cur_list = NULL;
3274         notification_h noti = NULL;
3275
3276         if (list == NULL) {
3277                 NOTIFICATION_ERR("INVALID DATA : list == NULL");
3278                 return NOTIFICATION_ERROR_INVALID_DATA;
3279         }
3280
3281         cur_list = notification_list_get_head(list);
3282
3283         while (cur_list != NULL) {
3284                 noti = notification_list_get_data(cur_list);
3285                 cur_list = notification_list_remove(cur_list, noti);
3286
3287                 notification_free(noti);
3288         }
3289
3290         return NOTIFICATION_ERROR_NONE;
3291 }
3292
3293 EXPORT_API notification_error_e notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
3294                                                        void *data)
3295 {
3296         if (noti_op == NULL) {
3297                 return NOTIFICATION_ERROR_INVALID_DATA;
3298         }
3299
3300         switch (type) {
3301                 case NOTIFICATION_OP_DATA_TYPE:
3302                         *((int*)data) = noti_op->type;
3303                         break;
3304                 case NOTIFICATION_OP_DATA_PRIV_ID:
3305                         *((int*)data) = noti_op->priv_id;
3306                         break;
3307                 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
3308                         *((int*)data) = noti_op->extra_info_1;
3309                         break;
3310                 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
3311                         *((int*)data) = noti_op->extra_info_2;
3312                         break;
3313                 default:
3314                         return NOTIFICATION_ERROR_INVALID_DATA;
3315                         break;
3316         }
3317
3318         return NOTIFICATION_ERROR_NONE;
3319 }