phonebookui/pbkcommonui/src/cntcollectionview.cpp
changeset 59 a642906a277a
parent 47 7cbcb2896f0e
child 65 ae724a111993
equal deleted inserted replaced
47:7cbcb2896f0e 59:a642906a277a
    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 /*!
    59     mFindAction(NULL),
    61     mFindAction(NULL),
    60     mExtensionAction(NULL),
    62     mExtensionAction(NULL),
    61     mNewGroupAction(NULL),
    63     mNewGroupAction(NULL),
    62     mDeleteGroupsAction(NULL),
    64     mDeleteGroupsAction(NULL),
    63     mHandledContact(NULL),
    65     mHandledContact(NULL),
    64     mFetchView(NULL),
       
    65     mActionGroup(NULL)
    66     mActionGroup(NULL)
    66 {
    67 {
    67     bool ok = false;
    68     bool ok = false;
    68     mDocumentLoader.load(CNT_COLLECTIONVIEW_XML, &ok);
    69     mDocumentLoader.load(CNT_COLLECTIONVIEW_XML, &ok);
    69 
    70 
    96     groups->setActionGroup(mActionGroup);
    97     groups->setActionGroup(mActionGroup);
    97     mNamesAction->setActionGroup(mActionGroup);
    98     mNamesAction->setActionGroup(mActionGroup);
    98     groups->setChecked(true);
    99     groups->setChecked(true);
    99     
   100     
   100     mFindAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:find"));
   101     mFindAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:find"));
   101     mFindAction->setEnabled(false);
   102     connect(mFindAction, SIGNAL(triggered()), this, SLOT(showNamesViewWithFinder()));
   102     mExtensionAction = static_cast<HbAction*> (mDocumentLoader.findObject("cnt:activity"));
   103     mExtensionAction = static_cast<HbAction*> (mDocumentLoader.findObject("cnt:activity"));
       
   104     
       
   105     connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(notifyNewGroup()));
   103 }
   106 }
   104 
   107 
   105 /*!
   108 /*!
   106 
   109 
   107 */
   110 */
   109 {
   112 {
   110     mView->deleteLater();
   113     mView->deleteLater();
   111     
   114     
   112     delete mHandledContact;
   115     delete mHandledContact;
   113     mHandledContact = NULL;
   116     mHandledContact = NULL;
   114     
       
   115     delete mFetchView;
       
   116     mFetchView = NULL;
       
   117 }
   117 }
   118 
   118 
   119 /*!
   119 /*!
   120 Called when activating the view
   120 Called when activating the view
   121 */
   121 */
   157     mListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon);
   157     mListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon);
   158     mListView->listItemPrototype()->setStretchingStyle(HbListViewItem::StretchLandscape);
   158     mListView->listItemPrototype()->setStretchingStyle(HbListViewItem::StretchLandscape);
   159     mModel = new CntCollectionListModel(getContactManager(), mExtensionManager, this);
   159     mModel = new CntCollectionListModel(getContactManager(), mExtensionManager, this);
   160     mListView->setModel(mModel);
   160     mListView->setModel(mModel);
   161     
   161     
   162     mFetchView = new CntFetchContacts(*mViewManager->contactManager( SYMBIAN_BACKEND ));
       
   163     connect(mFetchView, SIGNAL(clicked()), this, SLOT(handleNewGroupMembers()));
       
   164     
       
   165     CNT_EXIT
   162     CNT_EXIT
   166 }
   163 }
   167 
   164 
   168 void CntCollectionView::deactivate()
   165 void CntCollectionView::deactivate()
   169 {
   166 {
   182 Go back to previous view
   179 Go back to previous view
   183 */
   180 */
   184 void CntCollectionView::showPreviousView()
   181 void CntCollectionView::showPreviousView()
   185 {
   182 {
   186     CntViewParameters viewParameters;
   183     CntViewParameters viewParameters;
       
   184     mViewManager->back(viewParameters);
       
   185 }
       
   186 
       
   187 /*!
       
   188 Go back to previous view
       
   189 */
       
   190 void CntCollectionView::showNamesViewWithFinder()
       
   191 {
       
   192     CntViewParameters viewParameters;
       
   193     viewParameters.insert(EExtraAction, CNT_FIND_ACTION);
   187     mViewManager->back(viewParameters);
   194     mViewManager->back(viewParameters);
   188 }
   195 }
   189 
   196 
   190 /*!
   197 /*!
   191 Called after user clicked on the listview.
   198 Called after user clicked on the listview.
   225                 mViewManager->changeView(viewParameters);
   232                 mViewManager->changeView(viewParameters);
   226             }
   233             }
   227             else
   234             else
   228             {
   235             {
   229                 CntViewParameters viewParameters;
   236                 CntViewParameters viewParameters;
   230                 viewParameters.insert(EViewId, FavoritesMemberView);
   237                 viewParameters.insert(EViewId, favoritesMemberView);
   231                 QVariant var;
   238                 QVariant var;
   232                 var.setValue(favoriteGroup);
   239                 var.setValue(favoriteGroup);
   233                 viewParameters.insert(ESelectedGroupContact, var);
   240                 viewParameters.insert(ESelectedGroupContact, var);
   234                 mViewManager->changeView(viewParameters);
   241                 mViewManager->changeView(viewParameters);
   235             }
   242             }
   255         mModel->extensionGroupLongPressed(item->modelIndex().row(), coords, this);
   262         mModel->extensionGroupLongPressed(item->modelIndex().row(), coords, this);
   256     }
   263     }
   257     else
   264     else
   258     {
   265     {
   259         int id = item->modelIndex().data(Qt::UserRole).toInt();
   266         int id = item->modelIndex().data(Qt::UserRole).toInt();
   260         QVariant data( item->modelIndex().row() );
   267         QVariant data( id );
   261 
   268 
   262         int favoriteGrpId = CntFavourite::favouriteGroupId(mViewManager->contactManager(SYMBIAN_BACKEND));
   269         int favoriteGrpId = CntFavourite::favouriteGroupId(mViewManager->contactManager(SYMBIAN_BACKEND));
   263         
   270         
   264         HbMenu *menu = new HbMenu();
   271         HbMenu *menu = new HbMenu();
   265         menu->setAttribute(Qt::WA_DeleteOnClose);
   272         menu->setAttribute(Qt::WA_DeleteOnClose);
   278     }
   285     }
   279 }
   286 }
   280 
   287 
   281 void CntCollectionView::handleMenu(HbAction* action)
   288 void CntCollectionView::handleMenu(HbAction* action)
   282 {
   289 {
   283     int row = action->data().toInt();
       
   284     HbMenu *menuItem = static_cast<HbMenu*>(sender());
   290     HbMenu *menuItem = static_cast<HbMenu*>(sender());
   285     QModelIndex index = mModel->index(row, 0);
       
   286     
       
   287     int id = index.data(Qt::UserRole).toInt();
       
   288     
   291     
   289     if ( action == menuItem->actions().first() )
   292     if ( action == menuItem->actions().first() )
   290         {
   293     {
       
   294         int id = action->data().toInt();
       
   295         QModelIndex index = mModel->indexOfGroup(id);
   291         openGroup(index);
   296         openGroup(index);
   292         }
   297     }
   293     else if (action == menuItem->actions().at(1))
   298     else if (action == menuItem->actions().at(1))
   294         {
   299     {
   295         
   300         int id = action->data().toInt();
   296         QContact groupContact = getContactManager()->contact(id);
   301         QContact groupContact = getContactManager()->contact(id);
   297         deleteGroup(groupContact);
   302         deleteGroup(groupContact);
   298         }
   303     }
   299 }
   304 }
   300 
   305 
   301 
   306 
   302 
   307 
   303 void CntCollectionView::newGroup()
   308 void CntCollectionView::newGroup()
   305     HbInputDialog *popup = new HbInputDialog();
   310     HbInputDialog *popup = new HbInputDialog();
   306     popup->setAttribute(Qt::WA_DeleteOnClose, true);
   311     popup->setAttribute(Qt::WA_DeleteOnClose, true);
   307     
   312     
   308     HbLineEdit *lineEdit = popup->lineEdit();
   313     HbLineEdit *lineEdit = popup->lineEdit();
   309     lineEdit->setInputMethodHints(Qt::ImhNoPredictiveText);
   314     lineEdit->setInputMethodHints(Qt::ImhNoPredictiveText);
       
   315     lineEdit->setMaxLength( CNT_GROUPNAME_MAXLENGTH );
   310     
   316     
   311     popup->setPromptText(hbTrId("txt_phob_title_new_group_name"));
   317     popup->setPromptText(hbTrId("txt_phob_title_new_group_name"));
   312     popup->clearActions();
   318     popup->clearActions();
   313     HbAction* primaryAction = new HbAction(hbTrId("txt_phob_button_create"));
   319     HbAction* primaryAction = new HbAction(hbTrId("txt_phob_button_create"));
   314     popup->addAction(primaryAction);
   320     popup->addAction(primaryAction);
   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