ef3843af5961aa633518cc96a5211c1635bd2c8f
[platform/core/api/system-settings.git] / src / system_setting_platform.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <errno.h>
21
22 #include <string.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26
27
28 #include <dlog.h>
29 #include <vconf.h>
30
31 #include <glib.h>
32 #include <libxml/xmlmemory.h>
33 #include <libxml/parser.h>
34
35 #ifdef USE_X11
36 #include <Ecore_X.h>
37 #endif
38 #ifdef USE_WAYLAND
39 #include <Ecore.h>
40 #include <Ecore_Wayland.h>
41 #endif
42
43 #include <Elementary.h>
44
45 #include <system_settings.h>
46 #include <system_settings_private.h>
47
48 #define SMALL_FONT_DPI                      (-80)
49 #define MIDDLE_FONT_DPI                     (-100)
50 #define LARGE_FONT_DPI                      (-150)
51 #define HUGE_FONT_DPI                       (-190)
52 #define GIANT_FONT_DPI                      (-250)
53
54 #define SETTING_FONT_CONF_FILE "/opt/etc/fonts/conf.avail/99-slp.conf"
55 #define SETTING_STR_SLP_LEN  256
56
57 static char* _get_cur_font();
58 static void __font_size_set();
59 static int __font_size_get();
60
61 static void font_config_set(char *font_name);
62 static void font_config_set_notification();
63
64 /**
65  * VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR has a path of the ringtone file which user choose
66  * @return the ringtone file path specified by user in normal case
67  *         if it's not accessable, return the default ringtone path
68  */
69 int system_setting_get_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
70 {
71         char* vconf_value;
72         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, &vconf_value)) {
73                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
74         }
75
76         // check to see if it's accessable -> OK
77         // no --> default ringtone path VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR
78         int is_load = _is_file_accessible(vconf_value);
79         if (is_load == 0) {
80                 *value = vconf_value;
81         } else { // not zero on errro
82                 //*value = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR);
83                 //*value = strdup("ERROR");
84                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
85         }
86
87         //*value = vconf_value;
88         return SYSTEM_SETTINGS_ERROR_NONE;
89 }
90
91
92 int system_setting_get_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
93 {
94         char* vconf_value;
95         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, &vconf_value)) {
96                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
97         }
98         *value = vconf_value;
99         return SYSTEM_SETTINGS_ERROR_NONE;
100 }
101
102
103 int system_setting_get_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
104 {
105         char* vconf_value;
106         if (system_setting_vconf_get_value_string(VCONFKEY_BGSET, &vconf_value)) {
107                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
108         }
109         *value = vconf_value;
110         return SYSTEM_SETTINGS_ERROR_NONE;
111 }
112
113
114 int system_setting_get_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
115 {
116         char* vconf_value;
117
118         if (system_setting_vconf_get_value_string(VCONFKEY_IDLE_LOCK_BGSET, &vconf_value)) {
119                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
120         }
121         *value = vconf_value;
122
123         return SYSTEM_SETTINGS_ERROR_NONE;
124 }
125
126
127 // [int] vconf GET
128 int system_setting_get_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
129 {
130         int vconf_value;
131
132         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
133                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
134         }
135         *value = (void*)vconf_value;
136
137         return SYSTEM_SETTINGS_ERROR_NONE;
138 }
139
140
141 // [int] vconf GET
142 int system_setting_get_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
143 {
144         char* font_name = _get_cur_font();
145         *value = (void*)font_name;
146
147         return SYSTEM_SETTINGS_ERROR_NONE;
148 }
149
150
151 int system_setting_get_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
152 {
153         bool vconf_value;
154
155         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &vconf_value)) {
156                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
157         }
158         *value = (void*)vconf_value;
159
160         return SYSTEM_SETTINGS_ERROR_NONE;
161 }
162
163 int system_setting_get_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
164 {
165         bool vconf_value;
166
167         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &vconf_value)) {
168                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
169         }
170         *value = (void*)vconf_value;
171
172         return SYSTEM_SETTINGS_ERROR_NONE;
173 }
174
175 int system_setting_get_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
176 {
177         bool vconf_value;
178
179         if (system_setting_vconf_get_value_bool(VCONFKEY_3G_ENABLE, &vconf_value)) {
180                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
181         }
182         *value = (void*)vconf_value;
183
184         return SYSTEM_SETTINGS_ERROR_NONE;
185 }
186 ////////////////////////////////////////////////////////////////////////////////////////////////////
187
188 int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
189 {
190         char* vconf_value;
191         vconf_value = (char*)value;
192
193         int is_load = _is_file_accessible(vconf_value);
194         if (is_load == 0)
195         {
196                 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
197                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
198                 }
199         } else {
200                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
201         }
202
203         return SYSTEM_SETTINGS_ERROR_NONE;
204 }
205
206
207 int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
208 {
209         char* vconf_value;
210         vconf_value = (char*)value;
211         if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, vconf_value)) {
212                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
213         }
214
215         return SYSTEM_SETTINGS_ERROR_NONE;
216 }
217
218
219 int _is_file_accessible(const char * path)
220 {
221     int ret = access(path ,R_OK);
222     if (ret == 0)
223         {
224                 SETTING_TRACE("found the file  %s", path);
225         return 0;
226         }
227     else
228         {
229         return errno;
230         }
231 }
232
233 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
234 {
235         char* vconf_value;
236         vconf_value = (char*)value;
237
238         // error handling here
239         if (_is_file_accessible(vconf_value) != 0)
240                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
241
242         if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
243                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
244         }
245
246         return SYSTEM_SETTINGS_ERROR_NONE;
247 }
248
249 int system_setting_set_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
250 {
251         char* vconf_value;
252         vconf_value = (char*)value;
253
254         // error handling here
255         if (_is_file_accessible(vconf_value) != 0)
256                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
257
258         if (system_setting_vconf_set_value_string(VCONFKEY_IDLE_LOCK_BGSET, vconf_value)) {
259                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
260         }
261
262         return SYSTEM_SETTINGS_ERROR_NONE;
263 }
264
265 int system_setting_set_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
266 {
267         SETTING_TRACE_BEGIN;
268         int* vconf_value;
269         vconf_value = (int*)value;
270
271         if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT) {
272                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
273         }
274
275         if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, *vconf_value)) {
276                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
277         }
278         __font_size_set();
279         SETTING_TRACE_END;
280         return SYSTEM_SETTINGS_ERROR_NONE;
281 }
282 /**
283  * [internal API]
284  */
285 void *font_conf_doc_parse(char *doc_name, char *font_name)
286 {
287     xmlDocPtr doc = NULL;
288     xmlNodePtr cur = NULL;
289     xmlNodePtr cur2 = NULL;
290     xmlNodePtr cur3 = NULL;
291     xmlChar *key = NULL;
292
293     doc = xmlParseFile(doc_name);
294
295     cur = xmlDocGetRootElement(doc);
296
297     if (cur == NULL) {
298         xmlFreeDoc(doc);
299         doc = NULL;
300         return NULL;
301     }
302
303     if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
304         xmlFreeDoc(doc);
305         doc = NULL;
306         return NULL;
307     }
308
309     cur = cur->xmlChildrenNode;
310
311     Eina_Bool is_changed = EINA_FALSE;
312     while(cur != NULL)
313     {
314         if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
315         {
316             cur2 = cur->xmlChildrenNode;
317             while(cur2 != NULL)
318             {
319                 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
320                 {
321                     xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
322                     /* if name is not 'family', break */
323                     if (xmlStrcmp(name, (const xmlChar *)"family"))
324                     {
325                         xmlFree(name);
326                         name = NULL;
327                         break;
328                     }
329                     xmlFree(name);
330                     name = NULL;
331
332                     cur3 = cur2->xmlChildrenNode;
333                    while(cur3 != NULL)
334                     {
335                         if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
336                         {
337                             xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
338                             key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
339                             xmlFree(key);
340                             key = NULL;
341                             is_changed = EINA_TRUE;
342                         }
343                         cur3 = cur3->next;
344                     }
345                 }
346                 cur2 = cur2->next;
347             }
348         } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias")))
349         {
350             cur2 = cur->xmlChildrenNode;
351             while (cur2 != NULL)
352             {
353                 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family")))
354                 {
355                     xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
356                     key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
357                     xmlFree(key);
358                     key = NULL;
359                     is_changed = EINA_TRUE;
360                 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer")))
361                 {
362                     cur3 = cur2->xmlChildrenNode;
363                     while (cur3 != NULL)
364                     {
365                         if((!xmlStrcmp(cur3->name, (const xmlChar *)"family")))
366                         {
367                             xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
368                             key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
369                             xmlFree(key);
370                             key = NULL;
371                             is_changed = EINA_TRUE;
372                             cur3 = cur3->next;
373                             break; /* just set first element, so break */
374                         }
375                         cur3 = cur3->next;
376                     }
377                 }
378                 cur2 = cur2->next;
379             }
380         }
381         cur = cur->next;
382     }
383
384     if (is_changed) {
385         return doc;
386     } else {
387         xmlFreeDoc(doc);
388         doc = NULL;
389         return NULL;
390     }
391 }
392
393 int system_setting_set_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
394 {
395         char* font_name = NULL;
396         font_name = (char*)value;
397
398         font_config_set(font_name);
399         font_config_set_notification();
400
401         char* vconf_value;
402         vconf_value = (char*)value;
403         if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, vconf_value)) {
404                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
405         }
406
407     xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
408     if(doc != NULL) {
409         xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
410         xmlFreeDoc(doc);
411         doc = NULL;
412     }
413
414         return SYSTEM_SETTINGS_ERROR_NONE;
415 }
416
417 int system_setting_set_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
418 {
419         bool* vconf_value;
420         vconf_value = (bool*)value;
421         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, *vconf_value)) {
422                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
423         }
424         return SYSTEM_SETTINGS_ERROR_NONE;
425 }
426
427 int system_setting_set_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
428 {
429         bool* vconf_value;
430         vconf_value = (bool*)value;
431         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, *vconf_value)) {
432                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
433         }
434         return SYSTEM_SETTINGS_ERROR_NONE;
435
436 }
437
438 int system_setting_set_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
439 {
440         bool* vconf_value;
441         vconf_value = (bool*)value;
442         if (system_setting_vconf_set_value_bool(VCONFKEY_3G_ENABLE, *vconf_value)) {
443                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
444         }
445         return SYSTEM_SETTINGS_ERROR_NONE;
446 }
447
448 /////////////////////////////////////////////////////////////////////////////////////////////////
449 //
450
451 int system_setting_set_changed_callback_incoming_call_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
452 {
453         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0, user_data);
454 }
455
456 int system_setting_unset_changed_callback_incoming_call_ringtone(system_settings_key_e key)
457 {
458         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, 0);
459 }
460
461 int system_setting_set_changed_callback_email_alert_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
462 {
463         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, 0, user_data);
464 }
465
466 int system_setting_unset_changed_callback_email_alert_ringtone(system_settings_key_e key)
467 {
468         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_EMAIL_RINGTONE_PATH_STR, 0);
469 }
470
471 int system_setting_set_changed_callback_wallpaper_home_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
472 {
473         return system_setting_vconf_set_changed_cb(VCONFKEY_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, 0, user_data);
474 }
475
476 int system_setting_unset_changed_callback_wallpaper_home_screen(system_settings_key_e key)
477 {
478         return system_setting_vconf_unset_changed_cb(VCONFKEY_BGSET, 0);
479 }
480
481 int system_setting_set_changed_callback_wallpaper_lock_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
482 {
483         return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_BGSET,SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, 0, user_data);
484 }
485
486 int system_setting_unset_changed_callback_wallpaper_lock_screen(system_settings_key_e key)
487 {
488         return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, 0);
489 }
490
491 int system_setting_set_changed_callback_font_size(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
492 {
493         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE,SYSTEM_SETTINGS_KEY_FONT_SIZE, 1, user_data);
494 }
495
496 int system_setting_unset_changed_callback_font_size(system_settings_key_e key)
497 {
498         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, 1);
499 }
500
501 int system_setting_set_changed_callback_usb_debugging_option(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
502 {
503         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED, 1, user_data);
504 }
505
506 int system_setting_unset_changed_callback_usb_debugging_option(system_settings_key_e key)
507 {
508         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 1);
509 }
510
511 int system_setting_set_changed_callback_3g_data_network(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
512 {
513         return system_setting_vconf_set_changed_cb(VCONFKEY_3G_ENABLE,SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 1,user_data);
514 }
515
516 int system_setting_unset_changed_callback_3g_data_network(system_settings_key_e key)
517 {
518         return system_setting_vconf_unset_changed_cb(VCONFKEY_3G_ENABLE, 1);
519 }
520
521
522 /**
523  * @todo need to add custom event notification method
524  */
525 int system_setting_set_changed_callback_font_type(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
526 {
527         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,SYSTEM_SETTINGS_KEY_FONT_TYPE, 2, user_data);
528 }
529
530 int system_setting_unset_changed_callback_font_type(system_settings_key_e key)
531 {
532         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,2);
533 }
534
535 // TODO : 2th argument, callback, is not in use.
536 int system_setting_set_changed_callback_motion_activation(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
537 {
538         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 3, user_data );
539 }
540
541 int system_setting_unset_changed_callback_motion_activation(system_settings_key_e key)
542 {
543         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, 3);
544 }
545
546 static char* _get_cur_font()
547 {
548     xmlDocPtr doc = NULL;
549     xmlNodePtr cur = NULL;
550     xmlNodePtr cur2 = NULL;
551     xmlNodePtr cur3 = NULL;
552     xmlChar *key = NULL;
553
554     char *font_name = NULL;
555
556     doc = xmlParseFile(SETTING_FONT_CONF_FILE);
557
558     cur = xmlDocGetRootElement(doc);
559
560     if(cur == NULL) {
561         xmlFreeDoc(doc);
562         doc = NULL;
563         return NULL;
564     }
565
566     if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
567         xmlFreeDoc(doc);
568         doc = NULL;
569         return NULL;
570     }
571
572     cur = cur->xmlChildrenNode;
573
574     while(cur != NULL)
575     {
576         if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
577         {
578             cur2 = cur->xmlChildrenNode;
579             while(cur2 != NULL)
580             {
581                 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
582                 {
583                     cur3 = cur2->xmlChildrenNode;
584                     while(cur3 != NULL)
585                     {
586                         if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
587                         {
588                             key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
589
590                             font_name = g_strdup((char *)key);
591                             xmlFree(key);
592                             key = NULL;
593                             xmlFreeDoc(doc);
594                             doc = NULL;
595                             return font_name;
596                         }
597                        cur3 = cur3->next;
598                     }
599                 }
600                 cur2 = cur2->next;
601             }
602         }
603         cur = cur->next;
604     }
605
606     xmlFreeDoc(doc);
607     doc = NULL;
608     return NULL;
609 }
610
611 static void font_config_set_notification()
612 {
613 #ifdef USE_X11
614     /* notification */
615     Ecore_X_Window ecore_xwin = ecore_x_window_root_first_get();
616     if (ecore_xwin != 0)         {
617     Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
618     ecore_x_window_prop_string_set(ecore_xwin, atom, "tizen");
619     }
620     else {
621 #endif
622 #ifdef USE_WAYLAND
623     //No font change notification on Wayland.(yet?)
624 #endif
625 #ifdef USE_X11
626     }
627 #endif
628 }
629
630 static void font_config_set(char *font_name)
631 {
632     Eina_List *text_classes = NULL;
633     Elm_Text_Class *etc = NULL;
634     const Eina_List *l = NULL;
635     Eina_List *fo_list = NULL;
636     Elm_Font_Overlay *efo = NULL;
637     int font_size = __font_size_get();
638     int size = 0;
639
640     text_classes = elm_config_text_classes_list_get();
641
642     fo_list = (Eina_List *)elm_config_font_overlay_list_get();
643
644     Eina_List *ll = NULL;
645     Eina_List *l_next = NULL;
646
647     Eina_Bool slp_medium_exist = EINA_FALSE;
648     Eina_Bool slp_roman_exist = EINA_FALSE;
649     Eina_Bool slp_bold_exist = EINA_FALSE;
650     Eina_Bool slp_regular_exist = EINA_FALSE;
651
652     // Tizen
653     Eina_Bool tizen_exist = EINA_FALSE;
654
655     EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
656     {
657         if (!strcmp(efo->text_class, "tizen_medium")) {
658             elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
659             slp_medium_exist = EINA_TRUE;
660         } else if (!strcmp(efo->text_class, "tizen_roman")) {
661             elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
662             slp_roman_exist = EINA_TRUE;
663         } else if (!strcmp(efo->text_class, "tizen_bold")) {
664             elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
665             slp_bold_exist = EINA_TRUE;
666         } else if (!strcmp(efo->text_class, "tizen_regular")) {
667             elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
668             slp_regular_exist = EINA_TRUE;
669         }
670
671         // Tizen
672         if (!strcmp(efo->text_class, "tizen")) {
673             elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
674             tizen_exist = EINA_TRUE;
675         }
676
677     }
678
679     /* if slp_XX do not exist, need to set them, font size is -100(100%) */
680     if (slp_medium_exist == EINA_FALSE) {
681         elm_config_font_overlay_set("tizen_medium", (const char*)font_name,  MIDDLE_FONT_DPI);
682     }
683     if (slp_roman_exist == EINA_FALSE) {
684         elm_config_font_overlay_set("tizen_roman", (const char*)font_name,  MIDDLE_FONT_DPI);
685     }
686     if (slp_bold_exist == EINA_FALSE) {
687         elm_config_font_overlay_set("tizen_bold", (const char*)font_name,  MIDDLE_FONT_DPI);
688     }
689     if (slp_regular_exist == EINA_FALSE) {
690         elm_config_font_overlay_set("tizen_regular", (const char*)font_name,  MIDDLE_FONT_DPI);
691     }
692
693     // Tizen
694     if (tizen_exist == EINA_FALSE) {
695         elm_config_font_overlay_set("tizen", (const char*)font_name,  MIDDLE_FONT_DPI);
696     }
697
698     elm_config_font_overlay_set("tizen", (const char*)font_name,  MIDDLE_FONT_DPI);
699
700     // Tizen
701     elm_config_font_overlay_set("tizen", (const char*)font_name,  MIDDLE_FONT_DPI);
702
703     EINA_LIST_FOREACH(text_classes, l, etc)
704     {
705         ll = NULL;
706
707         size = font_size;
708         EINA_LIST_FOREACH(fo_list, ll, efo)
709         {
710             if (!strcmp(etc->name, efo->text_class)) {
711                 size = efo->size;
712             }
713         }
714         elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
715     }
716
717     elm_config_font_overlay_apply();
718     elm_config_all_flush();
719 //    elm_config_engine_set("software_x11");
720     elm_config_save();
721     elm_config_text_classes_list_free(text_classes);
722     text_classes = NULL;
723
724     // vconf update
725     vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
726 }
727
728 static void __font_size_set()
729 {
730     Eina_List *text_classes = NULL;
731     Elm_Text_Class *etc = NULL;
732     const Eina_List *l = NULL;
733     int font_size = __font_size_get();
734     char *font_name = _get_cur_font();
735
736     if (font_size == -1) {
737         return;
738     }
739
740     text_classes = elm_config_text_classes_list_get();
741
742     EINA_LIST_FOREACH(text_classes, l, etc)
743     {
744         elm_config_font_overlay_set(etc->name, font_name, font_size);
745     }
746
747         elm_config_font_overlay_apply();
748     elm_config_all_flush();
749     elm_config_save();
750     elm_config_text_classes_list_free(text_classes);
751     text_classes = NULL;
752     g_free(font_name);
753 }
754
755 static int __font_size_get()
756 {
757     int font_size = -1;
758     int err = -1;
759
760         int vconf_value = -1;
761         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
762                 return -1;
763         }
764
765     switch(vconf_value) {
766     case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
767         font_size = SMALL_FONT_DPI;
768         break;
769     case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
770         font_size = MIDDLE_FONT_DPI;
771         break;
772     case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
773         font_size = LARGE_FONT_DPI;
774         break;
775     case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
776         font_size = HUGE_FONT_DPI;
777         break;
778     case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
779         font_size = GIANT_FONT_DPI;
780         break;
781     default:
782         font_size = MIDDLE_FONT_DPI;
783         break;
784     }
785     return font_size;
786 }