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 static int setting_font_main_create(void *cb);
31 static int setting_font_main_destroy(void *cb);
32 static int setting_font_main_update(void *cb);
33 static int setting_font_main_cleanup(void *cb);
35 static void __setting_font_main_click_softkey_back_cb(void *data, Evas_Object *obj,
38 setting_view setting_view_font_main = {
39 .create = setting_font_main_create,
40 .destroy = setting_font_main_destroy,
41 .update = setting_font_main_update,
42 .cleanup = setting_font_main_cleanup,
45 static char* __setting_font_main_get_font_size(int value)
47 const char* font_size_arr[] = {
48 _("IDS_ST_BODY_SMALL_M_TEXTSIZE"), // 0
49 _("IDS_ST_BODY_NORMAL_T_PROFILE"), // 1
50 _("IDS_ST_BODY_TEXTSTYLE_LARGE"), // 2
51 _("IDS_EMAIL_OPT_HUGE_M_TEXTSIZE"), // 3
52 _("IDS_EMAIL_POP_GIANT_M_TEXTSIZE"), // 4
56 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
57 return (char *)font_size_arr[0];
58 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
59 return (char *)font_size_arr[1];
60 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
61 return (char *)font_size_arr[2];
62 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
63 return (char *)font_size_arr[3];
64 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
65 return (char *)font_size_arr[4];
67 return (char *)font_size_arr[1];
71 static Eina_List *__setting_font_main_available_list_get()
74 FcObjectSet *os = NULL;
76 FcPattern *pat = NULL;
77 Eina_List *list = NULL;
78 FcConfig *font_config = NULL;
80 font_config = FcInitLoadConfigAndFonts();
82 setting_retvm_if(font_config == NULL, NULL, "Failed: FcInitLoadConfigAndFonts");
84 pat = FcPatternCreate();
86 os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *) 0);
89 fs = FcFontList(font_config, pat, os);
90 FcObjectSetDestroy(os);
95 FcPatternDestroy(pat);
101 SETTING_TRACE_DEBUG("fs->nfont = %d", fs->nfont);
103 for (j = 0; j < fs->nfont; j++) {
104 FcChar8 *family = NULL;
105 FcChar8 *file = NULL;
107 if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) {
108 //SETTING_TRACE_DEBUG("FC_FILE : %s\n", file);
109 int preload_path_len = safeStrLen(SETTING_FONT_PRELOAD_FONT_PATH);
110 int download_path_len = safeStrLen(SETTING_FONT_DOWNLOADED_FONT_PATH);
111 if (!safeStrNCmp((const char*)file, SETTING_FONT_PRELOAD_FONT_PATH, preload_path_len) ||
112 !safeStrNCmp((const char*)file, SETTING_FONT_DOWNLOADED_FONT_PATH, download_path_len)) {
113 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, 0, &family) != FcResultMatch) {
114 SETTING_TRACE_DEBUG("Family name is invalid");
118 //SETTING_TRACE_DEBUG("family = %s", (char *)family);
119 if (eina_list_data_find(list, family) == NULL) {
120 list = eina_list_append(list, family);
121 /* list = eina_list_append(list, family); */
122 // for TEST because there's 1 font on target.
127 FcFontSetDestroy(fs);
131 FcConfigDestroy(font_config);
136 static void __setting_font_main_genlist_sel_cb(void *data, Evas_Object * obj, void *event_info)
139 setting_retm_if(data == NULL, "Data parameter is NULL");
141 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
142 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
143 elm_genlist_item_selected_set(item, 0);
144 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item);
146 SettingFontUG *ad = (SettingFontUG *)data;
148 if (ad->font_size == list_item) {
149 setting_view_change(&setting_view_font_main, &setting_view_font_font_size, ad);
153 static void __setting_font_main_genlist_item_create(void *data)
156 setting_retm_if(NULL == data, "data is NULL");
158 SettingFontUG *ad = (SettingFontUG *)data;
159 Elm_Object_Item *item = NULL;
160 item = elm_genlist_item_append(ad->genlist, &(ad->itc_seperator), NULL, NULL,
161 ELM_GENLIST_ITEM_NONE, NULL, NULL);
162 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
164 char *font_type_name = NULL;
165 font_type_name = cur_font_get();
167 ad->font_type = setting_create_Gendial_exp_parent_field(ad->genlist,
168 &(ad->itc_2text_3_parent),
170 SWALLOW_Type_INVALID,
171 SETTING_FONT_TYPE_STR,
174 ad->font_type->userdata = ad;
176 SETTING_TRACE_ERROR("ad->font_type is NULL");
178 G_FREE(ad->font_name);
179 ad->font_name = g_strdup(font_type_name);
180 G_FREE(font_type_name);
182 if (ad->viewmode == FONT_SEL_VIEW_APPCONTROL)
184 //--------------------------------------------------------------------
189 int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &value, &err);
191 SETTING_TRACE_ERROR("get vconf failed");
194 ad->font_size = setting_create_Gendial_field_def(ad->genlist, &(ad->itc_2text_2),
195 __setting_font_main_genlist_sel_cb,
196 ad, SWALLOW_Type_INVALID, NULL,
197 NULL, value, SETTING_FONT_SIZE_STR,
198 __setting_font_main_get_font_size(value), NULL);
200 ad->font_size->userdata = ad;
202 SETTING_TRACE_ERROR("ad->font_size is NULL");
206 setting_create_Gendial_field_def(ad->genlist, &(ad->itc_bg_1icon), NULL,
207 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
208 NULL, NULL, 0, SETTING_FONT_SIZE_DESC, NULL,
217 static void __setting_font_main_font_set(char *font_name)
219 retm_if(font_name == NULL, "Invalid argument: font_name is NULL");
220 xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
223 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
228 font_config_set(font_name);
231 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
232 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
233 ecore_x_window_prop_string_set(ecore_win, atom, "slp");
236 static void __setting_font_main_popup_cb(void *data, Evas_Object *obj, void *event_info)
239 setting_retm_if(data == NULL, "Data parameter is NULL");
240 SettingFontUG *ad = (SettingFontUG *) data;
242 switch (btn_type(obj)) {
243 case POPUP_RESPONSE_OK:
245 ad->font_type->sub_desc = (char *)g_strdup(_(ad->subitem->keyStr));
246 elm_object_item_data_set(ad->font_type->item, ad->font_type);
247 elm_genlist_item_update(ad->font_type->item);
249 ad->prev_font = ad->subitem->chk_status;
250 G_FREE(ad->font_name);
251 ad->font_name = (char *)g_strdup(_(ad->subitem->keyStr));
252 SETTING_TRACE("ad->subitem->keyStr = %s", ad->subitem->keyStr);
253 __setting_font_main_font_set(ad->subitem->keyStr);
254 ug_destroy_me(ad->ug);
257 case POPUP_RESPONSE_CANCEL:
259 elm_radio_value_set(ad->subitem->rgd, ad->prev_font);
270 evas_object_del(ad->popup);
275 static void __setting_font_main_popup(void *data)
278 setting_retm_if(data == NULL, "Data parameter is NULL");
279 SettingFontUG *ad = (SettingFontUG *) data;
281 char popup_desc[SETTING_STR_SLP_LEN + 1] = {0,};
282 snprintf(popup_desc, SETTING_STR_SLP_LEN, "%s %s?", _(SETTING_FONT_POPUP_DESC), ad->subitem->keyStr);
284 ad->popup = setting_create_popup_with_btn(ad, ad->win_get, NULL,
286 __setting_font_main_popup_cb, 0,
287 2, _("IDS_COM_SK_YES"),_("IDS_COM_SK_NO"));
292 * [UI][expandable list][event handler:selection][font change]
294 void __setting_font_main_sub_list_sel_cb(void *data, Evas_Object *obj, void *event_info)
298 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
299 Elm_Object_Item *subitem = (Elm_Object_Item *) event_info;
300 elm_genlist_item_selected_set(subitem, 0);
301 Setting_GenGroupItem_Data *data_subItem = elm_object_item_data_get(subitem);
302 ret_if(NULL == data_subItem);
304 SettingFontUG *ad = (SettingFontUG *) data;
306 /* if not change, return */
307 if (ad->prev_font == data_subItem->chk_status) {
308 SETTING_TRACE("NOT CHANGED ");
312 ad->subitem = data_subItem;
313 elm_radio_value_set(ad->subitem->rgd, ad->subitem->chk_status);
315 __setting_font_main_popup(ad);
318 static void __setting_font_main_exp_cb(void *data, Evas_Object *obj, void *event_info)
320 ret_if(NULL == data || NULL == event_info);
322 SettingFontUG *ad = (SettingFontUG *) data;
323 Elm_Object_Item *parentItem = event_info; /* parent item */
324 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
325 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
327 Evas_Object *rgd = NULL;
328 if (data_parentItem == ad->font_type) {
329 rgd = elm_radio_add(scroller);
330 elm_radio_value_set(rgd, -1);
332 Eina_List *font_list = NULL;
334 FcChar8 *font_data = NULL;
335 font_list = __setting_font_main_available_list_get();
338 int matched_font = -1;
339 Setting_GenGroupItem_Data *item = NULL;
340 EINA_LIST_FOREACH(font_list, l, font_data)
342 item = setting_create_Gendial_exp_sub_field(scroller, &(ad->itc_1icon_1text_sub),
343 __setting_font_main_sub_list_sel_cb, ad,
344 parentItem, SWALLOW_Type_1RADIO, rgd,
345 i, (const char*)font_data,
350 if (!safeStrCmp(ad->font_name, (const char*)font_data)) {
358 /* update check status */
359 if (matched_font != -1) {
360 elm_radio_value_set(rgd, matched_font);
363 ad->prev_font = matched_font;
368 /* ***************************************************
372 ***************************************************/
373 static int setting_font_main_create(void *cb)
377 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
379 SettingFontUG *ad = (SettingFontUG *) cb;
381 retvm_if(ad->win_main_layout == NULL, SETTING_DRAW_ERR_FAIL_LOAD_EDJ,
382 "win_main_layout is NULL");
385 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
388 _("IDS_COM_BODY_BACK"),
390 __setting_font_main_click_softkey_back_cb,
392 ad, &ad->genlist, &ad->navibar);
394 setting_enable_expandable_genlist(ad->genlist, ad,
395 __setting_font_main_exp_cb, NULL);
397 __setting_font_main_genlist_item_create(ad);
399 setting_view_font_main.is_create = 1;
400 return SETTING_RETURN_SUCCESS;
403 static int setting_font_main_destroy(void *cb)
406 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
408 SettingFontUG *ad = (SettingFontUG *) cb;
411 evas_object_del(ad->popup);
415 if (ad->ly_main != NULL) {
416 evas_object_del(ad->ly_main);
417 setting_view_font_main.is_create = 0;
420 return SETTING_RETURN_SUCCESS;
423 static int setting_font_main_update(void *cb)
427 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
429 SettingFontUG *ad = (SettingFontUG *) cb;
431 if (ad->ly_main != NULL) {
432 evas_object_show(ad->ly_main);
436 int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &value, &err);
438 SETTING_TRACE_ERROR("get vconf failed");
442 G_FREE(ad->font_size->sub_desc);
443 ad->font_size->sub_desc = (char *)g_strdup(__setting_font_main_get_font_size(value));
444 elm_object_item_data_set(ad->font_size->item, ad->font_size);
445 elm_genlist_item_update(ad->font_size->item);
448 setting_font_update_vconf_key(ad, SETTING_VCONF_INT_TYPE,
449 INT_SLP_SETTING_LCD_TIMEOUT_NORMAL);
452 return SETTING_RETURN_SUCCESS;
455 static int setting_font_main_cleanup(void *cb)
458 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
460 SettingFontUG *ad = (SettingFontUG *) cb;
462 if (ad->ly_main != NULL) {
463 evas_object_hide(ad->ly_main);
466 return SETTING_RETURN_SUCCESS;
469 /* ***************************************************
473 ***************************************************/
475 static void __setting_font_main_click_softkey_back_cb(void *data, Evas_Object *obj,
480 ret_if(data == NULL);
482 SettingFontUG *ad = (SettingFontUG *) data;
484 if (ad->viewmode == FONT_SEL_VIEW_APPCONTROL)
487 if (service_create(&svc))
490 service_add_extra_data(svc, "category", "FontType");
491 service_add_extra_data(svc, "FontType", ad->font_name);
493 SETTING_TRACE(" SERVICE_ADD_EXTRA : %s %s","category", "FontType");
494 SETTING_TRACE(" SERVICE_ADD_EXTRA : %s %s","FontType", ad->font_name);
497 ug_send_result(ad->ug, svc);
498 service_destroy(svc);
501 /* Send destroy request */
502 ug_destroy_me(ad->ug);