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