Fixed prevent issue
[apps/osp/Gallery.git] / src / GlAllListPanel.cpp
index 78ba548..21a7cdb 100644 (file)
@@ -1,7 +1,7 @@
 //
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
@@ -19,8 +19,6 @@
  * @brief              This is the implementation file for AllListPanel class.
  */
 
-#include <FContent.h>
-#include <FMedia.h>
 #include "GlAlbumInfo.h"
 #include "GlAllListPanel.h"
 #include "GlCommonUtil.h"
@@ -40,21 +38,21 @@ using namespace Tizen::Ui::Scenes;
 
 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
 static const int W_CLIENT = 720;
-static const int H_CONTENT_MARGIN = 24;
-static const int W_CONTENT_MARGIN = 14;
-static const int W_CONTENT_SPACE = 20;
-static const int H_CONTENT_SPACE = 24;
-
-AllListPanel::AllListPanel()
-       : __pContentIconListView(null)
-       , __itemCount(0)
+static const int H_CONTENT_MARGIN = 9;
+static const int W_CONTENT_MARGIN = 6;
+static const int W_CONTENT_SPACE = 6;
+static const int H_CONTENT_SPACE = 6;
+
+AllListPanel::AllListPanel(void)
+       : __itemCount(0)
+       , __pContentIconListView(null)
        , __pPresentationModel(null)
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
-AllListPanel::~AllListPanel()
+AllListPanel::~AllListPanel(void)
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -64,7 +62,7 @@ void
 AllListPanel::Refresh(void)
 {
        AppLogDebug("ENTER");
-       if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
+       if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
        {
                if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
                {
@@ -85,6 +83,25 @@ AllListPanel::Refresh(void)
        }
 
        __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
+       if (__itemCount == 0)
+       {
+               SceneManager* pSceneManager = SceneManager::GetInstance();
+               TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
+
+               pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_ALBUM_LIST,SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_DESTROY_OPTION_KEEP));
+       }
+       else
+       {
+               SceneManager* pSceneManager = SceneManager::GetInstance();
+               TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager", GetErrorMessage(GetLastResult()));
+
+               FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
+               if (pFileListForm != null)
+               {
+                       pFileListForm->SetMenuState(true);
+               }
+       }
+
        __pContentIconListView->UpdateList();
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
@@ -122,7 +139,6 @@ AllListPanel::OnInitializing(void)
        {
                __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
                delete pBitmapEmpty;
-               pBitmapEmpty = null;
        }
        __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
        __pContentIconListView->SetMargin(MARGIN_TYPE_LEFT, W_CONTENT_MARGIN);
@@ -134,10 +150,10 @@ AllListPanel::OnInitializing(void)
        __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
        __pContentIconListView->AddIconListViewItemEventListener(*this);
        __pContentIconListView->SetTouchAnimationEnabled(false);
-       result r = AddControl(*__pContentIconListView);
+       result r = AddControl(__pContentIconListView);
        __pContentIconListView->SetShowState(true);
 
-       __itemCount=0;
+       __itemCount = 0;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return r;
@@ -147,6 +163,13 @@ result
 AllListPanel::OnTerminating(void)
 {
        AppLogDebug("ENTER");
+       SceneManager* pSceneManager = SceneManager::GetInstance();
+       AppAssert(pSceneManager);
+       if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
+       {
+               FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
+               __pPresentationModel->RemoveContentEventListener(pFileListForm);
+       }
        __pPresentationModel->RemovePresentationModelListener(*this);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
@@ -201,12 +224,10 @@ AllListPanel::CreateItem(int index)
        if (pBitmap != null)
        {
                delete pBitmap;
-               pBitmap = null;
        }
        if (pItemText != null)
        {
                delete pItemText;
-               pItemText = null;
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
@@ -227,41 +248,53 @@ void
 AllListPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
 {
        AppLogDebug("ENTER");
+       result r = E_SUCCESS;
        if (status == ICON_LIST_VIEW_ITEM_SELECTED)
        {
-               HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
-               pDataList->Construct();
-               pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
-                               new (std::nothrow) String(APPCONTROL_DATA_IMAGE));
-
                if (__pPresentationModel->GetCurrentAlbumContentInfoCount() <= 0)
                {
                        AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
-
                        return;
                }
 
-               String combineText;
-               String path;
+               ArrayList* pArrayList = new (std::nothrow) ArrayList();
+               pArrayList->Construct();
                int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
-               for (int i = 0 ; i < loopCount; ++i)
-               {
-                       path = __pPresentationModel->GetContentFilePath(i);
 
-                       if (combineText.CompareTo(EMPTY_SPACE) != 0)
-                       {
-                               combineText.Append(L";");
-                       }
-                       combineText.Append(path);
+               for (int i = 0; i < loopCount; ++i)
+               {
+                       pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(i)));
                }
 
                String listIndex;
                listIndex.Format(10, L"%d", index);
-               pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), new (std::nothrow) String(combineText));
+               const String mimeType = APPCONTROL_MIME_IMAGE_ALL;
+
+               HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
+               pDataList->Construct();
+               pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_IMAGE));
+               pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), pArrayList);
                pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_INDEX), new (std::nothrow) String(listIndex));
 
-               __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE,
-                               APPCONTROL_OPERATION_ID_VIEW, pDataList, null);
+               r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
+                               &mimeType, pDataList, null);
+
+               if (r == E_MAX_EXCEEDED)
+               {
+                       MessageBox messageBox;
+                       messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
+                                       MSGBOX_STYLE_NONE, 3000);
+                       int modalResult;
+                       messageBox.ShowAndWait(modalResult);
+               }
+
+               String* pTemp = null;
+               loopCount = pArrayList->GetCount();
+               for (int i = 0; i < loopCount; ++i)
+               {
+                       pTemp = static_cast<String*>(pArrayList->GetAt(i));
+                       AppLog("print temp(%ls)", pTemp->GetPointer());
+               }
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
@@ -270,8 +303,7 @@ void
 AllListPanel::OnFileInfoChanged(const ContentType contentType)
 {
        AppLogDebug("ENTER");
-       if (contentType == CONTENT_TYPE_ALL
-               || contentType == CONTENT_TYPE_IMAGE
+       if (contentType == CONTENT_TYPE_ALL || contentType == CONTENT_TYPE_IMAGE
                || contentType == CONTENT_TYPE_VIDEO)
        {
                __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
@@ -292,15 +324,30 @@ AllListPanel::OnThumbnailDecoded(const int index)
 }
 
 void
+AllListPanel::ChangeOrientation(void)
+{
+       AppLogDebug("ENTER");
+       SceneManager* pSceneManager = SceneManager::GetInstance();
+       const Form* pForm = dynamic_cast<Form*>(pSceneManager->GetCurrentScene()->GetForm());
+       TryReturn(pForm != null,, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
+
+       Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
+       SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
+       __pContentIconListView->SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
+}
+
+void
 AllListPanel::OnSceneActivatedN(const SceneId& previousSceneId,
                                                                const SceneId& currentSceneId, IList* pArgs)
 {
        AppLogDebug("ENTER");
+       ChangeOrientation();
+
        __pPresentationModel = FileListPresentationModel::GetInstance();
 
        if (currentSceneId == IDSCN_ALL_LIST)
        {
-               if (previousSceneId == IDSCN_ALBUM_LIST)
+               if (previousSceneId == IDSCN_ALBUM_LIST && pArgs != null)
                {
                        AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pArgs->GetAt(0));
                        if (pAlbumInfo == null)
@@ -328,7 +375,6 @@ AllListPanel::OnSceneActivatedN(const SceneId& previousSceneId,
                        __pContentIconListView->UpdateList();
                }
        }
-
        SceneManager* pSceneManager = SceneManager::GetInstance();
        AppAssert(pSceneManager);
        if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
@@ -337,7 +383,18 @@ AllListPanel::OnSceneActivatedN(const SceneId& previousSceneId,
                if (pFileListForm != null)
                {
                        pFileListForm->SetTitleText(__pPresentationModel->GetCurrentAlbumName());
+
+                       if (__itemCount == 0)
+                       {
+                               pFileListForm->SetMenuState(false);
+                       }
+                       else
+                       {
+                               pFileListForm->SetMenuState(true);
+                       }
+
                }
+               __pPresentationModel->AddContentEventListener(pFileListForm);
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
@@ -347,13 +404,12 @@ AllListPanel::OnSceneDeactivated(const SceneId& currentSceneId,
                                                                const SceneId& nextSceneId)
 {
        AppLogDebug("ENTER");
-       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
-}
-
-void
-AllListPanel::OnUpdateContentList()
-{
-       AppLogDebug("ENTER");
-       Refresh();
+       SceneManager* pSceneManager = SceneManager::GetInstance();
+       AppAssert(pSceneManager);
+       if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST)
+       {
+               FileListForm* pFileListForm = dynamic_cast<FileListForm*>(pSceneManager->GetCurrentScene()->GetForm());
+               __pPresentationModel->RemoveContentEventListener(pFileListForm);
+       }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }