tizen 2.3 release
[apps/home/settings.git] / setting-ledindicator / src / setting-ledindicator.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-ledindicator.h>
22 #include <setting-cfg.h>
23
24 #ifndef UG_MODULE_API
25 #define UG_MODULE_API __attribute__ ((visibility("default")))
26 #endif
27
28 static void setting_ledindicator_ug_cb_resize(void *data, Evas *e,
29                                          Evas_Object *obj, void *event_info)
30 {
31         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *) data;
32         setting_view_update(&setting_view_ledindicator_main, ad);
33 }
34
35 static void *setting_ledindicator_ug_on_create(ui_gadget_h ug,
36                                           enum ug_mode mode, app_control_h service,
37                                           void *priv)
38 {
39         SETTING_TRACE_BEGIN;
40         setting_retvm_if((!priv), NULL, "!priv");
41         SettingLedIndicatorUG *ledindicatorUG = priv;
42         ledindicatorUG->ug = ug;
43         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
44
45         ledindicatorUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
46         ledindicatorUG->win_get = (Evas_Object *) ug_get_window();
47
48         evas_object_show(ledindicatorUG->win_main_layout);
49         ledindicatorUG->evas = evas_object_evas_get(ledindicatorUG->win_main_layout);
50
51         setting_retvm_if(ledindicatorUG->win_main_layout == NULL, NULL,
52                          "cannot get main window ");
53
54         // create bg
55         ledindicatorUG->bg = elm_bg_add(ledindicatorUG->win_get);
56         elm_object_style_set(ledindicatorUG->bg, "dialogue_field");
57         evas_object_size_hint_weight_set(ledindicatorUG->bg, EVAS_HINT_EXPAND,
58                                          EVAS_HINT_EXPAND);
59
60         // creating a view.
61         setting_view_create(&setting_view_ledindicator_main, (void *)ledindicatorUG);
62         evas_object_event_callback_add(ledindicatorUG->win_main_layout,
63                                        EVAS_CALLBACK_RESIZE,
64                                        setting_ledindicator_ug_cb_resize, ledindicatorUG);
65
66         return ledindicatorUG->ly_main;
67 }
68
69 static void setting_ledindicator_ug_on_start(ui_gadget_h ug, app_control_h service,
70                                         void *priv)
71 {
72 }
73
74 static void setting_ledindicator_ug_on_pause(ui_gadget_h ug, app_control_h service,
75                                         void *priv)
76 {
77 }
78
79 static void setting_ledindicator_ug_on_resume(ui_gadget_h ug, app_control_h service,
80                                          void *priv)
81 {
82 }
83
84 static void setting_ledindicator_ug_on_destroy(ui_gadget_h ug, app_control_h service,
85                                           void *priv)
86 {
87         SETTING_TRACE_BEGIN;
88         setting_retm_if((!priv), "!priv");
89         SettingLedIndicatorUG *ledindicatorUG = priv;
90         evas_object_event_callback_del(ledindicatorUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_ledindicator_ug_cb_resize);       //fix flash issue for gallery
91         ledindicatorUG->ug = ug;
92         if (ledindicatorUG->bg) {
93                 evas_object_del(ledindicatorUG->bg);
94         }
95         ledindicatorUG->bg = NULL;
96
97         // called when this shared gadget is terminated. similar with app_exit
98         setting_view_destroy(&setting_view_ledindicator_main, ledindicatorUG);
99
100         if (NULL != ug_get_layout(ledindicatorUG->ug)) {
101                 evas_object_hide((Evas_Object *) ug_get_layout(ledindicatorUG->ug));
102                 evas_object_del((Evas_Object *) ug_get_layout(ledindicatorUG->ug));
103         }
104 }
105
106 static void setting_ledindicator_ug_on_message(ui_gadget_h ug, app_control_h msg,
107                                           app_control_h service, void *priv)
108 {
109         SETTING_TRACE_BEGIN;
110 }
111
112 static void setting_ledindicator_ug_on_event(ui_gadget_h ug,
113                                         enum ug_event event, app_control_h service,
114                                         void *priv)
115 {
116         SETTING_TRACE_BEGIN;
117         setting_retm_if((!priv), "!priv");
118         SettingLedIndicatorUG *ad = priv;
119         switch (event) {
120         case UG_EVENT_LOW_MEMORY:
121                 break;
122         case UG_EVENT_LOW_BATTERY:
123                 break;
124         case UG_EVENT_LANG_CHANGE:
125                 setting_navi_items_update(ad->navi_bar);
126                 break;
127         case UG_EVENT_ROTATE_PORTRAIT:
128                 break;
129         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
130                 break;
131         case UG_EVENT_ROTATE_LANDSCAPE:
132                 break;
133         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
134                 break;
135         case UG_EVENT_REGION_CHANGE:
136                 break;
137         default:
138                 break;
139         }
140 }
141
142 static void setting_ledindicator_ug_on_key_event(ui_gadget_h ug,
143                                             enum ug_key_event event,
144                                             app_control_h service, void *priv)
145 {
146         SETTING_TRACE_BEGIN;
147         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *) priv;
148
149         switch (event) {
150         case UG_KEY_EVENT_END:
151                 {
152                         if (elm_naviframe_top_item_get(ad->navi_bar) ==
153                             elm_naviframe_bottom_item_get(ad->
154                                                                  navi_bar)) {
155                                 ug_destroy_me(ug);
156                         } else {
157
158                                 setting_view_cb_at_endKey(ad);
159                         }
160                 }
161                 break;
162         default:
163                 break;
164         }
165 }
166
167 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
168 {
169         SETTING_TRACE_BEGIN;
170         SettingLedIndicatorUG *ledindicatorUG = calloc(1, sizeof(SettingLedIndicatorUG));
171         setting_retvm_if(!ledindicatorUG, -1, "Create SettingLedIndicatorUG obj failed");
172
173         ops->create = setting_ledindicator_ug_on_create;
174         ops->start = setting_ledindicator_ug_on_start;
175         ops->pause = setting_ledindicator_ug_on_pause;
176         ops->resume = setting_ledindicator_ug_on_resume;
177         ops->destroy = setting_ledindicator_ug_on_destroy;
178         ops->message = setting_ledindicator_ug_on_message;
179         ops->event = setting_ledindicator_ug_on_event;
180         ops->key_event = setting_ledindicator_ug_on_key_event;
181         ops->priv = ledindicatorUG;
182         ops->opt = UG_OPT_INDICATOR_ENABLE;
183         return 0;
184 }
185
186 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
187 {
188         SETTING_TRACE_BEGIN;
189         struct SettingLedIndicatorUG *ledindicatorUG;
190         setting_retm_if(!ops, "ops == NULL");
191
192         ledindicatorUG = ops->priv;
193         if (ledindicatorUG) {
194                 FREE(ledindicatorUG);
195         }
196 }
197
198 static Setting_Cfg_Node_T s_cfg_node_array[] = {
199         {"IDS_ST_MBODY_CHARGING", NULL, "viewtype:frontpage", 0, 0, 0, Cfg_Item_View_Node_Toggle, NULL, NULL, NULL, NULL},
200         {"IDS_ST_BODY_LEDOT_LOW_BATTERY", NULL, "viewtype:frontpage", 0, 0, 0, Cfg_Item_View_Node_Toggle, NULL, NULL, NULL, NULL},
201         {"IDS_ST_BODY_NOTIFICATIONS", NULL, "viewtype:frontpage", 0, 0, 0, Cfg_Item_View_Node_Toggle, NULL, NULL, NULL, NULL},
202         {"IDS_ST_BODY_VOICE_RECORDING", NULL, "viewtype:frontpage", 0, 0, 0, Cfg_Item_View_Node_Toggle, NULL, NULL, NULL, NULL},
203 };
204
205 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv, char** applocale)
206 {
207         SETTING_TRACE_BEGIN;
208         SETTING_TRACE(">> setting-ledindicator-efl DB search code");
209         setting_retvm_if(!priv || !applocale,SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "pplist/applocale is NULL");
210
211         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
212
213         Eina_List **pplist = (Eina_List**)priv;
214         int i;
215         int size = sizeof(s_cfg_node_array)/sizeof(s_cfg_node_array[0]);
216         for(i=0;i<size;i++) {
217                 Setting_Cfg_Node_T * node = setting_plugin_search_item_subindex_add(s_cfg_node_array[i].key_name, s_cfg_node_array[i].ug_args, IMG_LEDIndicator,s_cfg_node_array[i].item_type,  s_cfg_node_array[i].data, "LED");
218                 *pplist = eina_list_append(*pplist, node);
219         }
220         return 0;
221 }
222
223 /**
224 * @brief get toggle state for "charging"
225 *
226 * @param stat store the toggle state
227 * @param data application context
228 *
229 * @return 0 for success
230 */
231 EXPORT_PUBLIC
232 int get_ledindicator_ug_charging_state(Cfg_Item_State* stat, void* data)
233 {
234         SETTING_TRACE_BEGIN;
235
236         int value = -1;
237         int ret = vconf_get_bool(VCONFKEY_SETAPPL_LED_INDICATOR_CHARGING, &value);
238
239         if (value == 1){
240                 *stat = Cfg_Item_On;
241         }else{
242                 *stat = Cfg_Item_Off;
243         }
244         return ret;
245 }
246
247 /**
248 * @brief set toggle state for "charging"
249 *
250 * @param stat the toggle state will be set
251 * @param data application context
252 *
253 * @return 0 for success
254 */
255 EXPORT_PUBLIC
256 int set_ledindicator_ug_charging_state(Cfg_Item_State stat, void* item, void* data)
257 {
258         SETTING_TRACE_BEGIN;
259         int value = -1;
260
261         if (stat == Cfg_Item_On){
262                 value = 1;
263         }else if (stat == Cfg_Item_Off){
264                 value = 0;
265         }else{
266                 value = 0;
267         }
268         int ret = vconf_set_bool(VCONFKEY_SETAPPL_LED_INDICATOR_CHARGING, value);
269         return ret;
270 }
271
272 /**
273 * @brief get toggle state for "low battery"
274 *
275 * @param stat store the toggle state
276 * @param data application context
277 *
278 * @return 0 for success
279 */
280 EXPORT_PUBLIC
281 int get_ledindicator_ug_low_battery_state(Cfg_Item_State* stat, void* data)
282 {
283         SETTING_TRACE_BEGIN;
284
285         int value = -1;
286         int ret = vconf_get_bool(VCONFKEY_SETAPPL_LED_INDICATOR_LOW_BATT, &value);
287
288         if (value == 1){
289                 *stat = Cfg_Item_On;
290         }else{
291                 *stat = Cfg_Item_Off;
292         }
293         return ret;
294 }
295
296 /**
297 * @brief set toggle state for "low_battery"
298 *
299 * @param stat the toggle state will be set
300 * @param data application context
301 *
302 * @return 0 for success
303 */
304 EXPORT_PUBLIC
305 int set_ledindicator_ug_low_battery_state(Cfg_Item_State stat, void* item, void* data)
306 {
307         SETTING_TRACE_BEGIN;
308         int value = -1;
309
310         if (stat == Cfg_Item_On){
311                 value = 1;
312         }else if (stat == Cfg_Item_Off){
313                 value = 0;
314         }else{
315                 value = 0;
316         }
317         int ret = vconf_set_bool(VCONFKEY_SETAPPL_LED_INDICATOR_LOW_BATT, value);
318         return ret;
319 }
320
321 /**
322 * @brief get toggle state for "notifications"
323 *
324 * @param stat store the toggle state
325 * @param data application context
326 *
327 * @return 0 for success
328 */
329 EXPORT_PUBLIC
330 int get_ledindicator_ug_notifications_state(Cfg_Item_State* stat, void* data)
331 {
332         SETTING_TRACE_BEGIN;
333
334         int value = -1;
335         int ret = vconf_get_bool(VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS, &value);
336
337         if (value == 1){
338                 *stat = Cfg_Item_On;
339         }else{
340                 *stat = Cfg_Item_Off;
341         }
342         return ret;
343 }
344
345 /**
346 * @brief set toggle state for "notifications"
347 *
348 * @param stat the toggle state will be set
349 * @param data application context
350 *
351 * @return 0 for success
352 */
353 EXPORT_PUBLIC
354 int set_ledindicator_ug_notifications_state(Cfg_Item_State stat, void* item, void* data)
355 {
356         SETTING_TRACE_BEGIN;
357         int value = -1;
358
359         if (stat == Cfg_Item_On){
360                 value = 1;
361         }else if (stat == Cfg_Item_Off){
362                 value = 0;
363         }else{
364                 value = 0;
365         }
366         int ret = vconf_set_bool(VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS, value);
367         return ret;
368 }
369
370 /**
371 * @brief get toggle state for "voice recording"
372 *
373 * @param stat store the toggle state
374 * @param data application context
375 *
376 * @return 0 for success
377 */
378 EXPORT_PUBLIC
379 int get_ledindicator_ug_voice_recording_state(Cfg_Item_State* stat, void* data)
380 {
381         SETTING_TRACE_BEGIN;
382
383         int value = -1;
384         int ret = vconf_get_bool(VCONFKEY_SETAPPL_LED_INDICATOR_VOICE_REC, &value);
385
386         if (value == 1){
387                 *stat = Cfg_Item_On;
388         }else{
389                 *stat = Cfg_Item_Off;
390         }
391         return ret;
392 }
393
394 /**
395 * @brief set toggle state for "notifications"
396 *
397 * @param stat the toggle state will be set
398 * @param data application context
399 *
400 * @return 0 for success
401 */
402 EXPORT_PUBLIC
403 int set_ledindicator_ug_voice_recording_state(Cfg_Item_State stat, void* item, void* data)
404 {
405         SETTING_TRACE_BEGIN;
406         int value = -1;
407
408         if (stat == Cfg_Item_On){
409                 value = 1;
410         }else if (stat == Cfg_Item_Off){
411                 value = 0;
412         }else{
413                 value = 0;
414         }
415         int ret = vconf_set_bool(VCONFKEY_SETAPPL_LED_INDICATOR_VOICE_REC, value);
416         return ret;
417 }
418
419
420 /**
421 * @brief function table for searchable menu item "charging"
422 *
423 * @see the struct cfg_func_table defination
424 */
425 EXPORT_PUBLIC
426 cfg_func_table opt_tab_charging = {
427         .get_item_state = get_ledindicator_ug_charging_state,
428         .set_item_state = set_ledindicator_ug_charging_state,
429         .set_item_update_ui = NULL,
430 };
431
432 /**
433 * @brief function table for searchable menu item "low battery"
434 *
435 * @see the struct cfg_func_table defination
436 */
437
438 EXPORT_PUBLIC
439 cfg_func_table opt_tab_low_batt = {
440         .get_item_state = get_ledindicator_ug_low_battery_state,
441         .set_item_state = set_ledindicator_ug_low_battery_state,
442         .set_item_update_ui = NULL,
443 };
444
445 /**
446 * @brief function table for searchable menu item "notifications"
447 *
448 * @see the struct cfg_func_table defination
449 */
450
451 EXPORT_PUBLIC
452 cfg_func_table opt_tab_noti = {
453         .get_item_state = get_ledindicator_ug_notifications_state,
454         .set_item_state = set_ledindicator_ug_notifications_state,
455         .set_item_update_ui = NULL,
456 };
457
458 /**
459 * @brief function table for searchable menu item "voice recording"
460 *
461 * @see the struct cfg_func_table defination
462 */
463
464 EXPORT_PUBLIC
465 cfg_func_table opt_tab_voice_rec = {
466         .get_item_state = get_ledindicator_ug_voice_recording_state,
467         .set_item_state = set_ledindicator_ug_voice_recording_state,
468         .set_item_update_ui = NULL,
469 };
470
471
472 /**
473 * @brief get the operation function table for searchable menu items
474 *
475 * @param str_id key string for searchable menu items
476 * @param tfunc_obj application context
477 *
478 * @return 0 for success
479 */
480 UG_MODULE_API int setting_plugin_search_query_ops(char* str_id, void** tfunc_obj)
481 {
482         SETTING_TRACE_BEGIN;
483         SETTING_TRACE(">> get tfunc operation via plugin-model 1");
484         if (str_id && !safeStrCmp(str_id, _("IDS_ST_MBODY_CHARGING"))) {
485                 *tfunc_obj = (void*)&opt_tab_charging;
486         }else if(str_id && !safeStrCmp(str_id, _("IDS_ST_BODY_LEDOT_LOW_BATTERY"))){
487                 *tfunc_obj = (void*)&opt_tab_low_batt;
488         }else if(str_id && !safeStrCmp(str_id, _("IDS_ST_BODY_NOTIFICATIONS"))){
489                 *tfunc_obj = (void*)&opt_tab_noti;
490         }else if(str_id && !safeStrCmp(str_id, _("IDS_ST_BODY_VOICE_RECORDING"))){
491                 *tfunc_obj = (void*)&opt_tab_voice_rec;
492         }
493         SETTING_TRACE(">> get tfunc operation via plugin-model 2");
494         return 0;
495 }
496
497
498