|
1 /* |
|
2 * Copyright (c) 2008 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: Landmark search factory |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INTERNAL INCLUDES |
|
20 #include "clapilandmarksearchfactory.h" |
|
21 #include "tlapisearchcriteria.h" |
|
22 #include "logger.h" |
|
23 // EXTERNAL INCLUDES |
|
24 #include <EPos_CPosLandmarkDatabase.h> |
|
25 #include <EPos_CPosLandmarkSearch.h> |
|
26 #include <EPos_CPosLmItemIterator.h> |
|
27 #include <EPos_CPosLmOperation.h> |
|
28 #include <EPos_CPosLmCompositeCriteria.h> |
|
29 #include <EPos_CPosLmCategoryCriteria.h> |
|
30 #include <EPos_CPosLmTextCriteria.h> |
|
31 #include <EPos_CPosLmAreaCriteria.h> |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // CLAPILandmarkSearchFactory::NewL |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CLAPILandmarkSearchFactory* CLAPILandmarkSearchFactory::NewL( |
|
38 CPosLandmarkDatabase& aDatabase) |
|
39 { |
|
40 JELOG2(EJavaLocation); |
|
41 CLAPILandmarkSearchFactory* self = CLAPILandmarkSearchFactory::NewLC( |
|
42 aDatabase); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CLAPILandmarkSearchFactory::NewLC |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CLAPILandmarkSearchFactory* CLAPILandmarkSearchFactory::NewLC( |
|
52 CPosLandmarkDatabase& aDatabase) |
|
53 { |
|
54 JELOG2(EJavaLocation); |
|
55 CLAPILandmarkSearchFactory* self = |
|
56 new(ELeave) CLAPILandmarkSearchFactory(aDatabase); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CLAPILandmarkSearchFactory::~CLAPILandmarkSearchFactory |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CLAPILandmarkSearchFactory::~CLAPILandmarkSearchFactory() |
|
67 { |
|
68 JELOG2(EJavaLocation); |
|
69 delete iLmSearch; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CLAPILandmarkSearchFactory::CreateIteratorL |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CPosLmItemIterator* CLAPILandmarkSearchFactory::CreateIteratorL( |
|
77 const TLAPISearchCriteria* aCriteria) |
|
78 { |
|
79 JELOG2(EJavaLocation); |
|
80 CPosLmItemIterator* iterator(NULL); |
|
81 // Sorting is left for the MIDlet. There is no requirement for this |
|
82 // as it slows the performance of listing landmarks. Usually there |
|
83 // is no need to sort the landmarks because those are plotted to a map |
|
84 |
|
85 // Match all landmark without using the Landmark Search API if the passed |
|
86 // search criteria is null or does not have any parameters set |
|
87 if (!aCriteria || !aCriteria->Text() && !aCriteria->CategoryName() |
|
88 && !aCriteria->HasValidCoordinates()) |
|
89 { |
|
90 iterator = iDatabase.LandmarkIteratorL(); |
|
91 } |
|
92 else |
|
93 { |
|
94 // Create a composite criteria and add other criterias to it |
|
95 CPosLmCompositeCriteria* criterias = CPosLmCompositeCriteria::NewLC( |
|
96 CPosLmCompositeCriteria::ECompositionAND); |
|
97 |
|
98 // Currently, category criteria is the first which will be matched |
|
99 // if the argument has been specified by the client |
|
100 const TDesC* categoryName = aCriteria->CategoryName(); |
|
101 if (categoryName) |
|
102 { |
|
103 CPosLmCategoryCriteria* criteria = CPosLmCategoryCriteria::NewLC(); |
|
104 // Empty string must find uncategorized landmarks |
|
105 if (categoryName->Length() > 0) |
|
106 { |
|
107 criteria->SetCategoryNameL(*categoryName); |
|
108 } |
|
109 // The ownership of the criteria is transferred to criterias |
|
110 // and the value is popped from the cleanup stack |
|
111 AddCriteriaAndPopL(*criterias, criteria); |
|
112 } |
|
113 |
|
114 const TDesC* text = aCriteria->Text(); |
|
115 // Next search argument will be the text criteria. The search |
|
116 // criteria must specify at least one attribute which is searched |
|
117 if (text) |
|
118 { |
|
119 CPosLmTextCriteria* criteria = CPosLmTextCriteria::NewLC(); |
|
120 criteria->SetTextL(*text); |
|
121 // Currently only name attribute is supported for searching |
|
122 criteria->SetAttributesToSearch(aCriteria->TextAttributes()); |
|
123 // The ownership of the criteria is transferred to criterias |
|
124 // and the value is popped from the cleanup stack |
|
125 AddCriteriaAndPopL(*criterias, criteria); |
|
126 } |
|
127 |
|
128 // Finally use the match area if specified |
|
129 if (aCriteria->HasValidCoordinates()) |
|
130 { |
|
131 TReal64 southLat; |
|
132 TReal64 northLat; |
|
133 TReal64 westLon; |
|
134 TReal64 eastLon; |
|
135 |
|
136 aCriteria->GetArea(southLat, northLat, westLon, eastLon); |
|
137 // Match all landmarks within the specified area |
|
138 CPosLmAreaCriteria* criteria = CPosLmAreaCriteria::NewLC(southLat, |
|
139 northLat, westLon, eastLon); |
|
140 // The ownership of the criteria is transferred to criterias |
|
141 // and the value is popped from the cleanup stack |
|
142 AddCriteriaAndPopL(*criterias, criteria); |
|
143 } |
|
144 // Start the search and do not use previous results |
|
145 CPosLmOperation* op = iLmSearch->StartLandmarkSearchL(*criterias); |
|
146 // The ownership is transferred to the following function call which |
|
147 // puts the operation to the clean-up stack so no need to push here |
|
148 ExecuteAndDeleteLD(op); |
|
149 CleanupStack::PopAndDestroy(criterias); |
|
150 // Get the match iterator from the landmark search manager |
|
151 iterator = iLmSearch->MatchIteratorL(); |
|
152 } |
|
153 |
|
154 // The ownership is transferred to the caller |
|
155 return iterator; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CLAPILandmarkSearchFactory::AddCriteriaAndPopL |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CLAPILandmarkSearchFactory::AddCriteriaAndPopL( |
|
163 CPosLmCompositeCriteria& aCompositeCriteria, |
|
164 CPosLmSearchCriteria* aCriteria) const |
|
165 { |
|
166 JELOG2(EJavaLocation); |
|
167 User::LeaveIfError(aCompositeCriteria.AddArgument(aCriteria)); |
|
168 CleanupStack::Pop(aCriteria); |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // CLAPILandmarkSearchFactory::CLAPILandmarkSearchFactory |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 CLAPILandmarkSearchFactory::CLAPILandmarkSearchFactory( |
|
176 CPosLandmarkDatabase& aDatabase) : |
|
177 iDatabase(aDatabase) |
|
178 { |
|
179 JELOG2(EJavaLocation); |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CLAPILandmarkSearchFactory::ConstructL |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CLAPILandmarkSearchFactory::ConstructL() |
|
187 { |
|
188 JELOG2(EJavaLocation); |
|
189 iLmSearch = CPosLandmarkSearch::NewL(iDatabase); |
|
190 } |
|
191 |
|
192 // End of file |