phonebookui/pbkcommonui/src/cntcollectionview.cpp
changeset 65 ae724a111993
parent 59 a642906a277a
child 71 7cc7d74059f9
equal deleted inserted replaced
59:a642906a277a 65:ae724a111993
    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 "cntdetailconst.h"
    26 #include "cntdebug.h"
    26 #include "cntdebug.h"
    27 
       
    28 #include <cntuiextensionfactory.h>
    27 #include <cntuiextensionfactory.h>
    29 #include <cntuigroupsupplier.h>
    28 #include <cntuigroupsupplier.h>
    30 #include <hblabel.h>
    29 #include <hblabel.h>
    31 #include <hblistview.h>
    30 #include <hblistview.h>
    32 #include <hblistviewitem.h>
    31 #include <hblistviewitem.h>
    48 const char *CNT_COLLECTIONVIEW_XML = ":/xml/contacts_collections.docml";
    47 const char *CNT_COLLECTIONVIEW_XML = ":/xml/contacts_collections.docml";
    49 
    48 
    50 /*!
    49 /*!
    51 
    50 
    52 */
    51 */
    53 CntCollectionView::CntCollectionView(CntExtensionManager &extensionManager) :
    52 CntCollectionView::CntCollectionView() :
    54     mExtensionManager(extensionManager),
       
    55     mView(NULL),
    53     mView(NULL),
    56     mSoftkey(NULL),
    54     mSoftkey(NULL),
    57     mViewManager(NULL),
    55     mViewManager(NULL),
    58     mModel(NULL),
    56     mModel(NULL),
    59     mListView(NULL),
    57     mListView(NULL),
   117 }
   115 }
   118 
   116 
   119 /*!
   117 /*!
   120 Called when activating the view
   118 Called when activating the view
   121 */
   119 */
   122 void CntCollectionView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs )
   120 void CntCollectionView::activate( const CntViewParameters aArgs )
   123 {
   121 {
   124     CNT_ENTRY
   122     CNT_ENTRY
   125     
   123     
   126     Q_UNUSED(aArgs)
   124     Q_UNUSED(aArgs)
   127     
   125     
   128     if (mView->navigationAction() != mSoftkey)
   126     if (mView->navigationAction() != mSoftkey)
   129         mView->setNavigationAction(mSoftkey);   
   127         mView->setNavigationAction(mSoftkey);   
   130     
   128     
   131     mViewManager = aMgr;
   129     mViewManager = &mEngine->viewManager();
   132 
   130     mExtensionManager = &mEngine->extensionManager();
       
   131     
   133     // disable delete group(s) button if only favorites group is present
   132     // disable delete group(s) button if only favorites group is present
   134     QContactDetailFilter groupFilter;
   133     QContactDetailFilter groupFilter;
   135     groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
   134     groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
   136     groupFilter.setValue(QLatin1String(QContactType::TypeGroup));
   135     groupFilter.setValue(QLatin1String(QContactType::TypeGroup));
   137     QList<QContactLocalId> groupContactIds = getContactManager()->contactIds(groupFilter);
   136     QList<QContactLocalId> groupContactIds = getContactManager()->contactIds(groupFilter);
   154     frame.setFrameType(HbFrameDrawer::NinePieces);
   153     frame.setFrameType(HbFrameDrawer::NinePieces);
   155     mListView->itemPrototypes().first()->setDefaultFrame(frame);
   154     mListView->itemPrototypes().first()->setDefaultFrame(frame);
   156     
   155     
   157     mListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon);
   156     mListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon);
   158     mListView->listItemPrototype()->setStretchingStyle(HbListViewItem::StretchLandscape);
   157     mListView->listItemPrototype()->setStretchingStyle(HbListViewItem::StretchLandscape);
   159     mModel = new CntCollectionListModel(getContactManager(), mExtensionManager, this);
   158     mModel = new CntCollectionListModel( mEngine, this);
   160     mListView->setModel(mModel);
   159     mListView->setModel(mModel);
   161     
   160     
   162     CNT_EXIT
   161     CNT_EXIT
   163 }
   162 }
   164 
   163 
   208         }
   207         }
   209     }
   208     }
   210     else
   209     else
   211     {
   210     {
   212         int id = index.data(Qt::UserRole).toInt();
   211         int id = index.data(Qt::UserRole).toInt();
   213         int favoriteGrpId = CntFavourite::favouriteGroupId(mViewManager->contactManager(SYMBIAN_BACKEND));
   212         int favoriteGrpId = CntFavourite::favouriteGroupId(getContactManager());
   214 
   213 
   215         if (id == favoriteGrpId )
   214         if (id == favoriteGrpId )
   216         {
   215         {
   217             QContact favoriteGroup = getContactManager()->contact(favoriteGrpId);
   216             QContact favoriteGroup = getContactManager()->contact(favoriteGrpId);
   218             QContactRelationshipFilter rFilter;
   217             QContactRelationshipFilter rFilter;
   264     else
   263     else
   265     {
   264     {
   266         int id = item->modelIndex().data(Qt::UserRole).toInt();
   265         int id = item->modelIndex().data(Qt::UserRole).toInt();
   267         QVariant data( id );
   266         QVariant data( id );
   268 
   267 
   269         int favoriteGrpId = CntFavourite::favouriteGroupId(mViewManager->contactManager(SYMBIAN_BACKEND));
   268         int favoriteGrpId = CntFavourite::favouriteGroupId(getContactManager());
   270         
   269         
   271         HbMenu *menu = new HbMenu();
   270         HbMenu *menu = new HbMenu();
   272         menu->setAttribute(Qt::WA_DeleteOnClose);
   271         menu->setAttribute(Qt::WA_DeleteOnClose);
   273         menu->setPreferredPos( coords );
   272         menu->setPreferredPos( coords );
   274         
   273         
   342         groupName.setCustomLabel(text);
   341         groupName.setCustomLabel(text);
   343         
   342         
   344         mHandledContact->saveDetail(&groupName);
   343         mHandledContact->saveDetail(&groupName);
   345         getContactManager()->saveContact(mHandledContact);
   344         getContactManager()->saveContact(mHandledContact);
   346         
   345         
   347         QContactDetailFilter filter;
       
   348         QList<QContactLocalId> contactsList = getContactManager()->contactIds(filter);
       
   349         QSet<QContactLocalId> contactsSet = contactsList.toSet();
       
   350 
       
   351         // Select some contact(s) to add to the group
   346         // Select some contact(s) to add to the group
   352         QString groupNameCreated = mHandledContact->displayLabel();
   347         QString groupNameCreated = mHandledContact->displayLabel();
   353         if (groupNameCreated.isEmpty())
   348         if (groupNameCreated.isEmpty())
   354         {
   349         {
   355             groupNameCreated = hbTrId("txt_phob_list_unnamed");
   350             groupNameCreated = hbTrId("txt_phob_list_unnamed");
   356         }
   351         }
   357         
   352         
   358         CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup(
   353         // if no contacts are present, then dont call the fetch popup
   359                 HbParameterLengthLimiter(hbTrId("txt_phob_title_members_of_1_group")).arg(groupNameCreated),
   354        QContactDetailFilter gFilter;
   360                 hbTrId("txt_common_button_save"),
   355        gFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
   361                 *mViewManager->contactManager(SYMBIAN_BACKEND));
   356        gFilter.setValue(QLatin1String(QContactType::TypeContact));
   362         connect( popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), this, SLOT(handleNewGroupMembers(QSet<QContactLocalId>)) );
   357       
   363         connect( popup, SIGNAL(fetchCancelled()), this, SLOT(handleCancelGroupMembers()) );
   358        QList<QContactLocalId> contactIds = getContactManager()->contactIds(gFilter);   
   364         
   359        if (contactIds.isEmpty())
   365         popup->setSelectedContacts( contactsSet );
   360        {
   366         popup->showPopup();
   361            mModel->addGroup(mHandledContact->localId());
       
   362            mDeleteGroupsAction->setEnabled(true);
       
   363                
       
   364            notifyNewGroup();
       
   365        }      
       
   366        else
       
   367        {
       
   368             CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup(
       
   369                     HbParameterLengthLimiter(hbTrId("txt_phob_title_members_of_1_group")).arg(groupNameCreated),
       
   370                     hbTrId("txt_common_button_save"),
       
   371                     mEngine->contactManager(SYMBIAN_BACKEND));
       
   372             connect( popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), this, SLOT(handleNewGroupMembers(QSet<QContactLocalId>)) );
       
   373             connect( popup, SIGNAL(fetchCancelled()), this, SLOT(handleCancelGroupMembers()) );
       
   374             
       
   375             QSet<QContactLocalId> ids;
       
   376             popup->setSelectedContacts(ids);
       
   377             popup->showPopup();
       
   378        }
   367     }
   379     }
   368 }
   380 }
   369 
   381 
   370 void CntCollectionView::handleNewGroupMembers( QSet<QContactLocalId> aIds )
   382 void CntCollectionView::handleNewGroupMembers( QSet<QContactLocalId> aIds )
   371 {
   383 {
   422     mListView->setModel(0);
   434     mListView->setModel(0);
   423     
   435     
   424     delete mModel;
   436     delete mModel;
   425     mModel = NULL;
   437     mModel = NULL;
   426     
   438     
   427     mModel = new CntCollectionListModel(getContactManager(), mExtensionManager, this);
   439     mModel = new CntCollectionListModel(mEngine, this);
   428     mListView->setModel(mModel);
   440     mListView->setModel(mModel);
   429 }
   441 }
   430 
   442 
   431 void CntCollectionView::deleteGroup(QContact group)
   443 void CntCollectionView::deleteGroup(QContact group)
   432 {
   444 {
   468 }
   480 }
   469 
   481 
   470 void CntCollectionView::deleteGroups()
   482 void CntCollectionView::deleteGroups()
   471 {
   483 {
   472     // save the group here
   484     // save the group here
   473     CntGroupDeletePopup *groupDeletePopup = new CntGroupDeletePopup(getContactManager());
   485     CntGroupDeletePopup *groupDeletePopup = new CntGroupDeletePopup( mEngine );
   474     
   486     
   475     groupDeletePopup->populateListOfGroup();
   487     groupDeletePopup->populateListOfGroup();
   476     groupDeletePopup->open(this, SLOT(handleDeleteGroups(HbAction*)));
   488     groupDeletePopup->open(this, SLOT(handleDeleteGroups(HbAction*)));
   477 
   489 
   478 }
   490 }
   501     }
   513     }
   502 }
   514 }
   503 
   515 
   504 QContactManager* CntCollectionView::getContactManager()
   516 QContactManager* CntCollectionView::getContactManager()
   505 {
   517 {
   506     if (!mViewManager) return NULL;
   518     if (!mEngine) {
   507 
   519         return NULL;
   508     return mViewManager->contactManager(SYMBIAN_BACKEND);
   520     }
   509 }
   521     return &mEngine->contactManager( SYMBIAN_BACKEND );
   510 
   522 }
   511 void CntCollectionView::saveNewGroup(QContact* aContact)
   523 
   512 {
   524 void CntCollectionView::saveNewGroup(QContact* aGroup)
   513     if (!aContact) return;
   525 {
       
   526     if (!aGroup) {
       
   527         return;
       
   528     }
   514     
   529     
   515     // Save the relationship from the selection model of the member selection list
   530     // Save the relationship from the selection model of the member selection list
   516     QList<QContactLocalId> selectedList = mSelectedContactsSet.toList();
   531     QList<QContactRelationship> relationships;
   517     for (int i = 0; i < selectedList.size(); i++ ) {
   532     foreach (QContactLocalId localId, mSelectedContactsSet)
   518         QContact contact = getContactManager()->contact(selectedList.at(i));
   533     {
   519         QContactRelationship relationship;
   534         QContactRelationship relationship;
       
   535         QContactId id;
       
   536         id.setLocalId(localId);
   520         relationship.setRelationshipType(QContactRelationship::HasMember);
   537         relationship.setRelationshipType(QContactRelationship::HasMember);
   521         relationship.setFirst(aContact->id());
   538         relationship.setFirst(aGroup->id());
   522         relationship.setSecond(contact.id());
   539         relationship.setSecond(id);
   523 
   540         relationships.append(relationship);
   524         // Save relationship
   541     }
   525         getContactManager()->saveRelationship(&relationship);
   542 
       
   543     // Save relationships
       
   544     if (!relationships.isEmpty()) {
       
   545         getContactManager()->saveRelationships(&relationships, NULL);
   526     }
   546     }
   527 }
   547 }
   528 
   548 
   529 // EOF
   549 // EOF