Fixed side effect
[apps/osp/Gallery.git] / src / GlFileListPresentationModel.cpp
index 32f37fd..d524e5d 100644 (file)
@@ -57,7 +57,7 @@ static const int W_WIDE_THUMBNAIL = 171;
 static const int H_WIDE_THUMBNAIL = 127;
 static const int W_PLAY_FG = 64;
 static const int H_PLAY_FG = 64;
-static const int GAP_W_PLAY_FG = (W_DEFAULT_THUMBNAIL -W_PLAY_FG)/2 ;
+static const int GAP_W_PLAY_FG = (W_DEFAULT_THUMBNAIL -W_PLAY_FG)/2;
 static const int GAP_H_PLAY_FG = (H_DEFAULT_THUMBNAIL - H_PLAY_FG)/2;
 static const int GAP_H_DURATION = H_DEFAULT_THUMBNAIL - H_DURATION;
 static const int ALPHA_DURATION = 70;
@@ -98,6 +98,13 @@ FileListPresentationModel::~FileListPresentationModel(void)
 {
        AppLogDebug("ENTER");
        DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
+       if (__pContentIdList)
+       {
+               __pContentIdList->RemoveAll(true);
+               delete __pContentIdList;
+               __pContentIdList = null;
+       }
+       delete __pContentManager;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -131,7 +138,9 @@ FileListPresentationModel::Construct(void)
 
        if (__pIconListViewCache != null)
        {
+               __pIconListViewCache->RemoveAll(true);
                delete __pIconListViewCache;
+               __pIconListViewCache = null;
        }
        __pIconListViewCache = new (std::nothrow) ArrayList(SingleObjectDeleter);
        __pIconListViewCache->Construct(SIZE_ICON_LIST_CACHE);
@@ -226,10 +235,10 @@ FileListPresentationModel::DestroyInstance(void)
        AppLogDebug("ENTER");
 
        delete __pThumbnailEvent;
-       __pIconListViewCache = null;
 
        if (__pIconListViewCache != null)
        {
+               __pIconListViewCache->RemoveAll(true);
                delete __pIconListViewCache;
                __pIconListViewCache = null;
        }
@@ -448,6 +457,7 @@ FileListPresentationModel::GetThumbnailInSyncCacheN(const int index, String*& pN
        {
                delete pThumbnailInfo;
        }
+
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return E_SUCCESS;
@@ -609,6 +619,8 @@ FileListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
                                }
                        }
 
+                       delete pEnum;
+
                        if (isMatch == false)
                        {
                                if (SIZE_ICON_LIST_CACHE <= __pIconListViewCache->GetCount())
@@ -682,7 +694,10 @@ FileListPresentationModel::OnContentUpdated(void)
                return;
        }
        //Clear the ImageCaches when content is updated like rotate.
-       ClearImageCache();
+       if (__pContentEventListener->GetCount())
+       {
+               ClearImageCache();
+       }
 
        IFormContentUpdateEventListener* pInterface = null;
        if (__pContentEventListener == null)
@@ -703,6 +718,9 @@ FileListPresentationModel::OnContentUpdated(void)
 void
 FileListPresentationModel::OnContentDeleted(void)
 {
+
+
+
        AppLogDebug("ENTER");
        if (__updateProgressStatus == true)
        {
@@ -718,6 +736,7 @@ FileListPresentationModel::OnContentDeleted(void)
        IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
        while (pEventEnum->MoveNext() == E_SUCCESS)
        {
+               ClearThumbnailRequests();
                pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
                pInterface->OnContentUpdated();
        }
@@ -988,15 +1007,15 @@ FileListPresentationModel::MoveToContentFile(const ContentId& contentId, const S
 
        r = File::Copy(filePath, destPath, false);
 
-       if ( r == E_STORAGE_FULL)
+       if (r == E_STORAGE_FULL)
        {
                File::Remove(destPath);
        }
        ContentManager::ScanFile(destPath);
 
-       if ( r == E_SUCCESS )
+       if (r == E_SUCCESS)
        {
-               if ( isCopyOperation == false)
+               if (isCopyOperation == false)
                {
                        File::Remove(filePath);               // if Move Op remove original file
                        ContentManager::ScanFile(filePath);
@@ -1010,6 +1029,12 @@ FileListPresentationModel::MoveToContentFile(const ContentId& contentId, const S
        return r;
 }
 
+void
+FileListPresentationModel::ClearProviderId(void)
+{
+       __providerId.Clear();
+}
+
 result
 FileListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
                const String* pUriData, const Tizen::Base::String* pMimeType, const HashMap* pDataList,
@@ -1017,7 +1042,8 @@ FileListPresentationModel::StartAppControl(const String& providerId, const Strin
 {
        AppLogDebug("ENTER");
        AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
-       __providerId.Clear();
+
+       ClearProviderId();
        __providerId.Append(providerId);
 
        if (pAc == null)
@@ -1052,7 +1078,7 @@ FileListPresentationModel::SetCurrentAlbumInfo(const String& albumName, const IL
                        bool isMatched = false;
                        int outterLoopCount = __pDirectoryList->GetCount();
                        int innerLoopCount = 0;
-                       for (int i = 0; i < outterLoopCount ; ++i)
+                       for (int i = 0; i < outterLoopCount; ++i)
                        {
                                isMatched = false;
                                innerLoopCount = directoryList.GetCount();
@@ -1135,6 +1161,36 @@ FileListPresentationModel::RefreshCurrentAlbumContentInfoList(const ContentType
        return r;
 }
 
+void
+FileListPresentationModel::AddDirectoryIfNew(const String& dirName)
+{
+
+       bool isMatched = false;
+       int dirCount = __pDirectoryList->GetCount();
+       String fullDirName;
+       fullDirName = Environment::GetMediaPath();
+       fullDirName.Append(dirName);
+
+       if (__albumName != ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"))//we are not in All albums
+       {
+               return;
+       }
+
+       for (int i = 0; i < dirCount; ++i)
+       {
+               if (static_cast<String*>(__pDirectoryList->GetAt(i))->CompareTo(fullDirName) == 0)
+               {
+                       isMatched = true;
+                       break;
+               }
+       }
+       
+       if (!isMatched)
+       {
+               __pDirectoryList->Add(new (std::nothrow) String(fullDirName));
+       }
+}
+
 result
 FileListPresentationModel::RefreshContentInfoList(const ContentType contentType)
 {
@@ -1160,6 +1216,7 @@ FileListPresentationModel::RefreshContentInfoList(const ContentType contentType)
                delete __pContentInfoList;
                __pContentInfoList = null;
        }
+
        __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
@@ -1581,36 +1638,37 @@ FileListPresentationModel::RotateImage(int index, RotateMode rotateMode)
        if (r == E_SUCCESS)
        {
                imageFormat = img.GetImageFormat(filePath);
-       }
 
-       r = rotateBuffer.Construct(filePath);
-       if (r == E_SUCCESS)
-       {
-               if (rotateMode == ROTATE_MODE_RIGHT)
+               r = rotateBuffer.Construct(filePath);
+               if (r == E_SUCCESS)
                {
-                       pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_90);
+                       if (rotateMode == ROTATE_MODE_RIGHT)
+                       {
+                               pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_90);
+                       }
+                       else
+                       {
+                               pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_270);
+                       }
                }
-               else
+
+               if (pRotatedBuffer != null)
                {
-                       pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_270);
+                       r = pRotatedBuffer->EncodeToFile(filePath, imageFormat, true, 100);
+                       delete pRotatedBuffer;
+                       ContentManager::ScanFile(filePath);
                }
        }
 
-       if (pRotatedBuffer != null)
-       {
-               r = pRotatedBuffer->EncodeToFile(filePath, imageFormat, true, 100);
-               delete pRotatedBuffer;
-               ContentManager::ScanFile(filePath);
-       }
        return r;
 }
 
 void
 FileListPresentationModel::ClearImageCache(void)
 {
-       AppLogDebug("FileListPresentationModel::ClearImageCache ++");
+       AppLogDebug("ENTER");
 
-       if(__pIconListViewCache != null && __providerId.Equals(APPCONTROL_PROVIDER_ID_IMAGE, false) == true)
+       if(__pIconListViewCache != null)
        {
                bool clearThumbnailReq = true;
                while(__pIconListViewCache->GetCount() != 0)
@@ -1624,7 +1682,7 @@ FileListPresentationModel::ClearImageCache(void)
                        __pIconListViewCache->RemoveAt(0, true);
                }
        }
-       AppLogDebug("FileListPresentationModel::ClearImageCache --");
+       AppLogDebug("EXIT");
 }
 
 void