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 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
97 Header* pHeader = GetHeader();
99 pHeader->SetStyle(HEADER_STYLE_TITLE);
102 itemSave.Construct(IDA_BUTTON_CREATE_NAME_SAVE);
103 itemSave.SetText(ResourceManager::GetString(L"IDS_COM_OPT_SAVE"));
105 GetFooter()->AddItem(itemSave);
106 GetFooter()->AddActionEventListener(*this);
107 GetFooter()->Invalidate(true);
109 SetFormBackEventListener(this);
110 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
112 __pNameEditField = static_cast<EditField*>(GetControl(L"IDC_EDITFIELD_NAME"));
113 __pNameEditField->AddTextEventListener(*this);
114 __pNameEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_NAME_EDIT_FIELD);
115 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
116 __pNameEditField->AddActionEventListener(*this);
122 AlbumNameEditorForm::OnTextValueChanged(const Control& source)
126 String specialCharacters(L"/");
127 String byteCountForInput;
130 int tempLength = 255;
132 MessageBox messageBox;
135 FooterItemStatus currentStatus = FOOTER_ITEM_STATUS_NORMAL;
137 result r = E_SUCCESS;
139 if (__pNameEditField != null)
141 byteCountForInput = __pNameEditField->GetText();
142 r = utf8.GetByteCount(byteCountForInput, byteCount);
143 AppLogDebug("result is %s",GetErrorMessage(r));
144 AppLogDebug("Byte count is %d",byteCount);
147 if (__pNameEditField != null)
149 currentText = __pNameEditField->GetText();
150 textToCheck = currentText.GetLength() - __textLength;
151 if (currentText.IsEmpty())
153 if (GetFooter() != null)
155 GetFooter()->SetItemEnabled(0, false);
156 GetFooter()->Invalidate(true);
161 if (GetFooter() != null)
163 GetFooter()->GetItemStatus(0, currentStatus);
165 if (currentStatus == FOOTER_ITEM_STATUS_DISABLED)
167 GetFooter()->SetItemEnabled(0,true);
168 GetFooter()->Invalidate(true);
173 if (currentText.StartsWith(".", 0))
175 String invalidCharacterString;
177 String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS");
179 validString = __pNameEditField->GetText();
181 if (validString.GetLength() > 1)
183 validString.Remove(0,1);
184 __pNameEditField->SetText(validString);
188 __pNameEditField->SetText("");
190 if (GetFooter() != null)
192 GetFooter()->SetItemEnabled(0, false);
193 GetFooter()->Invalidate(true);
196 __pNameEditField->ShowKeypad();
199 currentInput = __pNameEditField->GetText();
201 if (currentInput.Contains(specialCharacters[0]))
203 String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS");
205 currentInput.Replace("/", "");
206 __pNameEditField->SetText(currentInput);
209 inputLength = byteCount;
210 if (inputLength >= tempLength)
212 String maxCharacterString;
213 String currentInputCharacter;
214 int checkByteCount = 0;
215 int lengthOfFinalString = 0;
216 int currentCharacter = 0;
218 String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED");
220 currentText = __pNameEditField->GetText();
222 for (currentCharacter=0; checkByteCount < tempLength; currentCharacter++)
224 currentInputCharacter.Clear();
225 currentInputCharacter = currentText[currentCharacter];
226 r = utf8.GetByteCount(currentInputCharacter, byteCount);
231 AppLogDebug("result of byte count is %s",GetErrorMessage(r));
232 checkByteCount = checkByteCount + byteCount;
234 if( checkByteCount < tempLength)
236 lengthOfFinalString++;
240 r = __pNameEditField->GetText().SubString(0, lengthOfFinalString, currentInput);
241 AppLogDebug("current input is %S", currentInput.GetPointer());
242 r = __pNameEditField->SetText(currentInput);
243 __pNameEditField->ShowKeypad();
247 r = utf8.GetByteCount(__pNameEditField->GetText(), byteCount);
248 __textLength = byteCount;
251 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
255 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
257 AppLogDebug("ENTER");
258 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
262 AlbumNameEditorForm::OnTerminating(void)
264 AppLogDebug("ENTER");
265 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
270 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
275 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
278 if (res != COMPLETE_SUCCESS)
280 __pNameEditField->SetText(__nameEditFieldPreText);
281 __pNameEditField->HideKeypad();
282 __pNameEditField->Draw();
283 SceneManager* pSceneManager = SceneManager::GetInstance();
284 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
289 AlbumNameEditorForm::OnRenameAlbum(String& strOri)
291 AppLogDebug("Rename Album");
295 strOri.IndexOf(DIRECTORY_SEPARATOR, 0, index);
297 strOri.SubString(0, (strOri.GetLength() - index), path);
298 path.Append(__nameEditFieldText);
301 result r = __pPresentationModel->RenameAlbum(strOri, path, this);
305 AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
306 if (__pMessageBox == null)
308 __pMessageBox = new (std::nothrow) MessageBox();
309 if (r == E_FILE_ALREADY_EXIST)
311 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
312 MSGBOX_STYLE_NONE, 3000);
316 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
317 MSGBOX_STYLE_NONE, 3000);
321 __pMessageBox->ShowAndWait(modalResult);
323 delete __pMessageBox;
324 __pMessageBox = null;
330 Rectangle clientRect= GetClientAreaBounds();
331 Rectangle rect(0, 0, clientRect.width, clientRect.height);
332 __pProgressAnim = new (std::nothrow) ProgressAnimation;
333 __pProgressAnim->Construct(rect);
334 AddControl(__pProgressAnim);
335 __pProgressAnim->SetShowState(true);
336 GetFooter()->SetEnabled(false);
337 __pProgressAnim->AnimationStart();
338 __pProgressAnim->Draw();
344 AlbumNameEditorForm::OnCreateAlbum(void)
347 __pNameEditField->HideKeypad();
348 __pNameEditField->RequestRedraw();
349 path.Append(Tizen::System::Environment::GetMediaPath());
350 path.Append(__nameEditFieldText);
352 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
354 Directory::Create(path, true);
357 __nameEditFieldPreText = __nameEditFieldText;
361 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
362 delete __pMoveIndexList;
363 __pMoveIndexList = null;
367 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
369 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
370 delete __pMoveIndexList;
371 __pMoveIndexList = null;
376 GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
377 __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
378 if (__fileActionMode == FILE_ACTION_COPY)
380 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
381 __pFileMove->SetCopy();
385 __pFileMove->ClearCopy();
387 result r = __pFileMove->StartTimer();
393 __pNameEditField->SetText(__nameEditFieldPreText);
394 __pNameEditField->HideKeypad();
395 __pNameEditField->Draw();
396 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
397 SceneManager* pSceneManager = SceneManager::GetInstance();
398 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
402 AppLogDebug("MoveToContentFileList content in progress");
404 __fileActionMode = FILE_ACTION_MOVE;
408 void AlbumNameEditorForm::OnAlbumRenameComplete(void)
411 __pProgressAnim->AnimationStop();
412 __pProgressAnim->SetShowState(false);
413 RemoveControl(__pProgressAnim);
415 GetFooter()->SetEnabled(true);
416 SceneManager* pSceneManager = SceneManager::GetInstance();
417 pSceneManager->GoBackward((BackwardSceneTransition(IDSCN_ALBUM_LIST)));
421 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
423 AppLogDebug("ENTER");
425 __nameEditFieldText = __pNameEditField->GetText();
427 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
429 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
430 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
431 path = pAlbumInfo->GetDirectory(0);
436 case IDA_BUTTON_CREATE_NAME_SAVE:
438 __pNameEditField->SetEnabled(false);
440 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
444 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
446 String albumName = __pNameEditField->GetText();
447 if (__originalText.Equals(albumName , true))
449 SceneManager* pSceneManager = SceneManager::GetInstance();
450 pSceneManager->GoBackward(BackwardSceneTransition());
463 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
467 AlbumNameEditorForm::OnFormBackRequested(Form& source)
469 AppLogDebug("ENTER");
470 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
472 SceneManager* pSceneManager = SceneManager::GetInstance();
473 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
477 SceneManager* pSceneManager = SceneManager::GetInstance();
478 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
480 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
484 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
485 const SceneId& currentSceneId, IList* pArgs)
487 AppLogDebug("ENTER");
488 __pPresentationModel = AlbumListPresentationModel::GetInstance();
489 __previousSceneId = previousSceneId;
491 __pNameEditField->SetEnabled(true);
492 __pPresentationModel->AddContentEventListener(this);
496 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
497 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
499 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
500 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
502 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
504 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
505 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
507 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
512 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
513 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
515 AppLogDebug("Rash: FILE_MOVE_ACTION");
516 __fileActionMode = FILE_ACTION_MOVE;
518 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
520 AppLogDebug("Rash: FILE_COPY_ACTION");
521 __fileActionMode = FILE_ACTION_COPY;
523 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
526 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
530 IEnumerator* pEnum = pArgs->GetEnumeratorN();
531 if (pEnum->MoveNext() == E_SUCCESS)
533 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
536 __folderIndex = index->ToInt();
544 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
545 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
546 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
547 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
549 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
551 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
553 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
555 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
558 __callerSceneId = previousSceneId;
562 __callerSceneId = EMPTY_SPACE;
565 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
567 __nameEditFieldText = EMPTY_SPACE;
568 __nameEditFieldPreText = EMPTY_SPACE;
569 __pNameEditField->SetText(__nameEditFieldText);
570 __nameEditFieldTempText = __nameEditFieldText;
571 __pNameEditField->ShowKeypad();
572 __pNameEditField->SetFocus();
574 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
575 GetFooter()->SetItemEnabled(0, false);
576 GetFooter()->Invalidate(true);
582 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
583 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
585 String strName = pAlbumInfo->GetAlbumName();
586 __nameEditFieldText = strName;
587 __nameEditFieldPreText = strName;
588 __pNameEditField->SetText(__nameEditFieldText);
589 __nameEditFieldTempText = __nameEditFieldText;
590 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
591 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
592 __pNameEditField->ShowKeypad();
593 __pNameEditField->SetFocus();
594 __originalText = __pNameEditField->GetText();
595 utf8.GetByteCount(__nameEditFieldText, byteCount);
596 __textLength = byteCount;
597 GetFooter()->SetItemEnabled(0, true);
598 GetFooter()->Invalidate(true);
603 __pMoveIndexList = pArgs;
606 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
610 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
611 const SceneId& nextSceneId)
613 AppLogDebug("ENTER");
614 __pPresentationModel->RemoveContentEventListener(*this);
615 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
619 AlbumNameEditorForm::OnContentUpdated(void)
621 AppLogDebug("ENTER");
623 if ( __mountState == false )
625 SceneManager* pSceneManager = SceneManager::GetInstance();
626 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
627 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
631 __mountState = false;
636 AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
638 AppLogDebug("ENTER");
640 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
642 if ( __pFileMove && __pFileMove->IsStarted() )
644 __pFileMove->Cancel();
648 __mountState = false;
649 SceneManager* pSceneManager = SceneManager::GetInstance();
650 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
651 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
657 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
661 AlbumNameEditorForm::CreateMessage(String& str)
663 if (__pMessageBox == null)
665 __pMessageBox = new(std::nothrow) MessageBox;
667 if (__pMessageBox != null)
669 __pMessageBox->Construct(L"", str, MSGBOX_STYLE_OK, 3000);
670 __pMessageBox->ShowAndWait(__modalMsgBoxResult);
672 delete __pMessageBox;
673 __pMessageBox = null;
674 __modalMsgBoxResult = 0;