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 MpMusicPlayerApp.cpp
19 * @brief This is the implementation file for MusicPlayerApp class.
22 #include <FGraphics.h>
23 #include "MpBaseForm.h"
24 #include "MpBasePanel.h"
25 #include "MpCommonUtil.h"
26 #include "MpIMusicContentUpdateEventListner.h"
27 #include "MpMusicPlayerApp.h"
28 #include "MpMusicPlayerForm.h"
29 #include "MpResourceManager.h"
30 #include "MpSceneRegister.h"
31 #include "MpThumbnailProvider.h"
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Content;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::System;
41 using namespace Tizen::Ui;
42 using namespace Tizen::Ui::Controls;
43 using namespace Tizen::Ui::Scenes;
45 const wchar_t* TIZEN_APPCONTORL_PROVIDER_AUDIO = L"http://tizen.org/appcontrol/provider/musicplayer";
46 const wchar_t* TIZEN_APPCONTROL_OPERATION_PLAY = L"http://tizen.org/appcontrol/operation/play";
47 const wchar_t* TIZEN_APPCONTROL_OPERATION_VIEW = L"http://tizen.org/appcontrol/operation/view";
48 const wchar_t* TIZEN_APPCONTROL_OPERATION_CONFIGURE = L"http://tizen.org/appcontrol/operation/configure";
49 //const static Tizen::Base::String APPCONTROL_KEYFIELD_PATH = L"path";
50 static const wchar_t* PARAM_LANGUAGE = L"http://tizen.org/setting/locale.language";
51 static const wchar_t* PARAM_COUNTRY = L"http://tizen.org/setting/locale.country";
53 static const int TIMER_CONTENT_UPDATE_DELAY = 500;
55 MusicPlayerApp::MusicPlayerApp(void)
58 , __sceneId(IDSCN_ALL_LIST)
61 , __pContentManager(null)
62 , __pContentUpdateCompleteTimer(null)
63 , __pContentUpdateInProgressPopup(null)
69 MusicPlayerApp::~MusicPlayerApp(void)
76 MusicPlayerApp::CreateInstance(void)
80 return new (std::nothrow) MusicPlayerApp();
84 MusicPlayerApp::OnAppInitializing(AppRegistry& appRegistry)
88 AppControlProviderManager* pAppControlProviderManager = null;
90 CommonUtil::SetValue(AUTO_OFF_LEVEL, 0);
92 pAppControlProviderManager = AppControlProviderManager::GetInstance();
93 TryCatch(pAppControlProviderManager != null, r = E_OBJ_NOT_FOUND, "Failed to get AppControlProviderManager");
95 r = pAppControlProviderManager->SetAppControlProviderEventListener(this);
96 TryCatch(r == E_SUCCESS, , "Failed SetAppControlProviderEventListener");
102 //AppLogException("[%s]",GetErrorMessage(r));
107 MusicPlayerApp::OnAppInitialized(void)
109 AppLogDebug("ENTER");
110 result r = E_SUCCESS;
111 __pMainFrame = new (std::nothrow) MainFrame();
112 if (__pMainFrame == null)
118 __pContentManager = new (std::nothrow) ContentManager();
119 r = __pContentManager->Construct();
120 TryCatch(r == E_SUCCESS, r = E_FAILURE, "AddFrame failed.\n");
122 __pContentManager->AddContentUpdateEventListener(*this);
124 __pContentUpdateCompleteTimer = new (std::nothrow) Timer();
125 r = __pContentUpdateCompleteTimer->Construct(*this);
126 TryCatch(r == E_SUCCESS, r = E_FAILURE, "AddFrame failed.\n");
128 __pMainFrame->Construct();
129 r = AddFrame(*__pMainFrame);
130 TryCatch(r == E_SUCCESS, r = E_FAILURE, "AddFrame failed.\n");
132 SettingInfo::AddSettingEventListener(*this);
134 if (__sceneId.IsEmpty())
136 __sceneId = IDSCN_ALL_LIST;
138 r = __pMainFrame->GoToInitialScene(__sceneId, __pDataList);
148 delete __pContentUpdateCompleteTimer;
149 __pContentUpdateCompleteTimer = null;
150 delete __pContentManager;
151 __pContentManager = null;
153 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
158 MusicPlayerApp::OnAppWillTerminate(void)
160 AppLogDebug("ENTER");
161 if (__pContentManager != null)
163 __pContentManager->RemoveContentUpdateEventListener(*this);
166 if (__pContentUpdateCompleteTimer != null)
168 __pContentUpdateCompleteTimer->Cancel();
175 MusicPlayerApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
177 AppLogDebug("ENTER");
178 CommonUtil::SetValue(AUTO_OFF_LEVEL, 0);
179 /*if (__operationId.Equals(TIZEN_APPCONTROL_OPERATION_PLAY, true)
180 || __operationId.Equals(TIZEN_APPCONTROL_OPERATION_VIEW, true)
181 || __operationId.Equals(TIZEN_APPCONTROL_OPERATION_CONFIGURE, true))
183 AppControlProviderManager::GetInstance()->SendAppControlResult(__requestId, APP_CTRL_RESULT_TERMINATED, null);
185 ThumbnailProvider* pThumbnailProvider = dynamic_cast<ThumbnailProvider*>(ThumbnailProvider::GetInstance());
186 if (pThumbnailProvider != null)
188 pThumbnailProvider->Quit();
189 pThumbnailProvider->Join();
190 pThumbnailProvider->DestroyInstance();
193 delete __pContentUpdateCompleteTimer;
194 __pContentUpdateCompleteTimer = null;
195 delete __pContentManager;
196 __pContentManager = null;
203 MusicPlayerApp::OnForeground(void)
205 AppLogDebug("ENTER");
210 MusicPlayerApp::OnBackground(void)
212 AppLogDebug("ENTER");
213 Frame* pFrame = GetFrameAt(0);
216 if (pFrame->IsEnabled() == false)
218 pFrame->SetEnabled(true);
219 pFrame->Invalidate(true);
225 MusicPlayerApp::OnLowMemory(void)
227 AppLogDebug("ENTER");
232 MusicPlayerApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
234 AppLogDebug("ENTER");
239 MusicPlayerApp::OnScreenOn(void)
241 AppLogDebug("ENTER");
246 MusicPlayerApp::OnScreenOff(void)
248 AppLogDebug("ENTER");
253 MusicPlayerApp::OnSettingChanged(Tizen::Base::String& key)
255 AppLogDebug("ENTER");
256 if (key.Equals(PARAM_LANGUAGE, true) || key.Equals(PARAM_COUNTRY, true))
258 UiApp* pApp = UiApp::GetInstance();
265 MusicPlayerApp::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData,
266 const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData)
268 AppLogDebug("ENTER");
269 // result r = E_SUCCESS;
270 // TryCatch(__pDataList == null, r = E_OBJ_ALREADY_EXIST, "The application has already launched");
273 __operationId = operationId;
275 if (operationId.Equals(TIZEN_APPCONTROL_OPERATION_PLAY, true) || operationId.Equals(TIZEN_APPCONTROL_OPERATION_VIEW, true))
277 ParsingArgument(pUriData, pExtraData);
278 __sceneId = IDSCN_PLAYER;
280 else if (operationId.Equals(TIZEN_APPCONTROL_OPERATION_CONFIGURE, true))
282 __sceneId = IDSCN_MUSIC_SETTING;
286 __sceneId = IDSCN_ALL_LIST;
289 if (__pMainFrame != null)
291 SceneManager* pSceneManager = SceneManager::GetInstance();
292 AppAssert(pSceneManager);
294 result r = E_FAILURE;
295 SceneId currentSceneId = pSceneManager->GetCurrentSceneId();
296 if (__sceneId.Equals(IDSCN_PLAYER, false))
299 Scene* pScene = pSceneManager->GetCurrentScene();
300 PlayerForm* pPlayerForm = static_cast<PlayerForm*>(pScene->GetForm());
301 if (currentSceneId.Equals(IDSCN_PLAYER, false))
303 pPlayerForm->OnChangedContentListByAppControlN(__pDataList);
306 else if(pSceneManager->IsSceneAlive(IDSCN_PLAYER) && currentSceneId.Equals(IDSCN_CONTENT_DETAIL, false))
308 r = pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_PLAYER), __pDataList);
312 r = __pMainFrame->GoToInitialScene(__sceneId, __pDataList);
317 r = __pMainFrame->GoToInitialScene(__sceneId, __pDataList);
330 MusicPlayerApp::ParsingArgument(const Tizen::Base::String* pUriData, const Tizen::Base::Collection::IMap* pArgs)
332 AppLogDebug("ENTER");
333 // const String* pContentPath = null;
336 if (pUriData != null)
338 String original(L"file://");
341 sourceStr.Append(*pUriData);
342 sourceStr.Replace(original, replace);
343 // pContentPath = &sourceStr;
345 if (__pDataList != null)
347 __pDataList->RemoveAll();
351 __pDataList = new (std::nothrow) ArrayList();
352 __pDataList->Construct();
354 ArrayList* pContentPathArrayList = new (std::nothrow) ArrayList();
355 pContentPathArrayList->Construct();
357 AppLogDebug("sourceStr : %ls", sourceStr.GetPointer());
358 pContentPathArrayList->Add((new (std::nothrow) String(sourceStr)));
360 __pDataList->Add(pContentPathArrayList);
361 __pDataList->Add(new (std::nothrow) Integer(0));
364 /*For multiple file path*/
366 /* else if (pArgs != null && pArgs->GetCoun__pDataListt() > 0)
368 pContentPath = static_cast<const String*>(pArgs->GetValue(APPCONTROL_KEYFIELD_PATH));
375 ArrayList* pContentPathArrayList = new (std::nothrow) ArrayList();
376 pContentPathArrayList->Construct();
378 if (pContentPath != null)
383 AppLogDebug("pContentPath : %ls", pContentPath->GetPointer());
385 if (__pDataList == null)
387 __pDataList = new (std::nothrow) ArrayList();
388 __pDataList->Construct();
392 __pDataList->RemoveAll(true);
395 Tizen::Base::Utility::StringTokenizer PathStringTokenizer(*pContentPath, delim);
397 while (PathStringTokenizer.HasMoreTokens())
399 PathStringTokenizer.GetNextToken(token);
400 // if (File::IsFileExist(token))
402 AppLogDebug("token : %ls", token.GetPointer());
403 pContentPathArrayList->Add((new (std::nothrow) String(token)));
406 __pDataList->Add(pContentPathArrayList);
407 __pDataList->Add(*(new (std::nothrow) Integer(0)));
414 MusicPlayerApp::GetOperationId(void)
416 AppLogDebug("ENTER");
418 return __operationId;
422 MusicPlayerApp::GetRequestId(void)
428 MusicPlayerApp::ResetRequestId(void)
434 MusicPlayerApp::OnContentFileCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
436 AppLogDebug("ENTER");
437 if (contentType == CONTENT_TYPE_AUDIO && !IsFailed(r))
439 ReStartContentUpdateTimer();
445 MusicPlayerApp::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
447 AppLogDebug("ENTER");
448 if (contentType == CONTENT_TYPE_AUDIO && !IsFailed(r))
450 ReStartContentUpdateTimer();
456 MusicPlayerApp::OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
458 AppLogDebug("ENTER");
459 if (contentType == CONTENT_TYPE_AUDIO && !IsFailed(r))
461 ReStartContentUpdateTimer();
467 MusicPlayerApp::OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r)
469 AppLogDebug("ENTER");
472 ReStartContentUpdateTimer();
478 MusicPlayerApp::ReStartContentUpdateTimer(void)
480 AppLogDebug("ENTER");
481 if (__pContentUpdateCompleteTimer != null)
483 __pContentUpdateCompleteTimer->Cancel();
484 __pContentUpdateCompleteTimer->Start(TIMER_CONTENT_UPDATE_DELAY);
485 ShowContentUpdateInProgressPopup();
491 MusicPlayerApp::ShowContentUpdateInProgressPopup(void)
493 AppLogDebug("ENTER");
494 if (__pContentUpdateInProgressPopup != null)
500 __pContentUpdateInProgressPopup = new (std::nothrow) Popup();
501 result r = __pContentUpdateInProgressPopup->Construct(IDL_CONTENTS_UPDATE_POPUP);
504 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
505 delete __pContentUpdateInProgressPopup;
509 __pContentUpdateInProgressPopup->SetShowState(true);
510 __pContentUpdateInProgressPopup->Show();
515 MusicPlayerApp::HideContentUpdateInProgressPopup(void)
517 AppLogDebug("ENTER");
518 if (__pContentUpdateInProgressPopup == null)
524 __pContentUpdateInProgressPopup->SetShowState(false);
525 delete __pContentUpdateInProgressPopup;
526 __pContentUpdateInProgressPopup = null;
531 MusicPlayerApp::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
533 AppLogDebug("ENTER");
534 if (__pContentUpdateCompleteTimer != &timer)
536 AppLogDebug("EXIT(UnKnown Timer)");
540 CallOnMusicContentUpdateCompleted();
541 HideContentUpdateInProgressPopup();
546 MusicPlayerApp::CallOnMusicContentUpdateCompleted(void)
548 AppLogDebug("ENTER");
549 UiApp* pApp = UiApp::GetInstance();
552 if (pApp->GetAppUiState() == APP_UI_STATE_FOREGROUND || pApp->GetAppUiState() == APP_UI_STATE_PARTIAL_BACKGROUND)
554 SceneManager* pSceneManager = SceneManager::GetInstance();
555 AppAssert(pSceneManager);
557 IMusicContentUpdateEventListner* pEventListner = dynamic_cast<IMusicContentUpdateEventListner*>(pSceneManager->GetCurrentScene()->GetForm());
558 if (pEventListner == null)
560 pEventListner = dynamic_cast<IMusicContentUpdateEventListner*>(pSceneManager->GetCurrentScene()->GetPanel());
563 if (pEventListner != null)
565 pEventListner->OnMusicContentUpdateCompleted();
572 int frameChildControlCount = __pMainFrame->GetControlCount();
573 for (int iCount = 0; iCount < frameChildControlCount; iCount++)
575 Form* pForm = dynamic_cast<Form*>(__pMainFrame->GetControl(iCount));
581 IMusicContentUpdateEventListner* pEventListner = dynamic_cast<IMusicContentUpdateEventListner*>(pForm);
582 if (pEventListner != null)
584 pEventListner->OnMusicContentUpdateCompleted();
588 int formChildControlCount = pForm->GetControlCount();
589 for (int iCount = 0; iCount < formChildControlCount; iCount++)
591 IMusicContentUpdateEventListner* pEventListner = dynamic_cast<IMusicContentUpdateEventListner*>(pForm->GetControl(iCount));
592 if (pEventListner != null)
594 pEventListner->OnMusicContentUpdateCompleted();