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