Move notification_get_text_input_max_length to internal
[platform/core/api/notification.git] / src / notification_internal.c
index 0647f72..d1b8344 100755 (executable)
@@ -58,19 +58,23 @@ struct _notification_cb_info {
 
 static GHashTable *_noti_cb_hash = NULL;
 
+/* LCOV_EXCL_START */
 static void __free_changed_cb_info(gpointer data)
 {
        notification_cb_info_s *noti_cb_info = (notification_cb_info_s *)data;
        if (noti_cb_info)
                free(noti_cb_info);
 }
+/* LCOV_EXCL_STOP */
 
+/* LCOV_EXCL_START */
 static void __free_changed_cb_hash(gpointer data)
 {
        GList *changed_cb_list = (GList *)data;
        if (changed_cb_list)
                g_list_free_full(changed_cb_list, __free_changed_cb_info);
 }
+/* LCOV_EXCL_STOP */
 
 void notification_call_changed_cb_for_uid(notification_op *op_list, int op_num, uid_t uid)
 {
@@ -328,13 +332,7 @@ EXPORT_API int notification_update_content(notification_h noti,
 EXPORT_API int notification_set_icon(notification_h noti,
                const char *icon_path)
 {
-       int ret_err = NOTIFICATION_ERROR_NONE;
-
-       ret_err =
-               notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
-                               icon_path);
-
-       return ret_err;
+       return notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
 }
 /* LCOV_EXCL_STOP */
 
@@ -346,8 +344,7 @@ EXPORT_API int notification_get_icon(notification_h noti,
        int ret_err = NOTIFICATION_ERROR_NONE;
        char *ret_image_path = NULL;
 
-       ret_err =
-               notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
+       ret_err = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
                                &ret_image_path);
 
        if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL)
@@ -394,11 +391,6 @@ EXPORT_API int notification_translate_localized_text(notification_h noti)
                }
        }
 
-       if (noti->b_key) {
-               bundle_free(noti->b_key);
-               noti->b_key = NULL;
-       }
-
        return noti_err;
 }
 
@@ -407,13 +399,9 @@ EXPORT_API int notification_set_title(notification_h noti,
                const char *title,
                const char *loc_title)
 {
-       int noti_err = NOTIFICATION_ERROR_NONE;
-
-       noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
-                       title, loc_title,
-                       NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       return noti_err;
+       return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
+                               title, loc_title,
+                               NOTIFICATION_VARIABLE_TYPE_NONE);;
 }
 /* LCOV_EXCL_STOP */
 
@@ -425,8 +413,7 @@ EXPORT_API int notification_get_title(notification_h noti,
        int noti_err = NOTIFICATION_ERROR_NONE;
        char *ret_text = NULL;
 
-       noti_err =
-               notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
+       noti_err = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
                                &ret_text);
 
        if (title != NULL)
@@ -444,13 +431,9 @@ EXPORT_API int notification_set_content(notification_h noti,
                const char *content,
                const char *loc_content)
 {
-       int noti_err = NOTIFICATION_ERROR_NONE;
-
-       noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
-                       content, loc_content,
-                       NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       return noti_err;
+       return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
+                               content, loc_content,
+                               NOTIFICATION_VARIABLE_TYPE_NONE);
 }
 /* LCOV_EXCL_STOP */
 
@@ -462,8 +445,7 @@ EXPORT_API int notification_get_content(notification_h noti,
        int noti_err = NOTIFICATION_ERROR_NONE;
        char *ret_text = NULL;
 
-       noti_err =
-               notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
+       noti_err = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
                                &ret_text);
 
        if (content != NULL)
@@ -473,20 +455,6 @@ EXPORT_API int notification_get_content(notification_h noti,
                *loc_content = NULL;
 
        return noti_err;
-
-#if 0
-       ret =
-               vconf_get_bool
-               (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
-
-       if (ret == -1 || boolval == 0) {
-               if (content != NULL && noti->default_content != NULL)
-                       *content = noti->default_content;
-
-               if (loc_content != NULL && noti->loc_default_content != NULL)
-                       *loc_content = noti->loc_default_content;
-       }
-#endif
 }
 /* LCOV_EXCL_STOP */
 
@@ -687,14 +655,10 @@ EXPORT_API int notification_get_count(notification_type_e type,
 
 int notification_clear_for_uid(notification_type_e type, uid_t uid)
 {
-       int ret = 0;
-
        if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       ret = notification_ipc_request_delete_multiple(type, NULL, uid);
-
-       return ret;
+       return notification_ipc_request_delete_multiple(type, NULL, uid);
 }
 /* LCOV_EXCL_STOP */
 
@@ -739,7 +703,6 @@ EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_o
 EXPORT_API int notification_set_pkgname(notification_h noti,
                const char *pkgname)
 {
-       /* check noti and pkgname are valid data */
        if (noti == NULL || pkgname == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
@@ -836,76 +799,59 @@ EXPORT_API int notification_set_execute_option(notification_h noti,
                        || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       /* Create execute option bundle if does not exist */
        if (noti->b_execute_option == NULL)
                noti->b_execute_option = bundle_create();
 
        b = noti->b_execute_option;
 
-       /* Save text */
        if (text != NULL) {
-               /* Make text key */
                snprintf(buf_key, sizeof(buf_key), "text%d", type);
 
-               /* Check text key exist */
                bundle_get_str(b, buf_key, &ret_val);
                if (ret_val != NULL)
-                       /* Remove previous data */
                        bundle_del(b, buf_key);
 
-               /* Add text data */
                bundle_add_str(b, buf_key, text);
        }
 
-       /* Save key */
        if (key != NULL) {
-               /* Make key key */
                snprintf(buf_key, sizeof(buf_key), "key%d", type);
 
-               /* Check key key exist */
                bundle_get_str(b, buf_key, &ret_val);
                if (ret_val != NULL)
-                       /* Remove previous data */
                        bundle_del(b, buf_key);
 
-               /* Add text data */
                bundle_add_str(b, buf_key, key);
        }
 
        switch ((int)type) {
        case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
-               /* Remove previous data if exist */
                if (noti->b_service_responding != NULL) {
                        bundle_free(noti->b_service_responding);
                        noti->b_service_responding = NULL;
                }
 
-               /* Save service handle */
                if (service_handle != NULL)
                        noti->b_service_responding = bundle_dup(service_handle);
 
                break;
        case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
-               /* Remove previous data if exist */
                if (noti->b_service_single_launch != NULL) {
                        bundle_free(noti->b_service_single_launch);
                        noti->b_service_single_launch = NULL;
                }
 
-               /* Save service handle */
                if (service_handle != NULL)
                        noti->b_service_single_launch =
                                bundle_dup(service_handle);
 
                break;
        case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
-               /* Remove previous data if exist */
                if (noti->b_service_multi_launch != NULL) {
                        bundle_free(noti->b_service_multi_launch);
                        noti->b_service_multi_launch = NULL;
                }
 
-               /* Save service handle */
                if (service_handle != NULL)
                        noti->b_service_multi_launch =
                                bundle_dup(service_handle);
@@ -921,22 +867,17 @@ EXPORT_API int notification_set_execute_option(notification_h noti,
 EXPORT_API int notification_get_id(notification_h noti,
                int *group_id, int *priv_id)
 {
-       /* check noti is valid data */
        if (noti == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       /* Check group_id is valid data */
        if (group_id) {
-               /* Set group id */
                if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
                        *group_id = NOTIFICATION_GROUP_ID_NONE;
                else
                        *group_id = noti->group_id;
        }
 
-       /* Check priv_id is valid data */
        if (priv_id)
-               /* Set priv_id */
                *priv_id = noti->priv_id;
 
        return NOTIFICATION_ERROR_NONE;
@@ -1020,32 +961,25 @@ EXPORT_API int notification_get_execute_option(notification_h noti,
        }
 
        if (b != NULL) {
-               /* Return text */
                if (text != NULL) {
-                       /*  Get text domain and dir */
                        if (noti->domain == NULL || noti->dir == NULL)
                                _notification_get_text_domain(noti);
 
-                       /* Make key */
                        snprintf(buf_key, sizeof(buf_key), "key%d", type);
 
-                       /* Check key key exist */
                        bundle_get_str(b, buf_key, &ret_val);
                        if (ret_val != NULL && noti->domain != NULL
                                        && noti->dir != NULL) {
-                               /* Get application string */
                                bindtextdomain(noti->domain, noti->dir);
 
                                get_str = dgettext(noti->domain, ret_val);
 
                                *text = get_str;
                        } else if (ret_val != NULL) {
-                               /* Get system string */
                                get_str = dgettext("sys_string", ret_val);
 
                                *text = get_str;
                        } else {
-                               /* Get basic text */
                                snprintf(buf_key, sizeof(buf_key), "text%d",
                                                type);
 
@@ -1069,18 +1003,16 @@ EXPORT_API int notification_insert_for_uid(notification_h noti,
        int ret = 0;
        int id = 0;
 
-       /* Check noti is vaild data */
        if (noti == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       /* Check noti type is valid type */
        if (noti->type <= NOTIFICATION_TYPE_NONE
                        || noti->type >= NOTIFICATION_TYPE_MAX)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
        noti->uid = uid;
-       /* Save insert time */
        noti->insert_time = time(NULL);
+
        ret = notification_ipc_request_insert(noti, &id);
        if (ret != NOTIFICATION_ERROR_NONE)
                return ret;
@@ -1104,16 +1036,14 @@ EXPORT_API int notification_insert(notification_h noti,
 EXPORT_API int notification_update_async_for_uid(notification_h noti,
                void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
 {
-       int ret = 0;
        if (noti == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
        noti->uid = uid;
        /* Update insert time ? */
        noti->insert_time = time(NULL);
-       ret = notification_ipc_request_update_async(noti, result_cb, user_data);
 
-       return ret;
+       return notification_ipc_request_update_async(noti, result_cb, user_data);
 }
 
 EXPORT_API int notification_update_async(notification_h noti,
@@ -1245,11 +1175,9 @@ EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
        int ret = 0;
        int id = 0;
 
-       /* Check noti is vaild data */
        if (noti == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       /* Check noti type is valid type */
        if (noti->type <= NOTIFICATION_TYPE_NONE
                        || noti->type >= NOTIFICATION_TYPE_MAX)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -1270,32 +1198,26 @@ EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
 
 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
 {
-       int ret;
-
-       /* Check noti is valid data */
-       if (noti != NULL) {
-               noti->uid = uid;
-               /* Update insert time ? */
-               noti->insert_time = time(NULL);
-               ret = notification_ipc_request_update(noti);
-       } else {
+       if (noti == NULL) {
                notification_ipc_request_refresh(uid);
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       return ret;
+       noti->uid = uid;
+       /* Update insert time ? */
+       noti->insert_time = time(NULL);
+
+       return notification_ipc_request_update(noti);
 }
 
 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
 {
-       int ret = 0;
 
        if (noti == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id, uid);
-
-       return ret;
+       return notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE,
+                               noti->caller_pkgname, noti->priv_id, uid);
 }
 
 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
@@ -1359,3 +1281,133 @@ EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_
 
        return noti;
 }
+
+EXPORT_API notification_h notification_create_from_package_template(const char *pkgname, const char *template_name)
+{
+       int ret = 0;
+       notification_h noti = NULL;
+
+       if (pkgname == NULL || template_name == NULL) {
+               NOTIFICATION_ERR("Invalid parameter");
+               set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
+               return NULL;
+       }
+
+       noti = (notification_h)calloc(1, sizeof(struct _notification));
+       if (noti == NULL) {
+               NOTIFICATION_ERR("Failed to alloc a new notification");
+               set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
+               return NULL;
+       }
+
+       ret = notification_ipc_request_create_from_package_template(noti, pkgname, template_name);
+
+       set_last_result(ret);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               notification_free(noti);
+               return NULL;
+       }
+
+       return noti;
+}
+
+EXPORT_API int notification_set_default_button(notification_h noti, notification_button_index_e index)
+{
+       if (noti == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       if (index < 0 || index > NOTIFICATION_BUTTON_6)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       noti->default_button_index = index;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_get_default_button(notification_h noti, notification_button_index_e *index)
+{
+       if (noti == NULL || index == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       *index = noti->default_button_index;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_get_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e *type)
+{
+       if (noti == NULL || type == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       *type = noti->ongoing_value_type;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_set_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e type)
+{
+       if (noti == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       if (type < NOTIFICATION_ONGOING_VALUE_TYPE_PERCENT || type > NOTIFICATION_ONGOING_VALUE_TYPE_TIME)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       noti->ongoing_value_type = type;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_get_ongoing_time(notification_h noti, int *current, int *duration)
+{
+       if (noti == NULL || current == NULL || duration == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       *current = noti->ongoing_current;
+       *duration = noti->ongoing_duration;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_set_ongoing_time(notification_h noti, int current, int duration)
+{
+       if (noti == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       if (current < 0 || duration < 0 || current > duration)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       noti->ongoing_current = current;
+       noti->ongoing_duration = duration;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_get_hide_timeout(notification_h noti, int *timeout)
+{
+       if (noti == NULL || timeout == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       *timeout = noti->timeout;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_set_hide_timeout(notification_h noti, int timeout)
+{
+       if (noti == NULL || timeout < 0)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       noti->timeout = timeout;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_get_text_input_max_length(notification_h noti, int *text_input_max_length)
+{
+       if (noti == NULL || text_input_max_length == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       *text_input_max_length = noti->text_input_max_length;
+
+       return NOTIFICATION_ERROR_NONE;
+}