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