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