2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
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: MfMyFilesApp.cpp
19 * @brief: This file contains the declaration of MyFilesApp Class,
20 * which provides basic features necessary to define an UiApp.
24 #include <FUiScenes.h>
26 #include "MfCustomAppControl.h"
27 #include "MfFolderEntryPresentationModel.h"
28 #include "MfFormFactory.h"
29 #include "MfMainFrame.h"
30 #include "MfMyFilesApp.h"
31 #include "MfPanelFactory.h"
32 #include "MfSceneRegister.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Utility;
39 using namespace Tizen::System;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Controls;
42 using namespace Tizen::Ui::Scenes;
44 MyFilesApp::MyFilesApp(void)
46 , __pCurrentListToUpdate(null)
47 , __pNotificationListener(null)
48 , __pAudioNotificationListener(null)
50 __operationId.Append(L"");
51 __mimeType.Append(L"");
52 __bAppControlEnabled = false;
53 __inputSource = APPCONTROL_STATE_MAINVIEW_SELECTED;
54 __currentFileType = FILE_TYPE_ALL;
55 __currentSelectionMode = SELECTION_MODE_SINGE;
56 __currentView = APPCONTROL_VIEW_DEFAULT;
57 __currentExportFileType = EXPORT_TYPE_CONTACTS;
58 __bImgAppControlLaunched = true;
59 __currentAppControlResult = APP_CTRL_RESULT_FAILED;
61 __currentSceneId = L"";
62 __previousSceneId = L"";
64 __bIsAppInBackground = false;
67 MyFilesApp::~MyFilesApp(void)
73 MyFilesApp::CreateInstance(void)
75 // Create the instance through the constructor.
77 return new (std::nothrow) MyFilesApp();
81 MyFilesApp::OnAppInitializing(AppRegistry& appRegistry)
85 InitializeListeners();
86 r = AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);
87 //r = AppControlProviderManager::GetInstance()->SendAppControlResult()
92 MyFilesApp::OnAppInitialized(void)
96 SceneManager* pSceneManager = null;
97 MfMainFrame* pMyFileMainFrame = null;
98 MessageBox messageBox;
99 String languageKey = L"http://tizen.org/setting/locale.language";
102 pMyFileMainFrame = new (std::nothrow) MfMainFrame();
103 TryCatch(pMyFileMainFrame != null, , "MainFrame pointer is null!");
105 r = pMyFileMainFrame->Construct();
106 TryCatch(r == E_SUCCESS, , "MainFrame creation failed!");
108 //pMyFileMainFrame->SetOperationIdAndInputSource(__operationId, __inputSource);
109 pMyFileMainFrame->SetName(L"MyFilesAppFrame");
110 AddFrame(*pMyFileMainFrame);
112 ThumbnailManager::GetInstance();
114 SceneRegister::RegisterAllScenes();
115 // Prepare Scene management.
116 pSceneManager = SceneManager::GetInstance();
117 TryCatch(pSceneManager != null, , "ScneManager is null!");
120 if (pSceneManager != null)
122 if (__operationId.CompareTo("http://tizen.org/appcontrol/operation/pick") == 0)
124 if (__currentView != APPCONTROL_VIEW_IMPORT)
126 __inputSource = APPCONTROL_STATE_SELECTED;
127 /*IList* pArgs = new (std::nothrow) ArrayList();
128 pArgs->Add(new (std::nothrow) Integer(APPCONTROL_STATE_SELECTED));*/
129 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM), null);
133 else if (__currentView == APPCONTROL_VIEW_EXPORT)
135 if (__pResultList == null)
137 __pResultList = new (std::nothrow) HashMap();
138 __pResultList->Construct();
140 ArrayList* pArgs = null;
141 String currentFilePath;
143 pArgs = new (std::nothrow) ArrayList();
145 if (__currentExportFileType == EXPORT_TYPE_CALENDAR)
147 currentFilePath = BasePresentationModel::GetMediaPath();
148 currentFilePath.Append("Backup/Calendar/");
149 headertitle.Append("Calendar");
151 if (__currentExportFileType == EXPORT_TYPE_CONTACTS)
153 currentFilePath = BasePresentationModel::GetMediaPath();
154 currentFilePath.Append("Backup/Contacts/");
155 headertitle.Append("Contacts");
158 pArgs->Add(new String (headertitle));
159 FolderNavigationPresentationModel::SetCurrentFilePath(currentFilePath);
160 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_FOLDER_SELECTION_FORM), pArgs);
162 else if (__currentView == APPCONTROL_VIEW_IMPORT)
164 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_MOST_SELECTION_FORM), null);
170 //pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ROOT_DIRECTORY_FORM));
171 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM));
172 __bAppControlMode = false;
177 //Setting Application setting change event listener.
178 SettingInfo::GetValue(languageKey, __currentDisplayLanguage);
179 SettingInfo::AddSettingEventListener(*this);
183 return false; //Returning false changes app state to TERMINATING and app's OnAppTerminating function will be called.
187 MyFilesApp::OnAppControlRequestReceivedN(RequestId reqId, const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::String& category,
188 const Tizen::Base::String* pDataType, const Tizen::Base::String* pUriScheme, Tizen::Base::Collection::IList* pArgs)
190 //Empty Implementation.
194 MyFilesApp::OnAppWillTerminate(void)
200 MyFilesApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
202 AppLogDebug("ENTER");
204 result r = E_SUCCESS;
205 ArrayList* pAppControlResultList = null;
207 // Deallocate resources allocated by this App for termination.
208 // The App's permanent data and context can be saved via appRegistry.
210 if (__bAppControlEnabled == true)
212 if (__currentView == APPCONTROL_VIEW_EXPORT)
214 if (__currentAppControlResult == APP_CTRL_RESULT_CANCELED)
216 if (__pResultList != null)
218 __pResultList->RemoveAll(true);
219 delete __pResultList;
220 __pResultList = null;
222 r = AppControlProviderManager::GetInstance()->SendAppControlResult(__currentRequestId, __currentAppControlResult, null);
226 pAppControlResultList = new (std::nothrow) ArrayList();
227 pAppControlResultList->Construct();
228 resultList = FolderNavigationPresentationModel::GetCurrentPath();
229 pAppControlResultList->Add(new (std::nothrow) String(resultList));
230 if (__pResultList != null && resultList.CompareTo("") != 0)
232 __pResultList->Add(new (std::nothrow) String(appcontroldataKey),pAppControlResultList);
234 AppLog("Result added is %S",resultList.GetPointer());
235 r = AppControlProviderManager::GetInstance()->SendAppControlResult(__currentRequestId, __currentAppControlResult, __pResultList);
240 const HashMap* pResultHash = null;
241 IMapEnumerator* pResultMapEnum = null;
242 DirectoryEntry* pDirStr = null;
244 pResultHash = FolderEntryEditorPresentationModel::GetInstance()->GetCheckedList();
246 if (__currentAppControlResult != APP_CTRL_RESULT_CANCELED)
248 if (pResultHash != null)
250 pResultMapEnum = pResultHash->GetMapEnumeratorN();
252 if (pResultMapEnum != null)
254 pAppControlResultList = new (std::nothrow) ArrayList();
255 pAppControlResultList->Construct();
257 if (pResultHash->GetCount() != 0)
259 //__pResultList->Add(*new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
261 while (pResultMapEnum->MoveNext() == E_SUCCESS)
263 pDirStr = static_cast< DirectoryEntry* >(pResultMapEnum->GetValue());
267 pAppControlResultList->Add(new (std::nothrow) String(pDirStr->GetFullFilePath()));
271 delete pResultMapEnum;
276 if (__pResultList != null && __currentAppControlResult != APP_CTRL_RESULT_CANCELED)
278 //__pResultList->Add(new (std::nothrow) String(appcontrolKey), new (std::nothrow) String(resultList));
279 __pResultList->Add(new (std::nothrow) String(appcontroldataKey), pAppControlResultList);
282 if (__currentAppControlResult == APP_CTRL_RESULT_CANCELED)
284 if (__pResultList != null)
286 __pResultList->RemoveAll(true);
287 delete __pResultList;
288 __pResultList = null;
290 r = AppControlProviderManager::GetInstance()->SendAppControlResult(__currentRequestId, __currentAppControlResult, null);
294 r = AppControlProviderManager::GetInstance()->SendAppControlResult(__currentRequestId, __currentAppControlResult, __pResultList);
299 //Following code stops FolderEntryEditor thread and thumbnail manager thread. Don't remove this code as it's must to gracefully terminate the spawned thread from main threads.
300 FolderEntryEditorPresentationModel::GetInstance()->StopFolderEntryEditorThread();
301 ThumbnailManager::GetInstance()->StopThumbnailManagerThread();
303 InitializeListeners();
305 AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
310 MyFilesApp::OnForeground(void)
312 // Start or resume drawing when the application is moved to the foreground.
313 Frame* pCurrentFrame = null;
314 CustomAppControl::GetInstance()->SetAppControlInUse(null);
315 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
317 __bIsAppInBackground = false;
319 if (pCurrentFrame != null)
321 pCurrentFrame->SetEnabled(true);
324 if (__pCurrentListToUpdate != null && IsAppControlLaunched() == true)
326 AppLogDebug("OnAppControlCompleted Called");
327 __pCurrentListToUpdate->OnAppControlCompleted();
330 SetAppControlLaunched(false);
334 MyFilesApp::OnBackground(void)
336 AppLogDebug("ENTER");
337 __bIsAppInBackground = true;
338 if (__inputSource == APPCONTROL_STATE_SELECTED)
340 if (__pAudioNotificationListener != null)
342 __pAudioNotificationListener->OnAudioNotificationReceived();
345 AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
349 MyFilesApp::OnLowMemory(void)
351 //Empty Implementation
355 MyFilesApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
357 //Empty Implementation
361 MyFilesApp::OnScreenOn(void)
363 //Empty Implementation
367 MyFilesApp::OnScreenOff(void)
369 // Empty Implementation
372 MyFilesApp::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
374 AppLogDebug("ENTER");
375 ThumbRequest* pCurrentThumbReq = null;
379 case THUMBNAIL_LAODED:
380 case THUMBNAIL_FAILED:
382 if (__pCurrentListToUpdate == null)
386 pCurrentThumbReq = (ThumbRequest*) pArgs->GetAt(0);
387 if (pCurrentThumbReq != null && pCurrentThumbReq->pBitmap != null)
388 delete pCurrentThumbReq->pBitmap;
392 pArgs->RemoveAll(true);
402 pCurrentThumbReq = (ThumbRequest*) pArgs->GetAt(0);
403 __pCurrentListToUpdate->OnThumbnailReceived(pCurrentThumbReq);
407 pArgs->RemoveAll(true);
413 __pCurrentListToUpdate->OnThumbnailReceived(null);
418 case ID_COPY_COMPLETE:
419 case ID_FILE_RENAME_COMPLETE:
420 case ID_DELETE_COMPLETE:
421 case ID_MOVING_COMPLETE:
422 case ID_CREATE_FOLDER_COMPLETE:
423 case ID_FILE_MANAGING_FAILED:
424 case ID_FOLDER_SEARCH_STARTED:
425 case ID_SEARCH_COMPLETED:
426 case ID_SEARCH_RESULT_FOUND:
428 if (__pNotificationListener != null)
430 __pNotificationListener->OnNotificationReceived((Tizen::Base::Collection::ArrayList*) pArgs);
437 //Empty Implementation.
446 MyFilesApp::LaunchCacheManager(void)
448 //Empty Implementation
452 MyFilesApp::SetAppControlSelected(void)
454 __bAppControlEnabled = true;
458 MyFilesApp::ExtractType(Tizen::Base::String& inputType)
460 AppLogDebug("ENTER");
462 StringTokenizer strTok(inputType, L":");
464 while (strTok.HasMoreTokens())
467 strTok.GetNextToken(type);
469 AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
474 MyFilesApp::AddAppControlResult(Tizen::App::AppCtrlResult result)
476 AppLogDebug("ENTER");
477 if (__pResultList != null)
479 //if (result.CompareTo(APPCONTROL_RESULT_CANCELED) == 0)
480 if (result == APP_CTRL_RESULT_CANCELED)
482 FolderEntryEditorPresentationModel::GetInstance()->ClearCheckedList();
484 //__pResultList->Add(new (std::nothrow) String(result));
485 __currentAppControlResult = result;
487 AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
491 MyFilesApp::GetCurrentSelectionMode(void)
493 return __currentSelectionMode;
497 MyFilesApp::GetCurrentFileType(void)
499 return __currentFileType;
503 MyFilesApp::GetCurrentView(void)
505 return __currentView;
509 MyFilesApp::GetCurrentState(void)
511 return __inputSource;
515 MyFilesApp::GetCurrentExportFileType(void)
517 return __currentExportFileType;
521 MyFilesApp::SetNotifyListener(INotificationListener* listener)
523 __pNotificationListener = listener;
527 MyFilesApp::SetImageAppControlLanched(bool bAppControlLaunched)
529 __bImgAppControlLaunched = bAppControlLaunched;
533 MyFilesApp::IsImageAppControlLanched(void)
535 return __bImgAppControlLaunched;
539 MyFilesApp::SetCurrentView(IListViewStateChangeListener* pListToUpdate)
541 result res = E_SUCCESS;
542 __pCurrentListToUpdate = pListToUpdate;
546 IListViewStateChangeListener*
547 MyFilesApp::GetCurrentViewToUpdate(void)
549 return __pCurrentListToUpdate;
554 MyFilesApp::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData)
556 __bAppControlEnabled = false;
557 __currentRequestId = reqId;
558 __operationId.Clear();
559 __operationId.Append(operationId);
561 if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/pick") == 0)
564 const String* inputSelectionType = null;
565 const String* inputFileType = null;
567 __bAppControlMode = true;
569 if (pMimeType != null)
571 inputFileType = pMimeType;
573 __mimeType.Append(*pMimeType);
576 if (pExtraData != null)
578 inputSelectionType = static_cast< const String* >(pExtraData->GetValue(String(L"http://tizen.org/appcontrol/data/selection_mode")));
581 if (__pResultList == null)
583 __pResultList = new (std::nothrow) HashMap();
584 __pResultList->Construct();
587 __inputSource = APPCONTROL_STATE_SELECTED;
589 if (inputFileType != null)
591 if (inputFileType->CompareTo("*/*") == 0)
593 __currentFileType = FILE_TYPE_ALL;
595 else if (inputFileType->CompareTo("image/*") == 0)
597 __currentFileType = FILE_TYPE_IMAGE_TYPE;
599 else if (inputFileType->CompareTo("audio/*") == 0)
601 __currentFileType = FILE_TYPE_AUDIO_TYPE;
603 else if (inputFileType->CompareTo("video/*") == 0)
605 __currentFileType = FILE_TYPE_VIDEO_TYPE;
607 else if (inputFileType->CompareTo("contacts") == 0)
609 __currentFileType = FILE_TYPE_CONTACTS_TYPE;
611 else if(inputFileType->CompareTo("inode/directory") == 0)
613 __currentFileType = FILE_TYPE_ALL;
614 __currentView = APPCONTROL_VIEW_EXPORT;
618 __currentFileType = FILE_TYPE_ALL;
623 __currentFileType = FILE_TYPE_ALL;
626 if (inputSelectionType != null)
628 if (inputSelectionType->CompareTo("single") == 0)
630 __currentSelectionMode = SELECTION_MODE_SINGE;
632 else if (inputSelectionType->CompareTo("multiple") == 0)
634 __currentSelectionMode = SELECTION_MODE_MULTIPLE;
639 __currentSelectionMode = SELECTION_MODE_SINGE;
644 if (__inputSource == APPCONTROL_STATE_SELECTED)
646 SceneManager* pSceneManager = null;
647 pSceneManager = SceneManager::GetInstance();
649 if (pSceneManager != null && __currentView != APPCONTROL_VIEW_IMPORT)
651 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM), null);
652 //pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_MOST_SELECTION_FORM));
655 else if (pSceneManager != null && __currentView == APPCONTROL_VIEW_IMPORT)
657 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_MOST_SELECTION_FORM), null);
659 else if (pSceneManager != null && __currentView == APPCONTROL_VIEW_EXPORT)
661 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_FOLDER_SELECTION_FORM), null);
668 MyFilesApp::InitializeListeners(void)
670 __pCurrentListToUpdate = null;
671 __pNotificationListener = null;
674 MyFilesApp::OnSettingChanged(Tizen::Base::String& key)
676 AppLogDebug("SettingChanged:%S", key.GetPointer());
677 AppRegistry* pAppRegistry = null;
678 result r = E_SUCCESS;
680 String languageSettingKey = L"http://tizen.org/setting/locale.language";
681 String languageSelected;
683 String timeFormatKeyName(L"TimeFormat");
684 String timeFormatSettingSelected;
685 String timeFormatSettingKey = L"http://tizen.org/setting/locale.date_time.format";
686 TimeFormat timeFormatSelected = TIME_FORMAT_NONE;
688 if ( key.CompareTo(languageSettingKey) == 0 )
690 SettingInfo::GetValue(languageSettingKey, languageSelected);
692 if ( __currentDisplayLanguage.CompareTo(languageSelected) !=0)
694 Application::Terminate();
697 else if (key.CompareTo(timeFormatSettingKey) == 0)
699 SettingInfo::GetValue(timeFormatSettingKey, timeFormatSettingSelected);
700 pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
702 if (timeFormatSettingSelected.CompareTo(IDB_DATETIME_24HR) == 0)
704 timeFormatSelected = TIME_FORMAT_24_HOUR;
706 else if (timeFormatSettingSelected.CompareTo(IDB_DATETIME_12HR) == 0)
708 timeFormatSelected = TIME_FORMAT_12_HOUR;
710 r = pAppRegistry->Set(timeFormatKeyName, timeFormatSelected);
713 r = pAppRegistry->Save();
715 __pCurrentListToUpdate->OnSettingValueChanged();
717 AppLogDebug("SettingChanged--");
720 MyFilesApp::IsAppControlMode(void)
722 return __bAppControlMode;
726 MyFilesApp::SetAudioNotificationListener(IAudioNotificationListener* listener)
728 __pAudioNotificationListener = listener;
732 MyFilesApp::SetCurrentScene(const Tizen::Ui::Scenes::SceneId& currentScene, const Tizen::Ui::Scenes::SceneId& previousScene)
734 __currentSceneId = currentScene;
735 __previousSceneId = previousScene;
737 if ( __pCurrentListToUpdate )
738 __pCurrentListToUpdate->OnSceneIdChanged(__currentSceneId, __previousSceneId);
742 MyFilesApp::IsAppInBackground(void)
744 return __bIsAppInBackground;
748 MyFilesApp::SetAppControlLaunched(bool isAppControlLaunched)
750 AppLogDebug("Enter : %d", isAppControlLaunched);
751 __IsAppControlLaunched = isAppControlLaunched;
755 MyFilesApp::IsAppControlLaunched(void)
757 AppLogDebug("Enter");
758 return __IsAppControlLaunched;