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