Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntHistoryListForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 //!Internet HistoryListForm class
18 /*@file: HistoryListForm.cpp
19  *@brief:       This class defines HistoryListForm used define history
20  *
21  */
22
23 #include <FApp.h>
24 #include <FUi.h>
25 #include "IntBookmarkData.h"
26 #include "IntBookmarkPresentationModel.h"
27 #include "IntCommonLib.h"
28 #include "IntFaviconManager.h"
29 #include "IntHistoryListForm.h"
30 #include "IntHistoryPresentationModel.h"
31 #include "IntMultipleWindowPresentationModel.h"
32 #include "IntSceneRegister.h"
33 #include "IntTypes.h"
34
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Locales;
41 using namespace Tizen::Media;
42 using namespace Tizen::Ui;
43 using namespace Tizen::Ui::Controls;
44 using namespace Tizen::Ui::Scenes;
45 using namespace Tizen::System;
46
47 static const wchar_t* IDB_TAB_ICON_BOOKMARKS = L"I01_tab_icon_bookmarks.png";
48 static const wchar_t* IDB_TAB_ICON_HISTORY = L"I01_tab_icon_history.png";
49 static const wchar_t* IDB_ICON_BOOKMARK_ON_TEMP = L"I01_icon_bookmark_on_temp.png";
50 static const wchar_t* IDB_ICON_BOOKMARK_OFF_TEMP = L"I01_icon_bookmark_off_temp.png";
51
52
53 const int HistoryListForm::IDA_TABBAR_ITEM_1 = 101;
54 const int HistoryListForm::IDA_TABBAR_ITEM_2 = 102;
55 const int HistoryListForm::IDA_EDIT_HISTORY_LIST_FORM = 103;
56 const int HistoryListForm::IDA_FORMAT_ICON = 104;
57 const int HistoryListForm::IDA_FORMAT_TITLE = 105;
58 const int HistoryListForm::IDA_FORMAT_URL = 106;
59 const int HistoryListForm::IDA_FORMAT_BOOKMARK = 107;
60
61
62 HistoryListForm::HistoryListForm(void)
63 {
64         __pBookmarkList = null;
65         __pGroupedListView =null;
66         __pSearchListView = null;
67         __pSearchBar = null;
68         __pGroupData = null;
69         __pSearchedData = null ;
70         __searchHistory = false;
71         __isNoHistoryPresent = true;
72         __searchText = L"";
73         __previousSceneId = L"";
74 }
75
76 HistoryListForm::~HistoryListForm(void)
77 {
78         if (__pGroupData != null)
79         {
80                 __pGroupData->RemoveAll(false);
81                 delete __pGroupData;
82         }
83         if(__pBookmarkList != null)
84         {
85                 __pBookmarkList->RemoveAll(false);
86                 delete __pBookmarkList;
87         }
88         if (__pSearchListView)
89         {
90                 delete __pSearchListView;
91                 __pSearchListView = null;
92         }
93 }
94
95 bool
96 HistoryListForm::Initialize(void)
97 {
98         Construct(L"IDL_HISTORY_LIST");
99
100         return true;
101 }
102
103 result
104 HistoryListForm::OnInitializing(void)
105 {
106         AppLog("HistoryListForm::OnInitializing");
107         result r = E_SUCCESS;
108         SceneManager* pSceneManager = null;
109         HeaderItem bookmark;
110         HeaderItem history;
111         Header *pHeader = GetHeader();
112         Bitmap *pIconBitmap = null;
113         AppResource* pAppResource = UiApp::GetInstance()->GetAppResource();
114         const Color brown = Color(32, 32, 32, 0xFF);
115
116         // Setup back event listener
117         SetFormBackEventListener(this);
118
119         GetHeader()->AddActionEventListener(*this);
120         GetFooter()->AddActionEventListener(*this);
121
122         AddOrientationEventListener(*this);
123         SettingInfo::AddSettingEventListener(*this);
124
125         pSceneManager = SceneManager::GetInstance();
126         if (pSceneManager != null)
127         {
128                 pSceneManager->AddSceneEventListener(IDSCN_HISTORY_LIST, *this);
129         }
130
131         __fontSize = CommonUtil::GetFontSize();
132         if (pAppResource == null)
133         {
134                 return E_FAILURE;
135         }
136
137         __pGroupedListView = static_cast< GroupedListView* >(GetControl(L"IDC_GROUPEDLISTVIEW1"));
138         if (__pGroupedListView == null)
139         {
140                 return E_FAILURE;
141         }
142
143         r = __pGroupedListView->SetItemProvider(*this);
144         if (IsFailed(r))
145         {
146                 return r;
147         }
148
149
150         __pSearchBar = static_cast< SearchBar* >(GetControl(L"IDC_SEARCHBAR1"));
151         if (__pSearchBar == null)
152         {
153                 return E_FAILURE;
154         }
155         __pSearchListView = new(std::nothrow) GroupedListView();
156         if (__pSearchListView == null)
157         {
158                 return E_FAILURE;
159         }
160
161         __pGroupedListView->AddGroupedListViewItemEventListener(*this);
162         r = __pGroupedListView->SetBounds(Rectangle(0,__pGroupedListView->GetY(),GetClientAreaBounds().width,GetClientAreaBounds().height  - __pSearchBar->GetHeight() - __pSearchBar->GetY()));
163         if (IsFailed(r))
164         {
165                 return r;
166         }
167         r = __pSearchListView->Construct(Rectangle(0,0, GetClientAreaBounds().width, GetClientAreaBounds().height -__pSearchBar->GetHeight() - __pSearchBar->GetY()), GROUPED_LIST_VIEW_STYLE_INDEXED, true, false);
168         if (IsFailed(r))
169         {
170                 return r;
171         }
172         r = __pSearchListView->SetItemProvider(*this);
173         if (IsFailed(r))
174         {
175                 return r;
176         }
177         r = __pSearchListView->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_BR_BODY_NO_RESULTS_FOUND"));
178
179         if (IsFailed(r))
180         {
181                 return r;
182         }
183
184         __pSearchListView->SetBackgroundColor(GetBackgroundColor());
185         __pSearchListView->SetTextColorOfEmptyList(Color::GetColor(COLOR_ID_BLACK));
186         __pSearchListView->AddGroupedListViewItemEventListener(*this);
187         r = __pSearchListView->SetShowState(false);
188         if (IsFailed(r))
189         {
190                 return r;
191         }
192
193
194         __pSearchBar->AddSearchBarEventListener(*this);
195         __pSearchBar->AddKeypadEventListener(*this);
196         r = __pSearchBar->SetContent(__pSearchListView);
197
198         if (pHeader != null)
199         {
200                 pHeader->SetStyle(HEADER_STYLE_TAB);
201                 bookmark.Construct(IDA_TABBAR_ITEM_1);
202                 String strbookmark;
203                 pAppResource->GetString(L"IDS_BR_TAB_BOOKMARKS", strbookmark);
204                 bookmark.SetText(strbookmark);
205                 pIconBitmap = pAppResource->GetBitmapN(IDB_TAB_ICON_BOOKMARKS);
206                 bookmark.SetIcon(HEADER_ITEM_STATUS_NORMAL, pIconBitmap);
207                 bookmark.SetIcon(HEADER_ITEM_STATUS_PRESSED, pIconBitmap);
208                 pHeader->AddItem(bookmark);
209
210                 if (pIconBitmap)
211                 {
212                         delete pIconBitmap;
213                 }
214
215
216                 history.Construct(IDA_TABBAR_ITEM_2);
217                 String strhistory;
218                 pAppResource->GetString(L"IDS_BR_TAB_HISTORY", strhistory);
219                 history.SetText(strhistory);
220                 pIconBitmap = pAppResource->GetBitmapN(IDB_TAB_ICON_HISTORY);
221                 history.SetIcon(HEADER_ITEM_STATUS_NORMAL, pIconBitmap);
222                 history.SetIcon(HEADER_ITEM_STATUS_PRESSED, pIconBitmap);
223                 pHeader->AddItem(history);
224                 pHeader->SetItemSelected(1);
225                 pHeader->SetTabEditModeEnabled(false);
226
227                 if (pIconBitmap != NULL)
228                 {
229                         delete pIconBitmap;
230                 }
231         }
232
233         __pBookmarkList = new(std::nothrow) Collection::ArrayList();
234         __pBookmarkList->Construct();
235         BookmarkPresentationModel::GetInstance()->GetBookmarkForHistory(0,*__pBookmarkList);
236         return r;
237 }
238
239 result
240 HistoryListForm::OnTerminating(void)
241 {
242         result r = E_SUCCESS;
243
244         SettingInfo::RemoveSettingEventListener(*this);
245         return r;
246 }
247
248 void
249 HistoryListForm::OnActionPerformed(const Control& source, int actionId)
250 {
251         AppLog("HistoryListForm::OnActionPerformed");
252         result r = E_FAILURE;
253         SceneManager* pSceneManager = SceneManager::GetInstance();
254         if (pSceneManager == null)
255         {
256                 return;
257         }
258         switch (actionId)
259         {
260         case IDA_EDIT_HISTORY_LIST_FORM:
261         {
262                 AppLog("ID_EDIT_HISTORY_LIST_FORM entered");
263                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_EDIT_HISTORY_LIST, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
264                 if (IsFailed(r))
265                 {
266                         return;
267                 }
268         }
269         break;
270         case IDA_TABBAR_ITEM_1:
271         {
272                 result r = GetHeader()->SetItemSelected(1);
273                 AppLog("SetItemSelected result %s",GetErrorMessage(r));
274                 GetHeader()->Invalidate(true);
275
276                 if (pSceneManager != null)
277                 {
278                         if(__previousSceneId.CompareTo(IDSCN_BOOKMARK_VIEW) != 0)
279                         {
280                                 if(pSceneManager->GoForward(ForwardSceneTransition(IDSCN_BOOKMARK_VIEW, SCENE_TRANSITION_ANIMATION_TYPE_LEFT)) != E_SUCCESS)
281                                 {
282                                         AppLogDebug("BookmarkListForm::OnActionPerformed GoForward failed");
283                                         return;
284                                 }
285                         }
286                         else
287                         {
288
289                                 if(pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT))!= E_SUCCESS)
290                                 {
291                                         AppLogDebug("BookmarkListForm::OnActionPerformed GoBackward failed");
292                                         return;
293                                 }
294
295                         }
296                 }
297 //              r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
298                 if (IsFailed(r))
299                 {
300                         return;
301                 }
302         }
303         break;
304         default:
305                 break;
306         }
307 }
308
309 void
310 HistoryListForm::OnFormBackRequested(Form& source)
311 {
312         SceneManager* pSceneManager = SceneManager::GetInstance();
313         if (pSceneManager == null)
314         {
315                 return;
316         }
317         result r = E_FAILURE;
318         if(__previousSceneId.CompareTo(IDSCN_BOOKMARK_VIEW) != 0)
319         {
320                         r = pSceneManager->GoBackward(BackwardSceneTransition());
321         }
322         else
323         {
324                 r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
325         }
326         if(IsFailed(r))
327         {
328                 AppLogDebug("HistoryListForm::OnFormBackRequested GoForward failed %s",GetErrorMessage(r));
329         }
330 }
331
332 GroupItem*
333 HistoryListForm::CreateGroupItem(int groupIndex, int itemWidth)
334 {
335         result r = E_FAILURE;
336         int strMonth = 0;
337         String text(L"");
338         DateTime endTime;
339         DateTime startTime;
340         int count = 0;
341         GroupItem* pItem = null;
342         GroupItemClass* pGroupItemClass = null;
343
344         String weeksAgo2 = L"";
345         weeksAgo2.Format(25,CommonUtil::GetString(L"IDS_EMAIL_BODY_PD_WEEKS_AGO").GetPointer(),2);
346
347         String weeksAgo3 = L"";
348         weeksAgo3.Format(25,CommonUtil::GetString(L"IDS_EMAIL_BODY_PD_WEEKS_AGO").GetPointer(),3);
349
350         String weeksAgo4 = L"";
351         weeksAgo4.Format(25,CommonUtil::GetString(L"IDS_EMAIL_BODY_PD_WEEKS_AGO").GetPointer(),4);
352
353         pItem = new(std::nothrow) GroupItem();
354         if (pItem == null)
355         {
356                 return null;
357         }
358         pGroupItemClass = dynamic_cast< GroupItemClass* >(__pGroupData->GetAt(groupIndex));
359
360         if (pGroupItemClass == null || pGroupItemClass->GetHistoryData() == null || pGroupItemClass->GetHistoryData()->GetCount() == 0)
361         {
362                 AppLog("CreateGroupItem :: if history is null");
363                 r = pItem->Construct(Dimension(itemWidth, 0));
364                 return pItem;
365         }
366         else
367         {
368                 r = pItem->Construct(Dimension(itemWidth, 48));
369         }
370         text = pGroupItemClass->GetTitleText();
371
372         if (__searchHistory == false)
373         {
374                 String month = L"";
375                 text.Append(L" (");
376                 if (pGroupItemClass->GetTitleText() == CommonUtil::GetString(L"IDS_COM_BODY_TODAY") || pGroupItemClass->GetTitleText() == CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY"))
377                 {
378                         int dayOfWeek = 0;
379                         Calendar* pGregorianCalendar = Calendar::CreateInstanceN(CALENDAR_GREGORIAN);
380                         if ( pGregorianCalendar != NULL)
381                         {
382                                 r = pGregorianCalendar->SetTimeField(TIME_FIELD_YEAR, pGroupItemClass->GetStartTime().GetYear());
383                                 if (IsFailed(r))
384                                 {
385                                         if( pItem != null)
386                                         {
387                                                 delete pItem;
388                                         }
389                                         delete pGregorianCalendar;
390                                         return null;
391                                 }
392                                 r = pGregorianCalendar->SetTimeField(TIME_FIELD_MONTH, pGroupItemClass->GetStartTime().GetMonth());
393                                 if (IsFailed(r))
394                                 {
395                                         if( pItem != null)
396                                         {
397                                                 delete pItem;
398                                         }
399                                         delete pGregorianCalendar;
400                                         return null;
401                                 }
402                                 r = pGregorianCalendar->SetTimeField(TIME_FIELD_DAY_OF_MONTH, pGroupItemClass->GetStartTime().GetDay());
403                                 if (IsFailed(r))
404                                 {
405                                         if( pItem != null)
406                                         {
407                                                 delete pItem;
408                                         }
409                                         delete pGregorianCalendar;
410                                         return null;
411                                 }
412                                 dayOfWeek = pGregorianCalendar->GetTimeField(TIME_FIELD_DAY_OF_WEEK);
413                                 if (pGregorianCalendar != NULL)
414                                 {
415                                         delete pGregorianCalendar;
416                                 }
417
418                         }
419                         switch(dayOfWeek)
420                         {
421                         case SUNDAY:
422                                 text.Append(CommonUtil::GetString(L"IDS_COM_BODY_SUN"));
423                                 break;
424                         case MONDAY:
425                                 text.Append(CommonUtil::GetString(L"IDS_COM_BODY_MON"));
426                                 break;
427                         case TUESDAY:
428                                 text.Append(CommonUtil::GetString(L"IDS_COM_BODY_TUE"));
429                                 break;
430                         case WEDNESDAY:
431                                 text.Append(CommonUtil::GetString(L"IDS_COM_BODY_WED"));
432                                 break;
433                         case THURSDAY:
434                                 text.Append(CommonUtil::GetString(L"IDS_COM_BODY_THU"));
435                                 break;
436                         case FRIDAY:
437                                 text.Append(CommonUtil::GetString(L"IDS_COM_BODY_FRI"));
438                                 break;
439                         case SATURDAY:
440                                 text.Append(CommonUtil::GetString(L"IDS_COM_BODY_SAT"));
441                                 break;
442                         default:
443                                 break;
444                         }
445                         text.Append(L", ");
446                 }
447
448                 if (pGroupItemClass->GetTitleText() != CommonUtil::GetString(L"IDS_BR_BODY_OLDER"))
449                 {
450                         text.Append(pGroupItemClass->GetStartTime().GetDay());
451                         text.Append(L". ");
452                         strMonth = pGroupItemClass->GetStartTime().GetMonth();
453                         month = GetMonth(strMonth);
454                         text.Append(month);
455                 }
456                 else
457                 {
458                         text.Append(L"~ ");
459                 }
460
461
462
463                 if (pGroupItemClass->GetTitleText() == CommonUtil::GetString(L"IDS_BR_BODY_LAST_WEEK") || pGroupItemClass->GetTitleText() == weeksAgo2
464                                 || pGroupItemClass->GetTitleText() == weeksAgo3 || pGroupItemClass->GetTitleText() == weeksAgo4 || pGroupItemClass->GetTitleText() == CommonUtil::GetString(L"IDS_BR_EARLIER_THIS_MONTH") || pGroupItemClass->GetTitleText() == CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_MONTH") || pGroupItemClass->GetTitleText() == CommonUtil::GetString(L"IDS_BR_BODY_OLDER"))
465                 {
466                         text.Append(L" - ");
467                         text.Append(pGroupItemClass->GetEndTime().GetDay());
468                         text.Append(L". ");
469                         strMonth = pGroupItemClass->GetEndTime().GetMonth();
470                         month = GetMonth(strMonth);
471                         text.Append(month);
472                 }
473                 text.Append(L")");
474         }
475
476         r = pItem->SetElement(text, null);
477         if (IsFailed(r))
478         {
479                 delete pItem;
480                 AppLogDebug("Failed with %s", GetErrorMessage(r));
481                 return null;
482         }
483         r = pItem->SetTextSize(32);
484         if (IsFailed(r))
485         {
486                 delete pItem;
487                 return null;
488         }
489
490         return pItem;
491 }
492
493 ListItemBase*
494 HistoryListForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
495 {
496         AppLog("HistoryListForm::CreateItem");
497         result r = E_FAILURE;
498         History* pHistory = null;
499         Bitmap* pBitmap = null;
500         Bitmap* pBookmarkBitmap = null;
501         GroupItemClass* pGroupItemClass = null;
502         CustomItem* pItem = new(std::nothrow) CustomItem();
503         int bookmarkBtnWidth = 0;
504         String bitmapId;
505
506         Image* pImage = null;
507         pImage = new Image();
508         pImage->Construct();
509
510         if(__pGroupData == null)
511         {
512                 delete pItem;
513                 return null;
514         }
515
516         if (pItem == null)
517         {
518                 return null;
519         }
520         pGroupItemClass = dynamic_cast< GroupItemClass* >(__pGroupData->GetAt(groupIndex));
521         if (pGroupItemClass == null)
522         {
523                 delete pItem;
524                 return null;
525         }
526         if (pGroupItemClass->GetHistoryData() == null)
527         {
528                 delete pItem;
529                 return null;
530         }
531         pHistory = dynamic_cast< History* >(pGroupItemClass->GetHistoryData()->GetAt(itemIndex));
532         if (pHistory == null)
533         {
534                 delete pItem;
535                 return null;
536         }
537         r = pItem->Construct(Dimension(itemWidth, 128 - 44 + __fontSize), LIST_ANNEX_STYLE_NORMAL);
538         if (IsFailed(r))
539         {
540                 delete pItem;
541                 return null;
542         }
543
544         ByteBuffer* pFavIconBuffer = null;
545         pFavIconBuffer = pHistory->GetFavIconBuffer();
546
547         AppLog("BookmarkListForm::CreateItem check 0");
548
549         if (pFavIconBuffer != null)
550         {
551                 AppLog("BookmarkListForm::CreateItem pFavIconBuffer is not null");
552         }
553         else
554         {
555                 AppLog("BookmarkListForm::CreateItem pFavIconBuffer is null");
556         }
557
558         pBitmap = pImage->DecodeN(*pFavIconBuffer, IMG_FORMAT_PNG, BITMAP_PIXEL_FORMAT_ARGB8888);
559
560         AppLog("BookmarkListForm::CreateItem check 1");
561
562         //bitmapId = pHistory->GetFaviconId() ;
563         //pBitmap = pHistory->GetFavIconBitmap();
564
565         if (pBitmap == null)
566         {
567                 pBitmap = FaviconManager::GetInstance()->GetDefaultFaviconN();
568         }
569         if (pBitmap != null)
570         {
571                 r = pItem->AddElement(Rectangle(16, 28 + (__fontSize - 44)/2,72, 72), IDA_FORMAT_ICON, *pBitmap, null);
572                 delete pBitmap;
573                 if (IsFailed(r))
574                 {
575                         delete pItem;
576                         AppLogException("CreateItem failed with %s", GetErrorMessage(r));
577                         return null;
578                 }
579         }
580         bool urlFoundInBookmark = false;
581
582         if(__pBookmarkList != null)
583         {
584                 for (int i = 0; i < __pBookmarkList->GetCount();i++)
585                 {
586                         BookmarkData* pBookMark = dynamic_cast< BookmarkData* >(__pBookmarkList->GetAt(i));
587                         if(pBookMark != null && pHistory->GetHistoryUrl().CompareTo(pBookMark->GetUrl()) == 0)
588                         {
589                                 urlFoundInBookmark = true;
590                                 break;
591                         }
592                 }
593         }
594         if (urlFoundInBookmark == true)
595         {
596                 pBookmarkBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
597         }
598         else
599         {
600                 pBookmarkBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
601         }
602         bookmarkBtnWidth = 64;
603
604
605         r = pItem->AddElement(Rectangle(104, 10, GetClientAreaBounds().width - 108 - 32 - bookmarkBtnWidth - 32, 60 - 44 + __fontSize), IDA_FORMAT_TITLE, pHistory->GetHistoryTitle(), __fontSize,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT,true);
606         TryCatch(!IsFailed(r), "CreateItem failed with %s",GetErrorMessage(r));
607
608 //      if(__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
609 //              r = pItem->AddElement(Rectangle(104, 70, GetClientAreaBounds().width - 108 - 32 - bookmarkBtnWidth - 32, 48), IDA_FORMAT_URL, pHistory->GetHistoryUrl(),32,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT,true);
610 //      else
611                 r = pItem->AddElement(Rectangle(104, 70 - 44 +__fontSize, GetClientAreaBounds().width - 108 - 32 - bookmarkBtnWidth - 32, 48), IDA_FORMAT_URL, pHistory->GetHistoryUrl(),32,CUSTOM_COLOR_GREY,CUSTOM_COLOR_GREY,CUSTOM_COLOR_GREY,true);
612         TryCatch(!IsFailed(r), "CreateItem failed with %s",GetErrorMessage(r));
613         if ( pBookmarkBitmap != null)
614         {
615                 r = pItem->AddElement(Rectangle(GetClientAreaBounds().width - bookmarkBtnWidth - 16, (128 - pBookmarkBitmap->GetHeight())/2 +(__fontSize - 44)/2, bookmarkBtnWidth, bookmarkBtnWidth), IDA_FORMAT_BOOKMARK, *pBookmarkBitmap);
616                 TryCatch(!IsFailed(r), "CreateItem failed with %s",GetErrorMessage(r));
617                 delete pBookmarkBitmap;
618         }
619         delete pImage;
620         return pItem;
621
622         CATCH:
623         delete pItem;
624         return null;
625 }
626
627 bool
628 HistoryListForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
629 {
630
631         //      delete pItem;
632         //      pItem = null;
633         return false;
634 }
635
636 bool
637 HistoryListForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
638 {
639         AppLog("HistoryListForm::DeleteItem");
640         result r = E_FAILURE;
641         GroupItemClass* pGroupItemClass = dynamic_cast< GroupItemClass* >(__pGroupData->GetAt(groupIndex));
642         if (pGroupItemClass == null)
643         {
644                 return false;
645         }
646
647         //      if (pGroupItemClass->__pData != null)
648         //      {
649         //              r = pGroupItemClass->__pData->RemoveAt(itemIndex);
650         //              if (IsFailed(r))
651         //              {
652         //                      return false;
653         //              }
654         //      }
655
656         delete pItem;
657         pItem = null;
658         return true;
659 }
660
661 int
662 HistoryListForm::GetGroupCount(void)
663 {
664         __isNoHistoryPresent = true;
665         CreateGroupItems();
666         if (__pGroupData != null)
667         {
668                 if (__searchHistory == false)
669                 {
670                         int count = 0;
671                         DateTime startTime;
672                         DateTime endTime;
673                         HistoryPresentationModel::GetCurrentDateTime(endTime);;
674
675                         startTime.SetValue(0,0,0);
676
677                         HistoryPresentationModel::GetInstance()->GetHistoryCountWithTimeRange(startTime,endTime,count);
678                         if (count == 0)
679                         {
680                                 return 0;
681                         }
682                         return __pGroupData->GetCount();
683                 }
684                 else
685                 {
686                         int count = 0;
687                 //      String searchText = __pSearchBar->GetText();
688                         result r = HistoryPresentationModel::GetInstance()->GetSearchHistoryCount(count, __searchText);
689                         if(count)
690                                 return 1;
691                         else
692                                 return 0;
693                 }
694         }
695         else
696         {
697                 return 0;
698         }
699 }
700
701 int
702 HistoryListForm::GetItemCount(int groupIndex)
703 {
704         result r = E_FAILURE;
705         int count = 0;
706         DateTime endTime;
707         DateTime startTime;
708         String text;
709
710         GroupItemClass* pGroupItemClass = dynamic_cast< GroupItemClass* >(__pGroupData->GetAt(groupIndex));
711         if (pGroupItemClass == null)
712         {
713                 return null;
714         }
715         if (__searchHistory == false)
716         {
717                 startTime = pGroupItemClass->GetStartTime();
718                 endTime = pGroupItemClass->GetEndTime();
719                 r = HistoryPresentationModel::GetInstance()->GetHistoryCountWithTimeRange(startTime,endTime,count);
720         }
721         else
722         {
723                 //text =  __pSearchBar->GetText();
724                 r = HistoryPresentationModel::GetInstance()->GetSearchHistoryCount(count,__searchText);
725                 if(count == 0)
726                 {
727                         return count;
728                 }
729         }
730         if (IsFailed(r))
731         {
732                 return 0;
733         }
734
735         ArrayList* pData = new(std::nothrow) ArrayList();
736         if (pData == null)
737         {
738                 return 0;
739         }
740         r = pData->Construct();
741
742         if (IsFailed(r))
743         {
744                 delete pData;
745                 return 0;
746         }
747
748         if (__searchHistory == false)
749         {
750                 startTime = pGroupItemClass->GetStartTime();
751                 endTime = pGroupItemClass->GetEndTime();
752                 AppLog("Starttime %ls endtime %ls",startTime.ToString().GetPointer(),endTime.ToString().GetPointer());
753                 r = HistoryPresentationModel::GetInstance()->GetHistoryWithTimeRange(startTime,endTime, 0, count, *pData);
754         }
755         else
756         {
757                 //text = __pSearchBar->GetText() ;
758                 r = HistoryPresentationModel::GetInstance()->GetSearchHistory(0, count, *pData,__searchText );
759         }
760         if (IsFailed(r))
761         {
762                 delete pData;
763                 return 0;
764         }
765         pGroupItemClass->SetHistoryData(pData);
766
767
768         if (__isNoHistoryPresent == true && count == 0)
769         {
770                 __isNoHistoryPresent = true;
771                 GetFooter()->SetItemEnabled(0, false);
772         }
773         else
774         {
775                 __isNoHistoryPresent = false;
776                 GetFooter()->SetItemEnabled(0, true);
777         }
778         //       pGroupItemClass = dynamic_cast< GroupItemClass* >(__pGroupData->GetAt(groupIndex));
779         if (pGroupItemClass == null || pGroupItemClass->GetHistoryData() == null)
780         {
781                 delete pData;
782                 return 0;
783         }
784         else
785         {
786                 AppLogDebug("HistoryListForm::GetItemCount returning %d for %d title %ls",pGroupItemClass->GetHistoryData()->GetCount(),groupIndex,pGroupItemClass->GetTitleText().GetPointer());
787                 return pGroupItemClass->GetHistoryData()->GetCount();
788         }
789 }
790
791 void
792 HistoryListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
793 {
794
795         GetHeader()->SetItemSelected(1);
796 //      __previousSceneId = previousSceneId;
797         ArrayListT<String> * pList = dynamic_cast<ArrayListT<String>* >(SceneManager::GetInstance()->GetSceneHistoryN());
798         if(pList != null)
799         {
800                 pList->GetAt(pList->GetCount()-1,__previousSceneId);
801         }
802
803         if(__pBookmarkList != null)
804         {
805                 __pBookmarkList->RemoveAll(false);
806         }
807
808         BookmarkPresentationModel::GetInstance()->GetBookmarkForHistory(0,*__pBookmarkList);
809
810         AppLog("HistoryListForm::OnSceneActivatedN called");
811         //GetHeader()->Invalidate(true);
812         if (__pGroupData == null)
813         {
814                 __pGroupData = new(std::nothrow) ArrayList();
815                 __pGroupData->Construct();
816         }
817         if (__pGroupedListView != null)
818         {
819                 __pGroupedListView->UpdateList();
820         }
821         if (__isNoHistoryPresent == true)
822         {
823                 GetFooter()->SetItemEnabled(0, false);
824         }
825         else
826         {
827                 GetFooter()->SetItemEnabled(0, true);
828         }
829
830         int count = 0;
831         HistoryPresentationModel::GetInstance()->GetHistoryCount(count);
832         if (count == 0)
833         {
834                 __pSearchBar->SetShowState(false);
835                 __pSearchBar->Invalidate(true);
836         }
837         else
838         {
839                 __pSearchBar->SetShowState(true);
840                 __pSearchBar->Invalidate(true);
841         }
842
843         //      if (__isNoHistoryPresent == true)
844         //      {
845         //              //      __pGroupedListView->SetBitmapOfEmptyList(AppResource::GetInstance()->GetBitmapN(L"I01_Nocontents_Bookmarks.png"));
846         //              __pGroupedListView->UpdateList();
847         //      }
848
849         result r = GetHeader()->SetItemSelected(2);
850         if (IsFailed(r))
851         {
852                 AppLog("HistoryListForm::OnSceneActivatedN header failed %ls", GetErrorMessage(r));
853                 return;
854         }
855
856
857
858         Invalidate(true);
859
860 }
861
862 void
863 HistoryListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
864 {
865         AppLog("HistoryListForm::OnSceneDeactivated");
866         __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
867 }
868
869 void
870 HistoryListForm::OnGroupedListViewContextItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListContextItemStatus status)
871 {
872
873 }
874
875 void
876 HistoryListForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
877 {
878         GroupItemClass* pGroupItemClass = null;
879         History* pHistory = null;
880         AppLog("int groupIndex %d, int itemIndex %d, int elementId %d, ListItemStatus status %d",groupIndex,itemIndex,elementId,status);
881         if (elementId == IDA_FORMAT_BOOKMARK)
882         {
883                 String toggledUrl = L"";
884                 AppLog("BookMarkStatusChanged ID_FORMAT_BOOKMARK");
885                 pGroupItemClass = dynamic_cast< GroupItemClass* >(__pGroupData->GetAt(groupIndex));
886                 if (pGroupItemClass == null)
887                 {
888                         return;
889                 }
890                 pHistory = dynamic_cast< History* >(pGroupItemClass->GetHistoryData()->GetAt(itemIndex));
891                 if (pHistory == null)
892                 {
893                         return;
894                 }
895                 toggledUrl = pHistory->GetHistoryUrl();
896
897                 AppLog("History's Bookmark ID %ls ToggledUrl %ls",pHistory->GetBookmarkId().GetPointer(),toggledUrl.GetPointer());
898
899                 bool bookmarkFound = false;
900                 BookmarkData* pBookMark = null;
901                 if(__pBookmarkList != null)
902                 {
903                         for (int i = 0; i < __pBookmarkList->GetCount(); i++)
904                         {
905                                 pBookMark = dynamic_cast< BookmarkData* >(__pBookmarkList->GetAt(i));
906                                 if (pBookMark != null && toggledUrl.CompareTo(pBookMark->GetUrl()) == 0)
907                                 {
908                                         bookmarkFound = true;
909                                         break;
910                                 }
911                         }
912                 }
913                 if(bookmarkFound == false)
914                 {
915                         // Add the history in bookmark database
916                         result r = E_FAILURE;
917                         BookmarkData bookmark;
918
919                         String bookmarkTitle = pHistory->GetHistoryTitle();
920
921                         bookmark.SetBookmarkTitle(bookmarkTitle);
922                         bookmark.SetUrl(pHistory->GetHistoryUrl());
923                         bookmark.SetFaviconId(pHistory->GetFaviconId());
924                         bookmark.SetFavIconBuffer(*pHistory->GetFavIconBuffer());
925                         //r = BookmarkPresentationModel::GetInstance()->SaveBookmark(pBookmark);
926                         r = BookmarkPresentationModel::GetInstance()->SaveTempBookmark(bookmark);
927                 }
928                 else
929                 {
930                         // remove the history from bookmark database
931                         BookmarkPresentationModel::GetInstance()->DeleteBookmark(toggledUrl);
932                 }
933
934                 if(__pBookmarkList != null)
935                 {
936                         __pBookmarkList->RemoveAll(false);
937                         BookmarkPresentationModel::GetInstance()->GetBookmarkForHistory(0,*__pBookmarkList);
938                 }
939                 listView.RefreshList(groupIndex,itemIndex,LIST_REFRESH_TYPE_ITEM_MODIFY);
940                 listView.UpdateList();
941         }
942         else
943         {
944                 pGroupItemClass = dynamic_cast< GroupItemClass* >(__pGroupData->GetAt(groupIndex));
945                 if (pGroupItemClass == null)
946                 {
947                         return;
948                 }
949
950                 History* pHistory1 = dynamic_cast< History* >(pGroupItemClass->GetHistoryData()->GetAt(itemIndex));
951                 if (pHistory1 == null)
952                 {
953                         return;
954                 }
955                 SceneManager* pSceneManager = SceneManager::GetInstance();
956                 ArrayList *pArgList = null;
957                 result r = E_SUCCESS;
958                 pArgList = new(std::nothrow) ArrayList();
959                 if (pArgList != null)
960                 {
961                         r = pArgList->Construct();
962                         if (IsFailed(r))
963                         {
964                                 delete pArgList;
965                                 return;
966                         }
967
968                         r = pArgList->Add(*MultipleWindowPresentationModel::GetInstance()->GetActiveWindowInfo());
969                         r = pArgList->Add(*new(std::nothrow) String(pHistory1->GetHistoryUrl()));
970                         if (IsFailed(r))
971                         {
972                                 delete pArgList;
973                                 return;
974                         }
975
976
977                 }
978
979                 String scneId = L"";
980                 MultipleWindowPresentationModel::GetInstance()->GetCurrentSceneId(scneId);
981
982                 if (pSceneManager != null)
983                 {
984                         AppLog("pSceneManager exists");
985                         r = SceneManager::GetInstance()->GoForward(ForwardSceneTransition(scneId), pArgList);
986                         if(pArgList)
987                         {
988                                 pArgList->RemoveAll(false);
989                                 delete pArgList;
990                         }
991                         if (IsFailed(r))
992                         {
993                                 return;
994                         }
995                 }
996         }
997
998 }
999
1000 void
1001 HistoryListForm::OnGroupedListViewItemSwept(GroupedListView& listView, int groupIndex, int itemIndex, SweepDirection direction)
1002 {
1003
1004 }
1005
1006 void
1007 HistoryListForm::OnSearchBarModeChanged(SearchBar& source, SearchBarMode mode)
1008 {
1009         result r = E_FAILURE;
1010         if (mode == SEARCH_BAR_MODE_NORMAL)
1011         {
1012                 if ( Clipboard::GetInstance()->IsPopupVisible() == false && __searchHistory == false)
1013                 {
1014                         __pSearchListView->SetEnabled(true);
1015                 }
1016
1017                 r = __pSearchListView->SetShowState(false);
1018                 if (IsFailed(r))
1019                 {
1020                         return;
1021                 }
1022                 r = __pGroupedListView->SetShowState(true);
1023                 if (IsFailed(r))
1024                 {
1025                         return;
1026                 }
1027
1028                 __pSearchListView->SetEnabled(true);
1029                 if(__pSearchBar != null)
1030                         __pGroupedListView->SetBounds(0, __pSearchBar->GetY() + __pSearchBar->GetHeight(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
1031                 Invalidate(true);
1032                 __searchHistory = false;
1033                 r = __pGroupedListView->UpdateList();
1034                 if (__isNoHistoryPresent == true)
1035                 {
1036                         GetFooter()->SetItemEnabled(0, false);
1037                 }
1038                 else
1039                 {
1040                         GetFooter()->SetItemEnabled(0, true);
1041                 }
1042                 if(__pSearchBar != null)
1043                 {
1044                         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1045                 }
1046                 if (IsFailed(r))
1047                 {
1048                         return;
1049                 }
1050         }
1051         else
1052         {
1053
1054                 //              __pSearchListView->SetEnabled(false);
1055                 r = __pSearchListView->SetShowState(true);
1056                 if (IsFailed(r))
1057                 {
1058                         return;
1059                 }
1060                 __pSearchListView->SetEnabled(false);
1061                 r = __pSearchListView->UpdateList();
1062                 if (IsFailed(r))
1063                 {
1064                         return;
1065                 }
1066                 r = __pGroupedListView->SetShowState(false);
1067                 if (IsFailed(r))
1068                 {
1069                         return;
1070                 }
1071                 if(__pSearchBar != null)
1072                 {
1073                         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1074                 }
1075         }
1076 }
1077
1078 String
1079 HistoryListForm::GetMonth(int month)
1080 {
1081         String monthValue = L"";
1082         switch (month)
1083         {
1084         case JANUARY:
1085                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_JAN"));
1086                 break;
1087         case FEBRUARY:
1088                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_FEB"));
1089                 break;
1090         case MARCH:
1091                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_MAR"));
1092                 break;
1093         case APRIL:
1094                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_APR"));
1095                 break;
1096         case MAY:
1097                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_MAY"));
1098                 break;
1099         case JUNE:
1100                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_JUNE"));
1101                 break;
1102         case JULY:
1103                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_JUL"));
1104                 break;
1105         case AUGUST:
1106                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_AUG"));
1107                 break;
1108         case SEPTEMBER:
1109                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_SEP"));
1110                 break;
1111         case OCTOBER:
1112                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_OCT"));
1113                 break;
1114         case NOVEMBER:
1115                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_NOV"));
1116                 break;
1117         case DECEMBER:
1118                 monthValue.Append(CommonUtil::GetString(L"IDS_COM_BODY_DEC"));
1119                 break;
1120         default:
1121                 break;
1122         }
1123
1124
1125         return monthValue;
1126 }
1127
1128 void
1129 HistoryListForm::OnKeypadActionPerformed(Control &source, KeypadAction keypadAction)
1130 {
1131         result r = E_FAILURE;
1132         if (__pSearchBar != null)
1133         {
1134                 __pSearchBar->HideKeypad();
1135         }
1136
1137         if (__pSearchBar != null && keypadAction == KEYPAD_ACTION_SEARCH)
1138         {
1139                 __pSearchListView->SetEnabled(true);
1140                 __searchHistory = true;
1141                 __searchText =__pSearchBar->GetText();
1142                 AppLog("SearchTextHistory %S errormsg %s",__searchText.GetPointer(),GetErrorMessage(GetLastResult()));
1143
1144                 r = __pGroupedListView->SetShowState(false);
1145                 if (IsFailed(r))
1146                 {
1147                         return;
1148                 }
1149                 r = __pSearchListView->SetShowState(true);
1150                 if (IsFailed(r))
1151                 {
1152                         return;
1153                 }
1154                 r= __pSearchListView->UpdateList();
1155                 if (__isNoHistoryPresent == true)
1156                 {
1157                         GetFooter()->SetItemEnabled(0, false);
1158                 }
1159                 else
1160                 {
1161                         GetFooter()->SetItemEnabled(0, true);
1162                 }
1163                 __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1164
1165                 if (IsFailed(r))
1166                 {
1167                         return;
1168                 }
1169         }
1170         else
1171         {
1172                 __searchHistory = false;
1173         }
1174         Invalidate(true);
1175 }
1176
1177 void
1178 HistoryListForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
1179 {
1180         FloatRectangle clientRect;
1181         clientRect = GetClientAreaBoundsF();
1182         AppLogDebug("SearchBarForm::OnKeypadBoundsChanged ClientBounds(%f, %f, %f, %f)",clientRect.x, clientRect.y, clientRect.width, clientRect.height);
1183         __pSearchBar->SetContentAreaSize(FloatDimension(clientRect.width, clientRect.height - __pSearchBar->GetHeightF()));
1184         __pSearchListView->SetSize(FloatDimension(clientRect.width, clientRect.height - __pSearchBar->GetHeightF()));
1185         __pGroupedListView->SetSize(FloatDimension(clientRect.width, clientRect.height - __pSearchBar->GetHeightF()));
1186 //      __pGroupedListView->SetEnabled(false);
1187         Invalidate(true);
1188 }
1189
1190 void
1191 HistoryListForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1192 {
1193         result r = E_FAILURE;
1194         if (__pGroupedListView != null)
1195         {
1196                 if(__pSearchBar != null &&__pSearchBar->GetShowState())
1197                         r = __pGroupedListView->SetBounds(Rectangle(0,__pSearchBar->GetY() + __pSearchBar->GetHeight()/*72 + 30*/,GetClientAreaBounds().width,GetClientAreaBounds().height - __pSearchBar->GetHeight() - __pSearchBar->GetY()));
1198                 else if(__pSearchBar != null)
1199                         r = __pGroupedListView->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height - __pSearchBar->GetHeight() - __pSearchBar->GetY()));
1200                 if (IsFailed(r))
1201                 {
1202                         return;
1203                 }
1204                 __pGroupedListView->UpdateList();
1205
1206                 if (__pSearchListView != null)
1207                 {
1208                         r = __pSearchListView->SetBounds(Rectangle(0,  0, GetClientAreaBounds().width, __pGroupedListView->GetHeight()));
1209                         if (IsFailed(r))
1210                         {
1211                                 return;
1212                         }
1213
1214                         __pSearchListView->UpdateList();
1215
1216                         if(__pSearchBar != null)
1217                                 __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1218                 }
1219
1220         }
1221
1222         if (__isNoHistoryPresent == true)
1223         {
1224                 GetFooter()->SetItemEnabled(0, false);
1225         }
1226         else
1227         {
1228                 GetFooter()->SetItemEnabled(0, true);
1229         }
1230 }
1231
1232 void
1233 HistoryListForm::OnKeypadWillOpen(Control& source)
1234 {
1235         GetFooter()->SetShowState(false);
1236         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
1237         __pSearchListView->SetEnabled(false);
1238         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1239         Invalidate(true);
1240
1241 }
1242
1243 void
1244 HistoryListForm::OnKeypadOpened(Control& source)
1245 {
1246         // this is added because some time footer is shown when key pad is opened, do not remove
1247         GetFooter()->SetShowState(false);
1248         GetFooter()->Invalidate(true);
1249         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight());
1250 }
1251
1252 void
1253 HistoryListForm::OnKeypadClosed(Control& source)
1254 {
1255         if(Clipboard::GetInstance()->IsPopupVisible() == true)
1256         {
1257                 return;
1258         }
1259         GetFooter()->SetShowState(true);
1260         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight());
1261         __pSearchListView->Invalidate(false);
1262         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight()));
1263         __pGroupedListView->SetBounds(0, __pSearchBar->GetY() + __pSearchBar->GetHeight(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
1264         Invalidate(true);
1265 }
1266
1267 void
1268 HistoryListForm::CreateGroupItems()
1269 {
1270         result r = E_FAILURE;
1271         DateTime currentTime;
1272         DateTime dateTime;
1273         GroupItemClass* pGroupItemClass = null;
1274         String titleText;
1275
1276         String weeksAgo2 = L"";
1277         weeksAgo2.Format(25,CommonUtil::GetString(L"IDS_EMAIL_BODY_PD_WEEKS_AGO").GetPointer(),2);
1278
1279         String weeksAgo3 = L"";
1280         weeksAgo3.Format(25,CommonUtil::GetString(L"IDS_EMAIL_BODY_PD_WEEKS_AGO").GetPointer(),3);
1281
1282         if (__pGroupData != null)
1283         {
1284                 __pGroupData->RemoveAll(false);
1285                 delete __pGroupData;
1286                 __pGroupData = null;
1287         }
1288         __pGroupData = new(std::nothrow) ArrayList();
1289         if (__pGroupData == null)
1290         {
1291                 return;
1292         }
1293         r = __pGroupData->Construct();
1294         if (IsFailed(r))
1295         {
1296                 delete __pGroupData;
1297                 __pGroupData = null;
1298                 return;
1299         }
1300         if (__searchHistory == true)
1301         {
1302                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1303                 if (pGroupItemClass == null)
1304                 {
1305                         return;
1306                 }
1307                 titleText = CommonUtil::GetString(L"IDS_BR_BODY_SEARCHED_ITEMS");
1308                 pGroupItemClass->SetTitleText(titleText);
1309                 r = __pGroupData->Add(*pGroupItemClass);
1310                 if (IsFailed(r))
1311                 {
1312                         return;
1313                 }
1314         }
1315         else
1316         {
1317                 Calendar* pGregorianCalendar = null;
1318                 int dayOfWeek = 0;
1319                 int day = 0;
1320                 HistoryPresentationModel::GetCurrentDateTime(currentTime);
1321                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1322                 if (pGroupItemClass == null)
1323                 {
1324                         return;
1325                 }
1326                 titleText = CommonUtil::GetString(L"IDS_COM_BODY_TODAY");
1327                 pGroupItemClass->SetTitleText(titleText);
1328                 pGroupItemClass->SetEndTime(currentTime);
1329                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1330                 pGroupItemClass->SetStartTime(dateTime);
1331                 __pGroupData->Add(*pGroupItemClass);
1332
1333
1334                 pGregorianCalendar = Calendar::CreateInstanceN(CALENDAR_GREGORIAN);
1335                 if ( pGregorianCalendar != NULL )
1336                 {
1337                         pGregorianCalendar->SetTimeField(TIME_FIELD_YEAR, currentTime.GetYear());
1338                         pGregorianCalendar->SetTimeField(TIME_FIELD_MONTH, currentTime.GetMonth());
1339                         pGregorianCalendar->SetTimeField(TIME_FIELD_DAY_OF_MONTH, currentTime.GetDay());
1340                         dayOfWeek = pGregorianCalendar->GetTimeField(TIME_FIELD_DAY_OF_WEEK);
1341                         delete pGregorianCalendar;
1342                 }
1343                 switch(dayOfWeek)
1344                 {
1345                 case SUNDAY:
1346                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1347                         if (pGroupItemClass == null)
1348                         {
1349                                 return;
1350                         }
1351                         titleText = CommonUtil::GetString(L"IDS_BR_BODY_LAST_WEEK");
1352                         pGroupItemClass->SetTitleText(titleText);
1353                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1354                         pGroupItemClass->SetEndTime(dateTime);
1355                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1356                         dateTime.AddDays(currentTime.GetDay() - 6 - 1);
1357                         pGroupItemClass->SetStartTime(dateTime);
1358                         __pGroupData->Add(*pGroupItemClass);
1359                         break;
1360                 case MONDAY:
1361                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1362                         if (pGroupItemClass == null)
1363                         {
1364                                 return;
1365                         }
1366                         titleText = CommonUtil::GetString(L"IDS_BR_BODY_LAST_WEEK");
1367                         pGroupItemClass->SetTitleText(titleText);
1368                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1369                         pGroupItemClass->SetEndTime(dateTime);
1370                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1371                         dateTime.AddDays(currentTime.GetDay() - 7 - 1);
1372                         pGroupItemClass->SetStartTime(dateTime);
1373                         __pGroupData->Add(*pGroupItemClass);
1374                         break;
1375                 case TUESDAY:
1376                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1377                         if (pGroupItemClass == null)
1378                         {
1379                                 return;
1380                         }
1381                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1382                         pGroupItemClass->SetTitleText(titleText);
1383                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1384                         pGroupItemClass->SetEndTime(dateTime);
1385                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1386                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1387                         pGroupItemClass->SetStartTime(dateTime);
1388                         __pGroupData->Add(*pGroupItemClass);
1389
1390                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1391                         if (pGroupItemClass == null)
1392                         {
1393                                 return;
1394                         }
1395                         titleText = CommonUtil::GetString(L"IDS_BR_BODY_LAST_WEEK");
1396                         pGroupItemClass->SetTitleText(titleText);
1397                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1398                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1399                         pGroupItemClass->SetEndTime(dateTime);
1400                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1401                         dateTime.AddDays(currentTime.GetDay() - 8 - 1);
1402                         pGroupItemClass->SetStartTime(dateTime);
1403                         __pGroupData->Add(*pGroupItemClass);
1404                         break;
1405                 case WEDNESDAY:
1406                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1407                         if (pGroupItemClass == null)
1408                         {
1409                                 return;
1410                         }
1411                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1412                         pGroupItemClass->SetTitleText(titleText);
1413                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1414                         pGroupItemClass->SetEndTime(dateTime);
1415                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1416                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1417                         pGroupItemClass->SetStartTime(dateTime);
1418                         __pGroupData->Add(*pGroupItemClass);
1419
1420                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1421                         if (pGroupItemClass == null)
1422                         {
1423                                 return;
1424                         }
1425                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_MON");
1426                         pGroupItemClass->SetTitleText(titleText);
1427                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1428                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1429                         pGroupItemClass->SetEndTime(dateTime);
1430                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1431                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1432                         pGroupItemClass->SetStartTime(dateTime);
1433                         __pGroupData->Add(*pGroupItemClass);
1434
1435                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1436                         if (pGroupItemClass == null)
1437                         {
1438                                 return;
1439                         }
1440                         titleText = CommonUtil::GetString(L"IDS_BR_BODY_LAST_WEEK");
1441                         pGroupItemClass->SetTitleText(titleText);
1442                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1443                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1444                         pGroupItemClass->SetEndTime(dateTime);
1445                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1446                         dateTime.AddDays(currentTime.GetDay() - 9 - 1);
1447                         pGroupItemClass->SetStartTime(dateTime);
1448                         __pGroupData->Add(*pGroupItemClass);
1449                         break;
1450                 case THURSDAY:
1451                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1452                         if (pGroupItemClass == null)
1453                         {
1454                                 return;
1455                         }
1456                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1457                         pGroupItemClass->SetTitleText(titleText);
1458                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1459                         pGroupItemClass->SetEndTime(dateTime);
1460                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1461                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1462                         pGroupItemClass->SetStartTime(dateTime);
1463                         __pGroupData->Add(*pGroupItemClass);
1464
1465                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1466                         if (pGroupItemClass == null)
1467                         {
1468                                 return;
1469                         }
1470                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_TUE");
1471                         pGroupItemClass->SetTitleText(titleText);
1472                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1473                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1474                         pGroupItemClass->SetEndTime(dateTime);
1475                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1476                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1477                         pGroupItemClass->SetStartTime(dateTime);
1478                         __pGroupData->Add(*pGroupItemClass);
1479
1480                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1481                         if (pGroupItemClass == null)
1482                         {
1483                                 return;
1484                         }
1485                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_MON");
1486                         pGroupItemClass->SetTitleText(titleText);
1487                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1488                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1489                         pGroupItemClass->SetEndTime(dateTime);
1490                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1491                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1492                         pGroupItemClass->SetStartTime(dateTime);
1493                         __pGroupData->Add(*pGroupItemClass);
1494
1495                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1496                         if (pGroupItemClass == null)
1497                         {
1498                                 return;
1499                         }
1500                         titleText = CommonUtil::GetString(L"IDS_BR_BODY_LAST_WEEK");
1501                         pGroupItemClass->SetTitleText(titleText);
1502                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1503                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1504                         pGroupItemClass->SetEndTime(dateTime);
1505                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1506                         dateTime.AddDays(currentTime.GetDay() - 10 - 1);
1507                         pGroupItemClass->SetStartTime(dateTime);
1508                         __pGroupData->Add(*pGroupItemClass);
1509                         break;
1510                 case FRIDAY:
1511                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1512                         if (pGroupItemClass == null)
1513                         {
1514                                 return;
1515                         }
1516                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1517                         pGroupItemClass->SetTitleText(titleText);
1518                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1519                         pGroupItemClass->SetEndTime(dateTime);
1520                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1521                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1522                         pGroupItemClass->SetStartTime(dateTime);
1523                         __pGroupData->Add(*pGroupItemClass);
1524
1525                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1526                         if (pGroupItemClass == null)
1527                         {
1528                                 return;
1529                         }
1530                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_WED");
1531                         pGroupItemClass->SetTitleText(titleText);
1532                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1533                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1534                         pGroupItemClass->SetEndTime(dateTime);
1535                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1536                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1537                         pGroupItemClass->SetStartTime(dateTime);
1538                         __pGroupData->Add(*pGroupItemClass);
1539
1540                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1541                         if (pGroupItemClass == null)
1542                         {
1543                                 return;
1544                         }
1545                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_TUE");
1546                         pGroupItemClass->SetTitleText(titleText);
1547                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1548                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1549                         pGroupItemClass->SetEndTime(dateTime);
1550                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1551                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1552                         pGroupItemClass->SetStartTime(dateTime);
1553                         __pGroupData->Add(*pGroupItemClass);
1554
1555                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1556                         if (pGroupItemClass == null)
1557                         {
1558                                 return;
1559                         }
1560                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_MON");
1561                         pGroupItemClass->SetTitleText(titleText);
1562                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1563                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1564                         pGroupItemClass->SetEndTime(dateTime);
1565                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1566                         dateTime.AddDays(currentTime.GetDay() - 4 - 1);
1567                         pGroupItemClass->SetStartTime(dateTime);
1568                         __pGroupData->Add(*pGroupItemClass);
1569
1570                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1571                         if (pGroupItemClass == null)
1572                         {
1573                                 return;
1574                         }
1575                         titleText = CommonUtil::GetString(L"IDS_BR_BODY_LAST_WEEK");
1576                         pGroupItemClass->SetTitleText(titleText);
1577                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1578                         dateTime.AddDays(currentTime.GetDay() - 4 - 1);
1579                         pGroupItemClass->SetEndTime(dateTime);
1580                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1581                         dateTime.AddDays(currentTime.GetDay() - 11 - 1);
1582                         pGroupItemClass->SetStartTime(dateTime);
1583                         __pGroupData->Add(*pGroupItemClass);
1584                         break;
1585                 case SATURDAY:
1586                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1587                         if (pGroupItemClass == null)
1588                         {
1589                                 return;
1590                         }
1591                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1592                         pGroupItemClass->SetTitleText(titleText);
1593                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1594                         pGroupItemClass->SetEndTime(dateTime);
1595                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1596                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1597                         pGroupItemClass->SetStartTime(dateTime);
1598                         __pGroupData->Add(*pGroupItemClass);
1599
1600                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1601                         if (pGroupItemClass == null)
1602                         {
1603                                 return;
1604                         }
1605                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_THU");
1606                         pGroupItemClass->SetTitleText(titleText);
1607                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1608                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1609                         pGroupItemClass->SetEndTime(dateTime);
1610                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1611                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1612                         pGroupItemClass->SetStartTime(dateTime);
1613                         __pGroupData->Add(*pGroupItemClass);
1614
1615                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1616                         if (pGroupItemClass == null)
1617                         {
1618                                 return;
1619                         }
1620                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_WED");
1621                         pGroupItemClass->SetTitleText(titleText);
1622                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1623                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1624                         pGroupItemClass->SetEndTime(dateTime);
1625                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1626                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1627                         pGroupItemClass->SetStartTime(dateTime);
1628                         __pGroupData->Add(*pGroupItemClass);
1629
1630                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1631                         if (pGroupItemClass == null)
1632                         {
1633                                 return;
1634                         }
1635                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_TUE");
1636                         pGroupItemClass->SetTitleText(titleText);
1637                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1638                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1639                         pGroupItemClass->SetEndTime(dateTime);
1640                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1641                         dateTime.AddDays(currentTime.GetDay() - 4 - 1);
1642                         pGroupItemClass->SetStartTime(dateTime);
1643                         __pGroupData->Add(*pGroupItemClass);
1644
1645                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1646                         if (pGroupItemClass == null)
1647                         {
1648                                 return;
1649                         }
1650                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_MON");
1651                         pGroupItemClass->SetTitleText(titleText);
1652                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1653                         dateTime.AddDays(currentTime.GetDay() - 4 - 1);
1654                         pGroupItemClass->SetEndTime(dateTime);
1655                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1656                         dateTime.AddDays(currentTime.GetDay() - 5 - 1);
1657                         pGroupItemClass->SetStartTime(dateTime);
1658                         __pGroupData->Add(*pGroupItemClass);
1659
1660                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1661                         if (pGroupItemClass == null)
1662                         {
1663                                 return;
1664                         }
1665                         titleText = CommonUtil::GetString(L"IDS_BR_BODY_LAST_WEEK");
1666                         pGroupItemClass->SetTitleText(titleText);
1667                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1668                         dateTime.AddDays(currentTime.GetDay() - 5 - 1);
1669                         pGroupItemClass->SetEndTime(dateTime);
1670                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1671                         dateTime.AddDays(currentTime.GetDay() - 12 - 1);
1672                         pGroupItemClass->SetStartTime(dateTime);
1673                         __pGroupData->Add(*pGroupItemClass);
1674                         break;
1675
1676                 default:
1677                         break;
1678                 }
1679                 day = currentTime.GetDay();
1680                 switch(day/7)
1681                 {
1682                 case 2:
1683                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1684                         if (pGroupItemClass == null)
1685                         {
1686                                 return;
1687                         }
1688
1689                         pGroupItemClass->SetTitleText(weeksAgo2);
1690                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1691                         dateTime.AddDays(currentTime.GetDay() - 7 - dayOfWeek + 2 - 1);
1692                         pGroupItemClass->SetEndTime(dateTime);
1693                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1694                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1695                         pGroupItemClass->SetStartTime(dateTime);
1696                         __pGroupData->Add(*pGroupItemClass);
1697
1698                         if (pGroupItemClass->GetStartTime().GetDay() > 1 && pGroupItemClass->GetStartTime().GetDay() < 8)
1699                         {
1700                                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1701                                 if (pGroupItemClass == null)
1702                                 {
1703                                         return;
1704                                 }
1705                                 String weeksAgo3 = L"";
1706                                 weeksAgo3.Format(25,CommonUtil::GetString(L"IDS_EMAIL_BODY_PD_WEEKS_AGO").GetPointer(),3);
1707                                 pGroupItemClass->SetTitleText(weeksAgo3);
1708                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1709                                 dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1710                                 pGroupItemClass->SetEndTime(dateTime);
1711                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1712                                 dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1713                                 pGroupItemClass->SetStartTime(dateTime);
1714                                 __pGroupData->Add(*pGroupItemClass);
1715                         }
1716                         break;
1717                 case 3:
1718                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1719                         if (pGroupItemClass == null)
1720                         {
1721                                 return;
1722                         }
1723                         pGroupItemClass->SetTitleText(weeksAgo2);
1724                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1725                         dateTime.AddDays(currentTime.GetDay() - 7 - dayOfWeek + 2 - 1);
1726                         pGroupItemClass->SetEndTime(dateTime);
1727                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1728                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1729                         pGroupItemClass->SetStartTime(dateTime);
1730                         __pGroupData->Add(*pGroupItemClass);
1731
1732                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1733                         if (pGroupItemClass == null)
1734                         {
1735                                 return;
1736                         }
1737
1738                         pGroupItemClass->SetTitleText(weeksAgo3);
1739                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1740                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1741                         pGroupItemClass->SetEndTime(dateTime);
1742                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1743                         dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1744                         pGroupItemClass->SetStartTime(dateTime);
1745                         __pGroupData->Add(*pGroupItemClass);
1746
1747                         if (pGroupItemClass->GetStartTime().GetDay() > 1 && pGroupItemClass->GetStartTime().GetDay() < 8)
1748                         {
1749                                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1750                                 if (pGroupItemClass == null)
1751                                 {
1752                                         return;
1753                                 }
1754                                 titleText = CommonUtil::GetString(L"IDS_BR_EARLIER_THIS_MONTH");
1755                                 pGroupItemClass->SetTitleText(titleText);
1756                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1757                                 dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1758                                 pGroupItemClass->SetEndTime(dateTime);
1759                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1760                                 //dateTime.AddDays(currentTime.GetDay() - 28 - dayOfWeek + 2 - 1);
1761                                 pGroupItemClass->SetStartTime(dateTime);
1762                                 __pGroupData->Add(*pGroupItemClass);
1763                         }
1764                         break;
1765                 case 4:
1766                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1767                         if (pGroupItemClass == null)
1768                         {
1769                                 return;
1770                         }
1771                         pGroupItemClass->SetTitleText(weeksAgo2);
1772                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1773                         dateTime.AddDays(currentTime.GetDay() - 7 - dayOfWeek + 2 - 1);
1774                         pGroupItemClass->SetEndTime(dateTime);
1775                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1776                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1777                         pGroupItemClass->SetStartTime(dateTime);
1778                         __pGroupData->Add(*pGroupItemClass);
1779
1780                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1781                         if (pGroupItemClass == null)
1782                         {
1783                                 return;
1784                         }
1785                         pGroupItemClass->SetTitleText(weeksAgo3);
1786                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1787                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1788                         pGroupItemClass->SetEndTime(dateTime);
1789                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1790                         dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1791                         pGroupItemClass->SetStartTime(dateTime);
1792                         __pGroupData->Add(*pGroupItemClass);
1793
1794                         if (pGroupItemClass->GetStartTime().GetDay() > 1 && pGroupItemClass->GetStartTime().GetDay() < 8)
1795                         {
1796                                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1797                                 if (pGroupItemClass == null)
1798                                 {
1799                                         return;
1800                                 }
1801                                 titleText = CommonUtil::GetString(L"IDS_BR_EARLIER_THIS_MONTH");
1802                                 pGroupItemClass->SetTitleText(titleText);
1803                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1804                                 dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1805                                 pGroupItemClass->SetEndTime(dateTime);
1806                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1807                                 //dateTime.AddDays(currentTime.GetDay() - 28 - dayOfWeek + 2 - 1);
1808                                 pGroupItemClass->SetStartTime(dateTime);
1809                                 __pGroupData->Add(*pGroupItemClass);
1810                         }
1811                         break;
1812                 default:
1813                         break;
1814                 }
1815                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1816                 if (pGroupItemClass == null)
1817                 {
1818                         return;
1819                 }
1820                 titleText = CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_MONTH");
1821                 pGroupItemClass->SetTitleText(titleText);
1822                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1823                 dateTime.AddDays(-1);
1824                 pGroupItemClass->SetEndTime(dateTime);
1825                 dateTime.SetValue(currentTime.GetYear(), 1, 1);
1826                 dateTime.AddMonths(currentTime.GetMonth() - 1 - 1);
1827                 pGroupItemClass->SetStartTime(dateTime);
1828                 __pGroupData->Add(*pGroupItemClass);
1829
1830                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1831                 if (pGroupItemClass == null)
1832                 {
1833                         return;
1834                 }
1835                 titleText = CommonUtil::GetString(L"IDS_BR_BODY_OLDER");
1836                 pGroupItemClass->SetTitleText(titleText);
1837                 dateTime.SetValue(currentTime.GetYear(),1, 1);
1838                 dateTime.AddMonths(currentTime.GetMonth() - 2);
1839                 dateTime.AddDays(-1);
1840                 pGroupItemClass->SetEndTime(dateTime);
1841                 DateTime dateTime2;
1842                 dateTime2.SetValue(0, 0, 0);
1843                 pGroupItemClass->SetStartTime(dateTime2);
1844                 __pGroupData->Add(*pGroupItemClass);
1845         }
1846 }
1847
1848 GroupItemClass::GroupItemClass()
1849 {
1850         __pData = null;
1851 }
1852
1853 GroupItemClass&
1854 GroupItemClass::operator =(const GroupItemClass& rhs)
1855 {
1856         if (this != &rhs)
1857         {
1858                 __pData = rhs.__pData;
1859         }
1860         return *this;
1861 }
1862
1863 GroupItemClass::GroupItemClass(const GroupItemClass& groupItem)
1864 {
1865         __pData = groupItem.__pData;
1866 }
1867
1868 GroupItemClass::~GroupItemClass()
1869 {
1870         if (__pData)
1871         {
1872                 __pData->RemoveAll(true);
1873                 delete __pData;
1874         }
1875 }
1876
1877 void
1878 GroupItemClass::SetStartTime(DateTime& startTime)
1879 {
1880         __startTime = startTime;
1881 }
1882
1883 void
1884 GroupItemClass::SetEndTime(DateTime& endTime)
1885 {
1886         __endTime = endTime;
1887 }
1888
1889 void
1890 GroupItemClass::SetTitleText(String& titleText)
1891 {
1892         __titleText = titleText;
1893 }
1894
1895 void
1896 GroupItemClass::SetHistoryData(ArrayList* pData)
1897 {
1898         __pData = pData;
1899 }
1900
1901 DateTime
1902 GroupItemClass::GetStartTime(void)
1903 {
1904         return __startTime;
1905 }
1906
1907 DateTime
1908 GroupItemClass::GetEndTime(void)
1909 {
1910         return __endTime;
1911 }
1912
1913 String
1914 GroupItemClass::GetTitleText(void)
1915 {
1916         return __titleText;
1917 }
1918
1919 ArrayList*
1920 GroupItemClass::GetHistoryData(void)
1921 {
1922         return __pData;
1923 }
1924
1925 void
1926 HistoryListForm::OnSettingChanged(Tizen::Base::String& key)
1927 {
1928         if (__pGroupedListView)
1929         {
1930                 __pGroupedListView->UpdateList();
1931         }
1932 }