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