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