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