2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file: MfFolderEntryPresentationModel.cpp
19 * @brief: This model is responsible for getting the details of any Directory/File entries in the
20 * file system. Constructs the structure which contains basic information of these entries.
28 #include "MfFolderEntryDetailPresentationModel.h"
29 #include "MfFolderEntryPresentationModel.h"
30 #include "MfFolderEntriesComparer.h"
31 #include "MfFolderNavigationPresentationModel.h"
32 #include "MfMediaMetaData.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Utility;
39 using namespace Tizen::Content;
40 using namespace Tizen::Io;
41 using namespace Tizen::Locales;
42 using namespace Tizen::System;
43 using namespace Tizen::Ui;
44 using namespace Tizen::Graphics;
47 static const int INVALID_INDEX = -1;
48 IFolderEntryEventListener* FolderEntryPresentationModel::__pFolderEntryEventListener = null;
49 //! Constructor for the FileListPresentationModel class
51 FolderEntryPresentationModel::FolderEntryPresentationModel(void)
52 : __requestId(INVALID_INDEX)
55 , __ThumbnailRequestInProgress(false)
56 , __currentViewType(APPCONTROL_VIEW_DEFAULT)
57 , __sourceForm(CREATE_ITEM_SOURCE_NONE)
58 , __entryType(FILE_TYPE_ALL)
59 , __pFolderEntries(null)
60 , __pFileEventManager(null)
61 , __pThumbnailManager(null)
62 , __pFolderEntryStack(null)
64 //empty implementation
68 FolderEntryPresentationModel::Construct(void)
74 __currentRequestId = 0;
75 __deviceListCount = 1;
77 __pFileEventManager = new (std::nothrow) FileEventManager();
78 r = __pFileEventManager->Construct(*this);
80 __pFolderEntries = new (std::nothrow) ArrayList();
81 r = __pFolderEntries->Construct();
84 __pThumbnailManager = ThumbnailManager::GetInstance();
85 __pCacheManager = CacheManager::GetInstance();
87 AppLogDebug("Exit %s", GetErrorMessage(r));
91 //! Destructor for the FileListPresentationModel class
92 FolderEntryPresentationModel::~FolderEntryPresentationModel(void)
94 if (__pFolderEntries != null)
96 __pFolderEntries->RemoveAll(true);
97 delete __pFolderEntries;
99 if (__pThumbnailManager)
101 __requestId = INVALID_INDEX;
103 if (__pFileEventManager != null)
105 delete __pFileEventManager;
106 __pFileEventManager = null;
108 if (__pFolderEntryStack != null)
110 __pFolderEntryStack->RemoveAll(true);
111 delete __pFolderEntryStack;
115 //!Copy Constructor for the FileListPresentationModel class
116 FolderEntryPresentationModel::FolderEntryPresentationModel(const FolderEntryPresentationModel& content)
118 //empty Implementation
121 /*!Overloaded assignment operator for the FileListPresentationModel class.
123 FolderEntryPresentationModel&
124 FolderEntryPresentationModel::operator =(const FolderEntryPresentationModel& source)
129 /*! This function is responsible for constructing the arraylist which contains
130 * list of all the directory entries in the given path.
131 * Returns the constructed arraylist from the function.
134 FolderEntryPresentationModel::CreateFolderEntryList(const String& directoryName, int index)
136 AppLogDebug("Entry");
137 result r = E_SUCCESS;
138 DirectoryEntry* pName = null;
139 DirectoryEntry* pSource = null;
140 DirectoryEntry* pDestination = null;
143 int currentDirectoryCount = 0; //To keep track of the number of directories in the given path
144 int currentFileCount = 0; // To keep track of the number of files in the given path
145 int swapIndex = 0; //This is used to store the position where the next swap operation should be done
147 //Check whether the directory path is valid or not. If not then return null from the method.
148 if (directoryName.IsEmpty() || !directoryName.StartsWith(L"/", 0))
150 if (__pFolderEntries != null)
152 __pFolderEntries->RemoveAll(true);
153 delete __pFolderEntries;
154 __pFolderEntries = null;
159 //!This call is to construct the directory list of the given path.
160 r = MakeFolderEntryList(directoryName, index);
161 TryCatch(r == E_SUCCESS, , "construct directory failed");
163 if (__sourceForm == CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
165 AppLogDebug("returning after adding to list");
168 // After constructing the arraylist, the directoryCount, fileCount entries have to be updated.
169 // To update these values, call ConstructDirectoryEntryListN for the entries which are directory.
170 for (int fileEntriesCount = 0; fileEntriesCount < __pFolderEntries->GetCount(); fileEntriesCount++) // Start of Directory and File Count loop
172 currentDirectoryCount = 0;
173 currentFileCount = 0;
175 pName = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(fileEntriesCount));
176 TryCatch(pName != null, , "Failed to get entry");
177 fileFullName = pName->GetFullFilePath();
178 pName->SetDirectoryCount(0);
179 pName->SetFilecount(0);
181 //Only if the current entry is a directory we have to update DrirectoryCount and filecount.
182 // If its a file then these entries will be set to 0.
184 if (pName->IsDirectory())
186 GetFolderEntryCount(fileFullName, currentDirectoryCount, currentFileCount);
187 pName->SetDirectoryCount(currentDirectoryCount);
188 pName->SetFilecount(currentFileCount);
192 pName->SetDirectoryCount(0);
193 pName->SetFilecount(0);
196 // Once the arraylist for the given path is constructed, the entries which are directory should be in the top of the list.
197 // List is sorted so that Directory entries will be in the top of the list and file entries after this.
199 swapIndex = GetSwapIndex(); // The slot number is updated for the next swap operation
201 pSource = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(fileEntriesCount));
202 TryCatch(pSource != null, , "Failed to get entry");
205 // Swapping should be done only if the entry is a directory
206 if (pSource->IsDirectory())
208 if (swapIndex != INVALID_INDEX)
210 pDestination = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(swapIndex)); //This contains the index where the first non directory entry is present.
211 TryCatch(pDestination != null, , "Failed to get entry");
212 //Swapping will be done based on the slot number. The slot number is the first location where the non directory entry is present
213 SwapFolderEntries(*pSource, *pDestination);
217 } // End of Directory and File Count loop
219 if (__enableSort == true)
223 AppLogDebug("Exit %s", GetErrorMessage(r));
226 AppLogDebug("Exit %s", GetErrorMessage(r));
227 if (__pFolderEntries != null)
229 __pFolderEntries->RemoveAll(true);
234 FolderEntryPresentationModel::MakeFolderEntryList(const String& directoryName, int index)
236 AppLogDebug("Entry");
237 int fileExtensionLength = 0;
240 result r = E_SUCCESS;
241 Directory* pDirectory = null; //! Stores the newly constructed Directory entry
242 DirEnumerator* pDirectoryEnum = null; //! Directory Enumerator for the newly created Directory entry
243 ContentType contentType = CONTENT_TYPE_UNKNOWN;
245 pDirectory = new (std::nothrow) Directory();
246 r = pDirectory->Construct(directoryName);
247 AppLogDebug("dir construct result is %s",GetErrorMessage(r));
254 pDirectoryEnum = pDirectory->ReadN();
256 //Add all the directory entries in the given path to arraylist.
257 //Traverse the Directory Enumerator to find all the entries in the given Directory path
259 while (pDirectoryEnum->MoveNext() == E_SUCCESS)
261 DirEntry entryName = pDirectoryEnum->GetCurrentDirEntry();
263 //! Some of the default files like "." , "..", hidden files should not be added to the list.
264 if (!(entryName.GetName().StartsWith(L".", 0)) && !entryName.IsHidden())
266 //! Add the DirectoryStructure object to the arraylist for each directory entry in the path
267 DirectoryEntry* pCurrentFolderEntry = new (std::nothrow) DirectoryEntry();
269 entryValue = entryName.GetName();
272 fullpath = directoryName + entryValue;
274 // If the entry is a direcotry then currentDirectoryCount should be incremented.
275 // Else currentFileCount should be incremented.
277 if (entryName.IsDirectory())
279 fullpath.Append(L"/");
283 pCurrentFolderEntry->SetFileExtension(File::GetFileExtension(fullpath));
284 fileExtensionLength = pCurrentFolderEntry->GetFileExtension().GetLength();
285 if(fileExtensionLength != 0)
287 entryValue.Remove(entryValue.GetLength() - fileExtensionLength - 1, fileExtensionLength + 1);
291 pCurrentFolderEntry->SetFullFilePath(fullpath);
292 pCurrentFolderEntry->SetFileName(entryValue);
293 pCurrentFolderEntry->SetCheckDirectory(entryName.IsDirectory());
294 pCurrentFolderEntry->SetCreationTime(entryName.GetDateTime());
296 contentType = ContentManagerUtil::CheckContentType(fullpath);
298 if (!pCurrentFolderEntry->IsDirectory() && __sourceForm != CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
300 if (__entryType == FILE_TYPE_ALL)
302 __pFolderEntries->Add(pCurrentFolderEntry);
304 else if (__entryType == FILE_TYPE_AUDIO_TYPE)
306 if (contentType == CONTENT_TYPE_AUDIO)
308 __pFolderEntries->Add(pCurrentFolderEntry);
312 delete pCurrentFolderEntry;
313 pCurrentFolderEntry = null;
316 else if (__entryType == FILE_TYPE_VIDEO_TYPE)
318 if (contentType == CONTENT_TYPE_VIDEO)
320 __pFolderEntries->Add(pCurrentFolderEntry);
324 delete pCurrentFolderEntry;
325 pCurrentFolderEntry = null;
328 else if (__entryType == FILE_TYPE_IMAGE_TYPE)
330 if (contentType == CONTENT_TYPE_IMAGE)
332 __pFolderEntries->Add(pCurrentFolderEntry);
336 delete pCurrentFolderEntry;
337 pCurrentFolderEntry = null;
340 else if (__entryType == FILE_TYPE_CONTACTS_TYPE)
342 if (fullpath.EndsWith(L"vcs") || fullpath.EndsWith(L"VCS"))
344 __pFolderEntries->Add(pCurrentFolderEntry);
348 delete pCurrentFolderEntry;
349 pCurrentFolderEntry = null;
353 else if (pCurrentFolderEntry->IsDirectory() == true)
355 if (__currentViewType != APPCONTROL_VIEW_IMPORT)
357 __pFolderEntries->InsertAt(pCurrentFolderEntry, index);
363 //if (pDirectory != null)
369 //if (pDirectoryEnum != null)
371 delete pDirectoryEnum;
372 pDirectoryEnum = null;
377 if (pDirectory != null)
383 if (pDirectoryEnum != null)
385 delete pDirectoryEnum;
386 pDirectoryEnum = null;
388 AppLogDebug("Exit:[%s]", GetErrorMessage(r));
389 return r; //! Array list which contains the result value*/
392 /*! Used to swap two DirectoryStructure objects.
393 * Required during sorting elements so that directory will be in the top of arraylist
396 FolderEntryPresentationModel::SwapFolderEntries(DirectoryEntry& source, DirectoryEntry& destination)
398 //Exchange the contents of source object with the destination object
399 DirectoryEntry intermediate;
400 intermediate = source;
401 source = destination;
402 destination = intermediate;
405 /*! Returns the next available position in the list where the swapping should be done.
406 * Scans the list from the start and when any entry which is a file is found, that will be
407 * returned as the available slot. Used during sorting elements.
410 FolderEntryPresentationModel::GetSwapIndex(void)
412 int swapIndex = INVALID_INDEX;
413 DirectoryEntry* pDir = null;
415 for (int entryCount = 0; entryCount < __pFolderEntries->GetCount(); entryCount++)
417 pDir = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(entryCount));
419 // Keep searching till a slot is available.
420 // Slot is the position where the first file entry is present.
421 // When this position is reached, return the position as available slot.
423 if (!pDir->IsDirectory())
425 swapIndex = entryCount;
433 FolderEntryPresentationModel::GetFolderEntryList(void)
435 return __pFolderEntries;
439 FolderEntryPresentationModel::RefreshFolderEntries(void)
441 if (__pFolderEntries != null)
443 __pFolderEntries->RemoveAll(true);
445 if (__sourceForm == CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM)
447 __pFolderEntryStack->RemoveAll(true);
448 CreateTraversalTree();
452 CreateFolderEntryList(__currentFilePath);
457 FolderEntryPresentationModel::SetFolderEntryPath(const String& filePath)
459 AppLogDebug("Enter");
460 __currentFilePath.Clear();
461 __currentFilePath = filePath;
462 if (__pFolderEntries != null)
464 __pFolderEntries->RemoveAll(true);
466 CreateFolderEntryList(__currentFilePath);
471 FolderEntryPresentationModel::AddFolderEntryList(const String& filePath, int index)
473 AppLogDebug("Entry");
474 __currentFilePath.Clear();
475 __currentFilePath = filePath;
477 CreateFolderEntryList(__currentFilePath, index+1); //insert after index
481 FolderEntryPresentationModel::GetDirectoryTreeIndex(const String& filePath, int index)
483 AppLogDebug("ENTER search index = %d, search filepath = %ls",index,filePath.GetPointer());
484 if (filePath == BasePresentationModel::GetMediaPath() || filePath == BasePresentationModel::GetSdCardPath())
488 if (filePath != null)
490 DirectoryEntry* pCurrentDir = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index++));
491 int currentDirDepth = pCurrentDir->GetDirectoryDepth();
492 int dirDept = currentDirDepth;
494 while (currentDirDepth >= dirDept)
496 if (pCurrentDir->GetFullFilePath() == filePath)
500 pCurrentDir = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index++));
501 currentDirDepth = pCurrentDir->GetDirectoryDepth();
502 AppLogDebug("ENTER search index pCurrentDir->GetFullFilePath() = %ls", pCurrentDir->GetFullFilePath().GetPointer());
503 AppLogDebug("ENTER search index pCurrentDir->GetDirectoryDepth() = %d", pCurrentDir->GetDirectoryDepth());
510 FolderEntryPresentationModel::RemoveFolderEntryList(int index)
512 AppLogDebug("Entry");
514 DirectoryEntry* pCurrentDir = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index++));
515 int currentDirDepth = pCurrentDir->GetDirectoryDepth();
516 DirectoryEntry* pNextDir = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index));
517 int nextDirDepth = pNextDir->GetDirectoryDepth();
519 while (nextDirDepth > currentDirDepth)
521 __pFolderEntries->RemoveAt(index);
523 pNextDir = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index));
524 if (pNextDir != null)
526 nextDirDepth = pNextDir->GetDirectoryDepth();
537 FolderEntryPresentationModel::GetFolderEntryCount(const String& filePath, int& currentDirectoryCount, int& currentFileCount)
539 AppLogDebug("Entry");
540 result r = E_SUCCESS;
541 Directory* pDirectory = null;
542 FileAttributes fileAttrib;
543 String fileExtension;
544 ContentType contentType = CONTENT_TYPE_UNKNOWN;
546 r = File::GetAttributes(filePath, fileAttrib);
550 currentDirectoryCount = 0;
551 currentFileCount = 0;
555 currentDirectoryCount = 0;
556 currentFileCount = 0;
557 if (fileAttrib.IsDirectory())
559 DirEnumerator* pDirectoryEnum = null;
560 pDirectory = new (std::nothrow) Directory();
562 r = pDirectory->Construct(filePath);
563 if (pDirectory != null)
565 pDirectoryEnum = pDirectory->ReadN();
568 if (pDirectoryEnum != null)
570 while (pDirectoryEnum->MoveNext() == E_SUCCESS)
572 DirEntry entryName = pDirectoryEnum->GetCurrentDirEntry();
573 if (!(entryName.GetName().StartsWith(".", 0)) && !entryName.IsHidden())
575 String currentName = entryName.GetName();
576 String fullpath = filePath + L"/" + currentName;
578 r = File::GetAttributes(fullpath, fileAttrib);
580 fileExtension = File::GetFileExtension(fullpath);
581 contentType = ContentManagerUtil::CheckContentType(fullpath);
583 if (fileAttrib.IsDirectory())
585 currentDirectoryCount++;
589 if (__entryType == FILE_TYPE_ALL)
593 else if (__entryType == FILE_TYPE_AUDIO_TYPE)
595 if (contentType == CONTENT_TYPE_AUDIO)
600 else if (__entryType == FILE_TYPE_VIDEO_TYPE)
602 if (contentType == CONTENT_TYPE_VIDEO)
607 else if (__entryType == FILE_TYPE_IMAGE_TYPE)
609 if (contentType == CONTENT_TYPE_IMAGE)
614 else if (__entryType == FILE_TYPE_CONTACTS_TYPE)
616 if (fullpath.EndsWith(L"vcs") || fullpath.EndsWith(L"VCS"))
625 if (pDirectory != null)
630 if (pDirectoryEnum != null)
632 delete pDirectoryEnum;
633 pDirectoryEnum = null;
638 AppLogDebug("Exit %s", GetErrorMessage(r));
643 FolderEntryPresentationModel::SortFolderEntries(void)
645 AppLogDebug("Entry");
647 if (__sourceForm == CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
651 FolderEntriesComparer comparerObject;
652 ArrayList* pDirectoriesList = null;
653 ArrayList* pFilesList = null;
654 DirectoryEntry* pFiles = null;
655 DirectoryEntry* pFolderList = null;
656 DirectoryEntry* pFileList = null;
657 DirectoryEntry* pNewEntry = null;
658 int directoryCount = 0;
660 int currentCount = 0;
661 result r = E_SUCCESS;
663 AppRegistry* pAppRegistry = null;
664 String sortbyKeyName(L"SortBy");
668 pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
670 r = pAppRegistry->Get(sortbyKeyName, sortType);
671 TryCatch(r == E_SUCCESS, , "App Registry Get failed");
673 comparerObject.SetSortType(sortType);
675 pDirectoriesList = new (std::nothrow) ArrayList();
676 r = pDirectoriesList->Construct();
677 TryCatch(r == E_SUCCESS, , "App Registry Get failed");
679 pFilesList = new (std::nothrow) ArrayList();
680 r = pFilesList->Construct();
681 TryCatch(r == E_SUCCESS, , "App Registry Get failed");
683 if (__sourceForm == CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM)
685 if (__pFolderEntries != null)
687 __pFolderEntries->Sort(comparerObject);
692 //GetFolderEntryCount(__currentFilePath, directoryCount, fileCount);
693 GetSortFolderEntryCount(directoryCount, fileCount);
695 if (__pFolderEntries != null)
697 if (__currentViewType != APPCONTROL_VIEW_IMPORT)
699 if (directoryCount != 0)
701 for (currentCount = 0; currentCount < directoryCount; currentCount++)
703 pFiles = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(currentCount));
707 pFolderList = new (std::nothrow) DirectoryEntry(*pFiles);
708 pDirectoriesList->Add(pFolderList);
716 for (; currentCount < directoryCount + fileCount; currentCount++)
718 pFiles = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(currentCount));
722 pFileList = new (std::nothrow) DirectoryEntry(*pFiles);
723 pFilesList->Add(pFileList);
729 if (directoryCount != 0)
731 pDirectoriesList->Sort(comparerObject);
735 pFilesList->Sort(comparerObject);
738 if (__pFolderEntries != null)
740 __pFolderEntries->RemoveAll(true);
743 for (currentCount = 0; currentCount < pDirectoriesList->GetCount(); currentCount++)
745 pFiles = static_cast< DirectoryEntry* >(pDirectoriesList->GetAt(currentCount));
746 pNewEntry = new (std::nothrow) DirectoryEntry(*pFiles);
747 __pFolderEntries->Add(pNewEntry);
750 for (currentCount = 0; currentCount < pFilesList->GetCount(); currentCount++)
752 pFiles = static_cast< DirectoryEntry* >(pFilesList->GetAt(currentCount));
756 pNewEntry = new (std::nothrow) DirectoryEntry(*pFiles);
757 __pFolderEntries->Add(pNewEntry);
762 if (pDirectoriesList != null)
764 pDirectoriesList->RemoveAll(true);
765 delete pDirectoriesList;
766 pDirectoriesList = null;
769 if (pFilesList != null)
771 pFilesList->RemoveAll(true);
775 AppLogDebug("Exit %s", GetErrorMessage(r));
778 if (pDirectoriesList != null)
780 pDirectoriesList->RemoveAll(true);
781 delete pDirectoriesList;
782 pDirectoriesList = null;
785 if (pFilesList != null)
787 pFilesList->RemoveAll(true);
794 FolderEntryPresentationModel::OnFileEventOccured(unsigned long events, const Tizen::Base::String& path, unsigned int eventId)
796 AppLogDebug("OnFileEventOccured");
797 if (__pFolderEntryEventListener != null)
799 UpdateFileListEnteries(events, path);
800 AppLogDebug("%d", __pFolderEntries->GetCount());
801 __pFolderEntryEventListener->OnFileEventExecuted(path, events);
806 FolderEntryPresentationModel::SetFileEventListener(IFolderEntryEventListener* pIFileEventNotification)
808 result r = E_SUCCESS;
809 __currentFilePath = FolderNavigationPresentationModel::GetCurrentPath();
810 AppLogDebug("SetFileEventListener %ls %d", __currentFilePath.GetPointer(), __pFolderEntries->GetCount());
811 __pFolderEntryEventListener = pIFileEventNotification;
812 if (pIFileEventNotification != null)
814 r = __pFileEventManager->AddPath(__currentFilePath, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_DELETE);
818 if (__pFileEventManager != null)
820 r = __pFileEventManager->RemovePath(__currentFilePath);
822 AppLogDebug("its null %s", GetErrorMessage(r));
827 FolderEntryPresentationModel::SetFolderEntryType(FileType currentType)
829 __entryType = currentType;
833 FolderEntryPresentationModel::SetViewType(AppControlView currentView)
835 __currentViewType = currentView;
839 FolderEntryPresentationModel::UpdateFileListEnteries(const unsigned long events, const Tizen::Base::String& path)
841 AppLogDebug("Entry");
844 case FILE_EVENT_TYPE_CREATE:
846 DirectoryEntry* pDirStr = new (std::nothrow) DirectoryEntry();
850 StringTokenizer strTok(path, delim);
855 filePath = pDirStr->GetFullFilePath();
856 filePath.Append(__currentFilePath);
857 filePath.Append(path);
858 pDirStr->SetFullFilePath(filePath);
860 //pDirStr->fileName.Append(path);
861 while (strTok.HasMoreTokens())
863 strTok.GetNextToken(token);
864 fileName = pDirStr->GetFileName();
865 fileName.Append(token);
866 pDirStr->SetFileName(fileName);
867 //pDirStr->__fileName.Append(token);
870 pDirStr->SetCheckDirectory(false);
872 GetFolderEntryCount(pDirStr->GetFullFilePath(), dirCount, fileCount);
873 pDirStr->SetDirectoryCount(dirCount);
874 pDirStr->SetFilecount(fileCount);
875 pDirStr->SetFileExtension(File::GetFileExtension(pDirStr->GetFullFilePath()));
876 __pFolderEntries->Add(pDirStr);
877 AppLogDebug("%d", __pFolderEntries->GetCount());
881 case FILE_EVENT_TYPE_DELETE:
883 DirectoryEntry* pDirStr = null;
886 for (int entriesCount = 0; entriesCount < __pFolderEntries->GetCount(); entriesCount++)
888 pDirStr = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(entriesCount));
892 fileName.Append(pDirStr->GetFileName());
893 fileName.Append(L".");
894 fileName.Append(pDirStr->GetFileExtension());
895 if (path == fileName)
897 index = entriesCount;
902 __pFolderEntries->RemoveAt(index, true);
906 case FILE_EVENT_TYPE_DELETE_SELF:
915 AppLogDebug("Exit %s", GetErrorMessage(GetLastResult()));
919 FolderEntryPresentationModel::InitThumbnailManager(void)
921 result r = E_SUCCESS;
922 DirectoryEntry* pDirEntry = null;
924 AppLogDebug("Enter");
927 StopThumbnailManager();
930 __ThumbnailRequestInProgress = false;
932 TryReturn(__pThumbnailManager != null, E_FAILURE, "Thumbnails could not be generated");
933 TryReturn((__pFolderEntries != null) && (__pFolderEntries->GetCount() != 0) && (__requestId >= 0),E_FAILURE, "Invalid Arguments!");
935 pDirEntry = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(__requestId));
936 TryCatch(pDirEntry != null,r=E_FAILURE , "FileEntry list is empty!");
938 if (!pDirEntry->IsDirectory() )
940 pDirEntry->SetLoadBitmap(true);
941 pDirEntry->SetDummy(true);
944 if (!__ThumbnailRequestInProgress && pDirEntry->GetLoadBitmap())
946 __ThumbnailRequestInProgress = true;
947 r = StartThumbnailRequest(__requestId);
951 if ( __requestId >= __pFolderEntries->GetCount()-1)
952 __requestId = INVALID_INDEX;
959 FolderEntryPresentationModel::StartThumbnailRequest(int ReqIndex)
961 result r = E_SUCCESS;
962 ArrayList* pList = null;
963 ThumbRequest* pThumbReq = null;
964 DirectoryEntry* pDirEntry = null;
966 AppLogDebug("Enter [%d]", ReqIndex);
967 __requestId = ReqIndex;
971 StopThumbnailManager();
975 TryReturn(__pThumbnailManager != null, E_FAILURE, "Thumbnails could not be generated");
976 TryCatch((__pFolderEntries != null) && (__pFolderEntries->GetCount() != 0) && (__requestId >= 0), , "Invalid Arguments!");
978 if ( __requestId > __pFolderEntries->GetCount()-1 )
980 StopThumbnailManager();
984 pDirEntry = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(__requestId));
985 TryCatch(pDirEntry != null, , "FileEntry list is empty!");
987 if (pDirEntry->GetBitmap() == null && /* pDirEntry->IsDummy() && */!pDirEntry->IsDirectory() )
989 pThumbReq = new (std::nothrow) ThumbRequest(__sourceForm);
990 TryCatch(pThumbReq != null, , "ThumbRequest is null!");
992 pThumbReq->iRquestId = __requestId;
993 pThumbReq->currentRequestId = __currentRequestId;
994 pThumbReq->FilePath = pDirEntry->GetFullFilePath();
996 pList = new (std::nothrow) ArrayList();
997 TryCatch(pList != null, , "ArrayList is null!");
999 r = pList->Construct();
1000 TryCatch(r == E_SUCCESS, , "ArrayList is null!");
1002 pList->Add(pThumbReq);
1003 __pThumbnailManager->SendUserEvent(ThumbnailManager::THUMB_MGR_GET_THUMBNAIL, pList);
1008 StartThumbnailRequest(__requestId);
1014 pList->RemoveAll(false);
1017 if (pThumbReq != null)
1021 AppLogDebug("FLPM Error occured: Entered inputs are invalid!");
1022 Application::GetInstance()->SendUserEvent(THUMBNAIL_FAILED, null);
1023 __ThumbnailRequestInProgress = false;
1025 if ( __requestId >= __pFolderEntries->GetCount()-1)
1027 __requestId = INVALID_INDEX;
1028 StopThumbnailManager();
1034 AppLogDebug("Exit");
1039 FolderEntryPresentationModel::OnThumbnailResponseReceived(Tizen::Graphics::Bitmap* pThumb, int index)
1041 result r = E_SUCCESS;
1042 int FolderEntryCount = INVALID_INDEX;
1043 DirectoryEntry* pDirEntry = null;
1044 String* cachePath = null;
1045 String cacheImagePath;
1046 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1048 HashMap* pCacheList = null;
1050 __ThumbnailRequestInProgress = false;
1053 StopThumbnailManager();
1057 TryCatch(__pFolderEntries != null && __pFolderEntries->GetCount() != 0, , "Invalid Arguments");
1058 TryCatch(__requestId != INVALID_INDEX, , "Item index reached to maximum value!");
1060 pDirEntry = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index));
1061 TryCatch(pDirEntry != null, , "Invalid directory entry pointer!");
1063 if (index > INVALID_INDEX && pThumb != null)
1065 if (__requestId == index)
1067 pDirEntry->SetDummy(false);
1068 pDirEntry->SetLoadBitmap(false);
1069 pDirEntry->SetBitmap(pThumb);
1072 pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
1073 TryCatch(pCacheList != null, , "Cache Hashmap is null");
1075 cacheImagePath = pDirEntry->GetFullFilePath();
1078 contentType = ContentManagerUtil::CheckContentType(cacheImagePath);
1080 if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
1082 if ((pCacheList->GetValue(cacheImagePath)) == null)
1084 cachePath = new (std::nothrow) String(pDirEntry->GetFullFilePath());
1085 if (cachePath != null)
1086 __pCacheManager->AddCacheEntry(*cachePath,pThumb);
1091 FolderEntryCount = __pFolderEntries->GetCount();
1093 if (pDirEntry->GetLoadBitmap())
1095 if (__requestId < FolderEntryCount )
1098 StartThumbnailRequest(__requestId);
1100 else if (__requestId >= FolderEntryCount)
1102 __requestId = INVALID_INDEX;
1103 __ThumbnailRequestInProgress = false;
1104 StopThumbnailManager();
1110 StartThumbnailRequest(__requestId);
1120 if (!__ThumbnailRequestInProgress)
1122 if(__requestId >= __pFolderEntries->GetCount()-1 )
1123 StopThumbnailManager();
1128 AppLogDebug("Exit");
1133 FolderEntryPresentationModel::OnThumbnailResponseFailed(int index)
1135 result r = E_SUCCESS;
1136 int FolderEntryCount = INVALID_INDEX;
1137 DirectoryEntry* pDirEntry = null;
1139 AppLogDebug("Current ReqId : %d %d", __requestId, index);
1143 StopThumbnailManager();
1147 TryCatch((__pFolderEntries != null) && (__pFolderEntries->GetCount() != 0), r= E_FAILURE, "Data not found");
1148 AppLogDebug("ThumbnailResponseFailed : Request id [%d], Index [%d]", __requestId, index);
1150 __ThumbnailRequestInProgress = false;
1152 pDirEntry = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index));
1153 TryCatch(pDirEntry != null, , "Invalid parameters!");
1155 FolderEntryCount = __pFolderEntries->GetCount();
1157 if (pDirEntry->GetLoadBitmap())
1159 if (__requestId < FolderEntryCount )
1162 StartThumbnailRequest(__requestId);
1164 else if (__requestId >= FolderEntryCount)
1166 __requestId = INVALID_INDEX;
1167 __ThumbnailRequestInProgress = false;
1168 StopThumbnailManager();
1174 StartThumbnailRequest(__requestId);
1176 AppLogDebug("EXIT : %s", GetErrorMessage(r));
1178 __ThumbnailRequestInProgress = false;
1180 if(__requestId >= __pFolderEntries->GetCount()-1 )
1181 StopThumbnailManager();
1188 FolderEntryPresentationModel::SetListUpdateEventListener(IListViewStateChangeListener* pListener)
1190 result r = E_SUCCESS;
1192 __pListUpdateListener = pListener;
1199 FolderEntryPresentationModel::StopThumbnailManager(bool bForceStop)
1201 result r = E_SUCCESS;
1203 AppLogDebug("StopThumbnailManager [%d]", __requestId);
1205 __forceStop = bForceStop;
1207 TryCatch(__pThumbnailManager != null, r=E_FAILURE, "Thumbnails could not be generated");
1208 __pThumbnailManager->SendUserEvent(ThumbnailManager::THUMB_MGR_STOP, null);
1210 __ThumbnailRequestInProgress = false;
1211 __requestId = INVALID_INDEX;
1213 AppLogDebug("StopThumbnailManager--");
1218 FolderEntryPresentationModel::SetSortEnabled(bool enableFlag)
1220 __enableSort = enableFlag;
1222 IFolderEntryProviderListener::~IFolderEntryProviderListener(void)
1224 //empty Implementation
1228 FolderEntryPresentationModel::SetSourceForm(CreateItemSource currentSource)
1230 __sourceForm = currentSource;
1234 FolderEntryPresentationModel::GetSourceForm(void)
1236 return __sourceForm;
1239 FolderEntryPresentationModel::SetCurrentReqId(int currentRequestId)
1241 __currentRequestId = currentRequestId;
1244 FolderEntryPresentationModel::GetCurrentReqId(void)
1246 return __currentRequestId;
1249 FolderEntryPresentationModel::CreateStack(void)
1251 if (__pFolderEntryStack == null)
1253 __pFolderEntryStack = new (std::nothrow) Stack();
1254 __pFolderEntryStack->Construct();
1259 FolderEntryPresentationModel::CreateTraversalTree(void)
1261 Directory* pCurrentDirectory = null;
1262 //String* directoryPath = null;
1263 ArrayList* pDeviceList = null;
1264 DirEnumerator* pCurrentDirectoryEnum = null;
1265 String* currentDirectoryPath = null;
1266 String fileExtension;
1267 int fileExtensionLength = 0;
1268 int deviceListCount = 1;
1269 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1270 result r = E_SUCCESS;
1271 result fileExtensionResult = E_SUCCESS;
1273 if (__pFolderEntries != null)
1275 __pFolderEntries->RemoveAll(true);
1279 __pFolderEntries = new (std::nothrow) ArrayList();
1280 r = __pFolderEntries->Construct();
1283 if (pDeviceList == null)
1285 pDeviceList = new (std::nothrow) ArrayList();
1286 pDeviceList->Construct();
1289 GetDeviceList(pDeviceList);
1290 deviceListCount = pDeviceList->GetCount();
1292 __deviceListCount = deviceListCount;
1294 //currentDirectoryPath = new (std::nothrow) String(directoryPath);
1295 currentDirectoryPath = new (std::nothrow) String(*static_cast<String*>(pDeviceList->GetAt(0)));
1296 TryCatch(__pFolderEntryStack != null, , "Stack is null");
1297 r = __pFolderEntryStack->Push(currentDirectoryPath);
1298 TryCatch(r == E_SUCCESS, ,"push failed");
1300 while (deviceListCount > 0)
1302 while (__pFolderEntryStack->GetCount() > 0)
1304 pCurrentDirectory = new (std::nothrow) Directory();
1305 r = pCurrentDirectory->Construct(*currentDirectoryPath);
1306 TryCatch(r == E_SUCCESS, ,"Directory Construct failed");
1307 pCurrentDirectoryEnum = pCurrentDirectory->ReadN();
1308 while(pCurrentDirectoryEnum->MoveNext() == E_SUCCESS)
1310 DirEntry currentDirEntry = pCurrentDirectoryEnum->GetCurrentDirEntry();
1311 String directoryName = currentDirEntry.GetName();
1313 DirectoryEntry* pCurrentFolderEntry = new (std::nothrow) DirectoryEntry();
1314 String fullPath = *currentDirectoryPath+directoryName;
1315 pCurrentFolderEntry->SetFileExtension(File::GetFileExtension(fullPath));
1316 fileExtensionResult = GetLastResult();
1317 fileExtensionLength = pCurrentFolderEntry->GetFileExtension().GetLength();
1318 if(fileExtensionLength != 0)
1320 directoryName.Remove(directoryName.GetLength() - fileExtensionLength - 1, fileExtensionLength + 1);
1322 pCurrentFolderEntry->SetFullFilePath(fullPath);
1323 pCurrentFolderEntry->SetFileName(directoryName);
1324 pCurrentFolderEntry->SetCheckDirectory(false);
1325 pCurrentFolderEntry->SetCreationTime(currentDirEntry.GetDateTime());
1327 if(currentDirEntry.IsDirectory() && directoryName != "." && directoryName != "..")
1329 AppLogDebug("SearchPresentationModel::Search::");
1330 if (__sourceForm == CREATE_ITEM_SOURCE_SEARCH_FORM)
1332 AppLogDebug("SearchPresentationModel::Search::%S", pCurrentFolderEntry->GetFullFilePath().GetPointer());
1333 pCurrentFolderEntry->SetCheckDirectory(true);
1334 __pFolderEntries->Add(pCurrentFolderEntry);
1338 delete pCurrentFolderEntry;
1339 pCurrentFolderEntry = null;
1341 String pathtoPush = *currentDirectoryPath + directoryName + "/";
1342 r = __pFolderEntryStack->Push(new (std::nothrow) String(pathtoPush));
1343 TryCatch(r == E_SUCCESS, ,"push failed");
1345 else if (!(directoryName.StartsWith(L".", 0)) && !currentDirEntry.IsHidden())
1347 contentType = ContentManagerUtil::CheckContentType(fullPath);
1348 r = GetLastResult();
1349 fileExtension = pCurrentFolderEntry->GetFileExtension();
1351 if (__entryType == FILE_TYPE_ALL)
1353 __pFolderEntries->Add(pCurrentFolderEntry);
1355 else if (__entryType == FILE_TYPE_VIDEO_TYPE)
1357 if (contentType == CONTENT_TYPE_VIDEO)
1359 __pFolderEntries->Add(pCurrentFolderEntry);
1363 delete pCurrentFolderEntry;
1364 pCurrentFolderEntry = null;
1367 else if (__entryType == FILE_TYPE_IMAGE_TYPE)
1369 if (contentType == CONTENT_TYPE_IMAGE)
1371 __pFolderEntries->Add(pCurrentFolderEntry);
1375 delete pCurrentFolderEntry;
1376 pCurrentFolderEntry = null;
1379 else if (__entryType == FILE_TYPE_AUDIO_TYPE)
1381 if (contentType == CONTENT_TYPE_AUDIO)
1383 __pFolderEntries->Add(pCurrentFolderEntry);
1387 delete pCurrentFolderEntry;
1388 pCurrentFolderEntry = null;
1391 else if (__entryType == FILE_TYPE_DOCUMENT_TYPE)
1393 if ( fileExtension.EndsWith(L"pptx") || fileExtension.EndsWith(L"PPTX")
1394 || fileExtension.EndsWith(L"pdf") || fileExtension.EndsWith(L"PDF")
1395 ||fileExtension.EndsWith(L"doc") || fileExtension.EndsWith(L"DOC")
1396 || fileExtension.EndsWith(L"docx") || fileExtension.EndsWith(L"DOCX")
1397 || fileExtension.EndsWith(L"xls") || fileExtension.EndsWith(L"XLS")
1398 ||fileExtension.EndsWith(L"xlsx") || fileExtension.EndsWith(L"XLSX")
1399 || fileExtension.EndsWith(L"ppt") || fileExtension.EndsWith(L"PPT"))
1401 __pFolderEntries->Add(pCurrentFolderEntry);
1405 delete pCurrentFolderEntry;
1406 pCurrentFolderEntry = null;
1409 else if (__entryType == FILE_TYPE_CONTACTS_TYPE)
1411 if ( fileExtension.EndsWith(L"vcs") || fileExtension.EndsWith(L"VCS"))
1413 __pFolderEntries->Add(pCurrentFolderEntry);
1417 delete pCurrentFolderEntry;
1418 pCurrentFolderEntry = null;
1421 else if (__entryType == FILE_TYPE_OTHER_TYPE)
1423 if (contentType == CONTENT_TYPE_OTHER || r != E_SUCCESS)
1425 if ((fileExtension.EndsWith(L"pptx") || fileExtension.EndsWith(L"PPTX")
1426 || fileExtension.EndsWith(L"pdf") || fileExtension.EndsWith(L"PDF")
1427 || fileExtension.EndsWith(L"doc") || fileExtension.EndsWith(L"DOC")
1428 || fileExtension.EndsWith(L"docx") || fileExtension.EndsWith(L"DOCX")
1429 || fileExtension.EndsWith(L"xls") || fileExtension.EndsWith(L"XLS")
1430 || fileExtension.EndsWith(L"xlsx") || fileExtension.EndsWith(L"XLSX")
1431 || fileExtension.EndsWith(L"ppt") || fileExtension.EndsWith(L"PPT")
1434 delete pCurrentFolderEntry;
1435 pCurrentFolderEntry = null;
1439 __pFolderEntries->Add(pCurrentFolderEntry);
1444 delete pCurrentFolderEntry;
1445 pCurrentFolderEntry = null;
1450 delete pCurrentFolderEntry;
1451 pCurrentFolderEntry = null;
1455 //if(pCurrentDirectory != null)
1457 delete pCurrentDirectory;
1458 pCurrentDirectory = null;
1460 //if(pCurrentDirectoryEnum != null)
1462 delete pCurrentDirectoryEnum;
1463 pCurrentDirectoryEnum = null;
1465 currentDirectoryPath = static_cast<String *>(__pFolderEntryStack->Pop());
1466 TryCatch(currentDirectoryPath !=null, , "Pop Failed");
1468 if (currentDirectoryPath != null)
1470 delete currentDirectoryPath;
1471 currentDirectoryPath = null;
1475 if (deviceListCount > 0)
1477 currentDirectoryPath = new (std::nothrow) String(*static_cast<String*>(pDeviceList->GetAt(pDeviceList->GetCount() - deviceListCount)));
1478 TryCatch(__pFolderEntryStack != null, , "Stack is null");
1479 r = __pFolderEntryStack->Push(currentDirectoryPath);
1480 TryCatch(r == E_SUCCESS, ,"push failed");
1484 /*if (currentDirectoryPath != null)
1486 delete currentDirectoryPath;
1487 currentDirectoryPath = null;
1490 //todo Commented to remove warning
1491 // for(int count = 0; count<__pFolderEntries->GetCount(); count++)
1493 // DirectoryEntry* pName = (DirectoryEntry *)__pFolderEntries->GetAt(count);
1497 pDeviceList->RemoveAll(true);
1504 if (currentDirectoryPath != null)
1506 delete currentDirectoryPath;
1507 currentDirectoryPath = null;
1509 if (__pFolderEntryStack != null)
1511 __pFolderEntryStack->RemoveAll(true);
1513 if (pCurrentDirectory != null)
1515 delete pCurrentDirectory;
1516 pCurrentDirectory = null;
1519 pDeviceList->RemoveAll(true);
1526 FolderEntryPresentationModel::GetDeviceList(Tizen::Base::Collection::ArrayList* pDeviceList)
1528 String deviceSateSdCard;
1529 String deviceSateUsbClient;
1530 String mounted = sdCardStatusMounted;
1531 String inserted = usbDeviceStatusInserted;
1533 pDeviceList->Add(new (std::nothrow) String(BasePresentationModel::GetMediaPath()));
1535 DeviceManager::GetState(StorageCard, deviceSateSdCard);
1537 DeviceManager::GetState(UsbClient, deviceSateUsbClient);
1540 if (deviceSateSdCard == mounted)
1542 pDeviceList->Add(new (std::nothrow) String(BasePresentationModel::GetSdCardPath()));
1544 if (deviceSateUsbClient == inserted)
1546 pDeviceList->Add(new (std::nothrow) String(BasePresentationModel::GetUsbPath()));
1550 FolderEntryPresentationModel::GetSortFolderEntryCount(int& currentDirectoryCount, int& currentFileCount)
1552 bool directoryCheck = true;
1553 DirectoryEntry* pcurrentEntry = null;
1554 int currentCount = 0;
1555 if (__pFolderEntries == null || __pFolderEntries->GetCount() == 0)
1557 currentDirectoryCount = 0;
1558 currentFileCount = 0;
1561 currentDirectoryCount = 0;
1562 currentFileCount = 0;
1563 pcurrentEntry = static_cast<DirectoryEntry*>(__pFolderEntries->GetAt(currentCount));
1564 directoryCheck = pcurrentEntry->IsDirectory();
1565 while (__pFolderEntries->GetCount()>0 && directoryCheck)
1568 pcurrentEntry = static_cast<DirectoryEntry*>(__pFolderEntries->GetAt(currentCount));
1569 if (pcurrentEntry == null)
1573 directoryCheck = pcurrentEntry->IsDirectory();
1575 currentDirectoryCount = currentCount;
1576 currentFileCount = __pFolderEntries->GetCount() - currentCount;
1580 FolderEntryPresentationModel::GetDeviceListCount(void)
1582 return __deviceListCount;