phonebookui/pbkcommonui/src/cntcollectionview.cpp
changeset 50 77bc263e1626
parent 47 7cbcb2896f0e
child 53 e6aff7b69165
equal deleted inserted replaced
49:74b30151afd6 50:77bc263e1626
    96     groups->setActionGroup(mActionGroup);
    96     groups->setActionGroup(mActionGroup);
    97     mNamesAction->setActionGroup(mActionGroup);
    97     mNamesAction->setActionGroup(mActionGroup);
    98     groups->setChecked(true);
    98     groups->setChecked(true);
    99     
    99     
   100     mFindAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:find"));
   100     mFindAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:find"));
   101     mFindAction->setEnabled(false);
   101     connect(mFindAction, SIGNAL(triggered()), this, SLOT(showNamesViewWithFinder()));
   102     mExtensionAction = static_cast<HbAction*> (mDocumentLoader.findObject("cnt:activity"));
   102     mExtensionAction = static_cast<HbAction*> (mDocumentLoader.findObject("cnt:activity"));
   103 }
   103 }
   104 
   104 
   105 /*!
   105 /*!
   106 
   106 
   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(EFinder, "show");
   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.
   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()
   341         QContactDetailFilter filter;
   346         QContactDetailFilter filter;
   342         QList<QContactLocalId> contactsList = getContactManager()->contactIds(filter);
   347         QList<QContactLocalId> contactsList = getContactManager()->contactIds(filter);
   343         QSet<QContactLocalId> contactsSet = contactsList.toSet();
   348         QSet<QContactLocalId> contactsSet = contactsList.toSet();
   344 
   349 
   345         // Select some contact(s) to add to the group
   350         // Select some contact(s) to add to the group
   346         QString groupNameCreated(mHandledContact->displayLabel());
   351         QString groupNameCreated = mHandledContact->displayLabel();
       
   352         if (groupNameCreated.isEmpty())
       
   353         {
       
   354             groupNameCreated = hbTrId("txt_phob_list_unnamed");
       
   355         }
       
   356         
       
   357         if (!mFetchView)
       
   358         {
       
   359             mFetchView = new CntFetchContacts(*mViewManager->contactManager( SYMBIAN_BACKEND ));
       
   360             connect(mFetchView, SIGNAL(clicked()), this, SLOT(handleNewGroupMembers()));
       
   361         }
   347         mFetchView->setDetails(HbParameterLengthLimiter(hbTrId("txt_phob_title_members_of_1_group")).arg(groupNameCreated),
   362         mFetchView->setDetails(HbParameterLengthLimiter(hbTrId("txt_phob_title_members_of_1_group")).arg(groupNameCreated),
   348                                hbTrId("txt_common_button_save"));
   363                                hbTrId("txt_common_button_save"));
   349         mFetchView->displayContacts(HbAbstractItemView::MultiSelection, contactsSet);
   364         mFetchView->displayContacts(HbAbstractItemView::MultiSelection, contactsSet);
   350     }
   365     }
   351 }
   366 }
   352 
   367 
   353 void CntCollectionView::handleNewGroupMembers()
   368 void CntCollectionView::handleNewGroupMembers()
   354 {
   369 {
   355     mSelectedContactsSet = mFetchView->getSelectedContacts();
   370     mSelectedContactsSet = mFetchView->getSelectedContacts();
       
   371     
   356     if ( !mFetchView->wasCanceled() && mSelectedContactsSet.size() ) {
   372     if ( !mFetchView->wasCanceled() && mSelectedContactsSet.size() ) {
   357         saveNewGroup(mHandledContact);
   373         saveNewGroup(mHandledContact);
       
   374         
       
   375         delete mFetchView;
       
   376         mFetchView = NULL;
   358 
   377 
   359         CntViewParameters viewParameters;
   378         CntViewParameters viewParameters;
   360         viewParameters.insert(EViewId, groupMemberView);
   379         viewParameters.insert(EViewId, groupMemberView);
   361         QVariant var;
   380         QVariant var;
   362         var.setValue(*mHandledContact);
   381         var.setValue(*mHandledContact);
   363         viewParameters.insert(ESelectedGroupContact, var);
   382         viewParameters.insert(ESelectedGroupContact, var);
   364         mViewManager->changeView(viewParameters);
   383         mViewManager->changeView(viewParameters);
   365     }
   384     }
   366     
   385     else
   367     QString groupNameCreated(mHandledContact->displayLabel());
   386     {
       
   387         // Add the new group 
       
   388         mModel->addGroup(mHandledContact->localId());
       
   389         mDeleteGroupsAction->setEnabled(true);
       
   390         
       
   391         delete mFetchView;
       
   392         mFetchView = NULL;
       
   393     }
       
   394     
       
   395     QString groupNameCreated = mHandledContact->displayLabel();
       
   396     if (groupNameCreated.isEmpty())
       
   397     {
       
   398         groupNameCreated = hbTrId("txt_phob_list_unnamed");
       
   399     }
   368     HbNotificationDialog::launchDialog(HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_new_group_1_created")).arg(groupNameCreated));
   400     HbNotificationDialog::launchDialog(HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_new_group_1_created")).arg(groupNameCreated));
   369 
       
   370     // Refresh the page 
       
   371     refreshDataModel();
       
   372     mDeleteGroupsAction->setEnabled(true);
       
   373 
   401 
   374     delete mHandledContact;
   402     delete mHandledContact;
   375     mHandledContact = NULL;
   403     mHandledContact = NULL;
   376 }
   404 }
   377 
   405 
   386 
   414 
   387 void CntCollectionView::deleteGroup(QContact group)
   415 void CntCollectionView::deleteGroup(QContact group)
   388 {
   416 {
   389     mHandledContact = new QContact(group);
   417     mHandledContact = new QContact(group);
   390     QString name = mHandledContact->displayLabel();
   418     QString name = mHandledContact->displayLabel();
       
   419     if (name.isEmpty())
       
   420     {
       
   421         name = hbTrId("txt_phob_list_unnamed");
       
   422     }
   391 
   423 
   392     HbLabel *headingLabel = new HbLabel();
   424     HbLabel *headingLabel = new HbLabel();
   393     headingLabel->setPlainText(HbParameterLengthLimiter(hbTrId("txt_phob_dialog_delete_1_group")).arg(name));
   425     headingLabel->setPlainText(HbParameterLengthLimiter(hbTrId("txt_phob_dialog_delete_1_group")).arg(name));
   394           
   426           
   395     HbMessageBox::question(hbTrId("txt_phob_dialog_only_group_will_be_removed_contac")
   427     HbMessageBox::question(hbTrId("txt_phob_dialog_only_group_will_be_removed_contac")
   396             , this, SLOT(handleDeleteGroup(HbAction*)),
   428             , this, SLOT(handleDeleteGroup(int)), HbMessageBox::Delete | HbMessageBox::Cancel,
   397                 hbTrId("txt_common_button_delete"), hbTrId("txt_common_button_cancel"), headingLabel);
   429                 headingLabel);
   398 }
   430 }
   399 
   431 
   400 void CntCollectionView::handleDeleteGroup(HbAction* action)
   432 void CntCollectionView::handleDeleteGroup(int action)
   401 {
   433 {
   402     HbMessageBox *note = static_cast<HbMessageBox*>(sender());
   434     if (action == HbMessageBox::Delete)
   403     
       
   404     if (note && action == note->actions().first())
       
   405     {
   435     {
   406         getContactManager()->removeContact(mHandledContact->localId());
   436         getContactManager()->removeContact(mHandledContact->localId());
   407         mModel->removeGroup(mHandledContact->localId());
   437         mModel->removeGroup(mHandledContact->localId());
   408         
   438         
   409         // disable delete group(s) button if only favorites group is present
   439         // disable delete group(s) button if only favorites group is present