Fixed prevent issue
[apps/osp/Gallery.git] / src / GlAlbumNameEditorForm.cpp
index 3ce1d2f..f706bbc 100644 (file)
@@ -54,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()));
 }
@@ -96,7 +97,6 @@ AlbumNameEditorForm::OnInitializing(void)
        SetOrientation(ORIENTATION_AUTOMATIC);
                AddOrientationEventListener(*this);
 
-       DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        Header* pHeader = GetHeader();
 
        pHeader->SetStyle(HEADER_STYLE_TITLE);
@@ -116,6 +116,7 @@ AlbumNameEditorForm::OnInitializing(void)
        __pNameEditField->AddTextEventListener(*this);
        __pNameEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_NAME_EDIT_FIELD);
        __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
+       __pNameEditField->AddKeypadEventListener(*this);
        __pNameEditField->AddActionEventListener(*this);
 
        return E_SUCCESS;
@@ -207,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;
@@ -335,23 +354,50 @@ AlbumNameEditorForm::OnRenameAlbum(String& strOri)
                //Add a popup here
                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);
 
@@ -379,7 +425,6 @@ AlbumNameEditorForm::OnCreateAlbum(void)
        }
 
        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();
@@ -442,11 +491,21 @@ 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)
                {
@@ -474,9 +533,9 @@ void
 AlbumNameEditorForm::OnFormBackRequested(Form& source)
 {
        AppLogDebug("ENTER");
-       if (__pProgressAnim != null)
+       if (_pProgressAnim != null)
        {
-               if (__pProgressAnim->GetShowState())
+               if (_pProgressAnim->GetShowState())
                {
                        return;
                }
@@ -503,7 +562,7 @@ AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
        __pPresentationModel = AlbumListPresentationModel::GetInstance();
        __previousSceneId = previousSceneId;
 
-       __pNameEditField->SetEnabled(true);
+       DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        __pPresentationModel->AddContentEventListener(this);
 
        if (pArgs != null)
@@ -627,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()));
 }
 
@@ -638,6 +707,13 @@ AlbumNameEditorForm::OnContentUpdated(void)
 
        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()));
@@ -695,9 +771,31 @@ AlbumNameEditorForm::CreateMessage(String& str)
 void
 AlbumNameEditorForm::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
 {
-       if (__pProgressAnim != null)
+       if (_pProgressAnim != null)
        {
-               __pProgressAnim->ChangeOrientation(Form::GetBounds());
-               __pProgressAnim->Invalidate(true);
+               _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()));
+}