4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeonghoon Park <jh1979.park@samsung.com>, Youngjoo Park <yjoo93.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
28 #include <dbus/dbus.h>
29 #include <dbus/dbus-glib-lowlevel.h>
34 #include <vconf-keys.h>
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>
45 typedef struct _notification_cb_list notification_cb_list_s;
47 struct _notification_cb_list {
48 notification_cb_list_s *prev;
49 notification_cb_list_s *next;
51 void (*changed_cb) (void *data, notification_type_e type);
55 static notification_cb_list_s *g_notification_cb_list = NULL;
56 static DBusConnection *g_dbus_handle;
58 #define NOTI_PKGNAME_LEN 512
59 #define NOTI_CHANGED_NOTI "notification_noti_changed"
60 #define NOTI_CHANGED_ONGOING "notification_ontoing_changed"
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"
66 static char *_notification_get_pkgname_by_pid(void)
68 char buf[NOTI_PKGNAME_LEN] = { 0, };
69 char pkgname[NOTI_PKGNAME_LEN] = { 0, };
70 int pid = 0, ret = AUL_R_OK;
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);
79 fd = open(buf, O_RDONLY);
84 ret = read(fd, pkgname, sizeof(pkgname) - 1);
95 if (pkgname == NULL || pkgname[0] == '\0') {
98 return strdup(pkgname);
102 static char *_notification_get_icon(const char *package)
104 ail_appinfo_h handle;
109 ret = ail_package_get_appinfo(package, &handle);
110 if (ret != AIL_ERROR_OK) {
114 ret = ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &str);
115 if (ret != AIL_ERROR_OK) {
116 ail_package_destroy_appinfo(handle);
122 ret = ail_package_destroy_appinfo(handle);
123 if (ret != AIL_ERROR_OK) {
124 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
130 static char *_notification_get_name(const char *package)
132 ail_appinfo_h handle;
137 ret = ail_package_get_appinfo(package, &handle);
138 if (ret != AIL_ERROR_OK) {
142 ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
143 if (ret != AIL_ERROR_OK) {
144 ail_package_destroy_appinfo(handle);
150 ret = ail_package_destroy_appinfo(handle);
151 if (ret != AIL_ERROR_OK) {
152 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
158 static void _notification_get_text_domain(notification_h noti)
160 if (noti->domain != NULL) {
164 if (noti->dir != NULL) {
169 static void _notification_chagned_noti_cb(void *data)
171 notification_cb_list_s *noti_cb_list = NULL;
173 if (g_notification_cb_list == NULL) {
177 noti_cb_list = g_notification_cb_list;
179 while (noti_cb_list->prev != NULL) {
180 noti_cb_list = noti_cb_list->prev;
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);
189 noti_cb_list = noti_cb_list->next;
194 static void _notification_chagned_ongoing_cb(void *data)
196 notification_cb_list_s *noti_cb_list = NULL;
198 if (g_notification_cb_list == NULL) {
202 noti_cb_list = g_notification_cb_list;
204 while (noti_cb_list->prev != NULL) {
205 noti_cb_list = noti_cb_list->prev;
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);
214 noti_cb_list = noti_cb_list->next;
219 static void _notification_changed(const char *type)
221 DBusConnection *connection = NULL;
222 DBusMessage *message = NULL;
227 NOTIFICATION_ERR("type is NULL");
231 dbus_error_init(&err);
232 connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
234 NOTIFICATION_ERR("Fail to dbus_bus_get : %s", err.message);
238 message = dbus_message_new_signal(NOTI_DBUS_PATH,
243 NOTIFICATION_ERR("fail to create dbus message");
244 goto release_n_return;
247 ret = dbus_connection_send(connection, message, NULL);
249 NOTIFICATION_ERR("fail to send dbus message : %s", type);
250 goto release_n_return;
253 dbus_connection_flush(connection);
255 NOTIFICATION_DBG("success to emit signal [%s]", type);
258 dbus_error_free(&err);
261 dbus_message_unref(message);
264 dbus_connection_unref(connection);
267 static DBusHandlerResult _dbus_signal_filter(DBusConnection *conn,
268 DBusMessage *msg, void *user_data)
270 const char *interface = NULL;
272 interface = dbus_message_get_interface(msg);
273 NOTIFICATION_DBG("path : %s", dbus_message_get_path(msg));
274 NOTIFICATION_DBG("interface : %s", interface);
276 if (strcmp(NOTI_DBUS_INTERFACE, interface))
277 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
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;
287 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
290 static DBusConnection *_noti_changed_monitor_init()
293 DBusConnection *conn = NULL;
296 dbus_error_init(&err);
297 conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
299 printf("fail to get bus\n");
302 dbus_connection_setup_with_g_main(conn, NULL);
304 "path='%s',type='signal',interface='%s',member='%s'",
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);
317 dbus_connection_set_exit_on_disconnect(conn, FALSE);
321 static void _noti_chanaged_monitor_fini()
323 DBusConnection *conn = g_dbus_handle;
328 dbus_connection_remove_filter(conn, _dbus_signal_filter, NULL);
331 "path='%s',type='signal',interface='%s',member='%s'",
335 dbus_bus_remove_match(conn, rule, NULL);
337 dbus_connection_close(conn);
338 g_dbus_handle = NULL;
341 /* notification_set_icon will be removed */
342 EXPORT_API notification_error_e notification_set_icon(notification_h noti,
343 const char *icon_path)
345 int ret_err = NOTIFICATION_ERROR_NONE;
348 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
354 /* notification_get_icon will be removed */
355 EXPORT_API notification_error_e notification_get_icon(notification_h noti,
358 int ret_err = NOTIFICATION_ERROR_NONE;
359 char *ret_image_path = NULL;
362 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
365 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
366 *icon_path = ret_image_path;
368 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
374 EXPORT_API notification_error_e notification_set_image(notification_h noti,
375 notification_image_type_e type,
376 const char *image_path)
379 char buf_key[32] = { 0, };
380 const char *ret_val = NULL;
382 /* Check noti and image_path are valid data */
383 if (noti == NULL || image_path == NULL) {
384 return NOTIFICATION_ERROR_INVALID_DATA;
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;
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;
398 /* Set image type to key as char string type */
399 snprintf(buf_key, sizeof(buf_key), "%d", type);
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);
408 /* Add new image path with type key */
409 bundle_add(b, buf_key, image_path);
411 /* If image path bundle is not exist, create new one */
414 /* Set image type to key as char string type */
415 snprintf(buf_key, sizeof(buf_key), "%d", type);
417 /* Add new image path with type key */
418 bundle_add(b, buf_key, image_path);
420 /* Save to image path bundle */
421 noti->b_image_path = b;
424 return NOTIFICATION_ERROR_NONE;
427 EXPORT_API notification_error_e notification_get_image(notification_h noti,
428 notification_image_type_e type,
432 char buf_key[32] = { 0, };
433 const char *ret_val = NULL;
434 const char *pkgname = NULL;
436 /* Check noti and image_path is valid data */
437 if (noti == NULL || image_path == NULL) {
438 return NOTIFICATION_ERROR_INVALID_DATA;
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;
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;
452 /* Set image type to key as char string type */
453 snprintf(buf_key, sizeof(buf_key), "%d", type);
455 /* Get value of key */
456 ret_val = bundle_get_val(b, buf_key);
458 *image_path = (char *)ret_val;
460 /* If image path bundle does not exist, image path is NULL */
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;
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);
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);
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) {
489 appsvc_get_pkgname(noti->b_service_single_launch);
490 if (pkgname != NULL) {
491 noti->app_icon_path =
492 _notification_get_icon(pkgname);
496 *image_path = noti->app_icon_path;
500 return NOTIFICATION_ERROR_NONE;
503 EXPORT_API notification_error_e notification_set_time(notification_h noti,
506 /* Check noti is valid data */
508 return NOTIFICATION_ERROR_INVALID_DATA;
511 if (input_time == 0) {
512 /* If input time is 0, set current time */
513 noti->time = time(NULL);
515 /* save input time */
516 noti->time = input_time;
519 return NOTIFICATION_ERROR_NONE;
522 EXPORT_API notification_error_e notification_get_time(notification_h noti,
525 /* Check noti and time is valid data */
526 if (noti == NULL || ret_time == NULL) {
527 return NOTIFICATION_ERROR_INVALID_DATA;
530 /* Set time infomation */
531 *ret_time = noti->time;
533 return NOTIFICATION_ERROR_NONE;
536 EXPORT_API notification_error_e notification_get_insert_time(notification_h noti,
539 /* Check noti and ret_time is valid data */
540 if (noti == NULL || ret_time == NULL) {
541 return NOTIFICATION_ERROR_INVALID_DATA;
544 /* Set insert time information */
545 *ret_time = noti->insert_time;
547 return NOTIFICATION_ERROR_NONE;
550 EXPORT_API notification_error_e notification_set_title(notification_h noti,
552 const char *loc_title)
554 int noti_err = NOTIFICATION_ERROR_NONE;
556 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
558 NOTIFICATION_VARIABLE_TYPE_NONE);
563 EXPORT_API notification_error_e notification_get_title(notification_h noti,
567 int noti_err = NOTIFICATION_ERROR_NONE;
568 char *ret_text = NULL;
571 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
578 if (loc_title != NULL) {
585 EXPORT_API notification_error_e notification_set_content(notification_h noti,
587 const char *loc_content)
589 int noti_err = NOTIFICATION_ERROR_NONE;
591 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
592 content, loc_content,
593 NOTIFICATION_VARIABLE_TYPE_NONE);
598 EXPORT_API notification_error_e notification_get_content(notification_h noti,
602 int noti_err = NOTIFICATION_ERROR_NONE;
603 char *ret_text = NULL;
606 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
609 if (content != NULL) {
613 if (loc_content != NULL) {
622 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
624 if (ret == -1 || boolval == 0) {
625 if (content != NULL && noti->default_content != NULL) {
626 *content = noti->default_content;
629 if (loc_content != NULL && noti->loc_default_content != NULL) {
630 *loc_content = noti->loc_default_content;
636 EXPORT_API notification_error_e notification_set_text(notification_h noti,
637 notification_text_type_e type,
643 char buf_key[32] = { 0, };
644 char buf_val[1024] = { 0, };
645 const char *ret_val = NULL;
647 notification_variable_type_e var_type;
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;
656 /* Check noti is valid data */
658 return NOTIFICATION_ERROR_INVALID_DATA;
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;
667 /* Check text bundle exist */
669 if (noti->b_text != NULL) {
670 /* If text bundle exist, store local bundle data */
673 /* Make type to key as char string */
674 snprintf(buf_key, sizeof(buf_key), "%d", type);
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);
683 snprintf(buf_val, sizeof(buf_val), "%s", text);
685 /* Add new text value */
686 bundle_add(b, buf_key, buf_val);
688 /* If text bundle does not exist, create new one */
691 /* Make type to key as char string */
692 snprintf(buf_key, sizeof(buf_key), "%d", type);
694 snprintf(buf_val, sizeof(buf_val), "%s", text);
696 /* Add new text value */
697 bundle_add(b, buf_key, buf_val);
699 /* Save text bundle */
703 /* Reset if text is NULL */
704 if (noti->b_text != NULL) {
705 /* If text bundle exist, store local bundle data */
708 /* Make type to key as char string */
709 snprintf(buf_key, sizeof(buf_key), "%d", type);
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);
720 /* Save key if key is valid data */
722 /* Check key bundle exist */
723 if (noti->b_key != NULL) {
724 /* If key bundle exist, store local bundle data */
727 /* Make type to key as char string */
728 snprintf(buf_key, sizeof(buf_key), "%d", type);
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);
737 snprintf(buf_val, sizeof(buf_val), "%s", key);
739 /* Add new key value */
740 bundle_add(b, buf_key, buf_val);
742 /* If key bundle does not exist, create new one */
745 /* Make type to key as char string */
746 snprintf(buf_key, sizeof(buf_key), "%d", type);
748 snprintf(buf_val, sizeof(buf_val), "%s", key);
750 /* Add new key value */
751 bundle_add(b, buf_key, buf_val);
753 /* Save key bundle */
757 /* Reset if key is NULL */
758 if (noti->b_key != NULL) {
759 /* If key bundle exist, store local bundle data */
762 /* Make type to key as char string */
763 snprintf(buf_key, sizeof(buf_key), "%d", type);
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);
774 if (noti->b_format_args != NULL) {
775 b = noti->b_format_args;
780 va_start(var_args, args_type);
782 var_type = args_type;
785 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
787 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
788 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
790 ret_val = bundle_get_val(b, buf_key);
791 if (ret_val != NULL) {
792 bundle_del(b, buf_key);
795 bundle_add(b, buf_key, buf_val);
798 case NOTIFICATION_VARIABLE_TYPE_INT:
799 var_value_int = va_arg(var_args, int);
802 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
804 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
806 ret_val = bundle_get_val(b, buf_key);
807 if (ret_val != NULL) {
808 bundle_del(b, buf_key);
811 bundle_add(b, buf_key, buf_val);
813 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
814 var_value_double = va_arg(var_args, double);
817 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
819 snprintf(buf_val, sizeof(buf_val), "%.2f",
822 ret_val = bundle_get_val(b, buf_key);
823 if (ret_val != NULL) {
824 bundle_del(b, buf_key);
827 bundle_add(b, buf_key, buf_val);
829 case NOTIFICATION_VARIABLE_TYPE_STRING:
830 var_value_string = va_arg(var_args, char *);
833 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
835 snprintf(buf_val, sizeof(buf_val), "%s",
838 ret_val = bundle_get_val(b, buf_key);
839 if (ret_val != NULL) {
840 bundle_del(b, buf_key);
843 bundle_add(b, buf_key, buf_val);
845 case NOTIFICATION_VARIABLE_TYPE_COUNT:
847 va_arg(var_args, notification_count_pos_type_e);
850 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
852 snprintf(buf_val, sizeof(buf_val), "%d",
855 ret_val = bundle_get_val(b, buf_key);
856 if (ret_val != NULL) {
857 bundle_del(b, buf_key);
860 bundle_add(b, buf_key, buf_val);
863 NOTIFICATION_ERR("Error. invalid variable type. : %d",
865 noti_err = NOTIFICATION_ERROR_INVALID_DATA;
870 var_type = va_arg(var_args, notification_variable_type_e);
874 if (noti_err == NOTIFICATION_ERROR_NONE) {
875 noti->num_format_args = num_args;
877 noti->num_format_args = 0;
880 snprintf(buf_key, sizeof(buf_key), "num%d", type);
881 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
883 ret_val = bundle_get_val(b, buf_key);
884 if (ret_val != NULL) {
885 bundle_del(b, buf_key);
888 bundle_add(b, buf_key, buf_val);
890 noti->b_format_args = b;
895 EXPORT_API notification_error_e notification_get_text(notification_h noti,
896 notification_text_type_e type,
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;
907 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
908 int display_option_flag = 0;
910 char *temp_str = NULL;
911 char result_str[1024] = { 0, };
912 char buf_str[1024] = { 0, };
914 notification_variable_type_e ret_var_type = 0;
915 int ret_variable_int = 0;
916 double ret_variable_double = 0.0;
918 /* Check noti is valid data */
919 if (noti == NULL || text == NULL) {
920 return NOTIFICATION_ERROR_INVALID_DATA;
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;
929 /* Check content display option of setting */
930 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
931 || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
934 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL,
936 if (ret == -1 || boolval == 0) {
937 /* Set flag as display option is OFF */
938 //display_option_flag = 1;
943 if (noti->b_key != NULL) {
946 /* Get text domain and dir */
947 _notification_get_text_domain(noti);
949 snprintf(buf_key, sizeof(buf_key), "%d", type);
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);
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);
966 if (get_str == NULL && noti->b_text != NULL) {
969 snprintf(buf_key, sizeof(buf_key), "%d", type);
971 get_str = bundle_get_val(b, buf_key);
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) {
984 NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
985 } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
987 NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
991 if (noti->b_key != NULL) {
994 /* Get text domain and dir */
995 _notification_get_text_domain(noti);
997 snprintf(buf_key, sizeof(buf_key), "%d",
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);
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);
1013 get_check_type_str = NULL;
1017 if (get_check_type_str == NULL && noti->b_text != NULL) {
1019 /* Get basic text */
1020 snprintf(buf_key, sizeof(buf_key), "%d",
1023 get_check_type_str = bundle_get_val(b, buf_key);
1027 if (get_check_type_str != NULL) {
1028 /* Replace option off type string */
1029 get_str = get_check_type_str;
1031 /* Set default string */
1033 dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
1037 if (get_str != NULL) {
1038 /* Get number format args */
1039 b = noti->b_format_args;
1040 noti->num_format_args = 0;
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);
1050 if (noti->num_format_args == 0) {
1051 *text = (char *)get_str;
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);
1059 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
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);
1066 if (ret_variable_int ==
1067 NOTIFICATION_COUNT_POS_LEFT) {
1068 notification_noti_get_count(noti->type,
1069 noti->caller_pkgname,
1073 snprintf(buf_str, sizeof(buf_str),
1074 "%d ", ret_variable_int);
1075 strncat(result_str, buf_str,
1076 sizeof(result_str));
1083 /* Check variable IN pos */
1084 for (temp_str = (char *)get_str; *temp_str != '\0';
1086 if (*temp_str != '%') {
1087 strncat(result_str, temp_str, 1);
1089 if (*(temp_str + 1) == '%') {
1090 strncat(result_str, temp_str,
1092 } else if (*(temp_str + 1) == 'd') {
1094 ret_variable_int = 0;
1098 "%dtype%d", check_type,
1101 bundle_get_val(b, buf_key);
1102 ret_var_type = atoi(ret_val);
1104 NOTIFICATION_VARIABLE_TYPE_COUNT)
1106 /* Get notification count */
1107 notification_noti_get_count
1109 noti->caller_pkgname,
1129 sizeof(buf_str), "%d",
1131 strncat(result_str, buf_str,
1132 sizeof(result_str));
1137 } else if (*(temp_str + 1) == 's') {
1142 check_type, num_args);
1144 bundle_get_val(b, buf_key);
1147 sizeof(buf_str), "%s",
1149 strncat(result_str, buf_str,
1150 sizeof(result_str));
1155 } else if (*(temp_str + 1) == 'f') {
1160 check_type, num_args);
1162 bundle_get_val(b, buf_key);
1163 ret_variable_double =
1169 ret_variable_double);
1170 strncat(result_str, buf_str,
1171 sizeof(result_str));
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);
1188 NOTIFICATION_VARIABLE_TYPE_COUNT) {
1190 snprintf(buf_key, sizeof(buf_key),
1191 "%dvalue%d", check_type,
1193 ret_val = bundle_get_val(b, buf_key);
1194 ret_variable_int = atoi(ret_val);
1196 if (ret_variable_int ==
1197 NOTIFICATION_COUNT_POS_RIGHT) {
1198 notification_noti_get_count
1200 noti->caller_pkgname,
1205 sizeof(buf_str), " %d",
1207 strncat(result_str, buf_str,
1208 sizeof(result_str));
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);
1222 noti->temp_title = strdup(result_str);
1224 *text = noti->temp_title;
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 !=
1232 free(noti->temp_content);
1234 noti->temp_content = strdup(result_str);
1236 *text = noti->temp_content;
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;
1253 /* First, get app name from launch_pkgname */
1254 if (noti->launch_pkgname != NULL) {
1256 _notification_get_name(noti->
1260 /* Second, get app name from caller_pkgname */
1261 if (noti->app_name == NULL
1262 && noti->caller_pkgname != NULL) {
1264 _notification_get_name(noti->
1268 /* Third, get app name from service data */
1269 if (noti->app_name == NULL
1270 && noti->b_service_single_launch != NULL) {
1272 appsvc_get_pkgname(noti->
1273 b_service_single_launch);
1275 if (pkgname != NULL) {
1277 _notification_get_name(pkgname);
1281 *text = noti->app_name;
1287 NOTIFICATION_INFO("Get text : %s", *text);
1289 return NOTIFICATION_ERROR_NONE;
1292 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
1296 /* check noti and domain is valid data */
1297 if (noti == NULL || domain == NULL) {
1298 return NOTIFICATION_ERROR_INVALID_DATA;
1303 /* Remove previous domain */
1307 noti->domain = strdup(domain);
1309 /* Check locale dir */
1311 /* Remove previous locale dir */
1314 /* Copy locale dir */
1315 noti->dir = strdup(dir);
1317 return NOTIFICATION_ERROR_NONE;
1320 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
1324 /* Check noti is valid data */
1326 return NOTIFICATION_ERROR_INVALID_DATA;
1330 if (domain != NULL && noti->domain != NULL) {
1331 *domain = noti->domain;
1334 /* Get locale dir */
1335 if (dir != NULL && noti->dir != NULL) {
1339 return NOTIFICATION_ERROR_NONE;
1342 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1343 notification_sound_type_e type,
1346 /* Check noti is valid data */
1348 return NOTIFICATION_ERROR_INVALID_DATA;
1351 /* Check type is valid */
1352 if (type < NOTIFICATION_SOUND_TYPE_NONE
1353 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1354 return NOTIFICATION_ERROR_INVALID_DATA;
1357 /* Save sound type */
1358 noti->sound_type = type;
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);
1366 noti->sound_path = strdup(path);
1368 if (noti->sound_path != NULL) {
1369 free(noti->sound_path);
1370 noti->sound_path = NULL;
1374 return NOTIFICATION_ERROR_NONE;
1377 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1378 notification_sound_type_e *type,
1381 /* check noti and type is valid data */
1382 if (noti == NULL || type == NULL) {
1383 return NOTIFICATION_ERROR_INVALID_DATA;
1386 /* Set sound type */
1387 *type = noti->sound_type;
1389 /* Set sound path if user data type */
1390 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1392 *path = noti->sound_path;
1395 return NOTIFICATION_ERROR_NONE;
1398 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1399 notification_vibration_type_e type,
1402 /* Check noti is valid data */
1404 return NOTIFICATION_ERROR_INVALID_DATA;
1407 /* Check type is valid */
1408 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1409 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1410 return NOTIFICATION_ERROR_INVALID_DATA;
1413 /* Save vibration type */
1414 noti->vibration_type = type;
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);
1422 noti->vibration_path = strdup(path);
1424 if (noti->vibration_path != NULL) {
1425 free(noti->vibration_path);
1426 noti->vibration_path = NULL;
1430 return NOTIFICATION_ERROR_NONE;
1434 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1435 notification_vibration_type_e *type,
1438 /* check noti and type is valid data */
1439 if (noti == NULL || type == NULL) {
1440 return NOTIFICATION_ERROR_INVALID_DATA;
1443 /* Set vibration type */
1444 *type = noti->vibration_type;
1446 /* Set sound path if user data type */
1447 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1449 *path = noti->vibration_path;
1452 return NOTIFICATION_ERROR_NONE;
1455 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1456 const char *pkgname)
1458 if (noti == NULL || pkgname == NULL) {
1459 return NOTIFICATION_ERROR_INVALID_DATA;
1462 if (noti->launch_pkgname) {
1463 free(noti->launch_pkgname);
1466 noti->launch_pkgname = strdup(pkgname);
1468 return NOTIFICATION_ERROR_NONE;
1471 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1474 if (noti == NULL || pkgname == NULL) {
1475 return NOTIFICATION_ERROR_INVALID_DATA;
1478 if (noti->launch_pkgname) {
1479 *pkgname = noti->launch_pkgname;
1481 *pkgname = noti->caller_pkgname;
1484 return NOTIFICATION_ERROR_NONE;
1487 EXPORT_API notification_error_e notification_set_args(notification_h noti,
1489 bundle * group_args)
1491 if (noti == NULL || args == NULL) {
1492 return NOTIFICATION_ERROR_INVALID_DATA;
1496 bundle_free(noti->args);
1499 noti->args = bundle_dup(args);
1501 if (noti->group_args) {
1502 bundle_free(noti->group_args);
1503 noti->group_args = NULL;
1506 if (group_args != NULL) {
1507 noti->group_args = bundle_dup(group_args);
1510 return NOTIFICATION_ERROR_NONE;
1513 EXPORT_API notification_error_e notification_get_args(notification_h noti,
1515 bundle ** group_args)
1517 if (noti == NULL || args == NULL) {
1518 return NOTIFICATION_ERROR_INVALID_DATA;
1527 if (group_args != NULL && noti->group_args) {
1528 *group_args = noti->group_args;
1531 return NOTIFICATION_ERROR_NONE;
1534 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1535 notification_execute_type_e type,
1538 bundle *service_handle)
1540 char buf_key[32] = { 0, };
1541 const char *ret_val = NULL;
1545 return NOTIFICATION_ERROR_INVALID_DATA;
1548 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1549 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1550 return NOTIFICATION_ERROR_INVALID_DATA;
1553 /* Create execute option bundle if does not exist */
1554 if (noti->b_execute_option != NULL) {
1555 noti->b_execute_option = bundle_create();
1558 b = noti->b_execute_option;
1563 snprintf(buf_key, sizeof(buf_key), "text%d", type);
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);
1573 bundle_add(b, buf_key, text);
1579 snprintf(buf_key, sizeof(buf_key), "key%d", type);
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);
1589 bundle_add(b, buf_key, key);
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;
1600 /* Save service handle */
1601 if (service_handle != NULL) {
1602 noti->b_service_responding = bundle_dup(service_handle);
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;
1612 /* Save service handle */
1613 if (service_handle != NULL) {
1614 noti->b_service_single_launch =
1615 bundle_dup(service_handle);
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;
1625 /* Save service handle */
1626 if (service_handle != NULL) {
1627 noti->b_service_multi_launch =
1628 bundle_dup(service_handle);
1635 return NOTIFICATION_ERROR_NONE;
1638 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1639 notification_execute_type_e type,
1641 bundle **service_handle)
1643 char buf_key[32] = { 0, };
1644 const char *ret_val = NULL;
1645 char *get_str = NULL;
1649 return NOTIFICATION_ERROR_INVALID_DATA;
1652 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1653 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1654 return NOTIFICATION_ERROR_INVALID_DATA;
1658 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1659 b = noti->b_service_responding;
1661 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1662 b = noti->b_service_single_launch;
1664 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1665 b = noti->b_service_multi_launch;
1675 // Get text domain and dir
1676 if (noti->domain == NULL || noti->dir == NULL) {
1677 _notification_get_text_domain(noti);
1681 snprintf(buf_key, sizeof(buf_key), "key%d", type);
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);
1690 get_str = dgettext(noti->domain, ret_val);
1693 } else if (ret_val != NULL) {
1694 /* Get system string */
1695 get_str = dgettext("sys_string", ret_val);
1699 /* Get basic text */
1700 snprintf(buf_key, sizeof(buf_key), "text%d",
1703 ret_val = bundle_get_val(b, buf_key);
1711 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1712 b = noti->b_service_responding;
1714 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1715 b = noti->b_service_single_launch;
1717 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1718 b = noti->b_service_multi_launch;
1725 if (service_handle != NULL) {
1726 *service_handle = b;
1729 return NOTIFICATION_ERROR_NONE;
1732 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1735 /* Check noti is valid data */
1737 return NOTIFICATION_ERROR_INVALID_DATA;
1741 noti->flags_for_property = flags;
1743 return NOTIFICATION_ERROR_NONE;
1746 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1749 /* Check noti and flags are valid data */
1750 if (noti == NULL || flags == NULL) {
1751 return NOTIFICATION_ERROR_INVALID_DATA;
1755 *flags = noti->flags_for_property;
1757 return NOTIFICATION_ERROR_NONE;
1760 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1763 /* Check noti is valid data */
1765 return NOTIFICATION_ERROR_INVALID_DATA;
1769 noti->display_applist = applist;
1771 return NOTIFICATION_ERROR_NONE;
1774 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1777 /* Check noti and applist are valid data */
1778 if (noti == NULL || applist == NULL) {
1779 return NOTIFICATION_ERROR_INVALID_DATA;
1783 *applist = noti->display_applist;
1785 return NOTIFICATION_ERROR_NONE;
1788 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1791 /* Check noti is valid data */
1793 return NOTIFICATION_ERROR_INVALID_DATA;
1796 /* Save progress size */
1797 noti->progress_size = size;
1799 return NOTIFICATION_ERROR_NONE;
1802 EXPORT_API notification_error_e notification_get_size(notification_h noti,
1805 /* Check noti and size is valid data */
1806 if (noti == NULL || size == NULL) {
1807 return NOTIFICATION_ERROR_INVALID_DATA;
1810 /* Set progress size */
1811 *size = noti->progress_size;
1813 return NOTIFICATION_ERROR_NONE;
1816 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
1819 /* Check noti is valid data */
1821 return NOTIFICATION_ERROR_INVALID_DATA;
1824 /* Save progress percentage */
1825 noti->progress_percentage = percentage;
1827 return NOTIFICATION_ERROR_NONE;
1830 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
1833 /* Check noti and percentage are valid data */
1834 if (noti == NULL || percentage == NULL) {
1835 return NOTIFICATION_ERROR_INVALID_DATA;
1838 /* Set progress percentage */
1839 *percentage = noti->progress_percentage;
1841 return NOTIFICATION_ERROR_NONE;
1844 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
1845 const char *pkgname)
1847 /* check noti and pkgname are valid data */
1848 if (noti == NULL || pkgname == NULL) {
1849 return NOTIFICATION_ERROR_INVALID_DATA;
1852 /* Remove previous caller pkgname */
1853 if (noti->caller_pkgname) {
1854 free(noti->caller_pkgname);
1855 noti->caller_pkgname = NULL;
1858 noti->caller_pkgname = strdup(pkgname);
1860 return NOTIFICATION_ERROR_NONE;
1863 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
1866 /* Check noti and pkgname are valid data */
1867 if (noti == NULL || pkgname == NULL) {
1868 return NOTIFICATION_ERROR_INVALID_DATA;
1871 /* Get caller pkgname */
1872 if (noti->caller_pkgname) {
1873 *pkgname = noti->caller_pkgname;
1878 return NOTIFICATION_ERROR_NONE;
1881 EXPORT_API notification_error_e notification_set_badge(const char *pkgname,
1882 int group_id, int count)
1884 char *caller_pkgname = NULL;
1885 int ret = NOTIFICATION_ERROR_NONE;
1887 /* Check count is valid count */
1889 return NOTIFICATION_ERROR_INVALID_DATA;
1893 if (pkgname == NULL) {
1894 caller_pkgname = _notification_get_pkgname_by_pid();
1896 /* Set count into Group DB */
1898 notification_group_set_badge(caller_pkgname, group_id,
1901 if (caller_pkgname != NULL) {
1902 free(caller_pkgname);
1905 /* Set count into Group DB */
1906 ret = notification_group_set_badge(pkgname, group_id, count);
1912 EXPORT_API notification_error_e notification_get_badge(const char *pkgname,
1913 int group_id, int *count)
1915 char *caller_pkgname = NULL;
1916 int ret = NOTIFICATION_ERROR_NONE;
1917 int ret_unread_count = 0;
1920 if (pkgname == NULL) {
1921 caller_pkgname = _notification_get_pkgname_by_pid();
1923 /* Get count from Group DB */
1925 notification_group_get_badge(caller_pkgname, group_id,
1928 if (caller_pkgname != NULL) {
1929 free(caller_pkgname);
1932 /* Get count from Group DB */
1934 notification_group_get_badge(pkgname, group_id,
1938 if (ret != NOTIFICATION_ERROR_NONE) {
1943 if (count != NULL) {
1944 *count = ret_unread_count;
1947 return NOTIFICATION_ERROR_NONE;
1950 EXPORT_API notification_error_e notification_get_id(notification_h noti,
1951 int *group_id, int *priv_id)
1953 /* check noti is valid data */
1955 return NOTIFICATION_ERROR_INVALID_DATA;
1958 /* Check group_id is valid data */
1961 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1962 *group_id = NOTIFICATION_GROUP_ID_NONE;
1964 *group_id = noti->group_id;
1968 /* Check priv_id is valid data */
1971 *priv_id = noti->priv_id;
1974 return NOTIFICATION_ERROR_NONE;
1977 EXPORT_API notification_error_e notification_get_type(notification_h noti,
1978 notification_type_e *type)
1980 /* Check noti and type is valid data */
1981 if (noti == NULL || type == NULL) {
1982 return NOTIFICATION_ERROR_INVALID_DATA;
1988 return NOTIFICATION_ERROR_NONE;
1991 EXPORT_API notification_error_e notification_insert(notification_h noti,
1996 /* Check noti is vaild data */
1998 return NOTIFICATION_ERROR_INVALID_DATA;
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;
2007 /* Save insert time */
2008 noti->insert_time = time(NULL);
2010 /* Insert into DB */
2011 ret = notification_noti_insert(noti);
2012 if (ret != NOTIFICATION_ERROR_NONE) {
2016 /* Check disable update on insert property */
2017 if (noti->flags_for_property
2018 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
2019 /* Disable changed cb */
2021 /* Enable changed cb */
2022 _notification_changed(NOTI_CHANGED_NOTI);
2025 /* If priv_id is valid data, set priv_id */
2026 if (priv_id != NULL) {
2027 *priv_id = noti->priv_id;
2030 return NOTIFICATION_ERROR_NONE;
2033 EXPORT_API notification_error_e notification_update(notification_h noti)
2037 /* Check noti is valid data */
2039 /* Update insert time ? */
2040 noti->insert_time = time(NULL);
2042 ret = notification_noti_update(noti);
2043 if (ret != NOTIFICATION_ERROR_NONE) {
2048 /* Send changed notification */
2049 _notification_changed(NOTI_CHANGED_NOTI);
2051 return NOTIFICATION_ERROR_NONE;
2054 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
2058 /* Delete all notification of type */
2059 ret = notification_noti_delete_all(type, NULL);
2060 if (ret != NOTIFICATION_ERROR_NONE) {
2064 /* Send chagned notification */
2065 _notification_changed(NOTI_CHANGED_NOTI);
2067 return NOTIFICATION_ERROR_NONE;
2070 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
2071 notification_type_e type)
2074 char *caller_pkgname = NULL;
2076 if (pkgname == NULL) {
2077 caller_pkgname = _notification_get_pkgname_by_pid();
2079 caller_pkgname = strdup(pkgname);
2082 ret = notification_noti_delete_all(type, caller_pkgname);
2083 if (ret != NOTIFICATION_ERROR_NONE) {
2084 free(caller_pkgname);
2088 _notification_changed(NOTI_CHANGED_NOTI);
2090 free(caller_pkgname);
2095 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
2096 notification_type_e type,
2100 char *caller_pkgname = NULL;
2102 if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2103 return NOTIFICATION_ERROR_INVALID_DATA;
2106 if (pkgname == NULL) {
2107 caller_pkgname = _notification_get_pkgname_by_pid();
2109 caller_pkgname = strdup(pkgname);
2113 notification_noti_delete_group_by_group_id(caller_pkgname,
2115 if (ret != NOTIFICATION_ERROR_NONE) {
2116 free(caller_pkgname);
2120 _notification_changed(NOTI_CHANGED_NOTI);
2122 free(caller_pkgname);
2127 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2128 notification_type_e type,
2132 char *caller_pkgname = NULL;
2134 if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2135 return NOTIFICATION_ERROR_INVALID_DATA;
2138 if (pkgname == NULL) {
2139 caller_pkgname = _notification_get_pkgname_by_pid();
2141 caller_pkgname = strdup(pkgname);
2145 notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id);
2146 if (ret != NOTIFICATION_ERROR_NONE) {
2147 free(caller_pkgname);
2151 _notification_changed(NOTI_CHANGED_NOTI);
2153 free(caller_pkgname);
2158 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
2159 notification_type_e type,
2163 char *caller_pkgname = NULL;
2165 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2166 return NOTIFICATION_ERROR_INVALID_DATA;
2169 if (pkgname == NULL) {
2170 caller_pkgname = _notification_get_pkgname_by_pid();
2172 caller_pkgname = strdup(pkgname);
2175 ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id);
2176 if (ret != NOTIFICATION_ERROR_NONE) {
2177 free(caller_pkgname);
2181 _notification_changed(NOTI_CHANGED_NOTI);
2183 free(caller_pkgname);
2188 EXPORT_API notification_error_e notification_delete(notification_h noti)
2193 return NOTIFICATION_ERROR_INVALID_DATA;
2197 notification_noti_delete_by_priv_id(noti->caller_pkgname,
2199 if (ret != NOTIFICATION_ERROR_NONE) {
2203 if (noti->flags_for_property
2204 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) {
2205 NOTIFICATION_INFO("Disabled update while delete.");
2207 _notification_changed(NOTI_CHANGED_NOTI);
2210 return NOTIFICATION_ERROR_NONE;
2213 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
2217 char *caller_pkgname = NULL;
2218 int input_priv_id = 0;
2219 double input_progress = 0.0;
2221 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2223 return NOTIFICATION_ERROR_INVALID_DATA;
2225 input_priv_id = noti->priv_id;
2228 input_priv_id = priv_id;
2232 caller_pkgname = _notification_get_pkgname_by_pid();
2234 caller_pkgname = strdup(noti->caller_pkgname);
2237 if (progress < 0.0) {
2238 input_progress = 0.0;
2239 } else if (progress > 1.0) {
2240 input_progress = 1.0;
2242 input_progress = progress;
2245 notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2248 if (caller_pkgname) {
2249 free(caller_pkgname);
2252 return NOTIFICATION_ERROR_NONE;
2255 EXPORT_API notification_error_e notification_update_size(notification_h noti,
2259 char *caller_pkgname = NULL;
2260 int input_priv_id = 0;
2261 double input_size = 0.0;
2263 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2265 return NOTIFICATION_ERROR_INVALID_DATA;
2267 input_priv_id = noti->priv_id;
2270 input_priv_id = priv_id;
2274 caller_pkgname = _notification_get_pkgname_by_pid();
2276 caller_pkgname = strdup(noti->caller_pkgname);
2285 notification_ongoing_update_size(caller_pkgname, input_priv_id,
2288 if (caller_pkgname) {
2289 free(caller_pkgname);
2292 return NOTIFICATION_ERROR_NONE;
2295 EXPORT_API notification_error_e notification_update_content(notification_h noti,
2297 const char *content)
2299 char *caller_pkgname = NULL;
2300 int input_priv_id = 0;
2302 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2304 return NOTIFICATION_ERROR_INVALID_DATA;
2306 input_priv_id = noti->priv_id;
2309 input_priv_id = priv_id;
2313 caller_pkgname = _notification_get_pkgname_by_pid();
2315 caller_pkgname = strdup(noti->caller_pkgname);
2318 notification_ongoing_update_content(caller_pkgname, input_priv_id,
2321 if (caller_pkgname) {
2322 free(caller_pkgname);
2325 return NOTIFICATION_ERROR_NONE;
2328 EXPORT_API notification_h notification_new(notification_type_e type,
2329 int group_id, int priv_id)
2331 notification_h noti = NULL;
2333 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2334 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2338 if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2339 NOTIFICATION_ERR("INVALID GROUP ID : %d", group_id);
2343 if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2344 NOTIFICATION_ERR("INVALID PRIV ID : %d", priv_id);
2348 noti = (notification_h) malloc(sizeof(struct _notification));
2350 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2353 memset(noti, 0x00, sizeof(struct _notification));
2357 noti->group_id = group_id;
2358 noti->internal_group_id = 0;
2359 noti->priv_id = priv_id;
2361 noti->caller_pkgname = _notification_get_pkgname_by_pid();
2362 noti->launch_pkgname = NULL;
2364 noti->group_args = NULL;
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;
2371 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2372 noti->sound_path = NULL;
2374 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2375 noti->vibration_path = NULL;
2377 noti->domain = NULL;
2380 noti->b_text = NULL;
2382 noti->b_format_args = NULL;
2383 noti->num_format_args = 0;
2385 noti->b_image_path = NULL;
2388 noti->insert_time = 0;
2390 noti->flags_for_property = 0;
2391 noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2393 noti->progress_size = 0.0;
2394 noti->progress_percentage = 0.0;
2396 noti->app_icon_path = NULL;
2397 noti->app_name = NULL;
2398 noti->temp_title = NULL;
2399 noti->temp_content = NULL;
2404 EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone)
2406 notification_h new_noti = NULL;
2408 if (noti == NULL || clone == NULL) {
2409 NOTIFICATION_ERR("INVALID PARAMETER.");
2410 return NOTIFICATION_ERROR_INVALID_DATA;
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;
2418 memset(new_noti, 0x00, sizeof(struct _notification));
2420 new_noti->type = noti->type;
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;
2426 if(noti->caller_pkgname != NULL) {
2427 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2429 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2431 if(noti->launch_pkgname != NULL) {
2432 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2434 new_noti->launch_pkgname = NULL;
2437 if(noti->args != NULL) {
2438 new_noti->args = bundle_dup(noti->args);
2440 new_noti->args = NULL;
2442 if(noti->group_args != NULL) {
2443 new_noti->group_args = bundle_dup(noti->group_args);
2445 new_noti->group_args = NULL;
2448 if(noti->b_execute_option != NULL) {
2449 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2451 new_noti->b_execute_option = NULL;
2453 if(noti->b_service_responding != NULL) {
2454 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2456 new_noti->b_service_responding = NULL;
2458 if(noti->b_service_single_launch != NULL) {
2459 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2461 new_noti->b_service_single_launch = NULL;
2463 if(noti->b_service_multi_launch != NULL) {
2464 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2466 new_noti->b_service_multi_launch = NULL;
2469 new_noti->sound_type = noti->sound_type;
2470 if(noti->sound_path != NULL) {
2471 new_noti->sound_path = strdup(noti->sound_path);
2473 new_noti->sound_path = NULL;
2475 new_noti->vibration_type = noti->vibration_type;
2476 if(noti->vibration_path != NULL) {
2477 new_noti->vibration_path = strdup(noti->vibration_path);
2479 new_noti->vibration_path = NULL;
2482 if(noti->domain != NULL) {
2483 new_noti->domain = strdup(noti->domain);
2485 new_noti->domain = NULL;
2487 if(noti->dir != NULL) {
2488 new_noti->dir = strdup(noti->dir);
2490 new_noti->dir = NULL;
2493 if(noti->b_text != NULL) {
2494 new_noti->b_text = bundle_dup(noti->b_text);
2496 new_noti->b_text = NULL;
2498 if(noti->b_key != NULL) {
2499 new_noti->b_key = bundle_dup(noti->b_key);
2501 new_noti->b_key = NULL;
2503 if(noti->b_format_args != NULL) {
2504 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2506 new_noti->b_format_args = NULL;
2508 new_noti->num_format_args = noti->num_format_args;
2510 if(noti->b_image_path != NULL) {
2511 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2513 new_noti->b_image_path = NULL;
2516 new_noti->time = noti->time;
2517 new_noti->insert_time = noti->insert_time;
2519 new_noti->flags_for_property = noti->flags_for_property;
2520 new_noti->display_applist = noti->display_applist;
2522 new_noti->progress_size = noti->progress_size;
2523 new_noti->progress_percentage = noti->progress_percentage;
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;
2532 return NOTIFICATION_ERROR_NONE;
2536 EXPORT_API notification_error_e notification_free(notification_h noti)
2539 return NOTIFICATION_ERROR_INVALID_DATA;
2542 if (noti->caller_pkgname) {
2543 free(noti->caller_pkgname);
2545 if (noti->launch_pkgname) {
2546 free(noti->launch_pkgname);
2549 bundle_free(noti->args);
2551 if (noti->group_args) {
2552 bundle_free(noti->group_args);
2555 if (noti->b_execute_option) {
2556 bundle_free(noti->b_execute_option);
2558 if (noti->b_service_responding) {
2559 bundle_free(noti->b_service_responding);
2561 if (noti->b_service_single_launch) {
2562 bundle_free(noti->b_service_single_launch);
2564 if (noti->b_service_multi_launch) {
2565 bundle_free(noti->b_service_multi_launch);
2568 if (noti->sound_path) {
2569 free(noti->sound_path);
2571 if (noti->vibration_path) {
2572 free(noti->vibration_path);
2583 bundle_free(noti->b_text);
2586 bundle_free(noti->b_key);
2588 if (noti->b_format_args) {
2589 bundle_free(noti->b_format_args);
2592 if (noti->b_image_path) {
2593 bundle_free(noti->b_image_path);
2596 if (noti->app_icon_path) {
2597 free(noti->app_icon_path);
2599 if (noti->app_name) {
2600 free(noti->app_name);
2602 if (noti->temp_title) {
2603 free(noti->temp_title);
2605 if (noti->temp_content) {
2606 free(noti->temp_content);
2611 return NOTIFICATION_ERROR_NONE;
2614 EXPORT_API notification_error_e
2615 notification_resister_changed_cb(void (*changed_cb)
2616 (void *data, notification_type_e type),
2619 notification_cb_list_s *noti_cb_list_new = NULL;
2620 notification_cb_list_s *noti_cb_list = NULL;
2622 if (!g_dbus_handle) {
2623 g_dbus_handle = _noti_changed_monitor_init();
2625 return NOTIFICATION_ERROR_FROM_DBUS;
2629 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2631 noti_cb_list_new->next = NULL;
2632 noti_cb_list_new->prev = NULL;
2634 noti_cb_list_new->changed_cb = changed_cb;
2635 noti_cb_list_new->data = user_data;
2637 if (g_notification_cb_list == NULL) {
2638 g_notification_cb_list = noti_cb_list_new;
2640 noti_cb_list = g_notification_cb_list;
2642 while (noti_cb_list->next != NULL) {
2643 noti_cb_list = noti_cb_list->next;
2646 noti_cb_list->next = noti_cb_list_new;
2647 noti_cb_list_new->prev = noti_cb_list;
2649 return NOTIFICATION_ERROR_NONE;
2652 EXPORT_API notification_error_e
2653 notification_unresister_changed_cb(void (*changed_cb)
2654 (void *data, notification_type_e type))
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;
2660 noti_cb_list = g_notification_cb_list;
2662 if (noti_cb_list == NULL) {
2663 return NOTIFICATION_ERROR_INVALID_DATA;
2666 while (noti_cb_list->prev != NULL) {
2667 noti_cb_list = noti_cb_list->prev;
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;
2675 if (noti_cb_list_prev == NULL) {
2676 g_notification_cb_list = noti_cb_list_next;
2678 noti_cb_list_prev->next = noti_cb_list_next;
2681 if (noti_cb_list_next == NULL) {
2682 if (noti_cb_list_prev != NULL) {
2683 noti_cb_list_prev->next = NULL;
2686 noti_cb_list_next->prev = noti_cb_list_prev;
2691 if (g_notification_cb_list == NULL)
2692 _noti_chanaged_monitor_fini();
2694 return NOTIFICATION_ERROR_NONE;
2696 noti_cb_list = noti_cb_list->next;
2697 } while (noti_cb_list != NULL);
2699 return NOTIFICATION_ERROR_INVALID_DATA;
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)
2707 // Add DBus signal handler
2708 return NOTIFICATION_ERROR_NONE;
2711 EXPORT_API notification_error_e
2712 notification_unresister_badge_changed_cb(void (*changed_cb)
2713 (void *data, const char *pkgname,
2716 // Del DBus signal handler
2717 return NOTIFICATION_ERROR_NONE;
2720 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
2721 const char *pkgname,
2723 int priv_id, int *count)
2729 notification_noti_get_count(type, pkgname, group_id, priv_id,
2731 if (ret != NOTIFICATION_ERROR_NONE) {
2735 if (count != NULL) {
2736 *count = noti_count;
2739 return NOTIFICATION_ERROR_NONE;
2742 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
2744 notification_list_h *list)
2746 notification_list_h get_list = NULL;
2749 ret = notification_noti_get_grouping_list(type, count, &get_list);
2750 if (ret != NOTIFICATION_ERROR_NONE) {
2756 return NOTIFICATION_ERROR_NONE;
2759 EXPORT_API notification_error_e
2760 notification_get_grouping_list(notification_type_e type, int count,
2761 notification_list_h * list)
2763 notification_list_h get_list = NULL;
2766 ret = notification_noti_get_grouping_list(type, count, &get_list);
2767 if (ret != NOTIFICATION_ERROR_NONE) {
2773 return NOTIFICATION_ERROR_NONE;
2776 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
2780 notification_list_h *list)
2782 notification_list_h get_list = NULL;
2786 notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2788 if (ret != NOTIFICATION_ERROR_NONE) {
2794 return NOTIFICATION_ERROR_NONE;
2797 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
2799 notification_list_h cur_list = NULL;
2800 notification_h noti = NULL;
2803 NOTIFICATION_ERR("INVALID DATA : list == NULL");
2804 return NOTIFICATION_ERROR_INVALID_DATA;
2807 cur_list = notification_list_get_head(list);
2809 while (cur_list != NULL) {
2810 noti = notification_list_get_data(cur_list);
2811 cur_list = notification_list_remove(cur_list, noti);
2813 notification_free(noti);
2816 return NOTIFICATION_ERROR_NONE;