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