N_SE-36744 N_SE-36750 N_SE-36754 N_SE-36743
[apps/osp/MyFiles.git] / src / MfCategorySearch.cpp
1
2 #include "MfCategorySearch.h"
3 #include "MfBasePresentationModel.h"
4 #include "MfMyFilesApp.h"
5
6
7 using namespace Tizen::Base;
8 using namespace Tizen::Base::Collection;
9 using namespace Tizen::App;
10 using namespace Tizen::Graphics;
11 using namespace Tizen::Io;
12 using namespace Tizen::Ui;
13 using namespace Tizen::Ui::Controls;
14 using namespace Tizen::Ui::Scenes;
15 using namespace Tizen::System;
16 using namespace Tizen::Base::Utility;
17
18 CategorySearch::CategorySearch(void)
19 :__pHomeButton(null)
20 ,__pUpButton(null)
21 ,__pHeader(null)
22 {
23         __currentFileType = FILE_TYPE_OTHER_TYPE;
24         __counter = 0;
25 }
26
27 CategorySearch::~CategorySearch(void)
28 {
29         DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
30
31         if (__pHomeButton != null)
32         {
33                 delete __pHomeButton;
34         }
35
36         if (__pUpButton != null)
37         {
38                 delete __pUpButton;
39         }
40 }
41
42 bool
43 CategorySearch::Initialize(void)
44 {
45         Form::Construct(L"IDL_CATEGORY_SEARCH");
46         return true;
47 }
48
49 result
50 CategorySearch::OnInitializing(void)
51 {
52         result r = E_SUCCESS;
53         CreateItemSource createitemsource = CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM;
54         int sourceForm = THUMBNAIL_PROVIDER_SOURCEID_CATEGORY_SEARCH_FORM;
55
56         String path;
57         String rootParentPath;
58         String buttonHome;
59         String buttonUp;
60         String extensionVisibility;
61         String currentDirectoryPath = BasePresentationModel::GetMediaPath();
62
63         Bitmap* pBitmapHomeButton = null;
64         Bitmap* pBitmapUpButton = null;
65         Bitmap* pBitmapHomeButtonPress = null;
66         Bitmap* pBitmapUpButtonPress = null;
67         AppResource* pAppResource = null;
68
69         if (_pFolderEntryPM == null)
70         {
71                 _pFolderEntryPM = new (std::nothrow) FolderEntryPresentationModel();
72                 AppAssert(_pFolderEntryPM != null);
73                 r = _pFolderEntryPM->Construct();
74                 AppAssert(r==E_SUCCESS);
75                 _pFolderEntryPM->SetSourceForm(createitemsource);
76         }
77
78         _pBaseItemProvider = new (std::nothrow) BaseItemProvider();
79         TryCatch(_pBaseItemProvider != null, , "Failed to allocate base itemprovider");
80         _pBaseItemProvider->Construct();
81         _pBaseItemProvider->SetSourceForm(createitemsource);
82         _pBaseItemProvider->SetFolderEntryProvider(this);
83         _pBaseItemProvider->SetFooterItemStateChangeListener(this);
84
85         _pListView = static_cast<ListView *>(GetControl(L"IDC_LISTVIEW_CATEGORY_SEARCH"));
86         TryCatch(_pListView != null, , "__pListView is Null");
87         _pListView->AddListViewItemEventListener(*this);
88         _pListView->SetItemProvider(*this);
89         _pListView->SetItemProvider(*_pBaseItemProvider);
90
91         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
92
93         pAppResource = UiApp::App::GetInstance()->GetAppResource();
94         TryCatch(pAppResource != null, , "Resource manager not found!");
95
96         pAppResource->GetString(L"IDS_MF_BUTTON_HOME", buttonHome);
97         pAppResource->GetString(L"IDS_MF_TAB_UP", buttonUp);
98         pAppResource->GetString(L"IDS_MF_OPT_SHOW_FILE_EXTENSION", _showExtension);
99         pAppResource->GetString(L"IDS_MF_OPT_HIDE_FILE_EXTENSION_ABB", _hideExtension);
100         pBitmapHomeButton = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
101         pBitmapUpButton = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
102         pBitmapHomeButtonPress = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
103         pBitmapUpButtonPress = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
104         extensionVisibility = fileExtenstionKeyName;
105
106         __pHeader = GetHeader();
107         _extensionKeyName.Append(extensionVisibility);
108
109         createitemsource = CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM;
110
111         //Initialize the itemprovider class for the listview inside the popup
112         if (_pCustomListViewForPopup == null)
113         {
114                 _pCustomListViewForPopup = new (std::nothrow) CustomListViewForPopup();
115         }
116         TryCatch(_pCustomListViewForPopup != null, , "MfMyFilesApp::ListView For Popup not created!");
117
118         _pCustomListViewForPopup->SetEventListener(this);
119
120
121         if (_pThumbnailItemProvider == null)
122         {
123                 _pThumbnailItemProvider = new (std::nothrow) ThumbnailItemProviderAndListener(currentDirectoryPath, sourceForm);
124                 _pThumbnailItemProvider->SetFolderEntryProvider(this);
125         }
126         TryCatch(_pThumbnailItemProvider != null, , "Failed to allocate Memory to __pSubFolderThumbnailsProvider");
127
128         _pThumbnailItemProvider->SetFooterItemStateChangeListener(this);
129
130         _pIconListView = static_cast< IconListView* >(GetControl("IDC_ICONLISTVIEW_CATEGORY_SEARCH"));
131         TryCatch(_pIconListView != null, , "__pIconListviewSubThumbnails is Null");
132         _pIconListView->SetItemProvider(*_pThumbnailItemProvider);
133         _pIconListView->AddIconListViewItemEventListener(*this);
134         _pIconListView->AddTouchEventListener(*this);
135         _pIconListView->SetShowState(false);
136
137         _pLongPressGestureDetector = new (std::nothrow) TouchLongPressGestureDetector();
138         _pLongPressGestureDetector->Construct();
139
140         delete pBitmapHomeButton;
141         delete pBitmapUpButton;
142         delete pBitmapHomeButtonPress;
143         delete pBitmapUpButtonPress;
144
145         CreateFooterControls();
146         //Set FormBackEvent Listener
147         SetFormBackEventListener(this);
148         _pFileManager = FolderEntryEditorPresentationModel::GetInstance();
149
150         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
151
152         return r;
153 CATCH:
154         AppLogDebug("caught exception");
155         if (__pHomeButton != null)
156         {
157                 delete __pHomeButton;
158                 __pHomeButton = null;
159         }
160
161         if (__pUpButton != null)
162         {
163                 delete __pUpButton;
164                 __pUpButton = null;
165         }
166
167         if (_pCustomListViewForPopup != null)
168         {
169                 delete _pCustomListViewForPopup;
170                 _pCustomListViewForPopup = null;
171         }
172
173         if (pBitmapHomeButton != null)
174         {
175                 delete pBitmapHomeButton;
176                 pBitmapHomeButton = null;
177         }
178
179         if (pBitmapUpButton != null)
180         {
181                 delete pBitmapUpButton;
182                 pBitmapUpButton = null;
183         }
184         if (pBitmapHomeButtonPress != null)
185         {
186                 delete pBitmapHomeButtonPress;
187                 pBitmapHomeButtonPress = null;
188         }
189         if (pBitmapUpButtonPress != null)
190         {
191                 delete pBitmapUpButtonPress;
192                 pBitmapUpButtonPress = null;
193         }
194         return r;
195 }
196
197 result
198 CategorySearch::OnTerminating(void)
199 {
200         result r = E_SUCCESS;
201         //((MfMyFilesApp*)Application::GetInstance())->SetCurrentView(null);
202
203         _pFooter = GetFooter();
204         if (_pFooter != null)
205         {
206                 _pFooter->RemoveAllButtons();
207                 _pFooter->RemoveAllItems();
208         }
209
210         __pHeader = GetHeader();
211         if (__pHeader != null)
212         {
213                 __pHeader->RemoveAllButtons();
214                 __pHeader->RemoveAllItems();
215         }
216
217         return r;
218 }
219
220
221
222 void
223 CategorySearch::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
224 {
225         AppLogDebug("Entry");
226
227         DirectoryEntry* pCheckedEntry = null;
228         String selected;
229         String fullPath;
230         String fileName;
231         result r = E_SUCCESS;
232         MemoryType currentMemoryType = MEMORY_TYPE_PHONE;
233         ArrayList* pArgs = null;
234         SceneManager* pSceneManager = null;
235         AppResource* pAppResource = null;
236         CustomAppControl* pCustomAppControl = CustomAppControl::GetInstance();
237         pAppResource = UiApp::GetInstance()->GetAppResource();
238         pSceneManager = SceneManager::GetInstance();
239         if (pAppResource != null)
240         {
241                 pAppResource->GetString(L"IDS_COM_BODY_SELECTED", selected);
242         }
243         pCheckedEntry = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
244
245         if (pCheckedEntry == null)
246         {
247                 return;
248         }
249
250         _indexTracker  = index;
251 //      if (elementId == CONTENT_LIST_ITEM_TYPE_RENAME || elementId == DETAILED_LIST_ELEMENTS_RENAME)
252         if (status == LIST_ITEM_STATUS_MORE/* || elementId == DETAILED_LIST_ELEMENTS_RENAME*/)
253         {
254                 if (pArgs == null)
255                 {
256                         pArgs = new (std::nothrow) ArrayList();
257                         pArgs->Construct();
258                 }
259
260                 fullPath = pCheckedEntry->GetFullFilePath();
261                 GetParentFolderPath(&fullPath);
262                 FolderNavigationPresentationModel::SetCurrentFilePath(fullPath);
263
264                 if (fullPath.StartsWith(BasePresentationModel::GetMediaPath(),0))
265                 {
266                         currentMemoryType = MEMORY_TYPE_PHONE;
267                         FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
268                 }
269                 else if(fullPath.StartsWith(BasePresentationModel::GetSdCardPath(),0))
270                 {
271                         currentMemoryType = MEMORY_TYPE_SD_CARD;
272                         FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
273                 }
274
275                 GetFileName(&fullPath);
276                 pArgs->Add(fullPath);
277                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArgs);
278                 return;
279         }
280
281         if (_pFileEventManager != null)
282         {
283                 _pFileEventManager->RemovePath(_pathOfSelectedFile);
284                 delete _pFileEventManager;
285                 _pFileEventManager = null;
286         }
287         _pathOfSelectedFile = pCheckedEntry->GetFullFilePath();
288         AppLogDebug("Selected File path : %S", _pathOfSelectedFile.GetPointer());
289
290         _pFileEventManager = new (std::nothrow)FileEventManager();
291         _pFileEventManager->Construct(*this);
292
293         String FileName = pCheckedEntry->GetFileName() + "." + pCheckedEntry->GetFileExtension();
294         String parentDirectoryOfSelectedFile = L"";
295         _pathOfSelectedFile.SubString(0, _pathOfSelectedFile.GetLength() - FileName.GetLength() , parentDirectoryOfSelectedFile);
296
297         _pFileEventManager->AddPath(parentDirectoryOfSelectedFile, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_MOVED_TO | FILE_EVENT_TYPE_MOVED_FROM);
298
299         if (pCustomAppControl != null)
300         {
301                 __counter = index;
302                 pCustomAppControl->SetAppControlListener(null);
303                 AppControl* pAppControlInUse = pCustomAppControl->LaunchAppControl(_pathOfSelectedFile);
304                 if (pAppControlInUse != null)
305                         CustomAppControl::SetAppControlInUse(pAppControlInUse);
306         }
307 }
308
309 // ISceneEventListener
310 void
311 CategorySearch::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
312 {
313         //__currentFileType
314         AppLogDebug("Enter");
315         Integer* fileType;
316         int currentType;
317         String* headerTitleText;
318         AppRegistry* pAppRegistry = null;
319         String viewStyleKeyName(L"ListDisplayType");
320         int listViewDisplayType = VIEW_TYPE_AS_NORMAL_LIST;
321
322         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
323
324         pAppRegistry->Get(viewStyleKeyName, listViewDisplayType);
325         _flagViewAsStatus = listViewDisplayType;
326
327         SceneManager::GetInstance()->AddSceneManagerEventListener(*this);
328
329         SetCurrentDirectoryFlag(false);
330
331         if (pArgs != null)
332         {
333                 fileType = static_cast< Integer* >(pArgs->GetAt(0));
334                 currentType = fileType->ToInt();
335                 headerTitleText = static_cast< String* >(pArgs->GetAt(1));
336                 if (headerTitleText != null)
337                 {
338                         __currentHeaderText = *headerTitleText;
339                         __pHeader->SetTitleText(__currentHeaderText);
340                 }
341
342                 switch (currentType)
343                 {
344                 case FILE_TYPE_IMAGE_TYPE:
345                 {
346                         AppLogDebug("File type is image");
347                         __currentFileType = FILE_TYPE_IMAGE_TYPE;
348                 }
349                 break;
350
351                 case FILE_TYPE_VIDEO_TYPE:
352                 {
353                         __currentFileType = FILE_TYPE_VIDEO_TYPE;
354                 }
355                 break;
356
357                 case FILE_TYPE_AUDIO_TYPE:
358                 {
359                         __currentFileType = FILE_TYPE_AUDIO_TYPE;
360                 }
361                 break;
362
363                 case FILE_TYPE_DOCUMENT_TYPE:
364                 {
365                         __currentFileType = FILE_TYPE_DOCUMENT_TYPE;
366                 }
367                 break;
368
369                 case FILE_TYPE_OTHER_TYPE:
370                 {
371                         __currentFileType = FILE_TYPE_OTHER_TYPE;
372                 }
373                 break;
374
375                 default:
376                         break;
377                 }
378         }
379
380         if (_pFileManager != null)
381         {
382                 _pFileManager->SetFileManagingListener(this);
383         }
384
385         if (pArgs != null)
386         {
387                 pArgs->RemoveAll(true);
388                 delete pArgs;
389                 pArgs = null;
390         }
391
392         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
393         #if 0
394                 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_USB_CLIENT, *this);
395         #endif
396         AppLogDebug("Exit");
397 }
398
399 void
400 CategorySearch::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
401 {
402         if(_pFileEventManager != null)
403                 _pFileEventManager->RemovePath(_pathOfSelectedFile);
404
405         DeviceManager::RemoveAllDeviceEventListeners();
406
407         if (_pIconListView != null)
408         {
409                 _pIconListView->RemoveGestureDetector(*_pLongPressGestureDetector);
410         }
411
412 }
413
414 void
415 CategorySearch::OnSceneTransitionCompleted (const Tizen::Ui::Scenes::SceneId &previousSceneId, const Tizen::Ui::Scenes::SceneId &currentSceneId)
416 {
417         AppLogDebug("Enter");
418         String mediaPath = BasePresentationModel::GetMediaPath();
419         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
420         CreateItemSource sourceForm = CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM;
421         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
422
423         if (_pFolderEntryPM != null)
424         {
425                 _pFolderEntryPM->SetFolderEntryType(__currentFileType);
426                 _pFolderEntryPM->SetSourceForm(sourceForm);
427                 _pFolderEntryPM->CreateStack();
428                 _pFolderEntryPM->CreateTraversalTree(); 
429                 _pFolderEntryPM->SortFolderEntries();
430                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
431         }
432
433         SwitchViewType();
434
435         if (_pFilenames != null)
436         {
437                 if (_pFilenames->GetCount() == 0)
438                 {
439                         _bIsDirectoryEmpty = true;
440
441                         SetFooterItemsVisibility(DISABLE_FOOTER_ITEM);
442                 }
443                 else
444                 {
445                         _bIsDirectoryEmpty = false;
446
447                         SetFooterItemsVisibility(ENABLE_FOOTER_ITEM);
448
449                         if (_pIconListView != null && _pIconListView->IsVisible())
450                         {
451                                 _pIconListView->AddGestureDetector(*_pLongPressGestureDetector);
452                         }
453                 }
454         }
455
456         if (_pFolderEntryPM != null)
457         {
458                 _pFolderEntryPM->InitThumbnailManager();
459         }
460         AppLogDebug("Exit");
461 }
462
463 void
464 CategorySearch::OnSceneTransitionStarted (const Tizen::Ui::Scenes::SceneId &currentSceneId, const Tizen::Ui::Scenes::SceneId &nextSceneId)
465 {
466         //Empty Implementation
467 }
468
469 void
470 CategorySearch::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
471 {
472         SceneManager* pSceneManager = SceneManager::GetInstance();
473         result r = E_SUCCESS;
474         r = pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
475 }
476
477 void
478 CategorySearch::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
479 {
480         AppLogDebug("ENTER");
481
482         result r = E_SUCCESS;
483
484         switch (actionId)
485         {
486
487         case IDA_CONTEXT_MENU_HIDE_EXTENSION:
488         {
489                 //__currentDirectoryPath.Clear();
490                 //__currentDirectoryPath = FolderNavigationPresentationModel::GetCurrentPath();
491                 HideFileExtension();
492         }
493
494         break;
495
496         case IDA_CONTEXT_MENU_SHOW_EXTENSION:
497         {
498                 //__currentDirectoryPath.Clear();
499                 //__currentDirectoryPath = FolderNavigationPresentationModel::GetCurrentPath();
500                 ShowFileExtension();
501         }
502
503         break;
504
505         default:
506         {
507                 SubBaseOnActionPerformed(source, actionId);
508         }
509         break;
510         }
511         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
512 }
513 void
514 CategorySearch::GetParentFolderPath(Tizen::Base::String* filePath)
515 {
516         String displayPath;
517         String delim(L"/");
518         String token;
519         StringTokenizer tokenizer(*filePath, delim);
520         filePath->Clear();
521         while (tokenizer.HasMoreTokens())
522         {
523                 if (tokenizer.GetTokenCount() != 1)
524                 {
525                         filePath->Append(L"/");
526                         tokenizer.GetNextToken(token);
527                         filePath->Append(token);
528                 }
529                 else
530                 {
531                         break;
532                 }
533         }
534         filePath->Append(L"/");
535 }
536 void
537 CategorySearch::GetFileName(Tizen::Base::String* fileName)
538 {
539         String displayPath;
540         String delim(L"/");
541         String token;
542         if (fileName->StartsWith(BasePresentationModel::GetMediaPath(),0))
543         {
544                 fileName->Replace(BasePresentationModel::GetMediaPath(),"Phone/",0);
545         }
546         else if(fileName->StartsWith(BasePresentationModel::GetSdCardPath(),0))
547         {
548                 fileName->Replace(BasePresentationModel::GetSdCardPath(),"Memory Card/",0);
549         }
550         StringTokenizer tokenizer(*fileName, delim);
551         fileName->Clear();
552         while (tokenizer.HasMoreTokens())
553         {
554                 if (tokenizer.GetTokenCount() != 1)
555                 {
556                         tokenizer.GetNextToken(token);
557                 }
558                 else
559                 {
560                         tokenizer.GetNextToken(token);
561                         fileName->Append(token);
562                         break;
563                 }
564         }
565 }
566 void
567 CategorySearch::OnFileEventOccured(const unsigned long events,const Tizen::Base::String &  path, const unsigned int     eventId)
568 {
569         AppLogDebug("TopMostFolderFileListForm::OnFileEventOccured:%S", path.GetPointer());
570
571         //Scan the directory
572
573         HashMap* pCacheList = null;
574         DirectoryEntry* pCurrentEntry = null;
575         bool cacheKeyStatus = false;
576         String cachePath;
577
578         AppLogDebug("ContentManager::ScanFile:%S", path.GetPointer());
579
580         if ((events & FILE_EVENT_TYPE_CREATE) || (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM) || (events & FILE_EVENT_TYPE_MOVED_TO ))
581         {
582                 _bBackFromAppControl = true;
583                 if ( (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM))
584                 {
585                         AppLogDebug("Items to delete: %d", _indexTracker);
586                         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
587                         if (pCacheList != null)
588                         {
589                                 pCurrentEntry = static_cast<DirectoryEntry*>(_pFilenames->GetAt(_indexTracker));
590
591                                 if (pCurrentEntry != null)
592                                 {
593                                         cachePath = pCurrentEntry->GetFullFilePath();
594                                 }
595                                 cacheKeyStatus = pCacheList->ContainsKey(cachePath);
596                                 if (cacheKeyStatus)
597                                 {
598                                         CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
599                                 }
600                         }
601                 }
602                 if (_pFolderEntryPM!=null)
603                 {
604                         _pFolderEntryPM->RefreshFolderEntries();
605                 }
606         }
607
608 }
609
610 void
611 CategorySearch::OnNotificationReceived(Tizen::Base::Collection::ArrayList* pArgs)
612 {
613         AppLogDebug("Enter");
614         HashMap* pCacheList = null;
615         DirectoryEntry* pCurrentEntry = null;
616         bool cacheKeyStatus = false;
617         String cachePath;
618         Integer* pFileProcessingResult = null;
619         TryCatch(pArgs != null, , "Argument list received is invalid!");
620         pFileProcessingResult = (Integer*) pArgs->GetAt(0);
621
622         TryCatch(pFileProcessingResult != null, , "FileProcessing Result  list is invalid!");
623
624         switch (pFileProcessingResult->ToInt())
625         {
626         case FILE_MANAGING_RESULT_DELETING_SUCCESS:
627         {
628                 if (_pFilenames != null)
629                 {
630                         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
631
632                         if (pCacheList != null)
633                         {
634                                 pCurrentEntry = static_cast<DirectoryEntry*>(_pFilenames->GetAt(_indexTracker));
635
636                                 if (pCurrentEntry != null)
637                                 {
638                                         cachePath = pCurrentEntry->GetFullFilePath();
639                                 }
640
641                                 cacheKeyStatus = pCacheList->ContainsKey(cachePath);
642
643                                 if (cacheKeyStatus)
644                                 {
645                                         CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
646                                 }
647                         }
648                         _pFilenames->RemoveAt(_indexTracker, true);
649                         //r = __pListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
650                         if (_pListView != null)
651                         {
652                                 //_pListView->UpdateList();
653                                 _pListView->RefreshList(_indexTracker, LIST_REFRESH_TYPE_ITEM_REMOVE);
654                         }
655                         if (_pIconListView != null && _pIconListView->IsVisible())
656                         {
657                                 _pIconListView->RefreshList(_indexTracker, LIST_REFRESH_TYPE_ITEM_REMOVE);
658                         }
659                 }
660                 HideFileProgressingPopup();
661         }
662         break;
663
664         case FILE_MANAGING_RESULT_DELETING_FAILED:
665         {
666                 HideFileProgressingPopup();
667         }
668         break;
669         case FILE_MANAGING_RESULT_THREAD_STOP:
670         {
671                 HideFileProgressingPopup();
672         }
673         break;
674         default:
675         {
676                 //Do Nothing.
677         }
678         break;
679         }
680
681         if (_pFilenames->GetCount() == 0)
682         {
683                 SetFooterItemsVisibility(DISABLE_FOOTER_ITEM);
684         }
685
686 CATCH:
687         if (pArgs != null)
688         {
689                 pArgs->RemoveAll(true);
690                 delete pArgs;
691         }
692         ///return this;
693 }
694
695 void
696 CategorySearch::SetFooterItemsVisibility(int mode)
697 {
698         AppLogDebug("ENTRY mode = %d",mode);
699         _pFooter = GetFooter();
700
701         if (mode == 0)
702         {
703                 _pFooter->SetItemEnabled(0, false);
704                 _pFooter->SetItemEnabled(1, false);
705                 _pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
706         }
707         else
708         {
709                 _pFooter->SetItemEnabled(0, true);
710                 _pFooter->SetItemEnabled(1, true);
711                 _pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
712         }
713         _pFooter->Invalidate(true);
714 }
715 void
716 CategorySearch::OnIconListViewOverlayBitmapSelected (Tizen::Ui::Controls::IconListView &iconListView, int index, int overlayBitmapId)
717 {
718         result r = E_SUCCESS;
719
720         ArrayList* pArgs = null;
721         String fullPath;
722
723         DirectoryEntry* pCheckedEntry = null;
724
725         SceneManager* pSceneManager = null;
726
727         MemoryType currentMemoryType = MEMORY_TYPE_PHONE;
728
729         pSceneManager = SceneManager::GetInstance();
730
731         pCheckedEntry = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
732         if (pCheckedEntry == null)
733         {
734                 return;
735         }
736
737         if (pArgs == null)
738         {
739                 pArgs = new (std::nothrow) ArrayList();
740                 pArgs->Construct();
741         }
742
743         fullPath = pCheckedEntry->GetFullFilePath();
744         GetParentFolderPath(&fullPath);
745         FolderNavigationPresentationModel::SetCurrentFilePath(fullPath);
746
747         if (fullPath.StartsWith(BasePresentationModel::GetMediaPath(),0))
748         {
749                 currentMemoryType = MEMORY_TYPE_PHONE;
750                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
751         }
752         else if(fullPath.StartsWith(BasePresentationModel::GetSdCardPath(),0))
753         {
754                 currentMemoryType = MEMORY_TYPE_SD_CARD;
755                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
756         }
757
758         GetFileName(&fullPath);
759         pArgs->Add(fullPath);
760         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArgs);
761         return;
762
763 }
764
765 void
766 CategorySearch::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView& iconListView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
767 {
768         AppLogDebug("ENTER");
769         //If the source of the event is from the RootForm's IconListView, Changes the Scene to the SubFolderFileListForm. Else just refreshes the source IconListView.
770         String filepath;
771         DirectoryEntry* pDirStr = null;
772         CustomAppControl* pCustomAppControl = null;
773
774         //Get the directory structure at this index from the filenames arraylist
775         if (_pFilenames != null)
776         {
777                 pDirStr = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
778         }
779
780         //Get the filename of the specified index if pDirStr not null.
781         if (pDirStr != null)
782         {
783                 _pathOfSelectedFile = pDirStr->GetFullFilePath();
784
785                 pCustomAppControl = CustomAppControl::GetInstance();
786
787                 if (pCustomAppControl != null)
788                 {
789                         __counter = index;
790
791                         pCustomAppControl->SetAppControlListener(null);
792
793                         AppControl* pAppControlInUse = pCustomAppControl->LaunchAppControl(_pathOfSelectedFile);
794                         if (pAppControlInUse != null)
795                                 CustomAppControl::SetAppControlInUse(pAppControlInUse);
796                 }
797         }
798
799         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
800         return;
801 }
802
803 void
804 CategorySearch::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
805 {
806
807         ComponentType currentDeviceType;
808         switch (deviceType)
809         {
810         case StorageCard:
811         {
812                 currentDeviceType = COMPONENT_TYPE_STORAGE_CARD;
813         }
814         break;
815
816         case UsbClient:
817         {
818                 currentDeviceType = COMPONENT_TYPE_USB;
819         }
820         break;
821
822         default:
823         {
824                 //Do Nothing.
825         }
826         break;
827         }
828         OnDeviceChange(currentDeviceType, state);
829 }
830
831 void
832 CategorySearch::OnDeviceChange(ComponentType deviceType, const Tizen::Base::String& state)
833 {
834         if (_pFolderEntryPM != null)
835         {
836                 _pFolderEntryPM->CreateTraversalTree();
837                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
838         }
839
840         if (_pFilenames != null)
841         {
842                 if (_pFilenames->GetCount() == 0)
843                 {
844                         SetFooterItemsVisibility(DISABLE_FOOTER_ITEM);
845                 }
846                 else
847                 {
848                         SetFooterItemsVisibility(ENABLE_FOOTER_ITEM);
849                 }
850         }
851
852         if (_pListView != null && _pListView->IsVisible())
853         {
854                 _pListView->UpdateList();
855                 _pListView->Invalidate(true);
856         }
857
858         if (_pFolderEntryPM != null)
859         {
860                 _pFolderEntryPM->InitThumbnailManager();
861         }
862 }
863 void
864 CategorySearch::OnAppControlCompleted(void)
865 {
866         SubBaseFolderEntryForm::OnAppControlCompleted();
867 }