phonebookui/pbkcommonui/src/cntmycardview.cpp
changeset 53 e6aff7b69165
parent 50 77bc263e1626
child 61 d30183af6ca6
equal deleted inserted replaced
51:81c360d47083 53:e6aff7b69165
    14 * Description:  
    14 * Description:  
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "cntmycardview.h"
    18 #include "cntmycardview.h"
    19 #include "cntfetchcontactsview.h"
    19 #include "cntfetchcontactpopup.h"
    20 #include "cntglobal.h"
    20 #include "cntglobal.h"
    21 #include <qtcontacts.h>
    21 #include <qtcontacts.h>
    22 #include <hbpushbutton.h>
    22 #include <hbpushbutton.h>
    23 #include <hbaction.h>
    23 #include <hbaction.h>
    24 #include <hbview.h>
    24 #include <hbview.h>
    26 
    26 
    27 const char *CNT_MYCARD_UI_XML = ":/xml/contacts_mc.docml";
    27 const char *CNT_MYCARD_UI_XML = ":/xml/contacts_mc.docml";
    28 
    28 
    29 CntMyCardView::CntMyCardView() :
    29 CntMyCardView::CntMyCardView() :
    30     mContact(NULL),
    30     mContact(NULL),
    31     mViewManager(NULL),
    31     mViewManager(NULL)
    32     mFetchView(NULL)
       
    33 {
    32 {
    34     bool ok = false;
    33     bool ok = false;
    35     mDocumentLoader.load(CNT_MYCARD_UI_XML, &ok);
    34     mDocumentLoader.load(CNT_MYCARD_UI_XML, &ok);
    36 
    35 
    37     if (ok)
    36     if (ok)
    51 CntMyCardView::~CntMyCardView()
    50 CntMyCardView::~CntMyCardView()
    52 {
    51 {
    53     mView->deleteLater();
    52     mView->deleteLater();
    54     
    53     
    55     delete mContact;
    54     delete mContact;
    56     mContact = 0;
    55     mContact = NULL;
    57     
       
    58     delete mFetchView;
       
    59     mFetchView = NULL;
       
    60 }
    56 }
    61 
    57 
    62 /*!
    58 /*!
    63 Activates a previous view
    59 Activates a previous view
    64 */
    60 */
   128     viewParameters.insert(EMyCard, "myCard" );
   124     viewParameters.insert(EMyCard, "myCard" );
   129     
   125     
   130     QVariant var;
   126     QVariant var;
   131     var.setValue(*mContact);
   127     var.setValue(*mContact);
   132     viewParameters.insert(ESelectedContact, var);
   128     viewParameters.insert(ESelectedContact, var);
       
   129     viewParameters.insert(EExtraAction, CNT_ROOT_ACTION);
   133     mViewManager->changeView(viewParameters);
   130     mViewManager->changeView(viewParameters);
   134 }
   131 }
   135 
   132 
   136 /*!
   133 /*!
   137 Opens the my card selection view
   134 Opens the my card selection view
   138 */
   135 */
   139 void CntMyCardView::openMyCardSelectionView()
   136 void CntMyCardView::openMyCardSelectionView()
   140 {
   137 {
   141     // Display a list of contacts to choose a mycard from.
   138     CntFetchContactPopup* popup = CntFetchContactPopup::createSingleSelectionPopup(
   142     if (!mFetchView) {
   139             hbTrId("txt_phob_title_select_contact"),
   143         mFetchView = new CntFetchContacts(*mViewManager->contactManager( SYMBIAN_BACKEND ));
   140             *mViewManager->contactManager(SYMBIAN_BACKEND));
   144         connect(mFetchView, SIGNAL(clicked()), this, SLOT(handleMultiCardSelection()));
   141     connect( popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), this, SLOT(handleMultiCardSelection(QSet<QContactLocalId>)));
   145     }
   142     popup->showPopup();
   146     mFetchView->setDetails(hbTrId("txt_phob_title_select_contact"), "");
       
   147     QSet<QContactLocalId> emptyContactsSet;
       
   148     mFetchView->displayContacts(HbAbstractItemView::SingleSelection, emptyContactsSet);
       
   149 }
   143 }
   150 
   144 
   151 void CntMyCardView::handleMultiCardSelection()
   145 void CntMyCardView::handleMultiCardSelection( QSet<QContactLocalId> aIds )
   152 {
   146 {
   153     QContactManager* manager = mViewManager->contactManager( SYMBIAN_BACKEND );
   147     QContactManager* manager = mViewManager->contactManager( SYMBIAN_BACKEND );
   154 
   148 
   155     QSet<QContactLocalId> selectedContacts = mFetchView->getSelectedContacts();
   149     if ( !aIds.isEmpty() ) {
   156 
   150         QList<QContactLocalId> selectedContactsList = aIds.values();
   157     if ( !mFetchView->wasCanceled() && !selectedContacts.isEmpty() ) {
       
   158         QList<QContactLocalId> selectedContactsList = selectedContacts.values();
       
   159         QContact contact = manager->contact(selectedContactsList.front());
   151         QContact contact = manager->contact(selectedContactsList.front());
   160         removeFromGroup(&contact);
   152         removeFromGroup(&contact);
   161         
   153         
   162         manager->setSelfContactId( contact.localId() );
   154         manager->setSelfContactId( contact.localId() );
   163         showPreviousView();
   155         showPreviousView();
   164     }
       
   165     else {
       
   166         delete mFetchView;
       
   167         mFetchView = NULL;
       
   168     }
   156     }
   169 }
   157 }
   170 
   158 
   171 void CntMyCardView::removeFromGroup(const QContact* aContact)
   159 void CntMyCardView::removeFromGroup(const QContact* aContact)
   172 {
   160 {