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