[Tizen 3.0] 2.4 source code merge
[apps/core/preloaded/quickpanel.git] / daemon / settings / setting_module_api.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <Elementary.h>
19
20 #include <tzsh.h>
21 #include <tzsh_quickpanel_service.h>
22 #include <E_DBus.h>
23
24 #include "common.h"
25 #include "quickpanel_def.h"
26 #include "quickpanel-ui.h"
27 #include "settings.h"
28 #include "setting_utils.h"
29 #include "setting_module_api.h"
30 #include "settings_icon_common.h"
31
32 #ifdef QP_SCREENREADER_ENABLE
33 #include "accessibility.h"
34 #endif
35
36 #define E_DATA_CONTAINER_TYPE "container_type"
37
38 static qp_setting_icon_container_type _icon_container_type_get(Evas_Object *view)
39 {
40         retif(view == NULL, QP_SETTING_ICON_CONTAINER_NONE, "invalid parameter");
41
42         return (qp_setting_icon_container_type)evas_object_data_get(view, E_DATA_CONTAINER_TYPE);
43 }
44
45 static void _icon_view_add(QP_Module_Setting *module, Evas_Object *view ,qp_setting_icon_container_type container_type)
46 {
47         retif(module == NULL, , "invalid parameter");
48         retif(view == NULL, , "invalid parameter");
49
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);
53         }
54 }
55
56 static void _icon_view_del(QP_Module_Setting *module, Evas_Object *view)
57 {
58         retif(module == NULL, , "invalid parameter");
59         retif(view == NULL, , "invalid parameter");
60
61         module->view_list = eina_list_remove(module->view_list, view);
62 }
63
64 HAPI Evas_Object *quickpanel_setting_module_icon_create(QP_Module_Setting *module, Evas_Object *parent)
65 {
66         Evas_Object *view = NULL;
67         retif(module == NULL, NULL, "invalid parameter");
68         retif(parent == NULL, NULL, "invalid parameter");
69
70         view = quickpanel_setting_icon_new(parent);
71         retif(view == NULL, NULL, "failed to create icon");
72
73         if (module->label_get != NULL) {
74                 quickpanel_setting_icon_text_set(view, module->label_get(), ICON_VIEW_STATE_OFF);
75         }
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);
79                 } else {
80                         quickpanel_setting_icon_click_cb_add(view, module->handler_press, module);
81                 }
82         }
83         evas_object_data_set(view, E_DATA_MODULE_INFO, module);
84         evas_object_show(view);
85
86         return view;
87 }
88
89 HAPI QP_Module_Setting *quickpanel_setting_module_get_from_icon(Evas_Object *icon)
90 {
91         return evas_object_data_get(icon, E_DATA_MODULE_INFO);
92 }
93
94 HAPI void quickpanel_setting_module_icon_add(QP_Module_Setting *module, Evas_Object *icon, qp_setting_icon_container_type container_type)
95 {
96         _icon_view_add(module, icon, container_type);
97 }
98
99 HAPI Evas_Object *quickpanel_setting_module_icon_get(QP_Module_Setting *module, qp_setting_icon_container_type container_type)
100 {
101         Eina_List *l;
102         Eina_List *l_next;
103         Evas_Object *view = NULL;
104         retif(module == NULL, NULL, "invalid parameter");
105
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) {
109                                 return view;
110                         }
111                 }
112         }
113
114         return NULL;
115 }
116
117 HAPI void quickpanel_setting_module_icon_remove(QP_Module_Setting *module, Evas_Object *icon)
118 {
119         _icon_view_del(module, icon);
120 }
121
122 HAPI void quickpanel_setting_module_icon_state_set(QP_Module_Setting *module, int state)
123 {
124         retif(module == NULL, , "invalid parameter");
125         retif(module->loader == NULL, , "invalid parameter");
126
127         module->loader->state = state;
128 }
129
130 HAPI int quickpanel_setting_module_icon_state_get(QP_Module_Setting *module)
131 {
132         retif(module == NULL, FLAG_TURN_OFF, "invalid parameter");
133         retif(module->loader == NULL, FLAG_TURN_OFF, "invalid parameter");
134
135         return module->loader->state;
136 }
137
138 HAPI void quickpanel_setting_module_icon_view_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2)
139 {
140         Eina_List *l;
141         Eina_List *l_next;
142         Evas_Object *view = NULL;
143         retif(module == NULL, , "invalid parameter");
144
145         int status = quickpanel_setting_module_icon_state_get(module);
146
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);
150                 }
151         }
152 }
153
154 HAPI void quickpanel_setting_module_icon_view_update_text(QP_Module_Setting *module)
155 {
156         Eina_List *l;
157         Eina_List *l_next;
158         Evas_Object *view = NULL;
159         retif(module == NULL, , "invalid parameter");
160
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));
164                 }
165         }
166 }
167
168 HAPI void quickpanel_setting_module_icon_status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2)
169 {
170         retif(module == NULL, , "invalid parameter");
171
172         if (module->status_update != NULL) {
173                 module->status_update(module, flag_extra_1, flag_extra_2);
174         }
175 }
176
177 HAPI int quickpanel_setting_module_is_icon_clickable(QP_Module_Setting *module)
178 {
179         retif(module == NULL, 0, "invalid parameter");
180         retif(module->loader == NULL, 0, "invalid parameter");
181
182         if (module->loader->timer != NULL) {
183                 return 0;
184         }
185         if (module->loader->state_icon == STATE_ICON_BUSY) {
186                 return 0;
187         }
188
189         return 1;
190 }
191
192 static Eina_Bool _timer_expire_cb(void *data)
193 {
194         retif(data == NULL, ECORE_CALLBACK_CANCEL, "invalid parameter");
195
196         quickpanel_setting_module_icon_timer_del(data);
197         quickpanel_setting_module_icon_status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
198
199         return ECORE_CALLBACK_CANCEL;
200 }
201
202 HAPI void quickpanel_setting_module_icon_timer_add(QP_Module_Setting *module)
203 {
204         retif(module == NULL, , "invalid parameter");
205         retif(module->loader == NULL, , "invalid parameter");
206
207         quickpanel_setting_module_icon_timer_del(module);
208         module->loader->timer = ecore_timer_add(TIMER_COUNT, _timer_expire_cb, module);
209 }
210
211 HAPI void quickpanel_setting_module_icon_timer_del(QP_Module_Setting *module)
212 {
213         retif(module == NULL, , "invalid parameter");
214         retif(module->loader == NULL, , "invalid parameter");
215
216         if (module->loader->timer != NULL) {
217                 ecore_timer_del(module->loader->timer);
218                 module->loader->timer = NULL;
219         }
220 }
221
222 #ifdef __PROGRESSBAR_ENABLED__
223 static Evas_Object *_progressbar_get(Evas_Object *parent)
224 {
225         Evas_Object *content = NULL;
226
227         content = elm_progressbar_add(parent);
228         elm_progressbar_unit_format_set(content, "%0.0f%%");
229         retif(!content, NULL, "fail to elm_progressbar_add");
230
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);
236
237         return content;
238 }
239
240 static void _progressbar_set(Evas_Object *view, int is_enable, int is_request_on)
241 {
242         Evas_Object *content = NULL;
243         Evas_Object *content_old = NULL;
244         retif(view == NULL, , "invalid parameter");
245
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);
250                         content_old = NULL;
251                 }
252                 content = _progressbar_get(view);
253                 quickpanel_setting_icon_content_set(view, content);
254
255                 quickpanel_setting_icon_state_progress_set(view);
256                 quickpanel_setting_icon_state_set(view, ICON_VIEW_STATE_DIM);
257         }
258 }
259 #endif
260
261 HAPI void quickpanel_setting_module_progress_mode_set(QP_Module_Setting *module, int is_enable, int is_request_on)
262 {
263         Eina_List *l;
264         Eina_List *l_next;
265         Evas_Object *view = NULL;
266         retif(module == NULL, , "invalid parameter");
267         retif(module->loader == NULL, , "invalid parameter");
268
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);
272 #else
273                 if (is_enable) {
274                         quickpanel_setting_icon_state_progress_set(view);
275                 }
276 #endif
277         }
278
279         if (is_enable == FLAG_ENABLE) {
280                 module->loader->state_icon = STATE_ICON_BUSY;
281         } else {
282                 module->loader->state_icon = STATE_ICON_IDLE;
283         }
284 }
285
286 HAPI void quickpanel_setting_module_icon_destroy(QP_Module_Setting *module, Evas_Object *icon)
287 {
288         retif(module == NULL, , "invalid parameter");
289         retif(icon == NULL, , "invalid parameter");
290
291         _icon_view_del(module, icon);
292         quickpanel_setting_icon_click_cb_del(icon, module->handler_press);
293         evas_object_del(icon);
294         icon = NULL;
295 }