2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file GlAlbumNameEditorForm.cpp
19 * @brief This is the implementation file for AlbumNameEditorForm class.
23 #include "GlAlbumInfo.h"
24 #include "GlAlbumNameEditorForm.h"
25 #include "GlAlbumListPresentationModel.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlProgressAnimation.h"
28 #include "GlResourceManager.h"
30 #include "GlFileMoveTimer.h"
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Base::Utility;
37 using namespace Tizen::Content;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Media;
40 using namespace Tizen::Io;
41 using namespace Tizen::System;
42 using namespace Tizen::Ui;
43 using namespace Tizen::Ui::Controls;
44 using namespace Tizen::Ui::Scenes;
46 static const Rectangle RECT_NAME_EDIT_FIELD (0, 0, 720, 100);
47 static const unsigned int COLOR_NAME_EDIT_FIELD = Color32<255, 255, 255>::Value;
48 static const int ALBUM_MAX_LENGTH = 255;
50 AlbumNameEditorForm::AlbumNameEditorForm()
51 : __pNameEditField(null)
53 , __albumNameEditorMode(ALBUM_NAME_EDITOR_MODE_RENAME)
55 , __pPresentationModel(null)
56 , __pFilePresentationModel(null)
57 , __pMoveIndexList(null)
59 ,__pProgressAnim(null)
63 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
66 AlbumNameEditorForm::~AlbumNameEditorForm()
70 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
74 AlbumNameEditorForm::Initialize(void)
77 result r = Construct(FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR);
78 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
84 AlbumNameEditorForm::OnInitializing(void)
87 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
88 __pFilePresentationModel = FileListPresentationModel::GetInstance();
90 Header* pHeader = GetHeader();
92 pHeader->SetStyle(HEADER_STYLE_TITLE);
94 GetFooter()->SetBackButtonEnabled(true);
95 GetFooter()->SetBackButton();
98 itemSave.Construct(ACTION_ID_BUTTON_CREATE_NAME_SAVE);
99 itemSave.SetText(L"Save");
101 GetFooter()->AddItem(itemSave);
102 GetFooter()->AddActionEventListener(*this);
103 GetFooter()->Invalidate(true);
105 SetFormBackEventListener(this);
106 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
109 __pNameEditField = new (std::nothrow) EditField();
110 __pNameEditField->Construct(RECT_NAME_EDIT_FIELD, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY,
111 EDIT_FIELD_TITLE_STYLE_NONE, true, ALBUM_MAX_LENGTH);
112 __pNameEditField->AddTextEventListener(*this);
113 __pNameEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_NAME_EDIT_FIELD);
114 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
116 AddControl(*__pNameEditField);
117 __pNameEditField->AddActionEventListener(*this);
123 AlbumNameEditorForm::OnTextValueChanged(const Control& source)
125 AppLogDebug("ENTER");
126 String inputString = __pNameEditField->GetText();
128 if (inputString.Contains(DIRECTORY_SEPARATOR) == true)
130 if (__pMessageBox == null)
132 __pMessageBox = new (std::nothrow) MessageBox();
133 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS"),
134 MSGBOX_STYLE_NONE, 3000);
137 __pMessageBox->ShowAndWait(modalResult);
138 __overlayMsg = false;
139 delete __pMessageBox;
140 __pMessageBox = null;
143 __pNameEditField->SetText(__nameEditFieldTempText);
144 __pNameEditField->SetFocus();
149 ByteBuffer* buffer = StringUtil::StringToUtf8N(inputString);
153 remaining = buffer->GetRemaining();
156 if (remaining >= ALBUM_MAX_LENGTH)
158 if (__pMessageBox == null)
160 __pMessageBox = new (std::nothrow) MessageBox();
161 __pMessageBox->Construct(L"",
162 ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED"),
163 MSGBOX_STYLE_NONE, 3000);
165 __pMessageBox->ShowAndWait(modalResult);
166 delete __pMessageBox;
167 __pMessageBox = null;
170 __pNameEditField->SetText(__nameEditFieldTempText);
171 __pNameEditField->SetFocus();
175 __nameEditFieldTempText = inputString;
180 FooterItemStatus itemStatus;
181 GetFooter()->GetItemStatus(0, itemStatus);
182 if (inputString.GetLength() == 0)
184 if (itemStatus != FOOTER_ITEM_STATUS_DISABLED)
186 GetFooter()->SetItemEnabled(0, false);
191 if (itemStatus == FOOTER_ITEM_STATUS_DISABLED)
193 GetFooter()->SetItemEnabled(0, true);
196 GetFooter()->Invalidate(true);
198 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
202 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
204 AppLogDebug("ENTER");
205 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
209 AlbumNameEditorForm::OnTerminating(void)
211 AppLogDebug("ENTER");
212 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
217 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
222 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
224 __overlayMsg = false;
225 if (res != COMPLETE_SUCCESS)
227 __pNameEditField->SetText(__nameEditFieldPreText);
228 __pNameEditField->HideKeypad();
229 __pNameEditField->Draw();
230 SceneManager* pSceneManager = SceneManager::GetInstance();
231 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
236 AlbumNameEditorForm::OnRenameAlbum(const String& strOri)
238 AppLogDebug("Rename Album");
240 path.Append(Tizen::System::Environment::GetMediaPath());
241 path.Append(__nameEditFieldText);
244 result r = __pPresentationModel->RenameAlbum(strOri, path, this);
247 AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
248 if (__pMessageBox == null)
250 __pMessageBox = new (std::nothrow) MessageBox();
251 __pMessageBox->Construct(L"", L"Unable to rename", MSGBOX_STYLE_NONE, 3000);
254 __pMessageBox->ShowAndWait(modalResult);
255 __overlayMsg = false;
256 delete __pMessageBox;
257 __pMessageBox = null;
258 SceneManager* pSceneManager = SceneManager::GetInstance();
259 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
265 Rectangle clientRect= GetClientAreaBounds();
266 Rectangle rect(0,0,clientRect.width,clientRect.height);
267 __pProgressAnim = new (std::nothrow) ProgressAnimation;
268 __pProgressAnim->Construct(rect);
269 AddControl(*__pProgressAnim);
270 __pProgressAnim->SetShowState(true);
271 __pProgressAnim->AnimationStart();
272 __pProgressAnim->Draw();
279 AlbumNameEditorForm::OnCreateAlbum(void)
282 __pNameEditField->HideKeypad();
283 __pNameEditField->RequestRedraw();
284 path.Append(Tizen::System::Environment::GetMediaPath());
285 path.Append(__nameEditFieldText);
287 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
289 Directory::Create(path, true);
292 __nameEditFieldPreText = __nameEditFieldText;
296 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
297 delete __pMoveIndexList;
298 __pMoveIndexList = null;
302 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
304 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
305 delete __pMoveIndexList;
306 __pMoveIndexList = null;
311 GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
312 __pFileMove = new FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
313 result r = __pFileMove->StartTimer();
319 __pNameEditField->SetText(__nameEditFieldPreText);
320 __pNameEditField->HideKeypad();
321 __pNameEditField->Draw();
322 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
323 SceneManager* pSceneManager = SceneManager::GetInstance();
324 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
328 AppLogDebug("MoveToContentFileList content in progress");
333 void AlbumNameEditorForm::OnAlbumRenameComplete(void)
336 __pProgressAnim->AnimationStop();
337 __pProgressAnim->SetShowState(false);
338 RemoveControl(*__pProgressAnim);
339 __overlayMsg = false;
340 SceneManager* pSceneManager = SceneManager::GetInstance();
341 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
346 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
348 AppLogDebug("ENTER");
349 SceneManager* pSceneManager = SceneManager::GetInstance();
353 __nameEditFieldText = __pNameEditField->GetText();
355 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
357 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
358 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
359 pPath = pAlbumInfo->GetDirectory(0);
365 case ACTION_ID_BUTTON_CREATE_NAME_SAVE:
367 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
372 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
375 OnRenameAlbum(strOri);
383 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
387 AlbumNameEditorForm::OnFormBackRequested(Form& source)
389 AppLogDebug("ENTER");
390 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
392 SceneManager* pSceneManager = SceneManager::GetInstance();
393 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
397 SceneManager* pSceneManager = SceneManager::GetInstance();
398 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
400 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
404 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
405 const SceneId& currentSceneId, IList* pArgs)
407 AppLogDebug("ENTER");
408 __pPresentationModel = AlbumListPresentationModel::GetInstance();
409 __previousSceneId = previousSceneId;
413 Integer* albumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
414 if (albumTypePtr->ToInt() == ALBUM_CREATE)
416 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
417 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
419 else if (albumTypePtr->ToInt() == ALBUM_RENAME)
421 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
422 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
424 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
427 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
431 IEnumerator* pEnum = pArgs->GetEnumeratorN();
432 if (pEnum->MoveNext() == E_SUCCESS)
434 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
437 __folderIndex = index->ToInt();
445 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
446 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
447 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
448 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
450 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
452 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
454 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
456 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
459 __callerSceneId = previousSceneId;
463 __callerSceneId = EMPTY_SPACE;
468 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
471 __nameEditFieldText = EMPTY_SPACE;
472 __nameEditFieldPreText = EMPTY_SPACE;
473 __pNameEditField->SetText(__nameEditFieldText);
474 __nameEditFieldTempText = __nameEditFieldText;
475 __pNameEditField->SetFocus();
476 GetHeader()->SetTitleText(L"Create album");
477 GetFooter()->SetItemEnabled(0, false);
478 GetFooter()->Invalidate(true);
484 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
485 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
487 strName = pAlbumInfo->GetAlbumName();
488 __nameEditFieldText = strName;
489 __nameEditFieldPreText = strName;
490 __pNameEditField->SetText(__nameEditFieldText);
491 GetHeader()->SetTitleText(L"Rename");
492 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
493 __pNameEditField->SetFocus();
499 __pMoveIndexList = pArgs;
502 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
506 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
507 const SceneId& nextSceneId)
509 AppLogDebug("ENTER");
510 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));