17 |
17 |
18 #include "cntservices.h" |
18 #include "cntservices.h" |
19 #include "cntglobal.h" |
19 #include "cntglobal.h" |
20 #include "cntdebug.h" |
20 #include "cntdebug.h" |
21 #include <cntabstractviewmanager.h> |
21 #include <cntabstractviewmanager.h> |
|
22 #include "cntserviceviewmanager.h" |
22 #include "cntimageutility.h" |
23 #include "cntimageutility.h" |
23 #include "cntserviceviewparams.h" |
24 #include "cntserviceviewparams.h" |
|
25 #include <cntservicescontact.h> |
24 |
26 |
25 #include <hbview.h> |
27 #include <hbview.h> |
26 #include <hblistview.h> |
28 #include <hblistview.h> |
27 #include <qversitreader.h> |
29 #include <qversitreader.h> |
28 #include <qversitcontactimporter.h> |
30 #include <qversitcontactimporter.h> |
71 |
73 |
72 void CntServices::setViewManager( CntAbstractViewManager& aViewManager ) |
74 void CntServices::setViewManager( CntAbstractViewManager& aViewManager ) |
73 { |
75 { |
74 CNT_LOG |
76 CNT_LOG |
75 mViewManager = &aViewManager; |
77 mViewManager = &aViewManager; |
|
78 CntServiceViewManager* srvMng = static_cast<CntServiceViewManager*>(mViewManager); |
|
79 connect(srvMng, SIGNAL(applicationClosed()), this, SLOT(terminateService())); |
76 } |
80 } |
77 |
81 |
78 |
82 |
79 void CntServices::singleFetch( |
83 void CntServices::singleFetch( |
80 const QString &title, const QString &action, |
84 const QString &title, const QString &action, |
110 params.insert(ESelectionMode, HbAbstractItemView::MultiSelection); |
114 params.insert(ESelectionMode, HbAbstractItemView::MultiSelection); |
111 mViewManager->changeView(params); |
115 mViewManager->changeView(params); |
112 CNT_EXIT |
116 CNT_EXIT |
113 } |
117 } |
114 |
118 |
115 |
|
116 void CntServices::editCreateNew(const QString &definitionName, const QString &value, |
119 void CntServices::editCreateNew(const QString &definitionName, const QString &value, |
117 CntAbstractServiceProvider& aServiceProvider) |
120 CntAbstractServiceProvider& aServiceProvider, bool defaultForOnlineAccountIsImpp ) |
|
121 { |
|
122 CNT_ENTRY |
|
123 editCreateNew( definitionName, value, QString(), aServiceProvider, defaultForOnlineAccountIsImpp); |
|
124 CNT_EXIT |
|
125 } |
|
126 |
|
127 void CntServices::editCreateNew(const QString &definitionName, const QString &value, const QString& subType, |
|
128 CntAbstractServiceProvider& aServiceProvider, bool defaultForOnlineAccountIsImpp ) |
118 { |
129 { |
119 CNT_ENTRY |
130 CNT_ENTRY |
120 mCurrentProvider = &aServiceProvider; |
131 mCurrentProvider = &aServiceProvider; |
121 |
132 |
122 QContact contact; |
133 QContact contact; |
123 |
134 |
124 if (definitionName == QContactPhoneNumber::DefinitionName) |
135 if (definitionName == QContactPhoneNumber::DefinitionName) |
125 { |
136 { |
126 QContactPhoneNumber phoneNumber; |
137 QContactPhoneNumber phoneNumber; |
127 phoneNumber.setNumber(value); |
138 phoneNumber.setNumber(value); |
128 phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
139 if (!subType.isEmpty()) |
129 contact.saveDetail(&phoneNumber); |
140 { |
130 } |
141 phoneNumber.setSubTypes(subType); |
|
142 } |
|
143 else |
|
144 { |
|
145 phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile); // Mobile is the default if subtype is not given. |
|
146 } |
|
147 contact.saveDetail(&phoneNumber); |
|
148 } |
131 else if (definitionName == QContactEmailAddress::DefinitionName) |
149 else if (definitionName == QContactEmailAddress::DefinitionName) |
132 { |
150 { |
133 QContactEmailAddress email; |
151 QContactEmailAddress email; |
134 email.setEmailAddress(value); |
152 email.setEmailAddress(value); |
|
153 // Email addresses can't have subtypes. |
135 contact.saveDetail(&email); |
154 contact.saveDetail(&email); |
136 } |
155 } |
137 else if (definitionName == QContactOnlineAccount::DefinitionName) |
156 else if (definitionName == QContactOnlineAccount::DefinitionName) |
138 { |
157 { |
139 QContactOnlineAccount account; |
158 QContactOnlineAccount account; |
140 account.setAccountUri(value); |
159 fillOnlineAccount( account, value, subType, defaultForOnlineAccountIsImpp); |
141 account.setSubTypes(QContactOnlineAccount::SubTypeSipVoip); |
|
142 contact.saveDetail(&account); |
160 contact.saveDetail(&account); |
143 } |
161 } |
144 |
162 |
145 // Launch editor now |
163 // Launch editor now |
146 CntViewParameters params; |
164 CntViewParameters params; |
147 params.insert(EViewId, serviceEditView); |
165 params.insert(EViewId, serviceEditView); |
148 QVariant var; |
166 QVariant var; |
210 params.insert(ESelectedContact, var); |
228 params.insert(ESelectedContact, var); |
211 mViewManager->changeView(params); |
229 mViewManager->changeView(params); |
212 CNT_EXIT |
230 CNT_EXIT |
213 } |
231 } |
214 |
232 |
215 |
|
216 void CntServices::editUpdateExisting(const QString &definitionName, const QString &value, |
233 void CntServices::editUpdateExisting(const QString &definitionName, const QString &value, |
217 CntAbstractServiceProvider& aServiceProvider ) |
234 CntAbstractServiceProvider& aServiceProvider, bool defaultForOnlineAccountIsImpp ) |
|
235 { |
|
236 CNT_ENTRY |
|
237 editUpdateExisting( definitionName, value, QString(), aServiceProvider, defaultForOnlineAccountIsImpp ); |
|
238 CNT_EXIT |
|
239 } |
|
240 |
|
241 void CntServices::editUpdateExisting(const QString &definitionName, const QString &value, const QString& subType, |
|
242 CntAbstractServiceProvider& aServiceProvider, bool defaultForOnlineAccountIsImpp ) |
218 { |
243 { |
219 CNT_ENTRY |
244 CNT_ENTRY |
220 mCurrentProvider = &aServiceProvider; |
245 mCurrentProvider = &aServiceProvider; |
221 |
246 |
222 QContactDetail detail; |
247 QContactDetail detail; |
223 |
248 |
224 if (definitionName == QContactPhoneNumber::DefinitionName) |
249 if (definitionName == QContactPhoneNumber::DefinitionName) |
225 { |
250 { |
226 QContactPhoneNumber phoneNumber; |
251 QContactPhoneNumber phoneNumber; |
227 phoneNumber.setNumber(value); |
252 phoneNumber.setNumber(value); |
228 phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
253 if (!subType.isEmpty()) |
|
254 { |
|
255 phoneNumber.setSubTypes(subType); |
|
256 } |
|
257 else |
|
258 { |
|
259 phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
|
260 } |
229 detail = phoneNumber; |
261 detail = phoneNumber; |
230 } |
262 } |
231 else if (definitionName == QContactEmailAddress::DefinitionName) |
263 else if (definitionName == QContactEmailAddress::DefinitionName) |
232 { |
264 { |
233 QContactEmailAddress email; |
265 QContactEmailAddress email; |
234 email.setEmailAddress(value); |
266 email.setEmailAddress(value); |
|
267 // Email addresses can't have subtypes. |
235 detail = email; |
268 detail = email; |
236 } |
269 } |
237 else if (definitionName == QContactOnlineAccount::DefinitionName) |
270 else if (definitionName == QContactOnlineAccount::DefinitionName) |
238 { |
271 { |
239 QContactOnlineAccount account; |
272 QContactOnlineAccount account; |
240 account.setAccountUri(value); |
273 fillOnlineAccount( account, value, subType, defaultForOnlineAccountIsImpp); |
241 account.setSubTypes(QContactOnlineAccount::SubTypeSipVoip); |
|
242 detail = account; |
274 detail = account; |
243 } |
275 } |
244 |
276 |
245 CntViewParameters params; |
277 CntViewParameters params; |
246 params.insert(EViewId, serviceContactSelectionView); |
278 params.insert(EViewId, serviceContactSelectionView); |
296 CNT_ENTRY |
328 CNT_ENTRY |
297 mCurrentProvider = &aServiceProvider; |
329 mCurrentProvider = &aServiceProvider; |
298 |
330 |
299 QContact contact; |
331 QContact contact; |
300 QContactDetail detail; |
332 QContactDetail detail; |
|
333 |
|
334 QContactName name; |
|
335 name.setFirstName(hbTrId("txt_phob_list_unknown")); |
|
336 contact.saveDetail(&name); |
301 |
337 |
302 if (definitionName == QContactPhoneNumber::DefinitionName) |
338 if (definitionName == QContactPhoneNumber::DefinitionName) |
303 { |
339 { |
304 QContactPhoneNumber phoneNumber; |
340 QContactPhoneNumber phoneNumber; |
305 phoneNumber.setNumber(value); |
341 phoneNumber.setNumber(value); |
335 mViewManager->changeView(params); |
371 mViewManager->changeView(params); |
336 CNT_EXIT |
372 CNT_EXIT |
337 } |
373 } |
338 |
374 |
339 |
375 |
|
376 void CntServices::setQuittable(bool quittable) |
|
377 { |
|
378 mIsQuittable = quittable; |
|
379 } |
|
380 |
|
381 void CntServices::quitApp() |
|
382 { |
|
383 CNT_ENTRY |
|
384 |
|
385 // Only embedded applications should be exited once a client |
|
386 // disconnects. At the moments QtHighWay has unresolved issues |
|
387 // when closing non-embedded applications. Error ou1cimx1#472852 |
|
388 // has more info |
|
389 if ( mIsQuittable ) |
|
390 { |
|
391 qApp->quit(); |
|
392 } |
|
393 CNT_EXIT |
|
394 } |
|
395 |
340 void CntServices::removeNotSupportedDetails(QContact& contact) |
396 void CntServices::removeNotSupportedDetails(QContact& contact) |
341 { |
397 { |
342 CNT_ENTRY |
398 CNT_ENTRY |
343 // Check definition map, remove details not supported |
399 // Check definition map, remove details not supported |
344 for (int i=0; i < contact.details().count(); i++) |
400 for (int i=0; i < contact.details().count(); i++) |
413 } |
467 } |
414 } |
468 } |
415 CNT_EXIT |
469 CNT_EXIT |
416 } |
470 } |
417 |
471 |
|
472 void CntServices::fillOnlineAccount( QContactOnlineAccount& account, const QString& value, |
|
473 const QString& subType, bool defaultForOnlineAccountIsImpp ) |
|
474 { |
|
475 // The value should normally consist of two parts: |
|
476 // <service provider>:<user ID> |
|
477 // for eg. "serviceprovider:jack@serviceprovider.com" |
|
478 QStringList accountDetails = value.split(":"); |
|
479 if (accountDetails.count() == 1) |
|
480 { |
|
481 // For some reason it only had one part, so we're assuming it's the user ID. |
|
482 account.setAccountUri(accountDetails.at(0)); |
|
483 } |
|
484 else if (accountDetails.count() >= 2) |
|
485 { |
|
486 account.setServiceProvider(accountDetails.at(0)); |
|
487 account.setAccountUri(accountDetails.at(1)); // the user ID |
|
488 } |
|
489 |
|
490 if (!subType.isEmpty()) |
|
491 { |
|
492 account.setSubTypes(subType); |
|
493 } |
|
494 else |
|
495 { |
|
496 if (defaultForOnlineAccountIsImpp) |
|
497 { |
|
498 account.setSubTypes( QContactOnlineAccount::SubTypeImpp ); |
|
499 } |
|
500 else |
|
501 { |
|
502 account.setSubTypes( QContactOnlineAccount::SubTypeSipVoip ); |
|
503 } |
|
504 } |
|
505 } |
|
506 |
418 // This method is inherited from CntAbstractServiceProvider |
507 // This method is inherited from CntAbstractServiceProvider |
419 void CntServices::CompleteServiceAndCloseApp(const QVariant& retValue) |
508 void CntServices::CompleteServiceAndCloseApp(const QVariant& retValue) |
420 { |
509 { |
421 CNT_ENTRY |
510 CNT_ENTRY |
422 if ( mCurrentProvider ) |
511 if ( mCurrentProvider ) |
424 mCurrentProvider->CompleteServiceAndCloseApp( retValue ); |
513 mCurrentProvider->CompleteServiceAndCloseApp( retValue ); |
425 } |
514 } |
426 CNT_EXIT |
515 CNT_EXIT |
427 } |
516 } |
428 |
517 |
429 void CntServices::setQuitable(bool quitable) |
518 void CntServices::terminateService() |
430 { |
519 { |
431 mIsQuitable = quitable; |
520 CNT_ENTRY |
432 } |
521 if ( mCurrentProvider ) |
433 |
522 { |
434 void CntServices::quitApp() |
523 // Complete the service with KCntServicesTerminated return value |
435 { |
524 QVariant var(KCntServicesTerminated); |
436 CNT_ENTRY |
525 mCurrentProvider->CompleteServiceAndCloseApp( var ); |
437 |
526 } |
438 // Only embedded applications should be exited once a client |
|
439 // disconnects. At the moments QtHighWay has unresolved issues |
|
440 // when closing non-embedded applications. Error ou1cimx1#472852 |
|
441 // has more info |
|
442 if ( mIsQuitable ) |
|
443 { |
|
444 qApp->quit(); |
|
445 } |
|
446 |
|
447 CNT_EXIT |
527 CNT_EXIT |
448 } |
528 } |
449 |
529 |
450 Q_IMPLEMENT_USER_METATYPE(CntServicesContact) |
530 Q_IMPLEMENT_USER_METATYPE(CntServicesContact) |
451 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList) |
531 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList) |
|
532 |