2 // Tizen Web Device API
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 <PlatformException.h>
20 #include <system_settings.h>
22 #include "SystemInfoLocale.h"
23 #include "SystemInfoUtil.h"
26 namespace SystemInfo {
28 SystemInfoLocale::SystemInfoLocale()
32 m_language = fetchLanguage();
33 m_country = fetchCountry();
36 SystemInfoLocale::~SystemInfoLocale()
41 std::string SystemInfoLocale::getLanguage() const
46 std::string SystemInfoLocale::getCountry() const
51 std::string SystemInfoLocale::fetchLanguage()
55 char* language = NULL;
56 std::string str_language = "";
57 std::string log_msg = "";
60 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &language);
61 if (ret == SYSTEM_SETTINGS_ERROR_NONE) {
62 if (NULL != language) {
63 LOGD("language : %s", language);
64 str_language = language;
68 log_msg = "Failed to get language info";
69 LOGE("%s, %d, %s", log_msg.c_str(), ret,
70 SystemInfoUtil::getSettingErrorMessage(ret).c_str());
71 SystemInfoUtil::throwSettingException(ret, log_msg);
76 std::string SystemInfoLocale::fetchCountry()
81 std::string str_country = "";
82 std::string log_msg = "";
85 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, &country);
86 if (ret == SYSTEM_SETTINGS_ERROR_NONE) {
87 if (NULL != country) {
88 LOGD("country : %s", country);
90 token = strtok(country, ".");
97 log_msg = "Failed to get country info";
98 LOGE("%s, %d, %s", log_msg.c_str(), ret,
99 SystemInfoUtil::getSettingErrorMessage(ret).c_str());
100 SystemInfoUtil::throwSettingException(ret, log_msg);