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