emailuis/nmailui/src/nmmessagelistview.cpp
changeset 59 16ed8d08d0b1
parent 54 997a02608b3a
child 65 478bc57ad291
equal deleted inserted replaced
54:997a02608b3a 59:16ed8d08d0b1
    21 static const char *NMUI_MESSAGE_LIST_NO_MESSAGES = "MessageListNoMessages";
    21 static const char *NMUI_MESSAGE_LIST_NO_MESSAGES = "MessageListNoMessages";
    22 static const char *NMUI_MESSAGE_LIST_FOLDER_LABEL = "labelGroupBox";
    22 static const char *NMUI_MESSAGE_LIST_FOLDER_LABEL = "labelGroupBox";
    23 
    23 
    24 #include "nmuiheaders.h"
    24 #include "nmuiheaders.h"
    25 
    25 
    26 const QString syncIndicatorName = "com.nokia.nmail.indicatorplugin.sync/1.0";
    26 /*!
    27 
       
    28 /*! 
       
    29 	\class NmMessageListView
    27 	\class NmMessageListView
    30 	\brief Message list view
    28 	\brief Message list view
    31 */
    29 */
    32 
    30 
    33 /*!
    31 /*!
   146                          this, SLOT(handleSyncStateEvent(NmSyncState, const NmId &)));
   144                          this, SLOT(handleSyncStateEvent(NmSyncState, const NmId &)));
   147 
   145 
   148         // Menu needs one dummy item so that aboutToShow signal is emitted.
   146         // Menu needs one dummy item so that aboutToShow signal is emitted.
   149         NmAction *dummy = new NmAction(0);
   147         NmAction *dummy = new NmAction(0);
   150         menu()->addAction(dummy);
   148         menu()->addAction(dummy);
       
   149         // Set sync icon if needed
       
   150         updateSyncIcon();
   151     }
   151     }
   152     else {
   152     else {
   153         NM_ERROR(1,"nmailui: resource loading failed");
   153         NM_ERROR(1,"nmailui: resource loading failed");
   154     }
   154     }
   155 }
   155 }
   202 /*!
   202 /*!
   203     initTreeView
   203     initTreeView
   204 */
   204 */
   205 void NmMessageListView::initTreeView()
   205 void NmMessageListView::initTreeView()
   206 {
   206 {
   207     NM_FUNCTION; 
   207     NM_FUNCTION;
   208 
   208 
   209     // Get mailbox widget pointer and set parameters
   209     // Get mailbox widget pointer and set parameters
   210     if (mMessageListWidget){
   210     if (mMessageListWidget){
   211         QObject::connect(mMessageListWidget,
   211         QObject::connect(mMessageListWidget,
   212                 SIGNAL(activated(const QModelIndex &)), this,
   212                 SIGNAL(activated(const QModelIndex &)), this,
   228 {
   228 {
   229     NM_FUNCTION;
   229     NM_FUNCTION;
   230 
   230 
   231     // Check start parameter validity, message view cannot
   231     // Check start parameter validity, message view cannot
   232     // be updated if given parameter is zero.
   232     // be updated if given parameter is zero.
   233     if (startParam&&startParam->viewId()==NmUiViewMessageList&&
   233     if (startParam&&startParam->viewId()==NmUiViewMessageList &&
   234         startParam->folderId()!=0) {
   234         startParam->folderId()!=0) {
   235         // Delete existing start parameter data
   235         // Delete existing start parameter data
   236         delete mStartParam;
   236         delete mStartParam;
   237         mStartParam=NULL;
   237         mStartParam = NULL;
   238         // Store new start parameter data
   238         // Store new start parameter data
   239         mStartParam=startParam;
   239         mStartParam = startParam;
   240         // Update the model with new parameters
   240         // Disconnect signals from previous model
       
   241         QObject::disconnect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
       
   242                 this, SLOT(itemsAdded(const QModelIndex&,int,int)));
       
   243         QObject::disconnect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
       
   244                 this, SLOT(itemsRemoved()));
       
   245         QObject::disconnect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
       
   246                 this, SLOT(reloadViewContents(NmUiStartParam*)));
       
   247         // Update model pointer and refresh mailbox with new model
   241         mMessageListModel = &mUiEngine.messageListModel(startParam->mailboxId(), startParam->folderId());
   248         mMessageListModel = &mUiEngine.messageListModel(startParam->mailboxId(), startParam->folderId());
       
   249         
   242         refreshList();
   250         refreshList();
   243         // Refresh the mailboxname
   251         
       
   252         // Refresh the mailbox name
   244         setMailboxName();
   253         setMailboxName();
       
   254         
       
   255         // Store active folder type
       
   256         mCurrentFolderType = mUiEngine.folderTypeById(startParam->mailboxId(),startParam->folderId());
       
   257 
       
   258         // Update folder name
       
   259         setFolderName();
       
   260         
       
   261         // Set sync icon if needed
       
   262         updateSyncIcon();
   245     }
   263     }
   246     else {
   264     else {
   247         NM_ERROR(1,"nmailui: invalid message list start parameter");
   265         NM_ERROR(1,"nmailui: invalid message list start parameter");
   248         // Unused start parameter needs to be deleted
   266         // Unused start parameter needs to be deleted
   249         delete startParam;
   267         delete startParam;
   250     }
   268     }
   251 }
   269 }
   252 
   270 
   253  
   271 
   254 /*!
   272 /*!
   255     Return view id
   273     Return view id
   256 */
   274 */
   257 NmUiViewId NmMessageListView::nmailViewId() const
   275 NmUiViewId NmMessageListView::nmailViewId() const
   258 {
   276 {
   267 void NmMessageListView::refreshList()
   285 void NmMessageListView::refreshList()
   268 {
   286 {
   269     NM_FUNCTION;
   287     NM_FUNCTION;
   270 
   288 
   271     if (mMessageListModel) {
   289     if (mMessageListModel) {
   272         NmId mailboxId = mMessageListModel->currentMailboxId();    
   290         NmId mailboxId = mMessageListModel->currentMailboxId();
   273         // In each refresh, e.g. in folder change the UI signals
   291         // In each refresh, e.g. in folder change the UI signals
   274         // lower layer about the folder that has been opened.
   292         // lower layer about the folder that has been opened.
   275         if (mStartParam){
   293         if (mStartParam){
   276             mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId());
   294             mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId());
   277             
   295 
   278             NmFolderType folderType = mUiEngine.folderTypeById(mStartParam->mailboxId(),
   296             NmFolderType folderType = mUiEngine.folderTypeById(mStartParam->mailboxId(),
   279                                               mStartParam->folderId());
   297                                               mStartParam->folderId());
   280             if (folderType == NmFolderInbox) { // If the new folder is an inbox, first automatic sync should be shown
   298             if (folderType == NmFolderInbox) { // If the new folder is an inbox, first automatic sync should be shown
   281                 mIsFirstSyncInMessageList = true; 
   299                 mIsFirstSyncInMessageList = true;
   282             }
   300             }
   283         }
   301         }
   284 
   302 
   285         // Set item model to message list widget
   303         // Set item model to message list widget
   286         if (mMessageListWidget) {
   304         if (mMessageListWidget) {
   287             mMessageListWidget->setModel(static_cast<QStandardItemModel*>(mMessageListModel));
   305             mMessageListWidget->setModel(static_cast<QStandardItemModel*>(mMessageListModel));
   288             QObject::connect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
   306             QObject::connect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
   289                     this, SLOT(itemsAdded(const QModelIndex&,int,int)));
   307                     this, SLOT(itemsAdded(const QModelIndex&,int,int)),Qt::UniqueConnection);
   290             QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   308             QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   291                     this, SLOT(itemsRemoved()));
   309                     this, SLOT(itemsRemoved()),Qt::UniqueConnection);
   292             QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   310             QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   293                     this, SLOT(reloadViewContents(NmUiStartParam*)));
   311                     this, SLOT(reloadViewContents(NmUiStartParam*)),Qt::UniqueConnection);
   294 
   312 
   295             mPreviousModelCount=mMessageListModel->rowCount();
   313             mPreviousModelCount=mMessageListModel->rowCount();
   296             if (mPreviousModelCount==0){
   314             if (mPreviousModelCount==0){
   297                 showNoMessagesText();
   315                 showNoMessagesText();
   298             }
   316             }
   299             else{
   317             else{
   300                 hideNoMessagesText();
   318                 hideNoMessagesText();
   301             }
   319             }
   302         }    
   320         }
   303     }
   321     }
   304 }
   322 }
   305 
   323 
   306 /*!
   324 /*!
   307     Sync state event handling
   325     Sync state event handling
   308 */
   326 */
   309 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId & mailboxId)
   327 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId &mailboxId)
   310 {
   328 {
   311     NM_FUNCTION;
   329     NM_FUNCTION;
   312     if (mMessageListModel && mailboxId == mMessageListModel->currentMailboxId()) {
   330     if (mMessageListModel && mailboxId == mMessageListModel->currentMailboxId()) {
   313         if (syncState == Synchronizing) {
   331         if (syncState == Synchronizing) {
   314              // before first sync inbox id might be zero
   332              // before first sync inbox id might be zero
   320                 mStartParam->setFolderId(folderId);
   338                 mStartParam->setFolderId(folderId);
   321             }
   339             }
   322             // Show sync icon only for the first automatic sync after opening message list.
   340             // Show sync icon only for the first automatic sync after opening message list.
   323             // Sync icon for manual sync is shown in NmUiEngine::refreshMailbox, not here.
   341             // Sync icon for manual sync is shown in NmUiEngine::refreshMailbox, not here.
   324             if (mIsFirstSyncInMessageList) {
   342             if (mIsFirstSyncInMessageList) {
   325                 HbIndicator indicator;
   343 				mUiEngine.enableSyncIndicator(true);
   326                 indicator.activate(syncIndicatorName, QVariant());
       
   327                 mIsFirstSyncInMessageList = false;
   344                 mIsFirstSyncInMessageList = false;
   328             }
   345             }
   329         }
   346         }
   330     }
   347     }
   331 }
   348 }
   332 
   349 
   333 /*! 
   350 /*!
   334     folder selection handling within current mailbox
   351     folder selection handling within current mailbox
   335 */
   352 */
   336 void NmMessageListView::folderSelected()
   353 void NmMessageListView::folderSelected()
   337 {
   354 {
   338     NM_FUNCTION;
   355     NM_FUNCTION;
   348         // Store active folder type
   365         // Store active folder type
   349         mCurrentFolderType = mUiEngine.folderTypeById(startParam->mailboxId(),startParam->folderId());
   366         mCurrentFolderType = mUiEngine.folderTypeById(startParam->mailboxId(),startParam->folderId());
   350         // Reload view, ownership of the startparams is passed and old startparams
   367         // Reload view, ownership of the startparams is passed and old startparams
   351         // are deleted within reloadViewContents function
   368         // are deleted within reloadViewContents function
   352         reloadViewContents(startParam);
   369         reloadViewContents(startParam);
   353         //Set folder text to status bar
   370         // Set folder text to status bar
   354         setFolderName();
   371         setFolderName();
   355     }
   372     }
   356 }
   373 }
   357 
   374 
   358 
   375 
   359 /*!
   376 /*!
   360     Long keypress handling 
   377     Long keypress handling
   361 */
   378 */
   362 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords)
   379 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords)
   363 {
   380 {
   364     NM_FUNCTION;
   381     NM_FUNCTION;
   365    
   382 
   366     if (listViewItem) {
   383     if (listViewItem) {
   367         // Recreate item context menu each time it is called
   384         // Recreate item context menu each time it is called
   368         if (mItemContextMenu){
   385         if (mItemContextMenu){
   369             mItemContextMenu->clearActions();
   386             mItemContextMenu->clearActions();
   370             delete mItemContextMenu;    
   387             delete mItemContextMenu;
   371             mItemContextMenu=NULL;
   388             mItemContextMenu=NULL;
   372         }
   389         }
   373         mItemContextMenu = new HbMenu();
   390         mItemContextMenu = new HbMenu();
   374         // Store long press item for later use with response
   391         // Store long press item for later use with response
   375         mLongPressedItem = mMessageListModel->data(
   392         mLongPressedItem = mMessageListModel->data(
   610 */
   627 */
   611 void NmMessageListView::setFolderName()
   628 void NmMessageListView::setFolderName()
   612 {
   629 {
   613     NM_FUNCTION;
   630     NM_FUNCTION;
   614 
   631 
   615     if (mStartParam&&mFolderLabel){
   632     if (mStartParam && mFolderLabel){
   616         switch (mCurrentFolderType) {
   633         switch (mCurrentFolderType) {
   617         case NmFolderOutbox:
   634         case NmFolderOutbox:
   618             {
   635             {
   619             mFolderLabel->setHeading(hbTrId("txt_mail_subhead_outbox"));
   636             mFolderLabel->setHeading(hbTrId("txt_mail_subhead_outbox"));
   620             }
   637             }
   648 /*!
   665 /*!
   649     Handles the addition of a new item. Makes sure the message list widget is
   666     Handles the addition of a new item. Makes sure the message list widget is
   650     visible and keeps the scroll position on the top of the list.
   667     visible and keeps the scroll position on the top of the list.
   651 
   668 
   652     \param parent Not used.
   669     \param parent Not used.
   653     \param start 
   670     \param start
   654     \param end Not used.
   671     \param end Not used.
   655 */
   672 */
   656 void NmMessageListView::itemsAdded(const QModelIndex &parent, int start, int end)
   673 void NmMessageListView::itemsAdded(const QModelIndex &parent, int start, int end)
   657 {
   674 {
   658     NM_FUNCTION;
   675     NM_FUNCTION;
   686             }
   703             }
   687         }
   704         }
   688     }
   705     }
   689     // Store model count
   706     // Store model count
   690     if (mMessageListModel){
   707     if (mMessageListModel){
   691         mPreviousModelCount=mMessageListModel->rowCount();    
   708         mPreviousModelCount=mMessageListModel->rowCount();
   692     }
   709     }
   693 }
   710 }
   694 
   711 
   695 
   712 
   696 /*!
   713 /*!
   699 void NmMessageListView::itemsRemoved()
   716 void NmMessageListView::itemsRemoved()
   700 {
   717 {
   701     NM_FUNCTION;
   718     NM_FUNCTION;
   702     // Store model count
   719     // Store model count
   703     if (mMessageListModel){
   720     if (mMessageListModel){
   704         mPreviousModelCount=mMessageListModel->rowCount();    
   721         mPreviousModelCount=mMessageListModel->rowCount();
   705     }
   722     }
   706     if (mPreviousModelCount == 0){
   723     if (mPreviousModelCount == 0){
   707         showNoMessagesText();
   724         showNoMessagesText();
   708     }
   725     }
   709 }
   726 }
   732         mNoMessagesLabel->hide();
   749         mNoMessagesLabel->hide();
   733         mMessageListWidget->show();
   750         mMessageListWidget->show();
   734     }
   751     }
   735 }
   752 }
   736 
   753 
       
   754 /*!
       
   755     Updates sync icon based on sync status from the plugin.
       
   756 */
       
   757 void NmMessageListView::updateSyncIcon()
       
   758 {
       
   759     if (mStartParam) {
       
   760         NmSyncState syncState = mUiEngine.syncState(mStartParam->mailboxId());
       
   761         if (syncState==Synchronizing) {
       
   762             mUiEngine.enableSyncIndicator(true);
       
   763         } 
       
   764         else {
       
   765             mUiEngine.enableSyncIndicator(false);
       
   766         }
       
   767     }
       
   768 }
       
   769