Tizen 2.0 Release
[apps/home/settings.git] / setting-display / src / setting-display-screen-mode.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include <setting-display-screen-mode.h>
18 #include <Ecore_X.h>
19
20 static int setting_display_screen_mode_create(void *cb);
21 static int setting_display_screen_mode_destroy(void *cb);
22 static int setting_display_screen_mode_update(void *cb);
23 static int setting_display_screen_mode_cleanup(void *cb);
24
25 static char* str_in_arr[] = {"Dynamic", "Standard", "Natural", "Movie"};
26 static char* str_out_arr[] = {Keystr_Dynamic, Keystr_Standard, Keystr_Natural, Keystr_Movie};
27
28 static void  setting_display_screen_mode_mouse_up_Gendial_list_radio_cb(void *data, Evas_Object *obj, void *event_info);
29
30 setting_view setting_view_display_screen_mode = {
31         .create = setting_display_screen_mode_create,
32         .destroy = setting_display_screen_mode_destroy,
33         .update = setting_display_screen_mode_update,
34         .cleanup = setting_display_screen_mode_cleanup,
35 };
36
37
38 static Evas_Object *__gl_content_get(void *data, Evas_Object *obj, const char *part)
39 {
40         if (!strcmp(part, "elm.icon")) {
41                 #if 0
42                 Evas_Object *sub_layout = elm_layout_add(obj);
43                 elm_layout_file_set(sub_layout, SETTING_THEME_EDJ_NAME, "screen_mode");
44                 evas_object_size_hint_weight_set(sub_layout, EVAS_HINT_EXPAND, 0.0);
45                 evas_object_show(sub_layout);
46
47                 Evas_Object *image = elm_image_add(obj);
48                 elm_image_file_set(image, IMG_SCREEN_MODE, NULL);
49                 elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
50                 evas_object_show(image);
51
52                 int w = 0;
53                 int h = 0;
54                 elm_image_object_size_get(image, &w, &h);
55                 setting_resize_object(image, w * WIDGET_SCALE_FACTOR, h * WIDGET_SCALE_FACTOR);
56
57                 elm_object_part_content_set(sub_layout, "content", image);
58                 return sub_layout;
59                 #endif
60                 Evas_Object *image;
61                 image = elm_image_add(obj);
62                 elm_image_file_set(image, IMG_SCREEN_MODE, NULL);
63
64                 int w = 668; /* left padding and right padding is 26, so the width = 720 - 26 -26 */
65                 int h = 0;
66                 elm_image_object_size_get(image, NULL, &h);
67                 evas_object_size_hint_min_set(image, w * WIDGET_SCALE_FACTOR, h * WIDGET_SCALE_FACTOR);
68                 evas_object_size_hint_max_set(image, w * WIDGET_SCALE_FACTOR, h * WIDGET_SCALE_FACTOR);
69                 evas_object_resize(image, w * WIDGET_SCALE_FACTOR, h * WIDGET_SCALE_FACTOR);
70
71                 return image;
72         }
73
74         return NULL;
75 }
76
77 static void __gl_item_del(void *data, Evas_Object *obj)
78 {
79         setting_retm_if(data == NULL, "Data parameter is NULL");
80         Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *) data;
81         if (item_data) {
82                 G_FREE(item_data->keyStr);
83                 G_FREE(item_data->sub_desc);
84                 FREE(item_data);
85         }
86 }
87
88 /* ***************************************************
89  *
90  *basic func
91  *
92  ***************************************************/
93 static int setting_display_screen_mode_create(void *cb)
94 {
95         SETTING_TRACE_BEGIN;
96         /* error check */
97         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
98
99         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
100
101         setting_call_back_func gl_sel_cb = NULL;
102         Evas_Object *genlist = NULL;
103         Setting_GenGroupItem_Data *item_data = NULL;
104
105         genlist = elm_genlist_add(ad->navi_bar);
106         retvm_if(genlist == NULL, SETTING_RETURN_FAIL, "scroller == NULL");
107         elm_object_style_set(genlist, "dialogue");
108         elm_genlist_clear(genlist);     /* first to clear list */
109
110         setting_push_layout_navi_bar(_(Keystr_ScreenMode), _("IDS_COM_BODY_BACK"),
111                                    NULL, NULL,
112                                    setting_display_screen_mode_click_softkey_back_cb,
113                                    NULL, NULL, ad, genlist, ad->navi_bar, NULL);
114
115         Elm_Object_Item *item = elm_genlist_item_append(genlist,
116                                                         &(itc_sep_line),
117                                                         NULL, NULL,
118                                                         ELM_GENLIST_ITEM_NONE,
119                                                         NULL, NULL);
120         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
121
122         ad->itc_screen_mode.item_style = "1icon/with_no_line";
123         ad->itc_screen_mode.func.text_get = NULL;
124         ad->itc_screen_mode.func.content_get = __gl_content_get;
125         ad->itc_screen_mode.func.state_get = NULL;
126         ad->itc_screen_mode.func.del = __gl_item_del;
127
128         Setting_GenGroupItem_Data *screen_mode = (Setting_GenGroupItem_Data *) calloc(1, sizeof(Setting_GenGroupItem_Data));
129         setting_retvm_if(!screen_mode, SETTING_RETURN_FAIL, "calloc failed");
130
131         if (screen_mode) {
132                 screen_mode->userdata = ad;
133                 screen_mode->item = elm_genlist_item_append(genlist, &(ad->itc_screen_mode), screen_mode, NULL,
134                                             ELM_GENLIST_ITEM_NONE, NULL, NULL);
135                 elm_genlist_item_select_mode_set(screen_mode->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
136         } else {
137                 SETTING_TRACE_ERROR("screen_mode is NULL");
138                 return SETTING_RETURN_FAIL;
139         }
140
141         gl_sel_cb = setting_display_screen_mode_mouse_up_Gendial_list_radio_cb;
142
143         Evas_Object *radio = elm_radio_add(genlist);
144         elm_radio_state_value_set(radio, -1);
145
146         char* curmode = vconf_get_str(VCONFKEY_SETAPPL_SCREENMODE_SELNAME);
147         SETTING_TRACE(">>> CUR SCREEN MODE : %s ", curmode);
148
149         int i = 0;
150
151         for (i=0; i< sizeof(str_in_arr)/sizeof(str_in_arr[0]) ;i++)
152         {
153                 item_data = setting_create_Gendial_field_1radio(genlist,
154                                                         &(itc_1text_1icon_2),
155                                                         gl_sel_cb,
156                                                         radio,  /* sel data */
157                                                         SWALLOW_Type_1RADIO,
158                                                         radio, i,
159                                                         str_out_arr[i], NULL);
160                 if (item_data) {
161                         item_data->userdata = ad;
162                 } else {
163                         SETTING_TRACE_ERROR("item_data is NULL");
164                 }
165         }
166
167         // set toggle
168         int j;
169         for (j=0; j< sizeof(str_in_arr)/sizeof(str_in_arr[0]) ;j++) {
170                 if (0 == strcmp(str_in_arr[j], curmode)) {
171                 elm_radio_value_set(radio, j);
172                         break;
173                 }
174         }
175
176         item = elm_genlist_item_append(genlist, &itc_bottom_seperator, NULL, NULL,
177                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
178         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
179
180         setting_view_display_screen_mode.is_create = 1;
181         return SETTING_RETURN_SUCCESS;
182 }
183
184 static int setting_display_screen_mode_destroy(void *cb)
185 {
186         SETTING_TRACE_BEGIN;
187         /* error check */
188         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
189
190         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
191
192         elm_naviframe_item_pop(ad->navi_bar);
193
194         setting_view_display_screen_mode.is_create = 0;
195
196         return SETTING_RETURN_SUCCESS;
197 }
198
199 static int setting_display_screen_mode_update(void *cb)
200 {
201         SETTING_TRACE_BEGIN;
202         /* error check */
203         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
204
205         return SETTING_RETURN_SUCCESS;
206 }
207
208 static int setting_display_screen_mode_cleanup(void *cb)
209 {
210         SETTING_TRACE_BEGIN;
211         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
212
213         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
214
215         setting_display_screen_mode_destroy(ad);
216
217         return SETTING_RETURN_SUCCESS;
218 }
219
220 /* ***************************************************
221  *
222  *general func
223  *
224  ***************************************************/
225
226 static void
227 setting_display_screen_mode_click_softkey_back_cb(void *data, Evas_Object *obj, void *event_info)
228 {
229         SETTING_TRACE_BEGIN;
230         /* error check */
231         setting_retm_if(data == NULL,
232                         "[Setting > Display] Data parameter is NULL");
233
234         SettingDisplayUG *ad = (SettingDisplayUG *) data;
235
236         setting_view_change(&setting_view_display_screen_mode, &setting_view_display_main, ad);
237         SETTING_TRACE_END;
238 }
239
240
241 static void
242 setting_display_screen_mode_mouse_up_Gendial_list_radio_cb(void *data, Evas_Object *obj, void *event_info)
243 {
244     SETTING_TRACE_BEGIN;
245     /* error check */
246     setting_retm_if(data == NULL, "Data parameter is NULL");
247     setting_retm_if(event_info == NULL,
248             "Invalid argument: event info is NULL");
249
250     Evas_Object *radio = (Evas_Object *) data;
251     Elm_Object_Item *item = (Elm_Object_Item *) event_info;
252     elm_genlist_item_selected_set(item, 0); 
253
254     Setting_GenGroupItem_Data *list_item =
255         (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
256     //SettingDisplayUG *ad = (SettingDisplayUG *) list_item->userdata;
257
258     elm_radio_value_set(radio, list_item->chk_status);
259         vconf_set_str(VCONFKEY_SETAPPL_SCREENMODE_SELNAME, str_in_arr[list_item->chk_status]);
260         /* Set status to device manager */
261         device_set_image_enhance_mode(list_item->chk_status);
262         SETTING_TRACE(">>> AFTER VCONF SET : %s ", str_in_arr[list_item->chk_status]);
263 }