Git init
[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>
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
29 #include <aul.h>
30 #include <ail.h>
31 #include <appsvc.h>
32 #include <heynoti.h>
33 #include <vconf-keys.h>
34 #include <vconf.h>
35
36 #include <notification.h>
37 #include <notification_list.h>
38 #include <notification_debug.h>
39 #include <notification_internal.h>
40 #include <notification_noti.h>
41 #include <notification_ongoing.h>
42 #include <notification_group.h>
43
44 typedef struct _notification_cb_list notification_cb_list_s;
45
46 struct _notification_cb_list {
47         notification_cb_list_s *prev;
48         notification_cb_list_s *next;
49
50         void (*changed_cb) (void *data, notification_type_e type);
51         void *data;
52 };
53
54 static notification_cb_list_s *g_notification_cb_list = NULL;
55 static int g_notification_heynoti_fd = -1;
56
57 #define NOTI_PKGNAME_LEN        512
58 #define NOTI_CHANGED_NOTI       "notification_noti_changed"
59 #define NOTI_CHANGED_ONGOING    "notification_ontoing_changed"
60
61 static char *_notification_get_pkgname_by_pid(void)
62 {
63         char buf[NOTI_PKGNAME_LEN] = { 0, };
64         char pkgname[NOTI_PKGNAME_LEN] = { 0, };
65         int pid = 0, ret = AUL_R_OK;
66         int fd;
67
68         pid = getpid();
69
70         ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
71         if (ret != AUL_R_OK) {
72                 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
73
74                 fd = open(buf, O_RDONLY);
75                 if (fd < 0) {
76                         return NULL;
77                 }
78
79                 ret = read(fd, pkgname, sizeof(pkgname) - 1);
80                 if (ret <= 0) {
81                         close(fd);
82                         return NULL;
83                 }
84
85                 buf[ret] = 0;
86
87                 close(fd);
88         }
89
90         if (pkgname == NULL || pkgname[0] == '\0') {
91                 return NULL;
92         } else {
93                 return strdup(pkgname);
94         }
95 }
96
97 static char *_notification_get_icon(const char *package)
98 {
99         ail_appinfo_h handle;
100         ail_error_e ret;
101         char *str = NULL;
102         char *icon = NULL;
103
104         ret = ail_package_get_appinfo(package, &handle);
105         if (ret != AIL_ERROR_OK) {
106                 return NULL;
107         }
108
109         ret = ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &str);
110         if (ret != AIL_ERROR_OK) {
111                 ail_package_destroy_appinfo(handle);
112                 return NULL;
113         }
114
115         icon = strdup(str);
116
117         ret = ail_package_destroy_appinfo(handle);
118         if (ret != AIL_ERROR_OK) {
119                 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
120         }
121
122         return icon;
123 }
124
125 static char *_notification_get_name(const char *package)
126 {
127         ail_appinfo_h handle;
128         ail_error_e ret;
129         char *str = NULL;
130         char *name = NULL;
131
132         ret = ail_package_get_appinfo(package, &handle);
133         if (ret != AIL_ERROR_OK) {
134                 return NULL;
135         }
136
137         ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
138         if (ret != AIL_ERROR_OK) {
139                 ail_package_destroy_appinfo(handle);
140                 return NULL;
141         }
142
143         name = strdup(str);
144
145         ret = ail_package_destroy_appinfo(handle);
146         if (ret != AIL_ERROR_OK) {
147                 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
148         }
149
150         return name;
151 }
152
153 static void _notification_get_text_domain(notification_h noti)
154 {
155         if (noti->domain != NULL) {
156
157         }
158
159         if (noti->dir != NULL) {
160
161         }
162 }
163
164 static void _notification_chagned_noti_cb(void *data)
165 {
166         notification_cb_list_s *noti_cb_list = NULL;
167
168         if (g_notification_cb_list == NULL) {
169                 return;
170         }
171
172         noti_cb_list = g_notification_cb_list;
173
174         while (noti_cb_list->prev != NULL) {
175                 noti_cb_list = noti_cb_list->prev;
176         }
177
178         while (noti_cb_list != NULL) {
179                 if (noti_cb_list->changed_cb) {
180                         noti_cb_list->changed_cb(noti_cb_list->data,
181                                                  NOTIFICATION_TYPE_NOTI);
182                 }
183
184                 noti_cb_list = noti_cb_list->next;
185         }
186 }
187
188 #if 0
189 static void _notification_chagned_ongoing_cb(void *data)
190 {
191         notification_cb_list_s *noti_cb_list = NULL;
192
193         if (g_notification_cb_list == NULL) {
194                 return;
195         }
196
197         noti_cb_list = g_notification_cb_list;
198
199         while (noti_cb_list->prev != NULL) {
200                 noti_cb_list = noti_cb_list->prev;
201         }
202
203         while (noti_cb_list != NULL) {
204                 if (noti_cb_list->changed_cb) {
205                         noti_cb_list->changed_cb(noti_cb_list->data,
206                                                  NOTIFICATION_TYPE_ONGOING);
207                 }
208
209                 noti_cb_list = noti_cb_list->next;
210         }
211 }
212 #endif
213
214 static void _notification_changed(const char *type)
215 {
216         heynoti_publish(type);
217 }
218
219 /* notification_set_icon will be removed */
220 EXPORT_API notification_error_e notification_set_icon(notification_h noti,
221                                                       const char *icon_path)
222 {
223         int ret_err = NOTIFICATION_ERROR_NONE;
224
225         ret_err =
226             notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
227                                    icon_path);
228
229         return ret_err;
230 }
231
232 /* notification_get_icon will be removed */
233 EXPORT_API notification_error_e notification_get_icon(notification_h noti,
234                                                       char **icon_path)
235 {
236         int ret_err = NOTIFICATION_ERROR_NONE;
237         char *ret_image_path = NULL;
238
239         ret_err =
240             notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
241                                    &ret_image_path);
242
243         if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
244                 *icon_path = ret_image_path;
245
246                 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
247         }
248
249         return ret_err;
250 }
251
252 EXPORT_API notification_error_e notification_set_image(notification_h noti,
253                                                        notification_image_type_e type,
254                                                        const char *image_path)
255 {
256         bundle *b = NULL;
257         char buf_key[32] = { 0, };
258         const char *ret_val = NULL;
259
260         /* Check noti and image_path are valid data */
261         if (noti == NULL || image_path == NULL) {
262                 return NOTIFICATION_ERROR_INVALID_DATA;
263         }
264
265         /* Check image type is valid type */
266         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
267             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
268                 return NOTIFICATION_ERROR_INVALID_DATA;
269         }
270
271         /* Check image path bundle is exist */
272         if (noti->b_image_path) {
273                 /* If image path bundle is exist, store local bundle value */
274                 b = noti->b_image_path;
275
276                 /* Set image type to key as char string type */
277                 snprintf(buf_key, sizeof(buf_key), "%d", type);
278
279                 /* Get value using key */
280                 ret_val = bundle_get_val(b, buf_key);
281                 if (ret_val != NULL) {
282                         /* If key is exist, remove this value to store new image path */
283                         bundle_del(b, buf_key);
284                 }
285
286                 /* Add new image path with type key */
287                 bundle_add(b, buf_key, image_path);
288         } else {
289                 /* If image path bundle is not exist, create new one */
290                 b = bundle_create();
291
292                 /* Set image type to key as char string type */
293                 snprintf(buf_key, sizeof(buf_key), "%d", type);
294
295                 /* Add new image path with type key */
296                 bundle_add(b, buf_key, image_path);
297
298                 /* Save to image path bundle */
299                 noti->b_image_path = b;
300         }
301
302         return NOTIFICATION_ERROR_NONE;
303 }
304
305 EXPORT_API notification_error_e notification_get_image(notification_h noti,
306                                                        notification_image_type_e type,
307                                                        char **image_path)
308 {
309         bundle *b = NULL;
310         char buf_key[32] = { 0, };
311         const char *ret_val = NULL;
312         const char *pkgname = NULL;
313
314         /* Check noti and image_path is valid data */
315         if (noti == NULL || image_path == NULL) {
316                 return NOTIFICATION_ERROR_INVALID_DATA;
317         }
318
319         /* Check image type is valid data */
320         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
321             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
322                 return NOTIFICATION_ERROR_INVALID_DATA;
323         }
324
325         /* Check image path bundle exist */
326         if (noti->b_image_path) {
327                 /* If image path bundle exist, store local bundle data */
328                 b = noti->b_image_path;
329
330                 /* Set image type to key as char string type */
331                 snprintf(buf_key, sizeof(buf_key), "%d", type);
332
333                 /* Get value of key */
334                 ret_val = bundle_get_val(b, buf_key);
335
336                 *image_path = (char *)ret_val;
337         } else {
338                 /* If image path bundle does not exist, image path is NULL */
339                 *image_path = NULL;
340         }
341
342         /* If image path is NULL and type is ICON, icon path set from AIL */
343         /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
344         if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
345                 /* Check App icon path is already set */
346                 if (noti->app_icon_path != NULL) {
347                         /* image path will be app icon path */
348                         *image_path = noti->app_icon_path;
349                 } else {
350                         /* Get image path using launch_pkgname */
351                         if (noti->launch_pkgname != NULL) {
352                                 noti->app_icon_path =
353                                     _notification_get_icon(noti->launch_pkgname);
354                         }
355
356                         /* If app icon path is NULL, get image path using caller_pkgname */
357                         if (noti->app_icon_path == NULL
358                             && noti->caller_pkgname != NULL) {
359                                 noti->app_icon_path =
360                                     _notification_get_icon(noti->caller_pkgname);
361                         }
362
363                         /* If app icon path is NULL, get image path using service data */
364                         if (noti->app_icon_path == NULL
365                             && noti->b_service_single_launch != NULL) {
366                                 pkgname =
367                                     appsvc_get_pkgname(noti->b_service_single_launch);
368                                 if (pkgname != NULL) {
369                                         noti->app_icon_path =
370                                             _notification_get_icon(pkgname);
371                                 }
372                         }
373
374                         *image_path = noti->app_icon_path;
375                 }
376         }
377
378         return NOTIFICATION_ERROR_NONE;
379 }
380
381 EXPORT_API notification_error_e notification_set_time(notification_h noti,
382                                                       time_t input_time)
383 {
384         /* Check noti is valid data */
385         if (noti == NULL) {
386                 return NOTIFICATION_ERROR_INVALID_DATA;
387         }
388
389         if (input_time == 0) {
390                 /* If input time is 0, set current time */
391                 noti->time = time(NULL);
392         } else {
393                 /* save input time */
394                 noti->time = input_time;
395         }
396
397         return NOTIFICATION_ERROR_NONE;
398 }
399
400 EXPORT_API notification_error_e notification_get_time(notification_h noti,
401                                                       time_t * ret_time)
402 {
403         /* Check noti and time is valid data */
404         if (noti == NULL || ret_time == NULL) {
405                 return NOTIFICATION_ERROR_INVALID_DATA;
406         }
407
408         /* Set time infomation */
409         *ret_time = noti->time;
410
411         return NOTIFICATION_ERROR_NONE;
412 }
413
414 EXPORT_API notification_error_e notification_get_insert_time(notification_h noti,
415                                                              time_t * ret_time)
416 {
417         /* Check noti and ret_time is valid data */
418         if (noti == NULL || ret_time == NULL) {
419                 return NOTIFICATION_ERROR_INVALID_DATA;
420         }
421
422         /* Set insert time information */
423         *ret_time = noti->insert_time;
424
425         return NOTIFICATION_ERROR_NONE;
426 }
427
428 EXPORT_API notification_error_e notification_set_title(notification_h noti,
429                                                        const char *title,
430                                                        const char *loc_title)
431 {
432         int noti_err = NOTIFICATION_ERROR_NONE;
433
434         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
435                                          title, loc_title,
436                                          NOTIFICATION_VARIABLE_TYPE_NONE);
437
438         return noti_err;
439 }
440
441 EXPORT_API notification_error_e notification_get_title(notification_h noti,
442                                                        char **title,
443                                                        char **loc_title)
444 {
445         int noti_err = NOTIFICATION_ERROR_NONE;
446         char *ret_text = NULL;
447
448         noti_err =
449             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
450                                   &ret_text);
451
452         if (title != NULL) {
453                 *title = ret_text;
454         }
455
456         if (loc_title != NULL) {
457                 *loc_title = NULL;
458         }
459
460         return noti_err;
461 }
462
463 EXPORT_API notification_error_e notification_set_group_title(const char *pkgname,
464                                                              int group_id,
465                                                              const char *title,
466                                                              const char *loc_title,
467                                                              notification_count_display_type_e count_display)
468 {
469         char *caller_pkgname = NULL;
470         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
471
472         if ((title == NULL && loc_title == NULL)) {
473                 return NOTIFICATION_ERROR_INVALID_DATA;
474         }
475
476         if (group_id < NOTIFICATION_GROUP_ID_DEFAULT) {
477                 return NOTIFICATION_ERROR_INVALID_DATA;
478         }
479
480         if (pkgname == NULL) {
481                 caller_pkgname = _notification_get_pkgname_by_pid();
482
483                 noti_err =
484                     notification_group_set_title(caller_pkgname, group_id,
485                                                  title, loc_title,
486                                                  count_display);
487
488                 if (caller_pkgname != NULL) {
489                         free(caller_pkgname);
490                 }
491         } else {
492                 noti_err =
493                     notification_group_set_title(pkgname, group_id, title,
494                                                  loc_title, count_display);
495         }
496
497         return noti_err;
498 }
499
500 EXPORT_API notification_error_e notification_get_group_title(const char *pkgname,
501                                                              int group_id,
502                                                              char **title,
503                                                              char **loc_title,
504                                                              notification_count_display_type_e *count_display)
505 {
506         char *caller_pkgname = NULL;
507         char *ret_title = NULL;
508         char *ret_loc_title = NULL;
509         notification_count_display_type_e ret_count_display;
510         int ret = NOTIFICATION_ERROR_NONE;
511
512         if (pkgname == NULL) {
513                 caller_pkgname = _notification_get_pkgname_by_pid();
514
515                 ret =
516                     notification_group_get_title(caller_pkgname, group_id,
517                                                  &ret_title, &ret_loc_title,
518                                                  &ret_count_display);
519
520                 if (caller_pkgname != NULL) {
521                         free(caller_pkgname);
522                 }
523         } else {
524                 ret =
525                     notification_group_get_title(pkgname, group_id, &ret_title,
526                                                  &ret_loc_title,
527                                                  &ret_count_display);
528         }
529
530         if (ret != NOTIFICATION_ERROR_NONE) {
531                 return ret;
532         }
533
534         *title = ret_title;
535         *loc_title = ret_loc_title;
536         *count_display = ret_count_display;
537
538         return NOTIFICATION_ERROR_NONE;
539 }
540
541 EXPORT_API notification_error_e notification_set_content(notification_h noti,
542                                                          const char *content,
543                                                          const char *loc_content)
544 {
545         int noti_err = NOTIFICATION_ERROR_NONE;
546
547         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
548                                          content, loc_content,
549                                          NOTIFICATION_VARIABLE_TYPE_NONE);
550
551         return noti_err;
552 }
553
554 EXPORT_API notification_error_e notification_get_content(notification_h noti,
555                                                          char **content,
556                                                          char **loc_content)
557 {
558         int noti_err = NOTIFICATION_ERROR_NONE;
559         char *ret_text = NULL;
560
561         noti_err =
562             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
563                                   &ret_text);
564
565         if (content != NULL) {
566                 *content = ret_text;
567         }
568
569         if (loc_content != NULL) {
570                 *loc_content = NULL;
571         }
572
573         return noti_err;
574
575 #if 0
576         ret =
577             vconf_get_bool
578             (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
579
580         if (ret == -1 || boolval == 0) {
581                 if (content != NULL && noti->default_content != NULL) {
582                         *content = noti->default_content;
583                 }
584
585                 if (loc_content != NULL && noti->loc_default_content != NULL) {
586                         *loc_content = noti->loc_default_content;
587                 }
588         }
589 #endif
590 }
591
592 EXPORT_API notification_error_e notification_set_default_content(notification_h noti,
593                                                                  const char *content,
594                                                                  const char *loc_content)
595 {
596         int noti_err = NOTIFICATION_ERROR_NONE;
597
598         noti_err =
599             notification_set_text(noti,
600                                   NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF,
601                                   content, loc_content,
602                                   NOTIFICATION_VARIABLE_TYPE_NONE);
603
604         return noti_err;
605 }
606
607 EXPORT_API notification_error_e notification_get_default_content(notification_h noti,
608                                                                  char **content,
609                                                                  char **loc_content)
610 {
611         int noti_err = NOTIFICATION_ERROR_NONE;
612         char *ret_text = NULL;
613
614         noti_err =
615             notification_get_text(noti,
616                                   NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF,
617                                   &ret_text);
618
619         if (content != NULL) {
620                 *content = ret_text;
621         }
622
623         if (loc_content != NULL) {
624                 *loc_content = NULL;
625         }
626
627         return noti_err;
628 }
629
630 EXPORT_API notification_error_e notification_set_group_content(const char *pkgname,
631                                                                int group_id,
632                                                                const char *content,
633                                                                const char *loc_content,
634                                                                notification_count_display_type_e count_display)
635 {
636         const char *caller_pkgname = NULL;
637         if ((content == NULL && loc_content == NULL)) {
638                 return NOTIFICATION_ERROR_INVALID_DATA;
639         }
640
641         if (group_id < NOTIFICATION_GROUP_ID_DEFAULT) {
642                 return NOTIFICATION_ERROR_INVALID_DATA;
643         }
644
645         if (pkgname == NULL)
646                 caller_pkgname = _notification_get_pkgname_by_pid();
647         else
648                 caller_pkgname = pkgname;
649
650         notification_group_set_content(caller_pkgname, group_id, content,
651                                        loc_content, count_display);
652
653         return NOTIFICATION_ERROR_NONE;
654 }
655
656 EXPORT_API notification_error_e notification_get_group_content(const char *pkgname,
657                                                                int group_id,
658                                                                char **content,
659                                                                char **loc_content,
660                                                                notification_count_display_type_e *count_display)
661 {
662         const char *caller_pkgname = NULL;
663         char *ret_content = NULL;
664         char *ret_loc_content = NULL;
665         notification_count_display_type_e ret_count_display;
666         int ret = NOTIFICATION_ERROR_NONE;
667
668         if (pkgname == NULL)
669                 caller_pkgname = _notification_get_pkgname_by_pid();
670         else
671                 caller_pkgname = pkgname;
672
673         ret =
674             notification_group_get_content(caller_pkgname, group_id,
675                                            &ret_content, &ret_loc_content,
676                                            &ret_count_display);
677         if (ret != NOTIFICATION_ERROR_NONE) {
678                 return ret;
679         }
680
681         *content = ret_content;
682         *loc_content = ret_loc_content;
683         *count_display = ret_count_display;
684
685         return NOTIFICATION_ERROR_NONE;
686 }
687
688 EXPORT_API notification_error_e notification_set_text(notification_h noti,
689                                                       notification_text_type_e type,
690                                                       const char *text,
691                                                       const char *key,
692                                                       int args_type, ...)
693 {
694         bundle *b = NULL;
695         char buf_key[32] = { 0, };
696         char buf_val[1024] = { 0, };
697         const char *ret_val = NULL;
698         va_list var_args;
699         notification_variable_type_e var_type;
700         int num_args = 0;
701         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
702         int var_value_int = 0;
703         double var_value_double = 0.0;
704         char *var_value_string = NULL;
705         notification_count_pos_type_e var_value_count =
706             NOTIFICATION_COUNT_POS_NONE;
707
708         /* Check noti is valid data */
709         if (noti == NULL) {
710                 return NOTIFICATION_ERROR_INVALID_DATA;
711         }
712
713         /* Check text type is valid type */
714         if (type <= NOTIFICATION_TEXT_TYPE_NONE
715             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
716                 return NOTIFICATION_ERROR_INVALID_DATA;
717         }
718
719         /* Check text bundle exist */
720         if (text != NULL) {
721                 if (noti->b_text != NULL) {
722                         /* If text bundle exist, store local bundle data */
723                         b = noti->b_text;
724
725                         /* Make type to key as char string */
726                         snprintf(buf_key, sizeof(buf_key), "%d", type);
727
728                         /* Get value using type key */
729                         ret_val = bundle_get_val(b, buf_key);
730                         if (ret_val != NULL) {
731                                 /* If value exist, remove this to add new value */
732                                 bundle_del(b, buf_key);
733                         }
734
735                         snprintf(buf_val, sizeof(buf_val), "%s", text);
736
737                         /* Add new text value */
738                         bundle_add(b, buf_key, buf_val);
739                 } else {
740                         /* If text bundle does not exist, create new one */
741                         b = bundle_create();
742
743                         /* Make type to key as char string */
744                         snprintf(buf_key, sizeof(buf_key), "%d", type);
745
746                         snprintf(buf_val, sizeof(buf_val), "%s", text);
747
748                         /* Add new text value */
749                         bundle_add(b, buf_key, buf_val);
750
751                         /* Save text bundle */
752                         noti->b_text = b;
753                 }
754         }
755
756         /* Save key if key is valid data */
757         if (key != NULL) {
758                 /* Check key bundle exist */
759                 if (noti->b_key != NULL) {
760                         /* If key bundle exist,  store local bundle data */
761                         b = noti->b_key;
762
763                         /* Make type to key as char string */
764                         snprintf(buf_key, sizeof(buf_key), "%d", type);
765
766                         /* Get value using type key */
767                         ret_val = bundle_get_val(b, buf_key);
768                         if (ret_val != NULL) {
769                                 /* If value exist, remove this to add new value */
770                                 bundle_del(b, buf_key);
771                         }
772
773                         snprintf(buf_val, sizeof(buf_val), "%s", key);
774
775                         /* Add new key value */
776                         bundle_add(b, buf_key, buf_val);
777                 } else {
778                         /* If key bundle does not exist, create new one */
779                         b = bundle_create();
780
781                         /* Make type to key as char string */
782                         snprintf(buf_key, sizeof(buf_key), "%d", type);
783
784                         snprintf(buf_val, sizeof(buf_val), "%s", key);
785
786                         /* Add new key value */
787                         bundle_add(b, buf_key, buf_val);
788
789                         /* Save key bundle */
790                         noti->b_key = b;
791                 }
792         }
793
794         if (noti->b_format_args != NULL) {
795                 b = noti->b_format_args;
796         } else {
797                 b = bundle_create();
798         }
799
800         va_start(var_args, args_type);
801
802         var_type = args_type;
803         num_args = 0;
804
805         while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
806                 /* Type */
807                 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
808                 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
809
810                 ret_val = bundle_get_val(b, buf_key);
811                 if (ret_val != NULL) {
812                         bundle_del(b, buf_key);
813                 }
814
815                 bundle_add(b, buf_key, buf_val);
816
817                 switch (var_type) {
818                 case NOTIFICATION_VARIABLE_TYPE_INT:
819                         var_value_int = va_arg(var_args, int);
820
821                         /* Value */
822                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
823                                  num_args);
824                         snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
825
826                         ret_val = bundle_get_val(b, buf_key);
827                         if (ret_val != NULL) {
828                                 bundle_del(b, buf_key);
829                         }
830
831                         bundle_add(b, buf_key, buf_val);
832                         break;
833                 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
834                         var_value_double = va_arg(var_args, double);
835
836                         /* Value */
837                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
838                                  num_args);
839                         snprintf(buf_val, sizeof(buf_val), "%.2f",
840                                  var_value_double);
841
842                         ret_val = bundle_get_val(b, buf_key);
843                         if (ret_val != NULL) {
844                                 bundle_del(b, buf_key);
845                         }
846
847                         bundle_add(b, buf_key, buf_val);
848                         break;
849                 case NOTIFICATION_VARIABLE_TYPE_STRING:
850                         var_value_string = va_arg(var_args, char *);
851
852                         /* Value */
853                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
854                                  num_args);
855                         snprintf(buf_val, sizeof(buf_val), "%s",
856                                  var_value_string);
857
858                         ret_val = bundle_get_val(b, buf_key);
859                         if (ret_val != NULL) {
860                                 bundle_del(b, buf_key);
861                         }
862
863                         bundle_add(b, buf_key, buf_val);
864                         break;
865                 case NOTIFICATION_VARIABLE_TYPE_COUNT:
866                         var_value_count =
867                             va_arg(var_args, notification_count_pos_type_e);
868
869                         /* Value */
870                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
871                                  num_args);
872                         snprintf(buf_val, sizeof(buf_val), "%d",
873                                  var_value_count);
874
875                         ret_val = bundle_get_val(b, buf_key);
876                         if (ret_val != NULL) {
877                                 bundle_del(b, buf_key);
878                         }
879
880                         bundle_add(b, buf_key, buf_val);
881                         break;
882                 default:
883                         NOTIFICATION_ERR("Error. invalid variable type. : %d",
884                                          var_type);
885                         noti_err = NOTIFICATION_ERROR_INVALID_DATA;
886                         break;
887                 }
888
889                 num_args++;
890                 var_type = va_arg(var_args, notification_variable_type_e);
891         }
892         va_end(var_args);
893
894         if (noti_err == NOTIFICATION_ERROR_NONE) {
895                 noti->num_format_args = num_args;
896         } else {
897                 noti->num_format_args = 0;
898         }
899
900         snprintf(buf_key, sizeof(buf_key), "num%d", type);
901         snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
902
903         ret_val = bundle_get_val(b, buf_key);
904         if (ret_val != NULL) {
905                 bundle_del(b, buf_key);
906         }
907
908         bundle_add(b, buf_key, buf_val);
909
910         noti->b_format_args = b;
911
912         return noti_err;
913 }
914
915 EXPORT_API notification_error_e notification_get_text(notification_h noti,
916                                                       notification_text_type_e type,
917                                                       char **text)
918 {
919         bundle *b = NULL;
920         char buf_key[32] = { 0, };
921         const char *ret_val = NULL;
922         const char *pkgname = NULL;
923         const char *get_str = NULL;
924         const char *get_check_type_str = NULL;
925         int ret = 0;
926         int boolval = 0;
927         notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
928         int display_option_flag = 0;
929
930         char *temp_str = NULL;
931         char result_str[1024] = { 0, };
932         char buf_str[1024] = { 0, };
933         int num_args = 0;
934         notification_variable_type_e ret_var_type = 0;
935         int ret_variable_int = 0;
936         double ret_variable_double = 0.0;
937
938         /* Check noti is valid data */
939         if (noti == NULL || text == NULL) {
940                 return NOTIFICATION_ERROR_INVALID_DATA;
941         }
942
943         /* Check text type is valid type */
944         if (type <= NOTIFICATION_TEXT_TYPE_NONE
945             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
946                 return NOTIFICATION_ERROR_INVALID_DATA;
947         }
948
949         /* Check content display option of setting */
950         if (type == NOTIFICATION_TEXT_TYPE_CONTENT
951             || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
952                 ret =
953                     vconf_get_bool
954                     (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL,
955                      &boolval);
956                 if (ret == -1 || boolval == 0) {
957                         /* Set flag as display option is OFF */
958                         display_option_flag = 1;
959                 }
960         }
961
962         /* Check key */
963         if (noti->b_key != NULL) {
964                 b = noti->b_key;
965
966                 /* Get text domain and dir */
967                 _notification_get_text_domain(noti);
968
969                 snprintf(buf_key, sizeof(buf_key), "%d", type);
970
971                 ret_val = bundle_get_val(b, buf_key);
972                 if (ret_val != NULL && noti->domain != NULL
973                     && noti->dir != NULL) {
974                         /* Get application string */
975                         bindtextdomain(noti->domain, noti->dir);
976
977                         get_str = dgettext(noti->domain, ret_val);
978                 } else if (ret_val != NULL) {
979                         /* Get system string */
980                         get_str = dgettext("sys_string", ret_val);
981                 } else {
982                         get_str = NULL;
983                 }
984         }
985
986         if (get_str == NULL && noti->b_text != NULL) {
987                 b = noti->b_text;
988                 /* Get basic text */
989                 snprintf(buf_key, sizeof(buf_key), "%d", type);
990
991                 get_str = bundle_get_val(b, buf_key);
992         }
993
994         check_type = type;
995
996         /* Set display option is off type when option is off, type is noti */
997         if (get_str != NULL && display_option_flag == 1
998             && noti->type == NOTIFICATION_TYPE_NOTI) {
999                 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
1000                     || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
1001                         /* Set check_type to option content string */
1002                         if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
1003                                 check_type =
1004                                     NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
1005                         } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
1006                                 check_type =
1007                                     NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
1008                         }
1009
1010                         /* Check key */
1011                         if (noti->b_key != NULL) {
1012                                 b = noti->b_key;
1013
1014                                 /* Get text domain and dir */
1015                                 _notification_get_text_domain(noti);
1016
1017                                 snprintf(buf_key, sizeof(buf_key), "%d",
1018                                          check_type);
1019
1020                                 ret_val = bundle_get_val(b, buf_key);
1021                                 if (ret_val != NULL && noti->domain != NULL
1022                                     && noti->dir != NULL) {
1023                                         /* Get application string */
1024                                         bindtextdomain(noti->domain, noti->dir);
1025
1026                                         get_check_type_str =
1027                                             dgettext(noti->domain, ret_val);
1028                                 } else if (ret_val != NULL) {
1029                                         /* Get system string */
1030                                         get_check_type_str =
1031                                             dgettext("sys_string", ret_val);
1032                                 } else {
1033                                         get_check_type_str = NULL;
1034                                 }
1035                         }
1036
1037                         if (get_check_type_str == NULL && noti->b_text != NULL) {
1038                                 b = noti->b_text;
1039                                 /* Get basic text */
1040                                 snprintf(buf_key, sizeof(buf_key), "%d",
1041                                          check_type);
1042
1043                                 get_check_type_str = bundle_get_val(b, buf_key);
1044                         }
1045                 }
1046
1047                 if (get_check_type_str != NULL) {
1048                         /* Replace option off type string */
1049                         get_str = get_check_type_str;
1050                 } else {
1051                         /* Set default string */
1052                         get_str =
1053                             dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
1054                 }
1055         }
1056
1057         if (get_str != NULL) {
1058                 /* Get number format args */
1059                 b = noti->b_format_args;
1060                 noti->num_format_args = 0;
1061
1062                 if (b != NULL) {
1063                         snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
1064                         ret_val = bundle_get_val(b, buf_key);
1065                         if (ret_val != NULL) {
1066                                 noti->num_format_args = atoi(ret_val);
1067                         }
1068                 }
1069
1070                 if (noti->num_format_args == 0) {
1071                         *text = (char *)get_str;
1072                 } else {
1073                         /* Check first variable is count, LEFT pos */
1074                         snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1075                                  check_type, num_args);
1076                         ret_val = bundle_get_val(b, buf_key);
1077                         ret_var_type = atoi(ret_val);
1078
1079                         if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
1080                                 /* Get var Value */
1081                                 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
1082                                          check_type, num_args);
1083                                 ret_val = bundle_get_val(b, buf_key);
1084                                 ret_variable_int = atoi(ret_val);
1085
1086                                 if (ret_variable_int ==
1087                                     NOTIFICATION_COUNT_POS_LEFT) {
1088                                         notification_noti_get_count(noti->type,
1089                                                                     noti->caller_pkgname,
1090                                                                     noti->group_id,
1091                                                                     noti->priv_id,
1092                                                                     &ret_variable_int);
1093                                         snprintf(buf_str, sizeof(buf_str),
1094                                                  "%d ", ret_variable_int);
1095                                         strncat(result_str, buf_str,
1096                                                 sizeof(result_str));
1097
1098                                         num_args++;
1099                                 }
1100
1101                         }
1102
1103                         /* Check variable IN pos */
1104                         for (temp_str = (char *)get_str; *temp_str != '\0';
1105                              temp_str++) {
1106                                 if (*temp_str != '%') {
1107                                         strncat(result_str, temp_str, 1);
1108                                 } else {
1109                                         if (*(temp_str + 1) == '%') {
1110                                                 strncat(result_str, temp_str,
1111                                                         1);
1112                                         } else if (*(temp_str + 1) == 'd') {
1113                                                 /* Get var Type */
1114                                                 ret_variable_int = 0;
1115
1116                                                 snprintf(buf_key,
1117                                                          sizeof(buf_key),
1118                                                          "%dtype%d", check_type,
1119                                                          num_args);
1120                                                 ret_val =
1121                                                     bundle_get_val(b, buf_key);
1122                                                 ret_var_type = atoi(ret_val);
1123                                                 if (ret_var_type ==
1124                                                     NOTIFICATION_VARIABLE_TYPE_COUNT)
1125                                                 {
1126                                                         /* Get notification count */
1127                                                         notification_noti_get_count
1128                                                             (noti->type,
1129                                                              noti->caller_pkgname,
1130                                                              noti->group_id,
1131                                                              noti->priv_id,
1132                                                              &ret_variable_int);
1133                                                 } else {
1134                                                         /* Get var Value */
1135                                                         snprintf(buf_key,
1136                                                                  sizeof
1137                                                                  (buf_key),
1138                                                                  "%dvalue%d",
1139                                                                  check_type,
1140                                                                  num_args);
1141                                                         ret_val =
1142                                                             bundle_get_val(b,
1143                                                                            buf_key);
1144                                                         ret_variable_int =
1145                                                             atoi(ret_val);
1146                                                 }
1147
1148                                                 snprintf(buf_str,
1149                                                          sizeof(buf_str), "%d",
1150                                                          ret_variable_int);
1151                                                 strncat(result_str, buf_str,
1152                                                         sizeof(result_str));
1153
1154                                                 temp_str++;
1155
1156                                                 num_args++;
1157                                         } else if (*(temp_str + 1) == 's') {
1158                                                 /* Get var Value */
1159                                                 snprintf(buf_key,
1160                                                          sizeof(buf_key),
1161                                                          "%dvalue%d",
1162                                                          check_type, num_args);
1163                                                 ret_val =
1164                                                     bundle_get_val(b, buf_key);
1165
1166                                                 snprintf(buf_str,
1167                                                          sizeof(buf_str), "%s",
1168                                                          ret_val);
1169                                                 strncat(result_str, buf_str,
1170                                                         sizeof(result_str));
1171
1172                                                 temp_str++;
1173
1174                                                 num_args++;
1175                                         } else if (*(temp_str + 1) == 'f') {
1176                                                 /* Get var Value */
1177                                                 snprintf(buf_key,
1178                                                          sizeof(buf_key),
1179                                                          "%dvalue%d",
1180                                                          check_type, num_args);
1181                                                 ret_val =
1182                                                     bundle_get_val(b, buf_key);
1183                                                 ret_variable_double =
1184                                                     atof(ret_val);
1185
1186                                                 snprintf(buf_str,
1187                                                          sizeof(buf_str),
1188                                                          "%.2f",
1189                                                          ret_variable_double);
1190                                                 strncat(result_str, buf_str,
1191                                                         sizeof(result_str));
1192
1193                                                 temp_str++;
1194
1195                                                 num_args++;
1196                                         }
1197                                 }
1198
1199                         }
1200
1201                         /* Check last variable is count, LEFT pos */
1202                         if (num_args < noti->num_format_args) {
1203                                 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1204                                          check_type, num_args);
1205                                 ret_val = bundle_get_val(b, buf_key);
1206                                 ret_var_type = atoi(ret_val);
1207                                 if (ret_var_type ==
1208                                     NOTIFICATION_VARIABLE_TYPE_COUNT) {
1209                                         /* Get var Value */
1210                                         snprintf(buf_key, sizeof(buf_key),
1211                                                  "%dvalue%d", check_type,
1212                                                  num_args);
1213                                         ret_val = bundle_get_val(b, buf_key);
1214                                         ret_variable_int = atoi(ret_val);
1215
1216                                         if (ret_variable_int ==
1217                                             NOTIFICATION_COUNT_POS_RIGHT) {
1218                                                 notification_noti_get_count
1219                                                     (noti->type,
1220                                                      noti->caller_pkgname,
1221                                                      noti->group_id,
1222                                                      noti->priv_id,
1223                                                      &ret_variable_int);
1224                                                 snprintf(buf_str,
1225                                                          sizeof(buf_str), " %d",
1226                                                          ret_variable_int);
1227                                                 strncat(result_str, buf_str,
1228                                                         sizeof(result_str));
1229
1230                                                 num_args++;
1231                                         }
1232
1233                                 }
1234                         }
1235
1236                         switch (check_type) {
1237                         case NOTIFICATION_TEXT_TYPE_TITLE:
1238                         case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
1239                                 if (noti->temp_title != NULL)
1240                                         free(noti->temp_title);
1241
1242                                 noti->temp_title = strdup(result_str);
1243
1244                                 *text = noti->temp_title;
1245                                 break;
1246                         case NOTIFICATION_TEXT_TYPE_CONTENT:
1247                         case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1248                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
1249                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1250                                 if (noti->temp_content !=
1251                                     NULL)
1252                                         free(noti->temp_content);
1253
1254                                 noti->temp_content = strdup(result_str);
1255
1256                                 *text = noti->temp_content;
1257                                 break;
1258                         default:
1259                                 break;
1260                         }
1261
1262                 }
1263
1264         } else {
1265                 if (check_type == NOTIFICATION_TEXT_TYPE_TITLE
1266                     || check_type == NOTIFICATION_TEXT_TYPE_GROUP_TITLE) {
1267                         /* Remove app name if exist, because pkgname is changed according to language setting */
1268                         if (noti->app_name != NULL) {
1269                                 free(noti->app_name);
1270                                 noti->app_name = NULL;
1271                         }
1272
1273                         /* First, get app name from launch_pkgname */
1274                         if (noti->launch_pkgname != NULL) {
1275                                 noti->app_name =
1276                                     _notification_get_name(noti->
1277                                                            launch_pkgname);
1278                         }
1279
1280                         /* Second, get app name from caller_pkgname */
1281                         if (noti->app_name == NULL
1282                             && noti->caller_pkgname != NULL) {
1283                                 noti->app_name =
1284                                     _notification_get_name(noti->
1285                                                            caller_pkgname);
1286                         }
1287
1288                         /* Third, get app name from service data */
1289                         if (noti->app_name == NULL
1290                             && noti->b_service_single_launch != NULL) {
1291                                 pkgname =
1292                                     appsvc_get_pkgname(noti->
1293                                                        b_service_single_launch);
1294
1295                                 if (pkgname != NULL) {
1296                                         noti->app_name =
1297                                             _notification_get_name(pkgname);
1298                                 }
1299                         }
1300
1301                         *text = noti->app_name;
1302                 } else {
1303                         *text = NULL;
1304                 }
1305         }
1306
1307         NOTIFICATION_INFO("Get text : %s", *text);
1308
1309         return NOTIFICATION_ERROR_NONE;
1310 }
1311
1312 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
1313                                                              const char *domain,
1314                                                              const char *dir)
1315 {
1316         /* check noti and domain is valid data */
1317         if (noti == NULL || domain == NULL) {
1318                 return NOTIFICATION_ERROR_INVALID_DATA;
1319         }
1320
1321         /* Check domain */
1322         if (noti->domain) {
1323                 /* Remove previous domain */
1324                 free(noti->domain);
1325         }
1326         /* Copy domain */
1327         noti->domain = strdup(domain);
1328
1329         /* Check locale dir */
1330         if (noti->dir) {
1331                 /* Remove previous locale dir */
1332                 free(noti->dir);
1333         }
1334         /* Copy locale dir */
1335         noti->dir = strdup(dir);
1336
1337         return NOTIFICATION_ERROR_NONE;
1338 }
1339
1340 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
1341                                                              char **domain,
1342                                                              char **dir)
1343 {
1344         /* Check noti is valid data */
1345         if (noti == NULL) {
1346                 return NOTIFICATION_ERROR_INVALID_DATA;
1347         }
1348
1349         /* Get domain */
1350         if (domain != NULL && noti->domain != NULL) {
1351                 *domain = noti->domain;
1352         }
1353
1354         /* Get locale dir */
1355         if (dir != NULL && noti->dir != NULL) {
1356                 *dir = noti->dir;
1357         }
1358
1359         return NOTIFICATION_ERROR_NONE;
1360 }
1361
1362 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1363                                                        notification_sound_type_e type,
1364                                                        const char *path)
1365 {
1366         /* Check noti is valid data */
1367         if (noti == NULL) {
1368                 return NOTIFICATION_ERROR_INVALID_DATA;
1369         }
1370
1371         /* Check type is valid */
1372         if (type < NOTIFICATION_SOUND_TYPE_NONE
1373             || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1374                 return NOTIFICATION_ERROR_INVALID_DATA;
1375         }
1376
1377         /* Save sound type */
1378         noti->sound_type = type;
1379
1380         /* Save sound path if user data type */
1381         if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1382                 if (noti->sound_path != NULL) {
1383                         free(noti->sound_path);
1384                 }
1385
1386                 noti->sound_path = strdup(path);
1387         } else {
1388                 if (noti->sound_path != NULL) {
1389                         free(noti->sound_path);
1390                         noti->sound_path = NULL;
1391                 }
1392         }
1393
1394         return NOTIFICATION_ERROR_NONE;
1395 }
1396
1397 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1398                                                        notification_sound_type_e *type,
1399                                                        const char **path)
1400 {
1401         /* check noti and type is valid data */
1402         if (noti == NULL || type == NULL) {
1403                 return NOTIFICATION_ERROR_INVALID_DATA;
1404         }
1405
1406         /* Set sound type */
1407         *type = noti->sound_type;
1408
1409         /* Set sound path if user data type */
1410         if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1411             && path != NULL) {
1412                 *path = noti->sound_path;
1413         }
1414
1415         return NOTIFICATION_ERROR_NONE;
1416 }
1417
1418 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1419                                                            notification_vibration_type_e type,
1420                                                            const char *path)
1421 {
1422         /* Check noti is valid data */
1423         if (noti == NULL) {
1424                 return NOTIFICATION_ERROR_INVALID_DATA;
1425         }
1426
1427         /* Check type is valid */
1428         if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1429             || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1430                 return NOTIFICATION_ERROR_INVALID_DATA;
1431         }
1432
1433         /* Save vibration type */
1434         noti->vibration_type = type;
1435
1436         /* Save sound path if user data type */
1437         if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1438                 if (noti->vibration_path != NULL) {
1439                         free(noti->vibration_path);
1440                 }
1441
1442                 noti->vibration_path = strdup(path);
1443         } else {
1444                 if (noti->vibration_path != NULL) {
1445                         free(noti->vibration_path);
1446                         noti->vibration_path = NULL;
1447                 }
1448         }
1449
1450         return NOTIFICATION_ERROR_NONE;
1451
1452 }
1453
1454 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1455                                                            notification_vibration_type_e *type,
1456                                                            const char **path)
1457 {
1458         /* check noti and type is valid data */
1459         if (noti == NULL || type == NULL) {
1460                 return NOTIFICATION_ERROR_INVALID_DATA;
1461         }
1462
1463         /* Set vibration type */
1464         *type = noti->vibration_type;
1465
1466         /* Set sound path if user data type */
1467         if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1468             && path != NULL) {
1469                 *path = noti->vibration_path;
1470         }
1471
1472         return NOTIFICATION_ERROR_NONE;
1473 }
1474
1475 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1476                                                              const char *pkgname)
1477 {
1478         if (noti == NULL || pkgname == NULL) {
1479                 return NOTIFICATION_ERROR_INVALID_DATA;
1480         }
1481
1482         if (noti->launch_pkgname) {
1483                 free(noti->launch_pkgname);
1484         }
1485
1486         noti->launch_pkgname = strdup(pkgname);
1487
1488         return NOTIFICATION_ERROR_NONE;
1489 }
1490
1491 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1492                                                              char **pkgname)
1493 {
1494         if (noti == NULL || pkgname == NULL) {
1495                 return NOTIFICATION_ERROR_INVALID_DATA;
1496         }
1497
1498         if (noti->launch_pkgname) {
1499                 *pkgname = noti->launch_pkgname;
1500         } else {
1501                 *pkgname = noti->caller_pkgname;
1502         }
1503
1504         return NOTIFICATION_ERROR_NONE;
1505 }
1506
1507 EXPORT_API notification_error_e notification_set_args(notification_h noti,
1508                                                       bundle * args,
1509                                                       bundle * group_args)
1510 {
1511         if (noti == NULL || args == NULL) {
1512                 return NOTIFICATION_ERROR_INVALID_DATA;
1513         }
1514
1515         if (noti->args) {
1516                 bundle_free(noti->args);
1517         }
1518
1519         noti->args = bundle_dup(args);
1520
1521         if (noti->group_args) {
1522                 bundle_free(noti->group_args);
1523                 noti->group_args = NULL;
1524         }
1525
1526         if (group_args != NULL) {
1527                 noti->group_args = bundle_dup(group_args);
1528         }
1529
1530         return NOTIFICATION_ERROR_NONE;
1531 }
1532
1533 EXPORT_API notification_error_e notification_get_args(notification_h noti,
1534                                                       bundle ** args,
1535                                                       bundle ** group_args)
1536 {
1537         if (noti == NULL || args == NULL) {
1538                 return NOTIFICATION_ERROR_INVALID_DATA;
1539         }
1540
1541         if (noti->args) {
1542                 *args = noti->args;
1543         } else {
1544                 *args = NULL;
1545         }
1546
1547         if (group_args != NULL && noti->group_args) {
1548                 *group_args = noti->group_args;
1549         }
1550
1551         return NOTIFICATION_ERROR_NONE;
1552 }
1553
1554 EXPORT_API notification_error_e notification_set_service_data(notification_h noti,
1555                                                               bundle * service_data,
1556                                                               bundle * group_service_data)
1557 {
1558         int noti_err = NOTIFICATION_ERROR_NONE;
1559
1560         noti_err =
1561             notification_set_execute_option(noti,
1562                                             NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1563                                             NULL, NULL, service_data);
1564         if (noti_err != NOTIFICATION_ERROR_NONE) {
1565                 return noti_err;
1566         }
1567
1568         noti_err =
1569             notification_set_execute_option(noti,
1570                                             NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH,
1571                                             NULL, NULL, group_service_data);
1572
1573         return noti_err;
1574 }
1575
1576 EXPORT_API notification_error_e notification_get_service_data(notification_h noti,
1577                                                               bundle ** service_data,
1578                                                               bundle ** group_service_data)
1579 {
1580         int noti_err = NOTIFICATION_ERROR_NONE;
1581         bundle *get_service_data = NULL;
1582
1583         noti_err =
1584             notification_get_execute_option(noti,
1585                                             NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1586                                             NULL, &get_service_data);
1587         if (noti_err != NOTIFICATION_ERROR_NONE) {
1588                 return noti_err;
1589         }
1590
1591         if (service_data != NULL) {
1592                 *service_data = get_service_data;
1593         }
1594
1595         noti_err =
1596             notification_get_execute_option(noti,
1597                                             NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH,
1598                                             NULL, &get_service_data);
1599         if (noti_err != NOTIFICATION_ERROR_NONE) {
1600                 return noti_err;
1601         }
1602
1603         if (service_data != NULL) {
1604                 *group_service_data = get_service_data;
1605         }
1606
1607         return NOTIFICATION_ERROR_NONE;
1608 }
1609
1610 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1611                                                                 notification_execute_type_e type,
1612                                                                 const char *text,
1613                                                                 const char *key,
1614                                                                 bundle *service_handle)
1615 {
1616         char buf_key[32] = { 0, };
1617         const char *ret_val = NULL;
1618         bundle *b = NULL;
1619
1620         if (noti == NULL) {
1621                 return NOTIFICATION_ERROR_INVALID_DATA;
1622         }
1623
1624         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1625             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1626                 return NOTIFICATION_ERROR_INVALID_DATA;
1627         }
1628
1629         /* Create execute option bundle if does not exist */
1630         if (noti->b_execute_option != NULL) {
1631                 noti->b_execute_option = bundle_create();
1632         }
1633
1634         b = noti->b_execute_option;
1635
1636         /* Save text */
1637         if (text != NULL) {
1638                 /* Make text key */
1639                 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1640
1641                 /* Check text key exist */
1642                 ret_val = bundle_get_val(b, buf_key);
1643                 if (ret_val != NULL) {
1644                         /* Remove previous data */
1645                         bundle_del(b, buf_key);
1646                 }
1647
1648                 /* Add text data */
1649                 bundle_add(b, buf_key, text);
1650         }
1651
1652         /* Save key */
1653         if (key != NULL) {
1654                 /* Make key key */
1655                 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1656
1657                 /* Check key key exist */
1658                 ret_val = bundle_get_val(b, buf_key);
1659                 if (ret_val != NULL) {
1660                         /* Remove previous data */
1661                         bundle_del(b, buf_key);
1662                 }
1663
1664                 /* Add text data */
1665                 bundle_add(b, buf_key, key);
1666         }
1667
1668         switch (type) {
1669         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1670                 /* Remove previous data if exist */
1671                 if (noti->b_service_responding != NULL) {
1672                         bundle_free(noti->b_service_responding);
1673                         noti->b_service_responding = NULL;
1674                 }
1675
1676                 /* Save service handle */
1677                 if (service_handle != NULL) {
1678                         noti->b_service_responding = bundle_dup(service_handle);
1679                 }
1680                 break;
1681         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1682                 /* Remove previous data if exist */
1683                 if (noti->b_service_single_launch != NULL) {
1684                         bundle_free(noti->b_service_single_launch);
1685                         noti->b_service_single_launch = NULL;
1686                 }
1687
1688                 /* Save service handle */
1689                 if (service_handle != NULL) {
1690                         noti->b_service_single_launch =
1691                             bundle_dup(service_handle);
1692                 }
1693                 break;
1694         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1695                 /* Remove previous data if exist */
1696                 if (noti->b_service_multi_launch != NULL) {
1697                         bundle_free(noti->b_service_multi_launch);
1698                         noti->b_service_multi_launch = NULL;
1699                 }
1700
1701                 /* Save service handle */
1702                 if (service_handle != NULL) {
1703                         noti->b_service_multi_launch =
1704                             bundle_dup(service_handle);
1705                 }
1706                 break;
1707         default:
1708                 break;
1709         }
1710
1711         return NOTIFICATION_ERROR_NONE;
1712 }
1713
1714 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1715                                                                 notification_execute_type_e type,
1716                                                                 const char **text,
1717                                                                 bundle **service_handle)
1718 {
1719         char buf_key[32] = { 0, };
1720         const char *ret_val = NULL;
1721         char *get_str = NULL;
1722         bundle *b = NULL;
1723
1724         if (noti == NULL) {
1725                 return NOTIFICATION_ERROR_INVALID_DATA;
1726         }
1727
1728         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1729             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1730                 return NOTIFICATION_ERROR_INVALID_DATA;
1731         }
1732
1733         switch (type) {
1734         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1735                 b = noti->b_service_responding;
1736                 break;
1737         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1738                 b = noti->b_service_single_launch;
1739                 break;
1740         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1741                 b = noti->b_service_multi_launch;
1742                 break;
1743         default:
1744                 b = NULL;
1745                 break;
1746         }
1747
1748         if (b != NULL) {
1749                 // Return text
1750                 if (text != NULL) {
1751                         // Get text domain and dir
1752                         if (noti->domain == NULL || noti->dir == NULL) {
1753                                 _notification_get_text_domain(noti);
1754                         }
1755
1756                         /* Make key */
1757                         snprintf(buf_key, sizeof(buf_key), "key%d", type);
1758
1759                         /* Check key key exist */
1760                         ret_val = bundle_get_val(b, buf_key);
1761                         if (ret_val != NULL && noti->domain != NULL
1762                             && noti->dir != NULL) {
1763                                 /* Get application string */
1764                                 bindtextdomain(noti->domain, noti->dir);
1765
1766                                 get_str = dgettext(noti->domain, ret_val);
1767
1768                                 *text = get_str;
1769                         } else if (ret_val != NULL) {
1770                                 /* Get system string */
1771                                 get_str = dgettext("sys_string", ret_val);
1772
1773                                 *text = get_str;
1774                         } else {
1775                                 /* Get basic text */
1776                                 snprintf(buf_key, sizeof(buf_key), "text%d",
1777                                          type);
1778
1779                                 ret_val = bundle_get_val(b, buf_key);
1780
1781                                 *text = ret_val;
1782                         }
1783                 }
1784         }
1785
1786         switch (type) {
1787         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1788                 b = noti->b_service_responding;
1789                 break;
1790         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1791                 b = noti->b_service_single_launch;
1792                 break;
1793         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1794                 b = noti->b_service_multi_launch;
1795                 break;
1796         default:
1797                 b = NULL;
1798                 break;
1799         }
1800
1801         if (service_handle != NULL) {
1802                 *service_handle = b;
1803         }
1804
1805         return NOTIFICATION_ERROR_NONE;
1806 }
1807
1808 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1809                                                           int flags)
1810 {
1811         /* Check noti is valid data */
1812         if (noti == NULL) {
1813                 return NOTIFICATION_ERROR_INVALID_DATA;
1814         }
1815
1816         /* Set flags */
1817         noti->flags_for_property = flags;
1818
1819         return NOTIFICATION_ERROR_NONE;
1820 }
1821
1822 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1823                                                           int *flags)
1824 {
1825         /* Check noti and flags are valid data */
1826         if (noti == NULL || flags == NULL) {
1827                 return NOTIFICATION_ERROR_INVALID_DATA;
1828         }
1829
1830         /* Set flags */
1831         *flags = noti->flags_for_property;
1832
1833         return NOTIFICATION_ERROR_NONE;
1834 }
1835
1836 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1837                                                                  int applist)
1838 {
1839         /* Check noti is valid data */
1840         if (noti == NULL) {
1841                 return NOTIFICATION_ERROR_INVALID_DATA;
1842         }
1843
1844         /* Set app list */
1845         noti->display_applist = applist;
1846
1847         return NOTIFICATION_ERROR_NONE;
1848 }
1849
1850 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1851                                                                  int *applist)
1852 {
1853         /* Check noti and applist are valid data */
1854         if (noti == NULL || applist == NULL) {
1855                 return NOTIFICATION_ERROR_INVALID_DATA;
1856         }
1857
1858         /* Set app list */
1859         *applist = noti->display_applist;
1860
1861         return NOTIFICATION_ERROR_NONE;
1862 }
1863
1864 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1865                                                       double size)
1866 {
1867         /* Check noti is valid data */
1868         if (noti == NULL) {
1869                 return NOTIFICATION_ERROR_INVALID_DATA;
1870         }
1871
1872         /* Save progress size */
1873         noti->progress_size = size;
1874
1875         return NOTIFICATION_ERROR_NONE;
1876 }
1877
1878 EXPORT_API notification_error_e notification_get_size(notification_h noti,
1879                                                       double *size)
1880 {
1881         /* Check noti and size is valid data */
1882         if (noti == NULL || size == NULL) {
1883                 return NOTIFICATION_ERROR_INVALID_DATA;
1884         }
1885
1886         /* Set progress size */
1887         *size = noti->progress_size;
1888
1889         return NOTIFICATION_ERROR_NONE;
1890 }
1891
1892 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
1893                                                           double percentage)
1894 {
1895         /* Check noti is valid data */
1896         if (noti == NULL) {
1897                 return NOTIFICATION_ERROR_INVALID_DATA;
1898         }
1899
1900         /* Save progress percentage */
1901         noti->progress_percentage = percentage;
1902
1903         return NOTIFICATION_ERROR_NONE;
1904 }
1905
1906 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
1907                                                           double *percentage)
1908 {
1909         /* Check noti and percentage are valid data */
1910         if (noti == NULL || percentage == NULL) {
1911                 return NOTIFICATION_ERROR_INVALID_DATA;
1912         }
1913
1914         /* Set progress percentage */
1915         *percentage = noti->progress_percentage;
1916
1917         return NOTIFICATION_ERROR_NONE;
1918 }
1919
1920 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
1921                                                          const char *pkgname)
1922 {
1923         /* check noti and pkgname are valid data */
1924         if (noti == NULL || pkgname == NULL) {
1925                 return NOTIFICATION_ERROR_INVALID_DATA;
1926         }
1927
1928         /* Remove previous caller pkgname */
1929         if (noti->caller_pkgname) {
1930                 free(noti->caller_pkgname);
1931                 noti->caller_pkgname = NULL;
1932         }
1933
1934         noti->caller_pkgname = strdup(pkgname);
1935
1936         return NOTIFICATION_ERROR_NONE;
1937 }
1938
1939 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
1940                                                          char **pkgname)
1941 {
1942         /* Check noti and pkgname are valid data */
1943         if (noti == NULL || pkgname == NULL) {
1944                 return NOTIFICATION_ERROR_INVALID_DATA;
1945         }
1946
1947         /* Get caller pkgname */
1948         if (noti->caller_pkgname) {
1949                 *pkgname = noti->caller_pkgname;
1950         } else {
1951                 *pkgname = NULL;
1952         }
1953
1954         return NOTIFICATION_ERROR_NONE;
1955 }
1956
1957 EXPORT_API notification_error_e notification_set_unread_count(const char *pkgname,
1958                                                               int group_id,
1959                                                               int unread_count)
1960 {
1961         int ret = NOTIFICATION_ERROR_NONE;
1962
1963         ret = notification_set_badge(pkgname, group_id, unread_count);
1964
1965         return ret;
1966 }
1967
1968 EXPORT_API notification_error_e notification_get_unread_count(const char *pkgname,
1969                                                               int group_id,
1970                                                               int *unread_count)
1971 {
1972         int ret = NOTIFICATION_ERROR_NONE;
1973         int ret_unread_count = 0;
1974
1975         ret = notification_get_badge(pkgname, group_id, &ret_unread_count);
1976
1977         if (unread_count != NULL) {
1978                 *unread_count = ret_unread_count;
1979         }
1980
1981         return ret;
1982 }
1983
1984 EXPORT_API notification_error_e notification_set_badge(const char *pkgname,
1985                                                        int group_id, int count)
1986 {
1987         char *caller_pkgname = NULL;
1988         int ret = NOTIFICATION_ERROR_NONE;
1989
1990         /* Check count is valid count */
1991         if (count < 0) {
1992                 return NOTIFICATION_ERROR_INVALID_DATA;
1993         }
1994
1995         /* Check pkgname */
1996         if (pkgname == NULL) {
1997                 caller_pkgname = _notification_get_pkgname_by_pid();
1998
1999                 /* Set count into Group DB */
2000                 ret =
2001                     notification_group_set_badge(caller_pkgname, group_id,
2002                                                  count);
2003
2004                 if (caller_pkgname != NULL) {
2005                         free(caller_pkgname);
2006                 }
2007         } else {
2008                 /* Set count into Group DB */
2009                 ret = notification_group_set_badge(pkgname, group_id, count);
2010         }
2011
2012         return ret;
2013 }
2014
2015 EXPORT_API notification_error_e notification_get_badge(const char *pkgname,
2016                                                        int group_id, int *count)
2017 {
2018         char *caller_pkgname = NULL;
2019         int ret = NOTIFICATION_ERROR_NONE;
2020         int ret_unread_count = 0;
2021
2022         /* Check pkgname */
2023         if (pkgname == NULL) {
2024                 caller_pkgname = _notification_get_pkgname_by_pid();
2025
2026                 /* Get count from Group DB */
2027                 ret =
2028                     notification_group_get_badge(caller_pkgname, group_id,
2029                                                  &ret_unread_count);
2030
2031                 if (caller_pkgname != NULL) {
2032                         free(caller_pkgname);
2033                 }
2034         } else {
2035                 /* Get count from Group DB */
2036                 ret =
2037                     notification_group_get_badge(pkgname, group_id,
2038                                                  &ret_unread_count);
2039         }
2040
2041         if (ret != NOTIFICATION_ERROR_NONE) {
2042                 return ret;
2043         }
2044
2045         /* Set count */
2046         if (count != NULL) {
2047                 *count = ret_unread_count;
2048         }
2049
2050         return NOTIFICATION_ERROR_NONE;
2051 }
2052
2053 EXPORT_API notification_error_e notification_get_id(notification_h noti,
2054                                                     int *group_id, int *priv_id)
2055 {
2056         /* check noti is valid data */
2057         if (noti == NULL) {
2058                 return NOTIFICATION_ERROR_INVALID_DATA;
2059         }
2060
2061         /* Check group_id is valid data */
2062         if (group_id) {
2063                 /* Set group id */
2064                 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
2065                         *group_id = NOTIFICATION_GROUP_ID_NONE;
2066                 } else {
2067                         *group_id = noti->group_id;
2068                 }
2069         }
2070
2071         /* Check priv_id is valid data */
2072         if (priv_id) {
2073                 /* Set priv_id */
2074                 *priv_id = noti->priv_id;
2075         }
2076
2077         return NOTIFICATION_ERROR_NONE;
2078 }
2079
2080 EXPORT_API notification_error_e notification_get_type(notification_h noti,
2081                                                       notification_type_e *type)
2082 {
2083         /* Check noti and type is valid data */
2084         if (noti == NULL || type == NULL) {
2085                 return NOTIFICATION_ERROR_INVALID_DATA;
2086         }
2087
2088         /* Set noti type */
2089         *type = noti->type;
2090
2091         return NOTIFICATION_ERROR_NONE;
2092 }
2093
2094 EXPORT_API notification_error_e notification_insert(notification_h noti,
2095                                                     int *priv_id)
2096 {
2097         int ret = 0;
2098
2099         /* Check noti is vaild data */
2100         if (noti == NULL) {
2101                 return NOTIFICATION_ERROR_INVALID_DATA;
2102         }
2103
2104         /* Check noti type is valid type */
2105         if (noti->type <= NOTIFICATION_TYPE_NONE
2106             || noti->type >= NOTIFICATION_TYPE_MAX) {
2107                 return NOTIFICATION_ERROR_INVALID_DATA;
2108         }
2109
2110         /* Save insert time */
2111         noti->insert_time = time(NULL);
2112
2113         /* Insert into DB */
2114         ret = notification_noti_insert(noti);
2115         if (ret != NOTIFICATION_ERROR_NONE) {
2116                 return ret;
2117         }
2118
2119         /* Check disable update on insert property */
2120         if (noti->flags_for_property
2121                 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
2122                 /* Disable changed cb */
2123         } else {
2124                 /* Enable changed cb */
2125                 _notification_changed(NOTI_CHANGED_NOTI);
2126         }
2127
2128         /* If priv_id is valid data, set priv_id */
2129         if (priv_id != NULL) {
2130                 *priv_id = noti->priv_id;
2131         }
2132
2133         return NOTIFICATION_ERROR_NONE;
2134 }
2135
2136 EXPORT_API notification_error_e notification_update(notification_h noti)
2137 {
2138         /* Check noti is valid data */
2139         if (noti != NULL) {
2140                 /* TODO : Update noti */
2141         }
2142
2143         /* Send changed notification */
2144         _notification_changed(NOTI_CHANGED_NOTI);
2145
2146         return NOTIFICATION_ERROR_NONE;
2147 }
2148
2149 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
2150 {
2151         int ret = 0;
2152
2153         /* Delete all notification of type */
2154         ret = notification_noti_delete_all(type, NULL);
2155         if (ret != NOTIFICATION_ERROR_NONE) {
2156                 return ret;
2157         }
2158
2159         /* Send chagned notification */
2160         _notification_changed(NOTI_CHANGED_NOTI);
2161
2162         return NOTIFICATION_ERROR_NONE;
2163 }
2164
2165 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
2166                                                                 notification_type_e type)
2167 {
2168         int ret = 0;
2169         char *caller_pkgname = NULL;
2170
2171         if (pkgname == NULL) {
2172                 caller_pkgname = _notification_get_pkgname_by_pid();
2173         } else {
2174                 caller_pkgname = strdup(pkgname);
2175         }
2176
2177         ret = notification_noti_delete_all(type, caller_pkgname);
2178         if (ret != NOTIFICATION_ERROR_NONE) {
2179                 free(caller_pkgname);
2180                 return ret;
2181         }
2182
2183         _notification_changed(NOTI_CHANGED_NOTI);
2184
2185         free(caller_pkgname);
2186
2187         return ret;
2188 }
2189
2190 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
2191                                                                       notification_type_e type,
2192                                                                       int group_id)
2193 {
2194         int ret = 0;
2195         char *caller_pkgname = NULL;
2196
2197         if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2198                 return NOTIFICATION_ERROR_INVALID_DATA;
2199         }
2200
2201         if (pkgname == NULL) {
2202                 caller_pkgname = _notification_get_pkgname_by_pid();
2203         } else {
2204                 caller_pkgname = strdup(pkgname);
2205         }
2206
2207         ret =
2208             notification_noti_delete_group_by_group_id(caller_pkgname,
2209                                                        group_id);
2210         if (ret != NOTIFICATION_ERROR_NONE) {
2211                 free(caller_pkgname);
2212                 return ret;
2213         }
2214
2215         _notification_changed(NOTI_CHANGED_NOTI);
2216
2217         free(caller_pkgname);
2218
2219         return ret;
2220 }
2221
2222 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2223                                                                      notification_type_e type,
2224                                                                      int priv_id)
2225 {
2226         int ret = 0;
2227         char *caller_pkgname = NULL;
2228
2229         if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2230                 return NOTIFICATION_ERROR_INVALID_DATA;
2231         }
2232
2233         if (pkgname == NULL) {
2234                 caller_pkgname = _notification_get_pkgname_by_pid();
2235         } else {
2236                 caller_pkgname = strdup(pkgname);
2237         }
2238
2239         ret =
2240             notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id);
2241         if (ret != NOTIFICATION_ERROR_NONE) {
2242                 free(caller_pkgname);
2243                 return ret;
2244         }
2245
2246         _notification_changed(NOTI_CHANGED_NOTI);
2247
2248         free(caller_pkgname);
2249
2250         return ret;
2251 }
2252
2253 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
2254                                                                notification_type_e type,
2255                                                                int priv_id)
2256 {
2257         int ret = 0;
2258         char *caller_pkgname = NULL;
2259
2260         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2261                 return NOTIFICATION_ERROR_INVALID_DATA;
2262         }
2263
2264         if (pkgname == NULL) {
2265                 caller_pkgname = _notification_get_pkgname_by_pid();
2266         } else {
2267                 caller_pkgname = strdup(pkgname);
2268         }
2269
2270         ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id);
2271         if (ret != NOTIFICATION_ERROR_NONE) {
2272                 free(caller_pkgname);
2273                 return ret;
2274         }
2275
2276         _notification_changed(NOTI_CHANGED_NOTI);
2277
2278         free(caller_pkgname);
2279
2280         return ret;
2281 }
2282
2283 EXPORT_API notification_error_e notification_delete(notification_h noti)
2284 {
2285         int ret = 0;
2286
2287         if (noti == NULL) {
2288                 return NOTIFICATION_ERROR_INVALID_DATA;
2289         }
2290
2291         ret =
2292             notification_noti_delete_by_priv_id(noti->caller_pkgname,
2293                                                 noti->priv_id);
2294         if (ret != NOTIFICATION_ERROR_NONE) {
2295                 return ret;
2296         }
2297
2298         if (noti->flags_for_property
2299                 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) {
2300                 NOTIFICATION_INFO("Disabled update while delete.");
2301         } else {
2302                 _notification_changed(NOTI_CHANGED_NOTI);
2303         }
2304
2305         return NOTIFICATION_ERROR_NONE;
2306 }
2307
2308 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
2309                                                              int priv_id,
2310                                                              double progress)
2311 {
2312         char *caller_pkgname = NULL;
2313         int input_priv_id = 0;
2314         double input_progress = 0.0;
2315
2316         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2317                 if (noti == NULL) {
2318                         return NOTIFICATION_ERROR_INVALID_DATA;
2319                 } else {
2320                         input_priv_id = noti->priv_id;
2321                 }
2322         } else {
2323                 input_priv_id = priv_id;
2324         }
2325
2326         if (noti == NULL) {
2327                 caller_pkgname = _notification_get_pkgname_by_pid();
2328         } else {
2329                 caller_pkgname = strdup(noti->caller_pkgname);
2330         }
2331
2332         if (progress < 0.0) {
2333                 input_progress = 0.0;
2334         } else if (progress > 1.0) {
2335                 input_progress = 1.0;
2336         } else {
2337                 input_progress = progress;
2338         }
2339
2340         notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2341                                              input_progress);
2342
2343         if (caller_pkgname) {
2344                 free(caller_pkgname);
2345         }
2346
2347         return NOTIFICATION_ERROR_NONE;
2348 }
2349
2350 EXPORT_API notification_error_e notification_update_size(notification_h noti,
2351                                                          int priv_id,
2352                                                          double size)
2353 {
2354         char *caller_pkgname = NULL;
2355         int input_priv_id = 0;
2356         double input_size = 0.0;
2357
2358         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2359                 if (noti == NULL) {
2360                         return NOTIFICATION_ERROR_INVALID_DATA;
2361                 } else {
2362                         input_priv_id = noti->priv_id;
2363                 }
2364         } else {
2365                 input_priv_id = priv_id;
2366         }
2367
2368         if (noti == NULL) {
2369                 caller_pkgname = _notification_get_pkgname_by_pid();
2370         } else {
2371                 caller_pkgname = strdup(noti->caller_pkgname);
2372         }
2373
2374         if (size < 0.0) {
2375                 input_size = 0.0;
2376         } else {
2377                 input_size = size;
2378         }
2379
2380         notification_ongoing_update_size(caller_pkgname, input_priv_id,
2381                                          input_size);
2382
2383         if (caller_pkgname) {
2384                 free(caller_pkgname);
2385         }
2386
2387         return NOTIFICATION_ERROR_NONE;
2388 }
2389
2390 EXPORT_API notification_h notification_new(notification_type_e type,
2391                                            int group_id, int priv_id)
2392 {
2393         notification_h noti = NULL;
2394
2395         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2396                 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2397                 return NULL;
2398         }
2399
2400         if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2401                 NOTIFICATION_ERR("INVALID GROUP ID : %d", group_id);
2402                 return NULL;
2403         }
2404
2405         if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2406                 NOTIFICATION_ERR("INVALID PRIV ID : %d", priv_id);
2407                 return NULL;
2408         }
2409
2410         noti = (notification_h) malloc(sizeof(struct _notification));
2411         if (noti == NULL) {
2412                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2413                 return NULL;
2414         }
2415         memset(noti, 0x00, sizeof(struct _notification));
2416
2417         noti->type = type;
2418
2419         noti->group_id = group_id;
2420         noti->internal_group_id = 0;
2421         noti->priv_id = priv_id;
2422
2423         noti->caller_pkgname = _notification_get_pkgname_by_pid();
2424         noti->launch_pkgname = NULL;
2425         noti->args = NULL;
2426         noti->group_args = NULL;
2427
2428         noti->b_execute_option = NULL;
2429         noti->b_service_responding = NULL;
2430         noti->b_service_single_launch = NULL;
2431         noti->b_service_multi_launch = NULL;
2432
2433         noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2434         noti->sound_path = NULL;
2435
2436         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2437         noti->vibration_path = NULL;
2438
2439         noti->domain = NULL;
2440         noti->dir = NULL;
2441
2442         noti->b_text = NULL;
2443         noti->b_key = NULL;
2444         noti->b_format_args = NULL;
2445         noti->num_format_args = 0;
2446
2447         noti->b_image_path = NULL;
2448
2449         noti->time = 0;
2450         noti->insert_time = 0;
2451
2452         noti->flags_for_property = 0;
2453         noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2454
2455         noti->progress_size = 0.0;
2456         noti->progress_percentage = 0.0;
2457
2458         noti->app_icon_path = NULL;
2459         noti->app_name = NULL;
2460         noti->temp_title = NULL;
2461         noti->temp_content = NULL;
2462
2463         return noti;
2464 }
2465
2466 EXPORT_API notification_error_e notification_free(notification_h noti)
2467 {
2468         if (noti == NULL) {
2469                 return NOTIFICATION_ERROR_INVALID_DATA;
2470         }
2471
2472         if (noti->caller_pkgname) {
2473                 free(noti->caller_pkgname);
2474         }
2475         if (noti->launch_pkgname) {
2476                 free(noti->launch_pkgname);
2477         }
2478         if (noti->args) {
2479                 bundle_free(noti->args);
2480         }
2481         if (noti->group_args) {
2482                 bundle_free(noti->group_args);
2483         }
2484
2485         if (noti->b_execute_option) {
2486                 bundle_free(noti->b_execute_option);
2487         }
2488         if (noti->b_service_responding) {
2489                 bundle_free(noti->b_service_responding);
2490         }
2491         if (noti->b_service_single_launch) {
2492                 bundle_free(noti->b_service_single_launch);
2493         }
2494         if (noti->b_service_multi_launch) {
2495                 bundle_free(noti->b_service_multi_launch);
2496         }
2497
2498         if (noti->sound_path) {
2499                 free(noti->sound_path);
2500         }
2501         if (noti->vibration_path) {
2502                 free(noti->vibration_path);
2503         }
2504
2505         if (noti->domain) {
2506                 free(noti->domain);
2507         }
2508         if (noti->dir) {
2509                 free(noti->dir);
2510         }
2511
2512         if (noti->b_text) {
2513                 bundle_free(noti->b_text);
2514         }
2515         if (noti->b_key) {
2516                 bundle_free(noti->b_key);
2517         }
2518         if (noti->b_format_args) {
2519                 bundle_free(noti->b_format_args);
2520         }
2521
2522         if (noti->b_image_path) {
2523                 bundle_free(noti->b_image_path);
2524         }
2525
2526         if (noti->app_icon_path) {
2527                 free(noti->app_icon_path);
2528         }
2529         if (noti->app_name) {
2530                 free(noti->app_name);
2531         }
2532         if (noti->temp_title) {
2533                 free(noti->temp_title);
2534         }
2535         if (noti->temp_content) {
2536                 free(noti->temp_content);
2537         }
2538
2539         free(noti);
2540
2541         return NOTIFICATION_ERROR_NONE;
2542 }
2543
2544 EXPORT_API notification_error_e
2545 notification_resister_changed_cb(void (*changed_cb)
2546                                  (void *data, notification_type_e type),
2547                                  void *user_data)
2548 {
2549         notification_cb_list_s *noti_cb_list_new = NULL;
2550         notification_cb_list_s *noti_cb_list = NULL;
2551
2552         noti_cb_list_new =
2553             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2554
2555         noti_cb_list_new->next = NULL;
2556         noti_cb_list_new->prev = NULL;
2557
2558         noti_cb_list_new->changed_cb = changed_cb;
2559         noti_cb_list_new->data = user_data;
2560
2561         if (g_notification_cb_list == NULL) {
2562                 g_notification_cb_list = noti_cb_list_new;
2563         } else {
2564                 noti_cb_list = g_notification_cb_list;
2565
2566                 while (noti_cb_list->next != NULL) {
2567                         noti_cb_list = noti_cb_list->next;
2568                 }
2569
2570                 noti_cb_list->next = noti_cb_list_new;
2571                 noti_cb_list_new->prev = noti_cb_list;
2572         }
2573
2574         if (g_notification_heynoti_fd < 0) {
2575                 g_notification_heynoti_fd = heynoti_init();
2576
2577                 heynoti_subscribe(g_notification_heynoti_fd, NOTI_CHANGED_NOTI,
2578                                   _notification_chagned_noti_cb, NULL);
2579
2580                 heynoti_attach_handler(g_notification_heynoti_fd);
2581         }
2582
2583         return NOTIFICATION_ERROR_NONE;
2584 }
2585
2586 EXPORT_API notification_error_e
2587 notification_unresister_changed_cb(void (*changed_cb)
2588                                    (void *data, notification_type_e type))
2589 {
2590         notification_cb_list_s *noti_cb_list = NULL;
2591         notification_cb_list_s *noti_cb_list_prev = NULL;
2592         notification_cb_list_s *noti_cb_list_next = NULL;
2593
2594         noti_cb_list = g_notification_cb_list;
2595
2596         if (noti_cb_list == NULL) {
2597                 return NOTIFICATION_ERROR_INVALID_DATA;
2598         }
2599
2600         while (noti_cb_list->prev != NULL) {
2601                 noti_cb_list = noti_cb_list->prev;
2602         }
2603
2604         do {
2605                 if (noti_cb_list->changed_cb == changed_cb) {
2606                         noti_cb_list_prev = noti_cb_list->prev;
2607                         noti_cb_list_next = noti_cb_list->next;
2608
2609                         if (noti_cb_list_prev == NULL) {
2610                                 g_notification_cb_list = noti_cb_list_next;
2611                         } else {
2612                                 noti_cb_list_prev->next = noti_cb_list_next;
2613                         }
2614
2615                         if (noti_cb_list_next == NULL) {
2616                                 if (noti_cb_list_prev != NULL) {
2617                                         noti_cb_list_prev->next = NULL;
2618                                 }
2619                         } else {
2620                                 noti_cb_list_next->prev = noti_cb_list_prev;
2621                         }
2622
2623                         free(noti_cb_list);
2624
2625                         if (g_notification_cb_list == NULL) {
2626                                 heynoti_detach_handler
2627                                     (g_notification_heynoti_fd);
2628                                 heynoti_close(g_notification_heynoti_fd);
2629                                 g_notification_heynoti_fd = -1;
2630                         }
2631
2632                         return NOTIFICATION_ERROR_NONE;
2633                 }
2634                 noti_cb_list = noti_cb_list->next;
2635         } while (noti_cb_list != NULL);
2636
2637         return NOTIFICATION_ERROR_INVALID_DATA;
2638 }
2639
2640 EXPORT_API notification_error_e
2641 notification_resister_badge_changed_cb(void (*changed_cb)
2642                                        (void *data, const char *pkgname,
2643                                         int group_id), void *user_data)
2644 {
2645         // Add DBus signal handler
2646         return NOTIFICATION_ERROR_NONE;
2647 }
2648
2649 EXPORT_API notification_error_e
2650 notification_unresister_badge_changed_cb(void (*changed_cb)
2651                                          (void *data, const char *pkgname,
2652                                           int group_id))
2653 {
2654         // Del DBus signal handler
2655         return NOTIFICATION_ERROR_NONE;
2656 }
2657
2658 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
2659                                                        const char *pkgname,
2660                                                        int group_id,
2661                                                        int priv_id, int *count)
2662 {
2663         int ret = 0;
2664         int noti_count = 0;
2665
2666         ret =
2667             notification_noti_get_count(type, pkgname, group_id, priv_id,
2668                                         &noti_count);
2669         if (ret != NOTIFICATION_ERROR_NONE) {
2670                 return ret;
2671         }
2672
2673         if (count != NULL) {
2674                 *count = noti_count;
2675         }
2676
2677         return NOTIFICATION_ERROR_NONE;
2678 }
2679
2680 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
2681                                                       int count,
2682                                                       notification_list_h *list)
2683 {
2684         notification_list_h get_list = NULL;
2685         int ret = 0;
2686
2687         ret = notification_noti_get_grouping_list(type, count, &get_list);
2688         if (ret != NOTIFICATION_ERROR_NONE) {
2689                 return ret;
2690         }
2691
2692         *list = get_list;
2693
2694         return NOTIFICATION_ERROR_NONE;
2695 }
2696
2697 EXPORT_API notification_error_e
2698 notification_get_grouping_list(notification_type_e type, int count,
2699                                notification_list_h * list)
2700 {
2701         notification_list_h get_list = NULL;
2702         int ret = 0;
2703
2704         ret = notification_noti_get_grouping_list(type, count, &get_list);
2705         if (ret != NOTIFICATION_ERROR_NONE) {
2706                 return ret;
2707         }
2708
2709         *list = get_list;
2710
2711         return NOTIFICATION_ERROR_NONE;
2712 }
2713
2714 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
2715                                                              int group_id,
2716                                                              int priv_id,
2717                                                              int count,
2718                                                              notification_list_h *list)
2719 {
2720         notification_list_h get_list = NULL;
2721         int ret = 0;
2722
2723         ret =
2724             notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2725                                               &get_list);
2726         if (ret != NOTIFICATION_ERROR_NONE) {
2727                 return ret;
2728         }
2729
2730         *list = get_list;
2731
2732         return NOTIFICATION_ERROR_NONE;
2733 }
2734
2735 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
2736 {
2737         notification_list_h cur_list = NULL;
2738         notification_h noti = NULL;
2739
2740         if (list == NULL) {
2741                 NOTIFICATION_ERR("INVALID DATA : list == NULL");
2742                 return NOTIFICATION_ERROR_INVALID_DATA;
2743         }
2744
2745         cur_list = notification_list_get_head(list);
2746
2747         while (cur_list != NULL) {
2748                 noti = notification_list_get_data(cur_list);
2749                 cur_list = notification_list_remove(cur_list, noti);
2750
2751                 notification_free(noti);
2752         }
2753
2754         return NOTIFICATION_ERROR_NONE;
2755 }