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 "MpCommonUtil.h"
24 #include "MpPlaylistCreatorForm.h"
25 #include "MpPlaylistEditorPresentationModel.h"
26 #include "MpResourceManager.h"
27 #include "MpSceneRegister.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Content;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Media;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
39 PlaylistCreatorForm::PlaylistCreatorForm(void)
40 : __pPlaylistEditorPresentationModel(null)
41 , __pPlaylistEditField(null)
43 , __previousSceneId(L"")
49 PlaylistCreatorForm::~PlaylistCreatorForm(void)
56 PlaylistCreatorForm::Initialize(void)
59 Form::Construct(IDL_PLAYLIST_CREATOR_FORM);
64 PlaylistCreatorForm::OnInitializing(void)
67 __pPlaylistEditField = static_cast<EditField*>(GetControl(IDC_EDITFIELD));
68 __pPlaylistEditField->AddTextEventListener(*this);
69 __pPlaylistEditField->AddKeypadEventListener(*this);
70 __pPlaylistEditField->SetOverlayKeypadCommandButtonVisible(false);
71 __pPlaylistEditField->SetFocus();
72 __pPlaylistEditorPresentationModel = PlaylistEditorPresentationModel::GetInstance();
74 SetFormBackEventListener(this);
75 if (GetFooter() != null)
77 GetFooter()->AddActionEventListener(*this);
84 PlaylistCreatorForm::OnTerminating(void)
87 if (__pDataList != null)
89 __pDataList->RemoveAll(true);
97 PlaylistCreatorForm::OnKeypadActionPerformed(Tizen::Ui::Control& source,
98 Tizen::Ui::KeypadAction keypadAction)
100 AppLogDebug("ENTER");
105 PlaylistCreatorForm::OnKeypadClosed(Tizen::Ui::Control& source)
107 AppLogDebug("ENTER");
112 PlaylistCreatorForm::OnKeypadOpened(Tizen::Ui::Control& source)
114 AppLogDebug("ENTER");
119 PlaylistCreatorForm::OnKeypadWillOpen(Tizen::Ui::Control &source)
121 AppLogDebug("ENTER");
126 PlaylistCreatorForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
127 const Tizen::Ui::Scenes::SceneId& currentSceneId,
128 Tizen::Base::Collection::IList* pArgs)
130 AppLogDebug("ENTER");
131 String PlayListName = ResourceManager::GetString(L"IDS_MP_HEADER_MENU_PLAYLIST");
132 PlayListName.Append(L"_");
133 ArrayList* pNumberList = new (std::nothrow) ArrayList();
134 pNumberList->Construct();
136 int numericPlaylist = 1;
137 int totalPlaylistCount = __pPlaylistEditorPresentationModel->GetAllPlayListCount();
138 __previousSceneId = previousSceneId;
139 AppLogDebug("%d", totalPlaylistCount);
141 if (totalPlaylistCount != 0)
144 for (int i = 0; i < totalPlaylistCount; i++)
146 String currentPlayListName = __pPlaylistEditorPresentationModel->GetPlayListName(i);
147 if (currentPlayListName.GetLength() >= PlayListName.GetLength())
150 currentPlayListName.SubString(0, PlayListName.GetLength(), compareStr);
151 if (compareStr.Equals(PlayListName, true))
155 for (int index = currentPlayListName.GetLength()-1; index >= 0; index--)
157 currentPlayListName.GetCharAt(index, ch);
158 if (Character::IsDigit(ch))
164 currentPlayListName.SubString(index + 1, currentPlayListName.GetLength() - (index + 1), pLastStr);
169 if (pLastStr != null)
171 Integer::Parse(pLastStr, lastNum);
172 pNumberList->Add((new (std::nothrow) Integer(lastNum)));
177 if (pNumberList != null)
179 int pNumberListCount = pNumberList->GetCount();
180 IntegerComparer integerComparer;
181 pNumberList->Sort(integerComparer);
182 for (int index = 0; index < pNumberListCount; index++)
184 if (static_cast<Integer*>(pNumberList->GetAt(0))->ToInt() != 1)
190 int secondNumber = 0;
192 firstNumber = static_cast<Integer*>(pNumberList->GetAt(index))->ToInt();
193 if (index + 1 < pNumberListCount)
195 secondNumber = static_cast<Integer*>(pNumberList->GetAt(index + 1))->ToInt();
198 if (firstNumber + 1 < secondNumber)
200 numericPlaylist = firstNumber + 1;
205 numericPlaylist = firstNumber + 1;
209 PlayListName.Append(numericPlaylist);
210 if (__pPlaylistEditField->GetTextLength() == 0)
212 __pPlaylistEditField->SetText(PlayListName);
217 PlayListName.Append(numericPlaylist);
218 if (__pPlaylistEditField->GetTextLength() == 0)
220 __pPlaylistEditField->SetText(PlayListName);
224 __pPlaylistEditField->ShowKeypad();
226 if (pNumberList != null)
228 pNumberList->RemoveAll(true);
239 PlaylistCreatorForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
240 const Tizen::Ui::Scenes::SceneId& nextSceneId)
242 AppLogDebug("ENTER");
247 PlaylistCreatorForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
249 AppLogDebug("ENTER");
250 SceneManager* pSceneManager = SceneManager::GetInstance();
251 AppAssert(pSceneManager);
252 result r = E_FAILURE;
253 ArrayList* pList = null;
257 case IDA_FOOTER_BUTTON_SAVE:
259 String inputString = __pPlaylistEditField->GetText();
261 __pPlaylistEditField->HideKeypad();
262 if (inputString.GetLength() == 0)
264 MessageBox messageBox;
265 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_MUSIC_POP_UNABLE_CREATE_PLAYLIST"), MSGBOX_STYLE_NONE, 3000);
267 messageBox.ShowAndWait(modalResult);
268 __pPlaylistEditField->SetFocus();
269 __pPlaylistEditField->ShowKeypad();
273 r = __pPlaylistEditorPresentationModel->SetPlayListName(null, inputString);
276 MessageBox messageBox;
277 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_MUSIC_POP_UNABLE_CREATE_PLAYLIST"), MSGBOX_STYLE_NONE, 3000);
279 messageBox.ShowAndWait(modalResult);
280 __pPlaylistEditField->SetFocus();
281 __pPlaylistEditField->ShowKeypad();
285 if (__pDataList != null)
287 for (int index = 0; index < __pDataList->GetCount(); index++)
289 ContentId contentId = CommonUtil::GetContentId(*(static_cast<String*>(__pDataList->GetAt(index))));
290 if (!IsFailed(GetLastResult()))
292 __pPlaylistEditorPresentationModel->AddItem(contentId, inputString);
297 MessageBox messageBox;
298 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_MUSIC_POP_UNABLE_TO_ADD"),
302 messageBox.ShowAndWait(modalResult);
309 MessageBox messageBox;
310 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_SUCCESS"),
314 messageBox.ShowAndWait(modalResult);
315 pList = new (std::nothrow) ArrayList();
317 pList->Add(new (std::nothrow) Integer(1));
321 __pPlaylistEditorPresentationModel->RemovePlayList(inputString);
324 pSceneManager->GoBackward(BackwardSceneTransition(),pList);
328 AllListPresentationModel* pPresentationModel = AllListPresentationModel::GetInstance();
329 if (pPresentationModel->GetTotalCount() == 0)
331 pSceneManager->GoBackward(BackwardSceneTransition());
335 CommonUtil::SetAddtoPlaylistState(true);
336 CommonUtil::SetAddtoPlaylistName(inputString);
337 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_CONTENT_PICKER,
338 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY));
351 PlaylistCreatorForm::OnTextValueChanged(const Tizen::Ui::Control& source)
353 AppLogDebug("ENTER");
354 Footer* pFooter = GetFooter();
355 EditArea* pEditArea = const_cast<EditArea*>(static_cast<const EditArea*>(&source));
356 String editareaString = pEditArea->GetText();
357 if (editareaString.GetLength() == INIT_VALUE)
361 CommonUtil::SetFooterItemEnabled(*pFooter, false);
368 CommonUtil::SetFooterItemEnabled(*pFooter, true);
375 PlaylistCreatorForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
377 AppLogDebug("ENTER");
382 PlaylistCreatorForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
384 AppLogDebug("ENTER");
385 SceneManager* pSceneManager = SceneManager::GetInstance();
386 pSceneManager->GoBackward(BackwardSceneTransition());