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 , __albumNameEditorMode(ALBUM_NAME_EDITOR_MODE_RENAME)
59 , __pMoveIndexList(null)
60 , __fileActionMode(FILE_ACTION_MOVE)
62 , __pPresentationModel(null)
63 , __pFilePresentationModel(null)
67 _pProgressAnim = null;
68 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
71 AlbumNameEditorForm::~AlbumNameEditorForm(void)
74 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
76 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
80 AlbumNameEditorForm::Initialize(void)
83 result r = Construct(L"IDL_FORM_ALBUM_NAME_EDITOR");
84 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
90 AlbumNameEditorForm::OnInitializing(void)
93 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
94 __pFilePresentationModel = FileListPresentationModel::GetInstance();
96 SetOrientation(ORIENTATION_AUTOMATIC);
97 AddOrientationEventListener(*this);
99 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *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->AddActionEventListener(*this);
125 AlbumNameEditorForm::OnTextValueChanged(const Control& source)
129 String specialCharacters(L"/");
130 String byteCountForInput;
133 int tempLength = 255;
135 MessageBox messageBox;
138 FooterItemStatus currentStatus = FOOTER_ITEM_STATUS_NORMAL;
140 result r = E_SUCCESS;
142 if (__pNameEditField != null)
144 byteCountForInput = __pNameEditField->GetText();
145 r = utf8.GetByteCount(byteCountForInput, byteCount);
146 AppLogDebug("result is %s",GetErrorMessage(r));
147 AppLogDebug("Byte count is %d",byteCount);
150 if (__pNameEditField != null)
152 currentText = __pNameEditField->GetText();
153 textToCheck = currentText.GetLength() - __textLength;
154 if (currentText.IsEmpty())
156 if (GetFooter() != null)
158 GetFooter()->SetItemEnabled(0, false);
159 GetFooter()->Invalidate(true);
164 if (GetFooter() != null)
166 GetFooter()->GetItemStatus(0, currentStatus);
168 if (currentStatus == FOOTER_ITEM_STATUS_DISABLED)
170 GetFooter()->SetItemEnabled(0,true);
171 GetFooter()->Invalidate(true);
176 if (currentText.StartsWith(".", 0))
178 String invalidCharacterString;
180 String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS");
182 validString = __pNameEditField->GetText();
184 if (validString.GetLength() > 1)
186 validString.Remove(0,1);
187 __pNameEditField->SetText(validString);
191 __pNameEditField->SetText("");
193 if (GetFooter() != null)
195 GetFooter()->SetItemEnabled(0, false);
196 GetFooter()->Invalidate(true);
199 __pNameEditField->ShowKeypad();
202 currentInput = __pNameEditField->GetText();
204 if (currentInput.Contains(specialCharacters[0]))
206 String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS");
208 currentInput.Replace("/", "");
209 __pNameEditField->SetText(currentInput);
211 if (currentInput == L"")
213 if (GetFooter() != null)
215 GetFooter()->SetItemEnabled(0, false);
216 GetFooter()->Invalidate(true);
221 byteCountForInput = __pNameEditField->GetText();
222 r = utf8.GetByteCount(byteCountForInput, inputLength);
224 if (inputLength >= tempLength)
226 String maxCharacterString;
227 String currentInputCharacter;
228 int checkByteCount = 0;
229 int lengthOfFinalString = 0;
230 int currentCharacter = 0;
232 String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED");
234 currentText = __pNameEditField->GetText();
236 for (currentCharacter=0; checkByteCount < tempLength; ++currentCharacter)
238 currentInputCharacter.Clear();
239 currentInputCharacter = currentText[currentCharacter];
240 r = utf8.GetByteCount(currentInputCharacter, byteCount);
245 AppLogDebug("result of byte count is %s",GetErrorMessage(r));
246 checkByteCount = checkByteCount + byteCount;
248 if (checkByteCount < tempLength)
250 ++lengthOfFinalString;
254 r = __pNameEditField->GetText().SubString(0, lengthOfFinalString, currentInput);
255 AppLogDebug("current input is %S", currentInput.GetPointer());
256 r = __pNameEditField->SetText(currentInput);
257 __pNameEditField->ShowKeypad();
261 r = utf8.GetByteCount(__pNameEditField->GetText(), byteCount);
262 __textLength = byteCount;
265 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
269 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
271 AppLogDebug("ENTER");
272 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
276 AlbumNameEditorForm::OnTerminating(void)
278 AppLogDebug("ENTER");
279 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
284 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
289 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
292 if (res != COMPLETE_SUCCESS)
294 __pNameEditField->SetText(__nameEditFieldPreText);
295 __pNameEditField->HideKeypad();
296 __pNameEditField->Draw();
297 SceneManager* pSceneManager = SceneManager::GetInstance();
298 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
303 AlbumNameEditorForm::OnRenameAlbum(String& strOri)
305 AppLogDebug("Rename Album");
309 strOri.IndexOf(DIRECTORY_SEPARATOR, 0, index);
311 strOri.SubString(0, (strOri.GetLength() - index), path);
312 path.Append(__nameEditFieldText);
315 result r = __pPresentationModel->RenameAlbum(strOri, path, this);
319 AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
320 if (__pMessageBox == null)
322 __pMessageBox = new (std::nothrow) MessageBox();
323 if (r == E_FILE_ALREADY_EXIST)
325 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
326 MSGBOX_STYLE_NONE, 3000);
331 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
332 MSGBOX_STYLE_NONE, 3000);
336 __pMessageBox->ShowAndWait(modalResult);
338 delete __pMessageBox;
339 __pMessageBox = null;
340 __pNameEditField->SetEnabled(true);
341 __pNameEditField->ShowKeypad();
347 Rectangle clientRect = Form::GetBounds();
348 Rectangle rect(0, 0, clientRect.width, clientRect.height);
349 _pProgressAnim = new (std::nothrow) ProgressAnimation;
350 _pProgressAnim->Construct(rect);
351 AddControl(_pProgressAnim);
352 _pProgressAnim->SetShowState(true);
353 GetFooter()->SetEnabled(false);
354 _pProgressAnim->AnimationStart();
355 _pProgressAnim->Draw();
361 AlbumNameEditorForm::ShowAnimation()
363 Rectangle clientRect= GetClientAreaBounds();
364 Rectangle rect(0, 0, clientRect.width, clientRect.height);
365 _pProgressAnim = new (std::nothrow) ProgressAnimation;
366 _pProgressAnim->Construct(rect);
367 AddControl(_pProgressAnim);
368 _pProgressAnim->SetShowState(true);
369 GetFooter()->SetEnabled(false);
370 _pProgressAnim->AnimationStart();
371 _pProgressAnim->Draw();
376 AlbumNameEditorForm::StopAnimation(void)
380 _pProgressAnim->AnimationStop();
381 _pProgressAnim->SetShowState(false);
382 RemoveControl(_pProgressAnim);
383 GetFooter()->SetEnabled(true);
384 _pProgressAnim = null;
390 AlbumNameEditorForm::OnCreateAlbum(void)
393 __pNameEditField->HideKeypad();
394 __pNameEditField->RequestRedraw();
395 path.Append(Tizen::System::Environment::GetMediaPath());
396 path.Append(__nameEditFieldText);
398 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
400 Directory::Create(path, true);
403 __nameEditFieldPreText = __nameEditFieldText;
407 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
408 delete __pMoveIndexList;
409 __pMoveIndexList = null;
413 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
415 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
416 delete __pMoveIndexList;
417 __pMoveIndexList = null;
422 GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
423 __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
424 if (__fileActionMode == FILE_ACTION_COPY)
426 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
427 __pFileMove->SetCopy();
431 __pFileMove->ClearCopy();
433 result r = __pFileMove->StartTimer();
439 __pNameEditField->SetText(__nameEditFieldPreText);
440 __pNameEditField->HideKeypad();
441 __pNameEditField->Draw();
443 String msg = ResourceManager::GetString(L"IDS_COM_BODY_OPERATION_FAILED");
445 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
446 SceneManager* pSceneManager = SceneManager::GetInstance();
447 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
451 AppLogDebug("MoveToContentFileList content in progress");
453 __fileActionMode = FILE_ACTION_MOVE;
458 AlbumNameEditorForm::OnAlbumRenameComplete(void)
461 _pProgressAnim->AnimationStop();
462 _pProgressAnim->SetShowState(false);
463 RemoveControl(_pProgressAnim);
465 GetFooter()->SetEnabled(true);
466 SceneManager* pSceneManager = SceneManager::GetInstance();
467 pSceneManager->GoBackward((BackwardSceneTransition(IDSCN_ALBUM_LIST)));
471 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
473 AppLogDebug("ENTER");
475 __nameEditFieldText = __pNameEditField->GetText();
477 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
479 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
480 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
481 path = pAlbumInfo->GetDirectory(0);
486 case IDA_BUTTON_CREATE_NAME_SAVE:
488 __pNameEditField->SetEnabled(false);
489 GetFooter()->SetItemEnabled(0, false);
491 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
495 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
497 String albumName = __pNameEditField->GetText();
498 if (__originalText.Equals(albumName, true))
500 SceneManager* pSceneManager = SceneManager::GetInstance();
501 pSceneManager->GoBackward(BackwardSceneTransition());
514 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
518 AlbumNameEditorForm::OnFormBackRequested(Form& source)
520 AppLogDebug("ENTER");
521 if (_pProgressAnim != null)
523 if (_pProgressAnim->GetShowState())
529 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
531 SceneManager* pSceneManager = SceneManager::GetInstance();
532 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
536 SceneManager* pSceneManager = SceneManager::GetInstance();
537 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
539 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
543 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
544 const SceneId& currentSceneId, IList* pArgs)
546 AppLogDebug("ENTER");
547 __pPresentationModel = AlbumListPresentationModel::GetInstance();
548 __previousSceneId = previousSceneId;
551 __pPresentationModel->AddContentEventListener(this);
555 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
556 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
558 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
559 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
561 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
563 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
564 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
566 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
571 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
572 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
574 AppLogDebug("Rash: FILE_MOVE_ACTION");
575 __fileActionMode = FILE_ACTION_MOVE;
577 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
579 AppLogDebug("Rash: FILE_COPY_ACTION");
580 __fileActionMode = FILE_ACTION_COPY;
582 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
585 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
589 IEnumerator* pEnum = pArgs->GetEnumeratorN();
590 if (pEnum->MoveNext() == E_SUCCESS)
592 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
595 __folderIndex = index->ToInt();
604 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
605 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
606 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
607 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
609 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
611 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
613 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
615 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
618 __callerSceneId = previousSceneId;
622 __callerSceneId = EMPTY_SPACE;
625 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
627 __nameEditFieldText = EMPTY_SPACE;
628 __nameEditFieldPreText = EMPTY_SPACE;
629 __pNameEditField->SetText(__nameEditFieldText);
630 __nameEditFieldTempText = __nameEditFieldText;
631 __pNameEditField->ShowKeypad();
632 __pNameEditField->SetFocus();
634 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
635 GetFooter()->SetItemEnabled(0, false);
636 GetFooter()->Invalidate(true);
642 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
643 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
645 String strName = pAlbumInfo->GetAlbumName();
646 __nameEditFieldText = strName;
647 __nameEditFieldPreText = strName;
648 __pNameEditField->SetText(__nameEditFieldText);
649 __nameEditFieldTempText = __nameEditFieldText;
650 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
651 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
652 __pNameEditField->ShowKeypad();
653 __pNameEditField->SetFocus();
654 __originalText = __pNameEditField->GetText();
655 utf8.GetByteCount(__nameEditFieldText, byteCount);
656 __textLength = byteCount;
657 GetFooter()->SetItemEnabled(0, true);
658 GetFooter()->Invalidate(true);
663 __pMoveIndexList = pArgs;
666 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
670 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
671 const SceneId& nextSceneId)
673 AppLogDebug("ENTER");
675 if(__pNameEditField->IsEnabled() == false)
677 __pNameEditField->SetEnabled(true);
680 __pPresentationModel->RemoveContentEventListener(*this);
681 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
685 AlbumNameEditorForm::OnContentUpdated(void)
687 AppLogDebug("ENTER");
689 if (__mountState == false)
691 SceneManager* pSceneManager = SceneManager::GetInstance();
692 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
693 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
697 __mountState = false;
702 AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
704 AppLogDebug("ENTER");
706 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
708 if (__pFileMove && __pFileMove->IsStarted())
710 __pFileMove->Cancel();
714 __mountState = false;
715 SceneManager* pSceneManager = SceneManager::GetInstance();
716 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
717 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
723 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
727 AlbumNameEditorForm::CreateMessage(String& str)
729 if (__pMessageBox == null)
731 __pMessageBox = new(std::nothrow) MessageBox;
733 if (__pMessageBox != null)
735 __pMessageBox->Construct(L"", str, MSGBOX_STYLE_OK, 3000);
736 __pMessageBox->ShowAndWait(__modalMsgBoxResult);
738 delete __pMessageBox;
739 __pMessageBox = null;
740 __modalMsgBoxResult = 0;
746 AlbumNameEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
748 if (_pProgressAnim != null)
750 _pProgressAnim->ChangeOrientation(Form::GetBounds());
751 _pProgressAnim->Invalidate(true);