-//\r
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
-//\r
-// Licensed under the Flora License, Version 1.1 (the License);\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-// http://floralicense.org/license/\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an AS IS BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-\r
-/**\r
- * @file: MfFolderEntryDetailPresentationModel.cpp\r
- * @brief: This file contains the implementation of class FolderEntryDetailPresentationModel,\r
- * which acts as a manager for providing file or folder specific information.\r
- */\r
-\r
-#include "MfFolderEntryDetailPresentationModel.h"\r
-\r
-using namespace Tizen::App;\r
-using namespace Tizen::Base;\r
-using namespace Tizen::Base::Utility;\r
-using namespace Tizen::Content;\r
-using namespace Tizen::Io;\r
-\r
-FolderEntryDetailPresentationModel::FolderEntryDetailPresentationModel(void)\r
-{\r
- __noOfFiles = 0;\r
- __noOfFolders = 0;\r
- __directorySize = 0;\r
-}\r
-\r
-FolderEntryDetailPresentationModel::~FolderEntryDetailPresentationModel(void)\r
-{\r
- //empty Implementation\r
-}\r
-\r
-FolderEntryDetailPresentationModel&\r
-FolderEntryDetailPresentationModel::operator =(const FolderEntryDetailPresentationModel& mediaUtility)\r
-{\r
- return *this;\r
-}\r
-\r
-FolderEntryDetailPresentationModel::FolderEntryDetailPresentationModel(const FolderEntryDetailPresentationModel&)\r
-{\r
- //empty Implementation\r
-}\r
-\r
-MediaMetaData*\r
-FolderEntryDetailPresentationModel::GetFolderEntryMetaDataN(Tizen::Base::String filePath, FileType fileType)\r
-{\r
- AppLogDebug("Entry");\r
- result r = E_SUCCESS;\r
- MediaMetaData* pMediaMetaData = null;\r
- FolderMediaMetaData* pFolderMediaMetaData = null;\r
- ImageMediaMetaData* pImageMediaMetaData = null;\r
- AudioMediaMetaData* pAudioMediaMetaData = null;\r
- VideoMediaMetaData* pVideoMediaMetaData = null;\r
- OtherMediaMetaData* pOtherMediaMetaData = null;\r
-\r
- __directorySize = 0;\r
- __noOfFiles = 0;\r
- __noOfFolders = 0;\r
-\r
- TryCatch(filePath.GetLength() != 0, r=E_FAILURE,"Invalid file path");\r
- r = GetMetaData(filePath);\r
-\r
- __directorySize = GetFileSize(filePath);\r
- if (r == E_SUCCESS)\r
- {\r
- if (fileType == FILE_TYPE_FOLDER_TYPE)\r
- {\r
- pFolderMediaMetaData = new (std::nothrow) FolderMediaMetaData();\r
- TryCatch(pFolderMediaMetaData != null, , "Failed to allocate Memory to pFolderMediaMetaData");\r
- pFolderMediaMetaData->SetFileName(GetFileName(filePath));\r
- pFolderMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));\r
- pFolderMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));\r
- pFolderMediaMetaData->SetFileSize(__directorySize);\r
- pFolderMediaMetaData->SetNoOfFiles(__noOfFiles);\r
- pFolderMediaMetaData->SetNoOfFolders(__noOfFolders);\r
- pMediaMetaData = pFolderMediaMetaData;\r
- }\r
- else if (fileType == FILE_TYPE_IMAGE_TYPE)\r
- {\r
- pImageMediaMetaData = new (std::nothrow) ImageMediaMetaData();\r
- TryCatch(pImageMediaMetaData != null, , "Failed to allocate Memory to pImageMediaMetaData");\r
- pImageMediaMetaData->SetFileName(GetFileName(filePath));\r
- pImageMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));\r
- pImageMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));\r
- pImageMediaMetaData->SetFileSize(__directorySize);\r
- pImageMediaMetaData->SetFileFormat(GetFileFormat(filePath));\r
- pImageMediaMetaData->SetFileResolution(GetFileResolution(filePath, fileType));\r
- pMediaMetaData = pImageMediaMetaData;\r
- }\r
- else if (fileType == FILE_TYPE_AUDIO_TYPE)\r
- {\r
- pAudioMediaMetaData = new (std::nothrow) AudioMediaMetaData();\r
- TryCatch(pAudioMediaMetaData != null, , "Failed to allocate Memory to pAudioMediaMetaData");\r
- pAudioMediaMetaData->SetFileName(GetFileName(filePath));\r
- pAudioMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));\r
- pAudioMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));\r
- pAudioMediaMetaData->SetFileSize(__directorySize);\r
- pAudioMediaMetaData->SetFileFormat(GetFileFormat(filePath));\r
- pMediaMetaData = pAudioMediaMetaData;\r
- }\r
- else if (fileType == FILE_TYPE_VIDEO_TYPE)\r
- {\r
- pVideoMediaMetaData = new (std::nothrow) VideoMediaMetaData();\r
- TryCatch(pVideoMediaMetaData != null, , "Failed to allocate Memory to pVideoMediaMetaData");\r
- pVideoMediaMetaData->SetFileName(GetFileName(filePath));\r
- pVideoMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));\r
- pVideoMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));\r
- pVideoMediaMetaData->SetFileSize(__directorySize);\r
- pVideoMediaMetaData->SetFileFormat(GetFileFormat(filePath));\r
- pVideoMediaMetaData->SetFileResolution(GetFileResolution(filePath, fileType));\r
- pMediaMetaData = pVideoMediaMetaData;\r
- }\r
- else if (fileType == FILE_TYPE_OTHER_TYPE)\r
- {\r
- pOtherMediaMetaData = new (std::nothrow) OtherMediaMetaData();\r
- TryCatch(pOtherMediaMetaData != null, , "Failed to allocate Memory to pOtherMediaMetaData");\r
- pOtherMediaMetaData->SetFileName(GetFileName(filePath));\r
- pOtherMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));\r
- pOtherMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));\r
- pOtherMediaMetaData->SetFileSize(__directorySize);\r
- pOtherMediaMetaData->SetFileFormat(GetFileFormat(filePath));\r
- pMediaMetaData = pOtherMediaMetaData;\r
- }\r
-\r
- AppLogDebug("Exit %s", GetErrorMessage(r));\r
- return pMediaMetaData;\r
- }\r
- else\r
- {\r
- AppLogDebug("Exit %s", GetErrorMessage(r));\r
- return null;\r
- }\r
-\r
-CATCH:\r
-\r
- AppLogDebug("Exit %s", GetErrorMessage(GetLastResult()));\r
- return null;\r
-}\r
-\r
-Tizen::Base::String*\r
-FolderEntryDetailPresentationModel::GetFileName(const Tizen::Base::String& filePath)\r
-{\r
- AppLogDebug("Entry");\r
- String delim(L"/");\r
- String token;\r
- String* pFileName = null;\r
- StringTokenizer strTok(filePath, delim);\r
- result r = E_SUCCESS;\r
-\r
- String displayPhone;\r
- String displaySdCard;\r
- String defMediaPath = BasePresentationModel::GetMediaPath();\r
- String defSdCardPath = BasePresentationModel::GetSdCardPath();\r
-\r
- AppResource* pAppResource = null;\r
-\r
- pAppResource = UiApp::GetInstance()->GetAppResource();\r
-\r
- if (pAppResource != null)\r
- {\r
- pAppResource->GetString(L"IDS_MF_TAB_PHONE", displayPhone);\r
- pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", displaySdCard);\r
-\r
- displayPhone.Append("/");\r
- displaySdCard.Append("/");\r
- }\r
-\r
- if(filePath == defMediaPath)\r
- {\r
- token = displayPhone;\r
- token.Remove(token.GetLength()-1,1);\r
- }\r
- else if(filePath == defSdCardPath)\r
- {\r
- token = displaySdCard;\r
- token.Remove(token.GetLength()-1,1);\r
- }\r
- else\r
- {\r
- while (strTok.HasMoreTokens())\r
- {\r
- strTok.GetNextToken(token);\r
- }\r
- }\r
-\r
- pFileName = new (std::nothrow) String;\r
- pFileName->Append(token);\r
- AppLogDebug("Exit %s", GetErrorMessage(r));\r
- return pFileName;\r
-}\r
-\r
-String*\r
-FolderEntryDetailPresentationModel::GetFileDisplayPath(const Tizen::Base::String& filePath)\r
-{\r
- AppLogDebug("Entry");\r
- String previousParentPath(L"");\r
- String fileDisplayPath;\r
- String delim(L"/");\r
- String token(L"");\r
- String *pParentPath;\r
-\r
- String displayPhone;\r
- String displaySdCard;\r
- String defMediaPath = BasePresentationModel::GetMediaPath();\r
- String defSdCardPath = BasePresentationModel::GetSdCardPath();\r
-\r
- result r = E_SUCCESS;\r
- FileAttributes fileAttrib;\r
-\r
- r = File::GetAttributes(filePath, fileAttrib);\r
-\r
- AppResource* pAppResource = null;\r
-\r
- pAppResource = UiApp::GetInstance()->GetAppResource();\r
-\r
- if (pAppResource != null)\r
- {\r
- pAppResource->GetString(L"IDS_MF_TAB_PHONE", displayPhone);\r
- pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", displaySdCard);\r
-\r
-\r
- }\r
-\r
- if (filePath.Equals(BasePresentationModel::GetMediaPath(), false))\r
- {\r
- AppLogDebug("path sent is root path hence return");\r
- pParentPath = new (std::nothrow) String(displayPhone);\r
- return pParentPath;\r
- }\r
- else if(filePath.Equals(BasePresentationModel::GetSdCardPath(), false))\r
- {\r
- pParentPath = new (std::nothrow) String(displaySdCard);\r
- return pParentPath;\r
- }\r
- else\r
- {\r
- displayPhone.Append("/");\r
- displaySdCard.Append("/");\r
-\r
- StringTokenizer strTok(filePath, delim);\r
- while (strTok.HasMoreTokens())\r
- {\r
- strTok.GetNextToken(token);\r
- previousParentPath.Append(L"/");\r
- previousParentPath.Append(token);\r
-\r
- if (!fileAttrib.IsDirectory())\r
- {\r
- if (strTok.GetTokenCount() == 1 ||\r
- token.Equals(BasePresentationModel::GetMediaPath(), false) ||\r
- token.Equals(BasePresentationModel::GetSdCardPath(), false) ||\r
- token.Equals(BasePresentationModel::GetUsbPath(), false))\r
- {\r
- break;\r
- }\r
- }\r
- /*if (strTok.GetTokenCount() == 1 ||\r
- token.Equals(BasePresentationModel::GetMediaPath(), false) ||\r
- token.Equals(BasePresentationModel::GetSdCardPath(), false) ||\r
- token.Equals(BasePresentationModel::GetUsbPath(), false))\r
- {\r
- break;\r
- }*/\r
- }\r
- previousParentPath.Append(L"/");\r
- fileDisplayPath = previousParentPath;\r
-\r
- if (fileDisplayPath.IsEmpty() == false)\r
- {\r
- if (fileDisplayPath.StartsWith(defMediaPath, 0))\r
- {\r
- fileDisplayPath.Replace(defMediaPath, displayPhone);\r
- }\r
- else if (fileDisplayPath.StartsWith(defSdCardPath, 0))\r
- {\r
- fileDisplayPath.Replace(defSdCardPath, displaySdCard);\r
- }\r
- }\r
- //previousParentPath.Append(L"/");\r
- AppLogDebug("Display path is %ls",fileDisplayPath.GetPointer());\r
- fileDisplayPath.Remove(fileDisplayPath.GetLength()-1,1);\r
- pParentPath = new (std::nothrow) String(fileDisplayPath);\r
- AppLogDebug("Exit %s", GetErrorMessage(GetLastResult()));\r
- return pParentPath;\r
- }\r
-}\r
-\r
-long long int\r
-FolderEntryDetailPresentationModel::GetFileSize(const Tizen::Base::String& filePath)\r
-{\r
- AppLogDebug("Entry");\r
- result r = E_SUCCESS;\r
- Directory* pDirectory = null;\r
- DirEnumerator* pDirectoryEnum = null;\r
- FileAttributes fileAttrib;\r
-\r
- TryCatch(filePath.GetLength() != 0, r=E_FAILURE,"Invalid file path");\r
- r = File::GetAttributes(filePath, fileAttrib);\r
- TryCatch(r==E_SUCCESS,,"Failed to get folderentry attributes");\r
-\r
- if (fileAttrib.IsDirectory())\r
- {\r
- pDirectory = new (std::nothrow) Directory();\r
- TryCatch(pDirectory != null, , "Failed to allocate Memory to pDirectory");\r
- TryCatch(filePath.GetLength() != 0, , "Filepath is empty");\r
-\r
- r = pDirectory->Construct(filePath);\r
-\r
- pDirectoryEnum = pDirectory->ReadN();\r
-\r
- if (pDirectoryEnum != null)\r
- {\r
- while (pDirectoryEnum->MoveNext() == E_SUCCESS)\r
- {\r
- DirEntry entry = pDirectoryEnum->GetCurrentDirEntry();\r
- if (entry.GetName() != "." && entry.GetName() != ".." && entry.GetName() != ".emptydir" && entry.GetName() != ".tmp" && entry.GetName() != ".gitignore")\r
- {\r
- String str = entry.GetName();\r
- String fullpath = filePath + L"/" + str;\r
-\r
- r = File::GetAttributes(fullpath, fileAttrib);\r
- TryCatch(r==E_SUCCESS,,"Failed to get folderEntry attributes");\r
-\r
- __directorySize = __directorySize + fileAttrib.GetFileSize();\r
-\r
- if (fileAttrib.IsDirectory())\r
- {\r
- GetFileSize(fullpath); ///recursivley calling the function getMetaData\r
- }\r
- }\r
- }\r
- delete pDirectoryEnum;\r
- pDirectoryEnum = null;\r
- }\r
- delete pDirectory;\r
- pDirectory = null;\r
- }\r
- else\r
- {\r
- __directorySize = fileAttrib.GetFileSize();\r
- }\r
- AppLogDebug("Exit %s", GetErrorMessage(r));\r
- return __directorySize;\r
-\r
-CATCH:\r
- if (pDirectoryEnum != null)\r
- {\r
- delete pDirectoryEnum;\r
- pDirectoryEnum = null;\r
- }\r
- if (pDirectory != null)\r
- {\r
- delete pDirectory;\r
- pDirectory = null;\r
- }\r
- AppLogDebug("Exit %s", GetErrorMessage(r));\r
- return 0;\r
-\r
-}\r
-\r
-Tizen::Base::DateTime\r
-FolderEntryDetailPresentationModel::GetFileCreationTime(const Tizen::Base::String& filePath)\r
-{\r
- AppLogDebug("Entry");\r
- result r = E_SUCCESS;\r
- ///create an instance of fileAttribute\r
- DateTime fileCreationTime;\r
- FileAttributes fileAttrib;\r
-\r
- TryCatch(filePath.GetLength() != 0, r=E_FAILURE,"Invalid file path");\r
- r = File::GetAttributes(filePath, fileAttrib);\r
- TryCatch(r==E_SUCCESS,,"Failed to get folderentry attributes");\r
-\r
- fileCreationTime = fileAttrib.GetDateTime();\r
-\r
- AppLogDebug("Exit");\r
-\r
-CATCH:\r
- return fileCreationTime;\r
-}\r
-\r
-int\r
-FolderEntryDetailPresentationModel::GetFileCount(const Tizen::Base::String& filePath)\r
-{\r
- return __noOfFiles;\r
-}\r
-\r
-int\r
-FolderEntryDetailPresentationModel::GetFolderCount(const Tizen::Base::String& filePath)\r
-{\r
- return __noOfFolders;\r
-}\r
-\r
-result\r
-FolderEntryDetailPresentationModel::GetMetaData(const Tizen::Base::String filePath)\r
-{\r
- AppLogDebug("Entry");\r
- result r = E_SUCCESS;\r
- Directory* pDirectory = null;\r
- FileAttributes fileAttrib;\r
-\r
- TryCatch(filePath.GetLength() != 0, r=E_FAILURE,"Invalid file path");\r
- r = File::GetAttributes(filePath, fileAttrib);\r
- TryCatch(r==E_SUCCESS,,"Failed to get folderentry attributes");\r
-\r
- if (fileAttrib.IsDirectory())\r
- {\r
- pDirectory = new (std::nothrow) Directory();\r
- TryCatch(pDirectory != null, , "Failed to allocate Memory to pDirectory");\r
-\r
- DirEnumerator* pDirectoryEnum = null;\r
-\r
- r = pDirectory->Construct(filePath);\r
-\r
- pDirectoryEnum = pDirectory->ReadN();\r
-\r
- if (pDirectoryEnum != null)\r
- {\r
- while (pDirectoryEnum->MoveNext() == E_SUCCESS)\r
- {\r
- DirEntry entry = pDirectoryEnum->GetCurrentDirEntry();\r
- if (entry.GetName() != "." && entry.GetName() != ".." && entry.GetName() != ".emptydir" && entry.GetName() != ".tmp" && entry.GetName() != ".gitignore")\r
- {\r
-\r
- String str = entry.GetName();\r
- String fullpath = filePath + L"/" + str;\r
-\r
- r = File::GetAttributes(fullpath, fileAttrib);\r
-\r
- //__directorySize = __directorySize + fileAttrib.GetFileSize();\r
-\r
- if (fileAttrib.IsDirectory())\r
- {\r
- __noOfFolders = __noOfFolders + 1; ///increase the number of folders if current file is a directory\r
- }\r
- else\r
- {\r
-\r
- __noOfFiles++;\r
- }\r
-\r
- }\r
- }\r
-\r
-\r
- //if (pDirectoryEnum != null)\r
- //{\r
- delete pDirectoryEnum;\r
- pDirectoryEnum = null;\r
- //}\r
- }\r
- //if (pDirectory != null)\r
- //{\r
- delete pDirectory;\r
- pDirectory = null;\r
- //}\r
- }\r
- /*else\r
- {\r
- __directorySize = fileAttrib.GetFileSize();\r
- }*/\r
-\r
- AppLogDebug("Exit %s", GetErrorMessage(r));\r
- return r;\r
-\r
-CATCH:\r
- AppLogDebug("Exit %s", GetErrorMessage(r));\r
- return r;\r
-}\r
-\r
-Tizen::Base::String*\r
-FolderEntryDetailPresentationModel::GetFileFormat(const Tizen::Base::String& filePath)\r
-{\r
- AppLogDebug("Entry");\r
- String delim(L".");\r
- String* pFileName = null;\r
- pFileName = GetFileName(filePath);\r
- StringTokenizer strTok(*pFileName, delim);\r
- delete pFileName;\r
- String token;\r
- String* pFileFormat;\r
- pFileFormat = null;\r
- if(strTok.GetTokenCount() != 1)\r
- {\r
- while (strTok.HasMoreTokens())\r
- {\r
- strTok.GetNextToken(token);\r
-\r
- }\r
- }\r
- else\r
- {\r
- token.Clear();\r
- token.Append(L"Unknown");\r
- }\r
- pFileFormat = new (std::nothrow) String();\r
- pFileFormat->Append(token);\r
- AppLogDebug("Exit");\r
- return pFileFormat;\r
-}\r
-\r
-Tizen::Base::String*\r
-FolderEntryDetailPresentationModel::GetFileResolution(const Tizen::Base::String& filePath, FileType fileType)\r
-{\r
- AppLogDebug("Entry");\r
- Tizen::Base::String contentPath = filePath;\r
- String* pFileResolution = null;\r
- ImageMetadata* pImgMeta = null;\r
- VideoMetadata* pVideoMeta = null;\r
-\r
- pFileResolution = new (std::nothrow) String();\r
- TryCatch(pFileResolution != null, , "Failed to allocate Memory to pFileResolution");\r
-\r
- switch (fileType)\r
- {\r
- case FILE_TYPE_IMAGE_TYPE:\r
- {\r
- int width;\r
- int height;\r
- pImgMeta = ContentManagerUtil::GetImageMetaN(contentPath);\r
- TryCatch(pImgMeta != null, pFileResolution->Append(L"NOT FOUND");\r
- , "GetImageMetaN failed.");\r
-\r
- width = pImgMeta->GetWidth();\r
- height = pImgMeta->GetHeight();\r
- pFileResolution->Append(width);\r
- pFileResolution->Append(L"x");\r
- pFileResolution->Append(height);\r
-\r
- delete pImgMeta;\r
- //return pFileResolution;\r
-\r
- }\r
- break;\r
-\r
- case FILE_TYPE_VIDEO_TYPE:\r
- {\r
- int width;\r
- int height;\r
- pVideoMeta = ContentManagerUtil::GetVideoMetaN(contentPath);\r
- TryCatch(pVideoMeta != null, pFileResolution->Append(L"NOT FOUND"), "::GetImageMetaN failed.");\r
-\r
- width = pVideoMeta->GetWidth();\r
- height = pVideoMeta->GetHeight();\r
- pFileResolution->Append(width);\r
- pFileResolution->Append(L"x");\r
- pFileResolution->Append(height);\r
-\r
- delete pVideoMeta;\r
- //return pFileResolution;\r
- }\r
- break;\r
-\r
- default:\r
- {\r
- //do nothing\r
- }\r
- break;\r
- }\r
- AppLogDebug("Exit");\r
- return pFileResolution;\r
-\r
-CATCH:\r
- AppLogDebug("Exit");\r
- return pFileResolution;\r
-}\r
+//
+// 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: MfFolderEntryDetailPresentationModel.cpp
+ * @brief: This file contains the implementation of class FolderEntryDetailPresentationModel,
+ * which acts as a manager for providing file or folder specific information.
+ */
+
+#include "MfFolderEntryDetailPresentationModel.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Content;
+using namespace Tizen::Io;
+
+FolderEntryDetailPresentationModel::FolderEntryDetailPresentationModel(void)
+{
+ __noOfFiles = 0;
+ __noOfFolders = 0;
+ __directorySize = 0;
+}
+
+FolderEntryDetailPresentationModel::~FolderEntryDetailPresentationModel(void)
+{
+ //empty Implementation
+}
+
+FolderEntryDetailPresentationModel&
+FolderEntryDetailPresentationModel::operator =(const FolderEntryDetailPresentationModel& mediaUtility)
+{
+ return *this;
+}
+
+FolderEntryDetailPresentationModel::FolderEntryDetailPresentationModel(const FolderEntryDetailPresentationModel&)
+{
+ //empty Implementation
+}
+
+MediaMetaData*
+FolderEntryDetailPresentationModel::GetFolderEntryMetaDataN(Tizen::Base::String filePath, FileType fileType)
+{
+ AppLogDebug("Entry");
+ result r = E_SUCCESS;
+ MediaMetaData* pMediaMetaData = null;
+ FolderMediaMetaData* pFolderMediaMetaData = null;
+ ImageMediaMetaData* pImageMediaMetaData = null;
+ AudioMediaMetaData* pAudioMediaMetaData = null;
+ VideoMediaMetaData* pVideoMediaMetaData = null;
+ OtherMediaMetaData* pOtherMediaMetaData = null;
+
+ __directorySize = 0;
+ __noOfFiles = 0;
+ __noOfFolders = 0;
+
+ TryCatch(filePath.GetLength() != 0, r=E_FAILURE,"Invalid file path");
+ r = GetMetaData(filePath);
+
+ __directorySize = GetFileSize(filePath);
+ if (r == E_SUCCESS)
+ {
+ if (fileType == FILE_TYPE_FOLDER_TYPE)
+ {
+ pFolderMediaMetaData = new (std::nothrow) FolderMediaMetaData();
+ TryCatch(pFolderMediaMetaData != null, , "Failed to allocate Memory to pFolderMediaMetaData");
+ pFolderMediaMetaData->SetFileName(GetFileName(filePath));
+ pFolderMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));
+ pFolderMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));
+ pFolderMediaMetaData->SetFileSize(__directorySize);
+ pFolderMediaMetaData->SetNoOfFiles(__noOfFiles);
+ pFolderMediaMetaData->SetNoOfFolders(__noOfFolders);
+ pMediaMetaData = pFolderMediaMetaData;
+ }
+ else if (fileType == FILE_TYPE_IMAGE_TYPE)
+ {
+ pImageMediaMetaData = new (std::nothrow) ImageMediaMetaData();
+ TryCatch(pImageMediaMetaData != null, , "Failed to allocate Memory to pImageMediaMetaData");
+ pImageMediaMetaData->SetFileName(GetFileName(filePath));
+ pImageMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));
+ pImageMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));
+ pImageMediaMetaData->SetFileSize(__directorySize);
+ pImageMediaMetaData->SetFileFormat(GetFileFormat(filePath));
+ pImageMediaMetaData->SetFileResolution(GetFileResolution(filePath, fileType));
+ pMediaMetaData = pImageMediaMetaData;
+ }
+ else if (fileType == FILE_TYPE_AUDIO_TYPE)
+ {
+ pAudioMediaMetaData = new (std::nothrow) AudioMediaMetaData();
+ TryCatch(pAudioMediaMetaData != null, , "Failed to allocate Memory to pAudioMediaMetaData");
+ pAudioMediaMetaData->SetFileName(GetFileName(filePath));
+ pAudioMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));
+ pAudioMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));
+ pAudioMediaMetaData->SetFileSize(__directorySize);
+ pAudioMediaMetaData->SetFileFormat(GetFileFormat(filePath));
+ pMediaMetaData = pAudioMediaMetaData;
+ }
+ else if (fileType == FILE_TYPE_VIDEO_TYPE)
+ {
+ pVideoMediaMetaData = new (std::nothrow) VideoMediaMetaData();
+ TryCatch(pVideoMediaMetaData != null, , "Failed to allocate Memory to pVideoMediaMetaData");
+ pVideoMediaMetaData->SetFileName(GetFileName(filePath));
+ pVideoMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));
+ pVideoMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));
+ pVideoMediaMetaData->SetFileSize(__directorySize);
+ pVideoMediaMetaData->SetFileFormat(GetFileFormat(filePath));
+ pVideoMediaMetaData->SetFileResolution(GetFileResolution(filePath, fileType));
+ pMediaMetaData = pVideoMediaMetaData;
+ }
+ else if (fileType == FILE_TYPE_OTHER_TYPE)
+ {
+ pOtherMediaMetaData = new (std::nothrow) OtherMediaMetaData();
+ TryCatch(pOtherMediaMetaData != null, , "Failed to allocate Memory to pOtherMediaMetaData");
+ pOtherMediaMetaData->SetFileName(GetFileName(filePath));
+ pOtherMediaMetaData->SetFilePath(GetFileDisplayPath(filePath));
+ pOtherMediaMetaData->SetFileCreationTime(GetFileCreationTime(filePath));
+ pOtherMediaMetaData->SetFileSize(__directorySize);
+ pOtherMediaMetaData->SetFileFormat(GetFileFormat(filePath));
+ pMediaMetaData = pOtherMediaMetaData;
+ }
+
+ AppLogDebug("Exit %s", GetErrorMessage(r));
+ return pMediaMetaData;
+ }
+ else
+ {
+ AppLogDebug("Exit %s", GetErrorMessage(r));
+ return null;
+ }
+
+CATCH:
+
+ AppLogDebug("Exit %s", GetErrorMessage(GetLastResult()));
+ return null;
+}
+
+Tizen::Base::String*
+FolderEntryDetailPresentationModel::GetFileName(const Tizen::Base::String& filePath)
+{
+ AppLogDebug("Entry");
+ String delim(L"/");
+ String token;
+ String* pFileName = null;
+ StringTokenizer strTok(filePath, delim);
+ result r = E_SUCCESS;
+
+ String displayPhone;
+ String displaySdCard;
+ String defMediaPath = BasePresentationModel::GetMediaPath();
+ String defSdCardPath = BasePresentationModel::GetSdCardPath();
+
+ AppResource* pAppResource = null;
+
+ pAppResource = UiApp::GetInstance()->GetAppResource();
+
+ if (pAppResource != null)
+ {
+ pAppResource->GetString(L"IDS_MF_TAB_PHONE", displayPhone);
+ pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", displaySdCard);
+
+ displayPhone.Append("/");
+ displaySdCard.Append("/");
+ }
+
+ if(filePath == defMediaPath)
+ {
+ token = displayPhone;
+ token.Remove(token.GetLength()-1,1);
+ }
+ else if(filePath == defSdCardPath)
+ {
+ token = displaySdCard;
+ token.Remove(token.GetLength()-1,1);
+ }
+ else
+ {
+ while (strTok.HasMoreTokens())
+ {
+ strTok.GetNextToken(token);
+ }
+ }
+
+ pFileName = new (std::nothrow) String;
+ pFileName->Append(token);
+ AppLogDebug("Exit %s", GetErrorMessage(r));
+ return pFileName;
+}
+
+String*
+FolderEntryDetailPresentationModel::GetFileDisplayPath(const Tizen::Base::String& filePath)
+{
+ AppLogDebug("Entry");
+ String previousParentPath(L"");
+ String fileDisplayPath;
+ String delim(L"/");
+ String token(L"");
+ String *pParentPath;
+
+ String displayPhone;
+ String displaySdCard;
+ String defMediaPath = BasePresentationModel::GetMediaPath();
+ String defSdCardPath = BasePresentationModel::GetSdCardPath();
+
+ result r = E_SUCCESS;
+ FileAttributes fileAttrib;
+
+ r = File::GetAttributes(filePath, fileAttrib);
+
+ AppResource* pAppResource = null;
+
+ pAppResource = UiApp::GetInstance()->GetAppResource();
+
+ if (pAppResource != null)
+ {
+ pAppResource->GetString(L"IDS_MF_TAB_PHONE", displayPhone);
+ pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", displaySdCard);
+
+
+ }
+
+ if (filePath.Equals(BasePresentationModel::GetMediaPath(), false))
+ {
+ AppLogDebug("path sent is root path hence return");
+ pParentPath = new (std::nothrow) String(displayPhone);
+ return pParentPath;
+ }
+ else if(filePath.Equals(BasePresentationModel::GetSdCardPath(), false))
+ {
+ pParentPath = new (std::nothrow) String(displaySdCard);
+ return pParentPath;
+ }
+ else
+ {
+ displayPhone.Append("/");
+ displaySdCard.Append("/");
+
+ StringTokenizer strTok(filePath, delim);
+ while (strTok.HasMoreTokens())
+ {
+ strTok.GetNextToken(token);
+ previousParentPath.Append(L"/");
+ previousParentPath.Append(token);
+
+ if (!fileAttrib.IsDirectory())
+ {
+ if (strTok.GetTokenCount() == 1 ||
+ token.Equals(BasePresentationModel::GetMediaPath(), false) ||
+ token.Equals(BasePresentationModel::GetSdCardPath(), false) ||
+ token.Equals(BasePresentationModel::GetUsbPath(), false))
+ {
+ break;
+ }
+ }
+ /*if (strTok.GetTokenCount() == 1 ||
+ token.Equals(BasePresentationModel::GetMediaPath(), false) ||
+ token.Equals(BasePresentationModel::GetSdCardPath(), false) ||
+ token.Equals(BasePresentationModel::GetUsbPath(), false))
+ {
+ break;
+ }*/
+ }
+ previousParentPath.Append(L"/");
+ fileDisplayPath = previousParentPath;
+
+ if (fileDisplayPath.IsEmpty() == false)
+ {
+ if (fileDisplayPath.StartsWith(defMediaPath, 0))
+ {
+ fileDisplayPath.Replace(defMediaPath, displayPhone);
+ }
+ else if (fileDisplayPath.StartsWith(defSdCardPath, 0))
+ {
+ fileDisplayPath.Replace(defSdCardPath, displaySdCard);
+ }
+ }
+ //previousParentPath.Append(L"/");
+ AppLogDebug("Display path is %ls",fileDisplayPath.GetPointer());
+ fileDisplayPath.Remove(fileDisplayPath.GetLength()-1,1);
+ pParentPath = new (std::nothrow) String(fileDisplayPath);
+ AppLogDebug("Exit %s", GetErrorMessage(GetLastResult()));
+ return pParentPath;
+ }
+}
+
+long long int
+FolderEntryDetailPresentationModel::GetFileSize(const Tizen::Base::String& filePath)
+{
+ AppLogDebug("Entry");
+ result r = E_SUCCESS;
+ Directory* pDirectory = null;
+ DirEnumerator* pDirectoryEnum = null;
+ FileAttributes fileAttrib;
+
+ TryCatch(filePath.GetLength() != 0, r=E_FAILURE,"Invalid file path");
+ r = File::GetAttributes(filePath, fileAttrib);
+ TryCatch(r==E_SUCCESS,,"Failed to get folderentry attributes");
+
+ if (fileAttrib.IsDirectory())
+ {
+ pDirectory = new (std::nothrow) Directory();
+ TryCatch(pDirectory != null, , "Failed to allocate Memory to pDirectory");
+ TryCatch(filePath.GetLength() != 0, , "Filepath is empty");
+
+ r = pDirectory->Construct(filePath);
+
+ pDirectoryEnum = pDirectory->ReadN();
+
+ if (pDirectoryEnum != null)
+ {
+ while (pDirectoryEnum->MoveNext() == E_SUCCESS)
+ {
+ DirEntry entry = pDirectoryEnum->GetCurrentDirEntry();
+ if (entry.GetName() != "." && entry.GetName() != ".." && entry.GetName() != ".emptydir" && entry.GetName() != ".tmp" && entry.GetName() != ".gitignore")
+ {
+ String str = entry.GetName();
+ String fullpath = filePath + L"/" + str;
+
+ r = File::GetAttributes(fullpath, fileAttrib);
+ TryCatch(r==E_SUCCESS,,"Failed to get folderEntry attributes");
+
+
+
+ if (fileAttrib.IsDirectory())
+ {
+ GetFileSize(fullpath); ///recursivley calling the function getMetaData
+ }
+ else
+ {
+ __directorySize = __directorySize + fileAttrib.GetFileSize();
+ }
+ }
+ }
+ delete pDirectoryEnum;
+ pDirectoryEnum = null;
+ }
+ delete pDirectory;
+ pDirectory = null;
+ }
+ else
+ {
+ __directorySize = fileAttrib.GetFileSize();
+ }
+ AppLogDebug("Exit %s", GetErrorMessage(r));
+ return __directorySize;
+
+CATCH:
+ if (pDirectoryEnum != null)
+ {
+ delete pDirectoryEnum;
+ pDirectoryEnum = null;
+ }
+ if (pDirectory != null)
+ {
+ delete pDirectory;
+ pDirectory = null;
+ }
+ AppLogDebug("Exit %s", GetErrorMessage(r));
+ return 0;
+
+}
+
+Tizen::Base::DateTime
+FolderEntryDetailPresentationModel::GetFileCreationTime(const Tizen::Base::String& filePath)
+{
+ AppLogDebug("Entry");
+ result r = E_SUCCESS;
+ ///create an instance of fileAttribute
+ DateTime fileCreationTime;
+ FileAttributes fileAttrib;
+
+ TryCatch(filePath.GetLength() != 0, r=E_FAILURE,"Invalid file path");
+ r = File::GetAttributes(filePath, fileAttrib);
+ TryCatch(r==E_SUCCESS,,"Failed to get folderentry attributes");
+
+ fileCreationTime = fileAttrib.GetDateTime();
+
+ AppLogDebug("Exit");
+
+CATCH:
+ return fileCreationTime;
+}
+
+int
+FolderEntryDetailPresentationModel::GetFileCount(const Tizen::Base::String& filePath)
+{
+ return __noOfFiles;
+}
+
+int
+FolderEntryDetailPresentationModel::GetFolderCount(const Tizen::Base::String& filePath)
+{
+ return __noOfFolders;
+}
+
+result
+FolderEntryDetailPresentationModel::GetMetaData(const Tizen::Base::String filePath)
+{
+ AppLogDebug("Entry");
+ result r = E_SUCCESS;
+ Directory* pDirectory = null;
+ FileAttributes fileAttrib;
+
+ TryCatch(filePath.GetLength() != 0, r=E_FAILURE,"Invalid file path");
+ r = File::GetAttributes(filePath, fileAttrib);
+ TryCatch(r==E_SUCCESS,,"Failed to get folderentry attributes");
+
+ if (fileAttrib.IsDirectory())
+ {
+ pDirectory = new (std::nothrow) Directory();
+ TryCatch(pDirectory != null, , "Failed to allocate Memory to pDirectory");
+
+ DirEnumerator* pDirectoryEnum = null;
+
+ r = pDirectory->Construct(filePath);
+
+ pDirectoryEnum = pDirectory->ReadN();
+
+ if (pDirectoryEnum != null)
+ {
+ while (pDirectoryEnum->MoveNext() == E_SUCCESS)
+ {
+ DirEntry entry = pDirectoryEnum->GetCurrentDirEntry();
+ if (entry.GetName() != "." && entry.GetName() != ".." && entry.GetName() != ".emptydir" && entry.GetName() != ".tmp" && entry.GetName() != ".gitignore")
+ {
+
+ String str = entry.GetName();
+ String fullpath = filePath + L"/" + str;
+
+ r = File::GetAttributes(fullpath, fileAttrib);
+
+ //__directorySize = __directorySize + fileAttrib.GetFileSize();
+
+ if (fileAttrib.IsDirectory())
+ {
+ __noOfFolders = __noOfFolders + 1; ///increase the number of folders if current file is a directory
+ }
+ else
+ {
+
+ __noOfFiles++;
+ }
+
+ }
+ }
+
+
+ //if (pDirectoryEnum != null)
+ //{
+ delete pDirectoryEnum;
+ pDirectoryEnum = null;
+ //}
+ }
+ //if (pDirectory != null)
+ //{
+ delete pDirectory;
+ pDirectory = null;
+ //}
+ }
+ /*else
+ {
+ __directorySize = fileAttrib.GetFileSize();
+ }*/
+
+ AppLogDebug("Exit %s", GetErrorMessage(r));
+ return r;
+
+CATCH:
+ AppLogDebug("Exit %s", GetErrorMessage(r));
+ return r;
+}
+
+Tizen::Base::String*
+FolderEntryDetailPresentationModel::GetFileFormat(const Tizen::Base::String& filePath)
+{
+ AppLogDebug("Entry");
+ String delim(L".");
+ String* pFileName = null;
+ pFileName = GetFileName(filePath);
+ StringTokenizer strTok(*pFileName, delim);
+ delete pFileName;
+ String token;
+ String* pFileFormat;
+ pFileFormat = null;
+ if(strTok.GetTokenCount() != 1)
+ {
+ while (strTok.HasMoreTokens())
+ {
+ strTok.GetNextToken(token);
+
+ }
+ }
+ else
+ {
+ token.Clear();
+ token.Append(L"Unknown");
+ }
+ pFileFormat = new (std::nothrow) String();
+ pFileFormat->Append(token);
+ AppLogDebug("Exit");
+ return pFileFormat;
+}
+
+Tizen::Base::String*
+FolderEntryDetailPresentationModel::GetFileResolution(const Tizen::Base::String& filePath, FileType fileType)
+{
+ AppLogDebug("Entry");
+ Tizen::Base::String contentPath = filePath;
+ String* pFileResolution = null;
+ ImageMetadata* pImgMeta = null;
+ VideoMetadata* pVideoMeta = null;
+
+ pFileResolution = new (std::nothrow) String();
+ TryCatch(pFileResolution != null, , "Failed to allocate Memory to pFileResolution");
+
+ switch (fileType)
+ {
+ case FILE_TYPE_IMAGE_TYPE:
+ {
+ int width;
+ int height;
+ pImgMeta = ContentManagerUtil::GetImageMetaN(contentPath);
+ TryCatch(pImgMeta != null, pFileResolution->Append(L"NOT FOUND");
+ , "GetImageMetaN failed.");
+
+ width = pImgMeta->GetWidth();
+ height = pImgMeta->GetHeight();
+ pFileResolution->Append(width);
+ pFileResolution->Append(L"x");
+ pFileResolution->Append(height);
+
+ delete pImgMeta;
+ //return pFileResolution;
+
+ }
+ break;
+
+ case FILE_TYPE_VIDEO_TYPE:
+ {
+ int width;
+ int height;
+ pVideoMeta = ContentManagerUtil::GetVideoMetaN(contentPath);
+ TryCatch(pVideoMeta != null, pFileResolution->Append(L"NOT FOUND"), "::GetImageMetaN failed.");
+
+ width = pVideoMeta->GetWidth();
+ height = pVideoMeta->GetHeight();
+ pFileResolution->Append(width);
+ pFileResolution->Append(L"x");
+ pFileResolution->Append(height);
+
+ delete pVideoMeta;
+ //return pFileResolution;
+ }
+ break;
+
+ default:
+ {
+ //do nothing
+ }
+ break;
+ }
+ AppLogDebug("Exit");
+ return pFileResolution;
+
+CATCH:
+ AppLogDebug("Exit");
+ return pFileResolution;
+}