Fixed prevent issue
[apps/osp/Gallery.git] / src / GlAlbumNameEditorForm.cpp
index 3669f38..f706bbc 100644 (file)
@@ -46,10 +46,7 @@ using namespace Tizen::Ui;
 using namespace Tizen::Ui::Controls;
 using namespace Tizen::Ui::Scenes;
 
-
-static const Rectangle RECT_NAME_EDIT_FIELD (0, 0, 720, 100);
 static const unsigned int COLOR_NAME_EDIT_FIELD = Color32<255, 255, 255>::Value;
-static const int ALBUM_MAX_LENGTH = 255;
 
 AlbumNameEditorForm::AlbumNameEditorForm(void)
        : __pNameEditField(null)
@@ -57,24 +54,25 @@ AlbumNameEditorForm::AlbumNameEditorForm(void)
        , __modalMsgBoxResult(0)
        , __textLength(0)
        , __mountState(false)
+    , __isCreateAlbum(false)
+    , __isKeyPadOpen(false)
        , __albumNameEditorMode(ALBUM_NAME_EDITOR_MODE_RENAME)
        , __pMessageBox(null)
        , __pMoveIndexList(null)
        , __fileActionMode(FILE_ACTION_MOVE)
        , __pFileMove(null)
-       , __pProgressAnim(null)
        , __pPresentationModel(null)
        , __pFilePresentationModel(null)
 {
        AppLogDebug("ENTER");
        _overlayMsg = false;
+       _pProgressAnim = null;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
 AlbumNameEditorForm::~AlbumNameEditorForm(void)
 {
        AppLogDebug("ENTER");
-       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        delete __pFileMove;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
@@ -83,7 +81,7 @@ result
 AlbumNameEditorForm::Initialize(void)
 {
        AppLogDebug("ENTER");
-       result r = Construct(FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR);
+       result r = Construct(L"IDL_FORM_ALBUM_NAME_EDITOR");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return r;
@@ -96,14 +94,13 @@ AlbumNameEditorForm::OnInitializing(void)
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
        __pFilePresentationModel = FileListPresentationModel::GetInstance();
 
-       DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
+       SetOrientation(ORIENTATION_AUTOMATIC);
+               AddOrientationEventListener(*this);
+
        Header* pHeader = GetHeader();
 
        pHeader->SetStyle(HEADER_STYLE_TITLE);
 
-       GetFooter()->SetBackButtonEnabled(true);
-       GetFooter()->SetBackButton();
-
        FooterItem itemSave;
        itemSave.Construct(IDA_BUTTON_CREATE_NAME_SAVE);
        itemSave.SetText(ResourceManager::GetString(L"IDS_COM_OPT_SAVE"));
@@ -115,14 +112,11 @@ AlbumNameEditorForm::OnInitializing(void)
        SetFormBackEventListener(this);
        SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
 
-       __pNameEditField = new (std::nothrow) EditField();
-       __pNameEditField->Construct(RECT_NAME_EDIT_FIELD, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY,
-                       EDIT_FIELD_TITLE_STYLE_NONE, true, ALBUM_MAX_LENGTH);
+       __pNameEditField = static_cast<EditField*>(GetControl(L"IDC_EDITFIELD_NAME"));
        __pNameEditField->AddTextEventListener(*this);
        __pNameEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_NAME_EDIT_FIELD);
        __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
-
-       AddControl(__pNameEditField);
+       __pNameEditField->AddKeypadEventListener(*this);
        __pNameEditField->AddActionEventListener(*this);
 
        return E_SUCCESS;
@@ -214,10 +208,28 @@ AlbumNameEditorForm::OnTextValueChanged(const Control& source)
                        CreateMessage(msg);
                        currentInput.Replace("/", "");
                        __pNameEditField->SetText(currentInput);
+
+                       if (currentInput == L"")
+                       {
+                               if (GetFooter() != null)
+                               {
+                                       GetFooter()->SetItemEnabled(0, false);
+                                       GetFooter()->Invalidate(true);
+                               }
+                       }
                }
 
-               inputLength = byteCount;
-               if (inputLength  >= tempLength)
+               byteCountForInput = __pNameEditField->GetText();
+               r = utf8.GetByteCount(byteCountForInput, inputLength);
+
+               if ( inputLength  == tempLength )
+               {
+                       String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED");
+                       CreateMessage(msg);
+                       __pNameEditField->ShowKeypad();
+                       return;
+               }
+               else if (inputLength  > tempLength)
                {
                        String maxCharacterString;
                        String currentInputCharacter;
@@ -229,7 +241,7 @@ AlbumNameEditorForm::OnTextValueChanged(const Control& source)
                        CreateMessage(msg);
                        currentText = __pNameEditField->GetText();
 
-                       for (currentCharacter=0; checkByteCount < tempLength; currentCharacter++)
+                       for (currentCharacter=0; checkByteCount < tempLength; ++currentCharacter)
                        {
                                currentInputCharacter.Clear();
                                currentInputCharacter = currentText[currentCharacter];
@@ -240,7 +252,11 @@ AlbumNameEditorForm::OnTextValueChanged(const Control& source)
                                }
                                AppLogDebug("result of byte count is %s",GetErrorMessage(r));
                                checkByteCount = checkByteCount + byteCount;
-                               lengthOfFinalString++;
+
+                               if (checkByteCount < tempLength)
+                               {
+                                       ++lengthOfFinalString;
+                               }
                        }
 
                        r = __pNameEditField->GetText().SubString(0, lengthOfFinalString, currentInput);
@@ -316,6 +332,7 @@ AlbumNameEditorForm::OnRenameAlbum(String& strOri)
                        {
                                __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
                                                          MSGBOX_STYLE_NONE, 3000);
+
                        }
                        else
                        {
@@ -328,30 +345,59 @@ AlbumNameEditorForm::OnRenameAlbum(String& strOri)
                        _overlayMsg = false;
                        delete __pMessageBox;
                        __pMessageBox = null;
+                       __pNameEditField->SetEnabled(true);
+                       __pNameEditField->ShowKeypad();
                }
        }
        else
        {
                //Add a popup here
-               Rectangle clientRect= GetClientAreaBounds();
+               Rectangle clientRect = Form::GetBounds();
                Rectangle rect(0, 0, clientRect.width, clientRect.height);
-               __pProgressAnim = new (std::nothrow) ProgressAnimation;
-               __pProgressAnim->Construct(rect);
-               AddControl(__pProgressAnim);
-               __pProgressAnim->SetShowState(true);
+               _pProgressAnim = new (std::nothrow) ProgressAnimation;
+               _pProgressAnim->Construct(rect);
+               AddControl(_pProgressAnim);
+               _pProgressAnim->SetShowState(true);
                GetFooter()->SetEnabled(false);
-               __pProgressAnim->AnimationStart();
-               __pProgressAnim->Draw();
+               _pProgressAnim->AnimationStart();
+               _pProgressAnim->Draw();
                _overlayMsg = true;
        }
 }
 
 void
+AlbumNameEditorForm::ShowAnimation()
+{
+       Rectangle clientRect= GetClientAreaBounds();
+       Rectangle rect(0, 0, clientRect.width, clientRect.height);
+       _pProgressAnim = new (std::nothrow) ProgressAnimation;
+       _pProgressAnim->Construct(rect);
+       AddControl(_pProgressAnim);
+       _pProgressAnim->SetShowState(true);
+       GetFooter()->SetEnabled(false);
+       _pProgressAnim->AnimationStart();
+       _pProgressAnim->Draw();
+       _overlayMsg = true;
+}
+
+void
+AlbumNameEditorForm::StopAnimation(void)
+{
+       if (_pProgressAnim)
+       {
+               _pProgressAnim->AnimationStop();
+               _pProgressAnim->SetShowState(false);
+               RemoveControl(_pProgressAnim);
+               GetFooter()->SetEnabled(true);
+               _pProgressAnim = null;
+               _overlayMsg = false;
+       }
+}
+
+void
 AlbumNameEditorForm::OnCreateAlbum(void)
 {
        String path;
-       __pNameEditField->HideKeypad();
-       __pNameEditField->RequestRedraw();
        path.Append(Tizen::System::Environment::GetMediaPath());
        path.Append(__nameEditFieldText);
 
@@ -367,7 +413,7 @@ AlbumNameEditorForm::OnCreateAlbum(void)
                AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
                delete __pMoveIndexList;
                __pMoveIndexList = null;
-               return ;
+               return;
        }
 
        if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
@@ -375,11 +421,10 @@ AlbumNameEditorForm::OnCreateAlbum(void)
                AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
                delete __pMoveIndexList;
                __pMoveIndexList = null;
-               return ;
+               return;
        }
 
        delete __pFileMove;
-       GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
        __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
        if (__fileActionMode == FILE_ACTION_COPY)
        {
@@ -399,6 +444,9 @@ AlbumNameEditorForm::OnCreateAlbum(void)
                __pNameEditField->SetText(__nameEditFieldPreText);
                __pNameEditField->HideKeypad();
                __pNameEditField->Draw();
+
+               String msg = ResourceManager::GetString(L"IDS_COM_BODY_OPERATION_FAILED");
+               CreateMessage(msg);
                AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
                SceneManager* pSceneManager = SceneManager::GetInstance();
                pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
@@ -411,12 +459,13 @@ AlbumNameEditorForm::OnCreateAlbum(void)
        }
 }
 
-void AlbumNameEditorForm::OnAlbumRenameComplete(void)
+void
+AlbumNameEditorForm::OnAlbumRenameComplete(void)
 {
        //Hide popup here..
-       __pProgressAnim->AnimationStop();
-       __pProgressAnim->SetShowState(false);
-       RemoveControl(__pProgressAnim);
+       _pProgressAnim->AnimationStop();
+       _pProgressAnim->SetShowState(false);
+       RemoveControl(_pProgressAnim);
        _overlayMsg = false;
        GetFooter()->SetEnabled(true);
        SceneManager* pSceneManager = SceneManager::GetInstance();
@@ -441,14 +490,27 @@ AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
        {
        case IDA_BUTTON_CREATE_NAME_SAVE:
        {
+               __pNameEditField->SetEnabled(false);
+               __isCreateAlbum = false;
+               GetFooter()->SetItemEnabled(0, false);
+
                if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
                {
-                       OnCreateAlbum();
+                       if (__isKeyPadOpen == true )
+                       {
+                       __pNameEditField->HideKeypad();
+                       __isCreateAlbum = true;
+                       }
+                       else
+                       {
+                               OnCreateAlbum();
+                       }
+
                }
                else if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
                {
                        String albumName = __pNameEditField->GetText();
-                       if (__originalText.Equals(albumName , true))
+                       if (__originalText.Equals(albumName, true))
                        {
                                SceneManager* pSceneManager = SceneManager::GetInstance();
                                pSceneManager->GoBackward(BackwardSceneTransition());
@@ -471,6 +533,14 @@ void
 AlbumNameEditorForm::OnFormBackRequested(Form& source)
 {
        AppLogDebug("ENTER");
+       if (_pProgressAnim != null)
+       {
+               if (_pProgressAnim->GetShowState())
+               {
+                       return;
+               }
+       }
+
        if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
        {
                SceneManager* pSceneManager = SceneManager::GetInstance();
@@ -492,6 +562,7 @@ AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
        __pPresentationModel = AlbumListPresentationModel::GetInstance();
        __previousSceneId = previousSceneId;
 
+       DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        __pPresentationModel->AddContentEventListener(this);
 
        if (pArgs != null)
@@ -541,6 +612,7 @@ AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
                        }
                        delete pEnum;
                        delete pArgs;
+                       pArgs = NULL;
                }
        }
 
@@ -614,7 +686,17 @@ AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
                const SceneId& nextSceneId)
 {
        AppLogDebug("ENTER");
+
+       if(__pNameEditField->IsEnabled() == false)
+       {
+               __pNameEditField->SetEnabled(true);
+       }
+
+       __isKeyPadOpen = false;
+
        __pPresentationModel->RemoveContentEventListener(*this);
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
+
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -623,8 +705,15 @@ AlbumNameEditorForm::OnContentUpdated(void)
 {
        AppLogDebug("ENTER");
 
-       if ( __mountState == false )
+       if (__mountState == false)
        {
+               if (__pFileMove && __pFileMove->IsStarted())
+                       {
+                               __pFileMove->Cancel();
+                               delete __pFileMove;
+                               __pFileMove = null;
+                       }
+
                SceneManager* pSceneManager = SceneManager::GetInstance();
                pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
                AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -642,6 +731,12 @@ AlbumNameEditorForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Ba
 
        if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
        {
+               if (__pFileMove && __pFileMove->IsStarted())
+               {
+                       __pFileMove->Cancel();
+                       delete __pFileMove;
+                       __pFileMove = null;
+               }
                __mountState = false;
                SceneManager* pSceneManager = SceneManager::GetInstance();
                pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
@@ -672,3 +767,35 @@ AlbumNameEditorForm::CreateMessage(String& str)
                }
        }
 }
+
+void
+AlbumNameEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
+{
+       if (_pProgressAnim != null)
+       {
+               _pProgressAnim->ChangeOrientation(Form::GetBounds());
+               _pProgressAnim->Invalidate(true);
+       }
+}
+
+void
+AlbumNameEditorForm::OnKeypadClosed(Tizen::Ui::Control& source)
+{
+       AppLogDebug("ENTER");
+
+       if ( __isCreateAlbum == true)
+       {
+               OnCreateAlbum();
+       __isCreateAlbum = false;
+       }
+       __isKeyPadOpen = false;
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+void
+AlbumNameEditorForm::OnKeypadOpened(Tizen::Ui::Control& source)
+{
+       AppLogDebug("ENTER");
+       __isKeyPadOpen = true;
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}