HW key changes
[apps/osp/Gallery.git] / src / GlAlbumListForm.cpp
index 8412e3c..e04444d 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,7 +19,6 @@
  * @brief              This is the implementation file for AlbumListForm class.
  */
 
-#include <FApp.h>
 #include "GlAlbumInfo.h"
 #include "GlAlbumListForm.h"
 #include "GlAlbumListPresentationModel.h"
@@ -43,13 +42,15 @@ static const int W_FOLDER_SIZE = 348;
 static const int H_FOLDER_SIZE = 348;
 
 AlbumListForm::AlbumListForm(void)
-       : __pAlbumViewIconList(null)
-       , __pContextMenuMore(null)
+       : __isHWBackButtonExist(false)
        , __itemCount(0)
+       , __pAlbumViewIconList(null)
+       , __pContextMenuMore(null)
+       , __pOptionMenu(null)
        , __pPresentationModel(null)
+
 {
        AppLogDebug("ENTER");
-       __overlayMsg = false;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -74,12 +75,18 @@ AlbumListForm::OnInitializing(void)
 {
        AppLogDebug("ENTER");
        result r = E_SUCCESS;
+       GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
+
+        __isHWBackButtonExist = false;
+        __isHWBackButtonExist = pApp->IsHwKeySupported();
+       AppLogDebug("EXIT(%s)", GetErrorMessage(r));
+
 
        __pPresentationModel = AlbumListPresentationModel::GetInstance();
        __pPresentationModel->ClearThumbnailRequests();
        __pPresentationModel->AddPresentationModelListener(this);
 
-       if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
+       if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
        {
                if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
                {
@@ -128,7 +135,6 @@ AlbumListForm::InitializeHeader(void)
        if (pHeader == null)
        {
                AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
-
                return E_SYSTEM;
        }
 
@@ -136,7 +142,6 @@ AlbumListForm::InitializeHeader(void)
        if (r != E_SUCCESS)
        {
                AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
-
                return r;
        }
 
@@ -155,11 +160,10 @@ AlbumListForm::InitializeFooter(void)
        if (pFooter == null)
        {
                AppLogDebug("EXIT 1");
-
                return E_SYSTEM;
        }
 
-       if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
+       if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
        {
                pFooter->SetBackButton();
                SetFormBackEventListener(this);
@@ -171,7 +175,7 @@ AlbumListForm::InitializeFooter(void)
                pFooter->RemoveAllItems();
 
                FooterItem itemCamera;
-               itemCamera.Construct(ACTION_ID_FOOTER_CAMERA);
+               itemCamera.Construct(IDA_FOOTER_CAMERA);
                itemCamera.SetText(ResourceManager::GetString(L"EMPTY_SPACE"));
                Bitmap* pBitmap1 = ResourceManager::GetBitmapN(IDB_CONTROLBAR_CAMERA);
                if (pBitmap1 != null)
@@ -181,21 +185,44 @@ AlbumListForm::InitializeFooter(void)
                pFooter->AddItem(itemCamera);
                delete pBitmap1;
 
-               ButtonItem footerMore;
-               footerMore.Construct(BUTTON_ITEM_STYLE_ICON, ACTION_ID_FOOTER_MORE);
-               Bitmap* pBitmapMore = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE);
-               if (pBitmapMore != null)
+
+               if( __isHWBackButtonExist == false )
                {
-                       footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
-               }
-               pFooter->SetButton(BUTTON_POSITION_LEFT,footerMore);
-               delete pBitmapMore;
+                       ButtonItem footerMore;
+                       footerMore.Construct(BUTTON_ITEM_STYLE_ICON, IDA_FOOTER_MORE);
 
-               __pContextMenuMore = new (std::nothrow) ContextMenu();
-               __pContextMenuMore->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
-               __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), ACTION_ID_FOOTER_EDIT);
-               __pContextMenuMore->SetShowState(false);
-               __pContextMenuMore->AddActionEventListener(*this);
+                       Bitmap* pBitmapMore = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE);
+                       Bitmap* pBitmapMoreDim = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE_DISABLED);
+                       Bitmap* pBitmapMorePressed = ResourceManager::GetBitmapN(IDB_CONTROLBAR_MORE_PRESSED);
+
+                       if (pBitmapMore != null && pBitmapMoreDim != null && pBitmapMorePressed != null)
+                       {
+                               footerMore.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapMore);
+                               footerMore.SetIcon(BUTTON_ITEM_STATUS_DISABLED, pBitmapMoreDim);
+                               footerMore.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pBitmapMorePressed);
+                       }
+
+                       pFooter->SetButton(BUTTON_POSITION_LEFT, footerMore);
+                       delete pBitmapMore;
+                       delete pBitmapMoreDim;
+                       delete pBitmapMorePressed;
+
+                       __pContextMenuMore = new (std::nothrow) ContextMenu();
+                       __pContextMenuMore->Construct(Point(0, 0), CONTEXT_MENU_STYLE_LIST);
+                       __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
+                       __pContextMenuMore->SetShowState(false);
+                       __pContextMenuMore->AddActionEventListener(*this);
+               }
+               else
+               {
+                           __pOptionMenu = new (std::nothrow) OptionMenu();
+                           __pOptionMenu->Construct();
+                           __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"),IDA_FOOTER_EDIT);
+                           __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_HEADER_EDIT"), IDA_FOOTER_EDIT);
+                           __pOptionMenu->SetShowState(false);
+                           __pOptionMenu->AddActionEventListener(*this);
+                           SetFormMenuEventListener(this);
+               }
 
                SetFormBackEventListener(this);
        }
@@ -211,7 +238,7 @@ AlbumListForm::CreateIconListView(void)
        AppLogDebug("ENTER");
        Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
 
-       __pAlbumViewIconList = static_cast< IconListView* >(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
+       __pAlbumViewIconList = static_cast<IconListView*>(GetControl(L"IDC_ICONLISTVIEW_ALBUM_LIST"));
        AppAssert(__pAlbumViewIconList);
 
        __pAlbumViewIconList->SetItemProvider(*this);
@@ -292,13 +319,13 @@ AlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, Ico
                pArrayList->Construct();
                pArrayList->Add(pSendAlbumInfo);
 
-               if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
+               if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
                {
                        if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
                        {
                                pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_LIST_EDITOR), pArrayList);
                        }
-                       else if  (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
+                       else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
                        {
                                pSceneManager->GoForward(ForwardSceneTransition(IDSCN_VIDEO_LIST_EDITOR), pArrayList);
                        }
@@ -330,7 +357,7 @@ AlbumListForm::OnTerminating(void)
 {
        AppLogDebug("ENTER");
        __pPresentationModel->RemovePresentationModelListener(*this);
-
+       __pPresentationModel->RemoveContentEventListener(*this);
        if (__pContextMenuMore != null)
        {
                delete __pContextMenuMore;
@@ -349,41 +376,41 @@ AlbumListForm::OnActionPerformed(const Control& source, int actionId)
 
        switch (actionId)
        {
-       case ACTION_ID_FOOTER_CAMERA:
+       case IDA_FOOTER_CAMERA:
+       {
+               HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
+               pDataList->Construct();
+               pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
+                               new (std::nothrow) String(APPCONTROL_DATA_TRUE));
+               __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
+                               APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
+                               new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
+       }
+       break;
+
+       case IDA_FOOTER_EDIT:
+       {
+               pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
+       }
+       break;
+
+       case IDA_FOOTER_MORE:
+       {
+               if (__pContextMenuMore->GetShowState() == false && __pPresentationModel->GetFolderCount() != 0)
                {
-                       HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
-                       pDataList->Construct();
-                       pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_CAMERA_ALLOW_SWITCH),
-                                       new (std::nothrow) String(APPCONTROL_DATA_TRUE));
-
-                       __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CAMERA,
-                                       APPCONTROL_OPERATION_ID_CREATE_CONTENT, null,
-                                       new (std::nothrow) String(APPCONTROL_MIME_IMAGE_JPG), pDataList, null);
+                       Rectangle rect = source.GetBounds();
+                       __pContextMenuMore->SetAnchorPosition(Point(rect.width/10, rect.y));
+                       __pContextMenuMore->SetShowState(true);
+                       __pContextMenuMore->Show();
                }
-               break;
-       case ACTION_ID_FOOTER_EDIT:
+               else
                {
-                       pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
+                       __pContextMenuMore->SetShowState(false);
                }
-               break;
-       case ACTION_ID_FOOTER_MORE:
-               {
-                       if (__pContextMenuMore->GetShowState() == false && __pPresentationModel->GetFolderCount() != 0)
-                       {
-                               Rectangle rect = source.GetBounds();
-                               __pContextMenuMore->SetAnchorPosition(Point(rect.width/8, rect.y));
-                               __pContextMenuMore->SetShowState(true);
-                               __pContextMenuMore->Show();
-                       }
-                       else
-                       {
-                               __pContextMenuMore->SetShowState(false);
-                       }
-               }
-               break;
+       }
+       break;
+
        default:
-               {
-               }
                break;
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -393,13 +420,13 @@ void
 AlbumListForm::OnFormBackRequested(Form& source)
 {
        AppLogDebug("ENTER");
-       if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
+       if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
        {
                AppLogDebug("APP_CONTROL_MODE_PICK");
                GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
                if (pApp != null)
                {
-                       if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
+                       if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
                        {
                                pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
                        }
@@ -416,16 +443,16 @@ AlbumListForm::OnFormBackRequested(Form& source)
 }
 
 void
-AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId,
-                                                                                 const SceneId& currentSceneId, IList* pArgs)
+AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
 {
        AppLogDebug("ENTER");
        __pPresentationModel->AddContentEventListener(this);
 
-       if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
+       if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
        {
                if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
                {
+                       __pPresentationModel->ClearThumbnailRequests(false);
                        __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
                }
                else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
@@ -443,6 +470,15 @@ AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId,
        }
        __itemCount = __pPresentationModel->GetFolderCount();
 
+       if ( __itemCount == 0 )
+       {
+               GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
+       }
+       else
+       {
+               GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
+       }
+
        if (__pAlbumViewIconList != null)
        {
                __pAlbumViewIconList->UpdateList();
@@ -453,8 +489,7 @@ AlbumListForm::OnSceneActivatedN(const SceneId& previousSceneId,
 }
 
 void
-AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId,
-                                                                                  const SceneId& nextSceneId)
+AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
 {
        AppLogDebug("ENTER");
        __pPresentationModel->RemoveContentEventListener(*this);
@@ -462,14 +497,26 @@ AlbumListForm::OnSceneDeactivated(const SceneId& currentSceneId,
 }
 
 void
-AlbumListForm::OnContentUpdated()
+AlbumListForm::OnContentUpdated(void)
 {
        AppLogDebug("ENTER");
 
-       if (__pPresentationModel->GetAppControlMode() == APP_CONTROL_MODE_PICK)
+       if(__pContextMenuMore != null && __pContextMenuMore ->GetShowState() == true)
+       {
+               __pContextMenuMore->SetShowState(false);
+       }
+
+       if ( __pOptionMenu != null && __pOptionMenu ->GetShowState() == true)
+       {
+               __pOptionMenu->SetShowState(false);
+               __pOptionMenu->Show();
+       }
+
+       if (__pPresentationModel->GetAppControlMode() == APPCONTROL_MODE_PICK)
        {
                if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_IMAGE)
                {
+                       __pPresentationModel->ClearThumbnailRequests(false);
                        __pPresentationModel->InitializeAlbumInfoList(CONTENT_TYPE_IMAGE);
                }
                else if (__pPresentationModel->GetAppControlMediaType() == APPCONTROL_MEDIA_TYPE_VIDEO)
@@ -488,6 +535,17 @@ AlbumListForm::OnContentUpdated()
 
        __itemCount = __pPresentationModel->GetFolderCount();
        __pAlbumViewIconList->UpdateList();
+
+       if (__itemCount == 0 )
+       {
+               GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
+       }
+       else
+       {
+               GetFooter()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
+       }
+
+       GetFooter()->Invalidate(true);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -516,3 +574,17 @@ AlbumListForm::Update(void)
 
        return r;
 }
+
+void
+AlbumListForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
+{
+
+       if ( __pOptionMenu == null )
+       {
+               return ;
+       }
+
+       __pOptionMenu->SetShowState(true);
+       __pOptionMenu->Show();
+
+}