Fixed Nabi Issues, Changes for tizen-service implementation and DB Changes
[apps/osp/Internet.git] / src / IntBookmarkListForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (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
18 /*@file:    IntBookmarkListForm
19  *@brief:       This class defines BookmarkListForm
20  *
21  */
22
23 #include <FApp.h>
24 #include "IntBookmarkData.h"
25 #include "IntBookmarkListForm.h"
26 #include "IntBookmarkPresentationModel.h"
27 #include "IntCommonLib.h"
28 #include "IntConfirmationPopup.h"
29 #include "IntFaviconManager.h"
30 #include "IntMultipleWindowPresentationModel.h"
31 #include "IntSceneRegister.h"
32 #include "IntTypes.h"
33
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::Ui;
41 using namespace Tizen::Ui::Controls;
42 using namespace Tizen::Ui::Scenes;
43
44 const wchar_t* DEFAULT_VALUE_PARENTID = L"-1";
45 static const wchar_t* IDB_TAB_ICON_BOOKMARK = L"I01_tab_icon_bookmarks.png";
46 static const wchar_t* IDB_TAB_ICON_HISTORY = L"I01_tab_icon_history.png";
47 static const wchar_t* IDB_NO_CONTENT_BOOKMARK = L"I01_Nocontents_Bookmarks.png";
48 static const wchar_t* IDB_ICON_FOLDER_OPEN = L"I01_icon_folder_open.png";
49
50 const int BookmarkListForm::IDA_TABBAR_ITEM_1 = 101;
51 const int BookmarkListForm::IDA_TABBAR_ITEM_2 = 102;
52 const int BookmarkListForm::IDA_FOOTER_ITEM1 = 103;
53 const int BookmarkListForm::IDA_FOOTER_ITEM2 = 104;
54 const int BookmarkListForm::IDA_FOOTER_ITEM_ADDBOOKMARK = 105;
55 const int BookmarkListForm::IDA_FORMAT_FOLDER = 106;
56 const int BookmarkListForm::IDA_FORMAT_SITE = 107;
57 const int BookmarkListForm::IDA_CONTEXT_ITEM_FOLDER_EDIT = 108;
58 const int BookmarkListForm::IDA_CONTEXT_ITEM_FOLDER_DELETE = 109;
59 const int BookmarkListForm::IDA_CONTEXT_ITEM_EDIT = 110;
60 const int BookmarkListForm::IDA_CONTEXT_ITEM_SHARE = 111;
61 const int BookmarkListForm::IDA_CONTEXT_ITEM_DELETE = 112;
62 const int BookmarkListForm::IDA_FORMAT_ICON = 113;
63 const int BookmarkListForm::IDA_FORMAT_URL = 114;
64
65 //const int BookmarkListForm::IDA_CONFIRMATION_NO = 1000;
66 //const int BookmarkListForm::IDA_CONFIRMATION_YES = 1001;
67
68 BookmarkListForm::BookmarkListForm(void)
69 {
70         __pItemContextFolder = null ;
71         __pItemContextSite = null ;
72         __pListview = null;
73         __pData = null;
74         __pSearchListView = null;
75         __pSearchBar = null;
76         __searchBookmark = false;
77         __parentID = DEFAULT_VALUE_PARENTID;
78         __noBookmarks = true;
79         __selectedindex = 0;
80         __searchText = L"";
81 }
82
83 BookmarkListForm::~BookmarkListForm(void)
84 {
85
86         if (__pData != null)
87         {
88                 __pData->RemoveAll(true);
89                 delete __pData;
90                 __pData = NULL;
91         }
92
93         if (__pItemContextFolder != null)
94         {
95                 delete __pItemContextFolder;
96                 __pItemContextFolder = null;
97         }
98
99         if (__pItemContextSite != null)
100         {
101                 delete __pItemContextSite;
102                 __pItemContextSite = null;
103         }
104 }
105
106 result
107 BookmarkListForm::OnTerminating(void)
108 {
109         result r = E_SUCCESS;
110
111         if (__pData != null)
112         {
113                 __pData->RemoveAll(true);
114                 delete __pData;
115                 __pData = NULL;
116         }
117
118         return r;
119 }
120
121
122 bool
123 BookmarkListForm::Initialize(void)
124 {
125         Construct(L"IDL_BOOKMARK_LIST");
126         return true;
127 }
128
129 result
130 BookmarkListForm::OnInitializing(void)
131 {
132         result r = E_SUCCESS;
133         HeaderItem bookmark;
134         HeaderItem history;
135         Bitmap *pBitmapNormal = null;
136         Bitmap *pBitmapPressed = null;
137         Header *pHeader = GetHeader();
138         Bitmap *pIconBitmap = null;
139         AppResource* pAppResource = UiApp::GetInstance()->GetAppResource();
140         int bookmarkCount = 0;
141         const int WIDTH_CONTEXT_MENU_TWO_BUTTON = 336;
142         const int WIDTH_CONTEXT_MENU_THREE_BUTTON = 160;
143         const int HEIGHT_CONTEXT_MENU_BUTTON = 72;
144
145
146         // Setup back event listener
147         SetFormBackEventListener(this);
148         AddOrientationEventListener(*this);
149
150         SceneManager::GetInstance()->AddSceneEventListener(IDSCN_BOOKMARK_VIEW, *this);
151         GetHeader()->AddActionEventListener(*this);
152         GetFooter()->AddActionEventListener(*this);
153
154         if ( pAppResource == NULL )
155         {
156                 return E_FAILURE;
157         }
158
159         __pItemContextFolder = new(std::nothrow) ListContextItem();
160         __pItemContextFolder->Construct();
161         __pItemContextFolder->AddElement(IDA_CONTEXT_ITEM_FOLDER_EDIT, CommonUtil::GetString(L"IDS_BR_SK_EDIT"));
162         pBitmapNormal = CommonUtil::GetNinepatchedBitmapN(L"00_button_sweep_delete.9.png", WIDTH_CONTEXT_MENU_TWO_BUTTON, HEIGHT_CONTEXT_MENU_BUTTON);
163         pBitmapPressed = CommonUtil::GetNinepatchedBitmapN(L"00_button_sweep_delete_press.9.png", WIDTH_CONTEXT_MENU_TWO_BUTTON, HEIGHT_CONTEXT_MENU_BUTTON);
164
165         if (pBitmapNormal != null && pBitmapPressed != null)
166         {
167                 __pItemContextFolder->AddElement(IDA_CONTEXT_ITEM_FOLDER_DELETE, CommonUtil::GetString(L"IDS_BR_SK_DELETE_ABB"),  *pBitmapNormal, *pBitmapPressed, pBitmapPressed);
168         }
169
170         if (pBitmapNormal != null)
171         {
172                 delete pBitmapNormal;
173         }
174
175         if (pBitmapPressed != null)
176         {
177                 delete pBitmapPressed;
178         }
179
180         __pItemContextSite = new(std::nothrow) ListContextItem();
181         __pItemContextSite->Construct();
182         __pItemContextSite->AddElement(IDA_CONTEXT_ITEM_EDIT, CommonUtil::GetString(L"IDS_BR_SK_EDIT"));
183         __pItemContextSite->AddElement(IDA_CONTEXT_ITEM_SHARE, CommonUtil::GetString(L"IDS_BR_OPT_SHARE"));
184         pBitmapNormal = CommonUtil::GetNinepatchedBitmapN(L"00_button_sweep_delete.9.png", WIDTH_CONTEXT_MENU_THREE_BUTTON, HEIGHT_CONTEXT_MENU_BUTTON);
185         pBitmapPressed = CommonUtil::GetNinepatchedBitmapN(L"00_button_sweep_delete_press.9.png", WIDTH_CONTEXT_MENU_THREE_BUTTON, HEIGHT_CONTEXT_MENU_BUTTON);
186
187         if (pBitmapNormal != null && pBitmapPressed != null)
188         {
189                 __pItemContextSite->AddElement(IDA_CONTEXT_ITEM_DELETE, CommonUtil::GetString(L"IDS_BR_SK_DELETE_ABB"), *pBitmapNormal, *pBitmapPressed, pBitmapPressed);
190         }
191
192         if (pBitmapNormal != null)
193         {
194                 delete pBitmapNormal;
195         }
196
197         if (pBitmapPressed != null)
198         {
199                 delete pBitmapPressed;
200         }
201         __pListview = static_cast< ListView* >(GetControl("IDC_LISTVIEW1"));
202
203         if (__pListview == null)
204         {
205                 return E_FAILURE;
206         }
207         __pSearchBar = static_cast< SearchBar* >(GetControl(L"IDC_SEARCHBAR1"));
208
209         if (__pSearchBar == null)
210         {
211                 return E_FAILURE;
212         }
213
214         if (__pListview != null)
215         {
216                 //              __pListview->SetBounds(__pListview->GetX(), __pListview->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height);
217                 __pListview->AddFastScrollListener(*this);
218                 __pListview->AddListViewItemEventListener(*this);
219                 __pListview->SetItemProvider(*this);
220                 __pListview->UpdateList();
221         }
222
223         __pPopUp = new(std::nothrow) SharePopup();
224
225         if (__pPopUp != null)
226         {
227                 __pPopUp->Initialize();
228                 AddControl(*__pPopUp);
229         }
230
231         __pSearchListView = new(std::nothrow) ListView();
232
233         if (__pSearchListView == null)
234         {
235                 return E_FAILURE;
236         }
237
238         r = __pSearchListView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height -72 - 30), true, false);
239         TryCatch( !IsFailed(r),,"BookmarkListForm::OnSearchBarModeChanged Update list failed %s",GetErrorMessage(r));
240
241         __pSearchListView->SetItemProvider(*this);
242         __pSearchListView->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_BR_BODY_NO_RESULTS_FOUND"));
243         __pSearchListView->SetTextColorOfEmptyList(Color::GetColor(COLOR_ID_BLACK));
244         __pSearchListView->SetShowState(false);
245         __pSearchListView->AddListViewItemEventListener(*this);
246
247         __pSearchBar->AddSearchBarEventListener(*this);
248         __pSearchBar->AddKeypadEventListener(*this);
249         __pSearchBar->SetContent(__pSearchListView);
250
251         BookmarkPresentationModel::GetInstance()->GetFolderBookmarkCount(__parentID, bookmarkCount);
252         if(bookmarkCount <= 0)
253         {
254                 __pSearchBar->SetShowState(false);
255                 //__pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetY(),__pSearchBar->GetWidth(),GetClientAreaBounds().height - __pSearchBar->GetPosition().y);
256                 __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetY(),__pListview->GetWidth(),GetClientAreaBounds().height);
257         }
258         else
259         {
260                 __pSearchBar->SetShowState(true);
261         }
262
263
264         if (pHeader != null)
265         {
266                 pHeader->SetStyle(HEADER_STYLE_TAB);
267                 bookmark.Construct(IDA_TABBAR_ITEM_1);
268                 String strbookmark;
269                 pAppResource->GetString(L"IDS_BR_TAB_BOOKMARKS", strbookmark);
270                 bookmark.SetText(strbookmark);
271                 pIconBitmap = pAppResource->GetBitmapN(IDB_TAB_ICON_BOOKMARK);
272                 bookmark.SetIcon(HEADER_ITEM_STATUS_NORMAL, pIconBitmap);
273                 bookmark.SetIcon(HEADER_ITEM_STATUS_PRESSED, pIconBitmap);
274                 pHeader->AddItem(bookmark);
275
276                 if (pIconBitmap != NULL)
277                 {
278                         delete pIconBitmap;
279                 }
280
281                 history.Construct(IDA_TABBAR_ITEM_2);
282                 String strhistory;
283                 pAppResource->GetString(L"IDS_BR_TAB_HISTORY", strhistory);
284                 history.SetText(strhistory);
285                 pIconBitmap = pAppResource->GetBitmapN(IDB_TAB_ICON_HISTORY);
286                 history.SetIcon(HEADER_ITEM_STATUS_NORMAL, pIconBitmap);
287                 history.SetIcon(HEADER_ITEM_STATUS_PRESSED, pIconBitmap);
288                 pHeader->AddItem(history);
289                 pHeader->SetItemSelected(0);
290
291                 if (pIconBitmap != NULL)
292                 {
293                         delete pIconBitmap;
294                 }
295         }
296
297
298         CATCH:return r;
299 }
300
301 void
302 BookmarkListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
303 {
304         AppLogDebug("BookmarkListForm::OnActionPerformed actionId = %d",actionId);
305         String bookmarkId;
306         int id = 0;
307         BookmarkData* pBookMark = null;
308
309         switch (actionId)
310         {
311         case IDA_FOOTER_ITEM1:
312         {
313                 GetHeader()->SetItemSelected(0);
314                 GetHeader()->Invalidate(true);
315                 SceneManager* pSceneManager = SceneManager::GetInstance();
316                 pBookMark = dynamic_cast< BookmarkData* >(__pData->GetAt(__selectedindex));
317
318                 if ( pBookMark == NULL )
319                 {
320                         return;
321                 }
322
323                 ArrayList* pArgList = null;
324                 pArgList = new(std::nothrow) ArrayList();
325                 if (pArgList != null)
326                 {
327                         pArgList->Construct();
328                         pArgList->Add(*new(std::nothrow) String(pBookMark->GetParentId()));
329                 }
330                 //pArgList->Add(*new(std::nothrow) String(pBookmark->);
331                 if (pSceneManager != null)
332                 {
333                         if(pSceneManager->GoForward(ForwardSceneTransition(IDSCN_EDIT_BOOKMARK_LIST),pArgList) != E_SUCCESS)
334                         {
335                                 AppLogDebug("BookmarkListForm::OnActionPerformed GoForward failed");
336                                 pArgList->RemoveAll(true);
337                                 delete pArgList;
338                                 pArgList = null;
339                                 return;
340                         }
341                 }
342
343                 if ( pArgList != NULL)
344                 {
345                         pArgList->RemoveAll(true);
346                         delete pArgList;
347                 }
348         }
349
350         break;
351         case IDA_TABBAR_ITEM_2:
352         {
353                 GetHeader()->SetItemSelected(0);
354                 GetHeader()->Invalidate(true);
355
356                 SceneManager* pSceneManager = SceneManager::GetInstance();
357
358                 if (pSceneManager != null)
359                 {
360                         if(pSceneManager->GoForward(ForwardSceneTransition(IDSCN_HISTORY_LIST, SCENE_TRANSITION_ANIMATION_TYPE_LEFT)) != E_SUCCESS)
361                         {
362                                 AppLogDebug("BookmarkListForm::OnActionPerformed GoForward failed");
363                                 return;
364                         }
365                 }
366         }
367         break;
368         case IDA_FOOTER_ITEM2:
369         {
370                 SceneManager* pSceneManager = SceneManager::GetInstance();
371
372                 if (pSceneManager)
373                 {
374                         if(pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CREATE_BOOKMARK_FOLDER)) != E_SUCCESS)
375                         {
376                                 AppLogDebug("BookmarkListForm::OnActionPerformed GoForward failed");
377                                 return;
378                         }
379                 }
380         }
381         break;
382         case IDA_FOOTER_ITEM_ADDBOOKMARK:
383         {
384                 SceneManager* pSceneManager = SceneManager::GetInstance();
385
386                 // send array list 0-for add, 1 for edit with parent ID
387                 ArrayList* pArgList = null;
388                 pArgList = new(std::nothrow) ArrayList();
389                 if (pArgList != null)
390                 {
391                         pArgList->Construct();
392                         pArgList->Add(*new(std::nothrow) String(L"0"));
393                         pArgList->Add(*new(std::nothrow) String(__parentID));
394                 }
395
396                 if (pSceneManager)
397                 {
398                         if(pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ADD_BOOKMARK),pArgList) != E_SUCCESS)
399                         {
400                                 AppLogDebug("BookmarkListForm::OnActionPerformed GoForward failed");
401                                 pArgList->RemoveAll(true);
402                                 delete pArgList;
403                                 return;
404                         }
405                 }
406
407                 if (pArgList != null)
408                 {
409                         pArgList->RemoveAll(true);
410                         delete pArgList;
411                 }
412
413         }
414         break;
415         case IDA_BUTTON_NO:
416                 __pConfirmationPopup->SetShowState(false);
417                 __pConfirmationPopup->Show();
418                 break;
419         case IDA_BUTTON_YES:
420                 pBookMark = dynamic_cast< BookmarkData* >(__pData->GetAt(__selectedindex));
421                 if ( pBookMark== null)
422                         return;
423                 bookmarkId=pBookMark->GetBookmarkId();
424                 Integer::Parse(bookmarkId,id);
425                 if (pBookMark->GetBookmarkType() == BOOKMARK_TYPE_FOLDER)
426                         BookmarkPresentationModel::GetInstance()->DeleteFolder(id);
427                 else
428                         BookmarkPresentationModel::GetInstance()->DeleteBookmark(id);
429                 if (__pListview == null)
430                 {
431                         return;
432                 }
433                 AppLogDebug("__pListview GetBounds %d,%d,%d,%d",__pListview->GetBounds().x,__pListview->GetBounds().y,__pListview->GetBounds().width,__pListview->GetBounds().height);
434                 __pSearchListView->UpdateList();
435                 __pListview->UpdateList();
436
437                 if (__pListview->GetItemCount() == 0)
438                 {
439                         GetFooter()->SetItemEnabled(1,false);
440                         __pSearchBar->SetShowState(false);
441                         __pSearchBar->Invalidate(true);
442                 }
443
444                 if (__noBookmarks == true)
445                 {
446                         Bitmap* emptyListBmp = AppResource::GetInstance()->GetBitmapN(IDB_NO_CONTENT_BOOKMARK);
447                         GetFooter()->SetItemEnabled(1,false);
448                         __pSearchBar->SetShowState(false);
449                         __pSearchBar->Invalidate(true);
450                         //                      __pListview->SetBounds(__pSearchBar->GetPosition().x,__pSearchBar->GetPosition().y,__pSearchBar->GetWidth() ,GetClientAreaBounds().height);
451                         __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetPosition().y,__pSearchBar->GetWidth() ,GetClientAreaBounds().height);
452                         __pListview->SetBitmapOfEmptyList(emptyListBmp);
453                         if (emptyListBmp)
454                         {
455                                 delete emptyListBmp;
456                                 emptyListBmp = null;
457                         }
458                         __pListview->UpdateList();
459
460                 }
461                 else
462                 {
463                         GetFooter()->SetItemEnabled(1,true);
464
465                         if (__parentID.CompareTo(L"-1") == 0)
466                         {
467                                 __pSearchBar->SetShowState(true);
468                                 __pSearchBar->Invalidate(true);
469                         }
470                 }
471
472                 GetFooter()->Invalidate(true);
473                 __pConfirmationPopup->SetShowState(false);
474                 __pConfirmationPopup->Show();
475                 __selectedindex = 0;
476
477                 break;
478         default:
479                 break;
480         }
481 }
482
483 void
484 BookmarkListForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
485 {
486         AppLogDebug("BrowserApplicationForm::OnFormBackRequested");
487
488         UiApp* pApp = UiApp::GetInstance();
489         if      (pApp == null)
490         {
491                 return;
492         }
493
494         if (__parentID != DEFAULT_VALUE_PARENTID)
495         {
496                 __parentID = DEFAULT_VALUE_PARENTID;
497                 __pSearchBar->SetShowState(true);
498                 __pListview->SetBounds(__pListview->GetX() ,__pSearchBar->GetPosition().y + __pSearchBar->GetHeight(),__pListview->GetWidth(),GetClientAreaBounds().height - (__pSearchBar->GetY() + __pSearchBar->GetHeight()));
499                 __pListview->UpdateList();
500                 __pFooter = GetFooter();
501                 GetFooter()->SetItemEnabled(2,true);
502                 GetFooter()->Invalidate(true);
503         }
504         else
505         {
506                 SceneManager* pSceneManager = SceneManager::GetInstance();
507                 if (pSceneManager != null)
508                 {
509                         pSceneManager->GoBackward(BackwardSceneTransition());
510                 }
511         }
512
513         if (__noBookmarks == true)
514         {
515                 GetFooter()->SetItemEnabled(1,false);
516         }
517         else
518         {
519                 GetFooter()->SetItemEnabled(1,true);
520         }
521 }
522
523 Tizen::Ui::Controls::ListItemBase*
524 BookmarkListForm::CreateItem(int index, int itemWidth)
525 {
526         AppLog("BookmarkListForm::CreateItem index %d , itemWidth %d",index, itemWidth);
527         AppLog("listviewwidth %d",__pListview->GetWidth());
528         result r = E_FAILURE;
529         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
530         CustomItem* pItem = new(std::nothrow) CustomItem();
531         BookmarkData* pBookMark = dynamic_cast< BookmarkData* >(__pData->GetAt(index));
532         Bitmap* pBitmap = null;
533
534         const int x_Margin_Icon = 16;                 // local as there used only in this function
535         const int y_Margin_Icon = 28;
536         const int height_Icon = 72;
537         const int width_Icon = 72 ;
538         const int x_Margin_Title = 104 ;
539         const int y_Margin_Title = 10;
540         const int width_Title = GetClientAreaBounds().width - 108 - 52 - 30;
541         const int x_Margin_Url = 104 ;
542         const int y_Margin_Url = 70 ;
543         const int width_Url = GetClientAreaBounds().width - 108 - 52 ;
544         const int height_Url = 48;
545         const int itemHeight = 128;
546         const int textSize = 32;
547         String bitmapId;
548
549         if( pBookMark == NULL )
550         {
551                 delete pItem;
552                 pItem = null;
553                 return NULL;
554         }
555         if ( pBookMark->GetBookmarkType() == BOOKMARK_TYPE_FOLDER )
556         {
557                 r = pItem->Construct(Tizen::Graphics::Dimension(itemWidth,112), LIST_ANNEX_STYLE_DETAILED);
558                 TryCatch(!IsFailed(r),,"BookmarkListForm::CreateItem Construct failed %s",GetErrorMessage(r));
559
560                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_FOLDER_OPEN);
561                 if (pBitmap != null)
562                 {
563                         pItem->AddElement(Rectangle(x_Margin_Icon, 20, width_Icon, height_Icon), IDA_FORMAT_ICON, *pBitmap, null);
564                         delete pBitmap;
565                 }
566
567                 pItem->AddElement(Rectangle(x_Margin_Title, 26, width_Title, 60), IDA_FORMAT_FOLDER, pBookMark->GetBookmarkTitle(), true);
568
569                 if ( __pItemContextFolder != NULL)
570                 {
571                         pItem->SetContextItem(__pItemContextFolder);
572                 }
573         }
574         else
575         {
576                 r = pItem->Construct(Tizen::Graphics::Dimension(itemWidth, itemHeight), style);
577                 TryCatch( !IsFailed(r),,"BookmarkListForm::CreateItem Construct failed %s",GetErrorMessage(r));
578
579                 AppLogDebug("BookmarkListForm::faviconid %ls",pBookMark->GetFaviconId().GetPointer());
580                 bitmapId = pBookMark->GetFaviconId();
581
582                 pBitmap = FaviconManager::GetInstance()->GetFaviconN(bitmapId);
583                 if (pBitmap == null)
584                 {
585                         AppLogDebug("BookmarkListForm::CreateItem bitmap is null");
586                         pBitmap = FaviconManager::GetInstance()->GetDefaultFaviconN();
587                 }
588                 pItem->AddElement(Rectangle(x_Margin_Icon, y_Margin_Icon, width_Icon, height_Icon), IDA_FORMAT_ICON, *pBitmap, null);
589                 pItem->AddElement(Rectangle(x_Margin_Title, 0, width_Title, itemHeight - height_Url), IDA_FORMAT_SITE, pBookMark->GetBookmarkTitle(),44,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT,true);
590                 if(__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
591                         pItem->AddElement(Rectangle(x_Margin_Url, y_Margin_Url, width_Url, height_Url), IDA_FORMAT_URL, pBookMark->GetUrl(),textSize,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT,true);
592                 else
593                         pItem->AddElement(Rectangle(x_Margin_Url, y_Margin_Url, width_Url, height_Url), IDA_FORMAT_URL, pBookMark->GetUrl(),textSize,CUSTOM_COLOR_GREY,CUSTOM_COLOR_GREY,CUSTOM_COLOR_GREY,true);
594
595                 if (pBitmap != null)
596                 {
597                         delete pBitmap;
598                 }
599                 if ( __pItemContextSite != NULL)
600                 {
601                         pItem->SetContextItem(__pItemContextSite);
602                 }
603         }
604
605         return pItem;
606
607         CATCH:
608         delete pItem;
609         pItem = null;
610         return null;
611
612 }
613
614 bool
615 BookmarkListForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
616 {
617         delete pItem;
618         pItem = null;
619         return true;
620 }
621
622 int
623 BookmarkListForm::GetItemCount(void)
624 {
625         int count = 0;
626
627         if (__pData != NULL )
628         {
629                 __pData->RemoveAll(true);
630                 delete __pData;
631                 __pData = null;
632         }
633         __pData = new(std::nothrow) Collection::ArrayList();
634         __pData->Construct();
635
636         if (__searchBookmark == false)
637         {
638                 BookmarkPresentationModel::GetInstance()->GetFolderBookmarkCount(__parentID, count);
639                 BookmarkPresentationModel::GetInstance()->GetFoldersBookmarks(__parentID, 0, count, *__pData);
640         }
641         else
642         {
643                 BookmarkPresentationModel::GetInstance()->GetSearchFolderBookmarkCount(count,__searchText);
644                 BookmarkPresentationModel::GetInstance()->GetSearchFoldersBookmarks(0, count, *__pData, __searchText);
645         }
646
647         AppLogDebug("Count = %d parentId = %ls", count, __parentID.GetPointer());
648
649         if (count <= 0)
650         {
651                 __noBookmarks = true;
652                 GetFooter()->SetItemEnabled(1,false);
653         }
654         else
655         {
656                 __noBookmarks = false;
657                 GetFooter()->SetItemEnabled(1,true);
658         }
659
660         AppLogDebug("Result: %s", GetErrorMessage(GetLastResult()));
661         GetFooter()->Invalidate(true);
662         if (__pData != null && __pData->GetCount() >= 1)
663         {
664                 //              __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
665                 __pSearchBar->SetShowState(true);
666                 __pSearchBar->Invalidate(true);
667         }
668         else if (__searchBookmark == false)
669         {
670                 __pSearchBar->SetShowState(false);
671                 __pSearchBar->Invalidate(true);
672         }
673
674         if (__parentID.CompareTo(L"-1") != 0)
675         {
676                 __pSearchBar->SetShowState(false);
677                 __pSearchBar->Invalidate(true);
678         }
679         if (__noBookmarks == true)
680         {
681                 __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetPosition().y,__pSearchBar->GetWidth() ,GetClientAreaBounds().height);
682                 Bitmap* pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_NO_CONTENT_BOOKMARK);
683
684                 if ( pBitmap != NULL)
685                 {
686                         __pListview->SetBitmapOfEmptyList(pBitmap);
687                         delete pBitmap;
688                 }
689         }
690         else
691         {
692                 if (__parentID.CompareTo(L"-1") == 0)
693                 {
694                         __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetHeight(),GetClientAreaBounds().width ,GetClientAreaBounds().height - __pSearchBar->GetY() - __pSearchBar->GetHeight());
695                 }
696                 else
697                 {
698                         __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetY(),__pSearchBar->GetWidth() ,GetClientAreaBounds().height);
699
700                 }
701
702         }
703         __pListview->Invalidate(true);
704         return count;
705
706 }
707
708 void
709 BookmarkListForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus status)
710 {
711         AppLogDebug("BookmarkListForm::OnListViewContextItemStateChanged int index %d, int elementId %d, Tizen::Ui::Controls::ListContextItemStatus status %d",index,elementId,status);
712
713         String deleteText = CommonUtil::GetString(L"IDS_BR_SK_DELETE_ABB");
714         deleteText.Append(L"? ");
715         int timeOut = 25000;
716         result r = E_SUCCESS;
717
718         switch(elementId)
719         {
720         case IDA_CONTEXT_ITEM_FOLDER_EDIT:
721         {
722                 ArrayList* pArgList = null;
723                 String* pEdit = null;
724
725                 SceneManager* pSceneManager = SceneManager::GetInstance();
726                 BookmarkData* pBookMark = dynamic_cast< BookmarkData* >(__pData->GetAt(index));
727                 if (pBookMark != null && pBookMark->GetBookmarkType() == BOOKMARK_TYPE_FOLDER)
728                 {
729                         pArgList = new(std::nothrow) ArrayList();
730                         if (pArgList != null)
731                         {
732                                 pEdit= new(std::nothrow) String(CommonUtil::GetString(L"IDS_BR_HEADER_EDIT_FOLDER"));
733                                 pArgList->Construct();
734                                 pArgList->Add(*new(std::nothrow) BookmarkData(*pBookMark));
735                                 pArgList->Add(*pEdit);
736                                 if (    pSceneManager != null)
737                                 {
738                                         result r;
739                                         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CREATE_BOOKMARK_FOLDER), pArgList);
740                                 }
741
742                                 if (pArgList != null)
743                                 {
744                                         delete pArgList;
745                                         pArgList = null;
746                                 }
747                                 if(IsFailed(r))
748                                 {
749                                         AppLogDebug("BookmarkListForm::OnListViewContextItemStateChanged GoForward failed %s",GetErrorMessage(r));
750                                         return;
751                                 }
752                         }
753                 }
754
755         }
756         break;
757
758         case IDA_CONTEXT_ITEM_FOLDER_DELETE:
759         case IDA_CONTEXT_ITEM_DELETE:
760         {
761                 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
762                 __pConfirmationPopup->Initialize();
763                 __pConfirmationPopup->RemoveActionListener(*this);
764                 __pConfirmationPopup->AddActionListener(*this);
765                 __pConfirmationPopup->setMessage(deleteText);
766                 __pConfirmationPopup->Show();
767                 __selectedindex = index;
768         }
769         break;
770
771         case IDA_CONTEXT_ITEM_EDIT:
772         {
773                 ArrayList* pArgList = null;
774                 SceneManager* pSceneManager = SceneManager::GetInstance();
775                 BookmarkData* pBookMark = dynamic_cast< BookmarkData* >(__pData->GetAt(index));
776                 if (pBookMark!= null && pBookMark->GetBookmarkType() == BOOKMARK_TYPE_URL)
777                 {
778                         AppLogDebug("ID_CONTEXT_ITEM_SITE_1 BOOKMARK_TYPE_URL");
779                         pArgList = new(std::nothrow) ArrayList();
780                         if (pArgList != null)
781                         {
782                                 pArgList->Construct();
783                                 pArgList->Add(*new(std::nothrow) String(L"1"));
784                                 pArgList->Add(*new(std::nothrow) BookmarkData(*pBookMark));
785                                 if (    pSceneManager != null)
786                                 {
787                                         result r;
788                                         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ADD_BOOKMARK), pArgList);
789                                         if (pArgList != null)
790                                         {
791                                                 delete pArgList;
792                                                 pArgList = null;
793                                         }
794                                         if(IsFailed(r))
795                                         {
796                                                 AppLogDebug("BookmarkListForm::OnListViewContextItemStateChanged GoForward failed %s",GetErrorMessage(r));
797                                                 return;
798                                         }
799                                 }
800                         }
801                 }
802         }
803         break;
804         case IDA_CONTEXT_ITEM_SHARE:
805         {
806                 AppLogDebug("OnListViewContextItemStateChanged Share");
807
808                 BookmarkData* pBookmark = dynamic_cast<BookmarkData*>(__pData->GetAt(index));
809                 if (pBookmark != null)
810                 {
811                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
812                         pShareInfo->SetPageTitle(pBookmark->GetBookmarkTitle());
813                         pShareInfo->SetPageUrl(pBookmark->GetUrl());
814                         pShareInfo->SetImageAttached(false);
815                         __pPopUp->RemoveAllShareInfo();
816                         __pPopUp->AddShareInfo(pShareInfo);
817                 }
818
819                 if (__pPopUp != null)
820                 {
821                         __pPopUp->SetShowState(true);
822                         __pPopUp->Show();
823                 }
824         }
825         break;
826         default:
827                 break;
828         }
829
830 }
831
832 void
833 BookmarkListForm::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
834 {
835
836 }
837
838 void
839 BookmarkListForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
840 {
841         AppLogDebug("BookmarkListForm::OnListViewItemStateChanged");
842
843         result r = E_FAILURE;
844         ArrayList *pArgList = null;
845         SceneManager* pSceneManager = SceneManager::GetInstance();
846         BookmarkData* pBookmark = dynamic_cast< BookmarkData* >(__pData->GetAt(index));
847
848         if ( pBookmark == NULL )
849         {
850                 return;
851         }
852
853         switch (pBookmark->GetBookmarkType())
854         {
855         case BOOKMARK_TYPE_FOLDER:
856
857                 __parentID = pBookmark->GetBookmarkId();
858                 AppLogDebug("BOOKMARK_TYPE_FOLDER parent ID is %ls",__parentID.GetPointer());
859
860                 listView.UpdateList();
861                 if (listView.GetItemCount() == 0)
862                 {
863                         GetFooter()->SetItemEnabled(1,false);
864                 }
865                 else
866                 {
867                         GetFooter()->SetItemEnabled(1,true);
868                 }
869                 GetFooter()->SetItemEnabled(2,false);
870                 GetFooter()->Invalidate(true);
871                 __pSearchBar->HideKeypad();
872                 __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
873                 __pSearchBar->SetShowState(false);
874                 __pSearchBar->Invalidate(true);
875                 __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetY(),__pListview->GetWidth() ,GetClientAreaBounds().height);
876                 break;
877
878         case BOOKMARK_TYPE_URL:
879
880                 pArgList = new(std::nothrow) ArrayList();
881                 if (pArgList != null)
882                 {
883                         r = pArgList->Construct();
884                         TryCatch(!IsFailed(r), L"BookmarkListForm::OnListViewItemStateChanged pArgList Construct failed %s", GetErrorMessage(r));
885
886                         AppLogDebug("bookmark url = %ls",pBookmark->GetUrl().GetPointer());
887                         r = pArgList->Add(*MultipleWindowPresentationModel::GetInstance()->GetActiveWindowInfo());
888                         pArgList->Add(*new(std::nothrow) String(pBookmark->GetUrl()));
889
890                         if (pSceneManager != null)
891                         {
892                                 AppLogDebug("pSceneManager exists");
893                                 String prevSceneId;
894                                 MultipleWindowPresentationModel::GetInstance()->GetCurrentSceneId(prevSceneId);
895                                 r = pSceneManager->GoBackward(BackwardSceneTransition(prevSceneId), pArgList);
896                                 TryCatch(!IsFailed(r), L"BookmarkListForm::OnListViewItemStateChanged pArgList Construct failed %s", GetErrorMessage(r));
897                         }
898                         delete pArgList;
899                 }
900                 break;
901
902         default:
903                 break;
904         }
905
906         return;
907         CATCH:
908         if(pArgList)
909         {
910                 pArgList->RemoveAll(true);
911                 delete pArgList;
912         }
913
914 }
915
916 void
917 BookmarkListForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
918 {
919
920
921 }
922
923 void
924 BookmarkListForm::OnFastScrollIndexSelected(Tizen::Ui::Control& source, Tizen::Base::String& index)
925 {
926
927 }
928
929 void
930 BookmarkListForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
931 {
932         result r = E_FAILURE;
933
934         if (mode == SEARCH_BAR_MODE_NORMAL)
935         {
936                 __pSearchListView->SetShowState(false);
937                 __pSearchListView->UpdateList();
938                 __pListview->SetShowState(true);
939                 Invalidate(true);
940                 __searchBookmark = false;
941                 r = __pListview->UpdateList();
942                 __pSearchListView->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height -__pSearchBar->GetHeight());
943                 __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
944                 TryCatch( !IsFailed(r),,"BookmarkListForm::OnSearchBarModeChanged Update list failed %s",GetErrorMessage(r));
945                 CATCH:return;
946         }
947         else
948         {
949                 __pSearchListView->SetShowState(true);
950                 __pSearchListView->SetEnabled(false);
951                 __pListview->SetShowState(false);
952
953                 if(__pSearchBar)
954                 {
955                         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
956                         __pSearchBar->SetText(L"");
957                 }
958                 AppLog("OnSearchBarModeChanged SetContentAreaSize heihgt %d",__pSearchListView->GetHeight());
959                  __pListview->UpdateList();
960                 __pSearchListView->UpdateList();
961         }
962 }
963
964 void
965 BookmarkListForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
966 {
967         GetFooter()->SetShowState(false);
968         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), __pSearchListView->GetHeight() + GetFooter()->GetHeight());
969         __pSearchListView->SetEnabled(false);
970         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
971         Invalidate(true);
972         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), __pSearchListView->GetHeight() - GetFooter()->GetHeight());
973 }
974
975 void
976 BookmarkListForm::OnKeypadOpened(Tizen::Ui::Control& source)
977 {
978
979         __pSearchListView->UpdateList();
980 }
981
982 void
983 BookmarkListForm::OnKeypadClosed(Tizen::Ui::Control& source)
984 {
985
986         GetFooter()->SetShowState(true);
987         GetFooter()->Invalidate(true);
988         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight());
989         __pSearchListView->Invalidate(false);
990         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight()));
991 }
992
993 void
994 BookmarkListForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
995 {
996         AppLog("BookmarkListForm::OnKeypadActionPerformed %d",keypadAction);
997
998         if (__pSearchBar != null)
999         {
1000                 __pSearchBar->HideKeypad();
1001         }
1002
1003         if ( __pSearchBar != null && keypadAction == KEYPAD_ACTION_SEARCH)
1004         {
1005                 if (__pSearchBar->GetText().GetLength() == 0)
1006                 {
1007                         return;
1008                 }
1009
1010                 __searchText = __pSearchBar->GetText();
1011                 __searchBookmark = true;
1012                 __pListview->SetShowState(false);
1013                 __pSearchListView->SetEnabled(true);
1014                 __pSearchListView->SetShowState(true);
1015                 __pSearchListView->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height -__pSearchBar->GetHeight());
1016                 __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1017                 __pSearchListView->UpdateList();
1018
1019         }
1020         Invalidate(true);
1021 }
1022
1023 void
1024 BookmarkListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
1025 {
1026         AppLogDebug("BookmarkListForm::OnSceneActivatedN called");
1027
1028         __searchBookmark = false;
1029         GetFooter()->SetShowState(true);
1030         GetFooter()->Invalidate(true);
1031         GetHeader()->SetItemSelected(0);
1032         GetHeader()->Invalidate(true);
1033
1034         /*      if (previousSceneId != IDSCN_HISTORY_LIST && previousSceneId != IDSCN_CREATE_BOOKMARK_FOLDER && previousSceneId != IDSCN_EDIT_BOOKMARK_LIST)
1035         {
1036                 __previousSceneId = previousSceneId;
1037         }*/
1038
1039         if (__pListview != null)
1040         {
1041                 __pListview->UpdateList();
1042         }
1043
1044         return;
1045 }
1046
1047 void
1048 BookmarkListForm::OnOrientationChanged (const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
1049 {
1050         AppLog("BookmarkListForm::OnOrientationChanged start");
1051
1052         if (__pListview)
1053         {
1054                 if(__pSearchBar->GetShowState())
1055                 {
1056                         __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetHeight(),GetClientAreaBounds().width ,GetClientAreaBounds().height - __pSearchBar->GetY() - __pSearchBar->GetHeight());
1057                 }
1058                 else
1059                 {
1060                         __pListview->SetBounds(__pListview->GetX(),0,GetClientAreaBounds().width ,GetClientAreaBounds().height);
1061                 }
1062                 __pListview->UpdateList();
1063         }
1064
1065         if (__pSearchListView && __pListview)
1066         {
1067                 AppLog("__pListview->GetBounds() %d, %d, %d, %d",__pListview->GetBounds().x,__pListview->GetBounds().y,__pListview->GetBounds().width,__pListview->GetBounds().height);
1068                 __pSearchListView->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height -__pSearchBar->GetHeight());
1069
1070                 __pSearchListView->UpdateList();
1071         }
1072
1073         if (__pSearchListView && __pData != null )
1074         {
1075                 if (__parentID != DEFAULT_VALUE_PARENTID)
1076                 {
1077                         AppLog("BookmarkListForm::OnOrientationChanged parent id true");
1078                         __pSearchBar->SetShowState(false);
1079                         __pSearchBar->Invalidate(true);
1080                 }
1081
1082                 __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1083         }
1084
1085
1086         Invalidate(true);
1087 }
1088
1089 void
1090 BookmarkListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
1091 {
1092         if (__pData != null)
1093         {
1094                 __pData->RemoveAll(true);
1095                 delete __pData;
1096                 __pData = null;
1097         }
1098         __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
1099         return;
1100 }
1101