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