2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <sys/types.h>
29 #include <libxml/xmlmemory.h>
30 #include <libxml/parser.h>
33 #include <Elementary.h>
35 #include <system_settings.h>
36 #include <system_settings_private.h>
43 #define SMALL_FONT_DPI (-80)
44 #define MIDDLE_FONT_DPI (-100)
45 #define LARGE_FONT_DPI (-150)
46 #define HUGE_FONT_DPI (-190)
47 #define GIANT_FONT_DPI (-250)
49 #define SETTING_FONT_CONF_FILE "/opt/etc/fonts/conf.avail/99-slp.conf"
50 #define SETTING_STR_SLP_LEN 256
52 static char* _get_cur_font();
53 static void font_size_set();
54 static int __font_size_get();
56 static void font_config_set(char *font_name);
57 static void font_config_set_notification();
59 int system_setting_get_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
62 if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, &vconf_value)) {
63 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
66 return SYSTEM_SETTINGS_ERROR_NONE;
70 int system_setting_get_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
73 if (system_setting_vconf_get_value_string(VCONFKEY_BGSET, &vconf_value)) {
74 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
77 return SYSTEM_SETTINGS_ERROR_NONE;
81 int system_setting_get_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
85 if (system_setting_vconf_get_value_string(VCONFKEY_IDLE_LOCK_BGSET, &vconf_value)) {
86 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
90 return SYSTEM_SETTINGS_ERROR_NONE;
95 int system_setting_get_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
97 printf("system_setting_get_font_size \n");
100 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
101 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
103 *value = (void*)vconf_value;
105 return SYSTEM_SETTINGS_ERROR_NONE;
110 int system_setting_get_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
112 printf("system_setting_get_font_type\n");
115 char* font_name = _get_cur_font();
117 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_FONT_TYPE_INT, &vconf_value)) {
118 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
120 //*value = (void*)vconf_value;
122 *value = (void*)font_name;
124 return SYSTEM_SETTINGS_ERROR_NONE;
128 int system_setting_get_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
132 if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &vconf_value)) {
133 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
135 *value = (void*)vconf_value;
137 return SYSTEM_SETTINGS_ERROR_NONE;
140 ////////////////////////////////////////////////////////////////////////////////////////////////////
142 int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
144 printf(" mock --> real system_setting_set_incoming_call_ringtone \n");
146 vconf_value = (char*)value;
147 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
148 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
151 return SYSTEM_SETTINGS_ERROR_NONE;
154 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
156 printf(" mock --> real system_setting_set_wallpaper_home_screen \n");
159 vconf_value = (char*)value;
160 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
161 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
164 return SYSTEM_SETTINGS_ERROR_NONE;
167 int system_setting_set_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
169 printf(" mock --> real system_setting_set_wallpaper_lock_screen \n");
172 vconf_value = (char*)value;
173 if (system_setting_vconf_set_value_string(VCONFKEY_IDLE_LOCK_BGSET, vconf_value)) {
174 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
177 return SYSTEM_SETTINGS_ERROR_NONE;
180 int system_setting_set_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
182 printf(" real system_setting_set_font_size \n");
184 vconf_value = (int*)value;
186 if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT) {
187 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
190 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, *vconf_value)) {
191 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
195 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. system_setting_set_font_size called \n");
197 return SYSTEM_SETTINGS_ERROR_NONE;
200 int system_setting_set_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
202 printf(" real system_setting_set_font_type \n");
203 char* font_name = NULL;
204 font_name = (char*)value;
206 printf(">>>>>>>>>>>>> font name = %s \n", font_name);
207 font_config_set(font_name);
208 font_config_set_notification();
211 vconf_value = (char*)value;
212 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, vconf_value)) {
213 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
215 return SYSTEM_SETTINGS_ERROR_NONE;
218 int system_setting_set_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
220 printf(" mock --> real system_setting_set_motion_activation \n");
223 vconf_value = (bool*)value;
224 if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, *vconf_value)) {
225 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
227 return SYSTEM_SETTINGS_ERROR_NONE;
230 /////////////////////////////////////////////////////////////////////////////////////////////////
233 int system_setting_set_changed_callback_incoming_call_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
235 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0);
238 int system_setting_unset_changed_callback_incoming_call_ringtone(system_settings_key_e key)
240 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, 0);
243 int system_setting_set_changed_callback_wallpaper_home_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
245 return system_setting_vconf_set_changed_cb(VCONFKEY_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, 0);
248 int system_setting_unset_changed_callback_wallpaper_home_screen(system_settings_key_e key)
250 return system_setting_vconf_unset_changed_cb(VCONFKEY_BGSET, 0);
253 int system_setting_set_changed_callback_wallpaper_lock_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
255 return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_BGSET,SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, 0);
258 int system_setting_unset_changed_callback_wallpaper_lock_screen(system_settings_key_e key)
260 return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, 0);
263 int system_setting_set_changed_callback_font_size(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
265 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE,SYSTEM_SETTINGS_KEY_FONT_SIZE, 1);
268 int system_setting_unset_changed_callback_font_size(system_settings_key_e key)
270 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, 1);
274 * @todo need to add custom event notification method
276 int system_setting_set_changed_callback_font_type(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
278 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,SYSTEM_SETTINGS_KEY_FONT_TYPE, 2);
281 int system_setting_unset_changed_callback_font_type(system_settings_key_e key)
283 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,2);
286 // TODO : 2th argument, callback, is not in use.
287 int system_setting_set_changed_callback_motion_activation(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
289 printf("system_setting_set_changed_callback_motion_activation \n");
290 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 3);
293 int system_setting_unset_changed_callback_motion_activation(system_settings_key_e key)
295 printf("system_setting_unset_changed_callback_motion_activation \n");
296 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, 3);
299 static char* _get_cur_font()
301 printf("get current font \n");
303 xmlDocPtr doc = NULL;
304 xmlNodePtr cur = NULL;
305 xmlNodePtr cur2 = NULL;
306 xmlNodePtr cur3 = NULL;
309 char *font_name = NULL;
311 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
313 cur = xmlDocGetRootElement(doc);
316 printf("empty document");
322 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
323 printf("document of the wrong type, root node != fontconfig");
329 cur = cur->xmlChildrenNode;
333 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
335 cur2 = cur->xmlChildrenNode;
338 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
340 cur3 = cur2->xmlChildrenNode;
343 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
345 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
346 //printf("string is: %s", key);
348 font_name = g_strdup((char *)key);
369 static void font_config_set_notification()
372 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
373 printf("FONT CHANGE NOTIFICATION >>>>>>>>>> : %d \n", (unsigned int)ecore_win);
374 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
375 ecore_x_window_prop_string_set(ecore_win, atom, "slp");
378 static void font_config_set(char *font_name)
380 Eina_List *text_classes = NULL;
381 Elm_Text_Class *etc = NULL;
382 const Eina_List *l = NULL;
383 Eina_List *fo_list = NULL;
384 Elm_Font_Overlay *efo = NULL;
385 int font_size = __font_size_get();
388 text_classes = elm_config_text_classes_list_get();
390 fo_list = elm_config_font_overlay_list_get();
392 Eina_List *ll = NULL;
393 Eina_List *l_next = NULL;
395 Eina_Bool slp_medium_exist = EINA_FALSE;
396 Eina_Bool slp_roman_exist = EINA_FALSE;
397 Eina_Bool slp_bold_exist = EINA_FALSE;
398 Eina_Bool slp_regular_exist = EINA_FALSE;
400 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
402 if (!strcmp(efo->text_class, "slp_medium")) {
403 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
404 slp_medium_exist = EINA_TRUE;
405 } else if (!strcmp(efo->text_class, "slp_roman")) {
406 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
407 slp_roman_exist = EINA_TRUE;
408 } else if (!strcmp(efo->text_class, "slp_bold")) {
409 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
410 slp_bold_exist = EINA_TRUE;
411 } else if (!strcmp(efo->text_class, "slp_regular")) {
412 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
413 slp_regular_exist = EINA_TRUE;
417 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
418 if (slp_medium_exist == EINA_FALSE) {
419 elm_config_font_overlay_set("slp_medium", (const char*)font_name, MIDDLE_FONT_DPI);
421 if (slp_roman_exist == EINA_FALSE) {
422 elm_config_font_overlay_set("slp_roman", (const char*)font_name, MIDDLE_FONT_DPI);
424 if (slp_bold_exist == EINA_FALSE) {
425 elm_config_font_overlay_set("slp_bold", (const char*)font_name, MIDDLE_FONT_DPI);
427 if (slp_regular_exist == EINA_FALSE) {
428 elm_config_font_overlay_set("slp_regular", (const char*)font_name, MIDDLE_FONT_DPI);
431 EINA_LIST_FOREACH(text_classes, l, etc)
436 EINA_LIST_FOREACH(fo_list, ll, efo)
438 if (!strcmp(etc->name, efo->text_class)) {
442 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
445 elm_config_font_overlay_apply();
446 elm_config_all_flush();
448 elm_config_text_classes_list_free(text_classes);
452 static void font_size_set()
454 Eina_List *text_classes = NULL;
455 Elm_Text_Class *etc = NULL;
456 const Eina_List *l = NULL;
457 int font_size = __font_size_get();
458 char *font_name = _get_cur_font();
460 if (font_size == -1) {
461 //SETTING_TRACE_DEBUG("failed to call font_size_get");
464 printf(">> font name = %s, font size = %d \n", font_name, font_size);
467 text_classes = elm_config_text_classes_list_get();
469 EINA_LIST_FOREACH(text_classes, l, etc)
471 elm_config_font_overlay_set(etc->name, font_name, font_size);
474 elm_config_font_overlay_apply();
475 elm_config_all_flush();
477 elm_config_text_classes_list_free(text_classes);
481 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. font_size_set called \n");
484 static int __font_size_get()
489 int vconf_value = -1;
490 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
494 switch(vconf_value) {
495 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
496 font_size = SMALL_FONT_DPI;
498 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
499 font_size = MIDDLE_FONT_DPI;
501 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
502 font_size = LARGE_FONT_DPI;
504 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
505 font_size = HUGE_FONT_DPI;
507 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
508 font_size = GIANT_FONT_DPI;
511 font_size = MIDDLE_FONT_DPI;