+//
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file GlFileListPresentationModel.cpp
+ * @brief This is the implementation file for FileListPresentationModel class.
+ */
+
+#include <cstdlib>
+#include <FMedia.h>
+#include <FSystem.h>
+#include "GlCommonUtil.h"
+#include "GlFileListPresentationModel.h"
+#include "GlContentUpdateEventListener.h"
+#include "GlGalleryApp.h"
+#include "GlThumbnailEvent.h"
+#include "GlThumbnailEventArg.h"
+#include "GlThumbnailProvider.h"
+#include "GlTypes.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Content;
+using namespace Tizen::Graphics;
+using namespace Tizen::Io;
+using namespace Tizen::Media;
+using namespace Tizen::System;
+
+static const String CONTENT_INFO_ORDER = L"ContentFileName";
+
+static const int SIZE_PAGE_NO = 1;
+static const int SIZE_CONUNT_PER_PAGE = 3000;
+static const int SIZE_ICON_LIST_CACHE = 50;
+static const int W_DURATION_TEXT = 44;
+static const int H_DURATION_TEXT = 4;
+static const int W_DURATION = 171;
+static const int H_DURATION = 32;
+static const int W_DEFAULT_THUMBNAIL = 171;
+static const int H_DEFAULT_THUMBNAIL = 127;
+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_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;
+static const int FONT_SIZE_DURATION = 24;
+static const Dimension DIMENSION_REAL_ICON (171,127);
+static const Rectangle RECTANGLE_THUMBNAIL_OFFSET_POSION (1, 1, 171, 127);
+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";
+
+FileListPresentationModel* FileListPresentationModel::__pPresentationModelInstance = null;
+ThumbnailProvider* FileListPresentationModel::__pThumbnailProvider = null;
+ThumbnailEvent* FileListPresentationModel::__pThumbnailEvent = null;
+ArrayList* FileListPresentationModel::__pPresentationModelListener = null;
+ArrayList* FileListPresentationModel::__pContentEventListener = null;
+ArrayList* FileListPresentationModel::__pIconListViewCache = null;
+IList* FileListPresentationModel::__pDirectoryList = null;
+IList* FileListPresentationModel::__pContentInfoList = null;
+
+FileListPresentationModel::FileListPresentationModel(void)
+ : __pContentManager(null)
+ , __albumContentType(CONTENT_TYPE_ALL)
+ , __appControlMode(APPCONTROL_MODE_MAIN)
+ , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
+ , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
+ , __pContentIdList(null)
+ , __updateProgressStatus(false)
+{
+ AppLogDebug("ENTER");
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+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()));
+}
+
+FileListPresentationModel*
+FileListPresentationModel::GetInstance(void)
+{
+ AppLogDebug("ENTER");
+ if (__pPresentationModelInstance == null)
+ {
+ CreateInstance();
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return __pPresentationModelInstance;
+}
+
+result
+FileListPresentationModel::Construct(void)
+{
+ AppLogDebug("ENTER");
+
+ IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
+ __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
+ __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
+
+ DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
+
+ ContentUpdateEventListener::GetInstance();
+ __pContentManager = new (std::nothrow) ContentManager();
+ __pContentManager->Construct();
+
+ if (__pIconListViewCache != null)
+ {
+ __pIconListViewCache->RemoveAll(true);
+ delete __pIconListViewCache;
+ __pIconListViewCache = null;
+ }
+ __pIconListViewCache = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ __pIconListViewCache->Construct(SIZE_ICON_LIST_CACHE);
+
+ if (__pDirectoryList != null)
+ {
+ delete __pDirectoryList;
+ }
+ __pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+
+ if (__pContentInfoList != null)
+ {
+ delete __pContentInfoList;
+ }
+ __pContentInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+
+ __pPresentationModelListener = new (std::nothrow) ArrayList();
+ __pPresentationModelListener->Construct();
+
+ __pContentEventListener = new (std::nothrow) ArrayList();
+ __pContentEventListener->Construct();
+
+ __pThumbnailProvider = ThumbnailProvider::GetInstance();
+
+ GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
+ const IMap* pArguments = pApp->GetAppControlArguments();
+ String operationId = pApp->GetAppControlOperationId();
+
+ if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
+ {
+ __appControlMode = APPCONTROL_MODE_MAIN;
+ }
+ else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
+ {
+ __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)));
+
+ if (pApp->GetMimeType().StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
+ {
+ __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
+ }
+
+ if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
+ {
+ __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
+ }
+ }
+ }
+ else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
+ {
+ __appControlMode = APPCONTROL_MODE_SETTING;
+ }
+
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_SUCCESS;
+}
+
+void
+FileListPresentationModel::CreateInstance(void)
+{
+ AppLogDebug("ENTER");
+ __pPresentationModelInstance = new (std::nothrow) FileListPresentationModel();
+ result r = __pPresentationModelInstance->Construct();
+ if (IsFailed(r) == true)
+ {
+ delete __pPresentationModelInstance;
+ __pPresentationModelInstance = null;
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return;
+ }
+
+ std::atexit(DestroyInstance);
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+void
+FileListPresentationModel::DestroyInstance(void)
+{
+ AppLogDebug("ENTER");
+
+ delete __pThumbnailEvent;
+
+ if (__pIconListViewCache != null)
+ {
+ __pIconListViewCache->RemoveAll(true);
+ delete __pIconListViewCache;
+ __pIconListViewCache = null;
+ }
+
+ if (__pDirectoryList != null)
+ {
+ delete __pDirectoryList;
+ __pDirectoryList = null;
+ }
+
+ if (__pContentInfoList != null)
+ {
+ delete __pContentInfoList;
+ __pContentInfoList = null;
+ }
+
+ if (__pPresentationModelListener != null)
+ {
+ delete __pPresentationModelListener;
+ __pPresentationModelListener = null;
+ }
+
+ if (__pContentEventListener != null)
+ {
+ delete __pContentEventListener;
+ __pContentEventListener = null;
+ }
+
+ delete __pPresentationModelInstance;
+ __pPresentationModelInstance = null;
+
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+String
+FileListPresentationModel::GetFileNameFromFullPath(const String& fullPath, const bool withExt) const
+{
+ AppLogDebug("ENTER");
+ if (fullPath.CompareTo(EMPTY_SPACE) == 0)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return EMPTY_SPACE;
+ }
+
+ String delim(DIRECTORY_SEPARATOR);
+ StringTokenizer st(fullPath,delim);
+ String token;
+ while (st.HasMoreTokens())
+ {
+ st.GetNextToken(token);
+ }
+
+ if (withExt == true)
+ {
+ AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
+
+ return token;
+ }
+ else
+ {
+ String subDelim(FILE_EXT_SEPARATOR);
+ StringTokenizer subSt(token, subDelim);
+ String subToken;
+ subSt.GetNextToken(subToken);
+ AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
+
+ return subToken;
+ }
+}
+
+String
+FileListPresentationModel::GetDirecotyNameFromFullPath(const String& fullPath)const
+{
+ AppLogDebug("ENTER");
+ if (fullPath == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return null;
+ }
+ String delim(DIRECTORY_SEPARATOR);
+ StringTokenizer st(fullPath,delim);
+ String token;
+ while (st.HasMoreTokens())
+ {
+ st.GetNextToken(token);
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return token;
+}
+
+bool
+FileListPresentationModel::IsContainContentInDirectory(const String& directoryPath, ContentType contentType) const
+{
+ AppLogDebug("ENTER");
+ IListT<ContentType>* pContentTypeList = new (std::nothrow) ArrayListT<ContentType>();
+ if (&directoryPath == null || pContentTypeList == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return false;
+ }
+
+ if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_ALL)
+ {
+ pContentTypeList->Add(CONTENT_TYPE_IMAGE);
+ }
+ if (contentType == CONTENT_TYPE_VIDEO || contentType == CONTENT_TYPE_ALL)
+ {
+ pContentTypeList->Add(CONTENT_TYPE_VIDEO);
+ }
+
+ ContentDirectory contentDirectory;
+ result r = contentDirectory.Construct(*pContentTypeList);
+ if (pContentTypeList != null)
+ {
+ delete pContentTypeList;
+ }
+ TryReturn(r == E_SUCCESS, false, "[%s] Unable to construct ContentDirectory", GetErrorMessage(r));
+
+ bool returnValue = false;
+ int pageNo = SIZE_PAGE_NO;
+ int countPerPage = SIZE_CONUNT_PER_PAGE;
+
+ IList* pContentList = contentDirectory.GetContentDirectoryItemListN(directoryPath, pageNo, countPerPage,
+ CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
+
+ if (pContentList == null || pContentList->GetCount() <= 0)
+ {
+ returnValue = false;
+ }
+ else
+ {
+ returnValue = true;
+ }
+
+ if (pContentList != null)
+ {
+ delete pContentList;
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return returnValue;
+}
+
+result
+FileListPresentationModel::GetThumbnailInSyncCacheN(const int index, String*& pName, Bitmap*& pThumbnail)
+{
+ AppLogDebug("ENTER : index(%d)", index);
+ Bitmap* pOriginalBitmap = null;
+ Bitmap* pDestinationBitmap = null;
+ ContentInfo* pContentInfo = null;
+
+ if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
+ {
+ pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
+ if (pContentInfo == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_FAILURE;
+ }
+ }
+ else
+ {
+ AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
+ return E_FAILURE;
+ }
+
+ ThumbnailInfo* pThumbnailInfo = GetThumbnailInfoFromInternalBufferN(pContentInfo->GetContentId());
+ if (pThumbnailInfo != null)
+ {
+ pName = new (std::nothrow) String(pThumbnailInfo->GetFilePath());
+ pOriginalBitmap = pThumbnailInfo->GetBitmapN();
+ }
+
+ if ((pThumbnailInfo != null)&&(pThumbnailInfo->GetContentType() == CONTENT_TYPE_VIDEO))
+ {
+ if (pOriginalBitmap != null)
+ {
+ pDestinationBitmap = CoverVideoOverlayedImageOnThumbnailN(*pOriginalBitmap, *pThumbnailInfo);
+ delete pOriginalBitmap;
+ }
+ }
+ else
+ {
+ pDestinationBitmap = pOriginalBitmap;
+ }
+
+ if (pDestinationBitmap != null)
+ {
+ Bitmap* pThumbnailBgBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_BG);
+ Rectangle thumbnailRect(RECTANGLE_THUMBNAIL_OFFSET_POSION);
+ pDestinationBitmap->Scale(Dimension(RECTANGLE_THUMBNAIL_OFFSET_POSION.width - RECTANGLE_THUMBNAIL_OFFSET_POSION.x
+ , RECTANGLE_THUMBNAIL_OFFSET_POSION.height - RECTANGLE_THUMBNAIL_OFFSET_POSION.y));
+ if (pThumbnailBgBitmap != null)
+ {
+ pThumbnailBgBitmap->Scale(DIMENSION_REAL_ICON);
+ pThumbnail = GetShadedBackgroundBitmapN(*pThumbnailBgBitmap, *pDestinationBitmap, thumbnailRect);
+ delete pThumbnailBgBitmap;
+ delete pDestinationBitmap;
+ }
+ else
+ {
+ pThumbnail = pDestinationBitmap;
+ }
+ }
+ else
+ {
+ pThumbnail = null;
+ }
+
+ if (pThumbnailInfo != null)
+ {
+ delete pThumbnailInfo;
+ }
+
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_SUCCESS;
+}
+
+result
+FileListPresentationModel::GetThumbnailVideoInSyncCacheN(const int index,
+ String*& pName, Bitmap*& pThumbnail, String*& pDuration) const
+{
+ AppLogDebug("ENTER : index(%d)", index);
+ ContentInfo* pContentInfo = null;
+ Bitmap* pOriginalBitmap = null;
+
+ if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
+ {
+ pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
+ if (pContentInfo == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+ return E_FAILURE;
+ }
+ }
+ else
+ {
+ AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
+ return E_FAILURE;
+ }
+
+ ThumbnailInfo* pThumbnailInfo = GetThumbnailInfoFromInternalBufferN(pContentInfo->GetContentId());
+ if (pThumbnailInfo != null)
+ {
+ pName = new (std::nothrow) String(pThumbnailInfo->GetFilePath());
+ pOriginalBitmap = pThumbnailInfo->GetBitmapN();
+ pDuration = new (std::nothrow) String(CommonUtil::DurationToTimeString(pThumbnailInfo->GetDuration()));
+ }
+ else
+ {
+ pName = new (std::nothrow) String(EMPTY_SPACE);
+ pDuration = new (std::nothrow) String(CommonUtil::DurationToTimeString(0));
+ }
+
+ if (pOriginalBitmap != null)
+ {
+ Bitmap* pThumbnailBgBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_BG);
+ Rectangle thumbnailRect(RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION);
+ pOriginalBitmap->Scale(Dimension(RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.width - RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.x
+ , RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.height - RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.y));
+ if (pThumbnailBgBitmap != null)
+ {
+ pThumbnailBgBitmap->Scale(Dimension(W_WIDE_THUMBNAIL, H_WIDE_THUMBNAIL));
+ pThumbnail = GetShadedBackgroundBitmapN(*pThumbnailBgBitmap, *pOriginalBitmap, thumbnailRect);
+ delete pThumbnailBgBitmap;
+ }
+ delete pOriginalBitmap;
+ }
+ else
+ {
+ pThumbnail = null;
+ }
+
+ if (pThumbnail != null)
+ {
+ pThumbnail->Scale(Dimension(W_WIDE_THUMBNAIL, H_WIDE_THUMBNAIL));
+ }
+
+ if (pThumbnailInfo != null)
+ {
+ delete pThumbnailInfo;
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_SUCCESS;
+}
+
+void
+FileListPresentationModel::RequestThumbnail(const int index)
+{
+ AppLogDebug("ENTER : index(%d)", index);
+ ContentInfo* pContentInfo = null;
+
+ if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
+ {
+ pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
+ if (pContentInfo == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+ return;
+ }
+ }
+ else
+ {
+ AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
+
+ return;
+ }
+
+ __pThumbnailProvider->RequestThumbnail(pContentInfo->GetContentId(), __pThumbnailEvent);
+ AppLogDebug("EXIT");
+}
+
+void
+FileListPresentationModel::RequestThumbnail(const ContentId& contentId)
+{
+ __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
+}
+
+void
+FileListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
+{
+ AppLogDebug("ENTER");
+
+ if (__pThumbnailProvider != null)
+ {
+ __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
+ }
+
+ AppLogDebug("EXIT");
+}
+
+void
+FileListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
+{
+ AppLogDebug("ENTER");
+
+ if (&eventArg != null)
+ {
+ ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
+ if (pThumbnailEventArg == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return;
+ }
+ ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
+ if (pThumbnailInfo == null)
+ {
+ AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
+
+ return;
+ }
+
+ bool isMatch = false;
+ ContentId contentId = pThumbnailInfo->GetContentId();
+
+ if (__pIconListViewCache != null)
+ {
+ IEnumerator* pEnum = __pIconListViewCache->GetEnumeratorN();
+ Bitmap* pBitmap = null;
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ ThumbnailInfo* pTempThumbnailInfo = static_cast<ThumbnailInfo*>(pEnum->GetCurrent());
+
+ if (contentId == pTempThumbnailInfo->GetContentId())
+ {
+ AppLogDebug("[CHASEFIRE] PM receive (%ls)", pThumbnailInfo->GetFilePath().GetPointer());
+ pBitmap = pThumbnailInfo->GetBitmapN();
+ pTempThumbnailInfo->SetBitmap(*pBitmap);
+ delete pBitmap;
+
+ pTempThumbnailInfo->SetContentType(pThumbnailInfo->GetContentType());
+ pTempThumbnailInfo->SetDuration(pThumbnailInfo->GetDuration());
+ delete pThumbnailInfo;
+ isMatch = true;
+ break;
+ }
+ }
+
+ delete pEnum;
+
+ if (isMatch == false)
+ {
+ if (SIZE_ICON_LIST_CACHE <= __pIconListViewCache->GetCount())
+ {
+ __pIconListViewCache->RemoveAt(0, true);
+ }
+ AppLogDebug("[CHASEFIRE] (all:%d) Add Thumbail(%ls)", __pIconListViewCache->GetCount(),
+ pThumbnailInfo->GetFilePath().GetPointer());
+ __pIconListViewCache->Add(pThumbnailInfo);
+ }
+ }
+
+ int index = -1;
+ int loopCount = __pContentInfoList->GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ if (contentId == (static_cast<ContentInfo*>(__pContentInfoList->GetAt(i)))->GetContentId())
+ {
+ index = i;
+ break;
+ }
+ }
+
+ IAlbumEventListener* pInterface = null;
+ IEnumerator* pEventEnum = __pPresentationModelListener->GetEnumeratorN();
+ while (pEventEnum->MoveNext() == E_SUCCESS)
+ {
+ pInterface = static_cast<IAlbumEventListener*>(pEventEnum->GetCurrent());
+ pInterface->OnThumbnailDecoded(index);
+ }
+ delete pEventEnum;
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+void
+FileListPresentationModel::OnContentCreated(void)
+{
+ AppLogDebug("ENTER");
+ if (__updateProgressStatus == true)
+ {
+ AppLogDebug("EXIT update in application");
+ return;
+ }
+ IFormContentUpdateEventListener* pInterface = null;
+ if (__pContentEventListener == null)
+ {
+ AppLogDebug("EXIT");
+ return;
+ }
+ IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
+ while (pEventEnum->MoveNext() == E_SUCCESS)
+ {
+ pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
+ if (pInterface != null)
+ {
+ pInterface->OnContentUpdated();
+ }
+ }
+ delete pEventEnum;
+ AppLogDebug("EXIT");
+}
+
+void
+FileListPresentationModel::OnContentUpdated(const ContentId& contentId)
+{
+ AppLogDebug("ENTER");
+ RequestThumbnail(contentId);
+ AppLogDebug("EXIT");
+}
+
+void
+FileListPresentationModel::OnContentUpdated(void)
+{
+ AppLogDebug("ENTER");
+ if (__updateProgressStatus == true)
+ {
+ AppLogDebug("EXIT update in application");
+ return;
+ }
+ //Clear the ImageCaches when content is updated like rotate.
+ if (__pContentEventListener->GetCount())
+ {
+ ClearImageCache();
+ }
+
+ IFormContentUpdateEventListener* pInterface = null;
+ if (__pContentEventListener == null)
+ {
+ AppLogDebug("EXIT");
+ return;
+ }
+ IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
+ while (pEventEnum->MoveNext() == E_SUCCESS)
+ {
+ pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
+ pInterface->OnContentUpdated();
+ }
+ delete pEventEnum;
+ AppLogDebug("EXIT");
+}
+
+void
+FileListPresentationModel::OnContentDeleted(void)
+{
+ AppLogDebug("ENTER");
+ if (__updateProgressStatus == true)
+ {
+ AppLogDebug("EXIT update in application");
+ return;
+ }
+ IFormContentUpdateEventListener* pInterface = null;
+ if (__pContentEventListener == null)
+ {
+ AppLogDebug("EXIT");
+ return;
+ }
+ IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
+ while (pEventEnum->MoveNext() == E_SUCCESS)
+ {
+ ClearThumbnailRequests();
+ pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
+ pInterface->OnContentUpdated();
+ }
+ delete pEventEnum;
+ AppLogDebug("EXIT");
+}
+
+void
+FileListPresentationModel::AddPresentationModelListener(const IAlbumEventListener* listener)
+{
+ AppLogDebug("ENTER");
+ __pPresentationModelListener->Add((Object*)listener);
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+void
+FileListPresentationModel::RemovePresentationModelListener(const IAlbumEventListener& listener)
+{
+ AppLogDebug("ENTER");
+ __pPresentationModelListener->Remove(listener);
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+void
+FileListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
+{
+ AppLogDebug("ENTER");
+ if (__pContentEventListener != null)
+ {
+ __pContentEventListener->RemoveAll();
+ __pContentEventListener->Add((Object*)listener);
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+ }
+}
+
+void
+FileListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener* listener)
+{
+ AppLogDebug("ENTER");
+ __pContentEventListener->Remove(*listener);
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+ThumbnailInfo*
+FileListPresentationModel::GetThumbnailInfoFromInternalBufferN(const ContentId& contentId) const
+{
+ AppLogDebug("ENTER");
+ ThumbnailInfo* pThumbnailInfo = null;
+ ThumbnailInfo* pTempThumbnailInfo = null;
+ if (__pIconListViewCache != null)
+ {
+ int loopCount = __pIconListViewCache->GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ pTempThumbnailInfo = static_cast<ThumbnailInfo*>(__pIconListViewCache->GetAt(i));
+ if (contentId == pTempThumbnailInfo->GetContentId())
+ {
+
+ pThumbnailInfo = new (std::nothrow) ThumbnailInfo();
+ Bitmap* pBitmap = pTempThumbnailInfo->GetBitmapN();
+ pThumbnailInfo->Construct(pTempThumbnailInfo->GetContentId(), pTempThumbnailInfo->GetFilePath(),
+ *pBitmap, pTempThumbnailInfo->GetContentType(), pTempThumbnailInfo->GetDuration());
+ delete pBitmap;
+ break;
+ }
+ }
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ 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)
+{
+ AppLogDebug("ENTER");
+ if (&contentIndexList == null || contentIndexList.GetCount() <= 0)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_SUCCESS;
+ }
+
+ IList * pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ int loopCount = contentIndexList.GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
+
+ if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
+ {
+ pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>
+ (__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
+ }
+ }
+
+ loopCount = pContentIdList->GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(i));
+ if (pContentId != null)
+ {
+ ContentInfo* cntInfo = __pContentManager->GetContentInfoN(*pContentId);
+ if (cntInfo)
+ {
+ String filePath = cntInfo->GetContentPath();
+ delete cntInfo;
+ DeleteContentFile(filePath);
+ }
+ }
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_SUCCESS;
+}
+
+IList*
+FileListPresentationModel::GetCollisionIndexListN(const IList& contentIndexList, const String& destDirectory)
+{
+ AppLogDebug("ENTER");
+ if (&contentIndexList == null || contentIndexList.GetCount() <= 0 || &destDirectory == null
+ || destDirectory.IsEmpty() == true)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return null;
+ }
+
+ if (File::IsFileExist(destDirectory) == false)
+ {
+ AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
+
+ return null;
+ }
+
+ IList * pCollisionInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ ContentInfo* pContentInfo = null;
+ int loopCount = contentIndexList.GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
+
+ if ((pIndex != null) && (pIndex->ToInt()) >= 0 && __pContentInfoList->GetCount() > pIndex->ToInt())
+ {
+ pContentInfo = const_cast<ContentInfo*>(static_cast<const ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())));
+ String filePath = pContentInfo->GetContentPath();
+ String fileName = GetFileNameFromFullPath(filePath, true);
+
+ String destPath;
+ if (destDirectory.EndsWith(DIRECTORY_SEPARATOR) == true)
+ {
+ destPath.Append(destDirectory);
+ destPath.Append(fileName);
+ }
+ else
+ {
+ destPath.Append(destDirectory);
+ destPath.Append(DIRECTORY_SEPARATOR);
+ destPath.Append(fileName);
+ }
+
+ if (File::IsFileExist(destPath) == true)
+ {
+ pCollisionInfoList->Add(*(new (std::nothrow) String(pIndex->ToString() + MULTI_ITEM_SEPARATOR + fileName)));
+ }
+ }
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return pCollisionInfoList;
+}
+
+result
+FileListPresentationModel::MoveToContentFileList(const IList& contentIndexList, const String& destDirectory)
+{
+ AppLogDebug("ENTER");
+ result r = E_SUCCESS;
+ if (&contentIndexList == null || contentIndexList.GetCount() <= 0 || &destDirectory == null || destDirectory.IsEmpty() == true)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return r;
+ }
+
+ if (File::IsFileExist(destDirectory) == false)
+ {
+ Directory::Create(destDirectory, true);
+ }
+
+ delete __pContentIdList;
+ __pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ int loopCount = contentIndexList.GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
+
+ if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
+ {
+ __pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
+ }
+ }
+
+
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_SUCCESS;
+}
+
+result
+FileListPresentationModel::DeleteContentFile(const String& filePath)
+{
+ AppLogDebug("ENTER");
+ result r = E_SUCCESS;
+ r = File::Remove(filePath);
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return r;
+}
+
+result
+FileListPresentationModel::MoveToContentFile(const String& filePath, const String& destDirectory, const bool isCopyOperation)
+{
+ AppLogDebug("ENTER");
+ if (destDirectory.IsEmpty() == true)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+ return E_FAILURE;
+ }
+ result r = E_SUCCESS;
+
+ if (filePath.GetLength() < 4)
+ {
+ AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
+ return E_FAILURE;
+ }
+
+ String destPath;
+ if (destDirectory.EndsWith(DIRECTORY_SEPARATOR) == true)
+ {
+ destPath.Append(destDirectory);
+ destPath.Append(GetFileNameFromFullPath(filePath, true));
+ }
+ else
+ {
+ destPath.Append(destDirectory);
+ destPath.Append(DIRECTORY_SEPARATOR);
+ destPath.Append(GetFileNameFromFullPath(filePath, true));
+ }
+
+ if (destPath.CompareTo(filePath) == 0)
+ {
+ AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
+ return E_FAILURE;
+ }
+
+ while (File::IsFileExist(destPath) == true)
+ {
+ int index = 0;
+ r = destPath.IndexOf(FILE_EXT_SEPARATOR, 0, index);
+ if (!IsFailed(r))
+ {
+ if (index < 0)
+ {
+ return E_FAILURE;
+ }
+ else
+ {
+ destPath.Insert(Math::Rand()%10, index);
+ }
+ }
+ else
+ {
+ return E_FAILURE;
+ }
+ }
+
+ r = File::Copy(filePath, destPath, false);
+
+ if (r == E_STORAGE_FULL)
+ {
+ File::Remove(destPath);
+ }
+
+ if (r == E_SUCCESS)
+ {
+ if (isCopyOperation == false)
+ {
+ File::Remove(filePath); // if Move Op remove original file
+ }
+ }
+ 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,
+ IAppControlResponseListener* pListener)
+{
+ AppLogDebug("ENTER");
+ AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
+
+ ClearProviderId();
+ __providerId.Append(providerId);
+
+ if (pAc == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+ return E_FAILURE;
+ }
+ result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
+
+ if (r == E_SUCCESS)
+ {
+ GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
+ pGalleryApp->SetFrameEnabled(false);
+ }
+
+ delete pAc;
+
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return r;
+}
+
+result
+FileListPresentationModel::SetCurrentAlbumInfo(const String& albumName, const IList& directoryList)
+{
+ AppLogDebug("ENTER");
+
+ if (&directoryList != null)
+ {
+ if (__pDirectoryList != null && __pDirectoryList->GetCount() > 0)
+ {
+ bool isMatched = false;
+ int outterLoopCount = __pDirectoryList->GetCount();
+ int innerLoopCount = 0;
+ for (int i = 0; i < outterLoopCount; ++i)
+ {
+ isMatched = false;
+ innerLoopCount = directoryList.GetCount();
+ for (int j = 0; j < innerLoopCount; ++j)
+ {
+ if (static_cast<String*>(__pDirectoryList->GetAt(i))->CompareTo(
+ *(const_cast<String*>(static_cast<const String*>(directoryList.GetAt(j))))) == 0)
+ {
+ isMatched = true;
+ break;
+ }
+ }
+ }
+
+ outterLoopCount = directoryList.GetCount();
+ for (int i = 0; i < outterLoopCount; ++i)
+ {
+ isMatched = false;
+ innerLoopCount = __pDirectoryList->GetCount();
+ for (int j = 0; j < innerLoopCount; ++j)
+ {
+ if (const_cast<String*>(static_cast<const String*>(directoryList.GetAt(i)))->CompareTo(
+ *(static_cast<String*>(__pDirectoryList->GetAt(j)))) == 0)
+ {
+ isMatched = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ __albumName = albumName;
+ __providerId.Clear();
+
+ if (__pDirectoryList != null)
+ {
+ delete __pDirectoryList;
+ }
+ __pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+
+ int loopCount = directoryList.GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ __pDirectoryList->Add(new (std::nothrow) String(*(const_cast<String*>
+ (static_cast<const String*>(directoryList.GetAt(i))))));
+ }
+
+ if (__pContentInfoList != null)
+ {
+ delete __pContentInfoList;
+ __pContentInfoList = null;
+ }
+
+ if (GetAppControlMode() == APPCONTROL_MODE_PICK)
+ {
+ AppControlMediaType appControlMediaType = GetAppControlMediaType();
+ if (appControlMediaType == APPCONTROL_MEDIA_TYPE_IMAGE)
+ {
+ __albumContentType = CONTENT_TYPE_IMAGE;
+ }
+ else if (appControlMediaType == APPCONTROL_MEDIA_TYPE_VIDEO)
+ {
+ __albumContentType = CONTENT_TYPE_VIDEO;
+ }
+ }
+ __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_SUCCESS;
+}
+
+result
+FileListPresentationModel::RefreshCurrentAlbumContentInfoList(const ContentType contentType)
+{
+ AppLogDebug("ENTER");
+ result r = RefreshContentInfoList(contentType);
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ 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)
+{
+ AppLogDebug("ENTER");
+ if ((contentType != CONTENT_TYPE_ALL) && (contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO))
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_FAILURE;
+ }
+
+ if ((__pDirectoryList == null) || (__pDirectoryList->GetCount() <= 0))
+ {
+ AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_SUCCESS;
+ }
+
+ __albumContentType = contentType;
+
+ if (__pContentInfoList != null)
+ {
+ delete __pContentInfoList;
+ __pContentInfoList = null;
+ }
+
+ __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return E_SUCCESS;
+}
+
+String
+FileListPresentationModel::GetCurrentAlbumName(void) const
+{
+ AppLogDebug("ENTER");
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return __albumName;
+}
+
+void
+FileListPresentationModel::SetCurrentAlbumName(const String& albumName)
+{
+ AppLogDebug("ENTER");
+ if (&albumName == null)
+ {
+ __albumName = EMPTY_SPACE;
+ }
+ else
+ {
+ __albumName = albumName;
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+ContentType
+FileListPresentationModel::GetCurrentAlbumContentType(void) const
+{
+ AppLogDebug("ENTER");
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return __albumContentType;
+}
+
+void
+FileListPresentationModel::SetCurrentAlbumContentType(const ContentType contentType)
+{
+ AppLogDebug("ENTER");
+ __albumContentType = contentType;
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+IList*
+FileListPresentationModel::GetAlbumDirectoryListN(void) const
+{
+ AppLogDebug("ENTER");
+ IList* pAlbumDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ if (__pDirectoryList == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return pAlbumDirectoryList;
+ }
+
+ String* pDirectory = null;
+ int loopCount = __pDirectoryList->GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ pDirectory = static_cast<String*>(__pDirectoryList->GetAt(i));
+ pAlbumDirectoryList->Add(new (std::nothrow) String(*pDirectory));
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return pAlbumDirectoryList;
+}
+
+IList*
+FileListPresentationModel::GetAlbumContentInfoList(void) const
+{
+ AppLogDebug("ENTER");
+ IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+ if (__pContentInfoList == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return pContentList;
+ }
+
+ ContentInfo* pContentInfo = null;
+ int loopCount = __pContentInfoList->GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(i));
+ pContentList->Add(pContentInfo);
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return pContentList;
+}
+
+ContentInfo*
+FileListPresentationModel::GetContentInfo(const int index) const
+{
+ AppLogDebug("ENTER");
+ if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return null;
+ }
+
+ if (index < 0 || index >= __pContentInfoList->GetCount())
+ {
+ AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
+
+ return null;
+ }
+ ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return pContentInfo;
+}
+
+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)
+ {
+ const Integer* pIndex = static_cast<const Integer*>(indexList.GetAt(i));
+
+ if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
+ {
+ 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;
+}
+
+int
+FileListPresentationModel::GetCurrentAlbumContentInfoCount(void) const
+{
+ AppLogDebug("ENTER");
+ if (__pContentInfoList == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return 0;
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return __pContentInfoList->GetCount();
+}
+
+ContentId
+FileListPresentationModel::GetContentInfoIndex(const int index) const
+{
+ AppLogDebug("ENTER");
+ if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return 0;
+ }
+
+ if (index < 0 || index >= __pContentInfoList->GetCount())
+ {
+ AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
+
+ return 0;
+ }
+ ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
+ ContentId contentId = pContentInfo->GetContentId();
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return contentId;
+}
+
+String
+FileListPresentationModel::GetContentFilePath(const int index) const
+{
+ AppLogDebug("ENTER index(%d)", index);
+ if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return EMPTY_SPACE;
+ }
+
+ if (index < 0 || index >= __pContentInfoList->GetCount())
+ {
+ AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
+
+ return EMPTY_SPACE;
+ }
+
+ ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
+ String contentPath = pContentInfo->GetContentPath();
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return contentPath;
+}
+
+Bitmap*
+FileListPresentationModel::CoverVideoOverlayedImageOnThumbnailN(Bitmap& thumbnail,
+ const ThumbnailInfo& thumbmailInfo)
+{
+ AppLogDebug("ENTER");
+ Bitmap* pOverlayedImage = null;
+
+ if (&thumbmailInfo != null)
+ {
+ long duration = thumbmailInfo.GetDuration();
+
+ Canvas mainCanvas;
+ if (&thumbnail != null)
+ {
+ BufferInfo bufferInfo;
+ thumbnail.Lock(bufferInfo, INFINITE);
+ thumbnail.Unlock();
+ mainCanvas.Construct(bufferInfo);
+ }
+ else
+ {
+ Rectangle mainRect(0, 0, W_DEFAULT_THUMBNAIL, H_DEFAULT_THUMBNAIL);
+ mainCanvas.Construct(mainRect);
+ mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_BLACK), mainRect);
+ }
+
+ Rectangle playRect(GAP_W_PLAY_FG, GAP_H_PLAY_FG, W_PLAY_FG, H_PLAY_FG);
+ Bitmap* playBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_PLAY);
+ if (playBitmap != null)
+ {
+ mainCanvas.DrawBitmap(playRect, *playBitmap);
+ delete playBitmap;
+ }
+
+ Canvas durCanvas;
+ Rectangle durSize(0, 0, W_DURATION, H_DURATION);
+ Rectangle durRect(0, GAP_H_DURATION, W_DURATION, H_DURATION);
+ Color durColor(COLOR_DURATION_BG);
+ durColor.SetAlpha(ALPHA_DURATION);
+ durCanvas.Construct(durSize);
+ durCanvas.FillRectangle(durColor, durSize);
+ Font durFont;
+ durFont.Construct(FONT_STYLE_PLAIN, FONT_SIZE_DURATION);
+ durCanvas.SetFont(durFont);
+ durCanvas.DrawText(Point(W_DURATION_TEXT, H_DURATION_TEXT),
+ CommonUtil::DurationToTimeString(duration), COLOR_TEXT_OUTLINE);
+ Bitmap durBitmap;
+ durBitmap.Construct(durCanvas, durCanvas.GetBounds());
+ mainCanvas.DrawBitmap(durRect, durBitmap);
+
+ pOverlayedImage = new (std::nothrow) Bitmap();
+ pOverlayedImage->Construct(mainCanvas, mainCanvas.GetBounds());
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return pOverlayedImage;
+}
+
+Bitmap*
+FileListPresentationModel::GetShadedBackgroundBitmapN(Bitmap& bgBitmap,
+ const Bitmap& originalBitmap, const Rectangle& originalBitmapPosition) const
+{
+ AppLogDebug("ENTER");
+ if (&originalBitmap == null || &originalBitmap == null)
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+ return null;
+ }
+
+ BufferInfo bufferInfo;
+ bgBitmap.Lock(bufferInfo, INFINITE);
+ bgBitmap.Unlock();
+ Canvas mainCanvas;
+ mainCanvas.Construct(bufferInfo);
+ mainCanvas.Clear();
+ mainCanvas.DrawBitmap(originalBitmapPosition, originalBitmap);
+
+ Bitmap* pMainImage = new (std::nothrow) Bitmap();
+ pMainImage->Construct(mainCanvas,mainCanvas.GetBounds());
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return pMainImage;
+}
+
+IList*
+FileListPresentationModel::GetContentInfoListInDirectoryListN(const IList& contentDirectoryList,
+ ContentType contentType)const
+{
+ AppLogDebug("ENTER");
+ IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+
+ if ((&contentDirectoryList == null) || (contentDirectoryList.GetCount() == 0)
+ || ((contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO) && (contentType != CONTENT_TYPE_ALL)))
+ {
+ AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+ return pContentList;
+ }
+
+ ContentDirectory contentDirectory;
+ IListT<ContentType>* pContentTypeList = new (std::nothrow) ArrayListT<ContentType>();
+ if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_ALL)
+ {
+ pContentTypeList->Add(CONTENT_TYPE_IMAGE);
+ }
+ if (contentType == CONTENT_TYPE_VIDEO || contentType == CONTENT_TYPE_ALL)
+ {
+ pContentTypeList->Add(CONTENT_TYPE_VIDEO);
+ }
+ result r = contentDirectory.Construct(*pContentTypeList);
+ delete pContentTypeList;
+
+ if (r == E_SUCCESS)
+ {
+ int pageNo = SIZE_PAGE_NO;
+ int countPerPage = SIZE_CONUNT_PER_PAGE;
+ String* pContentDirectory = null;
+
+ int loopCount = contentDirectoryList.GetCount();
+ for (int i = 0; i < loopCount; ++i)
+ {
+ IList* pIList = null;
+ pContentDirectory = const_cast<String*>(static_cast<const String*>(contentDirectoryList.GetAt(i)));
+ if (pContentDirectory != null)
+ {
+ pIList = contentDirectory.GetContentDirectoryItemListN(*pContentDirectory, pageNo, countPerPage,
+ CONTENT_INFO_ORDER, SORT_ORDER_NONE);
+
+ if (pIList != null)
+ {
+ pContentList->AddItems(*pIList);
+ }
+ }
+ }
+ }
+ AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+ return pContentList;
+}
+
+String
+FileListPresentationModel::ConvertToAlbumName(const String& targetPath)const
+{
+ AppLogDebug("ENTER");
+ String albumName;
+ if (&targetPath == null || targetPath.GetLength() == 0)
+ {
+ 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");
+ }
+ else if (targetPath == RESERVED_DOWNLOAD_PATH)
+ {
+ 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);
+ albumName = directoryName;
+ }
+
+ return albumName;
+}
+
+AppControlMode
+FileListPresentationModel::GetAppControlMode(void) const
+{
+ AppLogDebug("Enter");
+ AppLogDebug("Exit");
+
+ return __appControlMode;
+}
+
+AppControlMediaType
+FileListPresentationModel::GetAppControlMediaType(void) const
+{
+ AppLogDebug("Enter");
+ AppLogDebug("Exit");
+
+ return __appControlMediaType;
+}
+
+AppControlSelectionMode
+FileListPresentationModel::GetAppControlSelectionMode(void) const
+{
+ AppLogDebug("Enter");
+ AppLogDebug("Exit");
+
+ return __appControlSelectionMode;
+}
+
+void
+FileListPresentationModel::SetUpdateProgressStatus(const bool status)
+{
+ AppLogDebug("ENTER status = %d",status);
+ __updateProgressStatus = status;
+ AppLogDebug("EXIT");
+}
+
+result
+FileListPresentationModel::RotateImage(const Tizen::Content::ContentId& contentId, RotateMode rotateMode)
+{
+ result r = E_SUCCESS;
+ ImageBuffer rotateBuffer;
+ ImageBuffer* pRotatedBuffer = null;
+ ImageFormat imageFormat;
+ Image img;
+ ContentInfo* cntInfo = __pContentManager->GetContentInfoN(contentId);
+ if (!cntInfo)
+ {
+ return E_FAILURE;
+ }
+ String filePath = cntInfo->GetContentPath();
+ delete cntInfo;
+
+ ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
+ if (contentType == CONTENT_TYPE_VIDEO)
+ {
+ return r;
+ }
+
+ r = img.Construct();
+
+ if (r == E_SUCCESS)
+ {
+ imageFormat = img.GetImageFormat(filePath);
+
+ r = rotateBuffer.Construct(filePath);
+ if (r == E_SUCCESS)
+ {
+ if (rotateMode == ROTATE_MODE_RIGHT)
+ {
+ pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_90);
+ }
+ else
+ {
+ pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_270);
+ }
+ }
+
+ if (pRotatedBuffer != null)
+ {
+ r = pRotatedBuffer->EncodeToFile(filePath, imageFormat, true, 100);
+ delete pRotatedBuffer;
+ ContentManager::ScanFile(filePath);
+ }
+ }
+
+ return 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
+FileListPresentationModel::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()));
+}