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