Fixed prevent issue
[apps/osp/Gallery.git] / src / GlAlbumNameEditorForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                GlAlbumNameEditorForm.cpp
19  * @brief               This is the implementation file for AlbumNameEditorForm class.
20  */
21
22 #include <FMedia.h>
23 #include <FText.h>
24
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"
32 #include "GlTypes.h"
33
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;
48
49 static const unsigned int COLOR_NAME_EDIT_FIELD = Color32<255, 255, 255>::Value;
50
51 AlbumNameEditorForm::AlbumNameEditorForm(void)
52         : __pNameEditField(null)
53         , __folderIndex(0)
54         , __modalMsgBoxResult(0)
55         , __textLength(0)
56         , __mountState(false)
57     , __isCreateAlbum(false)
58     , __isKeyPadOpen(false)
59         , __albumNameEditorMode(ALBUM_NAME_EDITOR_MODE_RENAME)
60         , __pMessageBox(null)
61         , __pMoveIndexList(null)
62         , __fileActionMode(FILE_ACTION_MOVE)
63         , __pFileMove(null)
64         , __pPresentationModel(null)
65         , __pFilePresentationModel(null)
66 {
67         AppLogDebug("ENTER");
68         _overlayMsg = false;
69         _pProgressAnim = null;
70         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
71 }
72
73 AlbumNameEditorForm::~AlbumNameEditorForm(void)
74 {
75         AppLogDebug("ENTER");
76         delete __pFileMove;
77         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
78 }
79
80 result
81 AlbumNameEditorForm::Initialize(void)
82 {
83         AppLogDebug("ENTER");
84         result r = Construct(L"IDL_FORM_ALBUM_NAME_EDITOR");
85         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
86
87         return r;
88 }
89
90 result
91 AlbumNameEditorForm::OnInitializing(void)
92 {
93         AppLogDebug("ENTER");
94         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
95         __pFilePresentationModel = FileListPresentationModel::GetInstance();
96
97         SetOrientation(ORIENTATION_AUTOMATIC);
98                 AddOrientationEventListener(*this);
99
100         Header* pHeader = GetHeader();
101
102         pHeader->SetStyle(HEADER_STYLE_TITLE);
103
104         FooterItem itemSave;
105         itemSave.Construct(IDA_BUTTON_CREATE_NAME_SAVE);
106         itemSave.SetText(ResourceManager::GetString(L"IDS_COM_OPT_SAVE"));
107
108         GetFooter()->AddItem(itemSave);
109         GetFooter()->AddActionEventListener(*this);
110         GetFooter()->Invalidate(true);
111
112         SetFormBackEventListener(this);
113         SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
114
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->AddKeypadEventListener(*this);
120         __pNameEditField->AddActionEventListener(*this);
121
122         return E_SUCCESS;
123 }
124
125 void
126 AlbumNameEditorForm::OnTextValueChanged(const Control& source)
127 {
128         String currentInput;
129         String currentText;
130         String specialCharacters(L"/");
131         String byteCountForInput;
132         int byteCount = 0;
133         int inputLength = 0;
134         int tempLength = 255;
135         int textToCheck = 0;
136         MessageBox messageBox;
137         Utf8Encoding utf8;
138
139         FooterItemStatus currentStatus = FOOTER_ITEM_STATUS_NORMAL;
140
141         result r = E_SUCCESS;
142
143         if (__pNameEditField != null)
144         {
145                 byteCountForInput = __pNameEditField->GetText();
146                 r = utf8.GetByteCount(byteCountForInput, byteCount);
147                 AppLogDebug("result is %s",GetErrorMessage(r));
148                 AppLogDebug("Byte count is %d",byteCount);
149         }
150
151         if (__pNameEditField != null)
152         {
153                 currentText = __pNameEditField->GetText();
154                 textToCheck = currentText.GetLength() - __textLength;
155                 if (currentText.IsEmpty())
156                 {
157                         if (GetFooter() != null)
158                         {
159                                 GetFooter()->SetItemEnabled(0, false);
160                                 GetFooter()->Invalidate(true);
161                         }
162                 }
163                 else
164                 {
165                         if (GetFooter() != null)
166                         {
167                                 GetFooter()->GetItemStatus(0, currentStatus);
168
169                                 if (currentStatus == FOOTER_ITEM_STATUS_DISABLED)
170                                 {
171                                         GetFooter()->SetItemEnabled(0,true);
172                                         GetFooter()->Invalidate(true);
173                                 }
174                         }
175                 }
176
177                 if (currentText.StartsWith(".", 0))
178                 {
179                         String invalidCharacterString;
180                         String validString;
181                         String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS");
182                         CreateMessage(msg);
183                         validString = __pNameEditField->GetText();
184
185                         if (validString.GetLength() > 1)
186                         {
187                                 validString.Remove(0,1);
188                                 __pNameEditField->SetText(validString);
189                         }
190                         else
191                         {
192                                 __pNameEditField->SetText("");
193
194                                 if (GetFooter() != null)
195                                 {
196                                         GetFooter()->SetItemEnabled(0, false);
197                                         GetFooter()->Invalidate(true);
198                                 }
199                         }
200                         __pNameEditField->ShowKeypad();
201                 }
202
203                 currentInput = __pNameEditField->GetText();
204
205                 if (currentInput.Contains(specialCharacters[0]))
206                 {
207                         String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS");
208                         CreateMessage(msg);
209                         currentInput.Replace("/", "");
210                         __pNameEditField->SetText(currentInput);
211
212                         if (currentInput == L"")
213                         {
214                                 if (GetFooter() != null)
215                                 {
216                                         GetFooter()->SetItemEnabled(0, false);
217                                         GetFooter()->Invalidate(true);
218                                 }
219                         }
220                 }
221
222                 byteCountForInput = __pNameEditField->GetText();
223                 r = utf8.GetByteCount(byteCountForInput, inputLength);
224
225                 if ( inputLength  == tempLength )
226                 {
227                         String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED");
228                         CreateMessage(msg);
229                         __pNameEditField->ShowKeypad();
230                         return;
231                 }
232                 else if (inputLength  > tempLength)
233                 {
234                         String maxCharacterString;
235                         String currentInputCharacter;
236                         int checkByteCount = 0;
237                         int lengthOfFinalString = 0;
238                         int currentCharacter = 0;
239
240                         String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED");
241                         CreateMessage(msg);
242                         currentText = __pNameEditField->GetText();
243
244                         for (currentCharacter=0; checkByteCount < tempLength; ++currentCharacter)
245                         {
246                                 currentInputCharacter.Clear();
247                                 currentInputCharacter = currentText[currentCharacter];
248                                 r = utf8.GetByteCount(currentInputCharacter, byteCount);
249                                 if (r != E_SUCCESS)
250                                 {
251                                         break;
252                                 }
253                                 AppLogDebug("result of byte count is %s",GetErrorMessage(r));
254                                 checkByteCount = checkByteCount + byteCount;
255
256                                 if (checkByteCount < tempLength)
257                                 {
258                                         ++lengthOfFinalString;
259                                 }
260                         }
261
262                         r = __pNameEditField->GetText().SubString(0, lengthOfFinalString, currentInput);
263                         AppLogDebug("current input is %S", currentInput.GetPointer());
264                         r = __pNameEditField->SetText(currentInput);
265                         __pNameEditField->ShowKeypad();
266                         return;
267                 }
268
269                 r = utf8.GetByteCount(__pNameEditField->GetText(), byteCount);
270                 __textLength = byteCount;
271         }
272
273         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
274 }
275
276 void
277 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
278 {
279         AppLogDebug("ENTER");
280         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
281 }
282
283 result
284 AlbumNameEditorForm::OnTerminating(void)
285 {
286         AppLogDebug("ENTER");
287         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
288
289         return E_SUCCESS;
290 }
291
292 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
293 {
294         Invalidate(true);
295 }
296
297 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
298 {
299         _overlayMsg = false;
300         if (res != COMPLETE_SUCCESS)
301         {
302                 __pNameEditField->SetText(__nameEditFieldPreText);
303                 __pNameEditField->HideKeypad();
304                 __pNameEditField->Draw();
305                 SceneManager* pSceneManager = SceneManager::GetInstance();
306                 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
307         }
308 }
309
310 void
311 AlbumNameEditorForm::OnRenameAlbum(String& strOri)
312 {
313         AppLogDebug("Rename Album");
314         String path;
315         int index = 0;
316         strOri.Reverse();
317         strOri.IndexOf(DIRECTORY_SEPARATOR, 0, index);
318         strOri.Reverse();
319         strOri.SubString(0, (strOri.GetLength() - index), path);
320         path.Append(__nameEditFieldText);
321
322         //Rename
323         result r = __pPresentationModel->RenameAlbum(strOri, path, this);
324
325         if (IsFailed(r))
326         {
327                 AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
328                 if (__pMessageBox == null)
329                 {
330                         __pMessageBox = new (std::nothrow) MessageBox();
331                         if (r == E_FILE_ALREADY_EXIST)
332                         {
333                                 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
334                                                           MSGBOX_STYLE_NONE, 3000);
335
336                         }
337                         else
338                         {
339                                 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
340                                                           MSGBOX_STYLE_NONE, 3000);
341                         }
342                         int modalResult = 0;
343                         _overlayMsg = true;
344                         __pMessageBox->ShowAndWait(modalResult);
345                         _overlayMsg = false;
346                         delete __pMessageBox;
347                         __pMessageBox = null;
348                         __pNameEditField->SetEnabled(true);
349                         __pNameEditField->ShowKeypad();
350                 }
351         }
352         else
353         {
354                 //Add a popup here
355                 Rectangle clientRect = Form::GetBounds();
356                 Rectangle rect(0, 0, clientRect.width, clientRect.height);
357                 _pProgressAnim = new (std::nothrow) ProgressAnimation;
358                 _pProgressAnim->Construct(rect);
359                 AddControl(_pProgressAnim);
360                 _pProgressAnim->SetShowState(true);
361                 GetFooter()->SetEnabled(false);
362                 _pProgressAnim->AnimationStart();
363                 _pProgressAnim->Draw();
364                 _overlayMsg = true;
365         }
366 }
367
368 void
369 AlbumNameEditorForm::ShowAnimation()
370 {
371         Rectangle clientRect= GetClientAreaBounds();
372         Rectangle rect(0, 0, clientRect.width, clientRect.height);
373         _pProgressAnim = new (std::nothrow) ProgressAnimation;
374         _pProgressAnim->Construct(rect);
375         AddControl(_pProgressAnim);
376         _pProgressAnim->SetShowState(true);
377         GetFooter()->SetEnabled(false);
378         _pProgressAnim->AnimationStart();
379         _pProgressAnim->Draw();
380         _overlayMsg = true;
381 }
382
383 void
384 AlbumNameEditorForm::StopAnimation(void)
385 {
386         if (_pProgressAnim)
387         {
388                 _pProgressAnim->AnimationStop();
389                 _pProgressAnim->SetShowState(false);
390                 RemoveControl(_pProgressAnim);
391                 GetFooter()->SetEnabled(true);
392                 _pProgressAnim = null;
393                 _overlayMsg = false;
394         }
395 }
396
397 void
398 AlbumNameEditorForm::OnCreateAlbum(void)
399 {
400         String path;
401         path.Append(Tizen::System::Environment::GetMediaPath());
402         path.Append(__nameEditFieldText);
403
404         if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
405         {
406                 Directory::Create(path, true);
407         }
408
409         __nameEditFieldPreText = __nameEditFieldText;
410
411         if (path.IsEmpty())
412         {
413                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
414                 delete __pMoveIndexList;
415                 __pMoveIndexList = null;
416                 return;
417         }
418
419         if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
420         {
421                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
422                 delete __pMoveIndexList;
423                 __pMoveIndexList = null;
424                 return;
425         }
426
427         delete __pFileMove;
428         __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
429         if (__fileActionMode == FILE_ACTION_COPY)
430         {
431                 AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
432                 __pFileMove->SetCopy();
433         }
434         else
435         {
436                 __pFileMove->ClearCopy();
437         }
438         result r = __pFileMove->StartTimer();
439
440         if (IsFailed(r))
441         {
442                 delete __pFileMove;
443                 __pFileMove = null;
444                 __pNameEditField->SetText(__nameEditFieldPreText);
445                 __pNameEditField->HideKeypad();
446                 __pNameEditField->Draw();
447
448                 String msg = ResourceManager::GetString(L"IDS_COM_BODY_OPERATION_FAILED");
449                 CreateMessage(msg);
450                 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
451                 SceneManager* pSceneManager = SceneManager::GetInstance();
452                 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
453         }
454         else
455         {
456                 AppLogDebug("MoveToContentFileList content in progress");
457                 _overlayMsg = true;
458                 __fileActionMode = FILE_ACTION_MOVE;
459         }
460 }
461
462 void
463 AlbumNameEditorForm::OnAlbumRenameComplete(void)
464 {
465         //Hide popup here..
466         _pProgressAnim->AnimationStop();
467         _pProgressAnim->SetShowState(false);
468         RemoveControl(_pProgressAnim);
469         _overlayMsg = false;
470         GetFooter()->SetEnabled(true);
471         SceneManager* pSceneManager = SceneManager::GetInstance();
472         pSceneManager->GoBackward((BackwardSceneTransition(IDSCN_ALBUM_LIST)));
473 }
474
475 void
476 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
477 {
478         AppLogDebug("ENTER");
479         String path;
480         __nameEditFieldText = __pNameEditField->GetText();
481
482         if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
483         {
484                 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
485                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
486                 path = pAlbumInfo->GetDirectory(0);
487         }
488
489         switch (actionId)
490         {
491         case IDA_BUTTON_CREATE_NAME_SAVE:
492         {
493                 __pNameEditField->SetEnabled(false);
494                 __isCreateAlbum = false;
495                 GetFooter()->SetItemEnabled(0, false);
496
497                 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
498                 {
499                         if (__isKeyPadOpen == true )
500                         {
501                         __pNameEditField->HideKeypad();
502                         __isCreateAlbum = true;
503                         }
504                         else
505                         {
506                                 OnCreateAlbum();
507                         }
508
509                 }
510                 else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
511                 {
512                         String albumName = __pNameEditField->GetText();
513                         if (__originalText.Equals(albumName, true))
514                         {
515                                 SceneManager* pSceneManager = SceneManager::GetInstance();
516                                 pSceneManager->GoBackward(BackwardSceneTransition());
517                         }
518                         else
519                         {
520                                 OnRenameAlbum(path);
521                         }
522                 }
523                 break;
524         }
525
526         default:
527                 break;
528         }
529         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
530 }
531
532 void
533 AlbumNameEditorForm::OnFormBackRequested(Form& source)
534 {
535         AppLogDebug("ENTER");
536         if (_pProgressAnim != null)
537         {
538                 if (_pProgressAnim->GetShowState())
539                 {
540                         return;
541                 }
542         }
543
544         if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
545         {
546                 SceneManager* pSceneManager = SceneManager::GetInstance();
547                 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
548         }
549         else
550         {
551                 SceneManager* pSceneManager = SceneManager::GetInstance();
552                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
553         }
554         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
555 }
556
557 void
558 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
559                 const SceneId& currentSceneId, IList* pArgs)
560 {
561         AppLogDebug("ENTER");
562         __pPresentationModel = AlbumListPresentationModel::GetInstance();
563         __previousSceneId = previousSceneId;
564
565         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
566         __pPresentationModel->AddContentEventListener(this);
567
568         if (pArgs != null)
569         {
570                 Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
571                 if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
572                 {
573                         AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
574                         __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
575                 }
576                 else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
577                 {
578                         AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
579                         __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
580                 }
581                 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
582         }
583
584         if (pArgs != null)
585         {
586                 Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
587                 if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
588                 {
589                         AppLogDebug("Rash: FILE_MOVE_ACTION");
590                         __fileActionMode = FILE_ACTION_MOVE;
591                 }
592                 else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
593                 {
594                         AppLogDebug("Rash: FILE_COPY_ACTION");
595                         __fileActionMode = FILE_ACTION_COPY;
596                 }
597                 pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
598         }
599
600         if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
601         {
602                 if (pArgs != null)
603                 {
604                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
605                         if (pEnum->MoveNext() == E_SUCCESS)
606                         {
607                                 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
608                                 if (index != null)
609                                 {
610                                         __folderIndex = index->ToInt();
611                                 }
612                         }
613                         delete pEnum;
614                         delete pArgs;
615                         pArgs = NULL;
616                 }
617         }
618
619         if (previousSceneId == IDSCN_ALL_LIST_EDITOR
620                         || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
621                         || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
622                         || previousSceneId == IDSCN_ALL_LIST_SELECTION)
623         {
624                 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
625                 {
626                         AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
627                 }
628                 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
629                 {
630                         AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
631                 }
632
633                 __callerSceneId = previousSceneId;
634         }
635         else
636         {
637                 __callerSceneId = EMPTY_SPACE;
638         }
639
640         if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
641         {
642                 __nameEditFieldText = EMPTY_SPACE;
643                 __nameEditFieldPreText = EMPTY_SPACE;
644                 __pNameEditField->SetText(__nameEditFieldText);
645                 __nameEditFieldTempText = __nameEditFieldText;
646                 __pNameEditField->ShowKeypad();
647                 __pNameEditField->SetFocus();
648
649                 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_MEDIABR_OPT_CREATE_ALBUM"));
650                 GetFooter()->SetItemEnabled(0, false);
651                 GetFooter()->Invalidate(true);
652         }
653         else
654         {
655                 int byteCount = 0;
656                 Utf8Encoding utf8;
657                 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
658                 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
659
660                 String strName = pAlbumInfo->GetAlbumName();
661                 __nameEditFieldText = strName;
662                 __nameEditFieldPreText = strName;
663                 __pNameEditField->SetText(__nameEditFieldText);
664                 __nameEditFieldTempText = __nameEditFieldText;
665                 GetHeader()->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_RENAME"));
666                 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
667                 __pNameEditField->ShowKeypad();
668                 __pNameEditField->SetFocus();
669                 __originalText = __pNameEditField->GetText();
670                 utf8.GetByteCount(__nameEditFieldText, byteCount);
671                 __textLength = byteCount;
672                 GetFooter()->SetItemEnabled(0, true);
673                 GetFooter()->Invalidate(true);
674         }
675
676         if (pArgs != NULL)
677         {
678                 __pMoveIndexList = pArgs;
679         }
680
681         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
682 }
683
684 void
685 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
686                 const SceneId& nextSceneId)
687 {
688         AppLogDebug("ENTER");
689
690         if(__pNameEditField->IsEnabled() == false)
691         {
692                 __pNameEditField->SetEnabled(true);
693         }
694
695         __isKeyPadOpen = false;
696
697         __pPresentationModel->RemoveContentEventListener(*this);
698         DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
699
700         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
701 }
702
703 void
704 AlbumNameEditorForm::OnContentUpdated(void)
705 {
706         AppLogDebug("ENTER");
707
708         if (__mountState == false)
709         {
710                 if (__pFileMove && __pFileMove->IsStarted())
711                         {
712                                 __pFileMove->Cancel();
713                                 delete __pFileMove;
714                                 __pFileMove = null;
715                         }
716
717                 SceneManager* pSceneManager = SceneManager::GetInstance();
718                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
719                 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
720         }
721         else
722         {
723                 __mountState = false;
724         }
725 }
726
727 void
728 AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
729 {
730         AppLogDebug("ENTER");
731
732         if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
733         {
734                 if (__pFileMove && __pFileMove->IsStarted())
735                 {
736                         __pFileMove->Cancel();
737                         delete __pFileMove;
738                         __pFileMove = null;
739                 }
740                 __mountState = false;
741                 SceneManager* pSceneManager = SceneManager::GetInstance();
742                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
743                 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
744         }
745         else
746         {
747                 __mountState = true;
748         }
749         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
750 }
751
752 void
753 AlbumNameEditorForm::CreateMessage(String& str)
754 {
755         if (__pMessageBox == null)
756         {
757                 __pMessageBox = new(std::nothrow) MessageBox;
758
759                 if (__pMessageBox != null)
760                 {
761                         __pMessageBox->Construct(L"", str, MSGBOX_STYLE_OK, 3000);
762                         __pMessageBox->ShowAndWait(__modalMsgBoxResult);
763
764                         delete __pMessageBox;
765                         __pMessageBox = null;
766                         __modalMsgBoxResult = 0;
767                 }
768         }
769 }
770
771 void
772 AlbumNameEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
773 {
774         if (_pProgressAnim != null)
775         {
776                 _pProgressAnim->ChangeOrientation(Form::GetBounds());
777                 _pProgressAnim->Invalidate(true);
778         }
779 }
780
781 void
782 AlbumNameEditorForm::OnKeypadClosed(Tizen::Ui::Control& source)
783 {
784         AppLogDebug("ENTER");
785
786         if ( __isCreateAlbum == true)
787         {
788                 OnCreateAlbum();
789         __isCreateAlbum = false;
790         }
791         __isKeyPadOpen = false;
792         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
793 }
794
795 void
796 AlbumNameEditorForm::OnKeypadOpened(Tizen::Ui::Control& source)
797 {
798         AppLogDebug("ENTER");
799         __isKeyPadOpen = true;
800         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
801 }