phonebookui/pbkcommonui/src/cntcollectionview.cpp
changeset 27 de1630741fbe
parent 25 76a2435edfd4
child 31 2a11b5b00470
equal deleted inserted replaced
25:76a2435edfd4 27:de1630741fbe
    17 
    17 
    18 #include "cntcollectionview.h"
    18 #include "cntcollectionview.h"
    19 #include "cntgroupselectionpopup.h"
    19 #include "cntgroupselectionpopup.h"
    20 #include "cntgroupdeletepopup.h"
    20 #include "cntgroupdeletepopup.h"
    21 #include "cntcollectionlistmodel.h"
    21 #include "cntcollectionlistmodel.h"
       
    22 #include "cntextensionmanager.h"
    22 #include "qtpbkglobal.h"
    23 #include "qtpbkglobal.h"
       
    24 
       
    25 #include <cntuiextensionfactory.h>
       
    26 #include <cntuigroupsupplier.h>
    23 
    27 
    24 #include <hblistview.h>
    28 #include <hblistview.h>
    25 #include <hblistviewitem.h>
    29 #include <hblistviewitem.h>
    26 #include <hbmenu.h>
    30 #include <hbmenu.h>
    27 #include <hbnotificationdialog.h>
    31 #include <hbnotificationdialog.h>
    36 const char *CNT_COLLECTIONVIEW_XML = ":/xml/contacts_collections.docml";
    40 const char *CNT_COLLECTIONVIEW_XML = ":/xml/contacts_collections.docml";
    37 
    41 
    38 /*!
    42 /*!
    39 
    43 
    40 */
    44 */
    41 CntCollectionView::CntCollectionView() :
    45 CntCollectionView::CntCollectionView(CntExtensionManager &extensionManager) :
    42     mView(0),
    46     mExtensionManager(extensionManager),
    43     mSoftkey(0),
    47     mView(NULL),
    44     mViewManager(0),
    48     mSoftkey(NULL),
    45     mModel(0),
    49     mViewManager(NULL),
    46     mListView(0),
    50     mModel(NULL),
    47     mNamesAction(0),
    51     mListView(NULL),
    48     mRefreshAction(0),
    52     mNamesAction(NULL),
    49     mNewGroupAction(0),
    53     mFindAction(NULL),
    50     mDeleteGroupsAction(0)
    54     mExtensionAction(NULL),
       
    55     mNewGroupAction(NULL),
       
    56     mDeleteGroupsAction(NULL)
    51 {
    57 {
    52     bool ok = false;
    58     bool ok = false;
    53     mDocumentLoader.load(CNT_COLLECTIONVIEW_XML, &ok);
    59     mDocumentLoader.load(CNT_COLLECTIONVIEW_XML, &ok);
    54 
    60 
    55     if (ok)
    61     if (ok)
    64     //back button
    70     //back button
    65     mSoftkey = new HbAction(Hb::BackNaviAction, mView);
    71     mSoftkey = new HbAction(Hb::BackNaviAction, mView);
    66     connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
    72     connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
    67     
    73     
    68     // menu actions
    74     // menu actions
       
    75     mNewGroupAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:newgroup"));
       
    76     connect(mNewGroupAction, SIGNAL(triggered()), this, SLOT(newGroup()));
    69     mDeleteGroupsAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:deletegroups"));
    77     mDeleteGroupsAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:deletegroups"));
    70     mDeleteGroupsAction->setParent(mView);
       
    71     connect(mDeleteGroupsAction, SIGNAL(triggered()), this, SLOT(deleteGroups()));
    78     connect(mDeleteGroupsAction, SIGNAL(triggered()), this, SLOT(deleteGroups()));
    72     
    79     
    73     // toolbar actions
    80     // toolbar actions
       
    81     
    74     mNamesAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:names"));
    82     mNamesAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:names"));
    75     mNamesAction->setParent(mView);
       
    76     connect(mNamesAction, SIGNAL(triggered()), this, SLOT(showPreviousView()));
    83     connect(mNamesAction, SIGNAL(triggered()), this, SLOT(showPreviousView()));
    77     mRefreshAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:refresh"));
    84     mFindAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:find"));
    78     mRefreshAction->setParent(mView);
    85     mExtensionAction = static_cast<HbAction*> (mDocumentLoader.findObject("cnt:activity"));
    79     connect(mRefreshAction, SIGNAL(triggered()), this, SLOT(refreshDataModel()));
       
    80     mNewGroupAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:newgroup"));
       
    81     mNewGroupAction->setParent(mView);
       
    82     connect(mNewGroupAction, SIGNAL(triggered()), this, SLOT(newGroup()));
       
    83 }
    86 }
    84 
    87 
    85 /*!
    88 /*!
    86 
    89 
    87 */
    90 */
    91 }
    94 }
    92 
    95 
    93 /*!
    96 /*!
    94 Called when activating the view
    97 Called when activating the view
    95 */
    98 */
    96 void CntCollectionView::activate( CntAbstractViewManager* aMgr, const CntViewParameters& aArgs )
    99 void CntCollectionView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs )
    97 {
   100 {
    98     Q_UNUSED(aArgs)
   101     Q_UNUSED(aArgs)
    99     
   102     
   100     if (mView->navigationAction() != mSoftkey)
   103     if (mView->navigationAction() != mSoftkey)
   101         mView->setNavigationAction(mSoftkey);   
   104         mView->setNavigationAction(mSoftkey);   
   112         mDeleteGroupsAction->setEnabled(false);
   115         mDeleteGroupsAction->setEnabled(false);
   113     }
   116     }
   114     
   117     
   115     // set up the list
   118     // set up the list
   116     mListView = static_cast<HbListView*>(mDocumentLoader.findWidget(QString("listView")));
   119     mListView = static_cast<HbListView*>(mDocumentLoader.findWidget(QString("listView")));
       
   120     mListView->setUniformItemSizes(true);
   117     
   121     
   118     connect(mListView, SIGNAL(activated(const QModelIndex&)), this,
   122     connect(mListView, SIGNAL(activated(const QModelIndex&)), this,
   119         SLOT(openGroup(const QModelIndex&)));
   123         SLOT(openGroup(const QModelIndex&)));
   120     connect(mListView, SIGNAL(longPressed(HbAbstractViewItem*,QPointF)), this,
   124     connect(mListView, SIGNAL(longPressed(HbAbstractViewItem*,QPointF)), this,
   121         SLOT(showContextMenu(HbAbstractViewItem*,QPointF)));
   125         SLOT(showContextMenu(HbAbstractViewItem*,QPointF)));
   124     frame.setFrameGraphicsName("qtg_fr_list_normal");
   128     frame.setFrameGraphicsName("qtg_fr_list_normal");
   125     frame.setFrameType(HbFrameDrawer::NinePieces);
   129     frame.setFrameType(HbFrameDrawer::NinePieces);
   126     mListView->itemPrototypes().first()->setDefaultFrame(frame);
   130     mListView->itemPrototypes().first()->setDefaultFrame(frame);
   127     
   131     
   128     mListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon);
   132     mListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon);
   129     
   133     mListView->listItemPrototype()->setStretchingStyle(HbListViewItem::StretchLandscape);
   130     mModel = new CntCollectionListModel(mViewManager->contactManager(SYMBIAN_BACKEND), this);
   134     mModel = new CntCollectionListModel(mViewManager->contactManager(SYMBIAN_BACKEND), mExtensionManager, this);
   131     mListView->setModel(mModel);
   135     mListView->setModel(mModel);
   132 }
   136 }
   133 
   137 
   134 void CntCollectionView::deactivate()
   138 void CntCollectionView::deactivate()
   135 {
   139 {
   148 /*!
   152 /*!
   149 Called after user clicked on the listview.
   153 Called after user clicked on the listview.
   150 */
   154 */
   151 void CntCollectionView::openGroup(const QModelIndex &index)
   155 void CntCollectionView::openGroup(const QModelIndex &index)
   152 {
   156 {
   153     int id = index.data(Qt::UserRole).toInt();
   157     if (mModel->isExtensionGroup(index))
   154     int favoriteGrpId = mModel->favoriteGroupId();
   158     {
   155 
   159         CntViewParameters params = mModel->extensionGroupActivated(index.row());
   156     if (id == favoriteGrpId )
   160         if (params.count())
   157     {
   161         {
   158         QContact favoriteGroup = mViewManager->contactManager(SYMBIAN_BACKEND)->contact(favoriteGrpId);
   162             mViewManager->changeView(params);
   159         QContactRelationshipFilter rFilter;
   163         }
   160         rFilter.setRelationshipType(QContactRelationship::HasMember);
   164     }
   161         rFilter.setRelatedContactRole(QContactRelationshipFilter::First);
   165     else
   162         rFilter.setRelatedContactId(favoriteGroup.id());
   166     {
   163         // group members and their count
   167         int id = index.data(Qt::UserRole).toInt();
   164         QList<QContactLocalId> groupMemberIds = mViewManager->contactManager(SYMBIAN_BACKEND)->contactIds(rFilter);
   168         int favoriteGrpId = mModel->favoriteGroupId();
   165         
   169 
   166         if (groupMemberIds.isEmpty())
   170         if (id == favoriteGrpId )
   167         {
   171         {
   168             CntViewParameters viewParameters(CntViewParameters::collectionFavoritesView);
   172             QContact favoriteGroup = mViewManager->contactManager(SYMBIAN_BACKEND)->contact(favoriteGrpId);
   169             viewParameters.setSelectedContact(favoriteGroup);
   173             QContactRelationshipFilter rFilter;
       
   174             rFilter.setRelationshipType(QContactRelationship::HasMember);
       
   175             rFilter.setRelatedContactRole(QContactRelationship::First);
       
   176             rFilter.setRelatedContactId(favoriteGroup.id());
       
   177             // group members and their count
       
   178             QList<QContactLocalId> groupMemberIds = mViewManager->contactManager(SYMBIAN_BACKEND)->contactIds(rFilter);
       
   179 
       
   180             if (groupMemberIds.isEmpty())
       
   181             {
       
   182                 CntViewParameters viewParameters;
       
   183                 viewParameters.insert(EViewId, collectionFavoritesView);
       
   184                 QVariant var;
       
   185                 var.setValue(favoriteGroup);
       
   186                 viewParameters.insert(ESelectedContact, var);
       
   187                 mViewManager->changeView(viewParameters);
       
   188             }
       
   189             else
       
   190             {
       
   191                 CntViewParameters viewParameters;
       
   192                 viewParameters.insert(EViewId, FavoritesMemberView);
       
   193                 QVariant var;
       
   194                 var.setValue(favoriteGroup);
       
   195                 viewParameters.insert(ESelectedContact, var);
       
   196                 mViewManager->changeView(viewParameters);
       
   197             }
       
   198         }
       
   199         else
       
   200         {
       
   201             QContact groupContact = mViewManager->contactManager(SYMBIAN_BACKEND)->contact(id);
       
   202 
       
   203             CntViewParameters viewParameters;
       
   204             viewParameters.insert(EViewId, groupMemberView);
       
   205             QVariant var;
       
   206             var.setValue(groupContact);
       
   207             viewParameters.insert(ESelectedContact, var);
   170             mViewManager->changeView(viewParameters);
   208             mViewManager->changeView(viewParameters);
   171         }
   209         }
   172         else 
   210     }
   173         {
   211 }
   174             CntViewParameters viewParameters(CntViewParameters::FavoritesMemberView);
   212 
   175             viewParameters.setSelectedContact(favoriteGroup);
   213 void CntCollectionView::showContextMenu(HbAbstractViewItem *item, const QPointF &coords)
   176             mViewManager->changeView(viewParameters);
   214 {
       
   215     if (mModel->isExtensionGroup(item->modelIndex()))
       
   216     {
       
   217         CntViewParameters params = mModel->extensionGroupLongPressed(item->modelIndex().row(), coords);
       
   218         if (params.count())
       
   219         {
       
   220             mViewManager->changeView(params);
   177         }
   221         }
   178     }
   222     }
   179     else
   223     else
   180     {
   224     {
   181         QContact groupContact = mViewManager->contactManager(SYMBIAN_BACKEND)->contact(id);
   225         int id = item->modelIndex().data(Qt::UserRole).toInt();
   182         CntViewParameters viewParameters(CntViewParameters::groupMemberView);
   226         int favoriteGrpId = mModel->favoriteGroupId();
   183         viewParameters.setSelectedContact(groupContact);
   227 
   184         mViewManager->changeView(viewParameters);
   228         HbMenu *menu = new HbMenu();
   185     }
   229         HbAction *openAction = 0;
   186 }
   230         HbAction *deleteAction = 0;
   187 
   231 
   188 void CntCollectionView::showContextMenu(HbAbstractViewItem *item, const QPointF &coords)
   232         openAction = menu->addAction(hbTrId("txt_common_menu_open"));
   189 {
   233 
   190     int id = item->modelIndex().data(Qt::UserRole).toInt();
   234         if (id != favoriteGrpId)
   191     int favoriteGrpId = mModel->favoriteGroupId();
   235         {
   192     
   236             deleteAction = menu->addAction(hbTrId("txt_phob_menu_delete_group"));
   193     HbMenu *menu = new HbMenu();
   237         }
   194     HbAction *openAction = 0;
   238 
   195     HbAction *deleteAction = 0;
   239         HbAction *selectedAction = menu->exec(coords);
   196     
   240 
   197     openAction = menu->addAction(hbTrId("txt_common_menu_open"));
   241         if (selectedAction)
   198     
   242         {
   199     if (id != favoriteGrpId)
   243             if (selectedAction == openAction)
   200     {
   244             {
   201         deleteAction = menu->addAction(hbTrId("txt_phob_menu_delete_group"));
   245                 openGroup(item->modelIndex());
   202     }
   246             }
   203     
   247             else if (selectedAction == deleteAction)
   204     HbAction *selectedAction = menu->exec(coords);
   248             {
   205 
   249                 QContact groupContact = mViewManager->contactManager(SYMBIAN_BACKEND)->contact(id);
   206     if (selectedAction)
   250                 deleteGroup(groupContact);
   207     {
   251             }
   208         if (selectedAction == openAction)
   252         }
   209         {
   253         menu->deleteLater();
   210             openGroup(item->modelIndex());
   254     }
   211         }
       
   212         else if (selectedAction == deleteAction)
       
   213         {
       
   214             QContact groupContact = mViewManager->contactManager(SYMBIAN_BACKEND)->contact(id);
       
   215             deleteGroup(groupContact);
       
   216         }
       
   217     }
       
   218     menu->deleteLater();
       
   219 }
   255 }
   220 
   256 
   221 void CntCollectionView::newGroup()
   257 void CntCollectionView::newGroup()
   222 {
   258 {
   223     QString mTextOfNewItem("");
   259     QString mTextOfNewItem("");
   255         groupSelectionPopup->populateListOfContact();
   291         groupSelectionPopup->populateListOfContact();
   256         HbAction* action = groupSelectionPopup->exec();
   292         HbAction* action = groupSelectionPopup->exec();
   257         if (action == groupSelectionPopup->primaryAction())
   293         if (action == groupSelectionPopup->primaryAction())
   258         {
   294         {
   259             groupSelectionPopup->saveNewGroup();
   295             groupSelectionPopup->saveNewGroup();
   260             CntViewParameters viewParameters(CntViewParameters::groupMemberView);
   296             
   261             viewParameters.setSelectedContact(groupContact);
   297             CntViewParameters viewParameters;
       
   298             viewParameters.insert(EViewId, groupMemberView);
       
   299             QVariant var;
       
   300             var.setValue(groupContact);
       
   301             viewParameters.insert(ESelectedContact, var);
   262             mViewManager->changeView(viewParameters);
   302             mViewManager->changeView(viewParameters);
       
   303             
   263             delete groupSelectionPopup;
   304             delete groupSelectionPopup;
   264         }
   305         }
   265         else if (action == groupSelectionPopup->secondaryAction())
   306         else if (action == groupSelectionPopup->secondaryAction())
   266         {
   307         {
   267             delete groupSelectionPopup;
   308             delete groupSelectionPopup;
   278 void CntCollectionView::refreshDataModel()
   319 void CntCollectionView::refreshDataModel()
   279 {
   320 {
   280     mListView->setModel(0);
   321     mListView->setModel(0);
   281     delete mModel;
   322     delete mModel;
   282     mModel = 0;
   323     mModel = 0;
   283     mModel = new CntCollectionListModel(mViewManager->contactManager(SYMBIAN_BACKEND), this);
   324     mModel = new CntCollectionListModel(mViewManager->contactManager(SYMBIAN_BACKEND), mExtensionManager, this);
   284     mListView->setModel(mModel);
   325     mListView->setModel(mModel);
   285 }
       
   286 
       
   287 void CntCollectionView::reorderGroup()
       
   288 {
       
   289     // wait for specs
       
   290 }
   326 }
   291 
   327 
   292 void CntCollectionView::deleteGroup(QContact group)
   328 void CntCollectionView::deleteGroup(QContact group)
   293 {
   329 {
   294     QString name = group.displayLabel();
   330     QString name = group.displayLabel();
   339     if (groupContactIds.count() < 2)
   375     if (groupContactIds.count() < 2)
   340     {
   376     {
   341         mDeleteGroupsAction->setEnabled(false);
   377         mDeleteGroupsAction->setEnabled(false);
   342     }
   378     }
   343 }
   379 }
   344 
       
   345 void CntCollectionView::disconnectAll()
       
   346 {
       
   347     // wait for specs
       
   348 }
       
   349 
       
   350 // EOF
   380 // EOF