Fixed jira issue and fixed prevent issue
[apps/osp/MusicPlayer.git] / src / MpContentListForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                MpContentListForm.cpp
19  * @brief               This is the implementation file for ContentListForm class.
20  */
21
22 #include "MpContentListForm.h"
23 #include "MpNowPlayContentPanel.h"
24 #include "MpPlaylistPickerPopup.h"
25 #include "MpSharePopup.h"
26 #include "MpTypes.h"
27
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;
39
40 static const int H_SHOW_CHECKED_COUNT_BALLOON_TOOL_TIP = 48;
41
42 ContentListForm::ContentListForm(void)
43         : __headerTitle(L"")
44         , __prevSceneId(L"")
45         , __pContentList(null)
46         , __pContextMenu(null)
47         , __pCommonUtilPopupHandler(null)
48         , __pNoContent(null)
49         , __pExtraInformaionArea(null)
50         , __pBallonTooltip(null)
51         , __pPlayListPicker(null)
52         , __pSharePicker(null)
53         , __screenState(SCREEN_STATE_NORMAL)
54         , __heightExtraInformaionArea(0)
55 {
56         AppLogDebug("ENTER");
57         AppLogDebug("EXIT");
58 }
59
60 ContentListForm::~ContentListForm(void)
61 {
62         AppLogDebug("ENTER");
63         AppLogDebug("EXIT");
64 }
65
66 result
67 ContentListForm::OnTerminating(void)
68 {
69         AppLogDebug("ENTER");
70         RemovePlayListPicker();
71         RemoveSharePicker();
72         RemovCommonPopup();
73         RemoveContextMenu();
74
75         __pContentList = null;
76         __pNoContent = null;
77         __pExtraInformaionArea = null;
78         __pBallonTooltip = null;
79         AppLogDebug("EXIT");
80         return E_SUCCESS;
81 }
82
83 result
84 ContentListForm::Initialize(void)
85 {
86         AppLogDebug("ENTER");
87         if (IsFailed(Form::Construct(IDL_CONTENT_LIST_FORM)))
88         {
89                 AppLogDebug("Construct(IDL_CONTENT_LIST_FORM) failed(%s)", GetErrorMessage(GetLastResult()));
90                 return false;
91         }
92
93         AppLogDebug("EXIT");
94         return Construct();
95 }
96
97 result
98 ContentListForm::Construct(void)
99 {
100         AppLogDebug("ENTER");
101         __pNoContent = static_cast<Label*>(GetControl(IDC_LABEL_NO_CONTENT));
102         __pBallonTooltip = static_cast<Label*>(GetControl(IDC_LABEL_BALLOON_TOOLTIP));
103
104         __pExtraInformaionArea = static_cast<Panel*>(GetControl(IDC_LABEL_CONTENT_ADDITIONAL_INFO));
105         if (__pExtraInformaionArea != null)
106         {
107                 __pExtraInformaionArea->SetSize(INIT_VALUE, INIT_VALUE);
108         }
109
110         AddOrientationEventListener(*this);
111         GetHeader()->AddActionEventListener(*this);
112         GetFooter()->AddActionEventListener(*this);
113         SetFormBackEventListener(this);
114         AppLogDebug("EXIT");
115         return E_SUCCESS;
116 }
117
118 void
119 ContentListForm::SetCommonPopup(Tizen::Ui::Controls::Popup* commonUtilPopup)
120 {
121         AppLogDebug("ENTER");
122         __pCommonUtilPopupHandler = commonUtilPopup;
123         SetShowStateCommonPopup(true);
124         __pCommonUtilPopupHandler->Show();
125         AppLogDebug("EXIT");
126 }
127
128 void
129 ContentListForm::SetContentList(Tizen::Ui::Container* pTableview)
130 {
131         AppLogDebug("ENTER");
132         __pContentList = pTableview;
133         AppLogDebug("EXIT");
134 }
135
136 result
137 ContentListForm::ShowSharePicker(Tizen::Base::Collection::IList* pIList)
138 {
139         AppLogDebug("ENTER");
140         RemoveSharePicker();
141
142         __pSharePicker = new (std::nothrow) SharePopup();
143         if (IsFailed(__pSharePicker->Initialize(this)))
144         {
145                 AppLogDebug("__pSharePicker->Initialize failed(%s)", GetErrorMessage(E_FAILURE));
146                 RemoveSharePicker();
147                 return E_FAILURE;
148         }
149
150         __pSharePicker->SetArguments(pIList);
151         __pSharePicker->SetShowState(true);
152         __pSharePicker->Show();
153
154         AppLogDebug("EXIT");
155         return E_SUCCESS;
156 }
157
158 result
159 ContentListForm::LanucherPicker(PickerType pickerType, PickerArgumentType argumentType)
160 {
161         AppLogDebug("ENTER");
162         IList* pArgumentList = GetPickerArgumentListN(pickerType, argumentType);
163         if (pArgumentList == null)
164         {
165                 AppLogDebug("GetPickerArgumentListN is null");
166                 return E_FAILURE;
167         }
168
169         result r = E_FAILURE;
170         if (pickerType == PICKER_TYPE_PLAY_LIST_PICKER)
171         {
172                 r = ShowPlayListPicker(pArgumentList);
173         }
174         else if (pickerType == PICKER_TYPE_SHARE_PICKER)
175         {
176                 r = ShowSharePicker(pArgumentList);
177         }
178
179         if (IsFailed(r))
180         {
181                 AppLogDebug("ShowPlayListPicker failed(%s)", GetErrorMessage(r));
182                 delete pArgumentList;
183         }
184
185         AppLogDebug("EXIT");
186         return r;
187 }
188
189 Tizen::Base::Collection::IList*
190 ContentListForm::GetPickerArgumentListN(PickerType pickerType, PickerArgumentType argumentType)
191 {
192         AppLogDebug("ENTER");
193         AppLogDebug("EXIT");
194         return null;
195 }
196
197 result
198 ContentListForm::ShowPlayListPicker(Tizen::Base::Collection::IList* pIList)
199 {
200         AppLogDebug("ENTER");
201         RemovePlayListPicker();
202
203         __pPlayListPicker = new (std::nothrow) PlayListPickerPopup();
204         if (IsFailed(__pPlayListPicker->Initialize(this, pIList)))
205         {
206                 AppLogDebug("__pSharePicker->Initialize failed(%s)", GetErrorMessage(E_FAILURE));
207                 RemovePlayListPicker();
208                 return E_FAILURE;
209         }
210
211         __pPlayListPicker->SetShowState(true);
212         __pPlayListPicker->Show();
213
214         AppLogDebug("EXIT");
215         return E_SUCCESS;
216 }
217
218 result
219 ContentListForm::SetShowStateCommonPopup(bool isShow)
220 {
221         AppLogDebug("ENTER");
222         if (__pCommonUtilPopupHandler == null)
223         {
224                 AppLogDebug("__pCommonUtilPopupHandler is null");
225                 return E_FAILURE;
226         }
227
228         AppLogDebug("EXIT");
229         return CommonUtil::SetShowStateControl(*__pCommonUtilPopupHandler, isShow);
230 }
231
232 void
233 ContentListForm::RemovCommonPopup(void)
234 {
235         AppLogDebug("ENTER");
236         if (__pCommonUtilPopupHandler != null)
237         {
238                 CommonUtil::SetShowStateControl(*__pCommonUtilPopupHandler, false);
239                 delete __pCommonUtilPopupHandler;
240                 __pCommonUtilPopupHandler = null;
241         }
242         AppLogDebug("EXIT");
243 }
244
245 result
246 ContentListForm::TryRemoveCommonPopup(int actionId)
247 {
248         AppLogDebug("ENTER");
249         result r = E_FAILURE;
250         if (CommonUtil::IsVaildCommonPopupActionId(actionId) == true)
251         {
252                 SetShowStateCommonPopup(false);
253                 RemovCommonPopup();
254                 r = E_SUCCESS;
255         }
256         AppLogDebug("EXIT");
257         return r;
258 }
259
260 void
261 ContentListForm::RemoveSharePicker(void)
262 {
263         AppLogDebug("ENTER");
264         if (__pSharePicker != null)
265         {
266                 CommonUtil::SetShowStateControl(*__pSharePicker, false);
267                 delete __pSharePicker;
268                 __pSharePicker = null;
269         }
270         AppLogDebug("EXIT");
271 }
272
273 void
274 ContentListForm::RemovePlayListPicker(void)
275 {
276         AppLogDebug("ENTER");
277         if (__pPlayListPicker != null )
278         {
279                 CommonUtil::SetShowStateControl(*__pPlayListPicker, false);
280                 delete __pPlayListPicker;
281                 __pPlayListPicker = null;
282         }
283         AppLogDebug("EXIT");
284 }
285
286 void
287 ContentListForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
288 {
289         AppLogDebug("ENTER");
290         UpdateScreenState();
291         AppLogDebug("EXIT");
292 }
293
294 void
295 ContentListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
296 {
297         AppLogDebug("ENTER");
298         AppLogDebug("EXIT");
299 }
300
301 void
302 ContentListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
303 {
304         AppLogDebug("ENTER");
305         AppLogDebug("EXIT");
306 }
307
308 result
309 ContentListForm::TryRemoveContextMenu(int actionId)
310 {
311         AppLogDebug("ENTER");
312         result r = E_FAILURE;
313         if (CommonUtil::IsVaildContextMenuItemActionId(actionId) == true)
314         {
315                 RemoveContextMenu();
316                 r = E_SUCCESS;
317         }
318         AppLogDebug("EXIT");
319         return r;
320 }
321
322 void
323 ContentListForm::OnScrollPositionChanged (Tizen::Ui::Control& source, int scrollPos)
324 {
325         AppLogDebug("ENTER");
326 //      __scrolledDistance = scrollPos;
327         AppLogDebug("EXIT");
328 }
329
330 void
331 ContentListForm::OnScrollEndReached (Tizen::Ui::Control& source, Tizen::Ui::Controls::ScrollEndEvent type)
332 {
333         AppLogDebug("ENTER");
334         AppLogDebug("EXIT");
335 }
336
337 void
338 ContentListForm::OnScrollStopped (Tizen::Ui::Control& source)
339 {
340         AppLogDebug("ENTER");
341         AppLogDebug("EXIT");
342 }
343
344 void
345 ContentListForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
346 {
347         AppLogDebug("ENTER");
348         if (GetScreenState() != SCREEN_STATE_NORMAL)
349         {
350                 ToggleScreenState(SCREEN_STATE_NORMAL);
351                 AppLogDebug("EXIT");
352                 return;
353         }
354
355         SceneManager* pSceneManager = SceneManager::GetInstance();
356         AppAssert(pSceneManager);
357         pSceneManager->GoBackward(BackwardSceneTransition(), null);
358         AppLogDebug("EXIT");
359 }
360
361 void
362 ContentListForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
363 {
364         AppLogDebug("ENTER");
365         if ((requestId != ID_DESTORY_PLAY_LIST_PICKER_POPUP) && (requestId != ID_DESTORY_SHARE_POPUP))
366         {
367                 AppLogDebug("EXIT");
368                 return;
369         }
370
371         if (GetScreenState() != SCREEN_STATE_NORMAL && pArgs != null)
372         {
373                 Boolean* pIsInitialize = static_cast<Boolean*>(pArgs->GetAt(0));
374                 if (pIsInitialize->Equals(true))
375                 {
376                         SetItemCheckedAll(false);
377                 }
378
379                 RemovePlayListPicker();
380                 RemoveSharePicker();
381
382                 pArgs->RemoveAll(true);
383                 delete pArgs;
384         }
385         AppLogDebug("EXIT");
386 }
387
388 void
389 ContentListForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
390 {
391         AppLogDebug("ENTER");
392         UpdateScreenState();
393         AppLogDebug("EXIT");
394 }
395
396 void
397 ContentListForm::OnMusicContentUpdateCompleted(void)
398 {
399         AppLogDebug("ENTER");
400         SetItemCheckedAll(false);
401
402         RemovePlayListPicker();
403         RemoveSharePicker();
404
405         UpdateContentList();
406         UpdateScreenState();
407
408         if (IsEmptyContentList() == false)
409         {
410                 UpdateTableView();
411         }
412         AppLogDebug("EXIT");
413 }
414
415 result
416 ContentListForm::SetShowStateNoContent(bool isShow)
417 {
418         AppLogDebug("ENTER");
419         AppLogDebug("EXIT");
420         return CommonUtil::SetShowStateControl(*__pNoContent, isShow);
421 }
422
423 result
424 ContentListForm::SetShowStateBalloonTooltip(bool isShow)
425 {
426         AppLogDebug("ENTER");
427         int balloonTooltipHeight = INIT_VALUE;
428         if (isShow == true && GetCheckedItemCount() != INIT_VALUE)
429         {
430                 balloonTooltipHeight = H_SHOW_CHECKED_COUNT_BALLOON_TOOL_TIP;
431         }
432         else
433         {
434                 isShow = false;
435         }
436
437         AppLogDebug("EXIT");
438         return CommonUtil::SetShowStateVariableHeightSizeControl(*__pBallonTooltip, balloonTooltipHeight, isShow);
439 }
440
441 void
442 ContentListForm::SetCheckedCountBallonTooltip(unsigned int checkedItemCount)
443 {
444         AppLogDebug("ENTER");
445         if (checkedItemCount == INIT_VALUE)
446         {
447                 SetShowStateBalloonTooltip(false);
448                 return;
449         }
450
451         __pBallonTooltip->SetText(CommonUtil::GetStringItemSelected(checkedItemCount));
452         if (__pBallonTooltip->GetShowState() == false)
453         {
454                 SetShowStateBalloonTooltip(true);
455         }
456         else
457         {
458                 __pBallonTooltip->Invalidate(true);
459         }
460         AppLogDebug("EXIT");
461 }
462
463 result
464 ContentListForm::SetShowStatExtraInformaionArea(bool isShow)
465 {
466         AppLogDebug("ENTER");
467         if (__pExtraInformaionArea == null)
468         {
469                 AppLogDebug("__pExtraInformaionArea is null");
470                 return E_FAILURE;
471         }
472
473         int renewHeight = INIT_VALUE;
474         if (isShow == true)
475         {
476                 renewHeight = __heightExtraInformaionArea;
477         }
478
479         AppLogDebug("EXIT");
480         return CommonUtil::SetShowStateVariableHeightSizeControl(*__pExtraInformaionArea, renewHeight, isShow);
481 }
482
483 result
484 ContentListForm::SetShowStateContentList(bool isShow)
485 {
486         AppLogDebug("ENTER");
487         if (__pContentList == null)
488         {
489                 AppLogDebug("__pContentList is null");
490                 return E_FAILURE;
491         }
492
493         AppLogDebug("EXIT");
494         return CommonUtil::SetShowStateControl(*__pContentList, isShow);
495 }
496
497 result
498 ContentListForm::SetExtraInformaionArea(Tizen::Ui::Control& control)
499 {
500         AppLogDebug("ENTER");
501         RemoveExtraInformaionArea();
502         if (IsExistExtraInformaionArea() == false)
503         {
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);
510                 return E_SUCCESS;
511         }
512         AppLogDebug("EXIT");
513         return E_FAILURE;
514 }
515
516 Tizen::Ui::Control*
517 ContentListForm::GetExtraInformaionAreaControl(void)
518 {
519         AppLogDebug("ENTER");
520         if (IsExistExtraInformaionArea() == false)
521         {
522                 AppLogDebug("AdditionalInforamtion is not Registered");
523                 return null;
524         }
525
526         AppLogDebug("EXIT");
527         return __pExtraInformaionArea->GetControl(INIT_VALUE);
528 }
529
530 bool
531 ContentListForm::IsExistExtraInformaionArea(void)
532 {
533         AppLogDebug("ENTER");
534         if (__pExtraInformaionArea!= null && __pExtraInformaionArea->GetControlCount() != INIT_VALUE)
535         {
536                 AppLogDebug("EXIT");
537                 return true;
538         }
539         AppLogDebug("EXIT");
540         return false;
541 }
542
543 void
544 ContentListForm::RemoveExtraInformaionArea(void)
545 {
546         AppLogDebug("ENTER");
547         if (__pExtraInformaionArea != null)
548         {
549                 __heightExtraInformaionArea = INIT_VALUE;
550                 __pExtraInformaionArea->RemoveAllControls();
551         }
552         AppLogDebug("EXIT");
553 }
554
555 void
556 ContentListForm::UpdateScreenState(void)
557 {
558         AppLogDebug("ENTER");
559         if (IsEmptyContentList() == true)
560         {
561                 SetShowStateContentList(false);
562                 SetShowStateBalloonTooltip(false);
563                 SetShowStatExtraInformaionArea(false);
564                 SetShowStateNoContent(true);
565
566                 GetHeader()->SetButtonEnabled(BUTTON_POSITION_RIGHT, false);
567                 GetHeader()->Invalidate(true);
568                 AppLogDebug("EXIT");
569                 return;
570         }
571
572         if (GetScreenState() != SCREEN_STATE_NORMAL)
573         {
574                 SetShowStateBalloonTooltip(true);
575                 SetShowStatExtraInformaionArea(false);
576         }
577         else
578         {
579                 SetShowStateBalloonTooltip(false);
580                 SetShowStatExtraInformaionArea(true);
581         }
582
583         SetShowStateNoContent(false);
584         SetShowStateContentList(true);
585         AppLogDebug("EXIT");
586 }
587
588 result
589 ContentListForm::ToggleScreenState(ScreenState screenState)
590 {
591         AppLogDebug("ENTER");
592         if (IsFailed(SetScreenState(screenState)))
593         {
594                 AppLogDebug("SetScreenState() failed(%s)", GetErrorMessage(E_FAILURE));
595                 return E_FAILURE;
596         }
597
598         if (screenState == SCREEN_STATE_NORMAL)
599         {
600                 SetHeader();
601                 SetFooter();
602                 SetItemCheckedAll(false);
603         }
604         else
605         {
606                 if (screenState == SCREEN_STATE_EDITOR)
607                 {
608                         CommonUtil::SetEditHeaderStyle(*GetHeader(), ResourceManager::GetString(L"IDS_COM_BODY_EDIT"));
609                         CommonUtil::SetBackButtonStyleFooter(*GetFooter(), STYLE_ADDTO_DELETE_ADD);
610                 }
611                 else if (screenState == SCREEN_STATE_SHARE_VIA)
612                 {
613                         CommonUtil::SetEditHeaderStyle(*GetHeader(), ResourceManager::GetString(L"IDS_IV_BODY_SHARE_VIA"));
614                         CommonUtil::SetBackButtonStyleFooter(*GetFooter(), STYLE_SHARE_ADD);
615                 }
616
617                 GetHeader()->Invalidate(true);
618                 SetCheckedCountBallonTooltip(GetCheckedItemCount());
619                 CommonUtil::SetFooterItemEnabled(*GetFooter(), false);
620         }
621
622         UpdateScreenState();
623         UpdateTableView();
624         AppLogDebug("EXIT");
625         return E_SUCCESS;
626 }
627
628 result
629 ContentListForm::CreateContextMenuN(const Tizen::Ui::Control& source)
630 {
631         AppLogDebug("ENTER");
632         RemoveContextMenu();
633         __pContextMenu = CommonUtil::CreateContextMenuN(source, *this);
634         if (__pContextMenu != null)
635         {
636                 return E_SUCCESS;
637         }
638         AppLogDebug("EXIT");
639         return E_FAILURE;
640 }
641
642 result
643 ContentListForm::SetContextMenuItem(unsigned int contextMenuItemStyle, Tizen::Graphics::Point anchorPosition)
644 {
645         AppLogDebug("ENTER");
646         if (__pContextMenu == null)
647         {
648                 AppLogDebug("EXIT");
649                 return E_FAILURE;
650         }
651
652         CommonUtil::AddContextMenuItem(*__pContextMenu, contextMenuItemStyle);
653         CommonUtil::ShowContextMenu(*__pContextMenu, true);
654
655         Point prevAnchorPosition = __pContextMenu->GetAnchorPosition();
656         if (anchorPosition.x != -1)
657         {
658                 prevAnchorPosition.x = anchorPosition.x;
659         }
660
661         if (anchorPosition.y != -1)
662         {
663                 prevAnchorPosition.y = anchorPosition.y;
664         }
665
666         __pContextMenu->SetAnchorPosition(prevAnchorPosition);
667         AppLogDebug("EXIT");
668         return E_SUCCESS;
669 }
670
671 void
672 ContentListForm::RemoveContextMenu(void)
673 {
674         AppLogDebug("ENTER");
675         if (__pContextMenu != null)
676         {
677                 CommonUtil::SetShowStateControl(*__pContextMenu, false);
678                 delete __pContextMenu;
679                 __pContextMenu = null;
680         }
681         AppLogDebug("EXIT");
682 }
683
684 ScreenState
685 ContentListForm::GetScreenState(void)
686 {
687         AppLogDebug("ENTER");
688         AppLogDebug("EXIT");
689         return __screenState;
690 }
691
692 result
693 ContentListForm::SetScreenState(ScreenState screenState)
694 {
695         AppLogDebug("ENTER");
696         result r = E_FAILURE;
697         if (__screenState != screenState && screenState != SCREEN_STATE_MAX)
698         {
699                 __screenState = screenState;
700                 r = E_SUCCESS;
701         }
702         AppLogDebug("EXIT");
703         return r;
704 }
705
706 result
707 ContentListForm::RemoveContentAt(const Tizen::Content::ContentId& contentId)
708 {
709         AppLogDebug("ENTER");
710         ContentManager contentManager;
711         contentManager.Construct();
712
713         if (IsFailed(contentManager.DeleteContent(contentId)))
714         {
715                 AppLogDebug("DeleteContent(%ls) failed", contentId.ToString().GetPointer());
716                 return GetLastResult();
717         }
718         AppLogDebug("EXIT");
719         return E_SUCCESS;
720 }
721
722 void
723 ContentListForm::UpdateExtraInformaionArea(void)
724 {
725         AppLogDebug("ENTER");
726         AppLogDebug("EXIT");
727 }