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 MpUserPlaylistContentListForm.cpp
19 * @brief This is the implementation file for UserPlaylistContentListForm class.
22 #include "MpPlaylistListPresentationModel.h"
23 #include "MpPlaylistPickerPopup.h"
24 #include "MpSharePopup.h"
25 #include "MpThumbnailInfo.h"
26 #include "MpUserPlaylistContentListForm.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Content;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Io;
34 using namespace Tizen::System;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
39 UserPlaylistContentListForm::UserPlaylistContentListForm(void)
40 : ContentListForm::ContentListForm()
41 , ThumbnailBase::ThumbnailBase()
42 , __pContentListTableView(null)
44 , __pPresentationModel(null)
45 , __checkedItemCount(0)
46 , __activatedStateContextItem(-1)
52 UserPlaylistContentListForm::~UserPlaylistContentListForm(void)
59 UserPlaylistContentListForm::Initialize(void)
62 if (IsFailed(Form::Construct(IDL_CONTENT_LIST_FORM)))
64 AppLogDebug("Construct(IDL_CONTENT_LIST_FORM) failed(%s)", GetErrorMessage(GetLastResult()));
73 UserPlaylistContentListForm::Construct(void)
76 __pContentListTableView = static_cast<TableView*>(GetControl(IDC_TABLEVIEW_CONTENT_LIST));
77 __pContentListTableView->AddTableViewItemEventListener(*this);
78 __pContentListTableView->SetItemProvider(this);
80 SetContentList(__pContentListTableView);
82 return ContentListForm::Construct();
86 UserPlaylistContentListForm::OnInitializing(void)
91 return ThumbnailBase::Construct();
95 UserPlaylistContentListForm::OnTerminating(void)
98 ThumbnailBase::Stop();
99 __pPresentationModel = null;
101 return ContentListForm::OnTerminating();
105 UserPlaylistContentListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
107 AppLogDebug("ENTER");
108 SceneManager* pSceneManager = SceneManager::GetInstance();
109 AppAssert(pSceneManager);
113 case IDA_HEADER_BUTTON_SELECTE_ALL:
115 bool isChecked = true;
116 if (__checkedItemCount == __pContentListTableView->GetItemCount())
120 SetItemCheckedAll(isChecked);
124 case IDA_FOOTER_BUTTON_SHARE:
126 LanucherPicker(PICKER_TYPE_SHARE_PICKER);
130 case IDA_FOOTER_BUTTON_ADD_TO_PLAYLIST:
132 LanucherPicker(PICKER_TYPE_PLAY_LIST_PICKER);
136 case IDA_CONTEXT_MENU_ITEM_SEARCH:
138 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SEARCH, SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY));
142 case IDA_CONTEXT_MENU_ITEM_EDIT:
144 ToggleScreenState(SCREEN_STATE_EDITOR);
148 case IDA_CONTEXT_MENU_ITEM_SHARE_VIA:
150 ToggleScreenState(SCREEN_STATE_SHARE_VIA);
154 case IDA_FOOTER_BUTTON_MORE:
156 Point anchorPoint(X_POINT_FOOTER_MORE, Y_POINT_PORTRAIT_FOOTER_MORE);
157 if ((GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE) || (GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
159 anchorPoint.y = Y_POINT_LANDSCAPE_FOOTER_MORE;
162 CreateContextMenuN(source);
163 if (IsEmptyContentList())
165 SetContextMenuItem(CONTEXT_MENU_ITEM_STYLE_ADD, anchorPoint);
169 SetContextMenuItem(CONTEXT_MENU_ITEM_STYLE_ADD | CONTEXT_MENU_ITEM_STYLE_SHARE_VIA | CONTEXT_MENU_ITEM_STYLE_EDIT, anchorPoint);
174 case IDA_FOOTER_BUTTON_DELETE:
176 int totalCount = __pPresentationModel->GetContentCount();
177 for (int iCount = 0; iCount < totalCount; iCount++)
179 if (__pContentListTableView->IsItemChecked(iCount) == true)
181 ContentInformation* pContentInfoStruct = __pPresentationModel->GetContentInfoN(iCount);
182 __pContentListTableView->SetItemChecked(iCount, false);
183 if (pContentInfoStruct == null)
187 __pPresentationModel->DeleteContent(USER_CONTENT, *pContentInfoStruct);
189 delete pContentInfoStruct;
192 RemoveCheckedTableviewItem(false);
193 __pPresentationModel->UpdatePlaylistContentList(USER_CONTENT, __headerTitle);
199 case IDA_CONTEXT_MENU_ITEM_STYLE_ADD:
201 if (__pPresentationModel->GetContentCount() == 0)
203 MessageBox messageBox;
204 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_MUSIC_HEADER_NO_SONGS"), MSGBOX_STYLE_NONE, 500);
207 messageBox.ShowAndWait(modalResult);
211 CommonUtil::SetAddtoPlaylistState(true);
212 CommonUtil::SetAddtoPlaylistName(__headerTitle);
213 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_CONTENT_PICKER));
222 TryRemoveContextMenu(actionId);
227 UserPlaylistContentListForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
228 const Tizen::Ui::Scenes::SceneId& currentSceneId,
229 Tizen::Base::Collection::IList* pArgs)
231 AppLogDebug("ENTER");
232 if (pArgs != null && previousSceneId.Equals(IDSCN_PLAYLIST_LIST, true) == true)
234 __prevSceneId.Append(*static_cast<String*>(pArgs->GetAt(DATA_ITEM_SCENE_NAME)));
235 __headerTitle.Append(*static_cast<String*>(pArgs->GetAt(DATA_ITEM_CONTENT_NAME)));
237 __pPresentationModel = PlaylistListPresentationModel::GetInstance();
238 __pPresentationModel->UpdatePlaylistContentList(USER_CONTENT, __headerTitle);
244 pArgs->RemoveAll(true);
247 // else if (!(__headerTitle.Equals(L"", false)))
249 // __pPresentationModel->UpdatePlaylistContentList(USER_CONTENT, __headerTitle);
250 // UpdateScreenState();
251 // UpdateTableView();
257 UserPlaylistContentListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
258 const Tizen::Ui::Scenes::SceneId& nextSceneId)
260 AppLogDebug("ENTER");
261 CancelAllThumbnailRequest();
266 UserPlaylistContentListForm::GetItemCount(void)
268 AppLogDebug("ENTER");
269 if (__pPresentationModel == null)
275 return __pPresentationModel->GetContentCount();
278 Tizen::Ui::Controls::TableViewItem*
279 UserPlaylistContentListForm::CreateItem(const int itemIndex, int itemWidth)
281 AppLogDebug("ENTER");
282 RelativeLayout layout;
285 TableViewAnnexStyle tableViewAnnexStyle = TABLE_VIEW_ANNEX_STYLE_NORMAL;
286 if (GetScreenState() != SCREEN_STATE_NORMAL)
288 tableViewAnnexStyle = TABLE_VIEW_ANNEX_STYLE_MARK;
291 TableViewItem* pItem = new (std::nothrow) TableViewItem();
292 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
294 result r = pItem->Construct(layout, Dimension(itemWidth, ITEM_HEIGHT), tableViewAnnexStyle);
295 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
296 TryCatch(pContentInfo != null, delete pItem, "pContentInfo is null", GetErrorMessage(GetLastResult()));
298 r = CreateTableViewItem(*pItem, *pContentInfo);
299 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
301 RequestThumbnail(pContentInfo->contentId, (new (std::nothrow) Integer(itemIndex)));
308 AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
314 UserPlaylistContentListForm::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
316 Tizen::Ui::Controls::TableViewItem* pItem,
317 Tizen::Ui::Controls::TableViewItemStatus status)
319 AppLogDebug("ENTER");
320 if (GetScreenState() != SCREEN_STATE_NORMAL)
322 SetItemCheckedStateChanged(status);
327 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
329 SceneManager* pSceneManager = SceneManager::GetInstance();
330 AppAssert(pSceneManager);
332 ArrayList* pSceneArg = MakePlayerSceneParam(itemIndex);
333 if (pSceneArg != null)
335 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER), pSceneArg);
342 UserPlaylistContentListForm::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex,
343 Tizen::Ui::Controls::TableViewContextItem* pContextItem,
346 AppLogDebug("ENTER");
349 __activatedStateContextItem = itemIndex;
355 UserPlaylistContentListForm::GetDefaultItemHeight(void)
357 AppLogDebug("ENTER");
363 UserPlaylistContentListForm::DeleteItem(const int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
365 AppLogDebug("ENTER");
371 UserPlaylistContentListForm::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView,
375 AppLogDebug("ENTER");
380 UserPlaylistContentListForm::CreateTableViewItem(Tizen::Ui::Container& parent, const ContentInformation& contentInfo)
382 AppLogDebug("ENTER");
383 Panel* pTableViewItem = new (std::nothrow) Panel();
384 if (GetScreenState() != SCREEN_STATE_NORMAL)
386 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_LIBARY_EDITOR_ITEM_PANEL)))
388 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
394 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL)))
396 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_EDITOR_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
401 static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENTS_TITLE_NAME))->SetText(contentInfo.TitleName);
402 static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENTS_ARTIST_NAME))->SetText(contentInfo.ArtistName);
403 static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENTS_THUMBNAIL))->SetBackgroundBitmap(*GetDefaultThumbnail());
405 parent.AddControl(*pTableViewItem);
406 CommonUtil::SetLayoutFitToContainer(parent, *pTableViewItem);
413 UserPlaylistContentListForm::SetHeader(void)
415 AppLogDebug("ENTER");
416 CommonUtil::SetSimpleTitleStyle(*GetHeader(), __headerTitle);
422 UserPlaylistContentListForm::SetFooter(void)
424 AppLogDebug("ENTER");
425 CommonUtil::SetBackButtonStyleFooter(*GetFooter(), STYLE_MORE_ADD);
431 UserPlaylistContentListForm::IsEmptyContentList(void)
433 AppLogDebug("ENTER");
434 if (__pPresentationModel->GetContentCount() != INIT_VALUE)
442 Tizen::Base::Collection::ArrayList*
443 UserPlaylistContentListForm::MakePlayerSceneParam(int startIndex)
445 AppLogDebug("ENTER");
446 ArrayList* pArgs = new (std::nothrow) ArrayList();
447 result r = pArgs->Construct();
450 AppLogDebug("pArgs->Construct failed(%s)", GetErrorMessage(r));
454 pArgs->Add(*(new (std::nothrow) String(MUSIC)));
455 pArgs->Add(*(new (std::nothrow) Integer(startIndex)));
456 pArgs->Add(*(__pPresentationModel->GetContentPathListN(USER_CONTENT)));
463 UserPlaylistContentListForm::OnThumbnailInfoReveivedN(ThumbnailInfo* pThumbnailInfo)
465 AppLogDebug("ENTER");
466 __pThumbnail = pThumbnailInfo->GetBitmapN();
467 Object* pParam = pThumbnailInfo->GetUserParamN();
470 __pContentListTableView->RefreshItem((static_cast<Integer*>(pParam))->ToInt(), TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
474 delete pThumbnailInfo;
479 UserPlaylistContentListForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
481 AppLogDebug("ENTER");
482 ContentListForm::OnUserEventReceivedN(requestId, pArgs);
483 if (requestId == ID_DESTORY_PLAY_LIST_PICKER_POPUP)
485 __pPresentationModel->UpdatePlaylistContentList(USER_CONTENT, __headerTitle);
486 __pContentListTableView->UpdateTableView();
492 UserPlaylistContentListForm::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
494 AppLogDebug("ENTER");
495 Panel* pItemPanel = null;
496 if (GetScreenState() != SCREEN_STATE_NORMAL)
498 pItemPanel = static_cast<Panel*>(pItem->GetControl(IDL_CONTENTS_LIBARY_EDITOR_ITEM_PANEL));
502 pItemPanel = static_cast<Panel*>(pItem->GetControl(IDL_CONTENTS_LIBARY_ITEM_PANEL));
505 if (pItemPanel == null)
507 AppLogDebug("pItemPanel is null");
513 Label* pThumbnailLabel = static_cast<Label*>(pItemPanel->GetControl(IDC_CONTENTS_THUMBNAIL));
514 if (__pThumbnail == null || pThumbnailLabel == null)
516 AppLogDebug("__pThumbnail or pThumbnailLabel is null");
522 pThumbnailLabel->SetBackgroundBitmap(*__pThumbnail);
525 pThumbnailLabel->Invalidate(true);
530 UserPlaylistContentListForm::GetCheckedItemCount(void)
532 AppLogDebug("ENTER");
534 return __checkedItemCount;
538 UserPlaylistContentListForm::UpdateTableView(void)
540 AppLogDebug("ENTER");
541 __pContentListTableView->UpdateTableView();
546 UserPlaylistContentListForm::UpdateContentList(void)
548 AppLogDebug("ENTER");
549 __pPresentationModel->UpdatePlaylistContentList(USER_CONTENT, __headerTitle);
555 UserPlaylistContentListForm::SetItemCheckedAll(bool isChecked)
557 AppLogDebug("ENTER");
558 if (isChecked == true)
560 __checkedItemCount = __pContentListTableView->GetItemCount();
564 __checkedItemCount = INIT_VALUE;
566 CommonUtil::SetItemCheckedAll(isChecked, *__pContentListTableView);
567 CommonUtil::SetFooterItemEnabled(*GetFooter(), isChecked);
568 SetCheckedCountBallonTooltip(GetCheckedItemCount());
573 UserPlaylistContentListForm::RemoveCheckedTableviewItem(bool itemRemove)
575 AppLogDebug("ENTER");
578 int totalCount = __pContentListTableView->GetItemCount();
579 for (int iCount = 0; iCount < totalCount; iCount++)
581 if (__pContentListTableView->IsItemChecked(iCount) == true)
583 __pContentListTableView->SetItemChecked(iCount, false);
584 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(iCount);
585 if (pContentInfo != null)
587 RemoveContentAt(pContentInfo->contentId);
594 __checkedItemCount = INIT_VALUE;
595 SetCheckedCountBallonTooltip(GetCheckedItemCount());
596 CommonUtil::SetFooterItemEnabled(*GetFooter(), false);
601 UserPlaylistContentListForm::SetItemCheckedStateChanged(Tizen::Ui::Controls::TableViewItemStatus status)
603 AppLogDebug("ENTER");
604 if (status == TABLE_VIEW_ITEM_STATUS_UNCHECKED)
606 __checkedItemCount--;
607 if (__checkedItemCount == INIT_VALUE)
609 CommonUtil::SetFooterItemEnabled(*GetFooter(), false);
612 else if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
614 if (__checkedItemCount == INIT_VALUE)
616 CommonUtil::SetFooterItemEnabled(*GetFooter(), true);
619 __checkedItemCount++;
622 SetCheckedCountBallonTooltip(GetCheckedItemCount());
626 Tizen::Base::Collection::IList*
627 UserPlaylistContentListForm::GetPickerArgumentListN(PickerType pickerType, PickerArgumentType argumentType)
629 AppLogDebug("ENTER");
630 Tizen::Base::Collection::ArrayList* pContentFilePathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
631 if (IsFailed(pContentFilePathList->Construct()))
633 AppLogDebug("pContentList->Construct failed(%s)", GetErrorMessage(GetLastResult()));
634 delete pContentFilePathList;
638 if (argumentType == PICKER_ARGUMENT_TYPE_ACTIVATED_STATE_CONTEXT_ITEM)
640 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(__activatedStateContextItem);
641 if (pContentInfo == null)
643 delete pContentFilePathList;
644 AppLogDebug("GetContentInfoN(%d) is null", __activatedStateContextItem);
648 pContentFilePathList->Add(*(new (std::nothrow) String(pContentInfo->ContentFilePath)));
651 else if (argumentType == PICKER_ARGUMENT_TYPE_CHECKED_ITEM_ALL)
653 int totalCount = __pContentListTableView->GetItemCount();
654 for (int iCount = 0; iCount < totalCount; iCount++)
656 if (__pContentListTableView->IsItemChecked(iCount) == true)
658 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(iCount);
659 if (pContentInfo == null)
661 AppLogDebug("GetContentInfoN(%d) is null", iCount);
662 delete pContentFilePathList;
666 if (pickerType == PICKER_TYPE_PLAY_LIST_PICKER)
668 pContentFilePathList->Add(*(new (std::nothrow) String(pContentInfo->ContentFilePath)));
670 else if (pickerType == PICKER_TYPE_SHARE_PICKER)
672 pContentFilePathList->Add(*(new (std::nothrow) String(L"attachment:" + pContentInfo->ContentFilePath)));
679 return pContentFilePathList;