|
1 /* |
|
2 * Copyright (c) 2006 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: This file contains search utilities to query the landmarks Db. |
|
15 * For example getting all landmarks under a category, Name of a |
|
16 * particular category etc. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 // INCLUDE FILES |
|
27 #include <EPos_CPosLandmark.h> |
|
28 #include <EPos_CPosLandmarkDatabase.h> |
|
29 #include <EPos_CPosLandmarkSearch.h> |
|
30 #include <EPos_CPosLmCategoryCriteria.h> |
|
31 #include "mlmkdbsearchutilsobserver.h" |
|
32 #include "MLmkAOOperationObserver.h" |
|
33 #include "CLmkAOOperation.h" |
|
34 #include "clmkdbsearchutils.h" |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CLmkDbSearchUtils::CLmkDbSearchUtils |
|
40 // C++ default constructor can NOT contain any code, that |
|
41 // might leave. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CLmkDbSearchUtils::CLmkDbSearchUtils(): |
|
45 CActive(EPriorityStandard) |
|
46 { |
|
47 CActiveScheduler::Add( this ); |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CLmkDbSearchUtils::~CLmkDbSearchUtils |
|
52 // Destructor |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 EXPORT_C CLmkDbSearchUtils::~CLmkDbSearchUtils() |
|
56 { |
|
57 delete iSearch; |
|
58 delete iDb; |
|
59 if (iSearchAO) |
|
60 { |
|
61 iSearchAO->StopOperation(); |
|
62 } |
|
63 delete iSearchAO; |
|
64 delete iCriteria; |
|
65 if ( IsActive() ) |
|
66 { |
|
67 Cancel(); |
|
68 } |
|
69 iLmItemId.Close(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CLmkDbSearchUtils::NewL |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 EXPORT_C CLmkDbSearchUtils* CLmkDbSearchUtils::NewL() |
|
77 { |
|
78 CLmkDbSearchUtils* self = new (ELeave) CLmkDbSearchUtils(); |
|
79 CleanupStack::PushL(self); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop();// self |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CLmkDbSearchUtils::ConstructL |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CLmkDbSearchUtils::ConstructL() |
|
90 { |
|
91 iDb = CPosLandmarkDatabase::OpenL(); |
|
92 iSearch = CPosLandmarkSearch::NewL( *iDb ); |
|
93 iCriteria = CPosLmCategoryCriteria::NewLC(); |
|
94 CleanupStack::Pop( iCriteria ); |
|
95 iSearchAO = NULL; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CLmkDbSearchUtils::GetLandmarksUnderCategoryL |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 EXPORT_C void CLmkDbSearchUtils::GetLandmarksUnderCategoryL(MLmkDbSearchUtilsObserver* aObserver, |
|
103 TPosLmItemId aCategoryId) |
|
104 { |
|
105 iObserver = aObserver; |
|
106 iCriteria->SetCategoryItemId(aCategoryId); |
|
107 TPosLmSortPref sortOrder( CPosLandmark::ELandmarkName, |
|
108 TPosLmSortPref::EAscending ); |
|
109 |
|
110 CPosLmOperation* operation = |
|
111 iSearch->StartLandmarkSearchL( *iCriteria , sortOrder ); |
|
112 |
|
113 CleanupStack::PushL( operation ); |
|
114 if (iSearchAO) |
|
115 { |
|
116 iSearchAO->StopOperation(); |
|
117 } |
|
118 delete iSearchAO; // Cancel if any pending requests |
|
119 iSearchAO = NULL; |
|
120 iSearchAO = CLmkAOOperation::NewL( operation, |
|
121 *this, |
|
122 MLmkAOOperationObserver::ESearch, |
|
123 EFalse ); |
|
124 |
|
125 CleanupStack::Pop( operation ); // ownership transferred |
|
126 iSearchAO->StartOperation(); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CLmkDbSearchUtils::GetCategoryNameL |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C HBufC* CLmkDbSearchUtils::GetCategoryNameL(TPosLmItemId aCategoryId) |
|
134 { |
|
135 CPosLmCategoryManager* mgr = CPosLmCategoryManager::NewL( *iDb ); |
|
136 CleanupStack::PushL( mgr ); |
|
137 // Leaves with KErrNotFound if category doesn't exist |
|
138 CPosLandmarkCategory* category = mgr->ReadCategoryLC( aCategoryId ); |
|
139 TPtrC categoryName; |
|
140 User::LeaveIfError(category->GetCategoryName(categoryName)); |
|
141 // The caller will take ownership of the buffer |
|
142 HBufC* retCategoryName = HBufC::NewL(categoryName.Length()); |
|
143 TPtr ptr = retCategoryName->Des(); |
|
144 ptr.Copy(categoryName); |
|
145 CleanupStack::PopAndDestroy( 2 ); // category and mgr |
|
146 return retCategoryName; |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CLmkDbSearchUtils::GetLandmarkForIdL |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C CPosLandmark* CLmkDbSearchUtils::GetLandmarkForIdL(TPosLmItemId aLandmarkId) |
|
154 { |
|
155 CPosLandmark* lmk = iDb->ReadLandmarkLC(aLandmarkId); |
|
156 CleanupStack::Pop(); // ReadLandmarkLC |
|
157 return lmk; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CLmkDbSearchUtils::GetLandmarksL |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 EXPORT_C void CLmkDbSearchUtils::GetLandmarksL(MLmkDbSearchUtilsObserver* aObserver, |
|
165 RArray<TPosLmItemId> aLmItemId, |
|
166 RPointerArray<CPosLandmark>* aArray) |
|
167 { |
|
168 iLmkArray = aArray; |
|
169 iLmItemId = aLmItemId; |
|
170 iSearchIndex = 0; |
|
171 iObserver = aObserver; |
|
172 SetActive(); |
|
173 TRequestStatus *status = &iStatus; |
|
174 User::RequestComplete(status, KErrNone); |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CLmkDbSearchUtils::RunL |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CLmkDbSearchUtils::RunL() |
|
182 { |
|
183 if(iSearchIndex >= iLmItemId.Count()) |
|
184 { |
|
185 iLmItemId.Close(); |
|
186 iObserver->HandleLmkSearchNotifyL(); |
|
187 } |
|
188 else |
|
189 { |
|
190 TPosLmItemId itemId = iLmItemId[iSearchIndex]; |
|
191 CPosLandmark* landmark = iDb->ReadLandmarkLC(itemId); |
|
192 iLmkArray->Append(landmark); |
|
193 CleanupStack::Pop(); // ReadLandmarkLC |
|
194 ++iSearchIndex; |
|
195 SetActive(); |
|
196 TRequestStatus *status = &iStatus; |
|
197 User::RequestComplete(status, KErrNone); |
|
198 } |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CLmkDbSearchUtils::DoCancel |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CLmkDbSearchUtils::DoCancel() |
|
206 { |
|
207 |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CLmkDbSearchUtils::HandleOperationL |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CLmkDbSearchUtils::HandleOperationL(TOperationTypes /*aType*/, |
|
215 TReal32 /*aProgress*/, |
|
216 TInt /*aStatus*/ ) |
|
217 { |
|
218 CPosLmItemIterator* iterator = iSearch->MatchIteratorL(); |
|
219 CleanupStack::PushL( iterator ); |
|
220 RArray<TPosLmItemId> itemIdArray; |
|
221 CleanupClosePushL( itemIdArray ); |
|
222 iterator->GetItemIdsL( itemIdArray, 0, iterator->NumOfItemsL() ); |
|
223 if ( iObserver ) |
|
224 { |
|
225 iObserver->HandleCategorySearchNotifyL( itemIdArray ); |
|
226 } |
|
227 CleanupStack::PopAndDestroy(); //itemIdArray |
|
228 CleanupStack::PopAndDestroy( iterator ); |
|
229 } |
|
230 |
|
231 |