Tizen 2.1 base
[apps/home/ug-myfile-efl.git] / src / common / mf-ug-search.c
1 /*
2  * Copyright 2012          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
20
21 #include <stdio.h>
22 #include <dirent.h>
23 #include <sys/types.h>
24 #include <string.h>
25 #include <glib.h>
26
27 #include "mf-ug-dlog.h"
28 #include "mf-ug-search.h"
29 #include "mf-ug-search-internal.h"
30
31
32 /*+++++++++++++++++++++++ APIs +++++++++++++++++++++++*/
33
34 int mf_ug_search_init(mf_search_handle *handle)
35 {
36         int ret = 0;
37         ms_handle_t *ms_handle = NULL;
38
39         if (!handle) {
40                 return -1;
41         }
42         if (!g_thread_supported()) {
43                 g_thread_init(NULL);
44         }
45         ret = _mf_ug_search_init(&ms_handle);
46         if (ret < 0) {
47                 ms_error("Fail to init search handle ");
48                 *handle = (mf_search_handle) 0;
49                 return ret;
50         }
51
52         *handle = (mf_search_handle) ms_handle;
53
54         return MF_SEARCH_ERROR_NONE;
55 }
56
57 int mf_ug_search_start(mf_search_handle handle,
58                     const char **root_path, unsigned int path_num, const char *needle, mf_search_option option, void *user_data)
59 {
60         int ret = 0;
61         if (!handle) {
62                 return MF_SEARCH_ERROR_INVAL_P;
63         }
64
65         if (!root_path || !needle || path_num < 1) {
66                 return MF_SEARCH_ERROR_INVAL_P;
67         }
68
69         ret = _mf_ug_search_start((ms_handle_t *) handle, root_path, path_num, needle, option, user_data);
70
71         if (ret < 0) {
72                 ms_error("Fail to start search ");
73         }
74         return ret;
75 }
76
77 int mf_ug_search_stop(mf_search_handle handle)
78 {
79         int ret = 0;
80
81         ret = _mf_ug_search_stop((ms_handle_t *) handle);
82         if (ret < 0) {
83                 ms_error("Fail to stop search ");
84         }
85         return ret;
86 }
87
88 void mf_ug_search_finalize(mf_search_handle *handle)
89 {
90         _mf_ug_search_finalize((ms_handle_t **) handle);
91         return;
92 }
93
94 /*+++++++++++++++++++++++ UTIL APIs +++++++++++++++++++++++*/
95
96 char *mf_ug_search_result_dir_get(mf_search_result_t *result)
97 {
98         return _mf_ug_search_result_dir_get(result);
99 }
100
101 char *mf_ug_search_result_file_get(mf_search_result_t *result)
102 {
103         return _mf_ug_search_result_file_get(result);
104 }
105
106 int mf_ug_search_result_is_end(mf_search_result_t *result, int *is_end)
107 {
108         if (result) {
109                 *is_end = _mf_ug_search_result_is_end(result);
110         } else {
111                 return MF_SEARCH_ERROR_INVAL_P;
112         }
113         return MF_SEARCH_ERROR_NONE;
114 }
115
116 int mf_ug_search_result_total_count_get(mf_search_result_t *result, unsigned int *count)
117 {
118         if (result) {
119                 *count = _mf_ug_search_result_total_count_get(result);
120         } else {
121                 return MF_SEARCH_ERROR_INVAL_P;
122         }
123         return MF_SEARCH_ERROR_NONE;
124 }
125
126 char *mf_ug_search_result_current_dir_get(mf_search_result_t *result)
127 {
128         return _mf_ug_search_result_current_dir_get(result);
129 }