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 MpPlaylistContentListForm.cpp
19 * @brief This is the implementation file for PlaylistContentListForm class.
23 #include "MpNowPlayContentPanel.h"
24 #include "MpPlaylistContentListForm.h"
25 #include "MpPlaylistListPresentationModel.h"
26 #include "MpPlaylistPickerPopup.h"
27 #include "MpSharePopup.h"
28 #include "MpThumbnailInfo.h"
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Content;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Io;
36 using namespace Tizen::Social;
37 using namespace Tizen::System;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
42 static const int COUNT_MESSAGE_BOX_TIMEOUT = 3000;
44 PlaylistContentListForm::PlaylistContentListForm(void)
45 : ContentListForm::ContentListForm()
46 , ThumbnailBase::ThumbnailBase()
47 , __pContentListTableView(null)
49 , __pPresentationModel(null)
50 , __checkedItemCount(0)
51 , __currentContentType(-1)
52 , __activatedStateContextItem(-1)
58 PlaylistContentListForm::~PlaylistContentListForm(void)
65 PlaylistContentListForm::Initialize(void)
68 if (IsFailed(Form::Construct(IDL_CONTENT_LIST_FORM)))
70 AppLogDebug("Construct(IDL_CONTENT_LIST_FORM) failed(%s)", GetErrorMessage(GetLastResult()));
79 PlaylistContentListForm::Construct(void)
82 __pContentListTableView = static_cast<TableView*>(GetControl(IDC_TABLEVIEW_CONTENT_LIST));
83 __pContentListTableView->AddTableViewItemEventListener(*this);
84 __pContentListTableView->SetItemProvider(this);
86 SetContentList(__pContentListTableView);
88 return ContentListForm::Construct();
92 PlaylistContentListForm::OnInitializing(void)
97 return ThumbnailBase::Construct();
101 PlaylistContentListForm::OnTerminating(void)
103 AppLogDebug("ENTER");
104 ThumbnailBase::Stop();
106 return ContentListForm::OnTerminating();
110 PlaylistContentListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
112 AppLogDebug("ENTER");
113 SceneManager* pSceneManager = SceneManager::GetInstance();
115 AppAssert(pSceneManager);
119 case IDA_HEADER_BUTTON_SELECTE_ALL:
121 bool isChecked = true;
122 if (__checkedItemCount == __pContentListTableView->GetItemCount())
126 SetItemCheckedAll(isChecked);
130 case IDA_CONTEXT_MENU_ITEM_SEARCH:
132 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SEARCH, SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY));
136 case IDA_CONTEXT_MENU_ITEM_EDIT:
138 if (__pPresentationModel->GetContentCount() == 0)
140 MessageBox messageBox;
141 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_MUSIC_HEADER_NO_SONGS"), MSGBOX_STYLE_NONE, 500);
144 messageBox.ShowAndWait(modalResult);
148 ToggleScreenState(SCREEN_STATE_EDITOR);
153 case IDA_CONTEXT_MENU_ITEM_SHARE_VIA:
155 if (__pPresentationModel->GetContentCount() == 0)
157 MessageBox messageBox;
158 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_MUSIC_HEADER_NO_SONGS"), MSGBOX_STYLE_NONE, 500);
161 messageBox.ShowAndWait(modalResult);
165 LanucherPicker(PICKER_TYPE_SHARE_PICKER);
170 case IDA_FOOTER_BUTTON_ADD_TO_PLAYLIST:
172 LanucherPicker(PICKER_TYPE_PLAY_LIST_PICKER);
176 case IDA_FOOTER_BUTTON_MORE:
178 Point anchorPoint(X_POINT_FOOTER_MORE, Y_POINT_PORTRAIT_FOOTER_MORE);
179 if ((GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE) || (GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
181 anchorPoint.y = Y_POINT_LANDSCAPE_FOOTER_MORE;
183 CreateContextMenuN(source);
184 SetContextMenuItem(CONTEXT_MENU_ITEM_STYLE_SHARE_VIA | CONTEXT_MENU_ITEM_STYLE_EDIT, anchorPoint);
188 case IDA_FOOTER_BUTTON_DELETE:
190 if (__currentContentType == RECENTLY_ADDED_CONTENT)
192 RemoveCheckedTableviewItem(true);
196 int totalCount = __pPresentationModel->GetContentCount();
197 for (int iCount = 0; iCount < totalCount; iCount++)
199 if (__pContentListTableView->IsItemChecked(iCount) == true)
201 ContentInformation* pContentInfoStruct = __pPresentationModel->GetContentInfoN(iCount);
202 if (pContentInfoStruct == null)
206 // __pContentListTableView->SetItemChecked(iCount, false);
207 __pPresentationModel->DeleteContent(__currentContentType, *pContentInfoStruct);
209 delete pContentInfoStruct;
212 RemoveCheckedTableviewItem(false);
213 __pPresentationModel->UpdatePlaylistContentList(__currentContentType, __headerTitle);
224 TryRemoveContextMenu(actionId);
229 PlaylistContentListForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
230 const Tizen::Ui::Scenes::SceneId& currentSceneId,
231 Tizen::Base::Collection::IList* pArgs)
233 AppLogDebug("ENTER");
234 if (pArgs != null && previousSceneId.Equals(IDSCN_PLAYLIST_LIST, true) == true)
236 __prevSceneId.Append(*static_cast<String*>(pArgs->GetAt(DATA_ITEM_SCENE_NAME)));
237 __headerTitle.Append(*static_cast<String*>(pArgs->GetAt(DATA_ITEM_CONTENT_NAME)));
238 __currentContentType = static_cast<Integer*>(pArgs->GetAt(DATA_ITEM_CONTENT_TYPE))->ToInt();
240 __pPresentationModel = PlaylistListPresentationModel::GetInstance();
241 __pPresentationModel->UpdatePlaylistContentList(__currentContentType, __headerTitle);
247 pArgs->RemoveAll(true);
254 PlaylistContentListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
255 const Tizen::Ui::Scenes::SceneId& nextSceneId)
257 AppLogDebug("ENTER");
258 CancelAllThumbnailRequest();
263 PlaylistContentListForm::GetItemCount(void)
265 AppLogDebug("ENTER");
266 if (__pPresentationModel == null)
272 return __pPresentationModel->GetContentCount();
275 Tizen::Ui::Controls::TableViewItem*
276 PlaylistContentListForm::CreateItem(const int itemIndex, int itemWidth)
278 AppLogDebug("ENTER");
279 RelativeLayout layout;
282 TableViewAnnexStyle tableViewAnnexStyle = TABLE_VIEW_ANNEX_STYLE_NORMAL;
283 if (GetScreenState() != SCREEN_STATE_NORMAL)
285 tableViewAnnexStyle = TABLE_VIEW_ANNEX_STYLE_MARK;
288 TableViewItem* pItem = new (std::nothrow) TableViewItem();
289 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
291 result r = pItem->Construct(layout, Dimension(itemWidth, ITEM_HEIGHT), tableViewAnnexStyle);
292 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
293 TryCatch(pContentInfo != null, delete pItem, "pContentInfo is null", GetErrorMessage(GetLastResult()));
295 r = CreateTableViewItem(*pItem, *pContentInfo);
296 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
298 RequestThumbnail(pContentInfo->contentId, (new (std::nothrow) Integer(itemIndex)));
305 AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
311 PlaylistContentListForm::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
313 Tizen::Ui::Controls::TableViewItem* pItem,
314 Tizen::Ui::Controls::TableViewItemStatus status)
316 AppLogDebug("ENTER");
317 if (GetScreenState() != SCREEN_STATE_NORMAL)
319 SetItemCheckedStateChanged(status);
324 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
326 SceneManager* pSceneManager = SceneManager::GetInstance();
327 AppAssert(pSceneManager);
329 ArrayList* pSceneArg = MakePlayerSceneParam(itemIndex);
330 if (pSceneArg != null)
332 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER), pSceneArg);
339 PlaylistContentListForm::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex,
340 Tizen::Ui::Controls::TableViewContextItem* pContextItem,
343 AppLogDebug("ENTER");
346 __activatedStateContextItem = itemIndex;
352 PlaylistContentListForm::GetDefaultItemHeight(void)
354 AppLogDebug("ENTER");
360 PlaylistContentListForm::DeleteItem(const int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
362 AppLogDebug("ENTER");
368 PlaylistContentListForm::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView,
372 AppLogDebug("ENTER");
376 Tizen::Base::Collection::ArrayList*
377 PlaylistContentListForm::GetSearchResultContentList(int itemIndex)
379 AppLogDebug("ENTER");
380 ArrayList* pTempList = new (std::nothrow) ArrayList();
381 if (pTempList == null)
386 pTempList->Construct();
388 pTempList->Add(*(new (std::nothrow) String(MUSIC)));
389 pTempList->Add(*(new (std::nothrow) Integer(itemIndex)));
390 pTempList->Add(*(__pPresentationModel->GetContentPathListN(__currentContentType)));
395 Tizen::Base::Collection::ArrayList*
396 PlaylistContentListForm::GetAudioContentInfoContentList(int itemIndex)
398 AppLogDebug("ENTER");
399 ArrayList* pTempList = new (std::nothrow) ArrayList();
400 if (pTempList == null)
405 pTempList->Construct();
407 pTempList->Add(*(new (std::nothrow) String(MUSIC)));
408 pTempList->Add(*(new (std::nothrow) Integer(itemIndex)));
409 pTempList->Add(*(__pPresentationModel->GetContentPathListN(__currentContentType)));
415 PlaylistContentListForm::IsEmptyContentList(void)
417 AppLogDebug("ENTER");
418 if (__pPresentationModel->GetContentCount() != INIT_VALUE)
427 PlaylistContentListForm::GetCheckedItemCount(void)
429 AppLogDebug("ENTER");
431 return __checkedItemCount;
434 Tizen::Base::Collection::ArrayList*
435 PlaylistContentListForm::MakePlayerSceneParam(int startIndex)
437 AppLogDebug("ENTER");
438 if (__currentContentType != RECENTLY_ADDED_CONTENT)
441 return GetAudioContentInfoContentList(startIndex);
443 else if (__currentContentType == RECENTLY_ADDED_CONTENT)
446 return GetSearchResultContentList(startIndex);
453 PlaylistContentListForm::SetHeader(void)
455 AppLogDebug("ENTER");
456 CommonUtil::SetSimpleTitleStyle(*GetHeader(), __headerTitle);
462 PlaylistContentListForm::SetFooter(void)
464 AppLogDebug("ENTER");
465 CommonUtil::SetBackButtonStyleFooter(*GetFooter(), STYLE_MORE_ADD);
471 PlaylistContentListForm::CreateTableViewItem(Tizen::Ui::Controls::TableViewItem& parent, const ContentInformation& contentInfo)
473 AppLogDebug("ENTER");
474 Panel* pTableViewItem = new (std::nothrow) Panel();
475 if (GetScreenState() != SCREEN_STATE_NORMAL)
477 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_LIBARY_EDITOR_ITEM_PANEL)))
479 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
485 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL)))
487 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_EDITOR_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
492 static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENTS_TITLE_NAME))->SetText(contentInfo.TitleName);
493 static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENTS_ARTIST_NAME))->SetText(contentInfo.ArtistName);
494 static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENTS_THUMBNAIL))->SetBackgroundBitmap(*GetDefaultThumbnail());
496 parent.AddControl(*pTableViewItem);
497 CommonUtil::SetLayoutFitToContainer(parent, *pTableViewItem);
504 PlaylistContentListForm::OnAppControlCompleteResponseReceived(const AppId& appId,
505 const String& operationId, AppCtrlResult appControlResult,
506 const IMap* pExtraData)
508 AppLogDebug("ENTER");
509 if (pExtraData == null)
514 AppLogDebug("%ls, %ls", appId.GetPointer(), operationId.GetPointer());
515 if (appId.Equals(String(PROVIDER_ID_CONTACT)))
517 if (appControlResult == APP_CTRL_RESULT_SUCCEEDED)
519 const String* pResultString = static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_SOCIAL_ITEM_ID)));
521 AppLogDebug("%ls", pResultString->GetPointer());
523 Integer::Parse(*pResultString, contactId);
525 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
526 Addressbook* pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
528 ContentInformation* pCcontentInfo = __pPresentationModel->GetContentInfoN(__activatedStateContextItem);
529 if (pCcontentInfo == null)
536 Contact* pContact = pAddressbook->GetContactN(contactId);
537 pContact->SetValue(CONTACT_PROPERTY_ID_RINGTONE, pCcontentInfo->ContentFilePath);
538 result r = pAddressbook->UpdateContact(*pContact);
542 MessageBox messageBox;
543 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_SUCCESS"),
545 COUNT_MESSAGE_BOX_TIMEOUT);
547 messageBox.ShowAndWait(modalResult);
550 delete pCcontentInfo;
551 pCcontentInfo = null;
564 PlaylistContentListForm::OnThumbnailInfoReveivedN(ThumbnailInfo* pThumbnailInfo)
566 AppLogDebug("ENTER");
567 Object* pParam = null;
568 __pThumbnail = pThumbnailInfo->GetBitmapN();
569 pParam = pThumbnailInfo->GetUserParamN();
572 __pContentListTableView->RefreshItem((static_cast<Integer*>(pParam))->ToInt(), TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
576 delete pThumbnailInfo;
581 PlaylistContentListForm::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
583 AppLogDebug("ENTER");
584 Panel* pItemPanel = null;
585 if (GetScreenState() != SCREEN_STATE_NORMAL)
587 pItemPanel = static_cast<Panel*>(pItem->GetControl(IDL_CONTENTS_LIBARY_EDITOR_ITEM_PANEL));
591 pItemPanel = static_cast<Panel*>(pItem->GetControl(IDL_CONTENTS_LIBARY_ITEM_PANEL));
594 if (pItemPanel == null)
596 AppLogDebug("pItemPanel is null");
602 Label* pThumbnailLabel = static_cast<Label*>(pItemPanel->GetControl(IDC_CONTENTS_THUMBNAIL));
603 if (__pThumbnail == null || pThumbnailLabel == null)
605 AppLogDebug("__pThumbnail or pThumbnailLabel is null");
611 pThumbnailLabel->SetBackgroundBitmap(*__pThumbnail);
614 pThumbnailLabel->Invalidate(true);
619 PlaylistContentListForm::UpdateTableView(void)
621 AppLogDebug("ENTER");
622 __pContentListTableView->UpdateTableView();
627 PlaylistContentListForm::UpdateContentList(void)
629 AppLogDebug("ENTER");
630 __pPresentationModel->UpdatePlaylistContentList(__currentContentType, __headerTitle);
636 PlaylistContentListForm::SetItemCheckedAll(bool isChecked)
638 AppLogDebug("ENTER");
639 if (isChecked == true)
641 __checkedItemCount = __pContentListTableView->GetItemCount();
645 __checkedItemCount = INIT_VALUE;
647 CommonUtil::SetItemCheckedAll(isChecked, *__pContentListTableView);
648 CommonUtil::SetFooterItemEnabled(*GetFooter(), isChecked);
649 SetCheckedCountBallonTooltip(GetCheckedItemCount());
654 PlaylistContentListForm::RemoveCheckedTableviewItem(bool itemRemove)
656 AppLogDebug("ENTER");
659 int totalCount = __pContentListTableView->GetItemCount();
660 for (int iCount = 0; iCount < totalCount; iCount++)
662 if (__pContentListTableView->IsItemChecked(iCount) == true)
664 __pContentListTableView->SetItemChecked(iCount, false);
665 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(iCount);
666 if (pContentInfo != null)
668 RemoveContentAt(pContentInfo->contentId);
676 SetItemCheckedAll(false);
682 PlaylistContentListForm::SetItemCheckedStateChanged(Tizen::Ui::Controls::TableViewItemStatus status)
684 AppLogDebug("ENTER");
685 if (status == TABLE_VIEW_ITEM_STATUS_UNCHECKED)
687 __checkedItemCount--;
688 if (__checkedItemCount == INIT_VALUE)
690 CommonUtil::SetFooterItemEnabled(*GetFooter(), false);
693 else if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
695 if (__checkedItemCount == INIT_VALUE)
697 CommonUtil::SetFooterItemEnabled(*GetFooter(), true);
700 __checkedItemCount++;
703 SetCheckedCountBallonTooltip(GetCheckedItemCount());
707 Tizen::Base::Collection::IList*
708 PlaylistContentListForm::GetPickerArgumentListN(PickerType pickerType, PickerArgumentType argumentType)
710 AppLogDebug("ENTER");
711 Tizen::Base::Collection::ArrayList* pContentFilePathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
712 if (IsFailed(pContentFilePathList->Construct()))
714 AppLogDebug("pContentList->Construct failed(%s)", GetErrorMessage(GetLastResult()));
715 delete pContentFilePathList;
719 if (argumentType == PICKER_ARGUMENT_TYPE_ACTIVATED_STATE_CONTEXT_ITEM)
721 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(__activatedStateContextItem);
722 if (pContentInfo == null)
724 delete pContentFilePathList;
725 AppLogDebug("GetContentInfoN(%d) is null", __activatedStateContextItem);
729 pContentFilePathList->Add(*(new (std::nothrow) String(pContentInfo->ContentFilePath)));
732 else if (argumentType == PICKER_ARGUMENT_TYPE_CHECKED_ITEM_ALL)
734 int totalCount = __pContentListTableView->GetItemCount();
735 for (int iCount = 0; iCount < totalCount; iCount++)
737 if (__pContentListTableView->IsItemChecked(iCount) == true)
739 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(iCount);
740 if (pContentInfo == null)
742 AppLogDebug("GetContentInfoN(%d) is null", iCount);
743 delete pContentFilePathList;
747 if (pickerType == PICKER_TYPE_PLAY_LIST_PICKER)
749 pContentFilePathList->Add(*(new (std::nothrow) String(pContentInfo->ContentFilePath)));
751 else if (pickerType == PICKER_TYPE_SHARE_PICKER)
753 pContentFilePathList->Add(*(new (std::nothrow) String(L"attachment:" + pContentInfo->ContentFilePath)));
760 return pContentFilePathList;