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 MpContentListForm.cpp
19 * @brief This is the implementation file for ContentListForm class.
22 #include "MpContentListForm.h"
23 #include "MpNowPlayContentPanel.h"
24 #include "MpPlaylistPickerPopup.h"
25 #include "MpSharePopup.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::Social;
35 using namespace Tizen::System;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
40 static const int H_SHOW_CHECKED_COUNT_BALLOON_TOOL_TIP = 48;
42 ContentListForm::ContentListForm(void)
45 , __pContentList(null)
46 , __pContextMenu(null)
47 , __pCommonUtilPopupHandler(null)
49 , __pExtraInformaionArea(null)
50 , __pBallonTooltip(null)
51 , __pPlayListPicker(null)
52 , __pSharePicker(null)
53 , __screenState(SCREEN_STATE_NORMAL)
54 , __heightExtraInformaionArea(0)
60 ContentListForm::~ContentListForm(void)
67 ContentListForm::OnTerminating(void)
70 RemovePlayListPicker();
75 __pContentList = null;
77 __pExtraInformaionArea = null;
78 __pBallonTooltip = null;
84 ContentListForm::Initialize(void)
87 if (IsFailed(Form::Construct(IDL_CONTENT_LIST_FORM)))
89 AppLogDebug("Construct(IDL_CONTENT_LIST_FORM) failed(%s)", GetErrorMessage(GetLastResult()));
98 ContentListForm::Construct(void)
100 AppLogDebug("ENTER");
101 __pNoContent = static_cast<Label*>(GetControl(IDC_LABEL_NO_CONTENT));
102 __pBallonTooltip = static_cast<Label*>(GetControl(IDC_LABEL_BALLOON_TOOLTIP));
104 __pExtraInformaionArea = static_cast<Panel*>(GetControl(IDC_LABEL_CONTENT_ADDITIONAL_INFO));
105 if (__pExtraInformaionArea != null)
107 __pExtraInformaionArea->SetSize(INIT_VALUE, INIT_VALUE);
110 AddOrientationEventListener(*this);
111 GetHeader()->AddActionEventListener(*this);
112 GetFooter()->AddActionEventListener(*this);
113 SetFormBackEventListener(this);
119 ContentListForm::SetCommonPopup(Tizen::Ui::Controls::Popup* commonUtilPopup)
121 AppLogDebug("ENTER");
122 __pCommonUtilPopupHandler = commonUtilPopup;
123 SetShowStateCommonPopup(true);
124 __pCommonUtilPopupHandler->Show();
129 ContentListForm::SetContentList(Tizen::Ui::Container* pTableview)
131 AppLogDebug("ENTER");
132 __pContentList = pTableview;
137 ContentListForm::ShowSharePicker(Tizen::Base::Collection::IList* pIList)
139 AppLogDebug("ENTER");
142 __pSharePicker = new (std::nothrow) SharePopup();
143 if (IsFailed(__pSharePicker->Initialize(this)))
145 AppLogDebug("__pSharePicker->Initialize failed(%s)", GetErrorMessage(E_FAILURE));
150 __pSharePicker->SetArguments(pIList);
151 __pSharePicker->SetShowState(true);
152 __pSharePicker->Show();
159 ContentListForm::LanucherPicker(PickerType pickerType, PickerArgumentType argumentType)
161 AppLogDebug("ENTER");
162 IList* pArgumentList = GetPickerArgumentListN(pickerType, argumentType);
163 if (pArgumentList == null)
165 AppLogDebug("GetPickerArgumentListN is null");
169 result r = E_FAILURE;
170 if (pickerType == PICKER_TYPE_PLAY_LIST_PICKER)
172 r = ShowPlayListPicker(pArgumentList);
174 else if (pickerType == PICKER_TYPE_SHARE_PICKER)
176 r = ShowSharePicker(pArgumentList);
181 AppLogDebug("ShowPlayListPicker failed(%s)", GetErrorMessage(r));
182 delete pArgumentList;
189 Tizen::Base::Collection::IList*
190 ContentListForm::GetPickerArgumentListN(PickerType pickerType, PickerArgumentType argumentType)
192 AppLogDebug("ENTER");
198 ContentListForm::ShowPlayListPicker(Tizen::Base::Collection::IList* pIList)
200 AppLogDebug("ENTER");
201 RemovePlayListPicker();
203 __pPlayListPicker = new (std::nothrow) PlayListPickerPopup();
204 if (IsFailed(__pPlayListPicker->Initialize(this, pIList)))
206 AppLogDebug("__pSharePicker->Initialize failed(%s)", GetErrorMessage(E_FAILURE));
207 RemovePlayListPicker();
211 __pPlayListPicker->SetShowState(true);
212 __pPlayListPicker->Show();
219 ContentListForm::SetShowStateCommonPopup(bool isShow)
221 AppLogDebug("ENTER");
222 if (__pCommonUtilPopupHandler == null)
224 AppLogDebug("__pCommonUtilPopupHandler is null");
229 return CommonUtil::SetShowStateControl(*__pCommonUtilPopupHandler, isShow);
233 ContentListForm::RemovCommonPopup(void)
235 AppLogDebug("ENTER");
236 if (__pCommonUtilPopupHandler != null)
238 CommonUtil::SetShowStateControl(*__pCommonUtilPopupHandler, false);
239 delete __pCommonUtilPopupHandler;
240 __pCommonUtilPopupHandler = null;
246 ContentListForm::TryRemoveCommonPopup(int actionId)
248 AppLogDebug("ENTER");
249 result r = E_FAILURE;
250 if (CommonUtil::IsVaildCommonPopupActionId(actionId) == true)
252 SetShowStateCommonPopup(false);
261 ContentListForm::RemoveSharePicker(void)
263 AppLogDebug("ENTER");
264 if (__pSharePicker != null)
266 CommonUtil::SetShowStateControl(*__pSharePicker, false);
267 delete __pSharePicker;
268 __pSharePicker = null;
274 ContentListForm::RemovePlayListPicker(void)
276 AppLogDebug("ENTER");
277 if (__pPlayListPicker != null )
279 CommonUtil::SetShowStateControl(*__pPlayListPicker, false);
280 delete __pPlayListPicker;
281 __pPlayListPicker = null;
287 ContentListForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
289 AppLogDebug("ENTER");
295 ContentListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
297 AppLogDebug("ENTER");
302 ContentListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
304 AppLogDebug("ENTER");
309 ContentListForm::TryRemoveContextMenu(int actionId)
311 AppLogDebug("ENTER");
312 result r = E_FAILURE;
313 if (CommonUtil::IsVaildContextMenuItemActionId(actionId) == true)
323 ContentListForm::OnScrollPositionChanged (Tizen::Ui::Control& source, int scrollPos)
325 AppLogDebug("ENTER");
326 // __scrolledDistance = scrollPos;
331 ContentListForm::OnScrollEndReached (Tizen::Ui::Control& source, Tizen::Ui::Controls::ScrollEndEvent type)
333 AppLogDebug("ENTER");
338 ContentListForm::OnScrollStopped (Tizen::Ui::Control& source)
340 AppLogDebug("ENTER");
345 ContentListForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
347 AppLogDebug("ENTER");
348 if (GetScreenState() != SCREEN_STATE_NORMAL)
350 ToggleScreenState(SCREEN_STATE_NORMAL);
355 SceneManager* pSceneManager = SceneManager::GetInstance();
356 AppAssert(pSceneManager);
357 pSceneManager->GoBackward(BackwardSceneTransition(), null);
362 ContentListForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
364 AppLogDebug("ENTER");
365 if ((requestId != ID_DESTORY_PLAY_LIST_PICKER_POPUP) && (requestId != ID_DESTORY_SHARE_POPUP))
371 if (GetScreenState() != SCREEN_STATE_NORMAL && pArgs != null)
373 Boolean* pIsInitialize = static_cast<Boolean*>(pArgs->GetAt(0));
374 if (pIsInitialize->Equals(true))
376 SetItemCheckedAll(false);
379 RemovePlayListPicker();
382 pArgs->RemoveAll(true);
389 ContentListForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
391 AppLogDebug("ENTER");
397 ContentListForm::OnMusicContentUpdateCompleted(void)
399 AppLogDebug("ENTER");
400 SetItemCheckedAll(false);
402 RemovePlayListPicker();
408 if (IsEmptyContentList() == false)
416 ContentListForm::SetShowStateNoContent(bool isShow)
418 AppLogDebug("ENTER");
420 return CommonUtil::SetShowStateControl(*__pNoContent, isShow);
424 ContentListForm::SetShowStateBalloonTooltip(bool isShow)
426 AppLogDebug("ENTER");
427 int balloonTooltipHeight = INIT_VALUE;
428 if (isShow == true && GetCheckedItemCount() != INIT_VALUE)
430 balloonTooltipHeight = H_SHOW_CHECKED_COUNT_BALLOON_TOOL_TIP;
438 return CommonUtil::SetShowStateVariableHeightSizeControl(*__pBallonTooltip, balloonTooltipHeight, isShow);
442 ContentListForm::SetCheckedCountBallonTooltip(unsigned int checkedItemCount)
444 AppLogDebug("ENTER");
445 if (checkedItemCount == INIT_VALUE)
447 SetShowStateBalloonTooltip(false);
451 __pBallonTooltip->SetText(CommonUtil::GetStringItemSelected(checkedItemCount));
452 if (__pBallonTooltip->GetShowState() == false)
454 SetShowStateBalloonTooltip(true);
458 __pBallonTooltip->Invalidate(true);
464 ContentListForm::SetShowStatExtraInformaionArea(bool isShow)
466 AppLogDebug("ENTER");
467 if (__pExtraInformaionArea == null)
469 AppLogDebug("__pExtraInformaionArea is null");
473 int renewHeight = INIT_VALUE;
476 renewHeight = __heightExtraInformaionArea;
480 return CommonUtil::SetShowStateVariableHeightSizeControl(*__pExtraInformaionArea, renewHeight, isShow);
484 ContentListForm::SetShowStateContentList(bool isShow)
486 AppLogDebug("ENTER");
487 if (__pContentList == null)
489 AppLogDebug("__pContentList is null");
494 return CommonUtil::SetShowStateControl(*__pContentList, isShow);
498 ContentListForm::SetExtraInformaionArea(Tizen::Ui::Control& control)
500 AppLogDebug("ENTER");
501 RemoveExtraInformaionArea();
502 if (IsExistExtraInformaionArea() == false)
504 Dimension dimension = control.GetSize();
505 __heightExtraInformaionArea = dimension.height;
506 __pExtraInformaionArea->AddControl(control);
507 CommonUtil::SetLayoutFitToContainer(*__pExtraInformaionArea, control);
508 __pExtraInformaionArea->SetSize(dimension);
509 __pExtraInformaionArea->Invalidate(true);
517 ContentListForm::GetExtraInformaionAreaControl(void)
519 AppLogDebug("ENTER");
520 if (IsExistExtraInformaionArea() == false)
522 AppLogDebug("AdditionalInforamtion is not Registered");
527 return __pExtraInformaionArea->GetControl(INIT_VALUE);
531 ContentListForm::IsExistExtraInformaionArea(void)
533 AppLogDebug("ENTER");
534 if (__pExtraInformaionArea!= null && __pExtraInformaionArea->GetControlCount() != INIT_VALUE)
544 ContentListForm::RemoveExtraInformaionArea(void)
546 AppLogDebug("ENTER");
547 if (__pExtraInformaionArea != null)
549 __heightExtraInformaionArea = INIT_VALUE;
550 __pExtraInformaionArea->RemoveAllControls();
556 ContentListForm::UpdateScreenState(void)
558 AppLogDebug("ENTER");
559 if (IsEmptyContentList() == true)
561 SetShowStateContentList(false);
562 SetShowStateBalloonTooltip(false);
563 SetShowStatExtraInformaionArea(false);
564 SetShowStateNoContent(true);
566 GetHeader()->SetButtonEnabled(BUTTON_POSITION_RIGHT, false);
567 GetHeader()->Invalidate(true);
572 if (GetScreenState() != SCREEN_STATE_NORMAL)
574 SetShowStateBalloonTooltip(true);
575 SetShowStatExtraInformaionArea(false);
579 SetShowStateBalloonTooltip(false);
580 SetShowStatExtraInformaionArea(true);
583 SetShowStateNoContent(false);
584 SetShowStateContentList(true);
589 ContentListForm::ToggleScreenState(ScreenState screenState)
591 AppLogDebug("ENTER");
592 if (IsFailed(SetScreenState(screenState)))
594 AppLogDebug("SetScreenState() failed(%s)", GetErrorMessage(E_FAILURE));
598 if (screenState == SCREEN_STATE_NORMAL)
602 SetItemCheckedAll(false);
606 if (screenState == SCREEN_STATE_EDITOR)
608 CommonUtil::SetEditHeaderStyle(*GetHeader(), ResourceManager::GetString(L"IDS_COM_BODY_EDIT"));
609 CommonUtil::SetBackButtonStyleFooter(*GetFooter(), STYLE_ADDTO_DELETE_ADD);
611 else if (screenState == SCREEN_STATE_SHARE_VIA)
613 CommonUtil::SetEditHeaderStyle(*GetHeader(), ResourceManager::GetString(L"IDS_IV_BODY_SHARE_VIA"));
614 CommonUtil::SetBackButtonStyleFooter(*GetFooter(), STYLE_SHARE_ADD);
617 GetHeader()->Invalidate(true);
618 SetCheckedCountBallonTooltip(GetCheckedItemCount());
619 CommonUtil::SetFooterItemEnabled(*GetFooter(), false);
629 ContentListForm::CreateContextMenuN(const Tizen::Ui::Control& source)
631 AppLogDebug("ENTER");
633 __pContextMenu = CommonUtil::CreateContextMenuN(source, *this);
634 if (__pContextMenu != null)
643 ContentListForm::SetContextMenuItem(unsigned int contextMenuItemStyle, Tizen::Graphics::Point anchorPosition)
645 AppLogDebug("ENTER");
646 if (__pContextMenu == null)
652 CommonUtil::AddContextMenuItem(*__pContextMenu, contextMenuItemStyle);
653 CommonUtil::ShowContextMenu(*__pContextMenu, true);
655 Point prevAnchorPosition = __pContextMenu->GetAnchorPosition();
656 if (anchorPosition.x != -1)
658 prevAnchorPosition.x = anchorPosition.x;
661 if (anchorPosition.y != -1)
663 prevAnchorPosition.y = anchorPosition.y;
666 __pContextMenu->SetAnchorPosition(prevAnchorPosition);
672 ContentListForm::RemoveContextMenu(void)
674 AppLogDebug("ENTER");
675 if (__pContextMenu != null)
677 CommonUtil::SetShowStateControl(*__pContextMenu, false);
678 delete __pContextMenu;
679 __pContextMenu = null;
685 ContentListForm::GetScreenState(void)
687 AppLogDebug("ENTER");
689 return __screenState;
693 ContentListForm::SetScreenState(ScreenState screenState)
695 AppLogDebug("ENTER");
696 result r = E_FAILURE;
697 if (__screenState != screenState && screenState != SCREEN_STATE_MAX)
699 __screenState = screenState;
707 ContentListForm::RemoveContentAt(const Tizen::Content::ContentId& contentId)
709 AppLogDebug("ENTER");
710 ContentManager contentManager;
711 contentManager.Construct();
713 if (IsFailed(contentManager.DeleteContent(contentId)))
715 AppLogDebug("DeleteContent(%ls) failed", contentId.ToString().GetPointer());
716 return GetLastResult();
723 ContentListForm::UpdateExtraInformaionArea(void)
725 AppLogDebug("ENTER");