phonebookui/pbkcommonui/src/cntcollectionview.cpp
changeset 53 e6aff7b69165
parent 50 77bc263e1626
child 54 47627ab5d7a4
equal deleted inserted replaced
51:81c360d47083 53:e6aff7b69165
    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"
    59     mFindAction(NULL),
    59     mFindAction(NULL),
    60     mExtensionAction(NULL),
    60     mExtensionAction(NULL),
    61     mNewGroupAction(NULL),
    61     mNewGroupAction(NULL),
    62     mDeleteGroupsAction(NULL),
    62     mDeleteGroupsAction(NULL),
    63     mHandledContact(NULL),
    63     mHandledContact(NULL),
    64     mFetchView(NULL),
       
    65     mActionGroup(NULL)
    64     mActionGroup(NULL)
    66 {
    65 {
    67     bool ok = false;
    66     bool ok = false;
    68     mDocumentLoader.load(CNT_COLLECTIONVIEW_XML, &ok);
    67     mDocumentLoader.load(CNT_COLLECTIONVIEW_XML, &ok);
    69 
    68 
   109 {
   108 {
   110     mView->deleteLater();
   109     mView->deleteLater();
   111     
   110     
   112     delete mHandledContact;
   111     delete mHandledContact;
   113     mHandledContact = NULL;
   112     mHandledContact = NULL;
   114     
       
   115     delete mFetchView;
       
   116     mFetchView = NULL;
       
   117 }
   113 }
   118 
   114 
   119 /*!
   115 /*!
   120 Called when activating the view
   116 Called when activating the view
   121 */
   117 */
   188 Go back to previous view
   184 Go back to previous view
   189 */
   185 */
   190 void CntCollectionView::showNamesViewWithFinder()
   186 void CntCollectionView::showNamesViewWithFinder()
   191 {
   187 {
   192     CntViewParameters viewParameters;
   188     CntViewParameters viewParameters;
   193     viewParameters.insert(EFinder, "show");
   189     viewParameters.insert(EExtraAction, CNT_FIND_ACTION);
   194     mViewManager->back(viewParameters);
   190     mViewManager->back(viewParameters);
   195 }
   191 }
   196 
   192 
   197 /*!
   193 /*!
   198 Called after user clicked on the listview.
   194 Called after user clicked on the listview.
   232                 mViewManager->changeView(viewParameters);
   228                 mViewManager->changeView(viewParameters);
   233             }
   229             }
   234             else
   230             else
   235             {
   231             {
   236                 CntViewParameters viewParameters;
   232                 CntViewParameters viewParameters;
   237                 viewParameters.insert(EViewId, FavoritesMemberView);
   233                 viewParameters.insert(EViewId, favoritesMemberView);
   238                 QVariant var;
   234                 QVariant var;
   239                 var.setValue(favoriteGroup);
   235                 var.setValue(favoriteGroup);
   240                 viewParameters.insert(ESelectedGroupContact, var);
   236                 viewParameters.insert(ESelectedGroupContact, var);
   241                 mViewManager->changeView(viewParameters);
   237                 mViewManager->changeView(viewParameters);
   242             }
   238             }
   352         if (groupNameCreated.isEmpty())
   348         if (groupNameCreated.isEmpty())
   353         {
   349         {
   354             groupNameCreated = hbTrId("txt_phob_list_unnamed");
   350             groupNameCreated = hbTrId("txt_phob_list_unnamed");
   355         }
   351         }
   356         
   352         
   357         if (!mFetchView)
   353         CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup(
   358         {
   354                 HbParameterLengthLimiter(hbTrId("txt_phob_title_members_of_1_group")).arg(groupNameCreated),
   359             mFetchView = new CntFetchContacts(*mViewManager->contactManager( SYMBIAN_BACKEND ));
   355                 hbTrId("txt_common_button_save"),
   360             connect(mFetchView, SIGNAL(clicked()), this, SLOT(handleNewGroupMembers()));
   356                 *mViewManager->contactManager(SYMBIAN_BACKEND));
   361         }
   357         connect( popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), this, SLOT(handleNewGroupMembers(QSet<QContactLocalId>)) );
   362         mFetchView->setDetails(HbParameterLengthLimiter(hbTrId("txt_phob_title_members_of_1_group")).arg(groupNameCreated),
   358         connect( popup, SIGNAL(fetchCancelled()), this, SLOT(handleCancelGroupMembers()) );
   363                                hbTrId("txt_common_button_save"));
   359         
   364         mFetchView->displayContacts(HbAbstractItemView::MultiSelection, contactsSet);
   360         popup->setSelectedContacts( contactsSet );
   365     }
   361         popup->showPopup();
   366 }
   362     }
   367 
   363 }
   368 void CntCollectionView::handleNewGroupMembers()
   364 
   369 {
   365 void CntCollectionView::handleNewGroupMembers( QSet<QContactLocalId> aIds )
   370     mSelectedContactsSet = mFetchView->getSelectedContacts();
   366 {
   371     
   367     mSelectedContactsSet = aIds;
   372     if ( !mFetchView->wasCanceled() && mSelectedContactsSet.size() ) {
   368 
       
   369     if ( aIds.size() > 0 )
       
   370     {
   373         saveNewGroup(mHandledContact);
   371         saveNewGroup(mHandledContact);
   374         
   372         
   375         delete mFetchView;
       
   376         mFetchView = NULL;
       
   377 
       
   378         CntViewParameters viewParameters;
   373         CntViewParameters viewParameters;
   379         viewParameters.insert(EViewId, groupMemberView);
   374         viewParameters.insert(EViewId, groupMemberView);
       
   375         
   380         QVariant var;
   376         QVariant var;
   381         var.setValue(*mHandledContact);
   377         var.setValue(*mHandledContact);
   382         viewParameters.insert(ESelectedGroupContact, var);
   378         viewParameters.insert(ESelectedGroupContact, var);
   383         mViewManager->changeView(viewParameters);
   379         mViewManager->changeView(viewParameters);
   384     }
   380     }
   385     else
   381     else
   386     {
   382     {
   387         // Add the new group 
       
   388         mModel->addGroup(mHandledContact->localId());
   383         mModel->addGroup(mHandledContact->localId());
   389         mDeleteGroupsAction->setEnabled(true);
   384         mDeleteGroupsAction->setEnabled(true);
   390         
   385     }
   391         delete mFetchView;
   386     notifyNewGroup();
   392         mFetchView = NULL;
   387 }
   393     }
   388 
   394     
   389 void CntCollectionView::handleCancelGroupMembers()
       
   390 {
       
   391     mSelectedContactsSet.clear();
       
   392     mModel->addGroup(mHandledContact->localId());
       
   393     mDeleteGroupsAction->setEnabled(true);
       
   394     
       
   395     notifyNewGroup();
       
   396 }
       
   397 
       
   398 void CntCollectionView::notifyNewGroup()
       
   399 {
   395     QString groupNameCreated = mHandledContact->displayLabel();
   400     QString groupNameCreated = mHandledContact->displayLabel();
   396     if (groupNameCreated.isEmpty())
   401     if (groupNameCreated.isEmpty())
   397     {
   402     {
   398         groupNameCreated = hbTrId("txt_phob_list_unnamed");
   403         groupNameCreated = hbTrId("txt_phob_list_unnamed");
   399     }
   404     }
   404 }
   409 }
   405 
   410 
   406 void CntCollectionView::refreshDataModel()
   411 void CntCollectionView::refreshDataModel()
   407 {
   412 {
   408     mListView->setModel(0);
   413     mListView->setModel(0);
       
   414     
   409     delete mModel;
   415     delete mModel;
   410     mModel = 0;
   416     mModel = NULL;
       
   417     
   411     mModel = new CntCollectionListModel(getContactManager(), mExtensionManager, this);
   418     mModel = new CntCollectionListModel(getContactManager(), mExtensionManager, this);
   412     mListView->setModel(mModel);
   419     mListView->setModel(mModel);
   413 }
   420 }
   414 
   421 
   415 void CntCollectionView::deleteGroup(QContact group)
   422 void CntCollectionView::deleteGroup(QContact group)