2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include "smartsearch.h"
26 #include <contacts-svc.h>
27 #include <calendar-svc-provider.h>
30 #include <email-api-mail.h>
32 #include <favorites.h>
33 #include <media_content.h>
35 #include <msg_storage.h>
36 #include <msg_storage_types.h>
40 #include <unicode/ucal.h>
41 #include <unicode/ustring.h>
42 #include <unicode/ustdio.h>
43 #include <unicode/udat.h>
45 char* g_keyword = NULL;
47 struct search_cb_data {
48 struct search_content_object *obj;
51 struct search_genlist_info *result_info;
54 struct search_cb_data_browser {
55 struct search_content_object *obj;
58 struct search_genlist_info *result_info;
59 struct search_more_result *info;
62 struct media_cb_data {
67 int search_sql_stmt_init(sqlite3_stmt * sql_stmt)
73 rc = sqlite3_clear_bindings(sql_stmt);
74 if (rc != SQLITE_OK) {
75 SEARCH_DEBUG_ERROR("sqlite3_clear_bindings error");
76 return SEARCH_RET_FAIL;
79 rc = sqlite3_reset(sql_stmt);
80 if (rc != SQLITE_OK) {
81 SEARCH_DEBUG_ERROR("sqlite3_reset error");
82 return SEARCH_RET_FAIL;
87 return SEARCH_RET_SUCCESS;
90 int search_sql_stmt_finalize(sqlite3_stmt * stmt)
96 ret = sqlite3_finalize(stmt);
97 if (ret != SQLITE_OK) {
98 SEARCH_DEBUG_ERROR("sqlite3_finalize error : %d ", ret);
107 int search_sql_prepare_stmt(sqlite3 *db_handle, const char *query,
108 sqlite3_stmt ** stmt_out)
115 rc = sqlite3_prepare(db_handle, query, strlen(query), stmt_out, NULL);
116 if (rc != SQLITE_OK) {
117 SEARCH_DEBUG_ERROR("sql preapre error : %d / %s", rc, query);
118 ret = SEARCH_RET_FAIL;
120 ret = SEARCH_RET_SUCCESS;
128 int search_sql_bind_text(sqlite3* db_handle, sqlite3_stmt *sql_stmt, int col, char *data)
131 int ret = SEARCH_RET_SEARCH_NONE;
133 rc = sqlite3_bind_text(sql_stmt, col, data, strlen(data), SQLITE_STATIC);
134 if (rc != SQLITE_OK) {
135 SEARCH_DEBUG_ERROR("SQL BIND TEXT ERROR : %s(%d) / %s\n",
136 sqlite3_errmsg(db_handle),
139 ret = SEARCH_RET_SEARCH_FAIL;
145 int search_sql_bind_int(sqlite3* db_handle, sqlite3_stmt *sql_stmt, int col, int data)
148 int ret = SEARCH_RET_SEARCH_NONE;
150 rc = sqlite3_bind_int(sql_stmt, col, data);
151 if (rc != SQLITE_OK) {
152 SEARCH_DEBUG_ERROR("SQL BIND INT ERROR : %s(%d) / %d\n",
153 sqlite3_errmsg(db_handle),
156 ret = SEARCH_RET_SEARCH_FAIL;
161 static int __search_sql_contact_search_result_cb(CTSvalue * value,
166 struct search_cb_data *scd = (struct search_cb_data*)user_data;
168 struct appdata *ad = scd->ad;
169 struct search_content_object* obj = scd->obj;
170 struct search_genlist_info *result_info = scd->result_info;
171 char *keyword = scd->keyword;
173 struct search_item_sel *sel_mem_info = NULL;
174 struct search_item_more_sel *sel_mem_more = NULL;
175 struct search_genlist_item_info *gen_item = NULL;
177 const char* contact_img_path = NULL;
178 char display_name[128] = { 0, };
179 const char *first, *last, *display, *number;
183 if (obj->mr_info.next_point == 0) {
184 //### Set group title
185 result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
192 if (obj->mr_info.next_point <
193 obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
195 (struct search_item_sel *)calloc(1,
198 sel_mem_info->type = obj->contents_type;
200 contact_img_path = contacts_svc_value_get_str(value,
201 CTS_LIST_NUM_CONTACT_IMG_PATH_STR);
203 if (contact_img_path != NULL) {
204 strncpy(sel_mem_info->icon1_path, contact_img_path,
205 MAX_LENGTH_PER_PATH - 1);
207 else if (obj->obj_icon_path)
208 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
209 MAX_LENGTH_PER_PATH - 1);
211 /************ START : set search result to sel_mem_info buf ************/
213 /***********************************************************************/
215 memset(display_name, 0x00, sizeof(display_name));
218 contacts_svc_value_get_str(value,
219 CTS_LIST_NUM_CONTACT_DISPLAY_STR);
222 snprintf(display_name, sizeof(display_name), "%s",
226 contacts_svc_value_get_str(value,
227 CTS_LIST_NUM_CONTACT_FIRST_STR);
229 contacts_svc_value_get_str(value,
230 CTS_LIST_NUM_CONTACT_LAST_STR);
232 if (CTS_ORDER_NAME_FIRSTLAST ==
233 contacts_svc_get_order(CTS_ORDER_OF_DISPLAY)) {
236 snprintf(display_name,
237 sizeof(display_name),
238 "%s %s", first, last);
240 snprintf(display_name,
241 sizeof(display_name),
246 snprintf(display_name,
247 sizeof(display_name),
254 snprintf(display_name,
255 sizeof(display_name),
256 "%s %s", last, first);
258 snprintf(display_name,
259 sizeof(display_name),
264 snprintf(display_name,
265 sizeof(display_name),
272 SEARCH_DEBUG_LOG("display_name : %s", display_name);
274 if(strlen(display_name) > 0) {
275 strncpy(sel_mem_info->main_buf,
276 search_markup_keyword(display_name, keyword, &is_word_in_str),
277 MAX_LENGTH_PER_LINE - 1);
280 /***********************************************************************/
282 number = contacts_svc_value_get_str(value, CTS_LIST_NUM_NUMBER_STR);
284 if((number) && strlen(number) > 0) {
285 strncpy(sel_mem_info->sub_buf,
286 search_markup_keyword(number, keyword, &is_word_in_str),
287 MAX_LENGTH_PER_LINE - 1);
290 /***********************************************************************/
292 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID - 1, "%d",
293 contacts_svc_value_get_int(value,
294 CTS_LIST_NUM_CONTACT_ID_INT));
295 SEARCH_DEBUG_LOG("Search CT_ID: %d", sel_mem_info->main_id);
296 /***********************************************************************/
297 /************ END : set search result to sel_mem_info buf **************/
298 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
300 ad->itc_pslist_2line_1icon,
303 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
304 obj->mr_info.next_point++;
305 } else if (obj->mr_info.next_point ==
306 obj->mr_info.offset +
307 SEARCH_CATEGORY_LIST_MORE_CNT) {
308 /* Set more title to genlist (under 'search all') */
310 (struct search_item_more_sel *)calloc(1,
312 search_item_more_sel));
313 sel_mem_more->obj = obj;
315 result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
322 ("__search_sql_contact_search_result_cb wrong index : %d",
323 obj->mr_info.next_point);
331 int search_sql_contact_search_result_by_api(struct search_content_object *obj,
332 int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
336 struct appdata *ad = (struct appdata *)data;
337 struct search_cb_data scd = {obj, ad, keyword, result_info};
341 /* Check whether search result is exist or not */
343 contacts_svc_smartsearch_excl(keyword, limit, offset,
344 __search_sql_contact_search_result_cb,
346 if (ret != CTS_SUCCESS) {
347 SEARCH_DEBUG_WARNING("contacts svc search return error : %d",
349 return SEARCH_RET_SEARCH_FAIL;
352 if (obj->mr_info.next_point == 0) {
353 SEARCH_DEBUG_WARNING("contacts svc search no result");
354 return SEARCH_RET_SEARCH_NONE;
359 return SEARCH_RET_SEARCH_SUCCESS;
362 int search_sql_calendar_search_result_by_api(struct search_content_object *obj,
363 int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
368 struct appdata *ad = (struct appdata *)data;
370 cal_struct *event = NULL;
371 cal_iter *iter = NULL;
373 struct search_item_sel *sel_mem_info = NULL;
374 struct search_item_more_sel *sel_mem_more = NULL;
375 struct search_genlist_item_info *gen_item = NULL;
379 char *summary = NULL;
384 long long int start_time = 0;
385 UErrorCode status = U_ZERO_ERROR;
387 int y = 0, m = 0, d = 0;
389 ret = calendar_svc_smartsearch_excl(keyword, offset, limit, &iter);
391 if (ret == CAL_SUCCESS) {
392 ret = calendar_svc_iter_next(iter);
393 if (ret != CAL_SUCCESS) {
395 ("calendar svc search no result : %d", ret);
396 return SEARCH_RET_SEARCH_NONE;
398 /* Set group title */
400 result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
406 /* Set search result to genlist */
410 if (loop_cnt == limit) {
413 /********** START : set search result to sel_mem_info buf ************/
415 ret = calendar_svc_iter_get_info(iter, &event);
417 if (ret == CAL_SUCCESS) {
419 (struct search_item_sel *)calloc(1,
423 sel_mem_info->type = obj->contents_type;
425 if (obj->obj_icon_path)
426 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
427 MAX_LENGTH_PER_PATH - 1);
430 calendar_svc_struct_get_str(event,
431 CAL_VALUE_TXT_SUMMARY);
433 if ((summary) && (strlen(summary) > 0)) {
434 strncpy(sel_mem_info->main_buf,
435 search_markup_keyword(summary,
438 MAX_LENGTH_PER_LINE - 1);
441 snprintf(sel_mem_info->main_id,
442 MAX_LENGTH_PER_ID - 1, "%d",
443 calendar_svc_struct_get_int(event,
444 CAL_VALUE_INT_INDEX));
446 time_type = calendar_svc_struct_get_int(event, CALS_VALUE_INT_DTSTART_TYPE);
448 if (time_type == CALS_TIME_LOCALTIME) {
449 y = calendar_svc_struct_get_int(event, CALS_VALUE_INT_DTSTART_YEAR);
450 m = calendar_svc_struct_get_int(event, CALS_VALUE_INT_DTSTART_MONTH);
451 d = calendar_svc_struct_get_int(event, CALS_VALUE_INT_DTSTART_MDAY);
452 } else if (time_type == CALS_TIME_UTIME) {
453 start_time = calendar_svc_struct_get_lli(event,
454 CALS_VALUE_LLI_DTEND_UTIME);
456 _tzid = (UChar *)malloc(sizeof(UChar) * (strlen("Europe/Berlin") + 1));
457 if (_tzid) u_uastrcpy(_tzid, "Europe/Berlin");
459 cal = ucal_open(_tzid, u_strlen(_tzid), "en_US", UCAL_TRADITIONAL, &status);
460 ucal_setMillis(cal, (double)(start_time * 1000.0), &status);
461 y = ucal_get(cal, UCAL_YEAR, &status);
462 m = ucal_get(cal, UCAL_MONTH, &status);
463 d = ucal_get(cal, UCAL_DATE, &status);
466 snprintf(sel_mem_info->sub_buf, MAX_LENGTH_PER_LINE, "%d.%d.%d", y,m,d);
468 calendar_svc_struct_free(&event);
471 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
473 ad->itc_pslist_2line_1icon,
476 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
479 ("calendar_svc_iter_get_info fail : %d",
485 while (calendar_svc_iter_next(iter) == CAL_SUCCESS);
487 SEARCH_DEBUG_WARNING("calendar_svc_search_list fail : %d", ret);
488 return SEARCH_RET_SEARCH_FAIL;
491 /* Set more title to genlist (under 'search all') */
492 if (loop_cnt == limit) {
493 obj->mr_info.next_point = offset + limit - 1;
496 (struct search_item_more_sel *)calloc(1,
498 search_item_more_sel));
499 sel_mem_more->obj = obj;
501 result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
509 return SEARCH_RET_SEARCH_SUCCESS;
512 static void __search_sql_memo_search_result_cb(memo_data_t * value,
517 struct search_cb_data *scd = (struct search_cb_data *)user_data;
518 struct appdata *ad = scd->ad;
519 struct search_content_object *obj = scd->obj;
520 struct search_genlist_info *result_info = scd->result_info;
522 struct search_genlist_item_info *gen_item = NULL;
523 struct search_item_sel *sel_mem_info = NULL;
524 struct search_item_more_sel *sel_mem_more = NULL;
526 char *keyword = scd->keyword;
531 SEARCH_DEBUG_WARNING("memo data value is null");
535 if (obj->mr_info.next_point == 0) {
536 /* Set group title */
537 result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
544 if (obj->mr_info.next_point <
545 obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
547 (struct search_item_sel *)calloc(1,
550 sel_mem_info->type = obj->contents_type;
552 /********** START : set search result to sel_mem_info buf ************/
554 if (obj->obj_icon_path)
555 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
556 MAX_LENGTH_PER_PATH - 1);
558 /* First, We should check comment field. It means drawing memo
559 * If comment field is NULL, then we check content field */
560 if ((value->comment) && (strlen(value->comment) > 0)) {
561 strncpy(sel_mem_info->main_buf,
562 search_markup_keyword(value->comment, keyword,
564 MAX_LENGTH_PER_LINE - 1);
565 } else if ((value->content) && (strlen(value->content) > 0)) {
566 strncpy(sel_mem_info->main_buf,
567 search_markup_keyword(value->content, keyword,
569 MAX_LENGTH_PER_LINE - 1);
571 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID - 1, "%d", value->id);
573 search_util_date_time_format_get_val(localtime
575 sel_mem_info->sub_buf);
577 /********** END : set search result to sel_mem_info buf *************/
579 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
581 ad->itc_pslist_2line_1icon,
584 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
586 obj->mr_info.next_point++;
587 } else if (obj->mr_info.next_point ==
588 obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
589 /* Set more title to genlist (under 'search all') */
591 (struct search_item_more_sel *)calloc(1,
593 search_item_more_sel));
594 sel_mem_more->obj = obj;
596 result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
603 ("__search_sql_memo_search_result_cb wrong index : %d",
604 obj->mr_info.next_point);
612 int search_sql_memo_search_result_by_api(struct search_content_object *obj,
613 int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
617 struct appdata *ad = (struct appdata *)data;
618 struct search_cb_data scd = {obj, ad, keyword, result_info};
620 memo_search_data(keyword,
623 __search_sql_memo_search_result_cb,
626 if (obj->mr_info.next_point == 0) {
627 SEARCH_DEBUG_WARNING("no memo search result");
628 return SEARCH_RET_SEARCH_NONE;
632 return SEARCH_RET_SEARCH_SUCCESS;
635 int search_sql_email_search_result_by_api(struct search_content_object *obj,
636 int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
640 struct appdata *ad = (struct appdata *)data;
642 int ret = EMAIL_ERROR_NONE;
644 email_mail_list_item_t *mail_list = NULL;
645 email_list_filter_t *filter_list = NULL;
646 email_list_sorting_rule_t *sorting_rule_list = NULL;
648 int filter_list_count = 5;
649 int sorting_rule_list_count = 1;
652 struct search_genlist_item_info *gen_item = NULL;
653 struct search_item_sel *sel_mem_info = NULL;
654 struct search_item_more_sel *sel_mem_more = NULL;
657 filter_list = (email_list_filter_t *)malloc(sizeof(email_list_filter_t) * filter_list_count);
658 memset(filter_list, 0 , sizeof(email_list_filter_t) * filter_list_count);
660 filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
661 filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
662 filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
663 filter_list[0].list_filter_item.rule.key_value.string_type_value = keyword;
664 filter_list[0].list_filter_item.rule.case_sensitivity = EMAIL_CASE_INSENSITIVE;
666 filter_list[1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
667 filter_list[1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
669 filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
670 filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_TO;
671 filter_list[2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
672 filter_list[2].list_filter_item.rule.key_value.string_type_value = keyword;
673 filter_list[2].list_filter_item.rule.case_sensitivity = EMAIL_CASE_INSENSITIVE;
675 filter_list[3].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
676 filter_list[3].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
678 filter_list[4].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
679 filter_list[4].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FROM;
680 filter_list[4].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
681 filter_list[4].list_filter_item.rule.key_value.string_type_value = keyword;
682 filter_list[4].list_filter_item.rule.case_sensitivity = EMAIL_CASE_INSENSITIVE;
684 sorting_rule_list = (email_list_sorting_rule_t *)malloc(sizeof(email_list_sorting_rule_t) * sorting_rule_list_count);
685 memset(sorting_rule_list, 0, sizeof(email_list_sorting_rule_t) * sorting_rule_list_count);
687 sorting_rule_list[0].target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
688 sorting_rule_list[0].sort_order = EMAIL_SORT_ORDER_ASCEND;
690 ret = email_get_mail_list_ex(filter_list, filter_list_count, sorting_rule_list, sorting_rule_list_count,
691 offset, limit, &mail_list, &mail_count);
694 if (ret != EMAIL_ERROR_NONE) {
695 SEARCH_DEBUG_WARNING("no email search result");
696 return SEARCH_RET_SEARCH_FAIL;
699 if (mail_count == 0) {
700 SEARCH_DEBUG_WARNING("no email search result");
701 return SEARCH_RET_SEARCH_NONE;
704 if(mail_list == NULL) {
705 SEARCH_DEBUG_WARNING("mail_list is null");
706 return SEARCH_RET_SEARCH_NONE;
709 /* Set group title */
711 result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
718 /* Set search result to genlist */
719 for(i = 0 ; i < mail_count ; i++) {
724 sel_mem_info = (struct search_item_sel *)calloc(1,
725 sizeof(struct search_item_sel));
727 sel_mem_info->type = obj->contents_type;
729 if (obj->obj_icon_path)
730 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
731 MAX_LENGTH_PER_PATH - 1);
733 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID - 1, "%d", mail_list[i].mail_id);
735 snprintf(sel_mem_info->path, MAX_LENGTH_PER_PATH - 1, "%d %d %d",
736 mail_list[i].account_id, mail_list[i].mail_id, mail_list[i].mailbox_id);
738 SEARCH_DEBUG_LOG("subject : %s", mail_list[i].subject);
740 if((mail_list[i].subject) && (strlen(mail_list[i].subject) > 0)) {
741 strncpy(sel_mem_info->main_buf,
742 search_markup_keyword(mail_list[i].subject, ad->search_word, &is_word_in_str),
743 MAX_LENGTH_PER_LINE - 1);
746 if((mail_list[i].from) && (strlen(mail_list[i].from) > 0)) {
747 strncpy(sel_mem_info->sub_buf,
748 search_markup_keyword(mail_list[i].from, ad->search_word, &is_word_in_str),
749 MAX_LENGTH_PER_LINE - 1);
752 if(is_word_in_str == false && (mail_list[i].recipients) && (strlen(mail_list[i].recipients) > 0)) {
753 strncpy(sel_mem_info->sub_buf,
754 search_markup_keyword(mail_list[i].recipients, ad->search_word, &is_word_in_str),
755 MAX_LENGTH_PER_LINE - 1);
758 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
760 ad->itc_pslist_2line_1icon,
763 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
766 SEARCH_FREE(mail_list);
768 /* Set more title to genlist (under 'search all') */
769 if (mail_count == limit) {
770 obj->mr_info.next_point = offset + mail_count - 1;
773 (struct search_item_more_sel *)calloc(1,
774 sizeof(struct search_item_more_sel));
775 sel_mem_more->obj = obj;
777 result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
784 SEARCH_FREE(filter_list);
785 SEARCH_FREE(sorting_rule_list);
788 return SEARCH_RET_SEARCH_SUCCESS;
791 static bool __search_media_info_cb(media_info_h media, void *user_data)
793 char *media_id = NULL;
794 char *media_name = NULL;
795 char *media_path = NULL;
796 char *media_thumbnail = NULL;
798 struct search_item_sel *sel_mem_info = NULL;
799 Elm_Genlist_Item_Class *itc_style = NULL;
800 bool is_word_in_str = false;
802 struct search_cb_data *scd = (struct search_cb_data*)user_data;
803 struct appdata *ad = scd->ad;
804 struct search_content_object *obj = scd->obj;
805 struct search_genlist_info *result_info = scd->result_info;
806 char *keyword = scd->keyword;
808 struct search_genlist_item_info *gen_item = NULL;
810 media_info_get_media_id(media, &media_id);
811 media_info_get_display_name(media, &media_name);
812 media_info_get_file_path(media, &media_path);
813 media_info_get_thumbnail_path(media, &media_thumbnail);
815 sel_mem_info = (struct search_item_sel *)calloc(1,
816 sizeof(struct search_item_sel));
818 sel_mem_info->type = obj->contents_type;
820 if ((media_thumbnail) && (strlen(media_thumbnail) > 0)
821 && ecore_file_exists(media_thumbnail) == EINA_TRUE) {
822 strncpy(sel_mem_info->icon1_path, media_thumbnail,
823 MAX_LENGTH_PER_PATH - 1);
824 } else if (obj->obj_icon_path)
825 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
826 MAX_LENGTH_PER_PATH - 1);
828 if (media_name && strlen(media_name)) {
829 strncpy(sel_mem_info->main_buf,
830 search_markup_keyword(media_name,
833 MAX_LENGTH_PER_LINE - 1);
837 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID, "%s",
841 snprintf(sel_mem_info->path, MAX_LENGTH_PER_PATH - 1, "%s",
844 itc_style = ad->itc_pslist_1line_1icon;
846 /* Add Info to genlist */
847 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
852 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
854 SEARCH_FREE(media_id);
855 SEARCH_FREE(media_name);
856 SEARCH_FREE(media_thumbnail);
857 SEARCH_FREE(media_path);
862 static bool __search_sql_music_info_cb(media_info_h media, void *user_data)
864 char *media_id = NULL;
865 char *media_path = NULL;
866 char *media_thumbnail = NULL;
871 audio_meta_h a_handle;
873 media_content_storage_e storage_type = MEDIA_CONTENT_STORAGE_INTERNAL;
875 struct search_item_sel *sel_mem_info = NULL;
876 Elm_Genlist_Item_Class *itc_style = NULL;
877 bool is_word_in_str = false;
879 struct search_cb_data *scd = (struct search_cb_data*)user_data;
880 struct appdata *ad = scd->ad;
881 struct search_content_object* obj = scd->obj;
882 struct search_genlist_info *result_info = scd->result_info;
883 char *keyword = scd->keyword;
885 struct search_genlist_item_info *gen_item = NULL;
887 media_info_get_media_id(media, &media_id);
888 media_info_get_file_path(media, &media_path);
889 media_info_get_storage_type(media, &storage_type);
890 media_info_get_thumbnail_path(media, &media_thumbnail);
892 media_info_get_audio(media, &a_handle);
893 audio_meta_get_title(a_handle, &title);
894 audio_meta_get_album(a_handle, &album);
895 audio_meta_get_artist(a_handle, &artist);
897 sel_mem_info = (struct search_item_sel *)calloc(1,
898 sizeof(struct search_item_sel));
900 sel_mem_info->type = obj->contents_type;;
902 if ((media_thumbnail) && (strlen(media_thumbnail) > 0)
903 && ecore_file_exists(media_thumbnail) == EINA_TRUE) {
904 strncpy(sel_mem_info->icon1_path , media_thumbnail,
905 MAX_LENGTH_PER_PATH -1 );
906 } else if(obj->obj_icon_path) {
907 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
908 MAX_LENGTH_PER_PATH - 1);
911 if ((title) && (strlen(title) > 0)) {
912 strncpy(sel_mem_info->main_buf,
913 search_markup_keyword(title, keyword, &is_word_in_str),
914 MAX_LENGTH_PER_LINE - 1);
917 if (is_word_in_str) {
918 if ((artist) && (strlen(artist) > 0)) {
919 strncpy(sel_mem_info->sub_buf,
920 search_markup_keyword(artist,
923 MAX_LENGTH_PER_LINE - 1);
926 memset(sel_mem_info->sub_buf, '\0', MAX_LENGTH_PER_LINE);
928 if ((artist) && (strlen(artist) > 0)) {
929 strncpy(sel_mem_info->sub_buf,
930 search_markup_keyword(artist,
933 MAX_LENGTH_PER_LINE - 1);
936 if (is_word_in_str == false && (album) && (strlen(album) > 0)) {
937 strncpy(sel_mem_info->sub_buf,
938 search_markup_keyword(album,
941 MAX_LENGTH_PER_LINE - 1);
944 if (is_word_in_str == false) {
945 SEARCH_DEBUG_LOG("search_result is 0. No match keyword in title,album,artist string");
949 if (storage_type == MEDIA_CONTENT_STORAGE_EXTERNAL) {
950 itc_style = ad->itc_pslist_2line_2icon;
951 strncpy(sel_mem_info->icon2_path, SEARCH_SDCARD_ICON,
952 MAX_LENGTH_PER_PATH - 1);
955 itc_style = ad->itc_pslist_2line_1icon;
959 snprintf(sel_mem_info->main_id,
960 MAX_LENGTH_PER_ID - 1, "%s", media_id);
963 strncpy(sel_mem_info->path, media_path, MAX_LENGTH_PER_PATH);
965 /* Add Information to genlist */
966 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
971 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
973 SEARCH_FREE(media_id);
974 SEARCH_FREE(media_path);
975 SEARCH_FREE(media_thumbnail);
983 static int __search_sql_media_search_result_by_api(struct search_content_object *obj,
984 int offset, int limit,
987 media_info_cb func_cb,
989 struct search_genlist_info *result_info)
993 struct appdata *ad = (struct appdata *)data;
994 struct search_cb_data scd = {obj, ad, keyword, result_info};
998 int func_ret = SEARCH_RET_SEARCH_SUCCESS;
1000 struct search_item_more_sel *sel_mem_more = NULL;
1002 media_info_get_media_count_from_db(filter, &result_cnt);
1004 if (result_cnt != 0) {
1005 /* Set group title */
1006 if (obj->mr_info.offset== 0) {
1007 result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
1014 ret = media_info_foreach_media_from_db(filter, func_cb, &scd);
1016 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1017 SEARCH_DEBUG_WARNING("media_info_foreach_media_from_db failed : %d\n", ret);
1018 func_ret = SEARCH_RET_SEARCH_FAIL;
1022 /* Set more title to genlist (under 'search all') */
1023 if (result_cnt == limit) {
1024 obj->mr_info.next_point = offset + result_cnt - 1;
1027 (struct search_item_more_sel *)calloc(1,
1028 sizeof(struct search_item_more_sel));
1029 sel_mem_more->obj = obj;
1031 result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
1035 obj->gl_result_grp);
1038 func_ret = SEARCH_RET_SEARCH_NONE;
1048 int search_sql_image_search_result_by_api(struct search_content_object *obj,
1049 int offset, int limit,
1052 struct search_genlist_info *result_info)
1056 int ret = SEARCH_RET_SEARCH_SUCCESS;
1058 char *search_query = NULL;
1059 char *escape_added_keyword = NULL;
1061 const char *image_query = "(MEDIA_TYPE=0 and MEDIA_DISPLAY_NAME like \"%%%s%%\" ESCAPE (\"%s\"))";
1063 SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char);
1064 memset(escape_added_keyword, 0x0, strlen(keyword)*2+5);
1065 search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX);
1067 len = strlen(escape_added_keyword) + strlen(DB_ESCAPE_CHAR) + strlen(image_query) + 1;
1068 search_query = (char*)calloc(1, len);
1070 snprintf(search_query, len, image_query, escape_added_keyword, "%");
1072 SEARCH_DEBUG_WARNING("keyword :%s", keyword);
1073 SEARCH_DEBUG_WARNING("search_query :%s", escape_added_keyword);
1077 ret = media_filter_create(&filter);
1078 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1079 SEARCH_DEBUG_WARNING("media_filter_create failed : %d\n", ret);
1080 ret = SEARCH_RET_SEARCH_FAIL;
1084 ret = media_filter_set_offset(filter, offset, limit);
1085 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1086 SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret);
1087 ret = SEARCH_RET_SEARCH_FAIL;
1091 ret = media_filter_set_condition(filter, search_query, MEDIA_CONTENT_COLLATE_DEFAULT);
1092 if(ret != MEDIA_CONTENT_ERROR_NONE) {
1093 SEARCH_DEBUG_WARNING("media_filter_set_condition failed : %d\n", ret);
1094 ret = SEARCH_RET_SEARCH_FAIL;
1098 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_DISPLAY_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
1099 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1100 SEARCH_DEBUG_WARNING("media_filter_set_order failed : %d\n", ret);
1101 ret = SEARCH_RET_SEARCH_FAIL;
1106 ret = __search_sql_media_search_result_by_api(obj,
1111 __search_media_info_cb,
1116 SEARCH_FREE(search_query);
1117 SEARCH_FREE(escape_added_keyword);
1118 media_filter_destroy(filter);
1125 int search_sql_video_search_result_by_api(struct search_content_object *obj,
1126 int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
1130 int ret = SEARCH_RET_SEARCH_SUCCESS;
1132 char *search_query = NULL;
1133 char *escape_added_keyword = NULL;
1135 const char *video_query = "(MEDIA_TYPE=1 and MEDIA_DISPLAY_NAME LIKE \"%%%s%%\" ESCAPE (\"%s\"))";
1137 SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char);
1138 memset(escape_added_keyword, 0x0, strlen(keyword)*2+5);
1139 search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX);
1141 len = strlen(escape_added_keyword) + strlen(DB_ESCAPE_CHAR) + strlen(video_query) + 1;
1142 search_query = (char*)calloc(1, len);
1144 snprintf(search_query, len, video_query, escape_added_keyword, DB_ESCAPE_CHAR);
1148 ret = media_filter_create(&filter);
1149 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1150 SEARCH_DEBUG_WARNING("media_filter_create failed : %d\n", ret);
1151 ret = SEARCH_RET_SEARCH_FAIL;
1155 ret = media_filter_set_offset(filter, offset, limit);
1156 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1157 SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret);
1158 ret = SEARCH_RET_SEARCH_FAIL;
1162 ret = media_filter_set_condition(filter, search_query, MEDIA_CONTENT_COLLATE_DEFAULT);
1163 if(ret != MEDIA_CONTENT_ERROR_NONE) {
1164 SEARCH_DEBUG_WARNING("media_filter_set_condition failed : %d\n", ret);
1165 ret = SEARCH_RET_SEARCH_FAIL;
1169 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_DISPLAY_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
1170 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1171 SEARCH_DEBUG_WARNING("media_filter_set_order failed : %d\n", ret);
1172 ret = SEARCH_RET_SEARCH_FAIL;
1176 ret = __search_sql_media_search_result_by_api(obj,
1181 __search_media_info_cb,
1187 SEARCH_FREE(search_query);
1188 SEARCH_FREE(escape_added_keyword);
1189 media_filter_destroy(filter);
1196 int search_sql_music_search_result_by_api(struct search_content_object *obj,
1197 int offset, int limit,
1200 struct search_genlist_info *result_info)
1204 int ret = SEARCH_RET_SEARCH_SUCCESS;
1206 char *search_query = NULL;
1207 char *escape_added_keyword = NULL;
1209 const char *music_query = "(MEDIA_TYPE=3 and MEDIA_TITLE LIKE \"%%%s%%\" or MEDIA_ALBUM LIKE \"%%%s%%\" or MEDIA_ARTIST LIKE \"%%%s%%\" ESCAPE (\"%s\"))";
1211 SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char);
1212 memset(escape_added_keyword, 0x0, strlen(keyword)*2+5);
1213 search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX);
1215 len = strlen(escape_added_keyword) + strlen(DB_ESCAPE_CHAR) + strlen(music_query) + 1;
1216 search_query = (char*)calloc(1, len);
1218 snprintf(search_query, len, music_query, escape_added_keyword,
1219 escape_added_keyword, escape_added_keyword, DB_ESCAPE_CHAR);
1223 ret = media_filter_create(&filter);
1224 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1225 SEARCH_DEBUG_WARNING("media_filter_create failed : %d\n", ret);
1226 ret = SEARCH_RET_SEARCH_FAIL;
1230 ret = media_filter_set_offset(filter, offset, limit);
1231 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1232 SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret);
1233 ret = SEARCH_RET_SEARCH_FAIL;
1237 ret = media_filter_set_condition(filter, search_query, MEDIA_CONTENT_COLLATE_DEFAULT);
1238 if(ret != MEDIA_CONTENT_ERROR_NONE) {
1239 SEARCH_DEBUG_WARNING("media_filter_set_condition failed : %d\n", ret);
1240 ret = SEARCH_RET_SEARCH_FAIL;
1244 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT);
1245 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1246 SEARCH_DEBUG_WARNING("media_filter_set_order failed : %d\n", ret);
1247 ret = SEARCH_RET_SEARCH_FAIL;
1251 ret = __search_sql_media_search_result_by_api(obj,
1256 __search_sql_music_info_cb,
1262 SEARCH_FREE(search_query);
1263 SEARCH_FREE(escape_added_keyword);
1264 media_filter_destroy(filter);
1271 ail_cb_ret_e __search_sql_menu_search_result_cb(
1272 const ail_appinfo_h appinfo,
1277 struct search_cb_data *scd = (struct search_cb_data*)data;
1278 struct appdata *ad = scd->ad;
1279 struct search_content_object* obj = scd->obj;
1280 struct search_genlist_info *result_info = scd->result_info;
1281 char *keyword = scd->keyword;
1283 struct search_genlist_item_info *gen_item = NULL;
1284 struct search_item_sel *sel_mem_info = NULL;
1285 struct search_item_more_sel *sel_mem_more = NULL;
1287 bool is_word_in_str;
1290 if (obj->mr_info.loop_cnt < obj->mr_info.next_point) {
1291 obj->mr_info.loop_cnt++;
1292 return AIL_CB_RET_CONTINUE;
1295 if(obj->mr_info.next_point <
1296 obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
1298 sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
1299 sel_mem_info->type = obj->contents_type;;
1301 /********** START : set search result to sel_mem_info buf ************/
1304 char *package = NULL;
1307 ail_appinfo_get_str(appinfo, AIL_PROP_ICON_STR, &icon);
1310 strncpy(sel_mem_info->icon1_path, icon,
1311 MAX_LENGTH_PER_PATH - 1);
1313 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
1314 if ((package) && (strlen(package) > 0)) {
1316 if(strcmp(package, "org.tizen.smartsearch") == 0) {
1317 SEARCH_DEBUG_LOG("'smartsearch' does not appended");
1318 obj->mr_info.loop_cnt++;
1319 SEARCH_FREE(sel_mem_info);
1320 return AIL_CB_RET_CONTINUE;
1323 strncpy(sel_mem_info->path, package, MAX_LENGTH_PER_PATH - 1);
1325 SEARCH_DEBUG_LOG("package : %s", package);
1327 SEARCH_DEBUG_LOG("package : null");
1330 ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &name);
1331 if ((name) && (strlen(name) > 0)) {
1332 strncpy(sel_mem_info->main_buf,
1333 search_markup_keyword(name, keyword, &is_word_in_str),
1334 MAX_LENGTH_PER_LINE - 1);
1336 SEARCH_DEBUG_LOG("name : %s", name);
1338 SEARCH_DEBUG_LOG("name : null");
1341 if(obj->mr_info.next_point == 0) {
1342 /* Set group title */
1343 result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
1350 /********** END : set search result to sel_mem_info buf *************/
1352 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
1354 ad->itc_pslist_1line_1icon,
1356 obj->gl_result_grp);
1357 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
1358 obj->mr_info.next_point++;
1359 obj->mr_info.loop_cnt++;
1361 ret = AIL_CB_RET_CONTINUE;
1363 } else if (obj->mr_info.next_point ==
1364 obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
1366 /* Check that only "SMARTSEARCH" is left in more result */
1367 if(obj->mr_info.next_point == obj->mr_info.result_cnt-1) {
1369 char *package = NULL;
1371 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
1372 if ((package) && (strlen(package) > 0) && (strcmp(package, "org.tizen.smartsearch") == 0)) {
1373 SEARCH_DEBUG_LOG("Only 'SMARTSEARCH' is left in more result");
1374 return AIL_CB_RET_CANCEL;
1378 /* Set more title to genlist (under 'search all') */
1379 sel_mem_more = (struct search_item_more_sel *)calloc(1, sizeof(struct search_item_more_sel));
1380 sel_mem_more->obj = obj;
1382 result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
1386 obj->gl_result_grp);
1388 ret = AIL_CB_RET_CANCEL;
1390 SEARCH_DEBUG_WARNING
1391 ("__search_sql_memo_search_result_cb wrong index : %d",
1392 obj->mr_info.next_point);
1394 ret = AIL_CB_RET_CANCEL;
1402 int search_sql_menu_search_result_by_api(struct search_content_object *obj,
1403 int offset, int limit,
1406 struct search_genlist_info *result_info)
1410 struct appdata *ad = (struct appdata *)data;
1411 struct search_cb_data scd = {obj, ad, keyword, result_info};
1416 ail_filter_h filter;
1419 char *escape_added_keyword = NULL;
1420 SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char);
1421 memset(escape_added_keyword, 0x0, strlen(keyword)*2+5);
1422 search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX);
1424 rc = ail_filter_new(&filter);
1425 if (rc != AIL_ERROR_OK) {
1426 SEARCH_DEBUG_WARNING("menu search - ail_filter_new error : %d", rc);
1427 return SEARCH_RET_SEARCH_FAIL;
1430 rc = ail_filter_add_str(filter, AIL_PROP_NAME_STR, escape_added_keyword);
1431 if (rc != AIL_ERROR_OK) {
1432 SEARCH_DEBUG_WARNING("menu search - ail_filter_add_str error : %d", rc);
1433 ret = SEARCH_RET_SEARCH_FAIL;
1437 rc = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false);
1438 if (rc != AIL_ERROR_OK) {
1439 SEARCH_DEBUG_WARNING("menu search - ail_filter_add_bool error : %d", rc);
1440 ret = SEARCH_RET_SEARCH_FAIL;
1444 rc = ail_filter_count_appinfo(filter, &cnt);
1445 if( rc != AIL_ERROR_OK) {
1446 SEARCH_DEBUG_WARNING("menu search - ail_filter_count_appinfo error : %d", rc);
1447 ret = SEARCH_RET_SEARCH_FAIL;
1451 SEARCH_DEBUG_LOG("ail search result : %d", cnt);
1452 obj->mr_info.result_cnt = cnt;
1455 obj->mr_info.loop_cnt = 0;
1456 rc = ail_filter_list_appinfo_foreach(filter, __search_sql_menu_search_result_cb, &scd);
1457 if( rc != AIL_ERROR_OK) {
1458 SEARCH_DEBUG_WARNING("menu search - ail_filter_list_appinfo_foreach error : %d", rc);
1459 ret = SEARCH_RET_SEARCH_FAIL;
1463 if (obj->mr_info.next_point == 0) {
1464 ret = SEARCH_RET_SEARCH_NONE;
1466 ret = SEARCH_RET_SEARCH_SUCCESS;
1469 ret = SEARCH_RET_SEARCH_NONE;
1473 ail_filter_destroy(filter);
1474 SEARCH_FREE(escape_added_keyword);
1480 bool __search_sql_browser_bookmark_result_cb(favorites_bookmark_entry_s *item, void *user_data)
1483 struct search_item_sel *sel_mem_info = NULL;
1486 bool is_word_in_str_main = false;
1487 bool is_word_in_str_sub = false;
1489 const char* match_str = NULL;
1491 struct search_cb_data_browser *scd = (struct search_cb_data_browser*)user_data;
1492 struct appdata *ad = scd->ad;
1493 struct search_content_object *obj = scd->obj;
1494 struct search_genlist_info *result_info = scd->result_info;
1495 char *keyword = scd->keyword;
1497 struct search_genlist_item_info *gen_item = NULL;
1498 struct search_more_result *info = scd->info;
1500 if (info->loop_cnt < info->next_point) {
1505 if (info->next_point <
1506 info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
1508 sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
1509 sel_mem_info->type = obj->contents_type;;
1511 /********** START : set search result to sel_mem_info buf ************/
1513 if (item != NULL && item->title) {
1514 match_str = search_markup_keyword(item->title, keyword, &is_word_in_str_main);
1515 strncpy(sel_mem_info->main_buf,
1517 MAX_LENGTH_PER_LINE - 1);
1520 if (item != NULL && item->address) {
1521 match_str = search_markup_keyword(item->address, keyword, &is_word_in_str_sub);
1522 strncpy(sel_mem_info->sub_buf,
1524 MAX_LENGTH_PER_LINE - 1);
1525 strncpy(sel_mem_info->path,
1527 MAX_LENGTH_PER_PATH - 1);
1530 if (is_word_in_str_main == true || is_word_in_str_sub == true) {
1531 if (obj->gl_result_grp == NULL ) {
1532 /* Set group title */
1533 result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
1540 if (obj->obj_icon_path)
1541 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
1542 MAX_LENGTH_PER_PATH - 1);
1544 strncpy(sel_mem_info->icon2_path,
1545 SEARCH_FAVORITE_ICON,
1546 MAX_LENGTH_PER_PATH - 1);
1548 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
1550 ad->itc_pslist_2line_2icon,
1552 obj->gl_result_grp);
1553 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
1556 /********** END : set search result to sel_mem_info buf *************/
1561 } else if (info->next_point ==
1562 info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
1563 info->offset = info->next_point;
1566 SEARCH_DEBUG_WARNING
1567 ("__search_sql_browser_bookmark_result_cb wrong index : %d",
1577 bool __search_sql_browser_history_result_cb(favorites_history_entry_s *item, void *user_data)
1580 struct search_item_sel *sel_mem_info = NULL;
1583 bool is_word_in_str_main = false;
1585 const char* match_str = NULL;
1587 struct search_cb_data_browser *scd = (struct search_cb_data_browser*)user_data;
1588 struct appdata *ad = scd->ad;
1589 struct search_content_object *obj = scd->obj;
1590 struct search_genlist_info *result_info = scd->result_info;
1591 char *keyword = scd->keyword;
1593 struct search_more_result *info = scd->info;
1594 struct search_genlist_item_info *gen_item = NULL;
1596 if (info->loop_cnt < info->next_point) {
1601 if (info->next_point <
1602 info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
1604 sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
1605 sel_mem_info->type = obj->contents_type;;
1607 /********** START : set search result to sel_mem_info buf ************/
1609 if (item != NULL && item->address) {
1610 SEARCH_DEBUG_WARNING("BROWSER : %s %s", item->address, keyword);
1611 match_str = search_markup_keyword(item->address, keyword, &is_word_in_str_main);
1614 if (is_word_in_str_main != false ) {
1615 if (obj->gl_result_grp == NULL ) {
1616 /* Set group title */
1617 result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
1624 if (obj->obj_icon_path)
1625 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
1626 MAX_LENGTH_PER_PATH - 1);
1629 strncpy(sel_mem_info->path, item->address, MAX_LENGTH_PER_PATH - 1);
1631 strncpy(sel_mem_info->main_buf,
1633 MAX_LENGTH_PER_LINE - 1);
1635 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
1637 ad->itc_pslist_1line_1icon,
1639 obj->gl_result_grp);
1640 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
1648 } else if (info->next_point ==
1649 info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
1650 info->offset = info->next_point;
1653 SEARCH_DEBUG_WARNING
1654 ("__search_sql_browser_history_result_cb wrong index : %d",
1664 int search_sql_browser_search_result_by_api(struct search_content_object *obj,
1665 int offset, int limit,
1668 struct search_genlist_info *result_info)
1672 struct appdata *ad = (struct appdata *)data;
1673 struct search_cb_data_browser scd_browser = {obj, ad, keyword, result_info, NULL};
1674 struct search_cb_data_browser scd_history = {obj, ad, keyword, result_info, NULL};
1676 static struct search_more_result browser_result[2];
1677 struct search_item_more_sel *sel_mem_more = NULL;
1680 int bookmark_cnt = 0, history_cnt = 0;
1681 int bookmark_ret = 0, history_ret = 0;
1684 /* offset 0 means first search result, so we initialize struct */
1685 memset(browser_result, 0x0, sizeof(browser_result));
1687 favorites_bookmark_get_count(&browser_result[0].result_cnt);
1688 favorites_history_get_count(&browser_result[1].result_cnt);
1690 bookmark_cnt = browser_result[0].result_cnt;
1691 history_cnt = browser_result[1].result_cnt;
1692 browser_result[0].ad = browser_result[1].ad = ad;
1693 obj->gl_result_grp = NULL;
1695 if ( bookmark_cnt <= 0 && history_cnt <= 0 )
1696 return SEARCH_RET_SEARCH_NONE;
1698 bookmark_cnt = browser_result[0].result_cnt;
1699 history_cnt = browser_result[1].result_cnt;
1700 browser_result[0].loop_cnt = 0;
1701 browser_result[1].loop_cnt = 0;
1704 if (offset >= bookmark_cnt + history_cnt) {
1705 /* We need not to search */
1706 return SEARCH_RET_SEARCH_NONE;
1709 scd_browser.info = &browser_result[0];
1710 scd_history.info = &browser_result[1];
1713 if (bookmark_cnt > browser_result[0].next_point )
1714 bookmark_ret = favorites_bookmark_foreach(__search_sql_browser_bookmark_result_cb,
1716 if (history_cnt > browser_result[1].next_point )
1717 history_ret = favorites_history_foreach(__search_sql_browser_history_result_cb,
1720 if (bookmark_ret == FAVORITES_ERROR_DB_FAILED
1721 && history_ret == FAVORITES_ERROR_DB_FAILED ) {
1722 ret = SEARCH_RET_SEARCH_FAIL;
1724 else if (obj->gl_result_grp == NULL) {
1725 /* It means we can't get matched results */
1726 ret = SEARCH_RET_SEARCH_NONE;
1729 /* Make More button */
1730 if (browser_result[0].next_point < bookmark_cnt
1731 || browser_result[1].next_point < history_cnt) {
1732 sel_mem_more = (struct search_item_more_sel *)calloc(1, sizeof(struct search_item_more_sel));
1733 sel_mem_more->obj = obj;
1735 result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
1739 obj->gl_result_grp);
1743 obj->mr_info.next_point = browser_result[0].next_point
1744 + browser_result[1].next_point;
1745 ret = SEARCH_RET_SEARCH_SUCCESS;
1753 int search_sql_msg_search_result_by_api(struct search_content_object *obj,
1754 int offset, int limit,
1757 struct search_genlist_info *result_info)
1764 struct search_item_sel *sel_mem_info = NULL;
1765 struct search_item_more_sel *sel_mem_more = NULL;
1766 struct appdata *ad = (struct appdata *)data;
1767 struct search_genlist_item_info *gen_item = NULL;
1769 bool is_word_in_str;
1773 bool is_more_btn = false;
1774 bool is_word_in_title = false;
1776 msg_error_t err = MSG_SUCCESS;
1777 msg_struct_list_s msgList;
1778 msg_struct_t search_s = NULL;
1779 msg_struct_list_s *addr_list = NULL;
1781 search_s = msg_create_struct(MSG_STRUCT_SEARCH_CONDITION);
1783 err = msg_set_int_value(search_s, MSG_SEARCH_CONDITION_FOLDERID_INT, MSG_ALLBOX_ID);
1784 if (err != MSG_SUCCESS) {
1785 SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_SEARCH_CONDITION_FOLDERID_INT");
1786 return SEARCH_RET_SEARCH_FAIL;
1789 err = msg_set_int_value(search_s, MSG_SEARCH_CONDITION_MSGTYPE_INT, MSG_TYPE_INVALID);
1790 if (err != MSG_SUCCESS) {
1791 SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_SEARCH_CONDITION_MSGTYPE_INT");
1792 return SEARCH_RET_SEARCH_FAIL;
1795 err = msg_set_str_value(search_s, MSG_SEARCH_CONDITION_SEARCH_VALUE_STR, keyword, strlen(keyword));
1796 if (err != MSG_SUCCESS) {
1797 SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_SEARCH_CONDITION_SEARCH_VALUE_STR");
1798 return SEARCH_RET_SEARCH_FAIL;
1801 err = msg_search_message(ad->msg_handle, search_s, offset, limit, &msgList);
1803 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1804 SEARCH_DEBUG_WARNING("msg_search_message is failed : %d", err);
1805 return SEARCH_RET_SEARCH_FAIL;
1808 if (msgList.nCount <= 0) {
1809 SEARCH_DEBUG_WARNING("no msg search result");
1810 ret = SEARCH_RET_SEARCH_NONE;
1813 /* Set group title */
1815 /* Set group title */
1816 result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
1823 /* Set search result to genlist */
1825 if(msgList.nCount < limit) {
1826 loop_cnt = msgList.nCount;
1827 is_more_btn = false;
1833 /********** START : set search result to sel_mem_info buf ************/
1835 for (i = 0; i < loop_cnt; i++) {
1837 const char *text_1line = NULL;
1838 const char *markup_keyword = NULL;
1839 const char *img_path = NULL;
1842 int contact_id = -1;
1843 int message_id = -1;
1845 char subject[MAX_SUBJECT_LEN] = {0};
1846 char str_number[MAX_ADDRESS_VAL_LEN] = {0,};
1847 char str_name[MAX_DISPLAY_NAME_LEN] = {0,};
1848 char msg_text[MAX_MSG_TEXT_LEN] = {0,};
1850 CTSstruct *contact = NULL;
1852 sel_mem_info = (struct search_item_sel *)
1853 calloc(1,sizeof(struct search_item_sel));
1854 sel_mem_info->type = obj->contents_type;;
1856 err = msg_get_int_value(msgList.msg_struct_info[i], MSG_MESSAGE_ID_INT, &message_id);
1857 if (err != MSG_SUCCESS) {
1858 SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_MESSAGE_ID_INT %d", err);
1861 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID - 1, "%d", message_id);
1863 err = msg_get_int_value(msgList.msg_struct_info[i], MSG_MESSAGE_TYPE_INT, &msg_type);
1864 if (err != MSG_SUCCESS) {
1865 SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_MESSAGE_TYPE_INT %d", err);
1869 SEARCH_DEBUG_LOG("mms : %d", msg_type);
1871 /* Set 1st line string */
1872 if (msg_type == MSG_TYPE_MMS) {
1874 err = msg_get_str_value(msgList.msg_struct_info[i], MSG_MESSAGE_SUBJECT_STR,
1875 subject, MAX_SUBJECT_LEN);
1877 if (err != MSG_SUCCESS) {
1878 SEARCH_DEBUG_WARNING("Fail to get sms context %d", err);
1882 text_1line = subject;
1883 markup_keyword = search_markup_keyword(text_1line,
1887 if (!is_word_in_title) {
1888 memset(msg_text, 0x00, sizeof(msg_text));
1889 err = msg_get_str_value(msgList.msg_struct_info[i],
1890 MSG_MESSAGE_MMS_TEXT_STR,
1894 if (err != MSG_SUCCESS) {
1895 SEARCH_DEBUG_WARNING("Fail to get mms context %d", err);
1899 text_1line = msg_text;
1901 markup_keyword = search_markup_keyword(text_1line,
1906 SEARCH_DEBUG_LOG("1st string : %s", text_1line);
1908 if ((text_1line) && (strlen(text_1line) > 0 ))
1909 strncpy(sel_mem_info->main_buf, markup_keyword, MAX_LENGTH_PER_LINE - 1);
1912 err = msg_get_str_value(msgList.msg_struct_info[i],
1913 MSG_MESSAGE_SMS_DATA_STR,
1917 if (err != MSG_SUCCESS) {
1918 SEARCH_DEBUG_WARNING("Fail to get sms context %d", err);
1922 text_1line = msg_text;
1924 markup_keyword = search_markup_keyword(text_1line,
1927 SEARCH_DEBUG_LOG("1st string : %s", text_1line);
1929 if ((text_1line) && (strlen(text_1line) > 0))
1930 strncpy(sel_mem_info->main_buf, markup_keyword, MAX_LENGTH_PER_LINE - 1);
1933 err = msg_get_list_handle(msgList.msg_struct_info[i],
1934 MSG_MESSAGE_ADDR_LIST_STRUCT,
1935 (void **)&addr_list);
1937 if (err != MSG_SUCCESS) {
1938 SEARCH_DEBUG_WARNING("Fail to get address list handle! %d", err);
1942 /* Set 2nd line string */
1943 for ( j=0; j<addr_list->nCount; j++) {
1944 memset(str_number, 0, sizeof(str_number));
1945 memset(str_name, 0, sizeof(str_name));
1947 is_word_in_str = false;
1949 /* First We set text_2line to first address data */
1950 err = msg_get_str_value(addr_list->msg_struct_info[j],
1951 MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
1953 MAX_ADDRESS_VAL_LEN);
1955 if (err != MSG_SUCCESS) {
1956 SEARCH_DEBUG_WARNING("Fail to get data! : MSG_ADDRESS_INFO_DISPLAYNAME_STR %d", err);
1960 err = msg_get_str_value(addr_list->msg_struct_info[j],
1961 MSG_ADDRESS_INFO_DISPLAYNAME_STR,
1963 MAX_DISPLAY_NAME_LEN);
1965 if (err != MSG_SUCCESS) {
1966 SEARCH_DEBUG_WARNING("Fail to get data! : MSG_ADDRESS_INFO_ADDRESS_VALUE_STR %d", err);
1970 err = msg_get_int_value(addr_list->msg_struct_info[j],
1971 MSG_ADDRESS_INFO_CONTACT_ID_INT,
1974 if (err != MSG_SUCCESS) {
1975 SEARCH_DEBUG_WARNING("Fail to get data! : MSG_ADDRESS_INFO_CONTACT_ID_INT %d", err);
1979 /* Set text_2line */
1980 markup_keyword = search_markup_keyword(str_number, keyword, &is_word_in_str);
1982 if( 0 == j || true == is_word_in_str) {
1983 if (strlen(str_name) > 0) {
1984 strncpy(sel_mem_info->sub_buf, str_name, MAX_LENGTH_PER_LINE - 1);
1986 strncpy(sel_mem_info->sub_buf, markup_keyword, MAX_LENGTH_PER_LINE - 1);
1989 /* Set Thumbnail Image */
1990 if (contact_id == -1) {
1991 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
1992 MAX_LENGTH_PER_PATH - 1);
1995 ret = contacts_svc_get_contact(contact_id, &contact);
1997 if (ret == CTS_SUCCESS) {
1998 CTSvalue* value = NULL;
1999 ret = contacts_svc_struct_get_value(contact, CTS_CF_BASE_INFO_VALUE, &value);
2001 if (ret == CTS_SUCCESS)
2002 img_path = contacts_svc_value_get_str(value, CTS_BASE_VAL_IMG_PATH_STR);
2004 if (img_path != NULL)
2005 strncpy(sel_mem_info->icon1_path , img_path,
2006 MAX_LENGTH_PER_PATH -1 );
2007 else if (obj->obj_icon_path)
2008 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
2009 MAX_LENGTH_PER_PATH - 1);
2011 else if (obj->obj_icon_path)
2012 strncpy(sel_mem_info->icon1_path, obj->obj_icon_path,
2013 MAX_LENGTH_PER_PATH - 1);
2017 if ((is_word_in_title) || (is_word_in_str)) {
2022 SEARCH_DEBUG_LOG("sel_mem_info->sub_buf : %s", sel_mem_info->sub_buf);
2024 gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
2026 ad->itc_pslist_2line_1icon,
2028 obj->gl_result_grp);
2030 result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
2033 msg_release_list_struct(&msgList);
2035 /* Set more title to genlist (under 'search all') */
2037 obj->mr_info.next_point = offset + limit - 1;
2039 sel_mem_more = (struct search_item_more_sel *)
2040 calloc(1,sizeof(struct search_item_more_sel));
2041 sel_mem_more->obj = obj;
2043 result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
2047 obj->gl_result_grp);
2050 ret = SEARCH_RET_SEARCH_SUCCESS;
2058 void search_sql_update_result_object(struct search_content_object* result_obj, sqlite3* db_handle, sqlite3_stmt** db_sql)
2064 sqlite3_stmt *sql_stmt = db_sql[SEARCH_STMT_UPDATE_OBJECT_INFO];
2065 SEARCH_RET_IF(sql_stmt==NULL);
2067 search_sql_bind_text(db_handle, sql_stmt, 1, result_obj->name);
2068 search_sql_bind_int(db_handle, sql_stmt, 2, result_obj->string_type);
2069 search_sql_bind_int(db_handle, sql_stmt, 3, result_obj->visible);
2070 search_sql_bind_int(db_handle, sql_stmt, 4, result_obj->order);
2071 search_sql_bind_int(db_handle, sql_stmt, 5, result_obj->contents_type);
2072 search_sql_bind_int(db_handle, sql_stmt, 6, result_obj->category_type);
2073 search_sql_bind_text(db_handle, sql_stmt, 7, result_obj->def_pkg_name);
2074 search_sql_bind_int(db_handle, sql_stmt, 8, result_obj->contents_type);
2076 rc = sqlite3_step(sql_stmt);
2078 if (rc == SQLITE_OK)
2079 SEARCH_DEBUG_LOG("INSERT STEP SUCCESS");
2081 search_sql_stmt_init(sql_stmt);