3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 /*@file: AddBookmarkForm.cpp
20 *@brief: This header file contains the definitions of the AddBookmarkForm class.
24 #include <FAppUiApp.h>
27 #include "IntAddBookmarkForm.h"
28 #include "IntBookmarkData.h"
29 #include "IntBookmarkPresentationModel.h"
30 #include "IntCommonLib.h"
31 #include "IntDropDownCustomItem.h"
32 #include "IntMultipleWindowPresentationModel.h"
33 #include "IntRadioCustomItem.h"
34 #include "IntSceneRegister.h"
36 using namespace Tizen::App;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Base::Utility;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Ui;
42 using namespace Tizen::Ui::Controls;
43 using namespace Tizen::Ui::Scenes;
45 static const int LIST_ITEM_HEIGHT = 112;
46 static const int H_ITEM_HEIGHT = 128;
47 static const int H_TITLE_ITEM_HEIGHT = 140;
48 static const wchar_t* IDB_LIST_LEFT_SIDE = L"ListLeftSide.png";
50 const int AddBookmarkForm::IDA_CREATE_BOOKMARK_FOLDER = 101;
51 const int AddBookmarkForm::IDA_BUTTON_DONE = 102;
52 const int AddBookmarkForm::IDA_BUTTON_CANCEL = 103;
53 const int AddBookmarkForm::IDA_LIST_LEFT_SIDE_MARGIN = 104;
54 const int AddBookmarkForm::IDA_LIST_LEFT_SIDE_MARGIN_DROPDOWN = 105;
56 AddBookmarkForm::AddBookmarkForm(void)
58 ,__folderName(CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS"))
59 ,__listHeight(H_TITLE_ITEM_HEIGHT)
62 , __pEditFieldTitle(null)
63 , __pEditFieldUrl(null)
66 , __previousScene(null)
67 , __pScrollPanel(null)
70 , __showFolderList(false)
71 ,__titleOnViewDeactivated(L"")
73 ,__urlOnViewDeactivated(L"")
79 AddBookmarkForm::~AddBookmarkForm(void)
81 // RemoveAllControls();
85 AddBookmarkForm::Initialize(void)
87 Construct(L"IDL_ADD_BOOKMARK");
93 AddBookmarkForm::OnInitializing(void)
96 Header* pHeader = null;
98 SceneManager* pSceneManager = SceneManager::GetInstance();
99 if (pSceneManager == null)
103 pSceneManager->AddSceneEventListener(IDSCN_ADD_BOOKMARK, *this);
105 pHeader = GetHeader();
109 pHeader->AddActionEventListener(*this);
112 // Main Panel which is a Scroll Panel
113 __pScrollPanel = static_cast< ScrollPanel* >(GetControl(L"IDC_SCROLLPANEL2"));
115 if (__pScrollPanel == null)
119 __pScrollPanel->SetPageScrollEnabled(true);
120 // Title EditField added on the Scroll Panel
121 __pEditFieldTitle = static_cast< EditField* >(__pScrollPanel->GetControl(L"IDC_EDITFIELD1"));
123 if (__pEditFieldTitle == null)
128 __pEditFieldTitle->SetGuideText(CommonUtil::GetString(L"IDS_BR_POP_ENTER_BOOKMARK_NAME"));
129 __pEditFieldTitle->AddTextEventListener(*this);
130 __pEditFieldTitle->AddKeypadEventListener(*this);
131 __pEditFieldTitle->SetOverlayKeypadCommandButtonVisible(false);
133 // Url Editfield added on the Scroll Panel
134 __pEditFieldUrl = static_cast< EditField* >(__pScrollPanel->GetControl(L"IDC_EDITFIELD2"));
136 if (__pEditFieldUrl == null)
141 __pEditFieldUrl->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
142 __pEditFieldUrl->AddTextEventListener(*this);
143 __pEditFieldUrl->AddKeypadEventListener(*this);
144 __pEditFieldUrl->AddFocusEventListener(*this);
145 __pEditFieldUrl->SetOverlayKeypadCommandButtonVisible(false);
147 __pList = static_cast< ListView* >(__pScrollPanel->GetControl(L"IDC_LISTVIEW1"));
153 __pList->SetItemProvider(*this);
154 __pList->AddListViewItemEventListener(*this);
155 AddOrientationEventListener(*this);
157 __pScrollPanel->SetSize(GetClientAreaBounds().width, GetClientAreaBounds().height);
158 r = __pScrollPanel->SetClientAreaHeight(__pList->GetY() + __listHeight);
159 ScrollPanelScrollDirection direction = __pScrollPanel->GetScrollDirection();
160 AppLogDebug("ScrollDirection = %d SetClientAreaHeight ret = %s value = %d autoresize = %d",direction,GetErrorMessage(r),__pScrollPanel->GetClientAreaBounds().height,__pScrollPanel->IsScrollAreaAutoResizingEnabled());
167 AddBookmarkForm::OnTerminating(void)
169 result r = E_SUCCESS;
174 AddBookmarkForm::OnActionPerformed(const Control& source, int actionId)
176 AppLog("AddBookmarkForm::OnActionPerformed entered actionId %d",actionId);
178 SceneManager* pSceneManager = SceneManager::GetInstance();
180 if (pSceneManager == null)
187 case IDA_CREATE_BOOKMARK_FOLDER:
189 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CREATE_BOOKMARK_FOLDER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
193 case IDA_BUTTON_DONE:
195 // Code to save the Bookmark
198 String bookMarkID = L"";
199 String folderTitle = L"";
200 ArrayList folderList;
209 String firstPattern(L"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
210 String secondPattern(L"^[A-Za-z0-9\.\+-:#@%/;$~?]+\\.[A-Za-z0-9\+-=:#@%/;$~()_?\\\.&]{2,}$"); // Url of type abc.com (i.e without protocol in front of it)
212 RegularExpression firstRegex;
213 RegularExpression secondRegex;
215 firstRegex.Construct(firstPattern, REGEX_CASELESS);
216 secondRegex.Construct(secondPattern, REGEX_CASELESS);
218 title = __pEditFieldTitle->GetText();
219 Url = __pEditFieldUrl->GetText();
222 ret = firstRegex.Match(Url, false); // This returns true value
223 flag = secondRegex.Match(Url, false); // Checks whether Url typed is of type abc.com (i.e without protocol in front of it)
231 String tempUrl = L"http://";
243 String msg = CommonUtil::GetString(L"IDS_BR_POP_INVALIDADDRESS");
248 if (__view == CommonUtil::GetString(L"IDS_BR_SK_EDIT"))
254 tempUrl = __pBookmark->GetUrl();
255 tempTitle = __pBookmark->GetBookmarkTitle();
256 tempParentId = __pBookmark->GetParentId();
260 r = BookmarkPresentationModel::GetInstance()->GetFolder("0", 0, __folderCount, folderList);
261 TryCatch(r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
263 for (count = 0; count < __folderCount; count++)
265 BookmarkData* pBookmark = null;
266 pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
267 if (pBookmark == NULL)
271 folderTitle = pBookmark->GetBookmarkTitle();
273 if (folderTitle == __folderName)
275 bookMarkID = pBookmark->GetBookmarkId();
280 if(bookMarkID.GetLength() == 0)
285 AppLog("IDA_BUTTON_DONE tempParentId ID is %S",tempParentId.GetPointer());
286 AppLog("IDA_BUTTON_DONE bookMarkID ID is %S",bookMarkID.GetPointer());
288 if (bookMarkID.CompareTo(tempParentId) == 0 && __pEditFieldUrl->GetText().CompareTo(tempUrl) == 0 && __pEditFieldTitle->GetText().CompareTo(tempTitle) == 0)
290 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
294 if(tempUrl != __pEditFieldUrl->GetText() || tempParentId != bookMarkID)
296 r = BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(Url,exist, bookMarkID, true);
297 TryCatch( r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
303 String msg = CommonUtil::GetString(L"IDS_BR_POP_BOOKMARK_ALREADY_EXISTS");
306 AppLogDebug("Bookmark already exists");
310 __pBookmark->SetUrl(Url);
311 __pBookmark->SetBookmarkTitle(title);
313 if (bookMarkID == L"")
315 __pBookmark->SetParentId(L"0");
319 __pBookmark->SetParentId(bookMarkID);
322 r = BookmarkPresentationModel::GetInstance()->SaveTempBookmark(*__pBookmark);
323 AppLogDebug("ID_BUTTON_DONE SaveBookmark = %s", GetErrorMessage(r));
324 AppLogDebug("parent id = %ls",__pBookmark->GetParentId().GetPointer());
325 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
330 AppLog("AddBookmarkForm::OnActionPerformed does url exist 1");
332 r = BookmarkPresentationModel::GetInstance()->GetFolder(L"0", 0, __folderCount, folderList);
333 TryCatch(r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
335 for (count = 0; count < __folderCount; count++)
337 BookmarkData* pBookmark = null;
338 pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
339 if (pBookmark == NULL)
343 folderTitle = pBookmark->GetBookmarkTitle();
345 if (folderTitle == __folderName)
347 bookMarkID = pBookmark->GetBookmarkId();
351 if(bookMarkID.GetLength() == 0)
355 r = BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(Url,exist, bookMarkID, true);
357 TryCatch( r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
358 AppLog("AddBookmarkForm::OnActionPerformed does url exist 2");
361 String msg = CommonUtil::GetString(L"IDS_BR_POP_BOOKMARK_ALREADY_EXISTS");
364 AppLogDebug("Bookmark already exists");
368 r = BookmarkPresentationModel::GetInstance()->GetFolder("0", 0, __folderCount, folderList);
369 TryCatch( r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
371 for (count = 0; count < __folderCount; count++)
373 BookmarkData* pBookmark = null;
374 pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
375 if ( pBookmark == NULL )
379 folderTitle = pBookmark->GetBookmarkTitle();
381 if (folderTitle == __folderName)
383 bookMarkID = pBookmark->GetBookmarkId();
387 BookmarkData bookmark;
389 if (__folderName != CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS"))
391 bookmark.SetParentId(bookMarkID);
394 bookmark.SetBookmarkTitle(title);
395 bookmark.SetUrl(Url);
396 if (__pBookmark != null)
398 bookmark.SetFaviconId(__pBookmark->GetFaviconId());
400 BookmarkPresentationModel::GetInstance()->SaveTempBookmark(bookmark);
401 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
406 folderList.RemoveAll(true);
410 case IDA_BUTTON_CANCEL:
412 if (__pEditFieldTitle != NULL)
414 __pEditFieldTitle->Clear();
417 if (__pEditFieldUrl != NULL)
419 __pEditFieldUrl->Clear();
422 pSceneManager->GoBackward(BackwardSceneTransition());
435 AddBookmarkForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
441 AddBookmarkForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
443 if (__pEditFieldTitle != NULL)
445 __pEditFieldTitle->HideKeypad();
448 if (__pEditFieldUrl != NULL)
450 __pEditFieldUrl->HideKeypad();
454 if (__showFolderList == false)
456 AppLog("AddBookmarkForm::OnListViewItemStateChanged false");
457 __showFolderList = true;
458 __pList->UpdateList();
459 __listHeight = H_TITLE_ITEM_HEIGHT + (__pList->GetItemCount() -1) * H_ITEM_HEIGHT;
464 AppLog("AddBookmarkForm::OnListViewItemStateChanged true");
465 __showFolderList = false;
466 __pList->UpdateList();
467 __listHeight = H_TITLE_ITEM_HEIGHT + (__pList->GetItemCount() - 1) * H_ITEM_HEIGHT;
474 __selectedIndex = index;
475 if (index > 1 && __pList->GetItemCount() != index +1)
477 String parentID = "0";
478 ArrayList folderList;
479 BookmarkData* pBookmark = null;
480 BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, __folderCount, folderList);
482 pBookmark = static_cast<BookmarkData*>(folderList.GetAt(index-2));
483 __folderName = pBookmark->GetBookmarkTitle();
487 __folderName = CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS") ;
489 __listHeight = H_TITLE_ITEM_HEIGHT + (__pList->GetItemCount()-1) * H_ITEM_HEIGHT;
490 if (__pList->GetItemCount() == index +1)
492 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_CREATE_BOOKMARK_FOLDER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
496 __pList->UpdateList();
497 // __pList->RefreshList(0, LIST_REFRESH_TYPE_ITEM_MODIFY);
501 result r = __pList->SetBounds(Rectangle(__pList->GetX(), __pList->GetY(), __pList->GetWidth(), __listHeight));
502 //__pList->Invalidate(true);
504 AppLog("the result is %s", GetErrorMessage(r));
505 AppLog("the list height is %d", __pList->GetHeight());
510 AddBookmarkForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
512 __pList->RefreshList(0, LIST_REFRESH_TYPE_ITEM_MODIFY);
517 AddBookmarkForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
523 AddBookmarkForm::GetItemCount(void)
525 AppLogDebug("AddBookmarkForm::GetItemCount");
527 ArrayList folderList;
528 String parentID = "0";
529 BookmarkData* pBookmark = null;
530 BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, __folderCount, folderList);
532 if (__selectedIndex == 0 && __view == CommonUtil::GetString(L"IDS_BR_SK_EDIT"))
534 for(int count = 0; count < __folderCount; count++)
536 pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
538 if (__pBookmark != null && pBookmark != NULL && __pBookmark->GetParentId() == pBookmark->GetBookmarkId())
540 __selectedIndex = count + 2;
541 __folderName = pBookmark->GetBookmarkTitle();
551 folderList.RemoveAll(true);
553 if (__showFolderList == false)
559 result r = BookmarkPresentationModel::GetInstance()->GetFolderCount(L"0",count);
560 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetBookmarkCount query failed %s",GetErrorMessage(r));
561 AppLog("count = %d", count);
570 AddBookmarkForm::CreateItem(int index, int itemWidth)
572 AppLog("AddBookmarkForm::CreateItem index = %d itemWidth %d list width = %d",index,itemWidth,__pList->GetWidth());
573 result r = E_FAILURE;
574 String folderTitle = L"";
575 RadioCustomItem* radioItem = null;
576 DropDownCustomItem* pItem = null;
577 Bitmap* pBitmap = null;
578 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_LIST_LEFT_SIDE);
581 itemWidth = __pList->GetWidth();
585 pItem = new(std::nothrow) DropDownCustomItem();
586 r = pItem->Construct(itemWidth);
590 AppLog("Create Item Failed with error %s", GetErrorMessage(r));
596 if ( __showFolderList == true )
598 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
602 pItem->SetCurState(DROP_DOWN__ITEM_STATE_CLOSED);
605 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
606 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
607 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
608 pItem->SetMainText(CommonUtil::GetString(L"IDS_BR_BODY_FOLDER"));
609 pItem->SetSubText(__folderName);
613 //pItem->AddElement(Rectangle(0, 0, 10, H_ITEM_HEIGHT), IDA_LIST_LEFT_SIDE_MARGIN_DROPDOWN, *pBitmap, null);
620 String parentID = "0";
621 ArrayList folderList;
623 BookmarkData* pBookmark = null;
624 r = BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, __folderCount, folderList);
628 radioItem = new(std::nothrow) RadioCustomItem();
629 // r = radioItem->Construct(GetClientAreaBounds().width, LIST_ITEM_HEIGHT);
630 r = radioItem->Construct(itemWidth, LIST_ITEM_HEIGHT);
633 AppLog("Create Item Failed with error %s", GetErrorMessage(r));
638 radioItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
639 radioItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
640 radioItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
641 folderTitle = CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS") ;
642 radioItem->SetText(folderTitle);
644 else if (index <= __folderCount + 1)
646 pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(index - 2));
647 if (pBookmark != null)
649 folderTitle = pBookmark->GetBookmarkTitle();
651 radioItem = new(std::nothrow) RadioCustomItem();
652 // r = radioItem->Construct(GetClientAreaBounds().width, LIST_ITEM_HEIGHT);
653 r = radioItem->Construct(itemWidth, LIST_ITEM_HEIGHT);
656 AppLog("Create Item Failed with error %s", GetErrorMessage(r));
662 radioItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
663 radioItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
664 radioItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
665 radioItem->SetText(folderTitle);
669 radioItem = new(std::nothrow) RadioCustomItem();
670 // r = radioItem->Construct(GetClientAreaBounds().width, LIST_ITEM_HEIGHT);
671 r = radioItem->Construct(itemWidth, LIST_ITEM_HEIGHT);
674 AppLog("Create Item Failed with error %s", GetErrorMessage(r));
679 //radioItem->AddElement(Rectangle(MARGIN_X, 0, __pList->GetBounds().width, LIST_ITEM_HEIGHT), IDA_FORMAT_STRING1, CommonUtil::GetString(L"IDS_CREATE_NEW_FOLDER"), textsize, Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), true);
680 folderTitle = CommonUtil::GetString(L"IDS_BR_OPT_NEW_FOLDER");
681 radioItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
682 radioItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
683 radioItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND);
684 radioItem->SetText(folderTitle);
688 if (__selectedIndex == index)
690 radioItem->SetSelected(true);
694 radioItem->SetSelected(false);
697 if(__selectedIndex == 0 && index == 1)
698 radioItem->SetSelected(true);
699 if (radioItem->GetSelected() == true)
701 __folderName = radioItem->GetText();
706 //radioItem->AddElement(Rectangle(0, 0, 10, LIST_ITEM_HEIGHT), IDA_LIST_LEFT_SIDE_MARGIN, *pBitmap, null);
710 folderList.RemoveAll(true);
717 AddBookmarkForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
729 AddBookmarkForm::OnKeypadActionPerformed(Control& source, KeypadAction keypadAction)
735 AddBookmarkForm::OnKeypadClosed(Control& source)
738 AppLog("the client area height is %d",GetClientAreaBounds().height);
740 __pScrollPanel->SetBounds(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
741 __pScrollPanel->Invalidate(true);
748 AddBookmarkForm::OnKeypadOpened(Control& source)
754 AddBookmarkForm::OnKeypadWillOpen(Control& source)
756 AppLog("the client area height is %d",GetClientAreaBounds().height);
758 // __pScrollPanel->SetBounds(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
760 // __pScrollPanel->Invalidate(true);
761 // __pScrollPanel->SetScrollPosition(source.GetY()-48,false);
762 __pScrollPanel->SetSize(GetClientAreaBounds().width,GetClientAreaBounds().height);
763 __pScrollPanel->SetClientAreaWidth(__pScrollPanel->GetWidth());
764 __pScrollPanel->SetClientAreaHeight(__pList->GetY()+__listHeight);
766 AppLog("the scroll panel height is Rect(%d,%d,%d,%d) ClientHeight = %d",__pScrollPanel->GetX(),__pScrollPanel->GetY(),__pScrollPanel->GetWidth(),__pScrollPanel->GetHeight(),__pScrollPanel->GetClientAreaBounds().height);
771 AddBookmarkForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
773 // Code to handle events when the AddBookmarkForm is activated.
775 String pageTitle = L"";
776 String pageUrl = L"";
779 result r = E_FAILURE;
780 Header* pHeader = GetHeader();
782 r = BookmarkPresentationModel::GetInstance()->GetFolderCount(str, __folderCount);
783 TryCatch( r == E_SUCCESS, ,"Failed to intitialize GETFOLDERCOUNT %s",GetErrorMessage(r));
785 if ( pHeader == NULL )
789 if ( previousSceneId != IDSCN_CREATE_BOOKMARK_FOLDER )
791 // check first argument of pargs 0 for Add, 1 - for Edit
792 String* firstValue = NULL;
795 firstValue = dynamic_cast<String*>(pArgs->GetAt(0));
798 if( firstValue == NULL || pArgs == NULL)
802 if (firstValue->CompareTo(L"1") == 0)
804 __view = CommonUtil::GetString(L"IDS_BR_SK_EDIT");
806 pHeader->SetTitleText(CommonUtil::GetString(L"IDS_BR_HEADER_EDIT_BOOKMARK"));
808 if (__pBookmark != NULL && pArgs != NULL)
814 if (__pBookmark == NULL && pArgs != NULL)
816 __pBookmark = dynamic_cast<BookmarkData*>(pArgs->GetAt(1));
821 pageTitle = __pBookmark->GetBookmarkTitle();
822 pageUrl = __pBookmark->GetUrl();
825 else if (firstValue->CompareTo(L"0") == 0)
827 __view = CommonUtil::GetString(L"IDS_COM_SK_ADD");
828 pHeader->SetTitleText(CommonUtil::GetString(L"IDS_BR_HEADER_EDIT_BOOKMARK"));
830 WindowInfo* pWindowInfo = MultipleWindowPresentationModel::GetInstance()->GetActiveWindowInfo();
832 if( pWindowInfo == NULL )
837 if(pWindowInfo->pageTitle.CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_ABOUT_C_BLANK")) != 0)
838 pageTitle = pWindowInfo->pageTitle;
840 if(pWindowInfo->pageUrl.IsEmpty() == false)
842 pageUrl = pWindowInfo->pageUrl;
844 String* parentID = dynamic_cast<String*>(pArgs->GetAt(1));
846 ArrayList folderList;
848 BookmarkData* pBookmark = null;
849 BookmarkPresentationModel::GetInstance()->GetFolder(L"0", 0, __folderCount, folderList);
850 for(int count = 0; count < folderList.GetCount(); count++)
852 pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
854 if ( pBookmark == null )
859 if (parentID != NULL && pBookmark->GetBookmarkId().CompareTo(parentID->GetPointer()) == 0)
861 __selectedIndex = count + 2;
862 __folderName = pBookmark->GetBookmarkTitle();
867 __selectedIndex = 1 ;
868 __folderName = CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS") ;
873 if (__folderCount == 0)
875 __selectedIndex = 1 ;
876 __folderName = CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS") ;
879 folderList.RemoveAll(true);
883 if ( previousSceneId == IDSCN_CREATE_BOOKMARK_FOLDER )
885 pageTitle = __titleOnViewDeactivated;
886 pageUrl = __urlOnViewDeactivated;
887 if(__pList && __pScrollPanel)
889 AppLog("__pList->GetItemCount() %d",__pList->GetItemCount());
890 __pList->ScrollToItem(__pList->GetItemCount());
891 // __pList->Invalidate(true);
892 __pScrollPanel->ScrollToBottom();
896 if(__pEditFieldTitle != NULL)
898 __pEditFieldTitle->ShowKeypad();
900 if ( previousSceneId != IDSCN_CREATE_BOOKMARK_FOLDER )
902 if (__pEditFieldTitle != NULL)
904 __pEditFieldTitle->SetText(pageTitle);
905 __pEditFieldTitle->ShowKeypad();
907 if (__pEditFieldUrl != NULL)
909 __pEditFieldUrl->SetText(pageUrl);
910 __pEditFieldUrl->HideKeypad();
916 if (__pEditFieldTitle != NULL)
918 __pEditFieldTitle->SetText(pageTitle);
919 __pEditFieldTitle->HideKeypad();
921 if (__pEditFieldUrl != NULL)
923 __pEditFieldUrl->SetText(pageUrl);
924 __pEditFieldUrl->HideKeypad();
927 if (__view == CommonUtil::GetString(L"IDS_BR_SK_EDIT") && previousSceneId == IDSCN_CREATE_BOOKMARK_FOLDER )
929 if (__oldFolderCount == 0)
931 if (__folderCount == 1)
936 else if (__oldFolderCount != __folderCount)
938 __selectedIndex = __folderCount + 1;
944 if (__view == CommonUtil::GetString(L"IDS_COM_SK_ADD") && previousSceneId == IDSCN_CREATE_BOOKMARK_FOLDER)
947 if (__oldFolderCount == 0)
949 if (__folderCount == 1)
954 else if (__oldFolderCount != __folderCount)
956 __selectedIndex = __folderCount + 1;
959 else if (__oldFolderCount == __folderCount )
961 __selectedIndex = __folderCount + 1;
963 if(__selectedIndex > 1)
965 String parentID = L"0";
966 ArrayList folderList;
967 BookmarkData* pBookmark = null;
968 BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, __folderCount, folderList);
969 pBookmark = static_cast<BookmarkData*>(folderList.GetAt(__selectedIndex-2));
970 if(pBookmark != null)
972 __folderName = pBookmark->GetBookmarkTitle();
976 if (__pEditFieldTitle != NULL)
978 title = __pEditFieldTitle->GetText();
982 if (__pEditFieldUrl != NULL)
984 url = __pEditFieldUrl->GetText();
988 // To disable done button if either of the Title or Url field is empty
989 if (title.GetLength() == 0 || url.GetLength() == 0)
991 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
992 pHeader->Invalidate(true);
996 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
997 pHeader->Invalidate(true);
1003 __pList->UpdateList();
1004 __listHeight = H_TITLE_ITEM_HEIGHT + (__pList->GetItemCount() - 1) * H_ITEM_HEIGHT;
1005 __pList->SetBounds(__pList->GetX(),__pList->GetY(),__pList->GetWidth(),__listHeight);
1009 // __pList->RefreshList(0, LIST_REFRESH_TYPE_ITEM_MODIFY);
1014 AddBookmarkForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
1016 // Add code to handle events when the AddBookmarkForm is Deactivated.
1017 if ( __pEditFieldTitle != NULL)
1019 __titleOnViewDeactivated = __pEditFieldTitle->GetText();
1022 if ( __pEditFieldUrl != NULL)
1024 __urlOnViewDeactivated = __pEditFieldUrl->GetText();
1027 __oldFolderCount = __folderCount;
1029 if (__view == CommonUtil::GetString(L"IDS_BR_SK_EDIT") )
1031 __selectedIndex = 0;
1037 AddBookmarkForm::OnFocusGained (const Tizen::Ui::Control &source)
1039 __pScrollPanel->SetSize(GetClientAreaBounds().width,GetClientAreaBounds().height);
1040 __pScrollPanel->SetClientAreaWidth(__pScrollPanel->GetWidth());
1041 __pScrollPanel->SetClientAreaHeight(GetClientAreaBounds().height);
1047 AddBookmarkForm::OnFocusLost (const Tizen::Ui::Control &source)
1053 AddBookmarkForm::OnTextValueChanged(const Control& source)
1057 Header* pHeader = GetHeader();
1058 if (pHeader == NULL)
1063 if (__pEditFieldTitle == NULL || __pEditFieldUrl == NULL)
1068 title = __pEditFieldTitle->GetText();
1069 url = __pEditFieldUrl->GetText();
1073 // To disable done button if either of the Title or Url field is empty
1074 if (title.GetLength() == 0 || url.GetLength() == 0)
1076 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
1077 pHeader->Invalidate(true);
1081 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
1082 pHeader->Invalidate(true);
1089 AddBookmarkForm::OnTextValueChangeCanceled(const Control& source)
1095 AddBookmarkForm::CreateMessage(String& str)
1097 Tizen::Ui::Controls::MessageBox* pMsgBox = null; // Message Box to display alert if folder with same name already exists
1098 int __modalMsgBoxResult;
1100 pMsgBox = new(std::nothrow) MessageBox;
1101 if (pMsgBox != null)
1103 pMsgBox->Construct(str, L"", MSGBOX_STYLE_OK, 3000);
1104 pMsgBox->ShowAndWait(__modalMsgBoxResult);
1107 __modalMsgBoxResult = 0;
1114 AddBookmarkForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1116 // if (__pEditFieldTitle != NULL)
1118 // __pEditFieldTitle->HideKeypad();
1120 // if (__pEditFieldUrl != NULL)
1122 // __pEditFieldUrl->HideKeypad();
1125 if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE)
1127 if (__pScrollPanel != null)
1129 __pScrollPanel->ScrollToTop();
1130 __pScrollPanel->SetClientAreaHeight(__pList->GetY()+__listHeight);
1134 if (__pList != null)
1136 __pList->SetBounds(__pList->GetX(),__pList->GetY(),__pList->GetWidth(),__listHeight);
1137 __pList->UpdateList();