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