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>
41 #define SMALL_FONT_DPI (-80)
42 #define MIDDLE_FONT_DPI (-100)
43 #define LARGE_FONT_DPI (-150)
44 #define HUGE_FONT_DPI (-190)
45 #define GIANT_FONT_DPI (-250)
47 #define SETTING_FONT_CONF_FILE "/opt/etc/fonts/conf.avail/99-slp.conf"
48 #define SETTING_STR_SLP_LEN 256
50 static char* _get_cur_font();
51 static void __font_size_set();
52 static int __font_size_get();
54 static void font_config_set(char *font_name);
55 static void font_config_set_notification();
58 * VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR has a path of the ringtone file which user choose
59 * @return the ringtone file path specified by user in normal case
60 * if it's not accessable, return the default ringtone path
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 // check to see if it's accessable -> OK
70 // no --> default ringtone path VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR
71 int is_load = _is_file_accessible(vconf_value);
74 } else { // not zero on errro
75 *value = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR);
78 //*value = vconf_value;
79 return SYSTEM_SETTINGS_ERROR_NONE;
83 int system_setting_get_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
86 if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, &vconf_value)) {
87 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
90 return SYSTEM_SETTINGS_ERROR_NONE;
94 int system_setting_get_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
97 if (system_setting_vconf_get_value_string(VCONFKEY_BGSET, &vconf_value)) {
98 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
100 *value = vconf_value;
101 return SYSTEM_SETTINGS_ERROR_NONE;
105 int system_setting_get_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
109 if (system_setting_vconf_get_value_string(VCONFKEY_IDLE_LOCK_BGSET, &vconf_value)) {
110 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
112 *value = vconf_value;
114 return SYSTEM_SETTINGS_ERROR_NONE;
119 int system_setting_get_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
123 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
124 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
126 *value = (void*)vconf_value;
128 return SYSTEM_SETTINGS_ERROR_NONE;
133 int system_setting_get_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
135 char* font_name = _get_cur_font();
136 *value = (void*)font_name;
138 return SYSTEM_SETTINGS_ERROR_NONE;
142 int system_setting_get_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
146 if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &vconf_value)) {
147 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
149 *value = (void*)vconf_value;
151 return SYSTEM_SETTINGS_ERROR_NONE;
154 int system_setting_get_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
158 if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &vconf_value)) {
159 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
161 *value = (void*)vconf_value;
163 return SYSTEM_SETTINGS_ERROR_NONE;
166 int system_setting_get_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
170 if (system_setting_vconf_get_value_bool(VCONFKEY_3G_ENABLE, &vconf_value)) {
171 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
173 *value = (void*)vconf_value;
175 return SYSTEM_SETTINGS_ERROR_NONE;
177 ////////////////////////////////////////////////////////////////////////////////////////////////////
179 int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
182 vconf_value = (char*)value;
184 int is_load = _is_file_accessible(vconf_value);
187 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
188 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
191 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
194 return SYSTEM_SETTINGS_ERROR_NONE;
198 int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
201 vconf_value = (char*)value;
202 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, vconf_value)) {
203 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
206 return SYSTEM_SETTINGS_ERROR_NONE;
210 int _is_file_accessible(const char * path)
212 int ret = access(path ,R_OK);
215 SETTING_TRACE("found the file %s", path);
224 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
227 vconf_value = (char*)value;
229 // error handling here
230 if (_is_file_accessible(vconf_value) != 0)
231 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
233 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
234 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
237 return SYSTEM_SETTINGS_ERROR_NONE;
240 int system_setting_set_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
243 vconf_value = (char*)value;
245 // error handling here
246 if (_is_file_accessible(vconf_value) != 0)
247 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
249 if (system_setting_vconf_set_value_string(VCONFKEY_IDLE_LOCK_BGSET, vconf_value)) {
250 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
253 return SYSTEM_SETTINGS_ERROR_NONE;
256 int system_setting_set_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
260 vconf_value = (int*)value;
262 if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT) {
263 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
266 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, *vconf_value)) {
267 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
271 return SYSTEM_SETTINGS_ERROR_NONE;
276 void *font_conf_doc_parse(char *doc_name, char *font_name)
278 xmlDocPtr doc = NULL;
279 xmlNodePtr cur = NULL;
280 xmlNodePtr cur2 = NULL;
281 xmlNodePtr cur3 = NULL;
284 doc = xmlParseFile(doc_name);
286 cur = xmlDocGetRootElement(doc);
294 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
300 cur = cur->xmlChildrenNode;
302 Eina_Bool is_changed = EINA_FALSE;
305 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
307 cur2 = cur->xmlChildrenNode;
310 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
312 xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
313 /* if name is not 'family', break */
314 if (xmlStrcmp(name, (const xmlChar *)"family"))
323 cur3 = cur2->xmlChildrenNode;
326 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
328 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
329 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
332 is_changed = EINA_TRUE;
339 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias")))
341 cur2 = cur->xmlChildrenNode;
344 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family")))
346 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
347 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
350 is_changed = EINA_TRUE;
351 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer")))
353 cur3 = cur2->xmlChildrenNode;
356 if((!xmlStrcmp(cur3->name, (const xmlChar *)"family")))
358 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
359 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
362 is_changed = EINA_TRUE;
364 break; /* just set first element, so break */
384 int system_setting_set_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
386 char* font_name = NULL;
387 font_name = (char*)value;
389 font_config_set(font_name);
390 font_config_set_notification();
393 vconf_value = (char*)value;
394 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, vconf_value)) {
395 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
398 xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
400 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
405 return SYSTEM_SETTINGS_ERROR_NONE;
408 int system_setting_set_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
411 vconf_value = (bool*)value;
412 if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, *vconf_value)) {
413 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
415 return SYSTEM_SETTINGS_ERROR_NONE;
418 int system_setting_set_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
421 vconf_value = (bool*)value;
422 if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, *vconf_value)) {
423 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
425 return SYSTEM_SETTINGS_ERROR_NONE;
429 int system_setting_set_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
432 vconf_value = (bool*)value;
433 if (system_setting_vconf_set_value_bool(VCONFKEY_3G_ENABLE, *vconf_value)) {
434 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
436 return SYSTEM_SETTINGS_ERROR_NONE;
439 /////////////////////////////////////////////////////////////////////////////////////////////////
442 int system_setting_set_changed_callback_incoming_call_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
444 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0, user_data);
447 int system_setting_unset_changed_callback_incoming_call_ringtone(system_settings_key_e key)
449 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, 0);
452 int system_setting_set_changed_callback_email_alert_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
454 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, 0, user_data);
457 int system_setting_unset_changed_callback_email_alert_ringtone(system_settings_key_e key)
459 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, 0);
462 int system_setting_set_changed_callback_wallpaper_home_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
464 return system_setting_vconf_set_changed_cb(VCONFKEY_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, 0, user_data);
467 int system_setting_unset_changed_callback_wallpaper_home_screen(system_settings_key_e key)
469 return system_setting_vconf_unset_changed_cb(VCONFKEY_BGSET, 0);
472 int system_setting_set_changed_callback_wallpaper_lock_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
474 return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_BGSET,SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, 0, user_data);
477 int system_setting_unset_changed_callback_wallpaper_lock_screen(system_settings_key_e key)
479 return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, 0);
482 int system_setting_set_changed_callback_font_size(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
484 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE,SYSTEM_SETTINGS_KEY_FONT_SIZE, 1, user_data);
487 int system_setting_unset_changed_callback_font_size(system_settings_key_e key)
489 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, 1);
492 int system_setting_set_changed_callback_usb_debugging_option(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
494 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED, 1, user_data);
497 int system_setting_unset_changed_callback_usb_debugging_option(system_settings_key_e key)
499 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 1);
502 int system_setting_set_changed_callback_3g_data_network(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
504 return system_setting_vconf_set_changed_cb(VCONFKEY_3G_ENABLE,SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 1,user_data);
507 int system_setting_unset_changed_callback_3g_data_network(system_settings_key_e key)
509 return system_setting_vconf_unset_changed_cb(VCONFKEY_3G_ENABLE, 1);
514 * @todo need to add custom event notification method
516 int system_setting_set_changed_callback_font_type(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
518 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,SYSTEM_SETTINGS_KEY_FONT_TYPE, 2, user_data);
521 int system_setting_unset_changed_callback_font_type(system_settings_key_e key)
523 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,2);
526 // TODO : 2th argument, callback, is not in use.
527 int system_setting_set_changed_callback_motion_activation(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
529 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 3, user_data );
532 int system_setting_unset_changed_callback_motion_activation(system_settings_key_e key)
534 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, 3);
537 static char* _get_cur_font()
539 xmlDocPtr doc = NULL;
540 xmlNodePtr cur = NULL;
541 xmlNodePtr cur2 = NULL;
542 xmlNodePtr cur3 = NULL;
545 char *font_name = NULL;
547 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
549 cur = xmlDocGetRootElement(doc);
557 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
563 cur = cur->xmlChildrenNode;
567 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
569 cur2 = cur->xmlChildrenNode;
572 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
574 cur3 = cur2->xmlChildrenNode;
577 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
579 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
581 font_name = g_strdup((char *)key);
602 static void font_config_set_notification()
605 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
606 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
607 ecore_x_window_prop_string_set(ecore_win, atom, "tizen");
610 static void font_config_set(char *font_name)
612 Eina_List *text_classes = NULL;
613 Elm_Text_Class *etc = NULL;
614 const Eina_List *l = NULL;
615 Eina_List *fo_list = NULL;
616 Elm_Font_Overlay *efo = NULL;
617 int font_size = __font_size_get();
620 text_classes = elm_config_text_classes_list_get();
622 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
624 Eina_List *ll = NULL;
625 Eina_List *l_next = NULL;
627 Eina_Bool slp_medium_exist = EINA_FALSE;
628 Eina_Bool slp_roman_exist = EINA_FALSE;
629 Eina_Bool slp_bold_exist = EINA_FALSE;
630 Eina_Bool slp_regular_exist = EINA_FALSE;
633 Eina_Bool tizen_exist = EINA_FALSE;
635 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
637 if (!strcmp(efo->text_class, "tizen_medium")) {
638 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
639 slp_medium_exist = EINA_TRUE;
640 } else if (!strcmp(efo->text_class, "tizen_roman")) {
641 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
642 slp_roman_exist = EINA_TRUE;
643 } else if (!strcmp(efo->text_class, "tizen_bold")) {
644 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
645 slp_bold_exist = EINA_TRUE;
646 } else if (!strcmp(efo->text_class, "tizen_regular")) {
647 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
648 slp_regular_exist = EINA_TRUE;
652 if (!strcmp(efo->text_class, "tizen")) {
653 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
654 tizen_exist = EINA_TRUE;
659 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
660 if (slp_medium_exist == EINA_FALSE) {
661 elm_config_font_overlay_set("tizen_medium", (const char*)font_name, MIDDLE_FONT_DPI);
663 if (slp_roman_exist == EINA_FALSE) {
664 elm_config_font_overlay_set("tizen_roman", (const char*)font_name, MIDDLE_FONT_DPI);
666 if (slp_bold_exist == EINA_FALSE) {
667 elm_config_font_overlay_set("tizen_bold", (const char*)font_name, MIDDLE_FONT_DPI);
669 if (slp_regular_exist == EINA_FALSE) {
670 elm_config_font_overlay_set("tizen_regular", (const char*)font_name, MIDDLE_FONT_DPI);
674 if (tizen_exist == EINA_FALSE) {
675 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
678 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
681 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
683 EINA_LIST_FOREACH(text_classes, l, etc)
688 EINA_LIST_FOREACH(fo_list, ll, efo)
690 if (!strcmp(etc->name, efo->text_class)) {
694 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
697 elm_config_font_overlay_apply();
698 elm_config_all_flush();
699 // elm_config_engine_set("software_x11");
701 elm_config_text_classes_list_free(text_classes);
705 vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
708 static void __font_size_set()
710 Eina_List *text_classes = NULL;
711 Elm_Text_Class *etc = NULL;
712 const Eina_List *l = NULL;
713 int font_size = __font_size_get();
714 char *font_name = _get_cur_font();
716 if (font_size == -1) {
720 text_classes = elm_config_text_classes_list_get();
722 EINA_LIST_FOREACH(text_classes, l, etc)
724 elm_config_font_overlay_set(etc->name, font_name, font_size);
727 elm_config_font_overlay_apply();
728 elm_config_all_flush();
730 elm_config_text_classes_list_free(text_classes);
735 static int __font_size_get()
740 int vconf_value = -1;
741 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
745 switch(vconf_value) {
746 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
747 font_size = SMALL_FONT_DPI;
749 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
750 font_size = MIDDLE_FONT_DPI;
752 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
753 font_size = LARGE_FONT_DPI;
755 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
756 font_size = HUGE_FONT_DPI;
758 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
759 font_size = GIANT_FONT_DPI;
762 font_size = MIDDLE_FONT_DPI;