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_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
73 if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, &vconf_value)) {
74 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
77 return SYSTEM_SETTINGS_ERROR_NONE;
81 int system_setting_get_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
84 if (system_setting_vconf_get_value_string(VCONFKEY_BGSET, &vconf_value)) {
85 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
88 return SYSTEM_SETTINGS_ERROR_NONE;
92 int system_setting_get_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
96 if (system_setting_vconf_get_value_string(VCONFKEY_IDLE_LOCK_BGSET, &vconf_value)) {
97 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
101 return SYSTEM_SETTINGS_ERROR_NONE;
106 int system_setting_get_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
108 printf("system_setting_get_font_size \n");
111 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
112 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
114 *value = (void*)vconf_value;
116 return SYSTEM_SETTINGS_ERROR_NONE;
121 int system_setting_get_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
123 printf("system_setting_get_font_type\n");
126 char* font_name = _get_cur_font();
129 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_FONT_TYPE_INT, &vconf_value)) {
130 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
132 //*value = (void*)vconf_value;
134 *value = (void*)font_name;
136 return SYSTEM_SETTINGS_ERROR_NONE;
140 int system_setting_get_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
144 if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &vconf_value)) {
145 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
147 *value = (void*)vconf_value;
149 return SYSTEM_SETTINGS_ERROR_NONE;
152 ////////////////////////////////////////////////////////////////////////////////////////////////////
154 int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
156 printf(" mock --> real system_setting_set_incoming_call_ringtone \n");
158 vconf_value = (char*)value;
159 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
160 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
163 return SYSTEM_SETTINGS_ERROR_NONE;
167 int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
169 printf(" mock --> real system_setting_set_email_alert_ringtone \n");
171 vconf_value = (char*)value;
172 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, vconf_value)) {
173 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
176 return SYSTEM_SETTINGS_ERROR_NONE;
180 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
182 printf(" mock --> real system_setting_set_wallpaper_home_screen \n");
185 vconf_value = (char*)value;
186 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
187 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
190 return SYSTEM_SETTINGS_ERROR_NONE;
193 int system_setting_set_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
195 printf(" mock --> real system_setting_set_wallpaper_lock_screen \n");
198 vconf_value = (char*)value;
199 if (system_setting_vconf_set_value_string(VCONFKEY_IDLE_LOCK_BGSET, vconf_value)) {
200 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
203 return SYSTEM_SETTINGS_ERROR_NONE;
206 int system_setting_set_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
208 printf(" real system_setting_set_font_size \n");
210 vconf_value = (int*)value;
212 if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT) {
213 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
216 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, *vconf_value)) {
217 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
221 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. system_setting_set_font_size called \n");
223 return SYSTEM_SETTINGS_ERROR_NONE;
228 void *font_conf_doc_parse(char *doc_name, char *font_name)
230 //setting_retvm_if(doc_name == NULL, NULL, "Param data is NULL");
231 //setting_retvm_if(font_name == NULL, NULL, "Param data is NULL");
232 xmlDocPtr doc = NULL;
233 xmlNodePtr cur = NULL;
234 xmlNodePtr cur2 = NULL;
235 xmlNodePtr cur3 = NULL;
238 doc = xmlParseFile(doc_name);
239 //setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
241 cur = xmlDocGetRootElement(doc);
244 //SETTING_TRACE_DEBUG("empty document");
250 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
251 //SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
257 cur = cur->xmlChildrenNode;
259 Eina_Bool is_changed = EINA_FALSE;
262 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
264 cur2 = cur->xmlChildrenNode;
267 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
269 xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
270 //SETTING_TRACE_DEBUG("name is: %s", name);
271 /* if name is not 'family', break */
272 if (xmlStrcmp(name, (const xmlChar *)"family"))
281 cur3 = cur2->xmlChildrenNode;
284 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
286 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
287 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
288 //SETTING_TRACE_DEBUG("after changed, string is: %s", key);
291 is_changed = EINA_TRUE;
298 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias")))
300 cur2 = cur->xmlChildrenNode;
303 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family")))
305 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
306 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
307 //SETTING_TRACE_DEBUG("after changed, string is: %s", key);
310 is_changed = EINA_TRUE;
311 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer")))
313 cur3 = cur2->xmlChildrenNode;
316 if((!xmlStrcmp(cur3->name, (const xmlChar *)"family")))
318 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
319 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
320 //SETTING_TRACE_DEBUG("after changed, string is: %s", key);
323 is_changed = EINA_TRUE;
325 break; /* just set first element, so break */
345 int system_setting_set_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
347 printf(" real system_setting_set_font_type \n");
348 char* font_name = NULL;
349 font_name = (char*)value;
351 printf(">>>>>>>>>>>>> font name = %s \n", font_name);
353 font_config_set(font_name);
354 font_config_set_notification();
357 vconf_value = (char*)value;
358 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, vconf_value)) {
359 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
362 xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
364 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
367 printf(">>>>>>>>>>>>> SUCCESSED : saving font name = %s \n", font_name);
369 printf(">>>>>>>>>>>>> FAILED : saving font name = %s \n", font_name);
372 return SYSTEM_SETTINGS_ERROR_NONE;
375 int system_setting_set_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
377 printf(" mock --> real system_setting_set_motion_activation \n");
380 vconf_value = (bool*)value;
381 if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, *vconf_value)) {
382 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
384 return SYSTEM_SETTINGS_ERROR_NONE;
387 /////////////////////////////////////////////////////////////////////////////////////////////////
390 int system_setting_set_changed_callback_incoming_call_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
392 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0);
395 int system_setting_unset_changed_callback_incoming_call_ringtone(system_settings_key_e key)
397 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, 0);
400 int system_setting_set_changed_callback_email_alert_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
402 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, 0);
405 int system_setting_unset_changed_callback_email_alert_ringtone(system_settings_key_e key)
407 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, 0);
410 int system_setting_set_changed_callback_wallpaper_home_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
412 return system_setting_vconf_set_changed_cb(VCONFKEY_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, 0);
415 int system_setting_unset_changed_callback_wallpaper_home_screen(system_settings_key_e key)
417 return system_setting_vconf_unset_changed_cb(VCONFKEY_BGSET, 0);
420 int system_setting_set_changed_callback_wallpaper_lock_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
422 return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_BGSET,SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, 0);
425 int system_setting_unset_changed_callback_wallpaper_lock_screen(system_settings_key_e key)
427 return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, 0);
430 int system_setting_set_changed_callback_font_size(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
432 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE,SYSTEM_SETTINGS_KEY_FONT_SIZE, 1);
435 int system_setting_unset_changed_callback_font_size(system_settings_key_e key)
437 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, 1);
441 * @todo need to add custom event notification method
443 int system_setting_set_changed_callback_font_type(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
445 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,SYSTEM_SETTINGS_KEY_FONT_TYPE, 2);
448 int system_setting_unset_changed_callback_font_type(system_settings_key_e key)
450 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,2);
453 // TODO : 2th argument, callback, is not in use.
454 int system_setting_set_changed_callback_motion_activation(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
456 printf("system_setting_set_changed_callback_motion_activation \n");
457 return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 3);
460 int system_setting_unset_changed_callback_motion_activation(system_settings_key_e key)
462 printf("system_setting_unset_changed_callback_motion_activation \n");
463 return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, 3);
466 static char* _get_cur_font()
468 printf("get current font \n");
470 xmlDocPtr doc = NULL;
471 xmlNodePtr cur = NULL;
472 xmlNodePtr cur2 = NULL;
473 xmlNodePtr cur3 = NULL;
476 char *font_name = NULL;
478 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
480 cur = xmlDocGetRootElement(doc);
483 printf("empty document");
489 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
490 printf("document of the wrong type, root node != fontconfig");
496 cur = cur->xmlChildrenNode;
500 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
502 cur2 = cur->xmlChildrenNode;
505 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
507 cur3 = cur2->xmlChildrenNode;
510 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
512 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
513 //printf("string is: %s", key);
515 font_name = g_strdup((char *)key);
536 static void font_config_set_notification()
539 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
540 printf("FONT CHANGE NOTIFICATION >>>>>>>>>> : %d \n", (unsigned int)ecore_win);
541 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
542 ecore_x_window_prop_string_set(ecore_win, atom, "tizen");
545 static void font_config_set(char *font_name)
547 Eina_List *text_classes = NULL;
548 Elm_Text_Class *etc = NULL;
549 const Eina_List *l = NULL;
550 Eina_List *fo_list = NULL;
551 Elm_Font_Overlay *efo = NULL;
552 int font_size = __font_size_get();
555 text_classes = elm_config_text_classes_list_get();
557 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
559 Eina_List *ll = NULL;
560 Eina_List *l_next = NULL;
562 Eina_Bool slp_medium_exist = EINA_FALSE;
563 Eina_Bool slp_roman_exist = EINA_FALSE;
564 Eina_Bool slp_bold_exist = EINA_FALSE;
565 Eina_Bool slp_regular_exist = EINA_FALSE;
568 Eina_Bool tizen_exist = EINA_FALSE;
570 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
572 if (!strcmp(efo->text_class, "tizen_medium")) {
573 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
574 slp_medium_exist = EINA_TRUE;
575 } else if (!strcmp(efo->text_class, "tizen_roman")) {
576 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
577 slp_roman_exist = EINA_TRUE;
578 } else if (!strcmp(efo->text_class, "tizen_bold")) {
579 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
580 slp_bold_exist = EINA_TRUE;
581 } else if (!strcmp(efo->text_class, "tizen_regular")) {
582 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
583 slp_regular_exist = EINA_TRUE;
587 if (!strcmp(efo->text_class, "tizen")) {
588 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
589 tizen_exist = EINA_TRUE;
594 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
595 if (slp_medium_exist == EINA_FALSE) {
596 elm_config_font_overlay_set("tizen_medium", (const char*)font_name, MIDDLE_FONT_DPI);
598 if (slp_roman_exist == EINA_FALSE) {
599 elm_config_font_overlay_set("tizen_roman", (const char*)font_name, MIDDLE_FONT_DPI);
601 if (slp_bold_exist == EINA_FALSE) {
602 elm_config_font_overlay_set("tizen_bold", (const char*)font_name, MIDDLE_FONT_DPI);
604 if (slp_regular_exist == EINA_FALSE) {
605 elm_config_font_overlay_set("tizen_regular", (const char*)font_name, MIDDLE_FONT_DPI);
609 if (tizen_exist == EINA_FALSE) {
610 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
613 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
616 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
618 EINA_LIST_FOREACH(text_classes, l, etc)
623 EINA_LIST_FOREACH(fo_list, ll, efo)
625 if (!strcmp(etc->name, efo->text_class)) {
629 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
632 elm_config_font_overlay_apply();
633 elm_config_all_flush();
634 // elm_config_engine_set("software_x11");
636 elm_config_text_classes_list_free(text_classes);
640 vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
643 static void font_size_set()
645 Eina_List *text_classes = NULL;
646 Elm_Text_Class *etc = NULL;
647 const Eina_List *l = NULL;
648 int font_size = __font_size_get();
649 char *font_name = _get_cur_font();
651 if (font_size == -1) {
652 //SETTING_TRACE_DEBUG("failed to call font_size_get");
655 printf(">> font name = %s, font size = %d \n", font_name, font_size);
658 text_classes = elm_config_text_classes_list_get();
660 EINA_LIST_FOREACH(text_classes, l, etc)
662 elm_config_font_overlay_set(etc->name, font_name, font_size);
665 elm_config_font_overlay_apply();
666 elm_config_all_flush();
668 elm_config_text_classes_list_free(text_classes);
672 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. font_size_set called \n");
675 static int __font_size_get()
680 int vconf_value = -1;
681 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
685 switch(vconf_value) {
686 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
687 font_size = SMALL_FONT_DPI;
689 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
690 font_size = MIDDLE_FONT_DPI;
692 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
693 font_size = LARGE_FONT_DPI;
695 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
696 font_size = HUGE_FONT_DPI;
698 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
699 font_size = GIANT_FONT_DPI;
702 font_size = MIDDLE_FONT_DPI;