2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file EmSearchPresentationModel.cpp
19 * @brief Keeps the implementation of SearchPresentationModel class
24 #include "EmNativeMailboxManager.h"
25 #include "EmSearchPresentationModel.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Locales;
33 using namespace Tizen::System;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
39 SearchPresentationModel* SearchPresentationModel::__pInstance = null;
41 SearchPresentationModel*
42 SearchPresentationModel::GetInstance()
46 if (__pInstance == null)
48 __pInstance = new (std::nothrow) SearchPresentationModel();
49 __pInstance->Construct();
52 AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
56 SearchPresentationModel::SearchPresentationModel()
57 : __searchFilter(SEARCH_ALL)
59 , __pSearchFromData(null)
61 // Empty implementation
64 SearchPresentationModel::~SearchPresentationModel()
66 // Empty implementation
70 SearchPresentationModel::Construct(void)
76 BasePresentationModel::Construct();
78 _pMailList = new (std::nothrow) ArrayList();
79 r = _pMailList->Construct();
80 TryCatch(r == E_SUCCESS, r = E_FAILURE, "Failed to construct result arraylist");
88 SearchPresentationModel::DestroyInstance(void)
92 if (__pInstance != null)
94 __pInstance->CleanupInstance();
104 SearchPresentationModel::CreateInstance(void)
106 AppLogDebug("ENTER");
108 result r = E_SUCCESS;
110 __pInstance = new (std::nothrow) SearchPresentationModel();
111 r = __pInstance->Construct();
120 std::atexit(DestroyInstance);
127 SearchPresentationModel::CleanupInstance(void)
129 AppLogDebug("ENTER");
131 _pMailList->RemoveAll();
139 SearchPresentationModel::FetchData(int accountId, bool forceUpdate)
141 // Empty Implementation
145 SearchPresentationModel::Initialize(BasePresentationModel* pModel)
147 AppLogDebug("ENTER");
149 result r = E_SUCCESS;
152 __pSearchFromData = __pModel->GetData();
154 _sortType = __pModel->GetSortType();
161 SearchPresentationModel::PerformSearch(const Tizen::Base::String& searchKey, bool fullDataSearch)
163 AppLogDebug("ENTER, searchKey:(%ls), fullDataSearch:(%d)", searchKey.GetPointer(), fullDataSearch);
165 EmailMessageListItem* pMsgItem;
170 __searchKey.Append(searchKey);
172 searchKey.ToUpperCase(tmpSearchKey);
174 if (tmpSearchKey.IsEmpty() == true)
178 if (_pMailList != null && __pSearchFromData != null)
180 _pMailList->AddItems(*__pSearchFromData);
184 else if (fullDataSearch == true && __pSearchFromData != null)
188 for (int i = 0; i < __pSearchFromData->GetCount(); i++)
190 pMsgItem = static_cast<EmailMessageListItem*>(__pSearchFromData->GetAt(i));
192 if (pMsgItem != null)
194 if (__searchFilter == SEARCH_ALL)
196 pMsgItem->GetFromEmailAddress().ToUpperCase(tmpSearchInp);
197 if (tmpSearchInp.Contains(tmpSearchKey))
199 _pMailList->Add(pMsgItem);
203 pMsgItem->GetSubject().ToUpperCase(tmpSearchInp);
204 if (tmpSearchInp.Contains(tmpSearchKey))
206 _pMailList->Add(pMsgItem);
210 pMsgItem->GetRecipients().ToUpperCase(tmpSearchInp);
211 if (tmpSearchInp.Contains(tmpSearchKey))
213 _pMailList->Add(pMsgItem);
217 pMsgItem->GetPreviewBodyText().ToUpperCase(tmpSearchInp);
218 if (tmpSearchInp.Contains(tmpSearchKey))
220 _pMailList->Add(pMsgItem);
224 else if (__searchFilter == SEARCH_SENDER)
226 pMsgItem->GetFromEmailAddress().ToUpperCase(tmpSearchInp);
227 if (tmpSearchInp.Contains(tmpSearchKey))
229 _pMailList->Add(pMsgItem);
232 else if (__searchFilter == SEARCH_TITLE)
234 pMsgItem->GetSubject().ToUpperCase(tmpSearchInp);
235 if (tmpSearchInp.Contains(tmpSearchKey))
237 _pMailList->Add(pMsgItem);
240 else if (__searchFilter == SEARCH_DATE)
242 // TODO Needs to be implemented
244 else if (__searchFilter == SEARCH_ADVANCED)
246 // TODO Needs to be implemented
258 SearchPresentationModel::SetSearchFilter(SearchFilter filter)
260 AppLogDebug("ENTER");
261 __searchFilter = filter;
266 SearchPresentationModel::ClearSearchData(void)
268 AppLogDebug("Enter");
270 if (_pMailList != null)
272 _pMailList->RemoveAll();
278 BasePresentationModel*
279 SearchPresentationModel::GetPresentationModel(void)
285 SearchPresentationModel::GetSearchKey(void)
292 SearchPresentationModel::GetSearchFilter(void)
294 return __searchFilter;
297 SearchResultProvider::SearchResultProvider()
298 : EmailBaseListViewItemProvider(SearchPresentationModel::GetInstance(), true)
300 __pSearchModel = SearchPresentationModel::GetInstance();
303 SearchResultProvider::~SearchResultProvider()
305 // Empty implementation
309 SearchResultProvider::CreateSubjectText(CustomItem* pItem, const EmailMessageListItem* pMail, const int& itemWidth)
311 AppLogDebug("ENTER");
315 if (pMail->GetHasAttachment() > 0)
317 subjectWidth = itemWidth - LIST_ITEM_OFFSET - X_ITEM_BITMAP - W_GENERIC_32;
321 subjectWidth = itemWidth - LIST_ITEM_OFFSET;
324 EnrichedTextCustomListElement* pCustomListElement = new (std::nothrow) EnrichedTextCustomListElement(__pSearchModel->GetSearchFilter(), SUBJECT_TEXT, pMail, __pSearchModel->GetSearchKey());
325 pItem->AddElement(Rectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1, subjectWidth, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE)), IDA_BASE_LISTVIEW_ITEM_PROVIDER_SUBJECT_ELEMENT, *(static_cast<ICustomElement *>(pCustomListElement)));
326 AppLogDebug("listheight %d", _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE));
327 AppLogDebug("rect bounds %d %d %d %d", X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1, subjectWidth, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE));
333 // String pSearchKey;
334 // String subjectText;
335 // String originalSubjectText;
336 // String firstSubString, secondSubString, thirdSubString;
338 // originalSubjectText = pMail->GetSubject();
340 // if (originalSubjectText.IsEmpty() == false)
342 // originalSubjectText.Trim();
345 // if (originalSubjectText.GetLength() == 0)
347 // originalSubjectText.Append(IDS_NO_SUBJECT);
350 // originalSubjectText.ToLowerCase(subjectText);
352 // if (pMail->GetHasAttachment() > 0)
354 // subjectWidth = itemWidth - LIST_ITEM_OFFSET - X_ITEM_BITMAP - W_GENERIC_32;
358 // subjectWidth = itemWidth - LIST_ITEM_OFFSET;
361 // if (__pSearchModel->GetSearchFilter() == SEARCH_TITLE || __pSearchModel->GetSearchFilter() == SEARCH_ALL)
365 // TextElement* first = null;
366 // TextElement* second = null;
367 // TextElement* third = null;
368 // EnrichedText* pSubject = new (std::nothrow) EnrichedText();
370 // r = pSubject->Construct(Dimension(itemWidth, H_SUBJECT_MAIN_TEXT));
371 // pSubject->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
372 // pSubject->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
373 // pSubject->SetTextAbbreviationEnabled(true);
375 // pSearchKey.Append(__pSearchModel->GetSearchKey());
376 // pSearchKey.ToLowerCase();
378 // r = subjectText.IndexOf(pSearchKey, 0, index);
380 // if (r == E_SUCCESS)
382 // originalSubjectText.SubString(0, index, firstSubString);
383 // originalSubjectText.SubString(index, pSearchKey.GetLength(), secondSubString);
384 // originalSubjectText.SubString(pSearchKey.GetLength()+index, subjectText.GetLength()-(firstSubString.GetLength()+secondSubString.GetLength()), thirdSubString);
386 // font.Construct(FONT_STYLE_PLAIN, _fontSize);
388 // if (firstSubString.GetLength() > 0)
390 // first = new (std::nothrow) TextElement();
391 // first->Construct(firstSubString);
392 // first->SetFont(font);
394 // if (pMail->isFlagsSeenField())
397 // first->SetTextColor(COLOR_READ_MAILS);
402 // first->SetTextColor(COLOR_UNREAD_MAILS);
405 // pSubject->Add(*first);
408 // if (secondSubString.GetLength() > 0)
410 // second = new (std::nothrow) TextElement();
411 // second->Construct(secondSubString);
412 // second->SetTextColor(Color::GetColor(COLOR_ID_RED));
413 // second->SetFont(font);
414 // pSubject->Add(*second);
417 // if (thirdSubString.GetLength() > 0)
419 // third = new (std::nothrow) TextElement();
420 // third->Construct(thirdSubString);
421 // third->SetFont(font);
423 // if (pMail->isFlagsSeenField())
425 // third->SetTextColor(COLOR_READ_MAILS);
430 // third->SetTextColor(COLOR_UNREAD_MAILS);
433 // pSubject->Add(*third);
436 // pItem->AddElement(Rectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1, subjectWidth, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE)), IDA_BASE_LISTVIEW_ITEM_PROVIDER_SUBJECT_ELEMENT, *pSubject);
442 // if (pMail->isFlagsSeenField())
444 // pItem->AddElement(Rectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1, subjectWidth, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE)), IDA_BASE_LISTVIEW_ITEM_PROVIDER_SUBJECT_ELEMENT, originalSubjectText, _fontSize, COLOR_READ_MAILS, Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), true);
448 // pItem->AddElement(Rectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1, subjectWidth, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE)), IDA_BASE_LISTVIEW_ITEM_PROVIDER_SUBJECT_ELEMENT, originalSubjectText, _fontSize, COLOR_UNREAD_MAILS, Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), true);
454 // if (pMail->isFlagsSeenField())
456 // pItem->AddElement(Rectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1, subjectWidth, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE)), IDA_BASE_LISTVIEW_ITEM_PROVIDER_SUBJECT_ELEMENT, originalSubjectText, _fontSize, COLOR_READ_MAILS, Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), true);
460 // pItem->AddElement(Rectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1, subjectWidth, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE)), IDA_BASE_LISTVIEW_ITEM_PROVIDER_SUBJECT_ELEMENT, originalSubjectText, _fontSize, COLOR_UNREAD_MAILS, Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), true);
469 SearchResultProvider::CreateRecipientText(CustomItem* pItem, const EmailMessageListItem* pMail, const int& itemWidth, const FloatDimension& dim)
471 AppLogDebug("ENTER");
475 EnrichedTextCustomListElement* pCustomListElement = new (std::nothrow) EnrichedTextCustomListElement(__pSearchModel->GetSearchFilter(), RECIPIENT_TEXT, pMail, __pSearchModel->GetSearchKey());
476 pItem->AddElement(Rectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1 + _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE), itemWidth - LIST_ITEM_OFFSET - 10 - dim.width, H_LIST_SUB_ITEM_3_LINE), IDA_BASE_LISTVIEW_ITEM_PROVIDER_RECIPIENT_ELEMENT, *(static_cast<ICustomElement *>(pCustomListElement)));
478 // result r = E_SUCCESS;
480 // String pSearchKey;
481 // String recipientText;
482 // String firstSubString, secondSubString, thirdSubString;
483 // email_mailbox_type_e mailboxType;
485 // if (pMail != null)
487 // mailboxType = _pModel->GetMailboxType(pMail->GetMailboxId());
489 // if (mailboxType == EMAIL_MAILBOX_TYPE_DRAFT || mailboxType == EMAIL_MAILBOX_TYPE_SENTBOX)
491 // String emailAddress;
492 // Utility::StringTokenizer emailIdTokenizer(pMail->GetRecipients(), IDS_DELIM_SEMICOLON);
494 // if (emailIdTokenizer.HasMoreTokens() == true)
496 // emailIdTokenizer.GetNextToken(emailAddress);
498 // if (emailAddress.GetLength() <= 1 && emailIdTokenizer.HasMoreTokens() == true)
500 // emailIdTokenizer.GetNextToken(emailAddress);
504 // Utils::ExtractEmailIdFromFullAddress(emailAddress, recipientText);
508 // Utils::ExtractAliasFromFullAddress(pMail->GetFromEmailAddress(), recipientText);
512 // recipientText.Trim();
514 // if (recipientText.GetLength() == 0)
516 // recipientText.Append(IDS_NO_RECIPIENTS);
519 // recipientText.ToLowerCase();
521 // if (__pSearchModel->GetSearchFilter() == SEARCH_SENDER || __pSearchModel->GetSearchFilter() == SEARCH_ALL)
524 // TextElement* first = null;
525 // TextElement* second = null;
526 // TextElement* third = null;
527 // EnrichedText* pRecipient = new (std::nothrow) EnrichedText();
529 // r = pRecipient->Construct(Dimension(itemWidth, H_LIST_SUB_ITEM_3_LINE));
530 // pRecipient->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
531 // pRecipient->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
532 // pRecipient->SetTextAbbreviationEnabled(true);
534 // pSearchKey.Append(__pSearchModel->GetSearchKey());
535 // pSearchKey.ToLowerCase(pSearchKey);
537 // r = recipientText.IndexOf(pSearchKey, 0, index);
539 // if (r == E_SUCCESS)
541 // recipientText.SubString(0, index, firstSubString);
542 // recipientText.SubString(index, pSearchKey.GetLength(), secondSubString);
543 // recipientText.SubString(pSearchKey.GetLength()+index, recipientText.GetLength()-(firstSubString.GetLength()+secondSubString.GetLength()), thirdSubString);
545 // font.Construct(FONT_STYLE_PLAIN, FONT_SIZE_LIST_NAME_ITEM);
547 // if (firstSubString.GetLength() > 0)
549 // first = new (std::nothrow) TextElement();
550 // first->Construct(firstSubString);
551 // first->SetFont(font);
552 // first->SetTextColor(COLOR_NAME_TEXT);
553 // pRecipient->Add(*first);
556 // if (secondSubString.GetLength() > 0)
558 // second = new (std::nothrow) TextElement();
559 // second->Construct(secondSubString);
560 // second->SetTextColor(Color::GetColor(COLOR_ID_RED));
561 // second->SetFont(font);
562 // pRecipient->Add(*second);
565 // if (thirdSubString.GetLength() > 0)
567 // third = new (std::nothrow) TextElement();
568 // third->Construct(thirdSubString);
569 // third->SetFont(font);
570 // third->SetTextColor(COLOR_NAME_TEXT);
571 // pRecipient->Add(*third);
574 // pItem->AddElement(FloatRectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1 + _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE), itemWidth - LIST_ITEM_OFFSET - 10 - dim.width, H_LIST_SUB_ITEM_3_LINE), IDA_BASE_LISTVIEW_ITEM_PROVIDER_RECIPIENT_ELEMENT, *pRecipient);
575 // delete pRecipient;
576 // pRecipient = null;
580 // if (recipientText.GetLength() != 0)
582 // if (recipientText.StartsWith(L";", 0) == true)
584 // recipientText.Remove(0,1);
588 // pItem->AddElement(FloatRectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1 + _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE), itemWidth - LIST_ITEM_OFFSET - 10 - dim.width, H_LIST_SUB_ITEM_3_LINE), IDA_BASE_LISTVIEW_ITEM_PROVIDER_RECIPIENT_ELEMENT, recipientText, FONT_SIZE_LIST_NAME_ITEM, COLOR_NAME_TEXT, Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), false);
593 // if (recipientText.GetLength() != 0)
595 // if (recipientText.StartsWith(L";", 0) == true)
597 // recipientText.Remove(0,1);
601 // pItem->AddElement(FloatRectangle(X_LIST_ITEM + offset, Y_LIST_ITEM_TYPE1 + _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE), itemWidth - LIST_ITEM_OFFSET - 10 - dim.width, H_LIST_SUB_ITEM_3_LINE), IDA_BASE_LISTVIEW_ITEM_PROVIDER_RECIPIENT_ELEMENT, recipientText, FONT_SIZE_LIST_NAME_ITEM, COLOR_NAME_TEXT, Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), false);
609 SearchResultProvider::CreateMessageText(CustomItem* pItem, const EmailMessageListItem* pMail, const int& itemWidth)
611 AppLogDebug("ENTER");
615 EnrichedTextCustomListElement* pCustomListElement = new (std::nothrow) EnrichedTextCustomListElement(__pSearchModel->GetSearchFilter(), MESSAGE_TEXT, pMail, __pSearchModel->GetSearchKey());
616 pItem->AddElement(Rectangle(X_LIST_ITEM + offset, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE) + H_LIST_SUB_ITEM_3_LINE, itemWidth - LIST_ITEM_OFFSET, H_LIST_SUB_ITEM_3_LINE), IDA_BASE_LISTVIEW_ITEM_PROVIDER_MESSAGE_ELEMENT, *(static_cast<ICustomElement *>(pCustomListElement)));
623 // String messageText;
624 // String originalMessageText;
625 // String firstSubString, secondSubString, thirdSubString;
627 // if (pMail != null)
629 // originalMessageText = pMail->GetPreviewBodyText();
630 // originalMessageText.Trim();
632 // if (originalMessageText.GetLength() == 0)
634 // originalMessageText.Append(IDS_NO_PREVIEW_TEXT);
637 // originalMessageText.ToLowerCase(messageText);
639 // if (__pSearchModel->GetSearchFilter() == SEARCH_ALL)
642 // TextElement* first = null;
643 // TextElement* second = null;
644 // TextElement* third = null;
645 // EnrichedText* pMessage = new (std::nothrow) EnrichedText();
647 // r = pMessage->Construct(Dimension(itemWidth, H_LIST_SUB_ITEM_3_LINE));
648 // pMessage->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
649 // pMessage->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
650 // pMessage->SetTextAbbreviationEnabled(true);
652 // searchKey.Append(__pSearchModel->GetSearchKey());
653 // searchKey.ToLowerCase(searchKey);
655 // r = messageText.IndexOf(searchKey, 0, index);
657 // if (r == E_SUCCESS)
659 // originalMessageText.SubString(0, index, firstSubString);
660 // originalMessageText.SubString(index, searchKey.GetLength(), secondSubString);
661 // originalMessageText.SubString(searchKey.GetLength()+index, messageText.GetLength()-(firstSubString.GetLength()+secondSubString.GetLength()), thirdSubString);
663 // font.Construct(FONT_STYLE_PLAIN, FONT_SIZE_LIST_CONTENTS_ITEM);
665 // if (firstSubString.GetLength() > 0)
667 // first = new (std::nothrow) TextElement();
668 // first->Construct(firstSubString);
669 // first->SetFont(font);
670 // first->SetTextColor(COLOR_CONTENTS_TEXT);
671 // pMessage->Add(*first);
674 // if (secondSubString.GetLength() > 0)
676 // second = new (std::nothrow) TextElement();
677 // second->Construct(secondSubString);
678 // second->SetTextColor(Color::GetColor(COLOR_ID_RED));
679 // second->SetFont(font);
680 // pMessage->Add(*second);
683 // if (thirdSubString.GetLength() > 0)
685 // third = new (std::nothrow) TextElement();
686 // third->Construct(thirdSubString);
687 // third->SetFont(font);
688 // third->SetTextColor(COLOR_CONTENTS_TEXT);
689 // pMessage->Add(*third);
692 // pItem->AddElement(Rectangle(X_LIST_ITEM + offset, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE) + H_LIST_SUB_ITEM_3_LINE, itemWidth - LIST_ITEM_OFFSET, H_LIST_SUB_ITEM_3_LINE), IDA_BASE_LISTVIEW_ITEM_PROVIDER_MESSAGE_ELEMENT, *pMessage);
696 // messageText.Append(pMail->GetPreviewBodyText());
698 // pItem->AddElement(Rectangle(X_LIST_ITEM + offset, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE) + H_LIST_SUB_ITEM_3_LINE, itemWidth - LIST_ITEM_OFFSET, H_LIST_SUB_ITEM_3_LINE), IDA_BASE_LISTVIEW_ITEM_PROVIDER_MESSAGE_ELEMENT, originalMessageText, FONT_SIZE_LIST_CONTENTS_ITEM, COLOR_CONTENTS_TEXT, Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), false);
703 // messageText.Append(pMail->GetPreviewBodyText());
705 // pItem->AddElement(Rectangle(X_LIST_ITEM + offset, _itemHeight-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE) + H_LIST_SUB_ITEM_3_LINE, itemWidth - LIST_ITEM_OFFSET, H_LIST_SUB_ITEM_3_LINE), IDA_BASE_LISTVIEW_ITEM_PROVIDER_MESSAGE_ELEMENT, originalMessageText, FONT_SIZE_LIST_CONTENTS_ITEM, COLOR_CONTENTS_TEXT, Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), false);
713 EnrichedTextCustomListElement::EnrichedTextCustomListElement(SearchFilter searchFilter, TextType textType, const EmailMessageListItem* pMail, String searchText)
715 AppLogDebug("ENTER");
717 __searchFilter = searchFilter;
718 __textType = textType;
720 __searchText = searchText;
726 EnrichedTextCustomListElement::OnDraw(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::Rectangle& rect, Tizen::Ui::Controls::ListItemDrawingStatus itemStatus)
728 AppLogDebug("ENTER");
730 if (__textType == SUBJECT_TEXT)
732 AppLogDebug("subject text");
740 String originalSubjectText;
741 String firstSubString, secondSubString, thirdSubString;
742 EnrichedText* pSubject = new (std::nothrow) EnrichedText();
744 r = pSubject->Construct(Dimension(rect.width, Utils::GetItemHeight()-(H_LIST_SUB_ITEM_3_LINE+H_LIST_PREVIEW_ITEM_1_LINE)));
745 pSubject->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
746 pSubject->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
747 pSubject->SetTextAbbreviationEnabled(true);
749 font.Construct(FONT_STYLE_PLAIN, Utils::GetFontSize());
750 originalSubjectText = __pMail->GetSubject();
752 if (originalSubjectText.IsEmpty() == false)
754 originalSubjectText.Trim();
757 if (originalSubjectText.GetLength() == 0)
759 originalSubjectText.Append(IDS_NO_SUBJECT);
762 originalSubjectText.ToLowerCase(subjectText);
764 // if (__pMail->GetHasAttachment() > 0)
766 // subjectWidth = rect.width - LIST_ITEM_OFFSET - X_ITEM_BITMAP - W_GENERIC_32;
770 // subjectWidth = rect.width - LIST_ITEM_OFFSET;
773 if (__searchFilter == SEARCH_TITLE || __searchFilter == SEARCH_ALL)
777 TextElement* first = null;
778 TextElement* second = null;
779 TextElement* third = null;
782 pSearchKey.Append(__searchText);
783 pSearchKey.ToLowerCase();
785 r = subjectText.IndexOf(pSearchKey, 0, index);
789 originalSubjectText.SubString(0, index, firstSubString);
790 originalSubjectText.SubString(index, pSearchKey.GetLength(), secondSubString);
791 originalSubjectText.SubString(pSearchKey.GetLength()+index, subjectText.GetLength()-(firstSubString.GetLength()+secondSubString.GetLength()), thirdSubString);
793 if (firstSubString.GetLength() > 0)
795 first = new (std::nothrow) TextElement();
796 first->Construct(firstSubString);
797 first->SetFont(font);
799 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
801 if (__pMail->isFlagsSeenField())
804 first->SetTextColor(COLOR_READ_MAILS);
809 first->SetTextColor(COLOR_UNREAD_MAILS);
814 first->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
817 pSubject->Add(*first);
820 if (secondSubString.GetLength() > 0)
822 second = new (std::nothrow) TextElement();
823 second->Construct(secondSubString);
824 second->SetTextColor(Color::GetColor(COLOR_ID_RED));
825 second->SetFont(font);
826 pSubject->Add(*second);
829 if (thirdSubString.GetLength() > 0)
831 third = new (std::nothrow) TextElement();
832 third->Construct(thirdSubString);
833 third->SetFont(font);
835 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
837 if (__pMail->isFlagsSeenField())
839 third->SetTextColor(COLOR_READ_MAILS);
844 third->SetTextColor(COLOR_UNREAD_MAILS);
849 third->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
852 pSubject->Add(*third);
857 first = new (std::nothrow) TextElement();
858 first->Construct(originalSubjectText);
859 first->SetFont(font);
861 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
863 if (__pMail->isFlagsSeenField())
865 first->SetTextColor(COLOR_READ_MAILS);
869 first->SetTextColor(COLOR_UNREAD_MAILS);
874 first->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
877 pSubject->Add(*first);
882 TextElement* first = null;
883 first = new (std::nothrow) TextElement();
884 first->Construct(originalSubjectText);
885 first->SetFont(font);
887 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
889 if (__pMail->isFlagsSeenField())
891 first->SetTextColor(COLOR_READ_MAILS);
895 first->SetTextColor(COLOR_UNREAD_MAILS);
900 first->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
903 pSubject->Add(*first);
906 canvas.DrawText(Point(rect.x, rect.y), *pSubject);
910 else if (__textType == RECIPIENT_TEXT)
913 AppLogDebug("recipient text");
915 result r = E_SUCCESS;
918 String recipientText;
919 String firstSubString, secondSubString, thirdSubString;
920 email_mailbox_type_e mailboxType;
922 EnrichedText* pRecipient = new (std::nothrow) EnrichedText();
923 r = pRecipient->Construct(Dimension(rect.width, H_LIST_SUB_ITEM_3_LINE));
924 pRecipient->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
925 pRecipient->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
926 pRecipient->SetTextAbbreviationEnabled(true);
928 font.Construct(FONT_STYLE_PLAIN, FONT_SIZE_LIST_NAME_ITEM);
930 // if (__pMail != null)
932 BasePresentationModel* pModel = SearchPresentationModel::GetInstance()->GetPresentationModel();
933 mailboxType = pModel->GetMailboxType(__pMail->GetMailboxId());
935 if (mailboxType == EMAIL_MAILBOX_TYPE_DRAFT || mailboxType == EMAIL_MAILBOX_TYPE_SENTBOX)
938 Utility::StringTokenizer emailIdTokenizer(__pMail->GetRecipients(), IDS_DELIM_SEMICOLON);
940 if (emailIdTokenizer.HasMoreTokens() == true)
942 emailIdTokenizer.GetNextToken(emailAddress);
944 if (emailAddress.GetLength() <= 1 && emailIdTokenizer.HasMoreTokens() == true)
946 emailIdTokenizer.GetNextToken(emailAddress);
950 Utils::ExtractEmailIdFromFullAddress(emailAddress, recipientText);
954 Utils::ExtractAliasFromFullAddress(__pMail->GetFromEmailAddress(), recipientText);
958 recipientText.Trim();
960 if (recipientText.GetLength() == 0)
962 recipientText.Append(IDS_NO_RECIPIENTS);
965 recipientText.ToLowerCase();
967 if (__searchFilter == SEARCH_SENDER || __searchFilter == SEARCH_ALL)
970 TextElement* first = null;
971 TextElement* second = null;
972 TextElement* third = null;
974 pSearchKey.Append(__searchText);
975 pSearchKey.ToLowerCase(pSearchKey);
977 r = recipientText.IndexOf(pSearchKey, 0, index);
981 recipientText.SubString(0, index, firstSubString);
982 recipientText.SubString(index, pSearchKey.GetLength(), secondSubString);
983 recipientText.SubString(pSearchKey.GetLength()+index, recipientText.GetLength()-(firstSubString.GetLength()+secondSubString.GetLength()), thirdSubString);
985 if (firstSubString.GetLength() > 0)
987 first = new (std::nothrow) TextElement();
988 first->Construct(firstSubString);
989 first->SetFont(font);
991 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
993 first->SetTextColor(COLOR_NAME_TEXT);
997 first->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
1000 pRecipient->Add(*first);
1003 if (secondSubString.GetLength() > 0)
1005 second = new (std::nothrow) TextElement();
1006 second->Construct(secondSubString);
1007 second->SetTextColor(Color::GetColor(COLOR_ID_RED));
1008 second->SetFont(font);
1009 pRecipient->Add(*second);
1012 if (thirdSubString.GetLength() > 0)
1014 third = new (std::nothrow) TextElement();
1015 third->Construct(thirdSubString);
1016 third->SetFont(font);
1018 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
1020 third->SetTextColor(COLOR_NAME_TEXT);
1024 third->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
1027 pRecipient->Add(*third);
1032 first = new (std::nothrow) TextElement();
1034 if (recipientText.GetLength() != 0)
1036 if (recipientText.StartsWith(L";", 0) == true)
1038 recipientText.Remove(0,1);
1042 first->Construct(recipientText);
1043 first->SetFont(font);
1045 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
1047 first->SetTextColor(COLOR_NAME_TEXT);
1051 first->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
1054 pRecipient->Add(*first);
1059 TextElement* first = null;
1060 first = new (std::nothrow) TextElement();
1062 if (recipientText.GetLength() != 0)
1064 if (recipientText.StartsWith(L";", 0) == true)
1066 recipientText.Remove(0,1);
1070 first->Construct(recipientText);
1071 first->SetFont(font);
1073 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
1075 first->SetTextColor(COLOR_NAME_TEXT);
1079 first->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
1082 pRecipient->Add(*first);
1086 canvas.DrawText(Point(rect.x, rect.y), *pRecipient);
1090 else if (__textType == MESSAGE_TEXT)
1095 result r = E_SUCCESS;
1098 String originalMessageText;
1099 String firstSubString, secondSubString, thirdSubString;
1101 EnrichedText* pMessage = new (std::nothrow) EnrichedText();
1103 r = pMessage->Construct(Dimension(rect.width, H_LIST_SUB_ITEM_3_LINE));
1104 pMessage->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
1105 pMessage->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
1106 pMessage->SetTextAbbreviationEnabled(true);
1108 font.Construct(FONT_STYLE_PLAIN, FONT_SIZE_LIST_CONTENTS_ITEM);
1110 if (__pMail != null)
1112 originalMessageText = __pMail->GetPreviewBodyText();
1113 originalMessageText.Trim();
1115 if (originalMessageText.GetLength() == 0)
1117 originalMessageText.Append(IDS_NO_PREVIEW_TEXT);
1120 originalMessageText.ToLowerCase(messageText);
1122 if (__searchFilter == SEARCH_ALL)
1125 TextElement* first = null;
1126 TextElement* second = null;
1127 TextElement* third = null;
1129 searchKey.Append(__searchText);
1130 searchKey.ToLowerCase(searchKey);
1132 r = messageText.IndexOf(searchKey, 0, index);
1136 originalMessageText.SubString(0, index, firstSubString);
1137 originalMessageText.SubString(index, searchKey.GetLength(), secondSubString);
1138 originalMessageText.SubString(searchKey.GetLength()+index, messageText.GetLength()-(firstSubString.GetLength()+secondSubString.GetLength()), thirdSubString);
1140 if (firstSubString.GetLength() > 0)
1142 first = new (std::nothrow) TextElement();
1143 first->Construct(firstSubString);
1144 first->SetFont(font);
1146 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
1148 first->SetTextColor(COLOR_CONTENTS_TEXT);
1152 first->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
1155 pMessage->Add(*first);
1158 if (secondSubString.GetLength() > 0)
1160 second = new (std::nothrow) TextElement();
1161 second->Construct(secondSubString);
1162 second->SetTextColor(Color::GetColor(COLOR_ID_RED));
1163 second->SetFont(font);
1164 pMessage->Add(*second);
1167 if (thirdSubString.GetLength() > 0)
1169 third = new (std::nothrow) TextElement();
1170 third->Construct(thirdSubString);
1171 third->SetFont(font);
1173 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
1175 third->SetTextColor(COLOR_CONTENTS_TEXT);
1179 third->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
1182 pMessage->Add(*third);
1187 first = new (std::nothrow) TextElement();
1188 first->Construct(originalMessageText);
1189 first->SetFont(font);
1191 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
1193 first->SetTextColor(COLOR_CONTENTS_TEXT);
1197 first->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
1200 pMessage->Add(*first);
1205 TextElement* first = null;
1206 first = new (std::nothrow) TextElement();
1207 first->Construct(originalMessageText);
1208 first->SetFont(font);
1210 if (itemStatus == LIST_ITEM_DRAWING_STATUS_NORMAL)
1212 first->SetTextColor(COLOR_CONTENTS_TEXT);
1216 first->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
1219 pMessage->Add(*first);
1223 canvas.DrawText(Point(rect.x, rect.y), *pMessage);