4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>, Youngsub Ko <ys4610.ko@samsung.com>
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;
930 if (noti->b_key != NULL) {
933 /* Get text domain and dir */
934 _notification_get_text_domain(noti);
936 snprintf(buf_key, sizeof(buf_key), "%d", type);
938 ret_val = bundle_get_val(b, buf_key);
939 if (ret_val != NULL && noti->domain != NULL
940 && noti->dir != NULL) {
941 /* Get application string */
942 bindtextdomain(noti->domain, noti->dir);
944 get_str = dgettext(noti->domain, ret_val);
945 } else if (ret_val != NULL) {
946 /* Get system string */
947 get_str = dgettext("sys_string", ret_val);
953 if (get_str == NULL && noti->b_text != NULL) {
956 snprintf(buf_key, sizeof(buf_key), "%d", type);
958 get_str = bundle_get_val(b, buf_key);
963 /* Set display option is off type when option is off, type is noti */
964 if (get_str != NULL && display_option_flag == 1
965 && noti->type == NOTIFICATION_TYPE_NOTI) {
966 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
967 || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
968 /* Set check_type to option content string */
969 if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
971 NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
972 } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
974 NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
978 if (noti->b_key != NULL) {
981 /* Get text domain and dir */
982 _notification_get_text_domain(noti);
984 snprintf(buf_key, sizeof(buf_key), "%d",
987 ret_val = bundle_get_val(b, buf_key);
988 if (ret_val != NULL && noti->domain != NULL
989 && noti->dir != NULL) {
990 /* Get application string */
991 bindtextdomain(noti->domain, noti->dir);
994 dgettext(noti->domain, ret_val);
995 } else if (ret_val != NULL) {
996 /* Get system string */
998 dgettext("sys_string", ret_val);
1000 get_check_type_str = NULL;
1004 if (get_check_type_str == NULL && noti->b_text != NULL) {
1006 /* Get basic text */
1007 snprintf(buf_key, sizeof(buf_key), "%d",
1010 get_check_type_str = bundle_get_val(b, buf_key);
1014 if (get_check_type_str != NULL) {
1015 /* Replace option off type string */
1016 get_str = get_check_type_str;
1018 /* Set default string */
1020 dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
1024 if (get_str != NULL) {
1025 /* Get number format args */
1026 b = noti->b_format_args;
1027 noti->num_format_args = 0;
1030 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
1031 ret_val = bundle_get_val(b, buf_key);
1032 if (ret_val != NULL) {
1033 noti->num_format_args = atoi(ret_val);
1037 if (noti->num_format_args == 0) {
1038 *text = (char *)get_str;
1040 /* Check first variable is count, LEFT pos */
1041 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1042 check_type, num_args);
1043 ret_val = bundle_get_val(b, buf_key);
1044 ret_var_type = atoi(ret_val);
1046 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
1048 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
1049 check_type, num_args);
1050 ret_val = bundle_get_val(b, buf_key);
1051 ret_variable_int = atoi(ret_val);
1053 if (ret_variable_int ==
1054 NOTIFICATION_COUNT_POS_LEFT) {
1055 notification_noti_get_count(noti->type,
1056 noti->caller_pkgname,
1060 snprintf(buf_str, sizeof(buf_str),
1061 "%d ", ret_variable_int);
1062 strncat(result_str, buf_str,
1063 sizeof(result_str));
1070 /* Check variable IN pos */
1071 for (temp_str = (char *)get_str; *temp_str != '\0';
1073 if (*temp_str != '%') {
1074 strncat(result_str, temp_str, 1);
1076 if (*(temp_str + 1) == '%') {
1077 strncat(result_str, temp_str,
1079 } else if (*(temp_str + 1) == 'd') {
1081 ret_variable_int = 0;
1085 "%dtype%d", check_type,
1088 bundle_get_val(b, buf_key);
1089 ret_var_type = atoi(ret_val);
1091 NOTIFICATION_VARIABLE_TYPE_COUNT)
1093 /* Get notification count */
1094 notification_noti_get_count
1096 noti->caller_pkgname,
1116 sizeof(buf_str), "%d",
1118 strncat(result_str, buf_str,
1119 sizeof(result_str));
1124 } else if (*(temp_str + 1) == 's') {
1129 check_type, num_args);
1131 bundle_get_val(b, buf_key);
1134 sizeof(buf_str), "%s",
1136 strncat(result_str, buf_str,
1137 sizeof(result_str));
1142 } else if (*(temp_str + 1) == 'f') {
1147 check_type, num_args);
1149 bundle_get_val(b, buf_key);
1150 ret_variable_double =
1156 ret_variable_double);
1157 strncat(result_str, buf_str,
1158 sizeof(result_str));
1168 /* Check last variable is count, LEFT pos */
1169 if (num_args < noti->num_format_args) {
1170 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1171 check_type, num_args);
1172 ret_val = bundle_get_val(b, buf_key);
1173 ret_var_type = atoi(ret_val);
1175 NOTIFICATION_VARIABLE_TYPE_COUNT) {
1177 snprintf(buf_key, sizeof(buf_key),
1178 "%dvalue%d", check_type,
1180 ret_val = bundle_get_val(b, buf_key);
1181 ret_variable_int = atoi(ret_val);
1183 if (ret_variable_int ==
1184 NOTIFICATION_COUNT_POS_RIGHT) {
1185 notification_noti_get_count
1187 noti->caller_pkgname,
1192 sizeof(buf_str), " %d",
1194 strncat(result_str, buf_str,
1195 sizeof(result_str));
1203 switch (check_type) {
1204 case NOTIFICATION_TEXT_TYPE_TITLE:
1205 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
1206 if (noti->temp_title != NULL)
1207 free(noti->temp_title);
1209 noti->temp_title = strdup(result_str);
1211 *text = noti->temp_title;
1213 case NOTIFICATION_TEXT_TYPE_CONTENT:
1214 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1215 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
1216 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1217 if (noti->temp_content !=
1219 free(noti->temp_content);
1221 noti->temp_content = strdup(result_str);
1223 *text = noti->temp_content;
1232 if (check_type == NOTIFICATION_TEXT_TYPE_TITLE
1233 || check_type == NOTIFICATION_TEXT_TYPE_GROUP_TITLE) {
1234 /* Remove app name if exist, because pkgname is changed according to language setting */
1235 if (noti->app_name != NULL) {
1236 free(noti->app_name);
1237 noti->app_name = NULL;
1240 /* First, get app name from launch_pkgname */
1241 if (noti->launch_pkgname != NULL) {
1243 _notification_get_name(noti->
1247 /* Second, get app name from caller_pkgname */
1248 if (noti->app_name == NULL
1249 && noti->caller_pkgname != NULL) {
1251 _notification_get_name(noti->
1255 /* Third, get app name from service data */
1256 if (noti->app_name == NULL
1257 && noti->b_service_single_launch != NULL) {
1259 appsvc_get_pkgname(noti->
1260 b_service_single_launch);
1262 if (pkgname != NULL) {
1264 _notification_get_name(pkgname);
1268 *text = noti->app_name;
1274 NOTIFICATION_INFO("Get text : %s", *text);
1276 return NOTIFICATION_ERROR_NONE;
1279 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
1283 /* check noti and domain is valid data */
1284 if (noti == NULL || domain == NULL) {
1285 return NOTIFICATION_ERROR_INVALID_DATA;
1290 /* Remove previous domain */
1294 noti->domain = strdup(domain);
1296 /* Check locale dir */
1298 /* Remove previous locale dir */
1301 /* Copy locale dir */
1302 noti->dir = strdup(dir);
1304 return NOTIFICATION_ERROR_NONE;
1307 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
1311 /* Check noti is valid data */
1313 return NOTIFICATION_ERROR_INVALID_DATA;
1317 if (domain != NULL && noti->domain != NULL) {
1318 *domain = noti->domain;
1321 /* Get locale dir */
1322 if (dir != NULL && noti->dir != NULL) {
1326 return NOTIFICATION_ERROR_NONE;
1329 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1330 notification_sound_type_e type,
1333 /* Check noti is valid data */
1335 return NOTIFICATION_ERROR_INVALID_DATA;
1338 /* Check type is valid */
1339 if (type < NOTIFICATION_SOUND_TYPE_NONE
1340 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1341 return NOTIFICATION_ERROR_INVALID_DATA;
1344 /* Save sound type */
1345 noti->sound_type = type;
1347 /* Save sound path if user data type */
1348 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1349 if (noti->sound_path != NULL) {
1350 free(noti->sound_path);
1353 noti->sound_path = strdup(path);
1355 if (noti->sound_path != NULL) {
1356 free(noti->sound_path);
1357 noti->sound_path = NULL;
1361 return NOTIFICATION_ERROR_NONE;
1364 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1365 notification_sound_type_e *type,
1368 /* check noti and type is valid data */
1369 if (noti == NULL || type == NULL) {
1370 return NOTIFICATION_ERROR_INVALID_DATA;
1373 /* Set sound type */
1374 *type = noti->sound_type;
1376 /* Set sound path if user data type */
1377 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1379 *path = noti->sound_path;
1382 return NOTIFICATION_ERROR_NONE;
1385 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1386 notification_vibration_type_e type,
1389 /* Check noti is valid data */
1391 return NOTIFICATION_ERROR_INVALID_DATA;
1394 /* Check type is valid */
1395 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1396 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1397 return NOTIFICATION_ERROR_INVALID_DATA;
1400 /* Save vibration type */
1401 noti->vibration_type = type;
1403 /* Save sound path if user data type */
1404 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1405 if (noti->vibration_path != NULL) {
1406 free(noti->vibration_path);
1409 noti->vibration_path = strdup(path);
1411 if (noti->vibration_path != NULL) {
1412 free(noti->vibration_path);
1413 noti->vibration_path = NULL;
1417 return NOTIFICATION_ERROR_NONE;
1421 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1422 notification_vibration_type_e *type,
1425 /* check noti and type is valid data */
1426 if (noti == NULL || type == NULL) {
1427 return NOTIFICATION_ERROR_INVALID_DATA;
1430 /* Set vibration type */
1431 *type = noti->vibration_type;
1433 /* Set sound path if user data type */
1434 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1436 *path = noti->vibration_path;
1439 return NOTIFICATION_ERROR_NONE;
1442 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1443 const char *pkgname)
1445 if (noti == NULL || pkgname == NULL) {
1446 return NOTIFICATION_ERROR_INVALID_DATA;
1449 if (noti->launch_pkgname) {
1450 free(noti->launch_pkgname);
1453 noti->launch_pkgname = strdup(pkgname);
1455 return NOTIFICATION_ERROR_NONE;
1458 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1461 if (noti == NULL || pkgname == NULL) {
1462 return NOTIFICATION_ERROR_INVALID_DATA;
1465 if (noti->launch_pkgname) {
1466 *pkgname = noti->launch_pkgname;
1468 *pkgname = noti->caller_pkgname;
1471 return NOTIFICATION_ERROR_NONE;
1474 EXPORT_API notification_error_e notification_set_args(notification_h noti,
1476 bundle * group_args)
1478 if (noti == NULL || args == NULL) {
1479 return NOTIFICATION_ERROR_INVALID_DATA;
1483 bundle_free(noti->args);
1486 noti->args = bundle_dup(args);
1488 if (noti->group_args) {
1489 bundle_free(noti->group_args);
1490 noti->group_args = NULL;
1493 if (group_args != NULL) {
1494 noti->group_args = bundle_dup(group_args);
1497 return NOTIFICATION_ERROR_NONE;
1500 EXPORT_API notification_error_e notification_get_args(notification_h noti,
1502 bundle ** group_args)
1504 if (noti == NULL || args == NULL) {
1505 return NOTIFICATION_ERROR_INVALID_DATA;
1514 if (group_args != NULL && noti->group_args) {
1515 *group_args = noti->group_args;
1518 return NOTIFICATION_ERROR_NONE;
1521 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1522 notification_execute_type_e type,
1525 bundle *service_handle)
1527 char buf_key[32] = { 0, };
1528 const char *ret_val = NULL;
1532 return NOTIFICATION_ERROR_INVALID_DATA;
1535 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1536 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1537 return NOTIFICATION_ERROR_INVALID_DATA;
1540 /* Create execute option bundle if does not exist */
1541 if (noti->b_execute_option != NULL) {
1542 noti->b_execute_option = bundle_create();
1545 b = noti->b_execute_option;
1550 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1552 /* Check text key exist */
1553 ret_val = bundle_get_val(b, buf_key);
1554 if (ret_val != NULL) {
1555 /* Remove previous data */
1556 bundle_del(b, buf_key);
1560 bundle_add(b, buf_key, text);
1566 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1568 /* Check key key exist */
1569 ret_val = bundle_get_val(b, buf_key);
1570 if (ret_val != NULL) {
1571 /* Remove previous data */
1572 bundle_del(b, buf_key);
1576 bundle_add(b, buf_key, key);
1580 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1581 /* Remove previous data if exist */
1582 if (noti->b_service_responding != NULL) {
1583 bundle_free(noti->b_service_responding);
1584 noti->b_service_responding = NULL;
1587 /* Save service handle */
1588 if (service_handle != NULL) {
1589 noti->b_service_responding = bundle_dup(service_handle);
1592 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1593 /* Remove previous data if exist */
1594 if (noti->b_service_single_launch != NULL) {
1595 bundle_free(noti->b_service_single_launch);
1596 noti->b_service_single_launch = NULL;
1599 /* Save service handle */
1600 if (service_handle != NULL) {
1601 noti->b_service_single_launch =
1602 bundle_dup(service_handle);
1605 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1606 /* Remove previous data if exist */
1607 if (noti->b_service_multi_launch != NULL) {
1608 bundle_free(noti->b_service_multi_launch);
1609 noti->b_service_multi_launch = NULL;
1612 /* Save service handle */
1613 if (service_handle != NULL) {
1614 noti->b_service_multi_launch =
1615 bundle_dup(service_handle);
1622 return NOTIFICATION_ERROR_NONE;
1625 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1626 notification_execute_type_e type,
1628 bundle **service_handle)
1630 char buf_key[32] = { 0, };
1631 const char *ret_val = NULL;
1632 char *get_str = NULL;
1636 return NOTIFICATION_ERROR_INVALID_DATA;
1639 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1640 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1641 return NOTIFICATION_ERROR_INVALID_DATA;
1645 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1646 b = noti->b_service_responding;
1648 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1649 b = noti->b_service_single_launch;
1651 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1652 b = noti->b_service_multi_launch;
1662 // Get text domain and dir
1663 if (noti->domain == NULL || noti->dir == NULL) {
1664 _notification_get_text_domain(noti);
1668 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1670 /* Check key key exist */
1671 ret_val = bundle_get_val(b, buf_key);
1672 if (ret_val != NULL && noti->domain != NULL
1673 && noti->dir != NULL) {
1674 /* Get application string */
1675 bindtextdomain(noti->domain, noti->dir);
1677 get_str = dgettext(noti->domain, ret_val);
1680 } else if (ret_val != NULL) {
1681 /* Get system string */
1682 get_str = dgettext("sys_string", ret_val);
1686 /* Get basic text */
1687 snprintf(buf_key, sizeof(buf_key), "text%d",
1690 ret_val = bundle_get_val(b, buf_key);
1698 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1699 b = noti->b_service_responding;
1701 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1702 b = noti->b_service_single_launch;
1704 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1705 b = noti->b_service_multi_launch;
1712 if (service_handle != NULL) {
1713 *service_handle = b;
1716 return NOTIFICATION_ERROR_NONE;
1719 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1722 /* Check noti is valid data */
1724 return NOTIFICATION_ERROR_INVALID_DATA;
1728 noti->flags_for_property = flags;
1730 return NOTIFICATION_ERROR_NONE;
1733 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1736 /* Check noti and flags are valid data */
1737 if (noti == NULL || flags == NULL) {
1738 return NOTIFICATION_ERROR_INVALID_DATA;
1742 *flags = noti->flags_for_property;
1744 return NOTIFICATION_ERROR_NONE;
1747 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1750 /* Check noti is valid data */
1752 return NOTIFICATION_ERROR_INVALID_DATA;
1756 noti->display_applist = applist;
1758 return NOTIFICATION_ERROR_NONE;
1761 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1764 /* Check noti and applist are valid data */
1765 if (noti == NULL || applist == NULL) {
1766 return NOTIFICATION_ERROR_INVALID_DATA;
1770 *applist = noti->display_applist;
1772 return NOTIFICATION_ERROR_NONE;
1775 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1778 /* Check noti is valid data */
1780 return NOTIFICATION_ERROR_INVALID_DATA;
1783 /* Save progress size */
1784 noti->progress_size = size;
1786 return NOTIFICATION_ERROR_NONE;
1789 EXPORT_API notification_error_e notification_get_size(notification_h noti,
1792 /* Check noti and size is valid data */
1793 if (noti == NULL || size == NULL) {
1794 return NOTIFICATION_ERROR_INVALID_DATA;
1797 /* Set progress size */
1798 *size = noti->progress_size;
1800 return NOTIFICATION_ERROR_NONE;
1803 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
1806 /* Check noti is valid data */
1808 return NOTIFICATION_ERROR_INVALID_DATA;
1811 /* Save progress percentage */
1812 noti->progress_percentage = percentage;
1814 return NOTIFICATION_ERROR_NONE;
1817 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
1820 /* Check noti and percentage are valid data */
1821 if (noti == NULL || percentage == NULL) {
1822 return NOTIFICATION_ERROR_INVALID_DATA;
1825 /* Set progress percentage */
1826 *percentage = noti->progress_percentage;
1828 return NOTIFICATION_ERROR_NONE;
1831 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
1832 const char *pkgname)
1834 /* check noti and pkgname are valid data */
1835 if (noti == NULL || pkgname == NULL) {
1836 return NOTIFICATION_ERROR_INVALID_DATA;
1839 /* Remove previous caller pkgname */
1840 if (noti->caller_pkgname) {
1841 free(noti->caller_pkgname);
1842 noti->caller_pkgname = NULL;
1845 noti->caller_pkgname = strdup(pkgname);
1847 return NOTIFICATION_ERROR_NONE;
1850 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
1853 /* Check noti and pkgname are valid data */
1854 if (noti == NULL || pkgname == NULL) {
1855 return NOTIFICATION_ERROR_INVALID_DATA;
1858 /* Get caller pkgname */
1859 if (noti->caller_pkgname) {
1860 *pkgname = noti->caller_pkgname;
1865 return NOTIFICATION_ERROR_NONE;
1868 EXPORT_API notification_error_e notification_set_badge(const char *pkgname,
1869 int group_id, int count)
1871 char *caller_pkgname = NULL;
1872 int ret = NOTIFICATION_ERROR_NONE;
1874 /* Check count is valid count */
1876 return NOTIFICATION_ERROR_INVALID_DATA;
1880 if (pkgname == NULL) {
1881 caller_pkgname = _notification_get_pkgname_by_pid();
1883 /* Set count into Group DB */
1885 notification_group_set_badge(caller_pkgname, group_id,
1888 if (caller_pkgname != NULL) {
1889 free(caller_pkgname);
1892 /* Set count into Group DB */
1893 ret = notification_group_set_badge(pkgname, group_id, count);
1899 EXPORT_API notification_error_e notification_get_badge(const char *pkgname,
1900 int group_id, int *count)
1902 char *caller_pkgname = NULL;
1903 int ret = NOTIFICATION_ERROR_NONE;
1904 int ret_unread_count = 0;
1907 if (pkgname == NULL) {
1908 caller_pkgname = _notification_get_pkgname_by_pid();
1910 /* Get count from Group DB */
1912 notification_group_get_badge(caller_pkgname, group_id,
1915 if (caller_pkgname != NULL) {
1916 free(caller_pkgname);
1919 /* Get count from Group DB */
1921 notification_group_get_badge(pkgname, group_id,
1925 if (ret != NOTIFICATION_ERROR_NONE) {
1930 if (count != NULL) {
1931 *count = ret_unread_count;
1934 return NOTIFICATION_ERROR_NONE;
1937 EXPORT_API notification_error_e notification_get_id(notification_h noti,
1938 int *group_id, int *priv_id)
1940 /* check noti is valid data */
1942 return NOTIFICATION_ERROR_INVALID_DATA;
1945 /* Check group_id is valid data */
1948 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1949 *group_id = NOTIFICATION_GROUP_ID_NONE;
1951 *group_id = noti->group_id;
1955 /* Check priv_id is valid data */
1958 *priv_id = noti->priv_id;
1961 return NOTIFICATION_ERROR_NONE;
1964 EXPORT_API notification_error_e notification_get_type(notification_h noti,
1965 notification_type_e *type)
1967 /* Check noti and type is valid data */
1968 if (noti == NULL || type == NULL) {
1969 return NOTIFICATION_ERROR_INVALID_DATA;
1975 return NOTIFICATION_ERROR_NONE;
1978 EXPORT_API notification_error_e notification_insert(notification_h noti,
1983 /* Check noti is vaild data */
1985 return NOTIFICATION_ERROR_INVALID_DATA;
1988 /* Check noti type is valid type */
1989 if (noti->type <= NOTIFICATION_TYPE_NONE
1990 || noti->type >= NOTIFICATION_TYPE_MAX) {
1991 return NOTIFICATION_ERROR_INVALID_DATA;
1994 /* Save insert time */
1995 noti->insert_time = time(NULL);
1997 /* Insert into DB */
1998 ret = notification_noti_insert(noti);
1999 if (ret != NOTIFICATION_ERROR_NONE) {
2003 /* Check disable update on insert property */
2004 if (noti->flags_for_property
2005 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
2006 /* Disable changed cb */
2008 /* Enable changed cb */
2009 _notification_changed(NOTI_CHANGED_NOTI);
2012 /* If priv_id is valid data, set priv_id */
2013 if (priv_id != NULL) {
2014 *priv_id = noti->priv_id;
2017 return NOTIFICATION_ERROR_NONE;
2020 EXPORT_API notification_error_e notification_update(notification_h noti)
2024 /* Check noti is valid data */
2026 /* Update insert time ? */
2027 noti->insert_time = time(NULL);
2029 ret = notification_noti_update(noti);
2030 if (ret != NOTIFICATION_ERROR_NONE) {
2035 /* Send changed notification */
2036 _notification_changed(NOTI_CHANGED_NOTI);
2038 return NOTIFICATION_ERROR_NONE;
2041 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
2045 /* Delete all notification of type */
2046 ret = notification_noti_delete_all(type, NULL);
2047 if (ret != NOTIFICATION_ERROR_NONE) {
2051 /* Send chagned notification */
2052 _notification_changed(NOTI_CHANGED_NOTI);
2054 return NOTIFICATION_ERROR_NONE;
2057 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
2058 notification_type_e type)
2061 char *caller_pkgname = NULL;
2063 if (pkgname == NULL) {
2064 caller_pkgname = _notification_get_pkgname_by_pid();
2066 caller_pkgname = strdup(pkgname);
2069 ret = notification_noti_delete_all(type, caller_pkgname);
2070 if (ret != NOTIFICATION_ERROR_NONE) {
2071 free(caller_pkgname);
2075 _notification_changed(NOTI_CHANGED_NOTI);
2077 free(caller_pkgname);
2082 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
2083 notification_type_e type,
2087 char *caller_pkgname = NULL;
2089 if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2090 return NOTIFICATION_ERROR_INVALID_DATA;
2093 if (pkgname == NULL) {
2094 caller_pkgname = _notification_get_pkgname_by_pid();
2096 caller_pkgname = strdup(pkgname);
2100 notification_noti_delete_group_by_group_id(caller_pkgname,
2102 if (ret != NOTIFICATION_ERROR_NONE) {
2103 free(caller_pkgname);
2107 _notification_changed(NOTI_CHANGED_NOTI);
2109 free(caller_pkgname);
2114 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2115 notification_type_e type,
2119 char *caller_pkgname = NULL;
2121 if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2122 return NOTIFICATION_ERROR_INVALID_DATA;
2125 if (pkgname == NULL) {
2126 caller_pkgname = _notification_get_pkgname_by_pid();
2128 caller_pkgname = strdup(pkgname);
2132 notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id);
2133 if (ret != NOTIFICATION_ERROR_NONE) {
2134 free(caller_pkgname);
2138 _notification_changed(NOTI_CHANGED_NOTI);
2140 free(caller_pkgname);
2145 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
2146 notification_type_e type,
2150 char *caller_pkgname = NULL;
2152 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2153 return NOTIFICATION_ERROR_INVALID_DATA;
2156 if (pkgname == NULL) {
2157 caller_pkgname = _notification_get_pkgname_by_pid();
2159 caller_pkgname = strdup(pkgname);
2162 ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id);
2163 if (ret != NOTIFICATION_ERROR_NONE) {
2164 free(caller_pkgname);
2168 _notification_changed(NOTI_CHANGED_NOTI);
2170 free(caller_pkgname);
2175 EXPORT_API notification_error_e notification_delete(notification_h noti)
2180 return NOTIFICATION_ERROR_INVALID_DATA;
2184 notification_noti_delete_by_priv_id(noti->caller_pkgname,
2186 if (ret != NOTIFICATION_ERROR_NONE) {
2190 if (noti->flags_for_property
2191 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) {
2192 NOTIFICATION_INFO("Disabled update while delete.");
2194 _notification_changed(NOTI_CHANGED_NOTI);
2197 return NOTIFICATION_ERROR_NONE;
2200 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
2204 char *caller_pkgname = NULL;
2205 int input_priv_id = 0;
2206 double input_progress = 0.0;
2208 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2210 return NOTIFICATION_ERROR_INVALID_DATA;
2212 input_priv_id = noti->priv_id;
2215 input_priv_id = priv_id;
2219 caller_pkgname = _notification_get_pkgname_by_pid();
2221 caller_pkgname = strdup(noti->caller_pkgname);
2224 if (progress < 0.0) {
2225 input_progress = 0.0;
2226 } else if (progress > 1.0) {
2227 input_progress = 1.0;
2229 input_progress = progress;
2232 notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2235 if (caller_pkgname) {
2236 free(caller_pkgname);
2239 return NOTIFICATION_ERROR_NONE;
2242 EXPORT_API notification_error_e notification_update_size(notification_h noti,
2246 char *caller_pkgname = NULL;
2247 int input_priv_id = 0;
2248 double input_size = 0.0;
2250 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2252 return NOTIFICATION_ERROR_INVALID_DATA;
2254 input_priv_id = noti->priv_id;
2257 input_priv_id = priv_id;
2261 caller_pkgname = _notification_get_pkgname_by_pid();
2263 caller_pkgname = strdup(noti->caller_pkgname);
2272 notification_ongoing_update_size(caller_pkgname, input_priv_id,
2275 if (caller_pkgname) {
2276 free(caller_pkgname);
2279 return NOTIFICATION_ERROR_NONE;
2282 EXPORT_API notification_error_e notification_update_content(notification_h noti,
2284 const char *content)
2286 char *caller_pkgname = NULL;
2287 int input_priv_id = 0;
2289 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2291 return NOTIFICATION_ERROR_INVALID_DATA;
2293 input_priv_id = noti->priv_id;
2296 input_priv_id = priv_id;
2300 caller_pkgname = _notification_get_pkgname_by_pid();
2302 caller_pkgname = strdup(noti->caller_pkgname);
2305 notification_ongoing_update_content(caller_pkgname, input_priv_id,
2308 if (caller_pkgname) {
2309 free(caller_pkgname);
2312 return NOTIFICATION_ERROR_NONE;
2315 EXPORT_API notification_h notification_new(notification_type_e type,
2316 int group_id, int priv_id)
2318 notification_h noti = NULL;
2320 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2321 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2325 if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2326 NOTIFICATION_ERR("INVALID GROUP ID : %d", group_id);
2330 if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2331 NOTIFICATION_ERR("INVALID PRIV ID : %d", priv_id);
2335 noti = (notification_h) malloc(sizeof(struct _notification));
2337 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2340 memset(noti, 0x00, sizeof(struct _notification));
2344 noti->group_id = group_id;
2345 noti->internal_group_id = 0;
2346 noti->priv_id = priv_id;
2348 noti->caller_pkgname = _notification_get_pkgname_by_pid();
2349 noti->launch_pkgname = NULL;
2351 noti->group_args = NULL;
2353 noti->b_execute_option = NULL;
2354 noti->b_service_responding = NULL;
2355 noti->b_service_single_launch = NULL;
2356 noti->b_service_multi_launch = NULL;
2358 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2359 noti->sound_path = NULL;
2361 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2362 noti->vibration_path = NULL;
2364 noti->domain = NULL;
2367 noti->b_text = NULL;
2369 noti->b_format_args = NULL;
2370 noti->num_format_args = 0;
2372 noti->b_image_path = NULL;
2375 noti->insert_time = 0;
2377 noti->flags_for_property = 0;
2378 noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2380 noti->progress_size = 0.0;
2381 noti->progress_percentage = 0.0;
2383 noti->app_icon_path = NULL;
2384 noti->app_name = NULL;
2385 noti->temp_title = NULL;
2386 noti->temp_content = NULL;
2391 EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone)
2393 notification_h new_noti = NULL;
2395 if (noti == NULL || clone == NULL) {
2396 NOTIFICATION_ERR("INVALID PARAMETER.");
2397 return NOTIFICATION_ERROR_INVALID_DATA;
2400 new_noti = (notification_h) malloc(sizeof(struct _notification));
2401 if (new_noti == NULL) {
2402 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2403 return NOTIFICATION_ERROR_NO_MEMORY;
2405 memset(new_noti, 0x00, sizeof(struct _notification));
2407 new_noti->type = noti->type;
2409 new_noti->group_id = noti->group_id;
2410 new_noti->internal_group_id = noti->internal_group_id;
2411 new_noti->priv_id = noti->priv_id;
2413 if(noti->caller_pkgname != NULL) {
2414 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2416 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2418 if(noti->launch_pkgname != NULL) {
2419 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2421 new_noti->launch_pkgname = NULL;
2424 if(noti->args != NULL) {
2425 new_noti->args = bundle_dup(noti->args);
2427 new_noti->args = NULL;
2429 if(noti->group_args != NULL) {
2430 new_noti->group_args = bundle_dup(noti->group_args);
2432 new_noti->group_args = NULL;
2435 if(noti->b_execute_option != NULL) {
2436 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2438 new_noti->b_execute_option = NULL;
2440 if(noti->b_service_responding != NULL) {
2441 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2443 new_noti->b_service_responding = NULL;
2445 if(noti->b_service_single_launch != NULL) {
2446 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2448 new_noti->b_service_single_launch = NULL;
2450 if(noti->b_service_multi_launch != NULL) {
2451 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2453 new_noti->b_service_multi_launch = NULL;
2456 new_noti->sound_type = noti->sound_type;
2457 if(noti->sound_path != NULL) {
2458 new_noti->sound_path = strdup(noti->sound_path);
2460 new_noti->sound_path = NULL;
2462 new_noti->vibration_type = noti->vibration_type;
2463 if(noti->vibration_path != NULL) {
2464 new_noti->vibration_path = strdup(noti->vibration_path);
2466 new_noti->vibration_path = NULL;
2469 if(noti->domain != NULL) {
2470 new_noti->domain = strdup(noti->domain);
2472 new_noti->domain = NULL;
2474 if(noti->dir != NULL) {
2475 new_noti->dir = strdup(noti->dir);
2477 new_noti->dir = NULL;
2480 if(noti->b_text != NULL) {
2481 new_noti->b_text = bundle_dup(noti->b_text);
2483 new_noti->b_text = NULL;
2485 if(noti->b_key != NULL) {
2486 new_noti->b_key = bundle_dup(noti->b_key);
2488 new_noti->b_key = NULL;
2490 if(noti->b_format_args != NULL) {
2491 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2493 new_noti->b_format_args = NULL;
2495 new_noti->num_format_args = noti->num_format_args;
2497 if(noti->b_image_path != NULL) {
2498 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2500 new_noti->b_image_path = NULL;
2503 new_noti->time = noti->time;
2504 new_noti->insert_time = noti->insert_time;
2506 new_noti->flags_for_property = noti->flags_for_property;
2507 new_noti->display_applist = noti->display_applist;
2509 new_noti->progress_size = noti->progress_size;
2510 new_noti->progress_percentage = noti->progress_percentage;
2512 new_noti->app_icon_path = NULL;
2513 new_noti->app_name = NULL;
2514 new_noti->temp_title = NULL;
2515 new_noti->temp_content = NULL;
2519 return NOTIFICATION_ERROR_NONE;
2523 EXPORT_API notification_error_e notification_free(notification_h noti)
2526 return NOTIFICATION_ERROR_INVALID_DATA;
2529 if (noti->caller_pkgname) {
2530 free(noti->caller_pkgname);
2532 if (noti->launch_pkgname) {
2533 free(noti->launch_pkgname);
2536 bundle_free(noti->args);
2538 if (noti->group_args) {
2539 bundle_free(noti->group_args);
2542 if (noti->b_execute_option) {
2543 bundle_free(noti->b_execute_option);
2545 if (noti->b_service_responding) {
2546 bundle_free(noti->b_service_responding);
2548 if (noti->b_service_single_launch) {
2549 bundle_free(noti->b_service_single_launch);
2551 if (noti->b_service_multi_launch) {
2552 bundle_free(noti->b_service_multi_launch);
2555 if (noti->sound_path) {
2556 free(noti->sound_path);
2558 if (noti->vibration_path) {
2559 free(noti->vibration_path);
2570 bundle_free(noti->b_text);
2573 bundle_free(noti->b_key);
2575 if (noti->b_format_args) {
2576 bundle_free(noti->b_format_args);
2579 if (noti->b_image_path) {
2580 bundle_free(noti->b_image_path);
2583 if (noti->app_icon_path) {
2584 free(noti->app_icon_path);
2586 if (noti->app_name) {
2587 free(noti->app_name);
2589 if (noti->temp_title) {
2590 free(noti->temp_title);
2592 if (noti->temp_content) {
2593 free(noti->temp_content);
2598 return NOTIFICATION_ERROR_NONE;
2601 EXPORT_API notification_error_e
2602 notification_resister_changed_cb(void (*changed_cb)
2603 (void *data, notification_type_e type),
2606 notification_cb_list_s *noti_cb_list_new = NULL;
2607 notification_cb_list_s *noti_cb_list = NULL;
2609 if (!g_dbus_handle) {
2610 g_dbus_handle = _noti_changed_monitor_init();
2612 return NOTIFICATION_ERROR_FROM_DBUS;
2616 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2618 noti_cb_list_new->next = NULL;
2619 noti_cb_list_new->prev = NULL;
2621 noti_cb_list_new->changed_cb = changed_cb;
2622 noti_cb_list_new->data = user_data;
2624 if (g_notification_cb_list == NULL) {
2625 g_notification_cb_list = noti_cb_list_new;
2627 noti_cb_list = g_notification_cb_list;
2629 while (noti_cb_list->next != NULL) {
2630 noti_cb_list = noti_cb_list->next;
2633 noti_cb_list->next = noti_cb_list_new;
2634 noti_cb_list_new->prev = noti_cb_list;
2636 return NOTIFICATION_ERROR_NONE;
2639 EXPORT_API notification_error_e
2640 notification_unresister_changed_cb(void (*changed_cb)
2641 (void *data, notification_type_e type))
2643 notification_cb_list_s *noti_cb_list = NULL;
2644 notification_cb_list_s *noti_cb_list_prev = NULL;
2645 notification_cb_list_s *noti_cb_list_next = NULL;
2647 noti_cb_list = g_notification_cb_list;
2649 if (noti_cb_list == NULL) {
2650 return NOTIFICATION_ERROR_INVALID_DATA;
2653 while (noti_cb_list->prev != NULL) {
2654 noti_cb_list = noti_cb_list->prev;
2658 if (noti_cb_list->changed_cb == changed_cb) {
2659 noti_cb_list_prev = noti_cb_list->prev;
2660 noti_cb_list_next = noti_cb_list->next;
2662 if (noti_cb_list_prev == NULL) {
2663 g_notification_cb_list = noti_cb_list_next;
2665 noti_cb_list_prev->next = noti_cb_list_next;
2668 if (noti_cb_list_next == NULL) {
2669 if (noti_cb_list_prev != NULL) {
2670 noti_cb_list_prev->next = NULL;
2673 noti_cb_list_next->prev = noti_cb_list_prev;
2678 if (g_notification_cb_list == NULL)
2679 _noti_chanaged_monitor_fini();
2681 return NOTIFICATION_ERROR_NONE;
2683 noti_cb_list = noti_cb_list->next;
2684 } while (noti_cb_list != NULL);
2686 return NOTIFICATION_ERROR_INVALID_DATA;
2689 EXPORT_API notification_error_e
2690 notification_resister_badge_changed_cb(void (*changed_cb)
2691 (void *data, const char *pkgname,
2692 int group_id), void *user_data)
2694 // Add DBus signal handler
2695 return NOTIFICATION_ERROR_NONE;
2698 EXPORT_API notification_error_e
2699 notification_unresister_badge_changed_cb(void (*changed_cb)
2700 (void *data, const char *pkgname,
2703 // Del DBus signal handler
2704 return NOTIFICATION_ERROR_NONE;
2707 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
2708 const char *pkgname,
2710 int priv_id, int *count)
2716 notification_noti_get_count(type, pkgname, group_id, priv_id,
2718 if (ret != NOTIFICATION_ERROR_NONE) {
2722 if (count != NULL) {
2723 *count = noti_count;
2726 return NOTIFICATION_ERROR_NONE;
2729 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
2731 notification_list_h *list)
2733 notification_list_h get_list = NULL;
2736 ret = notification_noti_get_grouping_list(type, count, &get_list);
2737 if (ret != NOTIFICATION_ERROR_NONE) {
2743 return NOTIFICATION_ERROR_NONE;
2746 EXPORT_API notification_error_e
2747 notification_get_grouping_list(notification_type_e type, int count,
2748 notification_list_h * list)
2750 notification_list_h get_list = NULL;
2753 ret = notification_noti_get_grouping_list(type, count, &get_list);
2754 if (ret != NOTIFICATION_ERROR_NONE) {
2760 return NOTIFICATION_ERROR_NONE;
2763 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
2767 notification_list_h *list)
2769 notification_list_h get_list = NULL;
2773 notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2775 if (ret != NOTIFICATION_ERROR_NONE) {
2781 return NOTIFICATION_ERROR_NONE;
2784 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
2786 notification_list_h cur_list = NULL;
2787 notification_h noti = NULL;
2790 NOTIFICATION_ERR("INVALID DATA : list == NULL");
2791 return NOTIFICATION_ERROR_INVALID_DATA;
2794 cur_list = notification_list_get_head(list);
2796 while (cur_list != NULL) {
2797 noti = notification_list_get_data(cur_list);
2798 cur_list = notification_list_remove(cur_list, noti);
2800 notification_free(noti);
2803 return NOTIFICATION_ERROR_NONE;