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 = 24;
44 static const int W_CONTENT_MARGIN = 14;
45 static const int W_CONTENT_SPACE = 20;
46 static const int H_CONTENT_SPACE = 24;
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_RIGHT);
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 if ( __deleteInProgress == false )
130 SceneManager* pSceneManager = SceneManager::GetInstance();
131 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
133 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
137 AllListSelectionPanel::OnTerminating(void)
139 AppLogDebug("ENTER");
140 result r = E_SUCCESS;
141 __pPresentationModel->RemovePresentationModelListener(*this);
142 if (__pSeletedIndexList != null)
144 delete __pSeletedIndexList;
145 __pSeletedIndexList = null;
147 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
153 AllListSelectionPanel::GetItemCount(void)
155 AppLogDebug("ENTER");
156 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
162 AllListSelectionPanel::CreateItem(int index)
164 AppLogDebug("ENTER : index(%d)", index);
165 IconListViewItem* pIconListviewItem;
166 Bitmap* pBitmap = null;
167 String* pItemText = null;
169 int realIndex = GetRealindexFromVirtualIndex(index);
170 result r = __pPresentationModel->GetThumbnailInSyncCacheN(realIndex, pItemText, pBitmap);
171 if (pBitmap == null || r == E_FAILURE)
173 __pPresentationModel->RequestThumbnail(realIndex);
174 pBitmap = CommonUtil::GetEmptyThumbnailN();
177 if (pItemText == null)
179 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
181 else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
184 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
187 if (__pContentIconListView->IsItemChecked(index) == true)
191 BufferInfo bufferInfo;
192 pBitmap->Lock(bufferInfo, INFINITE);
195 Color dimColor(COLOR_THUMBNAIL_DIM);
196 dimColor.SetAlpha(ALPHA_THUMBNAIL_DIM);
199 canvas.Construct(bufferInfo);
200 canvas.FillRectangle(dimColor, canvas.GetBounds());
202 Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
203 pSelectedBitmap->Construct(canvas, canvas.GetBounds());
204 pIconListviewItem = new (std::nothrow) IconListViewItem();
205 pIconListviewItem->Construct(*pBitmap, pItemText, pSelectedBitmap);
206 delete pSelectedBitmap;
207 pSelectedBitmap = null;
211 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
218 pIconListviewItem = new (std::nothrow) IconListViewItem();
219 pIconListviewItem->Construct(*pBitmap, pItemText);
227 if (pItemText != null)
232 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
234 return pIconListviewItem;
238 AllListSelectionPanel::DeleteItem(int index, IconListViewItem* pItem)
240 AppLogDebug("ENTER");
242 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
248 AllListSelectionPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
250 AppLogDebug("ENTER");
251 if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
253 SceneManager* pSceneManager = SceneManager::GetInstance();
254 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
256 FileListEditorForm* pFileListEditorForm =
257 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
258 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.",
259 GetErrorMessage(GetLastResult()));
262 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
263 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), GetItemCheckedCount());
264 pFileListEditorForm->SetTitleText(strTmp);
265 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
269 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
273 AllListSelectionPanel::OnFileInfoChanged(const ContentType contentType)
275 AppLogDebug("ENTER");
276 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
280 AllListSelectionPanel::OnThumbnailDecoded(const int index)
282 AppLogDebug("ENTER : index(%d)", index);
285 int virtualIndex = -1;
286 int loopCount = __pSeletedIndexList->GetCount();
287 for (int i = 0; i < loopCount; ++i)
289 virtualIndex = GetVirtualIndexFromRealIndex(index);
290 if (virtualIndex >= 0)
292 __pContentIconListView->RefreshList(virtualIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
297 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
301 AllListSelectionPanel::OnSceneActivatedN(const SceneId& previousSceneId,
302 const SceneId& currentSceneId, IList* pArgs)
304 AppLogDebug("ENTER");
305 __pPresentationModel = FileListPresentationModel::GetInstance();
307 SceneManager* pSceneManager = SceneManager::GetInstance();
308 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
310 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
314 __pSeletedIndexList = pArgs;
318 int loopCount = __pSeletedIndexList->GetCount();
319 for (int i = 0; i < loopCount; ++i)
321 __pContentIconListView->SetItemChecked(i, true);
322 __pContentIconListView->RequestRedraw(true);
326 FileListEditorForm* pFileListEditorForm =
327 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
328 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.",
329 GetErrorMessage(GetLastResult()));
331 if (pArgs != null && pArgs->GetCount() > 0)
333 String* pDirectory = static_cast<String*>(pArgs->GetAt(0));
334 if (pDirectory != null && pDirectory->GetLength() > 0)
336 pFileListEditorForm->MoveToAlbum(*pDirectory);
339 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
343 AllListSelectionPanel::OnSceneDeactivated(const SceneId& currentSceneId,
344 const SceneId& nextSceneId)
346 AppLogDebug("ENTER");
347 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
351 AllListSelectionPanel::GetItemCheckedCount(void) const
353 AppLogDebug("ENTER");
355 if (__pContentIconListView != null && __pSeletedIndexList != null)
357 int loopCount = __pSeletedIndexList->GetCount();
358 for (int i = 0; i < loopCount; ++i)
360 if (__pContentIconListView->IsItemChecked(i))
366 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
372 AllListSelectionPanel::GetItemCheckedIndexListN(void)
374 AppLogDebug("ENTER");
375 IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
376 Integer* pIndex=null;
378 if (__pContentIconListView!=null)
381 int loopCount = __pSeletedIndexList->GetCount();
382 for (int i = 0; i < loopCount; ++i)
384 if (__pContentIconListView->IsItemChecked(i))
386 realIndex = GetRealindexFromVirtualIndex(i);
387 pIndex = new (std::nothrow) Integer(realIndex);
392 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
398 AllListSelectionPanel::GetRealindexFromVirtualIndex(int virtualIndex)
400 if (__pSeletedIndexList == null || __pSeletedIndexList->GetCount() == 0)
402 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
407 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(virtualIndex));
409 if (pRealIndex != null)
411 realIndex = pRealIndex->ToInt();
413 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
419 AllListSelectionPanel::GetVirtualIndexFromRealIndex(int realIndex)
421 int returnValue = -1;
422 int loopCount = __pSeletedIndexList->GetCount();
423 for (int i = 0; i < loopCount; ++i)
425 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(i));
427 if (pRealIndex != null)
429 index = pRealIndex->ToInt();
432 if (index == realIndex)
438 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
444 AllListSelectionPanel::OnRequestDelete(void)
446 AppLogDebug("ENTER");
447 IList* pIndexList = GetItemCheckedIndexListN();
448 if (pIndexList->GetCount() <= 0)
450 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
455 delete __pFileDelete;
456 __pFileDelete = new FileDeleteTimer(pIndexList,
457 __pPresentationModel,
459 result r = __pFileDelete->StartTimer();
463 delete __pFileDelete;
464 __pFileDelete = null;
469 __deleteInProgress = true;
475 void AllListSelectionPanel::OnFileOpInvalidate(enum FileActionMode actionId)
477 SceneManager* pSceneManager = SceneManager::GetInstance();
478 FileListEditorForm* pFileListEditorForm =
479 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
480 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
481 GetErrorMessage(GetLastResult()));
482 pFileListEditorForm->Invalidate(true);
485 void AllListSelectionPanel::OnFileOpComplete(enum FileActionMode actionId, result res)
487 __deleteInProgress = false;
488 SceneManager* pSceneManager = SceneManager::GetInstance();
489 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.",
490 GetErrorMessage(GetLastResult()));
492 FileListEditorForm* pFileListEditorForm =
493 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
494 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get SceneManager.",
495 GetErrorMessage(GetLastResult()));
498 String selectString = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
499 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", selectString.GetPointer(), 0);
500 pFileListEditorForm->SetTitleText(strTmp);
502 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
503 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
504 __pContentIconListView->UpdateList();
506 if (GetItemCount() > 0)
508 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
512 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
514 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
518 AllListSelectionPanel::OnRequestMessage(void)
520 AppLogDebug("ENTER");
521 IList* pIndexList = GetItemCheckedIndexListN();
522 if (pIndexList == null || pIndexList->GetCount() <= 0)
524 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
531 Integer* pIndex = null;
534 int loopCount = pIndexList->GetCount();
535 AppLogDebug("pIndexList->GetCount(%d)", loopCount);
536 for (int i = 0; i < loopCount; ++i)
538 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
541 checkedIndex = pIndex->ToInt();
542 path = __pPresentationModel->GetContentFilePath(checkedIndex);
545 if (combineText.CompareTo(EMPTY_SPACE) != 0)
547 combineText.Append(L";");
549 combineText.Append(path);
551 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
552 pDataList->Construct();
553 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS), new (std::nothrow) String(combineText));
555 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE,
557 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
563 AllListSelectionPanel::OnRequestEmail(void)
565 AppLogDebug("ENTER");
566 IList* pIndexList = GetItemCheckedIndexListN();
567 if (pIndexList == null || pIndexList->GetCount() <= 0)
569 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
576 Integer* pIndex = null;
579 int loopCount = pIndexList->GetCount();
580 AppLogDebug("pIndexList->GetCount(%d)", loopCount);
581 for (int i = 0; i < loopCount; ++i)
583 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
586 checkedIndex = pIndex->ToInt();
587 path = __pPresentationModel->GetContentFilePath(checkedIndex);
590 if (combineText.CompareTo(EMPTY_SPACE) != 0)
592 combineText.Append(L";");
594 combineText.Append(path);
596 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
597 pDataList->Construct();
598 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS), new (std::nothrow) String(combineText));
600 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
601 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, null);
602 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
608 AllListSelectionPanel::OnRequestSlideShow(void)
610 AppLogDebug("ENTER");
611 IList* pIndexList = GetItemCheckedIndexListN();
612 if (pIndexList == null)
614 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
619 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
620 result r = pDataList->Construct();
627 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
632 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
633 new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
635 Integer* pRealIndex = null;
640 int loopCount = pIndexList->GetCount();
643 for (int i = 0; i < loopCount; ++i)
645 pRealIndex = static_cast<Integer*>(pIndexList->GetAt(i));
646 if (pRealIndex != null)
648 realIndex = pRealIndex->ToInt();
651 path = __pPresentationModel->GetContentFilePath(realIndex);
652 if (combineText.CompareTo(EMPTY_SPACE) != 0)
654 combineText.Append(L";");
656 combineText.Append(path);
658 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH),
659 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()));