Applied latest source code
[apps/native/preloaded/MusicPlayer.git] / src / MpGenreListEditorPanel.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                MpGenreListEditorPanel.cpp
19  * @brief               This is the implementation file for GenreListEditorPanel class.
20  */
21
22 #include "MpGenreListEditorPanel.h"
23 #include "MpPlaylistPickerPopup.h"
24 #include "MpThumbnailInfo.h"
25
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::Content;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Social;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Scenes;
33
34 GenresListEditorPanel::GenresListEditorPanel(void)
35         : ThumbnailBase::ThumbnailBase()
36         , __checkedItemCount(0)
37         , __pContentTableView(null)
38         , __pSelectAllCheckedButton(null)
39         , __pCheckedCountLabel(null)
40         , __pThumbnail(null)
41         , __pPlayListPickerPopup(null)
42 {
43         AppLogDebug("ENTER");
44         AppLogDebug("EXIT");
45 }
46
47 GenresListEditorPanel::~GenresListEditorPanel(void)
48 {
49         AppLogDebug("ENTER");
50         AppLogDebug("EXIT");
51 }
52
53 bool
54 GenresListEditorPanel::Initialize(void)
55 {
56         AppLogDebug("ENTER");
57         result r = BasePanel::Construct(Rectangle(INIT_VALUE, INIT_VALUE, INIT_VALUE, INIT_VALUE));
58         if (IsFailed(r))
59         {
60                 return false;
61         }
62         AppLogDebug("EXIT");
63         return true;
64 }
65
66 result
67 GenresListEditorPanel::OnInitializing(void)
68 {
69         AppLogDebug("ENTER");
70         __pPresentationModel = GenreListPresentationModel::GetInstance();
71
72         Form* pForm = dynamic_cast<Form*>(GetParent());
73         AppAssert(pForm);
74
75         int width = pForm->GetClientAreaBounds().width;
76         int height = pForm->GetClientAreaBounds().height;
77
78         SetBounds(INIT_VALUE, INIT_VALUE, width, height);
79
80         __pContentTableView = CommonUtil::CreateEditorTableView(width, height);
81         __pContentTableView->AddTableViewItemEventListener(*this);
82         __pContentTableView->SetItemProvider(this);
83
84         __pSelectAllCheckedButton = CommonUtil::CreateSelectAllCheckedButton(width);
85         __pSelectAllCheckedButton->AddActionEventListener(*this);
86
87         __pCheckedCountLabel = CommonUtil::CreateCheckedCountLabel(width, height);
88         __pCheckedCountLabel->SetShowState(false);
89
90         AddControl(__pContentTableView);
91         AddControl(__pSelectAllCheckedButton);
92         AddControl(__pCheckedCountLabel);
93
94         AppLogDebug("EXIT");
95         return ThumbnailBase::Construct();
96 }
97
98 result
99 GenresListEditorPanel::OnTerminating(void)
100 {
101         AppLogDebug("ENTER");
102         AppLogDebug("EXIT");
103         return E_SUCCESS;
104 }
105
106 void
107 GenresListEditorPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
108 {
109         AppLogDebug("ENTER");
110         SceneManager* pSceneManager = SceneManager::GetInstance();
111         AppAssert(pSceneManager);
112
113         int totalCount = __pPresentationModel->GetAllGenreCount();
114
115         switch (actionId)
116         {
117         case IDA_CHECK_BUTTON:
118                 {
119                         __checkedItemCount = totalCount;
120                         CommonUtil::SetAllCheckState(true, *__pContentTableView, totalCount);
121                         Form* pForm = dynamic_cast<Form*>(GetParent());
122                         AppAssert(pForm);
123                         CommonUtil::ShowCheckedCountLabel(*__pCheckedCountLabel, __checkedItemCount, *__pContentTableView, *pForm);
124                 }
125                 break;
126
127         case IDA_UNCHECK_BUTTON:
128                 {
129                         __checkedItemCount = INIT_VALUE;
130                         CommonUtil::SetAllCheckState(false, *__pContentTableView, totalCount);
131                         Form* pForm = dynamic_cast<Form*>(GetParent());
132                         AppAssert(pForm);
133                         CommonUtil::ShowCheckedCountLabel(*__pCheckedCountLabel, __checkedItemCount, *__pContentTableView, *pForm);
134                 }
135                 break;
136
137         case IDA_FOOTER_BUTTON_ADD_TO_PLAYLIST:
138                 {
139                         if (__checkedItemCount <= INIT_VALUE)
140                         {
141                                 return;
142                         }
143
144                         ArrayList* pDataList = new (std::nothrow) ArrayList();
145                         pDataList->Construct();
146
147                         int totalCount = __pPresentationModel->GetAllGenreCount();
148                         for (int iCount = 0; iCount < totalCount; iCount++)
149                         {
150                                 if (__pContentTableView->IsItemChecked(iCount) == true)
151                                 {
152                                         pDataList->AddItems(*(__pPresentationModel->GetContentPathListN(iCount)));
153                                 }
154                         }
155
156                         __pPlayListPickerPopup = new (std::nothrow) PlayListPickerPopup();
157                         __pPlayListPickerPopup->Initialize(this, pDataList);
158                         //__pPlayListPickerPopup->SetCollectedContent(pDataList);
159                         __pPlayListPickerPopup->SetShowState(true);
160                         __pPlayListPickerPopup->Show();
161                 }
162                 break;
163
164         case IDA_FOOTER_BUTTON_CANCEL:
165                 {
166                         pSceneManager->GoBackward(BackwardSceneTransition());
167                 }
168                 break;
169
170         default:
171                 break;
172         }
173
174         Form* pForm = dynamic_cast<Form*>(GetParent());
175         AppAssert(pForm);
176         CommonUtil::SetButtonEnabled(*pForm, __checkedItemCount, actionId);
177         AppLogDebug("EXIT");
178 }
179
180 void
181 GenresListEditorPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
182                                                                 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
183 {
184         AppLogDebug("ENTER");
185         Form* pForm = dynamic_cast<Form*>(GetParent());
186         AppAssert(pForm);
187
188         Footer* pFooter = CommonUtil::CreateAddtoPlaylistPickerFooter(*pForm);
189         pFooter->AddActionEventListener(*this);
190
191         CommonUtil::SetButtonEnabled(*pForm, __checkedItemCount);
192
193         UpdateContentList();
194
195         if (pArgs != null)
196         {
197                 pArgs->RemoveAll(true);
198                 delete pArgs;
199         }
200         AppLogDebug("EXIT");
201 }
202
203 void
204 GenresListEditorPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
205                                                                         const Tizen::Ui::Scenes::SceneId& nextSceneId)
206 {
207         AppLogDebug("ENTER");
208         Form* pForm = dynamic_cast<Form*>(GetParent());
209         AppAssert(pForm);
210
211         Footer* pFooter = pForm->GetFooter();
212         if (pFooter != null)
213         {
214                 pFooter->RemoveAllButtons();
215                 pFooter->RemoveAllItems();
216                 pFooter->RemoveActionEventListener(*this);
217         }
218
219         __checkedItemCount = INIT_VALUE;
220         CommonUtil::ShowCheckedCountLabel(*__pCheckedCountLabel, __checkedItemCount, *__pContentTableView, *pForm);
221         CommonUtil::ShowSelectAllCheckButton(*__pSelectAllCheckedButton);
222
223         int totalCount = __pPresentationModel->GetAllGenreCount();
224         for (int iCount = 0; iCount < totalCount; iCount++)
225         {
226                 __pContentTableView->SetItemChecked(iCount, false);
227         }
228         
229         CancelAllThumbnailRequest();
230         AppLogDebug("EXIT");
231 }
232
233 int
234 GenresListEditorPanel::GetItemCount(void)
235 {
236         AppLogDebug("ENTER");
237         if (__pPresentationModel == null)
238         {
239                 return INIT_VALUE;
240         }
241
242         AppLogDebug("EXIT");
243         return __pPresentationModel->GetAllGenreCount();
244 }
245
246 Tizen::Ui::Controls::TableViewItem*
247 GenresListEditorPanel::CreateItem(const int itemIndex, int itemWidth)
248 {
249         AppLogDebug("ENTER");
250         ContentInformation* pContentInfoStruct = __pPresentationModel->GetGenreInfoN(itemIndex);
251         if (pContentInfoStruct == null)
252         {
253                 return null;
254         }
255
256         TableViewItem* pItem = new (std::nothrow) TableViewItem();
257         pItem->Construct(Dimension(itemWidth, ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_MARK);
258 //      pItem->SetBackgroundColor(COLOR_ITEM);
259
260 //      RequestThumbnail(pContentInfoStruct->contentId, (new (std::nothrow) int(itemIndex)));
261         CommonUtil::CreateEditListTableViewItem(*pItem, *GetDefaultThumbnail(), pContentInfoStruct->GenreName, __pPresentationModel->GetContentCount(itemIndex));
262
263         delete pContentInfoStruct;
264         pContentInfoStruct = null;
265
266         AppLogDebug("EXIT");
267         return pItem;
268 }
269
270 bool
271 GenresListEditorPanel::DeleteItem(const int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
272 {
273         AppLogDebug("ENTER");
274         AppLogDebug("EXIT");
275         return false;
276 }
277
278 int
279 GenresListEditorPanel::GetDefaultItemHeight(void)
280 {
281         AppLogDebug("ENTER");
282         AppLogDebug("EXIT");
283         return ITEM_HEIGHT;
284 }
285
286 void
287 GenresListEditorPanel::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
288                                                         int itemIndex,
289                                                         Tizen::Ui::Controls::TableViewItem* pItem,
290                                                         Tizen::Ui::Controls::TableViewItemStatus status)
291 {
292         AppLogDebug("ENTER");
293         switch(status)
294         {
295         case TABLE_VIEW_ITEM_STATUS_CHECKED:
296                 {
297                         __checkedItemCount++;
298                         tableView.SetItemChecked(itemIndex, true);
299                 }
300                 break;
301
302         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
303                 {
304                         __checkedItemCount--;
305                         tableView.SetItemChecked(itemIndex, false);
306                 }
307                 break;
308
309         default:
310                 break;
311         }
312
313         Form* pForm = dynamic_cast<Form*>(GetParent());
314         AppAssert(pForm);
315         CommonUtil::SetButtonEnabled(*pForm, __checkedItemCount);
316
317         CommonUtil::ShowSelectAllCheckButton(*__pSelectAllCheckedButton);
318
319         if (__checkedItemCount == __pPresentationModel->GetAllGenreCount())
320         {
321                 __pSelectAllCheckedButton->SetSelected(true);
322         }
323
324         Invalidate(true);
325         CommonUtil::ShowCheckedCountLabel(*__pCheckedCountLabel, __checkedItemCount, *__pContentTableView, *pForm);
326         AppLogDebug("EXIT");
327 }
328
329 void
330 GenresListEditorPanel::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView,
331                                                                                 int itemIndex,
332                                                                                 Tizen::Ui::Controls::TableViewContextItem* pContextItem,
333                                                                                 bool activated)
334 {
335         AppLogDebug("ENTER");
336         AppLogDebug("EXIT");
337 }
338
339 void
340 GenresListEditorPanel::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView,
341                                                         int itemIndexFrom,
342                                                         int itemIndexTo)
343 {
344         AppLogDebug("ENTER");
345         AppLogDebug("EXIT");
346 }
347
348 void
349 GenresListEditorPanel::OnMusicContentUpdateCompleted(void)
350 {
351         AppLogDebug("ENTER");
352         UpdateContentList();
353         AppLogDebug("EXIT");
354 }
355
356 void
357 GenresListEditorPanel::UpdateContentList(void)
358 {
359         AppLogDebug("ENTER");
360         if (__pPresentationModel != null && __pContentTableView != null)
361         {
362                 __pPresentationModel->UpdateGnereList();
363                 __pContentTableView->UpdateTableView();
364         }
365         AppLogDebug("EXIT");
366 }
367
368 void
369 GenresListEditorPanel::OnThumbnailInfoReveivedN(ThumbnailInfo* pThumbnailInfo)
370 {
371         AppLogDebug("ENTER");
372         int itemIndex = 0;
373         void* pParam = null;
374         __pThumbnail = pThumbnailInfo->GetBitmapN();
375         pParam = pThumbnailInfo->GetUserParamN();
376         if (pParam)
377         {
378                 itemIndex = *(static_cast<int*>(pParam));
379         }
380         __pContentTableView->RefreshItem(itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
381         delete pThumbnailInfo;
382         delete static_cast<int*>(pParam);
383         AppLogDebug("EXIT");
384 }
385
386 void
387 GenresListEditorPanel::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
388 {
389         AppLogDebug("ENTER");
390         AppLogDebug("OnUserEventReceivedN %d", requestId);
391         if (requestId == ID_DESTORY_PLAY_LIST_PICKER_POPUP)
392         {
393                 if (__pPlayListPickerPopup != null)
394                 {
395                         delete __pPlayListPickerPopup;
396                         __pPlayListPickerPopup = null;
397                 }
398         }
399         AppLogDebug("EXIT");
400 }
401
402 void
403 GenresListEditorPanel::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
404 {
405         AppLogDebug("ENTER");
406         Label* pThumbnailLabel = static_cast<Label*>(pItem->GetControl(L"pSongThumbnailLabel"));
407         if (__pThumbnail == null || pThumbnailLabel == null)
408         {
409                 AppLogDebug("__pThumbnail or pThumbnailLabel is null");
410                 delete __pThumbnail;
411                 __pThumbnail = null;
412                 return;
413         }
414         pThumbnailLabel->SetBackgroundBitmap(*__pThumbnail);
415         delete __pThumbnail;
416         __pThumbnail = null;
417         pThumbnailLabel->Invalidate(true);
418         AppLogDebug("EXIT");
419 }