phonebookui/pbkcommonui/src/cntfavoritesview.cpp
changeset 59 a642906a277a
parent 47 7cbcb2896f0e
child 61 d30183af6ca6
equal deleted inserted replaced
47:7cbcb2896f0e 59:a642906a277a
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "cntfavoritesview.h"
    18 #include "cntfavoritesview.h"
    19 #include "cntfetchcontactsview.h"
    19 #include "cntfetchcontactpopup.h"
    20 #include "cntglobal.h"
    20 #include "cntglobal.h"
    21 #include <hbpushbutton.h>
    21 #include <hbpushbutton.h>
    22 #include <hbaction.h>
    22 #include <hbaction.h>
    23 #include <hbview.h>
    23 #include <hbview.h>
    24 #include <hbmainwindow.h>
    24 #include <hbmainwindow.h>
    28 
    28 
    29 CntFavoritesView::CntFavoritesView() :
    29 CntFavoritesView::CntFavoritesView() :
    30     mContact(NULL),
    30     mContact(NULL),
    31     mView(NULL),
    31     mView(NULL),
    32     mSoftkey(NULL),
    32     mSoftkey(NULL),
    33     mViewManager(NULL),
    33     mViewManager(NULL)
    34     mFetchView(NULL)
       
    35 {
    34 {
    36     bool ok = false;
    35     bool ok = false;
    37     mDocumentLoader.load(CNT_FAVORITE_UI_XML, &ok);
    36     mDocumentLoader.load(CNT_FAVORITE_UI_XML, &ok);
    38 
    37 
    39     if (ok)
    38     if (ok)
    55 CntFavoritesView::~CntFavoritesView()
    54 CntFavoritesView::~CntFavoritesView()
    56 {
    55 {
    57     mView->deleteLater();
    56     mView->deleteLater();
    58     
    57     
    59     delete mContact;
    58     delete mContact;
    60     mContact = 0;
    59     mContact = NULL;
    61 
       
    62     delete mFetchView;
       
    63     mFetchView = 0;
       
    64 }
    60 }
    65 
    61 
    66 void CntFavoritesView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs )
    62 void CntFavoritesView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs )
    67 {
    63 {
    68     if (mView->navigationAction() != mSoftkey)
    64     if (mView->navigationAction() != mSoftkey)
    83 {
    79 {
    84 }
    80 }
    85 
    81 
    86 void CntFavoritesView::openSelectionPopup()
    82 void CntFavoritesView::openSelectionPopup()
    87 {
    83 {
       
    84     /*
    88     QSet<QContactLocalId> emptySet;
    85     QSet<QContactLocalId> emptySet;
    89     
       
    90     if (!mFetchView) {
    86     if (!mFetchView) {
    91         mFetchView = new CntFetchContacts(*getContactManager());
    87         mFetchView = new CntFetchContacts(*getContactManager());
    92         connect(mFetchView, SIGNAL(clicked()), this, SLOT(handleMemberSelection()));
    88         connect(mFetchView, SIGNAL(clicked()), this, SLOT(handleMemberSelection()));
    93     }
    89     }
    94     mFetchView->setDetails(hbTrId("txt_phob_subtitle_favorites"), hbTrId("txt_common_button_save"));
    90     mFetchView->setDetails(hbTrId("txt_phob_subtitle_favorites"), hbTrId("txt_common_button_save"));
    95     mFetchView->displayContacts(HbAbstractItemView::MultiSelection, emptySet);
    91     mFetchView->displayContacts(HbAbstractItemView::MultiSelection, emptySet);
       
    92     */
       
    93     CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup(
       
    94             hbTrId("txt_phob_subtitle_favorites"), 
       
    95             hbTrId("txt_common_button_save"),
       
    96             *getContactManager());
       
    97     connect(popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), 
       
    98             this, SLOT(handleMemberSelection(QSet<QContactLocalId>)));
       
    99     popup->showPopup();
    96 }
   100 }
    97 
   101 
    98 void CntFavoritesView::handleMemberSelection()
   102 void CntFavoritesView::handleMemberSelection( QSet<QContactLocalId> aIds )
    99 {
   103 {
   100     QSet<QContactLocalId> members = mFetchView->getSelectedContacts();
   104     //QSet<QContactLocalId> members = mFetchView->getSelectedContacts();
   101     QList<QContactRelationship> memberships;
   105     //bool saveChanges = !mFetchView->wasCanceled();
   102     bool saveChanges = !mFetchView->wasCanceled();
       
   103 
   106 
   104     delete mFetchView;
   107     //delete mFetchView;
   105     mFetchView = 0;
   108     //mFetchView = 0;
   106 
   109 
   107     if (!saveChanges || members.count() == 0) {
   110     //if (!saveChanges || members.count() == 0)
       
   111     if ( aIds.isEmpty() )
       
   112     {
   108         showPreviousView();
   113         showPreviousView();
   109         return;
       
   110     }
   114     }
   111 
   115     else
   112     foreach (QContactLocalId id, members) {
   116     {
   113         QContact contact = getContactManager()->contact(id);
   117         QList<QContactRelationship> memberships;
   114         QContactRelationship membership;
   118         foreach (QContactLocalId id, aIds) {
   115         membership.setRelationshipType(QContactRelationship::HasMember);
   119             QContact contact = getContactManager()->contact(id);
   116         membership.setFirst(mContact->id());
   120             QContactRelationship membership;
   117         membership.setSecond(contact.id());
   121             membership.setRelationshipType(QContactRelationship::HasMember);
   118         memberships.append(membership);
   122             membership.setFirst(mContact->id());
       
   123             membership.setSecond(contact.id());
       
   124             memberships.append(membership);
       
   125         }
       
   126     
       
   127         if (!memberships.isEmpty()) {
       
   128             QMap<int, QContactManager::Error> errors;
       
   129             getContactManager()->saveRelationships(&memberships, &errors);
       
   130         }
       
   131     
       
   132         CntViewParameters viewParameters;
       
   133         viewParameters.insert(EViewId, favoritesMemberView);
       
   134         QVariant var;
       
   135         var.setValue(*mContact);
       
   136         viewParameters.insert(ESelectedGroupContact, var);
       
   137         mViewManager->changeView(viewParameters);
   119     }
   138     }
   120 
       
   121     if (!memberships.isEmpty()) {
       
   122         QMap<int, QContactManager::Error> errors;
       
   123         getContactManager()->saveRelationships(&memberships, &errors);
       
   124     }
       
   125 
       
   126     CntViewParameters viewParameters;
       
   127     viewParameters.insert(EViewId, FavoritesMemberView);
       
   128     QVariant var;
       
   129     var.setValue(*mContact);
       
   130     viewParameters.insert(ESelectedGroupContact, var);
       
   131     mViewManager->changeView(viewParameters);
       
   132 }
   139 }
   133 
   140 
   134 void CntFavoritesView::setOrientation(Qt::Orientation orientation)
   141 void CntFavoritesView::setOrientation(Qt::Orientation orientation)
   135 {
   142 {
   136     if (orientation == Qt::Vertical) 
   143     if (orientation == Qt::Vertical)