Fixed jira issues : N_SE-56423, N_SE-56330, N_SE-56326
[apps/osp/MusicPlayer.git] / src / MpFolderContentListForm.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                MpFolderContentListForm.cpp
19  * @brief               This is the implementation file for FolderContentListForm class.
20  */
21
22 #include <FSocial.h>
23 #include "MpFolderContentListForm.h"
24 #include "MpFolderListPresentationModel.h"
25 #include "MpMusicPlayerApp.h"
26 #include "MpPlaylistPickerPopup.h"
27 #include "MpSharePopup.h"
28 #include "MpThumbnailInfo.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Content;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Io;
36 using namespace Tizen::Social;
37 using namespace Tizen::System;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
41
42 FolderContentListForm::FolderContentListForm(void)
43         : ContentListForm::ContentListForm()
44         , ThumbnailBase::ThumbnailBase()
45         , __pTableViewContextItem(null)
46         , __pThumbnail(null)
47         , __pCurrentFolderPath(null)
48         , __pPresentationModel(null)
49         , __checkedItemCount(0)
50         , __currentFolderIndex(0)
51         , __activatedStateContextItem(0)
52 {
53         AppLogDebug("ENTER");
54         AppLogDebug("EXIT");
55 }
56
57 FolderContentListForm::~FolderContentListForm(void)
58 {
59         AppLogDebug("ENTER");
60         AppLogDebug("EXIT");
61 }
62
63 result
64 FolderContentListForm::Initialize(void)
65 {
66         AppLogDebug("ENTER");
67         if (IsFailed(Form::Construct(IDL_CONTENT_LIST_FORM)))
68         {
69                 AppLogDebug("Construct(IDL_CONTENT_LIST_FORM) failed(%s)", GetErrorMessage(GetLastResult()));
70                 return false;
71         }
72
73         AppLogDebug("EXIT");
74         return Construct();
75 }
76
77 result
78 FolderContentListForm::Construct(void)
79 {
80         AppLogDebug("ENTER");
81         __pContentListTableView = static_cast<TableView*>(GetControl(IDC_TABLEVIEW_CONTENT_LIST));
82         __pContentListTableView->AddTableViewItemEventListener(*this);
83         __pContentListTableView->SetItemProvider(this);
84
85         SetContentList(__pContentListTableView);
86         AppLogDebug("EXIT");
87         return ContentListForm::Construct();
88 }
89
90 result
91 FolderContentListForm::OnInitializing(void)
92 {
93         AppLogDebug("ENTER");
94         __pTableViewContextItem = CommonUtil::CreateTableViewContextItemN(*this, GetWidth(), FLICK_MENU_STYLE_TYPE_01);
95         __fontSizeValue = CommonUtil::GetFontSizeValue();
96         __itemHeight = CommonUtil::GetItemHeight(__fontSizeValue);
97
98         AppLogDebug("EXIT");
99         return ThumbnailBase::Construct();
100 }
101
102 result
103 FolderContentListForm::OnTerminating(void)
104 {
105         AppLogDebug("ENTER");
106         ThumbnailBase::Stop();
107         __pPresentationModel = null;
108         delete __pTableViewContextItem;
109         __pTableViewContextItem = null;
110
111         delete __pCurrentFolderPath;
112         __pCurrentFolderPath = null;
113         AppLogDebug("EXIT");
114         return ContentListForm::OnTerminating();
115 }
116
117 void
118 FolderContentListForm::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         if (pArgs != null)
124         {
125                 if (previousSceneId.Equals(IDSCN_PLAYLIST_CREATOR, false))
126                 {
127                         SetItemCheckedAll(false);
128                 }
129                 else
130                 {
131                         __prevSceneId.Clear();
132                         __prevSceneId.Append(*static_cast<String*>(pArgs->GetAt(DATA_ITEM_SCENE_NAME)));
133                         __currentFolderIndex = static_cast<Integer*>(pArgs->GetAt(DATA_ITEM_CONTENT_TYPE))->ToInt();
134                         __pCurrentFolderPath = new (std::nothrow) String(*(static_cast<String*>(pArgs->GetAt(DATA_ITEM_CONTENT_NAME))));
135
136                         __pPresentationModel = FolderListPresentationModel::GetInstance();
137                         __pPresentationModel->UpdateFolderPathList();
138                         __pPresentationModel->InitializeContentList(__currentFolderIndex);
139
140                         int position = INIT_VALUE;
141                         __pCurrentFolderPath->LastIndexOf(IDS_SEPARATOR_SLASH, __pCurrentFolderPath->GetLength() - 1, position);
142                         __pCurrentFolderPath->SubString(position + 1, __headerTitle);
143
144                         String ellipisiPath = CommonUtil::SetHighDepthToEllipsisPath(*__pCurrentFolderPath);
145                         Rectangle rect(INIT_VALUE, INIT_VALUE, GetWidth(), 42);
146
147                         Label* pAdditionalInfo = new (std::nothrow) Label();
148                         if (!IsFailed(pAdditionalInfo->Construct(rect, ellipisiPath)))
149                         {
150                                 pAdditionalInfo->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
151                                 pAdditionalInfo->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
152                                 pAdditionalInfo->SetTextConfig(32, LABEL_TEXT_STYLE_BOLD);
153                                 pAdditionalInfo->SetTextColor(COLOR_ITEM_SUB_TEXT);
154
155                                 SetExtraInformaionArea(*pAdditionalInfo);
156                         }
157                 }
158
159                 if (GetScreenState() == SCREEN_STATE_EDITOR)
160                 {
161                         CommonUtil::SetEditHeaderStyle(*GetHeader(), ResourceManager::GetString(L"IDS_COM_BODY_EDIT"));
162                 }
163                 else
164                 {
165                         SetHeader();
166                 }
167                 UpdateScreenState();
168                 UpdateTableView();
169
170                 pArgs->RemoveAll(true);
171                 delete pArgs;
172         }
173         AppLogDebug("EXIT");
174 }
175
176 void
177 FolderContentListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
178                                                                         const Tizen::Ui::Scenes::SceneId& nextSceneId)
179 {
180         AppLogDebug("ENTER");
181         CancelAllThumbnailRequest();
182         AppLogDebug("EXIT");
183 }
184
185 void
186 FolderContentListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
187 {
188         AppLogDebug("ENTER");
189         SceneManager* pSceneManager = SceneManager::GetInstance();
190         AppAssert(pSceneManager);
191
192         switch (actionId)
193         {
194         case IDA_CONTEXT_MENU_ITEM_GO_TO_LIBARY:
195                 {
196                         GoToLibrary();
197                 }
198                 break;
199
200         case IDA_CONTEXT_MENU_ITEM_SEARCH:
201                 {
202                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SEARCH, SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY));
203                 }
204                 break;
205
206         case IDA_CONTEXT_MENU_ITEM_EDIT:
207                 {
208                         ToggleScreenState(SCREEN_STATE_EDITOR);
209                 }
210                 break;
211
212         case IDA_FOOTER_BUTTON_MORE:
213                 {
214                         Point anchorPoint(X_POINT_FOOTER_MORE, Y_POINT_PORTRAIT_FOOTER_MORE);
215                         if ((GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE) || (GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
216                         {
217                                 anchorPoint.y = Y_POINT_LANDSCAPE_FOOTER_MORE;
218                         }
219                         CreateOptionMenuN(source);
220                         SetOptionMenuItem(CONTEXT_MENU_ITEM_STYLE_GO_TO_LIBARY | CONTEXT_MENU_ITEM_STYLE_EDIT, anchorPoint);
221                 }
222                 break;
223
224         case IDA_HEADER_BUTTON_SELECTE_ALL:
225                 {
226                         bool isChecked = true;
227                         if (__checkedItemCount == __pContentListTableView->GetItemCount())
228                         {
229                                 isChecked = false;
230                         }
231                         SetItemCheckedAll(isChecked);
232                 }
233                 break;
234
235         case IDA_FOOTER_BUTTON_ADD_TO_PLAYLIST:
236                 {
237                         LanucherPicker(PICKER_TYPE_PLAY_LIST_PICKER);
238                 }
239                 break;
240
241         case IDA_FLICK_MENU_ITEM_SHARE:
242                 {
243                         CreateContextMenuN(source);
244                         SetContextMenuItem(CONTEXT_MENU_ITEM_STYLE_EMAIL | CONTEXT_MENU_ITEM_STYLE_MESSAGE);
245                 }
246                 break;
247
248         case IDA_FLICK_MENU_ITEM_SET_AS:
249                 {
250                         CreateContextMenuN(source);
251                         SetContextMenuItem(CONTEXT_MENU_ITEM_STYLE_CALL | CONTEXT_MENU_ITEM_STYLE_CALLER);
252                 }
253                 break;
254
255         case IDA_FLICK_MENU_ITEM_DELETE:
256                 {
257                         SetCommonPopup(CommonUtil::CreateContentDeletePopup(*this, IDA_COMMON_POPUP_DELETE, IDA_COMMON_POPUP_CANCEL));
258
259                         if (__pContentListTableView->IsContextItemOpened(__activatedStateContextItem))
260                         {
261                                 __pContentListTableView->CloseContextItem(__activatedStateContextItem);
262                         }
263                 }
264                 break;
265
266         case IDA_COMMON_POPUP_CANCEL:
267                 {
268                         // empty statement
269                 }
270                 break;
271
272         case IDA_FLICK_MENU_ITEM_ADDTO:
273                 {
274                         LanucherPicker(PICKER_TYPE_PLAY_LIST_PICKER, PICKER_ARGUMENT_TYPE_ACTIVATED_STATE_CONTEXT_ITEM);
275
276                         if (__pContentListTableView->IsContextItemOpened(__activatedStateContextItem))
277                         {
278                                 __pContentListTableView->CloseContextItem(__activatedStateContextItem);
279                         }
280                 }
281                 break;
282
283         case IDA_COMMON_POPUP_DELETE:
284                 {
285                         if(GetScreenState() == SCREEN_STATE_NORMAL)
286                         {
287                                 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(__activatedStateContextItem);
288                                 if (pContentInfo != null)
289                                 {
290                                         RemoveContentAt(pContentInfo->contentId);
291                                         __pPresentationModel->RefreshContentList(__currentFolderIndex);
292                                         __pContentListTableView->RefreshItem(__activatedStateContextItem, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
293                                         delete pContentInfo;
294                                 }
295                         }
296                         else
297                         {
298                                 RemoveCheckedTableviewItem(true);
299                         }
300                 }
301                 break;
302
303         case IDA_CONTEXT_MENU_ITEM_EMAIL:
304                 // fall through
305         case IDA_CONTEXT_MENU_ITEM_MESSAGE:
306                 {
307                         result r = E_FAILURE;
308                         String providerID = ((actionId == IDA_CONTEXT_MENU_ITEM_EMAIL) ? PROVIDER_ID_EMAIL : PROVIDER_ID_MESSAGE);
309                         AppControl* pAppControl = AppManager::FindAppControlN(providerID, OPERATION_ID_COMPOSE);
310                         if (pAppControl == null)
311                         {
312                                 AppLogDebug("AppManager::FindAppControlN is null");
313                                 return;
314                         }
315
316                         ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(__activatedStateContextItem);
317                         if (pContentInfo == null)
318                         {
319                                 AppLogDebug("PresentationModel->GetContentInfoN is null");
320                                 delete pAppControl;
321                                 pAppControl = null;
322                                 return;
323                         }
324
325                         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
326                         pDataList->Construct();
327
328                         Tizen::Base::Collection::ArrayList* pValueList = new (std::nothrow) ArrayList(SingleObjectDeleter);
329                         pValueList->Construct();
330                         pValueList->Add((new (std::nothrow) String(pContentInfo->ContentFilePath)));
331
332                         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), pValueList);
333                         delete pContentInfo;
334
335                         r = pAppControl->Start(null, null, pDataList, this);
336                         if (r == E_SUCCESS)
337                         {
338                                 Frame* pFrame = MusicPlayerApp::GetInstance()->GetFrameAt(0);
339                                 AppAssert(pFrame);
340                                 pFrame->SetEnabled(false);
341                         }
342
343                         pDataList->RemoveAll(true);
344                         delete pDataList;
345                         pDataList = null;
346
347                         delete pAppControl;
348
349                         if (__pContentListTableView->IsContextItemOpened(__activatedStateContextItem))
350                         {
351                                 __pContentListTableView->CloseContextItem(__activatedStateContextItem);
352                         }
353                 }
354                 break;
355
356         case IDA_CONTEXT_MENU_ITEM_CALL:
357                 {
358                         ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(__activatedStateContextItem);
359                         if (pContentInfo == null)
360                         {
361                                 AppLogDebug("PresentationModel->GetContentInfoN is null");
362                                 return;
363                         }
364
365                         if (!IsFailed(SettingInfo::SetValue(CALL_RINGTONE_KEY, pContentInfo->ContentFilePath)))
366                         {
367                                 MessageBox messageBox;
368                                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_SUCCESS"),
369                                                                         MSGBOX_STYLE_OK,
370                                                                         COUNT_MESSAGE_BOX_TIMEOUT);
371                                 int modalResult = 0;
372                                 messageBox.ShowAndWait(modalResult);
373                         }
374                         delete pContentInfo;
375
376                         if (__pContentListTableView->IsContextItemOpened(__activatedStateContextItem))
377                         {
378                                 __pContentListTableView->CloseContextItem(__activatedStateContextItem);
379                         }
380                 }
381                 break;
382
383         case IDA_CONTEXT_MENU_ITEM_CALLER:
384                 {
385                         AppControl* pAppControl = AppManager::FindAppControlN(PROVIDER_ID_CONTACT, OPERATION_ID_SOCIAL_PICK);
386                         if (pAppControl == null)
387                         {
388                                 AppLogDebug("AppManager::FindAppControlN is null");
389                                 return;
390                         }
391
392                         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
393                         pDataList->Construct();
394                         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTION_MODE), new (std::nothrow) String(APPCONTROL_OPTION_SINGLE));
395                         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_ITEM_TYPE), new (std::nothrow) String(APPCONTROL_OPTION_PERSON));
396                         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_RESULT_TYPE), new (std::nothrow) String(APPCONTROL_OPTION_ITEM_ID));
397
398                         pAppControl->Start(null, null, pDataList, this);
399
400                         pDataList->RemoveAll(true);
401                         delete pDataList;
402                         pDataList = null;
403                         delete pAppControl;
404
405                         if (__pContentListTableView->IsContextItemOpened(__activatedStateContextItem))
406                         {
407                                 __pContentListTableView->CloseContextItem(__activatedStateContextItem);
408                         }
409                 }
410                 break;
411
412 //      case IDA_FOOTER_BUTTON_DELETE:
413 //              {
414 //                      RemoveCheckedTableviewItem(true);
415 //              }
416 //              break;
417         case IDA_FOOTER_BUTTON_DELETE:
418                 {
419                         SetCommonPopup(CommonUtil::CreateContentDeletePopup(*this, IDA_COMMON_POPUP_DELETE, IDA_COMMON_POPUP_CANCEL),this);
420                 }
421                 break;
422
423         case IDA_CONTEXT_MENU_ITEM_SHARE_VIA:
424                 {
425                         ToggleScreenState(SCREEN_STATE_SHARE_VIA);
426                 }
427                 break;
428
429         case IDA_FOOTER_BUTTON_SHARE:
430                 {
431                         LanucherPicker(PICKER_TYPE_SHARE_PICKER, PICKER_ARGUMENT_TYPE_CHECKED_ITEM_ALL);
432                 }
433                 break;
434
435         default:
436                 break;
437         }
438
439         TryRemoveContextMenu(actionId);
440         TryRemoveCommonPopup(actionId);
441         AppLogDebug("EXIT");
442 }
443
444 int
445 FolderContentListForm::GetItemCount(void)
446 {
447         AppLogDebug("ENTER");
448         AppLogDebug("EXIT");
449         return __pPresentationModel->GetContentCount(__currentFolderIndex);
450 }
451
452 Tizen::Ui::Controls::TableViewItem*
453 FolderContentListForm::CreateItem(const int itemIndex, int itemWidth)
454 {
455         AppLogDebug("ENTER");
456         RelativeLayout layout;
457         layout.Construct();
458
459         TableViewAnnexStyle tableViewAnnexStyle = TABLE_VIEW_ANNEX_STYLE_NORMAL;
460         if (GetScreenState() != SCREEN_STATE_NORMAL)
461         {
462                 tableViewAnnexStyle = TABLE_VIEW_ANNEX_STYLE_MARK;
463         }
464
465         TableViewItem* pItem = new (std::nothrow) TableViewItem();
466         ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
467
468         result r = pItem->Construct(layout, Dimension(itemWidth, __itemHeight), tableViewAnnexStyle);
469         TryCatch(r == E_SUCCESS, , "pItem->Construct(%s)", GetErrorMessage(r));
470         TryCatch(pContentInfo != null, , "pContentInfo is null", GetErrorMessage(GetLastResult()));
471
472         r = CreateTableViewItem(*pItem, *pContentInfo);
473         TryCatch(r == E_SUCCESS, , "CreateTableViewItem failed(%s)", GetErrorMessage(r));
474
475         RequestThumbnail(pContentInfo->contentId, (new (std::nothrow) Integer(itemIndex)));
476         delete pContentInfo;
477
478         AppLogDebug("EXIT");
479         return pItem;
480
481 CATCH:
482         AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
483
484         if (pItem != null)
485         {
486                 delete pItem;
487                 pItem = null;
488         }
489
490         delete pContentInfo;
491         return null;
492 }
493
494 void
495 FolderContentListForm::OnFormMenuRequested(Tizen::Ui::Controls::Form& source)
496 {
497         if (GetScreenState() == SCREEN_STATE_NORMAL && IsEmptyContentList() == false)
498         {
499                 CreateOptionMenuN(source);
500                 SetOptionMenuItem(CONTEXT_MENU_ITEM_STYLE_SHARE_VIA | CONTEXT_MENU_ITEM_STYLE_EDIT);
501         }
502 }
503
504 void
505 FolderContentListForm::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
506                                                         int itemIndex,
507                                                         Tizen::Ui::Controls::TableViewItem* pItem,
508                                                         Tizen::Ui::Controls::TableViewItemStatus status)
509 {
510         AppLogDebug("ENTER");
511         if (GetScreenState() != SCREEN_STATE_NORMAL)
512         {
513                 SetItemCheckedStateChanged(status);
514                 AppLogDebug("EXIT");
515                 return;
516         }
517
518         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
519         {
520                 SceneManager* pSceneManager = SceneManager::GetInstance();
521                 AppAssert(pSceneManager);
522
523                 ArrayList* pSceneArg = MakePlayerSceneParam(itemIndex);
524                 if (pSceneArg != null)
525                 {
526                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER), pSceneArg);
527                 }
528         }
529         AppLogDebug("EXIT");
530 }
531
532 void
533 FolderContentListForm::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex,
534                                                                                 Tizen::Ui::Controls::TableViewContextItem* pContextItem,
535                                                                                 bool activated)
536 {
537         AppLogDebug("ENTER");
538         if (itemIndex >= 0)
539         {
540                 AppLogDebug("INDEX %d", itemIndex);
541                 __activatedStateContextItem = itemIndex;
542         }
543         AppLogDebug("EXIT");
544 }
545
546 int
547 FolderContentListForm::GetDefaultItemHeight(void)
548 {
549         AppLogDebug("ENTER");
550         AppLogDebug("EXIT");
551         return ITEM_HEIGHT;
552 }
553
554 bool
555 FolderContentListForm::DeleteItem(const int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
556 {
557         AppLogDebug("ENTER");
558         AppLogDebug("EXIT");
559         return false;
560 }
561
562 void
563 FolderContentListForm::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView,
564                                                         int itemIndexFrom,
565                                                         int itemIndexTo)
566 {
567         AppLogDebug("ENTER");
568         AppLogDebug("EXIT");
569 }
570
571 Tizen::Base::Collection::ArrayList*
572 FolderContentListForm::MakePlayerSceneParam(int startIndex)
573 {
574         AppLogDebug("ENTER");
575         ArrayList* pSelectedMusicContent = __pPresentationModel->GetContentPathListN(__currentFolderIndex);
576         if (pSelectedMusicContent == null)
577         {
578                 AppLogDebug("EXIT");
579                 return null;
580         }
581
582         ArrayList* pTempList = new (std::nothrow) ArrayList();
583         pTempList->Construct();
584         pTempList->Add(*(new (std::nothrow) String(MUSIC)));
585         pTempList->Add(*(new (std::nothrow) Integer(startIndex)));
586         pTempList->Add(*(pSelectedMusicContent));
587
588         AppLogDebug("EXIT");
589         return pTempList;
590 }
591
592 result
593 FolderContentListForm::CreateTableViewItem(Tizen::Ui::Controls::TableViewItem& parent,  const ContentInformation& contentInfo)
594 {
595         AppLogDebug("ENTER");
596         Panel* pTableViewItem = new (std::nothrow) Panel();
597
598         if (GetScreenState() != SCREEN_STATE_NORMAL)
599         {
600                 if (__fontSizeValue.Equals(STRING_FONT_SIZE_GIANT, false))
601                 {
602                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_EDITOR_ITEM_PANEL_FONT_SIZE_GIANT)))
603                         {
604                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
605                                 return E_FAILURE;
606                         }
607                 }
608                 else if (__fontSizeValue.Equals(STRING_FONT_SIZE_HUGE, false))
609                 {
610                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_EDITOR_ITEM_PANEL_FONT_SIZE_HUGE)))
611                         {
612                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
613                                 return E_FAILURE;
614                         }
615                 }
616                 else if (__fontSizeValue.Equals(STRING_FONT_SIZE_LARGE, false))
617                 {
618                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_EDITOR_ITEM_PANEL_FONT_SIZE_LARGE)))
619                         {
620                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
621                                 return E_FAILURE;
622                         }
623                 }
624                 else if (__fontSizeValue.Equals(STRING_FONT_SIZE_SMALL, false))
625                 {
626                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_EDITOR_ITEM_PANEL_FONT_SIZE_SMALL)))
627                         {
628                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
629                                 return E_FAILURE;
630                         }
631                 }
632                 else
633                 {
634                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_EDITOR_ITEM_PANEL_DEFAULT)))
635                         {
636                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
637                                 return E_FAILURE;
638                         }
639                 }
640         }
641         else
642         {
643                 if (__fontSizeValue.Equals(STRING_FONT_SIZE_GIANT, false))
644                 {
645                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_ITEM_PANEL_FONT_SIZE_GIANT)))
646                         {
647                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
648                                 return E_FAILURE;
649                         }
650                 }
651                 else if (__fontSizeValue.Equals(STRING_FONT_SIZE_HUGE, false))
652                 {
653                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_ITEM_PANEL_FONT_SIZE_HUGE)))
654                         {
655                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
656                                 return E_FAILURE;
657                         }
658                 }
659                 else if (__fontSizeValue.Equals(STRING_FONT_SIZE_LARGE, false))
660                 {
661                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_ITEM_PANEL_FONT_SIZE_LARGE)))
662                         {
663                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
664                                 return E_FAILURE;
665                         }
666                 }
667                 else if (__fontSizeValue.Equals(STRING_FONT_SIZE_SMALL, false))
668                 {
669                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_ITEM_PANEL_FONT_SIZE_SMALL)))
670                         {
671                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
672                                 return E_FAILURE;
673                         }
674                 }
675                 else
676                 {
677                         if (IsFailed(pTableViewItem->Construct(IDL_CONTENT_LIST_FOLDER_ITEM_PANEL_DEFAULT)))
678                         {
679                                 AppLogDebug("Construct(IDL_CONTENTS_LIBARY_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
680                                 return E_FAILURE;
681                         }
682                 }
683         }
684
685         String filePath = contentInfo.ContentFilePath;
686         Bitmap* StorageIconBitmap = null;
687         int indexOf = -1;
688
689         String tempPath = contentInfo.ContentFilePath;
690         String fileName;
691         tempPath.LastIndexOf(L"/", tempPath.GetLength() - 1, indexOf);
692         tempPath.SubString(indexOf + 1, fileName);
693
694         String phonePath = IDS_STORAGE_PHONE_PATH;
695         phonePath.Remove(IDS_STORAGE_PHONE_PATH.GetLength() - 1, 1);
696
697         String sdCardPath = IDS_STORAGE_SDCARD_PATH;
698         sdCardPath.Remove(IDS_STORAGE_SDCARD_PATH.GetLength() - 1, 1);
699
700         if (filePath.Contains(phonePath))
701         {
702                 StorageIconBitmap = ResourceManager::GetBitmapN(IDB_STORAGE_PHONE);
703         }
704         else if (filePath.Contains(sdCardPath))
705         {
706                 StorageIconBitmap = ResourceManager::GetBitmapN(IDB_STORAGE_SDCARD);
707         }
708         else
709         {
710                 StorageIconBitmap = ResourceManager::GetBitmapN(IDB_STORAGE_PHONE);
711         }
712
713         Label* pFolderStorageIcon = static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENT_FOLDER_STORAGE_ICON));
714         pFolderStorageIcon->SetBackgroundBitmap(*StorageIconBitmap);
715         delete StorageIconBitmap;
716
717         static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENT_TITLE_NAME))->SetText(fileName);
718 //      static_cast<Label*>(pTableViewItem->GetControl(IDC_CONTENT_THUMBNAIL))->SetBackgroundBitmap(*GetDefaultThumbnail());
719
720         parent.AddControl(pTableViewItem);
721         parent.SetIndividualSelectionEnabled(pTableViewItem, true);
722
723         CommonUtil::SetLayoutFitToContainer(parent, *pTableViewItem);
724
725         AppLogDebug("EXIT");
726         return E_SUCCESS;
727 }
728
729 bool
730 FolderContentListForm::IsEmptyContentList(void)
731 {
732         AppLogDebug("ENTER");
733         if (__pPresentationModel->GetContentCount(__currentFolderIndex) != INIT_VALUE)
734         {
735                 return false;
736         }
737         AppLogDebug("EXIT");
738         return true;
739 }
740
741 result
742 FolderContentListForm::SetHeader(void)
743 {
744         AppLogDebug("ENTER");
745         CommonUtil::SetSimpleTitleStyle(*GetHeader(), __headerTitle);
746         AppLogDebug("EXIT");
747         return E_SUCCESS;
748 }
749
750 void
751 FolderContentListForm::OnAppControlCompleteResponseReceived(const AppId& appId,
752                 const String& operationId, AppCtrlResult appControlResult,
753                 const IMap* pExtraData)
754 {
755         AppLogDebug("ENTER");
756         if (pExtraData == null)
757         {
758                 AppLogDebug("EXIT");
759                 return;
760         }
761         AppLogDebug("%ls, %ls", appId.GetPointer(), operationId.GetPointer());
762         if (appId.Equals(String(PROVIDER_ID_CONTACT)))
763         {
764                 if (appControlResult == APP_CTRL_RESULT_SUCCEEDED)
765                 {
766                         int contactId = -1;
767                         String* pKey = null;
768                         ArrayList* pArrayListValue = null;
769                         String* pResultString = null;
770                         if (pExtraData != null)
771                         {
772                                 IMapEnumerator* pEnum = pExtraData->GetMapEnumeratorN();
773                                 while (pEnum->MoveNext() == E_SUCCESS)
774                                 {
775                                         pKey = static_cast<String*>(pEnum->GetKey());
776                                         if (pKey->Equals(APPCONTROL_KEY_SOCIAL_ITEM_ID, true))
777                                         {
778                                                 pArrayListValue = static_cast<ArrayList*>(pEnum->GetValue());
779                                                 pResultString = static_cast<String*>(pArrayListValue->GetAt(0));
780                                                 AppLogDebug("extraData : %ls:%ls", pKey->GetPointer(), pResultString->GetPointer());
781                                                 Integer::Parse(*pResultString, contactId);
782                                                 break;
783                                         }
784                                 }
785                                 delete pEnum;
786
787                                 if (contactId < 0)
788                                 {
789                                         AppLogDebug("pKey is invaild");
790                                         return;
791                                 }
792                         }
793                         else
794                         {
795                                 AppLogDebug("pExtraData is null");
796                                 return;
797                         }
798
799                         AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
800                         Addressbook* pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
801
802                         ContentInformation* pCcontentInfo = __pPresentationModel->GetContentInfoN(__activatedStateContextItem);
803                         if (pCcontentInfo == null)
804                         {
805                                 delete pAddressbook;
806                                 pAddressbook = null;
807                                 return;
808                         }
809
810                         Contact* pContact = pAddressbook->GetContactN(contactId);
811                         pContact->SetValue(CONTACT_PROPERTY_ID_RINGTONE, pCcontentInfo->ContentFilePath);
812                         result r = pAddressbook->UpdateContact(*pContact);
813
814                         if (r == E_SUCCESS)
815                         {
816                                 ShowDelayedMessageBox(ResourceManager::GetString(L"IDS_COM_POP_SUCCESS"));
817                         }
818
819                         delete pCcontentInfo;
820                         pCcontentInfo = null;
821
822                         delete pContact;
823                         pContact = null;
824
825                         delete pAddressbook;
826                         pAddressbook = null;
827                 }
828         }
829         AppLogDebug("EXIT");
830 }
831
832 void
833 FolderContentListForm::OnThumbnailInfoReveivedN(ThumbnailInfo* pThumbnailInfo)
834 {
835         AppLogDebug("ENTER");
836         __pThumbnail = pThumbnailInfo->GetBitmapN();
837         Object* pParam = pThumbnailInfo->GetUserParamN();
838         if (pParam != null)
839         {
840                 __pContentListTableView->RefreshItem((static_cast<Integer*>(pParam))->ToInt(), TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
841                 delete pParam;
842         }
843
844         delete pThumbnailInfo;
845         AppLogDebug("EXIT");
846 }
847
848 void
849 FolderContentListForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
850 {
851         AppLogDebug("ENTER");
852         ContentListForm::OnUserEventReceivedN(requestId, pArgs);
853         AppLogDebug("EXIT");
854 }
855
856 void
857 FolderContentListForm::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
858 {
859         AppLogDebug("ENTER");
860
861         if (pItem == null)
862         {
863                 AppLogDebug("pItem is null");
864                 delete __pThumbnail;
865                 __pThumbnail = null;
866                 return;
867         }
868
869         Label* pThumbnailLabel = static_cast<Label*>(pItem->GetControl(IDC_CONTENT_THUMBNAIL, true));
870         if (__pThumbnail == null || pThumbnailLabel == null)
871         {
872                 AppLogDebug("__pThumbnail or pThumbnailLabel is null");
873                 delete __pThumbnail;
874                 __pThumbnail = null;
875                 return;
876         }
877         pThumbnailLabel->SetBackgroundBitmap(*__pThumbnail);
878         delete __pThumbnail;
879         __pThumbnail = null;
880         pThumbnailLabel->Invalidate(true);
881         AppLogDebug("EXIT");
882 }
883
884 int
885 FolderContentListForm::GetCheckedItemCount(void)
886 {
887         AppLogDebug("ENTER");
888         AppLogDebug("EXIT");
889         return __checkedItemCount;
890 }
891
892 void
893 FolderContentListForm::UpdateTableView(void)
894 {
895         AppLogDebug("ENTER");
896         __pContentListTableView->UpdateTableView();
897         AppLogDebug("EXIT");
898 }
899
900 void
901 FolderContentListForm::UpdateContentList(void)
902 {
903         AppLogDebug("ENTER");
904         __currentFolderIndex = __pPresentationModel->GetFolderIndex(*__pCurrentFolderPath);
905
906         if (__currentFolderIndex < 0)
907         {
908                 SceneManager* pSceneManager = SceneManager::GetInstance();
909                 AppAssert(pSceneManager);
910                 SetScreenState(SCREEN_STATE_NORMAL);
911
912                 if (pSceneManager->GetCurrentSceneId().Equals(IDSCN_FOLDER_CONTENT_LIST,true))
913                 {
914                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_DESTROY_OPTION_KEEP));
915                 }
916
917         }
918         else
919         {
920                 __pPresentationModel->InitializeContentList(__currentFolderIndex);
921         }
922         AppLogDebug("EXIT");
923 }
924
925 void
926 FolderContentListForm::SetItemCheckedAll(bool isChecked)
927 {
928         AppLogDebug("ENTER");
929         if (isChecked == true)
930         {
931                 __checkedItemCount = __pContentListTableView->GetItemCount();
932         }
933         else
934         {
935                 __checkedItemCount = INIT_VALUE;
936         }
937         CommonUtil::SetItemCheckedAll(isChecked, *__pContentListTableView);
938         if(GetFooter() != null)
939         {
940                 CommonUtil::SetFooterItemEnabled(*GetFooter(), isChecked);
941         }
942
943         SetCheckedCountBallonTooltip(GetCheckedItemCount());
944         AppLogDebug("EXIT");
945 }
946
947 void
948 FolderContentListForm::RemoveCheckedTableviewItem(bool itemRemove)
949 {
950         AppLogDebug("ENTER");
951         if (itemRemove)
952         {
953                 int totalCount = __pContentListTableView->GetItemCount();
954                 for (int iCount = 0; iCount < totalCount; iCount++)
955                 {
956                         if (__pContentListTableView->IsItemChecked(iCount) == true)
957                         {
958                                 __pContentListTableView->SetItemChecked(iCount, false);
959                                 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(iCount);
960                                 RemoveContentAt(pContentInfo->contentId);
961                                 delete pContentInfo;
962                         }
963                 }
964         }
965         else
966         {
967                 SetItemCheckedAll(false);
968         }
969         AppLogDebug("EXIT");
970 }
971
972 void
973 FolderContentListForm::SetItemCheckedStateChanged(Tizen::Ui::Controls::TableViewItemStatus status)
974 {
975         AppLogDebug("ENTER");
976         if (status == TABLE_VIEW_ITEM_STATUS_UNCHECKED)
977         {
978                 __checkedItemCount--;
979                 if (__checkedItemCount == INIT_VALUE)
980                 {
981                         if (GetFooter() != null)
982                         {
983                                 CommonUtil::SetFooterItemEnabled(*GetFooter(), false);
984                         }
985                 }
986         }
987         else if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
988         {
989                 if (__checkedItemCount == INIT_VALUE)
990                 {
991                         if (GetFooter() != null)
992                         {
993                                 CommonUtil::SetFooterItemEnabled(*GetFooter(), true);
994                         }
995                 }
996
997                 __checkedItemCount++;
998         }
999
1000         SetCheckedCountBallonTooltip(GetCheckedItemCount());
1001         AppLogDebug("EXIT");
1002 }
1003
1004 void
1005 FolderContentListForm::GoToLibrary(void)
1006 {
1007         IEnumeratorT<SceneId>* pIEnum = null;
1008         SceneManager* pSceneManager = SceneManager::GetInstance();
1009         IListT<SceneId>* pSceneIdList = pSceneManager->GetSceneHistoryN();
1010         if (pSceneIdList == null)
1011         {
1012                 AppLogDebug("EXIT(ScenList is null)");
1013                 pSceneManager->GoBackward(BackwardSceneTransition());
1014                 return;
1015         }
1016
1017         pSceneManager->ClearSceneHistory();
1018
1019         pIEnum = pSceneIdList->GetEnumeratorN();
1020
1021         if (pIEnum != null)
1022         {
1023                 while (pIEnum->MoveNext() == E_SUCCESS)
1024                 {
1025                         SceneId sceneID;
1026                         pIEnum->GetCurrent(sceneID);
1027
1028                         if (!__prevSceneId.Equals(sceneID, false))
1029                         {
1030                                 pSceneManager->AddToSceneHistory(sceneID);
1031                         }
1032                         else
1033                         {
1034                                 pSceneManager->DestroyScene(sceneID);
1035                         }
1036                 }
1037                 delete pIEnum;
1038         }
1039
1040         pSceneManager->GoBackward(BackwardSceneTransition());
1041 }
1042
1043 Tizen::Base::Collection::IList*
1044 FolderContentListForm::GetPickerArgumentListN(PickerType pickerType, PickerArgumentType argumentType)
1045 {
1046         AppLogDebug("ENTER");
1047         Tizen::Base::Collection::ArrayList* pContentFilePathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1048         if (IsFailed(pContentFilePathList->Construct()))
1049         {
1050                 AppLogDebug("pContentList->Construct failed(%s)", GetErrorMessage(GetLastResult()));
1051                 delete pContentFilePathList;
1052                 return null;
1053         }
1054
1055         if (argumentType == PICKER_ARGUMENT_TYPE_ACTIVATED_STATE_CONTEXT_ITEM)
1056         {
1057                 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(__activatedStateContextItem);
1058                 if (pContentInfo == null)
1059                 {
1060                         delete pContentFilePathList;
1061                         AppLogDebug("GetContentInfoN(%d) is null", __activatedStateContextItem);
1062                         return null;
1063                 }
1064
1065                 pContentFilePathList->Add(*(new (std::nothrow) String(pContentInfo->ContentFilePath)));
1066                 delete pContentInfo;
1067         }
1068         else if (argumentType == PICKER_ARGUMENT_TYPE_CHECKED_ITEM_ALL)
1069         {
1070                 int totalCount = __pContentListTableView->GetItemCount();
1071                 for (int iCount = 0; iCount < totalCount; iCount++)
1072                 {
1073                         if (__pContentListTableView->IsItemChecked(iCount) == true)
1074                         {
1075                                 ContentInformation* pContentInfo = __pPresentationModel->GetContentInfoN(iCount);
1076                                 if (pContentInfo == null)
1077                                 {
1078                                         AppLogDebug("GetContentInfoN(%d) is null", iCount);
1079                                         delete pContentFilePathList;
1080                                         return null;
1081                                 }
1082
1083                                 if (pickerType == PICKER_TYPE_PLAY_LIST_PICKER)
1084                                 {
1085                                         pContentFilePathList->Add(*(new (std::nothrow) String(pContentInfo->ContentFilePath)));
1086                                 }
1087                                 else if (pickerType == PICKER_TYPE_SHARE_PICKER)
1088                                 {
1089                                         pContentFilePathList->Add(*(new (std::nothrow) String(pContentInfo->ContentFilePath)));
1090                                 }
1091                                 delete pContentInfo;
1092                         }
1093                 }
1094         }
1095         AppLogDebug("EXIT");
1096         return pContentFilePathList;
1097 }
1098
1099 void
1100 FolderContentListForm::OnFontSizeChanged(void)
1101 {
1102         __fontSizeValue = CommonUtil::GetFontSizeValue();
1103         __itemHeight = CommonUtil::GetItemHeight(__fontSizeValue);
1104         __pContentListTableView->UpdateTableView();
1105 }