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)
111 printf("system_setting_get_font_size \n");
114 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
115 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
117 *value = (void*)vconf_value;
119 return SYSTEM_SETTINGS_ERROR_NONE;
124 int system_setting_get_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
126 printf("system_setting_get_font_type\n");
129 char* font_name = _get_cur_font();
132 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_FONT_TYPE_INT, &vconf_value)) {
133 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
135 //*value = (void*)vconf_value;
137 *value = (void*)font_name;
139 return SYSTEM_SETTINGS_ERROR_NONE;
143 int system_setting_get_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
147 if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &vconf_value)) {
148 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
150 *value = (void*)vconf_value;
152 return SYSTEM_SETTINGS_ERROR_NONE;
155 ////////////////////////////////////////////////////////////////////////////////////////////////////
157 int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
159 printf(" mock --> real system_setting_set_incoming_call_ringtone \n");
161 vconf_value = (char*)value;
162 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
163 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
166 return SYSTEM_SETTINGS_ERROR_NONE;
170 int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
172 printf(" mock --> real system_setting_set_email_alert_ringtone \n");
174 vconf_value = (char*)value;
175 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, vconf_value)) {
176 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
179 return SYSTEM_SETTINGS_ERROR_NONE;
183 static int _is_file_accessible(const char * path)
185 int ret = access(path ,R_OK);
192 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
194 printf(" mock --> real system_setting_set_wallpaper_home_screen \n");
197 vconf_value = (char*)value;
199 // error handling here
200 if (_is_file_accessible(vconf_value) != 0)
201 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
203 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
204 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
207 return SYSTEM_SETTINGS_ERROR_NONE;
210 int system_setting_set_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
212 printf(" mock --> real system_setting_set_wallpaper_lock_screen \n");
215 vconf_value = (char*)value;
217 // error handling here
218 if (_is_file_accessible(vconf_value) != 0)
219 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
221 if (system_setting_vconf_set_value_string(VCONFKEY_IDLE_LOCK_BGSET, vconf_value)) {
222 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
225 return SYSTEM_SETTINGS_ERROR_NONE;
228 int system_setting_set_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
230 printf(" real system_setting_set_font_size \n");
232 vconf_value = (int*)value;
234 if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT) {
235 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
238 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, *vconf_value)) {
239 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
243 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. system_setting_set_font_size called \n");
245 return SYSTEM_SETTINGS_ERROR_NONE;
250 void *font_conf_doc_parse(char *doc_name, char *font_name)
252 //setting_retvm_if(doc_name == NULL, NULL, "Param data is NULL");
253 //setting_retvm_if(font_name == NULL, NULL, "Param data is NULL");
254 xmlDocPtr doc = NULL;
255 xmlNodePtr cur = NULL;
256 xmlNodePtr cur2 = NULL;
257 xmlNodePtr cur3 = NULL;
260 doc = xmlParseFile(doc_name);
261 //setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
263 cur = xmlDocGetRootElement(doc);
266 //SETTING_TRACE_DEBUG("empty document");
272 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
273 //SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
279 cur = cur->xmlChildrenNode;
281 Eina_Bool is_changed = EINA_FALSE;
284 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
286 cur2 = cur->xmlChildrenNode;
289 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
291 xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
292 //SETTING_TRACE_DEBUG("name is: %s", name);
293 /* if name is not 'family', break */
294 if (xmlStrcmp(name, (const xmlChar *)"family"))
303 cur3 = cur2->xmlChildrenNode;
306 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
308 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
309 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
310 //SETTING_TRACE_DEBUG("after changed, string is: %s", key);
313 is_changed = EINA_TRUE;
320 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias")))
322 cur2 = cur->xmlChildrenNode;
325 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family")))
327 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
328 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
329 //SETTING_TRACE_DEBUG("after changed, string is: %s", key);
332 is_changed = EINA_TRUE;
333 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer")))
335 cur3 = cur2->xmlChildrenNode;
338 if((!xmlStrcmp(cur3->name, (const xmlChar *)"family")))
340 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
341 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
342 //SETTING_TRACE_DEBUG("after changed, string is: %s", key);
345 is_changed = EINA_TRUE;
347 break; /* just set first element, so break */
367 int system_setting_set_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
369 printf(" real system_setting_set_font_type \n");
370 char* font_name = NULL;
371 font_name = (char*)value;
373 printf(">>>>>>>>>>>>> font name = %s \n", font_name);
375 font_config_set(font_name);
376 font_config_set_notification();
379 vconf_value = (char*)value;
380 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, vconf_value)) {
381 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
384 xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
386 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
389 printf(">>>>>>>>>>>>> SUCCESSED : saving font name = %s \n", font_name);
391 printf(">>>>>>>>>>>>> FAILED : saving font name = %s \n", font_name);
394 return SYSTEM_SETTINGS_ERROR_NONE;
397 int system_setting_set_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
399 printf(" mock --> real system_setting_set_motion_activation \n");
402 vconf_value = (bool*)value;
403 if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, *vconf_value)) {
404 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
406 return SYSTEM_SETTINGS_ERROR_NONE;
409 /////////////////////////////////////////////////////////////////////////////////////////////////
412 int system_setting_set_changed_callback_incoming_call_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
414 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0);
417 int system_setting_unset_changed_callback_incoming_call_ringtone(system_settings_key_e key)
419 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, 0);
422 int system_setting_set_changed_callback_email_alert_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
424 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, 0);
427 int system_setting_unset_changed_callback_email_alert_ringtone(system_settings_key_e key)
429 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, 0);
432 int system_setting_set_changed_callback_wallpaper_home_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
434 return system_setting_vconf_set_changed_cb(VCONFKEY_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, 0);
437 int system_setting_unset_changed_callback_wallpaper_home_screen(system_settings_key_e key)
439 return system_setting_vconf_unset_changed_cb(VCONFKEY_BGSET, 0);
442 int system_setting_set_changed_callback_wallpaper_lock_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
444 return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_BGSET,SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, 0);
447 int system_setting_unset_changed_callback_wallpaper_lock_screen(system_settings_key_e key)
449 return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, 0);
452 int system_setting_set_changed_callback_font_size(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
454 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE,SYSTEM_SETTINGS_KEY_FONT_SIZE, 1);
457 int system_setting_unset_changed_callback_font_size(system_settings_key_e key)
459 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, 1);
463 * @todo need to add custom event notification method
465 int system_setting_set_changed_callback_font_type(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
467 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,SYSTEM_SETTINGS_KEY_FONT_TYPE, 2);
470 int system_setting_unset_changed_callback_font_type(system_settings_key_e key)
472 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,2);
475 // TODO : 2th argument, callback, is not in use.
476 int system_setting_set_changed_callback_motion_activation(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
478 printf("system_setting_set_changed_callback_motion_activation \n");
479 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 3);
482 int system_setting_unset_changed_callback_motion_activation(system_settings_key_e key)
484 printf("system_setting_unset_changed_callback_motion_activation \n");
485 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, 3);
488 static char* _get_cur_font()
490 printf("get current font \n");
492 xmlDocPtr doc = NULL;
493 xmlNodePtr cur = NULL;
494 xmlNodePtr cur2 = NULL;
495 xmlNodePtr cur3 = NULL;
498 char *font_name = NULL;
500 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
502 cur = xmlDocGetRootElement(doc);
505 printf("empty document");
511 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
512 printf("document of the wrong type, root node != fontconfig");
518 cur = cur->xmlChildrenNode;
522 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
524 cur2 = cur->xmlChildrenNode;
527 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
529 cur3 = cur2->xmlChildrenNode;
532 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
534 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
535 //printf("string is: %s", key);
537 font_name = g_strdup((char *)key);
558 static void font_config_set_notification()
561 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
562 printf("FONT CHANGE NOTIFICATION >>>>>>>>>> : %d \n", (unsigned int)ecore_win);
563 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
564 ecore_x_window_prop_string_set(ecore_win, atom, "tizen");
567 static void font_config_set(char *font_name)
569 Eina_List *text_classes = NULL;
570 Elm_Text_Class *etc = NULL;
571 const Eina_List *l = NULL;
572 Eina_List *fo_list = NULL;
573 Elm_Font_Overlay *efo = NULL;
574 int font_size = __font_size_get();
577 text_classes = elm_config_text_classes_list_get();
579 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
581 Eina_List *ll = NULL;
582 Eina_List *l_next = NULL;
584 Eina_Bool slp_medium_exist = EINA_FALSE;
585 Eina_Bool slp_roman_exist = EINA_FALSE;
586 Eina_Bool slp_bold_exist = EINA_FALSE;
587 Eina_Bool slp_regular_exist = EINA_FALSE;
590 Eina_Bool tizen_exist = EINA_FALSE;
592 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
594 if (!strcmp(efo->text_class, "tizen_medium")) {
595 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
596 slp_medium_exist = EINA_TRUE;
597 } else if (!strcmp(efo->text_class, "tizen_roman")) {
598 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
599 slp_roman_exist = EINA_TRUE;
600 } else if (!strcmp(efo->text_class, "tizen_bold")) {
601 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
602 slp_bold_exist = EINA_TRUE;
603 } else if (!strcmp(efo->text_class, "tizen_regular")) {
604 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
605 slp_regular_exist = EINA_TRUE;
609 if (!strcmp(efo->text_class, "tizen")) {
610 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
611 tizen_exist = EINA_TRUE;
616 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
617 if (slp_medium_exist == EINA_FALSE) {
618 elm_config_font_overlay_set("tizen_medium", (const char*)font_name, MIDDLE_FONT_DPI);
620 if (slp_roman_exist == EINA_FALSE) {
621 elm_config_font_overlay_set("tizen_roman", (const char*)font_name, MIDDLE_FONT_DPI);
623 if (slp_bold_exist == EINA_FALSE) {
624 elm_config_font_overlay_set("tizen_bold", (const char*)font_name, MIDDLE_FONT_DPI);
626 if (slp_regular_exist == EINA_FALSE) {
627 elm_config_font_overlay_set("tizen_regular", (const char*)font_name, MIDDLE_FONT_DPI);
631 if (tizen_exist == EINA_FALSE) {
632 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
635 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
638 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
640 EINA_LIST_FOREACH(text_classes, l, etc)
645 EINA_LIST_FOREACH(fo_list, ll, efo)
647 if (!strcmp(etc->name, efo->text_class)) {
651 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
654 elm_config_font_overlay_apply();
655 elm_config_all_flush();
656 // elm_config_engine_set("software_x11");
658 elm_config_text_classes_list_free(text_classes);
662 vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
665 static void font_size_set()
667 Eina_List *text_classes = NULL;
668 Elm_Text_Class *etc = NULL;
669 const Eina_List *l = NULL;
670 int font_size = __font_size_get();
671 char *font_name = _get_cur_font();
673 if (font_size == -1) {
674 //SETTING_TRACE_DEBUG("failed to call font_size_get");
677 printf(">> font name = %s, font size = %d \n", font_name, font_size);
680 text_classes = elm_config_text_classes_list_get();
682 EINA_LIST_FOREACH(text_classes, l, etc)
684 elm_config_font_overlay_set(etc->name, font_name, font_size);
687 elm_config_font_overlay_apply();
688 elm_config_all_flush();
690 elm_config_text_classes_list_free(text_classes);
694 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. font_size_set called \n");
697 static int __font_size_get()
702 int vconf_value = -1;
703 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
707 switch(vconf_value) {
708 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
709 font_size = SMALL_FONT_DPI;
711 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
712 font_size = MIDDLE_FONT_DPI;
714 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
715 font_size = LARGE_FONT_DPI;
717 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
718 font_size = HUGE_FONT_DPI;
720 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
721 font_size = GIANT_FONT_DPI;
724 font_size = MIDDLE_FONT_DPI;