get system settings locale 18/42218/5 tizen_3.0.m1_mobile tizen_3.0.m1_tv accepted/tizen/mobile/20150721.043244 accepted/tizen/tv/20150721.043310 accepted/tizen/wearable/20150721.043337 submit/tizen/20150721.020022 submit/tizen_common/20151023.083358 submit/tizen_common/20151026.085049 tizen_3.0.m1_mobile_release tizen_3.0.m1_tv_release tizen_3.0.m2.a1_mobile_release tizen_3.0.m2.a1_tv_release
authorGukhwan Cho <gh78.cho@samsung.com>
Wed, 24 Jun 2015 13:27:04 +0000 (22:27 +0900)
committerjiwon44.park <jiwon44park@jiwon44.park>
Fri, 17 Jul 2015 06:27:27 +0000 (15:27 +0900)
Change-Id: I9536515caf2b30b1fdb68b49a0d1e2fd7e8b95c3
Signed-off-by: Gukhwan Cho <gh78.cho@samsung.com>
CMakeLists.txt
include/phone_number_types.h
packaging/phonenumber-utils.spec
src/phn.c
src/phn_common.h
src/phn_location.c
src/phn_location.h
src/phn_region_data.c
src/phn_region_data.h

index dc13772ab1d8cbde2bbd5fb964e65bd6cb451cf4..26e64d0f90cae480621328682c82e68b70466375 100644 (file)
@@ -13,7 +13,7 @@ SET(SRC_FILE
        src/phn_phonenumber_wrapper.cpp
 )
 INCLUDE(FindPkgConfig)
-pkg_check_modules(PN_pkgs REQUIRED dlog icu-i18n glib-2.0 capi-base-common)
+pkg_check_modules(PN_pkgs REQUIRED dlog icu-i18n glib-2.0 capi-base-common capi-system-system-settings)
 INCLUDE_DIRECTORIES(${PN_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${PN_pkgs_LIBRARY_DIRS})
 
index 3a7a01aae4fba6f74999e57c2dacf4c9919feb04..e6ca45adb0097273fa99d26ebaf7096581f9e097 100644 (file)
@@ -67,6 +67,7 @@ typedef enum {
        PHONE_NUMBER_LANG_THAI,                         /**< Thai */
        PHONE_NUMBER_LANG_TURKISH,                      /**< Turkish */
        PHONE_NUMBER_LANG_VIETNAMESE,                   /**< Vietnamese */
+       PHONE_NUMBER_LANG_SYSTEM,                       /**< Current System Value (Since 3.0) */
        PHONE_NUMBER_LANG_MAX,
 } phone_number_lang_e;
 
@@ -209,6 +210,7 @@ typedef enum {
        PHONE_NUMBER_REGION_WESTERN_SAHARA,                             /**< Western Sahara */
        PHONE_NUMBER_REGION_ZAMBIA,                                     /**< Zambia */
        PHONE_NUMBER_REGION_ZIMBABWE,                                   /**< Zimbabwe */
+       PHONE_NUMBER_REGION_SYSTEM,                                     /**< Current System Value (Since 3.0) */
        PHONE_NUMBER_REGION_MAX,
 } phone_number_region_e;
 
index 56aae9fc14b66ac7261a97ae003aeb7998bbc9e5..1bc9c86cadd7786bf98081c4b951cc4e37afd1f1 100644 (file)
@@ -1,6 +1,6 @@
 Name:       phonenumber-utils
 Summary:    Phone Number Utilities
-Version:    0.1.6
+Version:    0.1.7
 Release:    0
 Group:      Telephony/Utilities
 License:    Apache-2.0
@@ -13,6 +13,7 @@ BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(icu-i18n)
 BuildRequires: pkgconfig(protobuf)
 BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: libphonenumber-devel
 
 %description
index 2e72dc5fee528fe4f19a026db5f4f3d55a7187d9..960793d355ea767f84aeda11d571c39365e59a2a 100644 (file)
--- a/src/phn.c
+++ b/src/phn.c
@@ -30,8 +30,8 @@ API int phone_number_get_location_from_number(const char *number,
                phone_number_region_e region, phone_number_lang_e lang, char **location)
 {
        int ret;
-       const char *region_str = NULL;
-       const char *lang_str = NULL;
+       char *region_str = NULL;
+       char *lang_str = NULL;
 
        RETVM_IF(NULL == number || '\0' == *number, PHONE_NUMBER_ERROR_INVALID_PARAMETER,
                        "Invalid parameter (number is NULL)");
@@ -42,35 +42,56 @@ API int phone_number_get_location_from_number(const char *number,
        RETVM_IF(NULL == location, PHONE_NUMBER_ERROR_INVALID_PARAMETER,
                        "Invalid parameter (location is NULL)");
 
-       region_str = phn_region_data_get_region_str(region);
-       RETVM_IF(NULL == region_str, PHONE_NUMBER_ERROR_NOT_SUPPORTED, "phn_region_info not found(%d)", region);
+       ret = phn_region_data_get_region_str(region, &region_str);
+       if (PHONE_NUMBER_ERROR_NONE != ret) {
+               ERR("phn_region_data_get_region_str() Fail(%d)", ret);
+               return ret;
+       }
 
-       lang_str = phn_region_data_get_lang_str(lang);
-       RETVM_IF(NULL == lang_str, PHONE_NUMBER_ERROR_NOT_SUPPORTED, "phn_lang_info not found(%d)", lang);
+       ret = phn_region_data_get_lang_str(lang, &lang_str);
+       if (PHONE_NUMBER_ERROR_NONE != ret) {
+               ERR("phn_region_data_get_lang_str() Fail(%d)", ret);
+               free(region_str);
+               return ret;
+       }
 
        char *location_file = NULL;
        ret = phn_location_find_extra_data(region_str, &location_file);
        if (PHONE_NUMBER_ERROR_NONE == ret && location_file) {
-               ret = phn_location_get_location_from_extra_data(location_file, number, region, lang, location);
+               ret = phn_location_get_location_from_extra_data(location_file, number,
+                               region_str, lang_str, location);
                free(location_file);
-               if (PHONE_NUMBER_ERROR_NONE == ret && *location)
+               if (PHONE_NUMBER_ERROR_NONE == ret && *location) {
+                       free(region_str);
+                       free(lang_str);
                        return PHONE_NUMBER_ERROR_NONE;
+               }
        }
 
        bool exist = phn_region_data_find_match_info(region, lang);
-       if (!exist)
-               lang_str = PHN_REGION_DEFAULT_LANG;
+       if (false == exist) {
+               INFO("Language not matched with Region. Set to defualt language.");
+               free(lang_str);
+               lang_str = strdup(PHN_REGION_DEFAULT_LANG);
+       }
 
        ret = phn_get_location_from_number(number, region_str, lang_str, location);
-       RETVM_IF(PHONE_NUMBER_ERROR_NONE != ret, ret, "phn_get_location_from_number() Fail(%d)", ret);
+       if (PHONE_NUMBER_ERROR_NONE != ret) {
+               ERR("phn_get_location_from_number() Fail(%d)", ret);
+               free(region_str);
+               free(lang_str);
+               return ret;
+       }
 
+       free(region_str);
+       free(lang_str);
        return PHONE_NUMBER_ERROR_NONE;
 }
 
 API int phone_number_get_formatted_number(const char *number, phone_number_region_e region, char **formatted_number)
 {
        int ret;
-       const char *region_str = NULL;
+       char *region_str = NULL;
 
        RETVM_IF(NULL == number || '\0' == *number, PHONE_NUMBER_ERROR_INVALID_PARAMETER,
                        "Invalid parameter (number is NULL)");
@@ -78,12 +99,20 @@ API int phone_number_get_formatted_number(const char *number, phone_number_regio
                        "Invalid parameter (region:%d)", region);
        RETVM_IF(NULL == formatted_number, PHONE_NUMBER_ERROR_INVALID_PARAMETER, "Invalid parameter (formatted_number is NULL)");
 
-       region_str = phn_region_data_get_region_str(region);
-       RETVM_IF(NULL == region_str, PHONE_NUMBER_ERROR_NOT_SUPPORTED, "phn_region_info not found(%d)", region);
+       ret = phn_region_data_get_region_str(region, &region_str);
+       if (PHONE_NUMBER_ERROR_NONE != ret) {
+               ERR("phn_region_data_get_region_str() Fail(%d)", ret);
+               return ret;
+       }
 
        ret = phn_get_formatted_number(number, region_str, formatted_number);
-       RETVM_IF(PHONE_NUMBER_ERROR_NONE != ret, ret, "phn_get_formatted_number() Fail(%d)", ret);
+       if (PHONE_NUMBER_ERROR_NONE != ret) {
+               ERR("phn_get_formatted_number() Fail(%d)", ret);
+               free(region_str);
+               return ret;
+       }
 
+       free(region_str);
        return PHONE_NUMBER_ERROR_NONE;
 }
 
index 10d0b6c1779aada30d6346de95d2d39b8cfcc24c..d550140bd2b2955a68d102e4a0f6defa40d22e82 100644 (file)
@@ -22,6 +22,7 @@
 #include "phone_number_errors.h"
 
 #define PHN_STR_SHORT_LEN 1024
+#define STRING_EQUAL 0
 
 #define LOG_TAG "PHONE_NUMBER_UTILS"
 #include <dlog.h>
index 0e8f6b1ec62cad0f9bdfa0e012174eebe7384dde..aea8c54cf26c847c8f064f1ef2b5bea64ca3db62 100644 (file)
 #include "phn_region_data.h"
 #include "phn_location.h"
 
-#define PHN_PATH_MAX_LEN 1024
-#define PHN_COPY_SIZE_MAX 4096
-
 #define PHN_LOCATION_DIR "/opt/usr/data/phonenumber-utils"
-#define PHN_LOCATION_DOWNLOAD_DIR "/opt/usr/data/phonenumber-utils/downloads"
 #define PHN_LOCATION_FILE_PREFIX "location"
-#define PHN_LOCATION_LANG_INDEX_MAX 3
-#define PHN_LOCATION_FILE_MARK 0xfefe0000
 
 #define PHN_LOCATION_CHINA_MOBILE_SUFFIX_OFFSET 10000
 #define PHN_LOCATION_CHINA_MOBILE_PREFIX_LEN 3
@@ -58,7 +52,7 @@ struct phn_location_header {
        int mobile_prefix_len;
 };
 
-int phn_location_find_extra_data(const char *region_str, char **p_location_file)
+int phn_location_find_extra_data(char *region_str, char **p_location_file)
 {
        DIR *dirp = NULL;
        struct dirent **dir_list;
@@ -80,7 +74,7 @@ int phn_location_find_extra_data(const char *region_str, char **p_location_file)
                while (idx != count) {
                        const char *file_name = dir_list[idx]->d_name;
                        if (0 == strncmp(file_name, location_prefix, strlen(location_prefix))) {
-                               location_file = strdup(file_name);
+                               location_file = g_strdup(file_name);
                                break;
                        }
                        idx++;
@@ -97,7 +91,7 @@ int phn_location_find_extra_data(const char *region_str, char **p_location_file)
 }
 
 int phn_location_get_location_from_extra_data(const char *file, const char *number,
-               phone_number_region_e region, phone_number_lang_e lang, char **p_location)
+               char *region_str, char *lang_str, char **p_location)
 {
        int ret = 0;
        int city_str_len = 0;
@@ -110,30 +104,29 @@ int phn_location_get_location_from_extra_data(const char *file, const char *numb
        char file_path[PHN_STR_SHORT_LEN] = {0};
 
        /* support region - CN, support lang - zh,en,ko */
-       RETVM_IF(region != PHONE_NUMBER_REGION_CHINA, PHONE_NUMBER_ERROR_NOT_SUPPORTED,
-                       "Not supported region(%d)", region);
+       RETV_IF(NULL == region_str, PHONE_NUMBER_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == lang_str, PHONE_NUMBER_ERROR_INVALID_PARAMETER);
+
+       while (real_number && real_number[0] == '0')
+               real_number++;
+       RETVM_IF(NULL == real_number, PHONE_NUMBER_ERROR_INVALID_PARAMETER, "number=%s",
+                       number);
+
+       char lang_region[PHN_STR_SHORT_LEN] = {0};
+       snprintf(lang_region, sizeof(lang_region), "%s_%s", lang_str, region_str);
 
        int lang_index = 0;
-       switch (lang) {
-       case PHONE_NUMBER_LANG_CHINESE:
+       if (STRING_EQUAL == strcmp(lang_region, PHN_LOCATION_SUPPORT_ZH_CN)) {
                lang_index = 0;
-               break;
-       case PHONE_NUMBER_LANG_ENGLISH:
+       } else if (STRING_EQUAL == strcmp(lang_region, PHN_LOCATION_SUPPORT_EN_CN)) {
                lang_index = 1;
-               break;
-       case PHONE_NUMBER_LANG_KOREAN:
+       } else if (STRING_EQUAL == strcmp(lang_region, PHN_LOCATION_SUPPORT_KO_CN)) {
                lang_index = 2;
-               break;
-       default:
-               ERR("Not supported lang(%d)", lang);
+       } else {
+               ERR("Not supported(%s)", lang_region);
                return PHONE_NUMBER_ERROR_NOT_SUPPORTED;
        }
 
-       while (real_number && real_number[0] == '0')
-               real_number++;
-       RETVM_IF(NULL == real_number, PHONE_NUMBER_ERROR_INVALID_PARAMETER, "number=%s",
-                       number);
-
        snprintf(file_path, sizeof(file_path), "%s/%s", PHN_LOCATION_DIR, file);
 
        int fd = open(file_path, O_RDONLY);
@@ -281,11 +274,7 @@ int phn_location_get_location_from_extra_data(const char *file, const char *numb
                }
        }
 
-       if (region != PHONE_NUMBER_REGION_CHINA) {
-               ERR("Invalid region(%d)", region);
-               close(fd);
-               return PHONE_NUMBER_ERROR_NO_DATA;
-       } else if (strlen(number) < PHN_LOCATION_CHINA_MOBILE_NUMBER_MIN_LEN) {
+       if (strlen(number) < PHN_LOCATION_CHINA_MOBILE_NUMBER_MIN_LEN) {
                ERR("Invalid number(%s)", number);
                close(fd);
                return PHONE_NUMBER_ERROR_INVALID_PARAMETER;
index 1a7ae2b5d7b2c788c3c4b9eba345a1bd9a51edf0..bf7b18e368912800e79e32c0e2a2eb849b3e7429 100644 (file)
 
 #include "phone_number_types.h"
 
-int phn_location_find_extra_data(const char *region_str, char **p_location_file);
+#define PHN_LOCATION_SUPPORT_ZH_CN "zh_CN"
+#define PHN_LOCATION_SUPPORT_EN_CN "en_CN"
+#define PHN_LOCATION_SUPPORT_KO_CN "ko_CN"
+
+int phn_location_find_extra_data(char *region_str, char **p_location_file);
 int phn_location_get_location_from_extra_data(const char *file, const char *number,
-               phone_number_region_e region, phone_number_lang_e lang, char **p_location);
+               char *region_str, char *lang_str, char **p_location);
 
 #endif /* __PHN_LOCATION_H__ */
index 34fd94d385256a46e6a11752e9f29a155ee8fc60..d2c5898aed33d566e232df4edb5e2798b15fdf79 100644 (file)
  * limitations under the License.
  *
  */
+#include <stdlib.h>
+#include <glib.h>
+#include <system_settings.h>
+
 #include "phn_common.h"
 #include "phn_region_data.h"
 
@@ -108,6 +112,7 @@ const struct phn_match_info phn_match_info_table[] = {
        {PHONE_NUMBER_REGION_TURKEY, PHONE_NUMBER_LANG_TURKISH},
        {PHONE_NUMBER_REGION_SAUDI_ARABIA, PHONE_NUMBER_LANG_ARABIC},
        {PHONE_NUMBER_REGION_ISLAMIC_REPUBLIC_OF_IRAN, PHONE_NUMBER_LANG_PERSIAN},
+       {PHONE_NUMBER_REGION_SYSTEM, PHONE_NUMBER_LANG_SYSTEM},
 };
 
 const struct phn_lang_info phn_lang_info_table[] = {
@@ -278,25 +283,56 @@ const struct phn_region_info phn_region_info_table[] = {
        {"ZW", PHONE_NUMBER_REGION_ZIMBABWE},
 };
 
-const char* phn_region_data_get_region_str(phone_number_region_e region)
+int phn_region_data_get_region_str(phone_number_region_e region, char **region_str)
 {
-       int i;
+       int ret, i;
+
+       if (PHONE_NUMBER_REGION_SYSTEM == region) {
+               char *str = NULL;
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, &str);
+               if (str)
+                       *region_str = g_strdup(strchr(str, '_') + 1);
+               free(str);
+               if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
+                       ERR("system_settings_get_value_string() Fail(%d)", ret);
+                       return PHONE_NUMBER_ERROR_NOT_SUPPORTED;
+               }
+               return PHONE_NUMBER_ERROR_NONE;
+       }
 
        for (i = 0; i < sizeof(phn_region_info_table)/sizeof(struct phn_region_info); i++) {
-               if (phn_region_info_table[i].region == region)
-                       return phn_region_info_table[i].region_str;
+               if (phn_region_info_table[i].region == region) {
+                       *region_str = g_strdup(phn_region_info_table[i].region_str);
+                       return PHONE_NUMBER_ERROR_NONE;
+               }
        }
-       return NULL;
+       return PHONE_NUMBER_ERROR_NOT_SUPPORTED;
 }
 
-const char* phn_region_data_get_lang_str(phone_number_lang_e lang)
+int phn_region_data_get_lang_str(phone_number_lang_e lang, char **lang_str)
 {
-       int i;
+       int ret, i;
+
+       if (PHONE_NUMBER_LANG_SYSTEM == lang) {
+               char *str = NULL;
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &str);
+               if (str)
+                       *lang_str = g_strdup(strtok(str, "_"));
+               free(str);
+               if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
+                       ERR("system_settings_get_value_string() Fail(%d)", ret);
+                       return PHONE_NUMBER_ERROR_NOT_SUPPORTED;
+               }
+               return PHONE_NUMBER_ERROR_NONE;
+       }
+
        for (i = 0; i < sizeof(phn_lang_info_table)/sizeof(struct phn_lang_info); i++) {
-               if (phn_lang_info_table[i].lang == lang)
-                       return phn_lang_info_table[i].lang_str;
+               if (phn_lang_info_table[i].lang == lang) {
+                       *lang_str = g_strdup(phn_lang_info_table[i].lang_str);
+                       return PHONE_NUMBER_ERROR_NONE;
+               }
        }
-       return NULL;
+       return PHONE_NUMBER_ERROR_NOT_SUPPORTED;
 }
 
 bool phn_region_data_find_match_info(phone_number_region_e region,
index ef5da04130202a52c4d39903ab172a56d79371fd..3c674df55de3d725327c84e2efb1f014f2cc4d7e 100644 (file)
@@ -23,8 +23,8 @@
 
 #define PHN_REGION_DEFAULT_LANG "en"
 
-const char* phn_region_data_get_region_str(phone_number_region_e region);
-const char* phn_region_data_get_lang_str(phone_number_lang_e lang);
+int phn_region_data_get_region_str(phone_number_region_e region, char **region_str);
+int phn_region_data_get_lang_str(phone_number_lang_e lang, char **lang_str);
 bool phn_region_data_find_match_info(phone_number_region_e region,
                phone_number_lang_e lang);