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