Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntAddBookmarkForm.cpp
1 //
2
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 // !Internet
19 /*@file:    AddBookmarkForm.cpp
20  *@brief:       This header file contains the definitions of the AddBookmarkForm class.
21  *
22  */
23
24 #include <FAppUiApp.h>
25 #include <FUi.h>
26
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"
35
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;
44
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";
49
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;
55
56 AddBookmarkForm::AddBookmarkForm(void)
57 :__folderCount(0)
58 ,__folderName(CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS"))
59 ,__listHeight(H_TITLE_ITEM_HEIGHT)
60 , __oldFolderCount(0)
61 , __pBookmark(null)
62 , __pEditFieldTitle(null)
63 , __pEditFieldUrl(null)
64 ,__pList(null)
65 , __pListPanel(null)
66 , __previousScene(null)
67 , __pScrollPanel(null)
68 , __pWindowInfo(null)
69 , __selectedIndex(0)
70 , __showFolderList(false)
71 ,__titleOnViewDeactivated(L"")
72 , __view(L"")
73 ,__urlOnViewDeactivated(L"")
74
75 {
76
77 }
78
79 AddBookmarkForm::~AddBookmarkForm(void)
80 {
81         //      RemoveAllControls();
82 }
83
84 bool
85 AddBookmarkForm::Initialize(void)
86 {
87         Construct(L"IDL_ADD_BOOKMARK");
88
89         return true;
90 }
91
92 result
93 AddBookmarkForm::OnInitializing(void)
94 {
95         result r = E_SUCCESS;
96         Header* pHeader = null;
97
98         SceneManager* pSceneManager = SceneManager::GetInstance();
99         if (pSceneManager == null)
100         {
101                 return E_FAILURE;
102         }
103         pSceneManager->AddSceneEventListener(IDSCN_ADD_BOOKMARK, *this);
104
105         pHeader = GetHeader();
106
107         if (pHeader != null)
108         {
109                 pHeader->AddActionEventListener(*this);
110         }
111
112         // Main Panel which is a Scroll Panel
113         __pScrollPanel = static_cast< ScrollPanel* >(GetControl(L"IDC_SCROLLPANEL2"));
114
115         if (__pScrollPanel == null)
116         {
117                 return E_FAILURE;
118         }
119         __pScrollPanel->SetPageScrollEnabled(true);
120         // Title EditField added on the Scroll Panel
121         __pEditFieldTitle = static_cast< EditField* >(__pScrollPanel->GetControl(L"IDC_EDITFIELD1"));
122
123         if (__pEditFieldTitle == null)
124         {
125                 return E_FAILURE;
126         }
127
128         __pEditFieldTitle->SetGuideText(CommonUtil::GetString(L"IDS_BR_POP_ENTER_BOOKMARK_NAME"));
129         __pEditFieldTitle->AddTextEventListener(*this);
130         __pEditFieldTitle->AddKeypadEventListener(*this);
131         __pEditFieldTitle->SetOverlayKeypadCommandButtonVisible(false);
132
133         // Url Editfield added on the Scroll Panel
134         __pEditFieldUrl = static_cast< EditField* >(__pScrollPanel->GetControl(L"IDC_EDITFIELD2"));
135
136         if (__pEditFieldUrl == null)
137         {
138                 return E_FAILURE;
139         }
140
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);
146
147         __pList = static_cast< ListView* >(__pScrollPanel->GetControl(L"IDC_LISTVIEW1"));
148
149         if (__pList == null)
150         {
151                 return E_FAILURE;
152         }
153         __pList->SetItemProvider(*this);
154         __pList->AddListViewItemEventListener(*this);
155         AddOrientationEventListener(*this);
156
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());
161         r = E_SUCCESS;
162
163         return r;
164 }
165
166 result
167 AddBookmarkForm::OnTerminating(void)
168 {
169         result r = E_SUCCESS;
170         return r;
171 }
172
173 void
174 AddBookmarkForm::OnActionPerformed(const Control& source, int actionId)
175 {
176         AppLog("AddBookmarkForm::OnActionPerformed entered actionId %d",actionId);
177
178         SceneManager* pSceneManager = SceneManager::GetInstance();
179
180         if (pSceneManager == null)
181         {
182                 return ;
183         }
184
185         switch (actionId)
186         {
187         case IDA_CREATE_BOOKMARK_FOLDER:
188         {
189                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CREATE_BOOKMARK_FOLDER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
190         }
191         break;
192
193         case IDA_BUTTON_DONE:
194         {
195                 // Code to save the Bookmark
196                 String title = L"";
197                 String Url = L"";
198                 String bookMarkID = L"";
199                 String folderTitle = L"";
200                 ArrayList folderList;
201                 result r= E_SUCCESS;
202                 int count = 0;
203                 bool exist = false;
204                 bool ret = false;
205                 bool flag = false;
206                 bool valid = false;
207
208
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)
211
212                 RegularExpression firstRegex;
213                 RegularExpression secondRegex;
214
215                 firstRegex.Construct(firstPattern, REGEX_CASELESS);
216                 secondRegex.Construct(secondPattern, REGEX_CASELESS);
217
218                 title = __pEditFieldTitle->GetText();
219                 Url = __pEditFieldUrl->GetText();
220
221                 // Match
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)
224
225                 if (ret == true)
226                 {
227                         valid = true ;
228                 }
229                 else
230                 {
231                         String tempUrl = L"http://";
232                         tempUrl.Append(Url);
233
234                         if (flag == true)
235                         {
236                                 valid = true;
237                                 Url= tempUrl ;
238                         }
239                 }
240
241                 if (valid == false)
242                 {
243                         String msg = CommonUtil::GetString(L"IDS_BR_POP_INVALIDADDRESS");
244                         CreateMessage(msg);
245                 }
246                 else
247                 {
248                         if (__view == CommonUtil::GetString(L"IDS_BR_SK_EDIT"))
249                         {
250                                 String tempUrl ;
251                                 String tempTitle;
252                                 String tempParentId;
253
254                                 tempUrl = __pBookmark->GetUrl();
255                                 tempTitle = __pBookmark->GetBookmarkTitle();
256                                 tempParentId = __pBookmark->GetParentId();
257
258
259
260                                 r = BookmarkPresentationModel::GetInstance()->GetFolder("0", 0, __folderCount, folderList);
261                                 TryCatch(r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
262
263                                 for (count = 0; count < __folderCount; count++)
264                                 {
265                                         BookmarkData* pBookmark = null;
266                                         pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
267                                         if (pBookmark == NULL)
268                                         {
269                                                 return;
270                                         }
271                                         folderTitle = pBookmark->GetBookmarkTitle();
272
273                                         if (folderTitle == __folderName)
274                                         {
275                                                 bookMarkID = pBookmark->GetBookmarkId();
276                                                 break;
277                                         }
278                                 }
279
280                                 if(bookMarkID.GetLength() == 0)
281                                 {
282                                         bookMarkID = L"0";
283                                 }
284
285                                 AppLog("IDA_BUTTON_DONE tempParentId ID is %S",tempParentId.GetPointer());
286                                 AppLog("IDA_BUTTON_DONE bookMarkID ID is %S",bookMarkID.GetPointer());
287
288                                 if (bookMarkID.CompareTo(tempParentId) == 0 && __pEditFieldUrl->GetText().CompareTo(tempUrl) == 0 && __pEditFieldTitle->GetText().CompareTo(tempTitle) == 0)
289                                 {
290                                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
291                                         return;
292                                 }
293
294                                 if(tempUrl != __pEditFieldUrl->GetText() || tempParentId != bookMarkID)
295                                 {
296                                         r = BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(Url,exist, bookMarkID, true);
297                                         TryCatch( r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
298                                 }
299
300
301                                 if ( exist == true)
302                                 {
303                                         String msg = CommonUtil::GetString(L"IDS_BR_POP_BOOKMARK_ALREADY_EXISTS");
304                                         CreateMessage(msg);
305
306                                         AppLogDebug("Bookmark already exists");
307                                 }
308                                 else
309                                 {
310                                         __pBookmark->SetUrl(Url);
311                                         __pBookmark->SetBookmarkTitle(title);
312
313                                         if (bookMarkID == L"")
314                                         {
315                                                 __pBookmark->SetParentId(L"0");
316                                         }
317                                         else
318                                         {
319                                                 __pBookmark->SetParentId(bookMarkID);
320                                         }
321
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));
326                                 }
327                         }
328                         else
329                         {
330                                 AppLog("AddBookmarkForm::OnActionPerformed does url exist 1");
331
332                                 r = BookmarkPresentationModel::GetInstance()->GetFolder(L"0", 0, __folderCount, folderList);
333                                 TryCatch(r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
334
335                                 for (count = 0; count < __folderCount; count++)
336                                 {
337                                         BookmarkData* pBookmark = null;
338                                         pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
339                                         if (pBookmark == NULL)
340                                         {
341                                                 return;
342                                         }
343                                         folderTitle = pBookmark->GetBookmarkTitle();
344
345                                         if (folderTitle == __folderName)
346                                         {
347                                                 bookMarkID = pBookmark->GetBookmarkId();
348                                                 break;
349                                         }
350                                 }
351                                 if(bookMarkID.GetLength() == 0)
352                                 {
353                                         bookMarkID = L"0";
354                                 }
355                                 r = BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(Url,exist, bookMarkID, true);
356
357                                 TryCatch( r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
358                                 AppLog("AddBookmarkForm::OnActionPerformed does url exist 2");
359                                 if ( exist  == true)
360                                 {
361                                         String msg = CommonUtil::GetString(L"IDS_BR_POP_BOOKMARK_ALREADY_EXISTS");
362                                         CreateMessage(msg);
363
364                                         AppLogDebug("Bookmark already exists");
365                                 }
366                                 else
367                                 {
368                                         r = BookmarkPresentationModel::GetInstance()->GetFolder("0", 0, __folderCount, folderList);
369                                         TryCatch( r == E_SUCCESS,,"Failed to intitialize GetFolder %s",GetErrorMessage(r));
370
371                                         for (count = 0; count < __folderCount; count++)
372                                         {
373                                                 BookmarkData* pBookmark = null;
374                                                 pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
375                                                 if ( pBookmark == NULL )
376                                                 {
377                                                         return;
378                                                 }
379                                                 folderTitle = pBookmark->GetBookmarkTitle();
380
381                                                 if (folderTitle == __folderName)
382                                                 {
383                                                         bookMarkID = pBookmark->GetBookmarkId();
384                                                         break;
385                                                 }
386                                         }
387                                         BookmarkData bookmark;
388
389                                         if (__folderName != CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS"))
390                                         {
391                                                 bookmark.SetParentId(bookMarkID);
392                                         }
393
394                                         bookmark.SetBookmarkTitle(title);
395                                         bookmark.SetUrl(Url);
396                                         if (__pBookmark != null)
397                                         {
398                                                 bookmark.SetFaviconId(__pBookmark->GetFaviconId());
399                                         }
400                                         BookmarkPresentationModel::GetInstance()->SaveTempBookmark(bookmark);
401                                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
402                                 }
403                         }
404                 }
405
406                 folderList.RemoveAll(true);
407         }
408         break;
409
410         case IDA_BUTTON_CANCEL:
411         {
412                 if (__pEditFieldTitle != NULL)
413                 {
414                         __pEditFieldTitle->Clear();
415                 }
416
417                 if (__pEditFieldUrl != NULL)
418                 {
419                         __pEditFieldUrl->Clear();
420                 }
421
422                 pSceneManager->GoBackward(BackwardSceneTransition());
423
424         }
425         break;
426
427         default:
428                 break;
429         }
430
431         CATCH: return;
432 }
433
434 void
435 AddBookmarkForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
436 {
437         return;
438 }
439
440 void
441 AddBookmarkForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
442 {
443         if (__pEditFieldTitle != NULL)
444         {
445                 __pEditFieldTitle->HideKeypad();
446         }
447
448         if (__pEditFieldUrl != NULL)
449         {
450                 __pEditFieldUrl->HideKeypad();
451         }
452         if (index == 0)
453         {
454                 if (__showFolderList == false)
455                 {
456                         AppLog("AddBookmarkForm::OnListViewItemStateChanged false");
457                         __showFolderList = true;
458                         __pList->UpdateList();
459                         __listHeight = H_TITLE_ITEM_HEIGHT + (__pList->GetItemCount() -1) * H_ITEM_HEIGHT;
460
461                 }
462                 else
463                 {
464                         AppLog("AddBookmarkForm::OnListViewItemStateChanged true");
465                         __showFolderList = false;
466                         __pList->UpdateList();
467                         __listHeight = H_TITLE_ITEM_HEIGHT + (__pList->GetItemCount() - 1) * H_ITEM_HEIGHT;
468
469                 }
470
471         }
472         else
473         {
474                 __selectedIndex = index;
475                 if (index > 1 && __pList->GetItemCount() != index +1)
476                 {
477                         String parentID = "0";
478                         ArrayList folderList;
479                         BookmarkData* pBookmark = null;
480                         BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, __folderCount, folderList);
481
482                         pBookmark = static_cast<BookmarkData*>(folderList.GetAt(index-2));
483                         __folderName = pBookmark->GetBookmarkTitle();
484                 }
485                 else if(index == 1)
486                 {
487                         __folderName = CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS") ;
488                 }
489                 __listHeight = H_TITLE_ITEM_HEIGHT + (__pList->GetItemCount()-1) * H_ITEM_HEIGHT;
490                 if (__pList->GetItemCount() == index +1)
491                 {
492                         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_CREATE_BOOKMARK_FOLDER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
493                         return;
494                 }
495
496                 __pList->UpdateList();
497                 //              __pList->RefreshList(0, LIST_REFRESH_TYPE_ITEM_MODIFY);
498
499         }
500
501         result r = __pList->SetBounds(Rectangle(__pList->GetX(), __pList->GetY(), __pList->GetWidth(), __listHeight));
502         //__pList->Invalidate(true);
503         Invalidate(true);
504         AppLog("the result is %s", GetErrorMessage(r));
505         AppLog("the list height is %d", __pList->GetHeight());
506         return;
507 }
508
509 void
510 AddBookmarkForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
511 {
512         __pList->RefreshList(0, LIST_REFRESH_TYPE_ITEM_MODIFY);
513         return;
514 }
515
516 void
517 AddBookmarkForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
518 {
519         return;
520 }
521
522 int
523 AddBookmarkForm::GetItemCount(void)
524 {
525         AppLogDebug("AddBookmarkForm::GetItemCount");
526         int count = 0;
527         ArrayList folderList;
528         String parentID = "0";
529         BookmarkData* pBookmark = null;
530         BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, __folderCount, folderList);
531
532         if (__selectedIndex == 0 && __view == CommonUtil::GetString(L"IDS_BR_SK_EDIT"))
533         {
534                 for(int count = 0; count < __folderCount; count++)
535                 {
536                         pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
537
538                         if (__pBookmark != null && pBookmark != NULL && __pBookmark->GetParentId() == pBookmark->GetBookmarkId())
539                         {
540                                 __selectedIndex = count + 2;
541                                 __folderName = pBookmark->GetBookmarkTitle();
542                                 break;
543                         }
544                         else
545                         {
546                                 __selectedIndex = 1;
547                         }
548                 }
549         }
550
551         folderList.RemoveAll(true);
552
553         if (__showFolderList == false)
554         {
555                 return 1;
556         }
557         else
558         {
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);
562                 return count + 3;
563                 CATCH:
564                 return E_FAILURE;
565         }
566
567 }
568
569 ListItemBase*
570 AddBookmarkForm::CreateItem(int index, int itemWidth)
571 {
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);
579         if(itemWidth == 0)
580         {
581                 itemWidth = __pList->GetWidth();
582         }
583         if (index == 0)
584         {
585                 pItem = new(std::nothrow) DropDownCustomItem();
586                 r = pItem->Construct(itemWidth);
587
588                 if (IsFailed(r))
589                 {
590                         AppLog("Create Item Failed with error %s", GetErrorMessage(r));
591                         delete pItem;
592                         delete pBitmap;
593                         return null;
594                 }
595
596                 if ( __showFolderList == true )
597                 {
598                         pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
599                 }
600                 else
601                 {
602                         pItem->SetCurState(DROP_DOWN__ITEM_STATE_CLOSED);
603                 }
604
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);
610                 pItem->Make();
611                 if (pBitmap != null)
612                 {
613                         //pItem->AddElement(Rectangle(0, 0, 10, H_ITEM_HEIGHT), IDA_LIST_LEFT_SIDE_MARGIN_DROPDOWN, *pBitmap, null);
614                         delete pBitmap;
615                 }
616                 return pItem;
617         }
618         else
619         {
620                 String parentID = "0";
621                 ArrayList folderList;
622
623                 BookmarkData* pBookmark = null;
624                 r = BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, __folderCount, folderList);
625
626                 if (index == 1)
627                 {
628                         radioItem = new(std::nothrow) RadioCustomItem();
629                         //                      r = radioItem->Construct(GetClientAreaBounds().width, LIST_ITEM_HEIGHT);
630                         r = radioItem->Construct(itemWidth, LIST_ITEM_HEIGHT);
631                         if (IsFailed(r))
632                         {
633                                 AppLog("Create Item Failed with error %s", GetErrorMessage(r));
634                                 delete radioItem;
635                                 delete pBitmap;
636                                 return null;
637                         }
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);
643                 }
644                 else if (index <= __folderCount + 1)
645                 {
646                         pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(index - 2));
647                         if (pBookmark != null)
648                         {
649                                 folderTitle = pBookmark->GetBookmarkTitle();
650                         }
651                         radioItem = new(std::nothrow) RadioCustomItem();
652                         //                      r = radioItem->Construct(GetClientAreaBounds().width, LIST_ITEM_HEIGHT);
653                         r = radioItem->Construct(itemWidth, LIST_ITEM_HEIGHT);
654                         if (IsFailed(r))
655                         {
656                                 AppLog("Create Item Failed with error %s", GetErrorMessage(r));
657                                 delete radioItem;
658                                 delete pBitmap;
659                                 return null;
660                         }
661
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);
666                 }
667                 else
668                 {
669                         radioItem = new(std::nothrow) RadioCustomItem();
670                         //                      r = radioItem->Construct(GetClientAreaBounds().width, LIST_ITEM_HEIGHT);
671                         r = radioItem->Construct(itemWidth, LIST_ITEM_HEIGHT);
672                         if (IsFailed(r))
673                         {
674                                 AppLog("Create Item Failed with error %s", GetErrorMessage(r));
675                                 delete radioItem;
676                                 delete pBitmap;
677                                 return null;
678                         }
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);
685
686                 }
687
688                 if (__selectedIndex == index)
689                 {
690                         radioItem->SetSelected(true);
691                 }
692                 else
693                 {
694                         radioItem->SetSelected(false);
695                 }
696
697                 if(__selectedIndex == 0 && index == 1)
698                         radioItem->SetSelected(true);
699                 if (radioItem->GetSelected() == true)
700                 {
701                         __folderName = radioItem->GetText();
702                 }
703
704                 if (pBitmap != null)
705                 {
706                         //radioItem->AddElement(Rectangle(0, 0, 10, LIST_ITEM_HEIGHT), IDA_LIST_LEFT_SIDE_MARGIN, *pBitmap, null);
707                         delete pBitmap;
708                 }
709
710                 folderList.RemoveAll(true);
711                 radioItem->Make();
712                 return radioItem;
713         }
714 }
715
716 bool
717 AddBookmarkForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
718 {
719         if (pItem != null)
720         {
721                 delete pItem;
722                 pItem = null;
723         }
724
725         return true;
726 }
727
728 void
729 AddBookmarkForm::OnKeypadActionPerformed(Control& source, KeypadAction keypadAction)
730 {
731         return;
732 }
733
734 void
735 AddBookmarkForm::OnKeypadClosed(Control& source)
736 {
737
738         AppLog("the client area height is %d",GetClientAreaBounds().height);
739
740         __pScrollPanel->SetBounds(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
741         __pScrollPanel->Invalidate(true);
742
743         Invalidate(true);
744         return;
745 }
746
747 void
748 AddBookmarkForm::OnKeypadOpened(Control& source)
749 {
750         return;
751 }
752
753 void
754 AddBookmarkForm::OnKeypadWillOpen(Control& source)
755 {
756         AppLog("the client area height is %d",GetClientAreaBounds().height);
757
758         //      __pScrollPanel->SetBounds(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
759
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);
765         Invalidate(true);
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);
767         return;
768 }
769
770 void
771 AddBookmarkForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
772 {
773         // Code to handle events when the AddBookmarkForm is activated.
774         String str = "0";
775         String pageTitle = L"";
776         String pageUrl = L"";
777         String title = L"";
778         String url = L"";
779         result r = E_FAILURE;
780         Header* pHeader = GetHeader();
781
782         r = BookmarkPresentationModel::GetInstance()->GetFolderCount(str, __folderCount);
783         TryCatch( r == E_SUCCESS, ,"Failed to intitialize GETFOLDERCOUNT  %s",GetErrorMessage(r));
784
785         if ( pHeader == NULL )
786         {
787                 return ;
788         }
789         if ( previousSceneId != IDSCN_CREATE_BOOKMARK_FOLDER )
790         {
791                 // check first argument of pargs 0 for Add, 1 - for Edit
792                 String* firstValue = NULL;
793                 if(pArgs)
794                 {
795                         firstValue = dynamic_cast<String*>(pArgs->GetAt(0));
796                 }
797
798                 if( firstValue == NULL || pArgs == NULL)
799                 {
800                         return ;
801                 }
802                 if (firstValue->CompareTo(L"1") == 0)
803                 {
804                         __view = CommonUtil::GetString(L"IDS_BR_SK_EDIT");
805
806                         pHeader->SetTitleText(CommonUtil::GetString(L"IDS_BR_HEADER_EDIT_BOOKMARK"));
807
808                         if (__pBookmark != NULL && pArgs != NULL)
809                         {
810                                 delete __pBookmark;
811                                 __pBookmark = null;
812                         }
813
814                         if (__pBookmark == NULL && pArgs != NULL)
815                         {
816                                 __pBookmark = dynamic_cast<BookmarkData*>(pArgs->GetAt(1));
817                         }
818
819                         if (__pBookmark)
820                         {
821                                 pageTitle = __pBookmark->GetBookmarkTitle();
822                                 pageUrl = __pBookmark->GetUrl();
823                         }
824                 }
825                 else if (firstValue->CompareTo(L"0") == 0)
826                 {
827                         __view = CommonUtil::GetString(L"IDS_COM_SK_ADD");
828                         pHeader->SetTitleText(CommonUtil::GetString(L"IDS_BR_HEADER_EDIT_BOOKMARK"));
829
830                         WindowInfo* pWindowInfo = MultipleWindowPresentationModel::GetInstance()->GetActiveWindowInfo();
831
832                         if( pWindowInfo == NULL )
833                         {
834                                 return;
835                         }
836
837                         if(pWindowInfo->pageTitle.CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_ABOUT_C_BLANK")) != 0)
838                                 pageTitle = pWindowInfo->pageTitle;
839
840                         if(pWindowInfo->pageUrl.IsEmpty() == false)
841                         {
842                                 pageUrl = pWindowInfo->pageUrl;
843                         }
844                         String* parentID = dynamic_cast<String*>(pArgs->GetAt(1));
845
846                         ArrayList folderList;
847
848                         BookmarkData* pBookmark = null;
849                         BookmarkPresentationModel::GetInstance()->GetFolder(L"0", 0, __folderCount, folderList);
850                         for(int count = 0; count < folderList.GetCount(); count++)
851                         {
852                                 pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
853
854                                 if ( pBookmark == null )
855                                 {
856                                         return ;
857                                 }
858
859                                 if (parentID != NULL && pBookmark->GetBookmarkId().CompareTo(parentID->GetPointer()) == 0)
860                                 {
861                                         __selectedIndex = count + 2;
862                                         __folderName = pBookmark->GetBookmarkTitle();
863                                         break;
864                                 }
865                                 else
866                                 {
867                                         __selectedIndex = 1 ;
868                                         __folderName = CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS") ;
869                                 }
870
871                         }
872
873                         if (__folderCount == 0)
874                         {
875                                 __selectedIndex = 1 ;
876                                 __folderName = CommonUtil::GetString(L"IDS_BR_TAB_BOOKMARKS") ;
877                         }
878
879                         folderList.RemoveAll(true);
880                 }
881         }
882
883         if ( previousSceneId == IDSCN_CREATE_BOOKMARK_FOLDER )
884         {
885                 pageTitle = __titleOnViewDeactivated;
886                 pageUrl = __urlOnViewDeactivated;
887                 if(__pList && __pScrollPanel)
888                 {
889                         AppLog("__pList->GetItemCount() %d",__pList->GetItemCount());
890                         __pList->ScrollToItem(__pList->GetItemCount());
891 //                      __pList->Invalidate(true);
892                         __pScrollPanel->ScrollToBottom();
893                 }
894         }
895
896         if(__pEditFieldTitle != NULL)
897         {
898                 __pEditFieldTitle->ShowKeypad();
899         }
900         if ( previousSceneId != IDSCN_CREATE_BOOKMARK_FOLDER )
901         {
902                 if (__pEditFieldTitle != NULL)
903                 {
904                         __pEditFieldTitle->SetText(pageTitle);
905                         __pEditFieldTitle->ShowKeypad();
906                 }
907                 if (__pEditFieldUrl != NULL)
908                 {
909                         __pEditFieldUrl->SetText(pageUrl);
910                         __pEditFieldUrl->HideKeypad();
911                 }
912
913         }
914         else
915         {
916                 if (__pEditFieldTitle != NULL)
917                 {
918                         __pEditFieldTitle->SetText(pageTitle);
919                         __pEditFieldTitle->HideKeypad();
920                 }
921                 if (__pEditFieldUrl != NULL)
922                 {
923                         __pEditFieldUrl->SetText(pageUrl);
924                         __pEditFieldUrl->HideKeypad();
925                 }
926         }
927         if (__view == CommonUtil::GetString(L"IDS_BR_SK_EDIT") && previousSceneId == IDSCN_CREATE_BOOKMARK_FOLDER )
928         {
929                 if (__oldFolderCount == 0)
930                 {
931                         if (__folderCount == 1)
932                         {
933                                 __selectedIndex = 2;
934                         }
935                 }
936                 else if (__oldFolderCount != __folderCount)
937                 {
938                         __selectedIndex = __folderCount + 1;
939                 }
940
941         }
942
943
944         if (__view == CommonUtil::GetString(L"IDS_COM_SK_ADD")  && previousSceneId == IDSCN_CREATE_BOOKMARK_FOLDER)
945         {
946
947                 if (__oldFolderCount == 0)
948                 {
949                         if (__folderCount == 1)
950                         {
951                                 __selectedIndex = 2;
952                         }
953                 }
954                 else if (__oldFolderCount != __folderCount)
955                 {
956                         __selectedIndex = __folderCount + 1;
957
958                 }
959                 else if (__oldFolderCount == __folderCount )
960                 {
961                         __selectedIndex = __folderCount + 1;
962                 }
963                 if(__selectedIndex > 1)
964                 {
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)
971                         {
972                                 __folderName = pBookmark->GetBookmarkTitle();
973                         }
974                 }
975         }
976         if (__pEditFieldTitle != NULL)
977         {
978                 title = __pEditFieldTitle->GetText();
979                 title.Trim();
980         }
981
982         if (__pEditFieldUrl != NULL)
983         {
984                 url = __pEditFieldUrl->GetText();
985                 url.Trim();
986         }
987
988         // To disable done button if either of the Title or Url field is empty
989         if (title.GetLength() == 0 || url.GetLength() == 0)
990         {
991                 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
992                 pHeader->Invalidate(true);
993         }
994         else
995         {
996                 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
997                 pHeader->Invalidate(true);
998         }
999
1000         if(__pList != null)
1001         {
1002
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);
1006         }
1007
1008         Invalidate(true);
1009         //      __pList->RefreshList(0, LIST_REFRESH_TYPE_ITEM_MODIFY);
1010         CATCH : return;
1011 }
1012
1013 void
1014 AddBookmarkForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
1015 {
1016         // Add code to handle events when the AddBookmarkForm is Deactivated.
1017         if ( __pEditFieldTitle != NULL)
1018         {
1019                 __titleOnViewDeactivated = __pEditFieldTitle->GetText();
1020         }
1021
1022         if ( __pEditFieldUrl != NULL)
1023         {
1024                 __urlOnViewDeactivated = __pEditFieldUrl->GetText();
1025         }
1026
1027         __oldFolderCount = __folderCount;
1028
1029         if (__view == CommonUtil::GetString(L"IDS_BR_SK_EDIT") )
1030         {
1031                 __selectedIndex = 0;
1032         }
1033         return;
1034 }
1035
1036 void
1037 AddBookmarkForm::OnFocusGained (const Tizen::Ui::Control &source)
1038 {
1039         __pScrollPanel->SetSize(GetClientAreaBounds().width,GetClientAreaBounds().height);
1040         __pScrollPanel->SetClientAreaWidth(__pScrollPanel->GetWidth());
1041         __pScrollPanel->SetClientAreaHeight(GetClientAreaBounds().height);
1042         Invalidate(true);
1043         return;
1044
1045 }
1046 void
1047 AddBookmarkForm::OnFocusLost (const Tizen::Ui::Control &source)
1048 {
1049
1050 }
1051
1052 void
1053 AddBookmarkForm::OnTextValueChanged(const Control& source)
1054 {
1055         String title = L"";
1056         String url = L"";
1057         Header* pHeader = GetHeader();
1058         if (pHeader == NULL)
1059         {
1060                 return;
1061         }
1062
1063         if (__pEditFieldTitle == NULL || __pEditFieldUrl == NULL)
1064         {
1065                 return;
1066         }
1067
1068         title = __pEditFieldTitle->GetText();
1069         url = __pEditFieldUrl->GetText();
1070         title.Trim();
1071         url.Trim();
1072
1073         // To disable done button if either of the Title or Url field is empty
1074         if (title.GetLength() == 0 || url.GetLength() == 0)
1075         {
1076                 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
1077                 pHeader->Invalidate(true);
1078         }
1079         else
1080         {
1081                 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
1082                 pHeader->Invalidate(true);
1083         }
1084
1085         return;
1086 }
1087
1088 void
1089 AddBookmarkForm::OnTextValueChangeCanceled(const Control& source)
1090 {
1091         return;
1092 }
1093
1094 void
1095 AddBookmarkForm::CreateMessage(String& str)
1096 {
1097         Tizen::Ui::Controls::MessageBox* pMsgBox = null;       // Message Box to display alert if folder with same name already exists
1098         int __modalMsgBoxResult;
1099
1100         pMsgBox = new(std::nothrow) MessageBox;
1101         if (pMsgBox != null)
1102         {
1103                 pMsgBox->Construct(str, L"", MSGBOX_STYLE_OK, 3000);
1104                 pMsgBox->ShowAndWait(__modalMsgBoxResult);
1105                 delete pMsgBox;
1106                 pMsgBox = null;
1107                 __modalMsgBoxResult = 0;
1108         }
1109
1110         return;
1111 }
1112
1113 void
1114 AddBookmarkForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1115 {
1116         //      if (__pEditFieldTitle != NULL)
1117         //      {
1118         //              __pEditFieldTitle->HideKeypad();
1119         //      }
1120         //      if (__pEditFieldUrl != NULL)
1121         //      {
1122         //              __pEditFieldUrl->HideKeypad();
1123         //      }
1124
1125         if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE)
1126         {
1127                 if (__pScrollPanel != null)
1128                 {
1129                         __pScrollPanel->ScrollToTop();
1130                         __pScrollPanel->SetClientAreaHeight(__pList->GetY()+__listHeight);
1131                 }
1132         }
1133
1134         if (__pList != null)
1135         {
1136                 __pList->SetBounds(__pList->GetX(),__pList->GetY(),__pList->GetWidth(),__listHeight);
1137                 __pList->UpdateList();
1138         }
1139         Invalidate(true);
1140 }