emailuis/nmailui/src/nmmessagelistview.cpp
changeset 53 bf7eb7911fc5
parent 30 759dc5235cdb
child 54 997a02608b3a
equal deleted inserted replaced
30:759dc5235cdb 53:bf7eb7911fc5
    53 mNoMessagesLabel(NULL),
    53 mNoMessagesLabel(NULL),
    54 mFolderLabel(NULL),
    54 mFolderLabel(NULL),
    55 mSyncIcon(NULL),
    55 mSyncIcon(NULL),
    56 mViewReady(false),
    56 mViewReady(false),
    57 mCurrentFolderType(NmFolderInbox),
    57 mCurrentFolderType(NmFolderInbox),
    58 mSettingsLaunched(false)
    58 mSettingsLaunched(false),
       
    59 mPreviousModelCount(0)
    59 {
    60 {
    60     NM_FUNCTION;
    61     NM_FUNCTION;
    61 
    62 
    62     // Load view layout
    63     // Load view layout
    63     loadViewLayout();
    64     loadViewLayout();
       
    65     //create toolbar
       
    66     createToolBar();
    64     // Init tree view
    67     // Init tree view
    65     initTreeView();
    68     initTreeView();
    66     // set title
    69     // set title
    67     setMailboxName();
    70     setMailboxName();
    68     // Set folder name
    71     // Set folder name
   170 void NmMessageListView::viewReady()
   173 void NmMessageListView::viewReady()
   171 {
   174 {
   172     NM_FUNCTION;
   175     NM_FUNCTION;
   173 
   176 
   174     if (!mViewReady){
   177     if (!mViewReady){
   175         // Set mailbox name to title pane
       
   176         setMailboxName();
       
   177         //create toolbar
       
   178         createToolBar();
       
   179         // Refresh list
   178         // Refresh list
   180         QMetaObject::invokeMethod(this, "refreshList", Qt::QueuedConnection);
   179         QMetaObject::invokeMethod(this, "refreshList", Qt::QueuedConnection);
   181         mViewReady=true;
   180         mViewReady=true;
   182     }
   181     }
   183     mSettingsLaunched = false;
   182     mSettingsLaunched = false;
   227                 SLOT(itemActivated(const QModelIndex &)));
   226                 SLOT(itemActivated(const QModelIndex &)));
   228         QObject::connect(mMessageListWidget,
   227         QObject::connect(mMessageListWidget,
   229                 SIGNAL(longPressed(HbAbstractViewItem*, QPointF)), this,
   228                 SIGNAL(longPressed(HbAbstractViewItem*, QPointF)), this,
   230                 SLOT(showItemContextMenu(HbAbstractViewItem*, QPointF)));
   229                 SLOT(showItemContextMenu(HbAbstractViewItem*, QPointF)));
   231         mMessageListWidget->setFocus();
   230         mMessageListWidget->setFocus();
   232         mItemContextMenu = new HbMenu();
       
   233     }
   231     }
   234 }
   232 }
   235 
   233 
   236 
   234 
   237 /*!
   235 /*!
   312         QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   310         QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   313                 this, SLOT(itemsRemoved()));
   311                 this, SLOT(itemsRemoved()));
   314         QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   312         QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   315                 this, SLOT(reloadViewContents(NmUiStartParam*)));
   313                 this, SLOT(reloadViewContents(NmUiStartParam*)));
   316 
   314 
   317         if (mMessageListModel->rowCount()==0){
   315         mPreviousModelCount=mMessageListModel->rowCount();
       
   316         if (mPreviousModelCount==0){
   318             showNoMessagesText();
   317             showNoMessagesText();
   319         }
   318         }
   320         else{
   319         else{
   321             hideNoMessagesText();
   320             hideNoMessagesText();
   322         }
   321         }
   400     Long keypress handling 
   399     Long keypress handling 
   401 */
   400 */
   402 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords)
   401 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords)
   403 {
   402 {
   404     NM_FUNCTION;
   403     NM_FUNCTION;
   405 
   404    
   406     if (listViewItem) {
   405     if (listViewItem) {
       
   406         // Recreate item context menu each time it is called
       
   407         if (mItemContextMenu){
       
   408             mItemContextMenu->clearActions();
       
   409             delete mItemContextMenu;    
       
   410             mItemContextMenu=NULL;
       
   411         }
       
   412         mItemContextMenu = new HbMenu();
   407         // Store long press item for later use with response
   413         // Store long press item for later use with response
   408         mLongPressedItem = mMessageListModel->data(
   414         mLongPressedItem = mMessageListModel->data(
   409                 listViewItem->modelIndex(), Qt::DisplayRole).value<NmMessageListModelItem*>();
   415                 listViewItem->modelIndex(), Qt::DisplayRole).value<NmMessageListModelItem*>();
   410         if (mItemContextMenu && mLongPressedItem && mLongPressedItem->itemType() ==
   416         if (mItemContextMenu && mLongPressedItem && mLongPressedItem->itemType() ==
   411             NmMessageListModelItem::NmMessageItemMessage) {
   417             NmMessageListModelItem::NmMessageItemMessage) {
   572     // Handle toolbar commands here
   578     // Handle toolbar commands here
   573     else if ( actionResponse.menuType() == NmActionToolbar ) {
   579     else if ( actionResponse.menuType() == NmActionToolbar ) {
   574         if ( actionResponse.responseCommand() == NmActionResponseCommandNewMail ) {
   580         if ( actionResponse.responseCommand() == NmActionResponseCommandNewMail ) {
   575             // Check that given start response has mailbox and folder id's
   581             // Check that given start response has mailbox and folder id's
   576             if (actionResponse.mailboxId()!=0){
   582             if (actionResponse.mailboxId()!=0){
   577                 if (mUiEngine.isSendingMessage()) {
   583                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   578                     // sending is ongoing so just show a note
   584                         actionResponse.mailboxId(), mStartParam->folderId());
   579                     QString noteText = hbTrId("txt_mail_dialog_still_sending");
   585                 // startParam ownerhips transfers
   580 
   586                 mApplication.enterNmUiView(startParam);
   581                     // get message subject from the message being sent
       
   582                     const NmMessage *message = mUiEngine.messageBeingSent();
       
   583                     if (message) {
       
   584                         noteText = noteText.arg(NmUtilities::truncate(message->envelope().subject(), 20));
       
   585                     }
       
   586                     HbMessageBox::warning(noteText);
       
   587                 }
       
   588                 else {
       
   589                     NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
       
   590                             actionResponse.mailboxId(), mStartParam->folderId());
       
   591                     // startParam ownerhips transfers
       
   592                     mApplication.enterNmUiView(startParam);
       
   593                 }
       
   594             }
   587             }
   595         }
   588         }
   596         if (actionResponse.responseCommand() == NmActionResponseCommandSearch) {
   589         if (actionResponse.responseCommand() == NmActionResponseCommandSearch) {
   597             // Check that the given start response has mailbox and folder IDs.
   590             // Check that the given start response has mailbox and folder IDs.
   598             if (actionResponse.mailboxId() != 0) {
   591             if (actionResponse.mailboxId() != 0) {
   599                 if (mUiEngine.isSendingMessage()) {
   592                 NmUiStartParam *startParam =
   600                     // Sending is ongoing so just show a note.
   593                     new NmUiStartParam(NmUiViewMessageSearchList,
   601                     QString noteText = hbTrId("txt_mail_dialog_still_sending");
   594                                        actionResponse.mailboxId(),
   602 
   595                                        mStartParam->folderId());
   603                     // Get the message subject from the message being sent.
   596 
   604                     const NmMessage *message = mUiEngine.messageBeingSent();
   597                 // startParam ownership transfers.
   605 
   598                 mApplication.enterNmUiView(startParam);
   606                     if (message) {
       
   607                         noteText = noteText.arg(
       
   608                             NmUtilities::truncate(message->envelope().subject(), 20));
       
   609                     }
       
   610 
       
   611                     HbMessageBox::warning(noteText);
       
   612                 }
       
   613                 else {
       
   614                     NmUiStartParam *startParam =
       
   615                         new NmUiStartParam(NmUiViewMessageSearchList,
       
   616                                            actionResponse.mailboxId(),
       
   617                                            mStartParam->folderId());
       
   618 
       
   619                     // startParam ownership transfers.
       
   620                     mApplication.enterNmUiView(startParam);
       
   621                 }
       
   622             }
   599             }
   623         }
   600         }
   624     }
   601     }
   625 }
   602 }
   626 
   603 
   720     NM_FUNCTION;
   697     NM_FUNCTION;
   721 
   698 
   722     Q_UNUSED(parent);
   699     Q_UNUSED(parent);
   723     Q_UNUSED(end);
   700     Q_UNUSED(end);
   724 
   701 
   725     // If "no messages" label is shown, hide it and display the message list
   702     // Hide no messages if previous model count has been zero
   726     // widget.
   703     // and new items have been added to the list
   727     if (mNoMessagesLabel && mNoMessagesLabel->isVisible()) {
   704     if (mPreviousModelCount==0) {
   728         mNoMessagesLabel->hide();
   705         hideNoMessagesText();
   729         mMessageListWidget->show();
       
   730     }
   706     }
   731 
   707 
   732     // Make sure the top of the list is kept visible by scrolling back to the
   708     // Make sure the top of the list is kept visible by scrolling back to the
   733     // top if necessary.
   709     // top if necessary.
   734     if (start == 0 && mMessageListWidget) {
   710     if (start == 0 && mMessageListWidget) {
   747 
   723 
   748                 index = previous;
   724                 index = previous;
   749             }
   725             }
   750         }
   726         }
   751     }
   727     }
       
   728     // Store model count
       
   729     if (mMessageListModel){
       
   730         mPreviousModelCount=mMessageListModel->rowCount();    
       
   731     }
   752 }
   732 }
   753 
   733 
   754 
   734 
   755 /*!
   735 /*!
   756     Observe items removed
   736     Observe items removed
   757 */
   737 */
   758 void NmMessageListView::itemsRemoved()
   738 void NmMessageListView::itemsRemoved()
   759 {
   739 {
   760     NM_FUNCTION;
   740     NM_FUNCTION;
   761 
   741     // Store model count
   762     if (mMessageListModel && mMessageListModel->rowCount() == 0){
   742     if (mMessageListModel){
       
   743         mPreviousModelCount=mMessageListModel->rowCount();    
       
   744     }
       
   745     if (mPreviousModelCount == 0){
   763         showNoMessagesText();
   746         showNoMessagesText();
   764     }
   747     }
   765 }
   748 }
   766 
   749 
   767 /*!
   750 /*!