91 connect( mImageLabel, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
98 connect( mImageLabel, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
92 connect( mHeading, SIGNAL(textClicked()), this, SLOT(openNameEditor()) ); |
99 connect( mHeading, SIGNAL(textClicked()), this, SLOT(openNameEditor()) ); |
93 connect( mHeading, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
100 connect( mHeading, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
94 connect( mListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(activated(const QModelIndex&)) ); |
101 connect( mListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(activated(const QModelIndex&)) ); |
95 connect( mListView, SIGNAL(longPressed(HbAbstractViewItem*,const QPointF&)), this, SLOT(longPressed(HbAbstractViewItem*,const QPointF&)) ); |
102 connect( mListView, SIGNAL(longPressed(HbAbstractViewItem*,const QPointF&)), this, SLOT(longPressed(HbAbstractViewItem*,const QPointF&)) ); |
|
103 |
|
104 // closing the application from task swapper or end key will cause the contact to be saved |
|
105 connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(saveChanges())); |
96 } |
106 } |
97 |
107 |
98 CntEditViewPrivate::~CntEditViewPrivate() |
108 CntEditViewPrivate::~CntEditViewPrivate() |
99 { |
109 { |
100 mView->deleteLater(); |
110 mView->deleteLater(); |
|
111 |
101 delete mDocument; |
112 delete mDocument; |
|
113 mDocument = NULL; |
102 delete mModel; |
114 delete mModel; |
|
115 mModel = NULL; |
103 delete mContact; |
116 delete mContact; |
|
117 mContact = NULL; |
104 if (mMenu) |
118 if (mMenu) |
105 { |
119 { |
106 delete mMenu; |
120 delete mMenu; |
|
121 mMenu = NULL; |
107 } |
122 } |
108 delete mThumbnailManager; |
123 delete mThumbnailManager; |
|
124 mThumbnailManager = NULL; |
|
125 delete mSaveManager; |
|
126 mSaveManager = NULL; |
109 } |
127 } |
110 |
128 |
111 void CntEditViewPrivate::setOrientation(Qt::Orientation orientation) |
129 void CntEditViewPrivate::setOrientation(Qt::Orientation orientation) |
112 { |
130 { |
113 if (orientation == Qt::Vertical) |
131 if (orientation == Qt::Vertical) |
421 void CntEditViewPrivate::deleteContact() |
454 void CntEditViewPrivate::deleteContact() |
422 { |
455 { |
423 if ( mIsMyCard ) |
456 if ( mIsMyCard ) |
424 { |
457 { |
425 HbMessageBox::question(hbTrId("txt_phob_dialog_remove_all_personal_data_from_my_c"), this, |
458 HbMessageBox::question(hbTrId("txt_phob_dialog_remove_all_personal_data_from_my_c"), this, |
426 SLOT(handleDeleteContact(HbAction*)), |
459 SLOT(handleDeleteContact(int)), |
427 hbTrId("txt_common_button_yes"), |
460 HbMessageBox::Yes | HbMessageBox::No); |
428 hbTrId("txt_common_button_no")); |
|
429 } |
461 } |
430 else |
462 else |
431 { |
463 { |
432 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
464 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
433 QString name = cm->synthesizedDisplayLabel( *mContact ); |
465 QString name = cm->synthesizedContactDisplayLabel( *mContact ); |
434 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_delete_1")).arg(name), this, SLOT(handleDeleteContact(HbAction*)), |
466 if (name.isEmpty()) |
435 hbTrId("txt_common_button_delete"), hbTrId("txt_common_button_cancel")); |
467 { |
436 } |
468 name = hbTrId("txt_phob_list_unnamed"); |
437 } |
469 } |
438 |
470 |
439 void CntEditViewPrivate::handleDeleteContact(HbAction *action) |
471 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_delete_1")).arg(name), this, SLOT(handleDeleteContact(int)), |
|
472 HbMessageBox::Delete | HbMessageBox::Cancel); |
|
473 } |
|
474 } |
|
475 |
|
476 void CntEditViewPrivate::handleDeleteContact(int action) |
440 { |
477 { |
441 Q_Q(CntEditView); |
478 Q_Q(CntEditView); |
442 |
479 |
443 HbMessageBox *dlg = static_cast<HbMessageBox*>(sender()); |
480 if(action == HbMessageBox::Yes || action == HbMessageBox::Delete) |
444 if(dlg && action == dlg->actions().first()) |
|
445 { |
481 { |
446 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
482 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
447 |
483 |
|
484 disconnect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
|
485 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
448 emit q->contactRemoved(cm->removeContact( mContact->localId() )); |
486 emit q->contactRemoved(cm->removeContact( mContact->localId() )); |
449 |
487 |
450 mMgr->back( mArgs ); |
488 mMgr->back( mArgs, true ); |
451 } |
489 } |
452 } |
490 } |
453 |
491 |
454 void CntEditViewPrivate::discardChanges() |
492 void CntEditViewPrivate::discardChanges() |
455 { |
493 { |
457 |
495 |
458 emit q->changesDiscarded(); |
496 emit q->changesDiscarded(); |
459 |
497 |
460 // get a fresh one from backend. |
498 // get a fresh one from backend. |
461 QContactManager* mgr = mMgr->contactManager(SYMBIAN_BACKEND); |
499 QContactManager* mgr = mMgr->contactManager(SYMBIAN_BACKEND); |
462 mContact = new QContact(mgr->contact( mContact->localId() )); |
500 setSelectedContact( mgr->contact( mContact->localId()) ); |
463 |
501 |
464 QVariant var; |
502 QVariant var; |
465 var.setValue(*mContact); |
503 var.setValue(*mContact); |
466 |
504 |
467 CntViewParameters viewParameters; |
505 CntViewParameters viewParameters; |
468 viewParameters.insert(ESelectedContact, var); |
506 viewParameters.insert(ESelectedContact, var); |
469 |
507 |
470 mMgr->back( viewParameters ); |
508 if ( mArgs.value( EExtraAction ).toString() == CNT_ROOT_ACTION ) |
471 } |
509 { |
|
510 mMgr->back( viewParameters, true ); |
|
511 } |
|
512 else |
|
513 { |
|
514 mMgr->back( viewParameters ); |
|
515 } |
|
516 |
|
517 } |
472 |
518 |
473 void CntEditViewPrivate::saveChanges() |
519 void CntEditViewPrivate::saveChanges() |
474 { |
520 { |
475 Q_Q(CntEditView); |
521 Q_Q(CntEditView); |
476 |
522 |
477 QContactManager* mgr = mMgr->contactManager( SYMBIAN_BACKEND ); |
523 QString name = mMgr->contactManager(SYMBIAN_BACKEND)->synthesizedContactDisplayLabel(*mContact); |
478 bool isSavedContact = mContact->localId() > 0; |
524 |
479 |
525 if (name.isEmpty()) |
480 // if the contact is really changed or a new one |
526 { |
481 if ( (*mContact) != mgr->contact(mContact->localId()) || !isSavedContact ) |
527 name = hbTrId("txt_phob_list_unnamed"); |
482 { |
528 } |
483 int detailCount = mContact->details().count(); |
529 |
484 |
530 CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, mMgr->contactManager(SYMBIAN_BACKEND)); |
485 setPreferredDetails( mContact ); |
531 |
486 |
532 QVariant var; |
487 // If its a new contact |
533 bool backToRoot(false); |
488 if ( !isSavedContact ) |
534 |
489 { |
535 switch (result) |
490 if ( detailCount > 2 ) |
536 { |
491 { |
537 case CntSaveManager::ESaved: |
492 bool success = mgr->saveContact( mContact ); |
538 emit q->contactUpdated(KCntServicesReturnValueContactSaved); |
493 if ( success && mIsMyCard ) |
539 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name)); |
494 { |
540 var.setValue(*mContact); |
495 mgr->setSelfContactId( mContact->localId() ); |
541 mArgs.insert(ESelectedContact, var); |
496 } |
542 mArgs.insert(ESelectedAction, CNT_CREATE_ACTION); |
497 |
543 break; |
498 QString name = mgr->synthesizedDisplayLabel( *mContact ); |
544 case CntSaveManager::EUpdated: |
499 if (name.isEmpty()) |
545 emit q->contactUpdated(KCntServicesReturnValueContactSaved); |
500 { |
546 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contacts_1_updated")).arg(name)); |
501 name = hbTrId("txt_phob_dblist_unnamed"); |
547 var.setValue(*mContact); |
502 } |
548 mArgs.insert(ESelectedContact, var); |
503 |
549 mArgs.insert(ESelectedAction, CNT_EDIT_ACTION); |
504 if ( success ) |
550 break; |
505 { |
551 case CntSaveManager::EFailed: |
506 emit q->contactUpdated(1); |
552 emit q->contactUpdated(KCntServicesReturnValueContactNotModified); |
507 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name)); |
553 HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!")); |
508 } |
554 break; |
509 else |
555 case CntSaveManager::EDeleted: |
510 { |
556 emit q->contactRemoved(true); |
511 emit q->contactUpdated(0); |
557 backToRoot = true; |
512 //TODO: localization is missing |
558 break; |
513 HbDeviceNotificationDialog::notification(QString(),qtTrId("SAVING FAILED!")); |
559 case CntSaveManager::ENothingDone: |
514 } |
560 default: |
515 |
561 emit q->contactUpdated(KCntServicesReturnValueContactNotModified); |
516 QVariant var; |
562 break; |
517 var.setValue(*mContact); |
563 } |
518 mArgs.insert(ESelectedContact, var); |
564 |
519 mArgs.insert(ESelectedAction, CNT_CREATE_ACTION); |
565 if ( mArgs.value( EExtraAction ).toString() == CNT_ROOT_ACTION ) |
520 } |
566 { |
521 else |
567 backToRoot = true; |
522 { |
568 } |
523 // nothing happened to the contact. Flags should be used |
569 |
524 emit q->contactUpdated(-2); |
570 mMgr->back( mArgs, backToRoot ); |
525 } |
571 } |
526 } |
|
527 else |
|
528 { |
|
529 // contact details has been cleared out. |
|
530 if ( detailCount <= 4 ) |
|
531 { |
|
532 // get the contact from database, it should have the name still in it, |
|
533 // and show the delete notification to user |
|
534 QContact c = mgr->contact( mContact->localId() ); |
|
535 |
|
536 bool success = mgr->removeContact( mContact->localId() ); |
|
537 emit q->contactRemoved(success); |
|
538 } |
|
539 else |
|
540 { |
|
541 bool success = mgr->saveContact(mContact); |
|
542 |
|
543 QString name = mgr->synthesizedDisplayLabel( *mContact ); |
|
544 if (name.isEmpty()) |
|
545 { |
|
546 name = hbTrId("txt_phob_dblist_unnamed"); |
|
547 } |
|
548 |
|
549 if ( success ) |
|
550 { |
|
551 emit q->contactUpdated(1); |
|
552 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contacts_1_updated")).arg(name)); |
|
553 mArgs.insert(ESelectedAction, CNT_EDIT_ACTION); |
|
554 } |
|
555 else |
|
556 { |
|
557 emit q->contactUpdated(0); |
|
558 //TODO: localization is missing |
|
559 HbDeviceNotificationDialog::notification(QString(),qtTrId("SAVING FAILED!")); |
|
560 } |
|
561 |
|
562 QVariant var; |
|
563 var.setValue(*mContact); |
|
564 mArgs.insert(ESelectedContact, var); |
|
565 } |
|
566 } |
|
567 } |
|
568 else |
|
569 { |
|
570 emit q->changesDiscarded(); |
|
571 } |
|
572 |
|
573 mMgr->back( mArgs ); |
|
574 } |
|
575 |
|
576 void CntEditViewPrivate::setPreferredDetails( QContact* aContact ) |
|
577 { |
|
578 QList<QContactPhoneNumber> numberList( aContact->details<QContactPhoneNumber>() ); |
|
579 //set preferred number for call if there is only one phone number |
|
580 if ( aContact->preferredDetail("call").isEmpty() && numberList.count() == 1 ) |
|
581 { |
|
582 aContact->setPreferredDetail( "call", numberList.first() ); |
|
583 } |
|
584 //set preferred number for message if there is only one mobile phone number |
|
585 if ( aContact->preferredDetail("message").isEmpty() && numberList.count() >= 1 ) |
|
586 { |
|
587 int mobileNumbers = 0; |
|
588 int mobileNumberIndex = -1; |
|
589 for (int i = 0; i < numberList.count(); i++) |
|
590 { |
|
591 if (numberList.at(i).subTypes().count() && numberList.at(i).subTypes().first() == QContactPhoneNumber::SubTypeMobile) |
|
592 { |
|
593 mobileNumbers++; |
|
594 mobileNumberIndex = i; |
|
595 } |
|
596 } |
|
597 if ( mobileNumbers == 1 ) |
|
598 { |
|
599 aContact->setPreferredDetail( "message", numberList.at(mobileNumberIndex) ); |
|
600 } |
|
601 } |
|
602 QList<QContactEmailAddress> emailList( aContact->details<QContactEmailAddress>() ); |
|
603 //set preferred number for email if there is only one email address |
|
604 if ( aContact->preferredDetail("email").isEmpty() && emailList.count() == 1 ) |
|
605 { |
|
606 aContact->setPreferredDetail( "email", emailList.first() ); |
|
607 } |
|
608 } |
|
609 |
|
610 |
572 |
611 void CntEditViewPrivate::openNameEditor() |
573 void CntEditViewPrivate::openNameEditor() |
612 { |
574 { |
613 QVariant var; |
575 QVariant var; |
614 var.setValue(*mContact); |
576 var.setValue(*mContact); |