emailuis/nmailui/src/nmmessagelistview.cpp
changeset 51 d845db10c0d4
parent 48 10eaf342f539
child 56 15bc1d5d6267
equal deleted inserted replaced
49:00c7ae862740 51:d845db10c0d4
    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 /*!
   202 /*!
   200 /*!
   203     initTreeView
   201     initTreeView
   204 */
   202 */
   205 void NmMessageListView::initTreeView()
   203 void NmMessageListView::initTreeView()
   206 {
   204 {
   207     NM_FUNCTION; 
   205     NM_FUNCTION;
   208 
   206 
   209     // Get mailbox widget pointer and set parameters
   207     // Get mailbox widget pointer and set parameters
   210     if (mMessageListWidget){
   208     if (mMessageListWidget){
   211         QObject::connect(mMessageListWidget,
   209         QObject::connect(mMessageListWidget,
   212                 SIGNAL(activated(const QModelIndex &)), this,
   210                 SIGNAL(activated(const QModelIndex &)), this,
   235         // Delete existing start parameter data
   233         // Delete existing start parameter data
   236         delete mStartParam;
   234         delete mStartParam;
   237         mStartParam=NULL;
   235         mStartParam=NULL;
   238         // Store new start parameter data
   236         // Store new start parameter data
   239         mStartParam=startParam;
   237         mStartParam=startParam;
   240         // Update the model with new parameters
   238         // Disconnect signals from previous model
       
   239         QObject::disconnect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
       
   240                 this, SLOT(itemsAdded(const QModelIndex&,int,int)));
       
   241         QObject::disconnect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
       
   242                 this, SLOT(itemsRemoved()));
       
   243         QObject::disconnect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
       
   244                 this, SLOT(reloadViewContents(NmUiStartParam*)));
       
   245         // Update model pointer and refresh mailbox with new model
   241         mMessageListModel = &mUiEngine.messageListModel(startParam->mailboxId(), startParam->folderId());
   246         mMessageListModel = &mUiEngine.messageListModel(startParam->mailboxId(), startParam->folderId());
   242         refreshList();
   247         refreshList();
   243         // Refresh the mailboxname
   248         // Refresh the mailboxname
   244         setMailboxName();
   249         setMailboxName();
   245     }
   250     }
   248         // Unused start parameter needs to be deleted
   253         // Unused start parameter needs to be deleted
   249         delete startParam;
   254         delete startParam;
   250     }
   255     }
   251 }
   256 }
   252 
   257 
   253  
   258 
   254 /*!
   259 /*!
   255     Return view id
   260     Return view id
   256 */
   261 */
   257 NmUiViewId NmMessageListView::nmailViewId() const
   262 NmUiViewId NmMessageListView::nmailViewId() const
   258 {
   263 {
   267 void NmMessageListView::refreshList()
   272 void NmMessageListView::refreshList()
   268 {
   273 {
   269     NM_FUNCTION;
   274     NM_FUNCTION;
   270 
   275 
   271     if (mMessageListModel) {
   276     if (mMessageListModel) {
   272         NmId mailboxId = mMessageListModel->currentMailboxId();    
   277         NmId mailboxId = mMessageListModel->currentMailboxId();
   273         // In each refresh, e.g. in folder change the UI signals
   278         // In each refresh, e.g. in folder change the UI signals
   274         // lower layer about the folder that has been opened.
   279         // lower layer about the folder that has been opened.
   275         if (mStartParam){
   280         if (mStartParam){
   276             mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId());
   281             mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId());
   277             
   282 
   278             NmFolderType folderType = mUiEngine.folderTypeById(mStartParam->mailboxId(),
   283             NmFolderType folderType = mUiEngine.folderTypeById(mStartParam->mailboxId(),
   279                                               mStartParam->folderId());
   284                                               mStartParam->folderId());
   280             if (folderType == NmFolderInbox) { // If the new folder is an inbox, first automatic sync should be shown
   285             if (folderType == NmFolderInbox) { // If the new folder is an inbox, first automatic sync should be shown
   281                 mIsFirstSyncInMessageList = true; 
   286                 mIsFirstSyncInMessageList = true;
   282             }
   287             }
   283         }
   288         }
   284 
   289 
   285         // Set item model to message list widget
   290         // Set item model to message list widget
   286         if (mMessageListWidget) {
   291         if (mMessageListWidget) {
   287             mMessageListWidget->setModel(static_cast<QStandardItemModel*>(mMessageListModel));
   292             mMessageListWidget->setModel(static_cast<QStandardItemModel*>(mMessageListModel));
   288             QObject::connect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
   293             QObject::connect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
   289                     this, SLOT(itemsAdded(const QModelIndex&,int,int)));
   294                     this, SLOT(itemsAdded(const QModelIndex&,int,int)),Qt::UniqueConnection);
   290             QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   295             QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   291                     this, SLOT(itemsRemoved()));
   296                     this, SLOT(itemsRemoved()),Qt::UniqueConnection);
   292             QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   297             QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   293                     this, SLOT(reloadViewContents(NmUiStartParam*)));
   298                     this, SLOT(reloadViewContents(NmUiStartParam*)),Qt::UniqueConnection);
   294 
   299 
   295             mPreviousModelCount=mMessageListModel->rowCount();
   300             mPreviousModelCount=mMessageListModel->rowCount();
   296             if (mPreviousModelCount==0){
   301             if (mPreviousModelCount==0){
   297                 showNoMessagesText();
   302                 showNoMessagesText();
   298             }
   303             }
   299             else{
   304             else{
   300                 hideNoMessagesText();
   305                 hideNoMessagesText();
   301             }
   306             }
   302         }    
   307         }
   303     }
   308     }
   304 }
   309 }
   305 
   310 
   306 /*!
   311 /*!
   307     Sync state event handling
   312     Sync state event handling
   308 */
   313 */
   309 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId & mailboxId)
   314 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId &mailboxId)
   310 {
   315 {
   311     NM_FUNCTION;
   316     NM_FUNCTION;
   312     if (mMessageListModel && mailboxId == mMessageListModel->currentMailboxId()) {
   317     if (mMessageListModel && mailboxId == mMessageListModel->currentMailboxId()) {
   313         if (syncState == Synchronizing) {
   318         if (syncState == Synchronizing) {
   314              // before first sync inbox id might be zero
   319              // before first sync inbox id might be zero
   320                 mStartParam->setFolderId(folderId);
   325                 mStartParam->setFolderId(folderId);
   321             }
   326             }
   322             // Show sync icon only for the first automatic sync after opening message list.
   327             // 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.
   328             // Sync icon for manual sync is shown in NmUiEngine::refreshMailbox, not here.
   324             if (mIsFirstSyncInMessageList) {
   329             if (mIsFirstSyncInMessageList) {
   325                 HbIndicator indicator;
   330 				mUiEngine.enableSyncIndicator(true);
   326                 indicator.activate(syncIndicatorName, QVariant());
       
   327                 mIsFirstSyncInMessageList = false;
   331                 mIsFirstSyncInMessageList = false;
   328             }
   332             }
   329         }
   333         }
   330     }
   334     }
   331 }
   335 }
   332 
   336 
   333 /*! 
   337 /*!
   334     folder selection handling within current mailbox
   338     folder selection handling within current mailbox
   335 */
   339 */
   336 void NmMessageListView::folderSelected()
   340 void NmMessageListView::folderSelected()
   337 {
   341 {
   338     NM_FUNCTION;
   342     NM_FUNCTION;
   355     }
   359     }
   356 }
   360 }
   357 
   361 
   358 
   362 
   359 /*!
   363 /*!
   360     Long keypress handling 
   364     Long keypress handling
   361 */
   365 */
   362 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords)
   366 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords)
   363 {
   367 {
   364     NM_FUNCTION;
   368     NM_FUNCTION;
   365    
   369 
   366     if (listViewItem) {
   370     if (listViewItem) {
   367         // Recreate item context menu each time it is called
   371         // Recreate item context menu each time it is called
   368         if (mItemContextMenu){
   372         if (mItemContextMenu){
   369             mItemContextMenu->clearActions();
   373             mItemContextMenu->clearActions();
   370             delete mItemContextMenu;    
   374             delete mItemContextMenu;
   371             mItemContextMenu=NULL;
   375             mItemContextMenu=NULL;
   372         }
   376         }
   373         mItemContextMenu = new HbMenu();
   377         mItemContextMenu = new HbMenu();
   374         // Store long press item for later use with response
   378         // Store long press item for later use with response
   375         mLongPressedItem = mMessageListModel->data(
   379         mLongPressedItem = mMessageListModel->data(
   648 /*!
   652 /*!
   649     Handles the addition of a new item. Makes sure the message list widget is
   653     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.
   654     visible and keeps the scroll position on the top of the list.
   651 
   655 
   652     \param parent Not used.
   656     \param parent Not used.
   653     \param start 
   657     \param start
   654     \param end Not used.
   658     \param end Not used.
   655 */
   659 */
   656 void NmMessageListView::itemsAdded(const QModelIndex &parent, int start, int end)
   660 void NmMessageListView::itemsAdded(const QModelIndex &parent, int start, int end)
   657 {
   661 {
   658     NM_FUNCTION;
   662     NM_FUNCTION;
   686             }
   690             }
   687         }
   691         }
   688     }
   692     }
   689     // Store model count
   693     // Store model count
   690     if (mMessageListModel){
   694     if (mMessageListModel){
   691         mPreviousModelCount=mMessageListModel->rowCount();    
   695         mPreviousModelCount=mMessageListModel->rowCount();
   692     }
   696     }
   693 }
   697 }
   694 
   698 
   695 
   699 
   696 /*!
   700 /*!
   699 void NmMessageListView::itemsRemoved()
   703 void NmMessageListView::itemsRemoved()
   700 {
   704 {
   701     NM_FUNCTION;
   705     NM_FUNCTION;
   702     // Store model count
   706     // Store model count
   703     if (mMessageListModel){
   707     if (mMessageListModel){
   704         mPreviousModelCount=mMessageListModel->rowCount();    
   708         mPreviousModelCount=mMessageListModel->rowCount();
   705     }
   709     }
   706     if (mPreviousModelCount == 0){
   710     if (mPreviousModelCount == 0){
   707         showNoMessagesText();
   711         showNoMessagesText();
   708     }
   712     }
   709 }
   713 }