2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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.
25 #include "GlAlbumInfo.h"
26 #include "GlAlbumListPresentationModel.h"
27 #include "GlAlbumNameEditorForm.h"
28 #include "GlFileListPresentationModel.h"
29 #include "GlFileMoveTimer.h"
30 #include "GlProgressAnimation.h"
31 #include "GlResourceManager.h"
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Base::Utility;
39 using namespace Tizen::Content;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Io;
42 using namespace Tizen::Media;
43 using namespace Tizen::System;
44 using namespace Tizen::Text;
45 using namespace Tizen::Ui;
46 using namespace Tizen::Ui::Controls;
47 using namespace Tizen::Ui::Scenes;
49 static const unsigned int COLOR_NAME_EDIT_FIELD = Color32<255, 255, 255>::Value;
51 AlbumNameEditorForm::AlbumNameEditorForm(void)
52 : __pNameEditField(null)
54 , __modalMsgBoxResult(0)
57 , __isCreateAlbum(false)
58 , __isKeyPadOpen(false)
59 , __albumNameEditorMode(ALBUM_NAME_EDITOR_MODE_RENAME)
61 , __pMoveIndexList(null)
62 , __fileActionMode(FILE_ACTION_MOVE)
64 , __pPresentationModel(null)
65 , __pFilePresentationModel(null)
69 _pProgressAnim = null;
70 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
73 AlbumNameEditorForm::~AlbumNameEditorForm(void)
77 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
81 AlbumNameEditorForm::Initialize(void)
84 result r = Construct(L"IDL_FORM_ALBUM_NAME_EDITOR");
85 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
91 AlbumNameEditorForm::OnInitializing(void)
94 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
95 __pFilePresentationModel = FileListPresentationModel::GetInstance();
97 SetOrientation(ORIENTATION_AUTOMATIC);
98 AddOrientationEventListener(*this);
100 Header* pHeader = GetHeader();
102 pHeader->SetStyle(HEADER_STYLE_TITLE);
105 itemSave.Construct(IDA_BUTTON_CREATE_NAME_SAVE);
106 itemSave.SetText(ResourceManager::GetString(L"IDS_COM_OPT_SAVE"));
108 GetFooter()->AddItem(itemSave);
109 GetFooter()->AddActionEventListener(*this);
110 GetFooter()->Invalidate(true);
112 SetFormBackEventListener(this);
113 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
115 __pNameEditField = static_cast<EditField*>(GetControl(L"IDC_EDITFIELD_NAME"));
116 __pNameEditField->AddTextEventListener(*this);
117 __pNameEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_NAME_EDIT_FIELD);
118 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
119 __pNameEditField->AddKeypadEventListener(*this);
120 __pNameEditField->AddActionEventListener(*this);
126 AlbumNameEditorForm::OnTextValueChanged(const Control& source)
130 String specialCharacters(L"/");
131 String byteCountForInput;
134 int tempLength = 255;
136 MessageBox messageBox;
139 FooterItemStatus currentStatus = FOOTER_ITEM_STATUS_NORMAL;
141 result r = E_SUCCESS;
143 if (__pNameEditField != null)
145 byteCountForInput = __pNameEditField->GetText();
146 r = utf8.GetByteCount(byteCountForInput, byteCount);
147 AppLogDebug("result is %s",GetErrorMessage(r));
148 AppLogDebug("Byte count is %d",byteCount);
151 if (__pNameEditField != null)
153 currentText = __pNameEditField->GetText();
154 textToCheck = currentText.GetLength() - __textLength;
155 if (currentText.IsEmpty())
157 if (GetFooter() != null)
159 GetFooter()->SetItemEnabled(0, false);
160 GetFooter()->Invalidate(true);
165 if (GetFooter() != null)
167 GetFooter()->GetItemStatus(0, currentStatus);
169 if (currentStatus == FOOTER_ITEM_STATUS_DISABLED)
171 GetFooter()->SetItemEnabled(0,true);
172 GetFooter()->Invalidate(true);
177 if (currentText.StartsWith(".", 0))
179 String invalidCharacterString;
181 String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS");
183 validString = __pNameEditField->GetText();
185 if (validString.GetLength() > 1)
187 validString.Remove(0,1);
188 __pNameEditField->SetText(validString);
192 __pNameEditField->SetText("");
194 if (GetFooter() != null)
196 GetFooter()->SetItemEnabled(0, false);
197 GetFooter()->Invalidate(true);
200 __pNameEditField->ShowKeypad();
203 currentInput = __pNameEditField->GetText();
205 if (currentInput.Contains(specialCharacters[0]))
207 String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS");
209 currentInput.Replace("/", "");
210 __pNameEditField->SetText(currentInput);
212 if (currentInput == L"")
214 if (GetFooter() != null)
216 GetFooter()->SetItemEnabled(0, false);
217 GetFooter()->Invalidate(true);
222 byteCountForInput = __pNameEditField->GetText();
223 r = utf8.GetByteCount(byteCountForInput, inputLength);
225 if ( inputLength == tempLength )
227 String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED");
229 __pNameEditField->ShowKeypad();
232 else if (inputLength > tempLength)
234 String maxCharacterString;
235 String currentInputCharacter;
236 int checkByteCount = 0;
237 int lengthOfFinalString = 0;
238 int currentCharacter = 0;
240 String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED");
242 currentText = __pNameEditField->GetText();
244 for (currentCharacter=0; checkByteCount < tempLength; ++currentCharacter)
246 currentInputCharacter.Clear();
247 currentInputCharacter = currentText[currentCharacter];
248 r = utf8.GetByteCount(currentInputCharacter, byteCount);
253 AppLogDebug("result of byte count is %s",GetErrorMessage(r));
254 checkByteCount = checkByteCount + byteCount;
256 if (checkByteCount < tempLength)
258 ++lengthOfFinalString;
262 r = __pNameEditField->GetText().SubString(0, lengthOfFinalString, currentInput);
263 AppLogDebug("current input is %S", currentInput.GetPointer());
264 r = __pNameEditField->SetText(currentInput);
265 __pNameEditField->ShowKeypad();
269 r = utf8.GetByteCount(__pNameEditField->GetText(), byteCount);
270 __textLength = byteCount;
273 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
277 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
279 AppLogDebug("ENTER");
280 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
284 AlbumNameEditorForm::OnTerminating(void)
286 AppLogDebug("ENTER");
287 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
292 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
297 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
300 if (res != COMPLETE_SUCCESS)
302 __pNameEditField->SetText(__nameEditFieldPreText);
303 __pNameEditField->HideKeypad();
304 __pNameEditField->Draw();
305 SceneManager* pSceneManager = SceneManager::GetInstance();
306 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
311 AlbumNameEditorForm::OnRenameAlbum(String& strOri)
313 AppLogDebug("Rename Album");
317 strOri.IndexOf(DIRECTORY_SEPARATOR, 0, index);
319 strOri.SubString(0, (strOri.GetLength() - index), path);
320 path.Append(__nameEditFieldText);
323 result r = __pPresentationModel->RenameAlbum(strOri, path, this);
327 AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
328 if (__pMessageBox == null)
330 __pMessageBox = new (std::nothrow) MessageBox();
331 if (r == E_FILE_ALREADY_EXIST)
333 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
334 MSGBOX_STYLE_NONE, 3000);
339 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
340 MSGBOX_STYLE_NONE, 3000);
344 __pMessageBox->ShowAndWait(modalResult);
346 delete __pMessageBox;
347 __pMessageBox = null;
348 __pNameEditField->SetEnabled(true);
349 __pNameEditField->ShowKeypad();
355 Rectangle clientRect = Form::GetBounds();
356 Rectangle rect(0, 0, clientRect.width, clientRect.height);
357 _pProgressAnim = new (std::nothrow) ProgressAnimation;
358 _pProgressAnim->Construct(rect);
359 AddControl(_pProgressAnim);
360 _pProgressAnim->SetShowState(true);
361 GetFooter()->SetEnabled(false);
362 _pProgressAnim->AnimationStart();
363 _pProgressAnim->Draw();
369 AlbumNameEditorForm::ShowAnimation()
371 Rectangle clientRect= GetClientAreaBounds();
372 Rectangle rect(0, 0, clientRect.width, clientRect.height);
373 _pProgressAnim = new (std::nothrow) ProgressAnimation;
374 _pProgressAnim->Construct(rect);
375 AddControl(_pProgressAnim);
376 _pProgressAnim->SetShowState(true);
377 GetFooter()->SetEnabled(false);
378 _pProgressAnim->AnimationStart();
379 _pProgressAnim->Draw();
384 AlbumNameEditorForm::StopAnimation(void)
388 _pProgressAnim->AnimationStop();
389 _pProgressAnim->SetShowState(false);
390 RemoveControl(_pProgressAnim);
391 GetFooter()->SetEnabled(true);
392 _pProgressAnim = null;
398 AlbumNameEditorForm::OnCreateAlbum(void)
401 path.Append(Tizen::System::Environment::GetMediaPath());
402 path.Append(__nameEditFieldText);
404 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
406 Directory::Create(path, true);
409 __nameEditFieldPreText = __nameEditFieldText;
413 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
414 delete __pMoveIndexList;
415 __pMoveIndexList = null;
419 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
421 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
422 delete __pMoveIndexList;
423 __pMoveIndexList = null;
428 __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
429 if (__fileActionMode == FILE_ACTION_COPY)
431 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
432 __pFileMove->SetCopy();
436 __pFileMove->ClearCopy();
438 result r = __pFileMove->StartTimer();
444 __pNameEditField->SetText(__nameEditFieldPreText);
445 __pNameEditField->HideKeypad();
446 __pNameEditField->Draw();
448 String msg = ResourceManager::GetString(L"IDS_COM_BODY_OPERATION_FAILED");
450 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
451 SceneManager* pSceneManager = SceneManager::GetInstance();
452 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
456 AppLogDebug("MoveToContentFileList content in progress");
458 __fileActionMode = FILE_ACTION_MOVE;
463 AlbumNameEditorForm::OnAlbumRenameComplete(void)
466 _pProgressAnim->AnimationStop();
467 _pProgressAnim->SetShowState(false);
468 RemoveControl(_pProgressAnim);
470 GetFooter()->SetEnabled(true);
471 SceneManager* pSceneManager = SceneManager::GetInstance();
472 pSceneManager->GoBackward((BackwardSceneTransition(IDSCN_ALBUM_LIST)));
476 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
478 AppLogDebug("ENTER");
480 __nameEditFieldText = __pNameEditField->GetText();
482 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
484 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
485 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
486 path = pAlbumInfo->GetDirectory(0);
491 case IDA_BUTTON_CREATE_NAME_SAVE:
493 __pNameEditField->SetEnabled(false);
494 __isCreateAlbum = false;
495 GetFooter()->SetItemEnabled(0, false);
497 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
499 if (__isKeyPadOpen == true )
501 __pNameEditField->HideKeypad();
502 __isCreateAlbum = true;
510 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
512 String albumName = __pNameEditField->GetText();
513 if (__originalText.Equals(albumName, true))
515 SceneManager* pSceneManager = SceneManager::GetInstance();
516 pSceneManager->GoBackward(BackwardSceneTransition());
529 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
533 AlbumNameEditorForm::OnFormBackRequested(Form& source)
535 AppLogDebug("ENTER");
536 if (_pProgressAnim != null)
538 if (_pProgressAnim->GetShowState())
544 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
546 SceneManager* pSceneManager = SceneManager::GetInstance();
547 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
551 SceneManager* pSceneManager = SceneManager::GetInstance();
552 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
554 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
558 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
559 const SceneId& currentSceneId, IList* pArgs)
561 AppLogDebug("ENTER");
562 __pPresentationModel = AlbumListPresentationModel::GetInstance();
563 __previousSceneId = previousSceneId;
565 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
566 __pPresentationModel->AddContentEventListener(this);
570 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
571 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
573 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
574 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
576 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
578 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
579 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
581 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
586 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
587 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
589 AppLogDebug("Rash: FILE_MOVE_ACTION");
590 __fileActionMode = FILE_ACTION_MOVE;
592 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
594 AppLogDebug("Rash: FILE_COPY_ACTION");
595 __fileActionMode = FILE_ACTION_COPY;
597 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
600 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
604 IEnumerator* pEnum = pArgs->GetEnumeratorN();
605 if (pEnum->MoveNext() == E_SUCCESS)
607 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
610 __folderIndex = index->ToInt();
619 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
620 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
621 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
622 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
624 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
626 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
628 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
630 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
633 __callerSceneId = previousSceneId;
637 __callerSceneId = EMPTY_SPACE;
640 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
642 __nameEditFieldText = EMPTY_SPACE;
643 __nameEditFieldPreText = EMPTY_SPACE;
644 __pNameEditField->SetText(__nameEditFieldText);
645 __nameEditFieldTempText = __nameEditFieldText;
646 __pNameEditField->ShowKeypad();
647 __pNameEditField->SetFocus();
649 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
650 GetFooter()->SetItemEnabled(0, false);
651 GetFooter()->Invalidate(true);
657 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
658 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
660 String strName = pAlbumInfo->GetAlbumName();
661 __nameEditFieldText = strName;
662 __nameEditFieldPreText = strName;
663 __pNameEditField->SetText(__nameEditFieldText);
664 __nameEditFieldTempText = __nameEditFieldText;
665 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
666 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
667 __pNameEditField->ShowKeypad();
668 __pNameEditField->SetFocus();
669 __originalText = __pNameEditField->GetText();
670 utf8.GetByteCount(__nameEditFieldText, byteCount);
671 __textLength = byteCount;
672 GetFooter()->SetItemEnabled(0, true);
673 GetFooter()->Invalidate(true);
678 __pMoveIndexList = pArgs;
681 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
685 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
686 const SceneId& nextSceneId)
688 AppLogDebug("ENTER");
690 if(__pNameEditField->IsEnabled() == false)
692 __pNameEditField->SetEnabled(true);
695 __isKeyPadOpen = false;
697 __pPresentationModel->RemoveContentEventListener(*this);
698 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
700 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
704 AlbumNameEditorForm::OnContentUpdated(void)
706 AppLogDebug("ENTER");
708 if (__mountState == false)
710 if (__pFileMove && __pFileMove->IsStarted())
712 __pFileMove->Cancel();
717 SceneManager* pSceneManager = SceneManager::GetInstance();
718 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
719 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
723 __mountState = false;
728 AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
730 AppLogDebug("ENTER");
732 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
734 if (__pFileMove && __pFileMove->IsStarted())
736 __pFileMove->Cancel();
740 __mountState = false;
741 SceneManager* pSceneManager = SceneManager::GetInstance();
742 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
743 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
749 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
753 AlbumNameEditorForm::CreateMessage(String& str)
755 if (__pMessageBox == null)
757 __pMessageBox = new(std::nothrow) MessageBox;
759 if (__pMessageBox != null)
761 __pMessageBox->Construct(L"", str, MSGBOX_STYLE_OK, 3000);
762 __pMessageBox->ShowAndWait(__modalMsgBoxResult);
764 delete __pMessageBox;
765 __pMessageBox = null;
766 __modalMsgBoxResult = 0;
772 AlbumNameEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
774 if (_pProgressAnim != null)
776 _pProgressAnim->ChangeOrientation(Form::GetBounds());
777 _pProgressAnim->Invalidate(true);
782 AlbumNameEditorForm::OnKeypadClosed(Tizen::Ui::Control& source)
784 AppLogDebug("ENTER");
786 if ( __isCreateAlbum == true)
789 __isCreateAlbum = false;
791 __isKeyPadOpen = false;
792 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
796 AlbumNameEditorForm::OnKeypadOpened(Tizen::Ui::Control& source)
798 AppLogDebug("ENTER");
799 __isKeyPadOpen = true;
800 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));