NABI_SE issues resolved
[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, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), pArgs);
277
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         _fileEventPath = parentDirectoryOfSelectedFile;
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         DeviceManager::RemoveAllDeviceEventListeners();
403         if (_pFileEventManager != null)
404         {
405                 _pFileEventManager->RemovePath(_pathOfSelectedFile);
406                 delete _pFileEventManager;
407                 _pFileEventManager = null;
408         }
409
410         if (_pIconListView != null)
411         {
412                 _pIconListView->RemoveGestureDetector(_pLongPressGestureDetector);
413         }
414
415 }
416
417 void
418 CategorySearch::OnSceneTransitionCompleted (const Tizen::Ui::Scenes::SceneId &previousSceneId, const Tizen::Ui::Scenes::SceneId &currentSceneId)
419 {
420         AppLogDebug("Enter");
421         String mediaPath = BasePresentationModel::GetMediaPath();
422         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
423         CreateItemSource sourceForm = CREATE_ITEM_SOURCE_CATEGORY_SEARCH_FORM;
424         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
425         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_NONE);
426
427         if (_pFolderEntryPM != null)
428         {
429                 _pFolderEntryPM->SetFolderEntryType(__currentFileType);
430                 _pFolderEntryPM->SetSourceForm(sourceForm);
431                 _pFolderEntryPM->CreateStack();
432                 _pFolderEntryPM->CreateTraversalTree(); 
433                 _pFolderEntryPM->SortFolderEntries();
434                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
435         }
436
437         SwitchViewType();
438
439         if (_pFilenames != null)
440         {
441                 if (_pFilenames->GetCount() == 0)
442                 {
443                         _bIsDirectoryEmpty = true;
444
445                         SetFooterItemsVisibility(DISABLE_FOOTER_ITEM);
446                 }
447                 else
448                 {
449                         _bIsDirectoryEmpty = false;
450
451                         SetFooterItemsVisibility(ENABLE_FOOTER_ITEM);
452                         _pLongPressGestureDetector->AddLongPressGestureEventListener(*this);
453                         if (_pIconListView != null && _pIconListView->IsVisible())
454                         {
455                                 _pIconListView->AddGestureDetector(*_pLongPressGestureDetector);
456                         }
457                 }
458         }
459
460         if (_pFolderEntryPM != null)
461         {
462                 _pFolderEntryPM->InitThumbnailManager();
463         }
464         AppLogDebug("Exit");
465 }
466
467 void
468 CategorySearch::OnSceneTransitionStarted (const Tizen::Ui::Scenes::SceneId &currentSceneId, const Tizen::Ui::Scenes::SceneId &nextSceneId)
469 {
470         //Empty Implementation
471 }
472
473 void
474 CategorySearch::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
475 {
476         SceneManager* pSceneManager = SceneManager::GetInstance();
477         result r = E_SUCCESS;
478         r = pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
479 }
480
481 void
482 CategorySearch::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
483 {
484         AppLogDebug("ENTER");
485
486         result r = E_SUCCESS;
487
488         switch (actionId)
489         {
490
491         case IDA_CONTEXT_MENU_HIDE_EXTENSION:
492         {
493                 //__currentDirectoryPath.Clear();
494                 //__currentDirectoryPath = FolderNavigationPresentationModel::GetCurrentPath();
495                 HideFileExtension();
496         }
497
498         break;
499
500         case IDA_CONTEXT_MENU_SHOW_EXTENSION:
501         {
502                 //__currentDirectoryPath.Clear();
503                 //__currentDirectoryPath = FolderNavigationPresentationModel::GetCurrentPath();
504                 ShowFileExtension();
505         }
506
507         break;
508
509         default:
510         {
511                 SubBaseOnActionPerformed(source, actionId);
512         }
513         break;
514         }
515         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
516 }
517 void
518 CategorySearch::GetParentFolderPath(Tizen::Base::String* filePath)
519 {
520         String displayPath;
521         String delim(L"/");
522         String token;
523         StringTokenizer tokenizer(*filePath, delim);
524         filePath->Clear();
525         while (tokenizer.HasMoreTokens())
526         {
527                 if (tokenizer.GetTokenCount() != 1)
528                 {
529                         filePath->Append(L"/");
530                         tokenizer.GetNextToken(token);
531                         filePath->Append(token);
532                 }
533                 else
534                 {
535                         break;
536                 }
537         }
538         filePath->Append(L"/");
539 }
540 void
541 CategorySearch::GetFileName(Tizen::Base::String* fileName)
542 {
543         String displayPath;
544         String delim(L"/");
545         String token;
546         if (fileName->StartsWith(BasePresentationModel::GetMediaPath(),0))
547         {
548                 fileName->Replace(BasePresentationModel::GetMediaPath(),"Phone/",0);
549         }
550         else if(fileName->StartsWith(BasePresentationModel::GetSdCardPath(),0))
551         {
552                 fileName->Replace(BasePresentationModel::GetSdCardPath(),"Memory Card/",0);
553         }
554         StringTokenizer tokenizer(*fileName, delim);
555         fileName->Clear();
556         while (tokenizer.HasMoreTokens())
557         {
558                 if (tokenizer.GetTokenCount() != 1)
559                 {
560                         tokenizer.GetNextToken(token);
561                 }
562                 else
563                 {
564                         tokenizer.GetNextToken(token);
565                         fileName->Append(token);
566                         break;
567                 }
568         }
569 }
570 void
571 CategorySearch::OnFileEventOccured(const unsigned long events,const Tizen::Base::String &  path, const unsigned int     eventId)
572 {
573         AppLogDebug("TopMostFolderFileListForm::OnFileEventOccured:%S", path.GetPointer());
574
575         //Scan the directory
576
577         HashMap* pCacheList = null;
578         DirectoryEntry* pCurrentEntry = null;
579         bool cacheKeyStatus = false;
580         String cachePath;
581
582         AppLogDebug("ContentManager::ScanFile:%S", path.GetPointer());
583
584         if ((events & FILE_EVENT_TYPE_CREATE) || (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM) || (events & FILE_EVENT_TYPE_MOVED_TO ))
585         {
586                 _bBackFromAppControl = true;
587                 if ( (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM))
588                 {
589                         AppLogDebug("Items to delete: %d", _indexTracker);
590                         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
591                         if (pCacheList != null)
592                         {
593                                 pCurrentEntry = static_cast<DirectoryEntry*>(_pFilenames->GetAt(_indexTracker));
594
595                                 if (pCurrentEntry != null)
596                                 {
597                                         cachePath = pCurrentEntry->GetFullFilePath();
598                                 }
599                                 cacheKeyStatus = pCacheList->ContainsKey(cachePath);
600                                 if (cacheKeyStatus)
601                                 {
602                                         CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
603                                 }
604                         }
605                 }
606                 if (_pFolderEntryPM!=null)
607                 {
608                         _pFolderEntryPM->RefreshFolderEntries();
609                 }
610         }
611
612 }
613
614 void
615 CategorySearch::OnNotificationReceived(Tizen::Base::Collection::ArrayList* pArgs)
616 {
617         AppLogDebug("Enter");
618         HashMap* pCacheList = null;
619         DirectoryEntry* pCurrentEntry = null;
620         bool cacheKeyStatus = false;
621         String cachePath;
622         Integer* pFileProcessingResult = null;
623         TryCatch(pArgs != null, , "Argument list received is invalid!");
624         pFileProcessingResult = (Integer*) pArgs->GetAt(0);
625
626         TryCatch(pFileProcessingResult != null, , "FileProcessing Result  list is invalid!");
627         TryCatch(_pFilenames != null, , "_pFilenames is Null.");
628
629         switch (pFileProcessingResult->ToInt())
630         {
631         case FILE_MANAGING_RESULT_DELETING_SUCCESS:
632         {
633                 pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
634
635                 if (pCacheList != null)
636                 {
637                         pCurrentEntry = static_cast<DirectoryEntry*>(_pFilenames->GetAt(_indexTracker));
638
639                         if (pCurrentEntry != null)
640                         {
641                                 cachePath = pCurrentEntry->GetFullFilePath();
642                         }
643
644                         cacheKeyStatus = pCacheList->ContainsKey(cachePath);
645
646                         if (cacheKeyStatus)
647                         {
648                                 CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
649                         }
650                 }
651                 _pFilenames->RemoveAt(_indexTracker, true);
652
653                 if (_pListView != null)
654                 {
655                         _pListView->RefreshList(_indexTracker, LIST_REFRESH_TYPE_ITEM_REMOVE);
656                 }
657                 if (_pIconListView != null && _pIconListView->IsVisible())
658                 {
659                         _pIconListView->RefreshList(_indexTracker, LIST_REFRESH_TYPE_ITEM_REMOVE);
660                 }
661
662                 HideFileProgressingPopup();
663         }
664         break;
665
666         case FILE_MANAGING_RESULT_DELETING_FAILED:
667         {
668                 HideFileProgressingPopup();
669         }
670         break;
671         case FILE_MANAGING_RESULT_THREAD_STOP:
672         {
673                 HideFileProgressingPopup();
674         }
675         break;
676         default:
677         {
678                 //Do Nothing.
679         }
680         break;
681         }
682
683         if (_pFilenames->GetCount() == 0)
684         {
685                 SetFooterItemsVisibility(DISABLE_FOOTER_ITEM);
686         }
687
688 CATCH:
689         if (pArgs != null)
690         {
691                 pArgs->RemoveAll(true);
692                 delete pArgs;
693         }
694         ///return this;
695 }
696
697 void
698 CategorySearch::SetFooterItemsVisibility(int mode)
699 {
700         AppLogDebug("ENTRY mode = %d",mode);
701         _pFooter = GetFooter();
702
703         if (mode == 0)
704         {
705                 _pFooter->SetItemEnabled(0, false);
706                 _pFooter->SetItemEnabled(1, false);
707                 _pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
708         }
709         else
710         {
711                 _pFooter->SetItemEnabled(0, true);
712                 _pFooter->SetItemEnabled(1, true);
713                 _pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
714         }
715         _pFooter->Invalidate(true);
716 }
717 void
718 CategorySearch::OnIconListViewOverlayBitmapSelected (Tizen::Ui::Controls::IconListView &iconListView, int index, int overlayBitmapId)
719 {
720         result r = E_SUCCESS;
721
722         ArrayList* pArgs = null;
723         String fullPath;
724
725         DirectoryEntry* pCheckedEntry = null;
726
727         SceneManager* pSceneManager = null;
728
729         MemoryType currentMemoryType = MEMORY_TYPE_PHONE;
730
731         pSceneManager = SceneManager::GetInstance();
732
733         pCheckedEntry = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
734         if (pCheckedEntry == null)
735         {
736                 return;
737         }
738
739         if (pArgs == null)
740         {
741                 pArgs = new (std::nothrow) ArrayList();
742                 pArgs->Construct();
743         }
744
745         fullPath = pCheckedEntry->GetFullFilePath();
746         GetParentFolderPath(&fullPath);
747         FolderNavigationPresentationModel::SetCurrentFilePath(fullPath);
748
749         if (fullPath.StartsWith(BasePresentationModel::GetMediaPath(),0))
750         {
751                 currentMemoryType = MEMORY_TYPE_PHONE;
752                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
753         }
754         else if(fullPath.StartsWith(BasePresentationModel::GetSdCardPath(),0))
755         {
756                 currentMemoryType = MEMORY_TYPE_SD_CARD;
757                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
758         }
759
760         GetFileName(&fullPath);
761         pArgs->Add(fullPath);
762         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArgs);
763         return;
764
765 }
766
767 void
768 CategorySearch::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView& iconListView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
769 {
770         AppLogDebug("ENTER");
771         //If the source of the event is from the RootForm's IconListView, Changes the Scene to the SubFolderFileListForm. Else just refreshes the source IconListView.
772         String filepath;
773         DirectoryEntry* pDirStr = null;
774         CustomAppControl* pCustomAppControl = null;
775
776         //Get the directory structure at this index from the filenames arraylist
777         if (_pFilenames != null)
778         {
779                 pDirStr = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
780         }
781
782         //Get the filename of the specified index if pDirStr not null.
783         if (pDirStr != null)
784         {
785                 _pathOfSelectedFile = pDirStr->GetFullFilePath();
786
787                 if (_pFileEventManager != null)
788                 {
789                         _pFileEventManager->RemovePath(_pathOfSelectedFile);
790                         delete _pFileEventManager;
791                         _pFileEventManager = null;
792                 }
793
794
795                 _pFileEventManager = new (std::nothrow)FileEventManager();
796                 _pFileEventManager->Construct(*this);
797
798                 String FileName = pDirStr->GetFileName() + "." + pDirStr->GetFileExtension();
799                 String parentDirectoryOfSelectedFile = L"";
800                 _pathOfSelectedFile.SubString(0, _pathOfSelectedFile.GetLength() - FileName.GetLength() , parentDirectoryOfSelectedFile);
801                 _fileEventPath = parentDirectoryOfSelectedFile;
802                 _pFileEventManager->AddPath(parentDirectoryOfSelectedFile, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_MOVED_TO | FILE_EVENT_TYPE_MOVED_FROM);
803
804
805                 pCustomAppControl = CustomAppControl::GetInstance();
806
807                 if (pCustomAppControl != null)
808                 {
809                         __counter = index;
810
811                         pCustomAppControl->SetAppControlListener(null);
812
813                         AppControl* pAppControlInUse = pCustomAppControl->LaunchAppControl(_pathOfSelectedFile);
814                         if (pAppControlInUse != null)
815                                 CustomAppControl::SetAppControlInUse(pAppControlInUse);
816                 }
817         }
818
819         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
820         return;
821 }
822
823 void
824 CategorySearch::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
825 {
826
827         ComponentType currentDeviceType;
828         switch (deviceType)
829         {
830         case StorageCard:
831         {
832                 currentDeviceType = COMPONENT_TYPE_STORAGE_CARD;
833         }
834         break;
835
836         case UsbClient:
837         {
838                 currentDeviceType = COMPONENT_TYPE_USB;
839         }
840         break;
841
842         default:
843         {
844                 //Do Nothing.
845         }
846         break;
847         }
848         OnDeviceChange(currentDeviceType, state);
849 }
850
851 void
852 CategorySearch::OnDeviceChange(ComponentType deviceType, const Tizen::Base::String& state)
853 {
854         AppLogDebug("CategorySearch::OnDeviceChange");
855         if (_pFolderEntryPM != null)
856         {
857                 _pFolderEntryPM->CreateTraversalTree();
858                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
859         }
860
861         if (_pFilenames != null)
862         {
863                 if (_pFilenames->GetCount() == 0)
864                 {
865                         _bIsDirectoryEmpty = true;
866                         SetFooterItemsVisibility(DISABLE_FOOTER_ITEM);
867                 }
868                 else
869                 {
870                         _bIsDirectoryEmpty = false;
871                         SetFooterItemsVisibility(ENABLE_FOOTER_ITEM);
872                 }
873         }
874
875         if (_pListView != null && _pListView->IsVisible())
876         {
877                 _pListView->UpdateList();
878                 _pListView->Invalidate(true);
879         }
880
881         if (_pIconListView != null && _pIconListView->IsVisible())
882         {
883                 _pIconListView->UpdateList();
884                 _pIconListView->Invalidate(true);
885         }
886
887         if (_pFolderEntryPM != null)
888         {
889                 _pFolderEntryPM->InitThumbnailManager();
890         }
891 }
892 void
893 CategorySearch::OnAppControlCompleted(void)
894 {
895         if (_pFilenames != null)
896         {
897                 if (_pFilenames->GetCount() == 0)
898                 {
899                         SetFooterItemsVisibility(DISABLE_FOOTER_ITEM);
900                 }
901                 else
902                 {
903                         SetFooterItemsVisibility(ENABLE_FOOTER_ITEM);
904                 }
905         }
906         SubBaseFolderEntryForm::OnAppControlCompleted();
907 }