221 } |
236 } |
222 } |
237 } |
223 else |
238 else |
224 { |
239 { |
225 int id = item->modelIndex().data(Qt::UserRole).toInt(); |
240 int id = item->modelIndex().data(Qt::UserRole).toInt(); |
|
241 QVariant data( item->modelIndex().row() ); |
|
242 |
226 int favoriteGrpId = mModel->favoriteGroupId(); |
243 int favoriteGrpId = mModel->favoriteGroupId(); |
227 |
244 |
228 HbMenu *menu = new HbMenu(); |
245 HbMenu *menu = new HbMenu(); |
229 HbAction *openAction = 0; |
246 menu->setAttribute(Qt::WA_DeleteOnClose); |
230 HbAction *deleteAction = 0; |
247 menu->setPreferredPos( coords ); |
231 |
248 |
232 openAction = menu->addAction(hbTrId("txt_common_menu_open")); |
249 HbAction* openAction = menu->addAction(hbTrId("txt_common_menu_open")); |
|
250 openAction->setData( data ); |
233 |
251 |
234 if (id != favoriteGrpId) |
252 if (id != favoriteGrpId) |
235 { |
253 { |
236 deleteAction = menu->addAction(hbTrId("txt_phob_menu_delete_group")); |
254 HbAction* deleteAction = menu->addAction(hbTrId("txt_phob_menu_delete_group")); |
237 } |
255 deleteAction->setData( data ); |
238 |
256 } |
239 HbAction *selectedAction = menu->exec(coords); |
257 menu->open(this, SLOT(handleMenu(HbAction*))); |
240 |
258 |
241 if (selectedAction) |
259 } |
242 { |
260 } |
243 if (selectedAction == openAction) |
261 |
244 { |
262 void CntCollectionView::handleMenu(HbAction* action) |
245 openGroup(item->modelIndex()); |
263 { |
246 } |
264 int row = action->data().toInt(); |
247 else if (selectedAction == deleteAction) |
265 HbMenu *menuItem = static_cast<HbMenu*>(sender()); |
248 { |
266 QModelIndex index = mModel->index(row, 0); |
249 QContact groupContact = mViewManager->contactManager(SYMBIAN_BACKEND)->contact(id); |
267 |
250 deleteGroup(groupContact); |
268 int id = index.data(Qt::UserRole).toInt(); |
251 } |
269 |
252 } |
270 if ( action == menuItem->actions().first() ) |
253 menu->deleteLater(); |
271 { |
254 } |
272 openGroup(index); |
255 } |
273 } |
|
274 else if (action == menuItem->actions().at(1)) |
|
275 { |
|
276 |
|
277 QContact groupContact = getContactManager()->contact(id); |
|
278 deleteGroup(groupContact); |
|
279 } |
|
280 } |
|
281 |
|
282 |
256 |
283 |
257 void CntCollectionView::newGroup() |
284 void CntCollectionView::newGroup() |
258 { |
285 { |
259 QString mTextOfNewItem(""); |
286 HbInputDialog *popup = new HbInputDialog(); |
260 |
287 popup->setAttribute(Qt::WA_DeleteOnClose, true); |
261 HbInputDialog popup; |
288 |
262 |
289 popup->setPromptText(hbTrId("txt_phob_title_new_group_name")); |
263 HbGroupBox *headingLabel = new HbGroupBox(&popup); |
290 popup->setPrimaryAction(new HbAction(hbTrId("txt_phob_button_create"), popup)); |
264 headingLabel->setHeading("txt_phob_title_new_group_name"); |
291 popup->setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"), popup)); |
265 popup.setHeadingWidget(headingLabel); |
292 popup->setInputMode(HbInputDialog::TextInput); |
266 popup.setPrimaryAction(new HbAction(hbTrId("txt_phob_button_create"),&popup)); |
293 |
267 popup.setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"),&popup)); |
294 popup->open(this, SLOT(handleNewGroup(HbAction*))); |
268 popup.setInputMode(HbInputDialog::TextInput); |
295 } |
269 popup.setPromptText(""); |
296 |
270 popup.setBackgroundFaded(true); |
297 void CntCollectionView::handleNewGroup(HbAction* action) |
271 HbAction* action = popup.exec(); |
298 { |
272 QString text = popup.value().toString(); |
299 HbInputDialog *popup = static_cast<HbInputDialog*>(sender()); |
273 |
300 |
274 if (action == popup.primaryAction()) |
301 if (popup && action == popup->actions().first()) |
275 { |
302 { |
276 mTextOfNewItem = text; |
303 QString text = popup->value().toString(); |
277 |
304 |
278 QContact groupContact; |
305 mHandledContact = new QContact(); |
279 groupContact.setType(QContactType::TypeGroup); |
306 mHandledContact->setType(QContactType::TypeGroup); |
280 |
307 |
281 QContactName groupName; |
308 QContactName groupName; |
282 groupName.setCustomLabel(mTextOfNewItem); |
309 groupName.setCustomLabel(text); |
283 |
310 |
284 groupContact.saveDetail(&groupName); |
311 mHandledContact->saveDetail(&groupName); |
285 mViewManager->contactManager(SYMBIAN_BACKEND)->saveContact(&groupContact); |
312 getContactManager()->saveContact(mHandledContact); |
286 |
313 |
287 // call a dialog to display the contacts |
314 QContactDetailFilter filter; |
288 |
315 QList<QContactLocalId> contactsList = getContactManager()->contactIds(filter); |
289 CntGroupSelectionPopup *groupSelectionPopup = |
316 QSet<QContactLocalId> contactsSet = contactsList.toSet(); |
290 new CntGroupSelectionPopup(mViewManager->contactManager(SYMBIAN_BACKEND), &groupContact); |
317 |
291 groupSelectionPopup->populateListOfContact(); |
318 // Select some contact(s) to add to the group |
292 HbAction* action = groupSelectionPopup->exec(); |
319 QString groupNameCreated(mHandledContact->displayLabel()); |
293 if (action == groupSelectionPopup->primaryAction()) |
320 mFetchView->setDetails(HbParameterLengthLimiter(hbTrId("txt_phob_subtitle_1_group")).arg(groupNameCreated), |
294 { |
321 hbTrId("Save")); |
295 groupSelectionPopup->saveNewGroup(); |
322 mFetchView->displayContacts(CntFetchContacts::popup, |
296 |
323 HbAbstractItemView::MultiSelection, |
297 CntViewParameters viewParameters; |
324 contactsSet); |
298 viewParameters.insert(EViewId, groupMemberView); |
325 } |
299 QVariant var; |
326 } |
300 var.setValue(groupContact); |
327 |
301 viewParameters.insert(ESelectedContact, var); |
328 void CntCollectionView::handleNewGroupMembers() |
302 mViewManager->changeView(viewParameters); |
329 { |
303 |
330 mSelectedContactsSet = mFetchView->getSelectedContacts(); |
304 delete groupSelectionPopup; |
331 if ( !mFetchView->wasCanceled() && mSelectedContactsSet.size() ) { |
305 } |
332 saveNewGroup(mHandledContact); |
306 else if (action == groupSelectionPopup->secondaryAction()) |
333 |
307 { |
334 CntViewParameters viewParameters; |
308 delete groupSelectionPopup; |
335 viewParameters.insert(EViewId, groupMemberView); |
309 QString groupNameCreated(groupName.customLabel()); |
336 QVariant var; |
310 HbNotificationDialog::launchDialog(hbTrId("txt_phob_dpophead_new_group_1_created").arg(groupNameCreated)); |
337 var.setValue(*mHandledContact); |
311 //refresh the page |
338 viewParameters.insert(ESelectedContact, var); |
312 refreshDataModel(); |
339 mViewManager->changeView(viewParameters); |
313 mDeleteGroupsAction->setEnabled(true); |
340 } |
314 } |
341 |
315 |
342 QString groupNameCreated(mHandledContact->displayLabel()); |
316 } |
343 HbNotificationDialog::launchDialog(HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_new_group_1_created")).arg(groupNameCreated)); |
|
344 |
|
345 // Refresh the page |
|
346 refreshDataModel(); |
|
347 mDeleteGroupsAction->setEnabled(true); |
|
348 |
|
349 delete mHandledContact; |
|
350 mHandledContact = NULL; |
317 } |
351 } |
318 |
352 |
319 void CntCollectionView::refreshDataModel() |
353 void CntCollectionView::refreshDataModel() |
320 { |
354 { |
321 mListView->setModel(0); |
355 mListView->setModel(0); |
322 delete mModel; |
356 delete mModel; |
323 mModel = 0; |
357 mModel = 0; |
324 mModel = new CntCollectionListModel(mViewManager->contactManager(SYMBIAN_BACKEND), mExtensionManager, this); |
358 mModel = new CntCollectionListModel(getContactManager(), mExtensionManager, this); |
325 mListView->setModel(mModel); |
359 mListView->setModel(mModel); |
326 } |
360 } |
327 |
361 |
328 void CntCollectionView::deleteGroup(QContact group) |
362 void CntCollectionView::deleteGroup(QContact group) |
329 { |
363 { |
330 QString name = group.displayLabel(); |
364 mHandledContact = new QContact(group); |
331 |
365 QString name = mHandledContact->displayLabel(); |
332 HbMessageBox *note = new HbMessageBox(hbTrId("txt_phob_info_delete_1").arg(name), HbMessageBox::MessageTypeQuestion); |
366 |
333 note->setPrimaryAction(new HbAction(hbTrId("txt_phob_button_delete"), note)); |
367 HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_dialog_delete_1_group")).arg(name), this, SLOT(handleDeleteGroup(HbAction*)), |
334 note->setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"), note)); |
368 hbTrId("txt_phob_button_delete"), hbTrId("txt_common_button_cancel")); |
335 HbAction *selected = note->exec(); |
369 } |
336 if (selected == note->primaryAction()) |
370 |
337 { |
371 void CntCollectionView::handleDeleteGroup(HbAction* action) |
338 mViewManager->contactManager(SYMBIAN_BACKEND)->removeContact(group.localId()); |
372 { |
339 mModel->removeGroup(group.localId()); |
373 HbMessageBox *note = static_cast<HbMessageBox*>(sender()); |
|
374 |
|
375 if (note && action == note->actions().first()) |
|
376 { |
|
377 getContactManager()->removeContact(mHandledContact->localId()); |
|
378 mModel->removeGroup(mHandledContact->localId()); |
340 |
379 |
341 // disable delete group(s) button if only favorites group is present |
380 // disable delete group(s) button if only favorites group is present |
342 QContactDetailFilter groupFilter; |
381 QContactDetailFilter groupFilter; |
343 groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
382 groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
344 groupFilter.setValue(QLatin1String(QContactType::TypeGroup)); |
383 groupFilter.setValue(QLatin1String(QContactType::TypeGroup)); |
345 QList<QContactLocalId> groupContactIds = mViewManager->contactManager(SYMBIAN_BACKEND)->contactIds(groupFilter); |
384 QList<QContactLocalId> groupContactIds = getContactManager()->contactIds(groupFilter); |
346 if (groupContactIds.count() < 2) |
385 if (groupContactIds.count() < 2) |
347 { |
386 { |
348 mDeleteGroupsAction->setEnabled(false); |
387 mDeleteGroupsAction->setEnabled(false); |
349 } |
388 } |
350 } |
389 } |
351 delete note; |
390 |
|
391 delete mHandledContact; |
|
392 mHandledContact = NULL; |
352 } |
393 } |
353 |
394 |
354 void CntCollectionView::deleteGroups() |
395 void CntCollectionView::deleteGroups() |
355 { |
396 { |
356 // save the group here |
397 // save the group here |
357 CntGroupDeletePopup *groupDeletePopup = new CntGroupDeletePopup(mViewManager->contactManager(SYMBIAN_BACKEND)); |
398 CntGroupDeletePopup *groupDeletePopup = new CntGroupDeletePopup(getContactManager()); |
358 |
399 |
359 groupDeletePopup->populateListOfGroup(); |
400 groupDeletePopup->populateListOfGroup(); |
360 HbAction* action = groupDeletePopup->exec(); |
401 groupDeletePopup->open(this, SLOT(handleDeleteGroups(HbAction*))); |
361 if (action == groupDeletePopup->primaryAction()) |
402 |
362 { |
403 } |
363 groupDeletePopup->deleteGroup(); |
404 |
364 } |
405 void CntCollectionView::handleDeleteGroups(HbAction* action) |
365 |
406 { |
366 delete groupDeletePopup; |
407 CntGroupDeletePopup *groupDeletePopup = static_cast<CntGroupDeletePopup*>(sender()); |
367 //refresh the page |
408 |
368 refreshDataModel(); |
409 if (groupDeletePopup && action == groupDeletePopup->actions().first()) |
369 |
410 { |
370 // disable delete group(s) button if only favorites group is present |
411 QList<QContactLocalId> deletedList = groupDeletePopup->deleteGroup(); |
371 QContactDetailFilter groupFilter; |
412 foreach (QContactLocalId id, deletedList) |
372 groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
413 { |
373 groupFilter.setValue(QLatin1String(QContactType::TypeGroup)); |
414 mModel->removeGroup(id); |
374 QList<QContactLocalId> groupContactIds = mViewManager->contactManager(SYMBIAN_BACKEND)->contactIds(groupFilter); |
415 } |
375 if (groupContactIds.count() < 2) |
416 |
376 { |
417 // disable delete group(s) button if only favorites group is present |
377 mDeleteGroupsAction->setEnabled(false); |
418 QContactDetailFilter groupFilter; |
378 } |
419 groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
379 } |
420 groupFilter.setValue(QLatin1String(QContactType::TypeGroup)); |
|
421 QList<QContactLocalId> groupContactIds = getContactManager()->contactIds(groupFilter); |
|
422 if (groupContactIds.count() < 2) |
|
423 { |
|
424 mDeleteGroupsAction->setEnabled(false); |
|
425 } |
|
426 } |
|
427 } |
|
428 |
|
429 QContactManager* CntCollectionView::getContactManager() |
|
430 { |
|
431 if (!mViewManager) return NULL; |
|
432 |
|
433 return mViewManager->contactManager(SYMBIAN_BACKEND); |
|
434 } |
|
435 |
|
436 void CntCollectionView::saveNewGroup(QContact* aContact) |
|
437 { |
|
438 if (!aContact) return; |
|
439 |
|
440 // Save the relationship from the selection model of the member selection list |
|
441 QList<QContactLocalId> selectedList = mSelectedContactsSet.toList(); |
|
442 for (int i = 0; i < selectedList.size(); i++ ) { |
|
443 QContact contact = getContactManager()->contact(selectedList.at(i)); |
|
444 QContactRelationship relationship; |
|
445 relationship.setRelationshipType(QContactRelationship::HasMember); |
|
446 relationship.setFirst(aContact->id()); |
|
447 relationship.setSecond(contact.id()); |
|
448 |
|
449 // Save relationship |
|
450 getContactManager()->saveRelationship(&relationship); |
|
451 } |
|
452 } |
|
453 |
380 // EOF |
454 // EOF |