2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file GlAllListSelectionPanel.cpp
19 * @brief This is the implementation file for AllListSelectionPanel class.
24 #include "GlAllListSelectionPanel.h"
25 #include "GlCommonUtil.h"
26 #include "GlFileListEditorForm.h"
27 #include "GlFileListPresentationModel.h"
28 #include "GlResourceManager.h"
30 #include "GlFileDeleteTimer.h"
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::Content;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Media;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
42 static const int LENGTH_COUNT_LABEL = 256;
43 static const int H_CONTENT_MARGIN = 9;
44 static const int W_CONTENT_MARGIN = 6;
45 static const int W_CONTENT_SPACE = 6;
46 static const int H_CONTENT_SPACE = 6;
47 static const Color COLOR_THUMBNAIL_DIM (Color::GetColor(COLOR_ID_BLACK));
48 static const int ALPHA_THUMBNAIL_DIM = 70;
50 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
52 AllListSelectionPanel::AllListSelectionPanel(void)
53 : __pContentIconListView(null)
54 , __pSeletedIndexList(null)
56 , __deleteInProgress(false)
57 , __pPresentationModel(null)
61 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
64 AllListSelectionPanel::~AllListSelectionPanel(void)
68 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
72 AllListSelectionPanel::Initialize(void)
75 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
77 return Construct(RECT_INITIAL); // Should be set proper area at OnInitializing()
81 AllListSelectionPanel::OnInitializing(void)
84 const Form* pForm = dynamic_cast<Form*>(GetParent());
85 TryReturn(pForm != null, E_FAILURE, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
87 __pPresentationModel = FileListPresentationModel::GetInstance();
88 __pPresentationModel->ClearThumbnailRequests();
89 __pPresentationModel->AddPresentationModelListener(this);
91 Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
92 clientAreaBounds.x = clientAreaBounds.y = 0;
93 result r = SetBounds(clientAreaBounds);
95 __pContentIconListView = new (std::nothrow) IconListView();
96 __pContentIconListView->Construct(Rectangle(0, 0, clientAreaBounds.width, clientAreaBounds.height),
97 DIMENSION_DEFAULT_THUMBNAIL, ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
98 Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
99 if (pBitmapEmpty != null)
101 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
105 __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
106 __pContentIconListView->SetMargin(MARGIN_TYPE_LEFT, W_CONTENT_MARGIN);
107 __pContentIconListView->SetMargin(MARGIN_TYPE_RIGHT, W_CONTENT_MARGIN);
108 __pContentIconListView->SetMargin(MARGIN_TYPE_TOP, H_CONTENT_MARGIN);
109 __pContentIconListView->SetItemSpacing(W_CONTENT_SPACE, H_CONTENT_SPACE);
110 __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
111 __pContentIconListView->SetItemProvider(*this);
112 __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
113 __pContentIconListView->AddIconListViewItemEventListener(*this);
114 __pContentIconListView->SetTouchAnimationEnabled(false);
115 AddControl(*__pContentIconListView);
116 __pContentIconListView->SetShowState(true);
119 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
125 AllListSelectionPanel::OnUpdateContentList()
127 AppLogDebug("ENTER");
128 SceneManager* pSceneManager = SceneManager::GetInstance();
129 FileListEditorForm* pFileListEditorForm =
130 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
131 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
132 GetErrorMessage(GetLastResult()));
134 if ( pFileListEditorForm->GetOverlayStatus() == false && __deleteInProgress == false )
136 SceneManager* pSceneManager = SceneManager::GetInstance();
137 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
139 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
143 AllListSelectionPanel::OnTerminating(void)
145 AppLogDebug("ENTER");
146 result r = E_SUCCESS;
147 __pPresentationModel->RemovePresentationModelListener(*this);
148 if (__pSeletedIndexList != null)
150 delete __pSeletedIndexList;
151 __pSeletedIndexList = null;
153 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
159 AllListSelectionPanel::GetItemCount(void)
161 AppLogDebug("ENTER");
162 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
168 AllListSelectionPanel::CreateItem(int index)
170 AppLogDebug("ENTER : index(%d)", index);
171 IconListViewItem* pIconListviewItem;
172 Bitmap* pBitmap = null;
173 String* pItemText = null;
175 int realIndex = GetRealindexFromVirtualIndex(index);
176 result r = __pPresentationModel->GetThumbnailInSyncCacheN(realIndex, pItemText, pBitmap);
177 if (pBitmap == null || r == E_FAILURE)
179 __pPresentationModel->RequestThumbnail(realIndex);
180 pBitmap = CommonUtil::GetEmptyThumbnailN();
183 if (pItemText == null)
185 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
187 else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
190 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
193 if (__pContentIconListView->IsItemChecked(index) == true)
197 BufferInfo bufferInfo;
198 pBitmap->Lock(bufferInfo, INFINITE);
201 Color dimColor(COLOR_THUMBNAIL_DIM);
202 dimColor.SetAlpha(ALPHA_THUMBNAIL_DIM);
205 canvas.Construct(bufferInfo);
206 canvas.FillRectangle(dimColor, canvas.GetBounds());
208 Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
209 pSelectedBitmap->Construct(canvas, canvas.GetBounds());
210 pIconListviewItem = new (std::nothrow) IconListViewItem();
211 pIconListviewItem->Construct(*pBitmap, pItemText, pSelectedBitmap);
212 delete pSelectedBitmap;
213 pSelectedBitmap = null;
217 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
224 pIconListviewItem = new (std::nothrow) IconListViewItem();
225 pIconListviewItem->Construct(*pBitmap, pItemText);
233 if (pItemText != null)
238 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
240 return pIconListviewItem;
244 AllListSelectionPanel::DeleteItem(int index, IconListViewItem* pItem)
246 AppLogDebug("ENTER");
248 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
254 AllListSelectionPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
256 AppLogDebug("ENTER");
257 if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
259 SceneManager* pSceneManager = SceneManager::GetInstance();
260 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
262 FileListEditorForm* pFileListEditorForm =
263 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
264 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.",
265 GetErrorMessage(GetLastResult()));
268 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
269 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), GetItemCheckedCount());
270 pFileListEditorForm->SetTitleText(strTmp);
271 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
275 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
279 AllListSelectionPanel::OnFileInfoChanged(const ContentType contentType)
281 AppLogDebug("ENTER");
282 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
286 AllListSelectionPanel::OnThumbnailDecoded(const int index)
288 AppLogDebug("ENTER : index(%d)", index);
291 int virtualIndex = -1;
292 int loopCount = __pSeletedIndexList->GetCount();
293 for (int i = 0; i < loopCount; ++i)
295 virtualIndex = GetVirtualIndexFromRealIndex(index);
296 if (virtualIndex >= 0)
298 __pContentIconListView->RefreshList(virtualIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
303 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
307 AllListSelectionPanel::OnSceneActivatedN(const SceneId& previousSceneId,
308 const SceneId& currentSceneId, IList* pArgs)
310 AppLogDebug("ENTER");
311 __pPresentationModel = FileListPresentationModel::GetInstance();
313 SceneManager* pSceneManager = SceneManager::GetInstance();
314 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
316 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
320 __pSeletedIndexList = pArgs;
324 int loopCount = __pSeletedIndexList->GetCount();
325 for (int i = 0; i < loopCount; ++i)
327 __pContentIconListView->SetItemChecked(i, true);
328 __pContentIconListView->RequestRedraw(true);
332 FileListEditorForm* pFileListEditorForm =
333 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
334 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.",
335 GetErrorMessage(GetLastResult()));
337 if (pArgs != null && pArgs->GetCount() > 0)
339 String* pDirectory = static_cast<String*>(pArgs->GetAt(0));
340 if (pDirectory != null && pDirectory->GetLength() > 0)
342 pFileListEditorForm->MoveToAlbum(*pDirectory);
345 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
349 AllListSelectionPanel::OnSceneDeactivated(const SceneId& currentSceneId,
350 const SceneId& nextSceneId)
352 AppLogDebug("ENTER");
353 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
357 AllListSelectionPanel::GetItemCheckedCount(void) const
359 AppLogDebug("ENTER");
361 if (__pContentIconListView != null && __pSeletedIndexList != null)
363 int loopCount = __pSeletedIndexList->GetCount();
364 for (int i = 0; i < loopCount; ++i)
366 if (__pContentIconListView->IsItemChecked(i))
372 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
378 AllListSelectionPanel::GetItemCheckedIndexListN(void)
380 AppLogDebug("ENTER");
381 IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
382 Integer* pIndex=null;
384 if (__pContentIconListView!=null)
387 int loopCount = __pSeletedIndexList->GetCount();
388 for (int i = 0; i < loopCount; ++i)
390 if (__pContentIconListView->IsItemChecked(i))
392 realIndex = GetRealindexFromVirtualIndex(i);
393 pIndex = new (std::nothrow) Integer(realIndex);
398 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
404 AllListSelectionPanel::GetRealindexFromVirtualIndex(int virtualIndex)
406 if (__pSeletedIndexList == null || __pSeletedIndexList->GetCount() == 0)
408 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
413 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(virtualIndex));
415 if (pRealIndex != null)
417 realIndex = pRealIndex->ToInt();
419 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
425 AllListSelectionPanel::GetVirtualIndexFromRealIndex(int realIndex)
427 int returnValue = -1;
428 int loopCount = __pSeletedIndexList->GetCount();
429 for (int i = 0; i < loopCount; ++i)
431 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(i));
433 if (pRealIndex != null)
435 index = pRealIndex->ToInt();
438 if (index == realIndex)
444 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
450 AllListSelectionPanel::OnRequestDelete(void)
452 AppLogDebug("ENTER");
453 IList* pIndexList = GetItemCheckedIndexListN();
454 if (pIndexList->GetCount() <= 0)
456 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
461 delete __pFileDelete;
462 __pFileDelete = new FileDeleteTimer(pIndexList,
463 __pPresentationModel,
465 result r = __pFileDelete->StartTimer();
469 delete __pFileDelete;
470 __pFileDelete = null;
475 __deleteInProgress = true;
481 void AllListSelectionPanel::OnFileOpInvalidate(enum FileActionMode actionId)
483 SceneManager* pSceneManager = SceneManager::GetInstance();
484 FileListEditorForm* pFileListEditorForm =
485 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
486 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
487 GetErrorMessage(GetLastResult()));
488 pFileListEditorForm->Invalidate(true);
491 void AllListSelectionPanel::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
493 __deleteInProgress = false;
494 SceneManager* pSceneManager = SceneManager::GetInstance();
495 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.",
496 GetErrorMessage(GetLastResult()));
498 FileListEditorForm* pFileListEditorForm =
499 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
500 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
501 GetErrorMessage(GetLastResult()));
504 String selectString = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
505 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", selectString.GetPointer(), 0);
506 pFileListEditorForm->SetTitleText(strTmp);
508 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
509 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
510 __pContentIconListView->UpdateList();
512 if (GetItemCount() > 0)
514 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
518 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
520 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
524 AllListSelectionPanel::OnRequestMessage(void)
526 AppLogDebug("ENTER");
527 IList* pIndexList = GetItemCheckedIndexListN();
528 if (pIndexList == null || pIndexList->GetCount() <= 0)
530 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
537 Integer* pIndex = null;
540 int loopCount = pIndexList->GetCount();
541 AppLogDebug("pIndexList->GetCount(%d)", loopCount);
542 for (int i = 0; i < loopCount; ++i)
544 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
547 checkedIndex = pIndex->ToInt();
548 path = __pPresentationModel->GetContentFilePath(checkedIndex);
551 if (combineText.CompareTo(EMPTY_SPACE) != 0)
553 combineText.Append(L";");
555 combineText.Append(path);
557 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
558 pDataList->Construct();
559 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
560 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS), new (std::nothrow) String(combineText));
562 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
564 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
570 AllListSelectionPanel::OnRequestEmail(void)
572 AppLogDebug("ENTER");
573 IList* pIndexList = GetItemCheckedIndexListN();
574 if (pIndexList == null || pIndexList->GetCount() <= 0)
576 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
583 Integer* pIndex = null;
586 int loopCount = pIndexList->GetCount();
587 AppLogDebug("pIndexList->GetCount(%d)", loopCount);
588 for (int i = 0; i < loopCount; ++i)
590 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
593 checkedIndex = pIndex->ToInt();
594 path = __pPresentationModel->GetContentFilePath(checkedIndex);
597 if (combineText.CompareTo(EMPTY_SPACE) != 0)
599 combineText.Append(L";");
601 combineText.Append(path);
603 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
604 pDataList->Construct();
605 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS), new (std::nothrow) String(combineText));
607 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
608 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, null);
609 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
615 AllListSelectionPanel::OnRequestSlideShow(void)
617 AppLogDebug("ENTER");
618 IList* pIndexList = GetItemCheckedIndexListN();
619 if (pIndexList == null)
621 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
626 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
627 result r = pDataList->Construct();
634 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
639 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
640 new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
642 Integer* pRealIndex = null;
647 int loopCount = pIndexList->GetCount();
650 for (int i = 0; i < loopCount; ++i)
652 pRealIndex = static_cast<Integer*>(pIndexList->GetAt(i));
653 if (pRealIndex != null)
655 realIndex = pRealIndex->ToInt();
658 path = __pPresentationModel->GetContentFilePath(realIndex);
659 if (combineText.CompareTo(EMPTY_SPACE) != 0)
661 combineText.Append(L";");
663 combineText.Append(path);
665 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH),
666 new (std::nothrow) String(combineText));
672 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE,
673 APPCONTROL_OPERATION_ID_VIEW, pDataList, null);
674 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
680 AllListSelectionPanel::ResetSelection(void)
682 AppLogDebug("ENTER");
683 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
684 if (__pSeletedIndexList == null)
690 __itemCount = __pSeletedIndexList->GetCount();
693 SceneManager* pSceneManager = SceneManager::GetInstance();
694 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
696 FileListEditorForm* pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
697 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.", GetErrorMessage(GetLastResult()));
700 String bodyText = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
701 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", bodyText.GetPointer(), __itemCount);
702 pFileListEditorForm->SetTitleText(strTmp);
703 if (__pContentIconListView != null)
705 __pContentIconListView->UpdateList();
708 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
712 AllListSelectionPanel::SetButtonState(void)
714 AppLogDebug("ENTER");
715 SceneManager* pSceneManager = SceneManager::GetInstance();
716 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
718 FileListEditorForm* pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
719 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.", GetErrorMessage(GetLastResult()));
721 if (GetItemCheckedCount() > 0)
723 AppLogDebug("BUTTONSTATE : Request Enable");
724 pFileListEditorForm->SetFooterButtonsState(true);
728 AppLogDebug("BUTTONSTATE : Request disable");
729 pFileListEditorForm->SetFooterButtonsState(false);
731 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));