phonebookui/pbkcommonui/src/cntcollectionview.cpp
changeset 71 7cc7d74059f9
parent 65 ae724a111993
equal deleted inserted replaced
65:ae724a111993 71:7cc7d74059f9
    37 #include <hbview.h>
    37 #include <hbview.h>
    38 #include <hbframebackground.h>
    38 #include <hbframebackground.h>
    39 #include <hbgroupbox.h>
    39 #include <hbgroupbox.h>
    40 #include <hbmessagebox.h>
    40 #include <hbmessagebox.h>
    41 #include <hbparameterlengthlimiter.h>
    41 #include <hbparameterlengthlimiter.h>
       
    42 #include <hbeffect.h>
       
    43 #include <hbtoolbar.h>
    42 
    44 
    43 #include <QActionGroup>
    45 #include <QActionGroup>
    44 #include <QApplication>
    46 #include <QApplication>
    45 #include <QList>
    47 #include <QList>
    46 
    48 
    73     else
    75     else
    74     {
    76     {
    75         qFatal("Unable to read :/xml/contacts_collections.docml");
    77         qFatal("Unable to read :/xml/contacts_collections.docml");
    76     }
    78     }
    77     
    79     
       
    80     // disable toolbar effects
       
    81     HbEffect::disable(mView->toolBar());
       
    82     
    78     //back button
    83     //back button
    79     mSoftkey = new HbAction(Hb::BackNaviAction, mView);
    84     mSoftkey = new HbAction(Hb::BackNaviAction, mView);
    80     connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
    85     connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
    81     
    86     
    82     // menu actions
    87     // menu actions
   154     mListView->itemPrototypes().first()->setDefaultFrame(frame);
   159     mListView->itemPrototypes().first()->setDefaultFrame(frame);
   155     
   160     
   156     mListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon);
   161     mListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon);
   157     mListView->listItemPrototype()->setStretchingStyle(HbListViewItem::StretchLandscape);
   162     mListView->listItemPrototype()->setStretchingStyle(HbListViewItem::StretchLandscape);
   158     mModel = new CntCollectionListModel( mEngine, this);
   163     mModel = new CntCollectionListModel( mEngine, this);
       
   164     connect(mModel, SIGNAL(groupCountChanged()), this, SLOT(groupCountChanged()));
   159     mListView->setModel(mModel);
   165     mListView->setModel(mModel);
   160     
   166     
   161     CNT_EXIT
   167     CNT_EXIT
   162 }
   168 }
   163 
   169 
   341         groupName.setCustomLabel(text);
   347         groupName.setCustomLabel(text);
   342         
   348         
   343         mHandledContact->saveDetail(&groupName);
   349         mHandledContact->saveDetail(&groupName);
   344         getContactManager()->saveContact(mHandledContact);
   350         getContactManager()->saveContact(mHandledContact);
   345         
   351         
   346         // Select some contact(s) to add to the group
       
   347         QString groupNameCreated = mHandledContact->displayLabel();
   352         QString groupNameCreated = mHandledContact->displayLabel();
   348         if (groupNameCreated.isEmpty())
   353         if (groupNameCreated.isEmpty())
   349         {
   354         {
   350             groupNameCreated = hbTrId("txt_phob_list_unnamed");
   355             groupNameCreated = hbTrId("txt_phob_list_unnamed");
   351         }
   356         }
   356        gFilter.setValue(QLatin1String(QContactType::TypeContact));
   361        gFilter.setValue(QLatin1String(QContactType::TypeContact));
   357       
   362       
   358        QList<QContactLocalId> contactIds = getContactManager()->contactIds(gFilter);   
   363        QList<QContactLocalId> contactIds = getContactManager()->contactIds(gFilter);   
   359        if (contactIds.isEmpty())
   364        if (contactIds.isEmpty())
   360        {
   365        {
   361            mModel->addGroup(mHandledContact->localId());
       
   362            mDeleteGroupsAction->setEnabled(true);
       
   363                
       
   364            notifyNewGroup();
   366            notifyNewGroup();
   365        }      
   367        }      
   366        else
   368        else
   367        {
   369        {
   368             CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup(
   370             CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup(
   393         QVariant var;
   395         QVariant var;
   394         var.setValue(*mHandledContact);
   396         var.setValue(*mHandledContact);
   395         viewParameters.insert(ESelectedGroupContact, var);
   397         viewParameters.insert(ESelectedGroupContact, var);
   396         mViewManager->changeView(viewParameters);
   398         mViewManager->changeView(viewParameters);
   397     }
   399     }
   398     else
   400 
   399     {
       
   400         mModel->addGroup(mHandledContact->localId());
       
   401         mDeleteGroupsAction->setEnabled(true);
       
   402     }
       
   403     notifyNewGroup();
   401     notifyNewGroup();
   404 }
   402 }
   405 
   403 
   406 void CntCollectionView::handleCancelGroupMembers()
   404 void CntCollectionView::handleCancelGroupMembers()
   407 {
   405 {
   408     mSelectedContactsSet.clear();
   406     mSelectedContactsSet.clear();
   409     mModel->addGroup(mHandledContact->localId());
       
   410     mDeleteGroupsAction->setEnabled(true);
       
   411     
   407     
   412     notifyNewGroup();
   408     notifyNewGroup();
   413 }
   409 }
   414 
   410 
   415 void CntCollectionView::notifyNewGroup()
   411 void CntCollectionView::notifyNewGroup()
   435     
   431     
   436     delete mModel;
   432     delete mModel;
   437     mModel = NULL;
   433     mModel = NULL;
   438     
   434     
   439     mModel = new CntCollectionListModel(mEngine, this);
   435     mModel = new CntCollectionListModel(mEngine, this);
       
   436     connect(mModel, SIGNAL(groupCountChanged()), this, SLOT(groupCountChanged()));
   440     mListView->setModel(mModel);
   437     mListView->setModel(mModel);
   441 }
   438 }
   442 
   439 
   443 void CntCollectionView::deleteGroup(QContact group)
   440 void CntCollectionView::deleteGroup(QContact group)
   444 {
   441 {
   460 void CntCollectionView::handleDeleteGroup(int action)
   457 void CntCollectionView::handleDeleteGroup(int action)
   461 {
   458 {
   462     if (action == HbMessageBox::Delete)
   459     if (action == HbMessageBox::Delete)
   463     {
   460     {
   464         getContactManager()->removeContact(mHandledContact->localId());
   461         getContactManager()->removeContact(mHandledContact->localId());
   465         mModel->removeGroup(mHandledContact->localId());
       
   466         
       
   467         // disable delete group(s) button if only favorites group is present
       
   468         QContactDetailFilter groupFilter;
       
   469         groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
       
   470         groupFilter.setValue(QLatin1String(QContactType::TypeGroup));
       
   471         QList<QContactLocalId> groupContactIds = getContactManager()->contactIds(groupFilter);
       
   472         if (groupContactIds.count() < 2)
       
   473         {
       
   474             mDeleteGroupsAction->setEnabled(false);
       
   475         }
       
   476     }
   462     }
   477     
   463     
   478     delete mHandledContact;
   464     delete mHandledContact;
   479     mHandledContact = NULL;
   465     mHandledContact = NULL;
   480 }
   466 }
   493 {
   479 {
   494     CntGroupDeletePopup *groupDeletePopup = static_cast<CntGroupDeletePopup*>(sender());
   480     CntGroupDeletePopup *groupDeletePopup = static_cast<CntGroupDeletePopup*>(sender());
   495     
   481     
   496     if (groupDeletePopup && action == groupDeletePopup->actions().first())
   482     if (groupDeletePopup && action == groupDeletePopup->actions().first())
   497     {
   483     {
   498         QList<QContactLocalId> deletedList = groupDeletePopup->deleteGroup();
   484         groupDeletePopup->deleteGroup();
   499         foreach (QContactLocalId id, deletedList)
   485     }
   500         {
   486 }
   501             mModel->removeGroup(id);
   487 
   502         }
   488 void CntCollectionView::groupCountChanged()
   503         
   489 {
   504         // disable delete group(s) button if only favorites group is present
   490     QContactDetailFilter groupFilter;
   505         QContactDetailFilter groupFilter;
   491     groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
   506         groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
   492     groupFilter.setValue(QLatin1String(QContactType::TypeGroup));
   507         groupFilter.setValue(QLatin1String(QContactType::TypeGroup));
   493     QList<QContactLocalId> groupContactIds = getContactManager()->contactIds(groupFilter);
   508         QList<QContactLocalId> groupContactIds = getContactManager()->contactIds(groupFilter);
   494     if (groupContactIds.count() < 2)
   509         if (groupContactIds.count() < 2)
   495     {
   510         {
   496         mDeleteGroupsAction->setEnabled(false);
   511             mDeleteGroupsAction->setEnabled(false);
   497     }
   512         }
   498     else
       
   499     {
       
   500         mDeleteGroupsAction->setEnabled(true);
   513     }
   501     }
   514 }
   502 }
   515 
   503 
   516 QContactManager* CntCollectionView::getContactManager()
   504 QContactManager* CntCollectionView::getContactManager()
   517 {
   505 {