emailuis/nmailui/src/nmmessagesearchlistview.cpp
changeset 27 9ba4404ef423
parent 23 2dc6caa42ec3
child 30 759dc5235cdb
equal deleted inserted replaced
23:2dc6caa42ec3 27:9ba4404ef423
    38 */
    38 */
    39 NmMessageSearchListView::NmMessageSearchListView(
    39 NmMessageSearchListView::NmMessageSearchListView(
    40     NmApplication &application,
    40     NmApplication &application,
    41     NmUiStartParam* startParam,
    41     NmUiStartParam* startParam,
    42     NmUiEngine &uiEngine,
    42     NmUiEngine &uiEngine,
    43     NmMessageSearchListModel &searchListModel,
    43     NmMessageListModel &msgListModel,
    44     HbDocumentLoader *documentLoader,
    44     HbDocumentLoader *documentLoader,
    45     QGraphicsItem *parent)
    45     QGraphicsItem *parent)
    46 : NmBaseView(startParam, parent),
    46 : NmBaseView(startParam, application, parent),
    47   mApplication(application),
    47   mApplication(application),
    48   mUiEngine(uiEngine),
    48   mUiEngine(uiEngine),
    49   mSearchListModel(searchListModel),
    49   mMsgListModel(msgListModel),
    50   mDocumentLoader(documentLoader),
    50   mDocumentLoader(documentLoader),
    51   mItemContextMenu(NULL),
    51   mItemContextMenu(NULL),
    52   mMessageListWidget(NULL),
    52   mMessageListWidget(NULL),
       
    53   mInfoLabel(NULL),
    53   mNoMessagesLabel(NULL),
    54   mNoMessagesLabel(NULL),
    54   mInfoLabel(NULL),
       
    55   mLineEdit(NULL),
    55   mLineEdit(NULL),
    56   mPushButton(NULL),
    56   mPushButton(NULL),
    57   mLongPressedItem(NULL),
    57   mLongPressedItem(NULL),
    58   mViewReady(false),
    58   mViewReady(false),
    59   mSearchInProgress(false)
    59   mSearchInProgress(false)
   131             case NmActionResponseCommandUpdateMailboxName: {
   131             case NmActionResponseCommandUpdateMailboxName: {
   132                 setViewTitle();
   132                 setViewTitle();
   133                 break;
   133                 break;
   134             }
   134             }
   135             case NmActionResponseCommandMailboxDeleted: {
   135             case NmActionResponseCommandMailboxDeleted: {
   136                 mApplication.popView();
   136                 mApplication.prepareForPopView();
   137                 break;
   137                 break;
   138             }
   138             }
   139             default: {
   139             default: {
   140                 break;
   140                 break;
   141             }
   141             }
   142         }
   142         }
       
   143     }
       
   144     // Handle context menu commands here.
       
   145     if (actionResponse.menuType() == NmActionContextMenu) {
       
   146         if (mLongPressedItem){
       
   147             NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer,
       
   148                 mStartParam->mailboxId(), mStartParam->folderId(),
       
   149                 mLongPressedItem->envelope().messageId());
       
   150 
       
   151             mApplication.enterNmUiView(startParam);
       
   152             mLongPressedItem = NULL;
       
   153        }
   143     }
   154     }
   144 }
   155 }
   145 
   156 
   146 
   157 
   147 /*!
   158 /*!
   179             mMessageListWidget->setScrollDirections(Qt::Vertical);
   190             mMessageListWidget->setScrollDirections(Qt::Vertical);
   180             mMessageListWidget->setClampingStyle(HbScrollArea::BounceBackClamping);
   191             mMessageListWidget->setClampingStyle(HbScrollArea::BounceBackClamping);
   181             mMessageListWidget->setFrictionEnabled(true);
   192             mMessageListWidget->setFrictionEnabled(true);
   182         }
   193         }
   183 
   194 
   184         // Load the "no messages" label.
       
   185         mNoMessagesLabel = qobject_cast<HbLabel *>(
       
   186             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_NO_MESSAGES));
       
   187 
       
   188         if (mNoMessagesLabel) {
       
   189             NMLOG("NmMessageSearchListView: \"No messages\" label loaded.");
       
   190             mNoMessagesLabel->hide();
       
   191         }
       
   192 
       
   193         // Load the info label.
   195         // Load the info label.
   194         mInfoLabel = qobject_cast<HbLabel *>(
   196         mInfoLabel = qobject_cast<HbLabel *>(
   195             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL));
   197             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL));
   196 
   198 
   197         if (mInfoLabel) {
   199         if (mInfoLabel) {
   198             NMLOG("NmMessageSearchListView: Info label loaded.");
   200             NMLOG("NmMessageSearchListView: Info label loaded.");
   199             mInfoLabel->setPlainText(hbTrId("txt_mail_subhead_inbox"));
   201             mInfoLabel->setPlainText(hbTrId("txt_mail_subhead_inbox"));
   200             mInfoLabel->hide();
   202             mInfoLabel->hide();
       
   203         }
       
   204 
       
   205         // Load the no messages label.
       
   206         mNoMessagesLabel = qobject_cast<HbLabel *>(
       
   207             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_NO_MESSAGES));
       
   208 
       
   209         if (mNoMessagesLabel) {
       
   210             NMLOG("NmMessageSearchListView: No messages label loaded.");
       
   211             mNoMessagesLabel->hide();
   201         }
   212         }
   202 
   213 
   203         // Load the search panel.
   214         // Load the search panel.
   204         mLineEdit = qobject_cast<HbLineEdit *>(
   215         mLineEdit = qobject_cast<HbLineEdit *>(
   205             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_LINE_EDIT));
   216             mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_LINE_EDIT));
   240         mMessageListWidget->setFocus();
   251         mMessageListWidget->setFocus();
   241         mItemContextMenu = new HbMenu();
   252         mItemContextMenu = new HbMenu();
   242     }
   253     }
   243 
   254 
   244     // Clear the previous content if any.
   255     // Clear the previous content if any.
   245     mSearchListModel.clearSearchResults();
   256     mMsgListModel.clear();
   246 }
   257 }
   247 
   258 
   248 
   259 
   249 /*!
   260 /*!
   250     Sets the title according to the name of the current mailbox.
   261     Sets the title according to the name of the current mailbox.
   342 
   353 
   343         // Store the new start parameter data.
   354         // Store the new start parameter data.
   344         mStartParam = startParam;
   355         mStartParam = startParam;
   345 
   356 
   346         // Update the model with new parameters.
   357         // Update the model with new parameters.
   347         NmMessageListModel &messageListModel =
   358         mUiEngine.messageListModelForSearch(startParam->mailboxId());
   348             mUiEngine.messageListModel(startParam->mailboxId(),
       
   349                                        startParam->folderId());
       
   350         mSearchListModel.setSourceModel(&messageListModel);
       
   351         refreshList();
   359         refreshList();
   352 
   360 
   353         // Refresh the mailbox name.
   361         // Refresh the mailbox name.
   354         setViewTitle();
   362         setViewTitle();
   355     }
   363     }
   361     }
   369     }
   362 }
   370 }
   363 
   371 
   364 
   372 
   365 /*!
   373 /*!
       
   374     Called when text is changed in the edit field. If there is no search term
       
   375     in the edit field, the search button is dimmed and disabled. If the field
       
   376     contains text, the button can be clicked.
       
   377     
       
   378     \param text The text in the field after the modification.
       
   379 */
       
   380 void NmMessageSearchListView::criteriaChanged(QString text) 
       
   381 {
       
   382     NMLOG(QString("NmMessageSearchListView::criteriaChanged %1").arg(text));
       
   383     
       
   384     // Check if the button should be disabled/enabled.
       
   385     bool enabled = mPushButton->isEnabled();
       
   386 
       
   387     if (!enabled && !text.isEmpty()) {
       
   388         mPushButton->setEnabled(true);
       
   389     }
       
   390     else if (enabled && text.isEmpty()) {
       
   391         mPushButton->setEnabled(false);
       
   392     }
       
   393 }
       
   394 
       
   395 
       
   396 /*!
   366     Displays the item context menu. This method gets called if an item on the
   397     Displays the item context menu. This method gets called if an item on the
   367     list is long pressed.
   398     list is long pressed.
   368 */
   399 */
   369 void NmMessageSearchListView::showItemContextMenu(
   400 void NmMessageSearchListView::showItemContextMenu(
   370     HbAbstractViewItem *listViewItem, const QPointF &coords)
   401     HbAbstractViewItem *listViewItem, const QPointF &coords)
   371 {
   402 {
   372     // Store long press item for later use with response.
   403     // Store long press item for later use with response.
   373     mLongPressedItem = 
   404     mLongPressedItem = 
   374         mSearchListModel.data(listViewItem->modelIndex(),
   405         mMsgListModel.data(listViewItem->modelIndex(),
   375                               Qt::DisplayRole).value<NmMessageListModelItem*>();
   406                            Qt::DisplayRole).value<NmMessageListModelItem*>();
   376 
   407 
   377     if (mItemContextMenu && mLongPressedItem && mLongPressedItem->itemType() ==
   408     if (mItemContextMenu && mLongPressedItem &&
   378         NmMessageListModelItem::NmMessageItemMessage) {
   409         mLongPressedItem->itemType() == NmMessageListModelItem::NmMessageItemMessage) {
   379         // Clear the previous menu actions.
   410         // Clear the previous menu actions.
   380         mItemContextMenu->clearActions();
   411         mItemContextMenu->clearActions();
   381         NmUiExtensionManager &extMngr = mApplication.extManager();
   412         NmUiExtensionManager &extMngr = mApplication.extManager();
   382         QList<NmAction*> list;
   413         QList<NmAction*> list;
   383 
   414 
   384         // Fetch the menu actions based on the selected item.
   415         // Fetch the menu actions based on the selected item.
   385         NmMessageEnvelope *envelope = mLongPressedItem->envelopePtr();
   416         NmMessageEnvelope *envelope = mLongPressedItem->envelopePtr();
   386 
   417 
   387         if (envelope){
   418         if (envelope){
   388             NmActionRequest request(this, NmActionContextMenu, NmActionContextViewMessageList,
   419             NmActionRequest request(this, NmActionContextMenu,
   389                 NmActionContextDataMessage, mStartParam->mailboxId(), mStartParam->folderId(),
   420                 NmActionContextViewMessageList, NmActionContextDataMessage,
       
   421                 mStartParam->mailboxId(), mStartParam->folderId(),
   390                 envelope->messageId(),QVariant::fromValue(envelope));
   422                 envelope->messageId(),QVariant::fromValue(envelope));
   391 
   423 
   392             extMngr.getActions(request, list);
   424             extMngr.getActions(request, list);
   393         }
   425         }
   394         else{
   426         else{
   395             NmActionRequest request(this, NmActionContextMenu, NmActionContextViewMessageList,
   427             NmActionRequest request(this, NmActionContextMenu,
   396                 NmActionContextDataMessage, mStartParam->mailboxId(), mStartParam->folderId(),
   428                 NmActionContextViewMessageList, NmActionContextDataMessage,
       
   429                 mStartParam->mailboxId(), mStartParam->folderId(),
   397                 envelope->messageId());
   430                 envelope->messageId());
   398 
   431 
   399             extMngr.getActions(request, list);
   432             extMngr.getActions(request, list);
   400         }
   433         }
   401 
   434 
   402         for (int i(0); i < list.count(); ++i) {
   435         for (int i(0); i < list.count(); ++i) {
   403             mItemContextMenu->addAction(list[i]);
   436             mItemContextMenu->addAction(list[i]);
   404         }
   437         }
       
   438 
   405         mItemContextMenu->setPreferredPos(coords);
   439         mItemContextMenu->setPreferredPos(coords);
   406         mItemContextMenu->open(this, SLOT(contextButton(NmActionResponse&)));
   440         mItemContextMenu->open();
   407     }
   441     }
   408 }
   442 }
   409 
   443 
   410 /*!
       
   411     Slot. Signaled when menu option is selected
       
   412 */
       
   413 void NmMessageSearchListView::contextButton(NmActionResponse &result)
       
   414 {
       
   415 // Handle context menu commands here.
       
   416     if (result.menuType() == NmActionContextMenu){
       
   417         switch (result.responseCommand()) {
       
   418            case NmActionResponseCommandOpen: {
       
   419                if (mLongPressedItem){
       
   420                    NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer,
       
   421                        mStartParam->mailboxId(), mStartParam->folderId(),
       
   422                        mLongPressedItem->envelope().messageId());
       
   423 
       
   424                    mApplication.enterNmUiView(startParam);
       
   425                    mLongPressedItem = NULL;
       
   426                }
       
   427 
       
   428                break;
       
   429            }
       
   430            default: {
       
   431                break;
       
   432            }
       
   433         }
       
   434     }
       
   435 }
       
   436 
   444 
   437 /*!
   445 /*!
   438     Stores the given index and forwards the call to handleSelection(). This
   446     Stores the given index and forwards the call to handleSelection(). This
   439     method gets called when an item on the list is selected.  
   447     method gets called when an item on the list is selected.  
   440 
   448 
   444 {
   452 {
   445     mActivatedIndex = index;
   453     mActivatedIndex = index;
   446     QMetaObject::invokeMethod(this, "handleSelection", Qt::QueuedConnection);
   454     QMetaObject::invokeMethod(this, "handleSelection", Qt::QueuedConnection);
   447 }
   455 }
   448 
   456 
   449 /*!
       
   450     Called when text is changed in the edit field
       
   451     
       
   452     \param text new text entered in the field
       
   453  */
       
   454 void NmMessageSearchListView::criteriaChanged(QString text) 
       
   455 {
       
   456     NMLOG(QString("NmMessageSearchListView::criteriaChanged %1").arg(text));
       
   457     
       
   458     // Check when button should be disabled/enabled
       
   459     bool enabled = mPushButton->isEnabled();
       
   460     if (!enabled && !text.isEmpty()) {
       
   461 		mPushButton->setEnabled(true);
       
   462     }
       
   463     else if (enabled && text.isEmpty()) {
       
   464 		mPushButton->setEnabled(false);
       
   465     }
       
   466 }
       
   467 
   457 
   468 /*!
   458 /*!
   469     If the selected item is a message, will open the message.
   459     If the selected item is a message, will open the message.
   470 */
   460 */
   471 void NmMessageSearchListView::handleSelection()
   461 void NmMessageSearchListView::handleSelection()
   472 {
   462 {
   473     // Do expand/collapse for title divider items
   463     // Do expand/collapse for title divider items
   474     NmMessageListModelItem* modelItem = mSearchListModel.data(
   464     NmMessageListModelItem* modelItem = mMsgListModel.data(
   475         mActivatedIndex, Qt::DisplayRole).value<NmMessageListModelItem*>();
   465         mActivatedIndex, Qt::DisplayRole).value<NmMessageListModelItem*>();
   476 
   466 
   477     if (modelItem &&
   467     if (modelItem &&
   478         modelItem->itemType() == NmMessageListModelItem::NmMessageItemMessage)
   468         modelItem->itemType() == NmMessageListModelItem::NmMessageItemMessage)
   479     {
   469     {
   524 }
   514 }
   525 
   515 
   526 
   516 
   527 /*!
   517 /*!
   528     This method gets called when an item is removed from the list. If the list
   518     This method gets called when an item is removed from the list. If the list
   529     contains no items, "no messages" label is displayed.
   519     contains no items, the info label (if visible) is hidden and the "no
       
   520     messages" label is displayed. Otherwise, only the result count in the info
       
   521     label is updated.
   530 */
   522 */
   531 void NmMessageSearchListView::itemsRemoved()
   523 void NmMessageSearchListView::itemsRemoved()
   532 {
   524 {
   533     if (mSearchListModel.searchResultCount() == 0) {
   525     const int itemCount = mMsgListModel.rowCount();
       
   526 
       
   527     if (itemCount == 0) {
       
   528         if (mInfoLabel && mInfoLabel->isVisible()) {
       
   529             // Hide the info label.
       
   530             mInfoLabel->hide();
       
   531         }
       
   532 
       
   533         // Display the "no messages" label.
   534         noMessagesLabelVisibility(true);
   534         noMessagesLabelVisibility(true);
       
   535     }
       
   536     else if (mInfoLabel && mInfoLabel->isVisible()) {
       
   537         // Update the search result count in the info label.
       
   538         QString resultsString(hbTrId("txt_mail_list_search_results"));
       
   539         resultsString.arg(itemCount);
       
   540         mInfoLabel->setPlainText(resultsString);
   535     }
   541     }
   536 }
   542 }
   537 
   543 
   538 
   544 
   539 /*!
   545 /*!
   541 */
   547 */
   542 void NmMessageSearchListView::refreshList()
   548 void NmMessageSearchListView::refreshList()
   543 {
   549 {
   544     if (mMessageListWidget) {
   550     if (mMessageListWidget) {
   545         // Set the model.
   551         // Set the model.
   546         NmMessageListModel &messageListModel =
       
   547             mUiEngine.messageListModel(mStartParam->mailboxId(),
       
   548                                        mStartParam->folderId());
       
   549         mSearchListModel.setSourceModel(&messageListModel);
       
   550         mMessageListWidget->setModel(
   552         mMessageListWidget->setModel(
   551             static_cast<QSortFilterProxyModel*>(&mSearchListModel));
   553             static_cast<QStandardItemModel*>(&mMsgListModel));
   552 
   554 
   553         // Connect the signals.
   555         // Connect the signals.
   554         connect(&mSearchListModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
   556         connect(&mMsgListModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
   555                 this, SLOT(itemsAdded(const QModelIndex&, int, int)), Qt::UniqueConnection);
   557                 this, SLOT(itemsAdded(const QModelIndex&, int, int)), Qt::UniqueConnection);
   556 
   558 
   557         connect(&mSearchListModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
   559         connect(&mMsgListModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
   558                 this, SLOT(itemsRemoved()), Qt::UniqueConnection);
   560                 this, SLOT(itemsRemoved()), Qt::UniqueConnection);
   559 
   561 
   560         connect(&messageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   562         connect(&mMsgListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   561                 this, SLOT(reloadViewContents(NmUiStartParam*)), Qt::UniqueConnection);
   563                 this, SLOT(reloadViewContents(NmUiStartParam*)), Qt::UniqueConnection);
   562 
   564 
   563     }
   565     }
   564 }
   566 }
   565 
   567 
   583     else {
   585     else {
   584         // Do start the search.
   586         // Do start the search.
   585         mSearchInProgress = true;
   587         mSearchInProgress = true;
   586     
   588     
   587         // Clear previous results if any.
   589         // Clear previous results if any.
   588         mSearchListModel.clearSearchResults();
   590         mMsgListModel.clear();
   589 
   591 
   590         connect(&mUiEngine, SIGNAL(searchComplete()),
   592         connect(&mUiEngine, SIGNAL(searchComplete()),
   591                 this, SLOT(handleSearchComplete()), Qt::UniqueConnection);
   593                 this, SLOT(handleSearchComplete()), Qt::UniqueConnection);
   592     
   594     
   593         // Get the search input and start the search.
   595         // Get the search input and start the search.
   630     // Change the push button text.
   632     // Change the push button text.
   631     if (mPushButton) {
   633     if (mPushButton) {
   632         mPushButton->setIcon(HbIcon("qtg_mono_search"));
   634         mPushButton->setIcon(HbIcon("qtg_mono_search"));
   633     }
   635     }
   634 
   636 
   635     const int resultCount = mSearchListModel.searchResultCount();
   637     const int resultCount = mMsgListModel.rowCount();
   636 
       
   637     if (resultCount == 1) {
       
   638         // For some reason when the result count is only 1, the search list
       
   639         // will not display the found message. Until the underlying reason for
       
   640         // this bug is found, let us use the following solution to fix this
       
   641         // issue.
       
   642         refreshList();
       
   643     }
       
   644 
   638 
   645     if (resultCount) {
   639     if (resultCount) {
   646         if (mInfoLabel) {
   640         if (mInfoLabel) {
   647             // Display the result count on the info label.
   641             // Display the result count on the info label.
   648             QString resultsString(hbTrId("txt_mail_list_search_results"));
   642             QString resultsString(hbTrId("txt_mail_list_search_results"));