22 #include <hblistview.h> |
22 #include <hblistview.h> |
23 #include <hbmenu.h> |
23 #include <hbmenu.h> |
24 #include <hbaction.h> |
24 #include <hbaction.h> |
25 #include <hblistview.h> |
25 #include <hblistview.h> |
26 #include <hblistviewitem.h> |
26 #include <hblistviewitem.h> |
|
27 #include <hbindexfeedback.h> |
|
28 #include <hbscrollbar.h> |
27 #include <hbview.h> |
29 #include <hbview.h> |
28 #include <hbaction.h> |
30 #include <hbaction.h> |
29 #include <hblabel.h> |
31 #include <hblabel.h> |
30 #include <mobcntmodel.h> |
32 #include <mobcntmodel.h> |
31 #include <hbframebackground.h> |
33 #include <hbframebackground.h> |
90 mContact = new QContact(aArgs.value(ESelectedContact).value<QContact>()); |
92 mContact = new QContact(aArgs.value(ESelectedContact).value<QContact>()); |
91 mViewManager = aMgr; |
93 mViewManager = aMgr; |
92 |
94 |
93 mFavoriteListView = static_cast<HbListView*> (mDocumentLoader.findWidget("listView")); |
95 mFavoriteListView = static_cast<HbListView*> (mDocumentLoader.findWidget("listView")); |
94 mFavoriteListView->setUniformItemSizes(true); |
96 mFavoriteListView->setUniformItemSizes(true); |
|
97 mFavoriteListView->setFrictionEnabled(true); |
|
98 mFavoriteListView->setScrollingStyle(HbScrollArea::PanWithFollowOn); |
|
99 mFavoriteListView->verticalScrollBar()->setInteractive(true); |
95 connect(mFavoriteListView, SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)), |
100 connect(mFavoriteListView, SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)), |
96 this, SLOT(onLongPressed(HbAbstractViewItem *, const QPointF &))); |
101 this, SLOT(onLongPressed(HbAbstractViewItem *, const QPointF &))); |
|
102 |
|
103 HbIndexFeedback *indexFeedback = new HbIndexFeedback(mView); |
|
104 indexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter); |
|
105 indexFeedback->setItemView(mFavoriteListView); |
97 |
106 |
98 HbFrameBackground frame; |
107 HbFrameBackground frame; |
99 frame.setFrameGraphicsName("qtg_fr_list_normal"); |
108 frame.setFrameGraphicsName("qtg_fr_list_normal"); |
100 frame.setFrameType(HbFrameDrawer::NinePieces); |
109 frame.setFrameType(HbFrameDrawer::NinePieces); |
101 mFavoriteListView->itemPrototypes().first()->setDefaultFrame(frame); |
110 mFavoriteListView->itemPrototypes().first()->setDefaultFrame(frame); |
139 |
148 |
140 void CntFavoritesMemberView::manageFavorites() |
149 void CntFavoritesMemberView::manageFavorites() |
141 { |
150 { |
142 // call a dialog to display the contacts |
151 // call a dialog to display the contacts |
143 CntGroupSelectionPopup *groupSelectionPopup = new CntGroupSelectionPopup(mViewManager->contactManager(SYMBIAN_BACKEND), mContact); |
152 CntGroupSelectionPopup *groupSelectionPopup = new CntGroupSelectionPopup(mViewManager->contactManager(SYMBIAN_BACKEND), mContact); |
144 mFavoriteListView->setModel(0); |
153 |
145 groupSelectionPopup->populateListOfContact(); |
154 groupSelectionPopup->populateListOfContact(); |
146 |
155 |
147 HbAction* action = groupSelectionPopup->exec(); |
156 groupSelectionPopup->open(this, SLOT(handleManageFavorites(HbAction*))); |
148 if (action == groupSelectionPopup->primaryAction()) |
157 } |
|
158 |
|
159 void CntFavoritesMemberView::handleManageFavorites(HbAction *action) |
|
160 { |
|
161 CntGroupSelectionPopup *groupSelectionPopup = static_cast<CntGroupSelectionPopup*>(sender()); |
|
162 |
|
163 if (groupSelectionPopup && action == groupSelectionPopup->actions().first()) |
149 { |
164 { |
150 groupSelectionPopup->saveOldGroup(); |
165 groupSelectionPopup->saveOldGroup(); |
151 } |
166 } |
152 delete groupSelectionPopup; |
|
153 |
|
154 mFavoriteListView->setModel(mModel); |
|
155 } |
167 } |
156 |
168 |
157 |
169 |
158 /*! |
170 /*! |
159 Called when a list item is longpressed |
171 Called when a list item is longpressed |
160 */ |
172 */ |
161 void CntFavoritesMemberView::onLongPressed (HbAbstractViewItem *aItem, const QPointF &aCoords) |
173 void CntFavoritesMemberView::onLongPressed (HbAbstractViewItem *aItem, const QPointF &aCoords) |
162 { |
174 { |
|
175 QVariant data( aItem->modelIndex().row() ); |
|
176 |
163 QModelIndex index = aItem->modelIndex(); |
177 QModelIndex index = aItem->modelIndex(); |
164 QVariant variant = index.data(Qt::UserRole+1); |
178 QVariant variant = index.data(Qt::UserRole+1); |
165 const QMap<QString, QVariant> map = variant.toMap(); |
179 const QMap<QString, QVariant> map = variant.toMap(); |
166 |
180 |
167 HbMenu *menu = new HbMenu(); |
181 HbMenu *menu = new HbMenu(); |
|
182 menu->setAttribute(Qt::WA_DeleteOnClose); |
|
183 menu->setPreferredPos( aCoords ); |
168 |
184 |
169 HbAction *openContactAction = 0; |
185 HbAction *openContactAction = 0; |
170 HbAction *editContactAction = 0; |
186 HbAction *editContactAction = 0; |
171 HbAction *removeFromFavoritesAction = 0; |
187 HbAction *removeFromFavoritesAction = 0; |
172 HbAction *sendToHsAction = 0; |
188 HbAction *sendToHsAction = 0; |
175 |
191 |
176 openContactAction = menu->addAction(hbTrId("txt_common_menu_open")); |
192 openContactAction = menu->addAction(hbTrId("txt_common_menu_open")); |
177 editContactAction = menu->addAction(hbTrId("txt_common_menu_edit")); |
193 editContactAction = menu->addAction(hbTrId("txt_common_menu_edit")); |
178 removeFromFavoritesAction = menu->addAction(hbTrId("txt_phob_menu_remove_from_favorites")); |
194 removeFromFavoritesAction = menu->addAction(hbTrId("txt_phob_menu_remove_from_favorites")); |
179 sendToHsAction = menu->addAction(hbTrId("Send to HS")); |
195 sendToHsAction = menu->addAction(hbTrId("Send to HS")); |
180 |
196 |
181 HbAction *selectedAction = menu->exec(aCoords); |
197 openContactAction->setData( data ); |
182 |
198 editContactAction->setData( data ); |
183 if (selectedAction) |
199 removeFromFavoritesAction->setData( data ); |
184 { |
200 sendToHsAction->setData( data ); |
185 if (selectedAction == openContactAction) |
201 |
|
202 menu->open(this, SLOT(handleMenu(HbAction*))); |
|
203 } |
|
204 |
|
205 void CntFavoritesMemberView::handleMenu(HbAction* action) |
|
206 { |
|
207 int row = action->data().toInt(); |
|
208 HbMenu *menuItem = static_cast<HbMenu*>(sender()); |
|
209 QModelIndex index = mModel->index(row, 0); |
|
210 |
|
211 int id = index.data(Qt::UserRole).toInt(); |
|
212 |
|
213 if ( action == menuItem->actions().first() ) |
186 { |
214 { |
187 openContact(index); |
215 openContact(index); |
188 } |
216 } |
189 else if (selectedAction == editContactAction) |
217 else if (action == menuItem->actions().at(1)) |
190 { |
218 { |
191 editContact(index); |
219 editContact(index); |
192 } |
220 } |
193 else if (selectedAction == removeFromFavoritesAction) |
221 else if (action == menuItem->actions().at(2)) |
194 { |
222 { |
195 removeFromFavorites(index); |
223 removeFromFavorites(index); |
196 } |
224 } |
197 else if (selectedAction == sendToHsAction) |
225 else if (action == menuItem->actions().at(3)) |
198 { |
226 { |
199 // sendToHs(index); |
227 // sendToHs(index); |
200 } |
228 } |
201 } |
229 } |
202 menu->deleteLater(); |
|
203 } |
|
204 |
230 |
205 void CntFavoritesMemberView::openContact(const QModelIndex &index) |
231 void CntFavoritesMemberView::openContact(const QModelIndex &index) |
206 { |
232 { |
207 QContact selectedContact = mModel->contact(index); |
233 QContact selectedContact = mModel->contact(index); |
208 |
234 |
234 Called after user clicked on the listview. |
260 Called after user clicked on the listview. |
235 */ |
261 */ |
236 void CntFavoritesMemberView::removeFromFavorites(const QModelIndex &index) |
262 void CntFavoritesMemberView::removeFromFavorites(const QModelIndex &index) |
237 { |
263 { |
238 // get contact id using index |
264 // get contact id using index |
239 QContact selectedContact = mModel->contact(index); |
265 QContact selectedContact = mModel->contact(index); |
240 QContactRelationship relationship; |
266 QContactRelationship relationship; |
241 relationship.setRelationshipType(QContactRelationship::HasMember); |
267 relationship.setRelationshipType(QContactRelationship::HasMember); |
242 relationship.setFirst(mContact->id()); |
268 relationship.setFirst(mContact->id()); |
243 relationship.setSecond(selectedContact.id()); |
269 relationship.setSecond(selectedContact.id()); |
244 mViewManager->contactManager(SYMBIAN_BACKEND)->removeRelationship(relationship); |
270 mViewManager->contactManager(SYMBIAN_BACKEND)->removeRelationship(relationship); |
245 } |
271 } |
246 |
272 |