3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.1 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <setting-common-general-func.h>
19 #include <setting-common-data-slp-setting.h>
23 #include <libxml/xmlmemory.h>
24 #include <libxml/parser.h>
25 #include <system_info.h>
27 #include <system_settings.h>
30 char *setting_file_basename(char *path)
32 if (NULL == path || '\0' == path[0]) {
33 return NULL; /* invalid arguement */
35 char *p = strrchr(path, '/');
37 return (char *)g_strdup(path); /* cannot find '/' */
40 return NULL; /* end with '/' */
42 return (char *)g_strdup(p + 1);
46 char *get_pa_usb_connect_mode_str()
48 int ret = SETTING_RETURN_FAIL;
51 ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &value);
52 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
56 case SETTING_USB_DEBUG_MODE:
57 return (char*)g_strdup(_("IDS_ST_BODY_USB_DEBUGGING"));
59 return (char*)g_strdup(_("IDS_COM_POP_DISCONNECTED"));
64 char *get_brightness_mode_str()
67 setting_get_int_slp_key(INT_SLP_SETTING_AUTOMATIC_BRIGHTNESS, &value,
69 if (value != SETTING_BRIGHTNESS_AUTOMATIC_OFF) {
70 return setting_gettext("IDS_COM_BODY_AUTOMATIC");
72 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, value, &err);
153 snprintf(backlight_time_str, sizeof(backlight_time_str), "%s",
154 _("IDS_ST_BODY_ALWAYS_ON"));
155 } else if (value == 60) {
156 snprintf(backlight_time_str, sizeof(backlight_time_str), "%s",
157 _("IDS_COM_BODY_1_MINUTE"));
158 } else if (value > 60) {
159 snprintf(backlight_time_str, sizeof(backlight_time_str),
160 "%d %s", value / 60, (char *)(_("IDS_COM_BODY_MINUTES_LC")));
162 snprintf(backlight_time_str, sizeof(backlight_time_str),
163 "%d %s", value, (char *)(_("IDS_COM_BODY_SECONDS_LC")));
165 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);
190 char *get_pa_screen_timeout_str()
193 char screen_timeout_str[MAX_DISPLAY_NAME_LEN_ON_UI + 1];
197 setting_get_int_slp_key(INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT,
200 if (SETTING_RETURN_FAIL == ret || value < 0) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
201 value = 15; /* keep agree with postin file */
202 setting_set_int_slp_key
203 (INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT, value, &err);
207 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI, "%s",
209 } else if (value >= 60) {
210 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
212 (char *)(_("IDS_COM_BODY_MINUTES_LC")));
214 snprintf(screen_timeout_str, MAX_DISPLAY_NAME_LEN_ON_UI,
216 (char *)(_("IDS_COM_BODY_SECONDS_LC")));
218 return (char *)g_strdup(screen_timeout_str);
222 char *get_pa_display_language_str()
224 int ret = SETTING_RETURN_FAIL;
228 Eina_List* list = setting_get_language_list();
229 Eina_List* elist = NULL;
231 ret = setting_get_int_slp_key(INT_SLP_SETTING_LANG, &index, &err);
234 return g_strdup("Automatic");
236 setting_lang_entry* pnode;
239 EINA_LIST_FOREACH( list, elist, pnode)
241 if (pnode->number == index)
242 title = g_strdup(pnode->title);
247 char *get_pa_Wi_Fi_on_off_str()
250 int ret = SETTING_RETURN_FAIL;
252 setting_get_int_slp_key(INT_SLP_SETTING_WIFI_STATUS, &value, &err);
254 if (SETTING_RETURN_FAIL == ret) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
255 value = VCONFKEY_WIFI_OFF;
256 setting_set_int_slp_key(INT_SLP_SETTING_WIFI_STATUS,
257 VCONFKEY_WIFI_OFF, &err);
261 char *pa_wifi_device = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
262 SETTING_TRACE("pa_wifi_device:%s", pa_wifi_device);
263 if (NULL != pa_wifi_device && '\0' != pa_wifi_device[0]) {
264 return pa_wifi_device;
267 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_ON_M_STATUS"));
269 return (char*)g_strdup(setting_gettext("IDS_COM_BODY_OFF_M_STATUS"));
273 char *get_BT_on_off_str()
275 int ret = SETTING_RETURN_FAIL;
277 ret = setting_get_int_slp_key(INT_SLP_SETTING_BT_STATUS, &value, &err);
279 if (SETTING_RETURN_FAIL == ret) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
280 value = VCONFKEY_BT_STATUS_OFF;
281 setting_set_int_slp_key(INT_SLP_SETTING_BT_STATUS,
282 VCONFKEY_BT_STATUS_OFF, &err);
285 if (VCONFKEY_BT_STATUS_OFF == value) {
286 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
288 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
293 char *get_NFC_on_off_str()
295 int ret = SETTING_RETURN_FAIL;
296 int value = 0, err = 0;
297 ret = setting_get_bool_slp_key(BOOL_SLP_SETTING_NFC_STATUS, &value, &err);
299 if (SETTING_RETURN_FAIL == ret) { /* file system exceptional handle, eg. The vconf file lost due to file system. */
300 SETTING_TRACE_DEBUG("fail to get nfc status from vconf");
301 value = VCONFKEY_NFC_STATE_OFF;
304 if (VCONFKEY_NFC_STATE_OFF == value) {
305 return setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
307 return setting_gettext("IDS_COM_BODY_ON_M_STATUS");
312 char *get_pa_time_format_str()
314 int ret = SETTING_RETURN_FAIL;
316 char *format_str[] = { _("IDS_COM_BODY_12_HOURS"),
317 _("IDS_ST_BODY_24_HOURS") };
319 setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
321 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
324 /* value 1:12H 2:24H */
325 if (value > 0 && value <= 2) /* 1, 2 */
326 return (char *)g_strdup(format_str[value - 1]);
328 return (char *)g_strdup(format_str[0]); /* set to 12H compelsery */
333 char *get_pa_date_format_str()
335 int ret = SETTING_RETURN_FAIL;
337 char *format_str[] = { _("IDS_ST_BODY_DDMMYYYY_DOT"),
338 _("IDS_ST_BODY_MM_DD_YYYY_DOT"),
339 _("IDS_COM_BODY_YYYYMMDD"), _("IDS_ST_BODY_YYYY_DD_MM_DOT")
342 setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
343 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
344 return (char *)g_strdup(format_str[value]);
348 char *get_pa_week_format_str()
350 int ret = SETTING_RETURN_FAIL;
352 char *format_str[] = {
353 _("IDS_ST_BODY_SUNDAY"),
354 _("IDS_ST_BODY_MONDAY"),
358 setting_get_int_slp_key(INT_SLP_SETTING_WEEK_FORMAT, &value, &err);
359 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
360 return (char *)g_strdup(format_str[value]);
364 char *get_pa_roaming_network_str()
366 int ret = SETTING_RETURN_FAIL;
368 char *roaming_str[] = {
369 _("IDS_ST_BODY_AUTO_DOWNLOAD"), _("IDS_COM_BODY_MANUAL"),
370 _("IDS_ST_BODY_ALWAYS_REJECT")
373 setting_get_int_slp_key(INT_SLP_SETTING_ROAMING_NETWORK, &value,
375 setting_retvm_if(SETTING_RETURN_FAIL == ret, NULL, "Failed to get vconf value"); /* file system exceptional handle */
376 return (char *)g_strdup(roaming_str[value]);
379 char *get_pa_select_network()
384 char *net_name = NULL;
385 int service_type = VCONFKEY_TELEPHONY_SVCTYPE_SEARCH;
386 if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &service_type) != 0) {
387 SETTING_TRACE("fail to get VCONFKEY_TELEPHONY_SVCTYPE");
390 retv_if(service_type == VCONFKEY_TELEPHONY_SVCTYPE_NOSVC, (char *)strdup(_("IDS_COM_BODY_NO_SERVICE")));
391 retv_if(service_type == VCONFKEY_TELEPHONY_SVCTYPE_EMERGENCY, (char *)strdup(_("Emergency calls only")));
392 retv_if(service_type == VCONFKEY_TELEPHONY_SVCTYPE_SEARCH || service_type == VCONFKEY_TELEPHONY_SVCTYPE_NONE, (char *)strdup(_("IDS_COM_BODY_SEARCHING")));
394 ret = vconf_get_int(VCONFKEY_TELEPHONY_SPN_DISP_CONDITION, &state);
396 //SETTING_TRACE("VCONFKEY(%s) = %d", VCONFKEY_TELEPHONY_SPN_DISP_CONDITION, state);
397 char name[MAX_COMMON_BUFFER_LEN] = { 0, };
398 const char *kv = NULL;
400 if (state != VCONFKEY_TELEPHONY_DISP_INVALID) {
403 if (state & VCONFKEY_TELEPHONY_DISP_SPN) {
404 kv = vconf_get_str(VCONFKEY_TELEPHONY_SPN_NAME);
405 g_strlcat(name, kv, MAX_COMMON_BUFFER_LEN);
410 if (state & VCONFKEY_TELEPHONY_DISP_PLMN) {
412 g_strlcat(name, " - ", MAX_COMMON_BUFFER_LEN);
414 kv = vconf_get_str(VCONFKEY_TELEPHONY_NWNAME);
415 g_strlcat(name, kv, MAX_COMMON_BUFFER_LEN);
419 net_name = isEmptyStr(name) ? NULL : (char *)strdup(name);
421 } else { //exceptional: state == VCONFKEY_TELEPHONY_DISP_INVALID
422 //kv = vconf_get_str(VCONFKEY_TELEPHONY_NWNAME);
423 //net_name = (char *)strdup(kv);
425 // there is no name to display. displaying blank (if blank looks strange in UI point of view, we need to display something instead of blank)
434 double get_widgets_factor()
436 return elm_config_scale_get();
440 char *setting_gettext(const char *s)
442 /* fisrt find in app pg */
448 char *p = dgettext(SETTING_PACKAGE, s);
450 if (!safeStrCmp(s, p)) { /* not found */
451 /* find in system pkg */
452 p = dgettext(SYSTEM_PACKAGE, s);
458 bool is_digital_str(const char *cstr)
460 if (cstr == NULL || cstr[0] == 0) {
464 int len = (int)(safeStrLen(cstr));
466 if (cstr[0] == '-' || cstr[0] == '+') {
474 if (cstr[pos] < '0' || cstr[pos] > '9') {
484 bool is_substr_ncase(const char *parentstr, const char *substr)
486 if (NULL == parentstr || '\0' == parentstr[0])
489 int word_len = safeStrLen(parentstr);
490 int search_len = safeStrLen(substr);
493 for (i = 0; i < word_len; i++) {
494 if (!strncasecmp(substr, &parentstr[i], search_len)) {
503 bool is_string_belong_to_array(const char *partern, const char **array,
507 for (; idx < array_num; idx++) {
508 if (!safeStrCmp(partern, array[idx])) {
516 //remove sub string from a parent string
517 char *remove_first_substring(const char *parent, const char *pat)
519 setting_retvm_if(!parent, NULL, "NULL == parent, Exit %s with return NULL", __FUNCTION__);
520 char *str = strdup(parent); //to process the case parent pointing to const string
521 setting_retvm_if(!pat, str, "NULL == pat, Exit %s with return [%s]", __FUNCTION__, str);
524 int str_len = safeStrLen(str);
525 int pat_len = safeStrLen(pat);
526 setting_retvm_if(pat_len > str_len, str,
527 "patlen[%d] > strlen[%d], Exit %s with return [%s]",
528 pat_len, str_len, __FUNCTION__, str);
531 for (; idx < str_len; idx++) {
532 if (0 == safeStrNCmp(pat, str + idx, pat_len)) {
534 q = str + idx + pat_len;
546 //now str keeps the result string
547 SETTING_TRACE("Exit %s with return str:%s", __FUNCTION__, str);
551 //return True just when NULL or '\0'
552 bool isEmptyStr(const char *str)
554 if (NULL == str || '\0' == str[0])
559 //return True just when str is NULL, '\0' or all strings made up of spaces
560 bool isSpaceStr(const char *str)
566 if (*str != '\0' && *str != ' ')
570 else if (*str == '\0')
580 int safeStrCmp(const char *s1, const char *s2)
582 /* Check NULL value first */
583 if (isEmptyStr(s1) && isEmptyStr(s2)) {
585 } else if (isEmptyStr(s1)) {
587 } else if (isEmptyStr(s2)) {
588 return SETTING_RETURN_FAIL;
591 return strcmp(s1, s2);
595 int safeStrNCmp(const char *s1, const char *s2, int len)
598 /* Check NULL value first */
599 if (isEmptyStr(s1) && isEmptyStr(s2)) {
601 } else if (isEmptyStr(s1)) {
603 } else if (isEmptyStr(s2)) {
604 return SETTING_RETURN_FAIL;
611 return strncmp(s1, s2, len);
615 char *safeStrNCat(char *dst, const char *src, int maxlen)
617 if (dst && !isEmptyStr(src) && maxlen > 0) {
618 (void) g_strlcat(dst, src, maxlen + 1);
625 char *safeCopyStr(char *dst, const char *src, int maxlen)
635 int temp = (int)safeStrLen(src);
636 len = (temp <= maxlen) ? temp : maxlen;
637 memcpy(dst, src, len);
645 int safeStrLen(const char *str)
647 if (isEmptyStr(str)) {
648 SETTING_TRACE_DEBUG("string is empty");
657 * get the int value of substring before delim
659 bool get_substring_int(const char **ipStr, int *ipValue, char delim)
661 int iValue = *ipValue = 0;
662 const char *str = *ipStr;
664 if (str == NULL || str[0] == 0) { /* empty string */
668 bool bNegative = FALSE;
669 if ('-' == str[0]) { /* allow Negative number.. */
673 if (str[0] < '0' || str[0] > '9') { /* first elementy is not digital */
677 if (str[0] == '0') { /* first elementy is 0 */
678 if (str[1] == delim) {
693 /****first elementy is not 0*/
694 iValue = iValue * 10 + str[0] - '0';
696 if (((unsigned int)iValue & 0x80000000) != 0) { /* think about overloading */
700 if (str[0] == delim) {
717 if (str[0] < '0' || str[0] > '9') {
726 #define MaxIPAddressLength 15
729 * CHeck Whether a special string Is An IP String
731 * @param ipstr string representing IP numbers like "aaa.bbb.ccc.ddd"
732 * @return true if it's IP format string otherwise false
734 bool is_ip_string(const char *ipstr)
736 if (NULL == ipstr || 0 == ipstr[0])
738 int len = (int)safeStrLen(ipstr);
739 if (len > MaxIPAddressLength) {
743 if (ipstr[len - 1] == '.') {
750 if (!get_substring_int(&ipstr, &ip, '.') || ip > 255) {
751 SETTING_TRACE("ipstr:%s", ipstr);
754 SETTING_TRACE("ipstr:%s", ipstr);
763 int setting_invoke_reset_function(char *ug_name, service_h service, void *ext)
765 SETTING_TRACE("Enter %s with ug_name:%s", __FUNCTION__, ug_name);
766 int (*reset) (service_h pair, void *ptr);
767 int ret = OPERATE_LIB_SUCESS;
769 //1.first do exist-checking in /opt/ug/lib
770 char ug_file[PATH_MAX + 1];
771 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH, ug_name);
773 if(stat(ug_file, &st) != 0) {
775 //2.if it does not exit in /opt/ug/lib, then do exist-checking in /usr/ug/lib
776 memset(ug_file, 0x00, PATH_MAX + 1);
777 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR, ug_name);
778 if(stat(ug_file, &st) != 0) {
779 //both not exist,skip it
780 SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
781 return OPERATE_LIB_SUCESS;
784 //-------------------------------------------------------------------------------------
785 void *handle = dlopen(ug_file, RTLD_LAZY);
787 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", dlerror());
788 return LOAD_LIB_FAILED;
792 reset = dlsym(handle, "setting_plugin_reset");
793 if ((error = dlerror()) != NULL) {
794 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", error);
796 return UNDEFINED_LIB_SYMBOL;
800 ret = (*reset) (service, ext); /* CALL */
802 if (ret < 0) ret += UNDEFINED_LIB_SYMBOL;//from -2 on
809 int excuteCmd(char* exec_path, int option_num, ...)
811 char cmd[MAX_COMMON_BUFFER_LEN + 1] = {0, };
812 snprintf(cmd, MAX_COMMON_BUFFER_LEN,
817 va_start(args, option_num);
821 for (; argno < option_num; argno++) {
822 para = va_arg( args, char *);
823 SETTING_TRACE("Parameter #%d is: %s", argno, para);
826 g_strlcat(cmd, " ", MAX_COMMON_BUFFER_LEN + 1);
827 g_strlcat(cmd, para, MAX_COMMON_BUFFER_LEN + 1);
833 SETTING_TRACE("excute:%s", cmd);
838 void create_fontlink(const char *linkpath, const char *linkname,
839 const char *fontfilepath, const char *fontfilename)
841 char newpath[MAX_COMMON_BUFFER_LEN + 1];
842 char lcpath[MAX_COMMON_BUFFER_LEN + 1];
845 snprintf(newpath, MAX_COMMON_BUFFER_LEN, "%s/%s", linkpath, linkname);
847 snprintf(lcpath, MAX_COMMON_BUFFER_LEN, "%s/%s", fontfilepath, fontfilename);
849 SETTING_TRACE("newpath:%s", newpath);
850 SETTING_TRACE("lcpath:%s", lcpath);
853 ret = symlink(lcpath, newpath);
854 setting_retm_if(ret != 0, "fail to call symlink");
858 char* get_icon_path(const char *package)
860 ail_appinfo_h handle;
863 char *icon_path = IMG_DefaultIcon;//The default icon must exist.(it will be installed by Setting App)
868 if (ail_package_get_appinfo(package, &handle) != AIL_ERROR_OK) {
869 SETTING_TRACE_ERROR("Failed to ail_package_get_appinfo.");
874 if (result && ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &icon_path) != AIL_ERROR_OK) {
875 SETTING_TRACE_ERROR("Failed to ail_appinfo_get_str.");
879 if (result && access(icon_path, R_OK|F_OK ) !=0 ) {//The file cannot be accessed.
880 SETTING_TRACE_ERROR("The file[%s] cannot be accessed. To use defaut icon.", icon_path);
881 icon_path = IMG_DefaultIcon;
884 ret_str = strdup(icon_path);
885 if (destroy && ail_package_destroy_appinfo(handle) != AIL_ERROR_OK) {
886 SETTING_TRACE_ERROR("Failed to ail_package_destroy_appinfo.");
896 int ret = system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &str);
897 if (ret != SYSTEM_INFO_ERROR_NONE) {
898 SETTING_TRACE_ERROR("fail to call system_info_get_value_string");
908 if (!strncmp(str, "SLP", 3)){
922 char *model_str = NULL;
923 int ret = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model_str);
925 if (ret != SYSTEM_INFO_ERROR_NONE) {
926 SETTING_TRACE_ERROR("fail to call system_info_get_value_string");
931 if (0 == safeStrCmp(KeyStr_Emulator, model_str)) {
941 int get_popup_btn_response_type(const char *btn_str)
943 SETTING_TRACE("btn_str:%s", btn_str);
944 POPUP_BTN_RESPONSE_TYPE rsp_type = POPUP_RESPONSE_INVALID;
945 retv_if(!btn_str, rsp_type);
946 if (0 == safeStrCmp(btn_str, _("IDS_COM_BODY_CLOSE"))
947 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_TRY"))//KeyStr_Try
948 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_OK"))
949 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_YES"))
950 || 0 == safeStrCmp(btn_str, _("IDS_ST_BODY_USE_MOTION"))
951 || 0 == safeStrCmp(btn_str, _("IDS_COM_POP_TRY_AGAIN"))
952 || 0 == safeStrCmp(btn_str, _("IDS_COM_SK_DELETE"))
953 || 0 == safeStrCmp(btn_str, _(KeyStr_Save)))
955 rsp_type = POPUP_RESPONSE_OK;
959 rsp_type = POPUP_RESPONSE_CANCEL;
964 #define SUPPORT_STATIC_LOAD 1
965 #if SUPPORT_STATIC_LOAD
966 static char *system_service_list[MAX_SYSTEM_SERVICE_NUM] = {NULL, };
968 void clear_system_service_data()
970 #if SUPPORT_STATIC_LOAD
972 for (idx = 0; idx < MAX_SYSTEM_SERVICE_NUM && system_service_list[idx]; idx++)
974 FREE(system_service_list[idx]);
981 * should use g_free to free return string
982 * @see font_size_set()
987 xmlDocPtr doc = NULL;
988 xmlNodePtr cur = NULL;
989 xmlNodePtr cur2 = NULL;
990 xmlNodePtr cur3 = NULL;
993 char *font_name = NULL;
995 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
996 setting_retvm_if(doc == NULL, NULL, "Document not parsed successfully.");
998 cur = xmlDocGetRootElement(doc);
1001 SETTING_TRACE_DEBUG("empty document");
1007 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1008 SETTING_TRACE_DEBUG("document of the wrong type, root node != fontconfig");
1014 cur = cur->xmlChildrenNode;
1018 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
1020 cur2 = cur->xmlChildrenNode;
1023 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
1025 cur3 = cur2->xmlChildrenNode;
1028 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
1030 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1031 SETTING_TRACE_DEBUG("string is: %s", key);
1033 font_name = g_strdup((char *)key);
1056 * @see font_size_set()
1058 static int __font_size_get()
1063 int ret = setting_get_int_slp_key(INT_SLP_SETTING_ACCESSIBILITY_FONT_SIZE, &value, &err);
1064 retvm_if(ret != 0, -1, "get vconf failed");
1067 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1068 font_size = SMALL_FONT_DPI;
1070 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1071 font_size = MIDDLE_FONT_DPI;
1073 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1074 font_size = LARGE_FONT_DPI;
1076 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1077 font_size = HUGE_FONT_DPI;
1079 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1080 font_size = GIANT_FONT_DPI;
1083 font_size = MIDDLE_FONT_DPI;
1090 void font_config_set(char *font_name)
1092 Eina_List *text_classes = NULL;
1093 Elm_Text_Class *etc = NULL;
1094 const Eina_List *l = NULL;
1095 Eina_List *fo_list = NULL;
1096 Elm_Font_Overlay *efo = NULL;
1097 int font_size = __font_size_get();
1100 text_classes = elm_config_text_classes_list_get();
1102 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
1104 Eina_List *ll = NULL;
1105 Eina_List *l_next = NULL;
1107 Eina_Bool slp_medium_exist = EINA_FALSE;
1108 Eina_Bool slp_roman_exist = EINA_FALSE;
1109 Eina_Bool slp_bold_exist = EINA_FALSE;
1110 Eina_Bool slp_regular_exist = EINA_FALSE;
1113 Eina_Bool tizen_exist = EINA_FALSE;
1115 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo)
1117 if (!safeStrCmp(efo->text_class, "tizen_medium")) {
1118 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1119 slp_medium_exist = EINA_TRUE;
1120 } else if (!safeStrCmp(efo->text_class, "tizen_roman")) {
1121 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1122 slp_roman_exist = EINA_TRUE;
1123 } else if (!safeStrCmp(efo->text_class, "tizen_bold")) {
1124 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1125 slp_bold_exist = EINA_TRUE;
1126 } else if (!safeStrCmp(efo->text_class, "tizen_regular")) {
1127 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1128 slp_regular_exist = EINA_TRUE;
1132 if (!safeStrCmp(efo->text_class, "tizen")) {
1133 elm_config_font_overlay_set(efo->text_class, (const char*)font_name, efo->size);
1134 tizen_exist = EINA_TRUE;
1139 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
1140 if (slp_medium_exist == EINA_FALSE) {
1141 elm_config_font_overlay_set("tizen_medium", (const char*)font_name, MIDDLE_FONT_DPI);
1143 if (slp_roman_exist == EINA_FALSE) {
1144 elm_config_font_overlay_set("tizen_roman", (const char*)font_name, MIDDLE_FONT_DPI);
1146 if (slp_bold_exist == EINA_FALSE) {
1147 elm_config_font_overlay_set("tizen_bold", (const char*)font_name, MIDDLE_FONT_DPI);
1149 if (slp_regular_exist == EINA_FALSE) {
1150 elm_config_font_overlay_set("tizen_regular", (const char*)font_name, MIDDLE_FONT_DPI);
1154 if (tizen_exist == EINA_FALSE) {
1155 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
1158 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
1161 elm_config_font_overlay_set("tizen", (const char*)font_name, MIDDLE_FONT_DPI);
1163 EINA_LIST_FOREACH(text_classes, l, etc)
1168 EINA_LIST_FOREACH(fo_list, ll, efo)
1170 if (!safeStrCmp(etc->name, efo->text_class)) {
1174 elm_config_font_overlay_set(etc->name, (const char*)font_name, size);
1177 elm_config_font_overlay_apply();
1178 elm_config_all_flush();
1179 elm_config_engine_set("software_x11");
1181 elm_config_text_classes_list_free(text_classes);
1182 text_classes = NULL;
1185 vconf_set_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, font_name);
1190 * @see setting_font_font_size_list_mouse_up_cb
1192 void font_size_set()
1194 SETTING_TRACE_BEGIN;
1195 Eina_List *text_classes = NULL;
1196 Elm_Text_Class *etc = NULL;
1197 const Eina_List *l = NULL;
1198 int font_size = __font_size_get();
1199 char *font_name = cur_font_get();
1201 if (font_size == -1) {
1202 SETTING_TRACE_DEBUG("failed to call font_size_get");
1206 // update all screen
1207 text_classes = elm_config_text_classes_list_get();
1208 EINA_LIST_FOREACH(text_classes, l, etc)
1210 elm_config_font_overlay_set(etc->name, font_name, font_size);
1213 elm_config_all_flush();
1214 elm_config_engine_set("software_x11");
1216 elm_config_text_classes_list_free(text_classes);
1217 text_classes = NULL;
1224 void update_lang(void)
1229 lang = vconf_get_str(VCONFKEY_LANGSET);
1231 setenv("LANG", lang, 1);
1232 setenv("LC_MESSAGES", lang, 1);
1233 r = setlocale(LC_ALL, "");
1235 r = setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
1241 void update_region(void)
1245 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
1247 setenv("LC_CTYPE", region, 1);
1248 setenv("LC_NUMERIC", region, 1);
1249 setenv("LC_TIME", region, 1);
1250 setenv("LC_COLLATE", region, 1);
1251 setenv("LC_MONETARY", region, 1);
1252 setenv("LC_PAPER", region, 1);
1253 setenv("LC_NAME", region, 1);
1254 setenv("LC_ADDRESS", region, 1);
1255 setenv("LC_TELEPHONE", region, 1);
1256 setenv("LC_MEASUREMENT", region, 1);
1257 setenv("LC_IDENTIFICATION", region, 1);
1262 static int __set_i18n(const char *domain, const char *dir)
1265 if (domain == NULL) {
1270 r = setlocale(LC_ALL, "");
1271 /* if locale is not set properly, try again to set as language base */
1273 r = setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
1275 r = bindtextdomain(domain, dir);
1276 r = textdomain(domain);
1281 int setting_set_i18n(char* pkgname, char* localedir)
1282 //int set_i18n(const char *domainname, const char *dirname)
1289 return __set_i18n(pkgname, localedir);
1293 void app_launcher(char* pkg_name)
1296 service_create(&service);
1297 service_set_operation(service, SERVICE_OPERATION_DEFAULT);
1298 service_set_package(service, pkg_name);
1299 int launch_ret = service_send_launch_request(service, NULL, NULL);
1300 SETTING_TRACE("after app_service_create - %s : %d ", pkg_name, launch_ret);
1301 if (launch_ret == SERVICE_ERROR_NONE)
1304 SETTING_TRACE("on success");
1307 SETTING_TRACE("on error");
1309 service_destroy(service);
1313 char* substring(const char* str, size_t begin, size_t len)
1315 if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
1318 return strndup(str + begin, len);
1321 void set_defaultLangICU()
1323 // set default local automatically
1325 char *pa_region = vconf_get_str(VCONFKEY_LANGSET);
1326 char* pa_sub = substring(pa_region, 0, 4);
1327 SETTING_TRACE(" main - region set from ug result : %s", pa_sub);
1329 uloc_setDefault(pa_region, &err);
1330 SETTING_TRACE("errorcode %d ", err);