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