NABI_SE isues resolved
[apps/osp/MyFiles.git] / src / MfTopMostFolderFileListForm.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: MfTopMostFolderFileListForm.cpp
19  * @brief: This file contains the implementation of TopMostFolderFileListForm class, which acts as a
20  * media explorer displaying a list of all the files in the root directory
21  * and defines a set of operations that can be done with the files like edit, view etc.
22  */
23
24 #include "MfMyFilesApp.h"
25 #include "MfTopMostFolderFileListForm.h"
26
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Base::Runtime;
31 using namespace Tizen::Base::Utility;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Io;
34 using namespace Tizen::Locales;
35 using namespace Tizen::Media;
36 using namespace Tizen::System;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
40
41 TopMostFolderFileListForm::TopMostFolderFileListForm(void)
42         : __pHomeButton(null)
43         , __pUpButton(null)
44         , __pHeader(null)
45 {
46         __counter = 0;
47 }
48
49 TopMostFolderFileListForm::~TopMostFolderFileListForm(void)
50 {
51         if (__pHomeButton != null)
52         {
53                 delete __pHomeButton;
54         }
55
56         if (__pUpButton != null)
57         {
58                 delete __pUpButton;
59         }
60 }
61
62 bool
63 TopMostFolderFileListForm::Initialize(void)
64 {
65         Form::Construct(L"IDL_ROOT_DIRECTORY");
66         return true;
67 }
68
69 TopMostFolderFileListForm&
70 TopMostFolderFileListForm::operator =(const TopMostFolderFileListForm& topMostFolderFileListForm)
71 {
72         return *this;
73 }
74
75 TopMostFolderFileListForm::TopMostFolderFileListForm(const TopMostFolderFileListForm& topMostFolderFileListForm)
76 {
77         //Do Nothing
78 }
79
80
81 result
82 TopMostFolderFileListForm::OnInitializing(void)
83 {
84         AppLogDebug("ENTER");
85         result r = E_SUCCESS;
86         int sourceForm = THUMBNAIL_PROVIDER_SOURCEID_TOP_FOLDER_FILE_LIST_FORM;
87         _renameIndex = 0;
88         _renameOrCreate = SELECT_CREATE_FOLDER;
89         CreateItemSource createitemsource = CREATE_ITEM_SOURCE_TOP_MOST_FILE_LIST;
90
91         //AddOrientationEventListener(*this);
92         //SetOrientation(ORIENTATION_AUTOMATIC_FOUR_DIRECTION);
93
94         AppResource* pAppResource = null;
95         Bitmap* pBitmapHomeButton = null;
96         Bitmap* pBitmapUpButton = null;
97         Bitmap* pBitmapHomeButtonPress = null;
98         Bitmap* pBitmapUpButtonPress = null;
99
100         Color backgroundColor(0xAE, 0x36, 0x36, 0xFF);
101         String displayPath;
102         String path;
103         _pLabelDisplayPath = static_cast< Label* >(GetControl("IDC_LABEL_DISPLAY_PATH"));
104         TryCatch(_pLabelDisplayPath != null, , "Label is Null");
105         pAppResource = UiApp::GetInstance()->GetAppResource();
106         TryCatch(pAppResource != null, , "MfMyFilesApp::Resource manager not found!");
107
108         pBitmapHomeButton = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
109         pBitmapUpButton = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
110         pBitmapHomeButtonPress = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
111         pBitmapUpButtonPress = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
112
113         __pHeader = GetHeader();
114
115         if (__pHeader != null)
116         {
117                 __pHomeButton = new (std::nothrow) ButtonItem();
118                 __pHomeButton->Construct(BUTTON_ITEM_STYLE_TEXT, IDA_BTN_HOME);
119                 __pHomeButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL, pBitmapHomeButton);
120                 __pHomeButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED, pBitmapHomeButtonPress);
121
122                 __pUpButton = new (std::nothrow) ButtonItem();
123                 __pUpButton->Construct(BUTTON_ITEM_STYLE_TEXT, IDA_BTN_UP);
124                 __pUpButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL, pBitmapUpButton);
125                 __pUpButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED, pBitmapUpButtonPress);
126
127                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pHomeButton);
128                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pUpButton);
129                 __pHeader->AddActionEventListener(*this);
130         }
131
132         displayPath = defaultPhoneBody;
133         displayPath.Append("/");
134         pAppResource->GetString(L"IDS_MF_OPT_SHOW_FILE_EXTENSION", _showExtension);
135         pAppResource->GetString(L"IDS_MF_OPT_HIDE_FILE_EXTENSION_ABB", _hideExtension);
136         _extensionKeyName.Append(L"ExtensionVisibility");
137         // Setup back event listener
138         SetFormBackEventListener(this);
139
140         //Call the InitializeAppRegistry() method to define the keys used throughout the application.
141         InitializeAppRegistry();
142
143         //Create a new instance of the pointer for FileListPresentation Model.
144         if (_pFolderEntryPM == null)
145         {
146                 _pFolderEntryPM = new (std::nothrow) FolderEntryPresentationModel();
147                 AppAssert(_pFolderEntryPM != null);
148                 r = _pFolderEntryPM->Construct();
149                 AppAssert(r==E_SUCCESS);
150                 _pFolderEntryPM->SetSourceForm(createitemsource);
151         }
152
153 #if 0
154         _pFolderEntryPM->SetFolderEntryPath(__StoragePath);
155         __ptempFilenames = _pFolderEntryPM->GetFolderEntryList();
156         if (__ptempFilenames != null && __ptempFilenames->GetCount() > 1)
157         {
158
159                 pTabList = new (std::nothrow) ArrayList();
160                 if (pTabList != null)
161                 {
162                         pTabList->Add(new String("Memory Card"));
163                         r = CreateHeaderControls(pTabList);
164                 }
165         }
166         else
167         {
168                 r = CreateHeaderControls();
169         }
170 #endif
171
172         _pFileManager = FolderEntryEditorPresentationModel::GetInstance();
173         TryCatch(_pFileManager != null, , "MfMyFilesApp::File Manager not found!");
174
175         path = BasePresentationModel::GetMediaPath();
176         if (!path.IsEmpty())
177         {
178                 __rootMediaPath = path;
179                 FolderNavigationPresentationModel::SetCurrentFilePath(path);
180         }
181
182 //      _pFolderEntryPM->SetFolderEntryPath(__rootMediaPath);
183 //      _pFilenames = _pFolderEntryPM->GetFolderEntryList();
184 //      TryCatch(_pFilenames != null, , "MfMyFilesApp::Failed to allocate Memory to Filenames ArrayList");
185 //
186 //      AppLogDebug("Filenames Count %d", _pFilenames->GetCount());
187 //
188         _pBaseItemProvider = new (std::nothrow) BaseItemProvider();
189         TryCatch(_pBaseItemProvider != null, , "Failed to allocate base itemprovider");
190         _pBaseItemProvider->Construct();
191         _pBaseItemProvider->SetSourceForm(createitemsource);
192         _pBaseItemProvider->SetFolderEntryProvider(this);
193         _pBaseItemProvider->SetFooterItemStateChangeListener(this);
194
195         _pListView = static_cast< ListView* >(GetControl("IDC_LISTVIEW_ROOT_DIRECTORY"));
196         if (_pListView != null)
197         {
198                 _pListView->AddListViewItemEventListener(*this);
199                 //__pListView->SetItemProvider(*this);
200                 _pListView->SetItemProvider(*_pBaseItemProvider);
201                 _pListView->SetShowState(true);
202                 _pListView->SetBounds(0, H_DISPLAY_PATH_LABEL, GetClientAreaBounds().width, GetClientAreaBounds().height - H_DISPLAY_PATH_LABEL);
203         }
204
205         //Initialize the itemprovider class for the listview inside the popup
206         if (_pCustomListViewForPopup == null)
207         {
208                 _pCustomListViewForPopup = new (std::nothrow) CustomListViewForPopup();
209         }
210         TryCatch(_pCustomListViewForPopup != null, , "MfMyFilesApp::ListView For Popup not created!");
211
212         _pCustomListViewForPopup->SetEventListener(this);
213
214         _pFooter = GetFooter();
215         _pThumbnailItemProvider = new (std::nothrow) ThumbnailItemProviderAndListener(path, sourceForm);
216         //__pThumbnailItemProviderAndListener->Construct(__pContentManager);
217         TryCatch(_pThumbnailItemProvider != null, , "Failed to allocate Memory to __pThumbnailItemProviderAndListener");
218         _pThumbnailItemProvider->SetFolderEntryProvider(this);
219         _pThumbnailItemProvider->SetFooterItemStateChangeListener(this);
220
221         _pIconListView = static_cast< IconListView* >(GetControl("IDC_ICONLISTVIEW_ROOT_THUMBNAILS"));
222         if (_pIconListView != null)
223         {
224                 _pIconListView->AddIconListViewItemEventListener(*_pThumbnailItemProvider);
225                 _pIconListView->SetItemProvider(*_pThumbnailItemProvider);
226                 _pIconListView->SetBounds(0, H_DISPLAY_PATH_LABEL, GetClientAreaBounds().width, GetClientAreaBounds().height - H_DISPLAY_PATH_LABEL);
227                 _pIconListView->SetShowState(false);
228 //              _pIconListView->AddGestureDetector(*gestureDetector);
229         }
230
231         delete pBitmapHomeButton;
232         delete pBitmapUpButton;
233         delete pBitmapHomeButtonPress;
234         delete pBitmapUpButtonPress;
235         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
236         return r;
237
238 CATCH:
239         if (_pFolderEntryPM != null)
240         {
241                 delete _pFolderEntryPM;
242                 _pFolderEntryPM = null;
243         }
244
245         if (_pThumbnailItemProvider != null)
246         {
247                 delete _pThumbnailItemProvider;
248                 _pThumbnailItemProvider = null;
249         }
250
251         if (__pHomeButton != null)
252         {
253                 delete __pHomeButton;
254                 __pHomeButton = null;
255         }
256
257         if (__pUpButton != null)
258         {
259                 delete __pUpButton;
260                 __pUpButton = null;
261         }
262         if (pBitmapHomeButton != null)
263         {
264                 delete pBitmapHomeButton;
265                 pBitmapHomeButton = null;
266         }
267
268         if (pBitmapUpButton != null)
269         {
270                 delete pBitmapUpButton;
271                 pBitmapUpButton = null;
272         }
273         if (pBitmapHomeButtonPress != null)
274         {
275                 delete pBitmapHomeButtonPress;
276                 pBitmapHomeButtonPress = null;
277         }
278         if (pBitmapUpButtonPress != null)
279         {
280                 delete pBitmapUpButtonPress;
281                 pBitmapUpButtonPress = null;
282         }
283         return r;
284 }
285
286 result
287 TopMostFolderFileListForm::OnTerminating(void)
288 {
289         AppLogDebug("ENTER");
290         result r = E_SUCCESS;
291
292         _pFooter = GetFooter();
293         if (_pFooter != null)
294         {
295                 _pFooter->RemoveAllButtons();
296                 _pFooter->RemoveAllItems();
297         }
298         __pHeader = GetHeader();
299         if (__pHeader != null)
300         {
301                 __pHeader->RemoveAllButtons();
302                 __pHeader->RemoveAllItems();
303         }
304         return r;
305 }
306
307 void
308 TopMostFolderFileListForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
309 {
310         SceneManager* pSceneManager = SceneManager::GetInstance();
311 #if 0
312         SceneManager* pSceneManager = SceneManager::GetInstance();
313         String searchPath;
314 #endif
315
316         if (CheckSearchHistory() == true)
317         {
318 #if 0
319                 /*searchPath = FolderNavigationPresentationModel::GetSearchPreviousPath();
320
321                 FolderNavigationPresentationModel::SetCurrentFilePath(searchPath);
322                 if (SceneManager::GetInstance()->IsSceneAlive(__previousSceneName))
323                 {
324                         pSceneManager->GoBackward(BackwardSceneTransition(__previousSceneName, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_KEEP), null);
325                 }
326                 else
327                 {
328                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
329                 }*/
330 #endif
331                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
332         }
333         else
334         {
335                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
336         }
337 }
338
339 void
340 TopMostFolderFileListForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
341                 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
342 {
343         AppLogDebug("ENTER");
344         result r = E_SUCCESS;
345
346         String viewStyleKeyName(L"ListDisplayType");
347         AppResource* pAppResource = null;
348         AppRegistry* pAppRegistry = null;
349
350         SceneManager::GetInstance()->AddSceneManagerEventListener(*this);
351         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
352
353         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
354
355         _pFileManager->SetFileManagingListener(this);
356
357         if (previousSceneId == IDSCN_CREATE_FOLDER_FORM)
358         {
359                 if (_renameOrCreate == SELECT_RENAME)
360                 {
361                         return;
362                 }
363         }
364
365         int listViewDisplayType = VIEW_TYPE_AS_NORMAL_LIST;
366
367         pAppResource = UiApp::GetInstance()->GetAppResource();
368         TryCatch(pAppResource != null, , "MfMyFilesApp::Resource manager not found!");
369
370         //Call the CreateFooterControls() to personalize the footerItems.
371         r = CreateFooterControls();
372         TryCatch(r == E_SUCCESS, , "Failed to create footer controls");
373
374         //SceneManager::GetInstance()->AddSceneManagerEventListener(*this);
375
376         //Get the current path from the Folder Navigation Model.
377         __rootMediaPath.Clear();
378         __rootMediaPath.Append(FolderNavigationPresentationModel::GetCurrentPath());
379
380         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
381
382         r = pAppRegistry->Get(viewStyleKeyName, listViewDisplayType);
383         TryCatch(r == E_SUCCESS, , "Failed To Get Value From AppRegistry");
384         _flagViewAsStatus = listViewDisplayType;
385
386         if (_pMoreContextMenu != null)
387         {
388                 _pMoreContextMenu->SetShowState(false);
389         }
390
391         //Fill the ArrayList with the folder entries present at RootMediaPath.
392         _pFolderEntryPM->SetFolderEntryPath(__rootMediaPath);
393
394         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
395         TryCatch(_pFilenames != null, , "Failed to allocate Memory to Filenames ArrayList");
396
397         SetFooterVisibility();
398
399         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
400
401         if (pArgs != null)
402         {
403                 pArgs->RemoveAll(false);
404                 delete pArgs;
405         }
406         return;
407
408         CATCH:
409         if (pArgs != null)
410         {
411                 pArgs->RemoveAll(false);
412                 delete pArgs;
413         }
414
415 }
416
417 void
418 TopMostFolderFileListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
419                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
420 {
421         DeviceManager::RemoveAllDeviceEventListeners();
422         ((MyFilesApp*)Application::GetInstance())->SetCurrentView(null);
423         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
424         _pFolderEntryPM->StopThumbnailManager(true);
425         _pFolderEntryPM->SetCurrentReqId(0);
426         /*
427         if(_pFileEventManager != null)
428                 _pFileEventManager->RemovePath(__rootMediaPath);*/
429 }
430
431 void
432 TopMostFolderFileListForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
433 {
434         String rootMediaPath;
435         String fileName;
436         String filePath;
437         DirectoryEntry* pDirStr = null;
438
439         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
440
441         if (_pFilenames != null)
442         {
443                 pDirStr = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
444                 if (pDirStr != null)
445                 {
446                         rootMediaPath = pDirStr->GetFullFilePath();
447
448                         if (pDirStr->IsDirectory())
449                         {
450                                 //If the current filepath is a directory then load the SubDirectoryForm
451                                 filePath.Append(__rootMediaPath);
452                                 filePath.Append(pDirStr->GetFileName());
453                                 filePath.Append(L"/");
454
455
456                                 fileName.Append(pDirStr->GetFileName());
457
458                                 _currentFileName.Clear();
459                                 _currentFileName = pDirStr->GetFileName();
460
461                                 FolderNavigationPresentationModel::SetCurrentFilePath(filePath);
462                                 //_pFileListPM->SetFileEventListener(null);
463                                 LoadSubDirectoryForm(filePath, fileName);
464                         }
465                         else
466                         {
467                                 _pathOfSelectedFile = rootMediaPath;
468                                 //Else launch the corresponding AppControl.
469                                 if (_pathOfSelectedFile.EndsWith(L".tpk"))
470                                 {
471                                         String* pFileUriScheme = new (std::nothrow) String(L"file://");
472                                         pFileUriScheme->Append(_pathOfSelectedFile);
473                                         AppControl* pAc = null;
474                                         pAc = AppManager::FindAppControlN(L"D7eOJquGtL.Installer", L"http://tizen.org/appcontrol/operation/install");
475                                         if(pAc != null)
476                                         {
477                                                 pAc->Start(pFileUriScheme, null, null, null);
478                                         }
479                                         delete pFileUriScheme;
480                                 }
481                                 else
482                                 {
483                                         CustomAppControl* pCustomAppControl = CustomAppControl::GetInstance();
484                                         if (pCustomAppControl != null)
485                                         {
486                                                 __counter = index;
487
488                                                 pCustomAppControl->SetAppControlListener(null);
489                                                 AppControl* pAppControlInUse = pCustomAppControl->LaunchAppControl(_pathOfSelectedFile);
490                                                 if (pAppControlInUse != null)
491                                                         CustomAppControl::SetAppControlInUse(pAppControlInUse);
492                                         }
493                                 }
494                         }
495                 }
496         }
497         return;
498
499 }
500
501 void
502 TopMostFolderFileListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
503 {
504         result r = E_SUCCESS;
505         String mediaPath;
506         String storagePath;
507         String usbPath;
508         String displayMediaPath;
509         String displayStoragePath;
510         String displayUsbPath;
511         String extensionStatus;
512         String tabPhone;
513         String tabSDCard;
514         String tabUsb;
515
516         AppResource* pAppResource = AppResource::GetInstance();
517         Header* pHeader = null;
518         SceneManager* pSceneManager = null;
519         pSceneManager = SceneManager::GetInstance();
520
521         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
522
523         if (pAppResource != null)
524         {
525                 displayMediaPath = defaultPhoneBody;
526                 displayMediaPath.Append("/");
527
528                 displayStoragePath = defaultSdCardBody;
529                 displayStoragePath.Append("/");
530
531                 displayUsbPath = defaultExternalStorageBody;
532                 displayUsbPath.Append("/");
533
534                 pAppResource->GetString(L"IDS_MF_TAB_PHONE", tabPhone);
535                 pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", tabSDCard);
536                 pAppResource->GetString(L"IDS_COM_BODY_USB", tabUsb);
537         }
538
539
540         mediaPath = BasePresentationModel::GetMediaPath();
541         storagePath = BasePresentationModel::GetSdCardPath();
542         usbPath = BasePresentationModel::GetUsbPath();
543         AppLogDebug("SD Card Path is %ls", storagePath.GetPointer());
544
545         pHeader = GetHeader();
546
547         switch (actionId)
548         {
549         case IDA_CONTEXT_MENU_HIDE_EXTENSION:
550         {
551                 HideFileExtension();
552         }
553         break;
554
555         case IDA_CONTEXT_MENU_SHOW_EXTENSION:
556         {
557                 ShowFileExtension();
558         }
559         break;
560
561         case IDA_BTN_HOME:
562         {
563                 //Navigate to the TopFolderFileListForm.
564                 String homeRootPath;
565                 homeRootPath.Append(__rootMediaPath);
566
567                 while ((homeRootPath != BasePresentationModel::GetMediaPath()) && (homeRootPath != BasePresentationModel::GetSdCardPath()))
568                 {
569                         FolderNavigationPresentationModel::SetCurrentFilePath(homeRootPath);
570                         homeRootPath.Clear();
571                         homeRootPath = FolderNavigationPresentationModel::GetParentPath();
572                 }
573
574                 FolderNavigationPresentationModel::SetCurrentFilePath(homeRootPath);
575                 //ShowHomeView();
576                 if (CheckSearchHistory())
577                 {
578                         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
579                         //TryCatch(r == E_SUCCESS, , "scene transition failed");
580                 }
581                 else
582                 {
583                         r = pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_DESTROY), null);
584                         //TryCatch(r == E_SUCCESS, , "scene transition failed");
585                 }
586         }
587         break;
588
589         case IDA_BTN_UP:
590         {
591
592         }
593         break;
594 /*
595         case IDA_BTN_CANCEL:
596         {
597                 UiApp* pApp = UiApp::GetInstance();
598                 if (pApp != null)
599                 {
600                         pApp->Terminate();
601                 }
602         }
603         break;*/
604
605         case IDA_TABBAR_ITEM_PHONE:
606         {
607                 String currentPath;
608                 bool enableUpdate = false;
609                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
610
611                 if (currentPath.CompareTo(mediaPath) != 0)
612                 {
613                         enableUpdate = true;
614                 }
615
616                 if (enableUpdate)
617                 {
618                         if (pHeader != null)
619                         {
620                                 pHeader->SetItemSelected(0);
621                         }
622
623                         //_tabSelected = tabPhone;
624                         //__storageType = MEMORY_TYPE_PHONE;
625
626
627                         _pFolderEntryPM->SetFolderEntryPath(mediaPath);
628                         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
629
630                         __rootMediaPath.Clear();
631                         __rootMediaPath.Append(mediaPath);
632
633                         if (_pListView != null && _pListView->IsVisible())
634                         {
635                                 _pListView->UpdateList();
636                                 _pListView->ScrollToItem(0);
637
638                         }
639
640                         if (_pIconListView != null && _pIconListView->IsVisible())
641                         {
642                                 _pIconListView->UpdateList();
643                                 _pIconListView->ScrollToItem(0);
644                         }
645
646                         FolderNavigationPresentationModel::SetCurrentFilePath(mediaPath);
647                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_PHONE);
648
649
650                         SetFooterVisibility();
651
652                         //Invalidate(true);
653                 }
654                 if (_pFolderEntryPM != null)
655                 {
656                         _pFolderEntryPM->InitThumbnailManager();
657                 }
658         }
659         break;
660
661         case IDA_TABBAR_ITEM_SD_CARD:
662         {
663                 String currentPath;
664                 bool enableUpdate = false;
665                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
666
667                 if (currentPath.CompareTo(storagePath) != 0)
668                 {
669                         enableUpdate = true;
670                 }
671
672                 if (enableUpdate)
673                 {
674                         if (pHeader != null)
675                         {
676                                 pHeader->SetItemSelected(1);
677                         }
678
679                         //_tabSelected = tabSDCard;
680
681                         __rootMediaPath.Clear();
682                         __rootMediaPath.Append(storagePath);
683
684                         _pFolderEntryPM->SetFolderEntryPath(storagePath);
685                         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
686
687
688                         SetFooterVisibility();
689
690                         if (_pListView != null && _pListView->IsVisible())
691                         {
692                                 _pListView->ScrollToItem(0);
693                                 _pListView->UpdateList();
694                         }
695
696                         if (_pIconListView != null && _pIconListView->IsVisible())
697                         {
698                                 _pIconListView->ScrollToItem(0);
699                                 _pIconListView->UpdateList();
700                         }
701
702
703                         FolderNavigationPresentationModel::SetCurrentFilePath(storagePath);
704                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_SD_CARD);
705                         //Invalidate(true);
706                 }
707                 if (_pFolderEntryPM != null)
708                 {
709                         _pFolderEntryPM->InitThumbnailManager();
710                 }
711         }
712         break;
713
714         case IDA_TABBAR_ITEM_USB:
715         {
716                 String currentPath;
717                 bool enableUpdate = false;
718                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
719
720                 if (currentPath.CompareTo(usbPath) != 0)
721                 {
722                         enableUpdate = true;
723                 }
724
725                 if (enableUpdate)
726                 {
727                         //_tabSelected = tabUsb;
728
729                         if (pHeader != null)
730                         {
731                                 pHeader->SetItemSelected(2);
732                         }
733
734                         __rootMediaPath.Clear();
735                         __rootMediaPath.Append(usbPath);
736
737                         _pFolderEntryPM->SetFolderEntryPath(usbPath);
738                         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
739
740                         if (_pListView != null && _pListView->IsVisible())
741                         {
742                                 _pListView->ScrollToItem(0);
743                                 _pListView->UpdateList();
744                         }
745
746                         if (_pIconListView != null && _pIconListView->IsVisible())
747                         {
748                                 _pIconListView->ScrollToItem(0);
749                                 _pIconListView->UpdateList();
750                         }
751
752                         SetFooterVisibility();
753
754                         FolderNavigationPresentationModel::SetCurrentFilePath(usbPath);
755                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_EXTERNAL);
756                         //Invalidate(true);
757                 }
758         }
759         break;
760
761         default:
762         {
763                 SubBaseOnActionPerformed(source, actionId);
764         }
765         break;
766         }
767 }
768
769 void
770 TopMostFolderFileListForm::LoadSubDirectoryForm(Tizen::Base::String& fullPath, Tizen::Base::String& fileName)
771 {
772         result r = E_SUCCESS;
773         ArrayList* pArg = null;
774         SceneManager* pSceneManager = null;
775
776         pArg = new (std::nothrow) ArrayList();
777         pArg->Construct();
778
779         pArg->Add(&fileName);
780         TryCatch(r == E_SUCCESS, , "Failed to Add Arguments to ArrayList");
781
782         pSceneManager = SceneManager::GetInstance();
783         TryCatch(pSceneManager != null, , "Failed to get SceneManager Instance");
784
785         //pSceneManager->GoForward(SCENE_SUB_DIRECTORY_FORM,pArg, SCENE_TRANSITION_ANIMATION_TYPE_LEFT);
786         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArg);
787         return;
788
789         CATCH:
790         if (pArg != null)
791         {
792                 pArg->RemoveAll();
793                 delete pArg;
794                 pArg = null;
795         }
796         return;
797
798 }
799
800
801 void
802 TopMostFolderFileListForm::InitializeAppRegistry(void)
803 {
804         AppLogDebug("ENTER");
805         // 3 keys: ViewStyle, SortBy, Show/Hide File Extension
806         result r = E_SUCCESS;
807
808         AppRegistry* pAppRegistry = null;
809         String viewStyleKeyName(L"ListDisplayType");
810         ViewType viewStyle = VIEW_TYPE_AS_NORMAL_LIST;
811
812         String sortbyKeyName(L"SortBy");
813         SortByType sortStyle = SORT_BY_TYPE_DATE_RECENT;
814
815         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
816
817         r = pAppRegistry->Add(viewStyleKeyName, viewStyle);
818         if (r == E_SUCCESS)
819         {
820                 r = pAppRegistry->Save();
821         }
822
823         r = pAppRegistry->Add(_extensionKeyName, _hideExtension);
824         if (r == E_SUCCESS)
825         {
826                 r = pAppRegistry->Save();
827         }
828
829         r = pAppRegistry->Add(sortbyKeyName, sortStyle);
830         if (r == E_SUCCESS)
831         {
832                 r = pAppRegistry->Save();
833         }
834
835         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
836 }
837
838 void
839 TopMostFolderFileListForm::OnNotificationReceived(Tizen::Base::Collection::ArrayList* pArgs)
840 {
841         AppLogDebug("ENTER");
842         Integer* pFileProcessingResult = null;
843
844         TryCatch(pArgs != null, , "Argument list received is invalid!");
845         pFileProcessingResult = (Integer*) pArgs->GetAt(0);
846
847         TryCatch(pFileProcessingResult != null, , "FileProcessing Result  list is invalid!");
848
849         switch (pFileProcessingResult->ToInt())
850         {
851         case FILE_MANAGING_RESULT_DELETING_SUCCESS:
852         {
853                 AppLogDebug("FILE_PROCESSING_RESULT_DELETING_SUCCESS");
854                 if (_pFilenames != null)
855                 {
856                         _pFilenames->RemoveAt(_indexTracker, true);
857                         //r = __pListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
858                         _pListView->UpdateList();
859
860                         if (_pIconListView != null && _pIconListView->IsVisible())
861                         {
862                                 _pIconListView->UpdateList();
863                         }
864                 }
865                 HideFileProgressingPopup();
866         }
867         break;
868
869         case FILE_MANAGING_RESULT_DELETING_FAILED:
870         {
871                 HideFileProgressingPopup();
872         }
873         break;
874         case FILE_MANAGING_RESULT_THREAD_STOP:
875         {
876                 HideFileProgressingPopup();
877         }
878         break;
879         default:
880                 //Do Nothing.
881                 break;
882         }
883
884
885         Invalidate(true);
886
887         CATCH:
888         if (pArgs != null)
889         {
890                 pArgs->RemoveAll(true);
891                 delete pArgs;
892         }
893 }
894
895 void
896 TopMostFolderFileListForm::OnFileEventExecuted(const Tizen::Base::String& path, const unsigned long eventId)
897 {
898         AppLogDebug("ENTER");
899         int badgeNumber = 0;
900
901         //      Tizen::Shell::NotificationManager* pNotiMgr = null;
902         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
903
904         NotificationManager* pNotiMgr = null;
905         AppResource* pAppResource = null;
906         pAppResource = UiApp::GetInstance()->GetAppResource();
907         TryCatch(pAppResource != null, , "Failed to fetch AppResource");
908
909         pNotiMgr = new (std::nothrow) NotificationManager();
910         TryCatch(pNotiMgr != null, , "Failed to fetch AppNotificationManager");
911
912         pNotiMgr->Construct();
913         badgeNumber = pNotiMgr->GetBadgeNumber();
914         badgeNumber++;
915
916
917         //_pFolderEntryPM->SetFileEventListener(null);
918
919         switch (eventId)
920         {
921         case FILE_EVENT_TYPE_CREATE:
922         {
923                 if (_pListView != null && _pListView->IsVisible())
924                 {
925                         _pListView->RefreshList(_pFilenames->GetCount() - 1, LIST_REFRESH_TYPE_ITEM_ADD);
926                 }
927                 if (_pIconListView != null && _pIconListView->IsVisible())
928                 {
929                         _pIconListView->RefreshList(_pFilenames->GetCount() - 1, LIST_REFRESH_TYPE_ITEM_ADD);
930                 }
931         }
932         break;
933
934         case FILE_EVENT_TYPE_DELETE:
935         {
936                 if (_pListView != null && _pListView->IsVisible())
937                 {
938                         _pListView->RefreshList(__counter, LIST_REFRESH_TYPE_ITEM_REMOVE);
939                 }
940                 if (_pIconListView != null && _pIconListView->IsVisible())
941                 {
942                         if (_pThumbnailItemProvider != null)
943                         {
944                                 __counter = _pThumbnailItemProvider->GetPressedIndex();
945                         }
946                         _pIconListView->RefreshList(__counter, LIST_REFRESH_TYPE_ITEM_REMOVE);
947                 }
948         }
949         break;
950
951         default:
952         {
953                 //Empty Implementation.
954         }
955         break;
956         }
957
958         if (pNotiMgr != null)
959         {
960                 delete pNotiMgr;
961                 pNotiMgr = null;
962         }
963         return;
964
965         CATCH:
966         //      if (pNotiMgr != null)
967         //      {
968         //              delete pNotiMgr;
969         //              pNotiMgr = null;
970         //      }
971         return;
972 }
973
974 void
975 TopMostFolderFileListForm::OnSceneTransitionCompleted(const Tizen::Ui::Scenes::SceneId &previousSceneId,
976                 const Tizen::Ui::Scenes::SceneId &currentSceneId)
977 {
978         AppLogDebug("Enter");
979         AppLogDebug("_rename index %d",_renameIndex);
980         AppRegistry* pAppRegistry = null;
981         String sortbyKeyName(L"SortBy");
982         int sortStyle = SORT_BY_TYPE_DATE_RECENT;
983
984         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
985
986         if (_pFileEventManager != null)
987         {
988                 delete _pFileEventManager;
989                 _pFileEventManager = null;
990
991         }
992
993         /*_pFileEventManager = new FileEventManager();
994         _pFileEventManager->Construct(*this);
995
996         _pFileEventManager->AddPath(__rootMediaPath, FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_DELETE );*/
997
998
999         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
1000         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
1001
1002         if (previousSceneId == IDSCN_CREATE_FOLDER_FORM)
1003         {
1004                 if (_renameOrCreate == SELECT_RENAME)
1005                 {
1006                         pAppRegistry->Get(sortbyKeyName, sortStyle);
1007
1008                         if (sortStyle == SORT_BY_TYPE_NAME_ASCENDING || sortStyle == SORT_BY_TYPE_NAME_DESCENDING
1009                                         || sortStyle == SORT_BY_TYPE_DATE_OLDEST || sortStyle == SORT_BY_TYPE_DATE_RECENT)
1010                         {
1011                                 _pFolderEntryPM->SetFolderEntryPath(FolderNavigationPresentationModel::GetCurrentPath());
1012                                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
1013
1014                                 if (_pListView != null && _pListView->IsVisible())
1015                                 {
1016                                         _pListView->UpdateList();
1017                                         _pListView->ScrollToItem(0);
1018                                 }
1019                                 _pFolderEntryPM->InitThumbnailManager();
1020                         }
1021                         else
1022                         {
1023                                 _pListView->RefreshList(_renameIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
1024                         }
1025                         //_pFolderEntryPM->InitThumbnailManager();
1026                         return;
1027                 }
1028         }
1029         if (CheckSearchHistory())
1030         {
1031                 __previousSceneName = previousSceneId;
1032         }
1033
1034         SwitchViewType();
1035         _pFolderEntryPM->InitThumbnailManager();
1036 }
1037
1038 void
1039 TopMostFolderFileListForm::OnSceneTransitionStarted(const Tizen::Ui::Scenes::SceneId &currentSceneId,
1040                 const Tizen::Ui::Scenes::SceneId &nextSceneId)
1041 {
1042         //Empty Implementation.
1043 }
1044
1045 void
1046 TopMostFolderFileListForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1047 {
1048         switch (orientationStatus)
1049         {
1050         case ORIENTATION_STATUS_LANDSCAPE:
1051         {
1052                 SceneManager* pSceneManager = null;
1053                 pSceneManager = SceneManager::GetInstance();
1054                 if (pSceneManager != null)
1055                 {
1056                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SPLIT_PANEL_FORM, SCENE_TRANSITION_ANIMATION_TYPE_NONE), null);
1057                 }
1058         }
1059         break;
1060         default:
1061         break;
1062         }
1063 }
1064
1065 void
1066 TopMostFolderFileListForm::OnFileEventOccured(const unsigned long events,const Tizen::Base::String &  path, const unsigned int  eventId)
1067 {
1068         AppLogDebug("TopMostFolderFileListForm::OnFileEventOccured");
1069         if ((events & FILE_EVENT_TYPE_ATTRIBUTE) || (events & FILE_EVENT_TYPE_DELETE))
1070         {
1071                 _pFolderEntryPM->RefreshFolderEntries();
1072
1073                 if (_pListView != null && _pListView->IsVisible())
1074                 {
1075                         _pListView->UpdateList();
1076                 }
1077
1078                 if (_pIconListView != null && _pIconListView->IsVisible())
1079                 {
1080                         _pIconListView->UpdateList();
1081                 }
1082                 _pFolderEntryPM->InitThumbnailManager();
1083         }
1084
1085 }