0cdba42df3650fb02e715d3ff441608dd3f1f360
[apps/home/settings.git] / setting-display / src / setting-display-screen-mode.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-display-screen-mode.h>
22 #include <Ecore_X.h>
23
24 static int setting_display_screen_mode_create(void *cb);
25 static int setting_display_screen_mode_destroy(void *cb);
26 static int setting_display_screen_mode_update(void *cb);
27 static int setting_display_screen_mode_cleanup(void *cb);
28
29 /* Don't support Natural mode in redwood. */
30 const char* str_in_arr[4] = {"Dynamic", "Standard", "Natural", "Movie"};
31 const char* str_out_arr[4] = {Keystr_Dynamic, Keystr_Standard, Keystr_Natural, Keystr_Movie};
32
33 static void  setting_display_screen_mode_mouse_up_Gendial_list_radio_cb(void *data, Evas_Object *obj, void *event_info);
34
35 setting_view setting_view_display_screen_mode = {
36         .create = setting_display_screen_mode_create,
37         .destroy = setting_display_screen_mode_destroy,
38         .update = setting_display_screen_mode_update,
39         .cleanup = setting_display_screen_mode_cleanup,
40 };
41
42
43 static Evas_Object *__gl_content_get(void *data, Evas_Object *obj, const char *part)
44 {
45         if (!strcmp(part, "elm.icon")) {
46                 Evas_Object *image;
47                 image = elm_image_add(obj);
48                 elm_image_file_set(image, IMG_SCREEN_MODE, NULL);
49
50                 //int w = 668; /* left padding and right padding is 26, so the width = 720 - 26 -26 */
51                 int w = 720-36*2;/*enlarge the padding to 36 to fix issue P130319-9042 */
52                 int h = 0;
53                 elm_image_object_size_get(image, NULL, &h);
54                 evas_object_size_hint_min_set(image, ELM_SCALE_SIZE(w), ELM_SCALE_SIZE(h));
55                 evas_object_size_hint_max_set(image, w * WIDGET_SCALE_FACTOR, h * WIDGET_SCALE_FACTOR);
56                 evas_object_resize(image, w * WIDGET_SCALE_FACTOR, h * WIDGET_SCALE_FACTOR);
57
58                 return image;
59         }
60         return NULL;
61 }
62
63 static void __gl_item_del(void *data, Evas_Object *obj)
64 {
65         setting_retm_if(data == NULL, "Data parameter is NULL");
66         Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *) data;
67         if (item_data) {
68                 G_FREE(item_data->keyStr);
69                 G_FREE(item_data->sub_desc);
70                 FREE(item_data);
71         }
72 }
73
74 /* ***************************************************
75  *
76  *basic func
77  *
78  ***************************************************/
79 static int setting_display_screen_mode_create(void *cb)
80 {
81         SETTING_TRACE_BEGIN;
82         /* error check */
83         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
84
85         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
86
87         setting_call_back_func gl_sel_cb = NULL;
88         Evas_Object *genlist = NULL;
89         Setting_GenGroupItem_Data *item_data = NULL;
90
91
92         if (&setting_view_display_screen_mode == ad->view_to_load) {
93                 ad->ly_main =
94                     setting_create_layout_navi_bar_genlist(ad->win_main_layout,
95                                                    ad->win_get,
96                                                    "IDS_ST_BODY_SCREEN_MODE",
97                                                    _("IDS_COM_BODY_BACK"),
98                                                    NULL,
99                                                    (setting_call_back_func)setting_display_screen_mode_click_softkey_back_cb,
100                                                    NULL, ad,
101                                                    &genlist,
102                                                    &ad->navi_bar);
103         } else {
104                 genlist = elm_genlist_add(ad->navi_bar);
105                 retvm_if(genlist == NULL, SETTING_RETURN_FAIL, "scroller == NULL");
106                 elm_object_style_set(genlist, "dialogue");
107                 elm_genlist_clear(genlist);     /* first to clear list */
108                 setting_push_layout_navi_bar("IDS_ST_BODY_SCREEN_MODE", _("IDS_COM_BODY_BACK"),
109                                            NULL, NULL,
110                                            (setting_call_back_func)setting_display_screen_mode_click_softkey_back_cb,
111                                            NULL, NULL, ad, genlist, ad->navi_bar, NULL);
112         }
113         ad->genlist = genlist;
114
115         evas_object_smart_callback_add(ad->genlist, "realized", __gl_realized_cb, ad);
116
117         Elm_Object_Item *item = elm_genlist_item_append(genlist,
118                                                         &(itc_seperator),
119                                                         NULL, NULL,
120                                                         ELM_GENLIST_ITEM_NONE,
121                                                         NULL, NULL);
122         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
123
124         ad->itc_screen_mode.item_style = "1icon/with_no_line";
125         ad->itc_screen_mode.func.text_get = NULL;
126         ad->itc_screen_mode.func.content_get = __gl_content_get;
127         ad->itc_screen_mode.func.state_get = NULL;
128         ad->itc_screen_mode.func.del = __gl_item_del;
129
130         Setting_GenGroupItem_Data *screen_mode = (Setting_GenGroupItem_Data *) calloc(1, sizeof(Setting_GenGroupItem_Data));
131         setting_retvm_if(!screen_mode, SETTING_RETURN_FAIL, "calloc failed");
132
133         if (screen_mode) {
134                 screen_mode->userdata = ad;
135                 screen_mode->item = elm_genlist_item_append(genlist, &(ad->itc_screen_mode), screen_mode, NULL,
136                                             ELM_GENLIST_ITEM_NONE, NULL, NULL);
137                 elm_genlist_item_select_mode_set(screen_mode->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
138         } else {
139                 SETTING_TRACE_ERROR("screen_mode is NULL");
140                 return SETTING_RETURN_FAIL;
141         }
142
143         item = elm_genlist_item_append(genlist,
144                                                         &(itc_sep_line),
145                                                         NULL, NULL,
146                                                         ELM_GENLIST_ITEM_NONE,
147                                                         NULL, NULL);
148         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
149
150         gl_sel_cb = setting_display_screen_mode_mouse_up_Gendial_list_radio_cb;
151
152         Evas_Object *radio = elm_radio_add(genlist);
153         elm_radio_state_value_set(radio, -1);
154
155         int i = 0;
156
157         for (i = 0 ; i < SCREENMODE_MAX ; i++)
158         {
159 #if !SUPPORT_AMOLED             /* Natural mode can be supported on AMOLED only. So, skip this menu in other cases */
160                 if(safeStrCmp(str_in_arr[i], "Natural") == 0)
161                 {
162                         continue;
163                 }
164 #endif
165                 item_data = setting_create_Gendial_field_1radio(genlist,
166                                                         &(itc_1text_1icon_2),
167                                                         gl_sel_cb,
168                                                         radio,  /* sel data */
169                                                         SWALLOW_Type_1RADIO,
170                                                         radio, i,
171                                                         str_out_arr[i], NULL);
172                 if (item_data) {
173                         if (i==0) {
174                                 item_data->group_style = SETTING_GROUP_STYLE_TOP;
175                         }else if (i==(sizeof(str_in_arr)/sizeof(str_in_arr[0])-1)) {
176                                 item_data->group_style = SETTING_GROUP_STYLE_BOTTOM;
177                         }else {
178                                 item_data->group_style = SETTING_GROUP_STYLE_CENTER;
179                         }
180                         item_data->userdata = ad;
181                 } else {
182                         SETTING_TRACE_ERROR("item_data is NULL");
183                 }
184         }
185
186         // set toggle
187         char* curmode = vconf_get_str(VCONFKEY_SETAPPL_SCREENMODE_SELNAME);
188         SETTING_TRACE(">>> CUR SCREEN MODE : %s ", curmode);
189         int j;
190         if(!curmode){
191                 /*set defaule screen mode if get the cur mode failed from VCONF*/
192                 elm_radio_value_set(radio, 0);
193         }else{
194                 for (j=0; j< sizeof(str_in_arr)/sizeof(str_in_arr[0]) ;j++) {
195                         if (0 == strcmp(str_in_arr[j], curmode)) {
196                                 elm_radio_value_set(radio, j);
197                                 break;
198                         }
199                 }
200                 FREE(curmode);
201         }
202
203         item = elm_genlist_item_append(genlist, &itc_bottom_seperator, NULL, NULL,
204                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
205         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
206
207         setting_view_display_screen_mode.is_create = 1;
208         return SETTING_RETURN_SUCCESS;
209 }
210
211 static int setting_display_screen_mode_destroy(void *cb)
212 {
213         SETTING_TRACE_BEGIN;
214         /* error check */
215         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
216         retv_if(!(setting_view_display_screen_mode.is_create), SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
217         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
218
219         evas_object_smart_callback_del(ad->genlist, "realized", __gl_realized_cb);
220
221         if (&setting_view_display_screen_mode == ad->view_to_load) {
222                 if (ad->ly_main != NULL){
223                         evas_object_del(ad->ly_main);
224                         ad->ly_main = NULL;
225                 }
226                 setting_view_display_screen_mode.is_create = 0;
227         }
228         else
229         {
230                 setting_view_display_screen_mode.is_create = 0;
231                 elm_naviframe_item_pop(ad->navi_bar);
232         }
233         return SETTING_RETURN_SUCCESS;
234 }
235
236 static int setting_display_screen_mode_update(void *cb)
237 {
238         SETTING_TRACE_BEGIN;
239         /* error check */
240         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
241
242         return SETTING_RETURN_SUCCESS;
243 }
244
245 static int setting_display_screen_mode_cleanup(void *cb)
246 {
247         SETTING_TRACE_BEGIN;
248         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
249
250         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
251
252         setting_display_screen_mode_destroy(ad);
253
254         return SETTING_RETURN_SUCCESS;
255 }
256
257 /* ***************************************************
258  *
259  *general func
260  *
261  ***************************************************/
262
263 static Eina_Bool
264 setting_display_screen_mode_click_softkey_back_cb(void *data, Evas_Object *obj, void *event_info)
265 {
266         SETTING_TRACE_BEGIN;
267         /* error check */
268         setting_retvm_if(data == NULL,EINA_FALSE,
269                         "[Setting > Display] Data parameter is NULL");
270
271         SettingDisplayUG *ad = (SettingDisplayUG *) data;
272         if (&setting_view_display_screen_mode == ad->view_to_load) {
273                 /* Send destroy request */
274                 ug_destroy_me(ad->ug);
275                 return EINA_FALSE;
276         }
277
278         setting_view_change(&setting_view_display_screen_mode, &setting_view_display_main, ad);
279         SETTING_TRACE_END;
280         return EINA_TRUE;
281 }
282
283
284 static void
285 setting_display_screen_mode_mouse_up_Gendial_list_radio_cb(void *data, Evas_Object *obj, void *event_info)
286 {
287     SETTING_TRACE_BEGIN;
288     /* error check */
289     setting_retm_if(data == NULL, "Data parameter is NULL");
290     setting_retm_if(event_info == NULL, "Invalid argument: event info is NULL");
291
292     Evas_Object *radio = (Evas_Object *) data;
293     Elm_Object_Item *item = (Elm_Object_Item *) event_info;
294     elm_genlist_item_selected_set(item, 0);
295
296     Setting_GenGroupItem_Data *list_item =
297         (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
298     //SettingDisplayUG *ad = (SettingDisplayUG *) list_item->userdata;
299
300     elm_radio_value_set(radio, list_item->chk_status);
301         vconf_set_str(VCONFKEY_SETAPPL_SCREENMODE_SELNAME, str_in_arr[list_item->chk_status]);
302         /* Set status to device manager */
303         display_set_image_enhance(ENHANCE_MODE, list_item->chk_status);
304         //SETTING_TRACE(">>> AFTER VCONF SET : %s ", str_in_arr[list_item->chk_status]);
305 }