From: Kyuho Jo Date: Thu, 30 Apr 2015 09:48:37 +0000 (+0900) Subject: 1. New API set for notification settings. X-Git-Tag: submit/tizen_mobile/20150527.071719^2~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0bb7953ff37b994224745d92dd044cc44b728c91;p=platform%2Fcore%2Fapi%2Fnotification.git 1. New API set for notification settings. 2. notification_set_event_handler/notification_get_event_handler are implemented. Change-Id: I63ae26521a3bee757551b581316267fdf322ef86 Signed-off-by: Kyuho Jo --- diff --git a/AUTHORS b/AUTHORS old mode 100755 new mode 100644 diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index 8afaab4b..4c28f8ec --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ SET(DBFILE ".notification.db") SET(MAJOR_VER 0) SET(VERSION ${MAJOR_VER}.1.0) -# ADD_SUBDIRECTORY(test-app) +ADD_SUBDIRECTORY(test-app) SET(SRCS ./src/notification.c diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/TC/_export_env.sh b/TC/_export_env.sh old mode 100755 new mode 100644 diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh old mode 100755 new mode 100644 diff --git a/TC/build.sh b/TC/build.sh old mode 100755 new mode 100644 diff --git a/TC/clean.sh b/TC/clean.sh old mode 100755 new mode 100644 diff --git a/TC/config b/TC/config old mode 100755 new mode 100644 diff --git a/TC/push.sh b/TC/push.sh old mode 100755 new mode 100644 diff --git a/TC/run.sh b/TC/run.sh old mode 100755 new mode 100644 diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile old mode 100755 new mode 100644 diff --git a/TC/testcase/tslist b/TC/testcase/tslist old mode 100755 new mode 100644 diff --git a/TC/testcase/utc_notification.c b/TC/testcase/utc_notification.c old mode 100755 new mode 100644 diff --git a/TC/testcase/utc_notification_list.c b/TC/testcase/utc_notification_list.c old mode 100755 new mode 100644 diff --git a/TC/testcase/utc_notification_setting.c b/TC/testcase/utc_notification_setting.c old mode 100755 new mode 100644 diff --git a/TC/testcase/utc_notification_status.c b/TC/testcase/utc_notification_status.c old mode 100755 new mode 100644 diff --git a/TC/tet_scen b/TC/tet_scen old mode 100755 new mode 100644 diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg old mode 100755 new mode 100644 diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg old mode 100755 new mode 100644 diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg old mode 100755 new mode 100644 diff --git a/debian/control b/debian/control old mode 100755 new mode 100644 diff --git a/debian/libnotification-0.postinst.in b/debian/libnotification-0.postinst.in old mode 100755 new mode 100644 diff --git a/debian/rules b/debian/rules old mode 100755 new mode 100644 diff --git a/doc/notification_doc.h b/doc/notification_doc.h old mode 100755 new mode 100644 diff --git a/include/notification_db.h b/include/notification_db.h old mode 100755 new mode 100644 diff --git a/include/notification_error.h b/include/notification_error.h old mode 100755 new mode 100644 diff --git a/include/notification_group.h b/include/notification_group.h old mode 100755 new mode 100644 diff --git a/include/notification_ipc.h b/include/notification_ipc.h index 0eb78278..204d135a 100755 --- a/include/notification_ipc.h +++ b/include/notification_ipc.h @@ -23,6 +23,7 @@ #define __NOTIFICATION_IPC_H__ #include +#include #define NOTIFICATION_ADDR "/tmp/.notification.service" #define NOTIFICATION_DEL_PACKET_UNIT 10 @@ -53,6 +54,7 @@ int notification_ipc_is_master_ready(void); int notification_ipc_add_deffered_task(void (*deferred_task_cb)(void *data), void *user_data); int notification_ipc_del_deffered_task(void (*deferred_task_cb)(void *data)); +int notification_ipc_update_setting(notification_setting_h setting); int notification_ipc_noti_setting_property_set(const char *pkgname, const char *property, const char *value); int notification_ipc_noti_setting_property_get(const char *pkgname, const char *property, char **value); diff --git a/include/notification_list.h b/include/notification_list.h old mode 100755 new mode 100644 diff --git a/include/notification_noti.h b/include/notification_noti.h old mode 100755 new mode 100644 diff --git a/include/notification_ongoing.h b/include/notification_ongoing.h old mode 100755 new mode 100644 diff --git a/include/notification_private.h b/include/notification_private.h index a5c7cb01..21b5e8c4 100755 --- a/include/notification_private.h +++ b/include/notification_private.h @@ -44,6 +44,8 @@ struct _notification { bundle *b_service_single_launch; bundle *b_service_multi_launch; + bundle *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX]; + char *domain; /* Text domain for localization */ char *dir; /* Text dir for localization */ @@ -81,4 +83,6 @@ struct _notification { void notification_call_changed_cb(notification_op *op_list, int op_num); +char *notification_get_pkgname_by_pid(void); + #endif /* __NOTIFICATION_PRIVATE_H__ */ diff --git a/include/notification_setting.h b/include/notification_setting.h index 0bc92bbd..a06fef65 100755 --- a/include/notification_setting.h +++ b/include/notification_setting.h @@ -22,49 +22,23 @@ #ifndef __NOTIFICATION_SETTING_H__ #define __NOTIFICATION_SETTING_H__ -#include - -typedef struct _notification_setting_h notification_setting_h; +#include +#include "notification.h" #ifdef __cplusplus extern "C" { #endif -typedef enum _notification_setting_property { - NOTIFICATION_SETTING_PROPERTY_ALLOW_TO_NOTIFY = 1, - NOTIFICATION_SETTING_PROPERTY_DO_NOT_DISTURB = 2, - NOTIFICATION_SETTING_PROPERTY_VISIBILITY_CLASS = 3, -} notification_setting_property_e; +typedef struct notification_setting* notification_setting_h; +int notification_setting_get_setting(notification_setting_h *setting); +int notification_setting_get_visibility_class(notification_setting_h setting, int *value); +int notification_setting_set_visibility_class(notification_setting_h setting, int value); -/** - * @internal - * @brief This function sets notification property for designated package. - * @since_tizen 2.3 - * @privlevel public - * @privilege http://tizen.org/privilege/core/notification - * @param[in] pkgname The name of designated package - * @param[in] property name - * @param[in] property value - * @return #NOTIFICATION_ERROR_NONE if success, other value if failure - * @see #notification_error_e - */ -int notification_setting_property_set(const char *pkgname, const char *property, const char *value); +int notification_setting_update_setting(notification_setting_h setting); -/** - * @internal - * @brief This function gets notification property for designated package. - * @since_tizen 2.3 - * @privlevel public - * @privilege http://tizen.org/privilege/core/notification - * @param[in] pkgname The name of designated package - * @param[in] property name - * @param[in] pointer which can save the getting value - * @return #NOTIFICATION_ERROR_NONE if success, other value if failure - * @see #notification - */ -int notification_setting_property_get(const char *pkgname, const char *property, char **value); +int notification_setting_free_notification(notification_setting_h setting); #ifdef __cplusplus } diff --git a/include/notification_setting_internal.h b/include/notification_setting_internal.h new file mode 100755 index 00000000..bee4d1d4 --- /dev/null +++ b/include/notification_setting_internal.h @@ -0,0 +1,59 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung , Mi-Ju Lee , Xi Zhichan + * + * 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 INCLUDE_NOTIFICATION_SETTING_INTERNAL_H_ +#define INCLUDE_NOTIFICATION_SETTING_INTERNAL_H_ + +#include +#include "notification.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct notification_setting { + char *package_name; + bool allow_to_notify; + bool do_not_disturb_except; + int visibility_class; +}; + +int notification_setting_get_setting_array(notification_setting_h *setting_array, int *count); +int notification_setting_get_setting_by_package_name(const char *package_name, notification_setting_h *setting); + +int notification_setting_get_package_name(notification_setting_h setting, char **value); +int notification_setting_set_package_name(notification_setting_h setting, char *value); + +int notification_setting_get_allow_to_notify(notification_setting_h setting, bool *value); +int notification_setting_set_allow_to_notify(notification_setting_h setting, bool value); + +int notification_setting_get_do_not_disturb_except(notification_setting_h setting, bool *value); +int notification_setting_set_do_not_disturb_except(notification_setting_h setting, bool value); + + +/* OLD IMPLEMENTATION */ +int notification_setting_property_set(const char *pkgname, const char *property, const char *value) NOTIFICATION_DEPRECATED_API; +int notification_setting_property_get(const char *pkgname, const char *property, char **value) NOTIFICATION_DEPRECATED_API; + +#ifdef __cplusplus +} +#endif +#endif /* INCLUDE_NOTIFICATION_SETTING_INTERNAL_H_ */ diff --git a/include/notification_setting_service.h b/include/notification_setting_service.h index 789d60e1..a27af00c 100755 --- a/include/notification_setting_service.h +++ b/include/notification_setting_service.h @@ -31,6 +31,8 @@ extern "C" { int notification_setting_db_set(const char *pkgname, const char *property, const char *value); int notification_setting_db_get(const char *pkgname, const char *property, char **value); +int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class); + #ifdef __cplusplus } #endif diff --git a/include/notification_status.h b/include/notification_status.h old mode 100755 new mode 100644 diff --git a/include/notification_type.h b/include/notification_type.h index b606c469..6e940029 100755 --- a/include/notification_type.h +++ b/include/notification_type.h @@ -79,14 +79,15 @@ typedef enum _notification_launch_option_type { * @since_tizen 2.4 */ typedef enum _notification_event_type { - NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1 = 1, /** < Event type : Click on button 1 */ - NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2 = 2, /** < Event type : Click on button 2 */ - NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3 = 3, /** < Event type : Click on button 3 */ - NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4 = 4, /** < Event type : Click on button 4 */ - NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5 = 5, /** < Event type : Click on button 5 */ - NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6 = 6, /** < Event type : Click on button 6 */ - NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON = 5, /** < Event type : Click on icon */ - NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL = 6, /** < Event type : Click on thumbnail */ + NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1 = 0, /** < Event type : Click on button 1 */ + NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2 = 1, /** < Event type : Click on button 2 */ + NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3 = 2, /** < Event type : Click on button 3 */ + NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4 = 3, /** < Event type : Click on button 4 */ + NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5 = 4, /** < Event type : Click on button 5 */ + NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6 = 5, /** < Event type : Click on button 6 */ + NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON = 6, /** < Event type : Click on icon */ + NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL = 7, /** < Event type : Click on thumbnail */ + NOTIFICATION_EVENT_TYPE_MAX, } notification_event_type_e; /** diff --git a/notification-service.pc.in b/notification-service.pc.in old mode 100755 new mode 100644 diff --git a/notification.manifest b/notification.manifest old mode 100755 new mode 100644 diff --git a/notification.pc.in b/notification.pc.in old mode 100755 new mode 100644 diff --git a/packaging/notification.spec b/packaging/notification.spec index 4cc7d46b..7c52b2d0 100755 --- a/packaging/notification.spec +++ b/packaging/notification.spec @@ -1,6 +1,6 @@ Name: notification Summary: notification library -Version: 0.2.27 +Version: 0.2.28 Release: 1 Group: TBD License: Apache @@ -111,6 +111,14 @@ then b_service_responding TEXT, b_service_single_launch TEXT, b_service_multi_launch TEXT, + b_event_handler_click_on_button_1 TEXT, + b_event_handler_click_on_button_2 TEXT, + b_event_handler_click_on_button_3 TEXT, + b_event_handler_click_on_button_4 TEXT, + b_event_handler_click_on_button_5 TEXT, + b_event_handler_click_on_button_6 TEXT, + b_event_handler_click_on_icon TEXT, + b_event_handler_click_on_thumbnail TEXT, sound_type INTEGER default 0, sound_path TEXT, vibration_type INTEGER default 0, @@ -140,7 +148,7 @@ then rowid INTEGER PRIMARY KEY AUTOINCREMENT, UNIQUE (caller_pkgname, group_id) ); - create table if not exists ongoing_list ( + create table if not exists ongoing_list ( caller_pkgname TEXT NOT NULL, launch_pkgname TEXT, icon_path TEXT, @@ -160,9 +168,25 @@ then flag INTEGER default 0, progress_size DOUBLE default 0, progress_percentage DOUBLE default 0, - rowid INTEGER PRIMARY KEY AUTOINCREMENT, - UNIQUE (caller_pkgname, priv_id) + rowid INTEGER PRIMARY KEY AUTOINCREMENT, + UNIQUE (caller_pkgname, priv_id) ); + CREATE TABLE IF NOT EXISTS notification_setting ( + priv_id INTERGER PRIMARY KEY, + package_name TEXT NOT NULL, + allow_to_notify INTEGER DEFAULT 1, + do_not_disturb_except INTEGER DEFAULT 0, + visibility_class INTEGER DEFAULT 0, + UNIQUE (priv_id, package_name) + ); + + INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (1, "org.tizen.photos", 1, 0, 0); + INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (2, "org.tizen.email", 1, 0, 0); + INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (3, "org.tizen.message", 1, 0, 0); + INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (4, "org.tizen.internet", 1, 0, 0); + INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (5, "org.tizen.games", 1, 0, 0); + + CREATE UNIQUE INDEX package_name_idx1 ON notification_setting (package_name); ' fi diff --git a/src/notification.c b/src/notification.c index 419f52ab..77f9714d 100755 --- a/src/notification.c +++ b/src/notification.c @@ -71,7 +71,7 @@ static void (*posted_toast_message_cb) (void *data); #define NOTI_TEXT_RESULT_LEN 2048 #define NOTI_PKGNAME_LEN 512 -static char *_notification_get_pkgname_by_pid(void) +char *notification_get_pkgname_by_pid(void) { char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, }; int pid = 0, ret = AUL_R_OK; @@ -1413,12 +1413,91 @@ EXPORT_API int notification_get_launch_option(notification_h noti, EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler) { - return NOTIFICATION_ERROR_INVALID_OPERATION; + int err = NOTIFICATION_ERROR_NONE; + bundle *app_control_bundle = NULL; + + if (noti == NULL) { + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1 + || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) { + NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + if ((err = app_control_to_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) { + NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err); + goto out; + } + + if (noti->b_event_handler[event_type] != NULL) { + bundle_free(noti->b_event_handler[event_type]); + } + + noti->b_event_handler[event_type] = app_control_bundle; + +out: + return err; } EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler) { - return NOTIFICATION_ERROR_INVALID_OPERATION; + int err = NOTIFICATION_ERROR_NONE; + bundle *b = NULL; + app_control_h app_control_new = NULL; + + if (noti == NULL) { + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); + goto out; + } + if (event_handler == NULL) { + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); + goto out; + } + if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1 + || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) { + NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + b = noti->b_event_handler[event_type]; + + if (b == NULL) { + NOTIFICATION_DBG("No event handler\n"); + err = NOTIFICATION_ERROR_NOT_EXIST_ID; + goto out; + } + + err = app_control_create(&app_control_new); + if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) { + NOTIFICATION_ERR("app_control_create failed [%d]", err); + err = NOTIFICATION_ERROR_IO_ERROR; + goto out; + } + + err = app_control_import_from_bundle(app_control_new, b); + if (err == APP_CONTROL_ERROR_NONE) { + *event_handler = app_control_new; + } + else { + app_control_destroy(app_control_new); + NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err); + err = NOTIFICATION_ERROR_IO_ERROR; + goto out; + } + +out: + if (event_handler) + *event_handler = app_control_new; + + return err; } EXPORT_API int notification_set_execute_option(notification_h noti, @@ -1946,7 +2025,7 @@ EXPORT_API int notification_delete_all(notification_type_e type) return NOTIFICATION_ERROR_INVALID_PARAMETER; } - caller_pkgname = _notification_get_pkgname_by_pid(); + caller_pkgname = notification_get_pkgname_by_pid(); ret = notification_ipc_request_delete_multiple(type, caller_pkgname); @@ -1968,7 +2047,7 @@ EXPORT_API int notification_delete_all_by_type(const char *pkgname, } if (pkgname == NULL) { - caller_pkgname = _notification_get_pkgname_by_pid(); + caller_pkgname = notification_get_pkgname_by_pid(); } else { caller_pkgname = strdup(pkgname); } @@ -1994,7 +2073,7 @@ EXPORT_API int notification_delete_by_priv_id(const char *pkgname, } if (pkgname == NULL) { - caller_pkgname = _notification_get_pkgname_by_pid(); + caller_pkgname = notification_get_pkgname_by_pid(); } else { caller_pkgname = strdup(pkgname); } @@ -2041,7 +2120,7 @@ EXPORT_API int notification_update_progress(notification_h noti, } if (noti == NULL) { - caller_pkgname = _notification_get_pkgname_by_pid(); + caller_pkgname = notification_get_pkgname_by_pid(); } else { caller_pkgname = strdup(noti->caller_pkgname); } @@ -2084,7 +2163,7 @@ EXPORT_API int notification_update_size(notification_h noti, } if (noti == NULL) { - caller_pkgname = _notification_get_pkgname_by_pid(); + caller_pkgname = notification_get_pkgname_by_pid(); } else { caller_pkgname = strdup(noti->caller_pkgname); } @@ -2124,7 +2203,7 @@ EXPORT_API int notification_update_content(notification_h noti, } if (noti == NULL) { - caller_pkgname = _notification_get_pkgname_by_pid(); + caller_pkgname = notification_get_pkgname_by_pid(); } else { caller_pkgname = strdup(noti->caller_pkgname); } @@ -2163,7 +2242,7 @@ static notification_h _notification_create(notification_type_e type) else if (type == NOTIFICATION_TYPE_ONGOING) noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS; - noti->caller_pkgname = _notification_get_pkgname_by_pid(); + noti->caller_pkgname = notification_get_pkgname_by_pid(); noti->group_id = NOTIFICATION_GROUP_ID_NONE; noti->priv_id = NOTIFICATION_PRIV_ID_NONE; noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE; @@ -2222,7 +2301,7 @@ EXPORT_API notification_h notification_load_by_tag(const char *tag) return NULL; } - caller_pkgname = _notification_get_pkgname_by_pid(); + caller_pkgname = notification_get_pkgname_by_pid(); if (!caller_pkgname) { NOTIFICATION_ERR("Failed to get a package name"); set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY); @@ -2255,6 +2334,7 @@ EXPORT_API notification_h notification_load_by_tag(const char *tag) EXPORT_API int notification_clone(notification_h noti, notification_h *clone) { + int i = 0; notification_h new_noti = NULL; if (noti == NULL || clone == NULL) { @@ -2278,7 +2358,7 @@ EXPORT_API int notification_clone(notification_h noti, notification_h *clone) if(noti->caller_pkgname != NULL) { new_noti->caller_pkgname = strdup(noti->caller_pkgname); } else { - new_noti->caller_pkgname = _notification_get_pkgname_by_pid(); + new_noti->caller_pkgname = notification_get_pkgname_by_pid(); } if(noti->launch_pkgname != NULL) { new_noti->launch_pkgname = strdup(noti->launch_pkgname); @@ -2318,6 +2398,14 @@ EXPORT_API int notification_clone(notification_h noti, notification_h *clone) new_noti->b_service_multi_launch = NULL; } + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + if(noti->b_event_handler[i] != NULL) { + new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]); + } else { + new_noti->b_event_handler[i] = NULL; + } + } + new_noti->sound_type = noti->sound_type; if(noti->sound_path != NULL) { new_noti->sound_path = strdup(noti->sound_path); @@ -2391,6 +2479,7 @@ EXPORT_API int notification_clone(notification_h noti, notification_h *clone) EXPORT_API int notification_free(notification_h noti) { + int i = 0; if (noti == NULL) { return NOTIFICATION_ERROR_INVALID_PARAMETER; } @@ -2421,6 +2510,12 @@ EXPORT_API int notification_free(notification_h noti) bundle_free(noti->b_service_multi_launch); } + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + if(noti->b_event_handler[i] != NULL) { + bundle_free(noti->b_event_handler[i]); + } + } + if (noti->sound_path) { free(noti->sound_path); } @@ -3039,7 +3134,7 @@ EXPORT_API int notification_delete_group_by_group_id(const char *pkgname, char *caller_pkgname = NULL; if (pkgname == NULL) { - caller_pkgname = _notification_get_pkgname_by_pid(); + caller_pkgname = notification_get_pkgname_by_pid(); } else { caller_pkgname = strdup(pkgname); } @@ -3066,7 +3161,7 @@ EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname, char *caller_pkgname = NULL; if (pkgname == NULL) { - caller_pkgname = _notification_get_pkgname_by_pid(); + caller_pkgname = notification_get_pkgname_by_pid(); } else { caller_pkgname = strdup(pkgname); } diff --git a/src/notification_db.c b/src/notification_db.c old mode 100755 new mode 100644 diff --git a/src/notification_group.c b/src/notification_group.c old mode 100755 new mode 100644 diff --git a/src/notification_ipc.c b/src/notification_ipc.c index bc2024e8..741af31b 100755 --- a/src/notification_ipc.c +++ b/src/notification_ipc.c @@ -35,6 +35,7 @@ #include #include #include +#include #define NOTIFICATION_IPC_TIMEOUT 0.0 @@ -361,6 +362,7 @@ static inline bundle *_create_bundle_from_string(unsigned char *string) */ EXPORT_API int notification_ipc_make_noti_from_packet(notification_h noti, const struct packet *packet) { + int i = 0; int ret = 0; int type; int layout; @@ -375,6 +377,7 @@ EXPORT_API int notification_ipc_make_noti_from_packet(notification_h noti, const unsigned char *b_service_responding = NULL; unsigned char *b_service_single_launch = NULL; unsigned char *b_service_multi_launch = NULL; + unsigned char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL, }; char *domain = NULL; char *dir = NULL; unsigned char *b_text = NULL; @@ -408,7 +411,7 @@ EXPORT_API int notification_ipc_make_noti_from_packet(notification_h noti, const } ret = packet_get(packet, - "iiiiisssssssssssssisisisiiiiiiiiddsssss", + "iiiiisssssssssssssssssssssisisisiiiiiiiiddsssss", &type, &layout, &group_id, @@ -422,6 +425,14 @@ EXPORT_API int notification_ipc_make_noti_from_packet(notification_h noti, const &b_service_responding, &b_service_single_launch, &b_service_multi_launch, + &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1], + &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2], + &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3], + &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4], + &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5], + &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6], + &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON], + &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL], &domain, &dir, &b_text, @@ -449,7 +460,7 @@ EXPORT_API int notification_ipc_make_noti_from_packet(notification_h noti, const &temp_content, &tag); - if (ret != 39) { + if (ret != 47) { NOTIFICATION_ERR("failed to create a noti from packet"); return NOTIFICATION_ERROR_INVALID_PARAMETER; } @@ -468,6 +479,9 @@ EXPORT_API int notification_ipc_make_noti_from_packet(notification_h noti, const noti->b_service_responding = _create_bundle_from_string(b_service_responding); noti->b_service_single_launch = _create_bundle_from_string(b_service_single_launch); noti->b_service_multi_launch = _create_bundle_from_string(b_service_multi_launch); + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + noti->b_event_handler[i] = _create_bundle_from_string(b_event_handler[i]); + } noti->domain = _dup_string(domain); noti->dir = _dup_string(dir); noti->b_text = _create_bundle_from_string(b_text); @@ -506,6 +520,7 @@ EXPORT_API int notification_ipc_make_noti_from_packet(notification_h noti, const EXPORT_API struct packet *notification_ipc_make_packet_from_noti(notification_h noti, const char *command, int packet_type) { + int i = 0; int b_encode_len = 0; struct packet *result = NULL; char *args = NULL; @@ -515,6 +530,7 @@ EXPORT_API struct packet *notification_ipc_make_packet_from_noti(notification_h char *b_service_responding = NULL; char *b_service_single_launch = NULL; char *b_service_multi_launch = NULL; + char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , }; char *b_text = NULL; char *b_key = NULL; char *b_format_args = NULL; @@ -548,6 +564,13 @@ EXPORT_API struct packet *notification_ipc_make_packet_from_noti(notification_h (bundle_raw **) & b_service_multi_launch, &b_encode_len); } + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + if (noti->b_event_handler[i]) { + bundle_encode(noti->b_event_handler[i], + (bundle_raw **) & b_event_handler[i], &b_encode_len); + } + } + if (noti->b_text) { bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len); } @@ -591,7 +614,7 @@ EXPORT_API struct packet *notification_ipc_make_packet_from_noti(notification_h } result = func_to_create_packet(command, - "iiiiisssssssssssssisisisiiiiiiiiddsssss", + "iiiiisssssssssssssssssssssisisisiiiiiiiiddsssss", noti->type, noti->layout, noti->group_id, @@ -605,6 +628,14 @@ EXPORT_API struct packet *notification_ipc_make_packet_from_noti(notification_h NOTIFICATION_CHECK_STR(b_service_responding), NOTIFICATION_CHECK_STR(b_service_single_launch), NOTIFICATION_CHECK_STR(b_service_multi_launch), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]), NOTIFICATION_CHECK_STR(noti->domain), NOTIFICATION_CHECK_STR(noti->dir), NOTIFICATION_CHECK_STR(b_text), @@ -654,6 +685,12 @@ out: free(b_service_multi_launch); } + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + if (b_event_handler[i]) { + free(b_event_handler[i]); + } + } + if (b_text) { free(b_text); } @@ -673,6 +710,7 @@ out: EXPORT_API struct packet *notification_ipc_make_reply_packet_from_noti(notification_h noti, struct packet *packet) { + int i = 0; int b_encode_len = 0; struct packet *result = NULL; char *args = NULL; @@ -682,6 +720,7 @@ EXPORT_API struct packet *notification_ipc_make_reply_packet_from_noti(notificat char *b_service_responding = NULL; char *b_service_single_launch = NULL; char *b_service_multi_launch = NULL; + char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , }; char *b_text = NULL; char *b_key = NULL; char *b_format_args = NULL; @@ -714,6 +753,13 @@ EXPORT_API struct packet *notification_ipc_make_reply_packet_from_noti(notificat (bundle_raw **) & b_service_multi_launch, &b_encode_len); } + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + if (noti->b_event_handler[i]) { + bundle_encode(noti->b_event_handler[i], + (bundle_raw **) & b_event_handler[i], &b_encode_len); + } + } + if (noti->b_text) { bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len); } @@ -749,7 +795,7 @@ EXPORT_API struct packet *notification_ipc_make_reply_packet_from_noti(notificat } result = packet_create_reply(packet, - "iiiiisssssssssssssisisisiiiiiiiiddsssss", + "iiiiisssssssssssssssssssssisisisiiiiiiiiddsssss", noti->type, noti->layout, noti->group_id, @@ -763,6 +809,14 @@ EXPORT_API struct packet *notification_ipc_make_reply_packet_from_noti(notificat NOTIFICATION_CHECK_STR(b_service_responding), NOTIFICATION_CHECK_STR(b_service_single_launch), NOTIFICATION_CHECK_STR(b_service_multi_launch), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]), NOTIFICATION_CHECK_STR(noti->domain), NOTIFICATION_CHECK_STR(noti->dir), NOTIFICATION_CHECK_STR(b_text), @@ -811,6 +865,12 @@ EXPORT_API struct packet *notification_ipc_make_reply_packet_from_noti(notificat free(b_service_multi_launch); } + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + if (b_event_handler[i]) { + free(b_event_handler[i]); + } + } + if (b_text) { free(b_text); } @@ -1393,6 +1453,40 @@ int notification_ipc_request_refresh(void) return status; } + +int notification_ipc_update_setting(notification_setting_h setting) +{ + int status = 0; + int ret = 0; + struct packet *packet; + struct packet *result; + + packet = packet_create("update_noti_setting", "siii", setting->package_name, (int)setting->allow_to_notify, (int)setting->do_not_disturb_except, (int)setting->visibility_class); + result = com_core_packet_oneshot_send(NOTIFICATION_ADDR, + packet, + NOTIFICATION_IPC_TIMEOUT); + packet_destroy(packet); + + if (result != NULL) { + if (packet_get(result, "ii", &status, &ret) != 2) { + NOTIFICATION_ERR("Failed to get a result packet"); + packet_unref(result); + return NOTIFICATION_ERROR_IO_ERROR; + } + packet_unref(result); + } else { + NOTIFICATION_ERR("failed to receive answer(delete)"); + if (notification_ipc_is_master_ready() == 1) { + return NOTIFICATION_ERROR_PERMISSION_DENIED; + } + else { + return NOTIFICATION_ERROR_SERVICE_NOT_READY; + } + } + + return status; +} + int notification_ipc_noti_setting_property_set(const char *pkgname, const char *property, const char *value) { int status = 0; diff --git a/src/notification_list.c b/src/notification_list.c old mode 100755 new mode 100644 diff --git a/src/notification_noti.c b/src/notification_noti.c index dbfdd0aa..075ea10f 100755 --- a/src/notification_noti.c +++ b/src/notification_noti.c @@ -35,8 +35,6 @@ #include #define NOTI_BURST_DELETE_UNIT 10 -static Eina_List *toast_list; -static Eina_List *toast_popup; static void __free_and_set(void **target_ptr, void *new_ptr) { if (target_ptr != NULL) { @@ -185,6 +183,7 @@ err: static int _insertion_query_create(notification_h noti, char **query) { + int i = 0; int b_encode_len = 0; char *args = NULL; char *group_args = NULL; @@ -193,6 +192,7 @@ static int _insertion_query_create(notification_h noti, char **query) char *b_service_responding = NULL; char *b_service_single_launch = NULL; char *b_service_multi_launch = NULL; + char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , }; char *b_text = NULL; char *b_key = NULL; char *b_format_args = NULL; @@ -228,6 +228,13 @@ static int _insertion_query_create(notification_h noti, char **query) (bundle_raw **) & b_service_multi_launch, &b_encode_len); } + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + if (noti->b_event_handler[i]) { + bundle_encode(noti->b_event_handler[i], + (bundle_raw **) & b_event_handler[i], &b_encode_len); + } + } + if (noti->b_text) { bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len); } @@ -263,6 +270,9 @@ static int _insertion_query_create(notification_h noti, char **query) "args, group_args, " "b_execute_option, " "b_service_responding, b_service_single_launch, b_service_multi_launch, " + "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, " + "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, " + "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) values (" @@ -278,6 +288,9 @@ static int _insertion_query_create(notification_h noti, char **query) "'%s', '%s', " "'%s', " "'%s', '%s', '%s', " + "'%s', '%s', '%s', " + "'%s', '%s', '%s', " + "'%s', '%s', " "%d, '%s', %d, '%s', %d, %d, %d, %d," "%d, %d, %d, " "$progress_size, $progress_percentage)", @@ -297,6 +310,14 @@ static int _insertion_query_create(notification_h noti, char **query) NOTIFICATION_CHECK_STR(b_service_responding), NOTIFICATION_CHECK_STR(b_service_single_launch), NOTIFICATION_CHECK_STR(b_service_multi_launch), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]), noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path), noti->vibration_type, NOTIFICATION_CHECK_STR(noti->vibration_path), @@ -351,6 +372,7 @@ static int _insertion_query_create(notification_h noti, char **query) static int _update_query_create(notification_h noti, char **query) { + int i = 0; int b_encode_len = 0; char *args = NULL; char *group_args = NULL; @@ -359,6 +381,7 @@ static int _update_query_create(notification_h noti, char **query) char *b_service_responding = NULL; char *b_service_single_launch = NULL; char *b_service_multi_launch = NULL; + char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , }; char *b_text = NULL; char *b_key = NULL; char *b_format_args = NULL; @@ -394,6 +417,13 @@ static int _update_query_create(notification_h noti, char **query) (bundle_raw **) & b_service_multi_launch, &b_encode_len); } + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + if (noti->b_event_handler[i]) { + bundle_encode(noti->b_event_handler[i], + (bundle_raw **) & b_event_handler[i], &b_encode_len); + } + } + if (noti->b_text) { bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len); } @@ -430,6 +460,14 @@ static int _update_query_create(notification_h noti, char **query) "b_service_responding = '%s', " "b_service_single_launch = '%s', " "b_service_multi_launch = '%s', " + "b_event_handler_click_on_button_1 = '%s', " + "b_event_handler_click_on_button_2= '%s', " + "b_event_handler_click_on_button_3= '%s', " + "b_event_handler_click_on_button_4= '%s', " + "b_event_handler_click_on_button_5= '%s', " + "b_event_handler_click_on_button_6= '%s', " + "b_event_handler_click_on_icon= '%s', " + "b_event_handler_click_on_thumbnail= '%s', " "sound_type = %d, sound_path = '%s', " "vibration_type = %d, vibration_path = '%s', " "led_operation = %d, led_argb = %d, " @@ -452,6 +490,14 @@ static int _update_query_create(notification_h noti, char **query) NOTIFICATION_CHECK_STR(b_service_responding), NOTIFICATION_CHECK_STR(b_service_single_launch), NOTIFICATION_CHECK_STR(b_service_multi_launch), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]), + NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]), noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path), noti->vibration_type, NOTIFICATION_CHECK_STR(noti->vibration_path), @@ -506,6 +552,7 @@ static int _update_query_create(notification_h noti, char **query) static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) { int col = 0; + int i = 0; if (stmt == NULL || noti == NULL) { return ; @@ -540,6 +587,10 @@ static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notificat noti->b_service_multi_launch = notification_db_column_bundle(stmt, col++); + for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) { + noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++); + } + noti->sound_type = sqlite3_column_int(stmt, col++); __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++)); noti->vibration_type = sqlite3_column_int(stmt, col++); @@ -792,6 +843,9 @@ int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int pri "tag, b_text, b_key, b_format_args, num_format_args, " "text_domain, text_dir, time, insert_time, args, group_args, " "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, " + "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, " + "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, display_applist, progress_size, progress_percentage " "from noti_list "; @@ -864,6 +918,9 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, "tag, b_text, b_key, b_format_args, num_format_args, " "text_domain, text_dir, time, insert_time, args, group_args, " "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, " + "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, " + "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, display_applist, progress_size, progress_percentage " "from noti_list where caller_pkgname = ? and tag = ?", -1, &stmt, NULL); @@ -889,6 +946,9 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, "tag, b_text, b_key, b_format_args, num_format_args, " "text_domain, text_dir, time, insert_time, args, group_args, " "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, " + "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, " + "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, display_applist, progress_size, progress_percentage " "from noti_list where tag = ?", -1, &stmt, NULL); @@ -1555,6 +1615,9 @@ int notification_noti_get_grouping_list(notification_type_e type, "tag, b_text, b_key, b_format_args, num_format_args, " "text_domain, text_dir, time, insert_time, args, group_args, " "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, " + "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, " + "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, display_applist, progress_size, progress_percentage " "from noti_list "); @@ -1658,6 +1721,9 @@ int notification_noti_get_detail_list(const char *pkgname, "tag, b_text, b_key, b_format_args, num_format_args, " "text_domain, text_dir, time, insert_time, args, group_args, " "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, " + "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, " + "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, display_applist, progress_size, progress_percentage " "from noti_list "); @@ -1812,127 +1878,3 @@ err: return ret; } - -static void popup_timeout_cb(void *data, Evas_Object *obj, void *event_info) -{ - Eina_List *list = NULL; - char *msg = NULL; - int count = 0; - - evas_object_del(toast_popup); - toast_popup = NULL; - evas_object_del((Evas_Object *)data); - - count = eina_list_count(toast_list); - - if (count == 1){ - msg = (char *)eina_list_data_get(toast_list); - free(msg); - - eina_list_free(toast_list); - toast_list = NULL; - } else if (count > 1) { - msg = (char *)eina_list_data_get(toast_list); - toast_list = eina_list_remove(toast_list, msg); - free(msg); - _post_toast_message((char *)eina_list_data_get(toast_list)); - } -} - -int _post_toast_message(char *message) -{ - int let = 0; - Evas_Object *toast_window; - Evas *e; - Ecore_Evas *ee; - double scale = elm_config_scale_get(); - - - toast_window = elm_win_add(NULL, "toast", ELM_WIN_BASIC); - - elm_win_alpha_set(toast_window, EINA_TRUE); - elm_win_title_set(toast_window, "toast"); - - elm_win_indicator_mode_set(toast_window, ELM_WIN_INDICATOR_SHOW); - elm_win_indicator_type_set(toast_window,ELM_WIN_INDICATOR_TYPE_1); - - //elm_win_autodel_set(toast_win, EINA_TRUE); - if (elm_win_wm_rotation_supported_get(toast_window)) { - int rots[4] = { 0, 90, 180, 270 }; - elm_win_wm_rotation_available_rotations_set(toast_window, (const int*)(&rots), 4); - } - - e = evas_object_evas_get(toast_window); - ee = ecore_evas_ecore_evas_get(e); - ecore_evas_name_class_set(ee, "TOAST_POPUP", "SYSTEM_POPUP"); - - evas_object_resize(toast_window, (480 * scale), (650 * scale)); - ecore_x_window_shape_input_rectangle_set(elm_win_xwindow_get(toast_window), 0, 0, (480 * scale), (650 * scale)); - - toast_popup = elm_popup_add(toast_window); - - elm_object_style_set(toast_popup, "toast"); - evas_object_size_hint_weight_set(toast_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - - elm_object_text_set(toast_popup,message); - - if (eina_list_count(toast_list) != 1) { - elm_popup_timeout_set(toast_popup, 1.0); - } - else { - elm_popup_timeout_set(toast_popup, 3.0); - } - evas_object_smart_callback_add(toast_popup, "timeout", popup_timeout_cb, (void *)toast_window); - - elm_win_prop_focus_skip_set(toast_window, EINA_TRUE); - - evas_object_show(toast_window); - evas_object_show(toast_popup); - - return 0; -} - -EXPORT_API int notification_noti_post_toast_message(const char *message) -{ - int let = 0; - char *msg = NULL; - int count = 0; - - msg = (char *)calloc(strlen(message) + 1, sizeof(char)); - strcpy(msg, message); - -/* - if (eina_list_count(toast_list) == 10) { - toast_list = eina_list_last(toast_list); - eina_list_data_set(toast_list, msg); - toast_list = eina_list_nth_list(toast_list, 0); - } - else { -*/ - - count = eina_list_count(toast_list); - if (count == 0) { - toast_list = eina_list_append(toast_list, msg); - let = _post_toast_message(msg); - } - else if (count == 1) { - if (strcmp(msg, (char *)eina_list_nth(toast_list, count - 1)) == 0) { - elm_popup_timeout_set(toast_popup, 3.0); - } - else { - toast_list = eina_list_append(toast_list, msg); - elm_popup_timeout_set(toast_popup, 1.0); - } - } - else if (count >= 2) { - if (strcmp(msg, (char *)eina_list_nth(toast_list, count - 1)) == 0) { - free(msg); - return 0; - } - else { - toast_list = eina_list_append(toast_list, msg); - } - } - - return 0; -} diff --git a/src/notification_ongoing.c b/src/notification_ongoing.c old mode 100755 new mode 100644 diff --git a/src/notification_permission.c b/src/notification_permission.c old mode 100755 new mode 100644 diff --git a/src/notification_setting.c b/src/notification_setting.c index 8c0ede6c..436a9913 100755 --- a/src/notification_setting.c +++ b/src/notification_setting.c @@ -31,12 +31,490 @@ #include #include #include +#include +#define SAFE_STRDUP(s) \ + ({\ + char* _s = (char*)s;\ + (_s)? strdup(_s) : NULL;\ +}) + +#define SAFE_FREE(s) \ + ({\ + if (s) {\ + free(s);\ + s = NULL;\ + }\ +}) + +#define NOTIFICATION_SETTING_DB_TABLE "notification_setting" + +static int _get_table_field_data_int(char **table, int *buf, int index) +{ + if ((table == NULL) || (buf == NULL) || (index < 0)) { + NOTIFICATION_ERR("table[%p], buf[%p], index[%d]", table, buf, index); + return false; + } + + if (table[index] != NULL) { + *buf = atoi(table[index]); + return true; + } + + *buf = 0; + return false; +} + +static int _get_table_field_data_string(char **table, char **buf, int ucs2, int index) +{ + int ret = false; + + if ((table == NULL) || (buf == NULL) || (index < 0)) { + NOTIFICATION_ERR("table[%p], buf[%p], index[%d]", table, buf, index); + return false; + } + + char *pTemp = table[index]; + int sLen = 0; + if (pTemp == NULL) + *buf = NULL; + else { + sLen = strlen(pTemp); + if(sLen) { + *buf = (char *) malloc(sLen + 1); + if (*buf == NULL) { + NOTIFICATION_ERR("malloc is failed"); + goto out; + } + memset(*buf, 0, sLen + 1); + strncpy(*buf, pTemp, sLen); + } + else + *buf = NULL; + } + + ret = true; +out: + + return ret; +} + + + +EXPORT_API int notification_setting_get_setting_array(notification_setting_h *setting_array, int *count) +{ + int err = NOTIFICATION_ERROR_NONE; + sqlite3 *local_db_handle = NULL; + char *sql_query = NULL; + char **query_result = NULL; + int sql_return; + int row_count = 0; + int column_count = 0; + int i = 0; + int col_index = 0; + notification_setting_h result_setting_array= NULL; + + if (setting_array == NULL || count == NULL) { + NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + sql_return = db_util_open(DBPATH, &local_db_handle, 0); + + if (sql_return != SQLITE_OK || local_db_handle == NULL) { + NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); + err = NOTIFICATION_ERROR_FROM_DB; + goto out; + } + + sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class " + "FROM %s " + "ORDER BY package_name", NOTIFICATION_SETTING_DB_TABLE); + + if (!sql_query) { + NOTIFICATION_ERR("fail to alloc query"); + err = NOTIFICATION_ERROR_OUT_OF_MEMORY; + goto out; + } + + sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL); + + if (sql_return != SQLITE_OK && sql_return != -1) { + NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_return, sql_query); + err = NOTIFICATION_ERROR_FROM_DB; + goto out; + } + + if (!row_count) { + NOTIFICATION_DBG ("No setting found..."); + err= NOTIFICATION_ERROR_NOT_EXIST_ID; + goto out; + } + + NOTIFICATION_DBG ("row_count [%d] column_count [%d]", row_count, column_count); + if (!(result_setting_array = (struct notification_setting*)malloc(sizeof(struct notification_setting) * row_count))) { + NOTIFICATION_ERR("malloc failed..."); + err = NOTIFICATION_ERROR_OUT_OF_MEMORY; + goto out; + } + + col_index = column_count; + + for (i = 0; i < row_count; i++) { + _get_table_field_data_string(query_result, &(result_setting_array[i].package_name), 1, col_index++); + _get_table_field_data_int(query_result, (int*)&(result_setting_array[i].allow_to_notify), col_index++); + _get_table_field_data_int(query_result, (int*)&(result_setting_array[i].do_not_disturb_except), col_index++); + _get_table_field_data_int(query_result, &(result_setting_array[i].visibility_class), col_index++); + } + + *setting_array = result_setting_array; + *count = row_count; + +out: + if (query_result) + sqlite3_free_table(query_result); + + if (sql_query) + sqlite3_free(sql_query); + + if (local_db_handle) { + sql_return = db_util_close(local_db_handle); + if (sql_return != SQLITE_OK) { + NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); + } + } + + return err; +} + +EXPORT_API int notification_setting_get_setting_by_package_name(const char *package_name, notification_setting_h *setting) +{ + int err = NOTIFICATION_ERROR_NONE; + sqlite3 *local_db_handle = NULL; + char *sql_query = NULL; + char **query_result = NULL; + int sql_return; + int row_count = 0; + int column_count = 0; + int i = 0; + int col_index = 0; + notification_setting_h result_setting_array= NULL; + + if (package_name == NULL || setting == NULL) { + NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + sql_return = db_util_open(DBPATH, &local_db_handle, 0); + + if (sql_return != SQLITE_OK || local_db_handle == NULL) { + NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); + err = NOTIFICATION_ERROR_FROM_DB; + goto out; + } + + sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class " + "FROM %s " + "WHERE package_name = %Q ", NOTIFICATION_SETTING_DB_TABLE, package_name); + + if (!sql_query) { + NOTIFICATION_ERR("fail to alloc query"); + err = NOTIFICATION_ERROR_OUT_OF_MEMORY; + goto out; + } + + sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL); + + if (sql_return != SQLITE_OK && sql_return != -1) { + NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_return, sql_query); + err = NOTIFICATION_ERROR_FROM_DB; + goto out; + } + + if (!row_count) { + NOTIFICATION_DBG ("No setting found..."); + err= NOTIFICATION_ERROR_NOT_EXIST_ID; + goto out; + } + + NOTIFICATION_DBG ("row_count [%d] column_count [%d]", row_count, column_count); + + row_count = 1; + + if (!(result_setting_array = (struct notification_setting*)malloc(sizeof(struct notification_setting) * row_count))) { + NOTIFICATION_ERR("malloc failed..."); + err = NOTIFICATION_ERROR_OUT_OF_MEMORY; + goto out; + } + + col_index = column_count; + + _get_table_field_data_string(query_result, &(result_setting_array[i].package_name), 1, col_index++); + _get_table_field_data_int(query_result, (int*)&(result_setting_array[i].allow_to_notify), col_index++); + _get_table_field_data_int(query_result, (int*)&(result_setting_array[i].do_not_disturb_except), col_index++); + _get_table_field_data_int(query_result, &(result_setting_array[i].visibility_class), col_index++); + + *setting = result_setting_array; + +out: + if (query_result) + sqlite3_free_table(query_result); + + if (sql_query) + sqlite3_free(sql_query); + + if (local_db_handle) { + sql_return = db_util_close(local_db_handle); + if (sql_return != SQLITE_OK) { + NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); + } + } + + return err; +} + +EXPORT_API int notification_setting_get_setting(notification_setting_h *setting) +{ + char *package_name = NULL; + + package_name = notification_get_pkgname_by_pid(); + + if (package_name == NULL) + return NOTIFICATION_ERROR_NOT_EXIST_ID; + + return notification_setting_get_setting_by_package_name(package_name, setting); +} + +EXPORT_API int notification_setting_get_package_name(notification_setting_h setting, char **value) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL || value == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + if (setting->package_name == NULL) { + NOTIFICATION_ERR("setting->package_name is null\n"); + err = NOTIFICATION_ERROR_NOT_EXIST_ID; + goto out; + } + + *value = SAFE_STRDUP(setting->package_name); + +out: + + return err; +} + +EXPORT_API int notification_setting_set_package_name(notification_setting_h setting, char *value) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL || value == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + if (setting->package_name != NULL) { + free(setting->package_name); + } + + setting->package_name = SAFE_STRDUP(value); + +out: + + return err; +} + +EXPORT_API int notification_setting_get_allow_to_notify(notification_setting_h setting, bool *value) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL || value == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + *value = setting->allow_to_notify; + +out: + + return err; +} + +EXPORT_API int notification_setting_set_allow_to_notify(notification_setting_h setting, bool value) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + setting->allow_to_notify = value; + +out: + + return err; +} + +EXPORT_API int notification_setting_get_do_not_disturb_except(notification_setting_h setting, bool *value) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL || value == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + *value = setting->do_not_disturb_except; + +out: + + return err; +} + +EXPORT_API int notification_setting_set_do_not_disturb_except(notification_setting_h setting, bool value) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + setting->do_not_disturb_except = value; + +out: + + return err; +} + +EXPORT_API int notification_setting_get_visibility_class(notification_setting_h setting, int *value) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL || value == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + *value = setting->visibility_class; + +out: + + return err; +} + +EXPORT_API int notification_setting_set_visibility_class(notification_setting_h setting, int value) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + setting->visibility_class = value; + +out: + + return err; +} + +EXPORT_API int notification_setting_update_setting(notification_setting_h setting) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + err = notification_ipc_update_setting(setting); + if (err != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("notification_ipc_noti_setting_property_set returns[%d]\n", err); + goto out; + } + +out: + return err; +} + +EXPORT_API int notification_setting_free_notification(notification_setting_h setting) +{ + int err = NOTIFICATION_ERROR_NONE; + + if (setting == NULL) { + NOTIFICATION_ERR("Invalid parameter\n"); + err = NOTIFICATION_ERROR_INVALID_PARAMETER; + goto out; + } + + SAFE_FREE(setting->package_name); + /* add codes to free all properties */ + +out: + + return err; +} + +EXPORT_API int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class) +{ + int err = NOTIFICATION_ERROR_NONE; + sqlite3 *db = NULL; + char *sqlbuf = NULL; + int sqlret; + + if (package_name == NULL) + return NOTIFICATION_ERROR_INVALID_PARAMETER; + + sqlret = db_util_open(DBPATH, &db, 0); + if (sqlret != SQLITE_OK || db == NULL) { + NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret); + return NOTIFICATION_ERROR_FROM_DB; + } + + sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, do_not_disturb_except = %d, visibility_class = %d " \ + "WHERE package_name = %Q", + NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class, package_name); + if (!sqlbuf) { + NOTIFICATION_ERR("fail to alloc query"); + err = NOTIFICATION_ERROR_OUT_OF_MEMORY; + goto return_close_db; + } + + err = notification_db_exec(db, sqlbuf, NULL); + + return_close_db: + if (sqlbuf) + sqlite3_free(sqlbuf); + + sqlret = db_util_close(db); + if (sqlret != SQLITE_OK) { + NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret); + } + + return err; +} + + +/* OLD IMPLEMENTATION */ #define NOTIFICATION_SETTING_DB "notification_setting" #define NOTIFICATION_SETTING_DB_PATH "/opt/usr/dbspace/.notification_parser.db" -typedef struct _notification_setting_h notification_setting_h; - struct _notification_setting_h { char *appid; char *notification; @@ -53,31 +531,31 @@ struct prop_table { }; static struct prop_table g_prop_table[] = { - { - .property = "OPT_NOTIFICATION", - .column = "notification", - .default_value = "ON", - }, - { - .property = "OPT_SOUNDS", - .column = "sounds", - .default_value = "ON", - }, - { - .property = "OPT_CONTENTS", - .column = "contents", - .default_value = "ON", - }, - { - .property = "OPT_BADGE", - .column = "badge", - .default_value = "ON", - }, - { - .property = NULL, - .column = NULL, - .default_value = NULL, - } + { + .property = "OPT_NOTIFICATION", + .column = "notification", + .default_value = "ON", + }, + { + .property = "OPT_SOUNDS", + .column = "sounds", + .default_value = "ON", + }, + { + .property = "OPT_CONTENTS", + .column = "contents", + .default_value = "ON", + }, + { + .property = "OPT_BADGE", + .column = "badge", + .default_value = "ON", + }, + { + .property = NULL, + .column = NULL, + .default_value = NULL, + } }; static const char *_get_prop_column(const char *property) @@ -125,8 +603,8 @@ static int _is_record_exist(const char *pkgname, sqlite3 *db) return NOTIFICATION_ERROR_INVALID_PARAMETER; sqlbuf = sqlite3_mprintf("SELECT count(*) FROM %s WHERE " \ - "appid = %Q", - NOTIFICATION_SETTING_DB, pkgname); + "appid = %Q", + NOTIFICATION_SETTING_DB, pkgname); if (!sqlbuf) { NOTIFICATION_ERR("fail to alloc sql query"); @@ -152,7 +630,7 @@ static int _is_record_exist(const char *pkgname, sqlite3 *db) else result = NOTIFICATION_ERROR_NOT_EXIST_ID; -free_and_return: + free_and_return: if (sqlbuf) sqlite3_free(sqlbuf); @@ -207,7 +685,7 @@ EXPORT_API int notification_setting_db_set(const char *pkgname, const char *prop result = notification_db_exec(db, sqlbuf, NULL); -return_close_db: + return_close_db: if (sqlbuf) sqlite3_free(sqlbuf); @@ -287,7 +765,7 @@ EXPORT_API int notification_setting_db_get(const char *pkgname, const char *prop } } -return_close_db: + return_close_db: if (sqlbuf) sqlite3_free(sqlbuf); @@ -342,3 +820,4 @@ EXPORT_API int notification_setting_property_get(const char *pkgname, const char return NOTIFICATION_ERROR_NONE; } + diff --git a/src/notification_status.c b/src/notification_status.c index 5071851c..919f0188 100755 --- a/src/notification_status.c +++ b/src/notification_status.c @@ -26,6 +26,9 @@ #include #include #include +#include +#include +#include #include #include @@ -38,6 +41,9 @@ #define INTERFACE_NAME "org.tizen.system.notification.status_message" #define MEMBER_NAME "status_message" +static Eina_List *toast_list; +static Eina_List *toast_popup; + struct _message_cb_data { notification_status_message_cb callback; void *data; @@ -47,6 +53,121 @@ struct _message_cb_data { static struct _message_cb_data md; +int _post_toast_message(char *message); + +static void popup_timeout_cb(void *data, Evas_Object *obj, void *event_info) +{ + char *msg = NULL; + int count = 0; + + evas_object_del(toast_popup); + toast_popup = NULL; + evas_object_del((Evas_Object *)data); + + count = eina_list_count(toast_list); + + if (count == 1){ + msg = (char *)eina_list_data_get(toast_list); + free(msg); + + eina_list_free(toast_list); + toast_list = NULL; + } else if (count > 1) { + msg = (char *)eina_list_data_get(toast_list); + toast_list = eina_list_remove(toast_list, msg); + free(msg); + _post_toast_message((char *)eina_list_data_get(toast_list)); + } +} + +int _post_toast_message(char *message) +{ + Evas_Object *toast_window; + Evas *e; + Ecore_Evas *ee; + double scale = elm_config_scale_get(); + + + toast_window = elm_win_add(NULL, "toast", ELM_WIN_BASIC); + + elm_win_alpha_set(toast_window, EINA_TRUE); + elm_win_title_set(toast_window, "toast"); + + elm_win_indicator_mode_set(toast_window, ELM_WIN_INDICATOR_SHOW); + elm_win_indicator_type_set(toast_window,ELM_WIN_INDICATOR_TYPE_1); + + //elm_win_autodel_set(toast_win, EINA_TRUE); + if (elm_win_wm_rotation_supported_get(toast_window)) { + int rots[4] = { 0, 90, 180, 270 }; + elm_win_wm_rotation_available_rotations_set(toast_window, (const int*)(&rots), 4); + } + + e = evas_object_evas_get(toast_window); + ee = ecore_evas_ecore_evas_get(e); + ecore_evas_name_class_set(ee, "TOAST_POPUP", "SYSTEM_POPUP"); + + evas_object_resize(toast_window, (480 * scale), (650 * scale)); + ecore_x_window_shape_input_rectangle_set(elm_win_xwindow_get(toast_window), 0, 0, (480 * scale), (650 * scale)); + + toast_popup = elm_popup_add(toast_window); + + elm_object_style_set(toast_popup, "toast"); + evas_object_size_hint_weight_set(toast_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + + elm_object_text_set(toast_popup,message); + + if (eina_list_count(toast_list) != 1) { + elm_popup_timeout_set(toast_popup, 1.0); + } + else { + elm_popup_timeout_set(toast_popup, 3.0); + } + evas_object_smart_callback_add(toast_popup, "timeout", popup_timeout_cb, (void *)toast_window); + + elm_win_prop_focus_skip_set(toast_window, EINA_TRUE); + + evas_object_show(toast_window); + evas_object_show(toast_popup); + + return 0; +} + +int notification_noti_post_toast_message(const char *message) +{ + int let = 0; + char *msg = NULL; + int count = 0; + + msg = (char *)calloc(strlen(message) + 1, sizeof(char)); + strcpy(msg, message); + + count = eina_list_count(toast_list); + if (count == 0) { + toast_list = eina_list_append(toast_list, msg); + let = _post_toast_message(msg); + } + else if (count == 1) { + if (strcmp(msg, (char *)eina_list_nth(toast_list, count - 1)) == 0) { + elm_popup_timeout_set(toast_popup, 3.0); + } + else { + toast_list = eina_list_append(toast_list, msg); + elm_popup_timeout_set(toast_popup, 1.0); + } + } + else if (count >= 2) { + if (strcmp(msg, (char *)eina_list_nth(toast_list, count - 1)) == 0) { + free(msg); + return 0; + } + else { + toast_list = eina_list_append(toast_list, msg); + } + } + + return 0; +} + static void __notification_status_message_dbus_callback(void *data, DBusMessage *msg) { int ret = 0; diff --git a/test-app/CMakeLists.txt b/test-app/CMakeLists.txt old mode 100755 new mode 100644 index 6e53af2d..efa40eb0 --- a/test-app/CMakeLists.txt +++ b/test-app/CMakeLists.txt @@ -13,7 +13,7 @@ MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}") SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections -fPIC") ########################################################## # Define Test App diff --git a/test-app/main.c b/test-app/main.c index e132f2fa..073ee0ec 100755 --- a/test-app/main.c +++ b/test-app/main.c @@ -34,12 +34,15 @@ /* notification header */ #include #include +#include +#include /*-----------------------------------------------------------------------------------------*/ /* types */ typedef enum testapp_menu_type { TESTAPP_MENU_TYPE_MAIN_MENU = 1, TESTAPP_MENU_TYPE_BASIC_TEST_MENU = 2, + TESTAPP_MENU_TYPE_SETTING_TEST_MENU = 3 } testapp_menu_type_e; /*-----------------------------------------------------------------------------------------*/ @@ -133,6 +136,7 @@ void testapp_show_menu (testapp_menu_type_e menu) testapp_print (" Notification test application \n"); testapp_print ("==========================================\n"); testapp_print ("1. Basic Test\n"); + testapp_print ("2. Setting Test\n"); testapp_print ("0. Exit \n"); testapp_print ("------------------------------------------\n"); break; @@ -144,6 +148,16 @@ void testapp_show_menu (testapp_menu_type_e menu) testapp_print (" 2. Post simple notifications repeatedly\n"); testapp_print (" 3. Post a notification on indicator\n"); testapp_print (" 4. Post status status message\n"); + testapp_print (" 5. Delete all notification\n"); + testapp_print (" 6. Post a heads notification with a button\n"); + testapp_print ("------------------------------------------\n"); + break; + case TESTAPP_MENU_TYPE_SETTING_TEST_MENU: + testapp_print ("==========================================\n"); + testapp_print (" Setting test menu \n"); + testapp_print ("==========================================\n"); + testapp_print (" 1. Get setting list\n"); + testapp_print (" 2. Update setting\n"); testapp_print ("------------------------------------------\n"); break; default: @@ -181,7 +195,7 @@ static int testapp_add_a_notification() goto FINISH_OFF; } -FINISH_OFF: + FINISH_OFF: if (noti_handle) notification_free(noti_handle); @@ -201,7 +215,7 @@ static int testapp_test_post_notification() } -FINISH_OFF: + FINISH_OFF: return err; } @@ -224,8 +238,7 @@ static int testapp_test_post_notifications() } } - -FINISH_OFF: + FINISH_OFF: return err; } @@ -258,7 +271,7 @@ static int testapp_test_post_notification_on_indicator() goto FINISH_OFF; } -FINISH_OFF: + FINISH_OFF: if (noti_handle) notification_free(noti_handle); @@ -279,58 +292,274 @@ static int testapp_test_post_status_message() return noti_err; } +static int testapp_test_delete_all_notifications() +{ + int noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI); + + testapp_print("notification_delete_all returns[%d]", noti_err); + + return noti_err; +} + +static int testapp_test_post_heads_up_notification_with_button() +{ + notification_h noti_handle = NULL; + int noti_err = NOTIFICATION_ERROR_NONE; + int app_control_err = APP_CONTROL_ERROR_NONE; + int priv_id = 0; + int group_id = 0; + char *app_id = NULL; + app_control_h app_control = NULL; + time_t result = time(NULL); + char tag[100] = { 0, }; + + noti_handle = notification_create(NOTIFICATION_TYPE_NOTI); + + if (noti_handle == NULL) { + testapp_print("notification_create failed"); + goto FINISH_OFF; + } + + noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE); + noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE); + + noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_HEADS_UP | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY); + + snprintf(tag, 100, "%d", result); + + noti_err = notification_set_tag(noti_handle, tag); + + if (noti_err != NOTIFICATION_ERROR_NONE) { + testapp_print("notification_set_display_applist failed[%d]\n", noti_err); + goto FINISH_OFF; + } + + app_control_err = app_control_create(&app_control); + if (app_control_err != APP_CONTROL_ERROR_NONE ) { + testapp_print("app_control_create failed[%d]\n", app_control_err); + goto FINISH_OFF; + } + + app_control_err = app_control_set_app_id(app_control, "org.tizen.quickpanel"); + if (app_control_err != APP_CONTROL_ERROR_NONE ) { + testapp_print("app_control_set_app_id failed[%d]\n", app_control_err); + goto FINISH_OFF; + } + noti_err = notification_set_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control); + + if (noti_err != NOTIFICATION_ERROR_NONE) { + testapp_print("notification_set_event_handler failed[%d]", noti_err); + goto FINISH_OFF; + } + + noti_err = notification_post(noti_handle); + + app_control_destroy(app_control); + app_control = NULL; + + if (noti_err != NOTIFICATION_ERROR_NONE) { + testapp_print("notification_post failed[%d]", noti_err); + goto FINISH_OFF; + } + + noti_err = notification_get_id(noti_handle, &group_id, &priv_id); + + if (noti_err != NOTIFICATION_ERROR_NONE) { + testapp_print("notification_get_id failed[%d]", noti_err); + goto FINISH_OFF; + } + + /* + if (noti_handle) + notification_free(noti_handle); + noti_handle = NULL; + */ + + noti_handle = notification_load(NULL, priv_id); + + if (noti_handle == NULL) { + testapp_print("notification_load failed"); + goto FINISH_OFF; + } + + noti_err = notification_get_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control); + + if (noti_err != NOTIFICATION_ERROR_NONE ||app_control == NULL) { + testapp_print("notification_get_event_handler failed[%d]", noti_err); + goto FINISH_OFF; + } + + app_control_get_app_id(app_control, &app_id); + + if (app_id) { + testapp_print("result app_id [%s]", app_id); + free(app_id); + } + +FINISH_OFF: + + if (app_control) + app_control_destroy(app_control); + + if (noti_handle) + notification_free(noti_handle); + + return noti_err; +} static gboolean testapp_interpret_command_basic_test (int selected_number) { - gboolean go_to_loop = TRUE; + gboolean go_to_loop = TRUE; - switch (selected_number) { - case 1: - testapp_test_post_notification(); - break; + switch (selected_number) { + case 1: + testapp_test_post_notification(); + break; - case 2: - testapp_test_post_notifications(); - break; + case 2: + testapp_test_post_notifications(); + break; - case 3: - testapp_test_post_notification_on_indicator(); - break; + case 3: + testapp_test_post_notification_on_indicator(); + break; - case 4: - testapp_test_post_status_message(); - break; + case 4: + testapp_test_post_status_message(); + break; - case 0: - go_to_loop = FALSE; - break; + case 5: + testapp_test_delete_all_notifications(); + break; - default: - break; - } + case 6: + testapp_test_post_heads_up_notification_with_button(); + break; - return go_to_loop; + case 0: + go_to_loop = FALSE; + break; + + default: + break; + } + + return go_to_loop; } void testapp_notification_main () { - gboolean go_to_loop = TRUE; - int menu_number = 0; + gboolean go_to_loop = TRUE; + int menu_number = 0; - while (go_to_loop) { - testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU); - testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU); + while (go_to_loop) { + testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU); + testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU); - if (0 >= scanf("%d", &menu_number)) - testapp_print("Invalid input"); + if (0 >= scanf("%d", &menu_number)) + testapp_print("Invalid input"); - go_to_loop = testapp_interpret_command_basic_test(menu_number); - } + go_to_loop = testapp_interpret_command_basic_test(menu_number); + } } /* Basic Test } ---------------------------------------------------------------*/ +/* Setting Test } ---------------------------------------------------------------*/ + +static int testapp_test_get_setting_list() +{ + int err = NOTIFICATION_ERROR_NONE; + int i = 0; + int count = 0; + char *package_name = NULL; + bool allow_to_notify = false; + bool do_not_disturb_except = false; + bool visibility_class = false; + notification_setting_h setting_array = NULL; + + notification_setting_get_setting_array(&setting_array, &count); + + testapp_print("count [%d]\n", count); + + for (i = 0; i < count; i++) { + notification_setting_get_package_name(setting_array + i, &package_name); + notification_setting_get_allow_to_notify(setting_array + i, &allow_to_notify); + notification_setting_get_do_not_disturb_except(setting_array + i, &do_not_disturb_except); + notification_setting_get_visibility_class(setting_array + i, &visibility_class); + + testapp_print("[%d] : package_name[%s], allow_to_notify[%d], do_not_disturb_except[%d], visibility_class[%d]\n" + ,i, package_name, allow_to_notify, do_not_disturb_except, visibility_class); + free(package_name); + notification_setting_free_notification(setting_array + i); + } + + if (setting_array) + free(setting_array); + + return err; +} + +static int testapp_test_update_setting() +{ + int err = NOTIFICATION_ERROR_NONE; + notification_setting_h setting = NULL; + + err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting); + + if (err != NOTIFICATION_ERROR_NONE || setting == NULL) { + testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err); + } + else { + notification_setting_set_allow_to_notify(setting, 0); + notification_setting_update_setting(setting); + } +} + +static gboolean testapp_interpret_command_setting_test (int selected_number) +{ + gboolean go_to_loop = TRUE; + + switch (selected_number) { + case 1: + testapp_test_get_setting_list(); + break; + + case 2: + testapp_test_update_setting(); + break; + + case 0: + go_to_loop = FALSE; + break; + + default: + break; + } + + return go_to_loop; + +} + +void testapp_setting_main() +{ + gboolean go_to_loop = TRUE; + int menu_number = 0; + + while (go_to_loop) { + testapp_show_menu (TESTAPP_MENU_TYPE_SETTING_TEST_MENU); + testapp_show_prompt (TESTAPP_MENU_TYPE_SETTING_TEST_MENU); + + if (0 >= scanf("%d", &menu_number)) + testapp_print("Invalid input"); + + go_to_loop = testapp_interpret_command_setting_test(menu_number); + } +} +/* Setting Test } ---------------------------------------------------------------*/ /* Main { ---------------------------------------------------------------------*/ static gboolean testapp_interpret_command (int menu_number) @@ -342,6 +571,10 @@ static gboolean testapp_interpret_command (int menu_number) testapp_notification_main(); break; + case 2: + testapp_setting_main(); + break; + case 0: go_to_loop = FALSE; break; @@ -355,15 +588,19 @@ static gboolean testapp_interpret_command (int menu_number) void testapp_show_prompt (testapp_menu_type_e menu) { - switch (menu) { - case TESTAPP_MENU_TYPE_MAIN_MENU: - testapp_print ("[MAIN]# "); - break; - - case TESTAPP_MENU_TYPE_BASIC_TEST_MENU: - testapp_print ("[BASIC_TEST]# "); - break; - } + switch (menu) { + case TESTAPP_MENU_TYPE_MAIN_MENU: + testapp_print ("[MAIN]# "); + break; + + case TESTAPP_MENU_TYPE_BASIC_TEST_MENU: + testapp_print ("[BASIC_TEST]# "); + break; + + case TESTAPP_MENU_TYPE_SETTING_TEST_MENU: + testapp_print ("[SETTING_TEST]# "); + break; + } } int main (int argc, char *argv[])