Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntHistoryListForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 //!Internet HistoryListForm class
18 /*@file: HistoryListForm.cpp
19  *@brief:       This class defines HistoryListForm used define history
20  *
21  */
22
23 #include <FApp.h>
24 #include <FUi.h>
25 #include "IntBookmarkData.h"
26 #include "IntBookmarkPresentationModel.h"
27 #include "IntCommonLib.h"
28 #include "IntFaviconManager.h"
29 #include "IntHistoryListForm.h"
30 #include "IntHistoryPresentationModel.h"
31 #include "IntMultipleWindowPresentationModel.h"
32 #include "IntSceneRegister.h"
33 #include "IntTypes.h"
34
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Locales;
41 using namespace Tizen::Media;
42 using namespace Tizen::Ui;
43 using namespace Tizen::Ui::Controls;
44 using namespace Tizen::Ui::Scenes;
45 using namespace Tizen::System;
46
47 static const wchar_t* IDB_TAB_ICON_BOOKMARKS = L"I01_tab_icon_bookmarks.png";
48 static const wchar_t* IDB_TAB_ICON_HISTORY = L"I01_tab_icon_history.png";
49 static const wchar_t* IDB_ICON_BOOKMARK_ON_TEMP = L"I01_icon_bookmark_on_temp.png";
50 static const wchar_t* IDB_ICON_BOOKMARK_OFF_TEMP = L"I01_icon_bookmark_off_temp.png";
51
52
53 const int HistoryListForm::IDA_TABBAR_ITEM_1 = 101;
54 const int HistoryListForm::IDA_TABBAR_ITEM_2 = 102;
55 const int HistoryListForm::IDA_EDIT_HISTORY_LIST_FORM = 103;
56 const int HistoryListForm::IDA_FORMAT_ICON = 104;
57 const int HistoryListForm::IDA_FORMAT_TITLE = 105;
58 const int HistoryListForm::IDA_FORMAT_URL = 106;
59 const int HistoryListForm::IDA_FORMAT_BOOKMARK = 107;
60
61
62 HistoryListForm::HistoryListForm(void)
63 {
64         __pBookmarkList = null;
65         __pGroupedListView =null;
66         __pSearchListView = null;
67         __pSearchBar = null;
68         __pGroupData = null;
69         __pSearchedData = null ;
70         __searchHistory = false;
71         __isNoHistoryPresent = true;
72         __searchText = L"";
73         __previousSceneId = L"";
74 }
75
76 HistoryListForm::~HistoryListForm(void)
77 {
78         if (__pGroupData != null)
79         {
80                 __pGroupData->RemoveAll(false);
81                 delete __pGroupData;
82         }
83         if(__pBookmarkList != null)
84         {
85                 __pBookmarkList->RemoveAll(false);
86                 delete __pBookmarkList;
87         }
88 }
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                 __pSearchListView->SetEnabled(true);
1014                 if(__pSearchBar != null)
1015                         __pGroupedListView->SetBounds(0, __pSearchBar->GetY() + __pSearchBar->GetHeight(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
1016                 Invalidate(true);
1017                 __searchHistory = false;
1018                 r = __pGroupedListView->UpdateList();
1019                 if (__isNoHistoryPresent == true)
1020                 {
1021                         GetFooter()->SetItemEnabled(0, false);
1022                 }
1023                 else
1024                 {
1025                         GetFooter()->SetItemEnabled(0, true);
1026                 }
1027                 if(__pSearchBar != null)
1028                 {
1029                         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1030                 }
1031                 if (IsFailed(r))
1032                 {
1033                         return;
1034                 }
1035         }
1036         else
1037         {
1038                 // added
1039                 GetFooter()->SetShowState(false);
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"DS_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         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight());
1232 }
1233
1234 void
1235 HistoryListForm::OnKeypadClosed(Control& source)
1236 {
1237         if(Clipboard::GetInstance()->IsPopupVisible() == true)
1238         {
1239                 return;
1240         }
1241         GetFooter()->SetShowState(true);
1242         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight());
1243         __pSearchListView->Invalidate(false);
1244         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight()));
1245         __pGroupedListView->SetBounds(0, __pSearchBar->GetY() + __pSearchBar->GetHeight(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
1246         Invalidate(true);
1247 }
1248
1249 void
1250 HistoryListForm::CreateGroupItems()
1251 {
1252         result r = E_FAILURE;
1253         DateTime currentTime;
1254         DateTime dateTime;
1255         GroupItemClass* pGroupItemClass = null;
1256         String titleText;
1257
1258         String weeksAgo2 = L"";
1259         weeksAgo2.Format(25,CommonUtil::GetString(L"IDS_BR_BODY_PD_WEEKS_AGO").GetPointer(),2);
1260
1261         String weeksAgo3 = L"";
1262         weeksAgo3.Format(25,CommonUtil::GetString(L"IDS_BR_BODY_PD_WEEKS_AGO").GetPointer(),3);
1263
1264         if (__pGroupData != null)
1265         {
1266                 __pGroupData->RemoveAll(false);
1267                 delete __pGroupData;
1268                 __pGroupData = null;
1269         }
1270         __pGroupData = new(std::nothrow) ArrayList();
1271         if (__pGroupData == null)
1272         {
1273                 return;
1274         }
1275         r = __pGroupData->Construct();
1276         if (IsFailed(r))
1277         {
1278                 delete __pGroupData;
1279                 __pGroupData = null;
1280                 return;
1281         }
1282         if (__searchHistory == true)
1283         {
1284                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1285                 if (pGroupItemClass == null)
1286                 {
1287                         return;
1288                 }
1289                 titleText = CommonUtil::GetString(L"IDS_BR_BODY_SEARCHED_ITEMS");
1290                 pGroupItemClass->SetTitleText(titleText);
1291                 r = __pGroupData->Add(*pGroupItemClass);
1292                 if (IsFailed(r))
1293                 {
1294                         return;
1295                 }
1296         }
1297         else
1298         {
1299                 Calendar* pGregorianCalendar = null;
1300                 int dayOfWeek = 0;
1301                 int day = 0;
1302                 HistoryPresentationModel::GetCurrentDateTime(currentTime);
1303                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1304                 if (pGroupItemClass == null)
1305                 {
1306                         return;
1307                 }
1308                 titleText = CommonUtil::GetString(L"IDS_COM_BODY_TODAY");
1309                 pGroupItemClass->SetTitleText(titleText);
1310                 pGroupItemClass->SetEndTime(currentTime);
1311                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1312                 pGroupItemClass->SetStartTime(dateTime);
1313                 __pGroupData->Add(*pGroupItemClass);
1314
1315
1316                 pGregorianCalendar = Calendar::CreateInstanceN(CALENDAR_GREGORIAN);
1317                 if ( pGregorianCalendar != NULL )
1318                 {
1319                         pGregorianCalendar->SetTimeField(TIME_FIELD_YEAR, currentTime.GetYear());
1320                         pGregorianCalendar->SetTimeField(TIME_FIELD_MONTH, currentTime.GetMonth());
1321                         pGregorianCalendar->SetTimeField(TIME_FIELD_DAY_OF_MONTH, currentTime.GetDay());
1322                         dayOfWeek = pGregorianCalendar->GetTimeField(TIME_FIELD_DAY_OF_WEEK);
1323                         delete pGregorianCalendar;
1324                 }
1325                 switch(dayOfWeek)
1326                 {
1327                 case SUNDAY:
1328                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1329                         if (pGroupItemClass == null)
1330                         {
1331                                 return;
1332                         }
1333                         titleText = CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_WEEK");
1334                         pGroupItemClass->SetTitleText(titleText);
1335                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1336                         pGroupItemClass->SetEndTime(dateTime);
1337                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1338                         dateTime.AddDays(currentTime.GetDay() - 6 - 1);
1339                         pGroupItemClass->SetStartTime(dateTime);
1340                         __pGroupData->Add(*pGroupItemClass);
1341                         break;
1342                 case MONDAY:
1343                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1344                         if (pGroupItemClass == null)
1345                         {
1346                                 return;
1347                         }
1348                         titleText = CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_WEEK");
1349                         pGroupItemClass->SetTitleText(titleText);
1350                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1351                         pGroupItemClass->SetEndTime(dateTime);
1352                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1353                         dateTime.AddDays(currentTime.GetDay() - 7 - 1);
1354                         pGroupItemClass->SetStartTime(dateTime);
1355                         __pGroupData->Add(*pGroupItemClass);
1356                         break;
1357                 case TUESDAY:
1358                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1359                         if (pGroupItemClass == null)
1360                         {
1361                                 return;
1362                         }
1363                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1364                         pGroupItemClass->SetTitleText(titleText);
1365                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1366                         pGroupItemClass->SetEndTime(dateTime);
1367                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1368                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1369                         pGroupItemClass->SetStartTime(dateTime);
1370                         __pGroupData->Add(*pGroupItemClass);
1371
1372                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1373                         if (pGroupItemClass == null)
1374                         {
1375                                 return;
1376                         }
1377                         titleText = CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_WEEK");
1378                         pGroupItemClass->SetTitleText(titleText);
1379                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1380                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1381                         pGroupItemClass->SetEndTime(dateTime);
1382                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1383                         dateTime.AddDays(currentTime.GetDay() - 8 - 1);
1384                         pGroupItemClass->SetStartTime(dateTime);
1385                         __pGroupData->Add(*pGroupItemClass);
1386                         break;
1387                 case WEDNESDAY:
1388                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1389                         if (pGroupItemClass == null)
1390                         {
1391                                 return;
1392                         }
1393                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1394                         pGroupItemClass->SetTitleText(titleText);
1395                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1396                         pGroupItemClass->SetEndTime(dateTime);
1397                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1398                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1399                         pGroupItemClass->SetStartTime(dateTime);
1400                         __pGroupData->Add(*pGroupItemClass);
1401
1402                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1403                         if (pGroupItemClass == null)
1404                         {
1405                                 return;
1406                         }
1407                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_MON");
1408                         pGroupItemClass->SetTitleText(titleText);
1409                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1410                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1411                         pGroupItemClass->SetEndTime(dateTime);
1412                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1413                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1414                         pGroupItemClass->SetStartTime(dateTime);
1415                         __pGroupData->Add(*pGroupItemClass);
1416
1417                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1418                         if (pGroupItemClass == null)
1419                         {
1420                                 return;
1421                         }
1422                         titleText = CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_WEEK");
1423                         pGroupItemClass->SetTitleText(titleText);
1424                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1425                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1426                         pGroupItemClass->SetEndTime(dateTime);
1427                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1428                         dateTime.AddDays(currentTime.GetDay() - 9 - 1);
1429                         pGroupItemClass->SetStartTime(dateTime);
1430                         __pGroupData->Add(*pGroupItemClass);
1431                         break;
1432                 case THURSDAY:
1433                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1434                         if (pGroupItemClass == null)
1435                         {
1436                                 return;
1437                         }
1438                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1439                         pGroupItemClass->SetTitleText(titleText);
1440                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1441                         pGroupItemClass->SetEndTime(dateTime);
1442                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1443                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1444                         pGroupItemClass->SetStartTime(dateTime);
1445                         __pGroupData->Add(*pGroupItemClass);
1446
1447                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1448                         if (pGroupItemClass == null)
1449                         {
1450                                 return;
1451                         }
1452                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_TUE");
1453                         pGroupItemClass->SetTitleText(titleText);
1454                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1455                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1456                         pGroupItemClass->SetEndTime(dateTime);
1457                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1458                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1459                         pGroupItemClass->SetStartTime(dateTime);
1460                         __pGroupData->Add(*pGroupItemClass);
1461
1462                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1463                         if (pGroupItemClass == null)
1464                         {
1465                                 return;
1466                         }
1467                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_MON");
1468                         pGroupItemClass->SetTitleText(titleText);
1469                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1470                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1471                         pGroupItemClass->SetEndTime(dateTime);
1472                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1473                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1474                         pGroupItemClass->SetStartTime(dateTime);
1475                         __pGroupData->Add(*pGroupItemClass);
1476
1477                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1478                         if (pGroupItemClass == null)
1479                         {
1480                                 return;
1481                         }
1482                         titleText = CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_WEEK");
1483                         pGroupItemClass->SetTitleText(titleText);
1484                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1485                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1486                         pGroupItemClass->SetEndTime(dateTime);
1487                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1488                         dateTime.AddDays(currentTime.GetDay() - 10 - 1);
1489                         pGroupItemClass->SetStartTime(dateTime);
1490                         __pGroupData->Add(*pGroupItemClass);
1491                         break;
1492                 case FRIDAY:
1493                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1494                         if (pGroupItemClass == null)
1495                         {
1496                                 return;
1497                         }
1498                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1499                         pGroupItemClass->SetTitleText(titleText);
1500                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1501                         pGroupItemClass->SetEndTime(dateTime);
1502                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1503                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1504                         pGroupItemClass->SetStartTime(dateTime);
1505                         __pGroupData->Add(*pGroupItemClass);
1506
1507                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1508                         if (pGroupItemClass == null)
1509                         {
1510                                 return;
1511                         }
1512                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_WED");
1513                         pGroupItemClass->SetTitleText(titleText);
1514                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1515                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1516                         pGroupItemClass->SetEndTime(dateTime);
1517                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1518                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1519                         pGroupItemClass->SetStartTime(dateTime);
1520                         __pGroupData->Add(*pGroupItemClass);
1521
1522                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1523                         if (pGroupItemClass == null)
1524                         {
1525                                 return;
1526                         }
1527                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_TUE");
1528                         pGroupItemClass->SetTitleText(titleText);
1529                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1530                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1531                         pGroupItemClass->SetEndTime(dateTime);
1532                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1533                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1534                         pGroupItemClass->SetStartTime(dateTime);
1535                         __pGroupData->Add(*pGroupItemClass);
1536
1537                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1538                         if (pGroupItemClass == null)
1539                         {
1540                                 return;
1541                         }
1542                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_MON");
1543                         pGroupItemClass->SetTitleText(titleText);
1544                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1545                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1546                         pGroupItemClass->SetEndTime(dateTime);
1547                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1548                         dateTime.AddDays(currentTime.GetDay() - 4 - 1);
1549                         pGroupItemClass->SetStartTime(dateTime);
1550                         __pGroupData->Add(*pGroupItemClass);
1551
1552                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1553                         if (pGroupItemClass == null)
1554                         {
1555                                 return;
1556                         }
1557                         titleText = CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_WEEK");
1558                         pGroupItemClass->SetTitleText(titleText);
1559                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1560                         dateTime.AddDays(currentTime.GetDay() - 4 - 1);
1561                         pGroupItemClass->SetEndTime(dateTime);
1562                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1563                         dateTime.AddDays(currentTime.GetDay() - 11 - 1);
1564                         pGroupItemClass->SetStartTime(dateTime);
1565                         __pGroupData->Add(*pGroupItemClass);
1566                         break;
1567                 case SATURDAY:
1568                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1569                         if (pGroupItemClass == null)
1570                         {
1571                                 return;
1572                         }
1573                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_YESTERDAY");
1574                         pGroupItemClass->SetTitleText(titleText);
1575                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), currentTime.GetDay());
1576                         pGroupItemClass->SetEndTime(dateTime);
1577                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1578                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1579                         pGroupItemClass->SetStartTime(dateTime);
1580                         __pGroupData->Add(*pGroupItemClass);
1581
1582                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1583                         if (pGroupItemClass == null)
1584                         {
1585                                 return;
1586                         }
1587                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_THU");
1588                         pGroupItemClass->SetTitleText(titleText);
1589                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1590                         dateTime.AddDays(currentTime.GetDay() - 1 - 1);
1591                         pGroupItemClass->SetEndTime(dateTime);
1592                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1593                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1594                         pGroupItemClass->SetStartTime(dateTime);
1595                         __pGroupData->Add(*pGroupItemClass);
1596
1597                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1598                         if (pGroupItemClass == null)
1599                         {
1600                                 return;
1601                         }
1602                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_WED");
1603                         pGroupItemClass->SetTitleText(titleText);
1604                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1605                         dateTime.AddDays(currentTime.GetDay() - 2 - 1);
1606                         pGroupItemClass->SetEndTime(dateTime);
1607                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1608                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1609                         pGroupItemClass->SetStartTime(dateTime);
1610                         __pGroupData->Add(*pGroupItemClass);
1611
1612                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1613                         if (pGroupItemClass == null)
1614                         {
1615                                 return;
1616                         }
1617                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_TUE");
1618                         pGroupItemClass->SetTitleText(titleText);
1619                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1620                         dateTime.AddDays(currentTime.GetDay() - 3 - 1);
1621                         pGroupItemClass->SetEndTime(dateTime);
1622                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1623                         dateTime.AddDays(currentTime.GetDay() - 4 - 1);
1624                         pGroupItemClass->SetStartTime(dateTime);
1625                         __pGroupData->Add(*pGroupItemClass);
1626
1627                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1628                         if (pGroupItemClass == null)
1629                         {
1630                                 return;
1631                         }
1632                         titleText = CommonUtil::GetString(L"IDS_COM_BODY_MON");
1633                         pGroupItemClass->SetTitleText(titleText);
1634                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1635                         dateTime.AddDays(currentTime.GetDay() - 4 - 1);
1636                         pGroupItemClass->SetEndTime(dateTime);
1637                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1638                         dateTime.AddDays(currentTime.GetDay() - 5 - 1);
1639                         pGroupItemClass->SetStartTime(dateTime);
1640                         __pGroupData->Add(*pGroupItemClass);
1641
1642                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1643                         if (pGroupItemClass == null)
1644                         {
1645                                 return;
1646                         }
1647                         titleText = CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_WEEK");
1648                         pGroupItemClass->SetTitleText(titleText);
1649                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1650                         dateTime.AddDays(currentTime.GetDay() - 5 - 1);
1651                         pGroupItemClass->SetEndTime(dateTime);
1652                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1653                         dateTime.AddDays(currentTime.GetDay() - 12 - 1);
1654                         pGroupItemClass->SetStartTime(dateTime);
1655                         __pGroupData->Add(*pGroupItemClass);
1656                         break;
1657
1658                 default:
1659                         break;
1660                 }
1661                 day = currentTime.GetDay();
1662                 switch(day/7)
1663                 {
1664                 case 2:
1665                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1666                         if (pGroupItemClass == null)
1667                         {
1668                                 return;
1669                         }
1670
1671                         pGroupItemClass->SetTitleText(weeksAgo2);
1672                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1673                         dateTime.AddDays(currentTime.GetDay() - 7 - dayOfWeek + 2 - 1);
1674                         pGroupItemClass->SetEndTime(dateTime);
1675                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1676                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1677                         pGroupItemClass->SetStartTime(dateTime);
1678                         __pGroupData->Add(*pGroupItemClass);
1679
1680                         if (pGroupItemClass->GetStartTime().GetDay() > 1 && pGroupItemClass->GetStartTime().GetDay() < 8)
1681                         {
1682                                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1683                                 if (pGroupItemClass == null)
1684                                 {
1685                                         return;
1686                                 }
1687                                 String weeksAgo3 = L"";
1688                                 weeksAgo3.Format(25,CommonUtil::GetString(L"IDS_BR_BODY_PD_WEEKS_AGO").GetPointer(),3);
1689                                 pGroupItemClass->SetTitleText(weeksAgo3);
1690                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1691                                 dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1692                                 pGroupItemClass->SetEndTime(dateTime);
1693                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1694                                 dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1695                                 pGroupItemClass->SetStartTime(dateTime);
1696                                 __pGroupData->Add(*pGroupItemClass);
1697                         }
1698                         break;
1699                 case 3:
1700                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1701                         if (pGroupItemClass == null)
1702                         {
1703                                 return;
1704                         }
1705                         pGroupItemClass->SetTitleText(weeksAgo2);
1706                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1707                         dateTime.AddDays(currentTime.GetDay() - 7 - dayOfWeek + 2 - 1);
1708                         pGroupItemClass->SetEndTime(dateTime);
1709                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1710                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1711                         pGroupItemClass->SetStartTime(dateTime);
1712                         __pGroupData->Add(*pGroupItemClass);
1713
1714                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1715                         if (pGroupItemClass == null)
1716                         {
1717                                 return;
1718                         }
1719
1720                         pGroupItemClass->SetTitleText(weeksAgo3);
1721                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1722                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1723                         pGroupItemClass->SetEndTime(dateTime);
1724                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1725                         dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1726                         pGroupItemClass->SetStartTime(dateTime);
1727                         __pGroupData->Add(*pGroupItemClass);
1728
1729                         if (pGroupItemClass->GetStartTime().GetDay() > 1 && pGroupItemClass->GetStartTime().GetDay() < 8)
1730                         {
1731                                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1732                                 if (pGroupItemClass == null)
1733                                 {
1734                                         return;
1735                                 }
1736                                 titleText = CommonUtil::GetString(L"IDS_BR_EARLIER_THIS_MONTH");
1737                                 pGroupItemClass->SetTitleText(titleText);
1738                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1739                                 dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1740                                 pGroupItemClass->SetEndTime(dateTime);
1741                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1742                                 //dateTime.AddDays(currentTime.GetDay() - 28 - dayOfWeek + 2 - 1);
1743                                 pGroupItemClass->SetStartTime(dateTime);
1744                                 __pGroupData->Add(*pGroupItemClass);
1745                         }
1746                         break;
1747                 case 4:
1748                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1749                         if (pGroupItemClass == null)
1750                         {
1751                                 return;
1752                         }
1753                         pGroupItemClass->SetTitleText(weeksAgo2);
1754                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1755                         dateTime.AddDays(currentTime.GetDay() - 7 - dayOfWeek + 2 - 1);
1756                         pGroupItemClass->SetEndTime(dateTime);
1757                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1758                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1759                         pGroupItemClass->SetStartTime(dateTime);
1760                         __pGroupData->Add(*pGroupItemClass);
1761
1762                         pGroupItemClass = new(std::nothrow) GroupItemClass();
1763                         if (pGroupItemClass == null)
1764                         {
1765                                 return;
1766                         }
1767                         pGroupItemClass->SetTitleText(weeksAgo3);
1768                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1769                         dateTime.AddDays(currentTime.GetDay() - 14 - dayOfWeek + 2 - 1);
1770                         pGroupItemClass->SetEndTime(dateTime);
1771                         dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1772                         dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1773                         pGroupItemClass->SetStartTime(dateTime);
1774                         __pGroupData->Add(*pGroupItemClass);
1775
1776                         if (pGroupItemClass->GetStartTime().GetDay() > 1 && pGroupItemClass->GetStartTime().GetDay() < 8)
1777                         {
1778                                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1779                                 if (pGroupItemClass == null)
1780                                 {
1781                                         return;
1782                                 }
1783                                 titleText = CommonUtil::GetString(L"IDS_BR_EARLIER_THIS_MONTH");
1784                                 pGroupItemClass->SetTitleText(titleText);
1785                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1786                                 dateTime.AddDays(currentTime.GetDay() - 21 - dayOfWeek + 2 - 1);
1787                                 pGroupItemClass->SetEndTime(dateTime);
1788                                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1789                                 //dateTime.AddDays(currentTime.GetDay() - 28 - dayOfWeek + 2 - 1);
1790                                 pGroupItemClass->SetStartTime(dateTime);
1791                                 __pGroupData->Add(*pGroupItemClass);
1792                         }
1793                         break;
1794                 default:
1795                         break;
1796                 }
1797                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1798                 if (pGroupItemClass == null)
1799                 {
1800                         return;
1801                 }
1802                 titleText = CommonUtil::GetString(L"IDS_EMAIL_BODY_LAST_MONTH");
1803                 pGroupItemClass->SetTitleText(titleText);
1804                 dateTime.SetValue(currentTime.GetYear(),currentTime.GetMonth(), 1);
1805                 dateTime.AddDays(-1);
1806                 pGroupItemClass->SetEndTime(dateTime);
1807                 dateTime.SetValue(currentTime.GetYear(), 1, 1);
1808                 dateTime.AddMonths(currentTime.GetMonth() - 1 - 1);
1809                 pGroupItemClass->SetStartTime(dateTime);
1810                 __pGroupData->Add(*pGroupItemClass);
1811
1812                 pGroupItemClass = new(std::nothrow) GroupItemClass();
1813                 if (pGroupItemClass == null)
1814                 {
1815                         return;
1816                 }
1817                 titleText = CommonUtil::GetString(L"IDS_BR_BODY_OLDER");
1818                 pGroupItemClass->SetTitleText(titleText);
1819                 dateTime.SetValue(currentTime.GetYear(),1, 1);
1820                 dateTime.AddMonths(currentTime.GetMonth() - 2);
1821                 dateTime.AddDays(-1);
1822                 pGroupItemClass->SetEndTime(dateTime);
1823                 DateTime dateTime2;
1824                 dateTime2.SetValue(0, 0, 0);
1825                 pGroupItemClass->SetStartTime(dateTime2);
1826                 __pGroupData->Add(*pGroupItemClass);
1827         }
1828 }
1829
1830 GroupItemClass::GroupItemClass()
1831 {
1832         __pData = null;
1833 }
1834
1835 GroupItemClass&
1836 GroupItemClass::operator =(const GroupItemClass& rhs)
1837 {
1838         if (this != &rhs)
1839         {
1840                 __pData = rhs.__pData;
1841         }
1842         return *this;
1843 }
1844
1845 GroupItemClass::GroupItemClass(const GroupItemClass& groupItem)
1846 {
1847         __pData = groupItem.__pData;
1848 }
1849
1850 GroupItemClass::~GroupItemClass()
1851 {
1852         if (__pData)
1853         {
1854                 __pData->RemoveAll(true);
1855                 delete __pData;
1856         }
1857 }
1858
1859 void
1860 GroupItemClass::SetStartTime(DateTime& startTime)
1861 {
1862         __startTime = startTime;
1863 }
1864
1865 void
1866 GroupItemClass::SetEndTime(DateTime& endTime)
1867 {
1868         __endTime = endTime;
1869 }
1870
1871 void
1872 GroupItemClass::SetTitleText(String& titleText)
1873 {
1874         __titleText = titleText;
1875 }
1876
1877 void
1878 GroupItemClass::SetHistoryData(ArrayList* pData)
1879 {
1880         __pData = pData;
1881 }
1882
1883 DateTime
1884 GroupItemClass::GetStartTime(void)
1885 {
1886         return __startTime;
1887 }
1888
1889 DateTime
1890 GroupItemClass::GetEndTime(void)
1891 {
1892         return __endTime;
1893 }
1894
1895 String
1896 GroupItemClass::GetTitleText(void)
1897 {
1898         return __titleText;
1899 }
1900
1901 ArrayList*
1902 GroupItemClass::GetHistoryData(void)
1903 {
1904         return __pData;
1905 }
1906
1907 void
1908 HistoryListForm::OnSettingChanged(Tizen::Base::String& key)
1909 {
1910         if (__pGroupedListView)
1911         {
1912                 __pGroupedListView->UpdateList();
1913         }
1914 }