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);
212 inputLength = byteCount;
213 if (inputLength >= tempLength)
215 String maxCharacterString;
216 String currentInputCharacter;
217 int checkByteCount = 0;
218 int lengthOfFinalString = 0;
219 int currentCharacter = 0;
221 String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED");
223 currentText = __pNameEditField->GetText();
225 for (currentCharacter=0; checkByteCount < tempLength; currentCharacter++)
227 currentInputCharacter.Clear();
228 currentInputCharacter = currentText[currentCharacter];
229 r = utf8.GetByteCount(currentInputCharacter, byteCount);
234 AppLogDebug("result of byte count is %s",GetErrorMessage(r));
235 checkByteCount = checkByteCount + byteCount;
237 if( checkByteCount < tempLength)
239 lengthOfFinalString++;
243 r = __pNameEditField->GetText().SubString(0, lengthOfFinalString, currentInput);
244 AppLogDebug("current input is %S", currentInput.GetPointer());
245 r = __pNameEditField->SetText(currentInput);
246 __pNameEditField->ShowKeypad();
250 r = utf8.GetByteCount(__pNameEditField->GetText(), byteCount);
251 __textLength = byteCount;
254 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
258 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
260 AppLogDebug("ENTER");
261 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
265 AlbumNameEditorForm::OnTerminating(void)
267 AppLogDebug("ENTER");
268 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
273 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
278 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
281 if (res != COMPLETE_SUCCESS)
283 __pNameEditField->SetText(__nameEditFieldPreText);
284 __pNameEditField->HideKeypad();
285 __pNameEditField->Draw();
286 SceneManager* pSceneManager = SceneManager::GetInstance();
287 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
292 AlbumNameEditorForm::OnRenameAlbum(String& strOri)
294 AppLogDebug("Rename Album");
298 strOri.IndexOf(DIRECTORY_SEPARATOR, 0, index);
300 strOri.SubString(0, (strOri.GetLength() - index), path);
301 path.Append(__nameEditFieldText);
304 result r = __pPresentationModel->RenameAlbum(strOri, path, this);
308 AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
309 if (__pMessageBox == null)
311 __pMessageBox = new (std::nothrow) MessageBox();
312 if (r == E_FILE_ALREADY_EXIST)
314 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
315 MSGBOX_STYLE_NONE, 3000);
319 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
320 MSGBOX_STYLE_NONE, 3000);
324 __pMessageBox->ShowAndWait(modalResult);
326 delete __pMessageBox;
327 __pMessageBox = null;
333 Rectangle clientRect = GetClientAreaBounds();
334 Rectangle rect(0, 0, clientRect.width, clientRect.height);
335 __pProgressAnim = new (std::nothrow) ProgressAnimation;
336 __pProgressAnim->Construct(rect);
337 AddControl(__pProgressAnim);
338 __pProgressAnim->SetShowState(true);
339 GetFooter()->SetEnabled(false);
340 __pProgressAnim->AnimationStart();
341 __pProgressAnim->Draw();
347 AlbumNameEditorForm::OnCreateAlbum(void)
350 __pNameEditField->HideKeypad();
351 __pNameEditField->RequestRedraw();
352 path.Append(Tizen::System::Environment::GetMediaPath());
353 path.Append(__nameEditFieldText);
355 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
357 Directory::Create(path, true);
360 __nameEditFieldPreText = __nameEditFieldText;
364 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
365 delete __pMoveIndexList;
366 __pMoveIndexList = null;
370 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
372 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
373 delete __pMoveIndexList;
374 __pMoveIndexList = null;
379 GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
380 __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
381 if (__fileActionMode == FILE_ACTION_COPY)
383 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
384 __pFileMove->SetCopy();
388 __pFileMove->ClearCopy();
390 result r = __pFileMove->StartTimer();
396 __pNameEditField->SetText(__nameEditFieldPreText);
397 __pNameEditField->HideKeypad();
398 __pNameEditField->Draw();
399 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
400 SceneManager* pSceneManager = SceneManager::GetInstance();
401 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
405 AppLogDebug("MoveToContentFileList content in progress");
407 __fileActionMode = FILE_ACTION_MOVE;
411 void AlbumNameEditorForm::OnAlbumRenameComplete(void)
414 __pProgressAnim->AnimationStop();
415 __pProgressAnim->SetShowState(false);
416 RemoveControl(__pProgressAnim);
418 GetFooter()->SetEnabled(true);
419 SceneManager* pSceneManager = SceneManager::GetInstance();
420 pSceneManager->GoBackward((BackwardSceneTransition(IDSCN_ALBUM_LIST)));
424 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
426 AppLogDebug("ENTER");
428 __nameEditFieldText = __pNameEditField->GetText();
430 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
432 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
433 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
434 path = pAlbumInfo->GetDirectory(0);
439 case IDA_BUTTON_CREATE_NAME_SAVE:
441 __pNameEditField->SetEnabled(false);
443 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
447 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
449 String albumName = __pNameEditField->GetText();
450 if (__originalText.Equals(albumName , true))
452 SceneManager* pSceneManager = SceneManager::GetInstance();
453 pSceneManager->GoBackward(BackwardSceneTransition());
466 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
470 AlbumNameEditorForm::OnFormBackRequested(Form& source)
472 AppLogDebug("ENTER");
473 if (__pProgressAnim != null)
475 if (__pProgressAnim->GetShowState())
481 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
483 SceneManager* pSceneManager = SceneManager::GetInstance();
484 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
488 SceneManager* pSceneManager = SceneManager::GetInstance();
489 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
491 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
495 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
496 const SceneId& currentSceneId, IList* pArgs)
498 AppLogDebug("ENTER");
499 __pPresentationModel = AlbumListPresentationModel::GetInstance();
500 __previousSceneId = previousSceneId;
502 __pNameEditField->SetEnabled(true);
503 __pPresentationModel->AddContentEventListener(this);
507 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
508 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
510 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
511 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
513 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
515 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
516 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
518 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
523 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
524 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
526 AppLogDebug("Rash: FILE_MOVE_ACTION");
527 __fileActionMode = FILE_ACTION_MOVE;
529 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
531 AppLogDebug("Rash: FILE_COPY_ACTION");
532 __fileActionMode = FILE_ACTION_COPY;
534 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
537 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
541 IEnumerator* pEnum = pArgs->GetEnumeratorN();
542 if (pEnum->MoveNext() == E_SUCCESS)
544 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
547 __folderIndex = index->ToInt();
556 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
557 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
558 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
559 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
561 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
563 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
565 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
567 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
570 __callerSceneId = previousSceneId;
574 __callerSceneId = EMPTY_SPACE;
577 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
579 __nameEditFieldText = EMPTY_SPACE;
580 __nameEditFieldPreText = EMPTY_SPACE;
581 __pNameEditField->SetText(__nameEditFieldText);
582 __nameEditFieldTempText = __nameEditFieldText;
583 __pNameEditField->ShowKeypad();
584 __pNameEditField->SetFocus();
586 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
587 GetFooter()->SetItemEnabled(0, false);
588 GetFooter()->Invalidate(true);
594 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
595 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
597 String strName = pAlbumInfo->GetAlbumName();
598 __nameEditFieldText = strName;
599 __nameEditFieldPreText = strName;
600 __pNameEditField->SetText(__nameEditFieldText);
601 __nameEditFieldTempText = __nameEditFieldText;
602 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
603 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
604 __pNameEditField->ShowKeypad();
605 __pNameEditField->SetFocus();
606 __originalText = __pNameEditField->GetText();
607 utf8.GetByteCount(__nameEditFieldText, byteCount);
608 __textLength = byteCount;
609 GetFooter()->SetItemEnabled(0, true);
610 GetFooter()->Invalidate(true);
615 __pMoveIndexList = pArgs;
618 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
622 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
623 const SceneId& nextSceneId)
625 AppLogDebug("ENTER");
626 __pPresentationModel->RemoveContentEventListener(*this);
627 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
631 AlbumNameEditorForm::OnContentUpdated(void)
633 AppLogDebug("ENTER");
635 if ( __mountState == false )
637 SceneManager* pSceneManager = SceneManager::GetInstance();
638 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
639 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
643 __mountState = false;
648 AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
650 AppLogDebug("ENTER");
652 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
654 if ( __pFileMove && __pFileMove->IsStarted() )
656 __pFileMove->Cancel();
660 __mountState = false;
661 SceneManager* pSceneManager = SceneManager::GetInstance();
662 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
663 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
669 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
673 AlbumNameEditorForm::CreateMessage(String& str)
675 if (__pMessageBox == null)
677 __pMessageBox = new(std::nothrow) MessageBox;
679 if (__pMessageBox != null)
681 __pMessageBox->Construct(L"", str, MSGBOX_STYLE_OK, 3000);
682 __pMessageBox->ShowAndWait(__modalMsgBoxResult);
684 delete __pMessageBox;
685 __pMessageBox = null;
686 __modalMsgBoxResult = 0;
692 AlbumNameEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
694 if ( __pProgressAnim != NULL)
696 __pProgressAnim->ChangeOrientation(GetClientAreaBounds());
697 __pProgressAnim->Invalidate(true);