Fixed prevent issue
[apps/osp/Gallery.git] / src / GlAllListEditorPanel.cpp
index f4d3afa..d019e21 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
 //
@@ -20,7 +20,6 @@
  */
 
 #include <FContent.h>
-#include <FMedia.h>
 #include "GlAllListEditorPanel.h"
 #include "GlCommonUtil.h"
 #include "GlFileUpdateTimer.h"
@@ -39,9 +38,9 @@ using namespace Tizen::Media;
 using namespace Tizen::Ui::Controls;
 using namespace Tizen::Ui::Scenes;
 
-static const int H_COUNT_LABEL = 48;
-static const int H_COUNT_LABEL_BUTTON = 42;
-static const int W_COUNT_LABEL_BUTTON = 42;
+static const float H_COUNT_LABEL = 48.0f;
+static const float H_COUNT_LABEL_BUTTON = 42.0f;
+static const float W_COUNT_LABEL_BUTTON = 42.0f;
 static const int COUNT_LABEL_FONT_SIZE = 33;
 static const int H_CONTENT_MARGIN = 9;
 static const int W_CONTENT_MARGIN = 6;
@@ -57,13 +56,13 @@ static const int ALPHA_THUMBNAIL_DIM = 70;
 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
 
 AllListEditorPanel::AllListEditorPanel(void)
-       : __pContentIconListView(null)
+       : __itemCount(0)
+       , __pContentIconListView(null)
        , __pLabelSelectCnt(null)
        , __pButtonSelectRegion(null)
-       , __itemCount(0)
        , __pFileUpdateTimer(null)
        , __pFileListEditorForm(null)
-, __pPresentationModel(null)
+       , __pPresentationModel(null)
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -97,8 +96,9 @@ AllListEditorPanel::OnInitializing(void)
        __pPresentationModel->ClearThumbnailRequests();
        __pPresentationModel->AddPresentationModelListener(this);
 
-       Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
-       SetBounds(0, 0, clientAreaBounds.width, clientAreaBounds.height);
+       FloatRectangle clientAreaBounds = pForm->GetClientAreaBoundsF();
+       SetBounds(0.0f, 0.0f, clientAreaBounds.width, clientAreaBounds.height);
+
 
        __pContentIconListView = new (std::nothrow) IconListView();
        __pContentIconListView->Construct(Rectangle(0, 0, clientAreaBounds.width, clientAreaBounds.height - H_COUNT_LABEL),
@@ -119,27 +119,27 @@ AllListEditorPanel::OnInitializing(void)
        __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
        __pContentIconListView->AddIconListViewItemEventListener(*this);
        __pContentIconListView->SetTouchAnimationEnabled(false);
-       AddControl(*__pContentIconListView);
+       AddControl(__pContentIconListView);
        __pContentIconListView->SetShowState(true);
 
        __pLabelSelectCnt = new (std::nothrow) Label();
        String strTmp;
        strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED").GetPointer();
        __pLabelSelectCnt->Construct(
-                       Rectangle(0, clientAreaBounds.height-H_COUNT_LABEL, clientAreaBounds.width, H_COUNT_LABEL), strTmp);
+                       FloatRectangle(0, clientAreaBounds.height - H_COUNT_LABEL, clientAreaBounds.width, H_COUNT_LABEL), strTmp);
        __pLabelSelectCnt->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
        __pLabelSelectCnt->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
        __pLabelSelectCnt->SetBackgroundColor(COLOR_COUNT_LABEL);
        __pLabelSelectCnt->SetTextColor(Color(COLOR_SELECT_COUNT_FONT));
        __pLabelSelectCnt->SetTextConfig(COUNT_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
-       AddControl(*__pLabelSelectCnt);
+       AddControl(__pLabelSelectCnt);
        __pLabelSelectCnt->Invalidate(true);
 
        __pButtonSelectRegion = new (std::nothrow) Button();
-       __pButtonSelectRegion->Construct(Rectangle(clientAreaBounds.width - W_COUNT_LABEL_BUTTON - 10,
+       __pButtonSelectRegion->Construct(FloatRectangle(clientAreaBounds.width - W_COUNT_LABEL_BUTTON - 10,
                        clientAreaBounds.height - H_COUNT_LABEL_BUTTON - 4, W_COUNT_LABEL_BUTTON, H_COUNT_LABEL_BUTTON),
                        EMPTY_SPACE);
-       __pButtonSelectRegion->SetActionId(ACTION_ID_BUTTON_MOVE_TO_SELECTION);
+       __pButtonSelectRegion->SetActionId(IDA_BUTTON_MOVE_TO_SELECTION);
        __pButtonSelectRegion->SetColor(BUTTON_STATUS_NORMAL, COLOR_COUNT_LABEL_BUTTON);
        Bitmap* pSelectionBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_MOVE_SELECTION);
        if (pSelectionBitmap != null)
@@ -149,7 +149,7 @@ AllListEditorPanel::OnInitializing(void)
                __pButtonSelectRegion->SetNormalBitmap(Point(buttonRegionRect.width, buttonRegionRect.height),
                                *pSelectionBitmap);
        }
-       AddControl(*__pButtonSelectRegion);
+       AddControl(__pButtonSelectRegion);
 
        if (pSelectionBitmap != null)
        {
@@ -168,6 +168,7 @@ AllListEditorPanel::OnTerminating(void)
 {
        AppLogDebug("ENTER");
        __pPresentationModel->RemovePresentationModelListener(*this);
+       __pPresentationModel->RemoveContentEventListener(__pFileListEditorForm);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return E_SUCCESS;
@@ -182,14 +183,14 @@ AllListEditorPanel::OnActionPerformed(const Control& source, int actionId)
 
        switch (actionId)
        {
-       case ACTION_ID_BUTTON_CHECKED:
+       case IDA_BUTTON_CHECKED:
        {
                int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
-               for (int i=0 ; i < loopCount; ++i)
+               for (int i=0; i < loopCount; ++i)
                {
                        if (__pContentIconListView->IsItemChecked(i) == false)
                        {
-                               __pContentIconListView->SetItemChecked(i,true);
+                               __pContentIconListView->SetItemChecked(i, true);
                                __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
                        }
                }
@@ -213,9 +214,10 @@ AllListEditorPanel::OnActionPerformed(const Control& source, int actionId)
                __pLabelSelectCnt->SetText(strTmp);
                __pLabelSelectCnt->RequestRedraw(true);
                SetButtonState();
-               break;
        }
-       case ACTION_ID_BUTTON_UNCHECKED:
+       break;
+
+       case IDA_BUTTON_UNCHECKED:
        {
                int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
                for (int i = 0; i < loopCount; ++i)
@@ -246,9 +248,10 @@ AllListEditorPanel::OnActionPerformed(const Control& source, int actionId)
                __pLabelSelectCnt->RequestRedraw(true);
                __pContentIconListView->UpdateList();
                SetButtonState();
-               break;
        }
-       case ACTION_ID_BUTTON_MOVE_TO_SELECTION:
+       break;
+
+       case IDA_BUTTON_MOVE_TO_SELECTION:
        {
                if (pSceneManager->GetCurrentSceneId() == IDSCN_ALL_LIST_EDITOR)
                {
@@ -263,13 +266,12 @@ AllListEditorPanel::OnActionPerformed(const Control& source, int actionId)
                {
                        pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_SELECTION));
                }
-               break;
        }
+       break;
+
        default:
-       {
                break;
        }
-       }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -424,6 +426,9 @@ AllListEditorPanel::OnSceneActivatedN(const SceneId& previousSceneId,
                                                                const SceneId& currentSceneId, IList* pArgs)
 {
        AppLogDebug("ENTER");
+
+       ChangeOrientation();
+
        __pPresentationModel = FileListPresentationModel::GetInstance();
 
        SceneManager* pSceneManager = SceneManager::GetInstance();
@@ -432,7 +437,57 @@ AllListEditorPanel::OnSceneActivatedN(const SceneId& previousSceneId,
        TryReturnVoid(__pFileListEditorForm != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
        __pPresentationModel->AddContentEventListener(__pFileListEditorForm);
 
-       if (previousSceneId == IDSCN_ALL_LIST)
+       if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
+       {
+               if (pArgs != null)
+               {
+                       if (__pContentIconListView != null)
+                       {
+                               int loopCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
+                               for (int i = 0; i < loopCount; ++i)
+                               {
+                                       __pContentIconListView->SetItemChecked(i, false);
+                               }
+                               __pContentIconListView->UpdateList();
+                       }
+
+                       if (pArgs->GetCount() > 0) //SomeItems are Still Selected.
+                       {
+                               IList* pSeletedIndexList = pArgs;
+                               int loopCount = pSeletedIndexList->GetCount();
+                               if (__pContentIconListView != null)
+                               {
+                                       for (int i = 0; i < loopCount; ++i)
+                                       {
+                                               int index = static_cast<Integer*>(pSeletedIndexList->GetAt(i))->ToInt();
+                                               __pContentIconListView->SetItemChecked(index, true);
+                                       }
+                                       __pContentIconListView->UpdateList();
+                               }
+                       }
+               }
+
+               int checkedCount = GetItemCheckedCount();
+               String strTmp;
+
+               if (checkedCount == 0)
+               {
+                       strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
+               }
+               else if (checkedCount == 1)
+               {
+                       strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
+               }
+               else
+               {
+                       strTmp.Format(LENGTH_COUNT_LABEL,
+                                       ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
+               }
+
+               __pLabelSelectCnt->SetText(strTmp);
+               __pLabelSelectCnt->RequestRedraw(true);
+       }
+       else if (previousSceneId == IDSCN_ALL_LIST)
        {
                ResetSelection();
        }
@@ -475,6 +530,10 @@ AllListEditorPanel::GetItemCheckedCount(void) const
                        {
                                ++count;
                        }
+                       else
+                       {
+                               AppLog("Index i = %d is Not Checked", i);
+                       }
                }
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -521,7 +580,7 @@ AllListEditorPanel::OnRequestDelete(void)
        }
 
        delete __pFileUpdateTimer;
-       __pFileUpdateTimer = new FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_DELETE_ACTION);
+       __pFileUpdateTimer = new (std::nothrow) FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ACTION_DELETE);
        result r = __pFileUpdateTimer->StartTimer();
 
        if (IsFailed(r))
@@ -556,19 +615,37 @@ void AllListEditorPanel::OnFileOpComplete(enum FileActionMode actionId, enum Fil
        SceneManager* pSceneManager = SceneManager::GetInstance();
        if (GetItemCount() > 0)
        {
-               pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
+               pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST,SCENE_TRANSITION_ANIMATION_TYPE_NONE,
+                                                                  SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_DESTROY));
        }
        else
        {
-               pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
+               pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST,SCENE_TRANSITION_ANIMATION_TYPE_NONE,
+                                                                  SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_DESTROY));
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
+void
+AllListEditorPanel::ChangeOrientation(void)
+{
+       SceneManager* pSceneManager = SceneManager::GetInstance();
+       const Form* pForm = dynamic_cast<Form*>(pSceneManager->GetCurrentScene()->GetForm());
+       TryReturn(pForm != null,, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
+
+       FloatRectangle clientAreaBounds = pForm->GetClientAreaBoundsF();
+       SetBounds(0.0f, 0.0f, clientAreaBounds.width, clientAreaBounds.height);
+       __pContentIconListView->SetBounds(0.0f, 0.0f, clientAreaBounds.width, clientAreaBounds.height - H_COUNT_LABEL);
+       __pLabelSelectCnt->SetBounds(0.0f, clientAreaBounds.height - H_COUNT_LABEL, clientAreaBounds.width, H_COUNT_LABEL);
+       __pButtonSelectRegion->SetBounds(clientAreaBounds.width - W_COUNT_LABEL_BUTTON - 10.0f,
+                       clientAreaBounds.height - H_COUNT_LABEL_BUTTON - 4.0f, W_COUNT_LABEL_BUTTON, H_COUNT_LABEL_BUTTON);
+}
+
 result
 AllListEditorPanel::OnRequestMessage(void)
 {
        AppLogDebug("ENTER");
+       result r = E_SUCCESS;
        IList* pIndexList = GetItemCheckedIndexListN();
        if (pIndexList == null || pIndexList->GetCount() <= 0)
        {
@@ -598,17 +675,28 @@ AllListEditorPanel::OnRequestMessage(void)
        pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
        pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
 
-       __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE, null,
+       r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE, null,
                        null, 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);
+       }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
-       return E_SUCCESS;
+       return r;
 }
 
 result
 AllListEditorPanel::OnRequestEmail(void)
 {
        AppLogDebug("ENTER");
+       result r = E_SUCCESS;
+
        IList* pIndexList = GetItemCheckedIndexListN();
        if (pIndexList == null || pIndexList->GetCount() <= 0)
        {
@@ -633,21 +721,33 @@ AllListEditorPanel::OnRequestEmail(void)
                }
        }
 
+       const String uriData = APPCONTROL_URI_MAIL_TO;
        HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
        pDataList->Construct();
        pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
 
-       __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
-                       new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, null);
+       r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
+                       &uriData, null, 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);
+       }
+
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
-       return E_SUCCESS;
+       return r;
 }
 
 result
 AllListEditorPanel::OnRequestSlideShow(void)
 {
        AppLogDebug("ENTER");
+       result r = E_SUCCESS;
        IList* pIndexList = GetItemCheckedIndexListN();
        if (pIndexList == null)
        {
@@ -675,14 +775,24 @@ AllListEditorPanel::OnRequestSlideShow(void)
        pDataList->Construct();
        pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
        pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
+       const String mimeType = APPCONTROL_MIME_IMAGE_ALL;
 
-       __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
-                       new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), 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);
+       }
 
        delete pIndexList;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
-       return E_SUCCESS;
+       return r;
 }
 
 void
@@ -693,23 +803,15 @@ AllListEditorPanel::ResetSelection(void)
        __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
        __pContentIconListView->UpdateList();
 
-       int checkedCount = GetItemCheckedCount();
-       String strTmp;
-
-       if (checkedCount == 0)
+       for (int index = 0; index < __itemCount; ++index)
        {
-               strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
-       }
-       else if (checkedCount == 1)
-       {
-               strTmp = ResourceManager::GetString(L"IDS_VR_POP_1_ITEM_SELECTED");
-       }
-       else
-       {
-               strTmp.Format(LENGTH_COUNT_LABEL,
-                               ResourceManager::GetString(L"IDS_VR_POP_PD_ITEMS_SELECTED").GetPointer(), checkedCount);
+               __pContentIconListView->SetItemChecked(index, false);
+               __pContentIconListView->RefreshList(index,LIST_REFRESH_TYPE_ITEM_MODIFY);
        }
 
+       String strTmp;
+       strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
+
        __pLabelSelectCnt->SetText(strTmp);
        __pLabelSelectCnt->RequestRedraw(true);
        SetButtonState();
@@ -739,7 +841,7 @@ AllListEditorPanel::SetButtonState(void)
 }
 
 void
-AllListEditorPanel::SelectAllPressed(void)
+AllListEditorPanel::OnSelectAllPressed(void)
 {
        bool needToSelectAll = true;
        int checkedCount = GetItemCheckedCount();
@@ -751,7 +853,7 @@ AllListEditorPanel::SelectAllPressed(void)
 
        if (needToSelectAll == true)
        {
-               for (int i = 0 ; i < totalFileCount; ++i)
+               for (int i = 0; i < totalFileCount; ++i)
                {
                        if (__pContentIconListView->IsItemChecked(i) == false)
                        {
@@ -762,7 +864,7 @@ AllListEditorPanel::SelectAllPressed(void)
        }
        else
        {
-               for (int i = 0 ; i < totalFileCount; ++i)
+               for (int i = 0; i < totalFileCount; ++i)
                {
                        if (__pContentIconListView->IsItemChecked(i) == true)
                        {
@@ -807,7 +909,7 @@ AllListEditorPanel::OnRequestRotate(RotateMode rotateMode)
        }
 
        delete __pFileUpdateTimer;
-       __pFileUpdateTimer = new FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ROTATE_ACTION, rotateMode);
+       __pFileUpdateTimer = new (std::nothrow) FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ACTION_ROTATE, rotateMode);
        result r = __pFileUpdateTimer->StartTimer();
 
        if (IsFailed(r))
@@ -823,3 +925,27 @@ AllListEditorPanel::OnRequestRotate(RotateMode rotateMode)
        return E_SUCCESS;
 }
 
+void AllListEditorPanel::CancelUpdateProgress(void)
+{
+       if (__pFileUpdateTimer!= null && __pFileUpdateTimer->IsStarted())
+       {
+               __pFileUpdateTimer->Cancel();
+               delete __pFileUpdateTimer;
+               __pFileUpdateTimer = null;
+       }
+}
+
+void
+AllListEditorPanel::OnScanDirStart()
+{
+       AppLogDebug("ENTER");
+       __pFileListEditorForm->SetProgressState(true);
+       AppLogDebug("EXIT");
+}
+void
+AllListEditorPanel::OnScanDirComplete()
+{
+       AppLogDebug("ENTER");
+       __pFileListEditorForm->SetProgressState(false);
+       AppLogDebug("EXIT");
+}