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();
57 int system_setting_get_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
60 if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, &vconf_value)) {
61 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
64 return SYSTEM_SETTINGS_ERROR_NONE;
68 int system_setting_get_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
71 if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, &vconf_value)) {
72 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
75 return SYSTEM_SETTINGS_ERROR_NONE;
79 int system_setting_get_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
82 if (system_setting_vconf_get_value_string(VCONFKEY_BGSET, &vconf_value)) {
83 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
86 return SYSTEM_SETTINGS_ERROR_NONE;
90 int system_setting_get_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
94 if (system_setting_vconf_get_value_string(VCONFKEY_IDLE_LOCK_BGSET, &vconf_value)) {
95 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
99 return SYSTEM_SETTINGS_ERROR_NONE;
104 int system_setting_get_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
108 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
109 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
111 *value = (void*)vconf_value;
113 return SYSTEM_SETTINGS_ERROR_NONE;
118 int system_setting_get_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
120 char* font_name = _get_cur_font();
121 *value = (void*)font_name;
123 return SYSTEM_SETTINGS_ERROR_NONE;
127 int system_setting_get_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
131 if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &vconf_value)) {
132 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
134 *value = (void*)vconf_value;
136 return SYSTEM_SETTINGS_ERROR_NONE;
139 int system_setting_get_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
143 if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &vconf_value)) {
144 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
146 *value = (void*)vconf_value;
148 return SYSTEM_SETTINGS_ERROR_NONE;
151 int system_setting_get_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
155 if (system_setting_vconf_get_value_bool(VCONFKEY_3G_ENABLE, &vconf_value)) {
156 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
158 *value = (void*)vconf_value;
160 return SYSTEM_SETTINGS_ERROR_NONE;
162 ////////////////////////////////////////////////////////////////////////////////////////////////////
164 int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
167 vconf_value = (char*)value;
168 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
169 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
172 return SYSTEM_SETTINGS_ERROR_NONE;
176 int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
179 vconf_value = (char*)value;
180 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, vconf_value)) {
181 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
184 return SYSTEM_SETTINGS_ERROR_NONE;
188 static int _is_file_accessible(const char * path)
190 int ret = access(path ,R_OK);
197 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
200 vconf_value = (char*)value;
202 // error handling here
203 if (_is_file_accessible(vconf_value) != 0)
204 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
206 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
207 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
210 return SYSTEM_SETTINGS_ERROR_NONE;
213 int system_setting_set_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
216 vconf_value = (char*)value;
218 // error handling here
219 if (_is_file_accessible(vconf_value) != 0)
220 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
222 if (system_setting_vconf_set_value_string(VCONFKEY_IDLE_LOCK_BGSET, vconf_value)) {
223 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
226 return SYSTEM_SETTINGS_ERROR_NONE;
229 int system_setting_set_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
233 vconf_value = (int*)value;
235 if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT) {
236 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
239 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, *vconf_value)) {
240 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
244 return SYSTEM_SETTINGS_ERROR_NONE;
249 void *font_conf_doc_parse(char *doc_name, char *font_name)
251 xmlDocPtr doc = NULL;
252 xmlNodePtr cur = NULL;
253 xmlNodePtr cur2 = NULL;
254 xmlNodePtr cur3 = NULL;
257 doc = xmlParseFile(doc_name);
259 cur = xmlDocGetRootElement(doc);
267 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
273 cur = cur->xmlChildrenNode;
275 Eina_Bool is_changed = EINA_FALSE;
278 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
280 cur2 = cur->xmlChildrenNode;
283 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
285 xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
286 /* if name is not 'family', break */
287 if (xmlStrcmp(name, (const xmlChar *)"family"))
296 cur3 = cur2->xmlChildrenNode;
299 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
301 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
302 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
303 //printf("after changed, string is: %s \n", key);
306 is_changed = EINA_TRUE;
313 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias")))
315 cur2 = cur->xmlChildrenNode;
318 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family")))
320 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
321 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
322 //printf("after changed, string is: %s\n", key);
325 is_changed = EINA_TRUE;
326 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer")))
328 cur3 = cur2->xmlChildrenNode;
331 if((!xmlStrcmp(cur3->name, (const xmlChar *)"family")))
333 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
334 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
337 is_changed = EINA_TRUE;
339 break; /* just set first element, so break */
359 int system_setting_set_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
361 char* font_name = NULL;
362 font_name = (char*)value;
364 font_config_set(font_name);
365 font_config_set_notification();
368 vconf_value = (char*)value;
369 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, vconf_value)) {
370 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
373 xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
375 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
380 return SYSTEM_SETTINGS_ERROR_NONE;
383 int system_setting_set_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
386 vconf_value = (bool*)value;
387 if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, *vconf_value)) {
388 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
390 return SYSTEM_SETTINGS_ERROR_NONE;
393 int system_setting_set_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
396 vconf_value = (bool*)value;
397 if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, *vconf_value)) {
398 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
400 return SYSTEM_SETTINGS_ERROR_NONE;
404 int system_setting_set_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
407 vconf_value = (bool*)value;
408 if (system_setting_vconf_set_value_bool(VCONFKEY_3G_ENABLE, *vconf_value)) {
409 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
411 return SYSTEM_SETTINGS_ERROR_NONE;
414 /////////////////////////////////////////////////////////////////////////////////////////////////
417 int system_setting_set_changed_callback_incoming_call_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
419 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0, user_data);
422 int system_setting_unset_changed_callback_incoming_call_ringtone(system_settings_key_e key)
424 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, 0);
427 int system_setting_set_changed_callback_email_alert_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
429 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, 0, user_data);
432 int system_setting_unset_changed_callback_email_alert_ringtone(system_settings_key_e key)
434 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, 0);
437 int system_setting_set_changed_callback_wallpaper_home_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
439 return system_setting_vconf_set_changed_cb(VCONFKEY_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, 0, user_data);
442 int system_setting_unset_changed_callback_wallpaper_home_screen(system_settings_key_e key)
444 return system_setting_vconf_unset_changed_cb(VCONFKEY_BGSET, 0);
447 int system_setting_set_changed_callback_wallpaper_lock_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
449 return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_BGSET,SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, 0, user_data);
452 int system_setting_unset_changed_callback_wallpaper_lock_screen(system_settings_key_e key)
454 return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, 0);
457 int system_setting_set_changed_callback_font_size(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
459 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE,SYSTEM_SETTINGS_KEY_FONT_SIZE, 1, user_data);
462 int system_setting_unset_changed_callback_font_size(system_settings_key_e key)
464 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, 1);
467 int system_setting_set_changed_callback_usb_debugging_option(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
469 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED, 1, user_data);
472 int system_setting_unset_changed_callback_usb_debugging_option(system_settings_key_e key)
474 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 1);
477 int system_setting_set_changed_callback_3g_data_network(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
479 return system_setting_vconf_set_changed_cb(VCONFKEY_3G_ENABLE,SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 1,user_data);
482 int system_setting_unset_changed_callback_3g_data_network(system_settings_key_e key)
484 return system_setting_vconf_unset_changed_cb(VCONFKEY_3G_ENABLE, 1);
489 * @todo need to add custom event notification method
491 int system_setting_set_changed_callback_font_type(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
493 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,SYSTEM_SETTINGS_KEY_FONT_TYPE, 2, user_data);
496 int system_setting_unset_changed_callback_font_type(system_settings_key_e key)
498 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,2);
501 // TODO : 2th argument, callback, is not in use.
502 int system_setting_set_changed_callback_motion_activation(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
504 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 3, user_data );
507 int system_setting_unset_changed_callback_motion_activation(system_settings_key_e key)
509 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, 3);
512 static char* _get_cur_font()
514 xmlDocPtr doc = NULL;
515 xmlNodePtr cur = NULL;
516 xmlNodePtr cur2 = NULL;
517 xmlNodePtr cur3 = NULL;
520 char *font_name = NULL;
522 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
524 cur = xmlDocGetRootElement(doc);
532 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
538 cur = cur->xmlChildrenNode;
542 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
544 cur2 = cur->xmlChildrenNode;
547 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
549 cur3 = cur2->xmlChildrenNode;
552 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
554 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
555 //printf("string is: %s\n", key);
557 font_name = g_strdup((char *)key);
578 static void font_config_set_notification()
581 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
582 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
583 ecore_x_window_prop_string_set(ecore_win, atom, "tizen");
586 static void font_config_set(char *font_name)
588 Eina_List *text_classes = NULL;
589 Elm_Text_Class *etc = NULL;
590 const Eina_List *l = NULL;
591 Eina_List *fo_list = NULL;
592 Elm_Font_Overlay *efo = NULL;
593 int font_size = __font_size_get();
596 text_classes = elm_config_text_classes_list_get();
598 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
600 Eina_List *ll = NULL;
601 Eina_List *l_next = NULL;
603 Eina_Bool slp_medium_exist = EINA_FALSE;
604 Eina_Bool slp_roman_exist = EINA_FALSE;
605 Eina_Bool slp_bold_exist = EINA_FALSE;
606 Eina_Bool slp_regular_exist = EINA_FALSE;
609 Eina_Bool tizen_exist = EINA_FALSE;
611 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
613 if (!strcmp(efo->text_class, "tizen_medium")) {
614 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
615 slp_medium_exist = EINA_TRUE;
616 } else if (!strcmp(efo->text_class, "tizen_roman")) {
617 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
618 slp_roman_exist = EINA_TRUE;
619 } else if (!strcmp(efo->text_class, "tizen_bold")) {
620 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
621 slp_bold_exist = EINA_TRUE;
622 } else if (!strcmp(efo->text_class, "tizen_regular")) {
623 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
624 slp_regular_exist = EINA_TRUE;
628 if (!strcmp(efo->text_class, "tizen")) {
629 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
630 tizen_exist = EINA_TRUE;
635 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
636 if (slp_medium_exist == EINA_FALSE) {
637 elm_config_font_overlay_set("tizen_medium", (const char*)font_name, MIDDLE_FONT_DPI);
639 if (slp_roman_exist == EINA_FALSE) {
640 elm_config_font_overlay_set("tizen_roman", (const char*)font_name, MIDDLE_FONT_DPI);
642 if (slp_bold_exist == EINA_FALSE) {
643 elm_config_font_overlay_set("tizen_bold", (const char*)font_name, MIDDLE_FONT_DPI);
645 if (slp_regular_exist == EINA_FALSE) {
646 elm_config_font_overlay_set("tizen_regular", (const char*)font_name, MIDDLE_FONT_DPI);
650 if (tizen_exist == EINA_FALSE) {
651 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
654 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
657 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
659 EINA_LIST_FOREACH(text_classes, l, etc)
664 EINA_LIST_FOREACH(fo_list, ll, efo)
666 if (!strcmp(etc->name, efo->text_class)) {
670 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
673 elm_config_font_overlay_apply();
674 elm_config_all_flush();
675 // elm_config_engine_set("software_x11");
677 elm_config_text_classes_list_free(text_classes);
681 vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
684 static void __font_size_set()
686 Eina_List *text_classes = NULL;
687 Elm_Text_Class *etc = NULL;
688 const Eina_List *l = NULL;
689 int font_size = __font_size_get();
690 char *font_name = _get_cur_font();
692 if (font_size == -1) {
696 text_classes = elm_config_text_classes_list_get();
698 EINA_LIST_FOREACH(text_classes, l, etc)
700 elm_config_font_overlay_set(etc->name, font_name, font_size);
703 elm_config_font_overlay_apply();
704 elm_config_all_flush();
706 elm_config_text_classes_list_free(text_classes);
711 static int __font_size_get()
716 int vconf_value = -1;
717 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
721 switch(vconf_value) {
722 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
723 font_size = SMALL_FONT_DPI;
725 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
726 font_size = MIDDLE_FONT_DPI;
728 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
729 font_size = LARGE_FONT_DPI;
731 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
732 font_size = HUGE_FONT_DPI;
734 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
735 font_size = GIANT_FONT_DPI;
738 font_size = MIDDLE_FONT_DPI;