/* * Copyright 2012-2013 Samsung Electronics Co., Ltd/ * * Licensed under the Flora License, Version 1.1 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://floralicense.org/license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "smartsearch.h" #include "ps_searcher.h" #include "ps_app_interface.h" #include #include #include #include #include #include #include #include struct search_thread_data { struct appdata *ad; char *keyword; int is_search_result; }; struct search_genlist_item_info* search_add_genlist_item(int type, struct search_content_object *obj, Elm_Genlist_Item_Class *itc_style, void *data, Elm_Object_Item *parent) { struct search_genlist_item_info *item = (struct search_genlist_item_info *) calloc(1, sizeof(struct search_genlist_item_info)); if (item) { item->type = type; item->obj = obj; item->itc_style = itc_style; item->data = data; item->parent = parent; } return item; } static void ecore_exe_pipe_cb(void *data, void *buf, unsigned int size) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_pipe_data *pipe_data = *((struct search_pipe_data**)buf); struct search_content_object *obj = NULL; struct search_genlist_item_info *item = NULL; struct search_genlist_info *result_info = NULL; int cmd = 0; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(pipe_data == NULL); result_info = pipe_data->result_list; cmd = pipe_data->cmd; SEARCH_DEBUG_LOG("Pipe Command : %d ret : %d", cmd, pipe_data->search_ret); switch (cmd) { case SEARCH_PIPE_CMD_CLEAR_GENLIST: elm_genlist_clear(ad->search_gl); break; case SEARCH_PIPE_CMD_SET_LAYOUT: if (pipe_data->search_ret == SEARCH_RET_SEARCH_SUCCESS) search_layout_set_search_list(ad); else search_layout_set_search_no_result(ad); break; case SEARCH_PIPE_CMD_ADD_GENLIST_PHONE: if (result_info) { if (result_info->group) { item = result_info->group; obj = item->obj; obj->gl_result_grp = elm_genlist_item_append(ad->search_gl, item->itc_style, item->data, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); elm_genlist_item_select_mode_set(obj->gl_result_grp, ELM_OBJECT_SELECT_MODE_NONE); SEARCH_FREE(item); } if (result_info->itemlist) { GList *node = g_list_first(result_info->itemlist); while (node != NULL) { item = (struct search_genlist_item_info *)node->data; if (item) { obj = item->obj; elm_genlist_item_append(ad->search_gl, item->itc_style, item->data, obj->gl_result_grp, ELM_GENLIST_ITEM_NONE, search_gl_phone_result_sel, ad); SEARCH_FREE(item); } node = g_list_next(node); } g_list_free(result_info->itemlist); result_info->itemlist = NULL; } if (result_info->more) { item = result_info->more; obj = item->obj; elm_genlist_item_append(ad->search_gl, item->itc_style, item->data, obj->gl_result_grp, ELM_GENLIST_ITEM_NONE, search_gl_result_more_item_append_cb, ad); SEARCH_FREE(item); } SEARCH_FREE(result_info); } break; } SEARCH_FREE(pipe_data); SEARCH_FUNC_END; } static Evas_Object *__search_gl_content_get_genlist_item_type(void *data, Evas_Object *obj, const char *part) { Evas_Object *icon = NULL; int icon_size = 0; char *icon1_path = NULL; char *icon2_path = NULL; struct search_item_sel *sel_mem_info = (struct search_item_sel *)data; double scale = elm_config_scale_get(); SEARCH_RETV_IF(sel_mem_info == NULL, NULL); if (!SEARCH_STRCMP(part, "elm.icon") || !SEARCH_STRCMP(part, "elm.icon.1")) { icon1_path = sel_mem_info->icon1; if (icon1_path && strlen(icon1_path) > 0 ) { icon = elm_icon_add(obj); icon_size = (int)(SEARCH_THUMBNAIL_SIZE * scale); elm_image_prescale_set(icon, icon_size); elm_image_file_set(icon, icon1_path, NULL); evas_object_size_hint_min_set(icon, SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale); evas_object_size_hint_max_set(icon, SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale); evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); } } else if(!strcmp(part, "elm.icon.2")) { icon2_path = sel_mem_info->icon2; if (icon2_path && strlen(icon2_path) > 0 ) { icon = elm_icon_add(obj); icon_size = (int)(SEARCH_ICON_SIZE * scale); elm_image_prescale_set(icon, icon_size); elm_image_file_set(icon, icon2_path, NULL); evas_object_size_hint_min_set(icon, SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale); evas_object_size_hint_max_set(icon, SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale); evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); } } return icon; } static Evas_Object *__search_gl_content_get_genlist_bookmark_item_type(void *data, Evas_Object *obj, const char *part) { Evas_Object *icon = NULL; int icon_size = 0; int id = 0; char *icon2_path = NULL; struct search_item_sel *sel_mem_info = (struct search_item_sel *)data; SEARCH_RETV_IF(sel_mem_info == NULL, NULL); double scale = elm_config_scale_get(); if (!SEARCH_STRCMP(part, "elm.icon") || !SEARCH_STRCMP(part, "elm.icon.1")) { if (sel_mem_info->launch_param) { id = atoi(sel_mem_info->launch_param); favorites_bookmark_get_favicon(id, evas_object_evas_get(obj), &icon); } if (!icon && sel_mem_info->icon1) { icon = elm_icon_add(obj); icon_size = (int)(SEARCH_ICON_SIZE * scale); elm_image_prescale_set(icon, icon_size); elm_image_file_set(icon, sel_mem_info->icon1, NULL); } if (icon) { evas_object_size_hint_min_set(icon, SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale); evas_object_size_hint_max_set(icon, SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale); evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); } } else if(!strcmp(part, "elm.icon.2")) { icon2_path = sel_mem_info->icon2; if (icon2_path && strlen(icon2_path) > 0 ) { icon = elm_icon_add(obj); icon_size = (int)(SEARCH_ICON_SIZE * scale); elm_image_prescale_set(icon, icon_size); elm_image_file_set(icon, icon2_path, NULL); evas_object_size_hint_min_set(icon, SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale); evas_object_size_hint_max_set(icon, SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale); evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); } } return icon; } static Evas_Object *__search_gl_content_get_genlist_history_item_type(void *data, Evas_Object *obj, const char *part) { Evas_Object *icon = NULL; int icon_size = 0; char *icon2_path = NULL; int id = 0; struct search_item_sel *sel_mem_info = (struct search_item_sel *)data; SEARCH_RETV_IF(sel_mem_info == NULL, NULL); double scale = elm_config_scale_get(); if (!SEARCH_STRCMP(part, "elm.icon") || !SEARCH_STRCMP(part, "elm.icon.1")) { if (sel_mem_info->launch_param) { id = atoi(sel_mem_info->launch_param); favorites_history_get_favicon(id, evas_object_evas_get(obj), &icon); } if (!icon && sel_mem_info->icon1) { icon = elm_icon_add(obj); icon_size = (int)(SEARCH_ICON_SIZE * scale); elm_image_prescale_set(icon, icon_size); elm_image_file_set(icon, sel_mem_info->icon1, NULL); } if (icon) { evas_object_size_hint_min_set(icon, SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale); evas_object_size_hint_max_set(icon, SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale); evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); } } else if(!strcmp(part, "elm.icon.2")) { icon2_path = (char*)sel_mem_info->icon2; if (icon2_path && strlen(icon2_path) > 0 ) { icon = elm_icon_add(obj); icon_size = (int)(SEARCH_ICON_SIZE * scale); elm_image_prescale_set(icon, icon_size); elm_image_file_set(icon, icon2_path, NULL); evas_object_size_hint_min_set(icon, SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale); evas_object_size_hint_max_set(icon, SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale); evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); } } return icon; } static Eina_Bool __search_gl_state_get(void *data, Evas_Object * obj, const char *part) { return EINA_FALSE; } static char *__search_gl_label_get_genlist_item_type(void *data, Evas_Object * obj, const char *part) { char *buf = NULL; struct search_item_sel *sel_mem_info = (struct search_item_sel *)data; SEARCH_RETV_IF(sel_mem_info == NULL, g_strdup("")); if (!SEARCH_STRCMP(part, "elm.text") || !SEARCH_STRCMP(part, "elm.text.1")) { buf = g_strdup(sel_mem_info->text1); } else if (!SEARCH_STRCMP(part, "elm.text.sub") || !SEARCH_STRCMP(part, "elm.text.2")) { buf = g_strdup(sel_mem_info->text2); } else { buf = NULL; } return buf; } static char *__search_gl_label_get_normal_type(void *data, Evas_Object * obj, const char *part) { char *title_string = (char*)data; if(title_string) return strdup(title_string); else return strdup(""); } static char *__search_gl_label_get_group(void *data, Evas_Object * obj, const char *part) { struct search_content_object *object = (struct search_content_object*)data; SEARCH_RETV_IF(object == NULL, strdup("")); if (object->string_type == SEARCH_STR_TYPE_APP_STRING) { return strdup(gettext(object->name)); } else { return strdup(dgettext("sys_string", object->name)); } } static char *__search_gl_label_get_more(void *data, Evas_Object * obj, const char *part) { return strdup(gettext("IDS_SSEARCH_BODY_MORE_RESULTS")); } static void __search_gl_del_grouptitle(void *data, Evas_Object * obj) { SEARCH_FUNC_START; SEARCH_FUNC_END; return; } static void __search_gl_del(void *data, Evas_Object * obj) { struct search_item_sel *sel_mem_info = (struct search_item_sel *)data; SEARCH_RET_IF(sel_mem_info == NULL); SEARCH_FREE(sel_mem_info->icon1); SEARCH_FREE(sel_mem_info->icon2); SEARCH_FREE(sel_mem_info->text1); SEARCH_FREE(sel_mem_info->text2); SEARCH_FREE(sel_mem_info->launch_path); SEARCH_FREE(sel_mem_info->launch_param); SEARCH_FREE(sel_mem_info); return; } static void __search_gl_del_more_button(void *data, Evas_Object * obj) { struct search_item_more_sel *sel_mem_more = (struct search_item_more_sel *)data; SEARCH_RET_IF(sel_mem_more == NULL); SEARCH_FREE(sel_mem_more); return; } int search_app_connect(void *data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; int rc = 0, conn_ret = 0; int ret = SEARCH_RET_SUCCESS; int i = 0; SEARCH_RETV_IF(ad == NULL, SEARCH_RET_FAIL); for (i = 0; i < SEARCH_CONT_MAX ; ++i) { switch (ad->result_obj[i].contents_type) { /* Contact-service should be conneted for display Message result. Because We should display message with contact photo if user have contact photo which have matched to tel-number of sender or receiver */ case SEARCH_CONT_PHONE_MSG: { msg_error_t err = MSG_SUCCESS; if (ad->result_obj[i].visible == EINA_TRUE) { /* Connect Contact-service if contact category status is invisible */ if (ad->result_obj[SEARCH_CONT_PHONE_CONTACTS].visible == EINA_FALSE) { rc = contacts_connect2(); if (rc != CONTACTS_ERROR_NONE) { /* If we fail to connect contact-service, display message-app icon */ SEARCH_DEBUG_WARNING("Fail to connect contact service : %d",rc); } } /* Connect Message-Service */ err = msg_open_msg_handle(&ad->msg_handle); if (err != MSG_SUCCESS) { SEARCH_DEBUG_WARNING("msg_open_msg_handle error : %d", err); ad->msg_handle = NULL; } } else { /* Disconnect Contact-service if contact category status is invisible */ if (ad->result_obj[SEARCH_CONT_PHONE_CONTACTS].visible == EINA_FALSE) { rc = contacts_disconnect2(); if (rc != CONTACTS_ERROR_NONE) SEARCH_DEBUG_WARNING("Fail to disconnect contact service : %d",rc); } /* Disconnect Message-Service */ if (ad->msg_handle != NULL ) { err = msg_close_msg_handle(&ad->msg_handle); if (err != MSG_SUCCESS) SEARCH_DEBUG_WARNING("msg_close_msg_handle error : %d", err); ad->msg_handle = NULL; } } } break; case SEARCH_CONT_PHONE_EMAIL: break; /* IMAGE, MUSIC, VIDEO use common handle */ case SEARCH_CONT_PHONE_IMAGES: case SEARCH_CONT_PHONE_MUSIC: case SEARCH_CONT_PHONE_VIDEO: { if (ad->result_obj[SEARCH_CONT_PHONE_IMAGES].visible == EINA_TRUE || ad->result_obj[SEARCH_CONT_PHONE_MUSIC].visible == EINA_TRUE || ad->result_obj[SEARCH_CONT_PHONE_VIDEO].visible == EINA_TRUE ) { conn_ret = media_content_connect(); if (conn_ret != 0) SEARCH_DEBUG_WARNING("media_content_connect failed : %d\n", conn_ret); } else { conn_ret = media_content_disconnect(); if(conn_ret < 0) SEARCH_DEBUG_WARNING("media_content_disconnect failed : %d\n", conn_ret); } } break; case SEARCH_CONT_PHONE_MEMO: { if (ad->result_obj[i].visible == EINA_TRUE) { rc = memo_init(NULL); if (rc == -1) { SEARCH_DEBUG_WARNING ("memo svc connect fail : %d", rc); } } else memo_fini(); } break; } } SEARCH_FUNC_END; return ret; } int search_app_disconnect(void *data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; int conn_ret = 0; int i = 0; SEARCH_RETV_IF(ad == NULL, SEARCH_RET_FAIL); for (i = 0; i < SEARCH_CONT_MAX ; ++i) { switch (ad->result_obj[i].contents_type) { case SEARCH_CONT_PHONE_MSG: { if (ad->msg_handle != NULL ) { msg_error_t err = MSG_SUCCESS; err = msg_close_msg_handle(&ad->msg_handle); if (err != MSG_SUCCESS) { SEARCH_DEBUG_WARNING("msg_close_msg_handle error : %d", err); } ad->msg_handle = NULL; } } break; case SEARCH_CONT_PHONE_EMAIL: break; case SEARCH_CONT_PHONE_IMAGES: case SEARCH_CONT_PHONE_MUSIC: case SEARCH_CONT_PHONE_VIDEO: { conn_ret = media_content_disconnect(); if(conn_ret != 0) SEARCH_DEBUG_WARNING("media_content_disconnect failed : %d\n", conn_ret); } break; case SEARCH_CONT_PHONE_MEMO: { memo_fini(); } break; } } SEARCH_FUNC_END; return 0; } void search_gl_phone_result_sel(void *data, Evas_Object * obj, void *event_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem; Elm_Object_Item *it = (Elm_Object_Item *) event_info; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(it == NULL); cur_category_mem = (struct search_item_sel *)elm_object_item_data_get(it); SEARCH_RET_IF(cur_category_mem == NULL); SEARCH_DEBUG_LOG("cur_category_mem->type : %d", cur_category_mem->type); elm_genlist_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_NONE); elm_object_scroll_freeze_push(obj); switch (cur_category_mem->type) { case SEARCH_CONT_PHONE_CONTACTS: search_launch_contact_view(ad, cur_category_mem); break; case SEARCH_CONT_PHONE_MSG: search_launch_msg_view(ad, cur_category_mem); break; case SEARCH_CONT_PHONE_EMAIL: search_launch_email_view(ad, cur_category_mem); break; case SEARCH_CONT_PHONE_IMAGES: search_launch_image_view(ad, cur_category_mem); break; case SEARCH_CONT_PHONE_VIDEO: search_launch_video_view(ad, cur_category_mem); break; case SEARCH_CONT_PHONE_MUSIC: search_launch_music_view(ad, cur_category_mem); break; case SEARCH_CONT_PHONE_CALENDAR: search_launch_calendar_view(ad, cur_category_mem); break; case SEARCH_CONT_PHONE_MEMO: search_launch_memo_view(ad, cur_category_mem); break; case SEARCH_CONT_PHONE_MENU: search_launch_menu_view(ad, cur_category_mem); break; case SEARCH_CONT_PHONE_BROWSER: search_launch_browser_view(ad, cur_category_mem); default: break; } elm_genlist_item_selected_set(it, EINA_FALSE); SEARCH_FUNC_END; } static int __search_gl_set_phone_search_result(struct search_content_object *obj, int offset, char *keyword, void *data, struct search_genlist_info *result_info) { SEARCH_FUNC_START; int sel_cnt = SEARCH_CATEGORY_LIST_MORE_CNT; int func_ret = SEARCH_RET_SEARCH_NONE; struct appdata *ad = (struct appdata *)data; SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL); obj->mr_info.offset = offset; if (obj->mr_info.offset == 0) { obj->mr_info.next_point = 0; } SEARCH_DEBUG_LOG("offset : %d, limit : %d keyword : %s", offset, sel_cnt, keyword); if (obj->visible == EINA_TRUE ) { switch (obj->contents_type) { case SEARCH_CONT_PHONE_CONTACTS: { func_ret = search_sql_contact_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } break; case SEARCH_CONT_PHONE_MSG: { if (ad->msg_handle != NULL) { func_ret = search_sql_msg_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } } break; case SEARCH_CONT_PHONE_EMAIL: { func_ret = search_sql_email_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } break; case SEARCH_CONT_PHONE_IMAGES: { func_ret = search_sql_image_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } break; case SEARCH_CONT_PHONE_MUSIC: { func_ret = search_sql_music_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } break; case SEARCH_CONT_PHONE_VIDEO: { func_ret = search_sql_video_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } break; case SEARCH_CONT_PHONE_CALENDAR: { func_ret = search_sql_calendar_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } break; case SEARCH_CONT_PHONE_MEMO: { func_ret = search_sql_memo_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } break; case SEARCH_CONT_PHONE_MENU: { func_ret = search_sql_menu_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } break; case SEARCH_CONT_PHONE_BROWSER: { func_ret = search_sql_browser_search_result_by_api(obj, offset, sel_cnt, keyword, ad, result_info); } } } SEARCH_FUNC_END; return func_ret; } static void __search_thread_heavy_cb(void *data, Ecore_Thread *th) { SEARCH_FUNC_START; struct search_thread_data *thread_data = (struct search_thread_data*)data; struct appdata *ad = NULL; struct search_content_object *obj = NULL; struct search_genlist_info *result_info = NULL; int ret = 0; int i = SEARCH_CONT_PHONE_MIN; int category_type = 0; SEARCH_RET_IF(thread_data == NULL); ad = thread_data->ad; SEARCH_RET_IF(ad == NULL); SEARCH_DEBUG_LOG("Thread ID : %p Keyword : %s", th, thread_data->keyword); thread_data->is_search_result = SEARCH_RET_SEARCH_NONE; while (i <= SEARCH_CONT_PHONE_MAX) { int offset = 0; obj = &ad->result_obj[i]; category_type = obj->category_type; if (category_type == SEARCH_OBJ_PHONE_CONTENTS) { if (ecore_thread_check(th) != EINA_TRUE) { result_info = (struct search_genlist_info *)calloc(1, sizeof(struct search_genlist_info)); ret = __search_gl_set_phone_search_result(obj, offset, thread_data->keyword, ad, result_info); if (ret == SEARCH_RET_SEARCH_SUCCESS) { SEARCH_DEBUG_LOG("Matched result : %s %d", obj->name, ret); thread_data->is_search_result = SEARCH_RET_SEARCH_SUCCESS; ecore_thread_feedback(th, result_info); } else { SEARCH_FREE(result_info); } } } i++; } SEARCH_FUNC_END; } static void __search_thread_feedback_cb(void *data, Ecore_Thread *th, void *msg_data) { SEARCH_FUNC_START; struct search_thread_data *thread_data = (struct search_thread_data *)data; struct appdata *ad = NULL; struct search_genlist_info *result_list = (struct search_genlist_info *)msg_data; struct search_pipe_data *pdata = NULL; SEARCH_RET_IF(thread_data == NULL); SEARCH_RET_IF(result_list == NULL); ad = thread_data->ad; SEARCH_RET_IF(ad == NULL); if (ecore_thread_check(th) == EINA_TRUE) return; pdata = (struct search_pipe_data *)calloc(1,sizeof(struct search_pipe_data)); pdata->cmd = SEARCH_PIPE_CMD_ADD_GENLIST_PHONE; pdata->obj = NULL; pdata->result_list = result_list; pdata->search_ret = thread_data->is_search_result; ecore_pipe_write(ad->pipe, &pdata, sizeof(struct search_pipe_data)); SEARCH_FUNC_END; } static void __search_thread_end_cb(void *data, Ecore_Thread *th) { SEARCH_FUNC_START; struct search_thread_data *thread_data = (struct search_thread_data *)data; struct appdata *ad = NULL; struct search_pipe_data *pdata = NULL; SEARCH_RET_IF(thread_data == NULL); ad = thread_data->ad; SEARCH_RET_IF(ad == NULL); pdata = (struct search_pipe_data *)calloc(1,sizeof(struct search_pipe_data)); pdata->cmd = SEARCH_PIPE_CMD_SET_LAYOUT; pdata->search_ret = thread_data->is_search_result; if (ecore_thread_check(th) == EINA_TRUE) return; ecore_pipe_write(ad->pipe, &pdata, sizeof(struct search_pipe_data)); SEARCH_FREE(thread_data->keyword); SEARCH_FREE(thread_data); SEARCH_FUNC_END; } static void __search_thread_cancel_cb(void *data, Ecore_Thread *th) { SEARCH_FUNC_START; struct search_thread_data *thread_data = (struct search_thread_data *)data; SEARCH_RET_IF(thread_data == NULL); SEARCH_FREE(thread_data->keyword); SEARCH_FREE(thread_data); SEARCH_FUNC_END; } void search_stop_search(void *data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; SEARCH_RET_IF(ad == NULL); if (ad->search_thread) { ecore_thread_cancel(ad->search_thread); ad->search_thread = NULL; } if (ad->search_timer) { ecore_timer_del(ad->search_timer); ad->search_timer = NULL; } SEARCH_FUNC_END; } Ecore_Thread* search_make_result_thread(void *data) { SEARCH_FUNC_START; Ecore_Thread *th = NULL; struct appdata *ad = (struct appdata *)data; struct search_thread_data *thread_data = NULL; SEARCH_RETV_IF(ad == NULL, NULL); /* Create Thread for Phone Search */ thread_data = (struct search_thread_data *)calloc(1, sizeof(struct search_thread_data)); thread_data->ad = ad; thread_data->is_search_result = SEARCH_RET_SEARCH_NONE; thread_data->keyword = strdup(ad->search_word); th = ecore_thread_feedback_run(__search_thread_heavy_cb, __search_thread_feedback_cb, __search_thread_end_cb, __search_thread_cancel_cb, thread_data, EINA_TRUE); SEARCH_FUNC_END; return th; } void search_result_gl_init(void *data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; ad->pipe = ecore_pipe_add(ecore_exe_pipe_cb, ad); eina_lock_new(&ad->mutex); eina_condition_new(&ad->condition, &ad->mutex); Evas_Object *genlist; if (ad->itc_pslist_1line == NULL) { ad->itc_pslist_1line = elm_genlist_item_class_new(); ad->itc_pslist_1line->item_style = "1text.tb"; ad->itc_pslist_1line->func.text_get = __search_gl_label_get_genlist_item_type; ad->itc_pslist_1line->func.content_get = __search_gl_content_get_genlist_item_type; ad->itc_pslist_1line->func.state_get = __search_gl_state_get; ad->itc_pslist_1line->func.del = __search_gl_del; } if (ad->itc_pslist_1line_1icon == NULL) { ad->itc_pslist_1line_1icon = elm_genlist_item_class_new(); ad->itc_pslist_1line_1icon->item_style = "1text.1icon.2.tb"; ad->itc_pslist_1line_1icon->func.text_get = __search_gl_label_get_genlist_item_type; ad->itc_pslist_1line_1icon->func.content_get = __search_gl_content_get_genlist_item_type; ad->itc_pslist_1line_1icon->func.state_get = __search_gl_state_get; ad->itc_pslist_1line_1icon->func.del = __search_gl_del; } if (ad->itc_pslist_1line_1icon_browser_history== NULL) { ad->itc_pslist_1line_1icon_browser_history = elm_genlist_item_class_new(); ad->itc_pslist_1line_1icon_browser_history->item_style = "1text.1icon.2.tb"; ad->itc_pslist_1line_1icon_browser_history->func.text_get = __search_gl_label_get_genlist_item_type; ad->itc_pslist_1line_1icon_browser_history->func.content_get = __search_gl_content_get_genlist_history_item_type; ad->itc_pslist_1line_1icon_browser_history->func.state_get = __search_gl_state_get; ad->itc_pslist_1line_1icon_browser_history->func.del = __search_gl_del; } if (ad->itc_pslist_1line_2icon == NULL) { ad->itc_pslist_1line_2icon = elm_genlist_item_class_new(); ad->itc_pslist_1line_2icon->item_style = "1text.2icon.6.tb"; ad->itc_pslist_1line_2icon->func.text_get = __search_gl_label_get_genlist_item_type; ad->itc_pslist_1line_2icon->func.content_get = __search_gl_content_get_genlist_item_type; ad->itc_pslist_1line_2icon->func.state_get = __search_gl_state_get; ad->itc_pslist_1line_2icon->func.del = __search_gl_del; } if (ad->itc_pslist_2line_1icon == NULL) { ad->itc_pslist_2line_1icon = elm_genlist_item_class_new(); ad->itc_pslist_2line_1icon->item_style = "2text.1icon.4.tb"; ad->itc_pslist_2line_1icon->func.text_get = __search_gl_label_get_genlist_item_type; ad->itc_pslist_2line_1icon->func.content_get = __search_gl_content_get_genlist_item_type; ad->itc_pslist_2line_1icon->func.state_get = __search_gl_state_get; ad->itc_pslist_2line_1icon->func.del = __search_gl_del; } if (ad->itc_pslist_2line_2icon == NULL) { ad->itc_pslist_2line_2icon = elm_genlist_item_class_new(); ad->itc_pslist_2line_2icon->item_style = "2text.2icon.4.tb"; ad->itc_pslist_2line_2icon->func.text_get = __search_gl_label_get_genlist_item_type; ad->itc_pslist_2line_2icon->func.content_get = __search_gl_content_get_genlist_item_type; ad->itc_pslist_2line_2icon->func.state_get = __search_gl_state_get; ad->itc_pslist_2line_2icon->func.del = __search_gl_del; } if (ad->itc_pslist_2line_2icon_browser_bookmark == NULL) { ad->itc_pslist_2line_2icon_browser_bookmark = elm_genlist_item_class_new(); ad->itc_pslist_2line_2icon_browser_bookmark->item_style = "2text.2icon.4.tb"; ad->itc_pslist_2line_2icon_browser_bookmark->func.text_get = __search_gl_label_get_genlist_item_type; ad->itc_pslist_2line_2icon_browser_bookmark->func.state_get = __search_gl_state_get; ad->itc_pslist_2line_2icon_browser_bookmark->func.content_get = __search_gl_content_get_genlist_bookmark_item_type; ad->itc_pslist_2line_2icon_browser_bookmark->func.del = __search_gl_del; } if (ad->itc_grouptitle == NULL) { ad->itc_grouptitle = elm_genlist_item_class_new(); ad->itc_grouptitle->item_style = "groupindex"; ad->itc_grouptitle->func.text_get = __search_gl_label_get_group; ad->itc_grouptitle->func.state_get = __search_gl_state_get; ad->itc_grouptitle->func.del = __search_gl_del_grouptitle; } if (ad->itc_listmore == NULL) { ad->itc_listmore = elm_genlist_item_class_new(); ad->itc_listmore->item_style = "1text.tb"; ad->itc_listmore->func.text_get = __search_gl_label_get_more; ad->itc_listmore->func.state_get = __search_gl_state_get; ad->itc_listmore->func.del = __search_gl_del_more_button; } ad->search_gl = NULL; genlist = elm_genlist_add(ad->conformant); // To use multiline textblock/entry/editfield in genlist, set height_for_width mode // then the item's height is calculated while the item's width fits to genlist width. elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); elm_genlist_tree_effect_enabled_set(genlist, EINA_TRUE); ad->search_gl = genlist; evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); SEARCH_FUNC_END; } void search_result_gl_deinit(void *data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; SEARCH_RET_IF(ad == NULL); ecore_pipe_del(ad->pipe); eina_condition_free(&ad->condition); eina_lock_free(&ad->mutex); if (ad->itc_pslist_1line != NULL) elm_genlist_item_class_free(ad->itc_pslist_1line); if (ad->itc_pslist_1line_1icon != NULL) elm_genlist_item_class_free(ad->itc_pslist_1line_1icon); if (ad->itc_pslist_1line_1icon_browser_history != NULL) elm_genlist_item_class_free(ad->itc_pslist_1line_1icon_browser_history); if (ad->itc_pslist_1line_2icon != NULL) elm_genlist_item_class_free(ad->itc_pslist_1line_2icon); if (ad->itc_pslist_2line_1icon != NULL) elm_genlist_item_class_free(ad->itc_pslist_2line_1icon); if (ad->itc_pslist_2line_2icon != NULL) elm_genlist_item_class_free(ad->itc_pslist_2line_2icon); if (ad->itc_pslist_2line_2icon_browser_bookmark != NULL) elm_genlist_item_class_free(ad->itc_pslist_2line_2icon_browser_bookmark); if (ad->itc_grouptitle != NULL) elm_genlist_item_class_free(ad->itc_grouptitle); if (ad->itc_listmore != NULL) elm_genlist_item_class_free(ad->itc_listmore); SEARCH_FUNC_END; } void search_gl_result_more_item_append_cb(void *data, Evas_Object * obj, void *event_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; Elm_Object_Item *it = (Elm_Object_Item *) event_info; struct search_pipe_data *pdata = NULL; struct search_genlist_info *result_info = NULL; struct search_item_more_sel *sel_more = (search_item_more_sel *)elm_object_item_data_get(it); struct search_content_object *content_obj = sel_more->obj; int offset = content_obj->mr_info.next_point; int ret = SEARCH_RET_SEARCH_NONE; elm_object_item_del(it); result_info = (struct search_genlist_info *)calloc(1, sizeof(struct search_genlist_info)); ret = __search_gl_set_phone_search_result(content_obj, offset, ad->search_word, ad, result_info); pdata = (struct search_pipe_data *)calloc(1,sizeof(struct search_pipe_data)); pdata->cmd = SEARCH_PIPE_CMD_ADD_GENLIST_PHONE; pdata->obj = NULL; pdata->result_list = result_info; pdata->search_ret = ret; ecore_pipe_write(ad->pipe, &pdata, sizeof(struct search_pipe_data)); pdata = (struct search_pipe_data *)calloc(1,sizeof(struct search_pipe_data)); pdata->cmd = SEARCH_PIPE_CMD_SET_LAYOUT; pdata->search_ret = ret; ecore_pipe_write(ad->pipe, &pdata, sizeof(struct search_pipe_data)); SEARCH_FUNC_END; } void search_set_result_list(void *data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; int category = 0; int ret = SEARCH_RET_SEARCH_NONE; bool is_input_keyword = false; struct search_pipe_data *pipe_data = NULL; char *text = NULL; SEARCH_RET_IF(ad == NULL); category = ad->search_category; search_stop_search(ad); text = elm_entry_markup_to_utf8(elm_object_text_get(ad->search_entry)); SEARCH_FREE(ad->not_markup_search_word); SEARCH_FREE(ad->search_word); if((text) && (strlen(text) > 0)) { if (ad->first_search == true) { search_result_gl_init(ad); search_util_date_time_format_init(); search_app_connect(ad); ad->first_search = false; } ad->not_markup_search_word = strdup(elm_object_text_get(ad->search_entry)); ad->search_word = text; is_input_keyword = true; /* set keyword to vconf for save last search histroy */ ret = vconf_set_str(SMARTSEARCH_KEY_KEYWORD, ad->not_markup_search_word); if (ret < 0) SEARCH_DEBUG_WARNING("Error : set keyword to vconf"); } else { if (category == SEARCH_CATE_PHONE) { pipe_data = (struct search_pipe_data *)calloc(1, sizeof(struct search_pipe_data)); pipe_data->cmd = SEARCH_PIPE_CMD_SET_LAYOUT; pipe_data->search_ret = SEARCH_RET_SEARCH_NONE; ecore_pipe_write(ad->pipe, &pipe_data, sizeof(struct search_pipe_data)); } /* set keyword to vconf for save last search histroy */ ret = vconf_set_str(SMARTSEARCH_KEY_KEYWORD, ""); if (ret < 0) { SEARCH_DEBUG_WARNING("Error : set keyword to vconf"); } SEARCH_FREE(text); } /* If category is Phone, make a thread for search */ pipe_data = (struct search_pipe_data *)calloc(1, sizeof(struct search_pipe_data)); pipe_data->cmd = SEARCH_PIPE_CMD_CLEAR_GENLIST; ecore_pipe_write(ad->pipe, &pipe_data, sizeof(struct search_pipe_data)); switch(category) { case SEARCH_CATE_PHONE: if (is_input_keyword) { ad->search_thread = search_make_result_thread(ad); } break; } SEARCH_FUNC_END; } void search_layout_set_search_list(void* data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; SEARCH_RET_IF(ad == NULL); if (elm_object_part_content_get(ad->sb_layout,"list_noresult")) { elm_object_part_content_unset(ad->sb_layout,"list_noresult"); evas_object_hide(ad->noresult_view); if (ad->search_gl) { elm_object_part_content_set(ad->sb_layout, "list", ad->search_gl); evas_object_show(ad->search_gl); } } if (ad->search_gl) { elm_genlist_item_show(elm_genlist_first_item_get(ad->search_gl), ELM_GENLIST_ITEM_SCROLLTO_TOP); } SEARCH_FUNC_END; return; } void search_layout_set_search_no_result(void* data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; SEARCH_RET_IF(ad == NULL); if (elm_object_part_content_get(ad->sb_layout,"list")) { elm_object_part_content_unset(ad->sb_layout, "list"); if (ad->search_gl) { evas_object_hide(ad->search_gl); } elm_object_part_content_set(ad->sb_layout,"list_noresult", ad->noresult_view); evas_object_show(ad->noresult_view); } SEARCH_FUNC_END; return; } int search_layout_get_content_list_set_status(void* data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; int ret = SEARCH_RET_FAIL; SEARCH_RETV_IF(ad == NULL, ret); if (elm_object_part_content_get(ad->sb_layout,"list")) { ret = SEARCH_RET_SUCCESS; } else { ret = SEARCH_RET_FAIL; } SEARCH_FUNC_END; return ret; }