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-types.h>
31 #include <email-api.h>
33 #include <visual-svc.h>
34 #include <visual-svc-types.h>
35 #include <audio-svc.h>
36 #include <audio-svc-types.h>
37 #include <audio-svc-error.h>
41 static GList *g_history_list;
43 char* g_keyword = NULL;
45 int search_sql_stmt_init(sqlite3_stmt * sql_stmt)
51 rc = sqlite3_clear_bindings(sql_stmt);
52 if (rc != SQLITE_OK) {
53 SEARCH_DEBUG_ERROR("sqlite3_clear_bindings error");
54 return SEARCH_RET_FAIL;
57 rc = sqlite3_reset(sql_stmt);
58 if (rc != SQLITE_OK) {
59 SEARCH_DEBUG_ERROR("sqlite3_reset error");
60 return SEARCH_RET_FAIL;
66 int search_sql_stmt_finalize(sqlite3_stmt * stmt)
72 ret = sqlite3_finalize(stmt);
73 if (ret != SQLITE_OK) {
74 SEARCH_DEBUG_ERROR("sqlite3_finalize error : %d ", ret);
83 int search_sql_prepare_stmt(sqlite3 *db_handle, const char *query,
84 sqlite3_stmt ** stmt_out)
91 rc = sqlite3_prepare(db_handle, query, strlen(query), stmt_out, NULL);
92 if (rc != SQLITE_OK) {
93 SEARCH_DEBUG_ERROR("sql preapre error : %d / %s", rc, query);
94 ret = SEARCH_RET_FAIL;
96 ret = SEARCH_RET_SUCCESS;
104 static int __search_sql_contact_search_result_cb(CTSvalue * value,
109 struct appdata *ad = (struct appdata *)user_data;
111 struct search_item_sel *sel_mem = NULL;
112 int type = SEARCH_TYPE_PHONE_CONTACTS;
114 struct search_item_sel *sel_mem_info = NULL;
115 char display_name[128] = { 0, };
116 const char *first, *last, *display, *number;
120 if (ad->cate_info[type].next_point == 0) {
121 //### Set group title
124 (struct search_item_sel *)calloc(1,
127 sel_mem->type = type;
129 ad->gl_result_group_item[type] =
130 elm_genlist_item_append(ad->search_gl,
131 (ad->itc_grouptitle), sel_mem,
132 (Elm_Object_Item *) NULL,
133 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
136 if (ad->cate_info[type].next_point <
137 ad->cate_info[type].offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
139 (struct search_item_sel *)calloc(1,
142 sel_mem_info->type = type;
144 /************ START : set search result to sel_mem_info buf ************/
146 /***********************************************************************/
148 memset(display_name, 0x00, sizeof(display_name));
151 contacts_svc_value_get_str(value,
152 CTS_LIST_NUM_CONTACT_DISPLAY_STR);
155 snprintf(display_name, sizeof(display_name), "%s",
159 contacts_svc_value_get_str(value,
160 CTS_LIST_NUM_CONTACT_FIRST_STR);
162 contacts_svc_value_get_str(value,
163 CTS_LIST_NUM_CONTACT_LAST_STR);
165 if (CTS_ORDER_NAME_FIRSTLAST ==
166 contacts_svc_get_order(CTS_ORDER_OF_DISPLAY)) {
169 snprintf(display_name,
170 sizeof(display_name),
171 "%s %s", first, last);
173 snprintf(display_name,
174 sizeof(display_name),
179 snprintf(display_name,
180 sizeof(display_name),
187 snprintf(display_name,
188 sizeof(display_name),
189 "%s %s", last, first);
191 snprintf(display_name,
192 sizeof(display_name),
197 snprintf(display_name,
198 sizeof(display_name),
205 if((display_name) && strlen(display_name) > 0) {
206 char* markup_text_1line = elm_entry_utf8_to_markup(display_name);
208 strncpy(sel_mem_info->main_buf,
209 search_markup_keyword(markup_text_1line, ad->not_markup_search_word, &is_word_in_str),
210 MAX_LENGTH_PER_LINE - 1);
212 SEARCH_FREE(markup_text_1line);
215 /***********************************************************************/
217 number = contacts_svc_value_get_str(value, CTS_LIST_NUM_NUMBER_STR);
219 if((number) && strlen(number) > 0) {
220 char* markup_text_2line = elm_entry_utf8_to_markup(number);
222 strncpy(sel_mem_info->sub_buf,
223 search_markup_keyword(markup_text_2line, ad->not_markup_search_word, &is_word_in_str),
224 MAX_LENGTH_PER_LINE - 1);
225 SEARCH_FREE(markup_text_2line);
228 /***********************************************************************/
230 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID - 1, "%d",
231 contacts_svc_value_get_int(value,
232 CTS_LIST_NUM_CONTACT_ID_INT));
234 /***********************************************************************/
235 /************ END : set search result to sel_mem_info buf **************/
237 elm_genlist_item_append(ad->search_gl, (ad->itc_pslist_2line),
239 ad->gl_result_group_item[type],
240 ELM_GENLIST_ITEM_NONE,
241 search_gl_phone_result_sel, ad);
243 ad->cate_info[type].next_point++;
244 } else if (ad->cate_info[type].next_point ==
245 ad->cate_info[type].offset +
246 SEARCH_CATEGORY_LIST_MORE_CNT) {
247 /* Set more title to genlist (under 'search all') */
249 (struct search_item_sel *)calloc(1,
252 sel_mem->type = type;
254 elm_genlist_item_append(ad->search_gl, (ad->itc_listmore),
255 sel_mem, ad->gl_result_group_item[type],
256 ELM_GENLIST_ITEM_NONE,
257 search_gl_result_more_item_append_cb,
261 ("__search_sql_contact_search_result_cb wrong index : %d",
262 ad->cate_info[type].next_point);
270 int search_sql_contact_search_result_by_api(int type, int offset, int limit,
275 struct appdata *ad = (struct appdata *)data;
278 /* Check whether search result is exist or not */
280 contacts_svc_smartsearch_excl(ad->search_word, limit, offset,
281 __search_sql_contact_search_result_cb,
283 if (ret != CTS_SUCCESS) {
284 SEARCH_DEBUG_WARNING("contacts svc search return error : %d",
286 return SEARCH_RET_SEARCH_FAIL;
289 if (ad->cate_info[type].next_point == 0) {
290 SEARCH_DEBUG_WARNING("contacts svc search no result");
291 return SEARCH_RET_SEARCH_NONE;
296 return SEARCH_RET_SEARCH_SUCCESS;
299 int search_sql_calendar_search_result_by_api(int type, int offset, int limit,
305 struct appdata *ad = (struct appdata *)data;
307 cal_struct *event = NULL;
308 cal_iter *iter = NULL;
310 struct search_item_sel *sel_mem = NULL;
311 Elm_Object_Item *git = NULL;
314 struct search_item_sel *sel_mem_info = NULL;
317 char *summary = NULL;
320 time_t start_time = 0;
323 calendar_svc_search_list(0, 0, CAL_STRUCT_SCHEDULE,
324 CAL_VALUE_TXT_SUMMARY, ad->search_word,
325 offset, limit, &iter);
327 if (ret == CAL_SUCCESS) {
328 ret = calendar_svc_iter_next(iter);
329 if (ret != CAL_SUCCESS) {
331 ("calendar svc search no result : %d", ret);
332 return SEARCH_RET_SEARCH_NONE;
334 /* Set group title */
335 glist = ad->search_gl;
339 (struct search_item_sel *)calloc(1,
342 sel_mem->type = type;
345 elm_genlist_item_append(glist,
346 (ad->itc_grouptitle),
348 (Elm_Object_Item *) NULL,
349 ELM_GENLIST_ITEM_GROUP,
352 ad->gl_result_group_item[type] = git;
354 /* Set search result to genlist */
358 if (loop_cnt == limit) {
361 /********** START : set search result to sel_mem_info buf ************/
363 ret = calendar_svc_iter_get_info(iter, &event);
365 if (ret == CAL_SUCCESS) {
367 (struct search_item_sel *)calloc(1,
371 sel_mem_info->type = type;
374 calendar_svc_struct_get_str(event,
375 CAL_VALUE_TXT_SUMMARY);
377 if ((summary) && (strlen(summary) > 0)) {
378 char* markup_text_1line = elm_entry_utf8_to_markup(summary);
380 strncpy(sel_mem_info->main_buf,
381 search_markup_keyword(markup_text_1line,
382 ad->not_markup_search_word,
384 MAX_LENGTH_PER_LINE - 1);
386 SEARCH_FREE(markup_text_1line);
389 snprintf(sel_mem_info->main_id,
390 MAX_LENGTH_PER_ID - 1, "%d",
391 calendar_svc_struct_get_int(event,
392 CAL_VALUE_INT_INDEX));
395 calendar_svc_struct_get_time(event,
396 CAL_VALUE_GMT_START_DATE_TIME,
398 search_util_date_time_format_get_val(localtime
400 sel_mem_info->sub_buf);
402 calendar_svc_struct_free(&event);
405 elm_genlist_item_append(glist,
406 (ad->itc_pslist_1line),
408 ad->gl_result_group_item[type],
409 ELM_GENLIST_ITEM_NONE,
410 search_gl_phone_result_sel,
415 ("calendar_svc_iter_get_info fail : %d",
421 while (calendar_svc_iter_next(iter) == CAL_SUCCESS);
423 SEARCH_DEBUG_WARNING("calendar_svc_search_list fail : %d", ret);
424 return SEARCH_RET_SEARCH_FAIL;
427 /* Set more title to genlist (under 'search all') */
428 if (loop_cnt == limit) {
429 ad->cate_info[type].next_point = offset + limit - 1;
432 (struct search_item_sel *)calloc(1,
435 sel_mem->type = type;
437 elm_genlist_item_append(ad->search_gl, (ad->itc_listmore),
438 sel_mem, ad->gl_result_group_item[type],
439 ELM_GENLIST_ITEM_NONE,
440 search_gl_result_more_item_append_cb,
445 return SEARCH_RET_SEARCH_SUCCESS;
448 static void __search_sql_memo_search_result_cb(memo_data_t * value,
453 struct appdata *ad = (struct appdata *)user_data;
455 struct search_item_sel *sel_mem = NULL;
456 int type = SEARCH_TYPE_PHONE_MEMO;
458 struct search_item_sel *sel_mem_info = NULL;
463 SEARCH_DEBUG_WARNING("memo data value is null");
467 if (ad->cate_info[type].next_point == 0) {
468 /* Set group title */
471 (struct search_item_sel *)calloc(1,
474 sel_mem->type = type;
476 ad->gl_result_group_item[type] =
477 elm_genlist_item_append(ad->search_gl,
478 (ad->itc_grouptitle), sel_mem,
479 (Elm_Object_Item *) NULL,
480 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
483 if (ad->cate_info[type].next_point <
484 ad->cate_info[type].offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
486 (struct search_item_sel *)calloc(1,
489 sel_mem_info->type = type;
491 /********** START : set search result to sel_mem_info buf ************/
492 /* First, We should check comment field. It means drawing memo
493 * If comment field is NULL, then we check content field */
494 if ((value->comment) && (strlen(value->comment) > 0)) {
495 char* markup_text_1line = elm_entry_utf8_to_markup(value->comment);
497 strncpy(sel_mem_info->main_buf,
498 search_markup_keyword(markup_text_1line, ad->not_markup_search_word,
500 MAX_LENGTH_PER_LINE - 1);
502 SEARCH_FREE(markup_text_1line);
503 } else if ((value->content) && (strlen(value->content) > 0)) {
504 char* markup_text_1line = elm_entry_utf8_to_markup(value->content);
506 strncpy(sel_mem_info->main_buf,
507 search_markup_keyword(markup_text_1line, ad->not_markup_search_word,
509 MAX_LENGTH_PER_LINE - 1);
511 SEARCH_FREE(markup_text_1line);
513 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID - 1, "%d", value->id);
515 search_util_date_time_format_get_val(localtime
517 sel_mem_info->sub_buf);
519 /********** END : set search result to sel_mem_info buf *************/
521 elm_genlist_item_append(ad->search_gl, (ad->itc_pslist_1line),
523 ad->gl_result_group_item[type],
524 ELM_GENLIST_ITEM_NONE,
525 search_gl_phone_result_sel, ad);
527 ad->cate_info[type].next_point++;
528 } else if (ad->cate_info[type].next_point ==
529 ad->cate_info[type].offset +
530 SEARCH_CATEGORY_LIST_MORE_CNT) {
531 /* Set more title to genlist (under 'search all') */
533 (struct search_item_sel *)calloc(1,
536 sel_mem->type = type;
538 elm_genlist_item_append(ad->search_gl, (ad->itc_listmore),
539 sel_mem, ad->gl_result_group_item[type],
540 ELM_GENLIST_ITEM_NONE,
541 search_gl_result_more_item_append_cb,
545 ("__search_sql_memo_search_result_cb wrong index : %d",
546 ad->cate_info[type].next_point);
554 int search_sql_memo_search_result_by_api(int type, int offset, int limit,
559 struct appdata *ad = (struct appdata *)data;
561 memo_search_data(ad->search_word,
564 __search_sql_memo_search_result_cb,
567 if (ad->cate_info[type].next_point == 0) {
568 SEARCH_DEBUG_WARNING("no memo search result");
569 return SEARCH_RET_SEARCH_NONE;
573 return SEARCH_RET_SEARCH_SUCCESS;
576 int search_sql_email_search_result_by_api(int type, int offset, int limit,
581 struct appdata *ad = (struct appdata *)data;
586 emf_mail_list_item_t *mail_list = NULL;
588 struct search_item_sel *sel_mem = NULL;
589 Elm_Object_Item *git = NULL;
592 struct search_item_sel *sel_mem_info = NULL;
595 ret = email_find_mail(0, NULL, 0, EMF_SEARCH_FILTER_ALL ,
596 ad->search_word, offset, limit, EMF_SORT_DATETIME_HIGH,
597 &mail_list, &result_cnt);
600 SEARCH_DEBUG_WARNING("no email search result");
601 return SEARCH_RET_SEARCH_FAIL;
604 if(result_cnt == 0) {
605 SEARCH_DEBUG_WARNING("no email search result");
606 return SEARCH_RET_SEARCH_NONE;
609 if(mail_list == NULL) {
610 SEARCH_DEBUG_WARNING("mail_list is null");
611 return SEARCH_RET_SEARCH_NONE;
614 /* Set group title */
615 glist = ad->search_gl;
618 sel_mem = (struct search_item_sel *)calloc(1,
619 sizeof(struct search_item_sel));
621 sel_mem->type = type;
623 git = elm_genlist_item_append(glist,
624 (ad->itc_grouptitle),
626 (Elm_Object_Item *) NULL,
627 ELM_GENLIST_ITEM_GROUP,
630 ad->gl_result_group_item[type] = git;
633 /* Set search result to genlist */
634 for(i=0;i<result_cnt;i++) {
639 sel_mem_info = (struct search_item_sel *)calloc(1,
640 sizeof(struct search_item_sel));
642 sel_mem_info->type = type;
644 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID - 1, "%d", mail_list[i].mail_id);
646 snprintf(sel_mem_info->path, MAX_LENGTH_PER_PATH - 1, "%d %d %s",
647 mail_list[i].account_id, mail_list[i].mail_id, mail_list[i].mailbox_name);
649 SEARCH_DEBUG_LOG("subject : %s", mail_list[i].subject);
651 if((mail_list[i].subject) && (strlen(mail_list[i].subject) > 0)) {
652 char* markup_text_1line = elm_entry_utf8_to_markup(mail_list[i].subject);
654 strncpy(sel_mem_info->main_buf,
655 search_markup_keyword(markup_text_1line, ad->not_markup_search_word, &is_word_in_str),
656 MAX_LENGTH_PER_LINE - 1);
657 SEARCH_FREE(markup_text_1line);
660 if((mail_list[i].from) && (strlen(mail_list[i].from) > 0)) {
661 char* markup_text_2line = elm_entry_utf8_to_markup(mail_list[i].from);
663 strncpy(sel_mem_info->sub_buf,
664 search_markup_keyword(markup_text_2line, ad->not_markup_search_word, &is_word_in_str),
665 MAX_LENGTH_PER_LINE - 1);
666 SEARCH_FREE(markup_text_2line);
669 if(is_word_in_str == false && (mail_list[i].recipients) && (strlen(mail_list[i].recipients) > 0)) {
670 char* markup_text_2line = elm_entry_utf8_to_markup(mail_list[i].recipients);
672 strncpy(sel_mem_info->sub_buf,
673 search_markup_keyword(markup_text_2line, ad->not_markup_search_word, &is_word_in_str),
674 MAX_LENGTH_PER_LINE - 1);
675 SEARCH_FREE(markup_text_2line);
678 elm_genlist_item_append(glist,
679 (ad->itc_pslist_2line),
681 ad->gl_result_group_item
683 ELM_GENLIST_ITEM_NONE,
684 search_gl_phone_result_sel,
689 SEARCH_FREE(mail_list);
691 /* Set more title to genlist (under 'search all') */
692 if (result_cnt == limit) {
693 ad->cate_info[type].next_point = offset + result_cnt - 1;
696 (struct search_item_sel *)calloc(1,
697 sizeof(struct search_item_sel));
698 sel_mem->type = type;
700 elm_genlist_item_append(ad->search_gl, (ad->itc_listmore),
701 sel_mem, ad->gl_result_group_item[type],
702 ELM_GENLIST_ITEM_NONE,
703 search_gl_result_more_item_append_cb,
708 return SEARCH_RET_SEARCH_SUCCESS;
711 static int __search_sql_media_search_item_list_search_cb( Mitem* item, void* user_data)
713 GList** list = (GList**) user_data;
714 *list = g_list_append( *list, item );
719 static int __search_sql_media_search_result_by_api(int type, int offset, int limit,
720 minfo_file_type media_type, void *data)
724 struct appdata *ad = (struct appdata *)data;
729 int func_ret = SEARCH_RET_SEARCH_SUCCESS;
731 struct search_item_sel *sel_mem = NULL;
732 Elm_Object_Item *git = NULL;
735 struct search_item_sel *sel_mem_info = NULL;
738 GList *p_media_list = NULL;
740 minfo_item_filter item_filter;
742 memset(&item_filter, 0x00, sizeof(minfo_item_filter));
744 minfo_search_field_t search_field = MINFO_SEARCH_BY_NAME;
745 minfo_folder_type folder_type = MINFO_CLUSTER_TYPE_ALL;
747 item_filter.file_type = media_type;
749 /* MINFO_MEDIA_SORT_BY_NAME_DESC, MINFO_MEDIA_SORT_BY_DATE_DESC, MINFO_MEDIA_SORT_BY_DATE_ASC ... */
750 item_filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
752 item_filter.start_pos = offset;
753 item_filter.end_pos = offset+limit-1;
755 item_filter.with_meta = 0;
756 item_filter.favorite = MINFO_MEDIA_FAV_ALL;
758 /* get a set of items */
759 ret = minfo_get_item_list_search(ad->media_handle,
764 __search_sql_media_search_item_list_search_cb,
767 SEARCH_DEBUG_WARNING("minfo_get_item_list_search failed : %d\n", ret);
768 func_ret = SEARCH_RET_SEARCH_FAIL;
772 if (p_media_list == NULL) {
773 SEARCH_DEBUG_WARNING("minfo_get_item_list_search media list null\n");
774 func_ret = SEARCH_RET_SEARCH_FAIL;
778 result_cnt = g_list_length(p_media_list);
779 if (result_cnt == 0) {
780 SEARCH_DEBUG_WARNING("minfo_item_list length 0\n");
781 func_ret = SEARCH_RET_SEARCH_FAIL;
785 /* Set group title */
786 glist = ad->search_gl;
789 sel_mem = (struct search_item_sel *)calloc(1,
790 sizeof(struct search_item_sel));
792 sel_mem->type = type;
794 git = elm_genlist_item_append(glist,
795 (ad->itc_grouptitle),
797 (Elm_Object_Item *) NULL,
798 ELM_GENLIST_ITEM_GROUP,
801 ad->gl_result_group_item[type] = git;
804 /* Set search result to genlist */
805 for (i = 0; i < result_cnt; i++) {
811 item = (Mitem*)g_list_nth_data(p_media_list, i);
817 sel_mem_info = (struct search_item_sel *)calloc(1,
818 sizeof(struct search_item_sel));
820 sel_mem_info->type = type;
822 if ((item->display_name) && (strlen(item->display_name) > 0)) {
823 char* markup_text_1line = elm_entry_utf8_to_markup(item->display_name);
825 strncpy(sel_mem_info->main_buf,
826 search_markup_keyword(markup_text_1line,
827 ad->not_markup_search_word,
829 MAX_LENGTH_PER_LINE - 1);
830 SEARCH_FREE(markup_text_1line);
833 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID, "%d",
836 snprintf(sel_mem_info->path, MAX_LENGTH_PER_PATH - 1, "%s",
839 elm_genlist_item_append(glist,
840 (ad->itc_pslist_1line),
842 ad->gl_result_group_item
844 ELM_GENLIST_ITEM_NONE,
845 search_gl_phone_result_sel,
850 /* delete list to avoid memory leak */
851 for (i = 0; i < result_cnt; i++) {
852 item = (Mitem*)g_list_nth_data(p_media_list, i);
853 minfo_destroy_mtype_item(item);
856 g_list_free(p_media_list);
859 /* Set more title to genlist (under 'search all') */
860 if (result_cnt == limit) {
861 ad->cate_info[type].next_point = offset + result_cnt - 1;
864 (struct search_item_sel *)calloc(1,
865 sizeof(struct search_item_sel));
866 sel_mem->type = type;
868 elm_genlist_item_append(ad->search_gl, (ad->itc_listmore),
869 sel_mem, ad->gl_result_group_item[type],
870 ELM_GENLIST_ITEM_NONE,
871 search_gl_result_more_item_append_cb,
877 return SEARCH_RET_SEARCH_SUCCESS;
881 int search_sql_image_search_result_by_api(int type, int offset, int limit,
888 ret = __search_sql_media_search_result_by_api(type,
899 int search_sql_video_search_result_by_api(int type, int offset, int limit,
906 ret = __search_sql_media_search_result_by_api(type,
917 int search_sql_music_search_result_by_api(int type, int offset, int limit,
922 struct appdata *ad = (struct appdata *)data;
925 int ret = SEARCH_RET_SEARCH_NONE;
929 struct search_item_sel *sel_mem = NULL;
930 Elm_Object_Item *git = NULL;
932 struct search_item_sel *sel_mem_info = NULL;
935 AudioHandleType *handle = NULL;
937 rc = audio_svc_search_item_new(&handle, limit);
939 SEARCH_DEBUG_WARNING("audio_svc_search_item_new failed:%d\n",
944 rc = audio_svc_list_by_search(ad->media_handle,
946 AUDIO_SVC_ORDER_BY_TITLE_ASC,
949 AUDIO_SVC_SEARCH_TITLE,
951 strlen(ad->search_word),
952 AUDIO_SVC_SEARCH_ALBUM,
954 strlen(ad->search_word),
955 AUDIO_SVC_SEARCH_ARTIST,
957 strlen(ad->search_word),
960 if (rc != AUDIO_SVC_ERROR_NONE) {
961 SEARCH_DEBUG_WARNING("audio_svc_list_by_search error : %d",
964 ret = SEARCH_RET_SEARCH_FAIL;
968 for (loop_cnt = 0; loop_cnt < limit; loop_cnt++) {
969 AudioHandleType *item = NULL;
972 char *pathname = NULL;
975 char* audio_id = NULL;
977 rc = audio_svc_search_item_get(handle, loop_cnt, &item);
981 if (loop_cnt == limit -1)
984 audio_svc_item_get_val(item,
985 AUDIO_SVC_TRACK_DATA_AUDIO_ID, &audio_id, &size,
986 AUDIO_SVC_TRACK_DATA_PATHNAME, &pathname, &size,
987 AUDIO_SVC_TRACK_DATA_TITLE, &title, &size,
988 AUDIO_SVC_TRACK_DATA_ARTIST, &artist, &size,
989 AUDIO_SVC_TRACK_DATA_ALBUM, &album, &size,
992 if( audio_id == NULL) {
993 SEARCH_DEBUG_WARNING("audio_id value error. loop break");
997 ret = SEARCH_RET_SEARCH_SUCCESS;
999 if ((loop_cnt == 0) && (offset == 0)) {
1000 /* Set group title */
1001 sel_mem = (struct search_item_sel *)calloc(1,
1002 sizeof(struct search_item_sel));
1004 sel_mem->type = type;
1006 git = elm_genlist_item_append(ad->search_gl,
1007 (ad->itc_grouptitle),
1009 (Elm_Object_Item *) NULL,
1010 ELM_GENLIST_ITEM_GROUP,
1013 ad->gl_result_group_item[type] = git;
1016 sel_mem_info = (struct search_item_sel *)calloc(1,
1017 sizeof(struct search_item_sel));
1019 sel_mem_info->type = type;
1021 if ((title) && (strlen(title) > 0)) {
1022 char* markup_text_1line = elm_entry_utf8_to_markup(title);
1024 strncpy(sel_mem_info->main_buf,
1025 search_markup_keyword(markup_text_1line, ad->not_markup_search_word, &is_word_in_str),
1026 MAX_LENGTH_PER_LINE - 1);
1027 SEARCH_FREE(markup_text_1line);
1030 if (is_word_in_str) {
1031 if ((artist) && (strlen(artist) > 0)) {
1032 char* markup_text_2line = elm_entry_utf8_to_markup(artist);
1034 strncpy(sel_mem_info->sub_buf,
1035 search_markup_keyword(markup_text_2line,
1036 ad->not_markup_search_word,
1038 MAX_LENGTH_PER_LINE - 1);
1039 SEARCH_FREE(markup_text_2line);
1042 memset(sel_mem_info->sub_buf, '\0', MAX_LENGTH_PER_LINE);
1044 if ((artist) && (strlen(artist) > 0)) {
1045 char* markup_text_2line = elm_entry_utf8_to_markup(artist);
1047 strncpy(sel_mem_info->sub_buf,
1048 search_markup_keyword(markup_text_2line,
1049 ad->not_markup_search_word,
1051 MAX_LENGTH_PER_LINE - 1);
1052 SEARCH_FREE(markup_text_2line);
1055 if (is_word_in_str == false && (album) && (strlen(album) > 0)) {
1056 char* markup_text_2line = elm_entry_utf8_to_markup(album);
1058 strncpy(sel_mem_info->sub_buf,
1059 search_markup_keyword(markup_text_2line,
1060 ad->not_markup_search_word,
1062 MAX_LENGTH_PER_LINE - 1);
1063 SEARCH_FREE(markup_text_2line);
1066 if (is_word_in_str == false) {
1067 SEARCH_DEBUG_LOG("search_result is 0. No match keyword in title,album,artist string");
1071 snprintf(sel_mem_info->main_id,
1072 MAX_LENGTH_PER_ID - 1, "%s", audio_id);
1074 strncpy(sel_mem_info->path, pathname, MAX_LENGTH_PER_PATH);
1076 elm_genlist_item_append(ad->search_gl,
1077 (ad->itc_pslist_2line),
1079 ad->gl_result_group_item[type],
1080 ELM_GENLIST_ITEM_NONE,
1081 search_gl_phone_result_sel,
1083 sel_mem_info = NULL;
1087 /* Set more title to genlist (under 'search all') */
1088 if (loop_cnt == limit) {
1089 ad->cate_info[type].next_point = offset + loop_cnt - 1;
1092 (struct search_item_sel *)calloc(1,
1093 sizeof(struct search_item_sel));
1094 sel_mem->type = type;
1096 elm_genlist_item_append(ad->search_gl, (ad->itc_listmore),
1097 sel_mem, ad->gl_result_group_item[type],
1098 ELM_GENLIST_ITEM_NONE,
1099 search_gl_result_more_item_append_cb,
1105 audio_svc_search_item_free(handle);
1112 ail_cb_ret_e __search_sql_menu_search_result_cb(
1113 const ail_appinfo_h appinfo,
1118 struct appdata *ad = (struct appdata *)data;
1120 struct search_item_sel *sel_mem = NULL;
1121 struct search_item_sel *sel_mem_info = NULL;
1123 int type = SEARCH_TYPE_PHONE_MENU;
1125 bool is_word_in_str;
1128 if(ad->cate_info[type].loop_cnt < ad->cate_info[type].next_point) {
1129 ad->cate_info[type].loop_cnt++;
1130 return AIL_CB_RET_CONTINUE;
1133 if(ad->cate_info[type].next_point <
1134 ad->cate_info[type].offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
1136 sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
1137 sel_mem_info->type = type;
1139 /********** START : set search result to sel_mem_info buf ************/
1142 char *package = NULL;
1144 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
1145 if ((package) && (strlen(package) > 0)) {
1147 if(strcmp(package, SEARCHPKG) == 0) {
1148 ad->cate_info[type].loop_cnt++;
1149 SEARCH_FREE(sel_mem_info);
1150 return AIL_CB_RET_CONTINUE;
1153 strncpy(sel_mem_info->path, package, MAX_LENGTH_PER_PATH - 1);
1156 ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &name);
1157 if ((name) && (strlen(name) > 0)) {
1158 char* markup_text_1line = elm_entry_utf8_to_markup(name);
1160 strncpy(sel_mem_info->main_buf,
1161 search_markup_keyword(markup_text_1line, ad->not_markup_search_word,&is_word_in_str),
1162 MAX_LENGTH_PER_LINE - 1);
1163 SEARCH_FREE(markup_text_1line);
1165 SEARCH_DEBUG_LOG("name : %s", name);
1167 SEARCH_DEBUG_LOG("name : null");
1169 if(ad->cate_info[type].next_point == 0) {
1170 /* Set group title */
1171 sel_mem = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
1172 sel_mem->type = type;
1173 ad->gl_result_group_item[type] = elm_genlist_item_append(
1175 (ad->itc_grouptitle),
1177 (Elm_Object_Item *) NULL,
1178 ELM_GENLIST_ITEM_GROUP,
1183 /********** END : set search result to sel_mem_info buf *************/
1185 elm_genlist_item_append(ad->search_gl,
1186 (ad->itc_pslist_1line),
1188 ad->gl_result_group_item[type],
1189 ELM_GENLIST_ITEM_NONE,
1190 search_gl_phone_result_sel,
1193 ad->cate_info[type].next_point++;
1194 ad->cate_info[type].loop_cnt++;
1196 ret = AIL_CB_RET_CONTINUE;
1198 } else if (ad->cate_info[type].next_point ==
1199 ad->cate_info[type].offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
1201 /* Check that only "SMARTSEARCH" is left in more result */
1202 if(ad->cate_info[type].next_point == ad->cate_info[type].result_cnt-1) {
1204 char *package = NULL;
1206 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
1207 if ((package) && (strlen(package) > 0) && (strcmp(package, SEARCHPKG) == 0)) {
1208 return AIL_CB_RET_CANCEL;
1212 /* Set more title to genlist (under 'search all') */
1213 sel_mem = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
1214 sel_mem->type = type;
1216 elm_genlist_item_append(ad->search_gl, (ad->itc_listmore),
1217 sel_mem, ad->gl_result_group_item[type],
1218 ELM_GENLIST_ITEM_NONE,
1219 search_gl_result_more_item_append_cb,
1222 ret = AIL_CB_RET_CANCEL;
1224 SEARCH_DEBUG_WARNING
1225 ("__search_sql_memo_search_result_cb wrong index : %d",
1226 ad->cate_info[type].next_point);
1228 ret = AIL_CB_RET_CANCEL;
1236 int search_sql_menu_search_result_by_api(int type, int offset, int limit,
1237 char *keyword, void *data)
1241 struct appdata *ad = (struct appdata *)data;
1246 ail_filter_h filter;
1249 rc = ail_filter_new(&filter);
1250 if (rc != AIL_ERROR_OK) {
1251 SEARCH_DEBUG_WARNING("menu search - ail_filter_new error : %d", rc);
1252 return SEARCH_RET_SEARCH_FAIL;
1255 rc = ail_filter_add_str(filter, AIL_PROP_NAME_STR, keyword);
1256 if (rc != AIL_ERROR_OK) {
1257 SEARCH_DEBUG_WARNING("menu search - ail_filter_add_str error : %d", rc);
1258 ret = SEARCH_RET_SEARCH_FAIL;
1262 rc = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false);
1263 if (rc != AIL_ERROR_OK) {
1264 SEARCH_DEBUG_WARNING("menu search - ail_filter_add_bool error : %d", rc);
1265 ret = SEARCH_RET_SEARCH_FAIL;
1269 rc = ail_filter_count_appinfo(filter, &cnt);
1270 if( rc != AIL_ERROR_OK) {
1271 SEARCH_DEBUG_WARNING("menu search - ail_filter_count_appinfo error : %d", rc);
1272 ret = SEARCH_RET_SEARCH_FAIL;
1276 ad->cate_info[type].result_cnt = cnt;
1279 ad->cate_info[type].loop_cnt = 0;
1280 rc = ail_filter_list_appinfo_foreach(filter, __search_sql_menu_search_result_cb, data);
1281 if( rc != AIL_ERROR_OK) {
1282 SEARCH_DEBUG_WARNING("menu search - ail_filter_list_appinfo_foreach error : %d", rc);
1283 ret = SEARCH_RET_SEARCH_FAIL;
1287 if(ad->cate_info[type].next_point == 0) {
1288 ret = SEARCH_RET_SEARCH_NONE;
1290 ret = SEARCH_RET_SEARCH_SUCCESS;
1293 ret = SEARCH_RET_SEARCH_NONE;
1297 ail_filter_destroy(filter);
1304 int search_sql_msg_search_result_by_api(int type, int offset, int limit,
1309 struct appdata *ad = (struct appdata *)data;
1314 struct search_item_sel *sel_mem = NULL;
1315 Elm_Object_Item *git = NULL;
1317 struct search_item_sel *sel_mem_info = NULL;
1318 bool is_word_in_str;
1322 MSG_HANDLE_T msgHandle = NULL;
1323 MSG_ERROR_T err = MSG_SUCCESS;
1327 bool is_more_btn = false;
1328 bool is_word_in_title = false;
1330 int address_cnt = 0;
1332 MSG_SEARCH_CONDITION_S searchCon = {0,};
1334 searchCon.msgType = MSG_TYPE_INVALID;
1335 searchCon.folderId = MSG_ALLBOX_ID;
1336 searchCon.pSearchVal = ad->search_word;
1338 err = msg_search_message(ad->msg_handle, &searchCon, offset, limit, &msgList);
1340 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1341 SEARCH_DEBUG_WARNING("msg_search_message is failed : %d", err);
1342 return SEARCH_RET_SEARCH_FAIL;
1345 if (msgList.nCount <= 0) {
1346 SEARCH_DEBUG_WARNING("no msg search result");
1347 ret = SEARCH_RET_SEARCH_NONE;
1350 /* Set group title */
1351 glist = ad->search_gl;
1355 (struct search_item_sel *)calloc(1,
1358 sel_mem->type = type;
1361 elm_genlist_item_append(glist,
1362 (ad->itc_grouptitle),
1364 (Elm_Object_Item *) NULL,
1365 ELM_GENLIST_ITEM_GROUP,
1368 ad->gl_result_group_item[type] = git;
1371 /* Set search result to genlist */
1373 if(msgList.nCount < limit) {
1374 loop_cnt = msgList.nCount;
1375 is_more_btn = false;
1381 /********** START : set search result to sel_mem_info buf ************/
1383 for (i = 0; i < loop_cnt; i++) {
1384 const char *text_1line = NULL;
1385 const char *text_2line = NULL;
1386 const char *msg_address = NULL;
1387 const char *markup_keyword = NULL;
1389 sel_mem_info = (struct search_item_sel *)
1390 calloc(1,sizeof(struct search_item_sel));
1391 sel_mem_info->type = type;
1393 snprintf(sel_mem_info->main_id, MAX_LENGTH_PER_ID - 1, "%d", msg_get_message_id(msgList.msgInfo[i]));
1395 /* Set 1st line string */
1396 if(msg_is_mms(msgList.msgInfo[i])) {
1398 char* markup_text_1line = NULL;
1400 text_1line = msg_get_subject(msgList.msgInfo[i]);
1401 markup_text_1line = elm_entry_utf8_to_markup(text_1line);
1403 markup_keyword = search_markup_keyword(markup_text_1line,
1404 ad->not_markup_search_word,
1407 if (!is_word_in_title) {
1408 text_1line = msg_mms_get_text_contents(msgList.msgInfo[i]);
1409 markup_text_1line = elm_entry_utf8_to_markup(text_1line);
1410 markup_keyword = search_markup_keyword(markup_text_1line,
1411 ad->not_markup_search_word,
1415 if ((text_1line) && (strlen(text_1line) > 0 ))
1416 strncpy(sel_mem_info->main_buf, markup_keyword, MAX_LENGTH_PER_LINE - 1);
1418 SEARCH_FREE(markup_text_1line);
1421 char* markup_text_1line = NULL;
1423 text_1line = msg_sms_get_message_body(msgList.msgInfo[i]);
1424 markup_text_1line = elm_entry_utf8_to_markup(text_1line);
1425 markup_keyword = search_markup_keyword(markup_text_1line,
1426 ad->not_markup_search_word,
1429 if ((text_1line) && (strlen(text_1line) > 0))
1430 strncpy(sel_mem_info->main_buf, markup_keyword, MAX_LENGTH_PER_LINE - 1);
1432 SEARCH_FREE(markup_text_1line);
1435 /* Set 2nd line string */
1436 address_cnt = msg_get_address_count(msgList.msgInfo[i]);
1438 for(j = 0; j < address_cnt; j++) {
1440 if(msg_get_ith_contact_id(msgList.msgInfo[i],j) > 0) {
1441 text_2line = msg_get_ith_name(msgList.msgInfo[i],j);
1443 text_2line = msg_get_ith_address(msgList.msgInfo[i],j);
1446 if ((text_2line) && (strlen(text_2line) > 0)) {
1447 char* markup_text_2line = NULL;
1449 markup_text_2line = elm_entry_utf8_to_markup(text_2line);
1450 strncpy(sel_mem_info->sub_buf,
1451 search_markup_keyword(markup_text_2line,
1452 ad->not_markup_search_word,
1454 MAX_LENGTH_PER_LINE - 1);
1455 SEARCH_FREE(markup_text_2line);
1458 if ((is_word_in_title) || (is_word_in_str)) {
1463 elm_genlist_item_append(glist,
1464 (ad->itc_pslist_2line),
1466 ad->gl_result_group_item[type],
1467 ELM_GENLIST_ITEM_NONE,
1468 search_gl_phone_result_sel,
1470 sel_mem_info = NULL;
1473 msg_release_message_list(&msgList);
1475 /* Set more title to genlist (under 'search all') */
1477 ad->cate_info[type].next_point = offset + limit - 1;
1479 sel_mem = (struct search_item_sel *)
1480 calloc(1,sizeof(struct search_item_sel));
1481 sel_mem->type = type;
1483 elm_genlist_item_append(ad->search_gl, (ad->itc_listmore),
1484 sel_mem, ad->gl_result_group_item[type],
1485 ELM_GENLIST_ITEM_NONE,
1486 search_gl_result_more_item_append_cb,
1490 ret = SEARCH_RET_SEARCH_SUCCESS;