57 |
57 |
58 delete mContact; |
58 delete mContact; |
59 mContact = NULL; |
59 mContact = NULL; |
60 } |
60 } |
61 |
61 |
62 void CntFavoritesView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs ) |
62 void CntFavoritesView::activate( const CntViewParameters aArgs ) |
63 { |
63 { |
64 if (mView->navigationAction() != mSoftkey) |
64 if (mView->navigationAction() != mSoftkey) |
65 mView->setNavigationAction(mSoftkey); |
65 mView->setNavigationAction(mSoftkey); |
66 |
66 |
67 HbMainWindow* window = mView->mainWindow(); |
67 HbMainWindow* window = mView->mainWindow(); |
68 connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation))); |
68 connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation))); |
69 setOrientation(window->orientation()); |
69 setOrientation(window->orientation()); |
70 |
70 |
71 mContact = new QContact(aArgs.value(ESelectedGroupContact).value<QContact>()); |
71 mContact = new QContact(aArgs.value(ESelectedGroupContact).value<QContact>()); |
72 mViewManager = aMgr; |
72 mViewManager = &mEngine->viewManager(); |
73 |
73 |
74 HbPushButton *addButton = static_cast<HbPushButton*>(mDocumentLoader.findWidget(QString("cnt_button_add"))); |
74 HbPushButton *addButton = static_cast<HbPushButton*>(mDocumentLoader.findWidget(QString("cnt_button_add"))); |
75 connect(addButton, SIGNAL(clicked()), this, SLOT(openSelectionPopup())); |
75 connect(addButton, SIGNAL(clicked()), this, SLOT(openSelectionPopup())); |
|
76 |
|
77 // If no contacts are present, then disable the button |
|
78 QContactDetailFilter filter; |
|
79 filter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
|
80 filter.setValue(QLatin1String(QContactType::TypeContact)); |
|
81 |
|
82 QList<QContactLocalId> contactIds = getContactManager()->contactIds(filter); |
|
83 if (contactIds.isEmpty()) |
|
84 { |
|
85 addButton->setEnabled(false); |
|
86 } |
|
87 |
76 } |
88 } |
77 |
89 |
78 void CntFavoritesView::deactivate() |
90 void CntFavoritesView::deactivate() |
79 { |
91 { |
80 } |
92 } |
81 |
93 |
82 void CntFavoritesView::openSelectionPopup() |
94 void CntFavoritesView::openSelectionPopup() |
83 { |
95 { |
84 /* |
|
85 QSet<QContactLocalId> emptySet; |
|
86 if (!mFetchView) { |
|
87 mFetchView = new CntFetchContacts(*getContactManager()); |
|
88 connect(mFetchView, SIGNAL(clicked()), this, SLOT(handleMemberSelection())); |
|
89 } |
|
90 mFetchView->setDetails(hbTrId("txt_phob_subtitle_favorites"), hbTrId("txt_common_button_save")); |
|
91 mFetchView->displayContacts(HbAbstractItemView::MultiSelection, emptySet); |
|
92 */ |
|
93 CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup( |
96 CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup( |
94 hbTrId("txt_phob_subtitle_favorites"), |
97 hbTrId("txt_phob_subtitle_favorites"), |
95 hbTrId("txt_common_button_save"), |
98 hbTrId("txt_common_button_save"), |
96 *getContactManager()); |
99 *getContactManager()); |
97 connect(popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), |
100 connect(popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), |
98 this, SLOT(handleMemberSelection(QSet<QContactLocalId>))); |
101 this, SLOT(handleMemberSelection(QSet<QContactLocalId>))); |
|
102 QSet<QContactLocalId> ids; |
|
103 popup->setSelectedContacts(ids); |
99 popup->showPopup(); |
104 popup->showPopup(); |
100 } |
105 } |
101 |
106 |
102 void CntFavoritesView::handleMemberSelection( QSet<QContactLocalId> aIds ) |
107 void CntFavoritesView::handleMemberSelection( QSet<QContactLocalId> aIds ) |
103 { |
108 { |
104 //QSet<QContactLocalId> members = mFetchView->getSelectedContacts(); |
|
105 //bool saveChanges = !mFetchView->wasCanceled(); |
|
106 |
|
107 //delete mFetchView; |
|
108 //mFetchView = 0; |
|
109 |
|
110 //if (!saveChanges || members.count() == 0) |
|
111 if ( aIds.isEmpty() ) |
109 if ( aIds.isEmpty() ) |
112 { |
110 { |
113 showPreviousView(); |
111 showPreviousView(); |
114 } |
112 } |
115 else |
113 else |
116 { |
114 { |
117 QList<QContactRelationship> memberships; |
115 QList<QContactRelationship> memberships; |
118 foreach (QContactLocalId id, aIds) { |
116 foreach (QContactLocalId id, aIds) { |
119 QContact contact = getContactManager()->contact(id); |
117 QContactId contactId; |
|
118 contactId.setLocalId(id); |
120 QContactRelationship membership; |
119 QContactRelationship membership; |
121 membership.setRelationshipType(QContactRelationship::HasMember); |
120 membership.setRelationshipType(QContactRelationship::HasMember); |
122 membership.setFirst(mContact->id()); |
121 membership.setFirst(mContact->id()); |
123 membership.setSecond(contact.id()); |
122 membership.setSecond(contactId); |
124 memberships.append(membership); |
123 memberships.append(membership); |
125 } |
124 } |
126 |
125 |
127 if (!memberships.isEmpty()) { |
126 if (!memberships.isEmpty()) { |
128 QMap<int, QContactManager::Error> errors; |
127 getContactManager()->saveRelationships(&memberships, NULL); |
129 getContactManager()->saveRelationships(&memberships, &errors); |
|
130 } |
128 } |
131 |
129 |
132 CntViewParameters viewParameters; |
130 CntViewParameters viewParameters; |
133 viewParameters.insert(EViewId, favoritesMemberView); |
131 viewParameters.insert(EViewId, favoritesMemberView); |
134 QVariant var; |
132 QVariant var; |