|
1 /* |
|
2 * Copyright (c) 2005 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: Helper class that validates a search criteria and creates a copy. |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <EPos_CPosLmSearchCriteria.h> |
|
22 #include <EPos_CPosLmAreaCriteria.h> |
|
23 #include <EPos_CPosLmTextCriteria.h> |
|
24 #include <EPos_CPosLmCompositeCriteria.h> |
|
25 #include <EPos_CPosLmCategoryCriteria.h> |
|
26 #include <EPos_CPosLmNearestCriteria.h> |
|
27 #include <EPos_CPosLmCatNameCriteria.h> |
|
28 #include "EPos_PosLmCriteriaHelper.h" |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // PosLmCriteriaHelper::ValidateAndCopyL |
|
36 // |
|
37 // (other items were commented in a header). |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CPosLmSearchCriteria* PosLmCriteriaHelper::ValidateAndCopyL( |
|
41 const CPosLmSearchCriteria& aCriteria, |
|
42 TBool aIsLm, |
|
43 TBool& aUseDistanceSorting, |
|
44 TBool aIsTopCriteria) |
|
45 { |
|
46 CPosLmSearchCriteria* criteria = NULL; |
|
47 aUseDistanceSorting = EFalse; |
|
48 |
|
49 switch (aCriteria.CriteriaType()) |
|
50 { |
|
51 case CPosLmSearchCriteria::ECriteriaArea: |
|
52 __ASSERT_ALWAYS(aIsLm, User::Leave(KErrArgument)); |
|
53 |
|
54 criteria = ValidateAndCopyLC( |
|
55 static_cast<const CPosLmAreaCriteria&>(aCriteria)); |
|
56 break; |
|
57 |
|
58 case CPosLmSearchCriteria::ECriteriaText: |
|
59 __ASSERT_ALWAYS(aIsLm, User::Leave(KErrArgument)); |
|
60 |
|
61 criteria = ValidateAndCopyLC( |
|
62 static_cast<const CPosLmTextCriteria&>(aCriteria)); |
|
63 break; |
|
64 |
|
65 case CPosLmSearchCriteria::ECriteriaComposite: |
|
66 __ASSERT_ALWAYS(aIsLm, User::Leave(KErrNotSupported)); |
|
67 __ASSERT_ALWAYS(aIsTopCriteria, User::Leave(KErrArgument)); |
|
68 |
|
69 criteria = ValidateAndCopyLC( |
|
70 static_cast<const CPosLmCompositeCriteria&>(aCriteria), |
|
71 aIsLm, aUseDistanceSorting); |
|
72 break; |
|
73 |
|
74 case CPosLmSearchCriteria::ECriteriaCategory: |
|
75 __ASSERT_ALWAYS(aIsLm, User::Leave(KErrArgument)); |
|
76 |
|
77 criteria = ValidateAndCopyLC( |
|
78 static_cast<const CPosLmCategoryCriteria&>(aCriteria)); |
|
79 break; |
|
80 |
|
81 case CPosLmSearchCriteria::ECriteriaFindNearest: |
|
82 __ASSERT_ALWAYS(aIsLm, User::Leave(KErrArgument)); |
|
83 |
|
84 criteria = ValidateAndCopyLC( |
|
85 static_cast<const CPosLmNearestCriteria&>(aCriteria)); |
|
86 aUseDistanceSorting = ETrue; |
|
87 break; |
|
88 |
|
89 case CPosLmSearchCriteria::ECriteriaCategoryByName: |
|
90 __ASSERT_ALWAYS(!aIsLm, User::Leave(KErrArgument)); |
|
91 |
|
92 criteria = ValidateAndCopyLC( |
|
93 static_cast<const CPosLmCatNameCriteria&>(aCriteria)); |
|
94 break; |
|
95 |
|
96 case CPosLmSearchCriteria::ECriteriaIdList: |
|
97 User::Leave(KErrArgument); |
|
98 |
|
99 default: |
|
100 User::Leave(KErrNotSupported); |
|
101 } |
|
102 |
|
103 CleanupStack::Pop(criteria); |
|
104 return criteria; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // PosLmCriteriaHelper::ValidateAndCopyLC |
|
109 // |
|
110 // (other items were commented in a header). |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 CPosLmSearchCriteria* PosLmCriteriaHelper::ValidateAndCopyLC( |
|
114 const CPosLmCompositeCriteria& aCriteria, |
|
115 TBool aIsLm, |
|
116 TBool& aUseDistanceSorting) |
|
117 { |
|
118 __ASSERT_ALWAYS(aCriteria.NumOfArguments() > 0, User::Leave(KErrArgument)); |
|
119 |
|
120 CPosLmCompositeCriteria* criteria = |
|
121 CPosLmCompositeCriteria::NewLC(aCriteria.CompositionType()); |
|
122 |
|
123 TBool componentUseDistanceSorting; |
|
124 TInt noOfcomponentUseDistanceSorting(0); |
|
125 |
|
126 for (TUint i = 0; i < aCriteria.NumOfArguments(); i++) |
|
127 { |
|
128 CPosLmSearchCriteria* component = |
|
129 ValidateAndCopyL(aCriteria.Argument(i), aIsLm, |
|
130 componentUseDistanceSorting, EFalse); |
|
131 |
|
132 CleanupStack::PushL(component); |
|
133 User::LeaveIfError(criteria->AddArgument(component)); |
|
134 CleanupStack::Pop(component); |
|
135 |
|
136 if (componentUseDistanceSorting) |
|
137 { |
|
138 noOfcomponentUseDistanceSorting++; |
|
139 } |
|
140 |
|
141 } |
|
142 |
|
143 // Composite with none or more than one distance sorting criteria means |
|
144 // no distance sorting. |
|
145 aUseDistanceSorting = (noOfcomponentUseDistanceSorting == 1); |
|
146 |
|
147 return criteria; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // PosLmCriteriaHelper::ValidateAndCopyLC |
|
152 // |
|
153 // (other items were commented in a header). |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 CPosLmSearchCriteria* PosLmCriteriaHelper::ValidateAndCopyLC( |
|
157 const CPosLmAreaCriteria& aCriteria) |
|
158 { |
|
159 TReal64 southLatitude; |
|
160 TReal64 northLatitude; |
|
161 TReal64 westLongitude; |
|
162 TReal64 eastLongitude; |
|
163 aCriteria.GetSearchArea(southLatitude, northLatitude, |
|
164 westLongitude, eastLongitude); |
|
165 |
|
166 CPosLmAreaCriteria* criteria = CPosLmAreaCriteria::NewLC( |
|
167 southLatitude, northLatitude, |
|
168 westLongitude, eastLongitude); |
|
169 |
|
170 return criteria; |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // PosLmCriteriaHelper::ValidateAndCopyLC |
|
175 // |
|
176 // (other items were commented in a header). |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 CPosLmSearchCriteria* PosLmCriteriaHelper::ValidateAndCopyLC( |
|
180 const CPosLmTextCriteria& aCriteria) |
|
181 { |
|
182 __ASSERT_ALWAYS(aCriteria.Text().Length() > 0, User::Leave(KErrArgument)); |
|
183 |
|
184 CPosLmTextCriteria* criteria = CPosLmTextCriteria::NewLC(); |
|
185 |
|
186 criteria->SetTextL(aCriteria.Text()); |
|
187 criteria->SetAttributesToSearch(aCriteria.AttributesToSearch()); |
|
188 |
|
189 RArray<TUint> positionFields; |
|
190 CleanupClosePushL(positionFields); |
|
191 aCriteria.GetPositionFieldsToSearchL(positionFields); |
|
192 criteria->SetPositionFieldsToSearchL(positionFields); |
|
193 CleanupStack::PopAndDestroy(&positionFields); |
|
194 |
|
195 return criteria; |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // PosLmCriteriaHelper::ValidateAndCopyLC |
|
200 // |
|
201 // (other items were commented in a header). |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 CPosLmSearchCriteria* PosLmCriteriaHelper::ValidateAndCopyLC( |
|
205 const CPosLmCategoryCriteria& aCriteria) |
|
206 { |
|
207 __ASSERT_ALWAYS(aCriteria.CategoryItemId() == KPosLmNullItemId, |
|
208 User::Leave(KErrArgument)); |
|
209 |
|
210 CPosLmCategoryCriteria* criteria = CPosLmCategoryCriteria::NewLC(); |
|
211 if (aCriteria.CategoryName().Length() > 0) |
|
212 { |
|
213 criteria->SetCategoryNameL(aCriteria.CategoryName()); |
|
214 } |
|
215 else if (aCriteria.GlobalCategory() != KPosLmNullGlobalCategory) |
|
216 { |
|
217 criteria->SetGlobalCategory(aCriteria.GlobalCategory()); |
|
218 } |
|
219 |
|
220 return criteria; |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // PosLmCriteriaHelper::ValidateAndCopyLC |
|
225 // |
|
226 // (other items were commented in a header). |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 CPosLmSearchCriteria* PosLmCriteriaHelper::ValidateAndCopyLC( |
|
230 const CPosLmNearestCriteria& aCriteria) |
|
231 { |
|
232 TCoordinate coordinate; |
|
233 aCriteria.GetCoordinate(coordinate); |
|
234 |
|
235 CPosLmNearestCriteria* criteria = CPosLmNearestCriteria::NewLC( |
|
236 coordinate, |
|
237 aCriteria.UseCoverageRadius()); |
|
238 criteria->SetMaxDistance(aCriteria.MaxDistance()); |
|
239 |
|
240 return criteria; |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // PosLmCriteriaHelper::ValidateAndCopyLC |
|
245 // |
|
246 // (other items were commented in a header). |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 CPosLmSearchCriteria* PosLmCriteriaHelper::ValidateAndCopyLC( |
|
250 const CPosLmCatNameCriteria& aCriteria) |
|
251 { |
|
252 __ASSERT_ALWAYS(aCriteria.SearchPattern().Length() > 0, |
|
253 User::Leave(KErrArgument)); |
|
254 |
|
255 CPosLmCatNameCriteria* criteria = CPosLmCatNameCriteria::NewLC(); |
|
256 criteria->SetSearchPatternL(aCriteria.SearchPattern()); |
|
257 |
|
258 return criteria; |
|
259 } |
|
260 |
|
261 // End of File |