Fixed prevent issue
[apps/osp/Gallery.git] / src / GlFileListPresentationModel.cpp
index 76a07f3..17020bf 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;
@@ -68,6 +68,7 @@ static const Rectangle RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION (1, 1, 171, 127);
 static const Color COLOR_DURATION_BG (Color::GetColor(COLOR_ID_BLACK));
 static const Color COLOR_TEXT_OUTLINE (Color::GetColor(COLOR_ID_WHITE));
 
+static const String RESERVED_MEDIA_PATH = Environment::GetMediaPath();
 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
 static const String RESERVED_DOWNLOAD_PATH = Environment::GetMediaPath() + L"Downloads";
@@ -98,6 +99,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 +139,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 +236,10 @@ FileListPresentationModel::DestroyInstance(void)
        AppLogDebug("ENTER");
 
        delete __pThumbnailEvent;
-       __pIconListViewCache = null;
 
        if (__pIconListViewCache != null)
        {
+               __pIconListViewCache->RemoveAll(true);
                delete __pIconListViewCache;
                __pIconListViewCache = null;
        }
@@ -448,6 +458,7 @@ FileListPresentationModel::GetThumbnailInSyncCacheN(const int index, String*& pN
        {
                delete pThumbnailInfo;
        }
+
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return E_SUCCESS;
@@ -549,6 +560,12 @@ FileListPresentationModel::RequestThumbnail(const int index)
 }
 
 void
+FileListPresentationModel::RequestThumbnail(const ContentId& contentId)
+{
+       __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
+}
+
+void
 FileListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
 {
        AppLogDebug("ENTER");
@@ -609,6 +626,8 @@ FileListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
                                }
                        }
 
+                       delete pEnum;
+
                        if (isMatch == false)
                        {
                                if (SIZE_ICON_LIST_CACHE <= __pIconListViewCache->GetCount())
@@ -673,6 +692,14 @@ FileListPresentationModel::OnContentCreated(void)
 }
 
 void
+FileListPresentationModel::OnContentUpdated(const ContentId& contentId)
+{
+       AppLogDebug("ENTER");
+       RequestThumbnail(contentId);
+       AppLogDebug("EXIT");
+}
+
+void
 FileListPresentationModel::OnContentUpdated(void)
 {
        AppLogDebug("ENTER");
@@ -682,7 +709,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)
@@ -718,6 +748,7 @@ FileListPresentationModel::OnContentDeleted(void)
        IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
        while (pEventEnum->MoveNext() == E_SUCCESS)
        {
+               ClearThumbnailRequests();
                pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
                pInterface->OnContentUpdated();
        }
@@ -790,6 +821,31 @@ FileListPresentationModel::GetThumbnailInfoFromInternalBufferN(const ContentId&
        return pThumbnailInfo;
 }
 
+void
+FileListPresentationModel::ShowAnimation(void)
+{
+       IFormContentUpdateEventListener* pInterface = null;
+       IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
+       while (pEventEnum->MoveNext() == E_SUCCESS)
+       {
+               pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
+               pInterface->ShowAnimation();
+       }
+       delete pEventEnum;
+}
+
+void
+FileListPresentationModel::StopAnimation(void)
+{
+       IFormContentUpdateEventListener* pInterface = null;
+       IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
+       while (pEventEnum->MoveNext() == E_SUCCESS)
+       {
+               pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
+               pInterface->StopAnimation();
+       }
+       delete pEventEnum;
+}
 result
 FileListPresentationModel::DeleteContentFileList(const IList& contentIndexList)
 {
@@ -820,7 +876,13 @@ FileListPresentationModel::DeleteContentFileList(const IList& contentIndexList)
                ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(i));
                if (pContentId != null)
                {
-                       DeleteContentFile(*pContentId);
+                       ContentInfo* cntInfo = __pContentManager->GetContentInfoN(*pContentId);
+                       if (cntInfo)
+                       {
+                               String filePath = cntInfo->GetContentPath();
+                               delete cntInfo;
+                               DeleteContentFile(filePath);
+                       }
                }
        }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -921,45 +983,31 @@ FileListPresentationModel::MoveToContentFileList(const IList& contentIndexList,
 }
 
 result
-FileListPresentationModel::DeleteContentFile(const ContentId& contentId)
+FileListPresentationModel::DeleteContentFile(const String& filePath)
 {
        AppLogDebug("ENTER");
-       if (&contentId == null)
-       {
-               AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
-
-               return E_SUCCESS;
-       }
-       result r = __pContentManager->DeleteContent(contentId);
-
+       result r = E_SUCCESS;
+       r = File::Remove(filePath);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return r;
 }
 
 result
-FileListPresentationModel::MoveToContentFile(const ContentId& contentId, const String& destDirectory, const bool isCopyOperation)
+FileListPresentationModel::MoveToContentFile(const String& filePath, const String& destDirectory, const bool isCopyOperation)
 {
        AppLogDebug("ENTER");
-       if (contentId.ToString().IsEmpty() == true || destDirectory.IsEmpty() == true)
+       if (destDirectory.IsEmpty() == true)
        {
                AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
                return E_FAILURE;
        }
        result r = E_SUCCESS;
-       ContentInfo* pContentInfo = __pContentManager->GetContentInfoN(contentId);
-       if (pContentInfo == null)
-       {
-               AppLogDebug("Santhosh %s", destDirectory.GetPointer());
-               AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
-               return E_FAILURE;
-       }
 
-       String filePath = pContentInfo->GetContentPath();
        if (filePath.GetLength() < 4)
        {
                AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
-               return E_SUCCESS;
+               return E_FAILURE;
        }
 
        String destPath;
@@ -978,64 +1026,55 @@ FileListPresentationModel::MoveToContentFile(const ContentId& contentId, const S
        if (destPath.CompareTo(filePath) == 0)
        {
                AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
-               return E_SUCCESS;
-       }
-
-       if (File::IsFileExist(destPath) == true)
-       {
-               File::Remove(destPath);
+               return E_FAILURE;
        }
 
-       if (pContentInfo->GetContentType() == CONTENT_TYPE_IMAGE)
+       while (File::IsFileExist(destPath) == true)
        {
-               r = File::Copy(filePath, destPath, false);
-               if (r == E_SUCCESS)
+               int index = 0;
+               r = destPath.IndexOf(FILE_EXT_SEPARATOR, 0, index);
+               if (!IsFailed(r))
                {
-                       if (r == E_SUCCESS)
+                       if (index < 0)
                        {
-                               ImageContentInfo contentInfo;
-                               r = contentInfo.Construct(&destPath);
-                               if (r == E_SUCCESS)
-                               {
-                                       __pContentManager->CreateContent(contentInfo);
-                                       r = GetLastResult();
-                                       TryCatch(!IsFailed(r),,"CreateContent::the value is %s", GetErrorMessage(r));
-                                       if (!isCopyOperation)
-                                       {
-                                               r = __pContentManager->DeleteContent(contentId);
-                                               TryCatch(!IsFailed(r),,"DeleteContent::the value is %s", GetErrorMessage(r));
-                                       }
-                               }
+                               return E_FAILURE;
+                       }
+                       else
+                       {
+                               destPath.Insert(Math::Rand()%10, index);
                        }
                }
+               else
+               {
+                       return E_FAILURE;
+               }
        }
-       else if (pContentInfo->GetContentType() == CONTENT_TYPE_VIDEO)
+
+       r = File::Copy(filePath, destPath, false);
+
+       if (r == E_STORAGE_FULL)
        {
-               r = File::Copy(filePath, destPath, false);
-               if (r == E_SUCCESS)
+               File::Remove(destPath);
+       }
+
+       if (r == E_SUCCESS)
+       {
+               if (isCopyOperation == false)
                {
-                       VideoContentInfo contentInfo;
-                       r = contentInfo.Construct(&destPath);
-                       {
-                               __pContentManager->CreateContent(contentInfo);
-                               r = GetLastResult();
-                               TryCatch(!IsFailed(r),,"CreateContent::the value is %s", GetErrorMessage(r));
-                               if (!isCopyOperation)
-                               {
-                                       r = __pContentManager->DeleteContent(contentId);
-                                       TryCatch(!IsFailed(r),,"DeleteContent::the value is %s", GetErrorMessage(r));
-                               }
-                       }
+                       File::Remove(filePath);               // if Move Op remove original file
                }
        }
-       CATCH:
-       delete pContentInfo;
-
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        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,
@@ -1043,7 +1082,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)
@@ -1078,7 +1118,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();
@@ -1161,6 +1201,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 != ALL_ALBUMS_REAL_NAME) //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)
 {
@@ -1186,6 +1256,7 @@ FileListPresentationModel::RefreshContentInfoList(const ContentType contentType)
                delete __pContentInfoList;
                __pContentInfoList = null;
        }
+
        __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
@@ -1306,6 +1377,7 @@ FileListPresentationModel::GetContentInfo(const int index) const
 
 IList* FileListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
 {
+       AppLogDebug("ENTER");
        IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
        int loopCount = indexList.GetCount();
        for (int i = 0; i < loopCount; ++i)
@@ -1314,10 +1386,11 @@ IList* FileListPresentationModel::GetContentIdListAtIndexN(const IList& indexLis
 
                if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
                {
-                       pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
+                       ContentInfo* pContentInfo = const_cast<ContentInfo*>(static_cast<const ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())));
+                       pContentIdList->Add(new (std::nothrow) ContentId(pContentInfo->GetContentId()));
                }
        }
-
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
        return pContentIdList;
 }
 
@@ -1535,6 +1608,11 @@ FileListPresentationModel::ConvertToAlbumName(const String& targetPath)const
                return albumName;
        }
 
+       String mediaPath = RESERVED_MEDIA_PATH;
+       int length = mediaPath.GetLength();
+       mediaPath.Remove(length-1,1);
+
+
        if (targetPath == RESERVED_CAMERA_PATH || targetPath == RESERVED_CAMERA_PATH_EXT)
        {
                albumName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB");
@@ -1543,6 +1621,11 @@ FileListPresentationModel::ConvertToAlbumName(const String& targetPath)const
        {
                albumName = ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS");
        }
+       else if (targetPath == mediaPath)
+       {
+
+               albumName = ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME");
+       }
        else
        {
                String directoryName = GetDirecotyNameFromFullPath(targetPath);
@@ -1588,51 +1671,63 @@ FileListPresentationModel::SetUpdateProgressStatus(const bool status)
 }
 
 result
-FileListPresentationModel::RotateImage(int index, RotateMode rotateMode)
+FileListPresentationModel::RotateImage(const Tizen::Content::ContentId& contentId, RotateMode rotateMode)
 {
        result r = E_SUCCESS;
        ImageBuffer rotateBuffer;
        ImageBuffer* pRotatedBuffer = null;
        ImageFormat imageFormat;
        Image img;
-       String filePath = GetContentFilePath(index);
-       r = img.Construct();
-
+       ContentInfo* cntInfo = __pContentManager->GetContentInfoN(contentId);
+       if (!cntInfo)
+       {
+               return E_FAILURE;
+       }
+       String filePath = cntInfo->GetContentPath();
+       delete cntInfo;
 
-       if (r == E_SUCCESS)
+       ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
+       if (contentType == CONTENT_TYPE_VIDEO)
        {
-               imageFormat = img.GetImageFormat(filePath);
+               return r;
        }
 
-       r = rotateBuffer.Construct(filePath);
+       r = img.Construct();
+
        if (r == E_SUCCESS)
        {
-               if (rotateMode == ROTATE_MODE_RIGHT)
+               imageFormat = img.GetImageFormat(filePath);
+
+               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)
@@ -1646,7 +1741,7 @@ FileListPresentationModel::ClearImageCache(void)
                        __pIconListViewCache->RemoveAt(0, true);
                }
        }
-       AppLogDebug("FileListPresentationModel::ClearImageCache --");
+       AppLogDebug("EXIT");
 }
 
 void