16 */ |
16 */ |
17 |
17 |
18 #include "cntcontactcarddatacontainer.h" |
18 #include "cntcontactcarddatacontainer.h" |
19 #include "cntcontactcarddataitem.h" |
19 #include "cntcontactcarddataitem.h" |
20 #include "cntdetailorderinghelper.h" |
20 #include "cntdetailorderinghelper.h" |
21 #include <cntmaptileservice.h> //For fetching maptile |
21 #include <maptileservice.h> //For fetching maptile |
22 #include "cntuiactionextension.h" |
22 #include <cntuiactionextension.h> |
|
23 #include <cntuiextensionfactory.h> |
|
24 #include <cntuicontactcardextension.h> |
23 |
25 |
24 #include <QPainter> |
26 #include <QPainter> |
25 #include <QList> |
27 #include <QList> |
26 #include <qtcontacts.h> |
28 #include <qtcontacts.h> |
27 #include <hbicon.h> |
29 #include <hbicon.h> |
28 #include <cntviewparams.h> |
30 #include <hbnumbergrouping.h> |
29 #include <QLocale> |
31 #include <QLocale> |
30 #include <QDir> |
32 #include <QDir> |
31 |
33 |
|
34 #include <cntviewparams.h> |
32 #include "cntstringmapper.h" |
35 #include "cntstringmapper.h" |
33 #include <hbnumbergrouping.h> |
36 #include "cntextensionmanager.h" |
34 |
37 |
35 /*! |
38 /*! |
36 Compare function for CntContactCardDataItem |
39 Compare function for CntContactCardDataItem |
37 */ |
40 */ |
38 namespace |
41 namespace |
44 } |
47 } |
45 |
48 |
46 /*! |
49 /*! |
47 Constructor |
50 Constructor |
48 */ |
51 */ |
49 CntContactCardDataContainer::CntContactCardDataContainer( |
52 CntContactCardDataContainer::CntContactCardDataContainer( |
50 QContact* contact, QObject *parent, bool myCard, CntMapTileService* maptile, Qt::Orientations orientation ) : |
53 MapTileService* maptile, |
51 mContact(contact), |
54 CntExtensionManager& aExtensionManager, |
52 mSeparatorIndex(-1), |
55 Qt::Orientations orientation, |
53 mLocationFeatureEnabled(false), |
56 QObject *parent) : |
54 mMaptileInterface(maptile), |
57 mContact(NULL), |
55 mOrientation( orientation ) |
58 mSeparatorIndex(-1), |
56 { |
59 mLocationFeatureEnabled(false), |
57 Q_UNUSED(parent); |
60 mMaptileInterface(maptile), |
|
61 mOrientation( orientation ), |
|
62 mExtensionManager( &aExtensionManager ) |
|
63 { |
|
64 Q_UNUSED(parent); |
|
65 } |
|
66 |
|
67 void CntContactCardDataContainer::setContactData(QContact* contact, bool aMyCard) |
|
68 { |
|
69 clearContactData(); |
|
70 mContact = contact; |
|
71 mSeparatorIndex = -1; |
58 if (contact->type() == QContactType::TypeGroup) |
72 if (contact->type() == QContactType::TypeGroup) |
59 { |
73 { |
60 initializeGroupData(); |
74 initializeGroupData(); |
61 } |
75 } |
62 else |
76 else |
63 { |
77 { |
64 initializeActionsData(myCard); |
78 initializeActionsData(aMyCard); |
|
79 initialiseExtensionActions(aMyCard); |
65 initializeDetailsData(); |
80 initializeDetailsData(); |
66 sortDataItems(); |
81 sortDataItems(); |
67 } |
82 } |
68 } |
83 } |
69 |
84 |
70 /*! |
85 /*! |
71 Destructor |
86 Destructor |
72 */ |
87 */ |
73 CntContactCardDataContainer::~CntContactCardDataContainer() |
88 CntContactCardDataContainer::~CntContactCardDataContainer() |
74 { |
89 { |
75 while (!mDataItemList.isEmpty()) |
90 clearContactData(); |
76 { |
91 } |
77 delete mDataItemList.takeFirst(); |
92 |
78 } |
93 void CntContactCardDataContainer::clearContactData() |
|
94 { |
|
95 qDeleteAll(mDataItemList); |
|
96 mDataItemList.clear(); |
79 } |
97 } |
80 |
98 |
81 /*! |
99 /*! |
82 Initialize contact details which include actions. |
100 Initialize contact details which include actions. |
83 */ |
101 */ |
306 delete contactAction; |
324 delete contactAction; |
307 } |
325 } |
308 } |
326 } |
309 } |
327 } |
310 |
328 |
|
329 void CntContactCardDataContainer::initialiseExtensionActions(bool /*aMyCard*/) |
|
330 { |
|
331 // There can be several plugins that supply buttons. |
|
332 for( int n = 0; n < mExtensionManager->pluginCount(); ++n ) |
|
333 { |
|
334 CntUiExtensionFactory& factory = *mExtensionManager->pluginAt( n ); |
|
335 CntUiContactCardExtension* ext = factory.contactCardExtension(); |
|
336 if ( ext ) |
|
337 { |
|
338 ext->prepare( *mContact, false ); // aMyCard = false |
|
339 const int actionCount = ext->actionCount(); |
|
340 for( int x = 0; x < actionCount; ++x ) |
|
341 { |
|
342 const CntUiContactCardExtAction& action = ext->actionAt( x ); |
|
343 |
|
344 const QContactDetail& detail = action.detailUsedForChoosingPosition(); |
|
345 QString context = detail.contexts().isEmpty() ? QString() : detail.contexts().first(); |
|
346 int position = getPosition( |
|
347 detail.definitionName(), |
|
348 context, |
|
349 true); // dynamicAction = true |
|
350 |
|
351 CntContactCardDataItem* dataItem = new CntContactCardDataItem( |
|
352 action.firstTextLine(), |
|
353 position, |
|
354 true); // aIsFocusable = true |
|
355 dataItem->setContactCardExtensionAndActionIndex( *ext, x ); |
|
356 dataItem->setValueText(action.secondTextLine()); |
|
357 dataItem->setIcon( action.icon()); |
|
358 dataItem->setContactDetail( action.detailUsedForChoosingPosition() ); |
|
359 //TODO: dataItem->setLongPressText(); |
|
360 mDataItemList.append(dataItem); |
|
361 } |
|
362 } |
|
363 } |
|
364 } |
|
365 |
311 /*! |
366 /*! |
312 Initialize group details which includes actions. |
367 Initialize group details which includes actions. |
313 */ |
368 */ |
314 void CntContactCardDataContainer::initializeGroupData() |
369 void CntContactCardDataContainer::initializeGroupData() |
315 { |
370 { |
385 } |
440 } |
386 |
441 |
387 //address |
442 //address |
388 QString contextHome(QContactAddress::ContextHome.operator QString()); |
443 QString contextHome(QContactAddress::ContextHome.operator QString()); |
389 QString contextWork(QContactAddress::ContextWork.operator QString()); |
444 QString contextWork(QContactAddress::ContextWork.operator QString()); |
390 CntMapTileService::ContactAddressType sourceAddressType; |
445 MapTileService::AddressType sourceAddressType; |
391 if( mMaptileInterface ) |
446 if( mMaptileInterface ) |
392 { |
447 { |
393 mLocationFeatureEnabled = mMaptileInterface->isLocationFeatureEnabled() ; |
448 mLocationFeatureEnabled = mMaptileInterface->isLocationFeatureEnabled(MapTileService::AppTypeContacts) ; |
394 } |
449 } |
395 |
450 |
396 QList<QContactAddress> addressDetails = mContact->details<QContactAddress>(); |
451 QList<QContactAddress> addressDetails = mContact->details<QContactAddress>(); |
397 for (int i = 0; i < addressDetails.count(); i++) |
452 for (int i = 0; i < addressDetails.count(); i++) |
398 { |
453 { |
399 sourceAddressType = CntMapTileService::AddressPreference; |
454 sourceAddressType = MapTileService::AddressPreference; |
400 QVariantList addressList; |
455 QVariantList addressList; |
401 //no action |
456 //no action |
402 int position = CntContactCardDataItem::EOther; |
457 int position = CntContactCardDataItem::EOther; |
403 QString title; |
458 QString title; |
404 if (addressDetails[i].contexts().isEmpty()) |
459 if (addressDetails[i].contexts().isEmpty()) |
408 } |
463 } |
409 else |
464 else |
410 { |
465 { |
411 if ( addressDetails[i].contexts().at(0) == contextHome ) |
466 if ( addressDetails[i].contexts().at(0) == contextHome ) |
412 { |
467 { |
413 sourceAddressType = CntMapTileService::AddressHome; |
468 sourceAddressType = MapTileService::AddressHome; |
414 title = hbTrId("txt_phob_formlabel_address_home"); |
469 title = hbTrId("txt_phob_formlabel_address_home"); |
415 position = CntContactCardDataItem::EAddressHome; |
470 position = CntContactCardDataItem::EAddressHome; |
416 } |
471 } |
417 else if (addressDetails[i].contexts().at(0) == contextWork) |
472 else if (addressDetails[i].contexts().at(0) == contextWork) |
418 { |
473 { |
419 sourceAddressType = CntMapTileService::AddressWork; |
474 sourceAddressType = MapTileService::AddressWork; |
420 title = hbTrId("txt_phob_formlabel_address_work"); |
475 title = hbTrId("txt_phob_formlabel_address_work"); |
421 position = CntContactCardDataItem::EAddressWork; |
476 position = CntContactCardDataItem::EAddressWork; |
422 } |
477 } |
423 } |
478 } |
424 CntContactCardDataItem* dataItem = new CntContactCardDataItem(title, position, false); |
479 CntContactCardDataItem* dataItem = new CntContactCardDataItem(title, position, false); |
444 |
499 |
445 //Get the maptile image path |
500 //Get the maptile image path |
446 int status = mMaptileInterface->getMapTileImage( |
501 int status = mMaptileInterface->getMapTileImage( |
447 contactId, sourceAddressType, imageFile, mOrientation ); |
502 contactId, sourceAddressType, imageFile, mOrientation ); |
448 |
503 |
449 if( status == CntMapTileService::MapTileFetchingInProgress || status == |
504 if( status == MapTileService::MapTileFetchingInProgress || status == |
450 CntMapTileService::MapTileFetchingNetworkError ) |
505 MapTileService::MapTileFetchingNetworkError ) |
451 { |
506 { |
452 //Load the progress indicator icon |
507 //Load the progress indicator icon |
453 QString iconName("qtg_anim_small_loading_1"); |
508 QString iconName("qtg_anim_small_loading_1"); |
454 HbIcon inProgressIcon(iconName); |
509 HbIcon inProgressIcon(iconName); |
455 dataItem->setSecondaryIcon( inProgressIcon ); |
510 dataItem->setSecondaryIcon( inProgressIcon ); |
456 } |
511 } |
457 else if( status == CntMapTileService::MapTileFetchingUnknownError || |
512 else if( status == MapTileService::MapTileFetchingUnknownError || |
458 status == CntMapTileService::MapTileFetchingInvalidAddress ) |
513 status == MapTileService::MapTileFetchingInvalidAddress ) |
459 { |
514 { |
460 //Load the search stop icon |
515 //Load the search stop icon |
461 QString iconName("qtg_mono_search_stop"); |
516 QString iconName("qtg_mono_search_stop"); |
462 HbIcon stopIcon(iconName); |
517 HbIcon stopIcon(iconName); |
463 dataItem->setSecondaryIcon( stopIcon ); |
518 dataItem->setSecondaryIcon( stopIcon ); |
464 } |
519 } |
465 else if( status == CntMapTileService::MapTileFetchingCompleted ) |
520 else if( status == MapTileService::MapTileFetchingCompleted ) |
466 { |
521 { |
467 maptileAvailable = true; |
522 maptileAvailable = true; |
468 } |
523 } |
469 } |
524 } |
470 dataItem->setValueText(address.join(" ")); |
525 dataItem->setValueText(address.join(", ")); |
471 dataItem->setContactDetail(addressDetails[i]); |
526 dataItem->setContactDetail(addressDetails[i]); |
472 addSeparator(itemCount()); |
527 addSeparator(itemCount()); |
473 mDataItemList.append(dataItem); |
528 mDataItemList.append(dataItem); |
474 |
529 |
475 //Check whether location feature enabled |
530 //Check whether location feature enabled |
499 companyList.append(organizationDetails[i].name()); |
554 companyList.append(organizationDetails[i].name()); |
500 if (!organizationDetails[i].department().isEmpty()) |
555 if (!organizationDetails[i].department().isEmpty()) |
501 companyList.append(organizationDetails[i].department()); |
556 companyList.append(organizationDetails[i].department()); |
502 if (companyList.count()>0) |
557 if (companyList.count()>0) |
503 { |
558 { |
504 dataItem->setValueText(companyList.join(" ").trimmed()); |
559 dataItem->setValueText(companyList.join(", ").trimmed()); |
505 dataItem->setContactDetail(organizationDetails[i]); |
560 dataItem->setContactDetail(organizationDetails[i]); |
506 addSeparator(itemCount()); |
561 addSeparator(itemCount()); |
507 mDataItemList.append(dataItem); |
562 mDataItemList.append(dataItem); |
508 } |
563 } |
509 } |
564 } |
576 QList<QContactFamily> familyDetails = mContact->details<QContactFamily>(); |
631 QList<QContactFamily> familyDetails = mContact->details<QContactFamily>(); |
577 for (int i = 0; i < familyDetails.count(); i++) |
632 for (int i = 0; i < familyDetails.count(); i++) |
578 { |
633 { |
579 if (!familyDetails[i].spouse().isEmpty()) |
634 if (!familyDetails[i].spouse().isEmpty()) |
580 { |
635 { |
581 CntContactCardDataItem* dataSpouseItem = new CntContactCardDataItem(hbTrId("txt_phob_formlabel_spouse"), CntContactCardDataItem::EChildren, false); |
636 CntContactCardDataItem* dataSpouseItem = new CntContactCardDataItem(hbTrId("txt_phob_formlabel_spouse"), |
|
637 CntContactCardDataItem::ESpouse, false); |
582 dataSpouseItem->setValueText(familyDetails[i].spouse()); |
638 dataSpouseItem->setValueText(familyDetails[i].spouse()); |
583 dataSpouseItem->setContactDetail(familyDetails[i]); |
639 dataSpouseItem->setContactDetail(familyDetails[i]); |
584 addSeparator(itemCount()); |
640 addSeparator(itemCount()); |
585 mDataItemList.append(dataSpouseItem); |
641 mDataItemList.append(dataSpouseItem); |
586 } |
642 } |
587 |
643 |
588 if (!familyDetails[i].children().isEmpty()) |
644 if (!familyDetails[i].children().isEmpty()) |
589 { |
645 { |
590 CntContactCardDataItem* dataChildrenItem = new CntContactCardDataItem(hbTrId("txt_phob_formlabel_children"), CntContactCardDataItem::ESpouse, false); |
646 CntContactCardDataItem* dataChildrenItem = new CntContactCardDataItem(hbTrId("txt_phob_formlabel_children"), |
|
647 CntContactCardDataItem::EChildren, false); |
591 dataChildrenItem->setValueText(familyDetails[i].children().join(", ")); |
648 dataChildrenItem->setValueText(familyDetails[i].children().join(", ")); |
592 dataChildrenItem->setContactDetail(familyDetails[i]); |
649 dataChildrenItem->setContactDetail(familyDetails[i]); |
593 addSeparator(itemCount()); |
650 addSeparator(itemCount()); |
594 mDataItemList.append(dataChildrenItem); |
651 mDataItemList.append(dataChildrenItem); |
595 } |
652 } |