18 #include "cnteditview_p.h" |
18 #include "cnteditview_p.h" |
19 #include "cnteditviewlistmodel.h" |
19 #include "cnteditviewlistmodel.h" |
20 #include "cntdocumentloader.h" |
20 #include "cntdocumentloader.h" |
21 #include "cntdetailpopup.h" |
21 #include "cntdetailpopup.h" |
22 #include "cnteditviewheadingitem.h" |
22 #include "cnteditviewheadingitem.h" |
|
23 #include "cntthumbnailmanager.h" |
23 #include "cntimagelabel.h" |
24 #include "cntimagelabel.h" |
24 #include "cntsavemanager.h" |
25 #include "cntsavemanager.h" |
|
26 #include <cntabstractengine.h> |
25 #include "cntglobal.h" |
27 #include "cntglobal.h" |
26 #include "cntdebug.h" |
28 #include "cntdebug.h" |
27 |
29 |
28 #include <qtcontacts.h> |
30 #include <qtcontacts.h> |
29 #include <hbdocumentloader.h> |
31 #include <hbdocumentloader.h> |
30 #include <thumbnailmanager_qt.h> |
|
31 #include <hbabstractviewitem.h> |
32 #include <hbabstractviewitem.h> |
|
33 #include <hblistviewitem.h> |
32 #include <hbmessagebox.h> |
34 #include <hbmessagebox.h> |
33 #include <hbgroupbox.h> |
35 #include <hbgroupbox.h> |
34 #include <hbmainwindow.h> |
36 #include <hbmainwindow.h> |
35 #include <hbview.h> |
37 #include <hbview.h> |
36 #include <hblistview.h> |
38 #include <hblistview.h> |
64 mDocument->load( CNT_EDIT_XML, &ok ); |
66 mDocument->load( CNT_EDIT_XML, &ok ); |
65 if ( !ok ){ |
67 if ( !ok ){ |
66 qFatal( "Unable to load %S", CNT_EDIT_XML ); |
68 qFatal( "Unable to load %S", CNT_EDIT_XML ); |
67 } |
69 } |
68 mView = static_cast<HbView*>( mDocument->findWidget("view") ); |
70 mView = static_cast<HbView*>( mDocument->findWidget("view") ); |
|
71 |
69 mListView = static_cast<HbListView*>( mDocument->findWidget("listView") ); |
72 mListView = static_cast<HbListView*>( mDocument->findWidget("listView") ); |
70 mListView->setLayoutName("editviewlist"); |
73 mListView->setLayoutName("editviewlist"); |
|
74 mListView->setItemPixmapCacheEnabled(true); |
|
75 |
71 HbFrameBackground frame; |
76 HbFrameBackground frame; |
72 frame.setFrameGraphicsName("qtg_fr_list_normal"); |
77 frame.setFrameGraphicsName("qtg_fr_list_normal"); |
73 frame.setFrameType(HbFrameDrawer::NinePieces); |
78 frame.setFrameType(HbFrameDrawer::NinePieces); |
74 mListView->itemPrototypes().first()->setDefaultFrame(frame); |
79 mListView->listItemPrototype()->setDefaultFrame( frame ); |
75 |
80 |
76 mHeading = static_cast<CntEditViewHeadingItem*>( mDocument->findWidget("editViewHeading") ); |
81 mHeading = static_cast<CntEditViewHeadingItem*>( mDocument->findWidget("editViewHeading") ); |
77 mImageLabel = static_cast<CntImageLabel*>(mDocument->findWidget("editViewImage")); |
82 mImageLabel = static_cast<CntImageLabel*>(mDocument->findWidget("editViewImage")); |
78 |
83 |
79 mSoftkey = new HbAction(Hb::BackNaviAction, mView); |
84 mSoftkey = new HbAction(Hb::BackNaviAction, mView); |
162 QString myCard = mArgs.value( EMyCard ).toString(); |
166 QString myCard = mArgs.value( EMyCard ).toString(); |
163 QString selectedAction = mArgs.value( ESelectedAction ).toString(); |
167 QString selectedAction = mArgs.value( ESelectedAction ).toString(); |
164 QVariant contact = aArgs.value( ESelectedContact ); |
168 QVariant contact = aArgs.value( ESelectedContact ); |
165 |
169 |
166 setSelectedContact( contact.value<QContact>() ); |
170 setSelectedContact( contact.value<QContact>() ); |
167 mModel = new CntEditViewListModel( *mContact ); |
171 mModel = new CntEditViewListModel( *mContact, mEngine->extensionManager() ); |
168 mListView->setModel( mModel ); |
172 mListView->setModel( mModel ); |
169 |
173 |
170 QContactLocalId localId = mContact->localId(); |
174 QContactLocalId localId = mContact->localId(); |
171 QContactManager* cm = mMgr->contactManager(SYMBIAN_BACKEND); |
175 QContactManager& cm = mEngine->contactManager(SYMBIAN_BACKEND); |
172 QContactLocalId selfContactId = cm->selfContactId(); |
176 QContactLocalId selfContactId = cm.selfContactId(); |
173 mIsMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty(); |
177 mIsMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty(); |
174 |
178 |
175 if (mIsMyCard) |
179 if (mIsMyCard) |
176 { |
180 { |
177 mSaveManager = new CntSaveManager(CntSaveManager::EMyCard); |
181 mSaveManager = new CntSaveManager(CntSaveManager::EMyCard); |
207 { |
211 { |
208 mDelete->setEnabled( false ); |
212 mDelete->setEnabled( false ); |
209 } |
213 } |
210 |
214 |
211 // save and discard disabled if no changes found |
215 // save and discard disabled if no changes found |
212 if ( *mContact == cm->contact( mContact->localId()) ) |
216 if ( *mContact == cm.contact( mContact->localId()) ) |
213 { |
217 { |
214 mDiscard->setEnabled( false ); |
218 mDiscard->setEnabled( false ); |
215 mSave->setEnabled( false ); |
219 mSave->setEnabled( false ); |
216 } |
220 } |
217 |
221 |
218 mThumbnailManager = new ThumbnailManager(this); |
222 mThumbnailManager = &mEngine->thumbnailManager(); |
219 mThumbnailManager->setMode(ThumbnailManager::Default); |
|
220 mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality); |
|
221 mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge); |
|
222 |
|
223 connect( mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), |
223 connect( mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), |
224 this, SLOT(thumbnailReady(QPixmap, void*, int, int)) ); |
224 this, SLOT(thumbnailReady(QPixmap, void*, int, int)) ); |
225 |
225 |
226 loadAvatar(); |
226 loadAvatar(); |
227 |
227 |
299 } |
299 } |
300 |
300 |
301 void CntEditViewPrivate::handleMenuAction( HbAction* aAction ) |
301 void CntEditViewPrivate::handleMenuAction( HbAction* aAction ) |
302 { |
302 { |
303 HbMenu *menu = static_cast<HbMenu*>(sender()); |
303 HbMenu *menu = static_cast<HbMenu*>(sender()); |
304 int row = aAction->data().toInt(); |
|
305 mIndex = mModel->index(row, 0); |
|
306 CntEditViewItem* item = mModel->itemAt( mIndex ); |
|
307 if ( aAction ) |
304 if ( aAction ) |
308 { |
305 { |
|
306 int row = aAction->data().toInt(); |
|
307 mIndex = mModel->index(row, 0); |
|
308 CntEditViewItem* item = mModel->itemAt( mIndex ); |
|
309 |
309 switch ( aAction->property("menu").toInt() ) |
310 switch ( aAction->property("menu").toInt() ) |
310 { |
311 { |
311 case HbAction::EditRole: |
312 case HbAction::EditRole: |
312 { |
313 { |
313 if( item->data(ERoleEditorViewId) == ringToneFetcherView ) |
314 if( item->data(ERoleEditorViewId) == ringToneFetcherView ) |
451 } |
452 } |
452 |
453 |
453 |
454 |
454 void CntEditViewPrivate::deleteContact() |
455 void CntEditViewPrivate::deleteContact() |
455 { |
456 { |
|
457 CNT_ENTRY |
|
458 |
456 if ( mIsMyCard ) |
459 if ( mIsMyCard ) |
457 { |
460 { |
458 HbMessageBox::question(hbTrId("txt_phob_dialog_remove_all_personal_data_from_my_c"), this, |
461 HbMessageBox::question(hbTrId("txt_phob_dialog_remove_all_personal_data_from_my_c"), this, |
459 SLOT(handleDeleteContact(int)), |
462 SLOT(handleDeleteContact(int)), |
460 HbMessageBox::Yes | HbMessageBox::No); |
463 HbMessageBox::Yes | HbMessageBox::No); |
461 } |
464 } |
462 else |
465 else |
463 { |
466 { |
464 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
467 QContactManager& cm = mEngine->contactManager( SYMBIAN_BACKEND ); |
465 QString name = cm->synthesizedContactDisplayLabel( *mContact ); |
468 QString name = cm.synthesizedContactDisplayLabel( *mContact ); |
466 if (name.isEmpty()) |
469 if (name.isEmpty()) |
467 { |
470 { |
468 name = hbTrId("txt_phob_list_unnamed"); |
471 name = hbTrId("txt_phob_list_unnamed"); |
469 } |
472 } |
470 |
473 |
471 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_delete_1")).arg(name), this, SLOT(handleDeleteContact(int)), |
474 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_delete_1")).arg(name), this, SLOT(handleDeleteContact(int)), |
472 HbMessageBox::Delete | HbMessageBox::Cancel); |
475 HbMessageBox::Delete | HbMessageBox::Cancel); |
473 } |
476 } |
|
477 |
|
478 CNT_EXIT |
474 } |
479 } |
475 |
480 |
476 void CntEditViewPrivate::handleDeleteContact(int action) |
481 void CntEditViewPrivate::handleDeleteContact(int action) |
477 { |
482 { |
|
483 CNT_ENTRY |
|
484 |
478 Q_Q(CntEditView); |
485 Q_Q(CntEditView); |
479 |
486 |
480 if(action == HbMessageBox::Yes || action == HbMessageBox::Delete) |
487 if(action == HbMessageBox::Yes || action == HbMessageBox::Delete) |
481 { |
488 { |
482 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
489 QContactManager& cm = mEngine->contactManager( SYMBIAN_BACKEND ); |
483 |
490 |
484 disconnect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
491 disconnect(&cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
485 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
492 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
486 emit q->contactRemoved(cm->removeContact( mContact->localId() )); |
493 emit q->contactRemoved(cm.removeContact( mContact->localId() )); |
487 |
494 |
488 mMgr->back( mArgs, true ); |
495 mMgr->back( mArgs, true ); |
489 } |
496 } |
|
497 |
|
498 CNT_EXIT |
490 } |
499 } |
491 |
500 |
492 void CntEditViewPrivate::discardChanges() |
501 void CntEditViewPrivate::discardChanges() |
493 { |
502 { |
494 Q_Q(CntEditView); |
503 Q_Q(CntEditView); |
495 |
504 |
496 emit q->changesDiscarded(); |
505 emit q->changesDiscarded(); |
497 |
506 |
498 // get a fresh one from backend. |
507 // get a fresh one from backend. |
499 QContactManager* mgr = mMgr->contactManager(SYMBIAN_BACKEND); |
508 QContactManager& mgr = mEngine->contactManager(SYMBIAN_BACKEND); |
500 setSelectedContact( mgr->contact( mContact->localId()) ); |
509 setSelectedContact( mgr.contact( mContact->localId()) ); |
501 |
510 |
502 QVariant var; |
511 QVariant var; |
503 var.setValue(*mContact); |
512 var.setValue(*mContact); |
504 |
513 |
505 CntViewParameters viewParameters; |
514 mArgs.insert(ESelectedContact, var); |
506 viewParameters.insert(ESelectedContact, var); |
|
507 |
515 |
508 if ( mArgs.value( EExtraAction ).toString() == CNT_ROOT_ACTION ) |
516 if ( mArgs.value( EExtraAction ).toString() == CNT_ROOT_ACTION ) |
509 { |
517 { |
510 mMgr->back( viewParameters, true ); |
518 mMgr->back( mArgs, true ); |
511 } |
519 } |
512 else |
520 else |
513 { |
521 { |
514 mMgr->back( viewParameters ); |
522 mMgr->back( mArgs ); |
515 } |
523 } |
516 |
524 |
517 } |
525 } |
518 |
526 |
519 void CntEditViewPrivate::saveChanges() |
527 void CntEditViewPrivate::saveChanges() |
520 { |
528 { |
|
529 CNT_ENTRY |
|
530 |
521 Q_Q(CntEditView); |
531 Q_Q(CntEditView); |
522 |
532 |
523 QString name = mMgr->contactManager(SYMBIAN_BACKEND)->synthesizedContactDisplayLabel(*mContact); |
533 QContactManager& mgr = mEngine->contactManager(SYMBIAN_BACKEND); |
|
534 QString name = mgr.synthesizedContactDisplayLabel(*mContact); |
524 |
535 |
525 if (name.isEmpty()) |
536 if (name.isEmpty()) |
526 { |
537 { |
527 name = hbTrId("txt_phob_list_unnamed"); |
538 name = hbTrId("txt_phob_list_unnamed"); |
528 } |
539 } |
529 |
540 |
530 CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, mMgr->contactManager(SYMBIAN_BACKEND)); |
541 disconnect(&mgr, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
|
542 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
|
543 CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, &mgr); |
531 |
544 |
532 QVariant var; |
545 QVariant var; |
533 bool backToRoot(false); |
546 bool backToRoot(false); |
534 |
547 |
535 switch (result) |
548 switch (result) |
738 mDiscard->setEnabled( true ); |
753 mDiscard->setEnabled( true ); |
739 } |
754 } |
740 |
755 |
741 void CntEditViewPrivate::setSelectedContact( QContact aContact ) |
756 void CntEditViewPrivate::setSelectedContact( QContact aContact ) |
742 { |
757 { |
|
758 CNT_ENTRY |
|
759 |
743 if ( mContact ) |
760 if ( mContact ) |
744 { |
761 { |
745 delete mContact; |
762 delete mContact; |
746 mContact = NULL; |
763 mContact = NULL; |
747 } |
764 } |
748 mContact = new QContact( aContact ); |
765 mContact = new QContact( aContact ); |
749 |
766 |
750 QContactManager* cm = mMgr->contactManager( SYMBIAN_BACKEND ); |
767 QContactManager& cm = mEngine->contactManager( SYMBIAN_BACKEND ); |
751 connect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
768 connect(&cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
752 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)), Qt::UniqueConnection); |
769 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)), Qt::UniqueConnection); |
|
770 CNT_EXIT |
753 } |
771 } |
754 |
772 |
755 void CntEditViewPrivate::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds) |
773 void CntEditViewPrivate::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds) |
756 { |
774 { |
757 CNT_ENTRY |
775 CNT_ENTRY |