|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cntgroupmemberview.h" |
|
19 #include "qtpbkglobal.h" |
|
20 #include "cntcommands.h" |
|
21 #include <hbnotificationdialog.h> |
|
22 #include <hbmenu.h> |
|
23 |
|
24 #include <QStringListModel> |
|
25 #include <QMap> |
|
26 #include <hbpushbutton.h> |
|
27 #include <QGraphicsLinearLayout> |
|
28 #include <hbdocumentloader.h> |
|
29 #include <hblistview.h> |
|
30 #include <hblabel.h> |
|
31 #include <hblistviewitem.h> |
|
32 #include <hbtoolbar.h> |
|
33 #include <hbsearchpanel.h> |
|
34 #include <hbtextitem.h> |
|
35 |
|
36 |
|
37 #include "cntcontactcardheadingitem.h" |
|
38 #include "cntgroupselectionpopup.h" |
|
39 |
|
40 /*! |
|
41 \class CntGroupMemberView |
|
42 \brief |
|
43 |
|
44 This is the group members view class that shows list of contacts for a user group. View contains a listview that shows actual contacts that |
|
45 have been added to a particular group. There is also toolbar and menu for navigating between different views. Instance of this class is |
|
46 created by our viewmanager but view itself is owned by the mainwindow which will also delete it in the end. |
|
47 |
|
48 */ |
|
49 |
|
50 /*! |
|
51 Constructor, initialize member variables. |
|
52 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0) |
|
53 |
|
54 */ |
|
55 CntGroupMemberView::CntGroupMemberView(CntViewManager *viewManager, QGraphicsItem *parent) |
|
56 : CntBaseListView(viewManager, parent), |
|
57 mNoGroupContactsPresent(0), |
|
58 mGroupContact(0), |
|
59 mSearchPanel(0), |
|
60 mEmptyListLabel(0) |
|
61 { |
|
62 |
|
63 } |
|
64 |
|
65 /*! |
|
66 Destructor |
|
67 */ |
|
68 CntGroupMemberView::~CntGroupMemberView() |
|
69 { |
|
70 delete mGroupContact; |
|
71 } |
|
72 |
|
73 void CntGroupMemberView::aboutToCloseView() |
|
74 { |
|
75 if (mSearchPanel) |
|
76 { |
|
77 closeFind(); |
|
78 } |
|
79 else |
|
80 { |
|
81 CntViewParameters viewParameters(CntViewParameters::groupActionsView); |
|
82 viewParameters.setSelectedContact(*mGroupContact); |
|
83 viewManager()->onActivateView(viewParameters); |
|
84 } |
|
85 } |
|
86 |
|
87 /*! |
|
88 Add actions also to toolbar |
|
89 */ |
|
90 void CntGroupMemberView::addActionsToToolBar() |
|
91 { |
|
92 actions()->clearActionList(); |
|
93 |
|
94 actions()->actionList() << actions()->baseAction("cnt:managemembers") << actions()->baseAction("cnt:find"); |
|
95 actions()->addActionsToToolBar(toolBar()); |
|
96 |
|
97 //setItemVisible |
|
98 connect(actions()->baseAction("cnt:managemembers"), SIGNAL(triggered()), |
|
99 this, SLOT(manageMembers())); |
|
100 connect(actions()->baseAction("cnt:find"), SIGNAL(triggered()), |
|
101 this, SLOT(find())); |
|
102 actions()->baseAction("cnt:find")->setEnabled(false); // to be enabled after Intersection filter implementation |
|
103 |
|
104 } |
|
105 void CntGroupMemberView::find() |
|
106 { |
|
107 if (mSearchPanel == 0) |
|
108 { |
|
109 toolBar()->hide(); |
|
110 mSearchPanel = new HbSearchPanel(); |
|
111 setBannerName(hbTrId("Find: Group contacts")); |
|
112 banner()->setVisible(true); |
|
113 listLayout()->addItem(mSearchPanel); |
|
114 contactModel()->showMyCard(false); |
|
115 setFilter(QString()); |
|
116 |
|
117 connect(mSearchPanel, SIGNAL(exitClicked()), this, SLOT(closeFind())); |
|
118 connect(mSearchPanel, SIGNAL(criteriaChanged(QString)), this, SLOT(setFilter(QString))); |
|
119 } |
|
120 |
|
121 } |
|
122 |
|
123 void CntGroupMemberView::setFilter(const QString &filterString) |
|
124 { |
|
125 QStringList searchList = filterString.split(QRegExp("\\s+"), QString::SkipEmptyParts); |
|
126 |
|
127 QContactDetailFilter filter; |
|
128 filter.setDetailDefinitionName(QContactDisplayLabel::DefinitionName, QContactDisplayLabel::FieldLabel); |
|
129 filter.setMatchFlags(QContactFilter::MatchStartsWith); |
|
130 filter.setValue(searchList); |
|
131 |
|
132 mFilteredLocalIdList = contactManager()->contacts(filter); |
|
133 |
|
134 contactModel()->setFilterAndSortOrder(filter); |
|
135 // use intersection filter here <support from engine side> |
|
136 |
|
137 if (!contactModel()->rowCount()) |
|
138 { |
|
139 listLayout()->removeItem(listView()); |
|
140 listView()->setVisible(false); |
|
141 if (mEmptyListLabel == 0) |
|
142 { |
|
143 mEmptyListLabel = new HbTextItem(hbTrId("(no matching contacts)")); |
|
144 mEmptyListLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
|
145 mEmptyListLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
146 mEmptyListLabel->setAlignment(Qt::AlignCenter); |
|
147 listLayout()->insertItem(1, mEmptyListLabel); |
|
148 } |
|
149 } |
|
150 else |
|
151 { |
|
152 listLayout()->removeItem(mEmptyListLabel); |
|
153 delete mEmptyListLabel; |
|
154 mEmptyListLabel = 0; |
|
155 listLayout()->insertItem(1, listView()); |
|
156 listView()->setVisible(true); |
|
157 } |
|
158 } |
|
159 |
|
160 void CntGroupMemberView::closeFind() |
|
161 { |
|
162 if( mSearchPanel) |
|
163 { |
|
164 listLayout()->removeItem(mEmptyListLabel); |
|
165 delete mEmptyListLabel; |
|
166 mEmptyListLabel = 0; |
|
167 |
|
168 listLayout()->removeItem(banner()); |
|
169 banner()->setVisible(false); |
|
170 listLayout()->removeItem(mSearchPanel); |
|
171 listLayout()->addItem(listView()); |
|
172 listView()->setVisible(true); |
|
173 |
|
174 // display User-groups |
|
175 QContactRelationshipFilter rFilter; |
|
176 rFilter.setRelationshipType(QContactRelationship::HasMember); |
|
177 rFilter.setRole(QContactRelationshipFilter::Second); |
|
178 rFilter.setOtherParticipantId(mGroupContact->id()); |
|
179 |
|
180 contactModel()->setFilterAndSortOrder(rFilter); |
|
181 contactModel()->showMyCard(false); |
|
182 |
|
183 mSearchPanel->deleteLater(); |
|
184 mSearchPanel = 0; |
|
185 toolBar()->show(); |
|
186 } |
|
187 } |
|
188 |
|
189 void CntGroupMemberView::groupActions() |
|
190 { |
|
191 CntViewParameters viewParameters(CntViewParameters::groupActionsView); |
|
192 viewParameters.setSelectedContact(*mGroupContact); |
|
193 viewManager()->onActivateView(viewParameters); |
|
194 } |
|
195 |
|
196 void CntGroupMemberView::callNamesList() |
|
197 { |
|
198 CntViewParameters viewParameters(CntViewParameters::namesView); |
|
199 viewManager()->onActivateView(viewParameters); |
|
200 } |
|
201 |
|
202 void CntGroupMemberView::manageMembers() |
|
203 { |
|
204 // save the group here |
|
205 CntGroupSelectionPopup *groupSelectionPopup = new CntGroupSelectionPopup(contactManager(),contactModel(),mGroupContact); |
|
206 listView()->hide(); |
|
207 groupSelectionPopup->populateListOfContact(); |
|
208 |
|
209 |
|
210 HbAction* action = groupSelectionPopup->exec(); |
|
211 if (action == groupSelectionPopup->primaryAction()) |
|
212 { |
|
213 groupSelectionPopup->saveOldGroup(); |
|
214 CntViewParameters viewParameters(CntViewParameters::groupActionsView); |
|
215 viewParameters.setSelectedContact(*mGroupContact); |
|
216 viewManager()->onActivateView(viewParameters); |
|
217 } |
|
218 delete groupSelectionPopup; |
|
219 listView()->show(); |
|
220 } |
|
221 /*! |
|
222 Add actions to menu |
|
223 */ |
|
224 void CntGroupMemberView::addMenuItems() |
|
225 { |
|
226 actions()->clearActionList(); |
|
227 actions()->actionList() << actions()->baseAction("cnt:editgroupdetails") << actions()->baseAction("cnt:managemembersmenu") << |
|
228 actions()->baseAction("cnt:placegrouptohs") << actions()->baseAction("cnt:deletegroup"); |
|
229 actions()->addActionsToMenu(menu()); |
|
230 |
|
231 connect(actions()->baseAction("cnt:editgroupdetails"), SIGNAL(triggered()), |
|
232 this, SLOT (editGroup())); |
|
233 |
|
234 connect(actions()->baseAction("cnt:managemembersmenu"), SIGNAL(triggered()), |
|
235 this, SLOT (manageMembers())); |
|
236 |
|
237 connect(actions()->baseAction("cnt:placegrouptohs"), SIGNAL(triggered()), |
|
238 this, SLOT (placeGroupToHs())); |
|
239 |
|
240 connect(actions()->baseAction("cnt:deletegroup"), SIGNAL(triggered()), |
|
241 this, SLOT (deleteGroup())); |
|
242 |
|
243 } |
|
244 |
|
245 void CntGroupMemberView::editGroup() |
|
246 { |
|
247 CntViewParameters viewParameters(CntViewParameters::groupEditorView); |
|
248 viewParameters.setSelectedAction("EditGroupDetails"); |
|
249 viewParameters.setSelectedContact(*mGroupContact); |
|
250 viewManager()->onActivateView(viewParameters); |
|
251 } |
|
252 |
|
253 void CntGroupMemberView::placeGroupToHs() |
|
254 { |
|
255 // wait for specs |
|
256 } |
|
257 |
|
258 void CntGroupMemberView::deleteGroup() |
|
259 { |
|
260 // the delete command |
|
261 connect(commands(), SIGNAL(commandExecuted(QString, QContact)), this, |
|
262 SLOT(handleExecutedCommand(QString, QContact))); |
|
263 commands()->deleteContact(*mGroupContact); |
|
264 } |
|
265 |
|
266 /*! |
|
267 Called when a list item is longpressed |
|
268 */ |
|
269 void CntGroupMemberView::onLongPressed (HbAbstractViewItem *aItem, const QPointF &aCoords) |
|
270 { |
|
271 QModelIndex index = aItem->modelIndex(); |
|
272 QVariant variant = index.data(Qt::UserRole+1); |
|
273 const QMap<QString, QVariant> map = variant.toMap(); |
|
274 |
|
275 HbMenu *menu = new HbMenu(); |
|
276 HbAction *removeFromGroupAction = 0; |
|
277 HbAction *viewDetailsAction = 0; |
|
278 |
|
279 QString action = map.value("action").toString(); |
|
280 |
|
281 removeFromGroupAction = menu->addAction(hbTrId("txt_phob_menu_remove_from_group")); |
|
282 viewDetailsAction = menu->addAction(hbTrId("View details")); |
|
283 |
|
284 HbAction *selectedAction = menu->exec(aCoords); |
|
285 |
|
286 if (selectedAction) |
|
287 { |
|
288 if (selectedAction == removeFromGroupAction) |
|
289 { |
|
290 removeFromGroup(index); |
|
291 } |
|
292 else if (selectedAction == viewDetailsAction) |
|
293 { |
|
294 onListViewActivated(index); |
|
295 } |
|
296 } |
|
297 menu->deleteLater(); |
|
298 } |
|
299 |
|
300 void CntGroupMemberView::removeFromGroup(const QModelIndex &index) |
|
301 { |
|
302 // get contact id using index |
|
303 QContact selectedContact = contactModel()->contact(index); |
|
304 QContactRelationship relationship; |
|
305 relationship.setRelationshipType(QContactRelationship::HasMember); |
|
306 relationship.setFirst(mGroupContact->id()); |
|
307 relationship.setSecond(selectedContact.id()); |
|
308 contactManager()->removeRelationship(relationship); |
|
309 } |
|
310 |
|
311 void CntGroupMemberView::viewDetailsOfGroupContact(const QModelIndex &index) |
|
312 { |
|
313 QContact selectedContact = contactModel()->contact(index); |
|
314 CntViewParameters viewParameters(CntViewParameters::commLauncherView); |
|
315 viewParameters.setSelectedContact(selectedContact); |
|
316 viewManager()->onActivateView(viewParameters); |
|
317 } |
|
318 |
|
319 /*! |
|
320 Called after user clicked on the listview. |
|
321 */ |
|
322 void CntGroupMemberView::onListViewActivated(const QModelIndex &index) |
|
323 { |
|
324 CntViewParameters viewParameters(CntViewParameters::commLauncherView); |
|
325 viewParameters.setSelectedContact(contactModel()->contact(index)); |
|
326 viewParameters.setSelectedGroupContact(*mGroupContact); |
|
327 viewParameters.setSelectedAction("FromGroupMemberView"); |
|
328 viewManager()->onActivateView(viewParameters); |
|
329 |
|
330 } |
|
331 |
|
332 void CntGroupMemberView::handleExecutedCommand(QString command, QContact /*contact*/) |
|
333 { |
|
334 if (command == "delete") |
|
335 { |
|
336 CntViewParameters viewParameters(CntViewParameters::collectionView); |
|
337 viewManager()->onActivateView(viewParameters); |
|
338 } |
|
339 } |
|
340 |
|
341 void CntGroupMemberView::activateView(const CntViewParameters &viewParameters) |
|
342 { |
|
343 QContact contact = viewParameters.selectedContact(); |
|
344 mGroupContact = new QContact(contact); |
|
345 |
|
346 QContactName groupContactName = mGroupContact->detail( QContactName::DefinitionName ); |
|
347 QString groupName(groupContactName.value( QContactName::FieldCustomLabel )); |
|
348 |
|
349 setBannerName(groupName); |
|
350 |
|
351 // display User-groups |
|
352 QContactRelationshipFilter rFilter; |
|
353 rFilter.setRelationshipType(QContactRelationship::HasMember); |
|
354 rFilter.setRole(QContactRelationshipFilter::Second); |
|
355 rFilter.setOtherParticipantId(mGroupContact->id()); |
|
356 |
|
357 mLocalIdList = contactManager()->contacts(rFilter); |
|
358 |
|
359 contactModel()->setFilterAndSortOrder(rFilter); |
|
360 |
|
361 contactModel()->showMyCard(false); |
|
362 if (viewParameters.selectedAction() == "save") |
|
363 { |
|
364 QString name = contactManager()->synthesizeDisplayLabel(viewParameters.selectedContact()); |
|
365 HbNotificationDialog::launchDialog(hbTrId("Group \"%1\" saved").arg(name)); |
|
366 } |
|
367 |
|
368 CntBaseListView::activateView(viewParameters); |
|
369 } |
|
370 |
|
371 // end of file |