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