2 * Copyright (c) 2011-2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "sst_time_N_locale.h"
22 #include "sst_vconf.h"
23 #include "sst_utils.h"
24 #include "sst_interface.h"
26 int sst_locale_get_country(sst_interface *iface, void **value)
29 if (sst_vconf_get_string(iface->vconf_key, &locale)) {
30 ERR("sst_vconf_get_string(%s) Fail", iface->vconf_key);
31 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
34 // remove encoding ex) en_US.UTF-8 => en_US
37 for (i = 0; i < sizeof(country); i++) {
38 country[i] = locale[i];
39 if ('.' == country[i])
44 if (sizeof(country) <= i) {
45 ERR("Invalid locale(%s)", locale);
46 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
49 *value = strdup(country);
52 return SYSTEM_SETTINGS_ERROR_NONE;
55 int sst_locale_set_country(sst_interface *iface, void *value)
57 char *country = value;
58 const char *codeset = "UTF-8";
61 snprintf(locale, sizeof(locale), "%s.%s", country, codeset);
63 if (vconf_set_str(iface->vconf_key, locale)) {
64 ERR("vconf_set_str(%s) Fail", iface->vconf_key);
65 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
68 return SYSTEM_SETTINGS_ERROR_NONE;
71 int sst_locale_get_language(sst_interface *iface, void **value)
73 //It is same data with sst_locale_get_country()
74 int ret = sst_locale_get_country(iface, value);
75 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
76 ERR("sst_locale_get_country() Fail(%d)", ret);
80 return SYSTEM_SETTINGS_ERROR_NONE;
83 int sst_locale_set_language(sst_interface *iface, void *value)
85 //It is same data with sst_locale_set_country()
86 int ret = sst_locale_set_country(iface, value);
87 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
88 ERR("sst_locale_set_country() Fail(%d)", ret);
92 return SYSTEM_SETTINGS_ERROR_NONE;
95 int sst_locale_get_timeformat_24hour(sst_interface *iface, void **value)
99 if (vconf_get_int(iface->vconf_key, &int_val)) {
100 ERR("vconf_get_int(%s) Fail", iface->vconf_key);
101 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
104 bool ret_value = true;
105 if (int_val == VCONFKEY_TIME_FORMAT_12)
107 else if (int_val == VCONFKEY_TIME_FORMAT_24)
110 *value = (void*)ret_value;
112 return SYSTEM_SETTINGS_ERROR_NONE;
115 int sst_locale_set_timeformat_24hour(sst_interface *iface, void *value)
117 bool is_24hour = *(bool*)value;
121 vconf_val = VCONFKEY_TIME_FORMAT_24;
123 vconf_val = VCONFKEY_TIME_FORMAT_12;
125 if (vconf_set_int(iface->vconf_key, vconf_val)) {
126 ERR("vconf_set_int(%s) Fail", iface->vconf_key);
127 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
130 return SYSTEM_SETTINGS_ERROR_NONE;
133 int sst_locale_get_timezone(sst_interface *iface, void **value)
135 char tzpath[PATH_MAX];
136 ssize_t len = readlink(SETTING_TZONE_SYMLINK_PATH, tzpath, sizeof(tzpath) - 1);
138 ERR("readlink(%s) Fail(%d)", SETTING_TZONE_SYMLINK_PATH, errno);
139 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
143 // for including last '/', it used sizeof instead of strlen
144 int start = sizeof(SETTING_TIME_ZONEINFO_PATH);
146 *value = strdup(&tzpath[start]);
147 return SYSTEM_SETTINGS_ERROR_NONE;
150 int sst_locale_set_timezone(sst_interface *iface, void *value)
152 char *timezone = value;
154 char tzpath[PATH_MAX];
155 snprintf(tzpath, sizeof(tzpath), SETTING_TIME_ZONEINFO_PATH"/%s", timezone);
157 if (false == sst_utils_exist(tzpath)) {
158 ERR("sst_utils_exist(%s) Fail", tzpath);
159 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
162 int ret = alarmmgr_set_timezone(tzpath);
163 if (ALARMMGR_RESULT_SUCCESS != ret)
164 ERR("alarmmgr_set_timezone(%s) Fail", tzpath);
166 if (vconf_set_str(iface->vconf_key, timezone)) {
167 ERR("vconf_set_str(%s) Fail", iface->vconf_key);
168 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
171 return SYSTEM_SETTINGS_ERROR_NONE;