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);
104 __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
105 __pContentIconListView->SetMargin(MARGIN_TYPE_LEFT, W_CONTENT_MARGIN);
106 __pContentIconListView->SetMargin(MARGIN_TYPE_RIGHT, W_CONTENT_MARGIN);
107 __pContentIconListView->SetMargin(MARGIN_TYPE_TOP, H_CONTENT_MARGIN);
108 __pContentIconListView->SetItemSpacing(W_CONTENT_SPACE, H_CONTENT_SPACE);
109 __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
110 __pContentIconListView->SetItemProvider(*this);
111 __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
112 __pContentIconListView->AddIconListViewItemEventListener(*this);
113 __pContentIconListView->SetTouchAnimationEnabled(false);
114 AddControl(*__pContentIconListView);
115 __pContentIconListView->SetShowState(true);
118 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
124 AllListSelectionPanel::OnUpdateContentList()
126 AppLogDebug("ENTER");
127 SceneManager* pSceneManager = SceneManager::GetInstance();
128 FileListEditorForm* pFileListEditorForm =
129 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
130 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
131 GetErrorMessage(GetLastResult()));
133 if ( pFileListEditorForm->GetOverlayStatus() == false && __deleteInProgress == false )
135 SceneManager* pSceneManager = SceneManager::GetInstance();
136 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
138 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
142 AllListSelectionPanel::OnTerminating(void)
144 AppLogDebug("ENTER");
145 result r = E_SUCCESS;
146 __pPresentationModel->RemovePresentationModelListener(*this);
147 if (__pSeletedIndexList != null)
149 delete __pSeletedIndexList;
150 __pSeletedIndexList = null;
152 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
158 AllListSelectionPanel::GetItemCount(void)
160 AppLogDebug("ENTER");
161 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
167 AllListSelectionPanel::CreateItem(int index)
169 AppLogDebug("ENTER : index(%d)", index);
170 IconListViewItem* pIconListviewItem;
171 Bitmap* pBitmap = null;
172 String* pItemText = null;
174 int realIndex = GetRealindexFromVirtualIndex(index);
175 result r = __pPresentationModel->GetThumbnailInSyncCacheN(realIndex, pItemText, pBitmap);
176 if (pBitmap == null || r == E_FAILURE)
178 __pPresentationModel->RequestThumbnail(realIndex);
179 pBitmap = CommonUtil::GetEmptyThumbnailN();
182 if (pItemText == null)
184 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
186 else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
189 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
192 if (__pContentIconListView->IsItemChecked(index) == true)
196 BufferInfo bufferInfo;
197 pBitmap->Lock(bufferInfo, INFINITE);
200 Color dimColor(COLOR_THUMBNAIL_DIM);
201 dimColor.SetAlpha(ALPHA_THUMBNAIL_DIM);
204 canvas.Construct(bufferInfo);
205 canvas.FillRectangle(dimColor, canvas.GetBounds());
207 Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
208 pSelectedBitmap->Construct(canvas, canvas.GetBounds());
209 pIconListviewItem = new (std::nothrow) IconListViewItem();
210 pIconListviewItem->Construct(*pBitmap, pItemText, pSelectedBitmap);
211 delete pSelectedBitmap;
215 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
222 pIconListviewItem = new (std::nothrow) IconListViewItem();
223 pIconListviewItem->Construct(*pBitmap, pItemText);
230 if (pItemText != null)
234 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
236 return pIconListviewItem;
240 AllListSelectionPanel::DeleteItem(int index, IconListViewItem* pItem)
242 AppLogDebug("ENTER");
244 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
250 AllListSelectionPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
252 AppLogDebug("ENTER");
253 if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
255 SceneManager* pSceneManager = SceneManager::GetInstance();
256 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
258 FileListEditorForm* pFileListEditorForm =
259 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
260 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.",
261 GetErrorMessage(GetLastResult()));
264 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
265 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), GetItemCheckedCount());
266 pFileListEditorForm->SetTitleText(strTmp);
267 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
271 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
275 AllListSelectionPanel::OnFileInfoChanged(const ContentType contentType)
277 AppLogDebug("ENTER");
278 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
282 AllListSelectionPanel::OnThumbnailDecoded(const int index)
284 AppLogDebug("ENTER : index(%d)", index);
287 int virtualIndex = -1;
288 int loopCount = __pSeletedIndexList->GetCount();
289 for (int i = 0; i < loopCount; ++i)
291 virtualIndex = GetVirtualIndexFromRealIndex(index);
292 if (virtualIndex >= 0)
294 __pContentIconListView->RefreshList(virtualIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
299 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
303 AllListSelectionPanel::OnSceneActivatedN(const SceneId& previousSceneId,
304 const SceneId& currentSceneId, IList* pArgs)
306 AppLogDebug("ENTER");
307 __pPresentationModel = FileListPresentationModel::GetInstance();
309 SceneManager* pSceneManager = SceneManager::GetInstance();
310 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
312 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
316 __pSeletedIndexList = pArgs;
320 int loopCount = __pSeletedIndexList->GetCount();
321 for (int i = 0; i < loopCount; ++i)
323 __pContentIconListView->SetItemChecked(i, true);
324 __pContentIconListView->RequestRedraw(true);
328 FileListEditorForm* pFileListEditorForm =
329 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
330 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.",
331 GetErrorMessage(GetLastResult()));
333 if (pArgs != null && pArgs->GetCount() > 0)
335 String* pDirectory = static_cast<String*>(pArgs->GetAt(0));
336 if (pDirectory != null && pDirectory->GetLength() > 0)
338 pFileListEditorForm->MoveToAlbum(*pDirectory);
341 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
345 AllListSelectionPanel::OnSceneDeactivated(const SceneId& currentSceneId,
346 const SceneId& nextSceneId)
348 AppLogDebug("ENTER");
349 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
353 AllListSelectionPanel::GetItemCheckedCount(void) const
355 AppLogDebug("ENTER");
357 if (__pContentIconListView != null && __pSeletedIndexList != null)
359 int loopCount = __pSeletedIndexList->GetCount();
360 for (int i = 0; i < loopCount; ++i)
362 if (__pContentIconListView->IsItemChecked(i))
368 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
374 AllListSelectionPanel::GetItemCheckedIndexListN(void)
376 AppLogDebug("ENTER");
377 IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
378 Integer* pIndex=null;
380 if (__pContentIconListView!=null)
383 int loopCount = __pSeletedIndexList->GetCount();
384 for (int i = 0; i < loopCount; ++i)
386 if (__pContentIconListView->IsItemChecked(i))
388 realIndex = GetRealindexFromVirtualIndex(i);
389 pIndex = new (std::nothrow) Integer(realIndex);
394 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
400 AllListSelectionPanel::GetRealindexFromVirtualIndex(int virtualIndex)
402 if (__pSeletedIndexList == null || __pSeletedIndexList->GetCount() == 0)
404 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
409 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(virtualIndex));
411 if (pRealIndex != null)
413 realIndex = pRealIndex->ToInt();
415 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
421 AllListSelectionPanel::GetVirtualIndexFromRealIndex(int realIndex)
423 int returnValue = -1;
424 int loopCount = __pSeletedIndexList->GetCount();
425 for (int i = 0; i < loopCount; ++i)
427 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(i));
429 if (pRealIndex != null)
431 index = pRealIndex->ToInt();
434 if (index == realIndex)
440 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
446 AllListSelectionPanel::OnRequestDelete(void)
448 AppLogDebug("ENTER");
449 IList* pIndexList = GetItemCheckedIndexListN();
450 if (pIndexList->GetCount() <= 0)
452 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
457 delete __pFileDelete;
458 __pFileDelete = new FileDeleteTimer(pIndexList,
459 __pPresentationModel,
461 result r = __pFileDelete->StartTimer();
465 delete __pFileDelete;
466 __pFileDelete = null;
471 __deleteInProgress = true;
477 void AllListSelectionPanel::OnFileOpInvalidate(enum FileActionMode actionId)
479 SceneManager* pSceneManager = SceneManager::GetInstance();
480 FileListEditorForm* pFileListEditorForm =
481 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
482 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
483 GetErrorMessage(GetLastResult()));
484 pFileListEditorForm->Invalidate(true);
487 void AllListSelectionPanel::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
489 __deleteInProgress = false;
490 SceneManager* pSceneManager = SceneManager::GetInstance();
491 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.",
492 GetErrorMessage(GetLastResult()));
494 FileListEditorForm* pFileListEditorForm =
495 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
496 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
497 GetErrorMessage(GetLastResult()));
500 String selectString = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
501 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", selectString.GetPointer(), 0);
502 pFileListEditorForm->SetTitleText(strTmp);
504 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
505 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
506 __pContentIconListView->UpdateList();
508 if (GetItemCount() > 0)
510 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
514 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
516 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
520 AllListSelectionPanel::OnRequestMessage(void)
522 AppLogDebug("ENTER");
523 IList* pIndexList = GetItemCheckedIndexListN();
524 if (pIndexList == null || pIndexList->GetCount() <= 0)
526 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
533 Integer* pIndex = null;
536 int loopCount = pIndexList->GetCount();
537 AppLogDebug("pIndexList->GetCount(%d)", loopCount);
538 for (int i = 0; i < loopCount; ++i)
540 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
543 checkedIndex = pIndex->ToInt();
544 path = __pPresentationModel->GetContentFilePath(checkedIndex);
547 if (combineText.CompareTo(EMPTY_SPACE) != 0)
549 combineText.Append(L";");
551 combineText.Append(path);
553 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
554 pDataList->Construct();
555 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
556 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS), new (std::nothrow) String(combineText));
558 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
560 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
566 AllListSelectionPanel::OnRequestEmail(void)
568 AppLogDebug("ENTER");
569 IList* pIndexList = GetItemCheckedIndexListN();
570 if (pIndexList == null || pIndexList->GetCount() <= 0)
572 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
579 Integer* pIndex = null;
582 int loopCount = pIndexList->GetCount();
583 AppLogDebug("pIndexList->GetCount(%d)", loopCount);
584 for (int i = 0; i < loopCount; ++i)
586 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
589 checkedIndex = pIndex->ToInt();
590 path = __pPresentationModel->GetContentFilePath(checkedIndex);
593 if (combineText.CompareTo(EMPTY_SPACE) != 0)
595 combineText.Append(L";");
597 combineText.Append(path);
599 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
600 pDataList->Construct();
601 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS), new (std::nothrow) String(combineText));
603 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
604 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, null);
605 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
611 AllListSelectionPanel::OnRequestSlideShow(void)
613 AppLogDebug("ENTER");
614 IList* pIndexList = GetItemCheckedIndexListN();
615 if (pIndexList == null)
617 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
622 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
623 result r = pDataList->Construct();
628 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
633 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
634 new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
636 Integer* pRealIndex = null;
641 int loopCount = pIndexList->GetCount();
644 for (int i = 0; i < loopCount; ++i)
646 pRealIndex = static_cast<Integer*>(pIndexList->GetAt(i));
647 if (pRealIndex != null)
649 realIndex = pRealIndex->ToInt();
652 path = __pPresentationModel->GetContentFilePath(realIndex);
653 if (combineText.CompareTo(EMPTY_SPACE) != 0)
655 combineText.Append(L";");
657 combineText.Append(path);
659 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH),
660 new (std::nothrow) String(combineText));
665 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE,
666 APPCONTROL_OPERATION_ID_VIEW, pDataList, null);
667 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
673 AllListSelectionPanel::ResetSelection(void)
675 AppLogDebug("ENTER");
676 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
677 if (__pSeletedIndexList == null)
683 __itemCount = __pSeletedIndexList->GetCount();
686 SceneManager* pSceneManager = SceneManager::GetInstance();
687 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
689 FileListEditorForm* pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
690 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.", GetErrorMessage(GetLastResult()));
693 String bodyText = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
694 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", bodyText.GetPointer(), __itemCount);
695 pFileListEditorForm->SetTitleText(strTmp);
696 if (__pContentIconListView != null)
698 __pContentIconListView->UpdateList();
701 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
705 AllListSelectionPanel::SetButtonState(void)
707 AppLogDebug("ENTER");
708 SceneManager* pSceneManager = SceneManager::GetInstance();
709 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
711 FileListEditorForm* pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
712 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.", GetErrorMessage(GetLastResult()));
714 if (GetItemCheckedCount() > 0)
716 AppLogDebug("BUTTONSTATE : Request Enable");
717 pFileListEditorForm->SetFooterButtonsState(true);
721 AppLogDebug("BUTTONSTATE : Request disable");
722 pFileListEditorForm->SetFooterButtonsState(false);
724 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));