0e6c3c8ad699cc21394a07da4c4fcf8cd49a6c23
[apps/osp/MyFiles.git] / src / MfSubFolderFileListForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file: MfSubFolderFileListForm.cpp
19  * @brief: This file contains the implementation of SubFolderFileListForm class, which acts as a media explorer displaying a list of all the files in the sub directories of the root directory opt/Media/
20  * and defines a set of operations that can be done with the files like edit, view etc.
21  */
22
23 #include "MfSubFolderFileListForm.h"
24 #include "MfSearchForm.h"
25
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Utility;
30 using namespace Tizen::Content;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Io;
33 using namespace Tizen::Locales;
34 using namespace Tizen::Media;
35 using namespace Tizen::System;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
39
40 SubFolderFileListForm::SubFolderFileListForm(void)
41 : __pHomeButton(null)
42 , __pUpButton(null)
43 , __pHeader(null)
44 {
45         __counter = 0;
46 }
47
48 SubFolderFileListForm::~SubFolderFileListForm(void)
49 {
50         DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD,*this);
51         if(_pFileEventManager != null)
52         {
53                 _pFileEventManager->RemovePath(__currentDirectoryPath);
54                 delete _pFileEventManager;
55                 _pFileEventManager = null;
56         }
57
58         if (__pHomeButton != null)
59         {
60                 delete __pHomeButton;
61         }
62
63         if (__pUpButton != null)
64         {
65                 delete __pUpButton;
66         }
67 }
68
69 SubFolderFileListForm&
70 SubFolderFileListForm::operator =(const SubFolderFileListForm& pSubFolderFileListForm)
71 {
72         return *this;
73 }
74
75 SubFolderFileListForm::SubFolderFileListForm(const SubFolderFileListForm& pSubFolderFileListForm)
76 {
77         __pHomeButton = pSubFolderFileListForm.__pHomeButton;
78         __pUpButton = pSubFolderFileListForm.__pUpButton;
79         __pHeader = pSubFolderFileListForm.__pHeader;
80         _pLabelDisplayPath = pSubFolderFileListForm._pLabelDisplayPath;
81 }
82
83 bool
84 SubFolderFileListForm::Initialize(void)
85 {
86         Form::Construct(L"IDL_SUB_DIRECTORY");
87         return true;
88 }
89
90 result
91 SubFolderFileListForm::OnInitializing(void)
92 {
93         AppLogDebug("SubFolderFileListForm::Initializing");
94         result r = E_SUCCESS;
95         __counter = 0;
96         int sourceForm = THUMBNAIL_PROVIDER_SOURCEID_SUB_FOLDER_FILE_LIST_FORM;
97         CreateItemSource createitemsource = CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST;
98
99         String path;
100         String ThumbnailProviderPath;
101         String rootParentPath;
102         String displayPath;
103         String extensionVisibility;
104
105         SceneId currentSceneId;
106         AppResource* pAppResource = null;
107         Bitmap* pBitmapHomeButton = null;
108         Bitmap* pBitmapUpButton = null;
109         Bitmap* pBitmapHomeButtonPress = null;
110         Bitmap* pBitmapUpButtonPress = null;
111
112
113         String  SubDirectorySceneOne(L"ScnSubDirectoryForm"), SubDirecorySceneTwo(L"ScnSubDirectoryForm1");
114
115         _renameIndex = 0;
116         _renameOrCreate = SELECT_CREATE_FOLDER;
117
118
119 #if 0
120         DataBindingContext* pContext = null;
121         Bitmap* pHomeBitmap = null;
122         Bitmap* pUpBitmap = null;
123 #endif
124
125         Color formBgColor = GetBackgroundColor();
126
127         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
128
129         pAppResource = UiApp::App::GetInstance()->GetAppResource();
130         TryCatch(pAppResource != null, , "Resource manager not found!");
131
132         //Set FormBackEvent Listener
133         SetFormBackEventListener(this);
134
135         //Get the label control from IDL_SUB_DIRECTORY
136         _pLabelDisplayPath = static_cast< Label* >(GetControl("IDC_LABEL_DISPLAY_PATH"));
137         TryCatch(_pLabelDisplayPath != null, , "Label is Null");
138         _pLabelDisplayPath->SetBounds(0, 0, GetClientAreaBounds().width, H_DISPLAY_PATH_LABEL);
139
140         //pAppResource->GetString(L"IDS_MF_BUTTON_HOME", buttonHome);
141         //pAppResource->GetString(L"IDS_MF_TAB_UP", buttonUp);
142         pAppResource->GetString(L"IDS_MF_OPT_SHOW_FILE_EXTENSION", _showExtension);
143         pAppResource->GetString(L"IDS_MF_TAB_PHONE", displayPath);
144         pAppResource->GetString(L"IDS_MF_OPT_HIDE_FILE_EXTENSION_ABB", _hideExtension);
145         pBitmapHomeButton = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
146         pBitmapUpButton = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
147         pBitmapHomeButtonPress = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
148         pBitmapUpButtonPress = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
149         extensionVisibility = fileExtenstionKeyName;
150         displayPath.Append("/");
151
152         __pHeader = GetHeader();
153
154         if (__pHeader != null)
155         {
156                 __pHomeButton = new (std::nothrow) ButtonItem();
157                 __pHomeButton->Construct(BUTTON_ITEM_STYLE_TEXT, IDA_BTN_HOME);
158                 __pHomeButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL, pBitmapHomeButton);
159                 __pHomeButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED, pBitmapHomeButtonPress);
160
161                 __pUpButton = new (std::nothrow) ButtonItem();
162                 __pUpButton->Construct(BUTTON_ITEM_STYLE_TEXT, IDA_BTN_UP);
163                 __pUpButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL, pBitmapUpButton);
164                 __pUpButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED, pBitmapUpButtonPress);
165
166                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pHomeButton);
167                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pUpButton);
168                 __pHeader->AddActionEventListener(*this);
169                 __pHeader->Invalidate(true);
170         }
171
172         _extensionKeyName.Append(extensionVisibility);
173
174         //Pointer for FileListPresentationModel object
175         _pFolderEntryPM = new (std::nothrow) FolderEntryPresentationModel();
176         TryCatch(_pFolderEntryPM != null, , "Content Manager not found!");
177         _pFolderEntryPM->Construct();
178
179         currentSceneId = SceneManager::GetInstance()->GetCurrentSceneId();
180         AppLogDebug("Current Scene Id : %S", currentSceneId.GetPointer());
181
182         createitemsource = CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST;
183
184         _pFolderEntryPM->SetSourceForm(createitemsource);
185
186         _pFileManager = FolderEntryEditorPresentationModel::GetInstance();
187         TryCatch(_pFileManager != null, , "File Manager not found!");
188
189         //String that contains the path of the file to be displayed on the ListView
190         _displayPath = displayPath;
191
192         path = BasePresentationModel::GetMediaPath();
193         __currentDirectoryPath.Append(path);
194
195         //Initialize the itemprovider class for the listview inside the popup
196         if (_pCustomListViewForPopup == null)
197         {
198                 _pCustomListViewForPopup = new (std::nothrow) CustomListViewForPopup();
199         }
200         TryCatch(_pCustomListViewForPopup != null, , "MfMyFilesApp::ListView For Popup not created!");
201
202         _pCustomListViewForPopup->SetEventListener(this);
203
204         _pBaseItemProvider = new (std::nothrow) BaseItemProvider();
205         TryCatch(_pBaseItemProvider != null, , "Failed to allocate base itemprovider");
206         _pBaseItemProvider->Construct();
207         _pBaseItemProvider->SetSourceForm(createitemsource);
208         _pBaseItemProvider->SetFolderEntryProvider(this);
209         _pBaseItemProvider->SetFooterItemStateChangeListener(this);
210
211         //Get the ListView Control from IDL_SUB_DIRECTORY and set the ItemProvider and Listener
212         _pListView = static_cast< ListView* >(GetControl("IDC_LISTVIEW"));
213         TryCatch(_pListView != null, , "__pListView is Null");
214         _pListView->AddListViewItemEventListener(*this);
215         _pListView->SetItemProvider(*_pBaseItemProvider);
216         _pListView->SetShowState(false);
217
218         _pFooter = GetFooter();
219
220         if (_pThumbnailItemProvider == null)
221         {
222                 _pThumbnailItemProvider = new (std::nothrow) ThumbnailItemProviderAndListener(__currentDirectoryPath, sourceForm);
223                 _pThumbnailItemProvider->SetFolderEntryProvider(this);
224         }
225         TryCatch(_pThumbnailItemProvider != null, , "Failed to allocate Memory to __pSubFolderThumbnailsProvider");
226
227         _pThumbnailItemProvider->SetFooterItemStateChangeListener(this);
228
229         _pIconListView = static_cast< IconListView* >(GetControl("IDC_ICONLISTVIEW_SUB_DIRECTORY_THUMBNAILS"));
230         TryCatch(_pIconListView != null, , "__pIconListviewSubThumbnails is Null");
231         _pIconListView->AddIconListViewItemEventListener(*_pThumbnailItemProvider);
232         _pIconListView->AddTouchEventListener(*this);
233         _pIconListView->SetItemProvider(*_pThumbnailItemProvider);
234         _pIconListView->SetShowState(false);
235
236         _pLongPressGestureDetector = new (std::nothrow) TouchLongPressGestureDetector();
237         _pLongPressGestureDetector->Construct();
238
239 #if 0
240         pContext = GetDataBindingContextN();
241         TryCatch(pContext != null, , "Failed to Fetch the DataBinding Context");
242
243         pContext->Bind(L"ID_DISPLAY_PATH", L"IDC_LABEL_DISPLAY_PATH", L"text", _displayPath, DATA_BINDING_DATA_TYPE_STRING, DATA_BINDING_FLOW_TWO_WAY, DATA_BINDING_TRIGGER_EXPLICIT, null, null, null);
244
245         delete pContext;
246 #endif
247
248         delete pBitmapHomeButton;
249         delete pBitmapUpButton;
250         delete pBitmapHomeButtonPress;
251         delete pBitmapUpButtonPress;
252         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
253         return r;
254
255 CATCH:
256
257         if (_pCustomListViewForPopup != null)
258         {
259                 delete _pCustomListViewForPopup;
260                 _pCustomListViewForPopup = null;
261         }
262
263         if (pBitmapHomeButton != null)
264         {
265                 delete pBitmapHomeButton;
266                 pBitmapHomeButton = null;
267         }
268
269         if (pBitmapUpButton != null)
270         {
271                 delete pBitmapUpButton;
272                 pBitmapUpButton = null;
273         }
274         if (pBitmapHomeButtonPress != null)
275         {
276                 delete pBitmapHomeButtonPress;
277                 pBitmapHomeButtonPress = null;
278         }
279         if (pBitmapUpButtonPress != null)
280         {
281                 delete pBitmapUpButtonPress;
282                 pBitmapUpButtonPress = null;
283         }
284         return r;
285 }
286
287 result
288 SubFolderFileListForm::OnTerminating(void)
289 {
290         result r = E_SUCCESS;
291         //((MfMyFilesApp*)Application::GetInstance())->SetCurrentView(null);
292
293         _pFooter = GetFooter();
294         if (_pFooter != null)
295         {
296                 _pFooter->RemoveAllButtons();
297                 _pFooter->RemoveAllItems();
298         }
299
300         __pHeader = GetHeader();
301         if (__pHeader != null)
302         {
303                 __pHeader->RemoveAllButtons();
304                 __pHeader->RemoveAllItems();
305         }
306
307         return r;
308 }
309
310 void
311 SubFolderFileListForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
312 {
313         SceneManager* pSceneManager = SceneManager::GetInstance();
314         result r = E_SUCCESS;
315         String parentPath;
316         String currentPath;
317         String delim(L"/");
318         String token;
319         String displayPath;
320 #if 0
321         AppLogDebug("Scene History");
322         bool searchHistory = CheckSearchHistory();
323         String currentPath = FolderNavigationPresentationModel::GetCurrentPath();
324         String parentPath;
325
326         SceneManager* pSceneManager = SceneManager::GetInstance();
327 #endif
328         if (CheckSearchHistory() == true)
329         {
330 #if 0
331                 parentPath = FolderNavigationPresentationModel::GetSearchPreviousPath();
332                 AppLogDebug("ParentPath is %S", parentPath.GetPointer());
333                 FolderNavigationPresentationModel::SetCurrentFilePath(parentPath);
334                 AppLogDebug("__previousSceneName is %S", __previousSceneName.GetPointer());
335
336                 //pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
337
338
339                 if (parentPath == currentPath)
340                 {
341                         pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
342                 }
343                 else
344                 {
345                         if (__previousSceneName == IDSCN_SUB_DIRECTORY_FORM1 || __previousSceneName == IDSCN_SUB_DIRECTORY_FORM)
346                         {
347                                 String searchPath = FolderNavigationPresentationModel::GetCurrentPath();
348
349                                 FolderNavigationPresentationModel::SetSearchPreviousPath(searchPath);
350                                 if (SceneManager::GetInstance()->IsSceneAlive(__previousSceneName))
351                                 {
352                                         r = pSceneManager->GoForward(ForwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
353                                         AppLogDebug("result is %s", GetErrorMessage(r));
354                                 }
355                                 else
356                                 {
357                                         pSceneManager->GoForward(ForwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
358                                         AppLogDebug("result is %s", GetErrorMessage(r));
359                                 }
360                         }
361                         else
362                         {
363                                 r = pSceneManager->GoBackward(BackwardSceneTransition(__previousSceneName, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
364                                 AppLogDebug("result is %s", GetErrorMessage(r));
365                         }
366                 }
367 #endif
368                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
369         }
370         else
371         {
372                 //ShowParentDirectoryView();
373                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
374                 if (currentPath == BasePresentationModel::GetMediaPath() || currentPath == BasePresentationModel::GetSdCardPath())
375                 {
376                         FolderNavigationPresentationModel::SetCurrentFilePath(currentPath);
377                         r = ShowHomeView();
378                 }
379                 else
380                 {
381                         parentPath = FolderNavigationPresentationModel::GetParentPath();
382
383                         FolderNavigationPresentationModel::SetCurrentFilePath(parentPath);
384                         r = pSceneManager->GoForward(ForwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
385                 }
386         }
387 }
388
389 void
390 SubFolderFileListForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
391                 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
392 {
393         AppLogDebug("OnSceneActivatedN ENTER");
394
395         int listViewDisplayType = VIEW_TYPE_AS_NORMAL_LIST;
396
397         int sourceForm = THUMBNAIL_PROVIDER_SOURCEID_SUB_FOLDER_FILE_LIST_FORM;
398         CreateItemSource createitemsource = CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST;
399
400         result r = E_SUCCESS;
401         String parentPath;
402         String viewStyleKeyName(L"ListDisplayType");
403
404         String phone;
405         String sdCard;
406         String external;
407
408         String received_Filepath;
409         String* pReceived_Filename = null;
410         int receivedStorageType = null;
411
412         AppRegistry* pAppRegistry = null;
413         AppResource* pAppResource = null;
414         String check;
415         pAppResource = UiApp::GetInstance()->GetAppResource();
416         TryCatch(pAppResource != null, , "Failed to fetch AppResource");
417
418         //Create the FooterControls of IDL_SUB_DIRECTORY
419         r = CreateFooterControls();
420         TryCatch(r == E_SUCCESS, , "Failed to create footer controls");
421
422         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
423
424         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
425
426         pAppResource->GetString(L"IDS_MF_TAB_PHONE", phone);
427         pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", sdCard);
428         pAppResource->GetString(L"IDS_MF_TAB_EXTERNAL_STORAGE", external);
429
430         phone.Append(L"/");
431         sdCard.Append(L"/");
432         external.Append(L"/");
433
434         SceneManager::GetInstance()->AddSceneManagerEventListener(*this);
435         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
436
437         SetCurrentDirectoryFlag(false);
438
439         if (_pBaseItemProvider != null)
440         {
441                 _pBaseItemProvider->SetSourceForm(createitemsource);
442         }
443
444         if (_pFileManager != null)
445         {
446                 _pFileManager->SetFileManagingListener(this);
447         }
448
449         if (previousSceneId == IDSCN_CREATE_FOLDER_FORM)
450         {
451                 if (_renameOrCreate == SELECT_RENAME)
452                 {
453                         return;
454                 }
455         }
456
457         receivedStorageType = FolderNavigationPresentationModel::GetStorageType();
458
459         if (_pLabelDisplayPath != null)
460         {
461                 switch (receivedStorageType)
462                 {
463                 case MEMORY_TYPE_PHONE:
464                 {
465                         _displayPath = phone;
466                         _storageType = MEMORY_TYPE_PHONE;
467                 }
468                 break;
469
470                 case MEMORY_TYPE_SD_CARD:
471                 {
472                         _displayPath = sdCard;
473                         _storageType = MEMORY_TYPE_SD_CARD;
474                 }
475                 break;
476
477                 case MEMORY_TYPE_EXTERNAL:
478                 {
479                         _displayPath = external;
480                         _storageType = MEMORY_TYPE_EXTERNAL;
481                 }
482                 break;
483
484                 default:
485                 {
486                 }
487                 break;
488                 }
489
490         }
491
492         r = pAppRegistry->Get(viewStyleKeyName, listViewDisplayType);
493         TryCatch(r == E_SUCCESS, , "Failed to get values from AppRegistry");
494
495         _flagViewAsStatus = listViewDisplayType;
496
497         if (_pMoreContextMenu != null)
498         {
499                 _pMoreContextMenu->SetShowState(false);
500         }
501
502
503
504 #if 0
505         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_USB_CLIENT, *this);
506 #endif
507
508
509         if (pArgs != null)
510         {
511                 pReceived_Filename = static_cast< String* >(pArgs->GetAt(0));
512
513                 received_Filepath = FolderNavigationPresentationModel::GetCurrentPath();
514                 receivedStorageType = FolderNavigationPresentationModel::GetStorageType();
515
516                 if (pReceived_Filename != null)
517                 {
518                         check.Append(*pReceived_Filename);
519                         __pHeader = GetHeader();
520
521                         if (__pHeader != null)
522                         {
523                                 __pHeader->SetTitleText(check);
524                                 __pHeader->Invalidate(true);
525                         }
526                 }
527
528                 __currentDirectoryPath.Clear();
529                 __currentDirectoryPath.Append(received_Filepath);
530
531                 //Get the Directory Entries for the received Filepath.
532                 if (_pFolderEntryPM != null)
533                 {
534                         _pFolderEntryPM->SetSourceForm(CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST);
535                         _pFolderEntryPM->SetFolderEntryPath(received_Filepath);
536                         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
537                         TryCatch(_pFilenames != null, , "Failed to allocate Memory to __pFilenames");
538                 }
539
540
541                 if (_pThumbnailItemProvider != null)
542                 {
543                         _pThumbnailItemProvider->SetCreateItemSource(sourceForm);
544                         _pThumbnailItemProvider->SetFolderEntryProvider(this);
545                 }
546
547                 SetNextDisplayPath();
548                 SetHeaderTitleText(__currentDirectoryPath);
549
550         }
551         else
552         {
553                 //Empty Arguments Received.
554
555                 __currentDirectoryPath = FolderNavigationPresentationModel::GetCurrentPath();
556                 parentPath.Append(__currentDirectoryPath);
557                 SetNextDisplayPath();
558                 SetHeaderTitleText(__currentDirectoryPath);
559
560                 if (_pFolderEntryPM != null)
561                 {
562                         _pFolderEntryPM->SetSourceForm(CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST);
563                         _pFolderEntryPM->SetFolderEntryPath(parentPath);
564                         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
565                         TryCatch(_pFilenames != null, , "Failed to allocate Memory to Filenames ArrayList");
566                 }
567
568                 if (_pThumbnailItemProvider != null)
569                 {
570                         _pThumbnailItemProvider->SetCreateItemSource(sourceForm);
571                         _pThumbnailItemProvider->SetFolderEntryProvider(this);
572                 }
573         }
574
575         //_pFileListPM->SetFileEventListener(this);
576         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
577
578
579         if (pArgs != null)
580         {
581                 pArgs->RemoveAll(false);
582                 delete pArgs;
583         }
584         return;
585
586         CATCH:
587         if (pArgs != null)
588         {
589                 pArgs->RemoveAll(false);
590                 delete pArgs;
591         }
592         return;
593 }
594
595 void
596 SubFolderFileListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
597 {
598         AppLogDebug("ENTER");
599
600         result r = E_SUCCESS;
601         SceneManager* pSceneManager = null;
602         pSceneManager = SceneManager::GetInstance();
603
604         switch (actionId)
605         {
606         case IDA_BTN_HOME:
607         {
608                 //Navigate to the TopFolderFileListForm.
609                 String homeRootPath;
610                 homeRootPath.Append(__currentDirectoryPath);
611
612                 while ((homeRootPath != BasePresentationModel::GetMediaPath()) && (homeRootPath != BasePresentationModel::GetSdCardPath()))
613                 {
614                         FolderNavigationPresentationModel::SetCurrentFilePath(homeRootPath);
615                         homeRootPath.Clear();
616                         homeRootPath = FolderNavigationPresentationModel::GetParentPath();
617                 }
618
619                 FolderNavigationPresentationModel::SetCurrentFilePath(homeRootPath);
620                 //ShowHomeView();
621                 if (CheckSearchHistory())
622                 {
623                         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
624                         //TryCatch(r == E_SUCCESS, , "scene transition failed");
625                 }
626                 else
627                 {
628                         r = pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_DESTROY), null);
629                         //TryCatch(r == E_SUCCESS, , "scene transition failed");
630                 }
631         }
632         break;
633
634         case IDA_BTN_UP:
635         {
636                 bool searchHistory = CheckSearchHistory();
637                 String previousPath;
638                 //Navigate to the ParentForm.
639                 if (searchHistory)
640                 {
641                         __previousSceneName = SceneManager::GetInstance()->GetCurrentSceneId();
642                         AppLogDebug("__previousSceneName is %S", __previousSceneName.GetPointer());
643                         previousPath = FolderNavigationPresentationModel::GetCurrentPath();
644                         AppLogDebug("previousPath is %S", previousPath.GetPointer());
645                         FolderNavigationPresentationModel::SetSearchPreviousPath(previousPath);
646                 }
647                 ShowParentDirectoryView();
648         }
649         break;
650
651         case IDA_CONTEXT_MENU_HIDE_EXTENSION:
652         {
653                 __currentDirectoryPath.Clear();
654                 __currentDirectoryPath = FolderNavigationPresentationModel::GetCurrentPath();
655                 HideFileExtension();
656         }
657
658         break;
659
660         case IDA_CONTEXT_MENU_SHOW_EXTENSION:
661         {
662                 __currentDirectoryPath.Clear();
663                 __currentDirectoryPath = FolderNavigationPresentationModel::GetCurrentPath();
664                 ShowFileExtension();
665         }
666
667         break;
668
669         default:
670         {
671                 SubBaseOnActionPerformed(source, actionId);
672         }
673         break;
674         }
675         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
676 }
677
678 void
679 SubFolderFileListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
680                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
681 {
682         ((MyFilesApp*)Application::GetInstance())->SetCurrentView(null);
683
684         DeviceManager::RemoveAllDeviceEventListeners();
685
686         if (_pIconListView != null)
687         {
688                 _pIconListView->RemoveGestureDetector(*_pLongPressGestureDetector);
689         }
690
691         TryReturn(_pFolderEntryPM!=null, , "FolderEntryPresentationModel is NULL") ;
692         _pFolderEntryPM->StopThumbnailManager(true);
693         _pFolderEntryPM->SetCurrentReqId(0);
694
695         if(_pFileEventManager != null)
696         {
697                 _pFileEventManager->RemovePath(__currentDirectoryPath);
698                 delete _pFileEventManager;
699                 _pFileEventManager = null;
700         }
701 }
702
703
704 void
705 SubFolderFileListForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
706 {
707         //When state is changed, push the parent filepath to the stack and save the selected path as
708         //root path so that listview can be refreshed to this path the next time. If Up button is click in
709         //the mean time, refresh the root path to be pushed to the parent path (changed in ShowParentView())
710
711         AppLogDebug("ENTER");
712         String nextFilename;
713         String tempRootMediaPath;
714         String filePathToPush;
715         String searchPath;
716         bool searchHistory = false;
717         //result r = E_FAILURE;
718         DirectoryEntry* pDirStr = null;
719
720         ArrayList* pArgs = new (std::nothrow) ArrayList();
721         pArgs->Construct();
722
723
724         SceneManager* pSceneManager = SceneManager::GetInstance();
725         SceneId currentSceneId = pSceneManager->GetCurrentSceneId();
726
727         if (_pFilenames != null)
728         {
729                 pDirStr = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
730                 if (pDirStr != null)
731                 {
732                         //temprootmediapath gives the full file path of the selected item
733                         tempRootMediaPath = pDirStr->GetFullFilePath();
734
735                         if (pDirStr->IsDirectory())
736                         {
737                                 //Append the name of the file to the existing path
738                                 nextFilename = pDirStr->GetFileName();
739                                 _currentFileName.Clear();
740                                 _currentFileName = pDirStr->GetFileName();
741
742                                 //tempRootMediaPath.Append(L"/");
743                                 //Set the full file path as future parent filepath, changed when Up button is
744                                 //clicked..
745                                 if (__currentDirectoryPath != null)
746                                 {
747                                         __currentDirectoryPath.Clear();
748                                         //__currentDirectoryPath.Append(tempRootMediaPath);
749                                         __currentDirectoryPath = pDirStr->GetFullFilePath();
750                                 }
751                                 FolderNavigationPresentationModel::SetCurrentFilePath(__currentDirectoryPath);
752
753                                 pArgs->Add(&nextFilename);
754
755                                 searchHistory = CheckSearchHistory();
756                                 if (searchHistory)
757                                 {
758                                         searchPath = FolderNavigationPresentationModel::GetParentPath();
759                                         FolderNavigationPresentationModel::SetSearchPreviousPath(searchPath);
760                                 }
761
762                                 pSceneManager->GoForward(ForwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
763                         }
764                         else
765                         {
766                                 _indexTracker = index;                  //For OnFileEventOccured (RemoveCacheEntry)
767                                 _pathOfSelectedFile = tempRootMediaPath;
768                                 //It's not a directory, Launch the AppControl.
769                                 if (_pathOfSelectedFile.EndsWith(L".tpk") || _pathOfSelectedFile.EndsWith(L".wgt"))
770                                 {
771                                         String* pFileUriScheme = new (std::nothrow) String(L"file://");
772                                         pFileUriScheme->Append(_pathOfSelectedFile);
773
774                                         AppControl::FindAndStart(L"http://tizen.org/appcontrol/operation/view", pFileUriScheme, null, null, null, null);
775                                         delete pFileUriScheme;
776                                 }
777                                 else
778                                 {
779                                         CustomAppControl* pCustomAppControl = CustomAppControl::GetInstance();
780                                         if (pCustomAppControl != null)
781                                         {
782                                                 __counter = index;
783
784                                                 pCustomAppControl->SetAppControlListener(null);
785                                                 fileForAppControl = _pathOfSelectedFile;
786                                                 AppControl* pAppControlInUse = pCustomAppControl->LaunchAppControl(_pathOfSelectedFile);
787                                                 if (pAppControlInUse != null)
788                                                         CustomAppControl::SetAppControlInUse(pAppControlInUse);
789                                         }
790                                 }
791                         }
792                 }
793         }
794
795         return;
796
797 }
798
799 result
800 SubFolderFileListForm::ShowHomeView(void)
801 {
802         AppLogDebug("Enter");
803         SceneManager* pSceneManager = null;
804         result r = E_SUCCESS;
805         pSceneManager = SceneManager::GetInstance();
806         if (pSceneManager != null)
807         {
808                 if (CheckSearchHistory())
809                 {
810                         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
811                         TryCatch(r == E_SUCCESS, , "scene transition failed");
812                 }
813                 else
814                 {
815                         r = pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_DESTROY), null);
816                         TryCatch(r == E_SUCCESS, , "scene transition failed");
817                 }
818         }
819
820         if (_pFolderEntryPM != null)
821         {
822                 _pFolderEntryPM->InitThumbnailManager();
823         }
824
825         AppLogDebug("Exit");
826         return r;
827 CATCH:
828         return r;
829 }
830
831 void
832 SubFolderFileListForm::SetParentDisplayPath(void)
833 {
834         //Sets the display path for the parent directory using the current path.
835
836         String dislayPath;
837         String delim(L"/");
838         String parentDisplayPath;
839         String token;
840 #if 0
841         DataBindingContext* pContext = null;
842         pContext = GetDataBindingContextN();
843
844         if (pContext != null)
845         {
846                 //Update binding on the source to fetch the current display path.
847                 pContext->UpdateBinding(L"ID_DISPLAY_PATH", DATA_BINDING_DESTINATION_TYPE_SOURCE);
848         }
849 #endif
850
851         StringTokenizer tokenizer(_displayPath, delim);
852
853         //Use a string tokenizer to get the filepath until it's the last token, break the loop when
854         //it is the last token
855         while (tokenizer.HasMoreTokens())
856         {
857                 int tokenCount = tokenizer.GetTokenCount();
858
859                 if (tokenCount != 1)
860                 {
861                         tokenizer.GetNextToken(token);
862                         parentDisplayPath.Append(token);
863                         parentDisplayPath.Append(L"/");
864                 }
865                 else
866                 {
867                         break;
868                 }
869         }
870
871         //Set the display path to that of the generated filepath from the tokenizer
872         _displayPath = parentDisplayPath;
873
874         if (_pLabelDisplayPath != null)
875         {
876                 _pLabelDisplayPath->SetText(_displayPath);
877                 _pLabelDisplayPath->Invalidate(true);
878         }
879 #if 0
880         if (pContext != null)
881         {
882                 //Update Binding on the Target control to display the currently constructed path.
883                 pContext->UpdateBinding(L"ID_DISPLAY_PATH", DATA_BINDING_DESTINATION_TYPE_TARGET);
884         }
885
886         if (pContext != null)
887         {
888                 delete pContext;
889         }
890 #endif
891 }
892
893 void
894 SubFolderFileListForm::ShowParentDirectoryView(void)
895 {
896         AppLogDebug("ENTER");
897         //Shows the files of the above/parent directory
898         CreateItemSource sourceForm = CREATE_ITEM_SOURCE_NONE;
899         int fileCount = 0;
900         int folderCount = 0;
901
902         result r = E_SUCCESS;
903
904         String displayPath;
905         String pPoppedPath;
906         String ParentPath;
907         String backUpCurrentPath;
908
909         backUpCurrentPath = FolderNavigationPresentationModel::GetCurrentPath();
910
911 //      if(backUpCurrentPath == BasePresentationModel::GetMediaPath() || backUpCurrentPath == BasePresentationModel::GetSdCardPath())
912 //      {
913         //              return;
914         //      }
915
916         displayPath = defaultPhoneBody;
917         displayPath.Append("/");
918
919         //SetFooterVisibility(ENABLE_FOOTER_ITEM);
920
921         if (backUpCurrentPath == BasePresentationModel::GetMediaPath() || backUpCurrentPath == BasePresentationModel::GetSdCardPath() || backUpCurrentPath == BasePresentationModel::GetUsbPath())
922         {
923                 //It is the homeview, so call showhomeview
924                 r = ShowHomeView();
925                 TryCatch(r == E_SUCCESS, , "scene transition failed");
926                 //return;
927         }
928         else
929         {
930                 ParentPath = FolderNavigationPresentationModel::GetParentPath();
931
932                 //RemovePath to remove FileEventListener
933                 if(_pFileEventManager != null)
934                 {
935                         _pFileEventManager->RemovePath(__currentDirectoryPath);
936                 }
937                 __currentDirectoryPath.Clear();
938                 __currentDirectoryPath.Append(ParentPath);
939
940                 //AddPath to add FileEventListener for Parent Directory Path
941                 if(_pFileEventManager != null)
942                 {
943                         _pFileEventManager->AddPath(__currentDirectoryPath, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_MOVED_FROM | FILE_EVENT_TYPE_MOVED_TO | FILE_EVENT_TYPE_DELETE );
944                 }
945
946                 FolderNavigationPresentationModel::SetCurrentFilePath(__currentDirectoryPath);
947
948                 if (_pFolderEntryPM != null)
949                 {
950                         _pFolderEntryPM->GetFolderEntryCount(__currentDirectoryPath, folderCount, fileCount);
951                 }
952
953                 SetParentDisplayPath();
954                 SetHeaderTitleText(ParentPath);
955                 SetFooterVisibility(ENABLE_FOOTER_ITEM);
956
957                 if (fileCount == 0)
958                 {
959                         _pFooter = GetFooter();
960                         if (_pFooter)
961                         {
962                                 _pFooter->SetItemEnabled(1, false);
963                                 _pFooter->Invalidate(true);
964                         }
965                 }
966                 //Remove the current files from the filenames list
967                 if (_pFolderEntryPM != null)
968                 {
969                         //__pContentManager->ClearList();
970                         _pFolderEntryPM->SetFolderEntryPath(ParentPath);
971                         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
972                         TryCatch(_pFilenames != null, , "Failed to fetch ArrayList from the ContentBrowser!");
973
974                         sourceForm =  _pFolderEntryPM->GetSourceForm();
975                         AppLogDebug("Current Source Form is : %d",sourceForm);
976
977                         /*if ( sourceForm == CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST )
978                                 _pFolderEntryPM->SetSourceForm(CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST_TWO);
979                         else
980                                 _pFolderEntryPM->SetSourceForm(CREATE_ITEM_SOURCE_SUB_FOLDER_FILE_LIST);*/
981
982                         _pFolderEntryPM->InitThumbnailManager();
983
984                 }
985
986                 //Get the files in the parent path of the current view
987
988                 //Update the icon list to view the files of the parent directory
989                 if (_pListView != null && _pListView->IsVisible())
990                 {
991                         r = _pListView->UpdateList();
992                 }
993
994                 if (_pIconListView != null && _pIconListView->IsVisible())
995                 {
996                         r = _pIconListView->UpdateList();
997                 }
998         }
999         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
1000         return;
1001
1002 CATCH:
1003         FolderNavigationPresentationModel::SetCurrentFilePath(backUpCurrentPath);
1004 }
1005
1006
1007 void
1008 SubFolderFileListForm::OnNotificationReceived(Tizen::Base::Collection::ArrayList* pArgs)
1009 {
1010         AppLogDebug("Enter");
1011
1012         Integer* pFileProcessingResult = null;
1013         String cachePath;
1014
1015         TryCatch(pArgs != null, , "Argument list received is invalid!");
1016         pFileProcessingResult = (Integer*) pArgs->GetAt(0);
1017
1018         TryCatch(pFileProcessingResult != null, , "FileProcessing Result  list is invalid!");
1019
1020         switch (pFileProcessingResult->ToInt())
1021         {
1022                 case FILE_MANAGING_RESULT_DELETING_SUCCESS:
1023                 {
1024                         AppLogDebug("FILE DELETION SUCCESSFULL");
1025                         HideFileProgressingPopup();
1026                 }
1027                 break;
1028
1029                 case FILE_MANAGING_RESULT_DELETING_FAILED:
1030                 {
1031                         HideFileProgressingPopup();
1032                 }
1033                 break;
1034                 case FILE_MANAGING_RESULT_THREAD_STOP:
1035                 {
1036                         HideFileProgressingPopup();
1037                 }
1038                 break;
1039                 default:
1040                 {
1041                         //Do Nothing.
1042                 }
1043                 break;
1044         }
1045
1046         _pFolderEntryPM->InitThumbnailManager();                        //for thumbnail issues/disappering images/defulat images etc...
1047
1048         SetFooterVisibility(DISABLE_FOOTER_ITEM);
1049 CATCH:
1050         if (pArgs != null)
1051         {
1052                 pArgs->RemoveAll(true);
1053                 delete pArgs;
1054         }
1055         ///return this;
1056 }
1057
1058 void
1059 SubFolderFileListForm::OnDataBindingSourceUpdated(const Tizen::Base::String& bindingId, const Tizen::Base::String& controlName, const Tizen::Base::String& propertyName)
1060 {
1061         //Empty Implementation.
1062 }
1063
1064 void
1065 SubFolderFileListForm::OnDataBindingTargetUpdated(const Tizen::Base::String& bindingId, const Tizen::Base::String& controlName, const Tizen::Base::String& propertyName)
1066 {
1067         //Empty Implementation.
1068 }
1069
1070 void
1071 SubFolderFileListForm::OnDataBindingValidationFailed(const Tizen::Base::String& bindingId, const Tizen::Base::String& controlName, const Tizen::Base::String& propertyName, Tizen::Ui::DataBindingDestinationType destType)
1072 {
1073         //Empty Implementation.
1074 }
1075
1076 void
1077 SubFolderFileListForm::OnFileEventExecuted(const Tizen::Base::String& path, const unsigned long eventId)
1078 {
1079         AppLogDebug("ENTER");
1080
1081         int badgeNumber = 0;
1082         result r = E_SUCCESS;
1083
1084         //      Tizen::Shell::NotificationManager* pNotiMgr = null;
1085
1086         NotificationManager* pNotiMgr = null;
1087         AppResource* pAppResource = null;
1088         pAppResource = UiApp::GetInstance()->GetAppResource();
1089         TryCatch(pAppResource != null, , "Failed to fetch AppResource");
1090
1091         pNotiMgr = new (std::nothrow) NotificationManager();
1092         TryCatch(pNotiMgr != null, , "Failed to fetch AppNotificationManager");
1093
1094         pNotiMgr->Construct();
1095         badgeNumber = pNotiMgr->GetBadgeNumber();
1096         badgeNumber++;
1097
1098         if (_pFolderEntryPM != null)
1099         {
1100                 //_pFolderEntryPM->SetFileEventListener(null);
1101                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
1102                 TryCatch(_pFilenames != null, , "File Names List retrieval failed");
1103         }
1104
1105         switch (eventId)
1106         {
1107         case FILE_EVENT_TYPE_CREATE:
1108         {
1109                 if (_pListView != null && _pListView->IsVisible())
1110                 {
1111                         _pListView->RefreshList(_pFilenames->GetCount() - 1, LIST_REFRESH_TYPE_ITEM_ADD);
1112                 }
1113                 if (_pIconListView != null && _pIconListView->IsVisible())
1114                 {
1115                         _pIconListView->RefreshList(_pFilenames->GetCount() - 1, LIST_REFRESH_TYPE_ITEM_ADD);
1116                 }
1117
1118         }
1119         break;
1120
1121         case FILE_EVENT_TYPE_DELETE:
1122         {
1123                 if (_pListView != null && _pListView->IsVisible())
1124                 {
1125                         _pListView->RefreshList(__counter, LIST_REFRESH_TYPE_ITEM_REMOVE);
1126                 }
1127                 if (_pIconListView != null && _pIconListView->IsVisible())
1128                 {
1129                         if (_pThumbnailItemProvider != null)
1130                         {
1131                                 __counter = _pThumbnailItemProvider->GetPressedIndex();
1132                         }
1133                         _pIconListView->RefreshList(__counter, LIST_REFRESH_TYPE_ITEM_REMOVE);
1134                 }
1135
1136         }
1137         break;
1138
1139         case FILE_EVENT_TYPE_DELETE_SELF:
1140         {
1141                 ShowHomeView();
1142         }
1143         break;
1144
1145         default:
1146         {
1147                 //Do Nothing.
1148         }
1149         break;
1150         }
1151
1152         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
1153
1154         if (pNotiMgr != null)
1155         {
1156                 delete pNotiMgr;
1157                 pNotiMgr = null;
1158         }
1159         return;
1160
1161 CATCH:
1162         if (pNotiMgr != null)
1163         {
1164                 delete pNotiMgr;
1165                 pNotiMgr = null;
1166         }
1167         return;
1168 }
1169
1170 void
1171 SubFolderFileListForm::SetHeaderTitleText(Tizen::Base::String& filePath)
1172 {
1173         String token;
1174         String parentFileName;
1175         String delimiter(L"/");
1176         StringTokenizer tokenizer(filePath, delimiter);
1177
1178         AppResource* pAppResource = null;
1179
1180         pAppResource = UiApp::App::GetInstance()->GetAppResource();
1181
1182         if (filePath == BasePresentationModel::GetMediaPath())
1183         {
1184                 if (pAppResource != null)
1185                 {
1186                         pAppResource->GetString(L"IDS_MF_TAB_PHONE", parentFileName);
1187                 }
1188         }
1189         else if (filePath == BasePresentationModel::GetSdCardPath())
1190         {
1191                 if (pAppResource != null)
1192                 {
1193                         pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", parentFileName);
1194                 }
1195         }
1196         else
1197         {
1198                 while (tokenizer.HasMoreTokens())
1199                 {
1200                         int tokenCount = tokenizer.GetTokenCount();
1201
1202                         if (tokenCount == 1)
1203                         {
1204                                 tokenizer.GetNextToken(parentFileName);
1205                         }
1206                         else
1207                         {
1208                                 tokenizer.GetNextToken(token);
1209                         }
1210                 }
1211         }
1212
1213         __pHeader = GetHeader();
1214         if (__pHeader != null)
1215         {
1216                 if (!parentFileName.IsEmpty())
1217                 {
1218                         __pHeader->SetTitleText(parentFileName);
1219                         __pHeader->Invalidate(true);
1220                 }
1221         }
1222 }
1223
1224 void
1225 SubFolderFileListForm::OnDeviceChange(ComponentType deviceType, const Tizen::Base::String& state)
1226 {
1227         bool setMediaPath = false;
1228         MemoryType currentMemoryType = MEMORY_TYPE_PHONE;
1229         String unmounted = sdCardStatusUnmounted;
1230         String removed = usbDeviceStatusRemoved;
1231         String currentPath;
1232
1233         SceneManager* pSceneManager = null;
1234
1235         if (state == unmounted || state == removed)
1236         {
1237                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
1238                 if (state == unmounted)
1239                 {
1240                         if (currentPath.Contains(BasePresentationModel::GetSdCardPath()))
1241                         {
1242                                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetMediaPath());
1243                                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
1244                                 setMediaPath = true;
1245                         }
1246                 }
1247
1248                 if (state == removed)
1249                 {
1250                         if (currentPath.Contains(BasePresentationModel::GetUsbPath()))
1251                         {
1252                                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetMediaPath());
1253                                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
1254                                 setMediaPath = true;
1255                         }
1256                 }
1257
1258                 if (setMediaPath)
1259                 {
1260                         pSceneManager = SceneManager::GetInstance();
1261                         if (pSceneManager != null)
1262                         {
1263                                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_DESTROY), null);
1264                         }
1265                 }
1266         }
1267 }
1268
1269 void
1270 SubFolderFileListForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
1271 {
1272         ComponentType currentDeviceType;
1273         switch (deviceType)
1274         {
1275         case StorageCard:
1276         {
1277                 currentDeviceType = COMPONENT_TYPE_STORAGE_CARD;
1278         }
1279         break;
1280
1281         case UsbClient:
1282         {
1283                 currentDeviceType = COMPONENT_TYPE_USB;
1284         }
1285         break;
1286
1287         default:
1288         {
1289                 //Do Nothing.
1290         }
1291         break;
1292         }
1293         OnDeviceChange(currentDeviceType, state);
1294 }
1295
1296 void
1297 SubFolderFileListForm::OnSceneTransitionCompleted (const Tizen::Ui::Scenes::SceneId &previousSceneId, const Tizen::Ui::Scenes::SceneId &currentSceneId)
1298 {
1299         AppLogDebug("Enter");
1300
1301         AppRegistry* pAppRegistry = null;
1302         String sortbyKeyName(L"SortBy");
1303         int sortStyle = SORT_BY_TYPE_DATE_RECENT;
1304         int fileCount = 0;
1305         int folderCount = 0;
1306
1307         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
1308         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
1309
1310         _pLongPressGestureDetector->AddLongPressGestureEventListener(*this);
1311         if (_pIconListView != null)
1312         {
1313                 _pIconListView->AddGestureDetector(*_pLongPressGestureDetector);
1314         }
1315
1316         if (_pFileEventManager != null)
1317         {
1318                 delete _pFileEventManager;
1319                 _pFileEventManager = null;
1320
1321         }
1322         _pFileEventManager = new (std::nothrow)FileEventManager();
1323         _pFileEventManager->Construct(*this);
1324
1325         _pFileEventManager->AddPath(__currentDirectoryPath, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_MOVED_FROM | FILE_EVENT_TYPE_MOVED_TO | FILE_EVENT_TYPE_DELETE );
1326
1327         _pFolderEntryPM->GetFolderEntryCount(FolderNavigationPresentationModel::GetCurrentPath(),folderCount, fileCount);
1328
1329         if (previousSceneId == IDSCN_CREATE_FOLDER_FORM)
1330         {
1331                 if (_renameOrCreate == SELECT_RENAME)
1332                 {
1333                         pAppRegistry->Get(sortbyKeyName, sortStyle);
1334
1335                         if (sortStyle == SORT_BY_TYPE_NAME_ASCENDING || sortStyle == SORT_BY_TYPE_NAME_DESCENDING
1336                                         || sortStyle == SORT_BY_TYPE_DATE_OLDEST || sortStyle == SORT_BY_TYPE_DATE_RECENT)
1337                         {
1338                                 _pFolderEntryPM->SetFolderEntryPath(FolderNavigationPresentationModel::GetCurrentPath());
1339                                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
1340
1341                                 if (_pListView != null && _pListView->IsVisible())
1342                                 {
1343                                         _pListView->UpdateList();
1344                                         _pListView->ScrollToItem(0);
1345                                 }
1346                                 if (_pIconListView != null && _pIconListView->IsVisible())
1347                                 {
1348                                         _pIconListView->UpdateList();
1349                                         _pIconListView->ScrollToItem(0);
1350                                 }
1351                                 _pFolderEntryPM->InitThumbnailManager();
1352                         }
1353                         else
1354                         {
1355                                 if (_pListView != null && _pListView->IsVisible())
1356                                         _pListView->RefreshList(_renameIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
1357                                 if (_pIconListView != null && _pIconListView->IsVisible())
1358                                         _pIconListView->RefreshList(_renameIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
1359                         }
1360                         return;
1361                 }
1362         }
1363
1364         if (CheckSearchHistory())
1365         {
1366                 __previousSceneName = previousSceneId;
1367         }
1368
1369         SwitchViewType();
1370
1371         if (_pFilenames != null && _pFilenames->GetCount() == 0)
1372         {
1373                 _bIsDirectoryEmpty = true;
1374
1375                 SetFooterVisibility(DISABLE_FOOTER_ITEM);
1376
1377         }
1378         else
1379         {
1380                 _bIsDirectoryEmpty = false;
1381
1382                 SetFooterVisibility(ENABLE_FOOTER_ITEM);
1383
1384                 if (fileCount == 0)
1385                 {
1386                         _pFooter = GetFooter();
1387                         if (_pFooter)
1388                         {
1389                                 _pFooter->SetItemEnabled(1, false);
1390                                 _pFooter->Invalidate(true);
1391                         }
1392                 }
1393         }
1394
1395         if (_pFolderEntryPM != null)
1396         {
1397                 _pFolderEntryPM->InitThumbnailManager();
1398         }
1399 }
1400
1401 void
1402 SubFolderFileListForm::OnSceneTransitionStarted (const Tizen::Ui::Scenes::SceneId &currentSceneId, const Tizen::Ui::Scenes::SceneId &nextSceneId)
1403 {
1404         //Empty Implementation.
1405 }
1406
1407 void
1408 SubFolderFileListForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1409 {
1410         AppLogDebug("ENTER");
1411         switch (orientationStatus)
1412         {
1413         case ORIENTATION_STATUS_LANDSCAPE:
1414         {
1415                 SceneManager* pSceneManager = null;
1416                 pSceneManager = SceneManager::GetInstance();
1417                 if (pSceneManager != null)
1418                 {
1419                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SPLIT_PANEL_FORM, SCENE_TRANSITION_ANIMATION_TYPE_NONE), null);
1420                 }
1421         }
1422         break;
1423         default:
1424         break;
1425         }
1426 }
1427
1428 void
1429 SubFolderFileListForm::OnFileEventOccured(const unsigned long events,const Tizen::Base::String &  path, const unsigned int      eventId)
1430 {
1431         AppLogDebug("TopMostFolderFileListForm::OnFileEventOccured:%S", path.GetPointer());
1432
1433         //Scan the directory
1434         //RequestId reqId;
1435         HashMap* pCacheList = null;
1436         DirectoryEntry* pCurrentEntry = null;
1437         bool cacheKeyStatus = false;
1438         String cachePath;
1439
1440         //result r = ContentManager::ScanDirectory(__currentDirectoryPath,true,null,reqId);
1441         //AppLogDebug("ContentManager::ScanDirectory:%s", GetErrorMessage(r));
1442
1443         if ((events & FILE_EVENT_TYPE_CREATE) || (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM) || (events & FILE_EVENT_TYPE_MOVED_TO ))
1444         {
1445                 _bBackFromAppControl = true;
1446                 if ( (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM))
1447                 {
1448                         AppLogDebug("Items to delete: %d", _indexTracker);
1449                         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
1450                         if (pCacheList != null)
1451                         {
1452                                 pCurrentEntry = static_cast<DirectoryEntry*>(_pFilenames->GetAt(_indexTracker));
1453
1454                                 if (pCurrentEntry != null)
1455                                 {
1456                                         cachePath = pCurrentEntry->GetFullFilePath();
1457                                 }
1458
1459                                 cacheKeyStatus = pCacheList->ContainsKey(cachePath);
1460
1461                                 if (cacheKeyStatus)
1462                                 {
1463                                         CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
1464                                 }
1465                         }
1466                 }
1467                 if (_pFolderEntryPM!=null)
1468                 {
1469                          if ( (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM) )
1470                                  _pFilenames->RemoveAt(_indexTracker);
1471                          else
1472                                  _pFolderEntryPM->RefreshFolderEntries();
1473                 }
1474
1475                 if (_pListView != null && _pListView->IsVisible())
1476                 {
1477                         _pListView->UpdateList();
1478                 }
1479
1480                 if (_pIconListView != null && _pIconListView->IsVisible())
1481                 {
1482                         _pIconListView->UpdateList();
1483                 }
1484
1485                 if (_pFolderEntryPM!=null && ( (events & FILE_EVENT_TYPE_CREATE) || (events & FILE_EVENT_TYPE_MOVED_TO)))
1486                 {
1487                         _pFolderEntryPM->InitThumbnailManager();
1488                 }
1489         }
1490 }
1491
1492 void
1493 SubFolderFileListForm::OnContentScanCompleted (RequestId reqId, const Tizen::Base::String &scanPath, result r)
1494 {
1495         AppLogDebug("Enter");
1496         AppLogDebug("Exit");
1497 }
1498 void
1499 SubFolderFileListForm::OnAppControlCompleted(void)
1500 {
1501         SubBaseFolderEntryForm::OnAppControlCompleted();
1502 }