14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "cntcollectionview.h" |
18 #include "cntcollectionview.h" |
19 #include "cntfetchcontactsview.h" |
19 #include "cntfetchcontactpopup.h" |
20 #include "cntgroupdeletepopup.h" |
20 #include "cntgroupdeletepopup.h" |
21 #include "cntcollectionlistmodel.h" |
21 #include "cntcollectionlistmodel.h" |
22 #include "cntextensionmanager.h" |
22 #include "cntextensionmanager.h" |
23 #include "cntglobal.h" |
23 #include "cntglobal.h" |
24 #include "cntfavourite.h" |
24 #include "cntfavourite.h" |
|
25 #include "cntdetailconst.h" |
25 #include "cntdebug.h" |
26 #include "cntdebug.h" |
26 |
27 |
27 #include <cntuiextensionfactory.h> |
28 #include <cntuiextensionfactory.h> |
28 #include <cntuigroupsupplier.h> |
29 #include <cntuigroupsupplier.h> |
29 #include <hblabel.h> |
30 #include <hblabel.h> |
30 #include <hblistview.h> |
31 #include <hblistview.h> |
31 #include <hblistviewitem.h> |
32 #include <hblistviewitem.h> |
32 #include <hbmenu.h> |
33 #include <hbmenu.h> |
33 #include <hbnotificationdialog.h> |
34 #include <hbdevicenotificationdialog.h> |
34 #include <hbinputdialog.h> |
35 #include <hbinputdialog.h> |
35 #include <hbdialog.h> |
36 #include <hbdialog.h> |
36 #include <hbaction.h> |
37 #include <hbaction.h> |
37 #include <hbview.h> |
38 #include <hbview.h> |
38 #include <hbframebackground.h> |
39 #include <hbframebackground.h> |
39 #include <hbgroupbox.h> |
40 #include <hbgroupbox.h> |
40 #include <hbmessagebox.h> |
41 #include <hbmessagebox.h> |
41 #include <hbparameterlengthlimiter.h> |
42 #include <hbparameterlengthlimiter.h> |
42 |
43 |
43 #include <QActionGroup> |
44 #include <QActionGroup> |
|
45 #include <QApplication> |
44 #include <QList> |
46 #include <QList> |
45 |
47 |
46 const char *CNT_COLLECTIONVIEW_XML = ":/xml/contacts_collections.docml"; |
48 const char *CNT_COLLECTIONVIEW_XML = ":/xml/contacts_collections.docml"; |
47 |
49 |
48 /*! |
50 /*! |
341 QContactDetailFilter filter; |
347 QContactDetailFilter filter; |
342 QList<QContactLocalId> contactsList = getContactManager()->contactIds(filter); |
348 QList<QContactLocalId> contactsList = getContactManager()->contactIds(filter); |
343 QSet<QContactLocalId> contactsSet = contactsList.toSet(); |
349 QSet<QContactLocalId> contactsSet = contactsList.toSet(); |
344 |
350 |
345 // Select some contact(s) to add to the group |
351 // Select some contact(s) to add to the group |
346 QString groupNameCreated(mHandledContact->displayLabel()); |
352 QString groupNameCreated = mHandledContact->displayLabel(); |
347 mFetchView->setDetails(HbParameterLengthLimiter(hbTrId("txt_phob_title_members_of_1_group")).arg(groupNameCreated), |
353 if (groupNameCreated.isEmpty()) |
348 hbTrId("txt_common_button_save")); |
354 { |
349 mFetchView->displayContacts(HbAbstractItemView::MultiSelection, contactsSet); |
355 groupNameCreated = hbTrId("txt_phob_list_unnamed"); |
350 } |
356 } |
351 } |
357 |
352 |
358 CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup( |
353 void CntCollectionView::handleNewGroupMembers() |
359 HbParameterLengthLimiter(hbTrId("txt_phob_title_members_of_1_group")).arg(groupNameCreated), |
354 { |
360 hbTrId("txt_common_button_save"), |
355 mSelectedContactsSet = mFetchView->getSelectedContacts(); |
361 *mViewManager->contactManager(SYMBIAN_BACKEND)); |
356 if ( !mFetchView->wasCanceled() && mSelectedContactsSet.size() ) { |
362 connect( popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), this, SLOT(handleNewGroupMembers(QSet<QContactLocalId>)) ); |
|
363 connect( popup, SIGNAL(fetchCancelled()), this, SLOT(handleCancelGroupMembers()) ); |
|
364 |
|
365 popup->setSelectedContacts( contactsSet ); |
|
366 popup->showPopup(); |
|
367 } |
|
368 } |
|
369 |
|
370 void CntCollectionView::handleNewGroupMembers( QSet<QContactLocalId> aIds ) |
|
371 { |
|
372 mSelectedContactsSet = aIds; |
|
373 |
|
374 if ( aIds.size() > 0 ) |
|
375 { |
357 saveNewGroup(mHandledContact); |
376 saveNewGroup(mHandledContact); |
358 |
377 |
359 CntViewParameters viewParameters; |
378 CntViewParameters viewParameters; |
360 viewParameters.insert(EViewId, groupMemberView); |
379 viewParameters.insert(EViewId, groupMemberView); |
|
380 |
361 QVariant var; |
381 QVariant var; |
362 var.setValue(*mHandledContact); |
382 var.setValue(*mHandledContact); |
363 viewParameters.insert(ESelectedGroupContact, var); |
383 viewParameters.insert(ESelectedGroupContact, var); |
364 mViewManager->changeView(viewParameters); |
384 mViewManager->changeView(viewParameters); |
365 } |
385 } |
366 |
386 else |
367 QString groupNameCreated(mHandledContact->displayLabel()); |
387 { |
368 HbNotificationDialog::launchDialog(HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_new_group_1_created")).arg(groupNameCreated)); |
388 mModel->addGroup(mHandledContact->localId()); |
369 |
389 mDeleteGroupsAction->setEnabled(true); |
370 // Refresh the page |
390 } |
371 refreshDataModel(); |
391 notifyNewGroup(); |
|
392 } |
|
393 |
|
394 void CntCollectionView::handleCancelGroupMembers() |
|
395 { |
|
396 mSelectedContactsSet.clear(); |
|
397 mModel->addGroup(mHandledContact->localId()); |
372 mDeleteGroupsAction->setEnabled(true); |
398 mDeleteGroupsAction->setEnabled(true); |
373 |
399 |
374 delete mHandledContact; |
400 notifyNewGroup(); |
375 mHandledContact = NULL; |
401 } |
|
402 |
|
403 void CntCollectionView::notifyNewGroup() |
|
404 { |
|
405 if (mHandledContact != NULL) |
|
406 { |
|
407 QString groupNameCreated = mHandledContact->displayLabel(); |
|
408 if (groupNameCreated.isEmpty()) |
|
409 { |
|
410 groupNameCreated = hbTrId("txt_phob_list_unnamed"); |
|
411 } |
|
412 HbDeviceNotificationDialog::notification(QString(), |
|
413 HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_new_group_1_created")).arg(groupNameCreated)); |
|
414 |
|
415 delete mHandledContact; |
|
416 mHandledContact = NULL; |
|
417 } |
376 } |
418 } |
377 |
419 |
378 void CntCollectionView::refreshDataModel() |
420 void CntCollectionView::refreshDataModel() |
379 { |
421 { |
380 mListView->setModel(0); |
422 mListView->setModel(0); |
|
423 |
381 delete mModel; |
424 delete mModel; |
382 mModel = 0; |
425 mModel = NULL; |
|
426 |
383 mModel = new CntCollectionListModel(getContactManager(), mExtensionManager, this); |
427 mModel = new CntCollectionListModel(getContactManager(), mExtensionManager, this); |
384 mListView->setModel(mModel); |
428 mListView->setModel(mModel); |
385 } |
429 } |
386 |
430 |
387 void CntCollectionView::deleteGroup(QContact group) |
431 void CntCollectionView::deleteGroup(QContact group) |
388 { |
432 { |
389 mHandledContact = new QContact(group); |
433 mHandledContact = new QContact(group); |
390 QString name = mHandledContact->displayLabel(); |
434 QString name = mHandledContact->displayLabel(); |
|
435 if (name.isEmpty()) |
|
436 { |
|
437 name = hbTrId("txt_phob_list_unnamed"); |
|
438 } |
391 |
439 |
392 HbLabel *headingLabel = new HbLabel(); |
440 HbLabel *headingLabel = new HbLabel(); |
393 headingLabel->setPlainText(HbParameterLengthLimiter(hbTrId("txt_phob_dialog_delete_1_group")).arg(name)); |
441 headingLabel->setPlainText(HbParameterLengthLimiter(hbTrId("txt_phob_dialog_delete_1_group")).arg(name)); |
394 |
442 |
395 HbMessageBox::question(hbTrId("txt_phob_dialog_only_group_will_be_removed_contac") |
443 HbMessageBox::question(hbTrId("txt_phob_dialog_only_group_will_be_removed_contac") |
396 , this, SLOT(handleDeleteGroup(HbAction*)), |
444 , this, SLOT(handleDeleteGroup(int)), HbMessageBox::Delete | HbMessageBox::Cancel, |
397 hbTrId("txt_common_button_delete"), hbTrId("txt_common_button_cancel"), headingLabel); |
445 headingLabel); |
398 } |
446 } |
399 |
447 |
400 void CntCollectionView::handleDeleteGroup(HbAction* action) |
448 void CntCollectionView::handleDeleteGroup(int action) |
401 { |
449 { |
402 HbMessageBox *note = static_cast<HbMessageBox*>(sender()); |
450 if (action == HbMessageBox::Delete) |
403 |
|
404 if (note && action == note->actions().first()) |
|
405 { |
451 { |
406 getContactManager()->removeContact(mHandledContact->localId()); |
452 getContactManager()->removeContact(mHandledContact->localId()); |
407 mModel->removeGroup(mHandledContact->localId()); |
453 mModel->removeGroup(mHandledContact->localId()); |
408 |
454 |
409 // disable delete group(s) button if only favorites group is present |
455 // disable delete group(s) button if only favorites group is present |