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 MpPlaylistListEditorPanel.cpp
19 * @brief This is the implementation file for PlaylistListEditorPanel class.
22 #include "MpPlaylistEditorPresentationModel.h"
23 #include "MpPlaylistListEditorPanel.h"
24 #include "MpPlaylistPickerPopup.h"
25 #include "MpSharePopup.h"
26 #include "MpThumbnailInfo.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Content;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Social;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
37 static const int IDA_RENAME_EDIT_BUTTON = 101;
39 PlaylistListEditorPanel::PlaylistListEditorPanel(void)
40 : ContentEditPanel::ContentEditPanel()
41 , ThumbnailBase::ThumbnailBase()
42 , __selectedItemIndex(0)
43 , __pSelectAllCheckedButton(null)
45 , __pPlaylistName(null)
51 PlaylistListEditorPanel::~PlaylistListEditorPanel(void)
58 PlaylistListEditorPanel::OnInitializing(void)
61 __pPresentationModel = PlaylistEditorPresentationModel::GetInstance();
64 return ThumbnailBase::Construct();
68 PlaylistListEditorPanel::OnTerminating(void)
71 ThumbnailBase::Stop();
73 return ContentEditPanel::OnTerminating();
77 PlaylistListEditorPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
80 SceneManager* pSceneManager = SceneManager::GetInstance();
81 AppAssert(pSceneManager);
83 int totalCount = __pPresentationModel->GetAllPlayListCount();
85 Form* pForm = dynamic_cast<Form*>(GetParent());
88 Footer* pFooter = pForm->GetFooter();
92 case IDA_HEADER_BUTTON_SELECTE_ALL:
94 if (totalCount == __checkedItemCount)
96 SetItemCheckedAll(false);
100 SetItemCheckedAll(true);
105 case IDA_FOOTER_BUTTON_DELETE:
107 ContentManager contentManager;
108 contentManager.Construct();
110 int totalCount = __pPresentationModel->GetAllPlayListCount();
111 ArrayList* pTempList = new (std::nothrow) ArrayList();
112 pTempList->Construct();
113 for (int index = totalCount - 1; index >= 0; index--)
115 if (__pContentTableView->IsItemChecked(index) == true)
117 pTempList->Add(*(new (std::nothrow) String(__pPresentationModel->GetPlayListName(index))));
118 __pContentTableView->RefreshItem(index, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
122 if (pTempList != null)
124 for (int i = 0; i < pTempList->GetCount(); i++)
126 __pPresentationModel->RemovePlayList(*static_cast<String*>(pTempList->GetAt(i)));
130 __checkedItemCount = INIT_VALUE;
131 CommonUtil::SetFooterItemEnabled(*pFooter, false);
132 UpdateContentEditScreenState();
136 case IDA_RENAME_EDIT_BUTTON:
138 Integer::Parse(source.GetName(), __selectedItemIndex);
139 AppLogDebug("%d", __selectedItemIndex);
140 ArrayList* pData = new (std::nothrow) ArrayList();
142 pData->Add(*(new (std::nothrow) Integer(__selectedItemIndex)));
143 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYLIST_RENAME),pData);
154 PlaylistListEditorPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
155 const Tizen::Ui::Scenes::SceneId& currentSceneId,
156 Tizen::Base::Collection::IList* pArgs)
158 AppLogDebug("ENTER");
159 ContentPanel::OnSceneActivatedN(previousSceneId, currentSceneId, null);
161 Form* pForm = dynamic_cast<Form*>(GetParent());
164 SetEditHeaderStyle();
165 pForm->SetFormBackEventListener(this);
167 Footer* pFooter = CommonUtil::CreateBackButtonStyleFooter(*pForm, STYLE_DELETE_ADD);
168 pFooter->AddActionEventListener(*this);
169 pFooter->SetShowState(true);
170 CommonUtil::SetFooterItemEnabled(*pFooter, false);
172 UpdateContentEditScreenState();
176 pArgs->RemoveAll(true);
183 PlaylistListEditorPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
184 const Tizen::Ui::Scenes::SceneId& nextSceneId)
186 AppLogDebug("ENTER");
187 ContentPanel::OnSceneDeactivated(currentSceneId, nextSceneId);
189 Footer* pFooter = GetFooter();
190 pFooter->SetItemEnabled(0, true);
192 pFooter->RemoveAllButtons();
193 pFooter->RemoveAllItems();
194 pFooter->RemoveActionEventListener(*this);
196 __checkedItemCount = INIT_VALUE;
197 SetCheckedCountBallonTooltip(__checkedItemCount);
199 int totalCount = __pPresentationModel->GetAllPlayListCount();
200 for (int iCount = 0; iCount < totalCount; iCount++)
202 __pContentTableView->SetItemChecked(iCount, false);
204 CancelAllThumbnailRequest();
209 PlaylistListEditorPanel::GetItemCount(void)
211 AppLogDebug("ENTER");
212 if (__pPresentationModel == null)
219 return __pPresentationModel->GetAllPlayListCount();
222 Tizen::Ui::Controls::TableViewItem*
223 PlaylistListEditorPanel::CreateItem(const int itemIndex, int itemWidth)
225 AppLogDebug("ENTER");
226 RelativeLayout layout;
229 TableViewItem* pItem = new (std::nothrow) TableViewItem();
230 Tizen::Base::String playlistName = __pPresentationModel->GetPlayListName(itemIndex);
231 Panel* pPanel = null;
233 result r = pItem->Construct(layout, Dimension(itemWidth, ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_MARK);
234 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
236 r = CreateTableViewItem(*pItem, playlistName, itemIndex);
237 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
239 pPanel = static_cast<Panel*>(pItem->GetControl(IDL_CONTENTS_PLAYLIST_EDITOR_ITEM_PANEL));
240 if (__pPresentationModel->GetPlayListItemCount(playlistName) > 0 && !IsFailed(GetLastResult()))
242 static_cast<Label*>(pPanel->GetControl(IDC_CONTENTS_THUMBNAIL))->SetBackgroundBitmap(*GetDefaultThumbnail());
243 RequestThumbnail(__pPresentationModel->GetPlayListItemContentId(playlistName), (new (std::nothrow) Integer(itemIndex)));
247 Bitmap* thumbnail = (ResourceManager::GetBitmapN(L"34_player_list_thum_noitems.png"));
248 thumbnail->Scale(Dimension(W_THUMBNAIL, H_THUMBNAIL));
249 static_cast<Label*>(pPanel->GetControl(IDC_CONTENTS_THUMBNAIL))->SetBackgroundBitmap(*thumbnail);
257 AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
262 PlaylistListEditorPanel::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
264 AppLogDebug("ENTER");
265 Panel* pItemPanel = static_cast<Panel*>(pItem->GetControl(IDL_CONTENTS_PLAYLIST_EDITOR_ITEM_PANEL));
266 if (pItemPanel == null)
268 AppLogDebug("pItemPanel is null");
274 Label* pThumbnailLabel = static_cast<Label*>(pItemPanel->GetControl(IDC_CONTENTS_THUMBNAIL));
275 if (__pThumbnail == null || pThumbnailLabel == null)
277 AppLogDebug("__pThumbnail or pThumbnailLabel is null");
282 pThumbnailLabel->SetBackgroundBitmap(*__pThumbnail);
285 pThumbnailLabel->Invalidate(true);
291 PlaylistListEditorPanel::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
293 Tizen::Ui::Controls::TableViewItem* pItem,
294 Tizen::Ui::Controls::TableViewItemStatus status)
296 AppLogDebug("ENTER");
297 Form* pForm = dynamic_cast<Form*>(GetParent());
299 Footer* pFooter = pForm->GetFooter();
300 __selectedItemIndex = itemIndex;
304 case TABLE_VIEW_ITEM_STATUS_CHECKED:
306 __checkedItemCount++;
307 tableView.SetItemChecked(itemIndex, true);
311 case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
313 if (__checkedItemCount > INIT_VALUE)
315 __checkedItemCount--;
317 tableView.SetItemChecked(itemIndex, false);
325 if (__checkedItemCount > INIT_VALUE)
327 CommonUtil::SetFooterItemEnabled(*pFooter, true);
331 CommonUtil::SetFooterItemEnabled(*pFooter, false);
334 SetCheckedCountBallonTooltip(__checkedItemCount);
340 PlaylistListEditorPanel::UpdateContentList(void)
342 AppLogDebug( "ENTER");
343 AppLogDebug( "EXIT");
347 PlaylistListEditorPanel::SetEditHeaderStyle(void)
349 AppLogDebug("ENTER");
350 Header* pHeader = GetHeader();
351 String titleText(ResourceManager::GetString(L"IDS_COM_BODY_EDIT"));
352 CommonUtil::SetEditHeaderStyle(*pHeader, titleText);
353 pHeader->Invalidate(true);
358 PlaylistListEditorPanel::OnThumbnailInfoReveivedN(ThumbnailInfo* pThumbnailInfo)
360 AppLogDebug("ENTER");
361 __pThumbnail = pThumbnailInfo->GetBitmapN();
362 Object* pParam = pThumbnailInfo->GetUserParamN();
365 __pContentTableView->RefreshItem((static_cast<Integer*>(pParam))->ToInt(), TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
369 delete pThumbnailInfo;
374 PlaylistListEditorPanel::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
376 AppLogDebug("ENTER");
377 SceneManager* pSceneManager = SceneManager::GetInstance();
378 AppAssert(pSceneManager);
380 pSceneManager->GoBackward(BackwardSceneTransition());
385 PlaylistListEditorPanel::CreateTableViewItem(Tizen::Ui::Controls::TableViewItem& parent, const Tizen::Base::String& title, int itemIndex)
387 AppLogDebug("ENTER");
388 Panel* pTableViewItem = new (std::nothrow) Panel();
389 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_PLAYLIST_EDITOR_ITEM_PANEL)))
391 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_EDITOR_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
395 static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENTS_TITLE_NAME))->SetText(title);
398 str.Append(itemIndex);
400 Button* pEditButton = static_cast<Button*>(pTableViewItem->GetControl(IDC_BUTTON_EDIT));
401 pEditButton->SetName(str);
403 Bitmap* pNormalBitmap = ResourceManager::GetBitmapN(L"00_button_rename_normal.png");
404 Bitmap* pPressedBitmap = ResourceManager::GetBitmapN(L"00_button_rename_press.png");
405 Bitmap* pBackgroundNormalBitmap = ResourceManager::GetBitmapN(L"00_btn_circle_bg_normal.png");
406 Bitmap* pBackgroundPressBitmap = ResourceManager::GetBitmapN(L"00_btn_circle_bg_press.png");
408 pEditButton->SetNormalBitmap(Point(0, 0), *pNormalBitmap);
409 pEditButton->SetNormalBackgroundBitmap(*pBackgroundNormalBitmap);
410 pEditButton->SetPressedBitmap(Point(0, 0), *pPressedBitmap);
411 pEditButton->SetPressedBackgroundBitmap(*pBackgroundPressBitmap);
413 pEditButton->SetActionId(IDA_RENAME_EDIT_BUTTON);
414 pEditButton->AddActionEventListener(*this);
416 delete pNormalBitmap;
417 delete pPressedBitmap;
418 delete pBackgroundNormalBitmap;
419 delete pBackgroundPressBitmap;
421 parent.AddControl(*pTableViewItem);
422 parent.SetIndividualSelectionEnabled(pEditButton, true);
423 CommonUtil::SetLayoutFitToContainer(parent, *pTableViewItem);
430 PlaylistListEditorPanel::IsEmptyContentList(void)
432 AppLogDebug("ENTER");
433 if (__pPresentationModel->GetAllPlayListCount() == INIT_VALUE)