3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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: IntCreateBookmarkFolderForm
20 *@brief: This class creates Bookmark folder
24 #include <FAppUiApp.h>
26 #include "IntBookmarkPresentationModel.h"
27 #include "IntBookmarkData.h"
28 #include "IntCommonLib.h"
29 #include "IntCreateBookmarkFolderForm.h"
30 #include "IntSceneRegister.h"
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
41 const int CreateBookmarkFolderForm::IDA_BUTTON_DONE = 101;
42 const int CreateBookmarkFolderForm::IDA_BUTTON_CANCEL = 102;
44 CreateBookmarkFolderForm::CreateBookmarkFolderForm(void)
45 : __pFolderTitle(null)
47 , __modalMsgBoxResult(0)
54 CreateBookmarkFolderForm::~CreateBookmarkFolderForm(void)
60 CreateBookmarkFolderForm::Initialize(void)
62 result r = Construct(L"IDL_CREATE_BOOKMARK_FOLDER");
63 AppLogDebug("CreateBookmarkFolderForm Construct returned %s",GetErrorMessage(r));
68 CreateBookmarkFolderForm::OnInitializing(void)
70 // Add your initialization code here
73 Header* pHeader = null;
74 SceneManager* pSceneManager = SceneManager::GetInstance();
75 AppAssert(pSceneManager);
76 pSceneManager->AddSceneEventListener(IDSCN_CREATE_BOOKMARK_FOLDER, *this);
77 SetFormBackEventListener(this);
79 __pFolderTitle = static_cast< EditField* >(GetControl(L"IDC_EDITFIELD_FOLDER_TITLE"));
81 if (__pFolderTitle == null)
86 __pFolderTitle->AddKeypadEventListener(*this);
87 __pFolderTitle->AddTextEventListener(*this);
88 __pFolderTitle->SetOverlayKeypadCommandButtonVisible(false);
90 pHeader = GetHeader();
94 pHeader->AddActionEventListener(*this);
101 CreateBookmarkFolderForm::OnTerminating(void)
103 result r = E_SUCCESS;
108 CreateBookmarkFolderForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
110 AppLogDebug("CreateBookmarkFolderForm::OnSceneActivatedN");
112 result r = E_SUCCESS;
113 __previousScene = previousSceneId;
115 ArrayList folderList;
116 String parentID = "0";
124 String pStr = CommonUtil::GetString(L"IDS_BR_SK_EDIT");
126 String folder01 = CommonUtil::GetString(L"IDS_BR_HEADER_FOLDER");
127 folder01.Append(L"_");
129 String* pEvent = null;
132 pEvent = dynamic_cast<String*>(pArgs->GetAt(1));
137 if (pEvent->CompareTo(pStr) == 0)
144 Header* pHeader = GetHeader();
148 if (previousSceneId ==IDSCN_EDIT_BOOKMARK_LIST || __ret == true)
150 pHeader->SetTitleText(CommonUtil::GetString(L"IDS_BR_SK_EDIT"));
154 pHeader->SetTitleText(CommonUtil::GetString(L"IDS_BR_SK3_CREATE_FOLDER"));
158 if (__pFolderTitle == NULL)
163 if (previousSceneId == IDSCN_EDIT_BOOKMARK_LIST || __ret == true)
165 if (__pBookmark != NULL )
173 __pBookmark = dynamic_cast<BookmarkData*>(pArgs->GetAt(0));
176 if (__pBookmark != null)
178 __pFolderTitle->SetText(__pBookmark->GetBookmarkTitle());
179 __pFolderTitle->SetFocus();
180 __pFolderTitle->ShowKeypad();
185 __pFolderTitle->SetText(folder01);
186 __pFolderTitle->SetFocus();
187 __pFolderTitle->ShowKeypad();
189 r = BookmarkPresentationModel::GetInstance()->GetFolderCount(parentID, foldercount); // to get count of existing folders
190 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetInstance()->GetFolderCount failed %s",GetErrorMessage(r));
192 r = BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, foldercount, folderList); // to get list of existing folders
193 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetInstance()->GetFolder failed %s",GetErrorMessage(r));
195 while (true) // to provide user with unique folder title when he creates a new(std::nothrow) folder
196 { // to generate folder with default name of type Folder_##
201 title.Append(folder01);
208 title.Append(counter);
210 for (count = 0;count < foldercount ; count++)
212 BookmarkData* pBookmark = dynamic_cast<BookmarkData*>(folderList.GetAt(count));
214 if ( pBookmark != NULL)
216 folderTitle = pBookmark->GetBookmarkTitle();
219 if (title.Equals(folderTitle,false) == true)
221 flag = true; // if flag is true folder title already exists
222 break; // break from for loop
229 __pFolderTitle->SetText(title); // if flag is false folder title is unique
230 break; // break from while loop
233 } // end of while loop
238 folderList.RemoveAll(true);
243 CreateBookmarkFolderForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
249 CreateBookmarkFolderForm::OnActionPerformed(const Control& source, int actionId)
252 SceneManager* pSceneManager = SceneManager::GetInstance();
254 if (pSceneManager == null)
261 case IDA_BUTTON_CANCEL:
264 if (__pFolderTitle != NULL)
266 __pFolderTitle->Clear();
267 __pFolderTitle->HideKeypad();
270 r = pSceneManager->GoBackward(BackwardSceneTransition());
271 AppLogDebug("SCENE_ADD_BOOKMARK error = %s",GetErrorMessage(r));
272 TryCatch(!IsFailed(r),L"BookmarkPresentationModel::GetFolderCount failed %s",GetErrorMessage(r));
277 case IDA_BUTTON_DONE:
279 result r = E_SUCCESS;
281 ArrayList folderList;
282 String parentID = "0";
286 folderTitle = __pFolderTitle->GetText();
289 r = BookmarkPresentationModel::GetInstance()->GetFolderCount(parentID, foldercount);
290 TryCatch( !IsFailed(r),,"BookmarkPresentationModel::GetInstance()->GetFolderCount failed %s",GetErrorMessage(r));
292 r = BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, foldercount, folderList);
293 TryCatch( !IsFailed(r),,"BookmarkPresentationModel::GetInstance()->GetFolder failed %s",GetErrorMessage(r));
295 // To check if folder with same name exists
296 for (count = 0; count < foldercount; count++)
298 BookmarkData* pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
299 if ( pBookmark == NULL )
303 title = pBookmark->GetBookmarkTitle();
306 if (folderTitle.Equals(title, true) == true)
313 if (flag == true && ( __ret == true || __previousScene == IDSCN_EDIT_BOOKMARK_LIST) )
316 if(__pBookmark && (__pBookmark->GetBookmarkTitle() == folderTitle ))
318 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
319 folderList.RemoveAll(false);
326 String message = " Folder already exists ";
327 CreateMessage(message); // Message alert saying Folder already exists
331 if (__previousScene == IDSCN_EDIT_BOOKMARK_LIST || __ret == true )
333 __pBookmark->SetBookmarkTitle(folderTitle);
334 BookmarkPresentationModel::GetInstance()->SaveFolder(*__pBookmark);
336 r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
337 AppLogDebug("SCENE_ADD_BOOKMARK error = %s",GetErrorMessage(r));
342 ArrayList* pArgList = null;
343 pArgList = new(std::nothrow) ArrayList();
344 if (pArgList != null)
346 pArgList->Construct();
347 pArgList->Add(*new(std::nothrow) String(L"2"));
350 BookmarkData bookmark;
351 bookmark.SetBookmarkTitle(folderTitle);
352 BookmarkPresentationModel::GetInstance()->SaveFolder(bookmark);
353 result r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT),pArgList);
354 AppLogDebug("SCENE_ADD_BOOKMARK error = %s",GetErrorMessage(r));
355 if (pArgList != null)
357 pArgList->RemoveAll(false);
360 TryCatch( !IsFailed(r),L"BookmarkPresentationModel::GetFolder failed %s",GetErrorMessage(r));
365 folderList.RemoveAll(false);
377 CreateBookmarkFolderForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
379 SceneManager* pSceneManager = SceneManager::GetInstance();
380 if (pSceneManager == null)
385 if (__pFolderTitle != NULL)
387 __pFolderTitle->Clear();
388 __pFolderTitle->HideKeypad();
391 r = pSceneManager->GoBackward(BackwardSceneTransition());
392 AppLogDebug("SCENE_ADD_BOOKMARK error = %s",GetErrorMessage(r));
398 CreateBookmarkFolderForm::OnKeypadActionPerformed(Control& source, KeypadAction keypadAction)
404 CreateBookmarkFolderForm::OnKeypadClosed(Control& source)
406 // __pFolderTitle->SetFocus();
407 // __pFolderTitle->HideKeypad();
411 CreateBookmarkFolderForm::OnKeypadOpened(Control& source)
417 CreateBookmarkFolderForm::OnKeypadWillOpen(Control& source)
423 CreateBookmarkFolderForm::OnTextValueChanged(const Control& source)
426 Header* pHeader = GetHeader();
433 if (__pFolderTitle == NULL)
438 title = __pFolderTitle->GetText();
441 // To disable done button when folder title edit-field is empty
442 if (__pFolderTitle && title.GetLength() == 0)
444 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
448 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
450 pHeader->Invalidate(true);
455 CreateBookmarkFolderForm::OnTextValueChangeCanceled(const Control& source)
461 CreateBookmarkFolderForm::CreateMessage(String& msg)
464 if (__pMsgBox != null)
468 __modalMsgBoxResult = 0;
471 __pMsgBox = new(std::nothrow) MessageBox;
473 if (__pMsgBox != null)
475 __pMsgBox->Construct(L"", msg, MSGBOX_STYLE_OK, 3000);
478 if (__pMsgBox != null)
480 __pMsgBox->ShowAndWait(__modalMsgBoxResult);
481 if(__pFolderTitle != null)
482 __pFolderTitle->SetFocus();
483 /*if (__modalMsgBoxResult == MSGBOX_RESULT_OK)
485 AppLog("CreateBookmarkFolderForm::CreateMessage MSGBOX_RESULT_OK");
486 if (__pMsgBox != null)
492 if (__pMsgBox != null)
497 __modalMsgBoxResult = 0;