4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <setting-font-main.h>
23 #include <fontconfig/fontconfig.h>
24 #include <unicode/uloc.h>
25 #include <libxml/xmlmemory.h>
26 #include <libxml/parser.h>
29 static int setting_font_main_create(void *cb);
30 static int setting_font_main_destroy(void *cb);
31 static int setting_font_main_update(void *cb);
32 static int setting_font_main_cleanup(void *cb);
34 static void __setting_font_main_click_softkey_back_cb(void *data, Evas_Object *obj,
37 setting_view setting_view_font_main = {
38 .create = setting_font_main_create,
39 .destroy = setting_font_main_destroy,
40 .update = setting_font_main_update,
41 .cleanup = setting_font_main_cleanup,
44 static char* __setting_font_main_get_font_size(int value)
46 const char* font_size_arr[] = {
47 _("IDS_ST_BODY_SMALL_M_TEXTSIZE"), // 0
48 _("IDS_ST_BODY_NORMAL_T_PROFILE"), // 1
49 _("IDS_ST_BODY_TEXTSTYLE_LARGE"), // 2
50 _("IDS_EMAIL_OPT_HUGE_M_TEXTSIZE"), // 3
51 _("IDS_EMAIL_POP_GIANT_M_TEXTSIZE"), // 4
55 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
56 return (char *)font_size_arr[0];
57 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
58 return (char *)font_size_arr[1];
59 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
60 return (char *)font_size_arr[2];
61 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
62 return (char *)font_size_arr[3];
63 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
64 return (char *)font_size_arr[4];
66 return (char *)font_size_arr[1];
70 static Eina_List *__setting_font_main_available_list_get()
73 FcObjectSet *os = NULL;
75 FcPattern *pat = NULL;
76 Eina_List *list = NULL;
77 FcConfig *font_config = NULL;
79 font_config = FcInitLoadConfigAndFonts();
81 setting_retvm_if(font_config == NULL, NULL, "Failed: FcInitLoadConfigAndFonts");
83 pat = FcPatternCreate();
85 os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *) 0);
88 fs = FcFontList(font_config, pat, os);
89 FcObjectSetDestroy(os);
94 FcPatternDestroy(pat);
100 SETTING_TRACE_DEBUG("fs->nfont = %d", fs->nfont);
102 for (j = 0; j < fs->nfont; j++) {
103 FcChar8 *family = NULL;
104 FcChar8 *file = NULL;
106 if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) {
107 //SETTING_TRACE_DEBUG("FC_FILE : %s\n", file);
108 int preload_path_len = safeStrLen(SETTING_FONT_PRELOAD_FONT_PATH);
109 int download_path_len = safeStrLen(SETTING_FONT_DOWNLOADED_FONT_PATH);
110 if (!safeStrNCmp((const char*)file, SETTING_FONT_PRELOAD_FONT_PATH, preload_path_len) ||
111 !safeStrNCmp((const char*)file, SETTING_FONT_DOWNLOADED_FONT_PATH, download_path_len)) {
112 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, 0, &family) != FcResultMatch) {
113 SETTING_TRACE_DEBUG("Family name is invalid");
117 //SETTING_TRACE_DEBUG("family = %s", (char *)family);
118 if (eina_list_data_find(list, family) == NULL) {
119 list = eina_list_append(list, family);
120 /* list = eina_list_append(list, family); */
121 // for TEST because there's 1 font on target.
126 FcFontSetDestroy(fs);
130 FcConfigDestroy(font_config);
135 void __setting_font_main_launch_ug_destroy_cb(ui_gadget_h ug, void *priv)
138 /* if(ug) ug_destroy(ug); */
139 /* restore the '<-' button on the navigate bar */
140 retm_if(priv == NULL, "priv is NULL");
141 SettingFontUG *ad = (SettingFontUG *) priv;
145 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navibar);
146 retm_if(navi_it == NULL, "navi_it is NULL");
147 Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
149 if (back_btn != NULL) {
150 elm_object_style_set(back_btn, NAVI_BACK_BUTTON_STYLE); /* take into effect */
153 // update font size item
156 int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &value, &err);
157 retm_if(ret != 0, "get vconf failed");
160 G_FREE(ad->font_size->sub_desc);
161 ad->font_size->sub_desc = g_strdup(__setting_font_main_get_font_size(value));
163 elm_object_item_data_set(ad->font_size->item, ad->font_size);
164 elm_genlist_item_update(ad->font_size->item);
168 void __setting_font_main_launch_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
171 retm_if(priv == NULL, "priv is NULL");
172 SettingFontUG *ad = (SettingFontUG *) priv;
173 Evas_Object *base = NULL;
174 base = (Evas_Object *) ug_get_layout(ug);
175 retm_if(base == NULL, "base is NULL");
178 case UG_MODE_FULLVIEW:
179 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
180 elm_win_resize_object_add(ad->win_get, base);
181 evas_object_show(base);
190 static void __setting_font_main_launch_ug(void *data)
194 retm_if(data == NULL, "Data parameter is NULL");
196 SettingFontUG *ad = (SettingFontUG *) data;
199 if (service_create(&svc)) {
203 service_add_extra_data(svc, "caller", "font_size");
205 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
207 SETTING_TRACE_ERROR("calloc failed");
208 service_destroy(svc);
211 cbs->layout_cb = __setting_font_main_launch_ug_layout_cb;
212 cbs->result_cb = NULL;
213 cbs->destroy_cb = __setting_font_main_launch_ug_destroy_cb;
214 cbs->priv = (void *)ad;
216 ui_gadget_h ug = ug_create(ad->ug, "setting-accessibility-efl", UG_MODE_FULLVIEW, svc, cbs);
217 if (NULL == ug) { /* error handling */
218 SETTING_TRACE_ERROR("NULL == ug");
222 service_destroy(svc);
226 static void __setting_font_main_genlist_sel_cb(void *data, Evas_Object * obj, void *event_info)
229 setting_retm_if(data == NULL, "Data parameter is NULL");
231 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
232 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
233 elm_genlist_item_selected_set(item, 0);
234 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item);
236 SettingFontUG *ad = (SettingFontUG *)data;
238 if (ad->font_size == list_item) {
239 __setting_font_main_launch_ug(ad);
243 static void __setting_font_main_genlist_item_create(void *data)
246 setting_retm_if(NULL == data, "data is NULL");
248 SettingFontUG *ad = (SettingFontUG *)data;
249 Elm_Object_Item *item = NULL;
250 item = elm_genlist_item_append(ad->genlist, &(ad->itc_seperator), NULL, NULL,
251 ELM_GENLIST_ITEM_NONE, NULL, NULL);
252 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
254 char *font_type_name = NULL;
255 font_type_name = cur_font_get();
257 ad->font_type = setting_create_Gendial_exp_parent_field(ad->genlist,
258 &(ad->itc_2text_3_parent),
260 SWALLOW_Type_INVALID,
261 SETTING_FONT_TYPE_STR,
264 ad->font_type->userdata = ad;
266 SETTING_TRACE_ERROR("ad->font_type is NULL");
268 G_FREE(ad->font_name);
269 ad->font_name = g_strdup(font_type_name);
270 G_FREE(font_type_name);
272 if (ad->viewmode == FONT_SEL_VIEW_APPCONTROL)
274 //--------------------------------------------------------------------
279 int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &value, &err);
281 SETTING_TRACE_ERROR("get vconf failed");
286 ad->font_size = setting_create_Gendial_field_def(ad->genlist, &(ad->itc_2text_2),
287 __setting_font_main_genlist_sel_cb,
288 ad, SWALLOW_Type_INVALID, NULL,
289 NULL, value, SETTING_FONT_SIZE_STR,
290 __setting_font_main_get_font_size(value), NULL);
292 ad->font_size->userdata = ad;
294 SETTING_TRACE_ERROR("ad->font_size is NULL");
297 setting_create_Gendial_field_def(ad->genlist, &(ad->itc_bg_1icon), NULL,
298 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
299 NULL, NULL, 0, SETTING_FONT_SIZE_DESC, NULL,
307 static void __setting_font_main_font_set(char *font_name)
309 retm_if(font_name == NULL, "Invalid argument: font_name is NULL");
310 xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
313 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
318 font_config_set(font_name);
321 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
322 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
323 ecore_x_window_prop_string_set(ecore_win, atom, "slp");
326 static void __setting_font_main_popup_cb(void *data, Evas_Object *obj, void *event_info)
329 setting_retm_if(data == NULL, "Data parameter is NULL");
330 SettingFontUG *ad = (SettingFontUG *) data;
332 switch (btn_type(obj)) {
333 case POPUP_RESPONSE_OK:
335 ad->font_type->sub_desc = (char *)g_strdup(_(ad->subitem->keyStr));
336 elm_object_item_data_set(ad->font_type->item, ad->font_type);
337 elm_genlist_item_update(ad->font_type->item);
339 ad->prev_font = ad->subitem->chk_status;
340 G_FREE(ad->font_name);
341 ad->font_name = (char *)g_strdup(_(ad->subitem->keyStr));
342 SETTING_TRACE("ad->subitem->keyStr = %s", ad->subitem->keyStr);
343 __setting_font_main_font_set(ad->subitem->keyStr);
344 ug_destroy_me(ad->ug);
347 case POPUP_RESPONSE_CANCEL:
349 elm_radio_value_set(ad->subitem->rgd, ad->prev_font);
360 evas_object_del(ad->popup);
365 static void __setting_font_main_popup(void *data)
368 setting_retm_if(data == NULL, "Data parameter is NULL");
369 SettingFontUG *ad = (SettingFontUG *) data;
371 char popup_desc[SETTING_STR_SLP_LEN + 1] = {0,};
372 snprintf(popup_desc, SETTING_STR_SLP_LEN, "%s %s?", _(SETTING_FONT_POPUP_DESC), ad->subitem->keyStr);
374 ad->popup = setting_create_popup_with_btn(ad, ad->win_get, NULL,
376 __setting_font_main_popup_cb, 0,
377 2, _("IDS_COM_SK_YES"),_("IDS_COM_SK_NO"));
382 * [UI][expandable list][event handler:selection][font change]
384 void __setting_font_main_sub_list_sel_cb(void *data, Evas_Object *obj, void *event_info)
388 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
389 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
390 elm_genlist_item_selected_set(subitem, 0);
391 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
392 ret_if(NULL == data_subItem);
394 SettingFontUG *ad = (SettingFontUG *) data;
396 /* if not change, return */
397 if (ad->prev_font == data_subItem->chk_status) {
398 SETTING_TRACE("NOT CHANGED ");
402 ad->subitem = data_subItem;
403 elm_radio_value_set(ad->subitem->rgd, ad->subitem->chk_status);
405 __setting_font_main_popup(ad);
408 static void __setting_font_main_exp_cb(void *data, Evas_Object *obj, void *event_info)
410 ret_if(NULL == data || NULL == event_info);
412 SettingFontUG *ad = (SettingFontUG *) data;
413 Elm_Object_Item *parentItem = event_info; /* parent item */
414 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
415 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
417 Evas_Object *rgd = NULL;
418 if (data_parentItem == ad->font_type) {
419 rgd = elm_radio_add(scroller);
420 elm_radio_value_set(rgd, -1);
422 Eina_List *font_list = NULL;
424 FcChar8 *font_data = NULL;
425 font_list = __setting_font_main_available_list_get();
428 int matched_font = -1;
429 Setting_GenGroupItem_Data *item = NULL;
430 EINA_LIST_FOREACH(font_list, l, font_data)
432 item = setting_create_Gendial_exp_sub_field(scroller, &(ad->itc_1icon_1text_sub),
433 __setting_font_main_sub_list_sel_cb, ad,
434 parentItem, SWALLOW_Type_1RADIO, rgd,
435 i, (const char*)font_data,
440 if (!safeStrCmp(ad->font_name, (const char*)font_data)) {
448 /* update check status */
449 if (matched_font != -1) {
450 elm_radio_value_set(rgd, matched_font);
453 ad->prev_font = matched_font;
458 /* ***************************************************
462 ***************************************************/
463 static int setting_font_main_create(void *cb)
467 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
469 SettingFontUG *ad = (SettingFontUG *) cb;
471 retvm_if(ad->win_main_layout == NULL, SETTING_DRAW_ERR_FAIL_LOAD_EDJ,
472 "win_main_layout is NULL");
475 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
478 _("IDS_COM_BODY_BACK"),
480 __setting_font_main_click_softkey_back_cb,
482 ad, &ad->genlist, &ad->navibar);
484 setting_enable_expandable_genlist(ad->genlist, ad,
485 __setting_font_main_exp_cb, NULL);
487 __setting_font_main_genlist_item_create(ad);
489 setting_view_font_main.is_create = 1;
490 return SETTING_RETURN_SUCCESS;
493 static int setting_font_main_destroy(void *cb)
496 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
498 SettingFontUG *ad = (SettingFontUG *) cb;
501 evas_object_del(ad->popup);
505 if (ad->ly_main != NULL) {
506 evas_object_del(ad->ly_main);
507 setting_view_font_main.is_create = 0;
510 return SETTING_RETURN_SUCCESS;
513 static int setting_font_main_update(void *cb)
517 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
519 SettingFontUG *ad = (SettingFontUG *) cb;
521 if (ad->ly_main != NULL) {
522 evas_object_show(ad->ly_main);
524 setting_font_update_vconf_key(ad, SETTING_VCONF_INT_TYPE,
525 INT_SLP_SETTING_LCD_TIMEOUT_NORMAL);
528 return SETTING_RETURN_SUCCESS;
531 static int setting_font_main_cleanup(void *cb)
534 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
536 SettingFontUG *ad = (SettingFontUG *) cb;
538 if (ad->ly_main != NULL) {
539 evas_object_hide(ad->ly_main);
542 return SETTING_RETURN_SUCCESS;
545 /* ***************************************************
549 ***************************************************/
551 static void __setting_font_main_click_softkey_back_cb(void *data, Evas_Object *obj,
556 ret_if(data == NULL);
558 SettingFontUG *ad = (SettingFontUG *) data;
560 if (ad->viewmode == FONT_SEL_VIEW_APPCONTROL)
563 if (service_create(&svc))
566 service_add_extra_data(svc, "category", "FontType");
567 service_add_extra_data(svc, "FontType", ad->font_name);
569 SETTING_TRACE(" SERVICE_ADD_EXTRA : %s %s","category", "FontType");
570 SETTING_TRACE(" SERVICE_ADD_EXTRA : %s %s","FontType", ad->font_name);
573 ug_send_result(ad->ug, svc);
574 service_destroy(svc);
577 /* Send destroy request */
578 ug_destroy_me(ad->ug);