emailuis/nmailui/src/nmmessagelistview.cpp
changeset 43 99bcbff212ad
parent 40 2c62ef3caffd
child 44 c2d07d913565
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
    18 static const char *NMUI_MESSAGE_LIST_VIEW_XML = ":/docml/nmmessagelistview.docml";
    18 static const char *NMUI_MESSAGE_LIST_VIEW_XML = ":/docml/nmmessagelistview.docml";
    19 static const char *NMUI_MESSAGE_LIST_VIEW = "NmMessageListView";
    19 static const char *NMUI_MESSAGE_LIST_VIEW = "NmMessageListView";
    20 static const char *NMUI_MESSAGE_LIST_TREE_LIST = "MessageTreeList";
    20 static const char *NMUI_MESSAGE_LIST_TREE_LIST = "MessageTreeList";
    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 static const char *NMUI_MESSAGE_LIST_SYNC_ICON = "syncIcon";
    23 // Old sync icon implementation commented out but preserved so it could be put back if need be
       
    24 // static const char *NMUI_MESSAGE_LIST_SYNC_ICON = "syncIcon";
    24 
    25 
    25 #include "nmuiheaders.h"
    26 #include "nmuiheaders.h"
    26 
    27 
    27 /*!
    28 /*! 
    28 	\class NmMessageListView
    29 	\class NmMessageListView
    29 	\brief Message list view
    30 	\brief Message list view
    30 */
    31 */
    31 
    32 
    32 /*!
    33 /*!
    35 NmMessageListView::NmMessageListView(
    36 NmMessageListView::NmMessageListView(
    36     NmApplication &application,
    37     NmApplication &application,
    37     NmUiStartParam* startParam,
    38     NmUiStartParam* startParam,
    38     NmUiEngine &uiEngine,
    39     NmUiEngine &uiEngine,
    39     NmMailboxListModel &mailboxListModel,
    40     NmMailboxListModel &mailboxListModel,
    40     NmMessageListModel &messageListModel,
    41     NmMessageListModel *messageListModel,
    41     HbDocumentLoader *documentLoader,
    42     HbDocumentLoader *documentLoader,
    42     QGraphicsItem *parent)
    43     QGraphicsItem *parent)
    43 : NmBaseView(startParam, application, parent),
    44 : NmBaseView(startParam, application, parent),
    44 mApplication(application),
    45 mApplication(application),
    45 mMessageListWidget(NULL),
    46 mMessageListWidget(NULL),
    54 mSyncIcon(NULL),
    55 mSyncIcon(NULL),
    55 mViewReady(false),
    56 mViewReady(false),
    56 mCurrentFolderType(NmFolderInbox),
    57 mCurrentFolderType(NmFolderInbox),
    57 mSettingsLaunched(false)
    58 mSettingsLaunched(false)
    58 {
    59 {
       
    60     NM_FUNCTION;
       
    61 
    59     // Load view layout
    62     // Load view layout
    60     loadViewLayout();
    63     loadViewLayout();
    61     // Init tree view
    64     // Init tree view
    62     initTreeView();
    65     initTreeView();
       
    66     // set title
       
    67     setMailboxName();
    63     // Set folder name
    68     // Set folder name
    64     setFolderName();
    69     setFolderName();
    65 }
    70 }
    66 
    71 
    67 /*!
    72 /*!
    68     Destructor
    73     Destructor
    69 */
    74 */
    70 NmMessageListView::~NmMessageListView()
    75 NmMessageListView::~NmMessageListView()
    71 {
    76 {
       
    77     NM_FUNCTION;
       
    78 
    72     delete mDocumentLoader;
    79     delete mDocumentLoader;
    73     mWidgetList.clear();
    80     mWidgetList.clear();
    74     if (mItemContextMenu){
    81     if (mItemContextMenu){
    75         mItemContextMenu->clearActions();
    82         mItemContextMenu->clearActions();
    76     }
    83     }
    80 /*!
    87 /*!
    81     View layout loading from XML
    88     View layout loading from XML
    82 */
    89 */
    83 void NmMessageListView::loadViewLayout()
    90 void NmMessageListView::loadViewLayout()
    84 {
    91 {
       
    92     NM_FUNCTION;
       
    93 
    85     // Use document loader to load the view
    94     // Use document loader to load the view
    86     bool ok = false;
    95     bool ok = false;
    87     setObjectName(QString(NMUI_MESSAGE_LIST_VIEW));
    96     setObjectName(QString(NMUI_MESSAGE_LIST_VIEW));
    88     QObjectList objectList;
    97     QObjectList objectList;
    89     objectList.append(this);
    98     objectList.append(this);
    96 
   105 
    97     if (ok == true && mWidgetList.count()) {
   106     if (ok == true && mWidgetList.count()) {
    98         // Get message list widget
   107         // Get message list widget
    99         mMessageListWidget = qobject_cast<HbTreeView *>
   108         mMessageListWidget = qobject_cast<HbTreeView *>
   100             (mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_TREE_LIST));
   109             (mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_TREE_LIST));
       
   110 
   101         if (mMessageListWidget) {
   111         if (mMessageListWidget) {
   102             NMLOG("nmailui: List object loaded");
   112             NM_COMMENT("nmailui: list object loaded");
       
   113 
   103             // Set item prototype.
   114             // Set item prototype.
   104             mMessageListWidget->setItemPrototype(new NmMessageListViewItem());
   115             mMessageListWidget->setItemPrototype(new NmMessageListViewItem());
       
   116 
       
   117             // Set the list widget properties.
   105             mMessageListWidget->setItemRecycling(true);
   118             mMessageListWidget->setItemRecycling(true);
   106             mMessageListWidget->contentWidget()->setProperty("indentation", 0);
   119             mMessageListWidget->contentWidget()->setProperty("indentation", 0);
   107             mMessageListWidget->setScrollDirections(Qt::Vertical);
   120             mMessageListWidget->setScrollDirections(Qt::Vertical);
   108             mMessageListWidget->setClampingStyle(HbScrollArea::BounceBackClamping);
   121             mMessageListWidget->setClampingStyle(HbScrollArea::BounceBackClamping);
   109             mMessageListWidget->setFrictionEnabled(true);
   122             mMessageListWidget->setFrictionEnabled(true);
       
   123 
       
   124             // Enable animations to display an email as soon as it is added to
       
   125             // the list.
       
   126             mMessageListWidget->setEnabledAnimations(HbAbstractItemView::Appear &
       
   127                                                      HbAbstractItemView::Expand);
   110         }
   128         }
   111         else {
   129         else {
   112             NMLOG("nmailui: List object loading failed");
   130             NM_ERROR(1,"nmailui: list object loading failed");
   113         }
   131         }
       
   132 
   114         mNoMessagesLabel = qobject_cast<HbLabel *>
   133         mNoMessagesLabel = qobject_cast<HbLabel *>
   115             (mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_NO_MESSAGES));
   134             (mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_NO_MESSAGES));
   116         if (mNoMessagesLabel) {
   135         if (mNoMessagesLabel) {
   117             mNoMessagesLabel->hide();
   136             mNoMessagesLabel->hide();
   118         }
   137         }
   119         else{
   138         else{
   120             NMLOG("nmailui: (no messages) object loading failed");
   139             NM_ERROR(1,"nmailui: (no messages) object loading failed");
   121         }
   140         }
   122 
   141 
   123         mFolderLabel = qobject_cast<HbGroupBox *>(mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_FOLDER_LABEL));
   142         mFolderLabel = qobject_cast<HbGroupBox *>(mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_FOLDER_LABEL));
   124 
   143 
   125         // Disable the old sync icon implementation for the time being
   144         // Disable the old sync icon implementation for the time being (commment out loading the icon here)
   126         mSyncIcon = qobject_cast<HbLabel *>(mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_SYNC_ICON));
   145         //mSyncIcon = qobject_cast<HbLabel *>(mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_SYNC_ICON));
   127         if (mSyncIcon) {
   146         if (mSyncIcon) {
   128             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOffline));
   147             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOffline));
   129         }
   148         }
   130 
   149 
   131         // Connect options menu about to show to create options menu function
   150         // Connect options menu about to show to create options menu function
   139         // Menu needs one dummy item so that aboutToShow signal is emitted.
   158         // Menu needs one dummy item so that aboutToShow signal is emitted.
   140         NmAction *dummy = new NmAction(0);
   159         NmAction *dummy = new NmAction(0);
   141         menu()->addAction(dummy);
   160         menu()->addAction(dummy);
   142     }
   161     }
   143     else {
   162     else {
   144         NMLOG("nmailui: Resource loading failed");
   163         NM_ERROR(1,"nmailui: resource loading failed");
   145     }
   164     }
   146 }
   165 }
   147 
   166 
   148 /*!
   167 /*!
   149     Lazy loading when view layout has been loaded
   168     Lazy loading when view layout has been loaded
   150 */
   169 */
   151 void NmMessageListView::viewReady()
   170 void NmMessageListView::viewReady()
   152 {
   171 {
       
   172     NM_FUNCTION;
       
   173 
   153     if (!mViewReady){
   174     if (!mViewReady){
   154         // Set mailbox name to title pane
   175         // Set mailbox name to title pane
   155         setMailboxName();
   176         setMailboxName();
   156         //create toolbar
   177         //create toolbar
   157         createToolBar();
   178         createToolBar();
   165 /*!
   186 /*!
   166     Getter for currently displayed folder type
   187     Getter for currently displayed folder type
   167 */
   188 */
   168 NmFolderType NmMessageListView::folderType()
   189 NmFolderType NmMessageListView::folderType()
   169 {
   190 {
       
   191     NM_FUNCTION;
       
   192 
   170     return mCurrentFolderType;
   193     return mCurrentFolderType;
   171 }
   194 }
   172 
   195 
   173 /*!
   196 /*!
   174     okToExitView. Message list view determines whether it is 
   197     okToExitView. Message list view determines whether it is
   175     ok to exit view and calls mapplication popview.
   198     ok to exit view and calls mapplication popview.
   176 */
   199 */
   177 void NmMessageListView::okToExitView()
   200 void NmMessageListView::okToExitView()
   178 {
   201 {
       
   202     NM_FUNCTION;
       
   203 
   179     // Close view if current folder is inbox
   204     // Close view if current folder is inbox
   180     if (mCurrentFolderType==NmFolderInbox){
   205     if (mCurrentFolderType==NmFolderInbox){
   181         mApplication.popView();
   206         mApplication.popView();
   182     }
   207     }
   183     // Switch to inbox 
   208     // Switch to inbox
   184     else{
   209     else{
   185         NmId mailboxId = mStartParam->mailboxId();
   210         mSelectedMailboxId=mStartParam->mailboxId();
   186         NmId folderId = mUiEngine.standardFolderId(mailboxId,NmFolderInbox);
   211         mSelectedFolderId=mUiEngine.standardFolderId(mSelectedMailboxId,NmFolderInbox);
   187         folderSelected(mailboxId,folderId);
   212         QMetaObject::invokeMethod(this, "folderSelected", Qt::QueuedConnection);
   188     }
   213     }
   189 }
   214 }
   190 
   215 
   191 /*!
   216 /*!
   192     initTreeView
   217     initTreeView
   193 */
   218 */
   194 void NmMessageListView::initTreeView()
   219 void NmMessageListView::initTreeView()
   195 {
   220 {
       
   221     NM_FUNCTION; 
       
   222 
   196     // Get mailbox widget pointer and set parameters
   223     // Get mailbox widget pointer and set parameters
   197     if (mMessageListWidget){
   224     if (mMessageListWidget){
   198         QObject::connect(mMessageListWidget,
   225         QObject::connect(mMessageListWidget,
   199                 SIGNAL(activated(const QModelIndex &)), this,
   226                 SIGNAL(activated(const QModelIndex &)), this,
   200                 SLOT(itemActivated(const QModelIndex &)));
   227                 SLOT(itemActivated(const QModelIndex &)));
   212     Typically when view is already open and external view activation occurs
   239     Typically when view is already open and external view activation occurs
   213     for this same view
   240     for this same view
   214 */
   241 */
   215 void NmMessageListView::reloadViewContents(NmUiStartParam* startParam)
   242 void NmMessageListView::reloadViewContents(NmUiStartParam* startParam)
   216 {
   243 {
       
   244     NM_FUNCTION;
       
   245 
   217     // Check start parameter validity, message view cannot
   246     // Check start parameter validity, message view cannot
   218     // be updated if given parameter is zero.
   247     // be updated if given parameter is zero.
   219     if (startParam&&startParam->viewId()==NmUiViewMessageList&&
   248     if (startParam&&startParam->viewId()==NmUiViewMessageList&&
   220         startParam->folderId()!=0) {
   249         startParam->folderId()!=0) {
   221         // Delete existing start parameter data
   250         // Delete existing start parameter data
   222         delete mStartParam;
   251         delete mStartParam;
   223         mStartParam=NULL;
   252         mStartParam=NULL;
   224         // Store new start parameter data
   253         // Store new start parameter data
   225         mStartParam=startParam;
   254         mStartParam=startParam;
   226         // Update the model with new parameters
   255         // Update the model with new parameters
   227         mUiEngine.messageListModel(startParam->mailboxId(), startParam->folderId());
   256         mMessageListModel = &mUiEngine.messageListModel(startParam->mailboxId(), startParam->folderId());
   228         refreshList();
   257         refreshList();
   229         // Refresh the mailboxname
   258         // Refresh the mailboxname
   230         setMailboxName();
   259         setMailboxName();
   231     }
   260     }
   232     else {
   261     else {
   233         NMLOG("nmailui: Invalid message list start parameter");
   262         NM_ERROR(1,"nmailui: invalid message list start parameter");
   234         // Unused start parameter needs to be deleted
   263         // Unused start parameter needs to be deleted
   235         delete startParam;
   264         delete startParam;
   236     }
   265     }
   237 }
   266 }
   238 
   267 
   239 
   268  
   240 /*!
   269 /*!
   241     Return view id
   270     Return view id
   242 */
   271 */
   243 NmUiViewId NmMessageListView::nmailViewId() const
   272 NmUiViewId NmMessageListView::nmailViewId() const
   244 {
   273 {
       
   274     NM_FUNCTION;
       
   275 
   245     return NmUiViewMessageList;
   276     return NmUiViewMessageList;
   246 }
   277 }
   247 
   278 
   248 /*!
   279 /*!
   249     Refresh list
   280     Refresh list
   250 */
   281 */
   251 void NmMessageListView::refreshList()
   282 void NmMessageListView::refreshList()
   252 {
   283 {
   253     NmId mailboxId = mMessageListModel.currentMailboxId();
   284     NM_FUNCTION;
   254     if (mSyncIcon && mailboxId == mMessageListModel.currentMailboxId()) {
   285 
       
   286     NmId mailboxId = mMessageListModel->currentMailboxId();
       
   287     if (mSyncIcon && mailboxId == mMessageListModel->currentMailboxId()) {
   255         if (mUiEngine.syncState(mailboxId) == Synchronizing) {
   288         if (mUiEngine.syncState(mailboxId) == Synchronizing) {
   256             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconSynching));
   289             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconSynching));
   257         }
   290         }
   258         else {
   291         else {
   259             if (mUiEngine.connectionState(mailboxId) == Connected) {
   292             if (mUiEngine.connectionState(mailboxId) == Connected) {
   271         mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId());
   304         mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId());
   272     }
   305     }
   273 
   306 
   274     // Set item model to message list widget
   307     // Set item model to message list widget
   275     if (mMessageListWidget) {
   308     if (mMessageListWidget) {
   276         mMessageListWidget->setModel(static_cast<QStandardItemModel*>(&mMessageListModel));
   309         mMessageListWidget->setModel(static_cast<QStandardItemModel*>(mMessageListModel));
   277         QObject::connect(&mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
   310         QObject::connect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
   278                 this, SLOT(itemsAdded(const QModelIndex&,int,int)));
   311                 this, SLOT(itemsAdded(const QModelIndex&,int,int)));
   279         QObject::connect(&mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   312         QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   280                 this, SLOT(itemsRemoved()));
   313                 this, SLOT(itemsRemoved()));
   281         QObject::connect(&mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   314         QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   282                 this, SLOT(reloadViewContents(NmUiStartParam*)));
   315                 this, SLOT(reloadViewContents(NmUiStartParam*)));
   283 
   316 
   284         if (mMessageListModel.rowCount()==0){
   317         if (mMessageListModel->rowCount()==0){
   285             showNoMessagesText();
   318             showNoMessagesText();
   286         }
   319         }
       
   320         else{
       
   321             hideNoMessagesText();
       
   322         }
   287     }
   323     }
   288 }
   324 }
   289 
   325 
   290 /*!
   326 /*!
   291     Sync state event handling
   327     Sync state event handling
   292 */
   328 */
   293 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId & mailboxId)
   329 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId & mailboxId)
   294 {
   330 {
   295     if (mSyncIcon && mailboxId == mMessageListModel.currentMailboxId()) {
   331     NM_FUNCTION;
       
   332 
       
   333     if (mSyncIcon && mailboxId == mMessageListModel->currentMailboxId()) {
   296         if (syncState == Synchronizing) {
   334         if (syncState == Synchronizing) {
   297             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconSynching));
   335             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconSynching));
   298             // before first sync inbox id might be zero
   336             // before first sync inbox id might be zero
   299             if (mStartParam->folderId() == 0) {
   337             if (mStartParam->folderId() == 0) {
   300                 // after sync inbox id should be updated to correct value
   338                 // after sync inbox id should be updated to correct value
   318 /*!
   356 /*!
   319     Connection event handling
   357     Connection event handling
   320 */
   358 */
   321 void NmMessageListView::handleConnectionEvent(NmConnectState connectState, const NmId &mailboxId)
   359 void NmMessageListView::handleConnectionEvent(NmConnectState connectState, const NmId &mailboxId)
   322 {
   360 {
   323     if (mSyncIcon && mailboxId == mMessageListModel.currentMailboxId() && mUiEngine.syncState(mailboxId) != Synchronizing) {
   361     NM_FUNCTION;
       
   362 
       
   363     if (mSyncIcon && mailboxId == mMessageListModel->currentMailboxId() && mUiEngine.syncState(mailboxId) != Synchronizing) {
   324         if (connectState == Connected) {
   364         if (connectState == Connected) {
   325             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOnline));
   365             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOnline));
   326         }
   366         }
   327         else {
   367         else {
   328             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOffline));
   368             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOffline));
   329         }
   369         }
   330     }
   370     }
   331 }
   371 }
   332 
   372 
   333 /*!
   373 /*! 
   334     folder selection handling within current mailbox
   374     folder selection handling within current mailbox
   335 */
   375 */
   336 void NmMessageListView::folderSelected(NmId mailbox, NmId folder)
   376 void NmMessageListView::folderSelected()
   337 {
   377 {
       
   378     NM_FUNCTION;
       
   379 
   338     // Reload view contents with new startparams if mailbox or folder
   380     // Reload view contents with new startparams if mailbox or folder
   339     // id is different than current values.
   381     // id is different than current values.
   340     if (mStartParam && (mStartParam->mailboxId()!=mailbox||mStartParam->folderId()!=folder)){
   382     if (mStartParam && (mStartParam->mailboxId()!=mSelectedMailboxId||
       
   383                         mStartParam->folderId()!=mSelectedFolderId)){
   341         // Create start params
   384         // Create start params
   342         NmUiStartParam* startParam = new NmUiStartParam(NmUiViewMessageList,mailbox,folder);    
   385         NmUiStartParam* startParam = new NmUiStartParam(NmUiViewMessageList,
       
   386                                                         mSelectedMailboxId,
       
   387                                                         mSelectedFolderId);
   343         // Store active folder type
   388         // Store active folder type
   344         mCurrentFolderType = mUiEngine.folderTypeById(startParam->mailboxId(),startParam->folderId());  
   389         mCurrentFolderType = mUiEngine.folderTypeById(startParam->mailboxId(),startParam->folderId());
   345         // Reload view, ownership of the startparams is passed and old startparams
   390         // Reload view, ownership of the startparams is passed and old startparams
   346         // are deleted within reloadViewContents function
   391         // are deleted within reloadViewContents function
   347         reloadViewContents(startParam);
   392         reloadViewContents(startParam);
   348         //Set folder text to status bar
   393         //Set folder text to status bar
   349         setFolderName();
   394         setFolderName();
   350     }
   395     }
   351 }
   396 }
   352 
   397 
   353 
   398 
   354 /*!
   399 /*!
   355     Long keypress handling
   400     Long keypress handling 
   356 */
   401 */
   357 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords)
   402 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords)
   358 {
   403 {
       
   404     NM_FUNCTION;
       
   405 
   359     if (listViewItem) {
   406     if (listViewItem) {
   360         // Store long press item for later use with response
   407         // Store long press item for later use with response
   361         mLongPressedItem = mMessageListModel.data(
   408         mLongPressedItem = mMessageListModel->data(
   362                 listViewItem->modelIndex(), Qt::DisplayRole).value<NmMessageListModelItem*>();
   409                 listViewItem->modelIndex(), Qt::DisplayRole).value<NmMessageListModelItem*>();
   363         if (mItemContextMenu && mLongPressedItem && mLongPressedItem->itemType() ==
   410         if (mItemContextMenu && mLongPressedItem && mLongPressedItem->itemType() ==
   364             NmMessageListModelItem::NmMessageItemMessage) {
   411             NmMessageListModelItem::NmMessageItemMessage) {
   365     
   412 
   366             // Clear previous items from context menu
   413             // Clear previous items from context menu
   367             mItemContextMenu->clearActions();
   414             mItemContextMenu->clearActions();
   368             NmUiExtensionManager &extMngr = mApplication.extManager();
   415             NmUiExtensionManager &extMngr = mApplication.extManager();
   369             QList<NmAction*> list;
   416             QList<NmAction*> list;
   370             // Fetch items from extension based on item
   417             // Fetch items from extension based on item
   388     Item activation handling. Expand/collapse for title dividers
   435     Item activation handling. Expand/collapse for title dividers
   389     opening for mail items
   436     opening for mail items
   390 */
   437 */
   391 void NmMessageListView::itemActivated(const QModelIndex &index)
   438 void NmMessageListView::itemActivated(const QModelIndex &index)
   392 {
   439 {
       
   440     NM_FUNCTION;
       
   441 
   393     mActivatedIndex = index;
   442     mActivatedIndex = index;
   394     QMetaObject::invokeMethod(this, "handleSelection", Qt::QueuedConnection);
   443     QMetaObject::invokeMethod(this, "handleSelection", Qt::QueuedConnection);
   395 }
   444 }
   396 
   445 
   397 /*!
   446 /*!
   398     Item activation handling. Expand/collapse for title dividers
   447     Item activation handling. Expand/collapse for title dividers
   399     opening for mail items
   448     opening for mail items
   400 */
   449 */
   401 void NmMessageListView::handleSelection()
   450 void NmMessageListView::handleSelection()
   402 {
   451 {
       
   452     NM_FUNCTION;
       
   453 
   403     // Do expand/collapse for title divider items
   454     // Do expand/collapse for title divider items
   404     NmMessageListModelItem* modelItem = mMessageListModel.data(
   455     NmMessageListModelItem* modelItem = mMessageListModel->data(
   405             mActivatedIndex, Qt::DisplayRole).value<NmMessageListModelItem*>();
   456             mActivatedIndex, Qt::DisplayRole).value<NmMessageListModelItem*>();
   406     if (modelItem && modelItem->itemType()==
   457     if (modelItem && modelItem->itemType()==
   407         NmMessageListModelItem::NmMessageItemTitleDivider) {
   458         NmMessageListModelItem::NmMessageItemTitleDivider) {
   408         if (!mMessageListWidget->isExpanded(mActivatedIndex)) {
   459         if (!mMessageListWidget->isExpanded(mActivatedIndex)) {
   409             mMessageListWidget->setExpanded(mActivatedIndex, true);
   460             mMessageListWidget->setExpanded(mActivatedIndex, true);
   411         }
   462         }
   412         else {
   463         else {
   413             mMessageListWidget->setExpanded(mActivatedIndex, false);
   464             mMessageListWidget->setExpanded(mActivatedIndex, false);
   414             modelItem->setExpanded(false);
   465             modelItem->setExpanded(false);
   415         }
   466         }
   416     } 
   467     }
   417     if (modelItem && modelItem->itemType() == NmMessageListModelItem::NmMessageItemMessage
   468     if (modelItem && modelItem->itemType() == NmMessageListModelItem::NmMessageItemMessage
   418         && !mSettingsLaunched)
   469         && !mSettingsLaunched)
   419     {
   470     {
   420         NmFolderType folderType = mUiEngine.folderTypeById(mStartParam->mailboxId(),
   471         NmFolderType folderType = mUiEngine.folderTypeById(mStartParam->mailboxId(),
   421                                   mStartParam->folderId());
   472                                   mStartParam->folderId());
   422         if (folderType==NmFolderDrafts){
   473         if (folderType==NmFolderDrafts){
   423             NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   474             NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   424                 mStartParam->mailboxId(), mStartParam->folderId(),
   475                 mStartParam->mailboxId(), mStartParam->folderId(),
   425                 modelItem->envelope().messageId(),NmUiEditorFromDrafts);
   476                 modelItem->envelope().messageId(),NmUiEditorFromDrafts);
   426             mApplication.enterNmUiView(startParam);            
   477             mApplication.enterNmUiView(startParam);
   427         }
   478         }
   428         else if (folderType!=NmFolderOutbox){
   479         else if (folderType!=NmFolderOutbox){
   429             NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer,
   480             NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer,
   430                 mStartParam->mailboxId(), mStartParam->folderId(),
   481                 mStartParam->mailboxId(), mStartParam->folderId(),
   431                 modelItem->envelope().messageId());
   482                 modelItem->envelope().messageId());
   432             mApplication.enterNmUiView(startParam);        
   483             mApplication.enterNmUiView(startParam);
   433         }
   484         }
   434     }    
   485     }
   435 }
   486 }
   436 
   487 
   437 
   488 
   438 
   489 
   439 /*!
   490 /*!
   440     createOptionsMenu. Functions asks menu commands from extension
   491     createOptionsMenu. Functions asks menu commands from extension
   441     to be added to options menu.
   492     to be added to options menu.
   442 */
   493 */
   443 void NmMessageListView::createOptionsMenu()
   494 void NmMessageListView::createOptionsMenu()
   444 {
   495 {
       
   496     NM_FUNCTION;
       
   497 
   445     menu()->clearActions();
   498     menu()->clearActions();
   446     NmActionRequest request(this, NmActionOptionsMenu, NmActionContextViewMessageList,
   499     NmActionRequest request(this, NmActionOptionsMenu, NmActionContextViewMessageList,
   447     		NmActionContextDataNone, mStartParam->mailboxId(), mStartParam->folderId() );
   500     		NmActionContextDataNone, mStartParam->mailboxId(), mStartParam->folderId() );
   448     NmUiExtensionManager &extMngr = mApplication.extManager();
   501     NmUiExtensionManager &extMngr = mApplication.extManager();
   449     QList<NmAction*> list;
   502     QList<NmAction*> list;
   457     handleActionCommand. From NmMenuObserver, extension manager calls this
   510     handleActionCommand. From NmMenuObserver, extension manager calls this
   458     call to handle menu command in the UI.
   511     call to handle menu command in the UI.
   459 */
   512 */
   460 void NmMessageListView::handleActionCommand(NmActionResponse &actionResponse)
   513 void NmMessageListView::handleActionCommand(NmActionResponse &actionResponse)
   461 {
   514 {
       
   515     NM_FUNCTION;
       
   516 
   462     // Handle context menu commands here
   517     // Handle context menu commands here
   463     if (actionResponse.menuType() == NmActionOptionsMenu) {
   518     if (actionResponse.menuType() == NmActionOptionsMenu) {
   464         switch (actionResponse.responseCommand()) {
   519         switch (actionResponse.responseCommand()) {
   465             case NmActionResponseCommandNewMail: {
   520             case NmActionResponseCommandNewMail: {
   466                 // Check that given start response has mailbox and folder id's
   521                 // Check that given start response has mailbox and folder id's
   479             case NmActionResponseCommandMailboxDeleted: {
   534             case NmActionResponseCommandMailboxDeleted: {
   480                 mApplication.prepareForPopView();
   535                 mApplication.prepareForPopView();
   481 				break;
   536 				break;
   482             }
   537             }
   483             case NmActionResponseCommandSwitchFolder: {
   538             case NmActionResponseCommandSwitchFolder: {
   484                 folderSelected(actionResponse.mailboxId(), actionResponse.folderId());
   539                 mSelectedFolderId=actionResponse.folderId();
       
   540                 mSelectedMailboxId=actionResponse.mailboxId();
       
   541                 QMetaObject::invokeMethod(this, "folderSelected", Qt::QueuedConnection);
   485                 break;
   542                 break;
   486             }
   543             }
   487             case NmActionResponseCommandSettings: {
   544             case NmActionResponseCommandSettings: {
   488                 mSettingsLaunched = true;
   545                 mSettingsLaunched = true;
   489                 break;
   546                 break;
   491             default: {
   548             default: {
   492                 break;
   549                 break;
   493             }
   550             }
   494         }
   551         }
   495     }
   552     }
   496     
   553 
   497     // Handle context menu commands here
   554     // Handle context menu commands here
   498     else if (actionResponse.menuType()==NmActionContextMenu){
   555     else if (actionResponse.menuType()==NmActionContextMenu){
   499         switch (actionResponse.responseCommand()){
   556         switch (actionResponse.responseCommand()){
   500            case NmActionResponseCommandOpen:{
   557            case NmActionResponseCommandOpen:{
   501                if (mLongPressedItem){
   558                if (mLongPressedItem){
   509                break;
   566                break;
   510            default:
   567            default:
   511                break;
   568                break;
   512         }
   569         }
   513     }
   570     }
   514     
   571 
   515     // Handle toolbar commands here
   572     // Handle toolbar commands here
   516     else if ( actionResponse.menuType() == NmActionToolbar ) {
   573     else if ( actionResponse.menuType() == NmActionToolbar ) {
   517         if ( actionResponse.responseCommand() == NmActionResponseCommandNewMail ) {
   574         if ( actionResponse.responseCommand() == NmActionResponseCommandNewMail ) {
   518             // Check that given start response has mailbox and folder id's
   575             // Check that given start response has mailbox and folder id's
   519             if (actionResponse.mailboxId()!=0){
   576             if (actionResponse.mailboxId()!=0){
   520                 if (mUiEngine.isSendingMessage()) {
   577                 if (mUiEngine.isSendingMessage()) {
   521                     // sending is ongoing so just show a note
   578                     // sending is ongoing so just show a note
   522                     QString noteText = hbTrId("txt_mail_dialog_still_sending");
   579                     QString noteText = hbTrId("txt_mail_dialog_still_sending");
   523                     
   580 
   524                     // get message subject from the message being sent
   581                     // get message subject from the message being sent
   525                     const NmMessage *message = mUiEngine.messageBeingSent();
   582                     const NmMessage *message = mUiEngine.messageBeingSent();
   526                     if (message) {
   583                     if (message) {
   527                         noteText = noteText.arg(NmUtilities::truncate(message->envelope().subject(), 20));
   584                         noteText = noteText.arg(NmUtilities::truncate(message->envelope().subject(), 20));
   528                     }
   585                     }
   571 /*!
   628 /*!
   572     Set mailbox name to title
   629     Set mailbox name to title
   573 */
   630 */
   574 void NmMessageListView::setMailboxName()
   631 void NmMessageListView::setMailboxName()
   575 {
   632 {
       
   633     NM_FUNCTION;
       
   634 
   576     if (mStartParam){
   635     if (mStartParam){
   577         NmMailboxMetaData *meta = mUiEngine.mailboxById(mStartParam->mailboxId());
   636         NmMailboxMetaData *meta = mUiEngine.mailboxById(mStartParam->mailboxId());
   578         if (meta){
   637         if (meta){
   579             setTitle(meta->name());
   638             setTitle(meta->name());
   580         }
   639         }
   586     to be added to toolbar owned by the HbView. Also toolbar
   645     to be added to toolbar owned by the HbView. Also toolbar
   587     specific icons are added in this function.
   646     specific icons are added in this function.
   588 */
   647 */
   589 void NmMessageListView::createToolBar()
   648 void NmMessageListView::createToolBar()
   590 {
   649 {
       
   650     NM_FUNCTION;
       
   651 
   591     HbToolBar *tb = toolBar();
   652     HbToolBar *tb = toolBar();
   592     if (!tb) {
   653     if (!tb) {
   593         return;
   654         return;
   594     }
   655     }
   595     tb->clearActions();
   656     tb->clearActions();
   608 
   669 
   609 /*!
   670 /*!
   610     setFolderName. Function sets folder name to status bar
   671     setFolderName. Function sets folder name to status bar
   611 */
   672 */
   612 void NmMessageListView::setFolderName()
   673 void NmMessageListView::setFolderName()
   613 {   
   674 {
       
   675     NM_FUNCTION;
       
   676 
   614     if (mStartParam&&mFolderLabel){
   677     if (mStartParam&&mFolderLabel){
   615         switch (mCurrentFolderType) {
   678         switch (mCurrentFolderType) {
   616         case NmFolderOutbox:
   679         case NmFolderOutbox:
   617             {
   680             {
   618             mFolderLabel->setHeading(hbTrId("txt_mail_subhead_outbox"));
   681             mFolderLabel->setHeading(hbTrId("txt_mail_subhead_outbox"));
   636         case NmFolderInbox:
   699         case NmFolderInbox:
   637         default:
   700         default:
   638             {
   701             {
   639             mFolderLabel->setHeading(hbTrId("txt_mail_subhead_inbox"));
   702             mFolderLabel->setHeading(hbTrId("txt_mail_subhead_inbox"));
   640             }
   703             }
   641             break;        
   704             break;
   642         }       
   705         }
   643     }
   706     }
   644 }
   707 }
   645 
   708 
   646 /*!
   709 
   647     Observe items added
   710 /*!
       
   711     Handles the addition of a new item. Makes sure the message list widget is
       
   712     visible and keeps the scroll position on the top of the list.
       
   713 
       
   714     \param parent Not used.
       
   715     \param start 
       
   716     \param end Not used.
   648 */
   717 */
   649 void NmMessageListView::itemsAdded(const QModelIndex &parent, int start, int end)
   718 void NmMessageListView::itemsAdded(const QModelIndex &parent, int start, int end)
   650 {
   719 {
   651     NMLOG("nmailui: NmMessageListView::itemsAdded");
   720     NM_FUNCTION;
       
   721 
   652     Q_UNUSED(parent);
   722     Q_UNUSED(parent);
   653     Q_UNUSED(end);
   723     Q_UNUSED(end);
       
   724 
       
   725     // If "no messages" label is shown, hide it and display the message list
       
   726     // widget.
   654     if (mNoMessagesLabel && mNoMessagesLabel->isVisible()) {
   727     if (mNoMessagesLabel && mNoMessagesLabel->isVisible()) {
   655         mNoMessagesLabel->hide();
   728         mNoMessagesLabel->hide();
   656         mMessageListWidget->show();
   729         mMessageListWidget->show();
   657     }
   730     }
   658     if (0 == start && mMessageListWidget) {
   731 
       
   732     // Make sure the top of the list is kept visible by scrolling back to the
       
   733     // top if necessary.
       
   734     if (start == 0 && mMessageListWidget) {
   659         QList<HbAbstractViewItem*> items = mMessageListWidget->visibleItems();
   735         QList<HbAbstractViewItem*> items = mMessageListWidget->visibleItems();
       
   736 
   660         if (items.count()) {
   737         if (items.count()) {
   661             QModelIndex index = items.at(0)->modelIndex();
   738             QModelIndex index = items.at(0)->modelIndex();
   662             if (1 == index.row()) {
   739 
   663                 QModelIndex previous = mMessageListWidget->modelIterator()->previousIndex(index);
   740             while (index.row() > 0) {
       
   741                 QModelIndex previous =
       
   742                     mMessageListWidget->modelIterator()->previousIndex(index);
       
   743 
   664                 if (previous.isValid()) {
   744                 if (previous.isValid()) {
   665                     mMessageListWidget->scrollTo(previous);
   745                     mMessageListWidget->scrollTo(previous);
   666                 }
   746                 }
   667             }
   747 
   668         }
   748                 index = previous;
   669     }
   749             }
   670 }
   750         }
       
   751     }
       
   752 }
       
   753 
   671 
   754 
   672 /*!
   755 /*!
   673     Observe items removed
   756     Observe items removed
   674 */
   757 */
   675 void NmMessageListView::itemsRemoved()
   758 void NmMessageListView::itemsRemoved()
   676 {
   759 {
   677     if (mNoMessagesLabel && mMessageListModel.rowCount() == 0){
   760     NM_FUNCTION;
       
   761 
       
   762     if (mMessageListModel && mMessageListModel->rowCount() == 0){
   678         showNoMessagesText();
   763         showNoMessagesText();
   679     }
   764     }
   680 }
   765 }
   681 
   766 
   682 /*!
   767 /*!
   683     Show "(no messages)" text at the middle of the screen.
   768     Show "(no messages)" text at the middle of the screen.
   684 */
   769 */
   685 void NmMessageListView::showNoMessagesText()
   770 void NmMessageListView::showNoMessagesText()
   686 {
   771 {
   687     if (mNoMessagesLabel) {
   772     NM_FUNCTION;
       
   773 
       
   774     if (mNoMessagesLabel&&mMessageListWidget) {
   688         mMessageListWidget->hide();
   775         mMessageListWidget->hide();
   689         mNoMessagesLabel->show();
   776         mNoMessagesLabel->show();
   690     }
   777     }
   691 }
   778 }
       
   779 
       
   780 /*!
       
   781     Hide "(no messages)" text at the middle of the screen.
       
   782 */
       
   783 void NmMessageListView::hideNoMessagesText()
       
   784 {
       
   785     NM_FUNCTION;
       
   786 
       
   787     if (mNoMessagesLabel&&mMessageListWidget) {
       
   788         mNoMessagesLabel->hide();
       
   789         mMessageListWidget->show();
       
   790     }
       
   791 }
       
   792