Fixed zira issues
[apps/osp/Gallery.git] / src / GlAlbumNameEditorForm.cpp
index e37ff71..af295a1 100644 (file)
@@ -19,7 +19,7 @@
  * @brief              This is the implementation file for AlbumNameEditorForm class.
  */
 
-#include <FApp.h>
+#include <FMedia.h>
 #include "GlAlbumInfo.h"
 #include "GlAlbumListPresentationModel.h"
 #include "GlAlbumNameEditorForm.h"
@@ -47,24 +47,24 @@ 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()
+AlbumNameEditorForm::AlbumNameEditorForm(void)
        : __pNameEditField(null)
        , __folderIndex(0)
        , __albumNameEditorMode(ALBUM_NAME_EDITOR_MODE_RENAME)
        , __pMessageBox(null)
        , __pMoveIndexList(null)
-       , __fileActionMode(FILE_MOVE_ACTION)
+       , __fileActionMode(FILE_ACTION_MOVE)
        , __pFileMove(null)
        , __pProgressAnim(null)
        , __pPresentationModel(null)
        , __pFilePresentationModel(null)
 {
        AppLogDebug("ENTER");
-       __overlayMsg = false;
+       _overlayMsg = false;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
-AlbumNameEditorForm::~AlbumNameEditorForm()
+AlbumNameEditorForm::~AlbumNameEditorForm(void)
 {
        delete __pFileMove;
        AppLogDebug("ENTER");
@@ -96,7 +96,7 @@ AlbumNameEditorForm::OnInitializing(void)
        GetFooter()->SetBackButton();
 
        FooterItem itemSave;
-       itemSave.Construct(ACTION_ID_BUTTON_CREATE_NAME_SAVE);
+       itemSave.Construct(IDA_BUTTON_CREATE_NAME_SAVE);
        itemSave.SetText(ResourceManager::GetString(L"IDS_COM_OPT_SAVE"));
 
        GetFooter()->AddItem(itemSave);
@@ -133,9 +133,9 @@ AlbumNameEditorForm::OnTextValueChanged(const Control& source)
                        __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS"),
                                        MSGBOX_STYLE_NONE, 3000);
                        int modalResult = 0;
-                       __overlayMsg = true;
+                       _overlayMsg = true;
                        __pMessageBox->ShowAndWait(modalResult);
-                       __overlayMsg = false;
+                       _overlayMsg = false;
                        delete __pMessageBox;
                        __pMessageBox = null;
                }
@@ -146,11 +146,11 @@ AlbumNameEditorForm::OnTextValueChanged(const Control& source)
                return;
        }
 
-       ByteBuffer* buffer = StringUtil::StringToUtf8N(inputString);
+       ByteBuffer* pBuffer = StringUtil::StringToUtf8N(inputString);
        int remaining = 0;
-       if (buffer != null)
+       if (pBuffer != null)
        {
-               remaining = buffer->GetRemaining();
+               remaining = pBuffer->GetRemaining();
        }
 
        if (remaining >= ALBUM_MAX_LENGTH)
@@ -220,7 +220,7 @@ void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
 
 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
 {
-       __overlayMsg = false;
+       _overlayMsg = false;
        if (res != COMPLETE_SUCCESS)
        {
                __pNameEditField->SetText(__nameEditFieldPreText);
@@ -232,42 +232,57 @@ void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum Fi
 }
 
 void
-AlbumNameEditorForm::OnRenameAlbum(const String& strOri)
+AlbumNameEditorForm::OnRenameAlbum(String& strOri)
 {
        AppLogDebug("Rename Album");
        String path;
-       path.Append(Tizen::System::Environment::GetMediaPath());
+       int index = 0;
+       strOri.Reverse();
+       strOri.IndexOf(DIRECTORY_SEPARATOR, 0, index);
+       strOri.Reverse();
+       strOri.SubString(0, (strOri.GetLength() - index), path);
        path.Append(__nameEditFieldText);
 
        //Rename
        result r = __pPresentationModel->RenameAlbum(strOri, path, this);
+
        if (IsFailed(r))
        {
                AppLogDebug("Unable to rename Album %s", GetErrorMessage(r));
                if (__pMessageBox == null)
                {
                        __pMessageBox = new (std::nothrow) MessageBox();
-                       __pMessageBox->Construct(L"", L"Unable to rename", MSGBOX_STYLE_NONE, 3000);
+                       if (r == E_FILE_ALREADY_EXIST)
+                       {
+                               __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_BODY_UNABLE_TO_RENAME_ALBUM_NAME_ALREADY_IN_USE_ABB"),
+                                                         MSGBOX_STYLE_NONE, 3000);
+                       }
+                       else
+                       {
+                               __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_MEDIABR_POP_UNABLE_TO_RENAME"),
+                                                         MSGBOX_STYLE_NONE, 3000);
+                       }
                        int modalResult = 0;
-                       __overlayMsg = true;
+                       _overlayMsg = true;
                        __pMessageBox->ShowAndWait(modalResult);
-                       __overlayMsg = false;
+                       _overlayMsg = false;
                        delete __pMessageBox;
                        __pMessageBox = null;
                }
        }
        else
        {
-               //Add a popup here..
+               //Add a popup here
                Rectangle clientRect= GetClientAreaBounds();
-               Rectangle rect(0,0,clientRect.width,clientRect.height);
+               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;
+               _overlayMsg = true;
        }
 }
 
@@ -305,8 +320,8 @@ AlbumNameEditorForm::OnCreateAlbum(void)
 
        delete __pFileMove;
        GetMoveFileIndexList(path, __pMoveIndexList, __pFilePresentationModel);
-       __pFileMove = new FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
-       if(__fileActionMode == FILE_COPY_ACTION)
+       __pFileMove = new (std::nothrow) FileMoveTimer(path, __pMoveIndexList, __pFilePresentationModel, this);
+       if (__fileActionMode == FILE_ACTION_COPY)
        {
                AppLogDebug("Rash: Setting to Copy in AlbumNameEditor");
                __pFileMove->SetCopy();
@@ -331,8 +346,8 @@ AlbumNameEditorForm::OnCreateAlbum(void)
        else
        {
                AppLogDebug("MoveToContentFileList content in progress");
-               __overlayMsg = true;
-               __fileActionMode = FILE_MOVE_ACTION;
+               _overlayMsg = true;
+               __fileActionMode = FILE_ACTION_MOVE;
        }
 }
 
@@ -342,7 +357,8 @@ void AlbumNameEditorForm::OnAlbumRenameComplete(void)
        __pProgressAnim->AnimationStop();
        __pProgressAnim->SetShowState(false);
        RemoveControl(*__pProgressAnim);
-       __overlayMsg = false;
+       _overlayMsg = false;
+       GetFooter()->SetEnabled(true);
        SceneManager* pSceneManager = SceneManager::GetInstance();
        pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
 }
@@ -363,7 +379,7 @@ AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
 
        switch (actionId)
        {
-       case ACTION_ID_BUTTON_CREATE_NAME_SAVE:
+       case IDA_BUTTON_CREATE_NAME_SAVE:
        {
                if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
                {
@@ -372,7 +388,7 @@ AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
                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());
@@ -416,15 +432,17 @@ AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
        __pPresentationModel = AlbumListPresentationModel::GetInstance();
        __previousSceneId = previousSceneId;
 
+       __pPresentationModel->AddContentEventListener(this);
+
        if (pArgs != null)
        {
-               Integer* albumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
-               if (albumTypePtr->ToInt() == ALBUM_CREATE)
+               Integer* pAlbumTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
+               if (pAlbumTypePtr->ToInt() == ALBUM_CREATE)
                {
                        AppLogDebug("ALBUM_NAME_EDITOR_MODE_CREATE");
                        __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
                }
-               else if (albumTypePtr->ToInt() == ALBUM_RENAME)
+               else if (pAlbumTypePtr->ToInt() == ALBUM_RENAME)
                {
                        AppLogDebug("ALBUM_NAME_EDITOR_MODE_RENAME");
                        __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
@@ -435,15 +453,15 @@ AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
        if (pArgs != null)
        {
                Integer* operationTypePtr = static_cast<Integer*>(pArgs->GetAt(ALBUM_FIRST_ELEMENT));
-               if (operationTypePtr->ToInt() == FILE_MOVE_ACTION)
+               if (operationTypePtr->ToInt() == FILE_ACTION_MOVE)
                {
                        AppLogDebug("Rash: FILE_MOVE_ACTION");
-                       __fileActionMode = FILE_MOVE_ACTION;
+                       __fileActionMode = FILE_ACTION_MOVE;
                }
-               else if (operationTypePtr->ToInt() == FILE_COPY_ACTION)
+               else if (operationTypePtr->ToInt() == FILE_ACTION_COPY)
                {
                        AppLogDebug("Rash: FILE_COPY_ACTION");
-                       __fileActionMode = FILE_COPY_ACTION;
+                       __fileActionMode = FILE_ACTION_COPY;
                }
                pArgs->RemoveAt(ALBUM_FIRST_ELEMENT, true);
        }
@@ -528,5 +546,16 @@ AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
                const SceneId& nextSceneId)
 {
        AppLogDebug("ENTER");
+       __pPresentationModel->RemoveContentEventListener(*this);
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+void
+AlbumNameEditorForm::OnContentUpdated(void)
+{
+       AppLogDebug("ENTER");
+
+       SceneManager* pSceneManager = SceneManager::GetInstance();
+       pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }