37 #include <hbframebackground.h> |
38 #include <hbframebackground.h> |
38 #include <hbparameterlengthlimiter.h> |
39 #include <hbparameterlengthlimiter.h> |
39 #include <hbdevicenotificationdialog.h> |
40 #include <hbdevicenotificationdialog.h> |
40 #include <xqaiwrequest.h> |
41 #include <xqaiwrequest.h> |
41 #include <xqaiwdecl.h> |
42 #include <xqaiwdecl.h> |
42 #include <QDir> |
43 #include <cntservicescontact.h> |
|
44 |
|
45 #include <QFileInfo> |
|
46 #include <QApplication> |
43 |
47 |
44 const char *CNT_EDIT_XML = ":/xml/contacts_ev.docml"; |
48 const char *CNT_EDIT_XML = ":/xml/contacts_ev.docml"; |
45 |
49 |
46 CntEditViewPrivate::CntEditViewPrivate() : |
50 CntEditViewPrivate::CntEditViewPrivate() : |
47 mModel( NULL ), |
51 mModel( NULL ), |
48 mImageLabel( NULL ), |
52 mImageLabel( NULL ), |
49 mThumbnailManager( NULL ), |
53 mThumbnailManager( NULL ), |
50 mContact( NULL ), |
54 mContact( NULL ), |
51 mReq(0), |
55 mReq(0), |
52 mMenu(NULL) |
56 mMenu(NULL), |
|
57 mSaveManager(NULL) |
53 { |
58 { |
54 mDocument = new CntDocumentLoader; |
59 mDocument = new CntDocumentLoader; |
55 |
60 |
56 bool ok; |
61 bool ok; |
57 mDocument->load( CNT_EDIT_XML, &ok ); |
62 mDocument->load( CNT_EDIT_XML, &ok ); |
91 connect( mImageLabel, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
96 connect( mImageLabel, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
92 connect( mHeading, SIGNAL(textClicked()), this, SLOT(openNameEditor()) ); |
97 connect( mHeading, SIGNAL(textClicked()), this, SLOT(openNameEditor()) ); |
93 connect( mHeading, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
98 connect( mHeading, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
94 connect( mListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(activated(const QModelIndex&)) ); |
99 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&)) ); |
100 connect( mListView, SIGNAL(longPressed(HbAbstractViewItem*,const QPointF&)), this, SLOT(longPressed(HbAbstractViewItem*,const QPointF&)) ); |
|
101 |
|
102 // closing the application from task swapper or end key will cause the contact to be saved |
|
103 connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(saveChanges())); |
96 } |
104 } |
97 |
105 |
98 CntEditViewPrivate::~CntEditViewPrivate() |
106 CntEditViewPrivate::~CntEditViewPrivate() |
99 { |
107 { |
100 mView->deleteLater(); |
108 mView->deleteLater(); |
|
109 |
101 delete mDocument; |
110 delete mDocument; |
|
111 mDocument = NULL; |
102 delete mModel; |
112 delete mModel; |
|
113 mModel = NULL; |
103 delete mContact; |
114 delete mContact; |
|
115 mContact = NULL; |
104 if (mMenu) |
116 if (mMenu) |
105 { |
117 { |
106 delete mMenu; |
118 delete mMenu; |
|
119 mMenu = NULL; |
107 } |
120 } |
108 delete mThumbnailManager; |
121 delete mThumbnailManager; |
|
122 mThumbnailManager = NULL; |
|
123 delete mSaveManager; |
|
124 mSaveManager = NULL; |
109 } |
125 } |
110 |
126 |
111 void CntEditViewPrivate::setOrientation(Qt::Orientation orientation) |
127 void CntEditViewPrivate::setOrientation(Qt::Orientation orientation) |
112 { |
128 { |
113 if (orientation == Qt::Vertical) |
129 if (orientation == Qt::Vertical) |
421 void CntEditViewPrivate::deleteContact() |
446 void CntEditViewPrivate::deleteContact() |
422 { |
447 { |
423 if ( mIsMyCard ) |
448 if ( mIsMyCard ) |
424 { |
449 { |
425 HbMessageBox::question(hbTrId("txt_phob_dialog_remove_all_personal_data_from_my_c"), this, |
450 HbMessageBox::question(hbTrId("txt_phob_dialog_remove_all_personal_data_from_my_c"), this, |
426 SLOT(handleDeleteContact(HbAction*)), |
451 SLOT(handleDeleteContact(int)), |
427 hbTrId("txt_common_button_yes"), |
452 HbMessageBox::Yes | HbMessageBox::No); |
428 hbTrId("txt_common_button_no")); |
|
429 } |
453 } |
430 else |
454 else |
431 { |
455 { |
432 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
456 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
433 QString name = cm->synthesizedDisplayLabel( *mContact ); |
457 QString name = cm->synthesizedDisplayLabel( *mContact ); |
434 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_delete_1")).arg(name), this, SLOT(handleDeleteContact(HbAction*)), |
458 if (name.isEmpty()) |
435 hbTrId("txt_common_button_delete"), hbTrId("txt_common_button_cancel")); |
459 { |
436 } |
460 name = hbTrId("txt_phob_list_unnamed"); |
437 } |
461 } |
438 |
462 |
439 void CntEditViewPrivate::handleDeleteContact(HbAction *action) |
463 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_delete_1")).arg(name), this, SLOT(handleDeleteContact(int)), |
|
464 HbMessageBox::Delete | HbMessageBox::Cancel); |
|
465 } |
|
466 } |
|
467 |
|
468 void CntEditViewPrivate::handleDeleteContact(int action) |
440 { |
469 { |
441 Q_Q(CntEditView); |
470 Q_Q(CntEditView); |
442 |
471 |
443 HbMessageBox *dlg = static_cast<HbMessageBox*>(sender()); |
472 if(action == HbMessageBox::Yes || action == HbMessageBox::Delete) |
444 if(dlg && action == dlg->actions().first()) |
|
445 { |
473 { |
446 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
474 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
447 |
475 |
448 emit q->contactRemoved(cm->removeContact( mContact->localId() )); |
476 emit q->contactRemoved(cm->removeContact( mContact->localId() )); |
449 |
477 |
471 } |
499 } |
472 |
500 |
473 void CntEditViewPrivate::saveChanges() |
501 void CntEditViewPrivate::saveChanges() |
474 { |
502 { |
475 Q_Q(CntEditView); |
503 Q_Q(CntEditView); |
476 |
504 |
477 QContactManager* mgr = mMgr->contactManager( SYMBIAN_BACKEND ); |
505 QString name = mMgr->contactManager(SYMBIAN_BACKEND)->synthesizedDisplayLabel(*mContact); |
478 bool isSavedContact = mContact->localId() > 0; |
506 |
479 |
507 if (name.isEmpty()) |
480 // if the contact is really changed or a new one |
508 { |
481 if ( (*mContact) != mgr->contact(mContact->localId()) || !isSavedContact ) |
509 name = hbTrId("txt_phob_list_unnamed"); |
482 { |
510 } |
483 int detailCount = mContact->details().count(); |
511 |
484 |
512 CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, mMgr->contactManager(SYMBIAN_BACKEND)); |
485 setPreferredDetails( mContact ); |
513 |
486 |
514 QVariant var; |
487 // If its a new contact |
515 |
488 if ( !isSavedContact ) |
516 switch (result) |
489 { |
517 { |
490 if ( detailCount > 2 ) |
518 case CntSaveManager::ESaved: |
491 { |
519 emit q->contactUpdated(KCntServicesReturnValueContactSaved); |
492 bool success = mgr->saveContact( mContact ); |
520 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name)); |
493 if ( success && mIsMyCard ) |
521 var.setValue(*mContact); |
494 { |
522 mArgs.insert(ESelectedContact, var); |
495 mgr->setSelfContactId( mContact->localId() ); |
523 mArgs.insert(ESelectedAction, CNT_CREATE_ACTION); |
496 } |
524 break; |
497 |
525 case CntSaveManager::EUpdated: |
498 QString name = mgr->synthesizedDisplayLabel( *mContact ); |
526 emit q->contactUpdated(KCntServicesReturnValueContactSaved); |
499 if (name.isEmpty()) |
527 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contacts_1_updated")).arg(name)); |
500 { |
528 var.setValue(*mContact); |
501 name = hbTrId("txt_phob_dblist_unnamed"); |
529 mArgs.insert(ESelectedContact, var); |
502 } |
530 mArgs.insert(ESelectedAction, CNT_EDIT_ACTION); |
503 |
531 break; |
504 if ( success ) |
532 case CntSaveManager::EFailed: |
505 { |
533 emit q->contactUpdated(KCntServicesReturnValueContactNotModified); |
506 emit q->contactUpdated(1); |
534 HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!")); |
507 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name)); |
535 break; |
508 } |
536 case CntSaveManager::EDeleted: |
509 else |
537 emit q->contactUpdated(KCntServicesReturnValueContactDeleted); |
510 { |
538 break; |
511 emit q->contactUpdated(0); |
539 case CntSaveManager::ENothingDone: |
512 //TODO: localization is missing |
540 default: |
513 HbDeviceNotificationDialog::notification(QString(),qtTrId("SAVING FAILED!")); |
541 emit q->contactUpdated(KCntServicesReturnValueContactNotModified); |
514 } |
542 break; |
515 |
|
516 QVariant var; |
|
517 var.setValue(*mContact); |
|
518 mArgs.insert(ESelectedContact, var); |
|
519 mArgs.insert(ESelectedAction, CNT_CREATE_ACTION); |
|
520 } |
|
521 else |
|
522 { |
|
523 // nothing happened to the contact. Flags should be used |
|
524 emit q->contactUpdated(-2); |
|
525 } |
|
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 } |
543 } |
572 |
544 |
573 mMgr->back( mArgs ); |
545 mMgr->back( mArgs ); |
574 } |
546 } |
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 |
547 |
611 void CntEditViewPrivate::openNameEditor() |
548 void CntEditViewPrivate::openNameEditor() |
612 { |
549 { |
613 QVariant var; |
550 QVariant var; |
614 var.setValue(*mContact); |
551 var.setValue(*mContact); |