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);
78 __pFolderTitle = static_cast< EditField* >(GetControl(L"IDC_EDITFIELD_FOLDER_TITLE"));
80 if (__pFolderTitle == null)
85 __pFolderTitle->AddKeypadEventListener(*this);
86 __pFolderTitle->AddTextEventListener(*this);
87 __pFolderTitle->SetOverlayKeypadCommandButtonVisible(false);
89 pHeader = GetHeader();
93 pHeader->AddActionEventListener(*this);
100 CreateBookmarkFolderForm::OnTerminating(void)
102 result r = E_SUCCESS;
107 CreateBookmarkFolderForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
109 AppLogDebug("CreateBookmarkFolderForm::OnSceneActivatedN");
111 result r = E_SUCCESS;
112 __previousScene = previousSceneId;
114 ArrayList folderList;
115 String parentID = "0";
123 String pStr = CommonUtil::GetString(L"IDS_BR_HEADER_EDIT_FOLDER");
125 String folder01 = CommonUtil::GetString(L"IDS_BR_BODY_FOLDER");
126 folder01.Append(L"_");
128 String* pEvent = null;
131 pEvent = dynamic_cast<String*>(pArgs->GetAt(1));
136 if (pEvent->CompareTo(pStr) == 0)
143 Header* pHeader = GetHeader();
147 if (previousSceneId ==IDSCN_EDIT_BOOKMARK_LIST || __ret == true)
149 pHeader->SetTitleText(CommonUtil::GetString(L"IDS_BR_HEADER_EDIT_FOLDER"));
153 pHeader->SetTitleText(CommonUtil::GetString(L"IDS_BR_SK3_CREATE_FOLDER"));
157 if (__pFolderTitle == NULL)
162 if (previousSceneId == IDSCN_EDIT_BOOKMARK_LIST || __ret == true)
164 if (__pBookmark != NULL )
172 __pBookmark = dynamic_cast<BookmarkData*>(pArgs->GetAt(0));
175 if (__pBookmark != null)
177 __pFolderTitle->SetText(__pBookmark->GetBookmarkTitle());
178 __pFolderTitle->SetFocus();
179 __pFolderTitle->ShowKeypad();
184 __pFolderTitle->SetText(folder01);
185 __pFolderTitle->SetFocus();
186 __pFolderTitle->ShowKeypad();
188 r = BookmarkPresentationModel::GetInstance()->GetFolderCount(parentID, foldercount); // to get count of existing folders
189 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetInstance()->GetFolderCount failed %s",GetErrorMessage(r));
191 r = BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, foldercount, folderList); // to get list of existing folders
192 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetInstance()->GetFolder failed %s",GetErrorMessage(r));
194 while (true) // to provide user with unique folder title when he creates a new(std::nothrow) folder
195 { // to generate folder with default name of type Folder_##
200 title.Append(folder01);
207 title.Append(counter);
209 for (count = 0;count < foldercount ; count++)
211 BookmarkData* pBookmark = dynamic_cast<BookmarkData*>(folderList.GetAt(count));
213 if ( pBookmark != NULL)
215 folderTitle = pBookmark->GetBookmarkTitle();
218 if (title.Equals(folderTitle,false) == true)
220 flag = true; // if flag is true folder title already exists
221 break; // break from for loop
228 __pFolderTitle->SetText(title); // if flag is false folder title is unique
229 break; // break from while loop
232 } // end of while loop
237 folderList.RemoveAll(true);
242 CreateBookmarkFolderForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
252 CreateBookmarkFolderForm::OnActionPerformed(const Control& source, int actionId)
255 SceneManager* pSceneManager = SceneManager::GetInstance();
257 if (pSceneManager == null)
264 case IDA_BUTTON_CANCEL:
267 if (__pFolderTitle != NULL)
269 __pFolderTitle->Clear();
270 __pFolderTitle->HideKeypad();
273 r = pSceneManager->GoBackward(BackwardSceneTransition());
274 AppLogDebug("SCENE_ADD_BOOKMARK error = %s",GetErrorMessage(r));
275 TryCatch(!IsFailed(r),L"BookmarkPresentationModel::GetFolderCount failed %s",GetErrorMessage(r));
280 case IDA_BUTTON_DONE:
282 result r = E_SUCCESS;
284 ArrayList folderList;
285 String parentID = "0";
289 folderTitle = __pFolderTitle->GetText();
292 r = BookmarkPresentationModel::GetInstance()->GetFolderCount(parentID, foldercount);
293 TryCatch( !IsFailed(r),,"BookmarkPresentationModel::GetInstance()->GetFolderCount failed %s",GetErrorMessage(r));
295 r = BookmarkPresentationModel::GetInstance()->GetFolder(parentID, 0, foldercount, folderList);
296 TryCatch( !IsFailed(r),,"BookmarkPresentationModel::GetInstance()->GetFolder failed %s",GetErrorMessage(r));
298 // To check if folder with same name exists
299 for (count = 0; count < foldercount; count++)
301 BookmarkData* pBookmark = dynamic_cast< BookmarkData* >(folderList.GetAt(count));
302 if ( pBookmark == NULL )
306 title = pBookmark->GetBookmarkTitle();
309 if (folderTitle.Equals(title, true) == true)
316 if (flag == true && ( __ret == true || __previousScene == IDSCN_EDIT_BOOKMARK_LIST) )
319 if(__pBookmark && (__pBookmark->GetBookmarkTitle() == folderTitle ))
321 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
322 folderList.RemoveAll(false);
329 String message = " Folder already exists ";
330 CreateMessage(message); // Message alert saying Folder already exists
334 if (__previousScene == IDSCN_EDIT_BOOKMARK_LIST || __ret == true )
336 __pBookmark->SetBookmarkTitle(folderTitle);
337 BookmarkPresentationModel::GetInstance()->SaveFolder(*__pBookmark);
339 r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
340 AppLogDebug("SCENE_ADD_BOOKMARK error = %s",GetErrorMessage(r));
345 ArrayList* pArgList = null;
346 pArgList = new(std::nothrow) ArrayList();
347 if (pArgList != null)
349 pArgList->Construct();
350 pArgList->Add(*new(std::nothrow) String(L"2"));
353 BookmarkData bookmark;
354 bookmark.SetBookmarkTitle(folderTitle);
355 BookmarkPresentationModel::GetInstance()->SaveFolder(bookmark);
356 result r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT),pArgList);
357 AppLogDebug("SCENE_ADD_BOOKMARK error = %s",GetErrorMessage(r));
358 if (pArgList != null)
360 pArgList->RemoveAll(false);
363 TryCatch( !IsFailed(r),L"BookmarkPresentationModel::GetFolder failed %s",GetErrorMessage(r));
368 folderList.RemoveAll(false);
380 CreateBookmarkFolderForm::OnKeypadActionPerformed(Control& source, KeypadAction keypadAction)
386 CreateBookmarkFolderForm::OnKeypadClosed(Control& source)
388 // __pFolderTitle->SetFocus();
389 // __pFolderTitle->HideKeypad();
393 CreateBookmarkFolderForm::OnKeypadOpened(Control& source)
399 CreateBookmarkFolderForm::OnKeypadWillOpen(Control& source)
405 CreateBookmarkFolderForm::OnTextValueChanged(const Control& source)
408 Header* pHeader = GetHeader();
415 if (__pFolderTitle == NULL)
420 title = __pFolderTitle->GetText();
423 // To disable done button when folder title edit-field is empty
424 if (__pFolderTitle && title.GetLength() == 0)
426 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
430 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
432 pHeader->Invalidate(true);
437 CreateBookmarkFolderForm::OnTextValueChangeCanceled(const Control& source)
443 CreateBookmarkFolderForm::CreateMessage(String& msg)
446 if (__pMsgBox != null)
450 __modalMsgBoxResult = 0;
453 __pMsgBox = new(std::nothrow) MessageBox;
455 if (__pMsgBox != null)
457 __pMsgBox->Construct(L"", msg, MSGBOX_STYLE_OK, 3000);
460 if (__pMsgBox != null)
462 __pMsgBox->ShowAndWait(__modalMsgBoxResult);
463 if(__pFolderTitle != null)
464 __pFolderTitle->SetFocus();
465 /*if (__modalMsgBoxResult == MSGBOX_RESULT_OK)
467 AppLog("CreateBookmarkFolderForm::CreateMessage MSGBOX_RESULT_OK");
468 if (__pMsgBox != null)
474 if (__pMsgBox != null)
479 __modalMsgBoxResult = 0;