|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation indevice handler |
|
15 * |
|
16 */ |
|
17 #include "indevicehandler.h" |
|
18 #include <qcpixsearcher.h> |
|
19 #include <qcpixdocument.h> |
|
20 |
|
21 // --------------------------------------------------------------------------- |
|
22 // InDeviceHandler::InDeviceHandler() |
|
23 // --------------------------------------------------------------------------- |
|
24 // |
|
25 InDeviceHandler::InDeviceHandler() : |
|
26 mSearchInterface(0), mSearchResultCount(0) |
|
27 { |
|
28 } |
|
29 // --------------------------------------------------------------------------- |
|
30 // InDeviceHandler::getSearchResult(int aError, int estimatedResultCount) |
|
31 // aError: error code |
|
32 // estimatedResultCount: number of hits |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 void InDeviceHandler::getSearchResult(int aError, int estimatedResultCount) |
|
36 { |
|
37 qDebug() << aError << estimatedResultCount; |
|
38 mSearchResultCount = estimatedResultCount; |
|
39 emit handleAsyncSearchResult(aError, estimatedResultCount); |
|
40 } |
|
41 // --------------------------------------------------------------------------- |
|
42 // InDeviceHandler::getDocumentAsync(int aError, QCPixDocument* aDocument) |
|
43 // aError: error code |
|
44 // aDocument: holding the result item |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 void InDeviceHandler::getDocumentAsync(int aError, QCPixDocument* aDocument) |
|
48 { |
|
49 emit handleDocument(aError, aDocument); |
|
50 } |
|
51 // --------------------------------------------------------------------------- |
|
52 // InDeviceHandler::getDocumentAtIndex(int aIndex) |
|
53 // aIndex: item index to be found |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 QCPixDocument* InDeviceHandler::getDocumentAtIndex(int aIndex) |
|
57 { |
|
58 QCPixDocument* doc = NULL; |
|
59 if (mSearchInterface) |
|
60 { |
|
61 try |
|
62 { |
|
63 doc = mSearchInterface->getDocument(aIndex); |
|
64 |
|
65 } |
|
66 catch (...) |
|
67 { |
|
68 delete doc; |
|
69 return NULL; |
|
70 } |
|
71 } |
|
72 return doc; |
|
73 } |
|
74 // --------------------------------------------------------------------------- |
|
75 // InDeviceHandler:: search(QString aSearchString) |
|
76 // aSearchString: string to be searched sync |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void InDeviceHandler::search(QString aSearchString) |
|
80 { |
|
81 qDebug() << "InDeviceHandler::search Enter"; |
|
82 if (aSearchString.length()) |
|
83 { |
|
84 int error = 0; |
|
85 mSearchResultCount = 0; |
|
86 if (mSearchInterface) |
|
87 { |
|
88 try |
|
89 { |
|
90 mSearchResultCount = mSearchInterface->search(aSearchString); |
|
91 } |
|
92 catch (...) |
|
93 { |
|
94 error = -1; |
|
95 } |
|
96 } |
|
97 emit handleSearchResult(error, mSearchResultCount); |
|
98 } |
|
99 qDebug() << "InDeviceHandler::search Exit"; |
|
100 } |
|
101 // --------------------------------------------------------------------------- |
|
102 // InDeviceHandler::~InDeviceHandler() |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 InDeviceHandler::~InDeviceHandler() |
|
106 { |
|
107 if (mSearchInterface) |
|
108 { |
|
109 delete mSearchInterface; |
|
110 |
|
111 } |
|
112 } |
|
113 // --------------------------------------------------------------------------- |
|
114 // InDeviceHandler::getSearchResultCount() |
|
115 // gets the number of hits |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 int InDeviceHandler::getSearchResultCount() |
|
119 { |
|
120 return mSearchResultCount; |
|
121 } |
|
122 // --------------------------------------------------------------------------- |
|
123 // InDeviceHandler::getDocumentAsyncAtIndex(int aIndex) |
|
124 // aIndex : index of item to be found async |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void InDeviceHandler::getDocumentAsyncAtIndex(int aIndex) |
|
128 { |
|
129 if (mSearchInterface) |
|
130 { |
|
131 try |
|
132 { |
|
133 mSearchInterface->getDocumentAsync(aIndex); |
|
134 } |
|
135 catch (...) |
|
136 { |
|
137 // handle the exception |
|
138 return; |
|
139 } |
|
140 } |
|
141 |
|
142 } |
|
143 // --------------------------------------------------------------------------- |
|
144 // InDeviceHandler::searchAsync(QString aSearchAsyncString, QString/* aDefaultSearchField*/) |
|
145 // aSearchAsyncString: string to be searched |
|
146 // async |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void InDeviceHandler::searchAsync(QString aSearchAsyncString, QString/* aDefaultSearchField*/) |
|
150 { |
|
151 if (aSearchAsyncString.length()) |
|
152 { |
|
153 mSearchResultCount = 0; |
|
154 if (mSearchInterface) |
|
155 { |
|
156 try |
|
157 { |
|
158 mSearchInterface->searchAsync(aSearchAsyncString); |
|
159 } |
|
160 catch (...) |
|
161 { |
|
162 // handle the exception |
|
163 return; |
|
164 } |
|
165 } |
|
166 } |
|
167 } |
|
168 // --------------------------------------------------------------------------- |
|
169 // InDeviceHandler::cancelLastSearch() |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void InDeviceHandler::cancelLastSearch() |
|
173 { |
|
174 if (mSearchInterface) |
|
175 |
|
176 { |
|
177 try |
|
178 { |
|
179 mSearchInterface->cancelSearch(); |
|
180 } |
|
181 catch (...) |
|
182 { |
|
183 // handle the exception |
|
184 return; |
|
185 } |
|
186 } |
|
187 } |
|
188 // --------------------------------------------------------------------------- |
|
189 // InDeviceHandler::setCategory(QString astring) |
|
190 // astring: setting categories to be searched |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 void InDeviceHandler::setCategory(QString astring) |
|
194 { |
|
195 if (mSearchInterface) |
|
196 { |
|
197 delete mSearchInterface; |
|
198 mSearchInterface = NULL; |
|
199 } |
|
200 if (astring.length()) |
|
201 { |
|
202 QString database("root "); |
|
203 database.append(astring); |
|
204 mSearchInterface = QCPixSearcher::newInstance(database, |
|
205 DEFAULT_SEARCH_FIELD); |
|
206 try |
|
207 { |
|
208 mSearchInterface->connect(mSearchInterface, |
|
209 SIGNAL(handleSearchResults(int,int)), this, |
|
210 SLOT(getSearchResult(int,int))); |
|
211 } |
|
212 catch (...) |
|
213 { |
|
214 // handle the exception |
|
215 } |
|
216 |
|
217 try |
|
218 { |
|
219 mSearchInterface->connect(mSearchInterface, |
|
220 SIGNAL(handleDocument(int,QCPixDocument*)), this, |
|
221 SLOT(getDocumentAsync(int,QCPixDocument*))); |
|
222 } |
|
223 catch (...) |
|
224 { |
|
225 // handle the exception |
|
226 } |
|
227 } |
|
228 } |
|
229 // --------------------------------------------------------------------------- |
|
230 // InDeviceHandler::isPrepared() |
|
231 // verify the mSearchInterface is prepared or not |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 bool InDeviceHandler::isPrepared() |
|
235 { |
|
236 if (mSearchInterface) |
|
237 { |
|
238 return true; |
|
239 } |
|
240 |
|
241 return false; |
|
242 |
|
243 } |