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.
23 #include <sys/types.h>
32 #include <libxml/xmlmemory.h>
33 #include <libxml/parser.h>
36 #include <Elementary.h>
38 #include <system_settings.h>
39 #include <system_settings_private.h>
46 #define SMALL_FONT_DPI (-80)
47 #define MIDDLE_FONT_DPI (-100)
48 #define LARGE_FONT_DPI (-150)
49 #define HUGE_FONT_DPI (-190)
50 #define GIANT_FONT_DPI (-250)
52 #define SETTING_FONT_CONF_FILE "/opt/etc/fonts/conf.avail/99-slp.conf"
53 #define SETTING_STR_SLP_LEN 256
55 static char* _get_cur_font();
56 static void font_size_set();
57 static int __font_size_get();
59 static void font_config_set(char *font_name);
60 static void font_config_set_notification();
62 int system_setting_get_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
65 if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, &vconf_value)) {
66 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
69 return SYSTEM_SETTINGS_ERROR_NONE;
73 int system_setting_get_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
76 if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, &vconf_value)) {
77 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
80 return SYSTEM_SETTINGS_ERROR_NONE;
84 int system_setting_get_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
87 if (system_setting_vconf_get_value_string(VCONFKEY_BGSET, &vconf_value)) {
88 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
91 return SYSTEM_SETTINGS_ERROR_NONE;
95 int system_setting_get_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
99 if (system_setting_vconf_get_value_string(VCONFKEY_IDLE_LOCK_BGSET, &vconf_value)) {
100 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
102 *value = vconf_value;
104 return SYSTEM_SETTINGS_ERROR_NONE;
109 int system_setting_get_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
113 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
114 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
116 *value = (void*)vconf_value;
118 return SYSTEM_SETTINGS_ERROR_NONE;
123 int system_setting_get_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
125 char* font_name = _get_cur_font();
126 *value = (void*)font_name;
128 return SYSTEM_SETTINGS_ERROR_NONE;
132 int system_setting_get_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
136 if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &vconf_value)) {
137 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
139 *value = (void*)vconf_value;
141 return SYSTEM_SETTINGS_ERROR_NONE;
144 ////////////////////////////////////////////////////////////////////////////////////////////////////
146 int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
149 vconf_value = (char*)value;
150 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
151 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
154 return SYSTEM_SETTINGS_ERROR_NONE;
158 int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
161 vconf_value = (char*)value;
162 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, vconf_value)) {
163 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
166 return SYSTEM_SETTINGS_ERROR_NONE;
170 static int _is_file_accessible(const char * path)
172 int ret = access(path ,R_OK);
179 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
182 vconf_value = (char*)value;
184 // error handling here
185 if (_is_file_accessible(vconf_value) != 0)
186 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
188 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
189 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
192 return SYSTEM_SETTINGS_ERROR_NONE;
195 int system_setting_set_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
198 vconf_value = (char*)value;
200 // error handling here
201 if (_is_file_accessible(vconf_value) != 0)
202 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
204 if (system_setting_vconf_set_value_string(VCONFKEY_IDLE_LOCK_BGSET, vconf_value)) {
205 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
208 return SYSTEM_SETTINGS_ERROR_NONE;
211 int system_setting_set_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
214 vconf_value = (int*)value;
216 if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT) {
217 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
220 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, *vconf_value)) {
221 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
224 return SYSTEM_SETTINGS_ERROR_NONE;
229 void *font_conf_doc_parse(char *doc_name, char *font_name)
231 xmlDocPtr doc = NULL;
232 xmlNodePtr cur = NULL;
233 xmlNodePtr cur2 = NULL;
234 xmlNodePtr cur3 = NULL;
237 doc = xmlParseFile(doc_name);
239 cur = xmlDocGetRootElement(doc);
247 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
253 cur = cur->xmlChildrenNode;
255 Eina_Bool is_changed = EINA_FALSE;
258 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
260 cur2 = cur->xmlChildrenNode;
263 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
265 xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
266 /* if name is not 'family', break */
267 if (xmlStrcmp(name, (const xmlChar *)"family"))
276 cur3 = cur2->xmlChildrenNode;
279 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
281 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
282 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
283 //printf("after changed, string is: %s \n", key);
286 is_changed = EINA_TRUE;
293 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias")))
295 cur2 = cur->xmlChildrenNode;
298 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family")))
300 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
301 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
302 //printf("after changed, string is: %s\n", key);
305 is_changed = EINA_TRUE;
306 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer")))
308 cur3 = cur2->xmlChildrenNode;
311 if((!xmlStrcmp(cur3->name, (const xmlChar *)"family")))
313 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
314 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
317 is_changed = EINA_TRUE;
319 break; /* just set first element, so break */
339 int system_setting_set_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
341 char* font_name = NULL;
342 font_name = (char*)value;
344 font_config_set(font_name);
345 font_config_set_notification();
348 vconf_value = (char*)value;
349 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, vconf_value)) {
350 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
353 xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
355 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
360 return SYSTEM_SETTINGS_ERROR_NONE;
363 int system_setting_set_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
366 vconf_value = (bool*)value;
367 if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, *vconf_value)) {
368 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
370 return SYSTEM_SETTINGS_ERROR_NONE;
373 /////////////////////////////////////////////////////////////////////////////////////////////////
376 int system_setting_set_changed_callback_incoming_call_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
378 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0);
381 int system_setting_unset_changed_callback_incoming_call_ringtone(system_settings_key_e key)
383 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, 0);
386 int system_setting_set_changed_callback_email_alert_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
388 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, 0);
391 int system_setting_unset_changed_callback_email_alert_ringtone(system_settings_key_e key)
393 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, 0);
396 int system_setting_set_changed_callback_wallpaper_home_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
398 return system_setting_vconf_set_changed_cb(VCONFKEY_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, 0);
401 int system_setting_unset_changed_callback_wallpaper_home_screen(system_settings_key_e key)
403 return system_setting_vconf_unset_changed_cb(VCONFKEY_BGSET, 0);
406 int system_setting_set_changed_callback_wallpaper_lock_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
408 return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_BGSET,SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, 0);
411 int system_setting_unset_changed_callback_wallpaper_lock_screen(system_settings_key_e key)
413 return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, 0);
416 int system_setting_set_changed_callback_font_size(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
418 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE,SYSTEM_SETTINGS_KEY_FONT_SIZE, 1);
421 int system_setting_unset_changed_callback_font_size(system_settings_key_e key)
423 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, 1);
427 * @todo need to add custom event notification method
429 int system_setting_set_changed_callback_font_type(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
431 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,SYSTEM_SETTINGS_KEY_FONT_TYPE, 2);
434 int system_setting_unset_changed_callback_font_type(system_settings_key_e key)
436 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,2);
439 // TODO : 2th argument, callback, is not in use.
440 int system_setting_set_changed_callback_motion_activation(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
442 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 3);
445 int system_setting_unset_changed_callback_motion_activation(system_settings_key_e key)
447 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, 3);
450 static char* _get_cur_font()
452 xmlDocPtr doc = NULL;
453 xmlNodePtr cur = NULL;
454 xmlNodePtr cur2 = NULL;
455 xmlNodePtr cur3 = NULL;
458 char *font_name = NULL;
460 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
462 cur = xmlDocGetRootElement(doc);
470 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
476 cur = cur->xmlChildrenNode;
480 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
482 cur2 = cur->xmlChildrenNode;
485 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
487 cur3 = cur2->xmlChildrenNode;
490 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
492 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
493 //printf("string is: %s\n", key);
495 font_name = g_strdup((char *)key);
516 static void font_config_set_notification()
519 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
520 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
521 ecore_x_window_prop_string_set(ecore_win, atom, "tizen");
524 static void font_config_set(char *font_name)
526 Eina_List *text_classes = NULL;
527 Elm_Text_Class *etc = NULL;
528 const Eina_List *l = NULL;
529 Eina_List *fo_list = NULL;
530 Elm_Font_Overlay *efo = NULL;
531 int font_size = __font_size_get();
534 text_classes = elm_config_text_classes_list_get();
536 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
538 Eina_List *ll = NULL;
539 Eina_List *l_next = NULL;
541 Eina_Bool slp_medium_exist = EINA_FALSE;
542 Eina_Bool slp_roman_exist = EINA_FALSE;
543 Eina_Bool slp_bold_exist = EINA_FALSE;
544 Eina_Bool slp_regular_exist = EINA_FALSE;
547 Eina_Bool tizen_exist = EINA_FALSE;
549 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
551 if (!strcmp(efo->text_class, "tizen_medium")) {
552 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
553 slp_medium_exist = EINA_TRUE;
554 } else if (!strcmp(efo->text_class, "tizen_roman")) {
555 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
556 slp_roman_exist = EINA_TRUE;
557 } else if (!strcmp(efo->text_class, "tizen_bold")) {
558 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
559 slp_bold_exist = EINA_TRUE;
560 } else if (!strcmp(efo->text_class, "tizen_regular")) {
561 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
562 slp_regular_exist = EINA_TRUE;
566 if (!strcmp(efo->text_class, "tizen")) {
567 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
568 tizen_exist = EINA_TRUE;
573 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
574 if (slp_medium_exist == EINA_FALSE) {
575 elm_config_font_overlay_set("tizen_medium", (const char*)font_name, MIDDLE_FONT_DPI);
577 if (slp_roman_exist == EINA_FALSE) {
578 elm_config_font_overlay_set("tizen_roman", (const char*)font_name, MIDDLE_FONT_DPI);
580 if (slp_bold_exist == EINA_FALSE) {
581 elm_config_font_overlay_set("tizen_bold", (const char*)font_name, MIDDLE_FONT_DPI);
583 if (slp_regular_exist == EINA_FALSE) {
584 elm_config_font_overlay_set("tizen_regular", (const char*)font_name, MIDDLE_FONT_DPI);
588 if (tizen_exist == EINA_FALSE) {
589 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
592 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
595 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
597 EINA_LIST_FOREACH(text_classes, l, etc)
602 EINA_LIST_FOREACH(fo_list, ll, efo)
604 if (!strcmp(etc->name, efo->text_class)) {
608 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
611 elm_config_font_overlay_apply();
612 elm_config_all_flush();
613 // elm_config_engine_set("software_x11");
615 elm_config_text_classes_list_free(text_classes);
619 vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
622 static void font_size_set()
624 Eina_List *text_classes = NULL;
625 Elm_Text_Class *etc = NULL;
626 const Eina_List *l = NULL;
627 int font_size = __font_size_get();
628 char *font_name = _get_cur_font();
630 if (font_size == -1) {
634 text_classes = elm_config_text_classes_list_get();
636 EINA_LIST_FOREACH(text_classes, l, etc)
638 elm_config_font_overlay_set(etc->name, font_name, font_size);
641 elm_config_font_overlay_apply();
642 elm_config_all_flush();
644 elm_config_text_classes_list_free(text_classes);
649 static int __font_size_get()
654 int vconf_value = -1;
655 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
659 switch(vconf_value) {
660 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
661 font_size = SMALL_FONT_DPI;
663 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
664 font_size = MIDDLE_FONT_DPI;
666 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
667 font_size = LARGE_FONT_DPI;
669 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
670 font_size = HUGE_FONT_DPI;
672 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
673 font_size = GIANT_FONT_DPI;
676 font_size = MIDDLE_FONT_DPI;