change tzpath link for timezone handling
[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 #include <time.h>
22
23 #include <string.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27
28 #include <regex.h>
29
30 #include <dlog.h>
31 #include <vconf.h>
32
33 #include <glib.h>
34 #include <libxml/xmlmemory.h>
35 #include <libxml/parser.h>
36
37 #include <fontconfig/fontconfig.h>
38
39
40 #include <Elementary.h>
41 #include <Evas.h>
42 #include <Ecore_Evas.h>
43
44 #include <system_settings.h>
45 #include <system_settings_private.h>
46
47 #ifdef USE_EFL_ASSIST
48 #include <efl_assist.h>
49 #endif
50
51 #ifdef TIZEN_WEARABLE
52 #define SMALL_FONT_DPI                      (-90)
53 #endif
54 #ifdef TIZEN_MOBILE
55 #define SMALL_FONT_DPI                      (-80)
56 #endif
57 #define MIDDLE_FONT_DPI                     (-100)
58 #ifdef TIZEN_WEARABLE
59 #define LARGE_FONT_DPI                      (-110)
60 #endif
61 #ifdef TIZEN_MOBILE
62 #define LARGE_FONT_DPI                      (-150)
63 #endif
64 #define HUGE_FONT_DPI                       (-190)
65 #define GIANT_FONT_DPI                      (-250)
66
67 #define SETTING_FONT_PRELOAD_FONT_PATH "/usr/share/fonts"
68 #define SETTING_FONT_DOWNLOADED_FONT_PATH "/opt/share/fonts"
69
70 #define SETTING_FONT_CONF_FILE "/opt/etc/fonts/conf.avail/99-slp.conf"
71 #define SETTING_DEFAULT_FONT_CONF_FILE "/usr/opt/etc/fonts/conf.avail/99-slp.conf"
72
73 #define SETTING_STR_LEN  256
74
75 #define SETTING_TIME_ZONEINFO_PATH              "/usr/share/zoneinfo/"
76 #define SETTING_TIME_SHARE_LOCAL_PATH   "/usr/share/locale"
77 #define SETTING_TZONE_SYMLINK_PATH              "/etc/localtime"
78
79
80 static char *_get_cur_font();
81 static void __font_size_set();
82 static int __font_size_get();
83 static char *_get_default_font();
84
85 static bool font_config_set(char *font_name);
86 static void font_config_set_notification();
87
88 /**
89  * VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR has a path of the ringtone file which user choose
90  * @return the ringtone file path specified by user in normal case
91  *         if it's not accessable, return the default ringtone path
92  */
93 int system_setting_get_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
94 {
95         SETTING_TRACE_BEGIN;
96         char *vconf_value;
97         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, &vconf_value)) {
98                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
99         }
100
101         /* check to see if it's accessable -> OK */
102         /* no --> default ringtone path VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR */
103         int is_load = _is_file_accessible(vconf_value);
104         if (is_load == 0) {
105                 *value = vconf_value;
106         } else { /* not zero on errro */
107                 *value = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR);
108         }
109
110         /**value = vconf_value; */
111         return SYSTEM_SETTINGS_ERROR_NONE;
112 }
113
114
115 int system_setting_get_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
116 {
117         SETTING_TRACE_BEGIN;
118         char *vconf_value;
119         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, &vconf_value)) {
120                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
121         }
122
123         /* check to see if it's accessable -> OK */
124         /* no --> default ringtone path VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR */
125         int is_load = _is_file_accessible(vconf_value);
126         if (is_load == 0) {
127                 *value = vconf_value;
128         } else { /* not zero on errro */
129                 *value = vconf_get_str(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR);
130         }
131
132         return SYSTEM_SETTINGS_ERROR_NONE;
133 }
134
135
136 int system_setting_get_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
137 {
138         SETTING_TRACE_BEGIN;
139         char *vconf_value;
140         if (system_setting_vconf_get_value_string(VCONFKEY_BGSET, &vconf_value)) {
141                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
142         }
143         *value = vconf_value;
144         return SYSTEM_SETTINGS_ERROR_NONE;
145 }
146
147
148 int system_setting_get_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
149 {
150         SETTING_TRACE_BEGIN;
151         char *vconf_value;
152
153         if (system_setting_vconf_get_value_string(VCONFKEY_IDLE_LOCK_BGSET, &vconf_value)) {
154                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
155         }
156         *value = vconf_value;
157
158         return SYSTEM_SETTINGS_ERROR_NONE;
159 }
160
161
162 /* [int] vconf GET */
163 int system_setting_get_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
164 {
165         SETTING_TRACE_BEGIN;
166         int vconf_value;
167
168         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
169                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
170         }
171         *value = (void *)vconf_value;
172
173         return SYSTEM_SETTINGS_ERROR_NONE;
174 }
175
176
177 int system_setting_get_default_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
178 {
179         SETTING_TRACE_BEGIN;
180         char *font_name = _get_default_font();
181         if (font_name) {
182                 *value = (void *)font_name;
183                 return SYSTEM_SETTINGS_ERROR_NONE;
184         } else {
185                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
186         }
187 }
188
189 /* [int] vconf GET */
190 int system_setting_get_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
191 {
192         SETTING_TRACE_BEGIN;
193         char *font_name = _get_cur_font();
194         *value = (void *)font_name;
195
196         return SYSTEM_SETTINGS_ERROR_NONE;
197 }
198
199
200 int system_setting_get_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
201 {
202         SETTING_TRACE_BEGIN;
203         bool vconf_value;
204
205         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &vconf_value)) {
206                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
207         }
208         *value = (void *)vconf_value;
209
210         return SYSTEM_SETTINGS_ERROR_NONE;
211 }
212
213 int system_setting_get_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
214 {
215         SETTING_TRACE_BEGIN;
216         bool vconf_value;
217
218         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &vconf_value)) {
219                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
220         }
221         *value = (void *)vconf_value;
222
223         return SYSTEM_SETTINGS_ERROR_NONE;
224 }
225
226 int system_setting_get_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
227 {
228         SETTING_TRACE_BEGIN;
229         bool vconf_value;
230
231         if (system_setting_vconf_get_value_bool(VCONFKEY_3G_ENABLE, &vconf_value)) {
232                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
233         }
234         *value = (void *)vconf_value;
235
236         return SYSTEM_SETTINGS_ERROR_NONE;
237 }
238 /*////////////////////////////////////////////////////////////////////////////////////////////////// */
239
240
241 /**
242  * get current lock scren app package name (string)
243  *
244  * @return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE raise exception if current lock type is 'password'
245  */
246 int system_setting_get_lockscreen_app(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
247 {
248         SETTING_TRACE_BEGIN;
249         char *pkg_name = NULL;
250         int locktype = -1;
251         system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype);
252
253         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, &pkg_name)) {
254                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
255         }
256
257         if (pkg_name && strcmp(pkg_name, "com.samsung.lockscreen") == 0 && locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD) {
258                 return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE;
259         }
260
261         *value = pkg_name;
262         return SYSTEM_SETTINGS_ERROR_NONE;
263 }
264
265
266 /*////////////////////////////////////////////////////////////////////////////////////////////////// */
267
268 int _is_file_accessible(const char *path)
269 {
270         SETTING_TRACE_BEGIN;
271         int ret = access(path , R_OK);
272         if (ret == 0) {
273                 SETTING_TRACE("found the file  %s", path);
274                 return 0;
275         } else {
276                 // error code : 13
277                 SETTING_TRACE("found the file  %s --- error code : %d ", path, errno);
278                         return -errno;
279         }
280 }
281
282 int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
283 {
284         SETTING_TRACE_BEGIN;
285         char *vconf_value;
286         vconf_value = (char *)value;
287
288         int ret = _is_file_accessible(vconf_value);
289         if (ret == 0) {
290                 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
291                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
292                 }
293         } else {
294                 /* @todo add a common ret_handler */
295                 return ret;
296         }
297
298         return SYSTEM_SETTINGS_ERROR_NONE;
299 }
300
301
302 int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
303 {
304         SETTING_TRACE_BEGIN;
305         char *vconf_value;
306         vconf_value = (char *)value;
307
308         int ret = _is_file_accessible(vconf_value);
309         if (ret == 0) {
310                 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, vconf_value)) {
311                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
312                 }
313         } else {
314                 /*return SYSTEM_SETTINGS_ERROR_IO_ERROR;*/
315                 /* @todo add a common ret_handler */
316                 return ret;
317         }
318
319         return SYSTEM_SETTINGS_ERROR_NONE;
320 }
321
322
323 bool __is_supported_image_type_load(char *path)
324 {
325         SETTING_TRACE_BEGIN;
326         evas_init();
327         Ecore_Evas  *ee;
328         Evas        *evas;
329
330         ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
331         evas = ecore_evas_get(ee);
332
333         Evas_Object *img = evas_object_image_add(evas);
334         evas_object_image_file_set(img, path, NULL);
335         Evas_Load_Error ret = evas_object_image_load_error_get(img);
336
337         bool result = false;
338         if (ret == EVAS_LOAD_ERROR_NONE) {
339                 SETTING_TRACE("%s - OK", path);
340                 result = true;
341         } else {
342                 SETTING_TRACE("%s - NO", path);
343                 result = false;
344         }
345         ecore_evas_free(ee);
346         evas_shutdown();
347         return result;
348 }
349
350 bool __is_supported_image_type(char *path)
351 {
352         SETTING_TRACE_BEGIN;
353         bool ret = false;
354
355         evas_init();
356         if (evas_object_image_extension_can_load_get(path))
357                 ret = true;
358         else
359                 ret = false;
360
361         evas_shutdown();
362
363         return ret;
364 }
365
366 #define PATH_EXT_CHECK_REG ".(jpe?g|jpg|png|gif)$"
367 bool __is_supported_image_type_by_ext(char *file_path)
368 {
369         SETTING_TRACE_BEGIN;
370         regex_t fsm;
371         regmatch_t str[2048 + 1];
372
373         if (!file_path) return false;
374
375         int ret = false;
376         if (ret = regcomp(&fsm, PATH_EXT_CHECK_REG, REG_ICASE | REG_EXTENDED)) {
377                 SETTING_TRACE("regular expresstion fail");
378                 return 1;
379         }
380
381         /* code */
382         if (regexec(&fsm, file_path, strlen(file_path) + 1, str, 0) == REG_NOMATCH) {
383                 /*SETTING_TRACE("FAILED - %s", file_path[i]); */
384                 ret = 0;
385         } else {
386                 /*SETTING_TRACE("MATCHED - %s", file_path[i]); */
387                 ret = 1;
388         }
389         return ret;
390 }
391 #ifdef TIZEN_WEARABLE
392 static int system_setting_get_extended_wallpaper_num(const char *file_path, unsigned int *num)
393 {
394         SETTING_TRACE_BEGIN;
395         char buffer[256];
396         const char *find_str = "extended_wallpaper_";
397         char *ch = NULL;
398
399         if (!(ch = strstr(file_path, find_str))) {
400                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
401         }
402         strncpy(buffer, file_path, ch - file_path);
403         buffer[ch - file_path] = 0;
404         sprintf(buffer + (ch - file_path), "%s%s", "", ch + strlen(find_str));
405
406         if (!isdigit(buffer[0])) {
407                 SETTING_TRACE("%s is not number", buffer);
408                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
409         }
410
411         *num = atoi(buffer);
412
413         return SYSTEM_SETTINGS_ERROR_NONE;
414 }
415
416 static int system_setting_copy_extended_wallpaper(const char *dest_file_path, const char *source_file_path)
417 {
418         SETTING_TRACE_BEGIN;
419         if (!source_file_path || !dest_file_path) {
420                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
421         }
422
423         char buf[1024];
424
425         int fd;
426         fd = open(source_file_path, O_RDONLY);
427         if (fd < 0) {
428                 SETTING_TRACE("file open failed: %s", source_file_path);
429                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
430         }
431
432         int fd2;
433         fd2 = open(dest_file_path, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
434         if (fd2 < 0) {
435                 SETTING_TRACE("file creation failed: %s", dest_file_path);
436                 close(fd);
437                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
438         }
439
440         while (read(fd, buf, sizeof(buf) - 1) > 0) {
441                 write(fd2, buf, sizeof(buf) - 1);
442         }
443
444         close(fd2);
445         close(fd);
446
447         if (chmod(dest_file_path, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
448                 SETTING_TRACE("chmod failed: %s", dest_file_path);
449         }
450
451         return SYSTEM_SETTINGS_ERROR_NONE;
452 }
453
454 static int system_setting_remove_oldest_extended_wallpaper()
455 {
456         SETTING_TRACE_BEGIN;
457         DIR *dp;
458         struct dirent *dirp;
459         char *min_image_name = NULL;
460         unsigned int min_image_num = 0;
461         unsigned int temp_image_num = 0;
462         int image_count = 0;
463
464         if ((dp = opendir("/opt/usr/data/setting/wallpaper")) == NULL) {
465                 SETTING_TRACE("opendir error");
466                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
467         }
468
469         while ((dirp = readdir(dp))) {
470                 if (!strcmp(dirp->d_name, ".") || !strcmp(dirp->d_name, ".."))
471                         continue;
472
473                 if (system_setting_get_extended_wallpaper_num(dirp->d_name, &temp_image_num)
474                     != SYSTEM_SETTINGS_ERROR_NONE) {
475                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
476                 }
477
478                 if ((image_count == 0) || (min_image_num > temp_image_num)) {
479                         min_image_num = temp_image_num;
480                         min_image_name = dirp->d_name;
481                 }
482
483                 image_count++;
484         }
485
486         char buf[512];
487         if (min_image_name) {
488                 snprintf(buf, sizeof(buf) - 1, "/opt/usr/data/setting/wallpaper/%s", min_image_name);
489                 if (remove(buf) < 0) {  /* remove oldest image */
490                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
491                 }
492         }
493
494         return SYSTEM_SETTINGS_ERROR_NONE;
495 }
496
497 static int system_setting_check_extended_wallpaper(const char *file_path)
498 {
499         SETTING_TRACE_BEGIN;
500         if (!file_path || !strlen(file_path))
501                 return 0;
502         return (strstr(file_path, "/opt/usr/media/.bgwallpaper") != NULL);
503 }
504
505 #define WALLPAPER_MAX_COUNT             10
506 #endif
507
508 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
509 {
510         SETTING_TRACE_BEGIN;
511         char *vconf_value;
512         vconf_value = (char *)value;
513
514         bool isok  = __is_supported_image_type_load(vconf_value);
515         if (!isok) {
516                 /* not supported */
517                 SETTING_TRACE("path : %s is not supported file format", vconf_value);
518                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
519         } else {
520                 SETTING_TRACE("path : %s is SUPPORT file format", vconf_value);
521         }
522
523         /* error handling here */
524         if (_is_file_accessible(vconf_value) != 0)
525                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
526 #ifdef TIZEN_MOBILE
527         if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
528                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
529         }
530 #endif
531
532 #ifdef TIZEN_WEARABLE
533         if (system_setting_check_extended_wallpaper(vconf_value)) {     /* New extended wallpaper */
534                 DIR *dp;
535                 struct dirent *dirp;
536                 unsigned int max_image_num = 0;
537                 unsigned int temp_image_num = 0;
538                 int image_count = 0;
539
540                 if ((dp = opendir("/opt/usr/data/setting/wallpaper")) == NULL) {
541                         SETTING_TRACE("Setting - dir open error!");
542                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
543                 }
544
545                 /* Check a max number of wallpapers */
546                 while ((dirp = readdir(dp))) {
547                         if (!strcmp(dirp->d_name, ".") || !strcmp(dirp->d_name, ".."))
548                                 continue;
549
550                         if (system_setting_get_extended_wallpaper_num(dirp->d_name, &temp_image_num)
551                             != SYSTEM_SETTINGS_ERROR_NONE) {
552                                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
553                         }
554
555                         if ((image_count == 0) || (max_image_num < temp_image_num)) {
556                                 max_image_num = temp_image_num;
557                         }
558
559                         image_count++;
560                 }
561
562                 /* Numbering rule: Gear is odd number */
563                 max_image_num = (max_image_num % 2 == 0) ? max_image_num + 1
564                                 : max_image_num + 2;
565
566                 char file_name_buffer[512];
567                 snprintf(file_name_buffer, sizeof(file_name_buffer) - 1,
568                          "/opt/usr/data/setting/wallpaper/extended_wallpaper_%d.jpg", max_image_num);
569
570                 /* Copy image to /opt/usr/data/setting/wallpaper/ */
571                 if (system_setting_copy_extended_wallpaper(file_name_buffer, vconf_value)
572                     != SYSTEM_SETTINGS_ERROR_NONE) {
573                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
574                 }
575
576                 /* remove oldest wallpaper */
577                 if (image_count >= WALLPAPER_MAX_COUNT) {
578                         if (system_setting_remove_oldest_extended_wallpaper()
579                             != SYSTEM_SETTINGS_ERROR_NONE) {
580                                 remove(file_name_buffer);
581                                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
582                         }
583                 }
584
585                 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, file_name_buffer)) {
586                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
587                 }
588
589                 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_WALLPAPER_CHANGED_NOTI_INT,
590                                                        VCONFKEY_WALLPAPER_CHANGED_NOTI_GEAR)) {
591                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
592                 }
593         } else {
594                 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
595                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
596                 }
597         }
598 #endif
599
600         return SYSTEM_SETTINGS_ERROR_NONE;
601 }
602
603 int system_setting_set_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
604 {
605         char *vconf_value;
606         vconf_value = (char *)value;
607
608         bool isok  = __is_supported_image_type_load(vconf_value);
609         if (!isok) {
610                 /* not supported */
611                 SETTING_TRACE("path : %s is not supported file format", vconf_value);
612                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
613         } else {
614                 SETTING_TRACE("path : %s is SUPPORT file format", vconf_value);
615         }
616
617         /* error handling here */
618         if (_is_file_accessible(vconf_value) != 0)
619                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
620
621         if (system_setting_vconf_set_value_string(VCONFKEY_IDLE_LOCK_BGSET, vconf_value)) {
622                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
623         }
624
625         return SYSTEM_SETTINGS_ERROR_NONE;
626 }
627
628 int system_setting_set_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
629 {
630         SETTING_TRACE_BEGIN;
631         int *vconf_value;
632         vconf_value = (int *)value;
633
634         if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT) {
635                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
636         }
637
638         if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, *vconf_value)) {
639                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
640         }
641         __font_size_set();
642         SETTING_TRACE_END;
643         return SYSTEM_SETTINGS_ERROR_NONE;
644 }
645 /**
646  * [internal API]
647  */
648 void *font_conf_doc_parse(char *doc_name, char *font_name)
649 {
650         xmlDocPtr doc = NULL;
651         xmlNodePtr cur = NULL;
652         xmlNodePtr cur2 = NULL;
653         xmlNodePtr cur3 = NULL;
654         xmlChar *key = NULL;
655
656         doc = xmlParseFile(doc_name);
657
658         cur = xmlDocGetRootElement(doc);
659
660         if (cur == NULL) {
661                 xmlFreeDoc(doc);
662                 doc = NULL;
663                 return NULL;
664         }
665
666         if (xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
667                 xmlFreeDoc(doc);
668                 doc = NULL;
669                 return NULL;
670         }
671
672         cur = cur->xmlChildrenNode;
673
674         Eina_Bool is_changed = EINA_FALSE;
675         while (cur != NULL) {
676                 if ((!xmlStrcmp(cur->name, (const xmlChar *)"match"))) {
677                         cur2 = cur->xmlChildrenNode;
678                         while (cur2 != NULL) {
679                                 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"edit"))) {
680                                         xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
681                                         /* if name is not 'family', break */
682                                         if (xmlStrcmp(name, (const xmlChar *)"family")) {
683                                                 xmlFree(name);
684                                                 name = NULL;
685                                                 break;
686                                         }
687                                         xmlFree(name);
688                                         name = NULL;
689
690                                         cur3 = cur2->xmlChildrenNode;
691                                         while (cur3 != NULL) {
692                                                 if ((!xmlStrcmp(cur3->name, (const xmlChar *)"string"))) {
693                                                         xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
694                                                         key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
695                                                         xmlFree(key);
696                                                         key = NULL;
697                                                         is_changed = EINA_TRUE;
698                                                 }
699                                                 cur3 = cur3->next;
700                                         }
701                                 }
702                                 cur2 = cur2->next;
703                         }
704                 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias"))) {
705                         cur2 = cur->xmlChildrenNode;
706                         while (cur2 != NULL) {
707                                 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family"))) {
708                                         xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
709                                         key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
710                                         xmlFree(key);
711                                         key = NULL;
712                                         is_changed = EINA_TRUE;
713                                 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer"))) {
714                                         cur3 = cur2->xmlChildrenNode;
715                                         while (cur3 != NULL) {
716                                                 if ((!xmlStrcmp(cur3->name, (const xmlChar *)"family"))) {
717                                                         xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
718                                                         key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
719                                                         xmlFree(key);
720                                                         key = NULL;
721                                                         is_changed = EINA_TRUE;
722                                                         cur3 = cur3->next;
723                                                         return doc;
724                                                 }
725                                                 cur3 = cur3->next;
726                                         }
727                                 }
728                                 cur2 = cur2->next;
729                         }
730                 }
731                 cur = cur->next;
732         }
733
734         if (is_changed) {
735                 return doc;
736         } else {
737                 xmlFreeDoc(doc);
738                 doc = NULL;
739                 return NULL;
740         }
741 }
742
743 int system_setting_set_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
744 {
745         SETTING_TRACE_BEGIN;
746         char *font_name = NULL;
747         font_name = (char *)value;
748
749         /* get current font list */
750         int is_found = __is_available_font(font_name);
751
752         if (is_found) {
753                 SETTING_TRACE("found font : %s ", font_name);
754         } else {
755                 SETTING_TRACE(" NOT found font : %s ", font_name);
756                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
757         }
758
759         bool bsave = font_config_set(font_name);
760
761         if (!bsave) {
762                 SETTING_TRACE(" font type save error by font_config_set() ");
763                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
764         } else {
765                 SETTING_TRACE(" save OK - font_config_set() ");
766         }
767
768         xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
769         if (doc != NULL) {
770                 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
771                 xmlFreeDoc(doc);
772                 doc = NULL;
773         }
774
775         font_config_set_notification();
776
777         char *vconf_value;
778         vconf_value = (char *)value;
779         if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, vconf_value)) {
780                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
781         }
782         return SYSTEM_SETTINGS_ERROR_NONE;
783 }
784
785 int system_setting_set_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
786 {
787         SETTING_TRACE_BEGIN;
788         bool *vconf_value;
789         vconf_value = (bool *)value;
790         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, *vconf_value)) {
791                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
792         }
793         return SYSTEM_SETTINGS_ERROR_NONE;
794 }
795
796 int system_setting_set_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
797 {
798         SETTING_TRACE_BEGIN;
799         bool *vconf_value;
800         vconf_value = (bool *)value;
801         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, *vconf_value)) {
802                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
803         }
804         return SYSTEM_SETTINGS_ERROR_NONE;
805
806 }
807
808 int system_setting_set_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
809 {
810         SETTING_TRACE_BEGIN;
811         bool *vconf_value;
812         vconf_value = (bool *)value;
813         if (system_setting_vconf_set_value_bool(VCONFKEY_3G_ENABLE, *vconf_value)) {
814                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
815         }
816         return SYSTEM_SETTINGS_ERROR_NONE;
817 }
818
819 static int category_func(const char *name, void *user_data)
820 {
821         SETTING_TRACE_BEGIN;
822         static char *category = "lock-screen";
823         if (name && !strcmp(name, category)) {
824                 SETTING_TRACE(" SAME ");
825                 return -1;
826         } else {
827                 SETTING_TRACE(" DIFFERENT -- %s, category -- %s ", name, category);
828                 return 0;
829         }
830
831         return 0;
832 }
833
834 /**
835  *
836  * set 'swipe type' if current lockscreen app is 'com.samsung.lockscreen'
837  *
838  */
839 int system_setting_set_lockscreen_app(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
840 {
841         SETTING_TRACE_BEGIN;
842         char *vconf_value;
843         vconf_value = (char *)value;            /* ex) com.samsung.lockscreen */
844
845 #if 0
846         int r = 0;
847         pkgmgrinfo_appinfo_h handle;
848         char *apptype = NULL;
849         r = pkgmgrinfo_appinfo_get_appinfo(vconf_value, &handle);
850         if (r != PMINFO_R_OK) {
851                 SETTING_TRACE("*** pkginfo failed ");
852                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
853         } else {
854                 SETTING_TRACE("%x", handle);
855         }
856
857         int ret = pkgmgrinfo_appinfo_foreach_category(handle, category_func, (void *)"lock-screen");
858         if (ret != PMINFO_R_OK) {
859                 pkgmgrinfo_appinfo_destroy_appinfo(handle);
860                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
861         }
862
863         pkgmgrinfo_appinfo_destroy_appinfo(handle);
864         /*----------------------------------------------------------------------------------- */
865         int locktype = -1;
866         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype)) {
867                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
868         }
869
870         if (locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD)
871                 return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE;
872
873         if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, vconf_value)) {
874                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
875         }
876
877         if (vconf_value && strcmp(vconf_value, "com.samsung.lockscreen") == 0) {
878                 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, SETTING_SCREEN_LOCK_TYPE_SWIPE)) {
879                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
880                 }
881         }
882 #endif
883         return SYSTEM_SETTINGS_ERROR_NONE;
884 }
885
886 /*/////////////////////////////////////////////////////////////////////////////////////////////// */
887 /* */
888
889 int system_setting_set_changed_callback_incoming_call_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
890 {
891         SETTING_TRACE_BEGIN;
892         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0, user_data);
893 }
894
895 int system_setting_unset_changed_callback_incoming_call_ringtone(system_settings_key_e key)
896 {
897         SETTING_TRACE_BEGIN;
898         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, 0);
899 }
900
901 int system_setting_set_changed_callback_email_alert_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
902 {
903         SETTING_TRACE_BEGIN;
904         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, 0, user_data);
905 }
906
907 int system_setting_unset_changed_callback_email_alert_ringtone(system_settings_key_e key)
908 {
909         SETTING_TRACE_BEGIN;
910         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, 0);
911 }
912
913 int system_setting_set_changed_callback_wallpaper_home_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
914 {
915         SETTING_TRACE_BEGIN;
916         return system_setting_vconf_set_changed_cb(VCONFKEY_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, 0, user_data);
917 }
918
919 int system_setting_unset_changed_callback_wallpaper_home_screen(system_settings_key_e key)
920 {
921         SETTING_TRACE_BEGIN;
922         return system_setting_vconf_unset_changed_cb(VCONFKEY_BGSET, 0);
923 }
924
925 int system_setting_set_changed_callback_wallpaper_lock_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
926 {
927         SETTING_TRACE_BEGIN;
928         return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, 0, user_data);
929 }
930
931 int system_setting_unset_changed_callback_wallpaper_lock_screen(system_settings_key_e key)
932 {
933         SETTING_TRACE_BEGIN;
934         return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, 0);
935 }
936
937 int system_setting_set_changed_callback_font_size(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
938 {
939         SETTING_TRACE_BEGIN;
940         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, SYSTEM_SETTINGS_KEY_FONT_SIZE, 1, user_data);
941 }
942
943 int system_setting_unset_changed_callback_font_size(system_settings_key_e key)
944 {
945         SETTING_TRACE_BEGIN;
946         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, 1);
947 }
948
949 int system_setting_set_changed_callback_usb_debugging_option(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
950 {
951         SETTING_TRACE_BEGIN;
952         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED, 1, user_data);
953 }
954
955 int system_setting_unset_changed_callback_usb_debugging_option(system_settings_key_e key)
956 {
957         SETTING_TRACE_BEGIN;
958         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 1);
959 }
960
961 int system_setting_set_changed_callback_3g_data_network(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
962 {
963         SETTING_TRACE_BEGIN;
964         return system_setting_vconf_set_changed_cb(VCONFKEY_3G_ENABLE, SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 1, user_data);
965 }
966
967 int system_setting_unset_changed_callback_3g_data_network(system_settings_key_e key)
968 {
969         SETTING_TRACE_BEGIN;
970         return system_setting_vconf_unset_changed_cb(VCONFKEY_3G_ENABLE, 1);
971 }
972
973 int system_setting_set_changed_callback_lockscreen_app(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
974 {
975         SETTING_TRACE_BEGIN;
976         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, SYSTEM_SETTINGS_KEY_LOCKSCREEN_APP, 1, user_data);
977 }
978
979 int system_setting_unset_changed_callback_lockscreen_app(system_settings_key_e key)
980 {
981         SETTING_TRACE_BEGIN;
982         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, 1);
983 }
984
985
986 /**
987  * @todo need to add custom event notification method
988  */
989 int system_setting_set_changed_callback_font_type(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
990 {
991         SETTING_TRACE_BEGIN;
992         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, SYSTEM_SETTINGS_KEY_FONT_TYPE, 2, user_data);
993 }
994
995 int system_setting_unset_changed_callback_font_type(system_settings_key_e key)
996 {
997         SETTING_TRACE_BEGIN;
998         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, 2);
999 }
1000
1001 /* TODO : 2th argument, callback, is not in use. */
1002 int system_setting_set_changed_callback_motion_activation(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1003 {
1004         SETTING_TRACE_BEGIN;
1005         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 3, user_data);
1006 }
1007
1008 int system_setting_unset_changed_callback_motion_activation(system_settings_key_e key)
1009 {
1010         SETTING_TRACE_BEGIN;
1011         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, 3);
1012 }
1013
1014 static char *_get_cur_font()
1015 {
1016         SETTING_TRACE_BEGIN;
1017         xmlDocPtr doc = NULL;
1018         xmlNodePtr cur = NULL;
1019         xmlNodePtr cur2 = NULL;
1020         xmlNodePtr cur3 = NULL;
1021         xmlChar *key = NULL;
1022
1023         char *font_name = NULL;
1024
1025         doc = xmlParseFile(SETTING_FONT_CONF_FILE);
1026
1027         cur = xmlDocGetRootElement(doc);
1028
1029         if (cur == NULL) {
1030                 xmlFreeDoc(doc);
1031                 doc = NULL;
1032                 return NULL;
1033         }
1034
1035         if (xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1036                 xmlFreeDoc(doc);
1037                 doc = NULL;
1038                 return NULL;
1039         }
1040
1041         cur = cur->xmlChildrenNode;
1042
1043         while (cur != NULL) {
1044                 if ((!xmlStrcmp(cur->name, (const xmlChar *)"match"))) {
1045                         cur2 = cur->xmlChildrenNode;
1046                         while (cur2 != NULL) {
1047                                 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"edit"))) {
1048                                         cur3 = cur2->xmlChildrenNode;
1049                                         while (cur3 != NULL) {
1050                                                 if ((!xmlStrcmp(cur3->name, (const xmlChar *)"string"))) {
1051                                                         key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1052
1053                                                         font_name = g_strdup((char *)key);
1054                                                         xmlFree(key);
1055                                                         key = NULL;
1056                                                         xmlFreeDoc(doc);
1057                                                         doc = NULL;
1058                                                         return font_name;
1059                                                 }
1060                                                 cur3 = cur3->next;
1061                                         }
1062                                 }
1063                                 cur2 = cur2->next;
1064                         }
1065                 }
1066                 cur = cur->next;
1067         }
1068
1069         xmlFreeDoc(doc);
1070         doc = NULL;
1071         return NULL;
1072 }
1073
1074 static void font_config_set_notification()
1075 {
1076         SETTING_TRACE_BEGIN;
1077 #if 0
1078         /* notification */
1079         Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
1080         Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
1081         ecore_x_window_prop_string_set(ecore_win, atom, "tizen");
1082 #endif
1083 }
1084
1085 int __is_available_font(char *font_name)
1086 {
1087         SETTING_TRACE_BEGIN;
1088         FcObjectSet *os = NULL;
1089         FcFontSet *fs = NULL;
1090         FcPattern *pat = NULL;
1091         Eina_List *list = NULL;
1092         FcConfig *font_config = NULL;
1093
1094         int ret = 0;
1095
1096         if (font_name == NULL)
1097                 return -1;
1098
1099         font_config = FcInitLoadConfigAndFonts();
1100
1101         /*setting_retvm_if(font_config == NULL, NULL, "Failed: FcInitLoadConfigAndFonts"); */
1102
1103         char *locale = setlocale(0, NULL);
1104
1105         pat = FcPatternCreate();
1106
1107         os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FAMILYLANG, (char *) 0);
1108
1109         if (os) {
1110                 fs = FcFontList(font_config, pat, os);
1111                 FcObjectSetDestroy(os);
1112                 os = NULL;
1113         }
1114
1115         if (pat) {
1116                 FcPatternDestroy(pat);
1117                 pat = NULL;
1118         }
1119
1120         if (fs) {
1121                 int j;
1122                 SETTING_TRACE("fs->nfont = %d", fs->nfont);
1123
1124                 for (j = 0; j < fs->nfont; j++) {
1125                         FcChar8 *family = NULL;
1126                         FcChar8 *file = NULL;
1127
1128                         if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) {
1129                                 int preload_path_len = strlen(SETTING_FONT_PRELOAD_FONT_PATH);
1130                                 int download_path_len = strlen(SETTING_FONT_DOWNLOADED_FONT_PATH);
1131
1132                                 if (file && (!strncmp((const char *)file, SETTING_FONT_PRELOAD_FONT_PATH, preload_path_len)
1133                                              || !strncmp((const char *)file, SETTING_FONT_DOWNLOADED_FONT_PATH, download_path_len))) {
1134                                         char *family_result = NULL;
1135                                         FcChar8 *lang = NULL;
1136                                         int id = 0;
1137                                         if (FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) {
1138                                                 break;
1139                                         }
1140                                         if (FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) {
1141                                                 break;
1142                                         }
1143                                         family_result = (char *)family;
1144
1145                                         /* Find proper family name for current locale. */
1146                                         while (locale && family && lang) {
1147                                                 if (!strncmp(locale, (char *)lang, strlen((char *)lang))) {
1148                                                         family_result = (char *)family;
1149                                                         break;
1150                                                 }
1151
1152                                                 /* I will set english as default family language. */
1153                                                 /* If there is no proper family language for current locale, */
1154                                                 /* we have to show the english family name. */
1155                                                 if (!strcmp(lang, "en")) {
1156                                                         family_result = (char *)family;
1157                                                 }
1158                                                 id++;
1159                                                 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) {
1160                                                         break;
1161                                                 }
1162                                                 if (FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) {
1163                                                         break;
1164                                                 }
1165                                         }
1166
1167                                         if (family_result) {
1168                                                 SETTING_TRACE("-------- FONT - family_result = %s", (char *)family_result);
1169                                                 if (strcmp(family_result, font_name) == 0) {
1170                                                         ret = 1;
1171                                                         break;
1172                                                 }
1173                                         }
1174                                 }
1175                         }
1176                 }
1177                 FcFontSetDestroy(fs);
1178                 fs = NULL;
1179         }
1180         FcConfigDestroy(font_config);
1181         font_config = NULL;
1182         return ret;
1183 }
1184
1185
1186 static char *_get_default_font()
1187 {
1188         SETTING_TRACE_BEGIN;
1189         xmlDocPtr doc = NULL;
1190         xmlNodePtr cur = NULL;
1191         xmlNodePtr cur2 = NULL;
1192         xmlNodePtr cur3 = NULL;
1193         xmlChar *key = NULL;
1194         struct _xmlAttr *properties = NULL;
1195         char *default_font_name = NULL;
1196
1197         doc = xmlParseFile(SETTING_DEFAULT_FONT_CONF_FILE);
1198
1199         cur = xmlDocGetRootElement(doc);
1200
1201         if (cur == NULL) {
1202                 xmlFreeDoc(doc);
1203                 doc = NULL;
1204                 return NULL;
1205         }
1206
1207         if (xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1208                 xmlFreeDoc(doc);
1209                 doc = NULL;
1210                 return NULL;
1211         }
1212
1213         cur = cur->xmlChildrenNode;
1214
1215         while (cur != NULL) {
1216                 if ((!xmlStrcmp(cur->name, (const xmlChar *)"match"))) {
1217                         cur2 = cur->xmlChildrenNode;
1218                         while (cur2 != NULL) {
1219                                 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"edit"))) {
1220                                         properties = cur2->properties;
1221                                         /*find the "name" property*/
1222                                         while (NULL != properties) {
1223                                                 if (!xmlStrcmp(properties->name, (const xmlChar *)"name")) {
1224                                                         break;
1225                                                 }
1226                                                 properties = properties->next;
1227                                         }
1228
1229                                         /*If the value of "name" property is "family", then get the child node string,
1230                                         it shall be the default font type*/
1231                                         if (NULL != properties && !xmlStrcmp(properties->children->content, (const xmlChar *)"family")) {
1232                                                 cur3 = cur2->xmlChildrenNode;
1233                                                 while (cur3 != NULL) {
1234                                                         if ((!xmlStrcmp(cur3->name, (const xmlChar *)"string"))) {
1235                                                                 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1236                                                                 default_font_name = g_strdup((char *)key);
1237                                                                 xmlFree(key);
1238                                                                 key = NULL;
1239                                                                 xmlFreeDoc(doc);
1240                                                                 doc = NULL;
1241                                                                 return default_font_name;
1242                                                         }
1243                                                         cur3 = cur3->next;
1244                                                 }
1245                                         }
1246                                 }
1247                                 cur2 = cur2->next;
1248                         }
1249                 }
1250                 cur = cur->next;
1251         }
1252
1253         xmlFreeDoc(doc);
1254         doc = NULL;
1255         return NULL;
1256 }
1257
1258 static bool font_config_set(char *font_name)
1259 {
1260         SETTING_TRACE_BEGIN;
1261         Eina_List *text_classes = NULL;
1262         Elm_Text_Class *etc = NULL;
1263         const Eina_List *l = NULL;
1264         Eina_List *fo_list = NULL;
1265         Elm_Font_Overlay *efo = NULL;
1266
1267         int font_size = __font_size_get();
1268         int size = 0;
1269
1270         text_classes = elm_config_text_classes_list_get();
1271
1272         fo_list = (Eina_List *)elm_config_font_overlay_list_get();
1273
1274         Eina_List *ll = NULL;
1275         Eina_List *l_next = NULL;
1276
1277         Eina_Bool slp_medium_exist = EINA_FALSE;
1278         Eina_Bool slp_roman_exist = EINA_FALSE;
1279         Eina_Bool slp_bold_exist = EINA_FALSE;
1280         Eina_Bool slp_regular_exist = EINA_FALSE;
1281
1282         /* Tizen */
1283         Eina_Bool tizen_exist = EINA_FALSE;
1284
1285         EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo) {
1286                 if (!strcmp(efo->text_class, "tizen_medium")) {
1287                         elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
1288                         slp_medium_exist = EINA_TRUE;
1289                 } else if (!strcmp(efo->text_class, "tizen_roman")) {
1290                         elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
1291                         slp_roman_exist = EINA_TRUE;
1292                 } else if (!strcmp(efo->text_class, "tizen_bold")) {
1293                         elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
1294                         slp_bold_exist = EINA_TRUE;
1295                 } else if (!strcmp(efo->text_class, "tizen_regular")) {
1296                         elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
1297                         slp_regular_exist = EINA_TRUE;
1298                 }
1299
1300                 /* Tizen */
1301                 if (!strcmp(efo->text_class, "tizen")) {
1302                         elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
1303                         tizen_exist = EINA_TRUE;
1304                 }
1305
1306         }
1307
1308         /* if slp_XX do not exist, need to set them, font size is -100(100%) */
1309         if (slp_medium_exist == EINA_FALSE) {
1310                 elm_config_font_overlay_set("tizen_medium", (const char *)font_name,  MIDDLE_FONT_DPI);
1311         }
1312         if (slp_roman_exist == EINA_FALSE) {
1313                 elm_config_font_overlay_set("tizen_roman", (const char *)font_name,  MIDDLE_FONT_DPI);
1314         }
1315         if (slp_bold_exist == EINA_FALSE) {
1316                 elm_config_font_overlay_set("tizen_bold", (const char *)font_name,  MIDDLE_FONT_DPI);
1317         }
1318         if (slp_regular_exist == EINA_FALSE) {
1319                 elm_config_font_overlay_set("tizen_regular", (const char *)font_name,  MIDDLE_FONT_DPI);
1320         }
1321
1322         /* Tizen */
1323         if (tizen_exist == EINA_FALSE) {
1324                 elm_config_font_overlay_set("tizen", (const char *)font_name,  MIDDLE_FONT_DPI);
1325         }
1326
1327         elm_config_font_overlay_set("tizen", (const char *)font_name,  MIDDLE_FONT_DPI);
1328
1329         /* Tizen */
1330         elm_config_font_overlay_set("tizen", (const char *)font_name,  MIDDLE_FONT_DPI);
1331
1332         EINA_LIST_FOREACH(text_classes, l, etc) {
1333                 ll = NULL;
1334
1335                 size = font_size;
1336                 EINA_LIST_FOREACH(fo_list, ll, efo) {
1337                         if (!strcmp(etc->name, efo->text_class)) {
1338                                 size = efo->size;
1339                         }
1340                 }
1341                 elm_config_font_overlay_set(etc->name, (const char *)font_name, size);
1342         }
1343         elm_config_text_classes_list_free(text_classes);
1344         text_classes = NULL;
1345
1346         /* add new function */
1347 #ifdef USE_EFL_ASSIST
1348         ea_theme_system_font_set(font_name, font_size);
1349         ea_theme_system_fonts_apply();
1350 #endif
1351
1352         elm_config_font_overlay_apply();
1353         elm_config_all_flush();
1354         elm_config_save();
1355         return 1;
1356 }
1357
1358 static void __font_size_set()
1359 {
1360         SETTING_TRACE_BEGIN;
1361         Eina_List *text_classes = NULL;
1362         Elm_Text_Class *etc = NULL;
1363         const Eina_List *l = NULL;
1364         int font_size = __font_size_get();
1365         char *font_name = _get_cur_font();
1366
1367         if (font_size == -1) {
1368                 return;
1369         }
1370
1371         text_classes = elm_config_text_classes_list_get();
1372
1373         EINA_LIST_FOREACH(text_classes, l, etc) {
1374                 elm_config_font_overlay_set(etc->name, font_name, font_size);
1375         }
1376
1377         elm_config_text_classes_list_free(text_classes);
1378
1379 #ifdef USE_EFL_ASSIST
1380         ea_theme_system_font_set(font_name, font_size);
1381         ea_theme_system_fonts_apply();
1382 #endif
1383
1384         elm_config_font_overlay_apply();
1385         elm_config_all_flush();
1386         elm_config_save();
1387
1388         text_classes = NULL;
1389         g_free(font_name);
1390 }
1391
1392 static int __font_size_get()
1393 {
1394         SETTING_TRACE_BEGIN;
1395         int font_size = -1;
1396         int err = -1;
1397
1398         int vconf_value = -1;
1399         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
1400                 return -1;
1401         }
1402
1403         switch (vconf_value) {
1404                 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1405                         font_size = SMALL_FONT_DPI;
1406                         break;
1407                 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1408                         font_size = MIDDLE_FONT_DPI;
1409                         break;
1410                 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1411                         font_size = LARGE_FONT_DPI;
1412                         break;
1413                 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1414                         font_size = HUGE_FONT_DPI;
1415                         break;
1416                 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1417                         font_size = GIANT_FONT_DPI;
1418                         break;
1419                 default:
1420                         font_size = MIDDLE_FONT_DPI;
1421                         break;
1422         }
1423         return font_size;
1424 }
1425
1426 /*//////////////////////////////////////////////////////////////////////////////////////// */
1427 /*--------------------------------------- */
1428 int system_setting_get_locale_country(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1429 {
1430         SETTING_TRACE_BEGIN;
1431         char *vconf_value = NULL;
1432         if (system_setting_vconf_get_value_string(VCONFKEY_REGIONFORMAT, &vconf_value)) {
1433                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1434         }
1435
1436         /* parsing validation */
1437         /* en_US.UTF-8 */
1438         char arr[20];
1439         snprintf(arr, 20, vconf_value);
1440         arr[5] = '\0';
1441         *value = strdup(arr);
1442         free(vconf_value);
1443         vconf_value = NULL;
1444
1445         return SYSTEM_SETTINGS_ERROR_NONE;
1446 }
1447
1448 int system_setting_set_locale_country(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1449 {
1450         SETTING_TRACE_BEGIN;
1451         char *vconf_value = NULL;
1452         vconf_value = (char *)value;
1453
1454         char *ext = "UTF-8";
1455
1456         char arr[20];
1457         snprintf(arr, 20, "%s.%s", vconf_value, ext);
1458
1459         if (system_setting_vconf_set_value_string(VCONFKEY_REGIONFORMAT, arr)) {
1460                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1461         }
1462
1463         return SYSTEM_SETTINGS_ERROR_NONE;
1464 }
1465
1466 int system_setting_set_changed_callback_locale_country(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1467 {
1468         SETTING_TRACE_BEGIN;
1469         return system_setting_vconf_set_changed_cb(VCONFKEY_REGIONFORMAT, SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, 3, user_data);
1470 }
1471
1472 int system_setting_unset_changed_callback_locale_country(system_settings_key_e key)
1473 {
1474         SETTING_TRACE_BEGIN;
1475         return system_setting_vconf_unset_changed_cb(VCONFKEY_REGIONFORMAT, 3);
1476 }
1477
1478
1479 /*--------------------------------------- */
1480 int system_setting_get_locale_language(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1481 {
1482         SETTING_TRACE_BEGIN;
1483         char *vconf_value = NULL;
1484         if (system_setting_vconf_get_value_string(VCONFKEY_LANGSET, &vconf_value)) {
1485                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1486         }
1487
1488         /* parsing validation */
1489         /* en_US.UTF-8 */
1490         char arr[20];
1491         snprintf(arr, 20, vconf_value);
1492         arr[5] = '\0';
1493         *value = strdup(arr);
1494         free(vconf_value);
1495         vconf_value = NULL;
1496         return SYSTEM_SETTINGS_ERROR_NONE;
1497 }
1498
1499 int system_setting_set_locale_language(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1500 {
1501         SETTING_TRACE_BEGIN;
1502         char *vconf_value = NULL;
1503         vconf_value = (char *)value;
1504
1505         char *ext = "UTF-8";
1506
1507         char arr[20];
1508         snprintf(arr, 20, "%s.%s", vconf_value, ext);
1509
1510         if (system_setting_vconf_set_value_string(VCONFKEY_LANGSET, arr)) {
1511                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1512         }
1513
1514         return SYSTEM_SETTINGS_ERROR_NONE;
1515 }
1516
1517 int system_setting_set_changed_callback_locale_language(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1518 {
1519         SETTING_TRACE_BEGIN;
1520         /*return system_setting_vconf_set_changed_cb(VCONFKEY_LANGSET, SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, 3, user_data ); */
1521         return system_setting_vconf_set_changed_cb(VCONFKEY_LANGSET, SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, 100, user_data);
1522 }
1523
1524 int system_setting_unset_changed_callback_locale_language(system_settings_key_e key)
1525 {
1526         SETTING_TRACE_BEGIN;
1527         return system_setting_vconf_unset_changed_cb(VCONFKEY_LANGSET, 100);
1528 }
1529
1530 /*--------------------------------------- */
1531 int system_setting_get_locale_timeformat_24hour(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1532 {
1533         SETTING_TRACE_BEGIN;
1534         int vconf_value;
1535
1536         if (system_setting_vconf_get_value_int(VCONFKEY_REGIONFORMAT_TIME1224, &vconf_value)) {
1537                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1538         }
1539
1540         bool ret_value;
1541         if (vconf_value == VCONFKEY_TIME_FORMAT_12)
1542                 ret_value = false;
1543         else if (vconf_value == VCONFKEY_TIME_FORMAT_24)
1544                 ret_value = true;
1545
1546         *value = (void *)ret_value;
1547
1548         return SYSTEM_SETTINGS_ERROR_NONE;
1549 }
1550
1551 int system_setting_set_locale_timeformat_24hour(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1552 {
1553         SETTING_TRACE_BEGIN;
1554         bool *vconf_value;
1555
1556         vconf_value = (bool *)value;
1557
1558         if (*vconf_value) {
1559                 if (system_setting_vconf_set_value_int(VCONFKEY_REGIONFORMAT_TIME1224, VCONFKEY_TIME_FORMAT_24)) {
1560                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1561                 }
1562
1563         } else {
1564                 if (system_setting_vconf_set_value_int(VCONFKEY_REGIONFORMAT_TIME1224, VCONFKEY_TIME_FORMAT_12)) {
1565                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1566                 }
1567
1568         }
1569
1570         return SYSTEM_SETTINGS_ERROR_NONE;
1571 }
1572
1573 int system_setting_set_changed_callback_locale_timeformat_24hour(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1574 {
1575         SETTING_TRACE_BEGIN;
1576         return system_setting_vconf_set_changed_cb(VCONFKEY_REGIONFORMAT_TIME1224, SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, 3, user_data);
1577 }
1578
1579 int system_setting_unset_changed_callback_locale_timeformat_24hour(system_settings_key_e key)
1580 {
1581         SETTING_TRACE_BEGIN;
1582         return system_setting_vconf_unset_changed_cb(VCONFKEY_REGIONFORMAT_TIME1224, 3);
1583 }
1584
1585 int system_setting_get_locale_timezone(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1586 {
1587         SETTING_TRACE_BEGIN;
1588         char tzpath[256];
1589         ssize_t len = readlink(SETTING_TZONE_SYMLINK_PATH, tzpath, sizeof(tzpath) - 1);
1590         if (len != -1) {
1591                 tzpath[len] = '\0';
1592         } else {
1593                 SETTING_TRACE("parse error for SETTING_TZONE_SYMLINK_PATH");
1594                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1595         }
1596
1597         /* "/usr/share/zoneinfo/Asia/Seoul" */
1598         SETTING_TRACE("tzpath : %s ", &tzpath[20]);
1599         *value = strdup(&tzpath[20]);
1600         return SYSTEM_SETTINGS_ERROR_NONE;
1601 }
1602
1603 int system_setting_set_changed_callback_locale_timezone_changed(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1604 {
1605         SETTING_TRACE_BEGIN;
1606         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
1607 }
1608
1609 int system_setting_unset_changed_callback_locale_timezone_changed(system_settings_key_e key)
1610 {
1611         SETTING_TRACE_BEGIN;
1612         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
1613 }
1614
1615
1616 int system_setting_get_time_changed(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1617 {
1618         SETTING_TRACE_BEGIN;
1619         time_t cur_tick;
1620         cur_tick = time(NULL);
1621         *value = (void *)cur_tick;
1622         /* struct tm * localtime = time (cur_tick); */
1623         /* printf("%s\n", ctime(&cur_tick); */
1624         return SYSTEM_SETTINGS_ERROR_NONE;
1625
1626 }
1627
1628 int system_setting_set_changed_callback_time_changed(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1629 {
1630         SETTING_TRACE_BEGIN;
1631         return system_setting_vconf_set_changed_cb(VCONFKEY_SYSTEM_TIME_CHANGED, SYSTEM_SETTINGS_KEY_TIME_CHANGED, 3, user_data);
1632 }
1633
1634 int system_setting_unset_changed_callback_time_changed(system_settings_key_e key)
1635 {
1636         SETTING_TRACE_BEGIN;
1637         return system_setting_vconf_unset_changed_cb(VCONFKEY_SYSTEM_TIME_CHANGED, 3);
1638 }
1639
1640
1641
1642 /* SYSTEM_SETTINGS_KEY_SOUND_LOCK */
1643 int system_setting_get_sound_lock(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1644 {
1645         SETTING_TRACE_BEGIN;
1646         bool vconf_value;
1647
1648         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, &vconf_value)) {
1649                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1650         }
1651         *value = (void *)vconf_value;
1652
1653         return SYSTEM_SETTINGS_ERROR_NONE;
1654 }
1655
1656 int system_setting_set_changed_callback_sound_lock(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1657 {
1658         SETTING_TRACE_BEGIN;
1659         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, SYSTEM_SETTINGS_KEY_SOUND_LOCK, 3, user_data);
1660 }
1661
1662 int system_setting_unset_changed_callback_sound_lock(system_settings_key_e key)
1663 {
1664         SETTING_TRACE_BEGIN;
1665         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, 3);
1666 }
1667
1668 /**
1669  * a = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL b = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL
1670  *
1671  * a == false, b == false --> silent mode
1672  * a == true, b == false --> sound mode
1673  * a == false, b == true --> vibration mode
1674  */
1675 int system_setting_get_sound_silent_mode(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1676 {
1677         SETTING_TRACE_BEGIN;
1678         bool sound_cond;
1679         bool vib_cond;
1680
1681         bool vconf_value;
1682         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_cond)) {
1683                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1684         }
1685
1686         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vib_cond)) {
1687                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1688         }
1689
1690         if (sound_cond == false && vib_cond == false) {
1691                 vconf_value = true;
1692                 *value = (void *)vconf_value;
1693         } else {
1694                 vconf_value = false;
1695                 *value = (void *)vconf_value;
1696         }
1697         return SYSTEM_SETTINGS_ERROR_NONE;
1698 }
1699
1700 /**
1701  * a = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL b = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL
1702  *
1703  * a == false, b == false --> silent mode
1704  * a == true, b == false --> sound mode
1705  */
1706 int system_setting_set_sound_silent_mode(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1707 {
1708         SETTING_TRACE_BEGIN;
1709         bool *vconf_value;
1710
1711         vconf_value = (bool *)value;
1712
1713         bool vconf_sound = false;
1714         bool vconf_vib = false;
1715
1716         if (*vconf_value) {
1717                 vconf_sound = false;
1718                 vconf_vib = false;
1719         } else {
1720                 vconf_sound = true;
1721                 vconf_vib = false;
1722         }
1723
1724         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, vconf_sound)) {
1725                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1726         }
1727         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, vconf_vib)) {
1728                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1729         }
1730
1731         return SYSTEM_SETTINGS_ERROR_NONE;
1732 }
1733
1734
1735
1736 /* TODO */
1737 int system_setting_set_changed_callback_sound_silent_mode(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1738 {
1739         SETTING_TRACE_BEGIN;
1740         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, SYSTEM_SETTINGS_KEY_SOUND_SILENT_MODE, 3, user_data);
1741 }
1742
1743 /* TODO */
1744 int system_setting_unset_changed_callback_sound_silent_mode(system_settings_key_e key)
1745 {
1746         SETTING_TRACE_BEGIN;
1747         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, 3);
1748 }
1749
1750 /* SYSTEM_SETTINGS_KEY_SOUND_TOUCH */
1751 int system_setting_get_sound_touch(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1752 {
1753         SETTING_TRACE_BEGIN;
1754         bool vconf_value;
1755
1756         int ret = system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, &vconf_value);
1757         if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
1758                 return ret;
1759         }
1760         *value = (void *)vconf_value;
1761         return ret;
1762 }
1763
1764 int system_setting_set_changed_callback_sound_touch(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1765 {
1766         SETTING_TRACE_BEGIN;
1767         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, SYSTEM_SETTINGS_KEY_SOUND_TOUCH, 2, user_data);
1768 }
1769
1770 int system_setting_unset_changed_callback_sound_touch(system_settings_key_e key)
1771 {
1772         SETTING_TRACE_BEGIN;
1773         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, 2);
1774 }
1775
1776 #if 0
1777 /* SYSTEM_SETTINGS_KEY_SOUND_LOCK */
1778 int system_setting_get_sound_lock(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1779 {
1780         bool vconf_value;
1781
1782         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, &vconf_value)) {
1783                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1784         }
1785         *value = (void *)vconf_value;
1786
1787         return SYSTEM_SETTINGS_ERROR_NONE;
1788 }
1789 #endif
1790
1791 int system_setting_get_auto_rotation_mode(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1792 {
1793         SETTING_TRACE_BEGIN;
1794         bool vconf_value;
1795
1796         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &vconf_value)) {
1797                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1798         }
1799         *value = (void *)vconf_value;
1800
1801         return SYSTEM_SETTINGS_ERROR_NONE;
1802 }
1803
1804 int system_setting_set_auto_rotation_mode(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1805 {
1806         SETTING_TRACE_BEGIN;
1807         bool *vconf_value;
1808         vconf_value = (bool *)value;
1809         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, *vconf_value)) {
1810                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1811         }
1812         return SYSTEM_SETTINGS_ERROR_NONE;
1813 }
1814
1815 int system_setting_set_changed_callback_auto_rotation_mode(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1816 {
1817         SETTING_TRACE_BEGIN;
1818         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, SYSTEM_SETTINGS_KEY_DISPLAY_SCREEN_ROTATION_AUTO, 2, user_data);
1819 }
1820
1821 int system_setting_unset_changed_callback_auto_rotation_mode(system_settings_key_e key)
1822 {
1823         SETTING_TRACE_BEGIN;
1824         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, 2);
1825 }
1826
1827 int system_setting_get_screen_backlight_time(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1828 {
1829         SETTING_TRACE_BEGIN;
1830         int vconf_value;
1831
1832         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, &vconf_value)) {
1833                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1834         }
1835         *value = (void *)vconf_value;
1836
1837         return SYSTEM_SETTINGS_ERROR_NONE;
1838 }
1839
1840
1841 int system_setting_set_screen_backlight_time(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1842 {
1843         SETTING_TRACE_BEGIN;
1844         int *vconf_value;
1845         vconf_value = (int *)value;
1846
1847         if (!(*vconf_value > 0 && *vconf_value < 600)) {
1848                 SETTING_TRACE(" ERR Betweeny here  0 ~ 600");
1849                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
1850         }
1851
1852         if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, *vconf_value)) {
1853                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1854         }
1855         SETTING_TRACE_END;
1856         return SYSTEM_SETTINGS_ERROR_NONE;
1857 }
1858
1859 int system_setting_set_changed_callback_screen_backlight_time(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1860 {
1861         SETTING_TRACE_BEGIN;
1862         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, SYSTEM_SETTINGS_KEY_DISPLAY_SCREEN_ROTATION_AUTO, 2, user_data);
1863 }
1864
1865 int system_setting_unset_changed_callback_screen_backlight_time(system_settings_key_e key)
1866 {
1867         SETTING_TRACE_BEGIN;
1868         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 2);
1869 }
1870
1871 int system_setting_get_sound_notification(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1872 {
1873         SETTING_TRACE_BEGIN;
1874         char *vconf_value = NULL;
1875         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, &vconf_value)) {
1876                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1877         }
1878
1879         *value = vconf_value;
1880         return SYSTEM_SETTINGS_ERROR_NONE;
1881 }
1882
1883 int system_setting_set_sound_notification(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1884 {
1885         SETTING_TRACE_BEGIN;
1886         char *vconf_value = NULL;
1887         vconf_value = (char *)value;
1888
1889         int is_load = _is_file_accessible(vconf_value);
1890         if (is_load == 0) {
1891                 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, vconf_value)) {
1892                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1893                 }
1894         } else {
1895                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1896         }
1897
1898         return SYSTEM_SETTINGS_ERROR_NONE;
1899 }
1900
1901 int system_setting_set_changed_callback_sound_notification(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1902 {
1903         SETTING_TRACE_BEGIN;
1904         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0, user_data);
1905 }
1906
1907 int system_setting_unset_changed_callback_sound_notification(system_settings_key_e key)
1908 {
1909         SETTING_TRACE_BEGIN;
1910         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, 0);
1911 }
1912
1913 int system_setting_get_notification_repetition_period(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1914 {
1915         SETTING_TRACE_BEGIN;
1916         int vconf_value;
1917
1918         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, &vconf_value)) {
1919                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1920         }
1921         *value = (void *)vconf_value;
1922
1923         return SYSTEM_SETTINGS_ERROR_NONE;
1924 }
1925
1926 int system_setting_set_notification_repetition_period(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1927 {
1928         SETTING_TRACE_BEGIN;
1929         int *vconf_value;
1930         vconf_value = (int *)value;
1931
1932         if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, *vconf_value)) {
1933                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1934         }
1935         SETTING_TRACE_END;
1936         return SYSTEM_SETTINGS_ERROR_NONE;
1937 }
1938
1939 int system_setting_set_changed_callback_notification_repetition_period(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1940 {
1941         SETTING_TRACE_BEGIN;
1942         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, SYSTEM_SETTINGS_KEY_DISPLAY_SCREEN_ROTATION_AUTO, 1, user_data);
1943 }
1944
1945 int system_setting_unset_changed_callback_notification_repetition_period(system_settings_key_e key)
1946 {
1947         SETTING_TRACE_BEGIN;
1948         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, 1);
1949 }
1950
1951 int system_setting_get_device_name(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1952 {
1953         SETTING_TRACE_BEGIN;
1954         char *vconf_value = NULL;
1955         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_DEVICE_NAME_STR, &vconf_value)) {
1956                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1957         }
1958
1959         *value = vconf_value;
1960         return SYSTEM_SETTINGS_ERROR_NONE;
1961 }
1962
1963 int system_setting_set_device_name(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1964 {
1965         SETTING_TRACE_BEGIN;
1966         char *vconf_value = NULL;
1967         vconf_value = (char *)value;
1968
1969         if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_DEVICE_NAME_STR, vconf_value)) {
1970                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1971         }
1972
1973         return SYSTEM_SETTINGS_ERROR_NONE;
1974 }
1975
1976 int system_setting_set_changed_callback_device_name(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1977 {
1978         SETTING_TRACE_BEGIN;
1979         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_DEVICE_NAME_STR, SYSTEM_SETTINGS_KEY_DEVICE_NAME, 0, user_data);
1980 }
1981
1982 int system_setting_unset_changed_callback_device_name(system_settings_key_e key)
1983 {
1984         SETTING_TRACE_BEGIN;
1985         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_DEVICE_NAME_STR, 0);
1986 }
1987
1988 /*---------------------------------------------- */
1989 int system_setting_get_network_flight_mode(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1990 {
1991         SETTING_TRACE_BEGIN;
1992         bool vconf_value;
1993         if (system_setting_vconf_get_value_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &vconf_value)) {
1994                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1995         }
1996         *value = (void *)vconf_value;
1997
1998         return SYSTEM_SETTINGS_ERROR_NONE;
1999 }
2000
2001 int system_setting_set_changed_callback_network_flight_mode(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
2002 {
2003         SETTING_TRACE_BEGIN;
2004         return system_setting_vconf_set_changed_cb(VCONFKEY_TELEPHONY_FLIGHT_MODE, SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE, 3, user_data);
2005 }
2006
2007 int system_setting_unset_changed_callback_network_flight_mode(system_settings_key_e key)
2008 {
2009         SETTING_TRACE_BEGIN;
2010         return system_setting_vconf_unset_changed_cb(VCONFKEY_TELEPHONY_FLIGHT_MODE, 3);
2011 }
2012
2013 int system_setting_get_network_wifi_notification(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
2014 {
2015         SETTING_TRACE_BEGIN;
2016         int vconf_value;
2017         if (system_setting_vconf_get_value_int(VCONFKEY_WIFI_ENABLE_QS, &vconf_value)) {
2018                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
2019         }
2020         bool bret ;
2021         bret = (vconf_value == VCONFKEY_WIFI_QS_ENABLE) ? true : false;
2022
2023         *value = (void *)bret;
2024         return SYSTEM_SETTINGS_ERROR_NONE;
2025 }
2026
2027 int system_setting_set_changed_callback_network_wifi_notification(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
2028 {
2029         SETTING_TRACE_BEGIN;
2030         return system_setting_vconf_set_changed_cb(VCONFKEY_WIFI_ENABLE_QS, SYSTEM_SETTINGS_KEY_NETWORK_WIFI_NOTIFICATION, 4, user_data);
2031 }
2032
2033 int system_setting_unset_changed_callback_network_wifi_notification(system_settings_key_e key)
2034 {
2035         SETTING_TRACE_BEGIN;
2036         return system_setting_vconf_unset_changed_cb(VCONFKEY_WIFI_ENABLE_QS, 4);
2037 }
2038
2039
2040