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