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 "GlFileUpdateTimer.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 , __pFileListEditorForm(null)
57 , __pFileUpdateTimer(null)
58 , __pPresentationModel(null)
61 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
64 AllListSelectionPanel::~AllListSelectionPanel(void)
67 delete __pFileUpdateTimer;
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::OnTerminating(void)
126 AppLogDebug("ENTER");
127 result r = E_SUCCESS;
128 __pPresentationModel->RemovePresentationModelListener(*this);
129 if (__pSeletedIndexList != null)
131 delete __pSeletedIndexList;
132 __pSeletedIndexList = null;
134 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
140 AllListSelectionPanel::GetItemCount(void)
142 AppLogDebug("ENTER");
143 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
149 AllListSelectionPanel::CreateItem(int index)
151 AppLogDebug("ENTER : index(%d)", index);
152 IconListViewItem* pIconListviewItem;
153 Bitmap* pBitmap = null;
154 String* pItemText = null;
156 int realIndex = GetRealindexFromVirtualIndex(index);
157 result r = __pPresentationModel->GetThumbnailInSyncCacheN(realIndex, pItemText, pBitmap);
158 if (pBitmap == null || r == E_FAILURE)
160 __pPresentationModel->RequestThumbnail(realIndex);
161 pBitmap = CommonUtil::GetEmptyThumbnailN();
164 if (pItemText == null)
166 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
168 else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
171 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
174 if (__pContentIconListView->IsItemChecked(index) == true)
178 BufferInfo bufferInfo;
179 pBitmap->Lock(bufferInfo, INFINITE);
182 Color dimColor(COLOR_THUMBNAIL_DIM);
183 dimColor.SetAlpha(ALPHA_THUMBNAIL_DIM);
186 canvas.Construct(bufferInfo);
187 canvas.FillRectangle(dimColor, canvas.GetBounds());
189 Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
190 pSelectedBitmap->Construct(canvas, canvas.GetBounds());
191 pIconListviewItem = new (std::nothrow) IconListViewItem();
192 pIconListviewItem->Construct(*pBitmap, pItemText, pSelectedBitmap);
193 delete pSelectedBitmap;
197 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
205 pIconListviewItem = new (std::nothrow) IconListViewItem();
206 pIconListviewItem->Construct(*pBitmap, pItemText);
213 if (pItemText != null)
217 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
219 return pIconListviewItem;
223 AllListSelectionPanel::DeleteItem(int index, IconListViewItem* pItem)
225 AppLogDebug("ENTER");
227 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
233 AllListSelectionPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
235 AppLogDebug("ENTER");
236 if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
238 SceneManager* pSceneManager = SceneManager::GetInstance();
239 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
242 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
243 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), GetItemCheckedCount());
244 __pFileListEditorForm->SetTitleText(strTmp);
245 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
249 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
253 AllListSelectionPanel::OnFileInfoChanged(const ContentType contentType)
255 AppLogDebug("ENTER");
256 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
260 AllListSelectionPanel::OnThumbnailDecoded(const int index)
262 AppLogDebug("ENTER : index(%d)", index);
265 int virtualIndex = -1;
266 int loopCount = __pSeletedIndexList->GetCount();
267 for (int i = 0; i < loopCount; ++i)
269 virtualIndex = GetVirtualIndexFromRealIndex(index);
270 if (virtualIndex >= 0)
272 __pContentIconListView->RefreshList(virtualIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
277 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
281 AllListSelectionPanel::OnSceneActivatedN(const SceneId& previousSceneId,
282 const SceneId& currentSceneId, IList* pArgs)
284 AppLogDebug("ENTER");
285 __pPresentationModel = FileListPresentationModel::GetInstance();
287 SceneManager* pSceneManager = SceneManager::GetInstance();
288 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
290 __pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
291 TryReturnVoid(__pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.", GetErrorMessage(GetLastResult()));
292 __pPresentationModel->AddContentEventListener(__pFileListEditorForm);
294 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
298 __pSeletedIndexList = pArgs;
301 int loopCount = __pSeletedIndexList->GetCount();
302 for (int i = 0; i < loopCount; ++i)
304 __pContentIconListView->SetItemChecked(i, true);
305 __pContentIconListView->RequestRedraw(true);
310 if (pArgs != null && pArgs->GetCount() > 0)
312 String* pDirectory = static_cast<String*>(pArgs->GetAt(0));
313 if (pDirectory != null && pDirectory->GetLength() > 0)
315 __pFileListEditorForm->MoveToAlbum(*pDirectory);
318 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
322 AllListSelectionPanel::OnSceneDeactivated(const SceneId& currentSceneId,
323 const SceneId& nextSceneId)
325 AppLogDebug("ENTER");
326 __pPresentationModel->RemoveContentEventListener(__pFileListEditorForm);
327 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
331 AllListSelectionPanel::GetItemCheckedCount(void) const
333 AppLogDebug("ENTER");
335 if (__pContentIconListView != null && __pSeletedIndexList != null)
337 int loopCount = __pSeletedIndexList->GetCount();
338 for (int i = 0; i < loopCount; ++i)
340 if (__pContentIconListView->IsItemChecked(i))
346 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
352 AllListSelectionPanel::GetItemCheckedIndexListN(void)
354 AppLogDebug("ENTER");
355 IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
356 Integer* pIndex = null;
358 if (__pContentIconListView!=null)
361 int loopCount = __pSeletedIndexList->GetCount();
362 for (int i = 0; i < loopCount; ++i)
364 if (__pContentIconListView->IsItemChecked(i))
366 realIndex = GetRealindexFromVirtualIndex(i);
367 pIndex = new (std::nothrow) Integer(realIndex);
372 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
378 AllListSelectionPanel::GetRealindexFromVirtualIndex(int virtualIndex)
380 if (__pSeletedIndexList == null || __pSeletedIndexList->GetCount() == 0)
382 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
387 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(virtualIndex));
389 if (pRealIndex != null)
391 realIndex = pRealIndex->ToInt();
393 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
399 AllListSelectionPanel::GetVirtualIndexFromRealIndex(int realIndex)
401 int returnValue = -1;
402 int loopCount = __pSeletedIndexList->GetCount();
403 for (int i = 0; i < loopCount; ++i)
405 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(i));
407 if (pRealIndex != null)
409 index = pRealIndex->ToInt();
412 if (index == realIndex)
418 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
424 AllListSelectionPanel::OnRequestDelete(void)
426 AppLogDebug("ENTER");
427 IList* pIndexList = GetItemCheckedIndexListN();
428 if (pIndexList->GetCount() <= 0)
430 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
435 delete __pFileUpdateTimer;
436 __pFileUpdateTimer = new FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_DELETE_ACTION);
437 result r = __pFileUpdateTimer->StartTimer();
441 delete __pFileUpdateTimer;
442 __pFileUpdateTimer = null;
447 __pPresentationModel->SetUpdateProgressStatus(true);
453 void AllListSelectionPanel::OnFileOpInvalidate(enum FileActionMode actionId)
455 __pFileListEditorForm->Invalidate(true);
458 void AllListSelectionPanel::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
460 __pPresentationModel->SetUpdateProgressStatus(false);
461 SceneManager* pSceneManager = SceneManager::GetInstance();
462 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.",
463 GetErrorMessage(GetLastResult()));
466 String selectString = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
467 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", selectString.GetPointer(), 0);
468 __pFileListEditorForm->SetTitleText(strTmp);
470 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
471 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
472 __pContentIconListView->UpdateList();
474 if (GetItemCount() > 0)
476 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
480 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
482 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
486 AllListSelectionPanel::OnRequestMessage(void)
488 AppLogDebug("ENTER");
489 IList* pIndexList = GetItemCheckedIndexListN();
490 if (pIndexList == null || pIndexList->GetCount() <= 0)
492 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
497 Integer* pIndex = null;
499 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
500 pArrayList->Construct();
501 int loopCount = pIndexList->GetCount();
503 for (int i = 0; i < loopCount; ++i)
505 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
508 checkedIndex = pIndex->ToInt();
509 pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(checkedIndex)));
513 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
514 pDataList->Construct();
515 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
516 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
518 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE, null,
519 null, pDataList, null);
520 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
526 AllListSelectionPanel::OnRequestEmail(void)
528 AppLogDebug("ENTER");
529 IList* pIndexList = GetItemCheckedIndexListN();
530 if (pIndexList == null || pIndexList->GetCount() <= 0)
532 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
537 Integer* pIndex = null;
539 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
540 pArrayList->Construct();
541 int loopCount = pIndexList->GetCount();
543 for (int i = 0; i < loopCount; ++i)
545 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
548 checkedIndex = pIndex->ToInt();
549 pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(checkedIndex)));
553 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
554 pDataList->Construct();
555 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
557 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
558 new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, null);
559 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
565 AllListSelectionPanel::OnRequestSlideShow(void)
567 AppLogDebug("ENTER");
568 IList* pIndexList = GetItemCheckedIndexListN();
569 if (pIndexList == null)
571 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
575 Integer* pRealIndex = null;
577 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
578 pArrayList->Construct();
579 int loopCount = pIndexList->GetCount();
581 for (int i = 0; i < loopCount; ++i)
583 pRealIndex = static_cast<Integer*>(pIndexList->GetAt(i));
584 if (pRealIndex != null)
586 realIndex = pRealIndex->ToInt();
587 pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(realIndex)));
591 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
592 pDataList->Construct();
593 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
594 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
596 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
597 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
598 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
604 AllListSelectionPanel::ResetSelection(void)
606 AppLogDebug("ENTER");
607 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
608 if (__pSeletedIndexList == null)
614 __itemCount = __pSeletedIndexList->GetCount();
617 SceneManager* pSceneManager = SceneManager::GetInstance();
618 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
621 String bodyText = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
622 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", bodyText.GetPointer(), __itemCount);
623 __pFileListEditorForm->SetTitleText(strTmp);
624 if (__pContentIconListView != null)
626 __pContentIconListView->UpdateList();
629 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
633 AllListSelectionPanel::SetButtonState(void)
635 AppLogDebug("ENTER");
636 SceneManager* pSceneManager = SceneManager::GetInstance();
637 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
639 if (GetItemCheckedCount() > 0)
641 AppLogDebug("BUTTONSTATE : Request Enable");
642 __pFileListEditorForm->SetFooterButtonsState(true);
646 AppLogDebug("BUTTONSTATE : Request disable");
647 __pFileListEditorForm->SetFooterButtonsState(false);
649 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
653 AllListSelectionPanel::SelectAllPressed(void)
655 bool needToSelectAll = true;
656 int checkedCount = GetItemCheckedCount();
657 if (checkedCount == __itemCount)
659 needToSelectAll = false;
662 if (needToSelectAll == true)
664 for (int i = 0 ; i < __itemCount; ++i)
666 if (__pContentIconListView->IsItemChecked(i) == false)
668 __pContentIconListView->SetItemChecked(i,true);
669 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
675 for (int i = 0 ; i < __itemCount; ++i)
677 if (__pContentIconListView->IsItemChecked(i) == true)
679 __pContentIconListView->SetItemChecked(i, false);
680 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
685 SceneManager* pSceneManager = SceneManager::GetInstance();
686 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
689 if (needToSelectAll == true)
691 tempString.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
692 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), __itemCount);
696 tempString.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
697 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), 0);
699 __pFileListEditorForm->SetTitleText(tempString);
705 AllListSelectionPanel::OnRotateRequested(RotateMode rotateMode)
707 AppLogDebug("ENTER");
708 IList* pIndexList = GetItemCheckedIndexListN();
709 if (pIndexList == null)
711 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
714 else if (pIndexList->GetCount() <= 0)
717 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
722 delete __pFileUpdateTimer;
723 __pFileUpdateTimer = new FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ROTATE_ACTION, rotateMode);
724 result r = __pFileUpdateTimer->StartTimer();
728 delete __pFileUpdateTimer;
729 __pFileUpdateTimer = null;
734 __pPresentationModel->SetUpdateProgressStatus(true);