Favicon issue
[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                 if (pBitmap == null)
633                 {
634                         AppLogDebug("BookmarkListForm::CreateItem bitmap is null");
635                         pBitmap = FaviconManager::GetInstance()->GetDefaultFaviconN();
636                 }
637                 pItem->AddElement(Rectangle(x_Margin_Icon, y_Margin_Icon, width_Icon, height_Icon), IDA_FORMAT_ICON, *pBitmap, null);
638                 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);
639                 if(__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
640                         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);
641                 else
642                         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);
643
644                 if (pBitmap != null)
645                 {
646                         delete pBitmap;
647                 }
648                 if ( __pItemContextSite != NULL)
649                 {
650                         pItem->SetContextItem(__pItemContextSite);
651                 }
652         }
653
654         return pItem;
655
656         CATCH:
657         delete pItem;
658         pItem = null;
659         return null;
660
661 }
662
663 bool
664 BookmarkListForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
665 {
666         delete pItem;
667         pItem = null;
668         return true;
669 }
670
671 int
672 BookmarkListForm::GetItemCount(void)
673 {
674         int count = 0;
675
676         if (__pData != NULL )
677         {
678                 __pData->RemoveAll(true);
679                 delete __pData;
680                 __pData = null;
681         }
682         __pData = new(std::nothrow) Collection::ArrayList();
683         __pData->Construct();
684
685         if (__searchBookmark == false)
686         {
687                 BookmarkPresentationModel::GetInstance()->GetFolderBookmarkCount(__parentID, count);
688                 BookmarkPresentationModel::GetInstance()->GetFoldersBookmarks(__parentID, 0, count, *__pData);
689         }
690         else
691         {
692                 BookmarkPresentationModel::GetInstance()->GetSearchFolderBookmarkCount(count,__searchText);
693                 BookmarkPresentationModel::GetInstance()->GetSearchFoldersBookmarks(0, count, *__pData, __searchText);
694         }
695
696         AppLogDebug("Count = %d parentId = %ls", count, __parentID.GetPointer());
697
698         if (count <= 0)
699         {
700                 __noBookmarks = true;
701                 GetFooter()->SetItemEnabled(1,false);
702         }
703         else
704         {
705                 __noBookmarks = false;
706                 GetFooter()->SetItemEnabled(1,true);
707         }
708
709         AppLogDebug("Result: %s", GetErrorMessage(GetLastResult()));
710         GetFooter()->Invalidate(true);
711         if (__pData != null && __pData->GetCount() >= 1)
712         {
713                 //              __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
714                 __pSearchBar->SetShowState(true);
715                 __pSearchBar->Invalidate(true);
716         }
717         else if (__searchBookmark == false)
718         {
719                 __pSearchBar->SetShowState(false);
720                 __pSearchBar->Invalidate(true);
721         }
722
723         if (__parentID.CompareTo(L"-1") != 0)
724         {
725                 __pSearchBar->SetShowState(false);
726                 __pSearchBar->Invalidate(true);
727         }
728         if (__noBookmarks == true)
729         {
730                 __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetPosition().y,__pSearchBar->GetWidth() ,GetClientAreaBounds().height);
731                 Bitmap* pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_NO_CONTENT_BOOKMARK);
732
733                 if ( pBitmap != NULL)
734                 {
735                         __pListview->SetBitmapOfEmptyList(pBitmap);
736                         delete pBitmap;
737                 }
738         }
739         else
740         {
741                 if (__parentID.CompareTo(L"-1") == 0)
742                 {
743                         __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetHeight(),GetClientAreaBounds().width ,GetClientAreaBounds().height - __pSearchBar->GetY() - __pSearchBar->GetHeight());
744                 }
745                 else
746                 {
747                         __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetY(),__pSearchBar->GetWidth() ,GetClientAreaBounds().height);
748
749                 }
750
751         }
752         __pListview->Invalidate(true);
753         return count;
754
755 }
756
757 void
758 BookmarkListForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus status)
759 {
760         AppLogDebug("BookmarkListForm::OnListViewContextItemStateChanged int index %d, int elementId %d, Tizen::Ui::Controls::ListContextItemStatus status %d",index,elementId,status);
761
762         String deleteText = CommonUtil::GetString(L"IDS_BR_SK_DELETE_ABB");
763         deleteText.Append(L"? ");
764         int timeOut = 25000;
765         result r = E_SUCCESS;
766
767         switch(elementId)
768         {
769         case IDA_CONTEXT_ITEM_FOLDER_EDIT:
770         {
771                 ArrayList* pArgList = null;
772                 String* pEdit = null;
773
774                 SceneManager* pSceneManager = SceneManager::GetInstance();
775                 BookmarkData* pBookMark = dynamic_cast< BookmarkData* >(__pData->GetAt(index));
776                 if (pBookMark != null && pBookMark->GetBookmarkType() == BOOKMARK_TYPE_FOLDER)
777                 {
778                         pArgList = new(std::nothrow) ArrayList();
779                         if (pArgList != null)
780                         {
781                                 pEdit= new(std::nothrow) String(CommonUtil::GetString(L"IDS_BR_HEADER_EDIT_FOLDER"));
782                                 pArgList->Construct();
783                                 pArgList->Add(*new(std::nothrow) BookmarkData(*pBookMark));
784                                 pArgList->Add(*pEdit);
785                                 if (    pSceneManager != null)
786                                 {
787                                         result r;
788                                         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CREATE_BOOKMARK_FOLDER), pArgList);
789                                 }
790
791                                 if (pArgList != null)
792                                 {
793                                         delete pArgList;
794                                         pArgList = null;
795                                 }
796                                 if(IsFailed(r))
797                                 {
798                                         AppLogDebug("BookmarkListForm::OnListViewContextItemStateChanged GoForward failed %s",GetErrorMessage(r));
799                                         return;
800                                 }
801                         }
802                 }
803
804         }
805         break;
806
807         case IDA_CONTEXT_ITEM_FOLDER_DELETE:
808         case IDA_CONTEXT_ITEM_DELETE:
809         {
810                 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
811                 __pConfirmationPopup->Initialize();
812                 __pConfirmationPopup->RemoveActionListener(*this);
813                 __pConfirmationPopup->AddActionListener(*this);
814                 __pConfirmationPopup->setMessage(deleteText);
815                 __pConfirmationPopup->Show();
816                 __selectedindex = index;
817         }
818         break;
819
820         case IDA_CONTEXT_ITEM_EDIT:
821         {
822                 ArrayList* pArgList = null;
823                 SceneManager* pSceneManager = SceneManager::GetInstance();
824                 BookmarkData* pBookMark = dynamic_cast< BookmarkData* >(__pData->GetAt(index));
825                 if (pBookMark!= null && pBookMark->GetBookmarkType() == BOOKMARK_TYPE_URL)
826                 {
827                         AppLogDebug("ID_CONTEXT_ITEM_SITE_1 BOOKMARK_TYPE_URL");
828                         pArgList = new(std::nothrow) ArrayList();
829                         if (pArgList != null)
830                         {
831                                 pArgList->Construct();
832                                 pArgList->Add(*new(std::nothrow) String(L"1"));
833                                 pArgList->Add(*new(std::nothrow) BookmarkData(*pBookMark));
834                                 if (    pSceneManager != null)
835                                 {
836                                         result r;
837                                         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ADD_BOOKMARK), pArgList);
838                                         if (pArgList != null)
839                                         {
840                                                 delete pArgList;
841                                                 pArgList = null;
842                                         }
843                                         if(IsFailed(r))
844                                         {
845                                                 AppLogDebug("BookmarkListForm::OnListViewContextItemStateChanged GoForward failed %s",GetErrorMessage(r));
846                                                 return;
847                                         }
848                                 }
849                         }
850                 }
851         }
852         break;
853         case IDA_CONTEXT_ITEM_SHARE:
854         {
855                 AppLogDebug("OnListViewContextItemStateChanged Share");
856
857                 BookmarkData* pBookmark = dynamic_cast<BookmarkData*>(__pData->GetAt(index));
858                 if (pBookmark != null)
859                 {
860                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
861                         pShareInfo->SetPageTitle(pBookmark->GetBookmarkTitle());
862                         pShareInfo->SetPageUrl(pBookmark->GetUrl());
863                         pShareInfo->SetImageAttached(false);
864                         __pPopUp->RemoveAllShareInfo();
865                         __pPopUp->AddShareInfo(pShareInfo);
866                 }
867
868                 if (__pPopUp != null)
869                 {
870                         __pPopUp->SetShowState(true);
871                         __pPopUp->Show();
872                 }
873         }
874         break;
875         default:
876                 break;
877         }
878
879 }
880
881 void
882 BookmarkListForm::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
883 {
884
885 }
886
887 void
888 BookmarkListForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
889 {
890         AppLogDebug("BookmarkListForm::OnListViewItemStateChanged");
891
892         result r = E_FAILURE;
893         ArrayList *pArgList = null;
894         SceneManager* pSceneManager = SceneManager::GetInstance();
895         BookmarkData* pBookmark = dynamic_cast< BookmarkData* >(__pData->GetAt(index));
896
897         if ( pBookmark == NULL )
898         {
899                 return;
900         }
901
902         switch (pBookmark->GetBookmarkType())
903         {
904         case BOOKMARK_TYPE_FOLDER:
905
906                 __parentID = pBookmark->GetBookmarkId();
907                 AppLogDebug("BOOKMARK_TYPE_FOLDER parent ID is %ls",__parentID.GetPointer());
908
909                 listView.UpdateList();
910                 if (listView.GetItemCount() == 0)
911                 {
912                         GetFooter()->SetItemEnabled(1,false);
913                 }
914                 else
915                 {
916                         GetFooter()->SetItemEnabled(1,true);
917                 }
918                 GetFooter()->SetItemEnabled(2,false);
919                 GetFooter()->Invalidate(true);
920                 __pSearchBar->HideKeypad();
921                 __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
922                 __pSearchBar->SetShowState(false);
923                 __pSearchBar->Invalidate(true);
924                 __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetY(),__pListview->GetWidth() ,GetClientAreaBounds().height);
925                 break;
926
927         case BOOKMARK_TYPE_URL:
928
929                 pArgList = new(std::nothrow) ArrayList();
930                 if (pArgList != null)
931                 {
932                         r = pArgList->Construct();
933                         TryCatch(!IsFailed(r), L"BookmarkListForm::OnListViewItemStateChanged pArgList Construct failed %s", GetErrorMessage(r));
934
935                         AppLogDebug("bookmark url = %ls",pBookmark->GetUrl().GetPointer());
936                         r = pArgList->Add(*MultipleWindowPresentationModel::GetInstance()->GetActiveWindowInfo());
937                         pArgList->Add(*new(std::nothrow) String(pBookmark->GetUrl()));
938
939                         if (pSceneManager != null)
940                         {
941                                 AppLogDebug("pSceneManager exists");
942                                 String prevSceneId;
943                                 MultipleWindowPresentationModel::GetInstance()->GetCurrentSceneId(prevSceneId);
944                                 r = pSceneManager->GoBackward(BackwardSceneTransition(prevSceneId), pArgList);
945                                 TryCatch(!IsFailed(r), L"BookmarkListForm::OnListViewItemStateChanged pArgList Construct failed %s", GetErrorMessage(r));
946                         }
947                         delete pArgList;
948                 }
949                 break;
950
951         default:
952                 break;
953         }
954
955         return;
956         CATCH:
957         if(pArgList)
958         {
959                 pArgList->RemoveAll(true);
960                 delete pArgList;
961         }
962
963 }
964
965 void
966 BookmarkListForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
967 {
968
969
970 }
971
972 void
973 BookmarkListForm::OnFastScrollIndexSelected(Tizen::Ui::Control& source, Tizen::Base::String& index)
974 {
975
976 }
977
978 void
979 BookmarkListForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
980 {
981         result r = E_FAILURE;
982
983         if (mode == SEARCH_BAR_MODE_NORMAL)
984         {
985                 __pSearchListView->SetShowState(false);
986                 __pSearchListView->UpdateList();
987                 __pListview->SetShowState(true);
988                 Invalidate(true);
989                 __searchBookmark = false;
990                 r = __pListview->UpdateList();
991                 __pSearchListView->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height -__pSearchBar->GetHeight());
992                 __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
993                 TryCatch( !IsFailed(r),,"BookmarkListForm::OnSearchBarModeChanged Update list failed %s",GetErrorMessage(r));
994                 CATCH:return;
995         }
996         else
997         {
998                 __pSearchListView->SetShowState(true);
999                 __pSearchListView->SetEnabled(false);
1000                 __pListview->SetShowState(false);
1001
1002                 if(__pSearchBar)
1003                 {
1004                         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1005                         __pSearchBar->SetText(L"");
1006                 }
1007                 AppLog("OnSearchBarModeChanged SetContentAreaSize heihgt %d",__pSearchListView->GetHeight());
1008                  __pListview->UpdateList();
1009                 __pSearchListView->UpdateList();
1010         }
1011 }
1012
1013 void
1014 BookmarkListForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
1015 {
1016         GetFooter()->SetShowState(false);
1017         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), __pSearchListView->GetHeight() + GetFooter()->GetHeight());
1018         __pSearchListView->SetEnabled(false);
1019         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1020         Invalidate(true);
1021         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), __pSearchListView->GetHeight() - GetFooter()->GetHeight());
1022 }
1023
1024 void
1025 BookmarkListForm::OnKeypadOpened(Tizen::Ui::Control& source)
1026 {
1027
1028         __pSearchListView->UpdateList();
1029 }
1030
1031 void
1032 BookmarkListForm::OnKeypadClosed(Tizen::Ui::Control& source)
1033 {
1034
1035         GetFooter()->SetShowState(true);
1036         GetFooter()->Invalidate(true);
1037         __pSearchListView->SetBounds(__pSearchListView->GetX(), __pSearchListView->GetY(), __pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight());
1038         __pListview->SetBounds(__pSearchListView->GetX(), __pSearchBar->GetY() + __pSearchBar->GetHeight(), __pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight());
1039         __pSearchListView->Invalidate(false);
1040         __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight()));
1041         Invalidate(true);
1042 }
1043
1044 void
1045 BookmarkListForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
1046 {
1047         AppLog("BookmarkListForm::OnKeypadActionPerformed %d",keypadAction);
1048
1049         if (__pSearchBar != null)
1050         {
1051                 __pSearchBar->HideKeypad();
1052         }
1053
1054         if ( __pSearchBar != null && keypadAction == KEYPAD_ACTION_SEARCH)
1055         {
1056                 if (__pSearchBar->GetText().GetLength() == 0)
1057                 {
1058                         return;
1059                 }
1060
1061                 __searchText = __pSearchBar->GetText();
1062                 __searchBookmark = true;
1063                 __pListview->SetShowState(false);
1064                 __pSearchListView->SetEnabled(true);
1065                 __pSearchListView->SetShowState(true);
1066                 __pSearchListView->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height -__pSearchBar->GetHeight());
1067                 __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), __pSearchListView->GetHeight()));
1068                 __pSearchListView->UpdateList();
1069
1070         }
1071         Invalidate(true);
1072 }
1073
1074 void
1075 BookmarkListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
1076 {
1077         AppLogDebug("BookmarkListForm::OnSceneActivatedN called");
1078
1079         __searchBookmark = false;
1080         GetFooter()->SetShowState(true);
1081         GetFooter()->Invalidate(true);
1082         GetHeader()->SetItemSelected(0);
1083         GetHeader()->Invalidate(true);
1084
1085         /*      if (previousSceneId != IDSCN_HISTORY_LIST && previousSceneId != IDSCN_CREATE_BOOKMARK_FOLDER && previousSceneId != IDSCN_EDIT_BOOKMARK_LIST)
1086         {
1087                 __previousSceneId = previousSceneId;
1088         }*/
1089
1090         if (__pListview != null)
1091         {
1092                 __pListview->UpdateList();
1093         }
1094
1095         return;
1096 }
1097
1098 void
1099 BookmarkListForm::OnOrientationChanged (const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
1100 {
1101         AppLog("BookmarkListForm::OnOrientationChanged start");
1102
1103         if (__pListview)
1104         {
1105                 if(__pSearchBar->GetShowState())
1106                 {
1107                         __pListview->SetBounds(__pListview->GetX(),__pSearchBar->GetHeight(),GetClientAreaBounds().width ,GetClientAreaBounds().height - __pSearchBar->GetY() - __pSearchBar->GetHeight());
1108                 }
1109                 else
1110                 {
1111                         __pListview->SetBounds(__pListview->GetX(),0,GetClientAreaBounds().width ,GetClientAreaBounds().height);
1112                 }
1113                 __pListview->UpdateList();
1114         }
1115
1116         if (__pSearchListView && __pListview)
1117         {
1118                 AppLog("__pListview->GetBounds() %d, %d, %d, %d",__pListview->GetBounds().x,__pListview->GetBounds().y,__pListview->GetBounds().width,__pListview->GetBounds().height);
1119                 __pSearchListView->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height -__pSearchBar->GetHeight());
1120
1121                 __pSearchListView->UpdateList();
1122         }
1123
1124         if (__pSearchListView && __pData != null )
1125         {
1126                 if (__parentID != DEFAULT_VALUE_PARENTID)
1127                 {
1128                         AppLog("BookmarkListForm::OnOrientationChanged parent id true");
1129                         __pSearchBar->SetShowState(false);
1130                         __pSearchBar->Invalidate(true);
1131                 }
1132
1133                 __pSearchBar->SetContentAreaSize(Dimension(__pSearchListView->GetWidth(), GetClientAreaBounds().width));
1134         }
1135
1136
1137         Invalidate(true);
1138 }
1139
1140 void
1141 BookmarkListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
1142 {
1143         if (__pData != null)
1144         {
1145                 __pData->RemoveAll(true);
1146                 delete __pData;
1147                 __pData = null;
1148         }
1149         __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
1150         return;
1151 }
1152