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