Fixed issue 42036
[apps/osp/Gallery.git] / src / GlAllListEditorPanel.cpp
index a9ede81..5314ae9 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
 //
  */
 
 #include <FContent.h>
-#include <FMedia.h>
 #include "GlAllListEditorPanel.h"
 #include "GlCommonUtil.h"
+#include "GlFileUpdateTimer.h"
 #include "GlFileListEditorForm.h"
 #include "GlFileListPresentationModel.h"
 #include "GlResourceManager.h"
 #include "GlTypes.h"
-#include "GlFileDeleteTimer.h"
 
 using namespace Tizen::App;
 using namespace Tizen::Base;
@@ -42,6 +41,7 @@ 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 int COUNT_LABEL_FONT_SIZE = 33;
 static const int H_CONTENT_MARGIN = 9;
 static const int W_CONTENT_MARGIN = 6;
 static const int W_CONTENT_SPACE = 6;
@@ -56,14 +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)
-//     , __deleteInProgress(false)
-       , __pPresentationModel(null)
-       , __pFileDelete(null)
+       , __pFileUpdateTimer(null)
        , __pFileListEditorForm(null)
+       , __pPresentationModel(null)
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -72,7 +71,7 @@ AllListEditorPanel::AllListEditorPanel(void)
 AllListEditorPanel::~AllListEditorPanel(void)
 {
        AppLogDebug("ENTER");
-       delete __pFileDelete;
+       delete __pFileUpdateTimer;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -119,26 +118,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);
+                       Rectangle(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));
-       AddControl(*__pLabelSelectCnt);
+       __pLabelSelectCnt->SetTextConfig(COUNT_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
+       AddControl(__pLabelSelectCnt);
        __pLabelSelectCnt->Invalidate(true);
 
        __pButtonSelectRegion = new (std::nothrow) Button();
        __pButtonSelectRegion->Construct(Rectangle(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)
@@ -148,7 +148,7 @@ AllListEditorPanel::OnInitializing(void)
                __pButtonSelectRegion->SetNormalBitmap(Point(buttonRegionRect.width, buttonRegionRect.height),
                                *pSelectionBitmap);
        }
-       AddControl(*__pButtonSelectRegion);
+       AddControl(__pButtonSelectRegion);
 
        if (pSelectionBitmap != null)
        {
@@ -167,26 +167,12 @@ AllListEditorPanel::OnTerminating(void)
 {
        AppLogDebug("ENTER");
        __pPresentationModel->RemovePresentationModelListener(*this);
+       __pPresentationModel->RemoveContentEventListener(__pFileListEditorForm);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return E_SUCCESS;
 }
 
-/*
-void
-AllListEditorPanel::UpdatePanelContent()
-{
-       AppLogDebug("ENTER");
-
-       if (__pFileListEditorForm->GetOverlayStatus() == false && __deleteInProgress == false)
-       {
-               SceneManager* pSceneManager = SceneManager::GetInstance();
-               pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
-               AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
-       }
-}
-*/
-
 void
 AllListEditorPanel::OnActionPerformed(const Control& source, int actionId)
 {
@@ -196,14 +182,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);
                        }
                }
@@ -227,9 +213,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)
@@ -260,9 +247,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)
                {
@@ -277,13 +265,12 @@ AllListEditorPanel::OnActionPerformed(const Control& source, int actionId)
                {
                        pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST_SELECTION));
                }
-               break;
        }
+       break;
+
        default:
-       {
                break;
        }
-       }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -343,6 +330,7 @@ AllListEditorPanel::CreateItem(int index)
                else
                {
                        AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+                       delete pItemText;
                        return null;
                }
        }
@@ -445,7 +433,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();
        }
@@ -488,6 +526,10 @@ AllListEditorPanel::GetItemCheckedCount(void) const
                        {
                                ++count;
                        }
+                       else
+                       {
+                               AppLog("Index i = %d is Not Checked", i);
+                       }
                }
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -533,14 +575,14 @@ AllListEditorPanel::OnRequestDelete(void)
                return E_FAILURE;
        }
 
-       delete __pFileDelete;
-       __pFileDelete = new FileDeleteTimer(pIndexList, __pPresentationModel, this);
-       result r = __pFileDelete->StartTimer();
+       delete __pFileUpdateTimer;
+       __pFileUpdateTimer = new (std::nothrow) FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ACTION_DELETE);
+       result r = __pFileUpdateTimer->StartTimer();
 
        if (IsFailed(r))
        {
-               delete __pFileDelete;
-               __pFileDelete = null;
+               delete __pFileUpdateTimer;
+               __pFileUpdateTimer = null;
                return E_FAILURE;
        }
        else
@@ -569,11 +611,13 @@ 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()));
 }
@@ -582,6 +626,7 @@ result
 AllListEditorPanel::OnRequestMessage(void)
 {
        AppLogDebug("ENTER");
+       result r = E_SUCCESS;
        IList* pIndexList = GetItemCheckedIndexListN();
        if (pIndexList == null || pIndexList->GetCount() <= 0)
        {
@@ -611,17 +656,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)
        {
@@ -650,17 +706,28 @@ AllListEditorPanel::OnRequestEmail(void)
        pDataList->Construct();
        pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
 
-       __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
+       r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
                        new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), 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)
        {
@@ -689,13 +756,22 @@ AllListEditorPanel::OnRequestSlideShow(void)
        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);
 
-       __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
+       r = __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
                        new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), 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
@@ -706,23 +782,15 @@ AllListEditorPanel::ResetSelection(void)
        __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
        __pContentIconListView->UpdateList();
 
-       int checkedCount = GetItemCheckedCount();
-       String strTmp;
-
-       if (checkedCount == 0)
-       {
-               strTmp = ResourceManager::GetString(L"IDS_ST_POP_NO_ITEMS_SELECTED");
-       }
-       else if (checkedCount == 1)
+       for ( int index = 0; index < __itemCount; index++)
        {
-               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();
@@ -752,7 +820,7 @@ AllListEditorPanel::SetButtonState(void)
 }
 
 void
-AllListEditorPanel::SelectAllPressed(void)
+AllListEditorPanel::OnSelectAllPressed(void)
 {
        bool needToSelectAll = true;
        int checkedCount = GetItemCheckedCount();
@@ -764,7 +832,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)
                        {
@@ -775,7 +843,7 @@ AllListEditorPanel::SelectAllPressed(void)
        }
        else
        {
-               for (int i = 0 ; i < totalFileCount; ++i)
+               for (int i = 0; i < totalFileCount; ++i)
                {
                        if (__pContentIconListView->IsItemChecked(i) == true)
                        {
@@ -800,3 +868,48 @@ AllListEditorPanel::SelectAllPressed(void)
        __pLabelSelectCnt->RequestRedraw(true);
        SetButtonState();
 }
+
+result
+AllListEditorPanel::OnRequestRotate(RotateMode rotateMode)
+{
+       AppLogDebug("ENTER");
+       IList* pIndexList = GetItemCheckedIndexListN();
+       if (pIndexList == null)
+       {
+               AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+               return E_FAILURE;
+       }
+       else if (pIndexList->GetCount() <= 0)
+       {
+               delete pIndexList;
+               AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+               return E_FAILURE;
+       }
+
+       delete __pFileUpdateTimer;
+       __pFileUpdateTimer = new (std::nothrow) FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ACTION_ROTATE, rotateMode);
+       result r = __pFileUpdateTimer->StartTimer();
+
+       if (IsFailed(r))
+       {
+               delete __pFileUpdateTimer;
+               __pFileUpdateTimer = null;
+               return E_FAILURE;
+       }
+       else
+       {
+               __pPresentationModel->SetUpdateProgressStatus(true);
+       }
+       return E_SUCCESS;
+}
+
+void AllListEditorPanel::CancelUpdateProgress(void)
+{
+       if( __pFileUpdateTimer!= null && __pFileUpdateTimer->IsStarted())
+       {
+               __pFileUpdateTimer->Cancel();
+               delete __pFileUpdateTimer;
+               __pFileUpdateTimer = null;
+       }
+}