From 0bd6b90e5704ee100e2342110ac8df761924571c Mon Sep 17 00:00:00 2001 From: Lukasz Stanislawski Date: Sun, 31 Jan 2016 10:47:53 +0100 Subject: [PATCH] clock: rewrite unicode using i18n API. Change-Id: Ie096342f2de5a485ede835c326e286b56f58bec5 Signed-off-by: Lukasz Stanislawski --- inc/util.h | 2 + src/modules/clock/clock.c | 317 ++++++++++++++++++++++++---------------------- 2 files changed, 168 insertions(+), 151 deletions(-) diff --git a/inc/util.h b/inc/util.h index bb69022..a359e4f 100644 --- a/inc/util.h +++ b/inc/util.h @@ -72,4 +72,6 @@ extern void util_icon_access_register(icon_s *icon); extern void util_icon_access_unregister(icon_s *icon); #endif /* _SUPPORT_SCREEN_READER */ +#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) + #endif /* __INDICATOR_UTIL_H__ */ diff --git a/src/modules/clock/clock.c b/src/modules/clock/clock.c index 6f4ddd2..649cf64 100644 --- a/src/modules/clock/clock.c +++ b/src/modules/clock/clock.c @@ -22,9 +22,7 @@ #include #include //#include -#include -#include -#include +#include #include #include "common.h" @@ -69,7 +67,7 @@ static int apm_length = 0; static int apm_position = 0; extern Ecore_Timer *clock_timer; -static UDateTimePatternGenerator *_last_generator = NULL; +static i18n_udatepg_h _last_generator; static char *_last_locale = NULL; static int battery_charging = 0; @@ -115,14 +113,14 @@ void cal_delete_last_generator(void) _last_locale = NULL; } if (_last_generator) { - udatpg_close(_last_generator); + i18n_udatepg_destroy(_last_generator); _last_generator = NULL; } } -static UDateTimePatternGenerator *__cal_get_pattern_generator(const char *locale, UErrorCode *status) +static i18n_udatepg_h __cal_get_pattern_generator(const char *locale, int *status) { if (!_last_generator || !_last_locale || strcmp(locale, _last_locale)) { @@ -130,8 +128,11 @@ static UDateTimePatternGenerator *__cal_get_pattern_generator(const char *locale _last_locale = strdup(locale); - _last_generator = udatpg_open(locale, status); - + int ret = i18n_udatepg_create(locale, &_last_generator); + if (ret != I18N_ERROR_NONE) { + _E("i18n_udatepg_create failed %d", ret); + _last_generator = NULL; + } } return _last_generator; } @@ -267,6 +268,7 @@ static void _clock_format_changed_cb(keynode_t *node, void *data) { struct appdata *ad = NULL; int mode_24 = 0; + i18n_timezone_h timezone; ret_if(!data); @@ -296,11 +298,26 @@ static void _clock_format_changed_cb(keynode_t *node, void *data) } } - char *timezone = util_get_timezone_str(); - ICU_set_timezone(timezone); + char *timezone_str = util_get_timezone_str(); + + int ret = i18n_timezone_create(&timezone, timezone_str); + if (ret != I18N_ERROR_NONE) { + _E("Unable to create timzone handle for %s: %d", timezone_str, ret); + free(timezone_str); + return; + } + + ret = i18n_timezone_set_default(timezone); + if (ret != I18N_ERROR_NONE) { + _E("Unable to set default timzone: %d", ret); + i18n_timezone_destroy(timezone); + free(timezone_str); + return; + } + indicator_clock_changed_cb(data); - if(timezone!=NULL) - free(timezone); + i18n_timezone_destroy(timezone); + free(timezone_str); } @@ -572,31 +589,25 @@ void indicator_get_apm_by_region(char* output,void *data) retif(data == NULL, , "Data parameter is NULL"); retif(output == NULL, , "output parameter is NULL"); + i18n_uchar u_custom_skeleton[CLOCK_STR_LEN] = { 0, }; + i18n_uchar u_timezone[64] = {0,}; + i18n_uchar u_best_pattern[CLOCK_STR_LEN] = { 0, }; + i18n_uchar u_formatted[CLOCK_STR_LEN] = { 0, }; - UChar customSkeleton[CLOCK_STR_LEN] = { 0, }; - UChar u_timezone[64] = {0,}; - - UErrorCode status = U_ZERO_ERROR; - UDateFormat *formatter = NULL; + i18n_udate_format_h formatter; + int32_t best_pattern_len, formatted_len; - UChar bestPattern[CLOCK_STR_LEN] = { 0, }; - UChar formatted[CLOCK_STR_LEN] = { 0, }; + char s_best_pattern[CLOCK_STR_LEN] = { 0, }; + char s_formatted[CLOCK_STR_LEN] = { 0, }; - char bestPatternString[CLOCK_STR_LEN] = { 0, }; - char formattedString[CLOCK_STR_LEN] = { 0, }; - - UDateTimePatternGenerator *pattern_generator = NULL; - - char *time_skeleton = "hhmm"; + int status = 0; - char* timezone_id = NULL; - timezone_id = util_get_timezone_str(); + i18n_udatepg_h pattern_generator = NULL; char *locale = vconf_get_str(VCONFKEY_REGIONFORMAT); if(locale == NULL) { ERR("[Error] get value of fail."); - free(timezone_id); return; } @@ -607,62 +618,73 @@ void indicator_get_apm_by_region(char* output,void *data) if (p) { *p = 0; } + free(locale); - u_uastrncpy(customSkeleton, time_skeleton, strlen(time_skeleton)); + i18n_ustring_copy_ua_n(u_custom_skeleton, "hhmm", ARRAY_SIZE(u_custom_skeleton)); pattern_generator = __cal_get_pattern_generator (locale_tmp, &status); if (pattern_generator == NULL) { return ; } - int32_t bestPatternCapacity = (int32_t) (sizeof(bestPattern) / sizeof((bestPattern)[0])); - (void)udatpg_getBestPattern(pattern_generator, customSkeleton, - u_strlen(customSkeleton), bestPattern, - bestPatternCapacity, &status); + int ret = i18n_udatepg_get_best_pattern(pattern_generator, u_custom_skeleton, i18n_ustring_get_length(u_custom_skeleton), + u_best_pattern, (int32_t)ARRAY_SIZE(u_best_pattern), &best_pattern_len); + if (ret != I18N_ERROR_NONE) { + _E("i18n_udatepg_get_best_pattern failed: %d", ret); + i18n_udatepg_destroy(pattern_generator); + return; + } + i18n_udatepg_destroy(pattern_generator); - u_austrcpy(bestPatternString, bestPattern); - u_uastrcpy(bestPattern,"a"); + i18n_ustring_copy_au(s_best_pattern, u_best_pattern); + i18n_ustring_copy_ua(u_best_pattern, "a"); + char *timezone_id = util_get_timezone_str(); DBG("TimeZone is %s", timezone_id); - if(bestPatternString[0] == 'a') - { + if (s_best_pattern[0] == 'a') { apm_position = 0; } - else - { + else { apm_position = 1; } - UDate date = ucal_getNow(); - if(timezone_id) - { - u_uastrncpy(u_timezone, timezone_id, sizeof(u_timezone)); - formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale_tmp, u_timezone, -1, bestPattern, -1, &status); + i18n_udate date; + ret = i18n_ucalendar_get_now(&date); + if (ret != I18N_ERROR_NONE) { + ERR("i18n_ucalendar_get_now failed: %d", ret); + free(timezone_id); + return; } - else - { - formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale_tmp, NULL, -1, bestPattern, -1, &status); + if (timezone_id) { + i18n_ustring_copy_ua_n(u_timezone, timezone_id, ARRAY_SIZE(u_timezone)); } - if (formatter == NULL) { - return ; + + ret = i18n_udate_create(I18N_UDATE_PATTERN, I18N_UDATE_PATTERN, locale_tmp, timezone_id ? u_timezone : NULL, -1, + u_best_pattern, -1, &formatter); + if (ret != I18N_ERROR_NONE) { + free(timezone_id); + return; } - int32_t formattedCapacity = (int32_t) (sizeof(formatted) / sizeof((formatted)[0])); - (void)udat_format(formatter, date, formatted, formattedCapacity, NULL, &status); - u_austrcpy(formattedString, formatted); + free(timezone_id); + + ret = i18n_udate_format_date(formatter, date, u_formatted, ARRAY_SIZE(s_formatted), NULL, &formatted_len); + if (ret != I18N_ERROR_NONE) { + i18n_udate_destroy(formatter); + return; + } - apm_length = u_strlen(formatted); + i18n_udate_destroy(formatter); - udat_close(formatter); + i18n_ustring_copy_au(s_formatted, u_formatted); + apm_length = i18n_ustring_get_length(u_formatted); - if(strlen(formattedString)