applied capi-system-system-settings into Settings- use font-type related enumeration .
[apps/core/preloaded/settings.git] / setting-common / src / setting-common-general-func.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <ail.h>
22 #include <setting-common-general-func.h>
23 #include <setting-common-data-slp-setting.h>
24
25 #include <glib.h>
26 #include <iniparser.h>
27 #include <dlfcn.h>
28 #include <libxml/xmlmemory.h>
29 #include <libxml/parser.h>
30 #include <system_info.h>
31
32 #include <system_settings.h>
33
34 char *setting_file_basename(char *path)
35 {
36         if (NULL == path || '\0' == path[0]) {
37                 return NULL;    /* invalid arguement */
38         }
39         char *p = strrchr(path, '/');
40         if (!p) {
41                 return (char *)g_strdup(path);  /*  cannot find '/' */
42         }
43         if ('\0' == p[1]) {
44                 return NULL;    /* end with '/' */
45         }
46         return (char *)g_strdup(p + 1);
47 }
48
49 char *get_pa_usb_connect_mode_str()
50 {
51         int ret = SETTING_RETURN_FAIL;
52         int value;
53
54         ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &value);
55         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
56
57         switch (value)
58         {
59         case SETTING_USB_DEBUG_MODE:
60                 return (char*)g_strdup(_("IDS_ST_BODY_USB_DEBUGGING"));
61         default:
62                 return (char*)g_strdup(_("IDS_COM_POP_DISCONNECTED"));
63         }
64 }
65
66 char *get_brightness_mode_str()
67 {
68         int value, err;
69         setting_get_int_slp_key(INT_SLP_SETTING_AUTOMATIC_BRIGHTNESS, &value,
70                                  &err);
71         if (value != SETTING_BRIGHTNESS_AUTOMATIC_OFF) {
72                 return setting_gettext("IDS_COM_BODY_AUTOMATIC");
73         } else {
74                 return setting_gettext("IDS_COM_BODY_MANUAL");
75         }
76 }
77
78 char *get_pa_backlight_time_str()
79 {
80         int value = 0;
81         char backlight_time_str[MAX_DISPLAY_NAME_LEN_ON_UI];
82
83 #if SUPPORT_LCD_TIMEOUT_KEEPING
84         if (0 != vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &value)) {
85                 /* value = 600; */
86                 if(isEmulBin())
87                         value = 0;      /* keep agree with postin file */
88                 else
89                         value = 30;
90                 vconf_set_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, value);
91         }
92 #else
93         int err;
94         int ret =
95             setting_get_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL, &value,
96                                     &err);
97         #if NORMAL
98         if (SETTING_RETURN_FAIL == ret || value < 0) {  /* file system exceptional handle, eg. The vconf file lost due to file system. */
99                 /* value = 600; */
100                 if(isEmulBin())
101                         value = 0;      /* keep agree with postin file */
102                 else
103                         value = 30;
104                 setting_set_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL,
105                                         value, &err);
106         }
107         #else // for MDM server
108         // adjust value.
109         // if < 15, 15
110         // if 15 < < 30, 15
111         // if 30 < < 60, 30
112         // if 60 < < 120, 60
113         // if 120 < < 300, 120
114         // if 300 < < 600, 300
115         // if > 600, 600
116         if(isEmulBin())
117         {
118                 if (SETTING_RETURN_FAIL == ret || value < 15)
119                         value = 0;
120                 else if(value >= 15 && value < 30)
121                         value = 15;
122                 else if(value >= 30 && value < 60)
123                         value = 30;
124                 else if(value >= 60 && value < 120)
125                         value = 60;
126                 else if(value >= 120 && value < 300)
127                         value = 120;
128                 else if(value >= 300 && value < 600)
129                         value = 300;
130                 else
131                         value = 600;
132         }
133         else
134         {
135                 if (SETTING_RETURN_FAIL == ret || value < 30)
136                         value = 15;
137                 else if(value >= 30 && value < 60)
138                         value = 30;
139                 else if(value >= 60 && value < 120)
140                         value = 60;
141                 else if(value >= 120 && value < 300)
142                         value = 120;
143                 else if(value >= 300 && value < 600)
144                         value = 300;
145                 else
146                         value = 600;
147         }
148
149         setting_set_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL,
150                                         value, &err);
151         #endif
152 #endif
153
154         if (value == 0) {
155                 snprintf(backlight_time_str, sizeof(backlight_time_str), "%s",
156                          _("IDS_ST_BODY_ALWAYS_ON"));
157         } else if (value == 60) {
158                 snprintf(backlight_time_str, sizeof(backlight_time_str), "%s",
159                          _("IDS_COM_BODY_1_MINUTE"));
160         } else if (value > 60) {
161                 snprintf(backlight_time_str, sizeof(backlight_time_str),
162                          "%d %s", value / 60, (char *)(_("IDS_COM_BODY_MINUTES_LC")));
163         } else {
164                 snprintf(backlight_time_str, sizeof(backlight_time_str),
165                          "%d %s", value, (char *)(_("IDS_COM_BODY_SECONDS_LC")));
166         }
167         return (char *)g_strdup(backlight_time_str);
168 }
169
170 char *get_pa_powersaving_at_str()
171 {
172         int value = 30;
173         char powersaving_at_str[MAX_DISPLAY_NAME_LEN_ON_UI + 1];
174
175         int err;
176         int ret =
177             setting_get_int_slp_key(INT_SLP_SETTING_POWERSAVING_AT, &value,
178                                     &err);
179         if (SETTING_RETURN_FAIL == ret || value < 0) {  /* file system exceptional handle, eg. The vconf file lost due to file system. */
180                 value = 30;     /* keep agree with postin file */
181                 setting_set_int_slp_key(INT_SLP_SETTING_POWERSAVING_AT,
182                                         value, &err);
183         }
184
185         snprintf(powersaving_at_str, MAX_DISPLAY_NAME_LEN_ON_UI, "At %d%% %s",
186                  value, "battery power");
187         return (char *)g_strdup(powersaving_at_str);
188 }
189
190 char *get_pa_screen_timeout_str()
191 {
192         int value = 15;
193         char screen_timeout_str[MAX_DISPLAY_NAME_LEN_ON_UI + 1];
194
195         int err;
196         int ret =
197             setting_get_int_slp_key(INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT,
198                                     &value,
199                                     &err);
200         if (SETTING_RETURN_FAIL == ret || value < 0) {  /* file system exceptional handle, eg. The vconf file lost due to file system. */
201                 value = 15;     /* keep agree with postin file */
202                 setting_set_int_slp_key
203                     (INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT, value, &err);
204         }
205
206         if (value == 60) {
207                 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI, "%s",
208                          _("1 minute"));
209         } else if (value >= 60) {
210                 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
211                          "%d %s", value / 60,
212                          (char *)(_("IDS_COM_BODY_MINUTES_LC")));
213         } else {
214                 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
215                          "%d %s", value,
216                          (char *)(_("IDS_COM_BODY_SECONDS_LC")));
217         }
218         return (char *)g_strdup(screen_timeout_str);
219 }
220
221 char *get_pa_display_language_str()
222 {
223         int ret = SETTING_RETURN_FAIL;
224         int err;
225         int index;
226
227         Eina_List* list = setting_get_language_list();
228         Eina_List* elist = NULL;
229
230         ret = setting_get_int_slp_key(INT_SLP_SETTING_LANG, &index, &err);
231
232         if (0 == index)
233                 return g_strdup("Automatic");
234
235         setting_lang_entry* pnode;
236
237         char* title = NULL;
238     EINA_LIST_FOREACH( list, elist, pnode)
239     {
240                 if (pnode->number == index)
241                 title = g_strdup(pnode->title);
242     }
243         return title;
244 }
245
246 char *get_pa_Wi_Fi_on_off_str()
247 {
248         int value, err;
249         int ret = SETTING_RETURN_FAIL;
250         ret =
251             setting_get_int_slp_key(INT_SLP_SETTING_WIFI_STATUS, &value, &err);
252
253         if (SETTING_RETURN_FAIL == ret) {       /* file system exceptional handle, eg. The vconf file lost due to file system. */
254                 value = VCONFKEY_WIFI_OFF;
255                 setting_set_int_slp_key(INT_SLP_SETTING_WIFI_STATUS,
256                                         VCONFKEY_WIFI_OFF, &err);
257         }
258
259         if (value) {
260                 char *pa_wifi_device = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
261                 SETTING_TRACE("pa_wifi_device:%s", pa_wifi_device);
262                 if (NULL != pa_wifi_device && '\0' != pa_wifi_device[0]) {
263                         return pa_wifi_device;
264                 }
265
266                 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_ON_M_STATUS"));
267         } else {
268                 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_OFF_M_STATUS"));
269         }
270 }
271
272 char *get_Mobile_AP_on_off_str()
273 {
274         int value = -1, err;
275         int ret =
276             setting_get_int_slp_key(INT_SLP_SETTING_MOBILE_AP_STATUS, &value,
277                                     &err);
278
279         /*  7 means bitwise-operation */
280         /*
281               - 1 : wi-fi
282               - 2 : bluetooth
283               - 4 : USB
284               4, 2, 1 = 7
285         */
286         if (0 != ret || value < 0 || value > 7) {
287                 value = 0;
288                 setting_set_int_slp_key(INT_SLP_SETTING_MOBILE_AP_STATUS, value,
289                                         &err);
290         }
291
292         if (value != 0) {
293                 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
294         } else {                /*  0 */
295                 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
296         }
297 }
298
299 char *get_BT_on_off_str()
300 {
301         int ret = SETTING_RETURN_FAIL;
302         int value, err;
303         ret = setting_get_int_slp_key(INT_SLP_SETTING_BT_STATUS, &value, &err);
304
305         if (SETTING_RETURN_FAIL == ret) {       /* file system exceptional handle, eg. The vconf file lost due to file system. */
306                 value = VCONFKEY_BT_STATUS_OFF;
307                 setting_set_int_slp_key(INT_SLP_SETTING_BT_STATUS,
308                                         VCONFKEY_BT_STATUS_OFF, &err);
309         }
310
311         if (VCONFKEY_BT_STATUS_OFF == value) {
312                 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
313         } else {
314                 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
315         }
316 }
317
318 char *get_NFC_on_off_str()
319 {
320         int ret = SETTING_RETURN_FAIL;
321         int value = 0, err = 0;
322         ret = setting_get_bool_slp_key(BOOL_SLP_SETTING_NFC_STATUS, &value, &err);
323
324         if (SETTING_RETURN_FAIL == ret) {       /* file system exceptional handle, eg. The vconf file lost due to file system. */
325                 SETTING_TRACE_DEBUG("fail to get nfc status from vconf");
326                 value = VCONFKEY_NFC_STATE_OFF;
327         }
328
329         if (VCONFKEY_NFC_STATE_OFF == value) {
330                 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
331         } else {
332                 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
333         }
334 }
335
336 char *get_pa_time_format_str()
337 {
338         int ret = SETTING_RETURN_FAIL;
339         int value, err;
340         char *format_str[] = { _("IDS_COM_BODY_12_HOURS"),
341                                 _("IDS_ST_BODY_24_HOURS") };
342         ret =
343             setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
344                                     &value, &err);
345         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
346
347         /*  scope */
348         /*  value 1:12H  2:24H */
349         if (value > 0 && value <= 2)    /*  1, 2 */
350                 return (char *)g_strdup(format_str[value - 1]);
351         else
352                 return (char *)g_strdup(format_str[0]); /*  set to 12H compelsery */
353 }
354
355 /** @deprecated */
356 char *get_pa_date_format_str()
357 {
358         int ret = SETTING_RETURN_FAIL;
359         int value, err;
360         char *format_str[] = { _("IDS_ST_BODY_DDMMYYYY_DOT"),
361                 _("IDS_ST_BODY_MM_DD_YYYY_DOT"),
362                 _("IDS_COM_BODY_YYYYMMDD"), _("IDS_ST_BODY_YYYY_DD_MM_DOT")
363         };
364         ret =
365             setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
366         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
367         return (char *)g_strdup(format_str[value]);
368 }
369
370 char *get_pa_week_format_str()
371 {
372         int ret = SETTING_RETURN_FAIL;
373         int value, err;
374         char *format_str[] = {
375                 _("IDS_ST_BODY_SUNDAY"),
376                 _("IDS_ST_BODY_MONDAY"),
377         };
378
379         ret =
380             setting_get_int_slp_key(INT_SLP_SETTING_WEEK_FORMAT, &value, &err);
381         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
382         return (char *)g_strdup(format_str[value]);
383 }
384
385 char *get_pa_roaming_network_str()
386 {
387         int ret = SETTING_RETURN_FAIL;
388         int value, err;
389         char *roaming_str[] = {
390                 _("IDS_ST_BODY_AUTO_DOWNLOAD"), _("IDS_COM_BODY_MANUAL"),
391                 _("IDS_ST_BODY_ALWAYS_REJECT")
392         };
393         ret =
394             setting_get_int_slp_key(INT_SLP_SETTING_ROAMING_NETWORK, &value,
395                                     &err);
396         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
397         return (char *)g_strdup(roaming_str[value]);
398 }
399
400 double get_widgets_factor()
401 {
402         return elm_scale_get();
403 }
404
405 char *setting_gettext(const char *s)
406 {
407         /* fisrt find in app pg */
408
409         if (s == NULL) {
410                 return "NULL";
411         }
412
413         char *p = dgettext(SETTING_PACKAGE, s);
414
415         if (!safeStrCmp(s, p)) {        /* not found */
416                 /* find in system pkg */
417                 p = dgettext(SYSTEM_PACKAGE, s);
418         }
419         return p;
420 }
421
422 bool is_digital_str(const char *cstr)
423 {
424         if (cstr == NULL || cstr[0] == 0) {
425                 return FALSE;
426         }
427
428         int len = (int)(safeStrLen(cstr));
429         int pos = 0;
430         if (cstr[0] == '-' || cstr[0] == '+') {
431                 if (len <= 1) {
432                         return FALSE;
433                 }
434                 pos++;
435         }
436
437         while (pos < len) {
438                 if (cstr[pos] < '0' || cstr[pos] > '9') {
439                         return FALSE;
440                 }
441                 pos++;
442         }
443
444         return TRUE;
445 }
446
447 bool is_substr_ncase(const char *parentstr, const char *substr)
448 {
449         if (NULL == parentstr || '\0' == parentstr[0])
450                 return FALSE;
451
452         int word_len = safeStrLen(parentstr);
453         int search_len = safeStrLen(substr);
454         int i;
455         bool result = FALSE;
456         for (i = 0; i < word_len; i++) {
457                 if (!strncasecmp(substr, &parentstr[i], search_len)) {
458                         result = TRUE;
459                         break;
460                 }
461         }
462         return result;
463 }
464
465 bool is_string_belong_to_array(const char *partern, const char **array,
466                                int array_num)
467 {
468         int idx = 0;
469         for (; idx < array_num; idx++) {
470                 if (!safeStrCmp(partern, array[idx])) {
471                         return TRUE;
472                 }
473         }
474         return FALSE;
475 }
476
477 bool isEmptyStr(const char *str)
478 {
479         if (NULL == str || str[0] == '\0') {
480                 return TRUE;
481         } else {
482                 return FALSE;
483         }
484 }
485
486 int safeStrCmp(const char *s1, const char *s2)
487 {
488         /*  Check NULL value first */
489         if (isEmptyStr(s1) && isEmptyStr(s2)) {
490                 return 0;
491         } else if (isEmptyStr(s1)) {
492                 return 1;
493         } else if (isEmptyStr(s2)) {
494                 return SETTING_RETURN_FAIL;
495         }
496
497         return strcmp(s1, s2);
498 }
499
500 int safeStrNCmp(const char *s1, const char *s2, int len)
501 {
502
503         /*  Check NULL value first */
504         if (isEmptyStr(s1) && isEmptyStr(s2)) {
505                 return 0;
506         } else if (isEmptyStr(s1)) {
507                 return 1;
508         } else if (isEmptyStr(s2)) {
509                 return SETTING_RETURN_FAIL;
510         }
511
512         if (0 == len) {
513                 return 0;
514         }
515
516         return strncmp(s1, s2, len);
517 }
518
519 char *safeStrNCat(char *dst, const char *src, int maxlen)
520 {
521         if (dst && !isEmptyStr(src) && maxlen > 0) {
522                 (void) g_strlcat(dst, src, maxlen + 1);
523         }
524
525         return dst;
526 }
527
528
529 char *safeCopyStr(char *dst, const char *src, int maxlen)
530 {
531         if (maxlen < 0) {
532                 return NULL;
533         }
534
535         if (dst) {
536                 int len = 0;
537
538                 if (src) {
539                         int temp = (int)safeStrLen(src);
540                         len = (temp <= maxlen) ? temp : maxlen;
541                         memcpy(dst, src, len);
542                 }
543
544                 dst[len] = '\0';
545         }
546
547         return dst;
548 }
549
550 int safeStrLen(const char *str)
551 {
552         if (isEmptyStr(str)) {
553                 SETTING_TRACE_DEBUG("string is empty");
554                 return 0;
555         } else {
556                 return strlen(str);
557         }
558 }
559
560 /**
561 * get the int value of substring before delim
562 */
563 bool get_substring_int(const char **ipStr, int *ipValue, char delim)
564 {
565         int iValue = *ipValue = 0;
566         const char *str = *ipStr;
567
568         if (str == NULL || str[0] == 0) {       /* empty string */
569                 return FALSE;
570         }
571
572         bool bNegative = FALSE;
573         if ('-' == str[0]) {    /* allow Negative number.. */
574                 bNegative = TRUE;
575                 str++;
576         }
577         if (str[0] < '0' || str[0] > '9') {     /* first elementy is not digital */
578                 *ipStr = str;
579                 return FALSE;
580         }
581         if (str[0] == '0') {    /* first elementy is 0 */
582                 if (str[1] == delim) {
583                         str += 2;
584                         *ipStr = str;
585                         return TRUE;
586                 }
587                 if (str[1] == 0) {
588                         str++;
589                         *ipStr = str;
590                         return TRUE;
591                 }
592                 *ipStr = str;
593                 return FALSE;
594         }
595
596         for (;;) {
597 /****first elementy is not 0*/
598                 iValue = iValue * 10 + str[0] - '0';
599                 *ipValue = iValue;
600                 if (((unsigned int)iValue & 0x80000000) != 0) { /* think about overloading */
601                         break;
602                 }
603                 str++;
604                 if (str[0] == delim) {
605                         str++;
606                         if (bNegative) {
607                                 iValue = -iValue;
608                         }
609                         *ipStr = str;
610                         *ipValue = iValue;
611                         return TRUE;
612                 }
613                 if (str[0] == 0) {
614                         if (bNegative) {
615                                 iValue = -iValue;
616                         }
617                         *ipStr = str;
618                         *ipValue = iValue;
619                         return TRUE;
620                 }
621                 if (str[0] < '0' || str[0] > '9') {
622                         break;
623                 }
624         }
625
626         *ipStr = str;
627         return FALSE;
628 }
629
630 #define MaxIPAddressLength      15
631
632 /**
633 * CHeck Whether a special string Is An IP String
634 *
635 * @param ipstr string representing IP numbers like "aaa.bbb.ccc.ddd"
636 *
637 * @return true if it's IP format string otherwise false
638 */
639 bool is_ip_string(const char *ipstr)
640 {
641         if (NULL == ipstr || 0 == ipstr[0])
642                 return FALSE;
643         int len = (int)safeStrLen(ipstr);
644         if (len > MaxIPAddressLength) {
645                 return FALSE;
646         }
647
648         if (ipstr[len - 1] == '.') {
649                 return FALSE;
650         }
651
652         int ip;
653         int i = 0;
654         for (; i < 4; i++) {
655                 if (!get_substring_int(&ipstr, &ip, '.') || ip > 255) {
656                         SETTING_TRACE("ipstr:%s", ipstr);
657                         return FALSE;
658                 }
659                 SETTING_TRACE("ipstr:%s", ipstr);
660         }
661         if (ipstr[0] != 0) {
662                 return FALSE;
663         }
664
665         return TRUE;
666 }
667
668 int setting_invoke_reset_function(char *lib_name, service_h service, void *ext)
669 {
670         SETTING_TRACE("Enter %s with lib_name:%s", __FUNCTION__, lib_name);
671         int (*reset) (service_h pair, void *ptr);
672         int ret = OPERATE_LIB_SUCESS;
673
674         void *handle = dlopen(lib_name, RTLD_LAZY);
675         if (!handle) {
676                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", dlerror());
677                 return LOAD_LIB_FAILED;
678         }
679
680         char *error = NULL;
681         reset = dlsym(handle, "setting_plugin_reset");
682         if ((error = dlerror()) != NULL) {
683                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", error);
684                 dlclose(handle);
685                 return UNDEFINED_LIB_SYMBOL;
686         }
687
688         if (reset)
689                 ret = (*reset) (service, ext);   /*  CALL */
690
691         if (ret < 0) ret += UNDEFINED_LIB_SYMBOL;//from -2 on
692
693         dlclose(handle);
694         return ret;
695 }
696
697 int excuteCmd(char* exec_path, int option_num, ...)
698 {
699         char cmd[MAX_COMMON_BUFFER_LEN + 1] = {0, };
700         snprintf(cmd, MAX_COMMON_BUFFER_LEN,
701                  "%s", exec_path);
702
703
704         va_list args;
705         va_start(args, option_num);
706
707         char *para;
708         int argno = 0;
709         for (; argno < option_num; argno++) {
710                 para = va_arg( args, char *);
711                 SETTING_TRACE("Parameter #%d is: %s", argno, para);
712                 if (para)
713                 {
714                         g_strlcat(cmd, " ", MAX_COMMON_BUFFER_LEN + 1);
715                         g_strlcat(cmd, para, MAX_COMMON_BUFFER_LEN + 1);
716                 }
717         }
718
719         va_end(args);
720
721         SETTING_TRACE("excute:%s", cmd);
722         return system(cmd);
723 }
724
725
726 void create_fontlink(const char *linkpath, const char *linkname,
727                     const char *fontfilepath, const char *fontfilename)
728 {
729         char newpath[MAX_COMMON_BUFFER_LEN + 1];
730         char lcpath[MAX_COMMON_BUFFER_LEN + 1];
731
732         int ret =
733             snprintf(newpath, MAX_COMMON_BUFFER_LEN, "%s/%s", linkpath, linkname);
734         ret_if(ret < 0);
735         snprintf(lcpath, MAX_COMMON_BUFFER_LEN, "%s/%s", fontfilepath, fontfilename);
736
737         SETTING_TRACE("newpath:%s", newpath);
738         SETTING_TRACE("lcpath:%s", lcpath);
739
740         remove(newpath);
741         ret = symlink(lcpath, newpath);
742         setting_retm_if(ret != 0, "fail to call symlink");
743 }
744
745 char* get_icon_path(const char *package)
746 {
747         ail_appinfo_h handle;
748
749         char* ret_str;
750         char *icon_path = IMG_DefaultIcon;//The default icon must exist.(it will be installed by Setting App)
751
752         bool result = TRUE;
753         bool destroy = TRUE;
754
755         if (ail_package_get_appinfo(package, &handle) != AIL_ERROR_OK) {
756                 SETTING_TRACE_ERROR("Failed to ail_package_get_appinfo.");
757                 result = FALSE;
758                 destroy = FALSE;
759         }
760
761         if (result && ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &icon_path) != AIL_ERROR_OK) {
762                 SETTING_TRACE_ERROR("Failed to ail_appinfo_get_str.");
763                 result = FALSE;
764         }
765
766         if (result && access(icon_path, R_OK|F_OK ) !=0 ) {//The file cannot be accessed.
767                 SETTING_TRACE_ERROR("The file[%s] cannot be accessed. To use defaut icon.", icon_path);
768                 icon_path = IMG_DefaultIcon;
769         }
770
771         ret_str = strdup(icon_path);
772         if (destroy && ail_package_destroy_appinfo(handle) != AIL_ERROR_OK) {
773                 SETTING_TRACE_ERROR("Failed to ail_package_destroy_appinfo.");
774         }
775         return ret_str;
776 }
777
778 // SLP : 1
779 // not SLP : 0
780 int is_slp_binary()
781 {
782         dictionary* dic = iniparser_load("/etc/info.ini");
783         char* str = (char *)iniparser_getstr(dic, "Version:Build");
784         char* pos = str;
785         if (str) {
786                 while(*pos++){
787                         if('_' == *pos) {
788                                 *pos = '\0';
789                                 if (!strncmp(str, "SLP", 3)) return 1;
790                         }
791                 }
792         }
793         if (dic) {
794                 iniparser_freedict(dic);
795                 dic = NULL;
796         }
797         return 0;
798 }
799
800 bool isEmulBin()
801 {
802 #if DISABLED_CODE
803         char szEmul[__LEN_STR_EMUL+1];
804         const char* szBinVer = NULL;
805
806         dictionary* dic = iniparser_load(BIN_INFO_FILE_PATH);
807         // when failed to get the info, let's regard the binary as an emulator one
808         if (!dic)
809                 return TRUE;
810
811         szBinVer = (const char*)iniparser_getstr(dic, "Version:Build");
812         if (szBinVer) {
813                 char* str = g_strdup(szBinVer);
814                 if (str) {
815                         char* pPos = str;
816                         while (*pPos++) {
817                                 if ('_' == *pPos)
818                                         *pPos = ' ';
819                         }
820                         sscanf(str, "%*s %4s", szEmul);
821                 }
822                 G_FREE(str);
823         }
824
825         if (dic) {
826                 iniparser_freedict(dic);
827                 dic = NULL;
828         }
829
830         if (!strncmp(szEmul, __STR_EMUL, __LEN_STR_EMUL)) {
831                 return TRUE;
832         } else {
833                 return FALSE;
834         }
835 #else
836         char *model_str = NULL;
837         int ret = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model_str);
838         //SETTING_TRACE("model_str : %s", model_str);
839         if (ret != SYSTEM_INFO_ERROR_NONE) {
840                 SETTING_TRACE_ERROR("fail to call system_info_get_value_string");
841                 FREE(model_str);
842                 return FALSE;
843         }
844
845         if (0 == safeStrCmp(KeyStr_Emulator, model_str)) {
846                 FREE(model_str);
847                 return TRUE;
848         } else {
849                 FREE(model_str);
850                 return FALSE;
851         }
852 #endif
853 }
854
855 int get_popup_btn_response_type(const char *btn_str)
856 {
857         SETTING_TRACE("btn_str:%s", btn_str);
858         POPUP_BTN_RESPONSE_TYPE rsp_type = POPUP_RESPONSE_INVALID;
859         retv_if(!btn_str, rsp_type);
860         if (0 == safeStrCmp(btn_str, _("IDS_COM_BODY_CLOSE"))
861             || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_TRY"))//KeyStr_Try
862             || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_OK"))
863             || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_YES"))
864             || 0 == safeStrCmp(btn_str, _("IDS_ST_BODY_USE_MOTION"))
865             || 0 == safeStrCmp(btn_str, _("IDS_COM_POP_TRY_AGAIN"))
866             || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_DELETE"))
867             || 0 == safeStrCmp(btn_str, _(KeyStr_Save)))
868         {
869                 rsp_type = POPUP_RESPONSE_OK;
870         }
871         else //for others,
872         {
873                 rsp_type = POPUP_RESPONSE_CANCEL;
874         }
875         return rsp_type;
876 }
877
878 #define SUPPORT_STATIC_LOAD 1
879 #if SUPPORT_STATIC_LOAD
880 static char *system_service_list[MAX_SYSTEM_SERVICE_NUM] = {NULL, };
881 #endif
882 void clear_system_service_data()
883 {
884         #if SUPPORT_STATIC_LOAD
885         int idx;
886         for (idx = 0; idx < MAX_SYSTEM_SERVICE_NUM && system_service_list[idx]; idx++)
887         {
888                 FREE(system_service_list[idx]);
889         }
890         #endif
891 }
892
893 bool is_system_service(const char *pkg_name)
894 {
895         //SLP native apps list,
896         if (0 == safeStrCmp(pkg_name, "com.samsung.menu-screen")
897             || 0 == safeStrCmp(pkg_name, "com.samsung.live-data-provider")
898             || 0 == safeStrCmp(pkg_name, "com.samsung.live-magazine")
899             || 0 == safeStrCmp(pkg_name, "com.samsung.pwlock")
900             || 0 == safeStrCmp(pkg_name, "com.samsung.quickpanel")
901             || 0 == safeStrCmp(pkg_name, "com.samsung.vtmain")
902             || 0 == safeStrCmp(pkg_name, "com.samsung.call")
903             || 0 == safeStrCmp(pkg_name, "usb_setting")
904             || 0 == safeStrCmp(pkg_name, "com.samsung.indicator")
905             || 0 == safeStrCmp(pkg_name, "com.samsung.cluster-home")
906            )
907         {
908                 return TRUE;
909         }
910
911         //OSP service app list,
912         bool ret = FALSE;
913 #if SUPPORT_STATIC_LOAD
914         int idx = 0;
915         if (!system_service_list[0]) //just load the file
916         {
917                 FILE *fp = fopen(SYSTEM_SERVICE_LIST_PATH, "r");
918                 if (fp) {
919                         char result[MAX_PKG_NAME_LEN+1] = {0, };
920                         while (fgets(result, MAX_PKG_NAME_LEN, fp))
921                         {
922                                 result[strlen(result) - 1] = '\0';//offset 1
923                                 system_service_list[idx++] = strdup(result);
924                         }
925                         fclose(fp);
926                 }
927
928         }
929
930         for (idx = 0; idx < MAX_SYSTEM_SERVICE_NUM && system_service_list[idx]; idx++)
931         {
932                 if (0 == safeStrCmp(pkg_name, system_service_list[idx])) {
933                         ret = TRUE;
934                         break;
935                 }
936         }
937 #else
938         FILE *fp = fopen(SYSTEM_SERVICE_LIST_PATH, "r");
939         if (fp) {
940                 char result[MAX_PKG_NAME_LEN+1] = {0, };
941                 while (fgets(result, MAX_PKG_NAME_LEN, fp))
942                 {
943                         result[strlen(result) - 1] = '\0';//offset 1
944                         if (0 == safeStrCmp(pkg_name, result)) {
945                                 ret = TRUE;
946                                 break;
947                         }
948                 }
949                 fclose(fp);
950         }
951 #endif
952         SETTING_TRACE("ret:%d", ret);
953         return ret;
954 }
955
956 /**
957   * should use g_free to free returned string
958   */
959 char *get_default_font(int language)
960 {
961         char *font_name = NULL;
962
963         switch(language)
964         {
965         case SETTING_LANG_KOREA:
966                 font_name = g_strdup("SLPSansKorean");
967                 break;
968         case SETTING_LANG_CHINA:
969                 /* output_font : SLPSansFallback*/
970         case SETTING_LANG_CANTONESE:
971                 /* output_font : SLPSansFallback*/
972         case SETTING_LANG_TAIWAN:
973                 font_name = g_strdup("SLPSansFallback");
974                 break;
975         case SETTING_LANG_JAPAN:
976                 font_name = g_strdup("UDGothic");
977                 break;
978         case SETTING_LANG_AUTOMATIC:
979                 /* output_font : HelveticaNeue*/
980         case SETTING_LANG_ENGLISH:
981                 /* output_font : HelveticaNeue*/
982         case SETTING_LANG_GERMAN:
983                 /* output_font : HelveticaNeue*/
984         case SETTING_LANG_DUTCH:
985                 /* output_font : HelveticaNeue*/
986         case SETTING_LANG_SPAINISH:
987                 /* output_font : HelveticaNeue*/
988         case SETTING_LANG_PORTUGUESE:
989                 /* output_font : HelveticaNeue*/
990         case SETTING_LANG_GREEK:
991                 /* output_font : HelveticaNeue*/
992         case SETTING_LANG_ITALIAN:
993                 /* output_font : HelveticaNeue*/
994         case SETTING_LANG_FRENCH:
995                 /* output_font : HelveticaNeue*/
996         case SETTING_LANG_TURKISH:
997                 /* output_font : HelveticaNeue*/
998         case SETTING_LANG_RUSSIAN:
999                 font_name = g_strdup("HelveticaNeue");
1000                 break;
1001         default:
1002                 font_name = g_strdup("HelveticaNeue");
1003                 break;
1004         }
1005         return font_name;
1006 }
1007
1008 void *font_conf_doc_parse(char *doc_name, char *font_name)
1009 {
1010         SETTING_TRACE_BEGIN;
1011         setting_retvm_if(doc_name == NULL, NULL, "Param data is NULL");
1012         setting_retvm_if(font_name == NULL, NULL, "Param data is NULL");
1013         xmlDocPtr doc = NULL;
1014         xmlNodePtr cur = NULL;
1015         xmlNodePtr cur2 = NULL;
1016         xmlNodePtr cur3 = NULL;
1017         xmlChar *key = NULL;
1018
1019         doc = xmlParseFile(doc_name);
1020         setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
1021
1022         cur = xmlDocGetRootElement(doc);
1023
1024         if (cur == NULL) {
1025                 SETTING_TRACE_DEBUG("empty document");
1026                 xmlFreeDoc(doc);
1027                 doc = NULL;
1028                 return NULL;
1029         }
1030
1031         if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1032                 SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
1033                 xmlFreeDoc(doc);
1034                 doc = NULL;
1035                 return NULL;
1036         }
1037
1038         cur = cur->xmlChildrenNode;
1039
1040         while(cur != NULL)
1041         {
1042                 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
1043                 {
1044                         cur2 = cur->xmlChildrenNode;
1045                         while(cur2 != NULL)
1046                         {
1047                                 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
1048                                 {
1049                                         cur3 = cur2->xmlChildrenNode;
1050                                         while(cur3 != NULL)
1051                                         {
1052                                                 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
1053                                                 {
1054                                                         xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
1055                                                         key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1056                                                         SETTING_TRACE_DEBUG("after changed, string is: %s\n", key);
1057                                                         xmlFree(key);
1058                                                         key = NULL;
1059                                                         return doc;
1060                                                 }
1061                                                 cur3 = cur3->next;
1062                                         }
1063                                 }
1064                                 cur2 = cur2->next;
1065                         }
1066                 }
1067                 cur = cur->next;
1068         }
1069
1070         xmlFreeDoc(doc);
1071         doc = NULL;
1072         return NULL;
1073 }
1074
1075 /**
1076  * should use g_free to free return string
1077  */
1078 char *cur_font_get()
1079 {
1080         SETTING_TRACE_BEGIN;
1081         xmlDocPtr doc = NULL;
1082         xmlNodePtr cur = NULL;
1083         xmlNodePtr cur2 = NULL;
1084         xmlNodePtr cur3 = NULL;
1085         xmlChar *key = NULL;
1086
1087         char *font_name = NULL;
1088
1089         doc = xmlParseFile(SETTING_FONT_CONF_FILE);
1090         setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
1091
1092         cur = xmlDocGetRootElement(doc);
1093
1094         if(cur == NULL) {
1095                 SETTING_TRACE_DEBUG("empty document");
1096                 xmlFreeDoc(doc);
1097                 doc = NULL;
1098                 return NULL;
1099         }
1100
1101         if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1102                 SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
1103                 xmlFreeDoc(doc);
1104                 doc = NULL;
1105                 return NULL;
1106         }
1107
1108         cur = cur->xmlChildrenNode;
1109
1110         while(cur != NULL)
1111         {
1112                 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
1113                 {
1114                         cur2 = cur->xmlChildrenNode;
1115                         while(cur2 != NULL)
1116                         {
1117                                 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
1118                                 {
1119                                         cur3 = cur2->xmlChildrenNode;
1120                                         while(cur3 != NULL)
1121                                         {
1122                                                 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
1123                                                 {
1124                                                         key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1125                                                         SETTING_TRACE_DEBUG("string is: %s", key);
1126
1127                                                         font_name = g_strdup((char *)key);
1128                                                         xmlFree(key);
1129                                                         key = NULL;
1130                                                         xmlFreeDoc(doc);
1131                                                         doc = NULL;
1132                                                         return font_name;
1133                                                 }
1134                                                 cur3 = cur3->next;
1135                                         }
1136                                 }
1137                                 cur2 = cur2->next;
1138                         }
1139                 }
1140                 cur = cur->next;
1141         }
1142
1143         xmlFreeDoc(doc);
1144         doc = NULL;
1145         return NULL;
1146 }
1147
1148 static int __font_size_get()
1149 {
1150         int font_size = -1;
1151         int value = -1;
1152         int err = -1;
1153         int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &value, &err);
1154         retvm_if(ret != 0, -1, "get vconf failed");
1155
1156         switch(value) {
1157         case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1158                 font_size = SMALL_FONT_DPI;
1159                 break;
1160         case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1161                 font_size = MIDDLE_FONT_DPI;
1162                 break;
1163         case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1164                 font_size = LARGE_FONT_DPI;
1165                 break;
1166         case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1167                 font_size = HUGE_FONT_DPI;
1168                 break;
1169         case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1170                 font_size = GIANT_FONT_DPI;
1171                 break;
1172         default:
1173                 font_size = MIDDLE_FONT_DPI;
1174                 break;
1175         }
1176         return font_size;
1177 }
1178
1179 void font_config_set(char *font_name)
1180 {
1181         Eina_List *text_classes = NULL;
1182         Elm_Text_Class *etc = NULL;
1183         const Eina_List *l = NULL;
1184         Eina_List *fo_list = NULL;
1185         Elm_Font_Overlay *efo = NULL;
1186         int font_size = __font_size_get();
1187         int size = 0;
1188
1189         text_classes = elm_config_text_classes_list_get();
1190
1191         fo_list = (Eina_List *)elm_config_font_overlay_list_get();
1192
1193         Eina_List *ll = NULL;
1194         Eina_List *l_next = NULL;
1195
1196         Eina_Bool slp_medium_exist = EINA_FALSE;
1197         Eina_Bool slp_roman_exist = EINA_FALSE;
1198         Eina_Bool slp_bold_exist = EINA_FALSE;
1199         Eina_Bool slp_regular_exist = EINA_FALSE;
1200
1201         EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
1202         {
1203                 if (!safeStrCmp(efo->text_class, "slp_medium")) {
1204                         elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1205                         slp_medium_exist = EINA_TRUE;
1206                 } else if (!safeStrCmp(efo->text_class, "slp_roman")) {
1207                         elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1208                         slp_roman_exist = EINA_TRUE;
1209                 } else if (!safeStrCmp(efo->text_class, "slp_bold")) {
1210                         elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1211                         slp_bold_exist = EINA_TRUE;
1212                 } else if (!safeStrCmp(efo->text_class, "slp_regular")) {
1213                         elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1214                         slp_regular_exist = EINA_TRUE;
1215                 }
1216         }
1217
1218         /* if slp_XX do not exist, need to set them, font size is -100(100%) */
1219         if (slp_medium_exist == EINA_FALSE) {
1220                 elm_config_font_overlay_set("slp_medium", (const char*)font_name,  MIDDLE_FONT_DPI);
1221         }
1222         if (slp_roman_exist == EINA_FALSE) {
1223                 elm_config_font_overlay_set("slp_roman", (const char*)font_name,  MIDDLE_FONT_DPI);
1224         }
1225         if (slp_bold_exist == EINA_FALSE) {
1226                 elm_config_font_overlay_set("slp_bold", (const char*)font_name,  MIDDLE_FONT_DPI);
1227         }
1228         if (slp_regular_exist == EINA_FALSE) {
1229                 elm_config_font_overlay_set("slp_regular", (const char*)font_name,  MIDDLE_FONT_DPI);
1230         }
1231
1232         EINA_LIST_FOREACH(text_classes, l, etc)
1233         {
1234                 ll = NULL;
1235
1236                 size = font_size;
1237                 EINA_LIST_FOREACH(fo_list, ll, efo)
1238                 {
1239                         if (!safeStrCmp(etc->name, efo->text_class)) {
1240                                 size = efo->size;
1241                         }
1242                 }
1243                 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
1244         }
1245
1246         elm_config_font_overlay_apply();
1247         elm_config_all_flush();
1248         elm_config_engine_set("software_x11");
1249         elm_config_save();
1250         elm_config_text_classes_list_free(text_classes);
1251         text_classes = NULL;
1252
1253         // vconf update
1254         vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
1255 }
1256
1257 void font_size_set()
1258 {
1259         Eina_List *text_classes = NULL;
1260         Elm_Text_Class *etc = NULL;
1261         const Eina_List *l = NULL;
1262         int font_size = __font_size_get();
1263         char *font_name = cur_font_get();
1264
1265         if (font_size == -1) {
1266                 SETTING_TRACE_DEBUG("failed to call font_size_get");
1267                 return;
1268         }
1269
1270         text_classes = elm_config_text_classes_list_get();
1271
1272         EINA_LIST_FOREACH(text_classes, l, etc)
1273         {
1274                 elm_config_font_overlay_set(etc->name, font_name, font_size);
1275         }
1276
1277         elm_config_all_flush();
1278         elm_config_engine_set("software_x11");
1279         elm_config_save();
1280         elm_config_text_classes_list_free(text_classes);
1281         text_classes = NULL;
1282         G_FREE(font_name);
1283 }