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 MpPlaylistCreatorForm.cpp
19 * @brief This is the implementation file for PlaylistCreatorForm class.
22 #include "MpAllListPresentationModel.h"
23 #include "MpAlbumListPresentationModel.h"
24 #include "MpArtistListPresentationModel.h"
25 #include "MpFolderListPresentationModel.h"
26 #include "MpCommonUtil.h"
27 #include "MpPlaylistCreatorForm.h"
28 #include "MpPlaylistEditorPresentationModel.h"
29 #include "MpPlaylistListPresentationModel.h"
30 #include "MpResourceManager.h"
31 #include "MpSceneRegister.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Content;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Media;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Scenes;
43 PlaylistCreatorForm::PlaylistCreatorForm(void)
44 : __pPlaylistEditorPresentationModel(null)
45 , __pPlaylistEditField(null)
47 , __previousSceneId(L"")
53 PlaylistCreatorForm::~PlaylistCreatorForm(void)
60 PlaylistCreatorForm::Initialize(void)
63 Form::Construct(IDL_PLAYLIST_CREATOR_FORM);
68 PlaylistCreatorForm::OnInitializing(void)
71 __pPlaylistEditField = static_cast<EditField*>(GetControl(IDC_EDITFIELD));
72 __pPlaylistEditField->AddTextEventListener(*this);
73 __pPlaylistEditField->AddKeypadEventListener(*this);
74 __pPlaylistEditField->SetOverlayKeypadCommandButtonVisible(false);
75 __pPlaylistEditField->SetFocus();
76 __pPlaylistEditorPresentationModel = PlaylistEditorPresentationModel::GetInstance();
78 SetFormBackEventListener(this);
79 if (GetFooter() != null)
81 GetFooter()->AddActionEventListener(*this);
88 PlaylistCreatorForm::OnTerminating(void)
91 if (__pDataList != null)
93 __pDataList->RemoveAll(true);
101 PlaylistCreatorForm::OnKeypadActionPerformed(Tizen::Ui::Control& source,
102 Tizen::Ui::KeypadAction keypadAction)
104 AppLogDebug("ENTER");
109 PlaylistCreatorForm::OnKeypadClosed(Tizen::Ui::Control& source)
111 AppLogDebug("ENTER");
116 PlaylistCreatorForm::OnKeypadOpened(Tizen::Ui::Control& source)
118 AppLogDebug("ENTER");
123 PlaylistCreatorForm::OnKeypadWillOpen(Tizen::Ui::Control &source)
125 AppLogDebug("ENTER");
130 PlaylistCreatorForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
131 const Tizen::Ui::Scenes::SceneId& currentSceneId,
132 Tizen::Base::Collection::IList* pArgs)
134 AppLogDebug("ENTER");
135 String PlayListName = ResourceManager::GetString(L"IDS_MP_HEADER_MENU_PLAYLIST");
136 PlayListName.Append(L"_");
137 ArrayList* pNumberList = new (std::nothrow) ArrayList();
138 pNumberList->Construct();
140 int numericPlaylist = 1;
141 int totalPlaylistCount = __pPlaylistEditorPresentationModel->GetAllPlayListCount();
142 __previousSceneId = previousSceneId;
143 AppLogDebug("%d", totalPlaylistCount);
145 if (totalPlaylistCount != 0)
148 for (int i = 0; i < totalPlaylistCount; i++)
150 String currentPlayListName = __pPlaylistEditorPresentationModel->GetPlayListName(i);
151 if (currentPlayListName.GetLength() >= PlayListName.GetLength())
154 currentPlayListName.SubString(0, PlayListName.GetLength(), compareStr);
155 if (compareStr.Equals(PlayListName, true))
159 for (int index = currentPlayListName.GetLength()-1; index >= 0; index--)
161 currentPlayListName.GetCharAt(index, ch);
162 if (Character::IsDigit(ch))
168 currentPlayListName.SubString(index + 1, currentPlayListName.GetLength() - (index + 1), pLastStr);
173 if (pLastStr != null)
175 Integer::Parse(pLastStr, lastNum);
176 pNumberList->Add((new (std::nothrow) Integer(lastNum)));
181 if (pNumberList != null)
183 int pNumberListCount = pNumberList->GetCount();
184 IntegerComparer integerComparer;
185 pNumberList->Sort(integerComparer);
186 for (int index = 0; index < pNumberListCount; index++)
188 if (static_cast<Integer*>(pNumberList->GetAt(0))->ToInt() != 1)
194 int secondNumber = 0;
196 firstNumber = static_cast<Integer*>(pNumberList->GetAt(index))->ToInt();
197 if (index + 1 < pNumberListCount)
199 secondNumber = static_cast<Integer*>(pNumberList->GetAt(index + 1))->ToInt();
202 if (firstNumber + 1 < secondNumber)
204 numericPlaylist = firstNumber + 1;
209 numericPlaylist = firstNumber + 1;
213 PlayListName.Append(numericPlaylist);
214 if (__pPlaylistEditField->GetTextLength() == 0)
216 __pPlaylistEditField->SetText(PlayListName);
221 PlayListName.Append(numericPlaylist);
222 if (__pPlaylistEditField->GetTextLength() == 0)
224 __pPlaylistEditField->SetText(PlayListName);
228 __pPlaylistEditField->ShowKeypad();
230 if (pNumberList != null)
232 pNumberList->RemoveAll(true);
243 PlaylistCreatorForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
244 const Tizen::Ui::Scenes::SceneId& nextSceneId)
246 AppLogDebug("ENTER");
251 PlaylistCreatorForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
253 AppLogDebug("ENTER");
254 SceneManager* pSceneManager = SceneManager::GetInstance();
255 AppAssert(pSceneManager);
256 result r = E_FAILURE;
257 ArrayList* pList = null;
261 case IDA_FOOTER_BUTTON_SAVE:
263 String inputString = __pPlaylistEditField->GetText();
265 __pPlaylistEditField->HideKeypad();
266 if (inputString.GetLength() == 0)
268 MessageBox messageBox;
269 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_MUSIC_POP_UNABLE_CREATE_PLAYLIST"), MSGBOX_STYLE_NONE, 3000);
271 messageBox.ShowAndWait(modalResult);
272 __pPlaylistEditField->SetFocus();
273 __pPlaylistEditField->ShowKeypad();
277 r = __pPlaylistEditorPresentationModel->SetPlayListName(L"", inputString);
280 MessageBox messageBox;
281 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_MUSIC_POP_UNABLE_CREATE_PLAYLIST"), MSGBOX_STYLE_NONE, 3000);
283 messageBox.ShowAndWait(modalResult);
284 __pPlaylistEditField->SetFocus();
285 __pPlaylistEditField->ShowKeypad();
289 if (__pDataList != null)
291 for (int index = 0; index < __pDataList->GetCount(); index++)
293 ContentId contentId = CommonUtil::GetContentId(*(static_cast<String*>(__pDataList->GetAt(index))));
294 if (!IsFailed(GetLastResult()))
296 __pPlaylistEditorPresentationModel->AddItem(contentId, inputString);
306 MessageBox messageBox;
307 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_MUSIC_POP_UNABLE_TO_ADD"),
311 messageBox.ShowAndWait(modalResult);
318 MessageBox messageBox;
319 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_SUCCESS"),
323 messageBox.ShowAndWait(modalResult);
324 if (!__previousSceneId.Equals(IDSCN_PLAYER,true))
326 pList = new (std::nothrow) ArrayList();
328 pList->Add(new (std::nothrow) Integer(1));
333 __pPlaylistEditorPresentationModel->RemovePlayList(inputString);
336 if (__previousSceneId.Equals(IDSCN_PLAYER, true))
338 pSceneManager->GoBackward(BackwardSceneTransition());
342 pSceneManager->GoBackward(BackwardSceneTransition(), pList);
347 ArrayList* pList = new (std::nothrow) ArrayList();
349 AllListPresentationModel* pPresentationModel = AllListPresentationModel::GetInstance();
350 if (pPresentationModel->GetTotalCount() == 0)
352 pSceneManager->GoBackward(BackwardSceneTransition(), pList);
356 CommonUtil::SetAddtoPlaylistState(true);
357 CommonUtil::SetAddtoPlaylistName(inputString);
358 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_CONTENT_PICKER,
359 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY));
372 PlaylistCreatorForm::OnTextValueChanged(const Tizen::Ui::Control& source)
374 AppLogDebug("ENTER");
375 Footer* pFooter = GetFooter();
376 EditArea* pEditArea = const_cast<EditArea*>(static_cast<const EditArea*>(&source));
377 String editareaString = pEditArea->GetText();
378 if (editareaString.GetLength() == INIT_VALUE)
382 CommonUtil::SetFooterItemEnabled(*pFooter, false);
389 CommonUtil::SetFooterItemEnabled(*pFooter, true);
396 PlaylistCreatorForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
398 AppLogDebug("ENTER");
403 PlaylistCreatorForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
405 AppLogDebug("ENTER");
406 SceneManager* pSceneManager = SceneManager::GetInstance();
407 pSceneManager->GoBackward(BackwardSceneTransition());
412 PlaylistCreatorForm::OnMusicContentUpdateCompleted(void)
414 AppLogDebug("ENTER");
415 int validContents = 0;
416 int totalContents = 0;
417 SceneManager* pSceneManager = SceneManager::GetInstance();
419 if (pSceneManager != null && pSceneManager->GetCurrentSceneId().Equals(IDSCN_PLAYLIST_CREATOR,true))
421 if (__pDataList != null && __pDataList->GetCount())
423 totalContents = __pDataList->GetCount();
425 for (int pathIndex = 0; pathIndex < __pDataList->GetCount(); pathIndex++)
427 ContentId contentId = CommonUtil::GetContentId(*(static_cast<String*>(__pDataList->GetAt(pathIndex))));
429 if (IsFailed(GetLastResult()))
444 if ( validContents == 0)
446 IListT<SceneId>* pSceneList = pSceneManager->GetSceneHistoryN();
447 if(pSceneList != null)
449 if (pSceneList->GetCount() > 1)
451 pSceneManager->ClearSceneHistory();
452 for(int sceneIndex = 0; sceneIndex < pSceneList->GetCount(); sceneIndex++)
455 pSceneList->GetAt(sceneIndex,scenId);
457 if ((sceneIndex == pSceneList->GetCount()-1) && (__previousSceneId.Equals(IDSCN_ALBUM_CONTENT_LIST,true)
458 || __previousSceneId.Equals(IDSCN_FOLDER_CONTENT_LIST,true)
459 || __previousSceneId.Equals(IDSCN_ARTIST_CONTENT_LIST,true)))
461 pSceneManager->DestroyScene(scenId);
463 else if ((sceneIndex == pSceneList->GetCount()-1)
464 && (__previousSceneId.Equals(IDSCN_ALBUM_LIST_EDITOR,true)))
466 AlbumListPresentationModel* pListPresentationModel = AlbumListPresentationModel::GetInstance();
467 if (pListPresentationModel->GetAllAlbumCount() == 0)
469 pSceneManager->DestroyScene(scenId);
472 else if ((sceneIndex == pSceneList->GetCount()-1)
473 && (__previousSceneId.Equals(IDSCN_ARTIST_LIST_EDITOR,true)))
475 ArtistListPresentationModel* pListPresentationModel = ArtistListPresentationModel::GetInstance();
476 if (pListPresentationModel->GetArtistListCount() == 0)
478 pSceneManager->DestroyScene(scenId);
481 else if ((sceneIndex == pSceneList->GetCount()-1)
482 && (__previousSceneId.Equals(IDSCN_FOLDER_LIST_EDITOR,true)))
484 FolderListPresentationModel* pListPresentationModel = FolderListPresentationModel::GetInstance();
485 if (pListPresentationModel->GetAllFolderCount() ==0)
487 pSceneManager->DestroyScene(scenId);
490 else if ((sceneIndex == pSceneList->GetCount()-1)
491 && (__previousSceneId.Equals(IDSCN_ALL_LIST_EDITOR,true)))
493 AllListPresentationModel* pListPresentationModel = AllListPresentationModel::GetInstance();
494 if (pListPresentationModel->GetTotalCount() ==0)
496 pSceneManager->DestroyScene(scenId);
499 else if ((sceneIndex == pSceneList->GetCount()-1)
500 && (__previousSceneId.Equals(IDSCN_PLAYLIST_CONTENT_LIST,true)))
502 PlaylistListPresentationModel* pListPresentationModel = PlaylistListPresentationModel::GetInstance();
503 if (pListPresentationModel->GetContentCount() ==0)
505 pSceneManager->DestroyScene(scenId);
510 pSceneManager->AddToSceneHistory(scenId);
517 if (totalContents != 0 && totalContents > validContents)
519 if (!__previousSceneId.Equals(IDSCN_PLAYLIST_LIST,true))
521 pSceneManager->GoBackward(BackwardSceneTransition());