diff options
Diffstat (limited to 'src/ps_searcher.cpp')
-rwxr-xr-x | src/ps_searcher.cpp | 2255 |
1 files changed, 2255 insertions, 0 deletions
diff --git a/src/ps_searcher.cpp b/src/ps_searcher.cpp new file mode 100755 index 0000000..ed43f30 --- /dev/null +++ b/src/ps_searcher.cpp @@ -0,0 +1,2255 @@ +/* + * Copyright 2012-2013 Samsung Electronics Co., Ltd/ + * + * Licensed under the Flora License, Version 1.0 (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 <sqlite3.h> + +#include <contacts.h> +#include <calendar2.h> +#include <memo-db.h> + +#include <email-api-mail.h> + +#include <favorites.h> +#include <media_content.h> + +#include <msg_storage.h> +#include <msg_storage_types.h> +#include <msg.h> + +#include <ail.h> +#include <unicode/ucal.h> +#include <unicode/ustring.h> +#include <unicode/ustdio.h> +#include <unicode/udat.h> + +char* g_keyword = NULL; + +struct search_cb_data { + struct search_content_object *obj; + struct appdata *ad; + char *keyword; + struct search_genlist_info *result_info; +}; + +struct search_cb_data_browser { + struct search_content_object *obj; + struct appdata *ad; + char *keyword; + struct search_genlist_info *result_info; + struct search_more_result *info; + bool search_ret; +}; + +struct media_cb_data { + bool is_sdcard; + char *dirname; +}; + +int search_sql_stmt_init(sqlite3_stmt * sql_stmt) +{ + SEARCH_FUNC_START; + + int rc = 0; + + rc = sqlite3_clear_bindings(sql_stmt); + if (rc != SQLITE_OK) { + SEARCH_DEBUG_ERROR("sqlite3_clear_bindings error"); + return SEARCH_RET_FAIL; + } + + rc = sqlite3_reset(sql_stmt); + if (rc != SQLITE_OK) { + SEARCH_DEBUG_ERROR("sqlite3_reset error"); + return SEARCH_RET_FAIL; + } + + SEARCH_FUNC_END; + + return SEARCH_RET_SUCCESS; +} + +int search_sql_stmt_finalize(sqlite3_stmt * stmt) +{ + SEARCH_FUNC_START; + + int ret; + + ret = sqlite3_finalize(stmt); + if (ret != SQLITE_OK) { + SEARCH_DEBUG_ERROR("sqlite3_finalize error : %d ", ret); + return -1; + } + + SEARCH_FUNC_END; + + return 0; +} + +int search_sql_prepare_stmt(sqlite3 *db_handle, const char *query, + sqlite3_stmt ** stmt_out) +{ + SEARCH_FUNC_START; + + int rc = 0; + int ret = 0; + + rc = sqlite3_prepare(db_handle, query, strlen(query), stmt_out, NULL); + if (rc != SQLITE_OK) { + SEARCH_DEBUG_ERROR("sql preapre error : %d / %s", rc, query); + ret = SEARCH_RET_FAIL; + } else { + ret = SEARCH_RET_SUCCESS; + } + + SEARCH_FUNC_END; + + return ret; +} + +int search_sql_bind_text(sqlite3* db_handle, sqlite3_stmt *sql_stmt, int col, char *data) +{ + int rc = 0; + int ret = SEARCH_RET_SEARCH_NONE; + + rc = sqlite3_bind_text(sql_stmt, col, data, strlen(data), SQLITE_STATIC); + if (rc != SQLITE_OK) { + SEARCH_DEBUG_ERROR("SQL BIND TEXT ERROR : %s(%d) / %s\n", + sqlite3_errmsg(db_handle), + rc, + data); + ret = SEARCH_RET_SEARCH_FAIL; + } + + return ret; +} + +int search_sql_bind_int(sqlite3* db_handle, sqlite3_stmt *sql_stmt, int col, int data) +{ + int rc = 0; + int ret = SEARCH_RET_SEARCH_NONE; + + rc = sqlite3_bind_int(sql_stmt, col, data); + if (rc != SQLITE_OK) { + SEARCH_DEBUG_ERROR("SQL BIND INT ERROR : %s(%d) / %d\n", + sqlite3_errmsg(db_handle), + rc, + data); + ret = SEARCH_RET_SEARCH_FAIL; + } + return ret; +} + +int search_sql_contact_search_result_by_api(struct search_content_object *obj, + int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + struct appdata *ad = (struct appdata *)data; + int ret = 0; + + contacts_query_h query = NULL; + contacts_filter_h filter = NULL; + contacts_list_h list = NULL; + + unsigned int count = 0; + int total_cnt = -1; + int curr_cnt = -1; + int loop_cnt = 0; + int search_ret = SEARCH_RET_SEARCH_NONE; + + SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL); + + ret = contacts_connect2(); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_connect2 : %d", ret); + goto out_func; + } + + ret = contacts_query_create(_contacts_person_number._uri, &query); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_query_create : %d", ret); + goto out_func; + } + + ret = contacts_filter_create(_contacts_person_number._uri, &filter); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_filter_create : %d", ret); + goto out_func; + } + + ret = contacts_filter_add_str(filter, _contacts_person_number.display_name, CONTACTS_MATCH_CONTAINS, keyword); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_filter_add_str : %d", ret); + goto out_func; + } + + ret = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_filter_add_operator : %d", ret); + goto out_func; + } + + ret = contacts_filter_add_str(filter, _contacts_person_number.number, CONTACTS_MATCH_CONTAINS, keyword); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_filter_add_str : %d", ret); + goto out_func; + } + + ret = contacts_query_set_filter(query, filter); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_query_set_filter : %d", ret); + goto out_func; + } + + ret = contacts_query_set_sort(query, _contacts_person_number.display_name, true); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_query_set_sort : %d", ret); + goto out_func; + } + + ret = contacts_db_get_count_with_query(query, &total_cnt); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_db_get_count_with_query : %d", ret); + goto out_func; + } + + ret = contacts_db_get_records_with_query(query, offset, limit, &list); + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("contacts_db_get_records_with_query : %d", ret); + goto out_func; + } + + SEARCH_RETV_IF_WITH_ERRORV(ret != CONTACTS_ERROR_NONE, SEARCH_RET_SEARCH_FAIL, ret); + contacts_list_get_count(list, &count); + + SEARCH_DEBUG_LOG("CONTACT COUNT: %d", count); + SEARCH_DEBUG_LOG("TOTAL COUNT: %d", total_cnt); + + if (count > 0) { + /* Set group title */ + if (offset == 0) { + result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP, + obj, ad->itc_grouptitle, obj, NULL); + } + + do { + struct search_item_sel *sel_mem_info = NULL; + struct search_genlist_item_info *gen_item = NULL; + Elm_Genlist_Item_Class *itc_style = NULL; + + int contact_id = -1; + char *contact_img_path = NULL; + char *str_display = NULL; + char *num_display = NULL; + const char *text_1line = NULL; + const char *text_2line = NULL; + bool is_word_in_str = false; + char contact_id_str[MAX_LENGTH_PER_ID] = {0,}; + + sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel)); + + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", loop_cnt); + continue; + } + + sel_mem_info->type = obj->contents_type; + + contacts_record_h record; + contacts_list_get_current_record_p(list, &record); + contacts_record_get_str_p(record, _contacts_person.image_thumbnail_path, &contact_img_path); + + if (contact_img_path != NULL) { + sel_mem_info->icon1 = strdup(contact_img_path); + } + else if (obj->obj_icon_path) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + + contacts_record_get_str_p(record, _contacts_person.display_name, &str_display); + contacts_record_get_str_p(record, _contacts_number.number, &num_display); + + if (str_display != NULL) { + text_1line = str_display; + } + + if (num_display != NULL) { + text_2line = num_display; + } + + if (text_1line != NULL && text_2line != NULL) { + sel_mem_info->text1 = strdup(search_markup_keyword(str_display, keyword, &is_word_in_str)); + sel_mem_info->text2 = strdup(search_markup_keyword(num_display, keyword, &is_word_in_str)); + itc_style = ad->itc_pslist_2line_1icon; + } else { + if (text_1line) { + sel_mem_info->text1 = strdup(search_markup_keyword(str_display, keyword, &is_word_in_str)); + } + else { + sel_mem_info->text2 = strdup(search_markup_keyword(num_display, keyword, &is_word_in_str)); + } + itc_style = ad->itc_pslist_1line_1icon; + } + + contacts_record_get_int(record, _contacts_person.id, &contact_id); + snprintf(contact_id_str, MAX_LENGTH_PER_ID - 1, "%d", contact_id); + sel_mem_info->launch_param= strdup(contact_id_str); + + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, + obj, itc_style, sel_mem_info, + obj->gl_result_grp); + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + + loop_cnt++; + + if (loop_cnt == limit) { + break; + } + }while (contacts_list_next(list) == CONTACTS_ERROR_NONE); + } else { + SEARCH_DEBUG_WARNING("No matched contacts data", ret); + search_ret = SEARCH_RET_SEARCH_NONE; + goto out_func; + } + + contacts_list_destroy(list, true); + + /* Set more title to genlist (under 'search all') */ + curr_cnt = offset + loop_cnt; + + if (total_cnt > curr_cnt) { + struct search_item_more_sel *sel_mem_more = NULL; + + obj->mr_info.next_point = offset + limit; + + sel_mem_more = + (struct search_item_more_sel *)calloc(1, + sizeof(struct + search_item_more_sel)); + sel_mem_more->obj = obj; + + result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE, + obj, + ad->itc_listmore, + sel_mem_more, + obj->gl_result_grp); + } + + search_ret = SEARCH_RET_SEARCH_SUCCESS; + +out_func: + ret = contacts_disconnect2(); + + if (filter) { + contacts_filter_destroy(filter); + } + + if (query) { + contacts_query_destroy(query); + } + + SEARCH_FUNC_END; + + return search_ret; +} + +int search_sql_calendar_search_result_by_api(struct search_content_object *obj, + int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + struct appdata *ad = (struct appdata *)data; + struct search_item_sel *sel_mem_info = NULL; + struct search_item_more_sel *sel_mem_more = NULL; + struct search_genlist_item_info *gen_item = NULL; + + int loop_cnt = 0; + int count = -1; + int total_cnt = -1; + int ret = 0; + int search_ret = SEARCH_RET_SEARCH_NONE; + int curr_cnt = 0; + + SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL); + + ret = calendar_connect(); + SEARCH_RETV_IF_WITH_ERRORV(ret != CALENDAR_ERROR_NONE, SEARCH_RET_SEARCH_FAIL, ret); + + calendar_query_h query = NULL; + calendar_filter_h visibility_filter = NULL; + calendar_list_h list = NULL; + + ret = calendar_query_create(_calendar_event._uri, &query); + if (ret != CALENDAR_ERROR_NONE) { + SEARCH_DEBUG_WARNING("calendar_query_create : %d", ret); + goto out_func; + } + + ret = calendar_filter_create(_calendar_event._uri, &visibility_filter); + if (ret != CALENDAR_ERROR_NONE) { + SEARCH_DEBUG_WARNING("calendar_filter_create : %d", ret); + goto out_func; + } + + ret = calendar_filter_add_str(visibility_filter, _calendar_event.summary, CALENDAR_MATCH_CONTAINS, keyword); + if (ret != CALENDAR_ERROR_NONE) { + SEARCH_DEBUG_WARNING("calendar_filter_add_str : %d", ret); + goto out_func; + } + + ret = calendar_filter_add_operator(visibility_filter, CALENDAR_FILTER_OPERATOR_AND); + if (ret != CALENDAR_ERROR_NONE) { + SEARCH_DEBUG_WARNING("calendar_filter_add_operator : %d", ret); + goto out_func; + } + + ret = calendar_query_set_filter(query, visibility_filter); + if (ret != CALENDAR_ERROR_NONE) { + SEARCH_DEBUG_WARNING("calendar_query_set_filter : %d", ret); + goto out_func; + } + + ret = calendar_query_set_sort(query, _calendar_event.summary, true); + if (ret != CALENDAR_ERROR_NONE) { + SEARCH_DEBUG_WARNING("calendar_query_set_sort : %d", ret); + goto out_func; + } + + ret = calendar_db_get_count_with_query(query, &total_cnt); + if (ret != CALENDAR_ERROR_NONE) { + SEARCH_DEBUG_WARNING("calendar_db_get_count_with_query : %d", ret); + goto out_func; + } + + ret = calendar_db_get_records_with_query(query, offset, limit, &list); + if (ret != CALENDAR_ERROR_NONE) { + SEARCH_DEBUG_WARNING("calendar_db_get_records_with_query : %d", ret); + goto out_func; + } + + calendar_list_get_count(list, &count); + + SEARCH_DEBUG_LOG("CALENDAR COUNT : %d", count); + SEARCH_DEBUG_LOG("TOTAL COUNT : %d", total_cnt); + + if (count > 0) { + /* Set group title */ + if (offset == 0) { + result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP, + obj, + ad->itc_grouptitle, + obj, + NULL); + } + + do { + int main_id = -1; + char *summary = NULL; + bool is_word_in_str = false; + char format_val[MAX_LENGTH_PER_LINE] = {0,}; + char calendar_id_str[MAX_LENGTH_PER_ID] = {0,}; + + calendar_record_h record; + calendar_time_s cal; + calendar_list_get_current_record_p(list, &record); + + sel_mem_info = (struct search_item_sel *)calloc(1,sizeof(struct search_item_sel)); + + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", loop_cnt); + continue; + } + + sel_mem_info->type = obj->contents_type; + + /* Set Thumbnail Image */ + if (obj->obj_icon_path) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + + /* Set text 1line - Summary */ + calendar_record_get_str_p(record, _calendar_event.summary, &summary); + if ((summary) && (strlen(summary) > 0)) { + sel_mem_info->text1 = strdup(search_markup_keyword(summary, keyword, &is_word_in_str)); + } + + /* Set text 2line - Date */ + calendar_record_get_caltime(record, _calendar_event.start_time, &cal); + + if (cal.type == CALENDAR_TIME_UTIME) { + search_util_date_time_format_get_val(cal.time.utime, format_val, SEARCH_DATE_TYPE_YYMMDD); + } else { + search_util_date_time_format_get_val(cal.time.utime, format_val, SEARCH_DATE_TYPE_YYMM); + } + sel_mem_info->text2 = strdup(format_val); + + /* Set id for launching caledar contents */ + calendar_record_get_int (record, _calendar_event.id, &main_id); + snprintf(calendar_id_str, MAX_LENGTH_PER_ID - 1, "%d", main_id); + sel_mem_info->launch_param = strdup(calendar_id_str); + + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, obj, ad->itc_pslist_2line_1icon, + sel_mem_info, obj->gl_result_grp); + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + + loop_cnt++; + + if (loop_cnt == limit) { + break; + } + } while (calendar_list_next(list) == CALENDAR_ERROR_NONE); + } else { + SEARCH_DEBUG_WARNING("No Matched calendar data: %d", count); + + search_ret = SEARCH_RET_SEARCH_NONE; + goto out_func; + } + + curr_cnt = offset + loop_cnt; + + /* Set more title to genlist (under 'search all') */ + if (total_cnt > curr_cnt) { + obj->mr_info.next_point = offset + limit; + + sel_mem_more = + (struct search_item_more_sel *)calloc(1, + sizeof(struct + search_item_more_sel)); + sel_mem_more->obj = obj; + + result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE, + obj, + ad->itc_listmore, + sel_mem_more, + obj->gl_result_grp); + } + search_ret = SEARCH_RET_SEARCH_SUCCESS; + +out_func: + ret = calendar_disconnect(); + + if (visibility_filter) { + calendar_filter_destroy(visibility_filter); + } + + if (query) { + calendar_query_destroy(query); + } + + SEARCH_FUNC_END; + return search_ret; +} + +static void __search_sql_memo_search_result_cb(memo_data_t * value, + void *user_data) +{ + SEARCH_FUNC_START; + + struct search_cb_data *scd = (struct search_cb_data *)user_data; + struct appdata *ad = NULL; + struct search_content_object *obj = NULL; + struct search_genlist_info *result_info = NULL; + + struct search_genlist_item_info *gen_item = NULL; + struct search_item_sel *sel_mem_info = NULL; + struct search_item_more_sel *sel_mem_more = NULL; + + char *keyword = scd->keyword; + bool is_word_in_str = false; + char memo_id_str[MAX_LENGTH_PER_ID] = {0,}; + char format_val[MAX_LENGTH_PER_LINE] = {0,}; + + SEARCH_RET_IF(scd == NULL); + ad = scd->ad; + obj = scd->obj; + result_info = scd->result_info; + + SEARCH_RET_IF(ad == NULL); + SEARCH_RET_IF(value == NULL); + + if (obj->mr_info.next_point == 0) { + /* Set group title */ + result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP, + obj, + ad->itc_grouptitle, + obj, + NULL); + } + + if (obj->mr_info.next_point < + obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) { + sel_mem_info = (struct search_item_sel*)calloc(1, sizeof(struct search_item_sel)); + + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", obj->mr_info.next_point); + return; + } + + sel_mem_info->type = obj->contents_type; + + /********** START : set search result to sel_mem_info buf ************/ + + if (obj->obj_icon_path) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + + /* First, We should check comment field. It means drawing memo + * If comment field is NULL, then we check content field */ + if ((value->comment) && (strlen(value->comment) > 0)) { + sel_mem_info->text1 = strdup(search_markup_keyword(value->comment, keyword, &is_word_in_str)); + } else if ((value->content) && (strlen(value->content) > 0)) { + sel_mem_info->text1 = strdup(search_markup_keyword(value->content, keyword, &is_word_in_str)); + } + + search_util_date_time_format_get_val(value->modi_time, format_val, SEARCH_DATE_TYPE_YYMM); + sel_mem_info->text2 = strdup(format_val); + + snprintf(memo_id_str, MAX_LENGTH_PER_ID - 1, "%d", value->id); + sel_mem_info->launch_param = strdup(memo_id_str); + + /********** END : set search result to sel_mem_info buf *************/ + + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, obj, ad->itc_pslist_2line_1icon, + sel_mem_info, obj->gl_result_grp); + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + + obj->mr_info.next_point++; + } else if (obj->mr_info.next_point == + obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) { + /* Set more title to genlist (under 'search all') */ + sel_mem_more = + (struct search_item_more_sel *)calloc(1, + sizeof(struct + search_item_more_sel)); + sel_mem_more->obj = obj; + + result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE, + obj, + ad->itc_listmore, + sel_mem_more, + obj->gl_result_grp); + } else { + SEARCH_DEBUG_WARNING + ("__search_sql_memo_search_result_cb wrong index : %d", + obj->mr_info.next_point); + } + + SEARCH_FUNC_END; + + return; +} + +int search_sql_memo_search_result_by_api(struct search_content_object *obj, + int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + struct appdata *ad = (struct appdata *)data; + struct search_cb_data scd = {obj, ad, keyword, result_info}; + + SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL); + + memo_search_data(keyword, + limit, offset, + MEMO_SORT_TITLE_ASC, + __search_sql_memo_search_result_cb, + &scd); + + if (obj->mr_info.next_point == 0) { + SEARCH_DEBUG_WARNING("no memo search result"); + return SEARCH_RET_SEARCH_NONE; + } + + SEARCH_FUNC_END; + return SEARCH_RET_SEARCH_SUCCESS; +} + +int search_sql_email_search_result_by_api(struct search_content_object *obj, + int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + struct appdata *ad = (struct appdata *)data; + + int ret = EMAIL_ERROR_NONE; + int i = 0; + email_mail_list_item_t *mail_list = NULL; + email_list_filter_t *filter_list = NULL; + email_list_sorting_rule_t *sorting_rule_list = NULL; + + int filter_list_count = 5; + int sorting_rule_list_count = 1; + int mail_count = 0; + int total_mail_cnt = -1; + int unseen_mail_cnt = -1; + + struct search_genlist_item_info *gen_item = NULL; + struct search_item_sel *sel_mem_info = NULL; + struct search_item_more_sel *sel_mem_more = NULL; + bool is_word_in_str = false; + + SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL); + + int search_ret = SEARCH_RET_SEARCH_FAIL; + + filter_list = (email_list_filter_t *)malloc(sizeof(email_list_filter_t) * filter_list_count); + memset(filter_list, 0 , sizeof(email_list_filter_t) * filter_list_count); + + filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT; + filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE; + filter_list[0].list_filter_item.rule.key_value.string_type_value = keyword; + filter_list[0].list_filter_item.rule.case_sensitivity = EMAIL_CASE_INSENSITIVE; + + filter_list[1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; + filter_list[1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR; + + filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_TO; + filter_list[2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE; + filter_list[2].list_filter_item.rule.key_value.string_type_value = keyword; + filter_list[2].list_filter_item.rule.case_sensitivity = EMAIL_CASE_INSENSITIVE; + + filter_list[3].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR; + filter_list[3].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR; + + filter_list[4].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE; + filter_list[4].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FROM; + filter_list[4].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE; + filter_list[4].list_filter_item.rule.key_value.string_type_value = keyword; + filter_list[4].list_filter_item.rule.case_sensitivity = EMAIL_CASE_INSENSITIVE; + + sorting_rule_list = (email_list_sorting_rule_t *)malloc(sizeof(email_list_sorting_rule_t) * sorting_rule_list_count); + memset(sorting_rule_list, 0, sizeof(email_list_sorting_rule_t) * sorting_rule_list_count); + + sorting_rule_list[0].target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT; + sorting_rule_list[0].sort_order = EMAIL_SORT_ORDER_ASCEND; + + ret = email_count_mail(filter_list, filter_list_count, &total_mail_cnt, &unseen_mail_cnt); + if (ret != EMAIL_ERROR_NONE) { + SEARCH_DEBUG_WARNING("Fail to call email_count_mail"); + goto out_func; + } + + ret = email_get_mail_list_ex(filter_list, filter_list_count, sorting_rule_list, sorting_rule_list_count, + offset, limit, &mail_list, &mail_count); + + + + if (ret != EMAIL_ERROR_NONE) { + SEARCH_DEBUG_WARNING("Fail to call email_get_mail_list_ex"); + goto out_func; + } + + SEARCH_DEBUG_LOG("EMAIL TOTAL COUNT : %d UNSEEN : %d", total_mail_cnt, unseen_mail_cnt); + SEARCH_DEBUG_LOG("EMAIL COUNT : %d", mail_count); + + if(mail_list == NULL) { + SEARCH_DEBUG_WARNING("mail_list is null"); + search_ret = SEARCH_RET_SEARCH_NONE; + goto out_func; + } + + if (mail_count == 0) { + SEARCH_DEBUG_WARNING("no email search result"); + search_ret = SEARCH_RET_SEARCH_NONE; + goto out_func; + } + + /* Set group title */ + if (offset == 0) { + result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP, + obj, + ad->itc_grouptitle, + obj, + NULL); + } + + /* Set search result to genlist */ + for(i = 0 ; i < mail_count ; i++) { + char email_id_str[MAX_LENGTH_PER_ID] = {0,}; + char email_path_str[MAX_LENGTH_PER_PATH] = {0,}; + + sel_mem_info = (struct search_item_sel*)calloc(1, sizeof(struct search_item_sel)); + + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", i); + continue; + } + + sel_mem_info->type = obj->contents_type; + + if (obj->obj_icon_path) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + + } + + snprintf(email_id_str, MAX_LENGTH_PER_ID - 1, "%d", mail_list[i].mail_id); + sel_mem_info->launch_param = strdup(email_id_str); + + + snprintf(email_path_str, MAX_LENGTH_PER_PATH - 1, "%d %d %d", + mail_list[i].account_id, mail_list[i].mail_id, mail_list[i].mailbox_id); + sel_mem_info->launch_path = strdup(email_path_str); + + if(strlen(mail_list[i].subject) > 0) { + sel_mem_info->text1 = strdup(search_markup_keyword(mail_list[i].subject, ad->search_word, &is_word_in_str)); + } + + if(strlen(mail_list[i].full_address_from) > 0) { + sel_mem_info->text2 = strdup(search_markup_keyword(mail_list[i].full_address_from, ad->search_word, &is_word_in_str)); + } + + if(is_word_in_str == false && (strlen(mail_list[i].email_address_recipient) > 0)) { + sel_mem_info->text2 = strdup(search_markup_keyword(mail_list[i].email_address_recipient, ad->search_word, &is_word_in_str)); + } + + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, obj, ad->itc_pslist_2line_1icon, sel_mem_info, obj->gl_result_grp); + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + } + + /* Set more title to genlist (under 'search all') */ + if (i < total_mail_cnt) { + obj->mr_info.next_point = offset + i; + + sel_mem_more = + (struct search_item_more_sel *)calloc(1, + sizeof(struct search_item_more_sel)); + sel_mem_more->obj = obj; + + result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE, + obj, + ad->itc_listmore, + sel_mem_more, + obj->gl_result_grp); + } + search_ret = SEARCH_RET_SEARCH_SUCCESS; + +out_func: + SEARCH_FREE(filter_list); + SEARCH_FREE(sorting_rule_list); + SEARCH_FREE(mail_list); + + SEARCH_FUNC_END; + return search_ret; +} + +static bool __search_media_info_cb(media_info_h media, void *user_data) +{ + char *media_id = NULL; + char *media_name = NULL; + char *media_path = NULL; + char *media_thumbnail = NULL; + + struct search_item_sel *sel_mem_info = NULL; + Elm_Genlist_Item_Class *itc_style = NULL; + bool is_word_in_str = false; + + struct search_cb_data *scd = (struct search_cb_data*)user_data; + struct appdata *ad = NULL; + struct search_content_object *obj = NULL; + struct search_genlist_info *result_info = NULL; + char *keyword = NULL; + + struct search_genlist_item_info *gen_item = NULL; + char media_id_str[MAX_LENGTH_PER_PATH] = {0,}; + + SEARCH_RETV_IF(scd == NULL, true); + ad = scd->ad; + obj = scd->obj; + result_info = scd->result_info; + keyword = scd->keyword; + + SEARCH_RETV_IF(ad == NULL, true); + + media_info_get_media_id(media, &media_id); + media_info_get_display_name(media, &media_name); + media_info_get_file_path(media, &media_path); + media_info_get_thumbnail_path(media, &media_thumbnail); + + sel_mem_info = (struct search_item_sel*)calloc(1, sizeof(struct search_item_sel)); + + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", media_id); + return true; + } + + sel_mem_info->type = obj->contents_type; + + if ((media_thumbnail) && ecore_file_exists(media_thumbnail) == EINA_TRUE) { + sel_mem_info->icon1 = strdup(media_thumbnail); + } else if (obj->obj_icon_path) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + + if (media_name && strlen(media_name)) { + sel_mem_info->text1 = strdup(search_markup_keyword(media_name, keyword, &is_word_in_str)); + } + + if (media_id) { + snprintf(media_id_str, MAX_LENGTH_PER_ID, "%s", media_id); + sel_mem_info->launch_param = strdup(media_id_str); + } + + if (media_path) { + sel_mem_info->launch_path = strdup(media_path); + } + + itc_style = ad->itc_pslist_1line_1icon; + + /* Add Info to genlist */ + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, + obj, + itc_style, + sel_mem_info, + obj->gl_result_grp); + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + + SEARCH_FREE(media_id); + SEARCH_FREE(media_name); + SEARCH_FREE(media_thumbnail); + SEARCH_FREE(media_path); + + return true; + } + +static bool __search_sql_music_info_cb(media_info_h media, void *user_data) +{ + char *media_id = NULL; + char *media_path = NULL; + char *media_thumbnail = NULL; + char *title = NULL; + char *artist = NULL; + char *album = NULL; + int ret = 0; + + audio_meta_h a_handle = NULL; + + media_content_storage_e storage_type = MEDIA_CONTENT_STORAGE_INTERNAL; + + struct search_item_sel *sel_mem_info = NULL; + Elm_Genlist_Item_Class *itc_style = NULL; + bool is_word_in_str = false; + + struct search_cb_data *scd = (struct search_cb_data*)user_data; + struct appdata *ad = NULL; + struct search_content_object *obj = NULL; + struct search_genlist_info *result_info = NULL; + char *keyword = NULL; + + struct search_genlist_item_info *gen_item = NULL; + char music_id_str[MAX_LENGTH_PER_PATH] = {0,}; + + SEARCH_RETV_IF(scd == NULL, true); + ad = scd->ad; + obj = scd->obj; + result_info = scd->result_info; + keyword = scd->keyword; + + SEARCH_RETV_IF(ad == NULL, true); + + media_info_get_media_id(media, &media_id); + media_info_get_file_path(media, &media_path); + media_info_get_storage_type(media, &storage_type); + media_info_get_thumbnail_path(media, &media_thumbnail); + + ret = media_info_get_audio(media, &a_handle); + + if(ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("Fail to get audio info!"); + return true; + } else { + ret = audio_meta_get_title(a_handle, &title); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("Fail to get title info!"); + } + + ret = audio_meta_get_album(a_handle, &album); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("Fail to get album info!"); + } + + ret = audio_meta_get_artist(a_handle, &artist); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("Fail to get artist info!"); + } + + } + + audio_meta_destroy(a_handle); + + sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel)); + + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", media_id); + return true; + } + + sel_mem_info->type = obj->contents_type;; + + if ((media_thumbnail) && ecore_file_exists(media_thumbnail) == EINA_TRUE) { + sel_mem_info->icon1 = strdup(media_thumbnail); + } else if(obj->obj_icon_path) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + + if ((title) && (strlen(title) > 0)) { + sel_mem_info->text1 = strdup(search_markup_keyword(title, keyword, &is_word_in_str)); + } + + if (is_word_in_str) { + if ((artist) && (strlen(artist) > 0)) { + sel_mem_info->text2 = strdup(search_markup_keyword(artist, keyword, &is_word_in_str)); + } + } else { + if ((artist) && (strlen(artist) > 0)) { + sel_mem_info->text2 = strdup(search_markup_keyword(artist, keyword, &is_word_in_str)); + } + + if (is_word_in_str == false && (album) && (strlen(album) > 0)) { + sel_mem_info->text2 = strdup(search_markup_keyword(album, keyword, &is_word_in_str)); + } + + if (is_word_in_str == false) { + SEARCH_DEBUG_LOG("search_result is 0. No match keyword in title,album,artist string"); + } + } + + if (storage_type == MEDIA_CONTENT_STORAGE_EXTERNAL) { + itc_style = ad->itc_pslist_2line_2icon; + sel_mem_info->icon2 = strdup(SEARCH_SDCARD_ICON); + } + else { + itc_style = ad->itc_pslist_2line_1icon; + } + + if (media_id) { + snprintf(music_id_str, MAX_LENGTH_PER_ID - 1, "%s", media_id); + sel_mem_info->launch_param = strdup(music_id_str); + } + + if (media_path) { + sel_mem_info->launch_path = strdup(media_path); + } + + /* Add Information to genlist */ + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, obj, itc_style, sel_mem_info, + obj->gl_result_grp); + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + + SEARCH_FREE(media_id); + SEARCH_FREE(media_path); + SEARCH_FREE(media_thumbnail); + SEARCH_FREE(title); + SEARCH_FREE(artist); + SEARCH_FREE(album); + + return true; + } + +static int __search_sql_media_search_result_by_api(struct search_content_object *obj, + int offset, int limit, + char *keyword, + filter_h filter, + media_info_cb func_cb, + void *data, + struct search_genlist_info *result_info, + int total_cnt) +{ + SEARCH_FUNC_START; + + struct appdata *ad = (struct appdata *)data; + struct search_cb_data scd = {obj, ad, keyword, result_info}; + + int result_cnt = 0; + int ret = 0; + int func_ret = SEARCH_RET_SEARCH_SUCCESS; + int curr_cnt = 0; + + struct search_item_more_sel *sel_mem_more = NULL; + + SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL); + + media_info_get_media_count_from_db(filter, &result_cnt); + + if (result_cnt != 0) { + /* Set group title */ + if (obj->mr_info.offset== 0) { + result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP, + obj, + ad->itc_grouptitle, + obj, + NULL); + } + + ret = media_info_foreach_media_from_db(filter, func_cb, &scd); + + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_info_foreach_media_from_db failed : %d\n", ret); + func_ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + curr_cnt = offset + result_cnt; + + /* Set more title to genlist (under 'search all') */ + if (total_cnt > curr_cnt) { + obj->mr_info.next_point = offset + result_cnt; + + sel_mem_more = + (struct search_item_more_sel *)calloc(1, + sizeof(struct search_item_more_sel)); + sel_mem_more->obj = obj; + + result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE, + obj, + ad->itc_listmore, + sel_mem_more, + obj->gl_result_grp); + } + } else { + func_ret = SEARCH_RET_SEARCH_NONE; + } + +out_func: + SEARCH_FUNC_END; + + return func_ret; +} + + +int search_sql_image_search_result_by_api(struct search_content_object *obj, + int offset, int limit, + char *keyword, + void *data, + struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + int ret = SEARCH_RET_SEARCH_SUCCESS; + int len = 0; + int total_cnt = -1; + + char *search_query = NULL; + char *escape_added_keyword = NULL; + + const char *image_query = "(MEDIA_TYPE=0 and (MEDIA_DISPLAY_NAME like \"%%%s%%\" ESCAPE (\"%s\")))"; + + SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char); + memset(escape_added_keyword, 0x0, strlen(keyword)*2+5); + search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX); + + len = strlen(escape_added_keyword) + strlen(DB_ESCAPE_CHAR) + strlen(image_query) + 1; + search_query = (char*)calloc(1, len); + + snprintf(search_query, len, image_query, escape_added_keyword, "%"); + + filter_h filter; + + ret = media_filter_create(&filter); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_create failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + ret = media_filter_set_condition(filter, search_query, MEDIA_CONTENT_COLLATE_DEFAULT); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_condition failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_DISPLAY_NAME, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_order failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; +} + + media_info_get_media_count_from_db(filter, &total_cnt); + SEARCH_DEBUG_LOG("Matched Image Total Cnt : %d", total_cnt); + + ret = media_filter_set_offset(filter, offset, limit); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + + ret = __search_sql_media_search_result_by_api(obj, + offset, + limit, + keyword, + filter, + __search_media_info_cb, + data, + result_info, + total_cnt); + +out_func: + SEARCH_FREE(search_query); + SEARCH_FREE(escape_added_keyword); + media_filter_destroy(filter); + + SEARCH_FUNC_END; + + return ret; +} + +int search_sql_video_search_result_by_api(struct search_content_object *obj, + int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + int ret = SEARCH_RET_SEARCH_SUCCESS; + int len = 0; + char *search_query = NULL; + char *escape_added_keyword = NULL; + int total_cnt = -1; + + const char *video_query = "(MEDIA_TYPE=1 and (MEDIA_DISPLAY_NAME LIKE \"%%%s%%\" ESCAPE (\"%s\")))"; + + SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char); + memset(escape_added_keyword, 0x0, strlen(keyword)*2+5); + search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX); + + len = strlen(escape_added_keyword) + strlen(DB_ESCAPE_CHAR) + strlen(video_query) + 1; + search_query = (char*)calloc(1, len); + + snprintf(search_query, len, video_query, escape_added_keyword, DB_ESCAPE_CHAR); + + filter_h filter; + + ret = media_filter_create(&filter); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_create failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + ret = media_filter_set_offset(filter, offset, limit); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + ret = media_filter_set_condition(filter, search_query, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_condition failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_DISPLAY_NAME, MEDIA_CONTENT_COLLATE_DEFAULT); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_order failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + media_info_get_media_count_from_db(filter, &total_cnt); + SEARCH_DEBUG_LOG("Matched Video Total cnt : %d", total_cnt); + + ret = media_filter_set_offset(filter, offset, limit); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + ret = __search_sql_media_search_result_by_api(obj, + offset, + limit, + keyword, + filter, + __search_media_info_cb, + data, + result_info, + total_cnt); + +out_func: + + SEARCH_FREE(search_query); + SEARCH_FREE(escape_added_keyword); + media_filter_destroy(filter); + + SEARCH_FUNC_END; + + return ret; + } + +int search_sql_music_search_result_by_api(struct search_content_object *obj, + int offset, int limit, + char *keyword, + void *data, + struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + int ret = SEARCH_RET_SEARCH_SUCCESS; + int len = 0; + char *search_query = NULL; + char *escape_added_keyword = NULL; + int total_cnt = -1; + + const char *music_query = "(MEDIA_TYPE=3 and (MEDIA_TITLE LIKE \"%%%s%%\" or MEDIA_ALBUM LIKE \"%%%s%%\" or MEDIA_ARTIST LIKE \"%%%s%%\" ESCAPE (\"%s\")))"; + + SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char); + memset(escape_added_keyword, 0x0, strlen(keyword)*2+5); + search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX); + + len = strlen(escape_added_keyword) + strlen(DB_ESCAPE_CHAR) + strlen(music_query) + 1; + search_query = (char*)calloc(1, len); + + snprintf(search_query, len, music_query, escape_added_keyword, + escape_added_keyword, escape_added_keyword, DB_ESCAPE_CHAR); + + filter_h filter; + + ret = media_filter_create(&filter); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_create failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + + + ret = media_filter_set_condition(filter, search_query, MEDIA_CONTENT_COLLATE_DEFAULT); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_condition failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_order failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + media_info_get_media_count_from_db(filter, &total_cnt); + SEARCH_DEBUG_LOG("Matched Music Total cnt : %d", total_cnt); + + ret = media_filter_set_offset(filter, offset, limit); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + ret = __search_sql_media_search_result_by_api(obj, + offset, + limit, + keyword, + filter, + __search_sql_music_info_cb, + data, + result_info, + total_cnt); + +out_func: + + SEARCH_FREE(search_query); + SEARCH_FREE(escape_added_keyword); + media_filter_destroy(filter); + + SEARCH_FUNC_END; + + return ret; +} + +ail_cb_ret_e __search_sql_menu_search_result_cb( + const ail_appinfo_h appinfo, + void *data) +{ + SEARCH_FUNC_START; + + struct search_cb_data *scd = (struct search_cb_data*)data; + struct appdata *ad = scd->ad; + struct search_content_object* obj = scd->obj; + struct search_genlist_info *result_info = scd->result_info; + char *keyword = scd->keyword; + + struct search_genlist_item_info *gen_item = NULL; + struct search_item_sel *sel_mem_info = NULL; + struct search_item_more_sel *sel_mem_more = NULL; + + bool is_word_in_str; + ail_cb_ret_e ret; + + if (obj->mr_info.loop_cnt < obj->mr_info.next_point) { + obj->mr_info.loop_cnt++; + return AIL_CB_RET_CONTINUE; + } + + if(obj->mr_info.next_point < + obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) { + + sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel)); + + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", obj->mr_info.loop_cnt); + return AIL_CB_RET_CONTINUE; + } + + sel_mem_info->type = obj->contents_type;; + + /********** START : set search result to sel_mem_info buf ************/ + + char *name = NULL; + char *package = NULL; + char *icon = NULL; + + ail_appinfo_get_str(appinfo, AIL_PROP_ICON_STR, &icon); + + if (icon) { + sel_mem_info->icon1 = strdup(icon); + } + + ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package); + if ((package) && (strlen(package) > 0)) { + + if(strcmp(package, "org.tizen.smartsearch") == 0) { + SEARCH_DEBUG_LOG("'smartsearch' does not appended"); + obj->mr_info.loop_cnt++; + obj->mr_info.next_point++; + SEARCH_FREE(sel_mem_info); + return AIL_CB_RET_CONTINUE; + } + + sel_mem_info->launch_path = strdup(package); + } else { + SEARCH_DEBUG_WARNING("package : null"); + } + + ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &name); + if ((name) && (strlen(name) > 0)) { + sel_mem_info->text1 = strdup(search_markup_keyword(name, keyword, &is_word_in_str)); + } else { + SEARCH_DEBUG_WARNING("name : null"); +} + + if(obj->mr_info.next_point == 0) { + /* Set group title */ + result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP, + obj, + ad->itc_grouptitle, + obj, + NULL); + } + + /********** END : set search result to sel_mem_info buf *************/ + + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, + obj, + ad->itc_pslist_1line_1icon, + sel_mem_info, + obj->gl_result_grp); + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + obj->mr_info.next_point++; + obj->mr_info.loop_cnt++; + + ret = AIL_CB_RET_CONTINUE; + + } else if (obj->mr_info.next_point == + obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) { + + /* Check that only "SMARTSEARCH" is left in more result */ + if(obj->mr_info.next_point == obj->mr_info.result_cnt-1) { + + char *package = NULL; + + ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package); + if ((package) && (strlen(package) > 0) && (strcmp(package, "org.tizen.smartsearch") == 0)) { + SEARCH_DEBUG_LOG("Only 'SMARTSEARCH' is left in more result"); + return AIL_CB_RET_CANCEL; + } + } + + /* Set more title to genlist (under 'search all') */ + sel_mem_more = (struct search_item_more_sel *)calloc(1, sizeof(struct search_item_more_sel)); + sel_mem_more->obj = obj; + + result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE, + obj, + ad->itc_listmore, + sel_mem_more, + obj->gl_result_grp); + + ret = AIL_CB_RET_CANCEL; + } else { + SEARCH_DEBUG_WARNING + ("__search_sql_menu_search_result_cb wrong index : %d", + obj->mr_info.next_point); + + ret = AIL_CB_RET_CANCEL; + } + + SEARCH_FUNC_END; + + return ret; +} + +int search_sql_menu_search_result_by_api(struct search_content_object *obj, + int offset, int limit, + char *keyword, + void *data, + struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + struct appdata *ad = (struct appdata *)data; + struct search_cb_data scd = {obj, ad, keyword, result_info}; + + int cnt = 0; + int ret = 0; + + ail_filter_h filter = NULL; + ail_error_e rc; + + char *escape_added_keyword = NULL; + SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char); + memset(escape_added_keyword, 0x0, strlen(keyword)*2+5); + search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX); + + rc = ail_filter_new(&filter); + if (rc != AIL_ERROR_OK) { + SEARCH_DEBUG_WARNING("menu search - ail_filter_new error : %d", rc); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + rc = ail_filter_add_str(filter, AIL_PROP_NAME_STR, escape_added_keyword); + if (rc != AIL_ERROR_OK) { + SEARCH_DEBUG_WARNING("menu search - ail_filter_add_str error : %d", rc); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + rc = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false); + if (rc != AIL_ERROR_OK) { + SEARCH_DEBUG_WARNING("menu search - ail_filter_add_bool error : %d", rc); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + rc = ail_filter_count_appinfo(filter, &cnt); + if( rc != AIL_ERROR_OK) { + SEARCH_DEBUG_WARNING("menu search - ail_filter_count_appinfo error : %d", rc); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + SEARCH_DEBUG_LOG("ail search result : %d", cnt); + obj->mr_info.result_cnt = cnt; + + if(cnt > 0) { + obj->mr_info.loop_cnt = 0; + rc = ail_filter_list_appinfo_foreach(filter, __search_sql_menu_search_result_cb, &scd); + if( rc != AIL_ERROR_OK) { + SEARCH_DEBUG_WARNING("menu search - ail_filter_list_appinfo_foreach error : %d", rc); + ret = SEARCH_RET_SEARCH_FAIL; + goto out_func; + } + + if (obj->mr_info.next_point == 0) { + ret = SEARCH_RET_SEARCH_NONE; + } else { + ret = SEARCH_RET_SEARCH_SUCCESS; + } + } else { + ret = SEARCH_RET_SEARCH_NONE; + } + +out_func: + if (filter) { + ail_filter_destroy(filter); + } + + SEARCH_FREE(escape_added_keyword); + SEARCH_FUNC_END; + + return ret; +} + +bool __search_sql_browser_bookmark_result_cb(favorites_bookmark_entry_s *item, void *user_data) +{ + SEARCH_FUNC_START; + struct search_item_sel *sel_mem_info = NULL; + + bool ret = false; + bool is_word_in_str_main = false; + bool is_word_in_str_sub = false; + + char* match_str_title = NULL; + char* match_str_addr = NULL; + + struct search_cb_data_browser *scd = (struct search_cb_data_browser*)user_data; + struct appdata *ad = scd->ad; + struct search_content_object *obj = scd->obj; + struct search_genlist_info *result_info = scd->result_info; + char *keyword = scd->keyword; + + struct search_genlist_item_info *gen_item = NULL; + struct search_more_result *info = scd->info; + + if (info->loop_cnt < info->next_point) { + info->loop_cnt++; + return true; + } + + if (info->next_point < info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) { + char bookmark_id_str[MAX_LENGTH_PER_PATH] = {0,}; + + /********** START : set search result to sel_mem_info buf ************/ + + if (item != NULL && item->title) { + match_str_title = strdup(search_markup_keyword(item->title, keyword, &is_word_in_str_main)); + } + + if (item != NULL && item->address) { + match_str_addr = strdup(search_markup_keyword(item->address, keyword, &is_word_in_str_sub)); + } + + if (is_word_in_str_main == true || is_word_in_str_sub == true) { + if (obj->gl_result_grp == NULL && result_info->group == NULL) { + /* Set group title */ + result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP, + obj, + ad->itc_grouptitle, + obj, + NULL); + } + + sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel)); + + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", info->loop_cnt); + return true; + } + + sel_mem_info->type = obj->contents_type; + snprintf(bookmark_id_str, MAX_LENGTH_PER_ID - 1, "%d", item->id); + sel_mem_info->launch_param = strdup(bookmark_id_str); + + if (match_str_title) { + sel_mem_info->text1 = strdup(match_str_title); + } + + if (match_str_addr) { + sel_mem_info->text2 = strdup(match_str_addr); + sel_mem_info->launch_path= strdup(item->address); + } + + if (obj->obj_icon_path) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + + sel_mem_info->icon2 = strdup(SEARCH_FAVORITE_ICON); + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, + obj, + ad->itc_pslist_2line_2icon_browser_bookmark, + sel_mem_info, + obj->gl_result_grp); + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + scd->search_ret = true; + } + + SEARCH_FREE(match_str_title); + SEARCH_FREE(match_str_addr); + + /********** END : set search result to sel_mem_info buf *************/ + info->next_point++; + info->loop_cnt++; + + ret = true; + } else if (info->next_point == + info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) { + info->offset = info->next_point; + ret = false; + } else { + SEARCH_DEBUG_WARNING + ("__search_sql_browser_bookmark_result_cb wrong index : %d", + info->next_point); + + ret = false; + } + SEARCH_FUNC_END; + return ret; + +} + +bool __search_sql_browser_history_result_cb(favorites_history_entry_s *item, void *user_data) +{ + SEARCH_FUNC_START; + struct search_item_sel *sel_mem_info = NULL; + + bool ret = false; + bool is_word_in_str_main = false; + + const char* match_str = NULL; + + struct search_cb_data_browser *scd = (struct search_cb_data_browser*)user_data; + struct appdata *ad = scd->ad; + struct search_content_object *obj = scd->obj; + struct search_genlist_info *result_info = scd->result_info; + char *keyword = scd->keyword; + + struct search_more_result *info = scd->info; + struct search_genlist_item_info *gen_item = NULL; + + if (info->loop_cnt < info->next_point) { + info->loop_cnt++; + return true; + } + + if (info->next_point < info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) { + char history_id_str[MAX_LENGTH_PER_PATH] = {0,}; + + /********** START : set search result to sel_mem_info buf ************/ + + if (item != NULL && item->address) { + match_str = search_markup_keyword(item->address, keyword, &is_word_in_str_main); + } + + if (is_word_in_str_main != false ) { + if (obj->gl_result_grp == NULL && result_info->group == NULL ) { + /* Set group title */ + result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP, + obj, + ad->itc_grouptitle, + obj, + NULL); + } + + sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel)); + + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", info->loop_cnt); + return true; + } + + sel_mem_info->type = obj->contents_type; + snprintf(history_id_str, MAX_LENGTH_PER_ID - 1, "%d", item->id); + sel_mem_info->launch_param = strdup(history_id_str); + + if (obj->obj_icon_path) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + + if (item->address) { + sel_mem_info->launch_path = strdup(item->address); + } + + sel_mem_info->text1 = strdup(match_str); + + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, + obj, + ad->itc_pslist_1line_1icon_browser_history, + sel_mem_info, + obj->gl_result_grp); + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + scd->search_ret = true; + } + + info->next_point++; + info->loop_cnt++; + + ret = true; + + } else if (info->next_point == + info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) { + info->offset = info->next_point; + ret = false; + } else { + SEARCH_DEBUG_WARNING + ("__search_sql_browser_history_result_cb wrong index : %d", + info->next_point); + + ret = false; + } + + SEARCH_FUNC_END; + return ret; +} + +int search_sql_browser_search_result_by_api(struct search_content_object *obj, + int offset, int limit, + char *keyword, + void *data, + struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + struct appdata *ad = (struct appdata *)data; + struct search_cb_data_browser scd_browser = {obj, ad, keyword, result_info, NULL, false}; + struct search_cb_data_browser scd_history = {obj, ad, keyword, result_info, NULL, false}; + + static struct search_more_result browser_result[2]; + struct search_item_more_sel *sel_mem_more = NULL; + + int ret = 0; + int bookmark_cnt = 0, history_cnt = 0; + int bookmark_ret = 0, history_ret = 0; + + if (offset == 0) { + /* offset 0 means first search result, so we initialize struct */ + memset(browser_result, 0x0, sizeof(browser_result)); + + favorites_bookmark_get_count(&browser_result[0].result_cnt); + favorites_history_get_count(&browser_result[1].result_cnt); + + bookmark_cnt = browser_result[0].result_cnt; + history_cnt = browser_result[1].result_cnt; + browser_result[0].ad = browser_result[1].ad = ad; + obj->gl_result_grp = NULL; + + if ( bookmark_cnt <= 0 && history_cnt <= 0 ) + return SEARCH_RET_SEARCH_NONE; + } else { + bookmark_cnt = browser_result[0].result_cnt; + history_cnt = browser_result[1].result_cnt; + browser_result[0].loop_cnt = 0; + browser_result[1].loop_cnt = 0; + } + + if (offset >= bookmark_cnt + history_cnt) { + /* We need not to search */ + return SEARCH_RET_SEARCH_NONE; + } + + scd_browser.info = &browser_result[0]; + scd_history.info = &browser_result[1]; + + /* offset check */ + if (bookmark_cnt > browser_result[0].next_point ) + bookmark_ret = favorites_bookmark_foreach(__search_sql_browser_bookmark_result_cb, + &scd_browser); + if (history_cnt > browser_result[1].next_point && g_list_length(result_info->itemlist) < SEARCH_CATEGORY_LIST_MORE_CNT) + history_ret = favorites_history_foreach(__search_sql_browser_history_result_cb, + &scd_history); + + if (bookmark_ret == FAVORITES_ERROR_DB_FAILED + && history_ret == FAVORITES_ERROR_DB_FAILED ) { + ret = SEARCH_RET_SEARCH_FAIL; + } + else if (scd_browser.search_ret == false && scd_history.search_ret == false){ + /* It means we can't get matched results */ + ret = SEARCH_RET_SEARCH_NONE; + } + else { + /* Make More button */ + if (browser_result[0].next_point < bookmark_cnt + || browser_result[1].next_point < history_cnt) { + sel_mem_more = (struct search_item_more_sel *)calloc(1, sizeof(struct search_item_more_sel)); + sel_mem_more->obj = obj; + + result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE, + obj, + ad->itc_listmore, + sel_mem_more, + obj->gl_result_grp); + } + + /* return check */ + obj->mr_info.next_point = browser_result[0].next_point + + browser_result[1].next_point; + ret = SEARCH_RET_SEARCH_SUCCESS; + } + + SEARCH_FUNC_END; + + return ret; +} + +int search_sql_msg_search_result_by_api(struct search_content_object *obj, + int offset, int limit, + char *keyword, + void *data, + struct search_genlist_info *result_info) +{ + SEARCH_FUNC_START; + + int ret = SEARCH_RET_SEARCH_FAIL; + + struct search_item_sel *sel_mem_info = NULL; + struct search_item_more_sel *sel_mem_more = NULL; + struct appdata *ad = (struct appdata *)data; + struct search_genlist_item_info *gen_item = NULL; + + bool is_word_in_str; + + int i = 0; + int j = 0; + bool is_word_in_title = false; + + msg_error_t err = MSG_SUCCESS; + + msg_struct_list_s total_msgList; + msg_struct_list_s msgList; + msg_struct_t search_s = NULL; + msg_struct_list_s *addr_list = NULL; + + search_s = msg_create_struct(MSG_STRUCT_SEARCH_CONDITION); + + err = msg_set_int_value(search_s, MSG_SEARCH_CONDITION_FOLDERID_INT, MSG_ALLBOX_ID); + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_SEARCH_CONDITION_FOLDERID_INT"); + goto out_func; + }; + + err = msg_set_int_value(search_s, MSG_SEARCH_CONDITION_MSGTYPE_INT, MSG_TYPE_INVALID); + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_SEARCH_CONDITION_MSGTYPE_INT"); + goto out_func; + } + + err = msg_set_str_value(search_s, MSG_SEARCH_CONDITION_SEARCH_VALUE_STR, keyword, strlen(keyword)); + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_SEARCH_CONDITION_SEARCH_VALUE_STR"); + goto out_func; + } + + err = msg_search_message(ad->msg_handle, search_s, 0, 0, &total_msgList); + if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) { + SEARCH_DEBUG_WARNING("msg_search_message is failed : %d", err); + goto out_func; + } + + err = msg_search_message(ad->msg_handle, search_s, offset, limit, &msgList); + + if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) { + SEARCH_DEBUG_WARNING("msg_search_message is failed : %d", err); + goto out_func; + } + + SEARCH_DEBUG_LOG("Matched Total Message : %d", total_msgList.nCount); + SEARCH_DEBUG_LOG("Message Count : %d", msgList.nCount); + + if (msgList.nCount <= 0) { + SEARCH_DEBUG_WARNING("no msg search result"); + ret = SEARCH_RET_SEARCH_NONE; + } else { + + /* Set group title */ + if (offset == 0) { + /* Set group title */ + result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP, + obj, + ad->itc_grouptitle, + obj, + NULL); + } + + /********** START : set search result to sel_mem_info buf ************/ + + for (i = 0; i < msgList.nCount; i++) { + const char *text_1line = NULL; + const char *markup_keyword = NULL; + char *img_path = NULL; + + int msg_type = 0; + int contact_id = -1; + int message_id = -1; + + char subject[MAX_SUBJECT_LEN] = {0}; + char str_number[MAX_ADDRESS_VAL_LEN] = {0,}; + char str_name[MAX_DISPLAY_NAME_LEN] = {0,}; + char msg_text[MAX_MSG_TEXT_LEN] = {0,}; + char msg_id_str[MAX_LENGTH_PER_PATH] = {0,}; + + err = msg_get_int_value(msgList.msg_struct_info[i], MSG_MESSAGE_TYPE_INT, &msg_type); + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_MESSAGE_TYPE_INT %d", err); + goto out_func; + } + + SEARCH_DEBUG_LOG("mms : %d", msg_type); + + + sel_mem_info = (struct search_item_sel *)calloc(1,sizeof(struct search_item_sel)); + if (!sel_mem_info) { + SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", i); + return true; + } + + sel_mem_info->type = obj->contents_type;; + + err = msg_get_int_value(msgList.msg_struct_info[i], MSG_MESSAGE_ID_INT, &message_id); + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_MESSAGE_ID_INT %d", err); + goto out_func; + } + + snprintf(msg_id_str, MAX_LENGTH_PER_ID - 1, "%d", message_id); + sel_mem_info->launch_param= strdup(msg_id_str); + + /* Set 1st line string */ + if (msg_type == MSG_TYPE_MMS || msg_type == MSG_TYPE_MMS_JAVA || msg_type == MSG_TYPE_MMS_NOTI) { + /* MMS case */ + err = msg_get_str_value(msgList.msg_struct_info[i], MSG_MESSAGE_SUBJECT_STR, + subject, MAX_SUBJECT_LEN); + + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to get sms context %d", err); + goto out_func; + } + + text_1line = subject; + markup_keyword = search_markup_keyword(text_1line, keyword,&is_word_in_title); + + if (!is_word_in_title) { + memset(msg_text, 0x00, sizeof(msg_text)); + err = msg_get_str_value(msgList.msg_struct_info[i], + MSG_MESSAGE_MMS_TEXT_STR, + msg_text, + sizeof(msg_text)); + + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to get mms context %d", err); + goto out_func; + } + + text_1line = msg_text; + + markup_keyword = search_markup_keyword(text_1line, + keyword, + &is_word_in_title); + } + + if ((text_1line) && (strlen(text_1line) > 0 )) { + sel_mem_info->text1 = strdup(markup_keyword); + } else { + sel_mem_info->text1 = strdup("Unknown"); + } + } else if(msg_type == MSG_TYPE_SMS) { + /* SMS Case */ + err = msg_get_str_value(msgList.msg_struct_info[i], + MSG_MESSAGE_SMS_DATA_STR, + msg_text, + sizeof(msg_text)); + + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to get sms context %d", err); + goto out_func; + } + + text_1line = msg_text; + + markup_keyword = search_markup_keyword(text_1line, + keyword, + &is_word_in_title); + SEARCH_DEBUG_LOG("1st string : %s", text_1line); + + if ((text_1line) && (strlen(text_1line) > 0)) { + sel_mem_info->text1 = strdup(markup_keyword); + } + } + + err = msg_get_list_handle(msgList.msg_struct_info[i], + MSG_MESSAGE_ADDR_LIST_STRUCT, + (void **)&addr_list); + + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to get address list handle! %d", err); + goto out_func; + } + + /* Set 2nd line string */ + for ( j=0; j<addr_list->nCount; j++) { + memset(str_number, 0, sizeof(str_number)); + memset(str_name, 0, sizeof(str_name)); + contact_id = -1; + is_word_in_str = false; + + /* First We set text_2line to first address data */ + err = msg_get_str_value(addr_list->msg_struct_info[j], + MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, + str_number, + MAX_ADDRESS_VAL_LEN); + + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to get data! : MSG_ADDRESS_INFO_DISPLAYNAME_STR %d", err); + goto out_func; + } + + err = msg_get_str_value(addr_list->msg_struct_info[j], + MSG_ADDRESS_INFO_DISPLAYNAME_STR, + str_name, + MAX_DISPLAY_NAME_LEN); + + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to get data! : MSG_ADDRESS_INFO_ADDRESS_VALUE_STR %d", err); + goto out_func; + } + + err = msg_get_int_value(addr_list->msg_struct_info[j], + MSG_ADDRESS_INFO_CONTACT_ID_INT, + &contact_id); + + if (err != MSG_SUCCESS) { + SEARCH_DEBUG_WARNING("Fail to get data! : MSG_ADDRESS_INFO_CONTACT_ID_INT %d", err); + goto out_func; + } + + /* Set text_2line */ + markup_keyword = search_markup_keyword(str_number, keyword, &is_word_in_str); + + if (strlen(str_name) > 0) { + sel_mem_info->text2 = strdup(str_name); + } else if(strlen(str_number) > 0) { + sel_mem_info->text2 = strdup(markup_keyword); + } else { + sel_mem_info->text2 = strdup("Unknown"); + } + + /* Check Whether Thumbnail Image exist or not */ + if (contact_id > -1) { + contacts_query_h query = NULL; + contacts_filter_h filter = NULL; + contacts_list_h list = NULL; + + unsigned int count = 0; + ret = contacts_connect2(); + + if (ret != CONTACTS_ERROR_NONE) { + SEARCH_DEBUG_WARNING("Fail to connect contact service!"); + if (obj->obj_icon_path != NULL) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + continue; + } else { + contacts_query_create(_contacts_person_number._uri, &query); + contacts_filter_create(_contacts_person_number._uri, &filter); + contacts_filter_add_int(filter, _contacts_person.id, CONTACTS_MATCH_EQUAL, + contact_id); + contacts_query_set_filter(query, filter); + contacts_db_get_records_with_query(query, 0, 0, &list); + contacts_list_get_count(list, &count); + + if (count > 0) { + contacts_record_h record; + contacts_list_get_current_record_p(list, &record); + contacts_record_get_str_p(record, _contacts_person.image_thumbnail_path, &img_path); + } + + if (img_path != NULL) { + sel_mem_info->icon1 = strdup(img_path); + } else if (obj->obj_icon_path != NULL) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + if (filter) { + contacts_filter_destroy(filter); + } + + if (query) { + contacts_query_destroy(query); + } + if (list) { + contacts_list_destroy(list, true); + } + + ret = contacts_disconnect2(); + } + } else { + if (obj->obj_icon_path) { + sel_mem_info->icon1 = strdup(obj->obj_icon_path); + } + } + + if ((is_word_in_title) || (is_word_in_str)) { + break; + } + } + + gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, + obj, + ad->itc_pslist_2line_1icon, + sel_mem_info, + obj->gl_result_grp); + + result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item); + } + + msg_release_list_struct(&msgList); + msg_release_list_struct(&total_msgList); + + /* Set more title to genlist (under 'search all') */ + if (total_msgList.nCount > offset + i) { + obj->mr_info.next_point = offset + i; + + sel_mem_more = (struct search_item_more_sel *) + calloc(1,sizeof(struct search_item_more_sel)); + sel_mem_more->obj = obj; + + result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE, + obj, + ad->itc_listmore, + sel_mem_more, + obj->gl_result_grp); + } + + ret = SEARCH_RET_SEARCH_SUCCESS; + } + +out_func: + if (search_s != NULL) { + msg_release_struct(&search_s); + } + SEARCH_FUNC_END; + return ret; +} + +void search_sql_update_result_object(struct search_content_object* result_obj, sqlite3* db_handle, sqlite3_stmt** db_sql) +{ + SEARCH_FUNC_START; + + int rc = 0; + + sqlite3_stmt *sql_stmt = db_sql[SEARCH_STMT_UPDATE_OBJECT_INFO]; + SEARCH_RET_IF(sql_stmt==NULL); + + search_sql_bind_text(db_handle, sql_stmt, 1, result_obj->name); + search_sql_bind_int(db_handle, sql_stmt, 2, result_obj->string_type); + search_sql_bind_int(db_handle, sql_stmt, 3, result_obj->visible); + search_sql_bind_int(db_handle, sql_stmt, 4, result_obj->order); + search_sql_bind_int(db_handle, sql_stmt, 5, result_obj->contents_type); + search_sql_bind_int(db_handle, sql_stmt, 6, result_obj->category_type); + search_sql_bind_text(db_handle, sql_stmt, 7, result_obj->def_pkg_name); + search_sql_bind_int(db_handle, sql_stmt, 8, result_obj->contents_type); + + rc = sqlite3_step(sql_stmt); + + if (rc == SQLITE_OK) + SEARCH_DEBUG_LOG("INSERT STEP SUCCESS"); + + search_sql_stmt_init(sql_stmt); + + SEARCH_FUNC_END; + +} |