Fixed prevent issues
[apps/osp/Gallery.git] / src / GlAlbumListPresentationModel.cpp
index 932979d..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"
@@ -108,6 +109,7 @@ AlbumListPresentationModel::AlbumListPresentationModel(void)
 AlbumListPresentationModel::~AlbumListPresentationModel(void)
 {
        AppLogDebug("ENTER");
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -174,11 +176,6 @@ 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)
@@ -314,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");
 }
@@ -505,6 +506,7 @@ AlbumListPresentationModel::StartAppControl(const String& providerId, const Stri
                IAppControlResponseListener* pListener)
 {
        AppLogDebug("ENTER");
+       FileListPresentationModel::GetInstance()->ClearProviderId();
        AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
        if (pAc == null)
        {
@@ -638,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;
@@ -671,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);
 
@@ -715,6 +721,7 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
                                {
                                        delete pAlbumInfo;
                                }
+                               pAlbumInfo = null;
                        }
                }
 
@@ -773,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
@@ -947,11 +939,11 @@ IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexLi
                return null;
        }
 
-       IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
-       String* pDirPath = null;
-       if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
+       if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
        {
-               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)
@@ -960,18 +952,26 @@ IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexLi
                                pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
                        }
                }
-               else //get all files in directories which are checked for deletion
+       }
+       else
+       {
+               if(__pAlbumInfoList != null)
                {
                        int loopCount = indexList.GetCount();
+                       AlbumInfo* pInfo = null;
                        for (int i = 0; i < loopCount; ++i)
                        {
-                               const Integer* pIndex = static_cast<const Integer*>(indexList.GetAt(i));
-                               pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(pIndex->ToInt() - 1)); //index 0 is all-album which is not counted as a directory. hence delete 1 index
-                               if (pDirPath == null)
+                               int index  = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
+                               pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
+
+                               if(pInfo != null)
                                {
-                                       continue;
+                                       IList* pList = pInfo->GetContentIdListN();
+                                       if(pList != null)
+                                       {
+                                               pContentIdList->AddItems(*pList);
+                                       }
                                }
-                               pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
                        }
                }
        }
@@ -1119,17 +1119,6 @@ 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()));
 }