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);
320 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
321 MSGBOX_STYLE_NONE, 3000);
325 __pMessageBox->ShowAndWait(modalResult);
327 delete __pMessageBox;
328 __pMessageBox = null;
329 __pNameEditField->SetEnabled(true);
330 __pNameEditField->ShowKeypad();
336 Rectangle clientRect = GetClientAreaBounds();
337 Rectangle rect(0, 0, clientRect.width, clientRect.height);
338 __pProgressAnim = new (std::nothrow) ProgressAnimation;
339 __pProgressAnim->Construct(rect);
340 AddControl(__pProgressAnim);
341 __pProgressAnim->SetShowState(true);
342 GetFooter()->SetEnabled(false);
343 __pProgressAnim->AnimationStart();
344 __pProgressAnim->Draw();
350 AlbumNameEditorForm::OnCreateAlbum(void)
353 __pNameEditField->HideKeypad();
354 __pNameEditField->RequestRedraw();
355 path.Append(Tizen::System::Environment::GetMediaPath());
356 path.Append(__nameEditFieldText);
358 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
360 Directory::Create(path, true);
363 __nameEditFieldPreText = __nameEditFieldText;
367 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
368 delete __pMoveIndexList;
369 __pMoveIndexList = null;
373 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
375 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
376 delete __pMoveIndexList;
377 __pMoveIndexList = null;
382 GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
383 __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
384 if (__fileActionMode == FILE_ACTION_COPY)
386 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
387 __pFileMove->SetCopy();
391 __pFileMove->ClearCopy();
393 result r = __pFileMove->StartTimer();
399 __pNameEditField->SetText(__nameEditFieldPreText);
400 __pNameEditField->HideKeypad();
401 __pNameEditField->Draw();
402 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
403 SceneManager* pSceneManager = SceneManager::GetInstance();
404 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
408 AppLogDebug("MoveToContentFileList content in progress");
410 __fileActionMode = FILE_ACTION_MOVE;
414 void AlbumNameEditorForm::OnAlbumRenameComplete(void)
417 __pProgressAnim->AnimationStop();
418 __pProgressAnim->SetShowState(false);
419 RemoveControl(__pProgressAnim);
421 GetFooter()->SetEnabled(true);
422 SceneManager* pSceneManager = SceneManager::GetInstance();
423 pSceneManager->GoBackward((BackwardSceneTransition(IDSCN_ALBUM_LIST)));
427 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
429 AppLogDebug("ENTER");
431 __nameEditFieldText = __pNameEditField->GetText();
433 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
435 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
436 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
437 path = pAlbumInfo->GetDirectory(0);
442 case IDA_BUTTON_CREATE_NAME_SAVE:
444 __pNameEditField->SetEnabled(false);
445 GetFooter()->SetItemEnabled(0, false);
447 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
451 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
453 String albumName = __pNameEditField->GetText();
454 if (__originalText.Equals(albumName, true))
456 SceneManager* pSceneManager = SceneManager::GetInstance();
457 pSceneManager->GoBackward(BackwardSceneTransition());
470 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
474 AlbumNameEditorForm::OnFormBackRequested(Form& source)
476 AppLogDebug("ENTER");
477 if (__pProgressAnim != null)
479 if (__pProgressAnim->GetShowState())
485 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
487 SceneManager* pSceneManager = SceneManager::GetInstance();
488 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
492 SceneManager* pSceneManager = SceneManager::GetInstance();
493 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
495 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
499 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
500 const SceneId& currentSceneId, IList* pArgs)
502 AppLogDebug("ENTER");
503 __pPresentationModel = AlbumListPresentationModel::GetInstance();
504 __previousSceneId = previousSceneId;
506 __pNameEditField->SetEnabled(true);
507 __pPresentationModel->AddContentEventListener(this);
511 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
512 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
514 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
515 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
517 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
519 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
520 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
522 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
527 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
528 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
530 AppLogDebug("Rash: FILE_MOVE_ACTION");
531 __fileActionMode = FILE_ACTION_MOVE;
533 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
535 AppLogDebug("Rash: FILE_COPY_ACTION");
536 __fileActionMode = FILE_ACTION_COPY;
538 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
541 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
545 IEnumerator* pEnum = pArgs->GetEnumeratorN();
546 if (pEnum->MoveNext() == E_SUCCESS)
548 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
551 __folderIndex = index->ToInt();
560 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
561 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
562 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
563 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
565 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
567 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
569 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
571 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
574 __callerSceneId = previousSceneId;
578 __callerSceneId = EMPTY_SPACE;
581 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
583 __nameEditFieldText = EMPTY_SPACE;
584 __nameEditFieldPreText = EMPTY_SPACE;
585 __pNameEditField->SetText(__nameEditFieldText);
586 __nameEditFieldTempText = __nameEditFieldText;
587 __pNameEditField->ShowKeypad();
588 __pNameEditField->SetFocus();
590 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
591 GetFooter()->SetItemEnabled(0, false);
592 GetFooter()->Invalidate(true);
598 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
599 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
601 String strName = pAlbumInfo->GetAlbumName();
602 __nameEditFieldText = strName;
603 __nameEditFieldPreText = strName;
604 __pNameEditField->SetText(__nameEditFieldText);
605 __nameEditFieldTempText = __nameEditFieldText;
606 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
607 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
608 __pNameEditField->ShowKeypad();
609 __pNameEditField->SetFocus();
610 __originalText = __pNameEditField->GetText();
611 utf8.GetByteCount(__nameEditFieldText, byteCount);
612 __textLength = byteCount;
613 GetFooter()->SetItemEnabled(0, true);
614 GetFooter()->Invalidate(true);
619 __pMoveIndexList = pArgs;
622 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
626 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
627 const SceneId& nextSceneId)
629 AppLogDebug("ENTER");
630 __pPresentationModel->RemoveContentEventListener(*this);
631 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
635 AlbumNameEditorForm::OnContentUpdated(void)
637 AppLogDebug("ENTER");
639 if (__mountState == false)
641 SceneManager* pSceneManager = SceneManager::GetInstance();
642 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
643 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
647 __mountState = false;
652 AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
654 AppLogDebug("ENTER");
656 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
658 if (__pFileMove && __pFileMove->IsStarted())
660 __pFileMove->Cancel();
664 __mountState = false;
665 SceneManager* pSceneManager = SceneManager::GetInstance();
666 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
667 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
673 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
677 AlbumNameEditorForm::CreateMessage(String& str)
679 if (__pMessageBox == null)
681 __pMessageBox = new(std::nothrow) MessageBox;
683 if (__pMessageBox != null)
685 __pMessageBox->Construct(L"", str, MSGBOX_STYLE_OK, 3000);
686 __pMessageBox->ShowAndWait(__modalMsgBoxResult);
688 delete __pMessageBox;
689 __pMessageBox = null;
690 __modalMsgBoxResult = 0;
696 AlbumNameEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
698 if (__pProgressAnim != NULL)
700 __pProgressAnim->ChangeOrientation(GetClientAreaBounds());
701 __pProgressAnim->Invalidate(true);