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