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_pa_usb_connect_mode_str()
50 int ret = SETTING_RETURN_FAIL;
53 ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &value);
54 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
58 case SETTING_USB_DEBUG_MODE:
59 return (char*)g_strdup(_("IDS_ST_BODY_USB_DEBUGGING"));
61 return (char*)g_strdup(_("IDS_COM_POP_DISCONNECTED"));
65 char *get_brightness_mode_str()
68 setting_get_int_slp_key(INT_SLP_SETTING_AUTOMATIC_BRIGHTNESS, &value,
70 if (value != SETTING_BRIGHTNESS_AUTOMATIC_OFF) {
71 return setting_gettext("IDS_COM_BODY_AUTOMATIC");
73 return setting_gettext("IDS_COM_BODY_MANUAL");
77 char *get_pa_backlight_time_str()
80 char backlight_time_str[MAX_DISPLAY_NAME_LEN_ON_UI];
82 #if SUPPORT_LCD_TIMEOUT_KEEPING
83 if (0 != vconf_get_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, &value)) {
86 value = 0; /* keep agree with postin file */
89 vconf_set_int(VCONFKEY_LCD_TIMEOUT_NORMAL_BACKUP, value);
94 setting_get_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL, &value,
97 if (SETTING_RETURN_FAIL == ret || value < 0) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
100 value = 0; /* keep agree with postin file */
103 setting_set_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL,
106 #else // for MDM server
112 // if 120 < < 300, 120
113 // if 300 < < 600, 300
117 if (SETTING_RETURN_FAIL == ret || value < 15)
119 else if(value >= 15 && value < 30)
121 else if(value >= 30 && value < 60)
123 else if(value >= 60 && value < 120)
125 else if(value >= 120 && value < 300)
127 else if(value >= 300 && value < 600)
134 if (SETTING_RETURN_FAIL == ret || value < 30)
136 else if(value >= 30 && value < 60)
138 else if(value >= 60 && value < 120)
140 else if(value >= 120 && value < 300)
142 else if(value >= 300 && value < 600)
148 setting_set_int_slp_key(INT_SLP_SETTING_LCD_TIMEOUT_NORMAL,
154 snprintf(backlight_time_str, sizeof(backlight_time_str), "%s",
155 _("IDS_ST_BODY_ALWAYS_ON"));
156 } else if (value == 60) {
157 snprintf(backlight_time_str, sizeof(backlight_time_str), "%s",
158 _("IDS_COM_BODY_1_MINUTE"));
159 } else if (value > 60) {
160 snprintf(backlight_time_str, sizeof(backlight_time_str),
161 "%d %s", value / 60, (char *)(_("IDS_COM_BODY_MINUTES_LC")));
163 snprintf(backlight_time_str, sizeof(backlight_time_str),
164 "%d %s", value, (char *)(_("IDS_COM_BODY_SECONDS_LC")));
166 return (char *)g_strdup(backlight_time_str);
169 char *get_pa_powersaving_at_str()
172 char powersaving_at_str[MAX_DISPLAY_NAME_LEN_ON_UI + 1];
176 setting_get_int_slp_key(INT_SLP_SETTING_POWERSAVING_AT, &value,
178 if (SETTING_RETURN_FAIL == ret || value < 0) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
179 value = 30; /* keep agree with postin file */
180 setting_set_int_slp_key(INT_SLP_SETTING_POWERSAVING_AT,
184 snprintf(powersaving_at_str, MAX_DISPLAY_NAME_LEN_ON_UI, "At %d%% %s",
185 value, "battery power");
186 return (char *)g_strdup(powersaving_at_str);
189 char *get_pa_screen_timeout_str()
192 char screen_timeout_str[MAX_DISPLAY_NAME_LEN_ON_UI + 1];
196 setting_get_int_slp_key(INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT,
199 if (SETTING_RETURN_FAIL == ret || value < 0) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
200 value = 15; /* keep agree with postin file */
201 setting_set_int_slp_key
202 (INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT, value, &err);
206 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI, "%s",
208 } else if (value >= 60) {
209 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
211 (char *)(_("IDS_COM_BODY_MINUTES_LC")));
213 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
215 (char *)(_("IDS_COM_BODY_SECONDS_LC")));
217 return (char *)g_strdup(screen_timeout_str);
220 char *get_pa_display_language_str()
222 int ret = SETTING_RETURN_FAIL;
226 Eina_List* list = setting_get_language_list();
227 Eina_List* elist = NULL;
229 ret = setting_get_int_slp_key(INT_SLP_SETTING_LANG, &index, &err);
232 return g_strdup("Automatic");
234 setting_lang_entry* pnode;
237 EINA_LIST_FOREACH( list, elist, pnode)
239 if (pnode->number == index)
240 title = g_strdup(pnode->title);
245 char *get_pa_Wi_Fi_on_off_str()
248 int ret = SETTING_RETURN_FAIL;
250 setting_get_int_slp_key(INT_SLP_SETTING_WIFI_STATUS, &value, &err);
252 if (SETTING_RETURN_FAIL == ret) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
253 value = VCONFKEY_WIFI_OFF;
254 setting_set_int_slp_key(INT_SLP_SETTING_WIFI_STATUS,
255 VCONFKEY_WIFI_OFF, &err);
259 char *pa_wifi_device = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
260 SETTING_TRACE("pa_wifi_device:%s", pa_wifi_device);
261 if (NULL != pa_wifi_device && '\0' != pa_wifi_device[0]) {
262 return pa_wifi_device;
265 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_ON_M_STATUS"));
267 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_OFF_M_STATUS"));
271 char *get_Mobile_AP_on_off_str()
275 setting_get_int_slp_key(INT_SLP_SETTING_MOBILE_AP_STATUS, &value,
278 /* 7 means bitwise-operation */
285 if (0 != ret || value < 0 || value > 7) {
287 setting_set_int_slp_key(INT_SLP_SETTING_MOBILE_AP_STATUS, value,
292 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
294 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
298 char *get_BT_on_off_str()
300 int ret = SETTING_RETURN_FAIL;
302 ret = setting_get_int_slp_key(INT_SLP_SETTING_BT_STATUS, &value, &err);
304 if (SETTING_RETURN_FAIL == ret) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
305 value = VCONFKEY_BT_STATUS_OFF;
306 setting_set_int_slp_key(INT_SLP_SETTING_BT_STATUS,
307 VCONFKEY_BT_STATUS_OFF, &err);
310 if (VCONFKEY_BT_STATUS_OFF == value) {
311 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
313 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
317 char *get_NFC_on_off_str()
319 int ret = SETTING_RETURN_FAIL;
320 int value = 0, err = 0;
321 ret = setting_get_bool_slp_key(BOOL_SLP_SETTING_NFC_STATUS, &value, &err);
323 if (SETTING_RETURN_FAIL == ret) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
324 SETTING_TRACE_DEBUG("fail to get nfc status from vconf");
325 value = VCONFKEY_NFC_STATE_OFF;
328 if (VCONFKEY_NFC_STATE_OFF == value) {
329 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
331 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
335 char *get_pa_time_format_str()
337 int ret = SETTING_RETURN_FAIL;
339 char *format_str[] = { _("IDS_COM_BODY_12_HOURS"),
340 _("IDS_ST_BODY_24_HOURS") };
342 setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
344 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
347 /* value 1:12H 2:24H */
348 if (value > 0 && value <= 2) /* 1, 2 */
349 return (char *)g_strdup(format_str[value - 1]);
351 return (char *)g_strdup(format_str[0]); /* set to 12H compelsery */
355 char *get_pa_date_format_str()
357 int ret = SETTING_RETURN_FAIL;
359 char *format_str[] = { _("IDS_ST_BODY_DDMMYYYY_DOT"),
360 _("IDS_ST_BODY_MM_DD_YYYY_DOT"),
361 _("IDS_COM_BODY_YYYYMMDD"), _("IDS_ST_BODY_YYYY_DD_MM_DOT")
364 setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
365 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
366 return (char *)g_strdup(format_str[value]);
369 char *get_pa_week_format_str()
371 int ret = SETTING_RETURN_FAIL;
373 char *format_str[] = {
374 _("IDS_ST_BODY_SUNDAY"),
375 _("IDS_ST_BODY_MONDAY"),
379 setting_get_int_slp_key(INT_SLP_SETTING_WEEK_FORMAT, &value, &err);
380 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
381 return (char *)g_strdup(format_str[value]);
384 char *get_pa_roaming_network_str()
386 int ret = SETTING_RETURN_FAIL;
388 char *roaming_str[] = {
389 _("IDS_ST_BODY_AUTO_DOWNLOAD"), _("IDS_COM_BODY_MANUAL"),
390 _("IDS_ST_BODY_ALWAYS_REJECT")
393 setting_get_int_slp_key(INT_SLP_SETTING_ROAMING_NETWORK, &value,
395 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
396 return (char *)g_strdup(roaming_str[value]);
399 double get_widgets_factor()
401 return elm_scale_get();
404 char *setting_gettext(const char *s)
406 /* fisrt find in app pg */
412 char *p = dgettext(SETTING_PACKAGE, s);
414 if (!safeStrCmp(s, p)) { /* not found */
415 /* find in system pkg */
416 p = dgettext(SYSTEM_PACKAGE, s);
421 bool is_digital_str(const char *cstr)
423 if (cstr == NULL || cstr[0] == 0) {
427 int len = (int)(safeStrLen(cstr));
429 if (cstr[0] == '-' || cstr[0] == '+') {
437 if (cstr[pos] < '0' || cstr[pos] > '9') {
446 bool is_substr_ncase(const char *parentstr, const char *substr)
448 if (NULL == parentstr || '\0' == parentstr[0])
451 int word_len = safeStrLen(parentstr);
452 int search_len = safeStrLen(substr);
455 for (i = 0; i < word_len; i++) {
456 if (!strncasecmp(substr, &parentstr[i], search_len)) {
464 bool is_string_belong_to_array(const char *partern, const char **array,
468 for (; idx < array_num; idx++) {
469 if (!safeStrCmp(partern, array[idx])) {
476 //NULL, "", " ", " " etc.. are all empty strings
477 bool isEmptyStr(const char *str)
483 if (*str != '\0' && *str != ' ')
487 else if (*str == '\0')
497 int safeStrCmp(const char *s1, const char *s2)
499 /* Check NULL value first */
500 if (isEmptyStr(s1) && isEmptyStr(s2)) {
502 } else if (isEmptyStr(s1)) {
504 } else if (isEmptyStr(s2)) {
505 return SETTING_RETURN_FAIL;
508 return strcmp(s1, s2);
511 int safeStrNCmp(const char *s1, const char *s2, int len)
514 /* Check NULL value first */
515 if (isEmptyStr(s1) && isEmptyStr(s2)) {
517 } else if (isEmptyStr(s1)) {
519 } else if (isEmptyStr(s2)) {
520 return SETTING_RETURN_FAIL;
527 return strncmp(s1, s2, len);
530 char *safeStrNCat(char *dst, const char *src, int maxlen)
532 if (dst && !isEmptyStr(src) && maxlen > 0) {
533 (void) g_strlcat(dst, src, maxlen + 1);
540 char *safeCopyStr(char *dst, const char *src, int maxlen)
550 int temp = (int)safeStrLen(src);
551 len = (temp <= maxlen) ? temp : maxlen;
552 memcpy(dst, src, len);
561 int safeStrLen(const char *str)
563 if (isEmptyStr(str)) {
564 SETTING_TRACE_DEBUG("string is empty");
572 * get the int value of substring before delim
574 bool get_substring_int(const char **ipStr, int *ipValue, char delim)
576 int iValue = *ipValue = 0;
577 const char *str = *ipStr;
579 if (str == NULL || str[0] == 0) { /* empty string */
583 bool bNegative = FALSE;
584 if ('-' == str[0]) { /* allow Negative number.. */
588 if (str[0] < '0' || str[0] > '9') { /* first elementy is not digital */
592 if (str[0] == '0') { /* first elementy is 0 */
593 if (str[1] == delim) {
608 /****first elementy is not 0*/
609 iValue = iValue * 10 + str[0] - '0';
611 if (((unsigned int)iValue & 0x80000000) != 0) { /* think about overloading */
615 if (str[0] == delim) {
632 if (str[0] < '0' || str[0] > '9') {
641 #define MaxIPAddressLength 15
644 * CHeck Whether a special string Is An IP String
646 * @param ipstr string representing IP numbers like "aaa.bbb.ccc.ddd"
648 * @return true if it's IP format string otherwise false
650 bool is_ip_string(const char *ipstr)
652 if (NULL == ipstr || 0 == ipstr[0])
654 int len = (int)safeStrLen(ipstr);
655 if (len > MaxIPAddressLength) {
659 if (ipstr[len - 1] == '.') {
666 if (!get_substring_int(&ipstr, &ip, '.') || ip > 255) {
667 SETTING_TRACE("ipstr:%s", ipstr);
670 SETTING_TRACE("ipstr:%s", ipstr);
679 int setting_invoke_reset_function(char *ug_name, service_h service, void *ext)
681 SETTING_TRACE("Enter %s with ug_name:%s", __FUNCTION__, ug_name);
682 int (*reset) (service_h pair, void *ptr);
683 int ret = OPERATE_LIB_SUCESS;
685 //1.first do exist-checking in /opt/ug/lib
686 char ug_file[PATH_MAX + 1];
687 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH, ug_name);
689 if(stat(ug_file, &st) != 0) {
691 //2.if it does not exit in /opt/ug/lib, then do exist-checking in /usr/ug/lib
692 memset(ug_file, 0x00, PATH_MAX + 1);
693 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR, ug_name);
694 if(stat(ug_file, &st) != 0) {
695 //both not exist,skip it
696 SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
697 return OPERATE_LIB_SUCESS;
700 //-------------------------------------------------------------------------------------
701 void *handle = dlopen(ug_file, RTLD_LAZY);
703 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", dlerror());
704 return LOAD_LIB_FAILED;
708 reset = dlsym(handle, "setting_plugin_reset");
709 if ((error = dlerror()) != NULL) {
710 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", error);
712 return UNDEFINED_LIB_SYMBOL;
716 ret = (*reset) (service, ext); /* CALL */
718 if (ret < 0) ret += UNDEFINED_LIB_SYMBOL;//from -2 on
724 int excuteCmd(char* exec_path, int option_num, ...)
726 char cmd[MAX_COMMON_BUFFER_LEN + 1] = {0, };
727 snprintf(cmd, MAX_COMMON_BUFFER_LEN,
732 va_start(args, option_num);
736 for (; argno < option_num; argno++) {
737 para = va_arg( args, char *);
738 SETTING_TRACE("Parameter #%d is: %s", argno, para);
741 g_strlcat(cmd, " ", MAX_COMMON_BUFFER_LEN + 1);
742 g_strlcat(cmd, para, MAX_COMMON_BUFFER_LEN + 1);
748 SETTING_TRACE("excute:%s", cmd);
753 void create_fontlink(const char *linkpath, const char *linkname,
754 const char *fontfilepath, const char *fontfilename)
756 char newpath[MAX_COMMON_BUFFER_LEN + 1];
757 char lcpath[MAX_COMMON_BUFFER_LEN + 1];
760 snprintf(newpath, MAX_COMMON_BUFFER_LEN, "%s/%s", linkpath, linkname);
762 snprintf(lcpath, MAX_COMMON_BUFFER_LEN, "%s/%s", fontfilepath, fontfilename);
764 SETTING_TRACE("newpath:%s", newpath);
765 SETTING_TRACE("lcpath:%s", lcpath);
768 ret = symlink(lcpath, newpath);
769 setting_retm_if(ret != 0, "fail to call symlink");
772 char* get_icon_path(const char *package)
774 ail_appinfo_h handle;
777 char *icon_path = IMG_DefaultIcon;//The default icon must exist.(it will be installed by Setting App)
782 if (ail_package_get_appinfo(package, &handle) != AIL_ERROR_OK) {
783 SETTING_TRACE_ERROR("Failed to ail_package_get_appinfo.");
788 if (result && ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &icon_path) != AIL_ERROR_OK) {
789 SETTING_TRACE_ERROR("Failed to ail_appinfo_get_str.");
793 if (result && access(icon_path, R_OK|F_OK ) !=0 ) {//The file cannot be accessed.
794 SETTING_TRACE_ERROR("The file[%s] cannot be accessed. To use defaut icon.", icon_path);
795 icon_path = IMG_DefaultIcon;
798 ret_str = strdup(icon_path);
799 if (destroy && ail_package_destroy_appinfo(handle) != AIL_ERROR_OK) {
800 SETTING_TRACE_ERROR("Failed to ail_package_destroy_appinfo.");
810 int ret = system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &str);
811 if (ret != SYSTEM_INFO_ERROR_NONE) {
812 SETTING_TRACE_ERROR("fail to call system_info_get_value_string");
822 if (!strncmp(str, "SLP", 3)){
835 char *model_str = NULL;
836 int ret = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model_str);
837 //SETTING_TRACE("model_str : %s", model_str);
838 if (ret != SYSTEM_INFO_ERROR_NONE) {
839 SETTING_TRACE_ERROR("fail to call system_info_get_value_string");
844 if (0 == safeStrCmp(KeyStr_Emulator, model_str)) {
853 int get_popup_btn_response_type(const char *btn_str)
855 SETTING_TRACE("btn_str:%s", btn_str);
856 POPUP_BTN_RESPONSE_TYPE rsp_type = POPUP_RESPONSE_INVALID;
857 retv_if(!btn_str, rsp_type);
858 if (0 == safeStrCmp(btn_str, _("IDS_COM_BODY_CLOSE"))
859 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_TRY"))//KeyStr_Try
860 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_OK"))
861 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_YES"))
862 || 0 == safeStrCmp(btn_str, _("IDS_ST_BODY_USE_MOTION"))
863 || 0 == safeStrCmp(btn_str, _("IDS_COM_POP_TRY_AGAIN"))
864 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_DELETE"))
865 || 0 == safeStrCmp(btn_str, _(KeyStr_Save)))
867 rsp_type = POPUP_RESPONSE_OK;
871 rsp_type = POPUP_RESPONSE_CANCEL;
876 #define SUPPORT_STATIC_LOAD 1
877 #if SUPPORT_STATIC_LOAD
878 static char *system_service_list[MAX_SYSTEM_SERVICE_NUM] = {NULL, };
880 void clear_system_service_data()
882 #if SUPPORT_STATIC_LOAD
884 for (idx = 0; idx < MAX_SYSTEM_SERVICE_NUM && system_service_list[idx]; idx++)
886 FREE(system_service_list[idx]);
891 bool is_system_service(const char *pkg_name)
893 //SLP native apps list,
894 if (0 == safeStrCmp(pkg_name, "com.samsung.menu-screen")
895 || 0 == safeStrCmp(pkg_name, "com.samsung.live-data-provider")
896 || 0 == safeStrCmp(pkg_name, "com.samsung.live-magazine")
897 || 0 == safeStrCmp(pkg_name, "com.samsung.pwlock")
898 || 0 == safeStrCmp(pkg_name, "com.samsung.quickpanel")
899 || 0 == safeStrCmp(pkg_name, "com.samsung.vtmain")
900 || 0 == safeStrCmp(pkg_name, "com.samsung.call")
901 || 0 == safeStrCmp(pkg_name, "usb_setting")
902 || 0 == safeStrCmp(pkg_name, "com.samsung.indicator")
903 || 0 == safeStrCmp(pkg_name, "com.samsung.cluster-home")
909 //OSP service app list,
911 #if SUPPORT_STATIC_LOAD
913 if (!system_service_list[0]) //just load the file
915 FILE *fp = fopen(SYSTEM_SERVICE_LIST_PATH, "r");
917 char result[MAX_PKG_NAME_LEN+1] = {0, };
918 while (fgets(result, MAX_PKG_NAME_LEN, fp))
920 result[strlen(result) - 1] = '\0';//offset 1
921 system_service_list[idx++] = strdup(result);
928 for (idx = 0; idx < MAX_SYSTEM_SERVICE_NUM && system_service_list[idx]; idx++)
930 if (0 == safeStrCmp(pkg_name, system_service_list[idx])) {
936 FILE *fp = fopen(SYSTEM_SERVICE_LIST_PATH, "r");
938 char result[MAX_PKG_NAME_LEN+1] = {0, };
939 while (fgets(result, MAX_PKG_NAME_LEN, fp))
941 result[strlen(result) - 1] = '\0';//offset 1
942 if (0 == safeStrCmp(pkg_name, result)) {
950 SETTING_TRACE("ret:%d", ret);
955 * should use g_free to free returned string
957 char *get_default_font(int language)
959 char *font_name = NULL;
963 case SETTING_LANG_KOREA:
964 font_name = g_strdup("SLPSansKorean");
966 case SETTING_LANG_CHINA:
967 /* output_font : SLPSansFallback*/
968 case SETTING_LANG_CANTONESE:
969 /* output_font : SLPSansFallback*/
970 case SETTING_LANG_TAIWAN:
971 font_name = g_strdup("SLPSansFallback");
973 case SETTING_LANG_JAPAN:
974 font_name = g_strdup("UDGothic");
976 case SETTING_LANG_AUTOMATIC:
977 /* output_font : HelveticaNeue*/
978 case SETTING_LANG_ENGLISH:
979 /* output_font : HelveticaNeue*/
980 case SETTING_LANG_GERMAN:
981 /* output_font : HelveticaNeue*/
982 case SETTING_LANG_DUTCH:
983 /* output_font : HelveticaNeue*/
984 case SETTING_LANG_SPAINISH:
985 /* output_font : HelveticaNeue*/
986 case SETTING_LANG_PORTUGUESE:
987 /* output_font : HelveticaNeue*/
988 case SETTING_LANG_GREEK:
989 /* output_font : HelveticaNeue*/
990 case SETTING_LANG_ITALIAN:
991 /* output_font : HelveticaNeue*/
992 case SETTING_LANG_FRENCH:
993 /* output_font : HelveticaNeue*/
994 case SETTING_LANG_TURKISH:
995 /* output_font : HelveticaNeue*/
996 case SETTING_LANG_RUSSIAN:
997 font_name = g_strdup("HelveticaNeue");
1000 font_name = g_strdup("HelveticaNeue");
1006 void *font_conf_doc_parse(char *doc_name, char *font_name)
1008 SETTING_TRACE_BEGIN;
1009 setting_retvm_if(doc_name == NULL, NULL, "Param data is NULL");
1010 setting_retvm_if(font_name == NULL, NULL, "Param data is NULL");
1011 xmlDocPtr doc = NULL;
1012 xmlNodePtr cur = NULL;
1013 xmlNodePtr cur2 = NULL;
1014 xmlNodePtr cur3 = NULL;
1015 xmlChar *key = NULL;
1017 doc = xmlParseFile(doc_name);
1018 setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
1020 cur = xmlDocGetRootElement(doc);
1023 SETTING_TRACE_DEBUG("empty document");
1029 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1030 SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
1036 cur = cur->xmlChildrenNode;
1038 Eina_Bool is_changed = EINA_FALSE;
1041 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
1043 cur2 = cur->xmlChildrenNode;
1046 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
1048 xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
1049 SETTING_TRACE_DEBUG("name is: %s", name);
1050 /* if name is not 'family', break */
1051 if (xmlStrcmp(name, (const xmlChar *)"family"))
1060 cur3 = cur2->xmlChildrenNode;
1063 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
1065 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
1066 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1067 SETTING_TRACE_DEBUG("after changed, string is: %s", key);
1070 is_changed = EINA_TRUE;
1077 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias")))
1079 cur2 = cur->xmlChildrenNode;
1080 while (cur2 != NULL)
1082 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family")))
1084 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
1085 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
1086 SETTING_TRACE_DEBUG("after changed, string is: %s", key);
1089 is_changed = EINA_TRUE;
1090 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer")))
1092 cur3 = cur2->xmlChildrenNode;
1093 while (cur3 != NULL)
1095 if((!xmlStrcmp(cur3->name, (const xmlChar *)"family")))
1097 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
1098 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1099 SETTING_TRACE_DEBUG("after changed, string is: %s", key);
1102 is_changed = EINA_TRUE;
1104 break; /* just set first element, so break */
1126 * should use g_free to free return string
1128 char *cur_font_get()
1130 SETTING_TRACE_BEGIN;
1131 xmlDocPtr doc = NULL;
1132 xmlNodePtr cur = NULL;
1133 xmlNodePtr cur2 = NULL;
1134 xmlNodePtr cur3 = NULL;
1135 xmlChar *key = NULL;
1137 char *font_name = NULL;
1139 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
1140 setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
1142 cur = xmlDocGetRootElement(doc);
1145 SETTING_TRACE_DEBUG("empty document");
1151 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1152 SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
1158 cur = cur->xmlChildrenNode;
1162 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
1164 cur2 = cur->xmlChildrenNode;
1167 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
1169 cur3 = cur2->xmlChildrenNode;
1172 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
1174 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1175 SETTING_TRACE_DEBUG("string is: %s", key);
1177 font_name = g_strdup((char *)key);
1198 static int __font_size_get()
1203 int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &value, &err);
1204 retvm_if(ret != 0, -1, "get vconf failed");
1207 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1208 font_size = SMALL_FONT_DPI;
1210 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1211 font_size = MIDDLE_FONT_DPI;
1213 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1214 font_size = LARGE_FONT_DPI;
1216 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1217 font_size = HUGE_FONT_DPI;
1219 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1220 font_size = GIANT_FONT_DPI;
1223 font_size = MIDDLE_FONT_DPI;
1229 void font_config_set(char *font_name)
1231 Eina_List *text_classes = NULL;
1232 Elm_Text_Class *etc = NULL;
1233 const Eina_List *l = NULL;
1234 Eina_List *fo_list = NULL;
1235 Elm_Font_Overlay *efo = NULL;
1236 int font_size = __font_size_get();
1239 text_classes = elm_config_text_classes_list_get();
1241 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
1243 Eina_List *ll = NULL;
1244 Eina_List *l_next = NULL;
1246 Eina_Bool slp_medium_exist = EINA_FALSE;
1247 Eina_Bool slp_roman_exist = EINA_FALSE;
1248 Eina_Bool slp_bold_exist = EINA_FALSE;
1249 Eina_Bool slp_regular_exist = EINA_FALSE;
1251 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
1253 if (!safeStrCmp(efo->text_class, "slp_medium")) {
1254 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1255 slp_medium_exist = EINA_TRUE;
1256 } else if (!safeStrCmp(efo->text_class, "slp_roman")) {
1257 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1258 slp_roman_exist = EINA_TRUE;
1259 } else if (!safeStrCmp(efo->text_class, "slp_bold")) {
1260 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1261 slp_bold_exist = EINA_TRUE;
1262 } else if (!safeStrCmp(efo->text_class, "slp_regular")) {
1263 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1264 slp_regular_exist = EINA_TRUE;
1268 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
1269 if (slp_medium_exist == EINA_FALSE) {
1270 elm_config_font_overlay_set("slp_medium", (const char*)font_name, MIDDLE_FONT_DPI);
1272 if (slp_roman_exist == EINA_FALSE) {
1273 elm_config_font_overlay_set("slp_roman", (const char*)font_name, MIDDLE_FONT_DPI);
1275 if (slp_bold_exist == EINA_FALSE) {
1276 elm_config_font_overlay_set("slp_bold", (const char*)font_name, MIDDLE_FONT_DPI);
1278 if (slp_regular_exist == EINA_FALSE) {
1279 elm_config_font_overlay_set("slp_regular", (const char*)font_name, MIDDLE_FONT_DPI);
1282 EINA_LIST_FOREACH(text_classes, l, etc)
1287 EINA_LIST_FOREACH(fo_list, ll, efo)
1289 if (!safeStrCmp(etc->name, efo->text_class)) {
1293 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
1296 elm_config_font_overlay_apply();
1297 elm_config_all_flush();
1298 elm_config_engine_set("software_x11");
1300 elm_config_text_classes_list_free(text_classes);
1301 text_classes = NULL;
1304 vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
1307 void font_size_set()
1309 Eina_List *text_classes = NULL;
1310 Elm_Text_Class *etc = NULL;
1311 const Eina_List *l = NULL;
1312 int font_size = __font_size_get();
1313 char *font_name = cur_font_get();
1315 if (font_size == -1) {
1316 SETTING_TRACE_DEBUG("failed to call font_size_get");
1320 text_classes = elm_config_text_classes_list_get();
1322 EINA_LIST_FOREACH(text_classes, l, etc)
1324 elm_config_font_overlay_set(etc->name, font_name, font_size);
1327 elm_config_all_flush();
1328 elm_config_engine_set("software_x11");
1330 elm_config_text_classes_list_free(text_classes);
1331 text_classes = NULL;