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