5ecc6252e1b1a5c27a231e48249b993e0e2cb9f2
[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         if (__pHomeButton != null)
31         {
32                 delete __pHomeButton;
33         }
34
35         if (__pUpButton != null)
36         {
37                 delete __pUpButton;
38         }
39 }
40
41 bool
42 CategorySearch::Initialize(void)
43 {
44         Form::Construct(L"IDL_CATEGORY_SEARCH");
45         return true;
46 }
47
48 result
49 CategorySearch::OnInitializing(void)
50 {
51         result r = E_SUCCESS;
52         CreateItemSource createitemsource = CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM;
53         int sourceForm = THUMBNAIL_PROVIDER_SOURCEID_CATEGORY_SEARCH_FORM;
54
55         String path;
56         String rootParentPath;
57         String buttonHome;
58         String buttonUp;
59         String extensionVisibility;
60         String currentDirectoryPath = BasePresentationModel::GetMediaPath();
61
62         Bitmap* pBitmapHomeButton = null;
63         Bitmap* pBitmapUpButton = null;
64         Bitmap* pBitmapHomeButtonPress = null;
65         Bitmap* pBitmapUpButtonPress = null;
66         AppResource* pAppResource = null;
67
68         if (_pFolderEntryPM == null)
69         {
70                 _pFolderEntryPM = new (std::nothrow) FolderEntryPresentationModel();
71                 AppAssert(_pFolderEntryPM != null);
72                 r = _pFolderEntryPM->Construct();
73                 AppAssert(r==E_SUCCESS);
74                 _pFolderEntryPM->SetSourceForm(createitemsource);
75         }
76
77         _pBaseItemProvider = new (std::nothrow) BaseItemProvider();
78         TryCatch(_pBaseItemProvider != null, , "Failed to allocate base itemprovider");
79         _pBaseItemProvider->Construct();
80         _pBaseItemProvider->SetSourceForm(createitemsource);
81         _pBaseItemProvider->SetFolderEntryProvider(this);
82         _pBaseItemProvider->SetFooterItemStateChangeListener(this);
83
84         _pListView = static_cast<ListView *>(GetControl(L"IDC_LISTVIEW_CATEGORY_SEARCH"));
85         TryCatch(_pListView != null, , "__pListView is Null");
86         _pListView->AddListViewItemEventListener(*this);
87         _pListView->SetItemProvider(*this);
88         _pListView->SetItemProvider(*_pBaseItemProvider);
89
90         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
91
92         pAppResource = UiApp::App::GetInstance()->GetAppResource();
93         TryCatch(pAppResource != null, , "Resource manager not found!");
94
95         pAppResource->GetString(L"IDS_MF_BUTTON_HOME", buttonHome);
96         pAppResource->GetString(L"IDS_MF_TAB_UP", buttonUp);
97         pAppResource->GetString(L"IDS_MF_OPT_SHOW_FILE_EXTENSION", _showExtension);
98         pAppResource->GetString(L"IDS_MF_OPT_HIDE_FILE_EXTENSION_ABB", _hideExtension);
99         pBitmapHomeButton = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
100         pBitmapUpButton = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
101         pBitmapHomeButtonPress = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
102         pBitmapUpButtonPress = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
103         extensionVisibility = fileExtenstionKeyName;
104
105         __pHeader = GetHeader();
106         _extensionKeyName.Append(extensionVisibility);
107
108         createitemsource = CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM;
109
110         //Initialize the itemprovider class for the listview inside the popup
111         if (_pCustomListViewForPopup == null)
112         {
113                 _pCustomListViewForPopup = new (std::nothrow) CustomListViewForPopup();
114         }
115         TryCatch(_pCustomListViewForPopup != null, , "MfMyFilesApp::ListView For Popup not created!");
116
117         _pCustomListViewForPopup->SetEventListener(this);
118
119
120         if (_pThumbnailItemProvider == null)
121         {
122                 _pThumbnailItemProvider = new (std::nothrow) ThumbnailItemProviderAndListener(currentDirectoryPath, sourceForm);
123                 _pThumbnailItemProvider->SetFolderEntryProvider(this);
124         }
125         TryCatch(_pThumbnailItemProvider != null, , "Failed to allocate Memory to __pSubFolderThumbnailsProvider");
126
127         _pThumbnailItemProvider->SetFooterItemStateChangeListener(this);
128
129         _pIconListView = static_cast< IconListView* >(GetControl("IDC_ICONLISTVIEW_CATEGORY_SEARCH"));
130         TryCatch(_pIconListView != null, , "__pIconListviewSubThumbnails is Null");
131         _pIconListView->SetItemProvider(*_pThumbnailItemProvider);
132         _pIconListView->AddIconListViewItemEventListener(*this);
133         _pIconListView->AddTouchEventListener(*this);
134         _pIconListView->SetShowState(false);
135
136         _pLongPressGestureDetector = new (std::nothrow) TouchLongPressGestureDetector();
137         _pLongPressGestureDetector->Construct();
138
139         delete pBitmapHomeButton;
140         delete pBitmapUpButton;
141         delete pBitmapHomeButtonPress;
142         delete pBitmapUpButtonPress;
143
144         CreateFooterControls();
145         //Set FormBackEvent Listener
146         SetFormBackEventListener(this);
147         _pFileManager = FolderEntryEditorPresentationModel::GetInstance();
148
149         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
150
151         return r;
152 CATCH:
153         AppLogDebug("caught exception");
154         if (__pHomeButton != null)
155         {
156                 delete __pHomeButton;
157                 __pHomeButton = null;
158         }
159
160         if (__pUpButton != null)
161         {
162                 delete __pUpButton;
163                 __pUpButton = null;
164         }
165
166         if (_pCustomListViewForPopup != null)
167         {
168                 delete _pCustomListViewForPopup;
169                 _pCustomListViewForPopup = null;
170         }
171
172         if (pBitmapHomeButton != null)
173         {
174                 delete pBitmapHomeButton;
175                 pBitmapHomeButton = null;
176         }
177
178         if (pBitmapUpButton != null)
179         {
180                 delete pBitmapUpButton;
181                 pBitmapUpButton = null;
182         }
183         if (pBitmapHomeButtonPress != null)
184         {
185                 delete pBitmapHomeButtonPress;
186                 pBitmapHomeButtonPress = null;
187         }
188         if (pBitmapUpButtonPress != null)
189         {
190                 delete pBitmapUpButtonPress;
191                 pBitmapUpButtonPress = null;
192         }
193         return r;
194 }
195
196 result
197 CategorySearch::OnTerminating(void)
198 {
199         result r = E_SUCCESS;
200         //((MfMyFilesApp*)Application::GetInstance())->SetCurrentView(null);
201
202         _pFooter = GetFooter();
203         if (_pFooter != null)
204         {
205                 _pFooter->RemoveAllButtons();
206                 _pFooter->RemoveAllItems();
207         }
208
209         __pHeader = GetHeader();
210         if (__pHeader != null)
211         {
212                 __pHeader->RemoveAllButtons();
213                 __pHeader->RemoveAllItems();
214         }
215
216         return r;
217 }
218
219
220
221 void
222 CategorySearch::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
223 {
224         AppLogDebug("Entry");
225
226         DirectoryEntry* pCheckedEntry = null;
227         String selected;
228         String fullPath;
229         String fileName;
230         result r = E_SUCCESS;
231         MemoryType currentMemoryType = MEMORY_TYPE_PHONE;
232         ArrayList* pArgs = null;
233         SceneManager* pSceneManager = null;
234         AppResource* pAppResource = null;
235         CustomAppControl* pCustomAppControl = CustomAppControl::GetInstance();
236         pAppResource = UiApp::GetInstance()->GetAppResource();
237         pSceneManager = SceneManager::GetInstance();
238         if (pAppResource != null)
239         {
240                 pAppResource->GetString(L"IDS_COM_BODY_SELECTED", selected);
241         }
242         pCheckedEntry = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
243
244         if (pCheckedEntry == null)
245         {
246                 return;
247         }
248
249         _indexTracker  = index;
250 //      if (elementId == CONTENT_LIST_ITEM_TYPE_RENAME || elementId == DETAILED_LIST_ELEMENTS_RENAME)
251         if (status == LIST_ITEM_STATUS_MORE/* || elementId == DETAILED_LIST_ELEMENTS_RENAME*/)
252         {
253                 if (pArgs == null)
254                 {
255                         pArgs = new (std::nothrow) ArrayList();
256                         pArgs->Construct();
257                 }
258
259                 fullPath = pCheckedEntry->GetFullFilePath();
260                 GetParentFolderPath(&fullPath);
261                 FolderNavigationPresentationModel::SetCurrentFilePath(fullPath);
262
263                 if (fullPath.StartsWith(BasePresentationModel::GetMediaPath(),0))
264                 {
265                         currentMemoryType = MEMORY_TYPE_PHONE;
266                         FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
267                 }
268                 else if(fullPath.StartsWith(BasePresentationModel::GetSdCardPath(),0))
269                 {
270                         currentMemoryType = MEMORY_TYPE_SD_CARD;
271                         FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
272                 }
273
274                 GetFileName(&fullPath);
275                 pArgs->Add(fullPath);
276                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArgs);
277                 return;
278         }
279
280         if (_pFileEventManager != null)
281         {
282                 _pFileEventManager->RemovePath(_pathOfSelectedFile);
283                 delete _pFileEventManager;
284                 _pFileEventManager = null;
285         }
286         _pathOfSelectedFile = pCheckedEntry->GetFullFilePath();
287         AppLogDebug("Selected File path : %S", _pathOfSelectedFile.GetPointer());
288
289         _pFileEventManager = new (std::nothrow)FileEventManager();
290         _pFileEventManager->Construct(*this);
291
292         String FileName = pCheckedEntry->GetFileName() + "." + pCheckedEntry->GetFileExtension();
293         String parentDirectoryOfSelectedFile = L"";
294         _pathOfSelectedFile.SubString(0, _pathOfSelectedFile.GetLength() - FileName.GetLength() , parentDirectoryOfSelectedFile);
295         _fileEventPath = parentDirectoryOfSelectedFile;
296         _pFileEventManager->AddPath(parentDirectoryOfSelectedFile, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_MOVED_TO | FILE_EVENT_TYPE_MOVED_FROM);
297
298         if (pCustomAppControl != null)
299         {
300                 __counter = index;
301                 pCustomAppControl->SetAppControlListener(null);
302                 AppControl* pAppControlInUse = pCustomAppControl->LaunchAppControl(_pathOfSelectedFile);
303                 if (pAppControlInUse != null)
304                         CustomAppControl::SetAppControlInUse(pAppControlInUse);
305         }
306 }
307
308 // ISceneEventListener
309 void
310 CategorySearch::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
311 {
312         //__currentFileType
313         AppLogDebug("Enter");
314         Integer* fileType;
315         int currentType;
316         String* headerTitleText;
317         AppRegistry* pAppRegistry = null;
318         String viewStyleKeyName(L"ListDisplayType");
319         int listViewDisplayType = VIEW_TYPE_AS_NORMAL_LIST;
320
321         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
322
323         pAppRegistry->Get(viewStyleKeyName, listViewDisplayType);
324         _flagViewAsStatus = listViewDisplayType;
325
326         SceneManager::GetInstance()->AddSceneManagerEventListener(*this);
327
328         SetCurrentDirectoryFlag(false);
329
330         if (pArgs != null)
331         {
332                 fileType = static_cast< Integer* >(pArgs->GetAt(0));
333                 currentType = fileType->ToInt();
334                 headerTitleText = static_cast< String* >(pArgs->GetAt(1));
335                 if (headerTitleText != null)
336                 {
337                         __currentHeaderText = *headerTitleText;
338                         __pHeader->SetTitleText(__currentHeaderText);
339                 }
340
341                 switch (currentType)
342                 {
343                 case FILE_TYPE_IMAGE_TYPE:
344                 {
345                         AppLogDebug("File type is image");
346                         __currentFileType = FILE_TYPE_IMAGE_TYPE;
347                 }
348                 break;
349
350                 case FILE_TYPE_VIDEO_TYPE:
351                 {
352                         __currentFileType = FILE_TYPE_VIDEO_TYPE;
353                 }
354                 break;
355
356                 case FILE_TYPE_AUDIO_TYPE:
357                 {
358                         __currentFileType = FILE_TYPE_AUDIO_TYPE;
359                 }
360                 break;
361
362                 case FILE_TYPE_DOCUMENT_TYPE:
363                 {
364                         __currentFileType = FILE_TYPE_DOCUMENT_TYPE;
365                 }
366                 break;
367
368                 case FILE_TYPE_OTHER_TYPE:
369                 {
370                         __currentFileType = FILE_TYPE_OTHER_TYPE;
371                 }
372                 break;
373
374                 default:
375                         break;
376                 }
377         }
378
379         if (_pFileManager != null)
380         {
381                 _pFileManager->SetFileManagingListener(this);
382         }
383
384         if (pArgs != null)
385         {
386                 pArgs->RemoveAll(true);
387                 delete pArgs;
388                 pArgs = null;
389         }
390
391         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
392         #if 0
393                 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_USB_CLIENT, *this);
394         #endif
395         AppLogDebug("Exit");
396 }
397
398 void
399 CategorySearch::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
400 {
401         if(_pFileEventManager != null)
402                 _pFileEventManager->RemovePath(_pathOfSelectedFile);
403
404         DeviceManager::RemoveAllDeviceEventListeners();
405
406         if (_pIconListView != null)
407         {
408                 _pIconListView->RemoveGestureDetector(*_pLongPressGestureDetector);
409         }
410
411 }
412
413 void
414 CategorySearch::OnSceneTransitionCompleted (const Tizen::Ui::Scenes::SceneId &previousSceneId, const Tizen::Ui::Scenes::SceneId &currentSceneId)
415 {
416         AppLogDebug("Enter");
417         String mediaPath = BasePresentationModel::GetMediaPath();
418         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
419         CreateItemSource sourceForm = CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM;
420         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
421         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_NONE);
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                         _pLongPressGestureDetector->AddLongPressGestureEventListener(*this);
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         TryCatch(_pFilenames != null, , "_pFilenames is Null.");
624
625         switch (pFileProcessingResult->ToInt())
626         {
627         case FILE_MANAGING_RESULT_DELETING_SUCCESS:
628         {
629                 pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
630
631                 if (pCacheList != null)
632                 {
633                         pCurrentEntry = static_cast<DirectoryEntry*>(_pFilenames->GetAt(_indexTracker));
634
635                         if (pCurrentEntry != null)
636                         {
637                                 cachePath = pCurrentEntry->GetFullFilePath();
638                         }
639
640                         cacheKeyStatus = pCacheList->ContainsKey(cachePath);
641
642                         if (cacheKeyStatus)
643                         {
644                                 CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
645                         }
646                 }
647                 _pFilenames->RemoveAt(_indexTracker, true);
648
649                 if (_pListView != null)
650                 {
651                         _pListView->RefreshList(_indexTracker, LIST_REFRESH_TYPE_ITEM_REMOVE);
652                 }
653                 if (_pIconListView != null && _pIconListView->IsVisible())
654                 {
655                         _pIconListView->RefreshList(_indexTracker, LIST_REFRESH_TYPE_ITEM_REMOVE);
656                 }
657
658                 HideFileProgressingPopup();
659         }
660         break;
661
662         case FILE_MANAGING_RESULT_DELETING_FAILED:
663         {
664                 HideFileProgressingPopup();
665         }
666         break;
667         case FILE_MANAGING_RESULT_THREAD_STOP:
668         {
669                 HideFileProgressingPopup();
670         }
671         break;
672         default:
673         {
674                 //Do Nothing.
675         }
676         break;
677         }
678
679         if (_pFilenames->GetCount() == 0)
680         {
681                 SetFooterItemsVisibility(DISABLE_FOOTER_ITEM);
682         }
683
684 CATCH:
685         if (pArgs != null)
686         {
687                 pArgs->RemoveAll(true);
688                 delete pArgs;
689         }
690         ///return this;
691 }
692
693 void
694 CategorySearch::SetFooterItemsVisibility(int mode)
695 {
696         AppLogDebug("ENTRY mode = %d",mode);
697         _pFooter = GetFooter();
698
699         if (mode == 0)
700         {
701                 _pFooter->SetItemEnabled(0, false);
702                 _pFooter->SetItemEnabled(1, false);
703                 _pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
704         }
705         else
706         {
707                 _pFooter->SetItemEnabled(0, true);
708                 _pFooter->SetItemEnabled(1, true);
709                 _pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
710         }
711         _pFooter->Invalidate(true);
712 }
713 void
714 CategorySearch::OnIconListViewOverlayBitmapSelected (Tizen::Ui::Controls::IconListView &iconListView, int index, int overlayBitmapId)
715 {
716         result r = E_SUCCESS;
717
718         ArrayList* pArgs = null;
719         String fullPath;
720
721         DirectoryEntry* pCheckedEntry = null;
722
723         SceneManager* pSceneManager = null;
724
725         MemoryType currentMemoryType = MEMORY_TYPE_PHONE;
726
727         pSceneManager = SceneManager::GetInstance();
728
729         pCheckedEntry = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
730         if (pCheckedEntry == null)
731         {
732                 return;
733         }
734
735         if (pArgs == null)
736         {
737                 pArgs = new (std::nothrow) ArrayList();
738                 pArgs->Construct();
739         }
740
741         fullPath = pCheckedEntry->GetFullFilePath();
742         GetParentFolderPath(&fullPath);
743         FolderNavigationPresentationModel::SetCurrentFilePath(fullPath);
744
745         if (fullPath.StartsWith(BasePresentationModel::GetMediaPath(),0))
746         {
747                 currentMemoryType = MEMORY_TYPE_PHONE;
748                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
749         }
750         else if(fullPath.StartsWith(BasePresentationModel::GetSdCardPath(),0))
751         {
752                 currentMemoryType = MEMORY_TYPE_SD_CARD;
753                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
754         }
755
756         GetFileName(&fullPath);
757         pArgs->Add(fullPath);
758         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArgs);
759         return;
760
761 }
762
763 void
764 CategorySearch::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView& iconListView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
765 {
766         AppLogDebug("ENTER");
767         //If the source of the event is from the RootForm's IconListView, Changes the Scene to the SubFolderFileListForm. Else just refreshes the source IconListView.
768         String filepath;
769         DirectoryEntry* pDirStr = null;
770         CustomAppControl* pCustomAppControl = null;
771
772         //Get the directory structure at this index from the filenames arraylist
773         if (_pFilenames != null)
774         {
775                 pDirStr = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
776         }
777
778         //Get the filename of the specified index if pDirStr not null.
779         if (pDirStr != null)
780         {
781                 _pathOfSelectedFile = pDirStr->GetFullFilePath();
782
783                 if (_pFileEventManager != null)
784                 {
785                         _pFileEventManager->RemovePath(_pathOfSelectedFile);
786                         delete _pFileEventManager;
787                         _pFileEventManager = null;
788                 }
789
790
791                 _pFileEventManager = new (std::nothrow)FileEventManager();
792                 _pFileEventManager->Construct(*this);
793
794                 String FileName = pDirStr->GetFileName() + "." + pDirStr->GetFileExtension();
795                 String parentDirectoryOfSelectedFile = L"";
796                 _pathOfSelectedFile.SubString(0, _pathOfSelectedFile.GetLength() - FileName.GetLength() , parentDirectoryOfSelectedFile);
797                 _fileEventPath = parentDirectoryOfSelectedFile;
798                 _pFileEventManager->AddPath(parentDirectoryOfSelectedFile, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_MOVED_TO | FILE_EVENT_TYPE_MOVED_FROM);
799
800
801                 pCustomAppControl = CustomAppControl::GetInstance();
802
803                 if (pCustomAppControl != null)
804                 {
805                         __counter = index;
806
807                         pCustomAppControl->SetAppControlListener(null);
808
809                         AppControl* pAppControlInUse = pCustomAppControl->LaunchAppControl(_pathOfSelectedFile);
810                         if (pAppControlInUse != null)
811                                 CustomAppControl::SetAppControlInUse(pAppControlInUse);
812                 }
813         }
814
815         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
816         return;
817 }
818
819 void
820 CategorySearch::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
821 {
822
823         ComponentType currentDeviceType;
824         switch (deviceType)
825         {
826         case StorageCard:
827         {
828                 currentDeviceType = COMPONENT_TYPE_STORAGE_CARD;
829         }
830         break;
831
832         case UsbClient:
833         {
834                 currentDeviceType = COMPONENT_TYPE_USB;
835         }
836         break;
837
838         default:
839         {
840                 //Do Nothing.
841         }
842         break;
843         }
844         OnDeviceChange(currentDeviceType, state);
845 }
846
847 void
848 CategorySearch::OnDeviceChange(ComponentType deviceType, const Tizen::Base::String& state)
849 {
850         AppLogDebug("CategorySearch::OnDeviceChange");
851         if (_pFolderEntryPM != null)
852         {
853                 _pFolderEntryPM->CreateTraversalTree();
854                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
855         }
856
857         if (_pFilenames != null)
858         {
859                 if (_pFilenames->GetCount() == 0)
860                 {
861                         _bIsDirectoryEmpty = true;
862                         SetFooterItemsVisibility(DISABLE_FOOTER_ITEM);
863                 }
864                 else
865                 {
866                         _bIsDirectoryEmpty = false;
867                         SetFooterItemsVisibility(ENABLE_FOOTER_ITEM);
868                 }
869         }
870
871         if (_pListView != null && _pListView->IsVisible())
872         {
873                 _pListView->UpdateList();
874                 _pListView->Invalidate(true);
875         }
876
877         if (_pIconListView != null && _pIconListView->IsVisible())
878         {
879                 _pIconListView->UpdateList();
880                 _pIconListView->Invalidate(true);
881         }
882
883         if (_pFolderEntryPM != null)
884         {
885                 _pFolderEntryPM->InitThumbnailManager();
886         }
887 }
888 void
889 CategorySearch::OnAppControlCompleted(void)
890 {
891         SubBaseFolderEntryForm::OnAppControlCompleted();
892 }