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.
23 #include "GlAlbumInfo.h"
24 #include "GlAlbumListPresentationModel.h"
25 #include "GlAlbumNameEditorForm.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlFileMoveTimer.h"
28 #include "GlProgressAnimation.h"
29 #include "GlResourceManager.h"
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Base::Utility;
37 using namespace Tizen::Content;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Io;
40 using namespace Tizen::Media;
41 using namespace Tizen::System;
42 using namespace Tizen::Ui;
43 using namespace Tizen::Ui::Controls;
44 using namespace Tizen::Ui::Scenes;
46 static const Rectangle RECT_NAME_EDIT_FIELD (0, 0, 720, 100);
47 static const unsigned int COLOR_NAME_EDIT_FIELD = Color32<255, 255, 255>::Value;
48 static const int ALBUM_MAX_LENGTH = 255;
50 AlbumNameEditorForm::AlbumNameEditorForm(void)
51 : __pNameEditField(null)
54 , __albumNameEditorMode(ALBUM_NAME_EDITOR_MODE_RENAME)
56 , __pMoveIndexList(null)
57 , __fileActionMode(FILE_ACTION_MOVE)
59 , __pProgressAnim(null)
60 , __pPresentationModel(null)
61 , __pFilePresentationModel(null)
65 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
68 AlbumNameEditorForm::~AlbumNameEditorForm(void)
71 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
73 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
77 AlbumNameEditorForm::Initialize(void)
80 result r = Construct(FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR);
81 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
87 AlbumNameEditorForm::OnInitializing(void)
90 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
91 __pFilePresentationModel = FileListPresentationModel::GetInstance();
93 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
94 Header* pHeader = GetHeader();
96 pHeader->SetStyle(HEADER_STYLE_TITLE);
98 GetFooter()->SetBackButtonEnabled(true);
99 GetFooter()->SetBackButton();
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 = new (std::nothrow) EditField();
113 __pNameEditField->Construct(RECT_NAME_EDIT_FIELD, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY,
114 EDIT_FIELD_TITLE_STYLE_NONE, true, ALBUM_MAX_LENGTH);
115 __pNameEditField->AddTextEventListener(*this);
116 __pNameEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_NAME_EDIT_FIELD);
117 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
119 AddControl(__pNameEditField);
120 __pNameEditField->AddActionEventListener(*this);
126 AlbumNameEditorForm::OnTextValueChanged(const Control& source)
128 AppLogDebug("ENTER");
129 String inputString = __pNameEditField->GetText();
131 if (inputString.Contains(DIRECTORY_SEPARATOR) == true)
133 if (__pMessageBox == null)
135 __pMessageBox = new (std::nothrow) MessageBox();
136 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS"),
137 MSGBOX_STYLE_NONE, 3000);
140 __pMessageBox->ShowAndWait(modalResult);
142 delete __pMessageBox;
143 __pMessageBox = null;
146 __pNameEditField->SetText(__nameEditFieldTempText);
147 __pNameEditField->SetFocus();
152 ByteBuffer* pBuffer = StringUtil::StringToUtf8N(inputString);
156 remaining = pBuffer->GetRemaining();
159 if (remaining >= ALBUM_MAX_LENGTH)
161 if (__pMessageBox == null)
163 __pMessageBox = new (std::nothrow) MessageBox();
164 __pMessageBox->Construct(L"",
165 ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED"),
166 MSGBOX_STYLE_NONE, 3000);
168 __pMessageBox->ShowAndWait(modalResult);
169 delete __pMessageBox;
170 __pMessageBox = null;
173 __pNameEditField->SetText(__nameEditFieldTempText);
174 __pNameEditField->SetFocus();
178 __nameEditFieldTempText = inputString;
180 FooterItemStatus itemStatus;
181 GetFooter()->GetItemStatus(0, itemStatus);
182 if (inputString.GetLength() == 0)
184 if (itemStatus != FOOTER_ITEM_STATUS_DISABLED)
186 GetFooter()->SetItemEnabled(0, false);
191 if (itemStatus == FOOTER_ITEM_STATUS_DISABLED)
193 GetFooter()->SetItemEnabled(0, true);
196 GetFooter()->Invalidate(true);
198 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
202 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
204 AppLogDebug("ENTER");
205 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
209 AlbumNameEditorForm::OnTerminating(void)
211 AppLogDebug("ENTER");
212 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
217 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
222 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
225 if (res != COMPLETE_SUCCESS)
227 __pNameEditField->SetText(__nameEditFieldPreText);
228 __pNameEditField->HideKeypad();
229 __pNameEditField->Draw();
230 SceneManager* pSceneManager = SceneManager::GetInstance();
231 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
236 AlbumNameEditorForm::OnRenameAlbum(String& strOri)
238 AppLogDebug("Rename Album");
242 strOri.IndexOf(DIRECTORY_SEPARATOR, 0, index);
244 strOri.SubString(0, (strOri.GetLength() - index), path);
245 path.Append(__nameEditFieldText);
248 result r = __pPresentationModel->RenameAlbum(strOri, path, this);
252 AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
253 if (__pMessageBox == null)
255 __pMessageBox = new (std::nothrow) MessageBox();
256 if (r == E_FILE_ALREADY_EXIST)
258 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
259 MSGBOX_STYLE_NONE, 3000);
263 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
264 MSGBOX_STYLE_NONE, 3000);
268 __pMessageBox->ShowAndWait(modalResult);
270 delete __pMessageBox;
271 __pMessageBox = null;
277 Rectangle clientRect= GetClientAreaBounds();
278 Rectangle rect(0, 0, clientRect.width, clientRect.height);
279 __pProgressAnim = new (std::nothrow) ProgressAnimation;
280 __pProgressAnim->Construct(rect);
281 AddControl(__pProgressAnim);
282 __pProgressAnim->SetShowState(true);
283 GetFooter()->SetEnabled(false);
284 __pProgressAnim->AnimationStart();
285 __pProgressAnim->Draw();
291 AlbumNameEditorForm::OnCreateAlbum(void)
294 __pNameEditField->HideKeypad();
295 __pNameEditField->RequestRedraw();
296 path.Append(Tizen::System::Environment::GetMediaPath());
297 path.Append(__nameEditFieldText);
299 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
301 Directory::Create(path, true);
304 __nameEditFieldPreText = __nameEditFieldText;
308 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
309 delete __pMoveIndexList;
310 __pMoveIndexList = null;
314 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
316 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
317 delete __pMoveIndexList;
318 __pMoveIndexList = null;
323 GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
324 __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
325 if (__fileActionMode == FILE_ACTION_COPY)
327 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
328 __pFileMove->SetCopy();
332 __pFileMove->ClearCopy();
334 result r = __pFileMove->StartTimer();
340 __pNameEditField->SetText(__nameEditFieldPreText);
341 __pNameEditField->HideKeypad();
342 __pNameEditField->Draw();
343 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
344 SceneManager* pSceneManager = SceneManager::GetInstance();
345 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
349 AppLogDebug("MoveToContentFileList content in progress");
351 __fileActionMode = FILE_ACTION_MOVE;
355 void AlbumNameEditorForm::OnAlbumRenameComplete(void)
358 __pProgressAnim->AnimationStop();
359 __pProgressAnim->SetShowState(false);
360 RemoveControl(__pProgressAnim);
362 GetFooter()->SetEnabled(true);
363 SceneManager* pSceneManager = SceneManager::GetInstance();
364 pSceneManager->GoBackward((BackwardSceneTransition(IDSCN_ALBUM_LIST)));
368 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
370 AppLogDebug("ENTER");
372 __nameEditFieldText = __pNameEditField->GetText();
374 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
376 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
377 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
378 path = pAlbumInfo->GetDirectory(0);
383 case IDA_BUTTON_CREATE_NAME_SAVE:
385 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
389 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
391 String albumName = __pNameEditField->GetText();
392 if (__originalText.Equals(albumName , true))
394 SceneManager* pSceneManager = SceneManager::GetInstance();
395 pSceneManager->GoBackward(BackwardSceneTransition());
408 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
412 AlbumNameEditorForm::OnFormBackRequested(Form& source)
414 AppLogDebug("ENTER");
415 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
417 SceneManager* pSceneManager = SceneManager::GetInstance();
418 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
422 SceneManager* pSceneManager = SceneManager::GetInstance();
423 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
425 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
429 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
430 const SceneId& currentSceneId, IList* pArgs)
432 AppLogDebug("ENTER");
433 __pPresentationModel = AlbumListPresentationModel::GetInstance();
434 __previousSceneId = previousSceneId;
436 __pPresentationModel->AddContentEventListener(this);
440 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
441 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
443 AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
444 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
446 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
448 AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
449 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
451 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
456 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
457 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
459 AppLogDebug("Rash: FILE_MOVE_ACTION");
460 __fileActionMode = FILE_ACTION_MOVE;
462 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
464 AppLogDebug("Rash: FILE_COPY_ACTION");
465 __fileActionMode = FILE_ACTION_COPY;
467 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
470 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
474 IEnumerator* pEnum = pArgs->GetEnumeratorN();
475 if (pEnum->MoveNext() == E_SUCCESS)
477 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
480 __folderIndex = index->ToInt();
488 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
489 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
490 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
491 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
493 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
495 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
497 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
499 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
502 __callerSceneId = previousSceneId;
506 __callerSceneId = EMPTY_SPACE;
509 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
511 __nameEditFieldText = EMPTY_SPACE;
512 __nameEditFieldPreText = EMPTY_SPACE;
513 __pNameEditField->SetText(__nameEditFieldText);
514 __nameEditFieldTempText = __nameEditFieldText;
515 __pNameEditField->ShowKeypad();
516 __pNameEditField->SetFocus();
518 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
519 GetFooter()->SetItemEnabled(0, false);
520 GetFooter()->Invalidate(true);
525 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
526 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
528 String strName = pAlbumInfo->GetAlbumName();
529 __nameEditFieldText = strName;
530 __nameEditFieldPreText = strName;
531 __pNameEditField->SetText(__nameEditFieldText);
532 __nameEditFieldTempText = __nameEditFieldText;
533 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
534 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
535 __pNameEditField->ShowKeypad();
536 __pNameEditField->SetFocus();
537 __originalText = __pNameEditField->GetText();
542 __pMoveIndexList = pArgs;
545 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
549 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
550 const SceneId& nextSceneId)
552 AppLogDebug("ENTER");
553 __pPresentationModel->RemoveContentEventListener(*this);
554 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
558 AlbumNameEditorForm::OnContentUpdated(void)
560 AppLogDebug("ENTER");
562 if ( __mountState == false )
564 SceneManager* pSceneManager = SceneManager::GetInstance();
565 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
566 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
570 __mountState = false;
575 AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
577 AppLogDebug("ENTER");
579 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
581 __mountState = false;
582 SceneManager* pSceneManager = SceneManager::GetInstance();
583 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
584 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
590 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));