1 /* |
|
2 * Copyright (c) 2010 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: LocationPickerDataManager private implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <HbIcon> |
|
19 #include <locationdatalookupdb.h> |
|
20 #include <QFile> |
|
21 #include "locationpickerdatamanager_p.h" |
|
22 |
|
23 |
|
24 // ---------------------------------------------------------------------------- |
|
25 // LocationPickerDataManagerPrivate::LocationPickerDataManagerPrivate() |
|
26 // ---------------------------------------------------------------------------- |
|
27 |
|
28 LocationPickerDataManagerPrivate::LocationPickerDataManagerPrivate() : |
|
29 mModel( NULL ), |
|
30 mViewType( ELocationPickerContent ), |
|
31 mDb( NULL ) |
|
32 { |
|
33 mDb = new LocationDataLookupDb(); |
|
34 mDb->open(); |
|
35 } |
|
36 |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // LocationPickerDataManagerPrivate::~LocationPickerDataManagerPrivate() |
|
40 // ---------------------------------------------------------------------------- |
|
41 LocationPickerDataManagerPrivate::~LocationPickerDataManagerPrivate() |
|
42 { |
|
43 // delete the member variables; |
|
44 if( mDb ) |
|
45 { |
|
46 mDb->close(); |
|
47 delete mDb; |
|
48 mDb = NULL; |
|
49 } |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // LocationPickerDataManagerPrivate::populateModel() |
|
54 // ---------------------------------------------------------------------------- |
|
55 bool LocationPickerDataManagerPrivate::populateModel( QStandardItemModel &aModel, |
|
56 TViewType aViewType, quint32 aCollectionId ) |
|
57 { |
|
58 mModel = &aModel; |
|
59 mViewType = aViewType; |
|
60 |
|
61 if( !mDb ) |
|
62 { |
|
63 // no items in the landmark database, so return false. |
|
64 return false; |
|
65 } |
|
66 |
|
67 switch( mViewType ) |
|
68 { |
|
69 case ELocationPickerContent: |
|
70 case ELocationPickerSearchView: |
|
71 { |
|
72 QList<QLookupItem> itemArray; |
|
73 mDb->getEntries( itemArray ); |
|
74 return populateLandmarks( itemArray ); |
|
75 } |
|
76 |
|
77 case ELocationPickerCollectionListContent: |
|
78 { |
|
79 QList<int> aCount; |
|
80 mDb->getCount(aCount, aCollectionId); |
|
81 populateCollections(aCount); |
|
82 return true; |
|
83 } |
|
84 case ELocationPickerCollectionContent: |
|
85 { |
|
86 QList<QLookupItem> itemArray; |
|
87 mDb->getEntries( itemArray, aCollectionId ); |
|
88 if( itemArray.count() == 0 ) |
|
89 return false; |
|
90 |
|
91 return populateLandmarks( itemArray ); |
|
92 } |
|
93 } |
|
94 return true; |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // LocationPickerDataManagerPrivate::populateLandmarks() |
|
99 // ---------------------------------------------------------------------------- |
|
100 |
|
101 bool LocationPickerDataManagerPrivate::populateLandmarks( QList<QLookupItem> &aItemArray ) |
|
102 { |
|
103 mModel->clear(); |
|
104 |
|
105 if( !aItemArray.count() ) |
|
106 { |
|
107 return false; |
|
108 } |
|
109 QString lmAddressLine1; |
|
110 QString lmAddressLine2; |
|
111 QString contextAddress; |
|
112 QString contextAddressCountry; |
|
113 |
|
114 for( int i = 0; i < aItemArray.count(); i++ ) |
|
115 { |
|
116 contextAddress.clear(); |
|
117 contextAddressCountry.clear(); |
|
118 lmAddressLine1.clear(); |
|
119 lmAddressLine2.clear(); |
|
120 |
|
121 if( !aItemArray[i].mIsDuplicate ) |
|
122 { |
|
123 lmAddressLine1 = aItemArray[i].mName; |
|
124 |
|
125 bool addressEmtpy = true; // used to check if address line 2 is empty |
|
126 if( !aItemArray[i].mStreet.isEmpty() ) |
|
127 { |
|
128 if( lmAddressLine1.isEmpty() ) |
|
129 { |
|
130 lmAddressLine1 = aItemArray[i].mStreet; |
|
131 } |
|
132 else |
|
133 { |
|
134 lmAddressLine2 = aItemArray[i].mStreet; |
|
135 addressEmtpy = EFalse; |
|
136 } |
|
137 } |
|
138 if( !aItemArray[i].mCity.isEmpty() ) |
|
139 { |
|
140 if( lmAddressLine1.isEmpty() ) |
|
141 { |
|
142 lmAddressLine1 = aItemArray[i].mCity; |
|
143 } |
|
144 else |
|
145 { |
|
146 if( !addressEmtpy ) |
|
147 { |
|
148 lmAddressLine2 = lmAddressLine2 + KSeparator; |
|
149 lmAddressLine2 = lmAddressLine2 + KSpace; |
|
150 lmAddressLine2 = lmAddressLine2 + aItemArray[i].mCity; |
|
151 } |
|
152 else |
|
153 { |
|
154 lmAddressLine2 = aItemArray[i].mCity; |
|
155 addressEmtpy = EFalse; |
|
156 } |
|
157 } |
|
158 } |
|
159 if( !aItemArray[i].mState.isEmpty() ) |
|
160 { |
|
161 if( lmAddressLine1.isEmpty() ) |
|
162 { |
|
163 lmAddressLine1 = aItemArray[i].mState; |
|
164 } |
|
165 else |
|
166 { |
|
167 if( !addressEmtpy ) |
|
168 { |
|
169 lmAddressLine2 = lmAddressLine2 + KSeparator; |
|
170 lmAddressLine2 = lmAddressLine2 + KSpace; |
|
171 lmAddressLine2 = lmAddressLine2 + aItemArray[i].mState; |
|
172 } |
|
173 else |
|
174 { |
|
175 lmAddressLine2 = aItemArray[i].mState; |
|
176 addressEmtpy = EFalse; |
|
177 } |
|
178 } |
|
179 } |
|
180 contextAddress = lmAddressLine2; |
|
181 if( !aItemArray[i].mCountry.isEmpty() ) |
|
182 { |
|
183 if( !addressEmtpy ) |
|
184 { |
|
185 lmAddressLine2 = lmAddressLine2 + KSeparator; |
|
186 lmAddressLine2 = lmAddressLine2 + KSpace; |
|
187 lmAddressLine2 = lmAddressLine2 + aItemArray[i].mCountry; |
|
188 } |
|
189 else |
|
190 { |
|
191 lmAddressLine2 = aItemArray[i].mCountry; |
|
192 addressEmtpy = EFalse; |
|
193 } |
|
194 contextAddressCountry = aItemArray[i].mCountry; |
|
195 } |
|
196 // set icons based on contact address type |
|
197 QVariantList icons; |
|
198 HbIcon adressTypeIcon; |
|
199 HbIcon potraitIcon; |
|
200 QString adressType; |
|
201 bool adressIconPresent = false; |
|
202 if( aItemArray[i].mSourceType == ESourceContactsHome ) |
|
203 { |
|
204 adressTypeIcon = HbIcon(KContactHomeIcon); |
|
205 adressType = KContactHomeIcon; |
|
206 adressIconPresent = true; |
|
207 } |
|
208 else if( aItemArray[i].mSourceType == ESourceContactsWork ) |
|
209 { |
|
210 adressTypeIcon = HbIcon(KContactWorkIcon); |
|
211 adressType = KContactWorkIcon; |
|
212 adressIconPresent = true; |
|
213 } |
|
214 |
|
215 if( aItemArray[i].mSourceType == ESourceCalendar ) |
|
216 { |
|
217 potraitIcon = HbIcon( KCalendarImage ); |
|
218 } |
|
219 else if( aItemArray[i].mSourceType == ESourceContactsWork || aItemArray[i].mSourceType |
|
220 == ESourceContactsHome || aItemArray[i].mSourceType == ESourceContactsPref ) |
|
221 { |
|
222 potraitIcon = HbIcon( KContactsImage ); |
|
223 } |
|
224 else |
|
225 { |
|
226 potraitIcon = HbIcon( KDummyImage ); |
|
227 } |
|
228 |
|
229 // create a list item and set to model |
|
230 QStringList addressData; |
|
231 QString landscapeIconPath; |
|
232 |
|
233 if( QFile::exists( aItemArray[i].mMapTilePath ) ) |
|
234 { |
|
235 //draw maptile Icon |
|
236 landscapeIconPath = QString( aItemArray[i].mMapTilePath ); |
|
237 } |
|
238 else |
|
239 { |
|
240 //draw dummy icon |
|
241 landscapeIconPath = QString(""); |
|
242 } |
|
243 addressData.clear(); |
|
244 icons<<potraitIcon; |
|
245 if(adressIconPresent) |
|
246 { |
|
247 icons<<adressTypeIcon; |
|
248 } |
|
249 QStringList contextList; |
|
250 contextList<<lmAddressLine1<<contextAddress<<contextAddressCountry; |
|
251 QStandardItem *modelItem = new QStandardItem(); |
|
252 addressData << lmAddressLine1 << lmAddressLine2; |
|
253 modelItem->setData(QVariant(addressData), Qt::DisplayRole); |
|
254 modelItem->setData( icons, Qt::DecorationRole ); |
|
255 modelItem->setData( aItemArray[i].mId, Qt::UserRole ); |
|
256 modelItem->setData(landscapeIconPath,Qt::UserRole+1); |
|
257 modelItem->setData(adressType,Qt::UserRole+2); |
|
258 modelItem->setData(QVariant(contextList), Qt::UserRole+3); |
|
259 |
|
260 mModel->appendRow( modelItem ); |
|
261 } |
|
262 } |
|
263 |
|
264 return true; |
|
265 } |
|
266 |
|
267 // ---------------------------------------------------------------------------- |
|
268 // LocationPickerDataManagerPrivate::populateCollections() |
|
269 // ---------------------------------------------------------------------------- |
|
270 |
|
271 void LocationPickerDataManagerPrivate::populateCollections(QList<int>& aCount) |
|
272 { |
|
273 // add contact collection |
|
274 QStandardItem *modelItemContact = new QStandardItem(); |
|
275 int conNum = aCount.value(0); |
|
276 QString contactCollectionNum(hbTrId("txt_lint_list_ln_items",conNum)); |
|
277 QString contactCollectionName( hbTrId("txt_lint_list_contact_addresses") ); |
|
278 |
|
279 |
|
280 QStringList contact = (QStringList()<<contactCollectionName<<contactCollectionNum); |
|
281 modelItemContact->setData( QVariant( contact ), Qt::DisplayRole ); |
|
282 |
|
283 modelItemContact->setData( HbIcon ( KCollectionsContacts ), Qt::DecorationRole ); |
|
284 modelItemContact->setData( ESourceLandmarksContactsCat, Qt::UserRole ); |
|
285 mModel->appendRow( modelItemContact ); |
|
286 |
|
287 //txt_lint_list_calender_addresses |
|
288 int calNum = aCount.value(1); |
|
289 QString calendarCollectionNum(hbTrId("txt_lint_list_ln_items",calNum)); |
|
290 QString calendarCollectionName( hbTrId("txt_lint_list_calendar_locations") ); |
|
291 QStringList calender = (QStringList()<<calendarCollectionName<<calendarCollectionNum); |
|
292 |
|
293 QStandardItem *modelItemCalendar = new QStandardItem(); |
|
294 modelItemCalendar->setData( QVariant( calender ), Qt::DisplayRole ); |
|
295 modelItemCalendar->setData( HbIcon ( KCollectionsCalendar ), Qt::DecorationRole ); |
|
296 modelItemCalendar->setData( ESourceLandmarksCalendarCat, Qt::UserRole ); |
|
297 mModel->appendRow( modelItemCalendar ); |
|
298 |
|
299 //txt_lint_list_places_addresses |
|
300 int placNum = aCount.value(2); |
|
301 QString placesCollectionNum(hbTrId("txt_lint_list_ln_items",placNum)); |
|
302 QString placesCollectionName( hbTrId("txt_lint_list_places") ); |
|
303 QStringList places = (QStringList()<<placesCollectionName<<placesCollectionNum); |
|
304 |
|
305 QStandardItem *modelItemPlaces = new QStandardItem(); |
|
306 modelItemPlaces->setData( QVariant( places ), Qt::DisplayRole ); |
|
307 modelItemPlaces->setData( HbIcon (KCollectionsPlaces), Qt::DecorationRole ); |
|
308 modelItemPlaces->setData( ESourceLandmarks, Qt::UserRole ); |
|
309 mModel->appendRow( modelItemPlaces ); |
|
310 } |
|
311 |
|
312 |
|
313 // ---------------------------------------------------------------------------- |
|
314 // LocationPickerDataManagerPrivate::getLocationItem() |
|
315 // ---------------------------------------------------------------------------- |
|
316 |
|
317 void LocationPickerDataManagerPrivate::getLocationItem( quint32 aId, QLocationPickerItem& aItem ) |
|
318 { |
|
319 QLookupItem item; |
|
320 item.mId = aId; |
|
321 if( mDb->findEntryById( item ) ) |
|
322 { |
|
323 aItem.mName = item.mName; |
|
324 aItem.mStreet = item.mStreet; |
|
325 aItem.mPostalCode = item.mPostalCode; |
|
326 aItem.mCity = item.mCity; |
|
327 aItem.mState = item.mState; |
|
328 aItem.mCountry = item.mCountry; |
|
329 aItem.mLatitude = item.mLatitude; |
|
330 aItem.mLongitude = item.mLongitude; |
|
331 aItem.mIsValid = true; |
|
332 } |
|
333 else |
|
334 { |
|
335 aItem.mIsValid = false; |
|
336 } |
|
337 |
|
338 } |
|
339 |
|