28 #include <hbtoolbar.h> |
27 #include <hbtoolbar.h> |
29 #include <hbgroupbox.h> |
28 #include <hbgroupbox.h> |
30 #include <hbaction.h> |
29 #include <hbaction.h> |
31 #include <hbmessagebox.h> |
30 #include <hbmessagebox.h> |
32 #include <hbicon.h> |
31 #include <hbicon.h> |
|
32 #include <hbparameterlengthlimiter.h> |
|
33 #include <hbframeitem.h> |
|
34 #include <hbframedrawer.h> |
33 #include <shareui.h> |
35 #include <shareui.h> |
34 #include <thumbnailmanager_qt.h> |
36 #include <thumbnailmanager_qt.h> |
35 #include <cntmaptileservice.h> //For maptile processing |
37 #include <cntmaptileservice.h> //For maptile processing |
36 #include <qversitcontactexporter.h> |
38 #include <qversitcontactexporter.h> |
37 #include <qversitwriter.h> |
39 #include <qversitwriter.h> |
38 #include <xqservicerequest.h> |
40 #include <xqservicerequest.h> |
39 #include "cntcontactcarddatacontainer.h" |
41 #include "cntcontactcarddatacontainer.h" |
40 #include "cntcontactcarddetailitem.h" |
42 #include "cntcontactcarddetailitem.h" |
41 #include "cntcontactcardheadingitem.h" |
43 #include "cntcontactcardheadingitem.h" |
42 #include "cntcontactcarddataitem.h" |
44 #include "cntcontactcarddataitem.h" |
|
45 #include "cntcontactcardcontextmenu.h" |
43 #include "cntmainwindow.h" |
46 #include "cntmainwindow.h" |
44 #include "cntstringmapper.h" |
47 #include "cntstringmapper.h" |
45 #include "cntdocumentloader.h" |
48 #include "cntdocumentloader.h" |
46 #include "cntimagelabel.h" |
49 #include "cntimagelabel.h" |
|
50 #include "cntimageutility.h" |
47 |
51 |
48 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml"; |
52 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml"; |
49 |
53 |
50 /*! |
54 /*! |
51 Constructor, initialize member variables. |
55 Constructor, initialize member variables. |
233 } |
257 } |
234 |
258 |
235 // separator |
259 // separator |
236 else if (index == mDataContainer->separatorIndex()) |
260 else if (index == mDataContainer->separatorIndex()) |
237 { |
261 { |
238 HbGroupBox* details = new HbGroupBox(mView); |
262 HbFrameItem* frameItem = new HbFrameItem(QString("qtg_fr_list_separator"), HbFrameDrawer::NinePieces); |
239 details->setHeading(mDataContainer->dataItem(index)->titleText()); |
263 HbLabel* label = static_cast<HbLabel*>(document()->findWidget(QString("separator"))); |
240 mContainerLayout->addItem(details); |
264 label->setPlainText(mDataContainer->dataItem(index)->titleText()); |
|
265 label->setBackgroundItem(frameItem); |
|
266 mContainerLayout->addItem(label); |
241 } |
267 } |
242 |
268 |
243 // details |
269 // details |
244 else |
270 else |
245 { |
271 { |
246 CntContactCardDataItem* dataItem = mDataContainer->dataItem(index); |
272 CntContactCardDataItem* dataItem = mDataContainer->dataItem(index); |
247 if (!dataItem->icon().isNull()) |
273 if (!dataItem->icon().isNull()) |
248 { |
274 { |
249 HbLabel* iconLabel = new HbLabel(mView); |
275 HbLabel* iconLabel = new HbLabel(mView); |
250 iconLabel->setIcon(dataItem->icon()); |
276 iconLabel->setIcon(dataItem->icon()); |
251 iconLabel->setPreferredSize(dataItem->icon().width(), dataItem->icon().height()); |
277 |
|
278 int width = dataItem->icon().width(); |
|
279 int height = dataItem->icon().height(); |
|
280 |
|
281 //HbLabel setPreferredSize is not working properly, |
|
282 //so added minimum , maximum size to fix the issue |
|
283 iconLabel->setPreferredSize(QSizeF(width,height)); |
|
284 iconLabel->setMinimumSize(QSizeF(width, height)); |
|
285 iconLabel->setMaximumSize(QSizeF(width, height)); |
|
286 iconLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, |
|
287 QSizePolicy::Fixed)); |
252 mContainerLayout->addItem(iconLabel); |
288 mContainerLayout->addItem(iconLabel); |
253 } |
289 } |
254 else |
290 else |
255 { |
291 { |
256 CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget, false); |
292 CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget, false); |
388 relationship.setFirst(favoriteGroup.id()); |
424 relationship.setFirst(favoriteGroup.id()); |
389 relationship.setSecond(mContact->id()); |
425 relationship.setSecond(mContact->id()); |
390 // save relationship |
426 // save relationship |
391 contactManager()->saveRelationship(&relationship); |
427 contactManager()->saveRelationship(&relationship); |
392 |
428 |
393 mView->menu()->removeAction(qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))); |
429 qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(false); |
394 mView->menu()->addAction(qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))); |
430 qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(true); |
395 mHeadingItem->setSecondaryIcon(true); |
431 mHeadingItem->setSecondaryIcon(true); |
396 } |
432 } |
397 |
433 |
398 void CntContactCardViewPrivate::removeFromFavorite() |
434 void CntContactCardViewPrivate::removeFromFavorite() |
399 { |
435 { |
400 QContact favoriteGroup = contactManager()->contact(mFavoriteGroupId); |
436 QContact favoriteGroup = contactManager()->contact(mFavoriteGroupId); |
401 QContactRelationship relationship; |
437 QContactRelationship relationship; |
402 relationship.setRelationshipType(QContactRelationship::HasMember); |
438 relationship.setRelationshipType(QContactRelationship::HasMember); |
403 relationship.setFirst(favoriteGroup.id()); |
439 relationship.setFirst(favoriteGroup.id()); |
404 relationship.setSecond(mContact->id()); |
440 relationship.setSecond(mContact->id()); |
405 contactManager()->removeRelationship(relationship); |
441 contactManager()->removeRelationship(relationship); |
406 |
442 |
407 mView->menu()->removeAction(qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))); |
443 qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(false); |
408 mView->menu()->addAction(qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))); |
444 qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(true); |
409 mHeadingItem->setSecondaryIcon(false); |
445 mHeadingItem->setSecondaryIcon(false); |
410 } |
446 } |
411 |
447 |
412 /*! |
448 /*! |
413 Delete contact |
449 Delete contact |
414 */ |
450 */ |
415 void CntContactCardViewPrivate::deleteContact() |
451 void CntContactCardViewPrivate::deleteContact() |
416 { |
452 { |
417 QString name = contactManager()->synthesizedDisplayLabel(*mContact); |
453 QString name = contactManager()->synthesizedDisplayLabel(*mContact); |
418 |
454 |
419 HbMessageBox *note = new HbMessageBox(hbTrId("txt_phob_info_delete_1").arg(name), HbMessageBox::MessageTypeQuestion); |
455 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_delete_1")).arg(name), this, SLOT(handleDeleteContact(HbAction*)), |
420 note->setPrimaryAction(new HbAction(hbTrId("txt_phob_button_delete"), note)); |
456 hbTrId("txt_phob_button_delete"), hbTrId("txt_common_button_cancel")); |
421 note->setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"), note)); |
457 } |
422 HbAction *selected = note->exec(); |
458 |
423 if (selected == note->primaryAction()) |
459 /*! |
|
460 Handle action for deleting a contact |
|
461 */ |
|
462 void CntContactCardViewPrivate::handleDeleteContact(HbAction *action) |
|
463 { |
|
464 HbMessageBox *note = static_cast<HbMessageBox*>(sender()); |
|
465 |
|
466 if (note && action == note->actions().first()) |
424 { |
467 { |
425 contactManager()->removeContact(mContact->localId()); |
468 contactManager()->removeContact(mContact->localId()); |
426 CntViewParameters viewParameters; |
469 CntViewParameters viewParameters; |
427 viewParameters.insert(EViewId, namesView); |
470 viewParameters.insert(EViewId, namesView); |
428 QVariant var; |
|
429 var.setValue(*mContact); |
|
430 viewParameters.insert(ESelectedContact, var); |
|
431 viewParameters.insert(ESelectedAction, "delete"); |
|
432 mViewManager->changeView(viewParameters); |
471 mViewManager->changeView(viewParameters); |
433 } |
472 } |
434 delete note; |
|
435 } |
473 } |
436 |
474 |
437 /*! |
475 /*! |
438 Launch history view |
476 Launch history view |
439 */ |
477 */ |
458 /*! |
496 /*! |
459 Send the business card / my card |
497 Send the business card / my card |
460 */ |
498 */ |
461 void CntContactCardViewPrivate::sendBusinessCard() |
499 void CntContactCardViewPrivate::sendBusinessCard() |
462 { |
500 { |
|
501 // Check if the contact has an image. |
|
502 QList<QContactAvatar> avatars = mContact->details<QContactAvatar>(); |
|
503 bool imageExists( false ); |
|
504 foreach(QContactAvatar a, mContact->details<QContactAvatar>()) |
|
505 { |
|
506 if (!a.imageUrl().isEmpty()) |
|
507 { |
|
508 imageExists = true; |
|
509 HbMessageBox *note = new HbMessageBox( |
|
510 hbTrId("txt_phob_info_add_contact_card_image_to_business_c"), |
|
511 HbMessageBox::MessageTypeQuestion); |
|
512 note->setIcon(*mVCardIcon); |
|
513 |
|
514 HbAction* ok = new HbAction(hbTrId("txt_common_button_ok"), note); |
|
515 HbAction* cancel = new HbAction(hbTrId("txt_common_button_cancel"), note); |
|
516 |
|
517 ok->setObjectName( "ok" ); |
|
518 cancel->setObjectName( "cancel" ); |
|
519 |
|
520 note->addAction( ok ); |
|
521 note->addAction( cancel ); |
|
522 |
|
523 note->setModal( true ); |
|
524 note->setAttribute(Qt::WA_DeleteOnClose, true ); |
|
525 note->open( this, SLOT(handleSendBusinessCard(HbAction*))); |
|
526 break; |
|
527 } |
|
528 } |
|
529 |
|
530 if ( !imageExists ) |
|
531 { |
|
532 handleSendBusinessCard( NULL ); // no image |
|
533 } |
|
534 } |
|
535 |
|
536 /*! |
|
537 Set orientation of the view |
|
538 */ |
|
539 void CntContactCardViewPrivate::setOrientation(Qt::Orientation orientation) |
|
540 { |
|
541 if (orientation == Qt::Vertical) |
|
542 { |
|
543 // reading "portrait" section |
|
544 document()->load(CNT_CONTACTCARDVIEW_XML, "portrait"); |
|
545 } |
|
546 else |
|
547 { |
|
548 // reading "landscape" section |
|
549 document()->load(CNT_CONTACTCARDVIEW_XML, "landscape"); |
|
550 } |
|
551 } |
|
552 |
|
553 /*! |
|
554 Called after user clicked on the listview. |
|
555 */ |
|
556 void CntContactCardViewPrivate::onItemActivated() |
|
557 { |
|
558 CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender()); |
|
559 int index = item->index(); |
|
560 launchAction(*mContact, mDataContainer->dataItem(index)->detail(), mDataContainer->dataItem(index)->action()); |
|
561 } |
|
562 |
|
563 /*! |
|
564 Launch the call / message / email action |
|
565 */ |
|
566 void CntContactCardViewPrivate::launchAction(QContact contact, QContactDetail detail, QString action) |
|
567 { |
|
568 // detail might be empty -> in that case engine uses the preferred detail for the selected action |
|
569 QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(action, "symbian"); |
|
570 if (actionDescriptors.isEmpty()) |
|
571 { |
|
572 return; |
|
573 } |
|
574 mContactAction = QContactAction::action(actionDescriptors.first()); |
|
575 connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)), |
|
576 this, SLOT(progress(QContactAction::State))); |
|
577 mContactAction->invokeAction(contact, detail); |
|
578 } |
|
579 |
|
580 void CntContactCardViewPrivate::progress(QContactAction::State status) |
|
581 { |
|
582 switch(status) |
|
583 { |
|
584 case QContactAction::FinishedState: |
|
585 case QContactAction::FinishedWithErrorState: |
|
586 mContactAction->deleteLater(); |
|
587 mContactAction = 0; |
|
588 break; |
|
589 default: |
|
590 break; |
|
591 } |
|
592 } |
|
593 |
|
594 /*! |
|
595 Set selected detail as preferred for selected action |
|
596 */ |
|
597 void CntContactCardViewPrivate::setPreferredAction(const QString &aAction, const QContactDetail &aDetail) |
|
598 { |
|
599 mContact->setPreferredDetail(aAction, aDetail); |
|
600 contactManager()->saveContact(mContact); |
|
601 } |
|
602 |
|
603 /*! |
|
604 Item specific menu |
|
605 */ |
|
606 void CntContactCardViewPrivate::onLongPressed(const QPointF &aCoords) |
|
607 { |
|
608 CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender()); |
|
609 int index = item->index(); |
|
610 |
|
611 CntContactCardContextMenu *menu = new CntContactCardContextMenu( item ); |
|
612 HbAction *communicationAction = 0; |
|
613 HbAction *videoCommunicationAction = 0; |
|
614 HbAction *preferredAction = 0; |
|
615 CntStringMapper stringMapper; |
|
616 |
|
617 QString action = mDataContainer->dataItem(index)->action(); |
|
618 QContactDetail detail = mDataContainer->dataItem(index)->detail(); |
|
619 |
|
620 if (action.compare("call", Qt::CaseInsensitive) == 0) |
|
621 { |
|
622 QContactDetail detail = mDataContainer->dataItem(index)->detail(); |
|
623 if (detail.definitionName() == QContactPhoneNumber::DefinitionName) |
|
624 { |
|
625 QContactPhoneNumber number = static_cast<QContactPhoneNumber>(detail); |
|
626 QString context = number.contexts().isEmpty() ? QString() : number.contexts().first(); |
|
627 QString subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first(); |
|
628 |
|
629 communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(subtype, context)); |
|
630 |
|
631 // TODO : uncomment next line when videotelephony is released |
|
632 //videoCommunicationAction = menu->addAction(QString("VideoCall")); |
|
633 } |
|
634 } |
|
635 else if (action.compare("message", Qt::CaseInsensitive) == 0) |
|
636 { |
|
637 communicationAction = menu->addAction(hbTrId("txt_phob_menu_send_message")); |
|
638 } |
|
639 else if (action.compare("email", Qt::CaseInsensitive) == 0) |
|
640 { |
|
641 if (!detail.contexts().isEmpty()) |
|
642 { |
|
643 communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), detail.contexts().first())); |
|
644 } |
|
645 else |
|
646 { |
|
647 communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), QString())); |
|
648 } |
|
649 } |
|
650 |
|
651 if (action.compare("call", Qt::CaseInsensitive) == 0) |
|
652 { |
|
653 preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_number")); |
|
654 } |
|
655 else if (action.compare("message", Qt::CaseInsensitive) == 0) |
|
656 { |
|
657 preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_number")); |
|
658 } |
|
659 else if (action.compare("email", Qt::CaseInsensitive) == 0) |
|
660 { |
|
661 preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_email")); |
|
662 } |
|
663 |
|
664 if (mContact->isPreferredDetail(action, detail)) |
|
665 { |
|
666 preferredAction->setEnabled(false); |
|
667 } |
|
668 |
|
669 if ( communicationAction ) |
|
670 { |
|
671 communicationAction->setObjectName( "communicationAction" ); |
|
672 } |
|
673 |
|
674 if ( preferredAction ) |
|
675 { |
|
676 preferredAction->setObjectName( "preferredAction" ); |
|
677 menu->insertSeparator(preferredAction); |
|
678 } |
|
679 |
|
680 menu->setPreferredPos( aCoords ); |
|
681 menu->setAttribute( Qt::WA_DeleteOnClose, true ); |
|
682 menu->open( this, SLOT(handleMenuAction(HbAction*)) ); |
|
683 } |
|
684 |
|
685 void CntContactCardViewPrivate::handleMenuAction(HbAction* aAction) |
|
686 { |
|
687 CntContactCardContextMenu* menu = static_cast<CntContactCardContextMenu*>(sender()); |
|
688 CntContactCardDetailItem *item = menu->item(); |
|
689 int index = item->index(); |
|
690 |
|
691 QString action = mDataContainer->dataItem(index)->action(); |
|
692 QContactDetail detail = mDataContainer->dataItem(index)->detail(); |
|
693 |
|
694 QString name = aAction->objectName(); |
|
695 |
|
696 if ( name == "communicationAction" ) |
|
697 { |
|
698 launchAction( *mContact, detail, action ); |
|
699 } |
|
700 |
|
701 if ( name == "preferredAction" ) |
|
702 { |
|
703 setPreferredAction(action, detail); |
|
704 |
|
705 if (mPreferredItems.contains(action)) |
|
706 { |
|
707 CntContactCardDetailItem *oldItem = mPreferredItems.value(action); |
|
708 mDataContainer->dataItem(oldItem->index())->setSecondaryIcon(HbIcon()); |
|
709 oldItem->setDetails(mDataContainer->dataItem(oldItem->index())); |
|
710 } |
|
711 |
|
712 mDataContainer->dataItem(item->index())->setSecondaryIcon(HbIcon("qtg_mono_favourites")); |
|
713 item->setDetails(mDataContainer->dataItem(item->index())); |
|
714 |
|
715 mPreferredItems.insert(action, item); |
|
716 } |
|
717 } |
|
718 |
|
719 void CntContactCardViewPrivate::handleSendBusinessCard( HbAction* aAction ) |
|
720 { |
|
721 QList<QContact> list; |
|
722 if ( aAction && aAction->objectName() == "cancel" ) |
|
723 { |
|
724 QContact tmpContact( *mContact ); |
|
725 foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() ) |
|
726 { |
|
727 tmpContact.removeDetail( &a ); |
|
728 } |
|
729 list.append( tmpContact ); |
|
730 } |
|
731 else |
|
732 { |
|
733 list.append( *mContact ); |
|
734 } |
|
735 |
463 QString tempDir = QDir::tempPath().append("/tempcntvcard"); |
736 QString tempDir = QDir::tempPath().append("/tempcntvcard"); |
464 |
|
465 QDir dir(tempDir); |
737 QDir dir(tempDir); |
466 |
738 |
467 // Temporary directory to store the vCard file |
739 // Temporary directory to store the vCard file |
468 if (!dir.exists()) |
740 if (!dir.exists()) |
469 { |
741 { |
470 // Create a temp directory |
742 // Create a temp directory |
471 QDir::temp().mkdir("tempcntvcard"); |
743 QDir::temp().mkdir("tempcntvcard"); |
477 foreach(QString s, l) |
749 foreach(QString s, l) |
478 { |
750 { |
479 if (dir.exists(s)) |
751 if (dir.exists(s)) |
480 { |
752 { |
481 dir.remove(s); |
753 dir.remove(s); |
482 } |
754 } |
483 } |
755 } |
484 } |
756 } |
485 |
757 |
486 QString vCardName = QString(mContact->displayLabel().append(".vcf")); |
758 QString vCardName = QString(mContact->displayLabel().append(".vcf")); |
487 QString vCardPath = dir.absolutePath().append(QDir::separator()); |
759 QString vCardPath = dir.absolutePath().append(QDir::separator()); |
488 vCardPath.append(vCardName); |
760 vCardPath.append(vCardName); |
489 vCardPath = QDir::toNativeSeparators(vCardPath); |
761 vCardPath = QDir::toNativeSeparators(vCardPath); |
490 |
762 |
491 QString service("com.nokia.services.hbserviceprovider.conversationview"); |
763 QVersitContactExporter exporter; |
492 QString type("send(QVariant)"); |
764 // The vCard version needs to be 2.1 due to backward compatiblity when sending |
493 |
765 if (!exporter.exportContacts(list, QVersitDocument::VCard21Type)) |
494 // Create the vCard and send it to messaging service |
766 { |
495 if (createVCard(vCardPath)) |
767 |
496 { |
768 QList<QVersitDocument> docs = exporter.documents(); |
497 ShareUi s; |
769 QFile f(vCardPath); |
498 QStringList l; |
770 if ( f.open(QIODevice::WriteOnly) ) |
499 l << vCardPath; |
771 { |
500 s.send(l,false); |
772 // Start creating the vCard |
501 } |
773 QVersitWriter writer; |
502 } |
774 writer.setDevice(&f); |
503 |
775 |
504 /*! |
776 bool ret = writer.startWriting(docs); |
505 Set orientation of the view |
777 ret = writer.waitForFinished(); |
506 */ |
778 |
507 void CntContactCardViewPrivate::setOrientation(Qt::Orientation orientation) |
779 // Create the vCard and send it to messaging service |
508 { |
780 ShareUi s; |
509 if (orientation == Qt::Vertical) |
781 QStringList l; |
510 { |
782 l << vCardPath; |
511 // reading "portrait" section |
783 s.send(l,false); |
512 document()->load(CNT_CONTACTCARDVIEW_XML, "portrait"); |
784 } |
513 } |
785 } |
514 else |
|
515 { |
|
516 // reading "landscape" section |
|
517 document()->load(CNT_CONTACTCARDVIEW_XML, "landscape"); |
|
518 } |
|
519 } |
|
520 |
|
521 /*! |
|
522 Called after user clicked on the listview. |
|
523 */ |
|
524 void CntContactCardViewPrivate::onItemActivated() |
|
525 { |
|
526 CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender()); |
|
527 int index = item->index(); |
|
528 launchAction(*mContact, mDataContainer->dataItem(index)->detail(), mDataContainer->dataItem(index)->action()); |
|
529 } |
|
530 |
|
531 /*! |
|
532 Launch the call / message / email action |
|
533 */ |
|
534 void CntContactCardViewPrivate::launchAction(QContact contact, QContactDetail detail, QString action) |
|
535 { |
|
536 // detail might be empty -> in that case engine uses the preferred detail for the selected action |
|
537 QList<QContactActionDescriptor> callActionDescriptors = QContactAction::actionDescriptors(action, "symbian"); |
|
538 mContactAction = QContactAction::action(callActionDescriptors.at(0)); |
|
539 connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)), |
|
540 this, SLOT(progress(QContactAction::State))); |
|
541 mContactAction->invokeAction(contact, detail); |
|
542 } |
|
543 |
|
544 void CntContactCardViewPrivate::progress(QContactAction::State status) |
|
545 { |
|
546 switch(status) |
|
547 { |
|
548 case QContactAction::FinishedState: |
|
549 case QContactAction::FinishedWithErrorState: |
|
550 mContactAction->deleteLater(); |
|
551 mContactAction = 0; |
|
552 break; |
|
553 default: |
|
554 break; |
|
555 } |
|
556 } |
|
557 |
|
558 /*! |
|
559 Set selected detail as preferred for selected action |
|
560 */ |
|
561 void CntContactCardViewPrivate::setPreferredAction(const QString &aAction, const QContactDetail &aDetail) |
|
562 { |
|
563 mContact->setPreferredDetail(aAction, aDetail); |
|
564 contactManager()->saveContact(mContact); |
|
565 emit preferredUpdated(); |
|
566 } |
|
567 |
|
568 /*! |
|
569 Item specific menu |
|
570 */ |
|
571 void CntContactCardViewPrivate::onLongPressed(const QPointF &aCoords) |
|
572 { |
|
573 CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender()); |
|
574 int index = item->index(); |
|
575 |
|
576 HbMenu *menu = new HbMenu(); |
|
577 HbAction *communicationAction = 0; |
|
578 HbAction *preferredAction = 0; |
|
579 CntStringMapper stringMapper; |
|
580 |
|
581 QString action = mDataContainer->dataItem(index)->action(); |
|
582 QContactDetail detail = mDataContainer->dataItem(index)->detail(); |
|
583 |
|
584 if (action.compare("call", Qt::CaseInsensitive) == 0) |
|
585 { |
|
586 QContactDetail detail = mDataContainer->dataItem(index)->detail(); |
|
587 if (!detail.contexts().isEmpty()) |
|
588 { |
|
589 communicationAction = menu->addAction(stringMapper.getContactCardMenuLocString(detail.definitionName(), detail.contexts().first())); |
|
590 } |
|
591 else |
|
592 { |
|
593 communicationAction = menu->addAction(stringMapper.getContactCardMenuLocString(detail.definitionName(), QString())); |
|
594 } |
|
595 } |
|
596 else if (action.compare("message", Qt::CaseInsensitive) == 0) |
|
597 { |
|
598 communicationAction = menu->addAction(hbTrId("txt_phob_menu_send_message")); |
|
599 } |
|
600 else if (action.compare("email", Qt::CaseInsensitive) == 0) |
|
601 { |
|
602 if (!detail.contexts().isEmpty()) |
|
603 { |
|
604 communicationAction = menu->addAction(stringMapper.getContactCardMenuLocString(detail.definitionName(), detail.contexts().first())); |
|
605 } |
|
606 else |
|
607 { |
|
608 communicationAction = menu->addAction(stringMapper.getContactCardMenuLocString(detail.definitionName(), QString())); |
|
609 } |
|
610 } |
|
611 |
|
612 if (action.compare("call", Qt::CaseInsensitive) == 0) |
|
613 { |
|
614 preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_number")); |
|
615 } |
|
616 else if (action.compare("email", Qt::CaseInsensitive) == 0) |
|
617 { |
|
618 preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_email")); |
|
619 } |
|
620 |
|
621 if (mContact->isPreferredDetail(action, detail)) |
|
622 { |
|
623 preferredAction->setEnabled(false); |
|
624 } |
|
625 |
|
626 if (preferredAction) |
|
627 { |
|
628 menu->insertSeparator(preferredAction); |
|
629 } |
|
630 |
|
631 HbAction *selectedAction = menu->exec(aCoords); |
|
632 |
|
633 if (selectedAction) |
|
634 { |
|
635 if (selectedAction == communicationAction) |
|
636 { |
|
637 launchAction(*mContact, detail, action); |
|
638 } |
|
639 else if (selectedAction == preferredAction) |
|
640 { |
|
641 setPreferredAction(action, detail); |
|
642 //item->setUnderLine(true); |
|
643 |
|
644 if (mPreferredItems.contains(action)) |
|
645 { |
|
646 //mPreferredItems.value(action)->setUnderLine(false); |
|
647 } |
|
648 mPreferredItems.insert(action, item); |
|
649 } |
|
650 } |
|
651 menu->deleteLater(); |
|
652 } |
786 } |
653 |
787 |
654 /*! |
788 /*! |
655 Event filter for green key |
789 Event filter for green key |
656 */ |
790 */ |
805 } |
938 } |
806 return favoriteGroupContact; |
939 return favoriteGroupContact; |
807 } |
940 } |
808 |
941 |
809 /*! |
942 /*! |
810 Creates the v-card |
|
811 */ |
|
812 bool CntContactCardViewPrivate::createVCard(QString& vCardPath) |
|
813 { |
|
814 QList<QContact> list; |
|
815 QContact tempContact(*mContact); |
|
816 bool createVCard( false ); |
|
817 |
|
818 // Check if the contact has an image. |
|
819 QList<QContactAvatar> avatars = tempContact.details<QContactAvatar>(); |
|
820 |
|
821 foreach(QContactAvatar a, avatars) |
|
822 { |
|
823 if (!a.imageUrl().isEmpty()) |
|
824 { |
|
825 // If true and query the user if they want to add it to |
|
826 // the business card |
|
827 |
|
828 // TODO: Missing translation |
|
829 HbMessageBox *note = new HbMessageBox(hbTrId("txt_phob_info_add_contact_card_image_to_business_c"), |
|
830 HbMessageBox::MessageTypeQuestion); |
|
831 note->setIcon(*mVCardIcon); |
|
832 |
|
833 note->setPrimaryAction(new HbAction(hbTrId("txt_common_button_ok"), note)); |
|
834 note->setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"), note)); |
|
835 HbAction *selected = note->exec(); |
|
836 if (selected == note->secondaryAction()) |
|
837 { |
|
838 // Remove the avatar detail from the temp contact |
|
839 createVCard = tempContact.removeDetail(&a); |
|
840 } |
|
841 else if (selected == note->primaryAction()) |
|
842 { |
|
843 createVCard = true; |
|
844 } |
|
845 delete note; |
|
846 break; |
|
847 } |
|
848 else |
|
849 { |
|
850 // Contact does not have an image |
|
851 createVCard = true; |
|
852 } |
|
853 } |
|
854 |
|
855 // False = User clicked outside the popup, dismissing it |
|
856 // = User prompted the removal of the avatar but it failed |
|
857 if (!createVCard) |
|
858 { |
|
859 return false; |
|
860 } |
|
861 |
|
862 list.append(tempContact); |
|
863 QVersitContactExporter exporter; |
|
864 // The vCard version needs to be 2.1 due to backward compatiblity when sending |
|
865 if (!exporter.exportContacts(list, QVersitDocument::VCard21Type)) |
|
866 return false; |
|
867 |
|
868 QList<QVersitDocument> docs = exporter.documents(); |
|
869 |
|
870 QFile f(vCardPath); |
|
871 if (!f.open(QIODevice::WriteOnly)) |
|
872 { |
|
873 return false; |
|
874 } |
|
875 |
|
876 // Start creating the vCard |
|
877 QVersitWriter writer; |
|
878 writer.setDevice(&f); |
|
879 |
|
880 bool ret = writer.startWriting(docs); |
|
881 ret = writer.waitForFinished(); |
|
882 |
|
883 return ret; |
|
884 } |
|
885 |
|
886 /*! |
|
887 Return the pointer to the document loader |
943 Return the pointer to the document loader |
888 */ |
944 */ |
889 CntDocumentLoader* CntContactCardViewPrivate::document() |
945 CntDocumentLoader* CntContactCardViewPrivate::document() |
890 { |
946 { |
891 if (!mLoader) |
947 if (!mLoader) |