22 #include <qversitcontactimporter.h> |
22 #include <qversitcontactimporter.h> |
23 #include <qversitdocument.h> |
23 #include <qversitdocument.h> |
24 |
24 |
25 #include <QPixmap> |
25 #include <QPixmap> |
26 #include <QFile> |
26 #include <QFile> |
|
27 #include <QUrl> |
27 |
28 |
28 /* NOTE! THIS SERVICE WILL BE RENAMED TO com.nokia.services.phonebook.Services */ |
29 /* NOTE! THIS SERVICE WILL BE RENAMED TO com.nokia.services.phonebook.Services */ |
29 CntServiceHandler::CntServiceHandler(QObject *parent): |
30 CntServiceHandler::CntServiceHandler(QObject *parent): |
30 XQServiceProvider(QLatin1String("com.nokia.services.phonebookservices.Fetch"), parent), |
31 XQServiceProvider(QLatin1String("com.nokia.services.phonebookservices.Fetch"), parent), |
31 mCurrentRequestIndex(0) |
32 mCurrentRequestIndex(0) |
32 { |
33 { |
33 publishAll(); |
34 publishAll(); |
34 |
35 |
35 // Definition names supported in symbian back-end |
36 // Definition names supported in symbian back-end |
36 QString def("%1"); |
37 m_definitionNames << QContactName::DefinitionName; |
37 m_definitionNames << def.arg(QContactName::DefinitionName); |
38 m_definitionNames << QContactNickname::DefinitionName; |
38 m_definitionNames << def.arg(QContactNickname::DefinitionName); |
39 m_definitionNames << QContactPhoneNumber::DefinitionName; |
39 m_definitionNames << def.arg(QContactPhoneNumber::DefinitionName); |
40 m_definitionNames << QContactEmailAddress::DefinitionName; |
40 m_definitionNames << def.arg(QContactEmailAddress::DefinitionName); |
41 m_definitionNames << QContactAddress::DefinitionName; |
41 m_definitionNames << def.arg(QContactAddress::DefinitionName); |
42 m_definitionNames << QContactUrl::DefinitionName; |
42 m_definitionNames << def.arg(QContactUrl::DefinitionName); |
43 m_definitionNames << QContactBirthday::DefinitionName; |
43 m_definitionNames << def.arg(QContactBirthday::DefinitionName); |
44 m_definitionNames << QContactOrganization::DefinitionName; |
44 m_definitionNames << def.arg(QContactOrganization::DefinitionName); |
45 m_definitionNames << QContactSyncTarget::DefinitionName; |
45 m_definitionNames << def.arg(QContactSyncTarget::DefinitionName); |
46 m_definitionNames << QContactNote::DefinitionName; |
46 m_definitionNames << def.arg(QContactNote::DefinitionName); |
47 m_definitionNames << QContactFamily::DefinitionName; |
47 m_definitionNames << def.arg(QContactFamily::DefinitionName); |
48 m_definitionNames << QContactAvatar::DefinitionName; |
48 m_definitionNames << def.arg(QContactAvatar::DefinitionName); |
49 m_definitionNames << QContactAnniversary::DefinitionName; |
49 m_definitionNames << def.arg(QContactAnniversary::DefinitionName); |
50 m_definitionNames << QContactGeoLocation::DefinitionName; |
50 m_definitionNames << def.arg(QContactGeoLocation::DefinitionName); |
51 m_definitionNames << QContactGender::DefinitionName; |
51 m_definitionNames << def.arg(QContactGender::DefinitionName); |
52 m_definitionNames << QContactOnlineAccount::DefinitionName; |
52 m_definitionNames << def.arg(QContactOnlineAccount::DefinitionName); |
|
53 } |
53 } |
54 |
54 |
55 CntServiceHandler::~CntServiceHandler() |
55 CntServiceHandler::~CntServiceHandler() |
56 { |
56 { |
57 } |
57 } |
143 reader.startReading(); |
143 reader.startReading(); |
144 reader.waitForFinished(); |
144 reader.waitForFinished(); |
145 // Use the resulting document(s)... |
145 // Use the resulting document(s)... |
146 QVersitContactImporter importer; |
146 QVersitContactImporter importer; |
147 QList<QVersitDocument> versitDocuments = reader.results(); |
147 QList<QVersitDocument> versitDocuments = reader.results(); |
148 if(versitDocuments.count() > 0) |
148 if (versitDocuments.count() > 0 |
149 { |
149 && importer.importDocuments(versitDocuments)) |
150 contact = importer.importContacts(versitDocuments).first(); |
150 { |
151 } |
151 QList<QContact> contacts = importer.contacts(); |
|
152 if (contacts.count() > 0) |
|
153 contact = contacts.first(); |
|
154 } |
152 file.close(); |
155 file.close(); |
153 |
156 |
154 // Save photo to image file |
157 // Save thumbnail images |
155 // image file used in phonebook to generate thumbnail |
158 QList<QContactThumbnail> details = contact.details<QContactThumbnail>(); |
156 QList<QContactAvatar> details = contact.details<QContactAvatar>(); |
159 for (int i = 0;i < details.count();i++) |
157 if (details.count() > 0) |
160 { |
158 { |
161 if (!details.at(i).thumbnail().isNull()) |
159 for (int i = 0;i < details.count();i++) |
162 { |
|
163 QString imagepath; |
|
164 QPixmap pixmap = QPixmap::fromImage(details.at(i).thumbnail()); |
|
165 if (imageUtility.createImage(pixmap,imagepath)) |
160 { |
166 { |
161 if (details.at(i).subType() == QContactAvatar::SubTypeImage) |
167 // Update contact detail |
|
168 QContactAvatar detail=details.at(i); |
|
169 detail.setImageUrl(imagepath); |
|
170 contact.saveDetail(&detail); |
|
171 } |
|
172 } |
|
173 } |
|
174 |
|
175 removeNotSupportedDetails(contact); |
|
176 removeNotSupportedFields(contact); |
|
177 emit launchEditor(contact); |
|
178 |
|
179 mCurrentRequestIndex = setCurrentRequestAsync(); |
|
180 } |
|
181 |
|
182 /* |
|
183 * Remove details not supported in symbian back-end. |
|
184 */ |
|
185 void CntServiceHandler::removeNotSupportedDetails(QContact& contact) |
|
186 { |
|
187 // Check definition map, remove details not supported |
|
188 for (int i=0; i < contact.details().count(); i++) |
|
189 { |
|
190 if (!m_definitionNames.contains(contact.details().at(i).definitionName())) |
|
191 { |
|
192 QContactDetail detail= contact.details().at(i); |
|
193 contact.removeDetail(&detail); |
|
194 } |
|
195 } |
|
196 } |
|
197 /* |
|
198 * Remove fields not supported in symbian back-end. |
|
199 */ |
|
200 void CntServiceHandler::removeNotSupportedFields(QContact& contact) |
|
201 { |
|
202 QContactManager cm("symbian"); |
|
203 |
|
204 // Not all fields are supported in symbian back-end |
|
205 // Remove not supported fields |
|
206 for (int i=0; i < contact.details().count(); i++) |
|
207 { |
|
208 QContactDetail detail = contact.details().at(i); |
|
209 if (detail.definitionName() == QContactAddress::DefinitionName) |
|
210 { |
|
211 QContactAddress addrDetail = static_cast<QContactAddress>(detail); |
|
212 |
|
213 // Sub-types not supported |
|
214 if (detail.removeValue(QContactAddress::FieldSubTypes)) |
|
215 contact.saveDetail(&detail); |
|
216 } |
|
217 else if (detail.definitionName() == QContactAnniversary::DefinitionName) |
|
218 { |
|
219 QContactAnniversary annivDetail = static_cast<QContactAnniversary>(detail); |
|
220 |
|
221 // Sub-types not supported |
|
222 if (detail.removeValue(QContactAnniversary::FieldSubType)) |
|
223 contact.saveDetail(&detail); |
|
224 |
|
225 // Context not supported |
|
226 if (detail.removeValue(QContactDetail::FieldContext)) |
|
227 contact.saveDetail(&detail); |
|
228 } |
|
229 else if (detail.definitionName() == QContactPhoneNumber::DefinitionName) |
|
230 { |
|
231 QContactPhoneNumber phoneDetail = static_cast<QContactPhoneNumber>(detail); |
|
232 |
|
233 if (phoneDetail.subTypes().size() == 0) |
|
234 { |
|
235 // No Sub-type found, set as SubTypeMobile |
|
236 phoneDetail.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
|
237 contact.saveDetail(&phoneDetail); |
|
238 } |
|
239 else if (phoneDetail.subTypes().size() > 0 ) |
|
240 { |
|
241 // Sub-types not supported |
|
242 if (phoneDetail.subTypes().contains(QContactPhoneNumber::SubTypeVoice) |
|
243 || phoneDetail.subTypes().contains(QContactPhoneNumber::SubTypeMessagingCapable) |
|
244 || phoneDetail.subTypes().contains(QContactPhoneNumber::SubTypeVideo)) |
162 { |
245 { |
163 if(!details.at(i).pixmap().isNull()) |
246 // Replace as SubTypeMobile |
164 { |
247 phoneDetail.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
165 int err; |
248 contact.saveDetail(&phoneDetail); |
166 QString imagepath; |
|
167 QPixmap pixmap(details.at(i).pixmap()); |
|
168 if(imageUtility.createImage(pixmap,imagepath,err)) |
|
169 { |
|
170 // Update contact detail |
|
171 QContactAvatar detail=details.at(i); |
|
172 detail.setAvatar(imagepath); |
|
173 contact.saveDetail(&detail); |
|
174 } |
|
175 } |
|
176 } |
249 } |
177 } |
250 } |
178 } |
251 } |
179 removeDetails(contact); |
252 else if (detail.definitionName() == QContactUrl::DefinitionName) |
180 removeFields(contact); |
253 { |
181 emit launchEditor(contact); |
254 QContactUrl urlDetail = static_cast<QContactUrl>(detail); |
182 |
255 |
183 mCurrentRequestIndex = setCurrentRequestAsync(); |
256 QString stype=QContactUrl::SubTypeHomePage; |
184 } |
257 if (urlDetail.subType().compare(stype) != 0) |
185 |
|
186 /* |
|
187 * Remove details not supported in symbian back-end. |
|
188 */ |
|
189 void CntServiceHandler::removeDetails(QContact& contact) |
|
190 { |
|
191 // Check definition map, remove details not supported |
|
192 for (int i=0; i < contact.details().count(); i++) |
|
193 { |
|
194 if (!m_definitionNames.contains(contact.details().at(i).definitionName())) |
|
195 { |
258 { |
196 QContactDetail detail= contact.details().at(i); |
259 detail.removeValue(QContactUrl::FieldSubType); |
197 contact.removeDetail(&detail); |
260 contact.saveDetail(&detail); |
198 } |
261 } |
199 } |
262 } |
200 } |
263 } |
201 /* |
|
202 * Remove fields not supported in symbian back-end. |
|
203 */ |
|
204 void CntServiceHandler::removeFields(QContact& contact) |
|
205 { |
|
206 // Replace contact |
|
207 QContactManager cm("symbian"); |
|
208 for (int i=0; i < contact.details().count(); i++) |
|
209 { |
|
210 QContactDetail detail = contact.details().at(i); |
|
211 if(detail.definitionName() == QContactBirthday::DefinitionName) |
|
212 { |
|
213 // Not all fields are supported in symbian back-end, replace |
|
214 QContactBirthday saveBod; |
|
215 QContactBirthday bodDetail = static_cast<QContactBirthday>(detail); |
|
216 |
|
217 if(!bodDetail.date().isNull()) |
|
218 saveBod.setDate(bodDetail.date()); |
|
219 |
|
220 contact.removeDetail(&bodDetail); |
|
221 contact.saveDetail(&saveBod); |
|
222 } |
|
223 else if(detail.definitionName() == QContactNickname::DefinitionName) |
|
224 { |
|
225 // Not all fields are supported in symbian back-end, replace |
|
226 QContactNickname saveName; |
|
227 QContactNickname nameDetail = static_cast<QContactNickname>(detail); |
|
228 |
|
229 if(!nameDetail.nickname().isEmpty()) |
|
230 saveName.setNickname(nameDetail.nickname()); |
|
231 |
|
232 contact.removeDetail(&nameDetail); |
|
233 contact.saveDetail(&saveName); |
|
234 } |
|
235 else if(detail.definitionName() == QContactNote::DefinitionName) |
|
236 { |
|
237 // Not all fields are supported in symbian back-end, replace |
|
238 QContactNote saveNote; |
|
239 QContactNote noteDetail = static_cast<QContactNote>(detail); |
|
240 |
|
241 if(!noteDetail.note().isEmpty()) |
|
242 saveNote.setNote(noteDetail.note()); |
|
243 |
|
244 contact.removeDetail(¬eDetail); |
|
245 contact.saveDetail(&saveNote); |
|
246 } |
|
247 else if(detail.definitionName() == QContactOrganization::DefinitionName) |
|
248 { |
|
249 // Not all fields are supported in symbian back-end, replace |
|
250 QContactOrganization saveOrg; |
|
251 QContactOrganization orgDetail = static_cast<QContactOrganization>(detail); |
|
252 |
|
253 if(!orgDetail.name().isEmpty()) |
|
254 saveOrg.setName(orgDetail.name()); |
|
255 if(!orgDetail.title().isEmpty()) |
|
256 saveOrg.setTitle(orgDetail.title()); |
|
257 if(!orgDetail.assistantName().isEmpty()) |
|
258 saveOrg.setAssistantName(orgDetail.assistantName()); |
|
259 if(!orgDetail.department().isEmpty()) |
|
260 saveOrg.setDepartment(orgDetail.department()); |
|
261 |
|
262 if(orgDetail.contexts().size() > 0 |
|
263 && (orgDetail.contexts().contains(QContactDetail::ContextHome) |
|
264 || orgDetail.contexts().contains(QContactDetail::ContextWork))) |
|
265 { |
|
266 saveOrg.setContexts(orgDetail.contexts()); |
|
267 } |
|
268 |
|
269 contact.removeDetail(&orgDetail); |
|
270 contact.saveDetail(&saveOrg); |
|
271 } |
|
272 else if(detail.definitionName() == QContactAddress::DefinitionName) |
|
273 { |
|
274 // Not all fields are supported in symbian back-end, replace |
|
275 QContactAddress saveAddr; |
|
276 QContactAddress addrDetail = static_cast<QContactAddress>(detail); |
|
277 |
|
278 if(!addrDetail.street().isEmpty()) |
|
279 saveAddr.setStreet(addrDetail.street()); |
|
280 if(!addrDetail.locality().isEmpty()) |
|
281 saveAddr.setLocality(addrDetail.locality()); |
|
282 if(!addrDetail.region().isEmpty()) |
|
283 saveAddr.setRegion(addrDetail.region()); |
|
284 if(!addrDetail.postcode().isEmpty()) |
|
285 saveAddr.setPostcode(addrDetail.postcode()); |
|
286 if(!addrDetail.country().isEmpty()) |
|
287 saveAddr.setCountry(addrDetail.country()); |
|
288 if(!addrDetail.postOfficeBox().isEmpty()) |
|
289 saveAddr.setPostOfficeBox(addrDetail.postOfficeBox()); |
|
290 |
|
291 if(addrDetail.contexts().size() > 0 |
|
292 && (addrDetail.contexts().contains(QContactDetail::ContextHome) |
|
293 || addrDetail.contexts().contains(QContactDetail::ContextWork))) |
|
294 { |
|
295 saveAddr.setContexts(addrDetail.contexts()); |
|
296 } |
|
297 |
|
298 contact.removeDetail(&addrDetail); |
|
299 contact.saveDetail(&saveAddr); |
|
300 } |
|
301 else if(detail.definitionName() == QContactAnniversary::DefinitionName) |
|
302 { |
|
303 // Not all fields are supported in symbian back-end, replace |
|
304 QContactAnniversary saveAnniv; |
|
305 QContactAnniversary annivDetail = static_cast<QContactAnniversary>(detail); |
|
306 |
|
307 if(!annivDetail.originalDate().isNull()) |
|
308 saveAnniv.setOriginalDate(annivDetail.originalDate()); |
|
309 if(!annivDetail.event().isEmpty()) |
|
310 saveAnniv.setEvent(annivDetail.event()); |
|
311 |
|
312 contact.removeDetail(&annivDetail); |
|
313 contact.saveDetail(&saveAnniv); |
|
314 } |
|
315 else if(detail.definitionName() == QContactGender::DefinitionName) |
|
316 { |
|
317 // Not all fields are supported in symbian back-end, replace |
|
318 QContactGender saveGender; |
|
319 QContactGender genderDetail = static_cast<QContactGender>(detail); |
|
320 |
|
321 if(!genderDetail.gender().isEmpty()) |
|
322 saveGender.setGender(genderDetail.gender()); |
|
323 |
|
324 contact.removeDetail(&genderDetail); |
|
325 contact.saveDetail(&saveGender); |
|
326 } |
|
327 else if(detail.definitionName() == QContactGeoLocation::DefinitionName) |
|
328 { |
|
329 // Not all fields are supported in symbian back-end, replace |
|
330 QContactGeoLocation saveGeo; |
|
331 QContactGeoLocation geoDetail = static_cast<QContactGeoLocation>(detail); |
|
332 |
|
333 QString latitude,longitude; |
|
334 latitude.setNum(geoDetail.latitude()); |
|
335 longitude.setNum(geoDetail.longitude()); |
|
336 |
|
337 if(!latitude.isEmpty()) |
|
338 saveGeo.setLatitude(geoDetail.latitude()); |
|
339 if(!longitude.isEmpty()) |
|
340 saveGeo.setLongitude(geoDetail.longitude()); |
|
341 |
|
342 if(geoDetail.contexts().size() > 0 |
|
343 && (geoDetail.contexts().contains(QContactDetail::ContextHome) |
|
344 || geoDetail.contexts().contains(QContactDetail::ContextWork))) |
|
345 { |
|
346 saveGeo.setContexts(geoDetail.contexts()); |
|
347 } |
|
348 |
|
349 contact.removeDetail(&geoDetail); |
|
350 contact.saveDetail(&saveGeo); |
|
351 } |
|
352 else if(detail.definitionName() == QContactPhoneNumber::DefinitionName) |
|
353 { |
|
354 // Not all fields are supported in symbian back-end, replace |
|
355 QContactPhoneNumber savePhone; |
|
356 QContactPhoneNumber phoneDetail = static_cast<QContactPhoneNumber>(detail); |
|
357 |
|
358 if(!phoneDetail.number().isEmpty()) |
|
359 savePhone.setNumber(phoneDetail.number()); |
|
360 |
|
361 if(phoneDetail.subTypes().size() > 0) |
|
362 savePhone.setSubTypes(phoneDetail.subTypes()); |
|
363 |
|
364 if(phoneDetail.contexts().size() > 0 |
|
365 && (phoneDetail.contexts().contains(QContactDetail::ContextHome) |
|
366 || phoneDetail.contexts().contains(QContactDetail::ContextWork))) |
|
367 { |
|
368 savePhone.setContexts(phoneDetail.contexts()); |
|
369 } |
|
370 |
|
371 contact.removeDetail(&phoneDetail); |
|
372 contact.saveDetail(&savePhone); |
|
373 } |
|
374 else if(detail.definitionName() == QContactOnlineAccount::DefinitionName) |
|
375 { |
|
376 // Not all fields are supported in symbian back-end, replace |
|
377 QContactOnlineAccount saveOnlineAcc; |
|
378 QContactOnlineAccount onlineAccDetail = static_cast<QContactOnlineAccount>(detail); |
|
379 |
|
380 if(!onlineAccDetail.accountUri().isEmpty()) |
|
381 saveOnlineAcc.setAccountUri(onlineAccDetail.accountUri()); |
|
382 if(!onlineAccDetail.serviceProvider().isEmpty()) |
|
383 saveOnlineAcc.setServiceProvider(onlineAccDetail.serviceProvider()); |
|
384 if(!onlineAccDetail.presence().isEmpty()) |
|
385 saveOnlineAcc.setPresence(onlineAccDetail.presence()); |
|
386 if(!onlineAccDetail.statusMessage().isEmpty()) |
|
387 saveOnlineAcc.setStatusMessage(onlineAccDetail.statusMessage()); |
|
388 |
|
389 if(onlineAccDetail.subTypes().size() > 0) |
|
390 saveOnlineAcc.setSubTypes(onlineAccDetail.subTypes()); |
|
391 |
|
392 if(onlineAccDetail.contexts().size() > 0 |
|
393 && (onlineAccDetail.contexts().contains(QContactDetail::ContextHome) |
|
394 || onlineAccDetail.contexts().contains(QContactDetail::ContextWork))) |
|
395 { |
|
396 saveOnlineAcc.setContexts(onlineAccDetail.contexts()); |
|
397 } |
|
398 |
|
399 contact.removeDetail(&onlineAccDetail); |
|
400 contact.saveDetail(&saveOnlineAcc); |
|
401 } |
|
402 else if(detail.definitionName() == QContactUrl::DefinitionName) |
|
403 { |
|
404 // Not all fields are supported in symbian back-end, replace |
|
405 QContactUrl saveUrl; |
|
406 QContactUrl urlDetail = static_cast<QContactUrl>(detail); |
|
407 |
|
408 if(!urlDetail.url().isEmpty()) |
|
409 saveUrl.setUrl(urlDetail.url()); |
|
410 |
|
411 QString stype=QContactUrl::SubTypeHomePage; |
|
412 if(urlDetail.subType().compare(stype) == 0) |
|
413 { |
|
414 saveUrl.setSubType(stype); |
|
415 } |
|
416 |
|
417 if(urlDetail.contexts().size() > 0 |
|
418 && (urlDetail.contexts().contains(QContactDetail::ContextHome) |
|
419 || urlDetail.contexts().contains(QContactDetail::ContextWork))) |
|
420 { |
|
421 saveUrl.setContexts(urlDetail.contexts()); |
|
422 } |
|
423 |
|
424 contact.removeDetail(&urlDetail); |
|
425 contact.saveDetail(&saveUrl); |
|
426 } |
|
427 } |
|
428 } |
264 } |
429 /* |
265 /* |
430 Launch contact selection view with a given detail (selecting detail there opens the editor and adds the new detail) |
266 Launch contact selection view with a given detail (selecting detail there opens the editor and adds the new detail) |
431 */ |
267 */ |
432 void CntServiceHandler::editUpdateExisting(const QString &definitionName, const QString &value) |
268 void CntServiceHandler::editUpdateExisting(const QString &definitionName, const QString &value) |