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