TizenRefApp-8363 [App Shortcuts Widget] Replace unum with i18n API 56/124756/3
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Wed, 12 Apr 2017 08:56:19 +0000 (11:56 +0300)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Wed, 12 Apr 2017 09:55:48 +0000 (12:55 +0300)
Change-Id: Ic46d627a40c4554e696e0f9605b4aae0c6850003

apptray-widget/CMakeLists.txt
apptray-widget/inc/apptray_widget_common_defines.h
apptray-widget/src/apptray_widget.c
apptray-widget/src/apptray_widget_utils.c
packaging/org.tizen.apptray-widget.spec

index 7d8978b774ef7638646aa6e2ec450004743ad01b..81c68ad0e86afa0882fd41bd70e9525f85469cf1 100755 (executable)
@@ -38,6 +38,7 @@ pkg_check_modules(pkgs REQUIRED
        capi-system-system-settings
        capi-appfw-widget-application
        capi-appfw-preference
+       capi-base-utils-i18n
        badge
        dlog
        ecore
index bbf957d63fcf501fa474a9e9353d5294506880fb..1bbf353d20d9b909336781127783a9d5a71f5023 100644 (file)
@@ -36,8 +36,9 @@
 #define MAX_BADGE_COUNT 999
 #define WIDGET_SLOTS_MAX_COUNT 4
 
+#define BUFF_SMALL_SIZE 64
 #define BUFF_GIANT_SIZE 1024
-#define BUFF_SMALL_SIZE 128
+#define BUFF_MIDDLE_SIZE 128
 
 #define APPTRAY_WIDGET_APP_DOMAIN "apptray-widget-app"
 
index 45f8210a6dbcdcb7e1d494094b8c71988a7b39a1..b750c2de679831ab01dced2917913ff91693462d 100755 (executable)
@@ -228,7 +228,6 @@ static int _get_app_badge_count(const char *appid)
 static void _update_slot_ly_badge(struct slot_info *item)
 {
        _ENTER;
-       char *str = NULL;
        char badge_signal[16];
 
        ret_if(!item);
@@ -237,8 +236,8 @@ static void _update_slot_ly_badge(struct slot_info *item)
                item->badge_count = MAX_BADGE_COUNT;
        }
 
-       str = apptray_wgt_utils_get_count_str_from_icu(item->badge_count);
-       elm_object_part_text_set(item->eo, "badge_txt", str);
+       elm_object_part_text_set(item->eo, "badge_txt",
+                       apptray_wgt_utils_get_count_str_from_icu(item->badge_count));
 
        if (item->badge_count <= 0) {
                snprintf(badge_signal, sizeof(badge_signal), "badge,off");
@@ -250,8 +249,6 @@ static void _update_slot_ly_badge(struct slot_info *item)
                snprintf(badge_signal, sizeof(badge_signal), "badge,on,3");
        }
        elm_object_signal_emit(item->eo, badge_signal, "slot");
-
-       free(str);
 }
 
 static void _badge_changed_cb(unsigned int action, const char *appid, unsigned int count, void *data)
@@ -722,7 +719,7 @@ static void _destroy_add_apps_layout(struct info *item)
 
 static void _set_main_layout_slot_count(struct info *item, int count)
 {
-       char tmp[BUFF_SMALL_SIZE] = { 0 };
+       char tmp[BUFF_MIDDLE_SIZE] = { 0 };
        snprintf(tmp, sizeof(tmp), "%d_slots", count);
        elm_object_signal_emit(item->layout, tmp, "*");
 }
index 0fffbac46281d1ffcf6633a5be7679e2079093fa..a733d6d93fbce627d5275ffa5cb5692750253016 100755 (executable)
@@ -21,8 +21,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <system_settings.h>
-#include <unicode/unum.h>
-#include <unicode/ustring.h>
+#include <utils_i18n.h>
 
 #include "apptray_widget_log.h"
 #include "apptray_widget_common_defines.h"
@@ -78,35 +77,45 @@ const char *apptray_wgt_utils_get_default_app_icon_path()
        return res_path;
 }
 
-char *apptray_wgt_utils_get_count_str_from_icu(int count)
+char *apptray_wgt_utils_get_count_str_from_icu(int num)
 {
-       char *p = NULL;
+       static char buff[BUFF_SMALL_SIZE] = { 0 };
        char *locale = NULL;
-       char res[LOCALE_LEN] = { 0 };
+       i18n_unumber_format_h num_format = NULL;
+       i18n_uchar u_buff[BUFF_SMALL_SIZE] = { 0 };
+       i18n_error_code_e status = I18N_ERROR_NONE;
+       int32_t len = 0;
+
+       int res = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
+       if (res != SYSTEM_SETTINGS_ERROR_NONE) {
+               _E("Failed to get the locale . res[%d]", res);
+               goto fail;
+       }
 
-       UErrorCode status = U_ZERO_ERROR;
-       UNumberFormat *num_fmt = NULL;;
-       UChar result[LOCALE_LEN] = { 0 };
+       if (!locale) {
+               _E("Local is NULL");
+               goto fail;
+       }
 
-       uint32_t number = count;
-       int32_t len = (int32_t) (sizeof(result) / sizeof((result)[0]));
+       res = i18n_unumber_create(I18N_UNUMBER_DEFAULT, NULL, -1, locale, NULL, &num_format);
+       if (res != I18N_ERROR_NONE) {
+               _E("Failed to create unumber format. res[%d]", res);
+               goto fail;
+       }
 
-       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
-       retv_if(!locale, NULL);
+       len = (int32_t) (sizeof(u_buff) / sizeof(u_buff[0]));
+       i18n_unumber_format(num_format, num, u_buff, len, NULL, &status);
+       i18n_ustring_copy_au(buff, u_buff);
+       i18n_unumber_destroy(num_format);
 
-       if (locale[0] != '\0') {
-               p = strstr(locale, ".UTF-8");
-               if (p) {
-                       *p = 0;
-               }
-       }
+       free(locale);
+
+       return buff;
 
-       num_fmt = unum_open(UNUM_DEFAULT, NULL, -1, locale, NULL, &status);
-       unum_format(num_fmt, number, result, len, NULL, &status);
-       u_austrcpy(res, result);
-       unum_close(num_fmt);
+fail:
+       snprintf(buff, sizeof(buff), "%d", num);
 
        free(locale);
 
-       return strdup(res);
+       return buff;
 }
index 124a5610277a13ccfb1bbaf7375f3a88b8cd798f..5297da27a70e20b0a9da051c9e8d76e836279e5f 100755 (executable)
@@ -20,6 +20,7 @@ BuildRequires: pkgconfig(capi-appfw-package-manager)
 BuildRequires: pkgconfig(capi-appfw-app-manager)
 BuildRequires: pkgconfig(capi-appfw-preference)
 BuildRequires: pkgconfig(capi-system-system-settings)
+BuildRequires: pkgconfig(capi-base-utils-i18n)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(eet)
 BuildRequires: pkgconfig(eina)