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