apply FSL license
[apps/home/settings.git] / setting-common / src / setting-common-general-func.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.tizenopensource.org/license
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17
18 #include <ail.h>
19 #include <setting-common-general-func.h>
20 #include <setting-common-data-slp-setting.h>
21
22 #include <glib.h>
23 #include <iniparser.h>
24 #include <dlfcn.h>
25 #define SETTING_USB_DEFAULT_MODE        0
26 #define DEFAULT_USB_BUF_SIZE    64
27
28 char *setting_file_basename(char *path)
29 {
30         if (NULL == path || '\0' == path[0]) {
31                 return NULL;    /* invalid arguement */
32         }
33         char *p = strrchr(path, '/');
34         if (!p) {
35                 return (char *)g_strdup(path);  /*  cannot find '/' */
36         }
37         if ('\0' == p[1]) {
38                 return NULL;    /* end with '/' */
39         }
40         return (char *)g_strdup(p + 1);
41 }
42
43 char *get_pa_usb_connect_mode_str()
44 {
45         int ret = SETTING_RETURN_FAIL;
46         int value, selMode;
47         char title_default_usb_subtitle[DEFAULT_USB_BUF_SIZE];
48
49         ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &value);
50         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
51
52         switch (value)
53         {
54         case SETTING_USB_NONE_MODE:
55                 ret = vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, &selMode);
56                 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");
57                 if (SETTING_USB_DEBUG_MODE == selMode)
58                         return (char*)g_strdup(_("IDS_ST_BODY_USB_DEBUGGING"));
59         case SETTING_USB_DEFAULT_MODE:
60                 snprintf(title_default_usb_subtitle, DEFAULT_USB_BUF_SIZE, "USB %s",  _("IDS_COM_BODY_DEFAULT"));
61                 return (char*)g_strdup(title_default_usb_subtitle);
62         case SETTING_USB_DEBUG_MODE:
63                 return (char*)g_strdup(_("IDS_ST_BODY_USB_DEBUGGING"));
64         default:
65                 return NULL;
66         }
67 }
68
69 char *get_pa_theme_name_str()
70 {
71         int ret = SETTING_RETURN_FAIL;
72         int err;
73         char value[SETTING_STR_SLP_LEN] = { 0, };
74         char *name;
75         char *ext;
76         ret = setting_get_string_slp_key(STR_SLP_SETTING_THEME_NAME, value, &err);
77         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
78
79         name = strrchr(value, '/');
80         ext = strstr(value, ".edj");
81
82         if (!name)
83                 name = value;
84         else
85                 ++name;
86
87         if (!ext)
88                 ext = value + safeStrLen(value);
89
90         if (0 == safeStrCmp("tizen-black-hd", name)) {
91                 return (char *)g_strdup(_("IDS_ST_BODY_BLACK"));
92         } else if (0 == safeStrCmp("tizen-hd", name)) {
93                 return (char *)g_strdup(_("IDS_ST_BODY_WHITE"));
94         } else {
95                 return (char *)g_strndup(name, ext - name);
96         }
97 }
98
99 char *get_brightness_mode_str()
100 {
101         int value, err;
102         setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_BRIGHTNESS, &value,
103                                  &err);
104         if (value) {
105                 return setting_gettext("IDS_COM_BODY_AUTOMATIC");
106         } else {
107                 return setting_gettext("IDS_COM_BODY_MANUAL");
108         }
109 }
110
111 char *get_pa_backlight_time_str()
112 {
113         int value = 30;
114         char backlight_time_str[MAX_DISPLAY_NAME_LEN_ON_UI];
115
116         int err;
117         int ret =
118             setting_get_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL, &value,
119                                     &err);
120         if (SETTING_RETURN_FAIL == ret || value < 0) {  /* file system exceptional handle, eg. The vconf file lost due to file system. */
121                 value = 30;     /* keep agree with postin file */
122                 setting_set_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL,
123                                         value, &err);
124         }
125
126         if (value == 60) {
127                 snprintf(backlight_time_str, sizeof(backlight_time_str), "%s",
128                          _("1 minute"));
129         } else if (value >= 60) {
130                 snprintf(backlight_time_str, sizeof(backlight_time_str),
131                          "%d %s", value / 60, (char *)(_("IDS_COM_BODY_MINUTES_LC")));
132         } else {
133                 snprintf(backlight_time_str, sizeof(backlight_time_str),
134                          "%d %s", value, (char *)(_("IDS_COM_BODY_SECONDS_LC")));
135         }
136         return (char *)g_strdup(backlight_time_str);
137 }
138
139 char *get_pa_powersaving_at_str()
140 {
141         int value = 30;
142         char powersaving_at_str[MAX_DISPLAY_NAME_LEN_ON_UI + 1];
143
144         int err;
145         int ret =
146             setting_get_int_slp_key(INT_SLP_SETTING_POWERSAVING_AT, &value,
147                                     &err);
148         if (SETTING_RETURN_FAIL == ret || value < 0) {  /* file system exceptional handle, eg. The vconf file lost due to file system. */
149                 value = 30;     /* keep agree with postin file */
150                 setting_set_int_slp_key(INT_SLP_SETTING_POWERSAVING_AT,
151                                         value, &err);
152         }
153
154         snprintf(powersaving_at_str, MAX_DISPLAY_NAME_LEN_ON_UI, "%d%% %s",
155                  value, "battery power");
156         return (char *)g_strdup(powersaving_at_str);
157 }
158
159 char *get_pa_screen_timeout_str()
160 {
161         int value = 15;
162         char screen_timeout_str[MAX_DISPLAY_NAME_LEN_ON_UI + 1];
163
164         int err;
165         int ret =
166             setting_get_int_slp_key(INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT,
167                                     &value,
168                                     &err);
169         if (SETTING_RETURN_FAIL == ret || value < 0) {  /* file system exceptional handle, eg. The vconf file lost due to file system. */
170                 value = 15;     /* keep agree with postin file */
171                 setting_set_int_slp_key
172                     (INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT, value, &err);
173         }
174
175         if (value == 60) {
176                 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI, "%s",
177                          _("1 minute"));
178         } else if (value >= 60) {
179                 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
180                          "%d %s", value / 60,
181                          (char *)(_("IDS_COM_BODY_MINUTES_LC")));
182         } else {
183                 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
184                          "%d %s", value,
185                          (char *)(_("IDS_COM_BODY_SECONDS_LC")));
186         }
187         return (char *)g_strdup(screen_timeout_str);
188 }
189
190 char *get_pa_display_language_str()
191 {
192         int ret = SETTING_RETURN_FAIL;
193         int err;
194         int index;
195         setting_lang_entry* table = setting_get_language_table();
196         ret = setting_get_int_slp_key(INT_SLP_SETTING_LANG, &index, &err);
197         return (char *)g_strdup(table[index].title); // "auto"
198 }
199
200 char *setting_pa_main_get_language()
201 {
202         setting_lang_entry* table = setting_get_language_table();
203         char* pa_path = vconf_get_str(VCONFKEY_LANGSET);
204
205         int i;
206         for (i=0; i<SETTING_LANG_MAX; i++) {
207                 if ( ! strcmp(table[i].locale, pa_path) )
208                 {
209                         FREE(pa_path);
210                         return (char *)g_strdup(table[i].locale);
211                 }
212         }
213         FREE(pa_path);
214         return (char *)g_strdup(table[0].locale);       // "auto"
215 }
216
217 char *get_pa_Wi_Fi_on_off_str()
218 {
219         int value, err;
220         int ret = SETTING_RETURN_FAIL;
221         ret =
222             setting_get_int_slp_key(INT_SLP_SETTING_WIFI_STATUS, &value, &err);
223
224         if (SETTING_RETURN_FAIL == ret) {       /* file system exceptional handle, eg. The vconf file lost due to file system. */
225                 value = VCONFKEY_WIFI_OFF;
226                 setting_set_int_slp_key(INT_SLP_SETTING_WIFI_STATUS,
227                                         VCONFKEY_WIFI_OFF, &err);
228         }
229
230         if (value) {
231                 char *pa_wifi_device = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
232                 SETTING_TRACE("pa_wifi_device:%s", pa_wifi_device);
233                 if (NULL != pa_wifi_device && '\0' != pa_wifi_device[0]) {
234                         return pa_wifi_device;
235                 }
236
237                 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_ON_M_STATUS"));
238         } else {
239                 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_OFF_M_STATUS"));
240         }
241 }
242
243 char *get_Mobile_AP_on_off_str()
244 {
245         int value = -1, err;
246         int ret =
247             setting_get_int_slp_key(INT_SLP_SETTING_MOBILE_AP_STATUS, &value,
248                                     &err);
249
250         /*  7 means bitwise-operation */
251         /*
252               - 1 : wi-fi
253               - 2 : bluetooth
254               - 4 : USB
255               4, 2, 1 = 7
256         */
257         if (0 != ret || value < 0 || value > 7) {
258                 value = 0;
259                 setting_set_int_slp_key(INT_SLP_SETTING_MOBILE_AP_STATUS, value,
260                                         &err);
261         }
262
263         if (value != 0) {
264                 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
265         } else {                /*  0 */
266                 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
267         }
268 }
269
270 char *get_BT_on_off_str()
271 {
272         int ret = SETTING_RETURN_FAIL;
273         int value, err;
274         ret = setting_get_int_slp_key(INT_SLP_SETTING_BT_STATUS, &value, &err);
275
276         if (SETTING_RETURN_FAIL == ret) {       /* file system exceptional handle, eg. The vconf file lost due to file system. */
277                 value = VCONFKEY_BT_STATUS_OFF;
278                 setting_set_int_slp_key(INT_SLP_SETTING_BT_STATUS,
279                                         VCONFKEY_BT_STATUS_OFF, &err);
280         }
281
282         if (VCONFKEY_BT_STATUS_OFF == value) {
283                 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
284         } else {
285                 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
286         }
287 }
288
289 char *get_pa_time_format_str()
290 {
291         int ret = SETTING_RETURN_FAIL;
292         int value, err;
293         char *format_str[] = { _("IDS_COM_BODY_12_HOURS"),
294                                 _("IDS_ST_BODY_24_HOURS") };
295         ret =
296             setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
297                                     &value, &err);
298         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
299
300         /*  scope */
301         /*  value 1:12H  2:24H */
302         if (value > 0 && value <= 2)    /*  1, 2 */
303                 return (char *)g_strdup(format_str[value - 1]);
304         else
305                 return (char *)g_strdup(format_str[0]); /*  set to 12H compelsery */
306 }
307
308 /** @deprecated */
309 char *get_pa_date_format_str()
310 {
311         int ret = SETTING_RETURN_FAIL;
312         int value, err;
313         char *format_str[] = { _("IDS_ST_BODY_DDMMYYYY_DOT"),
314                 _("IDS_ST_BODY_MM_DD_YYYY_DOT"),
315                 _("IDS_COM_BODY_YYYYMMDD"), _("IDS_ST_BODY_YYYY_DD_MM_DOT")
316         };
317         ret =
318             setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
319         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
320         return (char *)g_strdup(format_str[value]);
321 }
322
323 char *get_pa_week_format_str()
324 {
325         int ret = SETTING_RETURN_FAIL;
326         int value, err;
327         char *format_str[] = {
328                 _("IDS_ST_BODY_SUNDAY"),
329                 _("IDS_ST_BODY_MONDAY"),
330                 _("IDS_ST_BODY_TUESDAY"),
331                 _("IDS_ST_BODY_WEDNESDAY"),
332                 _("IDS_ST_BODY_THURSDAY"),
333                 _("IDS_ST_BODY_FRIDAY"),
334                 _("IDS_ST_BODY_SATURDAY"),
335         };
336
337         ret =
338             setting_get_int_slp_key(INT_SLP_SETTING_WEEK_FORMAT, &value, &err);
339         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
340         return (char *)g_strdup(format_str[value]);
341 }
342
343 char *get_pa_roaming_network_str()
344 {
345         int ret = SETTING_RETURN_FAIL;
346         int value, err;
347         char *roaming_str[] = {
348                 _("IDS_ST_BODY_AUTO_DOWNLOAD"), _("IDS_COM_BODY_MANUAL"),
349                 _("IDS_ST_BODY_ALWAYS_REJECT")
350         };
351         ret =
352             setting_get_int_slp_key(INT_SLP_SETTING_ROAMING_NETWORK, &value,
353                                     &err);
354         setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value");        /* file system exceptional handle */
355         return (char *)g_strdup(roaming_str[value]);
356 }
357
358 double get_widgets_factor()
359 {
360         return elm_scale_get();
361 }
362
363 static Theme_Type g_theme_type = Theme_Invalid;
364
365
366 Theme_Type setting_get_theme()
367 {
368         if (Theme_Invalid == g_theme_type) {
369                 int ret = SETTING_RETURN_FAIL;
370                 int err;
371                 char value[SETTING_STR_SLP_LEN] = { 0, };
372                 char *name;
373                 char *ext;
374                 ret =
375                     setting_get_string_slp_key(STR_SLP_SETTING_THEME_NAME,
376                                                value, &err);
377                 setting_retvm_if(SETTING_RETURN_FAIL == ret, Theme_ERROR, "Failed to get vconf value"); /* file system exceptional handle */
378
379                 name = strrchr(value, '/');
380                 ext = strstr(value, ".edj");
381
382                 if (!name)
383                         name = value;
384                 else
385                         ++name;
386
387                 if (!ext)
388                         ext = value + safeStrLen(value);
389
390                 /* special theme process.. */
391                 if (0 == safeStrCmp("tizen-black", name) || 0 == safeStrCmp("tizen-black-hd", name)) {
392                         g_theme_type = Theme_Tizen_Black;
393                 } else if (0 == safeStrCmp("tizen", name) || 0 == safeStrCmp("tizen-hd", name)) {
394                         g_theme_type = Theme_Tizen;
395                 } else if (0 == safeStrCmp("tizen-blue", name)) {
396                         g_theme_type = Theme_Tizen_Blue;
397                 } else if (0 == safeStrCmp("grey-hd", name)) {
398                         g_theme_type = Theme_Tizen_Grey;
399                 } else {
400                         g_theme_type = Theme_ERROR;
401                 }
402         }
403
404         return g_theme_type;
405 }
406
407 char *setting_gettext(const char *s)
408 {
409         /* fisrt find in app pg */
410
411         if (s == NULL) {
412                 return "NULL";
413         }
414
415         char *p = dgettext(SETTING_PACKAGE, s);
416
417         if (!safeStrCmp(s, p)) {        /* not found */
418                 /* find in system pkg */
419                 p = dgettext(SYSTEM_PACKAGE, s);
420         }
421         return p;
422 }
423
424 bool is_digital_str(const char *cstr)
425 {
426         if (cstr == NULL || cstr[0] == 0) {
427                 return FALSE;
428         }
429
430         int len = (int)(safeStrLen(cstr));
431         int pos = 0;
432         if (cstr[0] == '-' || cstr[0] == '+') {
433                 if (len <= 1) {
434                         return FALSE;
435                 }
436                 pos++;
437         }
438
439         while (pos < len) {
440                 if (cstr[pos] < '0' || cstr[pos] > '9') {
441                         return FALSE;
442                 }
443                 pos++;
444         }
445
446         return TRUE;
447 }
448
449 bool is_substr_ncase(const char *parentstr, const char *substr)
450 {
451         if (NULL == parentstr || '\0' == parentstr[0])
452                 return FALSE;
453
454         int word_len = safeStrLen(parentstr);
455         int search_len = safeStrLen(substr);
456         int i;
457         bool result = FALSE;
458         for (i = 0; i < word_len; i++) {
459                 if (!strncasecmp(substr, &parentstr[i], search_len)) {
460                         result = TRUE;
461                         break;
462                 }
463         }
464         return result;
465 }
466
467 bool is_string_belong_to_array(const char *partern, const char **array,
468                                int array_num)
469 {
470         int idx = 0;
471         for (; idx < array_num; idx++) {
472                 if (!safeStrCmp(partern, array[idx])) {
473                         return TRUE;
474                 }
475         }
476         return FALSE;
477 }
478
479 bool isEmptyStr(const char *str)
480 {
481         if (NULL == str || str[0] == '\0') {
482                 return TRUE;
483         } else {
484                 return FALSE;
485         }
486 }
487
488 int safeStrCmp(const char *s1, const char *s2)
489 {
490         /*  Check NULL value first */
491         if (isEmptyStr(s1) && isEmptyStr(s2)) {
492                 return 0;
493         } else if (isEmptyStr(s1)) {
494                 return 1;
495         } else if (isEmptyStr(s2)) {
496                 return SETTING_RETURN_FAIL;
497         }
498
499         return strcmp(s1, s2);
500 }
501
502 int safeStrNCmp(const char *s1, const char *s2, int len)
503 {
504
505         /*  Check NULL value first */
506         if (isEmptyStr(s1) && isEmptyStr(s2)) {
507                 return 0;
508         } else if (isEmptyStr(s1)) {
509                 return 1;
510         } else if (isEmptyStr(s2)) {
511                 return SETTING_RETURN_FAIL;
512         }
513
514         if (0 == len) {
515                 return 0;
516         }
517
518         return strncmp(s1, s2, len);
519 }
520
521 char *safeStrNCat(char *dst, const char *src, int maxlen)
522 {
523         if (dst && !isEmptyStr(src) && maxlen > 0) {
524                 (void) g_strlcat(dst, src, maxlen + 1);
525         }
526
527         return dst;
528 }
529
530
531 char *safeCopyStr(char *dst, const char *src, int maxlen)
532 {
533         if (maxlen < 0) {
534                 return NULL;
535         }
536
537         if (dst) {
538                 int len = 0;
539
540                 if (src) {
541                         int temp = (int)safeStrLen(src);
542                         len = (temp <= maxlen) ? temp : maxlen;
543                         memcpy(dst, src, len);
544                 }
545
546                 dst[len] = '\0';
547         }
548
549         return dst;
550 }
551
552 int safeStrLen(const char *str)
553 {
554         if (isEmptyStr(str)) {
555                 SETTING_TRACE_DEBUG("string is empty");
556                 return 0;
557         } else {
558                 return strlen(str);
559         }
560 }
561
562 /**
563 * get the int value of substring before delim
564 */
565 bool get_substring_int(const char **ipStr, int *ipValue, char delim)
566 {
567         int iValue = *ipValue = 0;
568         const char *str = *ipStr;
569
570         if (str == NULL || str[0] == 0) {       /* empty string */
571                 return FALSE;
572         }
573
574         bool bNegative = FALSE;
575         if ('-' == str[0]) {    /* allow Negative number.. */
576                 bNegative = TRUE;
577                 str++;
578         }
579         if (str[0] < '0' || str[0] > '9') {     /* first elementy is not digital */
580                 *ipStr = str;
581                 return FALSE;
582         }
583         if (str[0] == '0') {    /* first elementy is 0 */
584                 if (str[1] == delim) {
585                         str += 2;
586                         *ipStr = str;
587                         return TRUE;
588                 }
589                 if (str[1] == 0) {
590                         str++;
591                         *ipStr = str;
592                         return TRUE;
593                 }
594                 *ipStr = str;
595                 return FALSE;
596         }
597
598         for (;;) {
599 /****first elementy is not 0*/
600                 iValue = iValue * 10 + str[0] - '0';
601                 *ipValue = iValue;
602                 if (((unsigned int)iValue & 0x80000000) != 0) { /* think about overloading */
603                         break;
604                 }
605                 str++;
606                 if (str[0] == delim) {
607                         str++;
608                         if (bNegative) {
609                                 iValue = -iValue;
610                         }
611                         *ipStr = str;
612                         *ipValue = iValue;
613                         return TRUE;
614                 }
615                 if (str[0] == 0) {
616                         if (bNegative) {
617                                 iValue = -iValue;
618                         }
619                         *ipStr = str;
620                         *ipValue = iValue;
621                         return TRUE;
622                 }
623                 if (str[0] < '0' || str[0] > '9') {
624                         break;
625                 }
626         }
627
628         *ipStr = str;
629         return FALSE;
630 }
631
632 #define MaxIPAddressLength      15
633
634 /**
635 * CHeck Whether a special string Is An IP String
636 *
637 * @param ipstr string representing IP numbers like "aaa.bbb.ccc.ddd"
638 *
639 * @return true if it's IP format string otherwise false
640 */
641 bool is_ip_string(const char *ipstr)
642 {
643         if (NULL == ipstr || 0 == ipstr[0])
644                 return FALSE;
645         int len = (int)safeStrLen(ipstr);
646         if (len > MaxIPAddressLength) {
647                 return FALSE;
648         }
649
650         if (ipstr[len - 1] == '.') {
651                 return FALSE;
652         }
653
654         int ip;
655         int i = 0;
656         for (; i < 4; i++) {
657                 if (!get_substring_int(&ipstr, &ip, '.') || ip > 255) {
658                         SETTING_TRACE("ipstr:%s", ipstr);
659                         return FALSE;
660                 }
661                 SETTING_TRACE("ipstr:%s", ipstr);
662         }
663         if (ipstr[0] != 0) {
664                 return FALSE;
665         }
666
667         return TRUE;
668 }
669
670 int setting_invoke_reset_function(char *lib_name, bundle *data, void *ext)
671 {
672         SETTING_TRACE("Enter %s with lib_name:%s", __FUNCTION__, lib_name);
673         int (*reset) (bundle *pair, void *ptr);
674         int ret = OPERATE_LIB_SUCESS;
675
676         void *handle = dlopen(lib_name, RTLD_LAZY);
677         if (!handle) {
678                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", dlerror());
679                 return LOAD_LIB_FAILED;
680         }
681
682         char *error = NULL;
683         reset = dlsym(handle, "setting_plugin_reset");
684         if ((error = dlerror()) != NULL) {
685                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", error);
686                 dlclose(handle);
687                 return UNDEFINED_LIB_SYMBOL;
688         }
689
690         if (reset)
691                 ret = (*reset) (data, ext);   /*  CALL */
692
693         if (ret < 0) ret += UNDEFINED_LIB_SYMBOL;//from -2 on
694
695         dlclose(handle);
696         return ret;
697 }
698
699 int excuteCmd(char* exec_path, int option_num, ...)
700 {
701         char cmd[MAX_COMMON_BUFFER_LEN + 1] = {0, };
702         snprintf(cmd, MAX_COMMON_BUFFER_LEN,
703                  "%s", exec_path);
704
705
706         va_list args;
707         va_start(args, option_num);
708
709         char *para;
710         int argno = 0;
711         for (; argno < option_num; argno++) {
712                 para = va_arg( args, char *);
713                 SETTING_TRACE("Parameter #%d is: %s", argno, para);
714                 if (para)
715                 {
716                         g_strlcat(cmd, " ", MAX_COMMON_BUFFER_LEN + 1);
717                         g_strlcat(cmd, para, MAX_COMMON_BUFFER_LEN + 1);
718                 }
719         }
720
721         va_end(args);
722
723         SETTING_TRACE("excute:%s", cmd);
724         return system(cmd);
725 }
726
727 void set_font_dpi(short size)
728 {
729         char buf[MAX_COMMON_BUFFER_LEN +1];
730         const char *xrespath = "/opt/etc/X11/Xresources";
731         int ret = snprintf(buf, sizeof(buf), "/bin/echo \"Xft.dpi: %d\" > %s", size,
732                            xrespath);
733         ret_if(ret < 0);
734
735         ret = system(buf);//echo Xft.dpi: 48 > /opt/etc/X11/Xresources
736         if ( ret == -1) {
737                 SETTING_TRACE_ERROR("Xft.dpi error \n");
738                 abort();
739         }
740
741
742         snprintf(buf, MAX_COMMON_BUFFER_LEN, "/usr/bin/xrdb -nocpp -load %s", xrespath);
743         ret = system(buf);
744         if ( ret == -1) {
745                 SETTING_TRACE_ERROR("xrdb -nocpp -load \n");
746                 abort();
747         } else {
748                 SETTING_TRACE("xrdb -nocpp -load - DONE \n");
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         symlink(lcpath, newpath);
768 }
769
770 char* get_icon_path(const char *package)
771 {
772     ail_appinfo_h handle;
773
774     char* ret_str;
775         char *icon_path = IMG_DefaultIcon;//The default icon must exist.(it will be installed by Setting App)
776
777         bool result = TRUE;
778         bool destroy = TRUE;
779
780         if (ail_package_get_appinfo(package, &handle) != AIL_ERROR_OK) {
781                 SETTING_TRACE_ERROR("Failed to ail_package_get_appinfo.");
782                 result = FALSE;
783                 destroy = FALSE;
784     }
785
786         if (result && ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &icon_path) != AIL_ERROR_OK) {
787                 SETTING_TRACE_ERROR("Failed to ail_appinfo_get_str.");
788                 result = FALSE;
789     }
790
791         if (result && access(icon_path, R_OK|F_OK ) !=0 ) {//The file cannot be accessed.
792                 SETTING_TRACE_ERROR("The file[%s] cannot be accessed. To use defaut icon.", icon_path);
793                 icon_path = IMG_DefaultIcon;
794     }
795
796         ret_str = strdup(icon_path);
797         if (destroy && ail_package_destroy_appinfo(handle) != AIL_ERROR_OK) {
798                 SETTING_TRACE_ERROR("Failed to ail_package_destroy_appinfo.");
799         }
800         return ret_str;
801 }
802
803 bool isEmulBin()
804 {
805         char szEmul[__LEN_STR_EMUL+1];
806         const char* szBinVer = NULL;
807
808         dictionary* dic = iniparser_load(BIN_INFO_FILE_PATH);
809 // when failed to get the info, let's regard the binary as an emulator one
810         if (!dic)
811                 return TRUE;
812
813         szBinVer = (const char*)iniparser_getstr(dic, "Version:Build");
814         if (szBinVer) {
815                 char* str = g_strdup(szBinVer);
816                 if (str) {
817                         char* pPos = str;
818                         while (*pPos++) {
819                                 if ('_' == *pPos)
820                                         *pPos = ' ';
821                         }
822                         sscanf(str, "%*s %4s", szEmul);
823                 }
824                 G_FREE(str);
825         }
826
827         if (dic) {
828                 iniparser_freedict(dic);
829                 dic = NULL;
830         }
831
832         if (!strncmp(szEmul, __STR_EMUL, __LEN_STR_EMUL)) {
833                 return TRUE;
834         } else {
835                 return FALSE;
836         }
837 }
838
839 int get_popup_btn_response_type(const char *btn_str)
840 {
841         SETTING_TRACE("btn_str:%s", btn_str);
842         POPUP_BTN_RESPONSE_TYPE rsp_type = POPUP_RESPONSE_INVALID;
843         retv_if(!btn_str, rsp_type);
844         if (0 == safeStrCmp(btn_str, _("IDS_COM_BODY_CLOSE"))
845             || 0 == safeStrCmp(btn_str, _("Try"))//KeyStr_Try
846             || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_OK"))
847             || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_YES"))
848             || 0 == safeStrCmp(btn_str, _("IDS_ST_BODY_USE_MOTION"))
849             || 0 == safeStrCmp(btn_str, _("IDS_COM_POP_TRY_AGAIN"))
850             || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_DELETE")))
851         {
852                 rsp_type = POPUP_RESPONSE_OK;
853         }
854         else //for others, 
855         {
856                 rsp_type = POPUP_RESPONSE_CANCEL;
857         }
858         return rsp_type;
859 }
860
861