4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <setting-common-general-func.h>
23 #include <setting-common-data-slp-setting.h>
27 #include <libxml/xmlmemory.h>
28 #include <libxml/parser.h>
29 #include <system_info.h>
31 #include <system_settings.h>
33 char *setting_file_basename(char *path)
35 if (NULL == path || '\0' == path[0]) {
36 return NULL; /* invalid arguement */
38 char *p = strrchr(path, '/');
40 return (char *)g_strdup(path); /* cannot find '/' */
43 return NULL; /* end with '/' */
45 return (char *)g_strdup(p + 1);
48 char *get_brightness_mode_str()
51 setting_get_int_slp_key(INT_SLP_SETTING_AUTOMATIC_BRIGHTNESS, &value,
53 if (value != SETTING_BRIGHTNESS_AUTOMATIC_OFF) {
54 return setting_gettext("IDS_COM_BODY_AUTOMATIC");
56 return setting_gettext("IDS_COM_BODY_MANUAL");
60 char *get_pa_backlight_time_str()
63 char backlight_time_str[MAX_DISPLAY_NAME_LEN_ON_UI];
65 #if SUPPORT_LCD_TIMEOUT_KEEPING
66 if (0 != vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &value)) {
69 value = 0; /* keep agree with postin file */
72 vconf_set_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, value);
77 setting_get_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL, &value,
80 if (SETTING_RETURN_FAIL == ret || value < 0) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
83 value = 0; /* keep agree with postin file */
86 setting_set_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL,
89 #else // for MDM server
95 // if 120 < < 300, 120
96 // if 300 < < 600, 300
100 if (SETTING_RETURN_FAIL == ret || value < 15)
102 else if(value >= 15 && value < 30)
104 else if(value >= 30 && value < 60)
106 else if(value >= 60 && value < 120)
108 else if(value >= 120 && value < 300)
110 else if(value >= 300 && value < 600)
117 if (SETTING_RETURN_FAIL == ret || value < 30)
119 else if(value >= 30 && value < 60)
121 else if(value >= 60 && value < 120)
123 else if(value >= 120 && value < 300)
125 else if(value >= 300 && value < 600)
131 setting_set_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL,
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")));
146 snprintf(backlight_time_str, sizeof(backlight_time_str),
147 "%d %s", value, (char *)(_("IDS_COM_BODY_SECONDS_LC")));
149 return (char *)g_strdup(backlight_time_str);
152 char *get_pa_powersaving_at_str()
155 char powersaving_at_str[MAX_DISPLAY_NAME_LEN_ON_UI + 1];
159 setting_get_int_slp_key(INT_SLP_SETTING_POWERSAVING_AT, &value,
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,
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);
172 char *get_pa_screen_timeout_str()
175 char screen_timeout_str[MAX_DISPLAY_NAME_LEN_ON_UI + 1];
179 setting_get_int_slp_key(INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT,
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);
189 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI, "%s",
191 } else if (value >= 60) {
192 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
194 (char *)(_("IDS_COM_BODY_MINUTES_LC")));
196 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
198 (char *)(_("IDS_COM_BODY_SECONDS_LC")));
200 return (char *)g_strdup(screen_timeout_str);
203 char *get_pa_display_language_str()
205 int ret = SETTING_RETURN_FAIL;
209 Eina_List* list = setting_get_language_list();
210 Eina_List* elist = NULL;
212 ret = setting_get_int_slp_key(INT_SLP_SETTING_LANG, &index, &err);
215 return g_strdup("Automatic");
217 setting_lang_entry* pnode;
220 EINA_LIST_FOREACH( list, elist, pnode)
222 if (pnode->number == index)
223 title = g_strdup(pnode->title);
228 char *get_pa_Wi_Fi_on_off_str()
231 int ret = SETTING_RETURN_FAIL;
233 setting_get_int_slp_key(INT_SLP_SETTING_WIFI_STATUS, &value, &err);
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);
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;
248 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_ON_M_STATUS"));
250 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_OFF_M_STATUS"));
254 char *get_BT_on_off_str()
256 int ret = SETTING_RETURN_FAIL;
258 ret = setting_get_int_slp_key(INT_SLP_SETTING_BT_STATUS, &value, &err);
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);
266 if (VCONFKEY_BT_STATUS_OFF == value) {
267 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
269 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
273 char *get_NFC_on_off_str()
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);
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;
284 if (VCONFKEY_NFC_STATE_OFF == value) {
285 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
287 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
291 char *get_pa_time_format_str()
293 int ret = SETTING_RETURN_FAIL;
295 char *format_str[] = { _("IDS_COM_BODY_12_HOURS"),
296 _("IDS_ST_BODY_24_HOURS") };
298 setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
300 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
303 /* value 1:12H 2:24H */
304 if (value > 0 && value <= 2) /* 1, 2 */
305 return (char *)g_strdup(format_str[value - 1]);
307 return (char *)g_strdup(format_str[0]); /* set to 12H compelsery */
311 char *get_pa_date_format_str()
313 int ret = SETTING_RETURN_FAIL;
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")
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]);
325 char *get_pa_week_format_str()
327 int ret = SETTING_RETURN_FAIL;
329 char *format_str[] = {
330 _("IDS_ST_BODY_SUNDAY"),
331 _("IDS_ST_BODY_MONDAY"),
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]);
340 char *get_pa_roaming_network_str()
342 int ret = SETTING_RETURN_FAIL;
344 char *roaming_str[] = {
345 _("IDS_ST_BODY_AUTO_DOWNLOAD"), _("IDS_COM_BODY_MANUAL"),
346 _("IDS_ST_BODY_ALWAYS_REJECT")
349 setting_get_int_slp_key(INT_SLP_SETTING_ROAMING_NETWORK, &value,
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]);
355 double get_widgets_factor()
357 return elm_scale_get();
360 char *setting_gettext(const char *s)
362 /* fisrt find in app pg */
368 char *p = dgettext(SETTING_PACKAGE, s);
370 if (!safeStrCmp(s, p)) { /* not found */
371 /* find in system pkg */
372 p = dgettext(SYSTEM_PACKAGE, s);
377 bool is_digital_str(const char *cstr)
379 if (cstr == NULL || cstr[0] == 0) {
383 int len = (int)(safeStrLen(cstr));
385 if (cstr[0] == '-' || cstr[0] == '+') {
393 if (cstr[pos] < '0' || cstr[pos] > '9') {
402 bool is_substr_ncase(const char *parentstr, const char *substr)
404 if (NULL == parentstr || '\0' == parentstr[0])
407 int word_len = safeStrLen(parentstr);
408 int search_len = safeStrLen(substr);
411 for (i = 0; i < word_len; i++) {
412 if (!strncasecmp(substr, &parentstr[i], search_len)) {
420 bool is_string_belong_to_array(const char *partern, const char **array,
424 for (; idx < array_num; idx++) {
425 if (!safeStrCmp(partern, array[idx])) {
432 //remove sub string from a parent string
433 char *remove_first_substring(const char *parent, const char *pat)
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);
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);
447 for (; idx < str_len; idx++) {
448 if (0 == safeStrNCmp(pat, str + idx, pat_len)) {
450 q = str + idx + pat_len;
462 //now str keeps the result string
463 SETTING_TRACE("Exit %s with return str:%s", __FUNCTION__, str);
467 //return True just when NULL or '\0'
468 bool isEmptyStr(const char *str)
470 if (NULL == str || '\0' == str[0])
475 //return True just when str is NULL, '\0' or all strings made up of spaces
476 bool isSpaceStr(const char *str)
482 if (*str != '\0' && *str != ' ')
486 else if (*str == '\0')
496 int safeStrCmp(const char *s1, const char *s2)
498 /* Check NULL value first */
499 if (isEmptyStr(s1) && isEmptyStr(s2)) {
501 } else if (isEmptyStr(s1)) {
503 } else if (isEmptyStr(s2)) {
504 return SETTING_RETURN_FAIL;
507 return strcmp(s1, s2);
510 int safeStrNCmp(const char *s1, const char *s2, int len)
513 /* Check NULL value first */
514 if (isEmptyStr(s1) && isEmptyStr(s2)) {
516 } else if (isEmptyStr(s1)) {
518 } else if (isEmptyStr(s2)) {
519 return SETTING_RETURN_FAIL;
526 return strncmp(s1, s2, len);
529 char *safeStrNCat(char *dst, const char *src, int maxlen)
531 if (dst && !isEmptyStr(src) && maxlen > 0) {
532 (void) g_strlcat(dst, src, maxlen + 1);
539 char *safeCopyStr(char *dst, const char *src, int maxlen)
549 int temp = (int)safeStrLen(src);
550 len = (temp <= maxlen) ? temp : maxlen;
551 memcpy(dst, src, len);
560 int safeStrLen(const char *str)
562 if (isEmptyStr(str)) {
563 SETTING_TRACE_DEBUG("string is empty");
571 * get the int value of substring before delim
573 bool get_substring_int(const char **ipStr, int *ipValue, char delim)
575 int iValue = *ipValue = 0;
576 const char *str = *ipStr;
578 if (str == NULL || str[0] == 0) { /* empty string */
582 bool bNegative = FALSE;
583 if ('-' == str[0]) { /* allow Negative number.. */
587 if (str[0] < '0' || str[0] > '9') { /* first elementy is not digital */
591 if (str[0] == '0') { /* first elementy is 0 */
592 if (str[1] == delim) {
607 /****first elementy is not 0*/
608 iValue = iValue * 10 + str[0] - '0';
610 if (((unsigned int)iValue & 0x80000000) != 0) { /* think about overloading */
614 if (str[0] == delim) {
631 if (str[0] < '0' || str[0] > '9') {
640 #define MaxIPAddressLength 15
643 * CHeck Whether a special string Is An IP String
645 * @param ipstr string representing IP numbers like "aaa.bbb.ccc.ddd"
647 * @return true if it's IP format string otherwise false
649 bool is_ip_string(const char *ipstr)
651 if (NULL == ipstr || 0 == ipstr[0])
653 int len = (int)safeStrLen(ipstr);
654 if (len > MaxIPAddressLength) {
658 if (ipstr[len - 1] == '.') {
665 if (!get_substring_int(&ipstr, &ip, '.') || ip > 255) {
666 SETTING_TRACE("ipstr:%s", ipstr);
669 SETTING_TRACE("ipstr:%s", ipstr);
678 int setting_invoke_reset_function(char *ug_name, service_h service, void *ext)
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;
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);
688 if(stat(ug_file, &st) != 0) {
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;
699 //-------------------------------------------------------------------------------------
700 void *handle = dlopen(ug_file, RTLD_LAZY);
702 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", dlerror());
703 return LOAD_LIB_FAILED;
707 reset = dlsym(handle, "setting_plugin_reset");
708 if ((error = dlerror()) != NULL) {
709 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", error);
711 return UNDEFINED_LIB_SYMBOL;
715 ret = (*reset) (service, ext); /* CALL */
717 if (ret < 0) ret += UNDEFINED_LIB_SYMBOL;//from -2 on
723 int excuteCmd(char* exec_path, int option_num, ...)
725 char cmd[MAX_COMMON_BUFFER_LEN + 1] = {0, };
726 snprintf(cmd, MAX_COMMON_BUFFER_LEN,
731 va_start(args, option_num);
735 for (; argno < option_num; argno++) {
736 para = va_arg( args, char *);
737 SETTING_TRACE("Parameter #%d is: %s", argno, para);
740 g_strlcat(cmd, " ", MAX_COMMON_BUFFER_LEN + 1);
741 g_strlcat(cmd, para, MAX_COMMON_BUFFER_LEN + 1);
747 SETTING_TRACE("excute:%s", cmd);
752 void create_fontlink(const char *linkpath, const char *linkname,
753 const char *fontfilepath, const char *fontfilename)
755 char newpath[MAX_COMMON_BUFFER_LEN + 1];
756 char lcpath[MAX_COMMON_BUFFER_LEN + 1];
759 snprintf(newpath, MAX_COMMON_BUFFER_LEN, "%s/%s", linkpath, linkname);
761 snprintf(lcpath, MAX_COMMON_BUFFER_LEN, "%s/%s", fontfilepath, fontfilename);
763 SETTING_TRACE("newpath:%s", newpath);
764 SETTING_TRACE("lcpath:%s", lcpath);
767 ret = symlink(lcpath, newpath);
768 setting_retm_if(ret != 0, "fail to call symlink");
771 char* get_icon_path(const char *package)
773 ail_appinfo_h handle;
776 char *icon_path = IMG_DefaultIcon;//The default icon must exist.(it will be installed by Setting App)
781 if (ail_package_get_appinfo(package, &handle) != AIL_ERROR_OK) {
782 SETTING_TRACE_ERROR("Failed to ail_package_get_appinfo.");
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.");
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;
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.");
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");
821 if (!strncmp(str, "SLP", 3)){
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");
843 if (0 == safeStrCmp(KeyStr_Emulator, model_str)) {
852 int get_popup_btn_response_type(const char *btn_str)
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)))
866 rsp_type = POPUP_RESPONSE_OK;
870 rsp_type = POPUP_RESPONSE_CANCEL;
875 #define SUPPORT_STATIC_LOAD 1
876 #if SUPPORT_STATIC_LOAD
877 static char *system_service_list[MAX_SYSTEM_SERVICE_NUM] = {NULL, };
879 void clear_system_service_data()
881 #if SUPPORT_STATIC_LOAD
883 for (idx = 0; idx < MAX_SYSTEM_SERVICE_NUM && system_service_list[idx]; idx++)
885 FREE(system_service_list[idx]);
890 bool is_system_service(const char *pkg_name)
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")
908 //OSP service app list,
910 #if SUPPORT_STATIC_LOAD
912 if (!system_service_list[0]) //just load the file
914 FILE *fp = fopen(SYSTEM_SERVICE_LIST_PATH, "r");
916 char result[MAX_PKG_NAME_LEN+1] = {0, };
917 while (fgets(result, MAX_PKG_NAME_LEN, fp))
919 result[strlen(result) - 1] = '\0';//offset 1
920 system_service_list[idx++] = strdup(result);
927 for (idx = 0; idx < MAX_SYSTEM_SERVICE_NUM && system_service_list[idx]; idx++)
929 if (0 == safeStrCmp(pkg_name, system_service_list[idx])) {
935 FILE *fp = fopen(SYSTEM_SERVICE_LIST_PATH, "r");
937 char result[MAX_PKG_NAME_LEN+1] = {0, };
938 while (fgets(result, MAX_PKG_NAME_LEN, fp))
940 result[strlen(result) - 1] = '\0';//offset 1
941 if (0 == safeStrCmp(pkg_name, result)) {
949 SETTING_TRACE("ret:%d", ret);
954 * should use g_free to free returned string
956 char *get_default_font(int language)
958 char *font_name = NULL;
962 case SETTING_LANG_KOREA:
963 font_name = g_strdup("SLPSansKorean");
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");
972 case SETTING_LANG_JAPAN:
973 font_name = g_strdup("UDGothic");
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");
999 font_name = g_strdup("HelveticaNeue");
1005 void *font_conf_doc_parse(char *doc_name, char *font_name)
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;
1016 doc = xmlParseFile(doc_name);
1017 setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
1019 cur = xmlDocGetRootElement(doc);
1022 SETTING_TRACE_DEBUG("empty document");
1028 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1029 SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
1035 cur = cur->xmlChildrenNode;
1037 Eina_Bool is_changed = EINA_FALSE;
1040 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
1042 cur2 = cur->xmlChildrenNode;
1045 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
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"))
1059 cur3 = cur2->xmlChildrenNode;
1062 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
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);
1069 is_changed = EINA_TRUE;
1076 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias")))
1078 cur2 = cur->xmlChildrenNode;
1079 while (cur2 != NULL)
1081 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family")))
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);
1088 is_changed = EINA_TRUE;
1089 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer")))
1091 cur3 = cur2->xmlChildrenNode;
1092 while (cur3 != NULL)
1094 if((!xmlStrcmp(cur3->name, (const xmlChar *)"family")))
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);
1101 is_changed = EINA_TRUE;
1103 break; /* just set first element, so break */
1125 * should use g_free to free return string
1127 char *cur_font_get()
1129 SETTING_TRACE_BEGIN;
1130 xmlDocPtr doc = NULL;
1131 xmlNodePtr cur = NULL;
1132 xmlNodePtr cur2 = NULL;
1133 xmlNodePtr cur3 = NULL;
1134 xmlChar *key = NULL;
1136 char *font_name = NULL;
1138 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
1139 setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
1141 cur = xmlDocGetRootElement(doc);
1144 SETTING_TRACE_DEBUG("empty document");
1150 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1151 SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
1157 cur = cur->xmlChildrenNode;
1161 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
1163 cur2 = cur->xmlChildrenNode;
1166 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
1168 cur3 = cur2->xmlChildrenNode;
1171 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
1173 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1174 SETTING_TRACE_DEBUG("string is: %s", key);
1176 font_name = g_strdup((char *)key);
1197 static int __font_size_get()
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");
1206 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1207 font_size = SMALL_FONT_DPI;
1209 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1210 font_size = MIDDLE_FONT_DPI;
1212 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1213 font_size = LARGE_FONT_DPI;
1215 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1216 font_size = HUGE_FONT_DPI;
1218 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1219 font_size = GIANT_FONT_DPI;
1222 font_size = MIDDLE_FONT_DPI;
1228 void font_config_set(char *font_name)
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();
1238 text_classes = elm_config_text_classes_list_get();
1240 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
1242 Eina_List *ll = NULL;
1243 Eina_List *l_next = NULL;
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;
1250 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
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;
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);
1271 if (slp_roman_exist == EINA_FALSE) {
1272 elm_config_font_overlay_set("slp_roman", (const char*)font_name, MIDDLE_FONT_DPI);
1274 if (slp_bold_exist == EINA_FALSE) {
1275 elm_config_font_overlay_set("slp_bold", (const char*)font_name, MIDDLE_FONT_DPI);
1277 if (slp_regular_exist == EINA_FALSE) {
1278 elm_config_font_overlay_set("slp_regular", (const char*)font_name, MIDDLE_FONT_DPI);
1281 EINA_LIST_FOREACH(text_classes, l, etc)
1286 EINA_LIST_FOREACH(fo_list, ll, efo)
1288 if (!safeStrCmp(etc->name, efo->text_class)) {
1292 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
1295 elm_config_font_overlay_apply();
1296 elm_config_all_flush();
1297 elm_config_engine_set("software_x11");
1299 elm_config_text_classes_list_free(text_classes);
1300 text_classes = NULL;
1303 vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
1306 void font_size_set()
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();
1314 if (font_size == -1) {
1315 SETTING_TRACE_DEBUG("failed to call font_size_get");
1319 text_classes = elm_config_text_classes_list_get();
1321 EINA_LIST_FOREACH(text_classes, l, etc)
1323 elm_config_font_overlay_set(etc->name, font_name, font_size);
1326 elm_config_all_flush();
1327 elm_config_engine_set("software_x11");
1329 elm_config_text_classes_list_free(text_classes);
1330 text_classes = NULL;
1336 void update_lang(void)
1341 lang = vconf_get_str(VCONFKEY_LANGSET);
1343 setenv("LANG", lang, 1);
1344 setenv("LC_MESSAGES", lang, 1);
1345 r = setlocale(LC_ALL, "");
1347 r = setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
1348 //_DBG("*****appcore setlocale=%s\n", r);
1354 void update_region(void)
1358 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
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);
1375 static int __set_i18n(const char *domain, const char *dir)
1379 if (domain == NULL) {
1384 r = setlocale(LC_ALL, "");
1385 /* if locale is not set properly, try again to set as language base */
1387 r = setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
1388 //_DBG("*****appcore setlocale=%s\n", r);
1390 //_retvm_if(r == NULL, -1, "appcore: setlocale() error");
1392 r = bindtextdomain(domain, dir);
1393 //_retvm_if(r == NULL, -1, "appcore: bindtextdomain() error");
1395 r = textdomain(domain);
1396 //_retvm_if(r == NULL, -1, "appcore: textdomain() error");
1403 int setting_set_i18n(char* pkgname, char* localedir)
1404 //int set_i18n(const char *domainname, const char *dirname)
1407 return appcore_set_i18n(pkgname, localedir);
1410 //_retv_if(_set, 0);
1415 return __set_i18n(pkgname, localedir);
1420 void app_launcher(char* pkg_name)
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)
1431 SETTING_TRACE("on success");
1435 SETTING_TRACE("on error");
1437 service_destroy(service);