Merge "fixed app name : setting -> settings"
[apps/core/preloaded/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 static char* str_in_arr[] = {"Dynamic", "Standard", "Natural", "Movie"};
30 static char* str_out_arr[] = {Keystr_Dynamic, Keystr_Standard, Keystr_Natural, Keystr_Movie};
31
32 static void  setting_display_screen_mode_mouse_up_Gendial_list_radio_cb(void *data, Evas_Object *obj, void *event_info);
33
34 setting_view setting_view_display_screen_mode = {
35         .create = setting_display_screen_mode_create,
36         .destroy = setting_display_screen_mode_destroy,
37         .update = setting_display_screen_mode_update,
38         .cleanup = setting_display_screen_mode_cleanup,
39 };
40
41
42 static Evas_Object *__gl_content_get(void *data, Evas_Object *obj, const char *part)
43 {
44         if (!strcmp(part, "elm.icon")) {
45                 Evas_Object *sub_layout = elm_layout_add(obj);
46                 elm_layout_file_set(sub_layout, SETTING_THEME_EDJ_NAME, "screen_mode");
47                 evas_object_size_hint_weight_set(sub_layout, EVAS_HINT_EXPAND, 0.0);
48                 evas_object_show(sub_layout);
49
50                 Evas_Object *image = elm_image_add(obj);
51                 elm_image_file_set(image, IMG_SCREEN_MODE, NULL);
52                 elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
53                 evas_object_show(image);
54
55                 int w = 0;
56                 int h = 0;
57                 elm_image_object_size_get(image, &w, &h);
58                 setting_resize_object(image, w * WIDGET_SCALE_FACTOR, h * WIDGET_SCALE_FACTOR);
59
60                 elm_object_part_content_set(sub_layout, "content", image);
61                 return sub_layout;
62         }
63
64         return NULL;
65 }
66
67 static void __gl_item_del(void *data, Evas_Object *obj)
68 {
69         setting_retm_if(data == NULL, "Data parameter is NULL");
70         Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *) data;
71         if (item_data) {
72                 G_FREE(item_data->keyStr);
73                 G_FREE(item_data->sub_desc);
74                 FREE(item_data);
75         }
76 }
77
78 /* ***************************************************
79  *
80  *basic func
81  *
82  ***************************************************/
83 static int setting_display_screen_mode_create(void *cb)
84 {
85         SETTING_TRACE_BEGIN;
86         /* error check */
87         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
88
89         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
90
91         setting_call_back_func gl_sel_cb = NULL;
92         Evas_Object *genlist = NULL;
93         Setting_GenGroupItem_Data *item_data = NULL;
94
95         genlist = elm_genlist_add(ad->navi_bar);
96         retvm_if(genlist == NULL, SETTING_RETURN_FAIL, "scroller == NULL");
97         elm_object_style_set(genlist, "dialogue");
98         elm_genlist_clear(genlist);     /* first to clear list */
99
100         setting_push_layout_navi_bar(_(Keystr_ScreenMode), _("IDS_COM_BODY_BACK"),
101                                    NULL, NULL,
102                                    setting_display_screen_mode_click_softkey_back_cb,
103                                    NULL, NULL, ad, genlist, ad->navi_bar, NULL);
104
105         Elm_Object_Item *item = elm_genlist_item_append(genlist,
106                                                         &(itc_sep_line),
107                                                         NULL, NULL,
108                                                         ELM_GENLIST_ITEM_NONE,
109                                                         NULL, NULL);
110         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
111
112         ad->itc_screen_mode.item_style = "1icon";
113         ad->itc_screen_mode.func.text_get = NULL;
114         ad->itc_screen_mode.func.content_get = __gl_content_get;
115         ad->itc_screen_mode.func.state_get = NULL;
116         ad->itc_screen_mode.func.del = __gl_item_del;
117
118         Setting_GenGroupItem_Data *screen_mode = (Setting_GenGroupItem_Data *) calloc(1, sizeof(Setting_GenGroupItem_Data));
119         setting_retvm_if(!screen_mode, SETTING_RETURN_FAIL, "calloc failed");
120
121         if (screen_mode) {
122                 screen_mode->userdata = ad;
123                 screen_mode->item = elm_genlist_item_append(genlist, &(ad->itc_screen_mode), screen_mode, NULL,
124                                             ELM_GENLIST_ITEM_NONE, NULL, NULL);
125                 elm_genlist_item_select_mode_set(screen_mode->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
126         } else {
127                 SETTING_TRACE_ERROR("screen_mode is NULL");
128                 return SETTING_RETURN_FAIL;
129         }
130
131         gl_sel_cb = setting_display_screen_mode_mouse_up_Gendial_list_radio_cb;
132
133         Evas_Object *radio = elm_radio_add(genlist);
134         elm_radio_state_value_set(radio, -1);
135
136         char* curmode = vconf_get_str(VCONFKEY_SETAPPL_SCREENMODE_SELNAME);
137         SETTING_TRACE(">>> CUR SCREEN MODE : %s ", curmode);
138
139         int i = 0;
140
141         for (i=0; i< sizeof(str_in_arr)/sizeof(str_in_arr[0]) ;i++)
142         {
143                 item_data = setting_create_Gendial_field_1radio(genlist,
144                                                         &(itc_1text_1icon_2),
145                                                         gl_sel_cb,
146                                                         radio,  /* sel data */
147                                                         SWALLOW_Type_1RADIO,
148                                                         radio, i,
149                                                         str_out_arr[i], NULL);
150                 if (item_data) {
151                         item_data->userdata = ad;
152                 } else {
153                         SETTING_TRACE_ERROR("item_data is NULL");
154                 }
155         }
156
157         // set toggle
158         int j;
159         for (j=0; j< sizeof(str_in_arr)/sizeof(str_in_arr[0]) ;j++) {
160                 if (0 == strcmp(str_in_arr[j], curmode)) {
161                 elm_radio_value_set(radio, j);
162                         break;
163                 }
164         }
165
166         item = elm_genlist_item_append(genlist, &itc_bottom_seperator, NULL, NULL,
167                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
168         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
169
170         setting_view_display_screen_mode.is_create = 1;
171         return SETTING_RETURN_SUCCESS;
172 }
173
174 static int setting_display_screen_mode_destroy(void *cb)
175 {
176         SETTING_TRACE_BEGIN;
177         /* error check */
178         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
179
180         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
181
182         elm_naviframe_item_pop(ad->navi_bar);
183
184         setting_view_display_screen_mode.is_create = 0;
185
186         return SETTING_RETURN_SUCCESS;
187 }
188
189 static int setting_display_screen_mode_update(void *cb)
190 {
191         SETTING_TRACE_BEGIN;
192         /* error check */
193         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
194
195         return SETTING_RETURN_SUCCESS;
196 }
197
198 static int setting_display_screen_mode_cleanup(void *cb)
199 {
200         SETTING_TRACE_BEGIN;
201         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
202
203         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
204
205         setting_display_screen_mode_destroy(ad);
206
207         return SETTING_RETURN_SUCCESS;
208 }
209
210 /* ***************************************************
211  *
212  *general func
213  *
214  ***************************************************/
215
216 static void
217 setting_display_screen_mode_click_softkey_back_cb(void *data, Evas_Object *obj, void *event_info)
218 {
219         SETTING_TRACE_BEGIN;
220         /* error check */
221         setting_retm_if(data == NULL,
222                         "[Setting > Display] Data parameter is NULL");
223
224         SettingDisplayUG *ad = (SettingDisplayUG *) data;
225
226         setting_view_change(&setting_view_display_screen_mode, &setting_view_display_main, ad);
227         SETTING_TRACE_END;
228 }
229
230
231 static void
232 setting_display_screen_mode_mouse_up_Gendial_list_radio_cb(void *data, Evas_Object *obj, void *event_info)
233 {
234     SETTING_TRACE_BEGIN;
235     /* error check */
236     setting_retm_if(data == NULL, "Data parameter is NULL");
237     setting_retm_if(event_info == NULL,
238             "Invalid argument: event info is NULL");
239
240     Evas_Object *radio = (Evas_Object *) data;
241     Elm_Object_Item *item = (Elm_Object_Item *) event_info;
242     elm_genlist_item_selected_set(item, 0); 
243
244     Setting_GenGroupItem_Data *list_item =
245         (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
246     //SettingDisplayUG *ad = (SettingDisplayUG *) list_item->userdata;
247
248     elm_radio_value_set(radio, list_item->chk_status);
249         vconf_set_str(VCONFKEY_SETAPPL_SCREENMODE_SELNAME, str_in_arr[list_item->chk_status]);
250         /* Set status to device manager */
251         device_set_image_enhance_mode(list_item->chk_status);
252         SETTING_TRACE(">>> AFTER VCONF SET : %s ", str_in_arr[list_item->chk_status]);
253 }