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