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.
18 #include <Elementary.h>
21 #include <tzsh_quickpanel_service.h>
25 #include "quickpanel_def.h"
26 #include "quickpanel-ui.h"
28 #include "setting_utils.h"
29 #include "setting_module_api.h"
30 #include "settings_icon_common.h"
32 #ifdef QP_SCREENREADER_ENABLE
33 #include "accessibility.h"
36 #define E_DATA_CONTAINER_TYPE "container_type"
38 static qp_setting_icon_container_type _icon_container_type_get(Evas_Object *view)
40 retif(view == NULL, QP_SETTING_ICON_CONTAINER_NONE, "invalid parameter");
42 return (qp_setting_icon_container_type)evas_object_data_get(view, E_DATA_CONTAINER_TYPE);
45 static void _icon_view_add(QP_Module_Setting *module, Evas_Object *view ,qp_setting_icon_container_type container_type)
47 retif(module == NULL, , "invalid parameter");
48 retif(view == NULL, , "invalid parameter");
50 if (eina_list_data_find(module->view_list, view) == NULL) {
51 evas_object_data_set(view, E_DATA_CONTAINER_TYPE, (void *)container_type);
52 module->view_list = eina_list_append(module->view_list, view);
56 static void _icon_view_del(QP_Module_Setting *module, Evas_Object *view)
58 retif(module == NULL, , "invalid parameter");
59 retif(view == NULL, , "invalid parameter");
61 module->view_list = eina_list_remove(module->view_list, view);
64 HAPI Evas_Object *quickpanel_setting_module_icon_create(QP_Module_Setting *module, Evas_Object *parent)
66 Evas_Object *view = NULL;
67 retif(module == NULL, NULL, "invalid parameter");
68 retif(parent == NULL, NULL, "invalid parameter");
70 view = quickpanel_setting_icon_new(parent);
71 retif(view == NULL, NULL, "failed to create icon");
73 if (module->label_get != NULL) {
74 quickpanel_setting_icon_text_set(view, module->label_get(), ICON_VIEW_STATE_OFF);
76 if (module->handler_press != NULL) {
77 if (module->is_disable_feedback) {
78 quickpanel_setting_icon_click_cb_without_feedback_add(view, module->handler_press, module);
80 quickpanel_setting_icon_click_cb_add(view, module->handler_press, module);
83 evas_object_data_set(view, E_DATA_MODULE_INFO, module);
84 evas_object_show(view);
89 HAPI QP_Module_Setting *quickpanel_setting_module_get_from_icon(Evas_Object *icon)
91 return evas_object_data_get(icon, E_DATA_MODULE_INFO);
94 HAPI void quickpanel_setting_module_icon_add(QP_Module_Setting *module, Evas_Object *icon, qp_setting_icon_container_type container_type)
96 _icon_view_add(module, icon, container_type);
99 HAPI Evas_Object *quickpanel_setting_module_icon_get(QP_Module_Setting *module, qp_setting_icon_container_type container_type)
103 Evas_Object *view = NULL;
104 retif(module == NULL, NULL, "invalid parameter");
106 if (module->view_update != NULL) {
107 EINA_LIST_FOREACH_SAFE(module->view_list, l, l_next, view) {
108 if (_icon_container_type_get(view) == container_type) {
117 HAPI void quickpanel_setting_module_icon_remove(QP_Module_Setting *module, Evas_Object *icon)
119 _icon_view_del(module, icon);
122 HAPI void quickpanel_setting_module_icon_state_set(QP_Module_Setting *module, int state)
124 retif(module == NULL, , "invalid parameter");
125 retif(module->loader == NULL, , "invalid parameter");
127 module->loader->state = state;
130 HAPI int quickpanel_setting_module_icon_state_get(QP_Module_Setting *module)
132 retif(module == NULL, FLAG_TURN_OFF, "invalid parameter");
133 retif(module->loader == NULL, FLAG_TURN_OFF, "invalid parameter");
135 return module->loader->state;
138 HAPI void quickpanel_setting_module_icon_view_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2)
142 Evas_Object *view = NULL;
143 retif(module == NULL, , "invalid parameter");
145 int status = quickpanel_setting_module_icon_state_get(module);
147 if (module->view_update != NULL) {
148 EINA_LIST_FOREACH_SAFE(module->view_list, l, l_next, view) {
149 module->view_update(view, status, flag_extra_1, flag_extra_2);
154 HAPI void quickpanel_setting_module_icon_view_update_text(QP_Module_Setting *module)
158 Evas_Object *view = NULL;
159 retif(module == NULL, , "invalid parameter");
161 if (module->view_update != NULL && module->label_get != NULL) {
162 EINA_LIST_FOREACH_SAFE(module->view_list, l, l_next, view) {
163 quickpanel_setting_icon_text_set(view, module->label_get(), quickpanel_setting_module_icon_state_get(module));
168 HAPI void quickpanel_setting_module_icon_status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2)
170 retif(module == NULL, , "invalid parameter");
172 if (module->status_update != NULL) {
173 module->status_update(module, flag_extra_1, flag_extra_2);
177 HAPI int quickpanel_setting_module_is_icon_clickable(QP_Module_Setting *module)
179 retif(module == NULL, 0, "invalid parameter");
180 retif(module->loader == NULL, 0, "invalid parameter");
182 if (module->loader->timer != NULL) {
185 if (module->loader->state_icon == STATE_ICON_BUSY) {
192 static Eina_Bool _timer_expire_cb(void *data)
194 retif(data == NULL, ECORE_CALLBACK_CANCEL, "invalid parameter");
196 quickpanel_setting_module_icon_timer_del(data);
197 quickpanel_setting_module_icon_status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
199 return ECORE_CALLBACK_CANCEL;
202 HAPI void quickpanel_setting_module_icon_timer_add(QP_Module_Setting *module)
204 retif(module == NULL, , "invalid parameter");
205 retif(module->loader == NULL, , "invalid parameter");
207 quickpanel_setting_module_icon_timer_del(module);
208 module->loader->timer = ecore_timer_add(TIMER_COUNT, _timer_expire_cb, module);
211 HAPI void quickpanel_setting_module_icon_timer_del(QP_Module_Setting *module)
213 retif(module == NULL, , "invalid parameter");
214 retif(module->loader == NULL, , "invalid parameter");
216 if (module->loader->timer != NULL) {
217 ecore_timer_del(module->loader->timer);
218 module->loader->timer = NULL;
222 #ifdef __PROGRESSBAR_ENABLED__
223 static Evas_Object *_progressbar_get(Evas_Object *parent)
225 Evas_Object *content = NULL;
227 content = elm_progressbar_add(parent);
228 elm_progressbar_unit_format_set(content, "%0.0f%%");
229 retif(!content, NULL, "fail to elm_progressbar_add");
231 elm_object_style_set(content, "quickpanel_style");
232 evas_object_size_hint_weight_set(content,
233 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
234 elm_progressbar_pulse(content, EINA_TRUE);
235 evas_object_show(content);
240 static void _progressbar_set(Evas_Object *view, int is_enable, int is_request_on)
242 Evas_Object *content = NULL;
243 Evas_Object *content_old = NULL;
244 retif(view == NULL, , "invalid parameter");
246 if (is_enable == FLAG_ENABLE) {
247 content_old = quickpanel_setting_icon_content_get(view);
248 if (content_old != NULL) {
249 evas_object_del(content_old);
252 content = _progressbar_get(view);
253 quickpanel_setting_icon_content_set(view, content);
255 quickpanel_setting_icon_state_progress_set(view);
256 quickpanel_setting_icon_state_set(view, ICON_VIEW_STATE_DIM);
261 HAPI void quickpanel_setting_module_progress_mode_set(QP_Module_Setting *module, int is_enable, int is_request_on)
265 Evas_Object *view = NULL;
266 retif(module == NULL, , "invalid parameter");
267 retif(module->loader == NULL, , "invalid parameter");
269 EINA_LIST_FOREACH_SAFE(module->view_list, l, l_next, view) {
270 #ifdef __PROGRESSBAR_ENABLED__
271 _progressbar_set(view, is_enable, is_request_on);
274 quickpanel_setting_icon_state_progress_set(view);
279 if (is_enable == FLAG_ENABLE) {
280 module->loader->state_icon = STATE_ICON_BUSY;
282 module->loader->state_icon = STATE_ICON_IDLE;
286 HAPI void quickpanel_setting_module_icon_destroy(QP_Module_Setting *module, Evas_Object *icon)
288 retif(module == NULL, , "invalid parameter");
289 retif(icon == NULL, , "invalid parameter");
291 _icon_view_del(module, icon);
292 quickpanel_setting_icon_click_cb_del(icon, module->handler_press);
293 evas_object_del(icon);