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