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"
24 #include "sst_interface.h"
26 int sst_locale_get_country(sst_interface *iface, char **value)
29 if (sst_vconf_get_str_ally(iface->vconf_key, &locale)) {
30 ERR("sst_vconf_get_str_ally(%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, const char *country)
57 const char *codeset = "UTF-8";
60 snprintf(locale, sizeof(locale), "%s.%s", country, codeset);
62 if (vconf_set_str(iface->vconf_key, locale)) {
63 ERR("vconf_set_str(%s) Fail", iface->vconf_key);
64 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
67 return SYSTEM_SETTINGS_ERROR_NONE;
70 int sst_locale_get_language(sst_interface *iface, char **value)
72 //It is same data with sst_locale_get_country()
73 int ret = sst_locale_get_country(iface, value);
74 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
75 ERR("sst_locale_get_country() Fail(%d)", ret);
79 return SYSTEM_SETTINGS_ERROR_NONE;
82 int sst_locale_set_language(sst_interface *iface, const char *value)
84 //It is same data with sst_locale_set_country()
85 int ret = sst_locale_set_country(iface, value);
86 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
87 ERR("sst_locale_set_country() Fail(%d)", ret);
91 return SYSTEM_SETTINGS_ERROR_NONE;
94 int sst_locale_get_timeformat_24hour(sst_interface *iface, bool *value)
98 if (vconf_get_int(iface->vconf_key, &time_fmt)) {
99 ERR("vconf_get_int(%s) Fail", iface->vconf_key);
100 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
104 if (time_fmt == VCONFKEY_TIME_FORMAT_12)
106 else if (time_fmt == VCONFKEY_TIME_FORMAT_24)
111 return SYSTEM_SETTINGS_ERROR_NONE;
114 int sst_locale_set_timeformat_24hour(sst_interface *iface, bool is_24hour)
119 vconf_val = VCONFKEY_TIME_FORMAT_24;
121 vconf_val = VCONFKEY_TIME_FORMAT_12;
123 if (vconf_set_int(iface->vconf_key, vconf_val)) {
124 ERR("vconf_set_int(%s) Fail", iface->vconf_key);
125 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
128 return SYSTEM_SETTINGS_ERROR_NONE;
131 int sst_locale_get_timezone(sst_interface *iface, char **value)
133 char tzpath[PATH_MAX];
134 ssize_t len = readlink(SETTING_TZONE_SYMLINK_PATH, tzpath, sizeof(tzpath) - 1);
136 ERR("readlink(%s) Fail(%d)", SETTING_TZONE_SYMLINK_PATH, errno);
137 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
141 // for including last '/', it used sizeof instead of strlen
142 int start = sizeof(SETTING_TIME_ZONEINFO_PATH);
144 *value = strdup(&tzpath[start]);
145 return SYSTEM_SETTINGS_ERROR_NONE;
148 int sst_locale_set_timezone(sst_interface *iface, const char *timezone)
150 char tzpath[PATH_MAX];
151 snprintf(tzpath, sizeof(tzpath), SETTING_TIME_ZONEINFO_PATH"/%s", timezone);
153 if (false == sst_misc_file_exists(tzpath)) {
154 ERR("sst_misc_file_exists(%s) Fail", tzpath);
155 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
158 int ret = alarmmgr_set_timezone(tzpath);
159 if (ALARMMGR_RESULT_SUCCESS != ret)
160 ERR("alarmmgr_set_timezone(%s) Fail", tzpath);
162 if (vconf_set_str(iface->vconf_key, timezone)) {
163 ERR("vconf_set_str(%s) Fail", iface->vconf_key);
164 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
167 return SYSTEM_SETTINGS_ERROR_NONE;
170 //TODO : checking this function is being used or not.
171 int sst_time_get_changed(sst_interface *iface, int *value)
175 cur_tick = time(NULL);
178 return SYSTEM_SETTINGS_ERROR_NONE;