3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 * http://floralicense.org/license/
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.
17 #include <setting-phone-display-language.h>
20 static int setting_phone_display_language_create(void *cb);
21 static int setting_phone_display_language_destroy(void *cb);
22 static int setting_phone_display_language_cleanup(void *cb);
25 setting_view setting_view_phone_display_language = {
26 .create = setting_phone_display_language_create,
27 .destroy = setting_phone_display_language_destroy,
29 .cleanup = setting_phone_display_language_cleanup,
35 static void setting_phone_display_language_caller_exist_right_cb(void *data,
40 setting_retm_if(data == NULL, "Data parameter is NULL");
42 SettingPhoneUG *ad = (SettingPhoneUG *) data;
46 int cur_chk_lang = (int)elm_radio_value_get(ad->chk_lang);
48 setting_phone_lang_change_lang_value(cur_chk_lang);
50 //ret = setting_get_int_slp_key(INT_SLP_SETTING_LANG, &chr_chk_lang, &err);
51 SETTING_TRACE("---> cur_chk_lang : %d", cur_chk_lang);
52 ret = setting_set_int_slp_key(INT_SLP_SETTING_LANG, cur_chk_lang, &err);
54 if (0 == cur_chk_lang) {
55 (void)vconf_set_str(VCONFKEY_LANGSET, ad->sim_lang);
58 /* Just filter out Setting App, other Apps stil need to be terminated
59 until they implement updating language or region automatically */
61 const char *pa_lang = vconf_get_str(VCONFKEY_LANGSET);
63 char *q = strchr(pa_lang, '.');
67 SETTING_TRACE("pa_lang:%s", pa_lang);
69 uloc_setDefault(pa_lang, &err);
70 free((void *)pa_lang);
73 SETTING_TRACE_ERROR("get vconf failed");
77 /* Create Bundle and send message */
79 if(service_create(&svc))
82 service_add_extra_data(svc, "result", "rbutton_click");
83 ug_send_result(ad->ug, svc);
87 ug_destroy_me(ad->ug);
91 /* ***************************************************
95 ***************************************************/
97 static int setting_phone_display_language_create(void *cb)
101 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
103 SettingPhoneUG *ad = (SettingPhoneUG *) cb;
104 char *title = _("IDS_ST_HEADER_DISPLAY_LANGUAGE");
106 Evas_Object *scroller = NULL;
107 setting_call_back_func gl_sel_cb = NULL;
109 if (&setting_view_phone_display_language == ad->view_to_load) {
112 service_h service = ad->bundle_data;
114 service_get_extra_data(service, "caller", &caller);
118 ad->ly_language = setting_create_layout_navi_bar_genlist(ad->win_main_layout,
121 _("IDS_COM_BODY_BACK"), NULL,
122 setting_phone_display_language_caller_exist_right_cb, NULL,
123 ad, &scroller, &ad->navi_bar);
124 gl_sel_cb = setting_phone_display_language_mouse_up_Gendial_list_radio_cb;
128 SETTING_TRACE_ERROR("[ERROR] caller is empty");
129 return SETTING_RETURN_FAIL;
132 /* add basic layout */
133 setting_push_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get,
134 title, _("IDS_COM_BODY_BACK"),
136 setting_phone_display_language_click_softkey_cancel_cb,
137 NULL, ad, &scroller, ad->navi_bar);
138 gl_sel_cb = setting_phone_display_language_mouse_up_Gendial_list_radio_cb;
141 ad->gl_lang = scroller;
143 Elm_Object_Item *item = NULL;
145 elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
146 ELM_GENLIST_ITEM_NONE, NULL, NULL);
147 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
149 /* scroller is a genlist */
150 ad->chk_lang = elm_radio_add(scroller);
151 elm_radio_state_value_set(ad->chk_lang, -1);
156 Setting_GenGroupItem_Data *item_data = NULL;
158 setting_create_Gendial_field_def(scroller,
162 SWALLOW_Type_INVALID, NULL, NULL,
164 "IDS_COM_BODY_AUTOMATIC", NULL, NULL);
166 item_data->userdata = ad;
168 SETTING_TRACE_ERROR("item_data is NULL");
171 // create loop operation here
172 Eina_List* elist = NULL;
173 setting_lang_entry* pnode = NULL;
174 int idx = SETTING_LANG_KOREA; // 2
176 // load language table from XML file
177 Eina_List* langlist = setting_get_language_list();
179 EINA_LIST_FOREACH( langlist, elist, pnode)
182 setting_create_Gendial_field_def(scroller,
186 SWALLOW_Type_INVALID, NULL, NULL,
187 //idx, // <<< WARNING
189 pnode->title, NULL, NULL);
191 item_data->userdata = ad;
193 SETTING_TRACE_ERROR("item_data is NULL");
198 item = elm_genlist_item_append(scroller, &itc_bottom_seperator, NULL, NULL,
199 ELM_GENLIST_ITEM_NONE, NULL, NULL);
200 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
202 // set radio button to the selected state.
205 ret = setting_get_int_slp_key(INT_SLP_SETTING_LANG, &index, &err);
206 elm_radio_value_set(ad->chk_lang, index);
208 ad->prev_lang = (int)elm_radio_value_get(ad->chk_lang);
209 setting_view_phone_display_language.is_create = 1;
211 return SETTING_RETURN_SUCCESS;
214 static int setting_phone_display_language_destroy(void *cb)
218 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
219 SettingPhoneUG *ad = (SettingPhoneUG *) cb;
221 /* FIXED : destroy only if it was created. */
222 if (setting_view_phone_display_language.is_create) {
224 evas_object_del(ad->popup);
228 if (ad->pop_progress) {
229 evas_object_del(ad->pop_progress);
230 ad->pop_progress = NULL;
232 elm_naviframe_item_pop(ad->navi_bar);
233 setting_view_phone_display_language.is_create = 0;
235 setting_get_language_list_destroy();
238 return SETTING_RETURN_SUCCESS;
241 static int setting_phone_display_language_cleanup(void *cb)
245 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
246 setting_phone_display_language_destroy(cb);
248 return SETTING_RETURN_SUCCESS;
252 setting_phone_display_language_click_softkey_cancel_cb(void *data,
258 retm_if(data == NULL, "Data parameter is NULL");
259 SettingPhoneUG *ad = (SettingPhoneUG *) data;
260 setting_view_change(&setting_view_phone_display_language,
261 &setting_view_phone_language_region, ad);
265 setting_phone_display_language_mouse_up_Gendial_list_radio_cb(void *data,
271 setting_retm_if(data == NULL, "Data parameter is NULL");
272 setting_retm_if(event_info == NULL,
273 "Invalid argument: event info is NULL");
275 Evas_Object *radio = (Evas_Object *) data;
276 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
277 elm_genlist_item_selected_set(item, 0);
278 Setting_GenGroupItem_Data *list_item =
279 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
280 SettingPhoneUG *ad = (SettingPhoneUG *) list_item->userdata;
285 //SETTING_TRACE("---------------------------------------------");
286 //SETTING_TRACE("ad->prev_lang = %d ", ad->prev_lang);
287 //SETTING_TRACE("chk_status = %d ", list_item->chk_status);
288 //SETTING_TRACE("---------------------------------------------");
289 /* if not change, return */
290 //if (ad->prev_lang == list_item->chk_status) {
291 // SETTING_TRACE("NOT CHANGED ");
295 elm_radio_value_set(radio, list_item->chk_status);
296 setting_phone_display_language_close_popup_ex(ad);
299 static void setting_phone_display_language_close_popup_ex(void *data)
302 setting_retm_if(data == NULL, "Data parameter is NULL");
303 SettingPhoneUG *ad = (SettingPhoneUG *) data;
305 ad->prev_lang = elm_radio_value_get(ad->chk_lang);
306 SETTING_TRACE("cur_chk_lang = %d", ad->prev_lang);
308 // 0. change VCONFKEY_LANGSET
309 setting_phone_lang_change_lang_value(ad->prev_lang);
311 /* if set automatic */
312 if (0 == ad->prev_lang) {
313 vconf_set_str(VCONFKEY_LANGSET, ad->sim_lang);
316 // 2. GET SELECTED LANG
317 const char *pa_lang = vconf_get_str(VCONFKEY_LANGSET);
318 if (pa_lang) { /* remove the */
319 char *q = strchr(pa_lang, '.');
323 SETTING_TRACE("pa_lang:%s", pa_lang);
326 // default UI language
327 uloc_setDefault(pa_lang, &err);
328 if (U_FAILURE(err)) {
329 SETTING_TRACE("FAILED : uloc_setDefault error code : %d", err);
331 SETTING_TRACE("SUCCESS : uloc_setDefault error code : %d", err);
336 service_h service = ad->bundle_data;
338 service_get_extra_data(service, "caller", &caller);
341 /* Create Bundle and send message */
343 if(service_create(&svc))
346 service_add_extra_data(svc, "result", "rbutton_click");
347 ug_send_result(ad->ug, svc);
349 service_destroy(svc);
351 ug_destroy_me(ad->ug);
354 /* after lang-change, go back to the previous page*/
355 elm_naviframe_item_pop(ad->navi_bar);
356 setting_view_phone_display_language.is_create = 0;