Fixed prevent issues
[apps/osp/Gallery.git] / src / GlAlbumListPresentationModel.cpp
index 6043788..ebcca82 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
 //
@@ -27,6 +27,7 @@
 #include "GlAlbumListPresentationModel.h"
 #include "GlAlbumRenameEventListener.h"
 #include "GlContentUpdateEventListener.h"
+#include "GlFileListPresentationModel.h"
 #include "GlGalleryApp.h"
 #include "GlThumbnailEvent.h"
 #include "GlThumbnailEventArg.h"
@@ -60,7 +61,7 @@ static const int FONT_SIZE_FOLDER_COUNT_SMALL = 35;
 
 static const int CANVAS_IMAGE_FOLDER_HEIGHT = 48;
 static const int CANVAS_IMAGE_FOLDER_WIDTH = 48;
-static const int IMAGE_COUNT_WIDTH  = 100;
+static const int IMAGE_COUNT_WIDTH = 100;
 static const int IMAGE_COUNT_HEIGHT = 60;
 static const int CANVAS_MARGIN_LEFT = 10;
 static const int GAP = 10;
@@ -94,10 +95,12 @@ IList* AlbumListPresentationModel::__pAlbumInfoList = null;
 
 AlbumListPresentationModel::AlbumListPresentationModel(void)
        : __pFolderBackgroundBitmap(null)
+       , __pContentManager(null)
        , __pAlbumListener(null)
-       , __appControlMode(APP_CONTROL_MODE_MAIN)
+       , __appControlMode(APPCONTROL_MODE_MAIN)
        , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
        , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
+       , __updateProgressStatus(false)
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -106,6 +109,7 @@ AlbumListPresentationModel::AlbumListPresentationModel(void)
 AlbumListPresentationModel::~AlbumListPresentationModel(void)
 {
        AppLogDebug("ENTER");
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -150,11 +154,11 @@ AlbumListPresentationModel::Construct(void)
 
        if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
        {
-               __appControlMode = APP_CONTROL_MODE_MAIN;
+               __appControlMode = APPCONTROL_MODE_MAIN;
        }
        else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
        {
-               __appControlMode = APP_CONTROL_MODE_PICK;
+               __appControlMode = APPCONTROL_MODE_PICK;
 
                String mimeType = pApp->GetMimeType();
                if (mimeType.IsEmpty() != true)
@@ -172,16 +176,11 @@ AlbumListPresentationModel::Construct(void)
                        {
                                __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
                        }
-
-                       if (pApp->GetMimeType().StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
-                       {
-                               __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
-                       }
                }
        }
        else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
        {
-               __appControlMode = APP_CONTROL_MODE_SETTING;
+               __appControlMode = APPCONTROL_MODE_SETTING;
        }
 
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -312,20 +311,24 @@ AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& new
        else
        {
                __pAlbumListener = pAlbumListener;
-               r = ContentManager::ScanDirectory(Tizen::System::Environment::GetMediaPath(), true, this, __reqId);
+               __renameNewPath = newPath;\r
+               r = ContentManager::ScanDirectory(newPath, true, NULL, __reqId);\r
+               AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
+               r = ContentManager::ScanDirectory(orgPath, true, NULL, __reqId);\r
                AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
        }
        AppLogDebug("EXIT");
        return r;
 }
 
-void AlbumListPresentationModel::OnContentScanCompleted (RequestId reqId, const Tizen::Base::String &scanPath, result r)
+void AlbumListPresentationModel::OnContentScanCompleted (const Tizen::Base::String &scanPath)\r
 {
-       AppLogDebug("ENTER");
-       if (__pAlbumListener && __reqId == reqId)
+       AppLogDebug("ENTER");\r
+       if (__pAlbumListener && ( scanPath == __renameNewPath))\r
        {
                InitializeAlbumInfoList(CONTENT_TYPE_ALL);
                __pAlbumListener->OnAlbumRenameComplete();
+               __renameNewPath = L"";
        }
        AppLogDebug("EXIT");
 }
@@ -425,7 +428,7 @@ AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo,
 
        textElementCount.Construct(strCnt);
 
-       if (strCnt.GetLength() > 3)             // if the count in Album is greater than 3 digit number, use small font
+       if (strCnt.GetLength() > 3)
        {
                textElementCount.SetFont(ftCntSmall);
        }
@@ -450,7 +453,7 @@ AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo,
 }
 
 Bitmap*
-AlbumListPresentationModel::CreateMergeBitmapN(int index)
+AlbumListPresentationModel::CreateMergeBitmapN(const int index)
 {
        AppLogDebug("ENTER index(%d)", index);
 
@@ -498,10 +501,12 @@ AlbumListPresentationModel::CreateMergeBitmapN(int index)
 }
 
 result
-AlbumListPresentationModel::StartAppControl(const String&  providerId, const String&  operationId,
-               const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
+AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
+               const String* pUriData, const String* pMimeType, const HashMap* pDataList,
+               IAppControlResponseListener* pListener)
 {
        AppLogDebug("ENTER");
+       FileListPresentationModel::GetInstance()->ClearProviderId();
        AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
        if (pAc == null)
        {
@@ -509,7 +514,7 @@ AlbumListPresentationModel::StartAppControl(const String&  providerId, const Str
 
                return E_FAILURE;
        }
-       result r = pAc->Start(null, pMimeType, pDataList, pListener);
+       result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
 
        if (r == E_SUCCESS)
        {
@@ -525,7 +530,7 @@ AlbumListPresentationModel::StartAppControl(const String&  providerId, const Str
 }
 
 String
-AlbumListPresentationModel::GetDirectoryName(String& directoryPath)
+AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
 {
        AppLogDebug("ENTER");
        String directoryName;
@@ -539,7 +544,7 @@ AlbumListPresentationModel::GetDirectoryName(String& directoryPath)
 }
 
 int
-AlbumListPresentationModel::GetFolderCount(void)
+AlbumListPresentationModel::GetFolderCount(void) const
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -559,13 +564,13 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
 
        if (__pAlbumInfoList != null)
        {
-               AlbumInfo* info = null;
+               AlbumInfo* pInfo = null;
                for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
                {
-                       info = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
-                       if (info->GetAlbumName().IsEmpty() == false)
+                       pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
+                       if (pInfo->GetAlbumName().IsEmpty() == false)
                        {
-                               AppLog("Print AlbumName(%d)(%ls)", i, info->GetAlbumName().GetPointer());
+                               AppLog("Print AlbumName(%d)(%ls)", i, pInfo->GetAlbumName().GetPointer());
                        }
                }
                delete __pAlbumInfoList;
@@ -576,7 +581,7 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
 
        if (contentType == CONTENT_TYPE_ALL)
        {
-               IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
+               IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
                TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
                pListT->Add(CONTENT_TYPE_IMAGE);
                pListT->Add(CONTENT_TYPE_VIDEO);
@@ -635,6 +640,10 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
                while (pEnum->MoveNext() == E_SUCCESS)
                {
                        pDirPath = static_cast<String*>(pEnum->GetCurrent());
+                       String mediaPath = RESERVED_MEDIA_PATH;
+                       int length = mediaPath.GetLength();
+                       mediaPath.Remove(length-1,1);
+
                        if (pDirPath == null)
                        {
                                continue;
@@ -668,7 +677,7 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
                                        delete pContentIdList;
                                }
                        }
-                       else if (*pDirPath == RESERVED_MEDIA_PATH)
+                       else if (*pDirPath == mediaPath)
                        {
                                IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
 
@@ -712,6 +721,7 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
                                {
                                        delete pAlbumInfo;
                                }
+                               pAlbumInfo = null;
                        }
                }
 
@@ -770,26 +780,11 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
        return;
 
 CATCH:
-       if (pContentDirectoryPathList != null)
-       {
-               delete pContentDirectoryPathList;
-       }
-       if (pAllAlbumInfo != null)
-       {
-               delete pAllAlbumInfo;
-       }
-       if (pCameraAlbumInfo != null)
-       {
-               delete pCameraAlbumInfo;
-       }
-       if (pDownloadAlbumInfo != null)
-       {
-               delete pDownloadAlbumInfo;
-       }
-       if (pNoNameAlbumInfo != null)
-       {
-               delete pNoNameAlbumInfo;
-       }
+       delete pContentDirectoryPathList;
+       delete pAllAlbumInfo;
+       delete pCameraAlbumInfo;
+       delete pDownloadAlbumInfo;
+       delete pNoNameAlbumInfo;
 }
 
 String
@@ -829,7 +824,7 @@ AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directory
        const String contentDirectoryPath = directoryPath;
        if (contentType == CONTENT_TYPE_ALL)
        {
-               IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
+               IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
                pListT->Add(CONTENT_TYPE_IMAGE);
                pListT->Add(CONTENT_TYPE_VIDEO);
                result r = directory.Construct(*pListT);
@@ -862,7 +857,7 @@ AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directory
                ContentId* pItem;
                while (pEnum->MoveNext() == E_SUCCESS)
                {
-                       ContentInfo* pContentInfo =  static_cast<ContentInfo*>(pEnum->GetCurrent());
+                       ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
                        pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
                        pContentIdList->Add(pItem);
                }
@@ -875,67 +870,15 @@ AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directory
 }
 
 result
-AlbumListPresentationModel::DeleteContentInfoInDirectory(int index, ContentType contentType)
+AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
 {
        AppLogDebug("ENTER");
        result r = E_SUCCESS;
-       if (__pAlbumInfoList == null)
-       {
-               AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
-
-               return r;
-       }
-
-       AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
-
-       int loopCount = pAlbumInfo->GetDirectoryCount();
-       for (int i = 0; i < loopCount; ++i)
+       ContentManager contentManager;
+       r = contentManager.Construct();
+       if (r == E_SUCCESS)
        {
-               ContentDirectory directory;
-               const String contentDirectoryPath = pAlbumInfo->GetDirectory(i);
-
-               if (contentType == CONTENT_TYPE_ALL)
-               {
-                       IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
-                       pListT->Add(CONTENT_TYPE_IMAGE);
-                       pListT->Add(CONTENT_TYPE_VIDEO);
-                       r = directory.Construct(*pListT);
-                       delete pListT;
-               }
-               else
-               {
-                       r = directory.Construct(contentType);
-               }
-               if (r != E_SUCCESS)
-               {
-                       continue;
-               }
-
-               int pageNo = 1;
-               int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
-               IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo,
-                               countPerPage, CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
-               ContentManager contentManager;
-               r = contentManager.Construct();
-               if (r != E_SUCCESS)
-               {
-                       delete pContentInfoList;
-                       continue;
-               }
-
-               if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
-               {
-                       IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
-                       while (pEnum->MoveNext() == E_SUCCESS || r == E_SUCCESS)
-                       {
-                               ContentInfo* pContentInfo =  static_cast<ContentInfo*>(pEnum->GetCurrent());
-                               ContentId contentId = pContentInfo->GetContentId();
-                               r = contentManager.DeleteContent(contentId);
-                       }
-                       delete pEnum;
-               }
-
-               delete pContentInfoList;
+               r = contentManager.DeleteContent(contentId);
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
@@ -967,7 +910,7 @@ AlbumListPresentationModel::GetAppControlSelectionMode(void) const
 }
 
 IList*
-AlbumListPresentationModel::GetAlbumInfoList(void)
+AlbumListPresentationModel::GetAlbumInfoList(void) const
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -975,6 +918,66 @@ AlbumListPresentationModel::GetAlbumInfoList(void)
        return __pAlbumInfoList;
 }
 
+IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
+{
+       AppLogDebug("ENTER");
+       ContentDirectory directory;
+       IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+
+       IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
+       TryReturn(pListT != null,null, "Unable to Create ArrayListT");
+       pListT->Add(CONTENT_TYPE_IMAGE);
+       pListT->Add(CONTENT_TYPE_VIDEO);
+
+       result r = directory.Construct(*pListT);
+       delete pListT;
+
+       if (r != E_SUCCESS)
+       {
+               AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
+               delete pContentIdList;
+               return null;
+       }
+
+       if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
+       {
+               IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
+               String* pDirPath = null;
+               if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
+               {
+                       int loopCount = pContentDirectoryPathList->GetCount();
+                       for (int i = 0; i < loopCount; ++i)
+                       {
+                               pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
+                               pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
+                       }
+               }
+       }
+       else
+       {
+               if(__pAlbumInfoList != null)
+               {
+                       int loopCount = indexList.GetCount();
+                       AlbumInfo* pInfo = null;
+                       for (int i = 0; i < loopCount; ++i)
+                       {
+                               int index  = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
+                               pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
+
+                               if(pInfo != null)
+                               {
+                                       IList* pList = pInfo->GetContentIdListN();
+                                       if(pList != null)
+                                       {
+                                               pContentIdList->AddItems(*pList);
+                                       }
+                               }
+                       }
+               }
+       }
+       return pContentIdList;
+}
+
 void
 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
 {
@@ -1036,8 +1039,8 @@ AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
                                int loopCount = pUpdateFolderIndex->GetCount();
                                for (int k = 0; k < loopCount; ++k)
                                {
-                                       Integer *index = (Integer*)pUpdateFolderIndex->GetAt(k);
-                                       int folderIndex = index->ToInt();
+                                       Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
+                                       int folderIndex = pIndex->ToInt();
                                        pListener->OnThumbnailDecoded(folderIndex);
                                }
                        }
@@ -1050,24 +1053,37 @@ AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
 }
 
 void
-AlbumListPresentationModel::OnContentCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
+AlbumListPresentationModel::OnContentCreated(void)
 {
        AppLogDebug("ENTER");
+       if (__updateProgressStatus == true)
+       {
+               AppLogDebug("EXIT update in application");
+               return;
+       }
        IFormContentUpdateEventListener* pInterface = null;
        IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
        while (pEventEnum->MoveNext() == E_SUCCESS)
        {
                pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
-               pInterface->OnContentUpdated();
+               if (pInterface != null)
+               {
+                       pInterface->OnContentUpdated();
+               }
        }
        delete pEventEnum;
        AppLogDebug("EXIT");
 }
 
 void
-AlbumListPresentationModel::OnContentUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
+AlbumListPresentationModel::OnContentUpdated(void)
 {
        AppLogDebug("ENTER");
+       if (__updateProgressStatus == true)
+       {
+               AppLogDebug("EXIT update in application");
+               return;
+       }
        IFormContentUpdateEventListener* pInterface = null;
        IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
        while (pEventEnum->MoveNext() == E_SUCCESS)
@@ -1080,9 +1096,14 @@ AlbumListPresentationModel::OnContentUpdated(Tizen::Content::ContentId contentId
 }
 
 void
-AlbumListPresentationModel::OnContentDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
+AlbumListPresentationModel::OnContentDeleted(void)
 {
        AppLogDebug("ENTER");
+       if (__updateProgressStatus == true)
+       {
+               AppLogDebug("EXIT update in application");
+               return;
+       }
        IFormContentUpdateEventListener* pInterface = null;
        IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
        while (pEventEnum->MoveNext() == E_SUCCESS)
@@ -1098,22 +1119,25 @@ void
 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
 {
        AppLogDebug("ENTER");
-       if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
-       {
-               IFormContentUpdateEventListener* pInterface = null;
-               IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
-               while (pEventEnum->MoveNext() == E_SUCCESS)
-               {
-                       pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
-                       pInterface->OnContentUpdated();
-               }
-               delete pEventEnum;
-       }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
 void
-AlbumListPresentationModel::RequestThumbnail(const int folderIndex, int pathIndex)
+AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
+{
+       AppLogDebug("ENTER status = %d",status);
+       __updateProgressStatus = status;
+       AppLogDebug("EXIT");
+}
+
+result
+AlbumListPresentationModel::RotateImage(int index, RotateMode rotateMode)
+{
+       return E_SUCCESS;
+}
+
+void
+AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
 {
        AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
 
@@ -1129,28 +1153,7 @@ AlbumListPresentationModel::RequestThumbnail(const int folderIndex, int pathInde
 }
 
 void
-AlbumListPresentationModel::CancelThumbnailRequest(const int folderIndex)
-{
-       AppLogDebug("ENTER : folderIndex(%d)", folderIndex);
-       if (__pAlbumInfoList != null)
-       {
-               AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
-               if (pAlbumInfo != null)
-               {
-                       /*
-                       for (int i = 0; i < loopCount ; ++i)
-                       {
-                               contentId = pAlbumInfo->GetContentId(i);
-                               __pThumbnailProvider->CancelThumbnailRequest(contentId, __pThumbnailEvent);
-                       }
-                        */
-               }
-       }
-       AppLogDebug("EXIT");
-}
-
-void
-AlbumListPresentationModel::ClearThumbnailRequests(bool appTerminating)
+AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
 {
        AppLogDebug("ENTER");
        if (__pThumbnailProvider != null)