17 |
17 |
18 static const char *NMUI_MESSAGE_SEARCH_LIST_VIEW_XML = ":/docml/nmmessagesearchlistview.docml"; |
18 static const char *NMUI_MESSAGE_SEARCH_LIST_VIEW_XML = ":/docml/nmmessagesearchlistview.docml"; |
19 static const char *NMUI_MESSAGE_SEARCH_LIST_VIEW = "NmMessageListView"; |
19 static const char *NMUI_MESSAGE_SEARCH_LIST_VIEW = "NmMessageListView"; |
20 static const char *NMUI_MESSAGE_SEARCH_LIST_TREE_LIST = "MessageTreeList"; |
20 static const char *NMUI_MESSAGE_SEARCH_LIST_TREE_LIST = "MessageTreeList"; |
21 static const char *NMUI_MESSAGE_SEARCH_LIST_NO_MESSAGES = "MessageListNoMessages"; |
21 static const char *NMUI_MESSAGE_SEARCH_LIST_NO_MESSAGES = "MessageListNoMessages"; |
22 static const char *NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL = "InfoLabel"; |
22 static const char *NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL = "LabelGroupBox"; |
23 static const char *NMUI_MESSAGE_SEARCH_LIST_LINE_EDIT = "LineEdit"; |
23 static const char *NMUI_MESSAGE_SEARCH_LIST_LINE_EDIT = "LineEdit"; |
24 static const char *NMUI_MESSAGE_SEARCH_LIST_PUSH_BUTTON = "PushButton"; |
24 static const char *NMUI_MESSAGE_SEARCH_LIST_PUSH_BUTTON = "PushButton"; |
25 |
25 |
26 |
26 |
27 #include "nmuiheaders.h" |
27 #include "nmuiheaders.h" |
143 } |
153 } |
144 // Handle context menu commands here. |
154 // Handle context menu commands here. |
145 if (actionResponse.menuType() == NmActionContextMenu) { |
155 if (actionResponse.menuType() == NmActionContextMenu) { |
146 if (mLongPressedItem){ |
156 if (mLongPressedItem){ |
147 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer, |
157 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageViewer, |
148 mStartParam->mailboxId(), mStartParam->folderId(), |
158 mStartParam->mailboxId(), mLongPressedItem->envelope().folderId(), |
149 mLongPressedItem->envelope().messageId()); |
159 mLongPressedItem->envelope().messageId()); |
150 |
160 |
151 mApplication.enterNmUiView(startParam); |
161 mApplication.enterNmUiView(startParam); |
152 mLongPressedItem = NULL; |
162 mLongPressedItem = NULL; |
153 } |
163 } |
179 // Get the message list widget. |
191 // Get the message list widget. |
180 mMessageListWidget = qobject_cast<HbTreeView *>( |
192 mMessageListWidget = qobject_cast<HbTreeView *>( |
181 mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_TREE_LIST)); |
193 mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_TREE_LIST)); |
182 |
194 |
183 if (mMessageListWidget) { |
195 if (mMessageListWidget) { |
184 NMLOG("NmMessageSearchListView: Message list widget loaded."); |
196 NM_COMMENT("NmMessageSearchListView: message list widget loaded"); |
185 |
197 |
186 // Set the item prototype. |
198 // Set the item prototype. |
187 mMessageListWidget->setItemPrototype(new NmMessageListViewItem()); |
199 mMessageListWidget->setItemPrototype(new NmMessageListViewItem()); |
|
200 |
|
201 // Set the list widget properties. |
188 mMessageListWidget->setItemRecycling(true); |
202 mMessageListWidget->setItemRecycling(true); |
189 mMessageListWidget->contentWidget()->setProperty("indentation", 0); |
203 mMessageListWidget->contentWidget()->setProperty("indentation", 0); |
190 mMessageListWidget->setScrollDirections(Qt::Vertical); |
204 mMessageListWidget->setScrollDirections(Qt::Vertical); |
191 mMessageListWidget->setClampingStyle(HbScrollArea::BounceBackClamping); |
205 mMessageListWidget->setClampingStyle(HbScrollArea::BounceBackClamping); |
192 mMessageListWidget->setFrictionEnabled(true); |
206 mMessageListWidget->setFrictionEnabled(true); |
|
207 |
|
208 // We want the search results to appear one by one. |
|
209 mMessageListWidget->setEnabledAnimations(HbAbstractItemView::Appear & |
|
210 HbAbstractItemView::Expand); |
193 } |
211 } |
194 |
212 |
195 // Load the info label. |
213 // Load the info label. |
196 mInfoLabel = qobject_cast<HbLabel *>( |
214 mInfoLabel = qobject_cast<HbGroupBox *>( |
197 mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL)); |
215 mDocumentLoader->findWidget(NMUI_MESSAGE_SEARCH_LIST_INFO_LABEL)); |
198 |
216 |
199 if (mInfoLabel) { |
217 if (mInfoLabel) { |
200 NMLOG("NmMessageSearchListView: Info label loaded."); |
218 NM_COMMENT("NmMessageSearchListView: info label loaded"); |
201 mInfoLabel->setPlainText(hbTrId("txt_mail_subhead_inbox")); |
|
202 mInfoLabel->hide(); |
219 mInfoLabel->hide(); |
203 } |
220 } |
204 |
221 |
205 // Load the no messages label. |
222 // Load the no messages label. |
206 mNoMessagesLabel = qobject_cast<HbLabel *>( |
223 mNoMessagesLabel = qobject_cast<HbLabel *>( |
228 connect(mPushButton, SIGNAL(clicked()), this, SLOT(toggleSearch())); |
245 connect(mPushButton, SIGNAL(clicked()), this, SLOT(toggleSearch())); |
229 mPushButton->setIcon(HbIcon("qtg_mono_search")); |
246 mPushButton->setIcon(HbIcon("qtg_mono_search")); |
230 } |
247 } |
231 } |
248 } |
232 else { |
249 else { |
233 NMLOG("NmMessageSearchListView: Failed to load widgets from XML!"); |
250 NM_ERROR(1, "NmMessageSearchListView: failed to load widgets from XML"); |
234 } |
251 } |
235 } |
252 } |
236 |
253 |
237 |
254 |
238 /*! |
255 /*! |
239 Initializes the tree view. |
256 Initializes the tree view. |
240 */ |
257 */ |
241 void NmMessageSearchListView::initTreeView() |
258 void NmMessageSearchListView::initTreeView() |
242 { |
259 { |
|
260 NM_FUNCTION; |
|
261 |
243 // Get the mailbox widget pointer and set the parameters. |
262 // Get the mailbox widget pointer and set the parameters. |
244 if (mMessageListWidget) { |
263 if (mMessageListWidget) { |
245 connect(mMessageListWidget, SIGNAL(activated(const QModelIndex &)), |
264 connect(mMessageListWidget, SIGNAL(activated(const QModelIndex &)), |
246 this, SLOT(itemActivated(const QModelIndex &))); |
265 this, SLOT(itemActivated(const QModelIndex &))); |
247 |
266 |
279 \param visible If true, will display the "no messages" label. If false, |
300 \param visible If true, will display the "no messages" label. If false, |
280 will display the message list widget. |
301 will display the message list widget. |
281 */ |
302 */ |
282 void NmMessageSearchListView::noMessagesLabelVisibility(bool visible) |
303 void NmMessageSearchListView::noMessagesLabelVisibility(bool visible) |
283 { |
304 { |
|
305 NM_FUNCTION; |
|
306 |
284 if (visible) { |
307 if (visible) { |
285 // Hide the message list widget and display the "no messages" label. |
308 // Hide the message list widget and display the "no messages" label. |
286 if (mMessageListWidget) { |
309 if (mMessageListWidget) { |
287 mMessageListWidget->hide(); |
310 mMessageListWidget->hide(); |
288 } |
311 } |
303 } |
326 } |
304 } |
327 } |
305 |
328 |
306 |
329 |
307 /*! |
330 /*! |
|
331 Updates the search result count information. If the message list does not |
|
332 contain any items, a "no messages" label is displayed. Otherwise the result |
|
333 count in the information label is updated according to the number of |
|
334 messages in the list. |
|
335 */ |
|
336 void NmMessageSearchListView::updateSearchResultCountInfo() |
|
337 { |
|
338 NM_FUNCTION; |
|
339 |
|
340 const int resultCount = mMsgListModel.rowCount(); |
|
341 |
|
342 if (resultCount) { |
|
343 if (mInfoLabel) { |
|
344 // Display the result count on the info label. |
|
345 QString resultsString(hbTrId("txt_mail_list_search_results").arg(resultCount)); |
|
346 mInfoLabel->setHeading(resultsString); |
|
347 |
|
348 if (!mInfoLabel->isVisible()) { |
|
349 mInfoLabel->show(); |
|
350 } |
|
351 } |
|
352 } |
|
353 else { |
|
354 // No search results! |
|
355 if (mInfoLabel && mInfoLabel->isVisible()) { |
|
356 mInfoLabel->hide(); |
|
357 } |
|
358 |
|
359 // Display the "no messages" label and highlight the search term. |
|
360 noMessagesLabelVisibility(true); |
|
361 } |
|
362 |
|
363 } |
|
364 |
|
365 |
|
366 /*! |
308 Sets the mode for the search input. |
367 Sets the mode for the search input. |
309 |
368 |
310 \param mode The mode to set. |
369 \param mode The mode to set. |
311 */ |
370 */ |
312 void NmMessageSearchListView::setSearchInputMode(NmSearchInputMode mode) |
371 void NmMessageSearchListView::setSearchInputMode(NmSearchInputMode mode) |
313 { |
372 { |
|
373 NM_FUNCTION; |
|
374 |
314 if (!mLineEdit) { |
375 if (!mLineEdit) { |
315 // No line edit widget! |
376 // No line edit widget! |
316 return; |
377 return; |
317 } |
378 } |
318 |
379 |
341 typically used when the view is already open and an external view activation |
402 typically used when the view is already open and an external view activation |
342 occurs for this same view. |
403 occurs for this same view. |
343 */ |
404 */ |
344 void NmMessageSearchListView::reloadViewContents(NmUiStartParam *startParam) |
405 void NmMessageSearchListView::reloadViewContents(NmUiStartParam *startParam) |
345 { |
406 { |
346 // Check the start parameter's validity; message view cannot be updated if |
407 NM_FUNCTION; |
347 // the given parameter is zero. |
408 |
348 if (startParam&&startParam->viewId() == NmUiViewMessageSearchList && |
409 if (startParam && startParam->viewId() == NmUiViewMessageSearchList) { |
349 startParam->folderId() != 0) { |
|
350 // Delete the existing start parameter data. |
410 // Delete the existing start parameter data. |
351 delete mStartParam; |
411 delete mStartParam; |
352 mStartParam = NULL; |
412 mStartParam = NULL; |
353 |
413 |
354 // Store the new start parameter data. |
414 // Store the new start parameter data. |
398 list is long pressed. |
459 list is long pressed. |
399 */ |
460 */ |
400 void NmMessageSearchListView::showItemContextMenu( |
461 void NmMessageSearchListView::showItemContextMenu( |
401 HbAbstractViewItem *listViewItem, const QPointF &coords) |
462 HbAbstractViewItem *listViewItem, const QPointF &coords) |
402 { |
463 { |
|
464 NM_FUNCTION; |
|
465 |
403 // Store long press item for later use with response. |
466 // Store long press item for later use with response. |
404 mLongPressedItem = |
467 mLongPressedItem = |
405 mMsgListModel.data(listViewItem->modelIndex(), |
468 mMsgListModel.data(listViewItem->modelIndex(), |
406 Qt::DisplayRole).value<NmMessageListModelItem*>(); |
469 Qt::DisplayRole).value<NmMessageListModelItem*>(); |
407 |
470 |
415 // Fetch the menu actions based on the selected item. |
478 // Fetch the menu actions based on the selected item. |
416 NmMessageEnvelope *envelope = mLongPressedItem->envelopePtr(); |
479 NmMessageEnvelope *envelope = mLongPressedItem->envelopePtr(); |
417 |
480 |
418 if (envelope){ |
481 if (envelope){ |
419 NmActionRequest request(this, NmActionContextMenu, |
482 NmActionRequest request(this, NmActionContextMenu, |
420 NmActionContextViewMessageList, NmActionContextDataMessage, |
483 NmActionContextViewMessageSearchList, NmActionContextDataMessage, |
421 mStartParam->mailboxId(), mStartParam->folderId(), |
484 mStartParam->mailboxId(), envelope->folderId(), |
422 envelope->messageId(),QVariant::fromValue(envelope)); |
485 envelope->messageId(), QVariant::fromValue(envelope)); |
423 |
|
424 extMngr.getActions(request, list); |
|
425 } |
|
426 else{ |
|
427 NmActionRequest request(this, NmActionContextMenu, |
|
428 NmActionContextViewMessageList, NmActionContextDataMessage, |
|
429 mStartParam->mailboxId(), mStartParam->folderId(), |
|
430 envelope->messageId()); |
|
431 |
486 |
432 extMngr.getActions(request, list); |
487 extMngr.getActions(request, list); |
433 } |
488 } |
434 |
489 |
435 for (int i(0); i < list.count(); ++i) { |
490 for (int i(0); i < list.count(); ++i) { |
448 |
503 |
449 \param index The index of the activated item. |
504 \param index The index of the activated item. |
450 */ |
505 */ |
451 void NmMessageSearchListView::itemActivated(const QModelIndex &index) |
506 void NmMessageSearchListView::itemActivated(const QModelIndex &index) |
452 { |
507 { |
|
508 NM_FUNCTION; |
|
509 |
453 mActivatedIndex = index; |
510 mActivatedIndex = index; |
454 QMetaObject::invokeMethod(this, "handleSelection", Qt::QueuedConnection); |
511 QMetaObject::invokeMethod(this, "handleSelection", Qt::QueuedConnection); |
455 } |
512 } |
456 |
513 |
457 |
514 |
458 /*! |
515 /*! |
459 If the selected item is a message, will open the message. |
516 If the selected item is a message, will open the message. |
460 */ |
517 */ |
461 void NmMessageSearchListView::handleSelection() |
518 void NmMessageSearchListView::handleSelection() |
462 { |
519 { |
|
520 NM_FUNCTION; |
|
521 |
463 // Do expand/collapse for title divider items |
522 // Do expand/collapse for title divider items |
464 NmMessageListModelItem* modelItem = mMsgListModel.data( |
523 NmMessageListModelItem* modelItem = mMsgListModel.data( |
465 mActivatedIndex, Qt::DisplayRole).value<NmMessageListModelItem*>(); |
524 mActivatedIndex, Qt::DisplayRole).value<NmMessageListModelItem*>(); |
466 |
525 |
467 if (modelItem && |
526 if (modelItem && |
486 Displays the message list widtet if not visible and scrolls to the |
545 Displays the message list widtet if not visible and scrolls to the |
487 appropriate point on the list. |
546 appropriate point on the list. |
488 */ |
547 */ |
489 void NmMessageSearchListView::itemsAdded(const QModelIndex &parent, int start, int end) |
548 void NmMessageSearchListView::itemsAdded(const QModelIndex &parent, int start, int end) |
490 { |
549 { |
491 NMLOG("nmailui: NmMessageSearchListView::itemsAdded()"); |
550 NM_FUNCTION; |
492 |
551 |
493 Q_UNUSED(parent); |
552 Q_UNUSED(parent); |
494 Q_UNUSED(end); |
553 Q_UNUSED(end); |
495 |
554 |
496 // Display the message list widget if not visible. |
555 // The search is an asynchronous operation. If a user stops the search, it |
497 noMessagesLabelVisibility(false); |
556 // might take a short while before the search is actually stopped and during |
|
557 // this time it is possible that messages matching the search are added. |
|
558 // Therefore, update the result count info if items are added after the |
|
559 // search has been stopped by the user. |
|
560 if (!mSearchInProgress) { |
|
561 updateSearchResultCountInfo(); |
|
562 } |
498 |
563 |
499 if (!start && mMessageListWidget) { |
564 if (!start && mMessageListWidget) { |
500 QList<HbAbstractViewItem*> items = mMessageListWidget->visibleItems(); |
565 QList<HbAbstractViewItem*> items = mMessageListWidget->visibleItems(); |
501 |
566 |
502 if (items.count()) { |
567 if (items.count()) { |
503 QModelIndex index = items.at(0)->modelIndex(); |
568 QModelIndex index = items.at(0)->modelIndex(); |
504 |
569 |
505 if (1 == index.row()) { |
570 while (index.row() > 0) { |
506 QModelIndex previous = mMessageListWidget->modelIterator()->previousIndex(index); |
571 QModelIndex previous = |
|
572 mMessageListWidget->modelIterator()->previousIndex(index); |
507 |
573 |
508 if (previous.isValid()) { |
574 if (previous.isValid()) { |
509 mMessageListWidget->scrollTo(previous); |
575 mMessageListWidget->scrollTo(previous); |
510 } |
576 } |
|
577 |
|
578 index = previous; |
511 } |
579 } |
512 } |
580 } |
513 } |
581 } |
514 } |
582 } |
515 |
583 |
516 |
584 |
517 /*! |
585 /*! |
518 This method gets called when an item is removed from the list. If the list |
586 This method gets called when an item is removed from the list. If the |
519 contains no items, the info label (if visible) is hidden and the "no |
587 search has completed (or stopped), the search result count information is |
520 messages" label is displayed. Otherwise, only the result count in the info |
588 updated according to the number of messages in the list. |
521 label is updated. |
|
522 */ |
589 */ |
523 void NmMessageSearchListView::itemsRemoved() |
590 void NmMessageSearchListView::itemsRemoved() |
524 { |
591 { |
525 const int itemCount = mMsgListModel.rowCount(); |
592 NM_FUNCTION; |
526 |
593 |
527 if (itemCount == 0) { |
594 if (!mSearchInProgress) { |
528 if (mInfoLabel && mInfoLabel->isVisible()) { |
595 updateSearchResultCountInfo(); |
529 // Hide the info label. |
|
530 mInfoLabel->hide(); |
|
531 } |
|
532 |
|
533 // Display the "no messages" label. |
|
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); |
|
541 } |
596 } |
542 } |
597 } |
543 |
598 |
544 |
599 |
545 /*! |
600 /*! |
546 Refreshes the search list. |
601 Refreshes the search list. |
547 */ |
602 */ |
548 void NmMessageSearchListView::refreshList() |
603 void NmMessageSearchListView::refreshList() |
549 { |
604 { |
|
605 NM_FUNCTION; |
|
606 |
550 if (mMessageListWidget) { |
607 if (mMessageListWidget) { |
551 // Set the model. |
608 // Set the model. |
552 mMessageListWidget->setModel( |
609 mMessageListWidget->setModel( |
553 static_cast<QStandardItemModel*>(&mMsgListModel)); |
610 static_cast<QStandardItemModel*>(&mMsgListModel)); |
554 |
611 |
624 info label. If no messages were found, the method displays the "no messages" |
683 info label. If no messages were found, the method displays the "no messages" |
625 label. In either case, the search panel is updated. |
684 label. In either case, the search panel is updated. |
626 */ |
685 */ |
627 void NmMessageSearchListView::handleSearchComplete() |
686 void NmMessageSearchListView::handleSearchComplete() |
628 { |
687 { |
629 NMLOG("NmMessageSearchListView::handleSearchComplete()"); |
688 NM_FUNCTION; |
|
689 |
630 mSearchInProgress = false; |
690 mSearchInProgress = false; |
631 |
691 |
632 // Change the push button text. |
692 // Change the push button text. |
633 if (mPushButton) { |
693 if (mPushButton) { |
634 mPushButton->setIcon(HbIcon("qtg_mono_search")); |
694 mPushButton->setIcon(HbIcon("qtg_mono_search")); |
635 } |
695 } |
636 |
696 |
|
697 // Display the search result count. |
|
698 updateSearchResultCountInfo(); |
|
699 |
637 const int resultCount = mMsgListModel.rowCount(); |
700 const int resultCount = mMsgListModel.rowCount(); |
638 |
701 |
639 if (resultCount) { |
702 if (resultCount) { |
640 if (mInfoLabel) { |
|
641 // Display the result count on the info label. |
|
642 QString resultsString(hbTrId("txt_mail_list_search_results")); |
|
643 resultsString.arg(resultCount); |
|
644 mInfoLabel->setPlainText(resultsString); |
|
645 |
|
646 if (!mInfoLabel->isVisible()) { |
|
647 mInfoLabel->show(); |
|
648 } |
|
649 } |
|
650 |
|
651 // Undim the search input. |
703 // Undim the search input. |
652 setSearchInputMode(NmNormalMode); |
704 setSearchInputMode(NmNormalMode); |
653 } |
705 } |
654 else { |
706 else { |
655 // No search results! |
707 // Highlight the search field. |
656 if (mInfoLabel && mInfoLabel->isVisible()) { |
|
657 mInfoLabel->hide(); |
|
658 } |
|
659 |
|
660 // Display the "no messags" label and highlight the search term. |
|
661 noMessagesLabelVisibility(true); |
708 noMessagesLabelVisibility(true); |
662 setSearchInputMode(NmHighlightedMode); |
709 setSearchInputMode(NmHighlightedMode); |
663 } |
710 } |
664 } |
711 } |
665 |
712 |