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_BT_on_off_str()
273 int ret = SETTING_RETURN_FAIL;
275 ret = setting_get_int_slp_key(INT_SLP_SETTING_BT_STATUS, &value, &err);
277 if (SETTING_RETURN_FAIL == ret) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
278 value = VCONFKEY_BT_STATUS_OFF;
279 setting_set_int_slp_key(INT_SLP_SETTING_BT_STATUS,
280 VCONFKEY_BT_STATUS_OFF, &err);
283 if (VCONFKEY_BT_STATUS_OFF == value) {
284 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
286 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
290 char *get_NFC_on_off_str()
292 int ret = SETTING_RETURN_FAIL;
293 int value = 0, err = 0;
294 ret = setting_get_bool_slp_key(BOOL_SLP_SETTING_NFC_STATUS, &value, &err);
296 if (SETTING_RETURN_FAIL == ret) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
297 SETTING_TRACE_DEBUG("fail to get nfc status from vconf");
298 value = VCONFKEY_NFC_STATE_OFF;
301 if (VCONFKEY_NFC_STATE_OFF == value) {
302 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
304 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
308 char *get_pa_time_format_str()
310 int ret = SETTING_RETURN_FAIL;
312 char *format_str[] = { _("IDS_COM_BODY_12_HOURS"),
313 _("IDS_ST_BODY_24_HOURS") };
315 setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
317 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
320 /* value 1:12H 2:24H */
321 if (value > 0 && value <= 2) /* 1, 2 */
322 return (char *)g_strdup(format_str[value - 1]);
324 return (char *)g_strdup(format_str[0]); /* set to 12H compelsery */
328 char *get_pa_date_format_str()
330 int ret = SETTING_RETURN_FAIL;
332 char *format_str[] = { _("IDS_ST_BODY_DDMMYYYY_DOT"),
333 _("IDS_ST_BODY_MM_DD_YYYY_DOT"),
334 _("IDS_COM_BODY_YYYYMMDD"), _("IDS_ST_BODY_YYYY_DD_MM_DOT")
337 setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
338 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
339 return (char *)g_strdup(format_str[value]);
342 char *get_pa_week_format_str()
344 int ret = SETTING_RETURN_FAIL;
346 char *format_str[] = {
347 _("IDS_ST_BODY_SUNDAY"),
348 _("IDS_ST_BODY_MONDAY"),
352 setting_get_int_slp_key(INT_SLP_SETTING_WEEK_FORMAT, &value, &err);
353 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
354 return (char *)g_strdup(format_str[value]);
357 char *get_pa_roaming_network_str()
359 int ret = SETTING_RETURN_FAIL;
361 char *roaming_str[] = {
362 _("IDS_ST_BODY_AUTO_DOWNLOAD"), _("IDS_COM_BODY_MANUAL"),
363 _("IDS_ST_BODY_ALWAYS_REJECT")
366 setting_get_int_slp_key(INT_SLP_SETTING_ROAMING_NETWORK, &value,
368 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
369 return (char *)g_strdup(roaming_str[value]);
372 double get_widgets_factor()
374 return elm_scale_get();
377 char *setting_gettext(const char *s)
379 /* fisrt find in app pg */
385 char *p = dgettext(SETTING_PACKAGE, s);
387 if (!safeStrCmp(s, p)) { /* not found */
388 /* find in system pkg */
389 p = dgettext(SYSTEM_PACKAGE, s);
394 bool is_digital_str(const char *cstr)
396 if (cstr == NULL || cstr[0] == 0) {
400 int len = (int)(safeStrLen(cstr));
402 if (cstr[0] == '-' || cstr[0] == '+') {
410 if (cstr[pos] < '0' || cstr[pos] > '9') {
419 bool is_substr_ncase(const char *parentstr, const char *substr)
421 if (NULL == parentstr || '\0' == parentstr[0])
424 int word_len = safeStrLen(parentstr);
425 int search_len = safeStrLen(substr);
428 for (i = 0; i < word_len; i++) {
429 if (!strncasecmp(substr, &parentstr[i], search_len)) {
437 bool is_string_belong_to_array(const char *partern, const char **array,
441 for (; idx < array_num; idx++) {
442 if (!safeStrCmp(partern, array[idx])) {
449 //remove sub string from a parent string
450 char *remove_first_substring(const char *parent, const char *pat)
452 setting_retvm_if(!parent, NULL, "NULL == parent, Exit %s with return NULL", __FUNCTION__);
453 char *str = strdup(parent); //to process the case parent pointing to const string
454 setting_retvm_if(!pat, str, "NULL == pat, Exit %s with return [%s]", __FUNCTION__, str);
457 int str_len = safeStrLen(str);
458 int pat_len = safeStrLen(pat);
459 setting_retvm_if(pat_len > str_len, str,
460 "patlen[%d] > strlen[%d], Exit %s with return [%s]",
461 pat_len, str_len, __FUNCTION__, str);
464 for (; idx < str_len; idx++) {
465 if (0 == safeStrNCmp(pat, str + idx, pat_len)) {
467 q = str + idx + pat_len;
479 //now str keeps the result string
480 SETTING_TRACE("Exit %s with return str:%s", __FUNCTION__, str);
485 //NULL, "", " ", " " etc.. are all empty strings
486 bool isEmptyStr(const char *str)
492 if (*str != '\0' && *str != ' ')
496 else if (*str == '\0')
506 int safeStrCmp(const char *s1, const char *s2)
508 /* Check NULL value first */
509 if (isEmptyStr(s1) && isEmptyStr(s2)) {
511 } else if (isEmptyStr(s1)) {
513 } else if (isEmptyStr(s2)) {
514 return SETTING_RETURN_FAIL;
517 return strcmp(s1, s2);
520 int safeStrNCmp(const char *s1, const char *s2, int len)
523 /* Check NULL value first */
524 if (isEmptyStr(s1) && isEmptyStr(s2)) {
526 } else if (isEmptyStr(s1)) {
528 } else if (isEmptyStr(s2)) {
529 return SETTING_RETURN_FAIL;
536 return strncmp(s1, s2, len);
539 char *safeStrNCat(char *dst, const char *src, int maxlen)
541 if (dst && !isEmptyStr(src) && maxlen > 0) {
542 (void) g_strlcat(dst, src, maxlen + 1);
549 char *safeCopyStr(char *dst, const char *src, int maxlen)
559 int temp = (int)safeStrLen(src);
560 len = (temp <= maxlen) ? temp : maxlen;
561 memcpy(dst, src, len);
570 int safeStrLen(const char *str)
572 if (isEmptyStr(str)) {
573 SETTING_TRACE_DEBUG("string is empty");
581 * get the int value of substring before delim
583 bool get_substring_int(const char **ipStr, int *ipValue, char delim)
585 int iValue = *ipValue = 0;
586 const char *str = *ipStr;
588 if (str == NULL || str[0] == 0) { /* empty string */
592 bool bNegative = FALSE;
593 if ('-' == str[0]) { /* allow Negative number.. */
597 if (str[0] < '0' || str[0] > '9') { /* first elementy is not digital */
601 if (str[0] == '0') { /* first elementy is 0 */
602 if (str[1] == delim) {
617 /****first elementy is not 0*/
618 iValue = iValue * 10 + str[0] - '0';
620 if (((unsigned int)iValue & 0x80000000) != 0) { /* think about overloading */
624 if (str[0] == delim) {
641 if (str[0] < '0' || str[0] > '9') {
650 #define MaxIPAddressLength 15
653 * CHeck Whether a special string Is An IP String
655 * @param ipstr string representing IP numbers like "aaa.bbb.ccc.ddd"
657 * @return true if it's IP format string otherwise false
659 bool is_ip_string(const char *ipstr)
661 if (NULL == ipstr || 0 == ipstr[0])
663 int len = (int)safeStrLen(ipstr);
664 if (len > MaxIPAddressLength) {
668 if (ipstr[len - 1] == '.') {
675 if (!get_substring_int(&ipstr, &ip, '.') || ip > 255) {
676 SETTING_TRACE("ipstr:%s", ipstr);
679 SETTING_TRACE("ipstr:%s", ipstr);
688 int setting_invoke_reset_function(char *ug_name, service_h service, void *ext)
690 SETTING_TRACE("Enter %s with ug_name:%s", __FUNCTION__, ug_name);
691 int (*reset) (service_h pair, void *ptr);
692 int ret = OPERATE_LIB_SUCESS;
694 //1.first do exist-checking in /opt/ug/lib
695 char ug_file[PATH_MAX + 1];
696 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH, ug_name);
698 if(stat(ug_file, &st) != 0) {
700 //2.if it does not exit in /opt/ug/lib, then do exist-checking in /usr/ug/lib
701 memset(ug_file, 0x00, PATH_MAX + 1);
702 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR, ug_name);
703 if(stat(ug_file, &st) != 0) {
704 //both not exist,skip it
705 SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
706 return OPERATE_LIB_SUCESS;
709 //-------------------------------------------------------------------------------------
710 void *handle = dlopen(ug_file, RTLD_LAZY);
712 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", dlerror());
713 return LOAD_LIB_FAILED;
717 reset = dlsym(handle, "setting_plugin_reset");
718 if ((error = dlerror()) != NULL) {
719 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", error);
721 return UNDEFINED_LIB_SYMBOL;
725 ret = (*reset) (service, ext); /* CALL */
727 if (ret < 0) ret += UNDEFINED_LIB_SYMBOL;//from -2 on
733 int excuteCmd(char* exec_path, int option_num, ...)
735 char cmd[MAX_COMMON_BUFFER_LEN + 1] = {0, };
736 snprintf(cmd, MAX_COMMON_BUFFER_LEN,
741 va_start(args, option_num);
745 for (; argno < option_num; argno++) {
746 para = va_arg( args, char *);
747 SETTING_TRACE("Parameter #%d is: %s", argno, para);
750 g_strlcat(cmd, " ", MAX_COMMON_BUFFER_LEN + 1);
751 g_strlcat(cmd, para, MAX_COMMON_BUFFER_LEN + 1);
757 SETTING_TRACE("excute:%s", cmd);
762 void create_fontlink(const char *linkpath, const char *linkname,
763 const char *fontfilepath, const char *fontfilename)
765 char newpath[MAX_COMMON_BUFFER_LEN + 1];
766 char lcpath[MAX_COMMON_BUFFER_LEN + 1];
769 snprintf(newpath, MAX_COMMON_BUFFER_LEN, "%s/%s", linkpath, linkname);
771 snprintf(lcpath, MAX_COMMON_BUFFER_LEN, "%s/%s", fontfilepath, fontfilename);
773 SETTING_TRACE("newpath:%s", newpath);
774 SETTING_TRACE("lcpath:%s", lcpath);
777 ret = symlink(lcpath, newpath);
778 setting_retm_if(ret != 0, "fail to call symlink");
781 char* get_icon_path(const char *package)
783 ail_appinfo_h handle;
786 char *icon_path = IMG_DefaultIcon;//The default icon must exist.(it will be installed by Setting App)
791 if (ail_package_get_appinfo(package, &handle) != AIL_ERROR_OK) {
792 SETTING_TRACE_ERROR("Failed to ail_package_get_appinfo.");
797 if (result && ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &icon_path) != AIL_ERROR_OK) {
798 SETTING_TRACE_ERROR("Failed to ail_appinfo_get_str.");
802 if (result && access(icon_path, R_OK|F_OK ) !=0 ) {//The file cannot be accessed.
803 SETTING_TRACE_ERROR("The file[%s] cannot be accessed. To use defaut icon.", icon_path);
804 icon_path = IMG_DefaultIcon;
807 ret_str = strdup(icon_path);
808 if (destroy && ail_package_destroy_appinfo(handle) != AIL_ERROR_OK) {
809 SETTING_TRACE_ERROR("Failed to ail_package_destroy_appinfo.");
819 int ret = system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &str);
820 if (ret != SYSTEM_INFO_ERROR_NONE) {
821 SETTING_TRACE_ERROR("fail to call system_info_get_value_string");
831 if (!strncmp(str, "SLP", 3)){
844 char *model_str = NULL;
845 int ret = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model_str);
846 //SETTING_TRACE("model_str : %s", model_str);
847 if (ret != SYSTEM_INFO_ERROR_NONE) {
848 SETTING_TRACE_ERROR("fail to call system_info_get_value_string");
853 if (0 == safeStrCmp(KeyStr_Emulator, model_str)) {
862 int get_popup_btn_response_type(const char *btn_str)
864 SETTING_TRACE("btn_str:%s", btn_str);
865 POPUP_BTN_RESPONSE_TYPE rsp_type = POPUP_RESPONSE_INVALID;
866 retv_if(!btn_str, rsp_type);
867 if (0 == safeStrCmp(btn_str, _("IDS_COM_BODY_CLOSE"))
868 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_TRY"))//KeyStr_Try
869 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_OK"))
870 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_YES"))
871 || 0 == safeStrCmp(btn_str, _("IDS_ST_BODY_USE_MOTION"))
872 || 0 == safeStrCmp(btn_str, _("IDS_COM_POP_TRY_AGAIN"))
873 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_DELETE"))
874 || 0 == safeStrCmp(btn_str, _(KeyStr_Save)))
876 rsp_type = POPUP_RESPONSE_OK;
880 rsp_type = POPUP_RESPONSE_CANCEL;
885 #define SUPPORT_STATIC_LOAD 1
886 #if SUPPORT_STATIC_LOAD
887 static char *system_service_list[MAX_SYSTEM_SERVICE_NUM] = {NULL, };
889 void clear_system_service_data()
891 #if SUPPORT_STATIC_LOAD
893 for (idx = 0; idx < MAX_SYSTEM_SERVICE_NUM && system_service_list[idx]; idx++)
895 FREE(system_service_list[idx]);
900 bool is_system_service(const char *pkg_name)
902 //SLP native apps list,
903 if (0 == safeStrCmp(pkg_name, "com.samsung.menu-screen")
904 || 0 == safeStrCmp(pkg_name, "com.samsung.live-data-provider")
905 || 0 == safeStrCmp(pkg_name, "com.samsung.live-magazine")
906 || 0 == safeStrCmp(pkg_name, "com.samsung.pwlock")
907 || 0 == safeStrCmp(pkg_name, "com.samsung.quickpanel")
908 || 0 == safeStrCmp(pkg_name, "com.samsung.vtmain")
909 || 0 == safeStrCmp(pkg_name, "com.samsung.call")
910 || 0 == safeStrCmp(pkg_name, "usb_setting")
911 || 0 == safeStrCmp(pkg_name, "com.samsung.indicator")
912 || 0 == safeStrCmp(pkg_name, "com.samsung.cluster-home")
918 //OSP service app list,
920 #if SUPPORT_STATIC_LOAD
922 if (!system_service_list[0]) //just load the file
924 FILE *fp = fopen(SYSTEM_SERVICE_LIST_PATH, "r");
926 char result[MAX_PKG_NAME_LEN+1] = {0, };
927 while (fgets(result, MAX_PKG_NAME_LEN, fp))
929 result[strlen(result) - 1] = '\0';//offset 1
930 system_service_list[idx++] = strdup(result);
937 for (idx = 0; idx < MAX_SYSTEM_SERVICE_NUM && system_service_list[idx]; idx++)
939 if (0 == safeStrCmp(pkg_name, system_service_list[idx])) {
945 FILE *fp = fopen(SYSTEM_SERVICE_LIST_PATH, "r");
947 char result[MAX_PKG_NAME_LEN+1] = {0, };
948 while (fgets(result, MAX_PKG_NAME_LEN, fp))
950 result[strlen(result) - 1] = '\0';//offset 1
951 if (0 == safeStrCmp(pkg_name, result)) {
959 SETTING_TRACE("ret:%d", ret);
964 * should use g_free to free returned string
966 char *get_default_font(int language)
968 char *font_name = NULL;
972 case SETTING_LANG_KOREA:
973 font_name = g_strdup("SLPSansKorean");
975 case SETTING_LANG_CHINA:
976 /* output_font : SLPSansFallback*/
977 case SETTING_LANG_CANTONESE:
978 /* output_font : SLPSansFallback*/
979 case SETTING_LANG_TAIWAN:
980 font_name = g_strdup("SLPSansFallback");
982 case SETTING_LANG_JAPAN:
983 font_name = g_strdup("UDGothic");
985 case SETTING_LANG_AUTOMATIC:
986 /* output_font : HelveticaNeue*/
987 case SETTING_LANG_ENGLISH:
988 /* output_font : HelveticaNeue*/
989 case SETTING_LANG_GERMAN:
990 /* output_font : HelveticaNeue*/
991 case SETTING_LANG_DUTCH:
992 /* output_font : HelveticaNeue*/
993 case SETTING_LANG_SPAINISH:
994 /* output_font : HelveticaNeue*/
995 case SETTING_LANG_PORTUGUESE:
996 /* output_font : HelveticaNeue*/
997 case SETTING_LANG_GREEK:
998 /* output_font : HelveticaNeue*/
999 case SETTING_LANG_ITALIAN:
1000 /* output_font : HelveticaNeue*/
1001 case SETTING_LANG_FRENCH:
1002 /* output_font : HelveticaNeue*/
1003 case SETTING_LANG_TURKISH:
1004 /* output_font : HelveticaNeue*/
1005 case SETTING_LANG_RUSSIAN:
1006 font_name = g_strdup("HelveticaNeue");
1009 font_name = g_strdup("HelveticaNeue");
1015 void *font_conf_doc_parse(char *doc_name, char *font_name)
1017 SETTING_TRACE_BEGIN;
1018 setting_retvm_if(doc_name == NULL, NULL, "Param data is NULL");
1019 setting_retvm_if(font_name == NULL, NULL, "Param data is NULL");
1020 xmlDocPtr doc = NULL;
1021 xmlNodePtr cur = NULL;
1022 xmlNodePtr cur2 = NULL;
1023 xmlNodePtr cur3 = NULL;
1024 xmlChar *key = NULL;
1026 doc = xmlParseFile(doc_name);
1027 setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
1029 cur = xmlDocGetRootElement(doc);
1032 SETTING_TRACE_DEBUG("empty document");
1038 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1039 SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
1045 cur = cur->xmlChildrenNode;
1047 Eina_Bool is_changed = EINA_FALSE;
1050 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
1052 cur2 = cur->xmlChildrenNode;
1055 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
1057 xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
1058 SETTING_TRACE_DEBUG("name is: %s", name);
1059 /* if name is not 'family', break */
1060 if (xmlStrcmp(name, (const xmlChar *)"family"))
1069 cur3 = cur2->xmlChildrenNode;
1072 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
1074 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
1075 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1076 SETTING_TRACE_DEBUG("after changed, string is: %s", key);
1079 is_changed = EINA_TRUE;
1086 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias")))
1088 cur2 = cur->xmlChildrenNode;
1089 while (cur2 != NULL)
1091 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family")))
1093 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
1094 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
1095 SETTING_TRACE_DEBUG("after changed, string is: %s", key);
1098 is_changed = EINA_TRUE;
1099 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer")))
1101 cur3 = cur2->xmlChildrenNode;
1102 while (cur3 != NULL)
1104 if((!xmlStrcmp(cur3->name, (const xmlChar *)"family")))
1106 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
1107 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1108 SETTING_TRACE_DEBUG("after changed, string is: %s", key);
1111 is_changed = EINA_TRUE;
1113 break; /* just set first element, so break */
1135 * should use g_free to free return string
1137 char *cur_font_get()
1139 SETTING_TRACE_BEGIN;
1140 xmlDocPtr doc = NULL;
1141 xmlNodePtr cur = NULL;
1142 xmlNodePtr cur2 = NULL;
1143 xmlNodePtr cur3 = NULL;
1144 xmlChar *key = NULL;
1146 char *font_name = NULL;
1148 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
1149 setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
1151 cur = xmlDocGetRootElement(doc);
1154 SETTING_TRACE_DEBUG("empty document");
1160 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1161 SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
1167 cur = cur->xmlChildrenNode;
1171 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
1173 cur2 = cur->xmlChildrenNode;
1176 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
1178 cur3 = cur2->xmlChildrenNode;
1181 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
1183 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1184 SETTING_TRACE_DEBUG("string is: %s", key);
1186 font_name = g_strdup((char *)key);
1207 static int __font_size_get()
1212 int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &value, &err);
1213 retvm_if(ret != 0, -1, "get vconf failed");
1216 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1217 font_size = SMALL_FONT_DPI;
1219 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1220 font_size = MIDDLE_FONT_DPI;
1222 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1223 font_size = LARGE_FONT_DPI;
1225 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1226 font_size = HUGE_FONT_DPI;
1228 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1229 font_size = GIANT_FONT_DPI;
1232 font_size = MIDDLE_FONT_DPI;
1238 void font_config_set(char *font_name)
1240 Eina_List *text_classes = NULL;
1241 Elm_Text_Class *etc = NULL;
1242 const Eina_List *l = NULL;
1243 Eina_List *fo_list = NULL;
1244 Elm_Font_Overlay *efo = NULL;
1245 int font_size = __font_size_get();
1248 text_classes = elm_config_text_classes_list_get();
1250 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
1252 Eina_List *ll = NULL;
1253 Eina_List *l_next = NULL;
1255 Eina_Bool slp_medium_exist = EINA_FALSE;
1256 Eina_Bool slp_roman_exist = EINA_FALSE;
1257 Eina_Bool slp_bold_exist = EINA_FALSE;
1258 Eina_Bool slp_regular_exist = EINA_FALSE;
1260 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
1262 if (!safeStrCmp(efo->text_class, "slp_medium")) {
1263 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1264 slp_medium_exist = EINA_TRUE;
1265 } else if (!safeStrCmp(efo->text_class, "slp_roman")) {
1266 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1267 slp_roman_exist = EINA_TRUE;
1268 } else if (!safeStrCmp(efo->text_class, "slp_bold")) {
1269 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1270 slp_bold_exist = EINA_TRUE;
1271 } else if (!safeStrCmp(efo->text_class, "slp_regular")) {
1272 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1273 slp_regular_exist = EINA_TRUE;
1277 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
1278 if (slp_medium_exist == EINA_FALSE) {
1279 elm_config_font_overlay_set("slp_medium", (const char*)font_name, MIDDLE_FONT_DPI);
1281 if (slp_roman_exist == EINA_FALSE) {
1282 elm_config_font_overlay_set("slp_roman", (const char*)font_name, MIDDLE_FONT_DPI);
1284 if (slp_bold_exist == EINA_FALSE) {
1285 elm_config_font_overlay_set("slp_bold", (const char*)font_name, MIDDLE_FONT_DPI);
1287 if (slp_regular_exist == EINA_FALSE) {
1288 elm_config_font_overlay_set("slp_regular", (const char*)font_name, MIDDLE_FONT_DPI);
1291 EINA_LIST_FOREACH(text_classes, l, etc)
1296 EINA_LIST_FOREACH(fo_list, ll, efo)
1298 if (!safeStrCmp(etc->name, efo->text_class)) {
1302 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
1305 elm_config_font_overlay_apply();
1306 elm_config_all_flush();
1307 elm_config_engine_set("software_x11");
1309 elm_config_text_classes_list_free(text_classes);
1310 text_classes = NULL;
1313 vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
1316 void font_size_set()
1318 Eina_List *text_classes = NULL;
1319 Elm_Text_Class *etc = NULL;
1320 const Eina_List *l = NULL;
1321 int font_size = __font_size_get();
1322 char *font_name = cur_font_get();
1324 if (font_size == -1) {
1325 SETTING_TRACE_DEBUG("failed to call font_size_get");
1329 text_classes = elm_config_text_classes_list_get();
1331 EINA_LIST_FOREACH(text_classes, l, etc)
1333 elm_config_font_overlay_set(etc->name, font_name, font_size);
1336 elm_config_all_flush();
1337 elm_config_engine_set("software_x11");
1339 elm_config_text_classes_list_free(text_classes);
1340 text_classes = NULL;