N_SE-36744 N_SE-36750 N_SE-36754 N_SE-36743
[apps/osp/MyFiles.git] / src / MfFolderEntryPresentationModel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
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.
21  */
22
23 #include <FApp.h>
24 #include <FLocales.h>
25 #include <FSystem.h>
26 #include <FUi.h>
27
28 #include "MfFolderEntryDetailPresentationModel.h"
29 #include "MfFolderEntryPresentationModel.h"
30 #include "MfFolderEntriesComparer.h"
31 #include "MfFolderNavigationPresentationModel.h"
32 #include "MfMediaMetaData.h"
33 #include "MfTypes.h"
34
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;
45
46
47 static const int INVALID_INDEX = -1;
48 IFolderEntryEventListener* FolderEntryPresentationModel::__pFolderEntryEventListener = null;
49 //! Constructor for the FileListPresentationModel class
50
51 FolderEntryPresentationModel::FolderEntryPresentationModel(void)
52 : __requestId(INVALID_INDEX)
53 , __forceStop(false)
54 , __enableSort(false)
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)
63 {
64         //empty implementation
65 }
66
67 result
68 FolderEntryPresentationModel::Construct(void)
69 {
70         AppLogDebug("Entry");
71         result r = E_SUCCESS;
72
73         __requestId = 0;
74         __currentRequestId = 0;
75         __deviceListCount = 1;
76
77         __pFileEventManager = new (std::nothrow) FileEventManager();
78         r = __pFileEventManager->Construct(*this);
79
80         __pFolderEntries = new (std::nothrow) ArrayList();
81         r = __pFolderEntries->Construct();
82         __enableSort = true;
83
84         __pThumbnailManager = ThumbnailManager::GetInstance();
85         __pCacheManager = CacheManager::GetInstance();
86
87         AppLogDebug("Exit %s", GetErrorMessage(r));
88         return r;
89 }
90
91 //! Destructor for the FileListPresentationModel class
92 FolderEntryPresentationModel::~FolderEntryPresentationModel(void)
93 {
94         if (__pFolderEntries != null)
95         {
96                 __pFolderEntries->RemoveAll(true);
97                 delete __pFolderEntries;
98         }
99         if (__pThumbnailManager)
100         {
101                 __requestId = INVALID_INDEX;
102         }
103         if (__pFileEventManager != null)
104         {
105                 delete __pFileEventManager;
106                 __pFileEventManager = null;
107         }
108         if (__pFolderEntryStack != null)
109         {
110                 __pFolderEntryStack->RemoveAll(true);
111                 delete __pFolderEntryStack;
112         }
113 }
114
115 //!Copy Constructor for the FileListPresentationModel class
116 FolderEntryPresentationModel::FolderEntryPresentationModel(const FolderEntryPresentationModel& content)
117 {
118         //empty Implementation
119 }
120
121 /*!Overloaded assignment operator for the FileListPresentationModel class.
122  */
123 FolderEntryPresentationModel&
124 FolderEntryPresentationModel::operator =(const FolderEntryPresentationModel& source)
125 {
126         return *this;
127 }
128
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.
132  */
133 void
134 FolderEntryPresentationModel::CreateFolderEntryList(const String& directoryName, int index)
135 {
136         AppLogDebug("Entry");
137         result r = E_SUCCESS;
138         DirectoryEntry* pName = null;
139         DirectoryEntry* pSource = null;
140         DirectoryEntry* pDestination = null;
141         String fileFullName;
142
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
146
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))
149         {
150                 if (__pFolderEntries != null)
151                 {
152                         __pFolderEntries->RemoveAll(true);
153                         delete __pFolderEntries;
154                         __pFolderEntries = null;
155                 }
156                 return;
157         }
158
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");
162
163         if (__sourceForm == CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
164         {
165                 AppLogDebug("returning after adding to list");
166                 return;
167         }
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
171         {
172                 currentDirectoryCount = 0;
173                 currentFileCount = 0;
174
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);
180
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.
183
184                 if (pName->IsDirectory())
185                 {
186                         GetFolderEntryCount(fileFullName, currentDirectoryCount, currentFileCount);
187                         pName->SetDirectoryCount(currentDirectoryCount);
188                         pName->SetFilecount(currentFileCount);
189                 }
190                 else
191                 {
192                         pName->SetDirectoryCount(0);
193                         pName->SetFilecount(0);
194                 }
195
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.
198
199                 swapIndex = GetSwapIndex();  // The slot number is updated for the next swap operation
200
201                 pSource = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(fileEntriesCount));
202                 TryCatch(pSource != null, , "Failed to get entry");
203
204
205                 // Swapping should be done only if the entry is a directory
206                 if (pSource->IsDirectory())
207                 {
208                         if (swapIndex != INVALID_INDEX)
209                         {
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);
214                         }
215                 }
216
217         } // End of Directory and File Count loop
218
219         if (__enableSort == true)
220         {
221                 SortFolderEntries();
222         }
223         AppLogDebug("Exit %s", GetErrorMessage(r));
224         return;
225         CATCH:
226         AppLogDebug("Exit %s", GetErrorMessage(r));
227         if (__pFolderEntries != null)
228         {
229                 __pFolderEntries->RemoveAll(true);
230         }
231 }
232
233 result
234 FolderEntryPresentationModel::MakeFolderEntryList(const String& directoryName, int index)
235 {
236         AppLogDebug("Entry");
237         int fileExtensionLength = 0;
238         String entryValue;
239         String fullpath;
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;
244
245         pDirectory = new (std::nothrow) Directory();
246         r = pDirectory->Construct(directoryName);
247         AppLogDebug("dir construct result is %s",GetErrorMessage(r));
248         if(r != E_SUCCESS)
249         {
250                 delete pDirectory;
251                 return r;
252         }
253
254         pDirectoryEnum = pDirectory->ReadN();
255
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
258
259         while (pDirectoryEnum->MoveNext() == E_SUCCESS)
260         {
261                 DirEntry entryName = pDirectoryEnum->GetCurrentDirEntry();
262
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())
265                 {
266                         //! Add the DirectoryStructure object to the arraylist for each directory entry in the path
267                         DirectoryEntry* pCurrentFolderEntry = new (std::nothrow) DirectoryEntry();
268                         entryValue.Clear();
269                         entryValue = entryName.GetName();
270                         fullpath.Clear();
271
272                         fullpath = directoryName + entryValue;
273
274                         // If the entry is a direcotry then currentDirectoryCount should be incremented.
275                         // Else currentFileCount should be incremented.
276
277                         if (entryName.IsDirectory())
278                         {
279                                 fullpath.Append(L"/");
280                         }
281                         else
282                         {
283                                 pCurrentFolderEntry->SetFileExtension(File::GetFileExtension(fullpath));
284                                 fileExtensionLength = pCurrentFolderEntry->GetFileExtension().GetLength();
285                                 if(fileExtensionLength != 0)
286                                 {
287                                         entryValue.Remove(entryValue.GetLength() - fileExtensionLength - 1, fileExtensionLength + 1);
288                                 }
289                         }
290
291                         pCurrentFolderEntry->SetFullFilePath(fullpath);
292                         pCurrentFolderEntry->SetFileName(entryValue);
293                         pCurrentFolderEntry->SetCheckDirectory(entryName.IsDirectory());
294                         pCurrentFolderEntry->SetCreationTime(entryName.GetDateTime());
295
296                         contentType = ContentManagerUtil::CheckContentType(fullpath);
297
298                         if (!pCurrentFolderEntry->IsDirectory() && __sourceForm != CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
299                         {
300                                 if (__entryType == FILE_TYPE_ALL)
301                                 {
302                                         __pFolderEntries->Add(pCurrentFolderEntry);
303                                 }
304                                 else if (__entryType == FILE_TYPE_AUDIO_TYPE)
305                                 {
306                                         if (contentType == CONTENT_TYPE_AUDIO)
307                                         {
308                                                 __pFolderEntries->Add(pCurrentFolderEntry);
309                                         }
310                                         else
311                                         {
312                                                 delete pCurrentFolderEntry;
313                                                 pCurrentFolderEntry = null;
314                                         }
315                                 }
316                                 else if (__entryType == FILE_TYPE_VIDEO_TYPE)
317                                 {
318                                         if (contentType == CONTENT_TYPE_VIDEO)
319                                         {
320                                                 __pFolderEntries->Add(pCurrentFolderEntry);
321                                         }
322                                         else
323                                         {
324                                                 delete pCurrentFolderEntry;
325                                                 pCurrentFolderEntry = null;
326                                         }
327                                 }
328                                 else if (__entryType == FILE_TYPE_IMAGE_TYPE)
329                                 {
330                                         if (contentType == CONTENT_TYPE_IMAGE)
331                                         {
332                                                 __pFolderEntries->Add(pCurrentFolderEntry);
333                                         }
334                                         else
335                                         {
336                                                 delete pCurrentFolderEntry;
337                                                 pCurrentFolderEntry = null;
338                                         }
339                                 }
340                                 else if (__entryType == FILE_TYPE_CONTACTS_TYPE)
341                                 {
342                                         if (fullpath.EndsWith(L"vcs") || fullpath.EndsWith(L"VCS"))
343                                         {
344                                                 __pFolderEntries->Add(pCurrentFolderEntry);
345                                         }
346                                         else
347                                         {
348                                                 delete pCurrentFolderEntry;
349                                                 pCurrentFolderEntry = null;
350                                         }
351                                 }
352                         }
353                         else if (pCurrentFolderEntry->IsDirectory() == true)
354                         {
355                                 if (__currentViewType != APPCONTROL_VIEW_IMPORT)
356                                 {
357                                         __pFolderEntries->InsertAt(pCurrentFolderEntry, index);
358                                 }
359                         }
360                 }
361         }
362
363         //if (pDirectory != null)
364         //{
365         delete pDirectory;
366         pDirectory = null;
367         //}
368
369         //if (pDirectoryEnum != null)
370         //{
371         delete pDirectoryEnum;
372         pDirectoryEnum = null;
373         //}
374
375         return r;
376         /*CATCH:
377         if (pDirectory != null)
378         {
379             delete pDirectory;
380             pDirectory = null;
381         }
382
383         if (pDirectoryEnum != null)
384         {
385             delete pDirectoryEnum;
386             pDirectoryEnum = null;
387         }
388         AppLogDebug("Exit:[%s]", GetErrorMessage(r));
389         return r; //! Array list which contains the result value*/
390 }
391
392 /*! Used to swap two DirectoryStructure objects.
393  * Required during sorting elements so that directory will be in the top of arraylist
394  */
395 void
396 FolderEntryPresentationModel::SwapFolderEntries(DirectoryEntry& source, DirectoryEntry& destination)
397 {
398         //Exchange the contents of source object with the destination object
399         DirectoryEntry intermediate;
400         intermediate = source;
401         source = destination;
402         destination = intermediate;
403 }
404
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.
408  */
409 int
410 FolderEntryPresentationModel::GetSwapIndex(void)
411 {
412         int swapIndex = INVALID_INDEX;
413         DirectoryEntry* pDir = null;
414
415         for (int entryCount = 0; entryCount < __pFolderEntries->GetCount(); entryCount++)
416         {
417                 pDir = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(entryCount));
418
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.
422
423                 if (!pDir->IsDirectory())
424                 {
425                         swapIndex = entryCount;
426                         break;
427                 }
428         }
429         return swapIndex;
430 }
431
432 ArrayList*
433 FolderEntryPresentationModel::GetFolderEntryList(void)
434 {
435         return __pFolderEntries;
436 }
437
438 void
439 FolderEntryPresentationModel::RefreshFolderEntries(void)
440 {
441         if (__pFolderEntries != null)
442         {
443                 __pFolderEntries->RemoveAll(true);
444         }
445         if (__sourceForm == CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM)
446         {
447                 __pFolderEntryStack->RemoveAll(true);
448                 CreateTraversalTree();
449         }
450         else
451         {
452                 CreateFolderEntryList(__currentFilePath);
453         }
454 }
455
456 void
457 FolderEntryPresentationModel::SetFolderEntryPath(const String& filePath)
458 {
459         AppLogDebug("Enter");
460         __currentFilePath.Clear();
461         __currentFilePath = filePath;
462         if (__pFolderEntries != null)
463         {
464                 __pFolderEntries->RemoveAll(true);
465         }
466         CreateFolderEntryList(__currentFilePath);
467         AppLogDebug("Exit");
468 }
469
470 void
471 FolderEntryPresentationModel::AddFolderEntryList(const String& filePath, int index)
472 {
473         AppLogDebug("Entry");
474         __currentFilePath.Clear();
475         __currentFilePath = filePath;
476
477         CreateFolderEntryList(__currentFilePath, index+1); //insert after index
478 }
479
480 int
481 FolderEntryPresentationModel::GetDirectoryTreeIndex(const String& filePath, int index)
482 {
483         AppLogDebug("ENTER search index = %d, search filepath = %ls",index,filePath.GetPointer());
484         if (filePath == BasePresentationModel::GetMediaPath() || filePath == BasePresentationModel::GetSdCardPath())
485         {
486                 return 0;
487         }
488         if (filePath != null)
489         {
490                 DirectoryEntry* pCurrentDir = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index++));
491                 int currentDirDepth = pCurrentDir->GetDirectoryDepth();
492                 int dirDept = currentDirDepth;
493
494                 while (currentDirDepth >= dirDept)
495                 {
496                         if (pCurrentDir->GetFullFilePath() == filePath)
497                         {
498                                 return index - 1;
499                         }
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());
504                 }
505         }
506         return -1;
507 }
508
509 void
510 FolderEntryPresentationModel::RemoveFolderEntryList(int index)
511 {
512         AppLogDebug("Entry");
513
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();
518
519         while (nextDirDepth > currentDirDepth)
520         {
521                 __pFolderEntries->RemoveAt(index);
522                 delete pNextDir;
523                 pNextDir = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index));
524                 if (pNextDir != null)
525                 {
526                         nextDirDepth = pNextDir->GetDirectoryDepth();
527                 }
528                 else
529                 {
530                         return;
531                 }
532         }
533         return;
534 }
535
536 void
537 FolderEntryPresentationModel::GetFolderEntryCount(const String& filePath, int& currentDirectoryCount, int& currentFileCount)
538 {
539         AppLogDebug("Entry");
540         result r = E_SUCCESS;
541         Directory* pDirectory = null;
542         FileAttributes fileAttrib;
543         String fileExtension;
544         ContentType contentType = CONTENT_TYPE_UNKNOWN;
545
546         r = File::GetAttributes(filePath, fileAttrib);
547
548         if (r != E_SUCCESS)
549         {
550                 currentDirectoryCount = 0;
551                 currentFileCount = 0;
552                 return;
553         }
554
555         currentDirectoryCount = 0;
556         currentFileCount = 0;
557         if (fileAttrib.IsDirectory())
558         {
559                 DirEnumerator* pDirectoryEnum = null;
560                 pDirectory = new (std::nothrow) Directory();
561
562                 r = pDirectory->Construct(filePath);
563                 if (pDirectory != null)
564                 {
565                         pDirectoryEnum = pDirectory->ReadN();
566                 }
567
568                 if (pDirectoryEnum != null)
569                 {
570                         while (pDirectoryEnum->MoveNext() == E_SUCCESS)
571                         {
572                                 DirEntry entryName = pDirectoryEnum->GetCurrentDirEntry();
573                                 if (!(entryName.GetName().StartsWith(".", 0)) && !entryName.IsHidden())
574                                 {
575                                         String currentName = entryName.GetName();
576                                         String fullpath = filePath + L"/" + currentName;
577
578                                         r = File::GetAttributes(fullpath, fileAttrib);
579
580                                         fileExtension = File::GetFileExtension(fullpath);
581                                         contentType = ContentManagerUtil::CheckContentType(fullpath);
582
583                                         if (fileAttrib.IsDirectory())
584                                         {
585                                                 currentDirectoryCount++;
586                                         }
587                                         else
588                                         {
589                                                 if (__entryType == FILE_TYPE_ALL)
590                                                 {
591                                                         currentFileCount++;
592                                                 }
593                                                 else if (__entryType == FILE_TYPE_AUDIO_TYPE)
594                                                 {
595                                                         if (contentType == CONTENT_TYPE_AUDIO)
596                                                         {
597                                                                 currentFileCount++;
598                                                         }
599                                                 }
600                                                 else if (__entryType == FILE_TYPE_VIDEO_TYPE)
601                                                 {
602                                                         if (contentType == CONTENT_TYPE_VIDEO)
603                                                         {
604                                                                 currentFileCount++;
605                                                         }
606                                                 }
607                                                 else if (__entryType == FILE_TYPE_IMAGE_TYPE)
608                                                 {
609                                                         if (contentType == CONTENT_TYPE_IMAGE)
610                                                         {
611                                                                 currentFileCount++;
612                                                         }
613                                                 }
614                                                 else if (__entryType == FILE_TYPE_CONTACTS_TYPE)
615                                                 {
616                                                         if (fullpath.EndsWith(L"vcs") || fullpath.EndsWith(L"VCS"))
617                                                         {
618                                                                 currentFileCount++;
619                                                         }
620                                                 }
621                                         }
622                                 }
623                         }
624
625                         if (pDirectory != null)
626                         {
627                                 delete pDirectory;
628                                 pDirectory = null;
629                         }
630                         if (pDirectoryEnum != null)
631                         {
632                                 delete pDirectoryEnum;
633                                 pDirectoryEnum = null;
634                         }
635                 }
636         }
637
638         AppLogDebug("Exit %s", GetErrorMessage(r));
639         return;
640 }
641
642 void
643 FolderEntryPresentationModel::SortFolderEntries(void)
644 {
645         AppLogDebug("Entry");
646
647         if (__sourceForm == CREATE_ITEM_SOURCE_SPLIT_PANEL_DIR_TREE)
648         {
649                 return;
650         }
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;
659         int fileCount = 0;
660         int currentCount = 0;
661         result r = E_SUCCESS;
662
663         AppRegistry* pAppRegistry = null;
664         String sortbyKeyName(L"SortBy");
665         int sortType;
666         String currentpath;
667
668         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
669
670         r = pAppRegistry->Get(sortbyKeyName, sortType);
671         TryCatch(r == E_SUCCESS, , "App Registry Get failed");
672
673         comparerObject.SetSortType(sortType);
674
675         pDirectoriesList = new (std::nothrow) ArrayList();
676         r = pDirectoriesList->Construct();
677         TryCatch(r == E_SUCCESS, , "App Registry Get failed");
678
679         pFilesList = new (std::nothrow) ArrayList();
680         r = pFilesList->Construct();
681         TryCatch(r == E_SUCCESS, , "App Registry Get failed");
682
683         if (__sourceForm == CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM)
684         {
685                 if (__pFolderEntries != null)
686                 {
687                         __pFolderEntries->Sort(comparerObject);
688                 }
689         }
690         else
691         {
692                 //GetFolderEntryCount(__currentFilePath, directoryCount, fileCount);
693                 GetSortFolderEntryCount(directoryCount, fileCount);
694
695                 if (__pFolderEntries != null)
696                 {
697                         if (__currentViewType != APPCONTROL_VIEW_IMPORT)
698                         {
699                                 if (directoryCount != 0)
700                                 {
701                                         for (currentCount = 0; currentCount < directoryCount; currentCount++)
702                                         {
703                                                 pFiles = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(currentCount));
704
705                                                 if (pFiles != null)
706                                                 {
707                                                         pFolderList = new (std::nothrow) DirectoryEntry(*pFiles);
708                                                         pDirectoriesList->Add(pFolderList);
709                                                 }
710                                         }
711                                 }
712                         }
713
714                         if (fileCount != 0)
715                         {
716                                 for (; currentCount < directoryCount + fileCount; currentCount++)
717                                 {
718                                         pFiles = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(currentCount));
719
720                                         if (pFiles != null)
721                                         {
722                                                 pFileList = new (std::nothrow) DirectoryEntry(*pFiles);
723                                                 pFilesList->Add(pFileList);
724                                         }
725                                 }
726                         }
727                 }
728
729                 if (directoryCount != 0)
730                 {
731                         pDirectoriesList->Sort(comparerObject);
732                 }
733                 if (fileCount != 0)
734                 {
735                         pFilesList->Sort(comparerObject);
736                 }
737
738                 if (__pFolderEntries != null)
739                 {
740                         __pFolderEntries->RemoveAll(true);
741                 }
742
743                 for (currentCount = 0; currentCount < pDirectoriesList->GetCount(); currentCount++)
744                 {
745                         pFiles = static_cast< DirectoryEntry* >(pDirectoriesList->GetAt(currentCount));
746                         pNewEntry = new (std::nothrow) DirectoryEntry(*pFiles);
747                         __pFolderEntries->Add(pNewEntry);
748                 }
749
750                 for (currentCount = 0; currentCount < pFilesList->GetCount(); currentCount++)
751                 {
752                         pFiles = static_cast< DirectoryEntry* >(pFilesList->GetAt(currentCount));
753
754                         if (pFiles != null)
755                         {
756                                 pNewEntry = new (std::nothrow) DirectoryEntry(*pFiles);
757                                 __pFolderEntries->Add(pNewEntry);
758                         }
759                 }
760         }
761
762         if (pDirectoriesList != null)
763         {
764                 pDirectoriesList->RemoveAll(true);
765                 delete pDirectoriesList;
766                 pDirectoriesList = null;
767         }
768
769         if (pFilesList != null)
770         {
771                 pFilesList->RemoveAll(true);
772                 delete pFilesList;
773                 pFilesList = null;
774         }
775         AppLogDebug("Exit %s", GetErrorMessage(r));
776         return;
777         CATCH:
778         if (pDirectoriesList != null)
779         {
780                 pDirectoriesList->RemoveAll(true);
781                 delete pDirectoriesList;
782                 pDirectoriesList = null;
783         }
784
785         if (pFilesList != null)
786         {
787                 pFilesList->RemoveAll(true);
788                 delete pFilesList;
789                 pFilesList = null;
790         }
791 }
792
793 void
794 FolderEntryPresentationModel::OnFileEventOccured(unsigned long events, const Tizen::Base::String& path, unsigned int eventId)
795 {
796         AppLogDebug("OnFileEventOccured");
797         if (__pFolderEntryEventListener != null)
798         {
799                 UpdateFileListEnteries(events, path);
800                 AppLogDebug("%d", __pFolderEntries->GetCount());
801                 __pFolderEntryEventListener->OnFileEventExecuted(path, events);
802         }
803 }
804
805 void
806 FolderEntryPresentationModel::SetFileEventListener(IFolderEntryEventListener* pIFileEventNotification)
807 {
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)
813         {
814                 r = __pFileEventManager->AddPath(__currentFilePath, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_DELETE);
815         }
816         else
817         {
818                 if (__pFileEventManager != null)
819                 {
820                         r = __pFileEventManager->RemovePath(__currentFilePath);
821                 }
822                 AppLogDebug("its null %s", GetErrorMessage(r));
823         }
824 }
825
826 void
827 FolderEntryPresentationModel::SetFolderEntryType(FileType currentType)
828 {
829         __entryType = currentType;
830 }
831
832 void
833 FolderEntryPresentationModel::SetViewType(AppControlView currentView)
834 {
835         __currentViewType = currentView;
836 }
837
838 void
839 FolderEntryPresentationModel::UpdateFileListEnteries(const unsigned long events, const Tizen::Base::String& path)
840 {
841         AppLogDebug("Entry");
842         switch (events)
843         {
844         case FILE_EVENT_TYPE_CREATE:
845         {
846                 DirectoryEntry* pDirStr = new (std::nothrow) DirectoryEntry();
847                 String delim(L".");
848                 String token;
849                 String filePath;
850                 StringTokenizer strTok(path, delim);
851                 int dirCount = 0;
852                 int fileCount = 0;
853                 String fileName;
854
855                 filePath = pDirStr->GetFullFilePath();
856                 filePath.Append(__currentFilePath);
857                 filePath.Append(path);
858                 pDirStr->SetFullFilePath(filePath);
859
860                 //pDirStr->fileName.Append(path);
861                 while (strTok.HasMoreTokens())
862                 {
863                         strTok.GetNextToken(token);
864                         fileName = pDirStr->GetFileName();
865                         fileName.Append(token);
866                         pDirStr->SetFileName(fileName);
867                         //pDirStr->__fileName.Append(token);
868                         break;
869                 }
870                 pDirStr->SetCheckDirectory(false);
871
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());
878         }
879         break;
880
881         case FILE_EVENT_TYPE_DELETE:
882         {
883                 DirectoryEntry* pDirStr = null;
884                 int index = 0;
885
886                 for (int entriesCount = 0; entriesCount < __pFolderEntries->GetCount(); entriesCount++)
887                 {
888                         pDirStr = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(entriesCount));
889                         String fileName;
890                         if (pDirStr != null)
891                         {
892                                 fileName.Append(pDirStr->GetFileName());
893                                 fileName.Append(L".");
894                                 fileName.Append(pDirStr->GetFileExtension());
895                                 if (path == fileName)
896                                 {
897                                         index = entriesCount;
898                                         break;
899                                 }
900                         }
901                 }
902                 __pFolderEntries->RemoveAt(index, true);
903         }
904         break;
905
906         case FILE_EVENT_TYPE_DELETE_SELF:
907         {
908                 //ShowHomeView();
909         }
910         break;
911
912         default:
913                 break;
914         }
915         AppLogDebug("Exit %s", GetErrorMessage(GetLastResult()));
916 }
917
918 result
919 FolderEntryPresentationModel::InitThumbnailManager(void)
920 {
921         result r = E_SUCCESS;
922         DirectoryEntry* pDirEntry = null;
923
924         AppLogDebug("Enter");
925
926         __forceStop = false;
927         StopThumbnailManager();
928
929         __requestId =0;
930         __ThumbnailRequestInProgress = false;
931
932         TryReturn(__pThumbnailManager != null, E_FAILURE, "Thumbnails could not be generated");
933         TryReturn((__pFolderEntries != null) && (__pFolderEntries->GetCount() != 0) && (__requestId >= 0),E_FAILURE, "Invalid Arguments!");
934
935         pDirEntry = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(__requestId));
936         TryCatch(pDirEntry != null,r=E_FAILURE , "FileEntry list is empty!");
937
938         if (!pDirEntry->IsDirectory() )
939         {
940                 pDirEntry->SetLoadBitmap(true);
941                 pDirEntry->SetDummy(true);
942         }
943
944         if (!__ThumbnailRequestInProgress && pDirEntry->GetLoadBitmap())
945         {
946                 __ThumbnailRequestInProgress = true;
947                 r = StartThumbnailRequest(__requestId);
948         }
949         return r;
950         CATCH:
951         if ( __requestId >= __pFolderEntries->GetCount()-1)
952                 __requestId = INVALID_INDEX;
953         else
954                 __requestId++;
955         return r;
956 }
957
958 result
959 FolderEntryPresentationModel::StartThumbnailRequest(int ReqIndex)
960 {
961         result r = E_SUCCESS;
962         ArrayList* pList = null;
963         ThumbRequest* pThumbReq = null;
964         DirectoryEntry* pDirEntry = null;
965
966         AppLogDebug("Enter [%d]", ReqIndex);
967         __requestId = ReqIndex;
968
969         if (__forceStop)
970         {
971                 StopThumbnailManager();
972                 return E_FAILURE;
973         }
974
975         TryReturn(__pThumbnailManager != null, E_FAILURE, "Thumbnails could not be generated");
976         TryCatch((__pFolderEntries != null) && (__pFolderEntries->GetCount() != 0) && (__requestId >= 0), , "Invalid Arguments!");
977
978         if ( __requestId > __pFolderEntries->GetCount()-1 )
979         {
980                 StopThumbnailManager();
981                 return E_FAILURE;
982         }
983
984         pDirEntry = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(__requestId));
985         TryCatch(pDirEntry != null, , "FileEntry list is empty!");
986
987         if (pDirEntry->GetBitmap() == null && /* pDirEntry->IsDummy()  && */!pDirEntry->IsDirectory() )
988         {
989                 pThumbReq = new (std::nothrow) ThumbRequest(__sourceForm);
990                 TryCatch(pThumbReq != null, , "ThumbRequest is null!");
991
992                 pThumbReq->iRquestId = __requestId;
993                 pThumbReq->currentRequestId = __currentRequestId;
994                 pThumbReq->FilePath = pDirEntry->GetFullFilePath();
995
996                 pList = new (std::nothrow) ArrayList();
997                 TryCatch(pList != null, , "ArrayList is null!");
998
999                 r = pList->Construct();
1000                 TryCatch(r == E_SUCCESS, , "ArrayList is null!");
1001
1002                 pList->Add(pThumbReq);
1003                 __pThumbnailManager->SendUserEvent(ThumbnailManager::THUMB_MGR_GET_THUMBNAIL, pList);
1004         }
1005         else
1006         {
1007                 __requestId++;
1008                 StartThumbnailRequest(__requestId);
1009         }
1010         return r;
1011         CATCH:
1012         if (pList != null)
1013         {
1014                 pList->RemoveAll(false);
1015                 delete pList;
1016         }
1017         if (pThumbReq != null)
1018         {
1019                 delete pThumbReq;
1020         }
1021         AppLogDebug("FLPM Error occured: Entered inputs are invalid!");
1022         Application::GetInstance()->SendUserEvent(THUMBNAIL_FAILED, null);
1023         __ThumbnailRequestInProgress = false;
1024
1025         if ( __requestId >= __pFolderEntries->GetCount()-1)
1026         {
1027                 __requestId = INVALID_INDEX;
1028                 StopThumbnailManager();
1029         }
1030         else
1031         {
1032                 __requestId++;
1033         }
1034         AppLogDebug("Exit");
1035         return r;
1036 }
1037
1038 result
1039 FolderEntryPresentationModel::OnThumbnailResponseReceived(Tizen::Graphics::Bitmap* pThumb, int index)
1040 {
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;
1047
1048         HashMap* pCacheList = null;
1049
1050         __ThumbnailRequestInProgress = false;
1051         if ( __forceStop )
1052         {
1053                 StopThumbnailManager();
1054                 return E_FAILURE;
1055         }
1056
1057         TryCatch(__pFolderEntries != null && __pFolderEntries->GetCount() != 0, , "Invalid Arguments");
1058         TryCatch(__requestId != INVALID_INDEX, , "Item index reached to maximum value!");
1059
1060         pDirEntry = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index));
1061         TryCatch(pDirEntry != null, , "Invalid directory entry pointer!");
1062
1063         if (index > INVALID_INDEX && pThumb != null)
1064         {
1065                 if (__requestId == index)
1066                 {
1067                         pDirEntry->SetDummy(false);
1068                         pDirEntry->SetLoadBitmap(false);
1069                         pDirEntry->SetBitmap(pThumb);
1070                 }
1071
1072                 pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
1073                 TryCatch(pCacheList != null, , "Cache Hashmap  is null");
1074
1075                 cacheImagePath = pDirEntry->GetFullFilePath();
1076
1077
1078                 contentType = ContentManagerUtil::CheckContentType(cacheImagePath);
1079
1080                 if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
1081                 {
1082                         if ((pCacheList->GetValue(cacheImagePath)) == null)
1083                         {
1084                                 cachePath = new (std::nothrow) String(pDirEntry->GetFullFilePath());
1085                                 if (cachePath != null)
1086                                         __pCacheManager->AddCacheEntry(*cachePath,pThumb);
1087                         }
1088                 }
1089         }
1090
1091         FolderEntryCount = __pFolderEntries->GetCount();
1092
1093         if (pDirEntry->GetLoadBitmap())
1094         {
1095                 if (__requestId < FolderEntryCount )
1096                 {
1097                         __requestId++;
1098                         StartThumbnailRequest(__requestId);
1099                 }
1100                 else if (__requestId >= FolderEntryCount)
1101                 {
1102                         __requestId = INVALID_INDEX;
1103                         __ThumbnailRequestInProgress = false;
1104                         StopThumbnailManager();
1105                 }
1106         }
1107         else
1108         {
1109                 __requestId++;
1110                 StartThumbnailRequest(__requestId);
1111         }
1112         return r;
1113
1114 CATCH:
1115
1116         if (pThumb != null)
1117         {
1118                 delete pThumb;
1119         }
1120         if (!__ThumbnailRequestInProgress)
1121         {
1122                 if(__requestId >= __pFolderEntries->GetCount()-1 )
1123                         StopThumbnailManager();
1124                 else
1125                         __requestId++;
1126         }
1127
1128         AppLogDebug("Exit");
1129         return r;
1130 }
1131
1132 result
1133 FolderEntryPresentationModel::OnThumbnailResponseFailed(int index)
1134 {
1135         result r = E_SUCCESS;
1136         int FolderEntryCount = INVALID_INDEX;
1137         DirectoryEntry* pDirEntry = null;
1138
1139         AppLogDebug("Current ReqId : %d %d", __requestId, index);
1140
1141         if ( __forceStop )
1142         {
1143                 StopThumbnailManager();
1144                 return E_FAILURE;
1145         }
1146
1147         TryCatch((__pFolderEntries != null) && (__pFolderEntries->GetCount() != 0), r= E_FAILURE, "Data not found");
1148         AppLogDebug("ThumbnailResponseFailed : Request id [%d], Index [%d]", __requestId, index);
1149
1150         __ThumbnailRequestInProgress = false;
1151
1152         pDirEntry = static_cast< DirectoryEntry* >(__pFolderEntries->GetAt(index));
1153         TryCatch(pDirEntry != null, , "Invalid parameters!");
1154
1155         FolderEntryCount = __pFolderEntries->GetCount();
1156
1157         if (pDirEntry->GetLoadBitmap())
1158         {
1159                 if (__requestId < FolderEntryCount )
1160                 {
1161                         __requestId++;
1162                         StartThumbnailRequest(__requestId);
1163                 }
1164                 else if (__requestId >= FolderEntryCount)
1165                 {
1166                         __requestId = INVALID_INDEX;
1167                         __ThumbnailRequestInProgress = false;
1168                         StopThumbnailManager();
1169                 }
1170         }
1171         else
1172         {
1173                 __requestId++;
1174                 StartThumbnailRequest(__requestId);
1175         }
1176         AppLogDebug("EXIT : %s", GetErrorMessage(r));
1177         CATCH:
1178         __ThumbnailRequestInProgress = false;
1179
1180         if(__requestId >= __pFolderEntries->GetCount()-1 )
1181                 StopThumbnailManager();
1182         else
1183                 __requestId++;
1184         return r;
1185 }
1186
1187 result
1188 FolderEntryPresentationModel::SetListUpdateEventListener(IListViewStateChangeListener* pListener)
1189 {
1190         result r = E_SUCCESS;
1191 #if 0
1192         __pListUpdateListener = pListener;
1193 #endif
1194         return r;
1195
1196 }
1197
1198 result
1199 FolderEntryPresentationModel::StopThumbnailManager(bool bForceStop)
1200 {
1201         result r = E_SUCCESS;
1202
1203         AppLogDebug("StopThumbnailManager [%d]", __requestId);
1204
1205         __forceStop = bForceStop;
1206
1207         TryCatch(__pThumbnailManager != null, r=E_FAILURE, "Thumbnails could not be generated");
1208         __pThumbnailManager->SendUserEvent(ThumbnailManager::THUMB_MGR_STOP, null);
1209         CATCH:
1210         __ThumbnailRequestInProgress = false;
1211         __requestId = INVALID_INDEX;
1212
1213         AppLogDebug("StopThumbnailManager--");
1214         return r;
1215 }
1216
1217 void
1218 FolderEntryPresentationModel::SetSortEnabled(bool enableFlag)
1219 {
1220         __enableSort = enableFlag;
1221 }
1222 IFolderEntryProviderListener::~IFolderEntryProviderListener(void)
1223 {
1224         //empty Implementation
1225 }
1226
1227 void
1228 FolderEntryPresentationModel::SetSourceForm(CreateItemSource currentSource)
1229 {
1230         __sourceForm = currentSource;
1231 }
1232
1233 CreateItemSource
1234 FolderEntryPresentationModel::GetSourceForm(void)
1235 {
1236         return __sourceForm;
1237 }
1238 void
1239 FolderEntryPresentationModel::SetCurrentReqId(int currentRequestId)
1240 {
1241         __currentRequestId = currentRequestId;
1242 }
1243 int
1244 FolderEntryPresentationModel::GetCurrentReqId(void)
1245 {
1246         return __currentRequestId;
1247 }
1248 void
1249 FolderEntryPresentationModel::CreateStack(void)
1250 {
1251         if (__pFolderEntryStack == null)
1252         {
1253                 __pFolderEntryStack = new (std::nothrow) Stack();
1254                 __pFolderEntryStack->Construct();
1255         }
1256 }
1257
1258 void
1259 FolderEntryPresentationModel::CreateTraversalTree(void)
1260 {
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;
1272
1273         if (__pFolderEntries != null)
1274         {
1275                 __pFolderEntries->RemoveAll(true);
1276         }
1277         else
1278         {
1279                 __pFolderEntries = new (std::nothrow) ArrayList();
1280                         r = __pFolderEntries->Construct();
1281         }
1282
1283         if (pDeviceList == null)
1284         {
1285                 pDeviceList = new (std::nothrow) ArrayList();
1286                 pDeviceList->Construct();
1287         }
1288
1289         GetDeviceList(pDeviceList);
1290         deviceListCount = pDeviceList->GetCount();
1291
1292         __deviceListCount = deviceListCount;
1293
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");
1299
1300         while (deviceListCount > 0)
1301         {
1302                 while (__pFolderEntryStack->GetCount() > 0)
1303                 {
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)
1309                         {
1310                                 DirEntry currentDirEntry = pCurrentDirectoryEnum->GetCurrentDirEntry();
1311                                 String directoryName = currentDirEntry.GetName();
1312
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)
1319                                 {
1320                                         directoryName.Remove(directoryName.GetLength() - fileExtensionLength - 1, fileExtensionLength + 1);
1321                                 }
1322                                 pCurrentFolderEntry->SetFullFilePath(fullPath);
1323                                 pCurrentFolderEntry->SetFileName(directoryName);
1324                                 pCurrentFolderEntry->SetCheckDirectory(false);
1325                                 pCurrentFolderEntry->SetCreationTime(currentDirEntry.GetDateTime());
1326
1327                                 if(currentDirEntry.IsDirectory() && directoryName != "." && directoryName != "..")
1328                                 {
1329                                         AppLogDebug("SearchPresentationModel::Search::");
1330                                         if (__sourceForm == CREATE_ITEM_SOURCE_SEARCH_FORM)
1331                                         {
1332                                                 AppLogDebug("SearchPresentationModel::Search::%S", pCurrentFolderEntry->GetFullFilePath().GetPointer());
1333                                                 pCurrentFolderEntry->SetCheckDirectory(true);
1334                                                 __pFolderEntries->Add(pCurrentFolderEntry);
1335                                         }
1336                                         else
1337                                         {
1338                                                 delete pCurrentFolderEntry;
1339                                                 pCurrentFolderEntry = null;
1340                                         }
1341                                         String pathtoPush = *currentDirectoryPath + directoryName + "/";
1342                                         r = __pFolderEntryStack->Push(new (std::nothrow) String(pathtoPush));
1343                                         TryCatch(r == E_SUCCESS, ,"push failed");
1344                                 }
1345                                 else if (!(directoryName.StartsWith(L".", 0)) && !currentDirEntry.IsHidden())
1346                                 {
1347                                         contentType = ContentManagerUtil::CheckContentType(fullPath);
1348                                         r = GetLastResult();
1349                                         fileExtension = pCurrentFolderEntry->GetFileExtension();
1350
1351                                         if (__entryType == FILE_TYPE_ALL)
1352                                         {
1353                                                 __pFolderEntries->Add(pCurrentFolderEntry);
1354                                         }
1355                                         else if (__entryType == FILE_TYPE_VIDEO_TYPE)
1356                                         {
1357                                                 if (contentType == CONTENT_TYPE_VIDEO)
1358                                                 {
1359                                                         __pFolderEntries->Add(pCurrentFolderEntry);
1360                                                 }
1361                                                 else
1362                                                 {
1363                                                         delete pCurrentFolderEntry;
1364                                                         pCurrentFolderEntry = null;
1365                                                 }
1366                                         }
1367                                         else if (__entryType == FILE_TYPE_IMAGE_TYPE)
1368                                         {
1369                                                 if (contentType == CONTENT_TYPE_IMAGE)
1370                                                 {
1371                                                         __pFolderEntries->Add(pCurrentFolderEntry);
1372                                                 }
1373                                                 else
1374                                                 {
1375                                                         delete pCurrentFolderEntry;
1376                                                         pCurrentFolderEntry = null;
1377                                                 }
1378                                         }
1379                                         else if (__entryType == FILE_TYPE_AUDIO_TYPE)
1380                                         {
1381                                                 if (contentType == CONTENT_TYPE_AUDIO)
1382                                                 {
1383                                                         __pFolderEntries->Add(pCurrentFolderEntry);
1384                                                 }
1385                                                 else
1386                                                 {
1387                                                         delete pCurrentFolderEntry;
1388                                                         pCurrentFolderEntry = null;
1389                                                 }
1390                                         }
1391                                         else if (__entryType == FILE_TYPE_DOCUMENT_TYPE)
1392                                         {
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"))
1400                                                 {
1401                                                         __pFolderEntries->Add(pCurrentFolderEntry);
1402                                                 }
1403                                                 else
1404                                                 {
1405                                                         delete pCurrentFolderEntry;
1406                                                         pCurrentFolderEntry = null;
1407                                                 }
1408                                         }
1409                                         else if (__entryType == FILE_TYPE_CONTACTS_TYPE)
1410                                         {
1411                                                 if ( fileExtension.EndsWith(L"vcs") || fileExtension.EndsWith(L"VCS"))
1412                                                 {
1413                                                         __pFolderEntries->Add(pCurrentFolderEntry);
1414                                                 }
1415                                                 else
1416                                                 {
1417                                                         delete pCurrentFolderEntry;
1418                                                         pCurrentFolderEntry = null;
1419                                                 }
1420                                         }
1421                                         else if (__entryType == FILE_TYPE_OTHER_TYPE)
1422                                         {
1423                                                 if (contentType == CONTENT_TYPE_OTHER || r != E_SUCCESS)
1424                                                 {
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")
1432                                                         ))
1433                                                         {
1434                                                                 delete pCurrentFolderEntry;
1435                                                                 pCurrentFolderEntry = null;
1436                                                         }
1437                                                         else
1438                                                         {
1439                                                                 __pFolderEntries->Add(pCurrentFolderEntry);
1440                                                         }
1441                                                 }
1442                                                 else
1443                                                 {
1444                                                         delete pCurrentFolderEntry;
1445                                                         pCurrentFolderEntry = null;
1446                                                 }
1447                                         }
1448                                         else
1449                                         {
1450                                                 delete pCurrentFolderEntry;
1451                                                 pCurrentFolderEntry = null;
1452                                         }
1453                                 }
1454                         }
1455                         //if(pCurrentDirectory != null)
1456                         //{
1457                                 delete pCurrentDirectory;
1458                                 pCurrentDirectory = null;
1459                         //}
1460                         //if(pCurrentDirectoryEnum != null)
1461                         //{
1462                                 delete pCurrentDirectoryEnum;
1463                                 pCurrentDirectoryEnum = null;
1464                         //}
1465                         currentDirectoryPath = static_cast<String *>(__pFolderEntryStack->Pop());
1466                         TryCatch(currentDirectoryPath !=null, , "Pop Failed");
1467                 }
1468                 if (currentDirectoryPath != null)
1469                 {
1470                         delete currentDirectoryPath;
1471                         currentDirectoryPath = null;
1472                 }
1473                 deviceListCount --;
1474
1475                 if (deviceListCount > 0)
1476                 {
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");
1481                 }
1482         }
1483
1484         /*if (currentDirectoryPath != null)
1485         {
1486                 delete currentDirectoryPath;
1487                 currentDirectoryPath = null;
1488         }*/
1489
1490         //todo Commented to remove warning
1491 //      for(int count = 0; count<__pFolderEntries->GetCount(); count++)
1492 //      {
1493 //              DirectoryEntry* pName = (DirectoryEntry *)__pFolderEntries->GetAt(count);
1494 //      }
1495
1496
1497         pDeviceList->RemoveAll(true);
1498         delete pDeviceList;
1499         pDeviceList = null;
1500
1501
1502         return;
1503 CATCH:
1504         if (currentDirectoryPath != null)
1505         {
1506                 delete currentDirectoryPath;
1507                 currentDirectoryPath = null;
1508         }
1509         if (__pFolderEntryStack != null)
1510         {
1511                 __pFolderEntryStack->RemoveAll(true);
1512         }
1513         if (pCurrentDirectory != null)
1514         {
1515                 delete pCurrentDirectory;
1516                 pCurrentDirectory = null;
1517         }
1518
1519         pDeviceList->RemoveAll(true);
1520         delete pDeviceList;
1521         pDeviceList = null;
1522
1523 }
1524
1525 void
1526 FolderEntryPresentationModel::GetDeviceList(Tizen::Base::Collection::ArrayList* pDeviceList)
1527 {
1528         String deviceSateSdCard;
1529         String deviceSateUsbClient;
1530         String mounted = sdCardStatusMounted;
1531         String inserted = usbDeviceStatusInserted;
1532
1533         pDeviceList->Add(new (std::nothrow) String(BasePresentationModel::GetMediaPath()));
1534
1535         DeviceManager::GetState(StorageCard, deviceSateSdCard);
1536 #if 0
1537         DeviceManager::GetState(UsbClient, deviceSateUsbClient);
1538 #endif
1539
1540         if (deviceSateSdCard == mounted)
1541         {
1542                 pDeviceList->Add(new (std::nothrow) String(BasePresentationModel::GetSdCardPath()));
1543         }
1544         if (deviceSateUsbClient == inserted)
1545         {
1546                 pDeviceList->Add(new (std::nothrow) String(BasePresentationModel::GetUsbPath()));
1547         }
1548 }
1549 void
1550 FolderEntryPresentationModel::GetSortFolderEntryCount(int& currentDirectoryCount, int& currentFileCount)
1551 {
1552         bool directoryCheck = true;
1553         DirectoryEntry* pcurrentEntry = null;
1554         int currentCount = 0;
1555         if (__pFolderEntries == null || __pFolderEntries->GetCount() == 0)
1556         {
1557                 currentDirectoryCount = 0;
1558                 currentFileCount = 0;
1559                 return;
1560         }
1561         currentDirectoryCount = 0;
1562         currentFileCount = 0;
1563         pcurrentEntry = static_cast<DirectoryEntry*>(__pFolderEntries->GetAt(currentCount));
1564         directoryCheck = pcurrentEntry->IsDirectory();
1565         while (__pFolderEntries->GetCount()>0 && directoryCheck)
1566         {
1567                 currentCount++;
1568                 pcurrentEntry = static_cast<DirectoryEntry*>(__pFolderEntries->GetAt(currentCount));
1569                 if (pcurrentEntry == null)
1570                 {
1571                         break;
1572                 }
1573                 directoryCheck = pcurrentEntry->IsDirectory();
1574         }
1575         currentDirectoryCount = currentCount;
1576         currentFileCount = __pFolderEntries->GetCount() - currentCount;
1577 }
1578
1579 int
1580 FolderEntryPresentationModel::GetDeviceListCount(void)
1581 {
1582         return __deviceListCount;
1583 }