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 , __pProgressAnim(null)
63 , __pPresentationModel(null)
64 , __pFilePresentationModel(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 inputLength = byteCount;
222 if (inputLength >= tempLength)
224 String maxCharacterString;
225 String currentInputCharacter;
226 int checkByteCount = 0;
227 int lengthOfFinalString = 0;
228 int currentCharacter = 0;
230 String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED");
232 currentText = __pNameEditField->GetText();
234 for (currentCharacter=0; checkByteCount < tempLength; ++currentCharacter)
236 currentInputCharacter.Clear();
237 currentInputCharacter = currentText[currentCharacter];
238 r = utf8.GetByteCount(currentInputCharacter, byteCount);
243 AppLogDebug("result of byte count is %s",GetErrorMessage(r));
244 checkByteCount = checkByteCount + byteCount;
246 if (checkByteCount < tempLength)
248 ++lengthOfFinalString;
252 r = __pNameEditField->GetText().SubString(0, lengthOfFinalString, currentInput);
253 AppLogDebug("current input is %S", currentInput.GetPointer());
254 r = __pNameEditField->SetText(currentInput);
255 __pNameEditField->ShowKeypad();
259 r = utf8.GetByteCount(__pNameEditField->GetText(), byteCount);
260 __textLength = byteCount;
263 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
267 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
269 AppLogDebug("ENTER");
270 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
274 AlbumNameEditorForm::OnTerminating(void)
276 AppLogDebug("ENTER");
277 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
282 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
287 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
290 if (res != COMPLETE_SUCCESS)
292 __pNameEditField->SetText(__nameEditFieldPreText);
293 __pNameEditField->HideKeypad();
294 __pNameEditField->Draw();
295 SceneManager* pSceneManager = SceneManager::GetInstance();
296 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
301 AlbumNameEditorForm::OnRenameAlbum(String& strOri)
303 AppLogDebug("Rename Album");
307 strOri.IndexOf(DIRECTORY_SEPARATOR, 0, index);
309 strOri.SubString(0, (strOri.GetLength() - index), path);
310 path.Append(__nameEditFieldText);
313 result r = __pPresentationModel->RenameAlbum(strOri, path, this);
317 AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
318 if (__pMessageBox == null)
320 __pMessageBox = new (std::nothrow) MessageBox();
321 if (r == E_FILE_ALREADY_EXIST)
323 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
324 MSGBOX_STYLE_NONE, 3000);
329 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
330 MSGBOX_STYLE_NONE, 3000);
334 __pMessageBox->ShowAndWait(modalResult);
336 delete __pMessageBox;
337 __pMessageBox = null;
338 __pNameEditField->SetEnabled(true);
339 __pNameEditField->ShowKeypad();
345 Rectangle clientRect = Form::GetBounds();
346 Rectangle rect(0, 0, clientRect.width, clientRect.height);
347 __pProgressAnim = new (std::nothrow) ProgressAnimation;
348 __pProgressAnim->Construct(rect);
349 AddControl(__pProgressAnim);
350 __pProgressAnim->SetShowState(true);
351 GetFooter()->SetEnabled(false);
352 __pProgressAnim->AnimationStart();
353 __pProgressAnim->Draw();
359 AlbumNameEditorForm::OnCreateAlbum(void)
362 __pNameEditField->HideKeypad();
363 __pNameEditField->RequestRedraw();
364 path.Append(Tizen::System::Environment::GetMediaPath());
365 path.Append(__nameEditFieldText);
367 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
369 Directory::Create(path, true);
372 __nameEditFieldPreText = __nameEditFieldText;
376 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
377 delete __pMoveIndexList;
378 __pMoveIndexList = null;
382 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
384 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
385 delete __pMoveIndexList;
386 __pMoveIndexList = null;
391 GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
392 __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
393 if (__fileActionMode == FILE_ACTION_COPY)
395 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
396 __pFileMove->SetCopy();
400 __pFileMove->ClearCopy();
402 result r = __pFileMove->StartTimer();
408 __pNameEditField->SetText(__nameEditFieldPreText);
409 __pNameEditField->HideKeypad();
410 __pNameEditField->Draw();
411 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
412 SceneManager* pSceneManager = SceneManager::GetInstance();
413 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
417 AppLogDebug("MoveToContentFileList content in progress");
419 __fileActionMode = FILE_ACTION_MOVE;
423 void AlbumNameEditorForm::OnAlbumRenameComplete(void)
426 __pProgressAnim->AnimationStop();
427 __pProgressAnim->SetShowState(false);
428 RemoveControl(__pProgressAnim);
430 GetFooter()->SetEnabled(true);
431 SceneManager* pSceneManager = SceneManager::GetInstance();
432 pSceneManager->GoBackward((BackwardSceneTransition(IDSCN_ALBUM_LIST)));
436 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
438 AppLogDebug("ENTER");
440 __nameEditFieldText = __pNameEditField->GetText();
442 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
444 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
445 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
446 path = pAlbumInfo->GetDirectory(0);
451 case IDA_BUTTON_CREATE_NAME_SAVE:
453 __pNameEditField->SetEnabled(false);
454 GetFooter()->SetItemEnabled(0, false);
456 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
460 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
462 String albumName = __pNameEditField->GetText();
463 if (__originalText.Equals(albumName, true))
465 SceneManager* pSceneManager = SceneManager::GetInstance();
466 pSceneManager->GoBackward(BackwardSceneTransition());
479 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
483 AlbumNameEditorForm::OnFormBackRequested(Form& source)
485 AppLogDebug("ENTER");
486 if (__pProgressAnim != null)
488 if (__pProgressAnim->GetShowState())
494 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
496 SceneManager* pSceneManager = SceneManager::GetInstance();
497 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
501 SceneManager* pSceneManager = SceneManager::GetInstance();
502 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
504 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
508 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
509 const SceneId& currentSceneId, IList* pArgs)
511 AppLogDebug("ENTER");
512 __pPresentationModel = AlbumListPresentationModel::GetInstance();
513 __previousSceneId = previousSceneId;
515 __pNameEditField->SetEnabled(true);
516 __pPresentationModel->AddContentEventListener(this);
520 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
521 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
523 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
524 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
526 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
528 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
529 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
531 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
536 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
537 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
539 AppLogDebug("Rash: FILE_MOVE_ACTION");
540 __fileActionMode = FILE_ACTION_MOVE;
542 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
544 AppLogDebug("Rash: FILE_COPY_ACTION");
545 __fileActionMode = FILE_ACTION_COPY;
547 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
550 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
554 IEnumerator* pEnum = pArgs->GetEnumeratorN();
555 if (pEnum->MoveNext() == E_SUCCESS)
557 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
560 __folderIndex = index->ToInt();
569 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
570 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
571 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
572 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
574 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
576 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
578 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
580 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
583 __callerSceneId = previousSceneId;
587 __callerSceneId = EMPTY_SPACE;
590 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
592 __nameEditFieldText = EMPTY_SPACE;
593 __nameEditFieldPreText = EMPTY_SPACE;
594 __pNameEditField->SetText(__nameEditFieldText);
595 __nameEditFieldTempText = __nameEditFieldText;
596 __pNameEditField->ShowKeypad();
597 __pNameEditField->SetFocus();
599 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
600 GetFooter()->SetItemEnabled(0, false);
601 GetFooter()->Invalidate(true);
607 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
608 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
610 String strName = pAlbumInfo->GetAlbumName();
611 __nameEditFieldText = strName;
612 __nameEditFieldPreText = strName;
613 __pNameEditField->SetText(__nameEditFieldText);
614 __nameEditFieldTempText = __nameEditFieldText;
615 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
616 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
617 __pNameEditField->ShowKeypad();
618 __pNameEditField->SetFocus();
619 __originalText = __pNameEditField->GetText();
620 utf8.GetByteCount(__nameEditFieldText, byteCount);
621 __textLength = byteCount;
622 GetFooter()->SetItemEnabled(0, true);
623 GetFooter()->Invalidate(true);
628 __pMoveIndexList = pArgs;
631 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
635 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
636 const SceneId& nextSceneId)
638 AppLogDebug("ENTER");
639 __pPresentationModel->RemoveContentEventListener(*this);
640 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
644 AlbumNameEditorForm::OnContentUpdated(void)
646 AppLogDebug("ENTER");
648 if (__mountState == false)
650 SceneManager* pSceneManager = SceneManager::GetInstance();
651 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
652 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
656 __mountState = false;
661 AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
663 AppLogDebug("ENTER");
665 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
667 if (__pFileMove && __pFileMove->IsStarted())
669 __pFileMove->Cancel();
673 __mountState = false;
674 SceneManager* pSceneManager = SceneManager::GetInstance();
675 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
676 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
682 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
686 AlbumNameEditorForm::CreateMessage(String& str)
688 if (__pMessageBox == null)
690 __pMessageBox = new(std::nothrow) MessageBox;
692 if (__pMessageBox != null)
694 __pMessageBox->Construct(L"", str, MSGBOX_STYLE_OK, 3000);
695 __pMessageBox->ShowAndWait(__modalMsgBoxResult);
697 delete __pMessageBox;
698 __pMessageBox = null;
699 __modalMsgBoxResult = 0;
705 AlbumNameEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
707 if (__pProgressAnim != null)
709 __pProgressAnim->ChangeOrientation(Form::GetBounds());
710 __pProgressAnim->Invalidate(true);