|
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 "cntcollectionview.h" |
|
19 |
|
20 #include <hblistview.h> |
|
21 #include <hblistviewitem.h> |
|
22 #include <hbmenu.h> |
|
23 #include <hbnotificationdialog.h> |
|
24 #include <hblabel.h> |
|
25 #include "hbinputdialog.h" |
|
26 #include "hbdialog.h" |
|
27 #include "hbaction.h" |
|
28 #include "cntgroupselectionpopup.h" |
|
29 |
|
30 const char *CNT_COLLECTIONVIEW_ACTIONS_XML = ":/xml/contacts_actions.docml"; |
|
31 |
|
32 /*! |
|
33 |
|
34 */ |
|
35 CntCollectionView::CntCollectionView(CntViewManager *viewManager, QGraphicsItem *parent) |
|
36 : CntBaseListView(viewManager, parent), |
|
37 mModel(0), |
|
38 mReorderAction(0), |
|
39 mDeleteGroupAction(0), |
|
40 mDisconnectAllAction(0), |
|
41 mOptionsMenu(0) |
|
42 { |
|
43 setBannerName(hbTrId("txt_phob_subtitle_groups")); |
|
44 } |
|
45 |
|
46 /*! |
|
47 |
|
48 */ |
|
49 CntCollectionView::~CntCollectionView() |
|
50 { |
|
51 delete mModel; |
|
52 mModel = 0; |
|
53 delete mOptionsMenu; |
|
54 mOptionsMenu = 0; |
|
55 } |
|
56 |
|
57 /*! |
|
58 |
|
59 */ |
|
60 void CntCollectionView::aboutToCloseView() |
|
61 { |
|
62 CntViewParameters viewParameters(CntViewParameters::namesView); |
|
63 viewManager()->onActivateView(viewParameters); |
|
64 } |
|
65 |
|
66 /*! |
|
67 Called after user clicked on the listview. |
|
68 */ |
|
69 void CntCollectionView::onListViewActivated(const QModelIndex &index) |
|
70 { |
|
71 int id = index.data(Qt::UserRole).toInt(); |
|
72 |
|
73 if (id == -1) |
|
74 { |
|
75 CntViewParameters viewParameters(CntViewParameters::collectionFavoritesView); |
|
76 viewManager()->onActivateView(viewParameters); |
|
77 } |
|
78 else |
|
79 { |
|
80 QContact groupContact = contactManager()->contact(id); |
|
81 CntViewParameters viewParameters(CntViewParameters::groupActionsView); |
|
82 viewParameters.setSelectedContact(groupContact); |
|
83 viewManager()->onActivateView(viewParameters); |
|
84 } |
|
85 } |
|
86 |
|
87 void CntCollectionView::onLongPressed(HbAbstractViewItem *item, const QPointF &coords) |
|
88 { |
|
89 HbMenu *menu = new HbMenu(); |
|
90 HbAction *openAction = 0; |
|
91 HbAction *deleteAction = 0; |
|
92 HbAction *homeScreenAction = 0; |
|
93 |
|
94 openAction = menu->addAction(hbTrId("txt_common_menu_open")); |
|
95 |
|
96 if (item->modelIndex().data(Qt::UserRole).toInt() > -1) |
|
97 { |
|
98 deleteAction = menu->addAction(hbTrId("txt_phob_menu_delete_group")); |
|
99 } |
|
100 |
|
101 homeScreenAction = menu->addAction(hbTrId("txt_phob_opt_send_to_homescreen_as_widget")); |
|
102 homeScreenAction->setEnabled(false); |
|
103 |
|
104 HbAction *selectedAction = menu->exec(coords); |
|
105 |
|
106 if (selectedAction) |
|
107 { |
|
108 if (selectedAction == openAction) |
|
109 { |
|
110 onListViewActivated(item->modelIndex()); |
|
111 } |
|
112 else if (selectedAction == deleteAction) |
|
113 { |
|
114 connect(commands(), SIGNAL(commandExecuted(QString, QContact)), this, |
|
115 SLOT(handleExecutedCommand(QString, QContact))); |
|
116 QContact groupContact = contactManager()->contact(item->modelIndex().data(Qt::UserRole).toInt()); |
|
117 commands()->deleteContact(groupContact); |
|
118 } |
|
119 else if (selectedAction == homeScreenAction) |
|
120 { |
|
121 |
|
122 } |
|
123 } |
|
124 menu->deleteLater(); |
|
125 } |
|
126 |
|
127 void CntCollectionView::handleExecutedCommand(QString command, QContact contact) |
|
128 { |
|
129 if (command == "delete") |
|
130 { |
|
131 static_cast<CntCollectionListModel*>(listView()->model())->removeGroup(contact.localId()); |
|
132 } |
|
133 } |
|
134 |
|
135 /*! |
|
136 Add actions also to toolbar |
|
137 */ |
|
138 void CntCollectionView::addActionsToToolBar() |
|
139 { |
|
140 actions()->clearActionList(); |
|
141 actions()->actionList() << actions()->baseAction("cnt:nameslist") << actions()->baseAction("cnt:collections") |
|
142 << actions()->baseAction("cnt:refresh") << actions()->baseAction("cnt:newgroup"); |
|
143 actions()->addActionsToToolBar(toolBar()); |
|
144 |
|
145 connect(actions()->baseAction("cnt:nameslist"), SIGNAL(triggered()), |
|
146 this, SLOT (aboutToCloseView())); |
|
147 |
|
148 actions()->baseAction("cnt:collections")->setEnabled(false); |
|
149 |
|
150 connect(actions()->baseAction("cnt:newgroup"), SIGNAL(triggered()), |
|
151 this, SLOT (newGroup())); |
|
152 } |
|
153 |
|
154 void CntCollectionView::newGroup() |
|
155 { |
|
156 QString mTextOfNewItem(""); |
|
157 |
|
158 HbInputDialog popup; |
|
159 |
|
160 HbGroupBox *headingLabel = new HbGroupBox(); |
|
161 HbLabel *label = new HbLabel(hbTrId("txt_phob_title_new_group_name")); |
|
162 headingLabel->setContentWidget(label); |
|
163 popup.setHeadingWidget(headingLabel); |
|
164 popup.setPrimaryAction(new HbAction(hbTrId("txt_phob_button_create"),&popup)); |
|
165 popup.setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"),&popup)); |
|
166 popup.setInputMode(HbInputDialog::TextInput); |
|
167 popup.setPromptText(""); |
|
168 popup.setBackgroundFaded(true); |
|
169 HbAction* action = popup.exec(); |
|
170 QString text = popup.value().toString(); |
|
171 |
|
172 if (action == popup.primaryAction()) |
|
173 { |
|
174 mTextOfNewItem = text; |
|
175 |
|
176 QContact groupContact; |
|
177 groupContact.setType(QContactType::TypeGroup); |
|
178 |
|
179 |
|
180 QContactName groupName; |
|
181 groupName.setCustomLabel(mTextOfNewItem); |
|
182 |
|
183 groupContact.saveDetail(&groupName); |
|
184 contactManager()->saveContact(&groupContact); |
|
185 |
|
186 // call a dialog to display the contacts |
|
187 |
|
188 CntGroupSelectionPopup *groupSelectionPopup = new CntGroupSelectionPopup(contactManager(),contactModel(),&groupContact); |
|
189 groupSelectionPopup->populateListOfContact(); |
|
190 HbAction* action = groupSelectionPopup->exec(); |
|
191 if (action == groupSelectionPopup->primaryAction()) |
|
192 { |
|
193 groupSelectionPopup->saveNewGroup(); |
|
194 CntViewParameters viewParameters(CntViewParameters::groupActionsView); |
|
195 viewParameters.setSelectedContact(groupContact); |
|
196 viewManager()->onActivateView(viewParameters); |
|
197 delete groupSelectionPopup; |
|
198 } |
|
199 else if (action == groupSelectionPopup->secondaryAction()) |
|
200 { |
|
201 delete groupSelectionPopup; |
|
202 QString groupNameCreated(groupName.value( QContactName::FieldCustomLabel )); |
|
203 HbNotificationDialog::launchDialog(hbTrId("txt_phob_dpophead_new_group_1_created").arg(groupNameCreated)); |
|
204 //refresh the page |
|
205 refreshDataModel(); |
|
206 //reconstruct the menu items |
|
207 addMenuItems(); |
|
208 } |
|
209 |
|
210 } |
|
211 } |
|
212 |
|
213 void CntCollectionView::setDataModel() |
|
214 { |
|
215 HbListViewItem *prototype = listView()->listItemPrototype(); |
|
216 prototype->setGraphicsSize(HbListViewItem::LargeIcon); |
|
217 mModel = new CntCollectionListModel(contactManager(), this); |
|
218 listView()->setModel(mModel); |
|
219 } |
|
220 |
|
221 void CntCollectionView::refreshDataModel() |
|
222 { |
|
223 delete mModel; |
|
224 mModel = 0; |
|
225 mModel = new CntCollectionListModel(contactManager(), this); |
|
226 listView()->setModel(mModel); |
|
227 } |
|
228 |
|
229 void CntCollectionView::addMenuItems() |
|
230 { |
|
231 bool ok = false; |
|
232 HbDocumentLoader documentLoader; |
|
233 documentLoader.load(CNT_COLLECTIONVIEW_ACTIONS_XML, &ok); |
|
234 if (!ok) |
|
235 { |
|
236 qFatal("Unable to read :/xml/contacts_actions.docml"); |
|
237 } |
|
238 |
|
239 //Uncomment this once spec for this is ready |
|
240 // mReorderAction = qobject_cast<HbAction *>(documentLoader.findObject("cnt:reordergroups")); |
|
241 mDeleteGroupAction = qobject_cast<HbAction* >(documentLoader.findObject("cnt:deletegroups")); |
|
242 |
|
243 //Uncomment this once spec for this is ready |
|
244 // mDisconnectAllAction =qobject_cast<HbAction *>(documentLoader.findObject("cnt:disconnectall")); |
|
245 |
|
246 delete mOptionsMenu; |
|
247 mOptionsMenu = 0; |
|
248 mOptionsMenu = new HbMenu(); |
|
249 //Uncomment this once spec for this is ready |
|
250 //mOptionsMenu->addAction(mReorderAction); |
|
251 |
|
252 //add deletegroup action to option menu if group presents |
|
253 QContactDetailFilter groupFilter; |
|
254 groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
|
255 groupFilter.setValue(QString(QLatin1String(QContactType::TypeGroup))); |
|
256 QList<QContactLocalId> groupContactIds = contactManager()->contacts(groupFilter); |
|
257 if (!groupContactIds.isEmpty()) |
|
258 { |
|
259 mOptionsMenu->addAction(mDeleteGroupAction); |
|
260 } |
|
261 |
|
262 //Uncomment this once spec for this is ready |
|
263 // mOptionsMenu->addAction(mDisconnectAllAction); |
|
264 |
|
265 // connect(mReorderAction, SIGNAL(triggered()), this, SLOT (reorderGroup())); |
|
266 connect(mDeleteGroupAction, SIGNAL(triggered()), this, SLOT (deleteGroups())); |
|
267 // connect(mDisconnectAllAction, SIGNAL(triggered()), this, SLOT (disconnectAll())); |
|
268 |
|
269 setMenu(mOptionsMenu); |
|
270 } |
|
271 |
|
272 void CntCollectionView::reorderGroup() |
|
273 { |
|
274 // wait for specs |
|
275 } |
|
276 |
|
277 void CntCollectionView::deleteGroups() |
|
278 { |
|
279 // save the group here |
|
280 QContact groupContact; |
|
281 groupContact.setType(QContactType::TypeGroup); |
|
282 |
|
283 CntGroupSelectionPopup *groupSelectionPopup = new CntGroupSelectionPopup(contactManager(),contactModel(),&groupContact); |
|
284 |
|
285 groupSelectionPopup->populateListOfGroup(); |
|
286 HbAction* action = groupSelectionPopup->exec(); |
|
287 if (action == groupSelectionPopup->primaryAction()) |
|
288 { |
|
289 groupSelectionPopup->deleteGroup(); |
|
290 } |
|
291 |
|
292 delete groupSelectionPopup; |
|
293 |
|
294 //refresh the page |
|
295 refreshDataModel(); |
|
296 //reconstruct the menu items |
|
297 addMenuItems(); |
|
298 } |
|
299 |
|
300 void CntCollectionView::disconnectAll() |
|
301 { |
|
302 // wait for specs |
|
303 } |
|
304 |
|
305 // EOF |