emailuis/nmailui/src/nmmessagesearchlistview.cpp
changeset 30 759dc5235cdb
parent 27 9ba4404ef423
child 48 10eaf342f539
child 54 997a02608b3a
--- a/emailuis/nmailui/src/nmmessagesearchlistview.cpp	Thu May 27 12:43:55 2010 +0300
+++ b/emailuis/nmailui/src/nmmessagesearchlistview.cpp	Fri Jun 11 13:27:14 2010 +0300
@@ -19,7 +19,7 @@
 static const char *NMUI_MESSAGE_SEARCH_LIST_VIEW = "NmMessageListView";
 static const char *NMUI_MESSAGE_SEARCH_LIST_TREE_LIST = "MessageTreeList";
 static const char *NMUI_MESSAGE_SEARCH_LIST_NO_MESSAGES = "MessageListNoMessages";
-static const char *NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL = "InfoLabel";
+static const char *NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL = "LabelGroupBox";
 static const char *NMUI_MESSAGE_SEARCH_LIST_LINE_EDIT = "LineEdit";
 static const char *NMUI_MESSAGE_SEARCH_LIST_PUSH_BUTTON = "PushButton";
 
@@ -58,6 +58,8 @@
   mViewReady(false),
   mSearchInProgress(false)
 {
+    NM_FUNCTION;
+    
     loadViewLayout();
     initTreeView();
 }
@@ -68,6 +70,8 @@
 */
 NmMessageSearchListView::~NmMessageSearchListView()
 {
+    NM_FUNCTION;
+    
     delete mDocumentLoader;
 
     mWidgetList.clear();
@@ -89,6 +93,8 @@
 */
 NmUiViewId NmMessageSearchListView::nmailViewId() const
 {
+    NM_FUNCTION;
+    
     return NmUiViewMessageSearchList;
 }
 
@@ -100,6 +106,8 @@
 */
 void NmMessageSearchListView::viewReady()
 {
+    NM_FUNCTION;
+    
     if (!mViewReady){
         // Set the mailbox name to the title pane.
         setViewTitle();
@@ -125,6 +133,8 @@
 */
 void NmMessageSearchListView::handleActionCommand(NmActionResponse &actionResponse)
 {
+    NM_FUNCTION;
+    
     // Handle options menu commands here.
     if (actionResponse.menuType() == NmActionOptionsMenu) {
         switch (actionResponse.responseCommand()) {
@@ -145,7 +155,7 @@
     if (actionResponse.menuType() == NmActionContextMenu) {
         if (mLongPressedItem){
             NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer,
-                mStartParam->mailboxId(), mStartParam->folderId(),
+                mStartParam->mailboxId(), mLongPressedItem->envelope().folderId(),
                 mLongPressedItem->envelope().messageId());
 
             mApplication.enterNmUiView(startParam);
@@ -162,6 +172,8 @@
 */
 void NmMessageSearchListView::loadViewLayout()
 {
+    NM_FUNCTION;
+    
     // Use the document loader to load the view layout.
     bool ok(false);
     setObjectName(QString(NMUI_MESSAGE_SEARCH_LIST_VIEW));
@@ -181,24 +193,29 @@
             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_TREE_LIST));
 
         if (mMessageListWidget) {
-            NMLOG("NmMessageSearchListView: Message list widget loaded.");
+            NM_COMMENT("NmMessageSearchListView: message list widget loaded");
 
             // Set the item prototype.
             mMessageListWidget->setItemPrototype(new NmMessageListViewItem());
+
+            // Set the list widget properties.
             mMessageListWidget->setItemRecycling(true);
             mMessageListWidget->contentWidget()->setProperty("indentation", 0);
             mMessageListWidget->setScrollDirections(Qt::Vertical);
             mMessageListWidget->setClampingStyle(HbScrollArea::BounceBackClamping);
             mMessageListWidget->setFrictionEnabled(true);
+
+            // We want the search results to appear one by one.
+            mMessageListWidget->setEnabledAnimations(HbAbstractItemView::Appear &
+                                                     HbAbstractItemView::Expand);
         }
 
         // Load the info label.
-        mInfoLabel = qobject_cast<HbLabel *>(
+        mInfoLabel = qobject_cast<HbGroupBox *>(
             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL));
 
         if (mInfoLabel) {
-            NMLOG("NmMessageSearchListView: Info label loaded.");
-            mInfoLabel->setPlainText(hbTrId("txt_mail_subhead_inbox"));
+            NM_COMMENT("NmMessageSearchListView: info label loaded");
             mInfoLabel->hide();
         }
 
@@ -230,7 +247,7 @@
         }
     }
     else {
-        NMLOG("NmMessageSearchListView: Failed to load widgets from XML!");
+        NM_ERROR(1, "NmMessageSearchListView: failed to load widgets from XML");
     }
 }
 
@@ -240,6 +257,8 @@
 */
 void NmMessageSearchListView::initTreeView()
 {
+    NM_FUNCTION;
+    
     // Get the mailbox widget pointer and set the parameters.
     if (mMessageListWidget) {
         connect(mMessageListWidget, SIGNAL(activated(const QModelIndex &)),
@@ -262,6 +281,8 @@
 */
 void NmMessageSearchListView::setViewTitle()
 {
+    NM_FUNCTION;
+    
     if (mStartParam){
         NmMailboxMetaData *meta = mUiEngine.mailboxById(mStartParam->mailboxId());
 
@@ -281,6 +302,8 @@
 */
 void NmMessageSearchListView::noMessagesLabelVisibility(bool visible)
 {
+    NM_FUNCTION;
+    
     if (visible) {
         // Hide the message list widget and display the "no messages" label.
         if (mMessageListWidget) {
@@ -305,12 +328,50 @@
 
 
 /*!
+    Updates the search result count information. If the message list does not
+    contain any items, a "no messages" label is displayed. Otherwise the result
+    count in the information label is updated according to the number of
+    messages in the list.
+*/
+void NmMessageSearchListView::updateSearchResultCountInfo()
+{
+    NM_FUNCTION;
+
+    const int resultCount = mMsgListModel.rowCount();
+
+    if (resultCount) {
+        if (mInfoLabel) {
+            // Display the result count on the info label.
+            QString resultsString(hbTrId("txt_mail_list_search_results").arg(resultCount));
+            mInfoLabel->setHeading(resultsString);
+
+            if (!mInfoLabel->isVisible()) {
+                mInfoLabel->show();
+            }
+        }
+    }
+    else {
+        // No search results!
+        if (mInfoLabel && mInfoLabel->isVisible()) {
+            mInfoLabel->hide();
+        }
+
+        // Display the "no messages" label and highlight the search term.
+        noMessagesLabelVisibility(true);
+    }
+    
+}
+
+
+/*!
     Sets the mode for the search input.
 
     \param mode The mode to set.
 */
 void NmMessageSearchListView::setSearchInputMode(NmSearchInputMode mode)
 {
+    NM_FUNCTION;
+    
     if (!mLineEdit) {
         // No line edit widget!
         return;
@@ -343,10 +404,9 @@
 */
 void NmMessageSearchListView::reloadViewContents(NmUiStartParam *startParam)
 {
-    // Check the start parameter's validity; message view cannot be updated if
-    // the given parameter is zero.
-    if (startParam&&startParam->viewId() == NmUiViewMessageSearchList &&
-        startParam->folderId() != 0) {
+    NM_FUNCTION;
+    
+    if (startParam && startParam->viewId() == NmUiViewMessageSearchList) {
         // Delete the existing start parameter data.
         delete mStartParam;
         mStartParam = NULL;
@@ -364,7 +424,7 @@
     else {
         // Invalid start parameter data! Unused start parameter needs to be
         // deleted.
-        NMLOG("NmMessageSearchListView: Invalid message list start parameter!");
+        NM_ERROR(1, "NmMessageSearchListView: invalid message list start parameter");
         delete startParam;
     }
 }
@@ -379,7 +439,8 @@
 */
 void NmMessageSearchListView::criteriaChanged(QString text) 
 {
-    NMLOG(QString("NmMessageSearchListView::criteriaChanged %1").arg(text));
+    NM_FUNCTION;
+    NM_COMMENT(QString("NmMessageSearchListView::criteriaChanged %1").arg(text));
     
     // Check if the button should be disabled/enabled.
     bool enabled = mPushButton->isEnabled();
@@ -400,6 +461,8 @@
 void NmMessageSearchListView::showItemContextMenu(
     HbAbstractViewItem *listViewItem, const QPointF &coords)
 {
+    NM_FUNCTION;
+    
     // Store long press item for later use with response.
     mLongPressedItem = 
         mMsgListModel.data(listViewItem->modelIndex(),
@@ -417,17 +480,9 @@
 
         if (envelope){
             NmActionRequest request(this, NmActionContextMenu,
-                NmActionContextViewMessageList, NmActionContextDataMessage,
-                mStartParam->mailboxId(), mStartParam->folderId(),
-                envelope->messageId(),QVariant::fromValue(envelope));
-
-            extMngr.getActions(request, list);
-        }
-        else{
-            NmActionRequest request(this, NmActionContextMenu,
-                NmActionContextViewMessageList, NmActionContextDataMessage,
-                mStartParam->mailboxId(), mStartParam->folderId(),
-                envelope->messageId());
+                NmActionContextViewMessageSearchList, NmActionContextDataMessage,
+                mStartParam->mailboxId(), envelope->folderId(),
+                envelope->messageId(), QVariant::fromValue(envelope));
 
             extMngr.getActions(request, list);
         }
@@ -450,6 +505,8 @@
 */
 void NmMessageSearchListView::itemActivated(const QModelIndex &index)
 {
+    NM_FUNCTION;
+    
     mActivatedIndex = index;
     QMetaObject::invokeMethod(this, "handleSelection", Qt::QueuedConnection);
 }
@@ -460,6 +517,8 @@
 */
 void NmMessageSearchListView::handleSelection()
 {
+    NM_FUNCTION;
+    
     // Do expand/collapse for title divider items
     NmMessageListModelItem* modelItem = mMsgListModel.data(
         mActivatedIndex, Qt::DisplayRole).value<NmMessageListModelItem*>();
@@ -474,7 +533,7 @@
 
         // Open the message.
         NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer,
-            mStartParam->mailboxId(), mStartParam->folderId(),
+            mStartParam->mailboxId(), modelItem->envelope().folderId(),
             modelItem->envelope().messageId());
 
         mApplication.enterNmUiView(startParam);
@@ -488,13 +547,19 @@
 */
 void NmMessageSearchListView::itemsAdded(const QModelIndex &parent, int start, int end)
 {
-    NMLOG("nmailui: NmMessageSearchListView::itemsAdded()");
-
+    NM_FUNCTION;
+    
     Q_UNUSED(parent);
     Q_UNUSED(end);
 
-    // Display the message list widget if not visible.
-    noMessagesLabelVisibility(false);
+    // The search is an asynchronous operation. If a user stops the search, it
+    // might take a short while before the search is actually stopped and during
+    // this time it is possible that messages matching the search are added.
+    // Therefore, update the result count info if items are added after the
+    // search has been stopped by the user.
+    if (!mSearchInProgress) {
+        updateSearchResultCountInfo();
+    }
 
     if (!start && mMessageListWidget) {
         QList<HbAbstractViewItem*> items = mMessageListWidget->visibleItems();
@@ -502,12 +567,15 @@
         if (items.count()) {
             QModelIndex index = items.at(0)->modelIndex();
 
-            if (1 == index.row()) {
-                QModelIndex previous = mMessageListWidget->modelIterator()->previousIndex(index);
+            while (index.row() > 0) {
+                QModelIndex previous =
+                    mMessageListWidget->modelIterator()->previousIndex(index);
 
                 if (previous.isValid()) {
                     mMessageListWidget->scrollTo(previous);
                 }
+
+                index = previous;
             }
         }
     }
@@ -515,29 +583,16 @@
 
 
 /*!
-    This method gets called when an item is removed from the list. If the list
-    contains no items, the info label (if visible) is hidden and the "no
-    messages" label is displayed. Otherwise, only the result count in the info
-    label is updated.
+    This method gets called when an item is removed from the list. If the
+    search has completed (or stopped), the search result count information is
+    updated according to the number of messages in the list.
 */
 void NmMessageSearchListView::itemsRemoved()
 {
-    const int itemCount = mMsgListModel.rowCount();
-
-    if (itemCount == 0) {
-        if (mInfoLabel && mInfoLabel->isVisible()) {
-            // Hide the info label.
-            mInfoLabel->hide();
-        }
-
-        // Display the "no messages" label.
-        noMessagesLabelVisibility(true);
-    }
-    else if (mInfoLabel && mInfoLabel->isVisible()) {
-        // Update the search result count in the info label.
-        QString resultsString(hbTrId("txt_mail_list_search_results"));
-        resultsString.arg(itemCount);
-        mInfoLabel->setPlainText(resultsString);
+    NM_FUNCTION;
+    
+    if (!mSearchInProgress) {
+        updateSearchResultCountInfo();
     }
 }
 
@@ -547,6 +602,8 @@
 */
 void NmMessageSearchListView::refreshList()
 {
+    NM_FUNCTION;
+    
     if (mMessageListWidget) {
         // Set the model.
         mMessageListWidget->setModel(
@@ -577,6 +634,8 @@
 */
 void NmMessageSearchListView::toggleSearch()
 {
+    NM_FUNCTION;
+    
     if (mSearchInProgress) {
         // Search is in progress - do cancel.
         mUiEngine.cancelSearch(mStartParam->mailboxId());
@@ -607,7 +666,7 @@
 
         // Display the info label.
         if (mInfoLabel) {
-            mInfoLabel->setPlainText(hbTrId("txt_mail_list_searching"));
+            mInfoLabel->setHeading(hbTrId("txt_mail_list_searching"));
             mInfoLabel->show();
         }
 
@@ -626,7 +685,8 @@
 */
 void NmMessageSearchListView::handleSearchComplete()
 {
-    NMLOG("NmMessageSearchListView::handleSearchComplete()");
+    NM_FUNCTION;
+    
     mSearchInProgress = false;
     
     // Change the push button text.
@@ -634,30 +694,17 @@
         mPushButton->setIcon(HbIcon("qtg_mono_search"));
     }
 
+    // Display the search result count.
+    updateSearchResultCountInfo();
+
     const int resultCount = mMsgListModel.rowCount();
 
     if (resultCount) {
-        if (mInfoLabel) {
-            // Display the result count on the info label.
-            QString resultsString(hbTrId("txt_mail_list_search_results"));
-            resultsString.arg(resultCount);
-            mInfoLabel->setPlainText(resultsString);
-
-            if (!mInfoLabel->isVisible()) {
-                mInfoLabel->show();
-            }
-        }
-
         // Undim the search input.
         setSearchInputMode(NmNormalMode);
     }
     else {
-        // No search results!
-        if (mInfoLabel && mInfoLabel->isVisible()) {
-            mInfoLabel->hide();
-        }
-
-        // Display the "no messags" label and highlight the search term.
+        // Highlight the search field.
         noMessagesLabelVisibility(true);
         setSearchInputMode(NmHighlightedMode);
     }