Applied latest source code
[apps/native/preloaded/MusicPlayer.git] / src / MpArtistListEditorPanel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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                MpArtistListEditorPanel.cpp
19  * @brief               This is the implementation file for ArtistListEditorPanel class.
20  */
21
22 #include "MpArtistListEditorPanel.h"
23 #include "MpThumbnailInfo.h"
24
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Collection;
27 using namespace Tizen::Content;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Social;
30 using namespace Tizen::Ui;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Scenes;
33
34 ArtistListEditorPanel::ArtistListEditorPanel(void)
35         : ContentEditPanel::ContentEditPanel()
36         , ThumbnailBase::ThumbnailBase()
37         , __pThumbnail(null)
38 {
39         AppLogDebug("ENTER");
40         AppLogDebug("EXIT");
41 }
42
43 ArtistListEditorPanel::~ArtistListEditorPanel(void)
44 {
45         AppLogDebug("ENTER");
46         AppLogDebug("EXIT");
47 }
48
49 result
50 ArtistListEditorPanel::OnInitializing(void)
51 {
52         AppLogDebug("ENTER");
53         __pPresentationModel = ArtistListPresentationModel::GetInstance();
54         __fontSizeValue = CommonUtil::GetFontSizeValue();
55         __itemHeight = CommonUtil::GetItemHeight(__fontSizeValue);
56
57         UpdateContentList();
58         SetLayoutFitToForm();
59         AppLogDebug("EXIT");
60         return ThumbnailBase::Construct();
61 }
62
63 void
64 ArtistListEditorPanel::OnFontSizeChanged(void)
65 {
66         __fontSizeValue = CommonUtil::GetFontSizeValue();
67         __itemHeight = CommonUtil::GetItemHeight(__fontSizeValue);
68         __pContentTableView->UpdateTableView();
69
70 }
71
72 result
73 ArtistListEditorPanel::OnTerminating(void)
74 {
75         AppLogDebug("ENTER");
76         ThumbnailBase::Stop();
77         AppLogDebug("EXIT");
78         return ContentEditPanel::OnTerminating();
79 }
80
81 void
82 ArtistListEditorPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
83 {
84         AppLogDebug("ENTER");
85         SceneManager* pSceneManager = SceneManager::GetInstance();
86         AppAssert(pSceneManager);
87
88         int totalCount = __pPresentationModel->GetArtistListCount();
89
90         switch (actionId)
91         {
92         case IDA_HEADER_BUTTON_SELECTE_ALL:
93                 {
94                         if (totalCount == __checkedItemCount)
95                         {
96                                 SetItemCheckedAll(false);
97                         }
98                         else
99                         {
100                                 SetItemCheckedAll(true);
101                         }
102                 }
103                 break;
104
105         case IDA_FOOTER_BUTTON_ADD_TO_PLAYLIST:
106                 {
107                         LanucherPicker(PICKER_TYPE_PLAY_LIST_PICKER);
108                 }
109                 break;
110
111         case IDA_FOOTER_BUTTON_DELETE:
112                 {
113                         ShowCommonDeletePopup(this);
114                 }
115                 break;
116
117         case IDA_DELETE_POPUP_DELETE:
118                 {
119                         for (int iCount = totalCount - 1; iCount >= 0; iCount--)
120                         {
121                                 if (__pContentTableView->IsItemChecked(iCount) == true)
122                                 {
123                                         __pPresentationModel->RemoveArtistList(iCount);
124                                 }
125                         }
126
127                         HideCommonDeletePopup(false);
128                 }
129                 break;
130
131         case IDA_DELETE_POPUP_CANCEL:
132         {
133                 HideCommonDeletePopup(false);
134         }
135         break;
136         default:
137                 break;
138         }
139         AppLogDebug("EXIT");
140 }
141
142 void
143 ArtistListEditorPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
144                                                 const Tizen::Ui::Scenes::SceneId& currentSceneId,
145                                                 Tizen::Base::Collection::IList* pArgs)
146 {
147         AppLogDebug("ENTER");
148         ContentPanel::OnSceneActivatedN(previousSceneId, currentSceneId, null);
149
150         Form* pForm = dynamic_cast<Form*>(GetParent());
151         AppAssert(pForm);
152         pForm->SetFormBackEventListener(this);
153         SetEditHeaderStyle();
154
155         SetFooterStyle(STYLE_ADDTO_DELETE_ADD);
156         SetFormStyle();
157         Footer* pFooter = CommonUtil::CreateBackButtonStyleFooter(*pForm, STYLE_ADDTO_DELETE_ADD);
158         if (pFooter != null)
159         {
160                 pFooter->AddActionEventListener(*this);
161                 pFooter->SetShowState(true);
162                 CommonUtil::SetFooterItemEnabled(*pFooter, false);
163         }
164
165         UpdateContentEditScreenState();
166
167         if (previousSceneId.Equals(IDSCN_PLAYLIST_CREATOR, true))
168         {
169                 if (pArgs != null)
170                 {
171                         int totalCount = 0;
172                         __pContentTableView->UpdateTableView();
173                         __checkedItemCount = INIT_VALUE;
174                         SetCheckedCountBallonTooltip(__checkedItemCount);
175
176                         totalCount = __pPresentationModel->GetArtistListCount();
177                         for (int count = 0; count < totalCount; count++)
178                         {
179                                 __pContentTableView->SetItemChecked(count, false);
180                         }
181                 }
182                 else
183                 {
184                         if (pFooter != null && __checkedItemCount != 0)
185                         {
186                                 CommonUtil::SetFooterItemEnabled(*pFooter, true);
187                         }
188                 }
189         }
190
191         if (pArgs != null)
192         {
193                 pArgs->RemoveAll(true);
194                 delete pArgs;
195         }
196         AppLogDebug("EXIT");
197 }
198
199 void
200 ArtistListEditorPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
201                                                                         const Tizen::Ui::Scenes::SceneId& nextSceneId)
202 {
203         AppLogDebug("ENTER");
204         ContentPanel::OnSceneDeactivated(currentSceneId, nextSceneId);
205         if (!(nextSceneId.Equals(IDSCN_PLAYLIST_CREATOR, false)))
206         {
207                 Footer* pFooter = GetFooter();
208                 if (pFooter != null)
209                 {
210                         pFooter->RemoveAllButtons();
211                         pFooter->RemoveAllItems();
212                         pFooter->RemoveActionEventListener(*this);
213                 }
214
215                 __checkedItemCount = INIT_VALUE;
216                 SetCheckedCountBallonTooltip(__checkedItemCount);
217                 int totalCount = __pPresentationModel->GetArtistListCount();
218                 for (int iCount = 0; iCount < totalCount; iCount++)
219                 {
220                         __pContentTableView->SetItemChecked(iCount, false);
221                 }
222         }
223         CancelAllThumbnailRequest();
224         AppLogDebug("EXIT");
225 }
226
227 int
228 ArtistListEditorPanel::GetItemCount(void)
229 {
230         AppLogDebug("ENTER");
231         if (__pContentTableView == null)
232         {
233                 return INIT_VALUE;
234         }
235
236         AppLogDebug("EXIT");
237         return __pPresentationModel->GetArtistListCount();
238 }
239
240 Tizen::Ui::Controls::TableViewItem*
241 ArtistListEditorPanel::CreateItem(const int itemIndex, int itemWidth)
242 {
243         AppLogDebug("ENTER");
244         RelativeLayout layout;
245         layout.Construct();
246
247         TableViewItem* pItem = new (std::nothrow) TableViewItem();
248         ContentInformation* pContentInfo = __pPresentationModel->GetArtistnIfoN(itemIndex);
249
250         result r = pItem->Construct(layout, Dimension(itemWidth, __itemHeight), TABLE_VIEW_ANNEX_STYLE_MARK);
251         TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
252         TryCatch(pContentInfo != null, delete pItem, "pContentInfo is null", GetErrorMessage(GetLastResult()));
253
254         r = CreateTableViewItem(*pItem, *pContentInfo);
255         TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
256
257         RequestThumbnail(pContentInfo->contentId, (new (std::nothrow) Integer(itemIndex)));
258         delete pContentInfo;
259
260         AppLogDebug("EXIT");
261         return pItem;
262
263 CATCH:
264         AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
265         delete pContentInfo;
266         return null;
267 }
268
269 void
270 ArtistListEditorPanel::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
271                                                                 int itemIndex,
272                                                                 Tizen::Ui::Controls::TableViewItem* pItem,
273                                                                 Tizen::Ui::Controls::TableViewItemStatus status)
274 {
275         AppLogDebug("ENTER");
276         Form* pForm = dynamic_cast<Form*>(GetParent());
277         AppAssert(pForm);
278
279         Footer* pFooter = pForm->GetFooter();
280
281         switch (status)
282         {
283         case TABLE_VIEW_ITEM_STATUS_CHECKED:
284                 {
285                         __checkedItemCount++;
286                         tableView.SetItemChecked(itemIndex, true);
287                 }
288                 break;
289
290         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
291                 {
292                         __checkedItemCount--;
293                         tableView.SetItemChecked(itemIndex, false);
294                 }
295                 break;
296
297         default:
298                 break;
299         }
300
301         if (__checkedItemCount > INIT_VALUE)
302         {
303                 if (pFooter != null)
304                 {
305                         CommonUtil::SetFooterItemEnabled(*pFooter, true);
306                 }
307         }
308         else
309         {
310                 if (pFooter != null)
311                 {
312                         CommonUtil::SetFooterItemEnabled(*pFooter, false);
313                 }
314         }
315
316         SetCheckedCountBallonTooltip(__checkedItemCount);
317         Invalidate(true);
318         AppLogDebug("EXIT");
319 }
320
321 result
322 ArtistListEditorPanel::CreateTableViewItem(Tizen::Ui::Container& parent,
323                                                         const ContentInformation& contentInfoStruct)
324 {
325         AppLogDebug("ENTER");
326         result r = E_SUCCESS;
327
328         Panel* pTableViewItem =  new (std::nothrow) Panel();
329
330         if (__fontSizeValue.Equals(STRING_FONT_SIZE_GIANT, false))
331         {
332                 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_ARTIST_EDITOR_ITEM_PANEL_FONT_SIZE_GIANT)))
333                 {
334                         AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
335                         return E_FAILURE;
336                 }
337         }
338         else if (__fontSizeValue.Equals(STRING_FONT_SIZE_HUGE, false))
339         {
340                 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_ARTIST_EDITOR_ITEM_PANEL_FONT_SIZE_HUGE)))
341                 {
342                         AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
343                         return E_FAILURE;
344                 }
345         }
346         else if (__fontSizeValue.Equals(STRING_FONT_SIZE_LARGE, false))
347         {
348                 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_ARTIST_EDITOR_ITEM_PANEL_FONT_SIZE_LARGE)))
349                 {
350                         AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
351                         return E_FAILURE;
352                 }
353         }
354         else if (__fontSizeValue.Equals(STRING_FONT_SIZE_SMALL, false))
355         {
356                 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_ARTIST_EDITOR_ITEM_PANEL_FONT_SIZE_SMALL)))
357                 {
358                         AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
359                         return E_FAILURE;
360                 }
361         }
362         else
363         {
364                 if (IsFailed(pTableViewItem->Construct(IDL_CONTENTS_ARTIST_EDITOR_ITEM_PANEL_DEFAULT)))
365                 {
366                         AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
367                         return E_FAILURE;
368                 }
369         }
370
371         static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENTS_ARTIST_NAME))->SetText(contentInfoStruct.ArtistName);
372 //      static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENTS_THUMBNAIL))->SetBackgroundBitmap(*GetDefaultThumbnail());
373
374         parent.AddControl(pTableViewItem);
375         CommonUtil::SetLayoutFitToContainer(parent, *pTableViewItem);
376
377         AppLogDebug("EXIT");
378         return r;
379 }
380
381 void
382 ArtistListEditorPanel::UpdateContentList(void)
383 {
384         AppLogDebug("ENTER");
385         if (__pPresentationModel != null)
386         {
387                 __pPresentationModel->UpdateArtistList();
388         }
389         AppLogDebug("EXIT");
390 }
391
392 void
393 ArtistListEditorPanel::SetEditHeaderStyle(void)
394 {
395         AppLogDebug("ENTER");
396         Header* pHeader = GetHeader();
397         String titleText(ResourceManager::GetString(L"IDS_COM_BODY_EDIT"));
398         CommonUtil::SetEditHeaderStyle(*pHeader, titleText);
399         pHeader->Invalidate(true);
400         AppLogDebug("EXIT");
401 }
402
403 void
404 ArtistListEditorPanel::OnThumbnailInfoReveivedN(ThumbnailInfo* pThumbnailInfo)
405 {
406         AppLogDebug("ENTER");
407         __pThumbnail = pThumbnailInfo->GetBitmapN();
408         Object* pParam = pThumbnailInfo->GetUserParamN();
409         if (pParam != null)
410         {
411                 __pContentTableView->RefreshItem((static_cast<Integer*>(pParam))->ToInt(), TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
412                 delete pParam;
413         }
414
415         delete pThumbnailInfo;
416         AppLogDebug("EXIT");
417 }
418
419 void
420 ArtistListEditorPanel::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
421 {
422         AppLogDebug("ENTER");
423         SceneManager* pSceneManager = SceneManager::GetInstance();
424         AppAssert(pSceneManager);
425
426         pSceneManager->GoBackward(BackwardSceneTransition());
427         AppLogDebug("EXIT");
428 }
429
430 void
431 ArtistListEditorPanel::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
432 {
433         AppLogDebug("ENTER");
434
435         if (pItem == null)
436         {
437                 AppLogDebug("pItem is null");
438                 delete __pThumbnail;
439                 __pThumbnail = null;
440                 return;
441         }
442
443         Label* pThumbnailLabel = static_cast<Label*>(pItem->GetControl(IDC_CONTENTS_THUMBNAIL, true));
444         if (__pThumbnail == null || pThumbnailLabel == null)
445         {
446                 AppLogDebug("__pThumbnail or pThumbnailLabel is null");
447                 delete __pThumbnail;
448                 __pThumbnail = null;
449                 return;
450         }
451
452         pThumbnailLabel->SetBackgroundBitmap(*__pThumbnail);
453         delete __pThumbnail;
454         __pThumbnail = null;
455         pThumbnailLabel->Invalidate(true);
456         AppLogDebug("EXIT");
457 }
458
459 bool
460 ArtistListEditorPanel::IsEmptyContentList(void)
461 {
462         AppLogDebug("ENTER");
463         if (__pPresentationModel->GetArtistListCount() == INIT_VALUE)
464         {
465                 AppLogDebug("EXIT");
466                 return true;
467         }
468         AppLogDebug("EXIT");
469         return false;
470 }
471
472 Tizen::Base::Collection::IList*
473 ArtistListEditorPanel::GetPickerArgumentListN(PickerType pickerType, PickerArgumentType argumentType)
474 {
475         AppLogDebug("ENTER");
476         ArrayList* pContentPathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
477         result r = pContentPathList->Construct();
478         if (IsFailed(r))
479         {
480                 AppLogDebug("pContentList->Construct failed(%s)", GetErrorMessage(r));
481                 delete pContentPathList;
482                 return null;
483         }
484
485         if (pickerType == PICKER_TYPE_PLAY_LIST_PICKER && argumentType == PICKER_ARGUMENT_TYPE_CHECKED_ITEM_ALL)
486         {
487                 int totalCount = __pPresentationModel->GetArtistListCount();
488                 for (int iCount = 0; iCount < totalCount; iCount++)
489                 {
490                         if (__pContentTableView->IsItemChecked(iCount) == true)
491                         {
492                                 pContentPathList->AddItems(*(__pPresentationModel->GetContentPathListN(iCount)));
493                         }
494                 }
495         }
496         else
497         {
498                 AppLogDebug("EXIT");
499                 delete pContentPathList;
500                 return null;
501         }
502
503         AppLogDebug("EXIT");
504         return pContentPathList;
505 }