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 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::OnCreateAlbum(void)
364 __pNameEditField->HideKeypad();
365 __pNameEditField->RequestRedraw();
366 path.Append(Tizen::System::Environment::GetMediaPath());
367 path.Append(__nameEditFieldText);
369 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
371 Directory::Create(path, true);
374 __nameEditFieldPreText = __nameEditFieldText;
378 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
379 delete __pMoveIndexList;
380 __pMoveIndexList = null;
384 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
386 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
387 delete __pMoveIndexList;
388 __pMoveIndexList = null;
393 GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
394 __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
395 if (__fileActionMode == FILE_ACTION_COPY)
397 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
398 __pFileMove->SetCopy();
402 __pFileMove->ClearCopy();
404 result r = __pFileMove->StartTimer();
410 __pNameEditField->SetText(__nameEditFieldPreText);
411 __pNameEditField->HideKeypad();
412 __pNameEditField->Draw();
413 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
414 SceneManager* pSceneManager = SceneManager::GetInstance();
415 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
419 AppLogDebug("MoveToContentFileList content in progress");
421 __fileActionMode = FILE_ACTION_MOVE;
425 void AlbumNameEditorForm::OnAlbumRenameComplete(void)
428 __pProgressAnim->AnimationStop();
429 __pProgressAnim->SetShowState(false);
430 RemoveControl(__pProgressAnim);
432 GetFooter()->SetEnabled(true);
433 SceneManager* pSceneManager = SceneManager::GetInstance();
434 pSceneManager->GoBackward((BackwardSceneTransition(IDSCN_ALBUM_LIST)));
438 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
440 AppLogDebug("ENTER");
442 __nameEditFieldText = __pNameEditField->GetText();
444 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
446 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
447 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
448 path = pAlbumInfo->GetDirectory(0);
453 case IDA_BUTTON_CREATE_NAME_SAVE:
455 __pNameEditField->SetEnabled(false);
456 GetFooter()->SetItemEnabled(0, false);
458 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
462 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
464 String albumName = __pNameEditField->GetText();
465 if (__originalText.Equals(albumName, true))
467 SceneManager* pSceneManager = SceneManager::GetInstance();
468 pSceneManager->GoBackward(BackwardSceneTransition());
481 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
485 AlbumNameEditorForm::OnFormBackRequested(Form& source)
487 AppLogDebug("ENTER");
488 if (__pProgressAnim != null)
490 if (__pProgressAnim->GetShowState())
496 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
498 SceneManager* pSceneManager = SceneManager::GetInstance();
499 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
503 SceneManager* pSceneManager = SceneManager::GetInstance();
504 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
506 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
510 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
511 const SceneId& currentSceneId, IList* pArgs)
513 AppLogDebug("ENTER");
514 __pPresentationModel = AlbumListPresentationModel::GetInstance();
515 __previousSceneId = previousSceneId;
518 __pPresentationModel->AddContentEventListener(this);
522 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
523 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
525 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
526 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
528 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
530 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
531 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
533 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
538 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
539 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
541 AppLogDebug("Rash: FILE_MOVE_ACTION");
542 __fileActionMode = FILE_ACTION_MOVE;
544 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
546 AppLogDebug("Rash: FILE_COPY_ACTION");
547 __fileActionMode = FILE_ACTION_COPY;
549 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
552 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
556 IEnumerator* pEnum = pArgs->GetEnumeratorN();
557 if (pEnum->MoveNext() == E_SUCCESS)
559 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
562 __folderIndex = index->ToInt();
571 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
572 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
573 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
574 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
576 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
578 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
580 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
582 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
585 __callerSceneId = previousSceneId;
589 __callerSceneId = EMPTY_SPACE;
592 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
594 __nameEditFieldText = EMPTY_SPACE;
595 __nameEditFieldPreText = EMPTY_SPACE;
596 __pNameEditField->SetText(__nameEditFieldText);
597 __nameEditFieldTempText = __nameEditFieldText;
598 __pNameEditField->ShowKeypad();
599 __pNameEditField->SetFocus();
601 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
602 GetFooter()->SetItemEnabled(0, false);
603 GetFooter()->Invalidate(true);
609 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
610 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
612 String strName = pAlbumInfo->GetAlbumName();
613 __nameEditFieldText = strName;
614 __nameEditFieldPreText = strName;
615 __pNameEditField->SetText(__nameEditFieldText);
616 __nameEditFieldTempText = __nameEditFieldText;
617 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
618 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
619 __pNameEditField->ShowKeypad();
620 __pNameEditField->SetFocus();
621 __originalText = __pNameEditField->GetText();
622 utf8.GetByteCount(__nameEditFieldText, byteCount);
623 __textLength = byteCount;
624 GetFooter()->SetItemEnabled(0, true);
625 GetFooter()->Invalidate(true);
630 __pMoveIndexList = pArgs;
633 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
637 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
638 const SceneId& nextSceneId)
640 AppLogDebug("ENTER");
642 if(__pNameEditField->IsEnabled() == false)
644 __pNameEditField->SetEnabled(true);
647 __pPresentationModel->RemoveContentEventListener(*this);
648 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
652 AlbumNameEditorForm::OnContentUpdated(void)
654 AppLogDebug("ENTER");
656 if (__mountState == false)
658 SceneManager* pSceneManager = SceneManager::GetInstance();
659 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
660 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
664 __mountState = false;
669 AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
671 AppLogDebug("ENTER");
673 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
675 if (__pFileMove && __pFileMove->IsStarted())
677 __pFileMove->Cancel();
681 __mountState = false;
682 SceneManager* pSceneManager = SceneManager::GetInstance();
683 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
684 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
690 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
694 AlbumNameEditorForm::CreateMessage(String& str)
696 if (__pMessageBox == null)
698 __pMessageBox = new(std::nothrow) MessageBox;
700 if (__pMessageBox != null)
702 __pMessageBox->Construct(L"", str, MSGBOX_STYLE_OK, 3000);
703 __pMessageBox->ShowAndWait(__modalMsgBoxResult);
705 delete __pMessageBox;
706 __pMessageBox = null;
707 __modalMsgBoxResult = 0;
713 AlbumNameEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
715 if (__pProgressAnim != null)
717 __pProgressAnim->ChangeOrientation(Form::GetBounds());
718 __pProgressAnim->Invalidate(true);