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: |
|
15 * Maptile service implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <centralrepository.h> |
|
21 #include <locationservicedefines.h> |
|
22 #include <qvaluespacepublisher.h> |
|
23 #include <qvaluespacesubscriber.h> |
|
24 #include <qfile.h> |
|
25 #include "cntmaptileservice.h" |
|
26 #include "cntmaptiledblookuptable.h" |
|
27 |
|
28 // CONSTANTS |
|
29 // Maptile interface uid |
|
30 const TUid KUidMapTileInterface = { 0x2002C3A8 }; |
|
31 // Central Repository Key IDs |
|
32 const TInt KEnableLocationFeature = 0x1; |
|
33 |
|
34 const char *CNT_MAPTILE_STATUS_RECEIVER = "/maptilestatuspublisher/name"; |
|
35 const char *CNT_MAPTILE_STATUS_PUBLISHER = "/cntmaptilepublisher"; |
|
36 |
|
37 const char* CNT_PORTRAIT_MAPTILE_IMAGE = "_Vertical"; |
|
38 const char* CNT_LANDSCAPE_MAPTILE_IMAGE = "_Contact_Horizontal"; |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CntMapTileService::CntMapTileService() |
|
42 // Default constructor |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CntMapTileService::CntMapTileService() |
|
46 { |
|
47 //publisher |
|
48 mPublisher = NULL; |
|
49 |
|
50 //subscriber |
|
51 mSubscriber = new QValueSpaceSubscriber( CNT_MAPTILE_STATUS_RECEIVER ); |
|
52 //Connect for maptile status change key |
|
53 QObject::connect(mSubscriber, SIGNAL(contentsChanged()), this, SLOT(setMaptileStatus())); |
|
54 |
|
55 } |
|
56 |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CntMapTileService::~CntMapTileService() |
|
60 // Destructor |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CntMapTileService::~CntMapTileService() |
|
64 { |
|
65 if( mSubscriber ) |
|
66 { |
|
67 delete mSubscriber; |
|
68 mSubscriber = NULL; |
|
69 } |
|
70 |
|
71 if( mPublisher ) |
|
72 { |
|
73 delete mPublisher; |
|
74 mPublisher = NULL; |
|
75 } |
|
76 } |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CntMapTileService::isLocationFeatureEnabled() |
|
79 // Checks whether location feature is enabled or disabled |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 bool CntMapTileService::isLocationFeatureEnabled() |
|
83 { |
|
84 //Create the centrep with uid 0x2002C3A8 |
|
85 bool enableLocationFeature = false; |
|
86 |
|
87 CRepository* centralRepository = NULL; |
|
88 |
|
89 TRAPD( err, centralRepository = CRepository::NewL( KUidMapTileInterface ) ); |
|
90 |
|
91 if ( KErrNone == err ) |
|
92 { |
|
93 TInt repValue; |
|
94 |
|
95 //Get the Location feature flag |
|
96 TInt ret = centralRepository->Get( KEnableLocationFeature , repValue ); |
|
97 |
|
98 if ( ret == KErrNone && repValue == 1 ) |
|
99 { |
|
100 enableLocationFeature = true; |
|
101 } |
|
102 |
|
103 delete centralRepository; |
|
104 } |
|
105 |
|
106 return enableLocationFeature; |
|
107 |
|
108 } |
|
109 |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CntMapTileService::getMapTileImage() |
|
113 // Gets the maptile image path associated with a contact. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 int CntMapTileService::getMapTileImage( |
|
117 int contactId , |
|
118 ContactAddressType sourceType, |
|
119 QString& imagePath, |
|
120 Qt::Orientations orientation ) |
|
121 { |
|
122 |
|
123 TLookupItem lookupItem; |
|
124 |
|
125 int addressCount = 0; |
|
126 int maptileStatus = MapTileFetchingUnknownError; |
|
127 |
|
128 //Read the entry from maptile database |
|
129 int error = readEntryFromMaptileDataBase( contactId, sourceType, lookupItem, addressCount ); |
|
130 |
|
131 //if entry available returns the file path otherwise NULL. |
|
132 if ( KErrNone == error ) |
|
133 { |
|
134 maptileStatus = lookupItem.iFetchingStatus; |
|
135 |
|
136 if( maptileStatus == MapTileFetchingCompleted ) |
|
137 { |
|
138 //Get the image path |
|
139 QString imageFile((QChar*)lookupItem.iFilePath.Ptr(), |
|
140 lookupItem.iFilePath.Length()); |
|
141 if( orientation == Qt::Vertical ) |
|
142 { |
|
143 imageFile.append( CNT_PORTRAIT_MAPTILE_IMAGE ); |
|
144 } |
|
145 else |
|
146 { |
|
147 imageFile.append( CNT_LANDSCAPE_MAPTILE_IMAGE ); |
|
148 } |
|
149 imagePath = imageFile; |
|
150 |
|
151 //Check if File exists |
|
152 if ( !QFile::exists( imagePath ) ) |
|
153 { |
|
154 imagePath.clear(); |
|
155 maptileStatus = MapTileFetchingUnknownError; |
|
156 } |
|
157 } |
|
158 else if( maptileStatus == MapTileFetchingNetworkError || |
|
159 maptileStatus == MapTileFetchingInProgress ) |
|
160 { |
|
161 //Publish the contact id for maptile processing |
|
162 publishValue( contactId, sourceType, addressCount ); |
|
163 } |
|
164 |
|
165 } |
|
166 else if ( KErrNotFound == error ) |
|
167 { |
|
168 //If entry is not found , it will be a newly added entry. |
|
169 publishValue( contactId, sourceType, addressCount ); |
|
170 maptileStatus = MapTileFetchingInProgress; |
|
171 } |
|
172 |
|
173 //Return the maptile status |
|
174 return maptileStatus; |
|
175 } |
|
176 |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CntMapTileService::setMaptileStatus() |
|
180 // Emits the maptile status changed event to contact application |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CntMapTileService::setMaptileStatus() |
|
184 { |
|
185 QString imagePath; |
|
186 ContactAddressType addressType = AddressPreference; |
|
187 |
|
188 QStringList subPath = mSubscriber->subPaths(); |
|
189 QVariant value = mSubscriber->value(subPath.at(0)); |
|
190 |
|
191 //Subscriber Protocol : [contactid-addresstype-maptilestatus] |
|
192 QStringList text = value.toString().split("-"); |
|
193 int id = text.at(0).toInt(); |
|
194 int status = text.at(2).toInt(); |
|
195 |
|
196 switch( text.at(1).toInt() ) |
|
197 { |
|
198 case ESourceContactsPref: |
|
199 addressType = AddressPreference; |
|
200 break; |
|
201 case ESourceContactsWork: |
|
202 addressType = AddressWork; |
|
203 break; |
|
204 case ESourceContactsHome: |
|
205 addressType = AddressHome; |
|
206 break; |
|
207 default: |
|
208 break; |
|
209 } |
|
210 |
|
211 //Emit the maptile status signal |
|
212 int type = addressType; |
|
213 if( mLastViewedContactId == id ) |
|
214 { |
|
215 emit maptileFetchingStatusUpdate( mLastViewedContactId, type , status ); |
|
216 } |
|
217 } |
|
218 |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CntMapTileService::publishValue() |
|
222 // Publish the the contact id and address for which maptile to be processed. |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CntMapTileService::publishValue( int id, ContactAddressType sourceType, int addressCount ) |
|
226 { |
|
227 |
|
228 mLastViewedContactId = id; |
|
229 int addressType = ESourceInvalid; |
|
230 |
|
231 switch( sourceType ) |
|
232 { |
|
233 case AddressPreference: |
|
234 addressType = ESourceContactsPref; |
|
235 break; |
|
236 case AddressWork: |
|
237 addressType = ESourceContactsWork; |
|
238 break; |
|
239 case AddressHome: |
|
240 addressType = ESourceContactsHome; |
|
241 break; |
|
242 } |
|
243 |
|
244 if ( !mPublisher ) |
|
245 { |
|
246 /* Constructs a QValueSpacePublisher that publishes values under path /mypublisher*/ |
|
247 mPublisher = new QValueSpacePublisher( CNT_MAPTILE_STATUS_PUBLISHER, this); |
|
248 } |
|
249 |
|
250 /* Publisher protocol [appid-addresstype-count] */ |
|
251 mContactEntryInfo.clear(); |
|
252 mContactEntryInfo.append( QVariant(id).toString()); |
|
253 mContactEntryInfo.append( QChar('-') ); |
|
254 mContactEntryInfo.append( QVariant(addressType).toString()); |
|
255 mContactEntryInfo.append( QChar('-') ); |
|
256 mContactEntryInfo.append( QVariant(addressCount).toString() ); |
|
257 |
|
258 mPublisher->setValue("name", mContactEntryInfo.toAscii() ); |
|
259 mPublisher->sync(); |
|
260 |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CntMapTileService::readEntryFromMaptileDataBase() |
|
265 // Read the entry from maptile database |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 int CntMapTileService::readEntryFromMaptileDataBase( |
|
269 int id, ContactAddressType sourceType, TLookupItem& aLookupItem, int& aNoOfAddress ) |
|
270 { |
|
271 |
|
272 //Maptile database instance |
|
273 CLookupMapTileDatabase* mapTileDatabase = NULL; |
|
274 |
|
275 TRAPD( err, mapTileDatabase = CLookupMapTileDatabase::NewL( |
|
276 KMapTileLookupDatabaseName ) ); |
|
277 |
|
278 if ( KErrNone == err ) |
|
279 { |
|
280 int appId = id; |
|
281 TRAP( err, aNoOfAddress = mapTileDatabase->FindNumberOfAddressL(appId) ); |
|
282 |
|
283 if( err != KErrNone ) |
|
284 { |
|
285 aNoOfAddress = 0; |
|
286 } |
|
287 |
|
288 aLookupItem.iUid = id; |
|
289 switch( sourceType ) |
|
290 { |
|
291 case AddressPreference: |
|
292 aLookupItem.iSource = ESourceContactsPref; |
|
293 break; |
|
294 case AddressWork: |
|
295 aLookupItem.iSource = ESourceContactsWork; |
|
296 break; |
|
297 case AddressHome: |
|
298 aLookupItem.iSource = ESourceContactsHome; |
|
299 break; |
|
300 default: |
|
301 break; |
|
302 } |
|
303 |
|
304 TRAP( err , mapTileDatabase->FindEntryL( aLookupItem ) ); |
|
305 |
|
306 //delet the database instance |
|
307 delete mapTileDatabase; |
|
308 |
|
309 } |
|
310 |
|
311 return err; |
|
312 } |
|
313 |
|
314 // End of file |
|
315 |
|