4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <setting-display-smart-screen.h>
23 #define SETTING_DISPLAY_SMART_STAY "IDS_ST_MBODY_SMART_STAY"
24 #define SETTING_DISPLAY_SMART_STAY_DESC "Screen stays on as long as you are looking at it"
26 #define SETTING_DISPLAY_SMART_ROTATION "IDS_ST_MBODY_SMART_ROTATION"
27 #define SETTING_DISPLAY_SMART_ROTATION_DESC "Screen display direction adjusts to your angle of sights"
29 #define SETTING_DISPLAY_SMART_STAY_DLG_STR1 "Smart stay detects your eyes with the front camera so that the screen stays on when you are looking at it"
31 #define SETTING_DISPLAY_SMART_STAY_DLG_STR2 "Smart stay may not work in these situations:<br>"\
32 " .When front camera fails to detect face and eyes<br>"\
33 " .When the source of light is behind you or when using device in the dark<br>"\
34 " .When front camera is used for the application"
36 #define SETTING_DISPLAY_SMART_ROTATION_DLG_STR1 "Smart rotation disables auto screen rotation by checking the orientation of your face and the device by its front camera."
38 #define SETTING_DISPLAY_SMART_ROTATION_DLG_STR2 "Smart rotation may not work in these situations:<br>"\
39 " .When front camera fails to detect face and eyes<br>"\
40 " .When the source of light is behind you or when using device in the dark<br>"\
41 " .When front camera is used for the application<br>"\
42 "Screen rotation can be slower if Smart rotation enabled"
43 #define DO_NOT_ASK_AGAIN "Don't ask again"
45 static int setting_display_smart_screen_create(void *cb);
46 static int setting_display_smart_screen_destroy(void *cb);
47 static int setting_display_smart_screen_update(void *cb);
48 static int setting_display_smart_screen_cleanup(void *cb);
50 setting_view setting_view_display_smart_screen = {
51 .create = setting_display_smart_screen_create,
52 .destroy = setting_display_smart_screen_destroy,
53 .update = setting_display_smart_screen_update,
54 .cleanup = setting_display_smart_screen_cleanup,
58 __smart_stay_on_resp_cb(void *data, Evas_Object *obj, void *event_info)
61 setting_retm_if(NULL == data, "NULL == data");
62 int response_type = btn_type(obj);
63 SettingDisplayUG *ad = (SettingDisplayUG *) data;
64 if (POPUP_RESPONSE_OK == response_type) { //need set vconf
65 ret_if (!ad->data_smart_stay);
66 int err = vconf_set_int(VCONFKEY_PM_SMARTSTAY_STATUS, ad->data_smart_stay->chk_status);
67 if (0 != err) { //if set failed, need rollback
68 SETTING_TRACE_ERROR("Set vconf Failed");
69 if (ad->data_smart_stay) {
70 ad->data_smart_stay->chk_status = !ad->data_smart_stay->chk_status;
71 elm_check_state_set(ad->data_smart_stay->eo_check, ad->data_smart_stay->chk_status);
76 if (ad->popup_chk && elm_check_state_get(ad->popup_chk)) {
77 vconf_set_bool(VCONFKEY_SETAPPL_SMARTSCREEN_SMARTSTAY_STATUS_REMINDER, FALSE);
80 } else if (POPUP_RESPONSE_CANCEL == response_type) { //need rollback
81 if (ad->data_smart_stay) {
82 ad->data_smart_stay->chk_status = !ad->data_smart_stay->chk_status;
83 elm_check_state_set(ad->data_smart_stay->eo_check, ad->data_smart_stay->chk_status);
87 evas_object_del(ad->popup);
93 __smart_rotate_on_resp_cb(void *data, Evas_Object *obj, void *event_info)
96 setting_retm_if(NULL == data, "NULL == data");
97 int response_type = btn_type(obj);
98 SettingDisplayUG *ad = (SettingDisplayUG *) data;
99 if (POPUP_RESPONSE_OK == response_type) { //need set vconf
100 ret_if (!ad->data_smart_rotation);
101 int err = vconf_set_bool(VCONFKEY_SETAPPL_SMARTSCREEN_SMART_ROTATION, ad->data_smart_rotation->chk_status);
102 if (0 != err) { //if set failed, need rollback
103 SETTING_TRACE_ERROR("Set vconf Failed");
104 if (ad->data_smart_rotation) {
105 ad->data_smart_rotation->chk_status = !ad->data_smart_rotation->chk_status;
106 elm_check_state_set(ad->data_smart_rotation->eo_check, ad->data_smart_rotation->chk_status);
111 if (ad->popup_chk && elm_check_state_get(ad->popup_chk)) {
112 vconf_set_bool(VCONFKEY_SETAPPL_SMARTSCREEN_SMARTROTATE_STATUS_REMINDER, FALSE);
115 } else if (POPUP_RESPONSE_CANCEL == response_type) { //need rollback
116 if (ad->data_smart_rotation) {
117 ad->data_smart_rotation->chk_status = !ad->data_smart_rotation->chk_status;
118 elm_check_state_set(ad->data_smart_rotation->eo_check, ad->data_smart_rotation->chk_status);
122 evas_object_del(ad->popup);
124 ad->popup_chk = NULL;
128 static void __handle_via_check_status(void *data)
130 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
131 retm_if(!list_item || !list_item->userdata, "list_item == NULL || list_item->userdata");
132 SettingDisplayUG *ad = list_item->userdata;
134 SETTING_TRACE("list_item->chk_status = %d", list_item->chk_status);
135 if (!safeStrCmp(SETTING_DISPLAY_SMART_STAY, list_item->keyStr)) {
136 int reminder_flag = TRUE;
137 int ret = vconf_get_bool(VCONFKEY_SETAPPL_SMARTSCREEN_SMARTSTAY_STATUS_REMINDER, &reminder_flag);
139 SETTING_TRACE_ERROR("Failed to get vconf value");
141 SETTING_TRACE("reminder_flag:%d", reminder_flag);
142 if (list_item->chk_status && reminder_flag) {
144 setting_create_popup_with_image_check(ad, ad->win_get,
145 _(SETTING_DISPLAY_SMART_STAY),
146 _(SETTING_DISPLAY_SMART_STAY_DLG_STR1),
147 _(SETTING_DISPLAY_SMART_STAY_DLG_STR2),
148 SETTING_ICON_PATH_CFG"SmartScreen.png",
151 __smart_stay_on_resp_cb,
153 2, _("IDS_COM_SK_OK"),
154 _("IDS_COM_SK_CANCEL"));
158 vconf_set_int(VCONFKEY_PM_SMARTSTAY_STATUS, list_item->chk_status);
159 if (0 != ret) { /* rollback */
160 SETTING_TRACE_ERROR("Set vconf Failed");
161 list_item->chk_status = !list_item->chk_status;
162 elm_check_state_set(list_item->eo_check,
163 list_item->chk_status);
167 } else if(!safeStrCmp(SETTING_DISPLAY_SMART_ROTATION, list_item->keyStr)) {
168 int reminder_flag = TRUE;
169 int ret = vconf_get_bool(VCONFKEY_SETAPPL_SMARTSCREEN_SMARTROTATE_STATUS_REMINDER, &reminder_flag);
171 SETTING_TRACE_ERROR("Failed to get vconf value");
173 SETTING_TRACE("reminder_flag:%d", reminder_flag);
174 if (list_item->chk_status && reminder_flag) {
176 setting_create_popup_with_image_check(ad, ad->win_get,
177 _(SETTING_DISPLAY_SMART_ROTATION),
178 _(SETTING_DISPLAY_SMART_ROTATION_DLG_STR1),
179 _(SETTING_DISPLAY_SMART_ROTATION_DLG_STR2),
180 SETTING_ICON_PATH_CFG"SmartScreen.png",
183 __smart_rotate_on_resp_cb,
185 2, _("IDS_COM_SK_OK"),
186 _("IDS_COM_SK_CANCEL"));
190 vconf_set_bool(VCONFKEY_SETAPPL_SMARTSCREEN_SMART_ROTATION, list_item->chk_status);
191 if (0 != ret) { /* rollback */
192 SETTING_TRACE_ERROR("Set vconf Failed");
193 list_item->chk_status = !list_item->chk_status;
194 elm_check_state_set(list_item->eo_check,
195 list_item->chk_status);
202 static void __setting_display_smart_screen_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
206 setting_retm_if(data == NULL, "Data parameter is NULL");
207 setting_retm_if(event_info == NULL, "Invalid argument: event info is NULL");
208 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
209 elm_genlist_item_selected_set(item, 0);
210 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
211 int old_status = elm_check_state_get(list_item->eo_check);
212 list_item->chk_status = !old_status;
213 elm_check_state_set(list_item->eo_check, list_item->chk_status);
214 __handle_via_check_status(list_item);
217 static void __setting_display_smart_screen_chk_btn_cb(void *data, Evas_Object *obj, void *event_info)
221 retm_if(data == NULL, "Data parameter is NULL");
222 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
223 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
224 __handle_via_check_status(list_item);
227 /* ***************************************************
231 ***************************************************/
232 static int setting_display_smart_screen_create(void *cb)
236 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
237 SettingDisplayUG *ad = (SettingDisplayUG *) cb;
239 Evas_Object *scroller = NULL;
240 setting_push_layout_navi_bar_genlist(ad->win_main_layout,
242 _(Keystr_SmartScreen), _("IDS_COM_BODY_BACK"),
244 __setting_display_smart_screen_click_softkey_back_cb,
248 Elm_Object_Item *item = NULL;
249 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
250 ELM_GENLIST_ITEM_NONE, NULL, NULL);
251 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
255 ret = vconf_get_int(VCONFKEY_PM_SMARTSTAY_STATUS, &value);
256 SETTING_TRACE("value = %d", value);
257 setting_retvm_if(ret != 0, SETTING_RETURN_FAIL, "fail to get vconf");
259 ad->data_smart_stay = setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
260 __setting_display_smart_screen_mouse_up_Gendial_list_cb,
261 ad, SWALLOW_Type_1TOGGLE, NULL,
263 SETTING_DISPLAY_SMART_STAY, NULL,
264 __setting_display_smart_screen_chk_btn_cb);
265 if (ad->data_smart_stay) {
266 ad->data_smart_stay->userdata = ad;
268 SETTING_TRACE_ERROR("ad->data_launch_image is NULL");
271 setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
272 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
273 NULL, NULL, 0, SETTING_DISPLAY_SMART_STAY_DESC, NULL, NULL);
274 elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL),
275 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
277 ret = vconf_get_bool(VCONFKEY_SETAPPL_SMARTSCREEN_SMART_ROTATION, &value);
278 SETTING_TRACE("value = %d", value);
279 setting_retvm_if(ret != 0, SETTING_RETURN_FAIL, "fail to get vconf");
281 ad->data_smart_rotation = setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
282 __setting_display_smart_screen_mouse_up_Gendial_list_cb,
283 ad, SWALLOW_Type_1TOGGLE, NULL,
285 SETTING_DISPLAY_SMART_ROTATION, NULL,
286 __setting_display_smart_screen_chk_btn_cb);
287 if (ad->data_smart_rotation) {
288 ad->data_smart_rotation->userdata = ad;
290 SETTING_TRACE_ERROR("ad->data_launch_image is NULL");
293 setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
294 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
295 NULL, NULL, 0, SETTING_DISPLAY_SMART_ROTATION_DESC, NULL, NULL);
296 elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_bottom_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL),
297 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
299 setting_view_display_smart_screen.is_create = 1;
300 return SETTING_RETURN_SUCCESS;
303 static int setting_display_smart_screen_destroy(void *cb)
307 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
308 SettingDisplayUG *ad = (SettingDisplayUG *) cb;
310 elm_naviframe_item_pop(ad->navi_bar);
311 setting_view_display_smart_screen.is_create = 0;
313 return SETTING_RETURN_SUCCESS;
316 static int setting_display_smart_screen_update(void *cb)
320 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
322 return SETTING_RETURN_SUCCESS;
325 static int setting_display_smart_screen_cleanup(void *cb)
328 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
330 SettingDisplayUG *ad = (SettingDisplayUG *) cb;
332 setting_display_smart_screen_destroy(ad);
334 return SETTING_RETURN_SUCCESS;
337 /* ***************************************************
341 ***************************************************/
343 static void __setting_display_smart_screen_click_softkey_back_cb(void *data, Evas_Object *obj, void *event_info)
347 setting_retm_if(data == NULL,
348 "[Setting > Display] Data parameter is NULL");
350 SettingDisplayUG *ad = (SettingDisplayUG *) data;
352 setting_view_change(&setting_view_display_smart_screen, &setting_view_display_main, ad);