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