diff options
-rwxr-xr-x[-rw-r--r--] | CMakeLists.txt | 1 | ||||
-rw-r--r-- | notification-ex/db_manager.cc | 4 | ||||
-rw-r--r-- | notification-ex/event_info_internal.h | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | notification/CMakeLists.txt | 3 | ||||
-rw-r--r-- | notification/include/notification_convert.h | 37 | ||||
-rw-r--r-- | notification/src/notification_convert.c | 1596 | ||||
-rw-r--r-- | notification/src/notification_enum_string.h | 98 | ||||
-rw-r--r-- | packaging/notification.spec | 1 |
8 files changed, 1738 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 90ed25c..ed518b6 100644..100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,4 +8,5 @@ ADD_SUBDIRECTORY(notification) ADD_SUBDIRECTORY(notification-ex) ADD_SUBDIRECTORY(unittest) +ADD_DEPENDENCIES(notification notification-ex) ADD_DEPENDENCIES(notification-ex_unittests notification-ex) diff --git a/notification-ex/db_manager.cc b/notification-ex/db_manager.cc index fc3b38a..de71ff9 100644 --- a/notification-ex/db_manager.cc +++ b/notification-ex/db_manager.cc @@ -407,7 +407,7 @@ int DBManager::InsertNotification(list<shared_ptr<item::AbstractItem>> addedItem i->GetId().c_str(), i->GetSenderAppId().c_str(), uid, - util::GetQuarkFromString(i->GetId() + to_string(uid)), + util::GetQuarkFromString(i->GetId()), GetPkgId(i->GetSenderAppId(),uid).c_str(), static_cast<int>(i->GetPolicy()), reinterpret_cast<char*>(b.ToRaw().first.get()), @@ -582,7 +582,7 @@ int DBManager::UpdateNotification(shared_ptr<item::AbstractItem> updatedItem) { query = sqlite3_mprintf("UPDATE noti_ex_list SET" " priv_id = %d, pkg_id = %Q, policy = %d, data = %Q, insert_time = %d" " WHERE root_id = %Q AND app_id = %Q AND uid = %d", - util::GetQuarkFromString(updatedItem->GetId() + to_string(uid)), + util::GetQuarkFromString(updatedItem->GetId()), GetPkgId(updatedItem->GetSenderAppId(), uid).c_str(), static_cast<int>(updatedItem->GetPolicy()), reinterpret_cast<char*>(b.ToRaw().first.get()), diff --git a/notification-ex/event_info_internal.h b/notification-ex/event_info_internal.h index ada713a..c13f4a9 100644 --- a/notification-ex/event_info_internal.h +++ b/notification-ex/event_info_internal.h @@ -30,7 +30,7 @@ namespace notification { -class EventInfo : public IEventInfoInternal { +class EXPORT_API EventInfo : public IEventInfoInternal { public: EventInfo(int type, std::string owner, std::string channel = "", std::string item_id = ""); diff --git a/notification/CMakeLists.txt b/notification/CMakeLists.txt index 24fb7d5..dacab76 100644..100755 --- a/notification/CMakeLists.txt +++ b/notification/CMakeLists.txt @@ -12,6 +12,7 @@ SET(INIT-SRCS ./src/notification_init.c ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../notification-ex/api) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) LIST(REMOVE_ITEM SRCS ${INIT-SRCS}) @@ -48,7 +49,7 @@ SET(CMAKE_SKIP_BUILD_RPATH TRUE) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJORVER}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} notification-ex) ADD_EXECUTABLE(notification_init ${INIT-SRCS}) TARGET_LINK_LIBRARIES(notification_init ${pkgs_LDFLAGS} notification "-pie") diff --git a/notification/include/notification_convert.h b/notification/include/notification_convert.h new file mode 100644 index 0000000..fe360cb --- /dev/null +++ b/notification/include/notification_convert.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NOTIFICATION_CONVERT_H__ +#define __NOTIFICATION_CONVERT_H__ + +#include <notification_ex.h> +#include <notification.h> + +#ifdef __cplusplus +extern "C" { +#endif + +int notification_convert_to_legacy(noti_ex_item_h item, notification_h *noti); +int notification_convert_to_ex(notification_h noti, noti_ex_item_h *item); +int notification_convert_to_legacy_error(int err); +int notification_convert_to_ex_error(int err); + + +#ifdef __cplusplus +} +#endif +#endif /* __NOTIFICATION_CONVERT_H__ */ + diff --git a/notification/src/notification_convert.c b/notification/src/notification_convert.c new file mode 100644 index 0000000..4efd987 --- /dev/null +++ b/notification/src/notification_convert.c @@ -0,0 +1,1596 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification.h" +#include "notification_private.h" +#include "notification_debug.h" +#include "notification_type.h" +#include "notification_enum_string.h" + +#include <notification_ex.h> +#include <notification_ex_internal.h> + +#include <gmodule.h> +#include <string.h> +#include <time.h> +#include <stdio.h> +#include <stdlib.h> + +#define MAX_PRO_STR_BUFSZ 20 +#define DEFAULT_BUTTON "DEFAULT_BUTTON" +#define HIDE_VIEWER_LIST "__NOTIFICATION_LEGACY_HIDE_VIEWER_LIST__" + +enum Policy { + None = 0, + OnBootClear = 1 << 0, + SimMode = 1 << 1, +}; + +#define NOTI_EX_RECEIVER_GROUP_PANEL "tizen.org/receiver/panel" + +int display_arr[] = { + NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY, + NOTIFICATION_DISPLAY_APP_TICKER, + NOTIFICATION_DISPLAY_APP_LOCK, + NOTIFICATION_DISPLAY_APP_INDICATOR, + NOTIFICATION_DISPLAY_APP_ACTIVE +}; + +const char *receiver_arr[] = { + NOTI_EX_RECEIVER_GROUP_PANEL, + NOTI_EX_RECEIVER_GROUP_TICKER, + NOTI_EX_RECEIVER_GROUP_LOCKSCREEN, + NOTI_EX_RECEIVER_GROUP_INDICATOR, + NOTI_EX_RECEIVER_GROUP_POPUP, +}; + +int _convert_to_ex_text(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_image(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_action(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_progress(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_accessory(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_time(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_property(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_receiver(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_tag(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_delete_hide_time(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_uid(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_event_flag(notification_h noti, noti_ex_item_h group); +int _convert_to_ex_layout(notification_h noti, noti_ex_item_h group); + +int _convert_to_legacy_text(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_image( noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_action(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_progress(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_accessory(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_time(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_property(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_receiver(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_tag(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_delete_hide_time(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_uid(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_event_flag(noti_ex_item_h group, notification_h noti); +int _convert_to_legacy_layout(noti_ex_item_h group, notification_h noti); + +typedef int (*convert_to_legacy)(noti_ex_item_h, notification_h); +typedef int (*convert_to_ex)(notification_h, noti_ex_item_h); + +convert_to_ex convert_to_ex_arr[] = { + _convert_to_ex_text, + _convert_to_ex_image, + _convert_to_ex_action, + _convert_to_ex_accessory, + _convert_to_ex_time, + _convert_to_ex_property, + _convert_to_ex_receiver, + _convert_to_ex_tag, + _convert_to_ex_delete_hide_time, + _convert_to_ex_uid, + _convert_to_ex_event_flag, + _convert_to_ex_progress, + _convert_to_ex_layout, +}; + +convert_to_legacy convert_to_legacy_arr[] = { + _convert_to_legacy_text, + _convert_to_legacy_image, + _convert_to_legacy_action, + _convert_to_legacy_accessory, + _convert_to_legacy_time, + _convert_to_legacy_property, + _convert_to_legacy_receiver, + _convert_to_legacy_tag, + _convert_to_legacy_delete_hide_time, + _convert_to_legacy_uid, + _convert_to_legacy_event_flag, + _convert_to_legacy_progress, + _convert_to_legacy_layout, +}; + +EXPORT_API int notification_convert_to_legacy_error(int err) +{ + switch (err) { + case NOTI_EX_ERROR_NONE: + return NOTIFICATION_ERROR_NONE; + case NOTI_EX_ERROR_INVALID_PARAMETER: + return NOTIFICATION_ERROR_INVALID_PARAMETER; + case NOTI_EX_ERROR_OUT_OF_MEMORY: + return NOTIFICATION_ERROR_OUT_OF_MEMORY; + case NOTI_EX_ERROR_IO_ERROR: + return NOTIFICATION_ERROR_IO_ERROR; + case NOTI_EX_ERROR_PERMISSION_DENIED: + return NOTIFICATION_ERROR_PERMISSION_DENIED; + case NOTI_EX_ERROR_INVALID_OPERATION: + return NOTIFICATION_ERROR_INVALID_OPERATION; + case NOTI_EX_ERROR_FROM_DB: + return NOTIFICATION_ERROR_FROM_DB; + case NOTI_EX_ERROR_ALREADY_EXIST_ID: + return NOTIFICATION_ERROR_ALREADY_EXIST_ID; + case NOTI_EX_ERROR_FROM_DBUS: + return NOTIFICATION_ERROR_FROM_DBUS; + case NOTI_EX_ERROR_NOT_EXIST_ID: + return NOTIFICATION_ERROR_NOT_EXIST_ID; + case NOTI_EX_ERROR_SERVICE_NOT_READY: + return NOTIFICATION_ERROR_SERVICE_NOT_READY; + case NOTI_EX_ERROR_MAX_EXCEEDED: + return NOTIFICATION_ERROR_MAX_EXCEEDED; + default: + ERR("invalid errno[%d]", err); + } + return NOTIFICATION_ERROR_INVALID_OPERATION; +} + +EXPORT_API int notification_convert_to_ex_error(int err) +{ + switch (err) { + case NOTIFICATION_ERROR_NONE: + return NOTI_EX_ERROR_NONE; + case NOTIFICATION_ERROR_INVALID_PARAMETER: + return NOTI_EX_ERROR_INVALID_PARAMETER; + case NOTIFICATION_ERROR_OUT_OF_MEMORY: + return NOTI_EX_ERROR_OUT_OF_MEMORY; + case NOTIFICATION_ERROR_IO_ERROR: + return NOTI_EX_ERROR_IO_ERROR; + case NOTIFICATION_ERROR_PERMISSION_DENIED: + return NOTI_EX_ERROR_PERMISSION_DENIED; + case NOTIFICATION_ERROR_INVALID_OPERATION: + return NOTI_EX_ERROR_INVALID_OPERATION; + case NOTIFICATION_ERROR_FROM_DB: + return NOTI_EX_ERROR_FROM_DB; + case NOTIFICATION_ERROR_ALREADY_EXIST_ID: + return NOTI_EX_ERROR_ALREADY_EXIST_ID; + case NOTIFICATION_ERROR_FROM_DBUS: + return NOTI_EX_ERROR_FROM_DBUS; + case NOTIFICATION_ERROR_NOT_EXIST_ID: + return NOTI_EX_ERROR_NOT_EXIST_ID; + case NOTIFICATION_ERROR_SERVICE_NOT_READY: + return NOTI_EX_ERROR_SERVICE_NOT_READY; + case NOTIFICATION_ERROR_MAX_EXCEEDED: + return NOTI_EX_ERROR_MAX_EXCEEDED; + default: + ERR("invalid errno[%d]", err); + } + return NOTI_EX_ERROR_INVALID_OPERATION; +} + +int _item_find_by_id(noti_ex_item_h handle, const char *id, + noti_ex_item_h *item, void *out1, void **out2) +{ + int type, ret = NOTI_EX_ERROR_NONE; + + ret = noti_ex_item_find_by_id(handle, id, item); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)(%s)", ret, id); + return ret; + } + + ret = noti_ex_item_get_type(*item, &type); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)(%s)(%d)", ret, id, type); + return ret; + } + + if (type == NOTI_EX_ITEM_TYPE_NULL) + return NOTI_EX_ERROR_NOT_EXIST_ID; + + switch (type) { + case NOTI_EX_ITEM_TYPE_TEXT: + if (out2 != NULL) + ret = noti_ex_item_text_get_contents(*item, (char **)out2); + break; + case NOTI_EX_ITEM_TYPE_IMAGE: + if (out2 != NULL) + ret = noti_ex_item_image_get_image_path(*item, (char **)out2); + break; + case NOTI_EX_ITEM_TYPE_TIME: + if (out1 != NULL) + ret = noti_ex_item_time_get_time(*item, (time_t *)out1); + break; + case NOTI_EX_ITEM_TYPE_PROGRESS: + ret = NOTI_EX_ERROR_NONE; + break; + default: + ret = NOTI_EX_ERROR_INVALID_PARAMETER; + } + + if (ret != NOTI_EX_ERROR_NONE) + ERR("failed to convert(%d)(%s)(%d)", ret, id, type); + + return ret; +} + +int _convert_to_ex_uid(notification_h noti, noti_ex_item_h group) +{ + int ret; + uid_t uid; + + ret = notification_get_uid(noti, &uid); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_item_set_uid(group, (int)uid); + if (ret != NOTI_EX_ERROR_NONE) + ERR("failed to convert(%d)", ret); + + return ret; +} + +int _convert_to_legacy_uid(noti_ex_item_h group, notification_h noti) +{ + int ret, uid; + + ret = noti_ex_item_get_uid(group, &uid); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_set_uid(noti, uid); + if (ret != NOTIFICATION_ERROR_NONE) + ERR("failed to convert(%d)", ret); + + return notification_convert_to_ex_error(ret); +} + +int _add_child(noti_ex_item_h group, noti_ex_item_h item, notification_h noti) +{ + char *sender_id; + int ret; + + ret = notification_get_pkgname(noti, &sender_id); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_item_set_sender_app_id(item, sender_id); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + return noti_ex_item_group_add_child(group, item); +} + +int _convert_to_ex_delete_hide_time( + notification_h noti, noti_ex_item_h group) +{ + int ret; + bool auto_remove; + noti_ex_item_info_h item_info; + noti_ex_item_h item; + int timeout; + + ret = notification_get_auto_remove(noti, &auto_remove); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_item_text_create(&item, NOTIFICATION_AUTO_REMOVE_STRING, + auto_remove ? "true" : "false", NULL); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to get hide_viewer_list(%d)", ret); + return ret; + } + + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + noti_ex_item_destroy(item); + return ret; + } + + ret = noti_ex_item_get_info(group, &item_info); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_get_delete_timeout(noti, &timeout); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_item_info_set_delete_time(item_info, timeout); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_get_hide_timeout(noti, &timeout); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_item_info_set_hide_time(item_info, timeout); + + return ret; +} + +int _convert_to_legacy_delete_hide_time( + noti_ex_item_h group, notification_h noti) +{ + int ret; + noti_ex_item_info_h item_info; + noti_ex_item_h item; + int timeout; + char *text; + + ret = _item_find_by_id( + group, NOTIFICATION_AUTO_REMOVE_STRING, &item, NULL, (void **)&text); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + if (strcmp(text, "false") == 0) + notification_set_auto_remove(noti, false); + + free(text); + + ret = noti_ex_item_get_info(group, &item_info); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_item_info_get_delete_time(item_info, &timeout); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_set_delete_timeout(noti, timeout); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_item_info_get_hide_time(item_info, &timeout); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_set_hide_timeout(noti, timeout); + if (ret != NOTIFICATION_ERROR_NONE) + ERR("failed to convert(%d)", ret); + + return notification_convert_to_ex_error(ret); +} + +int _convert_to_ex_tag(notification_h noti, noti_ex_item_h group) +{ + int ret; + noti_ex_item_h item; + const char *tag = NULL; + + notification_get_tag(noti, &tag); + if (tag == NULL) + return NOTI_EX_ERROR_NONE; + + ret = noti_ex_item_text_create(&item, NOTIFICATION_TAG_STRING, tag, NULL); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + noti_ex_item_destroy(item); + } + + return ret; +} + +int _convert_to_legacy_tag(noti_ex_item_h group, notification_h noti) +{ + int ret; + noti_ex_item_h item; + char *tag = NULL; + + ret = _item_find_by_id( + group, NOTIFICATION_TAG_STRING, &item, NULL, (void **)&tag); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + ret = notification_set_tag(noti, tag); + free(tag); + if (ret != NOTIFICATION_ERROR_NONE) + ERR("failed to convert(%d)", ret); + + return notification_convert_to_ex_error(ret); +} + +int _convert_to_ex_event_flag( + notification_h noti, noti_ex_item_h group) +{ + int ret; + noti_ex_item_h item; + bool flag; + + notification_get_event_flag(noti, &flag); + if (flag == false) + return NOTI_EX_ERROR_NONE; + + ret = noti_ex_item_text_create(&item, NOTIFICATION_EVENT_FLAG_STRING, "", NULL); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(item); + ERR("failed to convert(%d)", ret); + } + + return ret; +} + +int _convert_to_legacy_event_flag(noti_ex_item_h group, notification_h noti) +{ + int ret; + noti_ex_item_h item; + + ret = _item_find_by_id( + group, NOTIFICATION_EVENT_FLAG_STRING, &item, NULL, NULL); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + noti->event_flag = true; + + return ret; +} + +int _convert_to_ex_text(notification_h noti, noti_ex_item_h group) +{ + int i, length, ret; + noti_ex_item_h item; + char *text = NULL; + char buf[MAX_PRO_STR_BUFSZ]; + + for (i = NOTIFICATION_TEXT_TYPE_TITLE; + i <= NOTIFICATION_TEXT_TYPE_BUTTON_10; i++) { + ret = notification_get_text(noti, i, &text); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + if (text == NULL) + continue; + + ret = noti_ex_item_text_create(&item, text_type_arr[i], text, NULL); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(item); + ERR("failed to convert(%d)", ret); + return ret; + } + text = NULL; + } + + notification_get_text_input_max_length(noti, &length); + if (length == 0) + return NOTI_EX_ERROR_NONE; + + snprintf(buf, MAX_PRO_STR_BUFSZ, "%d", length); + ret = noti_ex_item_text_create( + &item, NOTIFICATION_TEXT_INPUT_LENGTH_STRING, buf, NULL); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(item); + ERR("failed to convert(%d)", ret); + } + + return ret; +} + +int _convert_to_legacy_text(noti_ex_item_h group, notification_h noti) +{ + int i, ret; + noti_ex_item_h item; + char *text; + + for (i = NOTIFICATION_TEXT_TYPE_TITLE; + i <= NOTIFICATION_TEXT_TYPE_BUTTON_10; i++) { + ret = _item_find_by_id( + group, text_type_arr[i], &item, NULL, (void **)&text); + if (ret == NOTI_EX_ERROR_NOT_EXIST_ID) + continue; + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_set_text( + noti, i, text, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); + free(text); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + } + + ret = _item_find_by_id(group, + NOTIFICATION_TEXT_INPUT_LENGTH_STRING, &item, NULL, (void **)&text); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + ret = notification_set_text_input(noti, atoi(text)); + free(text); + if (ret != NOTIFICATION_ERROR_NONE) + ERR("failed to convert(%d)", ret); + + return notification_convert_to_ex_error(ret); +} + +int _convert_to_ex_time(notification_h noti, noti_ex_item_h group) +{ + int ret; + noti_ex_item_h item; + time_t ret_time = 0; + + notification_get_time(noti, &ret_time); + ret = noti_ex_item_time_create(&item, NOTIFICATION_TIME_STRING, ret_time); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(item); + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_get_insert_time(noti, &ret_time); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_item_time_create(&item, + NOTIFICATION_INSERT_TIME_STRING, ret_time); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + noti_ex_item_destroy(item); + } + + return ret; +} + +int _convert_to_legacy_time(noti_ex_item_h group, notification_h noti) +{ + int ret; + noti_ex_item_h item; + time_t ret_time = 0; + + ret = _item_find_by_id( + group, NOTIFICATION_TIME_STRING, &item, (void *)&ret_time, NULL); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + ret = notification_set_time(noti, ret_time); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = _item_find_by_id( + group, NOTIFICATION_INSERT_TIME_STRING, &item, (void *)&ret_time, NULL); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + noti->insert_time = ret_time; + + return ret; +} + +int _convert_to_ex_property(notification_h noti, noti_ex_item_h group) +{ + int ret, flags, policy; + noti_ex_item_h item; + char buf[MAX_PRO_STR_BUFSZ]; + + ret = notification_get_property(noti, &flags); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + snprintf(buf, MAX_PRO_STR_BUFSZ, "%d", flags); + ret = noti_ex_item_text_create( + &item, NOTIFICATION_PROPERTY_STRING, buf, NULL); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(item); + ERR("failed to convert(%d)", ret); + return ret; + } + + if (flags & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) { + ret = noti_ex_item_get_policy(group, &policy); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_item_set_policy(group, policy | SimMode); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + } + + if (flags & NOTIFICATION_PROP_VOLATILE_DISPLAY) { + ret = noti_ex_item_get_policy(group, &policy); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + ret = noti_ex_item_set_policy(group, policy | OnBootClear); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + } + + return ret; +} + +int _convert_to_legacy_property(noti_ex_item_h group, notification_h noti) +{ + int ret, flags; + noti_ex_item_h item; + char *text; + + ret = _item_find_by_id( + group, NOTIFICATION_PROPERTY_STRING, &item, NULL, (void **)&text); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + flags = atoi(text); + free(text); + + ret = notification_set_property(noti, flags); + + return notification_convert_to_ex_error(ret); +} + +int _convert_to_ex_image(notification_h noti, noti_ex_item_h group) +{ + int i, ret; + noti_ex_item_h item; + char *path = NULL; + noti_ex_geometry_h geometry; + noti_ex_style_h style; + int height; + + for (i = NOTIFICATION_IMAGE_TYPE_ICON; + i <= NOTIFICATION_IMAGE_TYPE_MAX; i++) { + ret = notification_get_image(noti, i, &path); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + if (path == NULL) + continue; + + ret = noti_ex_item_image_create(&item, image_type_arr[i], path); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(item); + ERR("failed to convert(%d)", ret); + return ret; + } + path = NULL; + } + + path = NULL; + ret = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_EXTENSION, &path); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + if (path == NULL) + return NOTI_EX_ERROR_NONE; + + ret = noti_ex_item_find_by_id(group, + image_type_arr[NOTIFICATION_IMAGE_TYPE_EXTENSION], &item); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_get_extension_image_size(noti, &height); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_geometry_create(&geometry, 0, 0, 0, height); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_style_create(&style, NULL, NULL, geometry); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_geometry_destroy(geometry); + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_item_set_style(&item, style); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_style_destroy(style); + ERR("failed to convert(%d)", ret); + } + + return ret; +} + +int _convert_to_legacy_image(noti_ex_item_h group, notification_h noti) +{ + int i, ret; + noti_ex_item_h item; + char *path = NULL; + noti_ex_geometry_h geometry; + noti_ex_style_h style; + int height; + + for (i = NOTIFICATION_IMAGE_TYPE_ICON; + i <= NOTIFICATION_IMAGE_TYPE_BUTTON_10; i++) { + ret = _item_find_by_id( + group, image_type_arr[i], &item, NULL, (void **)&path); + if (ret == NOTI_EX_ERROR_NOT_EXIST_ID) + continue; + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + ret = notification_set_image(noti, i, path); + free(path); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + } + + ret = _item_find_by_id(group, image_type_arr[NOTIFICATION_IMAGE_TYPE_EXTENSION], + &item, NULL, NULL); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + ret = noti_ex_item_get_style(item, &style); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_style_get_geometry(style, &geometry); + noti_ex_style_destroy(style); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_geometry_get_height(geometry, &height); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_geometry_destroy(geometry); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_set_extension_image_size(noti, height); + + return notification_convert_to_ex_error(ret); +} + +int _make_ex_action(noti_ex_item_h group, int index, + app_control_h app_control, notification_h noti) +{ + noti_ex_item_h item; + notification_button_index_e default_button; + noti_ex_action_h appcontrol_action; + int ret; + + ret = notification_get_default_button(noti, &default_button); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_item_text_create(&item, event_type_arr[index], "", NULL); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + if (default_button == (index + 1)) + ret = noti_ex_action_app_control_create(&appcontrol_action, + app_control, NULL); + else + ret = noti_ex_action_app_control_create(&appcontrol_action, + app_control, DEFAULT_BUTTON); + + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(item); + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_item_set_action(item, appcontrol_action); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(item); + noti_ex_action_destroy(appcontrol_action); + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(item); + noti_ex_action_destroy(appcontrol_action); + ERR("failed to convert(%d)", ret); + } + + return ret; +} + +int _convert_to_ex_action(notification_h noti, noti_ex_item_h group) +{ + int i, ret; + app_control_h app_control = NULL; + + for (i = NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1; + i <= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_10; i++) { + ret = notification_get_event_handler(noti, i, &app_control); + if (ret != NOTIFICATION_ERROR_NONE + && ret != NOTIFICATION_ERROR_NOT_EXIST_ID) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + if (app_control == NULL) + continue; + + ret = _make_ex_action(group, i, app_control, noti); + app_control_destroy(app_control); + app_control = NULL; + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + } + + ret = notification_get_launch_option(noti, + NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, (void *)&app_control); + if (ret == NOTIFICATION_ERROR_NOT_EXIST_ID) + return NOTI_EX_ERROR_NONE; + + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + if (app_control == NULL) + return NOTI_EX_ERROR_NONE; + + ret = _make_ex_action(group, i, app_control, noti); + app_control_destroy(app_control); + + return ret; +} + +int _make_legacy_action(noti_ex_item_h group, int index, + app_control_h *app_control, notification_h noti) +{ + noti_ex_item_h item; + int ret; + noti_ex_action_h appcontrol_action; + char *default_button = NULL; + + ret = _item_find_by_id(group, event_type_arr[index], &item, NULL, NULL); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + ret = noti_ex_item_get_action(item, &appcontrol_action); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_action_get_extra(appcontrol_action, &default_button); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + if (default_button != NULL) { + notification_set_default_button(noti, + (notification_button_index_e)(index + 1)); + free(default_button); + } + + ret = noti_ex_action_app_control_get(appcontrol_action, app_control); + noti_ex_action_destroy(appcontrol_action); + if (ret != NOTI_EX_ERROR_NONE) + ERR("failed to convert(%d)", ret); + + return ret; +} + +int _convert_to_legacy_action(noti_ex_item_h group, notification_h noti) +{ + int i, ret; + app_control_h app_control; + + for (i = NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1; + i <= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_10; i++) { + ret = _make_legacy_action(group, i, &app_control, noti); + if (ret == NOTI_EX_ERROR_NOT_EXIST_ID) + continue; + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + ret = notification_set_event_handler(noti, i, app_control); + app_control_destroy(app_control); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + } + + ret = _make_legacy_action(group, i, &app_control, noti); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + ret = notification_set_launch_option( + noti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, app_control); + app_control_destroy(app_control); + + return notification_convert_to_ex_error(ret); +} + +int _convert_to_ex_accessory( + notification_h noti, noti_ex_item_h group) +{ + int ret; + notification_sound_type_e sound_type; + notification_vibration_type_e vibration_type; + notification_led_op_e operation; + const char *path = NULL; + int led_argb, on_ms, off_ms; + noti_ex_led_info_h led_info; + noti_ex_color_h color; + + ret = notification_get_sound(noti, &sound_type, &path); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + if (sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA) { + ret = noti_ex_item_set_sound_path(group, path); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + } + + path = NULL; + ret = notification_get_vibration(noti, &vibration_type, &path); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + if (vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) { + ret = noti_ex_item_set_vibration_path(group, path); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + } + + ret = notification_get_led(noti, &operation, &led_argb); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + if (operation == NOTIFICATION_LED_OP_OFF) + return NOTI_EX_ERROR_NONE; + + if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) + ret = noti_ex_color_create(&color, led_argb >> 24 & 255, + led_argb >> 16 & 255, + led_argb >> 8 & 255, + led_argb >> 0 & 255); + else + ret = noti_ex_color_create(&color, 0, 0, 0, 0); + + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_led_info_create(&led_info, color); + noti_ex_color_destroy(color); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_get_led_time_period(noti, &on_ms, &off_ms); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + ret = noti_ex_led_info_set_on_period(led_info, on_ms); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_led_info_set_off_period(led_info, off_ms); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_item_set_led_info(group, led_info); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + noti_ex_led_info_destroy(led_info); + } + + return ret; +} + +int _convert_to_legacy_accessory(noti_ex_item_h group, notification_h noti) +{ + char *path = NULL; + int led_argb, on_ms, off_ms, ret; + noti_ex_led_info_h led_info = NULL; + noti_ex_color_h color; + unsigned char a, r, g, b; + + ret = noti_ex_item_get_sound_path(group, &path); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + if (path != NULL) { + notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_USER_DATA, path); + free(path); + path = NULL; + } + + ret = noti_ex_item_get_vibration_path(group, &path); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + if (path != NULL) { + ret = notification_set_vibration( + noti, NOTIFICATION_VIBRATION_TYPE_USER_DATA, path); + free(path); + path = NULL; + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + } + + ret = noti_ex_item_get_led_info(group, &led_info); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + if (led_info == NULL) { + notification_set_led(noti, NOTIFICATION_LED_OP_OFF, 0); + return NOTI_EX_ERROR_NONE; + } + + ret = noti_ex_led_info_get_color(led_info, &color); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_color_get_alpha(color, &a); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_color_get_red(color, &r); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_color_get_green(color, &g); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_color_get_blue(color, &b); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + led_argb = (a << 24) | (r << 16) | (g << 8) | b; + + if (led_argb == 0) + ret = notification_set_led(noti, NOTIFICATION_LED_OP_ON, led_argb); + else + ret = notification_set_led(noti, NOTIFICATION_LED_OP_ON_CUSTOM_COLOR, led_argb); + + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_led_info_get_on_period(led_info, &on_ms); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = noti_ex_led_info_get_off_period(led_info, &off_ms); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = notification_set_led_time_period(noti, on_ms, off_ms); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + noti_ex_color_destroy(color); + noti_ex_led_info_destroy(led_info); + + return ret; +} + +int _convert_to_ex_progress(notification_h noti, noti_ex_item_h group) +{ + int ret; + noti_ex_item_h ongoing_item; + notification_type_e type; + double current, max; + + ret = notification_get_type(noti, &type); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + if (type != NOTIFICATION_TYPE_ONGOING) + return NOTI_EX_ERROR_NONE; + + ret = notification_get_progress(noti, ¤t); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = notification_get_size(noti, &max); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = noti_ex_item_progress_create(&ongoing_item, + NOTIFICATION_TYPE_ONGOING_STRING, 0, (float)current, (float)max); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, ongoing_item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + noti_ex_item_destroy(ongoing_item); + return ret; + } + ret = noti_ex_item_set_policy(group, OnBootClear); + + return ret; +} + +int _convert_to_legacy_progress(noti_ex_item_h group, notification_h noti) +{ + int ret; + noti_ex_item_h item; + float current, max; + + ret = _item_find_by_id( + group, NOTIFICATION_TYPE_ONGOING_STRING, &item, NULL, NULL); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + ret = noti_ex_item_progress_get_current(item, ¤t); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + ret = noti_ex_item_progress_get_max(item, &max); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + noti->type = NOTIFICATION_TYPE_ONGOING; + ret = notification_set_progress(noti, (double)current); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + ret = notification_set_size(noti, (double)max); + + return notification_convert_to_ex_error(ret); +} + +int _convert_to_ex_layout(notification_h noti, noti_ex_item_h group) +{ + int ret; + noti_ex_item_h layout_item; + notification_ly_type_e layout; + char buf[MAX_PRO_STR_BUFSZ]; + + ret = notification_get_layout(noti, &layout); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + snprintf(buf, MAX_PRO_STR_BUFSZ, "%d", layout); + + ret = noti_ex_item_text_create(&layout_item, + NOTIFICATION_LY_TYPE_STRING, buf, NULL); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + ret = _add_child(group, layout_item, noti); + if (ret != NOTI_EX_ERROR_NONE) { + noti_ex_item_destroy(layout_item); + ERR("failed to convert(%d)", ret); + } + + return ret; +} + +int _convert_to_legacy_layout(noti_ex_item_h group, notification_h noti) +{ + int ret; + noti_ex_item_h item; + notification_ly_type_e layout; + char *text; + + ret = _item_find_by_id( + group, NOTIFICATION_LY_TYPE_STRING, &item, NULL, (void **)&text); + if (ret != NOTI_EX_ERROR_NONE) + return ret; + + layout = atoi(text); + free(text); + + ret = notification_set_layout(noti, layout); + + return notification_convert_to_ex_error(ret); +} + +int _convert_to_ex_receiver(notification_h noti, noti_ex_item_h group) +{ + int i, ret = NOTI_EX_ERROR_NONE; + int display_applist; + const char **hide_list; + bundle *hide_bundle; + int length; + + ret = notification_get_display_applist(noti, &display_applist); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return notification_convert_to_ex_error(ret); + } + + if (display_applist & NOTIFICATION_DISPLAY_APP_ALL + != NOTIFICATION_DISPLAY_APP_ALL) { + for (i = 0; i < sizeof(display_arr) / sizeof(display_arr[0]); i++) { + if (display_applist & display_arr[i]) { + ret = noti_ex_item_add_receiver(group, receiver_arr[i]); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)(%d)(%d)", ret, + display_applist, i); + return ret; + } + } + } + } + + ret = notification_get_extension_data(noti, HIDE_VIEWER_LIST, &hide_bundle); + if (ret == NOTIFICATION_ERROR_INVALID_PARAMETER) + return NOTI_EX_ERROR_NONE; + + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + hide_list = bundle_get_str_array(hide_bundle, HIDE_VIEWER_LIST, &length); + if (hide_list == NULL) { + ERR("failed to covert(%d)", get_last_result()); + return NOTI_EX_ERROR_INVALID_PARAMETER; + } + + for (i = 0; i < length; i++) { + ret = noti_ex_item_add_hide_viewer(group, hide_list[i]); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)(%d)(%d)", ret, i, length); + return ret; + } + } + + return ret; +} + +int _convert_to_legacy_receiver(noti_ex_item_h group, notification_h noti) +{ + int i, j, count, display_applist, ret; + char **receiver_list; + char **hide_list; + bundle *hide_bundle; + + ret = noti_ex_item_get_receiver_list(group, &receiver_list, &count); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + if (count == 0) { + notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL); + return NOTI_EX_ERROR_NONE; + } + + notification_set_display_applist(noti, 0); + for (i = 0; i < count; i++) { + for (j = 0; j < sizeof(receiver_arr) / sizeof(receiver_arr[0]); j++) { + if (strcmp(receiver_list[i], receiver_arr[j]) == 0) { + notification_get_display_applist(noti, &display_applist); + display_applist |= display_arr[j]; + notification_set_display_applist(noti, display_applist); + break; + } + } + free(receiver_list[i]); + } + free(receiver_list); + + noti_ex_item_get_hide_viewer_list(group, &hide_list, &count); + if (count == 0) + return NOTI_EX_ERROR_NONE; + + hide_bundle = bundle_create(); + if (hide_bundle == NULL) { + ERR("out of memory"); + ret = NOTI_EX_ERROR_OUT_OF_MEMORY; + goto out; + } + + ret = bundle_add_str_array(hide_bundle, HIDE_VIEWER_LIST, + (const char **)hide_list, count); + if (ret != BUNDLE_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + ret = NOTI_EX_ERROR_IO_ERROR; + goto out; + } + ret = notification_set_extension_data(noti, HIDE_VIEWER_LIST, hide_bundle); + ret = notification_convert_to_ex_error(ret); + +out: + for (i = 0; i < count; i++) + free(hide_list[i]); + free(hide_list); + bundle_free(hide_bundle); + return ret; +} + + +EXPORT_API int notification_convert_to_legacy( + noti_ex_item_h item, notification_h *noti) +{ + notification_h notification; + int ret, i; + char *id; + + if (item == NULL || noti == NULL) { + ERR("Invalid param"); + return NOTI_EX_ERROR_INVALID_PARAMETER; + } + + notification = notification_create(NOTIFICATION_TYPE_NOTI); + if (notification == NULL) { + ret = get_last_result(); + ERR("notification_create failed %d", ret); + return ret; + } + + noti_ex_item_get_id(item, &id); + ret = notification_set_priv_id(notification, g_quark_from_string(id)); + free(id); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + goto out; + } + + ret = noti_ex_item_get_sender_app_id(item, &id); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + goto out; + } + + ret = notification_set_pkgname(notification, id); + free(id); + if (ret != NOTIFICATION_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + goto out; + } + + for (i = 0; i < sizeof(convert_to_legacy_arr) / sizeof(convert_to_legacy_arr[0]); i++) { + ret = convert_to_legacy_arr[i](item, notification); + if (ret == NOTI_EX_ERROR_NOT_EXIST_ID) + continue; + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed (%d)(%d)", i, ret); + goto out; + } + } + +out: + if (ret == NOTI_EX_ERROR_NONE) + *noti = notification; + else + notification_free(notification); + + return ret; +} + +EXPORT_API int notification_convert_to_ex( + notification_h noti, noti_ex_item_h *item) +{ + int ret, i; + noti_ex_item_h group_item; + const char *id = NULL; + const char *tag = NULL; + char *priv_id; + + if (noti == NULL || item == NULL) { + ERR("Invalid param"); + return NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (noti->priv_id > 0) { /* case of update */ + id = g_quark_to_string(noti->priv_id); + } else { /* case of insert */ + notification_get_tag(noti, &tag); + if (tag != NULL) + id = tag; + } + + ret = noti_ex_item_group_create(&group_item, id); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + return ret; + } + + notification_get_pkgname(noti, (char **)&id); + ret = noti_ex_item_set_sender_app_id(group_item, id); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + goto out; + } + + for (i = 0; i < sizeof(convert_to_ex_arr) / sizeof(convert_to_ex_arr[0]); i++) { + ret = convert_to_ex_arr[i](noti, group_item); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed (%d)(%d)", i, ret); + goto out; + } + } + +out: + if (ret == NOTI_EX_ERROR_NONE) { + if (noti->priv_id <= 0) { + ret = noti_ex_item_get_id(group_item, &priv_id); + if (ret != NOTI_EX_ERROR_NONE) { + ERR("failed to convert(%d)", ret); + noti_ex_item_destroy(group_item); + return notification_convert_to_legacy_error(ret); + } + notification_set_priv_id(noti, g_quark_from_string(priv_id)); + free(priv_id); + } + + *item = group_item; + } else { + noti_ex_item_destroy(group_item); + } + + return notification_convert_to_legacy_error(ret); +} + diff --git a/notification/src/notification_enum_string.h b/notification/src/notification_enum_string.h new file mode 100644 index 0000000..809e85a --- /dev/null +++ b/notification/src/notification_enum_string.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define NOTIFICATION_TYPE_ONGOING_STRING "NOTIFICATION_TYPE_ONGOING" +#define NOTIFICATION_LY_TYPE_STRING "NOTIFICATION_LY_TYPE" +#define NOTIFICATION_TIME_STRING "NOTIFICATION_TIME" +#define NOTIFICATION_INSERT_TIME_STRING "NOTIFICATION_INSERT_TIME" +#define NOTIFICATION_PROPERTY_STRING "NOTIFICATION_PROPERTY" +#define NOTIFICATION_TAG_STRING "NOTIFICATION_TAG" +#define NOTIFICATION_EVENT_FLAG_STRING "NOTIFICATION_EVENT_FLAG" +#define NOTIFICATION_TEXT_INPUT_LENGTH_STRING "NOTIFICATION_TEXT_INPUT_LENGTH" +#define NOTIFICATION_AUTO_REMOVE_STRING "NOTIFICATION_AUTO_REMOVE" + +const char *image_type_arr[] = { + "NOTIFICATION_IMAGE_TYPE_ICON", + "NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR", + "NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK", + "NOTIFICATION_IMAGE_TYPE_THUMBNAIL", + "NOTIFICATION_IMAGE_TYPE_THUMBNAIL_FOR_LOCK", + "NOTIFICATION_IMAGE_TYPE_ICON_SUB", + "NOTIFICATION_IMAGE_TYPE_BACKGROUND", + "NOTIFICATION_IMAGE_TYPE_LIST_1", + "NOTIFICATION_IMAGE_TYPE_LIST_2", + "NOTIFICATION_IMAGE_TYPE_LIST_3", + "NOTIFICATION_IMAGE_TYPE_LIST_4", + "NOTIFICATION_IMAGE_TYPE_LIST_5", + "NOTIFICATION_IMAGE_TYPE_BUTTON_1", + "NOTIFICATION_IMAGE_TYPE_BUTTON_2", + "NOTIFICATION_IMAGE_TYPE_BUTTON_3", + "NOTIFICATION_IMAGE_TYPE_BUTTON_4", + "NOTIFICATION_IMAGE_TYPE_BUTTON_5", + "NOTIFICATION_IMAGE_TYPE_BUTTON_6", + "NOTIFICATION_IMAGE_TYPE_TEXT_INPUT_BUTTON", + "NOTIFICATION_IMAGE_TYPE_EXTENSION", + "NOTIFICATION_IMAGE_TYPE_BUTTON_7", + "NOTIFICATION_IMAGE_TYPE_BUTTON_8", + "NOTIFICATION_IMAGE_TYPE_BUTTON_9", + "NOTIFICATION_IMAGE_TYPE_BUTTON_10" +}; + +const char *text_type_arr[] = { + "NOTIFICATION_TEXT_TYPE_TITLE", + "NOTIFICATION_TEXT_TYPE_CONTENT", + "NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF", + "NOTIFICATION_TEXT_TYPE_EVENT_COUNT", + "NOTIFICATION_TEXT_TYPE_INFO_1", + "NOTIFICATION_TEXT_TYPE_INFO_SUB_1", + "NOTIFICATION_TEXT_TYPE_INFO_2", + "NOTIFICATION_TEXT_TYPE_INFO_SUB_2", + "NOTIFICATION_TEXT_TYPE_INFO_3", + "NOTIFICATION_TEXT_TYPE_INFO_SUB_3", + "NOTIFICATION_TEXT_TYPE_GROUP_TITLE", + "NOTIFICATION_TEXT_TYPE_GROUP_CONTENT", + "NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF", + "NOTIFICATION_TEXT_TYPE_BUTTON_1", + "NOTIFICATION_TEXT_TYPE_BUTTON_2", + "NOTIFICATION_TEXT_TYPE_BUTTON_3", + "NOTIFICATION_TEXT_TYPE_BUTTON_4", + "NOTIFICATION_TEXT_TYPE_BUTTON_5", + "NOTIFICATION_TEXT_TYPE_BUTTON_6", + "NOTIFICATION_TEXT_TYPE_TEXT_INPUT_PLACEHOLDER", + "NOTIFICATION_TEXT_TYPE_TEXT_INPUT_BUTTON", + "NOTIFICATION_TEXT_TYPE_CONTENT_EXTENSION", + "NOTIFICATION_TEXT_TYPE_BUTTON_7", + "NOTIFICATION_TEXT_TYPE_BUTTON_8", + "NOTIFICATION_TEXT_TYPE_BUTTON_9", + "NOTIFICATION_TEXT_TYPE_BUTTON_10" +}; + +const char *event_type_arr[] = { + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_7", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_8", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_9", + "NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_10", + "NOTIFICATION_LAUNCH_OPTION_APP_CONTROL" +}; diff --git a/packaging/notification.spec b/packaging/notification.spec index 2abc8a4..8d3d3ac 100644 --- a/packaging/notification.spec +++ b/packaging/notification.spec @@ -103,6 +103,7 @@ fi %{_includedir}/notification/notification_setting.h %{_includedir}/notification/notification_setting_internal.h %{_includedir}/notification/notification_ipc.h +%{_includedir}/notification/notification_convert.h %{_includedir}/notification/notification_noti.h %{_includedir}/notification/notification_setting_service.h %{_includedir}/notification/notification_viewer.h |