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