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