c2b87343803d84b340832047cfa3eba095e574c4
[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         if (_pFilenames->GetCount() == 0)
398         {
399                 SetFooterVisibility(DISABLE_FOOTER_ITEM);
400         }
401         else
402         {
403                 SetFooterVisibility(ENABLE_FOOTER_ITEM);
404         }
405         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
406
407         if (pArgs != null)
408         {
409                 pArgs->RemoveAll(false);
410                 delete pArgs;
411         }
412         return;
413
414         CATCH:
415         if (pArgs != null)
416         {
417                 pArgs->RemoveAll(false);
418                 delete pArgs;
419         }
420
421 }
422
423 void
424 TopMostFolderFileListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
425                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
426 {
427         DeviceManager::RemoveAllDeviceEventListeners();
428         ((MyFilesApp*)Application::GetInstance())->SetCurrentView(null);
429         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
430         _pFolderEntryPM->StopThumbnailManager(true);
431         _pFolderEntryPM->SetCurrentReqId(0);
432         /*
433         if(_pFileEventManager != null)
434                 _pFileEventManager->RemovePath(__rootMediaPath);*/
435 }
436
437 void
438 TopMostFolderFileListForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
439 {
440         String rootMediaPath;
441         String fileName;
442         String filePath;
443         DirectoryEntry* pDirStr = null;
444
445         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
446
447         if (_pFilenames != null)
448         {
449                 pDirStr = static_cast< DirectoryEntry* >(_pFilenames->GetAt(index));
450                 if (pDirStr != null)
451                 {
452                         rootMediaPath = pDirStr->GetFullFilePath();
453
454                         if (pDirStr->IsDirectory())
455                         {
456                                 //If the current filepath is a directory then load the SubDirectoryForm
457                                 filePath.Append(__rootMediaPath);
458                                 filePath.Append(pDirStr->GetFileName());
459                                 filePath.Append(L"/");
460
461
462                                 fileName.Append(pDirStr->GetFileName());
463
464                                 _currentFileName.Clear();
465                                 _currentFileName = pDirStr->GetFileName();
466
467                                 FolderNavigationPresentationModel::SetCurrentFilePath(filePath);
468                                 //_pFileListPM->SetFileEventListener(null);
469                                 LoadSubDirectoryForm(filePath, fileName);
470                         }
471                         else
472                         {
473                                 _pathOfSelectedFile = rootMediaPath;
474                                 //Else launch the corresponding AppControl.
475                                 if (_pathOfSelectedFile.EndsWith(L".tpk"))
476                                 {
477                                         String* pFileUriScheme = new (std::nothrow) String(L"file://");
478                                         pFileUriScheme->Append(_pathOfSelectedFile);
479                                         AppControl* pAc = null;
480                                         pAc = AppManager::FindAppControlN(L"D7eOJquGtL.Installer", L"http://tizen.org/appcontrol/operation/install");
481                                         if(pAc != null)
482                                         {
483                                                 pAc->Start(pFileUriScheme, null, null, null);
484                                         }
485                                         delete pFileUriScheme;
486                                 }
487                                 else
488                                 {
489                                         CustomAppControl* pCustomAppControl = CustomAppControl::GetInstance();
490                                         if (pCustomAppControl != null)
491                                         {
492                                                 __counter = index;
493
494                                                 pCustomAppControl->SetAppControlListener(null);
495                                                 AppControl* pAppControlInUse = pCustomAppControl->LaunchAppControl(_pathOfSelectedFile);
496                                                 if (pAppControlInUse != null)
497                                                         CustomAppControl::SetAppControlInUse(pAppControlInUse);
498                                         }
499                                 }
500                         }
501                 }
502         }
503         return;
504
505 }
506
507 void
508 TopMostFolderFileListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
509 {
510         result r = E_SUCCESS;
511         String mediaPath;
512         String storagePath;
513         String usbPath;
514         String displayMediaPath;
515         String displayStoragePath;
516         String displayUsbPath;
517         String extensionStatus;
518         String tabPhone;
519         String tabSDCard;
520         String tabUsb;
521
522         AppResource* pAppResource = AppResource::GetInstance();
523         Header* pHeader = null;
524         SceneManager* pSceneManager = null;
525         pSceneManager = SceneManager::GetInstance();
526
527         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
528
529         if (pAppResource != null)
530         {
531                 displayMediaPath = defaultPhoneBody;
532                 displayMediaPath.Append("/");
533
534                 displayStoragePath = defaultSdCardBody;
535                 displayStoragePath.Append("/");
536
537                 displayUsbPath = defaultExternalStorageBody;
538                 displayUsbPath.Append("/");
539
540                 pAppResource->GetString(L"IDS_MF_TAB_PHONE", tabPhone);
541                 pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", tabSDCard);
542                 pAppResource->GetString(L"IDS_COM_BODY_USB", tabUsb);
543         }
544
545
546         mediaPath = BasePresentationModel::GetMediaPath();
547         storagePath = BasePresentationModel::GetSdCardPath();
548         usbPath = BasePresentationModel::GetUsbPath();
549         AppLogDebug("SD Card Path is %ls", storagePath.GetPointer());
550
551         pHeader = GetHeader();
552
553         switch (actionId)
554         {
555         case IDA_CONTEXT_MENU_HIDE_EXTENSION:
556         {
557                 HideFileExtension();
558         }
559         break;
560
561         case IDA_CONTEXT_MENU_SHOW_EXTENSION:
562         {
563                 ShowFileExtension();
564         }
565         break;
566
567         case IDA_BTN_HOME:
568         {
569                 //Navigate to the TopFolderFileListForm.
570                 String homeRootPath;
571                 homeRootPath.Append(__rootMediaPath);
572
573                 while ((homeRootPath != BasePresentationModel::GetMediaPath()) && (homeRootPath != BasePresentationModel::GetSdCardPath()))
574                 {
575                         FolderNavigationPresentationModel::SetCurrentFilePath(homeRootPath);
576                         homeRootPath.Clear();
577                         homeRootPath = FolderNavigationPresentationModel::GetParentPath();
578                 }
579
580                 FolderNavigationPresentationModel::SetCurrentFilePath(homeRootPath);
581                 //ShowHomeView();
582                 if (CheckSearchHistory())
583                 {
584                         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
585                         //TryCatch(r == E_SUCCESS, , "scene transition failed");
586                 }
587                 else
588                 {
589                         r = pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_DESTROY), null);
590                         //TryCatch(r == E_SUCCESS, , "scene transition failed");
591                 }
592         }
593         break;
594
595         case IDA_BTN_UP:
596         {
597
598         }
599         break;
600 /*
601         case IDA_BTN_CANCEL:
602         {
603                 UiApp* pApp = UiApp::GetInstance();
604                 if (pApp != null)
605                 {
606                         pApp->Terminate();
607                 }
608         }
609         break;*/
610
611         case IDA_TABBAR_ITEM_PHONE:
612         {
613                 String currentPath;
614                 bool enableUpdate = false;
615                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
616
617                 if (currentPath.CompareTo(mediaPath) != 0)
618                 {
619                         enableUpdate = true;
620                 }
621
622                 if (enableUpdate)
623                 {
624                         if (pHeader != null)
625                         {
626                                 pHeader->SetItemSelected(0);
627                         }
628
629                         //_tabSelected = tabPhone;
630                         //__storageType = MEMORY_TYPE_PHONE;
631
632
633                         _pFolderEntryPM->SetFolderEntryPath(mediaPath);
634                         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
635
636                         __rootMediaPath.Clear();
637                         __rootMediaPath.Append(mediaPath);
638
639                         if (_pListView != null && _pListView->IsVisible())
640                         {
641                                 _pListView->UpdateList();
642                                 _pListView->ScrollToItem(0);
643
644                         }
645
646                         if (_pIconListView != null && _pIconListView->IsVisible())
647                         {
648                                 _pIconListView->UpdateList();
649                                 _pIconListView->ScrollToItem(0);
650                         }
651
652                         FolderNavigationPresentationModel::SetCurrentFilePath(mediaPath);
653                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_PHONE);
654
655                         if (_pFilenames != null && _pFilenames->GetCount() == 0)
656                         {
657                                 SetFooterVisibility(DISABLE_FOOTER_ITEM);
658                         }
659                         else
660                         {
661                                 SetFooterVisibility(ENABLE_FOOTER_ITEM);
662                         }
663                         //Invalidate(true);
664                 }
665                 if (_pFolderEntryPM != null)
666                 {
667                         _pFolderEntryPM->InitThumbnailManager();
668                 }
669         }
670         break;
671
672         case IDA_TABBAR_ITEM_SD_CARD:
673         {
674                 String currentPath;
675                 bool enableUpdate = false;
676                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
677
678                 if (currentPath.CompareTo(storagePath) != 0)
679                 {
680                         enableUpdate = true;
681                 }
682
683                 if (enableUpdate)
684                 {
685                         if (pHeader != null)
686                         {
687                                 pHeader->SetItemSelected(1);
688                         }
689
690                         //_tabSelected = tabSDCard;
691
692                         __rootMediaPath.Clear();
693                         __rootMediaPath.Append(storagePath);
694
695                         _pFolderEntryPM->SetFolderEntryPath(storagePath);
696                         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
697
698                         if (_pFilenames->GetCount() == 0)
699                         {
700                                 SetFooterVisibility(DISABLE_FOOTER_ITEM);
701                         }
702                         else
703                         {
704                                 SetFooterVisibility(ENABLE_FOOTER_ITEM);
705                         }
706                         if (_pListView != null && _pListView->IsVisible())
707                         {
708                                 _pListView->ScrollToItem(0);
709                                 _pListView->UpdateList();
710                         }
711
712                         if (_pIconListView != null && _pIconListView->IsVisible())
713                         {
714                                 _pIconListView->ScrollToItem(0);
715                                 _pIconListView->UpdateList();
716                         }
717
718
719                         FolderNavigationPresentationModel::SetCurrentFilePath(storagePath);
720                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_SD_CARD);
721                         //Invalidate(true);
722                 }
723                 if (_pFolderEntryPM != null)
724                 {
725                         _pFolderEntryPM->InitThumbnailManager();
726                 }
727         }
728         break;
729
730         case IDA_TABBAR_ITEM_USB:
731         {
732                 String currentPath;
733                 bool enableUpdate = false;
734                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
735
736                 if (currentPath.CompareTo(usbPath) != 0)
737                 {
738                         enableUpdate = true;
739                 }
740
741                 if (enableUpdate)
742                 {
743                         //_tabSelected = tabUsb;
744
745                         if (pHeader != null)
746                         {
747                                 pHeader->SetItemSelected(2);
748                         }
749
750                         __rootMediaPath.Clear();
751                         __rootMediaPath.Append(usbPath);
752
753                         _pFolderEntryPM->SetFolderEntryPath(usbPath);
754                         _pFilenames = _pFolderEntryPM->GetFolderEntryList();
755
756                         if (_pListView != null && _pListView->IsVisible())
757                         {
758                                 _pListView->ScrollToItem(0);
759                                 _pListView->UpdateList();
760                         }
761
762                         if (_pIconListView != null && _pIconListView->IsVisible())
763                         {
764                                 _pIconListView->ScrollToItem(0);
765                                 _pIconListView->UpdateList();
766                         }
767
768                         if (_pFilenames->GetCount() == 0)
769                         {
770                                 SetFooterVisibility(DISABLE_FOOTER_ITEM);
771                         }
772                         else
773                         {
774                                 SetFooterVisibility(ENABLE_FOOTER_ITEM);
775                         }
776
777                         FolderNavigationPresentationModel::SetCurrentFilePath(usbPath);
778                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_EXTERNAL);
779                         //Invalidate(true);
780                 }
781         }
782         break;
783
784         default:
785         {
786                 SubBaseOnActionPerformed(source, actionId);
787         }
788         break;
789         }
790 }
791
792 void
793 TopMostFolderFileListForm::LoadSubDirectoryForm(Tizen::Base::String& fullPath, Tizen::Base::String& fileName)
794 {
795         result r = E_SUCCESS;
796         ArrayList* pArg = null;
797         SceneManager* pSceneManager = null;
798
799         pArg = new (std::nothrow) ArrayList();
800         pArg->Construct();
801
802         pArg->Add(&fileName);
803         TryCatch(r == E_SUCCESS, , "Failed to Add Arguments to ArrayList");
804
805         pSceneManager = SceneManager::GetInstance();
806         TryCatch(pSceneManager != null, , "Failed to get SceneManager Instance");
807
808         //pSceneManager->GoForward(SCENE_SUB_DIRECTORY_FORM,pArg, SCENE_TRANSITION_ANIMATION_TYPE_LEFT);
809         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArg);
810         return;
811
812         CATCH:
813         if (pArg != null)
814         {
815                 pArg->RemoveAll();
816                 delete pArg;
817                 pArg = null;
818         }
819         return;
820
821 }
822
823
824 void
825 TopMostFolderFileListForm::InitializeAppRegistry(void)
826 {
827         AppLogDebug("ENTER");
828         // 3 keys: ViewStyle, SortBy, Show/Hide File Extension
829         result r = E_SUCCESS;
830
831         AppRegistry* pAppRegistry = null;
832         String viewStyleKeyName(L"ListDisplayType");
833         ViewType viewStyle = VIEW_TYPE_AS_NORMAL_LIST;
834
835         String sortbyKeyName(L"SortBy");
836         SortByType sortStyle = SORT_BY_TYPE_DATE_RECENT;
837
838         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
839
840         r = pAppRegistry->Add(viewStyleKeyName, viewStyle);
841         if (r == E_SUCCESS)
842         {
843                 r = pAppRegistry->Save();
844         }
845
846         r = pAppRegistry->Add(_extensionKeyName, _hideExtension);
847         if (r == E_SUCCESS)
848         {
849                 r = pAppRegistry->Save();
850         }
851
852         r = pAppRegistry->Add(sortbyKeyName, sortStyle);
853         if (r == E_SUCCESS)
854         {
855                 r = pAppRegistry->Save();
856         }
857
858         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
859 }
860
861 void
862 TopMostFolderFileListForm::OnNotificationReceived(Tizen::Base::Collection::ArrayList* pArgs)
863 {
864         AppLogDebug("ENTER");
865         Integer* pFileProcessingResult = null;
866
867         TryCatch(pArgs != null, , "Argument list received is invalid!");
868         pFileProcessingResult = (Integer*) pArgs->GetAt(0);
869
870         TryCatch(pFileProcessingResult != null, , "FileProcessing Result  list is invalid!");
871
872         switch (pFileProcessingResult->ToInt())
873         {
874         case FILE_MANAGING_RESULT_DELETING_SUCCESS:
875         {
876                 AppLogDebug("FILE_PROCESSING_RESULT_DELETING_SUCCESS");
877                 if (_pFilenames != null)
878                 {
879                         _pFilenames->RemoveAt(_indexTracker, true);
880                         //r = __pListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
881                         _pListView->UpdateList();
882
883                         if (_pIconListView != null && _pIconListView->IsVisible())
884                         {
885                                 _pIconListView->UpdateList();
886                         }
887                 }
888                 HideFileProgressingPopup();
889         }
890         break;
891
892         case FILE_MANAGING_RESULT_DELETING_FAILED:
893         {
894                 HideFileProgressingPopup();
895         }
896         break;
897         case FILE_MANAGING_RESULT_THREAD_STOP:
898         {
899                 HideFileProgressingPopup();
900         }
901         break;
902         default:
903                 //Do Nothing.
904                 break;
905         }
906
907
908         Invalidate(true);
909
910         CATCH:
911         if (pArgs != null)
912         {
913                 pArgs->RemoveAll(true);
914                 delete pArgs;
915         }
916 }
917
918 void
919 TopMostFolderFileListForm::OnFileEventExecuted(const Tizen::Base::String& path, const unsigned long eventId)
920 {
921         AppLogDebug("ENTER");
922         int badgeNumber = 0;
923
924         //      Tizen::Shell::NotificationManager* pNotiMgr = null;
925         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
926
927         NotificationManager* pNotiMgr = null;
928         AppResource* pAppResource = null;
929         pAppResource = UiApp::GetInstance()->GetAppResource();
930         TryCatch(pAppResource != null, , "Failed to fetch AppResource");
931
932         pNotiMgr = new (std::nothrow) NotificationManager();
933         TryCatch(pNotiMgr != null, , "Failed to fetch AppNotificationManager");
934
935         pNotiMgr->Construct();
936         badgeNumber = pNotiMgr->GetBadgeNumber();
937         badgeNumber++;
938
939
940         //_pFolderEntryPM->SetFileEventListener(null);
941
942         switch (eventId)
943         {
944         case FILE_EVENT_TYPE_CREATE:
945         {
946                 if (_pListView != null && _pListView->IsVisible())
947                 {
948                         _pListView->RefreshList(_pFilenames->GetCount() - 1, LIST_REFRESH_TYPE_ITEM_ADD);
949                 }
950                 if (_pIconListView != null && _pIconListView->IsVisible())
951                 {
952                         _pIconListView->RefreshList(_pFilenames->GetCount() - 1, LIST_REFRESH_TYPE_ITEM_ADD);
953                 }
954         }
955         break;
956
957         case FILE_EVENT_TYPE_DELETE:
958         {
959                 if (_pListView != null && _pListView->IsVisible())
960                 {
961                         _pListView->RefreshList(__counter, LIST_REFRESH_TYPE_ITEM_REMOVE);
962                 }
963                 if (_pIconListView != null && _pIconListView->IsVisible())
964                 {
965                         if (_pThumbnailItemProvider != null)
966                         {
967                                 __counter = _pThumbnailItemProvider->GetPressedIndex();
968                         }
969                         _pIconListView->RefreshList(__counter, LIST_REFRESH_TYPE_ITEM_REMOVE);
970                 }
971         }
972         break;
973
974         default:
975         {
976                 //Empty Implementation.
977         }
978         break;
979         }
980
981         if (pNotiMgr != null)
982         {
983                 delete pNotiMgr;
984                 pNotiMgr = null;
985         }
986         return;
987
988         CATCH:
989         //      if (pNotiMgr != null)
990         //      {
991         //              delete pNotiMgr;
992         //              pNotiMgr = null;
993         //      }
994         return;
995 }
996
997 void
998 TopMostFolderFileListForm::OnSceneTransitionCompleted(const Tizen::Ui::Scenes::SceneId &previousSceneId,
999                 const Tizen::Ui::Scenes::SceneId &currentSceneId)
1000 {
1001         AppLogDebug("Enter");
1002         AppLogDebug("_rename index %d",_renameIndex);
1003         AppRegistry* pAppRegistry = null;
1004         String sortbyKeyName(L"SortBy");
1005         int sortStyle = SORT_BY_TYPE_DATE_RECENT;
1006
1007         TryReturn (_pFolderEntryPM !=null, , "FolderEntryPresentation Model is NULL");
1008
1009         if (_pFileEventManager != null)
1010         {
1011                 delete _pFileEventManager;
1012                 _pFileEventManager = null;
1013
1014         }
1015
1016         /*_pFileEventManager = new FileEventManager();
1017         _pFileEventManager->Construct(*this);
1018
1019         _pFileEventManager->AddPath(__rootMediaPath, FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_DELETE );*/
1020
1021
1022         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
1023         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
1024
1025         if (previousSceneId == IDSCN_CREATE_FOLDER_FORM)
1026         {
1027                 if (_renameOrCreate == SELECT_RENAME)
1028                 {
1029                         pAppRegistry->Get(sortbyKeyName, sortStyle);
1030
1031                         if (sortStyle == SORT_BY_TYPE_NAME_ASCENDING || sortStyle == SORT_BY_TYPE_NAME_DESCENDING
1032                                         || sortStyle == SORT_BY_TYPE_DATE_OLDEST || sortStyle == SORT_BY_TYPE_DATE_RECENT)
1033                         {
1034                                 _pFolderEntryPM->SetFolderEntryPath(FolderNavigationPresentationModel::GetCurrentPath());
1035                                 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
1036
1037                                 if (_pListView != null && _pListView->IsVisible())
1038                                 {
1039                                         _pListView->UpdateList();
1040                                         _pListView->ScrollToItem(0);
1041                                 }
1042                                 _pFolderEntryPM->InitThumbnailManager();
1043                         }
1044                         else
1045                         {
1046                                 _pListView->RefreshList(_renameIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
1047                         }
1048                         //_pFolderEntryPM->InitThumbnailManager();
1049                         return;
1050                 }
1051         }
1052         if (CheckSearchHistory())
1053         {
1054                 __previousSceneName = previousSceneId;
1055         }
1056
1057         SwitchViewType();
1058         _pFolderEntryPM->InitThumbnailManager();
1059 }
1060
1061 void
1062 TopMostFolderFileListForm::OnSceneTransitionStarted(const Tizen::Ui::Scenes::SceneId &currentSceneId,
1063                 const Tizen::Ui::Scenes::SceneId &nextSceneId)
1064 {
1065         //Empty Implementation.
1066 }
1067
1068 void
1069 TopMostFolderFileListForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1070 {
1071         switch (orientationStatus)
1072         {
1073         case ORIENTATION_STATUS_LANDSCAPE:
1074         {
1075                 SceneManager* pSceneManager = null;
1076                 pSceneManager = SceneManager::GetInstance();
1077                 if (pSceneManager != null)
1078                 {
1079                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SPLIT_PANEL_FORM, SCENE_TRANSITION_ANIMATION_TYPE_NONE), null);
1080                 }
1081         }
1082         break;
1083         default:
1084         break;
1085         }
1086 }
1087
1088 void
1089 TopMostFolderFileListForm::OnFileEventOccured(const unsigned long events,const Tizen::Base::String &  path, const unsigned int  eventId)
1090 {
1091         AppLogDebug("TopMostFolderFileListForm::OnFileEventOccured");
1092         if ((events & FILE_EVENT_TYPE_ATTRIBUTE) || (events & FILE_EVENT_TYPE_DELETE))
1093         {
1094                 _pFolderEntryPM->RefreshFolderEntries();
1095
1096                 if (_pListView != null && _pListView->IsVisible())
1097                 {
1098                         _pListView->UpdateList();
1099                 }
1100
1101                 if (_pIconListView != null && _pIconListView->IsVisible())
1102                 {
1103                         _pIconListView->UpdateList();
1104                 }
1105                 _pFolderEntryPM->InitThumbnailManager();
1106         }
1107
1108 }