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