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()));
204 pIconListviewItem = new (std::nothrow) IconListViewItem();
205 pIconListviewItem->Construct(*pBitmap, pItemText);
212 if (pItemText != null)
216 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
218 return pIconListviewItem;
222 AllListSelectionPanel::DeleteItem(int index, IconListViewItem* pItem)
224 AppLogDebug("ENTER");
226 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
232 AllListSelectionPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
234 AppLogDebug("ENTER");
235 if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
237 SceneManager* pSceneManager = SceneManager::GetInstance();
238 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
241 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
242 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), GetItemCheckedCount());
243 __pFileListEditorForm->SetTitleText(strTmp);
244 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
248 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
252 AllListSelectionPanel::OnFileInfoChanged(const ContentType contentType)
254 AppLogDebug("ENTER");
255 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
259 AllListSelectionPanel::OnThumbnailDecoded(const int index)
261 AppLogDebug("ENTER : index(%d)", index);
264 int virtualIndex = -1;
265 int loopCount = __pSeletedIndexList->GetCount();
266 for (int i = 0; i < loopCount; ++i)
268 virtualIndex = GetVirtualIndexFromRealIndex(index);
269 if (virtualIndex >= 0)
271 __pContentIconListView->RefreshList(virtualIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
276 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
280 AllListSelectionPanel::OnSceneActivatedN(const SceneId& previousSceneId,
281 const SceneId& currentSceneId, IList* pArgs)
283 AppLogDebug("ENTER");
284 __pPresentationModel = FileListPresentationModel::GetInstance();
286 SceneManager* pSceneManager = SceneManager::GetInstance();
287 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
289 __pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
290 TryReturnVoid(__pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.", GetErrorMessage(GetLastResult()));
291 __pPresentationModel->AddContentEventListener(__pFileListEditorForm);
293 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
297 __pSeletedIndexList = pArgs;
300 int loopCount = __pSeletedIndexList->GetCount();
301 for (int i = 0; i < loopCount; ++i)
303 __pContentIconListView->SetItemChecked(i, true);
304 __pContentIconListView->RequestRedraw(true);
309 if (pArgs != null && pArgs->GetCount() > 0)
311 String* pDirectory = static_cast<String*>(pArgs->GetAt(0));
312 if (pDirectory != null && pDirectory->GetLength() > 0)
314 __pFileListEditorForm->MoveToAlbum(*pDirectory);
317 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
321 AllListSelectionPanel::OnSceneDeactivated(const SceneId& currentSceneId,
322 const SceneId& nextSceneId)
324 AppLogDebug("ENTER");
325 __pPresentationModel->RemoveContentEventListener(__pFileListEditorForm);
326 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
330 AllListSelectionPanel::GetItemCheckedCount(void) const
332 AppLogDebug("ENTER");
334 if (__pContentIconListView != null && __pSeletedIndexList != null)
336 int loopCount = __pSeletedIndexList->GetCount();
337 for (int i = 0; i < loopCount; ++i)
339 if (__pContentIconListView->IsItemChecked(i))
345 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
351 AllListSelectionPanel::GetItemCheckedIndexListN(void)
353 AppLogDebug("ENTER");
354 IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
355 Integer* pIndex = null;
357 if (__pContentIconListView!=null)
360 int loopCount = __pSeletedIndexList->GetCount();
361 for (int i = 0; i < loopCount; ++i)
363 if (__pContentIconListView->IsItemChecked(i))
365 realIndex = GetRealindexFromVirtualIndex(i);
366 pIndex = new (std::nothrow) Integer(realIndex);
371 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
377 AllListSelectionPanel::GetRealindexFromVirtualIndex(int virtualIndex)
379 if (__pSeletedIndexList == null || __pSeletedIndexList->GetCount() == 0)
381 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
386 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(virtualIndex));
388 if (pRealIndex != null)
390 realIndex = pRealIndex->ToInt();
392 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
398 AllListSelectionPanel::GetVirtualIndexFromRealIndex(int realIndex)
400 int returnValue = -1;
401 int loopCount = __pSeletedIndexList->GetCount();
402 for (int i = 0; i < loopCount; ++i)
404 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(i));
406 if (pRealIndex != null)
408 index = pRealIndex->ToInt();
411 if (index == realIndex)
417 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
423 AllListSelectionPanel::OnRequestDelete(void)
425 AppLogDebug("ENTER");
426 IList* pIndexList = GetItemCheckedIndexListN();
427 if (pIndexList->GetCount() <= 0)
429 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
434 delete __pFileUpdateTimer;
435 __pFileUpdateTimer = new FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_DELETE_ACTION);
436 result r = __pFileUpdateTimer->StartTimer();
440 delete __pFileUpdateTimer;
441 __pFileUpdateTimer = null;
446 __pPresentationModel->SetUpdateProgressStatus(true);
452 void AllListSelectionPanel::OnFileOpInvalidate(enum FileActionMode actionId)
454 __pFileListEditorForm->Invalidate(true);
457 void AllListSelectionPanel::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
459 __pPresentationModel->SetUpdateProgressStatus(false);
460 SceneManager* pSceneManager = SceneManager::GetInstance();
461 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.",
462 GetErrorMessage(GetLastResult()));
465 String selectString = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
466 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", selectString.GetPointer(), 0);
467 __pFileListEditorForm->SetTitleText(strTmp);
469 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
470 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
471 __pContentIconListView->UpdateList();
473 if (GetItemCount() > 0)
475 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
479 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
481 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
485 AllListSelectionPanel::OnRequestMessage(void)
487 AppLogDebug("ENTER");
488 IList* pIndexList = GetItemCheckedIndexListN();
489 if (pIndexList == null || pIndexList->GetCount() <= 0)
491 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
496 Integer* pIndex = null;
498 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
499 pArrayList->Construct();
500 int loopCount = pIndexList->GetCount();
502 for (int i = 0; i < loopCount; ++i)
504 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
507 checkedIndex = pIndex->ToInt();
508 pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(checkedIndex)));
512 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
513 pDataList->Construct();
514 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
515 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
517 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE, null,
518 null, pDataList, null);
519 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
525 AllListSelectionPanel::OnRequestEmail(void)
527 AppLogDebug("ENTER");
528 IList* pIndexList = GetItemCheckedIndexListN();
529 if (pIndexList == null || pIndexList->GetCount() <= 0)
531 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
536 Integer* pIndex = null;
538 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
539 pArrayList->Construct();
540 int loopCount = pIndexList->GetCount();
542 for (int i = 0; i < loopCount; ++i)
544 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
547 checkedIndex = pIndex->ToInt();
548 pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(checkedIndex)));
552 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
553 pDataList->Construct();
554 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
556 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
557 new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, null);
558 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
564 AllListSelectionPanel::OnRequestSlideShow(void)
566 AppLogDebug("ENTER");
567 IList* pIndexList = GetItemCheckedIndexListN();
568 if (pIndexList == null)
570 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
574 Integer* pRealIndex = null;
576 ArrayList* pArrayList = new (std::nothrow) ArrayList(SingleObjectDeleter);
577 pArrayList->Construct();
578 int loopCount = pIndexList->GetCount();
580 for (int i = 0; i < loopCount; ++i)
582 pRealIndex = static_cast<Integer*>(pIndexList->GetAt(i));
583 if (pRealIndex != null)
585 realIndex = pRealIndex->ToInt();
586 pArrayList->Add(new (std::nothrow) String(__pPresentationModel->GetContentFilePath(realIndex)));
590 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
591 pDataList->Construct();
592 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE), new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
593 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pArrayList);
595 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE, APPCONTROL_OPERATION_ID_VIEW, null,
596 new (std::nothrow) String(APPCONTROL_MIME_IMAGE_ALL), pDataList, null);
597 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
603 AllListSelectionPanel::ResetSelection(void)
605 AppLogDebug("ENTER");
606 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
607 if (__pSeletedIndexList == null)
613 __itemCount = __pSeletedIndexList->GetCount();
616 SceneManager* pSceneManager = SceneManager::GetInstance();
617 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
620 String bodyText = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
621 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", bodyText.GetPointer(), __itemCount);
622 __pFileListEditorForm->SetTitleText(strTmp);
623 if (__pContentIconListView != null)
625 __pContentIconListView->UpdateList();
628 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
632 AllListSelectionPanel::SetButtonState(void)
634 AppLogDebug("ENTER");
635 SceneManager* pSceneManager = SceneManager::GetInstance();
636 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
638 if (GetItemCheckedCount() > 0)
640 AppLogDebug("BUTTONSTATE : Request Enable");
641 __pFileListEditorForm->SetFooterButtonsState(true);
645 AppLogDebug("BUTTONSTATE : Request disable");
646 __pFileListEditorForm->SetFooterButtonsState(false);
648 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
652 AllListSelectionPanel::SelectAllPressed(void)
654 bool needToSelectAll = true;
655 int checkedCount = GetItemCheckedCount();
656 if (checkedCount == __itemCount)
658 needToSelectAll = false;
661 if (needToSelectAll == true)
663 for (int i = 0 ; i < __itemCount; ++i)
665 if (__pContentIconListView->IsItemChecked(i) == false)
667 __pContentIconListView->SetItemChecked(i,true);
668 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
674 for (int i = 0 ; i < __itemCount; ++i)
676 if (__pContentIconListView->IsItemChecked(i) == true)
678 __pContentIconListView->SetItemChecked(i, false);
679 __pContentIconListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
684 SceneManager* pSceneManager = SceneManager::GetInstance();
685 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
688 if (needToSelectAll == true)
690 tempString.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
691 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), __itemCount);
695 tempString.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
696 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), 0);
698 __pFileListEditorForm->SetTitleText(tempString);
704 AllListSelectionPanel::OnRotateRequested(RotateMode rotateMode)
706 AppLogDebug("ENTER");
707 IList* pIndexList = GetItemCheckedIndexListN();
708 if (pIndexList == null)
710 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
713 else if (pIndexList->GetCount() <= 0)
716 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
721 delete __pFileUpdateTimer;
722 __pFileUpdateTimer = new FileUpdateTimer(pIndexList, __pPresentationModel, this, FILE_ROTATE_ACTION, rotateMode);
723 result r = __pFileUpdateTimer->StartTimer();
727 delete __pFileUpdateTimer;
728 __pFileUpdateTimer = null;
733 __pPresentationModel->SetUpdateProgressStatus(true);