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