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>
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.
33 #include <vconf-keys.h>
36 #include <notification.h>
37 #include <notification_list.h>
38 #include <notification_debug.h>
39 #include <notification_internal.h>
40 #include <notification_noti.h>
41 #include <notification_ongoing.h>
42 #include <notification_group.h>
44 typedef struct _notification_cb_list notification_cb_list_s;
46 struct _notification_cb_list {
47 notification_cb_list_s *prev;
48 notification_cb_list_s *next;
50 void (*changed_cb) (void *data, notification_type_e type);
54 static notification_cb_list_s *g_notification_cb_list = NULL;
55 static int g_notification_heynoti_fd = -1;
57 #define NOTI_PKGNAME_LEN 512
58 #define NOTI_CHANGED_NOTI "notification_noti_changed"
59 #define NOTI_CHANGED_ONGOING "notification_ontoing_changed"
61 static char *_notification_get_pkgname_by_pid(void)
63 char buf[NOTI_PKGNAME_LEN] = { 0, };
64 char pkgname[NOTI_PKGNAME_LEN] = { 0, };
65 int pid = 0, ret = AUL_R_OK;
70 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
71 if (ret != AUL_R_OK) {
72 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
74 fd = open(buf, O_RDONLY);
79 ret = read(fd, pkgname, sizeof(pkgname) - 1);
90 if (pkgname == NULL || pkgname[0] == '\0') {
93 return strdup(pkgname);
97 static char *_notification_get_icon(const char *package)
104 ret = ail_package_get_appinfo(package, &handle);
105 if (ret != AIL_ERROR_OK) {
109 ret = ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &str);
110 if (ret != AIL_ERROR_OK) {
111 ail_package_destroy_appinfo(handle);
117 ret = ail_package_destroy_appinfo(handle);
118 if (ret != AIL_ERROR_OK) {
119 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
125 static char *_notification_get_name(const char *package)
127 ail_appinfo_h handle;
132 ret = ail_package_get_appinfo(package, &handle);
133 if (ret != AIL_ERROR_OK) {
137 ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
138 if (ret != AIL_ERROR_OK) {
139 ail_package_destroy_appinfo(handle);
145 ret = ail_package_destroy_appinfo(handle);
146 if (ret != AIL_ERROR_OK) {
147 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
153 static void _notification_get_text_domain(notification_h noti)
155 if (noti->domain != NULL) {
159 if (noti->dir != NULL) {
164 static void _notification_chagned_noti_cb(void *data)
166 notification_cb_list_s *noti_cb_list = NULL;
168 if (g_notification_cb_list == NULL) {
172 noti_cb_list = g_notification_cb_list;
174 while (noti_cb_list->prev != NULL) {
175 noti_cb_list = noti_cb_list->prev;
178 while (noti_cb_list != NULL) {
179 if (noti_cb_list->changed_cb) {
180 noti_cb_list->changed_cb(noti_cb_list->data,
181 NOTIFICATION_TYPE_NOTI);
184 noti_cb_list = noti_cb_list->next;
189 static void _notification_chagned_ongoing_cb(void *data)
191 notification_cb_list_s *noti_cb_list = NULL;
193 if (g_notification_cb_list == NULL) {
197 noti_cb_list = g_notification_cb_list;
199 while (noti_cb_list->prev != NULL) {
200 noti_cb_list = noti_cb_list->prev;
203 while (noti_cb_list != NULL) {
204 if (noti_cb_list->changed_cb) {
205 noti_cb_list->changed_cb(noti_cb_list->data,
206 NOTIFICATION_TYPE_ONGOING);
209 noti_cb_list = noti_cb_list->next;
214 static void _notification_changed(const char *type)
216 heynoti_publish(type);
219 /* notification_set_icon will be removed */
220 EXPORT_API notification_error_e notification_set_icon(notification_h noti,
221 const char *icon_path)
223 int ret_err = NOTIFICATION_ERROR_NONE;
226 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
232 /* notification_get_icon will be removed */
233 EXPORT_API notification_error_e notification_get_icon(notification_h noti,
236 int ret_err = NOTIFICATION_ERROR_NONE;
237 char *ret_image_path = NULL;
240 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
243 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
244 *icon_path = ret_image_path;
246 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
252 EXPORT_API notification_error_e notification_set_image(notification_h noti,
253 notification_image_type_e type,
254 const char *image_path)
257 char buf_key[32] = { 0, };
258 const char *ret_val = NULL;
260 /* Check noti and image_path are valid data */
261 if (noti == NULL || image_path == NULL) {
262 return NOTIFICATION_ERROR_INVALID_DATA;
265 /* Check image type is valid type */
266 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
267 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
268 return NOTIFICATION_ERROR_INVALID_DATA;
271 /* Check image path bundle is exist */
272 if (noti->b_image_path) {
273 /* If image path bundle is exist, store local bundle value */
274 b = noti->b_image_path;
276 /* Set image type to key as char string type */
277 snprintf(buf_key, sizeof(buf_key), "%d", type);
279 /* Get value using key */
280 ret_val = bundle_get_val(b, buf_key);
281 if (ret_val != NULL) {
282 /* If key is exist, remove this value to store new image path */
283 bundle_del(b, buf_key);
286 /* Add new image path with type key */
287 bundle_add(b, buf_key, image_path);
289 /* If image path bundle is not exist, create new one */
292 /* Set image type to key as char string type */
293 snprintf(buf_key, sizeof(buf_key), "%d", type);
295 /* Add new image path with type key */
296 bundle_add(b, buf_key, image_path);
298 /* Save to image path bundle */
299 noti->b_image_path = b;
302 return NOTIFICATION_ERROR_NONE;
305 EXPORT_API notification_error_e notification_get_image(notification_h noti,
306 notification_image_type_e type,
310 char buf_key[32] = { 0, };
311 const char *ret_val = NULL;
312 const char *pkgname = NULL;
314 /* Check noti and image_path is valid data */
315 if (noti == NULL || image_path == NULL) {
316 return NOTIFICATION_ERROR_INVALID_DATA;
319 /* Check image type is valid data */
320 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
321 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
322 return NOTIFICATION_ERROR_INVALID_DATA;
325 /* Check image path bundle exist */
326 if (noti->b_image_path) {
327 /* If image path bundle exist, store local bundle data */
328 b = noti->b_image_path;
330 /* Set image type to key as char string type */
331 snprintf(buf_key, sizeof(buf_key), "%d", type);
333 /* Get value of key */
334 ret_val = bundle_get_val(b, buf_key);
336 *image_path = (char *)ret_val;
338 /* If image path bundle does not exist, image path is NULL */
342 /* If image path is NULL and type is ICON, icon path set from AIL */
343 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
344 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
345 /* Check App icon path is already set */
346 if (noti->app_icon_path != NULL) {
347 /* image path will be app icon path */
348 *image_path = noti->app_icon_path;
350 /* Get image path using launch_pkgname */
351 if (noti->launch_pkgname != NULL) {
352 noti->app_icon_path =
353 _notification_get_icon(noti->launch_pkgname);
356 /* If app icon path is NULL, get image path using caller_pkgname */
357 if (noti->app_icon_path == NULL
358 && noti->caller_pkgname != NULL) {
359 noti->app_icon_path =
360 _notification_get_icon(noti->caller_pkgname);
363 /* If app icon path is NULL, get image path using service data */
364 if (noti->app_icon_path == NULL
365 && noti->b_service_single_launch != NULL) {
367 appsvc_get_pkgname(noti->b_service_single_launch);
368 if (pkgname != NULL) {
369 noti->app_icon_path =
370 _notification_get_icon(pkgname);
374 *image_path = noti->app_icon_path;
378 return NOTIFICATION_ERROR_NONE;
381 EXPORT_API notification_error_e notification_set_time(notification_h noti,
384 /* Check noti is valid data */
386 return NOTIFICATION_ERROR_INVALID_DATA;
389 if (input_time == 0) {
390 /* If input time is 0, set current time */
391 noti->time = time(NULL);
393 /* save input time */
394 noti->time = input_time;
397 return NOTIFICATION_ERROR_NONE;
400 EXPORT_API notification_error_e notification_get_time(notification_h noti,
403 /* Check noti and time is valid data */
404 if (noti == NULL || ret_time == NULL) {
405 return NOTIFICATION_ERROR_INVALID_DATA;
408 /* Set time infomation */
409 *ret_time = noti->time;
411 return NOTIFICATION_ERROR_NONE;
414 EXPORT_API notification_error_e notification_get_insert_time(notification_h noti,
417 /* Check noti and ret_time is valid data */
418 if (noti == NULL || ret_time == NULL) {
419 return NOTIFICATION_ERROR_INVALID_DATA;
422 /* Set insert time information */
423 *ret_time = noti->insert_time;
425 return NOTIFICATION_ERROR_NONE;
428 EXPORT_API notification_error_e notification_set_title(notification_h noti,
430 const char *loc_title)
432 int noti_err = NOTIFICATION_ERROR_NONE;
434 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
436 NOTIFICATION_VARIABLE_TYPE_NONE);
441 EXPORT_API notification_error_e notification_get_title(notification_h noti,
445 int noti_err = NOTIFICATION_ERROR_NONE;
446 char *ret_text = NULL;
449 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
456 if (loc_title != NULL) {
463 EXPORT_API notification_error_e notification_set_group_title(const char *pkgname,
466 const char *loc_title,
467 notification_count_display_type_e count_display)
469 char *caller_pkgname = NULL;
470 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
472 if ((title == NULL && loc_title == NULL)) {
473 return NOTIFICATION_ERROR_INVALID_DATA;
476 if (group_id < NOTIFICATION_GROUP_ID_DEFAULT) {
477 return NOTIFICATION_ERROR_INVALID_DATA;
480 if (pkgname == NULL) {
481 caller_pkgname = _notification_get_pkgname_by_pid();
484 notification_group_set_title(caller_pkgname, group_id,
488 if (caller_pkgname != NULL) {
489 free(caller_pkgname);
493 notification_group_set_title(pkgname, group_id, title,
494 loc_title, count_display);
500 EXPORT_API notification_error_e notification_get_group_title(const char *pkgname,
504 notification_count_display_type_e *count_display)
506 char *caller_pkgname = NULL;
507 char *ret_title = NULL;
508 char *ret_loc_title = NULL;
509 notification_count_display_type_e ret_count_display;
510 int ret = NOTIFICATION_ERROR_NONE;
512 if (pkgname == NULL) {
513 caller_pkgname = _notification_get_pkgname_by_pid();
516 notification_group_get_title(caller_pkgname, group_id,
517 &ret_title, &ret_loc_title,
520 if (caller_pkgname != NULL) {
521 free(caller_pkgname);
525 notification_group_get_title(pkgname, group_id, &ret_title,
530 if (ret != NOTIFICATION_ERROR_NONE) {
535 *loc_title = ret_loc_title;
536 *count_display = ret_count_display;
538 return NOTIFICATION_ERROR_NONE;
541 EXPORT_API notification_error_e notification_set_content(notification_h noti,
543 const char *loc_content)
545 int noti_err = NOTIFICATION_ERROR_NONE;
547 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
548 content, loc_content,
549 NOTIFICATION_VARIABLE_TYPE_NONE);
554 EXPORT_API notification_error_e notification_get_content(notification_h noti,
558 int noti_err = NOTIFICATION_ERROR_NONE;
559 char *ret_text = NULL;
562 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
565 if (content != NULL) {
569 if (loc_content != NULL) {
578 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
580 if (ret == -1 || boolval == 0) {
581 if (content != NULL && noti->default_content != NULL) {
582 *content = noti->default_content;
585 if (loc_content != NULL && noti->loc_default_content != NULL) {
586 *loc_content = noti->loc_default_content;
592 EXPORT_API notification_error_e notification_set_default_content(notification_h noti,
594 const char *loc_content)
596 int noti_err = NOTIFICATION_ERROR_NONE;
599 notification_set_text(noti,
600 NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF,
601 content, loc_content,
602 NOTIFICATION_VARIABLE_TYPE_NONE);
607 EXPORT_API notification_error_e notification_get_default_content(notification_h noti,
611 int noti_err = NOTIFICATION_ERROR_NONE;
612 char *ret_text = NULL;
615 notification_get_text(noti,
616 NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF,
619 if (content != NULL) {
623 if (loc_content != NULL) {
630 EXPORT_API notification_error_e notification_set_group_content(const char *pkgname,
633 const char *loc_content,
634 notification_count_display_type_e count_display)
636 const char *caller_pkgname = NULL;
637 if ((content == NULL && loc_content == NULL)) {
638 return NOTIFICATION_ERROR_INVALID_DATA;
641 if (group_id < NOTIFICATION_GROUP_ID_DEFAULT) {
642 return NOTIFICATION_ERROR_INVALID_DATA;
646 caller_pkgname = _notification_get_pkgname_by_pid();
648 caller_pkgname = pkgname;
650 notification_group_set_content(caller_pkgname, group_id, content,
651 loc_content, count_display);
653 return NOTIFICATION_ERROR_NONE;
656 EXPORT_API notification_error_e notification_get_group_content(const char *pkgname,
660 notification_count_display_type_e *count_display)
662 const char *caller_pkgname = NULL;
663 char *ret_content = NULL;
664 char *ret_loc_content = NULL;
665 notification_count_display_type_e ret_count_display;
666 int ret = NOTIFICATION_ERROR_NONE;
669 caller_pkgname = _notification_get_pkgname_by_pid();
671 caller_pkgname = pkgname;
674 notification_group_get_content(caller_pkgname, group_id,
675 &ret_content, &ret_loc_content,
677 if (ret != NOTIFICATION_ERROR_NONE) {
681 *content = ret_content;
682 *loc_content = ret_loc_content;
683 *count_display = ret_count_display;
685 return NOTIFICATION_ERROR_NONE;
688 EXPORT_API notification_error_e notification_set_text(notification_h noti,
689 notification_text_type_e type,
695 char buf_key[32] = { 0, };
696 char buf_val[1024] = { 0, };
697 const char *ret_val = NULL;
699 notification_variable_type_e var_type;
701 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
702 int var_value_int = 0;
703 double var_value_double = 0.0;
704 char *var_value_string = NULL;
705 notification_count_pos_type_e var_value_count =
706 NOTIFICATION_COUNT_POS_NONE;
708 /* Check noti is valid data */
710 return NOTIFICATION_ERROR_INVALID_DATA;
713 /* Check text type is valid type */
714 if (type <= NOTIFICATION_TEXT_TYPE_NONE
715 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
716 return NOTIFICATION_ERROR_INVALID_DATA;
719 /* Check text bundle exist */
721 if (noti->b_text != NULL) {
722 /* If text bundle exist, store local bundle data */
725 /* Make type to key as char string */
726 snprintf(buf_key, sizeof(buf_key), "%d", type);
728 /* Get value using type key */
729 ret_val = bundle_get_val(b, buf_key);
730 if (ret_val != NULL) {
731 /* If value exist, remove this to add new value */
732 bundle_del(b, buf_key);
735 snprintf(buf_val, sizeof(buf_val), "%s", text);
737 /* Add new text value */
738 bundle_add(b, buf_key, buf_val);
740 /* If text bundle does not exist, create new one */
743 /* Make type to key as char string */
744 snprintf(buf_key, sizeof(buf_key), "%d", type);
746 snprintf(buf_val, sizeof(buf_val), "%s", text);
748 /* Add new text value */
749 bundle_add(b, buf_key, buf_val);
751 /* Save text bundle */
756 /* Save key if key is valid data */
758 /* Check key bundle exist */
759 if (noti->b_key != NULL) {
760 /* If key bundle exist, store local bundle data */
763 /* Make type to key as char string */
764 snprintf(buf_key, sizeof(buf_key), "%d", type);
766 /* Get value using type key */
767 ret_val = bundle_get_val(b, buf_key);
768 if (ret_val != NULL) {
769 /* If value exist, remove this to add new value */
770 bundle_del(b, buf_key);
773 snprintf(buf_val, sizeof(buf_val), "%s", key);
775 /* Add new key value */
776 bundle_add(b, buf_key, buf_val);
778 /* If key bundle does not exist, create new one */
781 /* Make type to key as char string */
782 snprintf(buf_key, sizeof(buf_key), "%d", type);
784 snprintf(buf_val, sizeof(buf_val), "%s", key);
786 /* Add new key value */
787 bundle_add(b, buf_key, buf_val);
789 /* Save key bundle */
794 if (noti->b_format_args != NULL) {
795 b = noti->b_format_args;
800 va_start(var_args, args_type);
802 var_type = args_type;
805 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
807 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
808 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
810 ret_val = bundle_get_val(b, buf_key);
811 if (ret_val != NULL) {
812 bundle_del(b, buf_key);
815 bundle_add(b, buf_key, buf_val);
818 case NOTIFICATION_VARIABLE_TYPE_INT:
819 var_value_int = va_arg(var_args, int);
822 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
824 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
826 ret_val = bundle_get_val(b, buf_key);
827 if (ret_val != NULL) {
828 bundle_del(b, buf_key);
831 bundle_add(b, buf_key, buf_val);
833 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
834 var_value_double = va_arg(var_args, double);
837 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
839 snprintf(buf_val, sizeof(buf_val), "%.2f",
842 ret_val = bundle_get_val(b, buf_key);
843 if (ret_val != NULL) {
844 bundle_del(b, buf_key);
847 bundle_add(b, buf_key, buf_val);
849 case NOTIFICATION_VARIABLE_TYPE_STRING:
850 var_value_string = va_arg(var_args, char *);
853 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
855 snprintf(buf_val, sizeof(buf_val), "%s",
858 ret_val = bundle_get_val(b, buf_key);
859 if (ret_val != NULL) {
860 bundle_del(b, buf_key);
863 bundle_add(b, buf_key, buf_val);
865 case NOTIFICATION_VARIABLE_TYPE_COUNT:
867 va_arg(var_args, notification_count_pos_type_e);
870 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
872 snprintf(buf_val, sizeof(buf_val), "%d",
875 ret_val = bundle_get_val(b, buf_key);
876 if (ret_val != NULL) {
877 bundle_del(b, buf_key);
880 bundle_add(b, buf_key, buf_val);
883 NOTIFICATION_ERR("Error. invalid variable type. : %d",
885 noti_err = NOTIFICATION_ERROR_INVALID_DATA;
890 var_type = va_arg(var_args, notification_variable_type_e);
894 if (noti_err == NOTIFICATION_ERROR_NONE) {
895 noti->num_format_args = num_args;
897 noti->num_format_args = 0;
900 snprintf(buf_key, sizeof(buf_key), "num%d", type);
901 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
903 ret_val = bundle_get_val(b, buf_key);
904 if (ret_val != NULL) {
905 bundle_del(b, buf_key);
908 bundle_add(b, buf_key, buf_val);
910 noti->b_format_args = b;
915 EXPORT_API notification_error_e notification_get_text(notification_h noti,
916 notification_text_type_e type,
920 char buf_key[32] = { 0, };
921 const char *ret_val = NULL;
922 const char *pkgname = NULL;
923 const char *get_str = NULL;
924 const char *get_check_type_str = NULL;
927 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
928 int display_option_flag = 0;
930 char *temp_str = NULL;
931 char result_str[1024] = { 0, };
932 char buf_str[1024] = { 0, };
934 notification_variable_type_e ret_var_type = 0;
935 int ret_variable_int = 0;
936 double ret_variable_double = 0.0;
938 /* Check noti is valid data */
939 if (noti == NULL || text == NULL) {
940 return NOTIFICATION_ERROR_INVALID_DATA;
943 /* Check text type is valid type */
944 if (type <= NOTIFICATION_TEXT_TYPE_NONE
945 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
946 return NOTIFICATION_ERROR_INVALID_DATA;
949 /* Check content display option of setting */
950 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
951 || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
954 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL,
956 if (ret == -1 || boolval == 0) {
957 /* Set flag as display option is OFF */
958 display_option_flag = 1;
963 if (noti->b_key != NULL) {
966 /* Get text domain and dir */
967 _notification_get_text_domain(noti);
969 snprintf(buf_key, sizeof(buf_key), "%d", type);
971 ret_val = bundle_get_val(b, buf_key);
972 if (ret_val != NULL && noti->domain != NULL
973 && noti->dir != NULL) {
974 /* Get application string */
975 bindtextdomain(noti->domain, noti->dir);
977 get_str = dgettext(noti->domain, ret_val);
978 } else if (ret_val != NULL) {
979 /* Get system string */
980 get_str = dgettext("sys_string", ret_val);
986 if (get_str == NULL && noti->b_text != NULL) {
989 snprintf(buf_key, sizeof(buf_key), "%d", type);
991 get_str = bundle_get_val(b, buf_key);
996 /* Set display option is off type when option is off, type is noti */
997 if (get_str != NULL && display_option_flag == 1
998 && noti->type == NOTIFICATION_TYPE_NOTI) {
999 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
1000 || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
1001 /* Set check_type to option content string */
1002 if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
1004 NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
1005 } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
1007 NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
1011 if (noti->b_key != NULL) {
1014 /* Get text domain and dir */
1015 _notification_get_text_domain(noti);
1017 snprintf(buf_key, sizeof(buf_key), "%d",
1020 ret_val = bundle_get_val(b, buf_key);
1021 if (ret_val != NULL && noti->domain != NULL
1022 && noti->dir != NULL) {
1023 /* Get application string */
1024 bindtextdomain(noti->domain, noti->dir);
1026 get_check_type_str =
1027 dgettext(noti->domain, ret_val);
1028 } else if (ret_val != NULL) {
1029 /* Get system string */
1030 get_check_type_str =
1031 dgettext("sys_string", ret_val);
1033 get_check_type_str = NULL;
1037 if (get_check_type_str == NULL && noti->b_text != NULL) {
1039 /* Get basic text */
1040 snprintf(buf_key, sizeof(buf_key), "%d",
1043 get_check_type_str = bundle_get_val(b, buf_key);
1047 if (get_check_type_str != NULL) {
1048 /* Replace option off type string */
1049 get_str = get_check_type_str;
1051 /* Set default string */
1053 dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
1057 if (get_str != NULL) {
1058 /* Get number format args */
1059 b = noti->b_format_args;
1060 noti->num_format_args = 0;
1063 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
1064 ret_val = bundle_get_val(b, buf_key);
1065 if (ret_val != NULL) {
1066 noti->num_format_args = atoi(ret_val);
1070 if (noti->num_format_args == 0) {
1071 *text = (char *)get_str;
1073 /* Check first variable is count, LEFT pos */
1074 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1075 check_type, num_args);
1076 ret_val = bundle_get_val(b, buf_key);
1077 ret_var_type = atoi(ret_val);
1079 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
1081 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
1082 check_type, num_args);
1083 ret_val = bundle_get_val(b, buf_key);
1084 ret_variable_int = atoi(ret_val);
1086 if (ret_variable_int ==
1087 NOTIFICATION_COUNT_POS_LEFT) {
1088 notification_noti_get_count(noti->type,
1089 noti->caller_pkgname,
1093 snprintf(buf_str, sizeof(buf_str),
1094 "%d ", ret_variable_int);
1095 strncat(result_str, buf_str,
1096 sizeof(result_str));
1103 /* Check variable IN pos */
1104 for (temp_str = (char *)get_str; *temp_str != '\0';
1106 if (*temp_str != '%') {
1107 strncat(result_str, temp_str, 1);
1109 if (*(temp_str + 1) == '%') {
1110 strncat(result_str, temp_str,
1112 } else if (*(temp_str + 1) == 'd') {
1114 ret_variable_int = 0;
1118 "%dtype%d", check_type,
1121 bundle_get_val(b, buf_key);
1122 ret_var_type = atoi(ret_val);
1124 NOTIFICATION_VARIABLE_TYPE_COUNT)
1126 /* Get notification count */
1127 notification_noti_get_count
1129 noti->caller_pkgname,
1149 sizeof(buf_str), "%d",
1151 strncat(result_str, buf_str,
1152 sizeof(result_str));
1157 } else if (*(temp_str + 1) == 's') {
1162 check_type, num_args);
1164 bundle_get_val(b, buf_key);
1167 sizeof(buf_str), "%s",
1169 strncat(result_str, buf_str,
1170 sizeof(result_str));
1175 } else if (*(temp_str + 1) == 'f') {
1180 check_type, num_args);
1182 bundle_get_val(b, buf_key);
1183 ret_variable_double =
1189 ret_variable_double);
1190 strncat(result_str, buf_str,
1191 sizeof(result_str));
1201 /* Check last variable is count, LEFT pos */
1202 if (num_args < noti->num_format_args) {
1203 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1204 check_type, num_args);
1205 ret_val = bundle_get_val(b, buf_key);
1206 ret_var_type = atoi(ret_val);
1208 NOTIFICATION_VARIABLE_TYPE_COUNT) {
1210 snprintf(buf_key, sizeof(buf_key),
1211 "%dvalue%d", check_type,
1213 ret_val = bundle_get_val(b, buf_key);
1214 ret_variable_int = atoi(ret_val);
1216 if (ret_variable_int ==
1217 NOTIFICATION_COUNT_POS_RIGHT) {
1218 notification_noti_get_count
1220 noti->caller_pkgname,
1225 sizeof(buf_str), " %d",
1227 strncat(result_str, buf_str,
1228 sizeof(result_str));
1236 switch (check_type) {
1237 case NOTIFICATION_TEXT_TYPE_TITLE:
1238 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
1239 if (noti->temp_title != NULL)
1240 free(noti->temp_title);
1242 noti->temp_title = strdup(result_str);
1244 *text = noti->temp_title;
1246 case NOTIFICATION_TEXT_TYPE_CONTENT:
1247 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1248 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
1249 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1250 if (noti->temp_content !=
1252 free(noti->temp_content);
1254 noti->temp_content = strdup(result_str);
1256 *text = noti->temp_content;
1265 if (check_type == NOTIFICATION_TEXT_TYPE_TITLE
1266 || check_type == NOTIFICATION_TEXT_TYPE_GROUP_TITLE) {
1267 /* Remove app name if exist, because pkgname is changed according to language setting */
1268 if (noti->app_name != NULL) {
1269 free(noti->app_name);
1270 noti->app_name = NULL;
1273 /* First, get app name from launch_pkgname */
1274 if (noti->launch_pkgname != NULL) {
1276 _notification_get_name(noti->
1280 /* Second, get app name from caller_pkgname */
1281 if (noti->app_name == NULL
1282 && noti->caller_pkgname != NULL) {
1284 _notification_get_name(noti->
1288 /* Third, get app name from service data */
1289 if (noti->app_name == NULL
1290 && noti->b_service_single_launch != NULL) {
1292 appsvc_get_pkgname(noti->
1293 b_service_single_launch);
1295 if (pkgname != NULL) {
1297 _notification_get_name(pkgname);
1301 *text = noti->app_name;
1307 NOTIFICATION_INFO("Get text : %s", *text);
1309 return NOTIFICATION_ERROR_NONE;
1312 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
1316 /* check noti and domain is valid data */
1317 if (noti == NULL || domain == NULL) {
1318 return NOTIFICATION_ERROR_INVALID_DATA;
1323 /* Remove previous domain */
1327 noti->domain = strdup(domain);
1329 /* Check locale dir */
1331 /* Remove previous locale dir */
1334 /* Copy locale dir */
1335 noti->dir = strdup(dir);
1337 return NOTIFICATION_ERROR_NONE;
1340 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
1344 /* Check noti is valid data */
1346 return NOTIFICATION_ERROR_INVALID_DATA;
1350 if (domain != NULL && noti->domain != NULL) {
1351 *domain = noti->domain;
1354 /* Get locale dir */
1355 if (dir != NULL && noti->dir != NULL) {
1359 return NOTIFICATION_ERROR_NONE;
1362 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1363 notification_sound_type_e type,
1366 /* Check noti is valid data */
1368 return NOTIFICATION_ERROR_INVALID_DATA;
1371 /* Check type is valid */
1372 if (type < NOTIFICATION_SOUND_TYPE_NONE
1373 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1374 return NOTIFICATION_ERROR_INVALID_DATA;
1377 /* Save sound type */
1378 noti->sound_type = type;
1380 /* Save sound path if user data type */
1381 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1382 if (noti->sound_path != NULL) {
1383 free(noti->sound_path);
1386 noti->sound_path = strdup(path);
1388 if (noti->sound_path != NULL) {
1389 free(noti->sound_path);
1390 noti->sound_path = NULL;
1394 return NOTIFICATION_ERROR_NONE;
1397 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1398 notification_sound_type_e *type,
1401 /* check noti and type is valid data */
1402 if (noti == NULL || type == NULL) {
1403 return NOTIFICATION_ERROR_INVALID_DATA;
1406 /* Set sound type */
1407 *type = noti->sound_type;
1409 /* Set sound path if user data type */
1410 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1412 *path = noti->sound_path;
1415 return NOTIFICATION_ERROR_NONE;
1418 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1419 notification_vibration_type_e type,
1422 /* Check noti is valid data */
1424 return NOTIFICATION_ERROR_INVALID_DATA;
1427 /* Check type is valid */
1428 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1429 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1430 return NOTIFICATION_ERROR_INVALID_DATA;
1433 /* Save vibration type */
1434 noti->vibration_type = type;
1436 /* Save sound path if user data type */
1437 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1438 if (noti->vibration_path != NULL) {
1439 free(noti->vibration_path);
1442 noti->vibration_path = strdup(path);
1444 if (noti->vibration_path != NULL) {
1445 free(noti->vibration_path);
1446 noti->vibration_path = NULL;
1450 return NOTIFICATION_ERROR_NONE;
1454 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1455 notification_vibration_type_e *type,
1458 /* check noti and type is valid data */
1459 if (noti == NULL || type == NULL) {
1460 return NOTIFICATION_ERROR_INVALID_DATA;
1463 /* Set vibration type */
1464 *type = noti->vibration_type;
1466 /* Set sound path if user data type */
1467 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1469 *path = noti->vibration_path;
1472 return NOTIFICATION_ERROR_NONE;
1475 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1476 const char *pkgname)
1478 if (noti == NULL || pkgname == NULL) {
1479 return NOTIFICATION_ERROR_INVALID_DATA;
1482 if (noti->launch_pkgname) {
1483 free(noti->launch_pkgname);
1486 noti->launch_pkgname = strdup(pkgname);
1488 return NOTIFICATION_ERROR_NONE;
1491 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1494 if (noti == NULL || pkgname == NULL) {
1495 return NOTIFICATION_ERROR_INVALID_DATA;
1498 if (noti->launch_pkgname) {
1499 *pkgname = noti->launch_pkgname;
1501 *pkgname = noti->caller_pkgname;
1504 return NOTIFICATION_ERROR_NONE;
1507 EXPORT_API notification_error_e notification_set_args(notification_h noti,
1509 bundle * group_args)
1511 if (noti == NULL || args == NULL) {
1512 return NOTIFICATION_ERROR_INVALID_DATA;
1516 bundle_free(noti->args);
1519 noti->args = bundle_dup(args);
1521 if (noti->group_args) {
1522 bundle_free(noti->group_args);
1523 noti->group_args = NULL;
1526 if (group_args != NULL) {
1527 noti->group_args = bundle_dup(group_args);
1530 return NOTIFICATION_ERROR_NONE;
1533 EXPORT_API notification_error_e notification_get_args(notification_h noti,
1535 bundle ** group_args)
1537 if (noti == NULL || args == NULL) {
1538 return NOTIFICATION_ERROR_INVALID_DATA;
1547 if (group_args != NULL && noti->group_args) {
1548 *group_args = noti->group_args;
1551 return NOTIFICATION_ERROR_NONE;
1554 EXPORT_API notification_error_e notification_set_service_data(notification_h noti,
1555 bundle * service_data,
1556 bundle * group_service_data)
1558 int noti_err = NOTIFICATION_ERROR_NONE;
1561 notification_set_execute_option(noti,
1562 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1563 NULL, NULL, service_data);
1564 if (noti_err != NOTIFICATION_ERROR_NONE) {
1569 notification_set_execute_option(noti,
1570 NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH,
1571 NULL, NULL, group_service_data);
1576 EXPORT_API notification_error_e notification_get_service_data(notification_h noti,
1577 bundle ** service_data,
1578 bundle ** group_service_data)
1580 int noti_err = NOTIFICATION_ERROR_NONE;
1581 bundle *get_service_data = NULL;
1584 notification_get_execute_option(noti,
1585 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1586 NULL, &get_service_data);
1587 if (noti_err != NOTIFICATION_ERROR_NONE) {
1591 if (service_data != NULL) {
1592 *service_data = get_service_data;
1596 notification_get_execute_option(noti,
1597 NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH,
1598 NULL, &get_service_data);
1599 if (noti_err != NOTIFICATION_ERROR_NONE) {
1603 if (service_data != NULL) {
1604 *group_service_data = get_service_data;
1607 return NOTIFICATION_ERROR_NONE;
1610 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1611 notification_execute_type_e type,
1614 bundle *service_handle)
1616 char buf_key[32] = { 0, };
1617 const char *ret_val = NULL;
1621 return NOTIFICATION_ERROR_INVALID_DATA;
1624 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1625 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1626 return NOTIFICATION_ERROR_INVALID_DATA;
1629 /* Create execute option bundle if does not exist */
1630 if (noti->b_execute_option != NULL) {
1631 noti->b_execute_option = bundle_create();
1634 b = noti->b_execute_option;
1639 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1641 /* Check text key exist */
1642 ret_val = bundle_get_val(b, buf_key);
1643 if (ret_val != NULL) {
1644 /* Remove previous data */
1645 bundle_del(b, buf_key);
1649 bundle_add(b, buf_key, text);
1655 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1657 /* Check key key exist */
1658 ret_val = bundle_get_val(b, buf_key);
1659 if (ret_val != NULL) {
1660 /* Remove previous data */
1661 bundle_del(b, buf_key);
1665 bundle_add(b, buf_key, key);
1669 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1670 /* Remove previous data if exist */
1671 if (noti->b_service_responding != NULL) {
1672 bundle_free(noti->b_service_responding);
1673 noti->b_service_responding = NULL;
1676 /* Save service handle */
1677 if (service_handle != NULL) {
1678 noti->b_service_responding = bundle_dup(service_handle);
1681 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1682 /* Remove previous data if exist */
1683 if (noti->b_service_single_launch != NULL) {
1684 bundle_free(noti->b_service_single_launch);
1685 noti->b_service_single_launch = NULL;
1688 /* Save service handle */
1689 if (service_handle != NULL) {
1690 noti->b_service_single_launch =
1691 bundle_dup(service_handle);
1694 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1695 /* Remove previous data if exist */
1696 if (noti->b_service_multi_launch != NULL) {
1697 bundle_free(noti->b_service_multi_launch);
1698 noti->b_service_multi_launch = NULL;
1701 /* Save service handle */
1702 if (service_handle != NULL) {
1703 noti->b_service_multi_launch =
1704 bundle_dup(service_handle);
1711 return NOTIFICATION_ERROR_NONE;
1714 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1715 notification_execute_type_e type,
1717 bundle **service_handle)
1719 char buf_key[32] = { 0, };
1720 const char *ret_val = NULL;
1721 char *get_str = NULL;
1725 return NOTIFICATION_ERROR_INVALID_DATA;
1728 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1729 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1730 return NOTIFICATION_ERROR_INVALID_DATA;
1734 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1735 b = noti->b_service_responding;
1737 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1738 b = noti->b_service_single_launch;
1740 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1741 b = noti->b_service_multi_launch;
1751 // Get text domain and dir
1752 if (noti->domain == NULL || noti->dir == NULL) {
1753 _notification_get_text_domain(noti);
1757 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1759 /* Check key key exist */
1760 ret_val = bundle_get_val(b, buf_key);
1761 if (ret_val != NULL && noti->domain != NULL
1762 && noti->dir != NULL) {
1763 /* Get application string */
1764 bindtextdomain(noti->domain, noti->dir);
1766 get_str = dgettext(noti->domain, ret_val);
1769 } else if (ret_val != NULL) {
1770 /* Get system string */
1771 get_str = dgettext("sys_string", ret_val);
1775 /* Get basic text */
1776 snprintf(buf_key, sizeof(buf_key), "text%d",
1779 ret_val = bundle_get_val(b, buf_key);
1787 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1788 b = noti->b_service_responding;
1790 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1791 b = noti->b_service_single_launch;
1793 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1794 b = noti->b_service_multi_launch;
1801 if (service_handle != NULL) {
1802 *service_handle = b;
1805 return NOTIFICATION_ERROR_NONE;
1808 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1811 /* Check noti is valid data */
1813 return NOTIFICATION_ERROR_INVALID_DATA;
1817 noti->flags_for_property = flags;
1819 return NOTIFICATION_ERROR_NONE;
1822 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1825 /* Check noti and flags are valid data */
1826 if (noti == NULL || flags == NULL) {
1827 return NOTIFICATION_ERROR_INVALID_DATA;
1831 *flags = noti->flags_for_property;
1833 return NOTIFICATION_ERROR_NONE;
1836 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1839 /* Check noti is valid data */
1841 return NOTIFICATION_ERROR_INVALID_DATA;
1845 noti->display_applist = applist;
1847 return NOTIFICATION_ERROR_NONE;
1850 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1853 /* Check noti and applist are valid data */
1854 if (noti == NULL || applist == NULL) {
1855 return NOTIFICATION_ERROR_INVALID_DATA;
1859 *applist = noti->display_applist;
1861 return NOTIFICATION_ERROR_NONE;
1864 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1867 /* Check noti is valid data */
1869 return NOTIFICATION_ERROR_INVALID_DATA;
1872 /* Save progress size */
1873 noti->progress_size = size;
1875 return NOTIFICATION_ERROR_NONE;
1878 EXPORT_API notification_error_e notification_get_size(notification_h noti,
1881 /* Check noti and size is valid data */
1882 if (noti == NULL || size == NULL) {
1883 return NOTIFICATION_ERROR_INVALID_DATA;
1886 /* Set progress size */
1887 *size = noti->progress_size;
1889 return NOTIFICATION_ERROR_NONE;
1892 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
1895 /* Check noti is valid data */
1897 return NOTIFICATION_ERROR_INVALID_DATA;
1900 /* Save progress percentage */
1901 noti->progress_percentage = percentage;
1903 return NOTIFICATION_ERROR_NONE;
1906 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
1909 /* Check noti and percentage are valid data */
1910 if (noti == NULL || percentage == NULL) {
1911 return NOTIFICATION_ERROR_INVALID_DATA;
1914 /* Set progress percentage */
1915 *percentage = noti->progress_percentage;
1917 return NOTIFICATION_ERROR_NONE;
1920 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
1921 const char *pkgname)
1923 /* check noti and pkgname are valid data */
1924 if (noti == NULL || pkgname == NULL) {
1925 return NOTIFICATION_ERROR_INVALID_DATA;
1928 /* Remove previous caller pkgname */
1929 if (noti->caller_pkgname) {
1930 free(noti->caller_pkgname);
1931 noti->caller_pkgname = NULL;
1934 noti->caller_pkgname = strdup(pkgname);
1936 return NOTIFICATION_ERROR_NONE;
1939 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
1942 /* Check noti and pkgname are valid data */
1943 if (noti == NULL || pkgname == NULL) {
1944 return NOTIFICATION_ERROR_INVALID_DATA;
1947 /* Get caller pkgname */
1948 if (noti->caller_pkgname) {
1949 *pkgname = noti->caller_pkgname;
1954 return NOTIFICATION_ERROR_NONE;
1957 EXPORT_API notification_error_e notification_set_unread_count(const char *pkgname,
1961 int ret = NOTIFICATION_ERROR_NONE;
1963 ret = notification_set_badge(pkgname, group_id, unread_count);
1968 EXPORT_API notification_error_e notification_get_unread_count(const char *pkgname,
1972 int ret = NOTIFICATION_ERROR_NONE;
1973 int ret_unread_count = 0;
1975 ret = notification_get_badge(pkgname, group_id, &ret_unread_count);
1977 if (unread_count != NULL) {
1978 *unread_count = ret_unread_count;
1984 EXPORT_API notification_error_e notification_set_badge(const char *pkgname,
1985 int group_id, int count)
1987 char *caller_pkgname = NULL;
1988 int ret = NOTIFICATION_ERROR_NONE;
1990 /* Check count is valid count */
1992 return NOTIFICATION_ERROR_INVALID_DATA;
1996 if (pkgname == NULL) {
1997 caller_pkgname = _notification_get_pkgname_by_pid();
1999 /* Set count into Group DB */
2001 notification_group_set_badge(caller_pkgname, group_id,
2004 if (caller_pkgname != NULL) {
2005 free(caller_pkgname);
2008 /* Set count into Group DB */
2009 ret = notification_group_set_badge(pkgname, group_id, count);
2015 EXPORT_API notification_error_e notification_get_badge(const char *pkgname,
2016 int group_id, int *count)
2018 char *caller_pkgname = NULL;
2019 int ret = NOTIFICATION_ERROR_NONE;
2020 int ret_unread_count = 0;
2023 if (pkgname == NULL) {
2024 caller_pkgname = _notification_get_pkgname_by_pid();
2026 /* Get count from Group DB */
2028 notification_group_get_badge(caller_pkgname, group_id,
2031 if (caller_pkgname != NULL) {
2032 free(caller_pkgname);
2035 /* Get count from Group DB */
2037 notification_group_get_badge(pkgname, group_id,
2041 if (ret != NOTIFICATION_ERROR_NONE) {
2046 if (count != NULL) {
2047 *count = ret_unread_count;
2050 return NOTIFICATION_ERROR_NONE;
2053 EXPORT_API notification_error_e notification_get_id(notification_h noti,
2054 int *group_id, int *priv_id)
2056 /* check noti is valid data */
2058 return NOTIFICATION_ERROR_INVALID_DATA;
2061 /* Check group_id is valid data */
2064 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
2065 *group_id = NOTIFICATION_GROUP_ID_NONE;
2067 *group_id = noti->group_id;
2071 /* Check priv_id is valid data */
2074 *priv_id = noti->priv_id;
2077 return NOTIFICATION_ERROR_NONE;
2080 EXPORT_API notification_error_e notification_get_type(notification_h noti,
2081 notification_type_e *type)
2083 /* Check noti and type is valid data */
2084 if (noti == NULL || type == NULL) {
2085 return NOTIFICATION_ERROR_INVALID_DATA;
2091 return NOTIFICATION_ERROR_NONE;
2094 EXPORT_API notification_error_e notification_insert(notification_h noti,
2099 /* Check noti is vaild data */
2101 return NOTIFICATION_ERROR_INVALID_DATA;
2104 /* Check noti type is valid type */
2105 if (noti->type <= NOTIFICATION_TYPE_NONE
2106 || noti->type >= NOTIFICATION_TYPE_MAX) {
2107 return NOTIFICATION_ERROR_INVALID_DATA;
2110 /* Save insert time */
2111 noti->insert_time = time(NULL);
2113 /* Insert into DB */
2114 ret = notification_noti_insert(noti);
2115 if (ret != NOTIFICATION_ERROR_NONE) {
2119 /* Check disable update on insert property */
2120 if (noti->flags_for_property
2121 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
2122 /* Disable changed cb */
2124 /* Enable changed cb */
2125 _notification_changed(NOTI_CHANGED_NOTI);
2128 /* If priv_id is valid data, set priv_id */
2129 if (priv_id != NULL) {
2130 *priv_id = noti->priv_id;
2133 return NOTIFICATION_ERROR_NONE;
2136 EXPORT_API notification_error_e notification_update(notification_h noti)
2138 /* Check noti is valid data */
2140 /* TODO : Update noti */
2143 /* Send changed notification */
2144 _notification_changed(NOTI_CHANGED_NOTI);
2146 return NOTIFICATION_ERROR_NONE;
2149 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
2153 /* Delete all notification of type */
2154 ret = notification_noti_delete_all(type, NULL);
2155 if (ret != NOTIFICATION_ERROR_NONE) {
2159 /* Send chagned notification */
2160 _notification_changed(NOTI_CHANGED_NOTI);
2162 return NOTIFICATION_ERROR_NONE;
2165 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
2166 notification_type_e type)
2169 char *caller_pkgname = NULL;
2171 if (pkgname == NULL) {
2172 caller_pkgname = _notification_get_pkgname_by_pid();
2174 caller_pkgname = strdup(pkgname);
2177 ret = notification_noti_delete_all(type, caller_pkgname);
2178 if (ret != NOTIFICATION_ERROR_NONE) {
2179 free(caller_pkgname);
2183 _notification_changed(NOTI_CHANGED_NOTI);
2185 free(caller_pkgname);
2190 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
2191 notification_type_e type,
2195 char *caller_pkgname = NULL;
2197 if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2198 return NOTIFICATION_ERROR_INVALID_DATA;
2201 if (pkgname == NULL) {
2202 caller_pkgname = _notification_get_pkgname_by_pid();
2204 caller_pkgname = strdup(pkgname);
2208 notification_noti_delete_group_by_group_id(caller_pkgname,
2210 if (ret != NOTIFICATION_ERROR_NONE) {
2211 free(caller_pkgname);
2215 _notification_changed(NOTI_CHANGED_NOTI);
2217 free(caller_pkgname);
2222 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2223 notification_type_e type,
2227 char *caller_pkgname = NULL;
2229 if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2230 return NOTIFICATION_ERROR_INVALID_DATA;
2233 if (pkgname == NULL) {
2234 caller_pkgname = _notification_get_pkgname_by_pid();
2236 caller_pkgname = strdup(pkgname);
2240 notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id);
2241 if (ret != NOTIFICATION_ERROR_NONE) {
2242 free(caller_pkgname);
2246 _notification_changed(NOTI_CHANGED_NOTI);
2248 free(caller_pkgname);
2253 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
2254 notification_type_e type,
2258 char *caller_pkgname = NULL;
2260 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2261 return NOTIFICATION_ERROR_INVALID_DATA;
2264 if (pkgname == NULL) {
2265 caller_pkgname = _notification_get_pkgname_by_pid();
2267 caller_pkgname = strdup(pkgname);
2270 ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id);
2271 if (ret != NOTIFICATION_ERROR_NONE) {
2272 free(caller_pkgname);
2276 _notification_changed(NOTI_CHANGED_NOTI);
2278 free(caller_pkgname);
2283 EXPORT_API notification_error_e notification_delete(notification_h noti)
2288 return NOTIFICATION_ERROR_INVALID_DATA;
2292 notification_noti_delete_by_priv_id(noti->caller_pkgname,
2294 if (ret != NOTIFICATION_ERROR_NONE) {
2298 if (noti->flags_for_property
2299 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) {
2300 NOTIFICATION_INFO("Disabled update while delete.");
2302 _notification_changed(NOTI_CHANGED_NOTI);
2305 return NOTIFICATION_ERROR_NONE;
2308 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
2312 char *caller_pkgname = NULL;
2313 int input_priv_id = 0;
2314 double input_progress = 0.0;
2316 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2318 return NOTIFICATION_ERROR_INVALID_DATA;
2320 input_priv_id = noti->priv_id;
2323 input_priv_id = priv_id;
2327 caller_pkgname = _notification_get_pkgname_by_pid();
2329 caller_pkgname = strdup(noti->caller_pkgname);
2332 if (progress < 0.0) {
2333 input_progress = 0.0;
2334 } else if (progress > 1.0) {
2335 input_progress = 1.0;
2337 input_progress = progress;
2340 notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2343 if (caller_pkgname) {
2344 free(caller_pkgname);
2347 return NOTIFICATION_ERROR_NONE;
2350 EXPORT_API notification_error_e notification_update_size(notification_h noti,
2354 char *caller_pkgname = NULL;
2355 int input_priv_id = 0;
2356 double input_size = 0.0;
2358 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2360 return NOTIFICATION_ERROR_INVALID_DATA;
2362 input_priv_id = noti->priv_id;
2365 input_priv_id = priv_id;
2369 caller_pkgname = _notification_get_pkgname_by_pid();
2371 caller_pkgname = strdup(noti->caller_pkgname);
2380 notification_ongoing_update_size(caller_pkgname, input_priv_id,
2383 if (caller_pkgname) {
2384 free(caller_pkgname);
2387 return NOTIFICATION_ERROR_NONE;
2390 EXPORT_API notification_h notification_new(notification_type_e type,
2391 int group_id, int priv_id)
2393 notification_h noti = NULL;
2395 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2396 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2400 if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2401 NOTIFICATION_ERR("INVALID GROUP ID : %d", group_id);
2405 if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2406 NOTIFICATION_ERR("INVALID PRIV ID : %d", priv_id);
2410 noti = (notification_h) malloc(sizeof(struct _notification));
2412 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2415 memset(noti, 0x00, sizeof(struct _notification));
2419 noti->group_id = group_id;
2420 noti->internal_group_id = 0;
2421 noti->priv_id = priv_id;
2423 noti->caller_pkgname = _notification_get_pkgname_by_pid();
2424 noti->launch_pkgname = NULL;
2426 noti->group_args = NULL;
2428 noti->b_execute_option = NULL;
2429 noti->b_service_responding = NULL;
2430 noti->b_service_single_launch = NULL;
2431 noti->b_service_multi_launch = NULL;
2433 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2434 noti->sound_path = NULL;
2436 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2437 noti->vibration_path = NULL;
2439 noti->domain = NULL;
2442 noti->b_text = NULL;
2444 noti->b_format_args = NULL;
2445 noti->num_format_args = 0;
2447 noti->b_image_path = NULL;
2450 noti->insert_time = 0;
2452 noti->flags_for_property = 0;
2453 noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2455 noti->progress_size = 0.0;
2456 noti->progress_percentage = 0.0;
2458 noti->app_icon_path = NULL;
2459 noti->app_name = NULL;
2460 noti->temp_title = NULL;
2461 noti->temp_content = NULL;
2466 EXPORT_API notification_error_e notification_free(notification_h noti)
2469 return NOTIFICATION_ERROR_INVALID_DATA;
2472 if (noti->caller_pkgname) {
2473 free(noti->caller_pkgname);
2475 if (noti->launch_pkgname) {
2476 free(noti->launch_pkgname);
2479 bundle_free(noti->args);
2481 if (noti->group_args) {
2482 bundle_free(noti->group_args);
2485 if (noti->b_execute_option) {
2486 bundle_free(noti->b_execute_option);
2488 if (noti->b_service_responding) {
2489 bundle_free(noti->b_service_responding);
2491 if (noti->b_service_single_launch) {
2492 bundle_free(noti->b_service_single_launch);
2494 if (noti->b_service_multi_launch) {
2495 bundle_free(noti->b_service_multi_launch);
2498 if (noti->sound_path) {
2499 free(noti->sound_path);
2501 if (noti->vibration_path) {
2502 free(noti->vibration_path);
2513 bundle_free(noti->b_text);
2516 bundle_free(noti->b_key);
2518 if (noti->b_format_args) {
2519 bundle_free(noti->b_format_args);
2522 if (noti->b_image_path) {
2523 bundle_free(noti->b_image_path);
2526 if (noti->app_icon_path) {
2527 free(noti->app_icon_path);
2529 if (noti->app_name) {
2530 free(noti->app_name);
2532 if (noti->temp_title) {
2533 free(noti->temp_title);
2535 if (noti->temp_content) {
2536 free(noti->temp_content);
2541 return NOTIFICATION_ERROR_NONE;
2544 EXPORT_API notification_error_e
2545 notification_resister_changed_cb(void (*changed_cb)
2546 (void *data, notification_type_e type),
2549 notification_cb_list_s *noti_cb_list_new = NULL;
2550 notification_cb_list_s *noti_cb_list = NULL;
2553 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2555 noti_cb_list_new->next = NULL;
2556 noti_cb_list_new->prev = NULL;
2558 noti_cb_list_new->changed_cb = changed_cb;
2559 noti_cb_list_new->data = user_data;
2561 if (g_notification_cb_list == NULL) {
2562 g_notification_cb_list = noti_cb_list_new;
2564 noti_cb_list = g_notification_cb_list;
2566 while (noti_cb_list->next != NULL) {
2567 noti_cb_list = noti_cb_list->next;
2570 noti_cb_list->next = noti_cb_list_new;
2571 noti_cb_list_new->prev = noti_cb_list;
2574 if (g_notification_heynoti_fd < 0) {
2575 g_notification_heynoti_fd = heynoti_init();
2577 heynoti_subscribe(g_notification_heynoti_fd, NOTI_CHANGED_NOTI,
2578 _notification_chagned_noti_cb, NULL);
2580 heynoti_attach_handler(g_notification_heynoti_fd);
2583 return NOTIFICATION_ERROR_NONE;
2586 EXPORT_API notification_error_e
2587 notification_unresister_changed_cb(void (*changed_cb)
2588 (void *data, notification_type_e type))
2590 notification_cb_list_s *noti_cb_list = NULL;
2591 notification_cb_list_s *noti_cb_list_prev = NULL;
2592 notification_cb_list_s *noti_cb_list_next = NULL;
2594 noti_cb_list = g_notification_cb_list;
2596 if (noti_cb_list == NULL) {
2597 return NOTIFICATION_ERROR_INVALID_DATA;
2600 while (noti_cb_list->prev != NULL) {
2601 noti_cb_list = noti_cb_list->prev;
2605 if (noti_cb_list->changed_cb == changed_cb) {
2606 noti_cb_list_prev = noti_cb_list->prev;
2607 noti_cb_list_next = noti_cb_list->next;
2609 if (noti_cb_list_prev == NULL) {
2610 g_notification_cb_list = noti_cb_list_next;
2612 noti_cb_list_prev->next = noti_cb_list_next;
2615 if (noti_cb_list_next == NULL) {
2616 if (noti_cb_list_prev != NULL) {
2617 noti_cb_list_prev->next = NULL;
2620 noti_cb_list_next->prev = noti_cb_list_prev;
2625 if (g_notification_cb_list == NULL) {
2626 heynoti_detach_handler
2627 (g_notification_heynoti_fd);
2628 heynoti_close(g_notification_heynoti_fd);
2629 g_notification_heynoti_fd = -1;
2632 return NOTIFICATION_ERROR_NONE;
2634 noti_cb_list = noti_cb_list->next;
2635 } while (noti_cb_list != NULL);
2637 return NOTIFICATION_ERROR_INVALID_DATA;
2640 EXPORT_API notification_error_e
2641 notification_resister_badge_changed_cb(void (*changed_cb)
2642 (void *data, const char *pkgname,
2643 int group_id), void *user_data)
2645 // Add DBus signal handler
2646 return NOTIFICATION_ERROR_NONE;
2649 EXPORT_API notification_error_e
2650 notification_unresister_badge_changed_cb(void (*changed_cb)
2651 (void *data, const char *pkgname,
2654 // Del DBus signal handler
2655 return NOTIFICATION_ERROR_NONE;
2658 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
2659 const char *pkgname,
2661 int priv_id, int *count)
2667 notification_noti_get_count(type, pkgname, group_id, priv_id,
2669 if (ret != NOTIFICATION_ERROR_NONE) {
2673 if (count != NULL) {
2674 *count = noti_count;
2677 return NOTIFICATION_ERROR_NONE;
2680 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
2682 notification_list_h *list)
2684 notification_list_h get_list = NULL;
2687 ret = notification_noti_get_grouping_list(type, count, &get_list);
2688 if (ret != NOTIFICATION_ERROR_NONE) {
2694 return NOTIFICATION_ERROR_NONE;
2697 EXPORT_API notification_error_e
2698 notification_get_grouping_list(notification_type_e type, int count,
2699 notification_list_h * list)
2701 notification_list_h get_list = NULL;
2704 ret = notification_noti_get_grouping_list(type, count, &get_list);
2705 if (ret != NOTIFICATION_ERROR_NONE) {
2711 return NOTIFICATION_ERROR_NONE;
2714 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
2718 notification_list_h *list)
2720 notification_list_h get_list = NULL;
2724 notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2726 if (ret != NOTIFICATION_ERROR_NONE) {
2732 return NOTIFICATION_ERROR_NONE;
2735 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
2737 notification_list_h cur_list = NULL;
2738 notification_h noti = NULL;
2741 NOTIFICATION_ERR("INVALID DATA : list == NULL");
2742 return NOTIFICATION_ERROR_INVALID_DATA;
2745 cur_list = notification_list_get_head(list);
2747 while (cur_list != NULL) {
2748 noti = notification_list_get_data(cur_list);
2749 cur_list = notification_list_remove(cur_list, noti);
2751 notification_free(noti);
2754 return NOTIFICATION_ERROR_NONE;