emailuis/nmailui/src/nmmessagesearchlistview.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 static const char *NMUI_MESSAGE_SEARCH_LIST_VIEW_XML = ":/docml/nmmessagesearchlistview.docml";
       
    19 static const char *NMUI_MESSAGE_SEARCH_LIST_VIEW = "NmMessageSearchListView";
       
    20 static const char *NMUI_MESSAGE_SEARCH_LIST_TREE_LIST = "MessageTreeList";
       
    21 static const char *NMUI_MESSAGE_SEARCH_LIST_NO_MESSAGES = "MessageListNoMessages";
       
    22 static const char *NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL = "LabelGroupBox";
       
    23 static const char *NMUI_MESSAGE_SEARCH_LIST_LINE_EDIT = "LineEdit";
       
    24 static const char *NMUI_MESSAGE_SEARCH_LIST_PUSH_BUTTON = "PushButton";
       
    25 
       
    26 
       
    27 #include "nmuiheaders.h"
       
    28 
       
    29 
       
    30 /*!
       
    31     \class NmMessageSearchListView
       
    32     \brief The view for searching messages.
       
    33 */
       
    34 
       
    35 
       
    36 /*!
       
    37     Class constructor.
       
    38 */
       
    39 NmMessageSearchListView::NmMessageSearchListView(
       
    40     NmApplication &application,
       
    41     NmUiStartParam* startParam,
       
    42     NmUiEngine &uiEngine,
       
    43     NmMessageListModel &msgListModel,
       
    44     HbDocumentLoader *documentLoader,
       
    45     QGraphicsItem *parent)
       
    46 : NmBaseView(startParam, application, parent),
       
    47   mApplication(application),
       
    48   mUiEngine(uiEngine),
       
    49   mMsgListModel(msgListModel),
       
    50   mDocumentLoader(documentLoader),
       
    51   mItemContextMenu(NULL),
       
    52   mMessageListWidget(NULL),
       
    53   mInfoLabel(NULL),
       
    54   mNoMessagesLabel(NULL),
       
    55   mLineEdit(NULL),
       
    56   mPushButton(NULL),
       
    57   mLongPressedItem(NULL),
       
    58   mViewReady(false),
       
    59   mSearchInProgress(false)
       
    60 {
       
    61     NM_FUNCTION;
       
    62     
       
    63     loadViewLayout();
       
    64     initTreeView();
       
    65 }
       
    66 
       
    67 
       
    68 /*!
       
    69     Class destructor.
       
    70 */
       
    71 NmMessageSearchListView::~NmMessageSearchListView()
       
    72 {
       
    73     NM_FUNCTION;
       
    74     
       
    75     delete mDocumentLoader;
       
    76 
       
    77     mWidgetList.clear();
       
    78 
       
    79     if (mItemContextMenu){
       
    80         mItemContextMenu->clearActions();
       
    81     }
       
    82 
       
    83     delete mItemContextMenu;
       
    84 }
       
    85 
       
    86 
       
    87 /*!
       
    88     From NmBaseView.
       
    89 
       
    90     Returns the view ID.
       
    91 
       
    92     \return The view ID.
       
    93 */
       
    94 NmUiViewId NmMessageSearchListView::nmailViewId() const
       
    95 {
       
    96     NM_FUNCTION;
       
    97     
       
    98     return NmUiViewMessageSearchList;
       
    99 }
       
   100 
       
   101 
       
   102 /*!
       
   103     From NmBaseView.
       
   104 
       
   105     Does the lazy loading after the view layout has been loaded.
       
   106 */
       
   107 void NmMessageSearchListView::viewReady()
       
   108 {
       
   109     NM_FUNCTION;
       
   110     
       
   111     if (!mViewReady){
       
   112         // Set the mailbox name to the title pane.
       
   113         setViewTitle();
       
   114 
       
   115         // Refresh the list.
       
   116         QMetaObject::invokeMethod(this, "refreshList", Qt::QueuedConnection);
       
   117 
       
   118         // Highlight the search input.
       
   119         setSearchInputMode(NmHighlightedMode);
       
   120 
       
   121         mViewReady = true;
       
   122     }
       
   123 }
       
   124 
       
   125 
       
   126 /*!
       
   127     From NmMenuObserver.
       
   128 
       
   129     Handles action commands which are usually given by the user by selecting
       
   130     menu items.
       
   131 
       
   132     \param actionResponse The command details.
       
   133 */
       
   134 void NmMessageSearchListView::handleActionCommand(NmActionResponse &actionResponse)
       
   135 {
       
   136     NM_FUNCTION;
       
   137     
       
   138     // Handle options menu commands here.
       
   139     if (actionResponse.menuType() == NmActionOptionsMenu) {
       
   140         switch (actionResponse.responseCommand()) {
       
   141             case NmActionResponseCommandUpdateMailboxName: {
       
   142                 setViewTitle();
       
   143                 break;
       
   144             }
       
   145             case NmActionResponseCommandMailboxDeleted: {
       
   146                 mApplication.prepareForPopView();
       
   147                 break;
       
   148             }
       
   149             default: {
       
   150                 break;
       
   151             }
       
   152         }
       
   153     }
       
   154     // Handle context menu commands here.
       
   155     if (actionResponse.menuType() == NmActionContextMenu) {
       
   156         if (mLongPressedItem){
       
   157             NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer,
       
   158                 mStartParam->mailboxId(), mLongPressedItem->envelope().folderId(),
       
   159                 mLongPressedItem->envelope().messageId());
       
   160 
       
   161             mApplication.enterNmUiView(startParam);
       
   162             mLongPressedItem = NULL;
       
   163        }
       
   164     }
       
   165 }
       
   166 
       
   167 
       
   168 /*!
       
   169     From NmBaseView.
       
   170 
       
   171     Loads the view layout from the XML file.
       
   172 */
       
   173 void NmMessageSearchListView::loadViewLayout()
       
   174 {
       
   175     NM_FUNCTION;
       
   176     
       
   177     // Use the document loader to load the view layout.
       
   178     bool ok(false);
       
   179     setObjectName(QString(NMUI_MESSAGE_SEARCH_LIST_VIEW));
       
   180     QObjectList objectList;
       
   181     objectList.append(this);
       
   182 
       
   183     // Pass the view to the document loader. Instead of creating a new view, the
       
   184     // document loader uses this view when the docml file is parsed.
       
   185     if (mDocumentLoader) {
       
   186         mDocumentLoader->setObjectTree(objectList);
       
   187         mWidgetList = mDocumentLoader->load(NMUI_MESSAGE_SEARCH_LIST_VIEW_XML, &ok);
       
   188     }
       
   189 
       
   190     if (ok) {
       
   191         // Load the search panel (contains the line edit and the push button
       
   192         // widgets.
       
   193         mLineEdit = qobject_cast<HbLineEdit *>(
       
   194             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_LINE_EDIT));
       
   195 
       
   196         if (mLineEdit) {
       
   197             connect(mLineEdit, SIGNAL(textChanged(QString)), 
       
   198                     this, SLOT(criteriaChanged(QString)));
       
   199         }
       
   200     
       
   201         mPushButton = qobject_cast<HbPushButton *>(
       
   202         mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_PUSH_BUTTON));
       
   203 
       
   204         if (mPushButton) {
       
   205             // button is disabled when line edit is empty
       
   206             mPushButton->setEnabled(false);
       
   207 
       
   208             // The push button both starts and stops the search.
       
   209             connect(mPushButton, SIGNAL(clicked()), this, SLOT(toggleSearch()));
       
   210             mPushButton->setIcon(HbIcon("qtg_mono_search"));
       
   211         }
       
   212 
       
   213         // Load the info label.
       
   214         mInfoLabel = qobject_cast<HbGroupBox *>(
       
   215             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL));
       
   216 
       
   217         if (mInfoLabel) {
       
   218             NM_COMMENT("NmMessageSearchListView: info label loaded");
       
   219 
       
   220             // If the heading is empty, the widget will not be shown which in
       
   221             // turn would ruin the layout.
       
   222             mInfoLabel->setHeading(" ");
       
   223         }
       
   224 
       
   225         // Get the message list widget.
       
   226         mMessageListWidget = qobject_cast<HbTreeView *>(
       
   227             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_TREE_LIST));
       
   228 
       
   229         if (mMessageListWidget) {
       
   230             NM_COMMENT("NmMessageSearchListView: message list widget loaded");
       
   231 
       
   232             // Set the item prototype.
       
   233             mMessageListWidget->setItemPrototype(new NmMessageListViewItem());
       
   234 
       
   235             // Set the list widget properties.
       
   236             mMessageListWidget->setItemRecycling(true);
       
   237             mMessageListWidget->contentWidget()->setProperty("indentation", 0);
       
   238             mMessageListWidget->setScrollDirections(Qt::Vertical);
       
   239             mMessageListWidget->setClampingStyle(HbScrollArea::BounceBackClamping);
       
   240             mMessageListWidget->setFrictionEnabled(true);
       
   241             mMessageListWidget->setItemPixmapCacheEnabled(true);
       
   242             
       
   243             // We want the search results to appear one by one.
       
   244             mMessageListWidget->setEnabledAnimations(HbAbstractItemView::Appear &
       
   245                                                      HbAbstractItemView::Expand);
       
   246         }
       
   247 
       
   248         // Load the no messages label.
       
   249         mNoMessagesLabel = qobject_cast<HbLabel *>(
       
   250             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_NO_MESSAGES));
       
   251 
       
   252         if (mNoMessagesLabel) {
       
   253             NMLOG("NmMessageSearchListView: No messages label loaded.");
       
   254             mNoMessagesLabel->hide();
       
   255         }
       
   256     }
       
   257     else {
       
   258         NM_ERROR(1, "NmMessageSearchListView: failed to load widgets from XML");
       
   259     }
       
   260 }
       
   261 
       
   262 
       
   263 /*!
       
   264     Initializes the tree view.
       
   265 */
       
   266 void NmMessageSearchListView::initTreeView()
       
   267 {
       
   268     NM_FUNCTION;
       
   269     
       
   270     // Get the mailbox widget pointer and set the parameters.
       
   271     if (mMessageListWidget) {
       
   272         connect(mMessageListWidget, SIGNAL(activated(const QModelIndex &)),
       
   273                 this, SLOT(itemActivated(const QModelIndex &)));
       
   274 
       
   275         connect(mMessageListWidget, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
       
   276                 this, SLOT(showItemContextMenu(HbAbstractViewItem*, QPointF)));
       
   277 
       
   278         mMessageListWidget->setFocus();
       
   279         mItemContextMenu = new HbMenu();
       
   280     }
       
   281 
       
   282     // Clear the previous content if any.
       
   283     mMsgListModel.clear();
       
   284 }
       
   285 
       
   286 
       
   287 /*!
       
   288     Sets the title according to the name of the current mailbox.
       
   289 */
       
   290 void NmMessageSearchListView::setViewTitle()
       
   291 {
       
   292     NM_FUNCTION;
       
   293     
       
   294     if (mStartParam){
       
   295         NmMailboxMetaData *meta = mUiEngine.mailboxById(mStartParam->mailboxId());
       
   296 
       
   297         if (meta){
       
   298             setTitle(meta->name());
       
   299         }
       
   300     }
       
   301 }
       
   302 
       
   303 
       
   304 /*!
       
   305     Toggles the visiblity between the message list widget and the "no messages"
       
   306     label.
       
   307 
       
   308     \param visible If true, will display the "no messages" label. If false,
       
   309                    will display the message list widget.
       
   310 */
       
   311 void NmMessageSearchListView::noMessagesLabelVisibility(bool visible)
       
   312 {
       
   313     NM_FUNCTION;
       
   314     
       
   315     if (visible) {
       
   316         // Hide the message list widget and display the "no messages" label.
       
   317         if (mMessageListWidget) {
       
   318             mMessageListWidget->hide();
       
   319         }
       
   320 
       
   321         if (mNoMessagesLabel && !mNoMessagesLabel->isVisible()) {
       
   322             mNoMessagesLabel->show();
       
   323         }
       
   324     }
       
   325     else {
       
   326         // Hide the "no messages" label and display the message list widget.
       
   327         if (mNoMessagesLabel && mNoMessagesLabel->isVisible()) {
       
   328             mNoMessagesLabel->hide();
       
   329         }
       
   330 
       
   331         if (mMessageListWidget) {
       
   332             mMessageListWidget->show();
       
   333         }
       
   334     }
       
   335 }
       
   336 
       
   337 
       
   338 /*!
       
   339     Updates the search result count information. If the message list does not
       
   340     contain any items, a "no messages" label is displayed. Otherwise the result
       
   341     count in the information label is updated according to the number of
       
   342     messages in the list.
       
   343 */
       
   344 void NmMessageSearchListView::updateSearchResultCountInfo()
       
   345 {
       
   346     NM_FUNCTION;
       
   347 
       
   348     const int resultCount = mMsgListModel.rowCount();
       
   349 
       
   350     if (resultCount) {
       
   351         if (mInfoLabel) {
       
   352             // Display the result count on the info label.
       
   353             QString resultsString(hbTrId("txt_mail_list_search_results",resultCount));
       
   354             mInfoLabel->setHeading(resultsString);
       
   355 
       
   356             if (!mInfoLabel->isVisible()) {
       
   357                 mInfoLabel->show();
       
   358             }
       
   359         }
       
   360     }
       
   361     else {
       
   362         // No search results!
       
   363         if (mInfoLabel && mInfoLabel->isVisible()) {
       
   364             mInfoLabel->hide();
       
   365         }
       
   366 
       
   367         // Display the "no messages" label and highlight the search term.
       
   368         noMessagesLabelVisibility(true);
       
   369     }
       
   370     
       
   371 }
       
   372 
       
   373 
       
   374 /*!
       
   375     Sets the mode for the search input.
       
   376 
       
   377     \param mode The mode to set.
       
   378 */
       
   379 void NmMessageSearchListView::setSearchInputMode(NmSearchInputMode mode)
       
   380 {
       
   381     NM_FUNCTION;
       
   382     
       
   383     if (!mLineEdit) {
       
   384         // No line edit widget!
       
   385         return;
       
   386     }
       
   387 
       
   388     switch (mode) {
       
   389         case NmNormalMode: {
       
   390             mLineEdit->setEnabled(true);
       
   391             break;
       
   392         }
       
   393         case NmHighlightedMode: {
       
   394             mLineEdit->setEnabled(true);
       
   395             mLineEdit->setFocus();
       
   396             break;
       
   397         }
       
   398         case NmDimmedMode: {
       
   399             mLineEdit->setEnabled(false);
       
   400             break;
       
   401         }
       
   402     }
       
   403 }
       
   404 
       
   405 
       
   406 /*!
       
   407     From NmBaseView.
       
   408 
       
   409     Reloads the view contents with new start parameters. This method is
       
   410     typically used when the view is already open and an external view activation
       
   411     occurs for this same view.
       
   412 */
       
   413 void NmMessageSearchListView::reloadViewContents(NmUiStartParam *startParam)
       
   414 {
       
   415     NM_FUNCTION;
       
   416     
       
   417     if (startParam && startParam->viewId() == NmUiViewMessageSearchList) {
       
   418         // Delete the existing start parameter data.
       
   419         delete mStartParam;
       
   420         mStartParam = NULL;
       
   421 
       
   422         // Store the new start parameter data.
       
   423         mStartParam = startParam;
       
   424 
       
   425         // Update the model with new parameters.
       
   426         mUiEngine.messageListModelForSearch(startParam->mailboxId());
       
   427         refreshList();
       
   428 
       
   429         // Refresh the mailbox name.
       
   430         setViewTitle();
       
   431     }
       
   432     else {
       
   433         // Invalid start parameter data! Unused start parameter needs to be
       
   434         // deleted.
       
   435         NM_ERROR(1, "NmMessageSearchListView: invalid message list start parameter");
       
   436         delete startParam;
       
   437     }
       
   438 }
       
   439 
       
   440 
       
   441 /*!
       
   442     Called when text is changed in the edit field. If there is no search term
       
   443     in the edit field, the search button is dimmed and disabled. If the field
       
   444     contains text, the button can be clicked.
       
   445     
       
   446     \param text The text in the field after the modification.
       
   447 */
       
   448 void NmMessageSearchListView::criteriaChanged(QString text) 
       
   449 {
       
   450     NM_FUNCTION;
       
   451     NM_COMMENT(QString("NmMessageSearchListView::criteriaChanged %1").arg(text));
       
   452     
       
   453     // Check if the button should be disabled/enabled.
       
   454     bool enabled = mPushButton->isEnabled();
       
   455 
       
   456     if (!enabled && !text.isEmpty()) {
       
   457         mPushButton->setEnabled(true);
       
   458     }
       
   459     else if (enabled && text.isEmpty()) {
       
   460         mPushButton->setEnabled(false);
       
   461     }
       
   462 }
       
   463 
       
   464 
       
   465 /*!
       
   466     Displays the item context menu. This method gets called if an item on the
       
   467     list is long pressed.
       
   468 */
       
   469 void NmMessageSearchListView::showItemContextMenu(
       
   470     HbAbstractViewItem *listViewItem, const QPointF &coords)
       
   471 {
       
   472     NM_FUNCTION;
       
   473     
       
   474     // Store long press item for later use with response.
       
   475     mLongPressedItem = 
       
   476         mMsgListModel.data(listViewItem->modelIndex(),
       
   477                            Qt::DisplayRole).value<NmMessageListModelItem*>();
       
   478 
       
   479     if (mItemContextMenu && mLongPressedItem &&
       
   480         mLongPressedItem->itemType() == NmMessageListModelItem::NmMessageItemMessage) {
       
   481         // Clear the previous menu actions.
       
   482         mItemContextMenu->clearActions();
       
   483         NmUiExtensionManager &extMngr = mApplication.extManager();
       
   484         QList<NmAction*> list;
       
   485 
       
   486         // Fetch the menu actions based on the selected item.
       
   487         NmMessageEnvelope *envelope = mLongPressedItem->envelopePtr();
       
   488 
       
   489         if (envelope){
       
   490             NmActionRequest request(this, NmActionContextMenu,
       
   491                 NmActionContextViewMessageSearchList, NmActionContextDataMessage,
       
   492                 mStartParam->mailboxId(), envelope->folderId(),
       
   493                 envelope->messageId(), QVariant::fromValue(envelope));
       
   494 
       
   495             extMngr.getActions(request, list);
       
   496         }
       
   497 
       
   498         for (int i(0); i < list.count(); ++i) {
       
   499             mItemContextMenu->addAction(list[i]);
       
   500         }
       
   501 
       
   502         mItemContextMenu->setPreferredPos(coords);
       
   503         mItemContextMenu->open();
       
   504     }
       
   505 }
       
   506 
       
   507 
       
   508 /*!
       
   509     Stores the given index and forwards the call to handleSelection(). This
       
   510     method gets called when an item on the list is selected.  
       
   511 
       
   512     \param index The index of the activated item.
       
   513 */
       
   514 void NmMessageSearchListView::itemActivated(const QModelIndex &index)
       
   515 {
       
   516     NM_FUNCTION;
       
   517     
       
   518     mActivatedIndex = index;
       
   519     QMetaObject::invokeMethod(this, "handleSelection", Qt::QueuedConnection);
       
   520 }
       
   521 
       
   522 
       
   523 /*!
       
   524     If the selected item is a message, will open the message.
       
   525 */
       
   526 void NmMessageSearchListView::handleSelection()
       
   527 {
       
   528     NM_FUNCTION;
       
   529     
       
   530     // Do expand/collapse for title divider items
       
   531     NmMessageListModelItem* modelItem = mMsgListModel.data(
       
   532         mActivatedIndex, Qt::DisplayRole).value<NmMessageListModelItem*>();
       
   533 
       
   534     if (modelItem &&
       
   535         modelItem->itemType() == NmMessageListModelItem::NmMessageItemMessage)
       
   536     {
       
   537         if (mSearchInProgress) {
       
   538             // Stop the search.
       
   539             toggleSearch();
       
   540         }
       
   541 
       
   542         // Open the message.
       
   543         NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer,
       
   544             mStartParam->mailboxId(), modelItem->envelope().folderId(),
       
   545             modelItem->envelope().messageId());
       
   546 
       
   547         mApplication.enterNmUiView(startParam);
       
   548     }
       
   549 }
       
   550 
       
   551 
       
   552 /*!
       
   553     Displays the message list widtet if not visible and scrolls to the
       
   554     appropriate point on the list.
       
   555 */
       
   556 void NmMessageSearchListView::itemsAdded(const QModelIndex &parent, int start, int end)
       
   557 {
       
   558     NM_FUNCTION;
       
   559     
       
   560     Q_UNUSED(parent);
       
   561     Q_UNUSED(end);
       
   562 
       
   563     // The search is an asynchronous operation. If a user stops the search, it
       
   564     // might take a short while before the search is actually stopped and during
       
   565     // this time it is possible that messages matching the search are added.
       
   566     // Therefore, update the result count info if items are added after the
       
   567     // search has been stopped by the user.
       
   568     if (!mSearchInProgress) {
       
   569         updateSearchResultCountInfo();
       
   570     }
       
   571 
       
   572     if (!start && mMessageListWidget) {
       
   573         QList<HbAbstractViewItem*> items = mMessageListWidget->visibleItems();
       
   574 
       
   575         if (items.count()) {
       
   576             QModelIndex index = items.at(0)->modelIndex();
       
   577 
       
   578             while (index.row() > 0) {
       
   579                 QModelIndex previous =
       
   580                     mMessageListWidget->modelIterator()->previousIndex(index);
       
   581 
       
   582                 if (previous.isValid()) {
       
   583                     mMessageListWidget->scrollTo(previous);
       
   584                 }
       
   585 
       
   586                 index = previous;
       
   587             }
       
   588         }
       
   589     }
       
   590 }
       
   591 
       
   592 
       
   593 /*!
       
   594     This method gets called when an item is removed from the list. If the
       
   595     search has completed (or stopped), the search result count information is
       
   596     updated according to the number of messages in the list.
       
   597 */
       
   598 void NmMessageSearchListView::itemsRemoved()
       
   599 {
       
   600     NM_FUNCTION;
       
   601     
       
   602     if (!mSearchInProgress) {
       
   603         updateSearchResultCountInfo();
       
   604     }
       
   605 }
       
   606 
       
   607 
       
   608 /*!
       
   609     Refreshes the search list.
       
   610 */
       
   611 void NmMessageSearchListView::refreshList()
       
   612 {
       
   613     NM_FUNCTION;
       
   614     
       
   615     if (mMessageListWidget) {
       
   616         // Set the model.
       
   617         mMessageListWidget->setModel(
       
   618             static_cast<QStandardItemModel*>(&mMsgListModel));
       
   619 
       
   620         // Connect the signals.
       
   621         connect(&mMsgListModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
       
   622                 this, SLOT(itemsAdded(const QModelIndex&, int, int)), Qt::UniqueConnection);
       
   623 
       
   624         connect(&mMsgListModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
       
   625                 this, SLOT(itemsRemoved()), Qt::UniqueConnection);
       
   626 
       
   627         connect(&mMsgListModel, SIGNAL(setNewParam(NmUiStartParam*)),
       
   628                 this, SLOT(reloadViewContents(NmUiStartParam*)), Qt::UniqueConnection);
       
   629     }
       
   630 
       
   631     // The info label cannot be hidden when constructed because doing so would
       
   632     // ruin the layout (for example the line edit widget's width would be too
       
   633     // short in lanscape).
       
   634     if (mInfoLabel) {
       
   635         mInfoLabel->hide();
       
   636     }
       
   637 }
       
   638 
       
   639 
       
   640 /*!
       
   641     Starts and stops the search according to the current status.
       
   642 
       
   643     Starts search: Uses the input given by the user as a search string and
       
   644     starts an asynchronous search. Any previous search results are removed from
       
   645     the search list.
       
   646 
       
   647     Stops search: Sets the number of search results into the info label.
       
   648 */
       
   649 void NmMessageSearchListView::toggleSearch()
       
   650 {
       
   651     NM_FUNCTION;
       
   652     
       
   653     if (mSearchInProgress) {
       
   654         // Search is in progress - do cancel.
       
   655         mUiEngine.cancelSearch(mStartParam->mailboxId());
       
   656         handleSearchComplete();
       
   657     }
       
   658     else {
       
   659         // Do start the search.
       
   660         mSearchInProgress = true;
       
   661     
       
   662         // Clear previous results if any.
       
   663         mMsgListModel.clear();
       
   664 
       
   665         connect(&mUiEngine, SIGNAL(searchComplete()),
       
   666                 this, SLOT(handleSearchComplete()), Qt::UniqueConnection);
       
   667     
       
   668         // Get the search input and start the search.
       
   669         QStringList searchStrings;
       
   670 
       
   671         if (mLineEdit) {
       
   672             searchStrings.append(mLineEdit->text());
       
   673         }
       
   674 
       
   675         mUiEngine.search(mStartParam->mailboxId(), searchStrings);
       
   676 
       
   677         // Hide the virtual keyboard
       
   678         QInputContext *ic = qApp->inputContext();
       
   679         if (ic) {
       
   680             QEvent *closeEvent = new QEvent(QEvent::CloseSoftwareInputPanel);
       
   681             ic->filterEvent(closeEvent);
       
   682             delete closeEvent;
       
   683         }
       
   684         
       
   685         // Hide the "no messages" label if visible and dim the search input.
       
   686         noMessagesLabelVisibility(false);
       
   687         setSearchInputMode(NmDimmedMode);
       
   688 
       
   689         // Display the info label.
       
   690         if (mInfoLabel) {
       
   691             mInfoLabel->setHeading(hbTrId("txt_mail_list_searching"));
       
   692             mInfoLabel->show();
       
   693         }
       
   694 
       
   695         // Change the push button text.
       
   696         if (mPushButton) {
       
   697             mPushButton->setIcon(HbIcon("qtg_mono_search_stop"));
       
   698         }
       
   699     }
       
   700 }
       
   701 
       
   702 
       
   703 /*!
       
   704     If the search matched any messages, displays the search result count in the
       
   705     info label. If no messages were found, the method displays the "no messages"
       
   706     label. In either case, the search panel is updated.
       
   707 */
       
   708 void NmMessageSearchListView::handleSearchComplete()
       
   709 {
       
   710     NM_FUNCTION;
       
   711     
       
   712     mSearchInProgress = false;
       
   713     
       
   714     // Change the push button text.
       
   715     if (mPushButton) {
       
   716         mPushButton->setIcon(HbIcon("qtg_mono_search"));
       
   717     }
       
   718 
       
   719     // Display the search result count.
       
   720     updateSearchResultCountInfo();
       
   721 
       
   722     const int resultCount = mMsgListModel.rowCount();
       
   723 
       
   724     if (resultCount) {
       
   725         // Undim the search input.
       
   726         setSearchInputMode(NmNormalMode);
       
   727     }
       
   728     else {
       
   729         // Highlight the search field.
       
   730         noMessagesLabelVisibility(true);
       
   731         setSearchInputMode(NmHighlightedMode);
       
   732     }
       
   733 }
       
   734 
       
   735 
       
   736 // End of file.