phonebookui/pbkcommonui/src/cntfavoritesmemberview.cpp
changeset 65 ae724a111993
parent 59 a642906a277a
equal deleted inserted replaced
59:a642906a277a 65:ae724a111993
    38 
    38 
    39 CntFavoritesMemberView::CntFavoritesMemberView() :
    39 CntFavoritesMemberView::CntFavoritesMemberView() :
    40     mContact(NULL),
    40     mContact(NULL),
    41     mModel(NULL),
    41     mModel(NULL),
    42     mFavoriteListView(NULL), 
    42     mFavoriteListView(NULL), 
    43     mViewManager(NULL),
    43     mViewManager(NULL)
    44     mFetchView(NULL)
       
    45 {
    44 {
    46     bool ok = false;
    45     bool ok = false;
    47     mDocumentLoader.load(CNT_FAVORITESMEMBERVIEW_XML, &ok);
    46     mDocumentLoader.load(CNT_FAVORITESMEMBERVIEW_XML, &ok);
    48   
    47   
    49     if (ok)
    48     if (ok)
    85 {
    84 {
    86     CntViewParameters viewParameters;
    85     CntViewParameters viewParameters;
    87     mViewManager->back(viewParameters);
    86     mViewManager->back(viewParameters);
    88 }
    87 }
    89 
    88 
    90 void CntFavoritesMemberView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs )
    89 void CntFavoritesMemberView::activate( const CntViewParameters aArgs )
    91 {
    90 {
    92     if (mView->navigationAction() != mSoftkey)
    91     if (mView->navigationAction() != mSoftkey)
    93         mView->setNavigationAction(mSoftkey);   
    92         mView->setNavigationAction(mSoftkey);   
    94     
    93     
    95     mContact = new QContact(aArgs.value(ESelectedGroupContact).value<QContact>());
    94     mContact = new QContact(aArgs.value(ESelectedGroupContact).value<QContact>());
    96     mViewManager = aMgr;
    95     mViewManager = &mEngine->viewManager();
    97 
    96 
    98     mFavoriteListView = static_cast<HbListView*> (mDocumentLoader.findWidget("listView"));
    97     mFavoriteListView = static_cast<HbListView*> (mDocumentLoader.findWidget("listView"));
    99     mFavoriteListView->setUniformItemSizes(true);
    98     mFavoriteListView->setUniformItemSizes(true);
   100     mFavoriteListView->setFrictionEnabled(true);
    99     mFavoriteListView->setFrictionEnabled(true);
   101     mFavoriteListView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
   100     mFavoriteListView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
   109     
   108     
   110     HbFrameBackground frame;
   109     HbFrameBackground frame;
   111     frame.setFrameGraphicsName("qtg_fr_list_normal");
   110     frame.setFrameGraphicsName("qtg_fr_list_normal");
   112     frame.setFrameType(HbFrameDrawer::NinePieces);
   111     frame.setFrameType(HbFrameDrawer::NinePieces);
   113     
   112     
   114     mFavoriteListView->itemPrototypes().first()->setDefaultFrame(frame);
   113     HbListViewItem* prototype = mFavoriteListView->listItemPrototype();
   115     mFavoriteListView->listItemPrototype()->setStretchingStyle(HbListViewItem::StretchLandscape);
   114     prototype->setDefaultFrame( frame );
   116     mFavoriteListView->listItemPrototype()->setGraphicsSize(HbListViewItem::Thumbnail);
   115     prototype->setStretchingStyle(HbListViewItem::StretchLandscape);
   117 
   116     prototype->setGraphicsSize(HbListViewItem::Thumbnail);
       
   117     
   118     if (!mModel)
   118     if (!mModel)
   119     {
   119     {
   120         createModel();
   120         createModel();
   121     }
   121     }
   122 
   122 
   135     membersFilter.setRelationshipType(QContactRelationship::HasMember);
   135     membersFilter.setRelationshipType(QContactRelationship::HasMember);
   136     membersFilter.setRelatedContactRole(QContactRelationship::First);
   136     membersFilter.setRelatedContactRole(QContactRelationship::First);
   137     membersFilter.setRelatedContactId(mContact->id());   
   137     membersFilter.setRelatedContactId(mContact->id());   
   138     mOriginalGroupMembers = getContactManager()->contactIds(membersFilter).toSet();
   138     mOriginalGroupMembers = getContactManager()->contactIds(membersFilter).toSet();
   139     
   139     
   140     /*
       
   141     if (!mFetchView) {
       
   142         mFetchView = new CntFetchContacts(*getContactManager());
       
   143         connect(mFetchView, SIGNAL(clicked()), this, SLOT(handleManageFavorites()));
       
   144     }
       
   145     mFetchView->setDetails(hbTrId("txt_phob_subtitle_favorites"), hbTrId("txt_common_button_save"));
       
   146     mFetchView->displayContacts(HbAbstractItemView::MultiSelection, mOriginalGroupMembers);
       
   147     */
       
   148     CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup(
   140     CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup(
   149             hbTrId("txt_phob_subtitle_favorites"), 
   141             hbTrId("txt_phob_subtitle_favorites"), 
   150             hbTrId("txt_common_button_save"),
   142             hbTrId("txt_common_button_save"),
   151             *getContactManager());
   143             *getContactManager());
   152     connect( popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), this, SLOT(handleManageFavorites(QSet<QContactLocalId>)) );
   144     connect( popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), this, SLOT(handleManageFavorites(QSet<QContactLocalId>)) );
   154     popup->showPopup();
   146     popup->showPopup();
   155 }
   147 }
   156 
   148 
   157 void CntFavoritesMemberView::handleManageFavorites(QSet<QContactLocalId> aIds)
   149 void CntFavoritesMemberView::handleManageFavorites(QSet<QContactLocalId> aIds)
   158 {
   150 {
   159 /*
       
   160     QSet<QContactLocalId> selectedContacts = mFetchView->getSelectedContacts();
       
   161     bool saveChanges = !mFetchView->wasCanceled();
       
   162 
       
   163     delete mFetchView;
       
   164     mFetchView = 0;
       
   165     
       
   166     if (!saveChanges) {
       
   167         return;
       
   168     }
       
   169 */
       
   170     for (int i = 0; i < 2; ++i) {
   151     for (int i = 0; i < 2; ++i) {
   171         // first iteration processes added members, second removed members
   152         // first iteration processes added members, second removed members
   172         QSet<QContactLocalId> members = (i == 0 ? aIds - mOriginalGroupMembers
   153         QSet<QContactLocalId> members = (i == 0 ? aIds - mOriginalGroupMembers
   173                                                 : mOriginalGroupMembers - aIds);
   154                                                 : mOriginalGroupMembers - aIds);
   174         QList<QContactRelationship> memberships;
   155         QList<QContactRelationship> memberships;
   175 
   156 
   176         foreach (QContactLocalId id, members) {
   157         foreach (QContactLocalId id, members) {
   177             QContact contact = getContactManager()->contact(id);
   158             QContactId contactId;
       
   159             contactId.setLocalId(id);
   178             QContactRelationship membership;
   160             QContactRelationship membership;
   179             membership.setRelationshipType(QContactRelationship::HasMember);
   161             membership.setRelationshipType(QContactRelationship::HasMember);
   180             membership.setFirst(mContact->id());
   162             membership.setFirst(mContact->id());
   181             membership.setSecond(contact.id());
   163             membership.setSecond(contactId);
   182             memberships.append(membership);
   164             memberships.append(membership);
   183         }
   165         }
   184 
   166 
   185         if (!memberships.isEmpty()) {
   167         if (!memberships.isEmpty()) {
   186             QMap<int, QContactManager::Error> errors;
       
   187             if (i == 0) {
   168             if (i == 0) {
   188                 getContactManager()->saveRelationships(&memberships, &errors);
   169                 getContactManager()->saveRelationships(&memberships, NULL);
   189             }
   170             }
   190             else {
   171             else {
   191                 getContactManager()->removeRelationships(memberships, &errors);
   172                 getContactManager()->removeRelationships(memberships, NULL);
   192             }
   173             }
   193         }
   174         }
   194     }
   175     }
   195 }
   176 }
   196 
   177 
   199     QContactRelationshipFilter rFilter;
   180     QContactRelationshipFilter rFilter;
   200     rFilter.setRelationshipType(QContactRelationship::HasMember);
   181     rFilter.setRelationshipType(QContactRelationship::HasMember);
   201     rFilter.setRelatedContactRole(QContactRelationship::First);
   182     rFilter.setRelatedContactRole(QContactRelationship::First);
   202     rFilter.setRelatedContactId(mContact->id());
   183     rFilter.setRelatedContactId(mContact->id());
   203 
   184 
   204     mModel = new CntListModel(mViewManager->contactManager(SYMBIAN_BACKEND), rFilter, false);
   185     mModel = new CntListModel( getContactManager(), rFilter, false);
   205     mFavoriteListView->setModel(mModel);
   186     mFavoriteListView->setModel(mModel);
   206 }
   187 }
   207 
   188 
   208 /*!
   189 /*!
   209 Called when a list item is longpressed
   190 Called when a list item is longpressed
   314 {
   295 {
   315     if (!mViewManager) {
   296     if (!mViewManager) {
   316         return NULL;
   297         return NULL;
   317     }
   298     }
   318 
   299 
   319     return mViewManager->contactManager(SYMBIAN_BACKEND);
   300     return &mEngine->contactManager(SYMBIAN_BACKEND);
   320 }
   301 }
   321 
   302 
   322 /*!
   303 /*!
   323 Called after user clicked on the listview.
   304 Called after user clicked on the listview.
   324 */
   305 */