Arrange code
[apps/osp/Gallery.git] / src / GlAlbumListPresentationModel.cpp
index 0f0fd89..8a02e3c 100644 (file)
@@ -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"
@@ -67,7 +68,7 @@ static const int GAP = 10;
 static const int HEIGHT_OFFSET = 5;
 static const int Y_POS_CANVAS = 260;
 static const int FOLDER_NAME_WIDTH = 165;
-static const int FOLDER_NAME_HEIGHT = 38 ;
+static const int FOLDER_NAME_HEIGHT = 38;
 
 
 static const int ALPHA_BG = 110;
@@ -109,6 +110,8 @@ AlbumListPresentationModel::~AlbumListPresentationModel(void)
 {
        AppLogDebug("ENTER");
        DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
+       delete __pFolderBackgroundBitmap;
+       delete __pContentManager;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -311,7 +314,6 @@ AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& new
        {
                __pAlbumListener = pAlbumListener;
                __renameNewPath = newPath;\r
-               __renameOrgPath = orgPath;\r
                r = ContentManager::ScanDirectory(newPath, true, NULL, __reqId);\r
                AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
                r = ContentManager::ScanDirectory(orgPath, true, NULL, __reqId);\r
@@ -324,10 +326,11 @@ AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& new
 void AlbumListPresentationModel::OnContentScanCompleted (const Tizen::Base::String &scanPath)\r
 {
        AppLogDebug("ENTER");\r
-       if (__pAlbumListener && ( scanPath == __renameNewPath))\r
+       if (__pAlbumListener && (scanPath == __renameNewPath))\r
        {
                InitializeAlbumInfoList(CONTENT_TYPE_ALL);
                __pAlbumListener->OnAlbumRenameComplete();
+               __renameNewPath = L"";
        }
        AppLogDebug("EXIT");
 }
@@ -439,12 +442,14 @@ AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo,
        enTextCount.SetTextAbbreviationEnabled(true);
        enTextCount.Add(textElementCount);
 
-       pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH , rectCanvas.y + HEIGHT_OFFSET);
+       pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH,
+                       rectCanvas.y + HEIGHT_OFFSET);
        canvas.SetFont(ftCnt);
        canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
        canvas.DrawText(pointText, enTextCount);
 
-       pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP , rectCanvas.y + GAP + HEIGHT_OFFSET);
+       pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP,
+                       rectCanvas.y + GAP + HEIGHT_OFFSET);
        canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
        canvas.DrawText(pointText, enText);
 
@@ -505,6 +510,7 @@ AlbumListPresentationModel::StartAppControl(const String& providerId, const Stri
                IAppControlResponseListener* pListener)
 {
        AppLogDebug("ENTER");
+       FileListPresentationModel::GetInstance()->ClearProviderId();
        AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
        if (pAc == null)
        {
@@ -532,7 +538,7 @@ AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
 {
        AppLogDebug("ENTER");
        String directoryName;
-       int lastIndex = -1 ;
+       int lastIndex = -1;
 
        directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
        directoryPath.SubString(lastIndex + 1, directoryName);
@@ -638,6 +644,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,10 +678,12 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
 
                                        pAllAlbumInfo->AppendDirectory(*pDirPath);
                                        pAllAlbumInfo->AppendContentIdList(*pContentIdList);
+
+                                       pContentIdList->RemoveAll(true);
                                        delete pContentIdList;
                                }
                        }
-                       else if (*pDirPath == RESERVED_MEDIA_PATH)
+                       else if (*pDirPath == mediaPath)
                        {
                                IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
 
@@ -682,6 +694,8 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
 
                                        pAllAlbumInfo->AppendDirectory(*pDirPath);
                                        pAllAlbumInfo->AppendContentIdList(*pContentIdList);
+
+                                       pContentIdList->RemoveAll(true);
                                        delete pContentIdList;
                                }
                        }
@@ -703,9 +717,16 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
 
                                                pAllAlbumInfo->AppendDirectory(*pDirPath);
                                                pAllAlbumInfo->AppendContentIdList(*pContentIdList);
+
+                                               pSubDirList->RemoveAll(true);
                                                delete pSubDirList;
                                        }
-                                       delete pContentIdList;
+
+                                       if (pContentIdList != NULL)
+                                       {
+                                               pContentIdList->RemoveAll(true);
+                                               delete pContentIdList;
+                                       }
                                }
                                if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
                                {
@@ -722,7 +743,7 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
                int insertIndex = 0;
                if (pAllAlbumInfo->GetContentIdCount() > 0)
                {
-                       __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
+                       __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, ++insertIndex);
                }
                else
                {
@@ -731,7 +752,7 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
 
                if (pCameraAlbumInfo->GetContentIdCount() > 0)
                {
-                       __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
+                       __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, ++insertIndex);
                }
                else
                {
@@ -740,7 +761,7 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
 
                if (pDownloadAlbumInfo->GetContentIdCount() > 0)
                {
-                       __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
+                       __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, ++insertIndex);
                }
                else
                {
@@ -749,7 +770,7 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
 
                if (pNoNameAlbumInfo->GetContentIdCount() > 0)
                {
-                       __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
+                       __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, ++insertIndex);
                }
                else
                {
@@ -768,32 +789,22 @@ AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentTy
 
        if (pContentDirectoryPathList != null)
        {
+               pContentDirectoryPathList->RemoveAll(true);
                delete pContentDirectoryPathList;
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
        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;
-       }
+if (pContentDirectoryPathList != null)
+{
+       pContentDirectoryPathList->RemoveAll(true);
+       delete pContentDirectoryPathList;
+}
+       delete pAllAlbumInfo;
+       delete pCameraAlbumInfo;
+       delete pDownloadAlbumInfo;
+       delete pNoNameAlbumInfo;
 }
 
 String
@@ -872,7 +883,13 @@ AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directory
                }
                delete pEnum;
        }
-       delete pContentInfoList;
+
+       if (pContentInfoList != NULL)
+       {
+               pContentInfoList->RemoveAll(true);
+               delete pContentInfoList;
+       }
+
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return pContentIdList;
@@ -1128,17 +1145,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()));
 }