#include <app.h>
#include <Elementary.h>
#include <widget_service.h>
+#include <utils_i18n.h>
#include "add_widget_viewer/add_widget_viewer.h"
#include "add_widget_viewer/add_widget_data.h"
.index = NULL
};
-static const char *IDX_STR = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
static void __add_widget_viewer_win_del_cb(void *data, Evas_Object* obj, void* event_info);
static Elm_Theme *__add_widget_viewer_create_theme(void);
static Evas_Object *__add_widget_viewer_create_conformant(void);
static Evas_Object *__add_widget_viewer_create_content(Evas_Object *naviframe, Evas_Object *genlist);
static Evas_Object *__add_widget_viewer_create_index(Evas_Object *layout);
-static void __add_widget_viewer_index_changed_cb(void *data, Evas_Object *obj, void *event_info);
static void __add_widget_viewer_index_cb(void *data, Evas_Object *obj, void *event_info);
static int __add_widget_viewer_compare_index_cb(const void *data1, const void *data2);
static Evas_Object *__add_widget_viewer_create_list(Evas_Object *content);
static void __add_widget_viewer_preview_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
static Evas_Object *__add_widget_viewer_list_widget_preview_box_create(Evas_Object *main_box, add_widget_data_t *widget, add_widget_data_preview_t *preview);
static void __add_widget_viewer_item_realized_cb(void *data, Evas_Object *obj, void *event_info);
+static i18n_uchar __add_widget_viewer_get_first_char_from_hangul(const char *index);
void add_widget_viewer_win_create(void)
{
return content;
}
+static i18n_uchar __add_widget_viewer_get_first_char_from_hangul(const char *label)
+{
+ i18n_uchar first_char[64] = {0, };
+ i18n_error_code_e error;
+ i18n_uchar base = 0xAC00;
+ i18n_uchar last = 0xD79F;
+ int first_char_len;
+ int index;
+ static i18n_uchar table[] = {
+ 0x3131, 0x3131,
+ 0x3134,
+ 0x3137, 0x3137,
+ 0x3139,
+ 0x3141,
+ 0x3142, 0x3142,
+ 0x3145, 0x3145,
+ 0x3147,
+ 0x3148, 0x3148,
+ 0x314a,
+ 0x314b,
+ 0x314c,
+ 0x314d,
+ 0x314e,
+ };
+
+ i18n_ustring_from_UTF8(first_char, 64, &first_char_len, label, strlen(label), &error);
+
+ if (first_char[0] < base || first_char[0] > last) {
+ return 0;
+ }
+ index = (first_char[0] - base) / (21 * 28);
+
+ return table[index];
+}
+
static Evas_Object *__add_widget_viewer_create_index(Evas_Object *layout)
{
Evas_Object *index;
+ int i = 0;
+ int j, len;
+ char *str;
+ char buf[PATH_MAX] = { 0, };
index = elm_index_add(layout);
elm_index_autohide_disabled_set(index, EINA_TRUE);
elm_index_omit_enabled_set(index, EINA_TRUE);
- elm_index_item_append(index, "#", __add_widget_viewer_index_cb, IDX_STR);
- int i;
- for (i = 1; i < strlen(IDX_STR); ++i) {
- char ch[2];
- ch[0] = IDX_STR[i];
- ch[1] = '\0';
- elm_index_item_append(index, ch, __add_widget_viewer_index_cb, (IDX_STR+i));
+ elm_index_item_append(index, "#", __add_widget_viewer_index_cb, NULL);
+
+ str = dgettext("efl-extension", "IDS_EA_BODY_ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+ len = strlen(str);
+
+ while (i < len) {
+ j = i;
+ eina_unicode_utf8_next_get(str, &i);
+ snprintf(buf, i - j + 1, "%s", str + j);
+ buf[i - j + 1] = 0;
+
+ LOGD("Create Index[%s]", buf);
+ elm_index_item_append(index, buf, __add_widget_viewer_index_cb, NULL);
}
elm_index_level_go(index, 0);
- evas_object_smart_callback_add(index, "changed", __add_widget_viewer_index_changed_cb, NULL);
+ evas_object_smart_callback_add(index, "changed", __add_widget_viewer_index_cb, str);
return index;
}
-static void __add_widget_viewer_index_changed_cb(void *data, Evas_Object *obj, void *event_info)
+static int __add_widget_viewer_compare_index_cb(const void *data1, const void *data2)
{
- char *idx_str = (char*)elm_object_item_data_get(event_info);
- Eina_List *widget_list = NULL;
- add_widget_data_t *widget = NULL;
+ add_widget_data_t *w = (add_widget_data_t *)data1;
+ i18n_uchar uchar_label[64] = {0, };
+ i18n_uchar uchar_index[64] = {0, };
+ i18n_ucollator_h collator_h = NULL;
+ i18n_error_code_e error;
+ const char *env;
+ char lang_buf[64];
+ char *index = (char *)data2;
+ int uchar_label_len = 0;
+ int uchar_index_len = 0;
- widget_list = add_widget_data_get_widget_list();
- if (!widget_list) {
- LOGE("Can not get widget list");
- return;
- }
- if(idx_str[0] == '#') {
- widget = eina_list_data_get(widget_list);
+ if (!index) {
+ LOGE("Index is NULL");
+ return -1;
}
+ env = getenv("LANG");
+ snprintf(lang_buf, strlen(env) - strlen(".UTF-8") + 1, "%s", env);
+
+ i18n_ustring_from_UTF8(uchar_index, 64, &uchar_index_len, index, strlen(index), &error);
+
+ if (!strcmp(lang_buf, "ko_KR")) {
+ i18n_uchar first_char;
- if(!widget) {
- widget = eina_list_search_unsorted(widget_list, __add_widget_viewer_compare_index_cb, idx_str);
+ first_char = __add_widget_viewer_get_first_char_from_hangul(w->label);
+ LOGD("first character: %d, index: %d", first_char, *uchar_index);
+
+ return uchar_index[0] - first_char;
}
- if (!widget) {
- LOGD("Can not find widget");
- return;
+ if (i18n_ucollator_create(lang_buf, &collator_h) != I18N_ERROR_NONE) {
+ LOGE("Failed to open ucollator");
+ return -1;
}
+ i18n_ucollator_set_strength(collator_h, I18N_UCOLLATOR_PRIMARY);
+ i18n_ustring_from_UTF8(uchar_label, 64, &uchar_label_len, w->label, uchar_index_len, &error);
+ i18n_ucollator_destroy(collator_h);
- elm_genlist_item_bring_in(widget->genlist_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
+ return uchar_index[0] - toupper(uchar_label[0]);
}
static void __add_widget_viewer_index_cb(void *data, Evas_Object *obj, void *event_info)
{
- char *idx_str = (char *)data;
- Eina_List *widget_list = NULL;
+ char *index = (char *)elm_index_item_letter_get(event_info);
add_widget_data_t *widget = NULL;
+ Eina_List *widget_list = NULL;
widget_list = add_widget_data_get_widget_list();
if (!widget_list) {
return;
}
- if(idx_str[0] == '#') {
+ if (!strcmp(index, "#")) {
widget = eina_list_data_get(widget_list);
}
- while(!widget && idx_str[0] != '\0') {
- widget = eina_list_search_unsorted(widget_list, __add_widget_viewer_compare_index_cb, idx_str);
- idx_str += 1;
- }
-
- if(!widget) {
- widget = eina_list_last_data_get(widget_list);
+ if (!widget) {
+ widget = eina_list_search_unsorted(widget_list, __add_widget_viewer_compare_index_cb, index);
}
if (!widget) {
elm_genlist_item_bring_in(widget->genlist_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
}
-static int __add_widget_viewer_compare_index_cb(const void *data1, const void *data2)
-{
- add_widget_data_t *w = (add_widget_data_t *)data1;
- char *idx_str = (char *)data2;
-
- char c1 = 0;
- char c2 = 0;
-
- c1 = tolower(idx_str[0]);
- c2 = tolower(w->label[0]);
-
- LOGD("Compare: %c == %c in %s, %s", c1, c2, idx_str, w->label);
-
- if (c1 < c2) return -1;
- if (c1 > c2) return 1;
- return 0;
-}
-
static Evas_Object *__add_widget_viewer_create_list(Evas_Object *content)
{
Elm_Genlist_Item_Class *itc_widget;