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