Tizen 2.0 Release
[apps/core/preloaded/myfiles.git] / src / widget / mf-search-bar.c
1 /*
2  * Copyright 2013         Samsung Electronics Co., Ltd
3  *
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
7  *
8  *  http://floralicense.org/license/
9  *
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.
15  */
16
17
18
19 #include <Eina.h>
20 #include <Ecore_X.h>
21
22 #include "mf-widget.h"
23 #include "mf-gengrid.h"
24 #include "mf-util.h"
25 #include "mf-dlog.h"
26 #include "mf-fm-svc-wrapper.h"
27 #include "mf-launch.h"
28 #include "mf-language-mgr.h"
29 #include "mf-tray-item.h"
30
31 #define MF_SEARCH_OPTION_DEF (MF_SEARCH_OPT_DIR | MF_SEARCH_OPT_FILE)
32 #define MF_SEARCH_ROOT_NUM 1
33 #define MF_SEARCH_TIMER_INTERVAL 0.5
34
35 extern Elm_Genlist_Item_Class itc, userfolderitc;
36 extern Elm_Genlist_Item_Class categoryitc;
37
38 extern Elm_Gengrid_Item_Class gic;
39 extern Elm_Gengrid_Item_Class search_itc;
40 extern int flagSearchMsg;
41 extern pthread_mutex_t gLockSearchMsg;
42 extern pthread_cond_t gCondSearchMsg;
43
44 Elm_Gengrid_Item_Class g_search_all_itc;
45 Elm_Gengrid_Item_Class search_all_itc;
46
47 typedef struct {
48         char *size;
49         char *create_date;
50 } mf_search_detail_infor_s;
51
52 static void __mf_search_bar_click_item(struct appdata *data, GString * path)
53 {
54         MF_TRACE_BEGIN;
55         struct appdata *ap = data;
56         assert(ap);
57         if (ap->mf_Status.path == NULL || ap->mf_Status.path->str == NULL) {
58                 return;
59         }
60         GString *new_path = NULL;
61
62
63         int error_code = 0;
64         int mmc_card = 0;
65
66         if (ap->mf_Status.more == MORE_RENAME) {
67                 mf_genlist_rename_done(ap, NULL, NULL);
68                 return;
69         }
70         myfileNaviBar *pNavi_s = mf_navi_bar_get_in_use(ap);
71         mf_retm_if(pNavi_s == NULL, "get navi structure failed");
72         if (ap->mf_Status.search_handler > 0) {
73                 mf_search_stop(ap->mf_Status.search_handler);
74                 mf_search_finalize(&ap->mf_Status.search_handler);
75         }
76
77         error_code = mf_util_is_mmc_on(&mmc_card);
78
79         if (mf_fm_svc_wrapper_is_dir(path)) {
80
81                 if (ap->mf_FileOperation.search_result_list) {
82                         mf_util_free_eina_list_with_data(&(ap->mf_FileOperation.search_result_list), MYFILE_TYPE_CHAR);
83                 }
84                 elm_object_focus_set(ap->mf_MainWindow.pSearchEntry, EINA_FALSE);
85
86                 ap->mf_Status.view_type = mf_view_normal;
87                 ap->mf_Status.more = MORE_DEFAULT;
88                 new_path = g_string_new(path->str);
89                 mf_debug("path is %s\n", ap->mf_Status.path->str);
90
91                 /*set new path*/
92                 g_string_free(ap->mf_Status.path, TRUE);
93                 ap->mf_Status.path = NULL;
94
95                 ap->mf_Status.path = new_path;
96
97                 if (pNavi_s->pCurrentPath != NULL) {
98                         free(pNavi_s->pCurrentPath);
99                         pNavi_s->pCurrentPath = NULL;
100                 }
101                 pNavi_s->pCurrentPath = g_strdup(new_path->str);
102
103                 mf_widget_refresh_view(ap);
104         } else {
105                 struct timeval mytime;
106                 gettimeofday(&mytime, NULL);
107                 mf_debug("[myfiles click time] %ld sec %ld usec \n", mytime.tv_sec, mytime.tv_usec);
108
109                 int ret = 0;
110                 ret = mf_launch_service(ap, path->str);
111                 mf_debug("ret is %d\n", ret);
112                 if (ret) {
113                         ap->mf_MainWindow.pNormalPopup =
114                                 mf_popup_create_popup(ap, POPMODE_TEXT, NULL, GET_SYS_STR(MF_LABEL_UNSUPPORT_FILE_TYPE), NULL, NULL, NULL, NULL, NULL);
115                 }
116         }
117         MF_TRACE_END;
118 }
119
120 static void __mf_search_bar_item_sel(void *data, Evas_Object * obj, void *event_info)
121 {
122         mf_debug("Start");
123         assert(data);
124
125         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
126         if (item != NULL) {
127                 mfItemData_s *selected = (mfItemData_s *) elm_object_item_data_get(item);
128
129                 elm_genlist_item_selected_set(item, FALSE);
130                 __mf_search_bar_click_item(data, selected->m_ItemName);
131         }
132 }
133
134 static void __mf_search_bar_grid_item_sel(void *data, Evas_Object * obj, void *event_info)
135 {
136         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
137         if (item != NULL) {
138                 mfItemData_s *selected = (mfItemData_s *) elm_object_item_data_get(item);
139                 mf_retm_if(selected == NULL, "selected is NULL");
140                 mf_retm_if(selected->m_ItemName == NULL, "selected->m_ItemName is NULL");
141                 mf_retm_if(selected->m_ItemName->str == NULL, "selected->m_ItemName->str is NULL");
142
143                 __mf_search_bar_click_item(data, selected->m_ItemName);
144         }
145 }
146
147 static void __mf_search_bar_sel_search_all(void *data, Evas_Object * obj, void *event_info)
148 {
149         mf_search_bar_search_started_callback(data, NULL, NULL);
150 }
151
152 static Evas_Object *_gl_content_get(void *data, Evas_Object * obj, const char *part)
153 {
154
155         mf_debug("part is [%s]", part);
156         if (!strcmp(part, "elm.icon")) {
157                 Evas_Object *btn = elm_button_add(obj);
158                 elm_object_text_set(btn, GET_STR(MF_LABEL_SEARCH_ALL));
159                 evas_object_smart_callback_add(btn, "clicked", __mf_search_bar_sel_search_all, data);
160
161                 return btn;
162         } else if(!strcmp(part, "elm.swallow.icon")) {
163                 Evas_Object *btn = elm_button_add(obj);
164                 elm_object_text_set(btn, GET_STR(MF_LABEL_SEARCH_ALL));
165                 evas_object_smart_callback_add(btn, "clicked", __mf_search_bar_sel_search_all, data);
166                 return btn;
167         }
168         return NULL;
169 }
170
171
172 void mf_search_bar_search_all_item_append(void *data)
173 {
174
175         MF_TRACE_BEGIN;
176         struct appdata *ap = (struct appdata *)data;
177         mf_retm_if(ap == NULL, "input data error");
178
179         if (ap->mf_Status.flagViewType == MF_VIEW_STYLE_THUMBNAIL) {
180
181                 Elm_Gengrid_Item_Class *itc = elm_gengrid_item_class_new();
182                 itc->item_style = "default_gridtext";
183                 itc->func.text_get = NULL;
184                 itc->func.content_get = _gl_content_get;
185                 itc->func.state_get = NULL;
186                 itc->func.del = NULL;
187
188                 elm_gengrid_item_append(ap->mf_MainWindow.pNaviGengrid, itc, ap, NULL, NULL);
189
190         } else {
191                 Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
192                 itc->item_style = "1icon";
193                 itc->func.text_get = NULL;
194                 itc->func.content_get = _gl_content_get;
195                 itc->func.state_get = NULL;
196                 itc->func.del = NULL;
197                 elm_genlist_item_append(ap->mf_MainWindow.pNaviGenlist, itc, ap, NULL,
198                                              ELM_GENLIST_ITEM_NONE, NULL, NULL);
199         }
200         ap->mf_Status.flagSearchAll = EINA_TRUE;
201 }
202 void mf_search_bar_item_append(void *data, void *user_data)
203 {
204         MF_TRACE_BEGIN;
205         struct appdata *ap = (struct appdata *)user_data;
206         mf_retm_if(ap == NULL, "input data error");
207         char *item_name = (char *)data;
208         mf_retm_if(item_name == NULL, "input item_name error");
209         mfItemData_s *m_TempItem = NULL;
210
211         GString *search_path = g_string_new(item_name);
212
213         g_string_free(search_path, TRUE);
214         search_path = NULL;
215         if (ap->mf_Status.view_type == mf_view_root_category && ap->mf_Status.more != MORE_SEARCH) {
216                 mf_util_generate_list(&ap->mf_FileOperation.category_list, item_name, FILE_TYPE_FILE);
217         }
218         m_TempItem = (mfItemData_s *) malloc(sizeof(mfItemData_s));
219
220         if (m_TempItem == NULL) {
221                 return;
222         }
223         memset(m_TempItem, 0, sizeof(mfItemData_s));
224
225         m_TempItem->m_ItemName = g_string_new(item_name);
226         m_TempItem->size = NULL;
227         m_TempItem->create_date = NULL;
228         m_TempItem->m_checked = FALSE;
229         m_TempItem->pCheckBox = NULL;
230         m_TempItem->thumb_path = NULL;
231         m_TempItem->real_thumb_flag = FALSE;
232         m_TempItem->unregister_lang_mgr = TRUE;
233         m_TempItem->media = NULL;
234         m_TempItem->ap = ap;
235
236         /*delete timer if exists*/
237
238         if (ap->mf_Status.flagViewType == MF_VIEW_STYLE_THUMBNAIL) {
239                 Elm_Object_Item *git = NULL;
240                 git = elm_gengrid_item_append(ap->mf_MainWindow.pNaviGengrid, &gic, m_TempItem, __mf_search_bar_grid_item_sel, ap);
241                 mf_language_mgr_register_gengrid_item(git);
242                 m_TempItem->item = git;
243         }
244         else
245         {
246                 Elm_Object_Item *it = NULL;
247                 if (ap->mf_Status.view_type == mf_view_root_category && ap->mf_Status.more != MORE_SEARCH) {
248                         it = elm_genlist_item_append(ap->mf_MainWindow.pNaviGenlist, &categoryitc, m_TempItem, NULL,
249                                                      ELM_GENLIST_ITEM_NONE, mf_genlist_gl_sel, m_TempItem);
250                 } else {
251                         it = elm_genlist_item_append(ap->mf_MainWindow.pNaviGenlist, &search_itc, m_TempItem, NULL,
252                                                      ELM_GENLIST_ITEM_NONE, __mf_search_bar_item_sel, ap);
253                 }
254                 m_TempItem->item = it;
255         }
256
257         mf_debug("get is [%d]", elm_genlist_items_count(ap->mf_MainWindow.pNaviGenlist));
258         MF_TRACE_END;
259
260 }
261
262 static void __mf_search_bar_genlist_del_cb(void *data, Evas * e, Evas_Object * obj, void *event_info)
263 {
264         MF_TRACE_BEGIN;
265         struct appdata *ap = (struct appdata *)data;
266         mf_retm_if(ap == NULL, "ap is NULL");
267         if(ap->mf_MainWindow.pSearchViewTimer) {
268                 ecore_timer_del(ap->mf_MainWindow.pSearchViewTimer);
269                 ap->mf_MainWindow.pSearchViewTimer = NULL;
270         }
271         MF_TRACE_END;
272 }
273
274 static void __mf_search_bar_result_cb(mf_search_result_t *result, void *user_data)
275 {
276         MF_TRACE_BEGIN;
277         mf_retm_if(result == NULL, "result is NULL");
278
279         struct appdata *ap = (struct appdata *)user_data;
280         mf_retm_if(ap == NULL, "ap is NULL");
281
282         myfileNaviBar *pNavi_s = mf_navi_bar_get_in_use(ap);
283         mf_retm_if(pNavi_s == NULL, "pNavi_s is NULL");
284
285         Evas_Object *pSearchBarLabel = NULL;
286
287         if (ap->mf_Status.view_type != mf_view_root_category) {
288                 elm_object_focus_set(ap->mf_MainWindow.pSearchEntry, EINA_TRUE);
289         }
290
291 #ifdef MYFILE_SPLIT_VIEW
292         if (ap->mf_FileOperation.search_result_list) {
293                 mf_util_free_eina_list_with_data(&(ap->mf_FileOperation.search_result_list), MYFILE_TYPE_CHAR);
294         }
295 #endif
296         if (ap->mf_Status.view_type == mf_view_root_category && ap->mf_Status.more != MORE_SEARCH) {
297                 if (ap->mf_FileOperation.category_list) {
298                         mf_util_free_eina_list_with_data(&(ap->mf_FileOperation.category_list), MYFILE_TYPE_FSNODE);
299                 }
300         }
301
302         if (g_list_length(result->dir_list) + g_list_length(result->file_list) == 0) {
303
304                 Evas_Object *parent = NULL;
305                 parent = ap->mf_MainWindow.pNaviLayout;
306                 ap->mf_Status.flagNoContent = EINA_TRUE;
307                 pSearchBarLabel = mf_widget_create_no_content(parent);
308                 elm_object_part_text_set(pSearchBarLabel, "elm.text", GET_SYS_STR(LABEL_NO_RESULT));
309
310                 if (ap->mf_Status.view_type != mf_view_root_category) {
311                         elm_object_part_content_set(parent, "content", pSearchBarLabel);
312                 } else {
313                         elm_object_part_content_set(parent, "content", pSearchBarLabel);
314                         Evas_Object *btn = mf_widget_get_part_content(ap->mf_MainWindow.pNaviBar, NAVI_BOTTOM_BUTTON_1_PART);
315                         elm_object_disabled_set(btn, EINA_TRUE);
316                 }
317
318         } else {
319                 ap->mf_Status.flagNoContent = EINA_FALSE;
320                 if (ap->mf_Status.view_type == mf_view_root_category && ap->mf_Status.more != MORE_SEARCH) {
321                         mf_genlist_set_category_list_style();
322                         mf_navi_bar_title_set(ap);
323                 }
324                 if (ap->mf_Status.flagViewType == MF_VIEW_STYLE_LIST || ap->mf_Status.flagViewType == MF_VIEW_SYTLE_LIST_DETAIL) {
325                         if (ap->mf_MainWindow.pNaviGenlist == NULL) {
326                                 ap->mf_MainWindow.pNaviGenlist = elm_genlist_add(ap->mf_MainWindow.pNaviLayout);
327                         }
328                         elm_genlist_clear(ap->mf_MainWindow.pNaviGenlist);
329
330                         elm_genlist_mode_set(ap->mf_MainWindow.pNaviGenlist, ELM_LIST_COMPRESS);
331                         elm_object_focus_set(ap->mf_MainWindow.pNaviGenlist, EINA_FALSE);
332                         evas_object_size_hint_weight_set(ap->mf_MainWindow.pNaviGenlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
333                         evas_object_size_hint_align_set(ap->mf_MainWindow.pNaviGenlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
334
335                         //elm_genlist_homogeneous_set(ap->mf_MainWindow.pNaviGenlist, EINA_TRUE);
336                         evas_object_smart_callback_add(ap->mf_MainWindow.pNaviGenlist, "drag,start,right", mf_genlist_gl_mode_sweep_set, ap);
337                         evas_object_smart_callback_add(ap->mf_MainWindow.pNaviGenlist, "drag,start,left", mf_genlist_gl_mode_sweep_unset, ap);
338                         evas_object_smart_callback_add(ap->mf_MainWindow.pNaviGenlist, "drag,start,up", mf_genlist_gl_mode_cancel, ap);
339                         evas_object_smart_callback_add(ap->mf_MainWindow.pNaviGenlist, "drag,start,down", mf_genlist_gl_mode_cancel, ap);
340                         //evas_object_smart_callback_add(ap->mf_MainWindow.pNaviGenlist, "drag,stop", mf_genlist_gl_mode_sweep_stop, NULL);
341                         if (ap->mf_Status.view_type == mf_view_root_category && ap->mf_Status.more != MORE_SEARCH) {
342                                 evas_object_smart_callback_add(ap->mf_MainWindow.pNaviGenlist, "selected", mf_genlist_gl_selected, ap);
343                         }
344                         evas_object_event_callback_add(ap->mf_MainWindow.pNaviGenlist,EVAS_CALLBACK_FREE, __mf_search_bar_genlist_del_cb, ap);
345                         evas_object_show(ap->mf_MainWindow.pNaviGenlist);
346                         mfNaviBarSetContent(ap, ap->mf_MainWindow.pNaviLayout, ap->mf_MainWindow.pNaviGenlist);
347                 } else {
348                         if (ap->mf_MainWindow.pNaviGengrid == NULL) {
349                                 ap->mf_MainWindow.pNaviGengrid = mf_gengrid_create_grid(ap->mf_MainWindow.pNaviLayout);
350                         }
351                         elm_gengrid_clear(ap->mf_MainWindow.pNaviGengrid);
352                         if (MF_SCALE_FACTORY == 1) {
353                                 elm_gengrid_item_size_set(ap->mf_MainWindow.pNaviGengrid, MF_HD_GENGRID_ITEM_WIDTH, MF_HD_GENGRID_ITEM_HEIGTH);
354                         } else {
355                                 elm_gengrid_item_size_set(ap->mf_MainWindow.pNaviGengrid, MF_WVGA_GENGRID_ITEM_WIDTH, MF_WVGA_GENGRID_ITEM_HEIGTH);
356                         }
357                         evas_object_show(ap->mf_MainWindow.pNaviGengrid);
358                         mfNaviBarSetContent(ap, ap->mf_MainWindow.pNaviLayout, ap->mf_MainWindow.pNaviGengrid);
359                 }
360                 if (result->dir_list != NULL) {
361                         g_list_foreach(result->dir_list, mf_search_bar_item_append, ap);
362                 }
363                 if (result->file_list != NULL) {
364                         g_list_foreach(result->file_list, mf_search_bar_item_append, ap);
365                 }
366                 MF_TRACE_END;
367         }
368 }
369
370 static void __mf_search_bar_stop_cb(void *data, Evas_Object * obj, void *event_info)
371 {
372         struct appdata *ap = (struct appdata *)data;
373         mf_retm_if(ap == NULL, "input data error");
374
375         Evas_Object *btn = (Evas_Object *)obj;
376         const char *label = elm_object_text_get(btn);
377
378         if (g_strcmp0(label, GET_SYS_STR(LABEL_CANCEL)) == 0 ) {
379                 if (ap->mf_FileOperation.sync_pipe != NULL) {
380                         ecore_pipe_del(ap->mf_FileOperation.sync_pipe);
381                         ap->mf_FileOperation.sync_pipe = NULL;
382                 }
383
384                 __mf_search_bar_result_cb(((ms_handle_t *) ap->mf_Status.search_handler)->result, ap);
385
386                 if (ap->mf_Status.search_handler > 0) {
387                         mf_search_stop(ap->mf_Status.search_handler);
388                 }
389
390                 evas_object_del(ap->mf_MainWindow.pNormalPopup);
391                 ap->mf_MainWindow.pNormalPopup = NULL;
392
393                 if (ap->mf_Status.search_handler > 0) {
394                         mf_search_finalize(&ap->mf_Status.search_handler);
395                 }
396         }
397 }
398
399 static int __mf_search_bar_idle_search_msg_cope_finished(void *data)
400 {
401         pthread_mutex_lock(&gLockSearchMsg);
402         if (flagSearchMsg == 0) {
403                 flagSearchMsg = 1;
404                 pthread_cond_signal(&gCondSearchMsg);
405         }
406         pthread_mutex_unlock(&gLockSearchMsg);
407
408         return ECORE_CALLBACK_CANCEL;
409 }
410
411 static void __mf_search_bar_pipe_cb(void *data, void *buffer, unsigned int nbyte)
412 {
413         MF_TRACE_BEGIN;
414         struct appdata *ap = (struct appdata *)data;
415         if (ap == NULL) {
416                 mf_debug("input ap is NULL");
417                 goto MF_CONTINURE_SEARCH;
418         }
419
420         mf_search_pipe_msg *pSearchMsg = (mf_search_pipe_msg *) buffer;
421         if (pSearchMsg == NULL) {
422                 mf_debug("received message is NULL");
423                 goto MF_CONTINURE_SEARCH;
424         }
425
426         if (pSearchMsg->mf_sp_msg_type == MF_SEARCH_PIPE_MSG_RESULT_REPORT) {
427                 mf_debug("result get");
428         } else if (pSearchMsg->mf_sp_msg_type == MF_SEARCH_PIPE_MSG_ROOT_CHANGE) {
429                 mf_debug("path change   %s", pSearchMsg->current_path);
430                 char *new_desc = mf_fm_svc_wrapper_translate_path(pSearchMsg->current_path, MF_TRANS_OPTION_POPUP);
431                 elm_object_text_set(ap->mf_MainWindow.pSearchLabel, new_desc);
432                 if (pSearchMsg->current_path) {
433                         free(pSearchMsg->current_path);
434                         pSearchMsg->current_path = NULL;
435                 }
436                 if (new_desc != NULL) {
437                         free(new_desc);
438                         new_desc = NULL;
439                 }
440         } else if (pSearchMsg->mf_sp_msg_type == MF_SEARCH_PIPE_MSG_FINISHED) {
441                 evas_object_del(ap->mf_MainWindow.pNormalPopup);
442                 ap->mf_MainWindow.pNormalPopup = NULL;
443                 __mf_search_bar_result_cb((mf_search_result_t *) pSearchMsg->report_result, data);
444         }
445
446 MF_CONTINURE_SEARCH:
447         ecore_idler_add((Ecore_Task_Cb)__mf_search_bar_idle_search_msg_cope_finished, NULL);
448         MF_TRACE_END;
449 }
450
451 void mf_search_bar_category_search_start(void *data, int category)
452 {
453         MF_TRACE_BEGIN;
454         mf_retm_if(data == NULL, "data is NULL");
455         struct appdata *ap = (struct appdata *)data;
456         int root_num = MF_SEARCH_ROOT_NUM;
457
458         mf_genlist_create_search_itc();
459
460         root_num = 1;
461         const char *SearchRoot[3] = {0};
462         SearchRoot[0] = PHONE_FOLDER;
463         if (ap->mf_Status.iStorageState & MYFILE_MMC) {
464                 SearchRoot[root_num] = MEMORY_FOLDER;
465                 root_num++;
466         }
467         if (ap->mf_Status.iStorageState & MYFILE_OTG) {
468                 SearchRoot[root_num] = OTG_FOLDER;
469                 root_num++;
470         }
471
472         char *new_desc = NULL;
473         /*Start Search routine*/
474         if (!mf_search_start(ap->mf_Status.search_handler, SearchRoot, root_num, \
475                              NULL, MF_SEARCH_OPT_FILE, (void *)ap, mf_tray_item_type, category)) {
476                 /*generate the popup used to show search path
477                 **it's sure that new_desc is not NULL even if original path is NULL*/
478                 new_desc = mf_fm_svc_wrapper_translate_path(ap->mf_Status.path->str, MF_TRANS_OPTION_POPUP);
479                 ap->mf_MainWindow.pNormalPopup = mf_ug_popup_create_search(ap, __mf_search_bar_stop_cb, ap);
480                         //mf_popup_create_popup(ap, POPMODE_TEXT_BTN_SEARCH, NULL, new_desc, NULL, NULL, NULL, __mf_search_bar_stop_cb, ap);
481         } else {
482                 mf_debug("search failed");
483         }
484
485         if (new_desc != NULL) {
486                 free(new_desc);
487                 new_desc = NULL;
488         }
489
490         MF_TRACE_END;
491 }
492 static bool __mf_search_bar_idle_search_start(void *data)
493 {
494         struct appdata *ap = (struct appdata *)data;
495         assert(ap);
496
497         myfileNaviBar *pNavi_s = mf_navi_bar_get_in_use(ap);
498         if (pNavi_s == NULL) {
499                 ap->mf_FileOperation.search_IME_hide_timer = NULL;
500                 mf_debug("pNavi_s is NULL");
501                 return ECORE_CALLBACK_CANCEL;
502         }
503
504         int root_num = 0;
505         mf_genlist_create_search_itc();
506
507         char *text = NULL;
508         const char *SearchRoot[3] = {0};
509         if (ap->mf_Status.more == MORE_SEARCH) {
510                 text = g_strdup(elm_object_text_get(ap->mf_MainWindow.pSearchEntry));
511         }
512
513         if (ap->mf_Status.view_type == mf_view_root || ap->mf_Status.view_type == mf_view_root_category) {
514                 SearchRoot[0] = PHONE_FOLDER;
515                 root_num++;
516                 if (ap->mf_Status.iStorageState & MYFILE_MMC) {
517                         SearchRoot[root_num] = MEMORY_FOLDER;
518                         root_num++;
519                 }
520                 if (ap->mf_Status.iStorageState & MYFILE_OTG) {
521                         SearchRoot[root_num] = OTG_FOLDER;
522                         root_num++;
523                 }
524         } else {
525                 if (ap->mf_Status.flagSearchAll == EINA_FALSE) {
526                         SearchRoot[0] = ap->mf_Status.path->str;
527                         root_num++;
528                 } else {
529                         int root = mf_fm_svc_wrapper_is_root_path(ap->mf_Status.path->str);
530                         switch (root) {
531                         case MYFILE_PHONE:
532                                 SearchRoot[0] = PHONE_FOLDER;
533                                 break;
534                         case MYFILE_MMC:
535                                 SearchRoot[0] = MEMORY_FOLDER;
536                                 break;
537                         case MYFILE_OTG:
538                                 SearchRoot[0] = OTG_FOLDER;
539                                 break;
540                         default:
541                                 SearchRoot[0] = PHONE_FOLDER;
542                                 break;
543                         }
544                         root_num++;
545                 }
546         }
547         mf_debug("search root is %s text is [%s]", ap->mf_Status.path->str, text);
548         char *new_desc = NULL;
549         /*Start Search routine*/
550         if (!mf_search_start(ap->mf_Status.search_handler, SearchRoot, root_num, \
551                              ((text) ? text : NULL), MF_SEARCH_OPTION_DEF, (void *)ap, NULL, mf_tray_item_category_none)) {
552                 /*generate the popup used to show search path
553                 **it's sure that new_desc is not NULL even if original path is NULL*/
554                 new_desc = mf_fm_svc_wrapper_translate_path(ap->mf_Status.path->str, MF_TRANS_OPTION_POPUP);
555                 ap->mf_MainWindow.pNormalPopup = mf_ug_popup_create_search(ap, __mf_search_bar_stop_cb, ap);
556                         //mf_popup_create_popup(ap, POPMODE_TEXT_BTN_SEARCH, NULL, new_desc, NULL, NULL, NULL, __mf_search_bar_stop_cb, ap);
557         }
558
559         if (new_desc != NULL) {
560                 free(new_desc);
561                 new_desc = NULL;
562         }
563
564         if (text != NULL) {
565                 free(text);
566                 text = NULL;
567         }
568
569         ap->mf_FileOperation.search_IME_hide_timer = NULL;
570         return ECORE_CALLBACK_CANCEL;
571 }
572
573 void mf_search_bar_enter_search_routine(void *data, Evas_Object * obj, void *event_info)
574 {
575         MF_TRACE_BEGIN;
576         struct appdata *ap = (struct appdata *)data;
577         assert(ap);
578
579         SAFE_FREE_OBJ(ap->mf_MainWindow.pContextPopup);
580
581         if (ap->mf_Status.more == MORE_RENAME) {
582                 mf_genlist_rename_done(ap, NULL, NULL);
583                 return;
584         }
585
586         if (ap->mf_Status.more != MORE_DEFAULT) {
587                 return;
588         }
589         if (ap->mf_Status.flagNaviPush) {
590                 mf_debug("the transition of the naviframe is not finished");
591                 return;
592         }
593
594         if (ap->mf_FileOperation.search_IME_hide_timer != NULL) {
595                 ecore_timer_del(ap->mf_FileOperation.search_IME_hide_timer);
596                 ap->mf_FileOperation.search_IME_hide_timer = NULL;
597         }
598
599         ap->mf_Status.more = MORE_SEARCH;
600         ap->mf_Status.flagSearchAll = EINA_FALSE;
601
602         mf_navi_bar_create_search_view(ap);
603         MF_TRACE_END;
604 }
605
606 void mf_search_bar_category_search(void *data, int category)
607 {
608         MF_TRACE_BEGIN;
609         struct appdata *ap = (struct appdata *)data;
610         mf_retm_if(ap == NULL, "input data error");
611         SAFE_FREE_CHAR(ap->mf_Status.search_filter);
612         if (ap->mf_Status.search_handler > 0)
613                 mf_search_finalize(&ap->mf_Status.search_handler);
614         int ret = mf_search_init(&ap->mf_Status.search_handler);
615         mf_retm_if(ret < 0, "Fail to mf_search_init()");
616
617         myfileNaviBar *pNavi_s = mf_navi_bar_get_in_use(ap);
618         mf_retm_if(pNavi_s == NULL, "input data error");
619
620         evas_object_del(mf_widget_unset_part_content(ap->mf_MainWindow.pNaviLayout, "content"));
621         Evas_Object *tray = mf_widget_unset_part_content(ap->mf_MainWindow.pNaviLayout, "swallow.shortcut");
622         SAFE_FREE_OBJ(tray);
623         ap->mf_MainWindow.pNaviGengrid = NULL;
624         ap->mf_MainWindow.pNaviGenlist = NULL;
625
626         if (ap->mf_FileOperation.sync_pipe != NULL) {
627                 ecore_pipe_del(ap->mf_FileOperation.sync_pipe);
628                 ap->mf_FileOperation.sync_pipe = NULL;
629         }
630         ap->mf_FileOperation.sync_pipe = ecore_pipe_add(__mf_search_bar_pipe_cb, ap);
631
632         if (ap->mf_FileOperation.sync_pipe == NULL) {
633                 mf_debug("add pipe failed");
634         }
635         /*this is to init global variable to ensure the first message can be transmitted correctly*/
636         /*flagSearchMsg is to indicate the condition wait to sync data of threads*/
637         pthread_mutex_lock(&gLockSearchMsg);
638         flagSearchMsg = 1;
639         pthread_mutex_unlock(&gLockSearchMsg);
640
641         /*delete guide text label in the box*/
642         mf_search_bar_category_search_start(ap, category);
643         mf_debug("enter pressed %d", category);
644         MF_TRACE_END;
645
646 }
647 void mf_search_bar_search_started_callback(void *data, Evas_Object * obj, void *event_info)
648 {
649         MF_TRACE_BEGIN;
650         struct appdata *ap = (struct appdata *)data;
651         mf_retm_if(ap == NULL, "input data error");
652
653         char *text = g_strdup(elm_object_text_get(ap->mf_MainWindow.pSearchEntry));
654         if (text == NULL || strlen(text) == 0 || strlen(g_strstrip(text)) == 0) {
655                 g_free(text);
656                 text = NULL;
657                 SAFE_FREE_CHAR(ap->mf_Status.search_filter);
658                 return;
659         }
660
661         g_free(text);
662         text = NULL;
663
664         SAFE_FREE_CHAR(ap->mf_Status.search_filter);
665         ap->mf_Status.search_filter = g_strdup(elm_object_text_get(ap->mf_MainWindow.pSearchEntry));
666         if (ap->mf_Status.more == MORE_RENAME) {
667                 mf_genlist_rename_done(ap, NULL, NULL);
668                 return;
669         }
670
671         if (ap->mf_Status.search_handler > 0)
672                 mf_search_finalize(&ap->mf_Status.search_handler);
673         int ret = mf_search_init(&ap->mf_Status.search_handler);
674         mf_retm_if(ret < 0, "Fail to mf_search_init()");
675
676         myfileNaviBar *pNavi_s = mf_navi_bar_get_in_use(ap);
677         mf_retm_if(pNavi_s == NULL, "input data error");
678
679         /*hide the IME*/
680         elm_object_focus_set(ap->mf_MainWindow.pSearchEntry, EINA_FALSE);
681
682         /*delete guide text label in the box*/
683         evas_object_del(mf_widget_unset_part_content(ap->mf_MainWindow.pNaviLayout, "content"));
684
685         ap->mf_MainWindow.pNaviGengrid = NULL;
686         ap->mf_MainWindow.pNaviGenlist = NULL;
687
688         if (ap->mf_FileOperation.sync_pipe != NULL) {
689                 ecore_pipe_del(ap->mf_FileOperation.sync_pipe);
690                 ap->mf_FileOperation.sync_pipe = NULL;
691         }
692         ap->mf_FileOperation.sync_pipe = ecore_pipe_add(__mf_search_bar_pipe_cb, ap);
693
694         if (ap->mf_FileOperation.sync_pipe == NULL) {
695                 mf_debug("add pipe failed");
696         }
697         /*this is to init global variable to ensure the first message can be transmitted correctly*/
698         /*flagSearchMsg is to indicate the condition wait to sync data of threads*/
699         pthread_mutex_lock(&gLockSearchMsg);
700         flagSearchMsg = 1;
701         pthread_mutex_unlock(&gLockSearchMsg);
702
703         elm_object_focus_set(ap->mf_MainWindow.pSearchEntry, EINA_FALSE);
704         /*delete guide text label in the box*/
705         ap->mf_FileOperation.search_IME_hide_timer = ecore_timer_add(MF_SEARCH_TIMER_INTERVAL, (Ecore_Task_Cb)__mf_search_bar_idle_search_start, ap);
706         mf_debug("enter pressed");
707         MF_TRACE_END;
708
709         return;
710 }