4b518dd105823b378a3c71d1a1933d8daa999ebf
[apps/home/settings.git] / setting-phone / src / setting-phone-display-language.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-phone-display-language.h>
18
19
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);
23
24
25 setting_view setting_view_phone_display_language = {
26         .create = setting_phone_display_language_create,
27         .destroy = setting_phone_display_language_destroy,
28         .update = NULL,
29         .cleanup = setting_phone_display_language_cleanup,
30 };
31
32 /*
33  * exit and save
34  */
35 static void setting_phone_display_language_caller_exist_right_cb(void *data,
36                                                        Evas_Object *obj,
37                                                        void *event_info)
38 {
39         SETTING_TRACE_BEGIN;
40         setting_retm_if(data == NULL, "Data parameter is NULL");
41
42         SettingPhoneUG *ad = (SettingPhoneUG *) data;
43 #if 0
44         int ret, err;
45
46         int cur_chk_lang = (int)elm_radio_value_get(ad->chk_lang);
47
48         setting_phone_lang_change_lang_value(cur_chk_lang);
49
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);
53
54         if (0 == cur_chk_lang) {
55                 (void)vconf_set_str(VCONFKEY_LANGSET, ad->sim_lang);
56         }
57
58         /* Just filter out Setting App, other Apps stil need to be terminated
59        until they implement updating language or region automatically */
60
61         const char *pa_lang = vconf_get_str(VCONFKEY_LANGSET);
62         if (pa_lang) {
63                 char *q = strchr(pa_lang, '.');
64                 if (q) {
65                         *q = '\0';
66                 }
67                 SETTING_TRACE("pa_lang:%s", pa_lang);
68                 int err = -1;
69                 uloc_setDefault(pa_lang, &err);
70                 free((void *)pa_lang);
71                 pa_lang = NULL;
72         } else {
73                 SETTING_TRACE_ERROR("get vconf failed");
74         }
75 #endif
76
77         /*  Create Bundle and send message */
78         service_h svc;
79         if(service_create(&svc))
80                 return;
81
82         service_add_extra_data(svc, "result", "rbutton_click");
83         ug_send_result(ad->ug, svc);
84
85         service_destroy(svc);
86
87         ug_destroy_me(ad->ug);
88 }
89
90
91 /* ***************************************************
92  *
93  *basic func
94  *
95  ***************************************************/
96
97 static int setting_phone_display_language_create(void *cb)
98 {
99         SETTING_TRACE_BEGIN;
100         /* error check */
101         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
102
103         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
104         char *title = _("IDS_ST_HEADER_DISPLAY_LANGUAGE");
105
106         Evas_Object *scroller = NULL;
107         setting_call_back_func gl_sel_cb = NULL;
108
109         if (&setting_view_phone_display_language == ad->view_to_load) {
110                 char *caller = NULL;
111
112                 service_h service = ad->bundle_data;
113
114                 service_get_extra_data(service, "caller", &caller);
115
116                 if(caller)
117                 {
118                         ad->ly_language = setting_create_layout_navi_bar_genlist(ad->win_main_layout,
119                                         ad->win_get,
120                                         title,
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;
125                 }
126                 else
127                 {
128                         SETTING_TRACE_ERROR("[ERROR] caller is empty");
129                         return SETTING_RETURN_FAIL;
130                 }
131         } else {
132                 /* add basic layout */
133                 setting_push_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get,
134                                              title, _("IDS_COM_BODY_BACK"),
135                                              NULL,
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;
139         }
140
141         ad->gl_lang = scroller;
142
143         Elm_Object_Item *item = NULL;
144         item =
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);
148
149         /* scroller is a genlist */
150         ad->chk_lang = elm_radio_add(scroller);
151         elm_radio_state_value_set(ad->chk_lang, -1);
152
153
154
155         // [UI] Automatic
156         Setting_GenGroupItem_Data *item_data = NULL;
157         item_data =
158             setting_create_Gendial_field_def(scroller,
159                                                 &(ad->itc_1text),
160                                                 gl_sel_cb,
161                                                 ad->chk_lang,
162                                                 SWALLOW_Type_INVALID, NULL, NULL,
163                                                 0,
164                                                 "IDS_COM_BODY_AUTOMATIC", NULL, NULL);
165         if (item_data) {
166                 item_data->userdata = ad;
167         } else {
168                 SETTING_TRACE_ERROR("item_data is NULL");
169         }
170
171         // create loop operation here
172     Eina_List* elist = NULL;
173         setting_lang_entry* pnode = NULL;
174     int idx = SETTING_LANG_KOREA;               // 2
175
176         // load language table from XML file
177     Eina_List* langlist = setting_get_language_list();
178
179     EINA_LIST_FOREACH( langlist, elist, pnode)
180     {
181                 item_data =
182                         setting_create_Gendial_field_def(scroller,
183                                                         &(ad->itc_1text),
184                                                         gl_sel_cb,
185                                                         ad->chk_lang,
186                                                         SWALLOW_Type_INVALID, NULL, NULL,
187                                                         //idx,                  // <<< WARNING
188                                                         pnode->number,
189                                                         pnode->title, NULL, NULL);
190                 if (item_data) {
191                         item_data->userdata = ad;
192                 } else {
193                         SETTING_TRACE_ERROR("item_data is NULL");
194                 }
195         idx++;
196     }
197
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);
201
202         // set radio button to the selected state.
203         int index = -1;
204         int ret, err;
205         ret = setting_get_int_slp_key(INT_SLP_SETTING_LANG, &index, &err);
206         elm_radio_value_set(ad->chk_lang, index);
207
208         ad->prev_lang = (int)elm_radio_value_get(ad->chk_lang);
209         setting_view_phone_display_language.is_create = 1;
210
211         return SETTING_RETURN_SUCCESS;
212 }
213
214 static int setting_phone_display_language_destroy(void *cb)
215 {
216         SETTING_TRACE_BEGIN;
217         /* error check */
218         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
219         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
220
221         /*  FIXED : destroy only if it was created. */
222         if (setting_view_phone_display_language.is_create) {
223                 if (ad->popup) {
224                         evas_object_del(ad->popup);
225                         ad->popup = NULL;
226                 }
227
228                 if (ad->pop_progress) {
229                         evas_object_del(ad->pop_progress);
230                         ad->pop_progress = NULL;
231                 }
232                 elm_naviframe_item_pop(ad->navi_bar);
233                 setting_view_phone_display_language.is_create = 0;
234
235                 setting_get_language_list_destroy();
236         }
237
238         return SETTING_RETURN_SUCCESS;
239 }
240
241 static int setting_phone_display_language_cleanup(void *cb)
242 {
243         SETTING_TRACE_BEGIN;
244         /* error check */
245         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
246         setting_phone_display_language_destroy(cb);
247
248         return SETTING_RETURN_SUCCESS;
249 }
250
251 static void
252 setting_phone_display_language_click_softkey_cancel_cb(void *data,
253                                                        Evas_Object *obj,
254                                                        void *event_info)
255 {
256         SETTING_TRACE_BEGIN;
257         /* error check */
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);
262 }
263
264 static void
265 setting_phone_display_language_mouse_up_Gendial_list_radio_cb(void *data,
266                                                               Evas_Object *obj,
267                                                               void *event_info)
268 {
269         SETTING_TRACE_BEGIN;
270         /* error check */
271         setting_retm_if(data == NULL, "Data parameter is NULL");
272         setting_retm_if(event_info == NULL,
273                         "Invalid argument: event info is NULL");
274
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;
281
282         if (ad->popup) {
283                 return;
284         }
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 ");
292         //      return;
293         //}
294
295         elm_radio_value_set(radio, list_item->chk_status);
296         setting_phone_display_language_close_popup_ex(ad);
297 }
298
299 static void setting_phone_display_language_close_popup_ex(void *data)
300 {
301         SETTING_TRACE_BEGIN;
302         setting_retm_if(data == NULL, "Data parameter is NULL");
303         SettingPhoneUG *ad = (SettingPhoneUG *) data;
304
305         ad->prev_lang = elm_radio_value_get(ad->chk_lang);
306         SETTING_TRACE("cur_chk_lang = %d", ad->prev_lang);
307
308         // 0. change VCONFKEY_LANGSET
309         setting_phone_lang_change_lang_value(ad->prev_lang);
310
311         /*  if set automatic */
312         if (0 == ad->prev_lang) {
313                 vconf_set_str(VCONFKEY_LANGSET, ad->sim_lang);
314         }
315
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, '.');
320                 if (q)
321                         *q = '\0';
322         }
323         SETTING_TRACE("pa_lang:%s", pa_lang);
324         int err = -1;
325         // 3. SET DEFAULT
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);
330         } else {
331                 SETTING_TRACE("SUCCESS : uloc_setDefault error code : %d", err);
332         }
333         FREE(pa_lang);
334
335         char *caller = NULL;
336         service_h service = ad->bundle_data;
337
338         service_get_extra_data(service, "caller", &caller);
339
340         if(caller) {
341                 /*  Create Bundle and send message */
342                 service_h svc;
343                 if(service_create(&svc))
344                         return;
345
346                 service_add_extra_data(svc, "result", "rbutton_click");
347                 ug_send_result(ad->ug, svc);
348
349                 service_destroy(svc);
350
351                 ug_destroy_me(ad->ug);
352
353         } else {
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;
357         }
358 }