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"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Utility;
35 using namespace Tizen::Content;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Media;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 static const int LENGTH_COUNT_LABEL = 256;
42 static const int H_CONTENT_MARGIN = 24;
43 static const int W_CONTENT_MARGIN = 14;
44 static const int W_CONTENT_SPACE = 20;
45 static const int H_CONTENT_SPACE = 24;
46 static const Color COLOR_THUMBNAIL_DIM (Color::GetColor(COLOR_ID_BLACK));
47 static const int ALPHA_THUMBNAIL_DIM = 70;
49 static const Rectangle RECT_INITIAL (0, 0, 10, 10);
51 AllListSelectionPanel::AllListSelectionPanel(void)
52 : __pContentIconListView(null)
53 , __pSeletedIndexList(null)
55 , __pPresentationModel(0)
58 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
61 AllListSelectionPanel::~AllListSelectionPanel(void)
64 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
68 AllListSelectionPanel::Initialize(void)
71 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
73 return Construct(RECT_INITIAL); // Should be set proper area at OnInitializing()
77 AllListSelectionPanel::OnInitializing(void)
80 const Form* pForm = dynamic_cast<Form*>(GetParent());
81 TryReturn(pForm != null, E_FAILURE, "[%s] fail to get the form.", GetErrorMessage(GetLastResult()));
83 __pPresentationModel = FileListPresentationModel::GetInstance();
84 __pPresentationModel->ClearThumbnailRequests();
85 __pPresentationModel->AddPresentationModelListener(this);
87 Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
88 clientAreaBounds.x = clientAreaBounds.y = 0;
89 result r = SetBounds(clientAreaBounds);
91 __pContentIconListView = new (std::nothrow) IconListView();
92 __pContentIconListView->Construct(Rectangle(0, 0, clientAreaBounds.width, clientAreaBounds.height),
93 DIMENSION_DEFAULT_THUMBNAIL, ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
94 Bitmap* pBitmapEmpty = ResourceManager::GetBitmapN(IDB_LISTVIEW_EMPTY);
95 if (pBitmapEmpty != null)
97 __pContentIconListView->SetBitmapOfEmptyList(pBitmapEmpty);
101 __pContentIconListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
102 __pContentIconListView->SetMargin(MARGIN_TYPE_LEFT, W_CONTENT_MARGIN);
103 __pContentIconListView->SetMargin(MARGIN_TYPE_RIGHT, W_CONTENT_MARGIN);
104 __pContentIconListView->SetMargin(MARGIN_TYPE_TOP, H_CONTENT_MARGIN);
105 __pContentIconListView->SetItemSpacing(W_CONTENT_SPACE, H_CONTENT_SPACE);
106 __pContentIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
107 __pContentIconListView->SetItemProvider(*this);
108 __pContentIconListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
109 __pContentIconListView->AddIconListViewItemEventListener(*this);
110 __pContentIconListView->SetTouchAnimationEnabled(false);
111 AddControl(*__pContentIconListView);
112 __pContentIconListView->SetShowState(true);
115 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
121 AllListSelectionPanel::OnUpdateContentList()
123 AppLogDebug("ENTER");
124 SceneManager* pSceneManager = SceneManager::GetInstance();
125 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
126 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
130 AllListSelectionPanel::OnTerminating(void)
132 AppLogDebug("ENTER");
133 result r = E_SUCCESS;
134 __pPresentationModel->RemovePresentationModelListener(*this);
135 if (__pSeletedIndexList != null)
137 delete __pSeletedIndexList;
138 __pSeletedIndexList = null;
140 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
146 AllListSelectionPanel::GetItemCount(void)
148 AppLogDebug("ENTER");
149 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
155 AllListSelectionPanel::CreateItem(int index)
157 AppLogDebug("ENTER : index(%d)", index);
158 IconListViewItem* pIconListviewItem;
159 Bitmap* pBitmap = null;
160 String* pItemText = null;
162 int realIndex = GetRealindexFromVirtualIndex(index);
163 result r = __pPresentationModel->GetThumbnailInSyncCacheN(realIndex, pItemText, pBitmap);
164 if (pBitmap == null || r == E_FAILURE)
166 __pPresentationModel->RequestThumbnail(realIndex);
167 pBitmap = CommonUtil::GetEmptyThumbnailN();
170 if (pItemText == null)
172 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
174 else if ((*pItemText) != ResourceManager::GetString(L"EMPTY_SPACE"))
177 pItemText = new (std::nothrow) String(ResourceManager::GetString(L"EMPTY_SPACE"));
180 if (__pContentIconListView->IsItemChecked(index) == true)
184 BufferInfo bufferInfo;
185 pBitmap->Lock(bufferInfo, INFINITE);
188 Color dimColor(COLOR_THUMBNAIL_DIM);
189 dimColor.SetAlpha(ALPHA_THUMBNAIL_DIM);
192 canvas.Construct(bufferInfo);
193 canvas.FillRectangle(dimColor, canvas.GetBounds());
195 Bitmap* pSelectedBitmap = new (std::nothrow) Bitmap();
196 pSelectedBitmap->Construct(canvas, canvas.GetBounds());
197 pIconListviewItem = new (std::nothrow) IconListViewItem();
198 pIconListviewItem->Construct(*pBitmap, pItemText, pSelectedBitmap);
199 delete pSelectedBitmap;
200 pSelectedBitmap = null;
204 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
211 pIconListviewItem = new (std::nothrow) IconListViewItem();
212 pIconListviewItem->Construct(*pBitmap, pItemText);
220 if (pItemText != null)
225 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
227 return pIconListviewItem;
231 AllListSelectionPanel::DeleteItem(int index, IconListViewItem* pItem)
233 AppLogDebug("ENTER");
235 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
241 AllListSelectionPanel::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
243 AppLogDebug("ENTER");
244 if (status == ICON_LIST_VIEW_ITEM_CHECKED || status == ICON_LIST_VIEW_ITEM_UNCHECKED)
246 SceneManager* pSceneManager = SceneManager::GetInstance();
247 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
249 FileListEditorForm* pFileListEditorForm =
250 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
251 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.",
252 GetErrorMessage(GetLastResult()));
255 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)",
256 ResourceManager::GetString(L"IDS_COM_BODY_SELECTED").GetPointer(), GetItemCheckedCount());
257 pFileListEditorForm->SetTitleText(strTmp);
258 __pContentIconListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
262 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
266 AllListSelectionPanel::OnFileInfoChanged(const ContentType contentType)
268 AppLogDebug("ENTER");
269 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
273 AllListSelectionPanel::OnThumbnailDecoded(const int index)
275 AppLogDebug("ENTER : index(%d)", index);
278 int virtualIndex = -1;
279 int loopCount = __pSeletedIndexList->GetCount();
280 for (int i = 0; i < loopCount; ++i)
282 virtualIndex = GetVirtualIndexFromRealIndex(index);
283 if (virtualIndex >= 0)
285 __pContentIconListView->RefreshList(virtualIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
290 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
294 AllListSelectionPanel::OnSceneActivatedN(const SceneId& previousSceneId,
295 const SceneId& currentSceneId, IList* pArgs)
297 AppLogDebug("ENTER");
298 __pPresentationModel = FileListPresentationModel::GetInstance();
300 SceneManager* pSceneManager = SceneManager::GetInstance();
301 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
303 if (previousSceneId == IDSCN_ALBUM_NAME_EDITOR)
305 if (pArgs != null && pArgs->GetCount() > 0)
307 String* pDirectory = static_cast<String*>(pArgs->GetAt(0));
308 OnRequestMoveToAction(*pDirectory);
311 else if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
315 __pSeletedIndexList = pArgs;
319 int loopCount = __pSeletedIndexList->GetCount();
320 for (int i = 0; i < loopCount; ++i)
322 __pContentIconListView->SetItemChecked(i, true);
323 __pContentIconListView->RequestRedraw(true);
327 FileListEditorForm* pFileListEditorForm =
328 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
329 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.",
330 GetErrorMessage(GetLastResult()));
332 if (pArgs != null && pArgs->GetCount() > 0)
334 String* pDirectory = static_cast<String*>(pArgs->GetAt(0));
335 if (pDirectory != null && pDirectory->GetLength() > 0)
337 pFileListEditorForm->MoveToAlbum(*pDirectory);
340 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
344 AllListSelectionPanel::OnSceneDeactivated(const SceneId& currentSceneId,
345 const SceneId& nextSceneId)
347 AppLogDebug("ENTER");
348 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
352 AllListSelectionPanel::GetItemCheckedCount(void) const
354 AppLogDebug("ENTER");
356 if (__pContentIconListView != null && __pSeletedIndexList != null)
358 int loopCount = __pSeletedIndexList->GetCount();
359 for (int i = 0; i < loopCount; ++i)
361 if (__pContentIconListView->IsItemChecked(i))
367 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
373 AllListSelectionPanel::GetItemCheckedIndexListN(void)
375 AppLogDebug("ENTER");
376 IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
377 Integer* pIndex=null;
379 if (__pContentIconListView!=null)
382 int loopCount = __pSeletedIndexList->GetCount();
383 for (int i = 0; i < loopCount; ++i)
385 if (__pContentIconListView->IsItemChecked(i))
387 realIndex = GetRealindexFromVirtualIndex(i);
388 pIndex = new (std::nothrow) Integer(realIndex);
393 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
399 AllListSelectionPanel::GetRealindexFromVirtualIndex(int virtualIndex)
401 if (__pSeletedIndexList == null || __pSeletedIndexList->GetCount() == 0)
403 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
408 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(virtualIndex));
410 if (pRealIndex != null)
412 realIndex = pRealIndex->ToInt();
414 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
420 AllListSelectionPanel::GetVirtualIndexFromRealIndex(int realIndex)
422 int returnValue = -1;
423 int loopCount = __pSeletedIndexList->GetCount();
424 for (int i = 0; i < loopCount; ++i)
426 Integer* pRealIndex = static_cast<Integer*>(__pSeletedIndexList->GetAt(i));
428 if (pRealIndex != null)
430 index = pRealIndex->ToInt();
433 if (index == realIndex)
439 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
445 AllListSelectionPanel::OnRequestDeleteAction(void)
447 AppLogDebug("ENTER");
448 IList* pIndexList = GetItemCheckedIndexListN();
449 if (pIndexList->GetCount() <= 0)
451 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
455 result r = __pPresentationModel->DeleteContentFileList(*pIndexList);
459 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
464 SceneManager* pSceneManager = SceneManager::GetInstance();
465 TryReturn(pSceneManager != null, E_FAILURE, "[%s] fail to get SceneManager.",
466 GetErrorMessage(GetLastResult()));
468 FileListEditorForm* pFileListEditorForm =
469 dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
470 TryReturn(pFileListEditorForm != null, E_FAILURE, "[%s] fail to get FileListEditorForm.",
471 GetErrorMessage(GetLastResult()));
474 String selectString = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
475 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", selectString.GetPointer(), 0);
476 pFileListEditorForm->SetTitleText(strTmp);
478 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
479 __itemCount = __pPresentationModel->GetCurrentAlbumContentInfoCount();
480 __pContentIconListView->UpdateList();
481 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
487 AllListSelectionPanel::OnRequestEmailAction(void)
489 AppLogDebug("ENTER");
490 IList* pIndexList = GetItemCheckedIndexListN();
491 if (pIndexList == null || pIndexList->GetCount() <= 0)
493 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
500 Integer* pIndex = null;
503 int loopCount = pIndexList->GetCount();
504 AppLogDebug("pIndexList->GetCount(%d)", loopCount);
505 for (int i = 0; i < loopCount; ++i)
507 pIndex = static_cast<Integer*>(pIndexList->GetAt(i));
510 checkedIndex = pIndex->ToInt();
511 path = __pPresentationModel->GetContentFilePath(checkedIndex);
514 if (combineText.CompareTo(EMPTY_SPACE) != 0)
516 combineText.Append(L";");
518 combineText.Append(path);
520 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
521 pDataList->Construct();
522 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS), new (std::nothrow) String(combineText));
524 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
525 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, null);
526 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
532 AllListSelectionPanel::OnRequestMoveToAction(String& destDirectory)
534 AppLogDebug("ENTER");
535 if (&destDirectory == null || destDirectory.IsEmpty())
537 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
541 IList* pIndexList = GetItemCheckedIndexListN();
542 if (pIndexList == null || pIndexList->GetCount() <= 0)
544 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
549 IList* pCollisionList = __pPresentationModel->GetCollisionIndexListN(*pIndexList, destDirectory);
551 if (pCollisionList != null)
553 int loopCount = pCollisionList->GetCount();
554 for (int i = 0; i < loopCount; ++i)
556 String* pCollisionString = const_cast<String*>(static_cast<const String*>(pCollisionList->GetAt(i)));
558 if (pCollisionString != null)
560 tmpString = (*pCollisionString);
563 String delim(MULTI_ITEM_SEPARATOR);
564 StringTokenizer st(tmpString, delim);
570 if (st.HasMoreTokens() == true)
572 st.GetNextToken(token);
573 Integer::Parse(token, collisionIndex);
575 if (st.HasMoreTokens() == true)
577 st.GetNextToken(fileNmae);
580 MessageBox messageBox;
581 messageBox.Construct(L"", fileNmae + ResourceManager::GetString(L"IDS_MEDIABR_POP_ALREADY_EXISTS_OVERWRITE_Q"), MSGBOX_STYLE_YESNO, 0);
583 messageBox.ShowAndWait(modalResult);
584 if (modalResult == MSGBOX_RESULT_NO)
586 int innerLoopCount = pIndexList->GetCount();
587 for (int j = 0; j < innerLoopCount; ++j)
589 if(collisionIndex == (const_cast<Integer*>(static_cast<const Integer*>(pIndexList->GetAt(j))))->ToInt())
591 pIndexList->RemoveAt(j, true);
599 delete pCollisionList;
601 result r = __pPresentationModel->MoveToContentFileList(*pIndexList, destDirectory);
604 TryReturn(r == E_SUCCESS, E_FAILURE, "Failed on OnRequestDeleteAction");
606 __pSeletedIndexList->RemoveAll(true);
608 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
614 AllListSelectionPanel::OnRequestSlideShowAction(void)
616 AppLogDebug("ENTER");
617 IList* pIndexList = GetItemCheckedIndexListN();
618 if (pIndexList == null)
620 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
625 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
626 result r = pDataList->Construct();
633 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
638 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
639 new (std::nothrow) String(APPCONTROL_DATA_SLIDE_SHOW));
641 Integer* pRealIndex = null;
646 int loopCount = pIndexList->GetCount();
649 for (int i = 0; i < loopCount; ++i)
651 pRealIndex = static_cast<Integer*>(pIndexList->GetAt(i));
652 if (pRealIndex != null)
654 realIndex = pRealIndex->ToInt();
657 path = __pPresentationModel->GetContentFilePath(realIndex);
658 if (combineText.CompareTo(EMPTY_SPACE) != 0)
660 combineText.Append(L";");
662 combineText.Append(path);
664 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH),
665 new (std::nothrow) String(combineText));
671 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_IMAGE,
672 APPCONTROL_OPERATION_ID_VIEW, pDataList, null);
673 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
679 AllListSelectionPanel::ResetSelection(void)
681 AppLogDebug("ENTER");
682 __pPresentationModel->RefreshCurrentAlbumContentInfoList(CONTENT_TYPE_ALL);
683 if (__pSeletedIndexList == null)
689 __itemCount = __pSeletedIndexList->GetCount();
692 SceneManager* pSceneManager = SceneManager::GetInstance();
693 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
695 FileListEditorForm* pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
696 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.", GetErrorMessage(GetLastResult()));
699 String bodyText = ResourceManager::GetString(L"IDS_COM_BODY_SELECTED");
700 strTmp.Format(LENGTH_COUNT_LABEL, L"%ls (%d)", bodyText.GetPointer(), __itemCount);
701 pFileListEditorForm->SetTitleText(strTmp);
702 if (__pContentIconListView != null)
704 __pContentIconListView->UpdateList();
707 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
711 AllListSelectionPanel::SetButtonState(void)
713 AppLogDebug("ENTER");
714 SceneManager* pSceneManager = SceneManager::GetInstance();
715 TryReturnVoid(pSceneManager != null, "[%s] fail to get SceneManager.", GetErrorMessage(GetLastResult()));
717 FileListEditorForm* pFileListEditorForm = dynamic_cast<FileListEditorForm*>(pSceneManager->GetCurrentScene()->GetForm());
718 TryReturnVoid(pFileListEditorForm != null, "[%s] fail to get FileListEditorForm.", GetErrorMessage(GetLastResult()));
720 if (GetItemCheckedCount() > 0)
722 AppLogDebug("BUTTONSTATE : Request Enable");
723 pFileListEditorForm->SetFooterButtonsState(true);
727 AppLogDebug("BUTTONSTATE : Request disable");
728 pFileListEditorForm->SetFooterButtonsState(false);
730 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));