tizen 2.4 release
[apps/home/quickpanel.git] / daemon / settings / modules / assistive_light.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 <app.h>
21 #include <device/led.h>
22 #include <vconf.h>
23 #include <tzsh.h>
24 #include <tzsh_quickpanel_service.h>
25
26 #include "common.h"
27 #include "quickpanel-ui.h"
28 #include "settings.h"
29 #include "setting_utils.h"
30 #include "setting_module_api.h"
31
32 #define E_DATA_POPUP_MODULE_ITEM "mobule_item"
33 #define BUTTON_LABEL _("IDS_ST_BUTTON2_TORCH_ABB")
34 #define BUTTON_ICON_NORMAL "quick_icon_torch.png"
35
36 static void _status_update(QP_Module_Setting *module, int light_status, int flag_extra_2);
37
38 static const char *_label_get(void)
39 {
40         return BUTTON_LABEL;
41 }
42
43 static void _on_vconf_assetive_light_changed(keynode_t *node, void *user_data)
44 {
45         Eina_Bool mode = EINA_FALSE;
46
47         if (!node) {
48                 ERR("node == NULL");
49                 return;
50         }
51
52         mode = node->value.b;
53
54         quickpanel_setting_module_icon_state_set(user_data, mode);
55         _status_update(user_data, mode, FLAG_VALUE_VOID);
56 }
57
58 static int _init(void *data)
59 {
60         vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TORCH_LIGHT, _on_vconf_assetive_light_changed, data);
61
62         return QP_OK;
63 }
64
65 static void _set_assetive_light_mode(Eina_Bool mode)
66 {
67         int max_brightness;
68         int ret = device_flash_get_max_brightness(&max_brightness);
69
70         if (ret != 0) {
71                 ERR("TORCH LIGHT CHANGE: ret != 0 -> %d", ret);
72                 return;
73         } else {
74                 ERR("TORCH LIGHT OK[%d]", max_brightness);
75         }
76
77         int ret_set = -1;
78
79         if(mode == EINA_TRUE) {
80                 ret_set = device_flash_set_brightness(max_brightness);
81                 if (ret_set != 0) {
82                         ERR("Failed to set brightness(%d)[%d]", max_brightness, ret_set);
83                 } else {
84                         if (vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TORCH_LIGHT, 1) < 0) {
85                                 ERR("Failed to set tourch light vconf key");
86                         }
87                 }
88         } else {
89                 ret_set = device_flash_set_brightness(0);
90                 if (ret_set != 0) {
91                         ERR("Failed to set brightness(0)[%d]", ret_set);
92                 } else {
93                         if (vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TORCH_LIGHT, 0) < 0) {
94                                 ERR("Failed to set tourch light vconf key");
95                         }
96                 }
97         }
98 }
99
100 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2)
101 {
102         Evas_Object *image = NULL;
103         const char *icon_path = NULL;
104
105         quickpanel_setting_icon_state_set(view, state);
106         icon_path = BUTTON_ICON_NORMAL;
107         image = quickpanel_setting_icon_image_new(view, icon_path);
108         quickpanel_setting_icon_content_set(view, image);
109         quickpanel_setting_icon_text_set(view, BUTTON_LABEL, state);
110 }
111
112 static void _status_update(QP_Module_Setting *module, int light_status, int flag_extra_2)
113 {
114         int ret = -1;
115         retif(module == NULL, , "Invalid parameter!");
116
117         int brightness = 0;
118         ret = device_flash_get_brightness(&brightness);
119         if (ret != 0) {
120                 ERR("Failed to get brightness[%d]", ret);
121         }
122
123         if (brightness > 0) {
124                 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
125         } else {
126                 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
127         }
128
129         quickpanel_setting_module_icon_view_update(module,
130                         quickpanel_setting_module_icon_state_get(module), FLAG_VALUE_VOID);
131 }
132
133 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
134 {
135         QP_Module_Setting *module = (QP_Module_Setting *)data;
136         retif(module == NULL, , "Invalid parameter!");
137
138         if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
139                 _set_assetive_light_mode(FLAG_TURN_OFF);
140         } else {
141                 _set_assetive_light_mode(FLAG_TURN_ON);
142         }
143
144         _status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
145 }
146
147 static void _lang_changed(void *data)
148 {
149         QP_Module_Setting *module = (QP_Module_Setting *) data;
150         retif(module == NULL, , "Invalid parameter!");
151
152         quickpanel_setting_module_icon_view_update_text(module);
153 }
154
155 static void _refresh(void *data)
156 {
157         QP_Module_Setting *module = (QP_Module_Setting *)data;
158         retif(module == NULL, , "Invalid parameter!");
159
160         quickpanel_setting_module_icon_view_update_text(module);
161 }
162
163 static int _fini(void *data)
164 {
165         return QP_OK;
166 }
167
168 QP_Module_Setting assistive_light =
169 {
170         .name                           = "assisitvelight",
171         .init                           = _init,
172         .fini                           = _fini,
173         .lang_changed           = _lang_changed,
174         .refresh                        = _refresh,
175         .icon_get                       = NULL,
176         .label_get                      = _label_get,
177         .supported_get          = NULL,
178         .view_update            = _view_update,
179         .status_update          = _status_update,
180         .handler_longpress  = NULL,
181         .handler_press          = _mouse_clicked_cb,
182 };
183