2 * Copyright (c) 2009 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "notification-setting-info.h"
20 #include <notification.h>
21 #include <notification_setting.h>
22 #include <notification_setting_internal.h>
24 setting_info_s *setting_info = NULL;
26 #define VOICE_CALL_PACKAGE "org.tizen.call-ui"
28 void create_app_notification_list()
33 char *package_name = NULL;
34 bool allow_to_notify = false;
35 bool do_not_disturb_except = false;
36 notification_setting_h setting_array = NULL;
37 notification_setting_h *temp = NULL;
38 item_info_s *item_info = NULL;
40 remove_all_apps_list();
41 setting_info = calloc(1, sizeof(setting_info_s));
43 notification_setting_get_setting_array(&setting_array, &count);
44 ret_if(!setting_array);
45 NOTISET_DBG("count %d", count);
47 for (i = 0; i < count; i++) {
48 item_info = calloc(1, sizeof(item_info_s));
50 temp = setting_array + i;
52 notification_setting_get_package_name(temp, &package_name);
53 item_info->appid = package_name;
55 notification_setting_get_allow_to_notify(temp, &allow_to_notify);
56 item_info->allow_to_notify = allow_to_notify;
58 notification_setting_get_do_not_disturb_except(temp, &do_not_disturb_except);
59 item_info->do_not_disturb_except = do_not_disturb_except;
61 item_info->icon = get_app_icon(package_name);
62 item_info->name = get_app_name(package_name);
66 if (item_info->name && strcmp(package_name, VOICE_CALL_PACKAGE) != 0) {
67 setting_info->all_apps_list = eina_list_append(setting_info->all_apps_list, item_info);
70 FREEIF(item_info->name);
71 FREEIF(item_info->icon);
77 setting_info->all_apps_list = eina_list_sort(setting_info->all_apps_list, eina_list_count(setting_info->all_apps_list), apps_sort_cb);
78 notification_setting_free_notification(setting_array);
81 void create_do_not_disturb_application_list()
86 char *package_name = NULL;
87 bool allow_to_notify = false;
88 bool do_not_disturb_except = false;
89 notification_setting_h setting_array = NULL;
90 notification_setting_h *temp = NULL;
92 remove_excepted_apps_list();
93 setting_info = calloc(1, sizeof(setting_info_s));
95 notification_setting_get_setting_array(&setting_array, &count);
96 ret_if(!setting_array);
97 NOTISET_DBG("count %d", count);
99 item_info_s *item_info = NULL;
100 for (i = 0; i < count; i++) {
101 item_info = calloc(1, sizeof(item_info_s));
103 temp = setting_array + i;
105 notification_setting_get_package_name(temp, &package_name);
106 item_info->appid = package_name;
108 notification_setting_get_allow_to_notify(temp, &allow_to_notify);
109 item_info->allow_to_notify = allow_to_notify;
111 notification_setting_get_do_not_disturb_except(temp, &do_not_disturb_except);
112 item_info->do_not_disturb_except = do_not_disturb_except;
114 item_info->icon = get_app_icon(package_name);
115 item_info->name = get_app_name(package_name);
117 item_info->index = i;
119 if(item_info->name) {
120 if (do_not_disturb_except) {
121 setting_info->excepted_list = eina_list_append(setting_info->excepted_list, item_info);
123 setting_info->not_excepted_list = eina_list_append(setting_info->not_excepted_list, item_info);
126 FREEIF(package_name);
127 FREEIF(item_info->name);
128 FREEIF(item_info->icon);
134 setting_info->excepted_list = eina_list_sort(setting_info->excepted_list, eina_list_count(setting_info->excepted_list), apps_sort_cb);
135 setting_info->not_excepted_list = eina_list_sort(setting_info->not_excepted_list, eina_list_count(setting_info->not_excepted_list), apps_sort_cb);
137 notification_setting_free_notification(setting_array);
140 Eina_List *get_excepted_apps_list()
143 return setting_info->excepted_list;
146 Eina_List *get_all_apps_list()
149 return setting_info->all_apps_list;
153 Eina_List *get_not_excepted_apps_list()
156 return setting_info->not_excepted_list;
160 bool get_do_not_disturb()
164 int err = NOTIFICATION_ERROR_NONE;
165 notification_system_setting_h system_setting = NULL;
166 bool do_not_disturb = false;
168 err = notification_system_setting_load_system_setting(&system_setting);
169 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
170 NOTISET_ERR("notification_system_setting_load_system_setting failed [%d]\n", err);
174 notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
175 NOTISET_DBG("do_not_disturb [%d]\n", do_not_disturb);
179 notification_system_setting_free_system_setting(system_setting);
181 return do_not_disturb;
184 void set_do_not_disturb(bool state)
187 int err = NOTIFICATION_ERROR_NONE;
188 notification_system_setting_h system_setting = NULL;
190 err = notification_system_setting_load_system_setting(&system_setting);
191 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
192 NOTISET_ERR("notification_system_setting_load_system_setting failed [%d]\n", err);
196 notification_system_setting_set_do_not_disturb(system_setting, state);
197 NOTISET_DBG("set do_not_disturb [%d]\n", state);
199 err = notification_system_setting_update_system_setting(system_setting);
200 if (err != NOTIFICATION_ERROR_NONE) {
201 NOTISET_ERR("notification_setting_update_setting [%d]\n", err);
206 notification_system_setting_free_system_setting(system_setting);
210 bool set_allow_to_nofity(char *pkg_name, bool state)
213 int err = NOTIFICATION_ERROR_NONE;
215 notification_system_setting_h system_setting = NULL;
217 err = notification_setting_get_setting_by_package_name(pkg_name, &system_setting);
218 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
219 NOTISET_ERR("notification_setting_get_setting_by_package_name [%d]\n", err);
223 notification_setting_set_allow_to_notify(system_setting, state);
224 NOTISET_DBG("notification_setting_set_allow_to_notify [%d]\n", state);
226 err = notification_setting_update_setting(system_setting);
227 if (err != NOTIFICATION_ERROR_NONE) {
228 NOTISET_ERR("notification_setting_update_setting [%d]\n", err);
233 notification_system_setting_free_system_setting(system_setting);
238 notification_system_setting_free_system_setting(system_setting);
244 bool set_excepted_apps(char *pkg_name, bool state)
248 int err = NOTIFICATION_ERROR_NONE;
250 notification_system_setting_h system_setting = NULL;
252 err = notification_setting_get_setting_by_package_name(pkg_name, &system_setting);
253 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
254 NOTISET_ERR("notification_setting_get_setting_by_package_name [%d]\n", err);
258 notification_setting_set_do_not_disturb_except(system_setting, state);
259 NOTISET_DBG("notification_setting_set_do_not_disturb_except [%s] [%d]\n", pkg_name, state);
261 err = notification_setting_update_setting(system_setting);
262 if (err != NOTIFICATION_ERROR_NONE) {
263 NOTISET_ERR("notification_setting_update_setting err[%d]\n", err);
267 notification_system_setting_free_system_setting(system_setting);
272 notification_system_setting_free_system_setting(system_setting);
278 static void _remove_apps_list(Eina_List* input_list) {
280 item_info_s *item_info = NULL;
283 EINA_LIST_FREE(input_list, item_info) {
284 //NOTISET_DBG("remove %s", item_info->name);
285 FREEIF(item_info->appid);
286 FREEIF(item_info->name);
287 FREEIF(item_info->icon);
294 void remove_all_apps_list() {
297 _remove_apps_list(setting_info->all_apps_list);
300 void remove_excepted_apps_list(){
303 _remove_apps_list(setting_info->excepted_list);
304 _remove_apps_list(setting_info->not_excepted_list);