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