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) |
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)); |
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 |