2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: CPosLandmarkSearch class
19 #ifndef CPOSLANDMARKSEARCH_H
20 #define CPOSLANDMARKSEARCH_H
23 #include <EPos_CPosLandmarkDatabase.h>
24 #include <EPos_CPosLmCategoryManager.h>
25 #include <EPos_CPosLmItemIterator.h>
26 #include <EPos_CPosLmOperation.h>
27 #include <EPos_TPosLmSortPref.h>
29 class CPosLmSearchCriteria;
30 class CPosLmDisplayData;
32 const TInt KPosLmMaxNumOfMatchesUnlimited = -1;
35 * This class is used to perform searches for landmarks or landmark categories
36 * in a landmark database.
38 * To search a landmark database, an instance of this class is created,
39 * supplying the database to search. The client creates a criterion object to
40 * specify what to search for. There are different criterion classes which all
41 * inherit from @ref CPosLmSearchCriteria. For instance, the client can search
42 * for landmarks which contain a certain text string by passing a
43 * @ref CPosLmTextCriteria.
45 * Some criterion classes are used for searching for landmarks (e.g.
46 * @ref CPosLmCategoryCriteria is used for searching for landmarks which
47 * contain a certain category) and some are used
48 * to search for landmark categories (e.g. @ref CPosLmCatNameCriteria is used
49 * to search for landmark categories by specifying a category name which may
50 * contain wild-card characters).
52 * Searches can be run in incremental mode.
53 * @ref StartLandmarkSearchL and @ref StartCategorySearchL both return a
54 * @p CPosLmOperation object which is used to execute the search. If it is
55 * run incrementally the client can supervise the progress of the operation.
56 * If it is sufficient to run the search synchronously, the client only has to
57 * call @p CPosLmOperation::ExecuteL. The client can cancel
58 * the search by deleting the @p CPosLmOperation object.
60 * By default, these functions start a new search, but the client can specify
61 * that only previous matches should be searched. This can be used to refine
62 * the search when there are many matches.
64 * During the search execution a read-lock is acquired for each database.
66 * Only one search can be performed at a time by the single instance of
67 * the class. If a search is already running, the search function leaves
68 * with error code @p KErrInUse.
70 * After search completion, the client can make a second search and specify
71 * that only the matches from the previous search shall be considered.
73 * The client can also set a limit on how many search matches should be
74 * returned (see @ref SetMaxNumOfMatches).
76 * The client retrieves the matches from the search by requesting an iterator
77 * (see @ref MatchIteratorL) or by using display data (see @ref SetDisplayData).
79 * @p NetworkServices capability is required for remote databases.
81 * @lib eposlmsearchlib.lib
84 class CPosLandmarkSearch : public CBase
89 * Two-phased constructor.
91 * The client takes ownership of the returned search object.
93 * @param[in] aDatabase The landmark database to search.
94 * @returns A new instance of this class.
96 IMPORT_C static CPosLandmarkSearch* NewL(
97 CPosLandmarkDatabase& aDatabase
103 IMPORT_C virtual ~CPosLandmarkSearch();
108 * Retrieves the maximum number of search matches limit.
110 * By default the maximum number of matches is unlimited.
112 * @return The maximum number of search matches or
113 * @p KPosLmMaxNumOfMatchesUnlimited if unlimited.
115 IMPORT_C TInt MaxNumOfMatches() const;
118 * Sets the maximum number of search matches limit.
120 * If the limit is set, the search operation will stop when this limit
123 * By default the maximum number of matches is unlimited.
125 * If a new value for maximum number of matches is set when a search is
126 * ongoing, it will not affect the current search. The new maximum will
127 * be utilized in the next search.
129 * @param[in] aMaxNumOfMatches the maximum number of search matches.
130 * KPosLmMaxNumOfMatchesUnlimited means that the number of matches is
133 IMPORT_C void SetMaxNumOfMatches(
134 TInt aMaxNumOfMatches = KPosLmMaxNumOfMatchesUnlimited
138 * Starts a search for landmarks.
140 * The client takes ownership of the returned operation object.
142 * This function requires @p ReadUserData capability.
144 * @param[in] aCriteria The search criterion.
145 * @param[in] aSearchOnlyPreviousMatches This flag may be used to perform a
146 * search within the results of previous search.
147 * @returns A handle to the search operation.
149 * @leave KErrInUse Search is already running.
150 * @leave KErrNotSupported search criterion is not supported.
151 * @leave KErrArgument Search criterion is not valid for landmark searching.
152 * @leave KErrArgument There are no previous matches and the client specifies that
153 * previous matches should be used.
155 virtual CPosLmOperation* StartLandmarkSearchL(
156 const CPosLmSearchCriteria& aCriteria,
157 TBool aSearchOnlyPreviousMatches = EFalse
161 * Starts a search for landmarks.
163 * This overload of the @ref StartLandmarkSearchL function lets the
164 * client define the sort order for the search matches.
165 * Only sorting by landmark name is supported.
167 * The client takes ownership of the returned operation object.
169 * This function requires @p ReadUserData capability.
171 * @param[in] aCriteria The search criterion.
172 * @param[in] aSortPref A sort preference object.
173 * @param[in] aSearchOnlyPreviousMatches This flag may be used to perform a
174 * search within the results of previous search.
175 * @returns A handle to the search operation.
177 * @leave KErrInUse Search is already running.
178 * @leave KErrArgument Search criterion is not valid for landmark searching.
179 * @leave KErrArgument There are no previous matches and the client specifies that
180 * previous matches should be used.
181 * @leave KErrNotSupported Search criterion is not supported.
182 * @leave KErrNotSupported Client tries to sort by other attribute than name.
184 virtual CPosLmOperation* StartLandmarkSearchL(
185 const CPosLmSearchCriteria& aCriteria,
186 const TPosLmSortPref& aSortPref,
187 TBool aSearchOnlyPreviousMatches = EFalse
191 * Starts a search for landmark categories.
193 * The criterion which defines whether a landmark category is a match or
194 * not is passed as input to this function.
196 * The client takes ownership of the returned operation object.
198 * This function requires @p ReadUserData capability.
200 * @param[in] aCriteria The search criterion.
201 * @param[in] aSortPref Sort preference for the search results.
202 * @param[in] aSearchOnlyPreviousMatches This flag may be used to perform a
203 * search within the results of previous search.
204 * @returns A handle to the search operation.
206 * @leave KErrInUse Search is already running.
207 * @leave KErrArgument Search criterion is not valid for category searching.
208 * @leave KErrNotSupported Search criterion is not supported.
210 virtual CPosLmOperation* StartCategorySearchL(
211 const CPosLmSearchCriteria& aCriteria,
212 CPosLmCategoryManager::TCategorySortPref aSortPref,
213 TBool aSearchOnlyPreviousMatches = EFalse
217 * Returns the number of matches so far in the search.
219 * This function can also be called during a search operation.
221 * @return The number of search matches.
223 virtual TUint NumOfMatches() const = 0;
226 * Creates an iterator object to iterate the matching landmarks or
227 * landmark categories.
229 * This function can also be called during a search in order to read the
230 * matches encountered so far. Note that the iterator will not iterate
231 * any new matches. If new matches are found, a new iterator must be
234 * If a sort preference was specified when the search was started,
235 * the landmarks/categories will be sorted when the search is complete
236 * but the items are not necessarily sorted if this function is called
239 * Note: If the client has set display data and resets the display data
240 * during a search, the sort order in the iterator might be incorrect.
242 * The client takes ownership of the returned iterator object.
244 * Note that the iterator iterates matches in @ref CPosLandmarkSearch.
245 * It cannot be used after the search object has been deleted. Make sure
246 * to delete the iterator first.
248 * @return A search match iterator.
250 virtual CPosLmItemIterator* MatchIteratorL() = 0;
253 * Display data can be used as an alternative way to get result
254 * from a database search. Landmarks or categories are added to the
255 * display data collection during a search depending on the search type.
257 * This function may replace the combination of using
258 * @ref MatchIteratorL and reading landmark or category data.
259 * Result data is read already during the search and no duplicate
260 * access to database is needed.
262 * The display data object will be reset each time a new search is
263 * started. No items during the search are removed from the
264 * collection. New found matches can be added every time next
265 * search step is completed, see @ref CPosLmDisplayData::NewItemIndex.
267 * Note: The database index of displayable data items in
268 * @ref CPosLmDisplayData will be set to 0 as it has no meaning in a
269 * single database search.
271 * The client owns the display data object. If the client deletes it
272 * during a search, this may lead to unexpected errors. The client must
273 * call @ref UnsetDisplayData before it deletes the display data object.
275 * Note: If the client resets the display data during a search, the sort
276 * order in the iterator might become incorrect.
278 * @param[in,out] aData The displayable data.
280 * @panic "Landmarks Client"-EPosSearchOperationInUse
281 * The client set display data during an ongoing search.
283 virtual void SetDisplayData( CPosLmDisplayData& aData ) = 0;
286 * Unsets display data. No further data will be added to the display
287 * data that was set with @ref SetDisplayData.
289 * @panic "Landmarks Client"-EPosSearchOperationInUse
290 * The client unset display data during an ongoing search.
292 virtual void UnsetDisplayData() = 0;
297 IMPORT_C CPosLandmarkSearch();
301 // Prohibit copy constructor
302 CPosLandmarkSearch( const CPosLandmarkSearch& );
303 // Prohibit assigment operator
304 CPosLandmarkSearch& operator= ( const CPosLandmarkSearch& );
309 TInt iMaxNumOfMatches;
312 #endif // CPOSLANDMARKSEARCH_H