NABI_SE issues fixes
[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         AppLogDebug("Enter");
1010
1011         Integer* pFileProcessingResult = null;
1012         String cachePath;
1013
1014         TryCatch(pArgs != null, , "Argument list received is invalid!");
1015         pFileProcessingResult = (Integer*) pArgs->GetAt(0);
1016
1017         TryCatch(pFileProcessingResult != null, , "FileProcessing Result  list is invalid!");
1018
1019         switch (pFileProcessingResult->ToInt())
1020         {
1021         case FILE_MANAGING_RESULT_DELETING_SUCCESS:
1022         {
1023                 AppLogDebug("FILE DELETION SUCCESSFULL");
1024                 HideFileProgressingPopup();
1025         }
1026         break;
1027
1028         case FILE_MANAGING_RESULT_DELETING_FAILED:
1029         {
1030                 HideFileProgressingPopup();
1031         }
1032         break;
1033         case FILE_MANAGING_RESULT_THREAD_STOP:
1034         {
1035                 HideFileProgressingPopup();
1036         }
1037         break;
1038         default:
1039         {
1040                 //Do Nothing.
1041         }
1042         break;
1043         }
1044
1045         SetFooterVisibility(DISABLE_FOOTER_ITEM);
1046 CATCH:
1047         if (pArgs != null)
1048         {
1049                 pArgs->RemoveAll(true);
1050                 delete pArgs;
1051         }
1052         ///return this;
1053 }
1054
1055 void
1056 SubFolderFileListForm::OnDataBindingSourceUpdated(const Tizen::Base::String& bindingId, const Tizen::Base::String& controlName, const Tizen::Base::String& propertyName)
1057 {
1058         //Empty Implementation.
1059 }
1060
1061 void
1062 SubFolderFileListForm::OnDataBindingTargetUpdated(const Tizen::Base::String& bindingId, const Tizen::Base::String& controlName, const Tizen::Base::String& propertyName)
1063 {
1064         //Empty Implementation.
1065 }
1066
1067 void
1068 SubFolderFileListForm::OnDataBindingValidationFailed(const Tizen::Base::String& bindingId, const Tizen::Base::String& controlName, const Tizen::Base::String& propertyName, Tizen::Ui::DataBindingDestinationType destType)
1069 {
1070         //Empty Implementation.
1071 }
1072
1073 void
1074 SubFolderFileListForm::OnFileEventExecuted(const Tizen::Base::String& path, const unsigned long eventId)
1075 {
1076         AppLogDebug("ENTER");
1077
1078         int badgeNumber = 0;
1079         result r = E_SUCCESS;
1080
1081         //      Tizen::Shell::NotificationManager* pNotiMgr = null;
1082
1083         NotificationManager* pNotiMgr = null;
1084         AppResource* pAppResource = null;
1085         pAppResource = UiApp::GetInstance()->GetAppResource();
1086         TryCatch(pAppResource != null, , "Failed to fetch AppResource");
1087
1088         pNotiMgr = new (std::nothrow) NotificationManager();
1089         TryCatch(pNotiMgr != null, , "Failed to fetch AppNotificationManager");
1090
1091         pNotiMgr->Construct();
1092         badgeNumber = pNotiMgr->GetBadgeNumber();
1093         badgeNumber++;
1094
1095         if (_pFolderEntryPM != null)
1096         {
1097                 //_pFolderEntryPM->SetFileEventListener(null);
1098                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
1099                 TryCatch(_pFilenames != null, , "File Names List retrieval failed");
1100         }
1101
1102         switch (eventId)
1103         {
1104         case FILE_EVENT_TYPE_CREATE:
1105         {
1106                 if (_pListView != null && _pListView->IsVisible())
1107                 {
1108                         _pListView->RefreshList(_pFilenames->GetCount() - 1, LIST_REFRESH_TYPE_ITEM_ADD);
1109                 }
1110                 if (_pIconListView != null && _pIconListView->IsVisible())
1111                 {
1112                         _pIconListView->RefreshList(_pFilenames->GetCount() - 1, LIST_REFRESH_TYPE_ITEM_ADD);
1113                 }
1114
1115         }
1116         break;
1117
1118         case FILE_EVENT_TYPE_DELETE:
1119         {
1120                 if (_pListView != null && _pListView->IsVisible())
1121                 {
1122                         _pListView->RefreshList(__counter, LIST_REFRESH_TYPE_ITEM_REMOVE);
1123                 }
1124                 if (_pIconListView != null && _pIconListView->IsVisible())
1125                 {
1126                         if (_pThumbnailItemProvider != null)
1127                         {
1128                                 __counter = _pThumbnailItemProvider->GetPressedIndex();
1129                         }
1130                         _pIconListView->RefreshList(__counter, LIST_REFRESH_TYPE_ITEM_REMOVE);
1131                 }
1132
1133         }
1134         break;
1135
1136         case FILE_EVENT_TYPE_DELETE_SELF:
1137         {
1138                 ShowHomeView();
1139         }
1140         break;
1141
1142         default:
1143         {
1144                 //Do Nothing.
1145         }
1146         break;
1147         }
1148
1149         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
1150
1151         if (pNotiMgr != null)
1152         {
1153                 delete pNotiMgr;
1154                 pNotiMgr = null;
1155         }
1156         return;
1157
1158 CATCH:
1159         if (pNotiMgr != null)
1160         {
1161                 delete pNotiMgr;
1162                 pNotiMgr = null;
1163         }
1164         return;
1165 }
1166
1167 void
1168 SubFolderFileListForm::SetHeaderTitleText(Tizen::Base::String& filePath)
1169 {
1170         String token;
1171         String parentFileName;
1172         String delimiter(L"/");
1173         StringTokenizer tokenizer(filePath, delimiter);
1174
1175         AppResource* pAppResource = null;
1176
1177         pAppResource = UiApp::App::GetInstance()->GetAppResource();
1178
1179         if (filePath == BasePresentationModel::GetMediaPath())
1180         {
1181                 if (pAppResource != null)
1182                 {
1183                         pAppResource->GetString(L"IDS_MF_TAB_PHONE", parentFileName);
1184                 }
1185         }
1186         else if (filePath == BasePresentationModel::GetSdCardPath())
1187         {
1188                 if (pAppResource != null)
1189                 {
1190                         pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", parentFileName);
1191                 }
1192         }
1193         else
1194         {
1195                 while (tokenizer.HasMoreTokens())
1196                 {
1197                         int tokenCount = tokenizer.GetTokenCount();
1198
1199                         if (tokenCount == 1)
1200                         {
1201                                 tokenizer.GetNextToken(parentFileName);
1202                         }
1203                         else
1204                         {
1205                                 tokenizer.GetNextToken(token);
1206                         }
1207                 }
1208         }
1209
1210         __pHeader = GetHeader();
1211         if (__pHeader != null)
1212         {
1213                 if (!parentFileName.IsEmpty())
1214                 {
1215                         __pHeader->SetTitleText(parentFileName);
1216                         __pHeader->Invalidate(true);
1217                 }
1218         }
1219 }
1220
1221 void
1222 SubFolderFileListForm::OnDeviceChange(ComponentType deviceType, const Tizen::Base::String& state)
1223 {
1224         bool setMediaPath = false;
1225         MemoryType currentMemoryType = MEMORY_TYPE_PHONE;
1226         String unmounted = sdCardStatusUnmounted;
1227         String removed = usbDeviceStatusRemoved;
1228         String currentPath;
1229
1230         SceneManager* pSceneManager = null;
1231
1232         if (state == unmounted || state == removed)
1233         {
1234                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
1235                 if (state == unmounted)
1236                 {
1237                         if (currentPath.Contains(BasePresentationModel::GetSdCardPath()))
1238                         {
1239                                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetMediaPath());
1240                                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
1241                                 setMediaPath = true;
1242                         }
1243                 }
1244
1245                 if (state == removed)
1246                 {
1247                         if (currentPath.Contains(BasePresentationModel::GetUsbPath()))
1248                         {
1249                                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetMediaPath());
1250                                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
1251                                 setMediaPath = true;
1252                         }
1253                 }
1254
1255                 if (setMediaPath)
1256                 {
1257                         pSceneManager = SceneManager::GetInstance();
1258                         if (pSceneManager != null)
1259                         {
1260                                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_DESTROY), null);
1261                         }
1262                 }
1263         }
1264 }
1265
1266 void
1267 SubFolderFileListForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
1268 {
1269         ComponentType currentDeviceType;
1270         switch (deviceType)
1271         {
1272         case StorageCard:
1273         {
1274                 currentDeviceType = COMPONENT_TYPE_STORAGE_CARD;
1275         }
1276         break;
1277
1278         case UsbClient:
1279         {
1280                 currentDeviceType = COMPONENT_TYPE_USB;
1281         }
1282         break;
1283
1284         default:
1285         {
1286                 //Do Nothing.
1287         }
1288         break;
1289         }
1290         OnDeviceChange(currentDeviceType, state);
1291 }
1292
1293 void
1294 SubFolderFileListForm::OnSceneTransitionCompleted (const Tizen::Ui::Scenes::SceneId &previousSceneId, const Tizen::Ui::Scenes::SceneId &currentSceneId)
1295 {
1296         AppLogDebug("Enter");
1297
1298         AppRegistry* pAppRegistry = null;
1299         String sortbyKeyName(L"SortBy");
1300         int sortStyle = SORT_BY_TYPE_DATE_RECENT;
1301         int fileCount = 0;
1302         int folderCount = 0;
1303
1304         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
1305         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
1306
1307         _pLongPressGestureDetector->AddLongPressGestureEventListener(*this);
1308         if (_pIconListView != null)
1309         {
1310                 _pIconListView->AddGestureDetector(*_pLongPressGestureDetector);
1311         }
1312
1313         if (_pFileEventManager != null)
1314         {
1315                 delete _pFileEventManager;
1316                 _pFileEventManager = null;
1317
1318         }
1319         _pFileEventManager = new (std::nothrow)FileEventManager();
1320         _pFileEventManager->Construct(*this);
1321
1322         _pFileEventManager->AddPath(__currentDirectoryPath, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_MOVED_FROM | FILE_EVENT_TYPE_MOVED_TO | FILE_EVENT_TYPE_DELETE );
1323
1324         _pFolderEntryPM->GetFolderEntryCount(FolderNavigationPresentationModel::GetCurrentPath(),folderCount, fileCount);
1325
1326         if (previousSceneId == IDSCN_CREATE_FOLDER_FORM)
1327         {
1328                 if (_renameOrCreate == SELECT_RENAME)
1329                 {
1330                         pAppRegistry->Get(sortbyKeyName, sortStyle);
1331
1332                         if (sortStyle == SORT_BY_TYPE_NAME_ASCENDING || sortStyle == SORT_BY_TYPE_NAME_DESCENDING
1333                                         || sortStyle == SORT_BY_TYPE_DATE_OLDEST || sortStyle == SORT_BY_TYPE_DATE_RECENT)
1334                         {
1335                                 _pFolderEntryPM->SetFolderEntryPath(FolderNavigationPresentationModel::GetCurrentPath());
1336                                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
1337
1338                                 if (_pListView != null && _pListView->IsVisible())
1339                                 {
1340                                         _pListView->UpdateList();
1341                                         _pListView->ScrollToItem(0);
1342                                 }
1343                                 if (_pIconListView != null && _pIconListView->IsVisible())
1344                                 {
1345                                         _pIconListView->UpdateList();
1346                                         _pIconListView->ScrollToItem(0);
1347                                 }
1348                                 _pFolderEntryPM->InitThumbnailManager();
1349                         }
1350                         else
1351                         {
1352                                 if (_pListView != null && _pListView->IsVisible())
1353                                         _pListView->RefreshList(_renameIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
1354                                 if (_pIconListView != null && _pIconListView->IsVisible())
1355                                         _pIconListView->RefreshList(_renameIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
1356                         }
1357                         return;
1358                 }
1359         }
1360
1361         if (CheckSearchHistory())
1362         {
1363                 __previousSceneName = previousSceneId;
1364         }
1365
1366         SwitchViewType();
1367
1368         if (_pFilenames != null && _pFilenames->GetCount() == 0)
1369         {
1370                 _bIsDirectoryEmpty = true;
1371
1372                 SetFooterVisibility(DISABLE_FOOTER_ITEM);
1373
1374         }
1375         else
1376         {
1377                 _bIsDirectoryEmpty = false;
1378
1379                 SetFooterVisibility(ENABLE_FOOTER_ITEM);
1380
1381                 if (fileCount == 0)
1382                 {
1383                         _pFooter = GetFooter();
1384                         if (_pFooter)
1385                         {
1386                                 _pFooter->SetItemEnabled(1, false);
1387                                 _pFooter->Invalidate(true);
1388                         }
1389                 }
1390         }
1391
1392         if (_pFolderEntryPM != null)
1393         {
1394                 _pFolderEntryPM->InitThumbnailManager();
1395         }
1396 }
1397
1398 void
1399 SubFolderFileListForm::OnSceneTransitionStarted (const Tizen::Ui::Scenes::SceneId &currentSceneId, const Tizen::Ui::Scenes::SceneId &nextSceneId)
1400 {
1401         //Empty Implementation.
1402 }
1403
1404 void
1405 SubFolderFileListForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1406 {
1407         AppLogDebug("ENTER");
1408         switch (orientationStatus)
1409         {
1410         case ORIENTATION_STATUS_LANDSCAPE:
1411         {
1412                 SceneManager* pSceneManager = null;
1413                 pSceneManager = SceneManager::GetInstance();
1414                 if (pSceneManager != null)
1415                 {
1416                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SPLIT_PANEL_FORM, SCENE_TRANSITION_ANIMATION_TYPE_NONE), null);
1417                 }
1418         }
1419         break;
1420         default:
1421         break;
1422         }
1423 }
1424
1425 void
1426 SubFolderFileListForm::OnFileEventOccured(const unsigned long events,const Tizen::Base::String &  path, const unsigned int      eventId)
1427 {
1428         AppLogDebug("TopMostFolderFileListForm::OnFileEventOccured:%S", path.GetPointer());
1429
1430         //Scan the directory
1431         //RequestId reqId;
1432         HashMap* pCacheList = null;
1433         DirectoryEntry* pCurrentEntry = null;
1434         bool cacheKeyStatus = false;
1435         String cachePath;
1436
1437         //result r = ContentManager::ScanDirectory(__currentDirectoryPath,true,null,reqId);
1438         //AppLogDebug("ContentManager::ScanDirectory:%s", GetErrorMessage(r));
1439
1440         if ((events & FILE_EVENT_TYPE_CREATE) || (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM) || (events & FILE_EVENT_TYPE_MOVED_TO ))
1441         {
1442                 _bBackFromAppControl = true;
1443                 if ( (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM))
1444                 {
1445                         AppLogDebug("Items to delete: %d", _indexTracker);
1446                         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
1447                         if (pCacheList != null)
1448                         {
1449                                 pCurrentEntry = static_cast<DirectoryEntry*>(_pFilenames->GetAt(_indexTracker));
1450
1451                                 if (pCurrentEntry != null)
1452                                 {
1453                                         cachePath = pCurrentEntry->GetFullFilePath();
1454                                 }
1455
1456                                 cacheKeyStatus = pCacheList->ContainsKey(cachePath);
1457
1458                                 if (cacheKeyStatus)
1459                                 {
1460                                         CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
1461                                 }
1462                         }
1463                 }
1464                 if (_pFolderEntryPM!=null)
1465                 {
1466                         _pFolderEntryPM->RefreshFolderEntries();
1467                 }
1468
1469                 if (_pListView != null && _pListView->IsVisible())
1470                 {
1471                         _pListView->UpdateList();
1472                 }
1473
1474                 if (_pIconListView != null && _pIconListView->IsVisible())
1475                 {
1476                         _pIconListView->UpdateList();
1477                 }
1478
1479                 if (_pFolderEntryPM!=null && ( (events & FILE_EVENT_TYPE_CREATE) || (events & FILE_EVENT_TYPE_MOVED_TO)))
1480                 {
1481                         _pFolderEntryPM->InitThumbnailManager();
1482                 }
1483         }
1484 }
1485
1486 void
1487 SubFolderFileListForm::OnContentScanCompleted (RequestId reqId, const Tizen::Base::String &scanPath, result r)
1488 {
1489         AppLogDebug("Enter");
1490         AppLogDebug("Exit");
1491 }
1492 void
1493 SubFolderFileListForm::OnAppControlCompleted(void)
1494 {
1495         SubBaseFolderEntryForm::OnAppControlCompleted();
1496 }