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>
28 #include <system_settings.h>
30 #define SETTING_FONT_MAX_LEN 10
32 static int setting_font_main_create(void *cb);
33 static int setting_font_main_destroy(void *cb);
34 static int setting_font_main_update(void *cb);
35 static int setting_font_main_cleanup(void *cb);
37 static void __setting_font_main_click_softkey_back_cb(void *data, Evas_Object *obj,
40 setting_view setting_view_font_main = {
41 .create = setting_font_main_create,
42 .destroy = setting_font_main_destroy,
43 .update = setting_font_main_update,
44 .cleanup = setting_font_main_cleanup,
47 static char* __setting_font_main_get_font_size(int value)
49 const char* font_size_arr[] = {
50 _("IDS_ST_BODY_SMALL_M_TEXTSIZE"), // 0
51 _("IDS_ST_BODY_NORMAL_T_PROFILE"), // 1
52 _("IDS_ST_BODY_TEXTSTYLE_LARGE"), // 2
53 _("IDS_EMAIL_OPT_HUGE_M_TEXTSIZE"), // 3
54 _("IDS_EMAIL_POP_GIANT_M_TEXTSIZE"), // 4
58 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
59 return (char *)font_size_arr[0];
60 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
61 return (char *)font_size_arr[1];
62 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
63 return (char *)font_size_arr[2];
64 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
65 return (char *)font_size_arr[3];
66 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
67 return (char *)font_size_arr[4];
69 return (char *)font_size_arr[1];
73 static Eina_List *__setting_font_main_available_list_get()
76 FcObjectSet *os = NULL;
78 FcPattern *pat = NULL;
79 Eina_List *list = NULL;
80 FcConfig *font_config = NULL;
82 font_config = FcInitLoadConfigAndFonts();
84 setting_retvm_if(font_config == NULL, NULL, "Failed: FcInitLoadConfigAndFonts");
86 pat = FcPatternCreate();
88 os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *) 0);
91 fs = FcFontList(font_config, pat, os);
92 FcObjectSetDestroy(os);
97 FcPatternDestroy(pat);
103 SETTING_TRACE_DEBUG("fs->nfont = %d", fs->nfont);
105 for (j = 0; j < fs->nfont; j++) {
106 FcChar8 *family = NULL;
107 FcChar8 *file = NULL;
109 if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) {
110 //SETTING_TRACE_DEBUG("FC_FILE : %s\n", file);
111 int preload_path_len = safeStrLen(SETTING_FONT_PRELOAD_FONT_PATH);
112 int download_path_len = safeStrLen(SETTING_FONT_DOWNLOADED_FONT_PATH);
113 if (!safeStrNCmp((const char*)file, SETTING_FONT_PRELOAD_FONT_PATH, preload_path_len) ||
114 !safeStrNCmp((const char*)file, SETTING_FONT_DOWNLOADED_FONT_PATH, download_path_len)) {
115 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, 0, &family) != FcResultMatch) {
116 SETTING_TRACE_DEBUG("Family name is invalid");
120 //SETTING_TRACE_DEBUG("family = %s", (char *)family);
121 if (eina_list_data_find(list, family) == NULL) {
122 list = eina_list_append(list, family);
123 /* list = eina_list_append(list, family); */
124 // for TEST because there's 1 font on target.
129 FcFontSetDestroy(fs);
133 FcConfigDestroy(font_config);
138 static void __setting_font_main_genlist_sel_cb(void *data, Evas_Object * obj, void *event_info)
141 setting_retm_if(data == NULL, "Data parameter is NULL");
143 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
144 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
145 elm_genlist_item_selected_set(item, 0);
146 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item);
148 SettingFontUG *ad = (SettingFontUG *)data;
150 if (ad->font_size == list_item) {
151 setting_view_change(&setting_view_font_main, &setting_view_font_font_size, ad);
155 static void __setting_font_main_genlist_item_create(void *data)
158 setting_retm_if(NULL == data, "data is NULL");
160 SettingFontUG *ad = (SettingFontUG *)data;
161 Elm_Object_Item *item = NULL;
163 if (ad->viewmode == FONT_SIZE_AND_FONT_SEL_UG || ad->viewmode == FONT_SEL_VIEW_APPCONTROL) // font type only
166 item = elm_genlist_item_append(ad->genlist, &(ad->itc_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 char *font_type_name = NULL;
170 font_type_name = cur_font_get();
172 ad->font_type = setting_create_Gendial_exp_parent_field(ad->genlist,
173 &(ad->itc_2text_3_parent),
175 SWALLOW_Type_INVALID,
176 SETTING_FONT_TYPE_STR,
179 ad->font_type->userdata = ad;
181 SETTING_TRACE_ERROR("ad->font_type is NULL");
183 G_FREE(ad->font_name);
184 ad->font_name = g_strdup(font_type_name);
185 G_FREE(font_type_name);
188 if (ad->viewmode == FONT_SIZE_AND_FONT_SEL_UG || ad->viewmode == FONT_SIZE_VIEW_APPCONTROL) // font size only
192 int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &ad->ret_font_size, &err);
194 SETTING_TRACE_ERROR("get vconf failed");
197 ad->font_size = setting_create_Gendial_field_def(ad->genlist, &(ad->itc_2text_2),
198 __setting_font_main_genlist_sel_cb,
199 ad, SWALLOW_Type_INVALID, NULL,
200 NULL, ad->ret_font_size, SETTING_FONT_SIZE_STR,
201 __setting_font_main_get_font_size(ad->ret_font_size), NULL);
203 ad->font_size->userdata = ad;
205 SETTING_TRACE_ERROR("ad->font_size is NULL");
209 setting_create_Gendial_field_def(ad->genlist, &(ad->itc_bg_1icon), NULL,
210 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
211 NULL, NULL, 0, SETTING_FONT_SIZE_DESC, NULL,
221 static void __setting_font_main_font_set(char *font_name)
223 retm_if(font_name == NULL, "Invalid argument: font_name is NULL");
224 xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
227 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
232 font_config_set(font_name);
235 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
236 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
237 ecore_x_window_prop_string_set(ecore_win, atom, "slp");
240 static void __setting_font_main_popup_cb(void *data, Evas_Object *obj, void *event_info)
243 setting_retm_if(data == NULL, "Data parameter is NULL");
244 SettingFontUG *ad = (SettingFontUG *) data;
246 switch (btn_type(obj)) {
247 case POPUP_RESPONSE_OK:
249 ad->font_type->sub_desc = (char *)g_strdup(_(ad->subitem->keyStr));
250 elm_object_item_data_set(ad->font_type->item, ad->font_type);
251 elm_genlist_item_update(ad->font_type->item);
253 ad->prev_font = ad->subitem->chk_status;
254 G_FREE(ad->font_name);
255 ad->font_name = (char *)g_strdup(_(ad->subitem->keyStr));
256 SETTING_TRACE("ad->subitem->keyStr = %s", ad->subitem->keyStr);
257 __setting_font_main_font_set(ad->subitem->keyStr);
258 ug_destroy_me(ad->ug);
261 case POPUP_RESPONSE_CANCEL:
263 elm_radio_value_set(ad->subitem->rgd, ad->prev_font);
274 evas_object_del(ad->popup);
279 static void __setting_font_main_popup(void *data)
282 setting_retm_if(data == NULL, "Data parameter is NULL");
283 SettingFontUG *ad = (SettingFontUG *) data;
285 char popup_desc[SETTING_STR_SLP_LEN + 1] = {0,};
286 snprintf(popup_desc, SETTING_STR_SLP_LEN, "%s %s?", _(SETTING_FONT_POPUP_DESC), ad->subitem->keyStr);
288 ad->popup = setting_create_popup_with_btn(ad, ad->win_get, NULL,
290 __setting_font_main_popup_cb, 0,
291 2, _("IDS_COM_SK_YES"),_("IDS_COM_SK_NO"));
296 * [UI][expandable list][event handler:selection][font change]
298 void __setting_font_main_sub_list_sel_cb(void *data, Evas_Object *obj, void *event_info)
302 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
303 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
304 elm_genlist_item_selected_set(subitem, 0);
305 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
306 ret_if(NULL == data_subItem);
308 SettingFontUG *ad = (SettingFontUG *) data;
310 /* if not change, return */
311 if (ad->prev_font == data_subItem->chk_status) {
312 SETTING_TRACE("NOT CHANGED ");
316 ad->subitem = data_subItem;
317 elm_radio_value_set(ad->subitem->rgd, ad->subitem->chk_status);
319 __setting_font_main_popup(ad);
322 static void __setting_font_main_exp_cb(void *data, Evas_Object *obj, void *event_info)
324 ret_if(NULL == data || NULL == event_info);
326 SettingFontUG *ad = (SettingFontUG *) data;
327 Elm_Object_Item *parentItem = event_info; /* parent item */
328 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
329 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
331 Evas_Object *rgd = NULL;
332 if (data_parentItem == ad->font_type) {
333 rgd = elm_radio_add(scroller);
334 elm_radio_value_set(rgd, -1);
336 Eina_List *font_list = NULL;
338 FcChar8 *font_data = NULL;
339 font_list = __setting_font_main_available_list_get();
342 int matched_font = -1;
343 Setting_GenGroupItem_Data *item = NULL;
344 EINA_LIST_FOREACH(font_list, l, font_data)
346 item = setting_create_Gendial_exp_sub_field(scroller, &(ad->itc_1icon_1text_sub),
347 __setting_font_main_sub_list_sel_cb, ad,
348 parentItem, SWALLOW_Type_1RADIO, rgd,
349 i, (const char*)font_data,
354 if (!safeStrCmp(ad->font_name, (const char*)font_data)) {
362 /* update check status */
363 if (matched_font != -1) {
364 elm_radio_value_set(rgd, matched_font);
367 ad->prev_font = matched_font;
372 /* ***************************************************
376 ***************************************************/
377 static int setting_font_main_create(void *cb)
381 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
383 SettingFontUG *ad = (SettingFontUG *) cb;
385 retvm_if(ad->win_main_layout == NULL, SETTING_DRAW_ERR_FAIL_LOAD_EDJ,
386 "win_main_layout is NULL");
389 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
392 _("IDS_COM_BODY_BACK"),
394 __setting_font_main_click_softkey_back_cb,
396 ad, &ad->genlist, &ad->navibar);
398 setting_enable_expandable_genlist(ad->genlist, ad,
399 __setting_font_main_exp_cb, NULL);
401 __setting_font_main_genlist_item_create(ad);
403 setting_view_font_main.is_create = 1;
404 return SETTING_RETURN_SUCCESS;
407 static int setting_font_main_destroy(void *cb)
410 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
412 SettingFontUG *ad = (SettingFontUG *) cb;
415 evas_object_del(ad->popup);
419 if (ad->ly_main != NULL) {
420 evas_object_del(ad->ly_main);
421 setting_view_font_main.is_create = 0;
424 return SETTING_RETURN_SUCCESS;
427 static int setting_font_main_update(void *cb)
431 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
433 SettingFontUG *ad = (SettingFontUG *) cb;
435 if (ad->ly_main != NULL) {
436 evas_object_show(ad->ly_main);
440 int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &value, &err);
442 SETTING_TRACE_ERROR("get vconf failed");
446 G_FREE(ad->font_size->sub_desc);
447 ad->font_size->sub_desc = (char *)g_strdup(__setting_font_main_get_font_size(value));
448 elm_object_item_data_set(ad->font_size->item, ad->font_size);
449 elm_genlist_item_update(ad->font_size->item);
452 setting_font_update_vconf_key(ad, SETTING_VCONF_INT_TYPE,
453 INT_SLP_SETTING_LCD_TIMEOUT_NORMAL);
456 return SETTING_RETURN_SUCCESS;
459 static int setting_font_main_cleanup(void *cb)
462 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
464 SettingFontUG *ad = (SettingFontUG *) cb;
466 if (ad->ly_main != NULL) {
467 evas_object_hide(ad->ly_main);
470 return SETTING_RETURN_SUCCESS;
473 /* ***************************************************
477 ***************************************************/
479 static void __setting_font_main_click_softkey_back_cb(void *data, Evas_Object *obj,
484 ret_if(data == NULL);
486 SettingFontUG *ad = (SettingFontUG *) data;
488 if (ad->viewmode == FONT_SEL_VIEW_APPCONTROL)
491 if (service_create(&svc))
494 service_add_extra_data(svc, "category", "FontType");
495 service_add_extra_data(svc, "FontType", ad->font_name);
497 SETTING_TRACE(" SERVICE_ADD_EXTRA : %s %s","category", "FontType");
498 SETTING_TRACE(" SERVICE_ADD_EXTRA : %s %s","FontType", ad->font_name);
501 ug_send_result(ad->ug, svc);
502 service_destroy(svc);
504 else if (ad->viewmode == FONT_SIZE_VIEW_APPCONTROL)
507 if (service_create(&svc))
511 int ret = setting_set_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, ad->ret_font_size, &err);
512 setting_retm_if(ret == -1, "Failed to set vconf");
514 char font_size[SETTING_FONT_MAX_LEN] = {0,};
515 snprintf(font_size, SETTING_FONT_MAX_LEN, "%d", ad->ret_font_size);
517 service_add_extra_data(svc, "category", "FontSize");
518 service_add_extra_data(svc, "FontSize", font_size);
520 SETTING_TRACE(" SERVICE_ADD_EXTRA : %s %s","category", "FontSize");
521 SETTING_TRACE(" SERVICE_ADD_EXTRA : %s %s","FontSize", font_size);
524 ug_send_result(ad->ug, svc);
525 service_destroy(svc);
527 /* Send destroy request */
528 ug_destroy_me(ad->ug);