2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
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.
18 * @file: MfFileManageForm.cpp
19 * @brief: This file contains the implementation of FileManageForm class,
20 * and is responsible for creating the Edit View form.
21 * Operations like copy, move, delete can be performed in this form.
26 #include "MfDirectoryEntry.h"
27 #include "MfFileManageForm.h"
28 #include "MfSceneRegister.h"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Locales;
37 using namespace Tizen::System;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Animations;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Scenes;
43 /*Constructor for the Edit Form.
44 * Variable are initialised to null or other default values
46 FileManageForm::FileManageForm(void)
48 __bScrollFlag = false;
49 __bCheckNullArgs = false;
50 _fileProcessedCount = 0;
51 __storageType = MEMORY_TYPE_NONE;
53 _viewType = VIEW_TYPE_AS_NORMAL_LIST;
56 FileManageForm::~FileManageForm(void)
58 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
61 FileManageForm::FileManageForm(const FileManageForm& editForm)
63 //empty Implementation
67 FileManageForm::operator =(const FileManageForm& editForm)
69 if (this != &editForm)
71 _pStrItemSelectedCount = editForm._pStrItemSelectedCount;
72 _currentDirectoryPath = editForm._currentDirectoryPath;
73 _pFilenames = editForm._pFilenames;
74 _pFooter = editForm._pFooter;
75 _pEditListView = editForm._pEditListView;
76 _pThumbnailManager = editForm._pThumbnailManager;
77 _pFileManager = editForm._pFileManager;
78 _pFolderEntryPM = editForm._pFolderEntryPM;
79 _pLabelNumberOfItems = editForm._pLabelNumberOfItems;
85 FileManageForm::Initialize(void)
87 Form::Construct(L"IDL_EDIT");
92 FileManageForm::OnInitializing(void)
96 int h_EditIconListView = 0;
99 Header* pHeader = null;
100 SceneManager* pSceneManager = null;
102 pSceneManager = SceneManager::GetInstance();
104 pSceneManager->SetFormTransitionAnimationDefaultValues(SCENE_TRANSITION_ANIMATION_TYPE_FADE_IN_OUT, 500, ANIMATION_INTERPOLATOR_EASE_IN_OUT);
106 AppResource* pAppResource = null;
108 h_EditIconListView = GetClientAreaBounds().height - H_CHECK_BUTTON;
110 Rectangle checkButtonBounds(X_DEFAULT, Y_DEFAULT, GetClientAreaBounds().width, H_CHECK_BUTTON);
111 Rectangle iconListViewBounds(X_DEFAULT, checkButtonBounds.height, GetClientAreaBounds().width, h_EditIconListView);
112 Rectangle listViewBounds(X_DEFAULT, checkButtonBounds.height, GetClientAreaBounds().width, h_EditIconListView);
114 pAppResource = UiApp::GetInstance()->GetAppResource();
115 TryCatch(pAppResource != null, , "MfMyFilesApp::Resource manager not found!");
117 pAppResource->GetString(L"IDS_COM_BODY_SELECT_ALL", selectAll);
118 pAppResource->GetString(L"IDS_MF_SK3_EDIT" , headerText);
120 pHeader = GetHeader();
122 //Set FormBackEvent Listener
123 SetFormBackEventListener(this);
124 //AddOrientationEventListener(*this);
126 _fileProcessedCount = 0;
128 CreateFooterControls();
130 _pFileManager = FolderEntryEditorPresentationModel::GetInstance();
131 TryCatch(_pFileManager != null, , "Failed to allocate FileManager");
133 _pStrItemSelectedCount = new (std::nothrow) String();
134 TryCatch(_pStrItemSelectedCount != null, , "Failed to allocate __pNumberOfItemSelected");
136 _pThumbnailItemProvider = new (std::nothrow) ThumbnailItemProviderAndListener(_currentDirectoryPath, THUMBNAIL_PROVIDER_SOURCEID_FILE_MANAGE_FORM);
137 _pThumbnailItemProvider->SetFolderEntryProvider(this);
139 _pEditIconListView = static_cast< IconListView* >(GetControl(L"IDC_ICONLISTVIEW_THUMBNAILS"));
140 if (_pEditIconListView != null)
142 _pEditIconListView->SetShowState(false);
143 _pEditIconListView->AddIconListViewItemEventListener(*this);
144 _pEditIconListView->AddScrollEventListener(*this);
145 _pEditIconListView->SetItemProvider(*_pThumbnailItemProvider);
148 _pBaseItemProvider = new (std::nothrow) BaseItemProvider();
149 TryCatch(_pBaseItemProvider != null, , "Failed to allocate base itemprovider");
150 _pBaseItemProvider->Construct();
151 _pBaseItemProvider->SetFolderEntryProvider(this);
153 _pEditListView = static_cast< ListView* >(GetControl(L"IDC_LISTVIEW1"));
154 if (_pEditListView != null)
156 _pEditListView->AddListViewItemEventListener(*this);
157 _pEditListView->AddScrollEventListener(*this);
159 r = _pCheckButtonSelectAll.Construct(BUTTON_ITEM_STYLE_TEXT, IDA_BTN_CHECKED);
160 r = _pCheckButtonSelectAll.SetText(selectAll);
163 pHeader->SetTitleText(headerText);
164 pHeader->AddActionEventListener(*this);
165 pHeader->SetButton(BUTTON_POSITION_RIGHT, _pCheckButtonSelectAll);
167 CreateLabelControl();
169 _currentDirectoryPath = FolderNavigationPresentationModel::GetCurrentPath();
171 AppLogDebug("Exit %s", GetErrorMessage(GetLastResult()));
176 AppLogDebug("Exit %s", GetErrorMessage(GetLastResult()));
181 FileManageForm::OnTerminating(void)
183 AppLogDebug("Entry");
184 result r = E_SUCCESS;
191 FileManageForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
192 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
194 AppLogDebug("Entry");
196 int listViewDisplayType = VIEW_TYPE_AS_NORMAL_LIST;
200 int thumbnailItemSource = THUMBNAIL_PROVIDER_SOURCEID_FILE_MANAGE_FORM;
202 result r = E_SUCCESS;
203 _previousSceneId = previousSceneId;
205 AppRegistry* pAppRegistry = null;
206 AppResource* pAppResource = null;
209 String viewStyleKeyName(L"ListDisplayType");
210 FolderEntryPresentationModel* pcurrentFolderEntryPM = null;
211 Integer* pEditOrShare = null;
212 Header* pHeader = null;
214 pAppResource = UiApp::App::GetInstance()->GetAppResource();
216 Rectangle listViewBounds(X_DEFAULT, H_CHECK_BUTTON, GetClientAreaBounds().width, GetClientAreaBounds().height - H_CHECK_BUTTON);
217 ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
218 pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
220 r = pAppRegistry->Get(viewStyleKeyName, listViewDisplayType);
221 TryCatch(r == E_SUCCESS, , "Unable to get registry values");
222 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
224 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_USB_CLIENT, *this);
227 SceneManager::GetInstance()->AddSceneManagerEventListener(*this);
228 _viewType = listViewDisplayType;
230 if (pArgs != null && previousSceneId != IDSCN_CREATE_FOLDER_FORM && (previousSceneId != IDSCN_SUB_DIRECTORY_MOVE_COPY_FORM && previousSceneId != IDSCN_SUB_DIRECTORY_MOVE_COPY_FORM1) )
232 pEditOrShare = static_cast<Integer *>(pArgs->GetAt(0));
233 _editOrShare = pEditOrShare->ToInt();
235 pcurrentFolderEntryPM = static_cast<FolderEntryPresentationModel *>(pArgs->GetAt(1));
236 TryCatch(pcurrentFolderEntryPM != null, , "FolderEntryPM is null");
238 _pFolderEntryPM = pcurrentFolderEntryPM;
239 _pBaseItemProvider->SetFolderEntryProvider(this);
240 _pThumbnailItemProvider->SetFolderEntryProvider(this);
242 if (_editOrShare == FILE_MANAGE_EDIT)
244 thumbnailItemSource = THUMBNAIL_PROVIDER_SOURCEID_FILE_MANAGE_FORM;
246 if (pAppResource != null)
248 pAppResource->GetString(L"IDS_MF_SK3_EDIT", headerText);
250 _pBaseItemProvider->SetSourceForm(CREATE_ITEM_SOURCE_FILE_MANAGE_FORM);
251 if (previousSceneId != IDSCN_CATEGORY_SEARCH_FORM)
253 _pFolderEntryPM->SetSourceForm(CREATE_ITEM_SOURCE_FILE_MANAGE_FORM);
255 _pThumbnailItemProvider->SetCreateItemSource(thumbnailItemSource);
259 thumbnailItemSource = THUMBNAIL_PROVIDER_SOURCEID_SHARE_FORM;
261 if (pAppResource != null)
263 pAppResource->GetString(L"IDS_COM_BUTTON_SHARE", headerText);
265 _pBaseItemProvider->SetSourceForm(CREATE_ITEM_SOURCE_SHARE_FORM);
266 if (previousSceneId != IDSCN_CATEGORY_SEARCH_FORM)
268 _pFolderEntryPM->SetSourceForm(CREATE_ITEM_SOURCE_SHARE_FORM);
270 _pThumbnailItemProvider->SetCreateItemSource(thumbnailItemSource);
273 _pEditListView->SetItemProvider(*_pBaseItemProvider);
275 _pFolderEntryPM->GetFolderEntryCount(FolderNavigationPresentationModel::GetCurrentPath(), folderCount, fileCount);
277 pHeader = GetHeader();
280 pHeader->SetTitleText(headerText);
282 if (previousSceneId != IDSCN_CATEGORY_SEARCH_FORM)
284 if (_editOrShare == FILE_MANAGE_SHARE)
288 pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, false);
292 pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, true);
296 pHeader->Invalidate(true);
302 if (_pFileManager != null)
304 _pFileManager->SetFileManagingListener(this);
307 if (previousSceneId == IDSCN_CREATE_FOLDER_FORM)
311 __bCheckNullArgs = true;
315 __bCheckNullArgs = false;
318 AppLogDebug("Exit %s", GetErrorMessage(r));
322 if (_pFilenames != null)
324 _pFilenames->RemoveAll(true);
328 AppLogDebug("Exit %s", GetErrorMessage(GetLastResult()));
332 FileManageForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
333 const Tizen::Ui::Scenes::SceneId& nextSceneId)
335 DeviceManager::RemoveAllDeviceEventListeners();
336 ((MyFilesApp*)Application::GetInstance())->SetCurrentView(null);
337 _pFolderEntryPM->StopThumbnailManager(true);
341 FileManageForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
343 SubBaseOnActionPerformed(source, actionId);
347 FileManageForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
349 SubBaseOnListViewItemStateChanged(listView, index, elementId, status);
353 FileManageForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
355 //Empty Implementation.
359 FileManageForm::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView& iconListView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
361 SubBaseOnIconListViewItemStateChanged(iconListView, index, status);
365 FileManageForm::OnIconListViewOverlayBitmapSelected (Tizen::Ui::Controls::IconListView &iconListView, int index, int overlayBitmapId)
367 if (overlayBitmapId == OVERLAYITEM_RENAME)
369 _renameItemIndex = index;
371 if (iconListView.IsItemChecked(index))
373 iconListView.SetItemChecked(index, false);
376 LoadRenameForm(index);
379 _renameItemIndex = INVALID_LIST_INDEX;
383 FileManageForm::OnListViewItemStateChangedNotify(ViewType listViewStyle)
385 //Empty Implementation.
389 FileManageForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
391 AppLogDebug("ENTRY");
392 switch (orientationStatus)
394 case ORIENTATION_STATUS_PORTRAIT:
399 case ORIENTATION_STATUS_LANDSCAPE:
401 if (__previousSceneId != IDSCN_CATEGORY_SEARCH_FORM)
403 SceneManager* pSceneManager = null;
404 pSceneManager = SceneManager::GetInstance();
405 if (pSceneManager != null)
407 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SPLIT_PANEL_FILE_MANAGE_FORM, SCENE_TRANSITION_ANIMATION_TYPE_NONE), null);
422 FileManageForm::OnFileManagingStart(void)
424 //ShowFileProgressingPopup();
428 FileManageForm::OnFileManagingStop(FileManagingResult fileManagingResult)
430 HideFileProgressingPopup();
432 switch (fileManagingResult)
434 case FILE_MANAGING_RESULT_DELETING_SUCCESS:
436 SceneManager* pSceneManager = SceneManager::GetInstance();
437 if (pSceneManager != null)
439 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_DESTROY), null);
453 FileManageForm::OnNotificationReceived(Tizen::Base::Collection::ArrayList* pArgs)
455 SubBaseOnNotificationReceived(pArgs);
459 FileManageForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
461 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
465 FileManageForm::OnThumbnailReceived(ThumbRequest* pThumbReq)
467 SubBaseOnThumbnailReceived(pThumbReq);
470 FolderEntryPresentationModel*
471 FileManageForm::GetFolderEntryPresentationModel(void)
473 return _pFolderEntryPM;
477 FileManageForm::OnDeviceChange(ComponentType deviceType, const Tizen::Base::String& state)
479 bool setMediaPath = false;
480 MemoryType currentMemoryType = MEMORY_TYPE_PHONE;
481 String unmounted = sdCardStatusUnmounted;
482 String removed = usbDeviceStatusRemoved;
485 SceneManager* pSceneManager = null;
487 if (state == unmounted || state == removed)
489 if (_previousSceneId == IDSCN_CATEGORY_SEARCH_FORM)
491 if (_pFolderEntryPM != null)
493 if (_pFolderEntryPM->GetDeviceListCount() > 1)
495 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
501 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
502 if (state == unmounted)
504 if (currentPath.Contains(BasePresentationModel::GetSdCardPath()))
506 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetMediaPath());
507 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
512 if (state == removed)
514 if (currentPath.Contains(BasePresentationModel::GetUsbPath()))
516 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetMediaPath());
517 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
524 pSceneManager = SceneManager::GetInstance();
525 if (pSceneManager != null)
527 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_DESTROY), null);
534 FileManageForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
537 ComponentType currentDeviceType;
542 currentDeviceType = COMPONENT_TYPE_STORAGE_CARD;
548 currentDeviceType = COMPONENT_TYPE_USB;
558 OnDeviceChange(currentDeviceType, state);
562 FileManageForm::OnScrollEndReached(Tizen::Ui::Control& source, Tizen::Ui::Controls::ScrollEndEvent type)
564 if (type == SCROLL_END_EVENT_END_BOTTOM)
566 __bScrollFlag = true;
570 __bScrollFlag = false;
575 FileManageForm::OnScrollPositionChanged(Tizen::Ui::Control& source, int scrollPos)
577 //Empty Implementation.
581 FileManageForm::OnScrollStopped(Tizen::Ui::Control& source)
583 //Empty Implementation.
587 FileManageForm::OnSceneTransitionCompleted(const Tizen::Ui::Scenes::SceneId &previousSceneId,
588 const Tizen::Ui::Scenes::SceneId ¤tSceneId)
590 AppLogDebug("Enter");
592 Integer* pRenameItemIndex = null;
593 const DirectoryEntry* pDir = null;
594 DirectoryEntry* pDirectoryEntry = null;
595 Integer pReceivedStorageType;
597 __previousSceneId = previousSceneId;
598 SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
600 if (previousSceneId != IDSCN_CREATE_FOLDER_FORM)
602 if (_pFolderEntryPM != null)
604 _pFilenames = _pFolderEntryPM->GetFolderEntryList();
607 if (_pFileManager != null)
609 if (_pFileManager->GetCheckedListCount() != 0)
611 _pFileManager->ClearCheckedList();
613 _isSelectAll = false;
616 if (_pLabelNumberOfItems != null)
618 _pLabelNumberOfItems->SetShowState(false);
621 SetFooterVisibility(DISABLE_FOOTER_ITEM);
625 if (_pEditListView != null && _pEditIconListView != null)
627 for (int itemCount = 0; itemCount < _pFilenames->GetCount(); itemCount++)
629 if (_pEditListView->IsItemChecked(itemCount) == true)
631 _pEditListView->SetItemChecked(itemCount, false);
634 if (_pEditIconListView->IsItemChecked(itemCount) == true)
636 _pEditIconListView->SetItemChecked(itemCount, false);
643 if (previousSceneId == IDSCN_CREATE_FOLDER_FORM)
645 if (_renameItemIndex != INVALID_LIST_INDEX && _pFileManager != null)
647 AppLogDebug("checked entry count is %d", _pFileManager->GetCheckedListCount());
648 if (_pEditListView != null && _pEditListView->IsVisible())
650 if (__bCheckNullArgs)
652 _pEditListView->RefreshList(_renameItemIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
655 if (_pEditIconListView != null && _pEditIconListView->IsVisible())
657 _pEditIconListView->RefreshList(_renameItemIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
659 pRenameItemIndex = new (std::nothrow) Integer(_renameItemIndex);
661 pDir = static_cast< const DirectoryEntry* >(_pFileManager->GetCheckedList()->GetValue(*pRenameItemIndex));
664 pDirectoryEntry = static_cast< DirectoryEntry* >(_pFilenames->GetAt(_renameItemIndex));
665 TryCatch(pDirectoryEntry != null, , "r = E_FAILURE pDirectoryEntry is null");
667 _pFileManager->RemoveCheckedListEntry(_renameItemIndex);
668 _pFileManager->AddCheckedListEntry(_renameItemIndex, pDirectoryEntry);
670 if (_pEditIconListView != null && _pEditIconListView->IsVisible())
672 _pEditIconListView->SetItemChecked(_renameItemIndex, true);
676 delete pRenameItemIndex;
684 case VIEW_TYPE_AS_DETAILED_LIST:
686 if (_pEditIconListView != null && _pEditIconListView->IsVisible())
688 _pEditIconListView->SetShowState(false);
690 if (_pEditListView != null)
692 _pEditListView->ScrollToItem(0);
693 _pEditListView->UpdateList();
694 _pEditListView->SetShowState(true);
699 case VIEW_TYPE_AS_NORMAL_LIST:
701 if (_pEditIconListView != null && _pEditIconListView->IsVisible())
703 _pEditIconListView->SetShowState(false);
706 if (_pEditListView != null)
708 _pEditListView->ScrollToItem(0);
709 _pEditListView->UpdateList();
710 _pEditListView->SetShowState(true);
715 case VIEW_TYPE_AS_THUMBNAILS:
717 if (_pEditListView != null && _pEditListView->IsVisible())
719 _pEditListView->SetShowState(false);
721 if (_pEditIconListView != null)
723 _pEditIconListView->ScrollToItem(0);
724 _pEditIconListView->UpdateList();
725 _pEditIconListView->SetShowState(true);
732 if (_pEditListView != null)
734 _pEditListView->UpdateList();
735 _pEditListView->SetShowState(true);
737 if (_pEditIconListView != null && _pEditIconListView->IsVisible())
739 _pEditIconListView->SetShowState(false);
745 if (_pLabelNumberOfItems != null && _pLabelNumberOfItems->GetShowState() == true)
747 if (_pEditIconListView != null && _pEditIconListView->IsVisible())
749 _pEditIconListView->SetBounds(Rectangle(X_DEFAULT, Y_DEFAULT, GetClientAreaBounds().width, GetClientAreaBounds().height - H_DISPLAY_PATH_LABEL));
751 _pEditIconListView->Invalidate(true);
754 if (_pEditListView != null && _pEditListView->IsVisible())
756 _pEditListView->SetBounds(Rectangle(X_DEFAULT, Y_DEFAULT, GetClientAreaBounds().width, GetClientAreaBounds().height - H_DISPLAY_PATH_LABEL));
758 _pEditListView->Invalidate(true);
763 if (_pEditIconListView != null && _pEditIconListView->IsVisible())
765 _pEditIconListView->SetBounds(Rectangle(X_DEFAULT, Y_DEFAULT, GetClientAreaBounds().width, GetClientAreaBounds().height));
767 _pEditIconListView->Invalidate(true);
770 if (_pEditListView != null && _pEditListView->IsVisible())
772 _pEditListView->SetBounds(Rectangle(X_DEFAULT, Y_DEFAULT, GetClientAreaBounds().width, GetClientAreaBounds().height));
774 _pEditListView->Invalidate(true);
777 _pFolderEntryPM->InitThumbnailManager();
785 FileManageForm::OnSceneTransitionStarted(const Tizen::Ui::Scenes::SceneId ¤tSceneId,
786 const Tizen::Ui::Scenes::SceneId &nextSceneId)
788 //Empty Implementation.