2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
16 #ifdef QP_SERVICE_NOTI_LED_ENABLE
19 #include "noti_util.h"
25 static int g_is_led_turned_on = 0;
27 static inline int _is_led_notification_enabled(void) {
31 ret = vconf_get_bool(VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS, &status);
35 ERR("LED notification turned off");
39 ERR("failed to get value of VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS:%d", ret);
45 static inline int __quickpanel_service_get_event_count(const char *pkgname) {
47 notification_h noti = NULL;
48 notification_list_h noti_list = NULL;
50 retif(pkgname == NULL, 0, "Invalid parameter!");
52 notification_get_detail_list(pkgname, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE, -1, ¬i_list);
53 if (noti_list != NULL) {
54 noti = notification_list_get_data(noti_list);
56 count = quickpanel_noti_get_event_count_from_noti(noti);
58 notification_free_list(noti_list);
67 static void _noti_led_on_with_custom_color(int led_argb) {
70 if ((ret = led_set_mode_with_color(LED_MISSED_NOTI, LED_ON, led_argb)) == -1) {
71 ERR("failed led_set_mode:%d", ret);
73 g_is_led_turned_on = 1;
76 static void _noti_led_on(notification_h noti) {
78 notification_led_op_e operation = -1;
82 if ((ret = led_set_mode(LED_MISSED_NOTI, LED_ON)) == -1) {
83 ERR("failed led_set_mode:%d", ret);
85 g_is_led_turned_on = 1;
87 notification_get_led(noti, &operation, &led_argb);
89 if (operation == NOTIFICATION_LED_OP_ON) {
90 if ((ret = led_set_mode(LED_MISSED_NOTI, LED_ON)) == -1) {
91 ERR("failed led_set_mode:%d", ret);
93 g_is_led_turned_on = 1;
94 } else if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
95 if ((ret = led_set_mode_with_color(LED_MISSED_NOTI, LED_ON, led_argb)) == -1) {
96 ERR("failed led_set_mode:%d", ret);
98 g_is_led_turned_on = 1;
100 ERR("NOTIFICATION_LED_OP_OFF");
105 static void _noti_led_off(void) {
108 if ((ret = led_set_mode(LED_MISSED_NOTI, LED_OFF)) == -1) {
109 ERR("failed led_set_mode:%d", ret);
111 g_is_led_turned_on = 0;
114 static int _is_keep_turn_on_led(int *op, int *argb) {
115 notification_h noti = NULL;
116 notification_list_h noti_list = NULL;
117 notification_list_h noti_list_head = NULL;
118 notification_led_op_e operation = -1;
121 notification_get_list(NOTIFICATION_TYPE_NOTI , -1, ¬i_list_head);
122 noti_list = noti_list_head;
124 while (noti_list != NULL) {
125 noti = notification_list_get_data(noti_list);
127 notification_get_led(noti, &operation, &led_argb);
128 if (operation >= NOTIFICATION_LED_OP_ON) {
129 notification_free_list(noti_list_head);
130 noti_list_head = NULL;
132 if (op != NULL) *op = operation;
133 if (argb != NULL) *argb = led_argb;
138 noti_list = notification_list_get_next(noti_list);
141 if (noti_list_head != NULL) {
142 notification_free_list(noti_list_head);
143 noti_list_head = NULL;
149 HAPI void quickpanel_service_noti_led_on(notification_h noti) {
150 notification_led_op_e operation = -1;
153 retif(_is_led_notification_enabled() == 0, , "led noti disabled");
156 if (_is_keep_turn_on_led(&operation, &led_argb) >= 1) {
157 if (operation == NOTIFICATION_LED_OP_ON) {
159 } else if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
160 _noti_led_on_with_custom_color(led_argb);
168 HAPI void quickpanel_service_noti_led_off(notification_h noti) {
169 retif(g_is_led_turned_on == 0, , "led already turned off");
171 if (_is_keep_turn_on_led(NULL, NULL) == 0) {
177 static void quickpanel_service_noti_vconf_cb(keynode_t *node,
183 is_on = _is_led_notification_enabled();
185 ERR("led notification status:%d", is_on);
188 if ((ret = led_set_mode(LED_MISSED_NOTI, LED_OFF)) == -1) {
189 ERR("failed led_set_mode:%d", ret);
191 g_is_led_turned_on = 0;
193 quickpanel_service_noti_led_on(NULL);
197 HAPI void quickpanel_service_noti_init(void *data) {
199 struct appdata *ad = data;
200 retif(ad == NULL, , "Invalid parameter!");
202 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS,
203 quickpanel_service_noti_vconf_cb,
206 ERR("failed to notify key[%s] : %d",
207 VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, ret);
211 HAPI void quickpanel_service_noti_fini(void *data) {
213 struct appdata *ad = data;
214 retif(ad == NULL, , "Invalid parameter!");
216 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS,
217 quickpanel_service_noti_vconf_cb);
219 ERR("failed to ignore key[%s] : %d",
220 VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS, ret);