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 "GlAlbumListPresentationModel.h"
25 #include "GlAlbumNameEditorForm.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlFileMoveTimer.h"
28 #include "GlProgressAnimation.h"
29 #include "GlResourceManager.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::Io;
40 using namespace Tizen::Media;
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(void)
51 : __pNameEditField(null)
53 , __albumNameEditorMode(ALBUM_NAME_EDITOR_MODE_RENAME)
55 , __pMoveIndexList(null)
56 , __fileActionMode(FILE_ACTION_MOVE)
58 , __pProgressAnim(null)
59 , __pPresentationModel(null)
60 , __pFilePresentationModel(null)
64 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
67 AlbumNameEditorForm::~AlbumNameEditorForm(void)
71 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
75 AlbumNameEditorForm::Initialize(void)
78 result r = Construct(FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR);
79 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
85 AlbumNameEditorForm::OnInitializing(void)
88 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
89 __pFilePresentationModel = FileListPresentationModel::GetInstance();
91 Header* pHeader = GetHeader();
93 pHeader->SetStyle(HEADER_STYLE_TITLE);
95 GetFooter()->SetBackButtonEnabled(true);
96 GetFooter()->SetBackButton();
99 itemSave.Construct(IDA_BUTTON_CREATE_NAME_SAVE);
100 itemSave.SetText(ResourceManager::GetString(L"IDS_COM_OPT_SAVE"));
102 GetFooter()->AddItem(itemSave);
103 GetFooter()->AddActionEventListener(*this);
104 GetFooter()->Invalidate(true);
106 SetFormBackEventListener(this);
107 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);
139 delete __pMessageBox;
140 __pMessageBox = null;
143 __pNameEditField->SetText(__nameEditFieldTempText);
144 __pNameEditField->SetFocus();
149 ByteBuffer* pBuffer = StringUtil::StringToUtf8N(inputString);
153 remaining = pBuffer->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;
179 FooterItemStatus itemStatus;
180 GetFooter()->GetItemStatus(0, itemStatus);
181 if (inputString.GetLength() == 0)
183 if (itemStatus != FOOTER_ITEM_STATUS_DISABLED)
185 GetFooter()->SetItemEnabled(0, false);
190 if (itemStatus == FOOTER_ITEM_STATUS_DISABLED)
192 GetFooter()->SetItemEnabled(0, true);
195 GetFooter()->Invalidate(true);
197 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
201 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
203 AppLogDebug("ENTER");
204 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
208 AlbumNameEditorForm::OnTerminating(void)
210 AppLogDebug("ENTER");
211 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
216 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
221 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
224 if (res != COMPLETE_SUCCESS)
226 __pNameEditField->SetText(__nameEditFieldPreText);
227 __pNameEditField->HideKeypad();
228 __pNameEditField->Draw();
229 SceneManager* pSceneManager = SceneManager::GetInstance();
230 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
235 AlbumNameEditorForm::OnRenameAlbum(String& strOri)
237 AppLogDebug("Rename Album");
241 strOri.IndexOf(DIRECTORY_SEPARATOR, 0, index);
243 strOri.SubString(0, (strOri.GetLength() - index), path);
244 path.Append(__nameEditFieldText);
247 result r = __pPresentationModel->RenameAlbum(strOri, path, this);
251 AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
252 if (__pMessageBox == null)
254 __pMessageBox = new (std::nothrow) MessageBox();
255 if (r == E_FILE_ALREADY_EXIST)
257 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
258 MSGBOX_STYLE_NONE, 3000);
262 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
263 MSGBOX_STYLE_NONE, 3000);
267 __pMessageBox->ShowAndWait(modalResult);
269 delete __pMessageBox;
270 __pMessageBox = null;
276 Rectangle clientRect= GetClientAreaBounds();
277 Rectangle rect(0, 0, clientRect.width, clientRect.height);
278 __pProgressAnim = new (std::nothrow) ProgressAnimation;
279 __pProgressAnim->Construct(rect);
280 AddControl(*__pProgressAnim);
281 __pProgressAnim->SetShowState(true);
282 GetFooter()->SetEnabled(false);
283 __pProgressAnim->AnimationStart();
284 __pProgressAnim->Draw();
290 AlbumNameEditorForm::OnCreateAlbum(void)
293 __pNameEditField->HideKeypad();
294 __pNameEditField->RequestRedraw();
295 path.Append(Tizen::System::Environment::GetMediaPath());
296 path.Append(__nameEditFieldText);
298 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
300 Directory::Create(path, true);
303 __nameEditFieldPreText = __nameEditFieldText;
307 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
308 delete __pMoveIndexList;
309 __pMoveIndexList = null;
313 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
315 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
316 delete __pMoveIndexList;
317 __pMoveIndexList = null;
322 GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
323 __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
324 if (__fileActionMode == FILE_ACTION_COPY)
326 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
327 __pFileMove->SetCopy();
331 __pFileMove->ClearCopy();
333 result r = __pFileMove->StartTimer();
339 __pNameEditField->SetText(__nameEditFieldPreText);
340 __pNameEditField->HideKeypad();
341 __pNameEditField->Draw();
342 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
343 SceneManager* pSceneManager = SceneManager::GetInstance();
344 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
348 AppLogDebug("MoveToContentFileList content in progress");
350 __fileActionMode = FILE_ACTION_MOVE;
354 void AlbumNameEditorForm::OnAlbumRenameComplete(void)
357 __pProgressAnim->AnimationStop();
358 __pProgressAnim->SetShowState(false);
359 RemoveControl(*__pProgressAnim);
361 GetFooter()->SetEnabled(true);
362 SceneManager* pSceneManager = SceneManager::GetInstance();
363 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
367 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
369 AppLogDebug("ENTER");
371 __nameEditFieldText = __pNameEditField->GetText();
373 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
375 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
376 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
377 path = pAlbumInfo->GetDirectory(0);
382 case IDA_BUTTON_CREATE_NAME_SAVE:
384 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
388 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
390 String albumName = __pNameEditField->GetText();
391 if (__originalText.Equals(albumName , true))
393 SceneManager* pSceneManager = SceneManager::GetInstance();
394 pSceneManager->GoBackward(BackwardSceneTransition());
407 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
411 AlbumNameEditorForm::OnFormBackRequested(Form& source)
413 AppLogDebug("ENTER");
414 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
416 SceneManager* pSceneManager = SceneManager::GetInstance();
417 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
421 SceneManager* pSceneManager = SceneManager::GetInstance();
422 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
424 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
428 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
429 const SceneId& currentSceneId, IList* pArgs)
431 AppLogDebug("ENTER");
432 __pPresentationModel = AlbumListPresentationModel::GetInstance();
433 __previousSceneId = previousSceneId;
435 __pPresentationModel->AddContentEventListener(this);
439 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
440 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
442 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
443 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
445 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
447 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
448 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
450 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
455 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
456 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
458 AppLogDebug("Rash: FILE_MOVE_ACTION");
459 __fileActionMode = FILE_ACTION_MOVE;
461 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
463 AppLogDebug("Rash: FILE_COPY_ACTION");
464 __fileActionMode = FILE_ACTION_COPY;
466 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
469 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
473 IEnumerator* pEnum = pArgs->GetEnumeratorN();
474 if (pEnum->MoveNext() == E_SUCCESS)
476 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
479 __folderIndex = index->ToInt();
487 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
488 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
489 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
490 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
492 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
494 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
496 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
498 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
501 __callerSceneId = previousSceneId;
505 __callerSceneId = EMPTY_SPACE;
508 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
510 __nameEditFieldText = EMPTY_SPACE;
511 __nameEditFieldPreText = EMPTY_SPACE;
512 __pNameEditField->SetText(__nameEditFieldText);
513 __nameEditFieldTempText = __nameEditFieldText;
514 __pNameEditField->SetFocus();
516 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
517 GetFooter()->SetItemEnabled(0, false);
518 GetFooter()->Invalidate(true);
523 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
524 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
526 String strName = pAlbumInfo->GetAlbumName();
527 __nameEditFieldText = strName;
528 __nameEditFieldPreText = strName;
529 __pNameEditField->SetText(__nameEditFieldText);
530 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
531 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
532 __pNameEditField->SetFocus();
533 __originalText = __pNameEditField->GetText();
538 __pMoveIndexList = pArgs;
541 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
545 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
546 const SceneId& nextSceneId)
548 AppLogDebug("ENTER");
549 __pPresentationModel->RemoveContentEventListener(*this);
550 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
554 AlbumNameEditorForm::OnContentUpdated(void)
556 AppLogDebug("ENTER");
558 SceneManager* pSceneManager = SceneManager::GetInstance();
559 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
560 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));