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