From 59019b59aabc10fec02122523cddd276f38d169d Mon Sep 17 00:00:00 2001 From: "seungha.son" Date: Mon, 5 Sep 2016 18:39:43 +0900 Subject: [PATCH] Add API for get/set default highlight button Signed-off-by: seungha.son Change-Id: If13602041791ba173a7cadd6af72885b2833eff6 --- include/notification_internal.h | 76 +++++++++++++++++++++++++++++++++++++++++ include/notification_private.h | 2 ++ src/notification.c | 2 ++ src/notification_db.c | 2 ++ src/notification_internal.c | 23 +++++++++++++ src/notification_ipc.c | 3 +- src/notification_noti.c | 10 +++--- 7 files changed, 113 insertions(+), 5 deletions(-) diff --git a/include/notification_internal.h b/include/notification_internal.h index a97c2b6..5df7184 100644 --- a/include/notification_internal.h +++ b/include/notification_internal.h @@ -726,6 +726,82 @@ int notification_unregister_detailed_changed_cb_for_uid( void *user_data, uid_t uid); /** + * @brief Sets the default button to display highlight on the notification. + * @since_tizen 3.0 + * @remarks If you want to default button is off, you set that index is zero + * @param[in] noti The notification handle + * @param[in] index The notification button index + * @return #NOTIFICATION_ERROR_NONE on success, + * otherwise any other value on failure + * @retval #NOTIFICATION_ERROR_NONE Success + * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @pre Notification handle should be created by notification_create(). + * @see #notification_button_index_e + * @par Sample code: + * @code +#include +... +{ + notification_h noti = NULL; + int noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + if(noti == NULL) { + return; + } + + noti_err = notification_set_default_button(noti, NOTIFICATION_BUTTON_1); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } + + ... + +} + * @endcode + */ +int notification_set_default_button(notification_h noti, notification_button_index_e index); + +/** + * @brief Gets the default button to display highlight on the notification. + * @since_tizen 3.0 + * @param[in] noti The notification handle + * @param[out] index The notification button index + * @return #NOTIFICATION_ERROR_NONE on success, + * otherwise any other value on failure + * @retval #NOTIFICATION_ERROR_NONE Success + * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @pre Notification handle should be created by notification_create(). + * @see #notification_button_index_e + * @par Sample code: + * @code +#include +... +{ + notification_h noti = NULL; + notification_button_index_e index; + int noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + if(noti == NULL) { + return; + } + + noti_err = notification_set_default_button(noti, &index); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } + + ... + +} + * @endcode + */ +int notification_get_default_button(notification_h noti, notification_button_index_e *index); + +/** * @brief This function translate localized texts * @param[in] noti The notification handle that is created by notification_create() * @return #NOTIFICATION_ERROR_NONE if success, other value if failure diff --git a/include/notification_private.h b/include/notification_private.h index d9a7167..a2e6ece 100644 --- a/include/notification_private.h +++ b/include/notification_private.h @@ -89,6 +89,7 @@ struct _notification { char *tag; bool ongoing_flag; bool auto_remove; + notification_button_index_e default_button_index; uid_t uid; }; @@ -142,6 +143,7 @@ typedef enum notification_data_type { NOTIFICATION_DATA_TYPE_TAG, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, + NOTIFICATION_DATA_TYPE_DEFAULT_BUTTON, NOTIFICATION_DATA_TYPE_UID, } notification_data_type_e; diff --git a/src/notification.c b/src/notification.c index 480fc19..3ab618e 100755 --- a/src/notification.c +++ b/src/notification.c @@ -1428,6 +1428,7 @@ static notification_h _notification_create(notification_type_e type) noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR; noti->auto_remove = true; noti->ongoing_flag = false; + noti->default_button_index = 0; if (getuid() >= REGULAR_UID_MIN) { noti->caller_pkgname = notification_get_pkgname_by_pid(); @@ -1638,6 +1639,7 @@ EXPORT_API int notification_clone(notification_h noti, notification_h *clone) new_noti->ongoing_flag = noti->ongoing_flag; new_noti->auto_remove = noti->auto_remove; + new_noti->default_button_index = noti->default_button_index; new_noti->uid = noti->uid; new_noti->app_icon_path = NULL; diff --git a/src/notification_db.c b/src/notification_db.c index 156ad78..b4cfaf0 100755 --- a/src/notification_db.c +++ b/src/notification_db.c @@ -80,6 +80,7 @@ create table if not exists noti_list ( \ progress_percentage DOUBLE default 0, \ ongoing_flag INTEGER default 0, \ auto_remove INTEGER default 1, \ + default_button_index INTEGER default 0, \ uid INTEGER \ ); \ create table if not exists noti_group_data ( \ @@ -189,6 +190,7 @@ create table if not exists noti_list ( \ progress_percentage DOUBLE default 0, \ ongoing_flag INTEGER default 0, \ auto_remove INTEGER default 1, \ + default_button_index INTEGER default 0, \ uid INTEGER, \ template_name TEXT, \ UNIQUE (caller_pkgname, template_name) \ diff --git a/src/notification_internal.c b/src/notification_internal.c index 337066b..dbf3820 100755 --- a/src/notification_internal.c +++ b/src/notification_internal.c @@ -1310,3 +1310,26 @@ EXPORT_API notification_h notification_create_from_package_template(const char * return noti; } + +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; +} + +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; +} diff --git a/src/notification_ipc.c b/src/notification_ipc.c index 940ce70..0453d57 100755 --- a/src/notification_ipc.c +++ b/src/notification_ipc.c @@ -1664,8 +1664,8 @@ EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h not g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TAG, g_variant_new_string((const gchar *)noti->tag)); g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ONGOING_FLAG, g_variant_new_int32(noti->ongoing_flag)); - g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_AUTO_REMOVE, g_variant_new_int32(noti->auto_remove)); + g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DEFAULT_BUTTON, g_variant_new_int32(noti->default_button_index)); g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_UID, g_variant_new_int32(noti->uid)); result_body = g_variant_builder_end(&builder); @@ -1813,6 +1813,7 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti, _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag); _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, "i", ¬i->ongoing_flag); _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, "i", ¬i->auto_remove); + _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DEFAULT_BUTTON, "i", ¬i->default_button_index); _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_UID, "i", ¬i->uid); noti->caller_pkgname = _dup_string(caller_pkgname); diff --git a/src/notification_noti.c b/src/notification_noti.c index 31ea558..1443822 100755 --- a/src/notification_noti.c +++ b/src/notification_noti.c @@ -261,7 +261,7 @@ static int _insertion_query_create(notification_h noti, char **query) "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, " "flags_for_property, flag_simmode, display_applist, " - "progress_size, progress_percentage, ongoing_flag, auto_remove, uid) values (" + "progress_size, progress_percentage, ongoing_flag, auto_remove, default_button_index, uid) values (" "%d, " "%d, " "'%s', '%s', " @@ -279,7 +279,7 @@ static int _insertion_query_create(notification_h noti, char **query) "'%s', '%s', " "%d, '%s', %d, '%s', %d, %d, %d, %d," "%d, %d, %d, " - "$progress_size, $progress_percentage, %d, %d, %d)", + "$progress_size, $progress_percentage, %d, %d, %d, %d)", noti->type, noti->layout, NOTIFICATION_CHECK_STR(noti->caller_pkgname), @@ -314,6 +314,7 @@ static int _insertion_query_create(notification_h noti, char **query) noti->flags_for_property, flag_simmode, noti->display_applist, noti->ongoing_flag, noti->auto_remove, + noti->default_button_index, noti->uid); /* Free decoded data */ @@ -450,7 +451,7 @@ static int _update_query_create(notification_h noti, char **query) "flags_for_property = %d, flag_simmode = %d, " "display_applist = %d, " "progress_size = $progress_size, progress_percentage = $progress_percentage, " - "ongoing_flag = %d, auto_remove = %d " + "ongoing_flag = %d, auto_remove = %d, default_button_index = %d " "where priv_id = %d ", noti->type, noti->layout, @@ -482,7 +483,7 @@ static int _update_query_create(notification_h noti, char **query) noti->led_on_ms, noti->led_off_ms, noti->flags_for_property, flag_simmode, noti->display_applist, - noti->ongoing_flag, noti->auto_remove, + noti->ongoing_flag, noti->auto_remove, noti->default_button_index, noti->priv_id); /* Free decoded data */ @@ -579,6 +580,7 @@ static void _notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notificati noti->ongoing_flag = sqlite3_column_int(stmt, col++); noti->auto_remove = sqlite3_column_int(stmt, col++); + noti->default_button_index = sqlite3_column_int(stmt, col++); noti->app_icon_path = NULL; noti->app_name = NULL; -- 2.7.4