NSE_42715
[apps/osp/Gallery.git] / src / GlFileListPresentationModel.cpp
index 687dbe8..d71a4eb 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
 //
@@ -97,6 +97,7 @@ FileListPresentationModel::FileListPresentationModel(void)
 FileListPresentationModel::~FileListPresentationModel(void)
 {
        AppLogDebug("ENTER");
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -167,6 +168,14 @@ FileListPresentationModel::Construct(void)
        {
                __appControlMode = APPCONTROL_MODE_PICK;
 
+               String mimeType = pApp->GetMimeType();
+               if (mimeType.IsEmpty() != true)
+               {
+                       if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
+                       {
+                               __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
+                       }
+               }
                if (pArguments != null)
                {
                        const String* selectionMode = static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
@@ -672,6 +681,9 @@ FileListPresentationModel::OnContentUpdated(void)
                AppLogDebug("EXIT update in application");
                return;
        }
+       //Clear the ImageCaches when content is updated like rotate.
+       ClearImageCache();
+
        IFormContentUpdateEventListener* pInterface = null;
        if (__pContentEventListener == null)
        {
@@ -974,49 +986,23 @@ FileListPresentationModel::MoveToContentFile(const ContentId& contentId, const S
                File::Remove(destPath);
        }
 
-       if (pContentInfo->GetContentType() == CONTENT_TYPE_IMAGE)
+       r = File::Copy(filePath, destPath, false);
+
+       if ( r == E_STORAGE_FULL)
        {
-               r = File::Copy(filePath, destPath, false);
-               if (r == E_SUCCESS)
-               {
-                       if (r == E_SUCCESS)
-                       {
-                               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));
-                                       }
-                               }
-                       }
-               }
+               File::Remove(destPath);
        }
-       else if (pContentInfo->GetContentType() == CONTENT_TYPE_VIDEO)
+       ContentManager::ScanFile(destPath);
+
+       if ( r == E_SUCCESS )
        {
-               r = File::Copy(filePath, destPath, false);
-               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
+                       ContentManager::ScanFile(filePath);
                }
        }
-       CATCH:
+
        delete pContentInfo;
 
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -1024,6 +1010,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,
@@ -1031,9 +1023,10 @@ FileListPresentationModel::StartAppControl(const String& providerId, const Strin
 {
        AppLogDebug("ENTER");
        AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
-       __providerId.Clear();\r
-       __providerId.Append(providerId);\r
-\r
+
+       ClearProviderId();
+       __providerId.Append(providerId);
+
        if (pAc == null)
        {
                AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
@@ -1100,7 +1093,7 @@ FileListPresentationModel::SetCurrentAlbumInfo(const String& albumName, const IL
        }
 
        __albumName = albumName;
-       __providerId.Clear();\r
+       __providerId.Clear();
 
        if (__pDirectoryList != null)
        {
@@ -1584,8 +1577,13 @@ FileListPresentationModel::RotateImage(int index, RotateMode rotateMode)
        ImageFormat imageFormat;
        Image img;
        String filePath = GetContentFilePath(index);
-       r = img.Construct();
+       ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
+       if (contentType == CONTENT_TYPE_VIDEO)
+       {
+               return r;
+       }
 
+       r = img.Construct();
 
        if (r == E_SUCCESS)
        {
@@ -1609,32 +1607,31 @@ FileListPresentationModel::RotateImage(int index, RotateMode rotateMode)
        {
                r = pRotatedBuffer->EncodeToFile(filePath, imageFormat, true, 100);
                delete pRotatedBuffer;
+               ContentManager::ScanFile(filePath);
        }
-
-       ContentManager::ScanFile(filePath);
        return r;
-}\r
-\r
-void\r
-FileListPresentationModel::ClearImageCache(void)\r
-{\r
-       AppLogDebug("FileListPresentationModel::ClearImageCache ++");\r
-\r
-       if(__pIconListViewCache != null && __providerId.Equals(APPCONTROL_PROVIDER_ID_IMAGE, false) == true)\r
-       {\r
-               bool clearThumbnailReq = true;\r
-               while(__pIconListViewCache->GetCount() != 0)\r
-               {\r
-                       //This is to Clear the Thumbnail Reuqests only Once\r
-                       if(clearThumbnailReq == true)\r
-                       {\r
-                               ClearThumbnailRequests();\r
-                               clearThumbnailReq = false;\r
-                       }\r
-                       __pIconListViewCache->RemoveAt(0, true);\r
-               }\r
-       }\r
-       AppLogDebug("FileListPresentationModel::ClearImageCache --");\r
+}
+
+void
+FileListPresentationModel::ClearImageCache(void)
+{
+       AppLogDebug("ENTER");
+
+       if(__pIconListViewCache != null)
+       {
+               bool clearThumbnailReq = true;
+               while(__pIconListViewCache->GetCount() != 0)
+               {
+                       //This is to Clear the Thumbnail Reuqests only Once
+                       if(clearThumbnailReq == true)
+                       {
+                               ClearThumbnailRequests();
+                               clearThumbnailReq = false;
+                       }
+                       __pIconListViewCache->RemoveAt(0, true);
+               }
+       }
+       AppLogDebug("EXIT");
 }
 
 void